]> git.ipfire.org Git - thirdparty/grsecurity-scrape.git/blame - test/grsecurity-2.9.1-3.6.4-201210281522.patch
Auto commit, 1 new patch{es}.
[thirdparty/grsecurity-scrape.git] / test / grsecurity-2.9.1-3.6.4-201210281522.patch
CommitLineData
b30c82a4
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 dcf132a..db194e3 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 637970c..0b6556b 100644
4958--- a/arch/score/kernel/process.c
4959+++ b/arch/score/kernel/process.c
4960@@ -161,8 +161,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 7f5f65d..3308382 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@@ -218,7 +218,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), %g0
5995+ andcc %l0, _TIF_WORK_SYSCALL, %g0
5996 ldx [%sp + PTREGS_OFF + PT_V9_TNPC], %l1 ! pc = npc
5997
5998 2:
5999diff --git a/arch/sparc/kernel/traps_32.c b/arch/sparc/kernel/traps_32.c
6000index a5785ea..405c5f7 100644
6001--- a/arch/sparc/kernel/traps_32.c
6002+++ b/arch/sparc/kernel/traps_32.c
6003@@ -44,6 +44,8 @@ static void instruction_dump(unsigned long *pc)
6004 #define __SAVE __asm__ __volatile__("save %sp, -0x40, %sp\n\t")
6005 #define __RESTORE __asm__ __volatile__("restore %g0, %g0, %g0\n\t")
6006
6007+extern void gr_handle_kernel_exploit(void);
6008+
6009 void die_if_kernel(char *str, struct pt_regs *regs)
6010 {
6011 static int die_counter;
6012@@ -76,15 +78,17 @@ void die_if_kernel(char *str, struct pt_regs *regs)
6013 count++ < 30 &&
6014 (((unsigned long) rw) >= PAGE_OFFSET) &&
6015 !(((unsigned long) rw) & 0x7)) {
6016- printk("Caller[%08lx]: %pS\n", rw->ins[7],
6017+ printk("Caller[%08lx]: %pA\n", rw->ins[7],
6018 (void *) rw->ins[7]);
6019 rw = (struct reg_window32 *)rw->ins[6];
6020 }
6021 }
6022 printk("Instruction DUMP:");
6023 instruction_dump ((unsigned long *) regs->pc);
6024- if(regs->psr & PSR_PS)
6025+ if(regs->psr & PSR_PS) {
6026+ gr_handle_kernel_exploit();
6027 do_exit(SIGKILL);
6028+ }
6029 do_exit(SIGSEGV);
6030 }
6031
6032diff --git a/arch/sparc/kernel/traps_64.c b/arch/sparc/kernel/traps_64.c
6033index 3b05e66..6ea2917 100644
6034--- a/arch/sparc/kernel/traps_64.c
6035+++ b/arch/sparc/kernel/traps_64.c
6036@@ -75,7 +75,7 @@ static void dump_tl1_traplog(struct tl1_traplog *p)
6037 i + 1,
6038 p->trapstack[i].tstate, p->trapstack[i].tpc,
6039 p->trapstack[i].tnpc, p->trapstack[i].tt);
6040- printk("TRAPLOG: TPC<%pS>\n", (void *) p->trapstack[i].tpc);
6041+ printk("TRAPLOG: TPC<%pA>\n", (void *) p->trapstack[i].tpc);
6042 }
6043 }
6044
6045@@ -95,6 +95,12 @@ void bad_trap(struct pt_regs *regs, long lvl)
6046
6047 lvl -= 0x100;
6048 if (regs->tstate & TSTATE_PRIV) {
6049+
6050+#ifdef CONFIG_PAX_REFCOUNT
6051+ if (lvl == 6)
6052+ pax_report_refcount_overflow(regs);
6053+#endif
6054+
6055 sprintf(buffer, "Kernel bad sw trap %lx", lvl);
6056 die_if_kernel(buffer, regs);
6057 }
6058@@ -113,11 +119,16 @@ void bad_trap(struct pt_regs *regs, long lvl)
6059 void bad_trap_tl1(struct pt_regs *regs, long lvl)
6060 {
6061 char buffer[32];
6062-
6063+
6064 if (notify_die(DIE_TRAP_TL1, "bad trap tl1", regs,
6065 0, lvl, SIGTRAP) == NOTIFY_STOP)
6066 return;
6067
6068+#ifdef CONFIG_PAX_REFCOUNT
6069+ if (lvl == 6)
6070+ pax_report_refcount_overflow(regs);
6071+#endif
6072+
6073 dump_tl1_traplog((struct tl1_traplog *)(regs + 1));
6074
6075 sprintf (buffer, "Bad trap %lx at tl>0", lvl);
6076@@ -1141,7 +1152,7 @@ static void cheetah_log_errors(struct pt_regs *regs, struct cheetah_err_info *in
6077 regs->tpc, regs->tnpc, regs->u_regs[UREG_I7], regs->tstate);
6078 printk("%s" "ERROR(%d): ",
6079 (recoverable ? KERN_WARNING : KERN_CRIT), smp_processor_id());
6080- printk("TPC<%pS>\n", (void *) regs->tpc);
6081+ printk("TPC<%pA>\n", (void *) regs->tpc);
6082 printk("%s" "ERROR(%d): M_SYND(%lx), E_SYND(%lx)%s%s\n",
6083 (recoverable ? KERN_WARNING : KERN_CRIT), smp_processor_id(),
6084 (afsr & CHAFSR_M_SYNDROME) >> CHAFSR_M_SYNDROME_SHIFT,
6085@@ -1748,7 +1759,7 @@ void cheetah_plus_parity_error(int type, struct pt_regs *regs)
6086 smp_processor_id(),
6087 (type & 0x1) ? 'I' : 'D',
6088 regs->tpc);
6089- printk(KERN_EMERG "TPC<%pS>\n", (void *) regs->tpc);
6090+ printk(KERN_EMERG "TPC<%pA>\n", (void *) regs->tpc);
6091 panic("Irrecoverable Cheetah+ parity error.");
6092 }
6093
6094@@ -1756,7 +1767,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_WARNING "TPC<%pS>\n", (void *) regs->tpc);
6099+ printk(KERN_WARNING "TPC<%pA>\n", (void *) regs->tpc);
6100 }
6101
6102 struct sun4v_error_entry {
6103@@ -1963,9 +1974,9 @@ void sun4v_itlb_error_report(struct pt_regs *regs, int tl)
6104
6105 printk(KERN_EMERG "SUN4V-ITLB: Error at TPC[%lx], tl %d\n",
6106 regs->tpc, tl);
6107- printk(KERN_EMERG "SUN4V-ITLB: TPC<%pS>\n", (void *) regs->tpc);
6108+ printk(KERN_EMERG "SUN4V-ITLB: TPC<%pA>\n", (void *) regs->tpc);
6109 printk(KERN_EMERG "SUN4V-ITLB: O7[%lx]\n", regs->u_regs[UREG_I7]);
6110- printk(KERN_EMERG "SUN4V-ITLB: O7<%pS>\n",
6111+ printk(KERN_EMERG "SUN4V-ITLB: O7<%pA>\n",
6112 (void *) regs->u_regs[UREG_I7]);
6113 printk(KERN_EMERG "SUN4V-ITLB: vaddr[%lx] ctx[%lx] "
6114 "pte[%lx] error[%lx]\n",
6115@@ -1987,9 +1998,9 @@ void sun4v_dtlb_error_report(struct pt_regs *regs, int tl)
6116
6117 printk(KERN_EMERG "SUN4V-DTLB: Error at TPC[%lx], tl %d\n",
6118 regs->tpc, tl);
6119- printk(KERN_EMERG "SUN4V-DTLB: TPC<%pS>\n", (void *) regs->tpc);
6120+ printk(KERN_EMERG "SUN4V-DTLB: TPC<%pA>\n", (void *) regs->tpc);
6121 printk(KERN_EMERG "SUN4V-DTLB: O7[%lx]\n", regs->u_regs[UREG_I7]);
6122- printk(KERN_EMERG "SUN4V-DTLB: O7<%pS>\n",
6123+ printk(KERN_EMERG "SUN4V-DTLB: O7<%pA>\n",
6124 (void *) regs->u_regs[UREG_I7]);
6125 printk(KERN_EMERG "SUN4V-DTLB: vaddr[%lx] ctx[%lx] "
6126 "pte[%lx] error[%lx]\n",
6127@@ -2195,13 +2206,13 @@ void show_stack(struct task_struct *tsk, unsigned long *_ksp)
6128 fp = (unsigned long)sf->fp + STACK_BIAS;
6129 }
6130
6131- printk(" [%016lx] %pS\n", pc, (void *) pc);
6132+ printk(" [%016lx] %pA\n", pc, (void *) pc);
6133 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
6134 if ((pc + 8UL) == (unsigned long) &return_to_handler) {
6135 int index = tsk->curr_ret_stack;
6136 if (tsk->ret_stack && index >= graph) {
6137 pc = tsk->ret_stack[index - graph].ret;
6138- printk(" [%016lx] %pS\n", pc, (void *) pc);
6139+ printk(" [%016lx] %pA\n", pc, (void *) pc);
6140 graph++;
6141 }
6142 }
6143@@ -2226,6 +2237,8 @@ static inline struct reg_window *kernel_stack_up(struct reg_window *rw)
6144 return (struct reg_window *) (fp + STACK_BIAS);
6145 }
6146
6147+extern void gr_handle_kernel_exploit(void);
6148+
6149 void die_if_kernel(char *str, struct pt_regs *regs)
6150 {
6151 static int die_counter;
6152@@ -2254,7 +2267,7 @@ void die_if_kernel(char *str, struct pt_regs *regs)
6153 while (rw &&
6154 count++ < 30 &&
6155 kstack_valid(tp, (unsigned long) rw)) {
6156- printk("Caller[%016lx]: %pS\n", rw->ins[7],
6157+ printk("Caller[%016lx]: %pA\n", rw->ins[7],
6158 (void *) rw->ins[7]);
6159
6160 rw = kernel_stack_up(rw);
6161@@ -2267,8 +2280,10 @@ void die_if_kernel(char *str, struct pt_regs *regs)
6162 }
6163 user_instruction_dump ((unsigned int __user *) regs->tpc);
6164 }
6165- if (regs->tstate & TSTATE_PRIV)
6166+ if (regs->tstate & TSTATE_PRIV) {
6167+ gr_handle_kernel_exploit();
6168 do_exit(SIGKILL);
6169+ }
6170 do_exit(SIGSEGV);
6171 }
6172 EXPORT_SYMBOL(die_if_kernel);
6173diff --git a/arch/sparc/kernel/unaligned_64.c b/arch/sparc/kernel/unaligned_64.c
6174index f81d038..e7a4680 100644
6175--- a/arch/sparc/kernel/unaligned_64.c
6176+++ b/arch/sparc/kernel/unaligned_64.c
6177@@ -278,7 +278,7 @@ static void log_unaligned(struct pt_regs *regs)
6178 static DEFINE_RATELIMIT_STATE(ratelimit, 5 * HZ, 5);
6179
6180 if (__ratelimit(&ratelimit)) {
6181- printk("Kernel unaligned access at TPC[%lx] %pS\n",
6182+ printk("Kernel unaligned access at TPC[%lx] %pA\n",
6183 regs->tpc, (void *) regs->tpc);
6184 }
6185 }
6186diff --git a/arch/sparc/lib/Makefile b/arch/sparc/lib/Makefile
6187index dff4096..bd9a388 100644
6188--- a/arch/sparc/lib/Makefile
6189+++ b/arch/sparc/lib/Makefile
6190@@ -2,7 +2,7 @@
6191 #
6192
6193 asflags-y := -ansi -DST_DIV0=0x02
6194-ccflags-y := -Werror
6195+#ccflags-y := -Werror
6196
6197 lib-$(CONFIG_SPARC32) += ashrdi3.o
6198 lib-$(CONFIG_SPARC32) += memcpy.o memset.o
6199diff --git a/arch/sparc/lib/atomic_64.S b/arch/sparc/lib/atomic_64.S
6200index 4d502da..527c48d 100644
6201--- a/arch/sparc/lib/atomic_64.S
6202+++ b/arch/sparc/lib/atomic_64.S
6203@@ -17,7 +17,12 @@
6204 ENTRY(atomic_add) /* %o0 = increment, %o1 = atomic_ptr */
6205 BACKOFF_SETUP(%o2)
6206 1: lduw [%o1], %g1
6207- add %g1, %o0, %g7
6208+ addcc %g1, %o0, %g7
6209+
6210+#ifdef CONFIG_PAX_REFCOUNT
6211+ tvs %icc, 6
6212+#endif
6213+
6214 cas [%o1], %g1, %g7
6215 cmp %g1, %g7
6216 bne,pn %icc, BACKOFF_LABEL(2f, 1b)
6217@@ -27,10 +32,28 @@ ENTRY(atomic_add) /* %o0 = increment, %o1 = atomic_ptr */
6218 2: BACKOFF_SPIN(%o2, %o3, 1b)
6219 ENDPROC(atomic_add)
6220
6221+ENTRY(atomic_add_unchecked) /* %o0 = increment, %o1 = atomic_ptr */
6222+ BACKOFF_SETUP(%o2)
6223+1: lduw [%o1], %g1
6224+ add %g1, %o0, %g7
6225+ cas [%o1], %g1, %g7
6226+ cmp %g1, %g7
6227+ bne,pn %icc, 2f
6228+ nop
6229+ retl
6230+ nop
6231+2: BACKOFF_SPIN(%o2, %o3, 1b)
6232+ENDPROC(atomic_add_unchecked)
6233+
6234 ENTRY(atomic_sub) /* %o0 = decrement, %o1 = atomic_ptr */
6235 BACKOFF_SETUP(%o2)
6236 1: lduw [%o1], %g1
6237- sub %g1, %o0, %g7
6238+ subcc %g1, %o0, %g7
6239+
6240+#ifdef CONFIG_PAX_REFCOUNT
6241+ tvs %icc, 6
6242+#endif
6243+
6244 cas [%o1], %g1, %g7
6245 cmp %g1, %g7
6246 bne,pn %icc, BACKOFF_LABEL(2f, 1b)
6247@@ -40,10 +63,28 @@ ENTRY(atomic_sub) /* %o0 = decrement, %o1 = atomic_ptr */
6248 2: BACKOFF_SPIN(%o2, %o3, 1b)
6249 ENDPROC(atomic_sub)
6250
6251+ENTRY(atomic_sub_unchecked) /* %o0 = decrement, %o1 = atomic_ptr */
6252+ BACKOFF_SETUP(%o2)
6253+1: lduw [%o1], %g1
6254+ sub %g1, %o0, %g7
6255+ cas [%o1], %g1, %g7
6256+ cmp %g1, %g7
6257+ bne,pn %icc, 2f
6258+ nop
6259+ retl
6260+ nop
6261+2: BACKOFF_SPIN(%o2, %o3, 1b)
6262+ENDPROC(atomic_sub_unchecked)
6263+
6264 ENTRY(atomic_add_ret) /* %o0 = increment, %o1 = atomic_ptr */
6265 BACKOFF_SETUP(%o2)
6266 1: lduw [%o1], %g1
6267- add %g1, %o0, %g7
6268+ addcc %g1, %o0, %g7
6269+
6270+#ifdef CONFIG_PAX_REFCOUNT
6271+ tvs %icc, 6
6272+#endif
6273+
6274 cas [%o1], %g1, %g7
6275 cmp %g1, %g7
6276 bne,pn %icc, BACKOFF_LABEL(2f, 1b)
6277@@ -53,10 +94,29 @@ ENTRY(atomic_add_ret) /* %o0 = increment, %o1 = atomic_ptr */
6278 2: BACKOFF_SPIN(%o2, %o3, 1b)
6279 ENDPROC(atomic_add_ret)
6280
6281+ENTRY(atomic_add_ret_unchecked) /* %o0 = increment, %o1 = atomic_ptr */
6282+ BACKOFF_SETUP(%o2)
6283+1: lduw [%o1], %g1
6284+ addcc %g1, %o0, %g7
6285+ cas [%o1], %g1, %g7
6286+ cmp %g1, %g7
6287+ bne,pn %icc, 2f
6288+ add %g7, %o0, %g7
6289+ sra %g7, 0, %o0
6290+ retl
6291+ nop
6292+2: BACKOFF_SPIN(%o2, %o3, 1b)
6293+ENDPROC(atomic_add_ret_unchecked)
6294+
6295 ENTRY(atomic_sub_ret) /* %o0 = decrement, %o1 = atomic_ptr */
6296 BACKOFF_SETUP(%o2)
6297 1: lduw [%o1], %g1
6298- sub %g1, %o0, %g7
6299+ subcc %g1, %o0, %g7
6300+
6301+#ifdef CONFIG_PAX_REFCOUNT
6302+ tvs %icc, 6
6303+#endif
6304+
6305 cas [%o1], %g1, %g7
6306 cmp %g1, %g7
6307 bne,pn %icc, BACKOFF_LABEL(2f, 1b)
6308@@ -69,7 +129,12 @@ ENDPROC(atomic_sub_ret)
6309 ENTRY(atomic64_add) /* %o0 = increment, %o1 = atomic_ptr */
6310 BACKOFF_SETUP(%o2)
6311 1: ldx [%o1], %g1
6312- add %g1, %o0, %g7
6313+ addcc %g1, %o0, %g7
6314+
6315+#ifdef CONFIG_PAX_REFCOUNT
6316+ tvs %xcc, 6
6317+#endif
6318+
6319 casx [%o1], %g1, %g7
6320 cmp %g1, %g7
6321 bne,pn %xcc, BACKOFF_LABEL(2f, 1b)
6322@@ -79,10 +144,28 @@ ENTRY(atomic64_add) /* %o0 = increment, %o1 = atomic_ptr */
6323 2: BACKOFF_SPIN(%o2, %o3, 1b)
6324 ENDPROC(atomic64_add)
6325
6326+ENTRY(atomic64_add_unchecked) /* %o0 = increment, %o1 = atomic_ptr */
6327+ BACKOFF_SETUP(%o2)
6328+1: ldx [%o1], %g1
6329+ addcc %g1, %o0, %g7
6330+ casx [%o1], %g1, %g7
6331+ cmp %g1, %g7
6332+ bne,pn %xcc, 2f
6333+ nop
6334+ retl
6335+ nop
6336+2: BACKOFF_SPIN(%o2, %o3, 1b)
6337+ENDPROC(atomic64_add_unchecked)
6338+
6339 ENTRY(atomic64_sub) /* %o0 = decrement, %o1 = atomic_ptr */
6340 BACKOFF_SETUP(%o2)
6341 1: ldx [%o1], %g1
6342- sub %g1, %o0, %g7
6343+ subcc %g1, %o0, %g7
6344+
6345+#ifdef CONFIG_PAX_REFCOUNT
6346+ tvs %xcc, 6
6347+#endif
6348+
6349 casx [%o1], %g1, %g7
6350 cmp %g1, %g7
6351 bne,pn %xcc, BACKOFF_LABEL(2f, 1b)
6352@@ -92,10 +175,28 @@ ENTRY(atomic64_sub) /* %o0 = decrement, %o1 = atomic_ptr */
6353 2: BACKOFF_SPIN(%o2, %o3, 1b)
6354 ENDPROC(atomic64_sub)
6355
6356+ENTRY(atomic64_sub_unchecked) /* %o0 = decrement, %o1 = atomic_ptr */
6357+ BACKOFF_SETUP(%o2)
6358+1: ldx [%o1], %g1
6359+ subcc %g1, %o0, %g7
6360+ casx [%o1], %g1, %g7
6361+ cmp %g1, %g7
6362+ bne,pn %xcc, 2f
6363+ nop
6364+ retl
6365+ nop
6366+2: BACKOFF_SPIN(%o2, %o3, 1b)
6367+ENDPROC(atomic64_sub_unchecked)
6368+
6369 ENTRY(atomic64_add_ret) /* %o0 = increment, %o1 = atomic_ptr */
6370 BACKOFF_SETUP(%o2)
6371 1: ldx [%o1], %g1
6372- add %g1, %o0, %g7
6373+ addcc %g1, %o0, %g7
6374+
6375+#ifdef CONFIG_PAX_REFCOUNT
6376+ tvs %xcc, 6
6377+#endif
6378+
6379 casx [%o1], %g1, %g7
6380 cmp %g1, %g7
6381 bne,pn %xcc, BACKOFF_LABEL(2f, 1b)
6382@@ -105,10 +206,29 @@ ENTRY(atomic64_add_ret) /* %o0 = increment, %o1 = atomic_ptr */
6383 2: BACKOFF_SPIN(%o2, %o3, 1b)
6384 ENDPROC(atomic64_add_ret)
6385
6386+ENTRY(atomic64_add_ret_unchecked) /* %o0 = increment, %o1 = atomic_ptr */
6387+ BACKOFF_SETUP(%o2)
6388+1: ldx [%o1], %g1
6389+ addcc %g1, %o0, %g7
6390+ casx [%o1], %g1, %g7
6391+ cmp %g1, %g7
6392+ bne,pn %xcc, 2f
6393+ add %g7, %o0, %g7
6394+ mov %g7, %o0
6395+ retl
6396+ nop
6397+2: BACKOFF_SPIN(%o2, %o3, 1b)
6398+ENDPROC(atomic64_add_ret_unchecked)
6399+
6400 ENTRY(atomic64_sub_ret) /* %o0 = decrement, %o1 = atomic_ptr */
6401 BACKOFF_SETUP(%o2)
6402 1: ldx [%o1], %g1
6403- sub %g1, %o0, %g7
6404+ subcc %g1, %o0, %g7
6405+
6406+#ifdef CONFIG_PAX_REFCOUNT
6407+ tvs %xcc, 6
6408+#endif
6409+
6410 casx [%o1], %g1, %g7
6411 cmp %g1, %g7
6412 bne,pn %xcc, BACKOFF_LABEL(2f, 1b)
6413diff --git a/arch/sparc/lib/ksyms.c b/arch/sparc/lib/ksyms.c
6414index 3b31218..345c609 100644
6415--- a/arch/sparc/lib/ksyms.c
6416+++ b/arch/sparc/lib/ksyms.c
6417@@ -109,12 +109,18 @@ EXPORT_SYMBOL(__downgrade_write);
6418
6419 /* Atomic counter implementation. */
6420 EXPORT_SYMBOL(atomic_add);
6421+EXPORT_SYMBOL(atomic_add_unchecked);
6422 EXPORT_SYMBOL(atomic_add_ret);
6423+EXPORT_SYMBOL(atomic_add_ret_unchecked);
6424 EXPORT_SYMBOL(atomic_sub);
6425+EXPORT_SYMBOL(atomic_sub_unchecked);
6426 EXPORT_SYMBOL(atomic_sub_ret);
6427 EXPORT_SYMBOL(atomic64_add);
6428+EXPORT_SYMBOL(atomic64_add_unchecked);
6429 EXPORT_SYMBOL(atomic64_add_ret);
6430+EXPORT_SYMBOL(atomic64_add_ret_unchecked);
6431 EXPORT_SYMBOL(atomic64_sub);
6432+EXPORT_SYMBOL(atomic64_sub_unchecked);
6433 EXPORT_SYMBOL(atomic64_sub_ret);
6434
6435 /* Atomic bit operations. */
6436diff --git a/arch/sparc/mm/Makefile b/arch/sparc/mm/Makefile
6437index 30c3ecc..736f015 100644
6438--- a/arch/sparc/mm/Makefile
6439+++ b/arch/sparc/mm/Makefile
6440@@ -2,7 +2,7 @@
6441 #
6442
6443 asflags-y := -ansi
6444-ccflags-y := -Werror
6445+#ccflags-y := -Werror
6446
6447 obj-$(CONFIG_SPARC64) += ultra.o tlb.o tsb.o gup.o
6448 obj-y += fault_$(BITS).o
6449diff --git a/arch/sparc/mm/fault_32.c b/arch/sparc/mm/fault_32.c
6450index 77ac917..baf45db 100644
6451--- a/arch/sparc/mm/fault_32.c
6452+++ b/arch/sparc/mm/fault_32.c
6453@@ -21,6 +21,9 @@
6454 #include <linux/perf_event.h>
6455 #include <linux/interrupt.h>
6456 #include <linux/kdebug.h>
6457+#include <linux/slab.h>
6458+#include <linux/pagemap.h>
6459+#include <linux/compiler.h>
6460
6461 #include <asm/page.h>
6462 #include <asm/pgtable.h>
6463@@ -159,6 +162,277 @@ static unsigned long compute_si_addr(struct pt_regs *regs, int text_fault)
6464 return safe_compute_effective_address(regs, insn);
6465 }
6466
6467+#ifdef CONFIG_PAX_PAGEEXEC
6468+#ifdef CONFIG_PAX_DLRESOLVE
6469+static void pax_emuplt_close(struct vm_area_struct *vma)
6470+{
6471+ vma->vm_mm->call_dl_resolve = 0UL;
6472+}
6473+
6474+static int pax_emuplt_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
6475+{
6476+ unsigned int *kaddr;
6477+
6478+ vmf->page = alloc_page(GFP_HIGHUSER);
6479+ if (!vmf->page)
6480+ return VM_FAULT_OOM;
6481+
6482+ kaddr = kmap(vmf->page);
6483+ memset(kaddr, 0, PAGE_SIZE);
6484+ kaddr[0] = 0x9DE3BFA8U; /* save */
6485+ flush_dcache_page(vmf->page);
6486+ kunmap(vmf->page);
6487+ return VM_FAULT_MAJOR;
6488+}
6489+
6490+static const struct vm_operations_struct pax_vm_ops = {
6491+ .close = pax_emuplt_close,
6492+ .fault = pax_emuplt_fault
6493+};
6494+
6495+static int pax_insert_vma(struct vm_area_struct *vma, unsigned long addr)
6496+{
6497+ int ret;
6498+
6499+ INIT_LIST_HEAD(&vma->anon_vma_chain);
6500+ vma->vm_mm = current->mm;
6501+ vma->vm_start = addr;
6502+ vma->vm_end = addr + PAGE_SIZE;
6503+ vma->vm_flags = VM_READ | VM_EXEC | VM_MAYREAD | VM_MAYEXEC;
6504+ vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
6505+ vma->vm_ops = &pax_vm_ops;
6506+
6507+ ret = insert_vm_struct(current->mm, vma);
6508+ if (ret)
6509+ return ret;
6510+
6511+ ++current->mm->total_vm;
6512+ return 0;
6513+}
6514+#endif
6515+
6516+/*
6517+ * PaX: decide what to do with offenders (regs->pc = fault address)
6518+ *
6519+ * returns 1 when task should be killed
6520+ * 2 when patched PLT trampoline was detected
6521+ * 3 when unpatched PLT trampoline was detected
6522+ */
6523+static int pax_handle_fetch_fault(struct pt_regs *regs)
6524+{
6525+
6526+#ifdef CONFIG_PAX_EMUPLT
6527+ int err;
6528+
6529+ do { /* PaX: patched PLT emulation #1 */
6530+ unsigned int sethi1, sethi2, jmpl;
6531+
6532+ err = get_user(sethi1, (unsigned int *)regs->pc);
6533+ err |= get_user(sethi2, (unsigned int *)(regs->pc+4));
6534+ err |= get_user(jmpl, (unsigned int *)(regs->pc+8));
6535+
6536+ if (err)
6537+ break;
6538+
6539+ if ((sethi1 & 0xFFC00000U) == 0x03000000U &&
6540+ (sethi2 & 0xFFC00000U) == 0x03000000U &&
6541+ (jmpl & 0xFFFFE000U) == 0x81C06000U)
6542+ {
6543+ unsigned int addr;
6544+
6545+ regs->u_regs[UREG_G1] = (sethi2 & 0x003FFFFFU) << 10;
6546+ addr = regs->u_regs[UREG_G1];
6547+ addr += (((jmpl | 0xFFFFE000U) ^ 0x00001000U) + 0x00001000U);
6548+ regs->pc = addr;
6549+ regs->npc = addr+4;
6550+ return 2;
6551+ }
6552+ } while (0);
6553+
6554+ do { /* PaX: patched PLT emulation #2 */
6555+ unsigned int ba;
6556+
6557+ err = get_user(ba, (unsigned int *)regs->pc);
6558+
6559+ if (err)
6560+ break;
6561+
6562+ if ((ba & 0xFFC00000U) == 0x30800000U || (ba & 0xFFF80000U) == 0x30480000U) {
6563+ unsigned int addr;
6564+
6565+ if ((ba & 0xFFC00000U) == 0x30800000U)
6566+ addr = regs->pc + ((((ba | 0xFFC00000U) ^ 0x00200000U) + 0x00200000U) << 2);
6567+ else
6568+ addr = regs->pc + ((((ba | 0xFFF80000U) ^ 0x00040000U) + 0x00040000U) << 2);
6569+ regs->pc = addr;
6570+ regs->npc = addr+4;
6571+ return 2;
6572+ }
6573+ } while (0);
6574+
6575+ do { /* PaX: patched PLT emulation #3 */
6576+ unsigned int sethi, bajmpl, nop;
6577+
6578+ err = get_user(sethi, (unsigned int *)regs->pc);
6579+ err |= get_user(bajmpl, (unsigned int *)(regs->pc+4));
6580+ err |= get_user(nop, (unsigned int *)(regs->pc+8));
6581+
6582+ if (err)
6583+ break;
6584+
6585+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
6586+ ((bajmpl & 0xFFFFE000U) == 0x81C06000U || (bajmpl & 0xFFF80000U) == 0x30480000U) &&
6587+ nop == 0x01000000U)
6588+ {
6589+ unsigned int addr;
6590+
6591+ addr = (sethi & 0x003FFFFFU) << 10;
6592+ regs->u_regs[UREG_G1] = addr;
6593+ if ((bajmpl & 0xFFFFE000U) == 0x81C06000U)
6594+ addr += (((bajmpl | 0xFFFFE000U) ^ 0x00001000U) + 0x00001000U);
6595+ else
6596+ addr = regs->pc + ((((bajmpl | 0xFFF80000U) ^ 0x00040000U) + 0x00040000U) << 2);
6597+ regs->pc = addr;
6598+ regs->npc = addr+4;
6599+ return 2;
6600+ }
6601+ } while (0);
6602+
6603+ do { /* PaX: unpatched PLT emulation step 1 */
6604+ unsigned int sethi, ba, nop;
6605+
6606+ err = get_user(sethi, (unsigned int *)regs->pc);
6607+ err |= get_user(ba, (unsigned int *)(regs->pc+4));
6608+ err |= get_user(nop, (unsigned int *)(regs->pc+8));
6609+
6610+ if (err)
6611+ break;
6612+
6613+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
6614+ ((ba & 0xFFC00000U) == 0x30800000U || (ba & 0xFFF80000U) == 0x30680000U) &&
6615+ nop == 0x01000000U)
6616+ {
6617+ unsigned int addr, save, call;
6618+
6619+ if ((ba & 0xFFC00000U) == 0x30800000U)
6620+ addr = regs->pc + 4 + ((((ba | 0xFFC00000U) ^ 0x00200000U) + 0x00200000U) << 2);
6621+ else
6622+ addr = regs->pc + 4 + ((((ba | 0xFFF80000U) ^ 0x00040000U) + 0x00040000U) << 2);
6623+
6624+ err = get_user(save, (unsigned int *)addr);
6625+ err |= get_user(call, (unsigned int *)(addr+4));
6626+ err |= get_user(nop, (unsigned int *)(addr+8));
6627+ if (err)
6628+ break;
6629+
6630+#ifdef CONFIG_PAX_DLRESOLVE
6631+ if (save == 0x9DE3BFA8U &&
6632+ (call & 0xC0000000U) == 0x40000000U &&
6633+ nop == 0x01000000U)
6634+ {
6635+ struct vm_area_struct *vma;
6636+ unsigned long call_dl_resolve;
6637+
6638+ down_read(&current->mm->mmap_sem);
6639+ call_dl_resolve = current->mm->call_dl_resolve;
6640+ up_read(&current->mm->mmap_sem);
6641+ if (likely(call_dl_resolve))
6642+ goto emulate;
6643+
6644+ vma = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
6645+
6646+ down_write(&current->mm->mmap_sem);
6647+ if (current->mm->call_dl_resolve) {
6648+ call_dl_resolve = current->mm->call_dl_resolve;
6649+ up_write(&current->mm->mmap_sem);
6650+ if (vma)
6651+ kmem_cache_free(vm_area_cachep, vma);
6652+ goto emulate;
6653+ }
6654+
6655+ call_dl_resolve = get_unmapped_area(NULL, 0UL, PAGE_SIZE, 0UL, MAP_PRIVATE);
6656+ if (!vma || (call_dl_resolve & ~PAGE_MASK)) {
6657+ up_write(&current->mm->mmap_sem);
6658+ if (vma)
6659+ kmem_cache_free(vm_area_cachep, vma);
6660+ return 1;
6661+ }
6662+
6663+ if (pax_insert_vma(vma, call_dl_resolve)) {
6664+ up_write(&current->mm->mmap_sem);
6665+ kmem_cache_free(vm_area_cachep, vma);
6666+ return 1;
6667+ }
6668+
6669+ current->mm->call_dl_resolve = call_dl_resolve;
6670+ up_write(&current->mm->mmap_sem);
6671+
6672+emulate:
6673+ regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
6674+ regs->pc = call_dl_resolve;
6675+ regs->npc = addr+4;
6676+ return 3;
6677+ }
6678+#endif
6679+
6680+ /* PaX: glibc 2.4+ generates sethi/jmpl instead of save/call */
6681+ if ((save & 0xFFC00000U) == 0x05000000U &&
6682+ (call & 0xFFFFE000U) == 0x85C0A000U &&
6683+ nop == 0x01000000U)
6684+ {
6685+ regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
6686+ regs->u_regs[UREG_G2] = addr + 4;
6687+ addr = (save & 0x003FFFFFU) << 10;
6688+ addr += (((call | 0xFFFFE000U) ^ 0x00001000U) + 0x00001000U);
6689+ regs->pc = addr;
6690+ regs->npc = addr+4;
6691+ return 3;
6692+ }
6693+ }
6694+ } while (0);
6695+
6696+ do { /* PaX: unpatched PLT emulation step 2 */
6697+ unsigned int save, call, nop;
6698+
6699+ err = get_user(save, (unsigned int *)(regs->pc-4));
6700+ err |= get_user(call, (unsigned int *)regs->pc);
6701+ err |= get_user(nop, (unsigned int *)(regs->pc+4));
6702+ if (err)
6703+ break;
6704+
6705+ if (save == 0x9DE3BFA8U &&
6706+ (call & 0xC0000000U) == 0x40000000U &&
6707+ nop == 0x01000000U)
6708+ {
6709+ unsigned int dl_resolve = regs->pc + ((((call | 0xC0000000U) ^ 0x20000000U) + 0x20000000U) << 2);
6710+
6711+ regs->u_regs[UREG_RETPC] = regs->pc;
6712+ regs->pc = dl_resolve;
6713+ regs->npc = dl_resolve+4;
6714+ return 3;
6715+ }
6716+ } while (0);
6717+#endif
6718+
6719+ return 1;
6720+}
6721+
6722+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
6723+{
6724+ unsigned long i;
6725+
6726+ printk(KERN_ERR "PAX: bytes at PC: ");
6727+ for (i = 0; i < 8; i++) {
6728+ unsigned int c;
6729+ if (get_user(c, (unsigned int *)pc+i))
6730+ printk(KERN_CONT "???????? ");
6731+ else
6732+ printk(KERN_CONT "%08x ", c);
6733+ }
6734+ printk("\n");
6735+}
6736+#endif
6737+
6738 static noinline void do_fault_siginfo(int code, int sig, struct pt_regs *regs,
6739 int text_fault)
6740 {
6741@@ -230,6 +504,24 @@ good_area:
6742 if (!(vma->vm_flags & VM_WRITE))
6743 goto bad_area;
6744 } else {
6745+
6746+#ifdef CONFIG_PAX_PAGEEXEC
6747+ if ((mm->pax_flags & MF_PAX_PAGEEXEC) && text_fault && !(vma->vm_flags & VM_EXEC)) {
6748+ up_read(&mm->mmap_sem);
6749+ switch (pax_handle_fetch_fault(regs)) {
6750+
6751+#ifdef CONFIG_PAX_EMUPLT
6752+ case 2:
6753+ case 3:
6754+ return;
6755+#endif
6756+
6757+ }
6758+ pax_report_fault(regs, (void *)regs->pc, (void *)regs->u_regs[UREG_FP]);
6759+ do_group_exit(SIGKILL);
6760+ }
6761+#endif
6762+
6763 /* Allow reads even for write-only mappings */
6764 if (!(vma->vm_flags & (VM_READ | VM_EXEC)))
6765 goto bad_area;
6766diff --git a/arch/sparc/mm/fault_64.c b/arch/sparc/mm/fault_64.c
6767index 1fe0429..8dd5dd5 100644
6768--- a/arch/sparc/mm/fault_64.c
6769+++ b/arch/sparc/mm/fault_64.c
6770@@ -21,6 +21,9 @@
6771 #include <linux/kprobes.h>
6772 #include <linux/kdebug.h>
6773 #include <linux/percpu.h>
6774+#include <linux/slab.h>
6775+#include <linux/pagemap.h>
6776+#include <linux/compiler.h>
6777
6778 #include <asm/page.h>
6779 #include <asm/pgtable.h>
6780@@ -74,7 +77,7 @@ static void __kprobes bad_kernel_pc(struct pt_regs *regs, unsigned long vaddr)
6781 printk(KERN_CRIT "OOPS: Bogus kernel PC [%016lx] in fault handler\n",
6782 regs->tpc);
6783 printk(KERN_CRIT "OOPS: RPC [%016lx]\n", regs->u_regs[15]);
6784- printk("OOPS: RPC <%pS>\n", (void *) regs->u_regs[15]);
6785+ printk("OOPS: RPC <%pA>\n", (void *) regs->u_regs[15]);
6786 printk(KERN_CRIT "OOPS: Fault was to vaddr[%lx]\n", vaddr);
6787 dump_stack();
6788 unhandled_fault(regs->tpc, current, regs);
6789@@ -272,6 +275,466 @@ static void noinline __kprobes bogus_32bit_fault_address(struct pt_regs *regs,
6790 show_regs(regs);
6791 }
6792
6793+#ifdef CONFIG_PAX_PAGEEXEC
6794+#ifdef CONFIG_PAX_DLRESOLVE
6795+static void pax_emuplt_close(struct vm_area_struct *vma)
6796+{
6797+ vma->vm_mm->call_dl_resolve = 0UL;
6798+}
6799+
6800+static int pax_emuplt_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
6801+{
6802+ unsigned int *kaddr;
6803+
6804+ vmf->page = alloc_page(GFP_HIGHUSER);
6805+ if (!vmf->page)
6806+ return VM_FAULT_OOM;
6807+
6808+ kaddr = kmap(vmf->page);
6809+ memset(kaddr, 0, PAGE_SIZE);
6810+ kaddr[0] = 0x9DE3BFA8U; /* save */
6811+ flush_dcache_page(vmf->page);
6812+ kunmap(vmf->page);
6813+ return VM_FAULT_MAJOR;
6814+}
6815+
6816+static const struct vm_operations_struct pax_vm_ops = {
6817+ .close = pax_emuplt_close,
6818+ .fault = pax_emuplt_fault
6819+};
6820+
6821+static int pax_insert_vma(struct vm_area_struct *vma, unsigned long addr)
6822+{
6823+ int ret;
6824+
6825+ INIT_LIST_HEAD(&vma->anon_vma_chain);
6826+ vma->vm_mm = current->mm;
6827+ vma->vm_start = addr;
6828+ vma->vm_end = addr + PAGE_SIZE;
6829+ vma->vm_flags = VM_READ | VM_EXEC | VM_MAYREAD | VM_MAYEXEC;
6830+ vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
6831+ vma->vm_ops = &pax_vm_ops;
6832+
6833+ ret = insert_vm_struct(current->mm, vma);
6834+ if (ret)
6835+ return ret;
6836+
6837+ ++current->mm->total_vm;
6838+ return 0;
6839+}
6840+#endif
6841+
6842+/*
6843+ * PaX: decide what to do with offenders (regs->tpc = fault address)
6844+ *
6845+ * returns 1 when task should be killed
6846+ * 2 when patched PLT trampoline was detected
6847+ * 3 when unpatched PLT trampoline was detected
6848+ */
6849+static int pax_handle_fetch_fault(struct pt_regs *regs)
6850+{
6851+
6852+#ifdef CONFIG_PAX_EMUPLT
6853+ int err;
6854+
6855+ do { /* PaX: patched PLT emulation #1 */
6856+ unsigned int sethi1, sethi2, jmpl;
6857+
6858+ err = get_user(sethi1, (unsigned int *)regs->tpc);
6859+ err |= get_user(sethi2, (unsigned int *)(regs->tpc+4));
6860+ err |= get_user(jmpl, (unsigned int *)(regs->tpc+8));
6861+
6862+ if (err)
6863+ break;
6864+
6865+ if ((sethi1 & 0xFFC00000U) == 0x03000000U &&
6866+ (sethi2 & 0xFFC00000U) == 0x03000000U &&
6867+ (jmpl & 0xFFFFE000U) == 0x81C06000U)
6868+ {
6869+ unsigned long addr;
6870+
6871+ regs->u_regs[UREG_G1] = (sethi2 & 0x003FFFFFU) << 10;
6872+ addr = regs->u_regs[UREG_G1];
6873+ addr += (((jmpl | 0xFFFFFFFFFFFFE000UL) ^ 0x00001000UL) + 0x00001000UL);
6874+
6875+ if (test_thread_flag(TIF_32BIT))
6876+ addr &= 0xFFFFFFFFUL;
6877+
6878+ regs->tpc = addr;
6879+ regs->tnpc = addr+4;
6880+ return 2;
6881+ }
6882+ } while (0);
6883+
6884+ do { /* PaX: patched PLT emulation #2 */
6885+ unsigned int ba;
6886+
6887+ err = get_user(ba, (unsigned int *)regs->tpc);
6888+
6889+ if (err)
6890+ break;
6891+
6892+ if ((ba & 0xFFC00000U) == 0x30800000U || (ba & 0xFFF80000U) == 0x30480000U) {
6893+ unsigned long addr;
6894+
6895+ if ((ba & 0xFFC00000U) == 0x30800000U)
6896+ addr = regs->tpc + ((((ba | 0xFFFFFFFFFFC00000UL) ^ 0x00200000UL) + 0x00200000UL) << 2);
6897+ else
6898+ addr = regs->tpc + ((((ba | 0xFFFFFFFFFFF80000UL) ^ 0x00040000UL) + 0x00040000UL) << 2);
6899+
6900+ if (test_thread_flag(TIF_32BIT))
6901+ addr &= 0xFFFFFFFFUL;
6902+
6903+ regs->tpc = addr;
6904+ regs->tnpc = addr+4;
6905+ return 2;
6906+ }
6907+ } while (0);
6908+
6909+ do { /* PaX: patched PLT emulation #3 */
6910+ unsigned int sethi, bajmpl, nop;
6911+
6912+ err = get_user(sethi, (unsigned int *)regs->tpc);
6913+ err |= get_user(bajmpl, (unsigned int *)(regs->tpc+4));
6914+ err |= get_user(nop, (unsigned int *)(regs->tpc+8));
6915+
6916+ if (err)
6917+ break;
6918+
6919+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
6920+ ((bajmpl & 0xFFFFE000U) == 0x81C06000U || (bajmpl & 0xFFF80000U) == 0x30480000U) &&
6921+ nop == 0x01000000U)
6922+ {
6923+ unsigned long addr;
6924+
6925+ addr = (sethi & 0x003FFFFFU) << 10;
6926+ regs->u_regs[UREG_G1] = addr;
6927+ if ((bajmpl & 0xFFFFE000U) == 0x81C06000U)
6928+ addr += (((bajmpl | 0xFFFFFFFFFFFFE000UL) ^ 0x00001000UL) + 0x00001000UL);
6929+ else
6930+ addr = regs->tpc + ((((bajmpl | 0xFFFFFFFFFFF80000UL) ^ 0x00040000UL) + 0x00040000UL) << 2);
6931+
6932+ if (test_thread_flag(TIF_32BIT))
6933+ addr &= 0xFFFFFFFFUL;
6934+
6935+ regs->tpc = addr;
6936+ regs->tnpc = addr+4;
6937+ return 2;
6938+ }
6939+ } while (0);
6940+
6941+ do { /* PaX: patched PLT emulation #4 */
6942+ unsigned int sethi, mov1, call, mov2;
6943+
6944+ err = get_user(sethi, (unsigned int *)regs->tpc);
6945+ err |= get_user(mov1, (unsigned int *)(regs->tpc+4));
6946+ err |= get_user(call, (unsigned int *)(regs->tpc+8));
6947+ err |= get_user(mov2, (unsigned int *)(regs->tpc+12));
6948+
6949+ if (err)
6950+ break;
6951+
6952+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
6953+ mov1 == 0x8210000FU &&
6954+ (call & 0xC0000000U) == 0x40000000U &&
6955+ mov2 == 0x9E100001U)
6956+ {
6957+ unsigned long addr;
6958+
6959+ regs->u_regs[UREG_G1] = regs->u_regs[UREG_RETPC];
6960+ addr = regs->tpc + 4 + ((((call | 0xFFFFFFFFC0000000UL) ^ 0x20000000UL) + 0x20000000UL) << 2);
6961+
6962+ if (test_thread_flag(TIF_32BIT))
6963+ addr &= 0xFFFFFFFFUL;
6964+
6965+ regs->tpc = addr;
6966+ regs->tnpc = addr+4;
6967+ return 2;
6968+ }
6969+ } while (0);
6970+
6971+ do { /* PaX: patched PLT emulation #5 */
6972+ unsigned int sethi, sethi1, sethi2, or1, or2, sllx, jmpl, nop;
6973+
6974+ err = get_user(sethi, (unsigned int *)regs->tpc);
6975+ err |= get_user(sethi1, (unsigned int *)(regs->tpc+4));
6976+ err |= get_user(sethi2, (unsigned int *)(regs->tpc+8));
6977+ err |= get_user(or1, (unsigned int *)(regs->tpc+12));
6978+ err |= get_user(or2, (unsigned int *)(regs->tpc+16));
6979+ err |= get_user(sllx, (unsigned int *)(regs->tpc+20));
6980+ err |= get_user(jmpl, (unsigned int *)(regs->tpc+24));
6981+ err |= get_user(nop, (unsigned int *)(regs->tpc+28));
6982+
6983+ if (err)
6984+ break;
6985+
6986+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
6987+ (sethi1 & 0xFFC00000U) == 0x03000000U &&
6988+ (sethi2 & 0xFFC00000U) == 0x0B000000U &&
6989+ (or1 & 0xFFFFE000U) == 0x82106000U &&
6990+ (or2 & 0xFFFFE000U) == 0x8A116000U &&
6991+ sllx == 0x83287020U &&
6992+ jmpl == 0x81C04005U &&
6993+ nop == 0x01000000U)
6994+ {
6995+ unsigned long addr;
6996+
6997+ regs->u_regs[UREG_G1] = ((sethi1 & 0x003FFFFFU) << 10) | (or1 & 0x000003FFU);
6998+ regs->u_regs[UREG_G1] <<= 32;
6999+ regs->u_regs[UREG_G5] = ((sethi2 & 0x003FFFFFU) << 10) | (or2 & 0x000003FFU);
7000+ addr = regs->u_regs[UREG_G1] + regs->u_regs[UREG_G5];
7001+ regs->tpc = addr;
7002+ regs->tnpc = addr+4;
7003+ return 2;
7004+ }
7005+ } while (0);
7006+
7007+ do { /* PaX: patched PLT emulation #6 */
7008+ unsigned int sethi, sethi1, sethi2, sllx, or, jmpl, nop;
7009+
7010+ err = get_user(sethi, (unsigned int *)regs->tpc);
7011+ err |= get_user(sethi1, (unsigned int *)(regs->tpc+4));
7012+ err |= get_user(sethi2, (unsigned int *)(regs->tpc+8));
7013+ err |= get_user(sllx, (unsigned int *)(regs->tpc+12));
7014+ err |= get_user(or, (unsigned int *)(regs->tpc+16));
7015+ err |= get_user(jmpl, (unsigned int *)(regs->tpc+20));
7016+ err |= get_user(nop, (unsigned int *)(regs->tpc+24));
7017+
7018+ if (err)
7019+ break;
7020+
7021+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
7022+ (sethi1 & 0xFFC00000U) == 0x03000000U &&
7023+ (sethi2 & 0xFFC00000U) == 0x0B000000U &&
7024+ sllx == 0x83287020U &&
7025+ (or & 0xFFFFE000U) == 0x8A116000U &&
7026+ jmpl == 0x81C04005U &&
7027+ nop == 0x01000000U)
7028+ {
7029+ unsigned long addr;
7030+
7031+ regs->u_regs[UREG_G1] = (sethi1 & 0x003FFFFFU) << 10;
7032+ regs->u_regs[UREG_G1] <<= 32;
7033+ regs->u_regs[UREG_G5] = ((sethi2 & 0x003FFFFFU) << 10) | (or & 0x3FFU);
7034+ addr = regs->u_regs[UREG_G1] + regs->u_regs[UREG_G5];
7035+ regs->tpc = addr;
7036+ regs->tnpc = addr+4;
7037+ return 2;
7038+ }
7039+ } while (0);
7040+
7041+ do { /* PaX: unpatched PLT emulation step 1 */
7042+ unsigned int sethi, ba, nop;
7043+
7044+ err = get_user(sethi, (unsigned int *)regs->tpc);
7045+ err |= get_user(ba, (unsigned int *)(regs->tpc+4));
7046+ err |= get_user(nop, (unsigned int *)(regs->tpc+8));
7047+
7048+ if (err)
7049+ break;
7050+
7051+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
7052+ ((ba & 0xFFC00000U) == 0x30800000U || (ba & 0xFFF80000U) == 0x30680000U) &&
7053+ nop == 0x01000000U)
7054+ {
7055+ unsigned long addr;
7056+ unsigned int save, call;
7057+ unsigned int sethi1, sethi2, or1, or2, sllx, add, jmpl;
7058+
7059+ if ((ba & 0xFFC00000U) == 0x30800000U)
7060+ addr = regs->tpc + 4 + ((((ba | 0xFFFFFFFFFFC00000UL) ^ 0x00200000UL) + 0x00200000UL) << 2);
7061+ else
7062+ addr = regs->tpc + 4 + ((((ba | 0xFFFFFFFFFFF80000UL) ^ 0x00040000UL) + 0x00040000UL) << 2);
7063+
7064+ if (test_thread_flag(TIF_32BIT))
7065+ addr &= 0xFFFFFFFFUL;
7066+
7067+ err = get_user(save, (unsigned int *)addr);
7068+ err |= get_user(call, (unsigned int *)(addr+4));
7069+ err |= get_user(nop, (unsigned int *)(addr+8));
7070+ if (err)
7071+ break;
7072+
7073+#ifdef CONFIG_PAX_DLRESOLVE
7074+ if (save == 0x9DE3BFA8U &&
7075+ (call & 0xC0000000U) == 0x40000000U &&
7076+ nop == 0x01000000U)
7077+ {
7078+ struct vm_area_struct *vma;
7079+ unsigned long call_dl_resolve;
7080+
7081+ down_read(&current->mm->mmap_sem);
7082+ call_dl_resolve = current->mm->call_dl_resolve;
7083+ up_read(&current->mm->mmap_sem);
7084+ if (likely(call_dl_resolve))
7085+ goto emulate;
7086+
7087+ vma = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
7088+
7089+ down_write(&current->mm->mmap_sem);
7090+ if (current->mm->call_dl_resolve) {
7091+ call_dl_resolve = current->mm->call_dl_resolve;
7092+ up_write(&current->mm->mmap_sem);
7093+ if (vma)
7094+ kmem_cache_free(vm_area_cachep, vma);
7095+ goto emulate;
7096+ }
7097+
7098+ call_dl_resolve = get_unmapped_area(NULL, 0UL, PAGE_SIZE, 0UL, MAP_PRIVATE);
7099+ if (!vma || (call_dl_resolve & ~PAGE_MASK)) {
7100+ up_write(&current->mm->mmap_sem);
7101+ if (vma)
7102+ kmem_cache_free(vm_area_cachep, vma);
7103+ return 1;
7104+ }
7105+
7106+ if (pax_insert_vma(vma, call_dl_resolve)) {
7107+ up_write(&current->mm->mmap_sem);
7108+ kmem_cache_free(vm_area_cachep, vma);
7109+ return 1;
7110+ }
7111+
7112+ current->mm->call_dl_resolve = call_dl_resolve;
7113+ up_write(&current->mm->mmap_sem);
7114+
7115+emulate:
7116+ regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
7117+ regs->tpc = call_dl_resolve;
7118+ regs->tnpc = addr+4;
7119+ return 3;
7120+ }
7121+#endif
7122+
7123+ /* PaX: glibc 2.4+ generates sethi/jmpl instead of save/call */
7124+ if ((save & 0xFFC00000U) == 0x05000000U &&
7125+ (call & 0xFFFFE000U) == 0x85C0A000U &&
7126+ nop == 0x01000000U)
7127+ {
7128+ regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
7129+ regs->u_regs[UREG_G2] = addr + 4;
7130+ addr = (save & 0x003FFFFFU) << 10;
7131+ addr += (((call | 0xFFFFFFFFFFFFE000UL) ^ 0x00001000UL) + 0x00001000UL);
7132+
7133+ if (test_thread_flag(TIF_32BIT))
7134+ addr &= 0xFFFFFFFFUL;
7135+
7136+ regs->tpc = addr;
7137+ regs->tnpc = addr+4;
7138+ return 3;
7139+ }
7140+
7141+ /* PaX: 64-bit PLT stub */
7142+ err = get_user(sethi1, (unsigned int *)addr);
7143+ err |= get_user(sethi2, (unsigned int *)(addr+4));
7144+ err |= get_user(or1, (unsigned int *)(addr+8));
7145+ err |= get_user(or2, (unsigned int *)(addr+12));
7146+ err |= get_user(sllx, (unsigned int *)(addr+16));
7147+ err |= get_user(add, (unsigned int *)(addr+20));
7148+ err |= get_user(jmpl, (unsigned int *)(addr+24));
7149+ err |= get_user(nop, (unsigned int *)(addr+28));
7150+ if (err)
7151+ break;
7152+
7153+ if ((sethi1 & 0xFFC00000U) == 0x09000000U &&
7154+ (sethi2 & 0xFFC00000U) == 0x0B000000U &&
7155+ (or1 & 0xFFFFE000U) == 0x88112000U &&
7156+ (or2 & 0xFFFFE000U) == 0x8A116000U &&
7157+ sllx == 0x89293020U &&
7158+ add == 0x8A010005U &&
7159+ jmpl == 0x89C14000U &&
7160+ nop == 0x01000000U)
7161+ {
7162+ regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
7163+ regs->u_regs[UREG_G4] = ((sethi1 & 0x003FFFFFU) << 10) | (or1 & 0x000003FFU);
7164+ regs->u_regs[UREG_G4] <<= 32;
7165+ regs->u_regs[UREG_G5] = ((sethi2 & 0x003FFFFFU) << 10) | (or2 & 0x000003FFU);
7166+ regs->u_regs[UREG_G5] += regs->u_regs[UREG_G4];
7167+ regs->u_regs[UREG_G4] = addr + 24;
7168+ addr = regs->u_regs[UREG_G5];
7169+ regs->tpc = addr;
7170+ regs->tnpc = addr+4;
7171+ return 3;
7172+ }
7173+ }
7174+ } while (0);
7175+
7176+#ifdef CONFIG_PAX_DLRESOLVE
7177+ do { /* PaX: unpatched PLT emulation step 2 */
7178+ unsigned int save, call, nop;
7179+
7180+ err = get_user(save, (unsigned int *)(regs->tpc-4));
7181+ err |= get_user(call, (unsigned int *)regs->tpc);
7182+ err |= get_user(nop, (unsigned int *)(regs->tpc+4));
7183+ if (err)
7184+ break;
7185+
7186+ if (save == 0x9DE3BFA8U &&
7187+ (call & 0xC0000000U) == 0x40000000U &&
7188+ nop == 0x01000000U)
7189+ {
7190+ unsigned long dl_resolve = regs->tpc + ((((call | 0xFFFFFFFFC0000000UL) ^ 0x20000000UL) + 0x20000000UL) << 2);
7191+
7192+ if (test_thread_flag(TIF_32BIT))
7193+ dl_resolve &= 0xFFFFFFFFUL;
7194+
7195+ regs->u_regs[UREG_RETPC] = regs->tpc;
7196+ regs->tpc = dl_resolve;
7197+ regs->tnpc = dl_resolve+4;
7198+ return 3;
7199+ }
7200+ } while (0);
7201+#endif
7202+
7203+ do { /* PaX: patched PLT emulation #7, must be AFTER the unpatched PLT emulation */
7204+ unsigned int sethi, ba, nop;
7205+
7206+ err = get_user(sethi, (unsigned int *)regs->tpc);
7207+ err |= get_user(ba, (unsigned int *)(regs->tpc+4));
7208+ err |= get_user(nop, (unsigned int *)(regs->tpc+8));
7209+
7210+ if (err)
7211+ break;
7212+
7213+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
7214+ (ba & 0xFFF00000U) == 0x30600000U &&
7215+ nop == 0x01000000U)
7216+ {
7217+ unsigned long addr;
7218+
7219+ addr = (sethi & 0x003FFFFFU) << 10;
7220+ regs->u_regs[UREG_G1] = addr;
7221+ addr = regs->tpc + ((((ba | 0xFFFFFFFFFFF80000UL) ^ 0x00040000UL) + 0x00040000UL) << 2);
7222+
7223+ if (test_thread_flag(TIF_32BIT))
7224+ addr &= 0xFFFFFFFFUL;
7225+
7226+ regs->tpc = addr;
7227+ regs->tnpc = addr+4;
7228+ return 2;
7229+ }
7230+ } while (0);
7231+
7232+#endif
7233+
7234+ return 1;
7235+}
7236+
7237+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
7238+{
7239+ unsigned long i;
7240+
7241+ printk(KERN_ERR "PAX: bytes at PC: ");
7242+ for (i = 0; i < 8; i++) {
7243+ unsigned int c;
7244+ if (get_user(c, (unsigned int *)pc+i))
7245+ printk(KERN_CONT "???????? ");
7246+ else
7247+ printk(KERN_CONT "%08x ", c);
7248+ }
7249+ printk("\n");
7250+}
7251+#endif
7252+
7253 asmlinkage void __kprobes do_sparc64_fault(struct pt_regs *regs)
7254 {
7255 struct mm_struct *mm = current->mm;
7256@@ -343,6 +806,29 @@ retry:
7257 if (!vma)
7258 goto bad_area;
7259
7260+#ifdef CONFIG_PAX_PAGEEXEC
7261+ /* PaX: detect ITLB misses on non-exec pages */
7262+ if ((mm->pax_flags & MF_PAX_PAGEEXEC) && vma->vm_start <= address &&
7263+ !(vma->vm_flags & VM_EXEC) && (fault_code & FAULT_CODE_ITLB))
7264+ {
7265+ if (address != regs->tpc)
7266+ goto good_area;
7267+
7268+ up_read(&mm->mmap_sem);
7269+ switch (pax_handle_fetch_fault(regs)) {
7270+
7271+#ifdef CONFIG_PAX_EMUPLT
7272+ case 2:
7273+ case 3:
7274+ return;
7275+#endif
7276+
7277+ }
7278+ pax_report_fault(regs, (void *)regs->tpc, (void *)(regs->u_regs[UREG_FP] + STACK_BIAS));
7279+ do_group_exit(SIGKILL);
7280+ }
7281+#endif
7282+
7283 /* Pure DTLB misses do not tell us whether the fault causing
7284 * load/store/atomic was a write or not, it only says that there
7285 * was no match. So in such a case we (carefully) read the
7286diff --git a/arch/sparc/mm/hugetlbpage.c b/arch/sparc/mm/hugetlbpage.c
7287index 07e1453..0a7d9e9 100644
7288--- a/arch/sparc/mm/hugetlbpage.c
7289+++ b/arch/sparc/mm/hugetlbpage.c
7290@@ -67,7 +67,7 @@ full_search:
7291 }
7292 return -ENOMEM;
7293 }
7294- if (likely(!vma || addr + len <= vma->vm_start)) {
7295+ if (likely(check_heap_stack_gap(vma, addr, len))) {
7296 /*
7297 * Remember the place where we stopped the search:
7298 */
7299@@ -106,7 +106,7 @@ hugetlb_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
7300 /* make sure it can fit in the remaining address space */
7301 if (likely(addr > len)) {
7302 vma = find_vma(mm, addr-len);
7303- if (!vma || addr <= vma->vm_start) {
7304+ if (check_heap_stack_gap(vma, addr - len, len)) {
7305 /* remember the address as a hint for next time */
7306 return (mm->free_area_cache = addr-len);
7307 }
7308@@ -115,16 +115,17 @@ hugetlb_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
7309 if (unlikely(mm->mmap_base < len))
7310 goto bottomup;
7311
7312- addr = (mm->mmap_base-len) & HPAGE_MASK;
7313+ addr = mm->mmap_base - len;
7314
7315 do {
7316+ addr &= HPAGE_MASK;
7317 /*
7318 * Lookup failure means no vma is above this address,
7319 * else if new region fits below vma->vm_start,
7320 * return with success:
7321 */
7322 vma = find_vma(mm, addr);
7323- if (likely(!vma || addr+len <= vma->vm_start)) {
7324+ if (likely(check_heap_stack_gap(vma, addr, len))) {
7325 /* remember the address as a hint for next time */
7326 return (mm->free_area_cache = addr);
7327 }
7328@@ -134,8 +135,8 @@ hugetlb_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
7329 mm->cached_hole_size = vma->vm_start - addr;
7330
7331 /* try just below the current vma->vm_start */
7332- addr = (vma->vm_start-len) & HPAGE_MASK;
7333- } while (likely(len < vma->vm_start));
7334+ addr = skip_heap_stack_gap(vma, len);
7335+ } while (!IS_ERR_VALUE(addr));
7336
7337 bottomup:
7338 /*
7339@@ -181,8 +182,7 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
7340 if (addr) {
7341 addr = ALIGN(addr, HPAGE_SIZE);
7342 vma = find_vma(mm, addr);
7343- if (task_size - len >= addr &&
7344- (!vma || addr + len <= vma->vm_start))
7345+ if (task_size - len >= addr && check_heap_stack_gap(vma, addr, len))
7346 return addr;
7347 }
7348 if (mm->get_unmapped_area == arch_get_unmapped_area)
7349diff --git a/arch/tile/include/asm/atomic_64.h b/arch/tile/include/asm/atomic_64.h
7350index f4500c6..889656c 100644
7351--- a/arch/tile/include/asm/atomic_64.h
7352+++ b/arch/tile/include/asm/atomic_64.h
7353@@ -143,6 +143,16 @@ static inline long atomic64_add_unless(atomic64_t *v, long a, long u)
7354
7355 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
7356
7357+#define atomic64_read_unchecked(v) atomic64_read(v)
7358+#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
7359+#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
7360+#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
7361+#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
7362+#define atomic64_inc_unchecked(v) atomic64_inc(v)
7363+#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
7364+#define atomic64_dec_unchecked(v) atomic64_dec(v)
7365+#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
7366+
7367 /* Atomic dec and inc don't implement barrier, so provide them if needed. */
7368 #define smp_mb__before_atomic_dec() smp_mb()
7369 #define smp_mb__after_atomic_dec() smp_mb()
7370diff --git a/arch/tile/include/asm/cache.h b/arch/tile/include/asm/cache.h
7371index a9a5299..0fce79e 100644
7372--- a/arch/tile/include/asm/cache.h
7373+++ b/arch/tile/include/asm/cache.h
7374@@ -15,11 +15,12 @@
7375 #ifndef _ASM_TILE_CACHE_H
7376 #define _ASM_TILE_CACHE_H
7377
7378+#include <linux/const.h>
7379 #include <arch/chip.h>
7380
7381 /* bytes per L1 data cache line */
7382 #define L1_CACHE_SHIFT CHIP_L1D_LOG_LINE_SIZE()
7383-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
7384+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
7385
7386 /* bytes per L2 cache line */
7387 #define L2_CACHE_SHIFT CHIP_L2_LOG_LINE_SIZE()
7388diff --git a/arch/tile/include/asm/uaccess.h b/arch/tile/include/asm/uaccess.h
7389index 9ab078a..d6635c2 100644
7390--- a/arch/tile/include/asm/uaccess.h
7391+++ b/arch/tile/include/asm/uaccess.h
7392@@ -403,9 +403,9 @@ static inline unsigned long __must_check copy_from_user(void *to,
7393 const void __user *from,
7394 unsigned long n)
7395 {
7396- int sz = __compiletime_object_size(to);
7397+ size_t sz = __compiletime_object_size(to);
7398
7399- if (likely(sz == -1 || sz >= n))
7400+ if (likely(sz == (size_t)-1 || sz >= n))
7401 n = _copy_from_user(to, from, n);
7402 else
7403 copy_from_user_overflow();
7404diff --git a/arch/um/Makefile b/arch/um/Makefile
7405index 0970910..9f65c40 100644
7406--- a/arch/um/Makefile
7407+++ b/arch/um/Makefile
7408@@ -62,6 +62,10 @@ USER_CFLAGS = $(patsubst $(KERNEL_DEFINES),,$(patsubst -D__KERNEL__,,\
7409 $(patsubst -I%,,$(KBUILD_CFLAGS)))) $(ARCH_INCLUDE) $(MODE_INCLUDE) \
7410 $(filter -I%,$(CFLAGS)) -D_FILE_OFFSET_BITS=64 -idirafter include
7411
7412+ifdef CONSTIFY_PLUGIN
7413+USER_CFLAGS += -fplugin-arg-constify_plugin-no-constify
7414+endif
7415+
7416 #This will adjust *FLAGS accordingly to the platform.
7417 include $(srctree)/$(ARCH_DIR)/Makefile-os-$(OS)
7418
7419diff --git a/arch/um/include/asm/cache.h b/arch/um/include/asm/cache.h
7420index 19e1bdd..3665b77 100644
7421--- a/arch/um/include/asm/cache.h
7422+++ b/arch/um/include/asm/cache.h
7423@@ -1,6 +1,7 @@
7424 #ifndef __UM_CACHE_H
7425 #define __UM_CACHE_H
7426
7427+#include <linux/const.h>
7428
7429 #if defined(CONFIG_UML_X86) && !defined(CONFIG_64BIT)
7430 # define L1_CACHE_SHIFT (CONFIG_X86_L1_CACHE_SHIFT)
7431@@ -12,6 +13,6 @@
7432 # define L1_CACHE_SHIFT 5
7433 #endif
7434
7435-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
7436+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
7437
7438 #endif
7439diff --git a/arch/um/include/asm/kmap_types.h b/arch/um/include/asm/kmap_types.h
7440index 2e0a6b1..a64d0f5 100644
7441--- a/arch/um/include/asm/kmap_types.h
7442+++ b/arch/um/include/asm/kmap_types.h
7443@@ -8,6 +8,6 @@
7444
7445 /* No more #include "asm/arch/kmap_types.h" ! */
7446
7447-#define KM_TYPE_NR 14
7448+#define KM_TYPE_NR 15
7449
7450 #endif
7451diff --git a/arch/um/include/asm/page.h b/arch/um/include/asm/page.h
7452index 7cfc3ce..cbd1a58 100644
7453--- a/arch/um/include/asm/page.h
7454+++ b/arch/um/include/asm/page.h
7455@@ -14,6 +14,9 @@
7456 #define PAGE_SIZE (_AC(1, UL) << PAGE_SHIFT)
7457 #define PAGE_MASK (~(PAGE_SIZE-1))
7458
7459+#define ktla_ktva(addr) (addr)
7460+#define ktva_ktla(addr) (addr)
7461+
7462 #ifndef __ASSEMBLY__
7463
7464 struct page;
7465diff --git a/arch/um/include/asm/pgtable-3level.h b/arch/um/include/asm/pgtable-3level.h
7466index 0032f92..cd151e0 100644
7467--- a/arch/um/include/asm/pgtable-3level.h
7468+++ b/arch/um/include/asm/pgtable-3level.h
7469@@ -58,6 +58,7 @@
7470 #define pud_present(x) (pud_val(x) & _PAGE_PRESENT)
7471 #define pud_populate(mm, pud, pmd) \
7472 set_pud(pud, __pud(_PAGE_TABLE + __pa(pmd)))
7473+#define pud_populate_kernel(mm, pud, pmd) pud_populate((mm), (pud), (pmd))
7474
7475 #ifdef CONFIG_64BIT
7476 #define set_pud(pudptr, pudval) set_64bit((u64 *) (pudptr), pud_val(pudval))
7477diff --git a/arch/um/kernel/process.c b/arch/um/kernel/process.c
7478index c5f5afa..6abce4b 100644
7479--- a/arch/um/kernel/process.c
7480+++ b/arch/um/kernel/process.c
7481@@ -402,22 +402,6 @@ int singlestepping(void * t)
7482 return 2;
7483 }
7484
7485-/*
7486- * Only x86 and x86_64 have an arch_align_stack().
7487- * All other arches have "#define arch_align_stack(x) (x)"
7488- * in their asm/system.h
7489- * As this is included in UML from asm-um/system-generic.h,
7490- * we can use it to behave as the subarch does.
7491- */
7492-#ifndef arch_align_stack
7493-unsigned long arch_align_stack(unsigned long sp)
7494-{
7495- if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
7496- sp -= get_random_int() % 8192;
7497- return sp & ~0xf;
7498-}
7499-#endif
7500-
7501 unsigned long get_wchan(struct task_struct *p)
7502 {
7503 unsigned long stack_page, sp, ip;
7504diff --git a/arch/unicore32/include/asm/cache.h b/arch/unicore32/include/asm/cache.h
7505index ad8f795..2c7eec6 100644
7506--- a/arch/unicore32/include/asm/cache.h
7507+++ b/arch/unicore32/include/asm/cache.h
7508@@ -12,8 +12,10 @@
7509 #ifndef __UNICORE_CACHE_H__
7510 #define __UNICORE_CACHE_H__
7511
7512-#define L1_CACHE_SHIFT (5)
7513-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
7514+#include <linux/const.h>
7515+
7516+#define L1_CACHE_SHIFT 5
7517+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
7518
7519 /*
7520 * Memory returned by kmalloc() may be used for DMA, so we must make
7521diff --git a/arch/x86/Kconfig b/arch/x86/Kconfig
7522index 50a1d1f..c26369f 100644
7523--- a/arch/x86/Kconfig
7524+++ b/arch/x86/Kconfig
7525@@ -220,7 +220,7 @@ config X86_HT
7526
7527 config X86_32_LAZY_GS
7528 def_bool y
7529- depends on X86_32 && !CC_STACKPROTECTOR
7530+ depends on X86_32 && !CC_STACKPROTECTOR && !PAX_MEMORY_UDEREF
7531
7532 config ARCH_HWEIGHT_CFLAGS
7533 string
7534@@ -1049,7 +1049,7 @@ choice
7535
7536 config NOHIGHMEM
7537 bool "off"
7538- depends on !X86_NUMAQ
7539+ depends on !X86_NUMAQ && !(PAX_PAGEEXEC && PAX_ENABLE_PAE)
7540 ---help---
7541 Linux can use up to 64 Gigabytes of physical memory on x86 systems.
7542 However, the address space of 32-bit x86 processors is only 4
7543@@ -1086,7 +1086,7 @@ config NOHIGHMEM
7544
7545 config HIGHMEM4G
7546 bool "4GB"
7547- depends on !X86_NUMAQ
7548+ depends on !X86_NUMAQ && !(PAX_PAGEEXEC && PAX_ENABLE_PAE)
7549 ---help---
7550 Select this if you have a 32-bit processor and between 1 and 4
7551 gigabytes of physical RAM.
7552@@ -1140,7 +1140,7 @@ config PAGE_OFFSET
7553 hex
7554 default 0xB0000000 if VMSPLIT_3G_OPT
7555 default 0x80000000 if VMSPLIT_2G
7556- default 0x78000000 if VMSPLIT_2G_OPT
7557+ default 0x70000000 if VMSPLIT_2G_OPT
7558 default 0x40000000 if VMSPLIT_1G
7559 default 0xC0000000
7560 depends on X86_32
7561@@ -1528,6 +1528,7 @@ config SECCOMP
7562
7563 config CC_STACKPROTECTOR
7564 bool "Enable -fstack-protector buffer overflow detection"
7565+ depends on X86_64 || !PAX_MEMORY_UDEREF
7566 ---help---
7567 This option turns on the -fstack-protector GCC feature. This
7568 feature puts, at the beginning of functions, a canary value on
7569@@ -1585,6 +1586,7 @@ config KEXEC_JUMP
7570 config PHYSICAL_START
7571 hex "Physical address where the kernel is loaded" if (EXPERT || CRASH_DUMP)
7572 default "0x1000000"
7573+ range 0x400000 0x40000000
7574 ---help---
7575 This gives the physical address where the kernel is loaded.
7576
7577@@ -1648,6 +1650,7 @@ config X86_NEED_RELOCS
7578 config PHYSICAL_ALIGN
7579 hex "Alignment value to which kernel should be aligned" if X86_32
7580 default "0x1000000"
7581+ range 0x400000 0x1000000 if PAX_KERNEXEC
7582 range 0x2000 0x1000000
7583 ---help---
7584 This value puts the alignment restrictions on physical address
7585@@ -1679,9 +1682,10 @@ config HOTPLUG_CPU
7586 Say N if you want to disable CPU hotplug.
7587
7588 config COMPAT_VDSO
7589- def_bool y
7590+ def_bool n
7591 prompt "Compat VDSO support"
7592 depends on X86_32 || IA32_EMULATION
7593+ depends on !PAX_NOEXEC && !PAX_MEMORY_UDEREF
7594 ---help---
7595 Map the 32-bit VDSO to the predictable old-style address too.
7596
7597diff --git a/arch/x86/Kconfig.cpu b/arch/x86/Kconfig.cpu
7598index 706e12e..62e4feb 100644
7599--- a/arch/x86/Kconfig.cpu
7600+++ b/arch/x86/Kconfig.cpu
7601@@ -334,7 +334,7 @@ config X86_PPRO_FENCE
7602
7603 config X86_F00F_BUG
7604 def_bool y
7605- depends on M586MMX || M586TSC || M586 || M486 || M386
7606+ depends on (M586MMX || M586TSC || M586 || M486 || M386) && !PAX_KERNEXEC
7607
7608 config X86_INVD_BUG
7609 def_bool y
7610@@ -358,7 +358,7 @@ config X86_POPAD_OK
7611
7612 config X86_ALIGNMENT_16
7613 def_bool y
7614- depends on MWINCHIP3D || MWINCHIPC6 || MCYRIXIII || MELAN || MK6 || M586MMX || M586TSC || M586 || M486 || MVIAC3_2 || MGEODEGX1
7615+ depends on MWINCHIP3D || MWINCHIPC6 || MCYRIXIII || X86_ELAN || MK8 || MK7 || MK6 || MCORE2 || MPENTIUM4 || MPENTIUMIII || MPENTIUMII || M686 || M586MMX || M586TSC || M586 || M486 || MVIAC3_2 || MGEODEGX1
7616
7617 config X86_INTEL_USERCOPY
7618 def_bool y
7619@@ -404,7 +404,7 @@ config X86_CMPXCHG64
7620 # generates cmov.
7621 config X86_CMOV
7622 def_bool y
7623- depends on (MK8 || MK7 || MCORE2 || MPENTIUM4 || MPENTIUMM || MPENTIUMIII || MPENTIUMII || M686 || MVIAC3_2 || MVIAC7 || MCRUSOE || MEFFICEON || X86_64 || MATOM || MGEODE_LX)
7624+ depends on (MK8 || MK7 || MCORE2 || MPSC || MPENTIUM4 || MPENTIUMM || MPENTIUMIII || MPENTIUMII || M686 || MVIAC3_2 || MVIAC7 || MCRUSOE || MEFFICEON || X86_64 || MATOM || MGEODE_LX)
7625
7626 config X86_MINIMUM_CPU_FAMILY
7627 int
7628diff --git a/arch/x86/Kconfig.debug b/arch/x86/Kconfig.debug
7629index b322f12..652d0d9 100644
7630--- a/arch/x86/Kconfig.debug
7631+++ b/arch/x86/Kconfig.debug
7632@@ -84,7 +84,7 @@ config X86_PTDUMP
7633 config DEBUG_RODATA
7634 bool "Write protect kernel read-only data structures"
7635 default y
7636- depends on DEBUG_KERNEL
7637+ depends on DEBUG_KERNEL && BROKEN
7638 ---help---
7639 Mark the kernel read-only data as write-protected in the pagetables,
7640 in order to catch accidental (and incorrect) writes to such const
7641@@ -102,7 +102,7 @@ config DEBUG_RODATA_TEST
7642
7643 config DEBUG_SET_MODULE_RONX
7644 bool "Set loadable kernel module data as NX and text as RO"
7645- depends on MODULES
7646+ depends on MODULES && BROKEN
7647 ---help---
7648 This option helps catch unintended modifications to loadable
7649 kernel module's text and read-only data. It also prevents execution
7650@@ -294,7 +294,7 @@ config OPTIMIZE_INLINING
7651
7652 config DEBUG_STRICT_USER_COPY_CHECKS
7653 bool "Strict copy size checks"
7654- depends on DEBUG_KERNEL && !TRACE_BRANCH_PROFILING
7655+ depends on DEBUG_KERNEL && !TRACE_BRANCH_PROFILING && !PAX_SIZE_OVERFLOW
7656 ---help---
7657 Enabling this option turns a certain set of sanity checks for user
7658 copy operations into compile time failures.
7659diff --git a/arch/x86/Makefile b/arch/x86/Makefile
7660index 05afcca..b6ecb51 100644
7661--- a/arch/x86/Makefile
7662+++ b/arch/x86/Makefile
7663@@ -50,6 +50,7 @@ else
7664 UTS_MACHINE := x86_64
7665 CHECKFLAGS += -D__x86_64__ -m64
7666
7667+ biarch := $(call cc-option,-m64)
7668 KBUILD_AFLAGS += -m64
7669 KBUILD_CFLAGS += -m64
7670
7671@@ -229,3 +230,12 @@ define archhelp
7672 echo ' FDARGS="..." arguments for the booted kernel'
7673 echo ' FDINITRD=file initrd for the booted kernel'
7674 endef
7675+
7676+define OLD_LD
7677+
7678+*** ${VERSION}.${PATCHLEVEL} PaX kernels no longer build correctly with old versions of binutils.
7679+*** Please upgrade your binutils to 2.18 or newer
7680+endef
7681+
7682+archprepare:
7683+ $(if $(LDFLAGS_BUILD_ID),,$(error $(OLD_LD)))
7684diff --git a/arch/x86/boot/Makefile b/arch/x86/boot/Makefile
7685index f7535be..37db2d1 100644
7686--- a/arch/x86/boot/Makefile
7687+++ b/arch/x86/boot/Makefile
7688@@ -64,6 +64,9 @@ KBUILD_CFLAGS := $(LINUXINCLUDE) -g -Os -D_SETUP -D__KERNEL__ \
7689 $(call cc-option, -fno-stack-protector) \
7690 $(call cc-option, -mpreferred-stack-boundary=2)
7691 KBUILD_CFLAGS += $(call cc-option, -m32)
7692+ifdef CONSTIFY_PLUGIN
7693+KBUILD_CFLAGS += -fplugin-arg-constify_plugin-no-constify
7694+endif
7695 KBUILD_AFLAGS := $(KBUILD_CFLAGS) -D__ASSEMBLY__
7696 GCOV_PROFILE := n
7697
7698diff --git a/arch/x86/boot/bitops.h b/arch/x86/boot/bitops.h
7699index 878e4b9..20537ab 100644
7700--- a/arch/x86/boot/bitops.h
7701+++ b/arch/x86/boot/bitops.h
7702@@ -26,7 +26,7 @@ static inline int variable_test_bit(int nr, const void *addr)
7703 u8 v;
7704 const u32 *p = (const u32 *)addr;
7705
7706- asm("btl %2,%1; setc %0" : "=qm" (v) : "m" (*p), "Ir" (nr));
7707+ asm volatile("btl %2,%1; setc %0" : "=qm" (v) : "m" (*p), "Ir" (nr));
7708 return v;
7709 }
7710
7711@@ -37,7 +37,7 @@ static inline int variable_test_bit(int nr, const void *addr)
7712
7713 static inline void set_bit(int nr, void *addr)
7714 {
7715- asm("btsl %1,%0" : "+m" (*(u32 *)addr) : "Ir" (nr));
7716+ asm volatile("btsl %1,%0" : "+m" (*(u32 *)addr) : "Ir" (nr));
7717 }
7718
7719 #endif /* BOOT_BITOPS_H */
7720diff --git a/arch/x86/boot/boot.h b/arch/x86/boot/boot.h
7721index 18997e5..83d9c67 100644
7722--- a/arch/x86/boot/boot.h
7723+++ b/arch/x86/boot/boot.h
7724@@ -85,7 +85,7 @@ static inline void io_delay(void)
7725 static inline u16 ds(void)
7726 {
7727 u16 seg;
7728- asm("movw %%ds,%0" : "=rm" (seg));
7729+ asm volatile("movw %%ds,%0" : "=rm" (seg));
7730 return seg;
7731 }
7732
7733@@ -181,7 +181,7 @@ static inline void wrgs32(u32 v, addr_t addr)
7734 static inline int memcmp(const void *s1, const void *s2, size_t len)
7735 {
7736 u8 diff;
7737- asm("repe; cmpsb; setnz %0"
7738+ asm volatile("repe; cmpsb; setnz %0"
7739 : "=qm" (diff), "+D" (s1), "+S" (s2), "+c" (len));
7740 return diff;
7741 }
7742diff --git a/arch/x86/boot/compressed/Makefile b/arch/x86/boot/compressed/Makefile
7743index 8a84501..b2d165f 100644
7744--- a/arch/x86/boot/compressed/Makefile
7745+++ b/arch/x86/boot/compressed/Makefile
7746@@ -14,6 +14,9 @@ cflags-$(CONFIG_X86_64) := -mcmodel=small
7747 KBUILD_CFLAGS += $(cflags-y)
7748 KBUILD_CFLAGS += $(call cc-option,-ffreestanding)
7749 KBUILD_CFLAGS += $(call cc-option,-fno-stack-protector)
7750+ifdef CONSTIFY_PLUGIN
7751+KBUILD_CFLAGS += -fplugin-arg-constify_plugin-no-constify
7752+endif
7753
7754 KBUILD_AFLAGS := $(KBUILD_CFLAGS) -D__ASSEMBLY__
7755 GCOV_PROFILE := n
7756diff --git a/arch/x86/boot/compressed/eboot.c b/arch/x86/boot/compressed/eboot.c
7757index b3e0227..f2c02d5 100644
7758--- a/arch/x86/boot/compressed/eboot.c
7759+++ b/arch/x86/boot/compressed/eboot.c
7760@@ -142,7 +142,6 @@ again:
7761 *addr = max_addr;
7762 }
7763
7764-free_pool:
7765 efi_call_phys1(sys_table->boottime->free_pool, map);
7766
7767 fail:
7768@@ -206,7 +205,6 @@ static efi_status_t low_alloc(unsigned long size, unsigned long align,
7769 if (i == map_size / desc_size)
7770 status = EFI_NOT_FOUND;
7771
7772-free_pool:
7773 efi_call_phys1(sys_table->boottime->free_pool, map);
7774 fail:
7775 return status;
7776diff --git a/arch/x86/boot/compressed/head_32.S b/arch/x86/boot/compressed/head_32.S
7777index aa4aaf1..6656f2f 100644
7778--- a/arch/x86/boot/compressed/head_32.S
7779+++ b/arch/x86/boot/compressed/head_32.S
7780@@ -116,7 +116,7 @@ preferred_addr:
7781 notl %eax
7782 andl %eax, %ebx
7783 #else
7784- movl $LOAD_PHYSICAL_ADDR, %ebx
7785+ movl $____LOAD_PHYSICAL_ADDR, %ebx
7786 #endif
7787
7788 /* Target address to relocate to for decompression */
7789@@ -202,7 +202,7 @@ relocated:
7790 * and where it was actually loaded.
7791 */
7792 movl %ebp, %ebx
7793- subl $LOAD_PHYSICAL_ADDR, %ebx
7794+ subl $____LOAD_PHYSICAL_ADDR, %ebx
7795 jz 2f /* Nothing to be done if loaded at compiled addr. */
7796 /*
7797 * Process relocations.
7798@@ -210,8 +210,7 @@ relocated:
7799
7800 1: subl $4, %edi
7801 movl (%edi), %ecx
7802- testl %ecx, %ecx
7803- jz 2f
7804+ jecxz 2f
7805 addl %ebx, -__PAGE_OFFSET(%ebx, %ecx)
7806 jmp 1b
7807 2:
7808diff --git a/arch/x86/boot/compressed/head_64.S b/arch/x86/boot/compressed/head_64.S
7809index 2c4b171..e1fa5b1 100644
7810--- a/arch/x86/boot/compressed/head_64.S
7811+++ b/arch/x86/boot/compressed/head_64.S
7812@@ -91,7 +91,7 @@ ENTRY(startup_32)
7813 notl %eax
7814 andl %eax, %ebx
7815 #else
7816- movl $LOAD_PHYSICAL_ADDR, %ebx
7817+ movl $____LOAD_PHYSICAL_ADDR, %ebx
7818 #endif
7819
7820 /* Target address to relocate to for decompression */
7821@@ -273,7 +273,7 @@ preferred_addr:
7822 notq %rax
7823 andq %rax, %rbp
7824 #else
7825- movq $LOAD_PHYSICAL_ADDR, %rbp
7826+ movq $____LOAD_PHYSICAL_ADDR, %rbp
7827 #endif
7828
7829 /* Target address to relocate to for decompression */
7830diff --git a/arch/x86/boot/compressed/misc.c b/arch/x86/boot/compressed/misc.c
7831index 88f7ff6..ed695dd 100644
7832--- a/arch/x86/boot/compressed/misc.c
7833+++ b/arch/x86/boot/compressed/misc.c
7834@@ -303,7 +303,7 @@ static void parse_elf(void *output)
7835 case PT_LOAD:
7836 #ifdef CONFIG_RELOCATABLE
7837 dest = output;
7838- dest += (phdr->p_paddr - LOAD_PHYSICAL_ADDR);
7839+ dest += (phdr->p_paddr - ____LOAD_PHYSICAL_ADDR);
7840 #else
7841 dest = (void *)(phdr->p_paddr);
7842 #endif
7843@@ -352,7 +352,7 @@ asmlinkage void decompress_kernel(void *rmode, memptr heap,
7844 error("Destination address too large");
7845 #endif
7846 #ifndef CONFIG_RELOCATABLE
7847- if ((unsigned long)output != LOAD_PHYSICAL_ADDR)
7848+ if ((unsigned long)output != ____LOAD_PHYSICAL_ADDR)
7849 error("Wrong destination address");
7850 #endif
7851
7852diff --git a/arch/x86/boot/cpucheck.c b/arch/x86/boot/cpucheck.c
7853index 4d3ff03..e4972ff 100644
7854--- a/arch/x86/boot/cpucheck.c
7855+++ b/arch/x86/boot/cpucheck.c
7856@@ -74,7 +74,7 @@ static int has_fpu(void)
7857 u16 fcw = -1, fsw = -1;
7858 u32 cr0;
7859
7860- asm("movl %%cr0,%0" : "=r" (cr0));
7861+ asm volatile("movl %%cr0,%0" : "=r" (cr0));
7862 if (cr0 & (X86_CR0_EM|X86_CR0_TS)) {
7863 cr0 &= ~(X86_CR0_EM|X86_CR0_TS);
7864 asm volatile("movl %0,%%cr0" : : "r" (cr0));
7865@@ -90,7 +90,7 @@ static int has_eflag(u32 mask)
7866 {
7867 u32 f0, f1;
7868
7869- asm("pushfl ; "
7870+ asm volatile("pushfl ; "
7871 "pushfl ; "
7872 "popl %0 ; "
7873 "movl %0,%1 ; "
7874@@ -115,7 +115,7 @@ static void get_flags(void)
7875 set_bit(X86_FEATURE_FPU, cpu.flags);
7876
7877 if (has_eflag(X86_EFLAGS_ID)) {
7878- asm("cpuid"
7879+ asm volatile("cpuid"
7880 : "=a" (max_intel_level),
7881 "=b" (cpu_vendor[0]),
7882 "=d" (cpu_vendor[1]),
7883@@ -124,7 +124,7 @@ static void get_flags(void)
7884
7885 if (max_intel_level >= 0x00000001 &&
7886 max_intel_level <= 0x0000ffff) {
7887- asm("cpuid"
7888+ asm volatile("cpuid"
7889 : "=a" (tfms),
7890 "=c" (cpu.flags[4]),
7891 "=d" (cpu.flags[0])
7892@@ -136,7 +136,7 @@ static void get_flags(void)
7893 cpu.model += ((tfms >> 16) & 0xf) << 4;
7894 }
7895
7896- asm("cpuid"
7897+ asm volatile("cpuid"
7898 : "=a" (max_amd_level)
7899 : "a" (0x80000000)
7900 : "ebx", "ecx", "edx");
7901@@ -144,7 +144,7 @@ static void get_flags(void)
7902 if (max_amd_level >= 0x80000001 &&
7903 max_amd_level <= 0x8000ffff) {
7904 u32 eax = 0x80000001;
7905- asm("cpuid"
7906+ asm volatile("cpuid"
7907 : "+a" (eax),
7908 "=c" (cpu.flags[6]),
7909 "=d" (cpu.flags[1])
7910@@ -203,9 +203,9 @@ int check_cpu(int *cpu_level_ptr, int *req_level_ptr, u32 **err_flags_ptr)
7911 u32 ecx = MSR_K7_HWCR;
7912 u32 eax, edx;
7913
7914- asm("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
7915+ asm volatile("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
7916 eax &= ~(1 << 15);
7917- asm("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
7918+ asm volatile("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
7919
7920 get_flags(); /* Make sure it really did something */
7921 err = check_flags();
7922@@ -218,9 +218,9 @@ int check_cpu(int *cpu_level_ptr, int *req_level_ptr, u32 **err_flags_ptr)
7923 u32 ecx = MSR_VIA_FCR;
7924 u32 eax, edx;
7925
7926- asm("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
7927+ asm volatile("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
7928 eax |= (1<<1)|(1<<7);
7929- asm("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
7930+ asm volatile("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
7931
7932 set_bit(X86_FEATURE_CX8, cpu.flags);
7933 err = check_flags();
7934@@ -231,12 +231,12 @@ int check_cpu(int *cpu_level_ptr, int *req_level_ptr, u32 **err_flags_ptr)
7935 u32 eax, edx;
7936 u32 level = 1;
7937
7938- asm("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
7939- asm("wrmsr" : : "a" (~0), "d" (edx), "c" (ecx));
7940- asm("cpuid"
7941+ asm volatile("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
7942+ asm volatile("wrmsr" : : "a" (~0), "d" (edx), "c" (ecx));
7943+ asm volatile("cpuid"
7944 : "+a" (level), "=d" (cpu.flags[0])
7945 : : "ecx", "ebx");
7946- asm("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
7947+ asm volatile("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
7948
7949 err = check_flags();
7950 }
7951diff --git a/arch/x86/boot/header.S b/arch/x86/boot/header.S
7952index b4e15dd..8ac59ce 100644
7953--- a/arch/x86/boot/header.S
7954+++ b/arch/x86/boot/header.S
7955@@ -391,10 +391,14 @@ setup_data: .quad 0 # 64-bit physical pointer to
7956 # single linked list of
7957 # struct setup_data
7958
7959-pref_address: .quad LOAD_PHYSICAL_ADDR # preferred load addr
7960+pref_address: .quad ____LOAD_PHYSICAL_ADDR # preferred load addr
7961
7962 #define ZO_INIT_SIZE (ZO__end - ZO_startup_32 + ZO_z_extract_offset)
7963+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
7964+#define VO_INIT_SIZE (VO__end - VO__text - __PAGE_OFFSET - ____LOAD_PHYSICAL_ADDR)
7965+#else
7966 #define VO_INIT_SIZE (VO__end - VO__text)
7967+#endif
7968 #if ZO_INIT_SIZE > VO_INIT_SIZE
7969 #define INIT_SIZE ZO_INIT_SIZE
7970 #else
7971diff --git a/arch/x86/boot/memory.c b/arch/x86/boot/memory.c
7972index db75d07..8e6d0af 100644
7973--- a/arch/x86/boot/memory.c
7974+++ b/arch/x86/boot/memory.c
7975@@ -19,7 +19,7 @@
7976
7977 static int detect_memory_e820(void)
7978 {
7979- int count = 0;
7980+ unsigned int count = 0;
7981 struct biosregs ireg, oreg;
7982 struct e820entry *desc = boot_params.e820_map;
7983 static struct e820entry buf; /* static so it is zeroed */
7984diff --git a/arch/x86/boot/video-vesa.c b/arch/x86/boot/video-vesa.c
7985index 11e8c6e..fdbb1ed 100644
7986--- a/arch/x86/boot/video-vesa.c
7987+++ b/arch/x86/boot/video-vesa.c
7988@@ -200,6 +200,7 @@ static void vesa_store_pm_info(void)
7989
7990 boot_params.screen_info.vesapm_seg = oreg.es;
7991 boot_params.screen_info.vesapm_off = oreg.di;
7992+ boot_params.screen_info.vesapm_size = oreg.cx;
7993 }
7994
7995 /*
7996diff --git a/arch/x86/boot/video.c b/arch/x86/boot/video.c
7997index 43eda28..5ab5fdb 100644
7998--- a/arch/x86/boot/video.c
7999+++ b/arch/x86/boot/video.c
8000@@ -96,7 +96,7 @@ static void store_mode_params(void)
8001 static unsigned int get_entry(void)
8002 {
8003 char entry_buf[4];
8004- int i, len = 0;
8005+ unsigned int i, len = 0;
8006 int key;
8007 unsigned int v;
8008
8009diff --git a/arch/x86/crypto/aes-x86_64-asm_64.S b/arch/x86/crypto/aes-x86_64-asm_64.S
8010index 5b577d5..3c1fed4 100644
8011--- a/arch/x86/crypto/aes-x86_64-asm_64.S
8012+++ b/arch/x86/crypto/aes-x86_64-asm_64.S
8013@@ -8,6 +8,8 @@
8014 * including this sentence is retained in full.
8015 */
8016
8017+#include <asm/alternative-asm.h>
8018+
8019 .extern crypto_ft_tab
8020 .extern crypto_it_tab
8021 .extern crypto_fl_tab
8022@@ -71,6 +73,8 @@ FUNC: movq r1,r2; \
8023 je B192; \
8024 leaq 32(r9),r9;
8025
8026+#define ret pax_force_retaddr 0, 1; ret
8027+
8028 #define epilogue(r1,r2,r3,r4,r5,r6,r7,r8,r9) \
8029 movq r1,r2; \
8030 movq r3,r4; \
8031diff --git a/arch/x86/crypto/aesni-intel_asm.S b/arch/x86/crypto/aesni-intel_asm.S
8032index 3470624..201259d 100644
8033--- a/arch/x86/crypto/aesni-intel_asm.S
8034+++ b/arch/x86/crypto/aesni-intel_asm.S
8035@@ -31,6 +31,7 @@
8036
8037 #include <linux/linkage.h>
8038 #include <asm/inst.h>
8039+#include <asm/alternative-asm.h>
8040
8041 #ifdef __x86_64__
8042 .data
8043@@ -1436,7 +1437,9 @@ _return_T_done_decrypt:
8044 pop %r14
8045 pop %r13
8046 pop %r12
8047+ pax_force_retaddr 0, 1
8048 ret
8049+ENDPROC(aesni_gcm_dec)
8050
8051
8052 /*****************************************************************************
8053@@ -1699,7 +1702,9 @@ _return_T_done_encrypt:
8054 pop %r14
8055 pop %r13
8056 pop %r12
8057+ pax_force_retaddr 0, 1
8058 ret
8059+ENDPROC(aesni_gcm_enc)
8060
8061 #endif
8062
8063@@ -1714,6 +1719,7 @@ _key_expansion_256a:
8064 pxor %xmm1, %xmm0
8065 movaps %xmm0, (TKEYP)
8066 add $0x10, TKEYP
8067+ pax_force_retaddr_bts
8068 ret
8069
8070 .align 4
8071@@ -1738,6 +1744,7 @@ _key_expansion_192a:
8072 shufps $0b01001110, %xmm2, %xmm1
8073 movaps %xmm1, 0x10(TKEYP)
8074 add $0x20, TKEYP
8075+ pax_force_retaddr_bts
8076 ret
8077
8078 .align 4
8079@@ -1757,6 +1764,7 @@ _key_expansion_192b:
8080
8081 movaps %xmm0, (TKEYP)
8082 add $0x10, TKEYP
8083+ pax_force_retaddr_bts
8084 ret
8085
8086 .align 4
8087@@ -1769,6 +1777,7 @@ _key_expansion_256b:
8088 pxor %xmm1, %xmm2
8089 movaps %xmm2, (TKEYP)
8090 add $0x10, TKEYP
8091+ pax_force_retaddr_bts
8092 ret
8093
8094 /*
8095@@ -1881,7 +1890,9 @@ ENTRY(aesni_set_key)
8096 #ifndef __x86_64__
8097 popl KEYP
8098 #endif
8099+ pax_force_retaddr 0, 1
8100 ret
8101+ENDPROC(aesni_set_key)
8102
8103 /*
8104 * void aesni_enc(struct crypto_aes_ctx *ctx, u8 *dst, const u8 *src)
8105@@ -1902,7 +1913,9 @@ ENTRY(aesni_enc)
8106 popl KLEN
8107 popl KEYP
8108 #endif
8109+ pax_force_retaddr 0, 1
8110 ret
8111+ENDPROC(aesni_enc)
8112
8113 /*
8114 * _aesni_enc1: internal ABI
8115@@ -1959,6 +1972,7 @@ _aesni_enc1:
8116 AESENC KEY STATE
8117 movaps 0x70(TKEYP), KEY
8118 AESENCLAST KEY STATE
8119+ pax_force_retaddr_bts
8120 ret
8121
8122 /*
8123@@ -2067,6 +2081,7 @@ _aesni_enc4:
8124 AESENCLAST KEY STATE2
8125 AESENCLAST KEY STATE3
8126 AESENCLAST KEY STATE4
8127+ pax_force_retaddr_bts
8128 ret
8129
8130 /*
8131@@ -2089,7 +2104,9 @@ ENTRY(aesni_dec)
8132 popl KLEN
8133 popl KEYP
8134 #endif
8135+ pax_force_retaddr 0, 1
8136 ret
8137+ENDPROC(aesni_dec)
8138
8139 /*
8140 * _aesni_dec1: internal ABI
8141@@ -2146,6 +2163,7 @@ _aesni_dec1:
8142 AESDEC KEY STATE
8143 movaps 0x70(TKEYP), KEY
8144 AESDECLAST KEY STATE
8145+ pax_force_retaddr_bts
8146 ret
8147
8148 /*
8149@@ -2254,6 +2272,7 @@ _aesni_dec4:
8150 AESDECLAST KEY STATE2
8151 AESDECLAST KEY STATE3
8152 AESDECLAST KEY STATE4
8153+ pax_force_retaddr_bts
8154 ret
8155
8156 /*
8157@@ -2311,7 +2330,9 @@ ENTRY(aesni_ecb_enc)
8158 popl KEYP
8159 popl LEN
8160 #endif
8161+ pax_force_retaddr 0, 1
8162 ret
8163+ENDPROC(aesni_ecb_enc)
8164
8165 /*
8166 * void aesni_ecb_dec(struct crypto_aes_ctx *ctx, const u8 *dst, u8 *src,
8167@@ -2369,7 +2390,9 @@ ENTRY(aesni_ecb_dec)
8168 popl KEYP
8169 popl LEN
8170 #endif
8171+ pax_force_retaddr 0, 1
8172 ret
8173+ENDPROC(aesni_ecb_dec)
8174
8175 /*
8176 * void aesni_cbc_enc(struct crypto_aes_ctx *ctx, const u8 *dst, u8 *src,
8177@@ -2410,7 +2433,9 @@ ENTRY(aesni_cbc_enc)
8178 popl LEN
8179 popl IVP
8180 #endif
8181+ pax_force_retaddr 0, 1
8182 ret
8183+ENDPROC(aesni_cbc_enc)
8184
8185 /*
8186 * void aesni_cbc_dec(struct crypto_aes_ctx *ctx, const u8 *dst, u8 *src,
8187@@ -2500,7 +2525,9 @@ ENTRY(aesni_cbc_dec)
8188 popl LEN
8189 popl IVP
8190 #endif
8191+ pax_force_retaddr 0, 1
8192 ret
8193+ENDPROC(aesni_cbc_dec)
8194
8195 #ifdef __x86_64__
8196 .align 16
8197@@ -2526,6 +2553,7 @@ _aesni_inc_init:
8198 mov $1, TCTR_LOW
8199 MOVQ_R64_XMM TCTR_LOW INC
8200 MOVQ_R64_XMM CTR TCTR_LOW
8201+ pax_force_retaddr_bts
8202 ret
8203
8204 /*
8205@@ -2554,6 +2582,7 @@ _aesni_inc:
8206 .Linc_low:
8207 movaps CTR, IV
8208 PSHUFB_XMM BSWAP_MASK IV
8209+ pax_force_retaddr_bts
8210 ret
8211
8212 /*
8213@@ -2614,5 +2643,7 @@ ENTRY(aesni_ctr_enc)
8214 .Lctr_enc_ret:
8215 movups IV, (IVP)
8216 .Lctr_enc_just_ret:
8217+ pax_force_retaddr 0, 1
8218 ret
8219+ENDPROC(aesni_ctr_enc)
8220 #endif
8221diff --git a/arch/x86/crypto/blowfish-x86_64-asm_64.S b/arch/x86/crypto/blowfish-x86_64-asm_64.S
8222index 391d245..67f35c2 100644
8223--- a/arch/x86/crypto/blowfish-x86_64-asm_64.S
8224+++ b/arch/x86/crypto/blowfish-x86_64-asm_64.S
8225@@ -20,6 +20,8 @@
8226 *
8227 */
8228
8229+#include <asm/alternative-asm.h>
8230+
8231 .file "blowfish-x86_64-asm.S"
8232 .text
8233
8234@@ -151,9 +153,11 @@ __blowfish_enc_blk:
8235 jnz __enc_xor;
8236
8237 write_block();
8238+ pax_force_retaddr 0, 1
8239 ret;
8240 __enc_xor:
8241 xor_block();
8242+ pax_force_retaddr 0, 1
8243 ret;
8244
8245 .align 8
8246@@ -188,6 +192,7 @@ blowfish_dec_blk:
8247
8248 movq %r11, %rbp;
8249
8250+ pax_force_retaddr 0, 1
8251 ret;
8252
8253 /**********************************************************************
8254@@ -342,6 +347,7 @@ __blowfish_enc_blk_4way:
8255
8256 popq %rbx;
8257 popq %rbp;
8258+ pax_force_retaddr 0, 1
8259 ret;
8260
8261 __enc_xor4:
8262@@ -349,6 +355,7 @@ __enc_xor4:
8263
8264 popq %rbx;
8265 popq %rbp;
8266+ pax_force_retaddr 0, 1
8267 ret;
8268
8269 .align 8
8270@@ -386,5 +393,6 @@ blowfish_dec_blk_4way:
8271 popq %rbx;
8272 popq %rbp;
8273
8274+ pax_force_retaddr 0, 1
8275 ret;
8276
8277diff --git a/arch/x86/crypto/camellia-x86_64-asm_64.S b/arch/x86/crypto/camellia-x86_64-asm_64.S
8278index 0b33743..7a56206 100644
8279--- a/arch/x86/crypto/camellia-x86_64-asm_64.S
8280+++ b/arch/x86/crypto/camellia-x86_64-asm_64.S
8281@@ -20,6 +20,8 @@
8282 *
8283 */
8284
8285+#include <asm/alternative-asm.h>
8286+
8287 .file "camellia-x86_64-asm_64.S"
8288 .text
8289
8290@@ -229,12 +231,14 @@ __enc_done:
8291 enc_outunpack(mov, RT1);
8292
8293 movq RRBP, %rbp;
8294+ pax_force_retaddr 0, 1
8295 ret;
8296
8297 __enc_xor:
8298 enc_outunpack(xor, RT1);
8299
8300 movq RRBP, %rbp;
8301+ pax_force_retaddr 0, 1
8302 ret;
8303
8304 .global camellia_dec_blk;
8305@@ -275,6 +279,7 @@ __dec_rounds16:
8306 dec_outunpack();
8307
8308 movq RRBP, %rbp;
8309+ pax_force_retaddr 0, 1
8310 ret;
8311
8312 /**********************************************************************
8313@@ -468,6 +473,7 @@ __enc2_done:
8314
8315 movq RRBP, %rbp;
8316 popq %rbx;
8317+ pax_force_retaddr 0, 1
8318 ret;
8319
8320 __enc2_xor:
8321@@ -475,6 +481,7 @@ __enc2_xor:
8322
8323 movq RRBP, %rbp;
8324 popq %rbx;
8325+ pax_force_retaddr 0, 1
8326 ret;
8327
8328 .global camellia_dec_blk_2way;
8329@@ -517,4 +524,5 @@ __dec2_rounds16:
8330
8331 movq RRBP, %rbp;
8332 movq RXOR, %rbx;
8333+ pax_force_retaddr 0, 1
8334 ret;
8335diff --git a/arch/x86/crypto/salsa20-x86_64-asm_64.S b/arch/x86/crypto/salsa20-x86_64-asm_64.S
8336index 6214a9b..1f4fc9a 100644
8337--- a/arch/x86/crypto/salsa20-x86_64-asm_64.S
8338+++ b/arch/x86/crypto/salsa20-x86_64-asm_64.S
8339@@ -1,3 +1,5 @@
8340+#include <asm/alternative-asm.h>
8341+
8342 # enter ECRYPT_encrypt_bytes
8343 .text
8344 .p2align 5
8345@@ -790,6 +792,7 @@ ECRYPT_encrypt_bytes:
8346 add %r11,%rsp
8347 mov %rdi,%rax
8348 mov %rsi,%rdx
8349+ pax_force_retaddr 0, 1
8350 ret
8351 # bytesatleast65:
8352 ._bytesatleast65:
8353@@ -891,6 +894,7 @@ ECRYPT_keysetup:
8354 add %r11,%rsp
8355 mov %rdi,%rax
8356 mov %rsi,%rdx
8357+ pax_force_retaddr
8358 ret
8359 # enter ECRYPT_ivsetup
8360 .text
8361@@ -917,4 +921,5 @@ ECRYPT_ivsetup:
8362 add %r11,%rsp
8363 mov %rdi,%rax
8364 mov %rsi,%rdx
8365+ pax_force_retaddr
8366 ret
8367diff --git a/arch/x86/crypto/serpent-avx-x86_64-asm_64.S b/arch/x86/crypto/serpent-avx-x86_64-asm_64.S
8368index 504106b..4e50951 100644
8369--- a/arch/x86/crypto/serpent-avx-x86_64-asm_64.S
8370+++ b/arch/x86/crypto/serpent-avx-x86_64-asm_64.S
8371@@ -24,6 +24,8 @@
8372 *
8373 */
8374
8375+#include <asm/alternative-asm.h>
8376+
8377 .file "serpent-avx-x86_64-asm_64.S"
8378 .text
8379
8380@@ -638,12 +640,14 @@ __serpent_enc_blk_8way_avx:
8381 write_blocks(%rsi, RA1, RB1, RC1, RD1, RK0, RK1, RK2);
8382 write_blocks(%rax, RA2, RB2, RC2, RD2, RK0, RK1, RK2);
8383
8384+ pax_force_retaddr
8385 ret;
8386
8387 __enc_xor8:
8388 xor_blocks(%rsi, RA1, RB1, RC1, RD1, RK0, RK1, RK2);
8389 xor_blocks(%rax, RA2, RB2, RC2, RD2, RK0, RK1, RK2);
8390
8391+ pax_force_retaddr
8392 ret;
8393
8394 .align 8
8395@@ -701,4 +705,5 @@ serpent_dec_blk_8way_avx:
8396 write_blocks(%rsi, RC1, RD1, RB1, RE1, RK0, RK1, RK2);
8397 write_blocks(%rax, RC2, RD2, RB2, RE2, RK0, RK1, RK2);
8398
8399+ pax_force_retaddr
8400 ret;
8401diff --git a/arch/x86/crypto/serpent-sse2-x86_64-asm_64.S b/arch/x86/crypto/serpent-sse2-x86_64-asm_64.S
8402index 3ee1ff0..cbc568b 100644
8403--- a/arch/x86/crypto/serpent-sse2-x86_64-asm_64.S
8404+++ b/arch/x86/crypto/serpent-sse2-x86_64-asm_64.S
8405@@ -24,6 +24,8 @@
8406 *
8407 */
8408
8409+#include <asm/alternative-asm.h>
8410+
8411 .file "serpent-sse2-x86_64-asm_64.S"
8412 .text
8413
8414@@ -692,12 +694,14 @@ __serpent_enc_blk_8way:
8415 write_blocks(%rsi, RA1, RB1, RC1, RD1, RK0, RK1, RK2);
8416 write_blocks(%rax, RA2, RB2, RC2, RD2, RK0, RK1, RK2);
8417
8418+ pax_force_retaddr
8419 ret;
8420
8421 __enc_xor8:
8422 xor_blocks(%rsi, RA1, RB1, RC1, RD1, RK0, RK1, RK2);
8423 xor_blocks(%rax, RA2, RB2, RC2, RD2, RK0, RK1, RK2);
8424
8425+ pax_force_retaddr
8426 ret;
8427
8428 .align 8
8429@@ -755,4 +759,5 @@ serpent_dec_blk_8way:
8430 write_blocks(%rsi, RC1, RD1, RB1, RE1, RK0, RK1, RK2);
8431 write_blocks(%rax, RC2, RD2, RB2, RE2, RK0, RK1, RK2);
8432
8433+ pax_force_retaddr
8434 ret;
8435diff --git a/arch/x86/crypto/sha1_ssse3_asm.S b/arch/x86/crypto/sha1_ssse3_asm.S
8436index 49d6987..df66bd4 100644
8437--- a/arch/x86/crypto/sha1_ssse3_asm.S
8438+++ b/arch/x86/crypto/sha1_ssse3_asm.S
8439@@ -28,6 +28,8 @@
8440 * (at your option) any later version.
8441 */
8442
8443+#include <asm/alternative-asm.h>
8444+
8445 #define CTX %rdi // arg1
8446 #define BUF %rsi // arg2
8447 #define CNT %rdx // arg3
8448@@ -104,6 +106,7 @@
8449 pop %r12
8450 pop %rbp
8451 pop %rbx
8452+ pax_force_retaddr 0, 1
8453 ret
8454
8455 .size \name, .-\name
8456diff --git a/arch/x86/crypto/twofish-avx-x86_64-asm_64.S b/arch/x86/crypto/twofish-avx-x86_64-asm_64.S
8457index 35f4557..16b379f 100644
8458--- a/arch/x86/crypto/twofish-avx-x86_64-asm_64.S
8459+++ b/arch/x86/crypto/twofish-avx-x86_64-asm_64.S
8460@@ -21,6 +21,8 @@
8461 *
8462 */
8463
8464+#include <asm/alternative-asm.h>
8465+
8466 .file "twofish-avx-x86_64-asm_64.S"
8467 .text
8468
8469@@ -250,12 +252,14 @@ __twofish_enc_blk_8way:
8470 outunpack_blocks(%rsi, RC1, RD1, RA1, RB1, RK1, RX, RY, RK2);
8471 outunpack_blocks(%rax, RC2, RD2, RA2, RB2, RK1, RX, RY, RK2);
8472
8473+ pax_force_retaddr
8474 ret;
8475
8476 __enc_xor8:
8477 outunpack_xor_blocks(%rsi, RC1, RD1, RA1, RB1, RK1, RX, RY, RK2);
8478 outunpack_xor_blocks(%rax, RC2, RD2, RA2, RB2, RK1, RX, RY, RK2);
8479
8480+ pax_force_retaddr
8481 ret;
8482
8483 .align 8
8484@@ -297,4 +301,5 @@ twofish_dec_blk_8way:
8485 outunpack_blocks(%rsi, RA1, RB1, RC1, RD1, RK1, RX, RY, RK2);
8486 outunpack_blocks(%rax, RA2, RB2, RC2, RD2, RK1, RX, RY, RK2);
8487
8488+ pax_force_retaddr
8489 ret;
8490diff --git a/arch/x86/crypto/twofish-x86_64-asm_64-3way.S b/arch/x86/crypto/twofish-x86_64-asm_64-3way.S
8491index 5b012a2..36d5364 100644
8492--- a/arch/x86/crypto/twofish-x86_64-asm_64-3way.S
8493+++ b/arch/x86/crypto/twofish-x86_64-asm_64-3way.S
8494@@ -20,6 +20,8 @@
8495 *
8496 */
8497
8498+#include <asm/alternative-asm.h>
8499+
8500 .file "twofish-x86_64-asm-3way.S"
8501 .text
8502
8503@@ -260,6 +262,7 @@ __twofish_enc_blk_3way:
8504 popq %r13;
8505 popq %r14;
8506 popq %r15;
8507+ pax_force_retaddr 0, 1
8508 ret;
8509
8510 __enc_xor3:
8511@@ -271,6 +274,7 @@ __enc_xor3:
8512 popq %r13;
8513 popq %r14;
8514 popq %r15;
8515+ pax_force_retaddr 0, 1
8516 ret;
8517
8518 .global twofish_dec_blk_3way
8519@@ -312,5 +316,6 @@ twofish_dec_blk_3way:
8520 popq %r13;
8521 popq %r14;
8522 popq %r15;
8523+ pax_force_retaddr 0, 1
8524 ret;
8525
8526diff --git a/arch/x86/crypto/twofish-x86_64-asm_64.S b/arch/x86/crypto/twofish-x86_64-asm_64.S
8527index 7bcf3fc..f53832f 100644
8528--- a/arch/x86/crypto/twofish-x86_64-asm_64.S
8529+++ b/arch/x86/crypto/twofish-x86_64-asm_64.S
8530@@ -21,6 +21,7 @@
8531 .text
8532
8533 #include <asm/asm-offsets.h>
8534+#include <asm/alternative-asm.h>
8535
8536 #define a_offset 0
8537 #define b_offset 4
8538@@ -268,6 +269,7 @@ twofish_enc_blk:
8539
8540 popq R1
8541 movq $1,%rax
8542+ pax_force_retaddr 0, 1
8543 ret
8544
8545 twofish_dec_blk:
8546@@ -319,4 +321,5 @@ twofish_dec_blk:
8547
8548 popq R1
8549 movq $1,%rax
8550+ pax_force_retaddr 0, 1
8551 ret
8552diff --git a/arch/x86/ia32/ia32_aout.c b/arch/x86/ia32/ia32_aout.c
8553index 07b3a68..bd2a388 100644
8554--- a/arch/x86/ia32/ia32_aout.c
8555+++ b/arch/x86/ia32/ia32_aout.c
8556@@ -159,6 +159,8 @@ static int aout_core_dump(long signr, struct pt_regs *regs, struct file *file,
8557 unsigned long dump_start, dump_size;
8558 struct user32 dump;
8559
8560+ memset(&dump, 0, sizeof(dump));
8561+
8562 fs = get_fs();
8563 set_fs(KERNEL_DS);
8564 has_dumped = 1;
8565diff --git a/arch/x86/ia32/ia32_signal.c b/arch/x86/ia32/ia32_signal.c
8566index 673ac9b..7a8c5df 100644
8567--- a/arch/x86/ia32/ia32_signal.c
8568+++ b/arch/x86/ia32/ia32_signal.c
8569@@ -162,7 +162,7 @@ asmlinkage long sys32_sigaltstack(const stack_ia32_t __user *uss_ptr,
8570 }
8571 seg = get_fs();
8572 set_fs(KERNEL_DS);
8573- ret = do_sigaltstack(uss_ptr ? &uss : NULL, &uoss, regs->sp);
8574+ ret = do_sigaltstack(uss_ptr ? (const stack_t __force_user *)&uss : NULL, (stack_t __force_user *)&uoss, regs->sp);
8575 set_fs(seg);
8576 if (ret >= 0 && uoss_ptr) {
8577 if (!access_ok(VERIFY_WRITE, uoss_ptr, sizeof(stack_ia32_t)))
8578@@ -361,7 +361,7 @@ static int ia32_setup_sigcontext(struct sigcontext_ia32 __user *sc,
8579 */
8580 static void __user *get_sigframe(struct k_sigaction *ka, struct pt_regs *regs,
8581 size_t frame_size,
8582- void **fpstate)
8583+ void __user **fpstate)
8584 {
8585 unsigned long sp;
8586
8587@@ -382,7 +382,7 @@ static void __user *get_sigframe(struct k_sigaction *ka, struct pt_regs *regs,
8588
8589 if (used_math()) {
8590 sp = sp - sig_xstate_ia32_size;
8591- *fpstate = (struct _fpstate_ia32 *) sp;
8592+ *fpstate = (struct _fpstate_ia32 __user *) sp;
8593 if (save_i387_xstate_ia32(*fpstate) < 0)
8594 return (void __user *) -1L;
8595 }
8596@@ -390,7 +390,7 @@ static void __user *get_sigframe(struct k_sigaction *ka, struct pt_regs *regs,
8597 sp -= frame_size;
8598 /* Align the stack pointer according to the i386 ABI,
8599 * i.e. so that on function entry ((sp + 4) & 15) == 0. */
8600- sp = ((sp + 4) & -16ul) - 4;
8601+ sp = ((sp - 12) & -16ul) - 4;
8602 return (void __user *) sp;
8603 }
8604
8605@@ -448,7 +448,7 @@ int ia32_setup_frame(int sig, struct k_sigaction *ka,
8606 * These are actually not used anymore, but left because some
8607 * gdb versions depend on them as a marker.
8608 */
8609- put_user_ex(*((u64 *)&code), (u64 *)frame->retcode);
8610+ put_user_ex(*((const u64 *)&code), (u64 __user *)frame->retcode);
8611 } put_user_catch(err);
8612
8613 if (err)
8614@@ -490,7 +490,7 @@ int ia32_setup_rt_frame(int sig, struct k_sigaction *ka, siginfo_t *info,
8615 0xb8,
8616 __NR_ia32_rt_sigreturn,
8617 0x80cd,
8618- 0,
8619+ 0
8620 };
8621
8622 frame = get_sigframe(ka, regs, sizeof(*frame), &fpstate);
8623@@ -520,16 +520,18 @@ int ia32_setup_rt_frame(int sig, struct k_sigaction *ka, siginfo_t *info,
8624
8625 if (ka->sa.sa_flags & SA_RESTORER)
8626 restorer = ka->sa.sa_restorer;
8627+ else if (current->mm->context.vdso)
8628+ /* Return stub is in 32bit vsyscall page */
8629+ restorer = VDSO32_SYMBOL(current->mm->context.vdso, rt_sigreturn);
8630 else
8631- restorer = VDSO32_SYMBOL(current->mm->context.vdso,
8632- rt_sigreturn);
8633+ restorer = &frame->retcode;
8634 put_user_ex(ptr_to_compat(restorer), &frame->pretcode);
8635
8636 /*
8637 * Not actually used anymore, but left because some gdb
8638 * versions need it.
8639 */
8640- put_user_ex(*((u64 *)&code), (u64 *)frame->retcode);
8641+ put_user_ex(*((const u64 *)&code), (u64 __user *)frame->retcode);
8642 } put_user_catch(err);
8643
8644 if (err)
8645diff --git a/arch/x86/ia32/ia32entry.S b/arch/x86/ia32/ia32entry.S
8646index 20e5f7b..f33c779 100644
8647--- a/arch/x86/ia32/ia32entry.S
8648+++ b/arch/x86/ia32/ia32entry.S
8649@@ -14,8 +14,10 @@
8650 #include <asm/segment.h>
8651 #include <asm/irqflags.h>
8652 #include <asm/asm.h>
8653+#include <asm/pgtable.h>
8654 #include <linux/linkage.h>
8655 #include <linux/err.h>
8656+#include <asm/alternative-asm.h>
8657
8658 /* Avoid __ASSEMBLER__'ifying <linux/audit.h> just for this. */
8659 #include <linux/elf-em.h>
8660@@ -95,6 +97,32 @@ ENTRY(native_irq_enable_sysexit)
8661 ENDPROC(native_irq_enable_sysexit)
8662 #endif
8663
8664+ .macro pax_enter_kernel_user
8665+ pax_set_fptr_mask
8666+#ifdef CONFIG_PAX_MEMORY_UDEREF
8667+ call pax_enter_kernel_user
8668+#endif
8669+ .endm
8670+
8671+ .macro pax_exit_kernel_user
8672+#ifdef CONFIG_PAX_MEMORY_UDEREF
8673+ call pax_exit_kernel_user
8674+#endif
8675+#ifdef CONFIG_PAX_RANDKSTACK
8676+ pushq %rax
8677+ pushq %r11
8678+ call pax_randomize_kstack
8679+ popq %r11
8680+ popq %rax
8681+#endif
8682+ .endm
8683+
8684+.macro pax_erase_kstack
8685+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
8686+ call pax_erase_kstack
8687+#endif
8688+.endm
8689+
8690 /*
8691 * 32bit SYSENTER instruction entry.
8692 *
8693@@ -121,12 +149,6 @@ ENTRY(ia32_sysenter_target)
8694 CFI_REGISTER rsp,rbp
8695 SWAPGS_UNSAFE_STACK
8696 movq PER_CPU_VAR(kernel_stack), %rsp
8697- addq $(KERNEL_STACK_OFFSET),%rsp
8698- /*
8699- * No need to follow this irqs on/off section: the syscall
8700- * disabled irqs, here we enable it straight after entry:
8701- */
8702- ENABLE_INTERRUPTS(CLBR_NONE)
8703 movl %ebp,%ebp /* zero extension */
8704 pushq_cfi $__USER32_DS
8705 /*CFI_REL_OFFSET ss,0*/
8706@@ -134,22 +156,42 @@ ENTRY(ia32_sysenter_target)
8707 CFI_REL_OFFSET rsp,0
8708 pushfq_cfi
8709 /*CFI_REL_OFFSET rflags,0*/
8710- movl TI_sysenter_return+THREAD_INFO(%rsp,3*8-KERNEL_STACK_OFFSET),%r10d
8711- CFI_REGISTER rip,r10
8712+ orl $X86_EFLAGS_IF,(%rsp)
8713+ GET_THREAD_INFO(%r11)
8714+ movl TI_sysenter_return(%r11), %r11d
8715+ CFI_REGISTER rip,r11
8716 pushq_cfi $__USER32_CS
8717 /*CFI_REL_OFFSET cs,0*/
8718 movl %eax, %eax
8719- pushq_cfi %r10
8720+ pushq_cfi %r11
8721 CFI_REL_OFFSET rip,0
8722 pushq_cfi %rax
8723 cld
8724 SAVE_ARGS 0,1,0
8725+ pax_enter_kernel_user
8726+
8727+#ifdef CONFIG_PAX_RANDKSTACK
8728+ pax_erase_kstack
8729+#endif
8730+
8731+ /*
8732+ * No need to follow this irqs on/off section: the syscall
8733+ * disabled irqs, here we enable it straight after entry:
8734+ */
8735+ ENABLE_INTERRUPTS(CLBR_NONE)
8736 /* no need to do an access_ok check here because rbp has been
8737 32bit zero extended */
8738+
8739+#ifdef CONFIG_PAX_MEMORY_UDEREF
8740+ mov $PAX_USER_SHADOW_BASE,%r11
8741+ add %r11,%rbp
8742+#endif
8743+
8744 1: movl (%rbp),%ebp
8745 _ASM_EXTABLE(1b,ia32_badarg)
8746- orl $TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
8747- testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
8748+ GET_THREAD_INFO(%r11)
8749+ orl $TS_COMPAT,TI_status(%r11)
8750+ testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%r11)
8751 CFI_REMEMBER_STATE
8752 jnz sysenter_tracesys
8753 cmpq $(IA32_NR_syscalls-1),%rax
8754@@ -159,12 +201,15 @@ sysenter_do_call:
8755 sysenter_dispatch:
8756 call *ia32_sys_call_table(,%rax,8)
8757 movq %rax,RAX-ARGOFFSET(%rsp)
8758+ GET_THREAD_INFO(%r11)
8759 DISABLE_INTERRUPTS(CLBR_NONE)
8760 TRACE_IRQS_OFF
8761- testl $_TIF_ALLWORK_MASK,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
8762+ testl $_TIF_ALLWORK_MASK,TI_flags(%r11)
8763 jnz sysexit_audit
8764 sysexit_from_sys_call:
8765- andl $~TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
8766+ pax_exit_kernel_user
8767+ pax_erase_kstack
8768+ andl $~TS_COMPAT,TI_status(%r11)
8769 /* clear IF, that popfq doesn't enable interrupts early */
8770 andl $~0x200,EFLAGS-R11(%rsp)
8771 movl RIP-R11(%rsp),%edx /* User %eip */
8772@@ -190,6 +235,9 @@ sysexit_from_sys_call:
8773 movl %eax,%esi /* 2nd arg: syscall number */
8774 movl $AUDIT_ARCH_I386,%edi /* 1st arg: audit arch */
8775 call __audit_syscall_entry
8776+
8777+ pax_erase_kstack
8778+
8779 movl RAX-ARGOFFSET(%rsp),%eax /* reload syscall number */
8780 cmpq $(IA32_NR_syscalls-1),%rax
8781 ja ia32_badsys
8782@@ -201,7 +249,7 @@ sysexit_from_sys_call:
8783 .endm
8784
8785 .macro auditsys_exit exit
8786- testl $(_TIF_ALLWORK_MASK & ~_TIF_SYSCALL_AUDIT),TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
8787+ testl $(_TIF_ALLWORK_MASK & ~_TIF_SYSCALL_AUDIT),TI_flags(%r11)
8788 jnz ia32_ret_from_sys_call
8789 TRACE_IRQS_ON
8790 sti
8791@@ -212,11 +260,12 @@ sysexit_from_sys_call:
8792 1: setbe %al /* 1 if error, 0 if not */
8793 movzbl %al,%edi /* zero-extend that into %edi */
8794 call __audit_syscall_exit
8795+ GET_THREAD_INFO(%r11)
8796 movq RAX-ARGOFFSET(%rsp),%rax /* reload syscall return value */
8797 movl $(_TIF_ALLWORK_MASK & ~_TIF_SYSCALL_AUDIT),%edi
8798 cli
8799 TRACE_IRQS_OFF
8800- testl %edi,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
8801+ testl %edi,TI_flags(%r11)
8802 jz \exit
8803 CLEAR_RREGS -ARGOFFSET
8804 jmp int_with_check
8805@@ -234,7 +283,7 @@ sysexit_audit:
8806
8807 sysenter_tracesys:
8808 #ifdef CONFIG_AUDITSYSCALL
8809- testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
8810+ testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags(%r11)
8811 jz sysenter_auditsys
8812 #endif
8813 SAVE_REST
8814@@ -246,6 +295,9 @@ sysenter_tracesys:
8815 RESTORE_REST
8816 cmpq $(IA32_NR_syscalls-1),%rax
8817 ja int_ret_from_sys_call /* sysenter_tracesys has set RAX(%rsp) */
8818+
8819+ pax_erase_kstack
8820+
8821 jmp sysenter_do_call
8822 CFI_ENDPROC
8823 ENDPROC(ia32_sysenter_target)
8824@@ -273,19 +325,25 @@ ENDPROC(ia32_sysenter_target)
8825 ENTRY(ia32_cstar_target)
8826 CFI_STARTPROC32 simple
8827 CFI_SIGNAL_FRAME
8828- CFI_DEF_CFA rsp,KERNEL_STACK_OFFSET
8829+ CFI_DEF_CFA rsp,0
8830 CFI_REGISTER rip,rcx
8831 /*CFI_REGISTER rflags,r11*/
8832 SWAPGS_UNSAFE_STACK
8833 movl %esp,%r8d
8834 CFI_REGISTER rsp,r8
8835 movq PER_CPU_VAR(kernel_stack),%rsp
8836+ SAVE_ARGS 8*6,0,0
8837+ pax_enter_kernel_user
8838+
8839+#ifdef CONFIG_PAX_RANDKSTACK
8840+ pax_erase_kstack
8841+#endif
8842+
8843 /*
8844 * No need to follow this irqs on/off section: the syscall
8845 * disabled irqs and here we enable it straight after entry:
8846 */
8847 ENABLE_INTERRUPTS(CLBR_NONE)
8848- SAVE_ARGS 8,0,0
8849 movl %eax,%eax /* zero extension */
8850 movq %rax,ORIG_RAX-ARGOFFSET(%rsp)
8851 movq %rcx,RIP-ARGOFFSET(%rsp)
8852@@ -301,10 +359,17 @@ ENTRY(ia32_cstar_target)
8853 /* no need to do an access_ok check here because r8 has been
8854 32bit zero extended */
8855 /* hardware stack frame is complete now */
8856+
8857+#ifdef CONFIG_PAX_MEMORY_UDEREF
8858+ mov $PAX_USER_SHADOW_BASE,%r11
8859+ add %r11,%r8
8860+#endif
8861+
8862 1: movl (%r8),%r9d
8863 _ASM_EXTABLE(1b,ia32_badarg)
8864- orl $TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
8865- testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
8866+ GET_THREAD_INFO(%r11)
8867+ orl $TS_COMPAT,TI_status(%r11)
8868+ testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%r11)
8869 CFI_REMEMBER_STATE
8870 jnz cstar_tracesys
8871 cmpq $IA32_NR_syscalls-1,%rax
8872@@ -314,12 +379,15 @@ cstar_do_call:
8873 cstar_dispatch:
8874 call *ia32_sys_call_table(,%rax,8)
8875 movq %rax,RAX-ARGOFFSET(%rsp)
8876+ GET_THREAD_INFO(%r11)
8877 DISABLE_INTERRUPTS(CLBR_NONE)
8878 TRACE_IRQS_OFF
8879- testl $_TIF_ALLWORK_MASK,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
8880+ testl $_TIF_ALLWORK_MASK,TI_flags(%r11)
8881 jnz sysretl_audit
8882 sysretl_from_sys_call:
8883- andl $~TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
8884+ pax_exit_kernel_user
8885+ pax_erase_kstack
8886+ andl $~TS_COMPAT,TI_status(%r11)
8887 RESTORE_ARGS 0,-ARG_SKIP,0,0,0
8888 movl RIP-ARGOFFSET(%rsp),%ecx
8889 CFI_REGISTER rip,rcx
8890@@ -347,7 +415,7 @@ sysretl_audit:
8891
8892 cstar_tracesys:
8893 #ifdef CONFIG_AUDITSYSCALL
8894- testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
8895+ testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags(%r11)
8896 jz cstar_auditsys
8897 #endif
8898 xchgl %r9d,%ebp
8899@@ -361,6 +429,9 @@ cstar_tracesys:
8900 xchgl %ebp,%r9d
8901 cmpq $(IA32_NR_syscalls-1),%rax
8902 ja int_ret_from_sys_call /* cstar_tracesys has set RAX(%rsp) */
8903+
8904+ pax_erase_kstack
8905+
8906 jmp cstar_do_call
8907 END(ia32_cstar_target)
8908
8909@@ -401,19 +472,26 @@ ENTRY(ia32_syscall)
8910 CFI_REL_OFFSET rip,RIP-RIP
8911 PARAVIRT_ADJUST_EXCEPTION_FRAME
8912 SWAPGS
8913- /*
8914- * No need to follow this irqs on/off section: the syscall
8915- * disabled irqs and here we enable it straight after entry:
8916- */
8917- ENABLE_INTERRUPTS(CLBR_NONE)
8918 movl %eax,%eax
8919 pushq_cfi %rax
8920 cld
8921 /* note the registers are not zero extended to the sf.
8922 this could be a problem. */
8923 SAVE_ARGS 0,1,0
8924- orl $TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
8925- testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
8926+ pax_enter_kernel_user
8927+
8928+#ifdef CONFIG_PAX_RANDKSTACK
8929+ pax_erase_kstack
8930+#endif
8931+
8932+ /*
8933+ * No need to follow this irqs on/off section: the syscall
8934+ * disabled irqs and here we enable it straight after entry:
8935+ */
8936+ ENABLE_INTERRUPTS(CLBR_NONE)
8937+ GET_THREAD_INFO(%r11)
8938+ orl $TS_COMPAT,TI_status(%r11)
8939+ testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%r11)
8940 jnz ia32_tracesys
8941 cmpq $(IA32_NR_syscalls-1),%rax
8942 ja ia32_badsys
8943@@ -436,6 +514,9 @@ ia32_tracesys:
8944 RESTORE_REST
8945 cmpq $(IA32_NR_syscalls-1),%rax
8946 ja int_ret_from_sys_call /* ia32_tracesys has set RAX(%rsp) */
8947+
8948+ pax_erase_kstack
8949+
8950 jmp ia32_do_call
8951 END(ia32_syscall)
8952
8953diff --git a/arch/x86/ia32/sys_ia32.c b/arch/x86/ia32/sys_ia32.c
8954index 4540bec..714d913 100644
8955--- a/arch/x86/ia32/sys_ia32.c
8956+++ b/arch/x86/ia32/sys_ia32.c
8957@@ -69,8 +69,8 @@ asmlinkage long sys32_ftruncate64(unsigned int fd, unsigned long offset_low,
8958 */
8959 static int cp_stat64(struct stat64 __user *ubuf, struct kstat *stat)
8960 {
8961- typeof(ubuf->st_uid) uid = 0;
8962- typeof(ubuf->st_gid) gid = 0;
8963+ typeof(((struct stat64 *)0)->st_uid) uid = 0;
8964+ typeof(((struct stat64 *)0)->st_gid) gid = 0;
8965 SET_UID(uid, from_kuid_munged(current_user_ns(), stat->uid));
8966 SET_GID(gid, from_kgid_munged(current_user_ns(), stat->gid));
8967 if (!access_ok(VERIFY_WRITE, ubuf, sizeof(struct stat64)) ||
8968@@ -287,7 +287,7 @@ asmlinkage long sys32_sigaction(int sig, struct old_sigaction32 __user *act,
8969 return ret;
8970 }
8971
8972-asmlinkage long sys32_waitpid(compat_pid_t pid, unsigned int *stat_addr,
8973+asmlinkage long sys32_waitpid(compat_pid_t pid, unsigned int __user *stat_addr,
8974 int options)
8975 {
8976 return compat_sys_wait4(pid, stat_addr, options, NULL);
8977@@ -303,7 +303,7 @@ asmlinkage long sys32_sched_rr_get_interval(compat_pid_t pid,
8978 mm_segment_t old_fs = get_fs();
8979
8980 set_fs(KERNEL_DS);
8981- ret = sys_sched_rr_get_interval(pid, (struct timespec __user *)&t);
8982+ ret = sys_sched_rr_get_interval(pid, (struct timespec __force_user *)&t);
8983 set_fs(old_fs);
8984 if (put_compat_timespec(&t, interval))
8985 return -EFAULT;
8986@@ -319,7 +319,7 @@ asmlinkage long sys32_rt_sigpending(compat_sigset_t __user *set,
8987 mm_segment_t old_fs = get_fs();
8988
8989 set_fs(KERNEL_DS);
8990- ret = sys_rt_sigpending((sigset_t __user *)&s, sigsetsize);
8991+ ret = sys_rt_sigpending((sigset_t __force_user *)&s, sigsetsize);
8992 set_fs(old_fs);
8993 if (!ret) {
8994 switch (_NSIG_WORDS) {
8995@@ -344,7 +344,7 @@ asmlinkage long sys32_rt_sigqueueinfo(int pid, int sig,
8996 if (copy_siginfo_from_user32(&info, uinfo))
8997 return -EFAULT;
8998 set_fs(KERNEL_DS);
8999- ret = sys_rt_sigqueueinfo(pid, sig, (siginfo_t __user *)&info);
9000+ ret = sys_rt_sigqueueinfo(pid, sig, (siginfo_t __force_user *)&info);
9001 set_fs(old_fs);
9002 return ret;
9003 }
9004@@ -376,7 +376,7 @@ asmlinkage long sys32_sendfile(int out_fd, int in_fd,
9005 return -EFAULT;
9006
9007 set_fs(KERNEL_DS);
9008- ret = sys_sendfile(out_fd, in_fd, offset ? (off_t __user *)&of : NULL,
9009+ ret = sys_sendfile(out_fd, in_fd, offset ? (off_t __force_user *)&of : NULL,
9010 count);
9011 set_fs(old_fs);
9012
9013diff --git a/arch/x86/include/asm/alternative-asm.h b/arch/x86/include/asm/alternative-asm.h
9014index 952bd01..7692c6f 100644
9015--- a/arch/x86/include/asm/alternative-asm.h
9016+++ b/arch/x86/include/asm/alternative-asm.h
9017@@ -15,6 +15,45 @@
9018 .endm
9019 #endif
9020
9021+#ifdef KERNEXEC_PLUGIN
9022+ .macro pax_force_retaddr_bts rip=0
9023+ btsq $63,\rip(%rsp)
9024+ .endm
9025+#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_BTS
9026+ .macro pax_force_retaddr rip=0, reload=0
9027+ btsq $63,\rip(%rsp)
9028+ .endm
9029+ .macro pax_force_fptr ptr
9030+ btsq $63,\ptr
9031+ .endm
9032+ .macro pax_set_fptr_mask
9033+ .endm
9034+#endif
9035+#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR
9036+ .macro pax_force_retaddr rip=0, reload=0
9037+ .if \reload
9038+ pax_set_fptr_mask
9039+ .endif
9040+ orq %r10,\rip(%rsp)
9041+ .endm
9042+ .macro pax_force_fptr ptr
9043+ orq %r10,\ptr
9044+ .endm
9045+ .macro pax_set_fptr_mask
9046+ movabs $0x8000000000000000,%r10
9047+ .endm
9048+#endif
9049+#else
9050+ .macro pax_force_retaddr rip=0, reload=0
9051+ .endm
9052+ .macro pax_force_fptr ptr
9053+ .endm
9054+ .macro pax_force_retaddr_bts rip=0
9055+ .endm
9056+ .macro pax_set_fptr_mask
9057+ .endm
9058+#endif
9059+
9060 .macro altinstruction_entry orig alt feature orig_len alt_len
9061 .long \orig - .
9062 .long \alt - .
9063diff --git a/arch/x86/include/asm/alternative.h b/arch/x86/include/asm/alternative.h
9064index 7078068..f58bcda 100644
9065--- a/arch/x86/include/asm/alternative.h
9066+++ b/arch/x86/include/asm/alternative.h
9067@@ -105,7 +105,7 @@ static inline int alternatives_text_reserved(void *start, void *end)
9068 ".section .discard,\"aw\",@progbits\n" \
9069 DISCARD_ENTRY(1) \
9070 ".previous\n" \
9071- ".section .altinstr_replacement, \"ax\"\n" \
9072+ ".section .altinstr_replacement, \"a\"\n" \
9073 ALTINSTR_REPLACEMENT(newinstr, feature, 1) \
9074 ".previous"
9075
9076@@ -119,7 +119,7 @@ static inline int alternatives_text_reserved(void *start, void *end)
9077 DISCARD_ENTRY(1) \
9078 DISCARD_ENTRY(2) \
9079 ".previous\n" \
9080- ".section .altinstr_replacement, \"ax\"\n" \
9081+ ".section .altinstr_replacement, \"a\"\n" \
9082 ALTINSTR_REPLACEMENT(newinstr1, feature1, 1) \
9083 ALTINSTR_REPLACEMENT(newinstr2, feature2, 2) \
9084 ".previous"
9085diff --git a/arch/x86/include/asm/apic.h b/arch/x86/include/asm/apic.h
9086index f342612..b3fe911 100644
9087--- a/arch/x86/include/asm/apic.h
9088+++ b/arch/x86/include/asm/apic.h
9089@@ -44,7 +44,7 @@ static inline void generic_apic_probe(void)
9090
9091 #ifdef CONFIG_X86_LOCAL_APIC
9092
9093-extern unsigned int apic_verbosity;
9094+extern int apic_verbosity;
9095 extern int local_apic_timer_c2_ok;
9096
9097 extern int disable_apic;
9098@@ -391,7 +391,7 @@ struct apic {
9099 */
9100 int (*x86_32_numa_cpu_node)(int cpu);
9101 #endif
9102-};
9103+} __do_const;
9104
9105 /*
9106 * Pointer to the local APIC driver in use on this system (there's
9107diff --git a/arch/x86/include/asm/apm.h b/arch/x86/include/asm/apm.h
9108index 20370c6..a2eb9b0 100644
9109--- a/arch/x86/include/asm/apm.h
9110+++ b/arch/x86/include/asm/apm.h
9111@@ -34,7 +34,7 @@ static inline void apm_bios_call_asm(u32 func, u32 ebx_in, u32 ecx_in,
9112 __asm__ __volatile__(APM_DO_ZERO_SEGS
9113 "pushl %%edi\n\t"
9114 "pushl %%ebp\n\t"
9115- "lcall *%%cs:apm_bios_entry\n\t"
9116+ "lcall *%%ss:apm_bios_entry\n\t"
9117 "setc %%al\n\t"
9118 "popl %%ebp\n\t"
9119 "popl %%edi\n\t"
9120@@ -58,7 +58,7 @@ static inline u8 apm_bios_call_simple_asm(u32 func, u32 ebx_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 %%bl\n\t"
9127 "popl %%ebp\n\t"
9128 "popl %%edi\n\t"
9129diff --git a/arch/x86/include/asm/atomic.h b/arch/x86/include/asm/atomic.h
9130index 58cb6d4..a4b806c 100644
9131--- a/arch/x86/include/asm/atomic.h
9132+++ b/arch/x86/include/asm/atomic.h
9133@@ -22,7 +22,18 @@
9134 */
9135 static inline int atomic_read(const atomic_t *v)
9136 {
9137- return (*(volatile int *)&(v)->counter);
9138+ return (*(volatile const int *)&(v)->counter);
9139+}
9140+
9141+/**
9142+ * atomic_read_unchecked - read atomic variable
9143+ * @v: pointer of type atomic_unchecked_t
9144+ *
9145+ * Atomically reads the value of @v.
9146+ */
9147+static inline int atomic_read_unchecked(const atomic_unchecked_t *v)
9148+{
9149+ return (*(volatile const int *)&(v)->counter);
9150 }
9151
9152 /**
9153@@ -38,6 +49,18 @@ static inline void atomic_set(atomic_t *v, int i)
9154 }
9155
9156 /**
9157+ * atomic_set_unchecked - set atomic variable
9158+ * @v: pointer of type atomic_unchecked_t
9159+ * @i: required value
9160+ *
9161+ * Atomically sets the value of @v to @i.
9162+ */
9163+static inline void atomic_set_unchecked(atomic_unchecked_t *v, int i)
9164+{
9165+ v->counter = i;
9166+}
9167+
9168+/**
9169 * atomic_add - add integer to atomic variable
9170 * @i: integer value to add
9171 * @v: pointer of type atomic_t
9172@@ -46,7 +69,29 @@ static inline void atomic_set(atomic_t *v, int i)
9173 */
9174 static inline void atomic_add(int i, atomic_t *v)
9175 {
9176- asm volatile(LOCK_PREFIX "addl %1,%0"
9177+ asm volatile(LOCK_PREFIX "addl %1,%0\n"
9178+
9179+#ifdef CONFIG_PAX_REFCOUNT
9180+ "jno 0f\n"
9181+ LOCK_PREFIX "subl %1,%0\n"
9182+ "int $4\n0:\n"
9183+ _ASM_EXTABLE(0b, 0b)
9184+#endif
9185+
9186+ : "+m" (v->counter)
9187+ : "ir" (i));
9188+}
9189+
9190+/**
9191+ * atomic_add_unchecked - add integer to atomic variable
9192+ * @i: integer value to add
9193+ * @v: pointer of type atomic_unchecked_t
9194+ *
9195+ * Atomically adds @i to @v.
9196+ */
9197+static inline void atomic_add_unchecked(int i, atomic_unchecked_t *v)
9198+{
9199+ asm volatile(LOCK_PREFIX "addl %1,%0\n"
9200 : "+m" (v->counter)
9201 : "ir" (i));
9202 }
9203@@ -60,7 +105,29 @@ static inline void atomic_add(int i, atomic_t *v)
9204 */
9205 static inline void atomic_sub(int i, atomic_t *v)
9206 {
9207- asm volatile(LOCK_PREFIX "subl %1,%0"
9208+ asm volatile(LOCK_PREFIX "subl %1,%0\n"
9209+
9210+#ifdef CONFIG_PAX_REFCOUNT
9211+ "jno 0f\n"
9212+ LOCK_PREFIX "addl %1,%0\n"
9213+ "int $4\n0:\n"
9214+ _ASM_EXTABLE(0b, 0b)
9215+#endif
9216+
9217+ : "+m" (v->counter)
9218+ : "ir" (i));
9219+}
9220+
9221+/**
9222+ * atomic_sub_unchecked - subtract integer from atomic variable
9223+ * @i: integer value to subtract
9224+ * @v: pointer of type atomic_unchecked_t
9225+ *
9226+ * Atomically subtracts @i from @v.
9227+ */
9228+static inline void atomic_sub_unchecked(int i, atomic_unchecked_t *v)
9229+{
9230+ asm volatile(LOCK_PREFIX "subl %1,%0\n"
9231 : "+m" (v->counter)
9232 : "ir" (i));
9233 }
9234@@ -78,7 +145,16 @@ static inline int atomic_sub_and_test(int i, atomic_t *v)
9235 {
9236 unsigned char c;
9237
9238- asm volatile(LOCK_PREFIX "subl %2,%0; sete %1"
9239+ asm volatile(LOCK_PREFIX "subl %2,%0\n"
9240+
9241+#ifdef CONFIG_PAX_REFCOUNT
9242+ "jno 0f\n"
9243+ LOCK_PREFIX "addl %2,%0\n"
9244+ "int $4\n0:\n"
9245+ _ASM_EXTABLE(0b, 0b)
9246+#endif
9247+
9248+ "sete %1\n"
9249 : "+m" (v->counter), "=qm" (c)
9250 : "ir" (i) : "memory");
9251 return c;
9252@@ -92,7 +168,27 @@ static inline int atomic_sub_and_test(int i, atomic_t *v)
9253 */
9254 static inline void atomic_inc(atomic_t *v)
9255 {
9256- asm volatile(LOCK_PREFIX "incl %0"
9257+ asm volatile(LOCK_PREFIX "incl %0\n"
9258+
9259+#ifdef CONFIG_PAX_REFCOUNT
9260+ "jno 0f\n"
9261+ LOCK_PREFIX "decl %0\n"
9262+ "int $4\n0:\n"
9263+ _ASM_EXTABLE(0b, 0b)
9264+#endif
9265+
9266+ : "+m" (v->counter));
9267+}
9268+
9269+/**
9270+ * atomic_inc_unchecked - increment atomic variable
9271+ * @v: pointer of type atomic_unchecked_t
9272+ *
9273+ * Atomically increments @v by 1.
9274+ */
9275+static inline void atomic_inc_unchecked(atomic_unchecked_t *v)
9276+{
9277+ asm volatile(LOCK_PREFIX "incl %0\n"
9278 : "+m" (v->counter));
9279 }
9280
9281@@ -104,7 +200,27 @@ static inline void atomic_inc(atomic_t *v)
9282 */
9283 static inline void atomic_dec(atomic_t *v)
9284 {
9285- asm volatile(LOCK_PREFIX "decl %0"
9286+ asm volatile(LOCK_PREFIX "decl %0\n"
9287+
9288+#ifdef CONFIG_PAX_REFCOUNT
9289+ "jno 0f\n"
9290+ LOCK_PREFIX "incl %0\n"
9291+ "int $4\n0:\n"
9292+ _ASM_EXTABLE(0b, 0b)
9293+#endif
9294+
9295+ : "+m" (v->counter));
9296+}
9297+
9298+/**
9299+ * atomic_dec_unchecked - decrement atomic variable
9300+ * @v: pointer of type atomic_unchecked_t
9301+ *
9302+ * Atomically decrements @v by 1.
9303+ */
9304+static inline void atomic_dec_unchecked(atomic_unchecked_t *v)
9305+{
9306+ asm volatile(LOCK_PREFIX "decl %0\n"
9307 : "+m" (v->counter));
9308 }
9309
9310@@ -120,7 +236,16 @@ static inline int atomic_dec_and_test(atomic_t *v)
9311 {
9312 unsigned char c;
9313
9314- asm volatile(LOCK_PREFIX "decl %0; sete %1"
9315+ asm volatile(LOCK_PREFIX "decl %0\n"
9316+
9317+#ifdef CONFIG_PAX_REFCOUNT
9318+ "jno 0f\n"
9319+ LOCK_PREFIX "incl %0\n"
9320+ "int $4\n0:\n"
9321+ _ASM_EXTABLE(0b, 0b)
9322+#endif
9323+
9324+ "sete %1\n"
9325 : "+m" (v->counter), "=qm" (c)
9326 : : "memory");
9327 return c != 0;
9328@@ -138,7 +263,35 @@ static inline int atomic_inc_and_test(atomic_t *v)
9329 {
9330 unsigned char c;
9331
9332- asm volatile(LOCK_PREFIX "incl %0; sete %1"
9333+ asm volatile(LOCK_PREFIX "incl %0\n"
9334+
9335+#ifdef CONFIG_PAX_REFCOUNT
9336+ "jno 0f\n"
9337+ LOCK_PREFIX "decl %0\n"
9338+ "int $4\n0:\n"
9339+ _ASM_EXTABLE(0b, 0b)
9340+#endif
9341+
9342+ "sete %1\n"
9343+ : "+m" (v->counter), "=qm" (c)
9344+ : : "memory");
9345+ return c != 0;
9346+}
9347+
9348+/**
9349+ * atomic_inc_and_test_unchecked - increment and test
9350+ * @v: pointer of type atomic_unchecked_t
9351+ *
9352+ * Atomically increments @v by 1
9353+ * and returns true if the result is zero, or false for all
9354+ * other cases.
9355+ */
9356+static inline int atomic_inc_and_test_unchecked(atomic_unchecked_t *v)
9357+{
9358+ unsigned char c;
9359+
9360+ asm volatile(LOCK_PREFIX "incl %0\n"
9361+ "sete %1\n"
9362 : "+m" (v->counter), "=qm" (c)
9363 : : "memory");
9364 return c != 0;
9365@@ -157,7 +310,16 @@ static inline int atomic_add_negative(int i, atomic_t *v)
9366 {
9367 unsigned char c;
9368
9369- asm volatile(LOCK_PREFIX "addl %2,%0; sets %1"
9370+ asm volatile(LOCK_PREFIX "addl %2,%0\n"
9371+
9372+#ifdef CONFIG_PAX_REFCOUNT
9373+ "jno 0f\n"
9374+ LOCK_PREFIX "subl %2,%0\n"
9375+ "int $4\n0:\n"
9376+ _ASM_EXTABLE(0b, 0b)
9377+#endif
9378+
9379+ "sets %1\n"
9380 : "+m" (v->counter), "=qm" (c)
9381 : "ir" (i) : "memory");
9382 return c;
9383@@ -179,7 +341,7 @@ static inline int atomic_add_return(int i, atomic_t *v)
9384 goto no_xadd;
9385 #endif
9386 /* Modern 486+ processor */
9387- return i + xadd(&v->counter, i);
9388+ return i + xadd_check_overflow(&v->counter, i);
9389
9390 #ifdef CONFIG_M386
9391 no_xadd: /* Legacy 386 processor */
9392@@ -192,6 +354,34 @@ no_xadd: /* Legacy 386 processor */
9393 }
9394
9395 /**
9396+ * atomic_add_return_unchecked - add integer and return
9397+ * @i: integer value to add
9398+ * @v: pointer of type atomic_unchecked_t
9399+ *
9400+ * Atomically adds @i to @v and returns @i + @v
9401+ */
9402+static inline int atomic_add_return_unchecked(int i, atomic_unchecked_t *v)
9403+{
9404+#ifdef CONFIG_M386
9405+ int __i;
9406+ unsigned long flags;
9407+ if (unlikely(boot_cpu_data.x86 <= 3))
9408+ goto no_xadd;
9409+#endif
9410+ /* Modern 486+ processor */
9411+ return i + xadd(&v->counter, i);
9412+
9413+#ifdef CONFIG_M386
9414+no_xadd: /* Legacy 386 processor */
9415+ raw_local_irq_save(flags);
9416+ __i = atomic_read_unchecked(v);
9417+ atomic_set_unchecked(v, i + __i);
9418+ raw_local_irq_restore(flags);
9419+ return i + __i;
9420+#endif
9421+}
9422+
9423+/**
9424 * atomic_sub_return - subtract integer and return
9425 * @v: pointer of type atomic_t
9426 * @i: integer value to subtract
9427@@ -204,6 +394,10 @@ static inline int atomic_sub_return(int i, atomic_t *v)
9428 }
9429
9430 #define atomic_inc_return(v) (atomic_add_return(1, v))
9431+static inline int atomic_inc_return_unchecked(atomic_unchecked_t *v)
9432+{
9433+ return atomic_add_return_unchecked(1, v);
9434+}
9435 #define atomic_dec_return(v) (atomic_sub_return(1, v))
9436
9437 static inline int atomic_cmpxchg(atomic_t *v, int old, int new)
9438@@ -211,11 +405,21 @@ static inline int atomic_cmpxchg(atomic_t *v, int old, int new)
9439 return cmpxchg(&v->counter, old, new);
9440 }
9441
9442+static inline int atomic_cmpxchg_unchecked(atomic_unchecked_t *v, int old, int new)
9443+{
9444+ return cmpxchg(&v->counter, old, new);
9445+}
9446+
9447 static inline int atomic_xchg(atomic_t *v, int new)
9448 {
9449 return xchg(&v->counter, new);
9450 }
9451
9452+static inline int atomic_xchg_unchecked(atomic_unchecked_t *v, int new)
9453+{
9454+ return xchg(&v->counter, new);
9455+}
9456+
9457 /**
9458 * __atomic_add_unless - add unless the number is already a given value
9459 * @v: pointer of type atomic_t
9460@@ -227,12 +431,25 @@ static inline int atomic_xchg(atomic_t *v, int new)
9461 */
9462 static inline int __atomic_add_unless(atomic_t *v, int a, int u)
9463 {
9464- int c, old;
9465+ int c, old, new;
9466 c = atomic_read(v);
9467 for (;;) {
9468- if (unlikely(c == (u)))
9469+ if (unlikely(c == u))
9470 break;
9471- old = atomic_cmpxchg((v), c, c + (a));
9472+
9473+ asm volatile("addl %2,%0\n"
9474+
9475+#ifdef CONFIG_PAX_REFCOUNT
9476+ "jno 0f\n"
9477+ "subl %2,%0\n"
9478+ "int $4\n0:\n"
9479+ _ASM_EXTABLE(0b, 0b)
9480+#endif
9481+
9482+ : "=r" (new)
9483+ : "0" (c), "ir" (a));
9484+
9485+ old = atomic_cmpxchg(v, c, new);
9486 if (likely(old == c))
9487 break;
9488 c = old;
9489@@ -240,6 +457,48 @@ static inline int __atomic_add_unless(atomic_t *v, int a, int u)
9490 return c;
9491 }
9492
9493+/**
9494+ * atomic_inc_not_zero_hint - increment if not null
9495+ * @v: pointer of type atomic_t
9496+ * @hint: probable value of the atomic before the increment
9497+ *
9498+ * This version of atomic_inc_not_zero() gives a hint of probable
9499+ * value of the atomic. This helps processor to not read the memory
9500+ * before doing the atomic read/modify/write cycle, lowering
9501+ * number of bus transactions on some arches.
9502+ *
9503+ * Returns: 0 if increment was not done, 1 otherwise.
9504+ */
9505+#define atomic_inc_not_zero_hint atomic_inc_not_zero_hint
9506+static inline int atomic_inc_not_zero_hint(atomic_t *v, int hint)
9507+{
9508+ int val, c = hint, new;
9509+
9510+ /* sanity test, should be removed by compiler if hint is a constant */
9511+ if (!hint)
9512+ return __atomic_add_unless(v, 1, 0);
9513+
9514+ do {
9515+ asm volatile("incl %0\n"
9516+
9517+#ifdef CONFIG_PAX_REFCOUNT
9518+ "jno 0f\n"
9519+ "decl %0\n"
9520+ "int $4\n0:\n"
9521+ _ASM_EXTABLE(0b, 0b)
9522+#endif
9523+
9524+ : "=r" (new)
9525+ : "0" (c));
9526+
9527+ val = atomic_cmpxchg(v, c, new);
9528+ if (val == c)
9529+ return 1;
9530+ c = val;
9531+ } while (c);
9532+
9533+ return 0;
9534+}
9535
9536 /*
9537 * atomic_dec_if_positive - decrement by 1 if old value positive
9538@@ -293,14 +552,37 @@ static inline void atomic_or_long(unsigned long *v1, unsigned long v2)
9539 #endif
9540
9541 /* These are x86-specific, used by some header files */
9542-#define atomic_clear_mask(mask, addr) \
9543- asm volatile(LOCK_PREFIX "andl %0,%1" \
9544- : : "r" (~(mask)), "m" (*(addr)) : "memory")
9545+static inline void atomic_clear_mask(unsigned int mask, atomic_t *v)
9546+{
9547+ asm volatile(LOCK_PREFIX "andl %1,%0"
9548+ : "+m" (v->counter)
9549+ : "r" (~(mask))
9550+ : "memory");
9551+}
9552
9553-#define atomic_set_mask(mask, addr) \
9554- asm volatile(LOCK_PREFIX "orl %0,%1" \
9555- : : "r" ((unsigned)(mask)), "m" (*(addr)) \
9556- : "memory")
9557+static inline void atomic_clear_mask_unchecked(unsigned int mask, atomic_unchecked_t *v)
9558+{
9559+ asm volatile(LOCK_PREFIX "andl %1,%0"
9560+ : "+m" (v->counter)
9561+ : "r" (~(mask))
9562+ : "memory");
9563+}
9564+
9565+static inline void atomic_set_mask(unsigned int mask, atomic_t *v)
9566+{
9567+ asm volatile(LOCK_PREFIX "orl %1,%0"
9568+ : "+m" (v->counter)
9569+ : "r" (mask)
9570+ : "memory");
9571+}
9572+
9573+static inline void atomic_set_mask_unchecked(unsigned int mask, atomic_unchecked_t *v)
9574+{
9575+ asm volatile(LOCK_PREFIX "orl %1,%0"
9576+ : "+m" (v->counter)
9577+ : "r" (mask)
9578+ : "memory");
9579+}
9580
9581 /* Atomic operations are already serializing on x86 */
9582 #define smp_mb__before_atomic_dec() barrier()
9583diff --git a/arch/x86/include/asm/atomic64_32.h b/arch/x86/include/asm/atomic64_32.h
9584index b154de7..aadebd8 100644
9585--- a/arch/x86/include/asm/atomic64_32.h
9586+++ b/arch/x86/include/asm/atomic64_32.h
9587@@ -12,6 +12,14 @@ typedef struct {
9588 u64 __aligned(8) counter;
9589 } atomic64_t;
9590
9591+#ifdef CONFIG_PAX_REFCOUNT
9592+typedef struct {
9593+ u64 __aligned(8) counter;
9594+} atomic64_unchecked_t;
9595+#else
9596+typedef atomic64_t atomic64_unchecked_t;
9597+#endif
9598+
9599 #define ATOMIC64_INIT(val) { (val) }
9600
9601 #define __ATOMIC64_DECL(sym) void atomic64_##sym(atomic64_t *, ...)
9602@@ -37,21 +45,31 @@ typedef struct {
9603 ATOMIC64_DECL_ONE(sym##_386)
9604
9605 ATOMIC64_DECL_ONE(add_386);
9606+ATOMIC64_DECL_ONE(add_unchecked_386);
9607 ATOMIC64_DECL_ONE(sub_386);
9608+ATOMIC64_DECL_ONE(sub_unchecked_386);
9609 ATOMIC64_DECL_ONE(inc_386);
9610+ATOMIC64_DECL_ONE(inc_unchecked_386);
9611 ATOMIC64_DECL_ONE(dec_386);
9612+ATOMIC64_DECL_ONE(dec_unchecked_386);
9613 #endif
9614
9615 #define alternative_atomic64(f, out, in...) \
9616 __alternative_atomic64(f, f, ASM_OUTPUT2(out), ## in)
9617
9618 ATOMIC64_DECL(read);
9619+ATOMIC64_DECL(read_unchecked);
9620 ATOMIC64_DECL(set);
9621+ATOMIC64_DECL(set_unchecked);
9622 ATOMIC64_DECL(xchg);
9623 ATOMIC64_DECL(add_return);
9624+ATOMIC64_DECL(add_return_unchecked);
9625 ATOMIC64_DECL(sub_return);
9626+ATOMIC64_DECL(sub_return_unchecked);
9627 ATOMIC64_DECL(inc_return);
9628+ATOMIC64_DECL(inc_return_unchecked);
9629 ATOMIC64_DECL(dec_return);
9630+ATOMIC64_DECL(dec_return_unchecked);
9631 ATOMIC64_DECL(dec_if_positive);
9632 ATOMIC64_DECL(inc_not_zero);
9633 ATOMIC64_DECL(add_unless);
9634@@ -77,6 +95,21 @@ static inline long long atomic64_cmpxchg(atomic64_t *v, long long o, long long n
9635 }
9636
9637 /**
9638+ * atomic64_cmpxchg_unchecked - cmpxchg atomic64 variable
9639+ * @p: pointer to type atomic64_unchecked_t
9640+ * @o: expected value
9641+ * @n: new value
9642+ *
9643+ * Atomically sets @v to @n if it was equal to @o and returns
9644+ * the old value.
9645+ */
9646+
9647+static inline long long atomic64_cmpxchg_unchecked(atomic64_unchecked_t *v, long long o, long long n)
9648+{
9649+ return cmpxchg64(&v->counter, o, n);
9650+}
9651+
9652+/**
9653 * atomic64_xchg - xchg atomic64 variable
9654 * @v: pointer to type atomic64_t
9655 * @n: value to assign
9656@@ -112,6 +145,22 @@ static inline void atomic64_set(atomic64_t *v, long long i)
9657 }
9658
9659 /**
9660+ * atomic64_set_unchecked - set atomic64 variable
9661+ * @v: pointer to type atomic64_unchecked_t
9662+ * @n: value to assign
9663+ *
9664+ * Atomically sets the value of @v to @n.
9665+ */
9666+static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, long long i)
9667+{
9668+ unsigned high = (unsigned)(i >> 32);
9669+ unsigned low = (unsigned)i;
9670+ alternative_atomic64(set, /* no output */,
9671+ "S" (v), "b" (low), "c" (high)
9672+ : "eax", "edx", "memory");
9673+}
9674+
9675+/**
9676 * atomic64_read - read atomic64 variable
9677 * @v: pointer to type atomic64_t
9678 *
9679@@ -125,6 +174,19 @@ static inline long long atomic64_read(const atomic64_t *v)
9680 }
9681
9682 /**
9683+ * atomic64_read_unchecked - read atomic64 variable
9684+ * @v: pointer to type atomic64_unchecked_t
9685+ *
9686+ * Atomically reads the value of @v and returns it.
9687+ */
9688+static inline long long atomic64_read_unchecked(atomic64_unchecked_t *v)
9689+{
9690+ long long r;
9691+ alternative_atomic64(read, "=&A" (r), "c" (v) : "memory");
9692+ return r;
9693+ }
9694+
9695+/**
9696 * atomic64_add_return - add and return
9697 * @i: integer value to add
9698 * @v: pointer to type atomic64_t
9699@@ -139,6 +201,21 @@ static inline long long atomic64_add_return(long long i, atomic64_t *v)
9700 return i;
9701 }
9702
9703+/**
9704+ * atomic64_add_return_unchecked - add and return
9705+ * @i: integer value to add
9706+ * @v: pointer to type atomic64_unchecked_t
9707+ *
9708+ * Atomically adds @i to @v and returns @i + *@v
9709+ */
9710+static inline long long atomic64_add_return_unchecked(long long i, atomic64_unchecked_t *v)
9711+{
9712+ alternative_atomic64(add_return_unchecked,
9713+ ASM_OUTPUT2("+A" (i), "+c" (v)),
9714+ ASM_NO_INPUT_CLOBBER("memory"));
9715+ return i;
9716+}
9717+
9718 /*
9719 * Other variants with different arithmetic operators:
9720 */
9721@@ -158,6 +235,14 @@ static inline long long atomic64_inc_return(atomic64_t *v)
9722 return a;
9723 }
9724
9725+static inline long long atomic64_inc_return_unchecked(atomic64_unchecked_t *v)
9726+{
9727+ long long a;
9728+ alternative_atomic64(inc_return_unchecked, "=&A" (a),
9729+ "S" (v) : "memory", "ecx");
9730+ return a;
9731+}
9732+
9733 static inline long long atomic64_dec_return(atomic64_t *v)
9734 {
9735 long long a;
9736@@ -182,6 +267,21 @@ static inline long long atomic64_add(long long i, atomic64_t *v)
9737 }
9738
9739 /**
9740+ * atomic64_add_unchecked - add integer to atomic64 variable
9741+ * @i: integer value to add
9742+ * @v: pointer to type atomic64_unchecked_t
9743+ *
9744+ * Atomically adds @i to @v.
9745+ */
9746+static inline long long atomic64_add_unchecked(long long i, atomic64_unchecked_t *v)
9747+{
9748+ __alternative_atomic64(add_unchecked, add_return_unchecked,
9749+ ASM_OUTPUT2("+A" (i), "+c" (v)),
9750+ ASM_NO_INPUT_CLOBBER("memory"));
9751+ return i;
9752+}
9753+
9754+/**
9755 * atomic64_sub - subtract the atomic64 variable
9756 * @i: integer value to subtract
9757 * @v: pointer to type atomic64_t
9758diff --git a/arch/x86/include/asm/atomic64_64.h b/arch/x86/include/asm/atomic64_64.h
9759index 0e1cbfc..5623683 100644
9760--- a/arch/x86/include/asm/atomic64_64.h
9761+++ b/arch/x86/include/asm/atomic64_64.h
9762@@ -18,7 +18,19 @@
9763 */
9764 static inline long atomic64_read(const atomic64_t *v)
9765 {
9766- return (*(volatile long *)&(v)->counter);
9767+ return (*(volatile const long *)&(v)->counter);
9768+}
9769+
9770+/**
9771+ * atomic64_read_unchecked - read atomic64 variable
9772+ * @v: pointer of type atomic64_unchecked_t
9773+ *
9774+ * Atomically reads the value of @v.
9775+ * Doesn't imply a read memory barrier.
9776+ */
9777+static inline long atomic64_read_unchecked(const atomic64_unchecked_t *v)
9778+{
9779+ return (*(volatile const long *)&(v)->counter);
9780 }
9781
9782 /**
9783@@ -34,6 +46,18 @@ static inline void atomic64_set(atomic64_t *v, long i)
9784 }
9785
9786 /**
9787+ * atomic64_set_unchecked - set atomic64 variable
9788+ * @v: pointer to type atomic64_unchecked_t
9789+ * @i: required value
9790+ *
9791+ * Atomically sets the value of @v to @i.
9792+ */
9793+static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, long i)
9794+{
9795+ v->counter = i;
9796+}
9797+
9798+/**
9799 * atomic64_add - add integer to atomic64 variable
9800 * @i: integer value to add
9801 * @v: pointer to type atomic64_t
9802@@ -42,6 +66,28 @@ static inline void atomic64_set(atomic64_t *v, long i)
9803 */
9804 static inline void atomic64_add(long i, atomic64_t *v)
9805 {
9806+ asm volatile(LOCK_PREFIX "addq %1,%0\n"
9807+
9808+#ifdef CONFIG_PAX_REFCOUNT
9809+ "jno 0f\n"
9810+ LOCK_PREFIX "subq %1,%0\n"
9811+ "int $4\n0:\n"
9812+ _ASM_EXTABLE(0b, 0b)
9813+#endif
9814+
9815+ : "=m" (v->counter)
9816+ : "er" (i), "m" (v->counter));
9817+}
9818+
9819+/**
9820+ * atomic64_add_unchecked - add integer to atomic64 variable
9821+ * @i: integer value to add
9822+ * @v: pointer to type atomic64_unchecked_t
9823+ *
9824+ * Atomically adds @i to @v.
9825+ */
9826+static inline void atomic64_add_unchecked(long i, atomic64_unchecked_t *v)
9827+{
9828 asm volatile(LOCK_PREFIX "addq %1,%0"
9829 : "=m" (v->counter)
9830 : "er" (i), "m" (v->counter));
9831@@ -56,7 +102,29 @@ static inline void atomic64_add(long i, atomic64_t *v)
9832 */
9833 static inline void atomic64_sub(long i, atomic64_t *v)
9834 {
9835- asm volatile(LOCK_PREFIX "subq %1,%0"
9836+ asm volatile(LOCK_PREFIX "subq %1,%0\n"
9837+
9838+#ifdef CONFIG_PAX_REFCOUNT
9839+ "jno 0f\n"
9840+ LOCK_PREFIX "addq %1,%0\n"
9841+ "int $4\n0:\n"
9842+ _ASM_EXTABLE(0b, 0b)
9843+#endif
9844+
9845+ : "=m" (v->counter)
9846+ : "er" (i), "m" (v->counter));
9847+}
9848+
9849+/**
9850+ * atomic64_sub_unchecked - subtract the atomic64 variable
9851+ * @i: integer value to subtract
9852+ * @v: pointer to type atomic64_unchecked_t
9853+ *
9854+ * Atomically subtracts @i from @v.
9855+ */
9856+static inline void atomic64_sub_unchecked(long i, atomic64_unchecked_t *v)
9857+{
9858+ asm volatile(LOCK_PREFIX "subq %1,%0\n"
9859 : "=m" (v->counter)
9860 : "er" (i), "m" (v->counter));
9861 }
9862@@ -74,7 +142,16 @@ static inline int atomic64_sub_and_test(long i, atomic64_t *v)
9863 {
9864 unsigned char c;
9865
9866- asm volatile(LOCK_PREFIX "subq %2,%0; sete %1"
9867+ asm volatile(LOCK_PREFIX "subq %2,%0\n"
9868+
9869+#ifdef CONFIG_PAX_REFCOUNT
9870+ "jno 0f\n"
9871+ LOCK_PREFIX "addq %2,%0\n"
9872+ "int $4\n0:\n"
9873+ _ASM_EXTABLE(0b, 0b)
9874+#endif
9875+
9876+ "sete %1\n"
9877 : "=m" (v->counter), "=qm" (c)
9878 : "er" (i), "m" (v->counter) : "memory");
9879 return c;
9880@@ -88,6 +165,27 @@ static inline int atomic64_sub_and_test(long i, atomic64_t *v)
9881 */
9882 static inline void atomic64_inc(atomic64_t *v)
9883 {
9884+ asm volatile(LOCK_PREFIX "incq %0\n"
9885+
9886+#ifdef CONFIG_PAX_REFCOUNT
9887+ "jno 0f\n"
9888+ LOCK_PREFIX "decq %0\n"
9889+ "int $4\n0:\n"
9890+ _ASM_EXTABLE(0b, 0b)
9891+#endif
9892+
9893+ : "=m" (v->counter)
9894+ : "m" (v->counter));
9895+}
9896+
9897+/**
9898+ * atomic64_inc_unchecked - increment atomic64 variable
9899+ * @v: pointer to type atomic64_unchecked_t
9900+ *
9901+ * Atomically increments @v by 1.
9902+ */
9903+static inline void atomic64_inc_unchecked(atomic64_unchecked_t *v)
9904+{
9905 asm volatile(LOCK_PREFIX "incq %0"
9906 : "=m" (v->counter)
9907 : "m" (v->counter));
9908@@ -101,7 +199,28 @@ static inline void atomic64_inc(atomic64_t *v)
9909 */
9910 static inline void atomic64_dec(atomic64_t *v)
9911 {
9912- asm volatile(LOCK_PREFIX "decq %0"
9913+ asm volatile(LOCK_PREFIX "decq %0\n"
9914+
9915+#ifdef CONFIG_PAX_REFCOUNT
9916+ "jno 0f\n"
9917+ LOCK_PREFIX "incq %0\n"
9918+ "int $4\n0:\n"
9919+ _ASM_EXTABLE(0b, 0b)
9920+#endif
9921+
9922+ : "=m" (v->counter)
9923+ : "m" (v->counter));
9924+}
9925+
9926+/**
9927+ * atomic64_dec_unchecked - decrement atomic64 variable
9928+ * @v: pointer to type atomic64_t
9929+ *
9930+ * Atomically decrements @v by 1.
9931+ */
9932+static inline void atomic64_dec_unchecked(atomic64_unchecked_t *v)
9933+{
9934+ asm volatile(LOCK_PREFIX "decq %0\n"
9935 : "=m" (v->counter)
9936 : "m" (v->counter));
9937 }
9938@@ -118,7 +237,16 @@ static inline int atomic64_dec_and_test(atomic64_t *v)
9939 {
9940 unsigned char c;
9941
9942- asm volatile(LOCK_PREFIX "decq %0; sete %1"
9943+ asm volatile(LOCK_PREFIX "decq %0\n"
9944+
9945+#ifdef CONFIG_PAX_REFCOUNT
9946+ "jno 0f\n"
9947+ LOCK_PREFIX "incq %0\n"
9948+ "int $4\n0:\n"
9949+ _ASM_EXTABLE(0b, 0b)
9950+#endif
9951+
9952+ "sete %1\n"
9953 : "=m" (v->counter), "=qm" (c)
9954 : "m" (v->counter) : "memory");
9955 return c != 0;
9956@@ -136,7 +264,16 @@ static inline int atomic64_inc_and_test(atomic64_t *v)
9957 {
9958 unsigned char c;
9959
9960- asm volatile(LOCK_PREFIX "incq %0; sete %1"
9961+ asm volatile(LOCK_PREFIX "incq %0\n"
9962+
9963+#ifdef CONFIG_PAX_REFCOUNT
9964+ "jno 0f\n"
9965+ LOCK_PREFIX "decq %0\n"
9966+ "int $4\n0:\n"
9967+ _ASM_EXTABLE(0b, 0b)
9968+#endif
9969+
9970+ "sete %1\n"
9971 : "=m" (v->counter), "=qm" (c)
9972 : "m" (v->counter) : "memory");
9973 return c != 0;
9974@@ -155,7 +292,16 @@ static inline int atomic64_add_negative(long i, atomic64_t *v)
9975 {
9976 unsigned char c;
9977
9978- asm volatile(LOCK_PREFIX "addq %2,%0; sets %1"
9979+ asm volatile(LOCK_PREFIX "addq %2,%0\n"
9980+
9981+#ifdef CONFIG_PAX_REFCOUNT
9982+ "jno 0f\n"
9983+ LOCK_PREFIX "subq %2,%0\n"
9984+ "int $4\n0:\n"
9985+ _ASM_EXTABLE(0b, 0b)
9986+#endif
9987+
9988+ "sets %1\n"
9989 : "=m" (v->counter), "=qm" (c)
9990 : "er" (i), "m" (v->counter) : "memory");
9991 return c;
9992@@ -170,6 +316,18 @@ static inline int atomic64_add_negative(long i, atomic64_t *v)
9993 */
9994 static inline long atomic64_add_return(long i, atomic64_t *v)
9995 {
9996+ return i + xadd_check_overflow(&v->counter, i);
9997+}
9998+
9999+/**
10000+ * atomic64_add_return_unchecked - add and return
10001+ * @i: integer value to add
10002+ * @v: pointer to type atomic64_unchecked_t
10003+ *
10004+ * Atomically adds @i to @v and returns @i + @v
10005+ */
10006+static inline long atomic64_add_return_unchecked(long i, atomic64_unchecked_t *v)
10007+{
10008 return i + xadd(&v->counter, i);
10009 }
10010
10011@@ -179,6 +337,10 @@ static inline long atomic64_sub_return(long i, atomic64_t *v)
10012 }
10013
10014 #define atomic64_inc_return(v) (atomic64_add_return(1, (v)))
10015+static inline long atomic64_inc_return_unchecked(atomic64_unchecked_t *v)
10016+{
10017+ return atomic64_add_return_unchecked(1, v);
10018+}
10019 #define atomic64_dec_return(v) (atomic64_sub_return(1, (v)))
10020
10021 static inline long atomic64_cmpxchg(atomic64_t *v, long old, long new)
10022@@ -186,6 +348,11 @@ static inline long atomic64_cmpxchg(atomic64_t *v, long old, long new)
10023 return cmpxchg(&v->counter, old, new);
10024 }
10025
10026+static inline long atomic64_cmpxchg_unchecked(atomic64_unchecked_t *v, long old, long new)
10027+{
10028+ return cmpxchg(&v->counter, old, new);
10029+}
10030+
10031 static inline long atomic64_xchg(atomic64_t *v, long new)
10032 {
10033 return xchg(&v->counter, new);
10034@@ -202,17 +369,30 @@ static inline long atomic64_xchg(atomic64_t *v, long new)
10035 */
10036 static inline int atomic64_add_unless(atomic64_t *v, long a, long u)
10037 {
10038- long c, old;
10039+ long c, old, new;
10040 c = atomic64_read(v);
10041 for (;;) {
10042- if (unlikely(c == (u)))
10043+ if (unlikely(c == u))
10044 break;
10045- old = atomic64_cmpxchg((v), c, c + (a));
10046+
10047+ asm volatile("add %2,%0\n"
10048+
10049+#ifdef CONFIG_PAX_REFCOUNT
10050+ "jno 0f\n"
10051+ "sub %2,%0\n"
10052+ "int $4\n0:\n"
10053+ _ASM_EXTABLE(0b, 0b)
10054+#endif
10055+
10056+ : "=r" (new)
10057+ : "0" (c), "ir" (a));
10058+
10059+ old = atomic64_cmpxchg(v, c, new);
10060 if (likely(old == c))
10061 break;
10062 c = old;
10063 }
10064- return c != (u);
10065+ return c != u;
10066 }
10067
10068 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
10069diff --git a/arch/x86/include/asm/bitops.h b/arch/x86/include/asm/bitops.h
10070index 72f5009..2f8b9a9 100644
10071--- a/arch/x86/include/asm/bitops.h
10072+++ b/arch/x86/include/asm/bitops.h
10073@@ -40,7 +40,7 @@
10074 * a mask operation on a byte.
10075 */
10076 #define IS_IMMEDIATE(nr) (__builtin_constant_p(nr))
10077-#define CONST_MASK_ADDR(nr, addr) BITOP_ADDR((void *)(addr) + ((nr)>>3))
10078+#define CONST_MASK_ADDR(nr, addr) BITOP_ADDR((volatile void *)(addr) + ((nr)>>3))
10079 #define CONST_MASK(nr) (1 << ((nr) & 7))
10080
10081 /**
10082diff --git a/arch/x86/include/asm/boot.h b/arch/x86/include/asm/boot.h
10083index b13fe63..0dab13a 100644
10084--- a/arch/x86/include/asm/boot.h
10085+++ b/arch/x86/include/asm/boot.h
10086@@ -11,10 +11,15 @@
10087 #include <asm/pgtable_types.h>
10088
10089 /* Physical address where kernel should be loaded. */
10090-#define LOAD_PHYSICAL_ADDR ((CONFIG_PHYSICAL_START \
10091+#define ____LOAD_PHYSICAL_ADDR ((CONFIG_PHYSICAL_START \
10092 + (CONFIG_PHYSICAL_ALIGN - 1)) \
10093 & ~(CONFIG_PHYSICAL_ALIGN - 1))
10094
10095+#ifndef __ASSEMBLY__
10096+extern unsigned char __LOAD_PHYSICAL_ADDR[];
10097+#define LOAD_PHYSICAL_ADDR ((unsigned long)__LOAD_PHYSICAL_ADDR)
10098+#endif
10099+
10100 /* Minimum kernel alignment, as a power of two */
10101 #ifdef CONFIG_X86_64
10102 #define MIN_KERNEL_ALIGN_LG2 PMD_SHIFT
10103diff --git a/arch/x86/include/asm/cache.h b/arch/x86/include/asm/cache.h
10104index 48f99f1..d78ebf9 100644
10105--- a/arch/x86/include/asm/cache.h
10106+++ b/arch/x86/include/asm/cache.h
10107@@ -5,12 +5,13 @@
10108
10109 /* L1 cache line size */
10110 #define L1_CACHE_SHIFT (CONFIG_X86_L1_CACHE_SHIFT)
10111-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
10112+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
10113
10114 #define __read_mostly __attribute__((__section__(".data..read_mostly")))
10115+#define __read_only __attribute__((__section__(".data..read_only")))
10116
10117 #define INTERNODE_CACHE_SHIFT CONFIG_X86_INTERNODE_CACHE_SHIFT
10118-#define INTERNODE_CACHE_BYTES (1 << INTERNODE_CACHE_SHIFT)
10119+#define INTERNODE_CACHE_BYTES (_AC(1,UL) << INTERNODE_CACHE_SHIFT)
10120
10121 #ifdef CONFIG_X86_VSMP
10122 #ifdef CONFIG_SMP
10123diff --git a/arch/x86/include/asm/cacheflush.h b/arch/x86/include/asm/cacheflush.h
10124index 9863ee3..4a1f8e1 100644
10125--- a/arch/x86/include/asm/cacheflush.h
10126+++ b/arch/x86/include/asm/cacheflush.h
10127@@ -27,7 +27,7 @@ static inline unsigned long get_page_memtype(struct page *pg)
10128 unsigned long pg_flags = pg->flags & _PGMT_MASK;
10129
10130 if (pg_flags == _PGMT_DEFAULT)
10131- return -1;
10132+ return ~0UL;
10133 else if (pg_flags == _PGMT_WC)
10134 return _PAGE_CACHE_WC;
10135 else if (pg_flags == _PGMT_UC_MINUS)
10136diff --git a/arch/x86/include/asm/checksum_32.h b/arch/x86/include/asm/checksum_32.h
10137index 46fc474..b02b0f9 100644
10138--- a/arch/x86/include/asm/checksum_32.h
10139+++ b/arch/x86/include/asm/checksum_32.h
10140@@ -31,6 +31,14 @@ asmlinkage __wsum csum_partial_copy_generic(const void *src, void *dst,
10141 int len, __wsum sum,
10142 int *src_err_ptr, int *dst_err_ptr);
10143
10144+asmlinkage __wsum csum_partial_copy_generic_to_user(const void *src, void *dst,
10145+ int len, __wsum sum,
10146+ int *src_err_ptr, int *dst_err_ptr);
10147+
10148+asmlinkage __wsum csum_partial_copy_generic_from_user(const void *src, void *dst,
10149+ int len, __wsum sum,
10150+ int *src_err_ptr, int *dst_err_ptr);
10151+
10152 /*
10153 * Note: when you get a NULL pointer exception here this means someone
10154 * passed in an incorrect kernel address to one of these functions.
10155@@ -50,7 +58,7 @@ static inline __wsum csum_partial_copy_from_user(const void __user *src,
10156 int *err_ptr)
10157 {
10158 might_sleep();
10159- return csum_partial_copy_generic((__force void *)src, dst,
10160+ return csum_partial_copy_generic_from_user((__force void *)src, dst,
10161 len, sum, err_ptr, NULL);
10162 }
10163
10164@@ -178,7 +186,7 @@ static inline __wsum csum_and_copy_to_user(const void *src,
10165 {
10166 might_sleep();
10167 if (access_ok(VERIFY_WRITE, dst, len))
10168- return csum_partial_copy_generic(src, (__force void *)dst,
10169+ return csum_partial_copy_generic_to_user(src, (__force void *)dst,
10170 len, sum, NULL, err_ptr);
10171
10172 if (len)
10173diff --git a/arch/x86/include/asm/cmpxchg.h b/arch/x86/include/asm/cmpxchg.h
10174index 99480e5..d81165b 100644
10175--- a/arch/x86/include/asm/cmpxchg.h
10176+++ b/arch/x86/include/asm/cmpxchg.h
10177@@ -14,8 +14,12 @@ extern void __cmpxchg_wrong_size(void)
10178 __compiletime_error("Bad argument size for cmpxchg");
10179 extern void __xadd_wrong_size(void)
10180 __compiletime_error("Bad argument size for xadd");
10181+extern void __xadd_check_overflow_wrong_size(void)
10182+ __compiletime_error("Bad argument size for xadd_check_overflow");
10183 extern void __add_wrong_size(void)
10184 __compiletime_error("Bad argument size for add");
10185+extern void __add_check_overflow_wrong_size(void)
10186+ __compiletime_error("Bad argument size for add_check_overflow");
10187
10188 /*
10189 * Constants for operation sizes. On 32-bit, the 64-bit size it set to
10190@@ -67,6 +71,34 @@ extern void __add_wrong_size(void)
10191 __ret; \
10192 })
10193
10194+#define __xchg_op_check_overflow(ptr, arg, op, lock) \
10195+ ({ \
10196+ __typeof__ (*(ptr)) __ret = (arg); \
10197+ switch (sizeof(*(ptr))) { \
10198+ case __X86_CASE_L: \
10199+ asm volatile (lock #op "l %0, %1\n" \
10200+ "jno 0f\n" \
10201+ "mov %0,%1\n" \
10202+ "int $4\n0:\n" \
10203+ _ASM_EXTABLE(0b, 0b) \
10204+ : "+r" (__ret), "+m" (*(ptr)) \
10205+ : : "memory", "cc"); \
10206+ break; \
10207+ case __X86_CASE_Q: \
10208+ asm volatile (lock #op "q %q0, %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+ default: \
10217+ __ ## op ## _check_overflow_wrong_size(); \
10218+ } \
10219+ __ret; \
10220+ })
10221+
10222 /*
10223 * Note: no "lock" prefix even on SMP: xchg always implies lock anyway.
10224 * Since this is generally used to protect other memory information, we
10225@@ -167,6 +199,9 @@ extern void __add_wrong_size(void)
10226 #define xadd_sync(ptr, inc) __xadd((ptr), (inc), "lock; ")
10227 #define xadd_local(ptr, inc) __xadd((ptr), (inc), "")
10228
10229+#define __xadd_check_overflow(ptr, inc, lock) __xchg_op_check_overflow((ptr), (inc), xadd, lock)
10230+#define xadd_check_overflow(ptr, inc) __xadd_check_overflow((ptr), (inc), LOCK_PREFIX)
10231+
10232 #define __add(ptr, inc, lock) \
10233 ({ \
10234 __typeof__ (*(ptr)) __ret = (inc); \
10235diff --git a/arch/x86/include/asm/cpufeature.h b/arch/x86/include/asm/cpufeature.h
10236index 6b7ee5f..9d664b3 100644
10237--- a/arch/x86/include/asm/cpufeature.h
10238+++ b/arch/x86/include/asm/cpufeature.h
10239@@ -202,13 +202,14 @@
10240 #define X86_FEATURE_BMI1 (9*32+ 3) /* 1st group bit manipulation extensions */
10241 #define X86_FEATURE_HLE (9*32+ 4) /* Hardware Lock Elision */
10242 #define X86_FEATURE_AVX2 (9*32+ 5) /* AVX2 instructions */
10243-#define X86_FEATURE_SMEP (9*32+ 7) /* Supervisor Mode Execution Protection */
10244+#define X86_FEATURE_SMEP (9*32+ 7) /* Supervisor Mode Execution Prevention */
10245 #define X86_FEATURE_BMI2 (9*32+ 8) /* 2nd group bit manipulation extensions */
10246 #define X86_FEATURE_ERMS (9*32+ 9) /* Enhanced REP MOVSB/STOSB */
10247 #define X86_FEATURE_INVPCID (9*32+10) /* Invalidate Processor Context ID */
10248 #define X86_FEATURE_RTM (9*32+11) /* Restricted Transactional Memory */
10249 #define X86_FEATURE_RDSEED (9*32+18) /* The RDSEED instruction */
10250 #define X86_FEATURE_ADX (9*32+19) /* The ADCX and ADOX instructions */
10251+#define X86_FEATURE_SMAP (9*32+20) /* Supervisor Mode Access Prevention */
10252
10253 #if defined(__KERNEL__) && !defined(__ASSEMBLY__)
10254
10255@@ -373,7 +374,7 @@ static __always_inline __pure bool __static_cpu_has(u16 bit)
10256 ".section .discard,\"aw\",@progbits\n"
10257 " .byte 0xff + (4f-3f) - (2b-1b)\n" /* size check */
10258 ".previous\n"
10259- ".section .altinstr_replacement,\"ax\"\n"
10260+ ".section .altinstr_replacement,\"a\"\n"
10261 "3: movb $1,%0\n"
10262 "4:\n"
10263 ".previous\n"
10264diff --git a/arch/x86/include/asm/desc.h b/arch/x86/include/asm/desc.h
10265index 8bf1c06..f723dfd 100644
10266--- a/arch/x86/include/asm/desc.h
10267+++ b/arch/x86/include/asm/desc.h
10268@@ -4,6 +4,7 @@
10269 #include <asm/desc_defs.h>
10270 #include <asm/ldt.h>
10271 #include <asm/mmu.h>
10272+#include <asm/pgtable.h>
10273
10274 #include <linux/smp.h>
10275 #include <linux/percpu.h>
10276@@ -17,6 +18,7 @@ static inline void fill_ldt(struct desc_struct *desc, const struct user_desc *in
10277
10278 desc->type = (info->read_exec_only ^ 1) << 1;
10279 desc->type |= info->contents << 2;
10280+ desc->type |= info->seg_not_present ^ 1;
10281
10282 desc->s = 1;
10283 desc->dpl = 0x3;
10284@@ -35,19 +37,14 @@ static inline void fill_ldt(struct desc_struct *desc, const struct user_desc *in
10285 }
10286
10287 extern struct desc_ptr idt_descr;
10288-extern gate_desc idt_table[];
10289 extern struct desc_ptr nmi_idt_descr;
10290-extern gate_desc nmi_idt_table[];
10291-
10292-struct gdt_page {
10293- struct desc_struct gdt[GDT_ENTRIES];
10294-} __attribute__((aligned(PAGE_SIZE)));
10295-
10296-DECLARE_PER_CPU_PAGE_ALIGNED(struct gdt_page, gdt_page);
10297+extern gate_desc idt_table[256];
10298+extern gate_desc nmi_idt_table[256];
10299
10300+extern struct desc_struct cpu_gdt_table[NR_CPUS][PAGE_SIZE / sizeof(struct desc_struct)];
10301 static inline struct desc_struct *get_cpu_gdt_table(unsigned int cpu)
10302 {
10303- return per_cpu(gdt_page, cpu).gdt;
10304+ return cpu_gdt_table[cpu];
10305 }
10306
10307 #ifdef CONFIG_X86_64
10308@@ -72,8 +69,14 @@ static inline void pack_gate(gate_desc *gate, unsigned char type,
10309 unsigned long base, unsigned dpl, unsigned flags,
10310 unsigned short seg)
10311 {
10312- gate->a = (seg << 16) | (base & 0xffff);
10313- gate->b = (base & 0xffff0000) | (((0x80 | type | (dpl << 5)) & 0xff) << 8);
10314+ gate->gate.offset_low = base;
10315+ gate->gate.seg = seg;
10316+ gate->gate.reserved = 0;
10317+ gate->gate.type = type;
10318+ gate->gate.s = 0;
10319+ gate->gate.dpl = dpl;
10320+ gate->gate.p = 1;
10321+ gate->gate.offset_high = base >> 16;
10322 }
10323
10324 #endif
10325@@ -118,12 +121,16 @@ static inline void paravirt_free_ldt(struct desc_struct *ldt, unsigned entries)
10326
10327 static inline void native_write_idt_entry(gate_desc *idt, int entry, const gate_desc *gate)
10328 {
10329+ pax_open_kernel();
10330 memcpy(&idt[entry], gate, sizeof(*gate));
10331+ pax_close_kernel();
10332 }
10333
10334 static inline void native_write_ldt_entry(struct desc_struct *ldt, int entry, const void *desc)
10335 {
10336+ pax_open_kernel();
10337 memcpy(&ldt[entry], desc, 8);
10338+ pax_close_kernel();
10339 }
10340
10341 static inline void
10342@@ -137,7 +144,9 @@ native_write_gdt_entry(struct desc_struct *gdt, int entry, const void *desc, int
10343 default: size = sizeof(*gdt); break;
10344 }
10345
10346+ pax_open_kernel();
10347 memcpy(&gdt[entry], desc, size);
10348+ pax_close_kernel();
10349 }
10350
10351 static inline void pack_descriptor(struct desc_struct *desc, unsigned long base,
10352@@ -210,7 +219,9 @@ static inline void native_set_ldt(const void *addr, unsigned int entries)
10353
10354 static inline void native_load_tr_desc(void)
10355 {
10356+ pax_open_kernel();
10357 asm volatile("ltr %w0"::"q" (GDT_ENTRY_TSS*8));
10358+ pax_close_kernel();
10359 }
10360
10361 static inline void native_load_gdt(const struct desc_ptr *dtr)
10362@@ -247,8 +258,10 @@ static inline void native_load_tls(struct thread_struct *t, unsigned int cpu)
10363 struct desc_struct *gdt = get_cpu_gdt_table(cpu);
10364 unsigned int i;
10365
10366+ pax_open_kernel();
10367 for (i = 0; i < GDT_ENTRY_TLS_ENTRIES; i++)
10368 gdt[GDT_ENTRY_TLS_MIN + i] = t->tls_array[i];
10369+ pax_close_kernel();
10370 }
10371
10372 #define _LDT_empty(info) \
10373@@ -311,7 +324,7 @@ static inline void set_desc_limit(struct desc_struct *desc, unsigned long limit)
10374 }
10375
10376 #ifdef CONFIG_X86_64
10377-static inline void set_nmi_gate(int gate, void *addr)
10378+static inline void set_nmi_gate(int gate, const void *addr)
10379 {
10380 gate_desc s;
10381
10382@@ -320,7 +333,7 @@ static inline void set_nmi_gate(int gate, void *addr)
10383 }
10384 #endif
10385
10386-static inline void _set_gate(int gate, unsigned type, void *addr,
10387+static inline void _set_gate(int gate, unsigned type, const void *addr,
10388 unsigned dpl, unsigned ist, unsigned seg)
10389 {
10390 gate_desc s;
10391@@ -339,7 +352,7 @@ static inline void _set_gate(int gate, unsigned type, void *addr,
10392 * Pentium F0 0F bugfix can have resulted in the mapped
10393 * IDT being write-protected.
10394 */
10395-static inline void set_intr_gate(unsigned int n, void *addr)
10396+static inline void set_intr_gate(unsigned int n, const void *addr)
10397 {
10398 BUG_ON((unsigned)n > 0xFF);
10399 _set_gate(n, GATE_INTERRUPT, addr, 0, 0, __KERNEL_CS);
10400@@ -369,19 +382,19 @@ static inline void alloc_intr_gate(unsigned int n, void *addr)
10401 /*
10402 * This routine sets up an interrupt gate at directory privilege level 3.
10403 */
10404-static inline void set_system_intr_gate(unsigned int n, void *addr)
10405+static inline void set_system_intr_gate(unsigned int n, const void *addr)
10406 {
10407 BUG_ON((unsigned)n > 0xFF);
10408 _set_gate(n, GATE_INTERRUPT, addr, 0x3, 0, __KERNEL_CS);
10409 }
10410
10411-static inline void set_system_trap_gate(unsigned int n, void *addr)
10412+static inline void set_system_trap_gate(unsigned int n, const void *addr)
10413 {
10414 BUG_ON((unsigned)n > 0xFF);
10415 _set_gate(n, GATE_TRAP, addr, 0x3, 0, __KERNEL_CS);
10416 }
10417
10418-static inline void set_trap_gate(unsigned int n, void *addr)
10419+static inline void set_trap_gate(unsigned int n, const void *addr)
10420 {
10421 BUG_ON((unsigned)n > 0xFF);
10422 _set_gate(n, GATE_TRAP, addr, 0, 0, __KERNEL_CS);
10423@@ -390,19 +403,31 @@ static inline void set_trap_gate(unsigned int n, void *addr)
10424 static inline void set_task_gate(unsigned int n, unsigned int gdt_entry)
10425 {
10426 BUG_ON((unsigned)n > 0xFF);
10427- _set_gate(n, GATE_TASK, (void *)0, 0, 0, (gdt_entry<<3));
10428+ _set_gate(n, GATE_TASK, (const void *)0, 0, 0, (gdt_entry<<3));
10429 }
10430
10431-static inline void set_intr_gate_ist(int n, void *addr, unsigned ist)
10432+static inline void set_intr_gate_ist(int n, const void *addr, unsigned ist)
10433 {
10434 BUG_ON((unsigned)n > 0xFF);
10435 _set_gate(n, GATE_INTERRUPT, addr, 0, ist, __KERNEL_CS);
10436 }
10437
10438-static inline void set_system_intr_gate_ist(int n, void *addr, unsigned ist)
10439+static inline void set_system_intr_gate_ist(int n, const void *addr, unsigned ist)
10440 {
10441 BUG_ON((unsigned)n > 0xFF);
10442 _set_gate(n, GATE_INTERRUPT, addr, 0x3, ist, __KERNEL_CS);
10443 }
10444
10445+#ifdef CONFIG_X86_32
10446+static inline void set_user_cs(unsigned long base, unsigned long limit, int cpu)
10447+{
10448+ struct desc_struct d;
10449+
10450+ if (likely(limit))
10451+ limit = (limit - 1UL) >> PAGE_SHIFT;
10452+ pack_descriptor(&d, base, limit, 0xFB, 0xC);
10453+ write_gdt_entry(get_cpu_gdt_table(cpu), GDT_ENTRY_DEFAULT_USER_CS, &d, DESCTYPE_S);
10454+}
10455+#endif
10456+
10457 #endif /* _ASM_X86_DESC_H */
10458diff --git a/arch/x86/include/asm/desc_defs.h b/arch/x86/include/asm/desc_defs.h
10459index 278441f..b95a174 100644
10460--- a/arch/x86/include/asm/desc_defs.h
10461+++ b/arch/x86/include/asm/desc_defs.h
10462@@ -31,6 +31,12 @@ struct desc_struct {
10463 unsigned base1: 8, type: 4, s: 1, dpl: 2, p: 1;
10464 unsigned limit: 4, avl: 1, l: 1, d: 1, g: 1, base2: 8;
10465 };
10466+ struct {
10467+ u16 offset_low;
10468+ u16 seg;
10469+ unsigned reserved: 8, type: 4, s: 1, dpl: 2, p: 1;
10470+ unsigned offset_high: 16;
10471+ } gate;
10472 };
10473 } __attribute__((packed));
10474
10475diff --git a/arch/x86/include/asm/e820.h b/arch/x86/include/asm/e820.h
10476index 3778256..c5d4fce 100644
10477--- a/arch/x86/include/asm/e820.h
10478+++ b/arch/x86/include/asm/e820.h
10479@@ -69,7 +69,7 @@ struct e820map {
10480 #define ISA_START_ADDRESS 0xa0000
10481 #define ISA_END_ADDRESS 0x100000
10482
10483-#define BIOS_BEGIN 0x000a0000
10484+#define BIOS_BEGIN 0x000c0000
10485 #define BIOS_END 0x00100000
10486
10487 #define BIOS_ROM_BASE 0xffe00000
10488diff --git a/arch/x86/include/asm/elf.h b/arch/x86/include/asm/elf.h
10489index 5939f44..f8845f6 100644
10490--- a/arch/x86/include/asm/elf.h
10491+++ b/arch/x86/include/asm/elf.h
10492@@ -243,7 +243,25 @@ extern int force_personality32;
10493 the loader. We need to make sure that it is out of the way of the program
10494 that it will "exec", and that there is sufficient room for the brk. */
10495
10496+#ifdef CONFIG_PAX_SEGMEXEC
10497+#define ELF_ET_DYN_BASE ((current->mm->pax_flags & MF_PAX_SEGMEXEC) ? SEGMEXEC_TASK_SIZE/3*2 : TASK_SIZE/3*2)
10498+#else
10499 #define ELF_ET_DYN_BASE (TASK_SIZE / 3 * 2)
10500+#endif
10501+
10502+#ifdef CONFIG_PAX_ASLR
10503+#ifdef CONFIG_X86_32
10504+#define PAX_ELF_ET_DYN_BASE 0x10000000UL
10505+
10506+#define PAX_DELTA_MMAP_LEN (current->mm->pax_flags & MF_PAX_SEGMEXEC ? 15 : 16)
10507+#define PAX_DELTA_STACK_LEN (current->mm->pax_flags & MF_PAX_SEGMEXEC ? 15 : 16)
10508+#else
10509+#define PAX_ELF_ET_DYN_BASE 0x400000UL
10510+
10511+#define PAX_DELTA_MMAP_LEN ((test_thread_flag(TIF_ADDR32)) ? 16 : TASK_SIZE_MAX_SHIFT - PAGE_SHIFT - 3)
10512+#define PAX_DELTA_STACK_LEN ((test_thread_flag(TIF_ADDR32)) ? 16 : TASK_SIZE_MAX_SHIFT - PAGE_SHIFT - 3)
10513+#endif
10514+#endif
10515
10516 /* This yields a mask that user programs can use to figure out what
10517 instruction set this CPU supports. This could be done in user space,
10518@@ -296,16 +314,12 @@ do { \
10519
10520 #define ARCH_DLINFO \
10521 do { \
10522- if (vdso_enabled) \
10523- NEW_AUX_ENT(AT_SYSINFO_EHDR, \
10524- (unsigned long)current->mm->context.vdso); \
10525+ NEW_AUX_ENT(AT_SYSINFO_EHDR, current->mm->context.vdso); \
10526 } while (0)
10527
10528 #define ARCH_DLINFO_X32 \
10529 do { \
10530- if (vdso_enabled) \
10531- NEW_AUX_ENT(AT_SYSINFO_EHDR, \
10532- (unsigned long)current->mm->context.vdso); \
10533+ NEW_AUX_ENT(AT_SYSINFO_EHDR, current->mm->context.vdso); \
10534 } while (0)
10535
10536 #define AT_SYSINFO 32
10537@@ -320,7 +334,7 @@ else \
10538
10539 #endif /* !CONFIG_X86_32 */
10540
10541-#define VDSO_CURRENT_BASE ((unsigned long)current->mm->context.vdso)
10542+#define VDSO_CURRENT_BASE (current->mm->context.vdso)
10543
10544 #define VDSO_ENTRY \
10545 ((unsigned long)VDSO32_SYMBOL(VDSO_CURRENT_BASE, vsyscall))
10546@@ -336,9 +350,6 @@ extern int x32_setup_additional_pages(struct linux_binprm *bprm,
10547 extern int syscall32_setup_pages(struct linux_binprm *, int exstack);
10548 #define compat_arch_setup_additional_pages syscall32_setup_pages
10549
10550-extern unsigned long arch_randomize_brk(struct mm_struct *mm);
10551-#define arch_randomize_brk arch_randomize_brk
10552-
10553 /*
10554 * True on X86_32 or when emulating IA32 on X86_64
10555 */
10556diff --git a/arch/x86/include/asm/emergency-restart.h b/arch/x86/include/asm/emergency-restart.h
10557index 75ce3f4..882e801 100644
10558--- a/arch/x86/include/asm/emergency-restart.h
10559+++ b/arch/x86/include/asm/emergency-restart.h
10560@@ -13,6 +13,6 @@ enum reboot_type {
10561
10562 extern enum reboot_type reboot_type;
10563
10564-extern void machine_emergency_restart(void);
10565+extern void machine_emergency_restart(void) __noreturn;
10566
10567 #endif /* _ASM_X86_EMERGENCY_RESTART_H */
10568diff --git a/arch/x86/include/asm/fpu-internal.h b/arch/x86/include/asm/fpu-internal.h
10569index 75f4c6d..ee3eb8f 100644
10570--- a/arch/x86/include/asm/fpu-internal.h
10571+++ b/arch/x86/include/asm/fpu-internal.h
10572@@ -86,6 +86,11 @@ static inline int fxrstor_checking(struct i387_fxsave_struct *fx)
10573 {
10574 int err;
10575
10576+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
10577+ if ((unsigned long)fx < PAX_USER_SHADOW_BASE)
10578+ fx = (struct i387_fxsave_struct __user *)((void *)fx + PAX_USER_SHADOW_BASE);
10579+#endif
10580+
10581 /* See comment in fxsave() below. */
10582 #ifdef CONFIG_AS_FXSAVEQ
10583 asm volatile("1: fxrstorq %[fx]\n\t"
10584@@ -115,6 +120,11 @@ static inline int fxsave_user(struct i387_fxsave_struct __user *fx)
10585 {
10586 int err;
10587
10588+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
10589+ if ((unsigned long)fx < PAX_USER_SHADOW_BASE)
10590+ fx = (struct i387_fxsave_struct __user *)((void __user *)fx + PAX_USER_SHADOW_BASE);
10591+#endif
10592+
10593 /*
10594 * Clear the bytes not touched by the fxsave and reserved
10595 * for the SW usage.
10596@@ -271,7 +281,7 @@ static inline int restore_fpu_checking(struct task_struct *tsk)
10597 "emms\n\t" /* clear stack tags */
10598 "fildl %P[addr]", /* set F?P to defined value */
10599 X86_FEATURE_FXSAVE_LEAK,
10600- [addr] "m" (tsk->thread.fpu.has_fpu));
10601+ [addr] "m" (init_tss[smp_processor_id()].x86_tss.sp0));
10602
10603 return fpu_restore_checking(&tsk->thread.fpu);
10604 }
10605diff --git a/arch/x86/include/asm/futex.h b/arch/x86/include/asm/futex.h
10606index 71ecbcb..bac10b7 100644
10607--- a/arch/x86/include/asm/futex.h
10608+++ b/arch/x86/include/asm/futex.h
10609@@ -11,16 +11,18 @@
10610 #include <asm/processor.h>
10611
10612 #define __futex_atomic_op1(insn, ret, oldval, uaddr, oparg) \
10613+ typecheck(u32 __user *, uaddr); \
10614 asm volatile("1:\t" insn "\n" \
10615 "2:\t.section .fixup,\"ax\"\n" \
10616 "3:\tmov\t%3, %1\n" \
10617 "\tjmp\t2b\n" \
10618 "\t.previous\n" \
10619 _ASM_EXTABLE(1b, 3b) \
10620- : "=r" (oldval), "=r" (ret), "+m" (*uaddr) \
10621+ : "=r" (oldval), "=r" (ret), "+m" (*(u32 __user *)____m(uaddr))\
10622 : "i" (-EFAULT), "0" (oparg), "1" (0))
10623
10624 #define __futex_atomic_op2(insn, ret, oldval, uaddr, oparg) \
10625+ typecheck(u32 __user *, uaddr); \
10626 asm volatile("1:\tmovl %2, %0\n" \
10627 "\tmovl\t%0, %3\n" \
10628 "\t" insn "\n" \
10629@@ -33,7 +35,7 @@
10630 _ASM_EXTABLE(1b, 4b) \
10631 _ASM_EXTABLE(2b, 4b) \
10632 : "=&a" (oldval), "=&r" (ret), \
10633- "+m" (*uaddr), "=&r" (tem) \
10634+ "+m" (*(u32 __user *)____m(uaddr)), "=&r" (tem) \
10635 : "r" (oparg), "i" (-EFAULT), "1" (0))
10636
10637 static inline int futex_atomic_op_inuser(int encoded_op, u32 __user *uaddr)
10638@@ -60,10 +62,10 @@ static inline int futex_atomic_op_inuser(int encoded_op, u32 __user *uaddr)
10639
10640 switch (op) {
10641 case FUTEX_OP_SET:
10642- __futex_atomic_op1("xchgl %0, %2", ret, oldval, uaddr, oparg);
10643+ __futex_atomic_op1(__copyuser_seg"xchgl %0, %2", ret, oldval, uaddr, oparg);
10644 break;
10645 case FUTEX_OP_ADD:
10646- __futex_atomic_op1(LOCK_PREFIX "xaddl %0, %2", ret, oldval,
10647+ __futex_atomic_op1(LOCK_PREFIX __copyuser_seg"xaddl %0, %2", ret, oldval,
10648 uaddr, oparg);
10649 break;
10650 case FUTEX_OP_OR:
10651@@ -122,13 +124,13 @@ static inline int futex_atomic_cmpxchg_inatomic(u32 *uval, u32 __user *uaddr,
10652 if (!access_ok(VERIFY_WRITE, uaddr, sizeof(u32)))
10653 return -EFAULT;
10654
10655- asm volatile("1:\t" LOCK_PREFIX "cmpxchgl %4, %2\n"
10656+ asm volatile("1:\t" LOCK_PREFIX __copyuser_seg"cmpxchgl %4, %2\n"
10657 "2:\t.section .fixup, \"ax\"\n"
10658 "3:\tmov %3, %0\n"
10659 "\tjmp 2b\n"
10660 "\t.previous\n"
10661 _ASM_EXTABLE(1b, 3b)
10662- : "+r" (ret), "=a" (oldval), "+m" (*uaddr)
10663+ : "+r" (ret), "=a" (oldval), "+m" (*(u32 __user *)____m(uaddr))
10664 : "i" (-EFAULT), "r" (newval), "1" (oldval)
10665 : "memory"
10666 );
10667diff --git a/arch/x86/include/asm/hw_irq.h b/arch/x86/include/asm/hw_irq.h
10668index eb92a6e..b98b2f4 100644
10669--- a/arch/x86/include/asm/hw_irq.h
10670+++ b/arch/x86/include/asm/hw_irq.h
10671@@ -136,8 +136,8 @@ extern void setup_ioapic_dest(void);
10672 extern void enable_IO_APIC(void);
10673
10674 /* Statistics */
10675-extern atomic_t irq_err_count;
10676-extern atomic_t irq_mis_count;
10677+extern atomic_unchecked_t irq_err_count;
10678+extern atomic_unchecked_t irq_mis_count;
10679
10680 /* EISA */
10681 extern void eisa_set_level_irq(unsigned int irq);
10682diff --git a/arch/x86/include/asm/io.h b/arch/x86/include/asm/io.h
10683index d8e8eef..99f81ae 100644
10684--- a/arch/x86/include/asm/io.h
10685+++ b/arch/x86/include/asm/io.h
10686@@ -194,6 +194,17 @@ extern void set_iounmap_nonlazy(void);
10687
10688 #include <linux/vmalloc.h>
10689
10690+#define ARCH_HAS_VALID_PHYS_ADDR_RANGE
10691+static inline int valid_phys_addr_range(unsigned long addr, size_t count)
10692+{
10693+ return ((addr + count + PAGE_SIZE - 1) >> PAGE_SHIFT) < (1ULL << (boot_cpu_data.x86_phys_bits - PAGE_SHIFT)) ? 1 : 0;
10694+}
10695+
10696+static inline int valid_mmap_phys_addr_range(unsigned long pfn, size_t count)
10697+{
10698+ return (pfn + (count >> PAGE_SHIFT)) < (1ULL << (boot_cpu_data.x86_phys_bits - PAGE_SHIFT)) ? 1 : 0;
10699+}
10700+
10701 /*
10702 * Convert a virtual cached pointer to an uncached pointer
10703 */
10704diff --git a/arch/x86/include/asm/irqflags.h b/arch/x86/include/asm/irqflags.h
10705index bba3cf8..06bc8da 100644
10706--- a/arch/x86/include/asm/irqflags.h
10707+++ b/arch/x86/include/asm/irqflags.h
10708@@ -141,6 +141,11 @@ static inline notrace unsigned long arch_local_irq_save(void)
10709 sti; \
10710 sysexit
10711
10712+#define GET_CR0_INTO_RDI mov %cr0, %rdi
10713+#define SET_RDI_INTO_CR0 mov %rdi, %cr0
10714+#define GET_CR3_INTO_RDI mov %cr3, %rdi
10715+#define SET_RDI_INTO_CR3 mov %rdi, %cr3
10716+
10717 #else
10718 #define INTERRUPT_RETURN iret
10719 #define ENABLE_INTERRUPTS_SYSEXIT sti; sysexit
10720diff --git a/arch/x86/include/asm/kprobes.h b/arch/x86/include/asm/kprobes.h
10721index 5478825..839e88c 100644
10722--- a/arch/x86/include/asm/kprobes.h
10723+++ b/arch/x86/include/asm/kprobes.h
10724@@ -37,13 +37,8 @@ typedef u8 kprobe_opcode_t;
10725 #define RELATIVEJUMP_SIZE 5
10726 #define RELATIVECALL_OPCODE 0xe8
10727 #define RELATIVE_ADDR_SIZE 4
10728-#define MAX_STACK_SIZE 64
10729-#define MIN_STACK_SIZE(ADDR) \
10730- (((MAX_STACK_SIZE) < (((unsigned long)current_thread_info()) + \
10731- THREAD_SIZE - (unsigned long)(ADDR))) \
10732- ? (MAX_STACK_SIZE) \
10733- : (((unsigned long)current_thread_info()) + \
10734- THREAD_SIZE - (unsigned long)(ADDR)))
10735+#define MAX_STACK_SIZE 64UL
10736+#define MIN_STACK_SIZE(ADDR) min(MAX_STACK_SIZE, current->thread.sp0 - (unsigned long)(ADDR))
10737
10738 #define flush_insn_slot(p) do { } while (0)
10739
10740diff --git a/arch/x86/include/asm/kvm_host.h b/arch/x86/include/asm/kvm_host.h
10741index 09155d6..d2e6df9 100644
10742--- a/arch/x86/include/asm/kvm_host.h
10743+++ b/arch/x86/include/asm/kvm_host.h
10744@@ -694,7 +694,7 @@ struct kvm_x86_ops {
10745 int (*check_intercept)(struct kvm_vcpu *vcpu,
10746 struct x86_instruction_info *info,
10747 enum x86_intercept_stage stage);
10748-};
10749+} __do_const;
10750
10751 struct kvm_arch_async_pf {
10752 u32 token;
10753diff --git a/arch/x86/include/asm/local.h b/arch/x86/include/asm/local.h
10754index c8bed0d..e5721fa 100644
10755--- a/arch/x86/include/asm/local.h
10756+++ b/arch/x86/include/asm/local.h
10757@@ -17,26 +17,58 @@ typedef struct {
10758
10759 static inline void local_inc(local_t *l)
10760 {
10761- asm volatile(_ASM_INC "%0"
10762+ asm volatile(_ASM_INC "%0\n"
10763+
10764+#ifdef CONFIG_PAX_REFCOUNT
10765+ "jno 0f\n"
10766+ _ASM_DEC "%0\n"
10767+ "int $4\n0:\n"
10768+ _ASM_EXTABLE(0b, 0b)
10769+#endif
10770+
10771 : "+m" (l->a.counter));
10772 }
10773
10774 static inline void local_dec(local_t *l)
10775 {
10776- asm volatile(_ASM_DEC "%0"
10777+ asm volatile(_ASM_DEC "%0\n"
10778+
10779+#ifdef CONFIG_PAX_REFCOUNT
10780+ "jno 0f\n"
10781+ _ASM_INC "%0\n"
10782+ "int $4\n0:\n"
10783+ _ASM_EXTABLE(0b, 0b)
10784+#endif
10785+
10786 : "+m" (l->a.counter));
10787 }
10788
10789 static inline void local_add(long i, local_t *l)
10790 {
10791- asm volatile(_ASM_ADD "%1,%0"
10792+ asm volatile(_ASM_ADD "%1,%0\n"
10793+
10794+#ifdef CONFIG_PAX_REFCOUNT
10795+ "jno 0f\n"
10796+ _ASM_SUB "%1,%0\n"
10797+ "int $4\n0:\n"
10798+ _ASM_EXTABLE(0b, 0b)
10799+#endif
10800+
10801 : "+m" (l->a.counter)
10802 : "ir" (i));
10803 }
10804
10805 static inline void local_sub(long i, local_t *l)
10806 {
10807- asm volatile(_ASM_SUB "%1,%0"
10808+ asm volatile(_ASM_SUB "%1,%0\n"
10809+
10810+#ifdef CONFIG_PAX_REFCOUNT
10811+ "jno 0f\n"
10812+ _ASM_ADD "%1,%0\n"
10813+ "int $4\n0:\n"
10814+ _ASM_EXTABLE(0b, 0b)
10815+#endif
10816+
10817 : "+m" (l->a.counter)
10818 : "ir" (i));
10819 }
10820@@ -54,7 +86,16 @@ static inline int local_sub_and_test(long i, local_t *l)
10821 {
10822 unsigned char c;
10823
10824- asm volatile(_ASM_SUB "%2,%0; sete %1"
10825+ asm volatile(_ASM_SUB "%2,%0\n"
10826+
10827+#ifdef CONFIG_PAX_REFCOUNT
10828+ "jno 0f\n"
10829+ _ASM_ADD "%2,%0\n"
10830+ "int $4\n0:\n"
10831+ _ASM_EXTABLE(0b, 0b)
10832+#endif
10833+
10834+ "sete %1\n"
10835 : "+m" (l->a.counter), "=qm" (c)
10836 : "ir" (i) : "memory");
10837 return c;
10838@@ -72,7 +113,16 @@ static inline int local_dec_and_test(local_t *l)
10839 {
10840 unsigned char c;
10841
10842- asm volatile(_ASM_DEC "%0; sete %1"
10843+ asm volatile(_ASM_DEC "%0\n"
10844+
10845+#ifdef CONFIG_PAX_REFCOUNT
10846+ "jno 0f\n"
10847+ _ASM_INC "%0\n"
10848+ "int $4\n0:\n"
10849+ _ASM_EXTABLE(0b, 0b)
10850+#endif
10851+
10852+ "sete %1\n"
10853 : "+m" (l->a.counter), "=qm" (c)
10854 : : "memory");
10855 return c != 0;
10856@@ -90,7 +140,16 @@ static inline int local_inc_and_test(local_t *l)
10857 {
10858 unsigned char c;
10859
10860- asm volatile(_ASM_INC "%0; sete %1"
10861+ asm volatile(_ASM_INC "%0\n"
10862+
10863+#ifdef CONFIG_PAX_REFCOUNT
10864+ "jno 0f\n"
10865+ _ASM_DEC "%0\n"
10866+ "int $4\n0:\n"
10867+ _ASM_EXTABLE(0b, 0b)
10868+#endif
10869+
10870+ "sete %1\n"
10871 : "+m" (l->a.counter), "=qm" (c)
10872 : : "memory");
10873 return c != 0;
10874@@ -109,7 +168,16 @@ static inline int local_add_negative(long i, local_t *l)
10875 {
10876 unsigned char c;
10877
10878- asm volatile(_ASM_ADD "%2,%0; sets %1"
10879+ asm volatile(_ASM_ADD "%2,%0\n"
10880+
10881+#ifdef CONFIG_PAX_REFCOUNT
10882+ "jno 0f\n"
10883+ _ASM_SUB "%2,%0\n"
10884+ "int $4\n0:\n"
10885+ _ASM_EXTABLE(0b, 0b)
10886+#endif
10887+
10888+ "sets %1\n"
10889 : "+m" (l->a.counter), "=qm" (c)
10890 : "ir" (i) : "memory");
10891 return c;
10892@@ -132,7 +200,15 @@ static inline long local_add_return(long i, local_t *l)
10893 #endif
10894 /* Modern 486+ processor */
10895 __i = i;
10896- asm volatile(_ASM_XADD "%0, %1;"
10897+ asm volatile(_ASM_XADD "%0, %1\n"
10898+
10899+#ifdef CONFIG_PAX_REFCOUNT
10900+ "jno 0f\n"
10901+ _ASM_MOV "%0,%1\n"
10902+ "int $4\n0:\n"
10903+ _ASM_EXTABLE(0b, 0b)
10904+#endif
10905+
10906 : "+r" (i), "+m" (l->a.counter)
10907 : : "memory");
10908 return i + __i;
10909diff --git a/arch/x86/include/asm/mman.h b/arch/x86/include/asm/mman.h
10910index 593e51d..fa69c9a 100644
10911--- a/arch/x86/include/asm/mman.h
10912+++ b/arch/x86/include/asm/mman.h
10913@@ -5,4 +5,14 @@
10914
10915 #include <asm-generic/mman.h>
10916
10917+#ifdef __KERNEL__
10918+#ifndef __ASSEMBLY__
10919+#ifdef CONFIG_X86_32
10920+#define arch_mmap_check i386_mmap_check
10921+int i386_mmap_check(unsigned long addr, unsigned long len,
10922+ unsigned long flags);
10923+#endif
10924+#endif
10925+#endif
10926+
10927 #endif /* _ASM_X86_MMAN_H */
10928diff --git a/arch/x86/include/asm/mmu.h b/arch/x86/include/asm/mmu.h
10929index 5f55e69..e20bfb1 100644
10930--- a/arch/x86/include/asm/mmu.h
10931+++ b/arch/x86/include/asm/mmu.h
10932@@ -9,7 +9,7 @@
10933 * we put the segment information here.
10934 */
10935 typedef struct {
10936- void *ldt;
10937+ struct desc_struct *ldt;
10938 int size;
10939
10940 #ifdef CONFIG_X86_64
10941@@ -18,7 +18,19 @@ typedef struct {
10942 #endif
10943
10944 struct mutex lock;
10945- void *vdso;
10946+ unsigned long vdso;
10947+
10948+#ifdef CONFIG_X86_32
10949+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
10950+ unsigned long user_cs_base;
10951+ unsigned long user_cs_limit;
10952+
10953+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_SMP)
10954+ cpumask_t cpu_user_cs_mask;
10955+#endif
10956+
10957+#endif
10958+#endif
10959 } mm_context_t;
10960
10961 #ifdef CONFIG_SMP
10962diff --git a/arch/x86/include/asm/mmu_context.h b/arch/x86/include/asm/mmu_context.h
10963index cdbf367..adb37ac 100644
10964--- a/arch/x86/include/asm/mmu_context.h
10965+++ b/arch/x86/include/asm/mmu_context.h
10966@@ -24,6 +24,18 @@ void destroy_context(struct mm_struct *mm);
10967
10968 static inline void enter_lazy_tlb(struct mm_struct *mm, struct task_struct *tsk)
10969 {
10970+
10971+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
10972+ unsigned int i;
10973+ pgd_t *pgd;
10974+
10975+ pax_open_kernel();
10976+ pgd = get_cpu_pgd(smp_processor_id());
10977+ for (i = USER_PGD_PTRS; i < 2 * USER_PGD_PTRS; ++i)
10978+ set_pgd_batched(pgd+i, native_make_pgd(0));
10979+ pax_close_kernel();
10980+#endif
10981+
10982 #ifdef CONFIG_SMP
10983 if (this_cpu_read(cpu_tlbstate.state) == TLBSTATE_OK)
10984 this_cpu_write(cpu_tlbstate.state, TLBSTATE_LAZY);
10985@@ -34,16 +46,30 @@ static inline void switch_mm(struct mm_struct *prev, struct mm_struct *next,
10986 struct task_struct *tsk)
10987 {
10988 unsigned cpu = smp_processor_id();
10989+#if defined(CONFIG_X86_32) && defined(CONFIG_SMP) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
10990+ int tlbstate = TLBSTATE_OK;
10991+#endif
10992
10993 if (likely(prev != next)) {
10994 #ifdef CONFIG_SMP
10995+#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
10996+ tlbstate = this_cpu_read(cpu_tlbstate.state);
10997+#endif
10998 this_cpu_write(cpu_tlbstate.state, TLBSTATE_OK);
10999 this_cpu_write(cpu_tlbstate.active_mm, next);
11000 #endif
11001 cpumask_set_cpu(cpu, mm_cpumask(next));
11002
11003 /* Re-load page tables */
11004+#ifdef CONFIG_PAX_PER_CPU_PGD
11005+ pax_open_kernel();
11006+ __clone_user_pgds(get_cpu_pgd(cpu), next->pgd);
11007+ __shadow_user_pgds(get_cpu_pgd(cpu) + USER_PGD_PTRS, next->pgd);
11008+ pax_close_kernel();
11009+ load_cr3(get_cpu_pgd(cpu));
11010+#else
11011 load_cr3(next->pgd);
11012+#endif
11013
11014 /* stop flush ipis for the previous mm */
11015 cpumask_clear_cpu(cpu, mm_cpumask(prev));
11016@@ -53,9 +79,38 @@ static inline void switch_mm(struct mm_struct *prev, struct mm_struct *next,
11017 */
11018 if (unlikely(prev->context.ldt != next->context.ldt))
11019 load_LDT_nolock(&next->context);
11020- }
11021+
11022+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_SMP)
11023+ if (!(__supported_pte_mask & _PAGE_NX)) {
11024+ smp_mb__before_clear_bit();
11025+ cpu_clear(cpu, prev->context.cpu_user_cs_mask);
11026+ smp_mb__after_clear_bit();
11027+ cpu_set(cpu, next->context.cpu_user_cs_mask);
11028+ }
11029+#endif
11030+
11031+#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
11032+ if (unlikely(prev->context.user_cs_base != next->context.user_cs_base ||
11033+ prev->context.user_cs_limit != next->context.user_cs_limit))
11034+ set_user_cs(next->context.user_cs_base, next->context.user_cs_limit, cpu);
11035 #ifdef CONFIG_SMP
11036+ else if (unlikely(tlbstate != TLBSTATE_OK))
11037+ set_user_cs(next->context.user_cs_base, next->context.user_cs_limit, cpu);
11038+#endif
11039+#endif
11040+
11041+ }
11042 else {
11043+
11044+#ifdef CONFIG_PAX_PER_CPU_PGD
11045+ pax_open_kernel();
11046+ __clone_user_pgds(get_cpu_pgd(cpu), next->pgd);
11047+ __shadow_user_pgds(get_cpu_pgd(cpu) + USER_PGD_PTRS, next->pgd);
11048+ pax_close_kernel();
11049+ load_cr3(get_cpu_pgd(cpu));
11050+#endif
11051+
11052+#ifdef CONFIG_SMP
11053 this_cpu_write(cpu_tlbstate.state, TLBSTATE_OK);
11054 BUG_ON(this_cpu_read(cpu_tlbstate.active_mm) != next);
11055
11056@@ -64,11 +119,28 @@ static inline void switch_mm(struct mm_struct *prev, struct mm_struct *next,
11057 * tlb flush IPI delivery. We must reload CR3
11058 * to make sure to use no freed page tables.
11059 */
11060+
11061+#ifndef CONFIG_PAX_PER_CPU_PGD
11062 load_cr3(next->pgd);
11063+#endif
11064+
11065 load_LDT_nolock(&next->context);
11066+
11067+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
11068+ if (!(__supported_pte_mask & _PAGE_NX))
11069+ cpu_set(cpu, next->context.cpu_user_cs_mask);
11070+#endif
11071+
11072+#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
11073+#ifdef CONFIG_PAX_PAGEEXEC
11074+ if (!((next->pax_flags & MF_PAX_PAGEEXEC) && (__supported_pte_mask & _PAGE_NX)))
11075+#endif
11076+ set_user_cs(next->context.user_cs_base, next->context.user_cs_limit, cpu);
11077+#endif
11078+
11079 }
11080+#endif
11081 }
11082-#endif
11083 }
11084
11085 #define activate_mm(prev, next) \
11086diff --git a/arch/x86/include/asm/module.h b/arch/x86/include/asm/module.h
11087index 9eae775..c914fea 100644
11088--- a/arch/x86/include/asm/module.h
11089+++ b/arch/x86/include/asm/module.h
11090@@ -5,6 +5,7 @@
11091
11092 #ifdef CONFIG_X86_64
11093 /* X86_64 does not define MODULE_PROC_FAMILY */
11094+#define MODULE_PROC_FAMILY ""
11095 #elif defined CONFIG_M386
11096 #define MODULE_PROC_FAMILY "386 "
11097 #elif defined CONFIG_M486
11098@@ -59,8 +60,20 @@
11099 #error unknown processor family
11100 #endif
11101
11102-#ifdef CONFIG_X86_32
11103-# define MODULE_ARCH_VERMAGIC MODULE_PROC_FAMILY
11104+#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_BTS
11105+#define MODULE_PAX_KERNEXEC "KERNEXEC_BTS "
11106+#elif defined(CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR)
11107+#define MODULE_PAX_KERNEXEC "KERNEXEC_OR "
11108+#else
11109+#define MODULE_PAX_KERNEXEC ""
11110 #endif
11111
11112+#ifdef CONFIG_PAX_MEMORY_UDEREF
11113+#define MODULE_PAX_UDEREF "UDEREF "
11114+#else
11115+#define MODULE_PAX_UDEREF ""
11116+#endif
11117+
11118+#define MODULE_ARCH_VERMAGIC MODULE_PROC_FAMILY MODULE_PAX_KERNEXEC MODULE_PAX_UDEREF
11119+
11120 #endif /* _ASM_X86_MODULE_H */
11121diff --git a/arch/x86/include/asm/page_64_types.h b/arch/x86/include/asm/page_64_types.h
11122index 320f7bb..e89f8f8 100644
11123--- a/arch/x86/include/asm/page_64_types.h
11124+++ b/arch/x86/include/asm/page_64_types.h
11125@@ -56,7 +56,7 @@ void copy_page(void *to, void *from);
11126
11127 /* duplicated to the one in bootmem.h */
11128 extern unsigned long max_pfn;
11129-extern unsigned long phys_base;
11130+extern const unsigned long phys_base;
11131
11132 extern unsigned long __phys_addr(unsigned long);
11133 #define __phys_reloc_hide(x) (x)
11134diff --git a/arch/x86/include/asm/paravirt.h b/arch/x86/include/asm/paravirt.h
11135index a0facf3..c017b15 100644
11136--- a/arch/x86/include/asm/paravirt.h
11137+++ b/arch/x86/include/asm/paravirt.h
11138@@ -632,6 +632,18 @@ static inline void set_pgd(pgd_t *pgdp, pgd_t pgd)
11139 val);
11140 }
11141
11142+static inline void set_pgd_batched(pgd_t *pgdp, pgd_t pgd)
11143+{
11144+ pgdval_t val = native_pgd_val(pgd);
11145+
11146+ if (sizeof(pgdval_t) > sizeof(long))
11147+ PVOP_VCALL3(pv_mmu_ops.set_pgd_batched, pgdp,
11148+ val, (u64)val >> 32);
11149+ else
11150+ PVOP_VCALL2(pv_mmu_ops.set_pgd_batched, pgdp,
11151+ val);
11152+}
11153+
11154 static inline void pgd_clear(pgd_t *pgdp)
11155 {
11156 set_pgd(pgdp, __pgd(0));
11157@@ -713,6 +725,21 @@ static inline void __set_fixmap(unsigned /* enum fixed_addresses */ idx,
11158 pv_mmu_ops.set_fixmap(idx, phys, flags);
11159 }
11160
11161+#ifdef CONFIG_PAX_KERNEXEC
11162+static inline unsigned long pax_open_kernel(void)
11163+{
11164+ return PVOP_CALL0(unsigned long, pv_mmu_ops.pax_open_kernel);
11165+}
11166+
11167+static inline unsigned long pax_close_kernel(void)
11168+{
11169+ return PVOP_CALL0(unsigned long, pv_mmu_ops.pax_close_kernel);
11170+}
11171+#else
11172+static inline unsigned long pax_open_kernel(void) { return 0; }
11173+static inline unsigned long pax_close_kernel(void) { return 0; }
11174+#endif
11175+
11176 #if defined(CONFIG_SMP) && defined(CONFIG_PARAVIRT_SPINLOCKS)
11177
11178 static inline int arch_spin_is_locked(struct arch_spinlock *lock)
11179@@ -929,7 +956,7 @@ extern void default_banner(void);
11180
11181 #define PARA_PATCH(struct, off) ((PARAVIRT_PATCH_##struct + (off)) / 4)
11182 #define PARA_SITE(ptype, clobbers, ops) _PVSITE(ptype, clobbers, ops, .long, 4)
11183-#define PARA_INDIRECT(addr) *%cs:addr
11184+#define PARA_INDIRECT(addr) *%ss:addr
11185 #endif
11186
11187 #define INTERRUPT_RETURN \
11188@@ -1004,6 +1031,21 @@ extern void default_banner(void);
11189 PARA_SITE(PARA_PATCH(pv_cpu_ops, PV_CPU_irq_enable_sysexit), \
11190 CLBR_NONE, \
11191 jmp PARA_INDIRECT(pv_cpu_ops+PV_CPU_irq_enable_sysexit))
11192+
11193+#define GET_CR0_INTO_RDI \
11194+ call PARA_INDIRECT(pv_cpu_ops+PV_CPU_read_cr0); \
11195+ mov %rax,%rdi
11196+
11197+#define SET_RDI_INTO_CR0 \
11198+ call PARA_INDIRECT(pv_cpu_ops+PV_CPU_write_cr0)
11199+
11200+#define GET_CR3_INTO_RDI \
11201+ call PARA_INDIRECT(pv_mmu_ops+PV_MMU_read_cr3); \
11202+ mov %rax,%rdi
11203+
11204+#define SET_RDI_INTO_CR3 \
11205+ call PARA_INDIRECT(pv_mmu_ops+PV_MMU_write_cr3)
11206+
11207 #endif /* CONFIG_X86_32 */
11208
11209 #endif /* __ASSEMBLY__ */
11210diff --git a/arch/x86/include/asm/paravirt_types.h b/arch/x86/include/asm/paravirt_types.h
11211index 142236e..6a6b4a6 100644
11212--- a/arch/x86/include/asm/paravirt_types.h
11213+++ b/arch/x86/include/asm/paravirt_types.h
11214@@ -84,20 +84,20 @@ struct pv_init_ops {
11215 */
11216 unsigned (*patch)(u8 type, u16 clobber, void *insnbuf,
11217 unsigned long addr, unsigned len);
11218-};
11219+} __no_const;
11220
11221
11222 struct pv_lazy_ops {
11223 /* Set deferred update mode, used for batching operations. */
11224 void (*enter)(void);
11225 void (*leave)(void);
11226-};
11227+} __no_const;
11228
11229 struct pv_time_ops {
11230 unsigned long long (*sched_clock)(void);
11231 unsigned long long (*steal_clock)(int cpu);
11232 unsigned long (*get_tsc_khz)(void);
11233-};
11234+} __no_const;
11235
11236 struct pv_cpu_ops {
11237 /* hooks for various privileged instructions */
11238@@ -191,7 +191,7 @@ struct pv_cpu_ops {
11239
11240 void (*start_context_switch)(struct task_struct *prev);
11241 void (*end_context_switch)(struct task_struct *next);
11242-};
11243+} __no_const;
11244
11245 struct pv_irq_ops {
11246 /*
11247@@ -222,7 +222,7 @@ struct pv_apic_ops {
11248 unsigned long start_eip,
11249 unsigned long start_esp);
11250 #endif
11251-};
11252+} __no_const;
11253
11254 struct pv_mmu_ops {
11255 unsigned long (*read_cr2)(void);
11256@@ -312,6 +312,7 @@ struct pv_mmu_ops {
11257 struct paravirt_callee_save make_pud;
11258
11259 void (*set_pgd)(pgd_t *pudp, pgd_t pgdval);
11260+ void (*set_pgd_batched)(pgd_t *pudp, pgd_t pgdval);
11261 #endif /* PAGETABLE_LEVELS == 4 */
11262 #endif /* PAGETABLE_LEVELS >= 3 */
11263
11264@@ -323,6 +324,12 @@ struct pv_mmu_ops {
11265 an mfn. We can tell which is which from the index. */
11266 void (*set_fixmap)(unsigned /* enum fixed_addresses */ idx,
11267 phys_addr_t phys, pgprot_t flags);
11268+
11269+#ifdef CONFIG_PAX_KERNEXEC
11270+ unsigned long (*pax_open_kernel)(void);
11271+ unsigned long (*pax_close_kernel)(void);
11272+#endif
11273+
11274 };
11275
11276 struct arch_spinlock;
11277@@ -333,7 +340,7 @@ struct pv_lock_ops {
11278 void (*spin_lock_flags)(struct arch_spinlock *lock, unsigned long flags);
11279 int (*spin_trylock)(struct arch_spinlock *lock);
11280 void (*spin_unlock)(struct arch_spinlock *lock);
11281-};
11282+} __no_const;
11283
11284 /* This contains all the paravirt structures: we get a convenient
11285 * number for each function using the offset which we use to indicate
11286diff --git a/arch/x86/include/asm/pgalloc.h b/arch/x86/include/asm/pgalloc.h
11287index b4389a4..7024269 100644
11288--- a/arch/x86/include/asm/pgalloc.h
11289+++ b/arch/x86/include/asm/pgalloc.h
11290@@ -63,6 +63,13 @@ static inline void pmd_populate_kernel(struct mm_struct *mm,
11291 pmd_t *pmd, pte_t *pte)
11292 {
11293 paravirt_alloc_pte(mm, __pa(pte) >> PAGE_SHIFT);
11294+ set_pmd(pmd, __pmd(__pa(pte) | _KERNPG_TABLE));
11295+}
11296+
11297+static inline void pmd_populate_user(struct mm_struct *mm,
11298+ pmd_t *pmd, pte_t *pte)
11299+{
11300+ paravirt_alloc_pte(mm, __pa(pte) >> PAGE_SHIFT);
11301 set_pmd(pmd, __pmd(__pa(pte) | _PAGE_TABLE));
11302 }
11303
11304@@ -99,12 +106,22 @@ static inline void __pmd_free_tlb(struct mmu_gather *tlb, pmd_t *pmd,
11305
11306 #ifdef CONFIG_X86_PAE
11307 extern void pud_populate(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd);
11308+static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd)
11309+{
11310+ pud_populate(mm, pudp, pmd);
11311+}
11312 #else /* !CONFIG_X86_PAE */
11313 static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
11314 {
11315 paravirt_alloc_pmd(mm, __pa(pmd) >> PAGE_SHIFT);
11316 set_pud(pud, __pud(_PAGE_TABLE | __pa(pmd)));
11317 }
11318+
11319+static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
11320+{
11321+ paravirt_alloc_pmd(mm, __pa(pmd) >> PAGE_SHIFT);
11322+ set_pud(pud, __pud(_KERNPG_TABLE | __pa(pmd)));
11323+}
11324 #endif /* CONFIG_X86_PAE */
11325
11326 #if PAGETABLE_LEVELS > 3
11327@@ -114,6 +131,12 @@ static inline void pgd_populate(struct mm_struct *mm, pgd_t *pgd, pud_t *pud)
11328 set_pgd(pgd, __pgd(_PAGE_TABLE | __pa(pud)));
11329 }
11330
11331+static inline void pgd_populate_kernel(struct mm_struct *mm, pgd_t *pgd, pud_t *pud)
11332+{
11333+ paravirt_alloc_pud(mm, __pa(pud) >> PAGE_SHIFT);
11334+ set_pgd(pgd, __pgd(_KERNPG_TABLE | __pa(pud)));
11335+}
11336+
11337 static inline pud_t *pud_alloc_one(struct mm_struct *mm, unsigned long addr)
11338 {
11339 return (pud_t *)get_zeroed_page(GFP_KERNEL|__GFP_REPEAT);
11340diff --git a/arch/x86/include/asm/pgtable-2level.h b/arch/x86/include/asm/pgtable-2level.h
11341index f2b489c..4f7e2e5 100644
11342--- a/arch/x86/include/asm/pgtable-2level.h
11343+++ b/arch/x86/include/asm/pgtable-2level.h
11344@@ -18,7 +18,9 @@ static inline void native_set_pte(pte_t *ptep , pte_t pte)
11345
11346 static inline void native_set_pmd(pmd_t *pmdp, pmd_t pmd)
11347 {
11348+ pax_open_kernel();
11349 *pmdp = pmd;
11350+ pax_close_kernel();
11351 }
11352
11353 static inline void native_set_pte_atomic(pte_t *ptep, pte_t pte)
11354diff --git a/arch/x86/include/asm/pgtable-3level.h b/arch/x86/include/asm/pgtable-3level.h
11355index 4cc9f2b..5fd9226 100644
11356--- a/arch/x86/include/asm/pgtable-3level.h
11357+++ b/arch/x86/include/asm/pgtable-3level.h
11358@@ -92,12 +92,16 @@ static inline void native_set_pte_atomic(pte_t *ptep, pte_t pte)
11359
11360 static inline void native_set_pmd(pmd_t *pmdp, pmd_t pmd)
11361 {
11362+ pax_open_kernel();
11363 set_64bit((unsigned long long *)(pmdp), native_pmd_val(pmd));
11364+ pax_close_kernel();
11365 }
11366
11367 static inline void native_set_pud(pud_t *pudp, pud_t pud)
11368 {
11369+ pax_open_kernel();
11370 set_64bit((unsigned long long *)(pudp), native_pud_val(pud));
11371+ pax_close_kernel();
11372 }
11373
11374 /*
11375diff --git a/arch/x86/include/asm/pgtable.h b/arch/x86/include/asm/pgtable.h
11376index c3520d7..cf742ef 100644
11377--- a/arch/x86/include/asm/pgtable.h
11378+++ b/arch/x86/include/asm/pgtable.h
11379@@ -44,6 +44,7 @@ extern struct mm_struct *pgd_page_get_mm(struct page *page);
11380
11381 #ifndef __PAGETABLE_PUD_FOLDED
11382 #define set_pgd(pgdp, pgd) native_set_pgd(pgdp, pgd)
11383+#define set_pgd_batched(pgdp, pgd) native_set_pgd_batched(pgdp, pgd)
11384 #define pgd_clear(pgd) native_pgd_clear(pgd)
11385 #endif
11386
11387@@ -81,12 +82,51 @@ extern struct mm_struct *pgd_page_get_mm(struct page *page);
11388
11389 #define arch_end_context_switch(prev) do {} while(0)
11390
11391+#define pax_open_kernel() native_pax_open_kernel()
11392+#define pax_close_kernel() native_pax_close_kernel()
11393 #endif /* CONFIG_PARAVIRT */
11394
11395+#define __HAVE_ARCH_PAX_OPEN_KERNEL
11396+#define __HAVE_ARCH_PAX_CLOSE_KERNEL
11397+
11398+#ifdef CONFIG_PAX_KERNEXEC
11399+static inline unsigned long native_pax_open_kernel(void)
11400+{
11401+ unsigned long cr0;
11402+
11403+ preempt_disable();
11404+ barrier();
11405+ cr0 = read_cr0() ^ X86_CR0_WP;
11406+ BUG_ON(unlikely(cr0 & X86_CR0_WP));
11407+ write_cr0(cr0);
11408+ return cr0 ^ X86_CR0_WP;
11409+}
11410+
11411+static inline unsigned long native_pax_close_kernel(void)
11412+{
11413+ unsigned long cr0;
11414+
11415+ cr0 = read_cr0() ^ X86_CR0_WP;
11416+ BUG_ON(unlikely(!(cr0 & X86_CR0_WP)));
11417+ write_cr0(cr0);
11418+ barrier();
11419+ preempt_enable_no_resched();
11420+ return cr0 ^ X86_CR0_WP;
11421+}
11422+#else
11423+static inline unsigned long native_pax_open_kernel(void) { return 0; }
11424+static inline unsigned long native_pax_close_kernel(void) { return 0; }
11425+#endif
11426+
11427 /*
11428 * The following only work if pte_present() is true.
11429 * Undefined behaviour if not..
11430 */
11431+static inline int pte_user(pte_t pte)
11432+{
11433+ return pte_val(pte) & _PAGE_USER;
11434+}
11435+
11436 static inline int pte_dirty(pte_t pte)
11437 {
11438 return pte_flags(pte) & _PAGE_DIRTY;
11439@@ -195,9 +235,29 @@ static inline pte_t pte_wrprotect(pte_t pte)
11440 return pte_clear_flags(pte, _PAGE_RW);
11441 }
11442
11443+static inline pte_t pte_mkread(pte_t pte)
11444+{
11445+ return __pte(pte_val(pte) | _PAGE_USER);
11446+}
11447+
11448 static inline pte_t pte_mkexec(pte_t pte)
11449 {
11450- return pte_clear_flags(pte, _PAGE_NX);
11451+#ifdef CONFIG_X86_PAE
11452+ if (__supported_pte_mask & _PAGE_NX)
11453+ return pte_clear_flags(pte, _PAGE_NX);
11454+ else
11455+#endif
11456+ return pte_set_flags(pte, _PAGE_USER);
11457+}
11458+
11459+static inline pte_t pte_exprotect(pte_t pte)
11460+{
11461+#ifdef CONFIG_X86_PAE
11462+ if (__supported_pte_mask & _PAGE_NX)
11463+ return pte_set_flags(pte, _PAGE_NX);
11464+ else
11465+#endif
11466+ return pte_clear_flags(pte, _PAGE_USER);
11467 }
11468
11469 static inline pte_t pte_mkdirty(pte_t pte)
11470@@ -389,6 +449,15 @@ pte_t *populate_extra_pte(unsigned long vaddr);
11471 #endif
11472
11473 #ifndef __ASSEMBLY__
11474+
11475+#ifdef CONFIG_PAX_PER_CPU_PGD
11476+extern pgd_t cpu_pgd[NR_CPUS][PTRS_PER_PGD];
11477+static inline pgd_t *get_cpu_pgd(unsigned int cpu)
11478+{
11479+ return cpu_pgd[cpu];
11480+}
11481+#endif
11482+
11483 #include <linux/mm_types.h>
11484
11485 static inline int pte_none(pte_t pte)
11486@@ -565,7 +634,7 @@ static inline pud_t *pud_offset(pgd_t *pgd, unsigned long address)
11487
11488 static inline int pgd_bad(pgd_t pgd)
11489 {
11490- return (pgd_flags(pgd) & ~_PAGE_USER) != _KERNPG_TABLE;
11491+ return (pgd_flags(pgd) & ~(_PAGE_USER | _PAGE_NX)) != _KERNPG_TABLE;
11492 }
11493
11494 static inline int pgd_none(pgd_t pgd)
11495@@ -588,7 +657,12 @@ static inline int pgd_none(pgd_t pgd)
11496 * pgd_offset() returns a (pgd_t *)
11497 * pgd_index() is used get the offset into the pgd page's array of pgd_t's;
11498 */
11499-#define pgd_offset(mm, address) ((mm)->pgd + pgd_index((address)))
11500+#define pgd_offset(mm, address) ((mm)->pgd + pgd_index(address))
11501+
11502+#ifdef CONFIG_PAX_PER_CPU_PGD
11503+#define pgd_offset_cpu(cpu, address) (get_cpu_pgd(cpu) + pgd_index(address))
11504+#endif
11505+
11506 /*
11507 * a shortcut which implies the use of the kernel's pgd, instead
11508 * of a process's
11509@@ -599,6 +673,20 @@ static inline int pgd_none(pgd_t pgd)
11510 #define KERNEL_PGD_BOUNDARY pgd_index(PAGE_OFFSET)
11511 #define KERNEL_PGD_PTRS (PTRS_PER_PGD - KERNEL_PGD_BOUNDARY)
11512
11513+#ifdef CONFIG_X86_32
11514+#define USER_PGD_PTRS KERNEL_PGD_BOUNDARY
11515+#else
11516+#define TASK_SIZE_MAX_SHIFT CONFIG_TASK_SIZE_MAX_SHIFT
11517+#define USER_PGD_PTRS (_AC(1,UL) << (TASK_SIZE_MAX_SHIFT - PGDIR_SHIFT))
11518+
11519+#ifdef CONFIG_PAX_MEMORY_UDEREF
11520+#define PAX_USER_SHADOW_BASE (_AC(1,UL) << TASK_SIZE_MAX_SHIFT)
11521+#else
11522+#define PAX_USER_SHADOW_BASE (_AC(0,UL))
11523+#endif
11524+
11525+#endif
11526+
11527 #ifndef __ASSEMBLY__
11528
11529 extern int direct_gbpages;
11530@@ -763,11 +851,23 @@ static inline void pmdp_set_wrprotect(struct mm_struct *mm,
11531 * dst and src can be on the same page, but the range must not overlap,
11532 * and must not cross a page boundary.
11533 */
11534-static inline void clone_pgd_range(pgd_t *dst, pgd_t *src, int count)
11535+static inline void clone_pgd_range(pgd_t *dst, const pgd_t *src, int count)
11536 {
11537- memcpy(dst, src, count * sizeof(pgd_t));
11538+ pax_open_kernel();
11539+ while (count--)
11540+ *dst++ = *src++;
11541+ pax_close_kernel();
11542 }
11543
11544+#ifdef CONFIG_PAX_PER_CPU_PGD
11545+extern void __clone_user_pgds(pgd_t *dst, const pgd_t *src);
11546+#endif
11547+
11548+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
11549+extern void __shadow_user_pgds(pgd_t *dst, const pgd_t *src);
11550+#else
11551+static inline void __shadow_user_pgds(pgd_t *dst, const pgd_t *src) {}
11552+#endif
11553
11554 #include <asm-generic/pgtable.h>
11555 #endif /* __ASSEMBLY__ */
11556diff --git a/arch/x86/include/asm/pgtable_32.h b/arch/x86/include/asm/pgtable_32.h
11557index 0c92113..34a77c6 100644
11558--- a/arch/x86/include/asm/pgtable_32.h
11559+++ b/arch/x86/include/asm/pgtable_32.h
11560@@ -25,9 +25,6 @@
11561 struct mm_struct;
11562 struct vm_area_struct;
11563
11564-extern pgd_t swapper_pg_dir[1024];
11565-extern pgd_t initial_page_table[1024];
11566-
11567 static inline void pgtable_cache_init(void) { }
11568 static inline void check_pgt_cache(void) { }
11569 void paging_init(void);
11570@@ -48,6 +45,12 @@ extern void set_pmd_pfn(unsigned long, unsigned long, pgprot_t);
11571 # include <asm/pgtable-2level.h>
11572 #endif
11573
11574+extern pgd_t swapper_pg_dir[PTRS_PER_PGD];
11575+extern pgd_t initial_page_table[PTRS_PER_PGD];
11576+#ifdef CONFIG_X86_PAE
11577+extern pmd_t swapper_pm_dir[PTRS_PER_PGD][PTRS_PER_PMD];
11578+#endif
11579+
11580 #if defined(CONFIG_HIGHPTE)
11581 #define pte_offset_map(dir, address) \
11582 ((pte_t *)kmap_atomic(pmd_page(*(dir))) + \
11583@@ -62,7 +65,9 @@ extern void set_pmd_pfn(unsigned long, unsigned long, pgprot_t);
11584 /* Clear a kernel PTE and flush it from the TLB */
11585 #define kpte_clear_flush(ptep, vaddr) \
11586 do { \
11587+ pax_open_kernel(); \
11588 pte_clear(&init_mm, (vaddr), (ptep)); \
11589+ pax_close_kernel(); \
11590 __flush_tlb_one((vaddr)); \
11591 } while (0)
11592
11593@@ -74,6 +79,9 @@ do { \
11594
11595 #endif /* !__ASSEMBLY__ */
11596
11597+#define HAVE_ARCH_UNMAPPED_AREA
11598+#define HAVE_ARCH_UNMAPPED_AREA_TOPDOWN
11599+
11600 /*
11601 * kern_addr_valid() is (1) for FLATMEM and (0) for
11602 * SPARSEMEM and DISCONTIGMEM
11603diff --git a/arch/x86/include/asm/pgtable_32_types.h b/arch/x86/include/asm/pgtable_32_types.h
11604index ed5903b..c7fe163 100644
11605--- a/arch/x86/include/asm/pgtable_32_types.h
11606+++ b/arch/x86/include/asm/pgtable_32_types.h
11607@@ -8,7 +8,7 @@
11608 */
11609 #ifdef CONFIG_X86_PAE
11610 # include <asm/pgtable-3level_types.h>
11611-# define PMD_SIZE (1UL << PMD_SHIFT)
11612+# define PMD_SIZE (_AC(1, UL) << PMD_SHIFT)
11613 # define PMD_MASK (~(PMD_SIZE - 1))
11614 #else
11615 # include <asm/pgtable-2level_types.h>
11616@@ -46,6 +46,19 @@ extern bool __vmalloc_start_set; /* set once high_memory is set */
11617 # define VMALLOC_END (FIXADDR_START - 2 * PAGE_SIZE)
11618 #endif
11619
11620+#ifdef CONFIG_PAX_KERNEXEC
11621+#ifndef __ASSEMBLY__
11622+extern unsigned char MODULES_EXEC_VADDR[];
11623+extern unsigned char MODULES_EXEC_END[];
11624+#endif
11625+#include <asm/boot.h>
11626+#define ktla_ktva(addr) (addr + LOAD_PHYSICAL_ADDR + PAGE_OFFSET)
11627+#define ktva_ktla(addr) (addr - LOAD_PHYSICAL_ADDR - PAGE_OFFSET)
11628+#else
11629+#define ktla_ktva(addr) (addr)
11630+#define ktva_ktla(addr) (addr)
11631+#endif
11632+
11633 #define MODULES_VADDR VMALLOC_START
11634 #define MODULES_END VMALLOC_END
11635 #define MODULES_LEN (MODULES_VADDR - MODULES_END)
11636diff --git a/arch/x86/include/asm/pgtable_64.h b/arch/x86/include/asm/pgtable_64.h
11637index 8251be0..4ea8b46 100644
11638--- a/arch/x86/include/asm/pgtable_64.h
11639+++ b/arch/x86/include/asm/pgtable_64.h
11640@@ -16,10 +16,14 @@
11641
11642 extern pud_t level3_kernel_pgt[512];
11643 extern pud_t level3_ident_pgt[512];
11644+extern pud_t level3_vmalloc_start_pgt[512];
11645+extern pud_t level3_vmalloc_end_pgt[512];
11646+extern pud_t level3_vmemmap_pgt[512];
11647+extern pud_t level2_vmemmap_pgt[512];
11648 extern pmd_t level2_kernel_pgt[512];
11649 extern pmd_t level2_fixmap_pgt[512];
11650-extern pmd_t level2_ident_pgt[512];
11651-extern pgd_t init_level4_pgt[];
11652+extern pmd_t level2_ident_pgt[512*2];
11653+extern pgd_t init_level4_pgt[512];
11654
11655 #define swapper_pg_dir init_level4_pgt
11656
11657@@ -61,7 +65,9 @@ static inline void native_set_pte_atomic(pte_t *ptep, pte_t pte)
11658
11659 static inline void native_set_pmd(pmd_t *pmdp, pmd_t pmd)
11660 {
11661+ pax_open_kernel();
11662 *pmdp = pmd;
11663+ pax_close_kernel();
11664 }
11665
11666 static inline void native_pmd_clear(pmd_t *pmd)
11667@@ -97,7 +103,9 @@ static inline pmd_t native_pmdp_get_and_clear(pmd_t *xp)
11668
11669 static inline void native_set_pud(pud_t *pudp, pud_t pud)
11670 {
11671+ pax_open_kernel();
11672 *pudp = pud;
11673+ pax_close_kernel();
11674 }
11675
11676 static inline void native_pud_clear(pud_t *pud)
11677@@ -107,6 +115,13 @@ static inline void native_pud_clear(pud_t *pud)
11678
11679 static inline void native_set_pgd(pgd_t *pgdp, pgd_t pgd)
11680 {
11681+ pax_open_kernel();
11682+ *pgdp = pgd;
11683+ pax_close_kernel();
11684+}
11685+
11686+static inline void native_set_pgd_batched(pgd_t *pgdp, pgd_t pgd)
11687+{
11688 *pgdp = pgd;
11689 }
11690
11691diff --git a/arch/x86/include/asm/pgtable_64_types.h b/arch/x86/include/asm/pgtable_64_types.h
11692index 766ea16..5b96cb3 100644
11693--- a/arch/x86/include/asm/pgtable_64_types.h
11694+++ b/arch/x86/include/asm/pgtable_64_types.h
11695@@ -59,5 +59,10 @@ typedef struct { pteval_t pte; } pte_t;
11696 #define MODULES_VADDR _AC(0xffffffffa0000000, UL)
11697 #define MODULES_END _AC(0xffffffffff000000, UL)
11698 #define MODULES_LEN (MODULES_END - MODULES_VADDR)
11699+#define MODULES_EXEC_VADDR MODULES_VADDR
11700+#define MODULES_EXEC_END MODULES_END
11701+
11702+#define ktla_ktva(addr) (addr)
11703+#define ktva_ktla(addr) (addr)
11704
11705 #endif /* _ASM_X86_PGTABLE_64_DEFS_H */
11706diff --git a/arch/x86/include/asm/pgtable_types.h b/arch/x86/include/asm/pgtable_types.h
11707index 013286a..8b42f4f 100644
11708--- a/arch/x86/include/asm/pgtable_types.h
11709+++ b/arch/x86/include/asm/pgtable_types.h
11710@@ -16,13 +16,12 @@
11711 #define _PAGE_BIT_PSE 7 /* 4 MB (or 2MB) page */
11712 #define _PAGE_BIT_PAT 7 /* on 4KB pages */
11713 #define _PAGE_BIT_GLOBAL 8 /* Global TLB entry PPro+ */
11714-#define _PAGE_BIT_UNUSED1 9 /* available for programmer */
11715+#define _PAGE_BIT_SPECIAL 9 /* special mappings, no associated struct page */
11716 #define _PAGE_BIT_IOMAP 10 /* flag used to indicate IO mapping */
11717 #define _PAGE_BIT_HIDDEN 11 /* hidden by kmemcheck */
11718 #define _PAGE_BIT_PAT_LARGE 12 /* On 2MB or 1GB pages */
11719-#define _PAGE_BIT_SPECIAL _PAGE_BIT_UNUSED1
11720-#define _PAGE_BIT_CPA_TEST _PAGE_BIT_UNUSED1
11721-#define _PAGE_BIT_SPLITTING _PAGE_BIT_UNUSED1 /* only valid on a PSE pmd */
11722+#define _PAGE_BIT_CPA_TEST _PAGE_BIT_SPECIAL
11723+#define _PAGE_BIT_SPLITTING _PAGE_BIT_SPECIAL /* only valid on a PSE pmd */
11724 #define _PAGE_BIT_NX 63 /* No execute: only valid after cpuid check */
11725
11726 /* If _PAGE_BIT_PRESENT is clear, we use these: */
11727@@ -40,7 +39,6 @@
11728 #define _PAGE_DIRTY (_AT(pteval_t, 1) << _PAGE_BIT_DIRTY)
11729 #define _PAGE_PSE (_AT(pteval_t, 1) << _PAGE_BIT_PSE)
11730 #define _PAGE_GLOBAL (_AT(pteval_t, 1) << _PAGE_BIT_GLOBAL)
11731-#define _PAGE_UNUSED1 (_AT(pteval_t, 1) << _PAGE_BIT_UNUSED1)
11732 #define _PAGE_IOMAP (_AT(pteval_t, 1) << _PAGE_BIT_IOMAP)
11733 #define _PAGE_PAT (_AT(pteval_t, 1) << _PAGE_BIT_PAT)
11734 #define _PAGE_PAT_LARGE (_AT(pteval_t, 1) << _PAGE_BIT_PAT_LARGE)
11735@@ -57,8 +55,10 @@
11736
11737 #if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
11738 #define _PAGE_NX (_AT(pteval_t, 1) << _PAGE_BIT_NX)
11739-#else
11740+#elif defined(CONFIG_KMEMCHECK)
11741 #define _PAGE_NX (_AT(pteval_t, 0))
11742+#else
11743+#define _PAGE_NX (_AT(pteval_t, 1) << _PAGE_BIT_HIDDEN)
11744 #endif
11745
11746 #define _PAGE_FILE (_AT(pteval_t, 1) << _PAGE_BIT_FILE)
11747@@ -96,6 +96,9 @@
11748 #define PAGE_READONLY_EXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | \
11749 _PAGE_ACCESSED)
11750
11751+#define PAGE_READONLY_NOEXEC PAGE_READONLY
11752+#define PAGE_SHARED_NOEXEC PAGE_SHARED
11753+
11754 #define __PAGE_KERNEL_EXEC \
11755 (_PAGE_PRESENT | _PAGE_RW | _PAGE_DIRTY | _PAGE_ACCESSED | _PAGE_GLOBAL)
11756 #define __PAGE_KERNEL (__PAGE_KERNEL_EXEC | _PAGE_NX)
11757@@ -106,7 +109,7 @@
11758 #define __PAGE_KERNEL_WC (__PAGE_KERNEL | _PAGE_CACHE_WC)
11759 #define __PAGE_KERNEL_NOCACHE (__PAGE_KERNEL | _PAGE_PCD | _PAGE_PWT)
11760 #define __PAGE_KERNEL_UC_MINUS (__PAGE_KERNEL | _PAGE_PCD)
11761-#define __PAGE_KERNEL_VSYSCALL (__PAGE_KERNEL_RX | _PAGE_USER)
11762+#define __PAGE_KERNEL_VSYSCALL (__PAGE_KERNEL_RO | _PAGE_USER)
11763 #define __PAGE_KERNEL_VVAR (__PAGE_KERNEL_RO | _PAGE_USER)
11764 #define __PAGE_KERNEL_VVAR_NOCACHE (__PAGE_KERNEL_VVAR | _PAGE_PCD | _PAGE_PWT)
11765 #define __PAGE_KERNEL_LARGE (__PAGE_KERNEL | _PAGE_PSE)
11766@@ -168,8 +171,8 @@
11767 * bits are combined, this will alow user to access the high address mapped
11768 * VDSO in the presence of CONFIG_COMPAT_VDSO
11769 */
11770-#define PTE_IDENT_ATTR 0x003 /* PRESENT+RW */
11771-#define PDE_IDENT_ATTR 0x067 /* PRESENT+RW+USER+DIRTY+ACCESSED */
11772+#define PTE_IDENT_ATTR 0x063 /* PRESENT+RW+DIRTY+ACCESSED */
11773+#define PDE_IDENT_ATTR 0x063 /* PRESENT+RW+DIRTY+ACCESSED */
11774 #define PGD_IDENT_ATTR 0x001 /* PRESENT (no other attributes) */
11775 #endif
11776
11777@@ -207,7 +210,17 @@ static inline pgdval_t pgd_flags(pgd_t pgd)
11778 {
11779 return native_pgd_val(pgd) & PTE_FLAGS_MASK;
11780 }
11781+#endif
11782
11783+#if PAGETABLE_LEVELS == 3
11784+#include <asm-generic/pgtable-nopud.h>
11785+#endif
11786+
11787+#if PAGETABLE_LEVELS == 2
11788+#include <asm-generic/pgtable-nopmd.h>
11789+#endif
11790+
11791+#ifndef __ASSEMBLY__
11792 #if PAGETABLE_LEVELS > 3
11793 typedef struct { pudval_t pud; } pud_t;
11794
11795@@ -221,8 +234,6 @@ static inline pudval_t native_pud_val(pud_t pud)
11796 return pud.pud;
11797 }
11798 #else
11799-#include <asm-generic/pgtable-nopud.h>
11800-
11801 static inline pudval_t native_pud_val(pud_t pud)
11802 {
11803 return native_pgd_val(pud.pgd);
11804@@ -242,8 +253,6 @@ static inline pmdval_t native_pmd_val(pmd_t pmd)
11805 return pmd.pmd;
11806 }
11807 #else
11808-#include <asm-generic/pgtable-nopmd.h>
11809-
11810 static inline pmdval_t native_pmd_val(pmd_t pmd)
11811 {
11812 return native_pgd_val(pmd.pud.pgd);
11813@@ -283,7 +292,6 @@ typedef struct page *pgtable_t;
11814
11815 extern pteval_t __supported_pte_mask;
11816 extern void set_nx(void);
11817-extern int nx_enabled;
11818
11819 #define pgprot_writecombine pgprot_writecombine
11820 extern pgprot_t pgprot_writecombine(pgprot_t prot);
11821diff --git a/arch/x86/include/asm/processor-flags.h b/arch/x86/include/asm/processor-flags.h
11822index aea1d1d..680cf09 100644
11823--- a/arch/x86/include/asm/processor-flags.h
11824+++ b/arch/x86/include/asm/processor-flags.h
11825@@ -65,6 +65,7 @@
11826 #define X86_CR4_PCIDE 0x00020000 /* enable PCID support */
11827 #define X86_CR4_OSXSAVE 0x00040000 /* enable xsave and xrestore */
11828 #define X86_CR4_SMEP 0x00100000 /* enable SMEP support */
11829+#define X86_CR4_SMAP 0x00200000 /* enable SMAP support */
11830
11831 /*
11832 * x86-64 Task Priority Register, CR8
11833diff --git a/arch/x86/include/asm/processor.h b/arch/x86/include/asm/processor.h
11834index d048cad..45e350f 100644
11835--- a/arch/x86/include/asm/processor.h
11836+++ b/arch/x86/include/asm/processor.h
11837@@ -289,7 +289,7 @@ struct tss_struct {
11838
11839 } ____cacheline_aligned;
11840
11841-DECLARE_PER_CPU_SHARED_ALIGNED(struct tss_struct, init_tss);
11842+extern struct tss_struct init_tss[NR_CPUS];
11843
11844 /*
11845 * Save the original ist values for checking stack pointers during debugging
11846@@ -822,11 +822,18 @@ static inline void spin_lock_prefetch(const void *x)
11847 */
11848 #define TASK_SIZE PAGE_OFFSET
11849 #define TASK_SIZE_MAX TASK_SIZE
11850+
11851+#ifdef CONFIG_PAX_SEGMEXEC
11852+#define SEGMEXEC_TASK_SIZE (TASK_SIZE / 2)
11853+#define STACK_TOP ((current->mm->pax_flags & MF_PAX_SEGMEXEC)?SEGMEXEC_TASK_SIZE:TASK_SIZE)
11854+#else
11855 #define STACK_TOP TASK_SIZE
11856-#define STACK_TOP_MAX STACK_TOP
11857+#endif
11858+
11859+#define STACK_TOP_MAX TASK_SIZE
11860
11861 #define INIT_THREAD { \
11862- .sp0 = sizeof(init_stack) + (long)&init_stack, \
11863+ .sp0 = sizeof(init_stack) + (long)&init_stack - 8, \
11864 .vm86_info = NULL, \
11865 .sysenter_cs = __KERNEL_CS, \
11866 .io_bitmap_ptr = NULL, \
11867@@ -840,7 +847,7 @@ static inline void spin_lock_prefetch(const void *x)
11868 */
11869 #define INIT_TSS { \
11870 .x86_tss = { \
11871- .sp0 = sizeof(init_stack) + (long)&init_stack, \
11872+ .sp0 = sizeof(init_stack) + (long)&init_stack - 8, \
11873 .ss0 = __KERNEL_DS, \
11874 .ss1 = __KERNEL_CS, \
11875 .io_bitmap_base = INVALID_IO_BITMAP_OFFSET, \
11876@@ -851,11 +858,7 @@ static inline void spin_lock_prefetch(const void *x)
11877 extern unsigned long thread_saved_pc(struct task_struct *tsk);
11878
11879 #define THREAD_SIZE_LONGS (THREAD_SIZE/sizeof(unsigned long))
11880-#define KSTK_TOP(info) \
11881-({ \
11882- unsigned long *__ptr = (unsigned long *)(info); \
11883- (unsigned long)(&__ptr[THREAD_SIZE_LONGS]); \
11884-})
11885+#define KSTK_TOP(info) ((container_of(info, struct task_struct, tinfo))->thread.sp0)
11886
11887 /*
11888 * The below -8 is to reserve 8 bytes on top of the ring0 stack.
11889@@ -870,7 +873,7 @@ extern unsigned long thread_saved_pc(struct task_struct *tsk);
11890 #define task_pt_regs(task) \
11891 ({ \
11892 struct pt_regs *__regs__; \
11893- __regs__ = (struct pt_regs *)(KSTK_TOP(task_stack_page(task))-8); \
11894+ __regs__ = (struct pt_regs *)((task)->thread.sp0); \
11895 __regs__ - 1; \
11896 })
11897
11898@@ -880,13 +883,13 @@ extern unsigned long thread_saved_pc(struct task_struct *tsk);
11899 /*
11900 * User space process size. 47bits minus one guard page.
11901 */
11902-#define TASK_SIZE_MAX ((1UL << 47) - PAGE_SIZE)
11903+#define TASK_SIZE_MAX ((1UL << TASK_SIZE_MAX_SHIFT) - PAGE_SIZE)
11904
11905 /* This decides where the kernel will search for a free chunk of vm
11906 * space during mmap's.
11907 */
11908 #define IA32_PAGE_OFFSET ((current->personality & ADDR_LIMIT_3GB) ? \
11909- 0xc0000000 : 0xFFFFe000)
11910+ 0xc0000000 : 0xFFFFf000)
11911
11912 #define TASK_SIZE (test_thread_flag(TIF_ADDR32) ? \
11913 IA32_PAGE_OFFSET : TASK_SIZE_MAX)
11914@@ -897,11 +900,11 @@ extern unsigned long thread_saved_pc(struct task_struct *tsk);
11915 #define STACK_TOP_MAX TASK_SIZE_MAX
11916
11917 #define INIT_THREAD { \
11918- .sp0 = (unsigned long)&init_stack + sizeof(init_stack) \
11919+ .sp0 = (unsigned long)&init_stack + sizeof(init_stack) - 16 \
11920 }
11921
11922 #define INIT_TSS { \
11923- .x86_tss.sp0 = (unsigned long)&init_stack + sizeof(init_stack) \
11924+ .x86_tss.sp0 = (unsigned long)&init_stack + sizeof(init_stack) - 16 \
11925 }
11926
11927 /*
11928@@ -929,6 +932,10 @@ extern void start_thread(struct pt_regs *regs, unsigned long new_ip,
11929 */
11930 #define TASK_UNMAPPED_BASE (PAGE_ALIGN(TASK_SIZE / 3))
11931
11932+#ifdef CONFIG_PAX_SEGMEXEC
11933+#define SEGMEXEC_TASK_UNMAPPED_BASE (PAGE_ALIGN(SEGMEXEC_TASK_SIZE / 3))
11934+#endif
11935+
11936 #define KSTK_EIP(task) (task_pt_regs(task)->ip)
11937
11938 /* Get/set a process' ability to use the timestamp counter instruction */
11939@@ -989,12 +996,12 @@ extern bool cpu_has_amd_erratum(const int *);
11940 #define cpu_has_amd_erratum(x) (false)
11941 #endif /* CONFIG_CPU_SUP_AMD */
11942
11943-extern unsigned long arch_align_stack(unsigned long sp);
11944+#define arch_align_stack(x) ((x) & ~0xfUL)
11945 extern void free_init_pages(char *what, unsigned long begin, unsigned long end);
11946
11947 void default_idle(void);
11948 bool set_pm_idle_to_default(void);
11949
11950-void stop_this_cpu(void *dummy);
11951+void stop_this_cpu(void *dummy) __noreturn;
11952
11953 #endif /* _ASM_X86_PROCESSOR_H */
11954diff --git a/arch/x86/include/asm/ptrace.h b/arch/x86/include/asm/ptrace.h
11955index dcfde52..dbfea06 100644
11956--- a/arch/x86/include/asm/ptrace.h
11957+++ b/arch/x86/include/asm/ptrace.h
11958@@ -155,28 +155,29 @@ static inline unsigned long regs_return_value(struct pt_regs *regs)
11959 }
11960
11961 /*
11962- * user_mode_vm(regs) determines whether a register set came from user mode.
11963+ * user_mode(regs) determines whether a register set came from user mode.
11964 * This is true if V8086 mode was enabled OR if the register set was from
11965 * protected mode with RPL-3 CS value. This tricky test checks that with
11966 * one comparison. Many places in the kernel can bypass this full check
11967- * if they have already ruled out V8086 mode, so user_mode(regs) can be used.
11968+ * if they have already ruled out V8086 mode, so user_mode_novm(regs) can
11969+ * be used.
11970 */
11971-static inline int user_mode(struct pt_regs *regs)
11972+static inline int user_mode_novm(struct pt_regs *regs)
11973 {
11974 #ifdef CONFIG_X86_32
11975 return (regs->cs & SEGMENT_RPL_MASK) == USER_RPL;
11976 #else
11977- return !!(regs->cs & 3);
11978+ return !!(regs->cs & SEGMENT_RPL_MASK);
11979 #endif
11980 }
11981
11982-static inline int user_mode_vm(struct pt_regs *regs)
11983+static inline int user_mode(struct pt_regs *regs)
11984 {
11985 #ifdef CONFIG_X86_32
11986 return ((regs->cs & SEGMENT_RPL_MASK) | (regs->flags & X86_VM_MASK)) >=
11987 USER_RPL;
11988 #else
11989- return user_mode(regs);
11990+ return user_mode_novm(regs);
11991 #endif
11992 }
11993
11994@@ -192,15 +193,16 @@ static inline int v8086_mode(struct pt_regs *regs)
11995 #ifdef CONFIG_X86_64
11996 static inline bool user_64bit_mode(struct pt_regs *regs)
11997 {
11998+ unsigned long cs = regs->cs & 0xffff;
11999 #ifndef CONFIG_PARAVIRT
12000 /*
12001 * On non-paravirt systems, this is the only long mode CPL 3
12002 * selector. We do not allow long mode selectors in the LDT.
12003 */
12004- return regs->cs == __USER_CS;
12005+ return cs == __USER_CS;
12006 #else
12007 /* Headers are too twisted for this to go in paravirt.h. */
12008- return regs->cs == __USER_CS || regs->cs == pv_info.extra_user_64bit_cs;
12009+ return cs == __USER_CS || cs == pv_info.extra_user_64bit_cs;
12010 #endif
12011 }
12012 #endif
12013diff --git a/arch/x86/include/asm/realmode.h b/arch/x86/include/asm/realmode.h
12014index fe1ec5b..dc5c3fe 100644
12015--- a/arch/x86/include/asm/realmode.h
12016+++ b/arch/x86/include/asm/realmode.h
12017@@ -22,16 +22,14 @@ struct real_mode_header {
12018 #endif
12019 /* APM/BIOS reboot */
12020 u32 machine_real_restart_asm;
12021-#ifdef CONFIG_X86_64
12022 u32 machine_real_restart_seg;
12023-#endif
12024 };
12025
12026 /* This must match data at trampoline_32/64.S */
12027 struct trampoline_header {
12028 #ifdef CONFIG_X86_32
12029 u32 start;
12030- u16 gdt_pad;
12031+ u16 boot_cs;
12032 u16 gdt_limit;
12033 u32 gdt_base;
12034 #else
12035diff --git a/arch/x86/include/asm/reboot.h b/arch/x86/include/asm/reboot.h
12036index a82c4f1..ac45053 100644
12037--- a/arch/x86/include/asm/reboot.h
12038+++ b/arch/x86/include/asm/reboot.h
12039@@ -6,13 +6,13 @@
12040 struct pt_regs;
12041
12042 struct machine_ops {
12043- void (*restart)(char *cmd);
12044- void (*halt)(void);
12045- void (*power_off)(void);
12046+ void (* __noreturn restart)(char *cmd);
12047+ void (* __noreturn halt)(void);
12048+ void (* __noreturn power_off)(void);
12049 void (*shutdown)(void);
12050 void (*crash_shutdown)(struct pt_regs *);
12051- void (*emergency_restart)(void);
12052-};
12053+ void (* __noreturn emergency_restart)(void);
12054+} __no_const;
12055
12056 extern struct machine_ops machine_ops;
12057
12058diff --git a/arch/x86/include/asm/rwsem.h b/arch/x86/include/asm/rwsem.h
12059index 2dbe4a7..ce1db00 100644
12060--- a/arch/x86/include/asm/rwsem.h
12061+++ b/arch/x86/include/asm/rwsem.h
12062@@ -64,6 +64,14 @@ static inline void __down_read(struct rw_semaphore *sem)
12063 {
12064 asm volatile("# beginning down_read\n\t"
12065 LOCK_PREFIX _ASM_INC "(%1)\n\t"
12066+
12067+#ifdef CONFIG_PAX_REFCOUNT
12068+ "jno 0f\n"
12069+ LOCK_PREFIX _ASM_DEC "(%1)\n"
12070+ "int $4\n0:\n"
12071+ _ASM_EXTABLE(0b, 0b)
12072+#endif
12073+
12074 /* adds 0x00000001 */
12075 " jns 1f\n"
12076 " call call_rwsem_down_read_failed\n"
12077@@ -85,6 +93,14 @@ static inline int __down_read_trylock(struct rw_semaphore *sem)
12078 "1:\n\t"
12079 " mov %1,%2\n\t"
12080 " add %3,%2\n\t"
12081+
12082+#ifdef CONFIG_PAX_REFCOUNT
12083+ "jno 0f\n"
12084+ "sub %3,%2\n"
12085+ "int $4\n0:\n"
12086+ _ASM_EXTABLE(0b, 0b)
12087+#endif
12088+
12089 " jle 2f\n\t"
12090 LOCK_PREFIX " cmpxchg %2,%0\n\t"
12091 " jnz 1b\n\t"
12092@@ -104,6 +120,14 @@ static inline void __down_write_nested(struct rw_semaphore *sem, int subclass)
12093 long tmp;
12094 asm volatile("# beginning down_write\n\t"
12095 LOCK_PREFIX " xadd %1,(%2)\n\t"
12096+
12097+#ifdef CONFIG_PAX_REFCOUNT
12098+ "jno 0f\n"
12099+ "mov %1,(%2)\n"
12100+ "int $4\n0:\n"
12101+ _ASM_EXTABLE(0b, 0b)
12102+#endif
12103+
12104 /* adds 0xffff0001, returns the old value */
12105 " test %1,%1\n\t"
12106 /* was the count 0 before? */
12107@@ -141,6 +165,14 @@ static inline void __up_read(struct rw_semaphore *sem)
12108 long tmp;
12109 asm volatile("# beginning __up_read\n\t"
12110 LOCK_PREFIX " xadd %1,(%2)\n\t"
12111+
12112+#ifdef CONFIG_PAX_REFCOUNT
12113+ "jno 0f\n"
12114+ "mov %1,(%2)\n"
12115+ "int $4\n0:\n"
12116+ _ASM_EXTABLE(0b, 0b)
12117+#endif
12118+
12119 /* subtracts 1, returns the old value */
12120 " jns 1f\n\t"
12121 " call call_rwsem_wake\n" /* expects old value in %edx */
12122@@ -159,6 +191,14 @@ static inline void __up_write(struct rw_semaphore *sem)
12123 long tmp;
12124 asm volatile("# beginning __up_write\n\t"
12125 LOCK_PREFIX " xadd %1,(%2)\n\t"
12126+
12127+#ifdef CONFIG_PAX_REFCOUNT
12128+ "jno 0f\n"
12129+ "mov %1,(%2)\n"
12130+ "int $4\n0:\n"
12131+ _ASM_EXTABLE(0b, 0b)
12132+#endif
12133+
12134 /* subtracts 0xffff0001, returns the old value */
12135 " jns 1f\n\t"
12136 " call call_rwsem_wake\n" /* expects old value in %edx */
12137@@ -176,6 +216,14 @@ static inline void __downgrade_write(struct rw_semaphore *sem)
12138 {
12139 asm volatile("# beginning __downgrade_write\n\t"
12140 LOCK_PREFIX _ASM_ADD "%2,(%1)\n\t"
12141+
12142+#ifdef CONFIG_PAX_REFCOUNT
12143+ "jno 0f\n"
12144+ LOCK_PREFIX _ASM_SUB "%2,(%1)\n"
12145+ "int $4\n0:\n"
12146+ _ASM_EXTABLE(0b, 0b)
12147+#endif
12148+
12149 /*
12150 * transitions 0xZZZZ0001 -> 0xYYYY0001 (i386)
12151 * 0xZZZZZZZZ00000001 -> 0xYYYYYYYY00000001 (x86_64)
12152@@ -194,7 +242,15 @@ static inline void __downgrade_write(struct rw_semaphore *sem)
12153 */
12154 static inline void rwsem_atomic_add(long delta, struct rw_semaphore *sem)
12155 {
12156- asm volatile(LOCK_PREFIX _ASM_ADD "%1,%0"
12157+ asm volatile(LOCK_PREFIX _ASM_ADD "%1,%0\n"
12158+
12159+#ifdef CONFIG_PAX_REFCOUNT
12160+ "jno 0f\n"
12161+ LOCK_PREFIX _ASM_SUB "%1,%0\n"
12162+ "int $4\n0:\n"
12163+ _ASM_EXTABLE(0b, 0b)
12164+#endif
12165+
12166 : "+m" (sem->count)
12167 : "er" (delta));
12168 }
12169@@ -204,7 +260,7 @@ static inline void rwsem_atomic_add(long delta, struct rw_semaphore *sem)
12170 */
12171 static inline long rwsem_atomic_update(long delta, struct rw_semaphore *sem)
12172 {
12173- return delta + xadd(&sem->count, delta);
12174+ return delta + xadd_check_overflow(&sem->count, delta);
12175 }
12176
12177 #endif /* __KERNEL__ */
12178diff --git a/arch/x86/include/asm/segment.h b/arch/x86/include/asm/segment.h
12179index c48a950..c6d7468 100644
12180--- a/arch/x86/include/asm/segment.h
12181+++ b/arch/x86/include/asm/segment.h
12182@@ -64,10 +64,15 @@
12183 * 26 - ESPFIX small SS
12184 * 27 - per-cpu [ offset to per-cpu data area ]
12185 * 28 - stack_canary-20 [ for stack protector ]
12186- * 29 - unused
12187- * 30 - unused
12188+ * 29 - PCI BIOS CS
12189+ * 30 - PCI BIOS DS
12190 * 31 - TSS for double fault handler
12191 */
12192+#define GDT_ENTRY_KERNEXEC_EFI_CS (1)
12193+#define GDT_ENTRY_KERNEXEC_EFI_DS (2)
12194+#define __KERNEXEC_EFI_CS (GDT_ENTRY_KERNEXEC_EFI_CS*8)
12195+#define __KERNEXEC_EFI_DS (GDT_ENTRY_KERNEXEC_EFI_DS*8)
12196+
12197 #define GDT_ENTRY_TLS_MIN 6
12198 #define GDT_ENTRY_TLS_MAX (GDT_ENTRY_TLS_MIN + GDT_ENTRY_TLS_ENTRIES - 1)
12199
12200@@ -79,6 +84,8 @@
12201
12202 #define GDT_ENTRY_KERNEL_CS (GDT_ENTRY_KERNEL_BASE+0)
12203
12204+#define GDT_ENTRY_KERNEXEC_KERNEL_CS (4)
12205+
12206 #define GDT_ENTRY_KERNEL_DS (GDT_ENTRY_KERNEL_BASE+1)
12207
12208 #define GDT_ENTRY_TSS (GDT_ENTRY_KERNEL_BASE+4)
12209@@ -104,6 +111,12 @@
12210 #define __KERNEL_STACK_CANARY 0
12211 #endif
12212
12213+#define GDT_ENTRY_PCIBIOS_CS (GDT_ENTRY_KERNEL_BASE+17)
12214+#define __PCIBIOS_CS (GDT_ENTRY_PCIBIOS_CS * 8)
12215+
12216+#define GDT_ENTRY_PCIBIOS_DS (GDT_ENTRY_KERNEL_BASE+18)
12217+#define __PCIBIOS_DS (GDT_ENTRY_PCIBIOS_DS * 8)
12218+
12219 #define GDT_ENTRY_DOUBLEFAULT_TSS 31
12220
12221 /*
12222@@ -141,7 +154,7 @@
12223 */
12224
12225 /* Matches PNP_CS32 and PNP_CS16 (they must be consecutive) */
12226-#define SEGMENT_IS_PNP_CODE(x) (((x) & 0xf4) == GDT_ENTRY_PNPBIOS_BASE * 8)
12227+#define SEGMENT_IS_PNP_CODE(x) (((x) & 0xFFFCU) == PNP_CS32 || ((x) & 0xFFFCU) == PNP_CS16)
12228
12229
12230 #else
12231@@ -165,6 +178,8 @@
12232 #define __USER32_CS (GDT_ENTRY_DEFAULT_USER32_CS*8+3)
12233 #define __USER32_DS __USER_DS
12234
12235+#define GDT_ENTRY_KERNEXEC_KERNEL_CS 7
12236+
12237 #define GDT_ENTRY_TSS 8 /* needs two entries */
12238 #define GDT_ENTRY_LDT 10 /* needs two entries */
12239 #define GDT_ENTRY_TLS_MIN 12
12240@@ -185,6 +200,7 @@
12241 #endif
12242
12243 #define __KERNEL_CS (GDT_ENTRY_KERNEL_CS*8)
12244+#define __KERNEXEC_KERNEL_CS (GDT_ENTRY_KERNEXEC_KERNEL_CS*8)
12245 #define __KERNEL_DS (GDT_ENTRY_KERNEL_DS*8)
12246 #define __USER_DS (GDT_ENTRY_DEFAULT_USER_DS*8+3)
12247 #define __USER_CS (GDT_ENTRY_DEFAULT_USER_CS*8+3)
12248@@ -265,7 +281,7 @@ static inline unsigned long get_limit(unsigned long segment)
12249 {
12250 unsigned long __limit;
12251 asm("lsll %1,%0" : "=r" (__limit) : "r" (segment));
12252- return __limit + 1;
12253+ return __limit;
12254 }
12255
12256 #endif /* !__ASSEMBLY__ */
12257diff --git a/arch/x86/include/asm/smp.h b/arch/x86/include/asm/smp.h
12258index 4f19a15..9e14f27 100644
12259--- a/arch/x86/include/asm/smp.h
12260+++ b/arch/x86/include/asm/smp.h
12261@@ -36,7 +36,7 @@ DECLARE_PER_CPU_READ_MOSTLY(cpumask_var_t, cpu_core_map);
12262 /* cpus sharing the last level cache: */
12263 DECLARE_PER_CPU_READ_MOSTLY(cpumask_var_t, cpu_llc_shared_map);
12264 DECLARE_PER_CPU_READ_MOSTLY(u16, cpu_llc_id);
12265-DECLARE_PER_CPU_READ_MOSTLY(int, cpu_number);
12266+DECLARE_PER_CPU_READ_MOSTLY(unsigned int, cpu_number);
12267
12268 static inline struct cpumask *cpu_sibling_mask(int cpu)
12269 {
12270@@ -79,7 +79,7 @@ struct smp_ops {
12271
12272 void (*send_call_func_ipi)(const struct cpumask *mask);
12273 void (*send_call_func_single_ipi)(int cpu);
12274-};
12275+} __no_const;
12276
12277 /* Globals due to paravirt */
12278 extern void set_cpu_sibling_map(int cpu);
12279@@ -190,14 +190,8 @@ extern unsigned disabled_cpus __cpuinitdata;
12280 extern int safe_smp_processor_id(void);
12281
12282 #elif defined(CONFIG_X86_64_SMP)
12283-#define raw_smp_processor_id() (this_cpu_read(cpu_number))
12284-
12285-#define stack_smp_processor_id() \
12286-({ \
12287- struct thread_info *ti; \
12288- __asm__("andq %%rsp,%0; ":"=r" (ti) : "0" (CURRENT_MASK)); \
12289- ti->cpu; \
12290-})
12291+#define raw_smp_processor_id() (this_cpu_read(cpu_number))
12292+#define stack_smp_processor_id() raw_smp_processor_id()
12293 #define safe_smp_processor_id() smp_processor_id()
12294
12295 #endif
12296diff --git a/arch/x86/include/asm/spinlock.h b/arch/x86/include/asm/spinlock.h
12297index 33692ea..350a534 100644
12298--- a/arch/x86/include/asm/spinlock.h
12299+++ b/arch/x86/include/asm/spinlock.h
12300@@ -172,6 +172,14 @@ static inline int arch_write_can_lock(arch_rwlock_t *lock)
12301 static inline void arch_read_lock(arch_rwlock_t *rw)
12302 {
12303 asm volatile(LOCK_PREFIX READ_LOCK_SIZE(dec) " (%0)\n\t"
12304+
12305+#ifdef CONFIG_PAX_REFCOUNT
12306+ "jno 0f\n"
12307+ LOCK_PREFIX READ_LOCK_SIZE(inc) " (%0)\n"
12308+ "int $4\n0:\n"
12309+ _ASM_EXTABLE(0b, 0b)
12310+#endif
12311+
12312 "jns 1f\n"
12313 "call __read_lock_failed\n\t"
12314 "1:\n"
12315@@ -181,6 +189,14 @@ static inline void arch_read_lock(arch_rwlock_t *rw)
12316 static inline void arch_write_lock(arch_rwlock_t *rw)
12317 {
12318 asm volatile(LOCK_PREFIX WRITE_LOCK_SUB(%1) "(%0)\n\t"
12319+
12320+#ifdef CONFIG_PAX_REFCOUNT
12321+ "jno 0f\n"
12322+ LOCK_PREFIX WRITE_LOCK_ADD(%1) "(%0)\n"
12323+ "int $4\n0:\n"
12324+ _ASM_EXTABLE(0b, 0b)
12325+#endif
12326+
12327 "jz 1f\n"
12328 "call __write_lock_failed\n\t"
12329 "1:\n"
12330@@ -210,13 +226,29 @@ static inline int arch_write_trylock(arch_rwlock_t *lock)
12331
12332 static inline void arch_read_unlock(arch_rwlock_t *rw)
12333 {
12334- asm volatile(LOCK_PREFIX READ_LOCK_SIZE(inc) " %0"
12335+ asm volatile(LOCK_PREFIX READ_LOCK_SIZE(inc) " %0\n"
12336+
12337+#ifdef CONFIG_PAX_REFCOUNT
12338+ "jno 0f\n"
12339+ LOCK_PREFIX READ_LOCK_SIZE(dec) " %0\n"
12340+ "int $4\n0:\n"
12341+ _ASM_EXTABLE(0b, 0b)
12342+#endif
12343+
12344 :"+m" (rw->lock) : : "memory");
12345 }
12346
12347 static inline void arch_write_unlock(arch_rwlock_t *rw)
12348 {
12349- asm volatile(LOCK_PREFIX WRITE_LOCK_ADD(%1) "%0"
12350+ asm volatile(LOCK_PREFIX WRITE_LOCK_ADD(%1) "%0\n"
12351+
12352+#ifdef CONFIG_PAX_REFCOUNT
12353+ "jno 0f\n"
12354+ LOCK_PREFIX WRITE_LOCK_SUB(%1) "%0\n"
12355+ "int $4\n0:\n"
12356+ _ASM_EXTABLE(0b, 0b)
12357+#endif
12358+
12359 : "+m" (rw->write) : "i" (RW_LOCK_BIAS) : "memory");
12360 }
12361
12362diff --git a/arch/x86/include/asm/stackprotector.h b/arch/x86/include/asm/stackprotector.h
12363index 6a99859..03cb807 100644
12364--- a/arch/x86/include/asm/stackprotector.h
12365+++ b/arch/x86/include/asm/stackprotector.h
12366@@ -47,7 +47,7 @@
12367 * head_32 for boot CPU and setup_per_cpu_areas() for others.
12368 */
12369 #define GDT_STACK_CANARY_INIT \
12370- [GDT_ENTRY_STACK_CANARY] = GDT_ENTRY_INIT(0x4090, 0, 0x18),
12371+ [GDT_ENTRY_STACK_CANARY] = GDT_ENTRY_INIT(0x4090, 0, 0x17),
12372
12373 /*
12374 * Initialize the stackprotector canary value.
12375@@ -112,7 +112,7 @@ static inline void setup_stack_canary_segment(int cpu)
12376
12377 static inline void load_stack_canary_segment(void)
12378 {
12379-#ifdef CONFIG_X86_32
12380+#if defined(CONFIG_X86_32) && !defined(CONFIG_PAX_MEMORY_UDEREF)
12381 asm volatile ("mov %0, %%gs" : : "r" (0));
12382 #endif
12383 }
12384diff --git a/arch/x86/include/asm/stacktrace.h b/arch/x86/include/asm/stacktrace.h
12385index 70bbe39..4ae2bd4 100644
12386--- a/arch/x86/include/asm/stacktrace.h
12387+++ b/arch/x86/include/asm/stacktrace.h
12388@@ -11,28 +11,20 @@
12389
12390 extern int kstack_depth_to_print;
12391
12392-struct thread_info;
12393+struct task_struct;
12394 struct stacktrace_ops;
12395
12396-typedef unsigned long (*walk_stack_t)(struct thread_info *tinfo,
12397- unsigned long *stack,
12398- unsigned long bp,
12399- const struct stacktrace_ops *ops,
12400- void *data,
12401- unsigned long *end,
12402- int *graph);
12403+typedef unsigned long walk_stack_t(struct task_struct *task,
12404+ void *stack_start,
12405+ unsigned long *stack,
12406+ unsigned long bp,
12407+ const struct stacktrace_ops *ops,
12408+ void *data,
12409+ unsigned long *end,
12410+ int *graph);
12411
12412-extern unsigned long
12413-print_context_stack(struct thread_info *tinfo,
12414- unsigned long *stack, unsigned long bp,
12415- const struct stacktrace_ops *ops, void *data,
12416- unsigned long *end, int *graph);
12417-
12418-extern unsigned long
12419-print_context_stack_bp(struct thread_info *tinfo,
12420- unsigned long *stack, unsigned long bp,
12421- const struct stacktrace_ops *ops, void *data,
12422- unsigned long *end, int *graph);
12423+extern walk_stack_t print_context_stack;
12424+extern walk_stack_t print_context_stack_bp;
12425
12426 /* Generic stack tracer with callbacks */
12427
12428@@ -40,7 +32,7 @@ struct stacktrace_ops {
12429 void (*address)(void *data, unsigned long address, int reliable);
12430 /* On negative return stop dumping */
12431 int (*stack)(void *data, char *name);
12432- walk_stack_t walk_stack;
12433+ walk_stack_t *walk_stack;
12434 };
12435
12436 void dump_trace(struct task_struct *tsk, struct pt_regs *regs,
12437diff --git a/arch/x86/include/asm/switch_to.h b/arch/x86/include/asm/switch_to.h
12438index 4ec45b3..a4f0a8a 100644
12439--- a/arch/x86/include/asm/switch_to.h
12440+++ b/arch/x86/include/asm/switch_to.h
12441@@ -108,7 +108,7 @@ do { \
12442 "call __switch_to\n\t" \
12443 "movq "__percpu_arg([current_task])",%%rsi\n\t" \
12444 __switch_canary \
12445- "movq %P[thread_info](%%rsi),%%r8\n\t" \
12446+ "movq "__percpu_arg([thread_info])",%%r8\n\t" \
12447 "movq %%rax,%%rdi\n\t" \
12448 "testl %[_tif_fork],%P[ti_flags](%%r8)\n\t" \
12449 "jnz ret_from_fork\n\t" \
12450@@ -119,7 +119,7 @@ do { \
12451 [threadrsp] "i" (offsetof(struct task_struct, thread.sp)), \
12452 [ti_flags] "i" (offsetof(struct thread_info, flags)), \
12453 [_tif_fork] "i" (_TIF_FORK), \
12454- [thread_info] "i" (offsetof(struct task_struct, stack)), \
12455+ [thread_info] "m" (current_tinfo), \
12456 [current_task] "m" (current_task) \
12457 __switch_canary_iparam \
12458 : "memory", "cc" __EXTRA_CLOBBER)
12459diff --git a/arch/x86/include/asm/sys_ia32.h b/arch/x86/include/asm/sys_ia32.h
12460index 3fda9db4..4ca1c61 100644
12461--- a/arch/x86/include/asm/sys_ia32.h
12462+++ b/arch/x86/include/asm/sys_ia32.h
12463@@ -40,7 +40,7 @@ asmlinkage long sys32_sigaction(int, struct old_sigaction32 __user *,
12464 struct old_sigaction32 __user *);
12465 asmlinkage long sys32_alarm(unsigned int);
12466
12467-asmlinkage long sys32_waitpid(compat_pid_t, unsigned int *, int);
12468+asmlinkage long sys32_waitpid(compat_pid_t, unsigned int __user *, int);
12469 asmlinkage long sys32_sysfs(int, u32, u32);
12470
12471 asmlinkage long sys32_sched_rr_get_interval(compat_pid_t,
12472diff --git a/arch/x86/include/asm/thread_info.h b/arch/x86/include/asm/thread_info.h
12473index 89f794f..1422765 100644
12474--- a/arch/x86/include/asm/thread_info.h
12475+++ b/arch/x86/include/asm/thread_info.h
12476@@ -10,6 +10,7 @@
12477 #include <linux/compiler.h>
12478 #include <asm/page.h>
12479 #include <asm/types.h>
12480+#include <asm/percpu.h>
12481
12482 /*
12483 * low level task data that entry.S needs immediate access to
12484@@ -24,7 +25,6 @@ struct exec_domain;
12485 #include <linux/atomic.h>
12486
12487 struct thread_info {
12488- struct task_struct *task; /* main task structure */
12489 struct exec_domain *exec_domain; /* execution domain */
12490 __u32 flags; /* low level flags */
12491 __u32 status; /* thread synchronous flags */
12492@@ -34,19 +34,13 @@ struct thread_info {
12493 mm_segment_t addr_limit;
12494 struct restart_block restart_block;
12495 void __user *sysenter_return;
12496-#ifdef CONFIG_X86_32
12497- unsigned long previous_esp; /* ESP of the previous stack in
12498- case of nested (IRQ) stacks
12499- */
12500- __u8 supervisor_stack[0];
12501-#endif
12502+ unsigned long lowest_stack;
12503 unsigned int sig_on_uaccess_error:1;
12504 unsigned int uaccess_err:1; /* uaccess failed */
12505 };
12506
12507-#define INIT_THREAD_INFO(tsk) \
12508+#define INIT_THREAD_INFO \
12509 { \
12510- .task = &tsk, \
12511 .exec_domain = &default_exec_domain, \
12512 .flags = 0, \
12513 .cpu = 0, \
12514@@ -57,7 +51,7 @@ struct thread_info {
12515 }, \
12516 }
12517
12518-#define init_thread_info (init_thread_union.thread_info)
12519+#define init_thread_info (init_thread_union.stack)
12520 #define init_stack (init_thread_union.stack)
12521
12522 #else /* !__ASSEMBLY__ */
12523@@ -98,6 +92,7 @@ struct thread_info {
12524 #define TIF_SYSCALL_TRACEPOINT 28 /* syscall tracepoint instrumentation */
12525 #define TIF_ADDR32 29 /* 32-bit address space on 64 bits */
12526 #define TIF_X32 30 /* 32-bit native x86-64 binary */
12527+#define TIF_GRSEC_SETXID 31 /* update credentials on syscall entry/exit */
12528
12529 #define _TIF_SYSCALL_TRACE (1 << TIF_SYSCALL_TRACE)
12530 #define _TIF_NOTIFY_RESUME (1 << TIF_NOTIFY_RESUME)
12531@@ -122,16 +117,18 @@ struct thread_info {
12532 #define _TIF_SYSCALL_TRACEPOINT (1 << TIF_SYSCALL_TRACEPOINT)
12533 #define _TIF_ADDR32 (1 << TIF_ADDR32)
12534 #define _TIF_X32 (1 << TIF_X32)
12535+#define _TIF_GRSEC_SETXID (1 << TIF_GRSEC_SETXID)
12536
12537 /* work to do in syscall_trace_enter() */
12538 #define _TIF_WORK_SYSCALL_ENTRY \
12539 (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_EMU | _TIF_SYSCALL_AUDIT | \
12540- _TIF_SECCOMP | _TIF_SINGLESTEP | _TIF_SYSCALL_TRACEPOINT)
12541+ _TIF_SECCOMP | _TIF_SINGLESTEP | _TIF_SYSCALL_TRACEPOINT | \
12542+ _TIF_GRSEC_SETXID)
12543
12544 /* work to do in syscall_trace_leave() */
12545 #define _TIF_WORK_SYSCALL_EXIT \
12546 (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | _TIF_SINGLESTEP | \
12547- _TIF_SYSCALL_TRACEPOINT)
12548+ _TIF_SYSCALL_TRACEPOINT | _TIF_GRSEC_SETXID)
12549
12550 /* work to do on interrupt/exception return */
12551 #define _TIF_WORK_MASK \
12552@@ -141,7 +138,8 @@ struct thread_info {
12553
12554 /* work to do on any return to user space */
12555 #define _TIF_ALLWORK_MASK \
12556- ((0x0000FFFF & ~_TIF_SECCOMP) | _TIF_SYSCALL_TRACEPOINT)
12557+ ((0x0000FFFF & ~_TIF_SECCOMP) | _TIF_SYSCALL_TRACEPOINT | \
12558+ _TIF_GRSEC_SETXID)
12559
12560 /* Only used for 64 bit */
12561 #define _TIF_DO_NOTIFY_MASK \
12562@@ -157,45 +155,40 @@ struct thread_info {
12563
12564 #define PREEMPT_ACTIVE 0x10000000
12565
12566-#ifdef CONFIG_X86_32
12567-
12568-#define STACK_WARN (THREAD_SIZE/8)
12569-/*
12570- * macros/functions for gaining access to the thread information structure
12571- *
12572- * preempt_count needs to be 1 initially, until the scheduler is functional.
12573- */
12574-#ifndef __ASSEMBLY__
12575-
12576-
12577-/* how to get the current stack pointer from C */
12578-register unsigned long current_stack_pointer asm("esp") __used;
12579-
12580-/* how to get the thread information struct from C */
12581-static inline struct thread_info *current_thread_info(void)
12582-{
12583- return (struct thread_info *)
12584- (current_stack_pointer & ~(THREAD_SIZE - 1));
12585-}
12586-
12587-#else /* !__ASSEMBLY__ */
12588-
12589+#ifdef __ASSEMBLY__
12590 /* how to get the thread information struct from ASM */
12591 #define GET_THREAD_INFO(reg) \
12592- movl $-THREAD_SIZE, reg; \
12593- andl %esp, reg
12594+ mov PER_CPU_VAR(current_tinfo), reg
12595
12596 /* use this one if reg already contains %esp */
12597-#define GET_THREAD_INFO_WITH_ESP(reg) \
12598- andl $-THREAD_SIZE, reg
12599+#define GET_THREAD_INFO_WITH_ESP(reg) GET_THREAD_INFO(reg)
12600+#else
12601+/* how to get the thread information struct from C */
12602+DECLARE_PER_CPU(struct thread_info *, current_tinfo);
12603+
12604+static __always_inline struct thread_info *current_thread_info(void)
12605+{
12606+ return this_cpu_read_stable(current_tinfo);
12607+}
12608+#endif
12609+
12610+#ifdef CONFIG_X86_32
12611+
12612+#define STACK_WARN (THREAD_SIZE/8)
12613+/*
12614+ * macros/functions for gaining access to the thread information structure
12615+ *
12616+ * preempt_count needs to be 1 initially, until the scheduler is functional.
12617+ */
12618+#ifndef __ASSEMBLY__
12619+
12620+/* how to get the current stack pointer from C */
12621+register unsigned long current_stack_pointer asm("esp") __used;
12622
12623 #endif
12624
12625 #else /* X86_32 */
12626
12627-#include <asm/percpu.h>
12628-#define KERNEL_STACK_OFFSET (5*8)
12629-
12630 /*
12631 * macros/functions for gaining access to the thread information structure
12632 * preempt_count needs to be 1 initially, until the scheduler is functional.
12633@@ -203,27 +196,8 @@ static inline struct thread_info *current_thread_info(void)
12634 #ifndef __ASSEMBLY__
12635 DECLARE_PER_CPU(unsigned long, kernel_stack);
12636
12637-static inline struct thread_info *current_thread_info(void)
12638-{
12639- struct thread_info *ti;
12640- ti = (void *)(this_cpu_read_stable(kernel_stack) +
12641- KERNEL_STACK_OFFSET - THREAD_SIZE);
12642- return ti;
12643-}
12644-
12645-#else /* !__ASSEMBLY__ */
12646-
12647-/* how to get the thread information struct from ASM */
12648-#define GET_THREAD_INFO(reg) \
12649- movq PER_CPU_VAR(kernel_stack),reg ; \
12650- subq $(THREAD_SIZE-KERNEL_STACK_OFFSET),reg
12651-
12652-/*
12653- * Same if PER_CPU_VAR(kernel_stack) is, perhaps with some offset, already in
12654- * a certain register (to be used in assembler memory operands).
12655- */
12656-#define THREAD_INFO(reg, off) KERNEL_STACK_OFFSET+(off)-THREAD_SIZE(reg)
12657-
12658+/* how to get the current stack pointer from C */
12659+register unsigned long current_stack_pointer asm("rsp") __used;
12660 #endif
12661
12662 #endif /* !X86_32 */
12663@@ -284,5 +258,12 @@ static inline bool is_ia32_task(void)
12664 extern void arch_task_cache_init(void);
12665 extern int arch_dup_task_struct(struct task_struct *dst, struct task_struct *src);
12666 extern void arch_release_task_struct(struct task_struct *tsk);
12667+
12668+#define __HAVE_THREAD_FUNCTIONS
12669+#define task_thread_info(task) (&(task)->tinfo)
12670+#define task_stack_page(task) ((task)->stack)
12671+#define setup_thread_stack(p, org) do {} while (0)
12672+#define end_of_stack(p) ((unsigned long *)task_stack_page(p) + 1)
12673+
12674 #endif
12675 #endif /* _ASM_X86_THREAD_INFO_H */
12676diff --git a/arch/x86/include/asm/uaccess.h b/arch/x86/include/asm/uaccess.h
12677index e1f3a17..1ab364d 100644
12678--- a/arch/x86/include/asm/uaccess.h
12679+++ b/arch/x86/include/asm/uaccess.h
12680@@ -7,12 +7,15 @@
12681 #include <linux/compiler.h>
12682 #include <linux/thread_info.h>
12683 #include <linux/string.h>
12684+#include <linux/sched.h>
12685 #include <asm/asm.h>
12686 #include <asm/page.h>
12687
12688 #define VERIFY_READ 0
12689 #define VERIFY_WRITE 1
12690
12691+extern void check_object_size(const void *ptr, unsigned long n, bool to);
12692+
12693 /*
12694 * The fs value determines whether argument validity checking should be
12695 * performed or not. If get_fs() == USER_DS, checking is performed, with
12696@@ -28,7 +31,12 @@
12697
12698 #define get_ds() (KERNEL_DS)
12699 #define get_fs() (current_thread_info()->addr_limit)
12700+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
12701+void __set_fs(mm_segment_t x);
12702+void set_fs(mm_segment_t x);
12703+#else
12704 #define set_fs(x) (current_thread_info()->addr_limit = (x))
12705+#endif
12706
12707 #define segment_eq(a, b) ((a).seg == (b).seg)
12708
12709@@ -76,8 +84,33 @@
12710 * checks that the pointer is in the user space range - after calling
12711 * this function, memory access functions may still return -EFAULT.
12712 */
12713-#define access_ok(type, addr, size) \
12714- (likely(__range_not_ok(addr, size, user_addr_max()) == 0))
12715+#define __access_ok(type, addr, size) (likely(__range_not_ok(addr, size, user_addr_max()) == 0))
12716+#define access_ok(type, addr, size) \
12717+({ \
12718+ long __size = size; \
12719+ unsigned long __addr = (unsigned long)addr; \
12720+ unsigned long __addr_ao = __addr & PAGE_MASK; \
12721+ unsigned long __end_ao = __addr + __size - 1; \
12722+ bool __ret_ao = __range_not_ok(__addr, __size, user_addr_max()) == 0;\
12723+ if (__ret_ao && unlikely((__end_ao ^ __addr_ao) & PAGE_MASK)) { \
12724+ while(__addr_ao <= __end_ao) { \
12725+ char __c_ao; \
12726+ __addr_ao += PAGE_SIZE; \
12727+ if (__size > PAGE_SIZE) \
12728+ cond_resched(); \
12729+ if (__get_user(__c_ao, (char __user *)__addr)) \
12730+ break; \
12731+ if (type != VERIFY_WRITE) { \
12732+ __addr = __addr_ao; \
12733+ continue; \
12734+ } \
12735+ if (__put_user(__c_ao, (char __user *)__addr)) \
12736+ break; \
12737+ __addr = __addr_ao; \
12738+ } \
12739+ } \
12740+ __ret_ao; \
12741+})
12742
12743 /*
12744 * The exception table consists of pairs of addresses relative to the
12745@@ -188,12 +221,20 @@ extern int __get_user_bad(void);
12746 asm volatile("call __put_user_" #size : "=a" (__ret_pu) \
12747 : "0" ((typeof(*(ptr)))(x)), "c" (ptr) : "ebx")
12748
12749-
12750+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
12751+#define __copyuser_seg "gs;"
12752+#define __COPYUSER_SET_ES "pushl %%gs; popl %%es\n"
12753+#define __COPYUSER_RESTORE_ES "pushl %%ss; popl %%es\n"
12754+#else
12755+#define __copyuser_seg
12756+#define __COPYUSER_SET_ES
12757+#define __COPYUSER_RESTORE_ES
12758+#endif
12759
12760 #ifdef CONFIG_X86_32
12761 #define __put_user_asm_u64(x, addr, err, errret) \
12762- asm volatile("1: movl %%eax,0(%2)\n" \
12763- "2: movl %%edx,4(%2)\n" \
12764+ asm volatile("1: "__copyuser_seg"movl %%eax,0(%2)\n" \
12765+ "2: "__copyuser_seg"movl %%edx,4(%2)\n" \
12766 "3:\n" \
12767 ".section .fixup,\"ax\"\n" \
12768 "4: movl %3,%0\n" \
12769@@ -205,8 +246,8 @@ extern int __get_user_bad(void);
12770 : "A" (x), "r" (addr), "i" (errret), "0" (err))
12771
12772 #define __put_user_asm_ex_u64(x, addr) \
12773- asm volatile("1: movl %%eax,0(%1)\n" \
12774- "2: movl %%edx,4(%1)\n" \
12775+ asm volatile("1: "__copyuser_seg"movl %%eax,0(%1)\n" \
12776+ "2: "__copyuser_seg"movl %%edx,4(%1)\n" \
12777 "3:\n" \
12778 _ASM_EXTABLE_EX(1b, 2b) \
12779 _ASM_EXTABLE_EX(2b, 3b) \
12780@@ -258,7 +299,7 @@ extern void __put_user_8(void);
12781 __typeof__(*(ptr)) __pu_val; \
12782 __chk_user_ptr(ptr); \
12783 might_fault(); \
12784- __pu_val = x; \
12785+ __pu_val = (x); \
12786 switch (sizeof(*(ptr))) { \
12787 case 1: \
12788 __put_user_x(1, __pu_val, ptr, __ret_pu); \
12789@@ -379,7 +420,7 @@ do { \
12790 } while (0)
12791
12792 #define __get_user_asm(x, addr, err, itype, rtype, ltype, errret) \
12793- asm volatile("1: mov"itype" %2,%"rtype"1\n" \
12794+ asm volatile("1: "__copyuser_seg"mov"itype" %2,%"rtype"1\n"\
12795 "2:\n" \
12796 ".section .fixup,\"ax\"\n" \
12797 "3: mov %3,%0\n" \
12798@@ -387,7 +428,7 @@ do { \
12799 " jmp 2b\n" \
12800 ".previous\n" \
12801 _ASM_EXTABLE(1b, 3b) \
12802- : "=r" (err), ltype(x) \
12803+ : "=r" (err), ltype (x) \
12804 : "m" (__m(addr)), "i" (errret), "0" (err))
12805
12806 #define __get_user_size_ex(x, ptr, size) \
12807@@ -412,7 +453,7 @@ do { \
12808 } while (0)
12809
12810 #define __get_user_asm_ex(x, addr, itype, rtype, ltype) \
12811- asm volatile("1: mov"itype" %1,%"rtype"0\n" \
12812+ asm volatile("1: "__copyuser_seg"mov"itype" %1,%"rtype"0\n"\
12813 "2:\n" \
12814 _ASM_EXTABLE_EX(1b, 2b) \
12815 : ltype(x) : "m" (__m(addr)))
12816@@ -429,13 +470,24 @@ do { \
12817 int __gu_err; \
12818 unsigned long __gu_val; \
12819 __get_user_size(__gu_val, (ptr), (size), __gu_err, -EFAULT); \
12820- (x) = (__force __typeof__(*(ptr)))__gu_val; \
12821+ (x) = (__typeof__(*(ptr)))__gu_val; \
12822 __gu_err; \
12823 })
12824
12825 /* FIXME: this hack is definitely wrong -AK */
12826 struct __large_struct { unsigned long buf[100]; };
12827-#define __m(x) (*(struct __large_struct __user *)(x))
12828+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
12829+#define ____m(x) \
12830+({ \
12831+ unsigned long ____x = (unsigned long)(x); \
12832+ if (____x < PAX_USER_SHADOW_BASE) \
12833+ ____x += PAX_USER_SHADOW_BASE; \
12834+ (void __user *)____x; \
12835+})
12836+#else
12837+#define ____m(x) (x)
12838+#endif
12839+#define __m(x) (*(struct __large_struct __user *)____m(x))
12840
12841 /*
12842 * Tell gcc we read from memory instead of writing: this is because
12843@@ -443,7 +495,7 @@ struct __large_struct { unsigned long buf[100]; };
12844 * aliasing issues.
12845 */
12846 #define __put_user_asm(x, addr, err, itype, rtype, ltype, errret) \
12847- asm volatile("1: mov"itype" %"rtype"1,%2\n" \
12848+ asm volatile("1: "__copyuser_seg"mov"itype" %"rtype"1,%2\n"\
12849 "2:\n" \
12850 ".section .fixup,\"ax\"\n" \
12851 "3: mov %3,%0\n" \
12852@@ -451,10 +503,10 @@ struct __large_struct { unsigned long buf[100]; };
12853 ".previous\n" \
12854 _ASM_EXTABLE(1b, 3b) \
12855 : "=r"(err) \
12856- : ltype(x), "m" (__m(addr)), "i" (errret), "0" (err))
12857+ : ltype (x), "m" (__m(addr)), "i" (errret), "0" (err))
12858
12859 #define __put_user_asm_ex(x, addr, itype, rtype, ltype) \
12860- asm volatile("1: mov"itype" %"rtype"0,%1\n" \
12861+ asm volatile("1: "__copyuser_seg"mov"itype" %"rtype"0,%1\n"\
12862 "2:\n" \
12863 _ASM_EXTABLE_EX(1b, 2b) \
12864 : : ltype(x), "m" (__m(addr)))
12865@@ -493,8 +545,12 @@ struct __large_struct { unsigned long buf[100]; };
12866 * On error, the variable @x is set to zero.
12867 */
12868
12869+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
12870+#define __get_user(x, ptr) get_user((x), (ptr))
12871+#else
12872 #define __get_user(x, ptr) \
12873 __get_user_nocheck((x), (ptr), sizeof(*(ptr)))
12874+#endif
12875
12876 /**
12877 * __put_user: - Write a simple value into user space, with less checking.
12878@@ -516,8 +572,12 @@ struct __large_struct { unsigned long buf[100]; };
12879 * Returns zero on success, or -EFAULT on error.
12880 */
12881
12882+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
12883+#define __put_user(x, ptr) put_user((x), (ptr))
12884+#else
12885 #define __put_user(x, ptr) \
12886 __put_user_nocheck((__typeof__(*(ptr)))(x), (ptr), sizeof(*(ptr)))
12887+#endif
12888
12889 #define __get_user_unaligned __get_user
12890 #define __put_user_unaligned __put_user
12891@@ -535,7 +595,7 @@ struct __large_struct { unsigned long buf[100]; };
12892 #define get_user_ex(x, ptr) do { \
12893 unsigned long __gue_val; \
12894 __get_user_size_ex((__gue_val), (ptr), (sizeof(*(ptr)))); \
12895- (x) = (__force __typeof__(*(ptr)))__gue_val; \
12896+ (x) = (__typeof__(*(ptr)))__gue_val; \
12897 } while (0)
12898
12899 #ifdef CONFIG_X86_WP_WORKS_OK
12900diff --git a/arch/x86/include/asm/uaccess_32.h b/arch/x86/include/asm/uaccess_32.h
12901index 576e39b..ccd0a39 100644
12902--- a/arch/x86/include/asm/uaccess_32.h
12903+++ b/arch/x86/include/asm/uaccess_32.h
12904@@ -11,15 +11,15 @@
12905 #include <asm/page.h>
12906
12907 unsigned long __must_check __copy_to_user_ll
12908- (void __user *to, const void *from, unsigned long n);
12909+ (void __user *to, const void *from, unsigned long n) __size_overflow(3);
12910 unsigned long __must_check __copy_from_user_ll
12911- (void *to, const void __user *from, unsigned long n);
12912+ (void *to, const void __user *from, unsigned long n) __size_overflow(3);
12913 unsigned long __must_check __copy_from_user_ll_nozero
12914- (void *to, const void __user *from, unsigned long n);
12915+ (void *to, const void __user *from, unsigned long n) __size_overflow(3);
12916 unsigned long __must_check __copy_from_user_ll_nocache
12917- (void *to, const void __user *from, unsigned long n);
12918+ (void *to, const void __user *from, unsigned long n) __size_overflow(3);
12919 unsigned long __must_check __copy_from_user_ll_nocache_nozero
12920- (void *to, const void __user *from, unsigned long n);
12921+ (void *to, const void __user *from, unsigned long n) __size_overflow(3);
12922
12923 /**
12924 * __copy_to_user_inatomic: - Copy a block of data into user space, with less checking.
12925@@ -43,6 +43,9 @@ unsigned long __must_check __copy_from_user_ll_nocache_nozero
12926 static __always_inline unsigned long __must_check
12927 __copy_to_user_inatomic(void __user *to, const void *from, unsigned long n)
12928 {
12929+ if ((long)n < 0)
12930+ return n;
12931+
12932 if (__builtin_constant_p(n)) {
12933 unsigned long ret;
12934
12935@@ -61,6 +64,8 @@ __copy_to_user_inatomic(void __user *to, const void *from, unsigned long n)
12936 return ret;
12937 }
12938 }
12939+ if (!__builtin_constant_p(n))
12940+ check_object_size(from, n, true);
12941 return __copy_to_user_ll(to, from, n);
12942 }
12943
12944@@ -82,12 +87,16 @@ static __always_inline unsigned long __must_check
12945 __copy_to_user(void __user *to, const void *from, unsigned long n)
12946 {
12947 might_fault();
12948+
12949 return __copy_to_user_inatomic(to, from, n);
12950 }
12951
12952 static __always_inline unsigned long
12953 __copy_from_user_inatomic(void *to, const void __user *from, unsigned long n)
12954 {
12955+ if ((long)n < 0)
12956+ return n;
12957+
12958 /* Avoid zeroing the tail if the copy fails..
12959 * If 'n' is constant and 1, 2, or 4, we do still zero on a failure,
12960 * but as the zeroing behaviour is only significant when n is not
12961@@ -137,6 +146,10 @@ static __always_inline unsigned long
12962 __copy_from_user(void *to, const void __user *from, unsigned long n)
12963 {
12964 might_fault();
12965+
12966+ if ((long)n < 0)
12967+ return n;
12968+
12969 if (__builtin_constant_p(n)) {
12970 unsigned long ret;
12971
12972@@ -152,6 +165,8 @@ __copy_from_user(void *to, const void __user *from, unsigned long n)
12973 return ret;
12974 }
12975 }
12976+ if (!__builtin_constant_p(n))
12977+ check_object_size(to, n, false);
12978 return __copy_from_user_ll(to, from, n);
12979 }
12980
12981@@ -159,6 +174,10 @@ static __always_inline unsigned long __copy_from_user_nocache(void *to,
12982 const void __user *from, unsigned long n)
12983 {
12984 might_fault();
12985+
12986+ if ((long)n < 0)
12987+ return n;
12988+
12989 if (__builtin_constant_p(n)) {
12990 unsigned long ret;
12991
12992@@ -181,15 +200,19 @@ static __always_inline unsigned long
12993 __copy_from_user_inatomic_nocache(void *to, const void __user *from,
12994 unsigned long n)
12995 {
12996- return __copy_from_user_ll_nocache_nozero(to, from, n);
12997+ if ((long)n < 0)
12998+ return n;
12999+
13000+ return __copy_from_user_ll_nocache_nozero(to, from, n);
13001 }
13002
13003-unsigned long __must_check copy_to_user(void __user *to,
13004- const void *from, unsigned long n);
13005-unsigned long __must_check _copy_from_user(void *to,
13006- const void __user *from,
13007- unsigned long n);
13008-
13009+extern void copy_to_user_overflow(void)
13010+#ifdef CONFIG_DEBUG_STRICT_USER_COPY_CHECKS
13011+ __compiletime_error("copy_to_user() buffer size is not provably correct")
13012+#else
13013+ __compiletime_warning("copy_to_user() buffer size is not provably correct")
13014+#endif
13015+;
13016
13017 extern void copy_from_user_overflow(void)
13018 #ifdef CONFIG_DEBUG_STRICT_USER_COPY_CHECKS
13019@@ -199,21 +222,65 @@ extern void copy_from_user_overflow(void)
13020 #endif
13021 ;
13022
13023-static inline unsigned long __must_check copy_from_user(void *to,
13024- const void __user *from,
13025- unsigned long n)
13026+/**
13027+ * copy_to_user: - Copy a block of data into user space.
13028+ * @to: Destination address, in user space.
13029+ * @from: Source address, in kernel space.
13030+ * @n: Number of bytes to copy.
13031+ *
13032+ * Context: User context only. This function may sleep.
13033+ *
13034+ * Copy data from kernel space to user space.
13035+ *
13036+ * Returns number of bytes that could not be copied.
13037+ * On success, this will be zero.
13038+ */
13039+static inline unsigned long __must_check
13040+copy_to_user(void __user *to, const void *from, unsigned long n)
13041 {
13042- int sz = __compiletime_object_size(to);
13043+ size_t sz = __compiletime_object_size(from);
13044
13045- if (likely(sz == -1 || sz >= n))
13046- n = _copy_from_user(to, from, n);
13047- else
13048+ if (unlikely(sz != (size_t)-1 && sz < n))
13049+ copy_to_user_overflow();
13050+ else if (access_ok(VERIFY_WRITE, to, n))
13051+ n = __copy_to_user(to, from, n);
13052+ return n;
13053+}
13054+
13055+/**
13056+ * copy_from_user: - Copy a block of data from user space.
13057+ * @to: Destination address, in kernel space.
13058+ * @from: Source address, in user space.
13059+ * @n: Number of bytes to copy.
13060+ *
13061+ * Context: User context only. This function may sleep.
13062+ *
13063+ * Copy data from user space to kernel space.
13064+ *
13065+ * Returns number of bytes that could not be copied.
13066+ * On success, this will be zero.
13067+ *
13068+ * If some data could not be copied, this function will pad the copied
13069+ * data to the requested size using zero bytes.
13070+ */
13071+static inline unsigned long __must_check
13072+copy_from_user(void *to, const void __user *from, unsigned long n)
13073+{
13074+ size_t sz = __compiletime_object_size(to);
13075+
13076+ if (unlikely(sz != (size_t)-1 && sz < n))
13077 copy_from_user_overflow();
13078-
13079+ else if (access_ok(VERIFY_READ, from, n))
13080+ n = __copy_from_user(to, from, n);
13081+ else if ((long)n > 0) {
13082+ if (!__builtin_constant_p(n))
13083+ check_object_size(to, n, false);
13084+ memset(to, 0, n);
13085+ }
13086 return n;
13087 }
13088
13089-unsigned long __must_check clear_user(void __user *mem, unsigned long len);
13090-unsigned long __must_check __clear_user(void __user *mem, unsigned long len);
13091+unsigned long __must_check clear_user(void __user *mem, unsigned long len) __size_overflow(2);
13092+unsigned long __must_check __clear_user(void __user *mem, unsigned long len) __size_overflow(2);
13093
13094 #endif /* _ASM_X86_UACCESS_32_H */
13095diff --git a/arch/x86/include/asm/uaccess_64.h b/arch/x86/include/asm/uaccess_64.h
13096index d8def8b..ac7fc15 100644
13097--- a/arch/x86/include/asm/uaccess_64.h
13098+++ b/arch/x86/include/asm/uaccess_64.h
13099@@ -10,6 +10,9 @@
13100 #include <asm/alternative.h>
13101 #include <asm/cpufeature.h>
13102 #include <asm/page.h>
13103+#include <asm/pgtable.h>
13104+
13105+#define set_fs(x) (current_thread_info()->addr_limit = (x))
13106
13107 /*
13108 * Copy To/From Userspace
13109@@ -17,13 +20,13 @@
13110
13111 /* Handles exceptions in both to and from, but doesn't do access_ok */
13112 __must_check unsigned long
13113-copy_user_enhanced_fast_string(void *to, const void *from, unsigned len);
13114+copy_user_enhanced_fast_string(void *to, const void *from, unsigned len) __size_overflow(3);
13115 __must_check unsigned long
13116-copy_user_generic_string(void *to, const void *from, unsigned len);
13117+copy_user_generic_string(void *to, const void *from, unsigned len) __size_overflow(3);
13118 __must_check unsigned long
13119-copy_user_generic_unrolled(void *to, const void *from, unsigned len);
13120+copy_user_generic_unrolled(void *to, const void *from, unsigned len) __size_overflow(3);
13121
13122-static __always_inline __must_check unsigned long
13123+static __always_inline __must_check __size_overflow(3) unsigned long
13124 copy_user_generic(void *to, const void *from, unsigned len)
13125 {
13126 unsigned ret;
13127@@ -41,142 +44,238 @@ copy_user_generic(void *to, const void *from, unsigned len)
13128 ASM_OUTPUT2("=a" (ret), "=D" (to), "=S" (from),
13129 "=d" (len)),
13130 "1" (to), "2" (from), "3" (len)
13131- : "memory", "rcx", "r8", "r9", "r10", "r11");
13132+ : "memory", "rcx", "r8", "r9", "r11");
13133 return ret;
13134 }
13135
13136+static __always_inline __must_check unsigned long
13137+__copy_to_user(void __user *to, const void *from, unsigned long len) __size_overflow(3);
13138+static __always_inline __must_check unsigned long
13139+__copy_from_user(void *to, const void __user *from, unsigned long len) __size_overflow(3);
13140 __must_check unsigned long
13141-_copy_to_user(void __user *to, const void *from, unsigned len);
13142-__must_check unsigned long
13143-_copy_from_user(void *to, const void __user *from, unsigned len);
13144-__must_check unsigned long
13145-copy_in_user(void __user *to, const void __user *from, unsigned len);
13146+copy_in_user(void __user *to, const void __user *from, unsigned long len) __size_overflow(3);
13147+
13148+extern void copy_to_user_overflow(void)
13149+#ifdef CONFIG_DEBUG_STRICT_USER_COPY_CHECKS
13150+ __compiletime_error("copy_to_user() buffer size is not provably correct")
13151+#else
13152+ __compiletime_warning("copy_to_user() buffer size is not provably correct")
13153+#endif
13154+;
13155+
13156+extern void copy_from_user_overflow(void)
13157+#ifdef CONFIG_DEBUG_STRICT_USER_COPY_CHECKS
13158+ __compiletime_error("copy_from_user() buffer size is not provably correct")
13159+#else
13160+ __compiletime_warning("copy_from_user() buffer size is not provably correct")
13161+#endif
13162+;
13163
13164 static inline unsigned long __must_check copy_from_user(void *to,
13165 const void __user *from,
13166 unsigned long n)
13167 {
13168- int sz = __compiletime_object_size(to);
13169-
13170 might_fault();
13171- if (likely(sz == -1 || sz >= n))
13172- n = _copy_from_user(to, from, n);
13173-#ifdef CONFIG_DEBUG_VM
13174- else
13175- WARN(1, "Buffer overflow detected!\n");
13176-#endif
13177+
13178+ if (access_ok(VERIFY_READ, from, n))
13179+ n = __copy_from_user(to, from, n);
13180+ else if (n < INT_MAX) {
13181+ if (!__builtin_constant_p(n))
13182+ check_object_size(to, n, false);
13183+ memset(to, 0, n);
13184+ }
13185 return n;
13186 }
13187
13188 static __always_inline __must_check
13189-int copy_to_user(void __user *dst, const void *src, unsigned size)
13190+int copy_to_user(void __user *dst, const void *src, unsigned long size)
13191 {
13192 might_fault();
13193
13194- return _copy_to_user(dst, src, size);
13195+ if (access_ok(VERIFY_WRITE, dst, size))
13196+ size = __copy_to_user(dst, src, size);
13197+ return size;
13198 }
13199
13200 static __always_inline __must_check
13201-int __copy_from_user(void *dst, const void __user *src, unsigned size)
13202+unsigned long __copy_from_user(void *dst, const void __user *src, unsigned long size)
13203 {
13204- int ret = 0;
13205+ size_t sz = __compiletime_object_size(dst);
13206+ unsigned ret = 0;
13207
13208 might_fault();
13209- if (!__builtin_constant_p(size))
13210- return copy_user_generic(dst, (__force void *)src, size);
13211+
13212+ if (size > INT_MAX)
13213+ return size;
13214+
13215+#ifdef CONFIG_PAX_MEMORY_UDEREF
13216+ if (!__access_ok(VERIFY_READ, src, size))
13217+ return size;
13218+#endif
13219+
13220+ if (unlikely(sz != (size_t)-1 && sz < size)) {
13221+ copy_from_user_overflow();
13222+ return size;
13223+ }
13224+
13225+ if (!__builtin_constant_p(size)) {
13226+ check_object_size(dst, size, false);
13227+
13228+#ifdef CONFIG_PAX_MEMORY_UDEREF
13229+ if ((unsigned long)src < PAX_USER_SHADOW_BASE)
13230+ src += PAX_USER_SHADOW_BASE;
13231+#endif
13232+
13233+ return copy_user_generic(dst, (__force_kernel const void *)src, size);
13234+ }
13235 switch (size) {
13236- case 1:__get_user_asm(*(u8 *)dst, (u8 __user *)src,
13237+ case 1:__get_user_asm(*(u8 *)dst, (const u8 __user *)src,
13238 ret, "b", "b", "=q", 1);
13239 return ret;
13240- case 2:__get_user_asm(*(u16 *)dst, (u16 __user *)src,
13241+ case 2:__get_user_asm(*(u16 *)dst, (const u16 __user *)src,
13242 ret, "w", "w", "=r", 2);
13243 return ret;
13244- case 4:__get_user_asm(*(u32 *)dst, (u32 __user *)src,
13245+ case 4:__get_user_asm(*(u32 *)dst, (const u32 __user *)src,
13246 ret, "l", "k", "=r", 4);
13247 return ret;
13248- case 8:__get_user_asm(*(u64 *)dst, (u64 __user *)src,
13249+ case 8:__get_user_asm(*(u64 *)dst, (const u64 __user *)src,
13250 ret, "q", "", "=r", 8);
13251 return ret;
13252 case 10:
13253- __get_user_asm(*(u64 *)dst, (u64 __user *)src,
13254+ __get_user_asm(*(u64 *)dst, (const u64 __user *)src,
13255 ret, "q", "", "=r", 10);
13256 if (unlikely(ret))
13257 return ret;
13258 __get_user_asm(*(u16 *)(8 + (char *)dst),
13259- (u16 __user *)(8 + (char __user *)src),
13260+ (const u16 __user *)(8 + (const char __user *)src),
13261 ret, "w", "w", "=r", 2);
13262 return ret;
13263 case 16:
13264- __get_user_asm(*(u64 *)dst, (u64 __user *)src,
13265+ __get_user_asm(*(u64 *)dst, (const u64 __user *)src,
13266 ret, "q", "", "=r", 16);
13267 if (unlikely(ret))
13268 return ret;
13269 __get_user_asm(*(u64 *)(8 + (char *)dst),
13270- (u64 __user *)(8 + (char __user *)src),
13271+ (const u64 __user *)(8 + (const char __user *)src),
13272 ret, "q", "", "=r", 8);
13273 return ret;
13274 default:
13275- return copy_user_generic(dst, (__force void *)src, size);
13276+
13277+#ifdef CONFIG_PAX_MEMORY_UDEREF
13278+ if ((unsigned long)src < PAX_USER_SHADOW_BASE)
13279+ src += PAX_USER_SHADOW_BASE;
13280+#endif
13281+
13282+ return copy_user_generic(dst, (__force_kernel const void *)src, size);
13283 }
13284 }
13285
13286 static __always_inline __must_check
13287-int __copy_to_user(void __user *dst, const void *src, unsigned size)
13288+unsigned long __copy_to_user(void __user *dst, const void *src, unsigned long size)
13289 {
13290- int ret = 0;
13291+ size_t sz = __compiletime_object_size(src);
13292+ unsigned ret = 0;
13293
13294 might_fault();
13295- if (!__builtin_constant_p(size))
13296- return copy_user_generic((__force void *)dst, src, size);
13297+
13298+ if (size > INT_MAX)
13299+ return size;
13300+
13301+#ifdef CONFIG_PAX_MEMORY_UDEREF
13302+ if (!__access_ok(VERIFY_WRITE, dst, size))
13303+ return size;
13304+#endif
13305+
13306+ if (unlikely(sz != (size_t)-1 && sz < size)) {
13307+ copy_to_user_overflow();
13308+ return size;
13309+ }
13310+
13311+ if (!__builtin_constant_p(size)) {
13312+ check_object_size(src, size, true);
13313+
13314+#ifdef CONFIG_PAX_MEMORY_UDEREF
13315+ if ((unsigned long)dst < PAX_USER_SHADOW_BASE)
13316+ dst += PAX_USER_SHADOW_BASE;
13317+#endif
13318+
13319+ return copy_user_generic((__force_kernel void *)dst, src, size);
13320+ }
13321 switch (size) {
13322- case 1:__put_user_asm(*(u8 *)src, (u8 __user *)dst,
13323+ case 1:__put_user_asm(*(const u8 *)src, (u8 __user *)dst,
13324 ret, "b", "b", "iq", 1);
13325 return ret;
13326- case 2:__put_user_asm(*(u16 *)src, (u16 __user *)dst,
13327+ case 2:__put_user_asm(*(const u16 *)src, (u16 __user *)dst,
13328 ret, "w", "w", "ir", 2);
13329 return ret;
13330- case 4:__put_user_asm(*(u32 *)src, (u32 __user *)dst,
13331+ case 4:__put_user_asm(*(const u32 *)src, (u32 __user *)dst,
13332 ret, "l", "k", "ir", 4);
13333 return ret;
13334- case 8:__put_user_asm(*(u64 *)src, (u64 __user *)dst,
13335+ case 8:__put_user_asm(*(const u64 *)src, (u64 __user *)dst,
13336 ret, "q", "", "er", 8);
13337 return ret;
13338 case 10:
13339- __put_user_asm(*(u64 *)src, (u64 __user *)dst,
13340+ __put_user_asm(*(const u64 *)src, (u64 __user *)dst,
13341 ret, "q", "", "er", 10);
13342 if (unlikely(ret))
13343 return ret;
13344 asm("":::"memory");
13345- __put_user_asm(4[(u16 *)src], 4 + (u16 __user *)dst,
13346+ __put_user_asm(4[(const u16 *)src], 4 + (u16 __user *)dst,
13347 ret, "w", "w", "ir", 2);
13348 return ret;
13349 case 16:
13350- __put_user_asm(*(u64 *)src, (u64 __user *)dst,
13351+ __put_user_asm(*(const u64 *)src, (u64 __user *)dst,
13352 ret, "q", "", "er", 16);
13353 if (unlikely(ret))
13354 return ret;
13355 asm("":::"memory");
13356- __put_user_asm(1[(u64 *)src], 1 + (u64 __user *)dst,
13357+ __put_user_asm(1[(const u64 *)src], 1 + (u64 __user *)dst,
13358 ret, "q", "", "er", 8);
13359 return ret;
13360 default:
13361- return copy_user_generic((__force void *)dst, src, size);
13362+
13363+#ifdef CONFIG_PAX_MEMORY_UDEREF
13364+ if ((unsigned long)dst < PAX_USER_SHADOW_BASE)
13365+ dst += PAX_USER_SHADOW_BASE;
13366+#endif
13367+
13368+ return copy_user_generic((__force_kernel void *)dst, src, size);
13369 }
13370 }
13371
13372 static __always_inline __must_check
13373-int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
13374+unsigned long __copy_in_user(void __user *dst, const void __user *src, unsigned long size)
13375 {
13376- int ret = 0;
13377+ unsigned ret = 0;
13378
13379 might_fault();
13380- if (!__builtin_constant_p(size))
13381- return copy_user_generic((__force void *)dst,
13382- (__force void *)src, size);
13383+
13384+ if (size > INT_MAX)
13385+ return size;
13386+
13387+#ifdef CONFIG_PAX_MEMORY_UDEREF
13388+ if (!__access_ok(VERIFY_READ, src, size))
13389+ return size;
13390+ if (!__access_ok(VERIFY_WRITE, dst, size))
13391+ return size;
13392+#endif
13393+
13394+ if (!__builtin_constant_p(size)) {
13395+
13396+#ifdef CONFIG_PAX_MEMORY_UDEREF
13397+ if ((unsigned long)src < PAX_USER_SHADOW_BASE)
13398+ src += PAX_USER_SHADOW_BASE;
13399+ if ((unsigned long)dst < PAX_USER_SHADOW_BASE)
13400+ dst += PAX_USER_SHADOW_BASE;
13401+#endif
13402+
13403+ return copy_user_generic((__force_kernel void *)dst,
13404+ (__force_kernel const void *)src, size);
13405+ }
13406 switch (size) {
13407 case 1: {
13408 u8 tmp;
13409- __get_user_asm(tmp, (u8 __user *)src,
13410+ __get_user_asm(tmp, (const u8 __user *)src,
13411 ret, "b", "b", "=q", 1);
13412 if (likely(!ret))
13413 __put_user_asm(tmp, (u8 __user *)dst,
13414@@ -185,7 +284,7 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
13415 }
13416 case 2: {
13417 u16 tmp;
13418- __get_user_asm(tmp, (u16 __user *)src,
13419+ __get_user_asm(tmp, (const u16 __user *)src,
13420 ret, "w", "w", "=r", 2);
13421 if (likely(!ret))
13422 __put_user_asm(tmp, (u16 __user *)dst,
13423@@ -195,7 +294,7 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
13424
13425 case 4: {
13426 u32 tmp;
13427- __get_user_asm(tmp, (u32 __user *)src,
13428+ __get_user_asm(tmp, (const u32 __user *)src,
13429 ret, "l", "k", "=r", 4);
13430 if (likely(!ret))
13431 __put_user_asm(tmp, (u32 __user *)dst,
13432@@ -204,7 +303,7 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
13433 }
13434 case 8: {
13435 u64 tmp;
13436- __get_user_asm(tmp, (u64 __user *)src,
13437+ __get_user_asm(tmp, (const u64 __user *)src,
13438 ret, "q", "", "=r", 8);
13439 if (likely(!ret))
13440 __put_user_asm(tmp, (u64 __user *)dst,
13441@@ -212,44 +311,89 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
13442 return ret;
13443 }
13444 default:
13445- return copy_user_generic((__force void *)dst,
13446- (__force void *)src, size);
13447+
13448+#ifdef CONFIG_PAX_MEMORY_UDEREF
13449+ if ((unsigned long)src < PAX_USER_SHADOW_BASE)
13450+ src += PAX_USER_SHADOW_BASE;
13451+ if ((unsigned long)dst < PAX_USER_SHADOW_BASE)
13452+ dst += PAX_USER_SHADOW_BASE;
13453+#endif
13454+
13455+ return copy_user_generic((__force_kernel void *)dst,
13456+ (__force_kernel const void *)src, size);
13457 }
13458 }
13459
13460-__must_check unsigned long clear_user(void __user *mem, unsigned long len);
13461-__must_check unsigned long __clear_user(void __user *mem, unsigned long len);
13462+__must_check unsigned long clear_user(void __user *mem, unsigned long len) __size_overflow(2);
13463+__must_check unsigned long __clear_user(void __user *mem, unsigned long len) __size_overflow(2);
13464
13465 static __must_check __always_inline int
13466-__copy_from_user_inatomic(void *dst, const void __user *src, unsigned size)
13467+__copy_from_user_inatomic(void *dst, const void __user *src, unsigned long size)
13468 {
13469- return copy_user_generic(dst, (__force const void *)src, size);
13470+ if (size > INT_MAX)
13471+ return size;
13472+
13473+#ifdef CONFIG_PAX_MEMORY_UDEREF
13474+ if (!__access_ok(VERIFY_READ, src, size))
13475+ return size;
13476+
13477+ if ((unsigned long)src < PAX_USER_SHADOW_BASE)
13478+ src += PAX_USER_SHADOW_BASE;
13479+#endif
13480+
13481+ return copy_user_generic(dst, (__force_kernel const void *)src, size);
13482 }
13483
13484-static __must_check __always_inline int
13485-__copy_to_user_inatomic(void __user *dst, const void *src, unsigned size)
13486+static __must_check __always_inline unsigned long
13487+__copy_to_user_inatomic(void __user *dst, const void *src, unsigned long size)
13488 {
13489- return copy_user_generic((__force void *)dst, src, size);
13490+ if (size > INT_MAX)
13491+ return size;
13492+
13493+#ifdef CONFIG_PAX_MEMORY_UDEREF
13494+ if (!__access_ok(VERIFY_WRITE, dst, size))
13495+ return size;
13496+
13497+ if ((unsigned long)dst < PAX_USER_SHADOW_BASE)
13498+ dst += PAX_USER_SHADOW_BASE;
13499+#endif
13500+
13501+ return copy_user_generic((__force_kernel void *)dst, src, size);
13502 }
13503
13504-extern long __copy_user_nocache(void *dst, const void __user *src,
13505- unsigned size, int zerorest);
13506+extern unsigned long __copy_user_nocache(void *dst, const void __user *src,
13507+ unsigned long size, int zerorest) __size_overflow(3);
13508
13509-static inline int
13510-__copy_from_user_nocache(void *dst, const void __user *src, unsigned size)
13511+static inline unsigned long __copy_from_user_nocache(void *dst, const void __user *src, unsigned long size)
13512 {
13513 might_sleep();
13514+
13515+ if (size > INT_MAX)
13516+ return size;
13517+
13518+#ifdef CONFIG_PAX_MEMORY_UDEREF
13519+ if (!__access_ok(VERIFY_READ, src, size))
13520+ return size;
13521+#endif
13522+
13523 return __copy_user_nocache(dst, src, size, 1);
13524 }
13525
13526-static inline int
13527-__copy_from_user_inatomic_nocache(void *dst, const void __user *src,
13528- unsigned size)
13529+static inline unsigned long __copy_from_user_inatomic_nocache(void *dst, const void __user *src,
13530+ unsigned long size)
13531 {
13532+ if (size > INT_MAX)
13533+ return size;
13534+
13535+#ifdef CONFIG_PAX_MEMORY_UDEREF
13536+ if (!__access_ok(VERIFY_READ, src, size))
13537+ return size;
13538+#endif
13539+
13540 return __copy_user_nocache(dst, src, size, 0);
13541 }
13542
13543-unsigned long
13544-copy_user_handle_tail(char *to, char *from, unsigned len, unsigned zerorest);
13545+extern unsigned long
13546+copy_user_handle_tail(char __user *to, char __user *from, unsigned long len, unsigned zerorest) __size_overflow(3);
13547
13548 #endif /* _ASM_X86_UACCESS_64_H */
13549diff --git a/arch/x86/include/asm/vdso.h b/arch/x86/include/asm/vdso.h
13550index bb05228..d763d5b 100644
13551--- a/arch/x86/include/asm/vdso.h
13552+++ b/arch/x86/include/asm/vdso.h
13553@@ -11,7 +11,7 @@ extern const char VDSO32_PRELINK[];
13554 #define VDSO32_SYMBOL(base, name) \
13555 ({ \
13556 extern const char VDSO32_##name[]; \
13557- (void *)(VDSO32_##name - VDSO32_PRELINK + (unsigned long)(base)); \
13558+ (void __user *)(VDSO32_##name - VDSO32_PRELINK + (unsigned long)(base)); \
13559 })
13560 #endif
13561
13562diff --git a/arch/x86/include/asm/word-at-a-time.h b/arch/x86/include/asm/word-at-a-time.h
13563index 5b238981..77fdd78 100644
13564--- a/arch/x86/include/asm/word-at-a-time.h
13565+++ b/arch/x86/include/asm/word-at-a-time.h
13566@@ -11,7 +11,7 @@
13567 * and shift, for example.
13568 */
13569 struct word_at_a_time {
13570- const unsigned long one_bits, high_bits;
13571+ unsigned long one_bits, high_bits;
13572 };
13573
13574 #define WORD_AT_A_TIME_CONSTANTS { REPEAT_BYTE(0x01), REPEAT_BYTE(0x80) }
13575diff --git a/arch/x86/include/asm/x86_init.h b/arch/x86/include/asm/x86_init.h
13576index 38155f6..e4184ba 100644
13577--- a/arch/x86/include/asm/x86_init.h
13578+++ b/arch/x86/include/asm/x86_init.h
13579@@ -29,7 +29,7 @@ struct x86_init_mpparse {
13580 void (*mpc_oem_bus_info)(struct mpc_bus *m, char *name);
13581 void (*find_smp_config)(void);
13582 void (*get_smp_config)(unsigned int early);
13583-};
13584+} __no_const;
13585
13586 /**
13587 * struct x86_init_resources - platform specific resource related ops
13588@@ -43,7 +43,7 @@ struct x86_init_resources {
13589 void (*probe_roms)(void);
13590 void (*reserve_resources)(void);
13591 char *(*memory_setup)(void);
13592-};
13593+} __no_const;
13594
13595 /**
13596 * struct x86_init_irqs - platform specific interrupt setup
13597@@ -56,7 +56,7 @@ struct x86_init_irqs {
13598 void (*pre_vector_init)(void);
13599 void (*intr_init)(void);
13600 void (*trap_init)(void);
13601-};
13602+} __no_const;
13603
13604 /**
13605 * struct x86_init_oem - oem platform specific customizing functions
13606@@ -66,7 +66,7 @@ struct x86_init_irqs {
13607 struct x86_init_oem {
13608 void (*arch_setup)(void);
13609 void (*banner)(void);
13610-};
13611+} __no_const;
13612
13613 /**
13614 * struct x86_init_mapping - platform specific initial kernel pagetable setup
13615@@ -77,7 +77,7 @@ struct x86_init_oem {
13616 */
13617 struct x86_init_mapping {
13618 void (*pagetable_reserve)(u64 start, u64 end);
13619-};
13620+} __no_const;
13621
13622 /**
13623 * struct x86_init_paging - platform specific paging functions
13624@@ -87,7 +87,7 @@ struct x86_init_mapping {
13625 struct x86_init_paging {
13626 void (*pagetable_setup_start)(pgd_t *base);
13627 void (*pagetable_setup_done)(pgd_t *base);
13628-};
13629+} __no_const;
13630
13631 /**
13632 * struct x86_init_timers - platform specific timer setup
13633@@ -102,7 +102,7 @@ struct x86_init_timers {
13634 void (*tsc_pre_init)(void);
13635 void (*timer_init)(void);
13636 void (*wallclock_init)(void);
13637-};
13638+} __no_const;
13639
13640 /**
13641 * struct x86_init_iommu - platform specific iommu setup
13642@@ -110,7 +110,7 @@ struct x86_init_timers {
13643 */
13644 struct x86_init_iommu {
13645 int (*iommu_init)(void);
13646-};
13647+} __no_const;
13648
13649 /**
13650 * struct x86_init_pci - platform specific pci init functions
13651@@ -124,7 +124,7 @@ struct x86_init_pci {
13652 int (*init)(void);
13653 void (*init_irq)(void);
13654 void (*fixup_irqs)(void);
13655-};
13656+} __no_const;
13657
13658 /**
13659 * struct x86_init_ops - functions for platform specific setup
13660@@ -140,7 +140,7 @@ struct x86_init_ops {
13661 struct x86_init_timers timers;
13662 struct x86_init_iommu iommu;
13663 struct x86_init_pci pci;
13664-};
13665+} __no_const;
13666
13667 /**
13668 * struct x86_cpuinit_ops - platform specific cpu hotplug setups
13669@@ -151,7 +151,7 @@ struct x86_cpuinit_ops {
13670 void (*setup_percpu_clockev)(void);
13671 void (*early_percpu_clock_init)(void);
13672 void (*fixup_cpu_id)(struct cpuinfo_x86 *c, int node);
13673-};
13674+} __no_const;
13675
13676 /**
13677 * struct x86_platform_ops - platform specific runtime functions
13678@@ -177,7 +177,7 @@ struct x86_platform_ops {
13679 void (*save_sched_clock_state)(void);
13680 void (*restore_sched_clock_state)(void);
13681 void (*apic_post_init)(void);
13682-};
13683+} __no_const;
13684
13685 struct pci_dev;
13686
13687@@ -186,14 +186,14 @@ struct x86_msi_ops {
13688 void (*teardown_msi_irq)(unsigned int irq);
13689 void (*teardown_msi_irqs)(struct pci_dev *dev);
13690 void (*restore_msi_irqs)(struct pci_dev *dev, int irq);
13691-};
13692+} __no_const;
13693
13694 struct x86_io_apic_ops {
13695 void (*init) (void);
13696 unsigned int (*read) (unsigned int apic, unsigned int reg);
13697 void (*write) (unsigned int apic, unsigned int reg, unsigned int value);
13698 void (*modify)(unsigned int apic, unsigned int reg, unsigned int value);
13699-};
13700+} __no_const;
13701
13702 extern struct x86_init_ops x86_init;
13703 extern struct x86_cpuinit_ops x86_cpuinit;
13704diff --git a/arch/x86/include/asm/xsave.h b/arch/x86/include/asm/xsave.h
13705index 8a1b6f9..a29c4e4 100644
13706--- a/arch/x86/include/asm/xsave.h
13707+++ b/arch/x86/include/asm/xsave.h
13708@@ -65,6 +65,11 @@ static inline int xsave_user(struct xsave_struct __user *buf)
13709 {
13710 int err;
13711
13712+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
13713+ if ((unsigned long)buf < PAX_USER_SHADOW_BASE)
13714+ buf = (struct xsave_struct __user *)((void __user*)buf + PAX_USER_SHADOW_BASE);
13715+#endif
13716+
13717 /*
13718 * Clear the xsave header first, so that reserved fields are
13719 * initialized to zero.
13720@@ -93,10 +98,15 @@ static inline int xsave_user(struct xsave_struct __user *buf)
13721 static inline int xrestore_user(struct xsave_struct __user *buf, u64 mask)
13722 {
13723 int err;
13724- struct xsave_struct *xstate = ((__force struct xsave_struct *)buf);
13725+ struct xsave_struct *xstate = ((__force_kernel struct xsave_struct *)buf);
13726 u32 lmask = mask;
13727 u32 hmask = mask >> 32;
13728
13729+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
13730+ if ((unsigned long)xstate < PAX_USER_SHADOW_BASE)
13731+ xstate = (struct xsave_struct *)((void *)xstate + PAX_USER_SHADOW_BASE);
13732+#endif
13733+
13734 __asm__ __volatile__("1: .byte " REX_PREFIX "0x0f,0xae,0x2f\n"
13735 "2:\n"
13736 ".section .fixup,\"ax\"\n"
13737diff --git a/arch/x86/kernel/acpi/sleep.c b/arch/x86/kernel/acpi/sleep.c
13738index 1b8e5a0..354fd59 100644
13739--- a/arch/x86/kernel/acpi/sleep.c
13740+++ b/arch/x86/kernel/acpi/sleep.c
13741@@ -69,8 +69,12 @@ int acpi_suspend_lowlevel(void)
13742 #else /* CONFIG_64BIT */
13743 #ifdef CONFIG_SMP
13744 stack_start = (unsigned long)temp_stack + sizeof(temp_stack);
13745+
13746+ pax_open_kernel();
13747 early_gdt_descr.address =
13748 (unsigned long)get_cpu_gdt_table(smp_processor_id());
13749+ pax_close_kernel();
13750+
13751 initial_gs = per_cpu_offset(smp_processor_id());
13752 #endif
13753 initial_code = (unsigned long)wakeup_long64;
13754diff --git a/arch/x86/kernel/acpi/wakeup_32.S b/arch/x86/kernel/acpi/wakeup_32.S
13755index 13ab720..95d5442 100644
13756--- a/arch/x86/kernel/acpi/wakeup_32.S
13757+++ b/arch/x86/kernel/acpi/wakeup_32.S
13758@@ -30,13 +30,11 @@ wakeup_pmode_return:
13759 # and restore the stack ... but you need gdt for this to work
13760 movl saved_context_esp, %esp
13761
13762- movl %cs:saved_magic, %eax
13763- cmpl $0x12345678, %eax
13764+ cmpl $0x12345678, saved_magic
13765 jne bogus_magic
13766
13767 # jump to place where we left off
13768- movl saved_eip, %eax
13769- jmp *%eax
13770+ jmp *(saved_eip)
13771
13772 bogus_magic:
13773 jmp bogus_magic
13774diff --git a/arch/x86/kernel/alternative.c b/arch/x86/kernel/alternative.c
13775index ced4534..3e75d69 100644
13776--- a/arch/x86/kernel/alternative.c
13777+++ b/arch/x86/kernel/alternative.c
13778@@ -281,6 +281,13 @@ void __init_or_module apply_alternatives(struct alt_instr *start,
13779 */
13780 for (a = start; a < end; a++) {
13781 instr = (u8 *)&a->instr_offset + a->instr_offset;
13782+
13783+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
13784+ instr += ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
13785+ if (instr < (u8 *)_text || (u8 *)_einittext <= instr)
13786+ instr -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
13787+#endif
13788+
13789 replacement = (u8 *)&a->repl_offset + a->repl_offset;
13790 BUG_ON(a->replacementlen > a->instrlen);
13791 BUG_ON(a->instrlen > sizeof(insnbuf));
13792@@ -312,10 +319,16 @@ static void alternatives_smp_lock(const s32 *start, const s32 *end,
13793 for (poff = start; poff < end; poff++) {
13794 u8 *ptr = (u8 *)poff + *poff;
13795
13796+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
13797+ ptr += ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
13798+ if (ptr < (u8 *)_text || (u8 *)_einittext <= ptr)
13799+ ptr -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
13800+#endif
13801+
13802 if (!*poff || ptr < text || ptr >= text_end)
13803 continue;
13804 /* turn DS segment override prefix into lock prefix */
13805- if (*ptr == 0x3e)
13806+ if (*ktla_ktva(ptr) == 0x3e)
13807 text_poke(ptr, ((unsigned char []){0xf0}), 1);
13808 };
13809 mutex_unlock(&text_mutex);
13810@@ -333,10 +346,16 @@ static void alternatives_smp_unlock(const s32 *start, const s32 *end,
13811 for (poff = start; poff < end; poff++) {
13812 u8 *ptr = (u8 *)poff + *poff;
13813
13814+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
13815+ ptr += ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
13816+ if (ptr < (u8 *)_text || (u8 *)_einittext <= ptr)
13817+ ptr -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
13818+#endif
13819+
13820 if (!*poff || ptr < text || ptr >= text_end)
13821 continue;
13822 /* turn lock prefix into DS segment override prefix */
13823- if (*ptr == 0xf0)
13824+ if (*ktla_ktva(ptr) == 0xf0)
13825 text_poke(ptr, ((unsigned char []){0x3E}), 1);
13826 };
13827 mutex_unlock(&text_mutex);
13828@@ -505,7 +524,7 @@ void __init_or_module apply_paravirt(struct paravirt_patch_site *start,
13829
13830 BUG_ON(p->len > MAX_PATCH_LEN);
13831 /* prep the buffer with the original instructions */
13832- memcpy(insnbuf, p->instr, p->len);
13833+ memcpy(insnbuf, ktla_ktva(p->instr), p->len);
13834 used = pv_init_ops.patch(p->instrtype, p->clobbers, insnbuf,
13835 (unsigned long)p->instr, p->len);
13836
13837@@ -573,7 +592,7 @@ void __init alternative_instructions(void)
13838 if (smp_alt_once)
13839 free_init_pages("SMP alternatives",
13840 (unsigned long)__smp_locks,
13841- (unsigned long)__smp_locks_end);
13842+ PAGE_ALIGN((unsigned long)__smp_locks_end));
13843
13844 restart_nmi();
13845 }
13846@@ -590,13 +609,17 @@ void __init alternative_instructions(void)
13847 * instructions. And on the local CPU you need to be protected again NMI or MCE
13848 * handlers seeing an inconsistent instruction while you patch.
13849 */
13850-void *__init_or_module text_poke_early(void *addr, const void *opcode,
13851+void *__kprobes text_poke_early(void *addr, const void *opcode,
13852 size_t len)
13853 {
13854 unsigned long flags;
13855 local_irq_save(flags);
13856- memcpy(addr, opcode, len);
13857+
13858+ pax_open_kernel();
13859+ memcpy(ktla_ktva(addr), opcode, len);
13860 sync_core();
13861+ pax_close_kernel();
13862+
13863 local_irq_restore(flags);
13864 /* Could also do a CLFLUSH here to speed up CPU recovery; but
13865 that causes hangs on some VIA CPUs. */
13866@@ -618,36 +641,22 @@ void *__init_or_module text_poke_early(void *addr, const void *opcode,
13867 */
13868 void *__kprobes text_poke(void *addr, const void *opcode, size_t len)
13869 {
13870- unsigned long flags;
13871- char *vaddr;
13872+ unsigned char *vaddr = ktla_ktva(addr);
13873 struct page *pages[2];
13874- int i;
13875+ size_t i;
13876
13877 if (!core_kernel_text((unsigned long)addr)) {
13878- pages[0] = vmalloc_to_page(addr);
13879- pages[1] = vmalloc_to_page(addr + PAGE_SIZE);
13880+ pages[0] = vmalloc_to_page(vaddr);
13881+ pages[1] = vmalloc_to_page(vaddr + PAGE_SIZE);
13882 } else {
13883- pages[0] = virt_to_page(addr);
13884+ pages[0] = virt_to_page(vaddr);
13885 WARN_ON(!PageReserved(pages[0]));
13886- pages[1] = virt_to_page(addr + PAGE_SIZE);
13887+ pages[1] = virt_to_page(vaddr + PAGE_SIZE);
13888 }
13889 BUG_ON(!pages[0]);
13890- local_irq_save(flags);
13891- set_fixmap(FIX_TEXT_POKE0, page_to_phys(pages[0]));
13892- if (pages[1])
13893- set_fixmap(FIX_TEXT_POKE1, page_to_phys(pages[1]));
13894- vaddr = (char *)fix_to_virt(FIX_TEXT_POKE0);
13895- memcpy(&vaddr[(unsigned long)addr & ~PAGE_MASK], opcode, len);
13896- clear_fixmap(FIX_TEXT_POKE0);
13897- if (pages[1])
13898- clear_fixmap(FIX_TEXT_POKE1);
13899- local_flush_tlb();
13900- sync_core();
13901- /* Could also do a CLFLUSH here to speed up CPU recovery; but
13902- that causes hangs on some VIA CPUs. */
13903+ text_poke_early(addr, opcode, len);
13904 for (i = 0; i < len; i++)
13905- BUG_ON(((char *)addr)[i] != ((char *)opcode)[i]);
13906- local_irq_restore(flags);
13907+ BUG_ON((vaddr)[i] != ((const unsigned char *)opcode)[i]);
13908 return addr;
13909 }
13910
13911diff --git a/arch/x86/kernel/apic/apic.c b/arch/x86/kernel/apic/apic.c
13912index 24deb30..94a3426 100644
13913--- a/arch/x86/kernel/apic/apic.c
13914+++ b/arch/x86/kernel/apic/apic.c
13915@@ -185,7 +185,7 @@ int first_system_vector = 0xfe;
13916 /*
13917 * Debug level, exported for io_apic.c
13918 */
13919-unsigned int apic_verbosity;
13920+int apic_verbosity;
13921
13922 int pic_mode;
13923
13924@@ -1923,7 +1923,7 @@ void smp_error_interrupt(struct pt_regs *regs)
13925 apic_write(APIC_ESR, 0);
13926 v1 = apic_read(APIC_ESR);
13927 ack_APIC_irq();
13928- atomic_inc(&irq_err_count);
13929+ atomic_inc_unchecked(&irq_err_count);
13930
13931 apic_printk(APIC_DEBUG, KERN_DEBUG "APIC error on CPU%d: %02x(%02x)",
13932 smp_processor_id(), v0 , v1);
13933@@ -2155,7 +2155,9 @@ void __init apic_set_eoi_write(void (*eoi_write)(u32 reg, u32 v))
13934 for (drv = __apicdrivers; drv < __apicdrivers_end; drv++) {
13935 /* Should happen once for each apic */
13936 WARN_ON((*drv)->eoi_write == eoi_write);
13937- (*drv)->eoi_write = eoi_write;
13938+ pax_open_kernel();
13939+ *(void **)&(*drv)->eoi_write = eoi_write;
13940+ pax_close_kernel();
13941 }
13942 }
13943
13944diff --git a/arch/x86/kernel/apic/io_apic.c b/arch/x86/kernel/apic/io_apic.c
13945index c265593..137c4ac 100644
13946--- a/arch/x86/kernel/apic/io_apic.c
13947+++ b/arch/x86/kernel/apic/io_apic.c
13948@@ -1084,7 +1084,7 @@ int IO_APIC_get_PCI_irq_vector(int bus, int slot, int pin,
13949 }
13950 EXPORT_SYMBOL(IO_APIC_get_PCI_irq_vector);
13951
13952-void lock_vector_lock(void)
13953+void lock_vector_lock(void) __acquires(vector_lock)
13954 {
13955 /* Used to the online set of cpus does not change
13956 * during assign_irq_vector.
13957@@ -1092,7 +1092,7 @@ void lock_vector_lock(void)
13958 raw_spin_lock(&vector_lock);
13959 }
13960
13961-void unlock_vector_lock(void)
13962+void unlock_vector_lock(void) __releases(vector_lock)
13963 {
13964 raw_spin_unlock(&vector_lock);
13965 }
13966@@ -2408,7 +2408,7 @@ static void ack_apic_edge(struct irq_data *data)
13967 ack_APIC_irq();
13968 }
13969
13970-atomic_t irq_mis_count;
13971+atomic_unchecked_t irq_mis_count;
13972
13973 #ifdef CONFIG_GENERIC_PENDING_IRQ
13974 static bool io_apic_level_ack_pending(struct irq_cfg *cfg)
13975@@ -2549,7 +2549,7 @@ static void ack_apic_level(struct irq_data *data)
13976 * at the cpu.
13977 */
13978 if (!(v & (1 << (i & 0x1f)))) {
13979- atomic_inc(&irq_mis_count);
13980+ atomic_inc_unchecked(&irq_mis_count);
13981
13982 eoi_ioapic_irq(irq, cfg);
13983 }
13984diff --git a/arch/x86/kernel/apm_32.c b/arch/x86/kernel/apm_32.c
13985index d65464e..1035d31 100644
13986--- a/arch/x86/kernel/apm_32.c
13987+++ b/arch/x86/kernel/apm_32.c
13988@@ -412,7 +412,7 @@ static DEFINE_MUTEX(apm_mutex);
13989 * This is for buggy BIOS's that refer to (real mode) segment 0x40
13990 * even though they are called in protected mode.
13991 */
13992-static struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4092,
13993+static const struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4093,
13994 (unsigned long)__va(0x400UL), PAGE_SIZE - 0x400 - 1);
13995
13996 static const char driver_version[] = "1.16ac"; /* no spaces */
13997@@ -590,7 +590,10 @@ static long __apm_bios_call(void *_call)
13998 BUG_ON(cpu != 0);
13999 gdt = get_cpu_gdt_table(cpu);
14000 save_desc_40 = gdt[0x40 / 8];
14001+
14002+ pax_open_kernel();
14003 gdt[0x40 / 8] = bad_bios_desc;
14004+ pax_close_kernel();
14005
14006 apm_irq_save(flags);
14007 APM_DO_SAVE_SEGS;
14008@@ -599,7 +602,11 @@ static long __apm_bios_call(void *_call)
14009 &call->esi);
14010 APM_DO_RESTORE_SEGS;
14011 apm_irq_restore(flags);
14012+
14013+ pax_open_kernel();
14014 gdt[0x40 / 8] = save_desc_40;
14015+ pax_close_kernel();
14016+
14017 put_cpu();
14018
14019 return call->eax & 0xff;
14020@@ -666,7 +673,10 @@ static long __apm_bios_call_simple(void *_call)
14021 BUG_ON(cpu != 0);
14022 gdt = get_cpu_gdt_table(cpu);
14023 save_desc_40 = gdt[0x40 / 8];
14024+
14025+ pax_open_kernel();
14026 gdt[0x40 / 8] = bad_bios_desc;
14027+ pax_close_kernel();
14028
14029 apm_irq_save(flags);
14030 APM_DO_SAVE_SEGS;
14031@@ -674,7 +684,11 @@ static long __apm_bios_call_simple(void *_call)
14032 &call->eax);
14033 APM_DO_RESTORE_SEGS;
14034 apm_irq_restore(flags);
14035+
14036+ pax_open_kernel();
14037 gdt[0x40 / 8] = save_desc_40;
14038+ pax_close_kernel();
14039+
14040 put_cpu();
14041 return error;
14042 }
14043@@ -2345,12 +2359,15 @@ static int __init apm_init(void)
14044 * code to that CPU.
14045 */
14046 gdt = get_cpu_gdt_table(0);
14047+
14048+ pax_open_kernel();
14049 set_desc_base(&gdt[APM_CS >> 3],
14050 (unsigned long)__va((unsigned long)apm_info.bios.cseg << 4));
14051 set_desc_base(&gdt[APM_CS_16 >> 3],
14052 (unsigned long)__va((unsigned long)apm_info.bios.cseg_16 << 4));
14053 set_desc_base(&gdt[APM_DS >> 3],
14054 (unsigned long)__va((unsigned long)apm_info.bios.dseg << 4));
14055+ pax_close_kernel();
14056
14057 proc_create("apm", 0, NULL, &apm_file_ops);
14058
14059diff --git a/arch/x86/kernel/asm-offsets.c b/arch/x86/kernel/asm-offsets.c
14060index 68de2dc..1f3c720 100644
14061--- a/arch/x86/kernel/asm-offsets.c
14062+++ b/arch/x86/kernel/asm-offsets.c
14063@@ -33,6 +33,8 @@ void common(void) {
14064 OFFSET(TI_status, thread_info, status);
14065 OFFSET(TI_addr_limit, thread_info, addr_limit);
14066 OFFSET(TI_preempt_count, thread_info, preempt_count);
14067+ OFFSET(TI_lowest_stack, thread_info, lowest_stack);
14068+ DEFINE(TI_task_thread_sp0, offsetof(struct task_struct, thread.sp0) - offsetof(struct task_struct, tinfo));
14069
14070 BLANK();
14071 OFFSET(crypto_tfm_ctx_offset, crypto_tfm, __crt_ctx);
14072@@ -53,8 +55,26 @@ void common(void) {
14073 OFFSET(PV_CPU_irq_enable_sysexit, pv_cpu_ops, irq_enable_sysexit);
14074 OFFSET(PV_CPU_read_cr0, pv_cpu_ops, read_cr0);
14075 OFFSET(PV_MMU_read_cr2, pv_mmu_ops, read_cr2);
14076+
14077+#ifdef CONFIG_PAX_KERNEXEC
14078+ OFFSET(PV_CPU_write_cr0, pv_cpu_ops, write_cr0);
14079 #endif
14080
14081+#ifdef CONFIG_PAX_MEMORY_UDEREF
14082+ OFFSET(PV_MMU_read_cr3, pv_mmu_ops, read_cr3);
14083+ OFFSET(PV_MMU_write_cr3, pv_mmu_ops, write_cr3);
14084+#ifdef CONFIG_X86_64
14085+ OFFSET(PV_MMU_set_pgd_batched, pv_mmu_ops, set_pgd_batched);
14086+#endif
14087+#endif
14088+
14089+#endif
14090+
14091+ BLANK();
14092+ DEFINE(PAGE_SIZE_asm, PAGE_SIZE);
14093+ DEFINE(PAGE_SHIFT_asm, PAGE_SHIFT);
14094+ DEFINE(THREAD_SIZE_asm, THREAD_SIZE);
14095+
14096 #ifdef CONFIG_XEN
14097 BLANK();
14098 OFFSET(XEN_vcpu_info_mask, vcpu_info, evtchn_upcall_mask);
14099diff --git a/arch/x86/kernel/asm-offsets_64.c b/arch/x86/kernel/asm-offsets_64.c
14100index 1b4754f..fbb4227 100644
14101--- a/arch/x86/kernel/asm-offsets_64.c
14102+++ b/arch/x86/kernel/asm-offsets_64.c
14103@@ -76,6 +76,7 @@ int main(void)
14104 BLANK();
14105 #undef ENTRY
14106
14107+ DEFINE(TSS_size, sizeof(struct tss_struct));
14108 OFFSET(TSS_ist, tss_struct, x86_tss.ist);
14109 BLANK();
14110
14111diff --git a/arch/x86/kernel/cpu/Makefile b/arch/x86/kernel/cpu/Makefile
14112index d30a6a9..79becab 100644
14113--- a/arch/x86/kernel/cpu/Makefile
14114+++ b/arch/x86/kernel/cpu/Makefile
14115@@ -8,10 +8,6 @@ CFLAGS_REMOVE_common.o = -pg
14116 CFLAGS_REMOVE_perf_event.o = -pg
14117 endif
14118
14119-# Make sure load_percpu_segment has no stackprotector
14120-nostackp := $(call cc-option, -fno-stack-protector)
14121-CFLAGS_common.o := $(nostackp)
14122-
14123 obj-y := intel_cacheinfo.o scattered.o topology.o
14124 obj-y += proc.o capflags.o powerflags.o common.o
14125 obj-y += vmware.o hypervisor.o mshyperv.o
14126diff --git a/arch/x86/kernel/cpu/amd.c b/arch/x86/kernel/cpu/amd.c
14127index 9d92e19..49d7d79 100644
14128--- a/arch/x86/kernel/cpu/amd.c
14129+++ b/arch/x86/kernel/cpu/amd.c
14130@@ -724,7 +724,7 @@ static unsigned int __cpuinit amd_size_cache(struct cpuinfo_x86 *c,
14131 unsigned int size)
14132 {
14133 /* AMD errata T13 (order #21922) */
14134- if ((c->x86 == 6)) {
14135+ if (c->x86 == 6) {
14136 /* Duron Rev A0 */
14137 if (c->x86_model == 3 && c->x86_mask == 0)
14138 size = 64;
14139diff --git a/arch/x86/kernel/cpu/common.c b/arch/x86/kernel/cpu/common.c
14140index a5fbc3c..2254849 100644
14141--- a/arch/x86/kernel/cpu/common.c
14142+++ b/arch/x86/kernel/cpu/common.c
14143@@ -86,60 +86,6 @@ static const struct cpu_dev __cpuinitconst default_cpu = {
14144
14145 static const struct cpu_dev *this_cpu __cpuinitdata = &default_cpu;
14146
14147-DEFINE_PER_CPU_PAGE_ALIGNED(struct gdt_page, gdt_page) = { .gdt = {
14148-#ifdef CONFIG_X86_64
14149- /*
14150- * We need valid kernel segments for data and code in long mode too
14151- * IRET will check the segment types kkeil 2000/10/28
14152- * Also sysret mandates a special GDT layout
14153- *
14154- * TLS descriptors are currently at a different place compared to i386.
14155- * Hopefully nobody expects them at a fixed place (Wine?)
14156- */
14157- [GDT_ENTRY_KERNEL32_CS] = GDT_ENTRY_INIT(0xc09b, 0, 0xfffff),
14158- [GDT_ENTRY_KERNEL_CS] = GDT_ENTRY_INIT(0xa09b, 0, 0xfffff),
14159- [GDT_ENTRY_KERNEL_DS] = GDT_ENTRY_INIT(0xc093, 0, 0xfffff),
14160- [GDT_ENTRY_DEFAULT_USER32_CS] = GDT_ENTRY_INIT(0xc0fb, 0, 0xfffff),
14161- [GDT_ENTRY_DEFAULT_USER_DS] = GDT_ENTRY_INIT(0xc0f3, 0, 0xfffff),
14162- [GDT_ENTRY_DEFAULT_USER_CS] = GDT_ENTRY_INIT(0xa0fb, 0, 0xfffff),
14163-#else
14164- [GDT_ENTRY_KERNEL_CS] = GDT_ENTRY_INIT(0xc09a, 0, 0xfffff),
14165- [GDT_ENTRY_KERNEL_DS] = GDT_ENTRY_INIT(0xc092, 0, 0xfffff),
14166- [GDT_ENTRY_DEFAULT_USER_CS] = GDT_ENTRY_INIT(0xc0fa, 0, 0xfffff),
14167- [GDT_ENTRY_DEFAULT_USER_DS] = GDT_ENTRY_INIT(0xc0f2, 0, 0xfffff),
14168- /*
14169- * Segments used for calling PnP BIOS have byte granularity.
14170- * They code segments and data segments have fixed 64k limits,
14171- * the transfer segment sizes are set at run time.
14172- */
14173- /* 32-bit code */
14174- [GDT_ENTRY_PNPBIOS_CS32] = GDT_ENTRY_INIT(0x409a, 0, 0xffff),
14175- /* 16-bit code */
14176- [GDT_ENTRY_PNPBIOS_CS16] = GDT_ENTRY_INIT(0x009a, 0, 0xffff),
14177- /* 16-bit data */
14178- [GDT_ENTRY_PNPBIOS_DS] = GDT_ENTRY_INIT(0x0092, 0, 0xffff),
14179- /* 16-bit data */
14180- [GDT_ENTRY_PNPBIOS_TS1] = GDT_ENTRY_INIT(0x0092, 0, 0),
14181- /* 16-bit data */
14182- [GDT_ENTRY_PNPBIOS_TS2] = GDT_ENTRY_INIT(0x0092, 0, 0),
14183- /*
14184- * The APM segments have byte granularity and their bases
14185- * are set at run time. All have 64k limits.
14186- */
14187- /* 32-bit code */
14188- [GDT_ENTRY_APMBIOS_BASE] = GDT_ENTRY_INIT(0x409a, 0, 0xffff),
14189- /* 16-bit code */
14190- [GDT_ENTRY_APMBIOS_BASE+1] = GDT_ENTRY_INIT(0x009a, 0, 0xffff),
14191- /* data */
14192- [GDT_ENTRY_APMBIOS_BASE+2] = GDT_ENTRY_INIT(0x4092, 0, 0xffff),
14193-
14194- [GDT_ENTRY_ESPFIX_SS] = GDT_ENTRY_INIT(0xc092, 0, 0xfffff),
14195- [GDT_ENTRY_PERCPU] = GDT_ENTRY_INIT(0xc092, 0, 0xfffff),
14196- GDT_STACK_CANARY_INIT
14197-#endif
14198-} };
14199-EXPORT_PER_CPU_SYMBOL_GPL(gdt_page);
14200-
14201 static int __init x86_xsave_setup(char *s)
14202 {
14203 setup_clear_cpu_cap(X86_FEATURE_XSAVE);
14204@@ -376,7 +322,7 @@ void switch_to_new_gdt(int cpu)
14205 {
14206 struct desc_ptr gdt_descr;
14207
14208- gdt_descr.address = (long)get_cpu_gdt_table(cpu);
14209+ gdt_descr.address = (unsigned long)get_cpu_gdt_table(cpu);
14210 gdt_descr.size = GDT_SIZE - 1;
14211 load_gdt(&gdt_descr);
14212 /* Reload the per-cpu base */
14213@@ -872,6 +818,10 @@ static void __cpuinit identify_cpu(struct cpuinfo_x86 *c)
14214 /* Filter out anything that depends on CPUID levels we don't have */
14215 filter_cpuid_features(c, true);
14216
14217+#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_SEGMEXEC) || defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF))
14218+ setup_clear_cpu_cap(X86_FEATURE_SEP);
14219+#endif
14220+
14221 /* If the model name is still unset, do table lookup. */
14222 if (!c->x86_model_id[0]) {
14223 const char *p;
14224@@ -1054,10 +1004,12 @@ static __init int setup_disablecpuid(char *arg)
14225 }
14226 __setup("clearcpuid=", setup_disablecpuid);
14227
14228+DEFINE_PER_CPU(struct thread_info *, current_tinfo) = &init_task.tinfo;
14229+EXPORT_PER_CPU_SYMBOL(current_tinfo);
14230+
14231 #ifdef CONFIG_X86_64
14232 struct desc_ptr idt_descr = { NR_VECTORS * 16 - 1, (unsigned long) idt_table };
14233-struct desc_ptr nmi_idt_descr = { NR_VECTORS * 16 - 1,
14234- (unsigned long) nmi_idt_table };
14235+struct desc_ptr nmi_idt_descr = { NR_VECTORS * 16 - 1, (unsigned long) nmi_idt_table };
14236
14237 DEFINE_PER_CPU_FIRST(union irq_stack_union,
14238 irq_stack_union) __aligned(PAGE_SIZE);
14239@@ -1071,7 +1023,7 @@ DEFINE_PER_CPU(struct task_struct *, current_task) ____cacheline_aligned =
14240 EXPORT_PER_CPU_SYMBOL(current_task);
14241
14242 DEFINE_PER_CPU(unsigned long, kernel_stack) =
14243- (unsigned long)&init_thread_union - KERNEL_STACK_OFFSET + THREAD_SIZE;
14244+ (unsigned long)&init_thread_union - 16 + THREAD_SIZE;
14245 EXPORT_PER_CPU_SYMBOL(kernel_stack);
14246
14247 DEFINE_PER_CPU(char *, irq_stack_ptr) =
14248@@ -1165,7 +1117,7 @@ struct pt_regs * __cpuinit idle_regs(struct pt_regs *regs)
14249 {
14250 memset(regs, 0, sizeof(struct pt_regs));
14251 regs->fs = __KERNEL_PERCPU;
14252- regs->gs = __KERNEL_STACK_CANARY;
14253+ savesegment(gs, regs->gs);
14254
14255 return regs;
14256 }
14257@@ -1220,7 +1172,7 @@ void __cpuinit cpu_init(void)
14258 int i;
14259
14260 cpu = stack_smp_processor_id();
14261- t = &per_cpu(init_tss, cpu);
14262+ t = init_tss + cpu;
14263 oist = &per_cpu(orig_ist, cpu);
14264
14265 #ifdef CONFIG_NUMA
14266@@ -1246,7 +1198,7 @@ void __cpuinit cpu_init(void)
14267 switch_to_new_gdt(cpu);
14268 loadsegment(fs, 0);
14269
14270- load_idt((const struct desc_ptr *)&idt_descr);
14271+ load_idt(&idt_descr);
14272
14273 memset(me->thread.tls_array, 0, GDT_ENTRY_TLS_ENTRIES * 8);
14274 syscall_init();
14275@@ -1255,7 +1207,6 @@ void __cpuinit cpu_init(void)
14276 wrmsrl(MSR_KERNEL_GS_BASE, 0);
14277 barrier();
14278
14279- x86_configure_nx();
14280 if (cpu != 0)
14281 enable_x2apic();
14282
14283@@ -1311,7 +1262,7 @@ void __cpuinit cpu_init(void)
14284 {
14285 int cpu = smp_processor_id();
14286 struct task_struct *curr = current;
14287- struct tss_struct *t = &per_cpu(init_tss, cpu);
14288+ struct tss_struct *t = init_tss + cpu;
14289 struct thread_struct *thread = &curr->thread;
14290
14291 if (cpumask_test_and_set_cpu(cpu, cpu_initialized_mask)) {
14292diff --git a/arch/x86/kernel/cpu/intel.c b/arch/x86/kernel/cpu/intel.c
14293index 0a4ce29..f211176 100644
14294--- a/arch/x86/kernel/cpu/intel.c
14295+++ b/arch/x86/kernel/cpu/intel.c
14296@@ -174,7 +174,7 @@ static void __cpuinit trap_init_f00f_bug(void)
14297 * Update the IDT descriptor and reload the IDT so that
14298 * it uses the read-only mapped virtual address.
14299 */
14300- idt_descr.address = fix_to_virt(FIX_F00F_IDT);
14301+ idt_descr.address = (struct desc_struct *)fix_to_virt(FIX_F00F_IDT);
14302 load_idt(&idt_descr);
14303 }
14304 #endif
14305diff --git a/arch/x86/kernel/cpu/mcheck/mce.c b/arch/x86/kernel/cpu/mcheck/mce.c
14306index 292d025..b520c94 100644
14307--- a/arch/x86/kernel/cpu/mcheck/mce.c
14308+++ b/arch/x86/kernel/cpu/mcheck/mce.c
14309@@ -45,6 +45,7 @@
14310 #include <asm/processor.h>
14311 #include <asm/mce.h>
14312 #include <asm/msr.h>
14313+#include <asm/local.h>
14314
14315 #include "mce-internal.h"
14316
14317@@ -253,7 +254,7 @@ static void print_mce(struct mce *m)
14318 !(m->mcgstatus & MCG_STATUS_EIPV) ? " !INEXACT!" : "",
14319 m->cs, m->ip);
14320
14321- if (m->cs == __KERNEL_CS)
14322+ if (m->cs == __KERNEL_CS || m->cs == __KERNEXEC_KERNEL_CS)
14323 print_symbol("{%s}", m->ip);
14324 pr_cont("\n");
14325 }
14326@@ -286,10 +287,10 @@ static void print_mce(struct mce *m)
14327
14328 #define PANIC_TIMEOUT 5 /* 5 seconds */
14329
14330-static atomic_t mce_paniced;
14331+static atomic_unchecked_t mce_paniced;
14332
14333 static int fake_panic;
14334-static atomic_t mce_fake_paniced;
14335+static atomic_unchecked_t mce_fake_paniced;
14336
14337 /* Panic in progress. Enable interrupts and wait for final IPI */
14338 static void wait_for_panic(void)
14339@@ -313,7 +314,7 @@ static void mce_panic(char *msg, struct mce *final, char *exp)
14340 /*
14341 * Make sure only one CPU runs in machine check panic
14342 */
14343- if (atomic_inc_return(&mce_paniced) > 1)
14344+ if (atomic_inc_return_unchecked(&mce_paniced) > 1)
14345 wait_for_panic();
14346 barrier();
14347
14348@@ -321,7 +322,7 @@ static void mce_panic(char *msg, struct mce *final, char *exp)
14349 console_verbose();
14350 } else {
14351 /* Don't log too much for fake panic */
14352- if (atomic_inc_return(&mce_fake_paniced) > 1)
14353+ if (atomic_inc_return_unchecked(&mce_fake_paniced) > 1)
14354 return;
14355 }
14356 /* First print corrected ones that are still unlogged */
14357@@ -693,7 +694,7 @@ static int mce_timed_out(u64 *t)
14358 * might have been modified by someone else.
14359 */
14360 rmb();
14361- if (atomic_read(&mce_paniced))
14362+ if (atomic_read_unchecked(&mce_paniced))
14363 wait_for_panic();
14364 if (!monarch_timeout)
14365 goto out;
14366@@ -1619,7 +1620,7 @@ static void unexpected_machine_check(struct pt_regs *regs, long error_code)
14367 }
14368
14369 /* Call the installed machine check handler for this CPU setup. */
14370-void (*machine_check_vector)(struct pt_regs *, long error_code) =
14371+void (*machine_check_vector)(struct pt_regs *, long error_code) __read_only =
14372 unexpected_machine_check;
14373
14374 /*
14375@@ -1642,7 +1643,9 @@ void __cpuinit mcheck_cpu_init(struct cpuinfo_x86 *c)
14376 return;
14377 }
14378
14379+ pax_open_kernel();
14380 machine_check_vector = do_machine_check;
14381+ pax_close_kernel();
14382
14383 __mcheck_cpu_init_generic();
14384 __mcheck_cpu_init_vendor(c);
14385@@ -1656,7 +1659,7 @@ void __cpuinit mcheck_cpu_init(struct cpuinfo_x86 *c)
14386 */
14387
14388 static DEFINE_SPINLOCK(mce_chrdev_state_lock);
14389-static int mce_chrdev_open_count; /* #times opened */
14390+static local_t mce_chrdev_open_count; /* #times opened */
14391 static int mce_chrdev_open_exclu; /* already open exclusive? */
14392
14393 static int mce_chrdev_open(struct inode *inode, struct file *file)
14394@@ -1664,7 +1667,7 @@ static int mce_chrdev_open(struct inode *inode, struct file *file)
14395 spin_lock(&mce_chrdev_state_lock);
14396
14397 if (mce_chrdev_open_exclu ||
14398- (mce_chrdev_open_count && (file->f_flags & O_EXCL))) {
14399+ (local_read(&mce_chrdev_open_count) && (file->f_flags & O_EXCL))) {
14400 spin_unlock(&mce_chrdev_state_lock);
14401
14402 return -EBUSY;
14403@@ -1672,7 +1675,7 @@ static int mce_chrdev_open(struct inode *inode, struct file *file)
14404
14405 if (file->f_flags & O_EXCL)
14406 mce_chrdev_open_exclu = 1;
14407- mce_chrdev_open_count++;
14408+ local_inc(&mce_chrdev_open_count);
14409
14410 spin_unlock(&mce_chrdev_state_lock);
14411
14412@@ -1683,7 +1686,7 @@ static int mce_chrdev_release(struct inode *inode, struct file *file)
14413 {
14414 spin_lock(&mce_chrdev_state_lock);
14415
14416- mce_chrdev_open_count--;
14417+ local_dec(&mce_chrdev_open_count);
14418 mce_chrdev_open_exclu = 0;
14419
14420 spin_unlock(&mce_chrdev_state_lock);
14421@@ -2407,7 +2410,7 @@ struct dentry *mce_get_debugfs_dir(void)
14422 static void mce_reset(void)
14423 {
14424 cpu_missing = 0;
14425- atomic_set(&mce_fake_paniced, 0);
14426+ atomic_set_unchecked(&mce_fake_paniced, 0);
14427 atomic_set(&mce_executing, 0);
14428 atomic_set(&mce_callin, 0);
14429 atomic_set(&global_nwo, 0);
14430diff --git a/arch/x86/kernel/cpu/mcheck/p5.c b/arch/x86/kernel/cpu/mcheck/p5.c
14431index 2d5454c..51987eb 100644
14432--- a/arch/x86/kernel/cpu/mcheck/p5.c
14433+++ b/arch/x86/kernel/cpu/mcheck/p5.c
14434@@ -11,6 +11,7 @@
14435 #include <asm/processor.h>
14436 #include <asm/mce.h>
14437 #include <asm/msr.h>
14438+#include <asm/pgtable.h>
14439
14440 /* By default disabled */
14441 int mce_p5_enabled __read_mostly;
14442@@ -49,7 +50,9 @@ void intel_p5_mcheck_init(struct cpuinfo_x86 *c)
14443 if (!cpu_has(c, X86_FEATURE_MCE))
14444 return;
14445
14446+ pax_open_kernel();
14447 machine_check_vector = pentium_machine_check;
14448+ pax_close_kernel();
14449 /* Make sure the vector pointer is visible before we enable MCEs: */
14450 wmb();
14451
14452diff --git a/arch/x86/kernel/cpu/mcheck/winchip.c b/arch/x86/kernel/cpu/mcheck/winchip.c
14453index 2d7998f..17c9de1 100644
14454--- a/arch/x86/kernel/cpu/mcheck/winchip.c
14455+++ b/arch/x86/kernel/cpu/mcheck/winchip.c
14456@@ -10,6 +10,7 @@
14457 #include <asm/processor.h>
14458 #include <asm/mce.h>
14459 #include <asm/msr.h>
14460+#include <asm/pgtable.h>
14461
14462 /* Machine check handler for WinChip C6: */
14463 static void winchip_machine_check(struct pt_regs *regs, long error_code)
14464@@ -23,7 +24,9 @@ void winchip_mcheck_init(struct cpuinfo_x86 *c)
14465 {
14466 u32 lo, hi;
14467
14468+ pax_open_kernel();
14469 machine_check_vector = winchip_machine_check;
14470+ pax_close_kernel();
14471 /* Make sure the vector pointer is visible before we enable MCEs: */
14472 wmb();
14473
14474diff --git a/arch/x86/kernel/cpu/mtrr/main.c b/arch/x86/kernel/cpu/mtrr/main.c
14475index 6b96110..0da73eb 100644
14476--- a/arch/x86/kernel/cpu/mtrr/main.c
14477+++ b/arch/x86/kernel/cpu/mtrr/main.c
14478@@ -62,7 +62,7 @@ static DEFINE_MUTEX(mtrr_mutex);
14479 u64 size_or_mask, size_and_mask;
14480 static bool mtrr_aps_delayed_init;
14481
14482-static const struct mtrr_ops *mtrr_ops[X86_VENDOR_NUM];
14483+static const struct mtrr_ops *mtrr_ops[X86_VENDOR_NUM] __read_only;
14484
14485 const struct mtrr_ops *mtrr_if;
14486
14487diff --git a/arch/x86/kernel/cpu/mtrr/mtrr.h b/arch/x86/kernel/cpu/mtrr/mtrr.h
14488index df5e41f..816c719 100644
14489--- a/arch/x86/kernel/cpu/mtrr/mtrr.h
14490+++ b/arch/x86/kernel/cpu/mtrr/mtrr.h
14491@@ -25,7 +25,7 @@ struct mtrr_ops {
14492 int (*validate_add_page)(unsigned long base, unsigned long size,
14493 unsigned int type);
14494 int (*have_wrcomb)(void);
14495-};
14496+} __do_const;
14497
14498 extern int generic_get_free_region(unsigned long base, unsigned long size,
14499 int replace_reg);
14500diff --git a/arch/x86/kernel/cpu/perf_event.c b/arch/x86/kernel/cpu/perf_event.c
14501index 915b876..171f845 100644
14502--- a/arch/x86/kernel/cpu/perf_event.c
14503+++ b/arch/x86/kernel/cpu/perf_event.c
14504@@ -1757,7 +1757,7 @@ static unsigned long get_segment_base(unsigned int segment)
14505 if (idx > GDT_ENTRIES)
14506 return 0;
14507
14508- desc = __this_cpu_ptr(&gdt_page.gdt[0]);
14509+ desc = get_cpu_gdt_table(smp_processor_id());
14510 }
14511
14512 return get_desc_base(desc + idx);
14513@@ -1847,7 +1847,7 @@ perf_callchain_user(struct perf_callchain_entry *entry, struct pt_regs *regs)
14514 break;
14515
14516 perf_callchain_store(entry, frame.return_address);
14517- fp = frame.next_frame;
14518+ fp = (const void __force_user *)frame.next_frame;
14519 }
14520 }
14521
14522diff --git a/arch/x86/kernel/cpu/perf_event_intel.c b/arch/x86/kernel/cpu/perf_event_intel.c
14523index 6bca492..36e4496 100644
14524--- a/arch/x86/kernel/cpu/perf_event_intel.c
14525+++ b/arch/x86/kernel/cpu/perf_event_intel.c
14526@@ -1947,10 +1947,10 @@ __init int intel_pmu_init(void)
14527 * v2 and above have a perf capabilities MSR
14528 */
14529 if (version > 1) {
14530- u64 capabilities;
14531+ u64 capabilities = x86_pmu.intel_cap.capabilities;
14532
14533- rdmsrl(MSR_IA32_PERF_CAPABILITIES, capabilities);
14534- x86_pmu.intel_cap.capabilities = capabilities;
14535+ if (rdmsrl_safe(MSR_IA32_PERF_CAPABILITIES, &x86_pmu.intel_cap.capabilities))
14536+ x86_pmu.intel_cap.capabilities = capabilities;
14537 }
14538
14539 intel_ds_init();
14540diff --git a/arch/x86/kernel/crash.c b/arch/x86/kernel/crash.c
14541index 13ad899..f642b9a 100644
14542--- a/arch/x86/kernel/crash.c
14543+++ b/arch/x86/kernel/crash.c
14544@@ -36,10 +36,8 @@ static void kdump_nmi_callback(int cpu, struct pt_regs *regs)
14545 {
14546 #ifdef CONFIG_X86_32
14547 struct pt_regs fixed_regs;
14548-#endif
14549
14550-#ifdef CONFIG_X86_32
14551- if (!user_mode_vm(regs)) {
14552+ if (!user_mode(regs)) {
14553 crash_fixup_ss_esp(&fixed_regs, regs);
14554 regs = &fixed_regs;
14555 }
14556diff --git a/arch/x86/kernel/doublefault_32.c b/arch/x86/kernel/doublefault_32.c
14557index 37250fe..bf2ec74 100644
14558--- a/arch/x86/kernel/doublefault_32.c
14559+++ b/arch/x86/kernel/doublefault_32.c
14560@@ -11,7 +11,7 @@
14561
14562 #define DOUBLEFAULT_STACKSIZE (1024)
14563 static unsigned long doublefault_stack[DOUBLEFAULT_STACKSIZE];
14564-#define STACK_START (unsigned long)(doublefault_stack+DOUBLEFAULT_STACKSIZE)
14565+#define STACK_START (unsigned long)(doublefault_stack+DOUBLEFAULT_STACKSIZE-2)
14566
14567 #define ptr_ok(x) ((x) > PAGE_OFFSET && (x) < PAGE_OFFSET + MAXMEM)
14568
14569@@ -21,7 +21,7 @@ static void doublefault_fn(void)
14570 unsigned long gdt, tss;
14571
14572 store_gdt(&gdt_desc);
14573- gdt = gdt_desc.address;
14574+ gdt = (unsigned long)gdt_desc.address;
14575
14576 printk(KERN_EMERG "PANIC: double fault, gdt at %08lx [%d bytes]\n", gdt, gdt_desc.size);
14577
14578@@ -58,10 +58,10 @@ struct tss_struct doublefault_tss __cacheline_aligned = {
14579 /* 0x2 bit is always set */
14580 .flags = X86_EFLAGS_SF | 0x2,
14581 .sp = STACK_START,
14582- .es = __USER_DS,
14583+ .es = __KERNEL_DS,
14584 .cs = __KERNEL_CS,
14585 .ss = __KERNEL_DS,
14586- .ds = __USER_DS,
14587+ .ds = __KERNEL_DS,
14588 .fs = __KERNEL_PERCPU,
14589
14590 .__cr3 = __pa_nodebug(swapper_pg_dir),
14591diff --git a/arch/x86/kernel/dumpstack.c b/arch/x86/kernel/dumpstack.c
14592index ae42418b..787c16b 100644
14593--- a/arch/x86/kernel/dumpstack.c
14594+++ b/arch/x86/kernel/dumpstack.c
14595@@ -2,6 +2,9 @@
14596 * Copyright (C) 1991, 1992 Linus Torvalds
14597 * Copyright (C) 2000, 2001, 2002 Andi Kleen, SuSE Labs
14598 */
14599+#ifdef CONFIG_GRKERNSEC_HIDESYM
14600+#define __INCLUDED_BY_HIDESYM 1
14601+#endif
14602 #include <linux/kallsyms.h>
14603 #include <linux/kprobes.h>
14604 #include <linux/uaccess.h>
14605@@ -35,16 +38,14 @@ void printk_address(unsigned long address, int reliable)
14606 static void
14607 print_ftrace_graph_addr(unsigned long addr, void *data,
14608 const struct stacktrace_ops *ops,
14609- struct thread_info *tinfo, int *graph)
14610+ struct task_struct *task, int *graph)
14611 {
14612- struct task_struct *task;
14613 unsigned long ret_addr;
14614 int index;
14615
14616 if (addr != (unsigned long)return_to_handler)
14617 return;
14618
14619- task = tinfo->task;
14620 index = task->curr_ret_stack;
14621
14622 if (!task->ret_stack || index < *graph)
14623@@ -61,7 +62,7 @@ print_ftrace_graph_addr(unsigned long addr, void *data,
14624 static inline void
14625 print_ftrace_graph_addr(unsigned long addr, void *data,
14626 const struct stacktrace_ops *ops,
14627- struct thread_info *tinfo, int *graph)
14628+ struct task_struct *task, int *graph)
14629 { }
14630 #endif
14631
14632@@ -72,10 +73,8 @@ print_ftrace_graph_addr(unsigned long addr, void *data,
14633 * severe exception (double fault, nmi, stack fault, debug, mce) hardware stack
14634 */
14635
14636-static inline int valid_stack_ptr(struct thread_info *tinfo,
14637- void *p, unsigned int size, void *end)
14638+static inline int valid_stack_ptr(void *t, void *p, unsigned int size, void *end)
14639 {
14640- void *t = tinfo;
14641 if (end) {
14642 if (p < end && p >= (end-THREAD_SIZE))
14643 return 1;
14644@@ -86,14 +85,14 @@ static inline int valid_stack_ptr(struct thread_info *tinfo,
14645 }
14646
14647 unsigned long
14648-print_context_stack(struct thread_info *tinfo,
14649+print_context_stack(struct task_struct *task, void *stack_start,
14650 unsigned long *stack, unsigned long bp,
14651 const struct stacktrace_ops *ops, void *data,
14652 unsigned long *end, int *graph)
14653 {
14654 struct stack_frame *frame = (struct stack_frame *)bp;
14655
14656- while (valid_stack_ptr(tinfo, stack, sizeof(*stack), end)) {
14657+ while (valid_stack_ptr(stack_start, stack, sizeof(*stack), end)) {
14658 unsigned long addr;
14659
14660 addr = *stack;
14661@@ -105,7 +104,7 @@ print_context_stack(struct thread_info *tinfo,
14662 } else {
14663 ops->address(data, addr, 0);
14664 }
14665- print_ftrace_graph_addr(addr, data, ops, tinfo, graph);
14666+ print_ftrace_graph_addr(addr, data, ops, task, graph);
14667 }
14668 stack++;
14669 }
14670@@ -114,7 +113,7 @@ print_context_stack(struct thread_info *tinfo,
14671 EXPORT_SYMBOL_GPL(print_context_stack);
14672
14673 unsigned long
14674-print_context_stack_bp(struct thread_info *tinfo,
14675+print_context_stack_bp(struct task_struct *task, void *stack_start,
14676 unsigned long *stack, unsigned long bp,
14677 const struct stacktrace_ops *ops, void *data,
14678 unsigned long *end, int *graph)
14679@@ -122,7 +121,7 @@ print_context_stack_bp(struct thread_info *tinfo,
14680 struct stack_frame *frame = (struct stack_frame *)bp;
14681 unsigned long *ret_addr = &frame->return_address;
14682
14683- while (valid_stack_ptr(tinfo, ret_addr, sizeof(*ret_addr), end)) {
14684+ while (valid_stack_ptr(stack_start, ret_addr, sizeof(*ret_addr), end)) {
14685 unsigned long addr = *ret_addr;
14686
14687 if (!__kernel_text_address(addr))
14688@@ -131,7 +130,7 @@ print_context_stack_bp(struct thread_info *tinfo,
14689 ops->address(data, addr, 1);
14690 frame = frame->next_frame;
14691 ret_addr = &frame->return_address;
14692- print_ftrace_graph_addr(addr, data, ops, tinfo, graph);
14693+ print_ftrace_graph_addr(addr, data, ops, task, graph);
14694 }
14695
14696 return (unsigned long)frame;
14697@@ -189,7 +188,7 @@ void dump_stack(void)
14698
14699 bp = stack_frame(current, NULL);
14700 printk("Pid: %d, comm: %.20s %s %s %.*s\n",
14701- current->pid, current->comm, print_tainted(),
14702+ task_pid_nr(current), current->comm, print_tainted(),
14703 init_utsname()->release,
14704 (int)strcspn(init_utsname()->version, " "),
14705 init_utsname()->version);
14706@@ -225,6 +224,8 @@ unsigned __kprobes long oops_begin(void)
14707 }
14708 EXPORT_SYMBOL_GPL(oops_begin);
14709
14710+extern void gr_handle_kernel_exploit(void);
14711+
14712 void __kprobes oops_end(unsigned long flags, struct pt_regs *regs, int signr)
14713 {
14714 if (regs && kexec_should_crash(current))
14715@@ -246,7 +247,10 @@ void __kprobes oops_end(unsigned long flags, struct pt_regs *regs, int signr)
14716 panic("Fatal exception in interrupt");
14717 if (panic_on_oops)
14718 panic("Fatal exception");
14719- do_exit(signr);
14720+
14721+ gr_handle_kernel_exploit();
14722+
14723+ do_group_exit(signr);
14724 }
14725
14726 int __kprobes __die(const char *str, struct pt_regs *regs, long err)
14727@@ -274,7 +278,7 @@ int __kprobes __die(const char *str, struct pt_regs *regs, long err)
14728 print_modules();
14729 show_regs(regs);
14730 #ifdef CONFIG_X86_32
14731- if (user_mode_vm(regs)) {
14732+ if (user_mode(regs)) {
14733 sp = regs->sp;
14734 ss = regs->ss & 0xffff;
14735 } else {
14736@@ -302,7 +306,7 @@ void die(const char *str, struct pt_regs *regs, long err)
14737 unsigned long flags = oops_begin();
14738 int sig = SIGSEGV;
14739
14740- if (!user_mode_vm(regs))
14741+ if (!user_mode(regs))
14742 report_bug(regs->ip, regs);
14743
14744 if (__die(str, regs, err))
14745diff --git a/arch/x86/kernel/dumpstack_32.c b/arch/x86/kernel/dumpstack_32.c
14746index 1038a41..ac7e5f6 100644
14747--- a/arch/x86/kernel/dumpstack_32.c
14748+++ b/arch/x86/kernel/dumpstack_32.c
14749@@ -38,15 +38,13 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
14750 bp = stack_frame(task, regs);
14751
14752 for (;;) {
14753- struct thread_info *context;
14754+ void *stack_start = (void *)((unsigned long)stack & ~(THREAD_SIZE-1));
14755
14756- context = (struct thread_info *)
14757- ((unsigned long)stack & (~(THREAD_SIZE - 1)));
14758- bp = ops->walk_stack(context, stack, bp, ops, data, NULL, &graph);
14759+ bp = ops->walk_stack(task, stack_start, stack, bp, ops, data, NULL, &graph);
14760
14761- stack = (unsigned long *)context->previous_esp;
14762- if (!stack)
14763+ if (stack_start == task_stack_page(task))
14764 break;
14765+ stack = *(unsigned long **)stack_start;
14766 if (ops->stack(data, "IRQ") < 0)
14767 break;
14768 touch_nmi_watchdog();
14769@@ -86,7 +84,7 @@ void show_regs(struct pt_regs *regs)
14770 {
14771 int i;
14772
14773- __show_regs(regs, !user_mode_vm(regs));
14774+ __show_regs(regs, !user_mode(regs));
14775
14776 pr_emerg("Process %.*s (pid: %d, ti=%p task=%p task.ti=%p)\n",
14777 TASK_COMM_LEN, current->comm, task_pid_nr(current),
14778@@ -95,21 +93,22 @@ void show_regs(struct pt_regs *regs)
14779 * When in-kernel, we also print out the stack and code at the
14780 * time of the fault..
14781 */
14782- if (!user_mode_vm(regs)) {
14783+ if (!user_mode(regs)) {
14784 unsigned int code_prologue = code_bytes * 43 / 64;
14785 unsigned int code_len = code_bytes;
14786 unsigned char c;
14787 u8 *ip;
14788+ unsigned long cs_base = get_desc_base(&get_cpu_gdt_table(smp_processor_id())[(0xffff & regs->cs) >> 3]);
14789
14790 pr_emerg("Stack:\n");
14791 show_stack_log_lvl(NULL, regs, &regs->sp, 0, KERN_EMERG);
14792
14793 pr_emerg("Code:");
14794
14795- ip = (u8 *)regs->ip - code_prologue;
14796+ ip = (u8 *)regs->ip - code_prologue + cs_base;
14797 if (ip < (u8 *)PAGE_OFFSET || probe_kernel_address(ip, c)) {
14798 /* try starting at IP */
14799- ip = (u8 *)regs->ip;
14800+ ip = (u8 *)regs->ip + cs_base;
14801 code_len = code_len - code_prologue + 1;
14802 }
14803 for (i = 0; i < code_len; i++, ip++) {
14804@@ -118,7 +117,7 @@ void show_regs(struct pt_regs *regs)
14805 pr_cont(" Bad EIP value.");
14806 break;
14807 }
14808- if (ip == (u8 *)regs->ip)
14809+ if (ip == (u8 *)regs->ip + cs_base)
14810 pr_cont(" <%02x>", c);
14811 else
14812 pr_cont(" %02x", c);
14813@@ -131,6 +130,7 @@ int is_valid_bugaddr(unsigned long ip)
14814 {
14815 unsigned short ud2;
14816
14817+ ip = ktla_ktva(ip);
14818 if (ip < PAGE_OFFSET)
14819 return 0;
14820 if (probe_kernel_address((unsigned short *)ip, ud2))
14821@@ -138,3 +138,15 @@ int is_valid_bugaddr(unsigned long ip)
14822
14823 return ud2 == 0x0b0f;
14824 }
14825+
14826+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
14827+void pax_check_alloca(unsigned long size)
14828+{
14829+ unsigned long sp = (unsigned long)&sp, stack_left;
14830+
14831+ /* all kernel stacks are of the same size */
14832+ stack_left = sp & (THREAD_SIZE - 1);
14833+ BUG_ON(stack_left < 256 || size >= stack_left - 256);
14834+}
14835+EXPORT_SYMBOL(pax_check_alloca);
14836+#endif
14837diff --git a/arch/x86/kernel/dumpstack_64.c b/arch/x86/kernel/dumpstack_64.c
14838index b653675..33190c0 100644
14839--- a/arch/x86/kernel/dumpstack_64.c
14840+++ b/arch/x86/kernel/dumpstack_64.c
14841@@ -119,9 +119,9 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
14842 unsigned long *irq_stack_end =
14843 (unsigned long *)per_cpu(irq_stack_ptr, cpu);
14844 unsigned used = 0;
14845- struct thread_info *tinfo;
14846 int graph = 0;
14847 unsigned long dummy;
14848+ void *stack_start;
14849
14850 if (!task)
14851 task = current;
14852@@ -142,10 +142,10 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
14853 * current stack address. If the stacks consist of nested
14854 * exceptions
14855 */
14856- tinfo = task_thread_info(task);
14857 for (;;) {
14858 char *id;
14859 unsigned long *estack_end;
14860+
14861 estack_end = in_exception_stack(cpu, (unsigned long)stack,
14862 &used, &id);
14863
14864@@ -153,7 +153,7 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
14865 if (ops->stack(data, id) < 0)
14866 break;
14867
14868- bp = ops->walk_stack(tinfo, stack, bp, ops,
14869+ bp = ops->walk_stack(task, estack_end - EXCEPTION_STKSZ, stack, bp, ops,
14870 data, estack_end, &graph);
14871 ops->stack(data, "<EOE>");
14872 /*
14873@@ -161,6 +161,8 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
14874 * second-to-last pointer (index -2 to end) in the
14875 * exception stack:
14876 */
14877+ if ((u16)estack_end[-1] != __KERNEL_DS)
14878+ goto out;
14879 stack = (unsigned long *) estack_end[-2];
14880 continue;
14881 }
14882@@ -172,7 +174,7 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
14883 if (in_irq_stack(stack, irq_stack, irq_stack_end)) {
14884 if (ops->stack(data, "IRQ") < 0)
14885 break;
14886- bp = ops->walk_stack(tinfo, stack, bp,
14887+ bp = ops->walk_stack(task, irq_stack, stack, bp,
14888 ops, data, irq_stack_end, &graph);
14889 /*
14890 * We link to the next stack (which would be
14891@@ -191,7 +193,9 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
14892 /*
14893 * This handles the process stack:
14894 */
14895- bp = ops->walk_stack(tinfo, stack, bp, ops, data, NULL, &graph);
14896+ stack_start = (void *)((unsigned long)stack & ~(THREAD_SIZE-1));
14897+ bp = ops->walk_stack(task, stack_start, stack, bp, ops, data, NULL, &graph);
14898+out:
14899 put_cpu();
14900 }
14901 EXPORT_SYMBOL(dump_trace);
14902@@ -304,3 +308,50 @@ int is_valid_bugaddr(unsigned long ip)
14903
14904 return ud2 == 0x0b0f;
14905 }
14906+
14907+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
14908+void pax_check_alloca(unsigned long size)
14909+{
14910+ unsigned long sp = (unsigned long)&sp, stack_start, stack_end;
14911+ unsigned cpu, used;
14912+ char *id;
14913+
14914+ /* check the process stack first */
14915+ stack_start = (unsigned long)task_stack_page(current);
14916+ stack_end = stack_start + THREAD_SIZE;
14917+ if (likely(stack_start <= sp && sp < stack_end)) {
14918+ unsigned long stack_left = sp & (THREAD_SIZE - 1);
14919+ BUG_ON(stack_left < 256 || size >= stack_left - 256);
14920+ return;
14921+ }
14922+
14923+ cpu = get_cpu();
14924+
14925+ /* check the irq stacks */
14926+ stack_end = (unsigned long)per_cpu(irq_stack_ptr, cpu);
14927+ stack_start = stack_end - IRQ_STACK_SIZE;
14928+ if (stack_start <= sp && sp < stack_end) {
14929+ unsigned long stack_left = sp & (IRQ_STACK_SIZE - 1);
14930+ put_cpu();
14931+ BUG_ON(stack_left < 256 || size >= stack_left - 256);
14932+ return;
14933+ }
14934+
14935+ /* check the exception stacks */
14936+ used = 0;
14937+ stack_end = (unsigned long)in_exception_stack(cpu, sp, &used, &id);
14938+ stack_start = stack_end - EXCEPTION_STKSZ;
14939+ if (stack_end && stack_start <= sp && sp < stack_end) {
14940+ unsigned long stack_left = sp & (EXCEPTION_STKSZ - 1);
14941+ put_cpu();
14942+ BUG_ON(stack_left < 256 || size >= stack_left - 256);
14943+ return;
14944+ }
14945+
14946+ put_cpu();
14947+
14948+ /* unknown stack */
14949+ BUG();
14950+}
14951+EXPORT_SYMBOL(pax_check_alloca);
14952+#endif
14953diff --git a/arch/x86/kernel/early_printk.c b/arch/x86/kernel/early_printk.c
14954index 9b9f18b..9fcaa04 100644
14955--- a/arch/x86/kernel/early_printk.c
14956+++ b/arch/x86/kernel/early_printk.c
14957@@ -7,6 +7,7 @@
14958 #include <linux/pci_regs.h>
14959 #include <linux/pci_ids.h>
14960 #include <linux/errno.h>
14961+#include <linux/sched.h>
14962 #include <asm/io.h>
14963 #include <asm/processor.h>
14964 #include <asm/fcntl.h>
14965diff --git a/arch/x86/kernel/entry_32.S b/arch/x86/kernel/entry_32.S
14966index 8f8e8ee..3617d6e 100644
14967--- a/arch/x86/kernel/entry_32.S
14968+++ b/arch/x86/kernel/entry_32.S
14969@@ -176,13 +176,153 @@
14970 /*CFI_REL_OFFSET gs, PT_GS*/
14971 .endm
14972 .macro SET_KERNEL_GS reg
14973+
14974+#ifdef CONFIG_CC_STACKPROTECTOR
14975 movl $(__KERNEL_STACK_CANARY), \reg
14976+#elif defined(CONFIG_PAX_MEMORY_UDEREF)
14977+ movl $(__USER_DS), \reg
14978+#else
14979+ xorl \reg, \reg
14980+#endif
14981+
14982 movl \reg, %gs
14983 .endm
14984
14985 #endif /* CONFIG_X86_32_LAZY_GS */
14986
14987-.macro SAVE_ALL
14988+.macro pax_enter_kernel
14989+#ifdef CONFIG_PAX_KERNEXEC
14990+ call pax_enter_kernel
14991+#endif
14992+.endm
14993+
14994+.macro pax_exit_kernel
14995+#ifdef CONFIG_PAX_KERNEXEC
14996+ call pax_exit_kernel
14997+#endif
14998+.endm
14999+
15000+#ifdef CONFIG_PAX_KERNEXEC
15001+ENTRY(pax_enter_kernel)
15002+#ifdef CONFIG_PARAVIRT
15003+ pushl %eax
15004+ pushl %ecx
15005+ call PARA_INDIRECT(pv_cpu_ops+PV_CPU_read_cr0)
15006+ mov %eax, %esi
15007+#else
15008+ mov %cr0, %esi
15009+#endif
15010+ bts $16, %esi
15011+ jnc 1f
15012+ mov %cs, %esi
15013+ cmp $__KERNEL_CS, %esi
15014+ jz 3f
15015+ ljmp $__KERNEL_CS, $3f
15016+1: ljmp $__KERNEXEC_KERNEL_CS, $2f
15017+2:
15018+#ifdef CONFIG_PARAVIRT
15019+ mov %esi, %eax
15020+ call PARA_INDIRECT(pv_cpu_ops+PV_CPU_write_cr0)
15021+#else
15022+ mov %esi, %cr0
15023+#endif
15024+3:
15025+#ifdef CONFIG_PARAVIRT
15026+ popl %ecx
15027+ popl %eax
15028+#endif
15029+ ret
15030+ENDPROC(pax_enter_kernel)
15031+
15032+ENTRY(pax_exit_kernel)
15033+#ifdef CONFIG_PARAVIRT
15034+ pushl %eax
15035+ pushl %ecx
15036+#endif
15037+ mov %cs, %esi
15038+ cmp $__KERNEXEC_KERNEL_CS, %esi
15039+ jnz 2f
15040+#ifdef CONFIG_PARAVIRT
15041+ call PARA_INDIRECT(pv_cpu_ops+PV_CPU_read_cr0);
15042+ mov %eax, %esi
15043+#else
15044+ mov %cr0, %esi
15045+#endif
15046+ btr $16, %esi
15047+ ljmp $__KERNEL_CS, $1f
15048+1:
15049+#ifdef CONFIG_PARAVIRT
15050+ mov %esi, %eax
15051+ call PARA_INDIRECT(pv_cpu_ops+PV_CPU_write_cr0);
15052+#else
15053+ mov %esi, %cr0
15054+#endif
15055+2:
15056+#ifdef CONFIG_PARAVIRT
15057+ popl %ecx
15058+ popl %eax
15059+#endif
15060+ ret
15061+ENDPROC(pax_exit_kernel)
15062+#endif
15063+
15064+.macro pax_erase_kstack
15065+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
15066+ call pax_erase_kstack
15067+#endif
15068+.endm
15069+
15070+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
15071+/*
15072+ * ebp: thread_info
15073+ */
15074+ENTRY(pax_erase_kstack)
15075+ pushl %edi
15076+ pushl %ecx
15077+ pushl %eax
15078+
15079+ mov TI_lowest_stack(%ebp), %edi
15080+ mov $-0xBEEF, %eax
15081+ std
15082+
15083+1: mov %edi, %ecx
15084+ and $THREAD_SIZE_asm - 1, %ecx
15085+ shr $2, %ecx
15086+ repne scasl
15087+ jecxz 2f
15088+
15089+ cmp $2*16, %ecx
15090+ jc 2f
15091+
15092+ mov $2*16, %ecx
15093+ repe scasl
15094+ jecxz 2f
15095+ jne 1b
15096+
15097+2: cld
15098+ mov %esp, %ecx
15099+ sub %edi, %ecx
15100+
15101+ cmp $THREAD_SIZE_asm, %ecx
15102+ jb 3f
15103+ ud2
15104+3:
15105+
15106+ shr $2, %ecx
15107+ rep stosl
15108+
15109+ mov TI_task_thread_sp0(%ebp), %edi
15110+ sub $128, %edi
15111+ mov %edi, TI_lowest_stack(%ebp)
15112+
15113+ popl %eax
15114+ popl %ecx
15115+ popl %edi
15116+ ret
15117+ENDPROC(pax_erase_kstack)
15118+#endif
15119+
15120+.macro __SAVE_ALL _DS
15121 cld
15122 PUSH_GS
15123 pushl_cfi %fs
15124@@ -205,7 +345,7 @@
15125 CFI_REL_OFFSET ecx, 0
15126 pushl_cfi %ebx
15127 CFI_REL_OFFSET ebx, 0
15128- movl $(__USER_DS), %edx
15129+ movl $\_DS, %edx
15130 movl %edx, %ds
15131 movl %edx, %es
15132 movl $(__KERNEL_PERCPU), %edx
15133@@ -213,6 +353,15 @@
15134 SET_KERNEL_GS %edx
15135 .endm
15136
15137+.macro SAVE_ALL
15138+#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
15139+ __SAVE_ALL __KERNEL_DS
15140+ pax_enter_kernel
15141+#else
15142+ __SAVE_ALL __USER_DS
15143+#endif
15144+.endm
15145+
15146 .macro RESTORE_INT_REGS
15147 popl_cfi %ebx
15148 CFI_RESTORE ebx
15149@@ -296,7 +445,7 @@ ENTRY(ret_from_fork)
15150 popfl_cfi
15151 jmp syscall_exit
15152 CFI_ENDPROC
15153-END(ret_from_fork)
15154+ENDPROC(ret_from_fork)
15155
15156 /*
15157 * Interrupt exit functions should be protected against kprobes
15158@@ -329,7 +478,15 @@ ret_from_intr:
15159 andl $SEGMENT_RPL_MASK, %eax
15160 #endif
15161 cmpl $USER_RPL, %eax
15162+
15163+#ifdef CONFIG_PAX_KERNEXEC
15164+ jae resume_userspace
15165+
15166+ pax_exit_kernel
15167+ jmp resume_kernel
15168+#else
15169 jb resume_kernel # not returning to v8086 or userspace
15170+#endif
15171
15172 ENTRY(resume_userspace)
15173 LOCKDEP_SYS_EXIT
15174@@ -341,8 +498,8 @@ ENTRY(resume_userspace)
15175 andl $_TIF_WORK_MASK, %ecx # is there any work to be done on
15176 # int/exception return?
15177 jne work_pending
15178- jmp restore_all
15179-END(ret_from_exception)
15180+ jmp restore_all_pax
15181+ENDPROC(ret_from_exception)
15182
15183 #ifdef CONFIG_PREEMPT
15184 ENTRY(resume_kernel)
15185@@ -357,7 +514,7 @@ need_resched:
15186 jz restore_all
15187 call preempt_schedule_irq
15188 jmp need_resched
15189-END(resume_kernel)
15190+ENDPROC(resume_kernel)
15191 #endif
15192 CFI_ENDPROC
15193 /*
15194@@ -391,28 +548,43 @@ sysenter_past_esp:
15195 /*CFI_REL_OFFSET cs, 0*/
15196 /*
15197 * Push current_thread_info()->sysenter_return to the stack.
15198- * A tiny bit of offset fixup is necessary - 4*4 means the 4 words
15199- * pushed above; +8 corresponds to copy_thread's esp0 setting.
15200 */
15201- pushl_cfi ((TI_sysenter_return)-THREAD_SIZE+8+4*4)(%esp)
15202+ pushl_cfi $0
15203 CFI_REL_OFFSET eip, 0
15204
15205 pushl_cfi %eax
15206 SAVE_ALL
15207+ GET_THREAD_INFO(%ebp)
15208+ movl TI_sysenter_return(%ebp),%ebp
15209+ movl %ebp,PT_EIP(%esp)
15210 ENABLE_INTERRUPTS(CLBR_NONE)
15211
15212 /*
15213 * Load the potential sixth argument from user stack.
15214 * Careful about security.
15215 */
15216+ movl PT_OLDESP(%esp),%ebp
15217+
15218+#ifdef CONFIG_PAX_MEMORY_UDEREF
15219+ mov PT_OLDSS(%esp),%ds
15220+1: movl %ds:(%ebp),%ebp
15221+ push %ss
15222+ pop %ds
15223+#else
15224 cmpl $__PAGE_OFFSET-3,%ebp
15225 jae syscall_fault
15226 1: movl (%ebp),%ebp
15227+#endif
15228+
15229 movl %ebp,PT_EBP(%esp)
15230 _ASM_EXTABLE(1b,syscall_fault)
15231
15232 GET_THREAD_INFO(%ebp)
15233
15234+#ifdef CONFIG_PAX_RANDKSTACK
15235+ pax_erase_kstack
15236+#endif
15237+
15238 testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%ebp)
15239 jnz sysenter_audit
15240 sysenter_do_call:
15241@@ -427,12 +599,24 @@ sysenter_do_call:
15242 testl $_TIF_ALLWORK_MASK, %ecx
15243 jne sysexit_audit
15244 sysenter_exit:
15245+
15246+#ifdef CONFIG_PAX_RANDKSTACK
15247+ pushl_cfi %eax
15248+ movl %esp, %eax
15249+ call pax_randomize_kstack
15250+ popl_cfi %eax
15251+#endif
15252+
15253+ pax_erase_kstack
15254+
15255 /* if something modifies registers it must also disable sysexit */
15256 movl PT_EIP(%esp), %edx
15257 movl PT_OLDESP(%esp), %ecx
15258 xorl %ebp,%ebp
15259 TRACE_IRQS_ON
15260 1: mov PT_FS(%esp), %fs
15261+2: mov PT_DS(%esp), %ds
15262+3: mov PT_ES(%esp), %es
15263 PTGS_TO_GS
15264 ENABLE_INTERRUPTS_SYSEXIT
15265
15266@@ -449,6 +633,9 @@ sysenter_audit:
15267 movl %eax,%edx /* 2nd arg: syscall number */
15268 movl $AUDIT_ARCH_I386,%eax /* 1st arg: audit arch */
15269 call __audit_syscall_entry
15270+
15271+ pax_erase_kstack
15272+
15273 pushl_cfi %ebx
15274 movl PT_EAX(%esp),%eax /* reload syscall number */
15275 jmp sysenter_do_call
15276@@ -474,10 +661,16 @@ sysexit_audit:
15277
15278 CFI_ENDPROC
15279 .pushsection .fixup,"ax"
15280-2: movl $0,PT_FS(%esp)
15281+4: movl $0,PT_FS(%esp)
15282+ jmp 1b
15283+5: movl $0,PT_DS(%esp)
15284+ jmp 1b
15285+6: movl $0,PT_ES(%esp)
15286 jmp 1b
15287 .popsection
15288- _ASM_EXTABLE(1b,2b)
15289+ _ASM_EXTABLE(1b,4b)
15290+ _ASM_EXTABLE(2b,5b)
15291+ _ASM_EXTABLE(3b,6b)
15292 PTGS_TO_GS_EX
15293 ENDPROC(ia32_sysenter_target)
15294
15295@@ -491,6 +684,11 @@ ENTRY(system_call)
15296 pushl_cfi %eax # save orig_eax
15297 SAVE_ALL
15298 GET_THREAD_INFO(%ebp)
15299+
15300+#ifdef CONFIG_PAX_RANDKSTACK
15301+ pax_erase_kstack
15302+#endif
15303+
15304 # system call tracing in operation / emulation
15305 testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%ebp)
15306 jnz syscall_trace_entry
15307@@ -509,6 +707,15 @@ syscall_exit:
15308 testl $_TIF_ALLWORK_MASK, %ecx # current->work
15309 jne syscall_exit_work
15310
15311+restore_all_pax:
15312+
15313+#ifdef CONFIG_PAX_RANDKSTACK
15314+ movl %esp, %eax
15315+ call pax_randomize_kstack
15316+#endif
15317+
15318+ pax_erase_kstack
15319+
15320 restore_all:
15321 TRACE_IRQS_IRET
15322 restore_all_notrace:
15323@@ -565,14 +772,34 @@ ldt_ss:
15324 * compensating for the offset by changing to the ESPFIX segment with
15325 * a base address that matches for the difference.
15326 */
15327-#define GDT_ESPFIX_SS PER_CPU_VAR(gdt_page) + (GDT_ENTRY_ESPFIX_SS * 8)
15328+#define GDT_ESPFIX_SS (GDT_ENTRY_ESPFIX_SS * 8)(%ebx)
15329 mov %esp, %edx /* load kernel esp */
15330 mov PT_OLDESP(%esp), %eax /* load userspace esp */
15331 mov %dx, %ax /* eax: new kernel esp */
15332 sub %eax, %edx /* offset (low word is 0) */
15333+#ifdef CONFIG_SMP
15334+ movl PER_CPU_VAR(cpu_number), %ebx
15335+ shll $PAGE_SHIFT_asm, %ebx
15336+ addl $cpu_gdt_table, %ebx
15337+#else
15338+ movl $cpu_gdt_table, %ebx
15339+#endif
15340 shr $16, %edx
15341- mov %dl, GDT_ESPFIX_SS + 4 /* bits 16..23 */
15342- mov %dh, GDT_ESPFIX_SS + 7 /* bits 24..31 */
15343+
15344+#ifdef CONFIG_PAX_KERNEXEC
15345+ mov %cr0, %esi
15346+ btr $16, %esi
15347+ mov %esi, %cr0
15348+#endif
15349+
15350+ mov %dl, 4 + GDT_ESPFIX_SS /* bits 16..23 */
15351+ mov %dh, 7 + GDT_ESPFIX_SS /* bits 24..31 */
15352+
15353+#ifdef CONFIG_PAX_KERNEXEC
15354+ bts $16, %esi
15355+ mov %esi, %cr0
15356+#endif
15357+
15358 pushl_cfi $__ESPFIX_SS
15359 pushl_cfi %eax /* new kernel esp */
15360 /* Disable interrupts, but do not irqtrace this section: we
15361@@ -601,35 +828,23 @@ work_resched:
15362 movl TI_flags(%ebp), %ecx
15363 andl $_TIF_WORK_MASK, %ecx # is there any work to be done other
15364 # than syscall tracing?
15365- jz restore_all
15366+ jz restore_all_pax
15367 testb $_TIF_NEED_RESCHED, %cl
15368 jnz work_resched
15369
15370 work_notifysig: # deal with pending signals and
15371 # notify-resume requests
15372+ movl %esp, %eax
15373 #ifdef CONFIG_VM86
15374 testl $X86_EFLAGS_VM, PT_EFLAGS(%esp)
15375- movl %esp, %eax
15376- jne work_notifysig_v86 # returning to kernel-space or
15377+ jz 1f # returning to kernel-space or
15378 # vm86-space
15379- TRACE_IRQS_ON
15380- ENABLE_INTERRUPTS(CLBR_NONE)
15381- movb PT_CS(%esp), %bl
15382- andb $SEGMENT_RPL_MASK, %bl
15383- cmpb $USER_RPL, %bl
15384- jb resume_kernel
15385- xorl %edx, %edx
15386- call do_notify_resume
15387- jmp resume_userspace
15388
15389- ALIGN
15390-work_notifysig_v86:
15391 pushl_cfi %ecx # save ti_flags for do_notify_resume
15392 call save_v86_state # %eax contains pt_regs pointer
15393 popl_cfi %ecx
15394 movl %eax, %esp
15395-#else
15396- movl %esp, %eax
15397+1:
15398 #endif
15399 TRACE_IRQS_ON
15400 ENABLE_INTERRUPTS(CLBR_NONE)
15401@@ -640,7 +855,7 @@ work_notifysig_v86:
15402 xorl %edx, %edx
15403 call do_notify_resume
15404 jmp resume_userspace
15405-END(work_pending)
15406+ENDPROC(work_pending)
15407
15408 # perform syscall exit tracing
15409 ALIGN
15410@@ -648,11 +863,14 @@ syscall_trace_entry:
15411 movl $-ENOSYS,PT_EAX(%esp)
15412 movl %esp, %eax
15413 call syscall_trace_enter
15414+
15415+ pax_erase_kstack
15416+
15417 /* What it returned is what we'll actually use. */
15418 cmpl $(NR_syscalls), %eax
15419 jnae syscall_call
15420 jmp syscall_exit
15421-END(syscall_trace_entry)
15422+ENDPROC(syscall_trace_entry)
15423
15424 # perform syscall exit tracing
15425 ALIGN
15426@@ -665,20 +883,24 @@ syscall_exit_work:
15427 movl %esp, %eax
15428 call syscall_trace_leave
15429 jmp resume_userspace
15430-END(syscall_exit_work)
15431+ENDPROC(syscall_exit_work)
15432 CFI_ENDPROC
15433
15434 RING0_INT_FRAME # can't unwind into user space anyway
15435 syscall_fault:
15436+#ifdef CONFIG_PAX_MEMORY_UDEREF
15437+ push %ss
15438+ pop %ds
15439+#endif
15440 GET_THREAD_INFO(%ebp)
15441 movl $-EFAULT,PT_EAX(%esp)
15442 jmp resume_userspace
15443-END(syscall_fault)
15444+ENDPROC(syscall_fault)
15445
15446 syscall_badsys:
15447 movl $-ENOSYS,PT_EAX(%esp)
15448 jmp resume_userspace
15449-END(syscall_badsys)
15450+ENDPROC(syscall_badsys)
15451 CFI_ENDPROC
15452 /*
15453 * End of kprobes section
15454@@ -750,6 +972,36 @@ ENTRY(ptregs_clone)
15455 CFI_ENDPROC
15456 ENDPROC(ptregs_clone)
15457
15458+ ALIGN;
15459+ENTRY(kernel_execve)
15460+ CFI_STARTPROC
15461+ pushl_cfi %ebp
15462+ sub $PT_OLDSS+4,%esp
15463+ pushl_cfi %edi
15464+ pushl_cfi %ecx
15465+ pushl_cfi %eax
15466+ lea 3*4(%esp),%edi
15467+ mov $PT_OLDSS/4+1,%ecx
15468+ xorl %eax,%eax
15469+ rep stosl
15470+ popl_cfi %eax
15471+ popl_cfi %ecx
15472+ popl_cfi %edi
15473+ movl $X86_EFLAGS_IF,PT_EFLAGS(%esp)
15474+ pushl_cfi %esp
15475+ call sys_execve
15476+ add $4,%esp
15477+ CFI_ADJUST_CFA_OFFSET -4
15478+ GET_THREAD_INFO(%ebp)
15479+ test %eax,%eax
15480+ jz syscall_exit
15481+ add $PT_OLDSS+4,%esp
15482+ CFI_ADJUST_CFA_OFFSET -PT_OLDSS-4
15483+ popl_cfi %ebp
15484+ ret
15485+ CFI_ENDPROC
15486+ENDPROC(kernel_execve)
15487+
15488 .macro FIXUP_ESPFIX_STACK
15489 /*
15490 * Switch back for ESPFIX stack to the normal zerobased stack
15491@@ -759,8 +1011,15 @@ ENDPROC(ptregs_clone)
15492 * normal stack and adjusts ESP with the matching offset.
15493 */
15494 /* fixup the stack */
15495- mov GDT_ESPFIX_SS + 4, %al /* bits 16..23 */
15496- mov GDT_ESPFIX_SS + 7, %ah /* bits 24..31 */
15497+#ifdef CONFIG_SMP
15498+ movl PER_CPU_VAR(cpu_number), %ebx
15499+ shll $PAGE_SHIFT_asm, %ebx
15500+ addl $cpu_gdt_table, %ebx
15501+#else
15502+ movl $cpu_gdt_table, %ebx
15503+#endif
15504+ mov 4 + GDT_ESPFIX_SS, %al /* bits 16..23 */
15505+ mov 7 + GDT_ESPFIX_SS, %ah /* bits 24..31 */
15506 shl $16, %eax
15507 addl %esp, %eax /* the adjusted stack pointer */
15508 pushl_cfi $__KERNEL_DS
15509@@ -813,7 +1072,7 @@ vector=vector+1
15510 .endr
15511 2: jmp common_interrupt
15512 .endr
15513-END(irq_entries_start)
15514+ENDPROC(irq_entries_start)
15515
15516 .previous
15517 END(interrupt)
15518@@ -861,7 +1120,7 @@ ENTRY(coprocessor_error)
15519 pushl_cfi $do_coprocessor_error
15520 jmp error_code
15521 CFI_ENDPROC
15522-END(coprocessor_error)
15523+ENDPROC(coprocessor_error)
15524
15525 ENTRY(simd_coprocessor_error)
15526 RING0_INT_FRAME
15527@@ -882,7 +1141,7 @@ ENTRY(simd_coprocessor_error)
15528 #endif
15529 jmp error_code
15530 CFI_ENDPROC
15531-END(simd_coprocessor_error)
15532+ENDPROC(simd_coprocessor_error)
15533
15534 ENTRY(device_not_available)
15535 RING0_INT_FRAME
15536@@ -890,18 +1149,18 @@ ENTRY(device_not_available)
15537 pushl_cfi $do_device_not_available
15538 jmp error_code
15539 CFI_ENDPROC
15540-END(device_not_available)
15541+ENDPROC(device_not_available)
15542
15543 #ifdef CONFIG_PARAVIRT
15544 ENTRY(native_iret)
15545 iret
15546 _ASM_EXTABLE(native_iret, iret_exc)
15547-END(native_iret)
15548+ENDPROC(native_iret)
15549
15550 ENTRY(native_irq_enable_sysexit)
15551 sti
15552 sysexit
15553-END(native_irq_enable_sysexit)
15554+ENDPROC(native_irq_enable_sysexit)
15555 #endif
15556
15557 ENTRY(overflow)
15558@@ -910,7 +1169,7 @@ ENTRY(overflow)
15559 pushl_cfi $do_overflow
15560 jmp error_code
15561 CFI_ENDPROC
15562-END(overflow)
15563+ENDPROC(overflow)
15564
15565 ENTRY(bounds)
15566 RING0_INT_FRAME
15567@@ -918,7 +1177,7 @@ ENTRY(bounds)
15568 pushl_cfi $do_bounds
15569 jmp error_code
15570 CFI_ENDPROC
15571-END(bounds)
15572+ENDPROC(bounds)
15573
15574 ENTRY(invalid_op)
15575 RING0_INT_FRAME
15576@@ -926,7 +1185,7 @@ ENTRY(invalid_op)
15577 pushl_cfi $do_invalid_op
15578 jmp error_code
15579 CFI_ENDPROC
15580-END(invalid_op)
15581+ENDPROC(invalid_op)
15582
15583 ENTRY(coprocessor_segment_overrun)
15584 RING0_INT_FRAME
15585@@ -934,35 +1193,35 @@ ENTRY(coprocessor_segment_overrun)
15586 pushl_cfi $do_coprocessor_segment_overrun
15587 jmp error_code
15588 CFI_ENDPROC
15589-END(coprocessor_segment_overrun)
15590+ENDPROC(coprocessor_segment_overrun)
15591
15592 ENTRY(invalid_TSS)
15593 RING0_EC_FRAME
15594 pushl_cfi $do_invalid_TSS
15595 jmp error_code
15596 CFI_ENDPROC
15597-END(invalid_TSS)
15598+ENDPROC(invalid_TSS)
15599
15600 ENTRY(segment_not_present)
15601 RING0_EC_FRAME
15602 pushl_cfi $do_segment_not_present
15603 jmp error_code
15604 CFI_ENDPROC
15605-END(segment_not_present)
15606+ENDPROC(segment_not_present)
15607
15608 ENTRY(stack_segment)
15609 RING0_EC_FRAME
15610 pushl_cfi $do_stack_segment
15611 jmp error_code
15612 CFI_ENDPROC
15613-END(stack_segment)
15614+ENDPROC(stack_segment)
15615
15616 ENTRY(alignment_check)
15617 RING0_EC_FRAME
15618 pushl_cfi $do_alignment_check
15619 jmp error_code
15620 CFI_ENDPROC
15621-END(alignment_check)
15622+ENDPROC(alignment_check)
15623
15624 ENTRY(divide_error)
15625 RING0_INT_FRAME
15626@@ -970,7 +1229,7 @@ ENTRY(divide_error)
15627 pushl_cfi $do_divide_error
15628 jmp error_code
15629 CFI_ENDPROC
15630-END(divide_error)
15631+ENDPROC(divide_error)
15632
15633 #ifdef CONFIG_X86_MCE
15634 ENTRY(machine_check)
15635@@ -979,7 +1238,7 @@ ENTRY(machine_check)
15636 pushl_cfi machine_check_vector
15637 jmp error_code
15638 CFI_ENDPROC
15639-END(machine_check)
15640+ENDPROC(machine_check)
15641 #endif
15642
15643 ENTRY(spurious_interrupt_bug)
15644@@ -988,7 +1247,7 @@ ENTRY(spurious_interrupt_bug)
15645 pushl_cfi $do_spurious_interrupt_bug
15646 jmp error_code
15647 CFI_ENDPROC
15648-END(spurious_interrupt_bug)
15649+ENDPROC(spurious_interrupt_bug)
15650 /*
15651 * End of kprobes section
15652 */
15653@@ -1102,7 +1361,7 @@ BUILD_INTERRUPT3(xen_hvm_callback_vector, XEN_HVM_EVTCHN_CALLBACK,
15654
15655 ENTRY(mcount)
15656 ret
15657-END(mcount)
15658+ENDPROC(mcount)
15659
15660 ENTRY(ftrace_caller)
15661 cmpl $0, function_trace_stop
15662@@ -1131,7 +1390,7 @@ ftrace_graph_call:
15663 .globl ftrace_stub
15664 ftrace_stub:
15665 ret
15666-END(ftrace_caller)
15667+ENDPROC(ftrace_caller)
15668
15669 #else /* ! CONFIG_DYNAMIC_FTRACE */
15670
15671@@ -1167,7 +1426,7 @@ trace:
15672 popl %ecx
15673 popl %eax
15674 jmp ftrace_stub
15675-END(mcount)
15676+ENDPROC(mcount)
15677 #endif /* CONFIG_DYNAMIC_FTRACE */
15678 #endif /* CONFIG_FUNCTION_TRACER */
15679
15680@@ -1188,7 +1447,7 @@ ENTRY(ftrace_graph_caller)
15681 popl %ecx
15682 popl %eax
15683 ret
15684-END(ftrace_graph_caller)
15685+ENDPROC(ftrace_graph_caller)
15686
15687 .globl return_to_handler
15688 return_to_handler:
15689@@ -1243,15 +1502,18 @@ error_code:
15690 movl $-1, PT_ORIG_EAX(%esp) # no syscall to restart
15691 REG_TO_PTGS %ecx
15692 SET_KERNEL_GS %ecx
15693- movl $(__USER_DS), %ecx
15694+ movl $(__KERNEL_DS), %ecx
15695 movl %ecx, %ds
15696 movl %ecx, %es
15697+
15698+ pax_enter_kernel
15699+
15700 TRACE_IRQS_OFF
15701 movl %esp,%eax # pt_regs pointer
15702 call *%edi
15703 jmp ret_from_exception
15704 CFI_ENDPROC
15705-END(page_fault)
15706+ENDPROC(page_fault)
15707
15708 /*
15709 * Debug traps and NMI can happen at the one SYSENTER instruction
15710@@ -1293,7 +1555,7 @@ debug_stack_correct:
15711 call do_debug
15712 jmp ret_from_exception
15713 CFI_ENDPROC
15714-END(debug)
15715+ENDPROC(debug)
15716
15717 /*
15718 * NMI is doubly nasty. It can happen _while_ we're handling
15719@@ -1330,6 +1592,9 @@ nmi_stack_correct:
15720 xorl %edx,%edx # zero error code
15721 movl %esp,%eax # pt_regs pointer
15722 call do_nmi
15723+
15724+ pax_exit_kernel
15725+
15726 jmp restore_all_notrace
15727 CFI_ENDPROC
15728
15729@@ -1366,12 +1631,15 @@ nmi_espfix_stack:
15730 FIXUP_ESPFIX_STACK # %eax == %esp
15731 xorl %edx,%edx # zero error code
15732 call do_nmi
15733+
15734+ pax_exit_kernel
15735+
15736 RESTORE_REGS
15737 lss 12+4(%esp), %esp # back to espfix stack
15738 CFI_ADJUST_CFA_OFFSET -24
15739 jmp irq_return
15740 CFI_ENDPROC
15741-END(nmi)
15742+ENDPROC(nmi)
15743
15744 ENTRY(int3)
15745 RING0_INT_FRAME
15746@@ -1383,14 +1651,14 @@ ENTRY(int3)
15747 call do_int3
15748 jmp ret_from_exception
15749 CFI_ENDPROC
15750-END(int3)
15751+ENDPROC(int3)
15752
15753 ENTRY(general_protection)
15754 RING0_EC_FRAME
15755 pushl_cfi $do_general_protection
15756 jmp error_code
15757 CFI_ENDPROC
15758-END(general_protection)
15759+ENDPROC(general_protection)
15760
15761 #ifdef CONFIG_KVM_GUEST
15762 ENTRY(async_page_fault)
15763@@ -1398,7 +1666,7 @@ ENTRY(async_page_fault)
15764 pushl_cfi $do_async_page_fault
15765 jmp error_code
15766 CFI_ENDPROC
15767-END(async_page_fault)
15768+ENDPROC(async_page_fault)
15769 #endif
15770
15771 /*
15772diff --git a/arch/x86/kernel/entry_64.S b/arch/x86/kernel/entry_64.S
15773index dcdd0ea..de0bb2d 100644
15774--- a/arch/x86/kernel/entry_64.S
15775+++ b/arch/x86/kernel/entry_64.S
15776@@ -57,6 +57,8 @@
15777 #include <asm/percpu.h>
15778 #include <asm/asm.h>
15779 #include <linux/err.h>
15780+#include <asm/pgtable.h>
15781+#include <asm/alternative-asm.h>
15782
15783 /* Avoid __ASSEMBLER__'ifying <linux/audit.h> just for this. */
15784 #include <linux/elf-em.h>
15785@@ -70,8 +72,9 @@
15786 #ifdef CONFIG_FUNCTION_TRACER
15787 #ifdef CONFIG_DYNAMIC_FTRACE
15788 ENTRY(mcount)
15789+ pax_force_retaddr
15790 retq
15791-END(mcount)
15792+ENDPROC(mcount)
15793
15794 ENTRY(ftrace_caller)
15795 cmpl $0, function_trace_stop
15796@@ -94,8 +97,9 @@ GLOBAL(ftrace_graph_call)
15797 #endif
15798
15799 GLOBAL(ftrace_stub)
15800+ pax_force_retaddr
15801 retq
15802-END(ftrace_caller)
15803+ENDPROC(ftrace_caller)
15804
15805 #else /* ! CONFIG_DYNAMIC_FTRACE */
15806 ENTRY(mcount)
15807@@ -114,6 +118,7 @@ ENTRY(mcount)
15808 #endif
15809
15810 GLOBAL(ftrace_stub)
15811+ pax_force_retaddr
15812 retq
15813
15814 trace:
15815@@ -123,12 +128,13 @@ trace:
15816 movq 8(%rbp), %rsi
15817 subq $MCOUNT_INSN_SIZE, %rdi
15818
15819+ pax_force_fptr ftrace_trace_function
15820 call *ftrace_trace_function
15821
15822 MCOUNT_RESTORE_FRAME
15823
15824 jmp ftrace_stub
15825-END(mcount)
15826+ENDPROC(mcount)
15827 #endif /* CONFIG_DYNAMIC_FTRACE */
15828 #endif /* CONFIG_FUNCTION_TRACER */
15829
15830@@ -148,8 +154,9 @@ ENTRY(ftrace_graph_caller)
15831
15832 MCOUNT_RESTORE_FRAME
15833
15834+ pax_force_retaddr
15835 retq
15836-END(ftrace_graph_caller)
15837+ENDPROC(ftrace_graph_caller)
15838
15839 GLOBAL(return_to_handler)
15840 subq $24, %rsp
15841@@ -165,6 +172,7 @@ GLOBAL(return_to_handler)
15842 movq 8(%rsp), %rdx
15843 movq (%rsp), %rax
15844 addq $24, %rsp
15845+ pax_force_fptr %rdi
15846 jmp *%rdi
15847 #endif
15848
15849@@ -180,6 +188,280 @@ ENTRY(native_usergs_sysret64)
15850 ENDPROC(native_usergs_sysret64)
15851 #endif /* CONFIG_PARAVIRT */
15852
15853+ .macro ljmpq sel, off
15854+#if defined(CONFIG_MPSC) || defined(CONFIG_MCORE2) || defined (CONFIG_MATOM)
15855+ .byte 0x48; ljmp *1234f(%rip)
15856+ .pushsection .rodata
15857+ .align 16
15858+ 1234: .quad \off; .word \sel
15859+ .popsection
15860+#else
15861+ pushq $\sel
15862+ pushq $\off
15863+ lretq
15864+#endif
15865+ .endm
15866+
15867+ .macro pax_enter_kernel
15868+ pax_set_fptr_mask
15869+#ifdef CONFIG_PAX_KERNEXEC
15870+ call pax_enter_kernel
15871+#endif
15872+ .endm
15873+
15874+ .macro pax_exit_kernel
15875+#ifdef CONFIG_PAX_KERNEXEC
15876+ call pax_exit_kernel
15877+#endif
15878+ .endm
15879+
15880+#ifdef CONFIG_PAX_KERNEXEC
15881+ENTRY(pax_enter_kernel)
15882+ pushq %rdi
15883+
15884+#ifdef CONFIG_PARAVIRT
15885+ PV_SAVE_REGS(CLBR_RDI)
15886+#endif
15887+
15888+ GET_CR0_INTO_RDI
15889+ bts $16,%rdi
15890+ jnc 3f
15891+ mov %cs,%edi
15892+ cmp $__KERNEL_CS,%edi
15893+ jnz 2f
15894+1:
15895+
15896+#ifdef CONFIG_PARAVIRT
15897+ PV_RESTORE_REGS(CLBR_RDI)
15898+#endif
15899+
15900+ popq %rdi
15901+ pax_force_retaddr
15902+ retq
15903+
15904+2: ljmpq __KERNEL_CS,1f
15905+3: ljmpq __KERNEXEC_KERNEL_CS,4f
15906+4: SET_RDI_INTO_CR0
15907+ jmp 1b
15908+ENDPROC(pax_enter_kernel)
15909+
15910+ENTRY(pax_exit_kernel)
15911+ pushq %rdi
15912+
15913+#ifdef CONFIG_PARAVIRT
15914+ PV_SAVE_REGS(CLBR_RDI)
15915+#endif
15916+
15917+ mov %cs,%rdi
15918+ cmp $__KERNEXEC_KERNEL_CS,%edi
15919+ jz 2f
15920+1:
15921+
15922+#ifdef CONFIG_PARAVIRT
15923+ PV_RESTORE_REGS(CLBR_RDI);
15924+#endif
15925+
15926+ popq %rdi
15927+ pax_force_retaddr
15928+ retq
15929+
15930+2: GET_CR0_INTO_RDI
15931+ btr $16,%rdi
15932+ ljmpq __KERNEL_CS,3f
15933+3: SET_RDI_INTO_CR0
15934+ jmp 1b
15935+#ifdef CONFIG_PARAVIRT
15936+ PV_RESTORE_REGS(CLBR_RDI);
15937+#endif
15938+
15939+ popq %rdi
15940+ pax_force_retaddr
15941+ retq
15942+ENDPROC(pax_exit_kernel)
15943+#endif
15944+
15945+ .macro pax_enter_kernel_user
15946+ pax_set_fptr_mask
15947+#ifdef CONFIG_PAX_MEMORY_UDEREF
15948+ call pax_enter_kernel_user
15949+#endif
15950+ .endm
15951+
15952+ .macro pax_exit_kernel_user
15953+#ifdef CONFIG_PAX_MEMORY_UDEREF
15954+ call pax_exit_kernel_user
15955+#endif
15956+#ifdef CONFIG_PAX_RANDKSTACK
15957+ pushq %rax
15958+ call pax_randomize_kstack
15959+ popq %rax
15960+#endif
15961+ .endm
15962+
15963+#ifdef CONFIG_PAX_MEMORY_UDEREF
15964+ENTRY(pax_enter_kernel_user)
15965+ pushq %rdi
15966+ pushq %rbx
15967+
15968+#ifdef CONFIG_PARAVIRT
15969+ PV_SAVE_REGS(CLBR_RDI)
15970+#endif
15971+
15972+ GET_CR3_INTO_RDI
15973+ mov %rdi,%rbx
15974+ add $__START_KERNEL_map,%rbx
15975+ sub phys_base(%rip),%rbx
15976+
15977+#ifdef CONFIG_PARAVIRT
15978+ pushq %rdi
15979+ cmpl $0, pv_info+PARAVIRT_enabled
15980+ jz 1f
15981+ i = 0
15982+ .rept USER_PGD_PTRS
15983+ mov i*8(%rbx),%rsi
15984+ mov $0,%sil
15985+ lea i*8(%rbx),%rdi
15986+ call PARA_INDIRECT(pv_mmu_ops+PV_MMU_set_pgd_batched)
15987+ i = i + 1
15988+ .endr
15989+ jmp 2f
15990+1:
15991+#endif
15992+
15993+ i = 0
15994+ .rept USER_PGD_PTRS
15995+ movb $0,i*8(%rbx)
15996+ i = i + 1
15997+ .endr
15998+
15999+#ifdef CONFIG_PARAVIRT
16000+2: popq %rdi
16001+#endif
16002+ SET_RDI_INTO_CR3
16003+
16004+#ifdef CONFIG_PAX_KERNEXEC
16005+ GET_CR0_INTO_RDI
16006+ bts $16,%rdi
16007+ SET_RDI_INTO_CR0
16008+#endif
16009+
16010+#ifdef CONFIG_PARAVIRT
16011+ PV_RESTORE_REGS(CLBR_RDI)
16012+#endif
16013+
16014+ popq %rbx
16015+ popq %rdi
16016+ pax_force_retaddr
16017+ retq
16018+ENDPROC(pax_enter_kernel_user)
16019+
16020+ENTRY(pax_exit_kernel_user)
16021+ push %rdi
16022+
16023+#ifdef CONFIG_PARAVIRT
16024+ pushq %rbx
16025+ PV_SAVE_REGS(CLBR_RDI)
16026+#endif
16027+
16028+#ifdef CONFIG_PAX_KERNEXEC
16029+ GET_CR0_INTO_RDI
16030+ btr $16,%rdi
16031+ SET_RDI_INTO_CR0
16032+#endif
16033+
16034+ GET_CR3_INTO_RDI
16035+ add $__START_KERNEL_map,%rdi
16036+ sub phys_base(%rip),%rdi
16037+
16038+#ifdef CONFIG_PARAVIRT
16039+ cmpl $0, pv_info+PARAVIRT_enabled
16040+ jz 1f
16041+ mov %rdi,%rbx
16042+ i = 0
16043+ .rept USER_PGD_PTRS
16044+ mov i*8(%rbx),%rsi
16045+ mov $0x67,%sil
16046+ lea i*8(%rbx),%rdi
16047+ call PARA_INDIRECT(pv_mmu_ops+PV_MMU_set_pgd_batched)
16048+ i = i + 1
16049+ .endr
16050+ jmp 2f
16051+1:
16052+#endif
16053+
16054+ i = 0
16055+ .rept USER_PGD_PTRS
16056+ movb $0x67,i*8(%rdi)
16057+ i = i + 1
16058+ .endr
16059+
16060+#ifdef CONFIG_PARAVIRT
16061+2: PV_RESTORE_REGS(CLBR_RDI)
16062+ popq %rbx
16063+#endif
16064+
16065+ popq %rdi
16066+ pax_force_retaddr
16067+ retq
16068+ENDPROC(pax_exit_kernel_user)
16069+#endif
16070+
16071+.macro pax_erase_kstack
16072+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
16073+ call pax_erase_kstack
16074+#endif
16075+.endm
16076+
16077+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
16078+ENTRY(pax_erase_kstack)
16079+ pushq %rdi
16080+ pushq %rcx
16081+ pushq %rax
16082+ pushq %r11
16083+
16084+ GET_THREAD_INFO(%r11)
16085+ mov TI_lowest_stack(%r11), %rdi
16086+ mov $-0xBEEF, %rax
16087+ std
16088+
16089+1: mov %edi, %ecx
16090+ and $THREAD_SIZE_asm - 1, %ecx
16091+ shr $3, %ecx
16092+ repne scasq
16093+ jecxz 2f
16094+
16095+ cmp $2*8, %ecx
16096+ jc 2f
16097+
16098+ mov $2*8, %ecx
16099+ repe scasq
16100+ jecxz 2f
16101+ jne 1b
16102+
16103+2: cld
16104+ mov %esp, %ecx
16105+ sub %edi, %ecx
16106+
16107+ cmp $THREAD_SIZE_asm, %rcx
16108+ jb 3f
16109+ ud2
16110+3:
16111+
16112+ shr $3, %ecx
16113+ rep stosq
16114+
16115+ mov TI_task_thread_sp0(%r11), %rdi
16116+ sub $256, %rdi
16117+ mov %rdi, TI_lowest_stack(%r11)
16118+
16119+ popq %r11
16120+ popq %rax
16121+ popq %rcx
16122+ popq %rdi
16123+ pax_force_retaddr
16124+ ret
16125+ENDPROC(pax_erase_kstack)
16126+#endif
16127
16128 .macro TRACE_IRQS_IRETQ offset=ARGOFFSET
16129 #ifdef CONFIG_TRACE_IRQFLAGS
16130@@ -271,8 +553,8 @@ ENDPROC(native_usergs_sysret64)
16131 .endm
16132
16133 .macro UNFAKE_STACK_FRAME
16134- addq $8*6, %rsp
16135- CFI_ADJUST_CFA_OFFSET -(6*8)
16136+ addq $8*6 + ARG_SKIP, %rsp
16137+ CFI_ADJUST_CFA_OFFSET -(6*8 + ARG_SKIP)
16138 .endm
16139
16140 /*
16141@@ -359,7 +641,7 @@ ENDPROC(native_usergs_sysret64)
16142 movq %rsp, %rsi
16143
16144 leaq -RBP(%rsp),%rdi /* arg1 for handler */
16145- testl $3, CS-RBP(%rsi)
16146+ testb $3, CS-RBP(%rsi)
16147 je 1f
16148 SWAPGS
16149 /*
16150@@ -394,9 +676,10 @@ ENTRY(save_rest)
16151 movq_cfi r15, R15+16
16152 movq %r11, 8(%rsp) /* return address */
16153 FIXUP_TOP_OF_STACK %r11, 16
16154+ pax_force_retaddr
16155 ret
16156 CFI_ENDPROC
16157-END(save_rest)
16158+ENDPROC(save_rest)
16159
16160 /* save complete stack frame */
16161 .pushsection .kprobes.text, "ax"
16162@@ -425,9 +708,10 @@ ENTRY(save_paranoid)
16163 js 1f /* negative -> in kernel */
16164 SWAPGS
16165 xorl %ebx,%ebx
16166-1: ret
16167+1: pax_force_retaddr_bts
16168+ ret
16169 CFI_ENDPROC
16170-END(save_paranoid)
16171+ENDPROC(save_paranoid)
16172 .popsection
16173
16174 /*
16175@@ -449,7 +733,7 @@ ENTRY(ret_from_fork)
16176
16177 RESTORE_REST
16178
16179- testl $3, CS-ARGOFFSET(%rsp) # from kernel_thread?
16180+ testb $3, CS-ARGOFFSET(%rsp) # from kernel_thread?
16181 jz retint_restore_args
16182
16183 testl $_TIF_IA32, TI_flags(%rcx) # 32-bit compat task needs IRET
16184@@ -459,7 +743,7 @@ ENTRY(ret_from_fork)
16185 jmp ret_from_sys_call # go to the SYSRET fastpath
16186
16187 CFI_ENDPROC
16188-END(ret_from_fork)
16189+ENDPROC(ret_from_fork)
16190
16191 /*
16192 * System call entry. Up to 6 arguments in registers are supported.
16193@@ -495,7 +779,7 @@ END(ret_from_fork)
16194 ENTRY(system_call)
16195 CFI_STARTPROC simple
16196 CFI_SIGNAL_FRAME
16197- CFI_DEF_CFA rsp,KERNEL_STACK_OFFSET
16198+ CFI_DEF_CFA rsp,0
16199 CFI_REGISTER rip,rcx
16200 /*CFI_REGISTER rflags,r11*/
16201 SWAPGS_UNSAFE_STACK
16202@@ -508,16 +792,23 @@ GLOBAL(system_call_after_swapgs)
16203
16204 movq %rsp,PER_CPU_VAR(old_rsp)
16205 movq PER_CPU_VAR(kernel_stack),%rsp
16206+ SAVE_ARGS 8*6,0
16207+ pax_enter_kernel_user
16208+
16209+#ifdef CONFIG_PAX_RANDKSTACK
16210+ pax_erase_kstack
16211+#endif
16212+
16213 /*
16214 * No need to follow this irqs off/on section - it's straight
16215 * and short:
16216 */
16217 ENABLE_INTERRUPTS(CLBR_NONE)
16218- SAVE_ARGS 8,0
16219 movq %rax,ORIG_RAX-ARGOFFSET(%rsp)
16220 movq %rcx,RIP-ARGOFFSET(%rsp)
16221 CFI_REL_OFFSET rip,RIP-ARGOFFSET
16222- testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
16223+ GET_THREAD_INFO(%rcx)
16224+ testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%rcx)
16225 jnz tracesys
16226 system_call_fastpath:
16227 #if __SYSCALL_MASK == ~0
16228@@ -527,7 +818,7 @@ system_call_fastpath:
16229 cmpl $__NR_syscall_max,%eax
16230 #endif
16231 ja badsys
16232- movq %r10,%rcx
16233+ movq R10-ARGOFFSET(%rsp),%rcx
16234 call *sys_call_table(,%rax,8) # XXX: rip relative
16235 movq %rax,RAX-ARGOFFSET(%rsp)
16236 /*
16237@@ -541,10 +832,13 @@ sysret_check:
16238 LOCKDEP_SYS_EXIT
16239 DISABLE_INTERRUPTS(CLBR_NONE)
16240 TRACE_IRQS_OFF
16241- movl TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET),%edx
16242+ GET_THREAD_INFO(%rcx)
16243+ movl TI_flags(%rcx),%edx
16244 andl %edi,%edx
16245 jnz sysret_careful
16246 CFI_REMEMBER_STATE
16247+ pax_exit_kernel_user
16248+ pax_erase_kstack
16249 /*
16250 * sysretq will re-enable interrupts:
16251 */
16252@@ -596,14 +890,18 @@ badsys:
16253 * jump back to the normal fast path.
16254 */
16255 auditsys:
16256- movq %r10,%r9 /* 6th arg: 4th syscall arg */
16257+ movq R10-ARGOFFSET(%rsp),%r9 /* 6th arg: 4th syscall arg */
16258 movq %rdx,%r8 /* 5th arg: 3rd syscall arg */
16259 movq %rsi,%rcx /* 4th arg: 2nd syscall arg */
16260 movq %rdi,%rdx /* 3rd arg: 1st syscall arg */
16261 movq %rax,%rsi /* 2nd arg: syscall number */
16262 movl $AUDIT_ARCH_X86_64,%edi /* 1st arg: audit arch */
16263 call __audit_syscall_entry
16264+
16265+ pax_erase_kstack
16266+
16267 LOAD_ARGS 0 /* reload call-clobbered registers */
16268+ pax_set_fptr_mask
16269 jmp system_call_fastpath
16270
16271 /*
16272@@ -624,7 +922,7 @@ sysret_audit:
16273 /* Do syscall tracing */
16274 tracesys:
16275 #ifdef CONFIG_AUDITSYSCALL
16276- testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
16277+ testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags(%rcx)
16278 jz auditsys
16279 #endif
16280 SAVE_REST
16281@@ -632,12 +930,16 @@ tracesys:
16282 FIXUP_TOP_OF_STACK %rdi
16283 movq %rsp,%rdi
16284 call syscall_trace_enter
16285+
16286+ pax_erase_kstack
16287+
16288 /*
16289 * Reload arg registers from stack in case ptrace changed them.
16290 * We don't reload %rax because syscall_trace_enter() returned
16291 * the value it wants us to use in the table lookup.
16292 */
16293 LOAD_ARGS ARGOFFSET, 1
16294+ pax_set_fptr_mask
16295 RESTORE_REST
16296 #if __SYSCALL_MASK == ~0
16297 cmpq $__NR_syscall_max,%rax
16298@@ -646,7 +948,7 @@ tracesys:
16299 cmpl $__NR_syscall_max,%eax
16300 #endif
16301 ja int_ret_from_sys_call /* RAX(%rsp) set to -ENOSYS above */
16302- movq %r10,%rcx /* fixup for C */
16303+ movq R10-ARGOFFSET(%rsp),%rcx /* fixup for C */
16304 call *sys_call_table(,%rax,8)
16305 movq %rax,RAX-ARGOFFSET(%rsp)
16306 /* Use IRET because user could have changed frame */
16307@@ -667,7 +969,9 @@ GLOBAL(int_with_check)
16308 andl %edi,%edx
16309 jnz int_careful
16310 andl $~TS_COMPAT,TI_status(%rcx)
16311- jmp retint_swapgs
16312+ pax_exit_kernel_user
16313+ pax_erase_kstack
16314+ jmp retint_swapgs_pax
16315
16316 /* Either reschedule or signal or syscall exit tracking needed. */
16317 /* First do a reschedule test. */
16318@@ -713,7 +1017,7 @@ int_restore_rest:
16319 TRACE_IRQS_OFF
16320 jmp int_with_check
16321 CFI_ENDPROC
16322-END(system_call)
16323+ENDPROC(system_call)
16324
16325 /*
16326 * Certain special system calls that need to save a complete full stack frame.
16327@@ -729,7 +1033,7 @@ ENTRY(\label)
16328 call \func
16329 jmp ptregscall_common
16330 CFI_ENDPROC
16331-END(\label)
16332+ENDPROC(\label)
16333 .endm
16334
16335 PTREGSCALL stub_clone, sys_clone, %r8
16336@@ -747,9 +1051,10 @@ ENTRY(ptregscall_common)
16337 movq_cfi_restore R12+8, r12
16338 movq_cfi_restore RBP+8, rbp
16339 movq_cfi_restore RBX+8, rbx
16340+ pax_force_retaddr
16341 ret $REST_SKIP /* pop extended registers */
16342 CFI_ENDPROC
16343-END(ptregscall_common)
16344+ENDPROC(ptregscall_common)
16345
16346 ENTRY(stub_execve)
16347 CFI_STARTPROC
16348@@ -764,7 +1069,7 @@ ENTRY(stub_execve)
16349 RESTORE_REST
16350 jmp int_ret_from_sys_call
16351 CFI_ENDPROC
16352-END(stub_execve)
16353+ENDPROC(stub_execve)
16354
16355 /*
16356 * sigreturn is special because it needs to restore all registers on return.
16357@@ -782,7 +1087,7 @@ ENTRY(stub_rt_sigreturn)
16358 RESTORE_REST
16359 jmp int_ret_from_sys_call
16360 CFI_ENDPROC
16361-END(stub_rt_sigreturn)
16362+ENDPROC(stub_rt_sigreturn)
16363
16364 #ifdef CONFIG_X86_X32_ABI
16365 PTREGSCALL stub_x32_sigaltstack, sys32_sigaltstack, %rdx
16366@@ -851,7 +1156,7 @@ vector=vector+1
16367 2: jmp common_interrupt
16368 .endr
16369 CFI_ENDPROC
16370-END(irq_entries_start)
16371+ENDPROC(irq_entries_start)
16372
16373 .previous
16374 END(interrupt)
16375@@ -871,6 +1176,16 @@ END(interrupt)
16376 subq $ORIG_RAX-RBP, %rsp
16377 CFI_ADJUST_CFA_OFFSET ORIG_RAX-RBP
16378 SAVE_ARGS_IRQ
16379+#ifdef CONFIG_PAX_MEMORY_UDEREF
16380+ testb $3, CS(%rdi)
16381+ jnz 1f
16382+ pax_enter_kernel
16383+ jmp 2f
16384+1: pax_enter_kernel_user
16385+2:
16386+#else
16387+ pax_enter_kernel
16388+#endif
16389 call \func
16390 .endm
16391
16392@@ -902,7 +1217,7 @@ ret_from_intr:
16393
16394 exit_intr:
16395 GET_THREAD_INFO(%rcx)
16396- testl $3,CS-ARGOFFSET(%rsp)
16397+ testb $3,CS-ARGOFFSET(%rsp)
16398 je retint_kernel
16399
16400 /* Interrupt came from user space */
16401@@ -924,12 +1239,16 @@ retint_swapgs: /* return to user-space */
16402 * The iretq could re-enable interrupts:
16403 */
16404 DISABLE_INTERRUPTS(CLBR_ANY)
16405+ pax_exit_kernel_user
16406+retint_swapgs_pax:
16407 TRACE_IRQS_IRETQ
16408 SWAPGS
16409 jmp restore_args
16410
16411 retint_restore_args: /* return to kernel space */
16412 DISABLE_INTERRUPTS(CLBR_ANY)
16413+ pax_exit_kernel
16414+ pax_force_retaddr RIP-ARGOFFSET
16415 /*
16416 * The iretq could re-enable interrupts:
16417 */
16418@@ -1012,7 +1331,7 @@ ENTRY(retint_kernel)
16419 #endif
16420
16421 CFI_ENDPROC
16422-END(common_interrupt)
16423+ENDPROC(common_interrupt)
16424 /*
16425 * End of kprobes section
16426 */
16427@@ -1029,7 +1348,7 @@ ENTRY(\sym)
16428 interrupt \do_sym
16429 jmp ret_from_intr
16430 CFI_ENDPROC
16431-END(\sym)
16432+ENDPROC(\sym)
16433 .endm
16434
16435 #ifdef CONFIG_SMP
16436@@ -1084,12 +1403,22 @@ ENTRY(\sym)
16437 CFI_ADJUST_CFA_OFFSET ORIG_RAX-R15
16438 call error_entry
16439 DEFAULT_FRAME 0
16440+#ifdef CONFIG_PAX_MEMORY_UDEREF
16441+ testb $3, CS(%rsp)
16442+ jnz 1f
16443+ pax_enter_kernel
16444+ jmp 2f
16445+1: pax_enter_kernel_user
16446+2:
16447+#else
16448+ pax_enter_kernel
16449+#endif
16450 movq %rsp,%rdi /* pt_regs pointer */
16451 xorl %esi,%esi /* no error code */
16452 call \do_sym
16453 jmp error_exit /* %ebx: no swapgs flag */
16454 CFI_ENDPROC
16455-END(\sym)
16456+ENDPROC(\sym)
16457 .endm
16458
16459 .macro paranoidzeroentry sym do_sym
16460@@ -1101,15 +1430,25 @@ ENTRY(\sym)
16461 CFI_ADJUST_CFA_OFFSET ORIG_RAX-R15
16462 call save_paranoid
16463 TRACE_IRQS_OFF
16464+#ifdef CONFIG_PAX_MEMORY_UDEREF
16465+ testb $3, CS(%rsp)
16466+ jnz 1f
16467+ pax_enter_kernel
16468+ jmp 2f
16469+1: pax_enter_kernel_user
16470+2:
16471+#else
16472+ pax_enter_kernel
16473+#endif
16474 movq %rsp,%rdi /* pt_regs pointer */
16475 xorl %esi,%esi /* no error code */
16476 call \do_sym
16477 jmp paranoid_exit /* %ebx: no swapgs flag */
16478 CFI_ENDPROC
16479-END(\sym)
16480+ENDPROC(\sym)
16481 .endm
16482
16483-#define INIT_TSS_IST(x) PER_CPU_VAR(init_tss) + (TSS_ist + ((x) - 1) * 8)
16484+#define INIT_TSS_IST(x) (TSS_ist + ((x) - 1) * 8)(%r12)
16485 .macro paranoidzeroentry_ist sym do_sym ist
16486 ENTRY(\sym)
16487 INTR_FRAME
16488@@ -1119,14 +1458,30 @@ ENTRY(\sym)
16489 CFI_ADJUST_CFA_OFFSET ORIG_RAX-R15
16490 call save_paranoid
16491 TRACE_IRQS_OFF_DEBUG
16492+#ifdef CONFIG_PAX_MEMORY_UDEREF
16493+ testb $3, CS(%rsp)
16494+ jnz 1f
16495+ pax_enter_kernel
16496+ jmp 2f
16497+1: pax_enter_kernel_user
16498+2:
16499+#else
16500+ pax_enter_kernel
16501+#endif
16502 movq %rsp,%rdi /* pt_regs pointer */
16503 xorl %esi,%esi /* no error code */
16504+#ifdef CONFIG_SMP
16505+ imul $TSS_size, PER_CPU_VAR(cpu_number), %r12d
16506+ lea init_tss(%r12), %r12
16507+#else
16508+ lea init_tss(%rip), %r12
16509+#endif
16510 subq $EXCEPTION_STKSZ, INIT_TSS_IST(\ist)
16511 call \do_sym
16512 addq $EXCEPTION_STKSZ, INIT_TSS_IST(\ist)
16513 jmp paranoid_exit /* %ebx: no swapgs flag */
16514 CFI_ENDPROC
16515-END(\sym)
16516+ENDPROC(\sym)
16517 .endm
16518
16519 .macro errorentry sym do_sym
16520@@ -1137,13 +1492,23 @@ ENTRY(\sym)
16521 CFI_ADJUST_CFA_OFFSET ORIG_RAX-R15
16522 call error_entry
16523 DEFAULT_FRAME 0
16524+#ifdef CONFIG_PAX_MEMORY_UDEREF
16525+ testb $3, CS(%rsp)
16526+ jnz 1f
16527+ pax_enter_kernel
16528+ jmp 2f
16529+1: pax_enter_kernel_user
16530+2:
16531+#else
16532+ pax_enter_kernel
16533+#endif
16534 movq %rsp,%rdi /* pt_regs pointer */
16535 movq ORIG_RAX(%rsp),%rsi /* get error code */
16536 movq $-1,ORIG_RAX(%rsp) /* no syscall to restart */
16537 call \do_sym
16538 jmp error_exit /* %ebx: no swapgs flag */
16539 CFI_ENDPROC
16540-END(\sym)
16541+ENDPROC(\sym)
16542 .endm
16543
16544 /* error code is on the stack already */
16545@@ -1156,13 +1521,23 @@ ENTRY(\sym)
16546 call save_paranoid
16547 DEFAULT_FRAME 0
16548 TRACE_IRQS_OFF
16549+#ifdef CONFIG_PAX_MEMORY_UDEREF
16550+ testb $3, CS(%rsp)
16551+ jnz 1f
16552+ pax_enter_kernel
16553+ jmp 2f
16554+1: pax_enter_kernel_user
16555+2:
16556+#else
16557+ pax_enter_kernel
16558+#endif
16559 movq %rsp,%rdi /* pt_regs pointer */
16560 movq ORIG_RAX(%rsp),%rsi /* get error code */
16561 movq $-1,ORIG_RAX(%rsp) /* no syscall to restart */
16562 call \do_sym
16563 jmp paranoid_exit /* %ebx: no swapgs flag */
16564 CFI_ENDPROC
16565-END(\sym)
16566+ENDPROC(\sym)
16567 .endm
16568
16569 zeroentry divide_error do_divide_error
16570@@ -1192,9 +1567,10 @@ gs_change:
16571 2: mfence /* workaround */
16572 SWAPGS
16573 popfq_cfi
16574+ pax_force_retaddr
16575 ret
16576 CFI_ENDPROC
16577-END(native_load_gs_index)
16578+ENDPROC(native_load_gs_index)
16579
16580 _ASM_EXTABLE(gs_change,bad_gs)
16581 .section .fixup,"ax"
16582@@ -1213,13 +1589,14 @@ ENTRY(kernel_thread_helper)
16583 * Here we are in the child and the registers are set as they were
16584 * at kernel_thread() invocation in the parent.
16585 */
16586+ pax_force_fptr %rsi
16587 call *%rsi
16588 # exit
16589 mov %eax, %edi
16590 call do_exit
16591 ud2 # padding for call trace
16592 CFI_ENDPROC
16593-END(kernel_thread_helper)
16594+ENDPROC(kernel_thread_helper)
16595
16596 /*
16597 * execve(). This function needs to use IRET, not SYSRET, to set up all state properly.
16598@@ -1246,11 +1623,11 @@ ENTRY(kernel_execve)
16599 RESTORE_REST
16600 testq %rax,%rax
16601 je int_ret_from_sys_call
16602- RESTORE_ARGS
16603 UNFAKE_STACK_FRAME
16604+ pax_force_retaddr
16605 ret
16606 CFI_ENDPROC
16607-END(kernel_execve)
16608+ENDPROC(kernel_execve)
16609
16610 /* Call softirq on interrupt stack. Interrupts are off. */
16611 ENTRY(call_softirq)
16612@@ -1268,9 +1645,10 @@ ENTRY(call_softirq)
16613 CFI_DEF_CFA_REGISTER rsp
16614 CFI_ADJUST_CFA_OFFSET -8
16615 decl PER_CPU_VAR(irq_count)
16616+ pax_force_retaddr
16617 ret
16618 CFI_ENDPROC
16619-END(call_softirq)
16620+ENDPROC(call_softirq)
16621
16622 #ifdef CONFIG_XEN
16623 zeroentry xen_hypervisor_callback xen_do_hypervisor_callback
16624@@ -1308,7 +1686,7 @@ ENTRY(xen_do_hypervisor_callback) # do_hypervisor_callback(struct *pt_regs)
16625 decl PER_CPU_VAR(irq_count)
16626 jmp error_exit
16627 CFI_ENDPROC
16628-END(xen_do_hypervisor_callback)
16629+ENDPROC(xen_do_hypervisor_callback)
16630
16631 /*
16632 * Hypervisor uses this for application faults while it executes.
16633@@ -1367,7 +1745,7 @@ ENTRY(xen_failsafe_callback)
16634 SAVE_ALL
16635 jmp error_exit
16636 CFI_ENDPROC
16637-END(xen_failsafe_callback)
16638+ENDPROC(xen_failsafe_callback)
16639
16640 apicinterrupt XEN_HVM_EVTCHN_CALLBACK \
16641 xen_hvm_callback_vector xen_evtchn_do_upcall
16642@@ -1416,16 +1794,31 @@ ENTRY(paranoid_exit)
16643 TRACE_IRQS_OFF_DEBUG
16644 testl %ebx,%ebx /* swapgs needed? */
16645 jnz paranoid_restore
16646- testl $3,CS(%rsp)
16647+ testb $3,CS(%rsp)
16648 jnz paranoid_userspace
16649+#ifdef CONFIG_PAX_MEMORY_UDEREF
16650+ pax_exit_kernel
16651+ TRACE_IRQS_IRETQ 0
16652+ SWAPGS_UNSAFE_STACK
16653+ RESTORE_ALL 8
16654+ pax_force_retaddr_bts
16655+ jmp irq_return
16656+#endif
16657 paranoid_swapgs:
16658+#ifdef CONFIG_PAX_MEMORY_UDEREF
16659+ pax_exit_kernel_user
16660+#else
16661+ pax_exit_kernel
16662+#endif
16663 TRACE_IRQS_IRETQ 0
16664 SWAPGS_UNSAFE_STACK
16665 RESTORE_ALL 8
16666 jmp irq_return
16667 paranoid_restore:
16668+ pax_exit_kernel
16669 TRACE_IRQS_IRETQ_DEBUG 0
16670 RESTORE_ALL 8
16671+ pax_force_retaddr_bts
16672 jmp irq_return
16673 paranoid_userspace:
16674 GET_THREAD_INFO(%rcx)
16675@@ -1454,7 +1847,7 @@ paranoid_schedule:
16676 TRACE_IRQS_OFF
16677 jmp paranoid_userspace
16678 CFI_ENDPROC
16679-END(paranoid_exit)
16680+ENDPROC(paranoid_exit)
16681
16682 /*
16683 * Exception entry point. This expects an error code/orig_rax on the stack.
16684@@ -1481,12 +1874,13 @@ ENTRY(error_entry)
16685 movq_cfi r14, R14+8
16686 movq_cfi r15, R15+8
16687 xorl %ebx,%ebx
16688- testl $3,CS+8(%rsp)
16689+ testb $3,CS+8(%rsp)
16690 je error_kernelspace
16691 error_swapgs:
16692 SWAPGS
16693 error_sti:
16694 TRACE_IRQS_OFF
16695+ pax_force_retaddr_bts
16696 ret
16697
16698 /*
16699@@ -1513,7 +1907,7 @@ bstep_iret:
16700 movq %rcx,RIP+8(%rsp)
16701 jmp error_swapgs
16702 CFI_ENDPROC
16703-END(error_entry)
16704+ENDPROC(error_entry)
16705
16706
16707 /* ebx: no swapgs flag (1: don't need swapgs, 0: need it) */
16708@@ -1533,7 +1927,7 @@ ENTRY(error_exit)
16709 jnz retint_careful
16710 jmp retint_swapgs
16711 CFI_ENDPROC
16712-END(error_exit)
16713+ENDPROC(error_exit)
16714
16715 /*
16716 * Test if a given stack is an NMI stack or not.
16717@@ -1591,9 +1985,11 @@ ENTRY(nmi)
16718 * If %cs was not the kernel segment, then the NMI triggered in user
16719 * space, which means it is definitely not nested.
16720 */
16721+ cmpl $__KERNEXEC_KERNEL_CS, 16(%rsp)
16722+ je 1f
16723 cmpl $__KERNEL_CS, 16(%rsp)
16724 jne first_nmi
16725-
16726+1:
16727 /*
16728 * Check the special variable on the stack to see if NMIs are
16729 * executing.
16730@@ -1752,6 +2148,17 @@ end_repeat_nmi:
16731 */
16732 movq %cr2, %r12
16733
16734+#ifdef CONFIG_PAX_MEMORY_UDEREF
16735+ testb $3, CS(%rsp)
16736+ jnz 1f
16737+ pax_enter_kernel
16738+ jmp 2f
16739+1: pax_enter_kernel_user
16740+2:
16741+#else
16742+ pax_enter_kernel
16743+#endif
16744+
16745 /* paranoidentry do_nmi, 0; without TRACE_IRQS_OFF */
16746 movq %rsp,%rdi
16747 movq $-1,%rsi
16748@@ -1767,21 +2174,32 @@ end_repeat_nmi:
16749 testl %ebx,%ebx /* swapgs needed? */
16750 jnz nmi_restore
16751 nmi_swapgs:
16752+#ifdef CONFIG_PAX_MEMORY_UDEREF
16753+ pax_exit_kernel_user
16754+#else
16755+ pax_exit_kernel
16756+#endif
16757 SWAPGS_UNSAFE_STACK
16758+ RESTORE_ALL 8
16759+ /* Clear the NMI executing stack variable */
16760+ movq $0, 10*8(%rsp)
16761+ jmp irq_return
16762 nmi_restore:
16763+ pax_exit_kernel
16764 RESTORE_ALL 8
16765+ pax_force_retaddr_bts
16766 /* Clear the NMI executing stack variable */
16767 movq $0, 10*8(%rsp)
16768 jmp irq_return
16769 CFI_ENDPROC
16770-END(nmi)
16771+ENDPROC(nmi)
16772
16773 ENTRY(ignore_sysret)
16774 CFI_STARTPROC
16775 mov $-ENOSYS,%eax
16776 sysret
16777 CFI_ENDPROC
16778-END(ignore_sysret)
16779+ENDPROC(ignore_sysret)
16780
16781 /*
16782 * End of kprobes section
16783diff --git a/arch/x86/kernel/ftrace.c b/arch/x86/kernel/ftrace.c
16784index c3a7cb4..3ad00dc 100644
16785--- a/arch/x86/kernel/ftrace.c
16786+++ b/arch/x86/kernel/ftrace.c
16787@@ -105,6 +105,8 @@ ftrace_modify_code_direct(unsigned long ip, unsigned const char *old_code,
16788 {
16789 unsigned char replaced[MCOUNT_INSN_SIZE];
16790
16791+ ip = ktla_ktva(ip);
16792+
16793 /*
16794 * Note: Due to modules and __init, code can
16795 * disappear and change, we need to protect against faulting
16796@@ -212,7 +214,7 @@ int ftrace_update_ftrace_func(ftrace_func_t func)
16797 unsigned char old[MCOUNT_INSN_SIZE], *new;
16798 int ret;
16799
16800- memcpy(old, &ftrace_call, MCOUNT_INSN_SIZE);
16801+ memcpy(old, (void *)ktla_ktva((unsigned long)ftrace_call), MCOUNT_INSN_SIZE);
16802 new = ftrace_call_replace(ip, (unsigned long)func);
16803
16804 /* See comment above by declaration of modifying_ftrace_code */
16805@@ -605,6 +607,8 @@ static int ftrace_mod_jmp(unsigned long ip,
16806 {
16807 unsigned char code[MCOUNT_INSN_SIZE];
16808
16809+ ip = ktla_ktva(ip);
16810+
16811 if (probe_kernel_read(code, (void *)ip, MCOUNT_INSN_SIZE))
16812 return -EFAULT;
16813
16814diff --git a/arch/x86/kernel/head32.c b/arch/x86/kernel/head32.c
16815index c18f59d..9c0c9f6 100644
16816--- a/arch/x86/kernel/head32.c
16817+++ b/arch/x86/kernel/head32.c
16818@@ -18,6 +18,7 @@
16819 #include <asm/io_apic.h>
16820 #include <asm/bios_ebda.h>
16821 #include <asm/tlbflush.h>
16822+#include <asm/boot.h>
16823
16824 static void __init i386_default_early_setup(void)
16825 {
16826@@ -30,8 +31,7 @@ static void __init i386_default_early_setup(void)
16827
16828 void __init i386_start_kernel(void)
16829 {
16830- memblock_reserve(__pa_symbol(&_text),
16831- __pa_symbol(&__bss_stop) - __pa_symbol(&_text));
16832+ memblock_reserve(LOAD_PHYSICAL_ADDR, __pa_symbol(&__bss_stop) - LOAD_PHYSICAL_ADDR);
16833
16834 #ifdef CONFIG_BLK_DEV_INITRD
16835 /* Reserve INITRD */
16836diff --git a/arch/x86/kernel/head_32.S b/arch/x86/kernel/head_32.S
16837index d42ab17..cb1b997 100644
16838--- a/arch/x86/kernel/head_32.S
16839+++ b/arch/x86/kernel/head_32.S
16840@@ -26,6 +26,12 @@
16841 /* Physical address */
16842 #define pa(X) ((X) - __PAGE_OFFSET)
16843
16844+#ifdef CONFIG_PAX_KERNEXEC
16845+#define ta(X) (X)
16846+#else
16847+#define ta(X) ((X) - __PAGE_OFFSET)
16848+#endif
16849+
16850 /*
16851 * References to members of the new_cpu_data structure.
16852 */
16853@@ -55,11 +61,7 @@
16854 * and small than max_low_pfn, otherwise will waste some page table entries
16855 */
16856
16857-#if PTRS_PER_PMD > 1
16858-#define PAGE_TABLE_SIZE(pages) (((pages) / PTRS_PER_PMD) + PTRS_PER_PGD)
16859-#else
16860-#define PAGE_TABLE_SIZE(pages) ((pages) / PTRS_PER_PGD)
16861-#endif
16862+#define PAGE_TABLE_SIZE(pages) ((pages) / PTRS_PER_PTE)
16863
16864 /* Number of possible pages in the lowmem region */
16865 LOWMEM_PAGES = (((1<<32) - __PAGE_OFFSET) >> PAGE_SHIFT)
16866@@ -78,6 +80,12 @@ INIT_MAP_SIZE = PAGE_TABLE_SIZE(KERNEL_PAGES) * PAGE_SIZE
16867 RESERVE_BRK(pagetables, INIT_MAP_SIZE)
16868
16869 /*
16870+ * Real beginning of normal "text" segment
16871+ */
16872+ENTRY(stext)
16873+ENTRY(_stext)
16874+
16875+/*
16876 * 32-bit kernel entrypoint; only used by the boot CPU. On entry,
16877 * %esi points to the real-mode code as a 32-bit pointer.
16878 * CS and DS must be 4 GB flat segments, but we don't depend on
16879@@ -85,6 +93,13 @@ RESERVE_BRK(pagetables, INIT_MAP_SIZE)
16880 * can.
16881 */
16882 __HEAD
16883+
16884+#ifdef CONFIG_PAX_KERNEXEC
16885+ jmp startup_32
16886+/* PaX: fill first page in .text with int3 to catch NULL derefs in kernel mode */
16887+.fill PAGE_SIZE-5,1,0xcc
16888+#endif
16889+
16890 ENTRY(startup_32)
16891 movl pa(stack_start),%ecx
16892
16893@@ -106,6 +121,57 @@ ENTRY(startup_32)
16894 2:
16895 leal -__PAGE_OFFSET(%ecx),%esp
16896
16897+#ifdef CONFIG_SMP
16898+ movl $pa(cpu_gdt_table),%edi
16899+ movl $__per_cpu_load,%eax
16900+ movw %ax,__KERNEL_PERCPU + 2(%edi)
16901+ rorl $16,%eax
16902+ movb %al,__KERNEL_PERCPU + 4(%edi)
16903+ movb %ah,__KERNEL_PERCPU + 7(%edi)
16904+ movl $__per_cpu_end - 1,%eax
16905+ subl $__per_cpu_start,%eax
16906+ movw %ax,__KERNEL_PERCPU + 0(%edi)
16907+#endif
16908+
16909+#ifdef CONFIG_PAX_MEMORY_UDEREF
16910+ movl $NR_CPUS,%ecx
16911+ movl $pa(cpu_gdt_table),%edi
16912+1:
16913+ movl $((((__PAGE_OFFSET-1) & 0xf0000000) >> 12) | 0x00c09700),GDT_ENTRY_KERNEL_DS * 8 + 4(%edi)
16914+ movl $((((__PAGE_OFFSET-1) & 0xf0000000) >> 12) | 0x00c0fb00),GDT_ENTRY_DEFAULT_USER_CS * 8 + 4(%edi)
16915+ movl $((((__PAGE_OFFSET-1) & 0xf0000000) >> 12) | 0x00c0f300),GDT_ENTRY_DEFAULT_USER_DS * 8 + 4(%edi)
16916+ addl $PAGE_SIZE_asm,%edi
16917+ loop 1b
16918+#endif
16919+
16920+#ifdef CONFIG_PAX_KERNEXEC
16921+ movl $pa(boot_gdt),%edi
16922+ movl $__LOAD_PHYSICAL_ADDR,%eax
16923+ movw %ax,__BOOT_CS + 2(%edi)
16924+ rorl $16,%eax
16925+ movb %al,__BOOT_CS + 4(%edi)
16926+ movb %ah,__BOOT_CS + 7(%edi)
16927+ rorl $16,%eax
16928+
16929+ ljmp $(__BOOT_CS),$1f
16930+1:
16931+
16932+ movl $NR_CPUS,%ecx
16933+ movl $pa(cpu_gdt_table),%edi
16934+ addl $__PAGE_OFFSET,%eax
16935+1:
16936+ movw %ax,__KERNEL_CS + 2(%edi)
16937+ movw %ax,__KERNEXEC_KERNEL_CS + 2(%edi)
16938+ rorl $16,%eax
16939+ movb %al,__KERNEL_CS + 4(%edi)
16940+ movb %al,__KERNEXEC_KERNEL_CS + 4(%edi)
16941+ movb %ah,__KERNEL_CS + 7(%edi)
16942+ movb %ah,__KERNEXEC_KERNEL_CS + 7(%edi)
16943+ rorl $16,%eax
16944+ addl $PAGE_SIZE_asm,%edi
16945+ loop 1b
16946+#endif
16947+
16948 /*
16949 * Clear BSS first so that there are no surprises...
16950 */
16951@@ -196,8 +262,11 @@ ENTRY(startup_32)
16952 movl %eax, pa(max_pfn_mapped)
16953
16954 /* Do early initialization of the fixmap area */
16955- movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,%eax
16956- movl %eax,pa(initial_pg_pmd+0x1000*KPMDS-8)
16957+#ifdef CONFIG_COMPAT_VDSO
16958+ movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR+_PAGE_USER,pa(initial_pg_pmd+0x1000*KPMDS-8)
16959+#else
16960+ movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,pa(initial_pg_pmd+0x1000*KPMDS-8)
16961+#endif
16962 #else /* Not PAE */
16963
16964 page_pde_offset = (__PAGE_OFFSET >> 20);
16965@@ -227,8 +296,11 @@ page_pde_offset = (__PAGE_OFFSET >> 20);
16966 movl %eax, pa(max_pfn_mapped)
16967
16968 /* Do early initialization of the fixmap area */
16969- movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,%eax
16970- movl %eax,pa(initial_page_table+0xffc)
16971+#ifdef CONFIG_COMPAT_VDSO
16972+ movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR+_PAGE_USER,pa(initial_page_table+0xffc)
16973+#else
16974+ movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,pa(initial_page_table+0xffc)
16975+#endif
16976 #endif
16977
16978 #ifdef CONFIG_PARAVIRT
16979@@ -242,9 +314,7 @@ page_pde_offset = (__PAGE_OFFSET >> 20);
16980 cmpl $num_subarch_entries, %eax
16981 jae bad_subarch
16982
16983- movl pa(subarch_entries)(,%eax,4), %eax
16984- subl $__PAGE_OFFSET, %eax
16985- jmp *%eax
16986+ jmp *pa(subarch_entries)(,%eax,4)
16987
16988 bad_subarch:
16989 WEAK(lguest_entry)
16990@@ -256,10 +326,10 @@ WEAK(xen_entry)
16991 __INITDATA
16992
16993 subarch_entries:
16994- .long default_entry /* normal x86/PC */
16995- .long lguest_entry /* lguest hypervisor */
16996- .long xen_entry /* Xen hypervisor */
16997- .long default_entry /* Moorestown MID */
16998+ .long ta(default_entry) /* normal x86/PC */
16999+ .long ta(lguest_entry) /* lguest hypervisor */
17000+ .long ta(xen_entry) /* Xen hypervisor */
17001+ .long ta(default_entry) /* Moorestown MID */
17002 num_subarch_entries = (. - subarch_entries) / 4
17003 .previous
17004 #else
17005@@ -310,6 +380,7 @@ default_entry:
17006 orl %edx,%eax
17007 movl %eax,%cr4
17008
17009+#ifdef CONFIG_X86_PAE
17010 testb $X86_CR4_PAE, %al # check if PAE is enabled
17011 jz 6f
17012
17013@@ -338,6 +409,9 @@ default_entry:
17014 /* Make changes effective */
17015 wrmsr
17016
17017+ btsl $_PAGE_BIT_NX-32,pa(__supported_pte_mask+4)
17018+#endif
17019+
17020 6:
17021
17022 /*
17023@@ -436,14 +510,20 @@ is386: movl $2,%ecx # set MP
17024 1: movl $(__KERNEL_DS),%eax # reload all the segment registers
17025 movl %eax,%ss # after changing gdt.
17026
17027- movl $(__USER_DS),%eax # DS/ES contains default USER segment
17028+# movl $(__KERNEL_DS),%eax # DS/ES contains default KERNEL segment
17029 movl %eax,%ds
17030 movl %eax,%es
17031
17032 movl $(__KERNEL_PERCPU), %eax
17033 movl %eax,%fs # set this cpu's percpu
17034
17035+#ifdef CONFIG_CC_STACKPROTECTOR
17036 movl $(__KERNEL_STACK_CANARY),%eax
17037+#elif defined(CONFIG_PAX_MEMORY_UDEREF)
17038+ movl $(__USER_DS),%eax
17039+#else
17040+ xorl %eax,%eax
17041+#endif
17042 movl %eax,%gs
17043
17044 xorl %eax,%eax # Clear LDT
17045@@ -520,8 +600,11 @@ setup_once:
17046 * relocation. Manually set base address in stack canary
17047 * segment descriptor.
17048 */
17049- movl $gdt_page,%eax
17050+ movl $cpu_gdt_table,%eax
17051 movl $stack_canary,%ecx
17052+#ifdef CONFIG_SMP
17053+ addl $__per_cpu_load,%ecx
17054+#endif
17055 movw %cx, 8 * GDT_ENTRY_STACK_CANARY + 2(%eax)
17056 shrl $16, %ecx
17057 movb %cl, 8 * GDT_ENTRY_STACK_CANARY + 4(%eax)
17058@@ -552,7 +635,7 @@ ENDPROC(early_idt_handlers)
17059 /* This is global to keep gas from relaxing the jumps */
17060 ENTRY(early_idt_handler)
17061 cld
17062- cmpl $2,%ss:early_recursion_flag
17063+ cmpl $1,%ss:early_recursion_flag
17064 je hlt_loop
17065 incl %ss:early_recursion_flag
17066
17067@@ -590,8 +673,8 @@ ENTRY(early_idt_handler)
17068 pushl (20+6*4)(%esp) /* trapno */
17069 pushl $fault_msg
17070 call printk
17071-#endif
17072 call dump_stack
17073+#endif
17074 hlt_loop:
17075 hlt
17076 jmp hlt_loop
17077@@ -610,8 +693,11 @@ ENDPROC(early_idt_handler)
17078 /* This is the default interrupt "handler" :-) */
17079 ALIGN
17080 ignore_int:
17081- cld
17082 #ifdef CONFIG_PRINTK
17083+ cmpl $2,%ss:early_recursion_flag
17084+ je hlt_loop
17085+ incl %ss:early_recursion_flag
17086+ cld
17087 pushl %eax
17088 pushl %ecx
17089 pushl %edx
17090@@ -620,9 +706,6 @@ ignore_int:
17091 movl $(__KERNEL_DS),%eax
17092 movl %eax,%ds
17093 movl %eax,%es
17094- cmpl $2,early_recursion_flag
17095- je hlt_loop
17096- incl early_recursion_flag
17097 pushl 16(%esp)
17098 pushl 24(%esp)
17099 pushl 32(%esp)
17100@@ -656,29 +739,43 @@ ENTRY(setup_once_ref)
17101 /*
17102 * BSS section
17103 */
17104-__PAGE_ALIGNED_BSS
17105- .align PAGE_SIZE
17106 #ifdef CONFIG_X86_PAE
17107+.section .initial_pg_pmd,"a",@progbits
17108 initial_pg_pmd:
17109 .fill 1024*KPMDS,4,0
17110 #else
17111+.section .initial_page_table,"a",@progbits
17112 ENTRY(initial_page_table)
17113 .fill 1024,4,0
17114 #endif
17115+.section .initial_pg_fixmap,"a",@progbits
17116 initial_pg_fixmap:
17117 .fill 1024,4,0
17118+.section .empty_zero_page,"a",@progbits
17119 ENTRY(empty_zero_page)
17120 .fill 4096,1,0
17121+.section .swapper_pg_dir,"a",@progbits
17122 ENTRY(swapper_pg_dir)
17123+#ifdef CONFIG_X86_PAE
17124+ .fill 4,8,0
17125+#else
17126 .fill 1024,4,0
17127+#endif
17128+
17129+/*
17130+ * The IDT has to be page-aligned to simplify the Pentium
17131+ * F0 0F bug workaround.. We have a special link segment
17132+ * for this.
17133+ */
17134+.section .idt,"a",@progbits
17135+ENTRY(idt_table)
17136+ .fill 256,8,0
17137
17138 /*
17139 * This starts the data section.
17140 */
17141 #ifdef CONFIG_X86_PAE
17142-__PAGE_ALIGNED_DATA
17143- /* Page-aligned for the benefit of paravirt? */
17144- .align PAGE_SIZE
17145+.section .initial_page_table,"a",@progbits
17146 ENTRY(initial_page_table)
17147 .long pa(initial_pg_pmd+PGD_IDENT_ATTR),0 /* low identity map */
17148 # if KPMDS == 3
17149@@ -697,12 +794,20 @@ ENTRY(initial_page_table)
17150 # error "Kernel PMDs should be 1, 2 or 3"
17151 # endif
17152 .align PAGE_SIZE /* needs to be page-sized too */
17153+
17154+#ifdef CONFIG_PAX_PER_CPU_PGD
17155+ENTRY(cpu_pgd)
17156+ .rept NR_CPUS
17157+ .fill 4,8,0
17158+ .endr
17159+#endif
17160+
17161 #endif
17162
17163 .data
17164 .balign 4
17165 ENTRY(stack_start)
17166- .long init_thread_union+THREAD_SIZE
17167+ .long init_thread_union+THREAD_SIZE-8
17168
17169 __INITRODATA
17170 int_msg:
17171@@ -730,7 +835,7 @@ fault_msg:
17172 * segment size, and 32-bit linear address value:
17173 */
17174
17175- .data
17176+.section .rodata,"a",@progbits
17177 .globl boot_gdt_descr
17178 .globl idt_descr
17179
17180@@ -739,7 +844,7 @@ fault_msg:
17181 .word 0 # 32 bit align gdt_desc.address
17182 boot_gdt_descr:
17183 .word __BOOT_DS+7
17184- .long boot_gdt - __PAGE_OFFSET
17185+ .long pa(boot_gdt)
17186
17187 .word 0 # 32-bit align idt_desc.address
17188 idt_descr:
17189@@ -750,7 +855,7 @@ idt_descr:
17190 .word 0 # 32 bit align gdt_desc.address
17191 ENTRY(early_gdt_descr)
17192 .word GDT_ENTRIES*8-1
17193- .long gdt_page /* Overwritten for secondary CPUs */
17194+ .long cpu_gdt_table /* Overwritten for secondary CPUs */
17195
17196 /*
17197 * The boot_gdt must mirror the equivalent in setup.S and is
17198@@ -759,5 +864,65 @@ ENTRY(early_gdt_descr)
17199 .align L1_CACHE_BYTES
17200 ENTRY(boot_gdt)
17201 .fill GDT_ENTRY_BOOT_CS,8,0
17202- .quad 0x00cf9a000000ffff /* kernel 4GB code at 0x00000000 */
17203- .quad 0x00cf92000000ffff /* kernel 4GB data at 0x00000000 */
17204+ .quad 0x00cf9b000000ffff /* kernel 4GB code at 0x00000000 */
17205+ .quad 0x00cf93000000ffff /* kernel 4GB data at 0x00000000 */
17206+
17207+ .align PAGE_SIZE_asm
17208+ENTRY(cpu_gdt_table)
17209+ .rept NR_CPUS
17210+ .quad 0x0000000000000000 /* NULL descriptor */
17211+ .quad 0x0000000000000000 /* 0x0b reserved */
17212+ .quad 0x0000000000000000 /* 0x13 reserved */
17213+ .quad 0x0000000000000000 /* 0x1b reserved */
17214+
17215+#ifdef CONFIG_PAX_KERNEXEC
17216+ .quad 0x00cf9b000000ffff /* 0x20 alternate kernel 4GB code at 0x00000000 */
17217+#else
17218+ .quad 0x0000000000000000 /* 0x20 unused */
17219+#endif
17220+
17221+ .quad 0x0000000000000000 /* 0x28 unused */
17222+ .quad 0x0000000000000000 /* 0x33 TLS entry 1 */
17223+ .quad 0x0000000000000000 /* 0x3b TLS entry 2 */
17224+ .quad 0x0000000000000000 /* 0x43 TLS entry 3 */
17225+ .quad 0x0000000000000000 /* 0x4b reserved */
17226+ .quad 0x0000000000000000 /* 0x53 reserved */
17227+ .quad 0x0000000000000000 /* 0x5b reserved */
17228+
17229+ .quad 0x00cf9b000000ffff /* 0x60 kernel 4GB code at 0x00000000 */
17230+ .quad 0x00cf93000000ffff /* 0x68 kernel 4GB data at 0x00000000 */
17231+ .quad 0x00cffb000000ffff /* 0x73 user 4GB code at 0x00000000 */
17232+ .quad 0x00cff3000000ffff /* 0x7b user 4GB data at 0x00000000 */
17233+
17234+ .quad 0x0000000000000000 /* 0x80 TSS descriptor */
17235+ .quad 0x0000000000000000 /* 0x88 LDT descriptor */
17236+
17237+ /*
17238+ * Segments used for calling PnP BIOS have byte granularity.
17239+ * The code segments and data segments have fixed 64k limits,
17240+ * the transfer segment sizes are set at run time.
17241+ */
17242+ .quad 0x00409b000000ffff /* 0x90 32-bit code */
17243+ .quad 0x00009b000000ffff /* 0x98 16-bit code */
17244+ .quad 0x000093000000ffff /* 0xa0 16-bit data */
17245+ .quad 0x0000930000000000 /* 0xa8 16-bit data */
17246+ .quad 0x0000930000000000 /* 0xb0 16-bit data */
17247+
17248+ /*
17249+ * The APM segments have byte granularity and their bases
17250+ * are set at run time. All have 64k limits.
17251+ */
17252+ .quad 0x00409b000000ffff /* 0xb8 APM CS code */
17253+ .quad 0x00009b000000ffff /* 0xc0 APM CS 16 code (16 bit) */
17254+ .quad 0x004093000000ffff /* 0xc8 APM DS data */
17255+
17256+ .quad 0x00c0930000000000 /* 0xd0 - ESPFIX SS */
17257+ .quad 0x0040930000000000 /* 0xd8 - PERCPU */
17258+ .quad 0x0040910000000017 /* 0xe0 - STACK_CANARY */
17259+ .quad 0x0000000000000000 /* 0xe8 - PCIBIOS_CS */
17260+ .quad 0x0000000000000000 /* 0xf0 - PCIBIOS_DS */
17261+ .quad 0x0000000000000000 /* 0xf8 - GDT entry 31: double-fault TSS */
17262+
17263+ /* Be sure this is zeroed to avoid false validations in Xen */
17264+ .fill PAGE_SIZE_asm - GDT_SIZE,1,0
17265+ .endr
17266diff --git a/arch/x86/kernel/head_64.S b/arch/x86/kernel/head_64.S
17267index 94bf9cc..400455a 100644
17268--- a/arch/x86/kernel/head_64.S
17269+++ b/arch/x86/kernel/head_64.S
17270@@ -20,6 +20,8 @@
17271 #include <asm/processor-flags.h>
17272 #include <asm/percpu.h>
17273 #include <asm/nops.h>
17274+#include <asm/cpufeature.h>
17275+#include <asm/alternative-asm.h>
17276
17277 #ifdef CONFIG_PARAVIRT
17278 #include <asm/asm-offsets.h>
17279@@ -41,6 +43,12 @@ L4_PAGE_OFFSET = pgd_index(__PAGE_OFFSET)
17280 L3_PAGE_OFFSET = pud_index(__PAGE_OFFSET)
17281 L4_START_KERNEL = pgd_index(__START_KERNEL_map)
17282 L3_START_KERNEL = pud_index(__START_KERNEL_map)
17283+L4_VMALLOC_START = pgd_index(VMALLOC_START)
17284+L3_VMALLOC_START = pud_index(VMALLOC_START)
17285+L4_VMALLOC_END = pgd_index(VMALLOC_END)
17286+L3_VMALLOC_END = pud_index(VMALLOC_END)
17287+L4_VMEMMAP_START = pgd_index(VMEMMAP_START)
17288+L3_VMEMMAP_START = pud_index(VMEMMAP_START)
17289
17290 .text
17291 __HEAD
17292@@ -88,35 +96,23 @@ startup_64:
17293 */
17294 addq %rbp, init_level4_pgt + 0(%rip)
17295 addq %rbp, init_level4_pgt + (L4_PAGE_OFFSET*8)(%rip)
17296+ addq %rbp, init_level4_pgt + (L4_VMALLOC_START*8)(%rip)
17297+ addq %rbp, init_level4_pgt + (L4_VMALLOC_END*8)(%rip)
17298+ addq %rbp, init_level4_pgt + (L4_VMEMMAP_START*8)(%rip)
17299 addq %rbp, init_level4_pgt + (L4_START_KERNEL*8)(%rip)
17300
17301 addq %rbp, level3_ident_pgt + 0(%rip)
17302+#ifndef CONFIG_XEN
17303+ addq %rbp, level3_ident_pgt + 8(%rip)
17304+#endif
17305
17306- addq %rbp, level3_kernel_pgt + (510*8)(%rip)
17307- addq %rbp, level3_kernel_pgt + (511*8)(%rip)
17308+ addq %rbp, level3_vmemmap_pgt + (L3_VMEMMAP_START*8)(%rip)
17309+
17310+ addq %rbp, level3_kernel_pgt + (L3_START_KERNEL*8)(%rip)
17311+ addq %rbp, level3_kernel_pgt + (L3_START_KERNEL*8+8)(%rip)
17312
17313 addq %rbp, level2_fixmap_pgt + (506*8)(%rip)
17314-
17315- /* Add an Identity mapping if I am above 1G */
17316- leaq _text(%rip), %rdi
17317- andq $PMD_PAGE_MASK, %rdi
17318-
17319- movq %rdi, %rax
17320- shrq $PUD_SHIFT, %rax
17321- andq $(PTRS_PER_PUD - 1), %rax
17322- jz ident_complete
17323-
17324- leaq (level2_spare_pgt - __START_KERNEL_map + _KERNPG_TABLE)(%rbp), %rdx
17325- leaq level3_ident_pgt(%rip), %rbx
17326- movq %rdx, 0(%rbx, %rax, 8)
17327-
17328- movq %rdi, %rax
17329- shrq $PMD_SHIFT, %rax
17330- andq $(PTRS_PER_PMD - 1), %rax
17331- leaq __PAGE_KERNEL_IDENT_LARGE_EXEC(%rdi), %rdx
17332- leaq level2_spare_pgt(%rip), %rbx
17333- movq %rdx, 0(%rbx, %rax, 8)
17334-ident_complete:
17335+ addq %rbp, level2_fixmap_pgt + (507*8)(%rip)
17336
17337 /*
17338 * Fixup the kernel text+data virtual addresses. Note that
17339@@ -159,8 +155,8 @@ ENTRY(secondary_startup_64)
17340 * after the boot processor executes this code.
17341 */
17342
17343- /* Enable PAE mode and PGE */
17344- movl $(X86_CR4_PAE | X86_CR4_PGE), %eax
17345+ /* Enable PAE mode and PSE/PGE */
17346+ movl $(X86_CR4_PSE | X86_CR4_PAE | X86_CR4_PGE), %eax
17347 movq %rax, %cr4
17348
17349 /* Setup early boot stage 4 level pagetables. */
17350@@ -182,9 +178,17 @@ ENTRY(secondary_startup_64)
17351 movl $MSR_EFER, %ecx
17352 rdmsr
17353 btsl $_EFER_SCE, %eax /* Enable System Call */
17354- btl $20,%edi /* No Execute supported? */
17355+ btl $(X86_FEATURE_NX & 31),%edi /* No Execute supported? */
17356 jnc 1f
17357 btsl $_EFER_NX, %eax
17358+ leaq init_level4_pgt(%rip), %rdi
17359+#ifndef CONFIG_EFI
17360+ btsq $_PAGE_BIT_NX, 8*L4_PAGE_OFFSET(%rdi)
17361+#endif
17362+ btsq $_PAGE_BIT_NX, 8*L4_VMALLOC_START(%rdi)
17363+ btsq $_PAGE_BIT_NX, 8*L4_VMALLOC_END(%rdi)
17364+ btsq $_PAGE_BIT_NX, 8*L4_VMEMMAP_START(%rdi)
17365+ btsq $_PAGE_BIT_NX, __supported_pte_mask(%rip)
17366 1: wrmsr /* Make changes effective */
17367
17368 /* Setup cr0 */
17369@@ -246,6 +250,7 @@ ENTRY(secondary_startup_64)
17370 * jump. In addition we need to ensure %cs is set so we make this
17371 * a far return.
17372 */
17373+ pax_set_fptr_mask
17374 movq initial_code(%rip),%rax
17375 pushq $0 # fake return address to stop unwinder
17376 pushq $__KERNEL_CS # set correct cs
17377@@ -268,7 +273,7 @@ ENTRY(secondary_startup_64)
17378 bad_address:
17379 jmp bad_address
17380
17381- .section ".init.text","ax"
17382+ __INIT
17383 .globl early_idt_handlers
17384 early_idt_handlers:
17385 # 104(%rsp) %rflags
17386@@ -347,11 +352,15 @@ ENTRY(early_idt_handler)
17387 addq $16,%rsp # drop vector number and error code
17388 decl early_recursion_flag(%rip)
17389 INTERRUPT_RETURN
17390+ .previous
17391
17392+ __INITDATA
17393 .balign 4
17394 early_recursion_flag:
17395 .long 0
17396+ .previous
17397
17398+ .section .rodata,"a",@progbits
17399 #ifdef CONFIG_EARLY_PRINTK
17400 early_idt_msg:
17401 .asciz "PANIC: early exception %02lx rip %lx:%lx error %lx cr2 %lx\n"
17402@@ -360,6 +369,7 @@ early_idt_ripmsg:
17403 #endif /* CONFIG_EARLY_PRINTK */
17404 .previous
17405
17406+ .section .rodata,"a",@progbits
17407 #define NEXT_PAGE(name) \
17408 .balign PAGE_SIZE; \
17409 ENTRY(name)
17410@@ -372,7 +382,6 @@ ENTRY(name)
17411 i = i + 1 ; \
17412 .endr
17413
17414- .data
17415 /*
17416 * This default setting generates an ident mapping at address 0x100000
17417 * and a mapping for the kernel that precisely maps virtual address
17418@@ -383,13 +392,41 @@ NEXT_PAGE(init_level4_pgt)
17419 .quad level3_ident_pgt - __START_KERNEL_map + _KERNPG_TABLE
17420 .org init_level4_pgt + L4_PAGE_OFFSET*8, 0
17421 .quad level3_ident_pgt - __START_KERNEL_map + _KERNPG_TABLE
17422+ .org init_level4_pgt + L4_VMALLOC_START*8, 0
17423+ .quad level3_vmalloc_start_pgt - __START_KERNEL_map + _KERNPG_TABLE
17424+ .org init_level4_pgt + L4_VMALLOC_END*8, 0
17425+ .quad level3_vmalloc_end_pgt - __START_KERNEL_map + _KERNPG_TABLE
17426+ .org init_level4_pgt + L4_VMEMMAP_START*8, 0
17427+ .quad level3_vmemmap_pgt - __START_KERNEL_map + _KERNPG_TABLE
17428 .org init_level4_pgt + L4_START_KERNEL*8, 0
17429 /* (2^48-(2*1024*1024*1024))/(2^39) = 511 */
17430 .quad level3_kernel_pgt - __START_KERNEL_map + _PAGE_TABLE
17431
17432+#ifdef CONFIG_PAX_PER_CPU_PGD
17433+NEXT_PAGE(cpu_pgd)
17434+ .rept NR_CPUS
17435+ .fill 512,8,0
17436+ .endr
17437+#endif
17438+
17439 NEXT_PAGE(level3_ident_pgt)
17440 .quad level2_ident_pgt - __START_KERNEL_map + _KERNPG_TABLE
17441+#ifdef CONFIG_XEN
17442 .fill 511,8,0
17443+#else
17444+ .quad level2_ident_pgt + PAGE_SIZE - __START_KERNEL_map + _KERNPG_TABLE
17445+ .fill 510,8,0
17446+#endif
17447+
17448+NEXT_PAGE(level3_vmalloc_start_pgt)
17449+ .fill 512,8,0
17450+
17451+NEXT_PAGE(level3_vmalloc_end_pgt)
17452+ .fill 512,8,0
17453+
17454+NEXT_PAGE(level3_vmemmap_pgt)
17455+ .fill L3_VMEMMAP_START,8,0
17456+ .quad level2_vmemmap_pgt - __START_KERNEL_map + _KERNPG_TABLE
17457
17458 NEXT_PAGE(level3_kernel_pgt)
17459 .fill L3_START_KERNEL,8,0
17460@@ -397,20 +434,23 @@ NEXT_PAGE(level3_kernel_pgt)
17461 .quad level2_kernel_pgt - __START_KERNEL_map + _KERNPG_TABLE
17462 .quad level2_fixmap_pgt - __START_KERNEL_map + _PAGE_TABLE
17463
17464+NEXT_PAGE(level2_vmemmap_pgt)
17465+ .fill 512,8,0
17466+
17467 NEXT_PAGE(level2_fixmap_pgt)
17468- .fill 506,8,0
17469- .quad level1_fixmap_pgt - __START_KERNEL_map + _PAGE_TABLE
17470- /* 8MB reserved for vsyscalls + a 2MB hole = 4 + 1 entries */
17471- .fill 5,8,0
17472+ .fill 507,8,0
17473+ .quad level1_vsyscall_pgt - __START_KERNEL_map + _PAGE_TABLE
17474+ /* 6MB reserved for vsyscalls + a 2MB hole = 3 + 1 entries */
17475+ .fill 4,8,0
17476
17477-NEXT_PAGE(level1_fixmap_pgt)
17478+NEXT_PAGE(level1_vsyscall_pgt)
17479 .fill 512,8,0
17480
17481-NEXT_PAGE(level2_ident_pgt)
17482- /* Since I easily can, map the first 1G.
17483+ /* Since I easily can, map the first 2G.
17484 * Don't set NX because code runs from these pages.
17485 */
17486- PMDS(0, __PAGE_KERNEL_IDENT_LARGE_EXEC, PTRS_PER_PMD)
17487+NEXT_PAGE(level2_ident_pgt)
17488+ PMDS(0, __PAGE_KERNEL_IDENT_LARGE_EXEC, 2*PTRS_PER_PMD)
17489
17490 NEXT_PAGE(level2_kernel_pgt)
17491 /*
17492@@ -423,37 +463,59 @@ NEXT_PAGE(level2_kernel_pgt)
17493 * If you want to increase this then increase MODULES_VADDR
17494 * too.)
17495 */
17496- PMDS(0, __PAGE_KERNEL_LARGE_EXEC,
17497- KERNEL_IMAGE_SIZE/PMD_SIZE)
17498-
17499-NEXT_PAGE(level2_spare_pgt)
17500- .fill 512, 8, 0
17501+ PMDS(0, __PAGE_KERNEL_LARGE_EXEC, KERNEL_IMAGE_SIZE/PMD_SIZE)
17502
17503 #undef PMDS
17504 #undef NEXT_PAGE
17505
17506- .data
17507+ .align PAGE_SIZE
17508+ENTRY(cpu_gdt_table)
17509+ .rept NR_CPUS
17510+ .quad 0x0000000000000000 /* NULL descriptor */
17511+ .quad 0x00cf9b000000ffff /* __KERNEL32_CS */
17512+ .quad 0x00af9b000000ffff /* __KERNEL_CS */
17513+ .quad 0x00cf93000000ffff /* __KERNEL_DS */
17514+ .quad 0x00cffb000000ffff /* __USER32_CS */
17515+ .quad 0x00cff3000000ffff /* __USER_DS, __USER32_DS */
17516+ .quad 0x00affb000000ffff /* __USER_CS */
17517+
17518+#ifdef CONFIG_PAX_KERNEXEC
17519+ .quad 0x00af9b000000ffff /* __KERNEXEC_KERNEL_CS */
17520+#else
17521+ .quad 0x0 /* unused */
17522+#endif
17523+
17524+ .quad 0,0 /* TSS */
17525+ .quad 0,0 /* LDT */
17526+ .quad 0,0,0 /* three TLS descriptors */
17527+ .quad 0x0000f40000000000 /* node/CPU stored in limit */
17528+ /* asm/segment.h:GDT_ENTRIES must match this */
17529+
17530+ /* zero the remaining page */
17531+ .fill PAGE_SIZE / 8 - GDT_ENTRIES,8,0
17532+ .endr
17533+
17534 .align 16
17535 .globl early_gdt_descr
17536 early_gdt_descr:
17537 .word GDT_ENTRIES*8-1
17538 early_gdt_descr_base:
17539- .quad INIT_PER_CPU_VAR(gdt_page)
17540+ .quad cpu_gdt_table
17541
17542 ENTRY(phys_base)
17543 /* This must match the first entry in level2_kernel_pgt */
17544 .quad 0x0000000000000000
17545
17546 #include "../../x86/xen/xen-head.S"
17547-
17548- .section .bss, "aw", @nobits
17549+
17550+ .section .rodata,"a",@progbits
17551 .align L1_CACHE_BYTES
17552 ENTRY(idt_table)
17553- .skip IDT_ENTRIES * 16
17554+ .fill 512,8,0
17555
17556 .align L1_CACHE_BYTES
17557 ENTRY(nmi_idt_table)
17558- .skip IDT_ENTRIES * 16
17559+ .fill 512,8,0
17560
17561 __PAGE_ALIGNED_BSS
17562 .align PAGE_SIZE
17563diff --git a/arch/x86/kernel/i386_ksyms_32.c b/arch/x86/kernel/i386_ksyms_32.c
17564index 9c3bd4a..e1d9b35 100644
17565--- a/arch/x86/kernel/i386_ksyms_32.c
17566+++ b/arch/x86/kernel/i386_ksyms_32.c
17567@@ -20,8 +20,12 @@ extern void cmpxchg8b_emu(void);
17568 EXPORT_SYMBOL(cmpxchg8b_emu);
17569 #endif
17570
17571+EXPORT_SYMBOL_GPL(cpu_gdt_table);
17572+
17573 /* Networking helper routines. */
17574 EXPORT_SYMBOL(csum_partial_copy_generic);
17575+EXPORT_SYMBOL(csum_partial_copy_generic_to_user);
17576+EXPORT_SYMBOL(csum_partial_copy_generic_from_user);
17577
17578 EXPORT_SYMBOL(__get_user_1);
17579 EXPORT_SYMBOL(__get_user_2);
17580@@ -36,3 +40,7 @@ EXPORT_SYMBOL(strstr);
17581
17582 EXPORT_SYMBOL(csum_partial);
17583 EXPORT_SYMBOL(empty_zero_page);
17584+
17585+#ifdef CONFIG_PAX_KERNEXEC
17586+EXPORT_SYMBOL(__LOAD_PHYSICAL_ADDR);
17587+#endif
17588diff --git a/arch/x86/kernel/i387.c b/arch/x86/kernel/i387.c
17589index f250431..54097e7 100644
17590--- a/arch/x86/kernel/i387.c
17591+++ b/arch/x86/kernel/i387.c
17592@@ -59,7 +59,7 @@ static inline bool interrupted_kernel_fpu_idle(void)
17593 static inline bool interrupted_user_mode(void)
17594 {
17595 struct pt_regs *regs = get_irq_regs();
17596- return regs && user_mode_vm(regs);
17597+ return regs && user_mode(regs);
17598 }
17599
17600 /*
17601diff --git a/arch/x86/kernel/i8259.c b/arch/x86/kernel/i8259.c
17602index 36d1853..bf25736 100644
17603--- a/arch/x86/kernel/i8259.c
17604+++ b/arch/x86/kernel/i8259.c
17605@@ -209,7 +209,7 @@ spurious_8259A_irq:
17606 "spurious 8259A interrupt: IRQ%d.\n", irq);
17607 spurious_irq_mask |= irqmask;
17608 }
17609- atomic_inc(&irq_err_count);
17610+ atomic_inc_unchecked(&irq_err_count);
17611 /*
17612 * Theoretically we do not have to handle this IRQ,
17613 * but in Linux this does not cause problems and is
17614diff --git a/arch/x86/kernel/ioport.c b/arch/x86/kernel/ioport.c
17615index 8c96897..be66bfa 100644
17616--- a/arch/x86/kernel/ioport.c
17617+++ b/arch/x86/kernel/ioport.c
17618@@ -6,6 +6,7 @@
17619 #include <linux/sched.h>
17620 #include <linux/kernel.h>
17621 #include <linux/capability.h>
17622+#include <linux/security.h>
17623 #include <linux/errno.h>
17624 #include <linux/types.h>
17625 #include <linux/ioport.h>
17626@@ -28,6 +29,12 @@ asmlinkage long sys_ioperm(unsigned long from, unsigned long num, int turn_on)
17627
17628 if ((from + num <= from) || (from + num > IO_BITMAP_BITS))
17629 return -EINVAL;
17630+#ifdef CONFIG_GRKERNSEC_IO
17631+ if (turn_on && grsec_disable_privio) {
17632+ gr_handle_ioperm();
17633+ return -EPERM;
17634+ }
17635+#endif
17636 if (turn_on && !capable(CAP_SYS_RAWIO))
17637 return -EPERM;
17638
17639@@ -54,7 +61,7 @@ asmlinkage long sys_ioperm(unsigned long from, unsigned long num, int turn_on)
17640 * because the ->io_bitmap_max value must match the bitmap
17641 * contents:
17642 */
17643- tss = &per_cpu(init_tss, get_cpu());
17644+ tss = init_tss + get_cpu();
17645
17646 if (turn_on)
17647 bitmap_clear(t->io_bitmap_ptr, from, num);
17648@@ -102,6 +109,12 @@ long sys_iopl(unsigned int level, struct pt_regs *regs)
17649 return -EINVAL;
17650 /* Trying to gain more privileges? */
17651 if (level > old) {
17652+#ifdef CONFIG_GRKERNSEC_IO
17653+ if (grsec_disable_privio) {
17654+ gr_handle_iopl();
17655+ return -EPERM;
17656+ }
17657+#endif
17658 if (!capable(CAP_SYS_RAWIO))
17659 return -EPERM;
17660 }
17661diff --git a/arch/x86/kernel/irq.c b/arch/x86/kernel/irq.c
17662index d44f782..31ab01e 100644
17663--- a/arch/x86/kernel/irq.c
17664+++ b/arch/x86/kernel/irq.c
17665@@ -18,7 +18,7 @@
17666 #include <asm/mce.h>
17667 #include <asm/hw_irq.h>
17668
17669-atomic_t irq_err_count;
17670+atomic_unchecked_t irq_err_count;
17671
17672 /* Function pointer for generic interrupt vector handling */
17673 void (*x86_platform_ipi_callback)(void) = NULL;
17674@@ -121,9 +121,9 @@ int arch_show_interrupts(struct seq_file *p, int prec)
17675 seq_printf(p, "%10u ", per_cpu(mce_poll_count, j));
17676 seq_printf(p, " Machine check polls\n");
17677 #endif
17678- seq_printf(p, "%*s: %10u\n", prec, "ERR", atomic_read(&irq_err_count));
17679+ seq_printf(p, "%*s: %10u\n", prec, "ERR", atomic_read_unchecked(&irq_err_count));
17680 #if defined(CONFIG_X86_IO_APIC)
17681- seq_printf(p, "%*s: %10u\n", prec, "MIS", atomic_read(&irq_mis_count));
17682+ seq_printf(p, "%*s: %10u\n", prec, "MIS", atomic_read_unchecked(&irq_mis_count));
17683 #endif
17684 return 0;
17685 }
17686@@ -164,10 +164,10 @@ u64 arch_irq_stat_cpu(unsigned int cpu)
17687
17688 u64 arch_irq_stat(void)
17689 {
17690- u64 sum = atomic_read(&irq_err_count);
17691+ u64 sum = atomic_read_unchecked(&irq_err_count);
17692
17693 #ifdef CONFIG_X86_IO_APIC
17694- sum += atomic_read(&irq_mis_count);
17695+ sum += atomic_read_unchecked(&irq_mis_count);
17696 #endif
17697 return sum;
17698 }
17699diff --git a/arch/x86/kernel/irq_32.c b/arch/x86/kernel/irq_32.c
17700index 344faf8..355f60d 100644
17701--- a/arch/x86/kernel/irq_32.c
17702+++ b/arch/x86/kernel/irq_32.c
17703@@ -39,7 +39,7 @@ static int check_stack_overflow(void)
17704 __asm__ __volatile__("andl %%esp,%0" :
17705 "=r" (sp) : "0" (THREAD_SIZE - 1));
17706
17707- return sp < (sizeof(struct thread_info) + STACK_WARN);
17708+ return sp < STACK_WARN;
17709 }
17710
17711 static void print_stack_overflow(void)
17712@@ -59,8 +59,8 @@ static inline void print_stack_overflow(void) { }
17713 * per-CPU IRQ handling contexts (thread information and stack)
17714 */
17715 union irq_ctx {
17716- struct thread_info tinfo;
17717- u32 stack[THREAD_SIZE/sizeof(u32)];
17718+ unsigned long previous_esp;
17719+ u32 stack[THREAD_SIZE/sizeof(u32)];
17720 } __attribute__((aligned(THREAD_SIZE)));
17721
17722 static DEFINE_PER_CPU(union irq_ctx *, hardirq_ctx);
17723@@ -80,10 +80,9 @@ static void call_on_stack(void *func, void *stack)
17724 static inline int
17725 execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
17726 {
17727- union irq_ctx *curctx, *irqctx;
17728+ union irq_ctx *irqctx;
17729 u32 *isp, arg1, arg2;
17730
17731- curctx = (union irq_ctx *) current_thread_info();
17732 irqctx = __this_cpu_read(hardirq_ctx);
17733
17734 /*
17735@@ -92,16 +91,16 @@ execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
17736 * handler) we can't do that and just have to keep using the
17737 * current stack (which is the irq stack already after all)
17738 */
17739- if (unlikely(curctx == irqctx))
17740+ if (unlikely((void *)current_stack_pointer - (void *)irqctx < THREAD_SIZE))
17741 return 0;
17742
17743 /* build the stack frame on the IRQ stack */
17744- isp = (u32 *) ((char *)irqctx + sizeof(*irqctx));
17745- irqctx->tinfo.task = curctx->tinfo.task;
17746- irqctx->tinfo.previous_esp = current_stack_pointer;
17747+ isp = (u32 *) ((char *)irqctx + sizeof(*irqctx) - 8);
17748+ irqctx->previous_esp = current_stack_pointer;
17749
17750- /* Copy the preempt_count so that the [soft]irq checks work. */
17751- irqctx->tinfo.preempt_count = curctx->tinfo.preempt_count;
17752+#ifdef CONFIG_PAX_MEMORY_UDEREF
17753+ __set_fs(MAKE_MM_SEG(0));
17754+#endif
17755
17756 if (unlikely(overflow))
17757 call_on_stack(print_stack_overflow, isp);
17758@@ -113,6 +112,11 @@ execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
17759 : "0" (irq), "1" (desc), "2" (isp),
17760 "D" (desc->handle_irq)
17761 : "memory", "cc", "ecx");
17762+
17763+#ifdef CONFIG_PAX_MEMORY_UDEREF
17764+ __set_fs(current_thread_info()->addr_limit);
17765+#endif
17766+
17767 return 1;
17768 }
17769
17770@@ -121,29 +125,14 @@ execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
17771 */
17772 void __cpuinit irq_ctx_init(int cpu)
17773 {
17774- union irq_ctx *irqctx;
17775-
17776 if (per_cpu(hardirq_ctx, cpu))
17777 return;
17778
17779- irqctx = page_address(alloc_pages_node(cpu_to_node(cpu),
17780- THREADINFO_GFP,
17781- THREAD_SIZE_ORDER));
17782- memset(&irqctx->tinfo, 0, sizeof(struct thread_info));
17783- irqctx->tinfo.cpu = cpu;
17784- irqctx->tinfo.preempt_count = HARDIRQ_OFFSET;
17785- irqctx->tinfo.addr_limit = MAKE_MM_SEG(0);
17786-
17787- per_cpu(hardirq_ctx, cpu) = irqctx;
17788-
17789- irqctx = page_address(alloc_pages_node(cpu_to_node(cpu),
17790- THREADINFO_GFP,
17791- THREAD_SIZE_ORDER));
17792- memset(&irqctx->tinfo, 0, sizeof(struct thread_info));
17793- irqctx->tinfo.cpu = cpu;
17794- irqctx->tinfo.addr_limit = MAKE_MM_SEG(0);
17795-
17796- per_cpu(softirq_ctx, cpu) = irqctx;
17797+ per_cpu(hardirq_ctx, cpu) = page_address(alloc_pages_node(cpu_to_node(cpu), THREADINFO_GFP, THREAD_SIZE_ORDER));
17798+ per_cpu(softirq_ctx, cpu) = page_address(alloc_pages_node(cpu_to_node(cpu), THREADINFO_GFP, THREAD_SIZE_ORDER));
17799+
17800+ printk(KERN_DEBUG "CPU %u irqstacks, hard=%p soft=%p\n",
17801+ cpu, per_cpu(hardirq_ctx, cpu), per_cpu(softirq_ctx, cpu));
17802
17803 printk(KERN_DEBUG "CPU %u irqstacks, hard=%p soft=%p\n",
17804 cpu, per_cpu(hardirq_ctx, cpu), per_cpu(softirq_ctx, cpu));
17805@@ -152,7 +141,6 @@ void __cpuinit irq_ctx_init(int cpu)
17806 asmlinkage void do_softirq(void)
17807 {
17808 unsigned long flags;
17809- struct thread_info *curctx;
17810 union irq_ctx *irqctx;
17811 u32 *isp;
17812
17813@@ -162,15 +150,22 @@ asmlinkage void do_softirq(void)
17814 local_irq_save(flags);
17815
17816 if (local_softirq_pending()) {
17817- curctx = current_thread_info();
17818 irqctx = __this_cpu_read(softirq_ctx);
17819- irqctx->tinfo.task = curctx->task;
17820- irqctx->tinfo.previous_esp = current_stack_pointer;
17821+ irqctx->previous_esp = current_stack_pointer;
17822
17823 /* build the stack frame on the softirq stack */
17824- isp = (u32 *) ((char *)irqctx + sizeof(*irqctx));
17825+ isp = (u32 *) ((char *)irqctx + sizeof(*irqctx) - 8);
17826+
17827+#ifdef CONFIG_PAX_MEMORY_UDEREF
17828+ __set_fs(MAKE_MM_SEG(0));
17829+#endif
17830
17831 call_on_stack(__do_softirq, isp);
17832+
17833+#ifdef CONFIG_PAX_MEMORY_UDEREF
17834+ __set_fs(current_thread_info()->addr_limit);
17835+#endif
17836+
17837 /*
17838 * Shouldn't happen, we returned above if in_interrupt():
17839 */
17840@@ -191,7 +186,7 @@ bool handle_irq(unsigned irq, struct pt_regs *regs)
17841 if (unlikely(!desc))
17842 return false;
17843
17844- if (user_mode_vm(regs) || !execute_on_irq_stack(overflow, desc, irq)) {
17845+ if (user_mode(regs) || !execute_on_irq_stack(overflow, desc, irq)) {
17846 if (unlikely(overflow))
17847 print_stack_overflow();
17848 desc->handle_irq(irq, desc);
17849diff --git a/arch/x86/kernel/irq_64.c b/arch/x86/kernel/irq_64.c
17850index d04d3ec..ea4b374 100644
17851--- a/arch/x86/kernel/irq_64.c
17852+++ b/arch/x86/kernel/irq_64.c
17853@@ -44,7 +44,7 @@ static inline void stack_overflow_check(struct pt_regs *regs)
17854 u64 estack_top, estack_bottom;
17855 u64 curbase = (u64)task_stack_page(current);
17856
17857- if (user_mode_vm(regs))
17858+ if (user_mode(regs))
17859 return;
17860
17861 if (regs->sp >= curbase + sizeof(struct thread_info) +
17862diff --git a/arch/x86/kernel/kdebugfs.c b/arch/x86/kernel/kdebugfs.c
17863index dc1404b..bbc43e7 100644
17864--- a/arch/x86/kernel/kdebugfs.c
17865+++ b/arch/x86/kernel/kdebugfs.c
17866@@ -27,7 +27,7 @@ struct setup_data_node {
17867 u32 len;
17868 };
17869
17870-static ssize_t setup_data_read(struct file *file, char __user *user_buf,
17871+static ssize_t __size_overflow(3) setup_data_read(struct file *file, char __user *user_buf,
17872 size_t count, loff_t *ppos)
17873 {
17874 struct setup_data_node *node = file->private_data;
17875diff --git a/arch/x86/kernel/kgdb.c b/arch/x86/kernel/kgdb.c
17876index 3f61904..873cea9 100644
17877--- a/arch/x86/kernel/kgdb.c
17878+++ b/arch/x86/kernel/kgdb.c
17879@@ -127,11 +127,11 @@ char *dbg_get_reg(int regno, void *mem, struct pt_regs *regs)
17880 #ifdef CONFIG_X86_32
17881 switch (regno) {
17882 case GDB_SS:
17883- if (!user_mode_vm(regs))
17884+ if (!user_mode(regs))
17885 *(unsigned long *)mem = __KERNEL_DS;
17886 break;
17887 case GDB_SP:
17888- if (!user_mode_vm(regs))
17889+ if (!user_mode(regs))
17890 *(unsigned long *)mem = kernel_stack_pointer(regs);
17891 break;
17892 case GDB_GS:
17893@@ -476,12 +476,12 @@ int kgdb_arch_handle_exception(int e_vector, int signo, int err_code,
17894 case 'k':
17895 /* clear the trace bit */
17896 linux_regs->flags &= ~X86_EFLAGS_TF;
17897- atomic_set(&kgdb_cpu_doing_single_step, -1);
17898+ atomic_set_unchecked(&kgdb_cpu_doing_single_step, -1);
17899
17900 /* set the trace bit if we're stepping */
17901 if (remcomInBuffer[0] == 's') {
17902 linux_regs->flags |= X86_EFLAGS_TF;
17903- atomic_set(&kgdb_cpu_doing_single_step,
17904+ atomic_set_unchecked(&kgdb_cpu_doing_single_step,
17905 raw_smp_processor_id());
17906 }
17907
17908@@ -546,7 +546,7 @@ static int __kgdb_notify(struct die_args *args, unsigned long cmd)
17909
17910 switch (cmd) {
17911 case DIE_DEBUG:
17912- if (atomic_read(&kgdb_cpu_doing_single_step) != -1) {
17913+ if (atomic_read_unchecked(&kgdb_cpu_doing_single_step) != -1) {
17914 if (user_mode(regs))
17915 return single_step_cont(regs, args);
17916 break;
17917diff --git a/arch/x86/kernel/kprobes-opt.c b/arch/x86/kernel/kprobes-opt.c
17918index c5e410e..da6aaf9 100644
17919--- a/arch/x86/kernel/kprobes-opt.c
17920+++ b/arch/x86/kernel/kprobes-opt.c
17921@@ -338,7 +338,7 @@ int __kprobes arch_prepare_optimized_kprobe(struct optimized_kprobe *op)
17922 * Verify if the address gap is in 2GB range, because this uses
17923 * a relative jump.
17924 */
17925- rel = (long)op->optinsn.insn - (long)op->kp.addr + RELATIVEJUMP_SIZE;
17926+ rel = (long)op->optinsn.insn - ktla_ktva((long)op->kp.addr) + RELATIVEJUMP_SIZE;
17927 if (abs(rel) > 0x7fffffff)
17928 return -ERANGE;
17929
17930@@ -359,11 +359,11 @@ int __kprobes arch_prepare_optimized_kprobe(struct optimized_kprobe *op)
17931 synthesize_set_arg1(buf + TMPL_MOVE_IDX, (unsigned long)op);
17932
17933 /* Set probe function call */
17934- synthesize_relcall(buf + TMPL_CALL_IDX, optimized_callback);
17935+ synthesize_relcall(buf + TMPL_CALL_IDX, ktla_ktva(optimized_callback));
17936
17937 /* Set returning jmp instruction at the tail of out-of-line buffer */
17938 synthesize_reljump(buf + TMPL_END_IDX + op->optinsn.size,
17939- (u8 *)op->kp.addr + op->optinsn.size);
17940+ (u8 *)ktla_ktva(op->kp.addr) + op->optinsn.size);
17941
17942 flush_icache_range((unsigned long) buf,
17943 (unsigned long) buf + TMPL_END_IDX +
17944@@ -385,7 +385,7 @@ static void __kprobes setup_optimize_kprobe(struct text_poke_param *tprm,
17945 ((long)op->kp.addr + RELATIVEJUMP_SIZE));
17946
17947 /* Backup instructions which will be replaced by jump address */
17948- memcpy(op->optinsn.copied_insn, op->kp.addr + INT3_SIZE,
17949+ memcpy(op->optinsn.copied_insn, ktla_ktva(op->kp.addr) + INT3_SIZE,
17950 RELATIVE_ADDR_SIZE);
17951
17952 insn_buf[0] = RELATIVEJUMP_OPCODE;
17953diff --git a/arch/x86/kernel/kprobes.c b/arch/x86/kernel/kprobes.c
17954index e2f751e..dffa2a0 100644
17955--- a/arch/x86/kernel/kprobes.c
17956+++ b/arch/x86/kernel/kprobes.c
17957@@ -120,8 +120,11 @@ static void __kprobes __synthesize_relative_insn(void *from, void *to, u8 op)
17958 } __attribute__((packed)) *insn;
17959
17960 insn = (struct __arch_relative_insn *)from;
17961+
17962+ pax_open_kernel();
17963 insn->raddr = (s32)((long)(to) - ((long)(from) + 5));
17964 insn->op = op;
17965+ pax_close_kernel();
17966 }
17967
17968 /* Insert a jump instruction at address 'from', which jumps to address 'to'.*/
17969@@ -164,7 +167,7 @@ int __kprobes can_boost(kprobe_opcode_t *opcodes)
17970 kprobe_opcode_t opcode;
17971 kprobe_opcode_t *orig_opcodes = opcodes;
17972
17973- if (search_exception_tables((unsigned long)opcodes))
17974+ if (search_exception_tables(ktva_ktla((unsigned long)opcodes)))
17975 return 0; /* Page fault may occur on this address. */
17976
17977 retry:
17978@@ -332,7 +335,9 @@ int __kprobes __copy_instruction(u8 *dest, u8 *src)
17979 /* Another subsystem puts a breakpoint, failed to recover */
17980 if (insn.opcode.bytes[0] == BREAKPOINT_INSTRUCTION)
17981 return 0;
17982+ pax_open_kernel();
17983 memcpy(dest, insn.kaddr, insn.length);
17984+ pax_close_kernel();
17985
17986 #ifdef CONFIG_X86_64
17987 if (insn_rip_relative(&insn)) {
17988@@ -355,7 +360,9 @@ int __kprobes __copy_instruction(u8 *dest, u8 *src)
17989 newdisp = (u8 *) src + (s64) insn.displacement.value - (u8 *) dest;
17990 BUG_ON((s64) (s32) newdisp != newdisp); /* Sanity check. */
17991 disp = (u8 *) dest + insn_offset_displacement(&insn);
17992+ pax_open_kernel();
17993 *(s32 *) disp = (s32) newdisp;
17994+ pax_close_kernel();
17995 }
17996 #endif
17997 return insn.length;
17998@@ -485,7 +492,7 @@ setup_singlestep(struct kprobe *p, struct pt_regs *regs, struct kprobe_ctlblk *k
17999 * nor set current_kprobe, because it doesn't use single
18000 * stepping.
18001 */
18002- regs->ip = (unsigned long)p->ainsn.insn;
18003+ regs->ip = ktva_ktla((unsigned long)p->ainsn.insn);
18004 preempt_enable_no_resched();
18005 return;
18006 }
18007@@ -504,7 +511,7 @@ setup_singlestep(struct kprobe *p, struct pt_regs *regs, struct kprobe_ctlblk *k
18008 if (p->opcode == BREAKPOINT_INSTRUCTION)
18009 regs->ip = (unsigned long)p->addr;
18010 else
18011- regs->ip = (unsigned long)p->ainsn.insn;
18012+ regs->ip = ktva_ktla((unsigned long)p->ainsn.insn);
18013 }
18014
18015 /*
18016@@ -583,7 +590,7 @@ static int __kprobes kprobe_handler(struct pt_regs *regs)
18017 setup_singlestep(p, regs, kcb, 0);
18018 return 1;
18019 }
18020- } else if (*addr != BREAKPOINT_INSTRUCTION) {
18021+ } else if (*(kprobe_opcode_t *)ktla_ktva((unsigned long)addr) != BREAKPOINT_INSTRUCTION) {
18022 /*
18023 * The breakpoint instruction was removed right
18024 * after we hit it. Another cpu has removed
18025@@ -628,6 +635,9 @@ static void __used __kprobes kretprobe_trampoline_holder(void)
18026 " movq %rax, 152(%rsp)\n"
18027 RESTORE_REGS_STRING
18028 " popfq\n"
18029+#ifdef KERNEXEC_PLUGIN
18030+ " btsq $63,(%rsp)\n"
18031+#endif
18032 #else
18033 " pushf\n"
18034 SAVE_REGS_STRING
18035@@ -765,7 +775,7 @@ static void __kprobes
18036 resume_execution(struct kprobe *p, struct pt_regs *regs, struct kprobe_ctlblk *kcb)
18037 {
18038 unsigned long *tos = stack_addr(regs);
18039- unsigned long copy_ip = (unsigned long)p->ainsn.insn;
18040+ unsigned long copy_ip = ktva_ktla((unsigned long)p->ainsn.insn);
18041 unsigned long orig_ip = (unsigned long)p->addr;
18042 kprobe_opcode_t *insn = p->ainsn.insn;
18043
18044@@ -947,7 +957,7 @@ kprobe_exceptions_notify(struct notifier_block *self, unsigned long val, void *d
18045 struct die_args *args = data;
18046 int ret = NOTIFY_DONE;
18047
18048- if (args->regs && user_mode_vm(args->regs))
18049+ if (args->regs && user_mode(args->regs))
18050 return ret;
18051
18052 switch (val) {
18053diff --git a/arch/x86/kernel/ldt.c b/arch/x86/kernel/ldt.c
18054index ebc9873..1b9724b 100644
18055--- a/arch/x86/kernel/ldt.c
18056+++ b/arch/x86/kernel/ldt.c
18057@@ -66,13 +66,13 @@ static int alloc_ldt(mm_context_t *pc, int mincount, int reload)
18058 if (reload) {
18059 #ifdef CONFIG_SMP
18060 preempt_disable();
18061- load_LDT(pc);
18062+ load_LDT_nolock(pc);
18063 if (!cpumask_equal(mm_cpumask(current->mm),
18064 cpumask_of(smp_processor_id())))
18065 smp_call_function(flush_ldt, current->mm, 1);
18066 preempt_enable();
18067 #else
18068- load_LDT(pc);
18069+ load_LDT_nolock(pc);
18070 #endif
18071 }
18072 if (oldsize) {
18073@@ -94,7 +94,7 @@ static inline int copy_ldt(mm_context_t *new, mm_context_t *old)
18074 return err;
18075
18076 for (i = 0; i < old->size; i++)
18077- write_ldt_entry(new->ldt, i, old->ldt + i * LDT_ENTRY_SIZE);
18078+ write_ldt_entry(new->ldt, i, old->ldt + i);
18079 return 0;
18080 }
18081
18082@@ -115,6 +115,24 @@ int init_new_context(struct task_struct *tsk, struct mm_struct *mm)
18083 retval = copy_ldt(&mm->context, &old_mm->context);
18084 mutex_unlock(&old_mm->context.lock);
18085 }
18086+
18087+ if (tsk == current) {
18088+ mm->context.vdso = 0;
18089+
18090+#ifdef CONFIG_X86_32
18091+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
18092+ mm->context.user_cs_base = 0UL;
18093+ mm->context.user_cs_limit = ~0UL;
18094+
18095+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_SMP)
18096+ cpus_clear(mm->context.cpu_user_cs_mask);
18097+#endif
18098+
18099+#endif
18100+#endif
18101+
18102+ }
18103+
18104 return retval;
18105 }
18106
18107@@ -229,6 +247,13 @@ static int write_ldt(void __user *ptr, unsigned long bytecount, int oldmode)
18108 }
18109 }
18110
18111+#ifdef CONFIG_PAX_SEGMEXEC
18112+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (ldt_info.contents & MODIFY_LDT_CONTENTS_CODE)) {
18113+ error = -EINVAL;
18114+ goto out_unlock;
18115+ }
18116+#endif
18117+
18118 fill_ldt(&ldt, &ldt_info);
18119 if (oldmode)
18120 ldt.avl = 0;
18121diff --git a/arch/x86/kernel/machine_kexec_32.c b/arch/x86/kernel/machine_kexec_32.c
18122index 5b19e4d..6476a76 100644
18123--- a/arch/x86/kernel/machine_kexec_32.c
18124+++ b/arch/x86/kernel/machine_kexec_32.c
18125@@ -26,7 +26,7 @@
18126 #include <asm/cacheflush.h>
18127 #include <asm/debugreg.h>
18128
18129-static void set_idt(void *newidt, __u16 limit)
18130+static void set_idt(struct desc_struct *newidt, __u16 limit)
18131 {
18132 struct desc_ptr curidt;
18133
18134@@ -38,7 +38,7 @@ static void set_idt(void *newidt, __u16 limit)
18135 }
18136
18137
18138-static void set_gdt(void *newgdt, __u16 limit)
18139+static void set_gdt(struct desc_struct *newgdt, __u16 limit)
18140 {
18141 struct desc_ptr curgdt;
18142
18143@@ -216,7 +216,7 @@ void machine_kexec(struct kimage *image)
18144 }
18145
18146 control_page = page_address(image->control_code_page);
18147- memcpy(control_page, relocate_kernel, KEXEC_CONTROL_CODE_MAX_SIZE);
18148+ memcpy(control_page, (void *)ktla_ktva((unsigned long)relocate_kernel), KEXEC_CONTROL_CODE_MAX_SIZE);
18149
18150 relocate_kernel_ptr = control_page;
18151 page_list[PA_CONTROL_PAGE] = __pa(control_page);
18152diff --git a/arch/x86/kernel/microcode_intel.c b/arch/x86/kernel/microcode_intel.c
18153index 0327e2b..e43737b 100644
18154--- a/arch/x86/kernel/microcode_intel.c
18155+++ b/arch/x86/kernel/microcode_intel.c
18156@@ -430,13 +430,13 @@ static enum ucode_state request_microcode_fw(int cpu, struct device *device)
18157
18158 static int get_ucode_user(void *to, const void *from, size_t n)
18159 {
18160- return copy_from_user(to, from, n);
18161+ return copy_from_user(to, (const void __force_user *)from, n);
18162 }
18163
18164 static enum ucode_state
18165 request_microcode_user(int cpu, const void __user *buf, size_t size)
18166 {
18167- return generic_load_microcode(cpu, (void *)buf, size, &get_ucode_user);
18168+ return generic_load_microcode(cpu, (__force_kernel void *)buf, size, &get_ucode_user);
18169 }
18170
18171 static void microcode_fini_cpu(int cpu)
18172diff --git a/arch/x86/kernel/module.c b/arch/x86/kernel/module.c
18173index 216a4d7..b328f09 100644
18174--- a/arch/x86/kernel/module.c
18175+++ b/arch/x86/kernel/module.c
18176@@ -43,15 +43,60 @@ do { \
18177 } while (0)
18178 #endif
18179
18180-void *module_alloc(unsigned long size)
18181+static inline void *__module_alloc(unsigned long size, pgprot_t prot)
18182 {
18183- if (PAGE_ALIGN(size) > MODULES_LEN)
18184+ if (size == 0 || PAGE_ALIGN(size) > MODULES_LEN)
18185 return NULL;
18186 return __vmalloc_node_range(size, 1, MODULES_VADDR, MODULES_END,
18187- GFP_KERNEL | __GFP_HIGHMEM, PAGE_KERNEL_EXEC,
18188+ GFP_KERNEL | __GFP_HIGHMEM | __GFP_ZERO, prot,
18189 -1, __builtin_return_address(0));
18190 }
18191
18192+void *module_alloc(unsigned long size)
18193+{
18194+
18195+#ifdef CONFIG_PAX_KERNEXEC
18196+ return __module_alloc(size, PAGE_KERNEL);
18197+#else
18198+ return __module_alloc(size, PAGE_KERNEL_EXEC);
18199+#endif
18200+
18201+}
18202+
18203+#ifdef CONFIG_PAX_KERNEXEC
18204+#ifdef CONFIG_X86_32
18205+void *module_alloc_exec(unsigned long size)
18206+{
18207+ struct vm_struct *area;
18208+
18209+ if (size == 0)
18210+ return NULL;
18211+
18212+ area = __get_vm_area(size, VM_ALLOC, (unsigned long)&MODULES_EXEC_VADDR, (unsigned long)&MODULES_EXEC_END);
18213+ return area ? area->addr : NULL;
18214+}
18215+EXPORT_SYMBOL(module_alloc_exec);
18216+
18217+void module_free_exec(struct module *mod, void *module_region)
18218+{
18219+ vunmap(module_region);
18220+}
18221+EXPORT_SYMBOL(module_free_exec);
18222+#else
18223+void module_free_exec(struct module *mod, void *module_region)
18224+{
18225+ module_free(mod, module_region);
18226+}
18227+EXPORT_SYMBOL(module_free_exec);
18228+
18229+void *module_alloc_exec(unsigned long size)
18230+{
18231+ return __module_alloc(size, PAGE_KERNEL_RX);
18232+}
18233+EXPORT_SYMBOL(module_alloc_exec);
18234+#endif
18235+#endif
18236+
18237 #ifdef CONFIG_X86_32
18238 int apply_relocate(Elf32_Shdr *sechdrs,
18239 const char *strtab,
18240@@ -62,14 +107,16 @@ int apply_relocate(Elf32_Shdr *sechdrs,
18241 unsigned int i;
18242 Elf32_Rel *rel = (void *)sechdrs[relsec].sh_addr;
18243 Elf32_Sym *sym;
18244- uint32_t *location;
18245+ uint32_t *plocation, location;
18246
18247 DEBUGP("Applying relocate section %u to %u\n",
18248 relsec, sechdrs[relsec].sh_info);
18249 for (i = 0; i < sechdrs[relsec].sh_size / sizeof(*rel); i++) {
18250 /* This is where to make the change */
18251- location = (void *)sechdrs[sechdrs[relsec].sh_info].sh_addr
18252- + rel[i].r_offset;
18253+ plocation = (void *)sechdrs[sechdrs[relsec].sh_info].sh_addr + rel[i].r_offset;
18254+ location = (uint32_t)plocation;
18255+ if (sechdrs[sechdrs[relsec].sh_info].sh_flags & SHF_EXECINSTR)
18256+ plocation = ktla_ktva((void *)plocation);
18257 /* This is the symbol it is referring to. Note that all
18258 undefined symbols have been resolved. */
18259 sym = (Elf32_Sym *)sechdrs[symindex].sh_addr
18260@@ -78,11 +125,15 @@ int apply_relocate(Elf32_Shdr *sechdrs,
18261 switch (ELF32_R_TYPE(rel[i].r_info)) {
18262 case R_386_32:
18263 /* We add the value into the location given */
18264- *location += sym->st_value;
18265+ pax_open_kernel();
18266+ *plocation += sym->st_value;
18267+ pax_close_kernel();
18268 break;
18269 case R_386_PC32:
18270 /* Add the value, subtract its position */
18271- *location += sym->st_value - (uint32_t)location;
18272+ pax_open_kernel();
18273+ *plocation += sym->st_value - location;
18274+ pax_close_kernel();
18275 break;
18276 default:
18277 pr_err("%s: Unknown relocation: %u\n",
18278@@ -127,21 +178,30 @@ int apply_relocate_add(Elf64_Shdr *sechdrs,
18279 case R_X86_64_NONE:
18280 break;
18281 case R_X86_64_64:
18282+ pax_open_kernel();
18283 *(u64 *)loc = val;
18284+ pax_close_kernel();
18285 break;
18286 case R_X86_64_32:
18287+ pax_open_kernel();
18288 *(u32 *)loc = val;
18289+ pax_close_kernel();
18290 if (val != *(u32 *)loc)
18291 goto overflow;
18292 break;
18293 case R_X86_64_32S:
18294+ pax_open_kernel();
18295 *(s32 *)loc = val;
18296+ pax_close_kernel();
18297 if ((s64)val != *(s32 *)loc)
18298 goto overflow;
18299 break;
18300 case R_X86_64_PC32:
18301 val -= (u64)loc;
18302+ pax_open_kernel();
18303 *(u32 *)loc = val;
18304+ pax_close_kernel();
18305+
18306 #if 0
18307 if ((s64)val != *(s32 *)loc)
18308 goto overflow;
18309diff --git a/arch/x86/kernel/nmi.c b/arch/x86/kernel/nmi.c
18310index f84f5c5..e27e54b 100644
18311--- a/arch/x86/kernel/nmi.c
18312+++ b/arch/x86/kernel/nmi.c
18313@@ -479,6 +479,17 @@ static inline void nmi_nesting_postprocess(void)
18314 dotraplinkage notrace __kprobes void
18315 do_nmi(struct pt_regs *regs, long error_code)
18316 {
18317+
18318+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
18319+ if (!user_mode(regs)) {
18320+ unsigned long cs = regs->cs & 0xFFFF;
18321+ unsigned long ip = ktva_ktla(regs->ip);
18322+
18323+ if ((cs == __KERNEL_CS || cs == __KERNEXEC_KERNEL_CS) && ip <= (unsigned long)_etext)
18324+ regs->ip = ip;
18325+ }
18326+#endif
18327+
18328 nmi_nesting_preprocess(regs);
18329
18330 nmi_enter();
18331diff --git a/arch/x86/kernel/paravirt-spinlocks.c b/arch/x86/kernel/paravirt-spinlocks.c
18332index 676b8c7..870ba04 100644
18333--- a/arch/x86/kernel/paravirt-spinlocks.c
18334+++ b/arch/x86/kernel/paravirt-spinlocks.c
18335@@ -13,7 +13,7 @@ default_spin_lock_flags(arch_spinlock_t *lock, unsigned long flags)
18336 arch_spin_lock(lock);
18337 }
18338
18339-struct pv_lock_ops pv_lock_ops = {
18340+struct pv_lock_ops pv_lock_ops __read_only = {
18341 #ifdef CONFIG_SMP
18342 .spin_is_locked = __ticket_spin_is_locked,
18343 .spin_is_contended = __ticket_spin_is_contended,
18344diff --git a/arch/x86/kernel/paravirt.c b/arch/x86/kernel/paravirt.c
18345index 17fff18..7bb2088 100644
18346--- a/arch/x86/kernel/paravirt.c
18347+++ b/arch/x86/kernel/paravirt.c
18348@@ -55,6 +55,9 @@ u64 _paravirt_ident_64(u64 x)
18349 {
18350 return x;
18351 }
18352+#if defined(CONFIG_X86_32) && defined(CONFIG_X86_PAE)
18353+PV_CALLEE_SAVE_REGS_THUNK(_paravirt_ident_64);
18354+#endif
18355
18356 void __init default_banner(void)
18357 {
18358@@ -147,15 +150,19 @@ unsigned paravirt_patch_default(u8 type, u16 clobbers, void *insnbuf,
18359 if (opfunc == NULL)
18360 /* If there's no function, patch it with a ud2a (BUG) */
18361 ret = paravirt_patch_insns(insnbuf, len, ud2a, ud2a+sizeof(ud2a));
18362- else if (opfunc == _paravirt_nop)
18363+ else if (opfunc == (void *)_paravirt_nop)
18364 /* If the operation is a nop, then nop the callsite */
18365 ret = paravirt_patch_nop();
18366
18367 /* identity functions just return their single argument */
18368- else if (opfunc == _paravirt_ident_32)
18369+ else if (opfunc == (void *)_paravirt_ident_32)
18370 ret = paravirt_patch_ident_32(insnbuf, len);
18371- else if (opfunc == _paravirt_ident_64)
18372+ else if (opfunc == (void *)_paravirt_ident_64)
18373 ret = paravirt_patch_ident_64(insnbuf, len);
18374+#if defined(CONFIG_X86_32) && defined(CONFIG_X86_PAE)
18375+ else if (opfunc == (void *)__raw_callee_save__paravirt_ident_64)
18376+ ret = paravirt_patch_ident_64(insnbuf, len);
18377+#endif
18378
18379 else if (type == PARAVIRT_PATCH(pv_cpu_ops.iret) ||
18380 type == PARAVIRT_PATCH(pv_cpu_ops.irq_enable_sysexit) ||
18381@@ -180,7 +187,7 @@ unsigned paravirt_patch_insns(void *insnbuf, unsigned len,
18382 if (insn_len > len || start == NULL)
18383 insn_len = len;
18384 else
18385- memcpy(insnbuf, start, insn_len);
18386+ memcpy(insnbuf, ktla_ktva(start), insn_len);
18387
18388 return insn_len;
18389 }
18390@@ -304,7 +311,7 @@ void arch_flush_lazy_mmu_mode(void)
18391 preempt_enable();
18392 }
18393
18394-struct pv_info pv_info = {
18395+struct pv_info pv_info __read_only = {
18396 .name = "bare hardware",
18397 .paravirt_enabled = 0,
18398 .kernel_rpl = 0,
18399@@ -315,16 +322,16 @@ struct pv_info pv_info = {
18400 #endif
18401 };
18402
18403-struct pv_init_ops pv_init_ops = {
18404+struct pv_init_ops pv_init_ops __read_only = {
18405 .patch = native_patch,
18406 };
18407
18408-struct pv_time_ops pv_time_ops = {
18409+struct pv_time_ops pv_time_ops __read_only = {
18410 .sched_clock = native_sched_clock,
18411 .steal_clock = native_steal_clock,
18412 };
18413
18414-struct pv_irq_ops pv_irq_ops = {
18415+struct pv_irq_ops pv_irq_ops __read_only = {
18416 .save_fl = __PV_IS_CALLEE_SAVE(native_save_fl),
18417 .restore_fl = __PV_IS_CALLEE_SAVE(native_restore_fl),
18418 .irq_disable = __PV_IS_CALLEE_SAVE(native_irq_disable),
18419@@ -336,7 +343,7 @@ struct pv_irq_ops pv_irq_ops = {
18420 #endif
18421 };
18422
18423-struct pv_cpu_ops pv_cpu_ops = {
18424+struct pv_cpu_ops pv_cpu_ops __read_only = {
18425 .cpuid = native_cpuid,
18426 .get_debugreg = native_get_debugreg,
18427 .set_debugreg = native_set_debugreg,
18428@@ -395,21 +402,26 @@ struct pv_cpu_ops pv_cpu_ops = {
18429 .end_context_switch = paravirt_nop,
18430 };
18431
18432-struct pv_apic_ops pv_apic_ops = {
18433+struct pv_apic_ops pv_apic_ops __read_only = {
18434 #ifdef CONFIG_X86_LOCAL_APIC
18435 .startup_ipi_hook = paravirt_nop,
18436 #endif
18437 };
18438
18439-#if defined(CONFIG_X86_32) && !defined(CONFIG_X86_PAE)
18440+#ifdef CONFIG_X86_32
18441+#ifdef CONFIG_X86_PAE
18442+/* 64-bit pagetable entries */
18443+#define PTE_IDENT PV_CALLEE_SAVE(_paravirt_ident_64)
18444+#else
18445 /* 32-bit pagetable entries */
18446 #define PTE_IDENT __PV_IS_CALLEE_SAVE(_paravirt_ident_32)
18447+#endif
18448 #else
18449 /* 64-bit pagetable entries */
18450 #define PTE_IDENT __PV_IS_CALLEE_SAVE(_paravirt_ident_64)
18451 #endif
18452
18453-struct pv_mmu_ops pv_mmu_ops = {
18454+struct pv_mmu_ops pv_mmu_ops __read_only = {
18455
18456 .read_cr2 = native_read_cr2,
18457 .write_cr2 = native_write_cr2,
18458@@ -459,6 +471,7 @@ struct pv_mmu_ops pv_mmu_ops = {
18459 .make_pud = PTE_IDENT,
18460
18461 .set_pgd = native_set_pgd,
18462+ .set_pgd_batched = native_set_pgd_batched,
18463 #endif
18464 #endif /* PAGETABLE_LEVELS >= 3 */
18465
18466@@ -478,6 +491,12 @@ struct pv_mmu_ops pv_mmu_ops = {
18467 },
18468
18469 .set_fixmap = native_set_fixmap,
18470+
18471+#ifdef CONFIG_PAX_KERNEXEC
18472+ .pax_open_kernel = native_pax_open_kernel,
18473+ .pax_close_kernel = native_pax_close_kernel,
18474+#endif
18475+
18476 };
18477
18478 EXPORT_SYMBOL_GPL(pv_time_ops);
18479diff --git a/arch/x86/kernel/pci-iommu_table.c b/arch/x86/kernel/pci-iommu_table.c
18480index 35ccf75..7a15747 100644
18481--- a/arch/x86/kernel/pci-iommu_table.c
18482+++ b/arch/x86/kernel/pci-iommu_table.c
18483@@ -2,7 +2,7 @@
18484 #include <asm/iommu_table.h>
18485 #include <linux/string.h>
18486 #include <linux/kallsyms.h>
18487-
18488+#include <linux/sched.h>
18489
18490 #define DEBUG 1
18491
18492diff --git a/arch/x86/kernel/process.c b/arch/x86/kernel/process.c
18493index ef6a845..8028ed3 100644
18494--- a/arch/x86/kernel/process.c
18495+++ b/arch/x86/kernel/process.c
18496@@ -36,7 +36,8 @@
18497 * section. Since TSS's are completely CPU-local, we want them
18498 * on exact cacheline boundaries, to eliminate cacheline ping-pong.
18499 */
18500-DEFINE_PER_CPU_SHARED_ALIGNED(struct tss_struct, init_tss) = INIT_TSS;
18501+struct tss_struct init_tss[NR_CPUS] ____cacheline_internodealigned_in_smp = { [0 ... NR_CPUS-1] = INIT_TSS };
18502+EXPORT_SYMBOL(init_tss);
18503
18504 #ifdef CONFIG_X86_64
18505 static DEFINE_PER_CPU(unsigned char, is_idle);
18506@@ -94,7 +95,7 @@ void arch_task_cache_init(void)
18507 task_xstate_cachep =
18508 kmem_cache_create("task_xstate", xstate_size,
18509 __alignof__(union thread_xstate),
18510- SLAB_PANIC | SLAB_NOTRACK, NULL);
18511+ SLAB_PANIC | SLAB_NOTRACK | SLAB_USERCOPY, NULL);
18512 }
18513
18514 static inline void drop_fpu(struct task_struct *tsk)
18515@@ -117,7 +118,7 @@ void exit_thread(void)
18516 unsigned long *bp = t->io_bitmap_ptr;
18517
18518 if (bp) {
18519- struct tss_struct *tss = &per_cpu(init_tss, get_cpu());
18520+ struct tss_struct *tss = init_tss + get_cpu();
18521
18522 t->io_bitmap_ptr = NULL;
18523 clear_thread_flag(TIF_IO_BITMAP);
18524@@ -148,7 +149,7 @@ void show_regs_common(void)
18525 board = dmi_get_system_info(DMI_BOARD_NAME);
18526
18527 printk(KERN_DEFAULT "Pid: %d, comm: %.20s %s %s %.*s %s %s%s%s\n",
18528- current->pid, current->comm, print_tainted(),
18529+ task_pid_nr(current), current->comm, print_tainted(),
18530 init_utsname()->release,
18531 (int)strcspn(init_utsname()->version, " "),
18532 init_utsname()->version,
18533@@ -161,6 +162,9 @@ void flush_thread(void)
18534 {
18535 struct task_struct *tsk = current;
18536
18537+#if defined(CONFIG_X86_32) && !defined(CONFIG_CC_STACKPROTECTOR) && !defined(CONFIG_PAX_MEMORY_UDEREF)
18538+ loadsegment(gs, 0);
18539+#endif
18540 flush_ptrace_hw_breakpoint(tsk);
18541 memset(tsk->thread.tls_array, 0, sizeof(tsk->thread.tls_array));
18542 drop_fpu(tsk);
18543@@ -318,10 +322,10 @@ int kernel_thread(int (*fn)(void *), void *arg, unsigned long flags)
18544 regs.di = (unsigned long) arg;
18545
18546 #ifdef CONFIG_X86_32
18547- regs.ds = __USER_DS;
18548- regs.es = __USER_DS;
18549+ regs.ds = __KERNEL_DS;
18550+ regs.es = __KERNEL_DS;
18551 regs.fs = __KERNEL_PERCPU;
18552- regs.gs = __KERNEL_STACK_CANARY;
18553+ savesegment(gs, regs.gs);
18554 #else
18555 regs.ss = __KERNEL_DS;
18556 #endif
18557@@ -407,7 +411,7 @@ static void __exit_idle(void)
18558 void exit_idle(void)
18559 {
18560 /* idle loop has pid 0 */
18561- if (current->pid)
18562+ if (task_pid_nr(current))
18563 return;
18564 __exit_idle();
18565 }
18566@@ -516,7 +520,7 @@ bool set_pm_idle_to_default(void)
18567
18568 return ret;
18569 }
18570-void stop_this_cpu(void *dummy)
18571+__noreturn void stop_this_cpu(void *dummy)
18572 {
18573 local_irq_disable();
18574 /*
18575@@ -744,16 +748,37 @@ static int __init idle_setup(char *str)
18576 }
18577 early_param("idle", idle_setup);
18578
18579-unsigned long arch_align_stack(unsigned long sp)
18580+#ifdef CONFIG_PAX_RANDKSTACK
18581+void pax_randomize_kstack(struct pt_regs *regs)
18582 {
18583- if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
18584- sp -= get_random_int() % 8192;
18585- return sp & ~0xf;
18586-}
18587+ struct thread_struct *thread = &current->thread;
18588+ unsigned long time;
18589
18590-unsigned long arch_randomize_brk(struct mm_struct *mm)
18591-{
18592- unsigned long range_end = mm->brk + 0x02000000;
18593- return randomize_range(mm->brk, range_end, 0) ? : mm->brk;
18594-}
18595+ if (!randomize_va_space)
18596+ return;
18597+
18598+ if (v8086_mode(regs))
18599+ return;
18600
18601+ rdtscl(time);
18602+
18603+ /* P4 seems to return a 0 LSB, ignore it */
18604+#ifdef CONFIG_MPENTIUM4
18605+ time &= 0x3EUL;
18606+ time <<= 2;
18607+#elif defined(CONFIG_X86_64)
18608+ time &= 0xFUL;
18609+ time <<= 4;
18610+#else
18611+ time &= 0x1FUL;
18612+ time <<= 3;
18613+#endif
18614+
18615+ thread->sp0 ^= time;
18616+ load_sp0(init_tss + smp_processor_id(), thread);
18617+
18618+#ifdef CONFIG_X86_64
18619+ this_cpu_write(kernel_stack, thread->sp0);
18620+#endif
18621+}
18622+#endif
18623diff --git a/arch/x86/kernel/process_32.c b/arch/x86/kernel/process_32.c
18624index 516fa18..80bd9e6 100644
18625--- a/arch/x86/kernel/process_32.c
18626+++ b/arch/x86/kernel/process_32.c
18627@@ -64,6 +64,7 @@ asmlinkage void ret_from_fork(void) __asm__("ret_from_fork");
18628 unsigned long thread_saved_pc(struct task_struct *tsk)
18629 {
18630 return ((unsigned long *)tsk->thread.sp)[3];
18631+//XXX return tsk->thread.eip;
18632 }
18633
18634 void __show_regs(struct pt_regs *regs, int all)
18635@@ -73,15 +74,14 @@ void __show_regs(struct pt_regs *regs, int all)
18636 unsigned long sp;
18637 unsigned short ss, gs;
18638
18639- if (user_mode_vm(regs)) {
18640+ if (user_mode(regs)) {
18641 sp = regs->sp;
18642 ss = regs->ss & 0xffff;
18643- gs = get_user_gs(regs);
18644 } else {
18645 sp = kernel_stack_pointer(regs);
18646 savesegment(ss, ss);
18647- savesegment(gs, gs);
18648 }
18649+ gs = get_user_gs(regs);
18650
18651 show_regs_common();
18652
18653@@ -134,13 +134,14 @@ int copy_thread(unsigned long clone_flags, unsigned long sp,
18654 struct task_struct *tsk;
18655 int err;
18656
18657- childregs = task_pt_regs(p);
18658+ childregs = task_stack_page(p) + THREAD_SIZE - sizeof(struct pt_regs) - 8;
18659 *childregs = *regs;
18660 childregs->ax = 0;
18661 childregs->sp = sp;
18662
18663 p->thread.sp = (unsigned long) childregs;
18664 p->thread.sp0 = (unsigned long) (childregs+1);
18665+ p->tinfo.lowest_stack = (unsigned long)task_stack_page(p);
18666
18667 p->thread.ip = (unsigned long) ret_from_fork;
18668
18669@@ -231,7 +232,7 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
18670 struct thread_struct *prev = &prev_p->thread,
18671 *next = &next_p->thread;
18672 int cpu = smp_processor_id();
18673- struct tss_struct *tss = &per_cpu(init_tss, cpu);
18674+ struct tss_struct *tss = init_tss + cpu;
18675 fpu_switch_t fpu;
18676
18677 /* never put a printk in __switch_to... printk() calls wake_up*() indirectly */
18678@@ -255,6 +256,10 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
18679 */
18680 lazy_save_gs(prev->gs);
18681
18682+#ifdef CONFIG_PAX_MEMORY_UDEREF
18683+ __set_fs(task_thread_info(next_p)->addr_limit);
18684+#endif
18685+
18686 /*
18687 * Load the per-thread Thread-Local Storage descriptor.
18688 */
18689@@ -285,6 +290,9 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
18690 */
18691 arch_end_context_switch(next_p);
18692
18693+ this_cpu_write(current_task, next_p);
18694+ this_cpu_write(current_tinfo, &next_p->tinfo);
18695+
18696 /*
18697 * Restore %gs if needed (which is common)
18698 */
18699@@ -293,8 +301,6 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
18700
18701 switch_fpu_finish(next_p, fpu);
18702
18703- this_cpu_write(current_task, next_p);
18704-
18705 return prev_p;
18706 }
18707
18708@@ -324,4 +330,3 @@ unsigned long get_wchan(struct task_struct *p)
18709 } while (count++ < 16);
18710 return 0;
18711 }
18712-
18713diff --git a/arch/x86/kernel/process_64.c b/arch/x86/kernel/process_64.c
18714index 0a980c9..1d0e689 100644
18715--- a/arch/x86/kernel/process_64.c
18716+++ b/arch/x86/kernel/process_64.c
18717@@ -153,8 +153,7 @@ int copy_thread(unsigned long clone_flags, unsigned long sp,
18718 struct pt_regs *childregs;
18719 struct task_struct *me = current;
18720
18721- childregs = ((struct pt_regs *)
18722- (THREAD_SIZE + task_stack_page(p))) - 1;
18723+ childregs = task_stack_page(p) + THREAD_SIZE - sizeof(struct pt_regs) - 16;
18724 *childregs = *regs;
18725
18726 childregs->ax = 0;
18727@@ -166,6 +165,7 @@ int copy_thread(unsigned long clone_flags, unsigned long sp,
18728 p->thread.sp = (unsigned long) childregs;
18729 p->thread.sp0 = (unsigned long) (childregs+1);
18730 p->thread.usersp = me->thread.usersp;
18731+ p->tinfo.lowest_stack = (unsigned long)task_stack_page(p);
18732
18733 set_tsk_thread_flag(p, TIF_FORK);
18734
18735@@ -271,7 +271,7 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
18736 struct thread_struct *prev = &prev_p->thread;
18737 struct thread_struct *next = &next_p->thread;
18738 int cpu = smp_processor_id();
18739- struct tss_struct *tss = &per_cpu(init_tss, cpu);
18740+ struct tss_struct *tss = init_tss + cpu;
18741 unsigned fsindex, gsindex;
18742 fpu_switch_t fpu;
18743
18744@@ -353,10 +353,9 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
18745 prev->usersp = this_cpu_read(old_rsp);
18746 this_cpu_write(old_rsp, next->usersp);
18747 this_cpu_write(current_task, next_p);
18748+ this_cpu_write(current_tinfo, &next_p->tinfo);
18749
18750- this_cpu_write(kernel_stack,
18751- (unsigned long)task_stack_page(next_p) +
18752- THREAD_SIZE - KERNEL_STACK_OFFSET);
18753+ this_cpu_write(kernel_stack, next->sp0);
18754
18755 /*
18756 * Now maybe reload the debug registers and handle I/O bitmaps
18757@@ -425,12 +424,11 @@ unsigned long get_wchan(struct task_struct *p)
18758 if (!p || p == current || p->state == TASK_RUNNING)
18759 return 0;
18760 stack = (unsigned long)task_stack_page(p);
18761- if (p->thread.sp < stack || p->thread.sp >= stack+THREAD_SIZE)
18762+ if (p->thread.sp < stack || p->thread.sp > stack+THREAD_SIZE-16-sizeof(u64))
18763 return 0;
18764 fp = *(u64 *)(p->thread.sp);
18765 do {
18766- if (fp < (unsigned long)stack ||
18767- fp >= (unsigned long)stack+THREAD_SIZE)
18768+ if (fp < stack || fp > stack+THREAD_SIZE-16-sizeof(u64))
18769 return 0;
18770 ip = *(u64 *)(fp+8);
18771 if (!in_sched_functions(ip))
18772diff --git a/arch/x86/kernel/ptrace.c b/arch/x86/kernel/ptrace.c
18773index c4c6a5c..905f440 100644
18774--- a/arch/x86/kernel/ptrace.c
18775+++ b/arch/x86/kernel/ptrace.c
18776@@ -824,7 +824,7 @@ long arch_ptrace(struct task_struct *child, long request,
18777 unsigned long addr, unsigned long data)
18778 {
18779 int ret;
18780- unsigned long __user *datap = (unsigned long __user *)data;
18781+ unsigned long __user *datap = (__force unsigned long __user *)data;
18782
18783 switch (request) {
18784 /* read the word at location addr in the USER area. */
18785@@ -909,14 +909,14 @@ long arch_ptrace(struct task_struct *child, long request,
18786 if ((int) addr < 0)
18787 return -EIO;
18788 ret = do_get_thread_area(child, addr,
18789- (struct user_desc __user *)data);
18790+ (__force struct user_desc __user *) data);
18791 break;
18792
18793 case PTRACE_SET_THREAD_AREA:
18794 if ((int) addr < 0)
18795 return -EIO;
18796 ret = do_set_thread_area(child, addr,
18797- (struct user_desc __user *)data, 0);
18798+ (__force struct user_desc __user *) data, 0);
18799 break;
18800 #endif
18801
18802@@ -1426,7 +1426,7 @@ static void fill_sigtrap_info(struct task_struct *tsk,
18803 memset(info, 0, sizeof(*info));
18804 info->si_signo = SIGTRAP;
18805 info->si_code = si_code;
18806- info->si_addr = user_mode_vm(regs) ? (void __user *)regs->ip : NULL;
18807+ info->si_addr = user_mode(regs) ? (__force void __user *)regs->ip : NULL;
18808 }
18809
18810 void user_single_step_siginfo(struct task_struct *tsk,
18811@@ -1455,6 +1455,10 @@ void send_sigtrap(struct task_struct *tsk, struct pt_regs *regs,
18812 # define IS_IA32 0
18813 #endif
18814
18815+#ifdef CONFIG_GRKERNSEC_SETXID
18816+extern void gr_delayed_cred_worker(void);
18817+#endif
18818+
18819 /*
18820 * We must return the syscall number to actually look up in the table.
18821 * This can be -1L to skip running any syscall at all.
18822@@ -1463,6 +1467,11 @@ long syscall_trace_enter(struct pt_regs *regs)
18823 {
18824 long ret = 0;
18825
18826+#ifdef CONFIG_GRKERNSEC_SETXID
18827+ if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
18828+ gr_delayed_cred_worker();
18829+#endif
18830+
18831 /*
18832 * If we stepped into a sysenter/syscall insn, it trapped in
18833 * kernel mode; do_debug() cleared TF and set TIF_SINGLESTEP.
18834@@ -1511,6 +1520,11 @@ void syscall_trace_leave(struct pt_regs *regs)
18835 {
18836 bool step;
18837
18838+#ifdef CONFIG_GRKERNSEC_SETXID
18839+ if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
18840+ gr_delayed_cred_worker();
18841+#endif
18842+
18843 audit_syscall_exit(regs);
18844
18845 if (unlikely(test_thread_flag(TIF_SYSCALL_TRACEPOINT)))
18846diff --git a/arch/x86/kernel/pvclock.c b/arch/x86/kernel/pvclock.c
18847index 42eb330..139955c 100644
18848--- a/arch/x86/kernel/pvclock.c
18849+++ b/arch/x86/kernel/pvclock.c
18850@@ -81,11 +81,11 @@ unsigned long pvclock_tsc_khz(struct pvclock_vcpu_time_info *src)
18851 return pv_tsc_khz;
18852 }
18853
18854-static atomic64_t last_value = ATOMIC64_INIT(0);
18855+static atomic64_unchecked_t last_value = ATOMIC64_INIT(0);
18856
18857 void pvclock_resume(void)
18858 {
18859- atomic64_set(&last_value, 0);
18860+ atomic64_set_unchecked(&last_value, 0);
18861 }
18862
18863 cycle_t pvclock_clocksource_read(struct pvclock_vcpu_time_info *src)
18864@@ -121,11 +121,11 @@ cycle_t pvclock_clocksource_read(struct pvclock_vcpu_time_info *src)
18865 * updating at the same time, and one of them could be slightly behind,
18866 * making the assumption that last_value always go forward fail to hold.
18867 */
18868- last = atomic64_read(&last_value);
18869+ last = atomic64_read_unchecked(&last_value);
18870 do {
18871 if (ret < last)
18872 return last;
18873- last = atomic64_cmpxchg(&last_value, last, ret);
18874+ last = atomic64_cmpxchg_unchecked(&last_value, last, ret);
18875 } while (unlikely(last != ret));
18876
18877 return ret;
18878diff --git a/arch/x86/kernel/reboot.c b/arch/x86/kernel/reboot.c
18879index 52190a9..8074389 100644
18880--- a/arch/x86/kernel/reboot.c
18881+++ b/arch/x86/kernel/reboot.c
18882@@ -36,7 +36,7 @@ void (*pm_power_off)(void);
18883 EXPORT_SYMBOL(pm_power_off);
18884
18885 static const struct desc_ptr no_idt = {};
18886-static int reboot_mode;
18887+static unsigned short reboot_mode;
18888 enum reboot_type reboot_type = BOOT_ACPI;
18889 int reboot_force;
18890
18891@@ -157,6 +157,11 @@ static int __init set_bios_reboot(const struct dmi_system_id *d)
18892
18893 void __noreturn machine_real_restart(unsigned int type)
18894 {
18895+
18896+#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF))
18897+ struct desc_struct *gdt;
18898+#endif
18899+
18900 local_irq_disable();
18901
18902 /*
18903@@ -184,7 +189,29 @@ void __noreturn machine_real_restart(unsigned int type)
18904
18905 /* Jump to the identity-mapped low memory code */
18906 #ifdef CONFIG_X86_32
18907- asm volatile("jmpl *%0" : :
18908+
18909+#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
18910+ gdt = get_cpu_gdt_table(smp_processor_id());
18911+ pax_open_kernel();
18912+#ifdef CONFIG_PAX_MEMORY_UDEREF
18913+ gdt[GDT_ENTRY_KERNEL_DS].type = 3;
18914+ gdt[GDT_ENTRY_KERNEL_DS].limit = 0xf;
18915+ loadsegment(ds, __KERNEL_DS);
18916+ loadsegment(es, __KERNEL_DS);
18917+ loadsegment(ss, __KERNEL_DS);
18918+#endif
18919+#ifdef CONFIG_PAX_KERNEXEC
18920+ gdt[GDT_ENTRY_KERNEL_CS].base0 = 0;
18921+ gdt[GDT_ENTRY_KERNEL_CS].base1 = 0;
18922+ gdt[GDT_ENTRY_KERNEL_CS].base2 = 0;
18923+ gdt[GDT_ENTRY_KERNEL_CS].limit0 = 0xffff;
18924+ gdt[GDT_ENTRY_KERNEL_CS].limit = 0xf;
18925+ gdt[GDT_ENTRY_KERNEL_CS].g = 1;
18926+#endif
18927+ pax_close_kernel();
18928+#endif
18929+
18930+ asm volatile("ljmpl *%0" : :
18931 "rm" (real_mode_header->machine_real_restart_asm),
18932 "a" (type));
18933 #else
18934@@ -539,7 +566,7 @@ void __attribute__((weak)) mach_reboot_fixups(void)
18935 * try to force a triple fault and then cycle between hitting the keyboard
18936 * controller and doing that
18937 */
18938-static void native_machine_emergency_restart(void)
18939+static void __noreturn native_machine_emergency_restart(void)
18940 {
18941 int i;
18942 int attempt = 0;
18943@@ -662,13 +689,13 @@ void native_machine_shutdown(void)
18944 #endif
18945 }
18946
18947-static void __machine_emergency_restart(int emergency)
18948+static void __noreturn __machine_emergency_restart(int emergency)
18949 {
18950 reboot_emergency = emergency;
18951 machine_ops.emergency_restart();
18952 }
18953
18954-static void native_machine_restart(char *__unused)
18955+static void __noreturn native_machine_restart(char *__unused)
18956 {
18957 pr_notice("machine restart\n");
18958
18959@@ -677,7 +704,7 @@ static void native_machine_restart(char *__unused)
18960 __machine_emergency_restart(0);
18961 }
18962
18963-static void native_machine_halt(void)
18964+static void __noreturn native_machine_halt(void)
18965 {
18966 /* Stop other cpus and apics */
18967 machine_shutdown();
18968@@ -687,7 +714,7 @@ static void native_machine_halt(void)
18969 stop_this_cpu(NULL);
18970 }
18971
18972-static void native_machine_power_off(void)
18973+static void __noreturn native_machine_power_off(void)
18974 {
18975 if (pm_power_off) {
18976 if (!reboot_force)
18977@@ -696,6 +723,7 @@ static void native_machine_power_off(void)
18978 }
18979 /* A fallback in case there is no PM info available */
18980 tboot_shutdown(TB_SHUTDOWN_HALT);
18981+ unreachable();
18982 }
18983
18984 struct machine_ops machine_ops = {
18985diff --git a/arch/x86/kernel/relocate_kernel_64.S b/arch/x86/kernel/relocate_kernel_64.S
18986index 7a6f3b3..bed145d7 100644
18987--- a/arch/x86/kernel/relocate_kernel_64.S
18988+++ b/arch/x86/kernel/relocate_kernel_64.S
18989@@ -11,6 +11,7 @@
18990 #include <asm/kexec.h>
18991 #include <asm/processor-flags.h>
18992 #include <asm/pgtable_types.h>
18993+#include <asm/alternative-asm.h>
18994
18995 /*
18996 * Must be relocatable PIC code callable as a C function
18997@@ -160,13 +161,14 @@ identity_mapped:
18998 xorq %rbp, %rbp
18999 xorq %r8, %r8
19000 xorq %r9, %r9
19001- xorq %r10, %r9
19002+ xorq %r10, %r10
19003 xorq %r11, %r11
19004 xorq %r12, %r12
19005 xorq %r13, %r13
19006 xorq %r14, %r14
19007 xorq %r15, %r15
19008
19009+ pax_force_retaddr 0, 1
19010 ret
19011
19012 1:
19013diff --git a/arch/x86/kernel/setup.c b/arch/x86/kernel/setup.c
19014index 198e774..e880f29 100644
19015--- a/arch/x86/kernel/setup.c
19016+++ b/arch/x86/kernel/setup.c
19017@@ -440,7 +440,7 @@ static void __init parse_setup_data(void)
19018
19019 switch (data->type) {
19020 case SETUP_E820_EXT:
19021- parse_e820_ext(data);
19022+ parse_e820_ext((struct setup_data __force_kernel *)data);
19023 break;
19024 case SETUP_DTB:
19025 add_dtb(pa_data);
19026@@ -632,7 +632,7 @@ static void __init trim_bios_range(void)
19027 * area (640->1Mb) as ram even though it is not.
19028 * take them out.
19029 */
19030- e820_remove_range(BIOS_BEGIN, BIOS_END - BIOS_BEGIN, E820_RAM, 1);
19031+ e820_remove_range(ISA_START_ADDRESS, ISA_END_ADDRESS - ISA_START_ADDRESS, E820_RAM, 1);
19032 sanitize_e820_map(e820.map, ARRAY_SIZE(e820.map), &e820.nr_map);
19033 }
19034
19035@@ -755,14 +755,14 @@ void __init setup_arch(char **cmdline_p)
19036
19037 if (!boot_params.hdr.root_flags)
19038 root_mountflags &= ~MS_RDONLY;
19039- init_mm.start_code = (unsigned long) _text;
19040- init_mm.end_code = (unsigned long) _etext;
19041+ init_mm.start_code = ktla_ktva((unsigned long) _text);
19042+ init_mm.end_code = ktla_ktva((unsigned long) _etext);
19043 init_mm.end_data = (unsigned long) _edata;
19044 init_mm.brk = _brk_end;
19045
19046- code_resource.start = virt_to_phys(_text);
19047- code_resource.end = virt_to_phys(_etext)-1;
19048- data_resource.start = virt_to_phys(_etext);
19049+ code_resource.start = virt_to_phys(ktla_ktva(_text));
19050+ code_resource.end = virt_to_phys(ktla_ktva(_etext))-1;
19051+ data_resource.start = virt_to_phys(_sdata);
19052 data_resource.end = virt_to_phys(_edata)-1;
19053 bss_resource.start = virt_to_phys(&__bss_start);
19054 bss_resource.end = virt_to_phys(&__bss_stop)-1;
19055diff --git a/arch/x86/kernel/setup_percpu.c b/arch/x86/kernel/setup_percpu.c
19056index 5cdff03..5810740 100644
19057--- a/arch/x86/kernel/setup_percpu.c
19058+++ b/arch/x86/kernel/setup_percpu.c
19059@@ -21,19 +21,17 @@
19060 #include <asm/cpu.h>
19061 #include <asm/stackprotector.h>
19062
19063-DEFINE_PER_CPU_READ_MOSTLY(int, cpu_number);
19064+#ifdef CONFIG_SMP
19065+DEFINE_PER_CPU_READ_MOSTLY(unsigned int, cpu_number);
19066 EXPORT_PER_CPU_SYMBOL(cpu_number);
19067+#endif
19068
19069-#ifdef CONFIG_X86_64
19070 #define BOOT_PERCPU_OFFSET ((unsigned long)__per_cpu_load)
19071-#else
19072-#define BOOT_PERCPU_OFFSET 0
19073-#endif
19074
19075 DEFINE_PER_CPU(unsigned long, this_cpu_off) = BOOT_PERCPU_OFFSET;
19076 EXPORT_PER_CPU_SYMBOL(this_cpu_off);
19077
19078-unsigned long __per_cpu_offset[NR_CPUS] __read_mostly = {
19079+unsigned long __per_cpu_offset[NR_CPUS] __read_only = {
19080 [0 ... NR_CPUS-1] = BOOT_PERCPU_OFFSET,
19081 };
19082 EXPORT_SYMBOL(__per_cpu_offset);
19083@@ -155,10 +153,10 @@ static inline void setup_percpu_segment(int cpu)
19084 {
19085 #ifdef CONFIG_X86_32
19086 struct desc_struct gdt;
19087+ unsigned long base = per_cpu_offset(cpu);
19088
19089- pack_descriptor(&gdt, per_cpu_offset(cpu), 0xFFFFF,
19090- 0x2 | DESCTYPE_S, 0x8);
19091- gdt.s = 1;
19092+ pack_descriptor(&gdt, base, (VMALLOC_END - base - 1) >> PAGE_SHIFT,
19093+ 0x83 | DESCTYPE_S, 0xC);
19094 write_gdt_entry(get_cpu_gdt_table(cpu),
19095 GDT_ENTRY_PERCPU, &gdt, DESCTYPE_S);
19096 #endif
19097@@ -219,6 +217,11 @@ void __init setup_per_cpu_areas(void)
19098 /* alrighty, percpu areas up and running */
19099 delta = (unsigned long)pcpu_base_addr - (unsigned long)__per_cpu_start;
19100 for_each_possible_cpu(cpu) {
19101+#ifdef CONFIG_CC_STACKPROTECTOR
19102+#ifdef CONFIG_X86_32
19103+ unsigned long canary = per_cpu(stack_canary.canary, cpu);
19104+#endif
19105+#endif
19106 per_cpu_offset(cpu) = delta + pcpu_unit_offsets[cpu];
19107 per_cpu(this_cpu_off, cpu) = per_cpu_offset(cpu);
19108 per_cpu(cpu_number, cpu) = cpu;
19109@@ -259,6 +262,12 @@ void __init setup_per_cpu_areas(void)
19110 */
19111 set_cpu_numa_node(cpu, early_cpu_to_node(cpu));
19112 #endif
19113+#ifdef CONFIG_CC_STACKPROTECTOR
19114+#ifdef CONFIG_X86_32
19115+ if (!cpu)
19116+ per_cpu(stack_canary.canary, cpu) = canary;
19117+#endif
19118+#endif
19119 /*
19120 * Up to this point, the boot CPU has been using .init.data
19121 * area. Reload any changed state for the boot CPU.
19122diff --git a/arch/x86/kernel/signal.c b/arch/x86/kernel/signal.c
19123index b280908..6de349e 100644
19124--- a/arch/x86/kernel/signal.c
19125+++ b/arch/x86/kernel/signal.c
19126@@ -194,7 +194,7 @@ static unsigned long align_sigframe(unsigned long sp)
19127 * Align the stack pointer according to the i386 ABI,
19128 * i.e. so that on function entry ((sp + 4) & 15) == 0.
19129 */
19130- sp = ((sp + 4) & -16ul) - 4;
19131+ sp = ((sp - 12) & -16ul) - 4;
19132 #else /* !CONFIG_X86_32 */
19133 sp = round_down(sp, 16) - 8;
19134 #endif
19135@@ -245,11 +245,11 @@ get_sigframe(struct k_sigaction *ka, struct pt_regs *regs, size_t frame_size,
19136 * Return an always-bogus address instead so we will die with SIGSEGV.
19137 */
19138 if (onsigstack && !likely(on_sig_stack(sp)))
19139- return (void __user *)-1L;
19140+ return (__force void __user *)-1L;
19141
19142 /* save i387 state */
19143 if (used_math() && save_i387_xstate(*fpstate) < 0)
19144- return (void __user *)-1L;
19145+ return (__force void __user *)-1L;
19146
19147 return (void __user *)sp;
19148 }
19149@@ -304,9 +304,9 @@ __setup_frame(int sig, struct k_sigaction *ka, sigset_t *set,
19150 }
19151
19152 if (current->mm->context.vdso)
19153- restorer = VDSO32_SYMBOL(current->mm->context.vdso, sigreturn);
19154+ restorer = (__force void __user *)VDSO32_SYMBOL(current->mm->context.vdso, sigreturn);
19155 else
19156- restorer = &frame->retcode;
19157+ restorer = (void __user *)&frame->retcode;
19158 if (ka->sa.sa_flags & SA_RESTORER)
19159 restorer = ka->sa.sa_restorer;
19160
19161@@ -320,7 +320,7 @@ __setup_frame(int sig, struct k_sigaction *ka, sigset_t *set,
19162 * reasons and because gdb uses it as a signature to notice
19163 * signal handler stack frames.
19164 */
19165- err |= __put_user(*((u64 *)&retcode), (u64 *)frame->retcode);
19166+ err |= __put_user(*((u64 *)&retcode), (u64 __user *)frame->retcode);
19167
19168 if (err)
19169 return -EFAULT;
19170@@ -374,7 +374,10 @@ static int __setup_rt_frame(int sig, struct k_sigaction *ka, siginfo_t *info,
19171 err |= __copy_to_user(&frame->uc.uc_sigmask, set, sizeof(*set));
19172
19173 /* Set up to return from userspace. */
19174- restorer = VDSO32_SYMBOL(current->mm->context.vdso, rt_sigreturn);
19175+ if (current->mm->context.vdso)
19176+ restorer = (__force void __user *)VDSO32_SYMBOL(current->mm->context.vdso, rt_sigreturn);
19177+ else
19178+ restorer = (void __user *)&frame->retcode;
19179 if (ka->sa.sa_flags & SA_RESTORER)
19180 restorer = ka->sa.sa_restorer;
19181 put_user_ex(restorer, &frame->pretcode);
19182@@ -386,7 +389,7 @@ static int __setup_rt_frame(int sig, struct k_sigaction *ka, siginfo_t *info,
19183 * reasons and because gdb uses it as a signature to notice
19184 * signal handler stack frames.
19185 */
19186- put_user_ex(*((u64 *)&rt_retcode), (u64 *)frame->retcode);
19187+ put_user_ex(*((u64 *)&rt_retcode), (u64 __user *)frame->retcode);
19188 } put_user_catch(err);
19189
19190 if (err)
19191diff --git a/arch/x86/kernel/smpboot.c b/arch/x86/kernel/smpboot.c
19192index 7c5a8c3..88d422f 100644
19193--- a/arch/x86/kernel/smpboot.c
19194+++ b/arch/x86/kernel/smpboot.c
19195@@ -670,6 +670,7 @@ static int __cpuinit do_boot_cpu(int apicid, int cpu, struct task_struct *idle)
19196 idle->thread.sp = (unsigned long) (((struct pt_regs *)
19197 (THREAD_SIZE + task_stack_page(idle))) - 1);
19198 per_cpu(current_task, cpu) = idle;
19199+ per_cpu(current_tinfo, cpu) = &idle->tinfo;
19200
19201 #ifdef CONFIG_X86_32
19202 /* Stack for startup_32 can be just as for start_secondary onwards */
19203@@ -677,11 +678,13 @@ static int __cpuinit do_boot_cpu(int apicid, int cpu, struct task_struct *idle)
19204 #else
19205 clear_tsk_thread_flag(idle, TIF_FORK);
19206 initial_gs = per_cpu_offset(cpu);
19207- per_cpu(kernel_stack, cpu) =
19208- (unsigned long)task_stack_page(idle) -
19209- KERNEL_STACK_OFFSET + THREAD_SIZE;
19210+ per_cpu(kernel_stack, cpu) = (unsigned long)task_stack_page(idle) - 16 + THREAD_SIZE;
19211 #endif
19212+
19213+ pax_open_kernel();
19214 early_gdt_descr.address = (unsigned long)get_cpu_gdt_table(cpu);
19215+ pax_close_kernel();
19216+
19217 initial_code = (unsigned long)start_secondary;
19218 stack_start = idle->thread.sp;
19219
19220@@ -817,6 +820,12 @@ int __cpuinit native_cpu_up(unsigned int cpu, struct task_struct *tidle)
19221
19222 per_cpu(cpu_state, cpu) = CPU_UP_PREPARE;
19223
19224+#ifdef CONFIG_PAX_PER_CPU_PGD
19225+ clone_pgd_range(get_cpu_pgd(cpu) + KERNEL_PGD_BOUNDARY,
19226+ swapper_pg_dir + KERNEL_PGD_BOUNDARY,
19227+ KERNEL_PGD_PTRS);
19228+#endif
19229+
19230 err = do_boot_cpu(apicid, cpu, tidle);
19231 if (err) {
19232 pr_debug("do_boot_cpu failed %d\n", err);
19233diff --git a/arch/x86/kernel/step.c b/arch/x86/kernel/step.c
19234index c346d11..d43b163 100644
19235--- a/arch/x86/kernel/step.c
19236+++ b/arch/x86/kernel/step.c
19237@@ -27,10 +27,10 @@ unsigned long convert_ip_to_linear(struct task_struct *child, struct pt_regs *re
19238 struct desc_struct *desc;
19239 unsigned long base;
19240
19241- seg &= ~7UL;
19242+ seg >>= 3;
19243
19244 mutex_lock(&child->mm->context.lock);
19245- if (unlikely((seg >> 3) >= child->mm->context.size))
19246+ if (unlikely(seg >= child->mm->context.size))
19247 addr = -1L; /* bogus selector, access would fault */
19248 else {
19249 desc = child->mm->context.ldt + seg;
19250@@ -42,7 +42,8 @@ unsigned long convert_ip_to_linear(struct task_struct *child, struct pt_regs *re
19251 addr += base;
19252 }
19253 mutex_unlock(&child->mm->context.lock);
19254- }
19255+ } else if (seg == __KERNEL_CS || seg == __KERNEXEC_KERNEL_CS)
19256+ addr = ktla_ktva(addr);
19257
19258 return addr;
19259 }
19260@@ -53,6 +54,9 @@ static int is_setting_trap_flag(struct task_struct *child, struct pt_regs *regs)
19261 unsigned char opcode[15];
19262 unsigned long addr = convert_ip_to_linear(child, regs);
19263
19264+ if (addr == -EINVAL)
19265+ return 0;
19266+
19267 copied = access_process_vm(child, addr, opcode, sizeof(opcode), 0);
19268 for (i = 0; i < copied; i++) {
19269 switch (opcode[i]) {
19270diff --git a/arch/x86/kernel/sys_i386_32.c b/arch/x86/kernel/sys_i386_32.c
19271index 0b0cb5f..db6b9ed 100644
19272--- a/arch/x86/kernel/sys_i386_32.c
19273+++ b/arch/x86/kernel/sys_i386_32.c
19274@@ -24,17 +24,224 @@
19275
19276 #include <asm/syscalls.h>
19277
19278-/*
19279- * Do a system call from kernel instead of calling sys_execve so we
19280- * end up with proper pt_regs.
19281- */
19282-int kernel_execve(const char *filename,
19283- const char *const argv[],
19284- const char *const envp[])
19285+int i386_mmap_check(unsigned long addr, unsigned long len, unsigned long flags)
19286 {
19287- long __res;
19288- asm volatile ("int $0x80"
19289- : "=a" (__res)
19290- : "0" (__NR_execve), "b" (filename), "c" (argv), "d" (envp) : "memory");
19291- return __res;
19292+ unsigned long pax_task_size = TASK_SIZE;
19293+
19294+#ifdef CONFIG_PAX_SEGMEXEC
19295+ if (current->mm->pax_flags & MF_PAX_SEGMEXEC)
19296+ pax_task_size = SEGMEXEC_TASK_SIZE;
19297+#endif
19298+
19299+ if (len > pax_task_size || addr > pax_task_size - len)
19300+ return -EINVAL;
19301+
19302+ return 0;
19303+}
19304+
19305+unsigned long
19306+arch_get_unmapped_area(struct file *filp, unsigned long addr,
19307+ unsigned long len, unsigned long pgoff, unsigned long flags)
19308+{
19309+ struct mm_struct *mm = current->mm;
19310+ struct vm_area_struct *vma;
19311+ unsigned long start_addr, pax_task_size = TASK_SIZE;
19312+
19313+#ifdef CONFIG_PAX_SEGMEXEC
19314+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
19315+ pax_task_size = SEGMEXEC_TASK_SIZE;
19316+#endif
19317+
19318+ pax_task_size -= PAGE_SIZE;
19319+
19320+ if (len > pax_task_size)
19321+ return -ENOMEM;
19322+
19323+ if (flags & MAP_FIXED)
19324+ return addr;
19325+
19326+#ifdef CONFIG_PAX_RANDMMAP
19327+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
19328+#endif
19329+
19330+ if (addr) {
19331+ addr = PAGE_ALIGN(addr);
19332+ if (pax_task_size - len >= addr) {
19333+ vma = find_vma(mm, addr);
19334+ if (check_heap_stack_gap(vma, addr, len))
19335+ return addr;
19336+ }
19337+ }
19338+ if (len > mm->cached_hole_size) {
19339+ start_addr = addr = mm->free_area_cache;
19340+ } else {
19341+ start_addr = addr = mm->mmap_base;
19342+ mm->cached_hole_size = 0;
19343+ }
19344+
19345+#ifdef CONFIG_PAX_PAGEEXEC
19346+ if (!(__supported_pte_mask & _PAGE_NX) && (mm->pax_flags & MF_PAX_PAGEEXEC) && (flags & MAP_EXECUTABLE) && start_addr >= mm->mmap_base) {
19347+ start_addr = 0x00110000UL;
19348+
19349+#ifdef CONFIG_PAX_RANDMMAP
19350+ if (mm->pax_flags & MF_PAX_RANDMMAP)
19351+ start_addr += mm->delta_mmap & 0x03FFF000UL;
19352+#endif
19353+
19354+ if (mm->start_brk <= start_addr && start_addr < mm->mmap_base)
19355+ start_addr = addr = mm->mmap_base;
19356+ else
19357+ addr = start_addr;
19358+ }
19359+#endif
19360+
19361+full_search:
19362+ for (vma = find_vma(mm, addr); ; vma = vma->vm_next) {
19363+ /* At this point: (!vma || addr < vma->vm_end). */
19364+ if (pax_task_size - len < addr) {
19365+ /*
19366+ * Start a new search - just in case we missed
19367+ * some holes.
19368+ */
19369+ if (start_addr != mm->mmap_base) {
19370+ start_addr = addr = mm->mmap_base;
19371+ mm->cached_hole_size = 0;
19372+ goto full_search;
19373+ }
19374+ return -ENOMEM;
19375+ }
19376+ if (check_heap_stack_gap(vma, addr, len))
19377+ break;
19378+ if (addr + mm->cached_hole_size < vma->vm_start)
19379+ mm->cached_hole_size = vma->vm_start - addr;
19380+ addr = vma->vm_end;
19381+ if (mm->start_brk <= addr && addr < mm->mmap_base) {
19382+ start_addr = addr = mm->mmap_base;
19383+ mm->cached_hole_size = 0;
19384+ goto full_search;
19385+ }
19386+ }
19387+
19388+ /*
19389+ * Remember the place where we stopped the search:
19390+ */
19391+ mm->free_area_cache = addr + len;
19392+ return addr;
19393+}
19394+
19395+unsigned long
19396+arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
19397+ const unsigned long len, const unsigned long pgoff,
19398+ const unsigned long flags)
19399+{
19400+ struct vm_area_struct *vma;
19401+ struct mm_struct *mm = current->mm;
19402+ unsigned long base = mm->mmap_base, addr = addr0, pax_task_size = TASK_SIZE;
19403+
19404+#ifdef CONFIG_PAX_SEGMEXEC
19405+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
19406+ pax_task_size = SEGMEXEC_TASK_SIZE;
19407+#endif
19408+
19409+ pax_task_size -= PAGE_SIZE;
19410+
19411+ /* requested length too big for entire address space */
19412+ if (len > pax_task_size)
19413+ return -ENOMEM;
19414+
19415+ if (flags & MAP_FIXED)
19416+ return addr;
19417+
19418+#ifdef CONFIG_PAX_PAGEEXEC
19419+ if (!(__supported_pte_mask & _PAGE_NX) && (mm->pax_flags & MF_PAX_PAGEEXEC) && (flags & MAP_EXECUTABLE))
19420+ goto bottomup;
19421+#endif
19422+
19423+#ifdef CONFIG_PAX_RANDMMAP
19424+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
19425+#endif
19426+
19427+ /* requesting a specific address */
19428+ if (addr) {
19429+ addr = PAGE_ALIGN(addr);
19430+ if (pax_task_size - len >= addr) {
19431+ vma = find_vma(mm, addr);
19432+ if (check_heap_stack_gap(vma, addr, len))
19433+ return addr;
19434+ }
19435+ }
19436+
19437+ /* check if free_area_cache is useful for us */
19438+ if (len <= mm->cached_hole_size) {
19439+ mm->cached_hole_size = 0;
19440+ mm->free_area_cache = mm->mmap_base;
19441+ }
19442+
19443+ /* either no address requested or can't fit in requested address hole */
19444+ addr = mm->free_area_cache;
19445+
19446+ /* make sure it can fit in the remaining address space */
19447+ if (addr > len) {
19448+ vma = find_vma(mm, addr-len);
19449+ if (check_heap_stack_gap(vma, addr - len, len))
19450+ /* remember the address as a hint for next time */
19451+ return (mm->free_area_cache = addr-len);
19452+ }
19453+
19454+ if (mm->mmap_base < len)
19455+ goto bottomup;
19456+
19457+ addr = mm->mmap_base-len;
19458+
19459+ do {
19460+ /*
19461+ * Lookup failure means no vma is above this address,
19462+ * else if new region fits below vma->vm_start,
19463+ * return with success:
19464+ */
19465+ vma = find_vma(mm, addr);
19466+ if (check_heap_stack_gap(vma, addr, len))
19467+ /* remember the address as a hint for next time */
19468+ return (mm->free_area_cache = addr);
19469+
19470+ /* remember the largest hole we saw so far */
19471+ if (addr + mm->cached_hole_size < vma->vm_start)
19472+ mm->cached_hole_size = vma->vm_start - addr;
19473+
19474+ /* try just below the current vma->vm_start */
19475+ addr = skip_heap_stack_gap(vma, len);
19476+ } while (!IS_ERR_VALUE(addr));
19477+
19478+bottomup:
19479+ /*
19480+ * A failed mmap() very likely causes application failure,
19481+ * so fall back to the bottom-up function here. This scenario
19482+ * can happen with large stack limits and large mmap()
19483+ * allocations.
19484+ */
19485+
19486+#ifdef CONFIG_PAX_SEGMEXEC
19487+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
19488+ mm->mmap_base = SEGMEXEC_TASK_UNMAPPED_BASE;
19489+ else
19490+#endif
19491+
19492+ mm->mmap_base = TASK_UNMAPPED_BASE;
19493+
19494+#ifdef CONFIG_PAX_RANDMMAP
19495+ if (mm->pax_flags & MF_PAX_RANDMMAP)
19496+ mm->mmap_base += mm->delta_mmap;
19497+#endif
19498+
19499+ mm->free_area_cache = mm->mmap_base;
19500+ mm->cached_hole_size = ~0UL;
19501+ addr = arch_get_unmapped_area(filp, addr0, len, pgoff, flags);
19502+ /*
19503+ * Restore the topdown base:
19504+ */
19505+ mm->mmap_base = base;
19506+ mm->free_area_cache = base;
19507+ mm->cached_hole_size = ~0UL;
19508+
19509+ return addr;
19510 }
19511diff --git a/arch/x86/kernel/sys_x86_64.c b/arch/x86/kernel/sys_x86_64.c
19512index b4d3c39..82bb73b 100644
19513--- a/arch/x86/kernel/sys_x86_64.c
19514+++ b/arch/x86/kernel/sys_x86_64.c
19515@@ -95,8 +95,8 @@ out:
19516 return error;
19517 }
19518
19519-static void find_start_end(unsigned long flags, unsigned long *begin,
19520- unsigned long *end)
19521+static void find_start_end(struct mm_struct *mm, unsigned long flags,
19522+ unsigned long *begin, unsigned long *end)
19523 {
19524 if (!test_thread_flag(TIF_ADDR32) && (flags & MAP_32BIT)) {
19525 unsigned long new_begin;
19526@@ -115,7 +115,7 @@ static void find_start_end(unsigned long flags, unsigned long *begin,
19527 *begin = new_begin;
19528 }
19529 } else {
19530- *begin = TASK_UNMAPPED_BASE;
19531+ *begin = mm->mmap_base;
19532 *end = TASK_SIZE;
19533 }
19534 }
19535@@ -132,16 +132,19 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
19536 if (flags & MAP_FIXED)
19537 return addr;
19538
19539- find_start_end(flags, &begin, &end);
19540+ find_start_end(mm, flags, &begin, &end);
19541
19542 if (len > end)
19543 return -ENOMEM;
19544
19545+#ifdef CONFIG_PAX_RANDMMAP
19546+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
19547+#endif
19548+
19549 if (addr) {
19550 addr = PAGE_ALIGN(addr);
19551 vma = find_vma(mm, addr);
19552- if (end - len >= addr &&
19553- (!vma || addr + len <= vma->vm_start))
19554+ if (end - len >= addr && check_heap_stack_gap(vma, addr, len))
19555 return addr;
19556 }
19557 if (((flags & MAP_32BIT) || test_thread_flag(TIF_ADDR32))
19558@@ -172,7 +175,7 @@ full_search:
19559 }
19560 return -ENOMEM;
19561 }
19562- if (!vma || addr + len <= vma->vm_start) {
19563+ if (check_heap_stack_gap(vma, addr, len)) {
19564 /*
19565 * Remember the place where we stopped the search:
19566 */
19567@@ -195,7 +198,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
19568 {
19569 struct vm_area_struct *vma;
19570 struct mm_struct *mm = current->mm;
19571- unsigned long addr = addr0, start_addr;
19572+ unsigned long base = mm->mmap_base, addr = addr0, start_addr;
19573
19574 /* requested length too big for entire address space */
19575 if (len > TASK_SIZE)
19576@@ -208,13 +211,18 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
19577 if (!test_thread_flag(TIF_ADDR32) && (flags & MAP_32BIT))
19578 goto bottomup;
19579
19580+#ifdef CONFIG_PAX_RANDMMAP
19581+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
19582+#endif
19583+
19584 /* requesting a specific address */
19585 if (addr) {
19586 addr = PAGE_ALIGN(addr);
19587- vma = find_vma(mm, addr);
19588- if (TASK_SIZE - len >= addr &&
19589- (!vma || addr + len <= vma->vm_start))
19590- return addr;
19591+ if (TASK_SIZE - len >= addr) {
19592+ vma = find_vma(mm, addr);
19593+ if (check_heap_stack_gap(vma, addr, len))
19594+ return addr;
19595+ }
19596 }
19597
19598 /* check if free_area_cache is useful for us */
19599@@ -240,7 +248,7 @@ try_again:
19600 * return with success:
19601 */
19602 vma = find_vma(mm, addr);
19603- if (!vma || addr+len <= vma->vm_start)
19604+ if (check_heap_stack_gap(vma, addr, len))
19605 /* remember the address as a hint for next time */
19606 return mm->free_area_cache = addr;
19607
19608@@ -249,8 +257,8 @@ try_again:
19609 mm->cached_hole_size = vma->vm_start - addr;
19610
19611 /* try just below the current vma->vm_start */
19612- addr = vma->vm_start-len;
19613- } while (len < vma->vm_start);
19614+ addr = skip_heap_stack_gap(vma, len);
19615+ } while (!IS_ERR_VALUE(addr));
19616
19617 fail:
19618 /*
19619@@ -270,13 +278,21 @@ bottomup:
19620 * can happen with large stack limits and large mmap()
19621 * allocations.
19622 */
19623+ mm->mmap_base = TASK_UNMAPPED_BASE;
19624+
19625+#ifdef CONFIG_PAX_RANDMMAP
19626+ if (mm->pax_flags & MF_PAX_RANDMMAP)
19627+ mm->mmap_base += mm->delta_mmap;
19628+#endif
19629+
19630+ mm->free_area_cache = mm->mmap_base;
19631 mm->cached_hole_size = ~0UL;
19632- mm->free_area_cache = TASK_UNMAPPED_BASE;
19633 addr = arch_get_unmapped_area(filp, addr0, len, pgoff, flags);
19634 /*
19635 * Restore the topdown base:
19636 */
19637- mm->free_area_cache = mm->mmap_base;
19638+ mm->mmap_base = base;
19639+ mm->free_area_cache = base;
19640 mm->cached_hole_size = ~0UL;
19641
19642 return addr;
19643diff --git a/arch/x86/kernel/tboot.c b/arch/x86/kernel/tboot.c
19644index f84fe00..93fe08f 100644
19645--- a/arch/x86/kernel/tboot.c
19646+++ b/arch/x86/kernel/tboot.c
19647@@ -220,7 +220,7 @@ static int tboot_setup_sleep(void)
19648
19649 void tboot_shutdown(u32 shutdown_type)
19650 {
19651- void (*shutdown)(void);
19652+ void (* __noreturn shutdown)(void);
19653
19654 if (!tboot_enabled())
19655 return;
19656@@ -242,7 +242,7 @@ void tboot_shutdown(u32 shutdown_type)
19657
19658 switch_to_tboot_pt();
19659
19660- shutdown = (void(*)(void))(unsigned long)tboot->shutdown_entry;
19661+ shutdown = (void *)tboot->shutdown_entry;
19662 shutdown();
19663
19664 /* should not reach here */
19665@@ -300,7 +300,7 @@ static int tboot_sleep(u8 sleep_state, u32 pm1a_control, u32 pm1b_control)
19666 return 0;
19667 }
19668
19669-static atomic_t ap_wfs_count;
19670+static atomic_unchecked_t ap_wfs_count;
19671
19672 static int tboot_wait_for_aps(int num_aps)
19673 {
19674@@ -324,9 +324,9 @@ static int __cpuinit tboot_cpu_callback(struct notifier_block *nfb,
19675 {
19676 switch (action) {
19677 case CPU_DYING:
19678- atomic_inc(&ap_wfs_count);
19679+ atomic_inc_unchecked(&ap_wfs_count);
19680 if (num_online_cpus() == 1)
19681- if (tboot_wait_for_aps(atomic_read(&ap_wfs_count)))
19682+ if (tboot_wait_for_aps(atomic_read_unchecked(&ap_wfs_count)))
19683 return NOTIFY_BAD;
19684 break;
19685 }
19686@@ -345,7 +345,7 @@ static __init int tboot_late_init(void)
19687
19688 tboot_create_trampoline();
19689
19690- atomic_set(&ap_wfs_count, 0);
19691+ atomic_set_unchecked(&ap_wfs_count, 0);
19692 register_hotcpu_notifier(&tboot_cpu_notifier);
19693
19694 acpi_os_set_prepare_sleep(&tboot_sleep);
19695diff --git a/arch/x86/kernel/time.c b/arch/x86/kernel/time.c
19696index 24d3c91..d06b473 100644
19697--- a/arch/x86/kernel/time.c
19698+++ b/arch/x86/kernel/time.c
19699@@ -30,9 +30,9 @@ unsigned long profile_pc(struct pt_regs *regs)
19700 {
19701 unsigned long pc = instruction_pointer(regs);
19702
19703- if (!user_mode_vm(regs) && in_lock_functions(pc)) {
19704+ if (!user_mode(regs) && in_lock_functions(pc)) {
19705 #ifdef CONFIG_FRAME_POINTER
19706- return *(unsigned long *)(regs->bp + sizeof(long));
19707+ return ktla_ktva(*(unsigned long *)(regs->bp + sizeof(long)));
19708 #else
19709 unsigned long *sp =
19710 (unsigned long *)kernel_stack_pointer(regs);
19711@@ -41,11 +41,17 @@ unsigned long profile_pc(struct pt_regs *regs)
19712 * or above a saved flags. Eflags has bits 22-31 zero,
19713 * kernel addresses don't.
19714 */
19715+
19716+#ifdef CONFIG_PAX_KERNEXEC
19717+ return ktla_ktva(sp[0]);
19718+#else
19719 if (sp[0] >> 22)
19720 return sp[0];
19721 if (sp[1] >> 22)
19722 return sp[1];
19723 #endif
19724+
19725+#endif
19726 }
19727 return pc;
19728 }
19729diff --git a/arch/x86/kernel/tls.c b/arch/x86/kernel/tls.c
19730index 9d9d2f9..cad418a 100644
19731--- a/arch/x86/kernel/tls.c
19732+++ b/arch/x86/kernel/tls.c
19733@@ -84,6 +84,11 @@ int do_set_thread_area(struct task_struct *p, int idx,
19734 if (idx < GDT_ENTRY_TLS_MIN || idx > GDT_ENTRY_TLS_MAX)
19735 return -EINVAL;
19736
19737+#ifdef CONFIG_PAX_SEGMEXEC
19738+ if ((p->mm->pax_flags & MF_PAX_SEGMEXEC) && (info.contents & MODIFY_LDT_CONTENTS_CODE))
19739+ return -EINVAL;
19740+#endif
19741+
19742 set_tls_desc(p, idx, &info, 1);
19743
19744 return 0;
19745@@ -204,7 +209,7 @@ int regset_tls_set(struct task_struct *target, const struct user_regset *regset,
19746
19747 if (kbuf)
19748 info = kbuf;
19749- else if (__copy_from_user(infobuf, ubuf, count))
19750+ else if (count > sizeof infobuf || __copy_from_user(infobuf, ubuf, count))
19751 return -EFAULT;
19752 else
19753 info = infobuf;
19754diff --git a/arch/x86/kernel/traps.c b/arch/x86/kernel/traps.c
19755index b481341..5918bbe 100644
19756--- a/arch/x86/kernel/traps.c
19757+++ b/arch/x86/kernel/traps.c
19758@@ -70,12 +70,6 @@ asmlinkage int system_call(void);
19759
19760 /* Do we ignore FPU interrupts ? */
19761 char ignore_fpu_irq;
19762-
19763-/*
19764- * The IDT has to be page-aligned to simplify the Pentium
19765- * F0 0F bug workaround.
19766- */
19767-gate_desc idt_table[NR_VECTORS] __page_aligned_data = { { { { 0, 0 } } }, };
19768 #endif
19769
19770 DECLARE_BITMAP(used_vectors, NR_VECTORS);
19771@@ -108,13 +102,13 @@ static inline void preempt_conditional_cli(struct pt_regs *regs)
19772 }
19773
19774 static void __kprobes
19775-do_trap(int trapnr, int signr, char *str, struct pt_regs *regs,
19776+do_trap(int trapnr, int signr, const char *str, struct pt_regs *regs,
19777 long error_code, siginfo_t *info)
19778 {
19779 struct task_struct *tsk = current;
19780
19781 #ifdef CONFIG_X86_32
19782- if (regs->flags & X86_VM_MASK) {
19783+ if (v8086_mode(regs)) {
19784 /*
19785 * traps 0, 1, 3, 4, and 5 should be forwarded to vm86.
19786 * On nmi (interrupt 2), do_trap should not be called.
19787@@ -125,7 +119,7 @@ do_trap(int trapnr, int signr, char *str, struct pt_regs *regs,
19788 }
19789 #endif
19790
19791- if (!user_mode(regs))
19792+ if (!user_mode_novm(regs))
19793 goto kernel_trap;
19794
19795 #ifdef CONFIG_X86_32
19796@@ -147,7 +141,7 @@ trap_signal:
19797 if (show_unhandled_signals && unhandled_signal(tsk, signr) &&
19798 printk_ratelimit()) {
19799 pr_info("%s[%d] trap %s ip:%lx sp:%lx error:%lx",
19800- tsk->comm, tsk->pid, str,
19801+ tsk->comm, task_pid_nr(tsk), str,
19802 regs->ip, regs->sp, error_code);
19803 print_vma_addr(" in ", regs->ip);
19804 pr_cont("\n");
19805@@ -164,8 +158,20 @@ kernel_trap:
19806 if (!fixup_exception(regs)) {
19807 tsk->thread.error_code = error_code;
19808 tsk->thread.trap_nr = trapnr;
19809+
19810+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
19811+ if (trapnr == 12 && ((regs->cs & 0xFFFF) == __KERNEL_CS || (regs->cs & 0xFFFF) == __KERNEXEC_KERNEL_CS))
19812+ str = "PAX: suspicious stack segment fault";
19813+#endif
19814+
19815 die(str, regs, error_code);
19816 }
19817+
19818+#ifdef CONFIG_PAX_REFCOUNT
19819+ if (trapnr == 4)
19820+ pax_report_refcount_overflow(regs);
19821+#endif
19822+
19823 return;
19824
19825 #ifdef CONFIG_X86_32
19826@@ -258,14 +264,30 @@ do_general_protection(struct pt_regs *regs, long error_code)
19827 conditional_sti(regs);
19828
19829 #ifdef CONFIG_X86_32
19830- if (regs->flags & X86_VM_MASK)
19831+ if (v8086_mode(regs))
19832 goto gp_in_vm86;
19833 #endif
19834
19835 tsk = current;
19836- if (!user_mode(regs))
19837+ if (!user_mode_novm(regs))
19838 goto gp_in_kernel;
19839
19840+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
19841+ if (!(__supported_pte_mask & _PAGE_NX) && tsk->mm && (tsk->mm->pax_flags & MF_PAX_PAGEEXEC)) {
19842+ struct mm_struct *mm = tsk->mm;
19843+ unsigned long limit;
19844+
19845+ down_write(&mm->mmap_sem);
19846+ limit = mm->context.user_cs_limit;
19847+ if (limit < TASK_SIZE) {
19848+ track_exec_limit(mm, limit, TASK_SIZE, VM_EXEC);
19849+ up_write(&mm->mmap_sem);
19850+ return;
19851+ }
19852+ up_write(&mm->mmap_sem);
19853+ }
19854+#endif
19855+
19856 tsk->thread.error_code = error_code;
19857 tsk->thread.trap_nr = X86_TRAP_GP;
19858
19859@@ -297,6 +319,13 @@ gp_in_kernel:
19860 if (notify_die(DIE_GPF, "general protection fault", regs, error_code,
19861 X86_TRAP_GP, SIGSEGV) == NOTIFY_STOP)
19862 return;
19863+
19864+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
19865+ if ((regs->cs & 0xFFFF) == __KERNEL_CS || (regs->cs & 0xFFFF) == __KERNEXEC_KERNEL_CS)
19866+ die("PAX: suspicious general protection fault", regs, error_code);
19867+ else
19868+#endif
19869+
19870 die("general protection fault", regs, error_code);
19871 }
19872
19873@@ -432,7 +461,7 @@ dotraplinkage void __kprobes do_debug(struct pt_regs *regs, long error_code)
19874 /* It's safe to allow irq's after DR6 has been saved */
19875 preempt_conditional_sti(regs);
19876
19877- if (regs->flags & X86_VM_MASK) {
19878+ if (v8086_mode(regs)) {
19879 handle_vm86_trap((struct kernel_vm86_regs *) regs, error_code,
19880 X86_TRAP_DB);
19881 preempt_conditional_cli(regs);
19882@@ -447,7 +476,7 @@ dotraplinkage void __kprobes do_debug(struct pt_regs *regs, long error_code)
19883 * We already checked v86 mode above, so we can check for kernel mode
19884 * by just checking the CPL of CS.
19885 */
19886- if ((dr6 & DR_STEP) && !user_mode(regs)) {
19887+ if ((dr6 & DR_STEP) && !user_mode_novm(regs)) {
19888 tsk->thread.debugreg6 &= ~DR_STEP;
19889 set_tsk_thread_flag(tsk, TIF_SINGLESTEP);
19890 regs->flags &= ~X86_EFLAGS_TF;
19891@@ -478,7 +507,7 @@ void math_error(struct pt_regs *regs, int error_code, int trapnr)
19892 return;
19893 conditional_sti(regs);
19894
19895- if (!user_mode_vm(regs))
19896+ if (!user_mode(regs))
19897 {
19898 if (!fixup_exception(regs)) {
19899 task->thread.error_code = error_code;
19900diff --git a/arch/x86/kernel/uprobes.c b/arch/x86/kernel/uprobes.c
19901index 36fd420..7e5892d 100644
19902--- a/arch/x86/kernel/uprobes.c
19903+++ b/arch/x86/kernel/uprobes.c
19904@@ -607,7 +607,7 @@ int arch_uprobe_exception_notify(struct notifier_block *self, unsigned long val,
19905 int ret = NOTIFY_DONE;
19906
19907 /* We are only interested in userspace traps */
19908- if (regs && !user_mode_vm(regs))
19909+ if (regs && !user_mode(regs))
19910 return NOTIFY_DONE;
19911
19912 switch (val) {
19913diff --git a/arch/x86/kernel/verify_cpu.S b/arch/x86/kernel/verify_cpu.S
19914index b9242ba..50c5edd 100644
19915--- a/arch/x86/kernel/verify_cpu.S
19916+++ b/arch/x86/kernel/verify_cpu.S
19917@@ -20,6 +20,7 @@
19918 * arch/x86/boot/compressed/head_64.S: Boot cpu verification
19919 * arch/x86/kernel/trampoline_64.S: secondary processor verification
19920 * arch/x86/kernel/head_32.S: processor startup
19921+ * arch/x86/kernel/acpi/realmode/wakeup.S: 32bit processor resume
19922 *
19923 * verify_cpu, returns the status of longmode and SSE in register %eax.
19924 * 0: Success 1: Failure
19925diff --git a/arch/x86/kernel/vm86_32.c b/arch/x86/kernel/vm86_32.c
19926index 54abcc0..eb6c848 100644
19927--- a/arch/x86/kernel/vm86_32.c
19928+++ b/arch/x86/kernel/vm86_32.c
19929@@ -43,6 +43,7 @@
19930 #include <linux/ptrace.h>
19931 #include <linux/audit.h>
19932 #include <linux/stddef.h>
19933+#include <linux/grsecurity.h>
19934
19935 #include <asm/uaccess.h>
19936 #include <asm/io.h>
19937@@ -150,7 +151,7 @@ struct pt_regs *save_v86_state(struct kernel_vm86_regs *regs)
19938 do_exit(SIGSEGV);
19939 }
19940
19941- tss = &per_cpu(init_tss, get_cpu());
19942+ tss = init_tss + get_cpu();
19943 current->thread.sp0 = current->thread.saved_sp0;
19944 current->thread.sysenter_cs = __KERNEL_CS;
19945 load_sp0(tss, &current->thread);
19946@@ -212,6 +213,13 @@ int sys_vm86old(struct vm86_struct __user *v86, struct pt_regs *regs)
19947 struct task_struct *tsk;
19948 int tmp, ret = -EPERM;
19949
19950+#ifdef CONFIG_GRKERNSEC_VM86
19951+ if (!capable(CAP_SYS_RAWIO)) {
19952+ gr_handle_vm86();
19953+ goto out;
19954+ }
19955+#endif
19956+
19957 tsk = current;
19958 if (tsk->thread.saved_sp0)
19959 goto out;
19960@@ -242,6 +250,14 @@ int sys_vm86(unsigned long cmd, unsigned long arg, struct pt_regs *regs)
19961 int tmp, ret;
19962 struct vm86plus_struct __user *v86;
19963
19964+#ifdef CONFIG_GRKERNSEC_VM86
19965+ if (!capable(CAP_SYS_RAWIO)) {
19966+ gr_handle_vm86();
19967+ ret = -EPERM;
19968+ goto out;
19969+ }
19970+#endif
19971+
19972 tsk = current;
19973 switch (cmd) {
19974 case VM86_REQUEST_IRQ:
19975@@ -328,7 +344,7 @@ static void do_sys_vm86(struct kernel_vm86_struct *info, struct task_struct *tsk
19976 tsk->thread.saved_fs = info->regs32->fs;
19977 tsk->thread.saved_gs = get_user_gs(info->regs32);
19978
19979- tss = &per_cpu(init_tss, get_cpu());
19980+ tss = init_tss + get_cpu();
19981 tsk->thread.sp0 = (unsigned long) &info->VM86_TSS_ESP0;
19982 if (cpu_has_sep)
19983 tsk->thread.sysenter_cs = 0;
19984@@ -535,7 +551,7 @@ static void do_int(struct kernel_vm86_regs *regs, int i,
19985 goto cannot_handle;
19986 if (i == 0x21 && is_revectored(AH(regs), &KVM86->int21_revectored))
19987 goto cannot_handle;
19988- intr_ptr = (unsigned long __user *) (i << 2);
19989+ intr_ptr = (__force unsigned long __user *) (i << 2);
19990 if (get_user(segoffs, intr_ptr))
19991 goto cannot_handle;
19992 if ((segoffs >> 16) == BIOSSEG)
19993diff --git a/arch/x86/kernel/vmlinux.lds.S b/arch/x86/kernel/vmlinux.lds.S
19994index 22a1530..8fbaaad 100644
19995--- a/arch/x86/kernel/vmlinux.lds.S
19996+++ b/arch/x86/kernel/vmlinux.lds.S
19997@@ -26,6 +26,13 @@
19998 #include <asm/page_types.h>
19999 #include <asm/cache.h>
20000 #include <asm/boot.h>
20001+#include <asm/segment.h>
20002+
20003+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
20004+#define __KERNEL_TEXT_OFFSET (LOAD_OFFSET + ____LOAD_PHYSICAL_ADDR)
20005+#else
20006+#define __KERNEL_TEXT_OFFSET 0
20007+#endif
20008
20009 #undef i386 /* in case the preprocessor is a 32bit one */
20010
20011@@ -69,30 +76,43 @@ jiffies_64 = jiffies;
20012
20013 PHDRS {
20014 text PT_LOAD FLAGS(5); /* R_E */
20015+#ifdef CONFIG_X86_32
20016+ module PT_LOAD FLAGS(5); /* R_E */
20017+#endif
20018+#ifdef CONFIG_XEN
20019+ rodata PT_LOAD FLAGS(5); /* R_E */
20020+#else
20021+ rodata PT_LOAD FLAGS(4); /* R__ */
20022+#endif
20023 data PT_LOAD FLAGS(6); /* RW_ */
20024-#ifdef CONFIG_X86_64
20025+ init.begin PT_LOAD FLAGS(6); /* RW_ */
20026 #ifdef CONFIG_SMP
20027 percpu PT_LOAD FLAGS(6); /* RW_ */
20028 #endif
20029+ text.init PT_LOAD FLAGS(5); /* R_E */
20030+ text.exit PT_LOAD FLAGS(5); /* R_E */
20031 init PT_LOAD FLAGS(7); /* RWE */
20032-#endif
20033 note PT_NOTE FLAGS(0); /* ___ */
20034 }
20035
20036 SECTIONS
20037 {
20038 #ifdef CONFIG_X86_32
20039- . = LOAD_OFFSET + LOAD_PHYSICAL_ADDR;
20040- phys_startup_32 = startup_32 - LOAD_OFFSET;
20041+ . = LOAD_OFFSET + ____LOAD_PHYSICAL_ADDR;
20042 #else
20043- . = __START_KERNEL;
20044- phys_startup_64 = startup_64 - LOAD_OFFSET;
20045+ . = __START_KERNEL;
20046 #endif
20047
20048 /* Text and read-only data */
20049- .text : AT(ADDR(.text) - LOAD_OFFSET) {
20050- _text = .;
20051+ .text (. - __KERNEL_TEXT_OFFSET): AT(ADDR(.text) - LOAD_OFFSET + __KERNEL_TEXT_OFFSET) {
20052 /* bootstrapping code */
20053+#ifdef CONFIG_X86_32
20054+ phys_startup_32 = startup_32 - LOAD_OFFSET + __KERNEL_TEXT_OFFSET;
20055+#else
20056+ phys_startup_64 = startup_64 - LOAD_OFFSET + __KERNEL_TEXT_OFFSET;
20057+#endif
20058+ __LOAD_PHYSICAL_ADDR = . - LOAD_OFFSET + __KERNEL_TEXT_OFFSET;
20059+ _text = .;
20060 HEAD_TEXT
20061 #ifdef CONFIG_X86_32
20062 . = ALIGN(PAGE_SIZE);
20063@@ -108,13 +128,48 @@ SECTIONS
20064 IRQENTRY_TEXT
20065 *(.fixup)
20066 *(.gnu.warning)
20067- /* End of text section */
20068- _etext = .;
20069 } :text = 0x9090
20070
20071- NOTES :text :note
20072+ . += __KERNEL_TEXT_OFFSET;
20073
20074- EXCEPTION_TABLE(16) :text = 0x9090
20075+#ifdef CONFIG_X86_32
20076+ . = ALIGN(PAGE_SIZE);
20077+ .module.text : AT(ADDR(.module.text) - LOAD_OFFSET) {
20078+
20079+#if defined(CONFIG_PAX_KERNEXEC) && defined(CONFIG_MODULES)
20080+ MODULES_EXEC_VADDR = .;
20081+ BYTE(0)
20082+ . += (CONFIG_PAX_KERNEXEC_MODULE_TEXT * 1024 * 1024);
20083+ . = ALIGN(HPAGE_SIZE) - 1;
20084+ MODULES_EXEC_END = .;
20085+#endif
20086+
20087+ } :module
20088+#endif
20089+
20090+ .text.end : AT(ADDR(.text.end) - LOAD_OFFSET) {
20091+ /* End of text section */
20092+ BYTE(0)
20093+ _etext = . - __KERNEL_TEXT_OFFSET;
20094+ }
20095+
20096+#ifdef CONFIG_X86_32
20097+ . = ALIGN(PAGE_SIZE);
20098+ .rodata.page_aligned : AT(ADDR(.rodata.page_aligned) - LOAD_OFFSET) {
20099+ *(.idt)
20100+ . = ALIGN(PAGE_SIZE);
20101+ *(.empty_zero_page)
20102+ *(.initial_pg_fixmap)
20103+ *(.initial_pg_pmd)
20104+ *(.initial_page_table)
20105+ *(.swapper_pg_dir)
20106+ } :rodata
20107+#endif
20108+
20109+ . = ALIGN(PAGE_SIZE);
20110+ NOTES :rodata :note
20111+
20112+ EXCEPTION_TABLE(16) :rodata
20113
20114 #if defined(CONFIG_DEBUG_RODATA)
20115 /* .text should occupy whole number of pages */
20116@@ -126,16 +181,20 @@ SECTIONS
20117
20118 /* Data */
20119 .data : AT(ADDR(.data) - LOAD_OFFSET) {
20120+
20121+#ifdef CONFIG_PAX_KERNEXEC
20122+ . = ALIGN(HPAGE_SIZE);
20123+#else
20124+ . = ALIGN(PAGE_SIZE);
20125+#endif
20126+
20127 /* Start of data section */
20128 _sdata = .;
20129
20130 /* init_task */
20131 INIT_TASK_DATA(THREAD_SIZE)
20132
20133-#ifdef CONFIG_X86_32
20134- /* 32 bit has nosave before _edata */
20135 NOSAVE_DATA
20136-#endif
20137
20138 PAGE_ALIGNED_DATA(PAGE_SIZE)
20139
20140@@ -176,12 +235,19 @@ SECTIONS
20141 #endif /* CONFIG_X86_64 */
20142
20143 /* Init code and data - will be freed after init */
20144- . = ALIGN(PAGE_SIZE);
20145 .init.begin : AT(ADDR(.init.begin) - LOAD_OFFSET) {
20146+ BYTE(0)
20147+
20148+#ifdef CONFIG_PAX_KERNEXEC
20149+ . = ALIGN(HPAGE_SIZE);
20150+#else
20151+ . = ALIGN(PAGE_SIZE);
20152+#endif
20153+
20154 __init_begin = .; /* paired with __init_end */
20155- }
20156+ } :init.begin
20157
20158-#if defined(CONFIG_X86_64) && defined(CONFIG_SMP)
20159+#ifdef CONFIG_SMP
20160 /*
20161 * percpu offsets are zero-based on SMP. PERCPU_VADDR() changes the
20162 * output PHDR, so the next output section - .init.text - should
20163@@ -190,12 +256,27 @@ SECTIONS
20164 PERCPU_VADDR(INTERNODE_CACHE_BYTES, 0, :percpu)
20165 #endif
20166
20167- INIT_TEXT_SECTION(PAGE_SIZE)
20168-#ifdef CONFIG_X86_64
20169- :init
20170-#endif
20171+ . = ALIGN(PAGE_SIZE);
20172+ init_begin = .;
20173+ .init.text (. - __KERNEL_TEXT_OFFSET): AT(init_begin - LOAD_OFFSET) {
20174+ VMLINUX_SYMBOL(_sinittext) = .;
20175+ INIT_TEXT
20176+ VMLINUX_SYMBOL(_einittext) = .;
20177+ . = ALIGN(PAGE_SIZE);
20178+ } :text.init
20179
20180- INIT_DATA_SECTION(16)
20181+ /*
20182+ * .exit.text is discard at runtime, not link time, to deal with
20183+ * references from .altinstructions and .eh_frame
20184+ */
20185+ .exit.text : AT(ADDR(.exit.text) - LOAD_OFFSET + __KERNEL_TEXT_OFFSET) {
20186+ EXIT_TEXT
20187+ . = ALIGN(16);
20188+ } :text.exit
20189+ . = init_begin + SIZEOF(.init.text) + SIZEOF(.exit.text);
20190+
20191+ . = ALIGN(PAGE_SIZE);
20192+ INIT_DATA_SECTION(16) :init
20193
20194 .x86_cpu_dev.init : AT(ADDR(.x86_cpu_dev.init) - LOAD_OFFSET) {
20195 __x86_cpu_dev_start = .;
20196@@ -257,19 +338,12 @@ SECTIONS
20197 }
20198
20199 . = ALIGN(8);
20200- /*
20201- * .exit.text is discard at runtime, not link time, to deal with
20202- * references from .altinstructions and .eh_frame
20203- */
20204- .exit.text : AT(ADDR(.exit.text) - LOAD_OFFSET) {
20205- EXIT_TEXT
20206- }
20207
20208 .exit.data : AT(ADDR(.exit.data) - LOAD_OFFSET) {
20209 EXIT_DATA
20210 }
20211
20212-#if !defined(CONFIG_X86_64) || !defined(CONFIG_SMP)
20213+#ifndef CONFIG_SMP
20214 PERCPU_SECTION(INTERNODE_CACHE_BYTES)
20215 #endif
20216
20217@@ -288,16 +362,10 @@ SECTIONS
20218 .smp_locks : AT(ADDR(.smp_locks) - LOAD_OFFSET) {
20219 __smp_locks = .;
20220 *(.smp_locks)
20221- . = ALIGN(PAGE_SIZE);
20222 __smp_locks_end = .;
20223+ . = ALIGN(PAGE_SIZE);
20224 }
20225
20226-#ifdef CONFIG_X86_64
20227- .data_nosave : AT(ADDR(.data_nosave) - LOAD_OFFSET) {
20228- NOSAVE_DATA
20229- }
20230-#endif
20231-
20232 /* BSS */
20233 . = ALIGN(PAGE_SIZE);
20234 .bss : AT(ADDR(.bss) - LOAD_OFFSET) {
20235@@ -313,6 +381,7 @@ SECTIONS
20236 __brk_base = .;
20237 . += 64 * 1024; /* 64k alignment slop space */
20238 *(.brk_reservation) /* areas brk users have reserved */
20239+ . = ALIGN(HPAGE_SIZE);
20240 __brk_limit = .;
20241 }
20242
20243@@ -339,13 +408,12 @@ SECTIONS
20244 * for the boot processor.
20245 */
20246 #define INIT_PER_CPU(x) init_per_cpu__##x = x + __per_cpu_load
20247-INIT_PER_CPU(gdt_page);
20248 INIT_PER_CPU(irq_stack_union);
20249
20250 /*
20251 * Build-time check on the image size:
20252 */
20253-. = ASSERT((_end - _text <= KERNEL_IMAGE_SIZE),
20254+. = ASSERT((_end - _text - __KERNEL_TEXT_OFFSET <= KERNEL_IMAGE_SIZE),
20255 "kernel image bigger than KERNEL_IMAGE_SIZE");
20256
20257 #ifdef CONFIG_SMP
20258diff --git a/arch/x86/kernel/vsmp_64.c b/arch/x86/kernel/vsmp_64.c
20259index 992f890..fc38904 100644
20260--- a/arch/x86/kernel/vsmp_64.c
20261+++ b/arch/x86/kernel/vsmp_64.c
20262@@ -217,8 +217,8 @@ static void fill_vector_allocation_domain(int cpu, struct cpumask *retmask,
20263 static void vsmp_apic_post_init(void)
20264 {
20265 /* need to update phys_pkg_id */
20266- apic->phys_pkg_id = apicid_phys_pkg_id;
20267- apic->vector_allocation_domain = fill_vector_allocation_domain;
20268+ *(void **)&apic->phys_pkg_id = apicid_phys_pkg_id;
20269+ *(void **)&apic->vector_allocation_domain = fill_vector_allocation_domain;
20270 }
20271
20272 void __init vsmp_init(void)
20273diff --git a/arch/x86/kernel/vsyscall_64.c b/arch/x86/kernel/vsyscall_64.c
20274index 8d141b3..40a0fe4 100644
20275--- a/arch/x86/kernel/vsyscall_64.c
20276+++ b/arch/x86/kernel/vsyscall_64.c
20277@@ -56,15 +56,13 @@
20278 DEFINE_VVAR(int, vgetcpu_mode);
20279 DEFINE_VVAR(struct vsyscall_gtod_data, vsyscall_gtod_data);
20280
20281-static enum { EMULATE, NATIVE, NONE } vsyscall_mode = EMULATE;
20282+static enum { EMULATE, NONE } vsyscall_mode = EMULATE;
20283
20284 static int __init vsyscall_setup(char *str)
20285 {
20286 if (str) {
20287 if (!strcmp("emulate", str))
20288 vsyscall_mode = EMULATE;
20289- else if (!strcmp("native", str))
20290- vsyscall_mode = NATIVE;
20291 else if (!strcmp("none", str))
20292 vsyscall_mode = NONE;
20293 else
20294@@ -306,8 +304,7 @@ done:
20295 return true;
20296
20297 sigsegv:
20298- force_sig(SIGSEGV, current);
20299- return true;
20300+ do_group_exit(SIGKILL);
20301 }
20302
20303 /*
20304@@ -360,10 +357,7 @@ void __init map_vsyscall(void)
20305 extern char __vvar_page;
20306 unsigned long physaddr_vvar_page = __pa_symbol(&__vvar_page);
20307
20308- __set_fixmap(VSYSCALL_FIRST_PAGE, physaddr_vsyscall,
20309- vsyscall_mode == NATIVE
20310- ? PAGE_KERNEL_VSYSCALL
20311- : PAGE_KERNEL_VVAR);
20312+ __set_fixmap(VSYSCALL_FIRST_PAGE, physaddr_vsyscall, PAGE_KERNEL_VVAR);
20313 BUILD_BUG_ON((unsigned long)__fix_to_virt(VSYSCALL_FIRST_PAGE) !=
20314 (unsigned long)VSYSCALL_START);
20315
20316diff --git a/arch/x86/kernel/x8664_ksyms_64.c b/arch/x86/kernel/x8664_ksyms_64.c
20317index 6020f6f..bedd6e3 100644
20318--- a/arch/x86/kernel/x8664_ksyms_64.c
20319+++ b/arch/x86/kernel/x8664_ksyms_64.c
20320@@ -30,8 +30,6 @@ EXPORT_SYMBOL(copy_user_generic_string);
20321 EXPORT_SYMBOL(copy_user_generic_unrolled);
20322 EXPORT_SYMBOL(copy_user_enhanced_fast_string);
20323 EXPORT_SYMBOL(__copy_user_nocache);
20324-EXPORT_SYMBOL(_copy_from_user);
20325-EXPORT_SYMBOL(_copy_to_user);
20326
20327 EXPORT_SYMBOL(copy_page);
20328 EXPORT_SYMBOL(clear_page);
20329diff --git a/arch/x86/kernel/xsave.c b/arch/x86/kernel/xsave.c
20330index 3d3e207..1a73ab2 100644
20331--- a/arch/x86/kernel/xsave.c
20332+++ b/arch/x86/kernel/xsave.c
20333@@ -132,7 +132,7 @@ int check_for_xstate(struct i387_fxsave_struct __user *buf,
20334 fx_sw_user->xstate_size > fx_sw_user->extended_size)
20335 return -EINVAL;
20336
20337- err = __get_user(magic2, (__u32 *) (((void *)fpstate) +
20338+ err = __get_user(magic2, (__u32 __user *) (((void __user *)fpstate) +
20339 fx_sw_user->extended_size -
20340 FP_XSTATE_MAGIC2_SIZE));
20341 if (err)
20342@@ -268,7 +268,7 @@ fx_only:
20343 * the other extended state.
20344 */
20345 xrstor_state(init_xstate_buf, pcntxt_mask & ~XSTATE_FPSSE);
20346- return fxrstor_checking((__force struct i387_fxsave_struct *)buf);
20347+ return fxrstor_checking((struct i387_fxsave_struct __force_kernel *)buf);
20348 }
20349
20350 /*
20351@@ -297,7 +297,7 @@ int restore_i387_xstate(void __user *buf)
20352 if (use_xsave())
20353 err = restore_user_xstate(buf);
20354 else
20355- err = fxrstor_checking((__force struct i387_fxsave_struct *)
20356+ err = fxrstor_checking((struct i387_fxsave_struct __force_kernel *)
20357 buf);
20358 if (unlikely(err)) {
20359 /*
20360diff --git a/arch/x86/kvm/cpuid.c b/arch/x86/kvm/cpuid.c
20361index 0595f13..b544fa3 100644
20362--- a/arch/x86/kvm/cpuid.c
20363+++ b/arch/x86/kvm/cpuid.c
20364@@ -124,15 +124,20 @@ int kvm_vcpu_ioctl_set_cpuid2(struct kvm_vcpu *vcpu,
20365 struct kvm_cpuid2 *cpuid,
20366 struct kvm_cpuid_entry2 __user *entries)
20367 {
20368- int r;
20369+ int r, i;
20370
20371 r = -E2BIG;
20372 if (cpuid->nent > KVM_MAX_CPUID_ENTRIES)
20373 goto out;
20374 r = -EFAULT;
20375- if (copy_from_user(&vcpu->arch.cpuid_entries, entries,
20376- cpuid->nent * sizeof(struct kvm_cpuid_entry2)))
20377+ if (!access_ok(VERIFY_READ, entries, cpuid->nent * sizeof(struct kvm_cpuid_entry2)))
20378 goto out;
20379+ for (i = 0; i < cpuid->nent; ++i) {
20380+ struct kvm_cpuid_entry2 cpuid_entry;
20381+ if (__copy_from_user(&cpuid_entry, entries + i, sizeof(cpuid_entry)))
20382+ goto out;
20383+ vcpu->arch.cpuid_entries[i] = cpuid_entry;
20384+ }
20385 vcpu->arch.cpuid_nent = cpuid->nent;
20386 kvm_apic_set_version(vcpu);
20387 kvm_x86_ops->cpuid_update(vcpu);
20388@@ -147,15 +152,19 @@ int kvm_vcpu_ioctl_get_cpuid2(struct kvm_vcpu *vcpu,
20389 struct kvm_cpuid2 *cpuid,
20390 struct kvm_cpuid_entry2 __user *entries)
20391 {
20392- int r;
20393+ int r, i;
20394
20395 r = -E2BIG;
20396 if (cpuid->nent < vcpu->arch.cpuid_nent)
20397 goto out;
20398 r = -EFAULT;
20399- if (copy_to_user(entries, &vcpu->arch.cpuid_entries,
20400- vcpu->arch.cpuid_nent * sizeof(struct kvm_cpuid_entry2)))
20401+ if (!access_ok(VERIFY_WRITE, entries, vcpu->arch.cpuid_nent * sizeof(struct kvm_cpuid_entry2)))
20402 goto out;
20403+ for (i = 0; i < vcpu->arch.cpuid_nent; ++i) {
20404+ struct kvm_cpuid_entry2 cpuid_entry = vcpu->arch.cpuid_entries[i];
20405+ if (__copy_to_user(entries + i, &cpuid_entry, sizeof(cpuid_entry)))
20406+ goto out;
20407+ }
20408 return 0;
20409
20410 out:
20411diff --git a/arch/x86/kvm/emulate.c b/arch/x86/kvm/emulate.c
20412index a3b57a2..ebbe732 100644
20413--- a/arch/x86/kvm/emulate.c
20414+++ b/arch/x86/kvm/emulate.c
20415@@ -256,6 +256,7 @@ struct gprefix {
20416
20417 #define ____emulate_2op(ctxt, _op, _x, _y, _suffix, _dsttype) \
20418 do { \
20419+ unsigned long _tmp; \
20420 __asm__ __volatile__ ( \
20421 _PRE_EFLAGS("0", "4", "2") \
20422 _op _suffix " %"_x"3,%1; " \
20423@@ -270,8 +271,6 @@ struct gprefix {
20424 /* Raw emulation: instruction has two explicit operands. */
20425 #define __emulate_2op_nobyte(ctxt,_op,_wx,_wy,_lx,_ly,_qx,_qy) \
20426 do { \
20427- unsigned long _tmp; \
20428- \
20429 switch ((ctxt)->dst.bytes) { \
20430 case 2: \
20431 ____emulate_2op(ctxt,_op,_wx,_wy,"w",u16); \
20432@@ -287,7 +286,6 @@ struct gprefix {
20433
20434 #define __emulate_2op(ctxt,_op,_bx,_by,_wx,_wy,_lx,_ly,_qx,_qy) \
20435 do { \
20436- unsigned long _tmp; \
20437 switch ((ctxt)->dst.bytes) { \
20438 case 1: \
20439 ____emulate_2op(ctxt,_op,_bx,_by,"b",u8); \
20440diff --git a/arch/x86/kvm/lapic.c b/arch/x86/kvm/lapic.c
20441index ce87878..ab48aa3 100644
20442--- a/arch/x86/kvm/lapic.c
20443+++ b/arch/x86/kvm/lapic.c
20444@@ -54,7 +54,7 @@
20445 #define APIC_BUS_CYCLE_NS 1
20446
20447 /* #define apic_debug(fmt,arg...) printk(KERN_WARNING fmt,##arg) */
20448-#define apic_debug(fmt, arg...)
20449+#define apic_debug(fmt, arg...) do {} while (0)
20450
20451 #define APIC_LVT_NUM 6
20452 /* 14 is the version for Xeon and Pentium 8.4.8*/
20453diff --git a/arch/x86/kvm/paging_tmpl.h b/arch/x86/kvm/paging_tmpl.h
20454index bb7cf01..0348a05 100644
20455--- a/arch/x86/kvm/paging_tmpl.h
20456+++ b/arch/x86/kvm/paging_tmpl.h
20457@@ -196,7 +196,7 @@ retry_walk:
20458 if (unlikely(kvm_is_error_hva(host_addr)))
20459 goto error;
20460
20461- ptep_user = (pt_element_t __user *)((void *)host_addr + offset);
20462+ ptep_user = (pt_element_t __force_user *)((void *)host_addr + offset);
20463 if (unlikely(__copy_from_user(&pte, ptep_user, sizeof(pte))))
20464 goto error;
20465
20466diff --git a/arch/x86/kvm/svm.c b/arch/x86/kvm/svm.c
20467index baead95..90feeb4 100644
20468--- a/arch/x86/kvm/svm.c
20469+++ b/arch/x86/kvm/svm.c
20470@@ -3516,7 +3516,11 @@ static void reload_tss(struct kvm_vcpu *vcpu)
20471 int cpu = raw_smp_processor_id();
20472
20473 struct svm_cpu_data *sd = per_cpu(svm_data, cpu);
20474+
20475+ pax_open_kernel();
20476 sd->tss_desc->type = 9; /* available 32/64-bit TSS */
20477+ pax_close_kernel();
20478+
20479 load_TR_desc();
20480 }
20481
20482@@ -3894,6 +3898,10 @@ static void svm_vcpu_run(struct kvm_vcpu *vcpu)
20483 #endif
20484 #endif
20485
20486+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
20487+ __set_fs(current_thread_info()->addr_limit);
20488+#endif
20489+
20490 reload_tss(vcpu);
20491
20492 local_irq_disable();
20493diff --git a/arch/x86/kvm/vmx.c b/arch/x86/kvm/vmx.c
20494index b1eb202..254e292 100644
20495--- a/arch/x86/kvm/vmx.c
20496+++ b/arch/x86/kvm/vmx.c
20497@@ -1331,7 +1331,11 @@ static void reload_tss(void)
20498 struct desc_struct *descs;
20499
20500 descs = (void *)gdt->address;
20501+
20502+ pax_open_kernel();
20503 descs[GDT_ENTRY_TSS].type = 9; /* available TSS */
20504+ pax_close_kernel();
20505+
20506 load_TR_desc();
20507 }
20508
20509@@ -1541,6 +1545,10 @@ static void vmx_vcpu_load(struct kvm_vcpu *vcpu, int cpu)
20510 vmcs_writel(HOST_TR_BASE, kvm_read_tr_base()); /* 22.2.4 */
20511 vmcs_writel(HOST_GDTR_BASE, gdt->address); /* 22.2.4 */
20512
20513+#ifdef CONFIG_PAX_PER_CPU_PGD
20514+ vmcs_writel(HOST_CR3, read_cr3()); /* 22.2.3 FIXME: shadow tables */
20515+#endif
20516+
20517 rdmsrl(MSR_IA32_SYSENTER_ESP, sysenter_esp);
20518 vmcs_writel(HOST_IA32_SYSENTER_ESP, sysenter_esp); /* 22.2.3 */
20519 vmx->loaded_vmcs->cpu = cpu;
20520@@ -2674,8 +2682,11 @@ static __init int hardware_setup(void)
20521 if (!cpu_has_vmx_flexpriority())
20522 flexpriority_enabled = 0;
20523
20524- if (!cpu_has_vmx_tpr_shadow())
20525- kvm_x86_ops->update_cr8_intercept = NULL;
20526+ if (!cpu_has_vmx_tpr_shadow()) {
20527+ pax_open_kernel();
20528+ *(void **)&kvm_x86_ops->update_cr8_intercept = NULL;
20529+ pax_close_kernel();
20530+ }
20531
20532 if (enable_ept && !cpu_has_vmx_ept_2m_page())
20533 kvm_disable_largepages();
20534@@ -3745,7 +3756,10 @@ static void vmx_set_constant_host_state(void)
20535
20536 vmcs_writel(HOST_CR0, read_cr0() | X86_CR0_TS); /* 22.2.3 */
20537 vmcs_writel(HOST_CR4, read_cr4()); /* 22.2.3, 22.2.5 */
20538+
20539+#ifndef CONFIG_PAX_PER_CPU_PGD
20540 vmcs_writel(HOST_CR3, read_cr3()); /* 22.2.3 FIXME: shadow tables */
20541+#endif
20542
20543 vmcs_write16(HOST_CS_SELECTOR, __KERNEL_CS); /* 22.2.4 */
20544 #ifdef CONFIG_X86_64
20545@@ -3767,7 +3781,7 @@ static void vmx_set_constant_host_state(void)
20546 vmcs_writel(HOST_IDTR_BASE, dt.address); /* 22.2.4 */
20547
20548 asm("mov $.Lkvm_vmx_return, %0" : "=r"(tmpl));
20549- vmcs_writel(HOST_RIP, tmpl); /* 22.2.5 */
20550+ vmcs_writel(HOST_RIP, ktla_ktva(tmpl)); /* 22.2.5 */
20551
20552 rdmsr(MSR_IA32_SYSENTER_CS, low32, high32);
20553 vmcs_write32(HOST_IA32_SYSENTER_CS, low32);
20554@@ -6321,6 +6335,12 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
20555 "jmp .Lkvm_vmx_return \n\t"
20556 ".Llaunched: " __ex(ASM_VMX_VMRESUME) "\n\t"
20557 ".Lkvm_vmx_return: "
20558+
20559+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
20560+ "ljmp %[cs],$.Lkvm_vmx_return2\n\t"
20561+ ".Lkvm_vmx_return2: "
20562+#endif
20563+
20564 /* Save guest registers, load host registers, keep flags */
20565 "mov %0, %c[wordsize](%%"R"sp) \n\t"
20566 "pop %0 \n\t"
20567@@ -6369,6 +6389,11 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
20568 #endif
20569 [cr2]"i"(offsetof(struct vcpu_vmx, vcpu.arch.cr2)),
20570 [wordsize]"i"(sizeof(ulong))
20571+
20572+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
20573+ ,[cs]"i"(__KERNEL_CS)
20574+#endif
20575+
20576 : "cc", "memory"
20577 , R"ax", R"bx", R"di", R"si"
20578 #ifdef CONFIG_X86_64
20579@@ -6376,7 +6401,7 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
20580 #endif
20581 );
20582
20583-#ifndef CONFIG_X86_64
20584+#ifdef CONFIG_X86_32
20585 /*
20586 * The sysexit path does not restore ds/es, so we must set them to
20587 * a reasonable value ourselves.
20588@@ -6385,8 +6410,18 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
20589 * may be executed in interrupt context, which saves and restore segments
20590 * around it, nullifying its effect.
20591 */
20592- loadsegment(ds, __USER_DS);
20593- loadsegment(es, __USER_DS);
20594+ loadsegment(ds, __KERNEL_DS);
20595+ loadsegment(es, __KERNEL_DS);
20596+ loadsegment(ss, __KERNEL_DS);
20597+
20598+#ifdef CONFIG_PAX_KERNEXEC
20599+ loadsegment(fs, __KERNEL_PERCPU);
20600+#endif
20601+
20602+#ifdef CONFIG_PAX_MEMORY_UDEREF
20603+ __set_fs(current_thread_info()->addr_limit);
20604+#endif
20605+
20606 #endif
20607
20608 vcpu->arch.regs_avail = ~((1 << VCPU_REGS_RIP) | (1 << VCPU_REGS_RSP)
20609diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
20610index 2966c84..207d0cb 100644
20611--- a/arch/x86/kvm/x86.c
20612+++ b/arch/x86/kvm/x86.c
20613@@ -1379,8 +1379,8 @@ static int xen_hvm_config(struct kvm_vcpu *vcpu, u64 data)
20614 {
20615 struct kvm *kvm = vcpu->kvm;
20616 int lm = is_long_mode(vcpu);
20617- u8 *blob_addr = lm ? (u8 *)(long)kvm->arch.xen_hvm_config.blob_addr_64
20618- : (u8 *)(long)kvm->arch.xen_hvm_config.blob_addr_32;
20619+ u8 __user *blob_addr = lm ? (u8 __user *)(long)kvm->arch.xen_hvm_config.blob_addr_64
20620+ : (u8 __user *)(long)kvm->arch.xen_hvm_config.blob_addr_32;
20621 u8 blob_size = lm ? kvm->arch.xen_hvm_config.blob_size_64
20622 : kvm->arch.xen_hvm_config.blob_size_32;
20623 u32 page_num = data & ~PAGE_MASK;
20624@@ -2243,6 +2243,8 @@ long kvm_arch_dev_ioctl(struct file *filp,
20625 if (n < msr_list.nmsrs)
20626 goto out;
20627 r = -EFAULT;
20628+ if (num_msrs_to_save > ARRAY_SIZE(msrs_to_save))
20629+ goto out;
20630 if (copy_to_user(user_msr_list->indices, &msrs_to_save,
20631 num_msrs_to_save * sizeof(u32)))
20632 goto out;
20633@@ -2368,7 +2370,7 @@ static int kvm_vcpu_ioctl_set_lapic(struct kvm_vcpu *vcpu,
20634 static int kvm_vcpu_ioctl_interrupt(struct kvm_vcpu *vcpu,
20635 struct kvm_interrupt *irq)
20636 {
20637- if (irq->irq < 0 || irq->irq >= 256)
20638+ if (irq->irq >= 256)
20639 return -EINVAL;
20640 if (irqchip_in_kernel(vcpu->kvm))
20641 return -ENXIO;
20642@@ -4889,7 +4891,7 @@ static void kvm_set_mmio_spte_mask(void)
20643 kvm_mmu_set_mmio_spte_mask(mask);
20644 }
20645
20646-int kvm_arch_init(void *opaque)
20647+int kvm_arch_init(const void *opaque)
20648 {
20649 int r;
20650 struct kvm_x86_ops *ops = (struct kvm_x86_ops *)opaque;
20651diff --git a/arch/x86/lguest/boot.c b/arch/x86/lguest/boot.c
20652index 642d880..cc9ebac 100644
20653--- a/arch/x86/lguest/boot.c
20654+++ b/arch/x86/lguest/boot.c
20655@@ -1116,12 +1116,12 @@ static u32 lguest_apic_safe_wait_icr_idle(void)
20656
20657 static void set_lguest_basic_apic_ops(void)
20658 {
20659- apic->read = lguest_apic_read;
20660- apic->write = lguest_apic_write;
20661- apic->icr_read = lguest_apic_icr_read;
20662- apic->icr_write = lguest_apic_icr_write;
20663- apic->wait_icr_idle = lguest_apic_wait_icr_idle;
20664- apic->safe_wait_icr_idle = lguest_apic_safe_wait_icr_idle;
20665+ *(void **)&apic->read = lguest_apic_read;
20666+ *(void **)&apic->write = lguest_apic_write;
20667+ *(void **)&apic->icr_read = lguest_apic_icr_read;
20668+ *(void **)&apic->icr_write = lguest_apic_icr_write;
20669+ *(void **)&apic->wait_icr_idle = lguest_apic_wait_icr_idle;
20670+ *(void **)&apic->safe_wait_icr_idle = lguest_apic_safe_wait_icr_idle;
20671 };
20672 #endif
20673
20674@@ -1200,9 +1200,10 @@ static __init int early_put_chars(u32 vtermno, const char *buf, int count)
20675 * Rebooting also tells the Host we're finished, but the RESTART flag tells the
20676 * Launcher to reboot us.
20677 */
20678-static void lguest_restart(char *reason)
20679+static __noreturn void lguest_restart(char *reason)
20680 {
20681 hcall(LHCALL_SHUTDOWN, __pa(reason), LGUEST_SHUTDOWN_RESTART, 0, 0);
20682+ BUG();
20683 }
20684
20685 /*G:050
20686diff --git a/arch/x86/lib/atomic64_386_32.S b/arch/x86/lib/atomic64_386_32.S
20687index 00933d5..3a64af9 100644
20688--- a/arch/x86/lib/atomic64_386_32.S
20689+++ b/arch/x86/lib/atomic64_386_32.S
20690@@ -48,6 +48,10 @@ BEGIN(read)
20691 movl (v), %eax
20692 movl 4(v), %edx
20693 RET_ENDP
20694+BEGIN(read_unchecked)
20695+ movl (v), %eax
20696+ movl 4(v), %edx
20697+RET_ENDP
20698 #undef v
20699
20700 #define v %esi
20701@@ -55,6 +59,10 @@ BEGIN(set)
20702 movl %ebx, (v)
20703 movl %ecx, 4(v)
20704 RET_ENDP
20705+BEGIN(set_unchecked)
20706+ movl %ebx, (v)
20707+ movl %ecx, 4(v)
20708+RET_ENDP
20709 #undef v
20710
20711 #define v %esi
20712@@ -70,6 +78,20 @@ RET_ENDP
20713 BEGIN(add)
20714 addl %eax, (v)
20715 adcl %edx, 4(v)
20716+
20717+#ifdef CONFIG_PAX_REFCOUNT
20718+ jno 0f
20719+ subl %eax, (v)
20720+ sbbl %edx, 4(v)
20721+ int $4
20722+0:
20723+ _ASM_EXTABLE(0b, 0b)
20724+#endif
20725+
20726+RET_ENDP
20727+BEGIN(add_unchecked)
20728+ addl %eax, (v)
20729+ adcl %edx, 4(v)
20730 RET_ENDP
20731 #undef v
20732
20733@@ -77,6 +99,24 @@ RET_ENDP
20734 BEGIN(add_return)
20735 addl (v), %eax
20736 adcl 4(v), %edx
20737+
20738+#ifdef CONFIG_PAX_REFCOUNT
20739+ into
20740+1234:
20741+ _ASM_EXTABLE(1234b, 2f)
20742+#endif
20743+
20744+ movl %eax, (v)
20745+ movl %edx, 4(v)
20746+
20747+#ifdef CONFIG_PAX_REFCOUNT
20748+2:
20749+#endif
20750+
20751+RET_ENDP
20752+BEGIN(add_return_unchecked)
20753+ addl (v), %eax
20754+ adcl 4(v), %edx
20755 movl %eax, (v)
20756 movl %edx, 4(v)
20757 RET_ENDP
20758@@ -86,6 +126,20 @@ RET_ENDP
20759 BEGIN(sub)
20760 subl %eax, (v)
20761 sbbl %edx, 4(v)
20762+
20763+#ifdef CONFIG_PAX_REFCOUNT
20764+ jno 0f
20765+ addl %eax, (v)
20766+ adcl %edx, 4(v)
20767+ int $4
20768+0:
20769+ _ASM_EXTABLE(0b, 0b)
20770+#endif
20771+
20772+RET_ENDP
20773+BEGIN(sub_unchecked)
20774+ subl %eax, (v)
20775+ sbbl %edx, 4(v)
20776 RET_ENDP
20777 #undef v
20778
20779@@ -96,6 +150,27 @@ BEGIN(sub_return)
20780 sbbl $0, %edx
20781 addl (v), %eax
20782 adcl 4(v), %edx
20783+
20784+#ifdef CONFIG_PAX_REFCOUNT
20785+ into
20786+1234:
20787+ _ASM_EXTABLE(1234b, 2f)
20788+#endif
20789+
20790+ movl %eax, (v)
20791+ movl %edx, 4(v)
20792+
20793+#ifdef CONFIG_PAX_REFCOUNT
20794+2:
20795+#endif
20796+
20797+RET_ENDP
20798+BEGIN(sub_return_unchecked)
20799+ negl %edx
20800+ negl %eax
20801+ sbbl $0, %edx
20802+ addl (v), %eax
20803+ adcl 4(v), %edx
20804 movl %eax, (v)
20805 movl %edx, 4(v)
20806 RET_ENDP
20807@@ -105,6 +180,20 @@ RET_ENDP
20808 BEGIN(inc)
20809 addl $1, (v)
20810 adcl $0, 4(v)
20811+
20812+#ifdef CONFIG_PAX_REFCOUNT
20813+ jno 0f
20814+ subl $1, (v)
20815+ sbbl $0, 4(v)
20816+ int $4
20817+0:
20818+ _ASM_EXTABLE(0b, 0b)
20819+#endif
20820+
20821+RET_ENDP
20822+BEGIN(inc_unchecked)
20823+ addl $1, (v)
20824+ adcl $0, 4(v)
20825 RET_ENDP
20826 #undef v
20827
20828@@ -114,6 +203,26 @@ BEGIN(inc_return)
20829 movl 4(v), %edx
20830 addl $1, %eax
20831 adcl $0, %edx
20832+
20833+#ifdef CONFIG_PAX_REFCOUNT
20834+ into
20835+1234:
20836+ _ASM_EXTABLE(1234b, 2f)
20837+#endif
20838+
20839+ movl %eax, (v)
20840+ movl %edx, 4(v)
20841+
20842+#ifdef CONFIG_PAX_REFCOUNT
20843+2:
20844+#endif
20845+
20846+RET_ENDP
20847+BEGIN(inc_return_unchecked)
20848+ movl (v), %eax
20849+ movl 4(v), %edx
20850+ addl $1, %eax
20851+ adcl $0, %edx
20852 movl %eax, (v)
20853 movl %edx, 4(v)
20854 RET_ENDP
20855@@ -123,6 +232,20 @@ RET_ENDP
20856 BEGIN(dec)
20857 subl $1, (v)
20858 sbbl $0, 4(v)
20859+
20860+#ifdef CONFIG_PAX_REFCOUNT
20861+ jno 0f
20862+ addl $1, (v)
20863+ adcl $0, 4(v)
20864+ int $4
20865+0:
20866+ _ASM_EXTABLE(0b, 0b)
20867+#endif
20868+
20869+RET_ENDP
20870+BEGIN(dec_unchecked)
20871+ subl $1, (v)
20872+ sbbl $0, 4(v)
20873 RET_ENDP
20874 #undef v
20875
20876@@ -132,6 +255,26 @@ BEGIN(dec_return)
20877 movl 4(v), %edx
20878 subl $1, %eax
20879 sbbl $0, %edx
20880+
20881+#ifdef CONFIG_PAX_REFCOUNT
20882+ into
20883+1234:
20884+ _ASM_EXTABLE(1234b, 2f)
20885+#endif
20886+
20887+ movl %eax, (v)
20888+ movl %edx, 4(v)
20889+
20890+#ifdef CONFIG_PAX_REFCOUNT
20891+2:
20892+#endif
20893+
20894+RET_ENDP
20895+BEGIN(dec_return_unchecked)
20896+ movl (v), %eax
20897+ movl 4(v), %edx
20898+ subl $1, %eax
20899+ sbbl $0, %edx
20900 movl %eax, (v)
20901 movl %edx, 4(v)
20902 RET_ENDP
20903@@ -143,6 +286,13 @@ BEGIN(add_unless)
20904 adcl %edx, %edi
20905 addl (v), %eax
20906 adcl 4(v), %edx
20907+
20908+#ifdef CONFIG_PAX_REFCOUNT
20909+ into
20910+1234:
20911+ _ASM_EXTABLE(1234b, 2f)
20912+#endif
20913+
20914 cmpl %eax, %ecx
20915 je 3f
20916 1:
20917@@ -168,6 +318,13 @@ BEGIN(inc_not_zero)
20918 1:
20919 addl $1, %eax
20920 adcl $0, %edx
20921+
20922+#ifdef CONFIG_PAX_REFCOUNT
20923+ into
20924+1234:
20925+ _ASM_EXTABLE(1234b, 2f)
20926+#endif
20927+
20928 movl %eax, (v)
20929 movl %edx, 4(v)
20930 movl $1, %eax
20931@@ -186,6 +343,13 @@ BEGIN(dec_if_positive)
20932 movl 4(v), %edx
20933 subl $1, %eax
20934 sbbl $0, %edx
20935+
20936+#ifdef CONFIG_PAX_REFCOUNT
20937+ into
20938+1234:
20939+ _ASM_EXTABLE(1234b, 1f)
20940+#endif
20941+
20942 js 1f
20943 movl %eax, (v)
20944 movl %edx, 4(v)
20945diff --git a/arch/x86/lib/atomic64_cx8_32.S b/arch/x86/lib/atomic64_cx8_32.S
20946index f5cc9eb..51fa319 100644
20947--- a/arch/x86/lib/atomic64_cx8_32.S
20948+++ b/arch/x86/lib/atomic64_cx8_32.S
20949@@ -35,10 +35,20 @@ ENTRY(atomic64_read_cx8)
20950 CFI_STARTPROC
20951
20952 read64 %ecx
20953+ pax_force_retaddr
20954 ret
20955 CFI_ENDPROC
20956 ENDPROC(atomic64_read_cx8)
20957
20958+ENTRY(atomic64_read_unchecked_cx8)
20959+ CFI_STARTPROC
20960+
20961+ read64 %ecx
20962+ pax_force_retaddr
20963+ ret
20964+ CFI_ENDPROC
20965+ENDPROC(atomic64_read_unchecked_cx8)
20966+
20967 ENTRY(atomic64_set_cx8)
20968 CFI_STARTPROC
20969
20970@@ -48,10 +58,25 @@ ENTRY(atomic64_set_cx8)
20971 cmpxchg8b (%esi)
20972 jne 1b
20973
20974+ pax_force_retaddr
20975 ret
20976 CFI_ENDPROC
20977 ENDPROC(atomic64_set_cx8)
20978
20979+ENTRY(atomic64_set_unchecked_cx8)
20980+ CFI_STARTPROC
20981+
20982+1:
20983+/* we don't need LOCK_PREFIX since aligned 64-bit writes
20984+ * are atomic on 586 and newer */
20985+ cmpxchg8b (%esi)
20986+ jne 1b
20987+
20988+ pax_force_retaddr
20989+ ret
20990+ CFI_ENDPROC
20991+ENDPROC(atomic64_set_unchecked_cx8)
20992+
20993 ENTRY(atomic64_xchg_cx8)
20994 CFI_STARTPROC
20995
20996@@ -60,12 +85,13 @@ ENTRY(atomic64_xchg_cx8)
20997 cmpxchg8b (%esi)
20998 jne 1b
20999
21000+ pax_force_retaddr
21001 ret
21002 CFI_ENDPROC
21003 ENDPROC(atomic64_xchg_cx8)
21004
21005-.macro addsub_return func ins insc
21006-ENTRY(atomic64_\func\()_return_cx8)
21007+.macro addsub_return func ins insc unchecked=""
21008+ENTRY(atomic64_\func\()_return\unchecked\()_cx8)
21009 CFI_STARTPROC
21010 SAVE ebp
21011 SAVE ebx
21012@@ -82,27 +108,44 @@ ENTRY(atomic64_\func\()_return_cx8)
21013 movl %edx, %ecx
21014 \ins\()l %esi, %ebx
21015 \insc\()l %edi, %ecx
21016+
21017+.ifb \unchecked
21018+#ifdef CONFIG_PAX_REFCOUNT
21019+ into
21020+2:
21021+ _ASM_EXTABLE(2b, 3f)
21022+#endif
21023+.endif
21024+
21025 LOCK_PREFIX
21026 cmpxchg8b (%ebp)
21027 jne 1b
21028-
21029-10:
21030 movl %ebx, %eax
21031 movl %ecx, %edx
21032+
21033+.ifb \unchecked
21034+#ifdef CONFIG_PAX_REFCOUNT
21035+3:
21036+#endif
21037+.endif
21038+
21039 RESTORE edi
21040 RESTORE esi
21041 RESTORE ebx
21042 RESTORE ebp
21043+ pax_force_retaddr
21044 ret
21045 CFI_ENDPROC
21046-ENDPROC(atomic64_\func\()_return_cx8)
21047+ENDPROC(atomic64_\func\()_return\unchecked\()_cx8)
21048 .endm
21049
21050 addsub_return add add adc
21051 addsub_return sub sub sbb
21052+addsub_return add add adc _unchecked
21053+addsub_return sub sub sbb _unchecked
21054
21055-.macro incdec_return func ins insc
21056-ENTRY(atomic64_\func\()_return_cx8)
21057+.macro incdec_return func ins insc unchecked=""
21058+ENTRY(atomic64_\func\()_return\unchecked\()_cx8)
21059 CFI_STARTPROC
21060 SAVE ebx
21061
21062@@ -112,21 +155,39 @@ ENTRY(atomic64_\func\()_return_cx8)
21063 movl %edx, %ecx
21064 \ins\()l $1, %ebx
21065 \insc\()l $0, %ecx
21066+
21067+.ifb \unchecked
21068+#ifdef CONFIG_PAX_REFCOUNT
21069+ into
21070+2:
21071+ _ASM_EXTABLE(2b, 3f)
21072+#endif
21073+.endif
21074+
21075 LOCK_PREFIX
21076 cmpxchg8b (%esi)
21077 jne 1b
21078
21079-10:
21080 movl %ebx, %eax
21081 movl %ecx, %edx
21082+
21083+.ifb \unchecked
21084+#ifdef CONFIG_PAX_REFCOUNT
21085+3:
21086+#endif
21087+.endif
21088+
21089 RESTORE ebx
21090+ pax_force_retaddr
21091 ret
21092 CFI_ENDPROC
21093-ENDPROC(atomic64_\func\()_return_cx8)
21094+ENDPROC(atomic64_\func\()_return\unchecked\()_cx8)
21095 .endm
21096
21097 incdec_return inc add adc
21098 incdec_return dec sub sbb
21099+incdec_return inc add adc _unchecked
21100+incdec_return dec sub sbb _unchecked
21101
21102 ENTRY(atomic64_dec_if_positive_cx8)
21103 CFI_STARTPROC
21104@@ -138,6 +199,13 @@ ENTRY(atomic64_dec_if_positive_cx8)
21105 movl %edx, %ecx
21106 subl $1, %ebx
21107 sbb $0, %ecx
21108+
21109+#ifdef CONFIG_PAX_REFCOUNT
21110+ into
21111+1234:
21112+ _ASM_EXTABLE(1234b, 2f)
21113+#endif
21114+
21115 js 2f
21116 LOCK_PREFIX
21117 cmpxchg8b (%esi)
21118@@ -147,6 +215,7 @@ ENTRY(atomic64_dec_if_positive_cx8)
21119 movl %ebx, %eax
21120 movl %ecx, %edx
21121 RESTORE ebx
21122+ pax_force_retaddr
21123 ret
21124 CFI_ENDPROC
21125 ENDPROC(atomic64_dec_if_positive_cx8)
21126@@ -171,6 +240,13 @@ ENTRY(atomic64_add_unless_cx8)
21127 movl %edx, %ecx
21128 addl %ebp, %ebx
21129 adcl %edi, %ecx
21130+
21131+#ifdef CONFIG_PAX_REFCOUNT
21132+ into
21133+1234:
21134+ _ASM_EXTABLE(1234b, 3f)
21135+#endif
21136+
21137 LOCK_PREFIX
21138 cmpxchg8b (%esi)
21139 jne 1b
21140@@ -181,6 +257,7 @@ ENTRY(atomic64_add_unless_cx8)
21141 CFI_ADJUST_CFA_OFFSET -8
21142 RESTORE ebx
21143 RESTORE ebp
21144+ pax_force_retaddr
21145 ret
21146 4:
21147 cmpl %edx, 4(%esp)
21148@@ -203,6 +280,13 @@ ENTRY(atomic64_inc_not_zero_cx8)
21149 xorl %ecx, %ecx
21150 addl $1, %ebx
21151 adcl %edx, %ecx
21152+
21153+#ifdef CONFIG_PAX_REFCOUNT
21154+ into
21155+1234:
21156+ _ASM_EXTABLE(1234b, 3f)
21157+#endif
21158+
21159 LOCK_PREFIX
21160 cmpxchg8b (%esi)
21161 jne 1b
21162@@ -210,6 +294,7 @@ ENTRY(atomic64_inc_not_zero_cx8)
21163 movl $1, %eax
21164 3:
21165 RESTORE ebx
21166+ pax_force_retaddr
21167 ret
21168 CFI_ENDPROC
21169 ENDPROC(atomic64_inc_not_zero_cx8)
21170diff --git a/arch/x86/lib/checksum_32.S b/arch/x86/lib/checksum_32.S
21171index 2af5df3..62b1a5a 100644
21172--- a/arch/x86/lib/checksum_32.S
21173+++ b/arch/x86/lib/checksum_32.S
21174@@ -29,7 +29,8 @@
21175 #include <asm/dwarf2.h>
21176 #include <asm/errno.h>
21177 #include <asm/asm.h>
21178-
21179+#include <asm/segment.h>
21180+
21181 /*
21182 * computes a partial checksum, e.g. for TCP/UDP fragments
21183 */
21184@@ -293,9 +294,24 @@ unsigned int csum_partial_copy_generic (const char *src, char *dst,
21185
21186 #define ARGBASE 16
21187 #define FP 12
21188-
21189-ENTRY(csum_partial_copy_generic)
21190+
21191+ENTRY(csum_partial_copy_generic_to_user)
21192 CFI_STARTPROC
21193+
21194+#ifdef CONFIG_PAX_MEMORY_UDEREF
21195+ pushl_cfi %gs
21196+ popl_cfi %es
21197+ jmp csum_partial_copy_generic
21198+#endif
21199+
21200+ENTRY(csum_partial_copy_generic_from_user)
21201+
21202+#ifdef CONFIG_PAX_MEMORY_UDEREF
21203+ pushl_cfi %gs
21204+ popl_cfi %ds
21205+#endif
21206+
21207+ENTRY(csum_partial_copy_generic)
21208 subl $4,%esp
21209 CFI_ADJUST_CFA_OFFSET 4
21210 pushl_cfi %edi
21211@@ -317,7 +333,7 @@ ENTRY(csum_partial_copy_generic)
21212 jmp 4f
21213 SRC(1: movw (%esi), %bx )
21214 addl $2, %esi
21215-DST( movw %bx, (%edi) )
21216+DST( movw %bx, %es:(%edi) )
21217 addl $2, %edi
21218 addw %bx, %ax
21219 adcl $0, %eax
21220@@ -329,30 +345,30 @@ DST( movw %bx, (%edi) )
21221 SRC(1: movl (%esi), %ebx )
21222 SRC( movl 4(%esi), %edx )
21223 adcl %ebx, %eax
21224-DST( movl %ebx, (%edi) )
21225+DST( movl %ebx, %es:(%edi) )
21226 adcl %edx, %eax
21227-DST( movl %edx, 4(%edi) )
21228+DST( movl %edx, %es:4(%edi) )
21229
21230 SRC( movl 8(%esi), %ebx )
21231 SRC( movl 12(%esi), %edx )
21232 adcl %ebx, %eax
21233-DST( movl %ebx, 8(%edi) )
21234+DST( movl %ebx, %es:8(%edi) )
21235 adcl %edx, %eax
21236-DST( movl %edx, 12(%edi) )
21237+DST( movl %edx, %es:12(%edi) )
21238
21239 SRC( movl 16(%esi), %ebx )
21240 SRC( movl 20(%esi), %edx )
21241 adcl %ebx, %eax
21242-DST( movl %ebx, 16(%edi) )
21243+DST( movl %ebx, %es:16(%edi) )
21244 adcl %edx, %eax
21245-DST( movl %edx, 20(%edi) )
21246+DST( movl %edx, %es:20(%edi) )
21247
21248 SRC( movl 24(%esi), %ebx )
21249 SRC( movl 28(%esi), %edx )
21250 adcl %ebx, %eax
21251-DST( movl %ebx, 24(%edi) )
21252+DST( movl %ebx, %es:24(%edi) )
21253 adcl %edx, %eax
21254-DST( movl %edx, 28(%edi) )
21255+DST( movl %edx, %es:28(%edi) )
21256
21257 lea 32(%esi), %esi
21258 lea 32(%edi), %edi
21259@@ -366,7 +382,7 @@ DST( movl %edx, 28(%edi) )
21260 shrl $2, %edx # This clears CF
21261 SRC(3: movl (%esi), %ebx )
21262 adcl %ebx, %eax
21263-DST( movl %ebx, (%edi) )
21264+DST( movl %ebx, %es:(%edi) )
21265 lea 4(%esi), %esi
21266 lea 4(%edi), %edi
21267 dec %edx
21268@@ -378,12 +394,12 @@ DST( movl %ebx, (%edi) )
21269 jb 5f
21270 SRC( movw (%esi), %cx )
21271 leal 2(%esi), %esi
21272-DST( movw %cx, (%edi) )
21273+DST( movw %cx, %es:(%edi) )
21274 leal 2(%edi), %edi
21275 je 6f
21276 shll $16,%ecx
21277 SRC(5: movb (%esi), %cl )
21278-DST( movb %cl, (%edi) )
21279+DST( movb %cl, %es:(%edi) )
21280 6: addl %ecx, %eax
21281 adcl $0, %eax
21282 7:
21283@@ -394,7 +410,7 @@ DST( movb %cl, (%edi) )
21284
21285 6001:
21286 movl ARGBASE+20(%esp), %ebx # src_err_ptr
21287- movl $-EFAULT, (%ebx)
21288+ movl $-EFAULT, %ss:(%ebx)
21289
21290 # zero the complete destination - computing the rest
21291 # is too much work
21292@@ -407,11 +423,15 @@ DST( movb %cl, (%edi) )
21293
21294 6002:
21295 movl ARGBASE+24(%esp), %ebx # dst_err_ptr
21296- movl $-EFAULT,(%ebx)
21297+ movl $-EFAULT,%ss:(%ebx)
21298 jmp 5000b
21299
21300 .previous
21301
21302+ pushl_cfi %ss
21303+ popl_cfi %ds
21304+ pushl_cfi %ss
21305+ popl_cfi %es
21306 popl_cfi %ebx
21307 CFI_RESTORE ebx
21308 popl_cfi %esi
21309@@ -421,26 +441,43 @@ DST( movb %cl, (%edi) )
21310 popl_cfi %ecx # equivalent to addl $4,%esp
21311 ret
21312 CFI_ENDPROC
21313-ENDPROC(csum_partial_copy_generic)
21314+ENDPROC(csum_partial_copy_generic_to_user)
21315
21316 #else
21317
21318 /* Version for PentiumII/PPro */
21319
21320 #define ROUND1(x) \
21321+ nop; nop; nop; \
21322 SRC(movl x(%esi), %ebx ) ; \
21323 addl %ebx, %eax ; \
21324- DST(movl %ebx, x(%edi) ) ;
21325+ DST(movl %ebx, %es:x(%edi)) ;
21326
21327 #define ROUND(x) \
21328+ nop; nop; nop; \
21329 SRC(movl x(%esi), %ebx ) ; \
21330 adcl %ebx, %eax ; \
21331- DST(movl %ebx, x(%edi) ) ;
21332+ DST(movl %ebx, %es:x(%edi)) ;
21333
21334 #define ARGBASE 12
21335-
21336-ENTRY(csum_partial_copy_generic)
21337+
21338+ENTRY(csum_partial_copy_generic_to_user)
21339 CFI_STARTPROC
21340+
21341+#ifdef CONFIG_PAX_MEMORY_UDEREF
21342+ pushl_cfi %gs
21343+ popl_cfi %es
21344+ jmp csum_partial_copy_generic
21345+#endif
21346+
21347+ENTRY(csum_partial_copy_generic_from_user)
21348+
21349+#ifdef CONFIG_PAX_MEMORY_UDEREF
21350+ pushl_cfi %gs
21351+ popl_cfi %ds
21352+#endif
21353+
21354+ENTRY(csum_partial_copy_generic)
21355 pushl_cfi %ebx
21356 CFI_REL_OFFSET ebx, 0
21357 pushl_cfi %edi
21358@@ -461,7 +498,7 @@ ENTRY(csum_partial_copy_generic)
21359 subl %ebx, %edi
21360 lea -1(%esi),%edx
21361 andl $-32,%edx
21362- lea 3f(%ebx,%ebx), %ebx
21363+ lea 3f(%ebx,%ebx,2), %ebx
21364 testl %esi, %esi
21365 jmp *%ebx
21366 1: addl $64,%esi
21367@@ -482,19 +519,19 @@ ENTRY(csum_partial_copy_generic)
21368 jb 5f
21369 SRC( movw (%esi), %dx )
21370 leal 2(%esi), %esi
21371-DST( movw %dx, (%edi) )
21372+DST( movw %dx, %es:(%edi) )
21373 leal 2(%edi), %edi
21374 je 6f
21375 shll $16,%edx
21376 5:
21377 SRC( movb (%esi), %dl )
21378-DST( movb %dl, (%edi) )
21379+DST( movb %dl, %es:(%edi) )
21380 6: addl %edx, %eax
21381 adcl $0, %eax
21382 7:
21383 .section .fixup, "ax"
21384 6001: movl ARGBASE+20(%esp), %ebx # src_err_ptr
21385- movl $-EFAULT, (%ebx)
21386+ movl $-EFAULT, %ss:(%ebx)
21387 # zero the complete destination (computing the rest is too much work)
21388 movl ARGBASE+8(%esp),%edi # dst
21389 movl ARGBASE+12(%esp),%ecx # len
21390@@ -502,10 +539,17 @@ DST( movb %dl, (%edi) )
21391 rep; stosb
21392 jmp 7b
21393 6002: movl ARGBASE+24(%esp), %ebx # dst_err_ptr
21394- movl $-EFAULT, (%ebx)
21395+ movl $-EFAULT, %ss:(%ebx)
21396 jmp 7b
21397 .previous
21398
21399+#ifdef CONFIG_PAX_MEMORY_UDEREF
21400+ pushl_cfi %ss
21401+ popl_cfi %ds
21402+ pushl_cfi %ss
21403+ popl_cfi %es
21404+#endif
21405+
21406 popl_cfi %esi
21407 CFI_RESTORE esi
21408 popl_cfi %edi
21409@@ -514,7 +558,7 @@ DST( movb %dl, (%edi) )
21410 CFI_RESTORE ebx
21411 ret
21412 CFI_ENDPROC
21413-ENDPROC(csum_partial_copy_generic)
21414+ENDPROC(csum_partial_copy_generic_to_user)
21415
21416 #undef ROUND
21417 #undef ROUND1
21418diff --git a/arch/x86/lib/clear_page_64.S b/arch/x86/lib/clear_page_64.S
21419index f2145cf..cea889d 100644
21420--- a/arch/x86/lib/clear_page_64.S
21421+++ b/arch/x86/lib/clear_page_64.S
21422@@ -11,6 +11,7 @@ ENTRY(clear_page_c)
21423 movl $4096/8,%ecx
21424 xorl %eax,%eax
21425 rep stosq
21426+ pax_force_retaddr
21427 ret
21428 CFI_ENDPROC
21429 ENDPROC(clear_page_c)
21430@@ -20,6 +21,7 @@ ENTRY(clear_page_c_e)
21431 movl $4096,%ecx
21432 xorl %eax,%eax
21433 rep stosb
21434+ pax_force_retaddr
21435 ret
21436 CFI_ENDPROC
21437 ENDPROC(clear_page_c_e)
21438@@ -43,6 +45,7 @@ ENTRY(clear_page)
21439 leaq 64(%rdi),%rdi
21440 jnz .Lloop
21441 nop
21442+ pax_force_retaddr
21443 ret
21444 CFI_ENDPROC
21445 .Lclear_page_end:
21446@@ -58,7 +61,7 @@ ENDPROC(clear_page)
21447
21448 #include <asm/cpufeature.h>
21449
21450- .section .altinstr_replacement,"ax"
21451+ .section .altinstr_replacement,"a"
21452 1: .byte 0xeb /* jmp <disp8> */
21453 .byte (clear_page_c - clear_page) - (2f - 1b) /* offset */
21454 2: .byte 0xeb /* jmp <disp8> */
21455diff --git a/arch/x86/lib/cmpxchg16b_emu.S b/arch/x86/lib/cmpxchg16b_emu.S
21456index 1e572c5..2a162cd 100644
21457--- a/arch/x86/lib/cmpxchg16b_emu.S
21458+++ b/arch/x86/lib/cmpxchg16b_emu.S
21459@@ -53,11 +53,13 @@ this_cpu_cmpxchg16b_emu:
21460
21461 popf
21462 mov $1, %al
21463+ pax_force_retaddr
21464 ret
21465
21466 not_same:
21467 popf
21468 xor %al,%al
21469+ pax_force_retaddr
21470 ret
21471
21472 CFI_ENDPROC
21473diff --git a/arch/x86/lib/copy_page_64.S b/arch/x86/lib/copy_page_64.S
21474index 6b34d04..dccb07f 100644
21475--- a/arch/x86/lib/copy_page_64.S
21476+++ b/arch/x86/lib/copy_page_64.S
21477@@ -9,6 +9,7 @@ copy_page_c:
21478 CFI_STARTPROC
21479 movl $4096/8,%ecx
21480 rep movsq
21481+ pax_force_retaddr
21482 ret
21483 CFI_ENDPROC
21484 ENDPROC(copy_page_c)
21485@@ -20,12 +21,14 @@ ENDPROC(copy_page_c)
21486
21487 ENTRY(copy_page)
21488 CFI_STARTPROC
21489- subq $2*8,%rsp
21490- CFI_ADJUST_CFA_OFFSET 2*8
21491+ subq $3*8,%rsp
21492+ CFI_ADJUST_CFA_OFFSET 3*8
21493 movq %rbx,(%rsp)
21494 CFI_REL_OFFSET rbx, 0
21495 movq %r12,1*8(%rsp)
21496 CFI_REL_OFFSET r12, 1*8
21497+ movq %r13,2*8(%rsp)
21498+ CFI_REL_OFFSET r13, 2*8
21499
21500 movl $(4096/64)-5,%ecx
21501 .p2align 4
21502@@ -37,7 +40,7 @@ ENTRY(copy_page)
21503 movq 16 (%rsi), %rdx
21504 movq 24 (%rsi), %r8
21505 movq 32 (%rsi), %r9
21506- movq 40 (%rsi), %r10
21507+ movq 40 (%rsi), %r13
21508 movq 48 (%rsi), %r11
21509 movq 56 (%rsi), %r12
21510
21511@@ -48,7 +51,7 @@ ENTRY(copy_page)
21512 movq %rdx, 16 (%rdi)
21513 movq %r8, 24 (%rdi)
21514 movq %r9, 32 (%rdi)
21515- movq %r10, 40 (%rdi)
21516+ movq %r13, 40 (%rdi)
21517 movq %r11, 48 (%rdi)
21518 movq %r12, 56 (%rdi)
21519
21520@@ -67,7 +70,7 @@ ENTRY(copy_page)
21521 movq 16 (%rsi), %rdx
21522 movq 24 (%rsi), %r8
21523 movq 32 (%rsi), %r9
21524- movq 40 (%rsi), %r10
21525+ movq 40 (%rsi), %r13
21526 movq 48 (%rsi), %r11
21527 movq 56 (%rsi), %r12
21528
21529@@ -76,7 +79,7 @@ ENTRY(copy_page)
21530 movq %rdx, 16 (%rdi)
21531 movq %r8, 24 (%rdi)
21532 movq %r9, 32 (%rdi)
21533- movq %r10, 40 (%rdi)
21534+ movq %r13, 40 (%rdi)
21535 movq %r11, 48 (%rdi)
21536 movq %r12, 56 (%rdi)
21537
21538@@ -89,8 +92,11 @@ ENTRY(copy_page)
21539 CFI_RESTORE rbx
21540 movq 1*8(%rsp),%r12
21541 CFI_RESTORE r12
21542- addq $2*8,%rsp
21543- CFI_ADJUST_CFA_OFFSET -2*8
21544+ movq 2*8(%rsp),%r13
21545+ CFI_RESTORE r13
21546+ addq $3*8,%rsp
21547+ CFI_ADJUST_CFA_OFFSET -3*8
21548+ pax_force_retaddr
21549 ret
21550 .Lcopy_page_end:
21551 CFI_ENDPROC
21552@@ -101,7 +107,7 @@ ENDPROC(copy_page)
21553
21554 #include <asm/cpufeature.h>
21555
21556- .section .altinstr_replacement,"ax"
21557+ .section .altinstr_replacement,"a"
21558 1: .byte 0xeb /* jmp <disp8> */
21559 .byte (copy_page_c - copy_page) - (2f - 1b) /* offset */
21560 2:
21561diff --git a/arch/x86/lib/copy_user_64.S b/arch/x86/lib/copy_user_64.S
21562index 5b2995f..78e7644 100644
21563--- a/arch/x86/lib/copy_user_64.S
21564+++ b/arch/x86/lib/copy_user_64.S
21565@@ -17,6 +17,7 @@
21566 #include <asm/cpufeature.h>
21567 #include <asm/alternative-asm.h>
21568 #include <asm/asm.h>
21569+#include <asm/pgtable.h>
21570
21571 /*
21572 * By placing feature2 after feature1 in altinstructions section, we logically
21573@@ -30,7 +31,7 @@
21574 .byte 0xe9 /* 32bit jump */
21575 .long \orig-1f /* by default jump to orig */
21576 1:
21577- .section .altinstr_replacement,"ax"
21578+ .section .altinstr_replacement,"a"
21579 2: .byte 0xe9 /* near jump with 32bit immediate */
21580 .long \alt1-1b /* offset */ /* or alternatively to alt1 */
21581 3: .byte 0xe9 /* near jump with 32bit immediate */
21582@@ -69,47 +70,20 @@
21583 #endif
21584 .endm
21585
21586-/* Standard copy_to_user with segment limit checking */
21587-ENTRY(_copy_to_user)
21588- CFI_STARTPROC
21589- GET_THREAD_INFO(%rax)
21590- movq %rdi,%rcx
21591- addq %rdx,%rcx
21592- jc bad_to_user
21593- cmpq TI_addr_limit(%rax),%rcx
21594- ja bad_to_user
21595- ALTERNATIVE_JUMP X86_FEATURE_REP_GOOD,X86_FEATURE_ERMS, \
21596- copy_user_generic_unrolled,copy_user_generic_string, \
21597- copy_user_enhanced_fast_string
21598- CFI_ENDPROC
21599-ENDPROC(_copy_to_user)
21600-
21601-/* Standard copy_from_user with segment limit checking */
21602-ENTRY(_copy_from_user)
21603- CFI_STARTPROC
21604- GET_THREAD_INFO(%rax)
21605- movq %rsi,%rcx
21606- addq %rdx,%rcx
21607- jc bad_from_user
21608- cmpq TI_addr_limit(%rax),%rcx
21609- ja bad_from_user
21610- ALTERNATIVE_JUMP X86_FEATURE_REP_GOOD,X86_FEATURE_ERMS, \
21611- copy_user_generic_unrolled,copy_user_generic_string, \
21612- copy_user_enhanced_fast_string
21613- CFI_ENDPROC
21614-ENDPROC(_copy_from_user)
21615-
21616 .section .fixup,"ax"
21617 /* must zero dest */
21618 ENTRY(bad_from_user)
21619 bad_from_user:
21620 CFI_STARTPROC
21621+ testl %edx,%edx
21622+ js bad_to_user
21623 movl %edx,%ecx
21624 xorl %eax,%eax
21625 rep
21626 stosb
21627 bad_to_user:
21628 movl %edx,%eax
21629+ pax_force_retaddr
21630 ret
21631 CFI_ENDPROC
21632 ENDPROC(bad_from_user)
21633@@ -139,19 +113,19 @@ ENTRY(copy_user_generic_unrolled)
21634 jz 17f
21635 1: movq (%rsi),%r8
21636 2: movq 1*8(%rsi),%r9
21637-3: movq 2*8(%rsi),%r10
21638+3: movq 2*8(%rsi),%rax
21639 4: movq 3*8(%rsi),%r11
21640 5: movq %r8,(%rdi)
21641 6: movq %r9,1*8(%rdi)
21642-7: movq %r10,2*8(%rdi)
21643+7: movq %rax,2*8(%rdi)
21644 8: movq %r11,3*8(%rdi)
21645 9: movq 4*8(%rsi),%r8
21646 10: movq 5*8(%rsi),%r9
21647-11: movq 6*8(%rsi),%r10
21648+11: movq 6*8(%rsi),%rax
21649 12: movq 7*8(%rsi),%r11
21650 13: movq %r8,4*8(%rdi)
21651 14: movq %r9,5*8(%rdi)
21652-15: movq %r10,6*8(%rdi)
21653+15: movq %rax,6*8(%rdi)
21654 16: movq %r11,7*8(%rdi)
21655 leaq 64(%rsi),%rsi
21656 leaq 64(%rdi),%rdi
21657@@ -177,6 +151,7 @@ ENTRY(copy_user_generic_unrolled)
21658 decl %ecx
21659 jnz 21b
21660 23: xor %eax,%eax
21661+ pax_force_retaddr
21662 ret
21663
21664 .section .fixup,"ax"
21665@@ -246,6 +221,7 @@ ENTRY(copy_user_generic_string)
21666 3: rep
21667 movsb
21668 4: xorl %eax,%eax
21669+ pax_force_retaddr
21670 ret
21671
21672 .section .fixup,"ax"
21673@@ -279,6 +255,7 @@ ENTRY(copy_user_enhanced_fast_string)
21674 1: rep
21675 movsb
21676 2: xorl %eax,%eax
21677+ pax_force_retaddr
21678 ret
21679
21680 .section .fixup,"ax"
21681diff --git a/arch/x86/lib/copy_user_nocache_64.S b/arch/x86/lib/copy_user_nocache_64.S
21682index cacddc7..09d49e4 100644
21683--- a/arch/x86/lib/copy_user_nocache_64.S
21684+++ b/arch/x86/lib/copy_user_nocache_64.S
21685@@ -8,6 +8,7 @@
21686
21687 #include <linux/linkage.h>
21688 #include <asm/dwarf2.h>
21689+#include <asm/alternative-asm.h>
21690
21691 #define FIX_ALIGNMENT 1
21692
21693@@ -15,6 +16,7 @@
21694 #include <asm/asm-offsets.h>
21695 #include <asm/thread_info.h>
21696 #include <asm/asm.h>
21697+#include <asm/pgtable.h>
21698
21699 .macro ALIGN_DESTINATION
21700 #ifdef FIX_ALIGNMENT
21701@@ -48,6 +50,15 @@
21702 */
21703 ENTRY(__copy_user_nocache)
21704 CFI_STARTPROC
21705+
21706+#ifdef CONFIG_PAX_MEMORY_UDEREF
21707+ mov $PAX_USER_SHADOW_BASE,%rcx
21708+ cmp %rcx,%rsi
21709+ jae 1f
21710+ add %rcx,%rsi
21711+1:
21712+#endif
21713+
21714 cmpl $8,%edx
21715 jb 20f /* less then 8 bytes, go to byte copy loop */
21716 ALIGN_DESTINATION
21717@@ -57,19 +68,19 @@ ENTRY(__copy_user_nocache)
21718 jz 17f
21719 1: movq (%rsi),%r8
21720 2: movq 1*8(%rsi),%r9
21721-3: movq 2*8(%rsi),%r10
21722+3: movq 2*8(%rsi),%rax
21723 4: movq 3*8(%rsi),%r11
21724 5: movnti %r8,(%rdi)
21725 6: movnti %r9,1*8(%rdi)
21726-7: movnti %r10,2*8(%rdi)
21727+7: movnti %rax,2*8(%rdi)
21728 8: movnti %r11,3*8(%rdi)
21729 9: movq 4*8(%rsi),%r8
21730 10: movq 5*8(%rsi),%r9
21731-11: movq 6*8(%rsi),%r10
21732+11: movq 6*8(%rsi),%rax
21733 12: movq 7*8(%rsi),%r11
21734 13: movnti %r8,4*8(%rdi)
21735 14: movnti %r9,5*8(%rdi)
21736-15: movnti %r10,6*8(%rdi)
21737+15: movnti %rax,6*8(%rdi)
21738 16: movnti %r11,7*8(%rdi)
21739 leaq 64(%rsi),%rsi
21740 leaq 64(%rdi),%rdi
21741@@ -96,6 +107,7 @@ ENTRY(__copy_user_nocache)
21742 jnz 21b
21743 23: xorl %eax,%eax
21744 sfence
21745+ pax_force_retaddr
21746 ret
21747
21748 .section .fixup,"ax"
21749diff --git a/arch/x86/lib/csum-copy_64.S b/arch/x86/lib/csum-copy_64.S
21750index 2419d5f..953ee51 100644
21751--- a/arch/x86/lib/csum-copy_64.S
21752+++ b/arch/x86/lib/csum-copy_64.S
21753@@ -9,6 +9,7 @@
21754 #include <asm/dwarf2.h>
21755 #include <asm/errno.h>
21756 #include <asm/asm.h>
21757+#include <asm/alternative-asm.h>
21758
21759 /*
21760 * Checksum copy with exception handling.
21761@@ -220,6 +221,7 @@ ENTRY(csum_partial_copy_generic)
21762 CFI_RESTORE rbp
21763 addq $7*8, %rsp
21764 CFI_ADJUST_CFA_OFFSET -7*8
21765+ pax_force_retaddr 0, 1
21766 ret
21767 CFI_RESTORE_STATE
21768
21769diff --git a/arch/x86/lib/csum-wrappers_64.c b/arch/x86/lib/csum-wrappers_64.c
21770index 25b7ae8..3b52ccd 100644
21771--- a/arch/x86/lib/csum-wrappers_64.c
21772+++ b/arch/x86/lib/csum-wrappers_64.c
21773@@ -52,7 +52,13 @@ csum_partial_copy_from_user(const void __user *src, void *dst,
21774 len -= 2;
21775 }
21776 }
21777- isum = csum_partial_copy_generic((__force const void *)src,
21778+
21779+#ifdef CONFIG_PAX_MEMORY_UDEREF
21780+ if ((unsigned long)src < PAX_USER_SHADOW_BASE)
21781+ src += PAX_USER_SHADOW_BASE;
21782+#endif
21783+
21784+ isum = csum_partial_copy_generic((const void __force_kernel *)src,
21785 dst, len, isum, errp, NULL);
21786 if (unlikely(*errp))
21787 goto out_err;
21788@@ -105,7 +111,13 @@ csum_partial_copy_to_user(const void *src, void __user *dst,
21789 }
21790
21791 *errp = 0;
21792- return csum_partial_copy_generic(src, (void __force *)dst,
21793+
21794+#ifdef CONFIG_PAX_MEMORY_UDEREF
21795+ if ((unsigned long)dst < PAX_USER_SHADOW_BASE)
21796+ dst += PAX_USER_SHADOW_BASE;
21797+#endif
21798+
21799+ return csum_partial_copy_generic(src, (void __force_kernel *)dst,
21800 len, isum, NULL, errp);
21801 }
21802 EXPORT_SYMBOL(csum_partial_copy_to_user);
21803diff --git a/arch/x86/lib/getuser.S b/arch/x86/lib/getuser.S
21804index b33b1fb..219f389 100644
21805--- a/arch/x86/lib/getuser.S
21806+++ b/arch/x86/lib/getuser.S
21807@@ -33,15 +33,38 @@
21808 #include <asm/asm-offsets.h>
21809 #include <asm/thread_info.h>
21810 #include <asm/asm.h>
21811+#include <asm/segment.h>
21812+#include <asm/pgtable.h>
21813+#include <asm/alternative-asm.h>
21814+
21815+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
21816+#define __copyuser_seg gs;
21817+#else
21818+#define __copyuser_seg
21819+#endif
21820
21821 .text
21822 ENTRY(__get_user_1)
21823 CFI_STARTPROC
21824+
21825+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
21826 GET_THREAD_INFO(%_ASM_DX)
21827 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
21828 jae bad_get_user
21829-1: movzb (%_ASM_AX),%edx
21830+
21831+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
21832+ mov $PAX_USER_SHADOW_BASE,%_ASM_DX
21833+ cmp %_ASM_DX,%_ASM_AX
21834+ jae 1234f
21835+ add %_ASM_DX,%_ASM_AX
21836+1234:
21837+#endif
21838+
21839+#endif
21840+
21841+1: __copyuser_seg movzb (%_ASM_AX),%edx
21842 xor %eax,%eax
21843+ pax_force_retaddr
21844 ret
21845 CFI_ENDPROC
21846 ENDPROC(__get_user_1)
21847@@ -49,12 +72,26 @@ ENDPROC(__get_user_1)
21848 ENTRY(__get_user_2)
21849 CFI_STARTPROC
21850 add $1,%_ASM_AX
21851+
21852+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
21853 jc bad_get_user
21854 GET_THREAD_INFO(%_ASM_DX)
21855 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
21856 jae bad_get_user
21857-2: movzwl -1(%_ASM_AX),%edx
21858+
21859+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
21860+ mov $PAX_USER_SHADOW_BASE,%_ASM_DX
21861+ cmp %_ASM_DX,%_ASM_AX
21862+ jae 1234f
21863+ add %_ASM_DX,%_ASM_AX
21864+1234:
21865+#endif
21866+
21867+#endif
21868+
21869+2: __copyuser_seg movzwl -1(%_ASM_AX),%edx
21870 xor %eax,%eax
21871+ pax_force_retaddr
21872 ret
21873 CFI_ENDPROC
21874 ENDPROC(__get_user_2)
21875@@ -62,12 +99,26 @@ ENDPROC(__get_user_2)
21876 ENTRY(__get_user_4)
21877 CFI_STARTPROC
21878 add $3,%_ASM_AX
21879+
21880+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
21881 jc bad_get_user
21882 GET_THREAD_INFO(%_ASM_DX)
21883 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
21884 jae bad_get_user
21885-3: mov -3(%_ASM_AX),%edx
21886+
21887+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
21888+ mov $PAX_USER_SHADOW_BASE,%_ASM_DX
21889+ cmp %_ASM_DX,%_ASM_AX
21890+ jae 1234f
21891+ add %_ASM_DX,%_ASM_AX
21892+1234:
21893+#endif
21894+
21895+#endif
21896+
21897+3: __copyuser_seg mov -3(%_ASM_AX),%edx
21898 xor %eax,%eax
21899+ pax_force_retaddr
21900 ret
21901 CFI_ENDPROC
21902 ENDPROC(__get_user_4)
21903@@ -80,8 +131,18 @@ ENTRY(__get_user_8)
21904 GET_THREAD_INFO(%_ASM_DX)
21905 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
21906 jae bad_get_user
21907+
21908+#ifdef CONFIG_PAX_MEMORY_UDEREF
21909+ mov $PAX_USER_SHADOW_BASE,%_ASM_DX
21910+ cmp %_ASM_DX,%_ASM_AX
21911+ jae 1234f
21912+ add %_ASM_DX,%_ASM_AX
21913+1234:
21914+#endif
21915+
21916 4: movq -7(%_ASM_AX),%_ASM_DX
21917 xor %eax,%eax
21918+ pax_force_retaddr
21919 ret
21920 CFI_ENDPROC
21921 ENDPROC(__get_user_8)
21922@@ -91,6 +152,7 @@ bad_get_user:
21923 CFI_STARTPROC
21924 xor %edx,%edx
21925 mov $(-EFAULT),%_ASM_AX
21926+ pax_force_retaddr
21927 ret
21928 CFI_ENDPROC
21929 END(bad_get_user)
21930diff --git a/arch/x86/lib/insn.c b/arch/x86/lib/insn.c
21931index b1e6c4b..21ae8fc 100644
21932--- a/arch/x86/lib/insn.c
21933+++ b/arch/x86/lib/insn.c
21934@@ -21,6 +21,11 @@
21935 #include <linux/string.h>
21936 #include <asm/inat.h>
21937 #include <asm/insn.h>
21938+#ifdef __KERNEL__
21939+#include <asm/pgtable_types.h>
21940+#else
21941+#define ktla_ktva(addr) addr
21942+#endif
21943
21944 /* Verify next sizeof(t) bytes can be on the same instruction */
21945 #define validate_next(t, insn, n) \
21946@@ -49,8 +54,8 @@
21947 void insn_init(struct insn *insn, const void *kaddr, int x86_64)
21948 {
21949 memset(insn, 0, sizeof(*insn));
21950- insn->kaddr = kaddr;
21951- insn->next_byte = kaddr;
21952+ insn->kaddr = ktla_ktva(kaddr);
21953+ insn->next_byte = ktla_ktva(kaddr);
21954 insn->x86_64 = x86_64 ? 1 : 0;
21955 insn->opnd_bytes = 4;
21956 if (x86_64)
21957diff --git a/arch/x86/lib/iomap_copy_64.S b/arch/x86/lib/iomap_copy_64.S
21958index 05a95e7..326f2fa 100644
21959--- a/arch/x86/lib/iomap_copy_64.S
21960+++ b/arch/x86/lib/iomap_copy_64.S
21961@@ -17,6 +17,7 @@
21962
21963 #include <linux/linkage.h>
21964 #include <asm/dwarf2.h>
21965+#include <asm/alternative-asm.h>
21966
21967 /*
21968 * override generic version in lib/iomap_copy.c
21969@@ -25,6 +26,7 @@ ENTRY(__iowrite32_copy)
21970 CFI_STARTPROC
21971 movl %edx,%ecx
21972 rep movsd
21973+ pax_force_retaddr
21974 ret
21975 CFI_ENDPROC
21976 ENDPROC(__iowrite32_copy)
21977diff --git a/arch/x86/lib/memcpy_64.S b/arch/x86/lib/memcpy_64.S
21978index 1c273be..da9cc0e 100644
21979--- a/arch/x86/lib/memcpy_64.S
21980+++ b/arch/x86/lib/memcpy_64.S
21981@@ -33,6 +33,7 @@
21982 rep movsq
21983 movl %edx, %ecx
21984 rep movsb
21985+ pax_force_retaddr
21986 ret
21987 .Lmemcpy_e:
21988 .previous
21989@@ -49,6 +50,7 @@
21990 movq %rdi, %rax
21991 movq %rdx, %rcx
21992 rep movsb
21993+ pax_force_retaddr
21994 ret
21995 .Lmemcpy_e_e:
21996 .previous
21997@@ -76,13 +78,13 @@ ENTRY(memcpy)
21998 */
21999 movq 0*8(%rsi), %r8
22000 movq 1*8(%rsi), %r9
22001- movq 2*8(%rsi), %r10
22002+ movq 2*8(%rsi), %rcx
22003 movq 3*8(%rsi), %r11
22004 leaq 4*8(%rsi), %rsi
22005
22006 movq %r8, 0*8(%rdi)
22007 movq %r9, 1*8(%rdi)
22008- movq %r10, 2*8(%rdi)
22009+ movq %rcx, 2*8(%rdi)
22010 movq %r11, 3*8(%rdi)
22011 leaq 4*8(%rdi), %rdi
22012 jae .Lcopy_forward_loop
22013@@ -105,12 +107,12 @@ ENTRY(memcpy)
22014 subq $0x20, %rdx
22015 movq -1*8(%rsi), %r8
22016 movq -2*8(%rsi), %r9
22017- movq -3*8(%rsi), %r10
22018+ movq -3*8(%rsi), %rcx
22019 movq -4*8(%rsi), %r11
22020 leaq -4*8(%rsi), %rsi
22021 movq %r8, -1*8(%rdi)
22022 movq %r9, -2*8(%rdi)
22023- movq %r10, -3*8(%rdi)
22024+ movq %rcx, -3*8(%rdi)
22025 movq %r11, -4*8(%rdi)
22026 leaq -4*8(%rdi), %rdi
22027 jae .Lcopy_backward_loop
22028@@ -130,12 +132,13 @@ ENTRY(memcpy)
22029 */
22030 movq 0*8(%rsi), %r8
22031 movq 1*8(%rsi), %r9
22032- movq -2*8(%rsi, %rdx), %r10
22033+ movq -2*8(%rsi, %rdx), %rcx
22034 movq -1*8(%rsi, %rdx), %r11
22035 movq %r8, 0*8(%rdi)
22036 movq %r9, 1*8(%rdi)
22037- movq %r10, -2*8(%rdi, %rdx)
22038+ movq %rcx, -2*8(%rdi, %rdx)
22039 movq %r11, -1*8(%rdi, %rdx)
22040+ pax_force_retaddr
22041 retq
22042 .p2align 4
22043 .Lless_16bytes:
22044@@ -148,6 +151,7 @@ ENTRY(memcpy)
22045 movq -1*8(%rsi, %rdx), %r9
22046 movq %r8, 0*8(%rdi)
22047 movq %r9, -1*8(%rdi, %rdx)
22048+ pax_force_retaddr
22049 retq
22050 .p2align 4
22051 .Lless_8bytes:
22052@@ -161,6 +165,7 @@ ENTRY(memcpy)
22053 movl -4(%rsi, %rdx), %r8d
22054 movl %ecx, (%rdi)
22055 movl %r8d, -4(%rdi, %rdx)
22056+ pax_force_retaddr
22057 retq
22058 .p2align 4
22059 .Lless_3bytes:
22060@@ -179,6 +184,7 @@ ENTRY(memcpy)
22061 movb %cl, (%rdi)
22062
22063 .Lend:
22064+ pax_force_retaddr
22065 retq
22066 CFI_ENDPROC
22067 ENDPROC(memcpy)
22068diff --git a/arch/x86/lib/memmove_64.S b/arch/x86/lib/memmove_64.S
22069index ee16461..c39c199 100644
22070--- a/arch/x86/lib/memmove_64.S
22071+++ b/arch/x86/lib/memmove_64.S
22072@@ -61,13 +61,13 @@ ENTRY(memmove)
22073 5:
22074 sub $0x20, %rdx
22075 movq 0*8(%rsi), %r11
22076- movq 1*8(%rsi), %r10
22077+ movq 1*8(%rsi), %rcx
22078 movq 2*8(%rsi), %r9
22079 movq 3*8(%rsi), %r8
22080 leaq 4*8(%rsi), %rsi
22081
22082 movq %r11, 0*8(%rdi)
22083- movq %r10, 1*8(%rdi)
22084+ movq %rcx, 1*8(%rdi)
22085 movq %r9, 2*8(%rdi)
22086 movq %r8, 3*8(%rdi)
22087 leaq 4*8(%rdi), %rdi
22088@@ -81,10 +81,10 @@ ENTRY(memmove)
22089 4:
22090 movq %rdx, %rcx
22091 movq -8(%rsi, %rdx), %r11
22092- lea -8(%rdi, %rdx), %r10
22093+ lea -8(%rdi, %rdx), %r9
22094 shrq $3, %rcx
22095 rep movsq
22096- movq %r11, (%r10)
22097+ movq %r11, (%r9)
22098 jmp 13f
22099 .Lmemmove_end_forward:
22100
22101@@ -95,14 +95,14 @@ ENTRY(memmove)
22102 7:
22103 movq %rdx, %rcx
22104 movq (%rsi), %r11
22105- movq %rdi, %r10
22106+ movq %rdi, %r9
22107 leaq -8(%rsi, %rdx), %rsi
22108 leaq -8(%rdi, %rdx), %rdi
22109 shrq $3, %rcx
22110 std
22111 rep movsq
22112 cld
22113- movq %r11, (%r10)
22114+ movq %r11, (%r9)
22115 jmp 13f
22116
22117 /*
22118@@ -127,13 +127,13 @@ ENTRY(memmove)
22119 8:
22120 subq $0x20, %rdx
22121 movq -1*8(%rsi), %r11
22122- movq -2*8(%rsi), %r10
22123+ movq -2*8(%rsi), %rcx
22124 movq -3*8(%rsi), %r9
22125 movq -4*8(%rsi), %r8
22126 leaq -4*8(%rsi), %rsi
22127
22128 movq %r11, -1*8(%rdi)
22129- movq %r10, -2*8(%rdi)
22130+ movq %rcx, -2*8(%rdi)
22131 movq %r9, -3*8(%rdi)
22132 movq %r8, -4*8(%rdi)
22133 leaq -4*8(%rdi), %rdi
22134@@ -151,11 +151,11 @@ ENTRY(memmove)
22135 * Move data from 16 bytes to 31 bytes.
22136 */
22137 movq 0*8(%rsi), %r11
22138- movq 1*8(%rsi), %r10
22139+ movq 1*8(%rsi), %rcx
22140 movq -2*8(%rsi, %rdx), %r9
22141 movq -1*8(%rsi, %rdx), %r8
22142 movq %r11, 0*8(%rdi)
22143- movq %r10, 1*8(%rdi)
22144+ movq %rcx, 1*8(%rdi)
22145 movq %r9, -2*8(%rdi, %rdx)
22146 movq %r8, -1*8(%rdi, %rdx)
22147 jmp 13f
22148@@ -167,9 +167,9 @@ ENTRY(memmove)
22149 * Move data from 8 bytes to 15 bytes.
22150 */
22151 movq 0*8(%rsi), %r11
22152- movq -1*8(%rsi, %rdx), %r10
22153+ movq -1*8(%rsi, %rdx), %r9
22154 movq %r11, 0*8(%rdi)
22155- movq %r10, -1*8(%rdi, %rdx)
22156+ movq %r9, -1*8(%rdi, %rdx)
22157 jmp 13f
22158 10:
22159 cmpq $4, %rdx
22160@@ -178,9 +178,9 @@ ENTRY(memmove)
22161 * Move data from 4 bytes to 7 bytes.
22162 */
22163 movl (%rsi), %r11d
22164- movl -4(%rsi, %rdx), %r10d
22165+ movl -4(%rsi, %rdx), %r9d
22166 movl %r11d, (%rdi)
22167- movl %r10d, -4(%rdi, %rdx)
22168+ movl %r9d, -4(%rdi, %rdx)
22169 jmp 13f
22170 11:
22171 cmp $2, %rdx
22172@@ -189,9 +189,9 @@ ENTRY(memmove)
22173 * Move data from 2 bytes to 3 bytes.
22174 */
22175 movw (%rsi), %r11w
22176- movw -2(%rsi, %rdx), %r10w
22177+ movw -2(%rsi, %rdx), %r9w
22178 movw %r11w, (%rdi)
22179- movw %r10w, -2(%rdi, %rdx)
22180+ movw %r9w, -2(%rdi, %rdx)
22181 jmp 13f
22182 12:
22183 cmp $1, %rdx
22184@@ -202,6 +202,7 @@ ENTRY(memmove)
22185 movb (%rsi), %r11b
22186 movb %r11b, (%rdi)
22187 13:
22188+ pax_force_retaddr
22189 retq
22190 CFI_ENDPROC
22191
22192@@ -210,6 +211,7 @@ ENTRY(memmove)
22193 /* Forward moving data. */
22194 movq %rdx, %rcx
22195 rep movsb
22196+ pax_force_retaddr
22197 retq
22198 .Lmemmove_end_forward_efs:
22199 .previous
22200diff --git a/arch/x86/lib/memset_64.S b/arch/x86/lib/memset_64.S
22201index 2dcb380..963660a 100644
22202--- a/arch/x86/lib/memset_64.S
22203+++ b/arch/x86/lib/memset_64.S
22204@@ -30,6 +30,7 @@
22205 movl %edx,%ecx
22206 rep stosb
22207 movq %r9,%rax
22208+ pax_force_retaddr
22209 ret
22210 .Lmemset_e:
22211 .previous
22212@@ -52,6 +53,7 @@
22213 movq %rdx,%rcx
22214 rep stosb
22215 movq %r9,%rax
22216+ pax_force_retaddr
22217 ret
22218 .Lmemset_e_e:
22219 .previous
22220@@ -59,7 +61,7 @@
22221 ENTRY(memset)
22222 ENTRY(__memset)
22223 CFI_STARTPROC
22224- movq %rdi,%r10
22225+ movq %rdi,%r11
22226
22227 /* expand byte value */
22228 movzbl %sil,%ecx
22229@@ -117,7 +119,8 @@ ENTRY(__memset)
22230 jnz .Lloop_1
22231
22232 .Lende:
22233- movq %r10,%rax
22234+ movq %r11,%rax
22235+ pax_force_retaddr
22236 ret
22237
22238 CFI_RESTORE_STATE
22239diff --git a/arch/x86/lib/mmx_32.c b/arch/x86/lib/mmx_32.c
22240index c9f2d9b..e7fd2c0 100644
22241--- a/arch/x86/lib/mmx_32.c
22242+++ b/arch/x86/lib/mmx_32.c
22243@@ -29,6 +29,7 @@ void *_mmx_memcpy(void *to, const void *from, size_t len)
22244 {
22245 void *p;
22246 int i;
22247+ unsigned long cr0;
22248
22249 if (unlikely(in_interrupt()))
22250 return __memcpy(to, from, len);
22251@@ -39,44 +40,72 @@ void *_mmx_memcpy(void *to, const void *from, size_t len)
22252 kernel_fpu_begin();
22253
22254 __asm__ __volatile__ (
22255- "1: prefetch (%0)\n" /* This set is 28 bytes */
22256- " prefetch 64(%0)\n"
22257- " prefetch 128(%0)\n"
22258- " prefetch 192(%0)\n"
22259- " prefetch 256(%0)\n"
22260+ "1: prefetch (%1)\n" /* This set is 28 bytes */
22261+ " prefetch 64(%1)\n"
22262+ " prefetch 128(%1)\n"
22263+ " prefetch 192(%1)\n"
22264+ " prefetch 256(%1)\n"
22265 "2: \n"
22266 ".section .fixup, \"ax\"\n"
22267- "3: movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
22268+ "3: \n"
22269+
22270+#ifdef CONFIG_PAX_KERNEXEC
22271+ " movl %%cr0, %0\n"
22272+ " movl %0, %%eax\n"
22273+ " andl $0xFFFEFFFF, %%eax\n"
22274+ " movl %%eax, %%cr0\n"
22275+#endif
22276+
22277+ " movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
22278+
22279+#ifdef CONFIG_PAX_KERNEXEC
22280+ " movl %0, %%cr0\n"
22281+#endif
22282+
22283 " jmp 2b\n"
22284 ".previous\n"
22285 _ASM_EXTABLE(1b, 3b)
22286- : : "r" (from));
22287+ : "=&r" (cr0) : "r" (from) : "ax");
22288
22289 for ( ; i > 5; i--) {
22290 __asm__ __volatile__ (
22291- "1: prefetch 320(%0)\n"
22292- "2: movq (%0), %%mm0\n"
22293- " movq 8(%0), %%mm1\n"
22294- " movq 16(%0), %%mm2\n"
22295- " movq 24(%0), %%mm3\n"
22296- " movq %%mm0, (%1)\n"
22297- " movq %%mm1, 8(%1)\n"
22298- " movq %%mm2, 16(%1)\n"
22299- " movq %%mm3, 24(%1)\n"
22300- " movq 32(%0), %%mm0\n"
22301- " movq 40(%0), %%mm1\n"
22302- " movq 48(%0), %%mm2\n"
22303- " movq 56(%0), %%mm3\n"
22304- " movq %%mm0, 32(%1)\n"
22305- " movq %%mm1, 40(%1)\n"
22306- " movq %%mm2, 48(%1)\n"
22307- " movq %%mm3, 56(%1)\n"
22308+ "1: prefetch 320(%1)\n"
22309+ "2: movq (%1), %%mm0\n"
22310+ " movq 8(%1), %%mm1\n"
22311+ " movq 16(%1), %%mm2\n"
22312+ " movq 24(%1), %%mm3\n"
22313+ " movq %%mm0, (%2)\n"
22314+ " movq %%mm1, 8(%2)\n"
22315+ " movq %%mm2, 16(%2)\n"
22316+ " movq %%mm3, 24(%2)\n"
22317+ " movq 32(%1), %%mm0\n"
22318+ " movq 40(%1), %%mm1\n"
22319+ " movq 48(%1), %%mm2\n"
22320+ " movq 56(%1), %%mm3\n"
22321+ " movq %%mm0, 32(%2)\n"
22322+ " movq %%mm1, 40(%2)\n"
22323+ " movq %%mm2, 48(%2)\n"
22324+ " movq %%mm3, 56(%2)\n"
22325 ".section .fixup, \"ax\"\n"
22326- "3: movw $0x05EB, 1b\n" /* jmp on 5 bytes */
22327+ "3:\n"
22328+
22329+#ifdef CONFIG_PAX_KERNEXEC
22330+ " movl %%cr0, %0\n"
22331+ " movl %0, %%eax\n"
22332+ " andl $0xFFFEFFFF, %%eax\n"
22333+ " movl %%eax, %%cr0\n"
22334+#endif
22335+
22336+ " movw $0x05EB, 1b\n" /* jmp on 5 bytes */
22337+
22338+#ifdef CONFIG_PAX_KERNEXEC
22339+ " movl %0, %%cr0\n"
22340+#endif
22341+
22342 " jmp 2b\n"
22343 ".previous\n"
22344 _ASM_EXTABLE(1b, 3b)
22345- : : "r" (from), "r" (to) : "memory");
22346+ : "=&r" (cr0) : "r" (from), "r" (to) : "memory", "ax");
22347
22348 from += 64;
22349 to += 64;
22350@@ -158,6 +187,7 @@ static void fast_clear_page(void *page)
22351 static void fast_copy_page(void *to, void *from)
22352 {
22353 int i;
22354+ unsigned long cr0;
22355
22356 kernel_fpu_begin();
22357
22358@@ -166,42 +196,70 @@ static void fast_copy_page(void *to, void *from)
22359 * but that is for later. -AV
22360 */
22361 __asm__ __volatile__(
22362- "1: prefetch (%0)\n"
22363- " prefetch 64(%0)\n"
22364- " prefetch 128(%0)\n"
22365- " prefetch 192(%0)\n"
22366- " prefetch 256(%0)\n"
22367+ "1: prefetch (%1)\n"
22368+ " prefetch 64(%1)\n"
22369+ " prefetch 128(%1)\n"
22370+ " prefetch 192(%1)\n"
22371+ " prefetch 256(%1)\n"
22372 "2: \n"
22373 ".section .fixup, \"ax\"\n"
22374- "3: movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
22375+ "3: \n"
22376+
22377+#ifdef CONFIG_PAX_KERNEXEC
22378+ " movl %%cr0, %0\n"
22379+ " movl %0, %%eax\n"
22380+ " andl $0xFFFEFFFF, %%eax\n"
22381+ " movl %%eax, %%cr0\n"
22382+#endif
22383+
22384+ " movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
22385+
22386+#ifdef CONFIG_PAX_KERNEXEC
22387+ " movl %0, %%cr0\n"
22388+#endif
22389+
22390 " jmp 2b\n"
22391 ".previous\n"
22392- _ASM_EXTABLE(1b, 3b) : : "r" (from));
22393+ _ASM_EXTABLE(1b, 3b) : "=&r" (cr0) : "r" (from) : "ax");
22394
22395 for (i = 0; i < (4096-320)/64; i++) {
22396 __asm__ __volatile__ (
22397- "1: prefetch 320(%0)\n"
22398- "2: movq (%0), %%mm0\n"
22399- " movntq %%mm0, (%1)\n"
22400- " movq 8(%0), %%mm1\n"
22401- " movntq %%mm1, 8(%1)\n"
22402- " movq 16(%0), %%mm2\n"
22403- " movntq %%mm2, 16(%1)\n"
22404- " movq 24(%0), %%mm3\n"
22405- " movntq %%mm3, 24(%1)\n"
22406- " movq 32(%0), %%mm4\n"
22407- " movntq %%mm4, 32(%1)\n"
22408- " movq 40(%0), %%mm5\n"
22409- " movntq %%mm5, 40(%1)\n"
22410- " movq 48(%0), %%mm6\n"
22411- " movntq %%mm6, 48(%1)\n"
22412- " movq 56(%0), %%mm7\n"
22413- " movntq %%mm7, 56(%1)\n"
22414+ "1: prefetch 320(%1)\n"
22415+ "2: movq (%1), %%mm0\n"
22416+ " movntq %%mm0, (%2)\n"
22417+ " movq 8(%1), %%mm1\n"
22418+ " movntq %%mm1, 8(%2)\n"
22419+ " movq 16(%1), %%mm2\n"
22420+ " movntq %%mm2, 16(%2)\n"
22421+ " movq 24(%1), %%mm3\n"
22422+ " movntq %%mm3, 24(%2)\n"
22423+ " movq 32(%1), %%mm4\n"
22424+ " movntq %%mm4, 32(%2)\n"
22425+ " movq 40(%1), %%mm5\n"
22426+ " movntq %%mm5, 40(%2)\n"
22427+ " movq 48(%1), %%mm6\n"
22428+ " movntq %%mm6, 48(%2)\n"
22429+ " movq 56(%1), %%mm7\n"
22430+ " movntq %%mm7, 56(%2)\n"
22431 ".section .fixup, \"ax\"\n"
22432- "3: movw $0x05EB, 1b\n" /* jmp on 5 bytes */
22433+ "3:\n"
22434+
22435+#ifdef CONFIG_PAX_KERNEXEC
22436+ " movl %%cr0, %0\n"
22437+ " movl %0, %%eax\n"
22438+ " andl $0xFFFEFFFF, %%eax\n"
22439+ " movl %%eax, %%cr0\n"
22440+#endif
22441+
22442+ " movw $0x05EB, 1b\n" /* jmp on 5 bytes */
22443+
22444+#ifdef CONFIG_PAX_KERNEXEC
22445+ " movl %0, %%cr0\n"
22446+#endif
22447+
22448 " jmp 2b\n"
22449 ".previous\n"
22450- _ASM_EXTABLE(1b, 3b) : : "r" (from), "r" (to) : "memory");
22451+ _ASM_EXTABLE(1b, 3b) : "=&r" (cr0) : "r" (from), "r" (to) : "memory", "ax");
22452
22453 from += 64;
22454 to += 64;
22455@@ -280,47 +338,76 @@ static void fast_clear_page(void *page)
22456 static void fast_copy_page(void *to, void *from)
22457 {
22458 int i;
22459+ unsigned long cr0;
22460
22461 kernel_fpu_begin();
22462
22463 __asm__ __volatile__ (
22464- "1: prefetch (%0)\n"
22465- " prefetch 64(%0)\n"
22466- " prefetch 128(%0)\n"
22467- " prefetch 192(%0)\n"
22468- " prefetch 256(%0)\n"
22469+ "1: prefetch (%1)\n"
22470+ " prefetch 64(%1)\n"
22471+ " prefetch 128(%1)\n"
22472+ " prefetch 192(%1)\n"
22473+ " prefetch 256(%1)\n"
22474 "2: \n"
22475 ".section .fixup, \"ax\"\n"
22476- "3: movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
22477+ "3: \n"
22478+
22479+#ifdef CONFIG_PAX_KERNEXEC
22480+ " movl %%cr0, %0\n"
22481+ " movl %0, %%eax\n"
22482+ " andl $0xFFFEFFFF, %%eax\n"
22483+ " movl %%eax, %%cr0\n"
22484+#endif
22485+
22486+ " movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
22487+
22488+#ifdef CONFIG_PAX_KERNEXEC
22489+ " movl %0, %%cr0\n"
22490+#endif
22491+
22492 " jmp 2b\n"
22493 ".previous\n"
22494- _ASM_EXTABLE(1b, 3b) : : "r" (from));
22495+ _ASM_EXTABLE(1b, 3b) : "=&r" (cr0) : "r" (from) : "ax");
22496
22497 for (i = 0; i < 4096/64; i++) {
22498 __asm__ __volatile__ (
22499- "1: prefetch 320(%0)\n"
22500- "2: movq (%0), %%mm0\n"
22501- " movq 8(%0), %%mm1\n"
22502- " movq 16(%0), %%mm2\n"
22503- " movq 24(%0), %%mm3\n"
22504- " movq %%mm0, (%1)\n"
22505- " movq %%mm1, 8(%1)\n"
22506- " movq %%mm2, 16(%1)\n"
22507- " movq %%mm3, 24(%1)\n"
22508- " movq 32(%0), %%mm0\n"
22509- " movq 40(%0), %%mm1\n"
22510- " movq 48(%0), %%mm2\n"
22511- " movq 56(%0), %%mm3\n"
22512- " movq %%mm0, 32(%1)\n"
22513- " movq %%mm1, 40(%1)\n"
22514- " movq %%mm2, 48(%1)\n"
22515- " movq %%mm3, 56(%1)\n"
22516+ "1: prefetch 320(%1)\n"
22517+ "2: movq (%1), %%mm0\n"
22518+ " movq 8(%1), %%mm1\n"
22519+ " movq 16(%1), %%mm2\n"
22520+ " movq 24(%1), %%mm3\n"
22521+ " movq %%mm0, (%2)\n"
22522+ " movq %%mm1, 8(%2)\n"
22523+ " movq %%mm2, 16(%2)\n"
22524+ " movq %%mm3, 24(%2)\n"
22525+ " movq 32(%1), %%mm0\n"
22526+ " movq 40(%1), %%mm1\n"
22527+ " movq 48(%1), %%mm2\n"
22528+ " movq 56(%1), %%mm3\n"
22529+ " movq %%mm0, 32(%2)\n"
22530+ " movq %%mm1, 40(%2)\n"
22531+ " movq %%mm2, 48(%2)\n"
22532+ " movq %%mm3, 56(%2)\n"
22533 ".section .fixup, \"ax\"\n"
22534- "3: movw $0x05EB, 1b\n" /* jmp on 5 bytes */
22535+ "3:\n"
22536+
22537+#ifdef CONFIG_PAX_KERNEXEC
22538+ " movl %%cr0, %0\n"
22539+ " movl %0, %%eax\n"
22540+ " andl $0xFFFEFFFF, %%eax\n"
22541+ " movl %%eax, %%cr0\n"
22542+#endif
22543+
22544+ " movw $0x05EB, 1b\n" /* jmp on 5 bytes */
22545+
22546+#ifdef CONFIG_PAX_KERNEXEC
22547+ " movl %0, %%cr0\n"
22548+#endif
22549+
22550 " jmp 2b\n"
22551 ".previous\n"
22552 _ASM_EXTABLE(1b, 3b)
22553- : : "r" (from), "r" (to) : "memory");
22554+ : "=&r" (cr0) : "r" (from), "r" (to) : "memory", "ax");
22555
22556 from += 64;
22557 to += 64;
22558diff --git a/arch/x86/lib/msr-reg.S b/arch/x86/lib/msr-reg.S
22559index f6d13ee..aca5f0b 100644
22560--- a/arch/x86/lib/msr-reg.S
22561+++ b/arch/x86/lib/msr-reg.S
22562@@ -3,6 +3,7 @@
22563 #include <asm/dwarf2.h>
22564 #include <asm/asm.h>
22565 #include <asm/msr.h>
22566+#include <asm/alternative-asm.h>
22567
22568 #ifdef CONFIG_X86_64
22569 /*
22570@@ -16,7 +17,7 @@ ENTRY(\op\()_safe_regs)
22571 CFI_STARTPROC
22572 pushq_cfi %rbx
22573 pushq_cfi %rbp
22574- movq %rdi, %r10 /* Save pointer */
22575+ movq %rdi, %r9 /* Save pointer */
22576 xorl %r11d, %r11d /* Return value */
22577 movl (%rdi), %eax
22578 movl 4(%rdi), %ecx
22579@@ -27,16 +28,17 @@ ENTRY(\op\()_safe_regs)
22580 movl 28(%rdi), %edi
22581 CFI_REMEMBER_STATE
22582 1: \op
22583-2: movl %eax, (%r10)
22584+2: movl %eax, (%r9)
22585 movl %r11d, %eax /* Return value */
22586- movl %ecx, 4(%r10)
22587- movl %edx, 8(%r10)
22588- movl %ebx, 12(%r10)
22589- movl %ebp, 20(%r10)
22590- movl %esi, 24(%r10)
22591- movl %edi, 28(%r10)
22592+ movl %ecx, 4(%r9)
22593+ movl %edx, 8(%r9)
22594+ movl %ebx, 12(%r9)
22595+ movl %ebp, 20(%r9)
22596+ movl %esi, 24(%r9)
22597+ movl %edi, 28(%r9)
22598 popq_cfi %rbp
22599 popq_cfi %rbx
22600+ pax_force_retaddr
22601 ret
22602 3:
22603 CFI_RESTORE_STATE
22604diff --git a/arch/x86/lib/putuser.S b/arch/x86/lib/putuser.S
22605index 7f951c8..ebd573a 100644
22606--- a/arch/x86/lib/putuser.S
22607+++ b/arch/x86/lib/putuser.S
22608@@ -15,7 +15,9 @@
22609 #include <asm/thread_info.h>
22610 #include <asm/errno.h>
22611 #include <asm/asm.h>
22612-
22613+#include <asm/segment.h>
22614+#include <asm/pgtable.h>
22615+#include <asm/alternative-asm.h>
22616
22617 /*
22618 * __put_user_X
22619@@ -29,52 +31,119 @@
22620 * as they get called from within inline assembly.
22621 */
22622
22623-#define ENTER CFI_STARTPROC ; \
22624- GET_THREAD_INFO(%_ASM_BX)
22625-#define EXIT ret ; \
22626+#define ENTER CFI_STARTPROC
22627+#define EXIT pax_force_retaddr; ret ; \
22628 CFI_ENDPROC
22629
22630+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
22631+#define _DEST %_ASM_CX,%_ASM_BX
22632+#else
22633+#define _DEST %_ASM_CX
22634+#endif
22635+
22636+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
22637+#define __copyuser_seg gs;
22638+#else
22639+#define __copyuser_seg
22640+#endif
22641+
22642 .text
22643 ENTRY(__put_user_1)
22644 ENTER
22645+
22646+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
22647+ GET_THREAD_INFO(%_ASM_BX)
22648 cmp TI_addr_limit(%_ASM_BX),%_ASM_CX
22649 jae bad_put_user
22650-1: movb %al,(%_ASM_CX)
22651+
22652+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
22653+ mov $PAX_USER_SHADOW_BASE,%_ASM_BX
22654+ cmp %_ASM_BX,%_ASM_CX
22655+ jb 1234f
22656+ xor %ebx,%ebx
22657+1234:
22658+#endif
22659+
22660+#endif
22661+
22662+1: __copyuser_seg movb %al,(_DEST)
22663 xor %eax,%eax
22664 EXIT
22665 ENDPROC(__put_user_1)
22666
22667 ENTRY(__put_user_2)
22668 ENTER
22669+
22670+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
22671+ GET_THREAD_INFO(%_ASM_BX)
22672 mov TI_addr_limit(%_ASM_BX),%_ASM_BX
22673 sub $1,%_ASM_BX
22674 cmp %_ASM_BX,%_ASM_CX
22675 jae bad_put_user
22676-2: movw %ax,(%_ASM_CX)
22677+
22678+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
22679+ mov $PAX_USER_SHADOW_BASE,%_ASM_BX
22680+ cmp %_ASM_BX,%_ASM_CX
22681+ jb 1234f
22682+ xor %ebx,%ebx
22683+1234:
22684+#endif
22685+
22686+#endif
22687+
22688+2: __copyuser_seg movw %ax,(_DEST)
22689 xor %eax,%eax
22690 EXIT
22691 ENDPROC(__put_user_2)
22692
22693 ENTRY(__put_user_4)
22694 ENTER
22695+
22696+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
22697+ GET_THREAD_INFO(%_ASM_BX)
22698 mov TI_addr_limit(%_ASM_BX),%_ASM_BX
22699 sub $3,%_ASM_BX
22700 cmp %_ASM_BX,%_ASM_CX
22701 jae bad_put_user
22702-3: movl %eax,(%_ASM_CX)
22703+
22704+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
22705+ mov $PAX_USER_SHADOW_BASE,%_ASM_BX
22706+ cmp %_ASM_BX,%_ASM_CX
22707+ jb 1234f
22708+ xor %ebx,%ebx
22709+1234:
22710+#endif
22711+
22712+#endif
22713+
22714+3: __copyuser_seg movl %eax,(_DEST)
22715 xor %eax,%eax
22716 EXIT
22717 ENDPROC(__put_user_4)
22718
22719 ENTRY(__put_user_8)
22720 ENTER
22721+
22722+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
22723+ GET_THREAD_INFO(%_ASM_BX)
22724 mov TI_addr_limit(%_ASM_BX),%_ASM_BX
22725 sub $7,%_ASM_BX
22726 cmp %_ASM_BX,%_ASM_CX
22727 jae bad_put_user
22728-4: mov %_ASM_AX,(%_ASM_CX)
22729+
22730+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
22731+ mov $PAX_USER_SHADOW_BASE,%_ASM_BX
22732+ cmp %_ASM_BX,%_ASM_CX
22733+ jb 1234f
22734+ xor %ebx,%ebx
22735+1234:
22736+#endif
22737+
22738+#endif
22739+
22740+4: __copyuser_seg mov %_ASM_AX,(_DEST)
22741 #ifdef CONFIG_X86_32
22742-5: movl %edx,4(%_ASM_CX)
22743+5: __copyuser_seg movl %edx,4(_DEST)
22744 #endif
22745 xor %eax,%eax
22746 EXIT
22747diff --git a/arch/x86/lib/rwlock.S b/arch/x86/lib/rwlock.S
22748index 1cad221..de671ee 100644
22749--- a/arch/x86/lib/rwlock.S
22750+++ b/arch/x86/lib/rwlock.S
22751@@ -16,13 +16,34 @@ ENTRY(__write_lock_failed)
22752 FRAME
22753 0: LOCK_PREFIX
22754 WRITE_LOCK_ADD($RW_LOCK_BIAS) (%__lock_ptr)
22755+
22756+#ifdef CONFIG_PAX_REFCOUNT
22757+ jno 1234f
22758+ LOCK_PREFIX
22759+ WRITE_LOCK_SUB($RW_LOCK_BIAS) (%__lock_ptr)
22760+ int $4
22761+1234:
22762+ _ASM_EXTABLE(1234b, 1234b)
22763+#endif
22764+
22765 1: rep; nop
22766 cmpl $WRITE_LOCK_CMP, (%__lock_ptr)
22767 jne 1b
22768 LOCK_PREFIX
22769 WRITE_LOCK_SUB($RW_LOCK_BIAS) (%__lock_ptr)
22770+
22771+#ifdef CONFIG_PAX_REFCOUNT
22772+ jno 1234f
22773+ LOCK_PREFIX
22774+ WRITE_LOCK_ADD($RW_LOCK_BIAS) (%__lock_ptr)
22775+ int $4
22776+1234:
22777+ _ASM_EXTABLE(1234b, 1234b)
22778+#endif
22779+
22780 jnz 0b
22781 ENDFRAME
22782+ pax_force_retaddr
22783 ret
22784 CFI_ENDPROC
22785 END(__write_lock_failed)
22786@@ -32,13 +53,34 @@ ENTRY(__read_lock_failed)
22787 FRAME
22788 0: LOCK_PREFIX
22789 READ_LOCK_SIZE(inc) (%__lock_ptr)
22790+
22791+#ifdef CONFIG_PAX_REFCOUNT
22792+ jno 1234f
22793+ LOCK_PREFIX
22794+ READ_LOCK_SIZE(dec) (%__lock_ptr)
22795+ int $4
22796+1234:
22797+ _ASM_EXTABLE(1234b, 1234b)
22798+#endif
22799+
22800 1: rep; nop
22801 READ_LOCK_SIZE(cmp) $1, (%__lock_ptr)
22802 js 1b
22803 LOCK_PREFIX
22804 READ_LOCK_SIZE(dec) (%__lock_ptr)
22805+
22806+#ifdef CONFIG_PAX_REFCOUNT
22807+ jno 1234f
22808+ LOCK_PREFIX
22809+ READ_LOCK_SIZE(inc) (%__lock_ptr)
22810+ int $4
22811+1234:
22812+ _ASM_EXTABLE(1234b, 1234b)
22813+#endif
22814+
22815 js 0b
22816 ENDFRAME
22817+ pax_force_retaddr
22818 ret
22819 CFI_ENDPROC
22820 END(__read_lock_failed)
22821diff --git a/arch/x86/lib/rwsem.S b/arch/x86/lib/rwsem.S
22822index 5dff5f0..cadebf4 100644
22823--- a/arch/x86/lib/rwsem.S
22824+++ b/arch/x86/lib/rwsem.S
22825@@ -94,6 +94,7 @@ ENTRY(call_rwsem_down_read_failed)
22826 __ASM_SIZE(pop,_cfi) %__ASM_REG(dx)
22827 CFI_RESTORE __ASM_REG(dx)
22828 restore_common_regs
22829+ pax_force_retaddr
22830 ret
22831 CFI_ENDPROC
22832 ENDPROC(call_rwsem_down_read_failed)
22833@@ -104,6 +105,7 @@ ENTRY(call_rwsem_down_write_failed)
22834 movq %rax,%rdi
22835 call rwsem_down_write_failed
22836 restore_common_regs
22837+ pax_force_retaddr
22838 ret
22839 CFI_ENDPROC
22840 ENDPROC(call_rwsem_down_write_failed)
22841@@ -117,7 +119,8 @@ ENTRY(call_rwsem_wake)
22842 movq %rax,%rdi
22843 call rwsem_wake
22844 restore_common_regs
22845-1: ret
22846+1: pax_force_retaddr
22847+ ret
22848 CFI_ENDPROC
22849 ENDPROC(call_rwsem_wake)
22850
22851@@ -131,6 +134,7 @@ ENTRY(call_rwsem_downgrade_wake)
22852 __ASM_SIZE(pop,_cfi) %__ASM_REG(dx)
22853 CFI_RESTORE __ASM_REG(dx)
22854 restore_common_regs
22855+ pax_force_retaddr
22856 ret
22857 CFI_ENDPROC
22858 ENDPROC(call_rwsem_downgrade_wake)
22859diff --git a/arch/x86/lib/thunk_64.S b/arch/x86/lib/thunk_64.S
22860index a63efd6..ccecad8 100644
22861--- a/arch/x86/lib/thunk_64.S
22862+++ b/arch/x86/lib/thunk_64.S
22863@@ -8,6 +8,7 @@
22864 #include <linux/linkage.h>
22865 #include <asm/dwarf2.h>
22866 #include <asm/calling.h>
22867+#include <asm/alternative-asm.h>
22868
22869 /* rdi: arg1 ... normal C conventions. rax is saved/restored. */
22870 .macro THUNK name, func, put_ret_addr_in_rdi=0
22871@@ -41,5 +42,6 @@
22872 SAVE_ARGS
22873 restore:
22874 RESTORE_ARGS
22875+ pax_force_retaddr
22876 ret
22877 CFI_ENDPROC
22878diff --git a/arch/x86/lib/usercopy_32.c b/arch/x86/lib/usercopy_32.c
22879index 1781b2f..90368dd 100644
22880--- a/arch/x86/lib/usercopy_32.c
22881+++ b/arch/x86/lib/usercopy_32.c
22882@@ -42,10 +42,12 @@ do { \
22883 int __d0; \
22884 might_fault(); \
22885 __asm__ __volatile__( \
22886+ __COPYUSER_SET_ES \
22887 "0: rep; stosl\n" \
22888 " movl %2,%0\n" \
22889 "1: rep; stosb\n" \
22890 "2:\n" \
22891+ __COPYUSER_RESTORE_ES \
22892 ".section .fixup,\"ax\"\n" \
22893 "3: lea 0(%2,%0,4),%0\n" \
22894 " jmp 2b\n" \
22895@@ -97,7 +99,7 @@ EXPORT_SYMBOL(__clear_user);
22896
22897 #ifdef CONFIG_X86_INTEL_USERCOPY
22898 static unsigned long
22899-__copy_user_intel(void __user *to, const void *from, unsigned long size)
22900+__generic_copy_to_user_intel(void __user *to, const void *from, unsigned long size)
22901 {
22902 int d0, d1;
22903 __asm__ __volatile__(
22904@@ -109,36 +111,36 @@ __copy_user_intel(void __user *to, const void *from, unsigned long size)
22905 " .align 2,0x90\n"
22906 "3: movl 0(%4), %%eax\n"
22907 "4: movl 4(%4), %%edx\n"
22908- "5: movl %%eax, 0(%3)\n"
22909- "6: movl %%edx, 4(%3)\n"
22910+ "5: "__copyuser_seg" movl %%eax, 0(%3)\n"
22911+ "6: "__copyuser_seg" movl %%edx, 4(%3)\n"
22912 "7: movl 8(%4), %%eax\n"
22913 "8: movl 12(%4),%%edx\n"
22914- "9: movl %%eax, 8(%3)\n"
22915- "10: movl %%edx, 12(%3)\n"
22916+ "9: "__copyuser_seg" movl %%eax, 8(%3)\n"
22917+ "10: "__copyuser_seg" movl %%edx, 12(%3)\n"
22918 "11: movl 16(%4), %%eax\n"
22919 "12: movl 20(%4), %%edx\n"
22920- "13: movl %%eax, 16(%3)\n"
22921- "14: movl %%edx, 20(%3)\n"
22922+ "13: "__copyuser_seg" movl %%eax, 16(%3)\n"
22923+ "14: "__copyuser_seg" movl %%edx, 20(%3)\n"
22924 "15: movl 24(%4), %%eax\n"
22925 "16: movl 28(%4), %%edx\n"
22926- "17: movl %%eax, 24(%3)\n"
22927- "18: movl %%edx, 28(%3)\n"
22928+ "17: "__copyuser_seg" movl %%eax, 24(%3)\n"
22929+ "18: "__copyuser_seg" movl %%edx, 28(%3)\n"
22930 "19: movl 32(%4), %%eax\n"
22931 "20: movl 36(%4), %%edx\n"
22932- "21: movl %%eax, 32(%3)\n"
22933- "22: movl %%edx, 36(%3)\n"
22934+ "21: "__copyuser_seg" movl %%eax, 32(%3)\n"
22935+ "22: "__copyuser_seg" movl %%edx, 36(%3)\n"
22936 "23: movl 40(%4), %%eax\n"
22937 "24: movl 44(%4), %%edx\n"
22938- "25: movl %%eax, 40(%3)\n"
22939- "26: movl %%edx, 44(%3)\n"
22940+ "25: "__copyuser_seg" movl %%eax, 40(%3)\n"
22941+ "26: "__copyuser_seg" movl %%edx, 44(%3)\n"
22942 "27: movl 48(%4), %%eax\n"
22943 "28: movl 52(%4), %%edx\n"
22944- "29: movl %%eax, 48(%3)\n"
22945- "30: movl %%edx, 52(%3)\n"
22946+ "29: "__copyuser_seg" movl %%eax, 48(%3)\n"
22947+ "30: "__copyuser_seg" movl %%edx, 52(%3)\n"
22948 "31: movl 56(%4), %%eax\n"
22949 "32: movl 60(%4), %%edx\n"
22950- "33: movl %%eax, 56(%3)\n"
22951- "34: movl %%edx, 60(%3)\n"
22952+ "33: "__copyuser_seg" movl %%eax, 56(%3)\n"
22953+ "34: "__copyuser_seg" movl %%edx, 60(%3)\n"
22954 " addl $-64, %0\n"
22955 " addl $64, %4\n"
22956 " addl $64, %3\n"
22957@@ -148,10 +150,12 @@ __copy_user_intel(void __user *to, const void *from, unsigned long size)
22958 " shrl $2, %0\n"
22959 " andl $3, %%eax\n"
22960 " cld\n"
22961+ __COPYUSER_SET_ES
22962 "99: rep; movsl\n"
22963 "36: movl %%eax, %0\n"
22964 "37: rep; movsb\n"
22965 "100:\n"
22966+ __COPYUSER_RESTORE_ES
22967 ".section .fixup,\"ax\"\n"
22968 "101: lea 0(%%eax,%0,4),%0\n"
22969 " jmp 100b\n"
22970@@ -201,46 +205,150 @@ __copy_user_intel(void __user *to, const void *from, unsigned long size)
22971 }
22972
22973 static unsigned long
22974+__generic_copy_from_user_intel(void *to, const void __user *from, unsigned long size)
22975+{
22976+ int d0, d1;
22977+ __asm__ __volatile__(
22978+ " .align 2,0x90\n"
22979+ "1: "__copyuser_seg" movl 32(%4), %%eax\n"
22980+ " cmpl $67, %0\n"
22981+ " jbe 3f\n"
22982+ "2: "__copyuser_seg" movl 64(%4), %%eax\n"
22983+ " .align 2,0x90\n"
22984+ "3: "__copyuser_seg" movl 0(%4), %%eax\n"
22985+ "4: "__copyuser_seg" movl 4(%4), %%edx\n"
22986+ "5: movl %%eax, 0(%3)\n"
22987+ "6: movl %%edx, 4(%3)\n"
22988+ "7: "__copyuser_seg" movl 8(%4), %%eax\n"
22989+ "8: "__copyuser_seg" movl 12(%4),%%edx\n"
22990+ "9: movl %%eax, 8(%3)\n"
22991+ "10: movl %%edx, 12(%3)\n"
22992+ "11: "__copyuser_seg" movl 16(%4), %%eax\n"
22993+ "12: "__copyuser_seg" movl 20(%4), %%edx\n"
22994+ "13: movl %%eax, 16(%3)\n"
22995+ "14: movl %%edx, 20(%3)\n"
22996+ "15: "__copyuser_seg" movl 24(%4), %%eax\n"
22997+ "16: "__copyuser_seg" movl 28(%4), %%edx\n"
22998+ "17: movl %%eax, 24(%3)\n"
22999+ "18: movl %%edx, 28(%3)\n"
23000+ "19: "__copyuser_seg" movl 32(%4), %%eax\n"
23001+ "20: "__copyuser_seg" movl 36(%4), %%edx\n"
23002+ "21: movl %%eax, 32(%3)\n"
23003+ "22: movl %%edx, 36(%3)\n"
23004+ "23: "__copyuser_seg" movl 40(%4), %%eax\n"
23005+ "24: "__copyuser_seg" movl 44(%4), %%edx\n"
23006+ "25: movl %%eax, 40(%3)\n"
23007+ "26: movl %%edx, 44(%3)\n"
23008+ "27: "__copyuser_seg" movl 48(%4), %%eax\n"
23009+ "28: "__copyuser_seg" movl 52(%4), %%edx\n"
23010+ "29: movl %%eax, 48(%3)\n"
23011+ "30: movl %%edx, 52(%3)\n"
23012+ "31: "__copyuser_seg" movl 56(%4), %%eax\n"
23013+ "32: "__copyuser_seg" movl 60(%4), %%edx\n"
23014+ "33: movl %%eax, 56(%3)\n"
23015+ "34: movl %%edx, 60(%3)\n"
23016+ " addl $-64, %0\n"
23017+ " addl $64, %4\n"
23018+ " addl $64, %3\n"
23019+ " cmpl $63, %0\n"
23020+ " ja 1b\n"
23021+ "35: movl %0, %%eax\n"
23022+ " shrl $2, %0\n"
23023+ " andl $3, %%eax\n"
23024+ " cld\n"
23025+ "99: rep; "__copyuser_seg" movsl\n"
23026+ "36: movl %%eax, %0\n"
23027+ "37: rep; "__copyuser_seg" movsb\n"
23028+ "100:\n"
23029+ ".section .fixup,\"ax\"\n"
23030+ "101: lea 0(%%eax,%0,4),%0\n"
23031+ " jmp 100b\n"
23032+ ".previous\n"
23033+ _ASM_EXTABLE(1b,100b)
23034+ _ASM_EXTABLE(2b,100b)
23035+ _ASM_EXTABLE(3b,100b)
23036+ _ASM_EXTABLE(4b,100b)
23037+ _ASM_EXTABLE(5b,100b)
23038+ _ASM_EXTABLE(6b,100b)
23039+ _ASM_EXTABLE(7b,100b)
23040+ _ASM_EXTABLE(8b,100b)
23041+ _ASM_EXTABLE(9b,100b)
23042+ _ASM_EXTABLE(10b,100b)
23043+ _ASM_EXTABLE(11b,100b)
23044+ _ASM_EXTABLE(12b,100b)
23045+ _ASM_EXTABLE(13b,100b)
23046+ _ASM_EXTABLE(14b,100b)
23047+ _ASM_EXTABLE(15b,100b)
23048+ _ASM_EXTABLE(16b,100b)
23049+ _ASM_EXTABLE(17b,100b)
23050+ _ASM_EXTABLE(18b,100b)
23051+ _ASM_EXTABLE(19b,100b)
23052+ _ASM_EXTABLE(20b,100b)
23053+ _ASM_EXTABLE(21b,100b)
23054+ _ASM_EXTABLE(22b,100b)
23055+ _ASM_EXTABLE(23b,100b)
23056+ _ASM_EXTABLE(24b,100b)
23057+ _ASM_EXTABLE(25b,100b)
23058+ _ASM_EXTABLE(26b,100b)
23059+ _ASM_EXTABLE(27b,100b)
23060+ _ASM_EXTABLE(28b,100b)
23061+ _ASM_EXTABLE(29b,100b)
23062+ _ASM_EXTABLE(30b,100b)
23063+ _ASM_EXTABLE(31b,100b)
23064+ _ASM_EXTABLE(32b,100b)
23065+ _ASM_EXTABLE(33b,100b)
23066+ _ASM_EXTABLE(34b,100b)
23067+ _ASM_EXTABLE(35b,100b)
23068+ _ASM_EXTABLE(36b,100b)
23069+ _ASM_EXTABLE(37b,100b)
23070+ _ASM_EXTABLE(99b,101b)
23071+ : "=&c"(size), "=&D" (d0), "=&S" (d1)
23072+ : "1"(to), "2"(from), "0"(size)
23073+ : "eax", "edx", "memory");
23074+ return size;
23075+}
23076+
23077+static unsigned long __size_overflow(3)
23078 __copy_user_zeroing_intel(void *to, const void __user *from, unsigned long size)
23079 {
23080 int d0, d1;
23081 __asm__ __volatile__(
23082 " .align 2,0x90\n"
23083- "0: movl 32(%4), %%eax\n"
23084+ "0: "__copyuser_seg" movl 32(%4), %%eax\n"
23085 " cmpl $67, %0\n"
23086 " jbe 2f\n"
23087- "1: movl 64(%4), %%eax\n"
23088+ "1: "__copyuser_seg" movl 64(%4), %%eax\n"
23089 " .align 2,0x90\n"
23090- "2: movl 0(%4), %%eax\n"
23091- "21: movl 4(%4), %%edx\n"
23092+ "2: "__copyuser_seg" movl 0(%4), %%eax\n"
23093+ "21: "__copyuser_seg" movl 4(%4), %%edx\n"
23094 " movl %%eax, 0(%3)\n"
23095 " movl %%edx, 4(%3)\n"
23096- "3: movl 8(%4), %%eax\n"
23097- "31: movl 12(%4),%%edx\n"
23098+ "3: "__copyuser_seg" movl 8(%4), %%eax\n"
23099+ "31: "__copyuser_seg" movl 12(%4),%%edx\n"
23100 " movl %%eax, 8(%3)\n"
23101 " movl %%edx, 12(%3)\n"
23102- "4: movl 16(%4), %%eax\n"
23103- "41: movl 20(%4), %%edx\n"
23104+ "4: "__copyuser_seg" movl 16(%4), %%eax\n"
23105+ "41: "__copyuser_seg" movl 20(%4), %%edx\n"
23106 " movl %%eax, 16(%3)\n"
23107 " movl %%edx, 20(%3)\n"
23108- "10: movl 24(%4), %%eax\n"
23109- "51: movl 28(%4), %%edx\n"
23110+ "10: "__copyuser_seg" movl 24(%4), %%eax\n"
23111+ "51: "__copyuser_seg" movl 28(%4), %%edx\n"
23112 " movl %%eax, 24(%3)\n"
23113 " movl %%edx, 28(%3)\n"
23114- "11: movl 32(%4), %%eax\n"
23115- "61: movl 36(%4), %%edx\n"
23116+ "11: "__copyuser_seg" movl 32(%4), %%eax\n"
23117+ "61: "__copyuser_seg" movl 36(%4), %%edx\n"
23118 " movl %%eax, 32(%3)\n"
23119 " movl %%edx, 36(%3)\n"
23120- "12: movl 40(%4), %%eax\n"
23121- "71: movl 44(%4), %%edx\n"
23122+ "12: "__copyuser_seg" movl 40(%4), %%eax\n"
23123+ "71: "__copyuser_seg" movl 44(%4), %%edx\n"
23124 " movl %%eax, 40(%3)\n"
23125 " movl %%edx, 44(%3)\n"
23126- "13: movl 48(%4), %%eax\n"
23127- "81: movl 52(%4), %%edx\n"
23128+ "13: "__copyuser_seg" movl 48(%4), %%eax\n"
23129+ "81: "__copyuser_seg" movl 52(%4), %%edx\n"
23130 " movl %%eax, 48(%3)\n"
23131 " movl %%edx, 52(%3)\n"
23132- "14: movl 56(%4), %%eax\n"
23133- "91: movl 60(%4), %%edx\n"
23134+ "14: "__copyuser_seg" movl 56(%4), %%eax\n"
23135+ "91: "__copyuser_seg" movl 60(%4), %%edx\n"
23136 " movl %%eax, 56(%3)\n"
23137 " movl %%edx, 60(%3)\n"
23138 " addl $-64, %0\n"
23139@@ -252,9 +360,9 @@ __copy_user_zeroing_intel(void *to, const void __user *from, unsigned long size)
23140 " shrl $2, %0\n"
23141 " andl $3, %%eax\n"
23142 " cld\n"
23143- "6: rep; movsl\n"
23144+ "6: rep; "__copyuser_seg" movsl\n"
23145 " movl %%eax,%0\n"
23146- "7: rep; movsb\n"
23147+ "7: rep; "__copyuser_seg" movsb\n"
23148 "8:\n"
23149 ".section .fixup,\"ax\"\n"
23150 "9: lea 0(%%eax,%0,4),%0\n"
23151@@ -297,48 +405,48 @@ __copy_user_zeroing_intel(void *to, const void __user *from, unsigned long size)
23152 * hyoshiok@miraclelinux.com
23153 */
23154
23155-static unsigned long __copy_user_zeroing_intel_nocache(void *to,
23156+static unsigned long __size_overflow(3) __copy_user_zeroing_intel_nocache(void *to,
23157 const void __user *from, unsigned long size)
23158 {
23159 int d0, d1;
23160
23161 __asm__ __volatile__(
23162 " .align 2,0x90\n"
23163- "0: movl 32(%4), %%eax\n"
23164+ "0: "__copyuser_seg" movl 32(%4), %%eax\n"
23165 " cmpl $67, %0\n"
23166 " jbe 2f\n"
23167- "1: movl 64(%4), %%eax\n"
23168+ "1: "__copyuser_seg" movl 64(%4), %%eax\n"
23169 " .align 2,0x90\n"
23170- "2: movl 0(%4), %%eax\n"
23171- "21: movl 4(%4), %%edx\n"
23172+ "2: "__copyuser_seg" movl 0(%4), %%eax\n"
23173+ "21: "__copyuser_seg" movl 4(%4), %%edx\n"
23174 " movnti %%eax, 0(%3)\n"
23175 " movnti %%edx, 4(%3)\n"
23176- "3: movl 8(%4), %%eax\n"
23177- "31: movl 12(%4),%%edx\n"
23178+ "3: "__copyuser_seg" movl 8(%4), %%eax\n"
23179+ "31: "__copyuser_seg" movl 12(%4),%%edx\n"
23180 " movnti %%eax, 8(%3)\n"
23181 " movnti %%edx, 12(%3)\n"
23182- "4: movl 16(%4), %%eax\n"
23183- "41: movl 20(%4), %%edx\n"
23184+ "4: "__copyuser_seg" movl 16(%4), %%eax\n"
23185+ "41: "__copyuser_seg" movl 20(%4), %%edx\n"
23186 " movnti %%eax, 16(%3)\n"
23187 " movnti %%edx, 20(%3)\n"
23188- "10: movl 24(%4), %%eax\n"
23189- "51: movl 28(%4), %%edx\n"
23190+ "10: "__copyuser_seg" movl 24(%4), %%eax\n"
23191+ "51: "__copyuser_seg" movl 28(%4), %%edx\n"
23192 " movnti %%eax, 24(%3)\n"
23193 " movnti %%edx, 28(%3)\n"
23194- "11: movl 32(%4), %%eax\n"
23195- "61: movl 36(%4), %%edx\n"
23196+ "11: "__copyuser_seg" movl 32(%4), %%eax\n"
23197+ "61: "__copyuser_seg" movl 36(%4), %%edx\n"
23198 " movnti %%eax, 32(%3)\n"
23199 " movnti %%edx, 36(%3)\n"
23200- "12: movl 40(%4), %%eax\n"
23201- "71: movl 44(%4), %%edx\n"
23202+ "12: "__copyuser_seg" movl 40(%4), %%eax\n"
23203+ "71: "__copyuser_seg" movl 44(%4), %%edx\n"
23204 " movnti %%eax, 40(%3)\n"
23205 " movnti %%edx, 44(%3)\n"
23206- "13: movl 48(%4), %%eax\n"
23207- "81: movl 52(%4), %%edx\n"
23208+ "13: "__copyuser_seg" movl 48(%4), %%eax\n"
23209+ "81: "__copyuser_seg" movl 52(%4), %%edx\n"
23210 " movnti %%eax, 48(%3)\n"
23211 " movnti %%edx, 52(%3)\n"
23212- "14: movl 56(%4), %%eax\n"
23213- "91: movl 60(%4), %%edx\n"
23214+ "14: "__copyuser_seg" movl 56(%4), %%eax\n"
23215+ "91: "__copyuser_seg" movl 60(%4), %%edx\n"
23216 " movnti %%eax, 56(%3)\n"
23217 " movnti %%edx, 60(%3)\n"
23218 " addl $-64, %0\n"
23219@@ -351,9 +459,9 @@ static unsigned long __copy_user_zeroing_intel_nocache(void *to,
23220 " shrl $2, %0\n"
23221 " andl $3, %%eax\n"
23222 " cld\n"
23223- "6: rep; movsl\n"
23224+ "6: rep; "__copyuser_seg" movsl\n"
23225 " movl %%eax,%0\n"
23226- "7: rep; movsb\n"
23227+ "7: rep; "__copyuser_seg" movsb\n"
23228 "8:\n"
23229 ".section .fixup,\"ax\"\n"
23230 "9: lea 0(%%eax,%0,4),%0\n"
23231@@ -391,48 +499,48 @@ static unsigned long __copy_user_zeroing_intel_nocache(void *to,
23232 return size;
23233 }
23234
23235-static unsigned long __copy_user_intel_nocache(void *to,
23236+static unsigned long __size_overflow(3) __copy_user_intel_nocache(void *to,
23237 const void __user *from, unsigned long size)
23238 {
23239 int d0, d1;
23240
23241 __asm__ __volatile__(
23242 " .align 2,0x90\n"
23243- "0: movl 32(%4), %%eax\n"
23244+ "0: "__copyuser_seg" movl 32(%4), %%eax\n"
23245 " cmpl $67, %0\n"
23246 " jbe 2f\n"
23247- "1: movl 64(%4), %%eax\n"
23248+ "1: "__copyuser_seg" movl 64(%4), %%eax\n"
23249 " .align 2,0x90\n"
23250- "2: movl 0(%4), %%eax\n"
23251- "21: movl 4(%4), %%edx\n"
23252+ "2: "__copyuser_seg" movl 0(%4), %%eax\n"
23253+ "21: "__copyuser_seg" movl 4(%4), %%edx\n"
23254 " movnti %%eax, 0(%3)\n"
23255 " movnti %%edx, 4(%3)\n"
23256- "3: movl 8(%4), %%eax\n"
23257- "31: movl 12(%4),%%edx\n"
23258+ "3: "__copyuser_seg" movl 8(%4), %%eax\n"
23259+ "31: "__copyuser_seg" movl 12(%4),%%edx\n"
23260 " movnti %%eax, 8(%3)\n"
23261 " movnti %%edx, 12(%3)\n"
23262- "4: movl 16(%4), %%eax\n"
23263- "41: movl 20(%4), %%edx\n"
23264+ "4: "__copyuser_seg" movl 16(%4), %%eax\n"
23265+ "41: "__copyuser_seg" movl 20(%4), %%edx\n"
23266 " movnti %%eax, 16(%3)\n"
23267 " movnti %%edx, 20(%3)\n"
23268- "10: movl 24(%4), %%eax\n"
23269- "51: movl 28(%4), %%edx\n"
23270+ "10: "__copyuser_seg" movl 24(%4), %%eax\n"
23271+ "51: "__copyuser_seg" movl 28(%4), %%edx\n"
23272 " movnti %%eax, 24(%3)\n"
23273 " movnti %%edx, 28(%3)\n"
23274- "11: movl 32(%4), %%eax\n"
23275- "61: movl 36(%4), %%edx\n"
23276+ "11: "__copyuser_seg" movl 32(%4), %%eax\n"
23277+ "61: "__copyuser_seg" movl 36(%4), %%edx\n"
23278 " movnti %%eax, 32(%3)\n"
23279 " movnti %%edx, 36(%3)\n"
23280- "12: movl 40(%4), %%eax\n"
23281- "71: movl 44(%4), %%edx\n"
23282+ "12: "__copyuser_seg" movl 40(%4), %%eax\n"
23283+ "71: "__copyuser_seg" movl 44(%4), %%edx\n"
23284 " movnti %%eax, 40(%3)\n"
23285 " movnti %%edx, 44(%3)\n"
23286- "13: movl 48(%4), %%eax\n"
23287- "81: movl 52(%4), %%edx\n"
23288+ "13: "__copyuser_seg" movl 48(%4), %%eax\n"
23289+ "81: "__copyuser_seg" movl 52(%4), %%edx\n"
23290 " movnti %%eax, 48(%3)\n"
23291 " movnti %%edx, 52(%3)\n"
23292- "14: movl 56(%4), %%eax\n"
23293- "91: movl 60(%4), %%edx\n"
23294+ "14: "__copyuser_seg" movl 56(%4), %%eax\n"
23295+ "91: "__copyuser_seg" movl 60(%4), %%edx\n"
23296 " movnti %%eax, 56(%3)\n"
23297 " movnti %%edx, 60(%3)\n"
23298 " addl $-64, %0\n"
23299@@ -445,9 +553,9 @@ static unsigned long __copy_user_intel_nocache(void *to,
23300 " shrl $2, %0\n"
23301 " andl $3, %%eax\n"
23302 " cld\n"
23303- "6: rep; movsl\n"
23304+ "6: rep; "__copyuser_seg" movsl\n"
23305 " movl %%eax,%0\n"
23306- "7: rep; movsb\n"
23307+ "7: rep; "__copyuser_seg" movsb\n"
23308 "8:\n"
23309 ".section .fixup,\"ax\"\n"
23310 "9: lea 0(%%eax,%0,4),%0\n"
23311@@ -487,32 +595,36 @@ static unsigned long __copy_user_intel_nocache(void *to,
23312 */
23313 unsigned long __copy_user_zeroing_intel(void *to, const void __user *from,
23314 unsigned long size);
23315-unsigned long __copy_user_intel(void __user *to, const void *from,
23316+unsigned long __generic_copy_to_user_intel(void __user *to, const void *from,
23317+ unsigned long size);
23318+unsigned long __generic_copy_from_user_intel(void *to, const void __user *from,
23319 unsigned long size);
23320 unsigned long __copy_user_zeroing_intel_nocache(void *to,
23321 const void __user *from, unsigned long size);
23322 #endif /* CONFIG_X86_INTEL_USERCOPY */
23323
23324 /* Generic arbitrary sized copy. */
23325-#define __copy_user(to, from, size) \
23326+#define __copy_user(to, from, size, prefix, set, restore) \
23327 do { \
23328 int __d0, __d1, __d2; \
23329 __asm__ __volatile__( \
23330+ set \
23331 " cmp $7,%0\n" \
23332 " jbe 1f\n" \
23333 " movl %1,%0\n" \
23334 " negl %0\n" \
23335 " andl $7,%0\n" \
23336 " subl %0,%3\n" \
23337- "4: rep; movsb\n" \
23338+ "4: rep; "prefix"movsb\n" \
23339 " movl %3,%0\n" \
23340 " shrl $2,%0\n" \
23341 " andl $3,%3\n" \
23342 " .align 2,0x90\n" \
23343- "0: rep; movsl\n" \
23344+ "0: rep; "prefix"movsl\n" \
23345 " movl %3,%0\n" \
23346- "1: rep; movsb\n" \
23347+ "1: rep; "prefix"movsb\n" \
23348 "2:\n" \
23349+ restore \
23350 ".section .fixup,\"ax\"\n" \
23351 "5: addl %3,%0\n" \
23352 " jmp 2b\n" \
23353@@ -537,14 +649,14 @@ do { \
23354 " negl %0\n" \
23355 " andl $7,%0\n" \
23356 " subl %0,%3\n" \
23357- "4: rep; movsb\n" \
23358+ "4: rep; "__copyuser_seg"movsb\n" \
23359 " movl %3,%0\n" \
23360 " shrl $2,%0\n" \
23361 " andl $3,%3\n" \
23362 " .align 2,0x90\n" \
23363- "0: rep; movsl\n" \
23364+ "0: rep; "__copyuser_seg"movsl\n" \
23365 " movl %3,%0\n" \
23366- "1: rep; movsb\n" \
23367+ "1: rep; "__copyuser_seg"movsb\n" \
23368 "2:\n" \
23369 ".section .fixup,\"ax\"\n" \
23370 "5: addl %3,%0\n" \
23371@@ -627,9 +739,9 @@ survive:
23372 }
23373 #endif
23374 if (movsl_is_ok(to, from, n))
23375- __copy_user(to, from, n);
23376+ __copy_user(to, from, n, "", __COPYUSER_SET_ES, __COPYUSER_RESTORE_ES);
23377 else
23378- n = __copy_user_intel(to, from, n);
23379+ n = __generic_copy_to_user_intel(to, from, n);
23380 return n;
23381 }
23382 EXPORT_SYMBOL(__copy_to_user_ll);
23383@@ -649,10 +761,9 @@ unsigned long __copy_from_user_ll_nozero(void *to, const void __user *from,
23384 unsigned long n)
23385 {
23386 if (movsl_is_ok(to, from, n))
23387- __copy_user(to, from, n);
23388+ __copy_user(to, from, n, __copyuser_seg, "", "");
23389 else
23390- n = __copy_user_intel((void __user *)to,
23391- (const void *)from, n);
23392+ n = __generic_copy_from_user_intel(to, from, n);
23393 return n;
23394 }
23395 EXPORT_SYMBOL(__copy_from_user_ll_nozero);
23396@@ -679,65 +790,50 @@ unsigned long __copy_from_user_ll_nocache_nozero(void *to, const void __user *fr
23397 if (n > 64 && cpu_has_xmm2)
23398 n = __copy_user_intel_nocache(to, from, n);
23399 else
23400- __copy_user(to, from, n);
23401+ __copy_user(to, from, n, __copyuser_seg, "", "");
23402 #else
23403- __copy_user(to, from, n);
23404+ __copy_user(to, from, n, __copyuser_seg, "", "");
23405 #endif
23406 return n;
23407 }
23408 EXPORT_SYMBOL(__copy_from_user_ll_nocache_nozero);
23409
23410-/**
23411- * copy_to_user: - Copy a block of data into user space.
23412- * @to: Destination address, in user space.
23413- * @from: Source address, in kernel space.
23414- * @n: Number of bytes to copy.
23415- *
23416- * Context: User context only. This function may sleep.
23417- *
23418- * Copy data from kernel space to user space.
23419- *
23420- * Returns number of bytes that could not be copied.
23421- * On success, this will be zero.
23422- */
23423-unsigned long
23424-copy_to_user(void __user *to, const void *from, unsigned long n)
23425-{
23426- if (access_ok(VERIFY_WRITE, to, n))
23427- n = __copy_to_user(to, from, n);
23428- return n;
23429-}
23430-EXPORT_SYMBOL(copy_to_user);
23431-
23432-/**
23433- * copy_from_user: - Copy a block of data from user space.
23434- * @to: Destination address, in kernel space.
23435- * @from: Source address, in user space.
23436- * @n: Number of bytes to copy.
23437- *
23438- * Context: User context only. This function may sleep.
23439- *
23440- * Copy data from user space to kernel space.
23441- *
23442- * Returns number of bytes that could not be copied.
23443- * On success, this will be zero.
23444- *
23445- * If some data could not be copied, this function will pad the copied
23446- * data to the requested size using zero bytes.
23447- */
23448-unsigned long
23449-_copy_from_user(void *to, const void __user *from, unsigned long n)
23450-{
23451- if (access_ok(VERIFY_READ, from, n))
23452- n = __copy_from_user(to, from, n);
23453- else
23454- memset(to, 0, n);
23455- return n;
23456-}
23457-EXPORT_SYMBOL(_copy_from_user);
23458-
23459 void copy_from_user_overflow(void)
23460 {
23461 WARN(1, "Buffer overflow detected!\n");
23462 }
23463 EXPORT_SYMBOL(copy_from_user_overflow);
23464+
23465+void copy_to_user_overflow(void)
23466+{
23467+ WARN(1, "Buffer overflow detected!\n");
23468+}
23469+EXPORT_SYMBOL(copy_to_user_overflow);
23470+
23471+#ifdef CONFIG_PAX_MEMORY_UDEREF
23472+void __set_fs(mm_segment_t x)
23473+{
23474+ switch (x.seg) {
23475+ case 0:
23476+ loadsegment(gs, 0);
23477+ break;
23478+ case TASK_SIZE_MAX:
23479+ loadsegment(gs, __USER_DS);
23480+ break;
23481+ case -1UL:
23482+ loadsegment(gs, __KERNEL_DS);
23483+ break;
23484+ default:
23485+ BUG();
23486+ }
23487+ return;
23488+}
23489+EXPORT_SYMBOL(__set_fs);
23490+
23491+void set_fs(mm_segment_t x)
23492+{
23493+ current_thread_info()->addr_limit = x;
23494+ __set_fs(x);
23495+}
23496+EXPORT_SYMBOL(set_fs);
23497+#endif
23498diff --git a/arch/x86/lib/usercopy_64.c b/arch/x86/lib/usercopy_64.c
23499index e5b130b..6690d31 100644
23500--- a/arch/x86/lib/usercopy_64.c
23501+++ b/arch/x86/lib/usercopy_64.c
23502@@ -16,6 +16,12 @@ unsigned long __clear_user(void __user *addr, unsigned long size)
23503 {
23504 long __d0;
23505 might_fault();
23506+
23507+#ifdef CONFIG_PAX_MEMORY_UDEREF
23508+ if ((unsigned long)addr < PAX_USER_SHADOW_BASE)
23509+ addr += PAX_USER_SHADOW_BASE;
23510+#endif
23511+
23512 /* no memory constraint because it doesn't change any memory gcc knows
23513 about */
23514 asm volatile(
23515@@ -52,12 +58,20 @@ unsigned long clear_user(void __user *to, unsigned long n)
23516 }
23517 EXPORT_SYMBOL(clear_user);
23518
23519-unsigned long copy_in_user(void __user *to, const void __user *from, unsigned len)
23520+unsigned long copy_in_user(void __user *to, const void __user *from, unsigned long len)
23521 {
23522- if (access_ok(VERIFY_WRITE, to, len) && access_ok(VERIFY_READ, from, len)) {
23523- return copy_user_generic((__force void *)to, (__force void *)from, len);
23524- }
23525- return len;
23526+ if (access_ok(VERIFY_WRITE, to, len) && access_ok(VERIFY_READ, from, len)) {
23527+
23528+#ifdef CONFIG_PAX_MEMORY_UDEREF
23529+ if ((unsigned long)to < PAX_USER_SHADOW_BASE)
23530+ to += PAX_USER_SHADOW_BASE;
23531+ if ((unsigned long)from < PAX_USER_SHADOW_BASE)
23532+ from += PAX_USER_SHADOW_BASE;
23533+#endif
23534+
23535+ return copy_user_generic((void __force_kernel *)to, (void __force_kernel *)from, len);
23536+ }
23537+ return len;
23538 }
23539 EXPORT_SYMBOL(copy_in_user);
23540
23541@@ -67,7 +81,7 @@ EXPORT_SYMBOL(copy_in_user);
23542 * it is not necessary to optimize tail handling.
23543 */
23544 unsigned long
23545-copy_user_handle_tail(char *to, char *from, unsigned len, unsigned zerorest)
23546+copy_user_handle_tail(char __user *to, char __user *from, unsigned long len, unsigned zerorest)
23547 {
23548 char c;
23549 unsigned zero_len;
23550@@ -84,3 +98,15 @@ copy_user_handle_tail(char *to, char *from, unsigned len, unsigned zerorest)
23551 break;
23552 return len;
23553 }
23554+
23555+void copy_from_user_overflow(void)
23556+{
23557+ WARN(1, "Buffer overflow detected!\n");
23558+}
23559+EXPORT_SYMBOL(copy_from_user_overflow);
23560+
23561+void copy_to_user_overflow(void)
23562+{
23563+ WARN(1, "Buffer overflow detected!\n");
23564+}
23565+EXPORT_SYMBOL(copy_to_user_overflow);
23566diff --git a/arch/x86/mm/extable.c b/arch/x86/mm/extable.c
23567index 903ec1e..c4166b2 100644
23568--- a/arch/x86/mm/extable.c
23569+++ b/arch/x86/mm/extable.c
23570@@ -6,12 +6,24 @@
23571 static inline unsigned long
23572 ex_insn_addr(const struct exception_table_entry *x)
23573 {
23574- return (unsigned long)&x->insn + x->insn;
23575+ unsigned long reloc = 0;
23576+
23577+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
23578+ reloc = ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
23579+#endif
23580+
23581+ return (unsigned long)&x->insn + x->insn + reloc;
23582 }
23583 static inline unsigned long
23584 ex_fixup_addr(const struct exception_table_entry *x)
23585 {
23586- return (unsigned long)&x->fixup + x->fixup;
23587+ unsigned long reloc = 0;
23588+
23589+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
23590+ reloc = ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
23591+#endif
23592+
23593+ return (unsigned long)&x->fixup + x->fixup + reloc;
23594 }
23595
23596 int fixup_exception(struct pt_regs *regs)
23597@@ -20,7 +32,7 @@ int fixup_exception(struct pt_regs *regs)
23598 unsigned long new_ip;
23599
23600 #ifdef CONFIG_PNPBIOS
23601- if (unlikely(SEGMENT_IS_PNP_CODE(regs->cs))) {
23602+ if (unlikely(!v8086_mode(regs) && SEGMENT_IS_PNP_CODE(regs->cs))) {
23603 extern u32 pnp_bios_fault_eip, pnp_bios_fault_esp;
23604 extern u32 pnp_bios_is_utter_crap;
23605 pnp_bios_is_utter_crap = 1;
23606@@ -145,6 +157,13 @@ void sort_extable(struct exception_table_entry *start,
23607 i += 4;
23608 p->fixup -= i;
23609 i += 4;
23610+
23611+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
23612+ BUILD_BUG_ON(!IS_ENABLED(CONFIG_BUILDTIME_EXTABLE_SORT));
23613+ p->insn -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
23614+ p->fixup -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
23615+#endif
23616+
23617 }
23618 }
23619
23620diff --git a/arch/x86/mm/fault.c b/arch/x86/mm/fault.c
23621index 76dcd9d..e9dffde 100644
23622--- a/arch/x86/mm/fault.c
23623+++ b/arch/x86/mm/fault.c
23624@@ -13,11 +13,18 @@
23625 #include <linux/perf_event.h> /* perf_sw_event */
23626 #include <linux/hugetlb.h> /* hstate_index_to_shift */
23627 #include <linux/prefetch.h> /* prefetchw */
23628+#include <linux/unistd.h>
23629+#include <linux/compiler.h>
23630
23631 #include <asm/traps.h> /* dotraplinkage, ... */
23632 #include <asm/pgalloc.h> /* pgd_*(), ... */
23633 #include <asm/kmemcheck.h> /* kmemcheck_*(), ... */
23634 #include <asm/fixmap.h> /* VSYSCALL_START */
23635+#include <asm/tlbflush.h>
23636+
23637+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
23638+#include <asm/stacktrace.h>
23639+#endif
23640
23641 /*
23642 * Page fault error code bits:
23643@@ -55,7 +62,7 @@ static inline int __kprobes notify_page_fault(struct pt_regs *regs)
23644 int ret = 0;
23645
23646 /* kprobe_running() needs smp_processor_id() */
23647- if (kprobes_built_in() && !user_mode_vm(regs)) {
23648+ if (kprobes_built_in() && !user_mode(regs)) {
23649 preempt_disable();
23650 if (kprobe_running() && kprobe_fault_handler(regs, 14))
23651 ret = 1;
23652@@ -116,7 +123,10 @@ check_prefetch_opcode(struct pt_regs *regs, unsigned char *instr,
23653 return !instr_lo || (instr_lo>>1) == 1;
23654 case 0x00:
23655 /* Prefetch instruction is 0x0F0D or 0x0F18 */
23656- if (probe_kernel_address(instr, opcode))
23657+ if (user_mode(regs)) {
23658+ if (__copy_from_user_inatomic(&opcode, (unsigned char __force_user *)(instr), 1))
23659+ return 0;
23660+ } else if (probe_kernel_address(instr, opcode))
23661 return 0;
23662
23663 *prefetch = (instr_lo == 0xF) &&
23664@@ -150,7 +160,10 @@ is_prefetch(struct pt_regs *regs, unsigned long error_code, unsigned long addr)
23665 while (instr < max_instr) {
23666 unsigned char opcode;
23667
23668- if (probe_kernel_address(instr, opcode))
23669+ if (user_mode(regs)) {
23670+ if (__copy_from_user_inatomic(&opcode, (unsigned char __force_user *)(instr), 1))
23671+ break;
23672+ } else if (probe_kernel_address(instr, opcode))
23673 break;
23674
23675 instr++;
23676@@ -181,6 +194,34 @@ force_sig_info_fault(int si_signo, int si_code, unsigned long address,
23677 force_sig_info(si_signo, &info, tsk);
23678 }
23679
23680+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
23681+static bool pax_is_fetch_fault(struct pt_regs *regs, unsigned long error_code, unsigned long address);
23682+#endif
23683+
23684+#ifdef CONFIG_PAX_EMUTRAMP
23685+static int pax_handle_fetch_fault(struct pt_regs *regs);
23686+#endif
23687+
23688+#ifdef CONFIG_PAX_PAGEEXEC
23689+static inline pmd_t * pax_get_pmd(struct mm_struct *mm, unsigned long address)
23690+{
23691+ pgd_t *pgd;
23692+ pud_t *pud;
23693+ pmd_t *pmd;
23694+
23695+ pgd = pgd_offset(mm, address);
23696+ if (!pgd_present(*pgd))
23697+ return NULL;
23698+ pud = pud_offset(pgd, address);
23699+ if (!pud_present(*pud))
23700+ return NULL;
23701+ pmd = pmd_offset(pud, address);
23702+ if (!pmd_present(*pmd))
23703+ return NULL;
23704+ return pmd;
23705+}
23706+#endif
23707+
23708 DEFINE_SPINLOCK(pgd_lock);
23709 LIST_HEAD(pgd_list);
23710
23711@@ -231,10 +272,22 @@ void vmalloc_sync_all(void)
23712 for (address = VMALLOC_START & PMD_MASK;
23713 address >= TASK_SIZE && address < FIXADDR_TOP;
23714 address += PMD_SIZE) {
23715+
23716+#ifdef CONFIG_PAX_PER_CPU_PGD
23717+ unsigned long cpu;
23718+#else
23719 struct page *page;
23720+#endif
23721
23722 spin_lock(&pgd_lock);
23723+
23724+#ifdef CONFIG_PAX_PER_CPU_PGD
23725+ for (cpu = 0; cpu < nr_cpu_ids; ++cpu) {
23726+ pgd_t *pgd = get_cpu_pgd(cpu);
23727+ pmd_t *ret;
23728+#else
23729 list_for_each_entry(page, &pgd_list, lru) {
23730+ pgd_t *pgd = page_address(page);
23731 spinlock_t *pgt_lock;
23732 pmd_t *ret;
23733
23734@@ -242,8 +295,13 @@ void vmalloc_sync_all(void)
23735 pgt_lock = &pgd_page_get_mm(page)->page_table_lock;
23736
23737 spin_lock(pgt_lock);
23738- ret = vmalloc_sync_one(page_address(page), address);
23739+#endif
23740+
23741+ ret = vmalloc_sync_one(pgd, address);
23742+
23743+#ifndef CONFIG_PAX_PER_CPU_PGD
23744 spin_unlock(pgt_lock);
23745+#endif
23746
23747 if (!ret)
23748 break;
23749@@ -277,6 +335,11 @@ static noinline __kprobes int vmalloc_fault(unsigned long address)
23750 * an interrupt in the middle of a task switch..
23751 */
23752 pgd_paddr = read_cr3();
23753+
23754+#ifdef CONFIG_PAX_PER_CPU_PGD
23755+ BUG_ON(__pa(get_cpu_pgd(smp_processor_id())) != (pgd_paddr & PHYSICAL_PAGE_MASK));
23756+#endif
23757+
23758 pmd_k = vmalloc_sync_one(__va(pgd_paddr), address);
23759 if (!pmd_k)
23760 return -1;
23761@@ -372,7 +435,14 @@ static noinline __kprobes int vmalloc_fault(unsigned long address)
23762 * happen within a race in page table update. In the later
23763 * case just flush:
23764 */
23765+
23766+#ifdef CONFIG_PAX_PER_CPU_PGD
23767+ BUG_ON(__pa(get_cpu_pgd(smp_processor_id())) != (read_cr3() & PHYSICAL_PAGE_MASK));
23768+ pgd = pgd_offset_cpu(smp_processor_id(), address);
23769+#else
23770 pgd = pgd_offset(current->active_mm, address);
23771+#endif
23772+
23773 pgd_ref = pgd_offset_k(address);
23774 if (pgd_none(*pgd_ref))
23775 return -1;
23776@@ -540,7 +610,7 @@ static int is_errata93(struct pt_regs *regs, unsigned long address)
23777 static int is_errata100(struct pt_regs *regs, unsigned long address)
23778 {
23779 #ifdef CONFIG_X86_64
23780- if ((regs->cs == __USER32_CS || (regs->cs & (1<<2))) && (address >> 32))
23781+ if ((regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT)) && (address >> 32))
23782 return 1;
23783 #endif
23784 return 0;
23785@@ -567,7 +637,7 @@ static int is_f00f_bug(struct pt_regs *regs, unsigned long address)
23786 }
23787
23788 static const char nx_warning[] = KERN_CRIT
23789-"kernel tried to execute NX-protected page - exploit attempt? (uid: %d)\n";
23790+"kernel tried to execute NX-protected page - exploit attempt? (uid: %d, task: %s, pid: %d)\n";
23791
23792 static void
23793 show_fault_oops(struct pt_regs *regs, unsigned long error_code,
23794@@ -576,15 +646,26 @@ show_fault_oops(struct pt_regs *regs, unsigned long error_code,
23795 if (!oops_may_print())
23796 return;
23797
23798- if (error_code & PF_INSTR) {
23799+ if ((__supported_pte_mask & _PAGE_NX) && (error_code & PF_INSTR)) {
23800 unsigned int level;
23801
23802 pte_t *pte = lookup_address(address, &level);
23803
23804 if (pte && pte_present(*pte) && !pte_exec(*pte))
23805- printk(nx_warning, from_kuid(&init_user_ns, current_uid()));
23806+ printk(nx_warning, from_kuid(&init_user_ns, current_uid()), current->comm, task_pid_nr(current));
23807 }
23808
23809+#ifdef CONFIG_PAX_KERNEXEC
23810+ if (init_mm.start_code <= address && address < init_mm.end_code) {
23811+ if (current->signal->curr_ip)
23812+ printk(KERN_ERR "PAX: From %pI4: %s:%d, uid/euid: %u/%u, attempted to modify kernel code\n",
23813+ &current->signal->curr_ip, current->comm, task_pid_nr(current), current_uid(), current_euid());
23814+ else
23815+ printk(KERN_ERR "PAX: %s:%d, uid/euid: %u/%u, attempted to modify kernel code\n",
23816+ current->comm, task_pid_nr(current), current_uid(), current_euid());
23817+ }
23818+#endif
23819+
23820 printk(KERN_ALERT "BUG: unable to handle kernel ");
23821 if (address < PAGE_SIZE)
23822 printk(KERN_CONT "NULL pointer dereference");
23823@@ -748,6 +829,21 @@ __bad_area_nosemaphore(struct pt_regs *regs, unsigned long error_code,
23824 }
23825 #endif
23826
23827+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
23828+ if (pax_is_fetch_fault(regs, error_code, address)) {
23829+
23830+#ifdef CONFIG_PAX_EMUTRAMP
23831+ switch (pax_handle_fetch_fault(regs)) {
23832+ case 2:
23833+ return;
23834+ }
23835+#endif
23836+
23837+ pax_report_fault(regs, (void *)regs->ip, (void *)regs->sp);
23838+ do_group_exit(SIGKILL);
23839+ }
23840+#endif
23841+
23842 if (unlikely(show_unhandled_signals))
23843 show_signal_msg(regs, error_code, address, tsk);
23844
23845@@ -844,7 +940,7 @@ do_sigbus(struct pt_regs *regs, unsigned long error_code, unsigned long address,
23846 if (fault & (VM_FAULT_HWPOISON|VM_FAULT_HWPOISON_LARGE)) {
23847 printk(KERN_ERR
23848 "MCE: Killing %s:%d due to hardware memory corruption fault at %lx\n",
23849- tsk->comm, tsk->pid, address);
23850+ tsk->comm, task_pid_nr(tsk), address);
23851 code = BUS_MCEERR_AR;
23852 }
23853 #endif
23854@@ -900,6 +996,99 @@ static int spurious_fault_check(unsigned long error_code, pte_t *pte)
23855 return 1;
23856 }
23857
23858+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
23859+static int pax_handle_pageexec_fault(struct pt_regs *regs, struct mm_struct *mm, unsigned long address, unsigned long error_code)
23860+{
23861+ pte_t *pte;
23862+ pmd_t *pmd;
23863+ spinlock_t *ptl;
23864+ unsigned char pte_mask;
23865+
23866+ if ((__supported_pte_mask & _PAGE_NX) || (error_code & (PF_PROT|PF_USER)) != (PF_PROT|PF_USER) || v8086_mode(regs) ||
23867+ !(mm->pax_flags & MF_PAX_PAGEEXEC))
23868+ return 0;
23869+
23870+ /* PaX: it's our fault, let's handle it if we can */
23871+
23872+ /* PaX: take a look at read faults before acquiring any locks */
23873+ if (unlikely(!(error_code & PF_WRITE) && (regs->ip == address))) {
23874+ /* instruction fetch attempt from a protected page in user mode */
23875+ up_read(&mm->mmap_sem);
23876+
23877+#ifdef CONFIG_PAX_EMUTRAMP
23878+ switch (pax_handle_fetch_fault(regs)) {
23879+ case 2:
23880+ return 1;
23881+ }
23882+#endif
23883+
23884+ pax_report_fault(regs, (void *)regs->ip, (void *)regs->sp);
23885+ do_group_exit(SIGKILL);
23886+ }
23887+
23888+ pmd = pax_get_pmd(mm, address);
23889+ if (unlikely(!pmd))
23890+ return 0;
23891+
23892+ pte = pte_offset_map_lock(mm, pmd, address, &ptl);
23893+ if (unlikely(!(pte_val(*pte) & _PAGE_PRESENT) || pte_user(*pte))) {
23894+ pte_unmap_unlock(pte, ptl);
23895+ return 0;
23896+ }
23897+
23898+ if (unlikely((error_code & PF_WRITE) && !pte_write(*pte))) {
23899+ /* write attempt to a protected page in user mode */
23900+ pte_unmap_unlock(pte, ptl);
23901+ return 0;
23902+ }
23903+
23904+#ifdef CONFIG_SMP
23905+ if (likely(address > get_limit(regs->cs) && cpu_isset(smp_processor_id(), mm->context.cpu_user_cs_mask)))
23906+#else
23907+ if (likely(address > get_limit(regs->cs)))
23908+#endif
23909+ {
23910+ set_pte(pte, pte_mkread(*pte));
23911+ __flush_tlb_one(address);
23912+ pte_unmap_unlock(pte, ptl);
23913+ up_read(&mm->mmap_sem);
23914+ return 1;
23915+ }
23916+
23917+ pte_mask = _PAGE_ACCESSED | _PAGE_USER | ((error_code & PF_WRITE) << (_PAGE_BIT_DIRTY-1));
23918+
23919+ /*
23920+ * PaX: fill DTLB with user rights and retry
23921+ */
23922+ __asm__ __volatile__ (
23923+ "orb %2,(%1)\n"
23924+#if defined(CONFIG_M586) || defined(CONFIG_M586TSC)
23925+/*
23926+ * PaX: let this uncommented 'invlpg' remind us on the behaviour of Intel's
23927+ * (and AMD's) TLBs. namely, they do not cache PTEs that would raise *any*
23928+ * page fault when examined during a TLB load attempt. this is true not only
23929+ * for PTEs holding a non-present entry but also present entries that will
23930+ * raise a page fault (such as those set up by PaX, or the copy-on-write
23931+ * mechanism). in effect it means that we do *not* need to flush the TLBs
23932+ * for our target pages since their PTEs are simply not in the TLBs at all.
23933+
23934+ * the best thing in omitting it is that we gain around 15-20% speed in the
23935+ * fast path of the page fault handler and can get rid of tracing since we
23936+ * can no longer flush unintended entries.
23937+ */
23938+ "invlpg (%0)\n"
23939+#endif
23940+ __copyuser_seg"testb $0,(%0)\n"
23941+ "xorb %3,(%1)\n"
23942+ :
23943+ : "r" (address), "r" (pte), "q" (pte_mask), "i" (_PAGE_USER)
23944+ : "memory", "cc");
23945+ pte_unmap_unlock(pte, ptl);
23946+ up_read(&mm->mmap_sem);
23947+ return 1;
23948+}
23949+#endif
23950+
23951 /*
23952 * Handle a spurious fault caused by a stale TLB entry.
23953 *
23954@@ -972,6 +1161,9 @@ int show_unhandled_signals = 1;
23955 static inline int
23956 access_error(unsigned long error_code, struct vm_area_struct *vma)
23957 {
23958+ if ((__supported_pte_mask & _PAGE_NX) && (error_code & PF_INSTR) && !(vma->vm_flags & VM_EXEC))
23959+ return 1;
23960+
23961 if (error_code & PF_WRITE) {
23962 /* write, present and write, not present: */
23963 if (unlikely(!(vma->vm_flags & VM_WRITE)))
23964@@ -1005,18 +1197,33 @@ do_page_fault(struct pt_regs *regs, unsigned long error_code)
23965 {
23966 struct vm_area_struct *vma;
23967 struct task_struct *tsk;
23968- unsigned long address;
23969 struct mm_struct *mm;
23970 int fault;
23971 int write = error_code & PF_WRITE;
23972 unsigned int flags = FAULT_FLAG_ALLOW_RETRY | FAULT_FLAG_KILLABLE |
23973 (write ? FAULT_FLAG_WRITE : 0);
23974
23975- tsk = current;
23976- mm = tsk->mm;
23977-
23978 /* Get the faulting address: */
23979- address = read_cr2();
23980+ unsigned long address = read_cr2();
23981+
23982+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
23983+ if (!user_mode(regs) && address < 2 * PAX_USER_SHADOW_BASE) {
23984+ if (!search_exception_tables(regs->ip)) {
23985+ printk(KERN_ERR "PAX: please report this to pageexec@freemail.hu\n");
23986+ bad_area_nosemaphore(regs, error_code, address);
23987+ return;
23988+ }
23989+ if (address < PAX_USER_SHADOW_BASE) {
23990+ printk(KERN_ERR "PAX: please report this to pageexec@freemail.hu\n");
23991+ printk(KERN_ERR "PAX: faulting IP: %pS\n", (void *)regs->ip);
23992+ show_trace_log_lvl(NULL, NULL, (void *)regs->sp, regs->bp, KERN_ERR);
23993+ } else
23994+ address -= PAX_USER_SHADOW_BASE;
23995+ }
23996+#endif
23997+
23998+ tsk = current;
23999+ mm = tsk->mm;
24000
24001 /*
24002 * Detect and handle instructions that would cause a page fault for
24003@@ -1077,7 +1284,7 @@ do_page_fault(struct pt_regs *regs, unsigned long error_code)
24004 * User-mode registers count as a user access even for any
24005 * potential system fault or CPU buglet:
24006 */
24007- if (user_mode_vm(regs)) {
24008+ if (user_mode(regs)) {
24009 local_irq_enable();
24010 error_code |= PF_USER;
24011 } else {
24012@@ -1132,6 +1339,11 @@ retry:
24013 might_sleep();
24014 }
24015
24016+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
24017+ if (pax_handle_pageexec_fault(regs, mm, address, error_code))
24018+ return;
24019+#endif
24020+
24021 vma = find_vma(mm, address);
24022 if (unlikely(!vma)) {
24023 bad_area(regs, error_code, address);
24024@@ -1143,18 +1355,24 @@ retry:
24025 bad_area(regs, error_code, address);
24026 return;
24027 }
24028- if (error_code & PF_USER) {
24029- /*
24030- * Accessing the stack below %sp is always a bug.
24031- * The large cushion allows instructions like enter
24032- * and pusha to work. ("enter $65535, $31" pushes
24033- * 32 pointers and then decrements %sp by 65535.)
24034- */
24035- if (unlikely(address + 65536 + 32 * sizeof(unsigned long) < regs->sp)) {
24036- bad_area(regs, error_code, address);
24037- return;
24038- }
24039+ /*
24040+ * Accessing the stack below %sp is always a bug.
24041+ * The large cushion allows instructions like enter
24042+ * and pusha to work. ("enter $65535, $31" pushes
24043+ * 32 pointers and then decrements %sp by 65535.)
24044+ */
24045+ if (unlikely(address + 65536 + 32 * sizeof(unsigned long) < task_pt_regs(tsk)->sp)) {
24046+ bad_area(regs, error_code, address);
24047+ return;
24048 }
24049+
24050+#ifdef CONFIG_PAX_SEGMEXEC
24051+ if (unlikely((mm->pax_flags & MF_PAX_SEGMEXEC) && vma->vm_end - SEGMEXEC_TASK_SIZE - 1 < address - SEGMEXEC_TASK_SIZE - 1)) {
24052+ bad_area(regs, error_code, address);
24053+ return;
24054+ }
24055+#endif
24056+
24057 if (unlikely(expand_stack(vma, address))) {
24058 bad_area(regs, error_code, address);
24059 return;
24060@@ -1209,3 +1427,292 @@ good_area:
24061
24062 up_read(&mm->mmap_sem);
24063 }
24064+
24065+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
24066+static bool pax_is_fetch_fault(struct pt_regs *regs, unsigned long error_code, unsigned long address)
24067+{
24068+ struct mm_struct *mm = current->mm;
24069+ unsigned long ip = regs->ip;
24070+
24071+ if (v8086_mode(regs))
24072+ ip = ((regs->cs & 0xffff) << 4) + (ip & 0xffff);
24073+
24074+#ifdef CONFIG_PAX_PAGEEXEC
24075+ if (mm->pax_flags & MF_PAX_PAGEEXEC) {
24076+ if ((__supported_pte_mask & _PAGE_NX) && (error_code & PF_INSTR))
24077+ return true;
24078+ if (!(error_code & (PF_PROT | PF_WRITE)) && ip == address)
24079+ return true;
24080+ return false;
24081+ }
24082+#endif
24083+
24084+#ifdef CONFIG_PAX_SEGMEXEC
24085+ if (mm->pax_flags & MF_PAX_SEGMEXEC) {
24086+ if (!(error_code & (PF_PROT | PF_WRITE)) && (ip + SEGMEXEC_TASK_SIZE == address))
24087+ return true;
24088+ return false;
24089+ }
24090+#endif
24091+
24092+ return false;
24093+}
24094+#endif
24095+
24096+#ifdef CONFIG_PAX_EMUTRAMP
24097+static int pax_handle_fetch_fault_32(struct pt_regs *regs)
24098+{
24099+ int err;
24100+
24101+ do { /* PaX: libffi trampoline emulation */
24102+ unsigned char mov, jmp;
24103+ unsigned int addr1, addr2;
24104+
24105+#ifdef CONFIG_X86_64
24106+ if ((regs->ip + 9) >> 32)
24107+ break;
24108+#endif
24109+
24110+ err = get_user(mov, (unsigned char __user *)regs->ip);
24111+ err |= get_user(addr1, (unsigned int __user *)(regs->ip + 1));
24112+ err |= get_user(jmp, (unsigned char __user *)(regs->ip + 5));
24113+ err |= get_user(addr2, (unsigned int __user *)(regs->ip + 6));
24114+
24115+ if (err)
24116+ break;
24117+
24118+ if (mov == 0xB8 && jmp == 0xE9) {
24119+ regs->ax = addr1;
24120+ regs->ip = (unsigned int)(regs->ip + addr2 + 10);
24121+ return 2;
24122+ }
24123+ } while (0);
24124+
24125+ do { /* PaX: gcc trampoline emulation #1 */
24126+ unsigned char mov1, mov2;
24127+ unsigned short jmp;
24128+ unsigned int addr1, addr2;
24129+
24130+#ifdef CONFIG_X86_64
24131+ if ((regs->ip + 11) >> 32)
24132+ break;
24133+#endif
24134+
24135+ err = get_user(mov1, (unsigned char __user *)regs->ip);
24136+ err |= get_user(addr1, (unsigned int __user *)(regs->ip + 1));
24137+ err |= get_user(mov2, (unsigned char __user *)(regs->ip + 5));
24138+ err |= get_user(addr2, (unsigned int __user *)(regs->ip + 6));
24139+ err |= get_user(jmp, (unsigned short __user *)(regs->ip + 10));
24140+
24141+ if (err)
24142+ break;
24143+
24144+ if (mov1 == 0xB9 && mov2 == 0xB8 && jmp == 0xE0FF) {
24145+ regs->cx = addr1;
24146+ regs->ax = addr2;
24147+ regs->ip = addr2;
24148+ return 2;
24149+ }
24150+ } while (0);
24151+
24152+ do { /* PaX: gcc trampoline emulation #2 */
24153+ unsigned char mov, jmp;
24154+ unsigned int addr1, addr2;
24155+
24156+#ifdef CONFIG_X86_64
24157+ if ((regs->ip + 9) >> 32)
24158+ break;
24159+#endif
24160+
24161+ err = get_user(mov, (unsigned char __user *)regs->ip);
24162+ err |= get_user(addr1, (unsigned int __user *)(regs->ip + 1));
24163+ err |= get_user(jmp, (unsigned char __user *)(regs->ip + 5));
24164+ err |= get_user(addr2, (unsigned int __user *)(regs->ip + 6));
24165+
24166+ if (err)
24167+ break;
24168+
24169+ if (mov == 0xB9 && jmp == 0xE9) {
24170+ regs->cx = addr1;
24171+ regs->ip = (unsigned int)(regs->ip + addr2 + 10);
24172+ return 2;
24173+ }
24174+ } while (0);
24175+
24176+ return 1; /* PaX in action */
24177+}
24178+
24179+#ifdef CONFIG_X86_64
24180+static int pax_handle_fetch_fault_64(struct pt_regs *regs)
24181+{
24182+ int err;
24183+
24184+ do { /* PaX: libffi trampoline emulation */
24185+ unsigned short mov1, mov2, jmp1;
24186+ unsigned char stcclc, jmp2;
24187+ unsigned long addr1, addr2;
24188+
24189+ err = get_user(mov1, (unsigned short __user *)regs->ip);
24190+ err |= get_user(addr1, (unsigned long __user *)(regs->ip + 2));
24191+ err |= get_user(mov2, (unsigned short __user *)(regs->ip + 10));
24192+ err |= get_user(addr2, (unsigned long __user *)(regs->ip + 12));
24193+ err |= get_user(stcclc, (unsigned char __user *)(regs->ip + 20));
24194+ err |= get_user(jmp1, (unsigned short __user *)(regs->ip + 21));
24195+ err |= get_user(jmp2, (unsigned char __user *)(regs->ip + 23));
24196+
24197+ if (err)
24198+ break;
24199+
24200+ if (mov1 == 0xBB49 && mov2 == 0xBA49 && (stcclc == 0xF8 || stcclc == 0xF9) && jmp1 == 0xFF49 && jmp2 == 0xE3) {
24201+ regs->r11 = addr1;
24202+ regs->r10 = addr2;
24203+ if (stcclc == 0xF8)
24204+ regs->flags &= ~X86_EFLAGS_CF;
24205+ else
24206+ regs->flags |= X86_EFLAGS_CF;
24207+ regs->ip = addr1;
24208+ return 2;
24209+ }
24210+ } while (0);
24211+
24212+ do { /* PaX: gcc trampoline emulation #1 */
24213+ unsigned short mov1, mov2, jmp1;
24214+ unsigned char jmp2;
24215+ unsigned int addr1;
24216+ unsigned long addr2;
24217+
24218+ err = get_user(mov1, (unsigned short __user *)regs->ip);
24219+ err |= get_user(addr1, (unsigned int __user *)(regs->ip + 2));
24220+ err |= get_user(mov2, (unsigned short __user *)(regs->ip + 6));
24221+ err |= get_user(addr2, (unsigned long __user *)(regs->ip + 8));
24222+ err |= get_user(jmp1, (unsigned short __user *)(regs->ip + 16));
24223+ err |= get_user(jmp2, (unsigned char __user *)(regs->ip + 18));
24224+
24225+ if (err)
24226+ break;
24227+
24228+ if (mov1 == 0xBB41 && mov2 == 0xBA49 && jmp1 == 0xFF49 && jmp2 == 0xE3) {
24229+ regs->r11 = addr1;
24230+ regs->r10 = addr2;
24231+ regs->ip = addr1;
24232+ return 2;
24233+ }
24234+ } while (0);
24235+
24236+ do { /* PaX: gcc trampoline emulation #2 */
24237+ unsigned short mov1, mov2, jmp1;
24238+ unsigned char jmp2;
24239+ unsigned long addr1, addr2;
24240+
24241+ err = get_user(mov1, (unsigned short __user *)regs->ip);
24242+ err |= get_user(addr1, (unsigned long __user *)(regs->ip + 2));
24243+ err |= get_user(mov2, (unsigned short __user *)(regs->ip + 10));
24244+ err |= get_user(addr2, (unsigned long __user *)(regs->ip + 12));
24245+ err |= get_user(jmp1, (unsigned short __user *)(regs->ip + 20));
24246+ err |= get_user(jmp2, (unsigned char __user *)(regs->ip + 22));
24247+
24248+ if (err)
24249+ break;
24250+
24251+ if (mov1 == 0xBB49 && mov2 == 0xBA49 && jmp1 == 0xFF49 && jmp2 == 0xE3) {
24252+ regs->r11 = addr1;
24253+ regs->r10 = addr2;
24254+ regs->ip = addr1;
24255+ return 2;
24256+ }
24257+ } while (0);
24258+
24259+ return 1; /* PaX in action */
24260+}
24261+#endif
24262+
24263+/*
24264+ * PaX: decide what to do with offenders (regs->ip = fault address)
24265+ *
24266+ * returns 1 when task should be killed
24267+ * 2 when gcc trampoline was detected
24268+ */
24269+static int pax_handle_fetch_fault(struct pt_regs *regs)
24270+{
24271+ if (v8086_mode(regs))
24272+ return 1;
24273+
24274+ if (!(current->mm->pax_flags & MF_PAX_EMUTRAMP))
24275+ return 1;
24276+
24277+#ifdef CONFIG_X86_32
24278+ return pax_handle_fetch_fault_32(regs);
24279+#else
24280+ if (regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT))
24281+ return pax_handle_fetch_fault_32(regs);
24282+ else
24283+ return pax_handle_fetch_fault_64(regs);
24284+#endif
24285+}
24286+#endif
24287+
24288+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
24289+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
24290+{
24291+ long i;
24292+
24293+ printk(KERN_ERR "PAX: bytes at PC: ");
24294+ for (i = 0; i < 20; i++) {
24295+ unsigned char c;
24296+ if (get_user(c, (unsigned char __force_user *)pc+i))
24297+ printk(KERN_CONT "?? ");
24298+ else
24299+ printk(KERN_CONT "%02x ", c);
24300+ }
24301+ printk("\n");
24302+
24303+ printk(KERN_ERR "PAX: bytes at SP-%lu: ", (unsigned long)sizeof(long));
24304+ for (i = -1; i < 80 / (long)sizeof(long); i++) {
24305+ unsigned long c;
24306+ if (get_user(c, (unsigned long __force_user *)sp+i)) {
24307+#ifdef CONFIG_X86_32
24308+ printk(KERN_CONT "???????? ");
24309+#else
24310+ if ((regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT)))
24311+ printk(KERN_CONT "???????? ???????? ");
24312+ else
24313+ printk(KERN_CONT "???????????????? ");
24314+#endif
24315+ } else {
24316+#ifdef CONFIG_X86_64
24317+ if ((regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT))) {
24318+ printk(KERN_CONT "%08x ", (unsigned int)c);
24319+ printk(KERN_CONT "%08x ", (unsigned int)(c >> 32));
24320+ } else
24321+#endif
24322+ printk(KERN_CONT "%0*lx ", 2 * (int)sizeof(long), c);
24323+ }
24324+ }
24325+ printk("\n");
24326+}
24327+#endif
24328+
24329+/**
24330+ * probe_kernel_write(): safely attempt to write to a location
24331+ * @dst: address to write to
24332+ * @src: pointer to the data that shall be written
24333+ * @size: size of the data chunk
24334+ *
24335+ * Safely write to address @dst from the buffer at @src. If a kernel fault
24336+ * happens, handle that and return -EFAULT.
24337+ */
24338+long notrace probe_kernel_write(void *dst, const void *src, size_t size)
24339+{
24340+ long ret;
24341+ mm_segment_t old_fs = get_fs();
24342+
24343+ set_fs(KERNEL_DS);
24344+ pagefault_disable();
24345+ pax_open_kernel();
24346+ ret = __copy_to_user_inatomic((void __force_user *)dst, src, size);
24347+ pax_close_kernel();
24348+ pagefault_enable();
24349+ set_fs(old_fs);
24350+
24351+ return ret ? -EFAULT : 0;
24352+}
24353diff --git a/arch/x86/mm/gup.c b/arch/x86/mm/gup.c
24354index dd74e46..7d26398 100644
24355--- a/arch/x86/mm/gup.c
24356+++ b/arch/x86/mm/gup.c
24357@@ -255,7 +255,7 @@ int __get_user_pages_fast(unsigned long start, int nr_pages, int write,
24358 addr = start;
24359 len = (unsigned long) nr_pages << PAGE_SHIFT;
24360 end = start + len;
24361- if (unlikely(!access_ok(write ? VERIFY_WRITE : VERIFY_READ,
24362+ if (unlikely(!__access_ok(write ? VERIFY_WRITE : VERIFY_READ,
24363 (void __user *)start, len)))
24364 return 0;
24365
24366diff --git a/arch/x86/mm/highmem_32.c b/arch/x86/mm/highmem_32.c
24367index 6f31ee5..8ee4164 100644
24368--- a/arch/x86/mm/highmem_32.c
24369+++ b/arch/x86/mm/highmem_32.c
24370@@ -44,7 +44,11 @@ void *kmap_atomic_prot(struct page *page, pgprot_t prot)
24371 idx = type + KM_TYPE_NR*smp_processor_id();
24372 vaddr = __fix_to_virt(FIX_KMAP_BEGIN + idx);
24373 BUG_ON(!pte_none(*(kmap_pte-idx)));
24374+
24375+ pax_open_kernel();
24376 set_pte(kmap_pte-idx, mk_pte(page, prot));
24377+ pax_close_kernel();
24378+
24379 arch_flush_lazy_mmu_mode();
24380
24381 return (void *)vaddr;
24382diff --git a/arch/x86/mm/hugetlbpage.c b/arch/x86/mm/hugetlbpage.c
24383index b91e485..d00e7c9 100644
24384--- a/arch/x86/mm/hugetlbpage.c
24385+++ b/arch/x86/mm/hugetlbpage.c
24386@@ -277,13 +277,20 @@ static unsigned long hugetlb_get_unmapped_area_bottomup(struct file *file,
24387 struct hstate *h = hstate_file(file);
24388 struct mm_struct *mm = current->mm;
24389 struct vm_area_struct *vma;
24390- unsigned long start_addr;
24391+ unsigned long start_addr, pax_task_size = TASK_SIZE;
24392+
24393+#ifdef CONFIG_PAX_SEGMEXEC
24394+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
24395+ pax_task_size = SEGMEXEC_TASK_SIZE;
24396+#endif
24397+
24398+ pax_task_size -= PAGE_SIZE;
24399
24400 if (len > mm->cached_hole_size) {
24401- start_addr = mm->free_area_cache;
24402+ start_addr = mm->free_area_cache;
24403 } else {
24404- start_addr = TASK_UNMAPPED_BASE;
24405- mm->cached_hole_size = 0;
24406+ start_addr = mm->mmap_base;
24407+ mm->cached_hole_size = 0;
24408 }
24409
24410 full_search:
24411@@ -291,26 +298,27 @@ full_search:
24412
24413 for (vma = find_vma(mm, addr); ; vma = vma->vm_next) {
24414 /* At this point: (!vma || addr < vma->vm_end). */
24415- if (TASK_SIZE - len < addr) {
24416+ if (pax_task_size - len < addr) {
24417 /*
24418 * Start a new search - just in case we missed
24419 * some holes.
24420 */
24421- if (start_addr != TASK_UNMAPPED_BASE) {
24422- start_addr = TASK_UNMAPPED_BASE;
24423+ if (start_addr != mm->mmap_base) {
24424+ start_addr = mm->mmap_base;
24425 mm->cached_hole_size = 0;
24426 goto full_search;
24427 }
24428 return -ENOMEM;
24429 }
24430- if (!vma || addr + len <= vma->vm_start) {
24431- mm->free_area_cache = addr + len;
24432- return addr;
24433- }
24434+ if (check_heap_stack_gap(vma, addr, len))
24435+ break;
24436 if (addr + mm->cached_hole_size < vma->vm_start)
24437 mm->cached_hole_size = vma->vm_start - addr;
24438 addr = ALIGN(vma->vm_end, huge_page_size(h));
24439 }
24440+
24441+ mm->free_area_cache = addr + len;
24442+ return addr;
24443 }
24444
24445 static unsigned long hugetlb_get_unmapped_area_topdown(struct file *file,
24446@@ -321,9 +329,8 @@ static unsigned long hugetlb_get_unmapped_area_topdown(struct file *file,
24447 struct mm_struct *mm = current->mm;
24448 struct vm_area_struct *vma;
24449 unsigned long base = mm->mmap_base;
24450- unsigned long addr = addr0;
24451+ unsigned long addr;
24452 unsigned long largest_hole = mm->cached_hole_size;
24453- unsigned long start_addr;
24454
24455 /* don't allow allocations above current base */
24456 if (mm->free_area_cache > base)
24457@@ -333,16 +340,15 @@ static unsigned long hugetlb_get_unmapped_area_topdown(struct file *file,
24458 largest_hole = 0;
24459 mm->free_area_cache = base;
24460 }
24461-try_again:
24462- start_addr = mm->free_area_cache;
24463
24464 /* make sure it can fit in the remaining address space */
24465 if (mm->free_area_cache < len)
24466 goto fail;
24467
24468 /* either no address requested or can't fit in requested address hole */
24469- addr = (mm->free_area_cache - len) & huge_page_mask(h);
24470+ addr = mm->free_area_cache - len;
24471 do {
24472+ addr &= huge_page_mask(h);
24473 /*
24474 * Lookup failure means no vma is above this address,
24475 * i.e. return with success:
24476@@ -351,10 +357,10 @@ try_again:
24477 if (!vma)
24478 return addr;
24479
24480- if (addr + len <= vma->vm_start) {
24481+ if (check_heap_stack_gap(vma, addr, len)) {
24482 /* remember the address as a hint for next time */
24483- mm->cached_hole_size = largest_hole;
24484- return (mm->free_area_cache = addr);
24485+ mm->cached_hole_size = largest_hole;
24486+ return (mm->free_area_cache = addr);
24487 } else if (mm->free_area_cache == vma->vm_end) {
24488 /* pull free_area_cache down to the first hole */
24489 mm->free_area_cache = vma->vm_start;
24490@@ -363,29 +369,34 @@ try_again:
24491
24492 /* remember the largest hole we saw so far */
24493 if (addr + largest_hole < vma->vm_start)
24494- largest_hole = vma->vm_start - addr;
24495+ largest_hole = vma->vm_start - addr;
24496
24497 /* try just below the current vma->vm_start */
24498- addr = (vma->vm_start - len) & huge_page_mask(h);
24499- } while (len <= vma->vm_start);
24500+ addr = skip_heap_stack_gap(vma, len);
24501+ } while (!IS_ERR_VALUE(addr));
24502
24503 fail:
24504 /*
24505- * if hint left us with no space for the requested
24506- * mapping then try again:
24507- */
24508- if (start_addr != base) {
24509- mm->free_area_cache = base;
24510- largest_hole = 0;
24511- goto try_again;
24512- }
24513- /*
24514 * A failed mmap() very likely causes application failure,
24515 * so fall back to the bottom-up function here. This scenario
24516 * can happen with large stack limits and large mmap()
24517 * allocations.
24518 */
24519- mm->free_area_cache = TASK_UNMAPPED_BASE;
24520+
24521+#ifdef CONFIG_PAX_SEGMEXEC
24522+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
24523+ mm->mmap_base = SEGMEXEC_TASK_UNMAPPED_BASE;
24524+ else
24525+#endif
24526+
24527+ mm->mmap_base = TASK_UNMAPPED_BASE;
24528+
24529+#ifdef CONFIG_PAX_RANDMMAP
24530+ if (mm->pax_flags & MF_PAX_RANDMMAP)
24531+ mm->mmap_base += mm->delta_mmap;
24532+#endif
24533+
24534+ mm->free_area_cache = mm->mmap_base;
24535 mm->cached_hole_size = ~0UL;
24536 addr = hugetlb_get_unmapped_area_bottomup(file, addr0,
24537 len, pgoff, flags);
24538@@ -393,6 +404,7 @@ fail:
24539 /*
24540 * Restore the topdown base:
24541 */
24542+ mm->mmap_base = base;
24543 mm->free_area_cache = base;
24544 mm->cached_hole_size = ~0UL;
24545
24546@@ -406,10 +418,19 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
24547 struct hstate *h = hstate_file(file);
24548 struct mm_struct *mm = current->mm;
24549 struct vm_area_struct *vma;
24550+ unsigned long pax_task_size = TASK_SIZE;
24551
24552 if (len & ~huge_page_mask(h))
24553 return -EINVAL;
24554- if (len > TASK_SIZE)
24555+
24556+#ifdef CONFIG_PAX_SEGMEXEC
24557+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
24558+ pax_task_size = SEGMEXEC_TASK_SIZE;
24559+#endif
24560+
24561+ pax_task_size -= PAGE_SIZE;
24562+
24563+ if (len > pax_task_size)
24564 return -ENOMEM;
24565
24566 if (flags & MAP_FIXED) {
24567@@ -421,8 +442,7 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
24568 if (addr) {
24569 addr = ALIGN(addr, huge_page_size(h));
24570 vma = find_vma(mm, addr);
24571- if (TASK_SIZE - len >= addr &&
24572- (!vma || addr + len <= vma->vm_start))
24573+ if (pax_task_size - len >= addr && check_heap_stack_gap(vma, addr, len))
24574 return addr;
24575 }
24576 if (mm->get_unmapped_area == arch_get_unmapped_area)
24577diff --git a/arch/x86/mm/init.c b/arch/x86/mm/init.c
24578index ab1f6a9..e16d764 100644
24579--- a/arch/x86/mm/init.c
24580+++ b/arch/x86/mm/init.c
24581@@ -16,6 +16,8 @@
24582 #include <asm/tlb.h>
24583 #include <asm/proto.h>
24584 #include <asm/dma.h> /* for MAX_DMA_PFN */
24585+#include <asm/desc.h>
24586+#include <asm/bios_ebda.h>
24587
24588 unsigned long __initdata pgt_buf_start;
24589 unsigned long __meminitdata pgt_buf_end;
24590@@ -38,7 +40,7 @@ struct map_range {
24591 static void __init find_early_table_space(struct map_range *mr, unsigned long end,
24592 int use_pse, int use_gbpages)
24593 {
24594- unsigned long puds, pmds, ptes, tables, start = 0, good_end = end;
24595+ unsigned long puds, pmds, ptes, tables, start = 0x100000, good_end = end;
24596 phys_addr_t base;
24597
24598 puds = (end + PUD_SIZE - 1) >> PUD_SHIFT;
24599@@ -317,10 +319,37 @@ unsigned long __init_refok init_memory_mapping(unsigned long start,
24600 * Access has to be given to non-kernel-ram areas as well, these contain the PCI
24601 * mmio resources as well as potential bios/acpi data regions.
24602 */
24603+
24604+#ifdef CONFIG_GRKERNSEC_KMEM
24605+static unsigned int ebda_start __read_only;
24606+static unsigned int ebda_end __read_only;
24607+#endif
24608+
24609 int devmem_is_allowed(unsigned long pagenr)
24610 {
24611- if (pagenr < 256)
24612+#ifdef CONFIG_GRKERNSEC_KMEM
24613+ /* allow BDA */
24614+ if (!pagenr)
24615 return 1;
24616+ /* allow EBDA */
24617+ if (pagenr >= ebda_start && pagenr < ebda_end)
24618+ return 1;
24619+#else
24620+ if (!pagenr)
24621+ return 1;
24622+#ifdef CONFIG_VM86
24623+ if (pagenr < (ISA_START_ADDRESS >> PAGE_SHIFT))
24624+ return 1;
24625+#endif
24626+#endif
24627+
24628+ if ((ISA_START_ADDRESS >> PAGE_SHIFT) <= pagenr && pagenr < (ISA_END_ADDRESS >> PAGE_SHIFT))
24629+ return 1;
24630+#ifdef CONFIG_GRKERNSEC_KMEM
24631+ /* throw out everything else below 1MB */
24632+ if (pagenr <= 256)
24633+ return 0;
24634+#endif
24635 if (iomem_is_exclusive(pagenr << PAGE_SHIFT))
24636 return 0;
24637 if (!page_is_ram(pagenr))
24638@@ -377,8 +406,116 @@ void free_init_pages(char *what, unsigned long begin, unsigned long end)
24639 #endif
24640 }
24641
24642+#ifdef CONFIG_GRKERNSEC_KMEM
24643+static inline void gr_init_ebda(void)
24644+{
24645+ unsigned int ebda_addr;
24646+ unsigned int ebda_size = 0;
24647+
24648+ ebda_addr = get_bios_ebda();
24649+ if (ebda_addr) {
24650+ ebda_size = *(unsigned char *)phys_to_virt(ebda_addr);
24651+ ebda_size <<= 10;
24652+ }
24653+ if (ebda_addr && ebda_size) {
24654+ ebda_start = ebda_addr >> PAGE_SHIFT;
24655+ ebda_end = min((unsigned int)PAGE_ALIGN(ebda_addr + ebda_size), (unsigned int)0xa0000) >> PAGE_SHIFT;
24656+ } else {
24657+ ebda_start = 0x9f000 >> PAGE_SHIFT;
24658+ ebda_end = 0xa0000 >> PAGE_SHIFT;
24659+ }
24660+}
24661+#else
24662+static inline void gr_init_ebda(void) { }
24663+#endif
24664+
24665 void free_initmem(void)
24666 {
24667+#ifdef CONFIG_PAX_KERNEXEC
24668+#ifdef CONFIG_X86_32
24669+ /* PaX: limit KERNEL_CS to actual size */
24670+ unsigned long addr, limit;
24671+ struct desc_struct d;
24672+ int cpu;
24673+#else
24674+ pgd_t *pgd;
24675+ pud_t *pud;
24676+ pmd_t *pmd;
24677+ unsigned long addr, end;
24678+#endif
24679+#endif
24680+
24681+ gr_init_ebda();
24682+
24683+#ifdef CONFIG_PAX_KERNEXEC
24684+#ifdef CONFIG_X86_32
24685+ limit = paravirt_enabled() ? ktva_ktla(0xffffffff) : (unsigned long)&_etext;
24686+ limit = (limit - 1UL) >> PAGE_SHIFT;
24687+
24688+ memset(__LOAD_PHYSICAL_ADDR + PAGE_OFFSET, POISON_FREE_INITMEM, PAGE_SIZE);
24689+ for (cpu = 0; cpu < nr_cpu_ids; cpu++) {
24690+ pack_descriptor(&d, get_desc_base(&get_cpu_gdt_table(cpu)[GDT_ENTRY_KERNEL_CS]), limit, 0x9B, 0xC);
24691+ write_gdt_entry(get_cpu_gdt_table(cpu), GDT_ENTRY_KERNEL_CS, &d, DESCTYPE_S);
24692+ }
24693+
24694+ /* PaX: make KERNEL_CS read-only */
24695+ addr = PFN_ALIGN(ktla_ktva((unsigned long)&_text));
24696+ if (!paravirt_enabled())
24697+ set_memory_ro(addr, (PFN_ALIGN(_sdata) - addr) >> PAGE_SHIFT);
24698+/*
24699+ for (addr = ktla_ktva((unsigned long)&_text); addr < (unsigned long)&_sdata; addr += PMD_SIZE) {
24700+ pgd = pgd_offset_k(addr);
24701+ pud = pud_offset(pgd, addr);
24702+ pmd = pmd_offset(pud, addr);
24703+ set_pmd(pmd, __pmd(pmd_val(*pmd) & ~_PAGE_RW));
24704+ }
24705+*/
24706+#ifdef CONFIG_X86_PAE
24707+ set_memory_nx(PFN_ALIGN(__init_begin), (PFN_ALIGN(__init_end) - PFN_ALIGN(__init_begin)) >> PAGE_SHIFT);
24708+/*
24709+ for (addr = (unsigned long)&__init_begin; addr < (unsigned long)&__init_end; addr += PMD_SIZE) {
24710+ pgd = pgd_offset_k(addr);
24711+ pud = pud_offset(pgd, addr);
24712+ pmd = pmd_offset(pud, addr);
24713+ set_pmd(pmd, __pmd(pmd_val(*pmd) | (_PAGE_NX & __supported_pte_mask)));
24714+ }
24715+*/
24716+#endif
24717+
24718+#ifdef CONFIG_MODULES
24719+ set_memory_4k((unsigned long)MODULES_EXEC_VADDR, (MODULES_EXEC_END - MODULES_EXEC_VADDR) >> PAGE_SHIFT);
24720+#endif
24721+
24722+#else
24723+ /* PaX: make kernel code/rodata read-only, rest non-executable */
24724+ for (addr = __START_KERNEL_map; addr < __START_KERNEL_map + KERNEL_IMAGE_SIZE; addr += PMD_SIZE) {
24725+ pgd = pgd_offset_k(addr);
24726+ pud = pud_offset(pgd, addr);
24727+ pmd = pmd_offset(pud, addr);
24728+ if (!pmd_present(*pmd))
24729+ continue;
24730+ if ((unsigned long)_text <= addr && addr < (unsigned long)_sdata)
24731+ set_pmd(pmd, __pmd(pmd_val(*pmd) & ~_PAGE_RW));
24732+ else
24733+ set_pmd(pmd, __pmd(pmd_val(*pmd) | (_PAGE_NX & __supported_pte_mask)));
24734+ }
24735+
24736+ addr = (unsigned long)__va(__pa(__START_KERNEL_map));
24737+ end = addr + KERNEL_IMAGE_SIZE;
24738+ for (; addr < end; addr += PMD_SIZE) {
24739+ pgd = pgd_offset_k(addr);
24740+ pud = pud_offset(pgd, addr);
24741+ pmd = pmd_offset(pud, addr);
24742+ if (!pmd_present(*pmd))
24743+ continue;
24744+ if ((unsigned long)__va(__pa(_text)) <= addr && addr < (unsigned long)__va(__pa(_sdata)))
24745+ set_pmd(pmd, __pmd(pmd_val(*pmd) & ~_PAGE_RW));
24746+ }
24747+#endif
24748+
24749+ flush_tlb_all();
24750+#endif
24751+
24752 free_init_pages("unused kernel memory",
24753 (unsigned long)(&__init_begin),
24754 (unsigned long)(&__init_end));
24755diff --git a/arch/x86/mm/init_32.c b/arch/x86/mm/init_32.c
24756index 575d86f..4987469 100644
24757--- a/arch/x86/mm/init_32.c
24758+++ b/arch/x86/mm/init_32.c
24759@@ -73,36 +73,6 @@ static __init void *alloc_low_page(void)
24760 }
24761
24762 /*
24763- * Creates a middle page table and puts a pointer to it in the
24764- * given global directory entry. This only returns the gd entry
24765- * in non-PAE compilation mode, since the middle layer is folded.
24766- */
24767-static pmd_t * __init one_md_table_init(pgd_t *pgd)
24768-{
24769- pud_t *pud;
24770- pmd_t *pmd_table;
24771-
24772-#ifdef CONFIG_X86_PAE
24773- if (!(pgd_val(*pgd) & _PAGE_PRESENT)) {
24774- if (after_bootmem)
24775- pmd_table = (pmd_t *)alloc_bootmem_pages(PAGE_SIZE);
24776- else
24777- pmd_table = (pmd_t *)alloc_low_page();
24778- paravirt_alloc_pmd(&init_mm, __pa(pmd_table) >> PAGE_SHIFT);
24779- set_pgd(pgd, __pgd(__pa(pmd_table) | _PAGE_PRESENT));
24780- pud = pud_offset(pgd, 0);
24781- BUG_ON(pmd_table != pmd_offset(pud, 0));
24782-
24783- return pmd_table;
24784- }
24785-#endif
24786- pud = pud_offset(pgd, 0);
24787- pmd_table = pmd_offset(pud, 0);
24788-
24789- return pmd_table;
24790-}
24791-
24792-/*
24793 * Create a page table and place a pointer to it in a middle page
24794 * directory entry:
24795 */
24796@@ -122,13 +92,28 @@ static pte_t * __init one_page_table_init(pmd_t *pmd)
24797 page_table = (pte_t *)alloc_low_page();
24798
24799 paravirt_alloc_pte(&init_mm, __pa(page_table) >> PAGE_SHIFT);
24800+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
24801+ set_pmd(pmd, __pmd(__pa(page_table) | _KERNPG_TABLE));
24802+#else
24803 set_pmd(pmd, __pmd(__pa(page_table) | _PAGE_TABLE));
24804+#endif
24805 BUG_ON(page_table != pte_offset_kernel(pmd, 0));
24806 }
24807
24808 return pte_offset_kernel(pmd, 0);
24809 }
24810
24811+static pmd_t * __init one_md_table_init(pgd_t *pgd)
24812+{
24813+ pud_t *pud;
24814+ pmd_t *pmd_table;
24815+
24816+ pud = pud_offset(pgd, 0);
24817+ pmd_table = pmd_offset(pud, 0);
24818+
24819+ return pmd_table;
24820+}
24821+
24822 pmd_t * __init populate_extra_pmd(unsigned long vaddr)
24823 {
24824 int pgd_idx = pgd_index(vaddr);
24825@@ -202,6 +187,7 @@ page_table_range_init(unsigned long start, unsigned long end, pgd_t *pgd_base)
24826 int pgd_idx, pmd_idx;
24827 unsigned long vaddr;
24828 pgd_t *pgd;
24829+ pud_t *pud;
24830 pmd_t *pmd;
24831 pte_t *pte = NULL;
24832
24833@@ -211,8 +197,13 @@ page_table_range_init(unsigned long start, unsigned long end, pgd_t *pgd_base)
24834 pgd = pgd_base + pgd_idx;
24835
24836 for ( ; (pgd_idx < PTRS_PER_PGD) && (vaddr != end); pgd++, pgd_idx++) {
24837- pmd = one_md_table_init(pgd);
24838- pmd = pmd + pmd_index(vaddr);
24839+ pud = pud_offset(pgd, vaddr);
24840+ pmd = pmd_offset(pud, vaddr);
24841+
24842+#ifdef CONFIG_X86_PAE
24843+ paravirt_alloc_pmd(&init_mm, __pa(pmd) >> PAGE_SHIFT);
24844+#endif
24845+
24846 for (; (pmd_idx < PTRS_PER_PMD) && (vaddr != end);
24847 pmd++, pmd_idx++) {
24848 pte = page_table_kmap_check(one_page_table_init(pmd),
24849@@ -224,11 +215,20 @@ page_table_range_init(unsigned long start, unsigned long end, pgd_t *pgd_base)
24850 }
24851 }
24852
24853-static inline int is_kernel_text(unsigned long addr)
24854+static inline int is_kernel_text(unsigned long start, unsigned long end)
24855 {
24856- if (addr >= (unsigned long)_text && addr <= (unsigned long)__init_end)
24857- return 1;
24858- return 0;
24859+ if ((start > ktla_ktva((unsigned long)_etext) ||
24860+ end <= ktla_ktva((unsigned long)_stext)) &&
24861+ (start > ktla_ktva((unsigned long)_einittext) ||
24862+ end <= ktla_ktva((unsigned long)_sinittext)) &&
24863+
24864+#ifdef CONFIG_ACPI_SLEEP
24865+ (start > (unsigned long)__va(acpi_wakeup_address) + 0x4000 || end <= (unsigned long)__va(acpi_wakeup_address)) &&
24866+#endif
24867+
24868+ (start > (unsigned long)__va(0xfffff) || end <= (unsigned long)__va(0xc0000)))
24869+ return 0;
24870+ return 1;
24871 }
24872
24873 /*
24874@@ -245,9 +245,10 @@ kernel_physical_mapping_init(unsigned long start,
24875 unsigned long last_map_addr = end;
24876 unsigned long start_pfn, end_pfn;
24877 pgd_t *pgd_base = swapper_pg_dir;
24878- int pgd_idx, pmd_idx, pte_ofs;
24879+ unsigned int pgd_idx, pmd_idx, pte_ofs;
24880 unsigned long pfn;
24881 pgd_t *pgd;
24882+ pud_t *pud;
24883 pmd_t *pmd;
24884 pte_t *pte;
24885 unsigned pages_2m, pages_4k;
24886@@ -280,8 +281,13 @@ repeat:
24887 pfn = start_pfn;
24888 pgd_idx = pgd_index((pfn<<PAGE_SHIFT) + PAGE_OFFSET);
24889 pgd = pgd_base + pgd_idx;
24890- for (; pgd_idx < PTRS_PER_PGD; pgd++, pgd_idx++) {
24891- pmd = one_md_table_init(pgd);
24892+ for (; pgd_idx < PTRS_PER_PGD && pfn < max_low_pfn; pgd++, pgd_idx++) {
24893+ pud = pud_offset(pgd, 0);
24894+ pmd = pmd_offset(pud, 0);
24895+
24896+#ifdef CONFIG_X86_PAE
24897+ paravirt_alloc_pmd(&init_mm, __pa(pmd) >> PAGE_SHIFT);
24898+#endif
24899
24900 if (pfn >= end_pfn)
24901 continue;
24902@@ -293,14 +299,13 @@ repeat:
24903 #endif
24904 for (; pmd_idx < PTRS_PER_PMD && pfn < end_pfn;
24905 pmd++, pmd_idx++) {
24906- unsigned int addr = pfn * PAGE_SIZE + PAGE_OFFSET;
24907+ unsigned long address = pfn * PAGE_SIZE + PAGE_OFFSET;
24908
24909 /*
24910 * Map with big pages if possible, otherwise
24911 * create normal page tables:
24912 */
24913 if (use_pse) {
24914- unsigned int addr2;
24915 pgprot_t prot = PAGE_KERNEL_LARGE;
24916 /*
24917 * first pass will use the same initial
24918@@ -310,11 +315,7 @@ repeat:
24919 __pgprot(PTE_IDENT_ATTR |
24920 _PAGE_PSE);
24921
24922- addr2 = (pfn + PTRS_PER_PTE-1) * PAGE_SIZE +
24923- PAGE_OFFSET + PAGE_SIZE-1;
24924-
24925- if (is_kernel_text(addr) ||
24926- is_kernel_text(addr2))
24927+ if (is_kernel_text(address, address + PMD_SIZE))
24928 prot = PAGE_KERNEL_LARGE_EXEC;
24929
24930 pages_2m++;
24931@@ -331,7 +332,7 @@ repeat:
24932 pte_ofs = pte_index((pfn<<PAGE_SHIFT) + PAGE_OFFSET);
24933 pte += pte_ofs;
24934 for (; pte_ofs < PTRS_PER_PTE && pfn < end_pfn;
24935- pte++, pfn++, pte_ofs++, addr += PAGE_SIZE) {
24936+ pte++, pfn++, pte_ofs++, address += PAGE_SIZE) {
24937 pgprot_t prot = PAGE_KERNEL;
24938 /*
24939 * first pass will use the same initial
24940@@ -339,7 +340,7 @@ repeat:
24941 */
24942 pgprot_t init_prot = __pgprot(PTE_IDENT_ATTR);
24943
24944- if (is_kernel_text(addr))
24945+ if (is_kernel_text(address, address + PAGE_SIZE))
24946 prot = PAGE_KERNEL_EXEC;
24947
24948 pages_4k++;
24949@@ -465,7 +466,7 @@ void __init native_pagetable_setup_start(pgd_t *base)
24950
24951 pud = pud_offset(pgd, va);
24952 pmd = pmd_offset(pud, va);
24953- if (!pmd_present(*pmd))
24954+ if (!pmd_present(*pmd) || pmd_huge(*pmd))
24955 break;
24956
24957 pte = pte_offset_kernel(pmd, va);
24958@@ -517,12 +518,10 @@ void __init early_ioremap_page_table_range_init(void)
24959
24960 static void __init pagetable_init(void)
24961 {
24962- pgd_t *pgd_base = swapper_pg_dir;
24963-
24964- permanent_kmaps_init(pgd_base);
24965+ permanent_kmaps_init(swapper_pg_dir);
24966 }
24967
24968-pteval_t __supported_pte_mask __read_mostly = ~(_PAGE_NX | _PAGE_GLOBAL | _PAGE_IOMAP);
24969+pteval_t __supported_pte_mask __read_only = ~(_PAGE_NX | _PAGE_GLOBAL | _PAGE_IOMAP);
24970 EXPORT_SYMBOL_GPL(__supported_pte_mask);
24971
24972 /* user-defined highmem size */
24973@@ -734,6 +733,12 @@ void __init mem_init(void)
24974
24975 pci_iommu_alloc();
24976
24977+#ifdef CONFIG_PAX_PER_CPU_PGD
24978+ clone_pgd_range(get_cpu_pgd(0) + KERNEL_PGD_BOUNDARY,
24979+ swapper_pg_dir + KERNEL_PGD_BOUNDARY,
24980+ KERNEL_PGD_PTRS);
24981+#endif
24982+
24983 #ifdef CONFIG_FLATMEM
24984 BUG_ON(!mem_map);
24985 #endif
24986@@ -760,7 +765,7 @@ void __init mem_init(void)
24987 reservedpages++;
24988
24989 codesize = (unsigned long) &_etext - (unsigned long) &_text;
24990- datasize = (unsigned long) &_edata - (unsigned long) &_etext;
24991+ datasize = (unsigned long) &_edata - (unsigned long) &_sdata;
24992 initsize = (unsigned long) &__init_end - (unsigned long) &__init_begin;
24993
24994 printk(KERN_INFO "Memory: %luk/%luk available (%dk kernel code, "
24995@@ -801,10 +806,10 @@ void __init mem_init(void)
24996 ((unsigned long)&__init_end -
24997 (unsigned long)&__init_begin) >> 10,
24998
24999- (unsigned long)&_etext, (unsigned long)&_edata,
25000- ((unsigned long)&_edata - (unsigned long)&_etext) >> 10,
25001+ (unsigned long)&_sdata, (unsigned long)&_edata,
25002+ ((unsigned long)&_edata - (unsigned long)&_sdata) >> 10,
25003
25004- (unsigned long)&_text, (unsigned long)&_etext,
25005+ ktla_ktva((unsigned long)&_text), ktla_ktva((unsigned long)&_etext),
25006 ((unsigned long)&_etext - (unsigned long)&_text) >> 10);
25007
25008 /*
25009@@ -882,6 +887,7 @@ void set_kernel_text_rw(void)
25010 if (!kernel_set_to_readonly)
25011 return;
25012
25013+ start = ktla_ktva(start);
25014 pr_debug("Set kernel text: %lx - %lx for read write\n",
25015 start, start+size);
25016
25017@@ -896,6 +902,7 @@ void set_kernel_text_ro(void)
25018 if (!kernel_set_to_readonly)
25019 return;
25020
25021+ start = ktla_ktva(start);
25022 pr_debug("Set kernel text: %lx - %lx for read only\n",
25023 start, start+size);
25024
25025@@ -924,6 +931,7 @@ void mark_rodata_ro(void)
25026 unsigned long start = PFN_ALIGN(_text);
25027 unsigned long size = PFN_ALIGN(_etext) - start;
25028
25029+ start = ktla_ktva(start);
25030 set_pages_ro(virt_to_page(start), size >> PAGE_SHIFT);
25031 printk(KERN_INFO "Write protecting the kernel text: %luk\n",
25032 size >> 10);
25033diff --git a/arch/x86/mm/init_64.c b/arch/x86/mm/init_64.c
25034index 2b6b4a3..c17210d 100644
25035--- a/arch/x86/mm/init_64.c
25036+++ b/arch/x86/mm/init_64.c
25037@@ -74,7 +74,7 @@ early_param("gbpages", parse_direct_gbpages_on);
25038 * around without checking the pgd every time.
25039 */
25040
25041-pteval_t __supported_pte_mask __read_mostly = ~_PAGE_IOMAP;
25042+pteval_t __supported_pte_mask __read_only = ~(_PAGE_NX | _PAGE_IOMAP);
25043 EXPORT_SYMBOL_GPL(__supported_pte_mask);
25044
25045 int force_personality32;
25046@@ -107,12 +107,22 @@ void sync_global_pgds(unsigned long start, unsigned long end)
25047
25048 for (address = start; address <= end; address += PGDIR_SIZE) {
25049 const pgd_t *pgd_ref = pgd_offset_k(address);
25050+
25051+#ifdef CONFIG_PAX_PER_CPU_PGD
25052+ unsigned long cpu;
25053+#else
25054 struct page *page;
25055+#endif
25056
25057 if (pgd_none(*pgd_ref))
25058 continue;
25059
25060 spin_lock(&pgd_lock);
25061+
25062+#ifdef CONFIG_PAX_PER_CPU_PGD
25063+ for (cpu = 0; cpu < nr_cpu_ids; ++cpu) {
25064+ pgd_t *pgd = pgd_offset_cpu(cpu, address);
25065+#else
25066 list_for_each_entry(page, &pgd_list, lru) {
25067 pgd_t *pgd;
25068 spinlock_t *pgt_lock;
25069@@ -121,6 +131,7 @@ void sync_global_pgds(unsigned long start, unsigned long end)
25070 /* the pgt_lock only for Xen */
25071 pgt_lock = &pgd_page_get_mm(page)->page_table_lock;
25072 spin_lock(pgt_lock);
25073+#endif
25074
25075 if (pgd_none(*pgd))
25076 set_pgd(pgd, *pgd_ref);
25077@@ -128,7 +139,10 @@ void sync_global_pgds(unsigned long start, unsigned long end)
25078 BUG_ON(pgd_page_vaddr(*pgd)
25079 != pgd_page_vaddr(*pgd_ref));
25080
25081+#ifndef CONFIG_PAX_PER_CPU_PGD
25082 spin_unlock(pgt_lock);
25083+#endif
25084+
25085 }
25086 spin_unlock(&pgd_lock);
25087 }
25088@@ -161,7 +175,7 @@ static pud_t *fill_pud(pgd_t *pgd, unsigned long vaddr)
25089 {
25090 if (pgd_none(*pgd)) {
25091 pud_t *pud = (pud_t *)spp_getpage();
25092- pgd_populate(&init_mm, pgd, pud);
25093+ pgd_populate_kernel(&init_mm, pgd, pud);
25094 if (pud != pud_offset(pgd, 0))
25095 printk(KERN_ERR "PAGETABLE BUG #00! %p <-> %p\n",
25096 pud, pud_offset(pgd, 0));
25097@@ -173,7 +187,7 @@ static pmd_t *fill_pmd(pud_t *pud, unsigned long vaddr)
25098 {
25099 if (pud_none(*pud)) {
25100 pmd_t *pmd = (pmd_t *) spp_getpage();
25101- pud_populate(&init_mm, pud, pmd);
25102+ pud_populate_kernel(&init_mm, pud, pmd);
25103 if (pmd != pmd_offset(pud, 0))
25104 printk(KERN_ERR "PAGETABLE BUG #01! %p <-> %p\n",
25105 pmd, pmd_offset(pud, 0));
25106@@ -202,7 +216,9 @@ void set_pte_vaddr_pud(pud_t *pud_page, unsigned long vaddr, pte_t new_pte)
25107 pmd = fill_pmd(pud, vaddr);
25108 pte = fill_pte(pmd, vaddr);
25109
25110+ pax_open_kernel();
25111 set_pte(pte, new_pte);
25112+ pax_close_kernel();
25113
25114 /*
25115 * It's enough to flush this one mapping.
25116@@ -261,14 +277,12 @@ static void __init __init_extra_mapping(unsigned long phys, unsigned long size,
25117 pgd = pgd_offset_k((unsigned long)__va(phys));
25118 if (pgd_none(*pgd)) {
25119 pud = (pud_t *) spp_getpage();
25120- set_pgd(pgd, __pgd(__pa(pud) | _KERNPG_TABLE |
25121- _PAGE_USER));
25122+ set_pgd(pgd, __pgd(__pa(pud) | _PAGE_TABLE));
25123 }
25124 pud = pud_offset(pgd, (unsigned long)__va(phys));
25125 if (pud_none(*pud)) {
25126 pmd = (pmd_t *) spp_getpage();
25127- set_pud(pud, __pud(__pa(pmd) | _KERNPG_TABLE |
25128- _PAGE_USER));
25129+ set_pud(pud, __pud(__pa(pmd) | _PAGE_TABLE));
25130 }
25131 pmd = pmd_offset(pud, phys);
25132 BUG_ON(!pmd_none(*pmd));
25133@@ -329,7 +343,7 @@ static __ref void *alloc_low_page(unsigned long *phys)
25134 if (pfn >= pgt_buf_top)
25135 panic("alloc_low_page: ran out of memory");
25136
25137- adr = early_memremap(pfn * PAGE_SIZE, PAGE_SIZE);
25138+ adr = (void __force_kernel *)early_memremap(pfn * PAGE_SIZE, PAGE_SIZE);
25139 clear_page(adr);
25140 *phys = pfn * PAGE_SIZE;
25141 return adr;
25142@@ -345,7 +359,7 @@ static __ref void *map_low_page(void *virt)
25143
25144 phys = __pa(virt);
25145 left = phys & (PAGE_SIZE - 1);
25146- adr = early_memremap(phys & PAGE_MASK, PAGE_SIZE);
25147+ adr = (void __force_kernel *)early_memremap(phys & PAGE_MASK, PAGE_SIZE);
25148 adr = (void *)(((unsigned long)adr) | left);
25149
25150 return adr;
25151@@ -548,7 +562,7 @@ phys_pud_init(pud_t *pud_page, unsigned long addr, unsigned long end,
25152 unmap_low_page(pmd);
25153
25154 spin_lock(&init_mm.page_table_lock);
25155- pud_populate(&init_mm, pud, __va(pmd_phys));
25156+ pud_populate_kernel(&init_mm, pud, __va(pmd_phys));
25157 spin_unlock(&init_mm.page_table_lock);
25158 }
25159 __flush_tlb_all();
25160@@ -594,7 +608,7 @@ kernel_physical_mapping_init(unsigned long start,
25161 unmap_low_page(pud);
25162
25163 spin_lock(&init_mm.page_table_lock);
25164- pgd_populate(&init_mm, pgd, __va(pud_phys));
25165+ pgd_populate_kernel(&init_mm, pgd, __va(pud_phys));
25166 spin_unlock(&init_mm.page_table_lock);
25167 pgd_changed = true;
25168 }
25169@@ -686,6 +700,12 @@ void __init mem_init(void)
25170
25171 pci_iommu_alloc();
25172
25173+#ifdef CONFIG_PAX_PER_CPU_PGD
25174+ clone_pgd_range(get_cpu_pgd(0) + KERNEL_PGD_BOUNDARY,
25175+ swapper_pg_dir + KERNEL_PGD_BOUNDARY,
25176+ KERNEL_PGD_PTRS);
25177+#endif
25178+
25179 /* clear_bss() already clear the empty_zero_page */
25180
25181 reservedpages = 0;
25182@@ -846,8 +866,8 @@ int kern_addr_valid(unsigned long addr)
25183 static struct vm_area_struct gate_vma = {
25184 .vm_start = VSYSCALL_START,
25185 .vm_end = VSYSCALL_START + (VSYSCALL_MAPPED_PAGES * PAGE_SIZE),
25186- .vm_page_prot = PAGE_READONLY_EXEC,
25187- .vm_flags = VM_READ | VM_EXEC
25188+ .vm_page_prot = PAGE_READONLY,
25189+ .vm_flags = VM_READ
25190 };
25191
25192 struct vm_area_struct *get_gate_vma(struct mm_struct *mm)
25193@@ -881,7 +901,7 @@ int in_gate_area_no_mm(unsigned long addr)
25194
25195 const char *arch_vma_name(struct vm_area_struct *vma)
25196 {
25197- if (vma->vm_mm && vma->vm_start == (long)vma->vm_mm->context.vdso)
25198+ if (vma->vm_mm && vma->vm_start == vma->vm_mm->context.vdso)
25199 return "[vdso]";
25200 if (vma == &gate_vma)
25201 return "[vsyscall]";
25202diff --git a/arch/x86/mm/iomap_32.c b/arch/x86/mm/iomap_32.c
25203index 7b179b4..6bd1777 100644
25204--- a/arch/x86/mm/iomap_32.c
25205+++ b/arch/x86/mm/iomap_32.c
25206@@ -64,7 +64,11 @@ void *kmap_atomic_prot_pfn(unsigned long pfn, pgprot_t prot)
25207 type = kmap_atomic_idx_push();
25208 idx = type + KM_TYPE_NR * smp_processor_id();
25209 vaddr = __fix_to_virt(FIX_KMAP_BEGIN + idx);
25210+
25211+ pax_open_kernel();
25212 set_pte(kmap_pte - idx, pfn_pte(pfn, prot));
25213+ pax_close_kernel();
25214+
25215 arch_flush_lazy_mmu_mode();
25216
25217 return (void *)vaddr;
25218diff --git a/arch/x86/mm/ioremap.c b/arch/x86/mm/ioremap.c
25219index 78fe3f1..8293b6f 100644
25220--- a/arch/x86/mm/ioremap.c
25221+++ b/arch/x86/mm/ioremap.c
25222@@ -97,7 +97,7 @@ static void __iomem *__ioremap_caller(resource_size_t phys_addr,
25223 for (pfn = phys_addr >> PAGE_SHIFT; pfn <= last_pfn; pfn++) {
25224 int is_ram = page_is_ram(pfn);
25225
25226- if (is_ram && pfn_valid(pfn) && !PageReserved(pfn_to_page(pfn)))
25227+ if (is_ram && pfn_valid(pfn) && (pfn >= 0x100 || !PageReserved(pfn_to_page(pfn))))
25228 return NULL;
25229 WARN_ON_ONCE(is_ram);
25230 }
25231@@ -315,6 +315,9 @@ void *xlate_dev_mem_ptr(unsigned long phys)
25232
25233 /* If page is RAM, we can use __va. Otherwise ioremap and unmap. */
25234 if (page_is_ram(start >> PAGE_SHIFT))
25235+#ifdef CONFIG_HIGHMEM
25236+ if ((start >> PAGE_SHIFT) < max_low_pfn)
25237+#endif
25238 return __va(phys);
25239
25240 addr = (void __force *)ioremap_cache(start, PAGE_SIZE);
25241@@ -344,7 +347,7 @@ static int __init early_ioremap_debug_setup(char *str)
25242 early_param("early_ioremap_debug", early_ioremap_debug_setup);
25243
25244 static __initdata int after_paging_init;
25245-static pte_t bm_pte[PAGE_SIZE/sizeof(pte_t)] __page_aligned_bss;
25246+static pte_t bm_pte[PAGE_SIZE/sizeof(pte_t)] __read_only __aligned(PAGE_SIZE);
25247
25248 static inline pmd_t * __init early_ioremap_pmd(unsigned long addr)
25249 {
25250@@ -381,8 +384,7 @@ void __init early_ioremap_init(void)
25251 slot_virt[i] = __fix_to_virt(FIX_BTMAP_BEGIN - NR_FIX_BTMAPS*i);
25252
25253 pmd = early_ioremap_pmd(fix_to_virt(FIX_BTMAP_BEGIN));
25254- memset(bm_pte, 0, sizeof(bm_pte));
25255- pmd_populate_kernel(&init_mm, pmd, bm_pte);
25256+ pmd_populate_user(&init_mm, pmd, bm_pte);
25257
25258 /*
25259 * The boot-ioremap range spans multiple pmds, for which
25260diff --git a/arch/x86/mm/kmemcheck/kmemcheck.c b/arch/x86/mm/kmemcheck/kmemcheck.c
25261index d87dd6d..bf3fa66 100644
25262--- a/arch/x86/mm/kmemcheck/kmemcheck.c
25263+++ b/arch/x86/mm/kmemcheck/kmemcheck.c
25264@@ -622,9 +622,9 @@ bool kmemcheck_fault(struct pt_regs *regs, unsigned long address,
25265 * memory (e.g. tracked pages)? For now, we need this to avoid
25266 * invoking kmemcheck for PnP BIOS calls.
25267 */
25268- if (regs->flags & X86_VM_MASK)
25269+ if (v8086_mode(regs))
25270 return false;
25271- if (regs->cs != __KERNEL_CS)
25272+ if (regs->cs != __KERNEL_CS && regs->cs != __KERNEXEC_KERNEL_CS)
25273 return false;
25274
25275 pte = kmemcheck_pte_lookup(address);
25276diff --git a/arch/x86/mm/mmap.c b/arch/x86/mm/mmap.c
25277index 845df68..1d8d29f 100644
25278--- a/arch/x86/mm/mmap.c
25279+++ b/arch/x86/mm/mmap.c
25280@@ -52,7 +52,7 @@ static unsigned int stack_maxrandom_size(void)
25281 * Leave an at least ~128 MB hole with possible stack randomization.
25282 */
25283 #define MIN_GAP (128*1024*1024UL + stack_maxrandom_size())
25284-#define MAX_GAP (TASK_SIZE/6*5)
25285+#define MAX_GAP (pax_task_size/6*5)
25286
25287 static int mmap_is_legacy(void)
25288 {
25289@@ -82,27 +82,40 @@ static unsigned long mmap_rnd(void)
25290 return rnd << PAGE_SHIFT;
25291 }
25292
25293-static unsigned long mmap_base(void)
25294+static unsigned long mmap_base(struct mm_struct *mm)
25295 {
25296 unsigned long gap = rlimit(RLIMIT_STACK);
25297+ unsigned long pax_task_size = TASK_SIZE;
25298+
25299+#ifdef CONFIG_PAX_SEGMEXEC
25300+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
25301+ pax_task_size = SEGMEXEC_TASK_SIZE;
25302+#endif
25303
25304 if (gap < MIN_GAP)
25305 gap = MIN_GAP;
25306 else if (gap > MAX_GAP)
25307 gap = MAX_GAP;
25308
25309- return PAGE_ALIGN(TASK_SIZE - gap - mmap_rnd());
25310+ return PAGE_ALIGN(pax_task_size - gap - mmap_rnd());
25311 }
25312
25313 /*
25314 * Bottom-up (legacy) layout on X86_32 did not support randomization, X86_64
25315 * does, but not when emulating X86_32
25316 */
25317-static unsigned long mmap_legacy_base(void)
25318+static unsigned long mmap_legacy_base(struct mm_struct *mm)
25319 {
25320- if (mmap_is_ia32())
25321+ if (mmap_is_ia32()) {
25322+
25323+#ifdef CONFIG_PAX_SEGMEXEC
25324+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
25325+ return SEGMEXEC_TASK_UNMAPPED_BASE;
25326+ else
25327+#endif
25328+
25329 return TASK_UNMAPPED_BASE;
25330- else
25331+ } else
25332 return TASK_UNMAPPED_BASE + mmap_rnd();
25333 }
25334
25335@@ -113,11 +126,23 @@ static unsigned long mmap_legacy_base(void)
25336 void arch_pick_mmap_layout(struct mm_struct *mm)
25337 {
25338 if (mmap_is_legacy()) {
25339- mm->mmap_base = mmap_legacy_base();
25340+ mm->mmap_base = mmap_legacy_base(mm);
25341+
25342+#ifdef CONFIG_PAX_RANDMMAP
25343+ if (mm->pax_flags & MF_PAX_RANDMMAP)
25344+ mm->mmap_base += mm->delta_mmap;
25345+#endif
25346+
25347 mm->get_unmapped_area = arch_get_unmapped_area;
25348 mm->unmap_area = arch_unmap_area;
25349 } else {
25350- mm->mmap_base = mmap_base();
25351+ mm->mmap_base = mmap_base(mm);
25352+
25353+#ifdef CONFIG_PAX_RANDMMAP
25354+ if (mm->pax_flags & MF_PAX_RANDMMAP)
25355+ mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
25356+#endif
25357+
25358 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
25359 mm->unmap_area = arch_unmap_area_topdown;
25360 }
25361diff --git a/arch/x86/mm/mmio-mod.c b/arch/x86/mm/mmio-mod.c
25362index dc0b727..dc9d71a 100644
25363--- a/arch/x86/mm/mmio-mod.c
25364+++ b/arch/x86/mm/mmio-mod.c
25365@@ -194,7 +194,7 @@ static void pre(struct kmmio_probe *p, struct pt_regs *regs,
25366 break;
25367 default:
25368 {
25369- unsigned char *ip = (unsigned char *)instptr;
25370+ unsigned char *ip = (unsigned char *)ktla_ktva(instptr);
25371 my_trace->opcode = MMIO_UNKNOWN_OP;
25372 my_trace->width = 0;
25373 my_trace->value = (*ip) << 16 | *(ip + 1) << 8 |
25374@@ -234,7 +234,7 @@ static void post(struct kmmio_probe *p, unsigned long condition,
25375 static void ioremap_trace_core(resource_size_t offset, unsigned long size,
25376 void __iomem *addr)
25377 {
25378- static atomic_t next_id;
25379+ static atomic_unchecked_t next_id;
25380 struct remap_trace *trace = kmalloc(sizeof(*trace), GFP_KERNEL);
25381 /* These are page-unaligned. */
25382 struct mmiotrace_map map = {
25383@@ -258,7 +258,7 @@ static void ioremap_trace_core(resource_size_t offset, unsigned long size,
25384 .private = trace
25385 },
25386 .phys = offset,
25387- .id = atomic_inc_return(&next_id)
25388+ .id = atomic_inc_return_unchecked(&next_id)
25389 };
25390 map.map_id = trace->id;
25391
25392diff --git a/arch/x86/mm/pageattr-test.c b/arch/x86/mm/pageattr-test.c
25393index b008656..773eac2 100644
25394--- a/arch/x86/mm/pageattr-test.c
25395+++ b/arch/x86/mm/pageattr-test.c
25396@@ -36,7 +36,7 @@ enum {
25397
25398 static int pte_testbit(pte_t pte)
25399 {
25400- return pte_flags(pte) & _PAGE_UNUSED1;
25401+ return pte_flags(pte) & _PAGE_CPA_TEST;
25402 }
25403
25404 struct split_state {
25405diff --git a/arch/x86/mm/pageattr.c b/arch/x86/mm/pageattr.c
25406index a718e0d..45efc32 100644
25407--- a/arch/x86/mm/pageattr.c
25408+++ b/arch/x86/mm/pageattr.c
25409@@ -261,7 +261,7 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
25410 */
25411 #ifdef CONFIG_PCI_BIOS
25412 if (pcibios_enabled && within(pfn, BIOS_BEGIN >> PAGE_SHIFT, BIOS_END >> PAGE_SHIFT))
25413- pgprot_val(forbidden) |= _PAGE_NX;
25414+ pgprot_val(forbidden) |= _PAGE_NX & __supported_pte_mask;
25415 #endif
25416
25417 /*
25418@@ -269,9 +269,10 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
25419 * Does not cover __inittext since that is gone later on. On
25420 * 64bit we do not enforce !NX on the low mapping
25421 */
25422- if (within(address, (unsigned long)_text, (unsigned long)_etext))
25423- pgprot_val(forbidden) |= _PAGE_NX;
25424+ if (within(address, ktla_ktva((unsigned long)_text), ktla_ktva((unsigned long)_etext)))
25425+ pgprot_val(forbidden) |= _PAGE_NX & __supported_pte_mask;
25426
25427+#ifdef CONFIG_DEBUG_RODATA
25428 /*
25429 * The .rodata section needs to be read-only. Using the pfn
25430 * catches all aliases.
25431@@ -279,6 +280,7 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
25432 if (within(pfn, __pa((unsigned long)__start_rodata) >> PAGE_SHIFT,
25433 __pa((unsigned long)__end_rodata) >> PAGE_SHIFT))
25434 pgprot_val(forbidden) |= _PAGE_RW;
25435+#endif
25436
25437 #if defined(CONFIG_X86_64) && defined(CONFIG_DEBUG_RODATA)
25438 /*
25439@@ -317,6 +319,13 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
25440 }
25441 #endif
25442
25443+#ifdef CONFIG_PAX_KERNEXEC
25444+ if (within(pfn, __pa((unsigned long)&_text), __pa((unsigned long)&_sdata))) {
25445+ pgprot_val(forbidden) |= _PAGE_RW;
25446+ pgprot_val(forbidden) |= _PAGE_NX & __supported_pte_mask;
25447+ }
25448+#endif
25449+
25450 prot = __pgprot(pgprot_val(prot) & ~pgprot_val(forbidden));
25451
25452 return prot;
25453@@ -369,23 +378,37 @@ EXPORT_SYMBOL_GPL(lookup_address);
25454 static void __set_pmd_pte(pte_t *kpte, unsigned long address, pte_t pte)
25455 {
25456 /* change init_mm */
25457+ pax_open_kernel();
25458 set_pte_atomic(kpte, pte);
25459+
25460 #ifdef CONFIG_X86_32
25461 if (!SHARED_KERNEL_PMD) {
25462+
25463+#ifdef CONFIG_PAX_PER_CPU_PGD
25464+ unsigned long cpu;
25465+#else
25466 struct page *page;
25467+#endif
25468
25469+#ifdef CONFIG_PAX_PER_CPU_PGD
25470+ for (cpu = 0; cpu < nr_cpu_ids; ++cpu) {
25471+ pgd_t *pgd = get_cpu_pgd(cpu);
25472+#else
25473 list_for_each_entry(page, &pgd_list, lru) {
25474- pgd_t *pgd;
25475+ pgd_t *pgd = (pgd_t *)page_address(page);
25476+#endif
25477+
25478 pud_t *pud;
25479 pmd_t *pmd;
25480
25481- pgd = (pgd_t *)page_address(page) + pgd_index(address);
25482+ pgd += pgd_index(address);
25483 pud = pud_offset(pgd, address);
25484 pmd = pmd_offset(pud, address);
25485 set_pte_atomic((pte_t *)pmd, pte);
25486 }
25487 }
25488 #endif
25489+ pax_close_kernel();
25490 }
25491
25492 static int
25493diff --git a/arch/x86/mm/pat.c b/arch/x86/mm/pat.c
25494index 3d68ef6..7f69136 100644
25495--- a/arch/x86/mm/pat.c
25496+++ b/arch/x86/mm/pat.c
25497@@ -376,7 +376,7 @@ int free_memtype(u64 start, u64 end)
25498
25499 if (!entry) {
25500 printk(KERN_INFO "%s:%d freeing invalid memtype [mem %#010Lx-%#010Lx]\n",
25501- current->comm, current->pid, start, end - 1);
25502+ current->comm, task_pid_nr(current), start, end - 1);
25503 return -EINVAL;
25504 }
25505
25506@@ -506,8 +506,8 @@ static inline int range_is_allowed(unsigned long pfn, unsigned long size)
25507
25508 while (cursor < to) {
25509 if (!devmem_is_allowed(pfn)) {
25510- printk(KERN_INFO "Program %s tried to access /dev/mem between [mem %#010Lx-%#010Lx]\n",
25511- current->comm, from, to - 1);
25512+ printk(KERN_INFO "Program %s tried to access /dev/mem between [mem %#010Lx-%#010Lx] (%#010Lx)\n",
25513+ current->comm, from, to - 1, cursor);
25514 return 0;
25515 }
25516 cursor += PAGE_SIZE;
25517@@ -570,7 +570,7 @@ int kernel_map_sync_memtype(u64 base, unsigned long size, unsigned long flags)
25518 if (ioremap_change_attr((unsigned long)__va(base), id_sz, flags) < 0) {
25519 printk(KERN_INFO "%s:%d ioremap_change_attr failed %s "
25520 "for [mem %#010Lx-%#010Lx]\n",
25521- current->comm, current->pid,
25522+ current->comm, task_pid_nr(current),
25523 cattr_name(flags),
25524 base, (unsigned long long)(base + size-1));
25525 return -EINVAL;
25526@@ -605,7 +605,7 @@ static int reserve_pfn_range(u64 paddr, unsigned long size, pgprot_t *vma_prot,
25527 flags = lookup_memtype(paddr);
25528 if (want_flags != flags) {
25529 printk(KERN_WARNING "%s:%d map pfn RAM range req %s for [mem %#010Lx-%#010Lx], got %s\n",
25530- current->comm, current->pid,
25531+ current->comm, task_pid_nr(current),
25532 cattr_name(want_flags),
25533 (unsigned long long)paddr,
25534 (unsigned long long)(paddr + size - 1),
25535@@ -627,7 +627,7 @@ static int reserve_pfn_range(u64 paddr, unsigned long size, pgprot_t *vma_prot,
25536 free_memtype(paddr, paddr + size);
25537 printk(KERN_ERR "%s:%d map pfn expected mapping type %s"
25538 " 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),
25544diff --git a/arch/x86/mm/pf_in.c b/arch/x86/mm/pf_in.c
25545index 9f0614d..92ae64a 100644
25546--- a/arch/x86/mm/pf_in.c
25547+++ b/arch/x86/mm/pf_in.c
25548@@ -148,7 +148,7 @@ enum reason_type get_ins_type(unsigned long ins_addr)
25549 int i;
25550 enum reason_type rv = OTHERS;
25551
25552- p = (unsigned char *)ins_addr;
25553+ p = (unsigned char *)ktla_ktva(ins_addr);
25554 p += skip_prefix(p, &prf);
25555 p += get_opcode(p, &opcode);
25556
25557@@ -168,7 +168,7 @@ static unsigned int get_ins_reg_width(unsigned long ins_addr)
25558 struct prefix_bits prf;
25559 int i;
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@@ -191,7 +191,7 @@ unsigned int get_ins_mem_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@@ -415,7 +415,7 @@ unsigned long get_ins_reg_val(unsigned long ins_addr, struct pt_regs *regs)
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 for (i = 0; i < ARRAY_SIZE(reg_rop); i++)
25584@@ -470,7 +470,7 @@ unsigned long get_ins_imm_val(unsigned long ins_addr)
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(imm_wop); i++)
25593diff --git a/arch/x86/mm/pgtable.c b/arch/x86/mm/pgtable.c
25594index 8573b83..4f3ed7e 100644
25595--- a/arch/x86/mm/pgtable.c
25596+++ b/arch/x86/mm/pgtable.c
25597@@ -84,10 +84,64 @@ static inline void pgd_list_del(pgd_t *pgd)
25598 list_del(&page->lru);
25599 }
25600
25601-#define UNSHARED_PTRS_PER_PGD \
25602- (SHARED_KERNEL_PMD ? KERNEL_PGD_BOUNDARY : PTRS_PER_PGD)
25603+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
25604+pgdval_t clone_pgd_mask __read_only = ~_PAGE_PRESENT;
25605
25606+void __shadow_user_pgds(pgd_t *dst, const pgd_t *src)
25607+{
25608+ unsigned int count = USER_PGD_PTRS;
25609
25610+ while (count--)
25611+ *dst++ = __pgd((pgd_val(*src++) | (_PAGE_NX & __supported_pte_mask)) & ~_PAGE_USER);
25612+}
25613+#endif
25614+
25615+#ifdef CONFIG_PAX_PER_CPU_PGD
25616+void __clone_user_pgds(pgd_t *dst, const pgd_t *src)
25617+{
25618+ unsigned int count = USER_PGD_PTRS;
25619+
25620+ while (count--) {
25621+ pgd_t pgd;
25622+
25623+#ifdef CONFIG_X86_64
25624+ pgd = __pgd(pgd_val(*src++) | _PAGE_USER);
25625+#else
25626+ pgd = *src++;
25627+#endif
25628+
25629+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
25630+ pgd = __pgd(pgd_val(pgd) & clone_pgd_mask);
25631+#endif
25632+
25633+ *dst++ = pgd;
25634+ }
25635+
25636+}
25637+#endif
25638+
25639+#ifdef CONFIG_X86_64
25640+#define pxd_t pud_t
25641+#define pyd_t pgd_t
25642+#define paravirt_release_pxd(pfn) paravirt_release_pud(pfn)
25643+#define pxd_free(mm, pud) pud_free((mm), (pud))
25644+#define pyd_populate(mm, pgd, pud) pgd_populate((mm), (pgd), (pud))
25645+#define pyd_offset(mm, address) pgd_offset((mm), (address))
25646+#define PYD_SIZE PGDIR_SIZE
25647+#else
25648+#define pxd_t pmd_t
25649+#define pyd_t pud_t
25650+#define paravirt_release_pxd(pfn) paravirt_release_pmd(pfn)
25651+#define pxd_free(mm, pud) pmd_free((mm), (pud))
25652+#define pyd_populate(mm, pgd, pud) pud_populate((mm), (pgd), (pud))
25653+#define pyd_offset(mm, address) pud_offset((mm), (address))
25654+#define PYD_SIZE PUD_SIZE
25655+#endif
25656+
25657+#ifdef CONFIG_PAX_PER_CPU_PGD
25658+static inline void pgd_ctor(struct mm_struct *mm, pgd_t *pgd) {}
25659+static inline void pgd_dtor(pgd_t *pgd) {}
25660+#else
25661 static void pgd_set_mm(pgd_t *pgd, struct mm_struct *mm)
25662 {
25663 BUILD_BUG_ON(sizeof(virt_to_page(pgd)->index) < sizeof(mm));
25664@@ -128,6 +182,7 @@ static void pgd_dtor(pgd_t *pgd)
25665 pgd_list_del(pgd);
25666 spin_unlock(&pgd_lock);
25667 }
25668+#endif
25669
25670 /*
25671 * List of all pgd's needed for non-PAE so it can invalidate entries
25672@@ -140,7 +195,7 @@ static void pgd_dtor(pgd_t *pgd)
25673 * -- wli
25674 */
25675
25676-#ifdef CONFIG_X86_PAE
25677+#if defined(CONFIG_X86_32) && defined(CONFIG_X86_PAE)
25678 /*
25679 * In PAE mode, we need to do a cr3 reload (=tlb flush) when
25680 * updating the top-level pagetable entries to guarantee the
25681@@ -152,7 +207,7 @@ static void pgd_dtor(pgd_t *pgd)
25682 * not shared between pagetables (!SHARED_KERNEL_PMDS), we allocate
25683 * and initialize the kernel pmds here.
25684 */
25685-#define PREALLOCATED_PMDS UNSHARED_PTRS_PER_PGD
25686+#define PREALLOCATED_PXDS (SHARED_KERNEL_PMD ? KERNEL_PGD_BOUNDARY : PTRS_PER_PGD)
25687
25688 void pud_populate(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd)
25689 {
25690@@ -170,36 +225,38 @@ void pud_populate(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd)
25691 */
25692 flush_tlb_mm(mm);
25693 }
25694+#elif defined(CONFIG_X86_64) && defined(CONFIG_PAX_PER_CPU_PGD)
25695+#define PREALLOCATED_PXDS USER_PGD_PTRS
25696 #else /* !CONFIG_X86_PAE */
25697
25698 /* No need to prepopulate any pagetable entries in non-PAE modes. */
25699-#define PREALLOCATED_PMDS 0
25700+#define PREALLOCATED_PXDS 0
25701
25702 #endif /* CONFIG_X86_PAE */
25703
25704-static void free_pmds(pmd_t *pmds[])
25705+static void free_pxds(pxd_t *pxds[])
25706 {
25707 int i;
25708
25709- for(i = 0; i < PREALLOCATED_PMDS; i++)
25710- if (pmds[i])
25711- free_page((unsigned long)pmds[i]);
25712+ for(i = 0; i < PREALLOCATED_PXDS; i++)
25713+ if (pxds[i])
25714+ free_page((unsigned long)pxds[i]);
25715 }
25716
25717-static int preallocate_pmds(pmd_t *pmds[])
25718+static int preallocate_pxds(pxd_t *pxds[])
25719 {
25720 int i;
25721 bool failed = false;
25722
25723- for(i = 0; i < PREALLOCATED_PMDS; i++) {
25724- pmd_t *pmd = (pmd_t *)__get_free_page(PGALLOC_GFP);
25725- if (pmd == NULL)
25726+ for(i = 0; i < PREALLOCATED_PXDS; i++) {
25727+ pxd_t *pxd = (pxd_t *)__get_free_page(PGALLOC_GFP);
25728+ if (pxd == NULL)
25729 failed = true;
25730- pmds[i] = pmd;
25731+ pxds[i] = pxd;
25732 }
25733
25734 if (failed) {
25735- free_pmds(pmds);
25736+ free_pxds(pxds);
25737 return -ENOMEM;
25738 }
25739
25740@@ -212,51 +269,55 @@ static int preallocate_pmds(pmd_t *pmds[])
25741 * preallocate which never got a corresponding vma will need to be
25742 * freed manually.
25743 */
25744-static void pgd_mop_up_pmds(struct mm_struct *mm, pgd_t *pgdp)
25745+static void pgd_mop_up_pxds(struct mm_struct *mm, pgd_t *pgdp)
25746 {
25747 int i;
25748
25749- for(i = 0; i < PREALLOCATED_PMDS; i++) {
25750+ for(i = 0; i < PREALLOCATED_PXDS; i++) {
25751 pgd_t pgd = pgdp[i];
25752
25753 if (pgd_val(pgd) != 0) {
25754- pmd_t *pmd = (pmd_t *)pgd_page_vaddr(pgd);
25755+ pxd_t *pxd = (pxd_t *)pgd_page_vaddr(pgd);
25756
25757- pgdp[i] = native_make_pgd(0);
25758+ set_pgd(pgdp + i, native_make_pgd(0));
25759
25760- paravirt_release_pmd(pgd_val(pgd) >> PAGE_SHIFT);
25761- pmd_free(mm, pmd);
25762+ paravirt_release_pxd(pgd_val(pgd) >> PAGE_SHIFT);
25763+ pxd_free(mm, pxd);
25764 }
25765 }
25766 }
25767
25768-static void pgd_prepopulate_pmd(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmds[])
25769+static void pgd_prepopulate_pxd(struct mm_struct *mm, pgd_t *pgd, pxd_t *pxds[])
25770 {
25771- pud_t *pud;
25772+ pyd_t *pyd;
25773 unsigned long addr;
25774 int i;
25775
25776- if (PREALLOCATED_PMDS == 0) /* Work around gcc-3.4.x bug */
25777+ if (PREALLOCATED_PXDS == 0) /* Work around gcc-3.4.x bug */
25778 return;
25779
25780- pud = pud_offset(pgd, 0);
25781+#ifdef CONFIG_X86_64
25782+ pyd = pyd_offset(mm, 0L);
25783+#else
25784+ pyd = pyd_offset(pgd, 0L);
25785+#endif
25786
25787- for (addr = i = 0; i < PREALLOCATED_PMDS;
25788- i++, pud++, addr += PUD_SIZE) {
25789- pmd_t *pmd = pmds[i];
25790+ for (addr = i = 0; i < PREALLOCATED_PXDS;
25791+ i++, pyd++, addr += PYD_SIZE) {
25792+ pxd_t *pxd = pxds[i];
25793
25794 if (i >= KERNEL_PGD_BOUNDARY)
25795- memcpy(pmd, (pmd_t *)pgd_page_vaddr(swapper_pg_dir[i]),
25796- sizeof(pmd_t) * PTRS_PER_PMD);
25797+ memcpy(pxd, (pxd_t *)pgd_page_vaddr(swapper_pg_dir[i]),
25798+ sizeof(pxd_t) * PTRS_PER_PMD);
25799
25800- pud_populate(mm, pud, pmd);
25801+ pyd_populate(mm, pyd, pxd);
25802 }
25803 }
25804
25805 pgd_t *pgd_alloc(struct mm_struct *mm)
25806 {
25807 pgd_t *pgd;
25808- pmd_t *pmds[PREALLOCATED_PMDS];
25809+ pxd_t *pxds[PREALLOCATED_PXDS];
25810
25811 pgd = (pgd_t *)__get_free_page(PGALLOC_GFP);
25812
25813@@ -265,11 +326,11 @@ pgd_t *pgd_alloc(struct mm_struct *mm)
25814
25815 mm->pgd = pgd;
25816
25817- if (preallocate_pmds(pmds) != 0)
25818+ if (preallocate_pxds(pxds) != 0)
25819 goto out_free_pgd;
25820
25821 if (paravirt_pgd_alloc(mm) != 0)
25822- goto out_free_pmds;
25823+ goto out_free_pxds;
25824
25825 /*
25826 * Make sure that pre-populating the pmds is atomic with
25827@@ -279,14 +340,14 @@ pgd_t *pgd_alloc(struct mm_struct *mm)
25828 spin_lock(&pgd_lock);
25829
25830 pgd_ctor(mm, pgd);
25831- pgd_prepopulate_pmd(mm, pgd, pmds);
25832+ pgd_prepopulate_pxd(mm, pgd, pxds);
25833
25834 spin_unlock(&pgd_lock);
25835
25836 return pgd;
25837
25838-out_free_pmds:
25839- free_pmds(pmds);
25840+out_free_pxds:
25841+ free_pxds(pxds);
25842 out_free_pgd:
25843 free_page((unsigned long)pgd);
25844 out:
25845@@ -295,7 +356,7 @@ out:
25846
25847 void pgd_free(struct mm_struct *mm, pgd_t *pgd)
25848 {
25849- pgd_mop_up_pmds(mm, pgd);
25850+ pgd_mop_up_pxds(mm, pgd);
25851 pgd_dtor(pgd);
25852 paravirt_pgd_free(mm, pgd);
25853 free_page((unsigned long)pgd);
25854diff --git a/arch/x86/mm/pgtable_32.c b/arch/x86/mm/pgtable_32.c
25855index a69bcb8..19068ab 100644
25856--- a/arch/x86/mm/pgtable_32.c
25857+++ b/arch/x86/mm/pgtable_32.c
25858@@ -47,10 +47,13 @@ void set_pte_vaddr(unsigned long vaddr, pte_t pteval)
25859 return;
25860 }
25861 pte = pte_offset_kernel(pmd, vaddr);
25862+
25863+ pax_open_kernel();
25864 if (pte_val(pteval))
25865 set_pte_at(&init_mm, vaddr, pte, pteval);
25866 else
25867 pte_clear(&init_mm, vaddr, pte);
25868+ pax_close_kernel();
25869
25870 /*
25871 * It's enough to flush this one mapping.
25872diff --git a/arch/x86/mm/setup_nx.c b/arch/x86/mm/setup_nx.c
25873index 410531d..0f16030 100644
25874--- a/arch/x86/mm/setup_nx.c
25875+++ b/arch/x86/mm/setup_nx.c
25876@@ -5,8 +5,10 @@
25877 #include <asm/pgtable.h>
25878 #include <asm/proto.h>
25879
25880+#if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
25881 static int disable_nx __cpuinitdata;
25882
25883+#ifndef CONFIG_PAX_PAGEEXEC
25884 /*
25885 * noexec = on|off
25886 *
25887@@ -28,12 +30,17 @@ static int __init noexec_setup(char *str)
25888 return 0;
25889 }
25890 early_param("noexec", noexec_setup);
25891+#endif
25892+
25893+#endif
25894
25895 void __cpuinit x86_configure_nx(void)
25896 {
25897+#if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
25898 if (cpu_has_nx && !disable_nx)
25899 __supported_pte_mask |= _PAGE_NX;
25900 else
25901+#endif
25902 __supported_pte_mask &= ~_PAGE_NX;
25903 }
25904
25905diff --git a/arch/x86/mm/tlb.c b/arch/x86/mm/tlb.c
25906index 613cd83..3a21f1c 100644
25907--- a/arch/x86/mm/tlb.c
25908+++ b/arch/x86/mm/tlb.c
25909@@ -48,7 +48,11 @@ void leave_mm(int cpu)
25910 BUG();
25911 if (cpumask_test_cpu(cpu, mm_cpumask(active_mm))) {
25912 cpumask_clear_cpu(cpu, mm_cpumask(active_mm));
25913+
25914+#ifndef CONFIG_PAX_PER_CPU_PGD
25915 load_cr3(swapper_pg_dir);
25916+#endif
25917+
25918 }
25919 }
25920 EXPORT_SYMBOL_GPL(leave_mm);
25921diff --git a/arch/x86/net/bpf_jit.S b/arch/x86/net/bpf_jit.S
25922index 877b9a1..a8ecf42 100644
25923--- a/arch/x86/net/bpf_jit.S
25924+++ b/arch/x86/net/bpf_jit.S
25925@@ -9,6 +9,7 @@
25926 */
25927 #include <linux/linkage.h>
25928 #include <asm/dwarf2.h>
25929+#include <asm/alternative-asm.h>
25930
25931 /*
25932 * Calling convention :
25933@@ -35,6 +36,7 @@ sk_load_word_positive_offset:
25934 jle bpf_slow_path_word
25935 mov (SKBDATA,%rsi),%eax
25936 bswap %eax /* ntohl() */
25937+ pax_force_retaddr
25938 ret
25939
25940 sk_load_half:
25941@@ -52,6 +54,7 @@ sk_load_half_positive_offset:
25942 jle bpf_slow_path_half
25943 movzwl (SKBDATA,%rsi),%eax
25944 rol $8,%ax # ntohs()
25945+ pax_force_retaddr
25946 ret
25947
25948 sk_load_byte:
25949@@ -66,6 +69,7 @@ sk_load_byte_positive_offset:
25950 cmp %esi,%r9d /* if (offset >= hlen) goto bpf_slow_path_byte */
25951 jle bpf_slow_path_byte
25952 movzbl (SKBDATA,%rsi),%eax
25953+ pax_force_retaddr
25954 ret
25955
25956 /**
25957@@ -87,6 +91,7 @@ sk_load_byte_msh_positive_offset:
25958 movzbl (SKBDATA,%rsi),%ebx
25959 and $15,%bl
25960 shl $2,%bl
25961+ pax_force_retaddr
25962 ret
25963
25964 /* rsi contains offset and can be scratched */
25965@@ -109,6 +114,7 @@ bpf_slow_path_word:
25966 js bpf_error
25967 mov -12(%rbp),%eax
25968 bswap %eax
25969+ pax_force_retaddr
25970 ret
25971
25972 bpf_slow_path_half:
25973@@ -117,12 +123,14 @@ bpf_slow_path_half:
25974 mov -12(%rbp),%ax
25975 rol $8,%ax
25976 movzwl %ax,%eax
25977+ pax_force_retaddr
25978 ret
25979
25980 bpf_slow_path_byte:
25981 bpf_slow_path_common(1)
25982 js bpf_error
25983 movzbl -12(%rbp),%eax
25984+ pax_force_retaddr
25985 ret
25986
25987 bpf_slow_path_byte_msh:
25988@@ -133,6 +141,7 @@ bpf_slow_path_byte_msh:
25989 and $15,%al
25990 shl $2,%al
25991 xchg %eax,%ebx
25992+ pax_force_retaddr
25993 ret
25994
25995 #define sk_negative_common(SIZE) \
25996@@ -157,6 +166,7 @@ sk_load_word_negative_offset:
25997 sk_negative_common(4)
25998 mov (%rax), %eax
25999 bswap %eax
26000+ pax_force_retaddr
26001 ret
26002
26003 bpf_slow_path_half_neg:
26004@@ -168,6 +178,7 @@ sk_load_half_negative_offset:
26005 mov (%rax),%ax
26006 rol $8,%ax
26007 movzwl %ax,%eax
26008+ pax_force_retaddr
26009 ret
26010
26011 bpf_slow_path_byte_neg:
26012@@ -177,6 +188,7 @@ sk_load_byte_negative_offset:
26013 .globl sk_load_byte_negative_offset
26014 sk_negative_common(1)
26015 movzbl (%rax), %eax
26016+ pax_force_retaddr
26017 ret
26018
26019 bpf_slow_path_byte_msh_neg:
26020@@ -190,6 +202,7 @@ sk_load_byte_msh_negative_offset:
26021 and $15,%al
26022 shl $2,%al
26023 xchg %eax,%ebx
26024+ pax_force_retaddr
26025 ret
26026
26027 bpf_error:
26028@@ -197,4 +210,5 @@ bpf_error:
26029 xor %eax,%eax
26030 mov -8(%rbp),%rbx
26031 leaveq
26032+ pax_force_retaddr
26033 ret
26034diff --git a/arch/x86/net/bpf_jit_comp.c b/arch/x86/net/bpf_jit_comp.c
26035index 33643a8..8e44870 100644
26036--- a/arch/x86/net/bpf_jit_comp.c
26037+++ b/arch/x86/net/bpf_jit_comp.c
26038@@ -120,6 +120,11 @@ static inline void bpf_flush_icache(void *start, void *end)
26039 set_fs(old_fs);
26040 }
26041
26042+struct bpf_jit_work {
26043+ struct work_struct work;
26044+ void *image;
26045+};
26046+
26047 #define CHOOSE_LOAD_FUNC(K, func) \
26048 ((int)K < 0 ? ((int)K >= SKF_LL_OFF ? func##_negative_offset : func) : func##_positive_offset)
26049
26050@@ -146,6 +151,10 @@ void bpf_jit_compile(struct sk_filter *fp)
26051 if (addrs == NULL)
26052 return;
26053
26054+ fp->work = kmalloc(sizeof(*fp->work), GFP_KERNEL);
26055+ if (!fp->work)
26056+ goto out;
26057+
26058 /* Before first pass, make a rough estimation of addrs[]
26059 * each bpf instruction is translated to less than 64 bytes
26060 */
26061@@ -593,17 +602,18 @@ cond_branch: f_offset = addrs[i + filter[i].jf] - addrs[i];
26062 break;
26063 default:
26064 /* hmm, too complex filter, give up with jit compiler */
26065- goto out;
26066+ goto error;
26067 }
26068 ilen = prog - temp;
26069 if (image) {
26070 if (unlikely(proglen + ilen > oldproglen)) {
26071 pr_err("bpb_jit_compile fatal error\n");
26072- kfree(addrs);
26073- module_free(NULL, image);
26074- return;
26075+ module_free_exec(NULL, image);
26076+ goto error;
26077 }
26078+ pax_open_kernel();
26079 memcpy(image + proglen, temp, ilen);
26080+ pax_close_kernel();
26081 }
26082 proglen += ilen;
26083 addrs[i] = proglen;
26084@@ -624,11 +634,9 @@ cond_branch: f_offset = addrs[i + filter[i].jf] - addrs[i];
26085 break;
26086 }
26087 if (proglen == oldproglen) {
26088- image = module_alloc(max_t(unsigned int,
26089- proglen,
26090- sizeof(struct work_struct)));
26091+ image = module_alloc_exec(proglen);
26092 if (!image)
26093- goto out;
26094+ goto error;
26095 }
26096 oldproglen = proglen;
26097 }
26098@@ -644,7 +652,10 @@ cond_branch: f_offset = addrs[i + filter[i].jf] - addrs[i];
26099 bpf_flush_icache(image, image + proglen);
26100
26101 fp->bpf_func = (void *)image;
26102- }
26103+ } else
26104+error:
26105+ kfree(fp->work);
26106+
26107 out:
26108 kfree(addrs);
26109 return;
26110@@ -652,18 +663,20 @@ out:
26111
26112 static void jit_free_defer(struct work_struct *arg)
26113 {
26114- module_free(NULL, arg);
26115+ module_free_exec(NULL, ((struct bpf_jit_work *)arg)->image);
26116+ kfree(arg);
26117 }
26118
26119 /* run from softirq, we must use a work_struct to call
26120- * module_free() from process context
26121+ * module_free_exec() from process context
26122 */
26123 void bpf_jit_free(struct sk_filter *fp)
26124 {
26125 if (fp->bpf_func != sk_run_filter) {
26126- struct work_struct *work = (struct work_struct *)fp->bpf_func;
26127+ struct work_struct *work = &fp->work->work;
26128
26129 INIT_WORK(work, jit_free_defer);
26130+ fp->work->image = fp->bpf_func;
26131 schedule_work(work);
26132 }
26133 }
26134diff --git a/arch/x86/oprofile/backtrace.c b/arch/x86/oprofile/backtrace.c
26135index d6aa6e8..266395a 100644
26136--- a/arch/x86/oprofile/backtrace.c
26137+++ b/arch/x86/oprofile/backtrace.c
26138@@ -46,11 +46,11 @@ dump_user_backtrace_32(struct stack_frame_ia32 *head)
26139 struct stack_frame_ia32 *fp;
26140 unsigned long bytes;
26141
26142- bytes = copy_from_user_nmi(bufhead, head, sizeof(bufhead));
26143+ bytes = copy_from_user_nmi(bufhead, (const char __force_user *)head, sizeof(bufhead));
26144 if (bytes != sizeof(bufhead))
26145 return NULL;
26146
26147- fp = (struct stack_frame_ia32 *) compat_ptr(bufhead[0].next_frame);
26148+ fp = (struct stack_frame_ia32 __force_kernel *) compat_ptr(bufhead[0].next_frame);
26149
26150 oprofile_add_trace(bufhead[0].return_address);
26151
26152@@ -92,7 +92,7 @@ static struct stack_frame *dump_user_backtrace(struct stack_frame *head)
26153 struct stack_frame bufhead[2];
26154 unsigned long bytes;
26155
26156- bytes = copy_from_user_nmi(bufhead, head, sizeof(bufhead));
26157+ bytes = copy_from_user_nmi(bufhead, (const char __force_user *)head, sizeof(bufhead));
26158 if (bytes != sizeof(bufhead))
26159 return NULL;
26160
26161@@ -111,7 +111,7 @@ x86_backtrace(struct pt_regs * const regs, unsigned int depth)
26162 {
26163 struct stack_frame *head = (struct stack_frame *)frame_pointer(regs);
26164
26165- if (!user_mode_vm(regs)) {
26166+ if (!user_mode(regs)) {
26167 unsigned long stack = kernel_stack_pointer(regs);
26168 if (depth)
26169 dump_trace(NULL, regs, (unsigned long *)stack, 0,
26170diff --git a/arch/x86/pci/mrst.c b/arch/x86/pci/mrst.c
26171index e14a2ff..3fd6b58 100644
26172--- a/arch/x86/pci/mrst.c
26173+++ b/arch/x86/pci/mrst.c
26174@@ -238,7 +238,9 @@ int __init pci_mrst_init(void)
26175 printk(KERN_INFO "Intel MID platform detected, using MID PCI ops\n");
26176 pci_mmcfg_late_init();
26177 pcibios_enable_irq = mrst_pci_irq_enable;
26178- pci_root_ops = pci_mrst_ops;
26179+ pax_open_kernel();
26180+ memcpy((void *)&pci_root_ops, &pci_mrst_ops, sizeof(pci_mrst_ops));
26181+ pax_close_kernel();
26182 pci_soc_mode = 1;
26183 /* Continue with standard init */
26184 return 1;
26185diff --git a/arch/x86/pci/pcbios.c b/arch/x86/pci/pcbios.c
26186index da8fe05..7ee6704 100644
26187--- a/arch/x86/pci/pcbios.c
26188+++ b/arch/x86/pci/pcbios.c
26189@@ -79,50 +79,93 @@ union bios32 {
26190 static struct {
26191 unsigned long address;
26192 unsigned short segment;
26193-} bios32_indirect = { 0, __KERNEL_CS };
26194+} bios32_indirect __read_only = { 0, __PCIBIOS_CS };
26195
26196 /*
26197 * Returns the entry point for the given service, NULL on error
26198 */
26199
26200-static unsigned long bios32_service(unsigned long service)
26201+static unsigned long __devinit bios32_service(unsigned long service)
26202 {
26203 unsigned char return_code; /* %al */
26204 unsigned long address; /* %ebx */
26205 unsigned long length; /* %ecx */
26206 unsigned long entry; /* %edx */
26207 unsigned long flags;
26208+ struct desc_struct d, *gdt;
26209
26210 local_irq_save(flags);
26211- __asm__("lcall *(%%edi); cld"
26212+
26213+ gdt = get_cpu_gdt_table(smp_processor_id());
26214+
26215+ pack_descriptor(&d, 0UL, 0xFFFFFUL, 0x9B, 0xC);
26216+ write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_CS, &d, DESCTYPE_S);
26217+ pack_descriptor(&d, 0UL, 0xFFFFFUL, 0x93, 0xC);
26218+ write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_DS, &d, DESCTYPE_S);
26219+
26220+ __asm__("movw %w7, %%ds; lcall *(%%edi); push %%ss; pop %%ds; cld"
26221 : "=a" (return_code),
26222 "=b" (address),
26223 "=c" (length),
26224 "=d" (entry)
26225 : "0" (service),
26226 "1" (0),
26227- "D" (&bios32_indirect));
26228+ "D" (&bios32_indirect),
26229+ "r"(__PCIBIOS_DS)
26230+ : "memory");
26231+
26232+ pax_open_kernel();
26233+ gdt[GDT_ENTRY_PCIBIOS_CS].a = 0;
26234+ gdt[GDT_ENTRY_PCIBIOS_CS].b = 0;
26235+ gdt[GDT_ENTRY_PCIBIOS_DS].a = 0;
26236+ gdt[GDT_ENTRY_PCIBIOS_DS].b = 0;
26237+ pax_close_kernel();
26238+
26239 local_irq_restore(flags);
26240
26241 switch (return_code) {
26242- case 0:
26243- return address + entry;
26244- case 0x80: /* Not present */
26245- printk(KERN_WARNING "bios32_service(0x%lx): not present\n", service);
26246- return 0;
26247- default: /* Shouldn't happen */
26248- printk(KERN_WARNING "bios32_service(0x%lx): returned 0x%x -- BIOS bug!\n",
26249- service, return_code);
26250+ case 0: {
26251+ int cpu;
26252+ unsigned char flags;
26253+
26254+ printk(KERN_INFO "bios32_service: base:%08lx length:%08lx entry:%08lx\n", address, length, entry);
26255+ if (address >= 0xFFFF0 || length > 0x100000 - address || length <= entry) {
26256+ printk(KERN_WARNING "bios32_service: not valid\n");
26257 return 0;
26258+ }
26259+ address = address + PAGE_OFFSET;
26260+ length += 16UL; /* some BIOSs underreport this... */
26261+ flags = 4;
26262+ if (length >= 64*1024*1024) {
26263+ length >>= PAGE_SHIFT;
26264+ flags |= 8;
26265+ }
26266+
26267+ for (cpu = 0; cpu < nr_cpu_ids; cpu++) {
26268+ gdt = get_cpu_gdt_table(cpu);
26269+ pack_descriptor(&d, address, length, 0x9b, flags);
26270+ write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_CS, &d, DESCTYPE_S);
26271+ pack_descriptor(&d, address, length, 0x93, flags);
26272+ write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_DS, &d, DESCTYPE_S);
26273+ }
26274+ return entry;
26275+ }
26276+ case 0x80: /* Not present */
26277+ printk(KERN_WARNING "bios32_service(0x%lx): not present\n", service);
26278+ return 0;
26279+ default: /* Shouldn't happen */
26280+ printk(KERN_WARNING "bios32_service(0x%lx): returned 0x%x -- BIOS bug!\n",
26281+ service, return_code);
26282+ return 0;
26283 }
26284 }
26285
26286 static struct {
26287 unsigned long address;
26288 unsigned short segment;
26289-} pci_indirect = { 0, __KERNEL_CS };
26290+} pci_indirect __read_only = { 0, __PCIBIOS_CS };
26291
26292-static int pci_bios_present;
26293+static int pci_bios_present __read_only;
26294
26295 static int __devinit check_pcibios(void)
26296 {
26297@@ -131,11 +174,13 @@ static int __devinit check_pcibios(void)
26298 unsigned long flags, pcibios_entry;
26299
26300 if ((pcibios_entry = bios32_service(PCI_SERVICE))) {
26301- pci_indirect.address = pcibios_entry + PAGE_OFFSET;
26302+ pci_indirect.address = pcibios_entry;
26303
26304 local_irq_save(flags);
26305- __asm__(
26306- "lcall *(%%edi); cld\n\t"
26307+ __asm__("movw %w6, %%ds\n\t"
26308+ "lcall *%%ss:(%%edi); cld\n\t"
26309+ "push %%ss\n\t"
26310+ "pop %%ds\n\t"
26311 "jc 1f\n\t"
26312 "xor %%ah, %%ah\n"
26313 "1:"
26314@@ -144,7 +189,8 @@ static int __devinit check_pcibios(void)
26315 "=b" (ebx),
26316 "=c" (ecx)
26317 : "1" (PCIBIOS_PCI_BIOS_PRESENT),
26318- "D" (&pci_indirect)
26319+ "D" (&pci_indirect),
26320+ "r" (__PCIBIOS_DS)
26321 : "memory");
26322 local_irq_restore(flags);
26323
26324@@ -189,7 +235,10 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
26325
26326 switch (len) {
26327 case 1:
26328- __asm__("lcall *(%%esi); cld\n\t"
26329+ __asm__("movw %w6, %%ds\n\t"
26330+ "lcall *%%ss:(%%esi); cld\n\t"
26331+ "push %%ss\n\t"
26332+ "pop %%ds\n\t"
26333 "jc 1f\n\t"
26334 "xor %%ah, %%ah\n"
26335 "1:"
26336@@ -198,7 +247,8 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
26337 : "1" (PCIBIOS_READ_CONFIG_BYTE),
26338 "b" (bx),
26339 "D" ((long)reg),
26340- "S" (&pci_indirect));
26341+ "S" (&pci_indirect),
26342+ "r" (__PCIBIOS_DS));
26343 /*
26344 * Zero-extend the result beyond 8 bits, do not trust the
26345 * BIOS having done it:
26346@@ -206,7 +256,10 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
26347 *value &= 0xff;
26348 break;
26349 case 2:
26350- __asm__("lcall *(%%esi); cld\n\t"
26351+ __asm__("movw %w6, %%ds\n\t"
26352+ "lcall *%%ss:(%%esi); cld\n\t"
26353+ "push %%ss\n\t"
26354+ "pop %%ds\n\t"
26355 "jc 1f\n\t"
26356 "xor %%ah, %%ah\n"
26357 "1:"
26358@@ -215,7 +268,8 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
26359 : "1" (PCIBIOS_READ_CONFIG_WORD),
26360 "b" (bx),
26361 "D" ((long)reg),
26362- "S" (&pci_indirect));
26363+ "S" (&pci_indirect),
26364+ "r" (__PCIBIOS_DS));
26365 /*
26366 * Zero-extend the result beyond 16 bits, do not trust the
26367 * BIOS having done it:
26368@@ -223,7 +277,10 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
26369 *value &= 0xffff;
26370 break;
26371 case 4:
26372- __asm__("lcall *(%%esi); cld\n\t"
26373+ __asm__("movw %w6, %%ds\n\t"
26374+ "lcall *%%ss:(%%esi); cld\n\t"
26375+ "push %%ss\n\t"
26376+ "pop %%ds\n\t"
26377 "jc 1f\n\t"
26378 "xor %%ah, %%ah\n"
26379 "1:"
26380@@ -232,7 +289,8 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
26381 : "1" (PCIBIOS_READ_CONFIG_DWORD),
26382 "b" (bx),
26383 "D" ((long)reg),
26384- "S" (&pci_indirect));
26385+ "S" (&pci_indirect),
26386+ "r" (__PCIBIOS_DS));
26387 break;
26388 }
26389
26390@@ -256,7 +314,10 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
26391
26392 switch (len) {
26393 case 1:
26394- __asm__("lcall *(%%esi); cld\n\t"
26395+ __asm__("movw %w6, %%ds\n\t"
26396+ "lcall *%%ss:(%%esi); cld\n\t"
26397+ "push %%ss\n\t"
26398+ "pop %%ds\n\t"
26399 "jc 1f\n\t"
26400 "xor %%ah, %%ah\n"
26401 "1:"
26402@@ -265,10 +326,14 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
26403 "c" (value),
26404 "b" (bx),
26405 "D" ((long)reg),
26406- "S" (&pci_indirect));
26407+ "S" (&pci_indirect),
26408+ "r" (__PCIBIOS_DS));
26409 break;
26410 case 2:
26411- __asm__("lcall *(%%esi); cld\n\t"
26412+ __asm__("movw %w6, %%ds\n\t"
26413+ "lcall *%%ss:(%%esi); cld\n\t"
26414+ "push %%ss\n\t"
26415+ "pop %%ds\n\t"
26416 "jc 1f\n\t"
26417 "xor %%ah, %%ah\n"
26418 "1:"
26419@@ -277,10 +342,14 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
26420 "c" (value),
26421 "b" (bx),
26422 "D" ((long)reg),
26423- "S" (&pci_indirect));
26424+ "S" (&pci_indirect),
26425+ "r" (__PCIBIOS_DS));
26426 break;
26427 case 4:
26428- __asm__("lcall *(%%esi); cld\n\t"
26429+ __asm__("movw %w6, %%ds\n\t"
26430+ "lcall *%%ss:(%%esi); cld\n\t"
26431+ "push %%ss\n\t"
26432+ "pop %%ds\n\t"
26433 "jc 1f\n\t"
26434 "xor %%ah, %%ah\n"
26435 "1:"
26436@@ -289,7 +358,8 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
26437 "c" (value),
26438 "b" (bx),
26439 "D" ((long)reg),
26440- "S" (&pci_indirect));
26441+ "S" (&pci_indirect),
26442+ "r" (__PCIBIOS_DS));
26443 break;
26444 }
26445
26446@@ -394,10 +464,13 @@ struct irq_routing_table * pcibios_get_irq_routing_table(void)
26447
26448 DBG("PCI: Fetching IRQ routing table... ");
26449 __asm__("push %%es\n\t"
26450+ "movw %w8, %%ds\n\t"
26451 "push %%ds\n\t"
26452 "pop %%es\n\t"
26453- "lcall *(%%esi); cld\n\t"
26454+ "lcall *%%ss:(%%esi); cld\n\t"
26455 "pop %%es\n\t"
26456+ "push %%ss\n\t"
26457+ "pop %%ds\n"
26458 "jc 1f\n\t"
26459 "xor %%ah, %%ah\n"
26460 "1:"
26461@@ -408,7 +481,8 @@ struct irq_routing_table * pcibios_get_irq_routing_table(void)
26462 "1" (0),
26463 "D" ((long) &opt),
26464 "S" (&pci_indirect),
26465- "m" (opt)
26466+ "m" (opt),
26467+ "r" (__PCIBIOS_DS)
26468 : "memory");
26469 DBG("OK ret=%d, size=%d, map=%x\n", ret, opt.size, map);
26470 if (ret & 0xff00)
26471@@ -432,7 +506,10 @@ int pcibios_set_irq_routing(struct pci_dev *dev, int pin, int irq)
26472 {
26473 int ret;
26474
26475- __asm__("lcall *(%%esi); cld\n\t"
26476+ __asm__("movw %w5, %%ds\n\t"
26477+ "lcall *%%ss:(%%esi); cld\n\t"
26478+ "push %%ss\n\t"
26479+ "pop %%ds\n"
26480 "jc 1f\n\t"
26481 "xor %%ah, %%ah\n"
26482 "1:"
26483@@ -440,7 +517,8 @@ int pcibios_set_irq_routing(struct pci_dev *dev, int pin, int irq)
26484 : "0" (PCIBIOS_SET_PCI_HW_INT),
26485 "b" ((dev->bus->number << 8) | dev->devfn),
26486 "c" ((irq << 8) | (pin + 10)),
26487- "S" (&pci_indirect));
26488+ "S" (&pci_indirect),
26489+ "r" (__PCIBIOS_DS));
26490 return !(ret & 0xff00);
26491 }
26492 EXPORT_SYMBOL(pcibios_set_irq_routing);
26493diff --git a/arch/x86/platform/efi/efi_32.c b/arch/x86/platform/efi/efi_32.c
26494index 40e4469..1ab536e 100644
26495--- a/arch/x86/platform/efi/efi_32.c
26496+++ b/arch/x86/platform/efi/efi_32.c
26497@@ -44,11 +44,22 @@ void efi_call_phys_prelog(void)
26498 {
26499 struct desc_ptr gdt_descr;
26500
26501+#ifdef CONFIG_PAX_KERNEXEC
26502+ struct desc_struct d;
26503+#endif
26504+
26505 local_irq_save(efi_rt_eflags);
26506
26507 load_cr3(initial_page_table);
26508 __flush_tlb_all();
26509
26510+#ifdef CONFIG_PAX_KERNEXEC
26511+ pack_descriptor(&d, 0, 0xFFFFF, 0x9B, 0xC);
26512+ write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_CS, &d, DESCTYPE_S);
26513+ pack_descriptor(&d, 0, 0xFFFFF, 0x93, 0xC);
26514+ write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_DS, &d, DESCTYPE_S);
26515+#endif
26516+
26517 gdt_descr.address = __pa(get_cpu_gdt_table(0));
26518 gdt_descr.size = GDT_SIZE - 1;
26519 load_gdt(&gdt_descr);
26520@@ -58,6 +69,14 @@ void efi_call_phys_epilog(void)
26521 {
26522 struct desc_ptr gdt_descr;
26523
26524+#ifdef CONFIG_PAX_KERNEXEC
26525+ struct desc_struct d;
26526+
26527+ memset(&d, 0, sizeof d);
26528+ write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_CS, &d, DESCTYPE_S);
26529+ write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_DS, &d, DESCTYPE_S);
26530+#endif
26531+
26532 gdt_descr.address = (unsigned long)get_cpu_gdt_table(0);
26533 gdt_descr.size = GDT_SIZE - 1;
26534 load_gdt(&gdt_descr);
26535diff --git a/arch/x86/platform/efi/efi_stub_32.S b/arch/x86/platform/efi/efi_stub_32.S
26536index fbe66e6..eae5e38 100644
26537--- a/arch/x86/platform/efi/efi_stub_32.S
26538+++ b/arch/x86/platform/efi/efi_stub_32.S
26539@@ -6,7 +6,9 @@
26540 */
26541
26542 #include <linux/linkage.h>
26543+#include <linux/init.h>
26544 #include <asm/page_types.h>
26545+#include <asm/segment.h>
26546
26547 /*
26548 * efi_call_phys(void *, ...) is a function with variable parameters.
26549@@ -20,7 +22,7 @@
26550 * service functions will comply with gcc calling convention, too.
26551 */
26552
26553-.text
26554+__INIT
26555 ENTRY(efi_call_phys)
26556 /*
26557 * 0. The function can only be called in Linux kernel. So CS has been
26558@@ -36,10 +38,24 @@ ENTRY(efi_call_phys)
26559 * The mapping of lower virtual memory has been created in prelog and
26560 * epilog.
26561 */
26562- movl $1f, %edx
26563- subl $__PAGE_OFFSET, %edx
26564- jmp *%edx
26565+#ifdef CONFIG_PAX_KERNEXEC
26566+ movl $(__KERNEXEC_EFI_DS), %edx
26567+ mov %edx, %ds
26568+ mov %edx, %es
26569+ mov %edx, %ss
26570+ addl $2f,(1f)
26571+ ljmp *(1f)
26572+
26573+__INITDATA
26574+1: .long __LOAD_PHYSICAL_ADDR, __KERNEXEC_EFI_CS
26575+.previous
26576+
26577+2:
26578+ subl $2b,(1b)
26579+#else
26580+ jmp 1f-__PAGE_OFFSET
26581 1:
26582+#endif
26583
26584 /*
26585 * 2. Now on the top of stack is the return
26586@@ -47,14 +63,8 @@ ENTRY(efi_call_phys)
26587 * parameter 2, ..., param n. To make things easy, we save the return
26588 * address of efi_call_phys in a global variable.
26589 */
26590- popl %edx
26591- movl %edx, saved_return_addr
26592- /* get the function pointer into ECX*/
26593- popl %ecx
26594- movl %ecx, efi_rt_function_ptr
26595- movl $2f, %edx
26596- subl $__PAGE_OFFSET, %edx
26597- pushl %edx
26598+ popl (saved_return_addr)
26599+ popl (efi_rt_function_ptr)
26600
26601 /*
26602 * 3. Clear PG bit in %CR0.
26603@@ -73,9 +83,8 @@ ENTRY(efi_call_phys)
26604 /*
26605 * 5. Call the physical function.
26606 */
26607- jmp *%ecx
26608+ call *(efi_rt_function_ptr-__PAGE_OFFSET)
26609
26610-2:
26611 /*
26612 * 6. After EFI runtime service returns, control will return to
26613 * following instruction. We'd better readjust stack pointer first.
26614@@ -88,35 +97,36 @@ ENTRY(efi_call_phys)
26615 movl %cr0, %edx
26616 orl $0x80000000, %edx
26617 movl %edx, %cr0
26618- jmp 1f
26619-1:
26620+
26621 /*
26622 * 8. Now restore the virtual mode from flat mode by
26623 * adding EIP with PAGE_OFFSET.
26624 */
26625- movl $1f, %edx
26626- jmp *%edx
26627+#ifdef CONFIG_PAX_KERNEXEC
26628+ movl $(__KERNEL_DS), %edx
26629+ mov %edx, %ds
26630+ mov %edx, %es
26631+ mov %edx, %ss
26632+ ljmp $(__KERNEL_CS),$1f
26633+#else
26634+ jmp 1f+__PAGE_OFFSET
26635+#endif
26636 1:
26637
26638 /*
26639 * 9. Balance the stack. And because EAX contain the return value,
26640 * we'd better not clobber it.
26641 */
26642- leal efi_rt_function_ptr, %edx
26643- movl (%edx), %ecx
26644- pushl %ecx
26645+ pushl (efi_rt_function_ptr)
26646
26647 /*
26648- * 10. Push the saved return address onto the stack and return.
26649+ * 10. Return to the saved return address.
26650 */
26651- leal saved_return_addr, %edx
26652- movl (%edx), %ecx
26653- pushl %ecx
26654- ret
26655+ jmpl *(saved_return_addr)
26656 ENDPROC(efi_call_phys)
26657 .previous
26658
26659-.data
26660+__INITDATA
26661 saved_return_addr:
26662 .long 0
26663 efi_rt_function_ptr:
26664diff --git a/arch/x86/platform/efi/efi_stub_64.S b/arch/x86/platform/efi/efi_stub_64.S
26665index 4c07cca..2c8427d 100644
26666--- a/arch/x86/platform/efi/efi_stub_64.S
26667+++ b/arch/x86/platform/efi/efi_stub_64.S
26668@@ -7,6 +7,7 @@
26669 */
26670
26671 #include <linux/linkage.h>
26672+#include <asm/alternative-asm.h>
26673
26674 #define SAVE_XMM \
26675 mov %rsp, %rax; \
26676@@ -40,6 +41,7 @@ ENTRY(efi_call0)
26677 call *%rdi
26678 addq $32, %rsp
26679 RESTORE_XMM
26680+ pax_force_retaddr 0, 1
26681 ret
26682 ENDPROC(efi_call0)
26683
26684@@ -50,6 +52,7 @@ ENTRY(efi_call1)
26685 call *%rdi
26686 addq $32, %rsp
26687 RESTORE_XMM
26688+ pax_force_retaddr 0, 1
26689 ret
26690 ENDPROC(efi_call1)
26691
26692@@ -60,6 +63,7 @@ ENTRY(efi_call2)
26693 call *%rdi
26694 addq $32, %rsp
26695 RESTORE_XMM
26696+ pax_force_retaddr 0, 1
26697 ret
26698 ENDPROC(efi_call2)
26699
26700@@ -71,6 +75,7 @@ ENTRY(efi_call3)
26701 call *%rdi
26702 addq $32, %rsp
26703 RESTORE_XMM
26704+ pax_force_retaddr 0, 1
26705 ret
26706 ENDPROC(efi_call3)
26707
26708@@ -83,6 +88,7 @@ ENTRY(efi_call4)
26709 call *%rdi
26710 addq $32, %rsp
26711 RESTORE_XMM
26712+ pax_force_retaddr 0, 1
26713 ret
26714 ENDPROC(efi_call4)
26715
26716@@ -96,6 +102,7 @@ ENTRY(efi_call5)
26717 call *%rdi
26718 addq $48, %rsp
26719 RESTORE_XMM
26720+ pax_force_retaddr 0, 1
26721 ret
26722 ENDPROC(efi_call5)
26723
26724@@ -112,5 +119,6 @@ ENTRY(efi_call6)
26725 call *%rdi
26726 addq $48, %rsp
26727 RESTORE_XMM
26728+ pax_force_retaddr 0, 1
26729 ret
26730 ENDPROC(efi_call6)
26731diff --git a/arch/x86/platform/mrst/mrst.c b/arch/x86/platform/mrst/mrst.c
26732index fd41a92..9c33628 100644
26733--- a/arch/x86/platform/mrst/mrst.c
26734+++ b/arch/x86/platform/mrst/mrst.c
26735@@ -78,13 +78,15 @@ struct sfi_rtc_table_entry sfi_mrtc_array[SFI_MRTC_MAX];
26736 EXPORT_SYMBOL_GPL(sfi_mrtc_array);
26737 int sfi_mrtc_num;
26738
26739-static void mrst_power_off(void)
26740+static __noreturn void mrst_power_off(void)
26741 {
26742+ BUG();
26743 }
26744
26745-static void mrst_reboot(void)
26746+static __noreturn void mrst_reboot(void)
26747 {
26748 intel_scu_ipc_simple_command(IPCMSG_COLD_BOOT, 0);
26749+ BUG();
26750 }
26751
26752 /* parse all the mtimer info to a static mtimer array */
26753diff --git a/arch/x86/power/cpu.c b/arch/x86/power/cpu.c
26754index 218cdb1..fd55c08 100644
26755--- a/arch/x86/power/cpu.c
26756+++ b/arch/x86/power/cpu.c
26757@@ -132,7 +132,7 @@ static void do_fpu_end(void)
26758 static void fix_processor_context(void)
26759 {
26760 int cpu = smp_processor_id();
26761- struct tss_struct *t = &per_cpu(init_tss, cpu);
26762+ struct tss_struct *t = init_tss + cpu;
26763
26764 set_tss_desc(cpu, t); /*
26765 * This just modifies memory; should not be
26766@@ -142,7 +142,9 @@ static void fix_processor_context(void)
26767 */
26768
26769 #ifdef CONFIG_X86_64
26770+ pax_open_kernel();
26771 get_cpu_gdt_table(cpu)[GDT_ENTRY_TSS].type = 9;
26772+ pax_close_kernel();
26773
26774 syscall_init(); /* This sets MSR_*STAR and related */
26775 #endif
26776diff --git a/arch/x86/realmode/init.c b/arch/x86/realmode/init.c
26777index cbca565..bae7133 100644
26778--- a/arch/x86/realmode/init.c
26779+++ b/arch/x86/realmode/init.c
26780@@ -62,7 +62,13 @@ void __init setup_real_mode(void)
26781 __va(real_mode_header->trampoline_header);
26782
26783 #ifdef CONFIG_X86_32
26784- trampoline_header->start = __pa(startup_32_smp);
26785+ trampoline_header->start = __pa(ktla_ktva(startup_32_smp));
26786+
26787+#ifdef CONFIG_PAX_KERNEXEC
26788+ trampoline_header->start -= LOAD_PHYSICAL_ADDR;
26789+#endif
26790+
26791+ trampoline_header->boot_cs = __BOOT_CS;
26792 trampoline_header->gdt_limit = __BOOT_DS + 7;
26793 trampoline_header->gdt_base = __pa(boot_gdt);
26794 #else
26795diff --git a/arch/x86/realmode/rm/Makefile b/arch/x86/realmode/rm/Makefile
26796index 8869287..d577672 100644
26797--- a/arch/x86/realmode/rm/Makefile
26798+++ b/arch/x86/realmode/rm/Makefile
26799@@ -78,5 +78,8 @@ KBUILD_CFLAGS := $(LINUXINCLUDE) -m32 -g -Os -D_SETUP -D__KERNEL__ -D_WAKEUP \
26800 $(call cc-option, -fno-unit-at-a-time)) \
26801 $(call cc-option, -fno-stack-protector) \
26802 $(call cc-option, -mpreferred-stack-boundary=2)
26803+ifdef CONSTIFY_PLUGIN
26804+KBUILD_CFLAGS += -fplugin-arg-constify_plugin-no-constify
26805+endif
26806 KBUILD_AFLAGS := $(KBUILD_CFLAGS) -D__ASSEMBLY__
26807 GCOV_PROFILE := n
26808diff --git a/arch/x86/realmode/rm/header.S b/arch/x86/realmode/rm/header.S
26809index a28221d..93c40f1 100644
26810--- a/arch/x86/realmode/rm/header.S
26811+++ b/arch/x86/realmode/rm/header.S
26812@@ -30,7 +30,9 @@ GLOBAL(real_mode_header)
26813 #endif
26814 /* APM/BIOS reboot */
26815 .long pa_machine_real_restart_asm
26816-#ifdef CONFIG_X86_64
26817+#ifdef CONFIG_X86_32
26818+ .long __KERNEL_CS
26819+#else
26820 .long __KERNEL32_CS
26821 #endif
26822 END(real_mode_header)
26823diff --git a/arch/x86/realmode/rm/trampoline_32.S b/arch/x86/realmode/rm/trampoline_32.S
26824index c1b2791..f9e31c7 100644
26825--- a/arch/x86/realmode/rm/trampoline_32.S
26826+++ b/arch/x86/realmode/rm/trampoline_32.S
26827@@ -25,6 +25,12 @@
26828 #include <asm/page_types.h>
26829 #include "realmode.h"
26830
26831+#ifdef CONFIG_PAX_KERNEXEC
26832+#define ta(X) (X)
26833+#else
26834+#define ta(X) (pa_ ## X)
26835+#endif
26836+
26837 .text
26838 .code16
26839
26840@@ -39,8 +45,6 @@ ENTRY(trampoline_start)
26841
26842 cli # We should be safe anyway
26843
26844- movl tr_start, %eax # where we need to go
26845-
26846 movl $0xA5A5A5A5, trampoline_status
26847 # write marker for master knows we're running
26848
26849@@ -56,7 +60,7 @@ ENTRY(trampoline_start)
26850 movw $1, %dx # protected mode (PE) bit
26851 lmsw %dx # into protected mode
26852
26853- ljmpl $__BOOT_CS, $pa_startup_32
26854+ ljmpl *(trampoline_header)
26855
26856 .section ".text32","ax"
26857 .code32
26858@@ -67,7 +71,7 @@ ENTRY(startup_32) # note: also used from wakeup_asm.S
26859 .balign 8
26860 GLOBAL(trampoline_header)
26861 tr_start: .space 4
26862- tr_gdt_pad: .space 2
26863+ tr_boot_cs: .space 2
26864 tr_gdt: .space 6
26865 END(trampoline_header)
26866
26867diff --git a/arch/x86/realmode/rm/trampoline_64.S b/arch/x86/realmode/rm/trampoline_64.S
26868index bb360dc..3e5945f 100644
26869--- a/arch/x86/realmode/rm/trampoline_64.S
26870+++ b/arch/x86/realmode/rm/trampoline_64.S
26871@@ -107,7 +107,7 @@ ENTRY(startup_32)
26872 wrmsr
26873
26874 # Enable paging and in turn activate Long Mode
26875- movl $(X86_CR0_PG | X86_CR0_WP | X86_CR0_PE), %eax
26876+ movl $(X86_CR0_PG | X86_CR0_PE), %eax
26877 movl %eax, %cr0
26878
26879 /*
26880diff --git a/arch/x86/tools/relocs.c b/arch/x86/tools/relocs.c
26881index 5a1847d..deccb30 100644
26882--- a/arch/x86/tools/relocs.c
26883+++ b/arch/x86/tools/relocs.c
26884@@ -12,10 +12,13 @@
26885 #include <regex.h>
26886 #include <tools/le_byteshift.h>
26887
26888+#include "../../../include/generated/autoconf.h"
26889+
26890 static void die(char *fmt, ...);
26891
26892 #define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
26893 static Elf32_Ehdr ehdr;
26894+static Elf32_Phdr *phdr;
26895 static unsigned long reloc_count, reloc_idx;
26896 static unsigned long *relocs;
26897 static unsigned long reloc16_count, reloc16_idx;
26898@@ -330,9 +333,39 @@ static void read_ehdr(FILE *fp)
26899 }
26900 }
26901
26902+static void read_phdrs(FILE *fp)
26903+{
26904+ unsigned int i;
26905+
26906+ phdr = calloc(ehdr.e_phnum, sizeof(Elf32_Phdr));
26907+ if (!phdr) {
26908+ die("Unable to allocate %d program headers\n",
26909+ ehdr.e_phnum);
26910+ }
26911+ if (fseek(fp, ehdr.e_phoff, SEEK_SET) < 0) {
26912+ die("Seek to %d failed: %s\n",
26913+ ehdr.e_phoff, strerror(errno));
26914+ }
26915+ if (fread(phdr, sizeof(*phdr), ehdr.e_phnum, fp) != ehdr.e_phnum) {
26916+ die("Cannot read ELF program headers: %s\n",
26917+ strerror(errno));
26918+ }
26919+ for(i = 0; i < ehdr.e_phnum; i++) {
26920+ phdr[i].p_type = elf32_to_cpu(phdr[i].p_type);
26921+ phdr[i].p_offset = elf32_to_cpu(phdr[i].p_offset);
26922+ phdr[i].p_vaddr = elf32_to_cpu(phdr[i].p_vaddr);
26923+ phdr[i].p_paddr = elf32_to_cpu(phdr[i].p_paddr);
26924+ phdr[i].p_filesz = elf32_to_cpu(phdr[i].p_filesz);
26925+ phdr[i].p_memsz = elf32_to_cpu(phdr[i].p_memsz);
26926+ phdr[i].p_flags = elf32_to_cpu(phdr[i].p_flags);
26927+ phdr[i].p_align = elf32_to_cpu(phdr[i].p_align);
26928+ }
26929+
26930+}
26931+
26932 static void read_shdrs(FILE *fp)
26933 {
26934- int i;
26935+ unsigned int i;
26936 Elf32_Shdr shdr;
26937
26938 secs = calloc(ehdr.e_shnum, sizeof(struct section));
26939@@ -367,7 +400,7 @@ static void read_shdrs(FILE *fp)
26940
26941 static void read_strtabs(FILE *fp)
26942 {
26943- int i;
26944+ unsigned int i;
26945 for (i = 0; i < ehdr.e_shnum; i++) {
26946 struct section *sec = &secs[i];
26947 if (sec->shdr.sh_type != SHT_STRTAB) {
26948@@ -392,7 +425,7 @@ static void read_strtabs(FILE *fp)
26949
26950 static void read_symtabs(FILE *fp)
26951 {
26952- int i,j;
26953+ unsigned int i,j;
26954 for (i = 0; i < ehdr.e_shnum; i++) {
26955 struct section *sec = &secs[i];
26956 if (sec->shdr.sh_type != SHT_SYMTAB) {
26957@@ -423,9 +456,11 @@ static void read_symtabs(FILE *fp)
26958 }
26959
26960
26961-static void read_relocs(FILE *fp)
26962+static void read_relocs(FILE *fp, int use_real_mode)
26963 {
26964- int i,j;
26965+ unsigned int i,j;
26966+ uint32_t base;
26967+
26968 for (i = 0; i < ehdr.e_shnum; i++) {
26969 struct section *sec = &secs[i];
26970 if (sec->shdr.sh_type != SHT_REL) {
26971@@ -445,9 +480,22 @@ static void read_relocs(FILE *fp)
26972 die("Cannot read symbol table: %s\n",
26973 strerror(errno));
26974 }
26975+ base = 0;
26976+
26977+#ifdef CONFIG_X86_32
26978+ for (j = 0; !use_real_mode && j < ehdr.e_phnum; j++) {
26979+ if (phdr[j].p_type != PT_LOAD )
26980+ continue;
26981+ 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)
26982+ continue;
26983+ base = CONFIG_PAGE_OFFSET + phdr[j].p_paddr - phdr[j].p_vaddr;
26984+ break;
26985+ }
26986+#endif
26987+
26988 for (j = 0; j < sec->shdr.sh_size/sizeof(Elf32_Rel); j++) {
26989 Elf32_Rel *rel = &sec->reltab[j];
26990- rel->r_offset = elf32_to_cpu(rel->r_offset);
26991+ rel->r_offset = elf32_to_cpu(rel->r_offset) + base;
26992 rel->r_info = elf32_to_cpu(rel->r_info);
26993 }
26994 }
26995@@ -456,13 +504,13 @@ static void read_relocs(FILE *fp)
26996
26997 static void print_absolute_symbols(void)
26998 {
26999- int i;
27000+ unsigned int i;
27001 printf("Absolute symbols\n");
27002 printf(" Num: Value Size Type Bind Visibility Name\n");
27003 for (i = 0; i < ehdr.e_shnum; i++) {
27004 struct section *sec = &secs[i];
27005 char *sym_strtab;
27006- int j;
27007+ unsigned int j;
27008
27009 if (sec->shdr.sh_type != SHT_SYMTAB) {
27010 continue;
27011@@ -489,14 +537,14 @@ static void print_absolute_symbols(void)
27012
27013 static void print_absolute_relocs(void)
27014 {
27015- int i, printed = 0;
27016+ unsigned int i, printed = 0;
27017
27018 for (i = 0; i < ehdr.e_shnum; i++) {
27019 struct section *sec = &secs[i];
27020 struct section *sec_applies, *sec_symtab;
27021 char *sym_strtab;
27022 Elf32_Sym *sh_symtab;
27023- int j;
27024+ unsigned int j;
27025 if (sec->shdr.sh_type != SHT_REL) {
27026 continue;
27027 }
27028@@ -558,13 +606,13 @@ static void print_absolute_relocs(void)
27029 static void walk_relocs(void (*visit)(Elf32_Rel *rel, Elf32_Sym *sym),
27030 int use_real_mode)
27031 {
27032- int i;
27033+ unsigned int i;
27034 /* Walk through the relocations */
27035 for (i = 0; i < ehdr.e_shnum; i++) {
27036 char *sym_strtab;
27037 Elf32_Sym *sh_symtab;
27038 struct section *sec_applies, *sec_symtab;
27039- int j;
27040+ unsigned int j;
27041 struct section *sec = &secs[i];
27042
27043 if (sec->shdr.sh_type != SHT_REL) {
27044@@ -588,6 +636,24 @@ static void walk_relocs(void (*visit)(Elf32_Rel *rel, Elf32_Sym *sym),
27045 sym = &sh_symtab[ELF32_R_SYM(rel->r_info)];
27046 r_type = ELF32_R_TYPE(rel->r_info);
27047
27048+ if (!use_real_mode) {
27049+ /* Don't relocate actual per-cpu variables, they are absolute indices, not addresses */
27050+ if (!strcmp(sec_name(sym->st_shndx), ".data..percpu") && strcmp(sym_name(sym_strtab, sym), "__per_cpu_load"))
27051+ continue;
27052+
27053+#if defined(CONFIG_PAX_KERNEXEC) && defined(CONFIG_X86_32)
27054+ /* Don't relocate actual code, they are relocated implicitly by the base address of KERNEL_CS */
27055+ if (!strcmp(sec_name(sym->st_shndx), ".text.end") && !strcmp(sym_name(sym_strtab, sym), "_etext"))
27056+ continue;
27057+ if (!strcmp(sec_name(sym->st_shndx), ".init.text"))
27058+ continue;
27059+ if (!strcmp(sec_name(sym->st_shndx), ".exit.text"))
27060+ continue;
27061+ if (!strcmp(sec_name(sym->st_shndx), ".text") && strcmp(sym_name(sym_strtab, sym), "__LOAD_PHYSICAL_ADDR"))
27062+ continue;
27063+#endif
27064+ }
27065+
27066 shn_abs = sym->st_shndx == SHN_ABS;
27067
27068 switch (r_type) {
27069@@ -681,7 +747,7 @@ static int write32(unsigned int v, FILE *f)
27070
27071 static void emit_relocs(int as_text, int use_real_mode)
27072 {
27073- int i;
27074+ unsigned int i;
27075 /* Count how many relocations I have and allocate space for them. */
27076 reloc_count = 0;
27077 walk_relocs(count_reloc, use_real_mode);
27078@@ -808,10 +874,11 @@ int main(int argc, char **argv)
27079 fname, strerror(errno));
27080 }
27081 read_ehdr(fp);
27082+ read_phdrs(fp);
27083 read_shdrs(fp);
27084 read_strtabs(fp);
27085 read_symtabs(fp);
27086- read_relocs(fp);
27087+ read_relocs(fp, use_real_mode);
27088 if (show_absolute_syms) {
27089 print_absolute_symbols();
27090 return 0;
27091diff --git a/arch/x86/vdso/Makefile b/arch/x86/vdso/Makefile
27092index fd14be1..e3c79c0 100644
27093--- a/arch/x86/vdso/Makefile
27094+++ b/arch/x86/vdso/Makefile
27095@@ -181,7 +181,7 @@ quiet_cmd_vdso = VDSO $@
27096 -Wl,-T,$(filter %.lds,$^) $(filter %.o,$^) && \
27097 sh $(srctree)/$(src)/checkundef.sh '$(NM)' '$@'
27098
27099-VDSO_LDFLAGS = -fPIC -shared $(call cc-ldoption, -Wl$(comma)--hash-style=sysv)
27100+VDSO_LDFLAGS = -fPIC -shared -Wl,--no-undefined $(call cc-ldoption, -Wl$(comma)--hash-style=sysv)
27101 GCOV_PROFILE := n
27102
27103 #
27104diff --git a/arch/x86/vdso/vdso32-setup.c b/arch/x86/vdso/vdso32-setup.c
27105index 0faad64..39ef157 100644
27106--- a/arch/x86/vdso/vdso32-setup.c
27107+++ b/arch/x86/vdso/vdso32-setup.c
27108@@ -25,6 +25,7 @@
27109 #include <asm/tlbflush.h>
27110 #include <asm/vdso.h>
27111 #include <asm/proto.h>
27112+#include <asm/mman.h>
27113
27114 enum {
27115 VDSO_DISABLED = 0,
27116@@ -226,7 +227,7 @@ static inline void map_compat_vdso(int map)
27117 void enable_sep_cpu(void)
27118 {
27119 int cpu = get_cpu();
27120- struct tss_struct *tss = &per_cpu(init_tss, cpu);
27121+ struct tss_struct *tss = init_tss + cpu;
27122
27123 if (!boot_cpu_has(X86_FEATURE_SEP)) {
27124 put_cpu();
27125@@ -249,7 +250,7 @@ static int __init gate_vma_init(void)
27126 gate_vma.vm_start = FIXADDR_USER_START;
27127 gate_vma.vm_end = FIXADDR_USER_END;
27128 gate_vma.vm_flags = VM_READ | VM_MAYREAD | VM_EXEC | VM_MAYEXEC;
27129- gate_vma.vm_page_prot = __P101;
27130+ gate_vma.vm_page_prot = vm_get_page_prot(gate_vma.vm_flags);
27131
27132 return 0;
27133 }
27134@@ -330,14 +331,14 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
27135 if (compat)
27136 addr = VDSO_HIGH_BASE;
27137 else {
27138- addr = get_unmapped_area(NULL, 0, PAGE_SIZE, 0, 0);
27139+ addr = get_unmapped_area(NULL, 0, PAGE_SIZE, 0, MAP_EXECUTABLE);
27140 if (IS_ERR_VALUE(addr)) {
27141 ret = addr;
27142 goto up_fail;
27143 }
27144 }
27145
27146- current->mm->context.vdso = (void *)addr;
27147+ current->mm->context.vdso = addr;
27148
27149 if (compat_uses_vma || !compat) {
27150 /*
27151@@ -353,11 +354,11 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
27152 }
27153
27154 current_thread_info()->sysenter_return =
27155- VDSO32_SYMBOL(addr, SYSENTER_RETURN);
27156+ (__force void __user *)VDSO32_SYMBOL(addr, SYSENTER_RETURN);
27157
27158 up_fail:
27159 if (ret)
27160- current->mm->context.vdso = NULL;
27161+ current->mm->context.vdso = 0;
27162
27163 up_write(&mm->mmap_sem);
27164
27165@@ -404,8 +405,14 @@ __initcall(ia32_binfmt_init);
27166
27167 const char *arch_vma_name(struct vm_area_struct *vma)
27168 {
27169- if (vma->vm_mm && vma->vm_start == (long)vma->vm_mm->context.vdso)
27170+ if (vma->vm_mm && vma->vm_start == vma->vm_mm->context.vdso)
27171 return "[vdso]";
27172+
27173+#ifdef CONFIG_PAX_SEGMEXEC
27174+ if (vma->vm_mm && vma->vm_mirror && vma->vm_mirror->vm_start == vma->vm_mm->context.vdso)
27175+ return "[vdso]";
27176+#endif
27177+
27178 return NULL;
27179 }
27180
27181@@ -415,7 +422,7 @@ struct vm_area_struct *get_gate_vma(struct mm_struct *mm)
27182 * Check to see if the corresponding task was created in compat vdso
27183 * mode.
27184 */
27185- if (mm && mm->context.vdso == (void *)VDSO_HIGH_BASE)
27186+ if (mm && mm->context.vdso == VDSO_HIGH_BASE)
27187 return &gate_vma;
27188 return NULL;
27189 }
27190diff --git a/arch/x86/vdso/vma.c b/arch/x86/vdso/vma.c
27191index 00aaf04..4a26505 100644
27192--- a/arch/x86/vdso/vma.c
27193+++ b/arch/x86/vdso/vma.c
27194@@ -16,8 +16,6 @@
27195 #include <asm/vdso.h>
27196 #include <asm/page.h>
27197
27198-unsigned int __read_mostly vdso_enabled = 1;
27199-
27200 extern char vdso_start[], vdso_end[];
27201 extern unsigned short vdso_sync_cpuid;
27202
27203@@ -141,7 +139,6 @@ static unsigned long vdso_addr(unsigned long start, unsigned len)
27204 * unaligned here as a result of stack start randomization.
27205 */
27206 addr = PAGE_ALIGN(addr);
27207- addr = align_addr(addr, NULL, ALIGN_VDSO);
27208
27209 return addr;
27210 }
27211@@ -154,30 +151,31 @@ static int setup_additional_pages(struct linux_binprm *bprm,
27212 unsigned size)
27213 {
27214 struct mm_struct *mm = current->mm;
27215- unsigned long addr;
27216+ unsigned long addr = 0;
27217 int ret;
27218
27219- if (!vdso_enabled)
27220- return 0;
27221-
27222 down_write(&mm->mmap_sem);
27223+
27224+#ifdef CONFIG_PAX_RANDMMAP
27225+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
27226+#endif
27227+
27228 addr = vdso_addr(mm->start_stack, size);
27229+ addr = align_addr(addr, NULL, ALIGN_VDSO);
27230 addr = get_unmapped_area(NULL, addr, size, 0, 0);
27231 if (IS_ERR_VALUE(addr)) {
27232 ret = addr;
27233 goto up_fail;
27234 }
27235
27236- current->mm->context.vdso = (void *)addr;
27237+ mm->context.vdso = addr;
27238
27239 ret = install_special_mapping(mm, addr, size,
27240 VM_READ|VM_EXEC|
27241 VM_MAYREAD|VM_MAYWRITE|VM_MAYEXEC,
27242 pages);
27243- if (ret) {
27244- current->mm->context.vdso = NULL;
27245- goto up_fail;
27246- }
27247+ if (ret)
27248+ mm->context.vdso = 0;
27249
27250 up_fail:
27251 up_write(&mm->mmap_sem);
27252@@ -197,10 +195,3 @@ int x32_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
27253 vdsox32_size);
27254 }
27255 #endif
27256-
27257-static __init int vdso_setup(char *s)
27258-{
27259- vdso_enabled = simple_strtoul(s, NULL, 0);
27260- return 0;
27261-}
27262-__setup("vdso=", vdso_setup);
27263diff --git a/arch/x86/xen/enlighten.c b/arch/x86/xen/enlighten.c
27264index c1461de..355f120 100644
27265--- a/arch/x86/xen/enlighten.c
27266+++ b/arch/x86/xen/enlighten.c
27267@@ -98,8 +98,6 @@ EXPORT_SYMBOL_GPL(xen_start_info);
27268
27269 struct shared_info xen_dummy_shared_info;
27270
27271-void *xen_initial_gdt;
27272-
27273 RESERVE_BRK(shared_info_page_brk, PAGE_SIZE);
27274 __read_mostly int xen_have_vector_callback;
27275 EXPORT_SYMBOL_GPL(xen_have_vector_callback);
27276@@ -917,21 +915,21 @@ static u32 xen_safe_apic_wait_icr_idle(void)
27277
27278 static void set_xen_basic_apic_ops(void)
27279 {
27280- apic->read = xen_apic_read;
27281- apic->write = xen_apic_write;
27282- apic->icr_read = xen_apic_icr_read;
27283- apic->icr_write = xen_apic_icr_write;
27284- apic->wait_icr_idle = xen_apic_wait_icr_idle;
27285- apic->safe_wait_icr_idle = xen_safe_apic_wait_icr_idle;
27286- apic->set_apic_id = xen_set_apic_id;
27287- apic->get_apic_id = xen_get_apic_id;
27288+ *(void **)&apic->read = xen_apic_read;
27289+ *(void **)&apic->write = xen_apic_write;
27290+ *(void **)&apic->icr_read = xen_apic_icr_read;
27291+ *(void **)&apic->icr_write = xen_apic_icr_write;
27292+ *(void **)&apic->wait_icr_idle = xen_apic_wait_icr_idle;
27293+ *(void **)&apic->safe_wait_icr_idle = xen_safe_apic_wait_icr_idle;
27294+ *(void **)&apic->set_apic_id = xen_set_apic_id;
27295+ *(void **)&apic->get_apic_id = xen_get_apic_id;
27296
27297 #ifdef CONFIG_SMP
27298- apic->send_IPI_allbutself = xen_send_IPI_allbutself;
27299- apic->send_IPI_mask_allbutself = xen_send_IPI_mask_allbutself;
27300- apic->send_IPI_mask = xen_send_IPI_mask;
27301- apic->send_IPI_all = xen_send_IPI_all;
27302- apic->send_IPI_self = xen_send_IPI_self;
27303+ *(void **)&apic->send_IPI_allbutself = xen_send_IPI_allbutself;
27304+ *(void **)&apic->send_IPI_mask_allbutself = xen_send_IPI_mask_allbutself;
27305+ *(void **)&apic->send_IPI_mask = xen_send_IPI_mask;
27306+ *(void **)&apic->send_IPI_all = xen_send_IPI_all;
27307+ *(void **)&apic->send_IPI_self = xen_send_IPI_self;
27308 #endif
27309 }
27310
27311@@ -1221,30 +1219,30 @@ static const struct pv_apic_ops xen_apic_ops __initconst = {
27312 #endif
27313 };
27314
27315-static void xen_reboot(int reason)
27316+static __noreturn void xen_reboot(int reason)
27317 {
27318 struct sched_shutdown r = { .reason = reason };
27319
27320- if (HYPERVISOR_sched_op(SCHEDOP_shutdown, &r))
27321- BUG();
27322+ HYPERVISOR_sched_op(SCHEDOP_shutdown, &r);
27323+ BUG();
27324 }
27325
27326-static void xen_restart(char *msg)
27327+static __noreturn void xen_restart(char *msg)
27328 {
27329 xen_reboot(SHUTDOWN_reboot);
27330 }
27331
27332-static void xen_emergency_restart(void)
27333+static __noreturn void xen_emergency_restart(void)
27334 {
27335 xen_reboot(SHUTDOWN_reboot);
27336 }
27337
27338-static void xen_machine_halt(void)
27339+static __noreturn void xen_machine_halt(void)
27340 {
27341 xen_reboot(SHUTDOWN_poweroff);
27342 }
27343
27344-static void xen_machine_power_off(void)
27345+static __noreturn void xen_machine_power_off(void)
27346 {
27347 if (pm_power_off)
27348 pm_power_off();
27349@@ -1347,7 +1345,17 @@ asmlinkage void __init xen_start_kernel(void)
27350 __userpte_alloc_gfp &= ~__GFP_HIGHMEM;
27351
27352 /* Work out if we support NX */
27353- x86_configure_nx();
27354+#if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
27355+ if ((cpuid_eax(0x80000000) & 0xffff0000) == 0x80000000 &&
27356+ (cpuid_edx(0x80000001) & (1U << (X86_FEATURE_NX & 31)))) {
27357+ unsigned l, h;
27358+
27359+ __supported_pte_mask |= _PAGE_NX;
27360+ rdmsr(MSR_EFER, l, h);
27361+ l |= EFER_NX;
27362+ wrmsr(MSR_EFER, l, h);
27363+ }
27364+#endif
27365
27366 xen_setup_features();
27367
27368@@ -1378,13 +1386,6 @@ asmlinkage void __init xen_start_kernel(void)
27369
27370 machine_ops = xen_machine_ops;
27371
27372- /*
27373- * The only reliable way to retain the initial address of the
27374- * percpu gdt_page is to remember it here, so we can go and
27375- * mark it RW later, when the initial percpu area is freed.
27376- */
27377- xen_initial_gdt = &per_cpu(gdt_page, 0);
27378-
27379 xen_smp_init();
27380
27381 #ifdef CONFIG_ACPI_NUMA
27382diff --git a/arch/x86/xen/mmu.c b/arch/x86/xen/mmu.c
27383index 5141d80..6c9fb41 100644
27384--- a/arch/x86/xen/mmu.c
27385+++ b/arch/x86/xen/mmu.c
27386@@ -1765,6 +1765,9 @@ pgd_t * __init xen_setup_kernel_pagetable(pgd_t *pgd,
27387 convert_pfn_mfn(init_level4_pgt);
27388 convert_pfn_mfn(level3_ident_pgt);
27389 convert_pfn_mfn(level3_kernel_pgt);
27390+ convert_pfn_mfn(level3_vmalloc_start_pgt);
27391+ convert_pfn_mfn(level3_vmalloc_end_pgt);
27392+ convert_pfn_mfn(level3_vmemmap_pgt);
27393
27394 l3 = m2v(pgd[pgd_index(__START_KERNEL_map)].pgd);
27395 l2 = m2v(l3[pud_index(__START_KERNEL_map)].pud);
27396@@ -1783,7 +1786,11 @@ pgd_t * __init xen_setup_kernel_pagetable(pgd_t *pgd,
27397 set_page_prot(init_level4_pgt, PAGE_KERNEL_RO);
27398 set_page_prot(level3_ident_pgt, PAGE_KERNEL_RO);
27399 set_page_prot(level3_kernel_pgt, PAGE_KERNEL_RO);
27400+ set_page_prot(level3_vmalloc_start_pgt, PAGE_KERNEL_RO);
27401+ set_page_prot(level3_vmalloc_end_pgt, PAGE_KERNEL_RO);
27402+ set_page_prot(level3_vmemmap_pgt, PAGE_KERNEL_RO);
27403 set_page_prot(level3_user_vsyscall, PAGE_KERNEL_RO);
27404+ set_page_prot(level2_vmemmap_pgt, PAGE_KERNEL_RO);
27405 set_page_prot(level2_kernel_pgt, PAGE_KERNEL_RO);
27406 set_page_prot(level2_fixmap_pgt, PAGE_KERNEL_RO);
27407
27408@@ -1967,6 +1974,7 @@ static void __init xen_post_allocator_init(void)
27409 pv_mmu_ops.set_pud = xen_set_pud;
27410 #if PAGETABLE_LEVELS == 4
27411 pv_mmu_ops.set_pgd = xen_set_pgd;
27412+ pv_mmu_ops.set_pgd_batched = xen_set_pgd;
27413 #endif
27414
27415 /* This will work as long as patching hasn't happened yet
27416@@ -2048,6 +2056,7 @@ static const struct pv_mmu_ops xen_mmu_ops __initconst = {
27417 .pud_val = PV_CALLEE_SAVE(xen_pud_val),
27418 .make_pud = PV_CALLEE_SAVE(xen_make_pud),
27419 .set_pgd = xen_set_pgd_hyper,
27420+ .set_pgd_batched = xen_set_pgd_hyper,
27421
27422 .alloc_pud = xen_alloc_pmd_init,
27423 .release_pud = xen_release_pmd_init,
27424diff --git a/arch/x86/xen/smp.c b/arch/x86/xen/smp.c
27425index f58dca7..ad21f52 100644
27426--- a/arch/x86/xen/smp.c
27427+++ b/arch/x86/xen/smp.c
27428@@ -229,11 +229,6 @@ static void __init xen_smp_prepare_boot_cpu(void)
27429 {
27430 BUG_ON(smp_processor_id() != 0);
27431 native_smp_prepare_boot_cpu();
27432-
27433- /* We've switched to the "real" per-cpu gdt, so make sure the
27434- old memory can be recycled */
27435- make_lowmem_page_readwrite(xen_initial_gdt);
27436-
27437 xen_filter_cpu_maps();
27438 xen_setup_vcpu_info_placement();
27439 }
27440@@ -300,12 +295,12 @@ cpu_initialize_context(unsigned int cpu, struct task_struct *idle)
27441 gdt = get_cpu_gdt_table(cpu);
27442
27443 ctxt->flags = VGCF_IN_KERNEL;
27444- ctxt->user_regs.ds = __USER_DS;
27445- ctxt->user_regs.es = __USER_DS;
27446+ ctxt->user_regs.ds = __KERNEL_DS;
27447+ ctxt->user_regs.es = __KERNEL_DS;
27448 ctxt->user_regs.ss = __KERNEL_DS;
27449 #ifdef CONFIG_X86_32
27450 ctxt->user_regs.fs = __KERNEL_PERCPU;
27451- ctxt->user_regs.gs = __KERNEL_STACK_CANARY;
27452+ savesegment(gs, ctxt->user_regs.gs);
27453 #else
27454 ctxt->gs_base_kernel = per_cpu_offset(cpu);
27455 #endif
27456@@ -355,13 +350,12 @@ static int __cpuinit xen_cpu_up(unsigned int cpu, struct task_struct *idle)
27457 int rc;
27458
27459 per_cpu(current_task, cpu) = idle;
27460+ per_cpu(current_tinfo, cpu) = &idle->tinfo;
27461 #ifdef CONFIG_X86_32
27462 irq_ctx_init(cpu);
27463 #else
27464 clear_tsk_thread_flag(idle, TIF_FORK);
27465- per_cpu(kernel_stack, cpu) =
27466- (unsigned long)task_stack_page(idle) -
27467- KERNEL_STACK_OFFSET + THREAD_SIZE;
27468+ per_cpu(kernel_stack, cpu) = (unsigned long)task_stack_page(idle) - 16 + THREAD_SIZE;
27469 #endif
27470 xen_setup_runstate_info(cpu);
27471 xen_setup_timer(cpu);
27472diff --git a/arch/x86/xen/xen-asm_32.S b/arch/x86/xen/xen-asm_32.S
27473index f9643fc..602e8af 100644
27474--- a/arch/x86/xen/xen-asm_32.S
27475+++ b/arch/x86/xen/xen-asm_32.S
27476@@ -84,14 +84,14 @@ ENTRY(xen_iret)
27477 ESP_OFFSET=4 # bytes pushed onto stack
27478
27479 /*
27480- * Store vcpu_info pointer for easy access. Do it this way to
27481- * avoid having to reload %fs
27482+ * Store vcpu_info pointer for easy access.
27483 */
27484 #ifdef CONFIG_SMP
27485- GET_THREAD_INFO(%eax)
27486- movl TI_cpu(%eax), %eax
27487- movl __per_cpu_offset(,%eax,4), %eax
27488- mov xen_vcpu(%eax), %eax
27489+ push %fs
27490+ mov $(__KERNEL_PERCPU), %eax
27491+ mov %eax, %fs
27492+ mov PER_CPU_VAR(xen_vcpu), %eax
27493+ pop %fs
27494 #else
27495 movl xen_vcpu, %eax
27496 #endif
27497diff --git a/arch/x86/xen/xen-head.S b/arch/x86/xen/xen-head.S
27498index aaa7291..3f77960 100644
27499--- a/arch/x86/xen/xen-head.S
27500+++ b/arch/x86/xen/xen-head.S
27501@@ -19,6 +19,17 @@ ENTRY(startup_xen)
27502 #ifdef CONFIG_X86_32
27503 mov %esi,xen_start_info
27504 mov $init_thread_union+THREAD_SIZE,%esp
27505+#ifdef CONFIG_SMP
27506+ movl $cpu_gdt_table,%edi
27507+ movl $__per_cpu_load,%eax
27508+ movw %ax,__KERNEL_PERCPU + 2(%edi)
27509+ rorl $16,%eax
27510+ movb %al,__KERNEL_PERCPU + 4(%edi)
27511+ movb %ah,__KERNEL_PERCPU + 7(%edi)
27512+ movl $__per_cpu_end - 1,%eax
27513+ subl $__per_cpu_start,%eax
27514+ movw %ax,__KERNEL_PERCPU + 0(%edi)
27515+#endif
27516 #else
27517 mov %rsi,xen_start_info
27518 mov $init_thread_union+THREAD_SIZE,%rsp
27519diff --git a/arch/x86/xen/xen-ops.h b/arch/x86/xen/xen-ops.h
27520index 202d4c1..99b072a 100644
27521--- a/arch/x86/xen/xen-ops.h
27522+++ b/arch/x86/xen/xen-ops.h
27523@@ -10,8 +10,6 @@
27524 extern const char xen_hypervisor_callback[];
27525 extern const char xen_failsafe_callback[];
27526
27527-extern void *xen_initial_gdt;
27528-
27529 struct trap_info;
27530 void xen_copy_trap_info(struct trap_info *traps);
27531
27532diff --git a/arch/xtensa/variants/dc232b/include/variant/core.h b/arch/xtensa/variants/dc232b/include/variant/core.h
27533index 525bd3d..ef888b1 100644
27534--- a/arch/xtensa/variants/dc232b/include/variant/core.h
27535+++ b/arch/xtensa/variants/dc232b/include/variant/core.h
27536@@ -119,9 +119,9 @@
27537 ----------------------------------------------------------------------*/
27538
27539 #define XCHAL_ICACHE_LINESIZE 32 /* I-cache line size in bytes */
27540-#define XCHAL_DCACHE_LINESIZE 32 /* D-cache line size in bytes */
27541 #define XCHAL_ICACHE_LINEWIDTH 5 /* log2(I line size in bytes) */
27542 #define XCHAL_DCACHE_LINEWIDTH 5 /* log2(D line size in bytes) */
27543+#define XCHAL_DCACHE_LINESIZE (_AC(1,UL) << XCHAL_DCACHE_LINEWIDTH) /* D-cache line size in bytes */
27544
27545 #define XCHAL_ICACHE_SIZE 16384 /* I-cache size in bytes or 0 */
27546 #define XCHAL_DCACHE_SIZE 16384 /* D-cache size in bytes or 0 */
27547diff --git a/arch/xtensa/variants/fsf/include/variant/core.h b/arch/xtensa/variants/fsf/include/variant/core.h
27548index 2f33760..835e50a 100644
27549--- a/arch/xtensa/variants/fsf/include/variant/core.h
27550+++ b/arch/xtensa/variants/fsf/include/variant/core.h
27551@@ -11,6 +11,7 @@
27552 #ifndef _XTENSA_CORE_H
27553 #define _XTENSA_CORE_H
27554
27555+#include <linux/const.h>
27556
27557 /****************************************************************************
27558 Parameters Useful for Any Code, USER or PRIVILEGED
27559@@ -112,9 +113,9 @@
27560 ----------------------------------------------------------------------*/
27561
27562 #define XCHAL_ICACHE_LINESIZE 16 /* I-cache line size in bytes */
27563-#define XCHAL_DCACHE_LINESIZE 16 /* D-cache line size in bytes */
27564 #define XCHAL_ICACHE_LINEWIDTH 4 /* log2(I line size in bytes) */
27565 #define XCHAL_DCACHE_LINEWIDTH 4 /* log2(D line size in bytes) */
27566+#define XCHAL_DCACHE_LINESIZE (_AC(1,UL) << XCHAL_DCACHE_LINEWIDTH) /* D-cache line size in bytes */
27567
27568 #define XCHAL_ICACHE_SIZE 8192 /* I-cache size in bytes or 0 */
27569 #define XCHAL_DCACHE_SIZE 8192 /* D-cache size in bytes or 0 */
27570diff --git a/arch/xtensa/variants/s6000/include/variant/core.h b/arch/xtensa/variants/s6000/include/variant/core.h
27571index af00795..2bb8105 100644
27572--- a/arch/xtensa/variants/s6000/include/variant/core.h
27573+++ b/arch/xtensa/variants/s6000/include/variant/core.h
27574@@ -11,6 +11,7 @@
27575 #ifndef _XTENSA_CORE_CONFIGURATION_H
27576 #define _XTENSA_CORE_CONFIGURATION_H
27577
27578+#include <linux/const.h>
27579
27580 /****************************************************************************
27581 Parameters Useful for Any Code, USER or PRIVILEGED
27582@@ -118,9 +119,9 @@
27583 ----------------------------------------------------------------------*/
27584
27585 #define XCHAL_ICACHE_LINESIZE 16 /* I-cache line size in bytes */
27586-#define XCHAL_DCACHE_LINESIZE 16 /* D-cache line size in bytes */
27587 #define XCHAL_ICACHE_LINEWIDTH 4 /* log2(I line size in bytes) */
27588 #define XCHAL_DCACHE_LINEWIDTH 4 /* log2(D line size in bytes) */
27589+#define XCHAL_DCACHE_LINESIZE (_AC(1,UL) << XCHAL_DCACHE_LINEWIDTH) /* D-cache line size in bytes */
27590
27591 #define XCHAL_ICACHE_SIZE 32768 /* I-cache size in bytes or 0 */
27592 #define XCHAL_DCACHE_SIZE 32768 /* D-cache size in bytes or 0 */
27593diff --git a/block/blk-iopoll.c b/block/blk-iopoll.c
27594index 58916af..9cb880b 100644
27595--- a/block/blk-iopoll.c
27596+++ b/block/blk-iopoll.c
27597@@ -77,7 +77,7 @@ void blk_iopoll_complete(struct blk_iopoll *iopoll)
27598 }
27599 EXPORT_SYMBOL(blk_iopoll_complete);
27600
27601-static void blk_iopoll_softirq(struct softirq_action *h)
27602+static void blk_iopoll_softirq(void)
27603 {
27604 struct list_head *list = &__get_cpu_var(blk_cpu_iopoll);
27605 int rearm = 0, budget = blk_iopoll_budget;
27606diff --git a/block/blk-map.c b/block/blk-map.c
27607index 623e1cd..ca1e109 100644
27608--- a/block/blk-map.c
27609+++ b/block/blk-map.c
27610@@ -302,7 +302,7 @@ int blk_rq_map_kern(struct request_queue *q, struct request *rq, void *kbuf,
27611 if (!len || !kbuf)
27612 return -EINVAL;
27613
27614- do_copy = !blk_rq_aligned(q, addr, len) || object_is_on_stack(kbuf);
27615+ do_copy = !blk_rq_aligned(q, addr, len) || object_starts_on_stack(kbuf);
27616 if (do_copy)
27617 bio = bio_copy_kern(q, kbuf, len, gfp_mask, reading);
27618 else
27619diff --git a/block/blk-softirq.c b/block/blk-softirq.c
27620index 467c8de..4bddc6d 100644
27621--- a/block/blk-softirq.c
27622+++ b/block/blk-softirq.c
27623@@ -18,7 +18,7 @@ static DEFINE_PER_CPU(struct list_head, blk_cpu_done);
27624 * Softirq action handler - move entries to local list and loop over them
27625 * while passing them to the queue registered handler.
27626 */
27627-static void blk_done_softirq(struct softirq_action *h)
27628+static void blk_done_softirq(void)
27629 {
27630 struct list_head *cpu_list, local_list;
27631
27632diff --git a/block/bsg.c b/block/bsg.c
27633index ff64ae3..593560c 100644
27634--- a/block/bsg.c
27635+++ b/block/bsg.c
27636@@ -176,16 +176,24 @@ static int blk_fill_sgv4_hdr_rq(struct request_queue *q, struct request *rq,
27637 struct sg_io_v4 *hdr, struct bsg_device *bd,
27638 fmode_t has_write_perm)
27639 {
27640+ unsigned char tmpcmd[sizeof(rq->__cmd)];
27641+ unsigned char *cmdptr;
27642+
27643 if (hdr->request_len > BLK_MAX_CDB) {
27644 rq->cmd = kzalloc(hdr->request_len, GFP_KERNEL);
27645 if (!rq->cmd)
27646 return -ENOMEM;
27647- }
27648+ cmdptr = rq->cmd;
27649+ } else
27650+ cmdptr = tmpcmd;
27651
27652- if (copy_from_user(rq->cmd, (void __user *)(unsigned long)hdr->request,
27653+ if (copy_from_user(cmdptr, (void __user *)(unsigned long)hdr->request,
27654 hdr->request_len))
27655 return -EFAULT;
27656
27657+ if (cmdptr != rq->cmd)
27658+ memcpy(rq->cmd, cmdptr, hdr->request_len);
27659+
27660 if (hdr->subprotocol == BSG_SUB_PROTOCOL_SCSI_CMD) {
27661 if (blk_verify_command(rq->cmd, has_write_perm))
27662 return -EPERM;
27663diff --git a/block/compat_ioctl.c b/block/compat_ioctl.c
27664index 7c668c8..db3521c 100644
27665--- a/block/compat_ioctl.c
27666+++ b/block/compat_ioctl.c
27667@@ -340,7 +340,7 @@ static int compat_fd_ioctl(struct block_device *bdev, fmode_t mode,
27668 err |= __get_user(f->spec1, &uf->spec1);
27669 err |= __get_user(f->fmt_gap, &uf->fmt_gap);
27670 err |= __get_user(name, &uf->name);
27671- f->name = compat_ptr(name);
27672+ f->name = (void __force_kernel *)compat_ptr(name);
27673 if (err) {
27674 err = -EFAULT;
27675 goto out;
27676diff --git a/block/partitions/efi.c b/block/partitions/efi.c
27677index 6296b40..417c00f 100644
27678--- a/block/partitions/efi.c
27679+++ b/block/partitions/efi.c
27680@@ -234,14 +234,14 @@ static gpt_entry *alloc_read_gpt_entries(struct parsed_partitions *state,
27681 if (!gpt)
27682 return NULL;
27683
27684+ if (!le32_to_cpu(gpt->num_partition_entries))
27685+ return NULL;
27686+ pte = kcalloc(le32_to_cpu(gpt->num_partition_entries), le32_to_cpu(gpt->sizeof_partition_entry), GFP_KERNEL);
27687+ if (!pte)
27688+ return NULL;
27689+
27690 count = le32_to_cpu(gpt->num_partition_entries) *
27691 le32_to_cpu(gpt->sizeof_partition_entry);
27692- if (!count)
27693- return NULL;
27694- pte = kzalloc(count, GFP_KERNEL);
27695- if (!pte)
27696- return NULL;
27697-
27698 if (read_lba(state, le64_to_cpu(gpt->partition_entry_lba),
27699 (u8 *) pte,
27700 count) < count) {
27701diff --git a/block/scsi_ioctl.c b/block/scsi_ioctl.c
27702index 9a87daa..fb17486 100644
27703--- a/block/scsi_ioctl.c
27704+++ b/block/scsi_ioctl.c
27705@@ -223,8 +223,20 @@ EXPORT_SYMBOL(blk_verify_command);
27706 static int blk_fill_sghdr_rq(struct request_queue *q, struct request *rq,
27707 struct sg_io_hdr *hdr, fmode_t mode)
27708 {
27709- if (copy_from_user(rq->cmd, hdr->cmdp, hdr->cmd_len))
27710+ unsigned char tmpcmd[sizeof(rq->__cmd)];
27711+ unsigned char *cmdptr;
27712+
27713+ if (rq->cmd != rq->__cmd)
27714+ cmdptr = rq->cmd;
27715+ else
27716+ cmdptr = tmpcmd;
27717+
27718+ if (copy_from_user(cmdptr, hdr->cmdp, hdr->cmd_len))
27719 return -EFAULT;
27720+
27721+ if (cmdptr != rq->cmd)
27722+ memcpy(rq->cmd, cmdptr, hdr->cmd_len);
27723+
27724 if (blk_verify_command(rq->cmd, mode & FMODE_WRITE))
27725 return -EPERM;
27726
27727@@ -433,6 +445,8 @@ int sg_scsi_ioctl(struct request_queue *q, struct gendisk *disk, fmode_t mode,
27728 int err;
27729 unsigned int in_len, out_len, bytes, opcode, cmdlen;
27730 char *buffer = NULL, sense[SCSI_SENSE_BUFFERSIZE];
27731+ unsigned char tmpcmd[sizeof(rq->__cmd)];
27732+ unsigned char *cmdptr;
27733
27734 if (!sic)
27735 return -EINVAL;
27736@@ -466,9 +480,18 @@ int sg_scsi_ioctl(struct request_queue *q, struct gendisk *disk, fmode_t mode,
27737 */
27738 err = -EFAULT;
27739 rq->cmd_len = cmdlen;
27740- if (copy_from_user(rq->cmd, sic->data, cmdlen))
27741+
27742+ if (rq->cmd != rq->__cmd)
27743+ cmdptr = rq->cmd;
27744+ else
27745+ cmdptr = tmpcmd;
27746+
27747+ if (copy_from_user(cmdptr, sic->data, cmdlen))
27748 goto error;
27749
27750+ if (rq->cmd != cmdptr)
27751+ memcpy(rq->cmd, cmdptr, cmdlen);
27752+
27753 if (in_len && copy_from_user(buffer, sic->data + cmdlen, in_len))
27754 goto error;
27755
27756diff --git a/crypto/cryptd.c b/crypto/cryptd.c
27757index 671d4d6..5f24030 100644
27758--- a/crypto/cryptd.c
27759+++ b/crypto/cryptd.c
27760@@ -63,7 +63,7 @@ struct cryptd_blkcipher_ctx {
27761
27762 struct cryptd_blkcipher_request_ctx {
27763 crypto_completion_t complete;
27764-};
27765+} __no_const;
27766
27767 struct cryptd_hash_ctx {
27768 struct crypto_shash *child;
27769@@ -80,7 +80,7 @@ struct cryptd_aead_ctx {
27770
27771 struct cryptd_aead_request_ctx {
27772 crypto_completion_t complete;
27773-};
27774+} __no_const;
27775
27776 static void cryptd_queue_worker(struct work_struct *work);
27777
27778diff --git a/drivers/acpi/apei/cper.c b/drivers/acpi/apei/cper.c
27779index e6defd8..c26a225 100644
27780--- a/drivers/acpi/apei/cper.c
27781+++ b/drivers/acpi/apei/cper.c
27782@@ -38,12 +38,12 @@
27783 */
27784 u64 cper_next_record_id(void)
27785 {
27786- static atomic64_t seq;
27787+ static atomic64_unchecked_t seq;
27788
27789- if (!atomic64_read(&seq))
27790- atomic64_set(&seq, ((u64)get_seconds()) << 32);
27791+ if (!atomic64_read_unchecked(&seq))
27792+ atomic64_set_unchecked(&seq, ((u64)get_seconds()) << 32);
27793
27794- return atomic64_inc_return(&seq);
27795+ return atomic64_inc_return_unchecked(&seq);
27796 }
27797 EXPORT_SYMBOL_GPL(cper_next_record_id);
27798
27799diff --git a/drivers/acpi/ec_sys.c b/drivers/acpi/ec_sys.c
27800index 7586544..636a2f0 100644
27801--- a/drivers/acpi/ec_sys.c
27802+++ b/drivers/acpi/ec_sys.c
27803@@ -12,6 +12,7 @@
27804 #include <linux/acpi.h>
27805 #include <linux/debugfs.h>
27806 #include <linux/module.h>
27807+#include <linux/uaccess.h>
27808 #include "internal.h"
27809
27810 MODULE_AUTHOR("Thomas Renninger <trenn@suse.de>");
27811@@ -34,7 +35,7 @@ static ssize_t acpi_ec_read_io(struct file *f, char __user *buf,
27812 * struct acpi_ec *ec = ((struct seq_file *)f->private_data)->private;
27813 */
27814 unsigned int size = EC_SPACE_SIZE;
27815- u8 *data = (u8 *) buf;
27816+ u8 data;
27817 loff_t init_off = *off;
27818 int err = 0;
27819
27820@@ -47,9 +48,11 @@ static ssize_t acpi_ec_read_io(struct file *f, char __user *buf,
27821 size = count;
27822
27823 while (size) {
27824- err = ec_read(*off, &data[*off - init_off]);
27825+ err = ec_read(*off, &data);
27826 if (err)
27827 return err;
27828+ if (put_user(data, &buf[*off - init_off]))
27829+ return -EFAULT;
27830 *off += 1;
27831 size--;
27832 }
27833@@ -65,7 +68,6 @@ static ssize_t acpi_ec_write_io(struct file *f, const char __user *buf,
27834
27835 unsigned int size = count;
27836 loff_t init_off = *off;
27837- u8 *data = (u8 *) buf;
27838 int err = 0;
27839
27840 if (*off >= EC_SPACE_SIZE)
27841@@ -76,7 +78,9 @@ static ssize_t acpi_ec_write_io(struct file *f, const char __user *buf,
27842 }
27843
27844 while (size) {
27845- u8 byte_write = data[*off - init_off];
27846+ u8 byte_write;
27847+ if (get_user(byte_write, &buf[*off - init_off]))
27848+ return -EFAULT;
27849 err = ec_write(*off, byte_write);
27850 if (err)
27851 return err;
27852diff --git a/drivers/acpi/proc.c b/drivers/acpi/proc.c
27853index 251c7b62..000462d 100644
27854--- a/drivers/acpi/proc.c
27855+++ b/drivers/acpi/proc.c
27856@@ -343,19 +343,13 @@ acpi_system_write_wakeup_device(struct file *file,
27857 size_t count, loff_t * ppos)
27858 {
27859 struct list_head *node, *next;
27860- char strbuf[5];
27861- char str[5] = "";
27862- unsigned int len = count;
27863+ char strbuf[5] = {0};
27864
27865- if (len > 4)
27866- len = 4;
27867- if (len < 0)
27868+ if (count > 4)
27869+ count = 4;
27870+ if (copy_from_user(strbuf, buffer, count))
27871 return -EFAULT;
27872-
27873- if (copy_from_user(strbuf, buffer, len))
27874- return -EFAULT;
27875- strbuf[len] = '\0';
27876- sscanf(strbuf, "%s", str);
27877+ strbuf[count] = '\0';
27878
27879 mutex_lock(&acpi_device_lock);
27880 list_for_each_safe(node, next, &acpi_wakeup_device_list) {
27881@@ -364,7 +358,7 @@ acpi_system_write_wakeup_device(struct file *file,
27882 if (!dev->wakeup.flags.valid)
27883 continue;
27884
27885- if (!strncmp(dev->pnp.bus_id, str, 4)) {
27886+ if (!strncmp(dev->pnp.bus_id, strbuf, 4)) {
27887 if (device_can_wakeup(&dev->dev)) {
27888 bool enable = !device_may_wakeup(&dev->dev);
27889 device_set_wakeup_enable(&dev->dev, enable);
27890diff --git a/drivers/acpi/processor_driver.c b/drivers/acpi/processor_driver.c
27891index bfc31cb..8213ce1 100644
27892--- a/drivers/acpi/processor_driver.c
27893+++ b/drivers/acpi/processor_driver.c
27894@@ -551,7 +551,7 @@ static int __cpuinit acpi_processor_add(struct acpi_device *device)
27895 return 0;
27896 #endif
27897
27898- BUG_ON((pr->id >= nr_cpu_ids) || (pr->id < 0));
27899+ BUG_ON(pr->id >= nr_cpu_ids);
27900
27901 /*
27902 * Buggy BIOS check
27903diff --git a/drivers/ata/libata-core.c b/drivers/ata/libata-core.c
27904index 8e1039c..ea9cbd4 100644
27905--- a/drivers/ata/libata-core.c
27906+++ b/drivers/ata/libata-core.c
27907@@ -4750,7 +4750,7 @@ void ata_qc_free(struct ata_queued_cmd *qc)
27908 struct ata_port *ap;
27909 unsigned int tag;
27910
27911- WARN_ON_ONCE(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
27912+ BUG_ON(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
27913 ap = qc->ap;
27914
27915 qc->flags = 0;
27916@@ -4766,7 +4766,7 @@ void __ata_qc_complete(struct ata_queued_cmd *qc)
27917 struct ata_port *ap;
27918 struct ata_link *link;
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 WARN_ON_ONCE(!(qc->flags & ATA_QCFLAG_ACTIVE));
27923 ap = qc->ap;
27924 link = qc->dev->link;
27925@@ -5828,6 +5828,7 @@ static void ata_finalize_port_ops(struct ata_port_operations *ops)
27926 return;
27927
27928 spin_lock(&lock);
27929+ pax_open_kernel();
27930
27931 for (cur = ops->inherits; cur; cur = cur->inherits) {
27932 void **inherit = (void **)cur;
27933@@ -5841,8 +5842,9 @@ static void ata_finalize_port_ops(struct ata_port_operations *ops)
27934 if (IS_ERR(*pp))
27935 *pp = NULL;
27936
27937- ops->inherits = NULL;
27938+ *(struct ata_port_operations **)&ops->inherits = NULL;
27939
27940+ pax_close_kernel();
27941 spin_unlock(&lock);
27942 }
27943
27944diff --git a/drivers/ata/pata_arasan_cf.c b/drivers/ata/pata_arasan_cf.c
27945index bfaa5cb..3ba1cc3 100644
27946--- a/drivers/ata/pata_arasan_cf.c
27947+++ b/drivers/ata/pata_arasan_cf.c
27948@@ -854,7 +854,9 @@ static int __devinit arasan_cf_probe(struct platform_device *pdev)
27949 /* Handle platform specific quirks */
27950 if (pdata->quirk) {
27951 if (pdata->quirk & CF_BROKEN_PIO) {
27952- ap->ops->set_piomode = NULL;
27953+ pax_open_kernel();
27954+ *(void **)&ap->ops->set_piomode = NULL;
27955+ pax_close_kernel();
27956 ap->pio_mask = 0;
27957 }
27958 if (pdata->quirk & CF_BROKEN_MWDMA)
27959diff --git a/drivers/atm/adummy.c b/drivers/atm/adummy.c
27960index f9b983a..887b9d8 100644
27961--- a/drivers/atm/adummy.c
27962+++ b/drivers/atm/adummy.c
27963@@ -114,7 +114,7 @@ adummy_send(struct atm_vcc *vcc, struct sk_buff *skb)
27964 vcc->pop(vcc, skb);
27965 else
27966 dev_kfree_skb_any(skb);
27967- atomic_inc(&vcc->stats->tx);
27968+ atomic_inc_unchecked(&vcc->stats->tx);
27969
27970 return 0;
27971 }
27972diff --git a/drivers/atm/ambassador.c b/drivers/atm/ambassador.c
27973index 89b30f3..7964211 100644
27974--- a/drivers/atm/ambassador.c
27975+++ b/drivers/atm/ambassador.c
27976@@ -454,7 +454,7 @@ static void tx_complete (amb_dev * dev, tx_out * tx) {
27977 PRINTD (DBG_FLOW|DBG_TX, "tx_complete %p %p", dev, tx);
27978
27979 // VC layer stats
27980- atomic_inc(&ATM_SKB(skb)->vcc->stats->tx);
27981+ atomic_inc_unchecked(&ATM_SKB(skb)->vcc->stats->tx);
27982
27983 // free the descriptor
27984 kfree (tx_descr);
27985@@ -495,7 +495,7 @@ static void rx_complete (amb_dev * dev, rx_out * rx) {
27986 dump_skb ("<<<", vc, skb);
27987
27988 // VC layer stats
27989- atomic_inc(&atm_vcc->stats->rx);
27990+ atomic_inc_unchecked(&atm_vcc->stats->rx);
27991 __net_timestamp(skb);
27992 // end of our responsibility
27993 atm_vcc->push (atm_vcc, skb);
27994@@ -510,7 +510,7 @@ static void rx_complete (amb_dev * dev, rx_out * rx) {
27995 } else {
27996 PRINTK (KERN_INFO, "dropped over-size frame");
27997 // should we count this?
27998- atomic_inc(&atm_vcc->stats->rx_drop);
27999+ atomic_inc_unchecked(&atm_vcc->stats->rx_drop);
28000 }
28001
28002 } else {
28003@@ -1338,7 +1338,7 @@ static int amb_send (struct atm_vcc * atm_vcc, struct sk_buff * skb) {
28004 }
28005
28006 if (check_area (skb->data, skb->len)) {
28007- atomic_inc(&atm_vcc->stats->tx_err);
28008+ atomic_inc_unchecked(&atm_vcc->stats->tx_err);
28009 return -ENOMEM; // ?
28010 }
28011
28012diff --git a/drivers/atm/atmtcp.c b/drivers/atm/atmtcp.c
28013index b22d71c..d6e1049 100644
28014--- a/drivers/atm/atmtcp.c
28015+++ b/drivers/atm/atmtcp.c
28016@@ -207,7 +207,7 @@ static int atmtcp_v_send(struct atm_vcc *vcc,struct sk_buff *skb)
28017 if (vcc->pop) vcc->pop(vcc,skb);
28018 else dev_kfree_skb(skb);
28019 if (dev_data) return 0;
28020- atomic_inc(&vcc->stats->tx_err);
28021+ atomic_inc_unchecked(&vcc->stats->tx_err);
28022 return -ENOLINK;
28023 }
28024 size = skb->len+sizeof(struct atmtcp_hdr);
28025@@ -215,7 +215,7 @@ static int atmtcp_v_send(struct atm_vcc *vcc,struct sk_buff *skb)
28026 if (!new_skb) {
28027 if (vcc->pop) vcc->pop(vcc,skb);
28028 else dev_kfree_skb(skb);
28029- atomic_inc(&vcc->stats->tx_err);
28030+ atomic_inc_unchecked(&vcc->stats->tx_err);
28031 return -ENOBUFS;
28032 }
28033 hdr = (void *) skb_put(new_skb,sizeof(struct atmtcp_hdr));
28034@@ -226,8 +226,8 @@ static int atmtcp_v_send(struct atm_vcc *vcc,struct sk_buff *skb)
28035 if (vcc->pop) vcc->pop(vcc,skb);
28036 else dev_kfree_skb(skb);
28037 out_vcc->push(out_vcc,new_skb);
28038- atomic_inc(&vcc->stats->tx);
28039- atomic_inc(&out_vcc->stats->rx);
28040+ atomic_inc_unchecked(&vcc->stats->tx);
28041+ atomic_inc_unchecked(&out_vcc->stats->rx);
28042 return 0;
28043 }
28044
28045@@ -301,7 +301,7 @@ static int atmtcp_c_send(struct atm_vcc *vcc,struct sk_buff *skb)
28046 out_vcc = find_vcc(dev, ntohs(hdr->vpi), ntohs(hdr->vci));
28047 read_unlock(&vcc_sklist_lock);
28048 if (!out_vcc) {
28049- atomic_inc(&vcc->stats->tx_err);
28050+ atomic_inc_unchecked(&vcc->stats->tx_err);
28051 goto done;
28052 }
28053 skb_pull(skb,sizeof(struct atmtcp_hdr));
28054@@ -313,8 +313,8 @@ static int atmtcp_c_send(struct atm_vcc *vcc,struct sk_buff *skb)
28055 __net_timestamp(new_skb);
28056 skb_copy_from_linear_data(skb, skb_put(new_skb, skb->len), skb->len);
28057 out_vcc->push(out_vcc,new_skb);
28058- atomic_inc(&vcc->stats->tx);
28059- atomic_inc(&out_vcc->stats->rx);
28060+ atomic_inc_unchecked(&vcc->stats->tx);
28061+ atomic_inc_unchecked(&out_vcc->stats->rx);
28062 done:
28063 if (vcc->pop) vcc->pop(vcc,skb);
28064 else dev_kfree_skb(skb);
28065diff --git a/drivers/atm/eni.c b/drivers/atm/eni.c
28066index 2059ee4..faf51c7 100644
28067--- a/drivers/atm/eni.c
28068+++ b/drivers/atm/eni.c
28069@@ -522,7 +522,7 @@ static int rx_aal0(struct atm_vcc *vcc)
28070 DPRINTK(DEV_LABEL "(itf %d): trashing empty cell\n",
28071 vcc->dev->number);
28072 length = 0;
28073- atomic_inc(&vcc->stats->rx_err);
28074+ atomic_inc_unchecked(&vcc->stats->rx_err);
28075 }
28076 else {
28077 length = ATM_CELL_SIZE-1; /* no HEC */
28078@@ -577,7 +577,7 @@ static int rx_aal5(struct atm_vcc *vcc)
28079 size);
28080 }
28081 eff = length = 0;
28082- atomic_inc(&vcc->stats->rx_err);
28083+ atomic_inc_unchecked(&vcc->stats->rx_err);
28084 }
28085 else {
28086 size = (descr & MID_RED_COUNT)*(ATM_CELL_PAYLOAD >> 2);
28087@@ -594,7 +594,7 @@ static int rx_aal5(struct atm_vcc *vcc)
28088 "(VCI=%d,length=%ld,size=%ld (descr 0x%lx))\n",
28089 vcc->dev->number,vcc->vci,length,size << 2,descr);
28090 length = eff = 0;
28091- atomic_inc(&vcc->stats->rx_err);
28092+ atomic_inc_unchecked(&vcc->stats->rx_err);
28093 }
28094 }
28095 skb = eff ? atm_alloc_charge(vcc,eff << 2,GFP_ATOMIC) : NULL;
28096@@ -767,7 +767,7 @@ rx_dequeued++;
28097 vcc->push(vcc,skb);
28098 pushed++;
28099 }
28100- atomic_inc(&vcc->stats->rx);
28101+ atomic_inc_unchecked(&vcc->stats->rx);
28102 }
28103 wake_up(&eni_dev->rx_wait);
28104 }
28105@@ -1227,7 +1227,7 @@ static void dequeue_tx(struct atm_dev *dev)
28106 PCI_DMA_TODEVICE);
28107 if (vcc->pop) vcc->pop(vcc,skb);
28108 else dev_kfree_skb_irq(skb);
28109- atomic_inc(&vcc->stats->tx);
28110+ atomic_inc_unchecked(&vcc->stats->tx);
28111 wake_up(&eni_dev->tx_wait);
28112 dma_complete++;
28113 }
28114@@ -1567,7 +1567,7 @@ tx_complete++;
28115 /*--------------------------------- entries ---------------------------------*/
28116
28117
28118-static const char *media_name[] __devinitdata = {
28119+static const char *media_name[] __devinitconst = {
28120 "MMF", "SMF", "MMF", "03?", /* 0- 3 */
28121 "UTP", "05?", "06?", "07?", /* 4- 7 */
28122 "TAXI","09?", "10?", "11?", /* 8-11 */
28123diff --git a/drivers/atm/firestream.c b/drivers/atm/firestream.c
28124index 86fed1b..6dc4721 100644
28125--- a/drivers/atm/firestream.c
28126+++ b/drivers/atm/firestream.c
28127@@ -749,7 +749,7 @@ static void process_txdone_queue (struct fs_dev *dev, struct queue *q)
28128 }
28129 }
28130
28131- atomic_inc(&ATM_SKB(skb)->vcc->stats->tx);
28132+ atomic_inc_unchecked(&ATM_SKB(skb)->vcc->stats->tx);
28133
28134 fs_dprintk (FS_DEBUG_TXMEM, "i");
28135 fs_dprintk (FS_DEBUG_ALLOC, "Free t-skb: %p\n", skb);
28136@@ -816,7 +816,7 @@ static void process_incoming (struct fs_dev *dev, struct queue *q)
28137 #endif
28138 skb_put (skb, qe->p1 & 0xffff);
28139 ATM_SKB(skb)->vcc = atm_vcc;
28140- atomic_inc(&atm_vcc->stats->rx);
28141+ atomic_inc_unchecked(&atm_vcc->stats->rx);
28142 __net_timestamp(skb);
28143 fs_dprintk (FS_DEBUG_ALLOC, "Free rec-skb: %p (pushed)\n", skb);
28144 atm_vcc->push (atm_vcc, skb);
28145@@ -837,12 +837,12 @@ static void process_incoming (struct fs_dev *dev, struct queue *q)
28146 kfree (pe);
28147 }
28148 if (atm_vcc)
28149- atomic_inc(&atm_vcc->stats->rx_drop);
28150+ atomic_inc_unchecked(&atm_vcc->stats->rx_drop);
28151 break;
28152 case 0x1f: /* Reassembly abort: no buffers. */
28153 /* Silently increment error counter. */
28154 if (atm_vcc)
28155- atomic_inc(&atm_vcc->stats->rx_drop);
28156+ atomic_inc_unchecked(&atm_vcc->stats->rx_drop);
28157 break;
28158 default: /* Hmm. Haven't written the code to handle the others yet... -- REW */
28159 printk (KERN_WARNING "Don't know what to do with RX status %x: %s.\n",
28160diff --git a/drivers/atm/fore200e.c b/drivers/atm/fore200e.c
28161index 361f5ae..7fc552d 100644
28162--- a/drivers/atm/fore200e.c
28163+++ b/drivers/atm/fore200e.c
28164@@ -933,9 +933,9 @@ fore200e_tx_irq(struct fore200e* fore200e)
28165 #endif
28166 /* check error condition */
28167 if (*entry->status & STATUS_ERROR)
28168- atomic_inc(&vcc->stats->tx_err);
28169+ atomic_inc_unchecked(&vcc->stats->tx_err);
28170 else
28171- atomic_inc(&vcc->stats->tx);
28172+ atomic_inc_unchecked(&vcc->stats->tx);
28173 }
28174 }
28175
28176@@ -1084,7 +1084,7 @@ fore200e_push_rpd(struct fore200e* fore200e, struct atm_vcc* vcc, struct rpd* rp
28177 if (skb == NULL) {
28178 DPRINTK(2, "unable to alloc new skb, rx PDU length = %d\n", pdu_len);
28179
28180- atomic_inc(&vcc->stats->rx_drop);
28181+ atomic_inc_unchecked(&vcc->stats->rx_drop);
28182 return -ENOMEM;
28183 }
28184
28185@@ -1127,14 +1127,14 @@ fore200e_push_rpd(struct fore200e* fore200e, struct atm_vcc* vcc, struct rpd* rp
28186
28187 dev_kfree_skb_any(skb);
28188
28189- atomic_inc(&vcc->stats->rx_drop);
28190+ atomic_inc_unchecked(&vcc->stats->rx_drop);
28191 return -ENOMEM;
28192 }
28193
28194 ASSERT(atomic_read(&sk_atm(vcc)->sk_wmem_alloc) >= 0);
28195
28196 vcc->push(vcc, skb);
28197- atomic_inc(&vcc->stats->rx);
28198+ atomic_inc_unchecked(&vcc->stats->rx);
28199
28200 ASSERT(atomic_read(&sk_atm(vcc)->sk_wmem_alloc) >= 0);
28201
28202@@ -1212,7 +1212,7 @@ fore200e_rx_irq(struct fore200e* fore200e)
28203 DPRINTK(2, "damaged PDU on %d.%d.%d\n",
28204 fore200e->atm_dev->number,
28205 entry->rpd->atm_header.vpi, entry->rpd->atm_header.vci);
28206- atomic_inc(&vcc->stats->rx_err);
28207+ atomic_inc_unchecked(&vcc->stats->rx_err);
28208 }
28209 }
28210
28211@@ -1657,7 +1657,7 @@ fore200e_send(struct atm_vcc *vcc, struct sk_buff *skb)
28212 goto retry_here;
28213 }
28214
28215- atomic_inc(&vcc->stats->tx_err);
28216+ atomic_inc_unchecked(&vcc->stats->tx_err);
28217
28218 fore200e->tx_sat++;
28219 DPRINTK(2, "tx queue of device %s is saturated, PDU dropped - heartbeat is %08x\n",
28220diff --git a/drivers/atm/he.c b/drivers/atm/he.c
28221index b182c2f..1c6fa8a 100644
28222--- a/drivers/atm/he.c
28223+++ b/drivers/atm/he.c
28224@@ -1709,7 +1709,7 @@ he_service_rbrq(struct he_dev *he_dev, int group)
28225
28226 if (RBRQ_HBUF_ERR(he_dev->rbrq_head)) {
28227 hprintk("HBUF_ERR! (cid 0x%x)\n", cid);
28228- atomic_inc(&vcc->stats->rx_drop);
28229+ atomic_inc_unchecked(&vcc->stats->rx_drop);
28230 goto return_host_buffers;
28231 }
28232
28233@@ -1736,7 +1736,7 @@ he_service_rbrq(struct he_dev *he_dev, int group)
28234 RBRQ_LEN_ERR(he_dev->rbrq_head)
28235 ? "LEN_ERR" : "",
28236 vcc->vpi, vcc->vci);
28237- atomic_inc(&vcc->stats->rx_err);
28238+ atomic_inc_unchecked(&vcc->stats->rx_err);
28239 goto return_host_buffers;
28240 }
28241
28242@@ -1788,7 +1788,7 @@ he_service_rbrq(struct he_dev *he_dev, int group)
28243 vcc->push(vcc, skb);
28244 spin_lock(&he_dev->global_lock);
28245
28246- atomic_inc(&vcc->stats->rx);
28247+ atomic_inc_unchecked(&vcc->stats->rx);
28248
28249 return_host_buffers:
28250 ++pdus_assembled;
28251@@ -2114,7 +2114,7 @@ __enqueue_tpd(struct he_dev *he_dev, struct he_tpd *tpd, unsigned cid)
28252 tpd->vcc->pop(tpd->vcc, tpd->skb);
28253 else
28254 dev_kfree_skb_any(tpd->skb);
28255- atomic_inc(&tpd->vcc->stats->tx_err);
28256+ atomic_inc_unchecked(&tpd->vcc->stats->tx_err);
28257 }
28258 pci_pool_free(he_dev->tpd_pool, tpd, TPD_ADDR(tpd->status));
28259 return;
28260@@ -2526,7 +2526,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
28261 vcc->pop(vcc, skb);
28262 else
28263 dev_kfree_skb_any(skb);
28264- atomic_inc(&vcc->stats->tx_err);
28265+ atomic_inc_unchecked(&vcc->stats->tx_err);
28266 return -EINVAL;
28267 }
28268
28269@@ -2537,7 +2537,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 #endif
28278@@ -2549,7 +2549,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 spin_unlock_irqrestore(&he_dev->global_lock, flags);
28285 return -ENOMEM;
28286 }
28287@@ -2591,7 +2591,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@@ -2622,7 +2622,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
28297 __enqueue_tpd(he_dev, tpd, cid);
28298 spin_unlock_irqrestore(&he_dev->global_lock, flags);
28299
28300- atomic_inc(&vcc->stats->tx);
28301+ atomic_inc_unchecked(&vcc->stats->tx);
28302
28303 return 0;
28304 }
28305diff --git a/drivers/atm/horizon.c b/drivers/atm/horizon.c
28306index 7d01c2a..4e3ac01 100644
28307--- a/drivers/atm/horizon.c
28308+++ b/drivers/atm/horizon.c
28309@@ -1034,7 +1034,7 @@ static void rx_schedule (hrz_dev * dev, int irq) {
28310 {
28311 struct atm_vcc * vcc = ATM_SKB(skb)->vcc;
28312 // VC layer stats
28313- atomic_inc(&vcc->stats->rx);
28314+ atomic_inc_unchecked(&vcc->stats->rx);
28315 __net_timestamp(skb);
28316 // end of our responsibility
28317 vcc->push (vcc, skb);
28318@@ -1186,7 +1186,7 @@ static void tx_schedule (hrz_dev * const dev, int irq) {
28319 dev->tx_iovec = NULL;
28320
28321 // VC layer stats
28322- atomic_inc(&ATM_SKB(skb)->vcc->stats->tx);
28323+ atomic_inc_unchecked(&ATM_SKB(skb)->vcc->stats->tx);
28324
28325 // free the skb
28326 hrz_kfree_skb (skb);
28327diff --git a/drivers/atm/idt77252.c b/drivers/atm/idt77252.c
28328index 8974bd2..b856f85 100644
28329--- a/drivers/atm/idt77252.c
28330+++ b/drivers/atm/idt77252.c
28331@@ -812,7 +812,7 @@ drain_scq(struct idt77252_dev *card, struct vc_map *vc)
28332 else
28333 dev_kfree_skb(skb);
28334
28335- atomic_inc(&vcc->stats->tx);
28336+ atomic_inc_unchecked(&vcc->stats->tx);
28337 }
28338
28339 atomic_dec(&scq->used);
28340@@ -1075,13 +1075,13 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
28341 if ((sb = dev_alloc_skb(64)) == NULL) {
28342 printk("%s: Can't allocate buffers for aal0.\n",
28343 card->name);
28344- atomic_add(i, &vcc->stats->rx_drop);
28345+ atomic_add_unchecked(i, &vcc->stats->rx_drop);
28346 break;
28347 }
28348 if (!atm_charge(vcc, sb->truesize)) {
28349 RXPRINTK("%s: atm_charge() dropped aal0 packets.\n",
28350 card->name);
28351- atomic_add(i - 1, &vcc->stats->rx_drop);
28352+ atomic_add_unchecked(i - 1, &vcc->stats->rx_drop);
28353 dev_kfree_skb(sb);
28354 break;
28355 }
28356@@ -1098,7 +1098,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
28357 ATM_SKB(sb)->vcc = vcc;
28358 __net_timestamp(sb);
28359 vcc->push(vcc, sb);
28360- atomic_inc(&vcc->stats->rx);
28361+ atomic_inc_unchecked(&vcc->stats->rx);
28362
28363 cell += ATM_CELL_PAYLOAD;
28364 }
28365@@ -1135,13 +1135,13 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
28366 "(CDC: %08x)\n",
28367 card->name, len, rpp->len, readl(SAR_REG_CDC));
28368 recycle_rx_pool_skb(card, rpp);
28369- atomic_inc(&vcc->stats->rx_err);
28370+ atomic_inc_unchecked(&vcc->stats->rx_err);
28371 return;
28372 }
28373 if (stat & SAR_RSQE_CRC) {
28374 RXPRINTK("%s: AAL5 CRC error.\n", card->name);
28375 recycle_rx_pool_skb(card, rpp);
28376- atomic_inc(&vcc->stats->rx_err);
28377+ atomic_inc_unchecked(&vcc->stats->rx_err);
28378 return;
28379 }
28380 if (skb_queue_len(&rpp->queue) > 1) {
28381@@ -1152,7 +1152,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
28382 RXPRINTK("%s: Can't alloc RX skb.\n",
28383 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 (!atm_charge(vcc, skb->truesize)) {
28390@@ -1171,7 +1171,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
28391 __net_timestamp(skb);
28392
28393 vcc->push(vcc, skb);
28394- atomic_inc(&vcc->stats->rx);
28395+ atomic_inc_unchecked(&vcc->stats->rx);
28396
28397 return;
28398 }
28399@@ -1193,7 +1193,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 if (skb->truesize > SAR_FB_SIZE_3)
28407 add_rx_skb(card, 3, SAR_FB_SIZE_3, 1);
28408@@ -1304,14 +1304,14 @@ idt77252_rx_raw(struct idt77252_dev *card)
28409 if (vcc->qos.aal != ATM_AAL0) {
28410 RPRINTK("%s: raw cell for non AAL0 vc %u.%u\n",
28411 card->name, vpi, vci);
28412- atomic_inc(&vcc->stats->rx_drop);
28413+ atomic_inc_unchecked(&vcc->stats->rx_drop);
28414 goto drop;
28415 }
28416
28417 if ((sb = dev_alloc_skb(64)) == NULL) {
28418 printk("%s: Can't allocate buffers for AAL0.\n",
28419 card->name);
28420- atomic_inc(&vcc->stats->rx_err);
28421+ atomic_inc_unchecked(&vcc->stats->rx_err);
28422 goto drop;
28423 }
28424
28425@@ -1330,7 +1330,7 @@ idt77252_rx_raw(struct idt77252_dev *card)
28426 ATM_SKB(sb)->vcc = vcc;
28427 __net_timestamp(sb);
28428 vcc->push(vcc, sb);
28429- atomic_inc(&vcc->stats->rx);
28430+ atomic_inc_unchecked(&vcc->stats->rx);
28431
28432 drop:
28433 skb_pull(queue, 64);
28434@@ -1955,13 +1955,13 @@ idt77252_send_skb(struct atm_vcc *vcc, struct sk_buff *skb, int oam)
28435
28436 if (vc == NULL) {
28437 printk("%s: NULL connection in send().\n", card->name);
28438- atomic_inc(&vcc->stats->tx_err);
28439+ atomic_inc_unchecked(&vcc->stats->tx_err);
28440 dev_kfree_skb(skb);
28441 return -EINVAL;
28442 }
28443 if (!test_bit(VCF_TX, &vc->flags)) {
28444 printk("%s: Trying to transmit on a non-tx VC.\n", card->name);
28445- atomic_inc(&vcc->stats->tx_err);
28446+ atomic_inc_unchecked(&vcc->stats->tx_err);
28447 dev_kfree_skb(skb);
28448 return -EINVAL;
28449 }
28450@@ -1973,14 +1973,14 @@ idt77252_send_skb(struct atm_vcc *vcc, struct sk_buff *skb, int oam)
28451 break;
28452 default:
28453 printk("%s: Unsupported AAL: %d\n", card->name, vcc->qos.aal);
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
28460 if (skb_shinfo(skb)->nr_frags != 0) {
28461 printk("%s: No scatter-gather yet.\n", card->name);
28462- atomic_inc(&vcc->stats->tx_err);
28463+ atomic_inc_unchecked(&vcc->stats->tx_err);
28464 dev_kfree_skb(skb);
28465 return -EINVAL;
28466 }
28467@@ -1988,7 +1988,7 @@ idt77252_send_skb(struct atm_vcc *vcc, struct sk_buff *skb, int oam)
28468
28469 err = queue_skb(card, vc, skb, oam);
28470 if (err) {
28471- atomic_inc(&vcc->stats->tx_err);
28472+ atomic_inc_unchecked(&vcc->stats->tx_err);
28473 dev_kfree_skb(skb);
28474 return err;
28475 }
28476@@ -2011,7 +2011,7 @@ idt77252_send_oam(struct atm_vcc *vcc, void *cell, int flags)
28477 skb = dev_alloc_skb(64);
28478 if (!skb) {
28479 printk("%s: Out of memory in send_oam().\n", card->name);
28480- atomic_inc(&vcc->stats->tx_err);
28481+ atomic_inc_unchecked(&vcc->stats->tx_err);
28482 return -ENOMEM;
28483 }
28484 atomic_add(skb->truesize, &sk_atm(vcc)->sk_wmem_alloc);
28485diff --git a/drivers/atm/iphase.c b/drivers/atm/iphase.c
28486index 96cce6d..62c3ec5 100644
28487--- a/drivers/atm/iphase.c
28488+++ b/drivers/atm/iphase.c
28489@@ -1145,7 +1145,7 @@ static int rx_pkt(struct atm_dev *dev)
28490 status = (u_short) (buf_desc_ptr->desc_mode);
28491 if (status & (RX_CER | RX_PTE | RX_OFL))
28492 {
28493- atomic_inc(&vcc->stats->rx_err);
28494+ atomic_inc_unchecked(&vcc->stats->rx_err);
28495 IF_ERR(printk("IA: bad packet, dropping it");)
28496 if (status & RX_CER) {
28497 IF_ERR(printk(" cause: packet CRC error\n");)
28498@@ -1168,7 +1168,7 @@ static int rx_pkt(struct atm_dev *dev)
28499 len = dma_addr - buf_addr;
28500 if (len > iadev->rx_buf_sz) {
28501 printk("Over %d bytes sdu received, dropped!!!\n", iadev->rx_buf_sz);
28502- atomic_inc(&vcc->stats->rx_err);
28503+ atomic_inc_unchecked(&vcc->stats->rx_err);
28504 goto out_free_desc;
28505 }
28506
28507@@ -1318,7 +1318,7 @@ static void rx_dle_intr(struct atm_dev *dev)
28508 ia_vcc = INPH_IA_VCC(vcc);
28509 if (ia_vcc == NULL)
28510 {
28511- atomic_inc(&vcc->stats->rx_err);
28512+ atomic_inc_unchecked(&vcc->stats->rx_err);
28513 atm_return(vcc, skb->truesize);
28514 dev_kfree_skb_any(skb);
28515 goto INCR_DLE;
28516@@ -1330,7 +1330,7 @@ static void rx_dle_intr(struct atm_dev *dev)
28517 if ((length > iadev->rx_buf_sz) || (length >
28518 (skb->len - sizeof(struct cpcs_trailer))))
28519 {
28520- atomic_inc(&vcc->stats->rx_err);
28521+ atomic_inc_unchecked(&vcc->stats->rx_err);
28522 IF_ERR(printk("rx_dle_intr: Bad AAL5 trailer %d (skb len %d)",
28523 length, skb->len);)
28524 atm_return(vcc, skb->truesize);
28525@@ -1346,7 +1346,7 @@ static void rx_dle_intr(struct atm_dev *dev)
28526
28527 IF_RX(printk("rx_dle_intr: skb push");)
28528 vcc->push(vcc,skb);
28529- atomic_inc(&vcc->stats->rx);
28530+ atomic_inc_unchecked(&vcc->stats->rx);
28531 iadev->rx_pkt_cnt++;
28532 }
28533 INCR_DLE:
28534@@ -2826,15 +2826,15 @@ static int ia_ioctl(struct atm_dev *dev, unsigned int cmd, void __user *arg)
28535 {
28536 struct k_sonet_stats *stats;
28537 stats = &PRIV(_ia_dev[board])->sonet_stats;
28538- printk("section_bip: %d\n", atomic_read(&stats->section_bip));
28539- printk("line_bip : %d\n", atomic_read(&stats->line_bip));
28540- printk("path_bip : %d\n", atomic_read(&stats->path_bip));
28541- printk("line_febe : %d\n", atomic_read(&stats->line_febe));
28542- printk("path_febe : %d\n", atomic_read(&stats->path_febe));
28543- printk("corr_hcs : %d\n", atomic_read(&stats->corr_hcs));
28544- printk("uncorr_hcs : %d\n", atomic_read(&stats->uncorr_hcs));
28545- printk("tx_cells : %d\n", atomic_read(&stats->tx_cells));
28546- printk("rx_cells : %d\n", atomic_read(&stats->rx_cells));
28547+ printk("section_bip: %d\n", atomic_read_unchecked(&stats->section_bip));
28548+ printk("line_bip : %d\n", atomic_read_unchecked(&stats->line_bip));
28549+ printk("path_bip : %d\n", atomic_read_unchecked(&stats->path_bip));
28550+ printk("line_febe : %d\n", atomic_read_unchecked(&stats->line_febe));
28551+ printk("path_febe : %d\n", atomic_read_unchecked(&stats->path_febe));
28552+ printk("corr_hcs : %d\n", atomic_read_unchecked(&stats->corr_hcs));
28553+ printk("uncorr_hcs : %d\n", atomic_read_unchecked(&stats->uncorr_hcs));
28554+ printk("tx_cells : %d\n", atomic_read_unchecked(&stats->tx_cells));
28555+ printk("rx_cells : %d\n", atomic_read_unchecked(&stats->rx_cells));
28556 }
28557 ia_cmds.status = 0;
28558 break;
28559@@ -2939,7 +2939,7 @@ static int ia_pkt_tx (struct atm_vcc *vcc, struct sk_buff *skb) {
28560 if ((desc == 0) || (desc > iadev->num_tx_desc))
28561 {
28562 IF_ERR(printk(DEV_LABEL "invalid desc for send: %d\n", desc);)
28563- atomic_inc(&vcc->stats->tx);
28564+ atomic_inc_unchecked(&vcc->stats->tx);
28565 if (vcc->pop)
28566 vcc->pop(vcc, skb);
28567 else
28568@@ -3044,14 +3044,14 @@ static int ia_pkt_tx (struct atm_vcc *vcc, struct sk_buff *skb) {
28569 ATM_DESC(skb) = vcc->vci;
28570 skb_queue_tail(&iadev->tx_dma_q, skb);
28571
28572- atomic_inc(&vcc->stats->tx);
28573+ atomic_inc_unchecked(&vcc->stats->tx);
28574 iadev->tx_pkt_cnt++;
28575 /* Increment transaction counter */
28576 writel(2, iadev->dma+IPHASE5575_TX_COUNTER);
28577
28578 #if 0
28579 /* add flow control logic */
28580- if (atomic_read(&vcc->stats->tx) % 20 == 0) {
28581+ if (atomic_read_unchecked(&vcc->stats->tx) % 20 == 0) {
28582 if (iavcc->vc_desc_cnt > 10) {
28583 vcc->tx_quota = vcc->tx_quota * 3 / 4;
28584 printk("Tx1: vcc->tx_quota = %d \n", (u32)vcc->tx_quota );
28585diff --git a/drivers/atm/lanai.c b/drivers/atm/lanai.c
28586index 68c7588..7036683 100644
28587--- a/drivers/atm/lanai.c
28588+++ b/drivers/atm/lanai.c
28589@@ -1303,7 +1303,7 @@ static void lanai_send_one_aal5(struct lanai_dev *lanai,
28590 vcc_tx_add_aal5_trailer(lvcc, skb->len, 0, 0);
28591 lanai_endtx(lanai, lvcc);
28592 lanai_free_skb(lvcc->tx.atmvcc, skb);
28593- atomic_inc(&lvcc->tx.atmvcc->stats->tx);
28594+ atomic_inc_unchecked(&lvcc->tx.atmvcc->stats->tx);
28595 }
28596
28597 /* Try to fill the buffer - don't call unless there is backlog */
28598@@ -1426,7 +1426,7 @@ static void vcc_rx_aal5(struct lanai_vcc *lvcc, int endptr)
28599 ATM_SKB(skb)->vcc = lvcc->rx.atmvcc;
28600 __net_timestamp(skb);
28601 lvcc->rx.atmvcc->push(lvcc->rx.atmvcc, skb);
28602- atomic_inc(&lvcc->rx.atmvcc->stats->rx);
28603+ atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx);
28604 out:
28605 lvcc->rx.buf.ptr = end;
28606 cardvcc_write(lvcc, endptr, vcc_rxreadptr);
28607@@ -1667,7 +1667,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
28608 DPRINTK("(itf %d) got RX service entry 0x%X for non-AAL5 "
28609 "vcc %d\n", lanai->number, (unsigned int) s, vci);
28610 lanai->stats.service_rxnotaal5++;
28611- atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
28612+ atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
28613 return 0;
28614 }
28615 if (likely(!(s & (SERVICE_TRASH | SERVICE_STREAM | SERVICE_CRCERR)))) {
28616@@ -1679,7 +1679,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
28617 int bytes;
28618 read_unlock(&vcc_sklist_lock);
28619 DPRINTK("got trashed rx pdu on vci %d\n", vci);
28620- atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
28621+ atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
28622 lvcc->stats.x.aal5.service_trash++;
28623 bytes = (SERVICE_GET_END(s) * 16) -
28624 (((unsigned long) lvcc->rx.buf.ptr) -
28625@@ -1691,7 +1691,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
28626 }
28627 if (s & SERVICE_STREAM) {
28628 read_unlock(&vcc_sklist_lock);
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_stream++;
28632 printk(KERN_ERR DEV_LABEL "(itf %d): Got AAL5 stream "
28633 "PDU on VCI %d!\n", lanai->number, vci);
28634@@ -1699,7 +1699,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
28635 return 0;
28636 }
28637 DPRINTK("got rx crc error on vci %d\n", vci);
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_rxcrc++;
28641 lvcc->rx.buf.ptr = &lvcc->rx.buf.start[SERVICE_GET_END(s) * 4];
28642 cardvcc_write(lvcc, SERVICE_GET_END(s), vcc_rxreadptr);
28643diff --git a/drivers/atm/nicstar.c b/drivers/atm/nicstar.c
28644index 1c70c45..300718d 100644
28645--- a/drivers/atm/nicstar.c
28646+++ b/drivers/atm/nicstar.c
28647@@ -1654,7 +1654,7 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
28648 if ((vc = (vc_map *) vcc->dev_data) == NULL) {
28649 printk("nicstar%d: vcc->dev_data == NULL on ns_send().\n",
28650 card->index);
28651- atomic_inc(&vcc->stats->tx_err);
28652+ atomic_inc_unchecked(&vcc->stats->tx_err);
28653 dev_kfree_skb_any(skb);
28654 return -EINVAL;
28655 }
28656@@ -1662,7 +1662,7 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
28657 if (!vc->tx) {
28658 printk("nicstar%d: Trying to transmit on a non-tx VC.\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@@ -1670,14 +1670,14 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
28666 if (vcc->qos.aal != ATM_AAL5 && vcc->qos.aal != ATM_AAL0) {
28667 printk("nicstar%d: Only AAL0 and AAL5 are supported.\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
28675 if (skb_shinfo(skb)->nr_frags != 0) {
28676 printk("nicstar%d: No scatter-gather yet.\n", card->index);
28677- atomic_inc(&vcc->stats->tx_err);
28678+ atomic_inc_unchecked(&vcc->stats->tx_err);
28679 dev_kfree_skb_any(skb);
28680 return -EINVAL;
28681 }
28682@@ -1725,11 +1725,11 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
28683 }
28684
28685 if (push_scqe(card, vc, scq, &scqe, skb) != 0) {
28686- atomic_inc(&vcc->stats->tx_err);
28687+ atomic_inc_unchecked(&vcc->stats->tx_err);
28688 dev_kfree_skb_any(skb);
28689 return -EIO;
28690 }
28691- atomic_inc(&vcc->stats->tx);
28692+ atomic_inc_unchecked(&vcc->stats->tx);
28693
28694 return 0;
28695 }
28696@@ -2046,14 +2046,14 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28697 printk
28698 ("nicstar%d: Can't allocate buffers for aal0.\n",
28699 card->index);
28700- atomic_add(i, &vcc->stats->rx_drop);
28701+ atomic_add_unchecked(i, &vcc->stats->rx_drop);
28702 break;
28703 }
28704 if (!atm_charge(vcc, sb->truesize)) {
28705 RXPRINTK
28706 ("nicstar%d: atm_charge() dropped aal0 packets.\n",
28707 card->index);
28708- atomic_add(i - 1, &vcc->stats->rx_drop); /* already increased by 1 */
28709+ atomic_add_unchecked(i - 1, &vcc->stats->rx_drop); /* already increased by 1 */
28710 dev_kfree_skb_any(sb);
28711 break;
28712 }
28713@@ -2068,7 +2068,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28714 ATM_SKB(sb)->vcc = vcc;
28715 __net_timestamp(sb);
28716 vcc->push(vcc, sb);
28717- atomic_inc(&vcc->stats->rx);
28718+ atomic_inc_unchecked(&vcc->stats->rx);
28719 cell += ATM_CELL_PAYLOAD;
28720 }
28721
28722@@ -2085,7 +2085,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28723 if (iovb == NULL) {
28724 printk("nicstar%d: Out of iovec buffers.\n",
28725 card->index);
28726- atomic_inc(&vcc->stats->rx_drop);
28727+ atomic_inc_unchecked(&vcc->stats->rx_drop);
28728 recycle_rx_buf(card, skb);
28729 return;
28730 }
28731@@ -2109,7 +2109,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28732 small or large buffer itself. */
28733 } else if (NS_PRV_IOVCNT(iovb) >= NS_MAX_IOVECS) {
28734 printk("nicstar%d: received too big AAL5 SDU.\n", card->index);
28735- atomic_inc(&vcc->stats->rx_err);
28736+ atomic_inc_unchecked(&vcc->stats->rx_err);
28737 recycle_iovec_rx_bufs(card, (struct iovec *)iovb->data,
28738 NS_MAX_IOVECS);
28739 NS_PRV_IOVCNT(iovb) = 0;
28740@@ -2129,7 +2129,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28741 ("nicstar%d: Expected a small buffer, and this is not one.\n",
28742 card->index);
28743 which_list(card, skb);
28744- atomic_inc(&vcc->stats->rx_err);
28745+ atomic_inc_unchecked(&vcc->stats->rx_err);
28746 recycle_rx_buf(card, skb);
28747 vc->rx_iov = NULL;
28748 recycle_iov_buf(card, iovb);
28749@@ -2142,7 +2142,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28750 ("nicstar%d: Expected a large 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_iovec_rx_bufs(card, (struct iovec *)iovb->data,
28756 NS_PRV_IOVCNT(iovb));
28757 vc->rx_iov = NULL;
28758@@ -2165,7 +2165,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28759 printk(" - PDU size mismatch.\n");
28760 else
28761 printk(".\n");
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@@ -2179,7 +2179,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28768 /* skb points to a small buffer */
28769 if (!atm_charge(vcc, skb->truesize)) {
28770 push_rxbufs(card, skb);
28771- atomic_inc(&vcc->stats->rx_drop);
28772+ atomic_inc_unchecked(&vcc->stats->rx_drop);
28773 } else {
28774 skb_put(skb, len);
28775 dequeue_sm_buf(card, skb);
28776@@ -2189,7 +2189,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28777 ATM_SKB(skb)->vcc = vcc;
28778 __net_timestamp(skb);
28779 vcc->push(vcc, skb);
28780- atomic_inc(&vcc->stats->rx);
28781+ atomic_inc_unchecked(&vcc->stats->rx);
28782 }
28783 } else if (NS_PRV_IOVCNT(iovb) == 2) { /* One small plus one large buffer */
28784 struct sk_buff *sb;
28785@@ -2200,7 +2200,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28786 if (len <= NS_SMBUFSIZE) {
28787 if (!atm_charge(vcc, sb->truesize)) {
28788 push_rxbufs(card, sb);
28789- atomic_inc(&vcc->stats->rx_drop);
28790+ atomic_inc_unchecked(&vcc->stats->rx_drop);
28791 } else {
28792 skb_put(sb, len);
28793 dequeue_sm_buf(card, sb);
28794@@ -2210,7 +2210,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28795 ATM_SKB(sb)->vcc = vcc;
28796 __net_timestamp(sb);
28797 vcc->push(vcc, sb);
28798- atomic_inc(&vcc->stats->rx);
28799+ atomic_inc_unchecked(&vcc->stats->rx);
28800 }
28801
28802 push_rxbufs(card, skb);
28803@@ -2219,7 +2219,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28804
28805 if (!atm_charge(vcc, skb->truesize)) {
28806 push_rxbufs(card, skb);
28807- atomic_inc(&vcc->stats->rx_drop);
28808+ atomic_inc_unchecked(&vcc->stats->rx_drop);
28809 } else {
28810 dequeue_lg_buf(card, skb);
28811 #ifdef NS_USE_DESTRUCTORS
28812@@ -2232,7 +2232,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28813 ATM_SKB(skb)->vcc = vcc;
28814 __net_timestamp(skb);
28815 vcc->push(vcc, skb);
28816- atomic_inc(&vcc->stats->rx);
28817+ atomic_inc_unchecked(&vcc->stats->rx);
28818 }
28819
28820 push_rxbufs(card, sb);
28821@@ -2253,7 +2253,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28822 printk
28823 ("nicstar%d: Out of huge buffers.\n",
28824 card->index);
28825- atomic_inc(&vcc->stats->rx_drop);
28826+ atomic_inc_unchecked(&vcc->stats->rx_drop);
28827 recycle_iovec_rx_bufs(card,
28828 (struct iovec *)
28829 iovb->data,
28830@@ -2304,7 +2304,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28831 card->hbpool.count++;
28832 } else
28833 dev_kfree_skb_any(hb);
28834- atomic_inc(&vcc->stats->rx_drop);
28835+ atomic_inc_unchecked(&vcc->stats->rx_drop);
28836 } else {
28837 /* Copy the small buffer to the huge buffer */
28838 sb = (struct sk_buff *)iov->iov_base;
28839@@ -2341,7 +2341,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28840 #endif /* NS_USE_DESTRUCTORS */
28841 __net_timestamp(hb);
28842 vcc->push(vcc, hb);
28843- atomic_inc(&vcc->stats->rx);
28844+ atomic_inc_unchecked(&vcc->stats->rx);
28845 }
28846 }
28847
28848diff --git a/drivers/atm/solos-pci.c b/drivers/atm/solos-pci.c
28849index 9851093..adb2b1e 100644
28850--- a/drivers/atm/solos-pci.c
28851+++ b/drivers/atm/solos-pci.c
28852@@ -714,7 +714,7 @@ void solos_bh(unsigned long card_arg)
28853 }
28854 atm_charge(vcc, skb->truesize);
28855 vcc->push(vcc, skb);
28856- atomic_inc(&vcc->stats->rx);
28857+ atomic_inc_unchecked(&vcc->stats->rx);
28858 break;
28859
28860 case PKT_STATUS:
28861@@ -1009,7 +1009,7 @@ static uint32_t fpga_tx(struct solos_card *card)
28862 vcc = SKB_CB(oldskb)->vcc;
28863
28864 if (vcc) {
28865- atomic_inc(&vcc->stats->tx);
28866+ atomic_inc_unchecked(&vcc->stats->tx);
28867 solos_pop(vcc, oldskb);
28868 } else
28869 dev_kfree_skb_irq(oldskb);
28870diff --git a/drivers/atm/suni.c b/drivers/atm/suni.c
28871index 0215934..ce9f5b1 100644
28872--- a/drivers/atm/suni.c
28873+++ b/drivers/atm/suni.c
28874@@ -49,8 +49,8 @@ static DEFINE_SPINLOCK(sunis_lock);
28875
28876
28877 #define ADD_LIMITED(s,v) \
28878- atomic_add((v),&stats->s); \
28879- if (atomic_read(&stats->s) < 0) atomic_set(&stats->s,INT_MAX);
28880+ atomic_add_unchecked((v),&stats->s); \
28881+ if (atomic_read_unchecked(&stats->s) < 0) atomic_set_unchecked(&stats->s,INT_MAX);
28882
28883
28884 static void suni_hz(unsigned long from_timer)
28885diff --git a/drivers/atm/uPD98402.c b/drivers/atm/uPD98402.c
28886index 5120a96..e2572bd 100644
28887--- a/drivers/atm/uPD98402.c
28888+++ b/drivers/atm/uPD98402.c
28889@@ -42,7 +42,7 @@ static int fetch_stats(struct atm_dev *dev,struct sonet_stats __user *arg,int ze
28890 struct sonet_stats tmp;
28891 int error = 0;
28892
28893- atomic_add(GET(HECCT),&PRIV(dev)->sonet_stats.uncorr_hcs);
28894+ atomic_add_unchecked(GET(HECCT),&PRIV(dev)->sonet_stats.uncorr_hcs);
28895 sonet_copy_stats(&PRIV(dev)->sonet_stats,&tmp);
28896 if (arg) error = copy_to_user(arg,&tmp,sizeof(tmp));
28897 if (zero && !error) {
28898@@ -161,9 +161,9 @@ static int uPD98402_ioctl(struct atm_dev *dev,unsigned int cmd,void __user *arg)
28899
28900
28901 #define ADD_LIMITED(s,v) \
28902- { atomic_add(GET(v),&PRIV(dev)->sonet_stats.s); \
28903- if (atomic_read(&PRIV(dev)->sonet_stats.s) < 0) \
28904- atomic_set(&PRIV(dev)->sonet_stats.s,INT_MAX); }
28905+ { atomic_add_unchecked(GET(v),&PRIV(dev)->sonet_stats.s); \
28906+ if (atomic_read_unchecked(&PRIV(dev)->sonet_stats.s) < 0) \
28907+ atomic_set_unchecked(&PRIV(dev)->sonet_stats.s,INT_MAX); }
28908
28909
28910 static void stat_event(struct atm_dev *dev)
28911@@ -194,7 +194,7 @@ static void uPD98402_int(struct atm_dev *dev)
28912 if (reason & uPD98402_INT_PFM) stat_event(dev);
28913 if (reason & uPD98402_INT_PCO) {
28914 (void) GET(PCOCR); /* clear interrupt cause */
28915- atomic_add(GET(HECCT),
28916+ atomic_add_unchecked(GET(HECCT),
28917 &PRIV(dev)->sonet_stats.uncorr_hcs);
28918 }
28919 if ((reason & uPD98402_INT_RFO) &&
28920@@ -222,9 +222,9 @@ static int uPD98402_start(struct atm_dev *dev)
28921 PUT(~(uPD98402_INT_PFM | uPD98402_INT_ALM | uPD98402_INT_RFO |
28922 uPD98402_INT_LOS),PIMR); /* enable them */
28923 (void) fetch_stats(dev,NULL,1); /* clear kernel counters */
28924- atomic_set(&PRIV(dev)->sonet_stats.corr_hcs,-1);
28925- atomic_set(&PRIV(dev)->sonet_stats.tx_cells,-1);
28926- atomic_set(&PRIV(dev)->sonet_stats.rx_cells,-1);
28927+ atomic_set_unchecked(&PRIV(dev)->sonet_stats.corr_hcs,-1);
28928+ atomic_set_unchecked(&PRIV(dev)->sonet_stats.tx_cells,-1);
28929+ atomic_set_unchecked(&PRIV(dev)->sonet_stats.rx_cells,-1);
28930 return 0;
28931 }
28932
28933diff --git a/drivers/atm/zatm.c b/drivers/atm/zatm.c
28934index abe4e20..83c4727 100644
28935--- a/drivers/atm/zatm.c
28936+++ b/drivers/atm/zatm.c
28937@@ -459,7 +459,7 @@ printk("dummy: 0x%08lx, 0x%08lx\n",dummy[0],dummy[1]);
28938 }
28939 if (!size) {
28940 dev_kfree_skb_irq(skb);
28941- if (vcc) atomic_inc(&vcc->stats->rx_err);
28942+ if (vcc) atomic_inc_unchecked(&vcc->stats->rx_err);
28943 continue;
28944 }
28945 if (!atm_charge(vcc,skb->truesize)) {
28946@@ -469,7 +469,7 @@ printk("dummy: 0x%08lx, 0x%08lx\n",dummy[0],dummy[1]);
28947 skb->len = size;
28948 ATM_SKB(skb)->vcc = vcc;
28949 vcc->push(vcc,skb);
28950- atomic_inc(&vcc->stats->rx);
28951+ atomic_inc_unchecked(&vcc->stats->rx);
28952 }
28953 zout(pos & 0xffff,MTA(mbx));
28954 #if 0 /* probably a stupid idea */
28955@@ -733,7 +733,7 @@ if (*ZATM_PRV_DSC(skb) != (uPD98401_TXPD_V | uPD98401_TXPD_DP |
28956 skb_queue_head(&zatm_vcc->backlog,skb);
28957 break;
28958 }
28959- atomic_inc(&vcc->stats->tx);
28960+ atomic_inc_unchecked(&vcc->stats->tx);
28961 wake_up(&zatm_vcc->tx_wait);
28962 }
28963
28964diff --git a/drivers/base/devtmpfs.c b/drivers/base/devtmpfs.c
28965index deb4a45..211eff2 100644
28966--- a/drivers/base/devtmpfs.c
28967+++ b/drivers/base/devtmpfs.c
28968@@ -347,7 +347,7 @@ int devtmpfs_mount(const char *mntdir)
28969 if (!thread)
28970 return 0;
28971
28972- err = sys_mount("devtmpfs", (char *)mntdir, "devtmpfs", MS_SILENT, NULL);
28973+ err = sys_mount((char __force_user *)"devtmpfs", (char __force_user *)mntdir, (char __force_user *)"devtmpfs", MS_SILENT, NULL);
28974 if (err)
28975 printk(KERN_INFO "devtmpfs: error mounting %i\n", err);
28976 else
28977diff --git a/drivers/base/power/wakeup.c b/drivers/base/power/wakeup.c
28978index cbb463b..babe2cf 100644
28979--- a/drivers/base/power/wakeup.c
28980+++ b/drivers/base/power/wakeup.c
28981@@ -29,14 +29,14 @@ bool events_check_enabled __read_mostly;
28982 * They need to be modified together atomically, so it's better to use one
28983 * atomic variable to hold them both.
28984 */
28985-static atomic_t combined_event_count = ATOMIC_INIT(0);
28986+static atomic_unchecked_t combined_event_count = ATOMIC_INIT(0);
28987
28988 #define IN_PROGRESS_BITS (sizeof(int) * 4)
28989 #define MAX_IN_PROGRESS ((1 << IN_PROGRESS_BITS) - 1)
28990
28991 static void split_counters(unsigned int *cnt, unsigned int *inpr)
28992 {
28993- unsigned int comb = atomic_read(&combined_event_count);
28994+ unsigned int comb = atomic_read_unchecked(&combined_event_count);
28995
28996 *cnt = (comb >> IN_PROGRESS_BITS);
28997 *inpr = comb & MAX_IN_PROGRESS;
28998@@ -385,7 +385,7 @@ static void wakeup_source_activate(struct wakeup_source *ws)
28999 ws->start_prevent_time = ws->last_time;
29000
29001 /* Increment the counter of events in progress. */
29002- cec = atomic_inc_return(&combined_event_count);
29003+ cec = atomic_inc_return_unchecked(&combined_event_count);
29004
29005 trace_wakeup_source_activate(ws->name, cec);
29006 }
29007@@ -511,7 +511,7 @@ static void wakeup_source_deactivate(struct wakeup_source *ws)
29008 * Increment the counter of registered wakeup events and decrement the
29009 * couter of wakeup events in progress simultaneously.
29010 */
29011- cec = atomic_add_return(MAX_IN_PROGRESS, &combined_event_count);
29012+ cec = atomic_add_return_unchecked(MAX_IN_PROGRESS, &combined_event_count);
29013 trace_wakeup_source_deactivate(ws->name, cec);
29014
29015 split_counters(&cnt, &inpr);
29016diff --git a/drivers/block/cciss.c b/drivers/block/cciss.c
29017index b0f553b..77b928b 100644
29018--- a/drivers/block/cciss.c
29019+++ b/drivers/block/cciss.c
29020@@ -1198,6 +1198,8 @@ static int cciss_ioctl32_passthru(struct block_device *bdev, fmode_t mode,
29021 int err;
29022 u32 cp;
29023
29024+ memset(&arg64, 0, sizeof(arg64));
29025+
29026 err = 0;
29027 err |=
29028 copy_from_user(&arg64.LUN_info, &arg32->LUN_info,
29029@@ -3007,7 +3009,7 @@ static void start_io(ctlr_info_t *h)
29030 while (!list_empty(&h->reqQ)) {
29031 c = list_entry(h->reqQ.next, CommandList_struct, list);
29032 /* can't do anything if fifo is full */
29033- if ((h->access.fifo_full(h))) {
29034+ if ((h->access->fifo_full(h))) {
29035 dev_warn(&h->pdev->dev, "fifo full\n");
29036 break;
29037 }
29038@@ -3017,7 +3019,7 @@ static void start_io(ctlr_info_t *h)
29039 h->Qdepth--;
29040
29041 /* Tell the controller execute command */
29042- h->access.submit_command(h, c);
29043+ h->access->submit_command(h, c);
29044
29045 /* Put job onto the completed Q */
29046 addQ(&h->cmpQ, c);
29047@@ -3443,17 +3445,17 @@ startio:
29048
29049 static inline unsigned long get_next_completion(ctlr_info_t *h)
29050 {
29051- return h->access.command_completed(h);
29052+ return h->access->command_completed(h);
29053 }
29054
29055 static inline int interrupt_pending(ctlr_info_t *h)
29056 {
29057- return h->access.intr_pending(h);
29058+ return h->access->intr_pending(h);
29059 }
29060
29061 static inline long interrupt_not_for_us(ctlr_info_t *h)
29062 {
29063- return ((h->access.intr_pending(h) == 0) ||
29064+ return ((h->access->intr_pending(h) == 0) ||
29065 (h->interrupts_enabled == 0));
29066 }
29067
29068@@ -3486,7 +3488,7 @@ static inline u32 next_command(ctlr_info_t *h)
29069 u32 a;
29070
29071 if (unlikely(!(h->transMethod & CFGTBL_Trans_Performant)))
29072- return h->access.command_completed(h);
29073+ return h->access->command_completed(h);
29074
29075 if ((*(h->reply_pool_head) & 1) == (h->reply_pool_wraparound)) {
29076 a = *(h->reply_pool_head); /* Next cmd in ring buffer */
29077@@ -4044,7 +4046,7 @@ static void __devinit cciss_put_controller_into_performant_mode(ctlr_info_t *h)
29078 trans_support & CFGTBL_Trans_use_short_tags);
29079
29080 /* Change the access methods to the performant access methods */
29081- h->access = SA5_performant_access;
29082+ h->access = &SA5_performant_access;
29083 h->transMethod = CFGTBL_Trans_Performant;
29084
29085 return;
29086@@ -4316,7 +4318,7 @@ static int __devinit cciss_pci_init(ctlr_info_t *h)
29087 if (prod_index < 0)
29088 return -ENODEV;
29089 h->product_name = products[prod_index].product_name;
29090- h->access = *(products[prod_index].access);
29091+ h->access = products[prod_index].access;
29092
29093 if (cciss_board_disabled(h)) {
29094 dev_warn(&h->pdev->dev, "controller appears to be disabled\n");
29095@@ -5041,7 +5043,7 @@ reinit_after_soft_reset:
29096 }
29097
29098 /* make sure the board interrupts are off */
29099- h->access.set_intr_mask(h, CCISS_INTR_OFF);
29100+ h->access->set_intr_mask(h, CCISS_INTR_OFF);
29101 rc = cciss_request_irq(h, do_cciss_msix_intr, do_cciss_intx);
29102 if (rc)
29103 goto clean2;
29104@@ -5093,7 +5095,7 @@ reinit_after_soft_reset:
29105 * fake ones to scoop up any residual completions.
29106 */
29107 spin_lock_irqsave(&h->lock, flags);
29108- h->access.set_intr_mask(h, CCISS_INTR_OFF);
29109+ h->access->set_intr_mask(h, CCISS_INTR_OFF);
29110 spin_unlock_irqrestore(&h->lock, flags);
29111 free_irq(h->intr[h->intr_mode], h);
29112 rc = cciss_request_irq(h, cciss_msix_discard_completions,
29113@@ -5113,9 +5115,9 @@ reinit_after_soft_reset:
29114 dev_info(&h->pdev->dev, "Board READY.\n");
29115 dev_info(&h->pdev->dev,
29116 "Waiting for stale completions to drain.\n");
29117- h->access.set_intr_mask(h, CCISS_INTR_ON);
29118+ h->access->set_intr_mask(h, CCISS_INTR_ON);
29119 msleep(10000);
29120- h->access.set_intr_mask(h, CCISS_INTR_OFF);
29121+ h->access->set_intr_mask(h, CCISS_INTR_OFF);
29122
29123 rc = controller_reset_failed(h->cfgtable);
29124 if (rc)
29125@@ -5138,7 +5140,7 @@ reinit_after_soft_reset:
29126 cciss_scsi_setup(h);
29127
29128 /* Turn the interrupts on so we can service requests */
29129- h->access.set_intr_mask(h, CCISS_INTR_ON);
29130+ h->access->set_intr_mask(h, CCISS_INTR_ON);
29131
29132 /* Get the firmware version */
29133 inq_buff = kzalloc(sizeof(InquiryData_struct), GFP_KERNEL);
29134@@ -5211,7 +5213,7 @@ static void cciss_shutdown(struct pci_dev *pdev)
29135 kfree(flush_buf);
29136 if (return_code != IO_OK)
29137 dev_warn(&h->pdev->dev, "Error flushing cache\n");
29138- h->access.set_intr_mask(h, CCISS_INTR_OFF);
29139+ h->access->set_intr_mask(h, CCISS_INTR_OFF);
29140 free_irq(h->intr[h->intr_mode], h);
29141 }
29142
29143diff --git a/drivers/block/cciss.h b/drivers/block/cciss.h
29144index 7fda30e..eb5dfe0 100644
29145--- a/drivers/block/cciss.h
29146+++ b/drivers/block/cciss.h
29147@@ -101,7 +101,7 @@ struct ctlr_info
29148 /* information about each logical volume */
29149 drive_info_struct *drv[CISS_MAX_LUN];
29150
29151- struct access_method access;
29152+ struct access_method *access;
29153
29154 /* queue and queue Info */
29155 struct list_head reqQ;
29156diff --git a/drivers/block/cpqarray.c b/drivers/block/cpqarray.c
29157index 9125bbe..eede5c8 100644
29158--- a/drivers/block/cpqarray.c
29159+++ b/drivers/block/cpqarray.c
29160@@ -404,7 +404,7 @@ static int __devinit cpqarray_register_ctlr( int i, struct pci_dev *pdev)
29161 if (register_blkdev(COMPAQ_SMART2_MAJOR+i, hba[i]->devname)) {
29162 goto Enomem4;
29163 }
29164- hba[i]->access.set_intr_mask(hba[i], 0);
29165+ hba[i]->access->set_intr_mask(hba[i], 0);
29166 if (request_irq(hba[i]->intr, do_ida_intr,
29167 IRQF_DISABLED|IRQF_SHARED, hba[i]->devname, hba[i]))
29168 {
29169@@ -459,7 +459,7 @@ static int __devinit cpqarray_register_ctlr( int i, struct pci_dev *pdev)
29170 add_timer(&hba[i]->timer);
29171
29172 /* Enable IRQ now that spinlock and rate limit timer are set up */
29173- hba[i]->access.set_intr_mask(hba[i], FIFO_NOT_EMPTY);
29174+ hba[i]->access->set_intr_mask(hba[i], FIFO_NOT_EMPTY);
29175
29176 for(j=0; j<NWD; j++) {
29177 struct gendisk *disk = ida_gendisk[i][j];
29178@@ -694,7 +694,7 @@ DBGINFO(
29179 for(i=0; i<NR_PRODUCTS; i++) {
29180 if (board_id == products[i].board_id) {
29181 c->product_name = products[i].product_name;
29182- c->access = *(products[i].access);
29183+ c->access = products[i].access;
29184 break;
29185 }
29186 }
29187@@ -792,7 +792,7 @@ static int __devinit cpqarray_eisa_detect(void)
29188 hba[ctlr]->intr = intr;
29189 sprintf(hba[ctlr]->devname, "ida%d", nr_ctlr);
29190 hba[ctlr]->product_name = products[j].product_name;
29191- hba[ctlr]->access = *(products[j].access);
29192+ hba[ctlr]->access = products[j].access;
29193 hba[ctlr]->ctlr = ctlr;
29194 hba[ctlr]->board_id = board_id;
29195 hba[ctlr]->pci_dev = NULL; /* not PCI */
29196@@ -980,7 +980,7 @@ static void start_io(ctlr_info_t *h)
29197
29198 while((c = h->reqQ) != NULL) {
29199 /* Can't do anything if we're busy */
29200- if (h->access.fifo_full(h) == 0)
29201+ if (h->access->fifo_full(h) == 0)
29202 return;
29203
29204 /* Get the first entry from the request Q */
29205@@ -988,7 +988,7 @@ static void start_io(ctlr_info_t *h)
29206 h->Qdepth--;
29207
29208 /* Tell the controller to do our bidding */
29209- h->access.submit_command(h, c);
29210+ h->access->submit_command(h, c);
29211
29212 /* Get onto the completion Q */
29213 addQ(&h->cmpQ, c);
29214@@ -1050,7 +1050,7 @@ static irqreturn_t do_ida_intr(int irq, void *dev_id)
29215 unsigned long flags;
29216 __u32 a,a1;
29217
29218- istat = h->access.intr_pending(h);
29219+ istat = h->access->intr_pending(h);
29220 /* Is this interrupt for us? */
29221 if (istat == 0)
29222 return IRQ_NONE;
29223@@ -1061,7 +1061,7 @@ static irqreturn_t do_ida_intr(int irq, void *dev_id)
29224 */
29225 spin_lock_irqsave(IDA_LOCK(h->ctlr), flags);
29226 if (istat & FIFO_NOT_EMPTY) {
29227- while((a = h->access.command_completed(h))) {
29228+ while((a = h->access->command_completed(h))) {
29229 a1 = a; a &= ~3;
29230 if ((c = h->cmpQ) == NULL)
29231 {
29232@@ -1449,11 +1449,11 @@ static int sendcmd(
29233 /*
29234 * Disable interrupt
29235 */
29236- info_p->access.set_intr_mask(info_p, 0);
29237+ info_p->access->set_intr_mask(info_p, 0);
29238 /* Make sure there is room in the command FIFO */
29239 /* Actually it should be completely empty at this time. */
29240 for (i = 200000; i > 0; i--) {
29241- temp = info_p->access.fifo_full(info_p);
29242+ temp = info_p->access->fifo_full(info_p);
29243 if (temp != 0) {
29244 break;
29245 }
29246@@ -1466,7 +1466,7 @@ DBG(
29247 /*
29248 * Send the cmd
29249 */
29250- info_p->access.submit_command(info_p, c);
29251+ info_p->access->submit_command(info_p, c);
29252 complete = pollcomplete(ctlr);
29253
29254 pci_unmap_single(info_p->pci_dev, (dma_addr_t) c->req.sg[0].addr,
29255@@ -1549,9 +1549,9 @@ static int revalidate_allvol(ctlr_info_t *host)
29256 * we check the new geometry. Then turn interrupts back on when
29257 * we're done.
29258 */
29259- host->access.set_intr_mask(host, 0);
29260+ host->access->set_intr_mask(host, 0);
29261 getgeometry(ctlr);
29262- host->access.set_intr_mask(host, FIFO_NOT_EMPTY);
29263+ host->access->set_intr_mask(host, FIFO_NOT_EMPTY);
29264
29265 for(i=0; i<NWD; i++) {
29266 struct gendisk *disk = ida_gendisk[ctlr][i];
29267@@ -1591,7 +1591,7 @@ static int pollcomplete(int ctlr)
29268 /* Wait (up to 2 seconds) for a command to complete */
29269
29270 for (i = 200000; i > 0; i--) {
29271- done = hba[ctlr]->access.command_completed(hba[ctlr]);
29272+ done = hba[ctlr]->access->command_completed(hba[ctlr]);
29273 if (done == 0) {
29274 udelay(10); /* a short fixed delay */
29275 } else
29276diff --git a/drivers/block/cpqarray.h b/drivers/block/cpqarray.h
29277index be73e9d..7fbf140 100644
29278--- a/drivers/block/cpqarray.h
29279+++ b/drivers/block/cpqarray.h
29280@@ -99,7 +99,7 @@ struct ctlr_info {
29281 drv_info_t drv[NWD];
29282 struct proc_dir_entry *proc;
29283
29284- struct access_method access;
29285+ struct access_method *access;
29286
29287 cmdlist_t *reqQ;
29288 cmdlist_t *cmpQ;
29289diff --git a/drivers/block/drbd/drbd_int.h b/drivers/block/drbd/drbd_int.h
29290index b953cc7..e3dc580 100644
29291--- a/drivers/block/drbd/drbd_int.h
29292+++ b/drivers/block/drbd/drbd_int.h
29293@@ -735,7 +735,7 @@ struct drbd_request;
29294 struct drbd_epoch {
29295 struct list_head list;
29296 unsigned int barrier_nr;
29297- atomic_t epoch_size; /* increased on every request added. */
29298+ atomic_unchecked_t epoch_size; /* increased on every request added. */
29299 atomic_t active; /* increased on every req. added, and dec on every finished. */
29300 unsigned long flags;
29301 };
29302@@ -1116,7 +1116,7 @@ struct drbd_conf {
29303 void *int_dig_in;
29304 void *int_dig_vv;
29305 wait_queue_head_t seq_wait;
29306- atomic_t packet_seq;
29307+ atomic_unchecked_t packet_seq;
29308 unsigned int peer_seq;
29309 spinlock_t peer_seq_lock;
29310 unsigned int minor;
29311@@ -1658,30 +1658,30 @@ static inline int drbd_setsockopt(struct socket *sock, int level, int optname,
29312
29313 static inline void drbd_tcp_cork(struct socket *sock)
29314 {
29315- int __user val = 1;
29316+ int val = 1;
29317 (void) drbd_setsockopt(sock, SOL_TCP, TCP_CORK,
29318- (char __user *)&val, sizeof(val));
29319+ (char __force_user *)&val, sizeof(val));
29320 }
29321
29322 static inline void drbd_tcp_uncork(struct socket *sock)
29323 {
29324- int __user val = 0;
29325+ int val = 0;
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_nodelay(struct socket *sock)
29332 {
29333- int __user val = 1;
29334+ int val = 1;
29335 (void) drbd_setsockopt(sock, SOL_TCP, TCP_NODELAY,
29336- (char __user *)&val, sizeof(val));
29337+ (char __force_user *)&val, sizeof(val));
29338 }
29339
29340 static inline void drbd_tcp_quickack(struct socket *sock)
29341 {
29342- int __user val = 2;
29343+ int val = 2;
29344 (void) drbd_setsockopt(sock, SOL_TCP, TCP_QUICKACK,
29345- (char __user *)&val, sizeof(val));
29346+ (char __force_user *)&val, sizeof(val));
29347 }
29348
29349 void drbd_bump_write_ordering(struct drbd_conf *mdev, enum write_ordering_e wo);
29350diff --git a/drivers/block/drbd/drbd_main.c b/drivers/block/drbd/drbd_main.c
29351index f93a032..71c87bf 100644
29352--- a/drivers/block/drbd/drbd_main.c
29353+++ b/drivers/block/drbd/drbd_main.c
29354@@ -2567,7 +2567,7 @@ static int _drbd_send_ack(struct drbd_conf *mdev, enum drbd_packets cmd,
29355 p.sector = sector;
29356 p.block_id = block_id;
29357 p.blksize = blksize;
29358- p.seq_num = cpu_to_be32(atomic_add_return(1, &mdev->packet_seq));
29359+ p.seq_num = cpu_to_be32(atomic_add_return_unchecked(1, &mdev->packet_seq));
29360
29361 if (!mdev->meta.socket || mdev->state.conn < C_CONNECTED)
29362 return false;
29363@@ -2865,7 +2865,7 @@ int drbd_send_dblock(struct drbd_conf *mdev, struct drbd_request *req)
29364
29365 p.sector = cpu_to_be64(req->sector);
29366 p.block_id = (unsigned long)req;
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 dp_flags = bio_flags_to_wire(mdev, req->master_bio->bi_rw);
29371
29372@@ -3150,7 +3150,7 @@ void drbd_init_set_defaults(struct drbd_conf *mdev)
29373 atomic_set(&mdev->unacked_cnt, 0);
29374 atomic_set(&mdev->local_cnt, 0);
29375 atomic_set(&mdev->net_cnt, 0);
29376- atomic_set(&mdev->packet_seq, 0);
29377+ atomic_set_unchecked(&mdev->packet_seq, 0);
29378 atomic_set(&mdev->pp_in_use, 0);
29379 atomic_set(&mdev->pp_in_use_by_net, 0);
29380 atomic_set(&mdev->rs_sect_in, 0);
29381@@ -3232,8 +3232,8 @@ void drbd_mdev_cleanup(struct drbd_conf *mdev)
29382 mdev->receiver.t_state);
29383
29384 /* no need to lock it, I'm the only thread alive */
29385- if (atomic_read(&mdev->current_epoch->epoch_size) != 0)
29386- dev_err(DEV, "epoch_size:%d\n", atomic_read(&mdev->current_epoch->epoch_size));
29387+ if (atomic_read_unchecked(&mdev->current_epoch->epoch_size) != 0)
29388+ dev_err(DEV, "epoch_size:%d\n", atomic_read_unchecked(&mdev->current_epoch->epoch_size));
29389 mdev->al_writ_cnt =
29390 mdev->bm_writ_cnt =
29391 mdev->read_cnt =
29392diff --git a/drivers/block/drbd/drbd_nl.c b/drivers/block/drbd/drbd_nl.c
29393index edb490a..ecd69da 100644
29394--- a/drivers/block/drbd/drbd_nl.c
29395+++ b/drivers/block/drbd/drbd_nl.c
29396@@ -2407,7 +2407,7 @@ static void drbd_connector_callback(struct cn_msg *req, struct netlink_skb_parms
29397 module_put(THIS_MODULE);
29398 }
29399
29400-static atomic_t drbd_nl_seq = ATOMIC_INIT(2); /* two. */
29401+static atomic_unchecked_t drbd_nl_seq = ATOMIC_INIT(2); /* two. */
29402
29403 static unsigned short *
29404 __tl_add_blob(unsigned short *tl, enum drbd_tags tag, const void *data,
29405@@ -2478,7 +2478,7 @@ void drbd_bcast_state(struct drbd_conf *mdev, union drbd_state state)
29406 cn_reply->id.idx = CN_IDX_DRBD;
29407 cn_reply->id.val = CN_VAL_DRBD;
29408
29409- cn_reply->seq = atomic_add_return(1, &drbd_nl_seq);
29410+ cn_reply->seq = atomic_add_return_unchecked(1, &drbd_nl_seq);
29411 cn_reply->ack = 0; /* not used here. */
29412 cn_reply->len = sizeof(struct drbd_nl_cfg_reply) +
29413 (int)((char *)tl - (char *)reply->tag_list);
29414@@ -2510,7 +2510,7 @@ void drbd_bcast_ev_helper(struct drbd_conf *mdev, char *helper_name)
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@@ -2588,7 +2588,7 @@ void drbd_bcast_ee(struct drbd_conf *mdev,
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@@ -2627,7 +2627,7 @@ void drbd_bcast_sync_progress(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);
29441diff --git a/drivers/block/drbd/drbd_receiver.c b/drivers/block/drbd/drbd_receiver.c
29442index c74ca2d..860c819 100644
29443--- a/drivers/block/drbd/drbd_receiver.c
29444+++ b/drivers/block/drbd/drbd_receiver.c
29445@@ -898,7 +898,7 @@ retry:
29446 sock->sk->sk_sndtimeo = mdev->net_conf->timeout*HZ/10;
29447 sock->sk->sk_rcvtimeo = MAX_SCHEDULE_TIMEOUT;
29448
29449- atomic_set(&mdev->packet_seq, 0);
29450+ atomic_set_unchecked(&mdev->packet_seq, 0);
29451 mdev->peer_seq = 0;
29452
29453 if (drbd_send_protocol(mdev) == -1)
29454@@ -999,7 +999,7 @@ static enum finish_epoch drbd_may_finish_epoch(struct drbd_conf *mdev,
29455 do {
29456 next_epoch = NULL;
29457
29458- epoch_size = atomic_read(&epoch->epoch_size);
29459+ epoch_size = atomic_read_unchecked(&epoch->epoch_size);
29460
29461 switch (ev & ~EV_CLEANUP) {
29462 case EV_PUT:
29463@@ -1035,7 +1035,7 @@ static enum finish_epoch drbd_may_finish_epoch(struct drbd_conf *mdev,
29464 rv = FE_DESTROYED;
29465 } else {
29466 epoch->flags = 0;
29467- atomic_set(&epoch->epoch_size, 0);
29468+ atomic_set_unchecked(&epoch->epoch_size, 0);
29469 /* atomic_set(&epoch->active, 0); is already zero */
29470 if (rv == FE_STILL_LIVE)
29471 rv = FE_RECYCLED;
29472@@ -1210,14 +1210,14 @@ static int receive_Barrier(struct drbd_conf *mdev, enum drbd_packets cmd, unsign
29473 drbd_wait_ee_list_empty(mdev, &mdev->active_ee);
29474 drbd_flush(mdev);
29475
29476- if (atomic_read(&mdev->current_epoch->epoch_size)) {
29477+ if (atomic_read_unchecked(&mdev->current_epoch->epoch_size)) {
29478 epoch = kmalloc(sizeof(struct drbd_epoch), GFP_NOIO);
29479 if (epoch)
29480 break;
29481 }
29482
29483 epoch = mdev->current_epoch;
29484- wait_event(mdev->ee_wait, atomic_read(&epoch->epoch_size) == 0);
29485+ wait_event(mdev->ee_wait, atomic_read_unchecked(&epoch->epoch_size) == 0);
29486
29487 D_ASSERT(atomic_read(&epoch->active) == 0);
29488 D_ASSERT(epoch->flags == 0);
29489@@ -1229,11 +1229,11 @@ static int receive_Barrier(struct drbd_conf *mdev, enum drbd_packets cmd, unsign
29490 }
29491
29492 epoch->flags = 0;
29493- atomic_set(&epoch->epoch_size, 0);
29494+ atomic_set_unchecked(&epoch->epoch_size, 0);
29495 atomic_set(&epoch->active, 0);
29496
29497 spin_lock(&mdev->epoch_lock);
29498- if (atomic_read(&mdev->current_epoch->epoch_size)) {
29499+ if (atomic_read_unchecked(&mdev->current_epoch->epoch_size)) {
29500 list_add(&epoch->list, &mdev->current_epoch->list);
29501 mdev->current_epoch = epoch;
29502 mdev->epochs++;
29503@@ -1702,7 +1702,7 @@ static int receive_Data(struct drbd_conf *mdev, enum drbd_packets cmd, unsigned
29504 spin_unlock(&mdev->peer_seq_lock);
29505
29506 drbd_send_ack_dp(mdev, P_NEG_ACK, p, data_size);
29507- atomic_inc(&mdev->current_epoch->epoch_size);
29508+ atomic_inc_unchecked(&mdev->current_epoch->epoch_size);
29509 return drbd_drain_block(mdev, data_size);
29510 }
29511
29512@@ -1732,7 +1732,7 @@ static int receive_Data(struct drbd_conf *mdev, enum drbd_packets cmd, unsigned
29513
29514 spin_lock(&mdev->epoch_lock);
29515 e->epoch = mdev->current_epoch;
29516- atomic_inc(&e->epoch->epoch_size);
29517+ atomic_inc_unchecked(&e->epoch->epoch_size);
29518 atomic_inc(&e->epoch->active);
29519 spin_unlock(&mdev->epoch_lock);
29520
29521@@ -3954,7 +3954,7 @@ static void drbd_disconnect(struct drbd_conf *mdev)
29522 D_ASSERT(list_empty(&mdev->done_ee));
29523
29524 /* ok, no more ee's on the fly, it is safe to reset the epoch_size */
29525- atomic_set(&mdev->current_epoch->epoch_size, 0);
29526+ atomic_set_unchecked(&mdev->current_epoch->epoch_size, 0);
29527 D_ASSERT(list_empty(&mdev->current_epoch->list));
29528 }
29529
29530diff --git a/drivers/block/loop.c b/drivers/block/loop.c
29531index 3bba655..6151b66 100644
29532--- a/drivers/block/loop.c
29533+++ b/drivers/block/loop.c
29534@@ -226,7 +226,7 @@ static int __do_lo_send_write(struct file *file,
29535 mm_segment_t old_fs = get_fs();
29536
29537 set_fs(get_ds());
29538- bw = file->f_op->write(file, buf, len, &pos);
29539+ bw = file->f_op->write(file, (const char __force_user *)buf, len, &pos);
29540 set_fs(old_fs);
29541 if (likely(bw == len))
29542 return 0;
29543diff --git a/drivers/char/Kconfig b/drivers/char/Kconfig
29544index ea6f632..eafb192 100644
29545--- a/drivers/char/Kconfig
29546+++ b/drivers/char/Kconfig
29547@@ -8,7 +8,8 @@ source "drivers/tty/Kconfig"
29548
29549 config DEVKMEM
29550 bool "/dev/kmem virtual device support"
29551- default y
29552+ default n
29553+ depends on !GRKERNSEC_KMEM
29554 help
29555 Say Y here if you want to support the /dev/kmem device. The
29556 /dev/kmem device is rarely used, but can be used for certain
29557@@ -581,6 +582,7 @@ config DEVPORT
29558 bool
29559 depends on !M68K
29560 depends on ISA || PCI
29561+ depends on !GRKERNSEC_KMEM
29562 default y
29563
29564 source "drivers/s390/char/Kconfig"
29565diff --git a/drivers/char/agp/frontend.c b/drivers/char/agp/frontend.c
29566index 2e04433..22afc64 100644
29567--- a/drivers/char/agp/frontend.c
29568+++ b/drivers/char/agp/frontend.c
29569@@ -817,7 +817,7 @@ static int agpioc_reserve_wrap(struct agp_file_private *priv, void __user *arg)
29570 if (copy_from_user(&reserve, arg, sizeof(struct agp_region)))
29571 return -EFAULT;
29572
29573- if ((unsigned) reserve.seg_count >= ~0U/sizeof(struct agp_segment))
29574+ if ((unsigned) reserve.seg_count >= ~0U/sizeof(struct agp_segment_priv))
29575 return -EFAULT;
29576
29577 client = agp_find_client_by_pid(reserve.pid);
29578diff --git a/drivers/char/genrtc.c b/drivers/char/genrtc.c
29579index 21cb980..f15107c 100644
29580--- a/drivers/char/genrtc.c
29581+++ b/drivers/char/genrtc.c
29582@@ -272,6 +272,7 @@ static int gen_rtc_ioctl(struct file *file,
29583 switch (cmd) {
29584
29585 case RTC_PLL_GET:
29586+ memset(&pll, 0, sizeof(pll));
29587 if (get_rtc_pll(&pll))
29588 return -EINVAL;
29589 else
29590diff --git a/drivers/char/hpet.c b/drivers/char/hpet.c
29591index dfd7876..c0b0885 100644
29592--- a/drivers/char/hpet.c
29593+++ b/drivers/char/hpet.c
29594@@ -571,7 +571,7 @@ static inline unsigned long hpet_time_div(struct hpets *hpets,
29595 }
29596
29597 static int
29598-hpet_ioctl_common(struct hpet_dev *devp, int cmd, unsigned long arg,
29599+hpet_ioctl_common(struct hpet_dev *devp, unsigned int cmd, unsigned long arg,
29600 struct hpet_info *info)
29601 {
29602 struct hpet_timer __iomem *timer;
29603diff --git a/drivers/char/ipmi/ipmi_msghandler.c b/drivers/char/ipmi/ipmi_msghandler.c
29604index 2c29942..604c5ba 100644
29605--- a/drivers/char/ipmi/ipmi_msghandler.c
29606+++ b/drivers/char/ipmi/ipmi_msghandler.c
29607@@ -420,7 +420,7 @@ struct ipmi_smi {
29608 struct proc_dir_entry *proc_dir;
29609 char proc_dir_name[10];
29610
29611- atomic_t stats[IPMI_NUM_STATS];
29612+ atomic_unchecked_t stats[IPMI_NUM_STATS];
29613
29614 /*
29615 * run_to_completion duplicate of smb_info, smi_info
29616@@ -453,9 +453,9 @@ static DEFINE_MUTEX(smi_watchers_mutex);
29617
29618
29619 #define ipmi_inc_stat(intf, stat) \
29620- atomic_inc(&(intf)->stats[IPMI_STAT_ ## stat])
29621+ atomic_inc_unchecked(&(intf)->stats[IPMI_STAT_ ## stat])
29622 #define ipmi_get_stat(intf, stat) \
29623- ((unsigned int) atomic_read(&(intf)->stats[IPMI_STAT_ ## stat]))
29624+ ((unsigned int) atomic_read_unchecked(&(intf)->stats[IPMI_STAT_ ## stat]))
29625
29626 static int is_lan_addr(struct ipmi_addr *addr)
29627 {
29628@@ -2884,7 +2884,7 @@ int ipmi_register_smi(struct ipmi_smi_handlers *handlers,
29629 INIT_LIST_HEAD(&intf->cmd_rcvrs);
29630 init_waitqueue_head(&intf->waitq);
29631 for (i = 0; i < IPMI_NUM_STATS; i++)
29632- atomic_set(&intf->stats[i], 0);
29633+ atomic_set_unchecked(&intf->stats[i], 0);
29634
29635 intf->proc_dir = NULL;
29636
29637diff --git a/drivers/char/ipmi/ipmi_si_intf.c b/drivers/char/ipmi/ipmi_si_intf.c
29638index 83f85cf..279e63f 100644
29639--- a/drivers/char/ipmi/ipmi_si_intf.c
29640+++ b/drivers/char/ipmi/ipmi_si_intf.c
29641@@ -275,7 +275,7 @@ struct smi_info {
29642 unsigned char slave_addr;
29643
29644 /* Counters and things for the proc filesystem. */
29645- atomic_t stats[SI_NUM_STATS];
29646+ atomic_unchecked_t stats[SI_NUM_STATS];
29647
29648 struct task_struct *thread;
29649
29650@@ -284,9 +284,9 @@ struct smi_info {
29651 };
29652
29653 #define smi_inc_stat(smi, stat) \
29654- atomic_inc(&(smi)->stats[SI_STAT_ ## stat])
29655+ atomic_inc_unchecked(&(smi)->stats[SI_STAT_ ## stat])
29656 #define smi_get_stat(smi, stat) \
29657- ((unsigned int) atomic_read(&(smi)->stats[SI_STAT_ ## stat]))
29658+ ((unsigned int) atomic_read_unchecked(&(smi)->stats[SI_STAT_ ## stat]))
29659
29660 #define SI_MAX_PARMS 4
29661
29662@@ -3193,7 +3193,7 @@ static int try_smi_init(struct smi_info *new_smi)
29663 atomic_set(&new_smi->req_events, 0);
29664 new_smi->run_to_completion = 0;
29665 for (i = 0; i < SI_NUM_STATS; i++)
29666- atomic_set(&new_smi->stats[i], 0);
29667+ atomic_set_unchecked(&new_smi->stats[i], 0);
29668
29669 new_smi->interrupt_disabled = 1;
29670 atomic_set(&new_smi->stop_operation, 0);
29671diff --git a/drivers/char/mbcs.c b/drivers/char/mbcs.c
29672index 47ff7e4..0c7d340 100644
29673--- a/drivers/char/mbcs.c
29674+++ b/drivers/char/mbcs.c
29675@@ -799,7 +799,7 @@ static int mbcs_remove(struct cx_dev *dev)
29676 return 0;
29677 }
29678
29679-static const struct cx_device_id __devinitdata mbcs_id_table[] = {
29680+static const struct cx_device_id __devinitconst mbcs_id_table[] = {
29681 {
29682 .part_num = MBCS_PART_NUM,
29683 .mfg_num = MBCS_MFG_NUM,
29684diff --git a/drivers/char/mem.c b/drivers/char/mem.c
29685index e5eedfa..fcab50ea 100644
29686--- a/drivers/char/mem.c
29687+++ b/drivers/char/mem.c
29688@@ -18,6 +18,7 @@
29689 #include <linux/raw.h>
29690 #include <linux/tty.h>
29691 #include <linux/capability.h>
29692+#include <linux/security.h>
29693 #include <linux/ptrace.h>
29694 #include <linux/device.h>
29695 #include <linux/highmem.h>
29696@@ -37,6 +38,10 @@
29697
29698 #define DEVPORT_MINOR 4
29699
29700+#if defined(CONFIG_GRKERNSEC) && !defined(CONFIG_GRKERNSEC_NO_RBAC)
29701+extern const struct file_operations grsec_fops;
29702+#endif
29703+
29704 static inline unsigned long size_inside_page(unsigned long start,
29705 unsigned long size)
29706 {
29707@@ -68,9 +73,13 @@ static inline int range_is_allowed(unsigned long pfn, unsigned long size)
29708
29709 while (cursor < to) {
29710 if (!devmem_is_allowed(pfn)) {
29711+#ifdef CONFIG_GRKERNSEC_KMEM
29712+ gr_handle_mem_readwrite(from, to);
29713+#else
29714 printk(KERN_INFO
29715 "Program %s tried to access /dev/mem between %Lx->%Lx.\n",
29716 current->comm, from, to);
29717+#endif
29718 return 0;
29719 }
29720 cursor += PAGE_SIZE;
29721@@ -78,6 +87,11 @@ static inline int range_is_allowed(unsigned long pfn, unsigned long size)
29722 }
29723 return 1;
29724 }
29725+#elif defined(CONFIG_GRKERNSEC_KMEM)
29726+static inline int range_is_allowed(unsigned long pfn, unsigned long size)
29727+{
29728+ return 0;
29729+}
29730 #else
29731 static inline int range_is_allowed(unsigned long pfn, unsigned long size)
29732 {
29733@@ -120,6 +134,7 @@ static ssize_t read_mem(struct file *file, char __user *buf,
29734
29735 while (count > 0) {
29736 unsigned long remaining;
29737+ char *temp;
29738
29739 sz = size_inside_page(p, count);
29740
29741@@ -135,7 +150,23 @@ static ssize_t read_mem(struct file *file, char __user *buf,
29742 if (!ptr)
29743 return -EFAULT;
29744
29745- remaining = copy_to_user(buf, ptr, sz);
29746+#ifdef CONFIG_PAX_USERCOPY
29747+ temp = kmalloc(sz, GFP_KERNEL|GFP_USERCOPY);
29748+ if (!temp) {
29749+ unxlate_dev_mem_ptr(p, ptr);
29750+ return -ENOMEM;
29751+ }
29752+ memcpy(temp, ptr, sz);
29753+#else
29754+ temp = ptr;
29755+#endif
29756+
29757+ remaining = copy_to_user(buf, temp, sz);
29758+
29759+#ifdef CONFIG_PAX_USERCOPY
29760+ kfree(temp);
29761+#endif
29762+
29763 unxlate_dev_mem_ptr(p, ptr);
29764 if (remaining)
29765 return -EFAULT;
29766@@ -398,9 +429,8 @@ static ssize_t read_kmem(struct file *file, char __user *buf,
29767 size_t count, loff_t *ppos)
29768 {
29769 unsigned long p = *ppos;
29770- ssize_t low_count, read, sz;
29771+ ssize_t low_count, read, sz, err = 0;
29772 char * kbuf; /* k-addr because vread() takes vmlist_lock rwlock */
29773- int err = 0;
29774
29775 read = 0;
29776 if (p < (unsigned long) high_memory) {
29777@@ -422,6 +452,8 @@ static ssize_t read_kmem(struct file *file, char __user *buf,
29778 }
29779 #endif
29780 while (low_count > 0) {
29781+ char *temp;
29782+
29783 sz = size_inside_page(p, low_count);
29784
29785 /*
29786@@ -431,7 +463,22 @@ static ssize_t read_kmem(struct file *file, char __user *buf,
29787 */
29788 kbuf = xlate_dev_kmem_ptr((char *)p);
29789
29790- if (copy_to_user(buf, kbuf, sz))
29791+#ifdef CONFIG_PAX_USERCOPY
29792+ temp = kmalloc(sz, GFP_KERNEL|GFP_USERCOPY);
29793+ if (!temp)
29794+ return -ENOMEM;
29795+ memcpy(temp, kbuf, sz);
29796+#else
29797+ temp = kbuf;
29798+#endif
29799+
29800+ err = copy_to_user(buf, temp, sz);
29801+
29802+#ifdef CONFIG_PAX_USERCOPY
29803+ kfree(temp);
29804+#endif
29805+
29806+ if (err)
29807 return -EFAULT;
29808 buf += sz;
29809 p += sz;
29810@@ -833,6 +880,9 @@ static const struct memdev {
29811 #ifdef CONFIG_CRASH_DUMP
29812 [12] = { "oldmem", 0, &oldmem_fops, NULL },
29813 #endif
29814+#if defined(CONFIG_GRKERNSEC) && !defined(CONFIG_GRKERNSEC_NO_RBAC)
29815+ [13] = { "grsec",S_IRUSR | S_IWUGO, &grsec_fops, NULL },
29816+#endif
29817 };
29818
29819 static int memory_open(struct inode *inode, struct file *filp)
29820diff --git a/drivers/char/nvram.c b/drivers/char/nvram.c
29821index 9df78e2..01ba9ae 100644
29822--- a/drivers/char/nvram.c
29823+++ b/drivers/char/nvram.c
29824@@ -247,7 +247,7 @@ static ssize_t nvram_read(struct file *file, char __user *buf,
29825
29826 spin_unlock_irq(&rtc_lock);
29827
29828- if (copy_to_user(buf, contents, tmp - contents))
29829+ if (tmp - contents > sizeof(contents) || copy_to_user(buf, contents, tmp - contents))
29830 return -EFAULT;
29831
29832 *ppos = i;
29833diff --git a/drivers/char/pcmcia/synclink_cs.c b/drivers/char/pcmcia/synclink_cs.c
29834index 0a484b4..f48ccd1 100644
29835--- a/drivers/char/pcmcia/synclink_cs.c
29836+++ b/drivers/char/pcmcia/synclink_cs.c
29837@@ -2340,9 +2340,9 @@ static void mgslpc_close(struct tty_struct *tty, struct file * filp)
29838
29839 if (debug_level >= DEBUG_LEVEL_INFO)
29840 printk("%s(%d):mgslpc_close(%s) entry, count=%d\n",
29841- __FILE__,__LINE__, info->device_name, port->count);
29842+ __FILE__,__LINE__, info->device_name, atomic_read(&port->count));
29843
29844- WARN_ON(!port->count);
29845+ WARN_ON(!atomic_read(&port->count));
29846
29847 if (tty_port_close_start(port, tty, filp) == 0)
29848 goto cleanup;
29849@@ -2360,7 +2360,7 @@ static void mgslpc_close(struct tty_struct *tty, struct file * filp)
29850 cleanup:
29851 if (debug_level >= DEBUG_LEVEL_INFO)
29852 printk("%s(%d):mgslpc_close(%s) exit, count=%d\n", __FILE__,__LINE__,
29853- tty->driver->name, port->count);
29854+ tty->driver->name, atomic_read(&port->count));
29855 }
29856
29857 /* Wait until the transmitter is empty.
29858@@ -2502,7 +2502,7 @@ static int mgslpc_open(struct tty_struct *tty, struct file * filp)
29859
29860 if (debug_level >= DEBUG_LEVEL_INFO)
29861 printk("%s(%d):mgslpc_open(%s), old ref count = %d\n",
29862- __FILE__,__LINE__,tty->driver->name, port->count);
29863+ __FILE__,__LINE__,tty->driver->name, atomic_read(&port->count));
29864
29865 /* If port is closing, signal caller to try again */
29866 if (tty_hung_up_p(filp) || port->flags & ASYNC_CLOSING){
29867@@ -2522,11 +2522,11 @@ static int mgslpc_open(struct tty_struct *tty, struct file * filp)
29868 goto cleanup;
29869 }
29870 spin_lock(&port->lock);
29871- port->count++;
29872+ atomic_inc(&port->count);
29873 spin_unlock(&port->lock);
29874 spin_unlock_irqrestore(&info->netlock, flags);
29875
29876- if (port->count == 1) {
29877+ if (atomic_read(&port->count) == 1) {
29878 /* 1st open on this device, init hardware */
29879 retval = startup(info, tty);
29880 if (retval < 0)
29881@@ -3891,7 +3891,7 @@ static int hdlcdev_attach(struct net_device *dev, unsigned short encoding,
29882 unsigned short new_crctype;
29883
29884 /* return error if TTY interface open */
29885- if (info->port.count)
29886+ if (atomic_read(&info->port.count))
29887 return -EBUSY;
29888
29889 switch (encoding)
29890@@ -3994,7 +3994,7 @@ static int hdlcdev_open(struct net_device *dev)
29891
29892 /* arbitrate between network and tty opens */
29893 spin_lock_irqsave(&info->netlock, flags);
29894- if (info->port.count != 0 || info->netcount != 0) {
29895+ if (atomic_read(&info->port.count) != 0 || info->netcount != 0) {
29896 printk(KERN_WARNING "%s: hdlc_open returning busy\n", dev->name);
29897 spin_unlock_irqrestore(&info->netlock, flags);
29898 return -EBUSY;
29899@@ -4083,7 +4083,7 @@ static int hdlcdev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
29900 printk("%s:hdlcdev_ioctl(%s)\n",__FILE__,dev->name);
29901
29902 /* return error if TTY interface open */
29903- if (info->port.count)
29904+ if (atomic_read(&info->port.count))
29905 return -EBUSY;
29906
29907 if (cmd != SIOCWANDEV)
29908diff --git a/drivers/char/random.c b/drivers/char/random.c
29909index b86eae9..4192a7a 100644
29910--- a/drivers/char/random.c
29911+++ b/drivers/char/random.c
29912@@ -272,8 +272,13 @@
29913 /*
29914 * Configuration information
29915 */
29916+#ifdef CONFIG_GRKERNSEC_RANDNET
29917+#define INPUT_POOL_WORDS 512
29918+#define OUTPUT_POOL_WORDS 128
29919+#else
29920 #define INPUT_POOL_WORDS 128
29921 #define OUTPUT_POOL_WORDS 32
29922+#endif
29923 #define SEC_XFER_SIZE 512
29924 #define EXTRACT_SIZE 10
29925
29926@@ -313,10 +318,17 @@ static struct poolinfo {
29927 int poolwords;
29928 int tap1, tap2, tap3, tap4, tap5;
29929 } poolinfo_table[] = {
29930+#ifdef CONFIG_GRKERNSEC_RANDNET
29931+ /* x^512 + x^411 + x^308 + x^208 +x^104 + x + 1 -- 225 */
29932+ { 512, 411, 308, 208, 104, 1 },
29933+ /* x^128 + x^103 + x^76 + x^51 + x^25 + x + 1 -- 105 */
29934+ { 128, 103, 76, 51, 25, 1 },
29935+#else
29936 /* x^128 + x^103 + x^76 + x^51 +x^25 + x + 1 -- 105 */
29937 { 128, 103, 76, 51, 25, 1 },
29938 /* x^32 + x^26 + x^20 + x^14 + x^7 + x + 1 -- 15 */
29939 { 32, 26, 20, 14, 7, 1 },
29940+#endif
29941 #if 0
29942 /* x^2048 + x^1638 + x^1231 + x^819 + x^411 + x + 1 -- 115 */
29943 { 2048, 1638, 1231, 819, 411, 1 },
29944@@ -527,8 +539,8 @@ static void _mix_pool_bytes(struct entropy_store *r, const void *in,
29945 input_rotate += i ? 7 : 14;
29946 }
29947
29948- ACCESS_ONCE(r->input_rotate) = input_rotate;
29949- ACCESS_ONCE(r->add_ptr) = i;
29950+ ACCESS_ONCE_RW(r->input_rotate) = input_rotate;
29951+ ACCESS_ONCE_RW(r->add_ptr) = i;
29952 smp_wmb();
29953
29954 if (out)
29955@@ -799,6 +811,17 @@ void add_disk_randomness(struct gendisk *disk)
29956 }
29957 #endif
29958
29959+#ifdef CONFIG_PAX_LATENT_ENTROPY
29960+u64 latent_entropy;
29961+
29962+__init void transfer_latent_entropy(void)
29963+{
29964+ mix_pool_bytes(&input_pool, &latent_entropy, sizeof(latent_entropy), NULL);
29965+ mix_pool_bytes(&nonblocking_pool, &latent_entropy, sizeof(latent_entropy), NULL);
29966+// printk(KERN_INFO "PAX: transferring latent entropy: %16llx\n", latent_entropy);
29967+}
29968+#endif
29969+
29970 /*********************************************************************
29971 *
29972 * Entropy extraction routines
29973@@ -1008,7 +1031,7 @@ static ssize_t extract_entropy_user(struct entropy_store *r, void __user *buf,
29974
29975 extract_buf(r, tmp);
29976 i = min_t(int, nbytes, EXTRACT_SIZE);
29977- if (copy_to_user(buf, tmp, i)) {
29978+ if (i > sizeof(tmp) || copy_to_user(buf, tmp, i)) {
29979 ret = -EFAULT;
29980 break;
29981 }
29982@@ -1342,7 +1365,7 @@ EXPORT_SYMBOL(generate_random_uuid);
29983 #include <linux/sysctl.h>
29984
29985 static int min_read_thresh = 8, min_write_thresh;
29986-static int max_read_thresh = INPUT_POOL_WORDS * 32;
29987+static int max_read_thresh = OUTPUT_POOL_WORDS * 32;
29988 static int max_write_thresh = INPUT_POOL_WORDS * 32;
29989 static char sysctl_bootid[16];
29990
29991diff --git a/drivers/char/sonypi.c b/drivers/char/sonypi.c
29992index f877805..403375a 100644
29993--- a/drivers/char/sonypi.c
29994+++ b/drivers/char/sonypi.c
29995@@ -54,6 +54,7 @@
29996
29997 #include <asm/uaccess.h>
29998 #include <asm/io.h>
29999+#include <asm/local.h>
30000
30001 #include <linux/sonypi.h>
30002
30003@@ -490,7 +491,7 @@ static struct sonypi_device {
30004 spinlock_t fifo_lock;
30005 wait_queue_head_t fifo_proc_list;
30006 struct fasync_struct *fifo_async;
30007- int open_count;
30008+ local_t open_count;
30009 int model;
30010 struct input_dev *input_jog_dev;
30011 struct input_dev *input_key_dev;
30012@@ -897,7 +898,7 @@ static int sonypi_misc_fasync(int fd, struct file *filp, int on)
30013 static int sonypi_misc_release(struct inode *inode, struct file *file)
30014 {
30015 mutex_lock(&sonypi_device.lock);
30016- sonypi_device.open_count--;
30017+ local_dec(&sonypi_device.open_count);
30018 mutex_unlock(&sonypi_device.lock);
30019 return 0;
30020 }
30021@@ -906,9 +907,9 @@ static int sonypi_misc_open(struct inode *inode, struct file *file)
30022 {
30023 mutex_lock(&sonypi_device.lock);
30024 /* Flush input queue on first open */
30025- if (!sonypi_device.open_count)
30026+ if (!local_read(&sonypi_device.open_count))
30027 kfifo_reset(&sonypi_device.fifo);
30028- sonypi_device.open_count++;
30029+ local_inc(&sonypi_device.open_count);
30030 mutex_unlock(&sonypi_device.lock);
30031
30032 return 0;
30033diff --git a/drivers/char/tpm/tpm.c b/drivers/char/tpm/tpm.c
30034index 4dc8024..90108d1 100644
30035--- a/drivers/char/tpm/tpm.c
30036+++ b/drivers/char/tpm/tpm.c
30037@@ -415,7 +415,7 @@ static ssize_t tpm_transmit(struct tpm_chip *chip, const char *buf,
30038 chip->vendor.req_complete_val)
30039 goto out_recv;
30040
30041- if ((status == chip->vendor.req_canceled)) {
30042+ if (status == chip->vendor.req_canceled) {
30043 dev_err(chip->dev, "Operation Canceled\n");
30044 rc = -ECANCELED;
30045 goto out;
30046diff --git a/drivers/char/tpm/tpm_bios.c b/drivers/char/tpm/tpm_bios.c
30047index 0636520..169c1d0 100644
30048--- a/drivers/char/tpm/tpm_bios.c
30049+++ b/drivers/char/tpm/tpm_bios.c
30050@@ -173,7 +173,7 @@ static void *tpm_bios_measurements_start(struct seq_file *m, loff_t *pos)
30051 event = addr;
30052
30053 if ((event->event_type == 0 && event->event_size == 0) ||
30054- ((addr + sizeof(struct tcpa_event) + event->event_size) >= limit))
30055+ (event->event_size >= limit - addr - sizeof(struct tcpa_event)))
30056 return NULL;
30057
30058 return addr;
30059@@ -198,7 +198,7 @@ static void *tpm_bios_measurements_next(struct seq_file *m, void *v,
30060 return NULL;
30061
30062 if ((event->event_type == 0 && event->event_size == 0) ||
30063- ((v + sizeof(struct tcpa_event) + event->event_size) >= limit))
30064+ (event->event_size >= limit - v - sizeof(struct tcpa_event)))
30065 return NULL;
30066
30067 (*pos)++;
30068@@ -291,7 +291,8 @@ static int tpm_binary_bios_measurements_show(struct seq_file *m, void *v)
30069 int i;
30070
30071 for (i = 0; i < sizeof(struct tcpa_event) + event->event_size; i++)
30072- seq_putc(m, data[i]);
30073+ if (!seq_putc(m, data[i]))
30074+ return -EFAULT;
30075
30076 return 0;
30077 }
30078@@ -410,8 +411,13 @@ static int read_log(struct tpm_bios_log *log)
30079 log->bios_event_log_end = log->bios_event_log + len;
30080
30081 virt = acpi_os_map_memory(start, len);
30082+ if (!virt) {
30083+ kfree(log->bios_event_log);
30084+ log->bios_event_log = NULL;
30085+ return -EFAULT;
30086+ }
30087
30088- memcpy(log->bios_event_log, virt, len);
30089+ memcpy(log->bios_event_log, (const char __force_kernel *)virt, len);
30090
30091 acpi_os_unmap_memory(virt, len);
30092 return 0;
30093diff --git a/drivers/char/virtio_console.c b/drivers/char/virtio_console.c
30094index cdf2f54..e55c197 100644
30095--- a/drivers/char/virtio_console.c
30096+++ b/drivers/char/virtio_console.c
30097@@ -563,7 +563,7 @@ static ssize_t fill_readbuf(struct port *port, char *out_buf, size_t out_count,
30098 if (to_user) {
30099 ssize_t ret;
30100
30101- ret = copy_to_user(out_buf, buf->buf + buf->offset, out_count);
30102+ ret = copy_to_user((char __force_user *)out_buf, buf->buf + buf->offset, out_count);
30103 if (ret)
30104 return -EFAULT;
30105 } else {
30106@@ -662,7 +662,7 @@ static ssize_t port_fops_read(struct file *filp, char __user *ubuf,
30107 if (!port_has_data(port) && !port->host_connected)
30108 return 0;
30109
30110- return fill_readbuf(port, ubuf, count, true);
30111+ return fill_readbuf(port, (char __force_kernel *)ubuf, count, true);
30112 }
30113
30114 static ssize_t port_fops_write(struct file *filp, const char __user *ubuf,
30115diff --git a/drivers/edac/edac_pci_sysfs.c b/drivers/edac/edac_pci_sysfs.c
30116index e164c55..3aabb50 100644
30117--- a/drivers/edac/edac_pci_sysfs.c
30118+++ b/drivers/edac/edac_pci_sysfs.c
30119@@ -26,8 +26,8 @@ static int edac_pci_log_pe = 1; /* log PCI parity errors */
30120 static int edac_pci_log_npe = 1; /* log PCI non-parity error errors */
30121 static int edac_pci_poll_msec = 1000; /* one second workq period */
30122
30123-static atomic_t pci_parity_count = ATOMIC_INIT(0);
30124-static atomic_t pci_nonparity_count = ATOMIC_INIT(0);
30125+static atomic_unchecked_t pci_parity_count = ATOMIC_INIT(0);
30126+static atomic_unchecked_t pci_nonparity_count = ATOMIC_INIT(0);
30127
30128 static struct kobject *edac_pci_top_main_kobj;
30129 static atomic_t edac_pci_sysfs_refcount = ATOMIC_INIT(0);
30130@@ -579,7 +579,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
30131 edac_printk(KERN_CRIT, EDAC_PCI,
30132 "Signaled System Error on %s\n",
30133 pci_name(dev));
30134- atomic_inc(&pci_nonparity_count);
30135+ atomic_inc_unchecked(&pci_nonparity_count);
30136 }
30137
30138 if (status & (PCI_STATUS_PARITY)) {
30139@@ -587,7 +587,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
30140 "Master Data Parity Error on %s\n",
30141 pci_name(dev));
30142
30143- atomic_inc(&pci_parity_count);
30144+ atomic_inc_unchecked(&pci_parity_count);
30145 }
30146
30147 if (status & (PCI_STATUS_DETECTED_PARITY)) {
30148@@ -595,7 +595,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
30149 "Detected 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
30157@@ -618,7 +618,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
30158 edac_printk(KERN_CRIT, EDAC_PCI, "Bridge "
30159 "Signaled System Error on %s\n",
30160 pci_name(dev));
30161- atomic_inc(&pci_nonparity_count);
30162+ atomic_inc_unchecked(&pci_nonparity_count);
30163 }
30164
30165 if (status & (PCI_STATUS_PARITY)) {
30166@@ -626,7 +626,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
30167 "Master Data Parity Error on "
30168 "%s\n", pci_name(dev));
30169
30170- atomic_inc(&pci_parity_count);
30171+ atomic_inc_unchecked(&pci_parity_count);
30172 }
30173
30174 if (status & (PCI_STATUS_DETECTED_PARITY)) {
30175@@ -634,7 +634,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
30176 "Detected Parity Error on %s\n",
30177 pci_name(dev));
30178
30179- atomic_inc(&pci_parity_count);
30180+ atomic_inc_unchecked(&pci_parity_count);
30181 }
30182 }
30183 }
30184@@ -676,7 +676,7 @@ void edac_pci_do_parity_check(void)
30185 if (!check_pci_errors)
30186 return;
30187
30188- before_count = atomic_read(&pci_parity_count);
30189+ before_count = atomic_read_unchecked(&pci_parity_count);
30190
30191 /* scan all PCI devices looking for a Parity Error on devices and
30192 * bridges.
30193@@ -688,7 +688,7 @@ void edac_pci_do_parity_check(void)
30194 /* Only if operator has selected panic on PCI Error */
30195 if (edac_pci_get_panic_on_pe()) {
30196 /* If the count is different 'after' from 'before' */
30197- if (before_count != atomic_read(&pci_parity_count))
30198+ if (before_count != atomic_read_unchecked(&pci_parity_count))
30199 panic("EDAC: PCI Parity Error");
30200 }
30201 }
30202diff --git a/drivers/edac/mce_amd.h b/drivers/edac/mce_amd.h
30203index 8c87a5e..a19cbd7 100644
30204--- a/drivers/edac/mce_amd.h
30205+++ b/drivers/edac/mce_amd.h
30206@@ -80,7 +80,7 @@ extern const char * const ii_msgs[];
30207 struct amd_decoder_ops {
30208 bool (*dc_mce)(u16, u8);
30209 bool (*ic_mce)(u16, u8);
30210-};
30211+} __no_const;
30212
30213 void amd_report_gart_errors(bool);
30214 void amd_register_ecc_decoder(void (*f)(int, struct mce *));
30215diff --git a/drivers/firewire/core-card.c b/drivers/firewire/core-card.c
30216index 57ea7f4..789e3c3 100644
30217--- a/drivers/firewire/core-card.c
30218+++ b/drivers/firewire/core-card.c
30219@@ -680,7 +680,7 @@ EXPORT_SYMBOL_GPL(fw_card_release);
30220
30221 void fw_core_remove_card(struct fw_card *card)
30222 {
30223- struct fw_card_driver dummy_driver = dummy_driver_template;
30224+ fw_card_driver_no_const dummy_driver = dummy_driver_template;
30225
30226 card->driver->update_phy_reg(card, 4,
30227 PHY_LINK_ACTIVE | PHY_CONTENDER, 0);
30228diff --git a/drivers/firewire/core-cdev.c b/drivers/firewire/core-cdev.c
30229index f8d2287..5aaf4db 100644
30230--- a/drivers/firewire/core-cdev.c
30231+++ b/drivers/firewire/core-cdev.c
30232@@ -1365,8 +1365,7 @@ static int init_iso_resource(struct client *client,
30233 int ret;
30234
30235 if ((request->channels == 0 && request->bandwidth == 0) ||
30236- request->bandwidth > BANDWIDTH_AVAILABLE_INITIAL ||
30237- request->bandwidth < 0)
30238+ request->bandwidth > BANDWIDTH_AVAILABLE_INITIAL)
30239 return -EINVAL;
30240
30241 r = kmalloc(sizeof(*r), GFP_KERNEL);
30242diff --git a/drivers/firewire/core-transaction.c b/drivers/firewire/core-transaction.c
30243index 87d6f2d..5bf9d90 100644
30244--- a/drivers/firewire/core-transaction.c
30245+++ b/drivers/firewire/core-transaction.c
30246@@ -37,6 +37,7 @@
30247 #include <linux/timer.h>
30248 #include <linux/types.h>
30249 #include <linux/workqueue.h>
30250+#include <linux/sched.h>
30251
30252 #include <asm/byteorder.h>
30253
30254diff --git a/drivers/firewire/core.h b/drivers/firewire/core.h
30255index 515a42c..5ecf3ba 100644
30256--- a/drivers/firewire/core.h
30257+++ b/drivers/firewire/core.h
30258@@ -111,6 +111,7 @@ struct fw_card_driver {
30259
30260 int (*stop_iso)(struct fw_iso_context *ctx);
30261 };
30262+typedef struct fw_card_driver __no_const fw_card_driver_no_const;
30263
30264 void fw_card_initialize(struct fw_card *card,
30265 const struct fw_card_driver *driver, struct device *device);
30266diff --git a/drivers/firmware/dmi_scan.c b/drivers/firmware/dmi_scan.c
30267index b298158..7ed8432 100644
30268--- a/drivers/firmware/dmi_scan.c
30269+++ b/drivers/firmware/dmi_scan.c
30270@@ -452,11 +452,6 @@ void __init dmi_scan_machine(void)
30271 }
30272 }
30273 else {
30274- /*
30275- * no iounmap() for that ioremap(); it would be a no-op, but
30276- * it's so early in setup that sucker gets confused into doing
30277- * what it shouldn't if we actually call it.
30278- */
30279 p = dmi_ioremap(0xF0000, 0x10000);
30280 if (p == NULL)
30281 goto error;
30282@@ -726,7 +721,7 @@ int dmi_walk(void (*decode)(const struct dmi_header *, void *),
30283 if (buf == NULL)
30284 return -1;
30285
30286- dmi_table(buf, dmi_len, dmi_num, decode, private_data);
30287+ dmi_table((char __force_kernel *)buf, dmi_len, dmi_num, decode, private_data);
30288
30289 iounmap(buf);
30290 return 0;
30291diff --git a/drivers/gpio/gpio-vr41xx.c b/drivers/gpio/gpio-vr41xx.c
30292index 82d5c20..44a7177 100644
30293--- a/drivers/gpio/gpio-vr41xx.c
30294+++ b/drivers/gpio/gpio-vr41xx.c
30295@@ -204,7 +204,7 @@ static int giu_get_irq(unsigned int irq)
30296 printk(KERN_ERR "spurious GIU interrupt: %04x(%04x),%04x(%04x)\n",
30297 maskl, pendl, maskh, pendh);
30298
30299- atomic_inc(&irq_err_count);
30300+ atomic_inc_unchecked(&irq_err_count);
30301
30302 return -EINVAL;
30303 }
30304diff --git a/drivers/gpu/drm/drm_crtc_helper.c b/drivers/gpu/drm/drm_crtc_helper.c
30305index 3252e70..b5314ace 100644
30306--- a/drivers/gpu/drm/drm_crtc_helper.c
30307+++ b/drivers/gpu/drm/drm_crtc_helper.c
30308@@ -286,7 +286,7 @@ static bool drm_encoder_crtc_ok(struct drm_encoder *encoder,
30309 struct drm_crtc *tmp;
30310 int crtc_mask = 1;
30311
30312- WARN(!crtc, "checking null crtc?\n");
30313+ BUG_ON(!crtc);
30314
30315 dev = crtc->dev;
30316
30317diff --git a/drivers/gpu/drm/drm_drv.c b/drivers/gpu/drm/drm_drv.c
30318index 9238de4..a27c72a 100644
30319--- a/drivers/gpu/drm/drm_drv.c
30320+++ b/drivers/gpu/drm/drm_drv.c
30321@@ -307,7 +307,7 @@ module_exit(drm_core_exit);
30322 /**
30323 * Copy and IOCTL return string to user space
30324 */
30325-static int drm_copy_field(char *buf, size_t *buf_len, const char *value)
30326+static int drm_copy_field(char __user *buf, size_t *buf_len, const char *value)
30327 {
30328 int len;
30329
30330@@ -390,7 +390,7 @@ long drm_ioctl(struct file *filp,
30331 return -ENODEV;
30332
30333 atomic_inc(&dev->ioctl_count);
30334- atomic_inc(&dev->counts[_DRM_STAT_IOCTLS]);
30335+ atomic_inc_unchecked(&dev->counts[_DRM_STAT_IOCTLS]);
30336 ++file_priv->ioctl_count;
30337
30338 DRM_DEBUG("pid=%d, cmd=0x%02x, nr=0x%02x, dev 0x%lx, auth=%d\n",
30339diff --git a/drivers/gpu/drm/drm_fops.c b/drivers/gpu/drm/drm_fops.c
30340index 5062eec..4e3e51f 100644
30341--- a/drivers/gpu/drm/drm_fops.c
30342+++ b/drivers/gpu/drm/drm_fops.c
30343@@ -71,7 +71,7 @@ static int drm_setup(struct drm_device * dev)
30344 }
30345
30346 for (i = 0; i < ARRAY_SIZE(dev->counts); i++)
30347- atomic_set(&dev->counts[i], 0);
30348+ atomic_set_unchecked(&dev->counts[i], 0);
30349
30350 dev->sigdata.lock = NULL;
30351
30352@@ -134,8 +134,8 @@ int drm_open(struct inode *inode, struct file *filp)
30353
30354 retcode = drm_open_helper(inode, filp, dev);
30355 if (!retcode) {
30356- atomic_inc(&dev->counts[_DRM_STAT_OPENS]);
30357- if (!dev->open_count++)
30358+ atomic_inc_unchecked(&dev->counts[_DRM_STAT_OPENS]);
30359+ if (local_inc_return(&dev->open_count) == 1)
30360 retcode = drm_setup(dev);
30361 }
30362 if (!retcode) {
30363@@ -422,7 +422,7 @@ int drm_release(struct inode *inode, struct file *filp)
30364
30365 mutex_lock(&drm_global_mutex);
30366
30367- DRM_DEBUG("open_count = %d\n", dev->open_count);
30368+ DRM_DEBUG("open_count = %ld\n", local_read(&dev->open_count));
30369
30370 if (dev->driver->preclose)
30371 dev->driver->preclose(dev, file_priv);
30372@@ -431,10 +431,10 @@ int drm_release(struct inode *inode, struct file *filp)
30373 * Begin inline drm_release
30374 */
30375
30376- DRM_DEBUG("pid = %d, device = 0x%lx, open_count = %d\n",
30377+ DRM_DEBUG("pid = %d, device = 0x%lx, open_count = %ld\n",
30378 task_pid_nr(current),
30379 (long)old_encode_dev(file_priv->minor->device),
30380- dev->open_count);
30381+ local_read(&dev->open_count));
30382
30383 /* Release any auth tokens that might point to this file_priv,
30384 (do that under the drm_global_mutex) */
30385@@ -530,8 +530,8 @@ int drm_release(struct inode *inode, struct file *filp)
30386 * End inline drm_release
30387 */
30388
30389- atomic_inc(&dev->counts[_DRM_STAT_CLOSES]);
30390- if (!--dev->open_count) {
30391+ atomic_inc_unchecked(&dev->counts[_DRM_STAT_CLOSES]);
30392+ if (local_dec_and_test(&dev->open_count)) {
30393 if (atomic_read(&dev->ioctl_count)) {
30394 DRM_ERROR("Device busy: %d\n",
30395 atomic_read(&dev->ioctl_count));
30396diff --git a/drivers/gpu/drm/drm_global.c b/drivers/gpu/drm/drm_global.c
30397index c87dc96..326055d 100644
30398--- a/drivers/gpu/drm/drm_global.c
30399+++ b/drivers/gpu/drm/drm_global.c
30400@@ -36,7 +36,7 @@
30401 struct drm_global_item {
30402 struct mutex mutex;
30403 void *object;
30404- int refcount;
30405+ atomic_t refcount;
30406 };
30407
30408 static struct drm_global_item glob[DRM_GLOBAL_NUM];
30409@@ -49,7 +49,7 @@ void drm_global_init(void)
30410 struct drm_global_item *item = &glob[i];
30411 mutex_init(&item->mutex);
30412 item->object = NULL;
30413- item->refcount = 0;
30414+ atomic_set(&item->refcount, 0);
30415 }
30416 }
30417
30418@@ -59,7 +59,7 @@ void drm_global_release(void)
30419 for (i = 0; i < DRM_GLOBAL_NUM; ++i) {
30420 struct drm_global_item *item = &glob[i];
30421 BUG_ON(item->object != NULL);
30422- BUG_ON(item->refcount != 0);
30423+ BUG_ON(atomic_read(&item->refcount) != 0);
30424 }
30425 }
30426
30427@@ -70,7 +70,7 @@ int drm_global_item_ref(struct drm_global_reference *ref)
30428 void *object;
30429
30430 mutex_lock(&item->mutex);
30431- if (item->refcount == 0) {
30432+ if (atomic_read(&item->refcount) == 0) {
30433 item->object = kzalloc(ref->size, GFP_KERNEL);
30434 if (unlikely(item->object == NULL)) {
30435 ret = -ENOMEM;
30436@@ -83,7 +83,7 @@ int drm_global_item_ref(struct drm_global_reference *ref)
30437 goto out_err;
30438
30439 }
30440- ++item->refcount;
30441+ atomic_inc(&item->refcount);
30442 ref->object = item->object;
30443 object = item->object;
30444 mutex_unlock(&item->mutex);
30445@@ -100,9 +100,9 @@ void drm_global_item_unref(struct drm_global_reference *ref)
30446 struct drm_global_item *item = &glob[ref->global_type];
30447
30448 mutex_lock(&item->mutex);
30449- BUG_ON(item->refcount == 0);
30450+ BUG_ON(atomic_read(&item->refcount) == 0);
30451 BUG_ON(ref->object != item->object);
30452- if (--item->refcount == 0) {
30453+ if (atomic_dec_and_test(&item->refcount)) {
30454 ref->release(ref);
30455 item->object = NULL;
30456 }
30457diff --git a/drivers/gpu/drm/drm_info.c b/drivers/gpu/drm/drm_info.c
30458index 8928edb..0c79258 100644
30459--- a/drivers/gpu/drm/drm_info.c
30460+++ b/drivers/gpu/drm/drm_info.c
30461@@ -75,10 +75,14 @@ int drm_vm_info(struct seq_file *m, void *data)
30462 struct drm_local_map *map;
30463 struct drm_map_list *r_list;
30464
30465- /* Hardcoded from _DRM_FRAME_BUFFER,
30466- _DRM_REGISTERS, _DRM_SHM, _DRM_AGP, and
30467- _DRM_SCATTER_GATHER and _DRM_CONSISTENT */
30468- const char *types[] = { "FB", "REG", "SHM", "AGP", "SG", "PCI" };
30469+ static const char * const types[] = {
30470+ [_DRM_FRAME_BUFFER] = "FB",
30471+ [_DRM_REGISTERS] = "REG",
30472+ [_DRM_SHM] = "SHM",
30473+ [_DRM_AGP] = "AGP",
30474+ [_DRM_SCATTER_GATHER] = "SG",
30475+ [_DRM_CONSISTENT] = "PCI",
30476+ [_DRM_GEM] = "GEM" };
30477 const char *type;
30478 int i;
30479
30480@@ -89,7 +93,7 @@ int drm_vm_info(struct seq_file *m, void *data)
30481 map = r_list->map;
30482 if (!map)
30483 continue;
30484- if (map->type < 0 || map->type > 5)
30485+ if (map->type >= ARRAY_SIZE(types))
30486 type = "??";
30487 else
30488 type = types[map->type];
30489@@ -254,7 +258,11 @@ int drm_vma_info(struct seq_file *m, void *data)
30490 vma->vm_flags & VM_MAYSHARE ? 's' : 'p',
30491 vma->vm_flags & VM_LOCKED ? 'l' : '-',
30492 vma->vm_flags & VM_IO ? 'i' : '-',
30493+#ifdef CONFIG_GRKERNSEC_HIDESYM
30494+ 0);
30495+#else
30496 vma->vm_pgoff);
30497+#endif
30498
30499 #if defined(__i386__)
30500 pgprot = pgprot_val(vma->vm_page_prot);
30501diff --git a/drivers/gpu/drm/drm_ioc32.c b/drivers/gpu/drm/drm_ioc32.c
30502index 637fcc3..e890b33 100644
30503--- a/drivers/gpu/drm/drm_ioc32.c
30504+++ b/drivers/gpu/drm/drm_ioc32.c
30505@@ -457,7 +457,7 @@ static int compat_drm_infobufs(struct file *file, unsigned int cmd,
30506 request = compat_alloc_user_space(nbytes);
30507 if (!access_ok(VERIFY_WRITE, request, nbytes))
30508 return -EFAULT;
30509- list = (struct drm_buf_desc *) (request + 1);
30510+ list = (struct drm_buf_desc __user *) (request + 1);
30511
30512 if (__put_user(count, &request->count)
30513 || __put_user(list, &request->list))
30514@@ -518,7 +518,7 @@ static int compat_drm_mapbufs(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_pub *) (request + 1);
30519+ list = (struct drm_buf_pub __user *) (request + 1);
30520
30521 if (__put_user(count, &request->count)
30522 || __put_user(list, &request->list))
30523diff --git a/drivers/gpu/drm/drm_ioctl.c b/drivers/gpu/drm/drm_ioctl.c
30524index 64a62c6..ceab35e 100644
30525--- a/drivers/gpu/drm/drm_ioctl.c
30526+++ b/drivers/gpu/drm/drm_ioctl.c
30527@@ -252,7 +252,7 @@ int drm_getstats(struct drm_device *dev, void *data,
30528 stats->data[i].value =
30529 (file_priv->master->lock.hw_lock ? file_priv->master->lock.hw_lock->lock : 0);
30530 else
30531- stats->data[i].value = atomic_read(&dev->counts[i]);
30532+ stats->data[i].value = atomic_read_unchecked(&dev->counts[i]);
30533 stats->data[i].type = dev->types[i];
30534 }
30535
30536diff --git a/drivers/gpu/drm/drm_lock.c b/drivers/gpu/drm/drm_lock.c
30537index 3203955..c8090af 100644
30538--- a/drivers/gpu/drm/drm_lock.c
30539+++ b/drivers/gpu/drm/drm_lock.c
30540@@ -86,7 +86,7 @@ int drm_lock(struct drm_device *dev, void *data, struct drm_file *file_priv)
30541 if (drm_lock_take(&master->lock, lock->context)) {
30542 master->lock.file_priv = file_priv;
30543 master->lock.lock_time = jiffies;
30544- atomic_inc(&dev->counts[_DRM_STAT_LOCKS]);
30545+ atomic_inc_unchecked(&dev->counts[_DRM_STAT_LOCKS]);
30546 break; /* Got lock */
30547 }
30548
30549@@ -157,7 +157,7 @@ int drm_unlock(struct drm_device *dev, void *data, struct drm_file *file_priv)
30550 return -EINVAL;
30551 }
30552
30553- atomic_inc(&dev->counts[_DRM_STAT_UNLOCKS]);
30554+ atomic_inc_unchecked(&dev->counts[_DRM_STAT_UNLOCKS]);
30555
30556 if (drm_lock_free(&master->lock, lock->context)) {
30557 /* FIXME: Should really bail out here. */
30558diff --git a/drivers/gpu/drm/drm_stub.c b/drivers/gpu/drm/drm_stub.c
30559index 21bcd4a..8e074e0 100644
30560--- a/drivers/gpu/drm/drm_stub.c
30561+++ b/drivers/gpu/drm/drm_stub.c
30562@@ -511,7 +511,7 @@ void drm_unplug_dev(struct drm_device *dev)
30563
30564 drm_device_set_unplugged(dev);
30565
30566- if (dev->open_count == 0) {
30567+ if (local_read(&dev->open_count) == 0) {
30568 drm_put_dev(dev);
30569 }
30570 mutex_unlock(&drm_global_mutex);
30571diff --git a/drivers/gpu/drm/i810/i810_dma.c b/drivers/gpu/drm/i810/i810_dma.c
30572index 463ec68..f5bd2b5 100644
30573--- a/drivers/gpu/drm/i810/i810_dma.c
30574+++ b/drivers/gpu/drm/i810/i810_dma.c
30575@@ -946,8 +946,8 @@ static int i810_dma_vertex(struct drm_device *dev, void *data,
30576 dma->buflist[vertex->idx],
30577 vertex->discard, vertex->used);
30578
30579- atomic_add(vertex->used, &dev->counts[_DRM_STAT_SECONDARY]);
30580- atomic_inc(&dev->counts[_DRM_STAT_DMA]);
30581+ atomic_add_unchecked(vertex->used, &dev->counts[_DRM_STAT_SECONDARY]);
30582+ atomic_inc_unchecked(&dev->counts[_DRM_STAT_DMA]);
30583 sarea_priv->last_enqueue = dev_priv->counter - 1;
30584 sarea_priv->last_dispatch = (int)hw_status[5];
30585
30586@@ -1107,8 +1107,8 @@ static int i810_dma_mc(struct drm_device *dev, void *data,
30587 i810_dma_dispatch_mc(dev, dma->buflist[mc->idx], mc->used,
30588 mc->last_render);
30589
30590- atomic_add(mc->used, &dev->counts[_DRM_STAT_SECONDARY]);
30591- atomic_inc(&dev->counts[_DRM_STAT_DMA]);
30592+ atomic_add_unchecked(mc->used, &dev->counts[_DRM_STAT_SECONDARY]);
30593+ atomic_inc_unchecked(&dev->counts[_DRM_STAT_DMA]);
30594 sarea_priv->last_enqueue = dev_priv->counter - 1;
30595 sarea_priv->last_dispatch = (int)hw_status[5];
30596
30597diff --git a/drivers/gpu/drm/i810/i810_drv.h b/drivers/gpu/drm/i810/i810_drv.h
30598index 6e0acad..93c8289 100644
30599--- a/drivers/gpu/drm/i810/i810_drv.h
30600+++ b/drivers/gpu/drm/i810/i810_drv.h
30601@@ -108,8 +108,8 @@ typedef struct drm_i810_private {
30602 int page_flipping;
30603
30604 wait_queue_head_t irq_queue;
30605- atomic_t irq_received;
30606- atomic_t irq_emitted;
30607+ atomic_unchecked_t irq_received;
30608+ atomic_unchecked_t irq_emitted;
30609
30610 int front_offset;
30611 } drm_i810_private_t;
30612diff --git a/drivers/gpu/drm/i915/i915_debugfs.c b/drivers/gpu/drm/i915/i915_debugfs.c
30613index 359f6e8..ada68fd 100644
30614--- a/drivers/gpu/drm/i915/i915_debugfs.c
30615+++ b/drivers/gpu/drm/i915/i915_debugfs.c
30616@@ -518,7 +518,7 @@ static int i915_interrupt_info(struct seq_file *m, void *data)
30617 I915_READ(GTIMR));
30618 }
30619 seq_printf(m, "Interrupts received: %d\n",
30620- atomic_read(&dev_priv->irq_received));
30621+ atomic_read_unchecked(&dev_priv->irq_received));
30622 for (i = 0; i < I915_NUM_RINGS; i++) {
30623 if (IS_GEN6(dev) || IS_GEN7(dev)) {
30624 seq_printf(m, "Graphics Interrupt mask (%s): %08x\n",
30625diff --git a/drivers/gpu/drm/i915/i915_dma.c b/drivers/gpu/drm/i915/i915_dma.c
30626index 914c0df..d47d380 100644
30627--- a/drivers/gpu/drm/i915/i915_dma.c
30628+++ b/drivers/gpu/drm/i915/i915_dma.c
30629@@ -1269,7 +1269,7 @@ static bool i915_switcheroo_can_switch(struct pci_dev *pdev)
30630 bool can_switch;
30631
30632 spin_lock(&dev->count_lock);
30633- can_switch = (dev->open_count == 0);
30634+ can_switch = (local_read(&dev->open_count) == 0);
30635 spin_unlock(&dev->count_lock);
30636 return can_switch;
30637 }
30638diff --git a/drivers/gpu/drm/i915/i915_drv.h b/drivers/gpu/drm/i915/i915_drv.h
30639index 627fe35..c9a7346 100644
30640--- a/drivers/gpu/drm/i915/i915_drv.h
30641+++ b/drivers/gpu/drm/i915/i915_drv.h
30642@@ -272,12 +272,12 @@ struct drm_i915_display_funcs {
30643 /* render clock increase/decrease */
30644 /* display clock increase/decrease */
30645 /* pll clock increase/decrease */
30646-};
30647+} __no_const;
30648
30649 struct drm_i915_gt_funcs {
30650 void (*force_wake_get)(struct drm_i915_private *dev_priv);
30651 void (*force_wake_put)(struct drm_i915_private *dev_priv);
30652-};
30653+} __no_const;
30654
30655 struct intel_device_info {
30656 u8 gen;
30657@@ -408,7 +408,7 @@ typedef struct drm_i915_private {
30658 int current_page;
30659 int page_flipping;
30660
30661- atomic_t irq_received;
30662+ atomic_unchecked_t irq_received;
30663
30664 /* protects the irq masks */
30665 spinlock_t irq_lock;
30666@@ -1014,7 +1014,7 @@ struct drm_i915_gem_object {
30667 * will be page flipped away on the next vblank. When it
30668 * reaches 0, dev_priv->pending_flip_queue will be woken up.
30669 */
30670- atomic_t pending_flip;
30671+ atomic_unchecked_t pending_flip;
30672 };
30673
30674 #define to_intel_bo(x) container_of(x, struct drm_i915_gem_object, base)
30675@@ -1482,7 +1482,7 @@ extern struct i2c_adapter *intel_gmbus_get_adapter(
30676 struct drm_i915_private *dev_priv, unsigned port);
30677 extern void intel_gmbus_set_speed(struct i2c_adapter *adapter, int speed);
30678 extern void intel_gmbus_force_bit(struct i2c_adapter *adapter, bool force_bit);
30679-extern inline bool intel_gmbus_is_forced_bit(struct i2c_adapter *adapter)
30680+static inline bool intel_gmbus_is_forced_bit(struct i2c_adapter *adapter)
30681 {
30682 return container_of(adapter, struct intel_gmbus, adapter)->force_bit;
30683 }
30684diff --git a/drivers/gpu/drm/i915/i915_gem_execbuffer.c b/drivers/gpu/drm/i915/i915_gem_execbuffer.c
30685index cdf46b5..e785624 100644
30686--- a/drivers/gpu/drm/i915/i915_gem_execbuffer.c
30687+++ b/drivers/gpu/drm/i915/i915_gem_execbuffer.c
30688@@ -189,7 +189,7 @@ i915_gem_object_set_to_gpu_domain(struct drm_i915_gem_object *obj,
30689 i915_gem_clflush_object(obj);
30690
30691 if (obj->base.pending_write_domain)
30692- cd->flips |= atomic_read(&obj->pending_flip);
30693+ cd->flips |= atomic_read_unchecked(&obj->pending_flip);
30694
30695 /* The actual obj->write_domain will be updated with
30696 * pending_write_domain after we emit the accumulated flush for all
30697@@ -907,9 +907,9 @@ i915_gem_check_execbuffer(struct drm_i915_gem_execbuffer2 *exec)
30698
30699 static int
30700 validate_exec_list(struct drm_i915_gem_exec_object2 *exec,
30701- int count)
30702+ unsigned int count)
30703 {
30704- int i;
30705+ unsigned int i;
30706
30707 for (i = 0; i < count; i++) {
30708 char __user *ptr = (char __user *)(uintptr_t)exec[i].relocs_ptr;
30709diff --git a/drivers/gpu/drm/i915/i915_irq.c b/drivers/gpu/drm/i915/i915_irq.c
30710index 73fa3e1..ab2e9b9 100644
30711--- a/drivers/gpu/drm/i915/i915_irq.c
30712+++ b/drivers/gpu/drm/i915/i915_irq.c
30713@@ -514,7 +514,7 @@ static irqreturn_t valleyview_irq_handler(DRM_IRQ_ARGS)
30714 u32 pipe_stats[I915_MAX_PIPES];
30715 bool blc_event;
30716
30717- atomic_inc(&dev_priv->irq_received);
30718+ atomic_inc_unchecked(&dev_priv->irq_received);
30719
30720 while (true) {
30721 iir = I915_READ(VLV_IIR);
30722@@ -661,7 +661,7 @@ static irqreturn_t ivybridge_irq_handler(DRM_IRQ_ARGS)
30723 irqreturn_t ret = IRQ_NONE;
30724 int i;
30725
30726- atomic_inc(&dev_priv->irq_received);
30727+ atomic_inc_unchecked(&dev_priv->irq_received);
30728
30729 /* disable master interrupt before clearing iir */
30730 de_ier = I915_READ(DEIER);
30731@@ -736,7 +736,7 @@ static irqreturn_t ironlake_irq_handler(DRM_IRQ_ARGS)
30732 u32 de_iir, gt_iir, de_ier, pch_iir, pm_iir;
30733 u32 hotplug_mask;
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@@ -1717,7 +1717,7 @@ static void ironlake_irq_preinstall(struct drm_device *dev)
30741 {
30742 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
30743
30744- atomic_set(&dev_priv->irq_received, 0);
30745+ atomic_set_unchecked(&dev_priv->irq_received, 0);
30746
30747 I915_WRITE(HWSTAM, 0xeffe);
30748
30749@@ -1743,7 +1743,7 @@ static void valleyview_irq_preinstall(struct drm_device *dev)
30750 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
30751 int pipe;
30752
30753- atomic_set(&dev_priv->irq_received, 0);
30754+ atomic_set_unchecked(&dev_priv->irq_received, 0);
30755
30756 /* VLV magic */
30757 I915_WRITE(VLV_IMR, 0);
30758@@ -2048,7 +2048,7 @@ static void i8xx_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 for_each_pipe(pipe)
30766 I915_WRITE(PIPESTAT(pipe), 0);
30767@@ -2099,7 +2099,7 @@ static irqreturn_t i8xx_irq_handler(DRM_IRQ_ARGS)
30768 I915_DISPLAY_PLANE_A_FLIP_PENDING_INTERRUPT |
30769 I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT;
30770
30771- atomic_inc(&dev_priv->irq_received);
30772+ atomic_inc_unchecked(&dev_priv->irq_received);
30773
30774 iir = I915_READ16(IIR);
30775 if (iir == 0)
30776@@ -2184,7 +2184,7 @@ static void i915_irq_preinstall(struct drm_device * dev)
30777 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
30778 int pipe;
30779
30780- atomic_set(&dev_priv->irq_received, 0);
30781+ atomic_set_unchecked(&dev_priv->irq_received, 0);
30782
30783 if (I915_HAS_HOTPLUG(dev)) {
30784 I915_WRITE(PORT_HOTPLUG_EN, 0);
30785@@ -2279,7 +2279,7 @@ static irqreturn_t i915_irq_handler(DRM_IRQ_ARGS)
30786 };
30787 int pipe, ret = IRQ_NONE;
30788
30789- atomic_inc(&dev_priv->irq_received);
30790+ atomic_inc_unchecked(&dev_priv->irq_received);
30791
30792 iir = I915_READ(IIR);
30793 do {
30794@@ -2405,7 +2405,7 @@ static void i965_irq_preinstall(struct drm_device * dev)
30795 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
30796 int pipe;
30797
30798- atomic_set(&dev_priv->irq_received, 0);
30799+ atomic_set_unchecked(&dev_priv->irq_received, 0);
30800
30801 I915_WRITE(PORT_HOTPLUG_EN, 0);
30802 I915_WRITE(PORT_HOTPLUG_STAT, I915_READ(PORT_HOTPLUG_STAT));
30803@@ -2512,7 +2512,7 @@ static irqreturn_t i965_irq_handler(DRM_IRQ_ARGS)
30804 int irq_received;
30805 int ret = IRQ_NONE, pipe;
30806
30807- atomic_inc(&dev_priv->irq_received);
30808+ atomic_inc_unchecked(&dev_priv->irq_received);
30809
30810 iir = I915_READ(IIR);
30811
30812diff --git a/drivers/gpu/drm/i915/intel_display.c b/drivers/gpu/drm/i915/intel_display.c
30813index b634f6f..84bb8ba 100644
30814--- a/drivers/gpu/drm/i915/intel_display.c
30815+++ b/drivers/gpu/drm/i915/intel_display.c
30816@@ -2182,7 +2182,7 @@ intel_finish_fb(struct drm_framebuffer *old_fb)
30817
30818 wait_event(dev_priv->pending_flip_queue,
30819 atomic_read(&dev_priv->mm.wedged) ||
30820- atomic_read(&obj->pending_flip) == 0);
30821+ atomic_read_unchecked(&obj->pending_flip) == 0);
30822
30823 /* Big Hammer, we also need to ensure that any pending
30824 * MI_WAIT_FOR_EVENT inside a user batch buffer on the
30825@@ -6168,7 +6168,7 @@ static void do_intel_finish_page_flip(struct drm_device *dev,
30826
30827 obj = work->old_fb_obj;
30828
30829- atomic_clear_mask(1 << intel_crtc->plane,
30830+ atomic_clear_mask_unchecked(1 << intel_crtc->plane,
30831 &obj->pending_flip.counter);
30832
30833 wake_up(&dev_priv->pending_flip_queue);
30834@@ -6515,7 +6515,7 @@ static int intel_crtc_page_flip(struct drm_crtc *crtc,
30835 /* Block clients from rendering to the new back buffer until
30836 * the flip occurs and the object is no longer visible.
30837 */
30838- atomic_add(1 << intel_crtc->plane, &work->old_fb_obj->pending_flip);
30839+ atomic_add_unchecked(1 << intel_crtc->plane, &work->old_fb_obj->pending_flip);
30840
30841 ret = dev_priv->display.queue_flip(dev, crtc, fb, obj);
30842 if (ret)
30843@@ -6530,7 +6530,7 @@ static int intel_crtc_page_flip(struct drm_crtc *crtc,
30844 return 0;
30845
30846 cleanup_pending:
30847- atomic_sub(1 << intel_crtc->plane, &work->old_fb_obj->pending_flip);
30848+ atomic_sub_unchecked(1 << intel_crtc->plane, &work->old_fb_obj->pending_flip);
30849 drm_gem_object_unreference(&work->old_fb_obj->base);
30850 drm_gem_object_unreference(&obj->base);
30851 mutex_unlock(&dev->struct_mutex);
30852diff --git a/drivers/gpu/drm/mga/mga_drv.h b/drivers/gpu/drm/mga/mga_drv.h
30853index 54558a0..2d97005 100644
30854--- a/drivers/gpu/drm/mga/mga_drv.h
30855+++ b/drivers/gpu/drm/mga/mga_drv.h
30856@@ -120,9 +120,9 @@ typedef struct drm_mga_private {
30857 u32 clear_cmd;
30858 u32 maccess;
30859
30860- atomic_t vbl_received; /**< Number of vblanks received. */
30861+ atomic_unchecked_t vbl_received; /**< Number of vblanks received. */
30862 wait_queue_head_t fence_queue;
30863- atomic_t last_fence_retired;
30864+ atomic_unchecked_t last_fence_retired;
30865 u32 next_fence_to_post;
30866
30867 unsigned int fb_cpp;
30868diff --git a/drivers/gpu/drm/mga/mga_irq.c b/drivers/gpu/drm/mga/mga_irq.c
30869index 2581202..f230a8d9 100644
30870--- a/drivers/gpu/drm/mga/mga_irq.c
30871+++ b/drivers/gpu/drm/mga/mga_irq.c
30872@@ -44,7 +44,7 @@ u32 mga_get_vblank_counter(struct drm_device *dev, int crtc)
30873 if (crtc != 0)
30874 return 0;
30875
30876- return atomic_read(&dev_priv->vbl_received);
30877+ return atomic_read_unchecked(&dev_priv->vbl_received);
30878 }
30879
30880
30881@@ -60,7 +60,7 @@ irqreturn_t mga_driver_irq_handler(DRM_IRQ_ARGS)
30882 /* VBLANK interrupt */
30883 if (status & MGA_VLINEPEN) {
30884 MGA_WRITE(MGA_ICLEAR, MGA_VLINEICLR);
30885- atomic_inc(&dev_priv->vbl_received);
30886+ atomic_inc_unchecked(&dev_priv->vbl_received);
30887 drm_handle_vblank(dev, 0);
30888 handled = 1;
30889 }
30890@@ -79,7 +79,7 @@ irqreturn_t mga_driver_irq_handler(DRM_IRQ_ARGS)
30891 if ((prim_start & ~0x03) != (prim_end & ~0x03))
30892 MGA_WRITE(MGA_PRIMEND, prim_end);
30893
30894- atomic_inc(&dev_priv->last_fence_retired);
30895+ atomic_inc_unchecked(&dev_priv->last_fence_retired);
30896 DRM_WAKEUP(&dev_priv->fence_queue);
30897 handled = 1;
30898 }
30899@@ -130,7 +130,7 @@ int mga_driver_fence_wait(struct drm_device *dev, unsigned int *sequence)
30900 * using fences.
30901 */
30902 DRM_WAIT_ON(ret, dev_priv->fence_queue, 3 * DRM_HZ,
30903- (((cur_fence = atomic_read(&dev_priv->last_fence_retired))
30904+ (((cur_fence = atomic_read_unchecked(&dev_priv->last_fence_retired))
30905 - *sequence) <= (1 << 23)));
30906
30907 *sequence = cur_fence;
30908diff --git a/drivers/gpu/drm/nouveau/nouveau_bios.c b/drivers/gpu/drm/nouveau/nouveau_bios.c
30909index a0a3fe3..209bf10 100644
30910--- a/drivers/gpu/drm/nouveau/nouveau_bios.c
30911+++ b/drivers/gpu/drm/nouveau/nouveau_bios.c
30912@@ -5340,7 +5340,7 @@ parse_bit_U_tbl_entry(struct drm_device *dev, struct nvbios *bios,
30913 struct bit_table {
30914 const char id;
30915 int (* const parse_fn)(struct drm_device *, struct nvbios *, struct bit_entry *);
30916-};
30917+} __no_const;
30918
30919 #define BIT_TABLE(id, funcid) ((struct bit_table){ id, parse_bit_##funcid##_tbl_entry })
30920
30921diff --git a/drivers/gpu/drm/nouveau/nouveau_drv.h b/drivers/gpu/drm/nouveau/nouveau_drv.h
30922index 4f2cc95..9c6c510 100644
30923--- a/drivers/gpu/drm/nouveau/nouveau_drv.h
30924+++ b/drivers/gpu/drm/nouveau/nouveau_drv.h
30925@@ -302,7 +302,7 @@ struct nouveau_exec_engine {
30926 u32 handle, u16 class);
30927 void (*set_tile_region)(struct drm_device *dev, int i);
30928 void (*tlb_flush)(struct drm_device *, int engine);
30929-};
30930+} __no_const;
30931
30932 struct nouveau_instmem_engine {
30933 void *priv;
30934@@ -324,13 +324,13 @@ struct nouveau_instmem_engine {
30935 struct nouveau_mc_engine {
30936 int (*init)(struct drm_device *dev);
30937 void (*takedown)(struct drm_device *dev);
30938-};
30939+} __no_const;
30940
30941 struct nouveau_timer_engine {
30942 int (*init)(struct drm_device *dev);
30943 void (*takedown)(struct drm_device *dev);
30944 uint64_t (*read)(struct drm_device *dev);
30945-};
30946+} __no_const;
30947
30948 struct nouveau_fb_engine {
30949 int num_tiles;
30950@@ -547,7 +547,7 @@ struct nouveau_vram_engine {
30951 void (*put)(struct drm_device *, struct nouveau_mem **);
30952
30953 bool (*flags_valid)(struct drm_device *, u32 tile_flags);
30954-};
30955+} __no_const;
30956
30957 struct nouveau_engine {
30958 struct nouveau_instmem_engine instmem;
30959@@ -693,7 +693,7 @@ struct drm_nouveau_private {
30960 struct drm_global_reference mem_global_ref;
30961 struct ttm_bo_global_ref bo_global_ref;
30962 struct ttm_bo_device bdev;
30963- atomic_t validate_sequence;
30964+ atomic_unchecked_t validate_sequence;
30965 int (*move)(struct nouveau_channel *,
30966 struct ttm_buffer_object *,
30967 struct ttm_mem_reg *, struct ttm_mem_reg *);
30968diff --git a/drivers/gpu/drm/nouveau/nouveau_gem.c b/drivers/gpu/drm/nouveau/nouveau_gem.c
30969index af7cfb8..aadc2a3 100644
30970--- a/drivers/gpu/drm/nouveau/nouveau_gem.c
30971+++ b/drivers/gpu/drm/nouveau/nouveau_gem.c
30972@@ -318,7 +318,7 @@ validate_init(struct nouveau_channel *chan, struct drm_file *file_priv,
30973 int trycnt = 0;
30974 int ret, i;
30975
30976- sequence = atomic_add_return(1, &dev_priv->ttm.validate_sequence);
30977+ sequence = atomic_add_return_unchecked(1, &dev_priv->ttm.validate_sequence);
30978 retry:
30979 if (++trycnt > 100000) {
30980 NV_ERROR(dev, "%s failed and gave up.\n", __func__);
30981diff --git a/drivers/gpu/drm/nouveau/nouveau_state.c b/drivers/gpu/drm/nouveau/nouveau_state.c
30982index c610144..97440e2 100644
30983--- a/drivers/gpu/drm/nouveau/nouveau_state.c
30984+++ b/drivers/gpu/drm/nouveau/nouveau_state.c
30985@@ -490,7 +490,7 @@ static bool nouveau_switcheroo_can_switch(struct pci_dev *pdev)
30986 bool can_switch;
30987
30988 spin_lock(&dev->count_lock);
30989- can_switch = (dev->open_count == 0);
30990+ can_switch = (local_read(&dev->open_count) == 0);
30991 spin_unlock(&dev->count_lock);
30992 return can_switch;
30993 }
30994diff --git a/drivers/gpu/drm/nouveau/nv50_sor.c b/drivers/gpu/drm/nouveau/nv50_sor.c
30995index 93240bd..c490f60 100644
30996--- a/drivers/gpu/drm/nouveau/nv50_sor.c
30997+++ b/drivers/gpu/drm/nouveau/nv50_sor.c
30998@@ -304,7 +304,7 @@ nv50_sor_dpms(struct drm_encoder *encoder, int mode)
30999 }
31000
31001 if (nv_encoder->dcb->type == OUTPUT_DP) {
31002- struct dp_train_func func = {
31003+ static struct dp_train_func func = {
31004 .link_set = nv50_sor_dp_link_set,
31005 .train_set = nv50_sor_dp_train_set,
31006 .train_adj = nv50_sor_dp_train_adj
31007diff --git a/drivers/gpu/drm/nouveau/nvd0_display.c b/drivers/gpu/drm/nouveau/nvd0_display.c
31008index 8a2fc89..3a5cf40 100644
31009--- a/drivers/gpu/drm/nouveau/nvd0_display.c
31010+++ b/drivers/gpu/drm/nouveau/nvd0_display.c
31011@@ -1367,7 +1367,7 @@ nvd0_sor_dpms(struct drm_encoder *encoder, int mode)
31012 nv_wait(dev, 0x61c030 + (or * 0x0800), 0x10000000, 0x00000000);
31013
31014 if (nv_encoder->dcb->type == OUTPUT_DP) {
31015- struct dp_train_func func = {
31016+ static struct dp_train_func func = {
31017 .link_set = nvd0_sor_dp_link_set,
31018 .train_set = nvd0_sor_dp_train_set,
31019 .train_adj = nvd0_sor_dp_train_adj
31020diff --git a/drivers/gpu/drm/r128/r128_cce.c b/drivers/gpu/drm/r128/r128_cce.c
31021index bcac90b..53bfc76 100644
31022--- a/drivers/gpu/drm/r128/r128_cce.c
31023+++ b/drivers/gpu/drm/r128/r128_cce.c
31024@@ -378,7 +378,7 @@ static int r128_do_init_cce(struct drm_device *dev, drm_r128_init_t *init)
31025
31026 /* GH: Simple idle check.
31027 */
31028- atomic_set(&dev_priv->idle_count, 0);
31029+ atomic_set_unchecked(&dev_priv->idle_count, 0);
31030
31031 /* We don't support anything other than bus-mastering ring mode,
31032 * but the ring can be in either AGP or PCI space for the ring
31033diff --git a/drivers/gpu/drm/r128/r128_drv.h b/drivers/gpu/drm/r128/r128_drv.h
31034index 930c71b..499aded 100644
31035--- a/drivers/gpu/drm/r128/r128_drv.h
31036+++ b/drivers/gpu/drm/r128/r128_drv.h
31037@@ -90,14 +90,14 @@ typedef struct drm_r128_private {
31038 int is_pci;
31039 unsigned long cce_buffers_offset;
31040
31041- atomic_t idle_count;
31042+ atomic_unchecked_t idle_count;
31043
31044 int page_flipping;
31045 int current_page;
31046 u32 crtc_offset;
31047 u32 crtc_offset_cntl;
31048
31049- atomic_t vbl_received;
31050+ atomic_unchecked_t vbl_received;
31051
31052 u32 color_fmt;
31053 unsigned int front_offset;
31054diff --git a/drivers/gpu/drm/r128/r128_irq.c b/drivers/gpu/drm/r128/r128_irq.c
31055index 429d5a0..7e899ed 100644
31056--- a/drivers/gpu/drm/r128/r128_irq.c
31057+++ b/drivers/gpu/drm/r128/r128_irq.c
31058@@ -42,7 +42,7 @@ u32 r128_get_vblank_counter(struct drm_device *dev, int crtc)
31059 if (crtc != 0)
31060 return 0;
31061
31062- return atomic_read(&dev_priv->vbl_received);
31063+ return atomic_read_unchecked(&dev_priv->vbl_received);
31064 }
31065
31066 irqreturn_t r128_driver_irq_handler(DRM_IRQ_ARGS)
31067@@ -56,7 +56,7 @@ irqreturn_t r128_driver_irq_handler(DRM_IRQ_ARGS)
31068 /* VBLANK interrupt */
31069 if (status & R128_CRTC_VBLANK_INT) {
31070 R128_WRITE(R128_GEN_INT_STATUS, R128_CRTC_VBLANK_INT_AK);
31071- atomic_inc(&dev_priv->vbl_received);
31072+ atomic_inc_unchecked(&dev_priv->vbl_received);
31073 drm_handle_vblank(dev, 0);
31074 return IRQ_HANDLED;
31075 }
31076diff --git a/drivers/gpu/drm/r128/r128_state.c b/drivers/gpu/drm/r128/r128_state.c
31077index a9e33ce..09edd4b 100644
31078--- a/drivers/gpu/drm/r128/r128_state.c
31079+++ b/drivers/gpu/drm/r128/r128_state.c
31080@@ -321,10 +321,10 @@ static void r128_clear_box(drm_r128_private_t *dev_priv,
31081
31082 static void r128_cce_performance_boxes(drm_r128_private_t *dev_priv)
31083 {
31084- if (atomic_read(&dev_priv->idle_count) == 0)
31085+ if (atomic_read_unchecked(&dev_priv->idle_count) == 0)
31086 r128_clear_box(dev_priv, 64, 4, 8, 8, 0, 255, 0);
31087 else
31088- atomic_set(&dev_priv->idle_count, 0);
31089+ atomic_set_unchecked(&dev_priv->idle_count, 0);
31090 }
31091
31092 #endif
31093diff --git a/drivers/gpu/drm/radeon/mkregtable.c b/drivers/gpu/drm/radeon/mkregtable.c
31094index 5a82b6b..9e69c73 100644
31095--- a/drivers/gpu/drm/radeon/mkregtable.c
31096+++ b/drivers/gpu/drm/radeon/mkregtable.c
31097@@ -637,14 +637,14 @@ static int parser_auth(struct table *t, const char *filename)
31098 regex_t mask_rex;
31099 regmatch_t match[4];
31100 char buf[1024];
31101- size_t end;
31102+ long end;
31103 int len;
31104 int done = 0;
31105 int r;
31106 unsigned o;
31107 struct offset *offset;
31108 char last_reg_s[10];
31109- int last_reg;
31110+ unsigned long last_reg;
31111
31112 if (regcomp
31113 (&mask_rex, "(0x[0-9a-fA-F]*) *([_a-zA-Z0-9]*)", REG_EXTENDED)) {
31114diff --git a/drivers/gpu/drm/radeon/radeon.h b/drivers/gpu/drm/radeon/radeon.h
31115index 59a1531..3bab49b 100644
31116--- a/drivers/gpu/drm/radeon/radeon.h
31117+++ b/drivers/gpu/drm/radeon/radeon.h
31118@@ -711,7 +711,7 @@ struct r600_blit_cp_primitives {
31119 int x2, int y2);
31120 void (*draw_auto)(struct radeon_device *rdev);
31121 void (*set_default_state)(struct radeon_device *rdev);
31122-};
31123+} __no_const;
31124
31125 struct r600_blit {
31126 struct radeon_bo *shader_obj;
31127@@ -1216,7 +1216,7 @@ struct radeon_asic {
31128 u32 (*page_flip)(struct radeon_device *rdev, int crtc, u64 crtc_base);
31129 void (*post_page_flip)(struct radeon_device *rdev, int crtc);
31130 } pflip;
31131-};
31132+} __no_const;
31133
31134 /*
31135 * Asic structures
31136diff --git a/drivers/gpu/drm/radeon/radeon_device.c b/drivers/gpu/drm/radeon/radeon_device.c
31137index 7a3daeb..5016171 100644
31138--- a/drivers/gpu/drm/radeon/radeon_device.c
31139+++ b/drivers/gpu/drm/radeon/radeon_device.c
31140@@ -952,7 +952,7 @@ static bool radeon_switcheroo_can_switch(struct pci_dev *pdev)
31141 bool can_switch;
31142
31143 spin_lock(&dev->count_lock);
31144- can_switch = (dev->open_count == 0);
31145+ can_switch = (local_read(&dev->open_count) == 0);
31146 spin_unlock(&dev->count_lock);
31147 return can_switch;
31148 }
31149diff --git a/drivers/gpu/drm/radeon/radeon_drv.h b/drivers/gpu/drm/radeon/radeon_drv.h
31150index a1b59ca..86f2d44 100644
31151--- a/drivers/gpu/drm/radeon/radeon_drv.h
31152+++ b/drivers/gpu/drm/radeon/radeon_drv.h
31153@@ -255,7 +255,7 @@ typedef struct drm_radeon_private {
31154
31155 /* SW interrupt */
31156 wait_queue_head_t swi_queue;
31157- atomic_t swi_emitted;
31158+ atomic_unchecked_t swi_emitted;
31159 int vblank_crtc;
31160 uint32_t irq_enable_reg;
31161 uint32_t r500_disp_irq_reg;
31162diff --git a/drivers/gpu/drm/radeon/radeon_ioc32.c b/drivers/gpu/drm/radeon/radeon_ioc32.c
31163index 48b7cea..342236f 100644
31164--- a/drivers/gpu/drm/radeon/radeon_ioc32.c
31165+++ b/drivers/gpu/drm/radeon/radeon_ioc32.c
31166@@ -359,7 +359,7 @@ static int compat_radeon_cp_setparam(struct file *file, unsigned int cmd,
31167 request = compat_alloc_user_space(sizeof(*request));
31168 if (!access_ok(VERIFY_WRITE, request, sizeof(*request))
31169 || __put_user(req32.param, &request->param)
31170- || __put_user((void __user *)(unsigned long)req32.value,
31171+ || __put_user((unsigned long)req32.value,
31172 &request->value))
31173 return -EFAULT;
31174
31175diff --git a/drivers/gpu/drm/radeon/radeon_irq.c b/drivers/gpu/drm/radeon/radeon_irq.c
31176index 00da384..32f972d 100644
31177--- a/drivers/gpu/drm/radeon/radeon_irq.c
31178+++ b/drivers/gpu/drm/radeon/radeon_irq.c
31179@@ -225,8 +225,8 @@ static int radeon_emit_irq(struct drm_device * dev)
31180 unsigned int ret;
31181 RING_LOCALS;
31182
31183- atomic_inc(&dev_priv->swi_emitted);
31184- ret = atomic_read(&dev_priv->swi_emitted);
31185+ atomic_inc_unchecked(&dev_priv->swi_emitted);
31186+ ret = atomic_read_unchecked(&dev_priv->swi_emitted);
31187
31188 BEGIN_RING(4);
31189 OUT_RING_REG(RADEON_LAST_SWI_REG, ret);
31190@@ -352,7 +352,7 @@ int radeon_driver_irq_postinstall(struct drm_device *dev)
31191 drm_radeon_private_t *dev_priv =
31192 (drm_radeon_private_t *) dev->dev_private;
31193
31194- atomic_set(&dev_priv->swi_emitted, 0);
31195+ atomic_set_unchecked(&dev_priv->swi_emitted, 0);
31196 DRM_INIT_WAITQUEUE(&dev_priv->swi_queue);
31197
31198 dev->max_vblank_count = 0x001fffff;
31199diff --git a/drivers/gpu/drm/radeon/radeon_state.c b/drivers/gpu/drm/radeon/radeon_state.c
31200index e8422ae..d22d4a8 100644
31201--- a/drivers/gpu/drm/radeon/radeon_state.c
31202+++ b/drivers/gpu/drm/radeon/radeon_state.c
31203@@ -2168,7 +2168,7 @@ static int radeon_cp_clear(struct drm_device *dev, void *data, struct drm_file *
31204 if (sarea_priv->nbox > RADEON_NR_SAREA_CLIPRECTS)
31205 sarea_priv->nbox = RADEON_NR_SAREA_CLIPRECTS;
31206
31207- if (DRM_COPY_FROM_USER(&depth_boxes, clear->depth_boxes,
31208+ if (sarea_priv->nbox > RADEON_NR_SAREA_CLIPRECTS || DRM_COPY_FROM_USER(&depth_boxes, clear->depth_boxes,
31209 sarea_priv->nbox * sizeof(depth_boxes[0])))
31210 return -EFAULT;
31211
31212@@ -3031,7 +3031,7 @@ static int radeon_cp_getparam(struct drm_device *dev, void *data, struct drm_fil
31213 {
31214 drm_radeon_private_t *dev_priv = dev->dev_private;
31215 drm_radeon_getparam_t *param = data;
31216- int value;
31217+ int value = 0;
31218
31219 DRM_DEBUG("pid=%d\n", DRM_CURRENTPID);
31220
31221diff --git a/drivers/gpu/drm/radeon/radeon_ttm.c b/drivers/gpu/drm/radeon/radeon_ttm.c
31222index 5b71c71..650f9e4 100644
31223--- a/drivers/gpu/drm/radeon/radeon_ttm.c
31224+++ b/drivers/gpu/drm/radeon/radeon_ttm.c
31225@@ -822,8 +822,10 @@ int radeon_mmap(struct file *filp, struct vm_area_struct *vma)
31226 }
31227 if (unlikely(ttm_vm_ops == NULL)) {
31228 ttm_vm_ops = vma->vm_ops;
31229- radeon_ttm_vm_ops = *ttm_vm_ops;
31230- radeon_ttm_vm_ops.fault = &radeon_ttm_fault;
31231+ pax_open_kernel();
31232+ memcpy((void *)&radeon_ttm_vm_ops, ttm_vm_ops, sizeof(radeon_ttm_vm_ops));
31233+ *(void **)&radeon_ttm_vm_ops.fault = &radeon_ttm_fault;
31234+ pax_close_kernel();
31235 }
31236 vma->vm_ops = &radeon_ttm_vm_ops;
31237 return 0;
31238diff --git a/drivers/gpu/drm/radeon/rs690.c b/drivers/gpu/drm/radeon/rs690.c
31239index 3b663fc..57850f4 100644
31240--- a/drivers/gpu/drm/radeon/rs690.c
31241+++ b/drivers/gpu/drm/radeon/rs690.c
31242@@ -304,9 +304,11 @@ void rs690_crtc_bandwidth_compute(struct radeon_device *rdev,
31243 if (rdev->pm.max_bandwidth.full > rdev->pm.sideport_bandwidth.full &&
31244 rdev->pm.sideport_bandwidth.full)
31245 rdev->pm.max_bandwidth = rdev->pm.sideport_bandwidth;
31246- read_delay_latency.full = dfixed_const(370 * 800 * 1000);
31247+ read_delay_latency.full = dfixed_const(800 * 1000);
31248 read_delay_latency.full = dfixed_div(read_delay_latency,
31249 rdev->pm.igp_sideport_mclk);
31250+ a.full = dfixed_const(370);
31251+ read_delay_latency.full = dfixed_mul(read_delay_latency, a);
31252 } else {
31253 if (rdev->pm.max_bandwidth.full > rdev->pm.k8_bandwidth.full &&
31254 rdev->pm.k8_bandwidth.full)
31255diff --git a/drivers/gpu/drm/ttm/ttm_page_alloc.c b/drivers/gpu/drm/ttm/ttm_page_alloc.c
31256index ebc6fac..a8313ed 100644
31257--- a/drivers/gpu/drm/ttm/ttm_page_alloc.c
31258+++ b/drivers/gpu/drm/ttm/ttm_page_alloc.c
31259@@ -394,9 +394,9 @@ static int ttm_pool_get_num_unused_pages(void)
31260 static int ttm_pool_mm_shrink(struct shrinker *shrink,
31261 struct shrink_control *sc)
31262 {
31263- static atomic_t start_pool = ATOMIC_INIT(0);
31264+ static atomic_unchecked_t start_pool = ATOMIC_INIT(0);
31265 unsigned i;
31266- unsigned pool_offset = atomic_add_return(1, &start_pool);
31267+ unsigned pool_offset = atomic_add_return_unchecked(1, &start_pool);
31268 struct ttm_page_pool *pool;
31269 int shrink_pages = sc->nr_to_scan;
31270
31271diff --git a/drivers/gpu/drm/via/via_drv.h b/drivers/gpu/drm/via/via_drv.h
31272index 88edacc..1e5412b 100644
31273--- a/drivers/gpu/drm/via/via_drv.h
31274+++ b/drivers/gpu/drm/via/via_drv.h
31275@@ -51,7 +51,7 @@ typedef struct drm_via_ring_buffer {
31276 typedef uint32_t maskarray_t[5];
31277
31278 typedef struct drm_via_irq {
31279- atomic_t irq_received;
31280+ atomic_unchecked_t irq_received;
31281 uint32_t pending_mask;
31282 uint32_t enable_mask;
31283 wait_queue_head_t irq_queue;
31284@@ -75,7 +75,7 @@ typedef struct drm_via_private {
31285 struct timeval last_vblank;
31286 int last_vblank_valid;
31287 unsigned usec_per_vblank;
31288- atomic_t vbl_received;
31289+ atomic_unchecked_t vbl_received;
31290 drm_via_state_t hc_state;
31291 char pci_buf[VIA_PCI_BUF_SIZE];
31292 const uint32_t *fire_offsets[VIA_FIRE_BUF_SIZE];
31293diff --git a/drivers/gpu/drm/via/via_irq.c b/drivers/gpu/drm/via/via_irq.c
31294index d391f48..10c8ca3 100644
31295--- a/drivers/gpu/drm/via/via_irq.c
31296+++ b/drivers/gpu/drm/via/via_irq.c
31297@@ -102,7 +102,7 @@ u32 via_get_vblank_counter(struct drm_device *dev, int crtc)
31298 if (crtc != 0)
31299 return 0;
31300
31301- return atomic_read(&dev_priv->vbl_received);
31302+ return atomic_read_unchecked(&dev_priv->vbl_received);
31303 }
31304
31305 irqreturn_t via_driver_irq_handler(DRM_IRQ_ARGS)
31306@@ -117,8 +117,8 @@ irqreturn_t via_driver_irq_handler(DRM_IRQ_ARGS)
31307
31308 status = VIA_READ(VIA_REG_INTERRUPT);
31309 if (status & VIA_IRQ_VBLANK_PENDING) {
31310- atomic_inc(&dev_priv->vbl_received);
31311- if (!(atomic_read(&dev_priv->vbl_received) & 0x0F)) {
31312+ atomic_inc_unchecked(&dev_priv->vbl_received);
31313+ if (!(atomic_read_unchecked(&dev_priv->vbl_received) & 0x0F)) {
31314 do_gettimeofday(&cur_vblank);
31315 if (dev_priv->last_vblank_valid) {
31316 dev_priv->usec_per_vblank =
31317@@ -128,7 +128,7 @@ irqreturn_t via_driver_irq_handler(DRM_IRQ_ARGS)
31318 dev_priv->last_vblank = cur_vblank;
31319 dev_priv->last_vblank_valid = 1;
31320 }
31321- if (!(atomic_read(&dev_priv->vbl_received) & 0xFF)) {
31322+ if (!(atomic_read_unchecked(&dev_priv->vbl_received) & 0xFF)) {
31323 DRM_DEBUG("US per vblank is: %u\n",
31324 dev_priv->usec_per_vblank);
31325 }
31326@@ -138,7 +138,7 @@ irqreturn_t via_driver_irq_handler(DRM_IRQ_ARGS)
31327
31328 for (i = 0; i < dev_priv->num_irqs; ++i) {
31329 if (status & cur_irq->pending_mask) {
31330- atomic_inc(&cur_irq->irq_received);
31331+ atomic_inc_unchecked(&cur_irq->irq_received);
31332 DRM_WAKEUP(&cur_irq->irq_queue);
31333 handled = 1;
31334 if (dev_priv->irq_map[drm_via_irq_dma0_td] == i)
31335@@ -243,11 +243,11 @@ via_driver_irq_wait(struct drm_device *dev, unsigned int irq, int force_sequence
31336 DRM_WAIT_ON(ret, cur_irq->irq_queue, 3 * DRM_HZ,
31337 ((VIA_READ(masks[irq][2]) & masks[irq][3]) ==
31338 masks[irq][4]));
31339- cur_irq_sequence = atomic_read(&cur_irq->irq_received);
31340+ cur_irq_sequence = atomic_read_unchecked(&cur_irq->irq_received);
31341 } else {
31342 DRM_WAIT_ON(ret, cur_irq->irq_queue, 3 * DRM_HZ,
31343 (((cur_irq_sequence =
31344- atomic_read(&cur_irq->irq_received)) -
31345+ atomic_read_unchecked(&cur_irq->irq_received)) -
31346 *sequence) <= (1 << 23)));
31347 }
31348 *sequence = cur_irq_sequence;
31349@@ -285,7 +285,7 @@ void via_driver_irq_preinstall(struct drm_device *dev)
31350 }
31351
31352 for (i = 0; i < dev_priv->num_irqs; ++i) {
31353- atomic_set(&cur_irq->irq_received, 0);
31354+ atomic_set_unchecked(&cur_irq->irq_received, 0);
31355 cur_irq->enable_mask = dev_priv->irq_masks[i][0];
31356 cur_irq->pending_mask = dev_priv->irq_masks[i][1];
31357 DRM_INIT_WAITQUEUE(&cur_irq->irq_queue);
31358@@ -367,7 +367,7 @@ int via_wait_irq(struct drm_device *dev, void *data, struct drm_file *file_priv)
31359 switch (irqwait->request.type & ~VIA_IRQ_FLAGS_MASK) {
31360 case VIA_IRQ_RELATIVE:
31361 irqwait->request.sequence +=
31362- atomic_read(&cur_irq->irq_received);
31363+ atomic_read_unchecked(&cur_irq->irq_received);
31364 irqwait->request.type &= ~_DRM_VBLANK_RELATIVE;
31365 case VIA_IRQ_ABSOLUTE:
31366 break;
31367diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h b/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
31368index 29c984f..4084f1a 100644
31369--- a/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
31370+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
31371@@ -263,7 +263,7 @@ struct vmw_private {
31372 * Fencing and IRQs.
31373 */
31374
31375- atomic_t marker_seq;
31376+ atomic_unchecked_t marker_seq;
31377 wait_queue_head_t fence_queue;
31378 wait_queue_head_t fifo_queue;
31379 int fence_queue_waiters; /* Protected by hw_mutex */
31380diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c b/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c
31381index a0c2f12..68ae6cb 100644
31382--- a/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c
31383+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c
31384@@ -137,7 +137,7 @@ int vmw_fifo_init(struct vmw_private *dev_priv, struct vmw_fifo_state *fifo)
31385 (unsigned int) min,
31386 (unsigned int) fifo->capabilities);
31387
31388- atomic_set(&dev_priv->marker_seq, dev_priv->last_read_seqno);
31389+ atomic_set_unchecked(&dev_priv->marker_seq, dev_priv->last_read_seqno);
31390 iowrite32(dev_priv->last_read_seqno, fifo_mem + SVGA_FIFO_FENCE);
31391 vmw_marker_queue_init(&fifo->marker_queue);
31392 return vmw_fifo_send_fence(dev_priv, &dummy);
31393@@ -355,7 +355,7 @@ void *vmw_fifo_reserve(struct vmw_private *dev_priv, uint32_t bytes)
31394 if (reserveable)
31395 iowrite32(bytes, fifo_mem +
31396 SVGA_FIFO_RESERVED);
31397- return fifo_mem + (next_cmd >> 2);
31398+ return (__le32 __force_kernel *)fifo_mem + (next_cmd >> 2);
31399 } else {
31400 need_bounce = true;
31401 }
31402@@ -475,7 +475,7 @@ int vmw_fifo_send_fence(struct vmw_private *dev_priv, uint32_t *seqno)
31403
31404 fm = vmw_fifo_reserve(dev_priv, bytes);
31405 if (unlikely(fm == NULL)) {
31406- *seqno = atomic_read(&dev_priv->marker_seq);
31407+ *seqno = atomic_read_unchecked(&dev_priv->marker_seq);
31408 ret = -ENOMEM;
31409 (void)vmw_fallback_wait(dev_priv, false, true, *seqno,
31410 false, 3*HZ);
31411@@ -483,7 +483,7 @@ int vmw_fifo_send_fence(struct vmw_private *dev_priv, uint32_t *seqno)
31412 }
31413
31414 do {
31415- *seqno = atomic_add_return(1, &dev_priv->marker_seq);
31416+ *seqno = atomic_add_return_unchecked(1, &dev_priv->marker_seq);
31417 } while (*seqno == 0);
31418
31419 if (!(fifo_state->capabilities & SVGA_FIFO_CAP_FENCE)) {
31420diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c b/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c
31421index cabc95f..14b3d77 100644
31422--- a/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c
31423+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c
31424@@ -107,7 +107,7 @@ bool vmw_seqno_passed(struct vmw_private *dev_priv,
31425 * emitted. Then the fence is stale and signaled.
31426 */
31427
31428- ret = ((atomic_read(&dev_priv->marker_seq) - seqno)
31429+ ret = ((atomic_read_unchecked(&dev_priv->marker_seq) - seqno)
31430 > VMW_FENCE_WRAP);
31431
31432 return ret;
31433@@ -138,7 +138,7 @@ int vmw_fallback_wait(struct vmw_private *dev_priv,
31434
31435 if (fifo_idle)
31436 down_read(&fifo_state->rwsem);
31437- signal_seq = atomic_read(&dev_priv->marker_seq);
31438+ signal_seq = atomic_read_unchecked(&dev_priv->marker_seq);
31439 ret = 0;
31440
31441 for (;;) {
31442diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c b/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c
31443index 8a8725c..afed796 100644
31444--- a/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c
31445+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c
31446@@ -151,7 +151,7 @@ int vmw_wait_lag(struct vmw_private *dev_priv,
31447 while (!vmw_lag_lt(queue, us)) {
31448 spin_lock(&queue->lock);
31449 if (list_empty(&queue->head))
31450- seqno = atomic_read(&dev_priv->marker_seq);
31451+ seqno = atomic_read_unchecked(&dev_priv->marker_seq);
31452 else {
31453 marker = list_first_entry(&queue->head,
31454 struct vmw_marker, head);
31455diff --git a/drivers/hid/hid-core.c b/drivers/hid/hid-core.c
31456index 5de3bb3..08e5063 100644
31457--- a/drivers/hid/hid-core.c
31458+++ b/drivers/hid/hid-core.c
31459@@ -2177,7 +2177,7 @@ static bool hid_ignore(struct hid_device *hdev)
31460
31461 int hid_add_device(struct hid_device *hdev)
31462 {
31463- static atomic_t id = ATOMIC_INIT(0);
31464+ static atomic_unchecked_t id = ATOMIC_INIT(0);
31465 int ret;
31466
31467 if (WARN_ON(hdev->status & HID_STAT_ADDED))
31468@@ -2212,7 +2212,7 @@ int hid_add_device(struct hid_device *hdev)
31469 /* XXX hack, any other cleaner solution after the driver core
31470 * is converted to allow more than 20 bytes as the device name? */
31471 dev_set_name(&hdev->dev, "%04X:%04X:%04X.%04X", hdev->bus,
31472- hdev->vendor, hdev->product, atomic_inc_return(&id));
31473+ hdev->vendor, hdev->product, atomic_inc_return_unchecked(&id));
31474
31475 hid_debug_register(hdev, dev_name(&hdev->dev));
31476 ret = device_add(&hdev->dev);
31477diff --git a/drivers/hid/hid-wiimote-debug.c b/drivers/hid/hid-wiimote-debug.c
31478index eec3291..8ed706b 100644
31479--- a/drivers/hid/hid-wiimote-debug.c
31480+++ b/drivers/hid/hid-wiimote-debug.c
31481@@ -66,7 +66,7 @@ static ssize_t wiidebug_eeprom_read(struct file *f, char __user *u, size_t s,
31482 else if (size == 0)
31483 return -EIO;
31484
31485- if (copy_to_user(u, buf, size))
31486+ if (size > sizeof(buf) || copy_to_user(u, buf, size))
31487 return -EFAULT;
31488
31489 *off += size;
31490diff --git a/drivers/hid/usbhid/hiddev.c b/drivers/hid/usbhid/hiddev.c
31491index 14599e2..711c965 100644
31492--- a/drivers/hid/usbhid/hiddev.c
31493+++ b/drivers/hid/usbhid/hiddev.c
31494@@ -625,7 +625,7 @@ static long hiddev_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
31495 break;
31496
31497 case HIDIOCAPPLICATION:
31498- if (arg < 0 || arg >= hid->maxapplication)
31499+ if (arg >= hid->maxapplication)
31500 break;
31501
31502 for (i = 0; i < hid->maxcollection; i++)
31503diff --git a/drivers/hv/channel.c b/drivers/hv/channel.c
31504index 4065374..10ed7dc 100644
31505--- a/drivers/hv/channel.c
31506+++ b/drivers/hv/channel.c
31507@@ -400,8 +400,8 @@ int vmbus_establish_gpadl(struct vmbus_channel *channel, void *kbuffer,
31508 int ret = 0;
31509 int t;
31510
31511- next_gpadl_handle = atomic_read(&vmbus_connection.next_gpadl_handle);
31512- atomic_inc(&vmbus_connection.next_gpadl_handle);
31513+ next_gpadl_handle = atomic_read_unchecked(&vmbus_connection.next_gpadl_handle);
31514+ atomic_inc_unchecked(&vmbus_connection.next_gpadl_handle);
31515
31516 ret = create_gpadl_header(kbuffer, size, &msginfo, &msgcount);
31517 if (ret)
31518diff --git a/drivers/hv/hv.c b/drivers/hv/hv.c
31519index 86f8885..ab9cb2b 100644
31520--- a/drivers/hv/hv.c
31521+++ b/drivers/hv/hv.c
31522@@ -132,7 +132,7 @@ static u64 do_hypercall(u64 control, void *input, void *output)
31523 u64 output_address = (output) ? virt_to_phys(output) : 0;
31524 u32 output_address_hi = output_address >> 32;
31525 u32 output_address_lo = output_address & 0xFFFFFFFF;
31526- void *hypercall_page = hv_context.hypercall_page;
31527+ void *hypercall_page = ktva_ktla(hv_context.hypercall_page);
31528
31529 __asm__ __volatile__ ("call *%8" : "=d"(hv_status_hi),
31530 "=a"(hv_status_lo) : "d" (control_hi),
31531diff --git a/drivers/hv/hyperv_vmbus.h b/drivers/hv/hyperv_vmbus.h
31532index 0614ff3..f0b2b5c 100644
31533--- a/drivers/hv/hyperv_vmbus.h
31534+++ b/drivers/hv/hyperv_vmbus.h
31535@@ -555,7 +555,7 @@ enum vmbus_connect_state {
31536 struct vmbus_connection {
31537 enum vmbus_connect_state conn_state;
31538
31539- atomic_t next_gpadl_handle;
31540+ atomic_unchecked_t next_gpadl_handle;
31541
31542 /*
31543 * Represents channel interrupts. Each bit position represents a
31544diff --git a/drivers/hv/vmbus_drv.c b/drivers/hv/vmbus_drv.c
31545index 4748086..3abf845 100644
31546--- a/drivers/hv/vmbus_drv.c
31547+++ b/drivers/hv/vmbus_drv.c
31548@@ -662,10 +662,10 @@ int vmbus_device_register(struct hv_device *child_device_obj)
31549 {
31550 int ret = 0;
31551
31552- static atomic_t device_num = ATOMIC_INIT(0);
31553+ static atomic_unchecked_t device_num = ATOMIC_INIT(0);
31554
31555 dev_set_name(&child_device_obj->device, "vmbus_0_%d",
31556- atomic_inc_return(&device_num));
31557+ atomic_inc_return_unchecked(&device_num));
31558
31559 child_device_obj->device.bus = &hv_bus;
31560 child_device_obj->device.parent = &hv_acpi_dev->dev;
31561diff --git a/drivers/hwmon/sht15.c b/drivers/hwmon/sht15.c
31562index 8b011d0..3de24a1 100644
31563--- a/drivers/hwmon/sht15.c
31564+++ b/drivers/hwmon/sht15.c
31565@@ -166,7 +166,7 @@ struct sht15_data {
31566 int supply_uV;
31567 bool supply_uV_valid;
31568 struct work_struct update_supply_work;
31569- atomic_t interrupt_handled;
31570+ atomic_unchecked_t interrupt_handled;
31571 };
31572
31573 /**
31574@@ -509,13 +509,13 @@ static int sht15_measurement(struct sht15_data *data,
31575 return ret;
31576
31577 gpio_direction_input(data->pdata->gpio_data);
31578- atomic_set(&data->interrupt_handled, 0);
31579+ atomic_set_unchecked(&data->interrupt_handled, 0);
31580
31581 enable_irq(gpio_to_irq(data->pdata->gpio_data));
31582 if (gpio_get_value(data->pdata->gpio_data) == 0) {
31583 disable_irq_nosync(gpio_to_irq(data->pdata->gpio_data));
31584 /* Only relevant if the interrupt hasn't occurred. */
31585- if (!atomic_read(&data->interrupt_handled))
31586+ if (!atomic_read_unchecked(&data->interrupt_handled))
31587 schedule_work(&data->read_work);
31588 }
31589 ret = wait_event_timeout(data->wait_queue,
31590@@ -782,7 +782,7 @@ static irqreturn_t sht15_interrupt_fired(int irq, void *d)
31591
31592 /* First disable the interrupt */
31593 disable_irq_nosync(irq);
31594- atomic_inc(&data->interrupt_handled);
31595+ atomic_inc_unchecked(&data->interrupt_handled);
31596 /* Then schedule a reading work struct */
31597 if (data->state != SHT15_READING_NOTHING)
31598 schedule_work(&data->read_work);
31599@@ -804,11 +804,11 @@ static void sht15_bh_read_data(struct work_struct *work_s)
31600 * If not, then start the interrupt again - care here as could
31601 * have gone low in meantime so verify it hasn't!
31602 */
31603- atomic_set(&data->interrupt_handled, 0);
31604+ atomic_set_unchecked(&data->interrupt_handled, 0);
31605 enable_irq(gpio_to_irq(data->pdata->gpio_data));
31606 /* If still not occurred or another handler was scheduled */
31607 if (gpio_get_value(data->pdata->gpio_data)
31608- || atomic_read(&data->interrupt_handled))
31609+ || atomic_read_unchecked(&data->interrupt_handled))
31610 return;
31611 }
31612
31613diff --git a/drivers/i2c/busses/i2c-amd756-s4882.c b/drivers/i2c/busses/i2c-amd756-s4882.c
31614index 378fcb5..5e91fa8 100644
31615--- a/drivers/i2c/busses/i2c-amd756-s4882.c
31616+++ b/drivers/i2c/busses/i2c-amd756-s4882.c
31617@@ -43,7 +43,7 @@
31618 extern struct i2c_adapter amd756_smbus;
31619
31620 static struct i2c_adapter *s4882_adapter;
31621-static struct i2c_algorithm *s4882_algo;
31622+static i2c_algorithm_no_const *s4882_algo;
31623
31624 /* Wrapper access functions for multiplexed SMBus */
31625 static DEFINE_MUTEX(amd756_lock);
31626diff --git a/drivers/i2c/busses/i2c-nforce2-s4985.c b/drivers/i2c/busses/i2c-nforce2-s4985.c
31627index 29015eb..af2d8e9 100644
31628--- a/drivers/i2c/busses/i2c-nforce2-s4985.c
31629+++ b/drivers/i2c/busses/i2c-nforce2-s4985.c
31630@@ -41,7 +41,7 @@
31631 extern struct i2c_adapter *nforce2_smbus;
31632
31633 static struct i2c_adapter *s4985_adapter;
31634-static struct i2c_algorithm *s4985_algo;
31635+static i2c_algorithm_no_const *s4985_algo;
31636
31637 /* Wrapper access functions for multiplexed SMBus */
31638 static DEFINE_MUTEX(nforce2_lock);
31639diff --git a/drivers/i2c/i2c-mux.c b/drivers/i2c/i2c-mux.c
31640index 1038c38..eb92f51 100644
31641--- a/drivers/i2c/i2c-mux.c
31642+++ b/drivers/i2c/i2c-mux.c
31643@@ -30,7 +30,7 @@
31644 /* multiplexer per channel data */
31645 struct i2c_mux_priv {
31646 struct i2c_adapter adap;
31647- struct i2c_algorithm algo;
31648+ i2c_algorithm_no_const algo;
31649
31650 struct i2c_adapter *parent;
31651 void *mux_priv; /* the mux chip/device */
31652diff --git a/drivers/ide/aec62xx.c b/drivers/ide/aec62xx.c
31653index 57d00ca..0145194 100644
31654--- a/drivers/ide/aec62xx.c
31655+++ b/drivers/ide/aec62xx.c
31656@@ -181,7 +181,7 @@ static const struct ide_port_ops atp86x_port_ops = {
31657 .cable_detect = atp86x_cable_detect,
31658 };
31659
31660-static const struct ide_port_info aec62xx_chipsets[] __devinitdata = {
31661+static const struct ide_port_info aec62xx_chipsets[] __devinitconst = {
31662 { /* 0: AEC6210 */
31663 .name = DRV_NAME,
31664 .init_chipset = init_chipset_aec62xx,
31665diff --git a/drivers/ide/alim15x3.c b/drivers/ide/alim15x3.c
31666index 2c8016a..911a27c 100644
31667--- a/drivers/ide/alim15x3.c
31668+++ b/drivers/ide/alim15x3.c
31669@@ -512,7 +512,7 @@ static const struct ide_dma_ops ali_dma_ops = {
31670 .dma_sff_read_status = ide_dma_sff_read_status,
31671 };
31672
31673-static const struct ide_port_info ali15x3_chipset __devinitdata = {
31674+static const struct ide_port_info ali15x3_chipset __devinitconst = {
31675 .name = DRV_NAME,
31676 .init_chipset = init_chipset_ali15x3,
31677 .init_hwif = init_hwif_ali15x3,
31678diff --git a/drivers/ide/amd74xx.c b/drivers/ide/amd74xx.c
31679index 3747b25..56fc995 100644
31680--- a/drivers/ide/amd74xx.c
31681+++ b/drivers/ide/amd74xx.c
31682@@ -223,7 +223,7 @@ static const struct ide_port_ops amd_port_ops = {
31683 .udma_mask = udma, \
31684 }
31685
31686-static const struct ide_port_info amd74xx_chipsets[] __devinitdata = {
31687+static const struct ide_port_info amd74xx_chipsets[] __devinitconst = {
31688 /* 0: AMD7401 */ DECLARE_AMD_DEV(0x00, ATA_UDMA2),
31689 /* 1: AMD7409 */ DECLARE_AMD_DEV(ATA_SWDMA2, ATA_UDMA4),
31690 /* 2: AMD7411/7441 */ DECLARE_AMD_DEV(ATA_SWDMA2, ATA_UDMA5),
31691diff --git a/drivers/ide/atiixp.c b/drivers/ide/atiixp.c
31692index 15f0ead..cb43480 100644
31693--- a/drivers/ide/atiixp.c
31694+++ b/drivers/ide/atiixp.c
31695@@ -139,7 +139,7 @@ static const struct ide_port_ops atiixp_port_ops = {
31696 .cable_detect = atiixp_cable_detect,
31697 };
31698
31699-static const struct ide_port_info atiixp_pci_info[] __devinitdata = {
31700+static const struct ide_port_info atiixp_pci_info[] __devinitconst = {
31701 { /* 0: IXP200/300/400/700 */
31702 .name = DRV_NAME,
31703 .enablebits = {{0x48,0x01,0x00}, {0x48,0x08,0x00}},
31704diff --git a/drivers/ide/cmd64x.c b/drivers/ide/cmd64x.c
31705index 5f80312..d1fc438 100644
31706--- a/drivers/ide/cmd64x.c
31707+++ b/drivers/ide/cmd64x.c
31708@@ -327,7 +327,7 @@ static const struct ide_dma_ops cmd646_rev1_dma_ops = {
31709 .dma_sff_read_status = ide_dma_sff_read_status,
31710 };
31711
31712-static const struct ide_port_info cmd64x_chipsets[] __devinitdata = {
31713+static const struct ide_port_info cmd64x_chipsets[] __devinitconst = {
31714 { /* 0: CMD643 */
31715 .name = DRV_NAME,
31716 .init_chipset = init_chipset_cmd64x,
31717diff --git a/drivers/ide/cs5520.c b/drivers/ide/cs5520.c
31718index 2c1e5f7..1444762 100644
31719--- a/drivers/ide/cs5520.c
31720+++ b/drivers/ide/cs5520.c
31721@@ -94,7 +94,7 @@ static const struct ide_port_ops cs5520_port_ops = {
31722 .set_dma_mode = cs5520_set_dma_mode,
31723 };
31724
31725-static const struct ide_port_info cyrix_chipset __devinitdata = {
31726+static const struct ide_port_info cyrix_chipset __devinitconst = {
31727 .name = DRV_NAME,
31728 .enablebits = { { 0x60, 0x01, 0x01 }, { 0x60, 0x02, 0x02 } },
31729 .port_ops = &cs5520_port_ops,
31730diff --git a/drivers/ide/cs5530.c b/drivers/ide/cs5530.c
31731index 4dc4eb9..49b40ad 100644
31732--- a/drivers/ide/cs5530.c
31733+++ b/drivers/ide/cs5530.c
31734@@ -245,7 +245,7 @@ static const struct ide_port_ops cs5530_port_ops = {
31735 .udma_filter = cs5530_udma_filter,
31736 };
31737
31738-static const struct ide_port_info cs5530_chipset __devinitdata = {
31739+static const struct ide_port_info cs5530_chipset __devinitconst = {
31740 .name = DRV_NAME,
31741 .init_chipset = init_chipset_cs5530,
31742 .init_hwif = init_hwif_cs5530,
31743diff --git a/drivers/ide/cs5535.c b/drivers/ide/cs5535.c
31744index 5059faf..18d4c85 100644
31745--- a/drivers/ide/cs5535.c
31746+++ b/drivers/ide/cs5535.c
31747@@ -170,7 +170,7 @@ static const struct ide_port_ops cs5535_port_ops = {
31748 .cable_detect = cs5535_cable_detect,
31749 };
31750
31751-static const struct ide_port_info cs5535_chipset __devinitdata = {
31752+static const struct ide_port_info cs5535_chipset __devinitconst = {
31753 .name = DRV_NAME,
31754 .port_ops = &cs5535_port_ops,
31755 .host_flags = IDE_HFLAG_SINGLE | IDE_HFLAG_POST_SET_MODE,
31756diff --git a/drivers/ide/cy82c693.c b/drivers/ide/cy82c693.c
31757index 847553f..3ffb49d 100644
31758--- a/drivers/ide/cy82c693.c
31759+++ b/drivers/ide/cy82c693.c
31760@@ -163,7 +163,7 @@ static const struct ide_port_ops cy82c693_port_ops = {
31761 .set_dma_mode = cy82c693_set_dma_mode,
31762 };
31763
31764-static const struct ide_port_info cy82c693_chipset __devinitdata = {
31765+static const struct ide_port_info cy82c693_chipset __devinitconst = {
31766 .name = DRV_NAME,
31767 .init_iops = init_iops_cy82c693,
31768 .port_ops = &cy82c693_port_ops,
31769diff --git a/drivers/ide/hpt366.c b/drivers/ide/hpt366.c
31770index 58c51cd..4aec3b8 100644
31771--- a/drivers/ide/hpt366.c
31772+++ b/drivers/ide/hpt366.c
31773@@ -443,7 +443,7 @@ static struct hpt_timings hpt37x_timings = {
31774 }
31775 };
31776
31777-static const struct hpt_info hpt36x __devinitdata = {
31778+static const struct hpt_info hpt36x __devinitconst = {
31779 .chip_name = "HPT36x",
31780 .chip_type = HPT36x,
31781 .udma_mask = HPT366_ALLOW_ATA66_3 ? (HPT366_ALLOW_ATA66_4 ? ATA_UDMA4 : ATA_UDMA3) : ATA_UDMA2,
31782@@ -451,7 +451,7 @@ static const struct hpt_info hpt36x __devinitdata = {
31783 .timings = &hpt36x_timings
31784 };
31785
31786-static const struct hpt_info hpt370 __devinitdata = {
31787+static const struct hpt_info hpt370 __devinitconst = {
31788 .chip_name = "HPT370",
31789 .chip_type = HPT370,
31790 .udma_mask = HPT370_ALLOW_ATA100_5 ? ATA_UDMA5 : ATA_UDMA4,
31791@@ -459,7 +459,7 @@ static const struct hpt_info hpt370 __devinitdata = {
31792 .timings = &hpt37x_timings
31793 };
31794
31795-static const struct hpt_info hpt370a __devinitdata = {
31796+static const struct hpt_info hpt370a __devinitconst = {
31797 .chip_name = "HPT370A",
31798 .chip_type = HPT370A,
31799 .udma_mask = HPT370_ALLOW_ATA100_5 ? ATA_UDMA5 : ATA_UDMA4,
31800@@ -467,7 +467,7 @@ static const struct hpt_info hpt370a __devinitdata = {
31801 .timings = &hpt37x_timings
31802 };
31803
31804-static const struct hpt_info hpt374 __devinitdata = {
31805+static const struct hpt_info hpt374 __devinitconst = {
31806 .chip_name = "HPT374",
31807 .chip_type = HPT374,
31808 .udma_mask = ATA_UDMA5,
31809@@ -475,7 +475,7 @@ static const struct hpt_info hpt374 __devinitdata = {
31810 .timings = &hpt37x_timings
31811 };
31812
31813-static const struct hpt_info hpt372 __devinitdata = {
31814+static const struct hpt_info hpt372 __devinitconst = {
31815 .chip_name = "HPT372",
31816 .chip_type = HPT372,
31817 .udma_mask = HPT372_ALLOW_ATA133_6 ? ATA_UDMA6 : ATA_UDMA5,
31818@@ -483,7 +483,7 @@ static const struct hpt_info hpt372 __devinitdata = {
31819 .timings = &hpt37x_timings
31820 };
31821
31822-static const struct hpt_info hpt372a __devinitdata = {
31823+static const struct hpt_info hpt372a __devinitconst = {
31824 .chip_name = "HPT372A",
31825 .chip_type = HPT372A,
31826 .udma_mask = HPT372_ALLOW_ATA133_6 ? ATA_UDMA6 : ATA_UDMA5,
31827@@ -491,7 +491,7 @@ static const struct hpt_info hpt372a __devinitdata = {
31828 .timings = &hpt37x_timings
31829 };
31830
31831-static const struct hpt_info hpt302 __devinitdata = {
31832+static const struct hpt_info hpt302 __devinitconst = {
31833 .chip_name = "HPT302",
31834 .chip_type = HPT302,
31835 .udma_mask = HPT302_ALLOW_ATA133_6 ? ATA_UDMA6 : ATA_UDMA5,
31836@@ -499,7 +499,7 @@ static const struct hpt_info hpt302 __devinitdata = {
31837 .timings = &hpt37x_timings
31838 };
31839
31840-static const struct hpt_info hpt371 __devinitdata = {
31841+static const struct hpt_info hpt371 __devinitconst = {
31842 .chip_name = "HPT371",
31843 .chip_type = HPT371,
31844 .udma_mask = HPT371_ALLOW_ATA133_6 ? ATA_UDMA6 : ATA_UDMA5,
31845@@ -507,7 +507,7 @@ static const struct hpt_info hpt371 __devinitdata = {
31846 .timings = &hpt37x_timings
31847 };
31848
31849-static const struct hpt_info hpt372n __devinitdata = {
31850+static const struct hpt_info hpt372n __devinitconst = {
31851 .chip_name = "HPT372N",
31852 .chip_type = HPT372N,
31853 .udma_mask = HPT372_ALLOW_ATA133_6 ? ATA_UDMA6 : ATA_UDMA5,
31854@@ -515,7 +515,7 @@ static const struct hpt_info hpt372n __devinitdata = {
31855 .timings = &hpt37x_timings
31856 };
31857
31858-static const struct hpt_info hpt302n __devinitdata = {
31859+static const struct hpt_info hpt302n __devinitconst = {
31860 .chip_name = "HPT302N",
31861 .chip_type = HPT302N,
31862 .udma_mask = HPT302_ALLOW_ATA133_6 ? ATA_UDMA6 : ATA_UDMA5,
31863@@ -523,7 +523,7 @@ static const struct hpt_info hpt302n __devinitdata = {
31864 .timings = &hpt37x_timings
31865 };
31866
31867-static const struct hpt_info hpt371n __devinitdata = {
31868+static const struct hpt_info hpt371n __devinitconst = {
31869 .chip_name = "HPT371N",
31870 .chip_type = HPT371N,
31871 .udma_mask = HPT371_ALLOW_ATA133_6 ? ATA_UDMA6 : ATA_UDMA5,
31872@@ -1361,7 +1361,7 @@ static const struct ide_dma_ops hpt36x_dma_ops = {
31873 .dma_sff_read_status = ide_dma_sff_read_status,
31874 };
31875
31876-static const struct ide_port_info hpt366_chipsets[] __devinitdata = {
31877+static const struct ide_port_info hpt366_chipsets[] __devinitconst = {
31878 { /* 0: HPT36x */
31879 .name = DRV_NAME,
31880 .init_chipset = init_chipset_hpt366,
31881diff --git a/drivers/ide/ide-cd.c b/drivers/ide/ide-cd.c
31882index 8126824..55a2798 100644
31883--- a/drivers/ide/ide-cd.c
31884+++ b/drivers/ide/ide-cd.c
31885@@ -768,7 +768,7 @@ static void cdrom_do_block_pc(ide_drive_t *drive, struct request *rq)
31886 alignment = queue_dma_alignment(q) | q->dma_pad_mask;
31887 if ((unsigned long)buf & alignment
31888 || blk_rq_bytes(rq) & q->dma_pad_mask
31889- || object_is_on_stack(buf))
31890+ || object_starts_on_stack(buf))
31891 drive->dma = 0;
31892 }
31893 }
31894diff --git a/drivers/ide/ide-pci-generic.c b/drivers/ide/ide-pci-generic.c
31895index 7f56b73..dab5b67 100644
31896--- a/drivers/ide/ide-pci-generic.c
31897+++ b/drivers/ide/ide-pci-generic.c
31898@@ -53,7 +53,7 @@ static const struct ide_port_ops netcell_port_ops = {
31899 .udma_mask = ATA_UDMA6, \
31900 }
31901
31902-static const struct ide_port_info generic_chipsets[] __devinitdata = {
31903+static const struct ide_port_info generic_chipsets[] __devinitconst = {
31904 /* 0: Unknown */
31905 DECLARE_GENERIC_PCI_DEV(0),
31906
31907diff --git a/drivers/ide/it8172.c b/drivers/ide/it8172.c
31908index 560e66d..d5dd180 100644
31909--- a/drivers/ide/it8172.c
31910+++ b/drivers/ide/it8172.c
31911@@ -115,7 +115,7 @@ static const struct ide_port_ops it8172_port_ops = {
31912 .set_dma_mode = it8172_set_dma_mode,
31913 };
31914
31915-static const struct ide_port_info it8172_port_info __devinitdata = {
31916+static const struct ide_port_info it8172_port_info __devinitconst = {
31917 .name = DRV_NAME,
31918 .port_ops = &it8172_port_ops,
31919 .enablebits = { {0x41, 0x80, 0x80}, {0x00, 0x00, 0x00} },
31920diff --git a/drivers/ide/it8213.c b/drivers/ide/it8213.c
31921index 46816ba..1847aeb 100644
31922--- a/drivers/ide/it8213.c
31923+++ b/drivers/ide/it8213.c
31924@@ -156,7 +156,7 @@ static const struct ide_port_ops it8213_port_ops = {
31925 .cable_detect = it8213_cable_detect,
31926 };
31927
31928-static const struct ide_port_info it8213_chipset __devinitdata = {
31929+static const struct ide_port_info it8213_chipset __devinitconst = {
31930 .name = DRV_NAME,
31931 .enablebits = { {0x41, 0x80, 0x80} },
31932 .port_ops = &it8213_port_ops,
31933diff --git a/drivers/ide/it821x.c b/drivers/ide/it821x.c
31934index 2e3169f..c5611db 100644
31935--- a/drivers/ide/it821x.c
31936+++ b/drivers/ide/it821x.c
31937@@ -630,7 +630,7 @@ static const struct ide_port_ops it821x_port_ops = {
31938 .cable_detect = it821x_cable_detect,
31939 };
31940
31941-static const struct ide_port_info it821x_chipset __devinitdata = {
31942+static const struct ide_port_info it821x_chipset __devinitconst = {
31943 .name = DRV_NAME,
31944 .init_chipset = init_chipset_it821x,
31945 .init_hwif = init_hwif_it821x,
31946diff --git a/drivers/ide/jmicron.c b/drivers/ide/jmicron.c
31947index 74c2c4a..efddd7d 100644
31948--- a/drivers/ide/jmicron.c
31949+++ b/drivers/ide/jmicron.c
31950@@ -102,7 +102,7 @@ static const struct ide_port_ops jmicron_port_ops = {
31951 .cable_detect = jmicron_cable_detect,
31952 };
31953
31954-static const struct ide_port_info jmicron_chipset __devinitdata = {
31955+static const struct ide_port_info jmicron_chipset __devinitconst = {
31956 .name = DRV_NAME,
31957 .enablebits = { { 0x40, 0x01, 0x01 }, { 0x40, 0x10, 0x10 } },
31958 .port_ops = &jmicron_port_ops,
31959diff --git a/drivers/ide/ns87415.c b/drivers/ide/ns87415.c
31960index 95327a2..73f78d8 100644
31961--- a/drivers/ide/ns87415.c
31962+++ b/drivers/ide/ns87415.c
31963@@ -293,7 +293,7 @@ static const struct ide_dma_ops ns87415_dma_ops = {
31964 .dma_sff_read_status = superio_dma_sff_read_status,
31965 };
31966
31967-static const struct ide_port_info ns87415_chipset __devinitdata = {
31968+static const struct ide_port_info ns87415_chipset __devinitconst = {
31969 .name = DRV_NAME,
31970 .init_hwif = init_hwif_ns87415,
31971 .tp_ops = &ns87415_tp_ops,
31972diff --git a/drivers/ide/opti621.c b/drivers/ide/opti621.c
31973index 1a53a4c..39edc66 100644
31974--- a/drivers/ide/opti621.c
31975+++ b/drivers/ide/opti621.c
31976@@ -131,7 +131,7 @@ static const struct ide_port_ops opti621_port_ops = {
31977 .set_pio_mode = opti621_set_pio_mode,
31978 };
31979
31980-static const struct ide_port_info opti621_chipset __devinitdata = {
31981+static const struct ide_port_info opti621_chipset __devinitconst = {
31982 .name = DRV_NAME,
31983 .enablebits = { {0x45, 0x80, 0x00}, {0x40, 0x08, 0x00} },
31984 .port_ops = &opti621_port_ops,
31985diff --git a/drivers/ide/pdc202xx_new.c b/drivers/ide/pdc202xx_new.c
31986index 9546fe2..2e5ceb6 100644
31987--- a/drivers/ide/pdc202xx_new.c
31988+++ b/drivers/ide/pdc202xx_new.c
31989@@ -465,7 +465,7 @@ static const struct ide_port_ops pdcnew_port_ops = {
31990 .udma_mask = udma, \
31991 }
31992
31993-static const struct ide_port_info pdcnew_chipsets[] __devinitdata = {
31994+static const struct ide_port_info pdcnew_chipsets[] __devinitconst = {
31995 /* 0: PDC202{68,70} */ DECLARE_PDCNEW_DEV(ATA_UDMA5),
31996 /* 1: PDC202{69,71,75,76,77} */ DECLARE_PDCNEW_DEV(ATA_UDMA6),
31997 };
31998diff --git a/drivers/ide/pdc202xx_old.c b/drivers/ide/pdc202xx_old.c
31999index 3a35ec6..5634510 100644
32000--- a/drivers/ide/pdc202xx_old.c
32001+++ b/drivers/ide/pdc202xx_old.c
32002@@ -270,7 +270,7 @@ static const struct ide_dma_ops pdc2026x_dma_ops = {
32003 .max_sectors = sectors, \
32004 }
32005
32006-static const struct ide_port_info pdc202xx_chipsets[] __devinitdata = {
32007+static const struct ide_port_info pdc202xx_chipsets[] __devinitconst = {
32008 { /* 0: PDC20246 */
32009 .name = DRV_NAME,
32010 .init_chipset = init_chipset_pdc202xx,
32011diff --git a/drivers/ide/piix.c b/drivers/ide/piix.c
32012index 1892e81..fe0fd60 100644
32013--- a/drivers/ide/piix.c
32014+++ b/drivers/ide/piix.c
32015@@ -344,7 +344,7 @@ static const struct ide_port_ops ich_port_ops = {
32016 .udma_mask = udma, \
32017 }
32018
32019-static const struct ide_port_info piix_pci_info[] __devinitdata = {
32020+static const struct ide_port_info piix_pci_info[] __devinitconst = {
32021 /* 0: MPIIX */
32022 { /*
32023 * MPIIX actually has only a single IDE channel mapped to
32024diff --git a/drivers/ide/rz1000.c b/drivers/ide/rz1000.c
32025index a6414a8..c04173e 100644
32026--- a/drivers/ide/rz1000.c
32027+++ b/drivers/ide/rz1000.c
32028@@ -38,7 +38,7 @@ static int __devinit rz1000_disable_readahead(struct pci_dev *dev)
32029 }
32030 }
32031
32032-static const struct ide_port_info rz1000_chipset __devinitdata = {
32033+static const struct ide_port_info rz1000_chipset __devinitconst = {
32034 .name = DRV_NAME,
32035 .host_flags = IDE_HFLAG_NO_DMA,
32036 };
32037diff --git a/drivers/ide/sc1200.c b/drivers/ide/sc1200.c
32038index 356b9b5..d4758eb 100644
32039--- a/drivers/ide/sc1200.c
32040+++ b/drivers/ide/sc1200.c
32041@@ -291,7 +291,7 @@ static const struct ide_dma_ops sc1200_dma_ops = {
32042 .dma_sff_read_status = ide_dma_sff_read_status,
32043 };
32044
32045-static const struct ide_port_info sc1200_chipset __devinitdata = {
32046+static const struct ide_port_info sc1200_chipset __devinitconst = {
32047 .name = DRV_NAME,
32048 .port_ops = &sc1200_port_ops,
32049 .dma_ops = &sc1200_dma_ops,
32050diff --git a/drivers/ide/scc_pata.c b/drivers/ide/scc_pata.c
32051index b7f5b0c..9701038 100644
32052--- a/drivers/ide/scc_pata.c
32053+++ b/drivers/ide/scc_pata.c
32054@@ -811,7 +811,7 @@ static const struct ide_dma_ops scc_dma_ops = {
32055 .dma_sff_read_status = scc_dma_sff_read_status,
32056 };
32057
32058-static const struct ide_port_info scc_chipset __devinitdata = {
32059+static const struct ide_port_info scc_chipset __devinitconst = {
32060 .name = "sccIDE",
32061 .init_iops = init_iops_scc,
32062 .init_dma = scc_init_dma,
32063diff --git a/drivers/ide/serverworks.c b/drivers/ide/serverworks.c
32064index 35fb8da..24d72ef 100644
32065--- a/drivers/ide/serverworks.c
32066+++ b/drivers/ide/serverworks.c
32067@@ -337,7 +337,7 @@ static const struct ide_port_ops svwks_port_ops = {
32068 .cable_detect = svwks_cable_detect,
32069 };
32070
32071-static const struct ide_port_info serverworks_chipsets[] __devinitdata = {
32072+static const struct ide_port_info serverworks_chipsets[] __devinitconst = {
32073 { /* 0: OSB4 */
32074 .name = DRV_NAME,
32075 .init_chipset = init_chipset_svwks,
32076diff --git a/drivers/ide/siimage.c b/drivers/ide/siimage.c
32077index ddeda44..46f7e30 100644
32078--- a/drivers/ide/siimage.c
32079+++ b/drivers/ide/siimage.c
32080@@ -719,7 +719,7 @@ static const struct ide_dma_ops sil_dma_ops = {
32081 .udma_mask = ATA_UDMA6, \
32082 }
32083
32084-static const struct ide_port_info siimage_chipsets[] __devinitdata = {
32085+static const struct ide_port_info siimage_chipsets[] __devinitconst = {
32086 /* 0: SiI680 */ DECLARE_SII_DEV(&sil_pata_port_ops),
32087 /* 1: SiI3112 */ DECLARE_SII_DEV(&sil_sata_port_ops)
32088 };
32089diff --git a/drivers/ide/sis5513.c b/drivers/ide/sis5513.c
32090index 4a00225..09e61b4 100644
32091--- a/drivers/ide/sis5513.c
32092+++ b/drivers/ide/sis5513.c
32093@@ -563,7 +563,7 @@ static const struct ide_port_ops sis_ata133_port_ops = {
32094 .cable_detect = sis_cable_detect,
32095 };
32096
32097-static const struct ide_port_info sis5513_chipset __devinitdata = {
32098+static const struct ide_port_info sis5513_chipset __devinitconst = {
32099 .name = DRV_NAME,
32100 .init_chipset = init_chipset_sis5513,
32101 .enablebits = { {0x4a, 0x02, 0x02}, {0x4a, 0x04, 0x04} },
32102diff --git a/drivers/ide/sl82c105.c b/drivers/ide/sl82c105.c
32103index f21dc2a..d051cd2 100644
32104--- a/drivers/ide/sl82c105.c
32105+++ b/drivers/ide/sl82c105.c
32106@@ -299,7 +299,7 @@ static const struct ide_dma_ops sl82c105_dma_ops = {
32107 .dma_sff_read_status = ide_dma_sff_read_status,
32108 };
32109
32110-static const struct ide_port_info sl82c105_chipset __devinitdata = {
32111+static const struct ide_port_info sl82c105_chipset __devinitconst = {
32112 .name = DRV_NAME,
32113 .init_chipset = init_chipset_sl82c105,
32114 .enablebits = {{0x40,0x01,0x01}, {0x40,0x10,0x10}},
32115diff --git a/drivers/ide/slc90e66.c b/drivers/ide/slc90e66.c
32116index 864ffe0..863a5e9 100644
32117--- a/drivers/ide/slc90e66.c
32118+++ b/drivers/ide/slc90e66.c
32119@@ -132,7 +132,7 @@ static const struct ide_port_ops slc90e66_port_ops = {
32120 .cable_detect = slc90e66_cable_detect,
32121 };
32122
32123-static const struct ide_port_info slc90e66_chipset __devinitdata = {
32124+static const struct ide_port_info slc90e66_chipset __devinitconst = {
32125 .name = DRV_NAME,
32126 .enablebits = { {0x41, 0x80, 0x80}, {0x43, 0x80, 0x80} },
32127 .port_ops = &slc90e66_port_ops,
32128diff --git a/drivers/ide/tc86c001.c b/drivers/ide/tc86c001.c
32129index 4799d5c..1794678 100644
32130--- a/drivers/ide/tc86c001.c
32131+++ b/drivers/ide/tc86c001.c
32132@@ -192,7 +192,7 @@ static const struct ide_dma_ops tc86c001_dma_ops = {
32133 .dma_sff_read_status = ide_dma_sff_read_status,
32134 };
32135
32136-static const struct ide_port_info tc86c001_chipset __devinitdata = {
32137+static const struct ide_port_info tc86c001_chipset __devinitconst = {
32138 .name = DRV_NAME,
32139 .init_hwif = init_hwif_tc86c001,
32140 .port_ops = &tc86c001_port_ops,
32141diff --git a/drivers/ide/triflex.c b/drivers/ide/triflex.c
32142index 281c914..55ce1b8 100644
32143--- a/drivers/ide/triflex.c
32144+++ b/drivers/ide/triflex.c
32145@@ -92,7 +92,7 @@ static const struct ide_port_ops triflex_port_ops = {
32146 .set_dma_mode = triflex_set_mode,
32147 };
32148
32149-static const struct ide_port_info triflex_device __devinitdata = {
32150+static const struct ide_port_info triflex_device __devinitconst = {
32151 .name = DRV_NAME,
32152 .enablebits = {{0x80, 0x01, 0x01}, {0x80, 0x02, 0x02}},
32153 .port_ops = &triflex_port_ops,
32154diff --git a/drivers/ide/trm290.c b/drivers/ide/trm290.c
32155index 4b42ca0..e494a98 100644
32156--- a/drivers/ide/trm290.c
32157+++ b/drivers/ide/trm290.c
32158@@ -324,7 +324,7 @@ static struct ide_dma_ops trm290_dma_ops = {
32159 .dma_check = trm290_dma_check,
32160 };
32161
32162-static const struct ide_port_info trm290_chipset __devinitdata = {
32163+static const struct ide_port_info trm290_chipset __devinitconst = {
32164 .name = DRV_NAME,
32165 .init_hwif = init_hwif_trm290,
32166 .tp_ops = &trm290_tp_ops,
32167diff --git a/drivers/ide/via82cxxx.c b/drivers/ide/via82cxxx.c
32168index f46f49c..eb77678 100644
32169--- a/drivers/ide/via82cxxx.c
32170+++ b/drivers/ide/via82cxxx.c
32171@@ -403,7 +403,7 @@ static const struct ide_port_ops via_port_ops = {
32172 .cable_detect = via82cxxx_cable_detect,
32173 };
32174
32175-static const struct ide_port_info via82cxxx_chipset __devinitdata = {
32176+static const struct ide_port_info via82cxxx_chipset __devinitconst = {
32177 .name = DRV_NAME,
32178 .init_chipset = init_chipset_via82cxxx,
32179 .enablebits = { { 0x40, 0x02, 0x02 }, { 0x40, 0x01, 0x01 } },
32180diff --git a/drivers/ieee802154/fakehard.c b/drivers/ieee802154/fakehard.c
32181index 73d4531..c90cd2d 100644
32182--- a/drivers/ieee802154/fakehard.c
32183+++ b/drivers/ieee802154/fakehard.c
32184@@ -386,7 +386,7 @@ static int __devinit ieee802154fake_probe(struct platform_device *pdev)
32185 phy->transmit_power = 0xbf;
32186
32187 dev->netdev_ops = &fake_ops;
32188- dev->ml_priv = &fake_mlme;
32189+ dev->ml_priv = (void *)&fake_mlme;
32190
32191 priv = netdev_priv(dev);
32192 priv->phy = phy;
32193diff --git a/drivers/infiniband/core/cm.c b/drivers/infiniband/core/cm.c
32194index d67999f..4c5d083 100644
32195--- a/drivers/infiniband/core/cm.c
32196+++ b/drivers/infiniband/core/cm.c
32197@@ -114,7 +114,7 @@ static char const counter_group_names[CM_COUNTER_GROUPS]
32198
32199 struct cm_counter_group {
32200 struct kobject obj;
32201- atomic_long_t counter[CM_ATTR_COUNT];
32202+ atomic_long_unchecked_t counter[CM_ATTR_COUNT];
32203 };
32204
32205 struct cm_counter_attribute {
32206@@ -1394,7 +1394,7 @@ static void cm_dup_req_handler(struct cm_work *work,
32207 struct ib_mad_send_buf *msg = NULL;
32208 int ret;
32209
32210- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
32211+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
32212 counter[CM_REQ_COUNTER]);
32213
32214 /* Quick state check to discard duplicate REQs. */
32215@@ -1778,7 +1778,7 @@ static void cm_dup_rep_handler(struct cm_work *work)
32216 if (!cm_id_priv)
32217 return;
32218
32219- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
32220+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
32221 counter[CM_REP_COUNTER]);
32222 ret = cm_alloc_response_msg(work->port, work->mad_recv_wc, &msg);
32223 if (ret)
32224@@ -1945,7 +1945,7 @@ static int cm_rtu_handler(struct cm_work *work)
32225 if (cm_id_priv->id.state != IB_CM_REP_SENT &&
32226 cm_id_priv->id.state != IB_CM_MRA_REP_RCVD) {
32227 spin_unlock_irq(&cm_id_priv->lock);
32228- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
32229+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
32230 counter[CM_RTU_COUNTER]);
32231 goto out;
32232 }
32233@@ -2128,7 +2128,7 @@ static int cm_dreq_handler(struct cm_work *work)
32234 cm_id_priv = cm_acquire_id(dreq_msg->remote_comm_id,
32235 dreq_msg->local_comm_id);
32236 if (!cm_id_priv) {
32237- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
32238+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
32239 counter[CM_DREQ_COUNTER]);
32240 cm_issue_drep(work->port, work->mad_recv_wc);
32241 return -EINVAL;
32242@@ -2153,7 +2153,7 @@ static int cm_dreq_handler(struct cm_work *work)
32243 case IB_CM_MRA_REP_RCVD:
32244 break;
32245 case IB_CM_TIMEWAIT:
32246- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
32247+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
32248 counter[CM_DREQ_COUNTER]);
32249 if (cm_alloc_response_msg(work->port, work->mad_recv_wc, &msg))
32250 goto unlock;
32251@@ -2167,7 +2167,7 @@ static int cm_dreq_handler(struct cm_work *work)
32252 cm_free_msg(msg);
32253 goto deref;
32254 case IB_CM_DREQ_RCVD:
32255- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
32256+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
32257 counter[CM_DREQ_COUNTER]);
32258 goto unlock;
32259 default:
32260@@ -2534,7 +2534,7 @@ static int cm_mra_handler(struct cm_work *work)
32261 ib_modify_mad(cm_id_priv->av.port->mad_agent,
32262 cm_id_priv->msg, timeout)) {
32263 if (cm_id_priv->id.lap_state == IB_CM_MRA_LAP_RCVD)
32264- atomic_long_inc(&work->port->
32265+ atomic_long_inc_unchecked(&work->port->
32266 counter_group[CM_RECV_DUPLICATES].
32267 counter[CM_MRA_COUNTER]);
32268 goto out;
32269@@ -2543,7 +2543,7 @@ static int cm_mra_handler(struct cm_work *work)
32270 break;
32271 case IB_CM_MRA_REQ_RCVD:
32272 case IB_CM_MRA_REP_RCVD:
32273- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
32274+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
32275 counter[CM_MRA_COUNTER]);
32276 /* fall through */
32277 default:
32278@@ -2705,7 +2705,7 @@ static int cm_lap_handler(struct cm_work *work)
32279 case IB_CM_LAP_IDLE:
32280 break;
32281 case IB_CM_MRA_LAP_SENT:
32282- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
32283+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
32284 counter[CM_LAP_COUNTER]);
32285 if (cm_alloc_response_msg(work->port, work->mad_recv_wc, &msg))
32286 goto unlock;
32287@@ -2721,7 +2721,7 @@ static int cm_lap_handler(struct cm_work *work)
32288 cm_free_msg(msg);
32289 goto deref;
32290 case IB_CM_LAP_RCVD:
32291- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
32292+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
32293 counter[CM_LAP_COUNTER]);
32294 goto unlock;
32295 default:
32296@@ -3005,7 +3005,7 @@ static int cm_sidr_req_handler(struct cm_work *work)
32297 cur_cm_id_priv = cm_insert_remote_sidr(cm_id_priv);
32298 if (cur_cm_id_priv) {
32299 spin_unlock_irq(&cm.lock);
32300- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
32301+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
32302 counter[CM_SIDR_REQ_COUNTER]);
32303 goto out; /* Duplicate message. */
32304 }
32305@@ -3217,10 +3217,10 @@ static void cm_send_handler(struct ib_mad_agent *mad_agent,
32306 if (!msg->context[0] && (attr_index != CM_REJ_COUNTER))
32307 msg->retries = 1;
32308
32309- atomic_long_add(1 + msg->retries,
32310+ atomic_long_add_unchecked(1 + msg->retries,
32311 &port->counter_group[CM_XMIT].counter[attr_index]);
32312 if (msg->retries)
32313- atomic_long_add(msg->retries,
32314+ atomic_long_add_unchecked(msg->retries,
32315 &port->counter_group[CM_XMIT_RETRIES].
32316 counter[attr_index]);
32317
32318@@ -3430,7 +3430,7 @@ static void cm_recv_handler(struct ib_mad_agent *mad_agent,
32319 }
32320
32321 attr_id = be16_to_cpu(mad_recv_wc->recv_buf.mad->mad_hdr.attr_id);
32322- atomic_long_inc(&port->counter_group[CM_RECV].
32323+ atomic_long_inc_unchecked(&port->counter_group[CM_RECV].
32324 counter[attr_id - CM_ATTR_ID_OFFSET]);
32325
32326 work = kmalloc(sizeof *work + sizeof(struct ib_sa_path_rec) * paths,
32327@@ -3635,7 +3635,7 @@ static ssize_t cm_show_counter(struct kobject *obj, struct attribute *attr,
32328 cm_attr = container_of(attr, struct cm_counter_attribute, attr);
32329
32330 return sprintf(buf, "%ld\n",
32331- atomic_long_read(&group->counter[cm_attr->index]));
32332+ atomic_long_read_unchecked(&group->counter[cm_attr->index]));
32333 }
32334
32335 static const struct sysfs_ops cm_counter_ops = {
32336diff --git a/drivers/infiniband/core/fmr_pool.c b/drivers/infiniband/core/fmr_pool.c
32337index 176c8f9..2627b62 100644
32338--- a/drivers/infiniband/core/fmr_pool.c
32339+++ b/drivers/infiniband/core/fmr_pool.c
32340@@ -98,8 +98,8 @@ struct ib_fmr_pool {
32341
32342 struct task_struct *thread;
32343
32344- atomic_t req_ser;
32345- atomic_t flush_ser;
32346+ atomic_unchecked_t req_ser;
32347+ atomic_unchecked_t flush_ser;
32348
32349 wait_queue_head_t force_wait;
32350 };
32351@@ -180,10 +180,10 @@ static int ib_fmr_cleanup_thread(void *pool_ptr)
32352 struct ib_fmr_pool *pool = pool_ptr;
32353
32354 do {
32355- if (atomic_read(&pool->flush_ser) - atomic_read(&pool->req_ser) < 0) {
32356+ if (atomic_read_unchecked(&pool->flush_ser) - atomic_read_unchecked(&pool->req_ser) < 0) {
32357 ib_fmr_batch_release(pool);
32358
32359- atomic_inc(&pool->flush_ser);
32360+ atomic_inc_unchecked(&pool->flush_ser);
32361 wake_up_interruptible(&pool->force_wait);
32362
32363 if (pool->flush_function)
32364@@ -191,7 +191,7 @@ static int ib_fmr_cleanup_thread(void *pool_ptr)
32365 }
32366
32367 set_current_state(TASK_INTERRUPTIBLE);
32368- if (atomic_read(&pool->flush_ser) - atomic_read(&pool->req_ser) >= 0 &&
32369+ if (atomic_read_unchecked(&pool->flush_ser) - atomic_read_unchecked(&pool->req_ser) >= 0 &&
32370 !kthread_should_stop())
32371 schedule();
32372 __set_current_state(TASK_RUNNING);
32373@@ -283,8 +283,8 @@ struct ib_fmr_pool *ib_create_fmr_pool(struct ib_pd *pd,
32374 pool->dirty_watermark = params->dirty_watermark;
32375 pool->dirty_len = 0;
32376 spin_lock_init(&pool->pool_lock);
32377- atomic_set(&pool->req_ser, 0);
32378- atomic_set(&pool->flush_ser, 0);
32379+ atomic_set_unchecked(&pool->req_ser, 0);
32380+ atomic_set_unchecked(&pool->flush_ser, 0);
32381 init_waitqueue_head(&pool->force_wait);
32382
32383 pool->thread = kthread_run(ib_fmr_cleanup_thread,
32384@@ -412,11 +412,11 @@ int ib_flush_fmr_pool(struct ib_fmr_pool *pool)
32385 }
32386 spin_unlock_irq(&pool->pool_lock);
32387
32388- serial = atomic_inc_return(&pool->req_ser);
32389+ serial = atomic_inc_return_unchecked(&pool->req_ser);
32390 wake_up_process(pool->thread);
32391
32392 if (wait_event_interruptible(pool->force_wait,
32393- atomic_read(&pool->flush_ser) - serial >= 0))
32394+ atomic_read_unchecked(&pool->flush_ser) - serial >= 0))
32395 return -EINTR;
32396
32397 return 0;
32398@@ -526,7 +526,7 @@ int ib_fmr_pool_unmap(struct ib_pool_fmr *fmr)
32399 } else {
32400 list_add_tail(&fmr->list, &pool->dirty_list);
32401 if (++pool->dirty_len >= pool->dirty_watermark) {
32402- atomic_inc(&pool->req_ser);
32403+ atomic_inc_unchecked(&pool->req_ser);
32404 wake_up_process(pool->thread);
32405 }
32406 }
32407diff --git a/drivers/infiniband/hw/cxgb4/mem.c b/drivers/infiniband/hw/cxgb4/mem.c
32408index 57e07c6..56d09d4 100644
32409--- a/drivers/infiniband/hw/cxgb4/mem.c
32410+++ b/drivers/infiniband/hw/cxgb4/mem.c
32411@@ -122,7 +122,7 @@ static int write_tpt_entry(struct c4iw_rdev *rdev, u32 reset_tpt_entry,
32412 int err;
32413 struct fw_ri_tpte tpt;
32414 u32 stag_idx;
32415- static atomic_t key;
32416+ static atomic_unchecked_t key;
32417
32418 if (c4iw_fatal_error(rdev))
32419 return -EIO;
32420@@ -139,7 +139,7 @@ static int write_tpt_entry(struct c4iw_rdev *rdev, u32 reset_tpt_entry,
32421 if (rdev->stats.stag.cur > rdev->stats.stag.max)
32422 rdev->stats.stag.max = rdev->stats.stag.cur;
32423 mutex_unlock(&rdev->stats.lock);
32424- *stag = (stag_idx << 8) | (atomic_inc_return(&key) & 0xff);
32425+ *stag = (stag_idx << 8) | (atomic_inc_return_unchecked(&key) & 0xff);
32426 }
32427 PDBG("%s stag_state 0x%0x type 0x%0x pdid 0x%0x, stag_idx 0x%x\n",
32428 __func__, stag_state, type, pdid, stag_idx);
32429diff --git a/drivers/infiniband/hw/ipath/ipath_rc.c b/drivers/infiniband/hw/ipath/ipath_rc.c
32430index 79b3dbc..96e5fcc 100644
32431--- a/drivers/infiniband/hw/ipath/ipath_rc.c
32432+++ b/drivers/infiniband/hw/ipath/ipath_rc.c
32433@@ -1868,7 +1868,7 @@ void ipath_rc_rcv(struct ipath_ibdev *dev, struct ipath_ib_header *hdr,
32434 struct ib_atomic_eth *ateth;
32435 struct ipath_ack_entry *e;
32436 u64 vaddr;
32437- atomic64_t *maddr;
32438+ atomic64_unchecked_t *maddr;
32439 u64 sdata;
32440 u32 rkey;
32441 u8 next;
32442@@ -1903,11 +1903,11 @@ void ipath_rc_rcv(struct ipath_ibdev *dev, struct ipath_ib_header *hdr,
32443 IB_ACCESS_REMOTE_ATOMIC)))
32444 goto nack_acc_unlck;
32445 /* Perform atomic OP and save result. */
32446- maddr = (atomic64_t *) qp->r_sge.sge.vaddr;
32447+ maddr = (atomic64_unchecked_t *) qp->r_sge.sge.vaddr;
32448 sdata = be64_to_cpu(ateth->swap_data);
32449 e = &qp->s_ack_queue[qp->r_head_ack_queue];
32450 e->atomic_data = (opcode == OP(FETCH_ADD)) ?
32451- (u64) atomic64_add_return(sdata, maddr) - sdata :
32452+ (u64) atomic64_add_return_unchecked(sdata, maddr) - sdata :
32453 (u64) cmpxchg((u64 *) qp->r_sge.sge.vaddr,
32454 be64_to_cpu(ateth->compare_data),
32455 sdata);
32456diff --git a/drivers/infiniband/hw/ipath/ipath_ruc.c b/drivers/infiniband/hw/ipath/ipath_ruc.c
32457index 1f95bba..9530f87 100644
32458--- a/drivers/infiniband/hw/ipath/ipath_ruc.c
32459+++ b/drivers/infiniband/hw/ipath/ipath_ruc.c
32460@@ -266,7 +266,7 @@ static void ipath_ruc_loopback(struct ipath_qp *sqp)
32461 unsigned long flags;
32462 struct ib_wc wc;
32463 u64 sdata;
32464- atomic64_t *maddr;
32465+ atomic64_unchecked_t *maddr;
32466 enum ib_wc_status send_status;
32467
32468 /*
32469@@ -382,11 +382,11 @@ again:
32470 IB_ACCESS_REMOTE_ATOMIC)))
32471 goto acc_err;
32472 /* Perform atomic OP and save result. */
32473- maddr = (atomic64_t *) qp->r_sge.sge.vaddr;
32474+ maddr = (atomic64_unchecked_t *) qp->r_sge.sge.vaddr;
32475 sdata = wqe->wr.wr.atomic.compare_add;
32476 *(u64 *) sqp->s_sge.sge.vaddr =
32477 (wqe->wr.opcode == IB_WR_ATOMIC_FETCH_AND_ADD) ?
32478- (u64) atomic64_add_return(sdata, maddr) - sdata :
32479+ (u64) atomic64_add_return_unchecked(sdata, maddr) - sdata :
32480 (u64) cmpxchg((u64 *) qp->r_sge.sge.vaddr,
32481 sdata, wqe->wr.wr.atomic.swap);
32482 goto send_comp;
32483diff --git a/drivers/infiniband/hw/nes/nes.c b/drivers/infiniband/hw/nes/nes.c
32484index 7140199..da60063 100644
32485--- a/drivers/infiniband/hw/nes/nes.c
32486+++ b/drivers/infiniband/hw/nes/nes.c
32487@@ -103,7 +103,7 @@ MODULE_PARM_DESC(limit_maxrdreqsz, "Limit max read request size to 256 Bytes");
32488 LIST_HEAD(nes_adapter_list);
32489 static LIST_HEAD(nes_dev_list);
32490
32491-atomic_t qps_destroyed;
32492+atomic_unchecked_t qps_destroyed;
32493
32494 static unsigned int ee_flsh_adapter;
32495 static unsigned int sysfs_nonidx_addr;
32496@@ -272,7 +272,7 @@ static void nes_cqp_rem_ref_callback(struct nes_device *nesdev, struct nes_cqp_r
32497 struct nes_qp *nesqp = cqp_request->cqp_callback_pointer;
32498 struct nes_adapter *nesadapter = nesdev->nesadapter;
32499
32500- atomic_inc(&qps_destroyed);
32501+ atomic_inc_unchecked(&qps_destroyed);
32502
32503 /* Free the control structures */
32504
32505diff --git a/drivers/infiniband/hw/nes/nes.h b/drivers/infiniband/hw/nes/nes.h
32506index c438e46..ca30356 100644
32507--- a/drivers/infiniband/hw/nes/nes.h
32508+++ b/drivers/infiniband/hw/nes/nes.h
32509@@ -178,17 +178,17 @@ extern unsigned int nes_debug_level;
32510 extern unsigned int wqm_quanta;
32511 extern struct list_head nes_adapter_list;
32512
32513-extern atomic_t cm_connects;
32514-extern atomic_t cm_accepts;
32515-extern atomic_t cm_disconnects;
32516-extern atomic_t cm_closes;
32517-extern atomic_t cm_connecteds;
32518-extern atomic_t cm_connect_reqs;
32519-extern atomic_t cm_rejects;
32520-extern atomic_t mod_qp_timouts;
32521-extern atomic_t qps_created;
32522-extern atomic_t qps_destroyed;
32523-extern atomic_t sw_qps_destroyed;
32524+extern atomic_unchecked_t cm_connects;
32525+extern atomic_unchecked_t cm_accepts;
32526+extern atomic_unchecked_t cm_disconnects;
32527+extern atomic_unchecked_t cm_closes;
32528+extern atomic_unchecked_t cm_connecteds;
32529+extern atomic_unchecked_t cm_connect_reqs;
32530+extern atomic_unchecked_t cm_rejects;
32531+extern atomic_unchecked_t mod_qp_timouts;
32532+extern atomic_unchecked_t qps_created;
32533+extern atomic_unchecked_t qps_destroyed;
32534+extern atomic_unchecked_t sw_qps_destroyed;
32535 extern u32 mh_detected;
32536 extern u32 mh_pauses_sent;
32537 extern u32 cm_packets_sent;
32538@@ -197,16 +197,16 @@ extern u32 cm_packets_created;
32539 extern u32 cm_packets_received;
32540 extern u32 cm_packets_dropped;
32541 extern u32 cm_packets_retrans;
32542-extern atomic_t cm_listens_created;
32543-extern atomic_t cm_listens_destroyed;
32544+extern atomic_unchecked_t cm_listens_created;
32545+extern atomic_unchecked_t cm_listens_destroyed;
32546 extern u32 cm_backlog_drops;
32547-extern atomic_t cm_loopbacks;
32548-extern atomic_t cm_nodes_created;
32549-extern atomic_t cm_nodes_destroyed;
32550-extern atomic_t cm_accel_dropped_pkts;
32551-extern atomic_t cm_resets_recvd;
32552-extern atomic_t pau_qps_created;
32553-extern atomic_t pau_qps_destroyed;
32554+extern atomic_unchecked_t cm_loopbacks;
32555+extern atomic_unchecked_t cm_nodes_created;
32556+extern atomic_unchecked_t cm_nodes_destroyed;
32557+extern atomic_unchecked_t cm_accel_dropped_pkts;
32558+extern atomic_unchecked_t cm_resets_recvd;
32559+extern atomic_unchecked_t pau_qps_created;
32560+extern atomic_unchecked_t pau_qps_destroyed;
32561
32562 extern u32 int_mod_timer_init;
32563 extern u32 int_mod_cq_depth_256;
32564diff --git a/drivers/infiniband/hw/nes/nes_cm.c b/drivers/infiniband/hw/nes/nes_cm.c
32565index 020e95c..fbb3450 100644
32566--- a/drivers/infiniband/hw/nes/nes_cm.c
32567+++ b/drivers/infiniband/hw/nes/nes_cm.c
32568@@ -68,14 +68,14 @@ u32 cm_packets_dropped;
32569 u32 cm_packets_retrans;
32570 u32 cm_packets_created;
32571 u32 cm_packets_received;
32572-atomic_t cm_listens_created;
32573-atomic_t cm_listens_destroyed;
32574+atomic_unchecked_t cm_listens_created;
32575+atomic_unchecked_t cm_listens_destroyed;
32576 u32 cm_backlog_drops;
32577-atomic_t cm_loopbacks;
32578-atomic_t cm_nodes_created;
32579-atomic_t cm_nodes_destroyed;
32580-atomic_t cm_accel_dropped_pkts;
32581-atomic_t cm_resets_recvd;
32582+atomic_unchecked_t cm_loopbacks;
32583+atomic_unchecked_t cm_nodes_created;
32584+atomic_unchecked_t cm_nodes_destroyed;
32585+atomic_unchecked_t cm_accel_dropped_pkts;
32586+atomic_unchecked_t cm_resets_recvd;
32587
32588 static inline int mini_cm_accelerated(struct nes_cm_core *, struct nes_cm_node *);
32589 static struct nes_cm_listener *mini_cm_listen(struct nes_cm_core *, struct nes_vnic *, struct nes_cm_info *);
32590@@ -148,13 +148,13 @@ static struct nes_cm_ops nes_cm_api = {
32591
32592 static struct nes_cm_core *g_cm_core;
32593
32594-atomic_t cm_connects;
32595-atomic_t cm_accepts;
32596-atomic_t cm_disconnects;
32597-atomic_t cm_closes;
32598-atomic_t cm_connecteds;
32599-atomic_t cm_connect_reqs;
32600-atomic_t cm_rejects;
32601+atomic_unchecked_t cm_connects;
32602+atomic_unchecked_t cm_accepts;
32603+atomic_unchecked_t cm_disconnects;
32604+atomic_unchecked_t cm_closes;
32605+atomic_unchecked_t cm_connecteds;
32606+atomic_unchecked_t cm_connect_reqs;
32607+atomic_unchecked_t cm_rejects;
32608
32609 int nes_add_ref_cm_node(struct nes_cm_node *cm_node)
32610 {
32611@@ -1279,7 +1279,7 @@ static int mini_cm_dec_refcnt_listen(struct nes_cm_core *cm_core,
32612 kfree(listener);
32613 listener = NULL;
32614 ret = 0;
32615- atomic_inc(&cm_listens_destroyed);
32616+ atomic_inc_unchecked(&cm_listens_destroyed);
32617 } else {
32618 spin_unlock_irqrestore(&cm_core->listen_list_lock, flags);
32619 }
32620@@ -1482,7 +1482,7 @@ static struct nes_cm_node *make_cm_node(struct nes_cm_core *cm_core,
32621 cm_node->rem_mac);
32622
32623 add_hte_node(cm_core, cm_node);
32624- atomic_inc(&cm_nodes_created);
32625+ atomic_inc_unchecked(&cm_nodes_created);
32626
32627 return cm_node;
32628 }
32629@@ -1540,7 +1540,7 @@ static int rem_ref_cm_node(struct nes_cm_core *cm_core,
32630 }
32631
32632 atomic_dec(&cm_core->node_cnt);
32633- atomic_inc(&cm_nodes_destroyed);
32634+ atomic_inc_unchecked(&cm_nodes_destroyed);
32635 nesqp = cm_node->nesqp;
32636 if (nesqp) {
32637 nesqp->cm_node = NULL;
32638@@ -1604,7 +1604,7 @@ static int process_options(struct nes_cm_node *cm_node, u8 *optionsloc,
32639
32640 static void drop_packet(struct sk_buff *skb)
32641 {
32642- atomic_inc(&cm_accel_dropped_pkts);
32643+ atomic_inc_unchecked(&cm_accel_dropped_pkts);
32644 dev_kfree_skb_any(skb);
32645 }
32646
32647@@ -1667,7 +1667,7 @@ static void handle_rst_pkt(struct nes_cm_node *cm_node, struct sk_buff *skb,
32648 {
32649
32650 int reset = 0; /* whether to send reset in case of err.. */
32651- atomic_inc(&cm_resets_recvd);
32652+ atomic_inc_unchecked(&cm_resets_recvd);
32653 nes_debug(NES_DBG_CM, "Received Reset, cm_node = %p, state = %u."
32654 " refcnt=%d\n", cm_node, cm_node->state,
32655 atomic_read(&cm_node->ref_count));
32656@@ -2308,7 +2308,7 @@ static struct nes_cm_node *mini_cm_connect(struct nes_cm_core *cm_core,
32657 rem_ref_cm_node(cm_node->cm_core, cm_node);
32658 return NULL;
32659 }
32660- atomic_inc(&cm_loopbacks);
32661+ atomic_inc_unchecked(&cm_loopbacks);
32662 loopbackremotenode->loopbackpartner = cm_node;
32663 loopbackremotenode->tcp_cntxt.rcv_wscale =
32664 NES_CM_DEFAULT_RCV_WND_SCALE;
32665@@ -2583,7 +2583,7 @@ static int mini_cm_recv_pkt(struct nes_cm_core *cm_core,
32666 nes_queue_mgt_skbs(skb, nesvnic, cm_node->nesqp);
32667 else {
32668 rem_ref_cm_node(cm_core, cm_node);
32669- atomic_inc(&cm_accel_dropped_pkts);
32670+ atomic_inc_unchecked(&cm_accel_dropped_pkts);
32671 dev_kfree_skb_any(skb);
32672 }
32673 break;
32674@@ -2891,7 +2891,7 @@ static int nes_cm_disconn_true(struct nes_qp *nesqp)
32675
32676 if ((cm_id) && (cm_id->event_handler)) {
32677 if (issue_disconn) {
32678- atomic_inc(&cm_disconnects);
32679+ atomic_inc_unchecked(&cm_disconnects);
32680 cm_event.event = IW_CM_EVENT_DISCONNECT;
32681 cm_event.status = disconn_status;
32682 cm_event.local_addr = cm_id->local_addr;
32683@@ -2913,7 +2913,7 @@ static int nes_cm_disconn_true(struct nes_qp *nesqp)
32684 }
32685
32686 if (issue_close) {
32687- atomic_inc(&cm_closes);
32688+ atomic_inc_unchecked(&cm_closes);
32689 nes_disconnect(nesqp, 1);
32690
32691 cm_id->provider_data = nesqp;
32692@@ -3049,7 +3049,7 @@ int nes_accept(struct iw_cm_id *cm_id, struct iw_cm_conn_param *conn_param)
32693
32694 nes_debug(NES_DBG_CM, "QP%u, cm_node=%p, jiffies = %lu listener = %p\n",
32695 nesqp->hwqp.qp_id, cm_node, jiffies, cm_node->listener);
32696- atomic_inc(&cm_accepts);
32697+ atomic_inc_unchecked(&cm_accepts);
32698
32699 nes_debug(NES_DBG_CM, "netdev refcnt = %u.\n",
32700 netdev_refcnt_read(nesvnic->netdev));
32701@@ -3251,7 +3251,7 @@ int nes_reject(struct iw_cm_id *cm_id, const void *pdata, u8 pdata_len)
32702 struct nes_cm_core *cm_core;
32703 u8 *start_buff;
32704
32705- atomic_inc(&cm_rejects);
32706+ atomic_inc_unchecked(&cm_rejects);
32707 cm_node = (struct nes_cm_node *)cm_id->provider_data;
32708 loopback = cm_node->loopbackpartner;
32709 cm_core = cm_node->cm_core;
32710@@ -3311,7 +3311,7 @@ int nes_connect(struct iw_cm_id *cm_id, struct iw_cm_conn_param *conn_param)
32711 ntohl(cm_id->local_addr.sin_addr.s_addr),
32712 ntohs(cm_id->local_addr.sin_port));
32713
32714- atomic_inc(&cm_connects);
32715+ atomic_inc_unchecked(&cm_connects);
32716 nesqp->active_conn = 1;
32717
32718 /* cache the cm_id in the qp */
32719@@ -3421,7 +3421,7 @@ int nes_create_listen(struct iw_cm_id *cm_id, int backlog)
32720 g_cm_core->api->stop_listener(g_cm_core, (void *)cm_node);
32721 return err;
32722 }
32723- atomic_inc(&cm_listens_created);
32724+ atomic_inc_unchecked(&cm_listens_created);
32725 }
32726
32727 cm_id->add_ref(cm_id);
32728@@ -3522,7 +3522,7 @@ static void cm_event_connected(struct nes_cm_event *event)
32729
32730 if (nesqp->destroyed)
32731 return;
32732- atomic_inc(&cm_connecteds);
32733+ atomic_inc_unchecked(&cm_connecteds);
32734 nes_debug(NES_DBG_CM, "QP%u attempting to connect to 0x%08X:0x%04X on"
32735 " local port 0x%04X. jiffies = %lu.\n",
32736 nesqp->hwqp.qp_id,
32737@@ -3709,7 +3709,7 @@ static void cm_event_reset(struct nes_cm_event *event)
32738
32739 cm_id->add_ref(cm_id);
32740 ret = cm_id->event_handler(cm_id, &cm_event);
32741- atomic_inc(&cm_closes);
32742+ atomic_inc_unchecked(&cm_closes);
32743 cm_event.event = IW_CM_EVENT_CLOSE;
32744 cm_event.status = 0;
32745 cm_event.provider_data = cm_id->provider_data;
32746@@ -3745,7 +3745,7 @@ static void cm_event_mpa_req(struct nes_cm_event *event)
32747 return;
32748 cm_id = cm_node->cm_id;
32749
32750- atomic_inc(&cm_connect_reqs);
32751+ atomic_inc_unchecked(&cm_connect_reqs);
32752 nes_debug(NES_DBG_CM, "cm_node = %p - cm_id = %p, jiffies = %lu\n",
32753 cm_node, cm_id, jiffies);
32754
32755@@ -3785,7 +3785,7 @@ static void cm_event_mpa_reject(struct nes_cm_event *event)
32756 return;
32757 cm_id = cm_node->cm_id;
32758
32759- atomic_inc(&cm_connect_reqs);
32760+ atomic_inc_unchecked(&cm_connect_reqs);
32761 nes_debug(NES_DBG_CM, "cm_node = %p - cm_id = %p, jiffies = %lu\n",
32762 cm_node, cm_id, jiffies);
32763
32764diff --git a/drivers/infiniband/hw/nes/nes_mgt.c b/drivers/infiniband/hw/nes/nes_mgt.c
32765index 3ba7be3..c81f6ff 100644
32766--- a/drivers/infiniband/hw/nes/nes_mgt.c
32767+++ b/drivers/infiniband/hw/nes/nes_mgt.c
32768@@ -40,8 +40,8 @@
32769 #include "nes.h"
32770 #include "nes_mgt.h"
32771
32772-atomic_t pau_qps_created;
32773-atomic_t pau_qps_destroyed;
32774+atomic_unchecked_t pau_qps_created;
32775+atomic_unchecked_t pau_qps_destroyed;
32776
32777 static void nes_replenish_mgt_rq(struct nes_vnic_mgt *mgtvnic)
32778 {
32779@@ -621,7 +621,7 @@ void nes_destroy_pau_qp(struct nes_device *nesdev, struct nes_qp *nesqp)
32780 {
32781 struct sk_buff *skb;
32782 unsigned long flags;
32783- atomic_inc(&pau_qps_destroyed);
32784+ atomic_inc_unchecked(&pau_qps_destroyed);
32785
32786 /* Free packets that have not yet been forwarded */
32787 /* Lock is acquired by skb_dequeue when removing the skb */
32788@@ -812,7 +812,7 @@ static void nes_mgt_ce_handler(struct nes_device *nesdev, struct nes_hw_nic_cq *
32789 cq->cq_vbase[head].cqe_words[NES_NIC_CQE_HASH_RCVNXT]);
32790 skb_queue_head_init(&nesqp->pau_list);
32791 spin_lock_init(&nesqp->pau_lock);
32792- atomic_inc(&pau_qps_created);
32793+ atomic_inc_unchecked(&pau_qps_created);
32794 nes_change_quad_hash(nesdev, mgtvnic->nesvnic, nesqp);
32795 }
32796
32797diff --git a/drivers/infiniband/hw/nes/nes_nic.c b/drivers/infiniband/hw/nes/nes_nic.c
32798index f3a3ecf..57d311d 100644
32799--- a/drivers/infiniband/hw/nes/nes_nic.c
32800+++ b/drivers/infiniband/hw/nes/nes_nic.c
32801@@ -1277,39 +1277,39 @@ static void nes_netdev_get_ethtool_stats(struct net_device *netdev,
32802 target_stat_values[++index] = mh_detected;
32803 target_stat_values[++index] = mh_pauses_sent;
32804 target_stat_values[++index] = nesvnic->endnode_ipv4_tcp_retransmits;
32805- target_stat_values[++index] = atomic_read(&cm_connects);
32806- target_stat_values[++index] = atomic_read(&cm_accepts);
32807- target_stat_values[++index] = atomic_read(&cm_disconnects);
32808- target_stat_values[++index] = atomic_read(&cm_connecteds);
32809- target_stat_values[++index] = atomic_read(&cm_connect_reqs);
32810- target_stat_values[++index] = atomic_read(&cm_rejects);
32811- target_stat_values[++index] = atomic_read(&mod_qp_timouts);
32812- target_stat_values[++index] = atomic_read(&qps_created);
32813- target_stat_values[++index] = atomic_read(&sw_qps_destroyed);
32814- target_stat_values[++index] = atomic_read(&qps_destroyed);
32815- target_stat_values[++index] = atomic_read(&cm_closes);
32816+ target_stat_values[++index] = atomic_read_unchecked(&cm_connects);
32817+ target_stat_values[++index] = atomic_read_unchecked(&cm_accepts);
32818+ target_stat_values[++index] = atomic_read_unchecked(&cm_disconnects);
32819+ target_stat_values[++index] = atomic_read_unchecked(&cm_connecteds);
32820+ target_stat_values[++index] = atomic_read_unchecked(&cm_connect_reqs);
32821+ target_stat_values[++index] = atomic_read_unchecked(&cm_rejects);
32822+ target_stat_values[++index] = atomic_read_unchecked(&mod_qp_timouts);
32823+ target_stat_values[++index] = atomic_read_unchecked(&qps_created);
32824+ target_stat_values[++index] = atomic_read_unchecked(&sw_qps_destroyed);
32825+ target_stat_values[++index] = atomic_read_unchecked(&qps_destroyed);
32826+ target_stat_values[++index] = atomic_read_unchecked(&cm_closes);
32827 target_stat_values[++index] = cm_packets_sent;
32828 target_stat_values[++index] = cm_packets_bounced;
32829 target_stat_values[++index] = cm_packets_created;
32830 target_stat_values[++index] = cm_packets_received;
32831 target_stat_values[++index] = cm_packets_dropped;
32832 target_stat_values[++index] = cm_packets_retrans;
32833- target_stat_values[++index] = atomic_read(&cm_listens_created);
32834- target_stat_values[++index] = atomic_read(&cm_listens_destroyed);
32835+ target_stat_values[++index] = atomic_read_unchecked(&cm_listens_created);
32836+ target_stat_values[++index] = atomic_read_unchecked(&cm_listens_destroyed);
32837 target_stat_values[++index] = cm_backlog_drops;
32838- target_stat_values[++index] = atomic_read(&cm_loopbacks);
32839- target_stat_values[++index] = atomic_read(&cm_nodes_created);
32840- target_stat_values[++index] = atomic_read(&cm_nodes_destroyed);
32841- target_stat_values[++index] = atomic_read(&cm_accel_dropped_pkts);
32842- target_stat_values[++index] = atomic_read(&cm_resets_recvd);
32843+ target_stat_values[++index] = atomic_read_unchecked(&cm_loopbacks);
32844+ target_stat_values[++index] = atomic_read_unchecked(&cm_nodes_created);
32845+ target_stat_values[++index] = atomic_read_unchecked(&cm_nodes_destroyed);
32846+ target_stat_values[++index] = atomic_read_unchecked(&cm_accel_dropped_pkts);
32847+ target_stat_values[++index] = atomic_read_unchecked(&cm_resets_recvd);
32848 target_stat_values[++index] = nesadapter->free_4kpbl;
32849 target_stat_values[++index] = nesadapter->free_256pbl;
32850 target_stat_values[++index] = int_mod_timer_init;
32851 target_stat_values[++index] = nesvnic->lro_mgr.stats.aggregated;
32852 target_stat_values[++index] = nesvnic->lro_mgr.stats.flushed;
32853 target_stat_values[++index] = nesvnic->lro_mgr.stats.no_desc;
32854- target_stat_values[++index] = atomic_read(&pau_qps_created);
32855- target_stat_values[++index] = atomic_read(&pau_qps_destroyed);
32856+ target_stat_values[++index] = atomic_read_unchecked(&pau_qps_created);
32857+ target_stat_values[++index] = atomic_read_unchecked(&pau_qps_destroyed);
32858 }
32859
32860 /**
32861diff --git a/drivers/infiniband/hw/nes/nes_verbs.c b/drivers/infiniband/hw/nes/nes_verbs.c
32862index 8b8812d..a5e1133 100644
32863--- a/drivers/infiniband/hw/nes/nes_verbs.c
32864+++ b/drivers/infiniband/hw/nes/nes_verbs.c
32865@@ -46,9 +46,9 @@
32866
32867 #include <rdma/ib_umem.h>
32868
32869-atomic_t mod_qp_timouts;
32870-atomic_t qps_created;
32871-atomic_t sw_qps_destroyed;
32872+atomic_unchecked_t mod_qp_timouts;
32873+atomic_unchecked_t qps_created;
32874+atomic_unchecked_t sw_qps_destroyed;
32875
32876 static void nes_unregister_ofa_device(struct nes_ib_device *nesibdev);
32877
32878@@ -1131,7 +1131,7 @@ static struct ib_qp *nes_create_qp(struct ib_pd *ibpd,
32879 if (init_attr->create_flags)
32880 return ERR_PTR(-EINVAL);
32881
32882- atomic_inc(&qps_created);
32883+ atomic_inc_unchecked(&qps_created);
32884 switch (init_attr->qp_type) {
32885 case IB_QPT_RC:
32886 if (nes_drv_opt & NES_DRV_OPT_NO_INLINE_DATA) {
32887@@ -1460,7 +1460,7 @@ static int nes_destroy_qp(struct ib_qp *ibqp)
32888 struct iw_cm_event cm_event;
32889 int ret = 0;
32890
32891- atomic_inc(&sw_qps_destroyed);
32892+ atomic_inc_unchecked(&sw_qps_destroyed);
32893 nesqp->destroyed = 1;
32894
32895 /* Blow away the connection if it exists. */
32896diff --git a/drivers/infiniband/hw/qib/qib.h b/drivers/infiniband/hw/qib/qib.h
32897index 7b1b8669..4b69f85 100644
32898--- a/drivers/infiniband/hw/qib/qib.h
32899+++ b/drivers/infiniband/hw/qib/qib.h
32900@@ -51,6 +51,7 @@
32901 #include <linux/completion.h>
32902 #include <linux/kref.h>
32903 #include <linux/sched.h>
32904+#include <linux/slab.h>
32905
32906 #include "qib_common.h"
32907 #include "qib_verbs.h"
32908diff --git a/drivers/input/gameport/gameport.c b/drivers/input/gameport/gameport.c
32909index da739d9..da1c7f4 100644
32910--- a/drivers/input/gameport/gameport.c
32911+++ b/drivers/input/gameport/gameport.c
32912@@ -487,14 +487,14 @@ EXPORT_SYMBOL(gameport_set_phys);
32913 */
32914 static void gameport_init_port(struct gameport *gameport)
32915 {
32916- static atomic_t gameport_no = ATOMIC_INIT(0);
32917+ static atomic_unchecked_t gameport_no = ATOMIC_INIT(0);
32918
32919 __module_get(THIS_MODULE);
32920
32921 mutex_init(&gameport->drv_mutex);
32922 device_initialize(&gameport->dev);
32923 dev_set_name(&gameport->dev, "gameport%lu",
32924- (unsigned long)atomic_inc_return(&gameport_no) - 1);
32925+ (unsigned long)atomic_inc_return_unchecked(&gameport_no) - 1);
32926 gameport->dev.bus = &gameport_bus;
32927 gameport->dev.release = gameport_release_port;
32928 if (gameport->parent)
32929diff --git a/drivers/input/input.c b/drivers/input/input.c
32930index 8921c61..f5cd63d 100644
32931--- a/drivers/input/input.c
32932+++ b/drivers/input/input.c
32933@@ -1814,7 +1814,7 @@ static void input_cleanse_bitmasks(struct input_dev *dev)
32934 */
32935 int input_register_device(struct input_dev *dev)
32936 {
32937- static atomic_t input_no = ATOMIC_INIT(0);
32938+ static atomic_unchecked_t input_no = ATOMIC_INIT(0);
32939 struct input_handler *handler;
32940 const char *path;
32941 int error;
32942@@ -1851,7 +1851,7 @@ int input_register_device(struct input_dev *dev)
32943 dev->setkeycode = input_default_setkeycode;
32944
32945 dev_set_name(&dev->dev, "input%ld",
32946- (unsigned long) atomic_inc_return(&input_no) - 1);
32947+ (unsigned long) atomic_inc_return_unchecked(&input_no) - 1);
32948
32949 error = device_add(&dev->dev);
32950 if (error)
32951diff --git a/drivers/input/joystick/sidewinder.c b/drivers/input/joystick/sidewinder.c
32952index 04c69af..5f92d00 100644
32953--- a/drivers/input/joystick/sidewinder.c
32954+++ b/drivers/input/joystick/sidewinder.c
32955@@ -30,6 +30,7 @@
32956 #include <linux/kernel.h>
32957 #include <linux/module.h>
32958 #include <linux/slab.h>
32959+#include <linux/sched.h>
32960 #include <linux/init.h>
32961 #include <linux/input.h>
32962 #include <linux/gameport.h>
32963diff --git a/drivers/input/joystick/xpad.c b/drivers/input/joystick/xpad.c
32964index 83811e4..0822b90 100644
32965--- a/drivers/input/joystick/xpad.c
32966+++ b/drivers/input/joystick/xpad.c
32967@@ -726,7 +726,7 @@ static void xpad_led_set(struct led_classdev *led_cdev,
32968
32969 static int xpad_led_probe(struct usb_xpad *xpad)
32970 {
32971- static atomic_t led_seq = ATOMIC_INIT(0);
32972+ static atomic_unchecked_t led_seq = ATOMIC_INIT(0);
32973 long led_no;
32974 struct xpad_led *led;
32975 struct led_classdev *led_cdev;
32976@@ -739,7 +739,7 @@ static int xpad_led_probe(struct usb_xpad *xpad)
32977 if (!led)
32978 return -ENOMEM;
32979
32980- led_no = (long)atomic_inc_return(&led_seq) - 1;
32981+ led_no = (long)atomic_inc_return_unchecked(&led_seq) - 1;
32982
32983 snprintf(led->name, sizeof(led->name), "xpad%ld", led_no);
32984 led->xpad = xpad;
32985diff --git a/drivers/input/mousedev.c b/drivers/input/mousedev.c
32986index 0110b5a..d3ad144 100644
32987--- a/drivers/input/mousedev.c
32988+++ b/drivers/input/mousedev.c
32989@@ -763,7 +763,7 @@ static ssize_t mousedev_read(struct file *file, char __user *buffer,
32990
32991 spin_unlock_irq(&client->packet_lock);
32992
32993- if (copy_to_user(buffer, data, count))
32994+ if (count > sizeof(data) || copy_to_user(buffer, data, count))
32995 return -EFAULT;
32996
32997 return count;
32998diff --git a/drivers/input/serio/serio.c b/drivers/input/serio/serio.c
32999index d0f7533..fb8215b 100644
33000--- a/drivers/input/serio/serio.c
33001+++ b/drivers/input/serio/serio.c
33002@@ -496,7 +496,7 @@ static void serio_release_port(struct device *dev)
33003 */
33004 static void serio_init_port(struct serio *serio)
33005 {
33006- static atomic_t serio_no = ATOMIC_INIT(0);
33007+ static atomic_unchecked_t serio_no = ATOMIC_INIT(0);
33008
33009 __module_get(THIS_MODULE);
33010
33011@@ -507,7 +507,7 @@ static void serio_init_port(struct serio *serio)
33012 mutex_init(&serio->drv_mutex);
33013 device_initialize(&serio->dev);
33014 dev_set_name(&serio->dev, "serio%ld",
33015- (long)atomic_inc_return(&serio_no) - 1);
33016+ (long)atomic_inc_return_unchecked(&serio_no) - 1);
33017 serio->dev.bus = &serio_bus;
33018 serio->dev.release = serio_release_port;
33019 serio->dev.groups = serio_device_attr_groups;
33020diff --git a/drivers/isdn/capi/capi.c b/drivers/isdn/capi/capi.c
33021index 38c4bd8..58965d9 100644
33022--- a/drivers/isdn/capi/capi.c
33023+++ b/drivers/isdn/capi/capi.c
33024@@ -83,8 +83,8 @@ struct capiminor {
33025
33026 struct capi20_appl *ap;
33027 u32 ncci;
33028- atomic_t datahandle;
33029- atomic_t msgid;
33030+ atomic_unchecked_t datahandle;
33031+ atomic_unchecked_t msgid;
33032
33033 struct tty_port port;
33034 int ttyinstop;
33035@@ -392,7 +392,7 @@ gen_data_b3_resp_for(struct capiminor *mp, struct sk_buff *skb)
33036 capimsg_setu16(s, 2, mp->ap->applid);
33037 capimsg_setu8 (s, 4, CAPI_DATA_B3);
33038 capimsg_setu8 (s, 5, CAPI_RESP);
33039- capimsg_setu16(s, 6, atomic_inc_return(&mp->msgid));
33040+ capimsg_setu16(s, 6, atomic_inc_return_unchecked(&mp->msgid));
33041 capimsg_setu32(s, 8, mp->ncci);
33042 capimsg_setu16(s, 12, datahandle);
33043 }
33044@@ -513,14 +513,14 @@ static void handle_minor_send(struct capiminor *mp)
33045 mp->outbytes -= len;
33046 spin_unlock_bh(&mp->outlock);
33047
33048- datahandle = atomic_inc_return(&mp->datahandle);
33049+ datahandle = atomic_inc_return_unchecked(&mp->datahandle);
33050 skb_push(skb, CAPI_DATA_B3_REQ_LEN);
33051 memset(skb->data, 0, CAPI_DATA_B3_REQ_LEN);
33052 capimsg_setu16(skb->data, 0, CAPI_DATA_B3_REQ_LEN);
33053 capimsg_setu16(skb->data, 2, mp->ap->applid);
33054 capimsg_setu8 (skb->data, 4, CAPI_DATA_B3);
33055 capimsg_setu8 (skb->data, 5, CAPI_REQ);
33056- capimsg_setu16(skb->data, 6, atomic_inc_return(&mp->msgid));
33057+ capimsg_setu16(skb->data, 6, atomic_inc_return_unchecked(&mp->msgid));
33058 capimsg_setu32(skb->data, 8, mp->ncci); /* NCCI */
33059 capimsg_setu32(skb->data, 12, (u32)(long)skb->data);/* Data32 */
33060 capimsg_setu16(skb->data, 16, len); /* Data length */
33061diff --git a/drivers/isdn/gigaset/interface.c b/drivers/isdn/gigaset/interface.c
33062index a6d9fd2..afdb8a3 100644
33063--- a/drivers/isdn/gigaset/interface.c
33064+++ b/drivers/isdn/gigaset/interface.c
33065@@ -160,9 +160,9 @@ static int if_open(struct tty_struct *tty, struct file *filp)
33066 }
33067 tty->driver_data = cs;
33068
33069- ++cs->port.count;
33070+ atomic_inc(&cs->port.count);
33071
33072- if (cs->port.count == 1) {
33073+ if (atomic_read(&cs->port.count) == 1) {
33074 tty_port_tty_set(&cs->port, tty);
33075 tty->low_latency = 1;
33076 }
33077@@ -186,9 +186,9 @@ static void if_close(struct tty_struct *tty, struct file *filp)
33078
33079 if (!cs->connected)
33080 gig_dbg(DEBUG_IF, "not connected"); /* nothing to do */
33081- else if (!cs->port.count)
33082+ else if (!atomic_read(&cs->port.count))
33083 dev_warn(cs->dev, "%s: device not opened\n", __func__);
33084- else if (!--cs->port.count)
33085+ else if (!atomic_dec_return(&cs->port.count))
33086 tty_port_tty_set(&cs->port, NULL);
33087
33088 mutex_unlock(&cs->mutex);
33089diff --git a/drivers/isdn/hardware/avm/b1.c b/drivers/isdn/hardware/avm/b1.c
33090index 821f7ac..28d4030 100644
33091--- a/drivers/isdn/hardware/avm/b1.c
33092+++ b/drivers/isdn/hardware/avm/b1.c
33093@@ -176,7 +176,7 @@ int b1_load_t4file(avmcard *card, capiloaddatapart *t4file)
33094 }
33095 if (left) {
33096 if (t4file->user) {
33097- if (copy_from_user(buf, dp, left))
33098+ if (left > sizeof buf || copy_from_user(buf, dp, left))
33099 return -EFAULT;
33100 } else {
33101 memcpy(buf, dp, left);
33102@@ -224,7 +224,7 @@ int b1_load_config(avmcard *card, capiloaddatapart *config)
33103 }
33104 if (left) {
33105 if (config->user) {
33106- if (copy_from_user(buf, dp, left))
33107+ if (left > sizeof buf || copy_from_user(buf, dp, left))
33108 return -EFAULT;
33109 } else {
33110 memcpy(buf, dp, left);
33111diff --git a/drivers/isdn/hardware/eicon/divasync.h b/drivers/isdn/hardware/eicon/divasync.h
33112index dd6b53a..19d9ee6 100644
33113--- a/drivers/isdn/hardware/eicon/divasync.h
33114+++ b/drivers/isdn/hardware/eicon/divasync.h
33115@@ -146,7 +146,7 @@ typedef struct _diva_didd_add_adapter {
33116 } diva_didd_add_adapter_t;
33117 typedef struct _diva_didd_remove_adapter {
33118 IDI_CALL p_request;
33119-} diva_didd_remove_adapter_t;
33120+} __no_const diva_didd_remove_adapter_t;
33121 typedef struct _diva_didd_read_adapter_array {
33122 void *buffer;
33123 dword length;
33124diff --git a/drivers/isdn/hardware/eicon/xdi_adapter.h b/drivers/isdn/hardware/eicon/xdi_adapter.h
33125index d303e65..28bcb7b 100644
33126--- a/drivers/isdn/hardware/eicon/xdi_adapter.h
33127+++ b/drivers/isdn/hardware/eicon/xdi_adapter.h
33128@@ -44,7 +44,7 @@ typedef struct _xdi_mbox_t {
33129 typedef struct _diva_os_idi_adapter_interface {
33130 diva_init_card_proc_t cleanup_adapter_proc;
33131 diva_cmd_card_proc_t cmd_proc;
33132-} diva_os_idi_adapter_interface_t;
33133+} __no_const diva_os_idi_adapter_interface_t;
33134
33135 typedef struct _diva_os_xdi_adapter {
33136 struct list_head link;
33137diff --git a/drivers/isdn/i4l/isdn_tty.c b/drivers/isdn/i4l/isdn_tty.c
33138index 7bc5067..fd36232 100644
33139--- a/drivers/isdn/i4l/isdn_tty.c
33140+++ b/drivers/isdn/i4l/isdn_tty.c
33141@@ -1505,9 +1505,9 @@ isdn_tty_open(struct tty_struct *tty, struct file *filp)
33142 port = &info->port;
33143 #ifdef ISDN_DEBUG_MODEM_OPEN
33144 printk(KERN_DEBUG "isdn_tty_open %s, count = %d\n", tty->name,
33145- port->count);
33146+ atomic_read(&port->count))
33147 #endif
33148- port->count++;
33149+ atomic_inc(&port->count);
33150 tty->driver_data = info;
33151 port->tty = tty;
33152 tty->port = port;
33153@@ -1553,7 +1553,7 @@ isdn_tty_close(struct tty_struct *tty, struct file *filp)
33154 #endif
33155 return;
33156 }
33157- if ((tty->count == 1) && (port->count != 1)) {
33158+ if ((tty->count == 1) && (atomic_read(&port->count) != 1)) {
33159 /*
33160 * Uh, oh. tty->count is 1, which means that the tty
33161 * structure will be freed. Info->count should always
33162@@ -1562,15 +1562,15 @@ isdn_tty_close(struct tty_struct *tty, struct file *filp)
33163 * serial port won't be shutdown.
33164 */
33165 printk(KERN_ERR "isdn_tty_close: bad port count; tty->count is 1, "
33166- "info->count is %d\n", port->count);
33167- port->count = 1;
33168+ "info->count is %d\n", atomic_read(&port->count));
33169+ atomic_set(&port->count, 1);
33170 }
33171- if (--port->count < 0) {
33172+ if (atomic_dec_return(&port->count) < 0) {
33173 printk(KERN_ERR "isdn_tty_close: bad port count for ttyi%d: %d\n",
33174- info->line, port->count);
33175- port->count = 0;
33176+ info->line, atomic_read(&port->count));
33177+ atomic_set(&port->count, 0);
33178 }
33179- if (port->count) {
33180+ if (atomic_read(&port->count)) {
33181 #ifdef ISDN_DEBUG_MODEM_OPEN
33182 printk(KERN_DEBUG "isdn_tty_close after info->count != 0\n");
33183 #endif
33184@@ -1624,7 +1624,7 @@ isdn_tty_hangup(struct tty_struct *tty)
33185 if (isdn_tty_paranoia_check(info, tty->name, "isdn_tty_hangup"))
33186 return;
33187 isdn_tty_shutdown(info);
33188- port->count = 0;
33189+ atomic_set(&port->count, 0);
33190 port->flags &= ~ASYNC_NORMAL_ACTIVE;
33191 port->tty = NULL;
33192 wake_up_interruptible(&port->open_wait);
33193@@ -1964,7 +1964,7 @@ isdn_tty_find_icall(int di, int ch, setup_parm *setup)
33194 for (i = 0; i < ISDN_MAX_CHANNELS; i++) {
33195 modem_info *info = &dev->mdm.info[i];
33196
33197- if (info->port.count == 0)
33198+ if (atomic_read(&info->port.count) == 0)
33199 continue;
33200 if ((info->emu.mdmreg[REG_SI1] & si2bit[si1]) && /* SI1 is matching */
33201 (info->emu.mdmreg[REG_SI2] == si2)) { /* SI2 is matching */
33202diff --git a/drivers/isdn/icn/icn.c b/drivers/isdn/icn/icn.c
33203index e74df7c..03a03ba 100644
33204--- a/drivers/isdn/icn/icn.c
33205+++ b/drivers/isdn/icn/icn.c
33206@@ -1045,7 +1045,7 @@ icn_writecmd(const u_char *buf, int len, int user, icn_card *card)
33207 if (count > len)
33208 count = len;
33209 if (user) {
33210- if (copy_from_user(msg, buf, count))
33211+ if (count > sizeof msg || copy_from_user(msg, buf, count))
33212 return -EFAULT;
33213 } else
33214 memcpy(msg, buf, count);
33215diff --git a/drivers/lguest/core.c b/drivers/lguest/core.c
33216index b5fdcb7..5b6c59f 100644
33217--- a/drivers/lguest/core.c
33218+++ b/drivers/lguest/core.c
33219@@ -92,9 +92,17 @@ static __init int map_switcher(void)
33220 * it's worked so far. The end address needs +1 because __get_vm_area
33221 * allocates an extra guard page, so we need space for that.
33222 */
33223+
33224+#if defined(CONFIG_MODULES) && defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
33225+ switcher_vma = __get_vm_area(TOTAL_SWITCHER_PAGES * PAGE_SIZE,
33226+ VM_ALLOC | VM_KERNEXEC, SWITCHER_ADDR, SWITCHER_ADDR
33227+ + (TOTAL_SWITCHER_PAGES+1) * PAGE_SIZE);
33228+#else
33229 switcher_vma = __get_vm_area(TOTAL_SWITCHER_PAGES * PAGE_SIZE,
33230 VM_ALLOC, SWITCHER_ADDR, SWITCHER_ADDR
33231 + (TOTAL_SWITCHER_PAGES+1) * PAGE_SIZE);
33232+#endif
33233+
33234 if (!switcher_vma) {
33235 err = -ENOMEM;
33236 printk("lguest: could not map switcher pages high\n");
33237@@ -119,7 +127,7 @@ static __init int map_switcher(void)
33238 * Now the Switcher is mapped at the right address, we can't fail!
33239 * Copy in the compiled-in Switcher code (from x86/switcher_32.S).
33240 */
33241- memcpy(switcher_vma->addr, start_switcher_text,
33242+ memcpy(switcher_vma->addr, ktla_ktva(start_switcher_text),
33243 end_switcher_text - start_switcher_text);
33244
33245 printk(KERN_INFO "lguest: mapped switcher at %p\n",
33246diff --git a/drivers/lguest/x86/core.c b/drivers/lguest/x86/core.c
33247index 39809035..ce25c5e 100644
33248--- a/drivers/lguest/x86/core.c
33249+++ b/drivers/lguest/x86/core.c
33250@@ -59,7 +59,7 @@ static struct {
33251 /* Offset from where switcher.S was compiled to where we've copied it */
33252 static unsigned long switcher_offset(void)
33253 {
33254- return SWITCHER_ADDR - (unsigned long)start_switcher_text;
33255+ return SWITCHER_ADDR - (unsigned long)ktla_ktva(start_switcher_text);
33256 }
33257
33258 /* This cpu's struct lguest_pages. */
33259@@ -100,7 +100,13 @@ static void copy_in_guest_info(struct lg_cpu *cpu, struct lguest_pages *pages)
33260 * These copies are pretty cheap, so we do them unconditionally: */
33261 /* Save the current Host top-level page directory.
33262 */
33263+
33264+#ifdef CONFIG_PAX_PER_CPU_PGD
33265+ pages->state.host_cr3 = read_cr3();
33266+#else
33267 pages->state.host_cr3 = __pa(current->mm->pgd);
33268+#endif
33269+
33270 /*
33271 * Set up the Guest's page tables to see this CPU's pages (and no
33272 * other CPU's pages).
33273@@ -472,7 +478,7 @@ void __init lguest_arch_host_init(void)
33274 * compiled-in switcher code and the high-mapped copy we just made.
33275 */
33276 for (i = 0; i < IDT_ENTRIES; i++)
33277- default_idt_entries[i] += switcher_offset();
33278+ default_idt_entries[i] = ktla_ktva(default_idt_entries[i]) + switcher_offset();
33279
33280 /*
33281 * Set up the Switcher's per-cpu areas.
33282@@ -555,7 +561,7 @@ void __init lguest_arch_host_init(void)
33283 * it will be undisturbed when we switch. To change %cs and jump we
33284 * need this structure to feed to Intel's "lcall" instruction.
33285 */
33286- lguest_entry.offset = (long)switch_to_guest + switcher_offset();
33287+ lguest_entry.offset = (long)ktla_ktva(switch_to_guest) + switcher_offset();
33288 lguest_entry.segment = LGUEST_CS;
33289
33290 /*
33291diff --git a/drivers/lguest/x86/switcher_32.S b/drivers/lguest/x86/switcher_32.S
33292index 40634b0..4f5855e 100644
33293--- a/drivers/lguest/x86/switcher_32.S
33294+++ b/drivers/lguest/x86/switcher_32.S
33295@@ -87,6 +87,7 @@
33296 #include <asm/page.h>
33297 #include <asm/segment.h>
33298 #include <asm/lguest.h>
33299+#include <asm/processor-flags.h>
33300
33301 // We mark the start of the code to copy
33302 // It's placed in .text tho it's never run here
33303@@ -149,6 +150,13 @@ ENTRY(switch_to_guest)
33304 // Changes type when we load it: damn Intel!
33305 // For after we switch over our page tables
33306 // That entry will be read-only: we'd crash.
33307+
33308+#ifdef CONFIG_PAX_KERNEXEC
33309+ mov %cr0, %edx
33310+ xor $X86_CR0_WP, %edx
33311+ mov %edx, %cr0
33312+#endif
33313+
33314 movl $(GDT_ENTRY_TSS*8), %edx
33315 ltr %dx
33316
33317@@ -157,9 +165,15 @@ ENTRY(switch_to_guest)
33318 // Let's clear it again for our return.
33319 // The GDT descriptor of the Host
33320 // Points to the table after two "size" bytes
33321- movl (LGUEST_PAGES_host_gdt_desc+2)(%eax), %edx
33322+ movl (LGUEST_PAGES_host_gdt_desc+2)(%eax), %eax
33323 // Clear "used" from type field (byte 5, bit 2)
33324- andb $0xFD, (GDT_ENTRY_TSS*8 + 5)(%edx)
33325+ andb $0xFD, (GDT_ENTRY_TSS*8 + 5)(%eax)
33326+
33327+#ifdef CONFIG_PAX_KERNEXEC
33328+ mov %cr0, %eax
33329+ xor $X86_CR0_WP, %eax
33330+ mov %eax, %cr0
33331+#endif
33332
33333 // Once our page table's switched, the Guest is live!
33334 // The Host fades as we run this final step.
33335@@ -295,13 +309,12 @@ deliver_to_host:
33336 // I consulted gcc, and it gave
33337 // These instructions, which I gladly credit:
33338 leal (%edx,%ebx,8), %eax
33339- movzwl (%eax),%edx
33340- movl 4(%eax), %eax
33341- xorw %ax, %ax
33342- orl %eax, %edx
33343+ movl 4(%eax), %edx
33344+ movw (%eax), %dx
33345 // Now the address of the handler's in %edx
33346 // We call it now: its "iret" drops us home.
33347- jmp *%edx
33348+ ljmp $__KERNEL_CS, $1f
33349+1: jmp *%edx
33350
33351 // Every interrupt can come to us here
33352 // But we must truly tell each apart.
33353diff --git a/drivers/macintosh/macio_asic.c b/drivers/macintosh/macio_asic.c
33354index 20e5c2c..9e849a9 100644
33355--- a/drivers/macintosh/macio_asic.c
33356+++ b/drivers/macintosh/macio_asic.c
33357@@ -748,7 +748,7 @@ static void __devexit macio_pci_remove(struct pci_dev* pdev)
33358 * MacIO is matched against any Apple ID, it's probe() function
33359 * will then decide wether it applies or not
33360 */
33361-static const struct pci_device_id __devinitdata pci_ids [] = { {
33362+static const struct pci_device_id __devinitconst pci_ids [] = { {
33363 .vendor = PCI_VENDOR_ID_APPLE,
33364 .device = PCI_ANY_ID,
33365 .subvendor = PCI_ANY_ID,
33366diff --git a/drivers/md/bitmap.c b/drivers/md/bitmap.c
33367index 94e7f6b..2f4a0d8 100644
33368--- a/drivers/md/bitmap.c
33369+++ b/drivers/md/bitmap.c
33370@@ -1786,7 +1786,7 @@ void bitmap_status(struct seq_file *seq, struct bitmap *bitmap)
33371 chunk_kb ? "KB" : "B");
33372 if (bitmap->storage.file) {
33373 seq_printf(seq, ", file: ");
33374- seq_path(seq, &bitmap->storage.file->f_path, " \t\n");
33375+ seq_path(seq, &bitmap->storage.file->f_path, " \t\n\\");
33376 }
33377
33378 seq_printf(seq, "\n");
33379diff --git a/drivers/md/dm-ioctl.c b/drivers/md/dm-ioctl.c
33380index afd9598..528d8f9 100644
33381--- a/drivers/md/dm-ioctl.c
33382+++ b/drivers/md/dm-ioctl.c
33383@@ -1593,7 +1593,7 @@ static int validate_params(uint cmd, struct dm_ioctl *param)
33384 cmd == DM_LIST_VERSIONS_CMD)
33385 return 0;
33386
33387- if ((cmd == DM_DEV_CREATE_CMD)) {
33388+ if (cmd == DM_DEV_CREATE_CMD) {
33389 if (!*param->name) {
33390 DMWARN("name not supplied when creating device");
33391 return -EINVAL;
33392diff --git a/drivers/md/dm-raid1.c b/drivers/md/dm-raid1.c
33393index bc5ddba8..b961159 100644
33394--- a/drivers/md/dm-raid1.c
33395+++ b/drivers/md/dm-raid1.c
33396@@ -40,7 +40,7 @@ enum dm_raid1_error {
33397
33398 struct mirror {
33399 struct mirror_set *ms;
33400- atomic_t error_count;
33401+ atomic_unchecked_t error_count;
33402 unsigned long error_type;
33403 struct dm_dev *dev;
33404 sector_t offset;
33405@@ -185,7 +185,7 @@ static struct mirror *get_valid_mirror(struct mirror_set *ms)
33406 struct mirror *m;
33407
33408 for (m = ms->mirror; m < ms->mirror + ms->nr_mirrors; m++)
33409- if (!atomic_read(&m->error_count))
33410+ if (!atomic_read_unchecked(&m->error_count))
33411 return m;
33412
33413 return NULL;
33414@@ -217,7 +217,7 @@ static void fail_mirror(struct mirror *m, enum dm_raid1_error error_type)
33415 * simple way to tell if a device has encountered
33416 * errors.
33417 */
33418- atomic_inc(&m->error_count);
33419+ atomic_inc_unchecked(&m->error_count);
33420
33421 if (test_and_set_bit(error_type, &m->error_type))
33422 return;
33423@@ -408,7 +408,7 @@ static struct mirror *choose_mirror(struct mirror_set *ms, sector_t sector)
33424 struct mirror *m = get_default_mirror(ms);
33425
33426 do {
33427- if (likely(!atomic_read(&m->error_count)))
33428+ if (likely(!atomic_read_unchecked(&m->error_count)))
33429 return m;
33430
33431 if (m-- == ms->mirror)
33432@@ -422,7 +422,7 @@ static int default_ok(struct mirror *m)
33433 {
33434 struct mirror *default_mirror = get_default_mirror(m->ms);
33435
33436- return !atomic_read(&default_mirror->error_count);
33437+ return !atomic_read_unchecked(&default_mirror->error_count);
33438 }
33439
33440 static int mirror_available(struct mirror_set *ms, struct bio *bio)
33441@@ -559,7 +559,7 @@ static void do_reads(struct mirror_set *ms, struct bio_list *reads)
33442 */
33443 if (likely(region_in_sync(ms, region, 1)))
33444 m = choose_mirror(ms, bio->bi_sector);
33445- else if (m && atomic_read(&m->error_count))
33446+ else if (m && atomic_read_unchecked(&m->error_count))
33447 m = NULL;
33448
33449 if (likely(m))
33450@@ -938,7 +938,7 @@ static int get_mirror(struct mirror_set *ms, struct dm_target *ti,
33451 }
33452
33453 ms->mirror[mirror].ms = ms;
33454- atomic_set(&(ms->mirror[mirror].error_count), 0);
33455+ atomic_set_unchecked(&(ms->mirror[mirror].error_count), 0);
33456 ms->mirror[mirror].error_type = 0;
33457 ms->mirror[mirror].offset = offset;
33458
33459@@ -1356,7 +1356,7 @@ static void mirror_resume(struct dm_target *ti)
33460 */
33461 static char device_status_char(struct mirror *m)
33462 {
33463- if (!atomic_read(&(m->error_count)))
33464+ if (!atomic_read_unchecked(&(m->error_count)))
33465 return 'A';
33466
33467 return (test_bit(DM_RAID1_FLUSH_ERROR, &(m->error_type))) ? 'F' :
33468diff --git a/drivers/md/dm-stripe.c b/drivers/md/dm-stripe.c
33469index a087bf2..4c94786 100644
33470--- a/drivers/md/dm-stripe.c
33471+++ b/drivers/md/dm-stripe.c
33472@@ -20,7 +20,7 @@ struct stripe {
33473 struct dm_dev *dev;
33474 sector_t physical_start;
33475
33476- atomic_t error_count;
33477+ atomic_unchecked_t error_count;
33478 };
33479
33480 struct stripe_c {
33481@@ -183,7 +183,7 @@ static int stripe_ctr(struct dm_target *ti, unsigned int argc, char **argv)
33482 kfree(sc);
33483 return r;
33484 }
33485- atomic_set(&(sc->stripe[i].error_count), 0);
33486+ atomic_set_unchecked(&(sc->stripe[i].error_count), 0);
33487 }
33488
33489 ti->private = sc;
33490@@ -324,7 +324,7 @@ static int stripe_status(struct dm_target *ti, status_type_t type,
33491 DMEMIT("%d ", sc->stripes);
33492 for (i = 0; i < sc->stripes; i++) {
33493 DMEMIT("%s ", sc->stripe[i].dev->name);
33494- buffer[i] = atomic_read(&(sc->stripe[i].error_count)) ?
33495+ buffer[i] = atomic_read_unchecked(&(sc->stripe[i].error_count)) ?
33496 'D' : 'A';
33497 }
33498 buffer[i] = '\0';
33499@@ -371,8 +371,8 @@ static int stripe_end_io(struct dm_target *ti, struct bio *bio,
33500 */
33501 for (i = 0; i < sc->stripes; i++)
33502 if (!strcmp(sc->stripe[i].dev->name, major_minor)) {
33503- atomic_inc(&(sc->stripe[i].error_count));
33504- if (atomic_read(&(sc->stripe[i].error_count)) <
33505+ atomic_inc_unchecked(&(sc->stripe[i].error_count));
33506+ if (atomic_read_unchecked(&(sc->stripe[i].error_count)) <
33507 DM_IO_ERROR_THRESHOLD)
33508 schedule_work(&sc->trigger_event);
33509 }
33510diff --git a/drivers/md/dm-table.c b/drivers/md/dm-table.c
33511index 100368e..64262ce 100644
33512--- a/drivers/md/dm-table.c
33513+++ b/drivers/md/dm-table.c
33514@@ -390,7 +390,7 @@ static int device_area_is_invalid(struct dm_target *ti, struct dm_dev *dev,
33515 if (!dev_size)
33516 return 0;
33517
33518- if ((start >= dev_size) || (start + len > dev_size)) {
33519+ if ((start >= dev_size) || (len > dev_size - start)) {
33520 DMWARN("%s: %s too small for target: "
33521 "start=%llu, len=%llu, dev_size=%llu",
33522 dm_device_name(ti->table->md), bdevname(bdev, b),
33523diff --git a/drivers/md/dm-thin-metadata.c b/drivers/md/dm-thin-metadata.c
33524index 693e149..b7e0fde 100644
33525--- a/drivers/md/dm-thin-metadata.c
33526+++ b/drivers/md/dm-thin-metadata.c
33527@@ -397,7 +397,7 @@ static void __setup_btree_details(struct dm_pool_metadata *pmd)
33528 {
33529 pmd->info.tm = pmd->tm;
33530 pmd->info.levels = 2;
33531- pmd->info.value_type.context = pmd->data_sm;
33532+ pmd->info.value_type.context = (dm_space_map_no_const *)pmd->data_sm;
33533 pmd->info.value_type.size = sizeof(__le64);
33534 pmd->info.value_type.inc = data_block_inc;
33535 pmd->info.value_type.dec = data_block_dec;
33536@@ -416,7 +416,7 @@ static void __setup_btree_details(struct dm_pool_metadata *pmd)
33537
33538 pmd->bl_info.tm = pmd->tm;
33539 pmd->bl_info.levels = 1;
33540- pmd->bl_info.value_type.context = pmd->data_sm;
33541+ pmd->bl_info.value_type.context = (dm_space_map_no_const *)pmd->data_sm;
33542 pmd->bl_info.value_type.size = sizeof(__le64);
33543 pmd->bl_info.value_type.inc = data_block_inc;
33544 pmd->bl_info.value_type.dec = data_block_dec;
33545diff --git a/drivers/md/dm.c b/drivers/md/dm.c
33546index 67ffa39..cb3b1dd 100644
33547--- a/drivers/md/dm.c
33548+++ b/drivers/md/dm.c
33549@@ -176,9 +176,9 @@ struct mapped_device {
33550 /*
33551 * Event handling.
33552 */
33553- atomic_t event_nr;
33554+ atomic_unchecked_t event_nr;
33555 wait_queue_head_t eventq;
33556- atomic_t uevent_seq;
33557+ atomic_unchecked_t uevent_seq;
33558 struct list_head uevent_list;
33559 spinlock_t uevent_lock; /* Protect access to uevent_list */
33560
33561@@ -1887,8 +1887,8 @@ static struct mapped_device *alloc_dev(int minor)
33562 rwlock_init(&md->map_lock);
33563 atomic_set(&md->holders, 1);
33564 atomic_set(&md->open_count, 0);
33565- atomic_set(&md->event_nr, 0);
33566- atomic_set(&md->uevent_seq, 0);
33567+ atomic_set_unchecked(&md->event_nr, 0);
33568+ atomic_set_unchecked(&md->uevent_seq, 0);
33569 INIT_LIST_HEAD(&md->uevent_list);
33570 spin_lock_init(&md->uevent_lock);
33571
33572@@ -2022,7 +2022,7 @@ static void event_callback(void *context)
33573
33574 dm_send_uevents(&uevents, &disk_to_dev(md->disk)->kobj);
33575
33576- atomic_inc(&md->event_nr);
33577+ atomic_inc_unchecked(&md->event_nr);
33578 wake_up(&md->eventq);
33579 }
33580
33581@@ -2677,18 +2677,18 @@ int dm_kobject_uevent(struct mapped_device *md, enum kobject_action action,
33582
33583 uint32_t dm_next_uevent_seq(struct mapped_device *md)
33584 {
33585- return atomic_add_return(1, &md->uevent_seq);
33586+ return atomic_add_return_unchecked(1, &md->uevent_seq);
33587 }
33588
33589 uint32_t dm_get_event_nr(struct mapped_device *md)
33590 {
33591- return atomic_read(&md->event_nr);
33592+ return atomic_read_unchecked(&md->event_nr);
33593 }
33594
33595 int dm_wait_event(struct mapped_device *md, int event_nr)
33596 {
33597 return wait_event_interruptible(md->eventq,
33598- (event_nr != atomic_read(&md->event_nr)));
33599+ (event_nr != atomic_read_unchecked(&md->event_nr)));
33600 }
33601
33602 void dm_uevent_add(struct mapped_device *md, struct list_head *elist)
33603diff --git a/drivers/md/md.c b/drivers/md/md.c
33604index 308e87b..7f365d6 100644
33605--- a/drivers/md/md.c
33606+++ b/drivers/md/md.c
33607@@ -277,10 +277,10 @@ EXPORT_SYMBOL_GPL(md_trim_bio);
33608 * start build, activate spare
33609 */
33610 static DECLARE_WAIT_QUEUE_HEAD(md_event_waiters);
33611-static atomic_t md_event_count;
33612+static atomic_unchecked_t md_event_count;
33613 void md_new_event(struct mddev *mddev)
33614 {
33615- atomic_inc(&md_event_count);
33616+ atomic_inc_unchecked(&md_event_count);
33617 wake_up(&md_event_waiters);
33618 }
33619 EXPORT_SYMBOL_GPL(md_new_event);
33620@@ -290,7 +290,7 @@ EXPORT_SYMBOL_GPL(md_new_event);
33621 */
33622 static void md_new_event_inintr(struct mddev *mddev)
33623 {
33624- atomic_inc(&md_event_count);
33625+ atomic_inc_unchecked(&md_event_count);
33626 wake_up(&md_event_waiters);
33627 }
33628
33629@@ -1519,7 +1519,7 @@ static int super_1_load(struct md_rdev *rdev, struct md_rdev *refdev, int minor_
33630 if ((le32_to_cpu(sb->feature_map) & MD_FEATURE_RESHAPE_ACTIVE) &&
33631 (le32_to_cpu(sb->feature_map) & MD_FEATURE_NEW_OFFSET))
33632 rdev->new_data_offset += (s32)le32_to_cpu(sb->new_offset);
33633- atomic_set(&rdev->corrected_errors, le32_to_cpu(sb->cnt_corrected_read));
33634+ atomic_set_unchecked(&rdev->corrected_errors, le32_to_cpu(sb->cnt_corrected_read));
33635
33636 rdev->sb_size = le32_to_cpu(sb->max_dev) * 2 + 256;
33637 bmask = queue_logical_block_size(rdev->bdev->bd_disk->queue)-1;
33638@@ -1763,7 +1763,7 @@ static void super_1_sync(struct mddev *mddev, struct md_rdev *rdev)
33639 else
33640 sb->resync_offset = cpu_to_le64(0);
33641
33642- sb->cnt_corrected_read = cpu_to_le32(atomic_read(&rdev->corrected_errors));
33643+ sb->cnt_corrected_read = cpu_to_le32(atomic_read_unchecked(&rdev->corrected_errors));
33644
33645 sb->raid_disks = cpu_to_le32(mddev->raid_disks);
33646 sb->size = cpu_to_le64(mddev->dev_sectors);
33647@@ -2757,7 +2757,7 @@ __ATTR(state, S_IRUGO|S_IWUSR, state_show, state_store);
33648 static ssize_t
33649 errors_show(struct md_rdev *rdev, char *page)
33650 {
33651- return sprintf(page, "%d\n", atomic_read(&rdev->corrected_errors));
33652+ return sprintf(page, "%d\n", atomic_read_unchecked(&rdev->corrected_errors));
33653 }
33654
33655 static ssize_t
33656@@ -2766,7 +2766,7 @@ errors_store(struct md_rdev *rdev, const char *buf, size_t len)
33657 char *e;
33658 unsigned long n = simple_strtoul(buf, &e, 10);
33659 if (*buf && (*e == 0 || *e == '\n')) {
33660- atomic_set(&rdev->corrected_errors, n);
33661+ atomic_set_unchecked(&rdev->corrected_errors, n);
33662 return len;
33663 }
33664 return -EINVAL;
33665@@ -3213,8 +3213,8 @@ int md_rdev_init(struct md_rdev *rdev)
33666 rdev->sb_loaded = 0;
33667 rdev->bb_page = NULL;
33668 atomic_set(&rdev->nr_pending, 0);
33669- atomic_set(&rdev->read_errors, 0);
33670- atomic_set(&rdev->corrected_errors, 0);
33671+ atomic_set_unchecked(&rdev->read_errors, 0);
33672+ atomic_set_unchecked(&rdev->corrected_errors, 0);
33673
33674 INIT_LIST_HEAD(&rdev->same_set);
33675 init_waitqueue_head(&rdev->blocked_wait);
33676@@ -6947,7 +6947,7 @@ static int md_seq_show(struct seq_file *seq, void *v)
33677
33678 spin_unlock(&pers_lock);
33679 seq_printf(seq, "\n");
33680- seq->poll_event = atomic_read(&md_event_count);
33681+ seq->poll_event = atomic_read_unchecked(&md_event_count);
33682 return 0;
33683 }
33684 if (v == (void*)2) {
33685@@ -7050,7 +7050,7 @@ static int md_seq_open(struct inode *inode, struct file *file)
33686 return error;
33687
33688 seq = file->private_data;
33689- seq->poll_event = atomic_read(&md_event_count);
33690+ seq->poll_event = atomic_read_unchecked(&md_event_count);
33691 return error;
33692 }
33693
33694@@ -7064,7 +7064,7 @@ static unsigned int mdstat_poll(struct file *filp, poll_table *wait)
33695 /* always allow read */
33696 mask = POLLIN | POLLRDNORM;
33697
33698- if (seq->poll_event != atomic_read(&md_event_count))
33699+ if (seq->poll_event != atomic_read_unchecked(&md_event_count))
33700 mask |= POLLERR | POLLPRI;
33701 return mask;
33702 }
33703@@ -7108,7 +7108,7 @@ static int is_mddev_idle(struct mddev *mddev, int init)
33704 struct gendisk *disk = rdev->bdev->bd_contains->bd_disk;
33705 curr_events = (int)part_stat_read(&disk->part0, sectors[0]) +
33706 (int)part_stat_read(&disk->part0, sectors[1]) -
33707- atomic_read(&disk->sync_io);
33708+ atomic_read_unchecked(&disk->sync_io);
33709 /* sync IO will cause sync_io to increase before the disk_stats
33710 * as sync_io is counted when a request starts, and
33711 * disk_stats is counted when it completes.
33712diff --git a/drivers/md/md.h b/drivers/md/md.h
33713index f385b03..b600be8 100644
33714--- a/drivers/md/md.h
33715+++ b/drivers/md/md.h
33716@@ -94,13 +94,13 @@ struct md_rdev {
33717 * only maintained for arrays that
33718 * support hot removal
33719 */
33720- atomic_t read_errors; /* number of consecutive read errors that
33721+ atomic_unchecked_t read_errors; /* number of consecutive read errors that
33722 * we have tried to ignore.
33723 */
33724 struct timespec last_read_error; /* monotonic time since our
33725 * last read error
33726 */
33727- atomic_t corrected_errors; /* number of corrected read errors,
33728+ atomic_unchecked_t corrected_errors; /* number of corrected read errors,
33729 * for reporting to userspace and storing
33730 * in superblock.
33731 */
33732@@ -432,7 +432,7 @@ static inline void rdev_dec_pending(struct md_rdev *rdev, struct mddev *mddev)
33733
33734 static inline void md_sync_acct(struct block_device *bdev, unsigned long nr_sectors)
33735 {
33736- atomic_add(nr_sectors, &bdev->bd_contains->bd_disk->sync_io);
33737+ atomic_add_unchecked(nr_sectors, &bdev->bd_contains->bd_disk->sync_io);
33738 }
33739
33740 struct md_personality
33741diff --git a/drivers/md/persistent-data/dm-space-map-disk.c b/drivers/md/persistent-data/dm-space-map-disk.c
33742index f6d29e6..7917f5e 100644
33743--- a/drivers/md/persistent-data/dm-space-map-disk.c
33744+++ b/drivers/md/persistent-data/dm-space-map-disk.c
33745@@ -22,7 +22,7 @@
33746 * Space map interface.
33747 */
33748 struct sm_disk {
33749- struct dm_space_map sm;
33750+ dm_space_map_no_const sm;
33751
33752 struct ll_disk ll;
33753 struct ll_disk old_ll;
33754diff --git a/drivers/md/persistent-data/dm-space-map-metadata.c b/drivers/md/persistent-data/dm-space-map-metadata.c
33755index e89ae5e..062e4c2 100644
33756--- a/drivers/md/persistent-data/dm-space-map-metadata.c
33757+++ b/drivers/md/persistent-data/dm-space-map-metadata.c
33758@@ -43,7 +43,7 @@ struct block_op {
33759 };
33760
33761 struct sm_metadata {
33762- struct dm_space_map sm;
33763+ dm_space_map_no_const sm;
33764
33765 struct ll_disk ll;
33766 struct ll_disk old_ll;
33767diff --git a/drivers/md/persistent-data/dm-space-map.h b/drivers/md/persistent-data/dm-space-map.h
33768index 1cbfc6b..56e1dbb 100644
33769--- a/drivers/md/persistent-data/dm-space-map.h
33770+++ b/drivers/md/persistent-data/dm-space-map.h
33771@@ -60,6 +60,7 @@ struct dm_space_map {
33772 int (*root_size)(struct dm_space_map *sm, size_t *result);
33773 int (*copy_root)(struct dm_space_map *sm, void *copy_to_here_le, size_t len);
33774 };
33775+typedef struct dm_space_map __no_const dm_space_map_no_const;
33776
33777 /*----------------------------------------------------------------*/
33778
33779diff --git a/drivers/md/raid1.c b/drivers/md/raid1.c
33780index 611b5f7..cee0bfb 100644
33781--- a/drivers/md/raid1.c
33782+++ b/drivers/md/raid1.c
33783@@ -1810,7 +1810,7 @@ static int fix_sync_read_error(struct r1bio *r1_bio)
33784 if (r1_sync_page_io(rdev, sect, s,
33785 bio->bi_io_vec[idx].bv_page,
33786 READ) != 0)
33787- atomic_add(s, &rdev->corrected_errors);
33788+ atomic_add_unchecked(s, &rdev->corrected_errors);
33789 }
33790 sectors -= s;
33791 sect += s;
33792@@ -2032,7 +2032,7 @@ static void fix_read_error(struct r1conf *conf, int read_disk,
33793 test_bit(In_sync, &rdev->flags)) {
33794 if (r1_sync_page_io(rdev, sect, s,
33795 conf->tmppage, READ)) {
33796- atomic_add(s, &rdev->corrected_errors);
33797+ atomic_add_unchecked(s, &rdev->corrected_errors);
33798 printk(KERN_INFO
33799 "md/raid1:%s: read error corrected "
33800 "(%d sectors at %llu on %s)\n",
33801diff --git a/drivers/md/raid10.c b/drivers/md/raid10.c
33802index a48c215..6bda6f4 100644
33803--- a/drivers/md/raid10.c
33804+++ b/drivers/md/raid10.c
33805@@ -1810,7 +1810,7 @@ static void end_sync_read(struct bio *bio, int error)
33806 /* The write handler will notice the lack of
33807 * R10BIO_Uptodate and record any errors etc
33808 */
33809- atomic_add(r10_bio->sectors,
33810+ atomic_add_unchecked(r10_bio->sectors,
33811 &conf->mirrors[d].rdev->corrected_errors);
33812
33813 /* for reconstruct, we always reschedule after a read.
33814@@ -2159,7 +2159,7 @@ static void check_decay_read_errors(struct mddev *mddev, struct md_rdev *rdev)
33815 {
33816 struct timespec cur_time_mon;
33817 unsigned long hours_since_last;
33818- unsigned int read_errors = atomic_read(&rdev->read_errors);
33819+ unsigned int read_errors = atomic_read_unchecked(&rdev->read_errors);
33820
33821 ktime_get_ts(&cur_time_mon);
33822
33823@@ -2181,9 +2181,9 @@ static void check_decay_read_errors(struct mddev *mddev, struct md_rdev *rdev)
33824 * overflowing the shift of read_errors by hours_since_last.
33825 */
33826 if (hours_since_last >= 8 * sizeof(read_errors))
33827- atomic_set(&rdev->read_errors, 0);
33828+ atomic_set_unchecked(&rdev->read_errors, 0);
33829 else
33830- atomic_set(&rdev->read_errors, read_errors >> hours_since_last);
33831+ atomic_set_unchecked(&rdev->read_errors, read_errors >> hours_since_last);
33832 }
33833
33834 static int r10_sync_page_io(struct md_rdev *rdev, sector_t sector,
33835@@ -2237,8 +2237,8 @@ static void fix_read_error(struct r10conf *conf, struct mddev *mddev, struct r10
33836 return;
33837
33838 check_decay_read_errors(mddev, rdev);
33839- atomic_inc(&rdev->read_errors);
33840- if (atomic_read(&rdev->read_errors) > max_read_errors) {
33841+ atomic_inc_unchecked(&rdev->read_errors);
33842+ if (atomic_read_unchecked(&rdev->read_errors) > max_read_errors) {
33843 char b[BDEVNAME_SIZE];
33844 bdevname(rdev->bdev, b);
33845
33846@@ -2246,7 +2246,7 @@ static void fix_read_error(struct r10conf *conf, struct mddev *mddev, struct r10
33847 "md/raid10:%s: %s: Raid device exceeded "
33848 "read_error threshold [cur %d:max %d]\n",
33849 mdname(mddev), b,
33850- atomic_read(&rdev->read_errors), max_read_errors);
33851+ atomic_read_unchecked(&rdev->read_errors), max_read_errors);
33852 printk(KERN_NOTICE
33853 "md/raid10:%s: %s: Failing raid device\n",
33854 mdname(mddev), b);
33855@@ -2401,7 +2401,7 @@ static void fix_read_error(struct r10conf *conf, struct mddev *mddev, struct r10
33856 sect +
33857 choose_data_offset(r10_bio, rdev)),
33858 bdevname(rdev->bdev, b));
33859- atomic_add(s, &rdev->corrected_errors);
33860+ atomic_add_unchecked(s, &rdev->corrected_errors);
33861 }
33862
33863 rdev_dec_pending(rdev, mddev);
33864diff --git a/drivers/md/raid5.c b/drivers/md/raid5.c
33865index 0689173..35df76c 100644
33866--- a/drivers/md/raid5.c
33867+++ b/drivers/md/raid5.c
33868@@ -1756,21 +1756,21 @@ static void raid5_end_read_request(struct bio * bi, int error)
33869 mdname(conf->mddev), STRIPE_SECTORS,
33870 (unsigned long long)s,
33871 bdevname(rdev->bdev, b));
33872- atomic_add(STRIPE_SECTORS, &rdev->corrected_errors);
33873+ atomic_add_unchecked(STRIPE_SECTORS, &rdev->corrected_errors);
33874 clear_bit(R5_ReadError, &sh->dev[i].flags);
33875 clear_bit(R5_ReWrite, &sh->dev[i].flags);
33876 } else if (test_bit(R5_ReadNoMerge, &sh->dev[i].flags))
33877 clear_bit(R5_ReadNoMerge, &sh->dev[i].flags);
33878
33879- if (atomic_read(&rdev->read_errors))
33880- atomic_set(&rdev->read_errors, 0);
33881+ if (atomic_read_unchecked(&rdev->read_errors))
33882+ atomic_set_unchecked(&rdev->read_errors, 0);
33883 } else {
33884 const char *bdn = bdevname(rdev->bdev, b);
33885 int retry = 0;
33886 int set_bad = 0;
33887
33888 clear_bit(R5_UPTODATE, &sh->dev[i].flags);
33889- atomic_inc(&rdev->read_errors);
33890+ atomic_inc_unchecked(&rdev->read_errors);
33891 if (test_bit(R5_ReadRepl, &sh->dev[i].flags))
33892 printk_ratelimited(
33893 KERN_WARNING
33894@@ -1798,7 +1798,7 @@ static void raid5_end_read_request(struct bio * bi, int error)
33895 mdname(conf->mddev),
33896 (unsigned long long)s,
33897 bdn);
33898- } else if (atomic_read(&rdev->read_errors)
33899+ } else if (atomic_read_unchecked(&rdev->read_errors)
33900 > conf->max_nr_stripes)
33901 printk(KERN_WARNING
33902 "md/raid:%s: Too many read errors, failing device %s.\n",
33903diff --git a/drivers/media/dvb/ddbridge/ddbridge-core.c b/drivers/media/dvb/ddbridge/ddbridge-core.c
33904index ebf3f05..b1f3e77 100644
33905--- a/drivers/media/dvb/ddbridge/ddbridge-core.c
33906+++ b/drivers/media/dvb/ddbridge/ddbridge-core.c
33907@@ -1679,7 +1679,7 @@ static struct ddb_info ddb_v6 = {
33908 .subvendor = _subvend, .subdevice = _subdev, \
33909 .driver_data = (unsigned long)&_driverdata }
33910
33911-static const struct pci_device_id ddb_id_tbl[] __devinitdata = {
33912+static const struct pci_device_id ddb_id_tbl[] __devinitconst = {
33913 DDB_ID(DDVID, 0x0002, DDVID, 0x0001, ddb_octopus),
33914 DDB_ID(DDVID, 0x0003, DDVID, 0x0001, ddb_octopus),
33915 DDB_ID(DDVID, 0x0003, DDVID, 0x0002, ddb_octopus_le),
33916diff --git a/drivers/media/dvb/dvb-core/dvb_demux.h b/drivers/media/dvb/dvb-core/dvb_demux.h
33917index fa7188a..04a045e 100644
33918--- a/drivers/media/dvb/dvb-core/dvb_demux.h
33919+++ b/drivers/media/dvb/dvb-core/dvb_demux.h
33920@@ -73,7 +73,7 @@ struct dvb_demux_feed {
33921 union {
33922 dmx_ts_cb ts;
33923 dmx_section_cb sec;
33924- } cb;
33925+ } __no_const cb;
33926
33927 struct dvb_demux *demux;
33928 void *priv;
33929diff --git a/drivers/media/dvb/dvb-core/dvbdev.c b/drivers/media/dvb/dvb-core/dvbdev.c
33930index 39eab73..60033e7 100644
33931--- a/drivers/media/dvb/dvb-core/dvbdev.c
33932+++ b/drivers/media/dvb/dvb-core/dvbdev.c
33933@@ -192,7 +192,7 @@ int dvb_register_device(struct dvb_adapter *adap, struct dvb_device **pdvbdev,
33934 const struct dvb_device *template, void *priv, int type)
33935 {
33936 struct dvb_device *dvbdev;
33937- struct file_operations *dvbdevfops;
33938+ file_operations_no_const *dvbdevfops;
33939 struct device *clsdev;
33940 int minor;
33941 int id;
33942diff --git a/drivers/media/dvb/dvb-usb/cxusb.c b/drivers/media/dvb/dvb-usb/cxusb.c
33943index 3940bb0..fb3952a 100644
33944--- a/drivers/media/dvb/dvb-usb/cxusb.c
33945+++ b/drivers/media/dvb/dvb-usb/cxusb.c
33946@@ -1068,7 +1068,7 @@ static struct dib0070_config dib7070p_dib0070_config = {
33947
33948 struct dib0700_adapter_state {
33949 int (*set_param_save) (struct dvb_frontend *);
33950-};
33951+} __no_const;
33952
33953 static int dib7070_set_param_override(struct dvb_frontend *fe)
33954 {
33955diff --git a/drivers/media/dvb/dvb-usb/dw2102.c b/drivers/media/dvb/dvb-usb/dw2102.c
33956index 9382895..ac8093c 100644
33957--- a/drivers/media/dvb/dvb-usb/dw2102.c
33958+++ b/drivers/media/dvb/dvb-usb/dw2102.c
33959@@ -95,7 +95,7 @@ struct su3000_state {
33960
33961 struct s6x0_state {
33962 int (*old_set_voltage)(struct dvb_frontend *f, fe_sec_voltage_t v);
33963-};
33964+} __no_const;
33965
33966 /* debug */
33967 static int dvb_usb_dw2102_debug;
33968diff --git a/drivers/media/dvb/frontends/dib3000.h b/drivers/media/dvb/frontends/dib3000.h
33969index 404f63a..4796533 100644
33970--- a/drivers/media/dvb/frontends/dib3000.h
33971+++ b/drivers/media/dvb/frontends/dib3000.h
33972@@ -39,7 +39,7 @@ struct dib_fe_xfer_ops
33973 int (*fifo_ctrl)(struct dvb_frontend *fe, int onoff);
33974 int (*pid_ctrl)(struct dvb_frontend *fe, int index, int pid, int onoff);
33975 int (*tuner_pass_ctrl)(struct dvb_frontend *fe, int onoff, u8 pll_ctrl);
33976-};
33977+} __no_const;
33978
33979 #if defined(CONFIG_DVB_DIB3000MB) || (defined(CONFIG_DVB_DIB3000MB_MODULE) && defined(MODULE))
33980 extern struct dvb_frontend* dib3000mb_attach(const struct dib3000_config* config,
33981diff --git a/drivers/media/dvb/ngene/ngene-cards.c b/drivers/media/dvb/ngene/ngene-cards.c
33982index 72ee8de..eae0c80 100644
33983--- a/drivers/media/dvb/ngene/ngene-cards.c
33984+++ b/drivers/media/dvb/ngene/ngene-cards.c
33985@@ -479,7 +479,7 @@ static struct ngene_info ngene_info_m780 = {
33986
33987 /****************************************************************************/
33988
33989-static const struct pci_device_id ngene_id_tbl[] __devinitdata = {
33990+static const struct pci_device_id ngene_id_tbl[] __devinitconst = {
33991 NGENE_ID(0x18c3, 0xabc3, ngene_info_cineS2),
33992 NGENE_ID(0x18c3, 0xabc4, ngene_info_cineS2),
33993 NGENE_ID(0x18c3, 0xdb01, ngene_info_satixS2),
33994diff --git a/drivers/media/radio/radio-cadet.c b/drivers/media/radio/radio-cadet.c
33995index 697a421..16c5a5f 100644
33996--- a/drivers/media/radio/radio-cadet.c
33997+++ b/drivers/media/radio/radio-cadet.c
33998@@ -302,6 +302,8 @@ static ssize_t cadet_read(struct file *file, char __user *data, size_t count, lo
33999 unsigned char readbuf[RDS_BUFFER];
34000 int i = 0;
34001
34002+ if (count > RDS_BUFFER)
34003+ return -EFAULT;
34004 mutex_lock(&dev->lock);
34005 if (dev->rdsstat == 0)
34006 cadet_start_rds(dev);
34007@@ -317,7 +319,7 @@ static ssize_t cadet_read(struct file *file, char __user *data, size_t count, lo
34008 while (i < count && dev->rdsin != dev->rdsout)
34009 readbuf[i++] = dev->rdsbuf[dev->rdsout++];
34010
34011- if (i && copy_to_user(data, readbuf, i))
34012+ if (i > sizeof(readbuf) || copy_to_user(data, readbuf, i))
34013 i = -EFAULT;
34014 unlock:
34015 mutex_unlock(&dev->lock);
34016diff --git a/drivers/media/radio/radio-tea5777.h b/drivers/media/radio/radio-tea5777.h
34017index 55cbd78..428b0da 100644
34018--- a/drivers/media/radio/radio-tea5777.h
34019+++ b/drivers/media/radio/radio-tea5777.h
34020@@ -63,7 +63,7 @@ struct radio_tea5777_ops {
34021
34022 struct radio_tea5777 {
34023 struct v4l2_device *v4l2_dev;
34024- struct v4l2_file_operations fops;
34025+ v4l2_file_operations_no_const fops;
34026 struct video_device vd; /* video device */
34027 bool has_am; /* Device can tune to AM freqs */
34028 bool write_before_read; /* must write before read quirk */
34029diff --git a/drivers/media/video/au0828/au0828.h b/drivers/media/video/au0828/au0828.h
34030index 9cde353..8c6a1c3 100644
34031--- a/drivers/media/video/au0828/au0828.h
34032+++ b/drivers/media/video/au0828/au0828.h
34033@@ -191,7 +191,7 @@ struct au0828_dev {
34034
34035 /* I2C */
34036 struct i2c_adapter i2c_adap;
34037- struct i2c_algorithm i2c_algo;
34038+ i2c_algorithm_no_const i2c_algo;
34039 struct i2c_client i2c_client;
34040 u32 i2c_rc;
34041
34042diff --git a/drivers/media/video/cx88/cx88-alsa.c b/drivers/media/video/cx88/cx88-alsa.c
34043index dfac6e3..c26de31 100644
34044--- a/drivers/media/video/cx88/cx88-alsa.c
34045+++ b/drivers/media/video/cx88/cx88-alsa.c
34046@@ -749,7 +749,7 @@ static struct snd_kcontrol_new snd_cx88_alc_switch = {
34047 * Only boards with eeprom and byte 1 at eeprom=1 have it
34048 */
34049
34050-static const struct pci_device_id const cx88_audio_pci_tbl[] __devinitdata = {
34051+static const struct pci_device_id const cx88_audio_pci_tbl[] __devinitconst = {
34052 {0x14f1,0x8801,PCI_ANY_ID,PCI_ANY_ID,0,0,0},
34053 {0x14f1,0x8811,PCI_ANY_ID,PCI_ANY_ID,0,0,0},
34054 {0, }
34055diff --git a/drivers/media/video/omap/omap_vout.c b/drivers/media/video/omap/omap_vout.c
34056index 88cf9d9..bbc4b2c 100644
34057--- a/drivers/media/video/omap/omap_vout.c
34058+++ b/drivers/media/video/omap/omap_vout.c
34059@@ -64,7 +64,6 @@ enum omap_vout_channels {
34060 OMAP_VIDEO2,
34061 };
34062
34063-static struct videobuf_queue_ops video_vbq_ops;
34064 /* Variables configurable through module params*/
34065 static u32 video1_numbuffers = 3;
34066 static u32 video2_numbuffers = 3;
34067@@ -1000,6 +999,12 @@ static int omap_vout_open(struct file *file)
34068 {
34069 struct videobuf_queue *q;
34070 struct omap_vout_device *vout = NULL;
34071+ static struct videobuf_queue_ops video_vbq_ops = {
34072+ .buf_setup = omap_vout_buffer_setup,
34073+ .buf_prepare = omap_vout_buffer_prepare,
34074+ .buf_release = omap_vout_buffer_release,
34075+ .buf_queue = omap_vout_buffer_queue,
34076+ };
34077
34078 vout = video_drvdata(file);
34079 v4l2_dbg(1, debug, &vout->vid_dev->v4l2_dev, "Entering %s\n", __func__);
34080@@ -1017,10 +1022,6 @@ static int omap_vout_open(struct file *file)
34081 vout->type = V4L2_BUF_TYPE_VIDEO_OUTPUT;
34082
34083 q = &vout->vbq;
34084- video_vbq_ops.buf_setup = omap_vout_buffer_setup;
34085- video_vbq_ops.buf_prepare = omap_vout_buffer_prepare;
34086- video_vbq_ops.buf_release = omap_vout_buffer_release;
34087- video_vbq_ops.buf_queue = omap_vout_buffer_queue;
34088 spin_lock_init(&vout->vbq_lock);
34089
34090 videobuf_queue_dma_contig_init(q, &video_vbq_ops, q->dev,
34091diff --git a/drivers/media/video/pvrusb2/pvrusb2-hdw-internal.h b/drivers/media/video/pvrusb2/pvrusb2-hdw-internal.h
34092index 036952f..80d356d 100644
34093--- a/drivers/media/video/pvrusb2/pvrusb2-hdw-internal.h
34094+++ b/drivers/media/video/pvrusb2/pvrusb2-hdw-internal.h
34095@@ -196,7 +196,7 @@ struct pvr2_hdw {
34096
34097 /* I2C stuff */
34098 struct i2c_adapter i2c_adap;
34099- struct i2c_algorithm i2c_algo;
34100+ i2c_algorithm_no_const i2c_algo;
34101 pvr2_i2c_func i2c_func[PVR2_I2C_FUNC_CNT];
34102 int i2c_cx25840_hack_state;
34103 int i2c_linked;
34104diff --git a/drivers/media/video/timblogiw.c b/drivers/media/video/timblogiw.c
34105index 02194c0..091733b 100644
34106--- a/drivers/media/video/timblogiw.c
34107+++ b/drivers/media/video/timblogiw.c
34108@@ -745,7 +745,7 @@ static int timblogiw_mmap(struct file *file, struct vm_area_struct *vma)
34109
34110 /* Platform device functions */
34111
34112-static __devinitconst struct v4l2_ioctl_ops timblogiw_ioctl_ops = {
34113+static __devinitconst v4l2_ioctl_ops_no_const timblogiw_ioctl_ops = {
34114 .vidioc_querycap = timblogiw_querycap,
34115 .vidioc_enum_fmt_vid_cap = timblogiw_enum_fmt,
34116 .vidioc_g_fmt_vid_cap = timblogiw_g_fmt,
34117@@ -767,7 +767,7 @@ static __devinitconst struct v4l2_ioctl_ops timblogiw_ioctl_ops = {
34118 .vidioc_enum_framesizes = timblogiw_enum_framesizes,
34119 };
34120
34121-static __devinitconst struct v4l2_file_operations timblogiw_fops = {
34122+static __devinitconst v4l2_file_operations_no_const timblogiw_fops = {
34123 .owner = THIS_MODULE,
34124 .open = timblogiw_open,
34125 .release = timblogiw_close,
34126diff --git a/drivers/message/fusion/mptbase.c b/drivers/message/fusion/mptbase.c
34127index d99db56..a16b959 100644
34128--- a/drivers/message/fusion/mptbase.c
34129+++ b/drivers/message/fusion/mptbase.c
34130@@ -6751,8 +6751,13 @@ static int mpt_iocinfo_proc_show(struct seq_file *m, void *v)
34131 seq_printf(m, " MaxChainDepth = 0x%02x frames\n", ioc->facts.MaxChainDepth);
34132 seq_printf(m, " MinBlockSize = 0x%02x bytes\n", 4*ioc->facts.BlockSize);
34133
34134+#ifdef CONFIG_GRKERNSEC_HIDESYM
34135+ seq_printf(m, " RequestFrames @ 0x%p (Dma @ 0x%p)\n", NULL, NULL);
34136+#else
34137 seq_printf(m, " RequestFrames @ 0x%p (Dma @ 0x%p)\n",
34138 (void *)ioc->req_frames, (void *)(ulong)ioc->req_frames_dma);
34139+#endif
34140+
34141 /*
34142 * Rounding UP to nearest 4-kB boundary here...
34143 */
34144diff --git a/drivers/message/fusion/mptsas.c b/drivers/message/fusion/mptsas.c
34145index 551262e..7551198 100644
34146--- a/drivers/message/fusion/mptsas.c
34147+++ b/drivers/message/fusion/mptsas.c
34148@@ -446,6 +446,23 @@ mptsas_is_end_device(struct mptsas_devinfo * attached)
34149 return 0;
34150 }
34151
34152+static inline void
34153+mptsas_set_rphy(MPT_ADAPTER *ioc, struct mptsas_phyinfo *phy_info, struct sas_rphy *rphy)
34154+{
34155+ if (phy_info->port_details) {
34156+ phy_info->port_details->rphy = rphy;
34157+ dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "sas_rphy_add: rphy=%p\n",
34158+ ioc->name, rphy));
34159+ }
34160+
34161+ if (rphy) {
34162+ dsaswideprintk(ioc, dev_printk(KERN_DEBUG,
34163+ &rphy->dev, MYIOC_s_FMT "add:", ioc->name));
34164+ dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "rphy=%p release=%p\n",
34165+ ioc->name, rphy, rphy->dev.release));
34166+ }
34167+}
34168+
34169 /* no mutex */
34170 static void
34171 mptsas_port_delete(MPT_ADAPTER *ioc, struct mptsas_portinfo_details * port_details)
34172@@ -484,23 +501,6 @@ mptsas_get_rphy(struct mptsas_phyinfo *phy_info)
34173 return NULL;
34174 }
34175
34176-static inline void
34177-mptsas_set_rphy(MPT_ADAPTER *ioc, struct mptsas_phyinfo *phy_info, struct sas_rphy *rphy)
34178-{
34179- if (phy_info->port_details) {
34180- phy_info->port_details->rphy = rphy;
34181- dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "sas_rphy_add: rphy=%p\n",
34182- ioc->name, rphy));
34183- }
34184-
34185- if (rphy) {
34186- dsaswideprintk(ioc, dev_printk(KERN_DEBUG,
34187- &rphy->dev, MYIOC_s_FMT "add:", ioc->name));
34188- dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "rphy=%p release=%p\n",
34189- ioc->name, rphy, rphy->dev.release));
34190- }
34191-}
34192-
34193 static inline struct sas_port *
34194 mptsas_get_port(struct mptsas_phyinfo *phy_info)
34195 {
34196diff --git a/drivers/message/fusion/mptscsih.c b/drivers/message/fusion/mptscsih.c
34197index 0c3ced7..1fe34ec 100644
34198--- a/drivers/message/fusion/mptscsih.c
34199+++ b/drivers/message/fusion/mptscsih.c
34200@@ -1270,15 +1270,16 @@ mptscsih_info(struct Scsi_Host *SChost)
34201
34202 h = shost_priv(SChost);
34203
34204- if (h) {
34205- if (h->info_kbuf == NULL)
34206- if ((h->info_kbuf = kmalloc(0x1000 /* 4Kb */, GFP_KERNEL)) == NULL)
34207- return h->info_kbuf;
34208- h->info_kbuf[0] = '\0';
34209+ if (!h)
34210+ return NULL;
34211
34212- mpt_print_ioc_summary(h->ioc, h->info_kbuf, &size, 0, 0);
34213- h->info_kbuf[size-1] = '\0';
34214- }
34215+ if (h->info_kbuf == NULL)
34216+ if ((h->info_kbuf = kmalloc(0x1000 /* 4Kb */, GFP_KERNEL)) == NULL)
34217+ return h->info_kbuf;
34218+ h->info_kbuf[0] = '\0';
34219+
34220+ mpt_print_ioc_summary(h->ioc, h->info_kbuf, &size, 0, 0);
34221+ h->info_kbuf[size-1] = '\0';
34222
34223 return h->info_kbuf;
34224 }
34225diff --git a/drivers/message/i2o/i2o_proc.c b/drivers/message/i2o/i2o_proc.c
34226index 8001aa6..b137580 100644
34227--- a/drivers/message/i2o/i2o_proc.c
34228+++ b/drivers/message/i2o/i2o_proc.c
34229@@ -255,12 +255,6 @@ static char *scsi_devices[] = {
34230 "Array Controller Device"
34231 };
34232
34233-static char *chtostr(char *tmp, u8 *chars, int n)
34234-{
34235- tmp[0] = 0;
34236- return strncat(tmp, (char *)chars, n);
34237-}
34238-
34239 static int i2o_report_query_status(struct seq_file *seq, int block_status,
34240 char *group)
34241 {
34242@@ -790,7 +784,6 @@ static int i2o_seq_show_ddm_table(struct seq_file *seq, void *v)
34243 } *result;
34244
34245 i2o_exec_execute_ddm_table ddm_table;
34246- char tmp[28 + 1];
34247
34248 result = kmalloc(sizeof(*result), GFP_KERNEL);
34249 if (!result)
34250@@ -825,8 +818,7 @@ static int i2o_seq_show_ddm_table(struct seq_file *seq, void *v)
34251
34252 seq_printf(seq, "%-#7x", ddm_table.i2o_vendor_id);
34253 seq_printf(seq, "%-#8x", ddm_table.module_id);
34254- seq_printf(seq, "%-29s",
34255- chtostr(tmp, ddm_table.module_name_version, 28));
34256+ seq_printf(seq, "%-.28s", ddm_table.module_name_version);
34257 seq_printf(seq, "%9d ", ddm_table.data_size);
34258 seq_printf(seq, "%8d", ddm_table.code_size);
34259
34260@@ -893,7 +885,6 @@ static int i2o_seq_show_drivers_stored(struct seq_file *seq, void *v)
34261
34262 i2o_driver_result_table *result;
34263 i2o_driver_store_table *dst;
34264- char tmp[28 + 1];
34265
34266 result = kmalloc(sizeof(i2o_driver_result_table), GFP_KERNEL);
34267 if (result == NULL)
34268@@ -928,9 +919,8 @@ static int i2o_seq_show_drivers_stored(struct seq_file *seq, void *v)
34269
34270 seq_printf(seq, "%-#7x", dst->i2o_vendor_id);
34271 seq_printf(seq, "%-#8x", dst->module_id);
34272- seq_printf(seq, "%-29s",
34273- chtostr(tmp, dst->module_name_version, 28));
34274- seq_printf(seq, "%-9s", chtostr(tmp, dst->date, 8));
34275+ seq_printf(seq, "%-.28s", dst->module_name_version);
34276+ seq_printf(seq, "%-.8s", dst->date);
34277 seq_printf(seq, "%8d ", dst->module_size);
34278 seq_printf(seq, "%8d ", dst->mpb_size);
34279 seq_printf(seq, "0x%04x", dst->module_flags);
34280@@ -1250,7 +1240,6 @@ static int i2o_seq_show_dev_identity(struct seq_file *seq, void *v)
34281 // == (allow) 512d bytes (max)
34282 static u16 *work16 = (u16 *) work32;
34283 int token;
34284- char tmp[16 + 1];
34285
34286 token = i2o_parm_field_get(d, 0xF100, -1, &work32, sizeof(work32));
34287
34288@@ -1262,14 +1251,10 @@ static int i2o_seq_show_dev_identity(struct seq_file *seq, void *v)
34289 seq_printf(seq, "Device Class : %s\n", i2o_get_class_name(work16[0]));
34290 seq_printf(seq, "Owner TID : %0#5x\n", work16[2]);
34291 seq_printf(seq, "Parent TID : %0#5x\n", work16[3]);
34292- seq_printf(seq, "Vendor info : %s\n",
34293- chtostr(tmp, (u8 *) (work32 + 2), 16));
34294- seq_printf(seq, "Product info : %s\n",
34295- chtostr(tmp, (u8 *) (work32 + 6), 16));
34296- seq_printf(seq, "Description : %s\n",
34297- chtostr(tmp, (u8 *) (work32 + 10), 16));
34298- seq_printf(seq, "Product rev. : %s\n",
34299- chtostr(tmp, (u8 *) (work32 + 14), 8));
34300+ seq_printf(seq, "Vendor info : %.16s\n", (u8 *) (work32 + 2));
34301+ seq_printf(seq, "Product info : %.16s\n", (u8 *) (work32 + 6));
34302+ seq_printf(seq, "Description : %.16s\n", (u8 *) (work32 + 10));
34303+ seq_printf(seq, "Product rev. : %.8s\n", (u8 *) (work32 + 14));
34304
34305 seq_printf(seq, "Serial number : ");
34306 print_serial_number(seq, (u8 *) (work32 + 16),
34307@@ -1306,8 +1291,6 @@ static int i2o_seq_show_ddm_identity(struct seq_file *seq, void *v)
34308 u8 pad[256]; // allow up to 256 byte (max) serial number
34309 } result;
34310
34311- char tmp[24 + 1];
34312-
34313 token = i2o_parm_field_get(d, 0xF101, -1, &result, sizeof(result));
34314
34315 if (token < 0) {
34316@@ -1316,10 +1299,8 @@ static int i2o_seq_show_ddm_identity(struct seq_file *seq, void *v)
34317 }
34318
34319 seq_printf(seq, "Registering DDM TID : 0x%03x\n", result.ddm_tid);
34320- seq_printf(seq, "Module name : %s\n",
34321- chtostr(tmp, result.module_name, 24));
34322- seq_printf(seq, "Module revision : %s\n",
34323- chtostr(tmp, result.module_rev, 8));
34324+ seq_printf(seq, "Module name : %.24s\n", result.module_name);
34325+ seq_printf(seq, "Module revision : %.8s\n", result.module_rev);
34326
34327 seq_printf(seq, "Serial number : ");
34328 print_serial_number(seq, result.serial_number, sizeof(result) - 36);
34329@@ -1343,8 +1324,6 @@ static int i2o_seq_show_uinfo(struct seq_file *seq, void *v)
34330 u8 instance_number[4];
34331 } result;
34332
34333- char tmp[64 + 1];
34334-
34335 token = i2o_parm_field_get(d, 0xF102, -1, &result, sizeof(result));
34336
34337 if (token < 0) {
34338@@ -1352,14 +1331,10 @@ static int i2o_seq_show_uinfo(struct seq_file *seq, void *v)
34339 return 0;
34340 }
34341
34342- seq_printf(seq, "Device name : %s\n",
34343- chtostr(tmp, result.device_name, 64));
34344- seq_printf(seq, "Service name : %s\n",
34345- chtostr(tmp, result.service_name, 64));
34346- seq_printf(seq, "Physical name : %s\n",
34347- chtostr(tmp, result.physical_location, 64));
34348- seq_printf(seq, "Instance number : %s\n",
34349- chtostr(tmp, result.instance_number, 4));
34350+ seq_printf(seq, "Device name : %.64s\n", result.device_name);
34351+ seq_printf(seq, "Service name : %.64s\n", result.service_name);
34352+ seq_printf(seq, "Physical name : %.64s\n", result.physical_location);
34353+ seq_printf(seq, "Instance number : %.4s\n", result.instance_number);
34354
34355 return 0;
34356 }
34357diff --git a/drivers/message/i2o/iop.c b/drivers/message/i2o/iop.c
34358index a8c08f3..155fe3d 100644
34359--- a/drivers/message/i2o/iop.c
34360+++ b/drivers/message/i2o/iop.c
34361@@ -111,10 +111,10 @@ u32 i2o_cntxt_list_add(struct i2o_controller * c, void *ptr)
34362
34363 spin_lock_irqsave(&c->context_list_lock, flags);
34364
34365- if (unlikely(atomic_inc_and_test(&c->context_list_counter)))
34366- atomic_inc(&c->context_list_counter);
34367+ if (unlikely(atomic_inc_and_test_unchecked(&c->context_list_counter)))
34368+ atomic_inc_unchecked(&c->context_list_counter);
34369
34370- entry->context = atomic_read(&c->context_list_counter);
34371+ entry->context = atomic_read_unchecked(&c->context_list_counter);
34372
34373 list_add(&entry->list, &c->context_list);
34374
34375@@ -1077,7 +1077,7 @@ struct i2o_controller *i2o_iop_alloc(void)
34376
34377 #if BITS_PER_LONG == 64
34378 spin_lock_init(&c->context_list_lock);
34379- atomic_set(&c->context_list_counter, 0);
34380+ atomic_set_unchecked(&c->context_list_counter, 0);
34381 INIT_LIST_HEAD(&c->context_list);
34382 #endif
34383
34384diff --git a/drivers/mfd/abx500-core.c b/drivers/mfd/abx500-core.c
34385index 7ce65f4..e66e9bc 100644
34386--- a/drivers/mfd/abx500-core.c
34387+++ b/drivers/mfd/abx500-core.c
34388@@ -15,7 +15,7 @@ static LIST_HEAD(abx500_list);
34389
34390 struct abx500_device_entry {
34391 struct list_head list;
34392- struct abx500_ops ops;
34393+ abx500_ops_no_const ops;
34394 struct device *dev;
34395 };
34396
34397diff --git a/drivers/mfd/janz-cmodio.c b/drivers/mfd/janz-cmodio.c
34398index 965c480..71f2db9 100644
34399--- a/drivers/mfd/janz-cmodio.c
34400+++ b/drivers/mfd/janz-cmodio.c
34401@@ -13,6 +13,7 @@
34402
34403 #include <linux/kernel.h>
34404 #include <linux/module.h>
34405+#include <linux/slab.h>
34406 #include <linux/init.h>
34407 #include <linux/pci.h>
34408 #include <linux/interrupt.h>
34409diff --git a/drivers/misc/lis3lv02d/lis3lv02d.c b/drivers/misc/lis3lv02d/lis3lv02d.c
34410index a981e2a..5ca0c8b 100644
34411--- a/drivers/misc/lis3lv02d/lis3lv02d.c
34412+++ b/drivers/misc/lis3lv02d/lis3lv02d.c
34413@@ -466,7 +466,7 @@ static irqreturn_t lis302dl_interrupt(int irq, void *data)
34414 * the lid is closed. This leads to interrupts as soon as a little move
34415 * is done.
34416 */
34417- atomic_inc(&lis3->count);
34418+ atomic_inc_unchecked(&lis3->count);
34419
34420 wake_up_interruptible(&lis3->misc_wait);
34421 kill_fasync(&lis3->async_queue, SIGIO, POLL_IN);
34422@@ -552,7 +552,7 @@ static int lis3lv02d_misc_open(struct inode *inode, struct file *file)
34423 if (lis3->pm_dev)
34424 pm_runtime_get_sync(lis3->pm_dev);
34425
34426- atomic_set(&lis3->count, 0);
34427+ atomic_set_unchecked(&lis3->count, 0);
34428 return 0;
34429 }
34430
34431@@ -585,7 +585,7 @@ static ssize_t lis3lv02d_misc_read(struct file *file, char __user *buf,
34432 add_wait_queue(&lis3->misc_wait, &wait);
34433 while (true) {
34434 set_current_state(TASK_INTERRUPTIBLE);
34435- data = atomic_xchg(&lis3->count, 0);
34436+ data = atomic_xchg_unchecked(&lis3->count, 0);
34437 if (data)
34438 break;
34439
34440@@ -626,7 +626,7 @@ static unsigned int lis3lv02d_misc_poll(struct file *file, poll_table *wait)
34441 struct lis3lv02d, miscdev);
34442
34443 poll_wait(file, &lis3->misc_wait, wait);
34444- if (atomic_read(&lis3->count))
34445+ if (atomic_read_unchecked(&lis3->count))
34446 return POLLIN | POLLRDNORM;
34447 return 0;
34448 }
34449diff --git a/drivers/misc/lis3lv02d/lis3lv02d.h b/drivers/misc/lis3lv02d/lis3lv02d.h
34450index 2b1482a..5d33616 100644
34451--- a/drivers/misc/lis3lv02d/lis3lv02d.h
34452+++ b/drivers/misc/lis3lv02d/lis3lv02d.h
34453@@ -266,7 +266,7 @@ struct lis3lv02d {
34454 struct input_polled_dev *idev; /* input device */
34455 struct platform_device *pdev; /* platform device */
34456 struct regulator_bulk_data regulators[2];
34457- atomic_t count; /* interrupt count after last read */
34458+ atomic_unchecked_t count; /* interrupt count after last read */
34459 union axis_conversion ac; /* hw -> logical axis */
34460 int mapped_btns[3];
34461
34462diff --git a/drivers/misc/sgi-gru/gruhandles.c b/drivers/misc/sgi-gru/gruhandles.c
34463index 2f30bad..c4c13d0 100644
34464--- a/drivers/misc/sgi-gru/gruhandles.c
34465+++ b/drivers/misc/sgi-gru/gruhandles.c
34466@@ -44,8 +44,8 @@ static void update_mcs_stats(enum mcs_op op, unsigned long clks)
34467 unsigned long nsec;
34468
34469 nsec = CLKS2NSEC(clks);
34470- atomic_long_inc(&mcs_op_statistics[op].count);
34471- atomic_long_add(nsec, &mcs_op_statistics[op].total);
34472+ atomic_long_inc_unchecked(&mcs_op_statistics[op].count);
34473+ atomic_long_add_unchecked(nsec, &mcs_op_statistics[op].total);
34474 if (mcs_op_statistics[op].max < nsec)
34475 mcs_op_statistics[op].max = nsec;
34476 }
34477diff --git a/drivers/misc/sgi-gru/gruprocfs.c b/drivers/misc/sgi-gru/gruprocfs.c
34478index 950dbe9..eeef0f8 100644
34479--- a/drivers/misc/sgi-gru/gruprocfs.c
34480+++ b/drivers/misc/sgi-gru/gruprocfs.c
34481@@ -32,9 +32,9 @@
34482
34483 #define printstat(s, f) printstat_val(s, &gru_stats.f, #f)
34484
34485-static void printstat_val(struct seq_file *s, atomic_long_t *v, char *id)
34486+static void printstat_val(struct seq_file *s, atomic_long_unchecked_t *v, char *id)
34487 {
34488- unsigned long val = atomic_long_read(v);
34489+ unsigned long val = atomic_long_read_unchecked(v);
34490
34491 seq_printf(s, "%16lu %s\n", val, id);
34492 }
34493@@ -134,8 +134,8 @@ static int mcs_statistics_show(struct seq_file *s, void *p)
34494
34495 seq_printf(s, "%-20s%12s%12s%12s\n", "#id", "count", "aver-clks", "max-clks");
34496 for (op = 0; op < mcsop_last; op++) {
34497- count = atomic_long_read(&mcs_op_statistics[op].count);
34498- total = atomic_long_read(&mcs_op_statistics[op].total);
34499+ count = atomic_long_read_unchecked(&mcs_op_statistics[op].count);
34500+ total = atomic_long_read_unchecked(&mcs_op_statistics[op].total);
34501 max = mcs_op_statistics[op].max;
34502 seq_printf(s, "%-20s%12ld%12ld%12ld\n", id[op], count,
34503 count ? total / count : 0, max);
34504diff --git a/drivers/misc/sgi-gru/grutables.h b/drivers/misc/sgi-gru/grutables.h
34505index 5c3ce24..4915ccb 100644
34506--- a/drivers/misc/sgi-gru/grutables.h
34507+++ b/drivers/misc/sgi-gru/grutables.h
34508@@ -167,82 +167,82 @@ extern unsigned int gru_max_gids;
34509 * GRU statistics.
34510 */
34511 struct gru_stats_s {
34512- atomic_long_t vdata_alloc;
34513- atomic_long_t vdata_free;
34514- atomic_long_t gts_alloc;
34515- atomic_long_t gts_free;
34516- atomic_long_t gms_alloc;
34517- atomic_long_t gms_free;
34518- atomic_long_t gts_double_allocate;
34519- atomic_long_t assign_context;
34520- atomic_long_t assign_context_failed;
34521- atomic_long_t free_context;
34522- atomic_long_t load_user_context;
34523- atomic_long_t load_kernel_context;
34524- atomic_long_t lock_kernel_context;
34525- atomic_long_t unlock_kernel_context;
34526- atomic_long_t steal_user_context;
34527- atomic_long_t steal_kernel_context;
34528- atomic_long_t steal_context_failed;
34529- atomic_long_t nopfn;
34530- atomic_long_t asid_new;
34531- atomic_long_t asid_next;
34532- atomic_long_t asid_wrap;
34533- atomic_long_t asid_reuse;
34534- atomic_long_t intr;
34535- atomic_long_t intr_cbr;
34536- atomic_long_t intr_tfh;
34537- atomic_long_t intr_spurious;
34538- atomic_long_t intr_mm_lock_failed;
34539- atomic_long_t call_os;
34540- atomic_long_t call_os_wait_queue;
34541- atomic_long_t user_flush_tlb;
34542- atomic_long_t user_unload_context;
34543- atomic_long_t user_exception;
34544- atomic_long_t set_context_option;
34545- atomic_long_t check_context_retarget_intr;
34546- atomic_long_t check_context_unload;
34547- atomic_long_t tlb_dropin;
34548- atomic_long_t tlb_preload_page;
34549- atomic_long_t tlb_dropin_fail_no_asid;
34550- atomic_long_t tlb_dropin_fail_upm;
34551- atomic_long_t tlb_dropin_fail_invalid;
34552- atomic_long_t tlb_dropin_fail_range_active;
34553- atomic_long_t tlb_dropin_fail_idle;
34554- atomic_long_t tlb_dropin_fail_fmm;
34555- atomic_long_t tlb_dropin_fail_no_exception;
34556- atomic_long_t tfh_stale_on_fault;
34557- atomic_long_t mmu_invalidate_range;
34558- atomic_long_t mmu_invalidate_page;
34559- atomic_long_t flush_tlb;
34560- atomic_long_t flush_tlb_gru;
34561- atomic_long_t flush_tlb_gru_tgh;
34562- atomic_long_t flush_tlb_gru_zero_asid;
34563+ atomic_long_unchecked_t vdata_alloc;
34564+ atomic_long_unchecked_t vdata_free;
34565+ atomic_long_unchecked_t gts_alloc;
34566+ atomic_long_unchecked_t gts_free;
34567+ atomic_long_unchecked_t gms_alloc;
34568+ atomic_long_unchecked_t gms_free;
34569+ atomic_long_unchecked_t gts_double_allocate;
34570+ atomic_long_unchecked_t assign_context;
34571+ atomic_long_unchecked_t assign_context_failed;
34572+ atomic_long_unchecked_t free_context;
34573+ atomic_long_unchecked_t load_user_context;
34574+ atomic_long_unchecked_t load_kernel_context;
34575+ atomic_long_unchecked_t lock_kernel_context;
34576+ atomic_long_unchecked_t unlock_kernel_context;
34577+ atomic_long_unchecked_t steal_user_context;
34578+ atomic_long_unchecked_t steal_kernel_context;
34579+ atomic_long_unchecked_t steal_context_failed;
34580+ atomic_long_unchecked_t nopfn;
34581+ atomic_long_unchecked_t asid_new;
34582+ atomic_long_unchecked_t asid_next;
34583+ atomic_long_unchecked_t asid_wrap;
34584+ atomic_long_unchecked_t asid_reuse;
34585+ atomic_long_unchecked_t intr;
34586+ atomic_long_unchecked_t intr_cbr;
34587+ atomic_long_unchecked_t intr_tfh;
34588+ atomic_long_unchecked_t intr_spurious;
34589+ atomic_long_unchecked_t intr_mm_lock_failed;
34590+ atomic_long_unchecked_t call_os;
34591+ atomic_long_unchecked_t call_os_wait_queue;
34592+ atomic_long_unchecked_t user_flush_tlb;
34593+ atomic_long_unchecked_t user_unload_context;
34594+ atomic_long_unchecked_t user_exception;
34595+ atomic_long_unchecked_t set_context_option;
34596+ atomic_long_unchecked_t check_context_retarget_intr;
34597+ atomic_long_unchecked_t check_context_unload;
34598+ atomic_long_unchecked_t tlb_dropin;
34599+ atomic_long_unchecked_t tlb_preload_page;
34600+ atomic_long_unchecked_t tlb_dropin_fail_no_asid;
34601+ atomic_long_unchecked_t tlb_dropin_fail_upm;
34602+ atomic_long_unchecked_t tlb_dropin_fail_invalid;
34603+ atomic_long_unchecked_t tlb_dropin_fail_range_active;
34604+ atomic_long_unchecked_t tlb_dropin_fail_idle;
34605+ atomic_long_unchecked_t tlb_dropin_fail_fmm;
34606+ atomic_long_unchecked_t tlb_dropin_fail_no_exception;
34607+ atomic_long_unchecked_t tfh_stale_on_fault;
34608+ atomic_long_unchecked_t mmu_invalidate_range;
34609+ atomic_long_unchecked_t mmu_invalidate_page;
34610+ atomic_long_unchecked_t flush_tlb;
34611+ atomic_long_unchecked_t flush_tlb_gru;
34612+ atomic_long_unchecked_t flush_tlb_gru_tgh;
34613+ atomic_long_unchecked_t flush_tlb_gru_zero_asid;
34614
34615- atomic_long_t copy_gpa;
34616- atomic_long_t read_gpa;
34617+ atomic_long_unchecked_t copy_gpa;
34618+ atomic_long_unchecked_t read_gpa;
34619
34620- atomic_long_t mesq_receive;
34621- atomic_long_t mesq_receive_none;
34622- atomic_long_t mesq_send;
34623- atomic_long_t mesq_send_failed;
34624- atomic_long_t mesq_noop;
34625- atomic_long_t mesq_send_unexpected_error;
34626- atomic_long_t mesq_send_lb_overflow;
34627- atomic_long_t mesq_send_qlimit_reached;
34628- atomic_long_t mesq_send_amo_nacked;
34629- atomic_long_t mesq_send_put_nacked;
34630- atomic_long_t mesq_page_overflow;
34631- atomic_long_t mesq_qf_locked;
34632- atomic_long_t mesq_qf_noop_not_full;
34633- atomic_long_t mesq_qf_switch_head_failed;
34634- atomic_long_t mesq_qf_unexpected_error;
34635- atomic_long_t mesq_noop_unexpected_error;
34636- atomic_long_t mesq_noop_lb_overflow;
34637- atomic_long_t mesq_noop_qlimit_reached;
34638- atomic_long_t mesq_noop_amo_nacked;
34639- atomic_long_t mesq_noop_put_nacked;
34640- atomic_long_t mesq_noop_page_overflow;
34641+ atomic_long_unchecked_t mesq_receive;
34642+ atomic_long_unchecked_t mesq_receive_none;
34643+ atomic_long_unchecked_t mesq_send;
34644+ atomic_long_unchecked_t mesq_send_failed;
34645+ atomic_long_unchecked_t mesq_noop;
34646+ atomic_long_unchecked_t mesq_send_unexpected_error;
34647+ atomic_long_unchecked_t mesq_send_lb_overflow;
34648+ atomic_long_unchecked_t mesq_send_qlimit_reached;
34649+ atomic_long_unchecked_t mesq_send_amo_nacked;
34650+ atomic_long_unchecked_t mesq_send_put_nacked;
34651+ atomic_long_unchecked_t mesq_page_overflow;
34652+ atomic_long_unchecked_t mesq_qf_locked;
34653+ atomic_long_unchecked_t mesq_qf_noop_not_full;
34654+ atomic_long_unchecked_t mesq_qf_switch_head_failed;
34655+ atomic_long_unchecked_t mesq_qf_unexpected_error;
34656+ atomic_long_unchecked_t mesq_noop_unexpected_error;
34657+ atomic_long_unchecked_t mesq_noop_lb_overflow;
34658+ atomic_long_unchecked_t mesq_noop_qlimit_reached;
34659+ atomic_long_unchecked_t mesq_noop_amo_nacked;
34660+ atomic_long_unchecked_t mesq_noop_put_nacked;
34661+ atomic_long_unchecked_t mesq_noop_page_overflow;
34662
34663 };
34664
34665@@ -251,8 +251,8 @@ enum mcs_op {cchop_allocate, cchop_start, cchop_interrupt, cchop_interrupt_sync,
34666 tghop_invalidate, mcsop_last};
34667
34668 struct mcs_op_statistic {
34669- atomic_long_t count;
34670- atomic_long_t total;
34671+ atomic_long_unchecked_t count;
34672+ atomic_long_unchecked_t total;
34673 unsigned long max;
34674 };
34675
34676@@ -275,7 +275,7 @@ extern struct mcs_op_statistic mcs_op_statistics[mcsop_last];
34677
34678 #define STAT(id) do { \
34679 if (gru_options & OPT_STATS) \
34680- atomic_long_inc(&gru_stats.id); \
34681+ atomic_long_inc_unchecked(&gru_stats.id); \
34682 } while (0)
34683
34684 #ifdef CONFIG_SGI_GRU_DEBUG
34685diff --git a/drivers/misc/sgi-xp/xp.h b/drivers/misc/sgi-xp/xp.h
34686index c862cd4..0d176fe 100644
34687--- a/drivers/misc/sgi-xp/xp.h
34688+++ b/drivers/misc/sgi-xp/xp.h
34689@@ -288,7 +288,7 @@ struct xpc_interface {
34690 xpc_notify_func, void *);
34691 void (*received) (short, int, void *);
34692 enum xp_retval (*partid_to_nasids) (short, void *);
34693-};
34694+} __no_const;
34695
34696 extern struct xpc_interface xpc_interface;
34697
34698diff --git a/drivers/misc/sgi-xp/xpc.h b/drivers/misc/sgi-xp/xpc.h
34699index b94d5f7..7f494c5 100644
34700--- a/drivers/misc/sgi-xp/xpc.h
34701+++ b/drivers/misc/sgi-xp/xpc.h
34702@@ -835,6 +835,7 @@ struct xpc_arch_operations {
34703 void (*received_payload) (struct xpc_channel *, void *);
34704 void (*notify_senders_of_disconnect) (struct xpc_channel *);
34705 };
34706+typedef struct xpc_arch_operations __no_const xpc_arch_operations_no_const;
34707
34708 /* struct xpc_partition act_state values (for XPC HB) */
34709
34710@@ -876,7 +877,7 @@ extern struct xpc_registration xpc_registrations[];
34711 /* found in xpc_main.c */
34712 extern struct device *xpc_part;
34713 extern struct device *xpc_chan;
34714-extern struct xpc_arch_operations xpc_arch_ops;
34715+extern xpc_arch_operations_no_const xpc_arch_ops;
34716 extern int xpc_disengage_timelimit;
34717 extern int xpc_disengage_timedout;
34718 extern int xpc_activate_IRQ_rcvd;
34719diff --git a/drivers/misc/sgi-xp/xpc_main.c b/drivers/misc/sgi-xp/xpc_main.c
34720index 8d082b4..aa749ae 100644
34721--- a/drivers/misc/sgi-xp/xpc_main.c
34722+++ b/drivers/misc/sgi-xp/xpc_main.c
34723@@ -162,7 +162,7 @@ static struct notifier_block xpc_die_notifier = {
34724 .notifier_call = xpc_system_die,
34725 };
34726
34727-struct xpc_arch_operations xpc_arch_ops;
34728+xpc_arch_operations_no_const xpc_arch_ops;
34729
34730 /*
34731 * Timer function to enforce the timelimit on the partition disengage.
34732diff --git a/drivers/mmc/host/sdhci-pci.c b/drivers/mmc/host/sdhci-pci.c
34733index 504da71..9722d43 100644
34734--- a/drivers/mmc/host/sdhci-pci.c
34735+++ b/drivers/mmc/host/sdhci-pci.c
34736@@ -653,7 +653,7 @@ static const struct sdhci_pci_fixes sdhci_via = {
34737 .probe = via_probe,
34738 };
34739
34740-static const struct pci_device_id pci_ids[] __devinitdata = {
34741+static const struct pci_device_id pci_ids[] __devinitconst = {
34742 {
34743 .vendor = PCI_VENDOR_ID_RICOH,
34744 .device = PCI_DEVICE_ID_RICOH_R5C822,
34745diff --git a/drivers/mtd/devices/doc2000.c b/drivers/mtd/devices/doc2000.c
34746index a4eb8b5..8c0628f 100644
34747--- a/drivers/mtd/devices/doc2000.c
34748+++ b/drivers/mtd/devices/doc2000.c
34749@@ -753,7 +753,7 @@ static int doc_write(struct mtd_info *mtd, loff_t to, size_t len,
34750
34751 /* The ECC will not be calculated correctly if less than 512 is written */
34752 /* DBB-
34753- if (len != 0x200 && eccbuf)
34754+ if (len != 0x200)
34755 printk(KERN_WARNING
34756 "ECC needs a full sector write (adr: %lx size %lx)\n",
34757 (long) to, (long) len);
34758diff --git a/drivers/mtd/nand/denali.c b/drivers/mtd/nand/denali.c
34759index 0650aaf..7718762 100644
34760--- a/drivers/mtd/nand/denali.c
34761+++ b/drivers/mtd/nand/denali.c
34762@@ -26,6 +26,7 @@
34763 #include <linux/pci.h>
34764 #include <linux/mtd/mtd.h>
34765 #include <linux/module.h>
34766+#include <linux/slab.h>
34767
34768 #include "denali.h"
34769
34770diff --git a/drivers/mtd/nftlmount.c b/drivers/mtd/nftlmount.c
34771index 51b9d6a..52af9a7 100644
34772--- a/drivers/mtd/nftlmount.c
34773+++ b/drivers/mtd/nftlmount.c
34774@@ -24,6 +24,7 @@
34775 #include <asm/errno.h>
34776 #include <linux/delay.h>
34777 #include <linux/slab.h>
34778+#include <linux/sched.h>
34779 #include <linux/mtd/mtd.h>
34780 #include <linux/mtd/nand.h>
34781 #include <linux/mtd/nftl.h>
34782diff --git a/drivers/net/ethernet/atheros/atlx/atl2.c b/drivers/net/ethernet/atheros/atlx/atl2.c
34783index 57d64b8..623dd86 100644
34784--- a/drivers/net/ethernet/atheros/atlx/atl2.c
34785+++ b/drivers/net/ethernet/atheros/atlx/atl2.c
34786@@ -2845,7 +2845,7 @@ static void atl2_force_ps(struct atl2_hw *hw)
34787 */
34788
34789 #define ATL2_PARAM(X, desc) \
34790- static const int __devinitdata X[ATL2_MAX_NIC + 1] = ATL2_PARAM_INIT; \
34791+ static const int __devinitconst X[ATL2_MAX_NIC + 1] = ATL2_PARAM_INIT; \
34792 MODULE_PARM(X, "1-" __MODULE_STRING(ATL2_MAX_NIC) "i"); \
34793 MODULE_PARM_DESC(X, desc);
34794 #else
34795diff --git a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h
34796index f83e033..8b4f43a 100644
34797--- a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h
34798+++ b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h
34799@@ -486,7 +486,7 @@ struct bnx2x_rx_mode_obj {
34800
34801 int (*wait_comp)(struct bnx2x *bp,
34802 struct bnx2x_rx_mode_ramrod_params *p);
34803-};
34804+} __no_const;
34805
34806 /********************** Set multicast group ***********************************/
34807
34808diff --git a/drivers/net/ethernet/broadcom/tg3.h b/drivers/net/ethernet/broadcom/tg3.h
34809index 6d52cb2..bc95640 100644
34810--- a/drivers/net/ethernet/broadcom/tg3.h
34811+++ b/drivers/net/ethernet/broadcom/tg3.h
34812@@ -140,6 +140,7 @@
34813 #define CHIPREV_ID_5750_A0 0x4000
34814 #define CHIPREV_ID_5750_A1 0x4001
34815 #define CHIPREV_ID_5750_A3 0x4003
34816+#define CHIPREV_ID_5750_C1 0x4201
34817 #define CHIPREV_ID_5750_C2 0x4202
34818 #define CHIPREV_ID_5752_A0_HW 0x5000
34819 #define CHIPREV_ID_5752_A0 0x6000
34820diff --git a/drivers/net/ethernet/chelsio/cxgb3/l2t.h b/drivers/net/ethernet/chelsio/cxgb3/l2t.h
34821index 8cffcdf..aadf043 100644
34822--- a/drivers/net/ethernet/chelsio/cxgb3/l2t.h
34823+++ b/drivers/net/ethernet/chelsio/cxgb3/l2t.h
34824@@ -87,7 +87,7 @@ typedef void (*arp_failure_handler_func)(struct t3cdev * dev,
34825 */
34826 struct l2t_skb_cb {
34827 arp_failure_handler_func arp_failure_handler;
34828-};
34829+} __no_const;
34830
34831 #define L2T_SKB_CB(skb) ((struct l2t_skb_cb *)(skb)->cb)
34832
34833diff --git a/drivers/net/ethernet/dec/tulip/de4x5.c b/drivers/net/ethernet/dec/tulip/de4x5.c
34834index f879e92..726f20f 100644
34835--- a/drivers/net/ethernet/dec/tulip/de4x5.c
34836+++ b/drivers/net/ethernet/dec/tulip/de4x5.c
34837@@ -5388,7 +5388,7 @@ de4x5_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
34838 for (i=0; i<ETH_ALEN; i++) {
34839 tmp.addr[i] = dev->dev_addr[i];
34840 }
34841- if (copy_to_user(ioc->data, tmp.addr, ioc->len)) return -EFAULT;
34842+ if (ioc->len > sizeof tmp.addr || copy_to_user(ioc->data, tmp.addr, ioc->len)) return -EFAULT;
34843 break;
34844
34845 case DE4X5_SET_HWADDR: /* Set the hardware address */
34846@@ -5428,7 +5428,7 @@ de4x5_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
34847 spin_lock_irqsave(&lp->lock, flags);
34848 memcpy(&statbuf, &lp->pktStats, ioc->len);
34849 spin_unlock_irqrestore(&lp->lock, flags);
34850- if (copy_to_user(ioc->data, &statbuf, ioc->len))
34851+ if (ioc->len > sizeof statbuf || copy_to_user(ioc->data, &statbuf, ioc->len))
34852 return -EFAULT;
34853 break;
34854 }
34855diff --git a/drivers/net/ethernet/dec/tulip/eeprom.c b/drivers/net/ethernet/dec/tulip/eeprom.c
34856index ed7d1dc..d426748 100644
34857--- a/drivers/net/ethernet/dec/tulip/eeprom.c
34858+++ b/drivers/net/ethernet/dec/tulip/eeprom.c
34859@@ -79,7 +79,7 @@ static struct eeprom_fixup eeprom_fixups[] __devinitdata = {
34860 {NULL}};
34861
34862
34863-static const char *block_name[] __devinitdata = {
34864+static const char *block_name[] __devinitconst = {
34865 "21140 non-MII",
34866 "21140 MII PHY",
34867 "21142 Serial PHY",
34868diff --git a/drivers/net/ethernet/dec/tulip/uli526x.c b/drivers/net/ethernet/dec/tulip/uli526x.c
34869index 75d45f8..3d9c55b 100644
34870--- a/drivers/net/ethernet/dec/tulip/uli526x.c
34871+++ b/drivers/net/ethernet/dec/tulip/uli526x.c
34872@@ -129,7 +129,7 @@ struct uli526x_board_info {
34873 struct uli_phy_ops {
34874 void (*write)(struct uli526x_board_info *, u8, u8, u16);
34875 u16 (*read)(struct uli526x_board_info *, u8, u8);
34876- } phy;
34877+ } __no_const phy;
34878 struct net_device *next_dev; /* next device */
34879 struct pci_dev *pdev; /* PCI device */
34880 spinlock_t lock;
34881diff --git a/drivers/net/ethernet/dec/tulip/winbond-840.c b/drivers/net/ethernet/dec/tulip/winbond-840.c
34882index 4d1ffca..7c1ec4d 100644
34883--- a/drivers/net/ethernet/dec/tulip/winbond-840.c
34884+++ b/drivers/net/ethernet/dec/tulip/winbond-840.c
34885@@ -236,7 +236,7 @@ struct pci_id_info {
34886 int drv_flags; /* Driver use, intended as capability flags. */
34887 };
34888
34889-static const struct pci_id_info pci_id_tbl[] __devinitdata = {
34890+static const struct pci_id_info pci_id_tbl[] __devinitconst = {
34891 { /* Sometime a Level-One switch card. */
34892 "Winbond W89c840", CanHaveMII | HasBrokenTx | FDXOnNoMII},
34893 { "Winbond W89c840", CanHaveMII | HasBrokenTx},
34894diff --git a/drivers/net/ethernet/dlink/sundance.c b/drivers/net/ethernet/dlink/sundance.c
34895index d7bb52a..3b83588 100644
34896--- a/drivers/net/ethernet/dlink/sundance.c
34897+++ b/drivers/net/ethernet/dlink/sundance.c
34898@@ -218,7 +218,7 @@ enum {
34899 struct pci_id_info {
34900 const char *name;
34901 };
34902-static const struct pci_id_info pci_id_tbl[] __devinitdata = {
34903+static const struct pci_id_info pci_id_tbl[] __devinitconst = {
34904 {"D-Link DFE-550TX FAST Ethernet Adapter"},
34905 {"D-Link DFE-550FX 100Mbps Fiber-optics Adapter"},
34906 {"D-Link DFE-580TX 4 port Server Adapter"},
34907diff --git a/drivers/net/ethernet/emulex/benet/be_main.c b/drivers/net/ethernet/emulex/benet/be_main.c
34908index 78b8aa8..dd6323a 100644
34909--- a/drivers/net/ethernet/emulex/benet/be_main.c
34910+++ b/drivers/net/ethernet/emulex/benet/be_main.c
34911@@ -403,7 +403,7 @@ static void accumulate_16bit_val(u32 *acc, u16 val)
34912
34913 if (wrapped)
34914 newacc += 65536;
34915- ACCESS_ONCE(*acc) = newacc;
34916+ ACCESS_ONCE_RW(*acc) = newacc;
34917 }
34918
34919 void be_parse_stats(struct be_adapter *adapter)
34920diff --git a/drivers/net/ethernet/faraday/ftgmac100.c b/drivers/net/ethernet/faraday/ftgmac100.c
34921index 74d749e..eefb1bd 100644
34922--- a/drivers/net/ethernet/faraday/ftgmac100.c
34923+++ b/drivers/net/ethernet/faraday/ftgmac100.c
34924@@ -31,6 +31,8 @@
34925 #include <linux/netdevice.h>
34926 #include <linux/phy.h>
34927 #include <linux/platform_device.h>
34928+#include <linux/interrupt.h>
34929+#include <linux/irqreturn.h>
34930 #include <net/ip.h>
34931
34932 #include "ftgmac100.h"
34933diff --git a/drivers/net/ethernet/faraday/ftmac100.c b/drivers/net/ethernet/faraday/ftmac100.c
34934index b901a01..1ff32ee 100644
34935--- a/drivers/net/ethernet/faraday/ftmac100.c
34936+++ b/drivers/net/ethernet/faraday/ftmac100.c
34937@@ -31,6 +31,8 @@
34938 #include <linux/module.h>
34939 #include <linux/netdevice.h>
34940 #include <linux/platform_device.h>
34941+#include <linux/interrupt.h>
34942+#include <linux/irqreturn.h>
34943
34944 #include "ftmac100.h"
34945
34946diff --git a/drivers/net/ethernet/fealnx.c b/drivers/net/ethernet/fealnx.c
34947index 9d71c9c..0e4a0ac 100644
34948--- a/drivers/net/ethernet/fealnx.c
34949+++ b/drivers/net/ethernet/fealnx.c
34950@@ -150,7 +150,7 @@ struct chip_info {
34951 int flags;
34952 };
34953
34954-static const struct chip_info skel_netdrv_tbl[] __devinitdata = {
34955+static const struct chip_info skel_netdrv_tbl[] __devinitconst = {
34956 { "100/10M Ethernet PCI Adapter", HAS_MII_XCVR },
34957 { "100/10M Ethernet PCI Adapter", HAS_CHIP_XCVR },
34958 { "1000/100/10M Ethernet PCI Adapter", HAS_MII_XCVR },
34959diff --git a/drivers/net/ethernet/intel/e1000e/hw.h b/drivers/net/ethernet/intel/e1000e/hw.h
34960index ed5b409..ec37828 100644
34961--- a/drivers/net/ethernet/intel/e1000e/hw.h
34962+++ b/drivers/net/ethernet/intel/e1000e/hw.h
34963@@ -797,6 +797,7 @@ struct e1000_mac_operations {
34964 void (*rar_set)(struct e1000_hw *, u8 *, u32);
34965 s32 (*read_mac_addr)(struct e1000_hw *);
34966 };
34967+typedef struct e1000_mac_operations __no_const e1000_mac_operations_no_const;
34968
34969 /*
34970 * When to use various PHY register access functions:
34971@@ -837,6 +838,7 @@ struct e1000_phy_operations {
34972 void (*power_up)(struct e1000_hw *);
34973 void (*power_down)(struct e1000_hw *);
34974 };
34975+typedef struct e1000_phy_operations __no_const e1000_phy_operations_no_const;
34976
34977 /* Function pointers for the NVM. */
34978 struct e1000_nvm_operations {
34979@@ -849,9 +851,10 @@ struct e1000_nvm_operations {
34980 s32 (*validate)(struct e1000_hw *);
34981 s32 (*write)(struct e1000_hw *, u16, u16, u16 *);
34982 };
34983+typedef struct e1000_nvm_operations __no_const e1000_nvm_operations_no_const;
34984
34985 struct e1000_mac_info {
34986- struct e1000_mac_operations ops;
34987+ e1000_mac_operations_no_const ops;
34988 u8 addr[ETH_ALEN];
34989 u8 perm_addr[ETH_ALEN];
34990
34991@@ -892,7 +895,7 @@ struct e1000_mac_info {
34992 };
34993
34994 struct e1000_phy_info {
34995- struct e1000_phy_operations ops;
34996+ e1000_phy_operations_no_const ops;
34997
34998 enum e1000_phy_type type;
34999
35000@@ -926,7 +929,7 @@ struct e1000_phy_info {
35001 };
35002
35003 struct e1000_nvm_info {
35004- struct e1000_nvm_operations ops;
35005+ e1000_nvm_operations_no_const ops;
35006
35007 enum e1000_nvm_type type;
35008 enum e1000_nvm_override override;
35009diff --git a/drivers/net/ethernet/intel/igb/e1000_hw.h b/drivers/net/ethernet/intel/igb/e1000_hw.h
35010index c2a51dc..c2bd262 100644
35011--- a/drivers/net/ethernet/intel/igb/e1000_hw.h
35012+++ b/drivers/net/ethernet/intel/igb/e1000_hw.h
35013@@ -327,6 +327,7 @@ struct e1000_mac_operations {
35014 void (*release_swfw_sync)(struct e1000_hw *, u16);
35015
35016 };
35017+typedef struct e1000_mac_operations __no_const e1000_mac_operations_no_const;
35018
35019 struct e1000_phy_operations {
35020 s32 (*acquire)(struct e1000_hw *);
35021@@ -343,6 +344,7 @@ struct e1000_phy_operations {
35022 s32 (*set_d3_lplu_state)(struct e1000_hw *, bool);
35023 s32 (*write_reg)(struct e1000_hw *, u32, u16);
35024 };
35025+typedef struct e1000_phy_operations __no_const e1000_phy_operations_no_const;
35026
35027 struct e1000_nvm_operations {
35028 s32 (*acquire)(struct e1000_hw *);
35029@@ -353,6 +355,7 @@ struct e1000_nvm_operations {
35030 s32 (*validate)(struct e1000_hw *);
35031 s32 (*valid_led_default)(struct e1000_hw *, u16 *);
35032 };
35033+typedef struct e1000_nvm_operations __no_const e1000_nvm_operations_no_const;
35034
35035 struct e1000_info {
35036 s32 (*get_invariants)(struct e1000_hw *);
35037@@ -364,7 +367,7 @@ struct e1000_info {
35038 extern const struct e1000_info e1000_82575_info;
35039
35040 struct e1000_mac_info {
35041- struct e1000_mac_operations ops;
35042+ e1000_mac_operations_no_const ops;
35043
35044 u8 addr[6];
35045 u8 perm_addr[6];
35046@@ -402,7 +405,7 @@ struct e1000_mac_info {
35047 };
35048
35049 struct e1000_phy_info {
35050- struct e1000_phy_operations ops;
35051+ e1000_phy_operations_no_const ops;
35052
35053 enum e1000_phy_type type;
35054
35055@@ -437,7 +440,7 @@ struct e1000_phy_info {
35056 };
35057
35058 struct e1000_nvm_info {
35059- struct e1000_nvm_operations ops;
35060+ e1000_nvm_operations_no_const ops;
35061 enum e1000_nvm_type type;
35062 enum e1000_nvm_override override;
35063
35064@@ -482,6 +485,7 @@ struct e1000_mbx_operations {
35065 s32 (*check_for_ack)(struct e1000_hw *, u16);
35066 s32 (*check_for_rst)(struct e1000_hw *, u16);
35067 };
35068+typedef struct e1000_mbx_operations __no_const e1000_mbx_operations_no_const;
35069
35070 struct e1000_mbx_stats {
35071 u32 msgs_tx;
35072@@ -493,7 +497,7 @@ struct e1000_mbx_stats {
35073 };
35074
35075 struct e1000_mbx_info {
35076- struct e1000_mbx_operations ops;
35077+ e1000_mbx_operations_no_const ops;
35078 struct e1000_mbx_stats stats;
35079 u32 timeout;
35080 u32 usec_delay;
35081diff --git a/drivers/net/ethernet/intel/igbvf/vf.h b/drivers/net/ethernet/intel/igbvf/vf.h
35082index 57db3c6..aa825fc 100644
35083--- a/drivers/net/ethernet/intel/igbvf/vf.h
35084+++ b/drivers/net/ethernet/intel/igbvf/vf.h
35085@@ -189,9 +189,10 @@ struct e1000_mac_operations {
35086 s32 (*read_mac_addr)(struct e1000_hw *);
35087 s32 (*set_vfta)(struct e1000_hw *, u16, bool);
35088 };
35089+typedef struct e1000_mac_operations __no_const e1000_mac_operations_no_const;
35090
35091 struct e1000_mac_info {
35092- struct e1000_mac_operations ops;
35093+ e1000_mac_operations_no_const ops;
35094 u8 addr[6];
35095 u8 perm_addr[6];
35096
35097@@ -213,6 +214,7 @@ struct e1000_mbx_operations {
35098 s32 (*check_for_ack)(struct e1000_hw *);
35099 s32 (*check_for_rst)(struct e1000_hw *);
35100 };
35101+typedef struct e1000_mbx_operations __no_const e1000_mbx_operations_no_const;
35102
35103 struct e1000_mbx_stats {
35104 u32 msgs_tx;
35105@@ -224,7 +226,7 @@ struct e1000_mbx_stats {
35106 };
35107
35108 struct e1000_mbx_info {
35109- struct e1000_mbx_operations ops;
35110+ e1000_mbx_operations_no_const ops;
35111 struct e1000_mbx_stats stats;
35112 u32 timeout;
35113 u32 usec_delay;
35114diff --git a/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c b/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c
35115index 3456d56..b688d81 100644
35116--- a/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c
35117+++ b/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c
35118@@ -884,7 +884,7 @@ void ixgbe_ptp_start_cyclecounter(struct ixgbe_adapter *adapter)
35119 /* store the new cycle speed */
35120 adapter->cycle_speed = cycle_speed;
35121
35122- ACCESS_ONCE(adapter->base_incval) = incval;
35123+ ACCESS_ONCE_RW(adapter->base_incval) = incval;
35124 smp_mb();
35125
35126 /* grab the ptp lock */
35127diff --git a/drivers/net/ethernet/intel/ixgbe/ixgbe_type.h b/drivers/net/ethernet/intel/ixgbe/ixgbe_type.h
35128index 400f86a..7f2e062 100644
35129--- a/drivers/net/ethernet/intel/ixgbe/ixgbe_type.h
35130+++ b/drivers/net/ethernet/intel/ixgbe/ixgbe_type.h
35131@@ -2799,6 +2799,7 @@ struct ixgbe_eeprom_operations {
35132 s32 (*update_checksum)(struct ixgbe_hw *);
35133 u16 (*calc_checksum)(struct ixgbe_hw *);
35134 };
35135+typedef struct ixgbe_eeprom_operations __no_const ixgbe_eeprom_operations_no_const;
35136
35137 struct ixgbe_mac_operations {
35138 s32 (*init_hw)(struct ixgbe_hw *);
35139@@ -2865,6 +2866,7 @@ struct ixgbe_mac_operations {
35140 s32 (*get_thermal_sensor_data)(struct ixgbe_hw *);
35141 s32 (*init_thermal_sensor_thresh)(struct ixgbe_hw *hw);
35142 };
35143+typedef struct ixgbe_mac_operations __no_const ixgbe_mac_operations_no_const;
35144
35145 struct ixgbe_phy_operations {
35146 s32 (*identify)(struct ixgbe_hw *);
35147@@ -2884,9 +2886,10 @@ struct ixgbe_phy_operations {
35148 s32 (*write_i2c_eeprom)(struct ixgbe_hw *, u8, u8);
35149 s32 (*check_overtemp)(struct ixgbe_hw *);
35150 };
35151+typedef struct ixgbe_phy_operations __no_const ixgbe_phy_operations_no_const;
35152
35153 struct ixgbe_eeprom_info {
35154- struct ixgbe_eeprom_operations ops;
35155+ ixgbe_eeprom_operations_no_const ops;
35156 enum ixgbe_eeprom_type type;
35157 u32 semaphore_delay;
35158 u16 word_size;
35159@@ -2896,7 +2899,7 @@ struct ixgbe_eeprom_info {
35160
35161 #define IXGBE_FLAGS_DOUBLE_RESET_REQUIRED 0x01
35162 struct ixgbe_mac_info {
35163- struct ixgbe_mac_operations ops;
35164+ ixgbe_mac_operations_no_const ops;
35165 enum ixgbe_mac_type type;
35166 u8 addr[ETH_ALEN];
35167 u8 perm_addr[ETH_ALEN];
35168@@ -2926,7 +2929,7 @@ struct ixgbe_mac_info {
35169 };
35170
35171 struct ixgbe_phy_info {
35172- struct ixgbe_phy_operations ops;
35173+ ixgbe_phy_operations_no_const ops;
35174 struct mdio_if_info mdio;
35175 enum ixgbe_phy_type type;
35176 u32 id;
35177@@ -2954,6 +2957,7 @@ struct ixgbe_mbx_operations {
35178 s32 (*check_for_ack)(struct ixgbe_hw *, u16);
35179 s32 (*check_for_rst)(struct ixgbe_hw *, u16);
35180 };
35181+typedef struct ixgbe_mbx_operations __no_const ixgbe_mbx_operations_no_const;
35182
35183 struct ixgbe_mbx_stats {
35184 u32 msgs_tx;
35185@@ -2965,7 +2969,7 @@ struct ixgbe_mbx_stats {
35186 };
35187
35188 struct ixgbe_mbx_info {
35189- struct ixgbe_mbx_operations ops;
35190+ ixgbe_mbx_operations_no_const ops;
35191 struct ixgbe_mbx_stats stats;
35192 u32 timeout;
35193 u32 usec_delay;
35194diff --git a/drivers/net/ethernet/intel/ixgbevf/vf.h b/drivers/net/ethernet/intel/ixgbevf/vf.h
35195index 25c951d..cc7cf33 100644
35196--- a/drivers/net/ethernet/intel/ixgbevf/vf.h
35197+++ b/drivers/net/ethernet/intel/ixgbevf/vf.h
35198@@ -70,6 +70,7 @@ struct ixgbe_mac_operations {
35199 s32 (*clear_vfta)(struct ixgbe_hw *);
35200 s32 (*set_vfta)(struct ixgbe_hw *, u32, u32, bool);
35201 };
35202+typedef struct ixgbe_mac_operations __no_const ixgbe_mac_operations_no_const;
35203
35204 enum ixgbe_mac_type {
35205 ixgbe_mac_unknown = 0,
35206@@ -79,7 +80,7 @@ enum ixgbe_mac_type {
35207 };
35208
35209 struct ixgbe_mac_info {
35210- struct ixgbe_mac_operations ops;
35211+ ixgbe_mac_operations_no_const ops;
35212 u8 addr[6];
35213 u8 perm_addr[6];
35214
35215@@ -103,6 +104,7 @@ struct ixgbe_mbx_operations {
35216 s32 (*check_for_ack)(struct ixgbe_hw *);
35217 s32 (*check_for_rst)(struct ixgbe_hw *);
35218 };
35219+typedef struct ixgbe_mbx_operations __no_const ixgbe_mbx_operations_no_const;
35220
35221 struct ixgbe_mbx_stats {
35222 u32 msgs_tx;
35223@@ -114,7 +116,7 @@ struct ixgbe_mbx_stats {
35224 };
35225
35226 struct ixgbe_mbx_info {
35227- struct ixgbe_mbx_operations ops;
35228+ ixgbe_mbx_operations_no_const ops;
35229 struct ixgbe_mbx_stats stats;
35230 u32 timeout;
35231 u32 udelay;
35232diff --git a/drivers/net/ethernet/neterion/vxge/vxge-config.h b/drivers/net/ethernet/neterion/vxge/vxge-config.h
35233index 9e0c1ee..8471f77 100644
35234--- a/drivers/net/ethernet/neterion/vxge/vxge-config.h
35235+++ b/drivers/net/ethernet/neterion/vxge/vxge-config.h
35236@@ -514,7 +514,7 @@ struct vxge_hw_uld_cbs {
35237 void (*link_down)(struct __vxge_hw_device *devh);
35238 void (*crit_err)(struct __vxge_hw_device *devh,
35239 enum vxge_hw_event type, u64 ext_data);
35240-};
35241+} __no_const;
35242
35243 /*
35244 * struct __vxge_hw_blockpool_entry - Block private data structure
35245diff --git a/drivers/net/ethernet/neterion/vxge/vxge-traffic.h b/drivers/net/ethernet/neterion/vxge/vxge-traffic.h
35246index 4a518a3..936b334 100644
35247--- a/drivers/net/ethernet/neterion/vxge/vxge-traffic.h
35248+++ b/drivers/net/ethernet/neterion/vxge/vxge-traffic.h
35249@@ -2088,7 +2088,7 @@ struct vxge_hw_mempool_cbs {
35250 struct vxge_hw_mempool_dma *dma_object,
35251 u32 index,
35252 u32 is_last);
35253-};
35254+} __no_const;
35255
35256 #define VXGE_HW_VIRTUAL_PATH_HANDLE(vpath) \
35257 ((struct __vxge_hw_vpath_handle *)(vpath)->vpath_handles.next)
35258diff --git a/drivers/net/ethernet/realtek/r8169.c b/drivers/net/ethernet/realtek/r8169.c
35259index b47d5b3..273a516 100644
35260--- a/drivers/net/ethernet/realtek/r8169.c
35261+++ b/drivers/net/ethernet/realtek/r8169.c
35262@@ -745,22 +745,22 @@ struct rtl8169_private {
35263 struct mdio_ops {
35264 void (*write)(struct rtl8169_private *, int, int);
35265 int (*read)(struct rtl8169_private *, int);
35266- } mdio_ops;
35267+ } __no_const mdio_ops;
35268
35269 struct pll_power_ops {
35270 void (*down)(struct rtl8169_private *);
35271 void (*up)(struct rtl8169_private *);
35272- } pll_power_ops;
35273+ } __no_const pll_power_ops;
35274
35275 struct jumbo_ops {
35276 void (*enable)(struct rtl8169_private *);
35277 void (*disable)(struct rtl8169_private *);
35278- } jumbo_ops;
35279+ } __no_const jumbo_ops;
35280
35281 struct csi_ops {
35282 void (*write)(struct rtl8169_private *, int, int);
35283 u32 (*read)(struct rtl8169_private *, int);
35284- } csi_ops;
35285+ } __no_const csi_ops;
35286
35287 int (*set_speed)(struct net_device *, u8 aneg, u16 sp, u8 dpx, u32 adv);
35288 int (*get_settings)(struct net_device *, struct ethtool_cmd *);
35289diff --git a/drivers/net/ethernet/sis/sis190.c b/drivers/net/ethernet/sis/sis190.c
35290index 4613591..d816601 100644
35291--- a/drivers/net/ethernet/sis/sis190.c
35292+++ b/drivers/net/ethernet/sis/sis190.c
35293@@ -1618,7 +1618,7 @@ static int __devinit sis190_get_mac_addr_from_eeprom(struct pci_dev *pdev,
35294 static int __devinit sis190_get_mac_addr_from_apc(struct pci_dev *pdev,
35295 struct net_device *dev)
35296 {
35297- static const u16 __devinitdata ids[] = { 0x0965, 0x0966, 0x0968 };
35298+ static const u16 __devinitconst ids[] = { 0x0965, 0x0966, 0x0968 };
35299 struct sis190_private *tp = netdev_priv(dev);
35300 struct pci_dev *isa_bridge;
35301 u8 reg, tmp8;
35302diff --git a/drivers/net/ethernet/stmicro/stmmac/mmc_core.c b/drivers/net/ethernet/stmicro/stmmac/mmc_core.c
35303index 0c74a70..3bc6f68 100644
35304--- a/drivers/net/ethernet/stmicro/stmmac/mmc_core.c
35305+++ b/drivers/net/ethernet/stmicro/stmmac/mmc_core.c
35306@@ -140,8 +140,8 @@ void dwmac_mmc_ctrl(void __iomem *ioaddr, unsigned int mode)
35307
35308 writel(value, ioaddr + MMC_CNTRL);
35309
35310- pr_debug("stmmac: MMC ctrl register (offset 0x%x): 0x%08x\n",
35311- MMC_CNTRL, value);
35312+// pr_debug("stmmac: MMC ctrl register (offset 0x%x): 0x%08x\n",
35313+// MMC_CNTRL, value);
35314 }
35315
35316 /* To mask all all interrupts.*/
35317diff --git a/drivers/net/hyperv/hyperv_net.h b/drivers/net/hyperv/hyperv_net.h
35318index 95ceb35..318fc12 100644
35319--- a/drivers/net/hyperv/hyperv_net.h
35320+++ b/drivers/net/hyperv/hyperv_net.h
35321@@ -99,7 +99,7 @@ struct rndis_device {
35322
35323 enum rndis_device_state state;
35324 bool link_state;
35325- atomic_t new_req_id;
35326+ atomic_unchecked_t new_req_id;
35327
35328 spinlock_t request_lock;
35329 struct list_head req_list;
35330diff --git a/drivers/net/hyperv/rndis_filter.c b/drivers/net/hyperv/rndis_filter.c
35331index 1e88a10..1b01736 100644
35332--- a/drivers/net/hyperv/rndis_filter.c
35333+++ b/drivers/net/hyperv/rndis_filter.c
35334@@ -99,7 +99,7 @@ static struct rndis_request *get_rndis_request(struct rndis_device *dev,
35335 * template
35336 */
35337 set = &rndis_msg->msg.set_req;
35338- set->req_id = atomic_inc_return(&dev->new_req_id);
35339+ set->req_id = atomic_inc_return_unchecked(&dev->new_req_id);
35340
35341 /* Add to the request list */
35342 spin_lock_irqsave(&dev->request_lock, flags);
35343@@ -730,7 +730,7 @@ static void rndis_filter_halt_device(struct rndis_device *dev)
35344
35345 /* Setup the rndis set */
35346 halt = &request->request_msg.msg.halt_req;
35347- halt->req_id = atomic_inc_return(&dev->new_req_id);
35348+ halt->req_id = atomic_inc_return_unchecked(&dev->new_req_id);
35349
35350 /* Ignore return since this msg is optional. */
35351 rndis_filter_send_request(dev, request);
35352diff --git a/drivers/net/ppp/ppp_generic.c b/drivers/net/ppp/ppp_generic.c
35353index 5c05572..389610b 100644
35354--- a/drivers/net/ppp/ppp_generic.c
35355+++ b/drivers/net/ppp/ppp_generic.c
35356@@ -986,7 +986,6 @@ ppp_net_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
35357 void __user *addr = (void __user *) ifr->ifr_ifru.ifru_data;
35358 struct ppp_stats stats;
35359 struct ppp_comp_stats cstats;
35360- char *vers;
35361
35362 switch (cmd) {
35363 case SIOCGPPPSTATS:
35364@@ -1008,8 +1007,7 @@ ppp_net_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
35365 break;
35366
35367 case SIOCGPPPVER:
35368- vers = PPP_VERSION;
35369- if (copy_to_user(addr, vers, strlen(vers) + 1))
35370+ if (copy_to_user(addr, PPP_VERSION, sizeof(PPP_VERSION)))
35371 break;
35372 err = 0;
35373 break;
35374diff --git a/drivers/net/tun.c b/drivers/net/tun.c
35375index 3a16d4f..a311cec 100644
35376--- a/drivers/net/tun.c
35377+++ b/drivers/net/tun.c
35378@@ -1367,7 +1367,7 @@ static int set_offload(struct tun_struct *tun, unsigned long arg)
35379 }
35380
35381 static long __tun_chr_ioctl(struct file *file, unsigned int cmd,
35382- unsigned long arg, int ifreq_len)
35383+ unsigned long arg, size_t ifreq_len)
35384 {
35385 struct tun_file *tfile = file->private_data;
35386 struct tun_struct *tun;
35387@@ -1378,6 +1378,9 @@ static long __tun_chr_ioctl(struct file *file, unsigned int cmd,
35388 int vnet_hdr_sz;
35389 int ret;
35390
35391+ if (ifreq_len > sizeof ifr)
35392+ return -EFAULT;
35393+
35394 if (cmd == TUNSETIFF || _IOC_TYPE(cmd) == 0x89) {
35395 if (copy_from_user(&ifr, argp, ifreq_len))
35396 return -EFAULT;
35397diff --git a/drivers/net/usb/hso.c b/drivers/net/usb/hso.c
35398index 62f30b4..ff99dfd 100644
35399--- a/drivers/net/usb/hso.c
35400+++ b/drivers/net/usb/hso.c
35401@@ -71,7 +71,7 @@
35402 #include <asm/byteorder.h>
35403 #include <linux/serial_core.h>
35404 #include <linux/serial.h>
35405-
35406+#include <asm/local.h>
35407
35408 #define MOD_AUTHOR "Option Wireless"
35409 #define MOD_DESCRIPTION "USB High Speed Option driver"
35410@@ -1182,7 +1182,7 @@ static void put_rxbuf_data_and_resubmit_ctrl_urb(struct hso_serial *serial)
35411 struct urb *urb;
35412
35413 urb = serial->rx_urb[0];
35414- if (serial->port.count > 0) {
35415+ if (atomic_read(&serial->port.count) > 0) {
35416 count = put_rxbuf_data(urb, serial);
35417 if (count == -1)
35418 return;
35419@@ -1218,7 +1218,7 @@ static void hso_std_serial_read_bulk_callback(struct urb *urb)
35420 DUMP1(urb->transfer_buffer, urb->actual_length);
35421
35422 /* Anyone listening? */
35423- if (serial->port.count == 0)
35424+ if (atomic_read(&serial->port.count) == 0)
35425 return;
35426
35427 if (status == 0) {
35428@@ -1300,8 +1300,7 @@ static int hso_serial_open(struct tty_struct *tty, struct file *filp)
35429 tty_port_tty_set(&serial->port, tty);
35430
35431 /* check for port already opened, if not set the termios */
35432- serial->port.count++;
35433- if (serial->port.count == 1) {
35434+ if (atomic_inc_return(&serial->port.count) == 1) {
35435 serial->rx_state = RX_IDLE;
35436 /* Force default termio settings */
35437 _hso_serial_set_termios(tty, NULL);
35438@@ -1313,7 +1312,7 @@ static int hso_serial_open(struct tty_struct *tty, struct file *filp)
35439 result = hso_start_serial_device(serial->parent, GFP_KERNEL);
35440 if (result) {
35441 hso_stop_serial_device(serial->parent);
35442- serial->port.count--;
35443+ atomic_dec(&serial->port.count);
35444 kref_put(&serial->parent->ref, hso_serial_ref_free);
35445 }
35446 } else {
35447@@ -1350,10 +1349,10 @@ static void hso_serial_close(struct tty_struct *tty, struct file *filp)
35448
35449 /* reset the rts and dtr */
35450 /* do the actual close */
35451- serial->port.count--;
35452+ atomic_dec(&serial->port.count);
35453
35454- if (serial->port.count <= 0) {
35455- serial->port.count = 0;
35456+ if (atomic_read(&serial->port.count) <= 0) {
35457+ atomic_set(&serial->port.count, 0);
35458 tty_port_tty_set(&serial->port, NULL);
35459 if (!usb_gone)
35460 hso_stop_serial_device(serial->parent);
35461@@ -1429,7 +1428,7 @@ static void hso_serial_set_termios(struct tty_struct *tty, struct ktermios *old)
35462
35463 /* the actual setup */
35464 spin_lock_irqsave(&serial->serial_lock, flags);
35465- if (serial->port.count)
35466+ if (atomic_read(&serial->port.count))
35467 _hso_serial_set_termios(tty, old);
35468 else
35469 tty->termios = old;
35470@@ -1888,7 +1887,7 @@ static void intr_callback(struct urb *urb)
35471 D1("Pending read interrupt on port %d\n", i);
35472 spin_lock(&serial->serial_lock);
35473 if (serial->rx_state == RX_IDLE &&
35474- serial->port.count > 0) {
35475+ atomic_read(&serial->port.count) > 0) {
35476 /* Setup and send a ctrl req read on
35477 * port i */
35478 if (!serial->rx_urb_filled[0]) {
35479@@ -3079,7 +3078,7 @@ static int hso_resume(struct usb_interface *iface)
35480 /* Start all serial ports */
35481 for (i = 0; i < HSO_SERIAL_TTY_MINORS; i++) {
35482 if (serial_table[i] && (serial_table[i]->interface == iface)) {
35483- if (dev2ser(serial_table[i])->port.count) {
35484+ if (atomic_read(&dev2ser(serial_table[i])->port.count)) {
35485 result =
35486 hso_start_serial_device(serial_table[i], GFP_NOIO);
35487 hso_kick_transmit(dev2ser(serial_table[i]));
35488diff --git a/drivers/net/wireless/ath/ath.h b/drivers/net/wireless/ath/ath.h
35489index 6169fbd..40e8422 100644
35490--- a/drivers/net/wireless/ath/ath.h
35491+++ b/drivers/net/wireless/ath/ath.h
35492@@ -119,6 +119,7 @@ struct ath_ops {
35493 void (*write_flush) (void *);
35494 u32 (*rmw)(void *, u32 reg_offset, u32 set, u32 clr);
35495 };
35496+typedef struct ath_ops __no_const ath_ops_no_const;
35497
35498 struct ath_common;
35499 struct ath_bus_ops;
35500diff --git a/drivers/net/wireless/ath/ath9k/ar9002_mac.c b/drivers/net/wireless/ath/ath9k/ar9002_mac.c
35501index 8d78253..bebbb68 100644
35502--- a/drivers/net/wireless/ath/ath9k/ar9002_mac.c
35503+++ b/drivers/net/wireless/ath/ath9k/ar9002_mac.c
35504@@ -184,8 +184,8 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
35505 ads->ds_txstatus6 = ads->ds_txstatus7 = 0;
35506 ads->ds_txstatus8 = ads->ds_txstatus9 = 0;
35507
35508- ACCESS_ONCE(ads->ds_link) = i->link;
35509- ACCESS_ONCE(ads->ds_data) = i->buf_addr[0];
35510+ ACCESS_ONCE_RW(ads->ds_link) = i->link;
35511+ ACCESS_ONCE_RW(ads->ds_data) = i->buf_addr[0];
35512
35513 ctl1 = i->buf_len[0] | (i->is_last ? 0 : AR_TxMore);
35514 ctl6 = SM(i->keytype, AR_EncrType);
35515@@ -199,26 +199,26 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
35516
35517 if ((i->is_first || i->is_last) &&
35518 i->aggr != AGGR_BUF_MIDDLE && i->aggr != AGGR_BUF_LAST) {
35519- ACCESS_ONCE(ads->ds_ctl2) = set11nTries(i->rates, 0)
35520+ ACCESS_ONCE_RW(ads->ds_ctl2) = set11nTries(i->rates, 0)
35521 | set11nTries(i->rates, 1)
35522 | set11nTries(i->rates, 2)
35523 | set11nTries(i->rates, 3)
35524 | (i->dur_update ? AR_DurUpdateEna : 0)
35525 | SM(0, AR_BurstDur);
35526
35527- ACCESS_ONCE(ads->ds_ctl3) = set11nRate(i->rates, 0)
35528+ ACCESS_ONCE_RW(ads->ds_ctl3) = set11nRate(i->rates, 0)
35529 | set11nRate(i->rates, 1)
35530 | set11nRate(i->rates, 2)
35531 | set11nRate(i->rates, 3);
35532 } else {
35533- ACCESS_ONCE(ads->ds_ctl2) = 0;
35534- ACCESS_ONCE(ads->ds_ctl3) = 0;
35535+ ACCESS_ONCE_RW(ads->ds_ctl2) = 0;
35536+ ACCESS_ONCE_RW(ads->ds_ctl3) = 0;
35537 }
35538
35539 if (!i->is_first) {
35540- ACCESS_ONCE(ads->ds_ctl0) = 0;
35541- ACCESS_ONCE(ads->ds_ctl1) = ctl1;
35542- ACCESS_ONCE(ads->ds_ctl6) = ctl6;
35543+ ACCESS_ONCE_RW(ads->ds_ctl0) = 0;
35544+ ACCESS_ONCE_RW(ads->ds_ctl1) = ctl1;
35545+ ACCESS_ONCE_RW(ads->ds_ctl6) = ctl6;
35546 return;
35547 }
35548
35549@@ -243,7 +243,7 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
35550 break;
35551 }
35552
35553- ACCESS_ONCE(ads->ds_ctl0) = (i->pkt_len & AR_FrameLen)
35554+ ACCESS_ONCE_RW(ads->ds_ctl0) = (i->pkt_len & AR_FrameLen)
35555 | (i->flags & ATH9K_TXDESC_VMF ? AR_VirtMoreFrag : 0)
35556 | SM(i->txpower, AR_XmitPower)
35557 | (i->flags & ATH9K_TXDESC_VEOL ? AR_VEOL : 0)
35558@@ -253,19 +253,19 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
35559 | (i->flags & ATH9K_TXDESC_RTSENA ? AR_RTSEnable :
35560 (i->flags & ATH9K_TXDESC_CTSENA ? AR_CTSEnable : 0));
35561
35562- ACCESS_ONCE(ads->ds_ctl1) = ctl1;
35563- ACCESS_ONCE(ads->ds_ctl6) = ctl6;
35564+ ACCESS_ONCE_RW(ads->ds_ctl1) = ctl1;
35565+ ACCESS_ONCE_RW(ads->ds_ctl6) = ctl6;
35566
35567 if (i->aggr == AGGR_BUF_MIDDLE || i->aggr == AGGR_BUF_LAST)
35568 return;
35569
35570- ACCESS_ONCE(ads->ds_ctl4) = set11nPktDurRTSCTS(i->rates, 0)
35571+ ACCESS_ONCE_RW(ads->ds_ctl4) = set11nPktDurRTSCTS(i->rates, 0)
35572 | set11nPktDurRTSCTS(i->rates, 1);
35573
35574- ACCESS_ONCE(ads->ds_ctl5) = set11nPktDurRTSCTS(i->rates, 2)
35575+ ACCESS_ONCE_RW(ads->ds_ctl5) = set11nPktDurRTSCTS(i->rates, 2)
35576 | set11nPktDurRTSCTS(i->rates, 3);
35577
35578- ACCESS_ONCE(ads->ds_ctl7) = set11nRateFlags(i->rates, 0)
35579+ ACCESS_ONCE_RW(ads->ds_ctl7) = set11nRateFlags(i->rates, 0)
35580 | set11nRateFlags(i->rates, 1)
35581 | set11nRateFlags(i->rates, 2)
35582 | set11nRateFlags(i->rates, 3)
35583diff --git a/drivers/net/wireless/ath/ath9k/ar9003_mac.c b/drivers/net/wireless/ath/ath9k/ar9003_mac.c
35584index 78816b8..1fcdfae 100644
35585--- a/drivers/net/wireless/ath/ath9k/ar9003_mac.c
35586+++ b/drivers/net/wireless/ath/ath9k/ar9003_mac.c
35587@@ -39,47 +39,47 @@ ar9003_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
35588 (i->qcu << AR_TxQcuNum_S) | desc_len;
35589
35590 checksum += val;
35591- ACCESS_ONCE(ads->info) = val;
35592+ ACCESS_ONCE_RW(ads->info) = val;
35593
35594 checksum += i->link;
35595- ACCESS_ONCE(ads->link) = i->link;
35596+ ACCESS_ONCE_RW(ads->link) = i->link;
35597
35598 checksum += i->buf_addr[0];
35599- ACCESS_ONCE(ads->data0) = i->buf_addr[0];
35600+ ACCESS_ONCE_RW(ads->data0) = i->buf_addr[0];
35601 checksum += i->buf_addr[1];
35602- ACCESS_ONCE(ads->data1) = i->buf_addr[1];
35603+ ACCESS_ONCE_RW(ads->data1) = i->buf_addr[1];
35604 checksum += i->buf_addr[2];
35605- ACCESS_ONCE(ads->data2) = i->buf_addr[2];
35606+ ACCESS_ONCE_RW(ads->data2) = i->buf_addr[2];
35607 checksum += i->buf_addr[3];
35608- ACCESS_ONCE(ads->data3) = i->buf_addr[3];
35609+ ACCESS_ONCE_RW(ads->data3) = i->buf_addr[3];
35610
35611 checksum += (val = (i->buf_len[0] << AR_BufLen_S) & AR_BufLen);
35612- ACCESS_ONCE(ads->ctl3) = val;
35613+ ACCESS_ONCE_RW(ads->ctl3) = val;
35614 checksum += (val = (i->buf_len[1] << AR_BufLen_S) & AR_BufLen);
35615- ACCESS_ONCE(ads->ctl5) = val;
35616+ ACCESS_ONCE_RW(ads->ctl5) = val;
35617 checksum += (val = (i->buf_len[2] << AR_BufLen_S) & AR_BufLen);
35618- ACCESS_ONCE(ads->ctl7) = val;
35619+ ACCESS_ONCE_RW(ads->ctl7) = val;
35620 checksum += (val = (i->buf_len[3] << AR_BufLen_S) & AR_BufLen);
35621- ACCESS_ONCE(ads->ctl9) = val;
35622+ ACCESS_ONCE_RW(ads->ctl9) = val;
35623
35624 checksum = (u16) (((checksum & 0xffff) + (checksum >> 16)) & 0xffff);
35625- ACCESS_ONCE(ads->ctl10) = checksum;
35626+ ACCESS_ONCE_RW(ads->ctl10) = checksum;
35627
35628 if (i->is_first || i->is_last) {
35629- ACCESS_ONCE(ads->ctl13) = set11nTries(i->rates, 0)
35630+ ACCESS_ONCE_RW(ads->ctl13) = set11nTries(i->rates, 0)
35631 | set11nTries(i->rates, 1)
35632 | set11nTries(i->rates, 2)
35633 | set11nTries(i->rates, 3)
35634 | (i->dur_update ? AR_DurUpdateEna : 0)
35635 | SM(0, AR_BurstDur);
35636
35637- ACCESS_ONCE(ads->ctl14) = set11nRate(i->rates, 0)
35638+ ACCESS_ONCE_RW(ads->ctl14) = set11nRate(i->rates, 0)
35639 | set11nRate(i->rates, 1)
35640 | set11nRate(i->rates, 2)
35641 | set11nRate(i->rates, 3);
35642 } else {
35643- ACCESS_ONCE(ads->ctl13) = 0;
35644- ACCESS_ONCE(ads->ctl14) = 0;
35645+ ACCESS_ONCE_RW(ads->ctl13) = 0;
35646+ ACCESS_ONCE_RW(ads->ctl14) = 0;
35647 }
35648
35649 ads->ctl20 = 0;
35650@@ -89,17 +89,17 @@ ar9003_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
35651
35652 ctl17 = SM(i->keytype, AR_EncrType);
35653 if (!i->is_first) {
35654- ACCESS_ONCE(ads->ctl11) = 0;
35655- ACCESS_ONCE(ads->ctl12) = i->is_last ? 0 : AR_TxMore;
35656- ACCESS_ONCE(ads->ctl15) = 0;
35657- ACCESS_ONCE(ads->ctl16) = 0;
35658- ACCESS_ONCE(ads->ctl17) = ctl17;
35659- ACCESS_ONCE(ads->ctl18) = 0;
35660- ACCESS_ONCE(ads->ctl19) = 0;
35661+ ACCESS_ONCE_RW(ads->ctl11) = 0;
35662+ ACCESS_ONCE_RW(ads->ctl12) = i->is_last ? 0 : AR_TxMore;
35663+ ACCESS_ONCE_RW(ads->ctl15) = 0;
35664+ ACCESS_ONCE_RW(ads->ctl16) = 0;
35665+ ACCESS_ONCE_RW(ads->ctl17) = ctl17;
35666+ ACCESS_ONCE_RW(ads->ctl18) = 0;
35667+ ACCESS_ONCE_RW(ads->ctl19) = 0;
35668 return;
35669 }
35670
35671- ACCESS_ONCE(ads->ctl11) = (i->pkt_len & AR_FrameLen)
35672+ ACCESS_ONCE_RW(ads->ctl11) = (i->pkt_len & AR_FrameLen)
35673 | (i->flags & ATH9K_TXDESC_VMF ? AR_VirtMoreFrag : 0)
35674 | SM(i->txpower, AR_XmitPower)
35675 | (i->flags & ATH9K_TXDESC_VEOL ? AR_VEOL : 0)
35676@@ -135,22 +135,22 @@ ar9003_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
35677 val = (i->flags & ATH9K_TXDESC_PAPRD) >> ATH9K_TXDESC_PAPRD_S;
35678 ctl12 |= SM(val, AR_PAPRDChainMask);
35679
35680- ACCESS_ONCE(ads->ctl12) = ctl12;
35681- ACCESS_ONCE(ads->ctl17) = ctl17;
35682+ ACCESS_ONCE_RW(ads->ctl12) = ctl12;
35683+ ACCESS_ONCE_RW(ads->ctl17) = ctl17;
35684
35685- ACCESS_ONCE(ads->ctl15) = set11nPktDurRTSCTS(i->rates, 0)
35686+ ACCESS_ONCE_RW(ads->ctl15) = set11nPktDurRTSCTS(i->rates, 0)
35687 | set11nPktDurRTSCTS(i->rates, 1);
35688
35689- ACCESS_ONCE(ads->ctl16) = set11nPktDurRTSCTS(i->rates, 2)
35690+ ACCESS_ONCE_RW(ads->ctl16) = set11nPktDurRTSCTS(i->rates, 2)
35691 | set11nPktDurRTSCTS(i->rates, 3);
35692
35693- ACCESS_ONCE(ads->ctl18) = set11nRateFlags(i->rates, 0)
35694+ ACCESS_ONCE_RW(ads->ctl18) = set11nRateFlags(i->rates, 0)
35695 | set11nRateFlags(i->rates, 1)
35696 | set11nRateFlags(i->rates, 2)
35697 | set11nRateFlags(i->rates, 3)
35698 | SM(i->rtscts_rate, AR_RTSCTSRate);
35699
35700- ACCESS_ONCE(ads->ctl19) = AR_Not_Sounding;
35701+ ACCESS_ONCE_RW(ads->ctl19) = AR_Not_Sounding;
35702 }
35703
35704 static u16 ar9003_calc_ptr_chksum(struct ar9003_txc *ads)
35705diff --git a/drivers/net/wireless/ath/ath9k/hw.h b/drivers/net/wireless/ath/ath9k/hw.h
35706index de6968f..29ac4c1 100644
35707--- a/drivers/net/wireless/ath/ath9k/hw.h
35708+++ b/drivers/net/wireless/ath/ath9k/hw.h
35709@@ -656,7 +656,7 @@ struct ath_hw_private_ops {
35710
35711 /* ANI */
35712 void (*ani_cache_ini_regs)(struct ath_hw *ah);
35713-};
35714+} __no_const;
35715
35716 /**
35717 * struct ath_hw_ops - callbacks used by hardware code and driver code
35718@@ -686,7 +686,7 @@ struct ath_hw_ops {
35719 void (*antdiv_comb_conf_set)(struct ath_hw *ah,
35720 struct ath_hw_antcomb_conf *antconf);
35721
35722-};
35723+} __no_const;
35724
35725 struct ath_nf_limits {
35726 s16 max;
35727@@ -706,7 +706,7 @@ enum ath_cal_list {
35728 #define AH_FASTCC 0x4
35729
35730 struct ath_hw {
35731- struct ath_ops reg_ops;
35732+ ath_ops_no_const reg_ops;
35733
35734 struct ieee80211_hw *hw;
35735 struct ath_common common;
35736diff --git a/drivers/net/wireless/brcm80211/brcmsmac/phy/phy_int.h b/drivers/net/wireless/brcm80211/brcmsmac/phy/phy_int.h
35737index af00e2c..ab04d34 100644
35738--- a/drivers/net/wireless/brcm80211/brcmsmac/phy/phy_int.h
35739+++ b/drivers/net/wireless/brcm80211/brcmsmac/phy/phy_int.h
35740@@ -545,7 +545,7 @@ struct phy_func_ptr {
35741 void (*carrsuppr)(struct brcms_phy *);
35742 s32 (*rxsigpwr)(struct brcms_phy *, s32);
35743 void (*detach)(struct brcms_phy *);
35744-};
35745+} __no_const;
35746
35747 struct brcms_phy {
35748 struct brcms_phy_pub pubpi_ro;
35749diff --git a/drivers/net/wireless/iwlegacy/3945-mac.c b/drivers/net/wireless/iwlegacy/3945-mac.c
35750index faec404..a5277f1 100644
35751--- a/drivers/net/wireless/iwlegacy/3945-mac.c
35752+++ b/drivers/net/wireless/iwlegacy/3945-mac.c
35753@@ -3611,7 +3611,9 @@ il3945_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
35754 */
35755 if (il3945_mod_params.disable_hw_scan) {
35756 D_INFO("Disabling hw_scan\n");
35757- il3945_mac_ops.hw_scan = NULL;
35758+ pax_open_kernel();
35759+ *(void **)&il3945_mac_ops.hw_scan = NULL;
35760+ pax_close_kernel();
35761 }
35762
35763 D_INFO("*** LOAD DRIVER ***\n");
35764diff --git a/drivers/net/wireless/iwlwifi/dvm/debugfs.c b/drivers/net/wireless/iwlwifi/dvm/debugfs.c
35765index a47b306..297daf2 100644
35766--- a/drivers/net/wireless/iwlwifi/dvm/debugfs.c
35767+++ b/drivers/net/wireless/iwlwifi/dvm/debugfs.c
35768@@ -203,7 +203,7 @@ static ssize_t iwl_dbgfs_sram_write(struct file *file,
35769 {
35770 struct iwl_priv *priv = file->private_data;
35771 char buf[64];
35772- int buf_size;
35773+ size_t buf_size;
35774 u32 offset, len;
35775
35776 memset(buf, 0, sizeof(buf));
35777@@ -473,7 +473,7 @@ static ssize_t iwl_dbgfs_rx_handlers_write(struct file *file,
35778 struct iwl_priv *priv = file->private_data;
35779
35780 char buf[8];
35781- int buf_size;
35782+ size_t buf_size;
35783 u32 reset_flag;
35784
35785 memset(buf, 0, sizeof(buf));
35786@@ -554,7 +554,7 @@ static ssize_t iwl_dbgfs_disable_ht40_write(struct file *file,
35787 {
35788 struct iwl_priv *priv = file->private_data;
35789 char buf[8];
35790- int buf_size;
35791+ size_t buf_size;
35792 int ht40;
35793
35794 memset(buf, 0, sizeof(buf));
35795@@ -606,7 +606,7 @@ static ssize_t iwl_dbgfs_sleep_level_override_write(struct file *file,
35796 {
35797 struct iwl_priv *priv = file->private_data;
35798 char buf[8];
35799- int buf_size;
35800+ size_t buf_size;
35801 int value;
35802
35803 memset(buf, 0, sizeof(buf));
35804@@ -1871,7 +1871,7 @@ static ssize_t iwl_dbgfs_clear_ucode_statistics_write(struct file *file,
35805 {
35806 struct iwl_priv *priv = file->private_data;
35807 char buf[8];
35808- int buf_size;
35809+ size_t buf_size;
35810 int clear;
35811
35812 memset(buf, 0, sizeof(buf));
35813@@ -1916,7 +1916,7 @@ static ssize_t iwl_dbgfs_ucode_tracing_write(struct file *file,
35814 {
35815 struct iwl_priv *priv = file->private_data;
35816 char buf[8];
35817- int buf_size;
35818+ size_t buf_size;
35819 int trace;
35820
35821 memset(buf, 0, sizeof(buf));
35822@@ -1987,7 +1987,7 @@ static ssize_t iwl_dbgfs_missed_beacon_write(struct file *file,
35823 {
35824 struct iwl_priv *priv = file->private_data;
35825 char buf[8];
35826- int buf_size;
35827+ size_t buf_size;
35828 int missed;
35829
35830 memset(buf, 0, sizeof(buf));
35831@@ -2028,7 +2028,7 @@ static ssize_t iwl_dbgfs_plcp_delta_write(struct file *file,
35832
35833 struct iwl_priv *priv = file->private_data;
35834 char buf[8];
35835- int buf_size;
35836+ size_t buf_size;
35837 int plcp;
35838
35839 memset(buf, 0, sizeof(buf));
35840@@ -2088,7 +2088,7 @@ static ssize_t iwl_dbgfs_txfifo_flush_write(struct file *file,
35841
35842 struct iwl_priv *priv = file->private_data;
35843 char buf[8];
35844- int buf_size;
35845+ size_t buf_size;
35846 int flush;
35847
35848 memset(buf, 0, sizeof(buf));
35849@@ -2178,7 +2178,7 @@ static ssize_t iwl_dbgfs_protection_mode_write(struct file *file,
35850
35851 struct iwl_priv *priv = file->private_data;
35852 char buf[8];
35853- int buf_size;
35854+ size_t buf_size;
35855 int rts;
35856
35857 if (!priv->cfg->ht_params)
35858@@ -2220,7 +2220,7 @@ static ssize_t iwl_dbgfs_echo_test_write(struct file *file,
35859 {
35860 struct iwl_priv *priv = file->private_data;
35861 char buf[8];
35862- int buf_size;
35863+ size_t buf_size;
35864
35865 memset(buf, 0, sizeof(buf));
35866 buf_size = min(count, sizeof(buf) - 1);
35867@@ -2256,7 +2256,7 @@ static ssize_t iwl_dbgfs_log_event_write(struct file *file,
35868 struct iwl_priv *priv = file->private_data;
35869 u32 event_log_flag;
35870 char buf[8];
35871- int buf_size;
35872+ size_t buf_size;
35873
35874 /* check that the interface is up */
35875 if (!iwl_is_ready(priv))
35876@@ -2310,7 +2310,7 @@ static ssize_t iwl_dbgfs_calib_disabled_write(struct file *file,
35877 struct iwl_priv *priv = file->private_data;
35878 char buf[8];
35879 u32 calib_disabled;
35880- int buf_size;
35881+ size_t buf_size;
35882
35883 memset(buf, 0, sizeof(buf));
35884 buf_size = min(count, sizeof(buf) - 1);
35885diff --git a/drivers/net/wireless/iwlwifi/pcie/trans.c b/drivers/net/wireless/iwlwifi/pcie/trans.c
35886index dbeebef..b45a152 100644
35887--- a/drivers/net/wireless/iwlwifi/pcie/trans.c
35888+++ b/drivers/net/wireless/iwlwifi/pcie/trans.c
35889@@ -1944,7 +1944,7 @@ static ssize_t iwl_dbgfs_interrupt_write(struct file *file,
35890 struct isr_statistics *isr_stats = &trans_pcie->isr_stats;
35891
35892 char buf[8];
35893- int buf_size;
35894+ size_t buf_size;
35895 u32 reset_flag;
35896
35897 memset(buf, 0, sizeof(buf));
35898@@ -1965,7 +1965,7 @@ static ssize_t iwl_dbgfs_csr_write(struct file *file,
35899 {
35900 struct iwl_trans *trans = file->private_data;
35901 char buf[8];
35902- int buf_size;
35903+ size_t buf_size;
35904 int csr;
35905
35906 memset(buf, 0, sizeof(buf));
35907diff --git a/drivers/net/wireless/mac80211_hwsim.c b/drivers/net/wireless/mac80211_hwsim.c
35908index 0083839..fcb7225 100644
35909--- a/drivers/net/wireless/mac80211_hwsim.c
35910+++ b/drivers/net/wireless/mac80211_hwsim.c
35911@@ -1748,9 +1748,11 @@ static int __init init_mac80211_hwsim(void)
35912 return -EINVAL;
35913
35914 if (fake_hw_scan) {
35915- mac80211_hwsim_ops.hw_scan = mac80211_hwsim_hw_scan;
35916- mac80211_hwsim_ops.sw_scan_start = NULL;
35917- mac80211_hwsim_ops.sw_scan_complete = NULL;
35918+ pax_open_kernel();
35919+ *(void **)&mac80211_hwsim_ops.hw_scan = mac80211_hwsim_hw_scan;
35920+ *(void **)&mac80211_hwsim_ops.sw_scan_start = NULL;
35921+ *(void **)&mac80211_hwsim_ops.sw_scan_complete = NULL;
35922+ pax_close_kernel();
35923 }
35924
35925 spin_lock_init(&hwsim_radio_lock);
35926diff --git a/drivers/net/wireless/mwifiex/main.h b/drivers/net/wireless/mwifiex/main.h
35927index e7c2a82..582e228 100644
35928--- a/drivers/net/wireless/mwifiex/main.h
35929+++ b/drivers/net/wireless/mwifiex/main.h
35930@@ -571,7 +571,7 @@ struct mwifiex_if_ops {
35931 int (*event_complete) (struct mwifiex_adapter *, struct sk_buff *);
35932 int (*data_complete) (struct mwifiex_adapter *, struct sk_buff *);
35933 int (*dnld_fw) (struct mwifiex_adapter *, struct mwifiex_fw_image *);
35934-};
35935+} __no_const;
35936
35937 struct mwifiex_adapter {
35938 u8 iface_type;
35939diff --git a/drivers/net/wireless/rndis_wlan.c b/drivers/net/wireless/rndis_wlan.c
35940index 7a4ae9e..56e00bd 100644
35941--- a/drivers/net/wireless/rndis_wlan.c
35942+++ b/drivers/net/wireless/rndis_wlan.c
35943@@ -1235,7 +1235,7 @@ static int set_rts_threshold(struct usbnet *usbdev, u32 rts_threshold)
35944
35945 netdev_dbg(usbdev->net, "%s(): %i\n", __func__, rts_threshold);
35946
35947- if (rts_threshold < 0 || rts_threshold > 2347)
35948+ if (rts_threshold > 2347)
35949 rts_threshold = 2347;
35950
35951 tmp = cpu_to_le32(rts_threshold);
35952diff --git a/drivers/net/wireless/rt2x00/rt2x00.h b/drivers/net/wireless/rt2x00/rt2x00.h
35953index 8afb546..0c0dc5c 100644
35954--- a/drivers/net/wireless/rt2x00/rt2x00.h
35955+++ b/drivers/net/wireless/rt2x00/rt2x00.h
35956@@ -397,7 +397,7 @@ struct rt2x00_intf {
35957 * for hardware which doesn't support hardware
35958 * sequence counting.
35959 */
35960- atomic_t seqno;
35961+ atomic_unchecked_t seqno;
35962 };
35963
35964 static inline struct rt2x00_intf* vif_to_intf(struct ieee80211_vif *vif)
35965diff --git a/drivers/net/wireless/rt2x00/rt2x00queue.c b/drivers/net/wireless/rt2x00/rt2x00queue.c
35966index f7e74a0..da71431 100644
35967--- a/drivers/net/wireless/rt2x00/rt2x00queue.c
35968+++ b/drivers/net/wireless/rt2x00/rt2x00queue.c
35969@@ -240,9 +240,9 @@ static void rt2x00queue_create_tx_descriptor_seq(struct rt2x00_dev *rt2x00dev,
35970 * sequence counter given by mac80211.
35971 */
35972 if (test_bit(ENTRY_TXD_FIRST_FRAGMENT, &txdesc->flags))
35973- seqno = atomic_add_return(0x10, &intf->seqno);
35974+ seqno = atomic_add_return_unchecked(0x10, &intf->seqno);
35975 else
35976- seqno = atomic_read(&intf->seqno);
35977+ seqno = atomic_read_unchecked(&intf->seqno);
35978
35979 hdr->seq_ctrl &= cpu_to_le16(IEEE80211_SCTL_FRAG);
35980 hdr->seq_ctrl |= cpu_to_le16(seqno);
35981diff --git a/drivers/net/wireless/ti/wl1251/wl1251.h b/drivers/net/wireless/ti/wl1251/wl1251.h
35982index fd02060..74ee481 100644
35983--- a/drivers/net/wireless/ti/wl1251/wl1251.h
35984+++ b/drivers/net/wireless/ti/wl1251/wl1251.h
35985@@ -266,7 +266,7 @@ struct wl1251_if_operations {
35986 void (*reset)(struct wl1251 *wl);
35987 void (*enable_irq)(struct wl1251 *wl);
35988 void (*disable_irq)(struct wl1251 *wl);
35989-};
35990+} __no_const;
35991
35992 struct wl1251 {
35993 struct ieee80211_hw *hw;
35994diff --git a/drivers/net/wireless/ti/wlcore/wlcore.h b/drivers/net/wireless/ti/wlcore/wlcore.h
35995index 0ce7a8e..56a0ccf 100644
35996--- a/drivers/net/wireless/ti/wlcore/wlcore.h
35997+++ b/drivers/net/wireless/ti/wlcore/wlcore.h
35998@@ -81,7 +81,7 @@ struct wlcore_ops {
35999 struct ieee80211_sta *sta,
36000 struct ieee80211_key_conf *key_conf);
36001 u32 (*pre_pkt_send)(struct wl1271 *wl, u32 buf_offset, u32 last_len);
36002-};
36003+} __no_const;
36004
36005 enum wlcore_partitions {
36006 PART_DOWN,
36007diff --git a/drivers/oprofile/buffer_sync.c b/drivers/oprofile/buffer_sync.c
36008index f34b5b2..b5abb9f 100644
36009--- a/drivers/oprofile/buffer_sync.c
36010+++ b/drivers/oprofile/buffer_sync.c
36011@@ -343,7 +343,7 @@ static void add_data(struct op_entry *entry, struct mm_struct *mm)
36012 if (cookie == NO_COOKIE)
36013 offset = pc;
36014 if (cookie == INVALID_COOKIE) {
36015- atomic_inc(&oprofile_stats.sample_lost_no_mapping);
36016+ atomic_inc_unchecked(&oprofile_stats.sample_lost_no_mapping);
36017 offset = pc;
36018 }
36019 if (cookie != last_cookie) {
36020@@ -387,14 +387,14 @@ add_sample(struct mm_struct *mm, struct op_sample *s, int in_kernel)
36021 /* add userspace sample */
36022
36023 if (!mm) {
36024- atomic_inc(&oprofile_stats.sample_lost_no_mm);
36025+ atomic_inc_unchecked(&oprofile_stats.sample_lost_no_mm);
36026 return 0;
36027 }
36028
36029 cookie = lookup_dcookie(mm, s->eip, &offset);
36030
36031 if (cookie == INVALID_COOKIE) {
36032- atomic_inc(&oprofile_stats.sample_lost_no_mapping);
36033+ atomic_inc_unchecked(&oprofile_stats.sample_lost_no_mapping);
36034 return 0;
36035 }
36036
36037@@ -563,7 +563,7 @@ void sync_buffer(int cpu)
36038 /* ignore backtraces if failed to add a sample */
36039 if (state == sb_bt_start) {
36040 state = sb_bt_ignore;
36041- atomic_inc(&oprofile_stats.bt_lost_no_mapping);
36042+ atomic_inc_unchecked(&oprofile_stats.bt_lost_no_mapping);
36043 }
36044 }
36045 release_mm(mm);
36046diff --git a/drivers/oprofile/event_buffer.c b/drivers/oprofile/event_buffer.c
36047index c0cc4e7..44d4e54 100644
36048--- a/drivers/oprofile/event_buffer.c
36049+++ b/drivers/oprofile/event_buffer.c
36050@@ -53,7 +53,7 @@ void add_event_entry(unsigned long value)
36051 }
36052
36053 if (buffer_pos == buffer_size) {
36054- atomic_inc(&oprofile_stats.event_lost_overflow);
36055+ atomic_inc_unchecked(&oprofile_stats.event_lost_overflow);
36056 return;
36057 }
36058
36059diff --git a/drivers/oprofile/oprof.c b/drivers/oprofile/oprof.c
36060index ed2c3ec..deda85a 100644
36061--- a/drivers/oprofile/oprof.c
36062+++ b/drivers/oprofile/oprof.c
36063@@ -110,7 +110,7 @@ static void switch_worker(struct work_struct *work)
36064 if (oprofile_ops.switch_events())
36065 return;
36066
36067- atomic_inc(&oprofile_stats.multiplex_counter);
36068+ atomic_inc_unchecked(&oprofile_stats.multiplex_counter);
36069 start_switch_worker();
36070 }
36071
36072diff --git a/drivers/oprofile/oprofile_stats.c b/drivers/oprofile/oprofile_stats.c
36073index 917d28e..d62d981 100644
36074--- a/drivers/oprofile/oprofile_stats.c
36075+++ b/drivers/oprofile/oprofile_stats.c
36076@@ -30,11 +30,11 @@ void oprofile_reset_stats(void)
36077 cpu_buf->sample_invalid_eip = 0;
36078 }
36079
36080- atomic_set(&oprofile_stats.sample_lost_no_mm, 0);
36081- atomic_set(&oprofile_stats.sample_lost_no_mapping, 0);
36082- atomic_set(&oprofile_stats.event_lost_overflow, 0);
36083- atomic_set(&oprofile_stats.bt_lost_no_mapping, 0);
36084- atomic_set(&oprofile_stats.multiplex_counter, 0);
36085+ atomic_set_unchecked(&oprofile_stats.sample_lost_no_mm, 0);
36086+ atomic_set_unchecked(&oprofile_stats.sample_lost_no_mapping, 0);
36087+ atomic_set_unchecked(&oprofile_stats.event_lost_overflow, 0);
36088+ atomic_set_unchecked(&oprofile_stats.bt_lost_no_mapping, 0);
36089+ atomic_set_unchecked(&oprofile_stats.multiplex_counter, 0);
36090 }
36091
36092
36093diff --git a/drivers/oprofile/oprofile_stats.h b/drivers/oprofile/oprofile_stats.h
36094index 38b6fc0..b5cbfce 100644
36095--- a/drivers/oprofile/oprofile_stats.h
36096+++ b/drivers/oprofile/oprofile_stats.h
36097@@ -13,11 +13,11 @@
36098 #include <linux/atomic.h>
36099
36100 struct oprofile_stat_struct {
36101- atomic_t sample_lost_no_mm;
36102- atomic_t sample_lost_no_mapping;
36103- atomic_t bt_lost_no_mapping;
36104- atomic_t event_lost_overflow;
36105- atomic_t multiplex_counter;
36106+ atomic_unchecked_t sample_lost_no_mm;
36107+ atomic_unchecked_t sample_lost_no_mapping;
36108+ atomic_unchecked_t bt_lost_no_mapping;
36109+ atomic_unchecked_t event_lost_overflow;
36110+ atomic_unchecked_t multiplex_counter;
36111 };
36112
36113 extern struct oprofile_stat_struct oprofile_stats;
36114diff --git a/drivers/oprofile/oprofilefs.c b/drivers/oprofile/oprofilefs.c
36115index 849357c..b83c1e0 100644
36116--- a/drivers/oprofile/oprofilefs.c
36117+++ b/drivers/oprofile/oprofilefs.c
36118@@ -185,7 +185,7 @@ static const struct file_operations atomic_ro_fops = {
36119
36120
36121 int oprofilefs_create_ro_atomic(struct super_block *sb, struct dentry *root,
36122- char const *name, atomic_t *val)
36123+ char const *name, atomic_unchecked_t *val)
36124 {
36125 return __oprofilefs_create_file(sb, root, name,
36126 &atomic_ro_fops, 0444, val);
36127diff --git a/drivers/parport/procfs.c b/drivers/parport/procfs.c
36128index 3f56bc0..707d642 100644
36129--- a/drivers/parport/procfs.c
36130+++ b/drivers/parport/procfs.c
36131@@ -64,7 +64,7 @@ static int do_active_device(ctl_table *table, int write,
36132
36133 *ppos += len;
36134
36135- return copy_to_user(result, buffer, len) ? -EFAULT : 0;
36136+ return (len > sizeof buffer || copy_to_user(result, buffer, len)) ? -EFAULT : 0;
36137 }
36138
36139 #ifdef CONFIG_PARPORT_1284
36140@@ -106,7 +106,7 @@ static int do_autoprobe(ctl_table *table, int write,
36141
36142 *ppos += len;
36143
36144- return copy_to_user (result, buffer, len) ? -EFAULT : 0;
36145+ return (len > sizeof buffer || copy_to_user (result, buffer, len)) ? -EFAULT : 0;
36146 }
36147 #endif /* IEEE1284.3 support. */
36148
36149diff --git a/drivers/pci/hotplug/cpci_hotplug.h b/drivers/pci/hotplug/cpci_hotplug.h
36150index 9fff878..ad0ad53 100644
36151--- a/drivers/pci/hotplug/cpci_hotplug.h
36152+++ b/drivers/pci/hotplug/cpci_hotplug.h
36153@@ -59,7 +59,7 @@ struct cpci_hp_controller_ops {
36154 int (*hardware_test) (struct slot* slot, u32 value);
36155 u8 (*get_power) (struct slot* slot);
36156 int (*set_power) (struct slot* slot, int value);
36157-};
36158+} __no_const;
36159
36160 struct cpci_hp_controller {
36161 unsigned int irq;
36162diff --git a/drivers/pci/hotplug/cpqphp_nvram.c b/drivers/pci/hotplug/cpqphp_nvram.c
36163index 76ba8a1..20ca857 100644
36164--- a/drivers/pci/hotplug/cpqphp_nvram.c
36165+++ b/drivers/pci/hotplug/cpqphp_nvram.c
36166@@ -428,9 +428,13 @@ static u32 store_HRT (void __iomem *rom_start)
36167
36168 void compaq_nvram_init (void __iomem *rom_start)
36169 {
36170+
36171+#ifndef CONFIG_PAX_KERNEXEC
36172 if (rom_start) {
36173 compaq_int15_entry_point = (rom_start + ROM_INT15_PHY_ADDR - ROM_PHY_ADDR);
36174 }
36175+#endif
36176+
36177 dbg("int15 entry = %p\n", compaq_int15_entry_point);
36178
36179 /* initialize our int15 lock */
36180diff --git a/drivers/pci/pcie/aspm.c b/drivers/pci/pcie/aspm.c
36181index b500840..d7159d3 100644
36182--- a/drivers/pci/pcie/aspm.c
36183+++ b/drivers/pci/pcie/aspm.c
36184@@ -27,9 +27,9 @@
36185 #define MODULE_PARAM_PREFIX "pcie_aspm."
36186
36187 /* Note: those are not register definitions */
36188-#define ASPM_STATE_L0S_UP (1) /* Upstream direction L0s state */
36189-#define ASPM_STATE_L0S_DW (2) /* Downstream direction L0s state */
36190-#define ASPM_STATE_L1 (4) /* L1 state */
36191+#define ASPM_STATE_L0S_UP (1U) /* Upstream direction L0s state */
36192+#define ASPM_STATE_L0S_DW (2U) /* Downstream direction L0s state */
36193+#define ASPM_STATE_L1 (4U) /* L1 state */
36194 #define ASPM_STATE_L0S (ASPM_STATE_L0S_UP | ASPM_STATE_L0S_DW)
36195 #define ASPM_STATE_ALL (ASPM_STATE_L0S | ASPM_STATE_L1)
36196
36197diff --git a/drivers/pci/probe.c b/drivers/pci/probe.c
36198index 61859d0..124539e 100644
36199--- a/drivers/pci/probe.c
36200+++ b/drivers/pci/probe.c
36201@@ -173,7 +173,7 @@ int __pci_read_base(struct pci_dev *dev, enum pci_bar_type type,
36202 struct pci_bus_region region;
36203 bool bar_too_big = false, bar_disabled = false;
36204
36205- mask = type ? PCI_ROM_ADDRESS_MASK : ~0;
36206+ mask = type ? (u32)PCI_ROM_ADDRESS_MASK : ~0;
36207
36208 /* No printks while decoding is disabled! */
36209 if (!dev->mmio_always_on) {
36210diff --git a/drivers/pci/proc.c b/drivers/pci/proc.c
36211index 27911b5..5b6db88 100644
36212--- a/drivers/pci/proc.c
36213+++ b/drivers/pci/proc.c
36214@@ -476,7 +476,16 @@ static const struct file_operations proc_bus_pci_dev_operations = {
36215 static int __init pci_proc_init(void)
36216 {
36217 struct pci_dev *dev = NULL;
36218+
36219+#ifdef CONFIG_GRKERNSEC_PROC_ADD
36220+#ifdef CONFIG_GRKERNSEC_PROC_USER
36221+ proc_bus_pci_dir = proc_mkdir_mode("bus/pci", S_IRUSR | S_IXUSR, NULL);
36222+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
36223+ proc_bus_pci_dir = proc_mkdir_mode("bus/pci", S_IRUSR | S_IXUSR | S_IRGRP | S_IXGRP, NULL);
36224+#endif
36225+#else
36226 proc_bus_pci_dir = proc_mkdir("bus/pci", NULL);
36227+#endif
36228 proc_create("devices", 0, proc_bus_pci_dir,
36229 &proc_bus_pci_dev_operations);
36230 proc_initialized = 1;
36231diff --git a/drivers/platform/x86/thinkpad_acpi.c b/drivers/platform/x86/thinkpad_acpi.c
36232index 52daaa8..d6b81eb 100644
36233--- a/drivers/platform/x86/thinkpad_acpi.c
36234+++ b/drivers/platform/x86/thinkpad_acpi.c
36235@@ -2097,7 +2097,7 @@ static int hotkey_mask_get(void)
36236 return 0;
36237 }
36238
36239-void static hotkey_mask_warn_incomplete_mask(void)
36240+static void hotkey_mask_warn_incomplete_mask(void)
36241 {
36242 /* log only what the user can fix... */
36243 const u32 wantedmask = hotkey_driver_mask &
36244@@ -2328,11 +2328,6 @@ static void hotkey_read_nvram(struct tp_nvram_state *n, const u32 m)
36245 }
36246 }
36247
36248-static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
36249- struct tp_nvram_state *newn,
36250- const u32 event_mask)
36251-{
36252-
36253 #define TPACPI_COMPARE_KEY(__scancode, __member) \
36254 do { \
36255 if ((event_mask & (1 << __scancode)) && \
36256@@ -2346,36 +2341,42 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
36257 tpacpi_hotkey_send_key(__scancode); \
36258 } while (0)
36259
36260- void issue_volchange(const unsigned int oldvol,
36261- const unsigned int newvol)
36262- {
36263- unsigned int i = oldvol;
36264+static void issue_volchange(const unsigned int oldvol,
36265+ const unsigned int newvol,
36266+ const u32 event_mask)
36267+{
36268+ unsigned int i = oldvol;
36269
36270- while (i > newvol) {
36271- TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEDOWN);
36272- i--;
36273- }
36274- while (i < newvol) {
36275- TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEUP);
36276- i++;
36277- }
36278+ while (i > newvol) {
36279+ TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEDOWN);
36280+ i--;
36281 }
36282+ while (i < newvol) {
36283+ TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEUP);
36284+ i++;
36285+ }
36286+}
36287
36288- void issue_brightnesschange(const unsigned int oldbrt,
36289- const unsigned int newbrt)
36290- {
36291- unsigned int i = oldbrt;
36292+static void issue_brightnesschange(const unsigned int oldbrt,
36293+ const unsigned int newbrt,
36294+ const u32 event_mask)
36295+{
36296+ unsigned int i = oldbrt;
36297
36298- while (i > newbrt) {
36299- TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNEND);
36300- i--;
36301- }
36302- while (i < newbrt) {
36303- TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNHOME);
36304- i++;
36305- }
36306+ while (i > newbrt) {
36307+ TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNEND);
36308+ i--;
36309+ }
36310+ while (i < newbrt) {
36311+ TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNHOME);
36312+ i++;
36313 }
36314+}
36315
36316+static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
36317+ struct tp_nvram_state *newn,
36318+ const u32 event_mask)
36319+{
36320 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_THINKPAD, thinkpad_toggle);
36321 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_FNSPACE, zoom_toggle);
36322 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_FNF7, display_toggle);
36323@@ -2409,7 +2410,7 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
36324 oldn->volume_level != newn->volume_level) {
36325 /* recently muted, or repeated mute keypress, or
36326 * multiple presses ending in mute */
36327- issue_volchange(oldn->volume_level, newn->volume_level);
36328+ issue_volchange(oldn->volume_level, newn->volume_level, event_mask);
36329 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_MUTE);
36330 }
36331 } else {
36332@@ -2419,7 +2420,7 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
36333 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEUP);
36334 }
36335 if (oldn->volume_level != newn->volume_level) {
36336- issue_volchange(oldn->volume_level, newn->volume_level);
36337+ issue_volchange(oldn->volume_level, newn->volume_level, event_mask);
36338 } else if (oldn->volume_toggle != newn->volume_toggle) {
36339 /* repeated vol up/down keypress at end of scale ? */
36340 if (newn->volume_level == 0)
36341@@ -2432,7 +2433,8 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
36342 /* handle brightness */
36343 if (oldn->brightness_level != newn->brightness_level) {
36344 issue_brightnesschange(oldn->brightness_level,
36345- newn->brightness_level);
36346+ newn->brightness_level,
36347+ event_mask);
36348 } else if (oldn->brightness_toggle != newn->brightness_toggle) {
36349 /* repeated key presses that didn't change state */
36350 if (newn->brightness_level == 0)
36351@@ -2441,10 +2443,10 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
36352 && !tp_features.bright_unkfw)
36353 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNHOME);
36354 }
36355+}
36356
36357 #undef TPACPI_COMPARE_KEY
36358 #undef TPACPI_MAY_SEND_KEY
36359-}
36360
36361 /*
36362 * Polling driver
36363diff --git a/drivers/pnp/pnpbios/bioscalls.c b/drivers/pnp/pnpbios/bioscalls.c
36364index 769d265..a3a05ca 100644
36365--- a/drivers/pnp/pnpbios/bioscalls.c
36366+++ b/drivers/pnp/pnpbios/bioscalls.c
36367@@ -58,7 +58,7 @@ do { \
36368 set_desc_limit(&gdt[(selname) >> 3], (size) - 1); \
36369 } while(0)
36370
36371-static struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4092,
36372+static const struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4093,
36373 (unsigned long)__va(0x400UL), PAGE_SIZE - 0x400 - 1);
36374
36375 /*
36376@@ -95,7 +95,10 @@ static inline u16 call_pnp_bios(u16 func, u16 arg1, u16 arg2, u16 arg3,
36377
36378 cpu = get_cpu();
36379 save_desc_40 = get_cpu_gdt_table(cpu)[0x40 / 8];
36380+
36381+ pax_open_kernel();
36382 get_cpu_gdt_table(cpu)[0x40 / 8] = bad_bios_desc;
36383+ pax_close_kernel();
36384
36385 /* On some boxes IRQ's during PnP BIOS calls are deadly. */
36386 spin_lock_irqsave(&pnp_bios_lock, flags);
36387@@ -133,7 +136,10 @@ static inline u16 call_pnp_bios(u16 func, u16 arg1, u16 arg2, u16 arg3,
36388 :"memory");
36389 spin_unlock_irqrestore(&pnp_bios_lock, flags);
36390
36391+ pax_open_kernel();
36392 get_cpu_gdt_table(cpu)[0x40 / 8] = save_desc_40;
36393+ pax_close_kernel();
36394+
36395 put_cpu();
36396
36397 /* If we get here and this is set then the PnP BIOS faulted on us. */
36398@@ -467,7 +473,7 @@ int pnp_bios_read_escd(char *data, u32 nvram_base)
36399 return status;
36400 }
36401
36402-void pnpbios_calls_init(union pnp_bios_install_struct *header)
36403+void __init pnpbios_calls_init(union pnp_bios_install_struct *header)
36404 {
36405 int i;
36406
36407@@ -475,6 +481,8 @@ void pnpbios_calls_init(union pnp_bios_install_struct *header)
36408 pnp_bios_callpoint.offset = header->fields.pm16offset;
36409 pnp_bios_callpoint.segment = PNP_CS16;
36410
36411+ pax_open_kernel();
36412+
36413 for_each_possible_cpu(i) {
36414 struct desc_struct *gdt = get_cpu_gdt_table(i);
36415 if (!gdt)
36416@@ -486,4 +494,6 @@ void pnpbios_calls_init(union pnp_bios_install_struct *header)
36417 set_desc_base(&gdt[GDT_ENTRY_PNPBIOS_DS],
36418 (unsigned long)__va(header->fields.pm16dseg));
36419 }
36420+
36421+ pax_close_kernel();
36422 }
36423diff --git a/drivers/pnp/resource.c b/drivers/pnp/resource.c
36424index b0ecacb..7c9da2e 100644
36425--- a/drivers/pnp/resource.c
36426+++ b/drivers/pnp/resource.c
36427@@ -360,7 +360,7 @@ int pnp_check_irq(struct pnp_dev *dev, struct resource *res)
36428 return 1;
36429
36430 /* check if the resource is valid */
36431- if (*irq < 0 || *irq > 15)
36432+ if (*irq > 15)
36433 return 0;
36434
36435 /* check if the resource is reserved */
36436@@ -424,7 +424,7 @@ int pnp_check_dma(struct pnp_dev *dev, struct resource *res)
36437 return 1;
36438
36439 /* check if the resource is valid */
36440- if (*dma < 0 || *dma == 4 || *dma > 7)
36441+ if (*dma == 4 || *dma > 7)
36442 return 0;
36443
36444 /* check if the resource is reserved */
36445diff --git a/drivers/power/bq27x00_battery.c b/drivers/power/bq27x00_battery.c
36446index 181ddec..774b6da 100644
36447--- a/drivers/power/bq27x00_battery.c
36448+++ b/drivers/power/bq27x00_battery.c
36449@@ -80,7 +80,7 @@
36450 struct bq27x00_device_info;
36451 struct bq27x00_access_methods {
36452 int (*read)(struct bq27x00_device_info *di, u8 reg, bool single);
36453-};
36454+} __no_const;
36455
36456 enum bq27x00_chip { BQ27000, BQ27500, BQ27425};
36457
36458diff --git a/drivers/regulator/max8660.c b/drivers/regulator/max8660.c
36459index 8d53174..04c65de 100644
36460--- a/drivers/regulator/max8660.c
36461+++ b/drivers/regulator/max8660.c
36462@@ -333,8 +333,10 @@ static int __devinit max8660_probe(struct i2c_client *client,
36463 max8660->shadow_regs[MAX8660_OVER1] = 5;
36464 } else {
36465 /* Otherwise devices can be toggled via software */
36466- max8660_dcdc_ops.enable = max8660_dcdc_enable;
36467- max8660_dcdc_ops.disable = max8660_dcdc_disable;
36468+ pax_open_kernel();
36469+ *(void **)&max8660_dcdc_ops.enable = max8660_dcdc_enable;
36470+ *(void **)&max8660_dcdc_ops.disable = max8660_dcdc_disable;
36471+ pax_close_kernel();
36472 }
36473
36474 /*
36475diff --git a/drivers/regulator/mc13892-regulator.c b/drivers/regulator/mc13892-regulator.c
36476index b388b74..ed82573 100644
36477--- a/drivers/regulator/mc13892-regulator.c
36478+++ b/drivers/regulator/mc13892-regulator.c
36479@@ -565,10 +565,12 @@ static int __devinit mc13892_regulator_probe(struct platform_device *pdev)
36480 }
36481 mc13xxx_unlock(mc13892);
36482
36483- mc13892_regulators[MC13892_VCAM].desc.ops->set_mode
36484+ pax_open_kernel();
36485+ *(void **)&mc13892_regulators[MC13892_VCAM].desc.ops->set_mode
36486 = mc13892_vcam_set_mode;
36487- mc13892_regulators[MC13892_VCAM].desc.ops->get_mode
36488+ *(void **)&mc13892_regulators[MC13892_VCAM].desc.ops->get_mode
36489 = mc13892_vcam_get_mode;
36490+ pax_close_kernel();
36491
36492 mc13xxx_data = mc13xxx_parse_regulators_dt(pdev, mc13892_regulators,
36493 ARRAY_SIZE(mc13892_regulators));
36494diff --git a/drivers/rtc/rtc-dev.c b/drivers/rtc/rtc-dev.c
36495index cace6d3..f623fda 100644
36496--- a/drivers/rtc/rtc-dev.c
36497+++ b/drivers/rtc/rtc-dev.c
36498@@ -14,6 +14,7 @@
36499 #include <linux/module.h>
36500 #include <linux/rtc.h>
36501 #include <linux/sched.h>
36502+#include <linux/grsecurity.h>
36503 #include "rtc-core.h"
36504
36505 static dev_t rtc_devt;
36506@@ -345,6 +346,8 @@ static long rtc_dev_ioctl(struct file *file,
36507 if (copy_from_user(&tm, uarg, sizeof(tm)))
36508 return -EFAULT;
36509
36510+ gr_log_timechange();
36511+
36512 return rtc_set_time(rtc, &tm);
36513
36514 case RTC_PIE_ON:
36515diff --git a/drivers/scsi/aacraid/aacraid.h b/drivers/scsi/aacraid/aacraid.h
36516index 9e933a8..4f969f7 100644
36517--- a/drivers/scsi/aacraid/aacraid.h
36518+++ b/drivers/scsi/aacraid/aacraid.h
36519@@ -503,7 +503,7 @@ struct adapter_ops
36520 int (*adapter_scsi)(struct fib * fib, struct scsi_cmnd * cmd);
36521 /* Administrative operations */
36522 int (*adapter_comm)(struct aac_dev * dev, int comm);
36523-};
36524+} __no_const;
36525
36526 /*
36527 * Define which interrupt handler needs to be installed
36528diff --git a/drivers/scsi/aacraid/linit.c b/drivers/scsi/aacraid/linit.c
36529index 7199534..cb7f158 100644
36530--- a/drivers/scsi/aacraid/linit.c
36531+++ b/drivers/scsi/aacraid/linit.c
36532@@ -93,7 +93,7 @@ static DECLARE_PCI_DEVICE_TABLE(aac_pci_tbl) = {
36533 #elif defined(__devinitconst)
36534 static const struct pci_device_id aac_pci_tbl[] __devinitconst = {
36535 #else
36536-static const struct pci_device_id aac_pci_tbl[] __devinitdata = {
36537+static const struct pci_device_id aac_pci_tbl[] __devinitconst = {
36538 #endif
36539 { 0x1028, 0x0001, 0x1028, 0x0001, 0, 0, 0 }, /* PERC 2/Si (Iguana/PERC2Si) */
36540 { 0x1028, 0x0002, 0x1028, 0x0002, 0, 0, 1 }, /* PERC 3/Di (Opal/PERC3Di) */
36541diff --git a/drivers/scsi/aic94xx/aic94xx_init.c b/drivers/scsi/aic94xx/aic94xx_init.c
36542index ff80552..1c4120c 100644
36543--- a/drivers/scsi/aic94xx/aic94xx_init.c
36544+++ b/drivers/scsi/aic94xx/aic94xx_init.c
36545@@ -1012,7 +1012,7 @@ static struct sas_domain_function_template aic94xx_transport_functions = {
36546 .lldd_ata_set_dmamode = asd_set_dmamode,
36547 };
36548
36549-static const struct pci_device_id aic94xx_pci_table[] __devinitdata = {
36550+static const struct pci_device_id aic94xx_pci_table[] __devinitconst = {
36551 {PCI_DEVICE(PCI_VENDOR_ID_ADAPTEC2, 0x410),0, 0, 1},
36552 {PCI_DEVICE(PCI_VENDOR_ID_ADAPTEC2, 0x412),0, 0, 1},
36553 {PCI_DEVICE(PCI_VENDOR_ID_ADAPTEC2, 0x416),0, 0, 1},
36554diff --git a/drivers/scsi/bfa/bfa.h b/drivers/scsi/bfa/bfa.h
36555index 4ad7e36..d004679 100644
36556--- a/drivers/scsi/bfa/bfa.h
36557+++ b/drivers/scsi/bfa/bfa.h
36558@@ -196,7 +196,7 @@ struct bfa_hwif_s {
36559 u32 *end);
36560 int cpe_vec_q0;
36561 int rme_vec_q0;
36562-};
36563+} __no_const;
36564 typedef void (*bfa_cb_iocfc_t) (void *cbarg, enum bfa_status status);
36565
36566 struct bfa_faa_cbfn_s {
36567diff --git a/drivers/scsi/bfa/bfa_fcpim.c b/drivers/scsi/bfa/bfa_fcpim.c
36568index f0f80e2..8ec946b 100644
36569--- a/drivers/scsi/bfa/bfa_fcpim.c
36570+++ b/drivers/scsi/bfa/bfa_fcpim.c
36571@@ -3715,7 +3715,7 @@ bfa_fcp_attach(struct bfa_s *bfa, void *bfad, struct bfa_iocfc_cfg_s *cfg,
36572
36573 bfa_iotag_attach(fcp);
36574
36575- fcp->itn_arr = (struct bfa_itn_s *) bfa_mem_kva_curp(fcp);
36576+ fcp->itn_arr = (bfa_itn_s_no_const *) bfa_mem_kva_curp(fcp);
36577 bfa_mem_kva_curp(fcp) = (u8 *)fcp->itn_arr +
36578 (fcp->num_itns * sizeof(struct bfa_itn_s));
36579 memset(fcp->itn_arr, 0,
36580@@ -3773,7 +3773,7 @@ bfa_itn_create(struct bfa_s *bfa, struct bfa_rport_s *rport,
36581 void (*isr)(struct bfa_s *bfa, struct bfi_msg_s *m))
36582 {
36583 struct bfa_fcp_mod_s *fcp = BFA_FCP_MOD(bfa);
36584- struct bfa_itn_s *itn;
36585+ bfa_itn_s_no_const *itn;
36586
36587 itn = BFA_ITN_FROM_TAG(fcp, rport->rport_tag);
36588 itn->isr = isr;
36589diff --git a/drivers/scsi/bfa/bfa_fcpim.h b/drivers/scsi/bfa/bfa_fcpim.h
36590index 36f26da..38a34a8 100644
36591--- a/drivers/scsi/bfa/bfa_fcpim.h
36592+++ b/drivers/scsi/bfa/bfa_fcpim.h
36593@@ -37,6 +37,7 @@ struct bfa_iotag_s {
36594 struct bfa_itn_s {
36595 bfa_isr_func_t isr;
36596 };
36597+typedef struct bfa_itn_s __no_const bfa_itn_s_no_const;
36598
36599 void bfa_itn_create(struct bfa_s *bfa, struct bfa_rport_s *rport,
36600 void (*isr)(struct bfa_s *bfa, struct bfi_msg_s *m));
36601@@ -147,7 +148,7 @@ struct bfa_fcp_mod_s {
36602 struct list_head iotag_tio_free_q; /* free IO resources */
36603 struct list_head iotag_unused_q; /* unused IO resources*/
36604 struct bfa_iotag_s *iotag_arr;
36605- struct bfa_itn_s *itn_arr;
36606+ bfa_itn_s_no_const *itn_arr;
36607 int num_ioim_reqs;
36608 int num_fwtio_reqs;
36609 int num_itns;
36610diff --git a/drivers/scsi/bfa/bfa_ioc.h b/drivers/scsi/bfa/bfa_ioc.h
36611index 1a99d4b..e85d64b 100644
36612--- a/drivers/scsi/bfa/bfa_ioc.h
36613+++ b/drivers/scsi/bfa/bfa_ioc.h
36614@@ -258,7 +258,7 @@ struct bfa_ioc_cbfn_s {
36615 bfa_ioc_disable_cbfn_t disable_cbfn;
36616 bfa_ioc_hbfail_cbfn_t hbfail_cbfn;
36617 bfa_ioc_reset_cbfn_t reset_cbfn;
36618-};
36619+} __no_const;
36620
36621 /*
36622 * IOC event notification mechanism.
36623@@ -346,7 +346,7 @@ struct bfa_ioc_hwif_s {
36624 void (*ioc_sync_ack) (struct bfa_ioc_s *ioc);
36625 bfa_boolean_t (*ioc_sync_complete) (struct bfa_ioc_s *ioc);
36626 bfa_boolean_t (*ioc_lpu_read_stat) (struct bfa_ioc_s *ioc);
36627-};
36628+} __no_const;
36629
36630 /*
36631 * Queue element to wait for room in request queue. FIFO order is
36632diff --git a/drivers/scsi/hosts.c b/drivers/scsi/hosts.c
36633index 593085a..47aa999 100644
36634--- a/drivers/scsi/hosts.c
36635+++ b/drivers/scsi/hosts.c
36636@@ -42,7 +42,7 @@
36637 #include "scsi_logging.h"
36638
36639
36640-static atomic_t scsi_host_next_hn = ATOMIC_INIT(0); /* host_no for next new host */
36641+static atomic_unchecked_t scsi_host_next_hn = ATOMIC_INIT(0); /* host_no for next new host */
36642
36643
36644 static void scsi_host_cls_release(struct device *dev)
36645@@ -361,7 +361,7 @@ struct Scsi_Host *scsi_host_alloc(struct scsi_host_template *sht, int privsize)
36646 * subtract one because we increment first then return, but we need to
36647 * know what the next host number was before increment
36648 */
36649- shost->host_no = atomic_inc_return(&scsi_host_next_hn) - 1;
36650+ shost->host_no = atomic_inc_return_unchecked(&scsi_host_next_hn) - 1;
36651 shost->dma_channel = 0xff;
36652
36653 /* These three are default values which can be overridden */
36654diff --git a/drivers/scsi/hpsa.c b/drivers/scsi/hpsa.c
36655index f9823f2..7bc3e81 100644
36656--- a/drivers/scsi/hpsa.c
36657+++ b/drivers/scsi/hpsa.c
36658@@ -536,7 +536,7 @@ static inline u32 next_command(struct ctlr_info *h, u8 q)
36659 unsigned long flags;
36660
36661 if (unlikely(!(h->transMethod & CFGTBL_Trans_Performant)))
36662- return h->access.command_completed(h, q);
36663+ return h->access->command_completed(h, q);
36664
36665 if ((rq->head[rq->current_entry] & 1) == rq->wraparound) {
36666 a = rq->head[rq->current_entry];
36667@@ -3355,7 +3355,7 @@ static void start_io(struct ctlr_info *h)
36668 while (!list_empty(&h->reqQ)) {
36669 c = list_entry(h->reqQ.next, struct CommandList, list);
36670 /* can't do anything if fifo is full */
36671- if ((h->access.fifo_full(h))) {
36672+ if ((h->access->fifo_full(h))) {
36673 dev_warn(&h->pdev->dev, "fifo full\n");
36674 break;
36675 }
36676@@ -3377,7 +3377,7 @@ static void start_io(struct ctlr_info *h)
36677
36678 /* Tell the controller execute command */
36679 spin_unlock_irqrestore(&h->lock, flags);
36680- h->access.submit_command(h, c);
36681+ h->access->submit_command(h, c);
36682 spin_lock_irqsave(&h->lock, flags);
36683 }
36684 spin_unlock_irqrestore(&h->lock, flags);
36685@@ -3385,17 +3385,17 @@ static void start_io(struct ctlr_info *h)
36686
36687 static inline unsigned long get_next_completion(struct ctlr_info *h, u8 q)
36688 {
36689- return h->access.command_completed(h, q);
36690+ return h->access->command_completed(h, q);
36691 }
36692
36693 static inline bool interrupt_pending(struct ctlr_info *h)
36694 {
36695- return h->access.intr_pending(h);
36696+ return h->access->intr_pending(h);
36697 }
36698
36699 static inline long interrupt_not_for_us(struct ctlr_info *h)
36700 {
36701- return (h->access.intr_pending(h) == 0) ||
36702+ return (h->access->intr_pending(h) == 0) ||
36703 (h->interrupts_enabled == 0);
36704 }
36705
36706@@ -4299,7 +4299,7 @@ static int __devinit hpsa_pci_init(struct ctlr_info *h)
36707 if (prod_index < 0)
36708 return -ENODEV;
36709 h->product_name = products[prod_index].product_name;
36710- h->access = *(products[prod_index].access);
36711+ h->access = products[prod_index].access;
36712
36713 pci_disable_link_state(h->pdev, PCIE_LINK_STATE_L0S |
36714 PCIE_LINK_STATE_L1 | PCIE_LINK_STATE_CLKPM);
36715@@ -4581,7 +4581,7 @@ static void controller_lockup_detected(struct ctlr_info *h)
36716
36717 assert_spin_locked(&lockup_detector_lock);
36718 remove_ctlr_from_lockup_detector_list(h);
36719- h->access.set_intr_mask(h, HPSA_INTR_OFF);
36720+ h->access->set_intr_mask(h, HPSA_INTR_OFF);
36721 spin_lock_irqsave(&h->lock, flags);
36722 h->lockup_detected = readl(h->vaddr + SA5_SCRATCHPAD_OFFSET);
36723 spin_unlock_irqrestore(&h->lock, flags);
36724@@ -4759,7 +4759,7 @@ reinit_after_soft_reset:
36725 }
36726
36727 /* make sure the board interrupts are off */
36728- h->access.set_intr_mask(h, HPSA_INTR_OFF);
36729+ h->access->set_intr_mask(h, HPSA_INTR_OFF);
36730
36731 if (hpsa_request_irq(h, do_hpsa_intr_msi, do_hpsa_intr_intx))
36732 goto clean2;
36733@@ -4793,7 +4793,7 @@ reinit_after_soft_reset:
36734 * fake ones to scoop up any residual completions.
36735 */
36736 spin_lock_irqsave(&h->lock, flags);
36737- h->access.set_intr_mask(h, HPSA_INTR_OFF);
36738+ h->access->set_intr_mask(h, HPSA_INTR_OFF);
36739 spin_unlock_irqrestore(&h->lock, flags);
36740 free_irqs(h);
36741 rc = hpsa_request_irq(h, hpsa_msix_discard_completions,
36742@@ -4812,9 +4812,9 @@ reinit_after_soft_reset:
36743 dev_info(&h->pdev->dev, "Board READY.\n");
36744 dev_info(&h->pdev->dev,
36745 "Waiting for stale completions to drain.\n");
36746- h->access.set_intr_mask(h, HPSA_INTR_ON);
36747+ h->access->set_intr_mask(h, HPSA_INTR_ON);
36748 msleep(10000);
36749- h->access.set_intr_mask(h, HPSA_INTR_OFF);
36750+ h->access->set_intr_mask(h, HPSA_INTR_OFF);
36751
36752 rc = controller_reset_failed(h->cfgtable);
36753 if (rc)
36754@@ -4835,7 +4835,7 @@ reinit_after_soft_reset:
36755 }
36756
36757 /* Turn the interrupts on so we can service requests */
36758- h->access.set_intr_mask(h, HPSA_INTR_ON);
36759+ h->access->set_intr_mask(h, HPSA_INTR_ON);
36760
36761 hpsa_hba_inquiry(h);
36762 hpsa_register_scsi(h); /* hook ourselves into SCSI subsystem */
36763@@ -4887,7 +4887,7 @@ static void hpsa_shutdown(struct pci_dev *pdev)
36764 * To write all data in the battery backed cache to disks
36765 */
36766 hpsa_flush_cache(h);
36767- h->access.set_intr_mask(h, HPSA_INTR_OFF);
36768+ h->access->set_intr_mask(h, HPSA_INTR_OFF);
36769 hpsa_free_irqs_and_disable_msix(h);
36770 }
36771
36772@@ -5056,7 +5056,7 @@ static __devinit void hpsa_enter_performant_mode(struct ctlr_info *h,
36773 return;
36774 }
36775 /* Change the access methods to the performant access methods */
36776- h->access = SA5_performant_access;
36777+ h->access = &SA5_performant_access;
36778 h->transMethod = CFGTBL_Trans_Performant;
36779 }
36780
36781diff --git a/drivers/scsi/hpsa.h b/drivers/scsi/hpsa.h
36782index 9816479..c5d4e97 100644
36783--- a/drivers/scsi/hpsa.h
36784+++ b/drivers/scsi/hpsa.h
36785@@ -79,7 +79,7 @@ struct ctlr_info {
36786 unsigned int msix_vector;
36787 unsigned int msi_vector;
36788 int intr_mode; /* either PERF_MODE_INT or SIMPLE_MODE_INT */
36789- struct access_method access;
36790+ struct access_method *access;
36791
36792 /* queue and queue Info */
36793 struct list_head reqQ;
36794diff --git a/drivers/scsi/ips.h b/drivers/scsi/ips.h
36795index f2df059..a3a9930 100644
36796--- a/drivers/scsi/ips.h
36797+++ b/drivers/scsi/ips.h
36798@@ -1027,7 +1027,7 @@ typedef struct {
36799 int (*intr)(struct ips_ha *);
36800 void (*enableint)(struct ips_ha *);
36801 uint32_t (*statupd)(struct ips_ha *);
36802-} ips_hw_func_t;
36803+} __no_const ips_hw_func_t;
36804
36805 typedef struct ips_ha {
36806 uint8_t ha_id[IPS_MAX_CHANNELS+1];
36807diff --git a/drivers/scsi/libfc/fc_exch.c b/drivers/scsi/libfc/fc_exch.c
36808index c772d8d..35c362c 100644
36809--- a/drivers/scsi/libfc/fc_exch.c
36810+++ b/drivers/scsi/libfc/fc_exch.c
36811@@ -100,12 +100,12 @@ struct fc_exch_mgr {
36812 u16 pool_max_index;
36813
36814 struct {
36815- atomic_t no_free_exch;
36816- atomic_t no_free_exch_xid;
36817- atomic_t xid_not_found;
36818- atomic_t xid_busy;
36819- atomic_t seq_not_found;
36820- atomic_t non_bls_resp;
36821+ atomic_unchecked_t no_free_exch;
36822+ atomic_unchecked_t no_free_exch_xid;
36823+ atomic_unchecked_t xid_not_found;
36824+ atomic_unchecked_t xid_busy;
36825+ atomic_unchecked_t seq_not_found;
36826+ atomic_unchecked_t non_bls_resp;
36827 } stats;
36828 };
36829
36830@@ -725,7 +725,7 @@ static struct fc_exch *fc_exch_em_alloc(struct fc_lport *lport,
36831 /* allocate memory for exchange */
36832 ep = mempool_alloc(mp->ep_pool, GFP_ATOMIC);
36833 if (!ep) {
36834- atomic_inc(&mp->stats.no_free_exch);
36835+ atomic_inc_unchecked(&mp->stats.no_free_exch);
36836 goto out;
36837 }
36838 memset(ep, 0, sizeof(*ep));
36839@@ -786,7 +786,7 @@ out:
36840 return ep;
36841 err:
36842 spin_unlock_bh(&pool->lock);
36843- atomic_inc(&mp->stats.no_free_exch_xid);
36844+ atomic_inc_unchecked(&mp->stats.no_free_exch_xid);
36845 mempool_free(ep, mp->ep_pool);
36846 return NULL;
36847 }
36848@@ -929,7 +929,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
36849 xid = ntohs(fh->fh_ox_id); /* we originated exch */
36850 ep = fc_exch_find(mp, xid);
36851 if (!ep) {
36852- atomic_inc(&mp->stats.xid_not_found);
36853+ atomic_inc_unchecked(&mp->stats.xid_not_found);
36854 reject = FC_RJT_OX_ID;
36855 goto out;
36856 }
36857@@ -959,7 +959,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
36858 ep = fc_exch_find(mp, xid);
36859 if ((f_ctl & FC_FC_FIRST_SEQ) && fc_sof_is_init(fr_sof(fp))) {
36860 if (ep) {
36861- atomic_inc(&mp->stats.xid_busy);
36862+ atomic_inc_unchecked(&mp->stats.xid_busy);
36863 reject = FC_RJT_RX_ID;
36864 goto rel;
36865 }
36866@@ -970,7 +970,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
36867 }
36868 xid = ep->xid; /* get our XID */
36869 } else if (!ep) {
36870- atomic_inc(&mp->stats.xid_not_found);
36871+ atomic_inc_unchecked(&mp->stats.xid_not_found);
36872 reject = FC_RJT_RX_ID; /* XID not found */
36873 goto out;
36874 }
36875@@ -987,7 +987,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
36876 } else {
36877 sp = &ep->seq;
36878 if (sp->id != fh->fh_seq_id) {
36879- atomic_inc(&mp->stats.seq_not_found);
36880+ atomic_inc_unchecked(&mp->stats.seq_not_found);
36881 if (f_ctl & FC_FC_END_SEQ) {
36882 /*
36883 * Update sequence_id based on incoming last
36884@@ -1437,22 +1437,22 @@ static void fc_exch_recv_seq_resp(struct fc_exch_mgr *mp, struct fc_frame *fp)
36885
36886 ep = fc_exch_find(mp, ntohs(fh->fh_ox_id));
36887 if (!ep) {
36888- atomic_inc(&mp->stats.xid_not_found);
36889+ atomic_inc_unchecked(&mp->stats.xid_not_found);
36890 goto out;
36891 }
36892 if (ep->esb_stat & ESB_ST_COMPLETE) {
36893- atomic_inc(&mp->stats.xid_not_found);
36894+ atomic_inc_unchecked(&mp->stats.xid_not_found);
36895 goto rel;
36896 }
36897 if (ep->rxid == FC_XID_UNKNOWN)
36898 ep->rxid = ntohs(fh->fh_rx_id);
36899 if (ep->sid != 0 && ep->sid != ntoh24(fh->fh_d_id)) {
36900- atomic_inc(&mp->stats.xid_not_found);
36901+ atomic_inc_unchecked(&mp->stats.xid_not_found);
36902 goto rel;
36903 }
36904 if (ep->did != ntoh24(fh->fh_s_id) &&
36905 ep->did != FC_FID_FLOGI) {
36906- atomic_inc(&mp->stats.xid_not_found);
36907+ atomic_inc_unchecked(&mp->stats.xid_not_found);
36908 goto rel;
36909 }
36910 sof = fr_sof(fp);
36911@@ -1461,7 +1461,7 @@ static void fc_exch_recv_seq_resp(struct fc_exch_mgr *mp, struct fc_frame *fp)
36912 sp->ssb_stat |= SSB_ST_RESP;
36913 sp->id = fh->fh_seq_id;
36914 } else if (sp->id != fh->fh_seq_id) {
36915- atomic_inc(&mp->stats.seq_not_found);
36916+ atomic_inc_unchecked(&mp->stats.seq_not_found);
36917 goto rel;
36918 }
36919
36920@@ -1525,9 +1525,9 @@ static void fc_exch_recv_resp(struct fc_exch_mgr *mp, struct fc_frame *fp)
36921 sp = fc_seq_lookup_orig(mp, fp); /* doesn't hold sequence */
36922
36923 if (!sp)
36924- atomic_inc(&mp->stats.xid_not_found);
36925+ atomic_inc_unchecked(&mp->stats.xid_not_found);
36926 else
36927- atomic_inc(&mp->stats.non_bls_resp);
36928+ atomic_inc_unchecked(&mp->stats.non_bls_resp);
36929
36930 fc_frame_free(fp);
36931 }
36932@@ -2174,13 +2174,13 @@ void fc_exch_update_stats(struct fc_lport *lport)
36933
36934 list_for_each_entry(ema, &lport->ema_list, ema_list) {
36935 mp = ema->mp;
36936- st->fc_no_free_exch += atomic_read(&mp->stats.no_free_exch);
36937+ st->fc_no_free_exch += atomic_read_unchecked(&mp->stats.no_free_exch);
36938 st->fc_no_free_exch_xid +=
36939- atomic_read(&mp->stats.no_free_exch_xid);
36940- st->fc_xid_not_found += atomic_read(&mp->stats.xid_not_found);
36941- st->fc_xid_busy += atomic_read(&mp->stats.xid_busy);
36942- st->fc_seq_not_found += atomic_read(&mp->stats.seq_not_found);
36943- st->fc_non_bls_resp += atomic_read(&mp->stats.non_bls_resp);
36944+ atomic_read_unchecked(&mp->stats.no_free_exch_xid);
36945+ st->fc_xid_not_found += atomic_read_unchecked(&mp->stats.xid_not_found);
36946+ st->fc_xid_busy += atomic_read_unchecked(&mp->stats.xid_busy);
36947+ st->fc_seq_not_found += atomic_read_unchecked(&mp->stats.seq_not_found);
36948+ st->fc_non_bls_resp += atomic_read_unchecked(&mp->stats.non_bls_resp);
36949 }
36950 }
36951 EXPORT_SYMBOL(fc_exch_update_stats);
36952diff --git a/drivers/scsi/libsas/sas_ata.c b/drivers/scsi/libsas/sas_ata.c
36953index a59fcdc..abe55f3 100644
36954--- a/drivers/scsi/libsas/sas_ata.c
36955+++ b/drivers/scsi/libsas/sas_ata.c
36956@@ -554,7 +554,7 @@ static struct ata_port_operations sas_sata_ops = {
36957 .postreset = ata_std_postreset,
36958 .error_handler = ata_std_error_handler,
36959 .post_internal_cmd = sas_ata_post_internal,
36960- .qc_defer = ata_std_qc_defer,
36961+ .qc_defer = ata_std_qc_defer,
36962 .qc_prep = ata_noop_qc_prep,
36963 .qc_issue = sas_ata_qc_issue,
36964 .qc_fill_rtf = sas_ata_qc_fill_rtf,
36965diff --git a/drivers/scsi/lpfc/lpfc.h b/drivers/scsi/lpfc/lpfc.h
36966index a65c05a..a39e402 100644
36967--- a/drivers/scsi/lpfc/lpfc.h
36968+++ b/drivers/scsi/lpfc/lpfc.h
36969@@ -420,7 +420,7 @@ struct lpfc_vport {
36970 struct dentry *debug_nodelist;
36971 struct dentry *vport_debugfs_root;
36972 struct lpfc_debugfs_trc *disc_trc;
36973- atomic_t disc_trc_cnt;
36974+ atomic_unchecked_t disc_trc_cnt;
36975 #endif
36976 uint8_t stat_data_enabled;
36977 uint8_t stat_data_blocked;
36978@@ -834,8 +834,8 @@ struct lpfc_hba {
36979 struct timer_list fabric_block_timer;
36980 unsigned long bit_flags;
36981 #define FABRIC_COMANDS_BLOCKED 0
36982- atomic_t num_rsrc_err;
36983- atomic_t num_cmd_success;
36984+ atomic_unchecked_t num_rsrc_err;
36985+ atomic_unchecked_t num_cmd_success;
36986 unsigned long last_rsrc_error_time;
36987 unsigned long last_ramp_down_time;
36988 unsigned long last_ramp_up_time;
36989@@ -871,7 +871,7 @@ struct lpfc_hba {
36990
36991 struct dentry *debug_slow_ring_trc;
36992 struct lpfc_debugfs_trc *slow_ring_trc;
36993- atomic_t slow_ring_trc_cnt;
36994+ atomic_unchecked_t slow_ring_trc_cnt;
36995 /* iDiag debugfs sub-directory */
36996 struct dentry *idiag_root;
36997 struct dentry *idiag_pci_cfg;
36998diff --git a/drivers/scsi/lpfc/lpfc_debugfs.c b/drivers/scsi/lpfc/lpfc_debugfs.c
36999index 3217d63..c417981 100644
37000--- a/drivers/scsi/lpfc/lpfc_debugfs.c
37001+++ b/drivers/scsi/lpfc/lpfc_debugfs.c
37002@@ -106,7 +106,7 @@ MODULE_PARM_DESC(lpfc_debugfs_mask_disc_trc,
37003
37004 #include <linux/debugfs.h>
37005
37006-static atomic_t lpfc_debugfs_seq_trc_cnt = ATOMIC_INIT(0);
37007+static atomic_unchecked_t lpfc_debugfs_seq_trc_cnt = ATOMIC_INIT(0);
37008 static unsigned long lpfc_debugfs_start_time = 0L;
37009
37010 /* iDiag */
37011@@ -147,7 +147,7 @@ lpfc_debugfs_disc_trc_data(struct lpfc_vport *vport, char *buf, int size)
37012 lpfc_debugfs_enable = 0;
37013
37014 len = 0;
37015- index = (atomic_read(&vport->disc_trc_cnt) + 1) &
37016+ index = (atomic_read_unchecked(&vport->disc_trc_cnt) + 1) &
37017 (lpfc_debugfs_max_disc_trc - 1);
37018 for (i = index; i < lpfc_debugfs_max_disc_trc; i++) {
37019 dtp = vport->disc_trc + i;
37020@@ -213,7 +213,7 @@ lpfc_debugfs_slow_ring_trc_data(struct lpfc_hba *phba, char *buf, int size)
37021 lpfc_debugfs_enable = 0;
37022
37023 len = 0;
37024- index = (atomic_read(&phba->slow_ring_trc_cnt) + 1) &
37025+ index = (atomic_read_unchecked(&phba->slow_ring_trc_cnt) + 1) &
37026 (lpfc_debugfs_max_slow_ring_trc - 1);
37027 for (i = index; i < lpfc_debugfs_max_slow_ring_trc; i++) {
37028 dtp = phba->slow_ring_trc + i;
37029@@ -636,14 +636,14 @@ lpfc_debugfs_disc_trc(struct lpfc_vport *vport, int mask, char *fmt,
37030 !vport || !vport->disc_trc)
37031 return;
37032
37033- index = atomic_inc_return(&vport->disc_trc_cnt) &
37034+ index = atomic_inc_return_unchecked(&vport->disc_trc_cnt) &
37035 (lpfc_debugfs_max_disc_trc - 1);
37036 dtp = vport->disc_trc + index;
37037 dtp->fmt = fmt;
37038 dtp->data1 = data1;
37039 dtp->data2 = data2;
37040 dtp->data3 = data3;
37041- dtp->seq_cnt = atomic_inc_return(&lpfc_debugfs_seq_trc_cnt);
37042+ dtp->seq_cnt = atomic_inc_return_unchecked(&lpfc_debugfs_seq_trc_cnt);
37043 dtp->jif = jiffies;
37044 #endif
37045 return;
37046@@ -674,14 +674,14 @@ lpfc_debugfs_slow_ring_trc(struct lpfc_hba *phba, char *fmt,
37047 !phba || !phba->slow_ring_trc)
37048 return;
37049
37050- index = atomic_inc_return(&phba->slow_ring_trc_cnt) &
37051+ index = atomic_inc_return_unchecked(&phba->slow_ring_trc_cnt) &
37052 (lpfc_debugfs_max_slow_ring_trc - 1);
37053 dtp = phba->slow_ring_trc + index;
37054 dtp->fmt = fmt;
37055 dtp->data1 = data1;
37056 dtp->data2 = data2;
37057 dtp->data3 = data3;
37058- dtp->seq_cnt = atomic_inc_return(&lpfc_debugfs_seq_trc_cnt);
37059+ dtp->seq_cnt = atomic_inc_return_unchecked(&lpfc_debugfs_seq_trc_cnt);
37060 dtp->jif = jiffies;
37061 #endif
37062 return;
37063@@ -4090,7 +4090,7 @@ lpfc_debugfs_initialize(struct lpfc_vport *vport)
37064 "slow_ring buffer\n");
37065 goto debug_failed;
37066 }
37067- atomic_set(&phba->slow_ring_trc_cnt, 0);
37068+ atomic_set_unchecked(&phba->slow_ring_trc_cnt, 0);
37069 memset(phba->slow_ring_trc, 0,
37070 (sizeof(struct lpfc_debugfs_trc) *
37071 lpfc_debugfs_max_slow_ring_trc));
37072@@ -4136,7 +4136,7 @@ lpfc_debugfs_initialize(struct lpfc_vport *vport)
37073 "buffer\n");
37074 goto debug_failed;
37075 }
37076- atomic_set(&vport->disc_trc_cnt, 0);
37077+ atomic_set_unchecked(&vport->disc_trc_cnt, 0);
37078
37079 snprintf(name, sizeof(name), "discovery_trace");
37080 vport->debug_disc_trc =
37081diff --git a/drivers/scsi/lpfc/lpfc_init.c b/drivers/scsi/lpfc/lpfc_init.c
37082index 45c1520..35ba744 100644
37083--- a/drivers/scsi/lpfc/lpfc_init.c
37084+++ b/drivers/scsi/lpfc/lpfc_init.c
37085@@ -10478,8 +10478,10 @@ lpfc_init(void)
37086 "misc_register returned with status %d", error);
37087
37088 if (lpfc_enable_npiv) {
37089- lpfc_transport_functions.vport_create = lpfc_vport_create;
37090- lpfc_transport_functions.vport_delete = lpfc_vport_delete;
37091+ pax_open_kernel();
37092+ *(void **)&lpfc_transport_functions.vport_create = lpfc_vport_create;
37093+ *(void **)&lpfc_transport_functions.vport_delete = lpfc_vport_delete;
37094+ pax_close_kernel();
37095 }
37096 lpfc_transport_template =
37097 fc_attach_transport(&lpfc_transport_functions);
37098diff --git a/drivers/scsi/lpfc/lpfc_scsi.c b/drivers/scsi/lpfc/lpfc_scsi.c
37099index 925975d..0f1fc07 100644
37100--- a/drivers/scsi/lpfc/lpfc_scsi.c
37101+++ b/drivers/scsi/lpfc/lpfc_scsi.c
37102@@ -311,7 +311,7 @@ lpfc_rampdown_queue_depth(struct lpfc_hba *phba)
37103 uint32_t evt_posted;
37104
37105 spin_lock_irqsave(&phba->hbalock, flags);
37106- atomic_inc(&phba->num_rsrc_err);
37107+ atomic_inc_unchecked(&phba->num_rsrc_err);
37108 phba->last_rsrc_error_time = jiffies;
37109
37110 if ((phba->last_ramp_down_time + QUEUE_RAMP_DOWN_INTERVAL) > jiffies) {
37111@@ -352,7 +352,7 @@ lpfc_rampup_queue_depth(struct lpfc_vport *vport,
37112 unsigned long flags;
37113 struct lpfc_hba *phba = vport->phba;
37114 uint32_t evt_posted;
37115- atomic_inc(&phba->num_cmd_success);
37116+ atomic_inc_unchecked(&phba->num_cmd_success);
37117
37118 if (vport->cfg_lun_queue_depth <= queue_depth)
37119 return;
37120@@ -396,8 +396,8 @@ lpfc_ramp_down_queue_handler(struct lpfc_hba *phba)
37121 unsigned long num_rsrc_err, num_cmd_success;
37122 int i;
37123
37124- num_rsrc_err = atomic_read(&phba->num_rsrc_err);
37125- num_cmd_success = atomic_read(&phba->num_cmd_success);
37126+ num_rsrc_err = atomic_read_unchecked(&phba->num_rsrc_err);
37127+ num_cmd_success = atomic_read_unchecked(&phba->num_cmd_success);
37128
37129 /*
37130 * The error and success command counters are global per
37131@@ -425,8 +425,8 @@ lpfc_ramp_down_queue_handler(struct lpfc_hba *phba)
37132 }
37133 }
37134 lpfc_destroy_vport_work_array(phba, vports);
37135- atomic_set(&phba->num_rsrc_err, 0);
37136- atomic_set(&phba->num_cmd_success, 0);
37137+ atomic_set_unchecked(&phba->num_rsrc_err, 0);
37138+ atomic_set_unchecked(&phba->num_cmd_success, 0);
37139 }
37140
37141 /**
37142@@ -460,8 +460,8 @@ lpfc_ramp_up_queue_handler(struct lpfc_hba *phba)
37143 }
37144 }
37145 lpfc_destroy_vport_work_array(phba, vports);
37146- atomic_set(&phba->num_rsrc_err, 0);
37147- atomic_set(&phba->num_cmd_success, 0);
37148+ atomic_set_unchecked(&phba->num_rsrc_err, 0);
37149+ atomic_set_unchecked(&phba->num_cmd_success, 0);
37150 }
37151
37152 /**
37153diff --git a/drivers/scsi/pmcraid.c b/drivers/scsi/pmcraid.c
37154index ea8a0b4..812a124 100644
37155--- a/drivers/scsi/pmcraid.c
37156+++ b/drivers/scsi/pmcraid.c
37157@@ -200,8 +200,8 @@ static int pmcraid_slave_alloc(struct scsi_device *scsi_dev)
37158 res->scsi_dev = scsi_dev;
37159 scsi_dev->hostdata = res;
37160 res->change_detected = 0;
37161- atomic_set(&res->read_failures, 0);
37162- atomic_set(&res->write_failures, 0);
37163+ atomic_set_unchecked(&res->read_failures, 0);
37164+ atomic_set_unchecked(&res->write_failures, 0);
37165 rc = 0;
37166 }
37167 spin_unlock_irqrestore(&pinstance->resource_lock, lock_flags);
37168@@ -2676,9 +2676,9 @@ static int pmcraid_error_handler(struct pmcraid_cmd *cmd)
37169
37170 /* If this was a SCSI read/write command keep count of errors */
37171 if (SCSI_CMD_TYPE(scsi_cmd->cmnd[0]) == SCSI_READ_CMD)
37172- atomic_inc(&res->read_failures);
37173+ atomic_inc_unchecked(&res->read_failures);
37174 else if (SCSI_CMD_TYPE(scsi_cmd->cmnd[0]) == SCSI_WRITE_CMD)
37175- atomic_inc(&res->write_failures);
37176+ atomic_inc_unchecked(&res->write_failures);
37177
37178 if (!RES_IS_GSCSI(res->cfg_entry) &&
37179 masked_ioasc != PMCRAID_IOASC_HW_DEVICE_BUS_STATUS_ERROR) {
37180@@ -3534,7 +3534,7 @@ static int pmcraid_queuecommand_lck(
37181 * block of scsi_cmd which is re-used (e.g. cancel/abort), which uses
37182 * hrrq_id assigned here in queuecommand
37183 */
37184- ioarcb->hrrq_id = atomic_add_return(1, &(pinstance->last_message_id)) %
37185+ ioarcb->hrrq_id = atomic_add_return_unchecked(1, &(pinstance->last_message_id)) %
37186 pinstance->num_hrrq;
37187 cmd->cmd_done = pmcraid_io_done;
37188
37189@@ -3859,7 +3859,7 @@ static long pmcraid_ioctl_passthrough(
37190 * block of scsi_cmd which is re-used (e.g. cancel/abort), which uses
37191 * hrrq_id assigned here in queuecommand
37192 */
37193- ioarcb->hrrq_id = atomic_add_return(1, &(pinstance->last_message_id)) %
37194+ ioarcb->hrrq_id = atomic_add_return_unchecked(1, &(pinstance->last_message_id)) %
37195 pinstance->num_hrrq;
37196
37197 if (request_size) {
37198@@ -4497,7 +4497,7 @@ static void pmcraid_worker_function(struct work_struct *workp)
37199
37200 pinstance = container_of(workp, struct pmcraid_instance, worker_q);
37201 /* add resources only after host is added into system */
37202- if (!atomic_read(&pinstance->expose_resources))
37203+ if (!atomic_read_unchecked(&pinstance->expose_resources))
37204 return;
37205
37206 fw_version = be16_to_cpu(pinstance->inq_data->fw_version);
37207@@ -5331,8 +5331,8 @@ static int __devinit pmcraid_init_instance(
37208 init_waitqueue_head(&pinstance->reset_wait_q);
37209
37210 atomic_set(&pinstance->outstanding_cmds, 0);
37211- atomic_set(&pinstance->last_message_id, 0);
37212- atomic_set(&pinstance->expose_resources, 0);
37213+ atomic_set_unchecked(&pinstance->last_message_id, 0);
37214+ atomic_set_unchecked(&pinstance->expose_resources, 0);
37215
37216 INIT_LIST_HEAD(&pinstance->free_res_q);
37217 INIT_LIST_HEAD(&pinstance->used_res_q);
37218@@ -6047,7 +6047,7 @@ static int __devinit pmcraid_probe(
37219 /* Schedule worker thread to handle CCN and take care of adding and
37220 * removing devices to OS
37221 */
37222- atomic_set(&pinstance->expose_resources, 1);
37223+ atomic_set_unchecked(&pinstance->expose_resources, 1);
37224 schedule_work(&pinstance->worker_q);
37225 return rc;
37226
37227diff --git a/drivers/scsi/pmcraid.h b/drivers/scsi/pmcraid.h
37228index e1d150f..6c6df44 100644
37229--- a/drivers/scsi/pmcraid.h
37230+++ b/drivers/scsi/pmcraid.h
37231@@ -748,7 +748,7 @@ struct pmcraid_instance {
37232 struct pmcraid_isr_param hrrq_vector[PMCRAID_NUM_MSIX_VECTORS];
37233
37234 /* Message id as filled in last fired IOARCB, used to identify HRRQ */
37235- atomic_t last_message_id;
37236+ atomic_unchecked_t last_message_id;
37237
37238 /* configuration table */
37239 struct pmcraid_config_table *cfg_table;
37240@@ -777,7 +777,7 @@ struct pmcraid_instance {
37241 atomic_t outstanding_cmds;
37242
37243 /* should add/delete resources to mid-layer now ?*/
37244- atomic_t expose_resources;
37245+ atomic_unchecked_t expose_resources;
37246
37247
37248
37249@@ -813,8 +813,8 @@ struct pmcraid_resource_entry {
37250 struct pmcraid_config_table_entry_ext cfg_entry_ext;
37251 };
37252 struct scsi_device *scsi_dev; /* Link scsi_device structure */
37253- atomic_t read_failures; /* count of failed READ commands */
37254- atomic_t write_failures; /* count of failed WRITE commands */
37255+ atomic_unchecked_t read_failures; /* count of failed READ commands */
37256+ atomic_unchecked_t write_failures; /* count of failed WRITE commands */
37257
37258 /* To indicate add/delete/modify during CCN */
37259 u8 change_detected;
37260diff --git a/drivers/scsi/qla2xxx/qla_attr.c b/drivers/scsi/qla2xxx/qla_attr.c
37261index 5ab9530..2dd80f7 100644
37262--- a/drivers/scsi/qla2xxx/qla_attr.c
37263+++ b/drivers/scsi/qla2xxx/qla_attr.c
37264@@ -1855,7 +1855,7 @@ qla24xx_vport_disable(struct fc_vport *fc_vport, bool disable)
37265 return 0;
37266 }
37267
37268-struct fc_function_template qla2xxx_transport_functions = {
37269+fc_function_template_no_const qla2xxx_transport_functions = {
37270
37271 .show_host_node_name = 1,
37272 .show_host_port_name = 1,
37273@@ -1902,7 +1902,7 @@ struct fc_function_template qla2xxx_transport_functions = {
37274 .bsg_timeout = qla24xx_bsg_timeout,
37275 };
37276
37277-struct fc_function_template qla2xxx_transport_vport_functions = {
37278+fc_function_template_no_const qla2xxx_transport_vport_functions = {
37279
37280 .show_host_node_name = 1,
37281 .show_host_port_name = 1,
37282diff --git a/drivers/scsi/qla2xxx/qla_def.h b/drivers/scsi/qla2xxx/qla_def.h
37283index 39007f5..7fafc64 100644
37284--- a/drivers/scsi/qla2xxx/qla_def.h
37285+++ b/drivers/scsi/qla2xxx/qla_def.h
37286@@ -2284,7 +2284,7 @@ struct isp_operations {
37287 int (*start_scsi) (srb_t *);
37288 int (*abort_isp) (struct scsi_qla_host *);
37289 int (*iospace_config)(struct qla_hw_data*);
37290-};
37291+} __no_const;
37292
37293 /* MSI-X Support *************************************************************/
37294
37295diff --git a/drivers/scsi/qla2xxx/qla_gbl.h b/drivers/scsi/qla2xxx/qla_gbl.h
37296index 9eacd2d..d79629c 100644
37297--- a/drivers/scsi/qla2xxx/qla_gbl.h
37298+++ b/drivers/scsi/qla2xxx/qla_gbl.h
37299@@ -484,8 +484,8 @@ extern void qla2x00_get_sym_node_name(scsi_qla_host_t *, uint8_t *);
37300 struct device_attribute;
37301 extern struct device_attribute *qla2x00_host_attrs[];
37302 struct fc_function_template;
37303-extern struct fc_function_template qla2xxx_transport_functions;
37304-extern struct fc_function_template qla2xxx_transport_vport_functions;
37305+extern fc_function_template_no_const qla2xxx_transport_functions;
37306+extern fc_function_template_no_const qla2xxx_transport_vport_functions;
37307 extern void qla2x00_alloc_sysfs_attr(scsi_qla_host_t *);
37308 extern void qla2x00_free_sysfs_attr(scsi_qla_host_t *);
37309 extern void qla2x00_init_host_attr(scsi_qla_host_t *);
37310diff --git a/drivers/scsi/qla4xxx/ql4_def.h b/drivers/scsi/qla4xxx/ql4_def.h
37311index 7fdba7f..1b4b2c2 100644
37312--- a/drivers/scsi/qla4xxx/ql4_def.h
37313+++ b/drivers/scsi/qla4xxx/ql4_def.h
37314@@ -268,7 +268,7 @@ struct ddb_entry {
37315 * (4000 only) */
37316 atomic_t relogin_timer; /* Max Time to wait for
37317 * relogin to complete */
37318- atomic_t relogin_retry_count; /* Num of times relogin has been
37319+ atomic_unchecked_t relogin_retry_count; /* Num of times relogin has been
37320 * retried */
37321 uint32_t default_time2wait; /* Default Min time between
37322 * relogins (+aens) */
37323diff --git a/drivers/scsi/qla4xxx/ql4_os.c b/drivers/scsi/qla4xxx/ql4_os.c
37324index 9da4266..377b3b6 100644
37325--- a/drivers/scsi/qla4xxx/ql4_os.c
37326+++ b/drivers/scsi/qla4xxx/ql4_os.c
37327@@ -2615,12 +2615,12 @@ static void qla4xxx_check_relogin_flash_ddb(struct iscsi_cls_session *cls_sess)
37328 */
37329 if (!iscsi_is_session_online(cls_sess)) {
37330 /* Reset retry relogin timer */
37331- atomic_inc(&ddb_entry->relogin_retry_count);
37332+ atomic_inc_unchecked(&ddb_entry->relogin_retry_count);
37333 DEBUG2(ql4_printk(KERN_INFO, ha,
37334 "%s: index[%d] relogin timed out-retrying"
37335 " relogin (%d), retry (%d)\n", __func__,
37336 ddb_entry->fw_ddb_index,
37337- atomic_read(&ddb_entry->relogin_retry_count),
37338+ atomic_read_unchecked(&ddb_entry->relogin_retry_count),
37339 ddb_entry->default_time2wait + 4));
37340 set_bit(DPC_RELOGIN_DEVICE, &ha->dpc_flags);
37341 atomic_set(&ddb_entry->retry_relogin_timer,
37342@@ -4635,7 +4635,7 @@ static void qla4xxx_setup_flash_ddb_entry(struct scsi_qla_host *ha,
37343
37344 atomic_set(&ddb_entry->retry_relogin_timer, INVALID_ENTRY);
37345 atomic_set(&ddb_entry->relogin_timer, 0);
37346- atomic_set(&ddb_entry->relogin_retry_count, 0);
37347+ atomic_set_unchecked(&ddb_entry->relogin_retry_count, 0);
37348 def_timeout = le16_to_cpu(ddb_entry->fw_ddb_entry.def_timeout);
37349 ddb_entry->default_relogin_timeout =
37350 (def_timeout > LOGIN_TOV) && (def_timeout < LOGIN_TOV * 10) ?
37351diff --git a/drivers/scsi/scsi.c b/drivers/scsi/scsi.c
37352index 2936b44..546ecdb 100644
37353--- a/drivers/scsi/scsi.c
37354+++ b/drivers/scsi/scsi.c
37355@@ -660,7 +660,7 @@ int scsi_dispatch_cmd(struct scsi_cmnd *cmd)
37356 unsigned long timeout;
37357 int rtn = 0;
37358
37359- atomic_inc(&cmd->device->iorequest_cnt);
37360+ atomic_inc_unchecked(&cmd->device->iorequest_cnt);
37361
37362 /* check if the device is still usable */
37363 if (unlikely(cmd->device->sdev_state == SDEV_DEL)) {
37364diff --git a/drivers/scsi/scsi_lib.c b/drivers/scsi/scsi_lib.c
37365index faa790f..7e351ddd 100644
37366--- a/drivers/scsi/scsi_lib.c
37367+++ b/drivers/scsi/scsi_lib.c
37368@@ -1442,7 +1442,7 @@ static void scsi_kill_request(struct request *req, struct request_queue *q)
37369 shost = sdev->host;
37370 scsi_init_cmd_errh(cmd);
37371 cmd->result = DID_NO_CONNECT << 16;
37372- atomic_inc(&cmd->device->iorequest_cnt);
37373+ atomic_inc_unchecked(&cmd->device->iorequest_cnt);
37374
37375 /*
37376 * SCSI request completion path will do scsi_device_unbusy(),
37377@@ -1468,9 +1468,9 @@ static void scsi_softirq_done(struct request *rq)
37378
37379 INIT_LIST_HEAD(&cmd->eh_entry);
37380
37381- atomic_inc(&cmd->device->iodone_cnt);
37382+ atomic_inc_unchecked(&cmd->device->iodone_cnt);
37383 if (cmd->result)
37384- atomic_inc(&cmd->device->ioerr_cnt);
37385+ atomic_inc_unchecked(&cmd->device->ioerr_cnt);
37386
37387 disposition = scsi_decide_disposition(cmd);
37388 if (disposition != SUCCESS &&
37389diff --git a/drivers/scsi/scsi_sysfs.c b/drivers/scsi/scsi_sysfs.c
37390index ce5224c..8c6d071 100644
37391--- a/drivers/scsi/scsi_sysfs.c
37392+++ b/drivers/scsi/scsi_sysfs.c
37393@@ -661,7 +661,7 @@ show_iostat_##field(struct device *dev, struct device_attribute *attr, \
37394 char *buf) \
37395 { \
37396 struct scsi_device *sdev = to_scsi_device(dev); \
37397- unsigned long long count = atomic_read(&sdev->field); \
37398+ unsigned long long count = atomic_read_unchecked(&sdev->field); \
37399 return snprintf(buf, 20, "0x%llx\n", count); \
37400 } \
37401 static DEVICE_ATTR(field, S_IRUGO, show_iostat_##field, NULL)
37402diff --git a/drivers/scsi/scsi_tgt_lib.c b/drivers/scsi/scsi_tgt_lib.c
37403index 84a1fdf..693b0d6 100644
37404--- a/drivers/scsi/scsi_tgt_lib.c
37405+++ b/drivers/scsi/scsi_tgt_lib.c
37406@@ -362,7 +362,7 @@ static int scsi_map_user_pages(struct scsi_tgt_cmd *tcmd, struct scsi_cmnd *cmd,
37407 int err;
37408
37409 dprintk("%lx %u\n", uaddr, len);
37410- err = blk_rq_map_user(q, rq, NULL, (void *)uaddr, len, GFP_KERNEL);
37411+ err = blk_rq_map_user(q, rq, NULL, (void __user *)uaddr, len, GFP_KERNEL);
37412 if (err) {
37413 /*
37414 * TODO: need to fixup sg_tablesize, max_segment_size,
37415diff --git a/drivers/scsi/scsi_transport_fc.c b/drivers/scsi/scsi_transport_fc.c
37416index e894ca7..de9d7660 100644
37417--- a/drivers/scsi/scsi_transport_fc.c
37418+++ b/drivers/scsi/scsi_transport_fc.c
37419@@ -498,7 +498,7 @@ static DECLARE_TRANSPORT_CLASS(fc_vport_class,
37420 * Netlink Infrastructure
37421 */
37422
37423-static atomic_t fc_event_seq;
37424+static atomic_unchecked_t fc_event_seq;
37425
37426 /**
37427 * fc_get_event_number - Obtain the next sequential FC event number
37428@@ -511,7 +511,7 @@ static atomic_t fc_event_seq;
37429 u32
37430 fc_get_event_number(void)
37431 {
37432- return atomic_add_return(1, &fc_event_seq);
37433+ return atomic_add_return_unchecked(1, &fc_event_seq);
37434 }
37435 EXPORT_SYMBOL(fc_get_event_number);
37436
37437@@ -659,7 +659,7 @@ static __init int fc_transport_init(void)
37438 {
37439 int error;
37440
37441- atomic_set(&fc_event_seq, 0);
37442+ atomic_set_unchecked(&fc_event_seq, 0);
37443
37444 error = transport_class_register(&fc_host_class);
37445 if (error)
37446@@ -849,7 +849,7 @@ static int fc_str_to_dev_loss(const char *buf, unsigned long *val)
37447 char *cp;
37448
37449 *val = simple_strtoul(buf, &cp, 0);
37450- if ((*cp && (*cp != '\n')) || (*val < 0))
37451+ if (*cp && (*cp != '\n'))
37452 return -EINVAL;
37453 /*
37454 * Check for overflow; dev_loss_tmo is u32
37455diff --git a/drivers/scsi/scsi_transport_iscsi.c b/drivers/scsi/scsi_transport_iscsi.c
37456index fa1dfaa..4bb620c 100644
37457--- a/drivers/scsi/scsi_transport_iscsi.c
37458+++ b/drivers/scsi/scsi_transport_iscsi.c
37459@@ -79,7 +79,7 @@ struct iscsi_internal {
37460 struct transport_container session_cont;
37461 };
37462
37463-static atomic_t iscsi_session_nr; /* sysfs session id for next new session */
37464+static atomic_unchecked_t iscsi_session_nr; /* sysfs session id for next new session */
37465 static struct workqueue_struct *iscsi_eh_timer_workq;
37466
37467 static DEFINE_IDA(iscsi_sess_ida);
37468@@ -1064,7 +1064,7 @@ int iscsi_add_session(struct iscsi_cls_session *session, unsigned int target_id)
37469 int err;
37470
37471 ihost = shost->shost_data;
37472- session->sid = atomic_add_return(1, &iscsi_session_nr);
37473+ session->sid = atomic_add_return_unchecked(1, &iscsi_session_nr);
37474
37475 if (target_id == ISCSI_MAX_TARGET) {
37476 id = ida_simple_get(&iscsi_sess_ida, 0, 0, GFP_KERNEL);
37477@@ -2943,7 +2943,7 @@ static __init int iscsi_transport_init(void)
37478 printk(KERN_INFO "Loading iSCSI transport class v%s.\n",
37479 ISCSI_TRANSPORT_VERSION);
37480
37481- atomic_set(&iscsi_session_nr, 0);
37482+ atomic_set_unchecked(&iscsi_session_nr, 0);
37483
37484 err = class_register(&iscsi_transport_class);
37485 if (err)
37486diff --git a/drivers/scsi/scsi_transport_srp.c b/drivers/scsi/scsi_transport_srp.c
37487index 21a045e..ec89e03 100644
37488--- a/drivers/scsi/scsi_transport_srp.c
37489+++ b/drivers/scsi/scsi_transport_srp.c
37490@@ -33,7 +33,7 @@
37491 #include "scsi_transport_srp_internal.h"
37492
37493 struct srp_host_attrs {
37494- atomic_t next_port_id;
37495+ atomic_unchecked_t next_port_id;
37496 };
37497 #define to_srp_host_attrs(host) ((struct srp_host_attrs *)(host)->shost_data)
37498
37499@@ -62,7 +62,7 @@ static int srp_host_setup(struct transport_container *tc, struct device *dev,
37500 struct Scsi_Host *shost = dev_to_shost(dev);
37501 struct srp_host_attrs *srp_host = to_srp_host_attrs(shost);
37502
37503- atomic_set(&srp_host->next_port_id, 0);
37504+ atomic_set_unchecked(&srp_host->next_port_id, 0);
37505 return 0;
37506 }
37507
37508@@ -211,7 +211,7 @@ struct srp_rport *srp_rport_add(struct Scsi_Host *shost,
37509 memcpy(rport->port_id, ids->port_id, sizeof(rport->port_id));
37510 rport->roles = ids->roles;
37511
37512- id = atomic_inc_return(&to_srp_host_attrs(shost)->next_port_id);
37513+ id = atomic_inc_return_unchecked(&to_srp_host_attrs(shost)->next_port_id);
37514 dev_set_name(&rport->dev, "port-%d:%d", shost->host_no, id);
37515
37516 transport_setup_device(&rport->dev);
37517diff --git a/drivers/scsi/sd.c b/drivers/scsi/sd.c
37518index 4df73e5..b691c58 100644
37519--- a/drivers/scsi/sd.c
37520+++ b/drivers/scsi/sd.c
37521@@ -2709,7 +2709,7 @@ static int sd_probe(struct device *dev)
37522 sdkp->disk = gd;
37523 sdkp->index = index;
37524 atomic_set(&sdkp->openers, 0);
37525- atomic_set(&sdkp->device->ioerr_cnt, 0);
37526+ atomic_set_unchecked(&sdkp->device->ioerr_cnt, 0);
37527
37528 if (!sdp->request_queue->rq_timeout) {
37529 if (sdp->type != TYPE_MOD)
37530diff --git a/drivers/scsi/sg.c b/drivers/scsi/sg.c
37531index 9c5c5f2..8414557 100644
37532--- a/drivers/scsi/sg.c
37533+++ b/drivers/scsi/sg.c
37534@@ -1101,7 +1101,7 @@ sg_ioctl(struct file *filp, unsigned int cmd_in, unsigned long arg)
37535 sdp->disk->disk_name,
37536 MKDEV(SCSI_GENERIC_MAJOR, sdp->index),
37537 NULL,
37538- (char *)arg);
37539+ (char __user *)arg);
37540 case BLKTRACESTART:
37541 return blk_trace_startstop(sdp->device->request_queue, 1);
37542 case BLKTRACESTOP:
37543diff --git a/drivers/spi/spi.c b/drivers/spi/spi.c
37544index 84c2861..ece0a31 100644
37545--- a/drivers/spi/spi.c
37546+++ b/drivers/spi/spi.c
37547@@ -1453,7 +1453,7 @@ int spi_bus_unlock(struct spi_master *master)
37548 EXPORT_SYMBOL_GPL(spi_bus_unlock);
37549
37550 /* portable code must never pass more than 32 bytes */
37551-#define SPI_BUFSIZ max(32,SMP_CACHE_BYTES)
37552+#define SPI_BUFSIZ max(32UL,SMP_CACHE_BYTES)
37553
37554 static u8 *buf;
37555
37556diff --git a/drivers/staging/octeon/ethernet-rx.c b/drivers/staging/octeon/ethernet-rx.c
37557index 34afc16..ffe44dd 100644
37558--- a/drivers/staging/octeon/ethernet-rx.c
37559+++ b/drivers/staging/octeon/ethernet-rx.c
37560@@ -421,11 +421,11 @@ static int cvm_oct_napi_poll(struct napi_struct *napi, int budget)
37561 /* Increment RX stats for virtual ports */
37562 if (work->ipprt >= CVMX_PIP_NUM_INPUT_PORTS) {
37563 #ifdef CONFIG_64BIT
37564- atomic64_add(1, (atomic64_t *)&priv->stats.rx_packets);
37565- atomic64_add(skb->len, (atomic64_t *)&priv->stats.rx_bytes);
37566+ atomic64_add_unchecked(1, (atomic64_unchecked_t *)&priv->stats.rx_packets);
37567+ atomic64_add_unchecked(skb->len, (atomic64_unchecked_t *)&priv->stats.rx_bytes);
37568 #else
37569- atomic_add(1, (atomic_t *)&priv->stats.rx_packets);
37570- atomic_add(skb->len, (atomic_t *)&priv->stats.rx_bytes);
37571+ atomic_add_unchecked(1, (atomic_unchecked_t *)&priv->stats.rx_packets);
37572+ atomic_add_unchecked(skb->len, (atomic_unchecked_t *)&priv->stats.rx_bytes);
37573 #endif
37574 }
37575 netif_receive_skb(skb);
37576@@ -437,9 +437,9 @@ static int cvm_oct_napi_poll(struct napi_struct *napi, int budget)
37577 dev->name);
37578 */
37579 #ifdef CONFIG_64BIT
37580- atomic64_add(1, (atomic64_t *)&priv->stats.rx_dropped);
37581+ atomic64_unchecked_add(1, (atomic64_unchecked_t *)&priv->stats.rx_dropped);
37582 #else
37583- atomic_add(1, (atomic_t *)&priv->stats.rx_dropped);
37584+ atomic_add_unchecked(1, (atomic_unchecked_t *)&priv->stats.rx_dropped);
37585 #endif
37586 dev_kfree_skb_irq(skb);
37587 }
37588diff --git a/drivers/staging/octeon/ethernet.c b/drivers/staging/octeon/ethernet.c
37589index 683bedc..86dba9a 100644
37590--- a/drivers/staging/octeon/ethernet.c
37591+++ b/drivers/staging/octeon/ethernet.c
37592@@ -252,11 +252,11 @@ static struct net_device_stats *cvm_oct_common_get_stats(struct net_device *dev)
37593 * since the RX tasklet also increments it.
37594 */
37595 #ifdef CONFIG_64BIT
37596- atomic64_add(rx_status.dropped_packets,
37597- (atomic64_t *)&priv->stats.rx_dropped);
37598+ atomic64_add_unchecked(rx_status.dropped_packets,
37599+ (atomic64_unchecked_t *)&priv->stats.rx_dropped);
37600 #else
37601- atomic_add(rx_status.dropped_packets,
37602- (atomic_t *)&priv->stats.rx_dropped);
37603+ atomic_add_unchecked(rx_status.dropped_packets,
37604+ (atomic_unchecked_t *)&priv->stats.rx_dropped);
37605 #endif
37606 }
37607
37608diff --git a/drivers/staging/rtl8712/rtl871x_io.h b/drivers/staging/rtl8712/rtl871x_io.h
37609index dc23395..cf7e9b1 100644
37610--- a/drivers/staging/rtl8712/rtl871x_io.h
37611+++ b/drivers/staging/rtl8712/rtl871x_io.h
37612@@ -108,7 +108,7 @@ struct _io_ops {
37613 u8 *pmem);
37614 u32 (*_write_port)(struct intf_hdl *pintfhdl, u32 addr, u32 cnt,
37615 u8 *pmem);
37616-};
37617+} __no_const;
37618
37619 struct io_req {
37620 struct list_head list;
37621diff --git a/drivers/staging/sbe-2t3e3/netdev.c b/drivers/staging/sbe-2t3e3/netdev.c
37622index c7b5e8b..783d6cb 100644
37623--- a/drivers/staging/sbe-2t3e3/netdev.c
37624+++ b/drivers/staging/sbe-2t3e3/netdev.c
37625@@ -51,7 +51,7 @@ int t3e3_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
37626 t3e3_if_config(sc, cmd_2t3e3, (char *)&param, &resp, &rlen);
37627
37628 if (rlen)
37629- if (copy_to_user(data, &resp, rlen))
37630+ if (rlen > sizeof resp || copy_to_user(data, &resp, rlen))
37631 return -EFAULT;
37632
37633 return 0;
37634diff --git a/drivers/staging/usbip/usbip_common.h b/drivers/staging/usbip/usbip_common.h
37635index 5d89c0f..9261317 100644
37636--- a/drivers/staging/usbip/usbip_common.h
37637+++ b/drivers/staging/usbip/usbip_common.h
37638@@ -289,7 +289,7 @@ struct usbip_device {
37639 void (*shutdown)(struct usbip_device *);
37640 void (*reset)(struct usbip_device *);
37641 void (*unusable)(struct usbip_device *);
37642- } eh_ops;
37643+ } __no_const eh_ops;
37644 };
37645
37646 #define kthread_get_run(threadfn, data, namefmt, ...) \
37647diff --git a/drivers/staging/usbip/vhci.h b/drivers/staging/usbip/vhci.h
37648index c66b8b3..a4a035b 100644
37649--- a/drivers/staging/usbip/vhci.h
37650+++ b/drivers/staging/usbip/vhci.h
37651@@ -83,7 +83,7 @@ struct vhci_hcd {
37652 unsigned resuming:1;
37653 unsigned long re_timeout;
37654
37655- atomic_t seqnum;
37656+ atomic_unchecked_t seqnum;
37657
37658 /*
37659 * NOTE:
37660diff --git a/drivers/staging/usbip/vhci_hcd.c b/drivers/staging/usbip/vhci_hcd.c
37661index 12a9a5f..afd8295 100644
37662--- a/drivers/staging/usbip/vhci_hcd.c
37663+++ b/drivers/staging/usbip/vhci_hcd.c
37664@@ -471,7 +471,7 @@ static void vhci_tx_urb(struct urb *urb)
37665 return;
37666 }
37667
37668- priv->seqnum = atomic_inc_return(&the_controller->seqnum);
37669+ priv->seqnum = atomic_inc_return_unchecked(&the_controller->seqnum);
37670 if (priv->seqnum == 0xffff)
37671 dev_info(&urb->dev->dev, "seqnum max\n");
37672
37673@@ -723,7 +723,7 @@ static int vhci_urb_dequeue(struct usb_hcd *hcd, struct urb *urb, int status)
37674 return -ENOMEM;
37675 }
37676
37677- unlink->seqnum = atomic_inc_return(&the_controller->seqnum);
37678+ unlink->seqnum = atomic_inc_return_unchecked(&the_controller->seqnum);
37679 if (unlink->seqnum == 0xffff)
37680 pr_info("seqnum max\n");
37681
37682@@ -911,7 +911,7 @@ static int vhci_start(struct usb_hcd *hcd)
37683 vdev->rhport = rhport;
37684 }
37685
37686- atomic_set(&vhci->seqnum, 0);
37687+ atomic_set_unchecked(&vhci->seqnum, 0);
37688 spin_lock_init(&vhci->lock);
37689
37690 hcd->power_budget = 0; /* no limit */
37691diff --git a/drivers/staging/usbip/vhci_rx.c b/drivers/staging/usbip/vhci_rx.c
37692index f0eaf04..5a82e06 100644
37693--- a/drivers/staging/usbip/vhci_rx.c
37694+++ b/drivers/staging/usbip/vhci_rx.c
37695@@ -77,7 +77,7 @@ static void vhci_recv_ret_submit(struct vhci_device *vdev,
37696 if (!urb) {
37697 pr_err("cannot find a urb of seqnum %u\n", pdu->base.seqnum);
37698 pr_info("max seqnum %d\n",
37699- atomic_read(&the_controller->seqnum));
37700+ atomic_read_unchecked(&the_controller->seqnum));
37701 usbip_event_add(ud, VDEV_EVENT_ERROR_TCP);
37702 return;
37703 }
37704diff --git a/drivers/staging/vt6655/hostap.c b/drivers/staging/vt6655/hostap.c
37705index 6ac6f45..1b208ba 100644
37706--- a/drivers/staging/vt6655/hostap.c
37707+++ b/drivers/staging/vt6655/hostap.c
37708@@ -73,14 +73,13 @@ static int msglevel =MSG_LEVEL_INFO;
37709 *
37710 */
37711
37712+static net_device_ops_no_const apdev_netdev_ops;
37713+
37714 static int hostap_enable_hostapd(PSDevice pDevice, int rtnl_locked)
37715 {
37716 PSDevice apdev_priv;
37717 struct net_device *dev = pDevice->dev;
37718 int ret;
37719- const struct net_device_ops apdev_netdev_ops = {
37720- .ndo_start_xmit = pDevice->tx_80211,
37721- };
37722
37723 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "%s: Enabling hostapd mode\n", dev->name);
37724
37725@@ -92,6 +91,8 @@ static int hostap_enable_hostapd(PSDevice pDevice, int rtnl_locked)
37726 *apdev_priv = *pDevice;
37727 memcpy(pDevice->apdev->dev_addr, dev->dev_addr, ETH_ALEN);
37728
37729+ /* only half broken now */
37730+ apdev_netdev_ops.ndo_start_xmit = pDevice->tx_80211;
37731 pDevice->apdev->netdev_ops = &apdev_netdev_ops;
37732
37733 pDevice->apdev->type = ARPHRD_IEEE80211;
37734diff --git a/drivers/staging/vt6656/hostap.c b/drivers/staging/vt6656/hostap.c
37735index 682002a..35ed5cf 100644
37736--- a/drivers/staging/vt6656/hostap.c
37737+++ b/drivers/staging/vt6656/hostap.c
37738@@ -60,14 +60,13 @@ static int msglevel =MSG_LEVEL_INFO;
37739 *
37740 */
37741
37742+static net_device_ops_no_const apdev_netdev_ops;
37743+
37744 static int hostap_enable_hostapd(PSDevice pDevice, int rtnl_locked)
37745 {
37746 PSDevice apdev_priv;
37747 struct net_device *dev = pDevice->dev;
37748 int ret;
37749- const struct net_device_ops apdev_netdev_ops = {
37750- .ndo_start_xmit = pDevice->tx_80211,
37751- };
37752
37753 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "%s: Enabling hostapd mode\n", dev->name);
37754
37755@@ -79,6 +78,8 @@ static int hostap_enable_hostapd(PSDevice pDevice, int rtnl_locked)
37756 *apdev_priv = *pDevice;
37757 memcpy(pDevice->apdev->dev_addr, dev->dev_addr, ETH_ALEN);
37758
37759+ /* only half broken now */
37760+ apdev_netdev_ops.ndo_start_xmit = pDevice->tx_80211;
37761 pDevice->apdev->netdev_ops = &apdev_netdev_ops;
37762
37763 pDevice->apdev->type = ARPHRD_IEEE80211;
37764diff --git a/drivers/staging/wlan-ng/hfa384x_usb.c b/drivers/staging/wlan-ng/hfa384x_usb.c
37765index 7843dfd..3db105f 100644
37766--- a/drivers/staging/wlan-ng/hfa384x_usb.c
37767+++ b/drivers/staging/wlan-ng/hfa384x_usb.c
37768@@ -204,7 +204,7 @@ static void unlocked_usbctlx_complete(hfa384x_t *hw, hfa384x_usbctlx_t *ctlx);
37769
37770 struct usbctlx_completor {
37771 int (*complete) (struct usbctlx_completor *);
37772-};
37773+} __no_const;
37774
37775 static int
37776 hfa384x_usbctlx_complete_sync(hfa384x_t *hw,
37777diff --git a/drivers/staging/zcache/tmem.c b/drivers/staging/zcache/tmem.c
37778index eaa9021..43f023b 100644
37779--- a/drivers/staging/zcache/tmem.c
37780+++ b/drivers/staging/zcache/tmem.c
37781@@ -39,7 +39,7 @@
37782 * A tmem host implementation must use this function to register callbacks
37783 * for memory allocation.
37784 */
37785-static struct tmem_hostops tmem_hostops;
37786+static tmem_hostops_no_const tmem_hostops;
37787
37788 static void tmem_objnode_tree_init(void);
37789
37790@@ -53,7 +53,7 @@ void tmem_register_hostops(struct tmem_hostops *m)
37791 * A tmem host implementation must use this function to register
37792 * callbacks for a page-accessible memory (PAM) implementation
37793 */
37794-static struct tmem_pamops tmem_pamops;
37795+static tmem_pamops_no_const tmem_pamops;
37796
37797 void tmem_register_pamops(struct tmem_pamops *m)
37798 {
37799diff --git a/drivers/staging/zcache/tmem.h b/drivers/staging/zcache/tmem.h
37800index 0d4aa82..f7832d4 100644
37801--- a/drivers/staging/zcache/tmem.h
37802+++ b/drivers/staging/zcache/tmem.h
37803@@ -180,6 +180,7 @@ struct tmem_pamops {
37804 void (*new_obj)(struct tmem_obj *);
37805 int (*replace_in_obj)(void *, struct tmem_obj *);
37806 };
37807+typedef struct tmem_pamops __no_const tmem_pamops_no_const;
37808 extern void tmem_register_pamops(struct tmem_pamops *m);
37809
37810 /* memory allocation methods provided by the host implementation */
37811@@ -189,6 +190,7 @@ struct tmem_hostops {
37812 struct tmem_objnode *(*objnode_alloc)(struct tmem_pool *);
37813 void (*objnode_free)(struct tmem_objnode *, struct tmem_pool *);
37814 };
37815+typedef struct tmem_hostops __no_const tmem_hostops_no_const;
37816 extern void tmem_register_hostops(struct tmem_hostops *m);
37817
37818 /* core tmem accessor functions */
37819diff --git a/drivers/target/target_core_transport.c b/drivers/target/target_core_transport.c
37820index 269f544..32def0d 100644
37821--- a/drivers/target/target_core_transport.c
37822+++ b/drivers/target/target_core_transport.c
37823@@ -1098,7 +1098,7 @@ struct se_device *transport_add_device_to_core_hba(
37824 spin_lock_init(&dev->se_port_lock);
37825 spin_lock_init(&dev->se_tmr_lock);
37826 spin_lock_init(&dev->qf_cmd_lock);
37827- atomic_set(&dev->dev_ordered_id, 0);
37828+ atomic_set_unchecked(&dev->dev_ordered_id, 0);
37829
37830 se_dev_set_default_attribs(dev, dev_limits);
37831
37832@@ -1288,7 +1288,7 @@ static int transport_check_alloc_task_attr(struct se_cmd *cmd)
37833 * Used to determine when ORDERED commands should go from
37834 * Dormant to Active status.
37835 */
37836- cmd->se_ordered_id = atomic_inc_return(&cmd->se_dev->dev_ordered_id);
37837+ cmd->se_ordered_id = atomic_inc_return_unchecked(&cmd->se_dev->dev_ordered_id);
37838 smp_mb__after_atomic_inc();
37839 pr_debug("Allocated se_ordered_id: %u for Task Attr: 0x%02x on %s\n",
37840 cmd->se_ordered_id, cmd->sam_task_attr,
37841diff --git a/drivers/tty/cyclades.c b/drivers/tty/cyclades.c
37842index e61cabd..7617d26 100644
37843--- a/drivers/tty/cyclades.c
37844+++ b/drivers/tty/cyclades.c
37845@@ -1589,10 +1589,10 @@ static int cy_open(struct tty_struct *tty, struct file *filp)
37846 printk(KERN_DEBUG "cyc:cy_open ttyC%d, count = %d\n", info->line,
37847 info->port.count);
37848 #endif
37849- info->port.count++;
37850+ atomic_inc(&info->port.count);
37851 #ifdef CY_DEBUG_COUNT
37852 printk(KERN_DEBUG "cyc:cy_open (%d): incrementing count to %d\n",
37853- current->pid, info->port.count);
37854+ current->pid, atomic_read(&info->port.count));
37855 #endif
37856
37857 /*
37858@@ -3987,7 +3987,7 @@ static int cyclades_proc_show(struct seq_file *m, void *v)
37859 for (j = 0; j < cy_card[i].nports; j++) {
37860 info = &cy_card[i].ports[j];
37861
37862- if (info->port.count) {
37863+ if (atomic_read(&info->port.count)) {
37864 /* XXX is the ldisc num worth this? */
37865 struct tty_struct *tty;
37866 struct tty_ldisc *ld;
37867diff --git a/drivers/tty/hvc/hvc_console.c b/drivers/tty/hvc/hvc_console.c
37868index 2d691eb..be02ebd 100644
37869--- a/drivers/tty/hvc/hvc_console.c
37870+++ b/drivers/tty/hvc/hvc_console.c
37871@@ -315,7 +315,7 @@ static int hvc_open(struct tty_struct *tty, struct file * filp)
37872
37873 spin_lock_irqsave(&hp->port.lock, flags);
37874 /* Check and then increment for fast path open. */
37875- if (hp->port.count++ > 0) {
37876+ if (atomic_inc_return(&hp->port.count) > 1) {
37877 spin_unlock_irqrestore(&hp->port.lock, flags);
37878 hvc_kick();
37879 return 0;
37880@@ -366,7 +366,7 @@ static void hvc_close(struct tty_struct *tty, struct file * filp)
37881
37882 spin_lock_irqsave(&hp->port.lock, flags);
37883
37884- if (--hp->port.count == 0) {
37885+ if (atomic_dec_return(&hp->port.count) == 0) {
37886 spin_unlock_irqrestore(&hp->port.lock, flags);
37887 /* We are done with the tty pointer now. */
37888 tty_port_tty_set(&hp->port, NULL);
37889@@ -384,9 +384,9 @@ static void hvc_close(struct tty_struct *tty, struct file * filp)
37890 */
37891 tty_wait_until_sent_from_close(tty, HVC_CLOSE_WAIT);
37892 } else {
37893- if (hp->port.count < 0)
37894+ if (atomic_read(&hp->port.count) < 0)
37895 printk(KERN_ERR "hvc_close %X: oops, count is %d\n",
37896- hp->vtermno, hp->port.count);
37897+ hp->vtermno, atomic_read(&hp->port.count));
37898 spin_unlock_irqrestore(&hp->port.lock, flags);
37899 }
37900
37901@@ -412,13 +412,13 @@ static void hvc_hangup(struct tty_struct *tty)
37902 * open->hangup case this can be called after the final close so prevent
37903 * that from happening for now.
37904 */
37905- if (hp->port.count <= 0) {
37906+ if (atomic_read(&hp->port.count) <= 0) {
37907 spin_unlock_irqrestore(&hp->port.lock, flags);
37908 return;
37909 }
37910
37911- temp_open_count = hp->port.count;
37912- hp->port.count = 0;
37913+ temp_open_count = atomic_read(&hp->port.count);
37914+ atomic_set(&hp->port.count, 0);
37915 spin_unlock_irqrestore(&hp->port.lock, flags);
37916 tty_port_tty_set(&hp->port, NULL);
37917
37918@@ -471,7 +471,7 @@ static int hvc_write(struct tty_struct *tty, const unsigned char *buf, int count
37919 return -EPIPE;
37920
37921 /* FIXME what's this (unprotected) check for? */
37922- if (hp->port.count <= 0)
37923+ if (atomic_read(&hp->port.count) <= 0)
37924 return -EIO;
37925
37926 spin_lock_irqsave(&hp->lock, flags);
37927diff --git a/drivers/tty/hvc/hvcs.c b/drivers/tty/hvc/hvcs.c
37928index d56788c..12d8f85 100644
37929--- a/drivers/tty/hvc/hvcs.c
37930+++ b/drivers/tty/hvc/hvcs.c
37931@@ -83,6 +83,7 @@
37932 #include <asm/hvcserver.h>
37933 #include <asm/uaccess.h>
37934 #include <asm/vio.h>
37935+#include <asm/local.h>
37936
37937 /*
37938 * 1.3.0 -> 1.3.1 In hvcs_open memset(..,0x00,..) instead of memset(..,0x3F,00).
37939@@ -416,7 +417,7 @@ static ssize_t hvcs_vterm_state_store(struct device *dev, struct device_attribut
37940
37941 spin_lock_irqsave(&hvcsd->lock, flags);
37942
37943- if (hvcsd->port.count > 0) {
37944+ if (atomic_read(&hvcsd->port.count) > 0) {
37945 spin_unlock_irqrestore(&hvcsd->lock, flags);
37946 printk(KERN_INFO "HVCS: vterm state unchanged. "
37947 "The hvcs device node is still in use.\n");
37948@@ -1134,7 +1135,7 @@ static int hvcs_open(struct tty_struct *tty, struct file *filp)
37949 if ((retval = hvcs_partner_connect(hvcsd)))
37950 goto error_release;
37951
37952- hvcsd->port.count = 1;
37953+ atomic_set(&hvcsd->port.count, 1);
37954 hvcsd->port.tty = tty;
37955 tty->driver_data = hvcsd;
37956
37957@@ -1168,7 +1169,7 @@ fast_open:
37958
37959 spin_lock_irqsave(&hvcsd->lock, flags);
37960 tty_port_get(&hvcsd->port);
37961- hvcsd->port.count++;
37962+ atomic_inc(&hvcsd->port.count);
37963 hvcsd->todo_mask |= HVCS_SCHED_READ;
37964 spin_unlock_irqrestore(&hvcsd->lock, flags);
37965
37966@@ -1212,7 +1213,7 @@ static void hvcs_close(struct tty_struct *tty, struct file *filp)
37967 hvcsd = tty->driver_data;
37968
37969 spin_lock_irqsave(&hvcsd->lock, flags);
37970- if (--hvcsd->port.count == 0) {
37971+ if (atomic_dec_and_test(&hvcsd->port.count)) {
37972
37973 vio_disable_interrupts(hvcsd->vdev);
37974
37975@@ -1238,10 +1239,10 @@ static void hvcs_close(struct tty_struct *tty, struct file *filp)
37976 free_irq(irq, hvcsd);
37977 tty_port_put(&hvcsd->port);
37978 return;
37979- } else if (hvcsd->port.count < 0) {
37980+ } else if (atomic_read(&hvcsd->port.count) < 0) {
37981 printk(KERN_ERR "HVCS: vty-server@%X open_count: %d"
37982 " is missmanaged.\n",
37983- hvcsd->vdev->unit_address, hvcsd->port.count);
37984+ hvcsd->vdev->unit_address, atomic_read(&hvcsd->port.count));
37985 }
37986
37987 spin_unlock_irqrestore(&hvcsd->lock, flags);
37988@@ -1257,7 +1258,7 @@ static void hvcs_hangup(struct tty_struct * tty)
37989
37990 spin_lock_irqsave(&hvcsd->lock, flags);
37991 /* Preserve this so that we know how many kref refs to put */
37992- temp_open_count = hvcsd->port.count;
37993+ temp_open_count = atomic_read(&hvcsd->port.count);
37994
37995 /*
37996 * Don't kref put inside the spinlock because the destruction
37997@@ -1272,7 +1273,7 @@ static void hvcs_hangup(struct tty_struct * tty)
37998 tty->driver_data = NULL;
37999 hvcsd->port.tty = NULL;
38000
38001- hvcsd->port.count = 0;
38002+ atomic_set(&hvcsd->port.count, 0);
38003
38004 /* This will drop any buffered data on the floor which is OK in a hangup
38005 * scenario. */
38006@@ -1343,7 +1344,7 @@ static int hvcs_write(struct tty_struct *tty,
38007 * the middle of a write operation? This is a crummy place to do this
38008 * but we want to keep it all in the spinlock.
38009 */
38010- if (hvcsd->port.count <= 0) {
38011+ if (atomic_read(&hvcsd->port.count) <= 0) {
38012 spin_unlock_irqrestore(&hvcsd->lock, flags);
38013 return -ENODEV;
38014 }
38015@@ -1417,7 +1418,7 @@ static int hvcs_write_room(struct tty_struct *tty)
38016 {
38017 struct hvcs_struct *hvcsd = tty->driver_data;
38018
38019- if (!hvcsd || hvcsd->port.count <= 0)
38020+ if (!hvcsd || atomic_read(&hvcsd->port.count) <= 0)
38021 return 0;
38022
38023 return HVCS_BUFF_LEN - hvcsd->chars_in_buffer;
38024diff --git a/drivers/tty/ipwireless/tty.c b/drivers/tty/ipwireless/tty.c
38025index f8b5fa0..4ba9f89 100644
38026--- a/drivers/tty/ipwireless/tty.c
38027+++ b/drivers/tty/ipwireless/tty.c
38028@@ -29,6 +29,7 @@
38029 #include <linux/tty_driver.h>
38030 #include <linux/tty_flip.h>
38031 #include <linux/uaccess.h>
38032+#include <asm/local.h>
38033
38034 #include "tty.h"
38035 #include "network.h"
38036@@ -99,10 +100,10 @@ static int ipw_open(struct tty_struct *linux_tty, struct file *filp)
38037 mutex_unlock(&tty->ipw_tty_mutex);
38038 return -ENODEV;
38039 }
38040- if (tty->port.count == 0)
38041+ if (atomic_read(&tty->port.count) == 0)
38042 tty->tx_bytes_queued = 0;
38043
38044- tty->port.count++;
38045+ atomic_inc(&tty->port.count);
38046
38047 tty->port.tty = linux_tty;
38048 linux_tty->driver_data = tty;
38049@@ -118,9 +119,7 @@ static int ipw_open(struct tty_struct *linux_tty, struct file *filp)
38050
38051 static void do_ipw_close(struct ipw_tty *tty)
38052 {
38053- tty->port.count--;
38054-
38055- if (tty->port.count == 0) {
38056+ if (atomic_dec_return(&tty->port.count) == 0) {
38057 struct tty_struct *linux_tty = tty->port.tty;
38058
38059 if (linux_tty != NULL) {
38060@@ -141,7 +140,7 @@ static void ipw_hangup(struct tty_struct *linux_tty)
38061 return;
38062
38063 mutex_lock(&tty->ipw_tty_mutex);
38064- if (tty->port.count == 0) {
38065+ if (atomic_read(&tty->port.count) == 0) {
38066 mutex_unlock(&tty->ipw_tty_mutex);
38067 return;
38068 }
38069@@ -170,7 +169,7 @@ void ipwireless_tty_received(struct ipw_tty *tty, unsigned char *data,
38070 return;
38071 }
38072
38073- if (!tty->port.count) {
38074+ if (!atomic_read(&tty->port.count)) {
38075 mutex_unlock(&tty->ipw_tty_mutex);
38076 return;
38077 }
38078@@ -212,7 +211,7 @@ static int ipw_write(struct tty_struct *linux_tty,
38079 return -ENODEV;
38080
38081 mutex_lock(&tty->ipw_tty_mutex);
38082- if (!tty->port.count) {
38083+ if (!atomic_read(&tty->port.count)) {
38084 mutex_unlock(&tty->ipw_tty_mutex);
38085 return -EINVAL;
38086 }
38087@@ -252,7 +251,7 @@ static int ipw_write_room(struct tty_struct *linux_tty)
38088 if (!tty)
38089 return -ENODEV;
38090
38091- if (!tty->port.count)
38092+ if (!atomic_read(&tty->port.count))
38093 return -EINVAL;
38094
38095 room = IPWIRELESS_TX_QUEUE_SIZE - tty->tx_bytes_queued;
38096@@ -294,7 +293,7 @@ static int ipw_chars_in_buffer(struct tty_struct *linux_tty)
38097 if (!tty)
38098 return 0;
38099
38100- if (!tty->port.count)
38101+ if (!atomic_read(&tty->port.count))
38102 return 0;
38103
38104 return tty->tx_bytes_queued;
38105@@ -375,7 +374,7 @@ static int ipw_tiocmget(struct tty_struct *linux_tty)
38106 if (!tty)
38107 return -ENODEV;
38108
38109- if (!tty->port.count)
38110+ if (!atomic_read(&tty->port.count))
38111 return -EINVAL;
38112
38113 return get_control_lines(tty);
38114@@ -391,7 +390,7 @@ ipw_tiocmset(struct tty_struct *linux_tty,
38115 if (!tty)
38116 return -ENODEV;
38117
38118- if (!tty->port.count)
38119+ if (!atomic_read(&tty->port.count))
38120 return -EINVAL;
38121
38122 return set_control_lines(tty, set, clear);
38123@@ -405,7 +404,7 @@ static int ipw_ioctl(struct tty_struct *linux_tty,
38124 if (!tty)
38125 return -ENODEV;
38126
38127- if (!tty->port.count)
38128+ if (!atomic_read(&tty->port.count))
38129 return -EINVAL;
38130
38131 /* FIXME: Exactly how is the tty object locked here .. */
38132@@ -561,7 +560,7 @@ void ipwireless_tty_free(struct ipw_tty *tty)
38133 * are gone */
38134 mutex_lock(&ttyj->ipw_tty_mutex);
38135 }
38136- while (ttyj->port.count)
38137+ while (atomic_read(&ttyj->port.count))
38138 do_ipw_close(ttyj);
38139 ipwireless_disassociate_network_ttys(network,
38140 ttyj->channel_idx);
38141diff --git a/drivers/tty/moxa.c b/drivers/tty/moxa.c
38142index 324467d..504cc25 100644
38143--- a/drivers/tty/moxa.c
38144+++ b/drivers/tty/moxa.c
38145@@ -1172,7 +1172,7 @@ static int moxa_open(struct tty_struct *tty, struct file *filp)
38146 }
38147
38148 ch = &brd->ports[port % MAX_PORTS_PER_BOARD];
38149- ch->port.count++;
38150+ atomic_inc(&ch->port.count);
38151 tty->driver_data = ch;
38152 tty_port_tty_set(&ch->port, tty);
38153 mutex_lock(&ch->port.mutex);
38154diff --git a/drivers/tty/n_gsm.c b/drivers/tty/n_gsm.c
38155index 90dff82..08119c3 100644
38156--- a/drivers/tty/n_gsm.c
38157+++ b/drivers/tty/n_gsm.c
38158@@ -1639,7 +1639,7 @@ static struct gsm_dlci *gsm_dlci_alloc(struct gsm_mux *gsm, int addr)
38159 kref_init(&dlci->ref);
38160 mutex_init(&dlci->mutex);
38161 dlci->fifo = &dlci->_fifo;
38162- if (kfifo_alloc(&dlci->_fifo, 4096, GFP_KERNEL) < 0) {
38163+ if (kfifo_alloc(&dlci->_fifo, 4096, GFP_KERNEL)) {
38164 kfree(dlci);
38165 return NULL;
38166 }
38167@@ -2909,7 +2909,7 @@ static int gsmtty_open(struct tty_struct *tty, struct file *filp)
38168 if (dlci == NULL)
38169 return -ENOMEM;
38170 port = &dlci->port;
38171- port->count++;
38172+ atomic_inc(&port->count);
38173 tty->driver_data = dlci;
38174 dlci_get(dlci);
38175 dlci_get(dlci->gsm->dlci[0]);
38176diff --git a/drivers/tty/n_tty.c b/drivers/tty/n_tty.c
38177index 26f0d0e..b7c4273 100644
38178--- a/drivers/tty/n_tty.c
38179+++ b/drivers/tty/n_tty.c
38180@@ -2124,6 +2124,7 @@ void n_tty_inherit_ops(struct tty_ldisc_ops *ops)
38181 {
38182 *ops = tty_ldisc_N_TTY;
38183 ops->owner = NULL;
38184- ops->refcount = ops->flags = 0;
38185+ atomic_set(&ops->refcount, 0);
38186+ ops->flags = 0;
38187 }
38188 EXPORT_SYMBOL_GPL(n_tty_inherit_ops);
38189diff --git a/drivers/tty/pty.c b/drivers/tty/pty.c
38190index 5505ffc..7affff9 100644
38191--- a/drivers/tty/pty.c
38192+++ b/drivers/tty/pty.c
38193@@ -718,8 +718,10 @@ static void __init unix98_pty_init(void)
38194 panic("Couldn't register Unix98 pts driver");
38195
38196 /* Now create the /dev/ptmx special device */
38197+ pax_open_kernel();
38198 tty_default_fops(&ptmx_fops);
38199- ptmx_fops.open = ptmx_open;
38200+ *(void **)&ptmx_fops.open = ptmx_open;
38201+ pax_close_kernel();
38202
38203 cdev_init(&ptmx_cdev, &ptmx_fops);
38204 if (cdev_add(&ptmx_cdev, MKDEV(TTYAUX_MAJOR, 2), 1) ||
38205diff --git a/drivers/tty/rocket.c b/drivers/tty/rocket.c
38206index 777d5f9..56d67ca 100644
38207--- a/drivers/tty/rocket.c
38208+++ b/drivers/tty/rocket.c
38209@@ -924,7 +924,7 @@ static int rp_open(struct tty_struct *tty, struct file *filp)
38210 tty->driver_data = info;
38211 tty_port_tty_set(port, tty);
38212
38213- if (port->count++ == 0) {
38214+ if (atomic_inc_return(&port->count) == 1) {
38215 atomic_inc(&rp_num_ports_open);
38216
38217 #ifdef ROCKET_DEBUG_OPEN
38218@@ -933,7 +933,7 @@ static int rp_open(struct tty_struct *tty, struct file *filp)
38219 #endif
38220 }
38221 #ifdef ROCKET_DEBUG_OPEN
38222- printk(KERN_INFO "rp_open ttyR%d, count=%d\n", info->line, info->port.count);
38223+ printk(KERN_INFO "rp_open ttyR%d, count=%d\n", info->line, atomic-read(&info->port.count));
38224 #endif
38225
38226 /*
38227@@ -1528,7 +1528,7 @@ static void rp_hangup(struct tty_struct *tty)
38228 spin_unlock_irqrestore(&info->port.lock, flags);
38229 return;
38230 }
38231- if (info->port.count)
38232+ if (atomic_read(&info->port.count))
38233 atomic_dec(&rp_num_ports_open);
38234 clear_bit((info->aiop * 8) + info->chan, (void *) &xmit_flags[info->board]);
38235 spin_unlock_irqrestore(&info->port.lock, flags);
38236diff --git a/drivers/tty/serial/kgdboc.c b/drivers/tty/serial/kgdboc.c
38237index 2b42a01..32a2ed3 100644
38238--- a/drivers/tty/serial/kgdboc.c
38239+++ b/drivers/tty/serial/kgdboc.c
38240@@ -24,8 +24,9 @@
38241 #define MAX_CONFIG_LEN 40
38242
38243 static struct kgdb_io kgdboc_io_ops;
38244+static struct kgdb_io kgdboc_io_ops_console;
38245
38246-/* -1 = init not run yet, 0 = unconfigured, 1 = configured. */
38247+/* -1 = init not run yet, 0 = unconfigured, 1/2 = configured. */
38248 static int configured = -1;
38249
38250 static char config[MAX_CONFIG_LEN];
38251@@ -148,6 +149,8 @@ static void cleanup_kgdboc(void)
38252 kgdboc_unregister_kbd();
38253 if (configured == 1)
38254 kgdb_unregister_io_module(&kgdboc_io_ops);
38255+ else if (configured == 2)
38256+ kgdb_unregister_io_module(&kgdboc_io_ops_console);
38257 }
38258
38259 static int configure_kgdboc(void)
38260@@ -157,13 +160,13 @@ static int configure_kgdboc(void)
38261 int err;
38262 char *cptr = config;
38263 struct console *cons;
38264+ int is_console = 0;
38265
38266 err = kgdboc_option_setup(config);
38267 if (err || !strlen(config) || isspace(config[0]))
38268 goto noconfig;
38269
38270 err = -ENODEV;
38271- kgdboc_io_ops.is_console = 0;
38272 kgdb_tty_driver = NULL;
38273
38274 kgdboc_use_kms = 0;
38275@@ -184,7 +187,7 @@ static int configure_kgdboc(void)
38276 int idx;
38277 if (cons->device && cons->device(cons, &idx) == p &&
38278 idx == tty_line) {
38279- kgdboc_io_ops.is_console = 1;
38280+ is_console = 1;
38281 break;
38282 }
38283 cons = cons->next;
38284@@ -194,12 +197,16 @@ static int configure_kgdboc(void)
38285 kgdb_tty_line = tty_line;
38286
38287 do_register:
38288- err = kgdb_register_io_module(&kgdboc_io_ops);
38289+ if (is_console) {
38290+ err = kgdb_register_io_module(&kgdboc_io_ops_console);
38291+ configured = 2;
38292+ } else {
38293+ err = kgdb_register_io_module(&kgdboc_io_ops);
38294+ configured = 1;
38295+ }
38296 if (err)
38297 goto noconfig;
38298
38299- configured = 1;
38300-
38301 return 0;
38302
38303 noconfig:
38304@@ -213,7 +220,7 @@ noconfig:
38305 static int __init init_kgdboc(void)
38306 {
38307 /* Already configured? */
38308- if (configured == 1)
38309+ if (configured >= 1)
38310 return 0;
38311
38312 return configure_kgdboc();
38313@@ -262,7 +269,7 @@ static int param_set_kgdboc_var(const char *kmessage, struct kernel_param *kp)
38314 if (config[len - 1] == '\n')
38315 config[len - 1] = '\0';
38316
38317- if (configured == 1)
38318+ if (configured >= 1)
38319 cleanup_kgdboc();
38320
38321 /* Go and configure with the new params. */
38322@@ -302,6 +309,15 @@ static struct kgdb_io kgdboc_io_ops = {
38323 .post_exception = kgdboc_post_exp_handler,
38324 };
38325
38326+static struct kgdb_io kgdboc_io_ops_console = {
38327+ .name = "kgdboc",
38328+ .read_char = kgdboc_get_char,
38329+ .write_char = kgdboc_put_char,
38330+ .pre_exception = kgdboc_pre_exp_handler,
38331+ .post_exception = kgdboc_post_exp_handler,
38332+ .is_console = 1
38333+};
38334+
38335 #ifdef CONFIG_KGDB_SERIAL_CONSOLE
38336 /* This is only available if kgdboc is a built in for early debugging */
38337 static int __init kgdboc_early_init(char *opt)
38338diff --git a/drivers/tty/serial/serial_core.c b/drivers/tty/serial/serial_core.c
38339index a21dc8e..fe43e9e 100644
38340--- a/drivers/tty/serial/serial_core.c
38341+++ b/drivers/tty/serial/serial_core.c
38342@@ -1392,7 +1392,7 @@ static void uart_hangup(struct tty_struct *tty)
38343 uart_flush_buffer(tty);
38344 uart_shutdown(tty, state);
38345 spin_lock_irqsave(&port->lock, flags);
38346- port->count = 0;
38347+ atomic_set(&port->count, 0);
38348 clear_bit(ASYNCB_NORMAL_ACTIVE, &port->flags);
38349 spin_unlock_irqrestore(&port->lock, flags);
38350 tty_port_tty_set(port, NULL);
38351@@ -1488,7 +1488,7 @@ static int uart_open(struct tty_struct *tty, struct file *filp)
38352 goto end;
38353 }
38354
38355- port->count++;
38356+ atomic_inc(&port->count);
38357 if (!state->uart_port || state->uart_port->flags & UPF_DEAD) {
38358 retval = -ENXIO;
38359 goto err_dec_count;
38360@@ -1515,7 +1515,7 @@ static int uart_open(struct tty_struct *tty, struct file *filp)
38361 /*
38362 * Make sure the device is in D0 state.
38363 */
38364- if (port->count == 1)
38365+ if (atomic_read(&port->count) == 1)
38366 uart_change_pm(state, 0);
38367
38368 /*
38369@@ -1533,7 +1533,7 @@ static int uart_open(struct tty_struct *tty, struct file *filp)
38370 end:
38371 return retval;
38372 err_dec_count:
38373- port->count--;
38374+ atomic_inc(&port->count);
38375 mutex_unlock(&port->mutex);
38376 goto end;
38377 }
38378diff --git a/drivers/tty/synclink.c b/drivers/tty/synclink.c
38379index 593d40a..bdc61f3 100644
38380--- a/drivers/tty/synclink.c
38381+++ b/drivers/tty/synclink.c
38382@@ -3095,7 +3095,7 @@ static void mgsl_close(struct tty_struct *tty, struct file * filp)
38383
38384 if (debug_level >= DEBUG_LEVEL_INFO)
38385 printk("%s(%d):mgsl_close(%s) entry, count=%d\n",
38386- __FILE__,__LINE__, info->device_name, info->port.count);
38387+ __FILE__,__LINE__, info->device_name, atomic_read(&info->port.count));
38388
38389 if (tty_port_close_start(&info->port, tty, filp) == 0)
38390 goto cleanup;
38391@@ -3113,7 +3113,7 @@ static void mgsl_close(struct tty_struct *tty, struct file * filp)
38392 cleanup:
38393 if (debug_level >= DEBUG_LEVEL_INFO)
38394 printk("%s(%d):mgsl_close(%s) exit, count=%d\n", __FILE__,__LINE__,
38395- tty->driver->name, info->port.count);
38396+ tty->driver->name, atomic_read(&info->port.count));
38397
38398 } /* end of mgsl_close() */
38399
38400@@ -3212,8 +3212,8 @@ static void mgsl_hangup(struct tty_struct *tty)
38401
38402 mgsl_flush_buffer(tty);
38403 shutdown(info);
38404-
38405- info->port.count = 0;
38406+
38407+ atomic_set(&info->port.count, 0);
38408 info->port.flags &= ~ASYNC_NORMAL_ACTIVE;
38409 info->port.tty = NULL;
38410
38411@@ -3302,12 +3302,12 @@ static int block_til_ready(struct tty_struct *tty, struct file * filp,
38412
38413 if (debug_level >= DEBUG_LEVEL_INFO)
38414 printk("%s(%d):block_til_ready before block on %s count=%d\n",
38415- __FILE__,__LINE__, tty->driver->name, port->count );
38416+ __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
38417
38418 spin_lock_irqsave(&info->irq_spinlock, flags);
38419 if (!tty_hung_up_p(filp)) {
38420 extra_count = true;
38421- port->count--;
38422+ atomic_dec(&port->count);
38423 }
38424 spin_unlock_irqrestore(&info->irq_spinlock, flags);
38425 port->blocked_open++;
38426@@ -3336,7 +3336,7 @@ static int block_til_ready(struct tty_struct *tty, struct file * filp,
38427
38428 if (debug_level >= DEBUG_LEVEL_INFO)
38429 printk("%s(%d):block_til_ready blocking on %s count=%d\n",
38430- __FILE__,__LINE__, tty->driver->name, port->count );
38431+ __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
38432
38433 tty_unlock();
38434 schedule();
38435@@ -3348,12 +3348,12 @@ static int block_til_ready(struct tty_struct *tty, struct file * filp,
38436
38437 /* FIXME: Racy on hangup during close wait */
38438 if (extra_count)
38439- port->count++;
38440+ atomic_inc(&port->count);
38441 port->blocked_open--;
38442
38443 if (debug_level >= DEBUG_LEVEL_INFO)
38444 printk("%s(%d):block_til_ready after blocking on %s count=%d\n",
38445- __FILE__,__LINE__, tty->driver->name, port->count );
38446+ __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
38447
38448 if (!retval)
38449 port->flags |= ASYNC_NORMAL_ACTIVE;
38450@@ -3398,7 +3398,7 @@ static int mgsl_open(struct tty_struct *tty, struct file * filp)
38451
38452 if (debug_level >= DEBUG_LEVEL_INFO)
38453 printk("%s(%d):mgsl_open(%s), old ref count = %d\n",
38454- __FILE__,__LINE__,tty->driver->name, info->port.count);
38455+ __FILE__,__LINE__,tty->driver->name, atomic_read(&info->port.count));
38456
38457 /* If port is closing, signal caller to try again */
38458 if (tty_hung_up_p(filp) || info->port.flags & ASYNC_CLOSING){
38459@@ -3417,10 +3417,10 @@ static int mgsl_open(struct tty_struct *tty, struct file * filp)
38460 spin_unlock_irqrestore(&info->netlock, flags);
38461 goto cleanup;
38462 }
38463- info->port.count++;
38464+ atomic_inc(&info->port.count);
38465 spin_unlock_irqrestore(&info->netlock, flags);
38466
38467- if (info->port.count == 1) {
38468+ if (atomic_read(&info->port.count) == 1) {
38469 /* 1st open on this device, init hardware */
38470 retval = startup(info);
38471 if (retval < 0)
38472@@ -3444,8 +3444,8 @@ cleanup:
38473 if (retval) {
38474 if (tty->count == 1)
38475 info->port.tty = NULL; /* tty layer will release tty struct */
38476- if(info->port.count)
38477- info->port.count--;
38478+ if (atomic_read(&info->port.count))
38479+ atomic_dec(&info->port.count);
38480 }
38481
38482 return retval;
38483@@ -7653,7 +7653,7 @@ static int hdlcdev_attach(struct net_device *dev, unsigned short encoding,
38484 unsigned short new_crctype;
38485
38486 /* return error if TTY interface open */
38487- if (info->port.count)
38488+ if (atomic_read(&info->port.count))
38489 return -EBUSY;
38490
38491 switch (encoding)
38492@@ -7748,7 +7748,7 @@ static int hdlcdev_open(struct net_device *dev)
38493
38494 /* arbitrate between network and tty opens */
38495 spin_lock_irqsave(&info->netlock, flags);
38496- if (info->port.count != 0 || info->netcount != 0) {
38497+ if (atomic_read(&info->port.count) != 0 || info->netcount != 0) {
38498 printk(KERN_WARNING "%s: hdlc_open returning busy\n", dev->name);
38499 spin_unlock_irqrestore(&info->netlock, flags);
38500 return -EBUSY;
38501@@ -7834,7 +7834,7 @@ static int hdlcdev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
38502 printk("%s:hdlcdev_ioctl(%s)\n",__FILE__,dev->name);
38503
38504 /* return error if TTY interface open */
38505- if (info->port.count)
38506+ if (atomic_read(&info->port.count))
38507 return -EBUSY;
38508
38509 if (cmd != SIOCWANDEV)
38510diff --git a/drivers/tty/synclink_gt.c b/drivers/tty/synclink_gt.c
38511index aa1debf..9297a16 100644
38512--- a/drivers/tty/synclink_gt.c
38513+++ b/drivers/tty/synclink_gt.c
38514@@ -671,7 +671,7 @@ static int open(struct tty_struct *tty, struct file *filp)
38515 tty->driver_data = info;
38516 info->port.tty = tty;
38517
38518- DBGINFO(("%s open, old ref count = %d\n", info->device_name, info->port.count));
38519+ DBGINFO(("%s open, old ref count = %d\n", info->device_name, atomic_read(&info->port.count)));
38520
38521 /* If port is closing, signal caller to try again */
38522 if (tty_hung_up_p(filp) || info->port.flags & ASYNC_CLOSING){
38523@@ -692,10 +692,10 @@ static int open(struct tty_struct *tty, struct file *filp)
38524 mutex_unlock(&info->port.mutex);
38525 goto cleanup;
38526 }
38527- info->port.count++;
38528+ atomic_inc(&info->port.count);
38529 spin_unlock_irqrestore(&info->netlock, flags);
38530
38531- if (info->port.count == 1) {
38532+ if (atomic_read(&info->port.count) == 1) {
38533 /* 1st open on this device, init hardware */
38534 retval = startup(info);
38535 if (retval < 0) {
38536@@ -716,8 +716,8 @@ cleanup:
38537 if (retval) {
38538 if (tty->count == 1)
38539 info->port.tty = NULL; /* tty layer will release tty struct */
38540- if(info->port.count)
38541- info->port.count--;
38542+ if(atomic_read(&info->port.count))
38543+ atomic_dec(&info->port.count);
38544 }
38545
38546 DBGINFO(("%s open rc=%d\n", info->device_name, retval));
38547@@ -730,7 +730,7 @@ static void close(struct tty_struct *tty, struct file *filp)
38548
38549 if (sanity_check(info, tty->name, "close"))
38550 return;
38551- DBGINFO(("%s close entry, count=%d\n", info->device_name, info->port.count));
38552+ DBGINFO(("%s close entry, count=%d\n", info->device_name, atomic_read(&info->port.count)));
38553
38554 if (tty_port_close_start(&info->port, tty, filp) == 0)
38555 goto cleanup;
38556@@ -747,7 +747,7 @@ static void close(struct tty_struct *tty, struct file *filp)
38557 tty_port_close_end(&info->port, tty);
38558 info->port.tty = NULL;
38559 cleanup:
38560- DBGINFO(("%s close exit, count=%d\n", tty->driver->name, info->port.count));
38561+ DBGINFO(("%s close exit, count=%d\n", tty->driver->name, atomic_read(&info->port.count)));
38562 }
38563
38564 static void hangup(struct tty_struct *tty)
38565@@ -765,7 +765,7 @@ static void hangup(struct tty_struct *tty)
38566 shutdown(info);
38567
38568 spin_lock_irqsave(&info->port.lock, flags);
38569- info->port.count = 0;
38570+ atomic_set(&info->port.count, 0);
38571 info->port.flags &= ~ASYNC_NORMAL_ACTIVE;
38572 info->port.tty = NULL;
38573 spin_unlock_irqrestore(&info->port.lock, flags);
38574@@ -1450,7 +1450,7 @@ static int hdlcdev_attach(struct net_device *dev, unsigned short encoding,
38575 unsigned short new_crctype;
38576
38577 /* return error if TTY interface open */
38578- if (info->port.count)
38579+ if (atomic_read(&info->port.count))
38580 return -EBUSY;
38581
38582 DBGINFO(("%s hdlcdev_attach\n", info->device_name));
38583@@ -1545,7 +1545,7 @@ static int hdlcdev_open(struct net_device *dev)
38584
38585 /* arbitrate between network and tty opens */
38586 spin_lock_irqsave(&info->netlock, flags);
38587- if (info->port.count != 0 || info->netcount != 0) {
38588+ if (atomic_read(&info->port.count) != 0 || info->netcount != 0) {
38589 DBGINFO(("%s hdlc_open busy\n", dev->name));
38590 spin_unlock_irqrestore(&info->netlock, flags);
38591 return -EBUSY;
38592@@ -1630,7 +1630,7 @@ static int hdlcdev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
38593 DBGINFO(("%s hdlcdev_ioctl\n", dev->name));
38594
38595 /* return error if TTY interface open */
38596- if (info->port.count)
38597+ if (atomic_read(&info->port.count))
38598 return -EBUSY;
38599
38600 if (cmd != SIOCWANDEV)
38601@@ -2419,7 +2419,7 @@ static irqreturn_t slgt_interrupt(int dummy, void *dev_id)
38602 if (port == NULL)
38603 continue;
38604 spin_lock(&port->lock);
38605- if ((port->port.count || port->netcount) &&
38606+ if ((atomic_read(&port->port.count) || port->netcount) &&
38607 port->pending_bh && !port->bh_running &&
38608 !port->bh_requested) {
38609 DBGISR(("%s bh queued\n", port->device_name));
38610@@ -3308,7 +3308,7 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
38611 spin_lock_irqsave(&info->lock, flags);
38612 if (!tty_hung_up_p(filp)) {
38613 extra_count = true;
38614- port->count--;
38615+ atomic_dec(&port->count);
38616 }
38617 spin_unlock_irqrestore(&info->lock, flags);
38618 port->blocked_open++;
38619@@ -3345,7 +3345,7 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
38620 remove_wait_queue(&port->open_wait, &wait);
38621
38622 if (extra_count)
38623- port->count++;
38624+ atomic_inc(&port->count);
38625 port->blocked_open--;
38626
38627 if (!retval)
38628diff --git a/drivers/tty/synclinkmp.c b/drivers/tty/synclinkmp.c
38629index a3dddc1..8905ab2 100644
38630--- a/drivers/tty/synclinkmp.c
38631+++ b/drivers/tty/synclinkmp.c
38632@@ -742,7 +742,7 @@ static int open(struct tty_struct *tty, struct file *filp)
38633
38634 if (debug_level >= DEBUG_LEVEL_INFO)
38635 printk("%s(%d):%s open(), old ref count = %d\n",
38636- __FILE__,__LINE__,tty->driver->name, info->port.count);
38637+ __FILE__,__LINE__,tty->driver->name, atomic_read(&info->port.count));
38638
38639 /* If port is closing, signal caller to try again */
38640 if (tty_hung_up_p(filp) || info->port.flags & ASYNC_CLOSING){
38641@@ -761,10 +761,10 @@ static int open(struct tty_struct *tty, struct file *filp)
38642 spin_unlock_irqrestore(&info->netlock, flags);
38643 goto cleanup;
38644 }
38645- info->port.count++;
38646+ atomic_inc(&info->port.count);
38647 spin_unlock_irqrestore(&info->netlock, flags);
38648
38649- if (info->port.count == 1) {
38650+ if (atomic_read(&info->port.count) == 1) {
38651 /* 1st open on this device, init hardware */
38652 retval = startup(info);
38653 if (retval < 0)
38654@@ -788,8 +788,8 @@ cleanup:
38655 if (retval) {
38656 if (tty->count == 1)
38657 info->port.tty = NULL; /* tty layer will release tty struct */
38658- if(info->port.count)
38659- info->port.count--;
38660+ if(atomic_read(&info->port.count))
38661+ atomic_dec(&info->port.count);
38662 }
38663
38664 return retval;
38665@@ -807,7 +807,7 @@ static void close(struct tty_struct *tty, struct file *filp)
38666
38667 if (debug_level >= DEBUG_LEVEL_INFO)
38668 printk("%s(%d):%s close() entry, count=%d\n",
38669- __FILE__,__LINE__, info->device_name, info->port.count);
38670+ __FILE__,__LINE__, info->device_name, atomic_read(&info->port.count));
38671
38672 if (tty_port_close_start(&info->port, tty, filp) == 0)
38673 goto cleanup;
38674@@ -826,7 +826,7 @@ static void close(struct tty_struct *tty, struct file *filp)
38675 cleanup:
38676 if (debug_level >= DEBUG_LEVEL_INFO)
38677 printk("%s(%d):%s close() exit, count=%d\n", __FILE__,__LINE__,
38678- tty->driver->name, info->port.count);
38679+ tty->driver->name, atomic_read(&info->port.count));
38680 }
38681
38682 /* Called by tty_hangup() when a hangup is signaled.
38683@@ -849,7 +849,7 @@ static void hangup(struct tty_struct *tty)
38684 shutdown(info);
38685
38686 spin_lock_irqsave(&info->port.lock, flags);
38687- info->port.count = 0;
38688+ atomic_set(&info->port.count, 0);
38689 info->port.flags &= ~ASYNC_NORMAL_ACTIVE;
38690 info->port.tty = NULL;
38691 spin_unlock_irqrestore(&info->port.lock, flags);
38692@@ -1557,7 +1557,7 @@ static int hdlcdev_attach(struct net_device *dev, unsigned short encoding,
38693 unsigned short new_crctype;
38694
38695 /* return error if TTY interface open */
38696- if (info->port.count)
38697+ if (atomic_read(&info->port.count))
38698 return -EBUSY;
38699
38700 switch (encoding)
38701@@ -1652,7 +1652,7 @@ static int hdlcdev_open(struct net_device *dev)
38702
38703 /* arbitrate between network and tty opens */
38704 spin_lock_irqsave(&info->netlock, flags);
38705- if (info->port.count != 0 || info->netcount != 0) {
38706+ if (atomic_read(&info->port.count) != 0 || info->netcount != 0) {
38707 printk(KERN_WARNING "%s: hdlc_open returning busy\n", dev->name);
38708 spin_unlock_irqrestore(&info->netlock, flags);
38709 return -EBUSY;
38710@@ -1738,7 +1738,7 @@ static int hdlcdev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
38711 printk("%s:hdlcdev_ioctl(%s)\n",__FILE__,dev->name);
38712
38713 /* return error if TTY interface open */
38714- if (info->port.count)
38715+ if (atomic_read(&info->port.count))
38716 return -EBUSY;
38717
38718 if (cmd != SIOCWANDEV)
38719@@ -2623,7 +2623,7 @@ static irqreturn_t synclinkmp_interrupt(int dummy, void *dev_id)
38720 * do not request bottom half processing if the
38721 * device is not open in a normal mode.
38722 */
38723- if ( port && (port->port.count || port->netcount) &&
38724+ if ( port && (atomic_read(&port->port.count) || port->netcount) &&
38725 port->pending_bh && !port->bh_running &&
38726 !port->bh_requested ) {
38727 if ( debug_level >= DEBUG_LEVEL_ISR )
38728@@ -3321,12 +3321,12 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
38729
38730 if (debug_level >= DEBUG_LEVEL_INFO)
38731 printk("%s(%d):%s block_til_ready() before block, count=%d\n",
38732- __FILE__,__LINE__, tty->driver->name, port->count );
38733+ __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
38734
38735 spin_lock_irqsave(&info->lock, flags);
38736 if (!tty_hung_up_p(filp)) {
38737 extra_count = true;
38738- port->count--;
38739+ atomic_dec(&port->count);
38740 }
38741 spin_unlock_irqrestore(&info->lock, flags);
38742 port->blocked_open++;
38743@@ -3355,7 +3355,7 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
38744
38745 if (debug_level >= DEBUG_LEVEL_INFO)
38746 printk("%s(%d):%s block_til_ready() count=%d\n",
38747- __FILE__,__LINE__, tty->driver->name, port->count );
38748+ __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
38749
38750 tty_unlock();
38751 schedule();
38752@@ -3366,12 +3366,12 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
38753 remove_wait_queue(&port->open_wait, &wait);
38754
38755 if (extra_count)
38756- port->count++;
38757+ atomic_inc(&port->count);
38758 port->blocked_open--;
38759
38760 if (debug_level >= DEBUG_LEVEL_INFO)
38761 printk("%s(%d):%s block_til_ready() after, count=%d\n",
38762- __FILE__,__LINE__, tty->driver->name, port->count );
38763+ __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
38764
38765 if (!retval)
38766 port->flags |= ASYNC_NORMAL_ACTIVE;
38767diff --git a/drivers/tty/sysrq.c b/drivers/tty/sysrq.c
38768index 05728894..b9d44c6 100644
38769--- a/drivers/tty/sysrq.c
38770+++ b/drivers/tty/sysrq.c
38771@@ -865,7 +865,7 @@ EXPORT_SYMBOL(unregister_sysrq_key);
38772 static ssize_t write_sysrq_trigger(struct file *file, const char __user *buf,
38773 size_t count, loff_t *ppos)
38774 {
38775- if (count) {
38776+ if (count && capable(CAP_SYS_ADMIN)) {
38777 char c;
38778
38779 if (get_user(c, buf))
38780diff --git a/drivers/tty/tty_io.c b/drivers/tty/tty_io.c
38781index b425c79..08a3f06 100644
38782--- a/drivers/tty/tty_io.c
38783+++ b/drivers/tty/tty_io.c
38784@@ -3283,7 +3283,7 @@ EXPORT_SYMBOL_GPL(get_current_tty);
38785
38786 void tty_default_fops(struct file_operations *fops)
38787 {
38788- *fops = tty_fops;
38789+ memcpy((void *)fops, &tty_fops, sizeof(tty_fops));
38790 }
38791
38792 /*
38793diff --git a/drivers/tty/tty_ldisc.c b/drivers/tty/tty_ldisc.c
38794index 6f99c99..8947bc4 100644
38795--- a/drivers/tty/tty_ldisc.c
38796+++ b/drivers/tty/tty_ldisc.c
38797@@ -56,7 +56,7 @@ static void put_ldisc(struct tty_ldisc *ld)
38798 if (atomic_dec_and_lock(&ld->users, &tty_ldisc_lock)) {
38799 struct tty_ldisc_ops *ldo = ld->ops;
38800
38801- ldo->refcount--;
38802+ atomic_dec(&ldo->refcount);
38803 module_put(ldo->owner);
38804 spin_unlock_irqrestore(&tty_ldisc_lock, flags);
38805
38806@@ -91,7 +91,7 @@ int tty_register_ldisc(int disc, struct tty_ldisc_ops *new_ldisc)
38807 spin_lock_irqsave(&tty_ldisc_lock, flags);
38808 tty_ldiscs[disc] = new_ldisc;
38809 new_ldisc->num = disc;
38810- new_ldisc->refcount = 0;
38811+ atomic_set(&new_ldisc->refcount, 0);
38812 spin_unlock_irqrestore(&tty_ldisc_lock, flags);
38813
38814 return ret;
38815@@ -119,7 +119,7 @@ int tty_unregister_ldisc(int disc)
38816 return -EINVAL;
38817
38818 spin_lock_irqsave(&tty_ldisc_lock, flags);
38819- if (tty_ldiscs[disc]->refcount)
38820+ if (atomic_read(&tty_ldiscs[disc]->refcount))
38821 ret = -EBUSY;
38822 else
38823 tty_ldiscs[disc] = NULL;
38824@@ -140,7 +140,7 @@ static struct tty_ldisc_ops *get_ldops(int disc)
38825 if (ldops) {
38826 ret = ERR_PTR(-EAGAIN);
38827 if (try_module_get(ldops->owner)) {
38828- ldops->refcount++;
38829+ atomic_inc(&ldops->refcount);
38830 ret = ldops;
38831 }
38832 }
38833@@ -153,7 +153,7 @@ static void put_ldops(struct tty_ldisc_ops *ldops)
38834 unsigned long flags;
38835
38836 spin_lock_irqsave(&tty_ldisc_lock, flags);
38837- ldops->refcount--;
38838+ atomic_dec(&ldops->refcount);
38839 module_put(ldops->owner);
38840 spin_unlock_irqrestore(&tty_ldisc_lock, flags);
38841 }
38842diff --git a/drivers/tty/tty_port.c b/drivers/tty/tty_port.c
38843index bf6e238..d401c04 100644
38844--- a/drivers/tty/tty_port.c
38845+++ b/drivers/tty/tty_port.c
38846@@ -138,7 +138,7 @@ void tty_port_hangup(struct tty_port *port)
38847 unsigned long flags;
38848
38849 spin_lock_irqsave(&port->lock, flags);
38850- port->count = 0;
38851+ atomic_set(&port->count, 0);
38852 port->flags &= ~ASYNC_NORMAL_ACTIVE;
38853 if (port->tty) {
38854 set_bit(TTY_IO_ERROR, &port->tty->flags);
38855@@ -264,7 +264,7 @@ int tty_port_block_til_ready(struct tty_port *port,
38856 /* The port lock protects the port counts */
38857 spin_lock_irqsave(&port->lock, flags);
38858 if (!tty_hung_up_p(filp))
38859- port->count--;
38860+ atomic_dec(&port->count);
38861 port->blocked_open++;
38862 spin_unlock_irqrestore(&port->lock, flags);
38863
38864@@ -306,7 +306,7 @@ int tty_port_block_til_ready(struct tty_port *port,
38865 we must not mess that up further */
38866 spin_lock_irqsave(&port->lock, flags);
38867 if (!tty_hung_up_p(filp))
38868- port->count++;
38869+ atomic_inc(&port->count);
38870 port->blocked_open--;
38871 if (retval == 0)
38872 port->flags |= ASYNC_NORMAL_ACTIVE;
38873@@ -326,19 +326,19 @@ int tty_port_close_start(struct tty_port *port,
38874 return 0;
38875 }
38876
38877- if (tty->count == 1 && port->count != 1) {
38878+ if (tty->count == 1 && atomic_read(&port->count) != 1) {
38879 printk(KERN_WARNING
38880 "tty_port_close_start: tty->count = 1 port count = %d.\n",
38881- port->count);
38882- port->count = 1;
38883+ atomic_read(&port->count));
38884+ atomic_set(&port->count, 1);
38885 }
38886- if (--port->count < 0) {
38887+ if (atomic_dec_return(&port->count) < 0) {
38888 printk(KERN_WARNING "tty_port_close_start: count = %d\n",
38889- port->count);
38890- port->count = 0;
38891+ atomic_read(&port->count));
38892+ atomic_set(&port->count, 0);
38893 }
38894
38895- if (port->count) {
38896+ if (atomic_read(&port->count)) {
38897 spin_unlock_irqrestore(&port->lock, flags);
38898 if (port->ops->drop)
38899 port->ops->drop(port);
38900@@ -418,7 +418,7 @@ int tty_port_open(struct tty_port *port, struct tty_struct *tty,
38901 {
38902 spin_lock_irq(&port->lock);
38903 if (!tty_hung_up_p(filp))
38904- ++port->count;
38905+ atomic_inc(&port->count);
38906 spin_unlock_irq(&port->lock);
38907 tty_port_tty_set(port, tty);
38908
38909diff --git a/drivers/tty/vt/keyboard.c b/drivers/tty/vt/keyboard.c
38910index 770a854..e5d3db3 100644
38911--- a/drivers/tty/vt/keyboard.c
38912+++ b/drivers/tty/vt/keyboard.c
38913@@ -659,6 +659,16 @@ static void k_spec(struct vc_data *vc, unsigned char value, char up_flag)
38914 kbd->kbdmode == VC_OFF) &&
38915 value != KVAL(K_SAK))
38916 return; /* SAK is allowed even in raw mode */
38917+
38918+#if defined(CONFIG_GRKERNSEC_PROC) || defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
38919+ {
38920+ void *func = fn_handler[value];
38921+ if (func == fn_show_state || func == fn_show_ptregs ||
38922+ func == fn_show_mem)
38923+ return;
38924+ }
38925+#endif
38926+
38927 fn_handler[value](vc);
38928 }
38929
38930@@ -1805,9 +1815,6 @@ int vt_do_kdsk_ioctl(int cmd, struct kbentry __user *user_kbe, int perm,
38931 if (copy_from_user(&tmp, user_kbe, sizeof(struct kbentry)))
38932 return -EFAULT;
38933
38934- if (!capable(CAP_SYS_TTY_CONFIG))
38935- perm = 0;
38936-
38937 switch (cmd) {
38938 case KDGKBENT:
38939 /* Ensure another thread doesn't free it under us */
38940@@ -1822,6 +1829,9 @@ int vt_do_kdsk_ioctl(int cmd, struct kbentry __user *user_kbe, int perm,
38941 spin_unlock_irqrestore(&kbd_event_lock, flags);
38942 return put_user(val, &user_kbe->kb_value);
38943 case KDSKBENT:
38944+ if (!capable(CAP_SYS_TTY_CONFIG))
38945+ perm = 0;
38946+
38947 if (!perm)
38948 return -EPERM;
38949 if (!i && v == K_NOSUCHMAP) {
38950@@ -1912,9 +1922,6 @@ int vt_do_kdgkb_ioctl(int cmd, struct kbsentry __user *user_kdgkb, int perm)
38951 int i, j, k;
38952 int ret;
38953
38954- if (!capable(CAP_SYS_TTY_CONFIG))
38955- perm = 0;
38956-
38957 kbs = kmalloc(sizeof(*kbs), GFP_KERNEL);
38958 if (!kbs) {
38959 ret = -ENOMEM;
38960@@ -1948,6 +1955,9 @@ int vt_do_kdgkb_ioctl(int cmd, struct kbsentry __user *user_kdgkb, int perm)
38961 kfree(kbs);
38962 return ((p && *p) ? -EOVERFLOW : 0);
38963 case KDSKBSENT:
38964+ if (!capable(CAP_SYS_TTY_CONFIG))
38965+ perm = 0;
38966+
38967 if (!perm) {
38968 ret = -EPERM;
38969 goto reterr;
38970diff --git a/drivers/uio/uio.c b/drivers/uio/uio.c
38971index a783d53..cb30d94 100644
38972--- a/drivers/uio/uio.c
38973+++ b/drivers/uio/uio.c
38974@@ -25,6 +25,7 @@
38975 #include <linux/kobject.h>
38976 #include <linux/cdev.h>
38977 #include <linux/uio_driver.h>
38978+#include <asm/local.h>
38979
38980 #define UIO_MAX_DEVICES (1U << MINORBITS)
38981
38982@@ -32,10 +33,10 @@ struct uio_device {
38983 struct module *owner;
38984 struct device *dev;
38985 int minor;
38986- atomic_t event;
38987+ atomic_unchecked_t event;
38988 struct fasync_struct *async_queue;
38989 wait_queue_head_t wait;
38990- int vma_count;
38991+ local_t vma_count;
38992 struct uio_info *info;
38993 struct kobject *map_dir;
38994 struct kobject *portio_dir;
38995@@ -242,7 +243,7 @@ static ssize_t show_event(struct device *dev,
38996 struct device_attribute *attr, char *buf)
38997 {
38998 struct uio_device *idev = dev_get_drvdata(dev);
38999- return sprintf(buf, "%u\n", (unsigned int)atomic_read(&idev->event));
39000+ return sprintf(buf, "%u\n", (unsigned int)atomic_read_unchecked(&idev->event));
39001 }
39002
39003 static struct device_attribute uio_class_attributes[] = {
39004@@ -408,7 +409,7 @@ void uio_event_notify(struct uio_info *info)
39005 {
39006 struct uio_device *idev = info->uio_dev;
39007
39008- atomic_inc(&idev->event);
39009+ atomic_inc_unchecked(&idev->event);
39010 wake_up_interruptible(&idev->wait);
39011 kill_fasync(&idev->async_queue, SIGIO, POLL_IN);
39012 }
39013@@ -461,7 +462,7 @@ static int uio_open(struct inode *inode, struct file *filep)
39014 }
39015
39016 listener->dev = idev;
39017- listener->event_count = atomic_read(&idev->event);
39018+ listener->event_count = atomic_read_unchecked(&idev->event);
39019 filep->private_data = listener;
39020
39021 if (idev->info->open) {
39022@@ -512,7 +513,7 @@ static unsigned int uio_poll(struct file *filep, poll_table *wait)
39023 return -EIO;
39024
39025 poll_wait(filep, &idev->wait, wait);
39026- if (listener->event_count != atomic_read(&idev->event))
39027+ if (listener->event_count != atomic_read_unchecked(&idev->event))
39028 return POLLIN | POLLRDNORM;
39029 return 0;
39030 }
39031@@ -537,7 +538,7 @@ static ssize_t uio_read(struct file *filep, char __user *buf,
39032 do {
39033 set_current_state(TASK_INTERRUPTIBLE);
39034
39035- event_count = atomic_read(&idev->event);
39036+ event_count = atomic_read_unchecked(&idev->event);
39037 if (event_count != listener->event_count) {
39038 if (copy_to_user(buf, &event_count, count))
39039 retval = -EFAULT;
39040@@ -606,13 +607,13 @@ static int uio_find_mem_index(struct vm_area_struct *vma)
39041 static void uio_vma_open(struct vm_area_struct *vma)
39042 {
39043 struct uio_device *idev = vma->vm_private_data;
39044- idev->vma_count++;
39045+ local_inc(&idev->vma_count);
39046 }
39047
39048 static void uio_vma_close(struct vm_area_struct *vma)
39049 {
39050 struct uio_device *idev = vma->vm_private_data;
39051- idev->vma_count--;
39052+ local_dec(&idev->vma_count);
39053 }
39054
39055 static int uio_vma_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
39056@@ -821,7 +822,7 @@ int __uio_register_device(struct module *owner,
39057 idev->owner = owner;
39058 idev->info = info;
39059 init_waitqueue_head(&idev->wait);
39060- atomic_set(&idev->event, 0);
39061+ atomic_set_unchecked(&idev->event, 0);
39062
39063 ret = uio_get_minor(idev);
39064 if (ret)
39065diff --git a/drivers/usb/atm/cxacru.c b/drivers/usb/atm/cxacru.c
39066index b7eb86a..36d28af 100644
39067--- a/drivers/usb/atm/cxacru.c
39068+++ b/drivers/usb/atm/cxacru.c
39069@@ -473,7 +473,7 @@ static ssize_t cxacru_sysfs_store_adsl_config(struct device *dev,
39070 ret = sscanf(buf + pos, "%x=%x%n", &index, &value, &tmp);
39071 if (ret < 2)
39072 return -EINVAL;
39073- if (index < 0 || index > 0x7f)
39074+ if (index > 0x7f)
39075 return -EINVAL;
39076 pos += tmp;
39077
39078diff --git a/drivers/usb/atm/usbatm.c b/drivers/usb/atm/usbatm.c
39079index ee62b35..b663594 100644
39080--- a/drivers/usb/atm/usbatm.c
39081+++ b/drivers/usb/atm/usbatm.c
39082@@ -333,7 +333,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
39083 if (printk_ratelimit())
39084 atm_warn(instance, "%s: OAM not supported (vpi %d, vci %d)!\n",
39085 __func__, vpi, vci);
39086- atomic_inc(&vcc->stats->rx_err);
39087+ atomic_inc_unchecked(&vcc->stats->rx_err);
39088 return;
39089 }
39090
39091@@ -361,7 +361,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
39092 if (length > ATM_MAX_AAL5_PDU) {
39093 atm_rldbg(instance, "%s: bogus length %u (vcc: 0x%p)!\n",
39094 __func__, length, vcc);
39095- atomic_inc(&vcc->stats->rx_err);
39096+ atomic_inc_unchecked(&vcc->stats->rx_err);
39097 goto out;
39098 }
39099
39100@@ -370,14 +370,14 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
39101 if (sarb->len < pdu_length) {
39102 atm_rldbg(instance, "%s: bogus pdu_length %u (sarb->len: %u, vcc: 0x%p)!\n",
39103 __func__, pdu_length, sarb->len, vcc);
39104- atomic_inc(&vcc->stats->rx_err);
39105+ atomic_inc_unchecked(&vcc->stats->rx_err);
39106 goto out;
39107 }
39108
39109 if (crc32_be(~0, skb_tail_pointer(sarb) - pdu_length, pdu_length) != 0xc704dd7b) {
39110 atm_rldbg(instance, "%s: packet failed crc check (vcc: 0x%p)!\n",
39111 __func__, vcc);
39112- atomic_inc(&vcc->stats->rx_err);
39113+ atomic_inc_unchecked(&vcc->stats->rx_err);
39114 goto out;
39115 }
39116
39117@@ -387,7 +387,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
39118 if (printk_ratelimit())
39119 atm_err(instance, "%s: no memory for skb (length: %u)!\n",
39120 __func__, length);
39121- atomic_inc(&vcc->stats->rx_drop);
39122+ atomic_inc_unchecked(&vcc->stats->rx_drop);
39123 goto out;
39124 }
39125
39126@@ -412,7 +412,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
39127
39128 vcc->push(vcc, skb);
39129
39130- atomic_inc(&vcc->stats->rx);
39131+ atomic_inc_unchecked(&vcc->stats->rx);
39132 out:
39133 skb_trim(sarb, 0);
39134 }
39135@@ -615,7 +615,7 @@ static void usbatm_tx_process(unsigned long data)
39136 struct atm_vcc *vcc = UDSL_SKB(skb)->atm.vcc;
39137
39138 usbatm_pop(vcc, skb);
39139- atomic_inc(&vcc->stats->tx);
39140+ atomic_inc_unchecked(&vcc->stats->tx);
39141
39142 skb = skb_dequeue(&instance->sndqueue);
39143 }
39144@@ -770,11 +770,11 @@ static int usbatm_atm_proc_read(struct atm_dev *atm_dev, loff_t * pos, char *pag
39145 if (!left--)
39146 return sprintf(page,
39147 "AAL5: tx %d ( %d err ), rx %d ( %d err, %d drop )\n",
39148- atomic_read(&atm_dev->stats.aal5.tx),
39149- atomic_read(&atm_dev->stats.aal5.tx_err),
39150- atomic_read(&atm_dev->stats.aal5.rx),
39151- atomic_read(&atm_dev->stats.aal5.rx_err),
39152- atomic_read(&atm_dev->stats.aal5.rx_drop));
39153+ atomic_read_unchecked(&atm_dev->stats.aal5.tx),
39154+ atomic_read_unchecked(&atm_dev->stats.aal5.tx_err),
39155+ atomic_read_unchecked(&atm_dev->stats.aal5.rx),
39156+ atomic_read_unchecked(&atm_dev->stats.aal5.rx_err),
39157+ atomic_read_unchecked(&atm_dev->stats.aal5.rx_drop));
39158
39159 if (!left--) {
39160 if (instance->disconnected)
39161diff --git a/drivers/usb/core/devices.c b/drivers/usb/core/devices.c
39162index 3440812..2a4ef1f 100644
39163--- a/drivers/usb/core/devices.c
39164+++ b/drivers/usb/core/devices.c
39165@@ -126,7 +126,7 @@ static const char format_endpt[] =
39166 * time it gets called.
39167 */
39168 static struct device_connect_event {
39169- atomic_t count;
39170+ atomic_unchecked_t count;
39171 wait_queue_head_t wait;
39172 } device_event = {
39173 .count = ATOMIC_INIT(1),
39174@@ -164,7 +164,7 @@ static const struct class_info clas_info[] = {
39175
39176 void usbfs_conn_disc_event(void)
39177 {
39178- atomic_add(2, &device_event.count);
39179+ atomic_add_unchecked(2, &device_event.count);
39180 wake_up(&device_event.wait);
39181 }
39182
39183@@ -648,7 +648,7 @@ static unsigned int usb_device_poll(struct file *file,
39184
39185 poll_wait(file, &device_event.wait, wait);
39186
39187- event_count = atomic_read(&device_event.count);
39188+ event_count = atomic_read_unchecked(&device_event.count);
39189 if (file->f_version != event_count) {
39190 file->f_version = event_count;
39191 return POLLIN | POLLRDNORM;
39192diff --git a/drivers/usb/early/ehci-dbgp.c b/drivers/usb/early/ehci-dbgp.c
39193index 89dcf15..481800b 100644
39194--- a/drivers/usb/early/ehci-dbgp.c
39195+++ b/drivers/usb/early/ehci-dbgp.c
39196@@ -97,7 +97,8 @@ static inline u32 dbgp_len_update(u32 x, u32 len)
39197
39198 #ifdef CONFIG_KGDB
39199 static struct kgdb_io kgdbdbgp_io_ops;
39200-#define dbgp_kgdb_mode (dbg_io_ops == &kgdbdbgp_io_ops)
39201+static struct kgdb_io kgdbdbgp_io_ops_console;
39202+#define dbgp_kgdb_mode (dbg_io_ops == &kgdbdbgp_io_ops || dbg_io_ops == &kgdbdbgp_io_ops_console)
39203 #else
39204 #define dbgp_kgdb_mode (0)
39205 #endif
39206@@ -1035,6 +1036,13 @@ static struct kgdb_io kgdbdbgp_io_ops = {
39207 .write_char = kgdbdbgp_write_char,
39208 };
39209
39210+static struct kgdb_io kgdbdbgp_io_ops_console = {
39211+ .name = "kgdbdbgp",
39212+ .read_char = kgdbdbgp_read_char,
39213+ .write_char = kgdbdbgp_write_char,
39214+ .is_console = 1
39215+};
39216+
39217 static int kgdbdbgp_wait_time;
39218
39219 static int __init kgdbdbgp_parse_config(char *str)
39220@@ -1050,8 +1058,10 @@ static int __init kgdbdbgp_parse_config(char *str)
39221 ptr++;
39222 kgdbdbgp_wait_time = simple_strtoul(ptr, &ptr, 10);
39223 }
39224- kgdb_register_io_module(&kgdbdbgp_io_ops);
39225- kgdbdbgp_io_ops.is_console = early_dbgp_console.index != -1;
39226+ if (early_dbgp_console.index != -1)
39227+ kgdb_register_io_module(&kgdbdbgp_io_ops_console);
39228+ else
39229+ kgdb_register_io_module(&kgdbdbgp_io_ops);
39230
39231 return 0;
39232 }
39233diff --git a/drivers/usb/gadget/u_serial.c b/drivers/usb/gadget/u_serial.c
39234index da6d479..80ed10b 100644
39235--- a/drivers/usb/gadget/u_serial.c
39236+++ b/drivers/usb/gadget/u_serial.c
39237@@ -735,9 +735,9 @@ static int gs_open(struct tty_struct *tty, struct file *file)
39238 spin_lock_irq(&port->port_lock);
39239
39240 /* already open? Great. */
39241- if (port->port.count) {
39242+ if (atomic_read(&port->port.count)) {
39243 status = 0;
39244- port->port.count++;
39245+ atomic_inc(&port->port.count);
39246
39247 /* currently opening/closing? wait ... */
39248 } else if (port->openclose) {
39249@@ -796,7 +796,7 @@ static int gs_open(struct tty_struct *tty, struct file *file)
39250 tty->driver_data = port;
39251 port->port.tty = tty;
39252
39253- port->port.count = 1;
39254+ atomic_set(&port->port.count, 1);
39255 port->openclose = false;
39256
39257 /* if connected, start the I/O stream */
39258@@ -838,11 +838,11 @@ static void gs_close(struct tty_struct *tty, struct file *file)
39259
39260 spin_lock_irq(&port->port_lock);
39261
39262- if (port->port.count != 1) {
39263- if (port->port.count == 0)
39264+ if (atomic_read(&port->port.count) != 1) {
39265+ if (atomic_read(&port->port.count) == 0)
39266 WARN_ON(1);
39267 else
39268- --port->port.count;
39269+ atomic_dec(&port->port.count);
39270 goto exit;
39271 }
39272
39273@@ -852,7 +852,7 @@ static void gs_close(struct tty_struct *tty, struct file *file)
39274 * and sleep if necessary
39275 */
39276 port->openclose = true;
39277- port->port.count = 0;
39278+ atomic_set(&port->port.count, 0);
39279
39280 gser = port->port_usb;
39281 if (gser && gser->disconnect)
39282@@ -1156,7 +1156,7 @@ static int gs_closed(struct gs_port *port)
39283 int cond;
39284
39285 spin_lock_irq(&port->port_lock);
39286- cond = (port->port.count == 0) && !port->openclose;
39287+ cond = (atomic_read(&port->port.count) == 0) && !port->openclose;
39288 spin_unlock_irq(&port->port_lock);
39289 return cond;
39290 }
39291@@ -1269,7 +1269,7 @@ int gserial_connect(struct gserial *gser, u8 port_num)
39292 /* if it's already open, start I/O ... and notify the serial
39293 * protocol about open/close status (connect/disconnect).
39294 */
39295- if (port->port.count) {
39296+ if (atomic_read(&port->port.count)) {
39297 pr_debug("gserial_connect: start ttyGS%d\n", port->port_num);
39298 gs_start_io(port);
39299 if (gser->connect)
39300@@ -1316,7 +1316,7 @@ void gserial_disconnect(struct gserial *gser)
39301
39302 port->port_usb = NULL;
39303 gser->ioport = NULL;
39304- if (port->port.count > 0 || port->openclose) {
39305+ if (atomic_read(&port->port.count) > 0 || port->openclose) {
39306 wake_up_interruptible(&port->drain_wait);
39307 if (port->port.tty)
39308 tty_hangup(port->port.tty);
39309@@ -1332,7 +1332,7 @@ void gserial_disconnect(struct gserial *gser)
39310
39311 /* finally, free any unused/unusable I/O buffers */
39312 spin_lock_irqsave(&port->port_lock, flags);
39313- if (port->port.count == 0 && !port->openclose)
39314+ if (atomic_read(&port->port.count) == 0 && !port->openclose)
39315 gs_buf_free(&port->port_write_buf);
39316 gs_free_requests(gser->out, &port->read_pool, NULL);
39317 gs_free_requests(gser->out, &port->read_queue, NULL);
39318diff --git a/drivers/usb/serial/console.c b/drivers/usb/serial/console.c
39319index b9cca6d..75c75df 100644
39320--- a/drivers/usb/serial/console.c
39321+++ b/drivers/usb/serial/console.c
39322@@ -127,7 +127,7 @@ static int usb_console_setup(struct console *co, char *options)
39323
39324 info->port = port;
39325
39326- ++port->port.count;
39327+ atomic_inc(&port->port.count);
39328 if (!test_bit(ASYNCB_INITIALIZED, &port->port.flags)) {
39329 if (serial->type->set_termios) {
39330 /*
39331@@ -177,7 +177,7 @@ static int usb_console_setup(struct console *co, char *options)
39332 }
39333 /* Now that any required fake tty operations are completed restore
39334 * the tty port count */
39335- --port->port.count;
39336+ atomic_dec(&port->port.count);
39337 /* The console is special in terms of closing the device so
39338 * indicate this port is now acting as a system console. */
39339 port->port.console = 1;
39340@@ -190,7 +190,7 @@ static int usb_console_setup(struct console *co, char *options)
39341 free_tty:
39342 kfree(tty);
39343 reset_open_count:
39344- port->port.count = 0;
39345+ atomic_set(&port->port.count, 0);
39346 usb_autopm_put_interface(serial->interface);
39347 error_get_interface:
39348 usb_serial_put(serial);
39349diff --git a/drivers/usb/wusbcore/wa-hc.h b/drivers/usb/wusbcore/wa-hc.h
39350index d6bea3e..60b250e 100644
39351--- a/drivers/usb/wusbcore/wa-hc.h
39352+++ b/drivers/usb/wusbcore/wa-hc.h
39353@@ -192,7 +192,7 @@ struct wahc {
39354 struct list_head xfer_delayed_list;
39355 spinlock_t xfer_list_lock;
39356 struct work_struct xfer_work;
39357- atomic_t xfer_id_count;
39358+ atomic_unchecked_t xfer_id_count;
39359 };
39360
39361
39362@@ -246,7 +246,7 @@ static inline void wa_init(struct wahc *wa)
39363 INIT_LIST_HEAD(&wa->xfer_delayed_list);
39364 spin_lock_init(&wa->xfer_list_lock);
39365 INIT_WORK(&wa->xfer_work, wa_urb_enqueue_run);
39366- atomic_set(&wa->xfer_id_count, 1);
39367+ atomic_set_unchecked(&wa->xfer_id_count, 1);
39368 }
39369
39370 /**
39371diff --git a/drivers/usb/wusbcore/wa-xfer.c b/drivers/usb/wusbcore/wa-xfer.c
39372index 57c01ab..8a05959 100644
39373--- a/drivers/usb/wusbcore/wa-xfer.c
39374+++ b/drivers/usb/wusbcore/wa-xfer.c
39375@@ -296,7 +296,7 @@ out:
39376 */
39377 static void wa_xfer_id_init(struct wa_xfer *xfer)
39378 {
39379- xfer->id = atomic_add_return(1, &xfer->wa->xfer_id_count);
39380+ xfer->id = atomic_add_return_unchecked(1, &xfer->wa->xfer_id_count);
39381 }
39382
39383 /*
39384diff --git a/drivers/vhost/vhost.c b/drivers/vhost/vhost.c
39385index ef82a0d..da8a0b3 100644
39386--- a/drivers/vhost/vhost.c
39387+++ b/drivers/vhost/vhost.c
39388@@ -634,7 +634,7 @@ static long vhost_set_memory(struct vhost_dev *d, struct vhost_memory __user *m)
39389 return 0;
39390 }
39391
39392-static long vhost_set_vring(struct vhost_dev *d, int ioctl, void __user *argp)
39393+static long vhost_set_vring(struct vhost_dev *d, unsigned int ioctl, void __user *argp)
39394 {
39395 struct file *eventfp, *filep = NULL,
39396 *pollstart = NULL, *pollstop = NULL;
39397diff --git a/drivers/video/aty/aty128fb.c b/drivers/video/aty/aty128fb.c
39398index 747442d..7c0c434 100644
39399--- a/drivers/video/aty/aty128fb.c
39400+++ b/drivers/video/aty/aty128fb.c
39401@@ -149,7 +149,7 @@ enum {
39402 };
39403
39404 /* Must match above enum */
39405-static const char *r128_family[] __devinitdata = {
39406+static const char *r128_family[] __devinitconst = {
39407 "AGP",
39408 "PCI",
39409 "PRO AGP",
39410diff --git a/drivers/video/fbcmap.c b/drivers/video/fbcmap.c
39411index 5c3960d..15cf8fc 100644
39412--- a/drivers/video/fbcmap.c
39413+++ b/drivers/video/fbcmap.c
39414@@ -285,8 +285,7 @@ int fb_set_user_cmap(struct fb_cmap_user *cmap, struct fb_info *info)
39415 rc = -ENODEV;
39416 goto out;
39417 }
39418- if (cmap->start < 0 || (!info->fbops->fb_setcolreg &&
39419- !info->fbops->fb_setcmap)) {
39420+ if (!info->fbops->fb_setcolreg && !info->fbops->fb_setcmap) {
39421 rc = -EINVAL;
39422 goto out1;
39423 }
39424diff --git a/drivers/video/fbmem.c b/drivers/video/fbmem.c
39425index 0dff12a..2ef47b3 100644
39426--- a/drivers/video/fbmem.c
39427+++ b/drivers/video/fbmem.c
39428@@ -428,7 +428,7 @@ static void fb_do_show_logo(struct fb_info *info, struct fb_image *image,
39429 image->dx += image->width + 8;
39430 }
39431 } else if (rotate == FB_ROTATE_UD) {
39432- for (x = 0; x < num && image->dx >= 0; x++) {
39433+ for (x = 0; x < num && (__s32)image->dx >= 0; x++) {
39434 info->fbops->fb_imageblit(info, image);
39435 image->dx -= image->width + 8;
39436 }
39437@@ -440,7 +440,7 @@ static void fb_do_show_logo(struct fb_info *info, struct fb_image *image,
39438 image->dy += image->height + 8;
39439 }
39440 } else if (rotate == FB_ROTATE_CCW) {
39441- for (x = 0; x < num && image->dy >= 0; x++) {
39442+ for (x = 0; x < num && (__s32)image->dy >= 0; x++) {
39443 info->fbops->fb_imageblit(info, image);
39444 image->dy -= image->height + 8;
39445 }
39446@@ -1166,7 +1166,7 @@ static long do_fb_ioctl(struct fb_info *info, unsigned int cmd,
39447 return -EFAULT;
39448 if (con2fb.console < 1 || con2fb.console > MAX_NR_CONSOLES)
39449 return -EINVAL;
39450- if (con2fb.framebuffer < 0 || con2fb.framebuffer >= FB_MAX)
39451+ if (con2fb.framebuffer >= FB_MAX)
39452 return -EINVAL;
39453 if (!registered_fb[con2fb.framebuffer])
39454 request_module("fb%d", con2fb.framebuffer);
39455diff --git a/drivers/video/geode/gx1fb_core.c b/drivers/video/geode/gx1fb_core.c
39456index 5a5d092..265c5ed 100644
39457--- a/drivers/video/geode/gx1fb_core.c
39458+++ b/drivers/video/geode/gx1fb_core.c
39459@@ -29,7 +29,7 @@ static int crt_option = 1;
39460 static char panel_option[32] = "";
39461
39462 /* Modes relevant to the GX1 (taken from modedb.c) */
39463-static const struct fb_videomode __devinitdata gx1_modedb[] = {
39464+static const struct fb_videomode __devinitconst gx1_modedb[] = {
39465 /* 640x480-60 VESA */
39466 { NULL, 60, 640, 480, 39682, 48, 16, 33, 10, 96, 2,
39467 0, FB_VMODE_NONINTERLACED, FB_MODE_IS_VESA },
39468diff --git a/drivers/video/gxt4500.c b/drivers/video/gxt4500.c
39469index 0fad23f..0e9afa4 100644
39470--- a/drivers/video/gxt4500.c
39471+++ b/drivers/video/gxt4500.c
39472@@ -156,7 +156,7 @@ struct gxt4500_par {
39473 static char *mode_option;
39474
39475 /* default mode: 1280x1024 @ 60 Hz, 8 bpp */
39476-static const struct fb_videomode defaultmode __devinitdata = {
39477+static const struct fb_videomode defaultmode __devinitconst = {
39478 .refresh = 60,
39479 .xres = 1280,
39480 .yres = 1024,
39481@@ -581,7 +581,7 @@ static int gxt4500_blank(int blank, struct fb_info *info)
39482 return 0;
39483 }
39484
39485-static const struct fb_fix_screeninfo gxt4500_fix __devinitdata = {
39486+static const struct fb_fix_screeninfo gxt4500_fix __devinitconst = {
39487 .id = "IBM GXT4500P",
39488 .type = FB_TYPE_PACKED_PIXELS,
39489 .visual = FB_VISUAL_PSEUDOCOLOR,
39490diff --git a/drivers/video/i810/i810_accel.c b/drivers/video/i810/i810_accel.c
39491index 7672d2e..b56437f 100644
39492--- a/drivers/video/i810/i810_accel.c
39493+++ b/drivers/video/i810/i810_accel.c
39494@@ -73,6 +73,7 @@ static inline int wait_for_space(struct fb_info *info, u32 space)
39495 }
39496 }
39497 printk("ringbuffer lockup!!!\n");
39498+ printk("head:%u tail:%u iring.size:%u space:%u\n", head, tail, par->iring.size, space);
39499 i810_report_error(mmio);
39500 par->dev_flags |= LOCKUP;
39501 info->pixmap.scan_align = 1;
39502diff --git a/drivers/video/i810/i810_main.c b/drivers/video/i810/i810_main.c
39503index b83f361..2b05a91 100644
39504--- a/drivers/video/i810/i810_main.c
39505+++ b/drivers/video/i810/i810_main.c
39506@@ -97,7 +97,7 @@ static int i810fb_blank (int blank_mode, struct fb_info *info);
39507 static void i810fb_release_resource (struct fb_info *info, struct i810fb_par *par);
39508
39509 /* PCI */
39510-static const char *i810_pci_list[] __devinitdata = {
39511+static const char *i810_pci_list[] __devinitconst = {
39512 "Intel(R) 810 Framebuffer Device" ,
39513 "Intel(R) 810-DC100 Framebuffer Device" ,
39514 "Intel(R) 810E Framebuffer Device" ,
39515diff --git a/drivers/video/jz4740_fb.c b/drivers/video/jz4740_fb.c
39516index de36693..3c63fc2 100644
39517--- a/drivers/video/jz4740_fb.c
39518+++ b/drivers/video/jz4740_fb.c
39519@@ -136,7 +136,7 @@ struct jzfb {
39520 uint32_t pseudo_palette[16];
39521 };
39522
39523-static const struct fb_fix_screeninfo jzfb_fix __devinitdata = {
39524+static const struct fb_fix_screeninfo jzfb_fix __devinitconst = {
39525 .id = "JZ4740 FB",
39526 .type = FB_TYPE_PACKED_PIXELS,
39527 .visual = FB_VISUAL_TRUECOLOR,
39528diff --git a/drivers/video/logo/logo_linux_clut224.ppm b/drivers/video/logo/logo_linux_clut224.ppm
39529index 3c14e43..eafa544 100644
39530--- a/drivers/video/logo/logo_linux_clut224.ppm
39531+++ b/drivers/video/logo/logo_linux_clut224.ppm
39532@@ -1,1604 +1,1123 @@
39533 P3
39534-# Standard 224-color Linux logo
39535 80 80
39536 255
39537- 0 0 0 0 0 0 0 0 0 0 0 0
39538- 0 0 0 0 0 0 0 0 0 0 0 0
39539- 0 0 0 0 0 0 0 0 0 0 0 0
39540- 0 0 0 0 0 0 0 0 0 0 0 0
39541- 0 0 0 0 0 0 0 0 0 0 0 0
39542- 0 0 0 0 0 0 0 0 0 0 0 0
39543- 0 0 0 0 0 0 0 0 0 0 0 0
39544- 0 0 0 0 0 0 0 0 0 0 0 0
39545- 0 0 0 0 0 0 0 0 0 0 0 0
39546- 6 6 6 6 6 6 10 10 10 10 10 10
39547- 10 10 10 6 6 6 6 6 6 6 6 6
39548- 0 0 0 0 0 0 0 0 0 0 0 0
39549- 0 0 0 0 0 0 0 0 0 0 0 0
39550- 0 0 0 0 0 0 0 0 0 0 0 0
39551- 0 0 0 0 0 0 0 0 0 0 0 0
39552- 0 0 0 0 0 0 0 0 0 0 0 0
39553- 0 0 0 0 0 0 0 0 0 0 0 0
39554- 0 0 0 0 0 0 0 0 0 0 0 0
39555- 0 0 0 0 0 0 0 0 0 0 0 0
39556- 0 0 0 0 0 0 0 0 0 0 0 0
39557- 0 0 0 0 0 0 0 0 0 0 0 0
39558- 0 0 0 0 0 0 0 0 0 0 0 0
39559- 0 0 0 0 0 0 0 0 0 0 0 0
39560- 0 0 0 0 0 0 0 0 0 0 0 0
39561- 0 0 0 0 0 0 0 0 0 0 0 0
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 6 6 6 10 10 10 14 14 14
39566- 22 22 22 26 26 26 30 30 30 34 34 34
39567- 30 30 30 30 30 30 26 26 26 18 18 18
39568- 14 14 14 10 10 10 6 6 6 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- 0 0 0 0 0 0 0 0 0 0 0 0
39572- 0 0 0 0 0 0 0 0 0 0 0 0
39573- 0 0 0 0 0 0 0 0 0 0 0 0
39574- 0 0 0 0 0 0 0 0 0 0 0 0
39575- 0 0 0 0 0 0 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 1 0 0 1 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- 6 6 6 14 14 14 26 26 26 42 42 42
39586- 54 54 54 66 66 66 78 78 78 78 78 78
39587- 78 78 78 74 74 74 66 66 66 54 54 54
39588- 42 42 42 26 26 26 18 18 18 10 10 10
39589- 6 6 6 0 0 0 0 0 0 0 0 0
39590- 0 0 0 0 0 0 0 0 0 0 0 0
39591- 0 0 0 0 0 0 0 0 0 0 0 0
39592- 0 0 0 0 0 0 0 0 0 0 0 0
39593- 0 0 0 0 0 0 0 0 0 0 0 0
39594- 0 0 0 0 0 0 0 0 0 0 0 0
39595- 0 0 0 0 0 0 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 1 0 0 0 0 0 0 0 0 0
39599- 0 0 0 0 0 0 0 0 0 0 0 0
39600- 0 0 0 0 0 0 0 0 0 0 0 0
39601- 0 0 0 0 0 0 0 0 0 0 0 0
39602- 0 0 0 0 0 0 0 0 0 0 0 0
39603- 0 0 0 0 0 0 0 0 0 0 0 0
39604- 0 0 0 0 0 0 0 0 0 10 10 10
39605- 22 22 22 42 42 42 66 66 66 86 86 86
39606- 66 66 66 38 38 38 38 38 38 22 22 22
39607- 26 26 26 34 34 34 54 54 54 66 66 66
39608- 86 86 86 70 70 70 46 46 46 26 26 26
39609- 14 14 14 6 6 6 0 0 0 0 0 0
39610- 0 0 0 0 0 0 0 0 0 0 0 0
39611- 0 0 0 0 0 0 0 0 0 0 0 0
39612- 0 0 0 0 0 0 0 0 0 0 0 0
39613- 0 0 0 0 0 0 0 0 0 0 0 0
39614- 0 0 0 0 0 0 0 0 0 0 0 0
39615- 0 0 0 0 0 0 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 1 0 0 1 0 0 1 0 0 0
39619- 0 0 0 0 0 0 0 0 0 0 0 0
39620- 0 0 0 0 0 0 0 0 0 0 0 0
39621- 0 0 0 0 0 0 0 0 0 0 0 0
39622- 0 0 0 0 0 0 0 0 0 0 0 0
39623- 0 0 0 0 0 0 0 0 0 0 0 0
39624- 0 0 0 0 0 0 10 10 10 26 26 26
39625- 50 50 50 82 82 82 58 58 58 6 6 6
39626- 2 2 6 2 2 6 2 2 6 2 2 6
39627- 2 2 6 2 2 6 2 2 6 2 2 6
39628- 6 6 6 54 54 54 86 86 86 66 66 66
39629- 38 38 38 18 18 18 6 6 6 0 0 0
39630- 0 0 0 0 0 0 0 0 0 0 0 0
39631- 0 0 0 0 0 0 0 0 0 0 0 0
39632- 0 0 0 0 0 0 0 0 0 0 0 0
39633- 0 0 0 0 0 0 0 0 0 0 0 0
39634- 0 0 0 0 0 0 0 0 0 0 0 0
39635- 0 0 0 0 0 0 0 0 0 0 0 0
39636- 0 0 0 0 0 0 0 0 0 0 0 0
39637- 0 0 0 0 0 0 0 0 0 0 0 0
39638- 0 0 0 0 0 0 0 0 0 0 0 0
39639- 0 0 0 0 0 0 0 0 0 0 0 0
39640- 0 0 0 0 0 0 0 0 0 0 0 0
39641- 0 0 0 0 0 0 0 0 0 0 0 0
39642- 0 0 0 0 0 0 0 0 0 0 0 0
39643- 0 0 0 0 0 0 0 0 0 0 0 0
39644- 0 0 0 6 6 6 22 22 22 50 50 50
39645- 78 78 78 34 34 34 2 2 6 2 2 6
39646- 2 2 6 2 2 6 2 2 6 2 2 6
39647- 2 2 6 2 2 6 2 2 6 2 2 6
39648- 2 2 6 2 2 6 6 6 6 70 70 70
39649- 78 78 78 46 46 46 22 22 22 6 6 6
39650- 0 0 0 0 0 0 0 0 0 0 0 0
39651- 0 0 0 0 0 0 0 0 0 0 0 0
39652- 0 0 0 0 0 0 0 0 0 0 0 0
39653- 0 0 0 0 0 0 0 0 0 0 0 0
39654- 0 0 0 0 0 0 0 0 0 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 1 0 0 1 0 0 1 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- 6 6 6 18 18 18 42 42 42 82 82 82
39665- 26 26 26 2 2 6 2 2 6 2 2 6
39666- 2 2 6 2 2 6 2 2 6 2 2 6
39667- 2 2 6 2 2 6 2 2 6 14 14 14
39668- 46 46 46 34 34 34 6 6 6 2 2 6
39669- 42 42 42 78 78 78 42 42 42 18 18 18
39670- 6 6 6 0 0 0 0 0 0 0 0 0
39671- 0 0 0 0 0 0 0 0 0 0 0 0
39672- 0 0 0 0 0 0 0 0 0 0 0 0
39673- 0 0 0 0 0 0 0 0 0 0 0 0
39674- 0 0 0 0 0 0 0 0 0 0 0 0
39675- 0 0 0 0 0 0 0 0 0 0 0 0
39676- 0 0 0 0 0 0 0 0 0 0 0 0
39677- 0 0 0 0 0 0 0 0 0 0 0 0
39678- 0 0 1 0 0 0 0 0 1 0 0 0
39679- 0 0 0 0 0 0 0 0 0 0 0 0
39680- 0 0 0 0 0 0 0 0 0 0 0 0
39681- 0 0 0 0 0 0 0 0 0 0 0 0
39682- 0 0 0 0 0 0 0 0 0 0 0 0
39683- 0 0 0 0 0 0 0 0 0 0 0 0
39684- 10 10 10 30 30 30 66 66 66 58 58 58
39685- 2 2 6 2 2 6 2 2 6 2 2 6
39686- 2 2 6 2 2 6 2 2 6 2 2 6
39687- 2 2 6 2 2 6 2 2 6 26 26 26
39688- 86 86 86 101 101 101 46 46 46 10 10 10
39689- 2 2 6 58 58 58 70 70 70 34 34 34
39690- 10 10 10 0 0 0 0 0 0 0 0 0
39691- 0 0 0 0 0 0 0 0 0 0 0 0
39692- 0 0 0 0 0 0 0 0 0 0 0 0
39693- 0 0 0 0 0 0 0 0 0 0 0 0
39694- 0 0 0 0 0 0 0 0 0 0 0 0
39695- 0 0 0 0 0 0 0 0 0 0 0 0
39696- 0 0 0 0 0 0 0 0 0 0 0 0
39697- 0 0 0 0 0 0 0 0 0 0 0 0
39698- 0 0 1 0 0 1 0 0 1 0 0 0
39699- 0 0 0 0 0 0 0 0 0 0 0 0
39700- 0 0 0 0 0 0 0 0 0 0 0 0
39701- 0 0 0 0 0 0 0 0 0 0 0 0
39702- 0 0 0 0 0 0 0 0 0 0 0 0
39703- 0 0 0 0 0 0 0 0 0 0 0 0
39704- 14 14 14 42 42 42 86 86 86 10 10 10
39705- 2 2 6 2 2 6 2 2 6 2 2 6
39706- 2 2 6 2 2 6 2 2 6 2 2 6
39707- 2 2 6 2 2 6 2 2 6 30 30 30
39708- 94 94 94 94 94 94 58 58 58 26 26 26
39709- 2 2 6 6 6 6 78 78 78 54 54 54
39710- 22 22 22 6 6 6 0 0 0 0 0 0
39711- 0 0 0 0 0 0 0 0 0 0 0 0
39712- 0 0 0 0 0 0 0 0 0 0 0 0
39713- 0 0 0 0 0 0 0 0 0 0 0 0
39714- 0 0 0 0 0 0 0 0 0 0 0 0
39715- 0 0 0 0 0 0 0 0 0 0 0 0
39716- 0 0 0 0 0 0 0 0 0 0 0 0
39717- 0 0 0 0 0 0 0 0 0 0 0 0
39718- 0 0 0 0 0 0 0 0 0 0 0 0
39719- 0 0 0 0 0 0 0 0 0 0 0 0
39720- 0 0 0 0 0 0 0 0 0 0 0 0
39721- 0 0 0 0 0 0 0 0 0 0 0 0
39722- 0 0 0 0 0 0 0 0 0 0 0 0
39723- 0 0 0 0 0 0 0 0 0 6 6 6
39724- 22 22 22 62 62 62 62 62 62 2 2 6
39725- 2 2 6 2 2 6 2 2 6 2 2 6
39726- 2 2 6 2 2 6 2 2 6 2 2 6
39727- 2 2 6 2 2 6 2 2 6 26 26 26
39728- 54 54 54 38 38 38 18 18 18 10 10 10
39729- 2 2 6 2 2 6 34 34 34 82 82 82
39730- 38 38 38 14 14 14 0 0 0 0 0 0
39731- 0 0 0 0 0 0 0 0 0 0 0 0
39732- 0 0 0 0 0 0 0 0 0 0 0 0
39733- 0 0 0 0 0 0 0 0 0 0 0 0
39734- 0 0 0 0 0 0 0 0 0 0 0 0
39735- 0 0 0 0 0 0 0 0 0 0 0 0
39736- 0 0 0 0 0 0 0 0 0 0 0 0
39737- 0 0 0 0 0 0 0 0 0 0 0 0
39738- 0 0 0 0 0 1 0 0 1 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 6 6 6
39744- 30 30 30 78 78 78 30 30 30 2 2 6
39745- 2 2 6 2 2 6 2 2 6 2 2 6
39746- 2 2 6 2 2 6 2 2 6 2 2 6
39747- 2 2 6 2 2 6 2 2 6 10 10 10
39748- 10 10 10 2 2 6 2 2 6 2 2 6
39749- 2 2 6 2 2 6 2 2 6 78 78 78
39750- 50 50 50 18 18 18 6 6 6 0 0 0
39751- 0 0 0 0 0 0 0 0 0 0 0 0
39752- 0 0 0 0 0 0 0 0 0 0 0 0
39753- 0 0 0 0 0 0 0 0 0 0 0 0
39754- 0 0 0 0 0 0 0 0 0 0 0 0
39755- 0 0 0 0 0 0 0 0 0 0 0 0
39756- 0 0 0 0 0 0 0 0 0 0 0 0
39757- 0 0 0 0 0 0 0 0 0 0 0 0
39758- 0 0 1 0 0 0 0 0 0 0 0 0
39759- 0 0 0 0 0 0 0 0 0 0 0 0
39760- 0 0 0 0 0 0 0 0 0 0 0 0
39761- 0 0 0 0 0 0 0 0 0 0 0 0
39762- 0 0 0 0 0 0 0 0 0 0 0 0
39763- 0 0 0 0 0 0 0 0 0 10 10 10
39764- 38 38 38 86 86 86 14 14 14 2 2 6
39765- 2 2 6 2 2 6 2 2 6 2 2 6
39766- 2 2 6 2 2 6 2 2 6 2 2 6
39767- 2 2 6 2 2 6 2 2 6 2 2 6
39768- 2 2 6 2 2 6 2 2 6 2 2 6
39769- 2 2 6 2 2 6 2 2 6 54 54 54
39770- 66 66 66 26 26 26 6 6 6 0 0 0
39771- 0 0 0 0 0 0 0 0 0 0 0 0
39772- 0 0 0 0 0 0 0 0 0 0 0 0
39773- 0 0 0 0 0 0 0 0 0 0 0 0
39774- 0 0 0 0 0 0 0 0 0 0 0 0
39775- 0 0 0 0 0 0 0 0 0 0 0 0
39776- 0 0 0 0 0 0 0 0 0 0 0 0
39777- 0 0 0 0 0 0 0 0 0 0 0 0
39778- 0 0 0 0 0 1 0 0 1 0 0 0
39779- 0 0 0 0 0 0 0 0 0 0 0 0
39780- 0 0 0 0 0 0 0 0 0 0 0 0
39781- 0 0 0 0 0 0 0 0 0 0 0 0
39782- 0 0 0 0 0 0 0 0 0 0 0 0
39783- 0 0 0 0 0 0 0 0 0 14 14 14
39784- 42 42 42 82 82 82 2 2 6 2 2 6
39785- 2 2 6 6 6 6 10 10 10 2 2 6
39786- 2 2 6 2 2 6 2 2 6 2 2 6
39787- 2 2 6 2 2 6 2 2 6 6 6 6
39788- 14 14 14 10 10 10 2 2 6 2 2 6
39789- 2 2 6 2 2 6 2 2 6 18 18 18
39790- 82 82 82 34 34 34 10 10 10 0 0 0
39791- 0 0 0 0 0 0 0 0 0 0 0 0
39792- 0 0 0 0 0 0 0 0 0 0 0 0
39793- 0 0 0 0 0 0 0 0 0 0 0 0
39794- 0 0 0 0 0 0 0 0 0 0 0 0
39795- 0 0 0 0 0 0 0 0 0 0 0 0
39796- 0 0 0 0 0 0 0 0 0 0 0 0
39797- 0 0 0 0 0 0 0 0 0 0 0 0
39798- 0 0 1 0 0 0 0 0 0 0 0 0
39799- 0 0 0 0 0 0 0 0 0 0 0 0
39800- 0 0 0 0 0 0 0 0 0 0 0 0
39801- 0 0 0 0 0 0 0 0 0 0 0 0
39802- 0 0 0 0 0 0 0 0 0 0 0 0
39803- 0 0 0 0 0 0 0 0 0 14 14 14
39804- 46 46 46 86 86 86 2 2 6 2 2 6
39805- 6 6 6 6 6 6 22 22 22 34 34 34
39806- 6 6 6 2 2 6 2 2 6 2 2 6
39807- 2 2 6 2 2 6 18 18 18 34 34 34
39808- 10 10 10 50 50 50 22 22 22 2 2 6
39809- 2 2 6 2 2 6 2 2 6 10 10 10
39810- 86 86 86 42 42 42 14 14 14 0 0 0
39811- 0 0 0 0 0 0 0 0 0 0 0 0
39812- 0 0 0 0 0 0 0 0 0 0 0 0
39813- 0 0 0 0 0 0 0 0 0 0 0 0
39814- 0 0 0 0 0 0 0 0 0 0 0 0
39815- 0 0 0 0 0 0 0 0 0 0 0 0
39816- 0 0 0 0 0 0 0 0 0 0 0 0
39817- 0 0 0 0 0 0 0 0 0 0 0 0
39818- 0 0 1 0 0 1 0 0 1 0 0 0
39819- 0 0 0 0 0 0 0 0 0 0 0 0
39820- 0 0 0 0 0 0 0 0 0 0 0 0
39821- 0 0 0 0 0 0 0 0 0 0 0 0
39822- 0 0 0 0 0 0 0 0 0 0 0 0
39823- 0 0 0 0 0 0 0 0 0 14 14 14
39824- 46 46 46 86 86 86 2 2 6 2 2 6
39825- 38 38 38 116 116 116 94 94 94 22 22 22
39826- 22 22 22 2 2 6 2 2 6 2 2 6
39827- 14 14 14 86 86 86 138 138 138 162 162 162
39828-154 154 154 38 38 38 26 26 26 6 6 6
39829- 2 2 6 2 2 6 2 2 6 2 2 6
39830- 86 86 86 46 46 46 14 14 14 0 0 0
39831- 0 0 0 0 0 0 0 0 0 0 0 0
39832- 0 0 0 0 0 0 0 0 0 0 0 0
39833- 0 0 0 0 0 0 0 0 0 0 0 0
39834- 0 0 0 0 0 0 0 0 0 0 0 0
39835- 0 0 0 0 0 0 0 0 0 0 0 0
39836- 0 0 0 0 0 0 0 0 0 0 0 0
39837- 0 0 0 0 0 0 0 0 0 0 0 0
39838- 0 0 0 0 0 0 0 0 0 0 0 0
39839- 0 0 0 0 0 0 0 0 0 0 0 0
39840- 0 0 0 0 0 0 0 0 0 0 0 0
39841- 0 0 0 0 0 0 0 0 0 0 0 0
39842- 0 0 0 0 0 0 0 0 0 0 0 0
39843- 0 0 0 0 0 0 0 0 0 14 14 14
39844- 46 46 46 86 86 86 2 2 6 14 14 14
39845-134 134 134 198 198 198 195 195 195 116 116 116
39846- 10 10 10 2 2 6 2 2 6 6 6 6
39847-101 98 89 187 187 187 210 210 210 218 218 218
39848-214 214 214 134 134 134 14 14 14 6 6 6
39849- 2 2 6 2 2 6 2 2 6 2 2 6
39850- 86 86 86 50 50 50 18 18 18 6 6 6
39851- 0 0 0 0 0 0 0 0 0 0 0 0
39852- 0 0 0 0 0 0 0 0 0 0 0 0
39853- 0 0 0 0 0 0 0 0 0 0 0 0
39854- 0 0 0 0 0 0 0 0 0 0 0 0
39855- 0 0 0 0 0 0 0 0 0 0 0 0
39856- 0 0 0 0 0 0 0 0 0 0 0 0
39857- 0 0 0 0 0 0 0 0 1 0 0 0
39858- 0 0 1 0 0 1 0 0 1 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 14 14 14
39864- 46 46 46 86 86 86 2 2 6 54 54 54
39865-218 218 218 195 195 195 226 226 226 246 246 246
39866- 58 58 58 2 2 6 2 2 6 30 30 30
39867-210 210 210 253 253 253 174 174 174 123 123 123
39868-221 221 221 234 234 234 74 74 74 2 2 6
39869- 2 2 6 2 2 6 2 2 6 2 2 6
39870- 70 70 70 58 58 58 22 22 22 6 6 6
39871- 0 0 0 0 0 0 0 0 0 0 0 0
39872- 0 0 0 0 0 0 0 0 0 0 0 0
39873- 0 0 0 0 0 0 0 0 0 0 0 0
39874- 0 0 0 0 0 0 0 0 0 0 0 0
39875- 0 0 0 0 0 0 0 0 0 0 0 0
39876- 0 0 0 0 0 0 0 0 0 0 0 0
39877- 0 0 0 0 0 0 0 0 0 0 0 0
39878- 0 0 0 0 0 0 0 0 0 0 0 0
39879- 0 0 0 0 0 0 0 0 0 0 0 0
39880- 0 0 0 0 0 0 0 0 0 0 0 0
39881- 0 0 0 0 0 0 0 0 0 0 0 0
39882- 0 0 0 0 0 0 0 0 0 0 0 0
39883- 0 0 0 0 0 0 0 0 0 14 14 14
39884- 46 46 46 82 82 82 2 2 6 106 106 106
39885-170 170 170 26 26 26 86 86 86 226 226 226
39886-123 123 123 10 10 10 14 14 14 46 46 46
39887-231 231 231 190 190 190 6 6 6 70 70 70
39888- 90 90 90 238 238 238 158 158 158 2 2 6
39889- 2 2 6 2 2 6 2 2 6 2 2 6
39890- 70 70 70 58 58 58 22 22 22 6 6 6
39891- 0 0 0 0 0 0 0 0 0 0 0 0
39892- 0 0 0 0 0 0 0 0 0 0 0 0
39893- 0 0 0 0 0 0 0 0 0 0 0 0
39894- 0 0 0 0 0 0 0 0 0 0 0 0
39895- 0 0 0 0 0 0 0 0 0 0 0 0
39896- 0 0 0 0 0 0 0 0 0 0 0 0
39897- 0 0 0 0 0 0 0 0 1 0 0 0
39898- 0 0 1 0 0 1 0 0 1 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 14 14 14
39904- 42 42 42 86 86 86 6 6 6 116 116 116
39905-106 106 106 6 6 6 70 70 70 149 149 149
39906-128 128 128 18 18 18 38 38 38 54 54 54
39907-221 221 221 106 106 106 2 2 6 14 14 14
39908- 46 46 46 190 190 190 198 198 198 2 2 6
39909- 2 2 6 2 2 6 2 2 6 2 2 6
39910- 74 74 74 62 62 62 22 22 22 6 6 6
39911- 0 0 0 0 0 0 0 0 0 0 0 0
39912- 0 0 0 0 0 0 0 0 0 0 0 0
39913- 0 0 0 0 0 0 0 0 0 0 0 0
39914- 0 0 0 0 0 0 0 0 0 0 0 0
39915- 0 0 0 0 0 0 0 0 0 0 0 0
39916- 0 0 0 0 0 0 0 0 0 0 0 0
39917- 0 0 0 0 0 0 0 0 1 0 0 0
39918- 0 0 1 0 0 0 0 0 1 0 0 0
39919- 0 0 0 0 0 0 0 0 0 0 0 0
39920- 0 0 0 0 0 0 0 0 0 0 0 0
39921- 0 0 0 0 0 0 0 0 0 0 0 0
39922- 0 0 0 0 0 0 0 0 0 0 0 0
39923- 0 0 0 0 0 0 0 0 0 14 14 14
39924- 42 42 42 94 94 94 14 14 14 101 101 101
39925-128 128 128 2 2 6 18 18 18 116 116 116
39926-118 98 46 121 92 8 121 92 8 98 78 10
39927-162 162 162 106 106 106 2 2 6 2 2 6
39928- 2 2 6 195 195 195 195 195 195 6 6 6
39929- 2 2 6 2 2 6 2 2 6 2 2 6
39930- 74 74 74 62 62 62 22 22 22 6 6 6
39931- 0 0 0 0 0 0 0 0 0 0 0 0
39932- 0 0 0 0 0 0 0 0 0 0 0 0
39933- 0 0 0 0 0 0 0 0 0 0 0 0
39934- 0 0 0 0 0 0 0 0 0 0 0 0
39935- 0 0 0 0 0 0 0 0 0 0 0 0
39936- 0 0 0 0 0 0 0 0 0 0 0 0
39937- 0 0 0 0 0 0 0 0 1 0 0 1
39938- 0 0 1 0 0 0 0 0 1 0 0 0
39939- 0 0 0 0 0 0 0 0 0 0 0 0
39940- 0 0 0 0 0 0 0 0 0 0 0 0
39941- 0 0 0 0 0 0 0 0 0 0 0 0
39942- 0 0 0 0 0 0 0 0 0 0 0 0
39943- 0 0 0 0 0 0 0 0 0 10 10 10
39944- 38 38 38 90 90 90 14 14 14 58 58 58
39945-210 210 210 26 26 26 54 38 6 154 114 10
39946-226 170 11 236 186 11 225 175 15 184 144 12
39947-215 174 15 175 146 61 37 26 9 2 2 6
39948- 70 70 70 246 246 246 138 138 138 2 2 6
39949- 2 2 6 2 2 6 2 2 6 2 2 6
39950- 70 70 70 66 66 66 26 26 26 6 6 6
39951- 0 0 0 0 0 0 0 0 0 0 0 0
39952- 0 0 0 0 0 0 0 0 0 0 0 0
39953- 0 0 0 0 0 0 0 0 0 0 0 0
39954- 0 0 0 0 0 0 0 0 0 0 0 0
39955- 0 0 0 0 0 0 0 0 0 0 0 0
39956- 0 0 0 0 0 0 0 0 0 0 0 0
39957- 0 0 0 0 0 0 0 0 0 0 0 0
39958- 0 0 0 0 0 0 0 0 0 0 0 0
39959- 0 0 0 0 0 0 0 0 0 0 0 0
39960- 0 0 0 0 0 0 0 0 0 0 0 0
39961- 0 0 0 0 0 0 0 0 0 0 0 0
39962- 0 0 0 0 0 0 0 0 0 0 0 0
39963- 0 0 0 0 0 0 0 0 0 10 10 10
39964- 38 38 38 86 86 86 14 14 14 10 10 10
39965-195 195 195 188 164 115 192 133 9 225 175 15
39966-239 182 13 234 190 10 232 195 16 232 200 30
39967-245 207 45 241 208 19 232 195 16 184 144 12
39968-218 194 134 211 206 186 42 42 42 2 2 6
39969- 2 2 6 2 2 6 2 2 6 2 2 6
39970- 50 50 50 74 74 74 30 30 30 6 6 6
39971- 0 0 0 0 0 0 0 0 0 0 0 0
39972- 0 0 0 0 0 0 0 0 0 0 0 0
39973- 0 0 0 0 0 0 0 0 0 0 0 0
39974- 0 0 0 0 0 0 0 0 0 0 0 0
39975- 0 0 0 0 0 0 0 0 0 0 0 0
39976- 0 0 0 0 0 0 0 0 0 0 0 0
39977- 0 0 0 0 0 0 0 0 0 0 0 0
39978- 0 0 0 0 0 0 0 0 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 10 10 10
39984- 34 34 34 86 86 86 14 14 14 2 2 6
39985-121 87 25 192 133 9 219 162 10 239 182 13
39986-236 186 11 232 195 16 241 208 19 244 214 54
39987-246 218 60 246 218 38 246 215 20 241 208 19
39988-241 208 19 226 184 13 121 87 25 2 2 6
39989- 2 2 6 2 2 6 2 2 6 2 2 6
39990- 50 50 50 82 82 82 34 34 34 10 10 10
39991- 0 0 0 0 0 0 0 0 0 0 0 0
39992- 0 0 0 0 0 0 0 0 0 0 0 0
39993- 0 0 0 0 0 0 0 0 0 0 0 0
39994- 0 0 0 0 0 0 0 0 0 0 0 0
39995- 0 0 0 0 0 0 0 0 0 0 0 0
39996- 0 0 0 0 0 0 0 0 0 0 0 0
39997- 0 0 0 0 0 0 0 0 0 0 0 0
39998- 0 0 0 0 0 0 0 0 0 0 0 0
39999- 0 0 0 0 0 0 0 0 0 0 0 0
40000- 0 0 0 0 0 0 0 0 0 0 0 0
40001- 0 0 0 0 0 0 0 0 0 0 0 0
40002- 0 0 0 0 0 0 0 0 0 0 0 0
40003- 0 0 0 0 0 0 0 0 0 10 10 10
40004- 34 34 34 82 82 82 30 30 30 61 42 6
40005-180 123 7 206 145 10 230 174 11 239 182 13
40006-234 190 10 238 202 15 241 208 19 246 218 74
40007-246 218 38 246 215 20 246 215 20 246 215 20
40008-226 184 13 215 174 15 184 144 12 6 6 6
40009- 2 2 6 2 2 6 2 2 6 2 2 6
40010- 26 26 26 94 94 94 42 42 42 14 14 14
40011- 0 0 0 0 0 0 0 0 0 0 0 0
40012- 0 0 0 0 0 0 0 0 0 0 0 0
40013- 0 0 0 0 0 0 0 0 0 0 0 0
40014- 0 0 0 0 0 0 0 0 0 0 0 0
40015- 0 0 0 0 0 0 0 0 0 0 0 0
40016- 0 0 0 0 0 0 0 0 0 0 0 0
40017- 0 0 0 0 0 0 0 0 0 0 0 0
40018- 0 0 0 0 0 0 0 0 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 10 10 10
40024- 30 30 30 78 78 78 50 50 50 104 69 6
40025-192 133 9 216 158 10 236 178 12 236 186 11
40026-232 195 16 241 208 19 244 214 54 245 215 43
40027-246 215 20 246 215 20 241 208 19 198 155 10
40028-200 144 11 216 158 10 156 118 10 2 2 6
40029- 2 2 6 2 2 6 2 2 6 2 2 6
40030- 6 6 6 90 90 90 54 54 54 18 18 18
40031- 6 6 6 0 0 0 0 0 0 0 0 0
40032- 0 0 0 0 0 0 0 0 0 0 0 0
40033- 0 0 0 0 0 0 0 0 0 0 0 0
40034- 0 0 0 0 0 0 0 0 0 0 0 0
40035- 0 0 0 0 0 0 0 0 0 0 0 0
40036- 0 0 0 0 0 0 0 0 0 0 0 0
40037- 0 0 0 0 0 0 0 0 0 0 0 0
40038- 0 0 0 0 0 0 0 0 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 10 10 10
40044- 30 30 30 78 78 78 46 46 46 22 22 22
40045-137 92 6 210 162 10 239 182 13 238 190 10
40046-238 202 15 241 208 19 246 215 20 246 215 20
40047-241 208 19 203 166 17 185 133 11 210 150 10
40048-216 158 10 210 150 10 102 78 10 2 2 6
40049- 6 6 6 54 54 54 14 14 14 2 2 6
40050- 2 2 6 62 62 62 74 74 74 30 30 30
40051- 10 10 10 0 0 0 0 0 0 0 0 0
40052- 0 0 0 0 0 0 0 0 0 0 0 0
40053- 0 0 0 0 0 0 0 0 0 0 0 0
40054- 0 0 0 0 0 0 0 0 0 0 0 0
40055- 0 0 0 0 0 0 0 0 0 0 0 0
40056- 0 0 0 0 0 0 0 0 0 0 0 0
40057- 0 0 0 0 0 0 0 0 0 0 0 0
40058- 0 0 0 0 0 0 0 0 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 10 10 10
40064- 34 34 34 78 78 78 50 50 50 6 6 6
40065- 94 70 30 139 102 15 190 146 13 226 184 13
40066-232 200 30 232 195 16 215 174 15 190 146 13
40067-168 122 10 192 133 9 210 150 10 213 154 11
40068-202 150 34 182 157 106 101 98 89 2 2 6
40069- 2 2 6 78 78 78 116 116 116 58 58 58
40070- 2 2 6 22 22 22 90 90 90 46 46 46
40071- 18 18 18 6 6 6 0 0 0 0 0 0
40072- 0 0 0 0 0 0 0 0 0 0 0 0
40073- 0 0 0 0 0 0 0 0 0 0 0 0
40074- 0 0 0 0 0 0 0 0 0 0 0 0
40075- 0 0 0 0 0 0 0 0 0 0 0 0
40076- 0 0 0 0 0 0 0 0 0 0 0 0
40077- 0 0 0 0 0 0 0 0 0 0 0 0
40078- 0 0 0 0 0 0 0 0 0 0 0 0
40079- 0 0 0 0 0 0 0 0 0 0 0 0
40080- 0 0 0 0 0 0 0 0 0 0 0 0
40081- 0 0 0 0 0 0 0 0 0 0 0 0
40082- 0 0 0 0 0 0 0 0 0 0 0 0
40083- 0 0 0 0 0 0 0 0 0 10 10 10
40084- 38 38 38 86 86 86 50 50 50 6 6 6
40085-128 128 128 174 154 114 156 107 11 168 122 10
40086-198 155 10 184 144 12 197 138 11 200 144 11
40087-206 145 10 206 145 10 197 138 11 188 164 115
40088-195 195 195 198 198 198 174 174 174 14 14 14
40089- 2 2 6 22 22 22 116 116 116 116 116 116
40090- 22 22 22 2 2 6 74 74 74 70 70 70
40091- 30 30 30 10 10 10 0 0 0 0 0 0
40092- 0 0 0 0 0 0 0 0 0 0 0 0
40093- 0 0 0 0 0 0 0 0 0 0 0 0
40094- 0 0 0 0 0 0 0 0 0 0 0 0
40095- 0 0 0 0 0 0 0 0 0 0 0 0
40096- 0 0 0 0 0 0 0 0 0 0 0 0
40097- 0 0 0 0 0 0 0 0 0 0 0 0
40098- 0 0 0 0 0 0 0 0 0 0 0 0
40099- 0 0 0 0 0 0 0 0 0 0 0 0
40100- 0 0 0 0 0 0 0 0 0 0 0 0
40101- 0 0 0 0 0 0 0 0 0 0 0 0
40102- 0 0 0 0 0 0 0 0 0 0 0 0
40103- 0 0 0 0 0 0 6 6 6 18 18 18
40104- 50 50 50 101 101 101 26 26 26 10 10 10
40105-138 138 138 190 190 190 174 154 114 156 107 11
40106-197 138 11 200 144 11 197 138 11 192 133 9
40107-180 123 7 190 142 34 190 178 144 187 187 187
40108-202 202 202 221 221 221 214 214 214 66 66 66
40109- 2 2 6 2 2 6 50 50 50 62 62 62
40110- 6 6 6 2 2 6 10 10 10 90 90 90
40111- 50 50 50 18 18 18 6 6 6 0 0 0
40112- 0 0 0 0 0 0 0 0 0 0 0 0
40113- 0 0 0 0 0 0 0 0 0 0 0 0
40114- 0 0 0 0 0 0 0 0 0 0 0 0
40115- 0 0 0 0 0 0 0 0 0 0 0 0
40116- 0 0 0 0 0 0 0 0 0 0 0 0
40117- 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 10 10 10 34 34 34
40124- 74 74 74 74 74 74 2 2 6 6 6 6
40125-144 144 144 198 198 198 190 190 190 178 166 146
40126-154 121 60 156 107 11 156 107 11 168 124 44
40127-174 154 114 187 187 187 190 190 190 210 210 210
40128-246 246 246 253 253 253 253 253 253 182 182 182
40129- 6 6 6 2 2 6 2 2 6 2 2 6
40130- 2 2 6 2 2 6 2 2 6 62 62 62
40131- 74 74 74 34 34 34 14 14 14 0 0 0
40132- 0 0 0 0 0 0 0 0 0 0 0 0
40133- 0 0 0 0 0 0 0 0 0 0 0 0
40134- 0 0 0 0 0 0 0 0 0 0 0 0
40135- 0 0 0 0 0 0 0 0 0 0 0 0
40136- 0 0 0 0 0 0 0 0 0 0 0 0
40137- 0 0 0 0 0 0 0 0 0 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 10 10 10 22 22 22 54 54 54
40144- 94 94 94 18 18 18 2 2 6 46 46 46
40145-234 234 234 221 221 221 190 190 190 190 190 190
40146-190 190 190 187 187 187 187 187 187 190 190 190
40147-190 190 190 195 195 195 214 214 214 242 242 242
40148-253 253 253 253 253 253 253 253 253 253 253 253
40149- 82 82 82 2 2 6 2 2 6 2 2 6
40150- 2 2 6 2 2 6 2 2 6 14 14 14
40151- 86 86 86 54 54 54 22 22 22 6 6 6
40152- 0 0 0 0 0 0 0 0 0 0 0 0
40153- 0 0 0 0 0 0 0 0 0 0 0 0
40154- 0 0 0 0 0 0 0 0 0 0 0 0
40155- 0 0 0 0 0 0 0 0 0 0 0 0
40156- 0 0 0 0 0 0 0 0 0 0 0 0
40157- 0 0 0 0 0 0 0 0 0 0 0 0
40158- 0 0 0 0 0 0 0 0 0 0 0 0
40159- 0 0 0 0 0 0 0 0 0 0 0 0
40160- 0 0 0 0 0 0 0 0 0 0 0 0
40161- 0 0 0 0 0 0 0 0 0 0 0 0
40162- 0 0 0 0 0 0 0 0 0 0 0 0
40163- 6 6 6 18 18 18 46 46 46 90 90 90
40164- 46 46 46 18 18 18 6 6 6 182 182 182
40165-253 253 253 246 246 246 206 206 206 190 190 190
40166-190 190 190 190 190 190 190 190 190 190 190 190
40167-206 206 206 231 231 231 250 250 250 253 253 253
40168-253 253 253 253 253 253 253 253 253 253 253 253
40169-202 202 202 14 14 14 2 2 6 2 2 6
40170- 2 2 6 2 2 6 2 2 6 2 2 6
40171- 42 42 42 86 86 86 42 42 42 18 18 18
40172- 6 6 6 0 0 0 0 0 0 0 0 0
40173- 0 0 0 0 0 0 0 0 0 0 0 0
40174- 0 0 0 0 0 0 0 0 0 0 0 0
40175- 0 0 0 0 0 0 0 0 0 0 0 0
40176- 0 0 0 0 0 0 0 0 0 0 0 0
40177- 0 0 0 0 0 0 0 0 0 0 0 0
40178- 0 0 0 0 0 0 0 0 0 0 0 0
40179- 0 0 0 0 0 0 0 0 0 0 0 0
40180- 0 0 0 0 0 0 0 0 0 0 0 0
40181- 0 0 0 0 0 0 0 0 0 0 0 0
40182- 0 0 0 0 0 0 0 0 0 6 6 6
40183- 14 14 14 38 38 38 74 74 74 66 66 66
40184- 2 2 6 6 6 6 90 90 90 250 250 250
40185-253 253 253 253 253 253 238 238 238 198 198 198
40186-190 190 190 190 190 190 195 195 195 221 221 221
40187-246 246 246 253 253 253 253 253 253 253 253 253
40188-253 253 253 253 253 253 253 253 253 253 253 253
40189-253 253 253 82 82 82 2 2 6 2 2 6
40190- 2 2 6 2 2 6 2 2 6 2 2 6
40191- 2 2 6 78 78 78 70 70 70 34 34 34
40192- 14 14 14 6 6 6 0 0 0 0 0 0
40193- 0 0 0 0 0 0 0 0 0 0 0 0
40194- 0 0 0 0 0 0 0 0 0 0 0 0
40195- 0 0 0 0 0 0 0 0 0 0 0 0
40196- 0 0 0 0 0 0 0 0 0 0 0 0
40197- 0 0 0 0 0 0 0 0 0 0 0 0
40198- 0 0 0 0 0 0 0 0 0 0 0 0
40199- 0 0 0 0 0 0 0 0 0 0 0 0
40200- 0 0 0 0 0 0 0 0 0 0 0 0
40201- 0 0 0 0 0 0 0 0 0 0 0 0
40202- 0 0 0 0 0 0 0 0 0 14 14 14
40203- 34 34 34 66 66 66 78 78 78 6 6 6
40204- 2 2 6 18 18 18 218 218 218 253 253 253
40205-253 253 253 253 253 253 253 253 253 246 246 246
40206-226 226 226 231 231 231 246 246 246 253 253 253
40207-253 253 253 253 253 253 253 253 253 253 253 253
40208-253 253 253 253 253 253 253 253 253 253 253 253
40209-253 253 253 178 178 178 2 2 6 2 2 6
40210- 2 2 6 2 2 6 2 2 6 2 2 6
40211- 2 2 6 18 18 18 90 90 90 62 62 62
40212- 30 30 30 10 10 10 0 0 0 0 0 0
40213- 0 0 0 0 0 0 0 0 0 0 0 0
40214- 0 0 0 0 0 0 0 0 0 0 0 0
40215- 0 0 0 0 0 0 0 0 0 0 0 0
40216- 0 0 0 0 0 0 0 0 0 0 0 0
40217- 0 0 0 0 0 0 0 0 0 0 0 0
40218- 0 0 0 0 0 0 0 0 0 0 0 0
40219- 0 0 0 0 0 0 0 0 0 0 0 0
40220- 0 0 0 0 0 0 0 0 0 0 0 0
40221- 0 0 0 0 0 0 0 0 0 0 0 0
40222- 0 0 0 0 0 0 10 10 10 26 26 26
40223- 58 58 58 90 90 90 18 18 18 2 2 6
40224- 2 2 6 110 110 110 253 253 253 253 253 253
40225-253 253 253 253 253 253 253 253 253 253 253 253
40226-250 250 250 253 253 253 253 253 253 253 253 253
40227-253 253 253 253 253 253 253 253 253 253 253 253
40228-253 253 253 253 253 253 253 253 253 253 253 253
40229-253 253 253 231 231 231 18 18 18 2 2 6
40230- 2 2 6 2 2 6 2 2 6 2 2 6
40231- 2 2 6 2 2 6 18 18 18 94 94 94
40232- 54 54 54 26 26 26 10 10 10 0 0 0
40233- 0 0 0 0 0 0 0 0 0 0 0 0
40234- 0 0 0 0 0 0 0 0 0 0 0 0
40235- 0 0 0 0 0 0 0 0 0 0 0 0
40236- 0 0 0 0 0 0 0 0 0 0 0 0
40237- 0 0 0 0 0 0 0 0 0 0 0 0
40238- 0 0 0 0 0 0 0 0 0 0 0 0
40239- 0 0 0 0 0 0 0 0 0 0 0 0
40240- 0 0 0 0 0 0 0 0 0 0 0 0
40241- 0 0 0 0 0 0 0 0 0 0 0 0
40242- 0 0 0 6 6 6 22 22 22 50 50 50
40243- 90 90 90 26 26 26 2 2 6 2 2 6
40244- 14 14 14 195 195 195 250 250 250 253 253 253
40245-253 253 253 253 253 253 253 253 253 253 253 253
40246-253 253 253 253 253 253 253 253 253 253 253 253
40247-253 253 253 253 253 253 253 253 253 253 253 253
40248-253 253 253 253 253 253 253 253 253 253 253 253
40249-250 250 250 242 242 242 54 54 54 2 2 6
40250- 2 2 6 2 2 6 2 2 6 2 2 6
40251- 2 2 6 2 2 6 2 2 6 38 38 38
40252- 86 86 86 50 50 50 22 22 22 6 6 6
40253- 0 0 0 0 0 0 0 0 0 0 0 0
40254- 0 0 0 0 0 0 0 0 0 0 0 0
40255- 0 0 0 0 0 0 0 0 0 0 0 0
40256- 0 0 0 0 0 0 0 0 0 0 0 0
40257- 0 0 0 0 0 0 0 0 0 0 0 0
40258- 0 0 0 0 0 0 0 0 0 0 0 0
40259- 0 0 0 0 0 0 0 0 0 0 0 0
40260- 0 0 0 0 0 0 0 0 0 0 0 0
40261- 0 0 0 0 0 0 0 0 0 0 0 0
40262- 6 6 6 14 14 14 38 38 38 82 82 82
40263- 34 34 34 2 2 6 2 2 6 2 2 6
40264- 42 42 42 195 195 195 246 246 246 253 253 253
40265-253 253 253 253 253 253 253 253 253 250 250 250
40266-242 242 242 242 242 242 250 250 250 253 253 253
40267-253 253 253 253 253 253 253 253 253 253 253 253
40268-253 253 253 250 250 250 246 246 246 238 238 238
40269-226 226 226 231 231 231 101 101 101 6 6 6
40270- 2 2 6 2 2 6 2 2 6 2 2 6
40271- 2 2 6 2 2 6 2 2 6 2 2 6
40272- 38 38 38 82 82 82 42 42 42 14 14 14
40273- 6 6 6 0 0 0 0 0 0 0 0 0
40274- 0 0 0 0 0 0 0 0 0 0 0 0
40275- 0 0 0 0 0 0 0 0 0 0 0 0
40276- 0 0 0 0 0 0 0 0 0 0 0 0
40277- 0 0 0 0 0 0 0 0 0 0 0 0
40278- 0 0 0 0 0 0 0 0 0 0 0 0
40279- 0 0 0 0 0 0 0 0 0 0 0 0
40280- 0 0 0 0 0 0 0 0 0 0 0 0
40281- 0 0 0 0 0 0 0 0 0 0 0 0
40282- 10 10 10 26 26 26 62 62 62 66 66 66
40283- 2 2 6 2 2 6 2 2 6 6 6 6
40284- 70 70 70 170 170 170 206 206 206 234 234 234
40285-246 246 246 250 250 250 250 250 250 238 238 238
40286-226 226 226 231 231 231 238 238 238 250 250 250
40287-250 250 250 250 250 250 246 246 246 231 231 231
40288-214 214 214 206 206 206 202 202 202 202 202 202
40289-198 198 198 202 202 202 182 182 182 18 18 18
40290- 2 2 6 2 2 6 2 2 6 2 2 6
40291- 2 2 6 2 2 6 2 2 6 2 2 6
40292- 2 2 6 62 62 62 66 66 66 30 30 30
40293- 10 10 10 0 0 0 0 0 0 0 0 0
40294- 0 0 0 0 0 0 0 0 0 0 0 0
40295- 0 0 0 0 0 0 0 0 0 0 0 0
40296- 0 0 0 0 0 0 0 0 0 0 0 0
40297- 0 0 0 0 0 0 0 0 0 0 0 0
40298- 0 0 0 0 0 0 0 0 0 0 0 0
40299- 0 0 0 0 0 0 0 0 0 0 0 0
40300- 0 0 0 0 0 0 0 0 0 0 0 0
40301- 0 0 0 0 0 0 0 0 0 0 0 0
40302- 14 14 14 42 42 42 82 82 82 18 18 18
40303- 2 2 6 2 2 6 2 2 6 10 10 10
40304- 94 94 94 182 182 182 218 218 218 242 242 242
40305-250 250 250 253 253 253 253 253 253 250 250 250
40306-234 234 234 253 253 253 253 253 253 253 253 253
40307-253 253 253 253 253 253 253 253 253 246 246 246
40308-238 238 238 226 226 226 210 210 210 202 202 202
40309-195 195 195 195 195 195 210 210 210 158 158 158
40310- 6 6 6 14 14 14 50 50 50 14 14 14
40311- 2 2 6 2 2 6 2 2 6 2 2 6
40312- 2 2 6 6 6 6 86 86 86 46 46 46
40313- 18 18 18 6 6 6 0 0 0 0 0 0
40314- 0 0 0 0 0 0 0 0 0 0 0 0
40315- 0 0 0 0 0 0 0 0 0 0 0 0
40316- 0 0 0 0 0 0 0 0 0 0 0 0
40317- 0 0 0 0 0 0 0 0 0 0 0 0
40318- 0 0 0 0 0 0 0 0 0 0 0 0
40319- 0 0 0 0 0 0 0 0 0 0 0 0
40320- 0 0 0 0 0 0 0 0 0 0 0 0
40321- 0 0 0 0 0 0 0 0 0 6 6 6
40322- 22 22 22 54 54 54 70 70 70 2 2 6
40323- 2 2 6 10 10 10 2 2 6 22 22 22
40324-166 166 166 231 231 231 250 250 250 253 253 253
40325-253 253 253 253 253 253 253 253 253 250 250 250
40326-242 242 242 253 253 253 253 253 253 253 253 253
40327-253 253 253 253 253 253 253 253 253 253 253 253
40328-253 253 253 253 253 253 253 253 253 246 246 246
40329-231 231 231 206 206 206 198 198 198 226 226 226
40330- 94 94 94 2 2 6 6 6 6 38 38 38
40331- 30 30 30 2 2 6 2 2 6 2 2 6
40332- 2 2 6 2 2 6 62 62 62 66 66 66
40333- 26 26 26 10 10 10 0 0 0 0 0 0
40334- 0 0 0 0 0 0 0 0 0 0 0 0
40335- 0 0 0 0 0 0 0 0 0 0 0 0
40336- 0 0 0 0 0 0 0 0 0 0 0 0
40337- 0 0 0 0 0 0 0 0 0 0 0 0
40338- 0 0 0 0 0 0 0 0 0 0 0 0
40339- 0 0 0 0 0 0 0 0 0 0 0 0
40340- 0 0 0 0 0 0 0 0 0 0 0 0
40341- 0 0 0 0 0 0 0 0 0 10 10 10
40342- 30 30 30 74 74 74 50 50 50 2 2 6
40343- 26 26 26 26 26 26 2 2 6 106 106 106
40344-238 238 238 253 253 253 253 253 253 253 253 253
40345-253 253 253 253 253 253 253 253 253 253 253 253
40346-253 253 253 253 253 253 253 253 253 253 253 253
40347-253 253 253 253 253 253 253 253 253 253 253 253
40348-253 253 253 253 253 253 253 253 253 253 253 253
40349-253 253 253 246 246 246 218 218 218 202 202 202
40350-210 210 210 14 14 14 2 2 6 2 2 6
40351- 30 30 30 22 22 22 2 2 6 2 2 6
40352- 2 2 6 2 2 6 18 18 18 86 86 86
40353- 42 42 42 14 14 14 0 0 0 0 0 0
40354- 0 0 0 0 0 0 0 0 0 0 0 0
40355- 0 0 0 0 0 0 0 0 0 0 0 0
40356- 0 0 0 0 0 0 0 0 0 0 0 0
40357- 0 0 0 0 0 0 0 0 0 0 0 0
40358- 0 0 0 0 0 0 0 0 0 0 0 0
40359- 0 0 0 0 0 0 0 0 0 0 0 0
40360- 0 0 0 0 0 0 0 0 0 0 0 0
40361- 0 0 0 0 0 0 0 0 0 14 14 14
40362- 42 42 42 90 90 90 22 22 22 2 2 6
40363- 42 42 42 2 2 6 18 18 18 218 218 218
40364-253 253 253 253 253 253 253 253 253 253 253 253
40365-253 253 253 253 253 253 253 253 253 253 253 253
40366-253 253 253 253 253 253 253 253 253 253 253 253
40367-253 253 253 253 253 253 253 253 253 253 253 253
40368-253 253 253 253 253 253 253 253 253 253 253 253
40369-253 253 253 253 253 253 250 250 250 221 221 221
40370-218 218 218 101 101 101 2 2 6 14 14 14
40371- 18 18 18 38 38 38 10 10 10 2 2 6
40372- 2 2 6 2 2 6 2 2 6 78 78 78
40373- 58 58 58 22 22 22 6 6 6 0 0 0
40374- 0 0 0 0 0 0 0 0 0 0 0 0
40375- 0 0 0 0 0 0 0 0 0 0 0 0
40376- 0 0 0 0 0 0 0 0 0 0 0 0
40377- 0 0 0 0 0 0 0 0 0 0 0 0
40378- 0 0 0 0 0 0 0 0 0 0 0 0
40379- 0 0 0 0 0 0 0 0 0 0 0 0
40380- 0 0 0 0 0 0 0 0 0 0 0 0
40381- 0 0 0 0 0 0 6 6 6 18 18 18
40382- 54 54 54 82 82 82 2 2 6 26 26 26
40383- 22 22 22 2 2 6 123 123 123 253 253 253
40384-253 253 253 253 253 253 253 253 253 253 253 253
40385-253 253 253 253 253 253 253 253 253 253 253 253
40386-253 253 253 253 253 253 253 253 253 253 253 253
40387-253 253 253 253 253 253 253 253 253 253 253 253
40388-253 253 253 253 253 253 253 253 253 253 253 253
40389-253 253 253 253 253 253 253 253 253 250 250 250
40390-238 238 238 198 198 198 6 6 6 38 38 38
40391- 58 58 58 26 26 26 38 38 38 2 2 6
40392- 2 2 6 2 2 6 2 2 6 46 46 46
40393- 78 78 78 30 30 30 10 10 10 0 0 0
40394- 0 0 0 0 0 0 0 0 0 0 0 0
40395- 0 0 0 0 0 0 0 0 0 0 0 0
40396- 0 0 0 0 0 0 0 0 0 0 0 0
40397- 0 0 0 0 0 0 0 0 0 0 0 0
40398- 0 0 0 0 0 0 0 0 0 0 0 0
40399- 0 0 0 0 0 0 0 0 0 0 0 0
40400- 0 0 0 0 0 0 0 0 0 0 0 0
40401- 0 0 0 0 0 0 10 10 10 30 30 30
40402- 74 74 74 58 58 58 2 2 6 42 42 42
40403- 2 2 6 22 22 22 231 231 231 253 253 253
40404-253 253 253 253 253 253 253 253 253 253 253 253
40405-253 253 253 253 253 253 253 253 253 250 250 250
40406-253 253 253 253 253 253 253 253 253 253 253 253
40407-253 253 253 253 253 253 253 253 253 253 253 253
40408-253 253 253 253 253 253 253 253 253 253 253 253
40409-253 253 253 253 253 253 253 253 253 253 253 253
40410-253 253 253 246 246 246 46 46 46 38 38 38
40411- 42 42 42 14 14 14 38 38 38 14 14 14
40412- 2 2 6 2 2 6 2 2 6 6 6 6
40413- 86 86 86 46 46 46 14 14 14 0 0 0
40414- 0 0 0 0 0 0 0 0 0 0 0 0
40415- 0 0 0 0 0 0 0 0 0 0 0 0
40416- 0 0 0 0 0 0 0 0 0 0 0 0
40417- 0 0 0 0 0 0 0 0 0 0 0 0
40418- 0 0 0 0 0 0 0 0 0 0 0 0
40419- 0 0 0 0 0 0 0 0 0 0 0 0
40420- 0 0 0 0 0 0 0 0 0 0 0 0
40421- 0 0 0 6 6 6 14 14 14 42 42 42
40422- 90 90 90 18 18 18 18 18 18 26 26 26
40423- 2 2 6 116 116 116 253 253 253 253 253 253
40424-253 253 253 253 253 253 253 253 253 253 253 253
40425-253 253 253 253 253 253 250 250 250 238 238 238
40426-253 253 253 253 253 253 253 253 253 253 253 253
40427-253 253 253 253 253 253 253 253 253 253 253 253
40428-253 253 253 253 253 253 253 253 253 253 253 253
40429-253 253 253 253 253 253 253 253 253 253 253 253
40430-253 253 253 253 253 253 94 94 94 6 6 6
40431- 2 2 6 2 2 6 10 10 10 34 34 34
40432- 2 2 6 2 2 6 2 2 6 2 2 6
40433- 74 74 74 58 58 58 22 22 22 6 6 6
40434- 0 0 0 0 0 0 0 0 0 0 0 0
40435- 0 0 0 0 0 0 0 0 0 0 0 0
40436- 0 0 0 0 0 0 0 0 0 0 0 0
40437- 0 0 0 0 0 0 0 0 0 0 0 0
40438- 0 0 0 0 0 0 0 0 0 0 0 0
40439- 0 0 0 0 0 0 0 0 0 0 0 0
40440- 0 0 0 0 0 0 0 0 0 0 0 0
40441- 0 0 0 10 10 10 26 26 26 66 66 66
40442- 82 82 82 2 2 6 38 38 38 6 6 6
40443- 14 14 14 210 210 210 253 253 253 253 253 253
40444-253 253 253 253 253 253 253 253 253 253 253 253
40445-253 253 253 253 253 253 246 246 246 242 242 242
40446-253 253 253 253 253 253 253 253 253 253 253 253
40447-253 253 253 253 253 253 253 253 253 253 253 253
40448-253 253 253 253 253 253 253 253 253 253 253 253
40449-253 253 253 253 253 253 253 253 253 253 253 253
40450-253 253 253 253 253 253 144 144 144 2 2 6
40451- 2 2 6 2 2 6 2 2 6 46 46 46
40452- 2 2 6 2 2 6 2 2 6 2 2 6
40453- 42 42 42 74 74 74 30 30 30 10 10 10
40454- 0 0 0 0 0 0 0 0 0 0 0 0
40455- 0 0 0 0 0 0 0 0 0 0 0 0
40456- 0 0 0 0 0 0 0 0 0 0 0 0
40457- 0 0 0 0 0 0 0 0 0 0 0 0
40458- 0 0 0 0 0 0 0 0 0 0 0 0
40459- 0 0 0 0 0 0 0 0 0 0 0 0
40460- 0 0 0 0 0 0 0 0 0 0 0 0
40461- 6 6 6 14 14 14 42 42 42 90 90 90
40462- 26 26 26 6 6 6 42 42 42 2 2 6
40463- 74 74 74 250 250 250 253 253 253 253 253 253
40464-253 253 253 253 253 253 253 253 253 253 253 253
40465-253 253 253 253 253 253 242 242 242 242 242 242
40466-253 253 253 253 253 253 253 253 253 253 253 253
40467-253 253 253 253 253 253 253 253 253 253 253 253
40468-253 253 253 253 253 253 253 253 253 253 253 253
40469-253 253 253 253 253 253 253 253 253 253 253 253
40470-253 253 253 253 253 253 182 182 182 2 2 6
40471- 2 2 6 2 2 6 2 2 6 46 46 46
40472- 2 2 6 2 2 6 2 2 6 2 2 6
40473- 10 10 10 86 86 86 38 38 38 10 10 10
40474- 0 0 0 0 0 0 0 0 0 0 0 0
40475- 0 0 0 0 0 0 0 0 0 0 0 0
40476- 0 0 0 0 0 0 0 0 0 0 0 0
40477- 0 0 0 0 0 0 0 0 0 0 0 0
40478- 0 0 0 0 0 0 0 0 0 0 0 0
40479- 0 0 0 0 0 0 0 0 0 0 0 0
40480- 0 0 0 0 0 0 0 0 0 0 0 0
40481- 10 10 10 26 26 26 66 66 66 82 82 82
40482- 2 2 6 22 22 22 18 18 18 2 2 6
40483-149 149 149 253 253 253 253 253 253 253 253 253
40484-253 253 253 253 253 253 253 253 253 253 253 253
40485-253 253 253 253 253 253 234 234 234 242 242 242
40486-253 253 253 253 253 253 253 253 253 253 253 253
40487-253 253 253 253 253 253 253 253 253 253 253 253
40488-253 253 253 253 253 253 253 253 253 253 253 253
40489-253 253 253 253 253 253 253 253 253 253 253 253
40490-253 253 253 253 253 253 206 206 206 2 2 6
40491- 2 2 6 2 2 6 2 2 6 38 38 38
40492- 2 2 6 2 2 6 2 2 6 2 2 6
40493- 6 6 6 86 86 86 46 46 46 14 14 14
40494- 0 0 0 0 0 0 0 0 0 0 0 0
40495- 0 0 0 0 0 0 0 0 0 0 0 0
40496- 0 0 0 0 0 0 0 0 0 0 0 0
40497- 0 0 0 0 0 0 0 0 0 0 0 0
40498- 0 0 0 0 0 0 0 0 0 0 0 0
40499- 0 0 0 0 0 0 0 0 0 0 0 0
40500- 0 0 0 0 0 0 0 0 0 6 6 6
40501- 18 18 18 46 46 46 86 86 86 18 18 18
40502- 2 2 6 34 34 34 10 10 10 6 6 6
40503-210 210 210 253 253 253 253 253 253 253 253 253
40504-253 253 253 253 253 253 253 253 253 253 253 253
40505-253 253 253 253 253 253 234 234 234 242 242 242
40506-253 253 253 253 253 253 253 253 253 253 253 253
40507-253 253 253 253 253 253 253 253 253 253 253 253
40508-253 253 253 253 253 253 253 253 253 253 253 253
40509-253 253 253 253 253 253 253 253 253 253 253 253
40510-253 253 253 253 253 253 221 221 221 6 6 6
40511- 2 2 6 2 2 6 6 6 6 30 30 30
40512- 2 2 6 2 2 6 2 2 6 2 2 6
40513- 2 2 6 82 82 82 54 54 54 18 18 18
40514- 6 6 6 0 0 0 0 0 0 0 0 0
40515- 0 0 0 0 0 0 0 0 0 0 0 0
40516- 0 0 0 0 0 0 0 0 0 0 0 0
40517- 0 0 0 0 0 0 0 0 0 0 0 0
40518- 0 0 0 0 0 0 0 0 0 0 0 0
40519- 0 0 0 0 0 0 0 0 0 0 0 0
40520- 0 0 0 0 0 0 0 0 0 10 10 10
40521- 26 26 26 66 66 66 62 62 62 2 2 6
40522- 2 2 6 38 38 38 10 10 10 26 26 26
40523-238 238 238 253 253 253 253 253 253 253 253 253
40524-253 253 253 253 253 253 253 253 253 253 253 253
40525-253 253 253 253 253 253 231 231 231 238 238 238
40526-253 253 253 253 253 253 253 253 253 253 253 253
40527-253 253 253 253 253 253 253 253 253 253 253 253
40528-253 253 253 253 253 253 253 253 253 253 253 253
40529-253 253 253 253 253 253 253 253 253 253 253 253
40530-253 253 253 253 253 253 231 231 231 6 6 6
40531- 2 2 6 2 2 6 10 10 10 30 30 30
40532- 2 2 6 2 2 6 2 2 6 2 2 6
40533- 2 2 6 66 66 66 58 58 58 22 22 22
40534- 6 6 6 0 0 0 0 0 0 0 0 0
40535- 0 0 0 0 0 0 0 0 0 0 0 0
40536- 0 0 0 0 0 0 0 0 0 0 0 0
40537- 0 0 0 0 0 0 0 0 0 0 0 0
40538- 0 0 0 0 0 0 0 0 0 0 0 0
40539- 0 0 0 0 0 0 0 0 0 0 0 0
40540- 0 0 0 0 0 0 0 0 0 10 10 10
40541- 38 38 38 78 78 78 6 6 6 2 2 6
40542- 2 2 6 46 46 46 14 14 14 42 42 42
40543-246 246 246 253 253 253 253 253 253 253 253 253
40544-253 253 253 253 253 253 253 253 253 253 253 253
40545-253 253 253 253 253 253 231 231 231 242 242 242
40546-253 253 253 253 253 253 253 253 253 253 253 253
40547-253 253 253 253 253 253 253 253 253 253 253 253
40548-253 253 253 253 253 253 253 253 253 253 253 253
40549-253 253 253 253 253 253 253 253 253 253 253 253
40550-253 253 253 253 253 253 234 234 234 10 10 10
40551- 2 2 6 2 2 6 22 22 22 14 14 14
40552- 2 2 6 2 2 6 2 2 6 2 2 6
40553- 2 2 6 66 66 66 62 62 62 22 22 22
40554- 6 6 6 0 0 0 0 0 0 0 0 0
40555- 0 0 0 0 0 0 0 0 0 0 0 0
40556- 0 0 0 0 0 0 0 0 0 0 0 0
40557- 0 0 0 0 0 0 0 0 0 0 0 0
40558- 0 0 0 0 0 0 0 0 0 0 0 0
40559- 0 0 0 0 0 0 0 0 0 0 0 0
40560- 0 0 0 0 0 0 6 6 6 18 18 18
40561- 50 50 50 74 74 74 2 2 6 2 2 6
40562- 14 14 14 70 70 70 34 34 34 62 62 62
40563-250 250 250 253 253 253 253 253 253 253 253 253
40564-253 253 253 253 253 253 253 253 253 253 253 253
40565-253 253 253 253 253 253 231 231 231 246 246 246
40566-253 253 253 253 253 253 253 253 253 253 253 253
40567-253 253 253 253 253 253 253 253 253 253 253 253
40568-253 253 253 253 253 253 253 253 253 253 253 253
40569-253 253 253 253 253 253 253 253 253 253 253 253
40570-253 253 253 253 253 253 234 234 234 14 14 14
40571- 2 2 6 2 2 6 30 30 30 2 2 6
40572- 2 2 6 2 2 6 2 2 6 2 2 6
40573- 2 2 6 66 66 66 62 62 62 22 22 22
40574- 6 6 6 0 0 0 0 0 0 0 0 0
40575- 0 0 0 0 0 0 0 0 0 0 0 0
40576- 0 0 0 0 0 0 0 0 0 0 0 0
40577- 0 0 0 0 0 0 0 0 0 0 0 0
40578- 0 0 0 0 0 0 0 0 0 0 0 0
40579- 0 0 0 0 0 0 0 0 0 0 0 0
40580- 0 0 0 0 0 0 6 6 6 18 18 18
40581- 54 54 54 62 62 62 2 2 6 2 2 6
40582- 2 2 6 30 30 30 46 46 46 70 70 70
40583-250 250 250 253 253 253 253 253 253 253 253 253
40584-253 253 253 253 253 253 253 253 253 253 253 253
40585-253 253 253 253 253 253 231 231 231 246 246 246
40586-253 253 253 253 253 253 253 253 253 253 253 253
40587-253 253 253 253 253 253 253 253 253 253 253 253
40588-253 253 253 253 253 253 253 253 253 253 253 253
40589-253 253 253 253 253 253 253 253 253 253 253 253
40590-253 253 253 253 253 253 226 226 226 10 10 10
40591- 2 2 6 6 6 6 30 30 30 2 2 6
40592- 2 2 6 2 2 6 2 2 6 2 2 6
40593- 2 2 6 66 66 66 58 58 58 22 22 22
40594- 6 6 6 0 0 0 0 0 0 0 0 0
40595- 0 0 0 0 0 0 0 0 0 0 0 0
40596- 0 0 0 0 0 0 0 0 0 0 0 0
40597- 0 0 0 0 0 0 0 0 0 0 0 0
40598- 0 0 0 0 0 0 0 0 0 0 0 0
40599- 0 0 0 0 0 0 0 0 0 0 0 0
40600- 0 0 0 0 0 0 6 6 6 22 22 22
40601- 58 58 58 62 62 62 2 2 6 2 2 6
40602- 2 2 6 2 2 6 30 30 30 78 78 78
40603-250 250 250 253 253 253 253 253 253 253 253 253
40604-253 253 253 253 253 253 253 253 253 253 253 253
40605-253 253 253 253 253 253 231 231 231 246 246 246
40606-253 253 253 253 253 253 253 253 253 253 253 253
40607-253 253 253 253 253 253 253 253 253 253 253 253
40608-253 253 253 253 253 253 253 253 253 253 253 253
40609-253 253 253 253 253 253 253 253 253 253 253 253
40610-253 253 253 253 253 253 206 206 206 2 2 6
40611- 22 22 22 34 34 34 18 14 6 22 22 22
40612- 26 26 26 18 18 18 6 6 6 2 2 6
40613- 2 2 6 82 82 82 54 54 54 18 18 18
40614- 6 6 6 0 0 0 0 0 0 0 0 0
40615- 0 0 0 0 0 0 0 0 0 0 0 0
40616- 0 0 0 0 0 0 0 0 0 0 0 0
40617- 0 0 0 0 0 0 0 0 0 0 0 0
40618- 0 0 0 0 0 0 0 0 0 0 0 0
40619- 0 0 0 0 0 0 0 0 0 0 0 0
40620- 0 0 0 0 0 0 6 6 6 26 26 26
40621- 62 62 62 106 106 106 74 54 14 185 133 11
40622-210 162 10 121 92 8 6 6 6 62 62 62
40623-238 238 238 253 253 253 253 253 253 253 253 253
40624-253 253 253 253 253 253 253 253 253 253 253 253
40625-253 253 253 253 253 253 231 231 231 246 246 246
40626-253 253 253 253 253 253 253 253 253 253 253 253
40627-253 253 253 253 253 253 253 253 253 253 253 253
40628-253 253 253 253 253 253 253 253 253 253 253 253
40629-253 253 253 253 253 253 253 253 253 253 253 253
40630-253 253 253 253 253 253 158 158 158 18 18 18
40631- 14 14 14 2 2 6 2 2 6 2 2 6
40632- 6 6 6 18 18 18 66 66 66 38 38 38
40633- 6 6 6 94 94 94 50 50 50 18 18 18
40634- 6 6 6 0 0 0 0 0 0 0 0 0
40635- 0 0 0 0 0 0 0 0 0 0 0 0
40636- 0 0 0 0 0 0 0 0 0 0 0 0
40637- 0 0 0 0 0 0 0 0 0 0 0 0
40638- 0 0 0 0 0 0 0 0 0 0 0 0
40639- 0 0 0 0 0 0 0 0 0 6 6 6
40640- 10 10 10 10 10 10 18 18 18 38 38 38
40641- 78 78 78 142 134 106 216 158 10 242 186 14
40642-246 190 14 246 190 14 156 118 10 10 10 10
40643- 90 90 90 238 238 238 253 253 253 253 253 253
40644-253 253 253 253 253 253 253 253 253 253 253 253
40645-253 253 253 253 253 253 231 231 231 250 250 250
40646-253 253 253 253 253 253 253 253 253 253 253 253
40647-253 253 253 253 253 253 253 253 253 253 253 253
40648-253 253 253 253 253 253 253 253 253 253 253 253
40649-253 253 253 253 253 253 253 253 253 246 230 190
40650-238 204 91 238 204 91 181 142 44 37 26 9
40651- 2 2 6 2 2 6 2 2 6 2 2 6
40652- 2 2 6 2 2 6 38 38 38 46 46 46
40653- 26 26 26 106 106 106 54 54 54 18 18 18
40654- 6 6 6 0 0 0 0 0 0 0 0 0
40655- 0 0 0 0 0 0 0 0 0 0 0 0
40656- 0 0 0 0 0 0 0 0 0 0 0 0
40657- 0 0 0 0 0 0 0 0 0 0 0 0
40658- 0 0 0 0 0 0 0 0 0 0 0 0
40659- 0 0 0 6 6 6 14 14 14 22 22 22
40660- 30 30 30 38 38 38 50 50 50 70 70 70
40661-106 106 106 190 142 34 226 170 11 242 186 14
40662-246 190 14 246 190 14 246 190 14 154 114 10
40663- 6 6 6 74 74 74 226 226 226 253 253 253
40664-253 253 253 253 253 253 253 253 253 253 253 253
40665-253 253 253 253 253 253 231 231 231 250 250 250
40666-253 253 253 253 253 253 253 253 253 253 253 253
40667-253 253 253 253 253 253 253 253 253 253 253 253
40668-253 253 253 253 253 253 253 253 253 253 253 253
40669-253 253 253 253 253 253 253 253 253 228 184 62
40670-241 196 14 241 208 19 232 195 16 38 30 10
40671- 2 2 6 2 2 6 2 2 6 2 2 6
40672- 2 2 6 6 6 6 30 30 30 26 26 26
40673-203 166 17 154 142 90 66 66 66 26 26 26
40674- 6 6 6 0 0 0 0 0 0 0 0 0
40675- 0 0 0 0 0 0 0 0 0 0 0 0
40676- 0 0 0 0 0 0 0 0 0 0 0 0
40677- 0 0 0 0 0 0 0 0 0 0 0 0
40678- 0 0 0 0 0 0 0 0 0 0 0 0
40679- 6 6 6 18 18 18 38 38 38 58 58 58
40680- 78 78 78 86 86 86 101 101 101 123 123 123
40681-175 146 61 210 150 10 234 174 13 246 186 14
40682-246 190 14 246 190 14 246 190 14 238 190 10
40683-102 78 10 2 2 6 46 46 46 198 198 198
40684-253 253 253 253 253 253 253 253 253 253 253 253
40685-253 253 253 253 253 253 234 234 234 242 242 242
40686-253 253 253 253 253 253 253 253 253 253 253 253
40687-253 253 253 253 253 253 253 253 253 253 253 253
40688-253 253 253 253 253 253 253 253 253 253 253 253
40689-253 253 253 253 253 253 253 253 253 224 178 62
40690-242 186 14 241 196 14 210 166 10 22 18 6
40691- 2 2 6 2 2 6 2 2 6 2 2 6
40692- 2 2 6 2 2 6 6 6 6 121 92 8
40693-238 202 15 232 195 16 82 82 82 34 34 34
40694- 10 10 10 0 0 0 0 0 0 0 0 0
40695- 0 0 0 0 0 0 0 0 0 0 0 0
40696- 0 0 0 0 0 0 0 0 0 0 0 0
40697- 0 0 0 0 0 0 0 0 0 0 0 0
40698- 0 0 0 0 0 0 0 0 0 0 0 0
40699- 14 14 14 38 38 38 70 70 70 154 122 46
40700-190 142 34 200 144 11 197 138 11 197 138 11
40701-213 154 11 226 170 11 242 186 14 246 190 14
40702-246 190 14 246 190 14 246 190 14 246 190 14
40703-225 175 15 46 32 6 2 2 6 22 22 22
40704-158 158 158 250 250 250 253 253 253 253 253 253
40705-253 253 253 253 253 253 253 253 253 253 253 253
40706-253 253 253 253 253 253 253 253 253 253 253 253
40707-253 253 253 253 253 253 253 253 253 253 253 253
40708-253 253 253 253 253 253 253 253 253 253 253 253
40709-253 253 253 250 250 250 242 242 242 224 178 62
40710-239 182 13 236 186 11 213 154 11 46 32 6
40711- 2 2 6 2 2 6 2 2 6 2 2 6
40712- 2 2 6 2 2 6 61 42 6 225 175 15
40713-238 190 10 236 186 11 112 100 78 42 42 42
40714- 14 14 14 0 0 0 0 0 0 0 0 0
40715- 0 0 0 0 0 0 0 0 0 0 0 0
40716- 0 0 0 0 0 0 0 0 0 0 0 0
40717- 0 0 0 0 0 0 0 0 0 0 0 0
40718- 0 0 0 0 0 0 0 0 0 6 6 6
40719- 22 22 22 54 54 54 154 122 46 213 154 11
40720-226 170 11 230 174 11 226 170 11 226 170 11
40721-236 178 12 242 186 14 246 190 14 246 190 14
40722-246 190 14 246 190 14 246 190 14 246 190 14
40723-241 196 14 184 144 12 10 10 10 2 2 6
40724- 6 6 6 116 116 116 242 242 242 253 253 253
40725-253 253 253 253 253 253 253 253 253 253 253 253
40726-253 253 253 253 253 253 253 253 253 253 253 253
40727-253 253 253 253 253 253 253 253 253 253 253 253
40728-253 253 253 253 253 253 253 253 253 253 253 253
40729-253 253 253 231 231 231 198 198 198 214 170 54
40730-236 178 12 236 178 12 210 150 10 137 92 6
40731- 18 14 6 2 2 6 2 2 6 2 2 6
40732- 6 6 6 70 47 6 200 144 11 236 178 12
40733-239 182 13 239 182 13 124 112 88 58 58 58
40734- 22 22 22 6 6 6 0 0 0 0 0 0
40735- 0 0 0 0 0 0 0 0 0 0 0 0
40736- 0 0 0 0 0 0 0 0 0 0 0 0
40737- 0 0 0 0 0 0 0 0 0 0 0 0
40738- 0 0 0 0 0 0 0 0 0 10 10 10
40739- 30 30 30 70 70 70 180 133 36 226 170 11
40740-239 182 13 242 186 14 242 186 14 246 186 14
40741-246 190 14 246 190 14 246 190 14 246 190 14
40742-246 190 14 246 190 14 246 190 14 246 190 14
40743-246 190 14 232 195 16 98 70 6 2 2 6
40744- 2 2 6 2 2 6 66 66 66 221 221 221
40745-253 253 253 253 253 253 253 253 253 253 253 253
40746-253 253 253 253 253 253 253 253 253 253 253 253
40747-253 253 253 253 253 253 253 253 253 253 253 253
40748-253 253 253 253 253 253 253 253 253 253 253 253
40749-253 253 253 206 206 206 198 198 198 214 166 58
40750-230 174 11 230 174 11 216 158 10 192 133 9
40751-163 110 8 116 81 8 102 78 10 116 81 8
40752-167 114 7 197 138 11 226 170 11 239 182 13
40753-242 186 14 242 186 14 162 146 94 78 78 78
40754- 34 34 34 14 14 14 6 6 6 0 0 0
40755- 0 0 0 0 0 0 0 0 0 0 0 0
40756- 0 0 0 0 0 0 0 0 0 0 0 0
40757- 0 0 0 0 0 0 0 0 0 0 0 0
40758- 0 0 0 0 0 0 0 0 0 6 6 6
40759- 30 30 30 78 78 78 190 142 34 226 170 11
40760-239 182 13 246 190 14 246 190 14 246 190 14
40761-246 190 14 246 190 14 246 190 14 246 190 14
40762-246 190 14 246 190 14 246 190 14 246 190 14
40763-246 190 14 241 196 14 203 166 17 22 18 6
40764- 2 2 6 2 2 6 2 2 6 38 38 38
40765-218 218 218 253 253 253 253 253 253 253 253 253
40766-253 253 253 253 253 253 253 253 253 253 253 253
40767-253 253 253 253 253 253 253 253 253 253 253 253
40768-253 253 253 253 253 253 253 253 253 253 253 253
40769-250 250 250 206 206 206 198 198 198 202 162 69
40770-226 170 11 236 178 12 224 166 10 210 150 10
40771-200 144 11 197 138 11 192 133 9 197 138 11
40772-210 150 10 226 170 11 242 186 14 246 190 14
40773-246 190 14 246 186 14 225 175 15 124 112 88
40774- 62 62 62 30 30 30 14 14 14 6 6 6
40775- 0 0 0 0 0 0 0 0 0 0 0 0
40776- 0 0 0 0 0 0 0 0 0 0 0 0
40777- 0 0 0 0 0 0 0 0 0 0 0 0
40778- 0 0 0 0 0 0 0 0 0 10 10 10
40779- 30 30 30 78 78 78 174 135 50 224 166 10
40780-239 182 13 246 190 14 246 190 14 246 190 14
40781-246 190 14 246 190 14 246 190 14 246 190 14
40782-246 190 14 246 190 14 246 190 14 246 190 14
40783-246 190 14 246 190 14 241 196 14 139 102 15
40784- 2 2 6 2 2 6 2 2 6 2 2 6
40785- 78 78 78 250 250 250 253 253 253 253 253 253
40786-253 253 253 253 253 253 253 253 253 253 253 253
40787-253 253 253 253 253 253 253 253 253 253 253 253
40788-253 253 253 253 253 253 253 253 253 253 253 253
40789-250 250 250 214 214 214 198 198 198 190 150 46
40790-219 162 10 236 178 12 234 174 13 224 166 10
40791-216 158 10 213 154 11 213 154 11 216 158 10
40792-226 170 11 239 182 13 246 190 14 246 190 14
40793-246 190 14 246 190 14 242 186 14 206 162 42
40794-101 101 101 58 58 58 30 30 30 14 14 14
40795- 6 6 6 0 0 0 0 0 0 0 0 0
40796- 0 0 0 0 0 0 0 0 0 0 0 0
40797- 0 0 0 0 0 0 0 0 0 0 0 0
40798- 0 0 0 0 0 0 0 0 0 10 10 10
40799- 30 30 30 74 74 74 174 135 50 216 158 10
40800-236 178 12 246 190 14 246 190 14 246 190 14
40801-246 190 14 246 190 14 246 190 14 246 190 14
40802-246 190 14 246 190 14 246 190 14 246 190 14
40803-246 190 14 246 190 14 241 196 14 226 184 13
40804- 61 42 6 2 2 6 2 2 6 2 2 6
40805- 22 22 22 238 238 238 253 253 253 253 253 253
40806-253 253 253 253 253 253 253 253 253 253 253 253
40807-253 253 253 253 253 253 253 253 253 253 253 253
40808-253 253 253 253 253 253 253 253 253 253 253 253
40809-253 253 253 226 226 226 187 187 187 180 133 36
40810-216 158 10 236 178 12 239 182 13 236 178 12
40811-230 174 11 226 170 11 226 170 11 230 174 11
40812-236 178 12 242 186 14 246 190 14 246 190 14
40813-246 190 14 246 190 14 246 186 14 239 182 13
40814-206 162 42 106 106 106 66 66 66 34 34 34
40815- 14 14 14 6 6 6 0 0 0 0 0 0
40816- 0 0 0 0 0 0 0 0 0 0 0 0
40817- 0 0 0 0 0 0 0 0 0 0 0 0
40818- 0 0 0 0 0 0 0 0 0 6 6 6
40819- 26 26 26 70 70 70 163 133 67 213 154 11
40820-236 178 12 246 190 14 246 190 14 246 190 14
40821-246 190 14 246 190 14 246 190 14 246 190 14
40822-246 190 14 246 190 14 246 190 14 246 190 14
40823-246 190 14 246 190 14 246 190 14 241 196 14
40824-190 146 13 18 14 6 2 2 6 2 2 6
40825- 46 46 46 246 246 246 253 253 253 253 253 253
40826-253 253 253 253 253 253 253 253 253 253 253 253
40827-253 253 253 253 253 253 253 253 253 253 253 253
40828-253 253 253 253 253 253 253 253 253 253 253 253
40829-253 253 253 221 221 221 86 86 86 156 107 11
40830-216 158 10 236 178 12 242 186 14 246 186 14
40831-242 186 14 239 182 13 239 182 13 242 186 14
40832-242 186 14 246 186 14 246 190 14 246 190 14
40833-246 190 14 246 190 14 246 190 14 246 190 14
40834-242 186 14 225 175 15 142 122 72 66 66 66
40835- 30 30 30 10 10 10 0 0 0 0 0 0
40836- 0 0 0 0 0 0 0 0 0 0 0 0
40837- 0 0 0 0 0 0 0 0 0 0 0 0
40838- 0 0 0 0 0 0 0 0 0 6 6 6
40839- 26 26 26 70 70 70 163 133 67 210 150 10
40840-236 178 12 246 190 14 246 190 14 246 190 14
40841-246 190 14 246 190 14 246 190 14 246 190 14
40842-246 190 14 246 190 14 246 190 14 246 190 14
40843-246 190 14 246 190 14 246 190 14 246 190 14
40844-232 195 16 121 92 8 34 34 34 106 106 106
40845-221 221 221 253 253 253 253 253 253 253 253 253
40846-253 253 253 253 253 253 253 253 253 253 253 253
40847-253 253 253 253 253 253 253 253 253 253 253 253
40848-253 253 253 253 253 253 253 253 253 253 253 253
40849-242 242 242 82 82 82 18 14 6 163 110 8
40850-216 158 10 236 178 12 242 186 14 246 190 14
40851-246 190 14 246 190 14 246 190 14 246 190 14
40852-246 190 14 246 190 14 246 190 14 246 190 14
40853-246 190 14 246 190 14 246 190 14 246 190 14
40854-246 190 14 246 190 14 242 186 14 163 133 67
40855- 46 46 46 18 18 18 6 6 6 0 0 0
40856- 0 0 0 0 0 0 0 0 0 0 0 0
40857- 0 0 0 0 0 0 0 0 0 0 0 0
40858- 0 0 0 0 0 0 0 0 0 10 10 10
40859- 30 30 30 78 78 78 163 133 67 210 150 10
40860-236 178 12 246 186 14 246 190 14 246 190 14
40861-246 190 14 246 190 14 246 190 14 246 190 14
40862-246 190 14 246 190 14 246 190 14 246 190 14
40863-246 190 14 246 190 14 246 190 14 246 190 14
40864-241 196 14 215 174 15 190 178 144 253 253 253
40865-253 253 253 253 253 253 253 253 253 253 253 253
40866-253 253 253 253 253 253 253 253 253 253 253 253
40867-253 253 253 253 253 253 253 253 253 253 253 253
40868-253 253 253 253 253 253 253 253 253 218 218 218
40869- 58 58 58 2 2 6 22 18 6 167 114 7
40870-216 158 10 236 178 12 246 186 14 246 190 14
40871-246 190 14 246 190 14 246 190 14 246 190 14
40872-246 190 14 246 190 14 246 190 14 246 190 14
40873-246 190 14 246 190 14 246 190 14 246 190 14
40874-246 190 14 246 186 14 242 186 14 190 150 46
40875- 54 54 54 22 22 22 6 6 6 0 0 0
40876- 0 0 0 0 0 0 0 0 0 0 0 0
40877- 0 0 0 0 0 0 0 0 0 0 0 0
40878- 0 0 0 0 0 0 0 0 0 14 14 14
40879- 38 38 38 86 86 86 180 133 36 213 154 11
40880-236 178 12 246 186 14 246 190 14 246 190 14
40881-246 190 14 246 190 14 246 190 14 246 190 14
40882-246 190 14 246 190 14 246 190 14 246 190 14
40883-246 190 14 246 190 14 246 190 14 246 190 14
40884-246 190 14 232 195 16 190 146 13 214 214 214
40885-253 253 253 253 253 253 253 253 253 253 253 253
40886-253 253 253 253 253 253 253 253 253 253 253 253
40887-253 253 253 253 253 253 253 253 253 253 253 253
40888-253 253 253 250 250 250 170 170 170 26 26 26
40889- 2 2 6 2 2 6 37 26 9 163 110 8
40890-219 162 10 239 182 13 246 186 14 246 190 14
40891-246 190 14 246 190 14 246 190 14 246 190 14
40892-246 190 14 246 190 14 246 190 14 246 190 14
40893-246 190 14 246 190 14 246 190 14 246 190 14
40894-246 186 14 236 178 12 224 166 10 142 122 72
40895- 46 46 46 18 18 18 6 6 6 0 0 0
40896- 0 0 0 0 0 0 0 0 0 0 0 0
40897- 0 0 0 0 0 0 0 0 0 0 0 0
40898- 0 0 0 0 0 0 6 6 6 18 18 18
40899- 50 50 50 109 106 95 192 133 9 224 166 10
40900-242 186 14 246 190 14 246 190 14 246 190 14
40901-246 190 14 246 190 14 246 190 14 246 190 14
40902-246 190 14 246 190 14 246 190 14 246 190 14
40903-246 190 14 246 190 14 246 190 14 246 190 14
40904-242 186 14 226 184 13 210 162 10 142 110 46
40905-226 226 226 253 253 253 253 253 253 253 253 253
40906-253 253 253 253 253 253 253 253 253 253 253 253
40907-253 253 253 253 253 253 253 253 253 253 253 253
40908-198 198 198 66 66 66 2 2 6 2 2 6
40909- 2 2 6 2 2 6 50 34 6 156 107 11
40910-219 162 10 239 182 13 246 186 14 246 190 14
40911-246 190 14 246 190 14 246 190 14 246 190 14
40912-246 190 14 246 190 14 246 190 14 246 190 14
40913-246 190 14 246 190 14 246 190 14 242 186 14
40914-234 174 13 213 154 11 154 122 46 66 66 66
40915- 30 30 30 10 10 10 0 0 0 0 0 0
40916- 0 0 0 0 0 0 0 0 0 0 0 0
40917- 0 0 0 0 0 0 0 0 0 0 0 0
40918- 0 0 0 0 0 0 6 6 6 22 22 22
40919- 58 58 58 154 121 60 206 145 10 234 174 13
40920-242 186 14 246 186 14 246 190 14 246 190 14
40921-246 190 14 246 190 14 246 190 14 246 190 14
40922-246 190 14 246 190 14 246 190 14 246 190 14
40923-246 190 14 246 190 14 246 190 14 246 190 14
40924-246 186 14 236 178 12 210 162 10 163 110 8
40925- 61 42 6 138 138 138 218 218 218 250 250 250
40926-253 253 253 253 253 253 253 253 253 250 250 250
40927-242 242 242 210 210 210 144 144 144 66 66 66
40928- 6 6 6 2 2 6 2 2 6 2 2 6
40929- 2 2 6 2 2 6 61 42 6 163 110 8
40930-216 158 10 236 178 12 246 190 14 246 190 14
40931-246 190 14 246 190 14 246 190 14 246 190 14
40932-246 190 14 246 190 14 246 190 14 246 190 14
40933-246 190 14 239 182 13 230 174 11 216 158 10
40934-190 142 34 124 112 88 70 70 70 38 38 38
40935- 18 18 18 6 6 6 0 0 0 0 0 0
40936- 0 0 0 0 0 0 0 0 0 0 0 0
40937- 0 0 0 0 0 0 0 0 0 0 0 0
40938- 0 0 0 0 0 0 6 6 6 22 22 22
40939- 62 62 62 168 124 44 206 145 10 224 166 10
40940-236 178 12 239 182 13 242 186 14 242 186 14
40941-246 186 14 246 190 14 246 190 14 246 190 14
40942-246 190 14 246 190 14 246 190 14 246 190 14
40943-246 190 14 246 190 14 246 190 14 246 190 14
40944-246 190 14 236 178 12 216 158 10 175 118 6
40945- 80 54 7 2 2 6 6 6 6 30 30 30
40946- 54 54 54 62 62 62 50 50 50 38 38 38
40947- 14 14 14 2 2 6 2 2 6 2 2 6
40948- 2 2 6 2 2 6 2 2 6 2 2 6
40949- 2 2 6 6 6 6 80 54 7 167 114 7
40950-213 154 11 236 178 12 246 190 14 246 190 14
40951-246 190 14 246 190 14 246 190 14 246 190 14
40952-246 190 14 242 186 14 239 182 13 239 182 13
40953-230 174 11 210 150 10 174 135 50 124 112 88
40954- 82 82 82 54 54 54 34 34 34 18 18 18
40955- 6 6 6 0 0 0 0 0 0 0 0 0
40956- 0 0 0 0 0 0 0 0 0 0 0 0
40957- 0 0 0 0 0 0 0 0 0 0 0 0
40958- 0 0 0 0 0 0 6 6 6 18 18 18
40959- 50 50 50 158 118 36 192 133 9 200 144 11
40960-216 158 10 219 162 10 224 166 10 226 170 11
40961-230 174 11 236 178 12 239 182 13 239 182 13
40962-242 186 14 246 186 14 246 190 14 246 190 14
40963-246 190 14 246 190 14 246 190 14 246 190 14
40964-246 186 14 230 174 11 210 150 10 163 110 8
40965-104 69 6 10 10 10 2 2 6 2 2 6
40966- 2 2 6 2 2 6 2 2 6 2 2 6
40967- 2 2 6 2 2 6 2 2 6 2 2 6
40968- 2 2 6 2 2 6 2 2 6 2 2 6
40969- 2 2 6 6 6 6 91 60 6 167 114 7
40970-206 145 10 230 174 11 242 186 14 246 190 14
40971-246 190 14 246 190 14 246 186 14 242 186 14
40972-239 182 13 230 174 11 224 166 10 213 154 11
40973-180 133 36 124 112 88 86 86 86 58 58 58
40974- 38 38 38 22 22 22 10 10 10 6 6 6
40975- 0 0 0 0 0 0 0 0 0 0 0 0
40976- 0 0 0 0 0 0 0 0 0 0 0 0
40977- 0 0 0 0 0 0 0 0 0 0 0 0
40978- 0 0 0 0 0 0 0 0 0 14 14 14
40979- 34 34 34 70 70 70 138 110 50 158 118 36
40980-167 114 7 180 123 7 192 133 9 197 138 11
40981-200 144 11 206 145 10 213 154 11 219 162 10
40982-224 166 10 230 174 11 239 182 13 242 186 14
40983-246 186 14 246 186 14 246 186 14 246 186 14
40984-239 182 13 216 158 10 185 133 11 152 99 6
40985-104 69 6 18 14 6 2 2 6 2 2 6
40986- 2 2 6 2 2 6 2 2 6 2 2 6
40987- 2 2 6 2 2 6 2 2 6 2 2 6
40988- 2 2 6 2 2 6 2 2 6 2 2 6
40989- 2 2 6 6 6 6 80 54 7 152 99 6
40990-192 133 9 219 162 10 236 178 12 239 182 13
40991-246 186 14 242 186 14 239 182 13 236 178 12
40992-224 166 10 206 145 10 192 133 9 154 121 60
40993- 94 94 94 62 62 62 42 42 42 22 22 22
40994- 14 14 14 6 6 6 0 0 0 0 0 0
40995- 0 0 0 0 0 0 0 0 0 0 0 0
40996- 0 0 0 0 0 0 0 0 0 0 0 0
40997- 0 0 0 0 0 0 0 0 0 0 0 0
40998- 0 0 0 0 0 0 0 0 0 6 6 6
40999- 18 18 18 34 34 34 58 58 58 78 78 78
41000-101 98 89 124 112 88 142 110 46 156 107 11
41001-163 110 8 167 114 7 175 118 6 180 123 7
41002-185 133 11 197 138 11 210 150 10 219 162 10
41003-226 170 11 236 178 12 236 178 12 234 174 13
41004-219 162 10 197 138 11 163 110 8 130 83 6
41005- 91 60 6 10 10 10 2 2 6 2 2 6
41006- 18 18 18 38 38 38 38 38 38 38 38 38
41007- 38 38 38 38 38 38 38 38 38 38 38 38
41008- 38 38 38 38 38 38 26 26 26 2 2 6
41009- 2 2 6 6 6 6 70 47 6 137 92 6
41010-175 118 6 200 144 11 219 162 10 230 174 11
41011-234 174 13 230 174 11 219 162 10 210 150 10
41012-192 133 9 163 110 8 124 112 88 82 82 82
41013- 50 50 50 30 30 30 14 14 14 6 6 6
41014- 0 0 0 0 0 0 0 0 0 0 0 0
41015- 0 0 0 0 0 0 0 0 0 0 0 0
41016- 0 0 0 0 0 0 0 0 0 0 0 0
41017- 0 0 0 0 0 0 0 0 0 0 0 0
41018- 0 0 0 0 0 0 0 0 0 0 0 0
41019- 6 6 6 14 14 14 22 22 22 34 34 34
41020- 42 42 42 58 58 58 74 74 74 86 86 86
41021-101 98 89 122 102 70 130 98 46 121 87 25
41022-137 92 6 152 99 6 163 110 8 180 123 7
41023-185 133 11 197 138 11 206 145 10 200 144 11
41024-180 123 7 156 107 11 130 83 6 104 69 6
41025- 50 34 6 54 54 54 110 110 110 101 98 89
41026- 86 86 86 82 82 82 78 78 78 78 78 78
41027- 78 78 78 78 78 78 78 78 78 78 78 78
41028- 78 78 78 82 82 82 86 86 86 94 94 94
41029-106 106 106 101 101 101 86 66 34 124 80 6
41030-156 107 11 180 123 7 192 133 9 200 144 11
41031-206 145 10 200 144 11 192 133 9 175 118 6
41032-139 102 15 109 106 95 70 70 70 42 42 42
41033- 22 22 22 10 10 10 0 0 0 0 0 0
41034- 0 0 0 0 0 0 0 0 0 0 0 0
41035- 0 0 0 0 0 0 0 0 0 0 0 0
41036- 0 0 0 0 0 0 0 0 0 0 0 0
41037- 0 0 0 0 0 0 0 0 0 0 0 0
41038- 0 0 0 0 0 0 0 0 0 0 0 0
41039- 0 0 0 0 0 0 6 6 6 10 10 10
41040- 14 14 14 22 22 22 30 30 30 38 38 38
41041- 50 50 50 62 62 62 74 74 74 90 90 90
41042-101 98 89 112 100 78 121 87 25 124 80 6
41043-137 92 6 152 99 6 152 99 6 152 99 6
41044-138 86 6 124 80 6 98 70 6 86 66 30
41045-101 98 89 82 82 82 58 58 58 46 46 46
41046- 38 38 38 34 34 34 34 34 34 34 34 34
41047- 34 34 34 34 34 34 34 34 34 34 34 34
41048- 34 34 34 34 34 34 38 38 38 42 42 42
41049- 54 54 54 82 82 82 94 86 76 91 60 6
41050-134 86 6 156 107 11 167 114 7 175 118 6
41051-175 118 6 167 114 7 152 99 6 121 87 25
41052-101 98 89 62 62 62 34 34 34 18 18 18
41053- 6 6 6 0 0 0 0 0 0 0 0 0
41054- 0 0 0 0 0 0 0 0 0 0 0 0
41055- 0 0 0 0 0 0 0 0 0 0 0 0
41056- 0 0 0 0 0 0 0 0 0 0 0 0
41057- 0 0 0 0 0 0 0 0 0 0 0 0
41058- 0 0 0 0 0 0 0 0 0 0 0 0
41059- 0 0 0 0 0 0 0 0 0 0 0 0
41060- 0 0 0 6 6 6 6 6 6 10 10 10
41061- 18 18 18 22 22 22 30 30 30 42 42 42
41062- 50 50 50 66 66 66 86 86 86 101 98 89
41063-106 86 58 98 70 6 104 69 6 104 69 6
41064-104 69 6 91 60 6 82 62 34 90 90 90
41065- 62 62 62 38 38 38 22 22 22 14 14 14
41066- 10 10 10 10 10 10 10 10 10 10 10 10
41067- 10 10 10 10 10 10 6 6 6 10 10 10
41068- 10 10 10 10 10 10 10 10 10 14 14 14
41069- 22 22 22 42 42 42 70 70 70 89 81 66
41070- 80 54 7 104 69 6 124 80 6 137 92 6
41071-134 86 6 116 81 8 100 82 52 86 86 86
41072- 58 58 58 30 30 30 14 14 14 6 6 6
41073- 0 0 0 0 0 0 0 0 0 0 0 0
41074- 0 0 0 0 0 0 0 0 0 0 0 0
41075- 0 0 0 0 0 0 0 0 0 0 0 0
41076- 0 0 0 0 0 0 0 0 0 0 0 0
41077- 0 0 0 0 0 0 0 0 0 0 0 0
41078- 0 0 0 0 0 0 0 0 0 0 0 0
41079- 0 0 0 0 0 0 0 0 0 0 0 0
41080- 0 0 0 0 0 0 0 0 0 0 0 0
41081- 0 0 0 6 6 6 10 10 10 14 14 14
41082- 18 18 18 26 26 26 38 38 38 54 54 54
41083- 70 70 70 86 86 86 94 86 76 89 81 66
41084- 89 81 66 86 86 86 74 74 74 50 50 50
41085- 30 30 30 14 14 14 6 6 6 0 0 0
41086- 0 0 0 0 0 0 0 0 0 0 0 0
41087- 0 0 0 0 0 0 0 0 0 0 0 0
41088- 0 0 0 0 0 0 0 0 0 0 0 0
41089- 6 6 6 18 18 18 34 34 34 58 58 58
41090- 82 82 82 89 81 66 89 81 66 89 81 66
41091- 94 86 66 94 86 76 74 74 74 50 50 50
41092- 26 26 26 14 14 14 6 6 6 0 0 0
41093- 0 0 0 0 0 0 0 0 0 0 0 0
41094- 0 0 0 0 0 0 0 0 0 0 0 0
41095- 0 0 0 0 0 0 0 0 0 0 0 0
41096- 0 0 0 0 0 0 0 0 0 0 0 0
41097- 0 0 0 0 0 0 0 0 0 0 0 0
41098- 0 0 0 0 0 0 0 0 0 0 0 0
41099- 0 0 0 0 0 0 0 0 0 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- 6 6 6 6 6 6 14 14 14 18 18 18
41103- 30 30 30 38 38 38 46 46 46 54 54 54
41104- 50 50 50 42 42 42 30 30 30 18 18 18
41105- 10 10 10 0 0 0 0 0 0 0 0 0
41106- 0 0 0 0 0 0 0 0 0 0 0 0
41107- 0 0 0 0 0 0 0 0 0 0 0 0
41108- 0 0 0 0 0 0 0 0 0 0 0 0
41109- 0 0 0 6 6 6 14 14 14 26 26 26
41110- 38 38 38 50 50 50 58 58 58 58 58 58
41111- 54 54 54 42 42 42 30 30 30 18 18 18
41112- 10 10 10 0 0 0 0 0 0 0 0 0
41113- 0 0 0 0 0 0 0 0 0 0 0 0
41114- 0 0 0 0 0 0 0 0 0 0 0 0
41115- 0 0 0 0 0 0 0 0 0 0 0 0
41116- 0 0 0 0 0 0 0 0 0 0 0 0
41117- 0 0 0 0 0 0 0 0 0 0 0 0
41118- 0 0 0 0 0 0 0 0 0 0 0 0
41119- 0 0 0 0 0 0 0 0 0 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 6 6 6
41123- 6 6 6 10 10 10 14 14 14 18 18 18
41124- 18 18 18 14 14 14 10 10 10 6 6 6
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- 0 0 0 0 0 0 0 0 0 0 0 0
41128- 0 0 0 0 0 0 0 0 0 0 0 0
41129- 0 0 0 0 0 0 0 0 0 6 6 6
41130- 14 14 14 18 18 18 22 22 22 22 22 22
41131- 18 18 18 14 14 14 10 10 10 6 6 6
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 0 0 0 0 0 0 0 0 0
41135- 0 0 0 0 0 0 0 0 0 0 0 0
41136- 0 0 0 0 0 0 0 0 0 0 0 0
41137+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41138+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41139+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41140+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41141+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41142+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41143+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41144+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41145+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41146+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41147+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41148+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41149+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41150+4 4 4 4 4 4
41151+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41152+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41153+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41154+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41155+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41156+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41157+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41158+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41159+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41160+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41161+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41162+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41163+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41164+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 4 4 4 4 4 4 4 4 4 4 4 4
41176+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41177+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41178+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 4 4 4 4 4 4 4 4 4 4 4 4
41190+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41191+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41192+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 4 4 4 4 4 4 4 4 4 4 4 4
41204+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41205+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41206+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 4 4 4 4 4 4 4 4 4 4 4 4
41218+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41219+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41220+4 4 4 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 3 3 3 0 0 0 0 0 0
41226+0 0 0 0 0 0 0 0 0 0 0 0 3 3 3 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 1 1 1 0 0 0
41231+0 0 0 3 3 3 4 4 4 4 4 4 4 4 4 4 4 4
41232+4 4 4 4 4 4 4 4 4 2 1 0 2 1 0 3 2 2
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
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 2 2 2 0 0 0 3 4 3 26 28 28
41240+37 38 37 37 38 37 14 17 19 2 2 2 0 0 0 2 2 2
41241+5 5 5 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 3 3 3 0 0 0 1 1 1 6 6 6
41245+2 2 2 0 0 0 3 3 3 4 4 4 4 4 4 4 4 4
41246+4 4 5 3 3 3 1 0 0 0 0 0 1 0 0 0 0 0
41247+1 1 1 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41248+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 4 4 4 4 4 4 4 4 4
41251+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41252+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41253+2 2 2 0 0 0 0 0 0 14 17 19 60 74 84 137 136 137
41254+153 152 153 137 136 137 125 124 125 60 73 81 6 6 6 3 1 0
41255+0 0 0 3 3 3 4 4 4 4 4 4 4 4 4 4 4 4
41256+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41257+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41258+4 4 4 4 4 4 0 0 0 4 4 4 41 54 63 125 124 125
41259+60 73 81 6 6 6 4 0 0 3 3 3 4 4 4 4 4 4
41260+4 4 4 0 0 0 6 9 11 41 54 63 41 65 82 22 30 35
41261+2 2 2 2 1 0 4 4 4 4 4 4 4 4 4 4 4 4
41262+4 4 4 4 4 4
41263+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41264+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41265+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41266+4 4 4 4 4 4 5 5 5 5 5 5 2 2 2 0 0 0
41267+4 0 0 6 6 6 41 54 63 137 136 137 174 174 174 167 166 167
41268+165 164 165 165 164 165 163 162 163 163 162 163 125 124 125 41 54 63
41269+1 1 1 0 0 0 0 0 0 3 3 3 5 5 5 4 4 4
41270+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41271+4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 5 5 5
41272+3 3 3 2 0 0 4 0 0 60 73 81 156 155 156 167 166 167
41273+163 162 163 85 115 134 5 7 8 0 0 0 4 4 4 5 5 5
41274+0 0 0 2 5 5 55 98 126 90 154 193 90 154 193 72 125 159
41275+37 51 59 2 0 0 1 1 1 4 5 5 4 4 4 4 4 4
41276+4 4 4 4 4 4
41277+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41278+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41279+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41280+4 4 4 5 5 5 4 4 4 1 1 1 0 0 0 3 3 3
41281+37 38 37 125 124 125 163 162 163 174 174 174 158 157 158 158 157 158
41282+156 155 156 156 155 156 158 157 158 165 164 165 174 174 174 166 165 166
41283+125 124 125 16 19 21 1 0 0 0 0 0 0 0 0 4 4 4
41284+5 5 5 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
41285+4 4 4 4 4 4 4 4 4 5 5 5 5 5 5 1 1 1
41286+0 0 0 0 0 0 37 38 37 153 152 153 174 174 174 158 157 158
41287+174 174 174 163 162 163 37 38 37 4 3 3 4 0 0 1 1 1
41288+0 0 0 22 40 52 101 161 196 101 161 196 90 154 193 101 161 196
41289+64 123 161 14 17 19 0 0 0 4 4 4 4 4 4 4 4 4
41290+4 4 4 4 4 4
41291+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41292+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41293+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
41294+5 5 5 2 2 2 0 0 0 4 0 0 24 26 27 85 115 134
41295+156 155 156 174 174 174 167 166 167 156 155 156 154 153 154 157 156 157
41296+156 155 156 156 155 156 155 154 155 153 152 153 158 157 158 167 166 167
41297+174 174 174 156 155 156 60 74 84 16 19 21 0 0 0 0 0 0
41298+1 1 1 5 5 5 5 5 5 4 4 4 4 4 4 4 4 4
41299+4 4 4 5 5 5 6 6 6 3 3 3 0 0 0 4 0 0
41300+13 16 17 60 73 81 137 136 137 165 164 165 156 155 156 153 152 153
41301+174 174 174 177 184 187 60 73 81 3 1 0 0 0 0 1 1 2
41302+22 30 35 64 123 161 136 185 209 90 154 193 90 154 193 90 154 193
41303+90 154 193 21 29 34 0 0 0 3 2 2 4 4 5 4 4 4
41304+4 4 4 4 4 4
41305+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41306+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41307+4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 3 3 3
41308+0 0 0 0 0 0 10 13 16 60 74 84 157 156 157 174 174 174
41309+174 174 174 158 157 158 153 152 153 154 153 154 156 155 156 155 154 155
41310+156 155 156 155 154 155 154 153 154 157 156 157 154 153 154 153 152 153
41311+163 162 163 174 174 174 177 184 187 137 136 137 60 73 81 13 16 17
41312+4 0 0 0 0 0 3 3 3 5 5 5 4 4 4 4 4 4
41313+5 5 5 4 4 4 1 1 1 0 0 0 3 3 3 41 54 63
41314+131 129 131 174 174 174 174 174 174 174 174 174 167 166 167 174 174 174
41315+190 197 201 137 136 137 24 26 27 4 0 0 16 21 25 50 82 103
41316+90 154 193 136 185 209 90 154 193 101 161 196 101 161 196 101 161 196
41317+31 91 132 3 6 7 0 0 0 4 4 4 4 4 4 4 4 4
41318+4 4 4 4 4 4
41319+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41320+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41321+4 4 4 4 4 4 4 4 4 2 2 2 0 0 0 4 0 0
41322+4 0 0 43 57 68 137 136 137 177 184 187 174 174 174 163 162 163
41323+155 154 155 155 154 155 156 155 156 155 154 155 158 157 158 165 164 165
41324+167 166 167 166 165 166 163 162 163 157 156 157 155 154 155 155 154 155
41325+153 152 153 156 155 156 167 166 167 174 174 174 174 174 174 131 129 131
41326+41 54 63 5 5 5 0 0 0 0 0 0 3 3 3 4 4 4
41327+1 1 1 0 0 0 1 0 0 26 28 28 125 124 125 174 174 174
41328+177 184 187 174 174 174 174 174 174 156 155 156 131 129 131 137 136 137
41329+125 124 125 24 26 27 4 0 0 41 65 82 90 154 193 136 185 209
41330+136 185 209 101 161 196 53 118 160 37 112 160 90 154 193 34 86 122
41331+7 12 15 0 0 0 4 4 4 4 4 4 4 4 4 4 4 4
41332+4 4 4 4 4 4
41333+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41334+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41335+4 4 4 3 3 3 0 0 0 0 0 0 5 5 5 37 38 37
41336+125 124 125 167 166 167 174 174 174 167 166 167 158 157 158 155 154 155
41337+156 155 156 156 155 156 156 155 156 163 162 163 167 166 167 155 154 155
41338+137 136 137 153 152 153 156 155 156 165 164 165 163 162 163 156 155 156
41339+156 155 156 156 155 156 155 154 155 158 157 158 166 165 166 174 174 174
41340+167 166 167 125 124 125 37 38 37 1 0 0 0 0 0 0 0 0
41341+0 0 0 24 26 27 60 74 84 158 157 158 174 174 174 174 174 174
41342+166 165 166 158 157 158 125 124 125 41 54 63 13 16 17 6 6 6
41343+6 6 6 37 38 37 80 127 157 136 185 209 101 161 196 101 161 196
41344+90 154 193 28 67 93 6 10 14 13 20 25 13 20 25 6 10 14
41345+1 1 2 4 3 3 4 4 4 4 4 4 4 4 4 4 4 4
41346+4 4 4 4 4 4
41347+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41348+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41349+1 1 1 1 0 0 4 3 3 37 38 37 60 74 84 153 152 153
41350+167 166 167 167 166 167 158 157 158 154 153 154 155 154 155 156 155 156
41351+157 156 157 158 157 158 167 166 167 167 166 167 131 129 131 43 57 68
41352+26 28 28 37 38 37 60 73 81 131 129 131 165 164 165 166 165 166
41353+158 157 158 155 154 155 156 155 156 156 155 156 156 155 156 158 157 158
41354+165 164 165 174 174 174 163 162 163 60 74 84 16 19 21 13 16 17
41355+60 73 81 131 129 131 174 174 174 174 174 174 167 166 167 165 164 165
41356+137 136 137 60 73 81 24 26 27 4 0 0 4 0 0 16 19 21
41357+52 104 138 101 161 196 136 185 209 136 185 209 90 154 193 27 99 146
41358+13 20 25 4 5 7 2 5 5 4 5 7 1 1 2 0 0 0
41359+4 4 4 4 4 4 3 3 3 2 2 2 2 2 2 4 4 4
41360+4 4 4 4 4 4
41361+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41362+4 4 4 4 4 4 4 4 4 4 4 4 3 3 3 0 0 0
41363+0 0 0 13 16 17 60 73 81 137 136 137 174 174 174 166 165 166
41364+158 157 158 156 155 156 157 156 157 156 155 156 155 154 155 158 157 158
41365+167 166 167 174 174 174 153 152 153 60 73 81 16 19 21 4 0 0
41366+4 0 0 4 0 0 6 6 6 26 28 28 60 74 84 158 157 158
41367+174 174 174 166 165 166 157 156 157 155 154 155 156 155 156 156 155 156
41368+155 154 155 158 157 158 167 166 167 167 166 167 131 129 131 125 124 125
41369+137 136 137 167 166 167 167 166 167 174 174 174 158 157 158 125 124 125
41370+16 19 21 4 0 0 4 0 0 10 13 16 49 76 92 107 159 188
41371+136 185 209 136 185 209 90 154 193 26 108 161 22 40 52 6 10 14
41372+2 3 3 1 1 2 1 1 2 4 4 5 4 4 5 4 4 5
41373+4 4 5 2 2 1 0 0 0 0 0 0 0 0 0 2 2 2
41374+4 4 4 4 4 4
41375+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41376+4 4 4 5 5 5 3 3 3 0 0 0 1 0 0 4 0 0
41377+37 51 59 131 129 131 167 166 167 167 166 167 163 162 163 157 156 157
41378+157 156 157 155 154 155 153 152 153 157 156 157 167 166 167 174 174 174
41379+153 152 153 125 124 125 37 38 37 4 0 0 4 0 0 4 0 0
41380+4 3 3 4 3 3 4 0 0 6 6 6 4 0 0 37 38 37
41381+125 124 125 174 174 174 174 174 174 165 164 165 156 155 156 154 153 154
41382+156 155 156 156 155 156 155 154 155 163 162 163 158 157 158 163 162 163
41383+174 174 174 174 174 174 174 174 174 125 124 125 37 38 37 0 0 0
41384+4 0 0 6 9 11 41 54 63 90 154 193 136 185 209 146 190 211
41385+136 185 209 37 112 160 22 40 52 6 10 14 3 6 7 1 1 2
41386+1 1 2 3 3 3 1 1 2 3 3 3 4 4 4 4 4 4
41387+2 2 2 2 0 0 16 19 21 37 38 37 24 26 27 0 0 0
41388+0 0 0 4 4 4
41389+4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 5 5 5
41390+4 4 4 0 0 0 0 0 0 0 0 0 26 28 28 120 125 127
41391+158 157 158 174 174 174 165 164 165 157 156 157 155 154 155 156 155 156
41392+153 152 153 153 152 153 167 166 167 174 174 174 174 174 174 125 124 125
41393+37 38 37 4 0 0 0 0 0 4 0 0 4 3 3 4 4 4
41394+4 4 4 4 4 4 5 5 5 4 0 0 4 0 0 4 0 0
41395+4 3 3 43 57 68 137 136 137 174 174 174 174 174 174 165 164 165
41396+154 153 154 153 152 153 153 152 153 153 152 153 163 162 163 174 174 174
41397+174 174 174 153 152 153 60 73 81 6 6 6 4 0 0 4 3 3
41398+32 43 50 80 127 157 136 185 209 146 190 211 146 190 211 90 154 193
41399+28 67 93 28 67 93 40 71 93 3 6 7 1 1 2 2 5 5
41400+50 82 103 79 117 143 26 37 45 0 0 0 3 3 3 1 1 1
41401+0 0 0 41 54 63 137 136 137 174 174 174 153 152 153 60 73 81
41402+2 0 0 0 0 0
41403+4 4 4 4 4 4 4 4 4 4 4 4 6 6 6 2 2 2
41404+0 0 0 2 0 0 24 26 27 60 74 84 153 152 153 174 174 174
41405+174 174 174 157 156 157 154 153 154 156 155 156 154 153 154 153 152 153
41406+165 164 165 174 174 174 177 184 187 137 136 137 43 57 68 6 6 6
41407+4 0 0 2 0 0 3 3 3 5 5 5 5 5 5 4 4 4
41408+4 4 4 4 4 4 4 4 4 5 5 5 6 6 6 4 3 3
41409+4 0 0 4 0 0 24 26 27 60 73 81 153 152 153 174 174 174
41410+174 174 174 158 157 158 158 157 158 174 174 174 174 174 174 158 157 158
41411+60 74 84 24 26 27 4 0 0 4 0 0 17 23 27 59 113 148
41412+136 185 209 191 222 234 146 190 211 136 185 209 31 91 132 7 11 13
41413+22 40 52 101 161 196 90 154 193 6 9 11 3 4 4 43 95 132
41414+136 185 209 172 205 220 55 98 126 0 0 0 0 0 0 2 0 0
41415+26 28 28 153 152 153 177 184 187 167 166 167 177 184 187 165 164 165
41416+37 38 37 0 0 0
41417+4 4 4 4 4 4 5 5 5 5 5 5 1 1 1 0 0 0
41418+13 16 17 60 73 81 137 136 137 174 174 174 174 174 174 165 164 165
41419+153 152 153 153 152 153 155 154 155 154 153 154 158 157 158 174 174 174
41420+177 184 187 163 162 163 60 73 81 16 19 21 4 0 0 4 0 0
41421+4 3 3 4 4 4 5 5 5 5 5 5 4 4 4 5 5 5
41422+5 5 5 5 5 5 5 5 5 4 4 4 4 4 4 5 5 5
41423+6 6 6 4 0 0 4 0 0 4 0 0 24 26 27 60 74 84
41424+166 165 166 174 174 174 177 184 187 165 164 165 125 124 125 24 26 27
41425+4 0 0 4 0 0 5 5 5 50 82 103 136 185 209 172 205 220
41426+146 190 211 136 185 209 26 108 161 22 40 52 7 12 15 44 81 103
41427+71 116 144 28 67 93 37 51 59 41 65 82 100 139 164 101 161 196
41428+90 154 193 90 154 193 28 67 93 0 0 0 0 0 0 26 28 28
41429+125 124 125 167 166 167 163 162 163 153 152 153 163 162 163 174 174 174
41430+85 115 134 4 0 0
41431+4 4 4 5 5 5 4 4 4 1 0 0 4 0 0 34 47 55
41432+125 124 125 174 174 174 174 174 174 167 166 167 157 156 157 153 152 153
41433+155 154 155 155 154 155 158 157 158 166 165 166 167 166 167 154 153 154
41434+125 124 125 26 28 28 4 0 0 4 0 0 4 0 0 5 5 5
41435+5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 1 1 1
41436+0 0 0 0 0 0 1 1 1 4 4 4 4 4 4 4 4 4
41437+5 5 5 5 5 5 4 3 3 4 0 0 4 0 0 6 6 6
41438+37 38 37 131 129 131 137 136 137 37 38 37 0 0 0 4 0 0
41439+4 5 5 43 61 72 90 154 193 172 205 220 146 190 211 136 185 209
41440+90 154 193 28 67 93 13 20 25 43 61 72 71 116 144 44 81 103
41441+2 5 5 7 11 13 59 113 148 101 161 196 90 154 193 28 67 93
41442+13 20 25 6 10 14 0 0 0 13 16 17 60 73 81 137 136 137
41443+166 165 166 158 157 158 156 155 156 154 153 154 167 166 167 174 174 174
41444+60 73 81 4 0 0
41445+4 4 4 4 4 4 0 0 0 3 3 3 60 74 84 174 174 174
41446+174 174 174 167 166 167 163 162 163 155 154 155 157 156 157 155 154 155
41447+156 155 156 163 162 163 167 166 167 158 157 158 125 124 125 37 38 37
41448+4 3 3 4 0 0 4 0 0 6 6 6 6 6 6 5 5 5
41449+4 4 4 4 4 4 4 4 4 1 1 1 0 0 0 2 3 3
41450+10 13 16 7 11 13 1 0 0 0 0 0 2 2 1 4 4 4
41451+4 4 4 4 4 4 4 4 4 5 5 5 4 3 3 4 0 0
41452+4 0 0 7 11 13 13 16 17 4 0 0 3 3 3 34 47 55
41453+80 127 157 146 190 211 172 205 220 136 185 209 136 185 209 136 185 209
41454+28 67 93 22 40 52 55 98 126 55 98 126 21 29 34 7 11 13
41455+50 82 103 101 161 196 101 161 196 35 83 115 13 20 25 2 2 1
41456+1 1 2 1 1 2 37 51 59 131 129 131 174 174 174 174 174 174
41457+167 166 167 163 162 163 163 162 163 167 166 167 174 174 174 125 124 125
41458+16 19 21 4 0 0
41459+4 4 4 4 0 0 4 0 0 60 74 84 174 174 174 174 174 174
41460+158 157 158 155 154 155 155 154 155 156 155 156 155 154 155 158 157 158
41461+167 166 167 165 164 165 131 129 131 60 73 81 13 16 17 4 0 0
41462+4 0 0 4 3 3 6 6 6 4 3 3 5 5 5 4 4 4
41463+4 4 4 3 2 2 0 0 0 0 0 0 7 11 13 45 69 86
41464+80 127 157 71 116 144 43 61 72 7 11 13 0 0 0 1 1 1
41465+4 3 3 4 4 4 4 4 4 4 4 4 6 6 6 5 5 5
41466+3 2 2 4 0 0 1 0 0 21 29 34 59 113 148 136 185 209
41467+146 190 211 136 185 209 136 185 209 136 185 209 136 185 209 136 185 209
41468+68 124 159 44 81 103 22 40 52 13 16 17 43 61 72 90 154 193
41469+136 185 209 59 113 148 21 29 34 3 4 3 1 1 1 0 0 0
41470+24 26 27 125 124 125 163 162 163 174 174 174 166 165 166 165 164 165
41471+163 162 163 125 124 125 125 124 125 125 124 125 125 124 125 26 28 28
41472+4 0 0 4 3 3
41473+3 3 3 0 0 0 24 26 27 153 152 153 177 184 187 158 157 158
41474+156 155 156 156 155 156 155 154 155 155 154 155 165 164 165 174 174 174
41475+155 154 155 60 74 84 26 28 28 4 0 0 4 0 0 3 1 0
41476+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 3 3
41477+2 0 0 0 0 0 0 0 0 32 43 50 72 125 159 101 161 196
41478+136 185 209 101 161 196 101 161 196 79 117 143 32 43 50 0 0 0
41479+0 0 0 2 2 2 4 4 4 4 4 4 3 3 3 1 0 0
41480+0 0 0 4 5 5 49 76 92 101 161 196 146 190 211 146 190 211
41481+136 185 209 136 185 209 136 185 209 136 185 209 136 185 209 90 154 193
41482+28 67 93 13 16 17 37 51 59 80 127 157 136 185 209 90 154 193
41483+22 40 52 6 9 11 3 4 3 2 2 1 16 19 21 60 73 81
41484+137 136 137 163 162 163 158 157 158 166 165 166 167 166 167 153 152 153
41485+60 74 84 37 38 37 6 6 6 13 16 17 4 0 0 1 0 0
41486+3 2 2 4 4 4
41487+3 2 2 4 0 0 37 38 37 137 136 137 167 166 167 158 157 158
41488+157 156 157 154 153 154 157 156 157 167 166 167 174 174 174 125 124 125
41489+37 38 37 4 0 0 4 0 0 4 0 0 4 3 3 4 4 4
41490+4 4 4 4 4 4 5 5 5 5 5 5 1 1 1 0 0 0
41491+0 0 0 16 21 25 55 98 126 90 154 193 136 185 209 101 161 196
41492+101 161 196 101 161 196 136 185 209 136 185 209 101 161 196 55 98 126
41493+14 17 19 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
41494+22 40 52 90 154 193 146 190 211 146 190 211 136 185 209 136 185 209
41495+136 185 209 136 185 209 136 185 209 101 161 196 35 83 115 7 11 13
41496+17 23 27 59 113 148 136 185 209 101 161 196 34 86 122 7 12 15
41497+2 5 5 3 4 3 6 6 6 60 73 81 131 129 131 163 162 163
41498+166 165 166 174 174 174 174 174 174 163 162 163 125 124 125 41 54 63
41499+13 16 17 4 0 0 4 0 0 4 0 0 1 0 0 2 2 2
41500+4 4 4 4 4 4
41501+1 1 1 2 1 0 43 57 68 137 136 137 153 152 153 153 152 153
41502+163 162 163 156 155 156 165 164 165 167 166 167 60 74 84 6 6 6
41503+4 0 0 4 0 0 5 5 5 4 4 4 4 4 4 4 4 4
41504+4 5 5 6 6 6 4 3 3 0 0 0 0 0 0 11 15 18
41505+40 71 93 100 139 164 101 161 196 101 161 196 101 161 196 101 161 196
41506+101 161 196 101 161 196 101 161 196 101 161 196 136 185 209 136 185 209
41507+101 161 196 45 69 86 6 6 6 0 0 0 17 23 27 55 98 126
41508+136 185 209 146 190 211 136 185 209 136 185 209 136 185 209 136 185 209
41509+136 185 209 136 185 209 90 154 193 22 40 52 7 11 13 50 82 103
41510+136 185 209 136 185 209 53 118 160 22 40 52 7 11 13 2 5 5
41511+3 4 3 37 38 37 125 124 125 157 156 157 166 165 166 167 166 167
41512+174 174 174 174 174 174 137 136 137 60 73 81 4 0 0 4 0 0
41513+4 0 0 4 0 0 5 5 5 3 3 3 3 3 3 4 4 4
41514+4 4 4 4 4 4
41515+4 0 0 4 0 0 41 54 63 137 136 137 125 124 125 131 129 131
41516+155 154 155 167 166 167 174 174 174 60 74 84 6 6 6 4 0 0
41517+4 3 3 6 6 6 4 4 4 4 4 4 4 4 4 5 5 5
41518+4 4 4 1 1 1 0 0 0 3 6 7 41 65 82 72 125 159
41519+101 161 196 101 161 196 101 161 196 90 154 193 90 154 193 101 161 196
41520+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 136 185 209
41521+136 185 209 136 185 209 80 127 157 55 98 126 101 161 196 146 190 211
41522+136 185 209 136 185 209 136 185 209 101 161 196 136 185 209 101 161 196
41523+136 185 209 101 161 196 35 83 115 22 30 35 101 161 196 172 205 220
41524+90 154 193 28 67 93 7 11 13 2 5 5 3 4 3 13 16 17
41525+85 115 134 167 166 167 174 174 174 174 174 174 174 174 174 174 174 174
41526+167 166 167 60 74 84 13 16 17 4 0 0 4 0 0 4 3 3
41527+6 6 6 5 5 5 4 4 4 5 5 5 4 4 4 5 5 5
41528+5 5 5 5 5 5
41529+1 1 1 4 0 0 41 54 63 137 136 137 137 136 137 125 124 125
41530+131 129 131 167 166 167 157 156 157 37 38 37 6 6 6 4 0 0
41531+6 6 6 5 5 5 4 4 4 4 4 4 4 5 5 2 2 1
41532+0 0 0 0 0 0 26 37 45 58 111 146 101 161 196 101 161 196
41533+101 161 196 90 154 193 90 154 193 90 154 193 101 161 196 101 161 196
41534+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
41535+101 161 196 136 185 209 136 185 209 136 185 209 146 190 211 136 185 209
41536+136 185 209 101 161 196 136 185 209 136 185 209 101 161 196 136 185 209
41537+101 161 196 136 185 209 136 185 209 136 185 209 136 185 209 16 89 141
41538+7 11 13 2 5 5 2 5 5 13 16 17 60 73 81 154 154 154
41539+174 174 174 174 174 174 174 174 174 174 174 174 163 162 163 125 124 125
41540+24 26 27 4 0 0 4 0 0 4 0 0 5 5 5 5 5 5
41541+4 4 4 4 4 4 4 4 4 5 5 5 5 5 5 5 5 5
41542+5 5 5 4 4 4
41543+4 0 0 6 6 6 37 38 37 137 136 137 137 136 137 131 129 131
41544+131 129 131 153 152 153 131 129 131 26 28 28 4 0 0 4 3 3
41545+6 6 6 4 4 4 4 4 4 4 4 4 0 0 0 0 0 0
41546+13 20 25 51 88 114 90 154 193 101 161 196 101 161 196 90 154 193
41547+90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 101 161 196
41548+101 161 196 101 161 196 101 161 196 101 161 196 136 185 209 101 161 196
41549+101 161 196 136 185 209 101 161 196 136 185 209 136 185 209 101 161 196
41550+136 185 209 101 161 196 136 185 209 101 161 196 101 161 196 101 161 196
41551+136 185 209 136 185 209 136 185 209 37 112 160 21 29 34 5 7 8
41552+2 5 5 13 16 17 43 57 68 131 129 131 174 174 174 174 174 174
41553+174 174 174 167 166 167 157 156 157 125 124 125 37 38 37 4 0 0
41554+4 0 0 4 0 0 5 5 5 5 5 5 4 4 4 4 4 4
41555+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41556+4 4 4 4 4 4
41557+1 1 1 4 0 0 41 54 63 153 152 153 137 136 137 137 136 137
41558+137 136 137 153 152 153 125 124 125 24 26 27 4 0 0 3 2 2
41559+4 4 4 4 4 4 4 3 3 4 0 0 3 6 7 43 61 72
41560+64 123 161 101 161 196 90 154 193 90 154 193 90 154 193 90 154 193
41561+90 154 193 90 154 193 90 154 193 90 154 193 101 161 196 90 154 193
41562+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
41563+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
41564+136 185 209 101 161 196 101 161 196 136 185 209 136 185 209 101 161 196
41565+101 161 196 90 154 193 28 67 93 13 16 17 7 11 13 3 6 7
41566+37 51 59 125 124 125 163 162 163 174 174 174 167 166 167 166 165 166
41567+167 166 167 131 129 131 60 73 81 4 0 0 4 0 0 4 0 0
41568+3 3 3 5 5 5 6 6 6 4 4 4 4 4 4 4 4 4
41569+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41570+4 4 4 4 4 4
41571+4 0 0 4 0 0 41 54 63 137 136 137 153 152 153 137 136 137
41572+153 152 153 157 156 157 125 124 125 24 26 27 0 0 0 2 2 2
41573+4 4 4 4 4 4 2 0 0 0 0 0 28 67 93 90 154 193
41574+90 154 193 90 154 193 90 154 193 90 154 193 64 123 161 90 154 193
41575+90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 101 161 196
41576+90 154 193 101 161 196 101 161 196 101 161 196 90 154 193 136 185 209
41577+101 161 196 101 161 196 136 185 209 101 161 196 136 185 209 101 161 196
41578+101 161 196 101 161 196 136 185 209 101 161 196 101 161 196 90 154 193
41579+35 83 115 13 16 17 3 6 7 2 5 5 13 16 17 60 74 84
41580+154 154 154 166 165 166 165 164 165 158 157 158 163 162 163 157 156 157
41581+60 74 84 13 16 17 4 0 0 4 0 0 3 2 2 4 4 4
41582+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41583+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41584+4 4 4 4 4 4
41585+1 1 1 4 0 0 41 54 63 157 156 157 155 154 155 137 136 137
41586+153 152 153 158 157 158 137 136 137 26 28 28 2 0 0 2 2 2
41587+4 4 4 4 4 4 1 0 0 6 10 14 34 86 122 90 154 193
41588+64 123 161 90 154 193 64 123 161 90 154 193 90 154 193 90 154 193
41589+64 123 161 90 154 193 90 154 193 90 154 193 90 154 193 90 154 193
41590+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
41591+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
41592+136 185 209 101 161 196 136 185 209 90 154 193 26 108 161 22 40 52
41593+13 16 17 5 7 8 2 5 5 2 5 5 37 38 37 165 164 165
41594+174 174 174 163 162 163 154 154 154 165 164 165 167 166 167 60 73 81
41595+6 6 6 4 0 0 4 0 0 4 4 4 4 4 4 4 4 4
41596+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41597+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41598+4 4 4 4 4 4
41599+4 0 0 6 6 6 41 54 63 156 155 156 158 157 158 153 152 153
41600+156 155 156 165 164 165 137 136 137 26 28 28 0 0 0 2 2 2
41601+4 4 5 4 4 4 2 0 0 7 12 15 31 96 139 64 123 161
41602+90 154 193 64 123 161 90 154 193 90 154 193 64 123 161 90 154 193
41603+90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 90 154 193
41604+90 154 193 90 154 193 90 154 193 101 161 196 101 161 196 101 161 196
41605+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 136 185 209
41606+101 161 196 136 185 209 26 108 161 22 40 52 7 11 13 5 7 8
41607+2 5 5 2 5 5 2 5 5 2 2 1 37 38 37 158 157 158
41608+174 174 174 154 154 154 156 155 156 167 166 167 165 164 165 37 38 37
41609+4 0 0 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41610+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41611+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41612+4 4 4 4 4 4
41613+3 1 0 4 0 0 60 73 81 157 156 157 163 162 163 153 152 153
41614+158 157 158 167 166 167 137 136 137 26 28 28 2 0 0 2 2 2
41615+4 5 5 4 4 4 4 0 0 7 12 15 24 86 132 26 108 161
41616+37 112 160 64 123 161 90 154 193 64 123 161 90 154 193 90 154 193
41617+90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 90 154 193
41618+90 154 193 101 161 196 90 154 193 101 161 196 101 161 196 101 161 196
41619+101 161 196 101 161 196 101 161 196 136 185 209 101 161 196 136 185 209
41620+90 154 193 35 83 115 13 16 17 13 16 17 7 11 13 3 6 7
41621+5 7 8 6 6 6 3 4 3 2 2 1 30 32 34 154 154 154
41622+167 166 167 154 154 154 154 154 154 174 174 174 165 164 165 37 38 37
41623+6 6 6 4 0 0 6 6 6 4 4 4 4 4 4 4 4 4
41624+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41625+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41626+4 4 4 4 4 4
41627+4 0 0 4 0 0 41 54 63 163 162 163 166 165 166 154 154 154
41628+163 162 163 174 174 174 137 136 137 26 28 28 0 0 0 2 2 2
41629+4 5 5 4 4 5 1 1 2 6 10 14 28 67 93 18 97 151
41630+18 97 151 18 97 151 26 108 161 37 112 160 37 112 160 90 154 193
41631+64 123 161 90 154 193 90 154 193 90 154 193 90 154 193 101 161 196
41632+90 154 193 101 161 196 101 161 196 90 154 193 101 161 196 101 161 196
41633+101 161 196 101 161 196 101 161 196 136 185 209 90 154 193 16 89 141
41634+13 20 25 7 11 13 5 7 8 5 7 8 2 5 5 4 5 5
41635+3 4 3 4 5 5 3 4 3 0 0 0 37 38 37 158 157 158
41636+174 174 174 158 157 158 158 157 158 167 166 167 174 174 174 41 54 63
41637+4 0 0 3 2 2 5 5 5 4 4 4 4 4 4 4 4 4
41638+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41639+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41640+4 4 4 4 4 4
41641+1 1 1 4 0 0 60 73 81 165 164 165 174 174 174 158 157 158
41642+167 166 167 174 174 174 153 152 153 26 28 28 2 0 0 2 2 2
41643+4 5 5 4 4 4 4 0 0 7 12 15 10 87 144 10 87 144
41644+18 97 151 18 97 151 18 97 151 26 108 161 26 108 161 26 108 161
41645+26 108 161 37 112 160 53 118 160 90 154 193 90 154 193 90 154 193
41646+90 154 193 90 154 193 101 161 196 101 161 196 101 161 196 101 161 196
41647+101 161 196 136 185 209 90 154 193 26 108 161 22 40 52 13 16 17
41648+7 11 13 3 6 7 5 7 8 5 7 8 2 5 5 4 5 5
41649+4 5 5 6 6 6 3 4 3 0 0 0 30 32 34 158 157 158
41650+174 174 174 156 155 156 155 154 155 165 164 165 154 153 154 37 38 37
41651+4 0 0 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41652+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41653+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41654+4 4 4 4 4 4
41655+4 0 0 4 0 0 60 73 81 167 166 167 174 174 174 163 162 163
41656+174 174 174 174 174 174 153 152 153 26 28 28 0 0 0 3 3 3
41657+5 5 5 4 4 4 1 1 2 7 12 15 28 67 93 18 97 151
41658+18 97 151 18 97 151 18 97 151 18 97 151 18 97 151 26 108 161
41659+26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
41660+90 154 193 26 108 161 90 154 193 90 154 193 90 154 193 101 161 196
41661+101 161 196 26 108 161 22 40 52 13 16 17 7 11 13 2 5 5
41662+2 5 5 6 6 6 2 5 5 4 5 5 4 5 5 4 5 5
41663+3 4 3 5 5 5 3 4 3 2 0 0 30 32 34 137 136 137
41664+153 152 153 137 136 137 131 129 131 137 136 137 131 129 131 37 38 37
41665+4 0 0 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41666+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41667+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41668+4 4 4 4 4 4
41669+1 1 1 4 0 0 60 73 81 167 166 167 174 174 174 166 165 166
41670+174 174 174 177 184 187 153 152 153 30 32 34 1 0 0 3 3 3
41671+5 5 5 4 3 3 4 0 0 7 12 15 10 87 144 10 87 144
41672+18 97 151 18 97 151 18 97 151 26 108 161 26 108 161 26 108 161
41673+26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
41674+26 108 161 26 108 161 26 108 161 90 154 193 90 154 193 26 108 161
41675+35 83 115 13 16 17 7 11 13 5 7 8 3 6 7 5 7 8
41676+2 5 5 6 6 6 4 5 5 4 5 5 3 4 3 4 5 5
41677+3 4 3 6 6 6 3 4 3 0 0 0 26 28 28 125 124 125
41678+131 129 131 125 124 125 125 124 125 131 129 131 131 129 131 37 38 37
41679+4 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41680+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41681+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41682+4 4 4 4 4 4
41683+3 1 0 4 0 0 60 73 81 174 174 174 177 184 187 167 166 167
41684+174 174 174 177 184 187 153 152 153 30 32 34 0 0 0 3 3 3
41685+5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 18 97 151
41686+18 97 151 18 97 151 18 97 151 18 97 151 18 97 151 26 108 161
41687+26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
41688+26 108 161 90 154 193 26 108 161 26 108 161 24 86 132 13 20 25
41689+7 11 13 13 20 25 22 40 52 5 7 8 3 4 3 3 4 3
41690+4 5 5 3 4 3 4 5 5 3 4 3 4 5 5 3 4 3
41691+4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 125 124 125
41692+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
41693+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41694+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41695+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41696+4 4 4 4 4 4
41697+1 1 1 4 0 0 60 73 81 174 174 174 177 184 187 174 174 174
41698+174 174 174 190 197 201 157 156 157 30 32 34 1 0 0 3 3 3
41699+5 5 5 4 3 3 4 0 0 7 12 15 10 87 144 10 87 144
41700+18 97 151 19 95 150 19 95 150 18 97 151 18 97 151 26 108 161
41701+18 97 151 26 108 161 26 108 161 26 108 161 26 108 161 90 154 193
41702+26 108 161 26 108 161 26 108 161 22 40 52 2 5 5 3 4 3
41703+28 67 93 37 112 160 34 86 122 2 5 5 3 4 3 3 4 3
41704+3 4 3 3 4 3 3 4 3 2 2 1 3 4 3 4 4 4
41705+4 5 5 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
41706+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
41707+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41708+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41709+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41710+4 4 4 4 4 4
41711+4 0 0 4 0 0 60 73 81 174 174 174 177 184 187 174 174 174
41712+174 174 174 190 197 201 158 157 158 30 32 34 0 0 0 2 2 2
41713+5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 18 97 151
41714+10 87 144 19 95 150 19 95 150 18 97 151 18 97 151 18 97 151
41715+26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
41716+18 97 151 22 40 52 2 5 5 2 2 1 22 40 52 26 108 161
41717+90 154 193 37 112 160 22 40 52 3 4 3 13 20 25 22 30 35
41718+3 6 7 1 1 1 2 2 2 6 9 11 5 5 5 4 3 3
41719+4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 131 129 131
41720+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
41721+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41722+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41723+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41724+4 4 4 4 4 4
41725+1 1 1 4 0 0 60 73 81 177 184 187 193 200 203 174 174 174
41726+177 184 187 193 200 203 163 162 163 30 32 34 4 0 0 2 2 2
41727+5 5 5 4 3 3 4 0 0 6 10 14 24 86 132 10 87 144
41728+10 87 144 10 87 144 19 95 150 19 95 150 19 95 150 18 97 151
41729+26 108 161 26 108 161 26 108 161 90 154 193 26 108 161 28 67 93
41730+6 10 14 2 5 5 13 20 25 24 86 132 37 112 160 90 154 193
41731+10 87 144 7 12 15 2 5 5 28 67 93 37 112 160 28 67 93
41732+2 2 1 7 12 15 35 83 115 28 67 93 3 6 7 1 0 0
41733+4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
41734+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
41735+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41736+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41737+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41738+4 4 4 4 4 4
41739+4 0 0 4 0 0 60 73 81 174 174 174 190 197 201 174 174 174
41740+177 184 187 193 200 203 163 162 163 30 32 34 0 0 0 2 2 2
41741+5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 10 87 144
41742+10 87 144 16 89 141 19 95 150 10 87 144 26 108 161 26 108 161
41743+26 108 161 26 108 161 26 108 161 28 67 93 6 10 14 1 1 2
41744+7 12 15 28 67 93 26 108 161 16 89 141 24 86 132 21 29 34
41745+3 4 3 21 29 34 37 112 160 37 112 160 27 99 146 21 29 34
41746+21 29 34 26 108 161 90 154 193 35 83 115 1 1 2 2 0 0
41747+4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 125 124 125
41748+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
41749+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41750+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41751+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41752+4 4 4 4 4 4
41753+3 1 0 4 0 0 60 73 81 193 200 203 193 200 203 174 174 174
41754+190 197 201 193 200 203 165 164 165 37 38 37 4 0 0 2 2 2
41755+5 5 5 4 3 3 4 0 0 6 10 14 24 86 132 10 87 144
41756+10 87 144 10 87 144 16 89 141 18 97 151 18 97 151 10 87 144
41757+24 86 132 24 86 132 13 20 25 4 5 7 4 5 7 22 40 52
41758+18 97 151 37 112 160 26 108 161 7 12 15 1 1 1 0 0 0
41759+28 67 93 37 112 160 26 108 161 28 67 93 22 40 52 28 67 93
41760+26 108 161 90 154 193 26 108 161 10 87 144 0 0 0 2 0 0
41761+4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
41762+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
41763+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41764+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41765+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41766+4 4 4 4 4 4
41767+4 0 0 6 6 6 60 73 81 174 174 174 193 200 203 174 174 174
41768+190 197 201 193 200 203 165 164 165 30 32 34 0 0 0 2 2 2
41769+5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 10 87 144
41770+10 87 144 10 87 144 10 87 144 18 97 151 28 67 93 6 10 14
41771+0 0 0 1 1 2 4 5 7 13 20 25 16 89 141 26 108 161
41772+26 108 161 26 108 161 24 86 132 6 9 11 2 3 3 22 40 52
41773+37 112 160 16 89 141 22 40 52 28 67 93 26 108 161 26 108 161
41774+90 154 193 26 108 161 26 108 161 28 67 93 1 1 1 4 0 0
41775+4 4 4 5 5 5 3 3 3 4 0 0 26 28 28 124 126 130
41776+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
41777+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41778+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41779+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41780+4 4 4 4 4 4
41781+4 0 0 4 0 0 60 73 81 193 200 203 193 200 203 174 174 174
41782+193 200 203 193 200 203 167 166 167 37 38 37 4 0 0 2 2 2
41783+5 5 5 4 4 4 4 0 0 6 10 14 28 67 93 10 87 144
41784+10 87 144 10 87 144 18 97 151 10 87 144 13 20 25 4 5 7
41785+1 1 2 1 1 1 22 40 52 26 108 161 26 108 161 26 108 161
41786+26 108 161 26 108 161 26 108 161 24 86 132 22 40 52 22 40 52
41787+22 40 52 22 40 52 10 87 144 26 108 161 26 108 161 26 108 161
41788+26 108 161 26 108 161 90 154 193 10 87 144 0 0 0 4 0 0
41789+4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
41790+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
41791+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41792+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41793+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41794+4 4 4 4 4 4
41795+4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
41796+190 197 201 205 212 215 167 166 167 30 32 34 0 0 0 2 2 2
41797+5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 10 87 144
41798+10 87 144 10 87 144 10 87 144 10 87 144 22 40 52 1 1 2
41799+2 0 0 1 1 2 24 86 132 26 108 161 26 108 161 26 108 161
41800+26 108 161 19 95 150 16 89 141 10 87 144 22 40 52 22 40 52
41801+10 87 144 26 108 161 37 112 160 26 108 161 26 108 161 26 108 161
41802+26 108 161 26 108 161 26 108 161 28 67 93 2 0 0 3 1 0
41803+4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 131 129 131
41804+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
41805+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41806+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41807+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41808+4 4 4 4 4 4
41809+4 0 0 4 0 0 60 73 81 220 221 221 190 197 201 174 174 174
41810+193 200 203 193 200 203 174 174 174 37 38 37 4 0 0 2 2 2
41811+5 5 5 4 4 4 3 2 2 1 1 2 13 20 25 10 87 144
41812+10 87 144 10 87 144 10 87 144 10 87 144 10 87 144 13 20 25
41813+13 20 25 22 40 52 10 87 144 18 97 151 18 97 151 26 108 161
41814+10 87 144 13 20 25 6 10 14 21 29 34 24 86 132 18 97 151
41815+26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
41816+26 108 161 90 154 193 18 97 151 13 20 25 0 0 0 4 3 3
41817+4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
41818+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
41819+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41820+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41821+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41822+4 4 4 4 4 4
41823+4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
41824+190 197 201 220 221 221 167 166 167 30 32 34 1 0 0 2 2 2
41825+5 5 5 4 4 4 4 4 5 2 5 5 4 5 7 13 20 25
41826+28 67 93 10 87 144 10 87 144 10 87 144 10 87 144 10 87 144
41827+10 87 144 10 87 144 18 97 151 10 87 144 18 97 151 18 97 151
41828+28 67 93 2 3 3 0 0 0 28 67 93 26 108 161 26 108 161
41829+26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
41830+26 108 161 10 87 144 13 20 25 1 1 2 3 2 2 4 4 4
41831+4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 131 129 131
41832+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
41833+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41834+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41835+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41836+4 4 4 4 4 4
41837+4 0 0 4 0 0 60 73 81 220 221 221 190 197 201 174 174 174
41838+193 200 203 193 200 203 174 174 174 26 28 28 4 0 0 4 3 3
41839+5 5 5 4 4 4 4 4 4 4 4 5 1 1 2 2 5 5
41840+4 5 7 22 40 52 10 87 144 10 87 144 18 97 151 10 87 144
41841+10 87 144 10 87 144 10 87 144 10 87 144 10 87 144 18 97 151
41842+10 87 144 28 67 93 22 40 52 10 87 144 26 108 161 18 97 151
41843+18 97 151 18 97 151 26 108 161 26 108 161 26 108 161 26 108 161
41844+22 40 52 1 1 2 0 0 0 2 3 3 4 4 4 4 4 4
41845+4 4 4 5 5 5 4 4 4 0 0 0 26 28 28 131 129 131
41846+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
41847+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41848+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41849+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41850+4 4 4 4 4 4
41851+4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
41852+190 197 201 220 221 221 190 197 201 41 54 63 4 0 0 2 2 2
41853+6 6 6 4 4 4 4 4 4 4 4 5 4 4 5 3 3 3
41854+1 1 2 1 1 2 6 10 14 22 40 52 10 87 144 18 97 151
41855+18 97 151 10 87 144 10 87 144 10 87 144 18 97 151 10 87 144
41856+10 87 144 18 97 151 26 108 161 18 97 151 18 97 151 10 87 144
41857+26 108 161 26 108 161 26 108 161 10 87 144 28 67 93 6 10 14
41858+1 1 2 1 1 2 4 3 3 4 4 5 4 4 4 4 4 4
41859+5 5 5 5 5 5 1 1 1 4 0 0 37 51 59 137 136 137
41860+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
41861+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41862+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41863+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41864+4 4 4 4 4 4
41865+4 0 0 4 0 0 60 73 81 220 221 221 193 200 203 174 174 174
41866+193 200 203 193 200 203 220 221 221 137 136 137 13 16 17 4 0 0
41867+2 2 2 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5
41868+4 4 5 4 3 3 1 1 2 4 5 7 13 20 25 28 67 93
41869+10 87 144 10 87 144 10 87 144 10 87 144 10 87 144 10 87 144
41870+10 87 144 18 97 151 18 97 151 10 87 144 18 97 151 26 108 161
41871+26 108 161 18 97 151 28 67 93 6 10 14 0 0 0 0 0 0
41872+2 3 3 4 5 5 4 4 5 4 4 4 4 4 4 5 5 5
41873+3 3 3 1 1 1 0 0 0 16 19 21 125 124 125 137 136 137
41874+131 129 131 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
41875+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41876+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41877+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41878+4 4 4 4 4 4
41879+4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
41880+193 200 203 190 197 201 220 221 221 220 221 221 153 152 153 30 32 34
41881+0 0 0 0 0 0 2 2 2 4 4 4 4 4 4 4 4 4
41882+4 4 4 4 5 5 4 5 7 1 1 2 1 1 2 4 5 7
41883+13 20 25 28 67 93 10 87 144 18 97 151 10 87 144 10 87 144
41884+10 87 144 10 87 144 10 87 144 18 97 151 26 108 161 18 97 151
41885+28 67 93 7 12 15 0 0 0 0 0 0 2 2 1 4 4 4
41886+4 5 5 4 5 5 4 4 4 4 4 4 3 3 3 0 0 0
41887+0 0 0 0 0 0 37 38 37 125 124 125 158 157 158 131 129 131
41888+125 124 125 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
41889+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41890+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41891+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41892+4 4 4 4 4 4
41893+4 3 3 4 0 0 41 54 63 193 200 203 220 221 221 174 174 174
41894+193 200 203 193 200 203 193 200 203 220 221 221 244 246 246 193 200 203
41895+120 125 127 5 5 5 1 0 0 0 0 0 1 1 1 4 4 4
41896+4 4 4 4 4 4 4 5 5 4 5 5 4 4 5 1 1 2
41897+4 5 7 4 5 7 22 40 52 10 87 144 10 87 144 10 87 144
41898+10 87 144 10 87 144 18 97 151 10 87 144 10 87 144 13 20 25
41899+4 5 7 2 3 3 1 1 2 4 4 4 4 5 5 4 4 4
41900+4 4 4 4 4 4 4 4 4 1 1 1 0 0 0 1 1 2
41901+24 26 27 60 74 84 153 152 153 163 162 163 137 136 137 125 124 125
41902+125 124 125 125 124 125 125 124 125 137 136 137 125 124 125 26 28 28
41903+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41904+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41905+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41906+4 4 4 4 4 4
41907+4 0 0 6 6 6 26 28 28 156 155 156 220 221 221 220 221 221
41908+174 174 174 193 200 203 193 200 203 193 200 203 205 212 215 220 221 221
41909+220 221 221 167 166 167 60 73 81 7 11 13 0 0 0 0 0 0
41910+3 3 3 4 4 4 4 4 4 4 4 4 4 4 5 4 4 5
41911+4 4 5 1 1 2 1 1 2 4 5 7 22 40 52 10 87 144
41912+10 87 144 10 87 144 10 87 144 22 40 52 4 5 7 1 1 2
41913+1 1 2 4 4 5 4 4 4 4 4 4 4 4 4 4 4 4
41914+5 5 5 2 2 2 0 0 0 4 0 0 16 19 21 60 73 81
41915+137 136 137 167 166 167 158 157 158 137 136 137 131 129 131 131 129 131
41916+125 124 125 125 124 125 131 129 131 155 154 155 60 74 84 5 7 8
41917+0 0 0 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41918+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41919+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41920+4 4 4 4 4 4
41921+5 5 5 4 0 0 4 0 0 60 73 81 193 200 203 220 221 221
41922+193 200 203 193 200 203 193 200 203 193 200 203 205 212 215 220 221 221
41923+220 221 221 220 221 221 220 221 221 137 136 137 43 57 68 6 6 6
41924+4 0 0 1 1 1 4 4 4 4 4 4 4 4 4 4 4 4
41925+4 4 5 4 4 5 3 2 2 1 1 2 2 5 5 13 20 25
41926+22 40 52 22 40 52 13 20 25 2 3 3 1 1 2 3 3 3
41927+4 5 7 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41928+1 1 1 0 0 0 2 3 3 41 54 63 131 129 131 166 165 166
41929+166 165 166 155 154 155 153 152 153 137 136 137 137 136 137 125 124 125
41930+125 124 125 137 136 137 137 136 137 125 124 125 37 38 37 4 3 3
41931+4 3 3 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
41932+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41933+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41934+4 4 4 4 4 4
41935+4 3 3 6 6 6 6 6 6 13 16 17 60 73 81 167 166 167
41936+220 221 221 220 221 221 220 221 221 193 200 203 193 200 203 193 200 203
41937+205 212 215 220 221 221 220 221 221 244 246 246 205 212 215 125 124 125
41938+24 26 27 0 0 0 0 0 0 2 2 2 5 5 5 5 5 5
41939+4 4 4 4 4 4 4 4 4 4 4 5 1 1 2 4 5 7
41940+4 5 7 4 5 7 1 1 2 3 2 2 4 4 5 4 4 4
41941+4 4 4 4 4 4 5 5 5 4 4 4 0 0 0 0 0 0
41942+2 0 0 26 28 28 125 124 125 174 174 174 174 174 174 166 165 166
41943+156 155 156 153 152 153 137 136 137 137 136 137 131 129 131 137 136 137
41944+137 136 137 137 136 137 60 74 84 30 32 34 4 0 0 4 0 0
41945+5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41946+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41947+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41948+4 4 4 4 4 4
41949+5 5 5 6 6 6 4 0 0 4 0 0 6 6 6 26 28 28
41950+125 124 125 174 174 174 220 221 221 220 221 221 220 221 221 193 200 203
41951+205 212 215 220 221 221 205 212 215 220 221 221 220 221 221 244 246 246
41952+193 200 203 60 74 84 13 16 17 4 0 0 0 0 0 3 3 3
41953+5 5 5 5 5 5 4 4 4 4 4 4 4 4 5 3 3 3
41954+1 1 2 3 3 3 4 4 5 4 4 5 4 4 4 4 4 4
41955+5 5 5 5 5 5 2 2 2 0 0 0 0 0 0 13 16 17
41956+60 74 84 174 174 174 193 200 203 174 174 174 167 166 167 163 162 163
41957+153 152 153 153 152 153 137 136 137 137 136 137 153 152 153 137 136 137
41958+125 124 125 41 54 63 24 26 27 4 0 0 4 0 0 5 5 5
41959+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41960+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41961+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41962+4 4 4 4 4 4
41963+4 3 3 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6
41964+6 6 6 37 38 37 131 129 131 220 221 221 220 221 221 220 221 221
41965+193 200 203 193 200 203 220 221 221 205 212 215 220 221 221 244 246 246
41966+244 246 246 244 246 246 174 174 174 41 54 63 0 0 0 0 0 0
41967+0 0 0 4 4 4 5 5 5 5 5 5 4 4 4 4 4 5
41968+4 4 5 4 4 5 4 4 4 4 4 4 6 6 6 6 6 6
41969+3 3 3 0 0 0 2 0 0 13 16 17 60 73 81 156 155 156
41970+220 221 221 193 200 203 174 174 174 165 164 165 163 162 163 154 153 154
41971+153 152 153 153 152 153 158 157 158 163 162 163 137 136 137 60 73 81
41972+13 16 17 4 0 0 4 0 0 4 3 3 4 4 4 4 4 4
41973+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41974+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41975+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41976+4 4 4 4 4 4
41977+5 5 5 4 3 3 4 3 3 6 6 6 6 6 6 6 6 6
41978+6 6 6 6 6 6 6 6 6 37 38 37 167 166 167 244 246 246
41979+244 246 246 220 221 221 205 212 215 205 212 215 220 221 221 193 200 203
41980+220 221 221 244 246 246 244 246 246 244 246 246 137 136 137 37 38 37
41981+3 2 2 0 0 0 1 1 1 5 5 5 5 5 5 4 4 4
41982+4 4 4 4 4 4 4 4 4 5 5 5 4 4 4 1 1 1
41983+0 0 0 5 5 5 43 57 68 153 152 153 193 200 203 220 221 221
41984+177 184 187 174 174 174 167 166 167 166 165 166 158 157 158 157 156 157
41985+158 157 158 166 165 166 156 155 156 85 115 134 13 16 17 4 0 0
41986+4 0 0 4 0 0 5 5 5 5 5 5 4 4 4 4 4 4
41987+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41988+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41989+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41990+4 4 4 4 4 4
41991+5 5 5 4 3 3 6 6 6 6 6 6 4 0 0 6 6 6
41992+6 6 6 6 6 6 6 6 6 6 6 6 13 16 17 60 73 81
41993+177 184 187 220 221 221 220 221 221 220 221 221 205 212 215 220 221 221
41994+220 221 221 205 212 215 220 221 221 244 246 246 244 246 246 205 212 215
41995+125 124 125 30 32 34 0 0 0 0 0 0 2 2 2 5 5 5
41996+4 4 4 4 4 4 4 4 4 1 1 1 0 0 0 1 0 0
41997+37 38 37 131 129 131 205 212 215 220 221 221 193 200 203 174 174 174
41998+174 174 174 174 174 174 167 166 167 165 164 165 166 165 166 167 166 167
41999+158 157 158 125 124 125 37 38 37 4 0 0 4 0 0 4 0 0
42000+4 3 3 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
42001+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42002+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42003+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42004+4 4 4 4 4 4
42005+4 4 4 5 5 5 4 3 3 4 3 3 6 6 6 6 6 6
42006+4 0 0 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6
42007+26 28 28 125 124 125 205 212 215 220 221 221 220 221 221 220 221 221
42008+205 212 215 220 221 221 205 212 215 220 221 221 220 221 221 244 246 246
42009+244 246 246 190 197 201 60 74 84 16 19 21 4 0 0 0 0 0
42010+0 0 0 0 0 0 0 0 0 0 0 0 16 19 21 120 125 127
42011+177 184 187 220 221 221 205 212 215 177 184 187 174 174 174 177 184 187
42012+174 174 174 174 174 174 167 166 167 174 174 174 166 165 166 137 136 137
42013+60 73 81 13 16 17 4 0 0 4 0 0 4 3 3 6 6 6
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 4 4 4 4 4 4 4 4 4 4 4 4
42016+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42017+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42018+4 4 4 4 4 4
42019+5 5 5 4 3 3 5 5 5 4 3 3 6 6 6 4 0 0
42020+6 6 6 6 6 6 4 0 0 6 6 6 4 0 0 6 6 6
42021+6 6 6 6 6 6 37 38 37 137 136 137 193 200 203 220 221 221
42022+220 221 221 205 212 215 220 221 221 205 212 215 205 212 215 220 221 221
42023+220 221 221 220 221 221 244 246 246 166 165 166 43 57 68 2 2 2
42024+0 0 0 4 0 0 16 19 21 60 73 81 157 156 157 202 210 214
42025+220 221 221 193 200 203 177 184 187 177 184 187 177 184 187 174 174 174
42026+174 174 174 174 174 174 174 174 174 157 156 157 60 74 84 24 26 27
42027+4 0 0 4 0 0 4 0 0 6 6 6 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 4 4 4 4 4 4 4 4 4 4 4 4
42030+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42031+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42032+4 4 4 4 4 4
42033+4 4 4 4 4 4 5 5 5 4 3 3 5 5 5 6 6 6
42034+6 6 6 4 0 0 6 6 6 6 6 6 6 6 6 4 0 0
42035+4 0 0 4 0 0 6 6 6 24 26 27 60 73 81 167 166 167
42036+220 221 221 220 221 221 220 221 221 205 212 215 205 212 215 205 212 215
42037+205 212 215 220 221 221 220 221 221 220 221 221 205 212 215 137 136 137
42038+60 74 84 125 124 125 137 136 137 190 197 201 220 221 221 193 200 203
42039+177 184 187 177 184 187 177 184 187 174 174 174 174 174 174 177 184 187
42040+190 197 201 174 174 174 125 124 125 37 38 37 6 6 6 4 0 0
42041+4 0 0 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 4 4 4 4 4 4 4 4 4 4 4 4
42044+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42045+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42046+4 4 4 4 4 4
42047+4 4 4 4 4 4 5 5 5 5 5 5 4 3 3 6 6 6
42048+4 0 0 6 6 6 6 6 6 6 6 6 4 0 0 6 6 6
42049+6 6 6 6 6 6 4 0 0 4 0 0 6 6 6 6 6 6
42050+125 124 125 193 200 203 244 246 246 220 221 221 205 212 215 205 212 215
42051+205 212 215 193 200 203 205 212 215 205 212 215 220 221 221 220 221 221
42052+193 200 203 193 200 203 205 212 215 193 200 203 193 200 203 177 184 187
42053+190 197 201 190 197 201 174 174 174 190 197 201 193 200 203 190 197 201
42054+153 152 153 60 73 81 4 0 0 4 0 0 4 0 0 3 2 2
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 4 4 4 4 4 4 4 4 4 4 4 4
42058+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42059+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42060+4 4 4 4 4 4
42061+4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 4 3 3
42062+6 6 6 4 3 3 4 3 3 4 3 3 6 6 6 6 6 6
42063+4 0 0 6 6 6 6 6 6 6 6 6 4 0 0 4 0 0
42064+4 0 0 26 28 28 131 129 131 220 221 221 244 246 246 220 221 221
42065+205 212 215 193 200 203 205 212 215 193 200 203 193 200 203 205 212 215
42066+220 221 221 193 200 203 193 200 203 193 200 203 190 197 201 174 174 174
42067+174 174 174 190 197 201 193 200 203 193 200 203 167 166 167 125 124 125
42068+6 6 6 4 0 0 4 0 0 4 3 3 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 4 4 4 4 4 4 4 4 4 4 4 4
42072+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42073+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42074+4 4 4 4 4 4
42075+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
42076+5 5 5 4 3 3 5 5 5 6 6 6 4 3 3 5 5 5
42077+6 6 6 6 6 6 4 0 0 6 6 6 6 6 6 6 6 6
42078+4 0 0 4 0 0 6 6 6 41 54 63 158 157 158 220 221 221
42079+220 221 221 220 221 221 193 200 203 193 200 203 193 200 203 190 197 201
42080+190 197 201 190 197 201 190 197 201 190 197 201 174 174 174 193 200 203
42081+193 200 203 220 221 221 174 174 174 125 124 125 37 38 37 4 0 0
42082+4 0 0 4 3 3 6 6 6 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 4 4 4 4 4 4 4 4 4 4 4 4
42086+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42087+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42088+4 4 4 4 4 4
42089+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42090+4 4 4 5 5 5 4 3 3 4 3 3 4 3 3 5 5 5
42091+4 3 3 6 6 6 5 5 5 4 3 3 6 6 6 6 6 6
42092+6 6 6 6 6 6 4 0 0 4 0 0 13 16 17 60 73 81
42093+174 174 174 220 221 221 220 221 221 205 212 215 190 197 201 174 174 174
42094+193 200 203 174 174 174 190 197 201 174 174 174 193 200 203 220 221 221
42095+193 200 203 131 129 131 37 38 37 6 6 6 4 0 0 4 0 0
42096+6 6 6 6 6 6 4 3 3 5 5 5 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 4 4 4 4 4 4 4 4 4 4 4 4
42100+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42101+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42102+4 4 4 4 4 4
42103+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42104+4 4 4 4 4 4 4 4 4 5 5 5 5 5 5 5 5 5
42105+5 5 5 4 3 3 4 3 3 5 5 5 4 3 3 4 3 3
42106+5 5 5 6 6 6 6 6 6 4 0 0 6 6 6 6 6 6
42107+6 6 6 125 124 125 174 174 174 220 221 221 220 221 221 193 200 203
42108+193 200 203 193 200 203 193 200 203 193 200 203 220 221 221 158 157 158
42109+60 73 81 6 6 6 4 0 0 4 0 0 5 5 5 6 6 6
42110+5 5 5 5 5 5 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 4 4 4 4 4 4 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 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42116+4 4 4 4 4 4
42117+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42118+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42119+4 4 4 5 5 5 5 5 5 4 3 3 5 5 5 4 3 3
42120+5 5 5 5 5 5 6 6 6 6 6 6 4 0 0 4 0 0
42121+4 0 0 4 0 0 26 28 28 125 124 125 174 174 174 193 200 203
42122+193 200 203 174 174 174 193 200 203 167 166 167 125 124 125 6 6 6
42123+6 6 6 6 6 6 4 0 0 6 6 6 6 6 6 5 5 5
42124+4 3 3 5 5 5 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 4 4 4 4 4 4 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 4 4 4 4 4 4 4 4 4
42130+4 4 4 4 4 4
42131+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42132+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42133+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
42134+4 3 3 6 6 6 4 0 0 6 6 6 6 6 6 6 6 6
42135+6 6 6 4 0 0 4 0 0 6 6 6 37 38 37 125 124 125
42136+153 152 153 131 129 131 125 124 125 37 38 37 6 6 6 6 6 6
42137+6 6 6 4 0 0 6 6 6 6 6 6 4 3 3 5 5 5
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 4 4 4 4 4 4 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 4 4 4
42145+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42146+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42147+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42148+4 4 4 5 5 5 5 5 5 4 3 3 5 5 5 4 3 3
42149+6 6 6 6 6 6 4 0 0 4 0 0 6 6 6 6 6 6
42150+24 26 27 24 26 27 6 6 6 6 6 6 6 6 6 4 0 0
42151+6 6 6 6 6 6 4 0 0 6 6 6 5 5 5 4 3 3
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 4 4 4 4 4 4 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
42159+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42160+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42161+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42162+4 4 4 4 4 4 5 5 5 4 3 3 5 5 5 6 6 6
42163+4 0 0 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6
42164+6 6 6 6 6 6 6 6 6 4 0 0 6 6 6 6 6 6
42165+4 0 0 6 6 6 6 6 6 4 3 3 5 5 5 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 4 4 4 4 4 4 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
42173+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42174+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42175+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42176+4 4 4 4 4 4 4 4 4 5 5 5 4 3 3 5 5 5
42177+5 5 5 5 5 5 4 0 0 6 6 6 4 0 0 6 6 6
42178+6 6 6 6 6 6 6 6 6 4 0 0 6 6 6 4 0 0
42179+6 6 6 4 3 3 5 5 5 4 3 3 5 5 5 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 4 4 4 4 4 4 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
42187+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42188+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42189+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42190+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
42191+4 3 3 6 6 6 4 3 3 6 6 6 6 6 6 6 6 6
42192+4 0 0 6 6 6 4 0 0 6 6 6 6 6 6 6 6 6
42193+6 6 6 4 3 3 5 5 5 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 4 4 4 4 4 4 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
42201+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42202+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42203+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42204+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42205+4 4 4 5 5 5 4 3 3 5 5 5 4 0 0 6 6 6
42206+6 6 6 4 0 0 6 6 6 6 6 6 4 0 0 6 6 6
42207+4 3 3 5 5 5 5 5 5 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 4 4 4 4 4 4 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
42215+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42216+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42217+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42218+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42219+4 4 4 5 5 5 4 3 3 5 5 5 6 6 6 4 3 3
42220+4 3 3 6 6 6 6 6 6 4 3 3 6 6 6 4 3 3
42221+5 5 5 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 4 4 4 4 4 4 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
42229+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42230+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42231+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42232+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42233+4 4 4 4 4 4 4 4 4 5 5 5 4 3 3 6 6 6
42234+5 5 5 4 3 3 4 3 3 4 3 3 5 5 5 5 5 5
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 4 4 4 4 4 4 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
42243+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42244+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42245+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42246+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42247+4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 4 3 3
42248+5 5 5 4 3 3 5 5 5 5 5 5 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 4 4 4 4 4 4 4 4 4 4 4 4
42254+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 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
42257diff --git a/drivers/video/udlfb.c b/drivers/video/udlfb.c
42258index 38fcfff..0072dcd 100644
42259--- a/drivers/video/udlfb.c
42260+++ b/drivers/video/udlfb.c
42261@@ -620,11 +620,11 @@ int dlfb_handle_damage(struct dlfb_data *dev, int x, int y,
42262 dlfb_urb_completion(urb);
42263
42264 error:
42265- atomic_add(bytes_sent, &dev->bytes_sent);
42266- atomic_add(bytes_identical, &dev->bytes_identical);
42267- atomic_add(width*height*2, &dev->bytes_rendered);
42268+ atomic_add_unchecked(bytes_sent, &dev->bytes_sent);
42269+ atomic_add_unchecked(bytes_identical, &dev->bytes_identical);
42270+ atomic_add_unchecked(width*height*2, &dev->bytes_rendered);
42271 end_cycles = get_cycles();
42272- atomic_add(((unsigned int) ((end_cycles - start_cycles)
42273+ atomic_add_unchecked(((unsigned int) ((end_cycles - start_cycles)
42274 >> 10)), /* Kcycles */
42275 &dev->cpu_kcycles_used);
42276
42277@@ -745,11 +745,11 @@ static void dlfb_dpy_deferred_io(struct fb_info *info,
42278 dlfb_urb_completion(urb);
42279
42280 error:
42281- atomic_add(bytes_sent, &dev->bytes_sent);
42282- atomic_add(bytes_identical, &dev->bytes_identical);
42283- atomic_add(bytes_rendered, &dev->bytes_rendered);
42284+ atomic_add_unchecked(bytes_sent, &dev->bytes_sent);
42285+ atomic_add_unchecked(bytes_identical, &dev->bytes_identical);
42286+ atomic_add_unchecked(bytes_rendered, &dev->bytes_rendered);
42287 end_cycles = get_cycles();
42288- atomic_add(((unsigned int) ((end_cycles - start_cycles)
42289+ atomic_add_unchecked(((unsigned int) ((end_cycles - start_cycles)
42290 >> 10)), /* Kcycles */
42291 &dev->cpu_kcycles_used);
42292 }
42293@@ -1373,7 +1373,7 @@ static ssize_t metrics_bytes_rendered_show(struct device *fbdev,
42294 struct fb_info *fb_info = dev_get_drvdata(fbdev);
42295 struct dlfb_data *dev = fb_info->par;
42296 return snprintf(buf, PAGE_SIZE, "%u\n",
42297- atomic_read(&dev->bytes_rendered));
42298+ atomic_read_unchecked(&dev->bytes_rendered));
42299 }
42300
42301 static ssize_t metrics_bytes_identical_show(struct device *fbdev,
42302@@ -1381,7 +1381,7 @@ static ssize_t metrics_bytes_identical_show(struct device *fbdev,
42303 struct fb_info *fb_info = dev_get_drvdata(fbdev);
42304 struct dlfb_data *dev = fb_info->par;
42305 return snprintf(buf, PAGE_SIZE, "%u\n",
42306- atomic_read(&dev->bytes_identical));
42307+ atomic_read_unchecked(&dev->bytes_identical));
42308 }
42309
42310 static ssize_t metrics_bytes_sent_show(struct device *fbdev,
42311@@ -1389,7 +1389,7 @@ static ssize_t metrics_bytes_sent_show(struct device *fbdev,
42312 struct fb_info *fb_info = dev_get_drvdata(fbdev);
42313 struct dlfb_data *dev = fb_info->par;
42314 return snprintf(buf, PAGE_SIZE, "%u\n",
42315- atomic_read(&dev->bytes_sent));
42316+ atomic_read_unchecked(&dev->bytes_sent));
42317 }
42318
42319 static ssize_t metrics_cpu_kcycles_used_show(struct device *fbdev,
42320@@ -1397,7 +1397,7 @@ static ssize_t metrics_cpu_kcycles_used_show(struct device *fbdev,
42321 struct fb_info *fb_info = dev_get_drvdata(fbdev);
42322 struct dlfb_data *dev = fb_info->par;
42323 return snprintf(buf, PAGE_SIZE, "%u\n",
42324- atomic_read(&dev->cpu_kcycles_used));
42325+ atomic_read_unchecked(&dev->cpu_kcycles_used));
42326 }
42327
42328 static ssize_t edid_show(
42329@@ -1457,10 +1457,10 @@ static ssize_t metrics_reset_store(struct device *fbdev,
42330 struct fb_info *fb_info = dev_get_drvdata(fbdev);
42331 struct dlfb_data *dev = fb_info->par;
42332
42333- atomic_set(&dev->bytes_rendered, 0);
42334- atomic_set(&dev->bytes_identical, 0);
42335- atomic_set(&dev->bytes_sent, 0);
42336- atomic_set(&dev->cpu_kcycles_used, 0);
42337+ atomic_set_unchecked(&dev->bytes_rendered, 0);
42338+ atomic_set_unchecked(&dev->bytes_identical, 0);
42339+ atomic_set_unchecked(&dev->bytes_sent, 0);
42340+ atomic_set_unchecked(&dev->cpu_kcycles_used, 0);
42341
42342 return count;
42343 }
42344diff --git a/drivers/video/uvesafb.c b/drivers/video/uvesafb.c
42345index b0e2a42..e2df3ad 100644
42346--- a/drivers/video/uvesafb.c
42347+++ b/drivers/video/uvesafb.c
42348@@ -19,6 +19,7 @@
42349 #include <linux/io.h>
42350 #include <linux/mutex.h>
42351 #include <linux/slab.h>
42352+#include <linux/moduleloader.h>
42353 #include <video/edid.h>
42354 #include <video/uvesafb.h>
42355 #ifdef CONFIG_X86
42356@@ -569,10 +570,32 @@ static int __devinit uvesafb_vbe_getpmi(struct uvesafb_ktask *task,
42357 if ((task->t.regs.eax & 0xffff) != 0x4f || task->t.regs.es < 0xc000) {
42358 par->pmi_setpal = par->ypan = 0;
42359 } else {
42360+
42361+#ifdef CONFIG_PAX_KERNEXEC
42362+#ifdef CONFIG_MODULES
42363+ par->pmi_code = module_alloc_exec((u16)task->t.regs.ecx);
42364+#endif
42365+ if (!par->pmi_code) {
42366+ par->pmi_setpal = par->ypan = 0;
42367+ return 0;
42368+ }
42369+#endif
42370+
42371 par->pmi_base = (u16 *)phys_to_virt(((u32)task->t.regs.es << 4)
42372 + task->t.regs.edi);
42373+
42374+#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
42375+ pax_open_kernel();
42376+ memcpy(par->pmi_code, par->pmi_base, (u16)task->t.regs.ecx);
42377+ pax_close_kernel();
42378+
42379+ par->pmi_start = ktva_ktla(par->pmi_code + par->pmi_base[1]);
42380+ par->pmi_pal = ktva_ktla(par->pmi_code + par->pmi_base[2]);
42381+#else
42382 par->pmi_start = (u8 *)par->pmi_base + par->pmi_base[1];
42383 par->pmi_pal = (u8 *)par->pmi_base + par->pmi_base[2];
42384+#endif
42385+
42386 printk(KERN_INFO "uvesafb: protected mode interface info at "
42387 "%04x:%04x\n",
42388 (u16)task->t.regs.es, (u16)task->t.regs.edi);
42389@@ -816,13 +839,14 @@ static int __devinit uvesafb_vbe_init(struct fb_info *info)
42390 par->ypan = ypan;
42391
42392 if (par->pmi_setpal || par->ypan) {
42393+#if !defined(CONFIG_MODULES) || !defined(CONFIG_PAX_KERNEXEC)
42394 if (__supported_pte_mask & _PAGE_NX) {
42395 par->pmi_setpal = par->ypan = 0;
42396 printk(KERN_WARNING "uvesafb: NX protection is actively."
42397 "We have better not to use the PMI.\n");
42398- } else {
42399+ } else
42400+#endif
42401 uvesafb_vbe_getpmi(task, par);
42402- }
42403 }
42404 #else
42405 /* The protected mode interface is not available on non-x86. */
42406@@ -1836,6 +1860,11 @@ out:
42407 if (par->vbe_modes)
42408 kfree(par->vbe_modes);
42409
42410+#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
42411+ if (par->pmi_code)
42412+ module_free_exec(NULL, par->pmi_code);
42413+#endif
42414+
42415 framebuffer_release(info);
42416 return err;
42417 }
42418@@ -1862,6 +1891,12 @@ static int uvesafb_remove(struct platform_device *dev)
42419 kfree(par->vbe_state_orig);
42420 if (par->vbe_state_saved)
42421 kfree(par->vbe_state_saved);
42422+
42423+#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
42424+ if (par->pmi_code)
42425+ module_free_exec(NULL, par->pmi_code);
42426+#endif
42427+
42428 }
42429
42430 framebuffer_release(info);
42431diff --git a/drivers/video/vesafb.c b/drivers/video/vesafb.c
42432index 501b340..86bd4cf 100644
42433--- a/drivers/video/vesafb.c
42434+++ b/drivers/video/vesafb.c
42435@@ -9,6 +9,7 @@
42436 */
42437
42438 #include <linux/module.h>
42439+#include <linux/moduleloader.h>
42440 #include <linux/kernel.h>
42441 #include <linux/errno.h>
42442 #include <linux/string.h>
42443@@ -52,8 +53,8 @@ static int vram_remap __initdata; /* Set amount of memory to be used */
42444 static int vram_total __initdata; /* Set total amount of memory */
42445 static int pmi_setpal __read_mostly = 1; /* pmi for palette changes ??? */
42446 static int ypan __read_mostly; /* 0..nothing, 1..ypan, 2..ywrap */
42447-static void (*pmi_start)(void) __read_mostly;
42448-static void (*pmi_pal) (void) __read_mostly;
42449+static void (*pmi_start)(void) __read_only;
42450+static void (*pmi_pal) (void) __read_only;
42451 static int depth __read_mostly;
42452 static int vga_compat __read_mostly;
42453 /* --------------------------------------------------------------------- */
42454@@ -233,6 +234,7 @@ static int __init vesafb_probe(struct platform_device *dev)
42455 unsigned int size_vmode;
42456 unsigned int size_remap;
42457 unsigned int size_total;
42458+ void *pmi_code = NULL;
42459
42460 if (screen_info.orig_video_isVGA != VIDEO_TYPE_VLFB)
42461 return -ENODEV;
42462@@ -275,10 +277,6 @@ static int __init vesafb_probe(struct platform_device *dev)
42463 size_remap = size_total;
42464 vesafb_fix.smem_len = size_remap;
42465
42466-#ifndef __i386__
42467- screen_info.vesapm_seg = 0;
42468-#endif
42469-
42470 if (!request_mem_region(vesafb_fix.smem_start, size_total, "vesafb")) {
42471 printk(KERN_WARNING
42472 "vesafb: cannot reserve video memory at 0x%lx\n",
42473@@ -307,9 +305,21 @@ static int __init vesafb_probe(struct platform_device *dev)
42474 printk(KERN_INFO "vesafb: mode is %dx%dx%d, linelength=%d, pages=%d\n",
42475 vesafb_defined.xres, vesafb_defined.yres, vesafb_defined.bits_per_pixel, vesafb_fix.line_length, screen_info.pages);
42476
42477+#ifdef __i386__
42478+
42479+#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
42480+ pmi_code = module_alloc_exec(screen_info.vesapm_size);
42481+ if (!pmi_code)
42482+#elif !defined(CONFIG_PAX_KERNEXEC)
42483+ if (0)
42484+#endif
42485+
42486+#endif
42487+ screen_info.vesapm_seg = 0;
42488+
42489 if (screen_info.vesapm_seg) {
42490- printk(KERN_INFO "vesafb: protected mode interface info at %04x:%04x\n",
42491- screen_info.vesapm_seg,screen_info.vesapm_off);
42492+ printk(KERN_INFO "vesafb: protected mode interface info at %04x:%04x %04x bytes\n",
42493+ screen_info.vesapm_seg,screen_info.vesapm_off,screen_info.vesapm_size);
42494 }
42495
42496 if (screen_info.vesapm_seg < 0xc000)
42497@@ -317,9 +327,25 @@ static int __init vesafb_probe(struct platform_device *dev)
42498
42499 if (ypan || pmi_setpal) {
42500 unsigned short *pmi_base;
42501+
42502 pmi_base = (unsigned short*)phys_to_virt(((unsigned long)screen_info.vesapm_seg << 4) + screen_info.vesapm_off);
42503- pmi_start = (void*)((char*)pmi_base + pmi_base[1]);
42504- pmi_pal = (void*)((char*)pmi_base + pmi_base[2]);
42505+
42506+#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
42507+ pax_open_kernel();
42508+ memcpy(pmi_code, pmi_base, screen_info.vesapm_size);
42509+#else
42510+ pmi_code = pmi_base;
42511+#endif
42512+
42513+ pmi_start = (void*)((char*)pmi_code + pmi_base[1]);
42514+ pmi_pal = (void*)((char*)pmi_code + pmi_base[2]);
42515+
42516+#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
42517+ pmi_start = ktva_ktla(pmi_start);
42518+ pmi_pal = ktva_ktla(pmi_pal);
42519+ pax_close_kernel();
42520+#endif
42521+
42522 printk(KERN_INFO "vesafb: pmi: set display start = %p, set palette = %p\n",pmi_start,pmi_pal);
42523 if (pmi_base[3]) {
42524 printk(KERN_INFO "vesafb: pmi: ports = ");
42525@@ -488,6 +514,11 @@ static int __init vesafb_probe(struct platform_device *dev)
42526 info->node, info->fix.id);
42527 return 0;
42528 err:
42529+
42530+#if defined(__i386__) && defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
42531+ module_free_exec(NULL, pmi_code);
42532+#endif
42533+
42534 if (info->screen_base)
42535 iounmap(info->screen_base);
42536 framebuffer_release(info);
42537diff --git a/drivers/video/via/via_clock.h b/drivers/video/via/via_clock.h
42538index 88714ae..16c2e11 100644
42539--- a/drivers/video/via/via_clock.h
42540+++ b/drivers/video/via/via_clock.h
42541@@ -56,7 +56,7 @@ struct via_clock {
42542
42543 void (*set_engine_pll_state)(u8 state);
42544 void (*set_engine_pll)(struct via_pll_config config);
42545-};
42546+} __no_const;
42547
42548
42549 static inline u32 get_pll_internal_frequency(u32 ref_freq,
42550diff --git a/drivers/virtio/virtio_mmio.c b/drivers/virtio/virtio_mmio.c
42551index 453db0c..604973e 100644
42552--- a/drivers/virtio/virtio_mmio.c
42553+++ b/drivers/virtio/virtio_mmio.c
42554@@ -521,7 +521,7 @@ static int vm_cmdline_set(const char *device,
42555
42556 resources[0].end = memparse(device, &str) - 1;
42557
42558- processed = sscanf(str, "@%lli:%u%n:%d%n",
42559+ processed = sscanf(str, "@%lli:%llu%n:%d%n",
42560 &base, &resources[1].start, &consumed,
42561 &vm_cmdline_id, &consumed);
42562
42563diff --git a/drivers/xen/xen-pciback/conf_space.h b/drivers/xen/xen-pciback/conf_space.h
42564index e56c934..fc22f4b 100644
42565--- a/drivers/xen/xen-pciback/conf_space.h
42566+++ b/drivers/xen/xen-pciback/conf_space.h
42567@@ -44,15 +44,15 @@ struct config_field {
42568 struct {
42569 conf_dword_write write;
42570 conf_dword_read read;
42571- } dw;
42572+ } __no_const dw;
42573 struct {
42574 conf_word_write write;
42575 conf_word_read read;
42576- } w;
42577+ } __no_const w;
42578 struct {
42579 conf_byte_write write;
42580 conf_byte_read read;
42581- } b;
42582+ } __no_const b;
42583 } u;
42584 struct list_head list;
42585 };
42586diff --git a/fs/9p/vfs_inode.c b/fs/9p/vfs_inode.c
42587index cbf9dbb..35c3af7 100644
42588--- a/fs/9p/vfs_inode.c
42589+++ b/fs/9p/vfs_inode.c
42590@@ -1329,7 +1329,7 @@ static void *v9fs_vfs_follow_link(struct dentry *dentry, struct nameidata *nd)
42591 void
42592 v9fs_vfs_put_link(struct dentry *dentry, struct nameidata *nd, void *p)
42593 {
42594- char *s = nd_get_link(nd);
42595+ const char *s = nd_get_link(nd);
42596
42597 p9_debug(P9_DEBUG_VFS, " %s %s\n",
42598 dentry->d_name.name, IS_ERR(s) ? "<error>" : s);
42599diff --git a/fs/Kconfig.binfmt b/fs/Kconfig.binfmt
42600index 0225742..1cd4732 100644
42601--- a/fs/Kconfig.binfmt
42602+++ b/fs/Kconfig.binfmt
42603@@ -89,7 +89,7 @@ config HAVE_AOUT
42604
42605 config BINFMT_AOUT
42606 tristate "Kernel support for a.out and ECOFF binaries"
42607- depends on HAVE_AOUT
42608+ depends on HAVE_AOUT && BROKEN
42609 ---help---
42610 A.out (Assembler.OUTput) is a set of formats for libraries and
42611 executables used in the earliest versions of UNIX. Linux used
42612diff --git a/fs/aio.c b/fs/aio.c
42613index 71f613c..9d01f1f 100644
42614--- a/fs/aio.c
42615+++ b/fs/aio.c
42616@@ -111,7 +111,7 @@ static int aio_setup_ring(struct kioctx *ctx)
42617 size += sizeof(struct io_event) * nr_events;
42618 nr_pages = (size + PAGE_SIZE-1) >> PAGE_SHIFT;
42619
42620- if (nr_pages < 0)
42621+ if (nr_pages <= 0)
42622 return -EINVAL;
42623
42624 nr_events = (PAGE_SIZE * nr_pages - sizeof(struct aio_ring)) / sizeof(struct io_event);
42625@@ -1373,18 +1373,19 @@ static ssize_t aio_fsync(struct kiocb *iocb)
42626 static ssize_t aio_setup_vectored_rw(int type, struct kiocb *kiocb, bool compat)
42627 {
42628 ssize_t ret;
42629+ struct iovec iovstack;
42630
42631 #ifdef CONFIG_COMPAT
42632 if (compat)
42633 ret = compat_rw_copy_check_uvector(type,
42634 (struct compat_iovec __user *)kiocb->ki_buf,
42635- kiocb->ki_nbytes, 1, &kiocb->ki_inline_vec,
42636+ kiocb->ki_nbytes, 1, &iovstack,
42637 &kiocb->ki_iovec);
42638 else
42639 #endif
42640 ret = rw_copy_check_uvector(type,
42641 (struct iovec __user *)kiocb->ki_buf,
42642- kiocb->ki_nbytes, 1, &kiocb->ki_inline_vec,
42643+ kiocb->ki_nbytes, 1, &iovstack,
42644 &kiocb->ki_iovec);
42645 if (ret < 0)
42646 goto out;
42647@@ -1393,6 +1394,10 @@ static ssize_t aio_setup_vectored_rw(int type, struct kiocb *kiocb, bool compat)
42648 if (ret < 0)
42649 goto out;
42650
42651+ if (kiocb->ki_iovec == &iovstack) {
42652+ kiocb->ki_inline_vec = iovstack;
42653+ kiocb->ki_iovec = &kiocb->ki_inline_vec;
42654+ }
42655 kiocb->ki_nr_segs = kiocb->ki_nbytes;
42656 kiocb->ki_cur_seg = 0;
42657 /* ki_nbytes/left now reflect bytes instead of segs */
42658diff --git a/fs/attr.c b/fs/attr.c
42659index 29e38a1..2bc037b 100644
42660--- a/fs/attr.c
42661+++ b/fs/attr.c
42662@@ -99,6 +99,7 @@ int inode_newsize_ok(const struct inode *inode, loff_t offset)
42663 unsigned long limit;
42664
42665 limit = rlimit(RLIMIT_FSIZE);
42666+ gr_learn_resource(current, RLIMIT_FSIZE, (unsigned long)offset, 1);
42667 if (limit != RLIM_INFINITY && offset > limit)
42668 goto out_sig;
42669 if (offset > inode->i_sb->s_maxbytes)
42670diff --git a/fs/autofs4/waitq.c b/fs/autofs4/waitq.c
42671index da8876d..4456166 100644
42672--- a/fs/autofs4/waitq.c
42673+++ b/fs/autofs4/waitq.c
42674@@ -61,7 +61,7 @@ static int autofs4_write(struct autofs_sb_info *sbi,
42675 {
42676 unsigned long sigpipe, flags;
42677 mm_segment_t fs;
42678- const char *data = (const char *)addr;
42679+ const char __user *data = (const char __force_user *)addr;
42680 ssize_t wr = 0;
42681
42682 sigpipe = sigismember(&current->pending.signal, SIGPIPE);
42683@@ -348,6 +348,10 @@ static int validate_request(struct autofs_wait_queue **wait,
42684 return 1;
42685 }
42686
42687+#ifdef CONFIG_GRKERNSEC_HIDESYM
42688+static atomic_unchecked_t autofs_dummy_name_id = ATOMIC_INIT(0);
42689+#endif
42690+
42691 int autofs4_wait(struct autofs_sb_info *sbi, struct dentry *dentry,
42692 enum autofs_notify notify)
42693 {
42694@@ -381,7 +385,12 @@ int autofs4_wait(struct autofs_sb_info *sbi, struct dentry *dentry,
42695
42696 /* If this is a direct mount request create a dummy name */
42697 if (IS_ROOT(dentry) && autofs_type_trigger(sbi->type))
42698+#ifdef CONFIG_GRKERNSEC_HIDESYM
42699+ /* this name does get written to userland via autofs4_write() */
42700+ qstr.len = sprintf(name, "%08lx", atomic_inc_return_unchecked(&autofs_dummy_name_id));
42701+#else
42702 qstr.len = sprintf(name, "%p", dentry);
42703+#endif
42704 else {
42705 qstr.len = autofs4_getpath(sbi, dentry, &name);
42706 if (!qstr.len) {
42707diff --git a/fs/befs/linuxvfs.c b/fs/befs/linuxvfs.c
42708index cf7f3c6..f61080d 100644
42709--- a/fs/befs/linuxvfs.c
42710+++ b/fs/befs/linuxvfs.c
42711@@ -502,7 +502,7 @@ static void befs_put_link(struct dentry *dentry, struct nameidata *nd, void *p)
42712 {
42713 befs_inode_info *befs_ino = BEFS_I(dentry->d_inode);
42714 if (befs_ino->i_flags & BEFS_LONG_SYMLINK) {
42715- char *link = nd_get_link(nd);
42716+ const char *link = nd_get_link(nd);
42717 if (!IS_ERR(link))
42718 kfree(link);
42719 }
42720diff --git a/fs/binfmt_aout.c b/fs/binfmt_aout.c
42721index d146e18..12d1bd1 100644
42722--- a/fs/binfmt_aout.c
42723+++ b/fs/binfmt_aout.c
42724@@ -16,6 +16,7 @@
42725 #include <linux/string.h>
42726 #include <linux/fs.h>
42727 #include <linux/file.h>
42728+#include <linux/security.h>
42729 #include <linux/stat.h>
42730 #include <linux/fcntl.h>
42731 #include <linux/ptrace.h>
42732@@ -83,6 +84,8 @@ static int aout_core_dump(struct coredump_params *cprm)
42733 #endif
42734 # define START_STACK(u) ((void __user *)u.start_stack)
42735
42736+ memset(&dump, 0, sizeof(dump));
42737+
42738 fs = get_fs();
42739 set_fs(KERNEL_DS);
42740 has_dumped = 1;
42741@@ -94,10 +97,12 @@ static int aout_core_dump(struct coredump_params *cprm)
42742
42743 /* If the size of the dump file exceeds the rlimit, then see what would happen
42744 if we wrote the stack, but not the data area. */
42745+ gr_learn_resource(current, RLIMIT_CORE, (dump.u_dsize + dump.u_ssize+1) * PAGE_SIZE, 1);
42746 if ((dump.u_dsize + dump.u_ssize+1) * PAGE_SIZE > cprm->limit)
42747 dump.u_dsize = 0;
42748
42749 /* Make sure we have enough room to write the stack and data areas. */
42750+ gr_learn_resource(current, RLIMIT_CORE, (dump.u_ssize + 1) * PAGE_SIZE, 1);
42751 if ((dump.u_ssize + 1) * PAGE_SIZE > cprm->limit)
42752 dump.u_ssize = 0;
42753
42754@@ -231,6 +236,8 @@ static int load_aout_binary(struct linux_binprm * bprm, struct pt_regs * regs)
42755 rlim = rlimit(RLIMIT_DATA);
42756 if (rlim >= RLIM_INFINITY)
42757 rlim = ~0;
42758+
42759+ gr_learn_resource(current, RLIMIT_DATA, ex.a_data + ex.a_bss, 1);
42760 if (ex.a_data + ex.a_bss > rlim)
42761 return -ENOMEM;
42762
42763@@ -265,6 +272,27 @@ static int load_aout_binary(struct linux_binprm * bprm, struct pt_regs * regs)
42764
42765 install_exec_creds(bprm);
42766
42767+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
42768+ current->mm->pax_flags = 0UL;
42769+#endif
42770+
42771+#ifdef CONFIG_PAX_PAGEEXEC
42772+ if (!(N_FLAGS(ex) & F_PAX_PAGEEXEC)) {
42773+ current->mm->pax_flags |= MF_PAX_PAGEEXEC;
42774+
42775+#ifdef CONFIG_PAX_EMUTRAMP
42776+ if (N_FLAGS(ex) & F_PAX_EMUTRAMP)
42777+ current->mm->pax_flags |= MF_PAX_EMUTRAMP;
42778+#endif
42779+
42780+#ifdef CONFIG_PAX_MPROTECT
42781+ if (!(N_FLAGS(ex) & F_PAX_MPROTECT))
42782+ current->mm->pax_flags |= MF_PAX_MPROTECT;
42783+#endif
42784+
42785+ }
42786+#endif
42787+
42788 if (N_MAGIC(ex) == OMAGIC) {
42789 unsigned long text_addr, map_size;
42790 loff_t pos;
42791@@ -330,7 +358,7 @@ static int load_aout_binary(struct linux_binprm * bprm, struct pt_regs * regs)
42792 }
42793
42794 error = vm_mmap(bprm->file, N_DATADDR(ex), ex.a_data,
42795- PROT_READ | PROT_WRITE | PROT_EXEC,
42796+ PROT_READ | PROT_WRITE,
42797 MAP_FIXED | MAP_PRIVATE | MAP_DENYWRITE | MAP_EXECUTABLE,
42798 fd_offset + ex.a_text);
42799 if (error != N_DATADDR(ex)) {
42800diff --git a/fs/binfmt_elf.c b/fs/binfmt_elf.c
42801index 0225fdd..9f0ef53 100644
42802--- a/fs/binfmt_elf.c
42803+++ b/fs/binfmt_elf.c
42804@@ -32,6 +32,7 @@
42805 #include <linux/elf.h>
42806 #include <linux/utsname.h>
42807 #include <linux/coredump.h>
42808+#include <linux/xattr.h>
42809 #include <asm/uaccess.h>
42810 #include <asm/param.h>
42811 #include <asm/page.h>
42812@@ -52,6 +53,10 @@ static int elf_core_dump(struct coredump_params *cprm);
42813 #define elf_core_dump NULL
42814 #endif
42815
42816+#ifdef CONFIG_PAX_MPROTECT
42817+static void elf_handle_mprotect(struct vm_area_struct *vma, unsigned long newflags);
42818+#endif
42819+
42820 #if ELF_EXEC_PAGESIZE > PAGE_SIZE
42821 #define ELF_MIN_ALIGN ELF_EXEC_PAGESIZE
42822 #else
42823@@ -71,6 +76,11 @@ static struct linux_binfmt elf_format = {
42824 .load_binary = load_elf_binary,
42825 .load_shlib = load_elf_library,
42826 .core_dump = elf_core_dump,
42827+
42828+#ifdef CONFIG_PAX_MPROTECT
42829+ .handle_mprotect= elf_handle_mprotect,
42830+#endif
42831+
42832 .min_coredump = ELF_EXEC_PAGESIZE,
42833 };
42834
42835@@ -78,6 +88,8 @@ static struct linux_binfmt elf_format = {
42836
42837 static int set_brk(unsigned long start, unsigned long end)
42838 {
42839+ unsigned long e = end;
42840+
42841 start = ELF_PAGEALIGN(start);
42842 end = ELF_PAGEALIGN(end);
42843 if (end > start) {
42844@@ -86,7 +98,7 @@ static int set_brk(unsigned long start, unsigned long end)
42845 if (BAD_ADDR(addr))
42846 return addr;
42847 }
42848- current->mm->start_brk = current->mm->brk = end;
42849+ current->mm->start_brk = current->mm->brk = e;
42850 return 0;
42851 }
42852
42853@@ -147,12 +159,13 @@ create_elf_tables(struct linux_binprm *bprm, struct elfhdr *exec,
42854 elf_addr_t __user *u_rand_bytes;
42855 const char *k_platform = ELF_PLATFORM;
42856 const char *k_base_platform = ELF_BASE_PLATFORM;
42857- unsigned char k_rand_bytes[16];
42858+ u32 k_rand_bytes[4];
42859 int items;
42860 elf_addr_t *elf_info;
42861 int ei_index = 0;
42862 const struct cred *cred = current_cred();
42863 struct vm_area_struct *vma;
42864+ unsigned long saved_auxv[AT_VECTOR_SIZE];
42865
42866 /*
42867 * In some cases (e.g. Hyper-Threading), we want to avoid L1
42868@@ -194,8 +207,12 @@ create_elf_tables(struct linux_binprm *bprm, struct elfhdr *exec,
42869 * Generate 16 random bytes for userspace PRNG seeding.
42870 */
42871 get_random_bytes(k_rand_bytes, sizeof(k_rand_bytes));
42872- u_rand_bytes = (elf_addr_t __user *)
42873- STACK_ALLOC(p, sizeof(k_rand_bytes));
42874+ srandom32(k_rand_bytes[0] ^ random32());
42875+ srandom32(k_rand_bytes[1] ^ random32());
42876+ srandom32(k_rand_bytes[2] ^ random32());
42877+ srandom32(k_rand_bytes[3] ^ random32());
42878+ p = STACK_ROUND(p, sizeof(k_rand_bytes));
42879+ u_rand_bytes = (elf_addr_t __user *) p;
42880 if (__copy_to_user(u_rand_bytes, k_rand_bytes, sizeof(k_rand_bytes)))
42881 return -EFAULT;
42882
42883@@ -307,9 +324,11 @@ create_elf_tables(struct linux_binprm *bprm, struct elfhdr *exec,
42884 return -EFAULT;
42885 current->mm->env_end = p;
42886
42887+ memcpy(saved_auxv, elf_info, ei_index * sizeof(elf_addr_t));
42888+
42889 /* Put the elf_info on the stack in the right place. */
42890 sp = (elf_addr_t __user *)envp + 1;
42891- if (copy_to_user(sp, elf_info, ei_index * sizeof(elf_addr_t)))
42892+ if (copy_to_user(sp, saved_auxv, ei_index * sizeof(elf_addr_t)))
42893 return -EFAULT;
42894 return 0;
42895 }
42896@@ -378,10 +397,10 @@ static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
42897 {
42898 struct elf_phdr *elf_phdata;
42899 struct elf_phdr *eppnt;
42900- unsigned long load_addr = 0;
42901+ unsigned long load_addr = 0, pax_task_size = TASK_SIZE;
42902 int load_addr_set = 0;
42903 unsigned long last_bss = 0, elf_bss = 0;
42904- unsigned long error = ~0UL;
42905+ unsigned long error = -EINVAL;
42906 unsigned long total_size;
42907 int retval, i, size;
42908
42909@@ -427,6 +446,11 @@ static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
42910 goto out_close;
42911 }
42912
42913+#ifdef CONFIG_PAX_SEGMEXEC
42914+ if (current->mm->pax_flags & MF_PAX_SEGMEXEC)
42915+ pax_task_size = SEGMEXEC_TASK_SIZE;
42916+#endif
42917+
42918 eppnt = elf_phdata;
42919 for (i = 0; i < interp_elf_ex->e_phnum; i++, eppnt++) {
42920 if (eppnt->p_type == PT_LOAD) {
42921@@ -470,8 +494,8 @@ static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
42922 k = load_addr + eppnt->p_vaddr;
42923 if (BAD_ADDR(k) ||
42924 eppnt->p_filesz > eppnt->p_memsz ||
42925- eppnt->p_memsz > TASK_SIZE ||
42926- TASK_SIZE - eppnt->p_memsz < k) {
42927+ eppnt->p_memsz > pax_task_size ||
42928+ pax_task_size - eppnt->p_memsz < k) {
42929 error = -ENOMEM;
42930 goto out_close;
42931 }
42932@@ -523,6 +547,311 @@ out:
42933 return error;
42934 }
42935
42936+#ifdef CONFIG_PAX_PT_PAX_FLAGS
42937+#ifdef CONFIG_PAX_SOFTMODE
42938+static unsigned long pax_parse_pt_pax_softmode(const struct elf_phdr * const elf_phdata)
42939+{
42940+ unsigned long pax_flags = 0UL;
42941+
42942+#ifdef CONFIG_PAX_PAGEEXEC
42943+ if (elf_phdata->p_flags & PF_PAGEEXEC)
42944+ pax_flags |= MF_PAX_PAGEEXEC;
42945+#endif
42946+
42947+#ifdef CONFIG_PAX_SEGMEXEC
42948+ if (elf_phdata->p_flags & PF_SEGMEXEC)
42949+ pax_flags |= MF_PAX_SEGMEXEC;
42950+#endif
42951+
42952+#ifdef CONFIG_PAX_EMUTRAMP
42953+ if ((elf_phdata->p_flags & PF_EMUTRAMP) && (pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)))
42954+ pax_flags |= MF_PAX_EMUTRAMP;
42955+#endif
42956+
42957+#ifdef CONFIG_PAX_MPROTECT
42958+ if (elf_phdata->p_flags & PF_MPROTECT)
42959+ pax_flags |= MF_PAX_MPROTECT;
42960+#endif
42961+
42962+#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
42963+ if (randomize_va_space && (elf_phdata->p_flags & PF_RANDMMAP))
42964+ pax_flags |= MF_PAX_RANDMMAP;
42965+#endif
42966+
42967+ return pax_flags;
42968+}
42969+#endif
42970+
42971+static unsigned long pax_parse_pt_pax_hardmode(const struct elf_phdr * const elf_phdata)
42972+{
42973+ unsigned long pax_flags = 0UL;
42974+
42975+#ifdef CONFIG_PAX_PAGEEXEC
42976+ if (!(elf_phdata->p_flags & PF_NOPAGEEXEC))
42977+ pax_flags |= MF_PAX_PAGEEXEC;
42978+#endif
42979+
42980+#ifdef CONFIG_PAX_SEGMEXEC
42981+ if (!(elf_phdata->p_flags & PF_NOSEGMEXEC))
42982+ pax_flags |= MF_PAX_SEGMEXEC;
42983+#endif
42984+
42985+#ifdef CONFIG_PAX_EMUTRAMP
42986+ if (!(elf_phdata->p_flags & PF_NOEMUTRAMP))
42987+ pax_flags |= MF_PAX_EMUTRAMP;
42988+#endif
42989+
42990+#ifdef CONFIG_PAX_MPROTECT
42991+ if (!(elf_phdata->p_flags & PF_NOMPROTECT))
42992+ pax_flags |= MF_PAX_MPROTECT;
42993+#endif
42994+
42995+#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
42996+ if (randomize_va_space && !(elf_phdata->p_flags & PF_NORANDMMAP))
42997+ pax_flags |= MF_PAX_RANDMMAP;
42998+#endif
42999+
43000+ return pax_flags;
43001+}
43002+#endif
43003+
43004+#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
43005+#ifdef CONFIG_PAX_SOFTMODE
43006+static unsigned long pax_parse_xattr_pax_softmode(unsigned long pax_flags_softmode)
43007+{
43008+ unsigned long pax_flags = 0UL;
43009+
43010+#ifdef CONFIG_PAX_PAGEEXEC
43011+ if (pax_flags_softmode & MF_PAX_PAGEEXEC)
43012+ pax_flags |= MF_PAX_PAGEEXEC;
43013+#endif
43014+
43015+#ifdef CONFIG_PAX_SEGMEXEC
43016+ if (pax_flags_softmode & MF_PAX_SEGMEXEC)
43017+ pax_flags |= MF_PAX_SEGMEXEC;
43018+#endif
43019+
43020+#ifdef CONFIG_PAX_EMUTRAMP
43021+ if (pax_flags_softmode & MF_PAX_EMUTRAMP)
43022+ pax_flags |= MF_PAX_EMUTRAMP;
43023+#endif
43024+
43025+#ifdef CONFIG_PAX_MPROTECT
43026+ if (pax_flags_softmode & MF_PAX_MPROTECT)
43027+ pax_flags |= MF_PAX_MPROTECT;
43028+#endif
43029+
43030+#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
43031+ if (randomize_va_space && (pax_flags_softmode & MF_PAX_RANDMMAP))
43032+ pax_flags |= MF_PAX_RANDMMAP;
43033+#endif
43034+
43035+ return pax_flags;
43036+}
43037+#endif
43038+
43039+static unsigned long pax_parse_xattr_pax_hardmode(unsigned long pax_flags_hardmode)
43040+{
43041+ unsigned long pax_flags = 0UL;
43042+
43043+#ifdef CONFIG_PAX_PAGEEXEC
43044+ if (!(pax_flags_hardmode & MF_PAX_PAGEEXEC))
43045+ pax_flags |= MF_PAX_PAGEEXEC;
43046+#endif
43047+
43048+#ifdef CONFIG_PAX_SEGMEXEC
43049+ if (!(pax_flags_hardmode & MF_PAX_SEGMEXEC))
43050+ pax_flags |= MF_PAX_SEGMEXEC;
43051+#endif
43052+
43053+#ifdef CONFIG_PAX_EMUTRAMP
43054+ if (!(pax_flags_hardmode & MF_PAX_EMUTRAMP))
43055+ pax_flags |= MF_PAX_EMUTRAMP;
43056+#endif
43057+
43058+#ifdef CONFIG_PAX_MPROTECT
43059+ if (!(pax_flags_hardmode & MF_PAX_MPROTECT))
43060+ pax_flags |= MF_PAX_MPROTECT;
43061+#endif
43062+
43063+#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
43064+ if (randomize_va_space && !(pax_flags_hardmode & MF_PAX_RANDMMAP))
43065+ pax_flags |= MF_PAX_RANDMMAP;
43066+#endif
43067+
43068+ return pax_flags;
43069+}
43070+#endif
43071+
43072+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
43073+static unsigned long pax_parse_ei_pax(const struct elfhdr * const elf_ex)
43074+{
43075+ unsigned long pax_flags = 0UL;
43076+
43077+#ifdef CONFIG_PAX_EI_PAX
43078+
43079+#ifdef CONFIG_PAX_PAGEEXEC
43080+ if (!(elf_ex->e_ident[EI_PAX] & EF_PAX_PAGEEXEC))
43081+ pax_flags |= MF_PAX_PAGEEXEC;
43082+#endif
43083+
43084+#ifdef CONFIG_PAX_SEGMEXEC
43085+ if (!(elf_ex->e_ident[EI_PAX] & EF_PAX_SEGMEXEC))
43086+ pax_flags |= MF_PAX_SEGMEXEC;
43087+#endif
43088+
43089+#ifdef CONFIG_PAX_EMUTRAMP
43090+ if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) && (elf_ex->e_ident[EI_PAX] & EF_PAX_EMUTRAMP))
43091+ pax_flags |= MF_PAX_EMUTRAMP;
43092+#endif
43093+
43094+#ifdef CONFIG_PAX_MPROTECT
43095+ if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) && !(elf_ex->e_ident[EI_PAX] & EF_PAX_MPROTECT))
43096+ pax_flags |= MF_PAX_MPROTECT;
43097+#endif
43098+
43099+#ifdef CONFIG_PAX_ASLR
43100+ if (randomize_va_space && !(elf_ex->e_ident[EI_PAX] & EF_PAX_RANDMMAP))
43101+ pax_flags |= MF_PAX_RANDMMAP;
43102+#endif
43103+
43104+#else
43105+
43106+#ifdef CONFIG_PAX_PAGEEXEC
43107+ pax_flags |= MF_PAX_PAGEEXEC;
43108+#endif
43109+
43110+#ifdef CONFIG_PAX_SEGMEXEC
43111+ pax_flags |= MF_PAX_SEGMEXEC;
43112+#endif
43113+
43114+#ifdef CONFIG_PAX_MPROTECT
43115+ pax_flags |= MF_PAX_MPROTECT;
43116+#endif
43117+
43118+#ifdef CONFIG_PAX_RANDMMAP
43119+ if (randomize_va_space)
43120+ pax_flags |= MF_PAX_RANDMMAP;
43121+#endif
43122+
43123+#endif
43124+
43125+ return pax_flags;
43126+}
43127+
43128+static unsigned long pax_parse_pt_pax(const struct elfhdr * const elf_ex, const struct elf_phdr * const elf_phdata)
43129+{
43130+
43131+#ifdef CONFIG_PAX_PT_PAX_FLAGS
43132+ unsigned long i;
43133+
43134+ for (i = 0UL; i < elf_ex->e_phnum; i++)
43135+ if (elf_phdata[i].p_type == PT_PAX_FLAGS) {
43136+ if (((elf_phdata[i].p_flags & PF_PAGEEXEC) && (elf_phdata[i].p_flags & PF_NOPAGEEXEC)) ||
43137+ ((elf_phdata[i].p_flags & PF_SEGMEXEC) && (elf_phdata[i].p_flags & PF_NOSEGMEXEC)) ||
43138+ ((elf_phdata[i].p_flags & PF_EMUTRAMP) && (elf_phdata[i].p_flags & PF_NOEMUTRAMP)) ||
43139+ ((elf_phdata[i].p_flags & PF_MPROTECT) && (elf_phdata[i].p_flags & PF_NOMPROTECT)) ||
43140+ ((elf_phdata[i].p_flags & PF_RANDMMAP) && (elf_phdata[i].p_flags & PF_NORANDMMAP)))
43141+ return ~0UL;
43142+
43143+#ifdef CONFIG_PAX_SOFTMODE
43144+ if (pax_softmode)
43145+ return pax_parse_pt_pax_softmode(&elf_phdata[i]);
43146+ else
43147+#endif
43148+
43149+ return pax_parse_pt_pax_hardmode(&elf_phdata[i]);
43150+ break;
43151+ }
43152+#endif
43153+
43154+ return ~0UL;
43155+}
43156+
43157+static unsigned long pax_parse_xattr_pax(struct file * const file)
43158+{
43159+
43160+#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
43161+ ssize_t xattr_size, i;
43162+ unsigned char xattr_value[5];
43163+ unsigned long pax_flags_hardmode = 0UL, pax_flags_softmode = 0UL;
43164+
43165+ xattr_size = vfs_getxattr(file->f_path.dentry, XATTR_NAME_PAX_FLAGS, xattr_value, sizeof xattr_value);
43166+ if (xattr_size <= 0)
43167+ return ~0UL;
43168+
43169+ for (i = 0; i < xattr_size; i++)
43170+ switch (xattr_value[i]) {
43171+ default:
43172+ return ~0UL;
43173+
43174+#define parse_flag(option1, option2, flag) \
43175+ case option1: \
43176+ pax_flags_hardmode |= MF_PAX_##flag; \
43177+ break; \
43178+ case option2: \
43179+ pax_flags_softmode |= MF_PAX_##flag; \
43180+ break;
43181+
43182+ parse_flag('p', 'P', PAGEEXEC);
43183+ parse_flag('e', 'E', EMUTRAMP);
43184+ parse_flag('m', 'M', MPROTECT);
43185+ parse_flag('r', 'R', RANDMMAP);
43186+ parse_flag('s', 'S', SEGMEXEC);
43187+
43188+#undef parse_flag
43189+ }
43190+
43191+ if (pax_flags_hardmode & pax_flags_softmode)
43192+ return ~0UL;
43193+
43194+#ifdef CONFIG_PAX_SOFTMODE
43195+ if (pax_softmode)
43196+ return pax_parse_xattr_pax_softmode(pax_flags_softmode);
43197+ else
43198+#endif
43199+
43200+ return pax_parse_xattr_pax_hardmode(pax_flags_hardmode);
43201+#else
43202+ return ~0UL;
43203+#endif
43204+
43205+}
43206+
43207+static long pax_parse_pax_flags(const struct elfhdr * const elf_ex, const struct elf_phdr * const elf_phdata, struct file * const file)
43208+{
43209+ unsigned long pax_flags, pt_pax_flags, xattr_pax_flags;
43210+
43211+ pax_flags = pax_parse_ei_pax(elf_ex);
43212+ pt_pax_flags = pax_parse_pt_pax(elf_ex, elf_phdata);
43213+ xattr_pax_flags = pax_parse_xattr_pax(file);
43214+
43215+ if (pt_pax_flags == ~0UL)
43216+ pt_pax_flags = xattr_pax_flags;
43217+ else if (xattr_pax_flags == ~0UL)
43218+ xattr_pax_flags = pt_pax_flags;
43219+ if (pt_pax_flags != xattr_pax_flags)
43220+ return -EINVAL;
43221+ if (pt_pax_flags != ~0UL)
43222+ pax_flags = pt_pax_flags;
43223+
43224+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_PAX_SEGMEXEC)
43225+ if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) == (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
43226+ if ((__supported_pte_mask & _PAGE_NX))
43227+ pax_flags &= ~MF_PAX_SEGMEXEC;
43228+ else
43229+ pax_flags &= ~MF_PAX_PAGEEXEC;
43230+ }
43231+#endif
43232+
43233+ if (0 > pax_check_flags(&pax_flags))
43234+ return -EINVAL;
43235+
43236+ current->mm->pax_flags = pax_flags;
43237+ return 0;
43238+}
43239+#endif
43240+
43241 /*
43242 * These are the functions used to load ELF style executables and shared
43243 * libraries. There is no binary dependent code anywhere else.
43244@@ -539,6 +868,11 @@ static unsigned long randomize_stack_top(unsigned long stack_top)
43245 {
43246 unsigned int random_variable = 0;
43247
43248+#ifdef CONFIG_PAX_RANDUSTACK
43249+ if (randomize_va_space)
43250+ return stack_top - current->mm->delta_stack;
43251+#endif
43252+
43253 if ((current->flags & PF_RANDOMIZE) &&
43254 !(current->personality & ADDR_NO_RANDOMIZE)) {
43255 random_variable = get_random_int() & STACK_RND_MASK;
43256@@ -557,7 +891,7 @@ static int load_elf_binary(struct linux_binprm *bprm, struct pt_regs *regs)
43257 unsigned long load_addr = 0, load_bias = 0;
43258 int load_addr_set = 0;
43259 char * elf_interpreter = NULL;
43260- unsigned long error;
43261+ unsigned long error = 0;
43262 struct elf_phdr *elf_ppnt, *elf_phdata;
43263 unsigned long elf_bss, elf_brk;
43264 int retval, i;
43265@@ -567,11 +901,11 @@ static int load_elf_binary(struct linux_binprm *bprm, struct pt_regs *regs)
43266 unsigned long start_code, end_code, start_data, end_data;
43267 unsigned long reloc_func_desc __maybe_unused = 0;
43268 int executable_stack = EXSTACK_DEFAULT;
43269- unsigned long def_flags = 0;
43270 struct {
43271 struct elfhdr elf_ex;
43272 struct elfhdr interp_elf_ex;
43273 } *loc;
43274+ unsigned long pax_task_size = TASK_SIZE;
43275
43276 loc = kmalloc(sizeof(*loc), GFP_KERNEL);
43277 if (!loc) {
43278@@ -707,11 +1041,81 @@ static int load_elf_binary(struct linux_binprm *bprm, struct pt_regs *regs)
43279 goto out_free_dentry;
43280
43281 /* OK, This is the point of no return */
43282- current->mm->def_flags = def_flags;
43283+
43284+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
43285+ current->mm->pax_flags = 0UL;
43286+#endif
43287+
43288+#ifdef CONFIG_PAX_DLRESOLVE
43289+ current->mm->call_dl_resolve = 0UL;
43290+#endif
43291+
43292+#if defined(CONFIG_PPC32) && defined(CONFIG_PAX_EMUSIGRT)
43293+ current->mm->call_syscall = 0UL;
43294+#endif
43295+
43296+#ifdef CONFIG_PAX_ASLR
43297+ current->mm->delta_mmap = 0UL;
43298+ current->mm->delta_stack = 0UL;
43299+#endif
43300+
43301+ current->mm->def_flags = 0;
43302+
43303+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
43304+ if (0 > pax_parse_pax_flags(&loc->elf_ex, elf_phdata, bprm->file)) {
43305+ send_sig(SIGKILL, current, 0);
43306+ goto out_free_dentry;
43307+ }
43308+#endif
43309+
43310+#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
43311+ pax_set_initial_flags(bprm);
43312+#elif defined(CONFIG_PAX_HOOK_ACL_FLAGS)
43313+ if (pax_set_initial_flags_func)
43314+ (pax_set_initial_flags_func)(bprm);
43315+#endif
43316+
43317+#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
43318+ if ((current->mm->pax_flags & MF_PAX_PAGEEXEC) && !(__supported_pte_mask & _PAGE_NX)) {
43319+ current->mm->context.user_cs_limit = PAGE_SIZE;
43320+ current->mm->def_flags |= VM_PAGEEXEC;
43321+ }
43322+#endif
43323+
43324+#ifdef CONFIG_PAX_SEGMEXEC
43325+ if (current->mm->pax_flags & MF_PAX_SEGMEXEC) {
43326+ current->mm->context.user_cs_base = SEGMEXEC_TASK_SIZE;
43327+ current->mm->context.user_cs_limit = TASK_SIZE-SEGMEXEC_TASK_SIZE;
43328+ pax_task_size = SEGMEXEC_TASK_SIZE;
43329+ current->mm->def_flags |= VM_NOHUGEPAGE;
43330+ }
43331+#endif
43332+
43333+#if defined(CONFIG_ARCH_TRACK_EXEC_LIMIT) || defined(CONFIG_PAX_SEGMEXEC)
43334+ if (current->mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
43335+ set_user_cs(current->mm->context.user_cs_base, current->mm->context.user_cs_limit, get_cpu());
43336+ put_cpu();
43337+ }
43338+#endif
43339
43340 /* Do this immediately, since STACK_TOP as used in setup_arg_pages
43341 may depend on the personality. */
43342 SET_PERSONALITY(loc->elf_ex);
43343+
43344+#ifdef CONFIG_PAX_ASLR
43345+ if (current->mm->pax_flags & MF_PAX_RANDMMAP) {
43346+ current->mm->delta_mmap = (pax_get_random_long() & ((1UL << PAX_DELTA_MMAP_LEN)-1)) << PAGE_SHIFT;
43347+ current->mm->delta_stack = (pax_get_random_long() & ((1UL << PAX_DELTA_STACK_LEN)-1)) << PAGE_SHIFT;
43348+ }
43349+#endif
43350+
43351+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
43352+ if (current->mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
43353+ executable_stack = EXSTACK_DISABLE_X;
43354+ current->personality &= ~READ_IMPLIES_EXEC;
43355+ } else
43356+#endif
43357+
43358 if (elf_read_implies_exec(loc->elf_ex, executable_stack))
43359 current->personality |= READ_IMPLIES_EXEC;
43360
43361@@ -802,6 +1206,20 @@ static int load_elf_binary(struct linux_binprm *bprm, struct pt_regs *regs)
43362 #else
43363 load_bias = ELF_PAGESTART(ELF_ET_DYN_BASE - vaddr);
43364 #endif
43365+
43366+#ifdef CONFIG_PAX_RANDMMAP
43367+ /* PaX: randomize base address at the default exe base if requested */
43368+ if ((current->mm->pax_flags & MF_PAX_RANDMMAP) && elf_interpreter) {
43369+#ifdef CONFIG_SPARC64
43370+ load_bias = (pax_get_random_long() & ((1UL << PAX_DELTA_MMAP_LEN) - 1)) << (PAGE_SHIFT+1);
43371+#else
43372+ load_bias = (pax_get_random_long() & ((1UL << PAX_DELTA_MMAP_LEN) - 1)) << PAGE_SHIFT;
43373+#endif
43374+ load_bias = ELF_PAGESTART(PAX_ELF_ET_DYN_BASE - vaddr + load_bias);
43375+ elf_flags |= MAP_FIXED;
43376+ }
43377+#endif
43378+
43379 }
43380
43381 error = elf_map(bprm->file, load_bias + vaddr, elf_ppnt,
43382@@ -834,9 +1252,9 @@ static int load_elf_binary(struct linux_binprm *bprm, struct pt_regs *regs)
43383 * allowed task size. Note that p_filesz must always be
43384 * <= p_memsz so it is only necessary to check p_memsz.
43385 */
43386- if (BAD_ADDR(k) || elf_ppnt->p_filesz > elf_ppnt->p_memsz ||
43387- elf_ppnt->p_memsz > TASK_SIZE ||
43388- TASK_SIZE - elf_ppnt->p_memsz < k) {
43389+ if (k >= pax_task_size || elf_ppnt->p_filesz > elf_ppnt->p_memsz ||
43390+ elf_ppnt->p_memsz > pax_task_size ||
43391+ pax_task_size - elf_ppnt->p_memsz < k) {
43392 /* set_brk can never work. Avoid overflows. */
43393 send_sig(SIGKILL, current, 0);
43394 retval = -EINVAL;
43395@@ -875,11 +1293,41 @@ static int load_elf_binary(struct linux_binprm *bprm, struct pt_regs *regs)
43396 goto out_free_dentry;
43397 }
43398 if (likely(elf_bss != elf_brk) && unlikely(padzero(elf_bss))) {
43399- send_sig(SIGSEGV, current, 0);
43400- retval = -EFAULT; /* Nobody gets to see this, but.. */
43401- goto out_free_dentry;
43402+ /*
43403+ * This bss-zeroing can fail if the ELF
43404+ * file specifies odd protections. So
43405+ * we don't check the return value
43406+ */
43407 }
43408
43409+#ifdef CONFIG_PAX_RANDMMAP
43410+ if (current->mm->pax_flags & MF_PAX_RANDMMAP) {
43411+ unsigned long start, size;
43412+
43413+ start = ELF_PAGEALIGN(elf_brk);
43414+ size = PAGE_SIZE + ((pax_get_random_long() & ((1UL << 22) - 1UL)) << 4);
43415+ down_read(&current->mm->mmap_sem);
43416+ retval = -ENOMEM;
43417+ if (!find_vma_intersection(current->mm, start, start + size + PAGE_SIZE)) {
43418+ unsigned long prot = PROT_NONE;
43419+
43420+ up_read(&current->mm->mmap_sem);
43421+ current->mm->brk_gap = PAGE_ALIGN(size) >> PAGE_SHIFT;
43422+// if (current->personality & ADDR_NO_RANDOMIZE)
43423+// prot = PROT_READ;
43424+ start = vm_mmap(NULL, start, size, prot, MAP_ANONYMOUS | MAP_FIXED | MAP_PRIVATE, 0);
43425+ retval = IS_ERR_VALUE(start) ? start : 0;
43426+ } else
43427+ up_read(&current->mm->mmap_sem);
43428+ if (retval == 0)
43429+ retval = set_brk(start + size, start + size + PAGE_SIZE);
43430+ if (retval < 0) {
43431+ send_sig(SIGKILL, current, 0);
43432+ goto out_free_dentry;
43433+ }
43434+ }
43435+#endif
43436+
43437 if (elf_interpreter) {
43438 unsigned long uninitialized_var(interp_map_addr);
43439
43440@@ -1107,7 +1555,7 @@ static bool always_dump_vma(struct vm_area_struct *vma)
43441 * Decide what to dump of a segment, part, all or none.
43442 */
43443 static unsigned long vma_dump_size(struct vm_area_struct *vma,
43444- unsigned long mm_flags)
43445+ unsigned long mm_flags, long signr)
43446 {
43447 #define FILTER(type) (mm_flags & (1UL << MMF_DUMP_##type))
43448
43449@@ -1144,7 +1592,7 @@ static unsigned long vma_dump_size(struct vm_area_struct *vma,
43450 if (vma->vm_file == NULL)
43451 return 0;
43452
43453- if (FILTER(MAPPED_PRIVATE))
43454+ if (signr == SIGKILL || FILTER(MAPPED_PRIVATE))
43455 goto whole;
43456
43457 /*
43458@@ -1366,9 +1814,9 @@ static void fill_auxv_note(struct memelfnote *note, struct mm_struct *mm)
43459 {
43460 elf_addr_t *auxv = (elf_addr_t *) mm->saved_auxv;
43461 int i = 0;
43462- do
43463+ do {
43464 i += 2;
43465- while (auxv[i - 2] != AT_NULL);
43466+ } while (auxv[i - 2] != AT_NULL);
43467 fill_note(note, "CORE", NT_AUXV, i * sizeof(elf_addr_t), auxv);
43468 }
43469
43470@@ -1879,14 +2327,14 @@ static void fill_extnum_info(struct elfhdr *elf, struct elf_shdr *shdr4extnum,
43471 }
43472
43473 static size_t elf_core_vma_data_size(struct vm_area_struct *gate_vma,
43474- unsigned long mm_flags)
43475+ struct coredump_params *cprm)
43476 {
43477 struct vm_area_struct *vma;
43478 size_t size = 0;
43479
43480 for (vma = first_vma(current, gate_vma); vma != NULL;
43481 vma = next_vma(vma, gate_vma))
43482- size += vma_dump_size(vma, mm_flags);
43483+ size += vma_dump_size(vma, cprm->mm_flags, cprm->signr);
43484 return size;
43485 }
43486
43487@@ -1980,7 +2428,7 @@ static int elf_core_dump(struct coredump_params *cprm)
43488
43489 dataoff = offset = roundup(offset, ELF_EXEC_PAGESIZE);
43490
43491- offset += elf_core_vma_data_size(gate_vma, cprm->mm_flags);
43492+ offset += elf_core_vma_data_size(gate_vma, cprm);
43493 offset += elf_core_extra_data_size();
43494 e_shoff = offset;
43495
43496@@ -1994,10 +2442,12 @@ static int elf_core_dump(struct coredump_params *cprm)
43497 offset = dataoff;
43498
43499 size += sizeof(*elf);
43500+ gr_learn_resource(current, RLIMIT_CORE, size, 1);
43501 if (size > cprm->limit || !dump_write(cprm->file, elf, sizeof(*elf)))
43502 goto end_coredump;
43503
43504 size += sizeof(*phdr4note);
43505+ gr_learn_resource(current, RLIMIT_CORE, size, 1);
43506 if (size > cprm->limit
43507 || !dump_write(cprm->file, phdr4note, sizeof(*phdr4note)))
43508 goto end_coredump;
43509@@ -2011,7 +2461,7 @@ static int elf_core_dump(struct coredump_params *cprm)
43510 phdr.p_offset = offset;
43511 phdr.p_vaddr = vma->vm_start;
43512 phdr.p_paddr = 0;
43513- phdr.p_filesz = vma_dump_size(vma, cprm->mm_flags);
43514+ phdr.p_filesz = vma_dump_size(vma, cprm->mm_flags, cprm->signr);
43515 phdr.p_memsz = vma->vm_end - vma->vm_start;
43516 offset += phdr.p_filesz;
43517 phdr.p_flags = vma->vm_flags & VM_READ ? PF_R : 0;
43518@@ -2022,6 +2472,7 @@ static int elf_core_dump(struct coredump_params *cprm)
43519 phdr.p_align = ELF_EXEC_PAGESIZE;
43520
43521 size += sizeof(phdr);
43522+ gr_learn_resource(current, RLIMIT_CORE, size, 1);
43523 if (size > cprm->limit
43524 || !dump_write(cprm->file, &phdr, sizeof(phdr)))
43525 goto end_coredump;
43526@@ -2046,7 +2497,7 @@ static int elf_core_dump(struct coredump_params *cprm)
43527 unsigned long addr;
43528 unsigned long end;
43529
43530- end = vma->vm_start + vma_dump_size(vma, cprm->mm_flags);
43531+ end = vma->vm_start + vma_dump_size(vma, cprm->mm_flags, cprm->signr);
43532
43533 for (addr = vma->vm_start; addr < end; addr += PAGE_SIZE) {
43534 struct page *page;
43535@@ -2055,6 +2506,7 @@ static int elf_core_dump(struct coredump_params *cprm)
43536 page = get_dump_page(addr);
43537 if (page) {
43538 void *kaddr = kmap(page);
43539+ gr_learn_resource(current, RLIMIT_CORE, size + PAGE_SIZE, 1);
43540 stop = ((size += PAGE_SIZE) > cprm->limit) ||
43541 !dump_write(cprm->file, kaddr,
43542 PAGE_SIZE);
43543@@ -2072,6 +2524,7 @@ static int elf_core_dump(struct coredump_params *cprm)
43544
43545 if (e_phnum == PN_XNUM) {
43546 size += sizeof(*shdr4extnum);
43547+ gr_learn_resource(current, RLIMIT_CORE, size, 1);
43548 if (size > cprm->limit
43549 || !dump_write(cprm->file, shdr4extnum,
43550 sizeof(*shdr4extnum)))
43551@@ -2092,6 +2545,97 @@ out:
43552
43553 #endif /* CONFIG_ELF_CORE */
43554
43555+#ifdef CONFIG_PAX_MPROTECT
43556+/* PaX: non-PIC ELF libraries need relocations on their executable segments
43557+ * therefore we'll grant them VM_MAYWRITE once during their life. Similarly
43558+ * we'll remove VM_MAYWRITE for good on RELRO segments.
43559+ *
43560+ * The checks favour ld-linux.so behaviour which operates on a per ELF segment
43561+ * basis because we want to allow the common case and not the special ones.
43562+ */
43563+static void elf_handle_mprotect(struct vm_area_struct *vma, unsigned long newflags)
43564+{
43565+ struct elfhdr elf_h;
43566+ struct elf_phdr elf_p;
43567+ unsigned long i;
43568+ unsigned long oldflags;
43569+ bool is_textrel_rw, is_textrel_rx, is_relro;
43570+
43571+ if (!(vma->vm_mm->pax_flags & MF_PAX_MPROTECT))
43572+ return;
43573+
43574+ oldflags = vma->vm_flags & (VM_MAYEXEC | VM_MAYWRITE | VM_MAYREAD | VM_EXEC | VM_WRITE | VM_READ);
43575+ newflags &= VM_MAYEXEC | VM_MAYWRITE | VM_MAYREAD | VM_EXEC | VM_WRITE | VM_READ;
43576+
43577+#ifdef CONFIG_PAX_ELFRELOCS
43578+ /* possible TEXTREL */
43579+ is_textrel_rw = vma->vm_file && !vma->anon_vma && oldflags == (VM_MAYEXEC | VM_MAYREAD | VM_EXEC | VM_READ) && newflags == (VM_WRITE | VM_READ);
43580+ 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);
43581+#else
43582+ is_textrel_rw = false;
43583+ is_textrel_rx = false;
43584+#endif
43585+
43586+ /* possible RELRO */
43587+ is_relro = vma->vm_file && vma->anon_vma && oldflags == (VM_MAYWRITE | VM_MAYREAD | VM_READ) && newflags == (VM_MAYWRITE | VM_MAYREAD | VM_READ);
43588+
43589+ if (!is_textrel_rw && !is_textrel_rx && !is_relro)
43590+ return;
43591+
43592+ if (sizeof(elf_h) != kernel_read(vma->vm_file, 0UL, (char *)&elf_h, sizeof(elf_h)) ||
43593+ memcmp(elf_h.e_ident, ELFMAG, SELFMAG) ||
43594+
43595+#ifdef CONFIG_PAX_ETEXECRELOCS
43596+ ((is_textrel_rw || is_textrel_rx) && (elf_h.e_type != ET_DYN && elf_h.e_type != ET_EXEC)) ||
43597+#else
43598+ ((is_textrel_rw || is_textrel_rx) && elf_h.e_type != ET_DYN) ||
43599+#endif
43600+
43601+ (is_relro && (elf_h.e_type != ET_DYN && elf_h.e_type != ET_EXEC)) ||
43602+ !elf_check_arch(&elf_h) ||
43603+ elf_h.e_phentsize != sizeof(struct elf_phdr) ||
43604+ elf_h.e_phnum > 65536UL / sizeof(struct elf_phdr))
43605+ return;
43606+
43607+ for (i = 0UL; i < elf_h.e_phnum; i++) {
43608+ if (sizeof(elf_p) != kernel_read(vma->vm_file, elf_h.e_phoff + i*sizeof(elf_p), (char *)&elf_p, sizeof(elf_p)))
43609+ return;
43610+ switch (elf_p.p_type) {
43611+ case PT_DYNAMIC:
43612+ if (!is_textrel_rw && !is_textrel_rx)
43613+ continue;
43614+ i = 0UL;
43615+ while ((i+1) * sizeof(elf_dyn) <= elf_p.p_filesz) {
43616+ elf_dyn dyn;
43617+
43618+ if (sizeof(dyn) != kernel_read(vma->vm_file, elf_p.p_offset + i*sizeof(dyn), (char *)&dyn, sizeof(dyn)))
43619+ return;
43620+ if (dyn.d_tag == DT_NULL)
43621+ return;
43622+ if (dyn.d_tag == DT_TEXTREL || (dyn.d_tag == DT_FLAGS && (dyn.d_un.d_val & DF_TEXTREL))) {
43623+ gr_log_textrel(vma);
43624+ if (is_textrel_rw)
43625+ vma->vm_flags |= VM_MAYWRITE;
43626+ else
43627+ /* PaX: disallow write access after relocs are done, hopefully noone else needs it... */
43628+ vma->vm_flags &= ~VM_MAYWRITE;
43629+ return;
43630+ }
43631+ i++;
43632+ }
43633+ return;
43634+
43635+ case PT_GNU_RELRO:
43636+ if (!is_relro)
43637+ continue;
43638+ if ((elf_p.p_offset >> PAGE_SHIFT) == vma->vm_pgoff && ELF_PAGEALIGN(elf_p.p_memsz) == vma->vm_end - vma->vm_start)
43639+ vma->vm_flags &= ~VM_MAYWRITE;
43640+ return;
43641+ }
43642+ }
43643+}
43644+#endif
43645+
43646 static int __init init_elf_binfmt(void)
43647 {
43648 register_binfmt(&elf_format);
43649diff --git a/fs/binfmt_flat.c b/fs/binfmt_flat.c
43650index 178cb70..8972997 100644
43651--- a/fs/binfmt_flat.c
43652+++ b/fs/binfmt_flat.c
43653@@ -562,7 +562,9 @@ static int load_flat_file(struct linux_binprm * bprm,
43654 realdatastart = (unsigned long) -ENOMEM;
43655 printk("Unable to allocate RAM for process data, errno %d\n",
43656 (int)-realdatastart);
43657+ down_write(&current->mm->mmap_sem);
43658 vm_munmap(textpos, text_len);
43659+ up_write(&current->mm->mmap_sem);
43660 ret = realdatastart;
43661 goto err;
43662 }
43663@@ -586,8 +588,10 @@ static int load_flat_file(struct linux_binprm * bprm,
43664 }
43665 if (IS_ERR_VALUE(result)) {
43666 printk("Unable to read data+bss, errno %d\n", (int)-result);
43667+ down_write(&current->mm->mmap_sem);
43668 vm_munmap(textpos, text_len);
43669 vm_munmap(realdatastart, len);
43670+ up_write(&current->mm->mmap_sem);
43671 ret = result;
43672 goto err;
43673 }
43674@@ -654,8 +658,10 @@ static int load_flat_file(struct linux_binprm * bprm,
43675 }
43676 if (IS_ERR_VALUE(result)) {
43677 printk("Unable to read code+data+bss, errno %d\n",(int)-result);
43678+ down_write(&current->mm->mmap_sem);
43679 vm_munmap(textpos, text_len + data_len + extra +
43680 MAX_SHARED_LIBS * sizeof(unsigned long));
43681+ up_write(&current->mm->mmap_sem);
43682 ret = result;
43683 goto err;
43684 }
43685diff --git a/fs/bio.c b/fs/bio.c
43686index 71072ab..439851b 100644
43687--- a/fs/bio.c
43688+++ b/fs/bio.c
43689@@ -842,7 +842,7 @@ struct bio *bio_copy_user_iov(struct request_queue *q,
43690 /*
43691 * Overflow, abort
43692 */
43693- if (end < start)
43694+ if (end < start || end - start > INT_MAX - nr_pages)
43695 return ERR_PTR(-EINVAL);
43696
43697 nr_pages += end - start;
43698@@ -976,7 +976,7 @@ static struct bio *__bio_map_user_iov(struct request_queue *q,
43699 /*
43700 * Overflow, abort
43701 */
43702- if (end < start)
43703+ if (end < start || end - start > INT_MAX - nr_pages)
43704 return ERR_PTR(-EINVAL);
43705
43706 nr_pages += end - start;
43707@@ -1238,7 +1238,7 @@ static void bio_copy_kern_endio(struct bio *bio, int err)
43708 const int read = bio_data_dir(bio) == READ;
43709 struct bio_map_data *bmd = bio->bi_private;
43710 int i;
43711- char *p = bmd->sgvecs[0].iov_base;
43712+ char *p = (char __force_kernel *)bmd->sgvecs[0].iov_base;
43713
43714 __bio_for_each_segment(bvec, bio, i, 0) {
43715 char *addr = page_address(bvec->bv_page);
43716diff --git a/fs/block_dev.c b/fs/block_dev.c
43717index 38e721b..7a9c5bc 100644
43718--- a/fs/block_dev.c
43719+++ b/fs/block_dev.c
43720@@ -704,7 +704,7 @@ static bool bd_may_claim(struct block_device *bdev, struct block_device *whole,
43721 else if (bdev->bd_contains == bdev)
43722 return true; /* is a whole device which isn't held */
43723
43724- else if (whole->bd_holder == bd_may_claim)
43725+ else if (whole->bd_holder == (void *)bd_may_claim)
43726 return true; /* is a partition of a device that is being partitioned */
43727 else if (whole->bd_holder != NULL)
43728 return false; /* is a partition of a held device */
43729diff --git a/fs/btrfs/check-integrity.c b/fs/btrfs/check-integrity.c
43730index 9197e2e..7f731f8 100644
43731--- a/fs/btrfs/check-integrity.c
43732+++ b/fs/btrfs/check-integrity.c
43733@@ -155,7 +155,7 @@ struct btrfsic_block {
43734 union {
43735 bio_end_io_t *bio;
43736 bh_end_io_t *bh;
43737- } orig_bio_bh_end_io;
43738+ } __no_const orig_bio_bh_end_io;
43739 int submit_bio_bh_rw;
43740 u64 flush_gen; /* only valid if !never_written */
43741 };
43742diff --git a/fs/btrfs/ctree.c b/fs/btrfs/ctree.c
43743index 6d183f6..f47cc7a 100644
43744--- a/fs/btrfs/ctree.c
43745+++ b/fs/btrfs/ctree.c
43746@@ -1037,9 +1037,12 @@ static noinline int __btrfs_cow_block(struct btrfs_trans_handle *trans,
43747 free_extent_buffer(buf);
43748 add_root_to_dirty_list(root);
43749 } else {
43750- if (root->root_key.objectid == BTRFS_TREE_RELOC_OBJECTID)
43751- parent_start = parent->start;
43752- else
43753+ if (root->root_key.objectid == BTRFS_TREE_RELOC_OBJECTID) {
43754+ if (parent)
43755+ parent_start = parent->start;
43756+ else
43757+ parent_start = 0;
43758+ } else
43759 parent_start = 0;
43760
43761 WARN_ON(trans->transid != btrfs_header_generation(parent));
43762diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c
43763index ec154f9..bf617a7 100644
43764--- a/fs/btrfs/inode.c
43765+++ b/fs/btrfs/inode.c
43766@@ -7126,7 +7126,7 @@ fail:
43767 return -ENOMEM;
43768 }
43769
43770-static int btrfs_getattr(struct vfsmount *mnt,
43771+int btrfs_getattr(struct vfsmount *mnt,
43772 struct dentry *dentry, struct kstat *stat)
43773 {
43774 struct inode *inode = dentry->d_inode;
43775@@ -7140,6 +7140,14 @@ static int btrfs_getattr(struct vfsmount *mnt,
43776 return 0;
43777 }
43778
43779+EXPORT_SYMBOL(btrfs_getattr);
43780+
43781+dev_t get_btrfs_dev_from_inode(struct inode *inode)
43782+{
43783+ return BTRFS_I(inode)->root->anon_dev;
43784+}
43785+EXPORT_SYMBOL(get_btrfs_dev_from_inode);
43786+
43787 /*
43788 * If a file is moved, it will inherit the cow and compression flags of the new
43789 * directory.
43790diff --git a/fs/btrfs/ioctl.c b/fs/btrfs/ioctl.c
43791index 9df50fa..6cd20d0 100644
43792--- a/fs/btrfs/ioctl.c
43793+++ b/fs/btrfs/ioctl.c
43794@@ -2942,9 +2942,12 @@ long btrfs_ioctl_space_info(struct btrfs_root *root, void __user *arg)
43795 for (i = 0; i < num_types; i++) {
43796 struct btrfs_space_info *tmp;
43797
43798+ /* Don't copy in more than we allocated */
43799 if (!slot_count)
43800 break;
43801
43802+ slot_count--;
43803+
43804 info = NULL;
43805 rcu_read_lock();
43806 list_for_each_entry_rcu(tmp, &root->fs_info->space_info,
43807@@ -2966,10 +2969,7 @@ long btrfs_ioctl_space_info(struct btrfs_root *root, void __user *arg)
43808 memcpy(dest, &space, sizeof(space));
43809 dest++;
43810 space_args.total_spaces++;
43811- slot_count--;
43812 }
43813- if (!slot_count)
43814- break;
43815 }
43816 up_read(&info->groups_sem);
43817 }
43818diff --git a/fs/btrfs/relocation.c b/fs/btrfs/relocation.c
43819index 4da0865..01c4778 100644
43820--- a/fs/btrfs/relocation.c
43821+++ b/fs/btrfs/relocation.c
43822@@ -1269,7 +1269,7 @@ static int __update_reloc_root(struct btrfs_root *root, int del)
43823 }
43824 spin_unlock(&rc->reloc_root_tree.lock);
43825
43826- BUG_ON((struct btrfs_root *)node->data != root);
43827+ BUG_ON(!node || (struct btrfs_root *)node->data != root);
43828
43829 if (!del) {
43830 spin_lock(&rc->reloc_root_tree.lock);
43831diff --git a/fs/cachefiles/bind.c b/fs/cachefiles/bind.c
43832index 622f469..e8d2d55 100644
43833--- a/fs/cachefiles/bind.c
43834+++ b/fs/cachefiles/bind.c
43835@@ -39,13 +39,11 @@ int cachefiles_daemon_bind(struct cachefiles_cache *cache, char *args)
43836 args);
43837
43838 /* start by checking things over */
43839- ASSERT(cache->fstop_percent >= 0 &&
43840- cache->fstop_percent < cache->fcull_percent &&
43841+ ASSERT(cache->fstop_percent < cache->fcull_percent &&
43842 cache->fcull_percent < cache->frun_percent &&
43843 cache->frun_percent < 100);
43844
43845- ASSERT(cache->bstop_percent >= 0 &&
43846- cache->bstop_percent < cache->bcull_percent &&
43847+ ASSERT(cache->bstop_percent < cache->bcull_percent &&
43848 cache->bcull_percent < cache->brun_percent &&
43849 cache->brun_percent < 100);
43850
43851diff --git a/fs/cachefiles/daemon.c b/fs/cachefiles/daemon.c
43852index 0a1467b..6a53245 100644
43853--- a/fs/cachefiles/daemon.c
43854+++ b/fs/cachefiles/daemon.c
43855@@ -196,7 +196,7 @@ static ssize_t cachefiles_daemon_read(struct file *file, char __user *_buffer,
43856 if (n > buflen)
43857 return -EMSGSIZE;
43858
43859- if (copy_to_user(_buffer, buffer, n) != 0)
43860+ if (n > sizeof(buffer) || copy_to_user(_buffer, buffer, n) != 0)
43861 return -EFAULT;
43862
43863 return n;
43864@@ -222,7 +222,7 @@ static ssize_t cachefiles_daemon_write(struct file *file,
43865 if (test_bit(CACHEFILES_DEAD, &cache->flags))
43866 return -EIO;
43867
43868- if (datalen < 0 || datalen > PAGE_SIZE - 1)
43869+ if (datalen > PAGE_SIZE - 1)
43870 return -EOPNOTSUPP;
43871
43872 /* drag the command string into the kernel so we can parse it */
43873@@ -386,7 +386,7 @@ static int cachefiles_daemon_fstop(struct cachefiles_cache *cache, char *args)
43874 if (args[0] != '%' || args[1] != '\0')
43875 return -EINVAL;
43876
43877- if (fstop < 0 || fstop >= cache->fcull_percent)
43878+ if (fstop >= cache->fcull_percent)
43879 return cachefiles_daemon_range_error(cache, args);
43880
43881 cache->fstop_percent = fstop;
43882@@ -458,7 +458,7 @@ static int cachefiles_daemon_bstop(struct cachefiles_cache *cache, char *args)
43883 if (args[0] != '%' || args[1] != '\0')
43884 return -EINVAL;
43885
43886- if (bstop < 0 || bstop >= cache->bcull_percent)
43887+ if (bstop >= cache->bcull_percent)
43888 return cachefiles_daemon_range_error(cache, args);
43889
43890 cache->bstop_percent = bstop;
43891diff --git a/fs/cachefiles/internal.h b/fs/cachefiles/internal.h
43892index bd6bc1b..b627b53 100644
43893--- a/fs/cachefiles/internal.h
43894+++ b/fs/cachefiles/internal.h
43895@@ -57,7 +57,7 @@ struct cachefiles_cache {
43896 wait_queue_head_t daemon_pollwq; /* poll waitqueue for daemon */
43897 struct rb_root active_nodes; /* active nodes (can't be culled) */
43898 rwlock_t active_lock; /* lock for active_nodes */
43899- atomic_t gravecounter; /* graveyard uniquifier */
43900+ atomic_unchecked_t gravecounter; /* graveyard uniquifier */
43901 unsigned frun_percent; /* when to stop culling (% files) */
43902 unsigned fcull_percent; /* when to start culling (% files) */
43903 unsigned fstop_percent; /* when to stop allocating (% files) */
43904@@ -169,19 +169,19 @@ extern int cachefiles_check_in_use(struct cachefiles_cache *cache,
43905 * proc.c
43906 */
43907 #ifdef CONFIG_CACHEFILES_HISTOGRAM
43908-extern atomic_t cachefiles_lookup_histogram[HZ];
43909-extern atomic_t cachefiles_mkdir_histogram[HZ];
43910-extern atomic_t cachefiles_create_histogram[HZ];
43911+extern atomic_unchecked_t cachefiles_lookup_histogram[HZ];
43912+extern atomic_unchecked_t cachefiles_mkdir_histogram[HZ];
43913+extern atomic_unchecked_t cachefiles_create_histogram[HZ];
43914
43915 extern int __init cachefiles_proc_init(void);
43916 extern void cachefiles_proc_cleanup(void);
43917 static inline
43918-void cachefiles_hist(atomic_t histogram[], unsigned long start_jif)
43919+void cachefiles_hist(atomic_unchecked_t histogram[], unsigned long start_jif)
43920 {
43921 unsigned long jif = jiffies - start_jif;
43922 if (jif >= HZ)
43923 jif = HZ - 1;
43924- atomic_inc(&histogram[jif]);
43925+ atomic_inc_unchecked(&histogram[jif]);
43926 }
43927
43928 #else
43929diff --git a/fs/cachefiles/namei.c b/fs/cachefiles/namei.c
43930index b0b5f7c..039bb26 100644
43931--- a/fs/cachefiles/namei.c
43932+++ b/fs/cachefiles/namei.c
43933@@ -318,7 +318,7 @@ try_again:
43934 /* first step is to make up a grave dentry in the graveyard */
43935 sprintf(nbuffer, "%08x%08x",
43936 (uint32_t) get_seconds(),
43937- (uint32_t) atomic_inc_return(&cache->gravecounter));
43938+ (uint32_t) atomic_inc_return_unchecked(&cache->gravecounter));
43939
43940 /* do the multiway lock magic */
43941 trap = lock_rename(cache->graveyard, dir);
43942diff --git a/fs/cachefiles/proc.c b/fs/cachefiles/proc.c
43943index eccd339..4c1d995 100644
43944--- a/fs/cachefiles/proc.c
43945+++ b/fs/cachefiles/proc.c
43946@@ -14,9 +14,9 @@
43947 #include <linux/seq_file.h>
43948 #include "internal.h"
43949
43950-atomic_t cachefiles_lookup_histogram[HZ];
43951-atomic_t cachefiles_mkdir_histogram[HZ];
43952-atomic_t cachefiles_create_histogram[HZ];
43953+atomic_unchecked_t cachefiles_lookup_histogram[HZ];
43954+atomic_unchecked_t cachefiles_mkdir_histogram[HZ];
43955+atomic_unchecked_t cachefiles_create_histogram[HZ];
43956
43957 /*
43958 * display the latency histogram
43959@@ -35,9 +35,9 @@ static int cachefiles_histogram_show(struct seq_file *m, void *v)
43960 return 0;
43961 default:
43962 index = (unsigned long) v - 3;
43963- x = atomic_read(&cachefiles_lookup_histogram[index]);
43964- y = atomic_read(&cachefiles_mkdir_histogram[index]);
43965- z = atomic_read(&cachefiles_create_histogram[index]);
43966+ x = atomic_read_unchecked(&cachefiles_lookup_histogram[index]);
43967+ y = atomic_read_unchecked(&cachefiles_mkdir_histogram[index]);
43968+ z = atomic_read_unchecked(&cachefiles_create_histogram[index]);
43969 if (x == 0 && y == 0 && z == 0)
43970 return 0;
43971
43972diff --git a/fs/cachefiles/rdwr.c b/fs/cachefiles/rdwr.c
43973index c994691..2a1537f 100644
43974--- a/fs/cachefiles/rdwr.c
43975+++ b/fs/cachefiles/rdwr.c
43976@@ -945,7 +945,7 @@ int cachefiles_write_page(struct fscache_storage *op, struct page *page)
43977 old_fs = get_fs();
43978 set_fs(KERNEL_DS);
43979 ret = file->f_op->write(
43980- file, (const void __user *) data, len, &pos);
43981+ file, (const void __force_user *) data, len, &pos);
43982 set_fs(old_fs);
43983 kunmap(page);
43984 if (ret != len)
43985diff --git a/fs/ceph/dir.c b/fs/ceph/dir.c
43986index e5b7731..b9c59fb 100644
43987--- a/fs/ceph/dir.c
43988+++ b/fs/ceph/dir.c
43989@@ -243,7 +243,7 @@ static int ceph_readdir(struct file *filp, void *dirent, filldir_t filldir)
43990 struct ceph_fs_client *fsc = ceph_inode_to_client(inode);
43991 struct ceph_mds_client *mdsc = fsc->mdsc;
43992 unsigned frag = fpos_frag(filp->f_pos);
43993- int off = fpos_off(filp->f_pos);
43994+ unsigned int off = fpos_off(filp->f_pos);
43995 int err;
43996 u32 ftype;
43997 struct ceph_mds_reply_info_parsed *rinfo;
43998diff --git a/fs/cifs/cifs_debug.c b/fs/cifs/cifs_debug.c
43999index d9ea6ed..1e6c8ac 100644
44000--- a/fs/cifs/cifs_debug.c
44001+++ b/fs/cifs/cifs_debug.c
44002@@ -267,8 +267,8 @@ static ssize_t cifs_stats_proc_write(struct file *file,
44003
44004 if (c == '1' || c == 'y' || c == 'Y' || c == '0') {
44005 #ifdef CONFIG_CIFS_STATS2
44006- atomic_set(&totBufAllocCount, 0);
44007- atomic_set(&totSmBufAllocCount, 0);
44008+ atomic_set_unchecked(&totBufAllocCount, 0);
44009+ atomic_set_unchecked(&totSmBufAllocCount, 0);
44010 #endif /* CONFIG_CIFS_STATS2 */
44011 spin_lock(&cifs_tcp_ses_lock);
44012 list_for_each(tmp1, &cifs_tcp_ses_list) {
44013@@ -281,7 +281,7 @@ static ssize_t cifs_stats_proc_write(struct file *file,
44014 tcon = list_entry(tmp3,
44015 struct cifs_tcon,
44016 tcon_list);
44017- atomic_set(&tcon->num_smbs_sent, 0);
44018+ atomic_set_unchecked(&tcon->num_smbs_sent, 0);
44019 if (server->ops->clear_stats)
44020 server->ops->clear_stats(tcon);
44021 }
44022@@ -313,8 +313,8 @@ static int cifs_stats_proc_show(struct seq_file *m, void *v)
44023 smBufAllocCount.counter, cifs_min_small);
44024 #ifdef CONFIG_CIFS_STATS2
44025 seq_printf(m, "Total Large %d Small %d Allocations\n",
44026- atomic_read(&totBufAllocCount),
44027- atomic_read(&totSmBufAllocCount));
44028+ atomic_read_unchecked(&totBufAllocCount),
44029+ atomic_read_unchecked(&totSmBufAllocCount));
44030 #endif /* CONFIG_CIFS_STATS2 */
44031
44032 seq_printf(m, "Operations (MIDs): %d\n", atomic_read(&midCount));
44033@@ -343,7 +343,7 @@ static int cifs_stats_proc_show(struct seq_file *m, void *v)
44034 if (tcon->need_reconnect)
44035 seq_puts(m, "\tDISCONNECTED ");
44036 seq_printf(m, "\nSMBs: %d",
44037- atomic_read(&tcon->num_smbs_sent));
44038+ atomic_read_unchecked(&tcon->num_smbs_sent));
44039 if (server->ops->print_stats)
44040 server->ops->print_stats(m, tcon);
44041 }
44042diff --git a/fs/cifs/cifsfs.c b/fs/cifs/cifsfs.c
44043index db8a404..c712e2e 100644
44044--- a/fs/cifs/cifsfs.c
44045+++ b/fs/cifs/cifsfs.c
44046@@ -1003,7 +1003,7 @@ cifs_init_request_bufs(void)
44047 /* cERROR(1, "CIFSMaxBufSize %d 0x%x",CIFSMaxBufSize,CIFSMaxBufSize); */
44048 cifs_req_cachep = kmem_cache_create("cifs_request",
44049 CIFSMaxBufSize + max_hdr_size, 0,
44050- SLAB_HWCACHE_ALIGN, NULL);
44051+ SLAB_HWCACHE_ALIGN | SLAB_USERCOPY, NULL);
44052 if (cifs_req_cachep == NULL)
44053 return -ENOMEM;
44054
44055@@ -1030,7 +1030,7 @@ cifs_init_request_bufs(void)
44056 efficient to alloc 1 per page off the slab compared to 17K (5page)
44057 alloc of large cifs buffers even when page debugging is on */
44058 cifs_sm_req_cachep = kmem_cache_create("cifs_small_rq",
44059- MAX_CIFS_SMALL_BUFFER_SIZE, 0, SLAB_HWCACHE_ALIGN,
44060+ MAX_CIFS_SMALL_BUFFER_SIZE, 0, SLAB_HWCACHE_ALIGN | SLAB_USERCOPY,
44061 NULL);
44062 if (cifs_sm_req_cachep == NULL) {
44063 mempool_destroy(cifs_req_poolp);
44064@@ -1115,8 +1115,8 @@ init_cifs(void)
44065 atomic_set(&bufAllocCount, 0);
44066 atomic_set(&smBufAllocCount, 0);
44067 #ifdef CONFIG_CIFS_STATS2
44068- atomic_set(&totBufAllocCount, 0);
44069- atomic_set(&totSmBufAllocCount, 0);
44070+ atomic_set_unchecked(&totBufAllocCount, 0);
44071+ atomic_set_unchecked(&totSmBufAllocCount, 0);
44072 #endif /* CONFIG_CIFS_STATS2 */
44073
44074 atomic_set(&midCount, 0);
44075diff --git a/fs/cifs/cifsglob.h b/fs/cifs/cifsglob.h
44076index 977dc0e..ba48ab9 100644
44077--- a/fs/cifs/cifsglob.h
44078+++ b/fs/cifs/cifsglob.h
44079@@ -590,35 +590,35 @@ struct cifs_tcon {
44080 __u16 Flags; /* optional support bits */
44081 enum statusEnum tidStatus;
44082 #ifdef CONFIG_CIFS_STATS
44083- atomic_t num_smbs_sent;
44084+ atomic_unchecked_t num_smbs_sent;
44085 union {
44086 struct {
44087- atomic_t num_writes;
44088- atomic_t num_reads;
44089- atomic_t num_flushes;
44090- atomic_t num_oplock_brks;
44091- atomic_t num_opens;
44092- atomic_t num_closes;
44093- atomic_t num_deletes;
44094- atomic_t num_mkdirs;
44095- atomic_t num_posixopens;
44096- atomic_t num_posixmkdirs;
44097- atomic_t num_rmdirs;
44098- atomic_t num_renames;
44099- atomic_t num_t2renames;
44100- atomic_t num_ffirst;
44101- atomic_t num_fnext;
44102- atomic_t num_fclose;
44103- atomic_t num_hardlinks;
44104- atomic_t num_symlinks;
44105- atomic_t num_locks;
44106- atomic_t num_acl_get;
44107- atomic_t num_acl_set;
44108+ atomic_unchecked_t num_writes;
44109+ atomic_unchecked_t num_reads;
44110+ atomic_unchecked_t num_flushes;
44111+ atomic_unchecked_t num_oplock_brks;
44112+ atomic_unchecked_t num_opens;
44113+ atomic_unchecked_t num_closes;
44114+ atomic_unchecked_t num_deletes;
44115+ atomic_unchecked_t num_mkdirs;
44116+ atomic_unchecked_t num_posixopens;
44117+ atomic_unchecked_t num_posixmkdirs;
44118+ atomic_unchecked_t num_rmdirs;
44119+ atomic_unchecked_t num_renames;
44120+ atomic_unchecked_t num_t2renames;
44121+ atomic_unchecked_t num_ffirst;
44122+ atomic_unchecked_t num_fnext;
44123+ atomic_unchecked_t num_fclose;
44124+ atomic_unchecked_t num_hardlinks;
44125+ atomic_unchecked_t num_symlinks;
44126+ atomic_unchecked_t num_locks;
44127+ atomic_unchecked_t num_acl_get;
44128+ atomic_unchecked_t num_acl_set;
44129 } cifs_stats;
44130 #ifdef CONFIG_CIFS_SMB2
44131 struct {
44132- atomic_t smb2_com_sent[NUMBER_OF_SMB2_COMMANDS];
44133- atomic_t smb2_com_failed[NUMBER_OF_SMB2_COMMANDS];
44134+ atomic_unchecked_t smb2_com_sent[NUMBER_OF_SMB2_COMMANDS];
44135+ atomic_unchecked_t smb2_com_failed[NUMBER_OF_SMB2_COMMANDS];
44136 } smb2_stats;
44137 #endif /* CONFIG_CIFS_SMB2 */
44138 } stats;
44139@@ -862,7 +862,7 @@ build_path_to_root(struct smb_vol *vol, struct cifs_sb_info *cifs_sb,
44140 }
44141
44142 #ifdef CONFIG_CIFS_STATS
44143-#define cifs_stats_inc atomic_inc
44144+#define cifs_stats_inc atomic_inc_unchecked
44145
44146 static inline void cifs_stats_bytes_written(struct cifs_tcon *tcon,
44147 unsigned int bytes)
44148@@ -1227,8 +1227,8 @@ GLOBAL_EXTERN atomic_t tconInfoReconnectCount;
44149 /* Various Debug counters */
44150 GLOBAL_EXTERN atomic_t bufAllocCount; /* current number allocated */
44151 #ifdef CONFIG_CIFS_STATS2
44152-GLOBAL_EXTERN atomic_t totBufAllocCount; /* total allocated over all time */
44153-GLOBAL_EXTERN atomic_t totSmBufAllocCount;
44154+GLOBAL_EXTERN atomic_unchecked_t totBufAllocCount; /* total allocated over all time */
44155+GLOBAL_EXTERN atomic_unchecked_t totSmBufAllocCount;
44156 #endif
44157 GLOBAL_EXTERN atomic_t smBufAllocCount;
44158 GLOBAL_EXTERN atomic_t midCount;
44159diff --git a/fs/cifs/link.c b/fs/cifs/link.c
44160index e6ce3b1..adc21fd 100644
44161--- a/fs/cifs/link.c
44162+++ b/fs/cifs/link.c
44163@@ -602,7 +602,7 @@ symlink_exit:
44164
44165 void cifs_put_link(struct dentry *direntry, struct nameidata *nd, void *cookie)
44166 {
44167- char *p = nd_get_link(nd);
44168+ const char *p = nd_get_link(nd);
44169 if (!IS_ERR(p))
44170 kfree(p);
44171 }
44172diff --git a/fs/cifs/misc.c b/fs/cifs/misc.c
44173index ce41fee..ac0d27a 100644
44174--- a/fs/cifs/misc.c
44175+++ b/fs/cifs/misc.c
44176@@ -169,7 +169,7 @@ cifs_buf_get(void)
44177 memset(ret_buf, 0, buf_size + 3);
44178 atomic_inc(&bufAllocCount);
44179 #ifdef CONFIG_CIFS_STATS2
44180- atomic_inc(&totBufAllocCount);
44181+ atomic_inc_unchecked(&totBufAllocCount);
44182 #endif /* CONFIG_CIFS_STATS2 */
44183 }
44184
44185@@ -204,7 +204,7 @@ cifs_small_buf_get(void)
44186 /* memset(ret_buf, 0, sizeof(struct smb_hdr) + 27);*/
44187 atomic_inc(&smBufAllocCount);
44188 #ifdef CONFIG_CIFS_STATS2
44189- atomic_inc(&totSmBufAllocCount);
44190+ atomic_inc_unchecked(&totSmBufAllocCount);
44191 #endif /* CONFIG_CIFS_STATS2 */
44192
44193 }
44194diff --git a/fs/cifs/smb1ops.c b/fs/cifs/smb1ops.c
44195index 3129ac7..cc4a948 100644
44196--- a/fs/cifs/smb1ops.c
44197+++ b/fs/cifs/smb1ops.c
44198@@ -524,27 +524,27 @@ static void
44199 cifs_clear_stats(struct cifs_tcon *tcon)
44200 {
44201 #ifdef CONFIG_CIFS_STATS
44202- atomic_set(&tcon->stats.cifs_stats.num_writes, 0);
44203- atomic_set(&tcon->stats.cifs_stats.num_reads, 0);
44204- atomic_set(&tcon->stats.cifs_stats.num_flushes, 0);
44205- atomic_set(&tcon->stats.cifs_stats.num_oplock_brks, 0);
44206- atomic_set(&tcon->stats.cifs_stats.num_opens, 0);
44207- atomic_set(&tcon->stats.cifs_stats.num_posixopens, 0);
44208- atomic_set(&tcon->stats.cifs_stats.num_posixmkdirs, 0);
44209- atomic_set(&tcon->stats.cifs_stats.num_closes, 0);
44210- atomic_set(&tcon->stats.cifs_stats.num_deletes, 0);
44211- atomic_set(&tcon->stats.cifs_stats.num_mkdirs, 0);
44212- atomic_set(&tcon->stats.cifs_stats.num_rmdirs, 0);
44213- atomic_set(&tcon->stats.cifs_stats.num_renames, 0);
44214- atomic_set(&tcon->stats.cifs_stats.num_t2renames, 0);
44215- atomic_set(&tcon->stats.cifs_stats.num_ffirst, 0);
44216- atomic_set(&tcon->stats.cifs_stats.num_fnext, 0);
44217- atomic_set(&tcon->stats.cifs_stats.num_fclose, 0);
44218- atomic_set(&tcon->stats.cifs_stats.num_hardlinks, 0);
44219- atomic_set(&tcon->stats.cifs_stats.num_symlinks, 0);
44220- atomic_set(&tcon->stats.cifs_stats.num_locks, 0);
44221- atomic_set(&tcon->stats.cifs_stats.num_acl_get, 0);
44222- atomic_set(&tcon->stats.cifs_stats.num_acl_set, 0);
44223+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_writes, 0);
44224+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_reads, 0);
44225+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_flushes, 0);
44226+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_oplock_brks, 0);
44227+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_opens, 0);
44228+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_posixopens, 0);
44229+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_posixmkdirs, 0);
44230+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_closes, 0);
44231+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_deletes, 0);
44232+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_mkdirs, 0);
44233+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_rmdirs, 0);
44234+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_renames, 0);
44235+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_t2renames, 0);
44236+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_ffirst, 0);
44237+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_fnext, 0);
44238+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_fclose, 0);
44239+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_hardlinks, 0);
44240+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_symlinks, 0);
44241+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_locks, 0);
44242+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_acl_get, 0);
44243+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_acl_set, 0);
44244 #endif
44245 }
44246
44247@@ -553,36 +553,36 @@ cifs_print_stats(struct seq_file *m, struct cifs_tcon *tcon)
44248 {
44249 #ifdef CONFIG_CIFS_STATS
44250 seq_printf(m, " Oplocks breaks: %d",
44251- atomic_read(&tcon->stats.cifs_stats.num_oplock_brks));
44252+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_oplock_brks));
44253 seq_printf(m, "\nReads: %d Bytes: %llu",
44254- atomic_read(&tcon->stats.cifs_stats.num_reads),
44255+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_reads),
44256 (long long)(tcon->bytes_read));
44257 seq_printf(m, "\nWrites: %d Bytes: %llu",
44258- atomic_read(&tcon->stats.cifs_stats.num_writes),
44259+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_writes),
44260 (long long)(tcon->bytes_written));
44261 seq_printf(m, "\nFlushes: %d",
44262- atomic_read(&tcon->stats.cifs_stats.num_flushes));
44263+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_flushes));
44264 seq_printf(m, "\nLocks: %d HardLinks: %d Symlinks: %d",
44265- atomic_read(&tcon->stats.cifs_stats.num_locks),
44266- atomic_read(&tcon->stats.cifs_stats.num_hardlinks),
44267- atomic_read(&tcon->stats.cifs_stats.num_symlinks));
44268+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_locks),
44269+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_hardlinks),
44270+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_symlinks));
44271 seq_printf(m, "\nOpens: %d Closes: %d Deletes: %d",
44272- atomic_read(&tcon->stats.cifs_stats.num_opens),
44273- atomic_read(&tcon->stats.cifs_stats.num_closes),
44274- atomic_read(&tcon->stats.cifs_stats.num_deletes));
44275+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_opens),
44276+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_closes),
44277+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_deletes));
44278 seq_printf(m, "\nPosix Opens: %d Posix Mkdirs: %d",
44279- atomic_read(&tcon->stats.cifs_stats.num_posixopens),
44280- atomic_read(&tcon->stats.cifs_stats.num_posixmkdirs));
44281+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_posixopens),
44282+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_posixmkdirs));
44283 seq_printf(m, "\nMkdirs: %d Rmdirs: %d",
44284- atomic_read(&tcon->stats.cifs_stats.num_mkdirs),
44285- atomic_read(&tcon->stats.cifs_stats.num_rmdirs));
44286+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_mkdirs),
44287+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_rmdirs));
44288 seq_printf(m, "\nRenames: %d T2 Renames %d",
44289- atomic_read(&tcon->stats.cifs_stats.num_renames),
44290- atomic_read(&tcon->stats.cifs_stats.num_t2renames));
44291+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_renames),
44292+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_t2renames));
44293 seq_printf(m, "\nFindFirst: %d FNext %d FClose %d",
44294- atomic_read(&tcon->stats.cifs_stats.num_ffirst),
44295- atomic_read(&tcon->stats.cifs_stats.num_fnext),
44296- atomic_read(&tcon->stats.cifs_stats.num_fclose));
44297+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_ffirst),
44298+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_fnext),
44299+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_fclose));
44300 #endif
44301 }
44302
44303diff --git a/fs/cifs/smb2ops.c b/fs/cifs/smb2ops.c
44304index 826209b..fa460f4 100644
44305--- a/fs/cifs/smb2ops.c
44306+++ b/fs/cifs/smb2ops.c
44307@@ -219,8 +219,8 @@ smb2_clear_stats(struct cifs_tcon *tcon)
44308 #ifdef CONFIG_CIFS_STATS
44309 int i;
44310 for (i = 0; i < NUMBER_OF_SMB2_COMMANDS; i++) {
44311- atomic_set(&tcon->stats.smb2_stats.smb2_com_sent[i], 0);
44312- atomic_set(&tcon->stats.smb2_stats.smb2_com_failed[i], 0);
44313+ atomic_set_unchecked(&tcon->stats.smb2_stats.smb2_com_sent[i], 0);
44314+ atomic_set_unchecked(&tcon->stats.smb2_stats.smb2_com_failed[i], 0);
44315 }
44316 #endif
44317 }
44318@@ -229,66 +229,66 @@ static void
44319 smb2_print_stats(struct seq_file *m, struct cifs_tcon *tcon)
44320 {
44321 #ifdef CONFIG_CIFS_STATS
44322- atomic_t *sent = tcon->stats.smb2_stats.smb2_com_sent;
44323- atomic_t *failed = tcon->stats.smb2_stats.smb2_com_failed;
44324+ atomic_unchecked_t *sent = tcon->stats.smb2_stats.smb2_com_sent;
44325+ atomic_unchecked_t *failed = tcon->stats.smb2_stats.smb2_com_failed;
44326 seq_printf(m, "\nNegotiates: %d sent %d failed",
44327- atomic_read(&sent[SMB2_NEGOTIATE_HE]),
44328- atomic_read(&failed[SMB2_NEGOTIATE_HE]));
44329+ atomic_read_unchecked(&sent[SMB2_NEGOTIATE_HE]),
44330+ atomic_read_unchecked(&failed[SMB2_NEGOTIATE_HE]));
44331 seq_printf(m, "\nSessionSetups: %d sent %d failed",
44332- atomic_read(&sent[SMB2_SESSION_SETUP_HE]),
44333- atomic_read(&failed[SMB2_SESSION_SETUP_HE]));
44334+ atomic_read_unchecked(&sent[SMB2_SESSION_SETUP_HE]),
44335+ atomic_read_unchecked(&failed[SMB2_SESSION_SETUP_HE]));
44336 #define SMB2LOGOFF 0x0002 /* trivial request/resp */
44337 seq_printf(m, "\nLogoffs: %d sent %d failed",
44338- atomic_read(&sent[SMB2_LOGOFF_HE]),
44339- atomic_read(&failed[SMB2_LOGOFF_HE]));
44340+ atomic_read_unchecked(&sent[SMB2_LOGOFF_HE]),
44341+ atomic_read_unchecked(&failed[SMB2_LOGOFF_HE]));
44342 seq_printf(m, "\nTreeConnects: %d sent %d failed",
44343- atomic_read(&sent[SMB2_TREE_CONNECT_HE]),
44344- atomic_read(&failed[SMB2_TREE_CONNECT_HE]));
44345+ atomic_read_unchecked(&sent[SMB2_TREE_CONNECT_HE]),
44346+ atomic_read_unchecked(&failed[SMB2_TREE_CONNECT_HE]));
44347 seq_printf(m, "\nTreeDisconnects: %d sent %d failed",
44348- atomic_read(&sent[SMB2_TREE_DISCONNECT_HE]),
44349- atomic_read(&failed[SMB2_TREE_DISCONNECT_HE]));
44350+ atomic_read_unchecked(&sent[SMB2_TREE_DISCONNECT_HE]),
44351+ atomic_read_unchecked(&failed[SMB2_TREE_DISCONNECT_HE]));
44352 seq_printf(m, "\nCreates: %d sent %d failed",
44353- atomic_read(&sent[SMB2_CREATE_HE]),
44354- atomic_read(&failed[SMB2_CREATE_HE]));
44355+ atomic_read_unchecked(&sent[SMB2_CREATE_HE]),
44356+ atomic_read_unchecked(&failed[SMB2_CREATE_HE]));
44357 seq_printf(m, "\nCloses: %d sent %d failed",
44358- atomic_read(&sent[SMB2_CLOSE_HE]),
44359- atomic_read(&failed[SMB2_CLOSE_HE]));
44360+ atomic_read_unchecked(&sent[SMB2_CLOSE_HE]),
44361+ atomic_read_unchecked(&failed[SMB2_CLOSE_HE]));
44362 seq_printf(m, "\nFlushes: %d sent %d failed",
44363- atomic_read(&sent[SMB2_FLUSH_HE]),
44364- atomic_read(&failed[SMB2_FLUSH_HE]));
44365+ atomic_read_unchecked(&sent[SMB2_FLUSH_HE]),
44366+ atomic_read_unchecked(&failed[SMB2_FLUSH_HE]));
44367 seq_printf(m, "\nReads: %d sent %d failed",
44368- atomic_read(&sent[SMB2_READ_HE]),
44369- atomic_read(&failed[SMB2_READ_HE]));
44370+ atomic_read_unchecked(&sent[SMB2_READ_HE]),
44371+ atomic_read_unchecked(&failed[SMB2_READ_HE]));
44372 seq_printf(m, "\nWrites: %d sent %d failed",
44373- atomic_read(&sent[SMB2_WRITE_HE]),
44374- atomic_read(&failed[SMB2_WRITE_HE]));
44375+ atomic_read_unchecked(&sent[SMB2_WRITE_HE]),
44376+ atomic_read_unchecked(&failed[SMB2_WRITE_HE]));
44377 seq_printf(m, "\nLocks: %d sent %d failed",
44378- atomic_read(&sent[SMB2_LOCK_HE]),
44379- atomic_read(&failed[SMB2_LOCK_HE]));
44380+ atomic_read_unchecked(&sent[SMB2_LOCK_HE]),
44381+ atomic_read_unchecked(&failed[SMB2_LOCK_HE]));
44382 seq_printf(m, "\nIOCTLs: %d sent %d failed",
44383- atomic_read(&sent[SMB2_IOCTL_HE]),
44384- atomic_read(&failed[SMB2_IOCTL_HE]));
44385+ atomic_read_unchecked(&sent[SMB2_IOCTL_HE]),
44386+ atomic_read_unchecked(&failed[SMB2_IOCTL_HE]));
44387 seq_printf(m, "\nCancels: %d sent %d failed",
44388- atomic_read(&sent[SMB2_CANCEL_HE]),
44389- atomic_read(&failed[SMB2_CANCEL_HE]));
44390+ atomic_read_unchecked(&sent[SMB2_CANCEL_HE]),
44391+ atomic_read_unchecked(&failed[SMB2_CANCEL_HE]));
44392 seq_printf(m, "\nEchos: %d sent %d failed",
44393- atomic_read(&sent[SMB2_ECHO_HE]),
44394- atomic_read(&failed[SMB2_ECHO_HE]));
44395+ atomic_read_unchecked(&sent[SMB2_ECHO_HE]),
44396+ atomic_read_unchecked(&failed[SMB2_ECHO_HE]));
44397 seq_printf(m, "\nQueryDirectories: %d sent %d failed",
44398- atomic_read(&sent[SMB2_QUERY_DIRECTORY_HE]),
44399- atomic_read(&failed[SMB2_QUERY_DIRECTORY_HE]));
44400+ atomic_read_unchecked(&sent[SMB2_QUERY_DIRECTORY_HE]),
44401+ atomic_read_unchecked(&failed[SMB2_QUERY_DIRECTORY_HE]));
44402 seq_printf(m, "\nChangeNotifies: %d sent %d failed",
44403- atomic_read(&sent[SMB2_CHANGE_NOTIFY_HE]),
44404- atomic_read(&failed[SMB2_CHANGE_NOTIFY_HE]));
44405+ atomic_read_unchecked(&sent[SMB2_CHANGE_NOTIFY_HE]),
44406+ atomic_read_unchecked(&failed[SMB2_CHANGE_NOTIFY_HE]));
44407 seq_printf(m, "\nQueryInfos: %d sent %d failed",
44408- atomic_read(&sent[SMB2_QUERY_INFO_HE]),
44409- atomic_read(&failed[SMB2_QUERY_INFO_HE]));
44410+ atomic_read_unchecked(&sent[SMB2_QUERY_INFO_HE]),
44411+ atomic_read_unchecked(&failed[SMB2_QUERY_INFO_HE]));
44412 seq_printf(m, "\nSetInfos: %d sent %d failed",
44413- atomic_read(&sent[SMB2_SET_INFO_HE]),
44414- atomic_read(&failed[SMB2_SET_INFO_HE]));
44415+ atomic_read_unchecked(&sent[SMB2_SET_INFO_HE]),
44416+ atomic_read_unchecked(&failed[SMB2_SET_INFO_HE]));
44417 seq_printf(m, "\nOplockBreaks: %d sent %d failed",
44418- atomic_read(&sent[SMB2_OPLOCK_BREAK_HE]),
44419- atomic_read(&failed[SMB2_OPLOCK_BREAK_HE]));
44420+ atomic_read_unchecked(&sent[SMB2_OPLOCK_BREAK_HE]),
44421+ atomic_read_unchecked(&failed[SMB2_OPLOCK_BREAK_HE]));
44422 #endif
44423 }
44424
44425diff --git a/fs/coda/cache.c b/fs/coda/cache.c
44426index 958ae0e..505c9d0 100644
44427--- a/fs/coda/cache.c
44428+++ b/fs/coda/cache.c
44429@@ -24,7 +24,7 @@
44430 #include "coda_linux.h"
44431 #include "coda_cache.h"
44432
44433-static atomic_t permission_epoch = ATOMIC_INIT(0);
44434+static atomic_unchecked_t permission_epoch = ATOMIC_INIT(0);
44435
44436 /* replace or extend an acl cache hit */
44437 void coda_cache_enter(struct inode *inode, int mask)
44438@@ -32,7 +32,7 @@ void coda_cache_enter(struct inode *inode, int mask)
44439 struct coda_inode_info *cii = ITOC(inode);
44440
44441 spin_lock(&cii->c_lock);
44442- cii->c_cached_epoch = atomic_read(&permission_epoch);
44443+ cii->c_cached_epoch = atomic_read_unchecked(&permission_epoch);
44444 if (cii->c_uid != current_fsuid()) {
44445 cii->c_uid = current_fsuid();
44446 cii->c_cached_perm = mask;
44447@@ -46,14 +46,14 @@ void coda_cache_clear_inode(struct inode *inode)
44448 {
44449 struct coda_inode_info *cii = ITOC(inode);
44450 spin_lock(&cii->c_lock);
44451- cii->c_cached_epoch = atomic_read(&permission_epoch) - 1;
44452+ cii->c_cached_epoch = atomic_read_unchecked(&permission_epoch) - 1;
44453 spin_unlock(&cii->c_lock);
44454 }
44455
44456 /* remove all acl caches */
44457 void coda_cache_clear_all(struct super_block *sb)
44458 {
44459- atomic_inc(&permission_epoch);
44460+ atomic_inc_unchecked(&permission_epoch);
44461 }
44462
44463
44464@@ -66,7 +66,7 @@ int coda_cache_check(struct inode *inode, int mask)
44465 spin_lock(&cii->c_lock);
44466 hit = (mask & cii->c_cached_perm) == mask &&
44467 cii->c_uid == current_fsuid() &&
44468- cii->c_cached_epoch == atomic_read(&permission_epoch);
44469+ cii->c_cached_epoch == atomic_read_unchecked(&permission_epoch);
44470 spin_unlock(&cii->c_lock);
44471
44472 return hit;
44473diff --git a/fs/compat.c b/fs/compat.c
44474index 1bdb350..9f28287 100644
44475--- a/fs/compat.c
44476+++ b/fs/compat.c
44477@@ -490,7 +490,7 @@ compat_sys_io_setup(unsigned nr_reqs, u32 __user *ctx32p)
44478
44479 set_fs(KERNEL_DS);
44480 /* The __user pointer cast is valid because of the set_fs() */
44481- ret = sys_io_setup(nr_reqs, (aio_context_t __user *) &ctx64);
44482+ ret = sys_io_setup(nr_reqs, (aio_context_t __force_user *) &ctx64);
44483 set_fs(oldfs);
44484 /* truncating is ok because it's a user address */
44485 if (!ret)
44486@@ -548,7 +548,7 @@ ssize_t compat_rw_copy_check_uvector(int type,
44487 goto out;
44488
44489 ret = -EINVAL;
44490- if (nr_segs > UIO_MAXIOV || nr_segs < 0)
44491+ if (nr_segs > UIO_MAXIOV)
44492 goto out;
44493 if (nr_segs > fast_segs) {
44494 ret = -ENOMEM;
44495@@ -831,6 +831,7 @@ struct compat_old_linux_dirent {
44496
44497 struct compat_readdir_callback {
44498 struct compat_old_linux_dirent __user *dirent;
44499+ struct file * file;
44500 int result;
44501 };
44502
44503@@ -848,6 +849,10 @@ static int compat_fillonedir(void *__buf, const char *name, int namlen,
44504 buf->result = -EOVERFLOW;
44505 return -EOVERFLOW;
44506 }
44507+
44508+ if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
44509+ return 0;
44510+
44511 buf->result++;
44512 dirent = buf->dirent;
44513 if (!access_ok(VERIFY_WRITE, dirent,
44514@@ -880,6 +885,7 @@ asmlinkage long compat_sys_old_readdir(unsigned int fd,
44515
44516 buf.result = 0;
44517 buf.dirent = dirent;
44518+ buf.file = file;
44519
44520 error = vfs_readdir(file, compat_fillonedir, &buf);
44521 if (buf.result)
44522@@ -899,6 +905,7 @@ struct compat_linux_dirent {
44523 struct compat_getdents_callback {
44524 struct compat_linux_dirent __user *current_dir;
44525 struct compat_linux_dirent __user *previous;
44526+ struct file * file;
44527 int count;
44528 int error;
44529 };
44530@@ -920,6 +927,10 @@ static int compat_filldir(void *__buf, const char *name, int namlen,
44531 buf->error = -EOVERFLOW;
44532 return -EOVERFLOW;
44533 }
44534+
44535+ if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
44536+ return 0;
44537+
44538 dirent = buf->previous;
44539 if (dirent) {
44540 if (__put_user(offset, &dirent->d_off))
44541@@ -966,6 +977,7 @@ asmlinkage long compat_sys_getdents(unsigned int fd,
44542 buf.previous = NULL;
44543 buf.count = count;
44544 buf.error = 0;
44545+ buf.file = file;
44546
44547 error = vfs_readdir(file, compat_filldir, &buf);
44548 if (error >= 0)
44549@@ -986,6 +998,7 @@ asmlinkage long compat_sys_getdents(unsigned int fd,
44550 struct compat_getdents_callback64 {
44551 struct linux_dirent64 __user *current_dir;
44552 struct linux_dirent64 __user *previous;
44553+ struct file * file;
44554 int count;
44555 int error;
44556 };
44557@@ -1002,6 +1015,10 @@ static int compat_filldir64(void * __buf, const char * name, int namlen, loff_t
44558 buf->error = -EINVAL; /* only used if we fail.. */
44559 if (reclen > buf->count)
44560 return -EINVAL;
44561+
44562+ if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
44563+ return 0;
44564+
44565 dirent = buf->previous;
44566
44567 if (dirent) {
44568@@ -1052,13 +1069,14 @@ asmlinkage long compat_sys_getdents64(unsigned int fd,
44569 buf.previous = NULL;
44570 buf.count = count;
44571 buf.error = 0;
44572+ buf.file = file;
44573
44574 error = vfs_readdir(file, compat_filldir64, &buf);
44575 if (error >= 0)
44576 error = buf.error;
44577 lastdirent = buf.previous;
44578 if (lastdirent) {
44579- typeof(lastdirent->d_off) d_off = file->f_pos;
44580+ typeof(((struct linux_dirent64 *)0)->d_off) d_off = file->f_pos;
44581 if (__put_user_unaligned(d_off, &lastdirent->d_off))
44582 error = -EFAULT;
44583 else
44584diff --git a/fs/compat_binfmt_elf.c b/fs/compat_binfmt_elf.c
44585index 112e45a..b59845b 100644
44586--- a/fs/compat_binfmt_elf.c
44587+++ b/fs/compat_binfmt_elf.c
44588@@ -30,11 +30,13 @@
44589 #undef elf_phdr
44590 #undef elf_shdr
44591 #undef elf_note
44592+#undef elf_dyn
44593 #undef elf_addr_t
44594 #define elfhdr elf32_hdr
44595 #define elf_phdr elf32_phdr
44596 #define elf_shdr elf32_shdr
44597 #define elf_note elf32_note
44598+#define elf_dyn Elf32_Dyn
44599 #define elf_addr_t Elf32_Addr
44600
44601 /*
44602diff --git a/fs/compat_ioctl.c b/fs/compat_ioctl.c
44603index debdfe0..75d31d4 100644
44604--- a/fs/compat_ioctl.c
44605+++ b/fs/compat_ioctl.c
44606@@ -210,6 +210,8 @@ static int do_video_set_spu_palette(unsigned int fd, unsigned int cmd,
44607
44608 err = get_user(palp, &up->palette);
44609 err |= get_user(length, &up->length);
44610+ if (err)
44611+ return -EFAULT;
44612
44613 up_native = compat_alloc_user_space(sizeof(struct video_spu_palette));
44614 err = put_user(compat_ptr(palp), &up_native->palette);
44615@@ -621,7 +623,7 @@ static int serial_struct_ioctl(unsigned fd, unsigned cmd,
44616 return -EFAULT;
44617 if (__get_user(udata, &ss32->iomem_base))
44618 return -EFAULT;
44619- ss.iomem_base = compat_ptr(udata);
44620+ ss.iomem_base = (unsigned char __force_kernel *)compat_ptr(udata);
44621 if (__get_user(ss.iomem_reg_shift, &ss32->iomem_reg_shift) ||
44622 __get_user(ss.port_high, &ss32->port_high))
44623 return -EFAULT;
44624@@ -796,7 +798,7 @@ static int compat_ioctl_preallocate(struct file *file,
44625 copy_in_user(&p->l_len, &p32->l_len, sizeof(s64)) ||
44626 copy_in_user(&p->l_sysid, &p32->l_sysid, sizeof(s32)) ||
44627 copy_in_user(&p->l_pid, &p32->l_pid, sizeof(u32)) ||
44628- copy_in_user(&p->l_pad, &p32->l_pad, 4*sizeof(u32)))
44629+ copy_in_user(p->l_pad, &p32->l_pad, 4*sizeof(u32)))
44630 return -EFAULT;
44631
44632 return ioctl_preallocate(file, p);
44633@@ -1610,8 +1612,8 @@ asmlinkage long compat_sys_ioctl(unsigned int fd, unsigned int cmd,
44634 static int __init init_sys32_ioctl_cmp(const void *p, const void *q)
44635 {
44636 unsigned int a, b;
44637- a = *(unsigned int *)p;
44638- b = *(unsigned int *)q;
44639+ a = *(const unsigned int *)p;
44640+ b = *(const unsigned int *)q;
44641 if (a > b)
44642 return 1;
44643 if (a < b)
44644diff --git a/fs/configfs/dir.c b/fs/configfs/dir.c
44645index 7414ae2..d98ad6d 100644
44646--- a/fs/configfs/dir.c
44647+++ b/fs/configfs/dir.c
44648@@ -1564,7 +1564,8 @@ static int configfs_readdir(struct file * filp, void * dirent, filldir_t filldir
44649 }
44650 for (p=q->next; p!= &parent_sd->s_children; p=p->next) {
44651 struct configfs_dirent *next;
44652- const char * name;
44653+ const unsigned char * name;
44654+ char d_name[sizeof(next->s_dentry->d_iname)];
44655 int len;
44656 struct inode *inode = NULL;
44657
44658@@ -1574,7 +1575,12 @@ static int configfs_readdir(struct file * filp, void * dirent, filldir_t filldir
44659 continue;
44660
44661 name = configfs_get_name(next);
44662- len = strlen(name);
44663+ if (next->s_dentry && name == next->s_dentry->d_iname) {
44664+ len = next->s_dentry->d_name.len;
44665+ memcpy(d_name, name, len);
44666+ name = d_name;
44667+ } else
44668+ len = strlen(name);
44669
44670 /*
44671 * We'll have a dentry and an inode for
44672diff --git a/fs/dcache.c b/fs/dcache.c
44673index 693f95b..95f1223 100644
44674--- a/fs/dcache.c
44675+++ b/fs/dcache.c
44676@@ -3164,7 +3164,7 @@ void __init vfs_caches_init(unsigned long mempages)
44677 mempages -= reserve;
44678
44679 names_cachep = kmem_cache_create("names_cache", PATH_MAX, 0,
44680- SLAB_HWCACHE_ALIGN|SLAB_PANIC, NULL);
44681+ SLAB_HWCACHE_ALIGN|SLAB_PANIC|SLAB_USERCOPY, NULL);
44682
44683 dcache_init();
44684 inode_init();
44685diff --git a/fs/debugfs/inode.c b/fs/debugfs/inode.c
44686index 4733eab..71ef6fa 100644
44687--- a/fs/debugfs/inode.c
44688+++ b/fs/debugfs/inode.c
44689@@ -406,7 +406,11 @@ EXPORT_SYMBOL_GPL(debugfs_create_file);
44690 */
44691 struct dentry *debugfs_create_dir(const char *name, struct dentry *parent)
44692 {
44693+#ifdef CONFIG_GRKERNSEC_SYSFS_RESTRICT
44694+ return __create_file(name, S_IFDIR | S_IRWXU,
44695+#else
44696 return __create_file(name, S_IFDIR | S_IRWXU | S_IRUGO | S_IXUGO,
44697+#endif
44698 parent, NULL, NULL);
44699 }
44700 EXPORT_SYMBOL_GPL(debugfs_create_dir);
44701diff --git a/fs/ecryptfs/inode.c b/fs/ecryptfs/inode.c
44702index cc7709e..7e7211f 100644
44703--- a/fs/ecryptfs/inode.c
44704+++ b/fs/ecryptfs/inode.c
44705@@ -674,7 +674,7 @@ static int ecryptfs_readlink_lower(struct dentry *dentry, char **buf,
44706 old_fs = get_fs();
44707 set_fs(get_ds());
44708 rc = lower_dentry->d_inode->i_op->readlink(lower_dentry,
44709- (char __user *)lower_buf,
44710+ (char __force_user *)lower_buf,
44711 PATH_MAX);
44712 set_fs(old_fs);
44713 if (rc < 0)
44714@@ -706,7 +706,7 @@ out:
44715 static void
44716 ecryptfs_put_link(struct dentry *dentry, struct nameidata *nd, void *ptr)
44717 {
44718- char *buf = nd_get_link(nd);
44719+ const char *buf = nd_get_link(nd);
44720 if (!IS_ERR(buf)) {
44721 /* Free the char* */
44722 kfree(buf);
44723diff --git a/fs/ecryptfs/miscdev.c b/fs/ecryptfs/miscdev.c
44724index 412e6ed..4292d22 100644
44725--- a/fs/ecryptfs/miscdev.c
44726+++ b/fs/ecryptfs/miscdev.c
44727@@ -315,7 +315,7 @@ check_list:
44728 goto out_unlock_msg_ctx;
44729 i = PKT_TYPE_SIZE + PKT_CTR_SIZE;
44730 if (msg_ctx->msg) {
44731- if (copy_to_user(&buf[i], packet_length, packet_length_size))
44732+ if (packet_length_size > sizeof(packet_length) || copy_to_user(&buf[i], packet_length, packet_length_size))
44733 goto out_unlock_msg_ctx;
44734 i += packet_length_size;
44735 if (copy_to_user(&buf[i], msg_ctx->msg, msg_ctx->msg_size))
44736diff --git a/fs/ecryptfs/read_write.c b/fs/ecryptfs/read_write.c
44737index b2a34a1..162fa69 100644
44738--- a/fs/ecryptfs/read_write.c
44739+++ b/fs/ecryptfs/read_write.c
44740@@ -48,7 +48,7 @@ int ecryptfs_write_lower(struct inode *ecryptfs_inode, char *data,
44741 return -EIO;
44742 fs_save = get_fs();
44743 set_fs(get_ds());
44744- rc = vfs_write(lower_file, data, size, &offset);
44745+ rc = vfs_write(lower_file, (const char __force_user *)data, size, &offset);
44746 set_fs(fs_save);
44747 mark_inode_dirty_sync(ecryptfs_inode);
44748 return rc;
44749@@ -244,7 +244,7 @@ int ecryptfs_read_lower(char *data, loff_t offset, size_t size,
44750 return -EIO;
44751 fs_save = get_fs();
44752 set_fs(get_ds());
44753- rc = vfs_read(lower_file, data, size, &offset);
44754+ rc = vfs_read(lower_file, (char __force_user *)data, size, &offset);
44755 set_fs(fs_save);
44756 return rc;
44757 }
44758diff --git a/fs/exec.c b/fs/exec.c
44759index 574cf4d..dfe774a 100644
44760--- a/fs/exec.c
44761+++ b/fs/exec.c
44762@@ -55,6 +55,15 @@
44763 #include <linux/pipe_fs_i.h>
44764 #include <linux/oom.h>
44765 #include <linux/compat.h>
44766+#include <linux/random.h>
44767+#include <linux/seq_file.h>
44768+
44769+#ifdef CONFIG_PAX_REFCOUNT
44770+#include <linux/kallsyms.h>
44771+#include <linux/kdebug.h>
44772+#endif
44773+
44774+#include <trace/events/fs.h>
44775
44776 #include <asm/uaccess.h>
44777 #include <asm/mmu_context.h>
44778@@ -66,6 +75,18 @@
44779
44780 #include <trace/events/sched.h>
44781
44782+#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
44783+void __weak pax_set_initial_flags(struct linux_binprm *bprm)
44784+{
44785+ 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");
44786+}
44787+#endif
44788+
44789+#ifdef CONFIG_PAX_HOOK_ACL_FLAGS
44790+void (*pax_set_initial_flags_func)(struct linux_binprm *bprm);
44791+EXPORT_SYMBOL(pax_set_initial_flags_func);
44792+#endif
44793+
44794 int core_uses_pid;
44795 char core_pattern[CORENAME_MAX_SIZE] = "core";
44796 unsigned int core_pipe_limit;
44797@@ -75,7 +96,7 @@ struct core_name {
44798 char *corename;
44799 int used, size;
44800 };
44801-static atomic_t call_count = ATOMIC_INIT(1);
44802+static atomic_unchecked_t call_count = ATOMIC_INIT(1);
44803
44804 /* The maximal length of core_pattern is also specified in sysctl.c */
44805
44806@@ -191,18 +212,10 @@ static struct page *get_arg_page(struct linux_binprm *bprm, unsigned long pos,
44807 int write)
44808 {
44809 struct page *page;
44810- int ret;
44811
44812-#ifdef CONFIG_STACK_GROWSUP
44813- if (write) {
44814- ret = expand_downwards(bprm->vma, pos);
44815- if (ret < 0)
44816- return NULL;
44817- }
44818-#endif
44819- ret = get_user_pages(current, bprm->mm, pos,
44820- 1, write, 1, &page, NULL);
44821- if (ret <= 0)
44822+ if (0 > expand_downwards(bprm->vma, pos))
44823+ return NULL;
44824+ if (0 >= get_user_pages(current, bprm->mm, pos, 1, write, 1, &page, NULL))
44825 return NULL;
44826
44827 if (write) {
44828@@ -218,6 +231,17 @@ static struct page *get_arg_page(struct linux_binprm *bprm, unsigned long pos,
44829 if (size <= ARG_MAX)
44830 return page;
44831
44832+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
44833+ // only allow 512KB for argv+env on suid/sgid binaries
44834+ // to prevent easy ASLR exhaustion
44835+ if (((bprm->cred->euid != current_euid()) ||
44836+ (bprm->cred->egid != current_egid())) &&
44837+ (size > (512 * 1024))) {
44838+ put_page(page);
44839+ return NULL;
44840+ }
44841+#endif
44842+
44843 /*
44844 * Limit to 1/4-th the stack size for the argv+env strings.
44845 * This ensures that:
44846@@ -277,6 +301,11 @@ static int __bprm_mm_init(struct linux_binprm *bprm)
44847 vma->vm_end = STACK_TOP_MAX;
44848 vma->vm_start = vma->vm_end - PAGE_SIZE;
44849 vma->vm_flags = VM_STACK_FLAGS | VM_STACK_INCOMPLETE_SETUP;
44850+
44851+#ifdef CONFIG_PAX_SEGMEXEC
44852+ vma->vm_flags &= ~(VM_EXEC | VM_MAYEXEC);
44853+#endif
44854+
44855 vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
44856 INIT_LIST_HEAD(&vma->anon_vma_chain);
44857
44858@@ -287,6 +316,12 @@ static int __bprm_mm_init(struct linux_binprm *bprm)
44859 mm->stack_vm = mm->total_vm = 1;
44860 up_write(&mm->mmap_sem);
44861 bprm->p = vma->vm_end - sizeof(void *);
44862+
44863+#ifdef CONFIG_PAX_RANDUSTACK
44864+ if (randomize_va_space)
44865+ bprm->p ^= random32() & ~PAGE_MASK;
44866+#endif
44867+
44868 return 0;
44869 err:
44870 up_write(&mm->mmap_sem);
44871@@ -395,19 +430,7 @@ err:
44872 return err;
44873 }
44874
44875-struct user_arg_ptr {
44876-#ifdef CONFIG_COMPAT
44877- bool is_compat;
44878-#endif
44879- union {
44880- const char __user *const __user *native;
44881-#ifdef CONFIG_COMPAT
44882- compat_uptr_t __user *compat;
44883-#endif
44884- } ptr;
44885-};
44886-
44887-static const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr)
44888+const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr)
44889 {
44890 const char __user *native;
44891
44892@@ -416,14 +439,14 @@ static const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr)
44893 compat_uptr_t compat;
44894
44895 if (get_user(compat, argv.ptr.compat + nr))
44896- return ERR_PTR(-EFAULT);
44897+ return (const char __force_user *)ERR_PTR(-EFAULT);
44898
44899 return compat_ptr(compat);
44900 }
44901 #endif
44902
44903 if (get_user(native, argv.ptr.native + nr))
44904- return ERR_PTR(-EFAULT);
44905+ return (const char __force_user *)ERR_PTR(-EFAULT);
44906
44907 return native;
44908 }
44909@@ -442,7 +465,7 @@ static int count(struct user_arg_ptr argv, int max)
44910 if (!p)
44911 break;
44912
44913- if (IS_ERR(p))
44914+ if (IS_ERR((const char __force_kernel *)p))
44915 return -EFAULT;
44916
44917 if (i++ >= max)
44918@@ -476,7 +499,7 @@ static int copy_strings(int argc, struct user_arg_ptr argv,
44919
44920 ret = -EFAULT;
44921 str = get_user_arg_ptr(argv, argc);
44922- if (IS_ERR(str))
44923+ if (IS_ERR((const char __force_kernel *)str))
44924 goto out;
44925
44926 len = strnlen_user(str, MAX_ARG_STRLEN);
44927@@ -558,7 +581,7 @@ int copy_strings_kernel(int argc, const char *const *__argv,
44928 int r;
44929 mm_segment_t oldfs = get_fs();
44930 struct user_arg_ptr argv = {
44931- .ptr.native = (const char __user *const __user *)__argv,
44932+ .ptr.native = (const char __force_user *const __force_user *)__argv,
44933 };
44934
44935 set_fs(KERNEL_DS);
44936@@ -593,7 +616,8 @@ static int shift_arg_pages(struct vm_area_struct *vma, unsigned long shift)
44937 unsigned long new_end = old_end - shift;
44938 struct mmu_gather tlb;
44939
44940- BUG_ON(new_start > new_end);
44941+ if (new_start >= new_end || new_start < mmap_min_addr)
44942+ return -ENOMEM;
44943
44944 /*
44945 * ensure there are no vmas between where we want to go
44946@@ -602,6 +626,10 @@ static int shift_arg_pages(struct vm_area_struct *vma, unsigned long shift)
44947 if (vma != find_vma(mm, new_start))
44948 return -EFAULT;
44949
44950+#ifdef CONFIG_PAX_SEGMEXEC
44951+ BUG_ON(pax_find_mirror_vma(vma));
44952+#endif
44953+
44954 /*
44955 * cover the whole range: [new_start, old_end)
44956 */
44957@@ -682,10 +710,6 @@ int setup_arg_pages(struct linux_binprm *bprm,
44958 stack_top = arch_align_stack(stack_top);
44959 stack_top = PAGE_ALIGN(stack_top);
44960
44961- if (unlikely(stack_top < mmap_min_addr) ||
44962- unlikely(vma->vm_end - vma->vm_start >= stack_top - mmap_min_addr))
44963- return -ENOMEM;
44964-
44965 stack_shift = vma->vm_end - stack_top;
44966
44967 bprm->p -= stack_shift;
44968@@ -697,8 +721,28 @@ int setup_arg_pages(struct linux_binprm *bprm,
44969 bprm->exec -= stack_shift;
44970
44971 down_write(&mm->mmap_sem);
44972+
44973+ /* Move stack pages down in memory. */
44974+ if (stack_shift) {
44975+ ret = shift_arg_pages(vma, stack_shift);
44976+ if (ret)
44977+ goto out_unlock;
44978+ }
44979+
44980 vm_flags = VM_STACK_FLAGS;
44981
44982+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
44983+ if (mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
44984+ vm_flags &= ~VM_EXEC;
44985+
44986+#ifdef CONFIG_PAX_MPROTECT
44987+ if (mm->pax_flags & MF_PAX_MPROTECT)
44988+ vm_flags &= ~VM_MAYEXEC;
44989+#endif
44990+
44991+ }
44992+#endif
44993+
44994 /*
44995 * Adjust stack execute permissions; explicitly enable for
44996 * EXSTACK_ENABLE_X, disable for EXSTACK_DISABLE_X and leave alone
44997@@ -717,13 +761,6 @@ int setup_arg_pages(struct linux_binprm *bprm,
44998 goto out_unlock;
44999 BUG_ON(prev != vma);
45000
45001- /* Move stack pages down in memory. */
45002- if (stack_shift) {
45003- ret = shift_arg_pages(vma, stack_shift);
45004- if (ret)
45005- goto out_unlock;
45006- }
45007-
45008 /* mprotect_fixup is overkill to remove the temporary stack flags */
45009 vma->vm_flags &= ~VM_STACK_INCOMPLETE_SETUP;
45010
45011@@ -781,6 +818,8 @@ struct file *open_exec(const char *name)
45012
45013 fsnotify_open(file);
45014
45015+ trace_open_exec(name);
45016+
45017 err = deny_write_access(file);
45018 if (err)
45019 goto exit;
45020@@ -804,7 +843,7 @@ int kernel_read(struct file *file, loff_t offset,
45021 old_fs = get_fs();
45022 set_fs(get_ds());
45023 /* The cast to a user pointer is valid due to the set_fs() */
45024- result = vfs_read(file, (void __user *)addr, count, &pos);
45025+ result = vfs_read(file, (void __force_user *)addr, count, &pos);
45026 set_fs(old_fs);
45027 return result;
45028 }
45029@@ -1257,7 +1296,7 @@ static int check_unsafe_exec(struct linux_binprm *bprm)
45030 }
45031 rcu_read_unlock();
45032
45033- if (p->fs->users > n_fs) {
45034+ if (atomic_read(&p->fs->users) > n_fs) {
45035 bprm->unsafe |= LSM_UNSAFE_SHARE;
45036 } else {
45037 res = -EAGAIN;
45038@@ -1460,6 +1499,28 @@ int search_binary_handler(struct linux_binprm *bprm,struct pt_regs *regs)
45039
45040 EXPORT_SYMBOL(search_binary_handler);
45041
45042+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
45043+static DEFINE_PER_CPU(u64, exec_counter);
45044+static int __init init_exec_counters(void)
45045+{
45046+ unsigned int cpu;
45047+
45048+ for_each_possible_cpu(cpu) {
45049+ per_cpu(exec_counter, cpu) = (u64)cpu;
45050+ }
45051+
45052+ return 0;
45053+}
45054+early_initcall(init_exec_counters);
45055+static inline void increment_exec_counter(void)
45056+{
45057+ BUILD_BUG_ON(NR_CPUS > (1 << 16));
45058+ current->exec_id = this_cpu_add_return(exec_counter, 1 << 16);
45059+}
45060+#else
45061+static inline void increment_exec_counter(void) {}
45062+#endif
45063+
45064 /*
45065 * sys_execve() executes a new program.
45066 */
45067@@ -1468,6 +1529,11 @@ static int do_execve_common(const char *filename,
45068 struct user_arg_ptr envp,
45069 struct pt_regs *regs)
45070 {
45071+#ifdef CONFIG_GRKERNSEC
45072+ struct file *old_exec_file;
45073+ struct acl_subject_label *old_acl;
45074+ struct rlimit old_rlim[RLIM_NLIMITS];
45075+#endif
45076 struct linux_binprm *bprm;
45077 struct file *file;
45078 struct files_struct *displaced;
45079@@ -1475,6 +1541,8 @@ static int do_execve_common(const char *filename,
45080 int retval;
45081 const struct cred *cred = current_cred();
45082
45083+ gr_learn_resource(current, RLIMIT_NPROC, atomic_read(&current->cred->user->processes), 1);
45084+
45085 /*
45086 * We move the actual failure in case of RLIMIT_NPROC excess from
45087 * set*uid() to execve() because too many poorly written programs
45088@@ -1515,12 +1583,27 @@ static int do_execve_common(const char *filename,
45089 if (IS_ERR(file))
45090 goto out_unmark;
45091
45092+ if (gr_ptrace_readexec(file, bprm->unsafe)) {
45093+ retval = -EPERM;
45094+ goto out_file;
45095+ }
45096+
45097 sched_exec();
45098
45099 bprm->file = file;
45100 bprm->filename = filename;
45101 bprm->interp = filename;
45102
45103+ if (gr_process_user_ban()) {
45104+ retval = -EPERM;
45105+ goto out_file;
45106+ }
45107+
45108+ if (!gr_acl_handle_execve(file->f_dentry, file->f_vfsmnt)) {
45109+ retval = -EACCES;
45110+ goto out_file;
45111+ }
45112+
45113 retval = bprm_mm_init(bprm);
45114 if (retval)
45115 goto out_file;
45116@@ -1537,24 +1620,65 @@ static int do_execve_common(const char *filename,
45117 if (retval < 0)
45118 goto out;
45119
45120+#ifdef CONFIG_GRKERNSEC
45121+ old_acl = current->acl;
45122+ memcpy(old_rlim, current->signal->rlim, sizeof(old_rlim));
45123+ old_exec_file = current->exec_file;
45124+ get_file(file);
45125+ current->exec_file = file;
45126+#endif
45127+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
45128+ /* limit suid stack to 8MB
45129+ we saved the old limits above and will restore them if this exec fails
45130+ */
45131+ if (((bprm->cred->euid != current_euid()) || (bprm->cred->egid != current_egid())) &&
45132+ (old_rlim[RLIMIT_STACK].rlim_cur > (8 * 1024 * 1024)))
45133+ current->signal->rlim[RLIMIT_STACK].rlim_cur = 8 * 1024 * 1024;
45134+#endif
45135+
45136+ if (!gr_tpe_allow(file)) {
45137+ retval = -EACCES;
45138+ goto out_fail;
45139+ }
45140+
45141+ if (gr_check_crash_exec(file)) {
45142+ retval = -EACCES;
45143+ goto out_fail;
45144+ }
45145+
45146+ retval = gr_set_proc_label(file->f_dentry, file->f_vfsmnt,
45147+ bprm->unsafe);
45148+ if (retval < 0)
45149+ goto out_fail;
45150+
45151 retval = copy_strings_kernel(1, &bprm->filename, bprm);
45152 if (retval < 0)
45153- goto out;
45154+ goto out_fail;
45155
45156 bprm->exec = bprm->p;
45157 retval = copy_strings(bprm->envc, envp, bprm);
45158 if (retval < 0)
45159- goto out;
45160+ goto out_fail;
45161
45162 retval = copy_strings(bprm->argc, argv, bprm);
45163 if (retval < 0)
45164- goto out;
45165+ goto out_fail;
45166+
45167+ gr_log_chroot_exec(file->f_dentry, file->f_vfsmnt);
45168+
45169+ gr_handle_exec_args(bprm, argv);
45170
45171 retval = search_binary_handler(bprm,regs);
45172 if (retval < 0)
45173- goto out;
45174+ goto out_fail;
45175+#ifdef CONFIG_GRKERNSEC
45176+ if (old_exec_file)
45177+ fput(old_exec_file);
45178+#endif
45179
45180 /* execve succeeded */
45181+
45182+ increment_exec_counter();
45183 current->fs->in_exec = 0;
45184 current->in_execve = 0;
45185 acct_update_integrals(current);
45186@@ -1563,6 +1687,14 @@ static int do_execve_common(const char *filename,
45187 put_files_struct(displaced);
45188 return retval;
45189
45190+out_fail:
45191+#ifdef CONFIG_GRKERNSEC
45192+ current->acl = old_acl;
45193+ memcpy(current->signal->rlim, old_rlim, sizeof(old_rlim));
45194+ fput(current->exec_file);
45195+ current->exec_file = old_exec_file;
45196+#endif
45197+
45198 out:
45199 if (bprm->mm) {
45200 acct_arg_size(bprm, 0);
45201@@ -1636,7 +1768,7 @@ static int expand_corename(struct core_name *cn)
45202 {
45203 char *old_corename = cn->corename;
45204
45205- cn->size = CORENAME_MAX_SIZE * atomic_inc_return(&call_count);
45206+ cn->size = CORENAME_MAX_SIZE * atomic_inc_return_unchecked(&call_count);
45207 cn->corename = krealloc(old_corename, cn->size, GFP_KERNEL);
45208
45209 if (!cn->corename) {
45210@@ -1733,7 +1865,7 @@ static int format_corename(struct core_name *cn, long signr)
45211 int pid_in_pattern = 0;
45212 int err = 0;
45213
45214- cn->size = CORENAME_MAX_SIZE * atomic_read(&call_count);
45215+ cn->size = CORENAME_MAX_SIZE * atomic_read_unchecked(&call_count);
45216 cn->corename = kmalloc(cn->size, GFP_KERNEL);
45217 cn->used = 0;
45218
45219@@ -1830,6 +1962,250 @@ out:
45220 return ispipe;
45221 }
45222
45223+int pax_check_flags(unsigned long *flags)
45224+{
45225+ int retval = 0;
45226+
45227+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_SEGMEXEC)
45228+ if (*flags & MF_PAX_SEGMEXEC)
45229+ {
45230+ *flags &= ~MF_PAX_SEGMEXEC;
45231+ retval = -EINVAL;
45232+ }
45233+#endif
45234+
45235+ if ((*flags & MF_PAX_PAGEEXEC)
45236+
45237+#ifdef CONFIG_PAX_PAGEEXEC
45238+ && (*flags & MF_PAX_SEGMEXEC)
45239+#endif
45240+
45241+ )
45242+ {
45243+ *flags &= ~MF_PAX_PAGEEXEC;
45244+ retval = -EINVAL;
45245+ }
45246+
45247+ if ((*flags & MF_PAX_MPROTECT)
45248+
45249+#ifdef CONFIG_PAX_MPROTECT
45250+ && !(*flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC))
45251+#endif
45252+
45253+ )
45254+ {
45255+ *flags &= ~MF_PAX_MPROTECT;
45256+ retval = -EINVAL;
45257+ }
45258+
45259+ if ((*flags & MF_PAX_EMUTRAMP)
45260+
45261+#ifdef CONFIG_PAX_EMUTRAMP
45262+ && !(*flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC))
45263+#endif
45264+
45265+ )
45266+ {
45267+ *flags &= ~MF_PAX_EMUTRAMP;
45268+ retval = -EINVAL;
45269+ }
45270+
45271+ return retval;
45272+}
45273+
45274+EXPORT_SYMBOL(pax_check_flags);
45275+
45276+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
45277+void pax_report_fault(struct pt_regs *regs, void *pc, void *sp)
45278+{
45279+ struct task_struct *tsk = current;
45280+ struct mm_struct *mm = current->mm;
45281+ char *buffer_exec = (char *)__get_free_page(GFP_KERNEL);
45282+ char *buffer_fault = (char *)__get_free_page(GFP_KERNEL);
45283+ char *path_exec = NULL;
45284+ char *path_fault = NULL;
45285+ unsigned long start = 0UL, end = 0UL, offset = 0UL;
45286+
45287+ if (buffer_exec && buffer_fault) {
45288+ struct vm_area_struct *vma, *vma_exec = NULL, *vma_fault = NULL;
45289+
45290+ down_read(&mm->mmap_sem);
45291+ vma = mm->mmap;
45292+ while (vma && (!vma_exec || !vma_fault)) {
45293+ if ((vma->vm_flags & VM_EXECUTABLE) && vma->vm_file)
45294+ vma_exec = vma;
45295+ if (vma->vm_start <= (unsigned long)pc && (unsigned long)pc < vma->vm_end)
45296+ vma_fault = vma;
45297+ vma = vma->vm_next;
45298+ }
45299+ if (vma_exec) {
45300+ path_exec = d_path(&vma_exec->vm_file->f_path, buffer_exec, PAGE_SIZE);
45301+ if (IS_ERR(path_exec))
45302+ path_exec = "<path too long>";
45303+ else {
45304+ path_exec = mangle_path(buffer_exec, path_exec, "\t\n\\");
45305+ if (path_exec) {
45306+ *path_exec = 0;
45307+ path_exec = buffer_exec;
45308+ } else
45309+ path_exec = "<path too long>";
45310+ }
45311+ }
45312+ if (vma_fault) {
45313+ start = vma_fault->vm_start;
45314+ end = vma_fault->vm_end;
45315+ offset = vma_fault->vm_pgoff << PAGE_SHIFT;
45316+ if (vma_fault->vm_file) {
45317+ path_fault = d_path(&vma_fault->vm_file->f_path, buffer_fault, PAGE_SIZE);
45318+ if (IS_ERR(path_fault))
45319+ path_fault = "<path too long>";
45320+ else {
45321+ path_fault = mangle_path(buffer_fault, path_fault, "\t\n\\");
45322+ if (path_fault) {
45323+ *path_fault = 0;
45324+ path_fault = buffer_fault;
45325+ } else
45326+ path_fault = "<path too long>";
45327+ }
45328+ } else
45329+ path_fault = "<anonymous mapping>";
45330+ }
45331+ up_read(&mm->mmap_sem);
45332+ }
45333+ if (tsk->signal->curr_ip)
45334+ printk(KERN_ERR "PAX: From %pI4: execution attempt in: %s, %08lx-%08lx %08lx\n", &tsk->signal->curr_ip, path_fault, start, end, offset);
45335+ else
45336+ printk(KERN_ERR "PAX: execution attempt in: %s, %08lx-%08lx %08lx\n", path_fault, start, end, offset);
45337+ printk(KERN_ERR "PAX: terminating task: %s(%s):%d, uid/euid: %u/%u, "
45338+ "PC: %p, SP: %p\n", path_exec, tsk->comm, task_pid_nr(tsk),
45339+ task_uid(tsk), task_euid(tsk), pc, sp);
45340+ free_page((unsigned long)buffer_exec);
45341+ free_page((unsigned long)buffer_fault);
45342+ pax_report_insns(regs, pc, sp);
45343+ do_coredump(SIGKILL, SIGKILL, regs);
45344+}
45345+#endif
45346+
45347+#ifdef CONFIG_PAX_REFCOUNT
45348+void pax_report_refcount_overflow(struct pt_regs *regs)
45349+{
45350+ if (current->signal->curr_ip)
45351+ printk(KERN_ERR "PAX: From %pI4: refcount overflow detected in: %s:%d, uid/euid: %u/%u\n",
45352+ &current->signal->curr_ip, current->comm, task_pid_nr(current), current_uid(), current_euid());
45353+ else
45354+ printk(KERN_ERR "PAX: refcount overflow detected in: %s:%d, uid/euid: %u/%u\n",
45355+ current->comm, task_pid_nr(current), current_uid(), current_euid());
45356+ print_symbol(KERN_ERR "PAX: refcount overflow occured at: %s\n", instruction_pointer(regs));
45357+ show_regs(regs);
45358+ force_sig_info(SIGKILL, SEND_SIG_FORCED, current);
45359+}
45360+#endif
45361+
45362+#ifdef CONFIG_PAX_USERCOPY
45363+/* 0: not at all, 1: fully, 2: fully inside frame, -1: partially (implies an error) */
45364+static noinline int check_stack_object(const void *obj, unsigned long len)
45365+{
45366+ const void * const stack = task_stack_page(current);
45367+ const void * const stackend = stack + THREAD_SIZE;
45368+
45369+#if defined(CONFIG_FRAME_POINTER) && defined(CONFIG_X86)
45370+ const void *frame = NULL;
45371+ const void *oldframe;
45372+#endif
45373+
45374+ if (obj + len < obj)
45375+ return -1;
45376+
45377+ if (obj + len <= stack || stackend <= obj)
45378+ return 0;
45379+
45380+ if (obj < stack || stackend < obj + len)
45381+ return -1;
45382+
45383+#if defined(CONFIG_FRAME_POINTER) && defined(CONFIG_X86)
45384+ oldframe = __builtin_frame_address(1);
45385+ if (oldframe)
45386+ frame = __builtin_frame_address(2);
45387+ /*
45388+ low ----------------------------------------------> high
45389+ [saved bp][saved ip][args][local vars][saved bp][saved ip]
45390+ ^----------------^
45391+ allow copies only within here
45392+ */
45393+ while (stack <= frame && frame < stackend) {
45394+ /* if obj + len extends past the last frame, this
45395+ check won't pass and the next frame will be 0,
45396+ causing us to bail out and correctly report
45397+ the copy as invalid
45398+ */
45399+ if (obj + len <= frame)
45400+ return obj >= oldframe + 2 * sizeof(void *) ? 2 : -1;
45401+ oldframe = frame;
45402+ frame = *(const void * const *)frame;
45403+ }
45404+ return -1;
45405+#else
45406+ return 1;
45407+#endif
45408+}
45409+
45410+static __noreturn void pax_report_usercopy(const void *ptr, unsigned long len, bool to, const char *type)
45411+{
45412+ if (current->signal->curr_ip)
45413+ printk(KERN_ERR "PAX: From %pI4: kernel memory %s attempt detected %s %p (%s) (%lu bytes)\n",
45414+ &current->signal->curr_ip, to ? "leak" : "overwrite", to ? "from" : "to", ptr, type ? : "unknown", len);
45415+ else
45416+ printk(KERN_ERR "PAX: kernel memory %s attempt detected %s %p (%s) (%lu bytes)\n",
45417+ to ? "leak" : "overwrite", to ? "from" : "to", ptr, type ? : "unknown", len);
45418+ dump_stack();
45419+ gr_handle_kernel_exploit();
45420+ do_group_exit(SIGKILL);
45421+}
45422+#endif
45423+
45424+void check_object_size(const void *ptr, unsigned long n, bool to)
45425+{
45426+
45427+#ifdef CONFIG_PAX_USERCOPY
45428+ const char *type;
45429+
45430+ if (!n)
45431+ return;
45432+
45433+ type = check_heap_object(ptr, n, to);
45434+ if (!type) {
45435+ if (check_stack_object(ptr, n) != -1)
45436+ return;
45437+ type = "<process stack>";
45438+ }
45439+
45440+ pax_report_usercopy(ptr, n, to, type);
45441+#endif
45442+
45443+}
45444+EXPORT_SYMBOL(check_object_size);
45445+
45446+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
45447+void pax_track_stack(void)
45448+{
45449+ unsigned long sp = (unsigned long)&sp;
45450+ if (sp < current_thread_info()->lowest_stack &&
45451+ sp > (unsigned long)task_stack_page(current))
45452+ current_thread_info()->lowest_stack = sp;
45453+}
45454+EXPORT_SYMBOL(pax_track_stack);
45455+#endif
45456+
45457+#ifdef CONFIG_PAX_SIZE_OVERFLOW
45458+void report_size_overflow(const char *file, unsigned int line, const char *func, const char *ssa_name)
45459+{
45460+ printk(KERN_ERR "PAX: size overflow detected in function %s %s:%u %s", func, file, line, ssa_name);
45461+ dump_stack();
45462+ do_group_exit(SIGKILL);
45463+}
45464+EXPORT_SYMBOL(report_size_overflow);
45465+#endif
45466+
45467 static int zap_process(struct task_struct *start, int exit_code)
45468 {
45469 struct task_struct *t;
45470@@ -2040,17 +2416,17 @@ static void wait_for_dump_helpers(struct file *file)
45471 pipe = file->f_path.dentry->d_inode->i_pipe;
45472
45473 pipe_lock(pipe);
45474- pipe->readers++;
45475- pipe->writers--;
45476+ atomic_inc(&pipe->readers);
45477+ atomic_dec(&pipe->writers);
45478
45479- while ((pipe->readers > 1) && (!signal_pending(current))) {
45480+ while ((atomic_read(&pipe->readers) > 1) && (!signal_pending(current))) {
45481 wake_up_interruptible_sync(&pipe->wait);
45482 kill_fasync(&pipe->fasync_readers, SIGIO, POLL_IN);
45483 pipe_wait(pipe);
45484 }
45485
45486- pipe->readers--;
45487- pipe->writers++;
45488+ atomic_dec(&pipe->readers);
45489+ atomic_inc(&pipe->writers);
45490 pipe_unlock(pipe);
45491
45492 }
45493@@ -2105,7 +2481,7 @@ void do_coredump(long signr, int exit_code, struct pt_regs *regs)
45494 int flag = 0;
45495 int ispipe;
45496 bool need_nonrelative = false;
45497- static atomic_t core_dump_count = ATOMIC_INIT(0);
45498+ static atomic_unchecked_t core_dump_count = ATOMIC_INIT(0);
45499 struct coredump_params cprm = {
45500 .signr = signr,
45501 .regs = regs,
45502@@ -2120,6 +2496,9 @@ void do_coredump(long signr, int exit_code, struct pt_regs *regs)
45503
45504 audit_core_dumps(signr);
45505
45506+ if (signr == SIGSEGV || signr == SIGBUS || signr == SIGKILL || signr == SIGILL)
45507+ gr_handle_brute_attach(current, cprm.mm_flags);
45508+
45509 binfmt = mm->binfmt;
45510 if (!binfmt || !binfmt->core_dump)
45511 goto fail;
45512@@ -2190,7 +2569,7 @@ void do_coredump(long signr, int exit_code, struct pt_regs *regs)
45513 }
45514 cprm.limit = RLIM_INFINITY;
45515
45516- dump_count = atomic_inc_return(&core_dump_count);
45517+ dump_count = atomic_inc_return_unchecked(&core_dump_count);
45518 if (core_pipe_limit && (core_pipe_limit < dump_count)) {
45519 printk(KERN_WARNING "Pid %d(%s) over core_pipe_limit\n",
45520 task_tgid_vnr(current), current->comm);
45521@@ -2217,6 +2596,8 @@ void do_coredump(long signr, int exit_code, struct pt_regs *regs)
45522 } else {
45523 struct inode *inode;
45524
45525+ gr_learn_resource(current, RLIMIT_CORE, binfmt->min_coredump, 1);
45526+
45527 if (cprm.limit < binfmt->min_coredump)
45528 goto fail_unlock;
45529
45530@@ -2268,7 +2649,7 @@ close_fail:
45531 filp_close(cprm.file, NULL);
45532 fail_dropcount:
45533 if (ispipe)
45534- atomic_dec(&core_dump_count);
45535+ atomic_dec_unchecked(&core_dump_count);
45536 fail_unlock:
45537 kfree(cn.corename);
45538 fail_corename:
45539@@ -2287,7 +2668,7 @@ fail:
45540 */
45541 int dump_write(struct file *file, const void *addr, int nr)
45542 {
45543- return access_ok(VERIFY_READ, addr, nr) && file->f_op->write(file, addr, nr, &file->f_pos) == nr;
45544+ return access_ok(VERIFY_READ, addr, nr) && file->f_op->write(file, (const char __force_user *)addr, nr, &file->f_pos) == nr;
45545 }
45546 EXPORT_SYMBOL(dump_write);
45547
45548diff --git a/fs/ext2/balloc.c b/fs/ext2/balloc.c
45549index 376aa77..59a129c 100644
45550--- a/fs/ext2/balloc.c
45551+++ b/fs/ext2/balloc.c
45552@@ -1190,10 +1190,10 @@ static int ext2_has_free_blocks(struct ext2_sb_info *sbi)
45553
45554 free_blocks = percpu_counter_read_positive(&sbi->s_freeblocks_counter);
45555 root_blocks = le32_to_cpu(sbi->s_es->s_r_blocks_count);
45556- if (free_blocks < root_blocks + 1 && !capable(CAP_SYS_RESOURCE) &&
45557+ if (free_blocks < root_blocks + 1 &&
45558 !uid_eq(sbi->s_resuid, current_fsuid()) &&
45559 (gid_eq(sbi->s_resgid, GLOBAL_ROOT_GID) ||
45560- !in_group_p (sbi->s_resgid))) {
45561+ !in_group_p (sbi->s_resgid)) && !capable_nolog(CAP_SYS_RESOURCE)) {
45562 return 0;
45563 }
45564 return 1;
45565diff --git a/fs/ext3/balloc.c b/fs/ext3/balloc.c
45566index 90d901f..159975f 100644
45567--- a/fs/ext3/balloc.c
45568+++ b/fs/ext3/balloc.c
45569@@ -1438,10 +1438,10 @@ static int ext3_has_free_blocks(struct ext3_sb_info *sbi, int use_reservation)
45570
45571 free_blocks = percpu_counter_read_positive(&sbi->s_freeblocks_counter);
45572 root_blocks = le32_to_cpu(sbi->s_es->s_r_blocks_count);
45573- if (free_blocks < root_blocks + 1 && !capable(CAP_SYS_RESOURCE) &&
45574+ if (free_blocks < root_blocks + 1 &&
45575 !use_reservation && !uid_eq(sbi->s_resuid, current_fsuid()) &&
45576 (gid_eq(sbi->s_resgid, GLOBAL_ROOT_GID) ||
45577- !in_group_p (sbi->s_resgid))) {
45578+ !in_group_p (sbi->s_resgid)) && !capable_nolog(CAP_SYS_RESOURCE)) {
45579 return 0;
45580 }
45581 return 1;
45582diff --git a/fs/ext4/balloc.c b/fs/ext4/balloc.c
45583index cf18217..8f6b9c3 100644
45584--- a/fs/ext4/balloc.c
45585+++ b/fs/ext4/balloc.c
45586@@ -498,8 +498,8 @@ static int ext4_has_free_clusters(struct ext4_sb_info *sbi,
45587 /* Hm, nope. Are (enough) root reserved clusters available? */
45588 if (uid_eq(sbi->s_resuid, current_fsuid()) ||
45589 (!gid_eq(sbi->s_resgid, GLOBAL_ROOT_GID) && in_group_p(sbi->s_resgid)) ||
45590- capable(CAP_SYS_RESOURCE) ||
45591- (flags & EXT4_MB_USE_ROOT_BLOCKS)) {
45592+ (flags & EXT4_MB_USE_ROOT_BLOCKS) ||
45593+ capable_nolog(CAP_SYS_RESOURCE)) {
45594
45595 if (free_clusters >= (nclusters + dirty_clusters))
45596 return 1;
45597diff --git a/fs/ext4/ext4.h b/fs/ext4/ext4.h
45598index 5c69f2b..05dec7f 100644
45599--- a/fs/ext4/ext4.h
45600+++ b/fs/ext4/ext4.h
45601@@ -1248,19 +1248,19 @@ struct ext4_sb_info {
45602 unsigned long s_mb_last_start;
45603
45604 /* stats for buddy allocator */
45605- atomic_t s_bal_reqs; /* number of reqs with len > 1 */
45606- atomic_t s_bal_success; /* we found long enough chunks */
45607- atomic_t s_bal_allocated; /* in blocks */
45608- atomic_t s_bal_ex_scanned; /* total extents scanned */
45609- atomic_t s_bal_goals; /* goal hits */
45610- atomic_t s_bal_breaks; /* too long searches */
45611- atomic_t s_bal_2orders; /* 2^order hits */
45612+ atomic_unchecked_t s_bal_reqs; /* number of reqs with len > 1 */
45613+ atomic_unchecked_t s_bal_success; /* we found long enough chunks */
45614+ atomic_unchecked_t s_bal_allocated; /* in blocks */
45615+ atomic_unchecked_t s_bal_ex_scanned; /* total extents scanned */
45616+ atomic_unchecked_t s_bal_goals; /* goal hits */
45617+ atomic_unchecked_t s_bal_breaks; /* too long searches */
45618+ atomic_unchecked_t s_bal_2orders; /* 2^order hits */
45619 spinlock_t s_bal_lock;
45620 unsigned long s_mb_buddies_generated;
45621 unsigned long long s_mb_generation_time;
45622- atomic_t s_mb_lost_chunks;
45623- atomic_t s_mb_preallocated;
45624- atomic_t s_mb_discarded;
45625+ atomic_unchecked_t s_mb_lost_chunks;
45626+ atomic_unchecked_t s_mb_preallocated;
45627+ atomic_unchecked_t s_mb_discarded;
45628 atomic_t s_lock_busy;
45629
45630 /* locality groups */
45631diff --git a/fs/ext4/mballoc.c b/fs/ext4/mballoc.c
45632index b26410c..7383d90 100644
45633--- a/fs/ext4/mballoc.c
45634+++ b/fs/ext4/mballoc.c
45635@@ -1746,7 +1746,7 @@ void ext4_mb_simple_scan_group(struct ext4_allocation_context *ac,
45636 BUG_ON(ac->ac_b_ex.fe_len != ac->ac_g_ex.fe_len);
45637
45638 if (EXT4_SB(sb)->s_mb_stats)
45639- atomic_inc(&EXT4_SB(sb)->s_bal_2orders);
45640+ atomic_inc_unchecked(&EXT4_SB(sb)->s_bal_2orders);
45641
45642 break;
45643 }
45644@@ -2040,7 +2040,7 @@ repeat:
45645 ac->ac_status = AC_STATUS_CONTINUE;
45646 ac->ac_flags |= EXT4_MB_HINT_FIRST;
45647 cr = 3;
45648- atomic_inc(&sbi->s_mb_lost_chunks);
45649+ atomic_inc_unchecked(&sbi->s_mb_lost_chunks);
45650 goto repeat;
45651 }
45652 }
45653@@ -2551,25 +2551,25 @@ int ext4_mb_release(struct super_block *sb)
45654 if (sbi->s_mb_stats) {
45655 ext4_msg(sb, KERN_INFO,
45656 "mballoc: %u blocks %u reqs (%u success)",
45657- atomic_read(&sbi->s_bal_allocated),
45658- atomic_read(&sbi->s_bal_reqs),
45659- atomic_read(&sbi->s_bal_success));
45660+ atomic_read_unchecked(&sbi->s_bal_allocated),
45661+ atomic_read_unchecked(&sbi->s_bal_reqs),
45662+ atomic_read_unchecked(&sbi->s_bal_success));
45663 ext4_msg(sb, KERN_INFO,
45664 "mballoc: %u extents scanned, %u goal hits, "
45665 "%u 2^N hits, %u breaks, %u lost",
45666- atomic_read(&sbi->s_bal_ex_scanned),
45667- atomic_read(&sbi->s_bal_goals),
45668- atomic_read(&sbi->s_bal_2orders),
45669- atomic_read(&sbi->s_bal_breaks),
45670- atomic_read(&sbi->s_mb_lost_chunks));
45671+ atomic_read_unchecked(&sbi->s_bal_ex_scanned),
45672+ atomic_read_unchecked(&sbi->s_bal_goals),
45673+ atomic_read_unchecked(&sbi->s_bal_2orders),
45674+ atomic_read_unchecked(&sbi->s_bal_breaks),
45675+ atomic_read_unchecked(&sbi->s_mb_lost_chunks));
45676 ext4_msg(sb, KERN_INFO,
45677 "mballoc: %lu generated and it took %Lu",
45678 sbi->s_mb_buddies_generated,
45679 sbi->s_mb_generation_time);
45680 ext4_msg(sb, KERN_INFO,
45681 "mballoc: %u preallocated, %u discarded",
45682- atomic_read(&sbi->s_mb_preallocated),
45683- atomic_read(&sbi->s_mb_discarded));
45684+ atomic_read_unchecked(&sbi->s_mb_preallocated),
45685+ atomic_read_unchecked(&sbi->s_mb_discarded));
45686 }
45687
45688 free_percpu(sbi->s_locality_groups);
45689@@ -3051,16 +3051,16 @@ static void ext4_mb_collect_stats(struct ext4_allocation_context *ac)
45690 struct ext4_sb_info *sbi = EXT4_SB(ac->ac_sb);
45691
45692 if (sbi->s_mb_stats && ac->ac_g_ex.fe_len > 1) {
45693- atomic_inc(&sbi->s_bal_reqs);
45694- atomic_add(ac->ac_b_ex.fe_len, &sbi->s_bal_allocated);
45695+ atomic_inc_unchecked(&sbi->s_bal_reqs);
45696+ atomic_add_unchecked(ac->ac_b_ex.fe_len, &sbi->s_bal_allocated);
45697 if (ac->ac_b_ex.fe_len >= ac->ac_o_ex.fe_len)
45698- atomic_inc(&sbi->s_bal_success);
45699- atomic_add(ac->ac_found, &sbi->s_bal_ex_scanned);
45700+ atomic_inc_unchecked(&sbi->s_bal_success);
45701+ atomic_add_unchecked(ac->ac_found, &sbi->s_bal_ex_scanned);
45702 if (ac->ac_g_ex.fe_start == ac->ac_b_ex.fe_start &&
45703 ac->ac_g_ex.fe_group == ac->ac_b_ex.fe_group)
45704- atomic_inc(&sbi->s_bal_goals);
45705+ atomic_inc_unchecked(&sbi->s_bal_goals);
45706 if (ac->ac_found > sbi->s_mb_max_to_scan)
45707- atomic_inc(&sbi->s_bal_breaks);
45708+ atomic_inc_unchecked(&sbi->s_bal_breaks);
45709 }
45710
45711 if (ac->ac_op == EXT4_MB_HISTORY_ALLOC)
45712@@ -3460,7 +3460,7 @@ ext4_mb_new_inode_pa(struct ext4_allocation_context *ac)
45713 trace_ext4_mb_new_inode_pa(ac, pa);
45714
45715 ext4_mb_use_inode_pa(ac, pa);
45716- atomic_add(pa->pa_free, &sbi->s_mb_preallocated);
45717+ atomic_add_unchecked(pa->pa_free, &sbi->s_mb_preallocated);
45718
45719 ei = EXT4_I(ac->ac_inode);
45720 grp = ext4_get_group_info(sb, ac->ac_b_ex.fe_group);
45721@@ -3520,7 +3520,7 @@ ext4_mb_new_group_pa(struct ext4_allocation_context *ac)
45722 trace_ext4_mb_new_group_pa(ac, pa);
45723
45724 ext4_mb_use_group_pa(ac, pa);
45725- atomic_add(pa->pa_free, &EXT4_SB(sb)->s_mb_preallocated);
45726+ atomic_add_unchecked(pa->pa_free, &EXT4_SB(sb)->s_mb_preallocated);
45727
45728 grp = ext4_get_group_info(sb, ac->ac_b_ex.fe_group);
45729 lg = ac->ac_lg;
45730@@ -3609,7 +3609,7 @@ ext4_mb_release_inode_pa(struct ext4_buddy *e4b, struct buffer_head *bitmap_bh,
45731 * from the bitmap and continue.
45732 */
45733 }
45734- atomic_add(free, &sbi->s_mb_discarded);
45735+ atomic_add_unchecked(free, &sbi->s_mb_discarded);
45736
45737 return err;
45738 }
45739@@ -3627,7 +3627,7 @@ ext4_mb_release_group_pa(struct ext4_buddy *e4b,
45740 ext4_get_group_no_and_offset(sb, pa->pa_pstart, &group, &bit);
45741 BUG_ON(group != e4b->bd_group && pa->pa_len != 0);
45742 mb_free_blocks(pa->pa_inode, e4b, bit, pa->pa_len);
45743- atomic_add(pa->pa_len, &EXT4_SB(sb)->s_mb_discarded);
45744+ atomic_add_unchecked(pa->pa_len, &EXT4_SB(sb)->s_mb_discarded);
45745 trace_ext4_mballoc_discard(sb, NULL, group, bit, pa->pa_len);
45746
45747 return 0;
45748diff --git a/fs/fcntl.c b/fs/fcntl.c
45749index 887b5ba..0e3f2c3 100644
45750--- a/fs/fcntl.c
45751+++ b/fs/fcntl.c
45752@@ -225,6 +225,11 @@ int __f_setown(struct file *filp, struct pid *pid, enum pid_type type,
45753 if (err)
45754 return err;
45755
45756+ if (gr_handle_chroot_fowner(pid, type))
45757+ return -ENOENT;
45758+ if (gr_check_protected_task_fowner(pid, type))
45759+ return -EACCES;
45760+
45761 f_modown(filp, pid, type, force);
45762 return 0;
45763 }
45764@@ -267,7 +272,7 @@ pid_t f_getown(struct file *filp)
45765
45766 static int f_setown_ex(struct file *filp, unsigned long arg)
45767 {
45768- struct f_owner_ex * __user owner_p = (void * __user)arg;
45769+ struct f_owner_ex __user *owner_p = (void __user *)arg;
45770 struct f_owner_ex owner;
45771 struct pid *pid;
45772 int type;
45773@@ -307,7 +312,7 @@ static int f_setown_ex(struct file *filp, unsigned long arg)
45774
45775 static int f_getown_ex(struct file *filp, unsigned long arg)
45776 {
45777- struct f_owner_ex * __user owner_p = (void * __user)arg;
45778+ struct f_owner_ex __user *owner_p = (void __user *)arg;
45779 struct f_owner_ex owner;
45780 int ret = 0;
45781
45782@@ -374,6 +379,7 @@ static long do_fcntl(int fd, unsigned int cmd, unsigned long arg,
45783 switch (cmd) {
45784 case F_DUPFD:
45785 case F_DUPFD_CLOEXEC:
45786+ gr_learn_resource(current, RLIMIT_NOFILE, arg, 0);
45787 if (arg >= rlimit(RLIMIT_NOFILE))
45788 break;
45789 err = alloc_fd(arg, cmd == F_DUPFD_CLOEXEC ? O_CLOEXEC : 0);
45790diff --git a/fs/fifo.c b/fs/fifo.c
45791index cf6f434..3d7942c 100644
45792--- a/fs/fifo.c
45793+++ b/fs/fifo.c
45794@@ -59,10 +59,10 @@ static int fifo_open(struct inode *inode, struct file *filp)
45795 */
45796 filp->f_op = &read_pipefifo_fops;
45797 pipe->r_counter++;
45798- if (pipe->readers++ == 0)
45799+ if (atomic_inc_return(&pipe->readers) == 1)
45800 wake_up_partner(inode);
45801
45802- if (!pipe->writers) {
45803+ if (!atomic_read(&pipe->writers)) {
45804 if ((filp->f_flags & O_NONBLOCK)) {
45805 /* suppress POLLHUP until we have
45806 * seen a writer */
45807@@ -81,15 +81,15 @@ static int fifo_open(struct inode *inode, struct file *filp)
45808 * errno=ENXIO when there is no process reading the FIFO.
45809 */
45810 ret = -ENXIO;
45811- if ((filp->f_flags & O_NONBLOCK) && !pipe->readers)
45812+ if ((filp->f_flags & O_NONBLOCK) && !atomic_read(&pipe->readers))
45813 goto err;
45814
45815 filp->f_op = &write_pipefifo_fops;
45816 pipe->w_counter++;
45817- if (!pipe->writers++)
45818+ if (atomic_inc_return(&pipe->writers) == 1)
45819 wake_up_partner(inode);
45820
45821- if (!pipe->readers) {
45822+ if (!atomic_read(&pipe->readers)) {
45823 if (wait_for_partner(inode, &pipe->r_counter))
45824 goto err_wr;
45825 }
45826@@ -104,11 +104,11 @@ static int fifo_open(struct inode *inode, struct file *filp)
45827 */
45828 filp->f_op = &rdwr_pipefifo_fops;
45829
45830- pipe->readers++;
45831- pipe->writers++;
45832+ atomic_inc(&pipe->readers);
45833+ atomic_inc(&pipe->writers);
45834 pipe->r_counter++;
45835 pipe->w_counter++;
45836- if (pipe->readers == 1 || pipe->writers == 1)
45837+ if (atomic_read(&pipe->readers) == 1 || atomic_read(&pipe->writers) == 1)
45838 wake_up_partner(inode);
45839 break;
45840
45841@@ -122,19 +122,19 @@ static int fifo_open(struct inode *inode, struct file *filp)
45842 return 0;
45843
45844 err_rd:
45845- if (!--pipe->readers)
45846+ if (atomic_dec_and_test(&pipe->readers))
45847 wake_up_interruptible(&pipe->wait);
45848 ret = -ERESTARTSYS;
45849 goto err;
45850
45851 err_wr:
45852- if (!--pipe->writers)
45853+ if (atomic_dec_and_test(&pipe->writers))
45854 wake_up_interruptible(&pipe->wait);
45855 ret = -ERESTARTSYS;
45856 goto err;
45857
45858 err:
45859- if (!pipe->readers && !pipe->writers)
45860+ if (!atomic_read(&pipe->readers) && !atomic_read(&pipe->writers))
45861 free_pipe_info(inode);
45862
45863 err_nocleanup:
45864diff --git a/fs/file.c b/fs/file.c
45865index ba3f605..fade102 100644
45866--- a/fs/file.c
45867+++ b/fs/file.c
45868@@ -15,6 +15,7 @@
45869 #include <linux/slab.h>
45870 #include <linux/vmalloc.h>
45871 #include <linux/file.h>
45872+#include <linux/security.h>
45873 #include <linux/fdtable.h>
45874 #include <linux/bitops.h>
45875 #include <linux/interrupt.h>
45876@@ -255,6 +256,7 @@ int expand_files(struct files_struct *files, int nr)
45877 * N.B. For clone tasks sharing a files structure, this test
45878 * will limit the total number of files that can be opened.
45879 */
45880+ gr_learn_resource(current, RLIMIT_NOFILE, nr, 0);
45881 if (nr >= rlimit(RLIMIT_NOFILE))
45882 return -EMFILE;
45883
45884diff --git a/fs/filesystems.c b/fs/filesystems.c
45885index 96f2428..f5eeb8e 100644
45886--- a/fs/filesystems.c
45887+++ b/fs/filesystems.c
45888@@ -273,7 +273,12 @@ struct file_system_type *get_fs_type(const char *name)
45889 int len = dot ? dot - name : strlen(name);
45890
45891 fs = __get_fs_type(name, len);
45892+
45893+#ifdef CONFIG_GRKERNSEC_MODHARDEN
45894+ if (!fs && (___request_module(true, "grsec_modharden_fs", "%.*s", len, name) == 0))
45895+#else
45896 if (!fs && (request_module("%.*s", len, name) == 0))
45897+#endif
45898 fs = __get_fs_type(name, len);
45899
45900 if (dot && fs && !(fs->fs_flags & FS_HAS_SUBTYPE)) {
45901diff --git a/fs/fs_struct.c b/fs/fs_struct.c
45902index 5df4775..9d9336f 100644
45903--- a/fs/fs_struct.c
45904+++ b/fs/fs_struct.c
45905@@ -4,6 +4,7 @@
45906 #include <linux/path.h>
45907 #include <linux/slab.h>
45908 #include <linux/fs_struct.h>
45909+#include <linux/grsecurity.h>
45910 #include "internal.h"
45911
45912 /*
45913@@ -19,6 +20,7 @@ void set_fs_root(struct fs_struct *fs, struct path *path)
45914 write_seqcount_begin(&fs->seq);
45915 old_root = fs->root;
45916 fs->root = *path;
45917+ gr_set_chroot_entries(current, path);
45918 write_seqcount_end(&fs->seq);
45919 spin_unlock(&fs->lock);
45920 if (old_root.dentry)
45921@@ -53,6 +55,21 @@ static inline int replace_path(struct path *p, const struct path *old, const str
45922 return 1;
45923 }
45924
45925+static inline int replace_root_path(struct task_struct *task, struct path *p, const struct path *old, struct path *new)
45926+{
45927+ if (likely(p->dentry != old->dentry || p->mnt != old->mnt))
45928+ return 0;
45929+ *p = *new;
45930+
45931+ /* This function is only called from pivot_root(). Leave our
45932+ gr_chroot_dentry and is_chrooted flags as-is, so that a
45933+ pivoted root isn't treated as a chroot
45934+ */
45935+ //gr_set_chroot_entries(task, new);
45936+
45937+ return 1;
45938+}
45939+
45940 void chroot_fs_refs(struct path *old_root, struct path *new_root)
45941 {
45942 struct task_struct *g, *p;
45943@@ -67,7 +84,7 @@ void chroot_fs_refs(struct path *old_root, struct path *new_root)
45944 int hits = 0;
45945 spin_lock(&fs->lock);
45946 write_seqcount_begin(&fs->seq);
45947- hits += replace_path(&fs->root, old_root, new_root);
45948+ hits += replace_root_path(p, &fs->root, old_root, new_root);
45949 hits += replace_path(&fs->pwd, old_root, new_root);
45950 write_seqcount_end(&fs->seq);
45951 while (hits--) {
45952@@ -99,7 +116,8 @@ void exit_fs(struct task_struct *tsk)
45953 task_lock(tsk);
45954 spin_lock(&fs->lock);
45955 tsk->fs = NULL;
45956- kill = !--fs->users;
45957+ gr_clear_chroot_entries(tsk);
45958+ kill = !atomic_dec_return(&fs->users);
45959 spin_unlock(&fs->lock);
45960 task_unlock(tsk);
45961 if (kill)
45962@@ -112,7 +130,7 @@ struct fs_struct *copy_fs_struct(struct fs_struct *old)
45963 struct fs_struct *fs = kmem_cache_alloc(fs_cachep, GFP_KERNEL);
45964 /* We don't need to lock fs - think why ;-) */
45965 if (fs) {
45966- fs->users = 1;
45967+ atomic_set(&fs->users, 1);
45968 fs->in_exec = 0;
45969 spin_lock_init(&fs->lock);
45970 seqcount_init(&fs->seq);
45971@@ -121,6 +139,9 @@ struct fs_struct *copy_fs_struct(struct fs_struct *old)
45972 spin_lock(&old->lock);
45973 fs->root = old->root;
45974 path_get(&fs->root);
45975+ /* instead of calling gr_set_chroot_entries here,
45976+ we call it from every caller of this function
45977+ */
45978 fs->pwd = old->pwd;
45979 path_get(&fs->pwd);
45980 spin_unlock(&old->lock);
45981@@ -139,8 +160,9 @@ int unshare_fs_struct(void)
45982
45983 task_lock(current);
45984 spin_lock(&fs->lock);
45985- kill = !--fs->users;
45986+ kill = !atomic_dec_return(&fs->users);
45987 current->fs = new_fs;
45988+ gr_set_chroot_entries(current, &new_fs->root);
45989 spin_unlock(&fs->lock);
45990 task_unlock(current);
45991
45992@@ -153,13 +175,13 @@ EXPORT_SYMBOL_GPL(unshare_fs_struct);
45993
45994 int current_umask(void)
45995 {
45996- return current->fs->umask;
45997+ return current->fs->umask | gr_acl_umask();
45998 }
45999 EXPORT_SYMBOL(current_umask);
46000
46001 /* to be mentioned only in INIT_TASK */
46002 struct fs_struct init_fs = {
46003- .users = 1,
46004+ .users = ATOMIC_INIT(1),
46005 .lock = __SPIN_LOCK_UNLOCKED(init_fs.lock),
46006 .seq = SEQCNT_ZERO,
46007 .umask = 0022,
46008@@ -175,12 +197,13 @@ void daemonize_fs_struct(void)
46009 task_lock(current);
46010
46011 spin_lock(&init_fs.lock);
46012- init_fs.users++;
46013+ atomic_inc(&init_fs.users);
46014 spin_unlock(&init_fs.lock);
46015
46016 spin_lock(&fs->lock);
46017 current->fs = &init_fs;
46018- kill = !--fs->users;
46019+ gr_set_chroot_entries(current, &current->fs->root);
46020+ kill = !atomic_dec_return(&fs->users);
46021 spin_unlock(&fs->lock);
46022
46023 task_unlock(current);
46024diff --git a/fs/fscache/cookie.c b/fs/fscache/cookie.c
46025index 9905350..02eaec4 100644
46026--- a/fs/fscache/cookie.c
46027+++ b/fs/fscache/cookie.c
46028@@ -68,11 +68,11 @@ struct fscache_cookie *__fscache_acquire_cookie(
46029 parent ? (char *) parent->def->name : "<no-parent>",
46030 def->name, netfs_data);
46031
46032- fscache_stat(&fscache_n_acquires);
46033+ fscache_stat_unchecked(&fscache_n_acquires);
46034
46035 /* if there's no parent cookie, then we don't create one here either */
46036 if (!parent) {
46037- fscache_stat(&fscache_n_acquires_null);
46038+ fscache_stat_unchecked(&fscache_n_acquires_null);
46039 _leave(" [no parent]");
46040 return NULL;
46041 }
46042@@ -87,7 +87,7 @@ struct fscache_cookie *__fscache_acquire_cookie(
46043 /* allocate and initialise a cookie */
46044 cookie = kmem_cache_alloc(fscache_cookie_jar, GFP_KERNEL);
46045 if (!cookie) {
46046- fscache_stat(&fscache_n_acquires_oom);
46047+ fscache_stat_unchecked(&fscache_n_acquires_oom);
46048 _leave(" [ENOMEM]");
46049 return NULL;
46050 }
46051@@ -109,13 +109,13 @@ struct fscache_cookie *__fscache_acquire_cookie(
46052
46053 switch (cookie->def->type) {
46054 case FSCACHE_COOKIE_TYPE_INDEX:
46055- fscache_stat(&fscache_n_cookie_index);
46056+ fscache_stat_unchecked(&fscache_n_cookie_index);
46057 break;
46058 case FSCACHE_COOKIE_TYPE_DATAFILE:
46059- fscache_stat(&fscache_n_cookie_data);
46060+ fscache_stat_unchecked(&fscache_n_cookie_data);
46061 break;
46062 default:
46063- fscache_stat(&fscache_n_cookie_special);
46064+ fscache_stat_unchecked(&fscache_n_cookie_special);
46065 break;
46066 }
46067
46068@@ -126,13 +126,13 @@ struct fscache_cookie *__fscache_acquire_cookie(
46069 if (fscache_acquire_non_index_cookie(cookie) < 0) {
46070 atomic_dec(&parent->n_children);
46071 __fscache_cookie_put(cookie);
46072- fscache_stat(&fscache_n_acquires_nobufs);
46073+ fscache_stat_unchecked(&fscache_n_acquires_nobufs);
46074 _leave(" = NULL");
46075 return NULL;
46076 }
46077 }
46078
46079- fscache_stat(&fscache_n_acquires_ok);
46080+ fscache_stat_unchecked(&fscache_n_acquires_ok);
46081 _leave(" = %p", cookie);
46082 return cookie;
46083 }
46084@@ -168,7 +168,7 @@ static int fscache_acquire_non_index_cookie(struct fscache_cookie *cookie)
46085 cache = fscache_select_cache_for_object(cookie->parent);
46086 if (!cache) {
46087 up_read(&fscache_addremove_sem);
46088- fscache_stat(&fscache_n_acquires_no_cache);
46089+ fscache_stat_unchecked(&fscache_n_acquires_no_cache);
46090 _leave(" = -ENOMEDIUM [no cache]");
46091 return -ENOMEDIUM;
46092 }
46093@@ -256,12 +256,12 @@ static int fscache_alloc_object(struct fscache_cache *cache,
46094 object = cache->ops->alloc_object(cache, cookie);
46095 fscache_stat_d(&fscache_n_cop_alloc_object);
46096 if (IS_ERR(object)) {
46097- fscache_stat(&fscache_n_object_no_alloc);
46098+ fscache_stat_unchecked(&fscache_n_object_no_alloc);
46099 ret = PTR_ERR(object);
46100 goto error;
46101 }
46102
46103- fscache_stat(&fscache_n_object_alloc);
46104+ fscache_stat_unchecked(&fscache_n_object_alloc);
46105
46106 object->debug_id = atomic_inc_return(&fscache_object_debug_id);
46107
46108@@ -377,10 +377,10 @@ void __fscache_update_cookie(struct fscache_cookie *cookie)
46109 struct fscache_object *object;
46110 struct hlist_node *_p;
46111
46112- fscache_stat(&fscache_n_updates);
46113+ fscache_stat_unchecked(&fscache_n_updates);
46114
46115 if (!cookie) {
46116- fscache_stat(&fscache_n_updates_null);
46117+ fscache_stat_unchecked(&fscache_n_updates_null);
46118 _leave(" [no cookie]");
46119 return;
46120 }
46121@@ -414,12 +414,12 @@ void __fscache_relinquish_cookie(struct fscache_cookie *cookie, int retire)
46122 struct fscache_object *object;
46123 unsigned long event;
46124
46125- fscache_stat(&fscache_n_relinquishes);
46126+ fscache_stat_unchecked(&fscache_n_relinquishes);
46127 if (retire)
46128- fscache_stat(&fscache_n_relinquishes_retire);
46129+ fscache_stat_unchecked(&fscache_n_relinquishes_retire);
46130
46131 if (!cookie) {
46132- fscache_stat(&fscache_n_relinquishes_null);
46133+ fscache_stat_unchecked(&fscache_n_relinquishes_null);
46134 _leave(" [no cookie]");
46135 return;
46136 }
46137@@ -435,7 +435,7 @@ void __fscache_relinquish_cookie(struct fscache_cookie *cookie, int retire)
46138
46139 /* wait for the cookie to finish being instantiated (or to fail) */
46140 if (test_bit(FSCACHE_COOKIE_CREATING, &cookie->flags)) {
46141- fscache_stat(&fscache_n_relinquishes_waitcrt);
46142+ fscache_stat_unchecked(&fscache_n_relinquishes_waitcrt);
46143 wait_on_bit(&cookie->flags, FSCACHE_COOKIE_CREATING,
46144 fscache_wait_bit, TASK_UNINTERRUPTIBLE);
46145 }
46146diff --git a/fs/fscache/internal.h b/fs/fscache/internal.h
46147index f6aad48..88dcf26 100644
46148--- a/fs/fscache/internal.h
46149+++ b/fs/fscache/internal.h
46150@@ -144,94 +144,94 @@ extern void fscache_proc_cleanup(void);
46151 extern atomic_t fscache_n_ops_processed[FSCACHE_MAX_THREADS];
46152 extern atomic_t fscache_n_objs_processed[FSCACHE_MAX_THREADS];
46153
46154-extern atomic_t fscache_n_op_pend;
46155-extern atomic_t fscache_n_op_run;
46156-extern atomic_t fscache_n_op_enqueue;
46157-extern atomic_t fscache_n_op_deferred_release;
46158-extern atomic_t fscache_n_op_release;
46159-extern atomic_t fscache_n_op_gc;
46160-extern atomic_t fscache_n_op_cancelled;
46161-extern atomic_t fscache_n_op_rejected;
46162+extern atomic_unchecked_t fscache_n_op_pend;
46163+extern atomic_unchecked_t fscache_n_op_run;
46164+extern atomic_unchecked_t fscache_n_op_enqueue;
46165+extern atomic_unchecked_t fscache_n_op_deferred_release;
46166+extern atomic_unchecked_t fscache_n_op_release;
46167+extern atomic_unchecked_t fscache_n_op_gc;
46168+extern atomic_unchecked_t fscache_n_op_cancelled;
46169+extern atomic_unchecked_t fscache_n_op_rejected;
46170
46171-extern atomic_t fscache_n_attr_changed;
46172-extern atomic_t fscache_n_attr_changed_ok;
46173-extern atomic_t fscache_n_attr_changed_nobufs;
46174-extern atomic_t fscache_n_attr_changed_nomem;
46175-extern atomic_t fscache_n_attr_changed_calls;
46176+extern atomic_unchecked_t fscache_n_attr_changed;
46177+extern atomic_unchecked_t fscache_n_attr_changed_ok;
46178+extern atomic_unchecked_t fscache_n_attr_changed_nobufs;
46179+extern atomic_unchecked_t fscache_n_attr_changed_nomem;
46180+extern atomic_unchecked_t fscache_n_attr_changed_calls;
46181
46182-extern atomic_t fscache_n_allocs;
46183-extern atomic_t fscache_n_allocs_ok;
46184-extern atomic_t fscache_n_allocs_wait;
46185-extern atomic_t fscache_n_allocs_nobufs;
46186-extern atomic_t fscache_n_allocs_intr;
46187-extern atomic_t fscache_n_allocs_object_dead;
46188-extern atomic_t fscache_n_alloc_ops;
46189-extern atomic_t fscache_n_alloc_op_waits;
46190+extern atomic_unchecked_t fscache_n_allocs;
46191+extern atomic_unchecked_t fscache_n_allocs_ok;
46192+extern atomic_unchecked_t fscache_n_allocs_wait;
46193+extern atomic_unchecked_t fscache_n_allocs_nobufs;
46194+extern atomic_unchecked_t fscache_n_allocs_intr;
46195+extern atomic_unchecked_t fscache_n_allocs_object_dead;
46196+extern atomic_unchecked_t fscache_n_alloc_ops;
46197+extern atomic_unchecked_t fscache_n_alloc_op_waits;
46198
46199-extern atomic_t fscache_n_retrievals;
46200-extern atomic_t fscache_n_retrievals_ok;
46201-extern atomic_t fscache_n_retrievals_wait;
46202-extern atomic_t fscache_n_retrievals_nodata;
46203-extern atomic_t fscache_n_retrievals_nobufs;
46204-extern atomic_t fscache_n_retrievals_intr;
46205-extern atomic_t fscache_n_retrievals_nomem;
46206-extern atomic_t fscache_n_retrievals_object_dead;
46207-extern atomic_t fscache_n_retrieval_ops;
46208-extern atomic_t fscache_n_retrieval_op_waits;
46209+extern atomic_unchecked_t fscache_n_retrievals;
46210+extern atomic_unchecked_t fscache_n_retrievals_ok;
46211+extern atomic_unchecked_t fscache_n_retrievals_wait;
46212+extern atomic_unchecked_t fscache_n_retrievals_nodata;
46213+extern atomic_unchecked_t fscache_n_retrievals_nobufs;
46214+extern atomic_unchecked_t fscache_n_retrievals_intr;
46215+extern atomic_unchecked_t fscache_n_retrievals_nomem;
46216+extern atomic_unchecked_t fscache_n_retrievals_object_dead;
46217+extern atomic_unchecked_t fscache_n_retrieval_ops;
46218+extern atomic_unchecked_t fscache_n_retrieval_op_waits;
46219
46220-extern atomic_t fscache_n_stores;
46221-extern atomic_t fscache_n_stores_ok;
46222-extern atomic_t fscache_n_stores_again;
46223-extern atomic_t fscache_n_stores_nobufs;
46224-extern atomic_t fscache_n_stores_oom;
46225-extern atomic_t fscache_n_store_ops;
46226-extern atomic_t fscache_n_store_calls;
46227-extern atomic_t fscache_n_store_pages;
46228-extern atomic_t fscache_n_store_radix_deletes;
46229-extern atomic_t fscache_n_store_pages_over_limit;
46230+extern atomic_unchecked_t fscache_n_stores;
46231+extern atomic_unchecked_t fscache_n_stores_ok;
46232+extern atomic_unchecked_t fscache_n_stores_again;
46233+extern atomic_unchecked_t fscache_n_stores_nobufs;
46234+extern atomic_unchecked_t fscache_n_stores_oom;
46235+extern atomic_unchecked_t fscache_n_store_ops;
46236+extern atomic_unchecked_t fscache_n_store_calls;
46237+extern atomic_unchecked_t fscache_n_store_pages;
46238+extern atomic_unchecked_t fscache_n_store_radix_deletes;
46239+extern atomic_unchecked_t fscache_n_store_pages_over_limit;
46240
46241-extern atomic_t fscache_n_store_vmscan_not_storing;
46242-extern atomic_t fscache_n_store_vmscan_gone;
46243-extern atomic_t fscache_n_store_vmscan_busy;
46244-extern atomic_t fscache_n_store_vmscan_cancelled;
46245+extern atomic_unchecked_t fscache_n_store_vmscan_not_storing;
46246+extern atomic_unchecked_t fscache_n_store_vmscan_gone;
46247+extern atomic_unchecked_t fscache_n_store_vmscan_busy;
46248+extern atomic_unchecked_t fscache_n_store_vmscan_cancelled;
46249
46250-extern atomic_t fscache_n_marks;
46251-extern atomic_t fscache_n_uncaches;
46252+extern atomic_unchecked_t fscache_n_marks;
46253+extern atomic_unchecked_t fscache_n_uncaches;
46254
46255-extern atomic_t fscache_n_acquires;
46256-extern atomic_t fscache_n_acquires_null;
46257-extern atomic_t fscache_n_acquires_no_cache;
46258-extern atomic_t fscache_n_acquires_ok;
46259-extern atomic_t fscache_n_acquires_nobufs;
46260-extern atomic_t fscache_n_acquires_oom;
46261+extern atomic_unchecked_t fscache_n_acquires;
46262+extern atomic_unchecked_t fscache_n_acquires_null;
46263+extern atomic_unchecked_t fscache_n_acquires_no_cache;
46264+extern atomic_unchecked_t fscache_n_acquires_ok;
46265+extern atomic_unchecked_t fscache_n_acquires_nobufs;
46266+extern atomic_unchecked_t fscache_n_acquires_oom;
46267
46268-extern atomic_t fscache_n_updates;
46269-extern atomic_t fscache_n_updates_null;
46270-extern atomic_t fscache_n_updates_run;
46271+extern atomic_unchecked_t fscache_n_updates;
46272+extern atomic_unchecked_t fscache_n_updates_null;
46273+extern atomic_unchecked_t fscache_n_updates_run;
46274
46275-extern atomic_t fscache_n_relinquishes;
46276-extern atomic_t fscache_n_relinquishes_null;
46277-extern atomic_t fscache_n_relinquishes_waitcrt;
46278-extern atomic_t fscache_n_relinquishes_retire;
46279+extern atomic_unchecked_t fscache_n_relinquishes;
46280+extern atomic_unchecked_t fscache_n_relinquishes_null;
46281+extern atomic_unchecked_t fscache_n_relinquishes_waitcrt;
46282+extern atomic_unchecked_t fscache_n_relinquishes_retire;
46283
46284-extern atomic_t fscache_n_cookie_index;
46285-extern atomic_t fscache_n_cookie_data;
46286-extern atomic_t fscache_n_cookie_special;
46287+extern atomic_unchecked_t fscache_n_cookie_index;
46288+extern atomic_unchecked_t fscache_n_cookie_data;
46289+extern atomic_unchecked_t fscache_n_cookie_special;
46290
46291-extern atomic_t fscache_n_object_alloc;
46292-extern atomic_t fscache_n_object_no_alloc;
46293-extern atomic_t fscache_n_object_lookups;
46294-extern atomic_t fscache_n_object_lookups_negative;
46295-extern atomic_t fscache_n_object_lookups_positive;
46296-extern atomic_t fscache_n_object_lookups_timed_out;
46297-extern atomic_t fscache_n_object_created;
46298-extern atomic_t fscache_n_object_avail;
46299-extern atomic_t fscache_n_object_dead;
46300+extern atomic_unchecked_t fscache_n_object_alloc;
46301+extern atomic_unchecked_t fscache_n_object_no_alloc;
46302+extern atomic_unchecked_t fscache_n_object_lookups;
46303+extern atomic_unchecked_t fscache_n_object_lookups_negative;
46304+extern atomic_unchecked_t fscache_n_object_lookups_positive;
46305+extern atomic_unchecked_t fscache_n_object_lookups_timed_out;
46306+extern atomic_unchecked_t fscache_n_object_created;
46307+extern atomic_unchecked_t fscache_n_object_avail;
46308+extern atomic_unchecked_t fscache_n_object_dead;
46309
46310-extern atomic_t fscache_n_checkaux_none;
46311-extern atomic_t fscache_n_checkaux_okay;
46312-extern atomic_t fscache_n_checkaux_update;
46313-extern atomic_t fscache_n_checkaux_obsolete;
46314+extern atomic_unchecked_t fscache_n_checkaux_none;
46315+extern atomic_unchecked_t fscache_n_checkaux_okay;
46316+extern atomic_unchecked_t fscache_n_checkaux_update;
46317+extern atomic_unchecked_t fscache_n_checkaux_obsolete;
46318
46319 extern atomic_t fscache_n_cop_alloc_object;
46320 extern atomic_t fscache_n_cop_lookup_object;
46321@@ -255,6 +255,11 @@ static inline void fscache_stat(atomic_t *stat)
46322 atomic_inc(stat);
46323 }
46324
46325+static inline void fscache_stat_unchecked(atomic_unchecked_t *stat)
46326+{
46327+ atomic_inc_unchecked(stat);
46328+}
46329+
46330 static inline void fscache_stat_d(atomic_t *stat)
46331 {
46332 atomic_dec(stat);
46333@@ -267,6 +272,7 @@ extern const struct file_operations fscache_stats_fops;
46334
46335 #define __fscache_stat(stat) (NULL)
46336 #define fscache_stat(stat) do {} while (0)
46337+#define fscache_stat_unchecked(stat) do {} while (0)
46338 #define fscache_stat_d(stat) do {} while (0)
46339 #endif
46340
46341diff --git a/fs/fscache/object.c b/fs/fscache/object.c
46342index b6b897c..0ffff9c 100644
46343--- a/fs/fscache/object.c
46344+++ b/fs/fscache/object.c
46345@@ -128,7 +128,7 @@ static void fscache_object_state_machine(struct fscache_object *object)
46346 /* update the object metadata on disk */
46347 case FSCACHE_OBJECT_UPDATING:
46348 clear_bit(FSCACHE_OBJECT_EV_UPDATE, &object->events);
46349- fscache_stat(&fscache_n_updates_run);
46350+ fscache_stat_unchecked(&fscache_n_updates_run);
46351 fscache_stat(&fscache_n_cop_update_object);
46352 object->cache->ops->update_object(object);
46353 fscache_stat_d(&fscache_n_cop_update_object);
46354@@ -217,7 +217,7 @@ static void fscache_object_state_machine(struct fscache_object *object)
46355 spin_lock(&object->lock);
46356 object->state = FSCACHE_OBJECT_DEAD;
46357 spin_unlock(&object->lock);
46358- fscache_stat(&fscache_n_object_dead);
46359+ fscache_stat_unchecked(&fscache_n_object_dead);
46360 goto terminal_transit;
46361
46362 /* handle the parent cache of this object being withdrawn from
46363@@ -232,7 +232,7 @@ static void fscache_object_state_machine(struct fscache_object *object)
46364 spin_lock(&object->lock);
46365 object->state = FSCACHE_OBJECT_DEAD;
46366 spin_unlock(&object->lock);
46367- fscache_stat(&fscache_n_object_dead);
46368+ fscache_stat_unchecked(&fscache_n_object_dead);
46369 goto terminal_transit;
46370
46371 /* complain about the object being woken up once it is
46372@@ -461,7 +461,7 @@ static void fscache_lookup_object(struct fscache_object *object)
46373 parent->cookie->def->name, cookie->def->name,
46374 object->cache->tag->name);
46375
46376- fscache_stat(&fscache_n_object_lookups);
46377+ fscache_stat_unchecked(&fscache_n_object_lookups);
46378 fscache_stat(&fscache_n_cop_lookup_object);
46379 ret = object->cache->ops->lookup_object(object);
46380 fscache_stat_d(&fscache_n_cop_lookup_object);
46381@@ -472,7 +472,7 @@ static void fscache_lookup_object(struct fscache_object *object)
46382 if (ret == -ETIMEDOUT) {
46383 /* probably stuck behind another object, so move this one to
46384 * the back of the queue */
46385- fscache_stat(&fscache_n_object_lookups_timed_out);
46386+ fscache_stat_unchecked(&fscache_n_object_lookups_timed_out);
46387 set_bit(FSCACHE_OBJECT_EV_REQUEUE, &object->events);
46388 }
46389
46390@@ -495,7 +495,7 @@ void fscache_object_lookup_negative(struct fscache_object *object)
46391
46392 spin_lock(&object->lock);
46393 if (object->state == FSCACHE_OBJECT_LOOKING_UP) {
46394- fscache_stat(&fscache_n_object_lookups_negative);
46395+ fscache_stat_unchecked(&fscache_n_object_lookups_negative);
46396
46397 /* transit here to allow write requests to begin stacking up
46398 * and read requests to begin returning ENODATA */
46399@@ -541,7 +541,7 @@ void fscache_obtained_object(struct fscache_object *object)
46400 * result, in which case there may be data available */
46401 spin_lock(&object->lock);
46402 if (object->state == FSCACHE_OBJECT_LOOKING_UP) {
46403- fscache_stat(&fscache_n_object_lookups_positive);
46404+ fscache_stat_unchecked(&fscache_n_object_lookups_positive);
46405
46406 clear_bit(FSCACHE_COOKIE_NO_DATA_YET, &cookie->flags);
46407
46408@@ -555,7 +555,7 @@ void fscache_obtained_object(struct fscache_object *object)
46409 set_bit(FSCACHE_OBJECT_EV_REQUEUE, &object->events);
46410 } else {
46411 ASSERTCMP(object->state, ==, FSCACHE_OBJECT_CREATING);
46412- fscache_stat(&fscache_n_object_created);
46413+ fscache_stat_unchecked(&fscache_n_object_created);
46414
46415 object->state = FSCACHE_OBJECT_AVAILABLE;
46416 spin_unlock(&object->lock);
46417@@ -602,7 +602,7 @@ static void fscache_object_available(struct fscache_object *object)
46418 fscache_enqueue_dependents(object);
46419
46420 fscache_hist(fscache_obj_instantiate_histogram, object->lookup_jif);
46421- fscache_stat(&fscache_n_object_avail);
46422+ fscache_stat_unchecked(&fscache_n_object_avail);
46423
46424 _leave("");
46425 }
46426@@ -861,7 +861,7 @@ enum fscache_checkaux fscache_check_aux(struct fscache_object *object,
46427 enum fscache_checkaux result;
46428
46429 if (!object->cookie->def->check_aux) {
46430- fscache_stat(&fscache_n_checkaux_none);
46431+ fscache_stat_unchecked(&fscache_n_checkaux_none);
46432 return FSCACHE_CHECKAUX_OKAY;
46433 }
46434
46435@@ -870,17 +870,17 @@ enum fscache_checkaux fscache_check_aux(struct fscache_object *object,
46436 switch (result) {
46437 /* entry okay as is */
46438 case FSCACHE_CHECKAUX_OKAY:
46439- fscache_stat(&fscache_n_checkaux_okay);
46440+ fscache_stat_unchecked(&fscache_n_checkaux_okay);
46441 break;
46442
46443 /* entry requires update */
46444 case FSCACHE_CHECKAUX_NEEDS_UPDATE:
46445- fscache_stat(&fscache_n_checkaux_update);
46446+ fscache_stat_unchecked(&fscache_n_checkaux_update);
46447 break;
46448
46449 /* entry requires deletion */
46450 case FSCACHE_CHECKAUX_OBSOLETE:
46451- fscache_stat(&fscache_n_checkaux_obsolete);
46452+ fscache_stat_unchecked(&fscache_n_checkaux_obsolete);
46453 break;
46454
46455 default:
46456diff --git a/fs/fscache/operation.c b/fs/fscache/operation.c
46457index 30afdfa..2256596 100644
46458--- a/fs/fscache/operation.c
46459+++ b/fs/fscache/operation.c
46460@@ -17,7 +17,7 @@
46461 #include <linux/slab.h>
46462 #include "internal.h"
46463
46464-atomic_t fscache_op_debug_id;
46465+atomic_unchecked_t fscache_op_debug_id;
46466 EXPORT_SYMBOL(fscache_op_debug_id);
46467
46468 /**
46469@@ -38,7 +38,7 @@ void fscache_enqueue_operation(struct fscache_operation *op)
46470 ASSERTCMP(op->object->state, >=, FSCACHE_OBJECT_AVAILABLE);
46471 ASSERTCMP(atomic_read(&op->usage), >, 0);
46472
46473- fscache_stat(&fscache_n_op_enqueue);
46474+ fscache_stat_unchecked(&fscache_n_op_enqueue);
46475 switch (op->flags & FSCACHE_OP_TYPE) {
46476 case FSCACHE_OP_ASYNC:
46477 _debug("queue async");
46478@@ -69,7 +69,7 @@ static void fscache_run_op(struct fscache_object *object,
46479 wake_up_bit(&op->flags, FSCACHE_OP_WAITING);
46480 if (op->processor)
46481 fscache_enqueue_operation(op);
46482- fscache_stat(&fscache_n_op_run);
46483+ fscache_stat_unchecked(&fscache_n_op_run);
46484 }
46485
46486 /*
46487@@ -98,11 +98,11 @@ int fscache_submit_exclusive_op(struct fscache_object *object,
46488 if (object->n_ops > 1) {
46489 atomic_inc(&op->usage);
46490 list_add_tail(&op->pend_link, &object->pending_ops);
46491- fscache_stat(&fscache_n_op_pend);
46492+ fscache_stat_unchecked(&fscache_n_op_pend);
46493 } else if (!list_empty(&object->pending_ops)) {
46494 atomic_inc(&op->usage);
46495 list_add_tail(&op->pend_link, &object->pending_ops);
46496- fscache_stat(&fscache_n_op_pend);
46497+ fscache_stat_unchecked(&fscache_n_op_pend);
46498 fscache_start_operations(object);
46499 } else {
46500 ASSERTCMP(object->n_in_progress, ==, 0);
46501@@ -118,7 +118,7 @@ int fscache_submit_exclusive_op(struct fscache_object *object,
46502 object->n_exclusive++; /* reads and writes must wait */
46503 atomic_inc(&op->usage);
46504 list_add_tail(&op->pend_link, &object->pending_ops);
46505- fscache_stat(&fscache_n_op_pend);
46506+ fscache_stat_unchecked(&fscache_n_op_pend);
46507 ret = 0;
46508 } else {
46509 /* not allowed to submit ops in any other state */
46510@@ -203,11 +203,11 @@ int fscache_submit_op(struct fscache_object *object,
46511 if (object->n_exclusive > 0) {
46512 atomic_inc(&op->usage);
46513 list_add_tail(&op->pend_link, &object->pending_ops);
46514- fscache_stat(&fscache_n_op_pend);
46515+ fscache_stat_unchecked(&fscache_n_op_pend);
46516 } else if (!list_empty(&object->pending_ops)) {
46517 atomic_inc(&op->usage);
46518 list_add_tail(&op->pend_link, &object->pending_ops);
46519- fscache_stat(&fscache_n_op_pend);
46520+ fscache_stat_unchecked(&fscache_n_op_pend);
46521 fscache_start_operations(object);
46522 } else {
46523 ASSERTCMP(object->n_exclusive, ==, 0);
46524@@ -219,12 +219,12 @@ int fscache_submit_op(struct fscache_object *object,
46525 object->n_ops++;
46526 atomic_inc(&op->usage);
46527 list_add_tail(&op->pend_link, &object->pending_ops);
46528- fscache_stat(&fscache_n_op_pend);
46529+ fscache_stat_unchecked(&fscache_n_op_pend);
46530 ret = 0;
46531 } else if (object->state == FSCACHE_OBJECT_DYING ||
46532 object->state == FSCACHE_OBJECT_LC_DYING ||
46533 object->state == FSCACHE_OBJECT_WITHDRAWING) {
46534- fscache_stat(&fscache_n_op_rejected);
46535+ fscache_stat_unchecked(&fscache_n_op_rejected);
46536 ret = -ENOBUFS;
46537 } else if (!test_bit(FSCACHE_IOERROR, &object->cache->flags)) {
46538 fscache_report_unexpected_submission(object, op, ostate);
46539@@ -294,7 +294,7 @@ int fscache_cancel_op(struct fscache_operation *op)
46540
46541 ret = -EBUSY;
46542 if (!list_empty(&op->pend_link)) {
46543- fscache_stat(&fscache_n_op_cancelled);
46544+ fscache_stat_unchecked(&fscache_n_op_cancelled);
46545 list_del_init(&op->pend_link);
46546 object->n_ops--;
46547 if (test_bit(FSCACHE_OP_EXCLUSIVE, &op->flags))
46548@@ -331,7 +331,7 @@ void fscache_put_operation(struct fscache_operation *op)
46549 if (test_and_set_bit(FSCACHE_OP_DEAD, &op->flags))
46550 BUG();
46551
46552- fscache_stat(&fscache_n_op_release);
46553+ fscache_stat_unchecked(&fscache_n_op_release);
46554
46555 if (op->release) {
46556 op->release(op);
46557@@ -348,7 +348,7 @@ void fscache_put_operation(struct fscache_operation *op)
46558 * lock, and defer it otherwise */
46559 if (!spin_trylock(&object->lock)) {
46560 _debug("defer put");
46561- fscache_stat(&fscache_n_op_deferred_release);
46562+ fscache_stat_unchecked(&fscache_n_op_deferred_release);
46563
46564 cache = object->cache;
46565 spin_lock(&cache->op_gc_list_lock);
46566@@ -410,7 +410,7 @@ void fscache_operation_gc(struct work_struct *work)
46567
46568 _debug("GC DEFERRED REL OBJ%x OP%x",
46569 object->debug_id, op->debug_id);
46570- fscache_stat(&fscache_n_op_gc);
46571+ fscache_stat_unchecked(&fscache_n_op_gc);
46572
46573 ASSERTCMP(atomic_read(&op->usage), ==, 0);
46574
46575diff --git a/fs/fscache/page.c b/fs/fscache/page.c
46576index 3f7a59b..cf196cc 100644
46577--- a/fs/fscache/page.c
46578+++ b/fs/fscache/page.c
46579@@ -60,7 +60,7 @@ bool __fscache_maybe_release_page(struct fscache_cookie *cookie,
46580 val = radix_tree_lookup(&cookie->stores, page->index);
46581 if (!val) {
46582 rcu_read_unlock();
46583- fscache_stat(&fscache_n_store_vmscan_not_storing);
46584+ fscache_stat_unchecked(&fscache_n_store_vmscan_not_storing);
46585 __fscache_uncache_page(cookie, page);
46586 return true;
46587 }
46588@@ -90,11 +90,11 @@ bool __fscache_maybe_release_page(struct fscache_cookie *cookie,
46589 spin_unlock(&cookie->stores_lock);
46590
46591 if (xpage) {
46592- fscache_stat(&fscache_n_store_vmscan_cancelled);
46593- fscache_stat(&fscache_n_store_radix_deletes);
46594+ fscache_stat_unchecked(&fscache_n_store_vmscan_cancelled);
46595+ fscache_stat_unchecked(&fscache_n_store_radix_deletes);
46596 ASSERTCMP(xpage, ==, page);
46597 } else {
46598- fscache_stat(&fscache_n_store_vmscan_gone);
46599+ fscache_stat_unchecked(&fscache_n_store_vmscan_gone);
46600 }
46601
46602 wake_up_bit(&cookie->flags, 0);
46603@@ -107,7 +107,7 @@ page_busy:
46604 /* we might want to wait here, but that could deadlock the allocator as
46605 * the work threads writing to the cache may all end up sleeping
46606 * on memory allocation */
46607- fscache_stat(&fscache_n_store_vmscan_busy);
46608+ fscache_stat_unchecked(&fscache_n_store_vmscan_busy);
46609 return false;
46610 }
46611 EXPORT_SYMBOL(__fscache_maybe_release_page);
46612@@ -131,7 +131,7 @@ static void fscache_end_page_write(struct fscache_object *object,
46613 FSCACHE_COOKIE_STORING_TAG);
46614 if (!radix_tree_tag_get(&cookie->stores, page->index,
46615 FSCACHE_COOKIE_PENDING_TAG)) {
46616- fscache_stat(&fscache_n_store_radix_deletes);
46617+ fscache_stat_unchecked(&fscache_n_store_radix_deletes);
46618 xpage = radix_tree_delete(&cookie->stores, page->index);
46619 }
46620 spin_unlock(&cookie->stores_lock);
46621@@ -152,7 +152,7 @@ static void fscache_attr_changed_op(struct fscache_operation *op)
46622
46623 _enter("{OBJ%x OP%x}", object->debug_id, op->debug_id);
46624
46625- fscache_stat(&fscache_n_attr_changed_calls);
46626+ fscache_stat_unchecked(&fscache_n_attr_changed_calls);
46627
46628 if (fscache_object_is_active(object)) {
46629 fscache_stat(&fscache_n_cop_attr_changed);
46630@@ -177,11 +177,11 @@ int __fscache_attr_changed(struct fscache_cookie *cookie)
46631
46632 ASSERTCMP(cookie->def->type, !=, FSCACHE_COOKIE_TYPE_INDEX);
46633
46634- fscache_stat(&fscache_n_attr_changed);
46635+ fscache_stat_unchecked(&fscache_n_attr_changed);
46636
46637 op = kzalloc(sizeof(*op), GFP_KERNEL);
46638 if (!op) {
46639- fscache_stat(&fscache_n_attr_changed_nomem);
46640+ fscache_stat_unchecked(&fscache_n_attr_changed_nomem);
46641 _leave(" = -ENOMEM");
46642 return -ENOMEM;
46643 }
46644@@ -199,7 +199,7 @@ int __fscache_attr_changed(struct fscache_cookie *cookie)
46645 if (fscache_submit_exclusive_op(object, op) < 0)
46646 goto nobufs;
46647 spin_unlock(&cookie->lock);
46648- fscache_stat(&fscache_n_attr_changed_ok);
46649+ fscache_stat_unchecked(&fscache_n_attr_changed_ok);
46650 fscache_put_operation(op);
46651 _leave(" = 0");
46652 return 0;
46653@@ -207,7 +207,7 @@ int __fscache_attr_changed(struct fscache_cookie *cookie)
46654 nobufs:
46655 spin_unlock(&cookie->lock);
46656 kfree(op);
46657- fscache_stat(&fscache_n_attr_changed_nobufs);
46658+ fscache_stat_unchecked(&fscache_n_attr_changed_nobufs);
46659 _leave(" = %d", -ENOBUFS);
46660 return -ENOBUFS;
46661 }
46662@@ -243,7 +243,7 @@ static struct fscache_retrieval *fscache_alloc_retrieval(
46663 /* allocate a retrieval operation and attempt to submit it */
46664 op = kzalloc(sizeof(*op), GFP_NOIO);
46665 if (!op) {
46666- fscache_stat(&fscache_n_retrievals_nomem);
46667+ fscache_stat_unchecked(&fscache_n_retrievals_nomem);
46668 return NULL;
46669 }
46670
46671@@ -271,13 +271,13 @@ static int fscache_wait_for_deferred_lookup(struct fscache_cookie *cookie)
46672 return 0;
46673 }
46674
46675- fscache_stat(&fscache_n_retrievals_wait);
46676+ fscache_stat_unchecked(&fscache_n_retrievals_wait);
46677
46678 jif = jiffies;
46679 if (wait_on_bit(&cookie->flags, FSCACHE_COOKIE_LOOKING_UP,
46680 fscache_wait_bit_interruptible,
46681 TASK_INTERRUPTIBLE) != 0) {
46682- fscache_stat(&fscache_n_retrievals_intr);
46683+ fscache_stat_unchecked(&fscache_n_retrievals_intr);
46684 _leave(" = -ERESTARTSYS");
46685 return -ERESTARTSYS;
46686 }
46687@@ -295,8 +295,8 @@ static int fscache_wait_for_deferred_lookup(struct fscache_cookie *cookie)
46688 */
46689 static int fscache_wait_for_retrieval_activation(struct fscache_object *object,
46690 struct fscache_retrieval *op,
46691- atomic_t *stat_op_waits,
46692- atomic_t *stat_object_dead)
46693+ atomic_unchecked_t *stat_op_waits,
46694+ atomic_unchecked_t *stat_object_dead)
46695 {
46696 int ret;
46697
46698@@ -304,7 +304,7 @@ static int fscache_wait_for_retrieval_activation(struct fscache_object *object,
46699 goto check_if_dead;
46700
46701 _debug(">>> WT");
46702- fscache_stat(stat_op_waits);
46703+ fscache_stat_unchecked(stat_op_waits);
46704 if (wait_on_bit(&op->op.flags, FSCACHE_OP_WAITING,
46705 fscache_wait_bit_interruptible,
46706 TASK_INTERRUPTIBLE) < 0) {
46707@@ -321,7 +321,7 @@ static int fscache_wait_for_retrieval_activation(struct fscache_object *object,
46708
46709 check_if_dead:
46710 if (unlikely(fscache_object_is_dead(object))) {
46711- fscache_stat(stat_object_dead);
46712+ fscache_stat_unchecked(stat_object_dead);
46713 return -ENOBUFS;
46714 }
46715 return 0;
46716@@ -348,7 +348,7 @@ int __fscache_read_or_alloc_page(struct fscache_cookie *cookie,
46717
46718 _enter("%p,%p,,,", cookie, page);
46719
46720- fscache_stat(&fscache_n_retrievals);
46721+ fscache_stat_unchecked(&fscache_n_retrievals);
46722
46723 if (hlist_empty(&cookie->backing_objects))
46724 goto nobufs;
46725@@ -381,7 +381,7 @@ int __fscache_read_or_alloc_page(struct fscache_cookie *cookie,
46726 goto nobufs_unlock;
46727 spin_unlock(&cookie->lock);
46728
46729- fscache_stat(&fscache_n_retrieval_ops);
46730+ fscache_stat_unchecked(&fscache_n_retrieval_ops);
46731
46732 /* pin the netfs read context in case we need to do the actual netfs
46733 * read because we've encountered a cache read failure */
46734@@ -411,15 +411,15 @@ int __fscache_read_or_alloc_page(struct fscache_cookie *cookie,
46735
46736 error:
46737 if (ret == -ENOMEM)
46738- fscache_stat(&fscache_n_retrievals_nomem);
46739+ fscache_stat_unchecked(&fscache_n_retrievals_nomem);
46740 else if (ret == -ERESTARTSYS)
46741- fscache_stat(&fscache_n_retrievals_intr);
46742+ fscache_stat_unchecked(&fscache_n_retrievals_intr);
46743 else if (ret == -ENODATA)
46744- fscache_stat(&fscache_n_retrievals_nodata);
46745+ fscache_stat_unchecked(&fscache_n_retrievals_nodata);
46746 else if (ret < 0)
46747- fscache_stat(&fscache_n_retrievals_nobufs);
46748+ fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
46749 else
46750- fscache_stat(&fscache_n_retrievals_ok);
46751+ fscache_stat_unchecked(&fscache_n_retrievals_ok);
46752
46753 fscache_put_retrieval(op);
46754 _leave(" = %d", ret);
46755@@ -429,7 +429,7 @@ nobufs_unlock:
46756 spin_unlock(&cookie->lock);
46757 kfree(op);
46758 nobufs:
46759- fscache_stat(&fscache_n_retrievals_nobufs);
46760+ fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
46761 _leave(" = -ENOBUFS");
46762 return -ENOBUFS;
46763 }
46764@@ -467,7 +467,7 @@ int __fscache_read_or_alloc_pages(struct fscache_cookie *cookie,
46765
46766 _enter("%p,,%d,,,", cookie, *nr_pages);
46767
46768- fscache_stat(&fscache_n_retrievals);
46769+ fscache_stat_unchecked(&fscache_n_retrievals);
46770
46771 if (hlist_empty(&cookie->backing_objects))
46772 goto nobufs;
46773@@ -497,7 +497,7 @@ int __fscache_read_or_alloc_pages(struct fscache_cookie *cookie,
46774 goto nobufs_unlock;
46775 spin_unlock(&cookie->lock);
46776
46777- fscache_stat(&fscache_n_retrieval_ops);
46778+ fscache_stat_unchecked(&fscache_n_retrieval_ops);
46779
46780 /* pin the netfs read context in case we need to do the actual netfs
46781 * read because we've encountered a cache read failure */
46782@@ -527,15 +527,15 @@ int __fscache_read_or_alloc_pages(struct fscache_cookie *cookie,
46783
46784 error:
46785 if (ret == -ENOMEM)
46786- fscache_stat(&fscache_n_retrievals_nomem);
46787+ fscache_stat_unchecked(&fscache_n_retrievals_nomem);
46788 else if (ret == -ERESTARTSYS)
46789- fscache_stat(&fscache_n_retrievals_intr);
46790+ fscache_stat_unchecked(&fscache_n_retrievals_intr);
46791 else if (ret == -ENODATA)
46792- fscache_stat(&fscache_n_retrievals_nodata);
46793+ fscache_stat_unchecked(&fscache_n_retrievals_nodata);
46794 else if (ret < 0)
46795- fscache_stat(&fscache_n_retrievals_nobufs);
46796+ fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
46797 else
46798- fscache_stat(&fscache_n_retrievals_ok);
46799+ fscache_stat_unchecked(&fscache_n_retrievals_ok);
46800
46801 fscache_put_retrieval(op);
46802 _leave(" = %d", ret);
46803@@ -545,7 +545,7 @@ nobufs_unlock:
46804 spin_unlock(&cookie->lock);
46805 kfree(op);
46806 nobufs:
46807- fscache_stat(&fscache_n_retrievals_nobufs);
46808+ fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
46809 _leave(" = -ENOBUFS");
46810 return -ENOBUFS;
46811 }
46812@@ -569,7 +569,7 @@ int __fscache_alloc_page(struct fscache_cookie *cookie,
46813
46814 _enter("%p,%p,,,", cookie, page);
46815
46816- fscache_stat(&fscache_n_allocs);
46817+ fscache_stat_unchecked(&fscache_n_allocs);
46818
46819 if (hlist_empty(&cookie->backing_objects))
46820 goto nobufs;
46821@@ -595,7 +595,7 @@ int __fscache_alloc_page(struct fscache_cookie *cookie,
46822 goto nobufs_unlock;
46823 spin_unlock(&cookie->lock);
46824
46825- fscache_stat(&fscache_n_alloc_ops);
46826+ fscache_stat_unchecked(&fscache_n_alloc_ops);
46827
46828 ret = fscache_wait_for_retrieval_activation(
46829 object, op,
46830@@ -611,11 +611,11 @@ int __fscache_alloc_page(struct fscache_cookie *cookie,
46831
46832 error:
46833 if (ret == -ERESTARTSYS)
46834- fscache_stat(&fscache_n_allocs_intr);
46835+ fscache_stat_unchecked(&fscache_n_allocs_intr);
46836 else if (ret < 0)
46837- fscache_stat(&fscache_n_allocs_nobufs);
46838+ fscache_stat_unchecked(&fscache_n_allocs_nobufs);
46839 else
46840- fscache_stat(&fscache_n_allocs_ok);
46841+ fscache_stat_unchecked(&fscache_n_allocs_ok);
46842
46843 fscache_put_retrieval(op);
46844 _leave(" = %d", ret);
46845@@ -625,7 +625,7 @@ nobufs_unlock:
46846 spin_unlock(&cookie->lock);
46847 kfree(op);
46848 nobufs:
46849- fscache_stat(&fscache_n_allocs_nobufs);
46850+ fscache_stat_unchecked(&fscache_n_allocs_nobufs);
46851 _leave(" = -ENOBUFS");
46852 return -ENOBUFS;
46853 }
46854@@ -666,7 +666,7 @@ static void fscache_write_op(struct fscache_operation *_op)
46855
46856 spin_lock(&cookie->stores_lock);
46857
46858- fscache_stat(&fscache_n_store_calls);
46859+ fscache_stat_unchecked(&fscache_n_store_calls);
46860
46861 /* find a page to store */
46862 page = NULL;
46863@@ -677,7 +677,7 @@ static void fscache_write_op(struct fscache_operation *_op)
46864 page = results[0];
46865 _debug("gang %d [%lx]", n, page->index);
46866 if (page->index > op->store_limit) {
46867- fscache_stat(&fscache_n_store_pages_over_limit);
46868+ fscache_stat_unchecked(&fscache_n_store_pages_over_limit);
46869 goto superseded;
46870 }
46871
46872@@ -689,7 +689,7 @@ static void fscache_write_op(struct fscache_operation *_op)
46873 spin_unlock(&cookie->stores_lock);
46874 spin_unlock(&object->lock);
46875
46876- fscache_stat(&fscache_n_store_pages);
46877+ fscache_stat_unchecked(&fscache_n_store_pages);
46878 fscache_stat(&fscache_n_cop_write_page);
46879 ret = object->cache->ops->write_page(op, page);
46880 fscache_stat_d(&fscache_n_cop_write_page);
46881@@ -757,7 +757,7 @@ int __fscache_write_page(struct fscache_cookie *cookie,
46882 ASSERTCMP(cookie->def->type, !=, FSCACHE_COOKIE_TYPE_INDEX);
46883 ASSERT(PageFsCache(page));
46884
46885- fscache_stat(&fscache_n_stores);
46886+ fscache_stat_unchecked(&fscache_n_stores);
46887
46888 op = kzalloc(sizeof(*op), GFP_NOIO);
46889 if (!op)
46890@@ -808,7 +808,7 @@ int __fscache_write_page(struct fscache_cookie *cookie,
46891 spin_unlock(&cookie->stores_lock);
46892 spin_unlock(&object->lock);
46893
46894- op->op.debug_id = atomic_inc_return(&fscache_op_debug_id);
46895+ op->op.debug_id = atomic_inc_return_unchecked(&fscache_op_debug_id);
46896 op->store_limit = object->store_limit;
46897
46898 if (fscache_submit_op(object, &op->op) < 0)
46899@@ -816,8 +816,8 @@ int __fscache_write_page(struct fscache_cookie *cookie,
46900
46901 spin_unlock(&cookie->lock);
46902 radix_tree_preload_end();
46903- fscache_stat(&fscache_n_store_ops);
46904- fscache_stat(&fscache_n_stores_ok);
46905+ fscache_stat_unchecked(&fscache_n_store_ops);
46906+ fscache_stat_unchecked(&fscache_n_stores_ok);
46907
46908 /* the work queue now carries its own ref on the object */
46909 fscache_put_operation(&op->op);
46910@@ -825,14 +825,14 @@ int __fscache_write_page(struct fscache_cookie *cookie,
46911 return 0;
46912
46913 already_queued:
46914- fscache_stat(&fscache_n_stores_again);
46915+ fscache_stat_unchecked(&fscache_n_stores_again);
46916 already_pending:
46917 spin_unlock(&cookie->stores_lock);
46918 spin_unlock(&object->lock);
46919 spin_unlock(&cookie->lock);
46920 radix_tree_preload_end();
46921 kfree(op);
46922- fscache_stat(&fscache_n_stores_ok);
46923+ fscache_stat_unchecked(&fscache_n_stores_ok);
46924 _leave(" = 0");
46925 return 0;
46926
46927@@ -851,14 +851,14 @@ nobufs:
46928 spin_unlock(&cookie->lock);
46929 radix_tree_preload_end();
46930 kfree(op);
46931- fscache_stat(&fscache_n_stores_nobufs);
46932+ fscache_stat_unchecked(&fscache_n_stores_nobufs);
46933 _leave(" = -ENOBUFS");
46934 return -ENOBUFS;
46935
46936 nomem_free:
46937 kfree(op);
46938 nomem:
46939- fscache_stat(&fscache_n_stores_oom);
46940+ fscache_stat_unchecked(&fscache_n_stores_oom);
46941 _leave(" = -ENOMEM");
46942 return -ENOMEM;
46943 }
46944@@ -876,7 +876,7 @@ void __fscache_uncache_page(struct fscache_cookie *cookie, struct page *page)
46945 ASSERTCMP(cookie->def->type, !=, FSCACHE_COOKIE_TYPE_INDEX);
46946 ASSERTCMP(page, !=, NULL);
46947
46948- fscache_stat(&fscache_n_uncaches);
46949+ fscache_stat_unchecked(&fscache_n_uncaches);
46950
46951 /* cache withdrawal may beat us to it */
46952 if (!PageFsCache(page))
46953@@ -929,7 +929,7 @@ void fscache_mark_pages_cached(struct fscache_retrieval *op,
46954 unsigned long loop;
46955
46956 #ifdef CONFIG_FSCACHE_STATS
46957- atomic_add(pagevec->nr, &fscache_n_marks);
46958+ atomic_add_unchecked(pagevec->nr, &fscache_n_marks);
46959 #endif
46960
46961 for (loop = 0; loop < pagevec->nr; loop++) {
46962diff --git a/fs/fscache/stats.c b/fs/fscache/stats.c
46963index 4765190..2a067f2 100644
46964--- a/fs/fscache/stats.c
46965+++ b/fs/fscache/stats.c
46966@@ -18,95 +18,95 @@
46967 /*
46968 * operation counters
46969 */
46970-atomic_t fscache_n_op_pend;
46971-atomic_t fscache_n_op_run;
46972-atomic_t fscache_n_op_enqueue;
46973-atomic_t fscache_n_op_requeue;
46974-atomic_t fscache_n_op_deferred_release;
46975-atomic_t fscache_n_op_release;
46976-atomic_t fscache_n_op_gc;
46977-atomic_t fscache_n_op_cancelled;
46978-atomic_t fscache_n_op_rejected;
46979+atomic_unchecked_t fscache_n_op_pend;
46980+atomic_unchecked_t fscache_n_op_run;
46981+atomic_unchecked_t fscache_n_op_enqueue;
46982+atomic_unchecked_t fscache_n_op_requeue;
46983+atomic_unchecked_t fscache_n_op_deferred_release;
46984+atomic_unchecked_t fscache_n_op_release;
46985+atomic_unchecked_t fscache_n_op_gc;
46986+atomic_unchecked_t fscache_n_op_cancelled;
46987+atomic_unchecked_t fscache_n_op_rejected;
46988
46989-atomic_t fscache_n_attr_changed;
46990-atomic_t fscache_n_attr_changed_ok;
46991-atomic_t fscache_n_attr_changed_nobufs;
46992-atomic_t fscache_n_attr_changed_nomem;
46993-atomic_t fscache_n_attr_changed_calls;
46994+atomic_unchecked_t fscache_n_attr_changed;
46995+atomic_unchecked_t fscache_n_attr_changed_ok;
46996+atomic_unchecked_t fscache_n_attr_changed_nobufs;
46997+atomic_unchecked_t fscache_n_attr_changed_nomem;
46998+atomic_unchecked_t fscache_n_attr_changed_calls;
46999
47000-atomic_t fscache_n_allocs;
47001-atomic_t fscache_n_allocs_ok;
47002-atomic_t fscache_n_allocs_wait;
47003-atomic_t fscache_n_allocs_nobufs;
47004-atomic_t fscache_n_allocs_intr;
47005-atomic_t fscache_n_allocs_object_dead;
47006-atomic_t fscache_n_alloc_ops;
47007-atomic_t fscache_n_alloc_op_waits;
47008+atomic_unchecked_t fscache_n_allocs;
47009+atomic_unchecked_t fscache_n_allocs_ok;
47010+atomic_unchecked_t fscache_n_allocs_wait;
47011+atomic_unchecked_t fscache_n_allocs_nobufs;
47012+atomic_unchecked_t fscache_n_allocs_intr;
47013+atomic_unchecked_t fscache_n_allocs_object_dead;
47014+atomic_unchecked_t fscache_n_alloc_ops;
47015+atomic_unchecked_t fscache_n_alloc_op_waits;
47016
47017-atomic_t fscache_n_retrievals;
47018-atomic_t fscache_n_retrievals_ok;
47019-atomic_t fscache_n_retrievals_wait;
47020-atomic_t fscache_n_retrievals_nodata;
47021-atomic_t fscache_n_retrievals_nobufs;
47022-atomic_t fscache_n_retrievals_intr;
47023-atomic_t fscache_n_retrievals_nomem;
47024-atomic_t fscache_n_retrievals_object_dead;
47025-atomic_t fscache_n_retrieval_ops;
47026-atomic_t fscache_n_retrieval_op_waits;
47027+atomic_unchecked_t fscache_n_retrievals;
47028+atomic_unchecked_t fscache_n_retrievals_ok;
47029+atomic_unchecked_t fscache_n_retrievals_wait;
47030+atomic_unchecked_t fscache_n_retrievals_nodata;
47031+atomic_unchecked_t fscache_n_retrievals_nobufs;
47032+atomic_unchecked_t fscache_n_retrievals_intr;
47033+atomic_unchecked_t fscache_n_retrievals_nomem;
47034+atomic_unchecked_t fscache_n_retrievals_object_dead;
47035+atomic_unchecked_t fscache_n_retrieval_ops;
47036+atomic_unchecked_t fscache_n_retrieval_op_waits;
47037
47038-atomic_t fscache_n_stores;
47039-atomic_t fscache_n_stores_ok;
47040-atomic_t fscache_n_stores_again;
47041-atomic_t fscache_n_stores_nobufs;
47042-atomic_t fscache_n_stores_oom;
47043-atomic_t fscache_n_store_ops;
47044-atomic_t fscache_n_store_calls;
47045-atomic_t fscache_n_store_pages;
47046-atomic_t fscache_n_store_radix_deletes;
47047-atomic_t fscache_n_store_pages_over_limit;
47048+atomic_unchecked_t fscache_n_stores;
47049+atomic_unchecked_t fscache_n_stores_ok;
47050+atomic_unchecked_t fscache_n_stores_again;
47051+atomic_unchecked_t fscache_n_stores_nobufs;
47052+atomic_unchecked_t fscache_n_stores_oom;
47053+atomic_unchecked_t fscache_n_store_ops;
47054+atomic_unchecked_t fscache_n_store_calls;
47055+atomic_unchecked_t fscache_n_store_pages;
47056+atomic_unchecked_t fscache_n_store_radix_deletes;
47057+atomic_unchecked_t fscache_n_store_pages_over_limit;
47058
47059-atomic_t fscache_n_store_vmscan_not_storing;
47060-atomic_t fscache_n_store_vmscan_gone;
47061-atomic_t fscache_n_store_vmscan_busy;
47062-atomic_t fscache_n_store_vmscan_cancelled;
47063+atomic_unchecked_t fscache_n_store_vmscan_not_storing;
47064+atomic_unchecked_t fscache_n_store_vmscan_gone;
47065+atomic_unchecked_t fscache_n_store_vmscan_busy;
47066+atomic_unchecked_t fscache_n_store_vmscan_cancelled;
47067
47068-atomic_t fscache_n_marks;
47069-atomic_t fscache_n_uncaches;
47070+atomic_unchecked_t fscache_n_marks;
47071+atomic_unchecked_t fscache_n_uncaches;
47072
47073-atomic_t fscache_n_acquires;
47074-atomic_t fscache_n_acquires_null;
47075-atomic_t fscache_n_acquires_no_cache;
47076-atomic_t fscache_n_acquires_ok;
47077-atomic_t fscache_n_acquires_nobufs;
47078-atomic_t fscache_n_acquires_oom;
47079+atomic_unchecked_t fscache_n_acquires;
47080+atomic_unchecked_t fscache_n_acquires_null;
47081+atomic_unchecked_t fscache_n_acquires_no_cache;
47082+atomic_unchecked_t fscache_n_acquires_ok;
47083+atomic_unchecked_t fscache_n_acquires_nobufs;
47084+atomic_unchecked_t fscache_n_acquires_oom;
47085
47086-atomic_t fscache_n_updates;
47087-atomic_t fscache_n_updates_null;
47088-atomic_t fscache_n_updates_run;
47089+atomic_unchecked_t fscache_n_updates;
47090+atomic_unchecked_t fscache_n_updates_null;
47091+atomic_unchecked_t fscache_n_updates_run;
47092
47093-atomic_t fscache_n_relinquishes;
47094-atomic_t fscache_n_relinquishes_null;
47095-atomic_t fscache_n_relinquishes_waitcrt;
47096-atomic_t fscache_n_relinquishes_retire;
47097+atomic_unchecked_t fscache_n_relinquishes;
47098+atomic_unchecked_t fscache_n_relinquishes_null;
47099+atomic_unchecked_t fscache_n_relinquishes_waitcrt;
47100+atomic_unchecked_t fscache_n_relinquishes_retire;
47101
47102-atomic_t fscache_n_cookie_index;
47103-atomic_t fscache_n_cookie_data;
47104-atomic_t fscache_n_cookie_special;
47105+atomic_unchecked_t fscache_n_cookie_index;
47106+atomic_unchecked_t fscache_n_cookie_data;
47107+atomic_unchecked_t fscache_n_cookie_special;
47108
47109-atomic_t fscache_n_object_alloc;
47110-atomic_t fscache_n_object_no_alloc;
47111-atomic_t fscache_n_object_lookups;
47112-atomic_t fscache_n_object_lookups_negative;
47113-atomic_t fscache_n_object_lookups_positive;
47114-atomic_t fscache_n_object_lookups_timed_out;
47115-atomic_t fscache_n_object_created;
47116-atomic_t fscache_n_object_avail;
47117-atomic_t fscache_n_object_dead;
47118+atomic_unchecked_t fscache_n_object_alloc;
47119+atomic_unchecked_t fscache_n_object_no_alloc;
47120+atomic_unchecked_t fscache_n_object_lookups;
47121+atomic_unchecked_t fscache_n_object_lookups_negative;
47122+atomic_unchecked_t fscache_n_object_lookups_positive;
47123+atomic_unchecked_t fscache_n_object_lookups_timed_out;
47124+atomic_unchecked_t fscache_n_object_created;
47125+atomic_unchecked_t fscache_n_object_avail;
47126+atomic_unchecked_t fscache_n_object_dead;
47127
47128-atomic_t fscache_n_checkaux_none;
47129-atomic_t fscache_n_checkaux_okay;
47130-atomic_t fscache_n_checkaux_update;
47131-atomic_t fscache_n_checkaux_obsolete;
47132+atomic_unchecked_t fscache_n_checkaux_none;
47133+atomic_unchecked_t fscache_n_checkaux_okay;
47134+atomic_unchecked_t fscache_n_checkaux_update;
47135+atomic_unchecked_t fscache_n_checkaux_obsolete;
47136
47137 atomic_t fscache_n_cop_alloc_object;
47138 atomic_t fscache_n_cop_lookup_object;
47139@@ -133,113 +133,113 @@ static int fscache_stats_show(struct seq_file *m, void *v)
47140 seq_puts(m, "FS-Cache statistics\n");
47141
47142 seq_printf(m, "Cookies: idx=%u dat=%u spc=%u\n",
47143- atomic_read(&fscache_n_cookie_index),
47144- atomic_read(&fscache_n_cookie_data),
47145- atomic_read(&fscache_n_cookie_special));
47146+ atomic_read_unchecked(&fscache_n_cookie_index),
47147+ atomic_read_unchecked(&fscache_n_cookie_data),
47148+ atomic_read_unchecked(&fscache_n_cookie_special));
47149
47150 seq_printf(m, "Objects: alc=%u nal=%u avl=%u ded=%u\n",
47151- atomic_read(&fscache_n_object_alloc),
47152- atomic_read(&fscache_n_object_no_alloc),
47153- atomic_read(&fscache_n_object_avail),
47154- atomic_read(&fscache_n_object_dead));
47155+ atomic_read_unchecked(&fscache_n_object_alloc),
47156+ atomic_read_unchecked(&fscache_n_object_no_alloc),
47157+ atomic_read_unchecked(&fscache_n_object_avail),
47158+ atomic_read_unchecked(&fscache_n_object_dead));
47159 seq_printf(m, "ChkAux : non=%u ok=%u upd=%u obs=%u\n",
47160- atomic_read(&fscache_n_checkaux_none),
47161- atomic_read(&fscache_n_checkaux_okay),
47162- atomic_read(&fscache_n_checkaux_update),
47163- atomic_read(&fscache_n_checkaux_obsolete));
47164+ atomic_read_unchecked(&fscache_n_checkaux_none),
47165+ atomic_read_unchecked(&fscache_n_checkaux_okay),
47166+ atomic_read_unchecked(&fscache_n_checkaux_update),
47167+ atomic_read_unchecked(&fscache_n_checkaux_obsolete));
47168
47169 seq_printf(m, "Pages : mrk=%u unc=%u\n",
47170- atomic_read(&fscache_n_marks),
47171- atomic_read(&fscache_n_uncaches));
47172+ atomic_read_unchecked(&fscache_n_marks),
47173+ atomic_read_unchecked(&fscache_n_uncaches));
47174
47175 seq_printf(m, "Acquire: n=%u nul=%u noc=%u ok=%u nbf=%u"
47176 " oom=%u\n",
47177- atomic_read(&fscache_n_acquires),
47178- atomic_read(&fscache_n_acquires_null),
47179- atomic_read(&fscache_n_acquires_no_cache),
47180- atomic_read(&fscache_n_acquires_ok),
47181- atomic_read(&fscache_n_acquires_nobufs),
47182- atomic_read(&fscache_n_acquires_oom));
47183+ atomic_read_unchecked(&fscache_n_acquires),
47184+ atomic_read_unchecked(&fscache_n_acquires_null),
47185+ atomic_read_unchecked(&fscache_n_acquires_no_cache),
47186+ atomic_read_unchecked(&fscache_n_acquires_ok),
47187+ atomic_read_unchecked(&fscache_n_acquires_nobufs),
47188+ atomic_read_unchecked(&fscache_n_acquires_oom));
47189
47190 seq_printf(m, "Lookups: n=%u neg=%u pos=%u crt=%u tmo=%u\n",
47191- atomic_read(&fscache_n_object_lookups),
47192- atomic_read(&fscache_n_object_lookups_negative),
47193- atomic_read(&fscache_n_object_lookups_positive),
47194- atomic_read(&fscache_n_object_created),
47195- atomic_read(&fscache_n_object_lookups_timed_out));
47196+ atomic_read_unchecked(&fscache_n_object_lookups),
47197+ atomic_read_unchecked(&fscache_n_object_lookups_negative),
47198+ atomic_read_unchecked(&fscache_n_object_lookups_positive),
47199+ atomic_read_unchecked(&fscache_n_object_created),
47200+ atomic_read_unchecked(&fscache_n_object_lookups_timed_out));
47201
47202 seq_printf(m, "Updates: n=%u nul=%u run=%u\n",
47203- atomic_read(&fscache_n_updates),
47204- atomic_read(&fscache_n_updates_null),
47205- atomic_read(&fscache_n_updates_run));
47206+ atomic_read_unchecked(&fscache_n_updates),
47207+ atomic_read_unchecked(&fscache_n_updates_null),
47208+ atomic_read_unchecked(&fscache_n_updates_run));
47209
47210 seq_printf(m, "Relinqs: n=%u nul=%u wcr=%u rtr=%u\n",
47211- atomic_read(&fscache_n_relinquishes),
47212- atomic_read(&fscache_n_relinquishes_null),
47213- atomic_read(&fscache_n_relinquishes_waitcrt),
47214- atomic_read(&fscache_n_relinquishes_retire));
47215+ atomic_read_unchecked(&fscache_n_relinquishes),
47216+ atomic_read_unchecked(&fscache_n_relinquishes_null),
47217+ atomic_read_unchecked(&fscache_n_relinquishes_waitcrt),
47218+ atomic_read_unchecked(&fscache_n_relinquishes_retire));
47219
47220 seq_printf(m, "AttrChg: n=%u ok=%u nbf=%u oom=%u run=%u\n",
47221- atomic_read(&fscache_n_attr_changed),
47222- atomic_read(&fscache_n_attr_changed_ok),
47223- atomic_read(&fscache_n_attr_changed_nobufs),
47224- atomic_read(&fscache_n_attr_changed_nomem),
47225- atomic_read(&fscache_n_attr_changed_calls));
47226+ atomic_read_unchecked(&fscache_n_attr_changed),
47227+ atomic_read_unchecked(&fscache_n_attr_changed_ok),
47228+ atomic_read_unchecked(&fscache_n_attr_changed_nobufs),
47229+ atomic_read_unchecked(&fscache_n_attr_changed_nomem),
47230+ atomic_read_unchecked(&fscache_n_attr_changed_calls));
47231
47232 seq_printf(m, "Allocs : n=%u ok=%u wt=%u nbf=%u int=%u\n",
47233- atomic_read(&fscache_n_allocs),
47234- atomic_read(&fscache_n_allocs_ok),
47235- atomic_read(&fscache_n_allocs_wait),
47236- atomic_read(&fscache_n_allocs_nobufs),
47237- atomic_read(&fscache_n_allocs_intr));
47238+ atomic_read_unchecked(&fscache_n_allocs),
47239+ atomic_read_unchecked(&fscache_n_allocs_ok),
47240+ atomic_read_unchecked(&fscache_n_allocs_wait),
47241+ atomic_read_unchecked(&fscache_n_allocs_nobufs),
47242+ atomic_read_unchecked(&fscache_n_allocs_intr));
47243 seq_printf(m, "Allocs : ops=%u owt=%u abt=%u\n",
47244- atomic_read(&fscache_n_alloc_ops),
47245- atomic_read(&fscache_n_alloc_op_waits),
47246- atomic_read(&fscache_n_allocs_object_dead));
47247+ atomic_read_unchecked(&fscache_n_alloc_ops),
47248+ atomic_read_unchecked(&fscache_n_alloc_op_waits),
47249+ atomic_read_unchecked(&fscache_n_allocs_object_dead));
47250
47251 seq_printf(m, "Retrvls: n=%u ok=%u wt=%u nod=%u nbf=%u"
47252 " int=%u oom=%u\n",
47253- atomic_read(&fscache_n_retrievals),
47254- atomic_read(&fscache_n_retrievals_ok),
47255- atomic_read(&fscache_n_retrievals_wait),
47256- atomic_read(&fscache_n_retrievals_nodata),
47257- atomic_read(&fscache_n_retrievals_nobufs),
47258- atomic_read(&fscache_n_retrievals_intr),
47259- atomic_read(&fscache_n_retrievals_nomem));
47260+ atomic_read_unchecked(&fscache_n_retrievals),
47261+ atomic_read_unchecked(&fscache_n_retrievals_ok),
47262+ atomic_read_unchecked(&fscache_n_retrievals_wait),
47263+ atomic_read_unchecked(&fscache_n_retrievals_nodata),
47264+ atomic_read_unchecked(&fscache_n_retrievals_nobufs),
47265+ atomic_read_unchecked(&fscache_n_retrievals_intr),
47266+ atomic_read_unchecked(&fscache_n_retrievals_nomem));
47267 seq_printf(m, "Retrvls: ops=%u owt=%u abt=%u\n",
47268- atomic_read(&fscache_n_retrieval_ops),
47269- atomic_read(&fscache_n_retrieval_op_waits),
47270- atomic_read(&fscache_n_retrievals_object_dead));
47271+ atomic_read_unchecked(&fscache_n_retrieval_ops),
47272+ atomic_read_unchecked(&fscache_n_retrieval_op_waits),
47273+ atomic_read_unchecked(&fscache_n_retrievals_object_dead));
47274
47275 seq_printf(m, "Stores : n=%u ok=%u agn=%u nbf=%u oom=%u\n",
47276- atomic_read(&fscache_n_stores),
47277- atomic_read(&fscache_n_stores_ok),
47278- atomic_read(&fscache_n_stores_again),
47279- atomic_read(&fscache_n_stores_nobufs),
47280- atomic_read(&fscache_n_stores_oom));
47281+ atomic_read_unchecked(&fscache_n_stores),
47282+ atomic_read_unchecked(&fscache_n_stores_ok),
47283+ atomic_read_unchecked(&fscache_n_stores_again),
47284+ atomic_read_unchecked(&fscache_n_stores_nobufs),
47285+ atomic_read_unchecked(&fscache_n_stores_oom));
47286 seq_printf(m, "Stores : ops=%u run=%u pgs=%u rxd=%u olm=%u\n",
47287- atomic_read(&fscache_n_store_ops),
47288- atomic_read(&fscache_n_store_calls),
47289- atomic_read(&fscache_n_store_pages),
47290- atomic_read(&fscache_n_store_radix_deletes),
47291- atomic_read(&fscache_n_store_pages_over_limit));
47292+ atomic_read_unchecked(&fscache_n_store_ops),
47293+ atomic_read_unchecked(&fscache_n_store_calls),
47294+ atomic_read_unchecked(&fscache_n_store_pages),
47295+ atomic_read_unchecked(&fscache_n_store_radix_deletes),
47296+ atomic_read_unchecked(&fscache_n_store_pages_over_limit));
47297
47298 seq_printf(m, "VmScan : nos=%u gon=%u bsy=%u can=%u\n",
47299- atomic_read(&fscache_n_store_vmscan_not_storing),
47300- atomic_read(&fscache_n_store_vmscan_gone),
47301- atomic_read(&fscache_n_store_vmscan_busy),
47302- atomic_read(&fscache_n_store_vmscan_cancelled));
47303+ atomic_read_unchecked(&fscache_n_store_vmscan_not_storing),
47304+ atomic_read_unchecked(&fscache_n_store_vmscan_gone),
47305+ atomic_read_unchecked(&fscache_n_store_vmscan_busy),
47306+ atomic_read_unchecked(&fscache_n_store_vmscan_cancelled));
47307
47308 seq_printf(m, "Ops : pend=%u run=%u enq=%u can=%u rej=%u\n",
47309- atomic_read(&fscache_n_op_pend),
47310- atomic_read(&fscache_n_op_run),
47311- atomic_read(&fscache_n_op_enqueue),
47312- atomic_read(&fscache_n_op_cancelled),
47313- atomic_read(&fscache_n_op_rejected));
47314+ atomic_read_unchecked(&fscache_n_op_pend),
47315+ atomic_read_unchecked(&fscache_n_op_run),
47316+ atomic_read_unchecked(&fscache_n_op_enqueue),
47317+ atomic_read_unchecked(&fscache_n_op_cancelled),
47318+ atomic_read_unchecked(&fscache_n_op_rejected));
47319 seq_printf(m, "Ops : dfr=%u rel=%u gc=%u\n",
47320- atomic_read(&fscache_n_op_deferred_release),
47321- atomic_read(&fscache_n_op_release),
47322- atomic_read(&fscache_n_op_gc));
47323+ atomic_read_unchecked(&fscache_n_op_deferred_release),
47324+ atomic_read_unchecked(&fscache_n_op_release),
47325+ atomic_read_unchecked(&fscache_n_op_gc));
47326
47327 seq_printf(m, "CacheOp: alo=%d luo=%d luc=%d gro=%d\n",
47328 atomic_read(&fscache_n_cop_alloc_object),
47329diff --git a/fs/fuse/cuse.c b/fs/fuse/cuse.c
47330index ee8d550..7189d8c 100644
47331--- a/fs/fuse/cuse.c
47332+++ b/fs/fuse/cuse.c
47333@@ -585,10 +585,12 @@ static int __init cuse_init(void)
47334 INIT_LIST_HEAD(&cuse_conntbl[i]);
47335
47336 /* inherit and extend fuse_dev_operations */
47337- cuse_channel_fops = fuse_dev_operations;
47338- cuse_channel_fops.owner = THIS_MODULE;
47339- cuse_channel_fops.open = cuse_channel_open;
47340- cuse_channel_fops.release = cuse_channel_release;
47341+ pax_open_kernel();
47342+ memcpy((void *)&cuse_channel_fops, &fuse_dev_operations, sizeof(fuse_dev_operations));
47343+ *(void **)&cuse_channel_fops.owner = THIS_MODULE;
47344+ *(void **)&cuse_channel_fops.open = cuse_channel_open;
47345+ *(void **)&cuse_channel_fops.release = cuse_channel_release;
47346+ pax_close_kernel();
47347
47348 cuse_class = class_create(THIS_MODULE, "cuse");
47349 if (IS_ERR(cuse_class))
47350diff --git a/fs/fuse/dev.c b/fs/fuse/dev.c
47351index f4246cf..b4aed1d 100644
47352--- a/fs/fuse/dev.c
47353+++ b/fs/fuse/dev.c
47354@@ -1242,7 +1242,7 @@ static ssize_t fuse_dev_splice_read(struct file *in, loff_t *ppos,
47355 ret = 0;
47356 pipe_lock(pipe);
47357
47358- if (!pipe->readers) {
47359+ if (!atomic_read(&pipe->readers)) {
47360 send_sig(SIGPIPE, current, 0);
47361 if (!ret)
47362 ret = -EPIPE;
47363diff --git a/fs/fuse/dir.c b/fs/fuse/dir.c
47364index 324bc08..4fdd56e 100644
47365--- a/fs/fuse/dir.c
47366+++ b/fs/fuse/dir.c
47367@@ -1226,7 +1226,7 @@ static char *read_link(struct dentry *dentry)
47368 return link;
47369 }
47370
47371-static void free_link(char *link)
47372+static void free_link(const char *link)
47373 {
47374 if (!IS_ERR(link))
47375 free_page((unsigned long) link);
47376diff --git a/fs/gfs2/inode.c b/fs/gfs2/inode.c
47377index 753af3d..f7b021a 100644
47378--- a/fs/gfs2/inode.c
47379+++ b/fs/gfs2/inode.c
47380@@ -1498,7 +1498,7 @@ out:
47381
47382 static void gfs2_put_link(struct dentry *dentry, struct nameidata *nd, void *p)
47383 {
47384- char *s = nd_get_link(nd);
47385+ const char *s = nd_get_link(nd);
47386 if (!IS_ERR(s))
47387 kfree(s);
47388 }
47389diff --git a/fs/hugetlbfs/inode.c b/fs/hugetlbfs/inode.c
47390index 8349a89..51a0254 100644
47391--- a/fs/hugetlbfs/inode.c
47392+++ b/fs/hugetlbfs/inode.c
47393@@ -920,7 +920,7 @@ static struct file_system_type hugetlbfs_fs_type = {
47394 .kill_sb = kill_litter_super,
47395 };
47396
47397-static struct vfsmount *hugetlbfs_vfsmount;
47398+struct vfsmount *hugetlbfs_vfsmount;
47399
47400 static int can_do_hugetlb_shm(void)
47401 {
47402diff --git a/fs/inode.c b/fs/inode.c
47403index ac8d904..9f45d40 100644
47404--- a/fs/inode.c
47405+++ b/fs/inode.c
47406@@ -867,8 +867,8 @@ unsigned int get_next_ino(void)
47407
47408 #ifdef CONFIG_SMP
47409 if (unlikely((res & (LAST_INO_BATCH-1)) == 0)) {
47410- static atomic_t shared_last_ino;
47411- int next = atomic_add_return(LAST_INO_BATCH, &shared_last_ino);
47412+ static atomic_unchecked_t shared_last_ino;
47413+ int next = atomic_add_return_unchecked(LAST_INO_BATCH, &shared_last_ino);
47414
47415 res = next - LAST_INO_BATCH;
47416 }
47417diff --git a/fs/jffs2/erase.c b/fs/jffs2/erase.c
47418index 4a6cf28..d3a29d3 100644
47419--- a/fs/jffs2/erase.c
47420+++ b/fs/jffs2/erase.c
47421@@ -452,7 +452,8 @@ static void jffs2_mark_erased_block(struct jffs2_sb_info *c, struct jffs2_eraseb
47422 struct jffs2_unknown_node marker = {
47423 .magic = cpu_to_je16(JFFS2_MAGIC_BITMASK),
47424 .nodetype = cpu_to_je16(JFFS2_NODETYPE_CLEANMARKER),
47425- .totlen = cpu_to_je32(c->cleanmarker_size)
47426+ .totlen = cpu_to_je32(c->cleanmarker_size),
47427+ .hdr_crc = cpu_to_je32(0)
47428 };
47429
47430 jffs2_prealloc_raw_node_refs(c, jeb, 1);
47431diff --git a/fs/jffs2/wbuf.c b/fs/jffs2/wbuf.c
47432index a6597d6..41b30ec 100644
47433--- a/fs/jffs2/wbuf.c
47434+++ b/fs/jffs2/wbuf.c
47435@@ -1023,7 +1023,8 @@ static const struct jffs2_unknown_node oob_cleanmarker =
47436 {
47437 .magic = constant_cpu_to_je16(JFFS2_MAGIC_BITMASK),
47438 .nodetype = constant_cpu_to_je16(JFFS2_NODETYPE_CLEANMARKER),
47439- .totlen = constant_cpu_to_je32(8)
47440+ .totlen = constant_cpu_to_je32(8),
47441+ .hdr_crc = constant_cpu_to_je32(0)
47442 };
47443
47444 /*
47445diff --git a/fs/jfs/super.c b/fs/jfs/super.c
47446index c55c745..f67ee56 100644
47447--- a/fs/jfs/super.c
47448+++ b/fs/jfs/super.c
47449@@ -806,7 +806,7 @@ static int __init init_jfs_fs(void)
47450
47451 jfs_inode_cachep =
47452 kmem_cache_create("jfs_ip", sizeof(struct jfs_inode_info), 0,
47453- SLAB_RECLAIM_ACCOUNT|SLAB_MEM_SPREAD,
47454+ SLAB_RECLAIM_ACCOUNT|SLAB_MEM_SPREAD|SLAB_USERCOPY,
47455 init_once);
47456 if (jfs_inode_cachep == NULL)
47457 return -ENOMEM;
47458diff --git a/fs/libfs.c b/fs/libfs.c
47459index a74cb17..37fcbe4 100644
47460--- a/fs/libfs.c
47461+++ b/fs/libfs.c
47462@@ -165,6 +165,9 @@ int dcache_readdir(struct file * filp, void * dirent, filldir_t filldir)
47463
47464 for (p=q->next; p != &dentry->d_subdirs; p=p->next) {
47465 struct dentry *next;
47466+ char d_name[sizeof(next->d_iname)];
47467+ const unsigned char *name;
47468+
47469 next = list_entry(p, struct dentry, d_u.d_child);
47470 spin_lock_nested(&next->d_lock, DENTRY_D_LOCK_NESTED);
47471 if (!simple_positive(next)) {
47472@@ -174,7 +177,12 @@ int dcache_readdir(struct file * filp, void * dirent, filldir_t filldir)
47473
47474 spin_unlock(&next->d_lock);
47475 spin_unlock(&dentry->d_lock);
47476- if (filldir(dirent, next->d_name.name,
47477+ name = next->d_name.name;
47478+ if (name == next->d_iname) {
47479+ memcpy(d_name, name, next->d_name.len);
47480+ name = d_name;
47481+ }
47482+ if (filldir(dirent, name,
47483 next->d_name.len, filp->f_pos,
47484 next->d_inode->i_ino,
47485 dt_type(next->d_inode)) < 0)
47486diff --git a/fs/lockd/clntproc.c b/fs/lockd/clntproc.c
47487index 05d2912..760abfa 100644
47488--- a/fs/lockd/clntproc.c
47489+++ b/fs/lockd/clntproc.c
47490@@ -36,11 +36,11 @@ static const struct rpc_call_ops nlmclnt_cancel_ops;
47491 /*
47492 * Cookie counter for NLM requests
47493 */
47494-static atomic_t nlm_cookie = ATOMIC_INIT(0x1234);
47495+static atomic_unchecked_t nlm_cookie = ATOMIC_INIT(0x1234);
47496
47497 void nlmclnt_next_cookie(struct nlm_cookie *c)
47498 {
47499- u32 cookie = atomic_inc_return(&nlm_cookie);
47500+ u32 cookie = atomic_inc_return_unchecked(&nlm_cookie);
47501
47502 memcpy(c->data, &cookie, 4);
47503 c->len=4;
47504diff --git a/fs/locks.c b/fs/locks.c
47505index 7e81bfc..c3649aa 100644
47506--- a/fs/locks.c
47507+++ b/fs/locks.c
47508@@ -2066,16 +2066,16 @@ void locks_remove_flock(struct file *filp)
47509 return;
47510
47511 if (filp->f_op && filp->f_op->flock) {
47512- struct file_lock fl = {
47513+ struct file_lock flock = {
47514 .fl_pid = current->tgid,
47515 .fl_file = filp,
47516 .fl_flags = FL_FLOCK,
47517 .fl_type = F_UNLCK,
47518 .fl_end = OFFSET_MAX,
47519 };
47520- filp->f_op->flock(filp, F_SETLKW, &fl);
47521- if (fl.fl_ops && fl.fl_ops->fl_release_private)
47522- fl.fl_ops->fl_release_private(&fl);
47523+ filp->f_op->flock(filp, F_SETLKW, &flock);
47524+ if (flock.fl_ops && flock.fl_ops->fl_release_private)
47525+ flock.fl_ops->fl_release_private(&flock);
47526 }
47527
47528 lock_flocks();
47529diff --git a/fs/namei.c b/fs/namei.c
47530index 81bd546..80149d9 100644
47531--- a/fs/namei.c
47532+++ b/fs/namei.c
47533@@ -265,16 +265,32 @@ int generic_permission(struct inode *inode, int mask)
47534 if (ret != -EACCES)
47535 return ret;
47536
47537+#ifdef CONFIG_GRKERNSEC
47538+ /* we'll block if we have to log due to a denied capability use */
47539+ if (mask & MAY_NOT_BLOCK)
47540+ return -ECHILD;
47541+#endif
47542+
47543 if (S_ISDIR(inode->i_mode)) {
47544 /* DACs are overridable for directories */
47545- if (inode_capable(inode, CAP_DAC_OVERRIDE))
47546- return 0;
47547 if (!(mask & MAY_WRITE))
47548- if (inode_capable(inode, CAP_DAC_READ_SEARCH))
47549+ if (inode_capable_nolog(inode, CAP_DAC_OVERRIDE) ||
47550+ inode_capable(inode, CAP_DAC_READ_SEARCH))
47551 return 0;
47552+ if (inode_capable(inode, CAP_DAC_OVERRIDE))
47553+ return 0;
47554 return -EACCES;
47555 }
47556 /*
47557+ * Searching includes executable on directories, else just read.
47558+ */
47559+ mask &= MAY_READ | MAY_WRITE | MAY_EXEC;
47560+ if (mask == MAY_READ)
47561+ if (inode_capable_nolog(inode, CAP_DAC_OVERRIDE) ||
47562+ inode_capable(inode, CAP_DAC_READ_SEARCH))
47563+ return 0;
47564+
47565+ /*
47566 * Read/write DACs are always overridable.
47567 * Executable DACs are overridable when there is
47568 * at least one exec bit set.
47569@@ -283,14 +299,6 @@ int generic_permission(struct inode *inode, int mask)
47570 if (inode_capable(inode, CAP_DAC_OVERRIDE))
47571 return 0;
47572
47573- /*
47574- * Searching includes executable on directories, else just read.
47575- */
47576- mask &= MAY_READ | MAY_WRITE | MAY_EXEC;
47577- if (mask == MAY_READ)
47578- if (inode_capable(inode, CAP_DAC_READ_SEARCH))
47579- return 0;
47580-
47581 return -EACCES;
47582 }
47583
47584@@ -772,7 +780,7 @@ follow_link(struct path *link, struct nameidata *nd, void **p)
47585 {
47586 struct dentry *dentry = link->dentry;
47587 int error;
47588- char *s;
47589+ const char *s;
47590
47591 BUG_ON(nd->flags & LOOKUP_RCU);
47592
47593@@ -793,6 +801,12 @@ follow_link(struct path *link, struct nameidata *nd, void **p)
47594 if (error)
47595 goto out_put_nd_path;
47596
47597+ if (gr_handle_follow_link(dentry->d_parent->d_inode,
47598+ dentry->d_inode, dentry, nd->path.mnt)) {
47599+ error = -EACCES;
47600+ goto out_put_nd_path;
47601+ }
47602+
47603 nd->last_type = LAST_BIND;
47604 *p = dentry->d_inode->i_op->follow_link(dentry, nd);
47605 error = PTR_ERR(*p);
47606@@ -1550,6 +1564,8 @@ static inline int nested_symlink(struct path *path, struct nameidata *nd)
47607 break;
47608 res = walk_component(nd, path, &nd->last,
47609 nd->last_type, LOOKUP_FOLLOW);
47610+ if (res >= 0 && gr_handle_symlink_owner(&link, nd->inode))
47611+ res = -EACCES;
47612 put_link(nd, &link, cookie);
47613 } while (res > 0);
47614
47615@@ -1943,6 +1959,8 @@ static int path_lookupat(int dfd, const char *name,
47616 if (err)
47617 break;
47618 err = lookup_last(nd, &path);
47619+ if (!err && gr_handle_symlink_owner(&link, nd->inode))
47620+ err = -EACCES;
47621 put_link(nd, &link, cookie);
47622 }
47623 }
47624@@ -1950,6 +1968,21 @@ static int path_lookupat(int dfd, const char *name,
47625 if (!err)
47626 err = complete_walk(nd);
47627
47628+ if (!(nd->flags & LOOKUP_PARENT)) {
47629+#ifdef CONFIG_GRKERNSEC
47630+ if (flags & LOOKUP_RCU) {
47631+ if (!err)
47632+ path_put(&nd->path);
47633+ err = -ECHILD;
47634+ } else
47635+#endif
47636+ if (!gr_acl_handle_hidden_file(nd->path.dentry, nd->path.mnt)) {
47637+ if (!err)
47638+ path_put(&nd->path);
47639+ err = -ENOENT;
47640+ }
47641+ }
47642+
47643 if (!err && nd->flags & LOOKUP_DIRECTORY) {
47644 if (!nd->inode->i_op->lookup) {
47645 path_put(&nd->path);
47646@@ -1977,6 +2010,15 @@ static int do_path_lookup(int dfd, const char *name,
47647 retval = path_lookupat(dfd, name, flags | LOOKUP_REVAL, nd);
47648
47649 if (likely(!retval)) {
47650+ if (*name != '/' && nd->path.dentry && nd->inode) {
47651+#ifdef CONFIG_GRKERNSEC
47652+ if (flags & LOOKUP_RCU)
47653+ return -ECHILD;
47654+#endif
47655+ if (!gr_chroot_fchdir(nd->path.dentry, nd->path.mnt))
47656+ return -ENOENT;
47657+ }
47658+
47659 if (unlikely(!audit_dummy_context())) {
47660 if (nd->path.dentry && nd->inode)
47661 audit_inode(name, nd->path.dentry);
47662@@ -2336,6 +2378,13 @@ static int may_open(struct path *path, int acc_mode, int flag)
47663 if (flag & O_NOATIME && !inode_owner_or_capable(inode))
47664 return -EPERM;
47665
47666+ if (gr_handle_rofs_blockwrite(dentry, path->mnt, acc_mode))
47667+ return -EPERM;
47668+ if (gr_handle_rawio(inode))
47669+ return -EPERM;
47670+ if (!gr_acl_handle_open(dentry, path->mnt, acc_mode))
47671+ return -EACCES;
47672+
47673 return 0;
47674 }
47675
47676@@ -2557,7 +2606,7 @@ looked_up:
47677 * cleared otherwise prior to returning.
47678 */
47679 static int lookup_open(struct nameidata *nd, struct path *path,
47680- struct file *file,
47681+ struct path *link, struct file *file,
47682 const struct open_flags *op,
47683 bool got_write, int *opened)
47684 {
47685@@ -2592,6 +2641,17 @@ static int lookup_open(struct nameidata *nd, struct path *path,
47686 /* Negative dentry, just create the file */
47687 if (!dentry->d_inode && (op->open_flag & O_CREAT)) {
47688 umode_t mode = op->mode;
47689+
47690+ if (link && gr_handle_symlink_owner(link, dir->d_inode)) {
47691+ error = -EACCES;
47692+ goto out_dput;
47693+ }
47694+
47695+ if (!gr_acl_handle_creat(dentry, dir, nd->path.mnt, op->open_flag, op->acc_mode, mode)) {
47696+ error = -EACCES;
47697+ goto out_dput;
47698+ }
47699+
47700 if (!IS_POSIXACL(dir->d_inode))
47701 mode &= ~current_umask();
47702 /*
47703@@ -2613,6 +2673,8 @@ static int lookup_open(struct nameidata *nd, struct path *path,
47704 nd->flags & LOOKUP_EXCL);
47705 if (error)
47706 goto out_dput;
47707+ else
47708+ gr_handle_create(dentry, nd->path.mnt);
47709 }
47710 out_no_open:
47711 path->dentry = dentry;
47712@@ -2627,7 +2689,7 @@ out_dput:
47713 /*
47714 * Handle the last step of open()
47715 */
47716-static int do_last(struct nameidata *nd, struct path *path,
47717+static int do_last(struct nameidata *nd, struct path *path, struct path *link,
47718 struct file *file, const struct open_flags *op,
47719 int *opened, const char *pathname)
47720 {
47721@@ -2656,16 +2718,44 @@ static int do_last(struct nameidata *nd, struct path *path,
47722 error = complete_walk(nd);
47723 if (error)
47724 return error;
47725+#ifdef CONFIG_GRKERNSEC
47726+ if (nd->flags & LOOKUP_RCU) {
47727+ error = -ECHILD;
47728+ goto out;
47729+ }
47730+#endif
47731+ if (!gr_acl_handle_hidden_file(nd->path.dentry, nd->path.mnt)) {
47732+ error = -ENOENT;
47733+ goto out;
47734+ }
47735 audit_inode(pathname, nd->path.dentry);
47736 if (open_flag & O_CREAT) {
47737 error = -EISDIR;
47738 goto out;
47739 }
47740+ if (link && gr_handle_symlink_owner(link, nd->inode)) {
47741+ error = -EACCES;
47742+ goto out;
47743+ }
47744 goto finish_open;
47745 case LAST_BIND:
47746 error = complete_walk(nd);
47747 if (error)
47748 return error;
47749+#ifdef CONFIG_GRKERNSEC
47750+ if (nd->flags & LOOKUP_RCU) {
47751+ error = -ECHILD;
47752+ goto out;
47753+ }
47754+#endif
47755+ if (!gr_acl_handle_hidden_file(dir, nd->path.mnt)) {
47756+ error = -ENOENT;
47757+ goto out;
47758+ }
47759+ if (link && gr_handle_symlink_owner(link, nd->inode)) {
47760+ error = -EACCES;
47761+ goto out;
47762+ }
47763 audit_inode(pathname, dir);
47764 goto finish_open;
47765 }
47766@@ -2714,7 +2804,7 @@ retry_lookup:
47767 */
47768 }
47769 mutex_lock(&dir->d_inode->i_mutex);
47770- error = lookup_open(nd, path, file, op, got_write, opened);
47771+ error = lookup_open(nd, path, link, file, op, got_write, opened);
47772 mutex_unlock(&dir->d_inode->i_mutex);
47773
47774 if (error <= 0) {
47775@@ -2738,11 +2828,28 @@ retry_lookup:
47776 goto finish_open_created;
47777 }
47778
47779+ if (!gr_acl_handle_hidden_file(path->dentry, nd->path.mnt)) {
47780+ error = -ENOENT;
47781+ goto exit_dput;
47782+ }
47783+ if (link && gr_handle_symlink_owner(link, path->dentry->d_inode)) {
47784+ error = -EACCES;
47785+ goto exit_dput;
47786+ }
47787+
47788 /*
47789 * create/update audit record if it already exists.
47790 */
47791- if (path->dentry->d_inode)
47792+ if (path->dentry->d_inode) {
47793+ /* only check if O_CREAT is specified, all other checks need to go
47794+ into may_open */
47795+ if (gr_handle_fifo(path->dentry, path->mnt, dir, open_flag, acc_mode)) {
47796+ error = -EACCES;
47797+ goto exit_dput;
47798+ }
47799+
47800 audit_inode(pathname, path->dentry);
47801+ }
47802
47803 /*
47804 * If atomic_open() acquired write access it is dropped now due to
47805@@ -2783,6 +2890,11 @@ finish_lookup:
47806 }
47807 }
47808 BUG_ON(inode != path->dentry->d_inode);
47809+ /* if we're resolving a symlink to another symlink */
47810+ if (link && gr_handle_symlink_owner(link, inode)) {
47811+ error = -EACCES;
47812+ goto out;
47813+ }
47814 return 1;
47815 }
47816
47817@@ -2792,7 +2904,6 @@ finish_lookup:
47818 save_parent.dentry = nd->path.dentry;
47819 save_parent.mnt = mntget(path->mnt);
47820 nd->path.dentry = path->dentry;
47821-
47822 }
47823 nd->inode = inode;
47824 /* Why this, you ask? _Now_ we might have grown LOOKUP_JUMPED... */
47825@@ -2801,6 +2912,22 @@ finish_lookup:
47826 path_put(&save_parent);
47827 return error;
47828 }
47829+
47830+#ifdef CONFIG_GRKERNSEC
47831+ if (nd->flags & LOOKUP_RCU) {
47832+ error = -ECHILD;
47833+ goto out;
47834+ }
47835+#endif
47836+ if (!gr_acl_handle_hidden_file(nd->path.dentry, nd->path.mnt)) {
47837+ error = -ENOENT;
47838+ goto out;
47839+ }
47840+ if (link && gr_handle_symlink_owner(link, nd->inode)) {
47841+ error = -EACCES;
47842+ goto out;
47843+ }
47844+
47845 error = -EISDIR;
47846 if ((open_flag & O_CREAT) && S_ISDIR(nd->inode->i_mode))
47847 goto out;
47848@@ -2899,7 +3026,7 @@ static struct file *path_openat(int dfd, const char *pathname,
47849 if (unlikely(error))
47850 goto out;
47851
47852- error = do_last(nd, &path, file, op, &opened, pathname);
47853+ error = do_last(nd, &path, NULL, file, op, &opened, pathname);
47854 while (unlikely(error > 0)) { /* trailing symlink */
47855 struct path link = path;
47856 void *cookie;
47857@@ -2917,7 +3044,7 @@ static struct file *path_openat(int dfd, const char *pathname,
47858 error = follow_link(&link, nd, &cookie);
47859 if (unlikely(error))
47860 break;
47861- error = do_last(nd, &path, file, op, &opened, pathname);
47862+ error = do_last(nd, &path, &link, file, op, &opened, pathname);
47863 put_link(nd, &link, cookie);
47864 }
47865 out:
47866@@ -3006,8 +3133,12 @@ struct dentry *kern_path_create(int dfd, const char *pathname, struct path *path
47867 goto unlock;
47868
47869 error = -EEXIST;
47870- if (dentry->d_inode)
47871+ if (dentry->d_inode) {
47872+ if (!gr_acl_handle_hidden_file(dentry, nd.path.mnt)) {
47873+ error = -ENOENT;
47874+ }
47875 goto fail;
47876+ }
47877 /*
47878 * Special case - lookup gave negative, but... we had foo/bar/
47879 * From the vfs_mknod() POV we just have a negative dentry -
47880@@ -3058,6 +3189,20 @@ struct dentry *user_path_create(int dfd, const char __user *pathname, struct pat
47881 }
47882 EXPORT_SYMBOL(user_path_create);
47883
47884+static struct dentry *user_path_create_with_name(int dfd, const char __user *pathname, struct path *path, char **to, int is_dir)
47885+{
47886+ char *tmp = getname(pathname);
47887+ struct dentry *res;
47888+ if (IS_ERR(tmp))
47889+ return ERR_CAST(tmp);
47890+ res = kern_path_create(dfd, tmp, path, is_dir);
47891+ if (IS_ERR(res))
47892+ putname(tmp);
47893+ else
47894+ *to = tmp;
47895+ return res;
47896+}
47897+
47898 int vfs_mknod(struct inode *dir, struct dentry *dentry, umode_t mode, dev_t dev)
47899 {
47900 int error = may_create(dir, dentry);
47901@@ -3119,6 +3264,17 @@ SYSCALL_DEFINE4(mknodat, int, dfd, const char __user *, filename, umode_t, mode,
47902
47903 if (!IS_POSIXACL(path.dentry->d_inode))
47904 mode &= ~current_umask();
47905+
47906+ if (gr_handle_chroot_mknod(dentry, path.mnt, mode)) {
47907+ error = -EPERM;
47908+ goto out;
47909+ }
47910+
47911+ if (!gr_acl_handle_mknod(dentry, path.dentry, path.mnt, mode)) {
47912+ error = -EACCES;
47913+ goto out;
47914+ }
47915+
47916 error = security_path_mknod(&path, dentry, mode, dev);
47917 if (error)
47918 goto out;
47919@@ -3135,6 +3291,8 @@ SYSCALL_DEFINE4(mknodat, int, dfd, const char __user *, filename, umode_t, mode,
47920 break;
47921 }
47922 out:
47923+ if (!error)
47924+ gr_handle_create(dentry, path.mnt);
47925 done_path_create(&path, dentry);
47926 return error;
47927 }
47928@@ -3181,9 +3339,18 @@ SYSCALL_DEFINE3(mkdirat, int, dfd, const char __user *, pathname, umode_t, mode)
47929
47930 if (!IS_POSIXACL(path.dentry->d_inode))
47931 mode &= ~current_umask();
47932+
47933+ if (!gr_acl_handle_mkdir(dentry, path.dentry, path.mnt)) {
47934+ error = -EACCES;
47935+ goto out;
47936+ }
47937+
47938 error = security_path_mkdir(&path, dentry, mode);
47939 if (!error)
47940 error = vfs_mkdir(path.dentry->d_inode, dentry, mode);
47941+ if (!error)
47942+ gr_handle_create(dentry, path.mnt);
47943+out:
47944 done_path_create(&path, dentry);
47945 return error;
47946 }
47947@@ -3260,6 +3427,8 @@ static long do_rmdir(int dfd, const char __user *pathname)
47948 char * name;
47949 struct dentry *dentry;
47950 struct nameidata nd;
47951+ ino_t saved_ino = 0;
47952+ dev_t saved_dev = 0;
47953
47954 error = user_path_parent(dfd, pathname, &nd, &name);
47955 if (error)
47956@@ -3291,10 +3460,21 @@ static long do_rmdir(int dfd, const char __user *pathname)
47957 error = -ENOENT;
47958 goto exit3;
47959 }
47960+
47961+ saved_ino = dentry->d_inode->i_ino;
47962+ saved_dev = gr_get_dev_from_dentry(dentry);
47963+
47964+ if (!gr_acl_handle_rmdir(dentry, nd.path.mnt)) {
47965+ error = -EACCES;
47966+ goto exit3;
47967+ }
47968+
47969 error = security_path_rmdir(&nd.path, dentry);
47970 if (error)
47971 goto exit3;
47972 error = vfs_rmdir(nd.path.dentry->d_inode, dentry);
47973+ if (!error && (saved_dev || saved_ino))
47974+ gr_handle_delete(saved_ino, saved_dev);
47975 exit3:
47976 dput(dentry);
47977 exit2:
47978@@ -3356,6 +3536,8 @@ static long do_unlinkat(int dfd, const char __user *pathname)
47979 struct dentry *dentry;
47980 struct nameidata nd;
47981 struct inode *inode = NULL;
47982+ ino_t saved_ino = 0;
47983+ dev_t saved_dev = 0;
47984
47985 error = user_path_parent(dfd, pathname, &nd, &name);
47986 if (error)
47987@@ -3381,10 +3563,22 @@ static long do_unlinkat(int dfd, const char __user *pathname)
47988 if (!inode)
47989 goto slashes;
47990 ihold(inode);
47991+
47992+ if (inode->i_nlink <= 1) {
47993+ saved_ino = inode->i_ino;
47994+ saved_dev = gr_get_dev_from_dentry(dentry);
47995+ }
47996+ if (!gr_acl_handle_unlink(dentry, nd.path.mnt)) {
47997+ error = -EACCES;
47998+ goto exit2;
47999+ }
48000+
48001 error = security_path_unlink(&nd.path, dentry);
48002 if (error)
48003 goto exit2;
48004 error = vfs_unlink(nd.path.dentry->d_inode, dentry);
48005+ if (!error && (saved_ino || saved_dev))
48006+ gr_handle_delete(saved_ino, saved_dev);
48007 exit2:
48008 dput(dentry);
48009 }
48010@@ -3456,9 +3650,17 @@ SYSCALL_DEFINE3(symlinkat, const char __user *, oldname,
48011 if (IS_ERR(dentry))
48012 goto out_putname;
48013
48014+ if (!gr_acl_handle_symlink(dentry, path.dentry, path.mnt, from)) {
48015+ error = -EACCES;
48016+ goto out;
48017+ }
48018+
48019 error = security_path_symlink(&path, dentry, from);
48020 if (!error)
48021 error = vfs_symlink(path.dentry->d_inode, dentry, from);
48022+ if (!error)
48023+ gr_handle_create(dentry, path.mnt);
48024+out:
48025 done_path_create(&path, dentry);
48026 out_putname:
48027 putname(from);
48028@@ -3528,6 +3730,7 @@ SYSCALL_DEFINE5(linkat, int, olddfd, const char __user *, oldname,
48029 {
48030 struct dentry *new_dentry;
48031 struct path old_path, new_path;
48032+ char *to = NULL;
48033 int how = 0;
48034 int error;
48035
48036@@ -3551,7 +3754,7 @@ SYSCALL_DEFINE5(linkat, int, olddfd, const char __user *, oldname,
48037 if (error)
48038 return error;
48039
48040- new_dentry = user_path_create(newdfd, newname, &new_path, 0);
48041+ new_dentry = user_path_create_with_name(newdfd, newname, &new_path, &to, 0);
48042 error = PTR_ERR(new_dentry);
48043 if (IS_ERR(new_dentry))
48044 goto out;
48045@@ -3562,11 +3765,28 @@ SYSCALL_DEFINE5(linkat, int, olddfd, const char __user *, oldname,
48046 error = may_linkat(&old_path);
48047 if (unlikely(error))
48048 goto out_dput;
48049+
48050+ if (gr_handle_hardlink(old_path.dentry, old_path.mnt,
48051+ old_path.dentry->d_inode,
48052+ old_path.dentry->d_inode->i_mode, to)) {
48053+ error = -EACCES;
48054+ goto out_dput;
48055+ }
48056+
48057+ if (!gr_acl_handle_link(new_dentry, new_path.dentry, new_path.mnt,
48058+ old_path.dentry, old_path.mnt, to)) {
48059+ error = -EACCES;
48060+ goto out_dput;
48061+ }
48062+
48063 error = security_path_link(old_path.dentry, &new_path, new_dentry);
48064 if (error)
48065 goto out_dput;
48066 error = vfs_link(old_path.dentry, new_path.dentry->d_inode, new_dentry);
48067+ if (!error)
48068+ gr_handle_create(new_dentry, new_path.mnt);
48069 out_dput:
48070+ putname(to);
48071 done_path_create(&new_path, new_dentry);
48072 out:
48073 path_put(&old_path);
48074@@ -3802,12 +4022,21 @@ SYSCALL_DEFINE4(renameat, int, olddfd, const char __user *, oldname,
48075 if (new_dentry == trap)
48076 goto exit5;
48077
48078+ error = gr_acl_handle_rename(new_dentry, new_dir, newnd.path.mnt,
48079+ old_dentry, old_dir->d_inode, oldnd.path.mnt,
48080+ to);
48081+ if (error)
48082+ goto exit5;
48083+
48084 error = security_path_rename(&oldnd.path, old_dentry,
48085 &newnd.path, new_dentry);
48086 if (error)
48087 goto exit5;
48088 error = vfs_rename(old_dir->d_inode, old_dentry,
48089 new_dir->d_inode, new_dentry);
48090+ if (!error)
48091+ gr_handle_rename(old_dir->d_inode, new_dir->d_inode, old_dentry,
48092+ new_dentry, oldnd.path.mnt, new_dentry->d_inode ? 1 : 0);
48093 exit5:
48094 dput(new_dentry);
48095 exit4:
48096@@ -3832,6 +4061,8 @@ SYSCALL_DEFINE2(rename, const char __user *, oldname, const char __user *, newna
48097
48098 int vfs_readlink(struct dentry *dentry, char __user *buffer, int buflen, const char *link)
48099 {
48100+ char tmpbuf[64];
48101+ const char *newlink;
48102 int len;
48103
48104 len = PTR_ERR(link);
48105@@ -3841,7 +4072,14 @@ int vfs_readlink(struct dentry *dentry, char __user *buffer, int buflen, const c
48106 len = strlen(link);
48107 if (len > (unsigned) buflen)
48108 len = buflen;
48109- if (copy_to_user(buffer, link, len))
48110+
48111+ if (len < sizeof(tmpbuf)) {
48112+ memcpy(tmpbuf, link, len);
48113+ newlink = tmpbuf;
48114+ } else
48115+ newlink = link;
48116+
48117+ if (copy_to_user(buffer, newlink, len))
48118 len = -EFAULT;
48119 out:
48120 return len;
48121diff --git a/fs/namespace.c b/fs/namespace.c
48122index 7bdf790..eb79c4b 100644
48123--- a/fs/namespace.c
48124+++ b/fs/namespace.c
48125@@ -1212,6 +1212,9 @@ static int do_umount(struct mount *mnt, int flags)
48126 if (!(sb->s_flags & MS_RDONLY))
48127 retval = do_remount_sb(sb, MS_RDONLY, NULL, 0);
48128 up_write(&sb->s_umount);
48129+
48130+ gr_log_remount(mnt->mnt_devname, retval);
48131+
48132 return retval;
48133 }
48134
48135@@ -1231,6 +1234,9 @@ static int do_umount(struct mount *mnt, int flags)
48136 br_write_unlock(&vfsmount_lock);
48137 up_write(&namespace_sem);
48138 release_mounts(&umount_list);
48139+
48140+ gr_log_unmount(mnt->mnt_devname, retval);
48141+
48142 return retval;
48143 }
48144
48145@@ -2244,6 +2250,16 @@ long do_mount(char *dev_name, char *dir_name, char *type_page,
48146 MS_NOATIME | MS_NODIRATIME | MS_RELATIME| MS_KERNMOUNT |
48147 MS_STRICTATIME);
48148
48149+ if (gr_handle_rofs_mount(path.dentry, path.mnt, mnt_flags)) {
48150+ retval = -EPERM;
48151+ goto dput_out;
48152+ }
48153+
48154+ if (gr_handle_chroot_mount(path.dentry, path.mnt, dev_name)) {
48155+ retval = -EPERM;
48156+ goto dput_out;
48157+ }
48158+
48159 if (flags & MS_REMOUNT)
48160 retval = do_remount(&path, flags & ~MS_REMOUNT, mnt_flags,
48161 data_page);
48162@@ -2258,6 +2274,9 @@ long do_mount(char *dev_name, char *dir_name, char *type_page,
48163 dev_name, data_page);
48164 dput_out:
48165 path_put(&path);
48166+
48167+ gr_log_mount(dev_name, dir_name, retval);
48168+
48169 return retval;
48170 }
48171
48172@@ -2516,6 +2535,11 @@ SYSCALL_DEFINE2(pivot_root, const char __user *, new_root,
48173 if (error)
48174 goto out2;
48175
48176+ if (gr_handle_chroot_pivot()) {
48177+ error = -EPERM;
48178+ goto out2;
48179+ }
48180+
48181 get_fs_root(current->fs, &root);
48182 error = lock_mount(&old);
48183 if (error)
48184diff --git a/fs/nfs/inode.c b/fs/nfs/inode.c
48185index 9b47610..066975e 100644
48186--- a/fs/nfs/inode.c
48187+++ b/fs/nfs/inode.c
48188@@ -1026,16 +1026,16 @@ static int nfs_size_need_update(const struct inode *inode, const struct nfs_fatt
48189 return nfs_size_to_loff_t(fattr->size) > i_size_read(inode);
48190 }
48191
48192-static atomic_long_t nfs_attr_generation_counter;
48193+static atomic_long_unchecked_t nfs_attr_generation_counter;
48194
48195 static unsigned long nfs_read_attr_generation_counter(void)
48196 {
48197- return atomic_long_read(&nfs_attr_generation_counter);
48198+ return atomic_long_read_unchecked(&nfs_attr_generation_counter);
48199 }
48200
48201 unsigned long nfs_inc_attr_generation_counter(void)
48202 {
48203- return atomic_long_inc_return(&nfs_attr_generation_counter);
48204+ return atomic_long_inc_return_unchecked(&nfs_attr_generation_counter);
48205 }
48206
48207 void nfs_fattr_init(struct nfs_fattr *fattr)
48208diff --git a/fs/nfsd/vfs.c b/fs/nfsd/vfs.c
48209index a9269f1..5490437 100644
48210--- a/fs/nfsd/vfs.c
48211+++ b/fs/nfsd/vfs.c
48212@@ -941,7 +941,7 @@ nfsd_vfs_read(struct svc_rqst *rqstp, struct svc_fh *fhp, struct file *file,
48213 } else {
48214 oldfs = get_fs();
48215 set_fs(KERNEL_DS);
48216- host_err = vfs_readv(file, (struct iovec __user *)vec, vlen, &offset);
48217+ host_err = vfs_readv(file, (struct iovec __force_user *)vec, vlen, &offset);
48218 set_fs(oldfs);
48219 }
48220
48221@@ -1045,7 +1045,7 @@ nfsd_vfs_write(struct svc_rqst *rqstp, struct svc_fh *fhp, struct file *file,
48222
48223 /* Write the data. */
48224 oldfs = get_fs(); set_fs(KERNEL_DS);
48225- host_err = vfs_writev(file, (struct iovec __user *)vec, vlen, &offset);
48226+ host_err = vfs_writev(file, (struct iovec __force_user *)vec, vlen, &offset);
48227 set_fs(oldfs);
48228 if (host_err < 0)
48229 goto out_nfserr;
48230@@ -1581,7 +1581,7 @@ nfsd_readlink(struct svc_rqst *rqstp, struct svc_fh *fhp, char *buf, int *lenp)
48231 */
48232
48233 oldfs = get_fs(); set_fs(KERNEL_DS);
48234- host_err = inode->i_op->readlink(path.dentry, buf, *lenp);
48235+ host_err = inode->i_op->readlink(path.dentry, (char __force_user *)buf, *lenp);
48236 set_fs(oldfs);
48237
48238 if (host_err < 0)
48239diff --git a/fs/notify/fanotify/fanotify_user.c b/fs/notify/fanotify/fanotify_user.c
48240index d438036..0ecadde 100644
48241--- a/fs/notify/fanotify/fanotify_user.c
48242+++ b/fs/notify/fanotify/fanotify_user.c
48243@@ -274,7 +274,8 @@ static ssize_t copy_event_to_user(struct fsnotify_group *group,
48244 goto out_close_fd;
48245
48246 ret = -EFAULT;
48247- if (copy_to_user(buf, &fanotify_event_metadata,
48248+ if (fanotify_event_metadata.event_len > sizeof fanotify_event_metadata ||
48249+ copy_to_user(buf, &fanotify_event_metadata,
48250 fanotify_event_metadata.event_len))
48251 goto out_kill_access_response;
48252
48253diff --git a/fs/notify/notification.c b/fs/notify/notification.c
48254index c887b13..0fdf472 100644
48255--- a/fs/notify/notification.c
48256+++ b/fs/notify/notification.c
48257@@ -57,7 +57,7 @@ static struct kmem_cache *fsnotify_event_holder_cachep;
48258 * get set to 0 so it will never get 'freed'
48259 */
48260 static struct fsnotify_event *q_overflow_event;
48261-static atomic_t fsnotify_sync_cookie = ATOMIC_INIT(0);
48262+static atomic_unchecked_t fsnotify_sync_cookie = ATOMIC_INIT(0);
48263
48264 /**
48265 * fsnotify_get_cookie - return a unique cookie for use in synchronizing events.
48266@@ -65,7 +65,7 @@ static atomic_t fsnotify_sync_cookie = ATOMIC_INIT(0);
48267 */
48268 u32 fsnotify_get_cookie(void)
48269 {
48270- return atomic_inc_return(&fsnotify_sync_cookie);
48271+ return atomic_inc_return_unchecked(&fsnotify_sync_cookie);
48272 }
48273 EXPORT_SYMBOL_GPL(fsnotify_get_cookie);
48274
48275diff --git a/fs/ntfs/dir.c b/fs/ntfs/dir.c
48276index 99e3610..02c1068 100644
48277--- a/fs/ntfs/dir.c
48278+++ b/fs/ntfs/dir.c
48279@@ -1329,7 +1329,7 @@ find_next_index_buffer:
48280 ia = (INDEX_ALLOCATION*)(kaddr + (ia_pos & ~PAGE_CACHE_MASK &
48281 ~(s64)(ndir->itype.index.block_size - 1)));
48282 /* Bounds checks. */
48283- if (unlikely((u8*)ia < kaddr || (u8*)ia > kaddr + PAGE_CACHE_SIZE)) {
48284+ if (unlikely(!kaddr || (u8*)ia < kaddr || (u8*)ia > kaddr + PAGE_CACHE_SIZE)) {
48285 ntfs_error(sb, "Out of bounds check failed. Corrupt directory "
48286 "inode 0x%lx or driver bug.", vdir->i_ino);
48287 goto err_out;
48288diff --git a/fs/ntfs/file.c b/fs/ntfs/file.c
48289index 1ecf464..e1ff8bf 100644
48290--- a/fs/ntfs/file.c
48291+++ b/fs/ntfs/file.c
48292@@ -2232,6 +2232,6 @@ const struct inode_operations ntfs_file_inode_ops = {
48293 #endif /* NTFS_RW */
48294 };
48295
48296-const struct file_operations ntfs_empty_file_ops = {};
48297+const struct file_operations ntfs_empty_file_ops __read_only;
48298
48299-const struct inode_operations ntfs_empty_inode_ops = {};
48300+const struct inode_operations ntfs_empty_inode_ops __read_only;
48301diff --git a/fs/ocfs2/localalloc.c b/fs/ocfs2/localalloc.c
48302index a9f78c7..ed8a381 100644
48303--- a/fs/ocfs2/localalloc.c
48304+++ b/fs/ocfs2/localalloc.c
48305@@ -1279,7 +1279,7 @@ static int ocfs2_local_alloc_slide_window(struct ocfs2_super *osb,
48306 goto bail;
48307 }
48308
48309- atomic_inc(&osb->alloc_stats.moves);
48310+ atomic_inc_unchecked(&osb->alloc_stats.moves);
48311
48312 bail:
48313 if (handle)
48314diff --git a/fs/ocfs2/ocfs2.h b/fs/ocfs2/ocfs2.h
48315index d355e6e..578d905 100644
48316--- a/fs/ocfs2/ocfs2.h
48317+++ b/fs/ocfs2/ocfs2.h
48318@@ -235,11 +235,11 @@ enum ocfs2_vol_state
48319
48320 struct ocfs2_alloc_stats
48321 {
48322- atomic_t moves;
48323- atomic_t local_data;
48324- atomic_t bitmap_data;
48325- atomic_t bg_allocs;
48326- atomic_t bg_extends;
48327+ atomic_unchecked_t moves;
48328+ atomic_unchecked_t local_data;
48329+ atomic_unchecked_t bitmap_data;
48330+ atomic_unchecked_t bg_allocs;
48331+ atomic_unchecked_t bg_extends;
48332 };
48333
48334 enum ocfs2_local_alloc_state
48335diff --git a/fs/ocfs2/suballoc.c b/fs/ocfs2/suballoc.c
48336index f169da4..9112253 100644
48337--- a/fs/ocfs2/suballoc.c
48338+++ b/fs/ocfs2/suballoc.c
48339@@ -872,7 +872,7 @@ static int ocfs2_reserve_suballoc_bits(struct ocfs2_super *osb,
48340 mlog_errno(status);
48341 goto bail;
48342 }
48343- atomic_inc(&osb->alloc_stats.bg_extends);
48344+ atomic_inc_unchecked(&osb->alloc_stats.bg_extends);
48345
48346 /* You should never ask for this much metadata */
48347 BUG_ON(bits_wanted >
48348@@ -2008,7 +2008,7 @@ int ocfs2_claim_metadata(handle_t *handle,
48349 mlog_errno(status);
48350 goto bail;
48351 }
48352- atomic_inc(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
48353+ atomic_inc_unchecked(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
48354
48355 *suballoc_loc = res.sr_bg_blkno;
48356 *suballoc_bit_start = res.sr_bit_offset;
48357@@ -2172,7 +2172,7 @@ int ocfs2_claim_new_inode_at_loc(handle_t *handle,
48358 trace_ocfs2_claim_new_inode_at_loc((unsigned long long)di_blkno,
48359 res->sr_bits);
48360
48361- atomic_inc(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
48362+ atomic_inc_unchecked(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
48363
48364 BUG_ON(res->sr_bits != 1);
48365
48366@@ -2214,7 +2214,7 @@ int ocfs2_claim_new_inode(handle_t *handle,
48367 mlog_errno(status);
48368 goto bail;
48369 }
48370- atomic_inc(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
48371+ atomic_inc_unchecked(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
48372
48373 BUG_ON(res.sr_bits != 1);
48374
48375@@ -2318,7 +2318,7 @@ int __ocfs2_claim_clusters(handle_t *handle,
48376 cluster_start,
48377 num_clusters);
48378 if (!status)
48379- atomic_inc(&osb->alloc_stats.local_data);
48380+ atomic_inc_unchecked(&osb->alloc_stats.local_data);
48381 } else {
48382 if (min_clusters > (osb->bitmap_cpg - 1)) {
48383 /* The only paths asking for contiguousness
48384@@ -2344,7 +2344,7 @@ int __ocfs2_claim_clusters(handle_t *handle,
48385 ocfs2_desc_bitmap_to_cluster_off(ac->ac_inode,
48386 res.sr_bg_blkno,
48387 res.sr_bit_offset);
48388- atomic_inc(&osb->alloc_stats.bitmap_data);
48389+ atomic_inc_unchecked(&osb->alloc_stats.bitmap_data);
48390 *num_clusters = res.sr_bits;
48391 }
48392 }
48393diff --git a/fs/ocfs2/super.c b/fs/ocfs2/super.c
48394index 68f4541..89cfe6a 100644
48395--- a/fs/ocfs2/super.c
48396+++ b/fs/ocfs2/super.c
48397@@ -301,11 +301,11 @@ static int ocfs2_osb_dump(struct ocfs2_super *osb, char *buf, int len)
48398 "%10s => GlobalAllocs: %d LocalAllocs: %d "
48399 "SubAllocs: %d LAWinMoves: %d SAExtends: %d\n",
48400 "Stats",
48401- atomic_read(&osb->alloc_stats.bitmap_data),
48402- atomic_read(&osb->alloc_stats.local_data),
48403- atomic_read(&osb->alloc_stats.bg_allocs),
48404- atomic_read(&osb->alloc_stats.moves),
48405- atomic_read(&osb->alloc_stats.bg_extends));
48406+ atomic_read_unchecked(&osb->alloc_stats.bitmap_data),
48407+ atomic_read_unchecked(&osb->alloc_stats.local_data),
48408+ atomic_read_unchecked(&osb->alloc_stats.bg_allocs),
48409+ atomic_read_unchecked(&osb->alloc_stats.moves),
48410+ atomic_read_unchecked(&osb->alloc_stats.bg_extends));
48411
48412 out += snprintf(buf + out, len - out,
48413 "%10s => State: %u Descriptor: %llu Size: %u bits "
48414@@ -2116,11 +2116,11 @@ static int ocfs2_initialize_super(struct super_block *sb,
48415 spin_lock_init(&osb->osb_xattr_lock);
48416 ocfs2_init_steal_slots(osb);
48417
48418- atomic_set(&osb->alloc_stats.moves, 0);
48419- atomic_set(&osb->alloc_stats.local_data, 0);
48420- atomic_set(&osb->alloc_stats.bitmap_data, 0);
48421- atomic_set(&osb->alloc_stats.bg_allocs, 0);
48422- atomic_set(&osb->alloc_stats.bg_extends, 0);
48423+ atomic_set_unchecked(&osb->alloc_stats.moves, 0);
48424+ atomic_set_unchecked(&osb->alloc_stats.local_data, 0);
48425+ atomic_set_unchecked(&osb->alloc_stats.bitmap_data, 0);
48426+ atomic_set_unchecked(&osb->alloc_stats.bg_allocs, 0);
48427+ atomic_set_unchecked(&osb->alloc_stats.bg_extends, 0);
48428
48429 /* Copy the blockcheck stats from the superblock probe */
48430 osb->osb_ecc_stats = *stats;
48431diff --git a/fs/open.c b/fs/open.c
48432index e1f2cdb..3bd5f39 100644
48433--- a/fs/open.c
48434+++ b/fs/open.c
48435@@ -31,6 +31,8 @@
48436 #include <linux/ima.h>
48437 #include <linux/dnotify.h>
48438
48439+#define CREATE_TRACE_POINTS
48440+#include <trace/events/fs.h>
48441 #include "internal.h"
48442
48443 int do_truncate(struct dentry *dentry, loff_t length, unsigned int time_attrs,
48444@@ -112,6 +114,10 @@ static long do_sys_truncate(const char __user *pathname, loff_t length)
48445 error = locks_verify_truncate(inode, NULL, length);
48446 if (!error)
48447 error = security_path_truncate(&path);
48448+
48449+ if (!error && !gr_acl_handle_truncate(path.dentry, path.mnt))
48450+ error = -EACCES;
48451+
48452 if (!error)
48453 error = do_truncate(path.dentry, length, 0, NULL);
48454
48455@@ -364,6 +370,9 @@ SYSCALL_DEFINE3(faccessat, int, dfd, const char __user *, filename, int, mode)
48456 if (__mnt_is_readonly(path.mnt))
48457 res = -EROFS;
48458
48459+ if (!res && !gr_acl_handle_access(path.dentry, path.mnt, mode))
48460+ res = -EACCES;
48461+
48462 out_path_release:
48463 path_put(&path);
48464 out:
48465@@ -390,6 +399,8 @@ SYSCALL_DEFINE1(chdir, const char __user *, filename)
48466 if (error)
48467 goto dput_and_out;
48468
48469+ gr_log_chdir(path.dentry, path.mnt);
48470+
48471 set_fs_pwd(current->fs, &path);
48472
48473 dput_and_out:
48474@@ -416,6 +427,13 @@ SYSCALL_DEFINE1(fchdir, unsigned int, fd)
48475 goto out_putf;
48476
48477 error = inode_permission(inode, MAY_EXEC | MAY_CHDIR);
48478+
48479+ if (!error && !gr_chroot_fchdir(file->f_path.dentry, file->f_path.mnt))
48480+ error = -EPERM;
48481+
48482+ if (!error)
48483+ gr_log_chdir(file->f_path.dentry, file->f_path.mnt);
48484+
48485 if (!error)
48486 set_fs_pwd(current->fs, &file->f_path);
48487 out_putf:
48488@@ -444,7 +462,13 @@ SYSCALL_DEFINE1(chroot, const char __user *, filename)
48489 if (error)
48490 goto dput_and_out;
48491
48492+ if (gr_handle_chroot_chroot(path.dentry, path.mnt))
48493+ goto dput_and_out;
48494+
48495 set_fs_root(current->fs, &path);
48496+
48497+ gr_handle_chroot_chdir(&path);
48498+
48499 error = 0;
48500 dput_and_out:
48501 path_put(&path);
48502@@ -462,6 +486,16 @@ static int chmod_common(struct path *path, umode_t mode)
48503 if (error)
48504 return error;
48505 mutex_lock(&inode->i_mutex);
48506+
48507+ if (!gr_acl_handle_chmod(path->dentry, path->mnt, &mode)) {
48508+ error = -EACCES;
48509+ goto out_unlock;
48510+ }
48511+ if (gr_handle_chroot_chmod(path->dentry, path->mnt, mode)) {
48512+ error = -EACCES;
48513+ goto out_unlock;
48514+ }
48515+
48516 error = security_path_chmod(path, mode);
48517 if (error)
48518 goto out_unlock;
48519@@ -517,6 +551,9 @@ static int chown_common(struct path *path, uid_t user, gid_t group)
48520 uid = make_kuid(current_user_ns(), user);
48521 gid = make_kgid(current_user_ns(), group);
48522
48523+ if (!gr_acl_handle_chown(path->dentry, path->mnt))
48524+ return -EACCES;
48525+
48526 newattrs.ia_valid = ATTR_CTIME;
48527 if (user != (uid_t) -1) {
48528 if (!uid_valid(uid))
48529@@ -958,6 +995,7 @@ long do_sys_open(int dfd, const char __user *filename, int flags, umode_t mode)
48530 } else {
48531 fsnotify_open(f);
48532 fd_install(fd, f);
48533+ trace_do_sys_open(tmp, flags, mode);
48534 }
48535 }
48536 putname(tmp);
48537diff --git a/fs/pipe.c b/fs/pipe.c
48538index 8d85d70..581036b 100644
48539--- a/fs/pipe.c
48540+++ b/fs/pipe.c
48541@@ -438,9 +438,9 @@ redo:
48542 }
48543 if (bufs) /* More to do? */
48544 continue;
48545- if (!pipe->writers)
48546+ if (!atomic_read(&pipe->writers))
48547 break;
48548- if (!pipe->waiting_writers) {
48549+ if (!atomic_read(&pipe->waiting_writers)) {
48550 /* syscall merging: Usually we must not sleep
48551 * if O_NONBLOCK is set, or if we got some data.
48552 * But if a writer sleeps in kernel space, then
48553@@ -504,7 +504,7 @@ pipe_write(struct kiocb *iocb, const struct iovec *_iov,
48554 mutex_lock(&inode->i_mutex);
48555 pipe = inode->i_pipe;
48556
48557- if (!pipe->readers) {
48558+ if (!atomic_read(&pipe->readers)) {
48559 send_sig(SIGPIPE, current, 0);
48560 ret = -EPIPE;
48561 goto out;
48562@@ -553,7 +553,7 @@ redo1:
48563 for (;;) {
48564 int bufs;
48565
48566- if (!pipe->readers) {
48567+ if (!atomic_read(&pipe->readers)) {
48568 send_sig(SIGPIPE, current, 0);
48569 if (!ret)
48570 ret = -EPIPE;
48571@@ -644,9 +644,9 @@ redo2:
48572 kill_fasync(&pipe->fasync_readers, SIGIO, POLL_IN);
48573 do_wakeup = 0;
48574 }
48575- pipe->waiting_writers++;
48576+ atomic_inc(&pipe->waiting_writers);
48577 pipe_wait(pipe);
48578- pipe->waiting_writers--;
48579+ atomic_dec(&pipe->waiting_writers);
48580 }
48581 out:
48582 mutex_unlock(&inode->i_mutex);
48583@@ -716,7 +716,7 @@ pipe_poll(struct file *filp, poll_table *wait)
48584 mask = 0;
48585 if (filp->f_mode & FMODE_READ) {
48586 mask = (nrbufs > 0) ? POLLIN | POLLRDNORM : 0;
48587- if (!pipe->writers && filp->f_version != pipe->w_counter)
48588+ if (!atomic_read(&pipe->writers) && filp->f_version != pipe->w_counter)
48589 mask |= POLLHUP;
48590 }
48591
48592@@ -726,7 +726,7 @@ pipe_poll(struct file *filp, poll_table *wait)
48593 * Most Unices do not set POLLERR for FIFOs but on Linux they
48594 * behave exactly like pipes for poll().
48595 */
48596- if (!pipe->readers)
48597+ if (!atomic_read(&pipe->readers))
48598 mask |= POLLERR;
48599 }
48600
48601@@ -740,10 +740,10 @@ pipe_release(struct inode *inode, int decr, int decw)
48602
48603 mutex_lock(&inode->i_mutex);
48604 pipe = inode->i_pipe;
48605- pipe->readers -= decr;
48606- pipe->writers -= decw;
48607+ atomic_sub(decr, &pipe->readers);
48608+ atomic_sub(decw, &pipe->writers);
48609
48610- if (!pipe->readers && !pipe->writers) {
48611+ if (!atomic_read(&pipe->readers) && !atomic_read(&pipe->writers)) {
48612 free_pipe_info(inode);
48613 } else {
48614 wake_up_interruptible_sync_poll(&pipe->wait, POLLIN | POLLOUT | POLLRDNORM | POLLWRNORM | POLLERR | POLLHUP);
48615@@ -833,7 +833,7 @@ pipe_read_open(struct inode *inode, struct file *filp)
48616
48617 if (inode->i_pipe) {
48618 ret = 0;
48619- inode->i_pipe->readers++;
48620+ atomic_inc(&inode->i_pipe->readers);
48621 }
48622
48623 mutex_unlock(&inode->i_mutex);
48624@@ -850,7 +850,7 @@ pipe_write_open(struct inode *inode, struct file *filp)
48625
48626 if (inode->i_pipe) {
48627 ret = 0;
48628- inode->i_pipe->writers++;
48629+ atomic_inc(&inode->i_pipe->writers);
48630 }
48631
48632 mutex_unlock(&inode->i_mutex);
48633@@ -868,9 +868,9 @@ pipe_rdwr_open(struct inode *inode, struct file *filp)
48634 if (inode->i_pipe) {
48635 ret = 0;
48636 if (filp->f_mode & FMODE_READ)
48637- inode->i_pipe->readers++;
48638+ atomic_inc(&inode->i_pipe->readers);
48639 if (filp->f_mode & FMODE_WRITE)
48640- inode->i_pipe->writers++;
48641+ atomic_inc(&inode->i_pipe->writers);
48642 }
48643
48644 mutex_unlock(&inode->i_mutex);
48645@@ -962,7 +962,7 @@ void free_pipe_info(struct inode *inode)
48646 inode->i_pipe = NULL;
48647 }
48648
48649-static struct vfsmount *pipe_mnt __read_mostly;
48650+struct vfsmount *pipe_mnt __read_mostly;
48651
48652 /*
48653 * pipefs_dname() is called from d_path().
48654@@ -992,7 +992,8 @@ static struct inode * get_pipe_inode(void)
48655 goto fail_iput;
48656 inode->i_pipe = pipe;
48657
48658- pipe->readers = pipe->writers = 1;
48659+ atomic_set(&pipe->readers, 1);
48660+ atomic_set(&pipe->writers, 1);
48661 inode->i_fop = &rdwr_pipefifo_fops;
48662
48663 /*
48664diff --git a/fs/proc/Kconfig b/fs/proc/Kconfig
48665index 15af622..0e9f4467 100644
48666--- a/fs/proc/Kconfig
48667+++ b/fs/proc/Kconfig
48668@@ -30,12 +30,12 @@ config PROC_FS
48669
48670 config PROC_KCORE
48671 bool "/proc/kcore support" if !ARM
48672- depends on PROC_FS && MMU
48673+ depends on PROC_FS && MMU && !GRKERNSEC_PROC_ADD
48674
48675 config PROC_VMCORE
48676 bool "/proc/vmcore support"
48677- depends on PROC_FS && CRASH_DUMP
48678- default y
48679+ depends on PROC_FS && CRASH_DUMP && !GRKERNSEC
48680+ default n
48681 help
48682 Exports the dump image of crashed kernel in ELF format.
48683
48684@@ -59,8 +59,8 @@ config PROC_SYSCTL
48685 limited in memory.
48686
48687 config PROC_PAGE_MONITOR
48688- default y
48689- depends on PROC_FS && MMU
48690+ default n
48691+ depends on PROC_FS && MMU && !GRKERNSEC
48692 bool "Enable /proc page monitoring" if EXPERT
48693 help
48694 Various /proc files exist to monitor process memory utilization:
48695diff --git a/fs/proc/array.c b/fs/proc/array.c
48696index c1c207c..01ce725 100644
48697--- a/fs/proc/array.c
48698+++ b/fs/proc/array.c
48699@@ -60,6 +60,7 @@
48700 #include <linux/tty.h>
48701 #include <linux/string.h>
48702 #include <linux/mman.h>
48703+#include <linux/grsecurity.h>
48704 #include <linux/proc_fs.h>
48705 #include <linux/ioport.h>
48706 #include <linux/uaccess.h>
48707@@ -346,6 +347,21 @@ static void task_cpus_allowed(struct seq_file *m, struct task_struct *task)
48708 seq_putc(m, '\n');
48709 }
48710
48711+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
48712+static inline void task_pax(struct seq_file *m, struct task_struct *p)
48713+{
48714+ if (p->mm)
48715+ seq_printf(m, "PaX:\t%c%c%c%c%c\n",
48716+ p->mm->pax_flags & MF_PAX_PAGEEXEC ? 'P' : 'p',
48717+ p->mm->pax_flags & MF_PAX_EMUTRAMP ? 'E' : 'e',
48718+ p->mm->pax_flags & MF_PAX_MPROTECT ? 'M' : 'm',
48719+ p->mm->pax_flags & MF_PAX_RANDMMAP ? 'R' : 'r',
48720+ p->mm->pax_flags & MF_PAX_SEGMEXEC ? 'S' : 's');
48721+ else
48722+ seq_printf(m, "PaX:\t-----\n");
48723+}
48724+#endif
48725+
48726 int proc_pid_status(struct seq_file *m, struct pid_namespace *ns,
48727 struct pid *pid, struct task_struct *task)
48728 {
48729@@ -363,9 +379,24 @@ int proc_pid_status(struct seq_file *m, struct pid_namespace *ns,
48730 task_cpus_allowed(m, task);
48731 cpuset_task_status_allowed(m, task);
48732 task_context_switch_counts(m, task);
48733+
48734+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
48735+ task_pax(m, task);
48736+#endif
48737+
48738+#if defined(CONFIG_GRKERNSEC) && !defined(CONFIG_GRKERNSEC_NO_RBAC)
48739+ task_grsec_rbac(m, task);
48740+#endif
48741+
48742 return 0;
48743 }
48744
48745+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
48746+#define PAX_RAND_FLAGS(_mm) (_mm != NULL && _mm != current->mm && \
48747+ (_mm->pax_flags & MF_PAX_RANDMMAP || \
48748+ _mm->pax_flags & MF_PAX_SEGMEXEC))
48749+#endif
48750+
48751 static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
48752 struct pid *pid, struct task_struct *task, int whole)
48753 {
48754@@ -387,6 +418,13 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
48755 char tcomm[sizeof(task->comm)];
48756 unsigned long flags;
48757
48758+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
48759+ if (current->exec_id != m->exec_id) {
48760+ gr_log_badprocpid("stat");
48761+ return 0;
48762+ }
48763+#endif
48764+
48765 state = *get_task_state(task);
48766 vsize = eip = esp = 0;
48767 permitted = ptrace_may_access(task, PTRACE_MODE_READ | PTRACE_MODE_NOAUDIT);
48768@@ -458,6 +496,19 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
48769 gtime = task->gtime;
48770 }
48771
48772+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
48773+ if (PAX_RAND_FLAGS(mm)) {
48774+ eip = 0;
48775+ esp = 0;
48776+ wchan = 0;
48777+ }
48778+#endif
48779+#ifdef CONFIG_GRKERNSEC_HIDESYM
48780+ wchan = 0;
48781+ eip =0;
48782+ esp =0;
48783+#endif
48784+
48785 /* scale priority and nice values from timeslices to -20..20 */
48786 /* to make it look like a "normal" Unix priority/nice value */
48787 priority = task_prio(task);
48788@@ -494,9 +545,15 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
48789 seq_put_decimal_ull(m, ' ', vsize);
48790 seq_put_decimal_ull(m, ' ', mm ? get_mm_rss(mm) : 0);
48791 seq_put_decimal_ull(m, ' ', rsslim);
48792+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
48793+ seq_put_decimal_ull(m, ' ', PAX_RAND_FLAGS(mm) ? 1 : (mm ? (permitted ? mm->start_code : 1) : 0));
48794+ seq_put_decimal_ull(m, ' ', PAX_RAND_FLAGS(mm) ? 1 : (mm ? (permitted ? mm->end_code : 1) : 0));
48795+ seq_put_decimal_ull(m, ' ', PAX_RAND_FLAGS(mm) ? 0 : ((permitted && mm) ? mm->start_stack : 0));
48796+#else
48797 seq_put_decimal_ull(m, ' ', mm ? (permitted ? mm->start_code : 1) : 0);
48798 seq_put_decimal_ull(m, ' ', mm ? (permitted ? mm->end_code : 1) : 0);
48799 seq_put_decimal_ull(m, ' ', (permitted && mm) ? mm->start_stack : 0);
48800+#endif
48801 seq_put_decimal_ull(m, ' ', esp);
48802 seq_put_decimal_ull(m, ' ', eip);
48803 /* The signal information here is obsolete.
48804@@ -518,7 +575,11 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
48805 seq_put_decimal_ull(m, ' ', cputime_to_clock_t(gtime));
48806 seq_put_decimal_ll(m, ' ', cputime_to_clock_t(cgtime));
48807
48808- if (mm && permitted) {
48809+ if (mm && permitted
48810+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
48811+ && !PAX_RAND_FLAGS(mm)
48812+#endif
48813+ ) {
48814 seq_put_decimal_ull(m, ' ', mm->start_data);
48815 seq_put_decimal_ull(m, ' ', mm->end_data);
48816 seq_put_decimal_ull(m, ' ', mm->start_brk);
48817@@ -556,8 +617,15 @@ int proc_pid_statm(struct seq_file *m, struct pid_namespace *ns,
48818 struct pid *pid, struct task_struct *task)
48819 {
48820 unsigned long size = 0, resident = 0, shared = 0, text = 0, data = 0;
48821- struct mm_struct *mm = get_task_mm(task);
48822+ struct mm_struct *mm;
48823
48824+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
48825+ if (current->exec_id != m->exec_id) {
48826+ gr_log_badprocpid("statm");
48827+ return 0;
48828+ }
48829+#endif
48830+ mm = get_task_mm(task);
48831 if (mm) {
48832 size = task_statm(mm, &shared, &text, &data, &resident);
48833 mmput(mm);
48834@@ -580,6 +648,13 @@ int proc_pid_statm(struct seq_file *m, struct pid_namespace *ns,
48835 return 0;
48836 }
48837
48838+#ifdef CONFIG_GRKERNSEC_PROC_IPADDR
48839+int proc_pid_ipaddr(struct task_struct *task, char *buffer)
48840+{
48841+ return sprintf(buffer, "%pI4\n", &task->signal->curr_ip);
48842+}
48843+#endif
48844+
48845 #ifdef CONFIG_CHECKPOINT_RESTORE
48846 static struct pid *
48847 get_children_pid(struct inode *inode, struct pid *pid_prev, loff_t pos)
48848diff --git a/fs/proc/base.c b/fs/proc/base.c
48849index 1b6c84c..66b738b 100644
48850--- a/fs/proc/base.c
48851+++ b/fs/proc/base.c
48852@@ -110,6 +110,14 @@ struct pid_entry {
48853 union proc_op op;
48854 };
48855
48856+struct getdents_callback {
48857+ struct linux_dirent __user * current_dir;
48858+ struct linux_dirent __user * previous;
48859+ struct file * file;
48860+ int count;
48861+ int error;
48862+};
48863+
48864 #define NOD(NAME, MODE, IOP, FOP, OP) { \
48865 .name = (NAME), \
48866 .len = sizeof(NAME) - 1, \
48867@@ -209,6 +217,9 @@ static int proc_pid_cmdline(struct task_struct *task, char * buffer)
48868 if (!mm->arg_end)
48869 goto out_mm; /* Shh! No looking before we're done */
48870
48871+ if (gr_acl_handle_procpidmem(task))
48872+ goto out_mm;
48873+
48874 len = mm->arg_end - mm->arg_start;
48875
48876 if (len > PAGE_SIZE)
48877@@ -236,12 +247,28 @@ out:
48878 return res;
48879 }
48880
48881+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
48882+#define PAX_RAND_FLAGS(_mm) (_mm != NULL && _mm != current->mm && \
48883+ (_mm->pax_flags & MF_PAX_RANDMMAP || \
48884+ _mm->pax_flags & MF_PAX_SEGMEXEC))
48885+#endif
48886+
48887 static int proc_pid_auxv(struct task_struct *task, char *buffer)
48888 {
48889 struct mm_struct *mm = mm_access(task, PTRACE_MODE_READ);
48890 int res = PTR_ERR(mm);
48891 if (mm && !IS_ERR(mm)) {
48892 unsigned int nwords = 0;
48893+
48894+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
48895+ /* allow if we're currently ptracing this task */
48896+ if (PAX_RAND_FLAGS(mm) &&
48897+ (!(task->ptrace & PT_PTRACED) || (task->parent != current))) {
48898+ mmput(mm);
48899+ return 0;
48900+ }
48901+#endif
48902+
48903 do {
48904 nwords += 2;
48905 } while (mm->saved_auxv[nwords - 2] != 0); /* AT_NULL */
48906@@ -255,7 +282,7 @@ static int proc_pid_auxv(struct task_struct *task, char *buffer)
48907 }
48908
48909
48910-#ifdef CONFIG_KALLSYMS
48911+#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
48912 /*
48913 * Provides a wchan file via kallsyms in a proper one-value-per-file format.
48914 * Returns the resolved symbol. If that fails, simply return the address.
48915@@ -294,7 +321,7 @@ static void unlock_trace(struct task_struct *task)
48916 mutex_unlock(&task->signal->cred_guard_mutex);
48917 }
48918
48919-#ifdef CONFIG_STACKTRACE
48920+#if defined(CONFIG_STACKTRACE) && !defined(CONFIG_GRKERNSEC_HIDESYM)
48921
48922 #define MAX_STACK_TRACE_DEPTH 64
48923
48924@@ -486,7 +513,7 @@ static int proc_pid_limits(struct task_struct *task, char *buffer)
48925 return count;
48926 }
48927
48928-#ifdef CONFIG_HAVE_ARCH_TRACEHOOK
48929+#if defined(CONFIG_HAVE_ARCH_TRACEHOOK) && !defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
48930 static int proc_pid_syscall(struct task_struct *task, char *buffer)
48931 {
48932 long nr;
48933@@ -515,7 +542,7 @@ static int proc_pid_syscall(struct task_struct *task, char *buffer)
48934 /************************************************************************/
48935
48936 /* permission checks */
48937-static int proc_fd_access_allowed(struct inode *inode)
48938+static int proc_fd_access_allowed(struct inode *inode, unsigned int log)
48939 {
48940 struct task_struct *task;
48941 int allowed = 0;
48942@@ -525,7 +552,10 @@ static int proc_fd_access_allowed(struct inode *inode)
48943 */
48944 task = get_proc_task(inode);
48945 if (task) {
48946- allowed = ptrace_may_access(task, PTRACE_MODE_READ);
48947+ if (log)
48948+ allowed = ptrace_may_access(task, PTRACE_MODE_READ);
48949+ else
48950+ allowed = ptrace_may_access(task, PTRACE_MODE_READ | PTRACE_MODE_NOAUDIT);
48951 put_task_struct(task);
48952 }
48953 return allowed;
48954@@ -563,10 +593,35 @@ static bool has_pid_permissions(struct pid_namespace *pid,
48955 struct task_struct *task,
48956 int hide_pid_min)
48957 {
48958+ if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
48959+ return false;
48960+
48961+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
48962+ rcu_read_lock();
48963+ {
48964+ const struct cred *tmpcred = current_cred();
48965+ const struct cred *cred = __task_cred(task);
48966+
48967+ if (!tmpcred->uid || (tmpcred->uid == cred->uid)
48968+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
48969+ || in_group_p(grsec_proc_gid)
48970+#endif
48971+ ) {
48972+ rcu_read_unlock();
48973+ return true;
48974+ }
48975+ }
48976+ rcu_read_unlock();
48977+
48978+ if (!pid->hide_pid)
48979+ return false;
48980+#endif
48981+
48982 if (pid->hide_pid < hide_pid_min)
48983 return true;
48984 if (in_group_p(pid->pid_gid))
48985 return true;
48986+
48987 return ptrace_may_access(task, PTRACE_MODE_READ);
48988 }
48989
48990@@ -584,7 +639,11 @@ static int proc_pid_permission(struct inode *inode, int mask)
48991 put_task_struct(task);
48992
48993 if (!has_perms) {
48994+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
48995+ {
48996+#else
48997 if (pid->hide_pid == 2) {
48998+#endif
48999 /*
49000 * Let's make getdents(), stat(), and open()
49001 * consistent with each other. If a process
49002@@ -682,6 +741,11 @@ static int __mem_open(struct inode *inode, struct file *file, unsigned int mode)
49003 if (!task)
49004 return -ESRCH;
49005
49006+ if (gr_acl_handle_procpidmem(task)) {
49007+ put_task_struct(task);
49008+ return -EPERM;
49009+ }
49010+
49011 mm = mm_access(task, mode);
49012 put_task_struct(task);
49013
49014@@ -697,6 +761,10 @@ static int __mem_open(struct inode *inode, struct file *file, unsigned int mode)
49015
49016 file->private_data = mm;
49017
49018+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
49019+ file->f_version = current->exec_id;
49020+#endif
49021+
49022 return 0;
49023 }
49024
49025@@ -718,6 +786,17 @@ static ssize_t mem_rw(struct file *file, char __user *buf,
49026 ssize_t copied;
49027 char *page;
49028
49029+#ifdef CONFIG_GRKERNSEC
49030+ if (write)
49031+ return -EPERM;
49032+#endif
49033+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
49034+ if (file->f_version != current->exec_id) {
49035+ gr_log_badprocpid("mem");
49036+ return 0;
49037+ }
49038+#endif
49039+
49040 if (!mm)
49041 return 0;
49042
49043@@ -822,6 +901,13 @@ static ssize_t environ_read(struct file *file, char __user *buf,
49044 if (!mm)
49045 return 0;
49046
49047+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
49048+ if (file->f_version != current->exec_id) {
49049+ gr_log_badprocpid("environ");
49050+ return 0;
49051+ }
49052+#endif
49053+
49054 page = (char *)__get_free_page(GFP_TEMPORARY);
49055 if (!page)
49056 return -ENOMEM;
49057@@ -1435,7 +1521,7 @@ static void *proc_pid_follow_link(struct dentry *dentry, struct nameidata *nd)
49058 int error = -EACCES;
49059
49060 /* Are we allowed to snoop on the tasks file descriptors? */
49061- if (!proc_fd_access_allowed(inode))
49062+ if (!proc_fd_access_allowed(inode, 0))
49063 goto out;
49064
49065 error = PROC_I(inode)->op.proc_get_link(dentry, &path);
49066@@ -1479,8 +1565,18 @@ static int proc_pid_readlink(struct dentry * dentry, char __user * buffer, int b
49067 struct path path;
49068
49069 /* Are we allowed to snoop on the tasks file descriptors? */
49070- if (!proc_fd_access_allowed(inode))
49071- goto out;
49072+ /* logging this is needed for learning on chromium to work properly,
49073+ but we don't want to flood the logs from 'ps' which does a readlink
49074+ on /proc/fd/2 of tasks in the listing, nor do we want 'ps' to learn
49075+ CAP_SYS_PTRACE as it's not necessary for its basic functionality
49076+ */
49077+ if (dentry->d_name.name[0] == '2' && dentry->d_name.name[1] == '\0') {
49078+ if (!proc_fd_access_allowed(inode,0))
49079+ goto out;
49080+ } else {
49081+ if (!proc_fd_access_allowed(inode,1))
49082+ goto out;
49083+ }
49084
49085 error = PROC_I(inode)->op.proc_get_link(dentry, &path);
49086 if (error)
49087@@ -1545,7 +1641,11 @@ struct inode *proc_pid_make_inode(struct super_block * sb, struct task_struct *t
49088 rcu_read_lock();
49089 cred = __task_cred(task);
49090 inode->i_uid = cred->euid;
49091+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
49092+ inode->i_gid = grsec_proc_gid;
49093+#else
49094 inode->i_gid = cred->egid;
49095+#endif
49096 rcu_read_unlock();
49097 }
49098 security_task_to_inode(task, inode);
49099@@ -1581,10 +1681,19 @@ int pid_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat)
49100 return -ENOENT;
49101 }
49102 if ((inode->i_mode == (S_IFDIR|S_IRUGO|S_IXUGO)) ||
49103+#ifdef CONFIG_GRKERNSEC_PROC_USER
49104+ (inode->i_mode == (S_IFDIR|S_IRUSR|S_IXUSR)) ||
49105+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
49106+ (inode->i_mode == (S_IFDIR|S_IRUSR|S_IRGRP|S_IXUSR|S_IXGRP)) ||
49107+#endif
49108 task_dumpable(task)) {
49109 cred = __task_cred(task);
49110 stat->uid = cred->euid;
49111+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
49112+ stat->gid = grsec_proc_gid;
49113+#else
49114 stat->gid = cred->egid;
49115+#endif
49116 }
49117 }
49118 rcu_read_unlock();
49119@@ -1622,11 +1731,20 @@ int pid_revalidate(struct dentry *dentry, unsigned int flags)
49120
49121 if (task) {
49122 if ((inode->i_mode == (S_IFDIR|S_IRUGO|S_IXUGO)) ||
49123+#ifdef CONFIG_GRKERNSEC_PROC_USER
49124+ (inode->i_mode == (S_IFDIR|S_IRUSR|S_IXUSR)) ||
49125+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
49126+ (inode->i_mode == (S_IFDIR|S_IRUSR|S_IRGRP|S_IXUSR|S_IXGRP)) ||
49127+#endif
49128 task_dumpable(task)) {
49129 rcu_read_lock();
49130 cred = __task_cred(task);
49131 inode->i_uid = cred->euid;
49132+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
49133+ inode->i_gid = grsec_proc_gid;
49134+#else
49135 inode->i_gid = cred->egid;
49136+#endif
49137 rcu_read_unlock();
49138 } else {
49139 inode->i_uid = GLOBAL_ROOT_UID;
49140@@ -1744,7 +1862,8 @@ static int proc_fd_info(struct inode *inode, struct path *path, char *info)
49141 int fd = proc_fd(inode);
49142
49143 if (task) {
49144- files = get_files_struct(task);
49145+ if (!gr_acl_handle_procpidmem(task))
49146+ files = get_files_struct(task);
49147 put_task_struct(task);
49148 }
49149 if (files) {
49150@@ -2343,11 +2462,21 @@ static const struct file_operations proc_map_files_operations = {
49151 */
49152 static int proc_fd_permission(struct inode *inode, int mask)
49153 {
49154+ struct task_struct *task;
49155 int rv = generic_permission(inode, mask);
49156- if (rv == 0)
49157- return 0;
49158+
49159 if (task_pid(current) == proc_pid(inode))
49160 rv = 0;
49161+
49162+ task = get_proc_task(inode);
49163+ if (task == NULL)
49164+ return rv;
49165+
49166+ if (gr_acl_handle_procpidmem(task))
49167+ rv = -EACCES;
49168+
49169+ put_task_struct(task);
49170+
49171 return rv;
49172 }
49173
49174@@ -2457,6 +2586,9 @@ static struct dentry *proc_pident_lookup(struct inode *dir,
49175 if (!task)
49176 goto out_no_task;
49177
49178+ if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
49179+ goto out;
49180+
49181 /*
49182 * Yes, it does not scale. And it should not. Don't add
49183 * new entries into /proc/<tgid>/ without very good reasons.
49184@@ -2501,6 +2633,9 @@ static int proc_pident_readdir(struct file *filp,
49185 if (!task)
49186 goto out_no_task;
49187
49188+ if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
49189+ goto out;
49190+
49191 ret = 0;
49192 i = filp->f_pos;
49193 switch (i) {
49194@@ -2771,7 +2906,7 @@ static void *proc_self_follow_link(struct dentry *dentry, struct nameidata *nd)
49195 static void proc_self_put_link(struct dentry *dentry, struct nameidata *nd,
49196 void *cookie)
49197 {
49198- char *s = nd_get_link(nd);
49199+ const char *s = nd_get_link(nd);
49200 if (!IS_ERR(s))
49201 __putname(s);
49202 }
49203@@ -3040,7 +3175,7 @@ static const struct pid_entry tgid_base_stuff[] = {
49204 REG("autogroup", S_IRUGO|S_IWUSR, proc_pid_sched_autogroup_operations),
49205 #endif
49206 REG("comm", S_IRUGO|S_IWUSR, proc_pid_set_comm_operations),
49207-#ifdef CONFIG_HAVE_ARCH_TRACEHOOK
49208+#if defined(CONFIG_HAVE_ARCH_TRACEHOOK) && !defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
49209 INF("syscall", S_IRUGO, proc_pid_syscall),
49210 #endif
49211 INF("cmdline", S_IRUGO, proc_pid_cmdline),
49212@@ -3065,10 +3200,10 @@ static const struct pid_entry tgid_base_stuff[] = {
49213 #ifdef CONFIG_SECURITY
49214 DIR("attr", S_IRUGO|S_IXUGO, proc_attr_dir_inode_operations, proc_attr_dir_operations),
49215 #endif
49216-#ifdef CONFIG_KALLSYMS
49217+#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
49218 INF("wchan", S_IRUGO, proc_pid_wchan),
49219 #endif
49220-#ifdef CONFIG_STACKTRACE
49221+#if defined(CONFIG_STACKTRACE) && !defined(CONFIG_GRKERNSEC_HIDESYM)
49222 ONE("stack", S_IRUGO, proc_pid_stack),
49223 #endif
49224 #ifdef CONFIG_SCHEDSTATS
49225@@ -3102,6 +3237,9 @@ static const struct pid_entry tgid_base_stuff[] = {
49226 #ifdef CONFIG_HARDWALL
49227 INF("hardwall", S_IRUGO, proc_pid_hardwall),
49228 #endif
49229+#ifdef CONFIG_GRKERNSEC_PROC_IPADDR
49230+ INF("ipaddr", S_IRUSR, proc_pid_ipaddr),
49231+#endif
49232 #ifdef CONFIG_USER_NS
49233 REG("uid_map", S_IRUGO|S_IWUSR, proc_uid_map_operations),
49234 REG("gid_map", S_IRUGO|S_IWUSR, proc_gid_map_operations),
49235@@ -3233,7 +3371,14 @@ static struct dentry *proc_pid_instantiate(struct inode *dir,
49236 if (!inode)
49237 goto out;
49238
49239+#ifdef CONFIG_GRKERNSEC_PROC_USER
49240+ inode->i_mode = S_IFDIR|S_IRUSR|S_IXUSR;
49241+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
49242+ inode->i_gid = grsec_proc_gid;
49243+ inode->i_mode = S_IFDIR|S_IRUSR|S_IRGRP|S_IXUSR|S_IXGRP;
49244+#else
49245 inode->i_mode = S_IFDIR|S_IRUGO|S_IXUGO;
49246+#endif
49247 inode->i_op = &proc_tgid_base_inode_operations;
49248 inode->i_fop = &proc_tgid_base_operations;
49249 inode->i_flags|=S_IMMUTABLE;
49250@@ -3275,7 +3420,11 @@ struct dentry *proc_pid_lookup(struct inode *dir, struct dentry * dentry, unsign
49251 if (!task)
49252 goto out;
49253
49254+ if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
49255+ goto out_put_task;
49256+
49257 result = proc_pid_instantiate(dir, dentry, task, NULL);
49258+out_put_task:
49259 put_task_struct(task);
49260 out:
49261 return result;
49262@@ -3338,6 +3487,8 @@ static int proc_pid_fill_cache(struct file *filp, void *dirent, filldir_t filldi
49263 static int fake_filldir(void *buf, const char *name, int namelen,
49264 loff_t offset, u64 ino, unsigned d_type)
49265 {
49266+ struct getdents_callback * __buf = (struct getdents_callback *) buf;
49267+ __buf->error = -EINVAL;
49268 return 0;
49269 }
49270
49271@@ -3404,7 +3555,7 @@ static const struct pid_entry tid_base_stuff[] = {
49272 REG("sched", S_IRUGO|S_IWUSR, proc_pid_sched_operations),
49273 #endif
49274 REG("comm", S_IRUGO|S_IWUSR, proc_pid_set_comm_operations),
49275-#ifdef CONFIG_HAVE_ARCH_TRACEHOOK
49276+#if defined(CONFIG_HAVE_ARCH_TRACEHOOK) && !defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
49277 INF("syscall", S_IRUGO, proc_pid_syscall),
49278 #endif
49279 INF("cmdline", S_IRUGO, proc_pid_cmdline),
49280@@ -3431,10 +3582,10 @@ static const struct pid_entry tid_base_stuff[] = {
49281 #ifdef CONFIG_SECURITY
49282 DIR("attr", S_IRUGO|S_IXUGO, proc_attr_dir_inode_operations, proc_attr_dir_operations),
49283 #endif
49284-#ifdef CONFIG_KALLSYMS
49285+#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
49286 INF("wchan", S_IRUGO, proc_pid_wchan),
49287 #endif
49288-#ifdef CONFIG_STACKTRACE
49289+#if defined(CONFIG_STACKTRACE) && !defined(CONFIG_GRKERNSEC_HIDESYM)
49290 ONE("stack", S_IRUGO, proc_pid_stack),
49291 #endif
49292 #ifdef CONFIG_SCHEDSTATS
49293diff --git a/fs/proc/cmdline.c b/fs/proc/cmdline.c
49294index 82676e3..5f8518a 100644
49295--- a/fs/proc/cmdline.c
49296+++ b/fs/proc/cmdline.c
49297@@ -23,7 +23,11 @@ static const struct file_operations cmdline_proc_fops = {
49298
49299 static int __init proc_cmdline_init(void)
49300 {
49301+#ifdef CONFIG_GRKERNSEC_PROC_ADD
49302+ proc_create_grsec("cmdline", 0, NULL, &cmdline_proc_fops);
49303+#else
49304 proc_create("cmdline", 0, NULL, &cmdline_proc_fops);
49305+#endif
49306 return 0;
49307 }
49308 module_init(proc_cmdline_init);
49309diff --git a/fs/proc/devices.c b/fs/proc/devices.c
49310index b143471..bb105e5 100644
49311--- a/fs/proc/devices.c
49312+++ b/fs/proc/devices.c
49313@@ -64,7 +64,11 @@ static const struct file_operations proc_devinfo_operations = {
49314
49315 static int __init proc_devices_init(void)
49316 {
49317+#ifdef CONFIG_GRKERNSEC_PROC_ADD
49318+ proc_create_grsec("devices", 0, NULL, &proc_devinfo_operations);
49319+#else
49320 proc_create("devices", 0, NULL, &proc_devinfo_operations);
49321+#endif
49322 return 0;
49323 }
49324 module_init(proc_devices_init);
49325diff --git a/fs/proc/inode.c b/fs/proc/inode.c
49326index 7ac817b..c5c9eb0 100644
49327--- a/fs/proc/inode.c
49328+++ b/fs/proc/inode.c
49329@@ -21,11 +21,17 @@
49330 #include <linux/seq_file.h>
49331 #include <linux/slab.h>
49332 #include <linux/mount.h>
49333+#include <linux/grsecurity.h>
49334
49335 #include <asm/uaccess.h>
49336
49337 #include "internal.h"
49338
49339+#ifdef CONFIG_PROC_SYSCTL
49340+extern const struct inode_operations proc_sys_inode_operations;
49341+extern const struct inode_operations proc_sys_dir_operations;
49342+#endif
49343+
49344 static void proc_evict_inode(struct inode *inode)
49345 {
49346 struct proc_dir_entry *de;
49347@@ -51,6 +57,13 @@ static void proc_evict_inode(struct inode *inode)
49348 ns_ops = PROC_I(inode)->ns_ops;
49349 if (ns_ops && ns_ops->put)
49350 ns_ops->put(PROC_I(inode)->ns);
49351+
49352+#ifdef CONFIG_PROC_SYSCTL
49353+ if (inode->i_op == &proc_sys_inode_operations ||
49354+ inode->i_op == &proc_sys_dir_operations)
49355+ gr_handle_delete(inode->i_ino, inode->i_sb->s_dev);
49356+#endif
49357+
49358 }
49359
49360 static struct kmem_cache * proc_inode_cachep;
49361@@ -456,7 +469,11 @@ struct inode *proc_get_inode(struct super_block *sb, struct proc_dir_entry *de)
49362 if (de->mode) {
49363 inode->i_mode = de->mode;
49364 inode->i_uid = de->uid;
49365+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
49366+ inode->i_gid = grsec_proc_gid;
49367+#else
49368 inode->i_gid = de->gid;
49369+#endif
49370 }
49371 if (de->size)
49372 inode->i_size = de->size;
49373diff --git a/fs/proc/internal.h b/fs/proc/internal.h
49374index e1167a1..bd24f20 100644
49375--- a/fs/proc/internal.h
49376+++ b/fs/proc/internal.h
49377@@ -52,6 +52,9 @@ extern int proc_pid_status(struct seq_file *m, struct pid_namespace *ns,
49378 struct pid *pid, struct task_struct *task);
49379 extern int proc_pid_statm(struct seq_file *m, struct pid_namespace *ns,
49380 struct pid *pid, struct task_struct *task);
49381+#ifdef CONFIG_GRKERNSEC_PROC_IPADDR
49382+extern int proc_pid_ipaddr(struct task_struct *task, char *buffer);
49383+#endif
49384 extern loff_t mem_lseek(struct file *file, loff_t offset, int orig);
49385
49386 extern const struct file_operations proc_tid_children_operations;
49387diff --git a/fs/proc/kcore.c b/fs/proc/kcore.c
49388index 86c67ee..cdca321 100644
49389--- a/fs/proc/kcore.c
49390+++ b/fs/proc/kcore.c
49391@@ -480,9 +480,10 @@ read_kcore(struct file *file, char __user *buffer, size_t buflen, loff_t *fpos)
49392 * the addresses in the elf_phdr on our list.
49393 */
49394 start = kc_offset_to_vaddr(*fpos - elf_buflen);
49395- if ((tsz = (PAGE_SIZE - (start & ~PAGE_MASK))) > buflen)
49396+ tsz = PAGE_SIZE - (start & ~PAGE_MASK);
49397+ if (tsz > buflen)
49398 tsz = buflen;
49399-
49400+
49401 while (buflen) {
49402 struct kcore_list *m;
49403
49404@@ -511,20 +512,23 @@ read_kcore(struct file *file, char __user *buffer, size_t buflen, loff_t *fpos)
49405 kfree(elf_buf);
49406 } else {
49407 if (kern_addr_valid(start)) {
49408- unsigned long n;
49409+ char *elf_buf;
49410+ mm_segment_t oldfs;
49411
49412- n = copy_to_user(buffer, (char *)start, tsz);
49413- /*
49414- * We cannot distinguish between fault on source
49415- * and fault on destination. When this happens
49416- * we clear too and hope it will trigger the
49417- * EFAULT again.
49418- */
49419- if (n) {
49420- if (clear_user(buffer + tsz - n,
49421- n))
49422+ elf_buf = kmalloc(tsz, GFP_KERNEL);
49423+ if (!elf_buf)
49424+ return -ENOMEM;
49425+ oldfs = get_fs();
49426+ set_fs(KERNEL_DS);
49427+ if (!__copy_from_user(elf_buf, (const void __user *)start, tsz)) {
49428+ set_fs(oldfs);
49429+ if (copy_to_user(buffer, elf_buf, tsz)) {
49430+ kfree(elf_buf);
49431 return -EFAULT;
49432+ }
49433 }
49434+ set_fs(oldfs);
49435+ kfree(elf_buf);
49436 } else {
49437 if (clear_user(buffer, tsz))
49438 return -EFAULT;
49439@@ -544,6 +548,9 @@ read_kcore(struct file *file, char __user *buffer, size_t buflen, loff_t *fpos)
49440
49441 static int open_kcore(struct inode *inode, struct file *filp)
49442 {
49443+#if defined(CONFIG_GRKERNSEC_PROC_ADD) || defined(CONFIG_GRKERNSEC_HIDESYM)
49444+ return -EPERM;
49445+#endif
49446 if (!capable(CAP_SYS_RAWIO))
49447 return -EPERM;
49448 if (kcore_need_update)
49449diff --git a/fs/proc/meminfo.c b/fs/proc/meminfo.c
49450index 80e4645..53e5fcf 100644
49451--- a/fs/proc/meminfo.c
49452+++ b/fs/proc/meminfo.c
49453@@ -158,7 +158,7 @@ static int meminfo_proc_show(struct seq_file *m, void *v)
49454 vmi.used >> 10,
49455 vmi.largest_chunk >> 10
49456 #ifdef CONFIG_MEMORY_FAILURE
49457- ,atomic_long_read(&mce_bad_pages) << (PAGE_SHIFT - 10)
49458+ ,atomic_long_read_unchecked(&mce_bad_pages) << (PAGE_SHIFT - 10)
49459 #endif
49460 #ifdef CONFIG_TRANSPARENT_HUGEPAGE
49461 ,K(global_page_state(NR_ANON_TRANSPARENT_HUGEPAGES) *
49462diff --git a/fs/proc/nommu.c b/fs/proc/nommu.c
49463index b1822dd..df622cb 100644
49464--- a/fs/proc/nommu.c
49465+++ b/fs/proc/nommu.c
49466@@ -66,7 +66,7 @@ static int nommu_region_show(struct seq_file *m, struct vm_region *region)
49467 if (len < 1)
49468 len = 1;
49469 seq_printf(m, "%*c", len, ' ');
49470- seq_path(m, &file->f_path, "");
49471+ seq_path(m, &file->f_path, "\n\\");
49472 }
49473
49474 seq_putc(m, '\n');
49475diff --git a/fs/proc/proc_net.c b/fs/proc/proc_net.c
49476index fe72cd0..cb9b67d 100644
49477--- a/fs/proc/proc_net.c
49478+++ b/fs/proc/proc_net.c
49479@@ -23,6 +23,7 @@
49480 #include <linux/nsproxy.h>
49481 #include <net/net_namespace.h>
49482 #include <linux/seq_file.h>
49483+#include <linux/grsecurity.h>
49484
49485 #include "internal.h"
49486
49487@@ -105,6 +106,17 @@ static struct net *get_proc_task_net(struct inode *dir)
49488 struct task_struct *task;
49489 struct nsproxy *ns;
49490 struct net *net = NULL;
49491+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
49492+ const struct cred *cred = current_cred();
49493+#endif
49494+
49495+#ifdef CONFIG_GRKERNSEC_PROC_USER
49496+ if (cred->fsuid)
49497+ return net;
49498+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
49499+ if (cred->fsuid && !in_group_p(grsec_proc_gid))
49500+ return net;
49501+#endif
49502
49503 rcu_read_lock();
49504 task = pid_task(proc_pid(dir), PIDTYPE_PID);
49505diff --git a/fs/proc/proc_sysctl.c b/fs/proc/proc_sysctl.c
49506index eb7cc91..7327a46 100644
49507--- a/fs/proc/proc_sysctl.c
49508+++ b/fs/proc/proc_sysctl.c
49509@@ -12,11 +12,15 @@
49510 #include <linux/module.h>
49511 #include "internal.h"
49512
49513+extern int gr_handle_chroot_sysctl(const int op);
49514+extern int gr_handle_sysctl_mod(const char *dirname, const char *name,
49515+ const int op);
49516+
49517 static const struct dentry_operations proc_sys_dentry_operations;
49518 static const struct file_operations proc_sys_file_operations;
49519-static const struct inode_operations proc_sys_inode_operations;
49520+const struct inode_operations proc_sys_inode_operations;
49521 static const struct file_operations proc_sys_dir_file_operations;
49522-static const struct inode_operations proc_sys_dir_operations;
49523+const struct inode_operations proc_sys_dir_operations;
49524
49525 void proc_sys_poll_notify(struct ctl_table_poll *poll)
49526 {
49527@@ -467,6 +471,9 @@ static struct dentry *proc_sys_lookup(struct inode *dir, struct dentry *dentry,
49528
49529 err = NULL;
49530 d_set_d_op(dentry, &proc_sys_dentry_operations);
49531+
49532+ gr_handle_proc_create(dentry, inode);
49533+
49534 d_add(dentry, inode);
49535
49536 out:
49537@@ -482,18 +489,20 @@ static ssize_t proc_sys_call_handler(struct file *filp, void __user *buf,
49538 struct inode *inode = filp->f_path.dentry->d_inode;
49539 struct ctl_table_header *head = grab_header(inode);
49540 struct ctl_table *table = PROC_I(inode)->sysctl_entry;
49541+ int op = write ? MAY_WRITE : MAY_READ;
49542 ssize_t error;
49543 size_t res;
49544
49545 if (IS_ERR(head))
49546 return PTR_ERR(head);
49547
49548+
49549 /*
49550 * At this point we know that the sysctl was not unregistered
49551 * and won't be until we finish.
49552 */
49553 error = -EPERM;
49554- if (sysctl_perm(head->root, table, write ? MAY_WRITE : MAY_READ))
49555+ if (sysctl_perm(head->root, table, op))
49556 goto out;
49557
49558 /* if that can happen at all, it should be -EINVAL, not -EISDIR */
49559@@ -501,6 +510,22 @@ static ssize_t proc_sys_call_handler(struct file *filp, void __user *buf,
49560 if (!table->proc_handler)
49561 goto out;
49562
49563+#ifdef CONFIG_GRKERNSEC
49564+ error = -EPERM;
49565+ if (gr_handle_chroot_sysctl(op))
49566+ goto out;
49567+ dget(filp->f_path.dentry);
49568+ if (gr_handle_sysctl_mod(filp->f_path.dentry->d_parent->d_name.name, table->procname, op)) {
49569+ dput(filp->f_path.dentry);
49570+ goto out;
49571+ }
49572+ dput(filp->f_path.dentry);
49573+ if (!gr_acl_handle_open(filp->f_path.dentry, filp->f_path.mnt, op))
49574+ goto out;
49575+ if (write && !capable(CAP_SYS_ADMIN))
49576+ goto out;
49577+#endif
49578+
49579 /* careful: calling conventions are nasty here */
49580 res = count;
49581 error = table->proc_handler(table, write, buf, &res, ppos);
49582@@ -598,6 +623,9 @@ static int proc_sys_fill_cache(struct file *filp, void *dirent,
49583 return -ENOMEM;
49584 } else {
49585 d_set_d_op(child, &proc_sys_dentry_operations);
49586+
49587+ gr_handle_proc_create(child, inode);
49588+
49589 d_add(child, inode);
49590 }
49591 } else {
49592@@ -641,6 +669,9 @@ static int scan(struct ctl_table_header *head, ctl_table *table,
49593 if ((*pos)++ < file->f_pos)
49594 return 0;
49595
49596+ if (!gr_acl_handle_hidden_file(file->f_path.dentry, file->f_path.mnt))
49597+ return 0;
49598+
49599 if (unlikely(S_ISLNK(table->mode)))
49600 res = proc_sys_link_fill_cache(file, dirent, filldir, head, table);
49601 else
49602@@ -758,6 +789,9 @@ static int proc_sys_getattr(struct vfsmount *mnt, struct dentry *dentry, struct
49603 if (IS_ERR(head))
49604 return PTR_ERR(head);
49605
49606+ if (table && !gr_acl_handle_hidden_file(dentry, mnt))
49607+ return -ENOENT;
49608+
49609 generic_fillattr(inode, stat);
49610 if (table)
49611 stat->mode = (stat->mode & S_IFMT) | table->mode;
49612@@ -780,13 +814,13 @@ static const struct file_operations proc_sys_dir_file_operations = {
49613 .llseek = generic_file_llseek,
49614 };
49615
49616-static const struct inode_operations proc_sys_inode_operations = {
49617+const struct inode_operations proc_sys_inode_operations = {
49618 .permission = proc_sys_permission,
49619 .setattr = proc_sys_setattr,
49620 .getattr = proc_sys_getattr,
49621 };
49622
49623-static const struct inode_operations proc_sys_dir_operations = {
49624+const struct inode_operations proc_sys_dir_operations = {
49625 .lookup = proc_sys_lookup,
49626 .permission = proc_sys_permission,
49627 .setattr = proc_sys_setattr,
49628diff --git a/fs/proc/root.c b/fs/proc/root.c
49629index 9a2d9fd..ddfc92a 100644
49630--- a/fs/proc/root.c
49631+++ b/fs/proc/root.c
49632@@ -187,7 +187,15 @@ void __init proc_root_init(void)
49633 #ifdef CONFIG_PROC_DEVICETREE
49634 proc_device_tree_init();
49635 #endif
49636+#ifdef CONFIG_GRKERNSEC_PROC_ADD
49637+#ifdef CONFIG_GRKERNSEC_PROC_USER
49638+ proc_mkdir_mode("bus", S_IRUSR | S_IXUSR, NULL);
49639+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
49640+ proc_mkdir_mode("bus", S_IRUSR | S_IXUSR | S_IRGRP | S_IXGRP, NULL);
49641+#endif
49642+#else
49643 proc_mkdir("bus", NULL);
49644+#endif
49645 proc_sys_init();
49646 }
49647
49648diff --git a/fs/proc/task_mmu.c b/fs/proc/task_mmu.c
49649index 4540b8f..1b9772f 100644
49650--- a/fs/proc/task_mmu.c
49651+++ b/fs/proc/task_mmu.c
49652@@ -11,12 +11,19 @@
49653 #include <linux/rmap.h>
49654 #include <linux/swap.h>
49655 #include <linux/swapops.h>
49656+#include <linux/grsecurity.h>
49657
49658 #include <asm/elf.h>
49659 #include <asm/uaccess.h>
49660 #include <asm/tlbflush.h>
49661 #include "internal.h"
49662
49663+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
49664+#define PAX_RAND_FLAGS(_mm) (_mm != NULL && _mm != current->mm && \
49665+ (_mm->pax_flags & MF_PAX_RANDMMAP || \
49666+ _mm->pax_flags & MF_PAX_SEGMEXEC))
49667+#endif
49668+
49669 void task_mem(struct seq_file *m, struct mm_struct *mm)
49670 {
49671 unsigned long data, text, lib, swap;
49672@@ -52,8 +59,13 @@ void task_mem(struct seq_file *m, struct mm_struct *mm)
49673 "VmExe:\t%8lu kB\n"
49674 "VmLib:\t%8lu kB\n"
49675 "VmPTE:\t%8lu kB\n"
49676- "VmSwap:\t%8lu kB\n",
49677- hiwater_vm << (PAGE_SHIFT-10),
49678+ "VmSwap:\t%8lu kB\n"
49679+
49680+#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
49681+ "CsBase:\t%8lx\nCsLim:\t%8lx\n"
49682+#endif
49683+
49684+ ,hiwater_vm << (PAGE_SHIFT-10),
49685 (total_vm - mm->reserved_vm) << (PAGE_SHIFT-10),
49686 mm->locked_vm << (PAGE_SHIFT-10),
49687 mm->pinned_vm << (PAGE_SHIFT-10),
49688@@ -62,7 +74,19 @@ void task_mem(struct seq_file *m, struct mm_struct *mm)
49689 data << (PAGE_SHIFT-10),
49690 mm->stack_vm << (PAGE_SHIFT-10), text, lib,
49691 (PTRS_PER_PTE*sizeof(pte_t)*mm->nr_ptes) >> 10,
49692- swap << (PAGE_SHIFT-10));
49693+ swap << (PAGE_SHIFT-10)
49694+
49695+#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
49696+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
49697+ , PAX_RAND_FLAGS(mm) ? 0 : mm->context.user_cs_base
49698+ , PAX_RAND_FLAGS(mm) ? 0 : mm->context.user_cs_limit
49699+#else
49700+ , mm->context.user_cs_base
49701+ , mm->context.user_cs_limit
49702+#endif
49703+#endif
49704+
49705+ );
49706 }
49707
49708 unsigned long task_vsize(struct mm_struct *mm)
49709@@ -231,13 +255,13 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
49710 pgoff = ((loff_t)vma->vm_pgoff) << PAGE_SHIFT;
49711 }
49712
49713- /* We don't show the stack guard page in /proc/maps */
49714+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
49715+ start = PAX_RAND_FLAGS(mm) ? 0UL : vma->vm_start;
49716+ end = PAX_RAND_FLAGS(mm) ? 0UL : vma->vm_end;
49717+#else
49718 start = vma->vm_start;
49719- if (stack_guard_page_start(vma, start))
49720- start += PAGE_SIZE;
49721 end = vma->vm_end;
49722- if (stack_guard_page_end(vma, end))
49723- end -= PAGE_SIZE;
49724+#endif
49725
49726 seq_printf(m, "%08lx-%08lx %c%c%c%c %08llx %02x:%02x %lu %n",
49727 start,
49728@@ -246,7 +270,11 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
49729 flags & VM_WRITE ? 'w' : '-',
49730 flags & VM_EXEC ? 'x' : '-',
49731 flags & VM_MAYSHARE ? 's' : 'p',
49732+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
49733+ PAX_RAND_FLAGS(mm) ? 0UL : pgoff,
49734+#else
49735 pgoff,
49736+#endif
49737 MAJOR(dev), MINOR(dev), ino, &len);
49738
49739 /*
49740@@ -255,7 +283,7 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
49741 */
49742 if (file) {
49743 pad_len_spaces(m, len);
49744- seq_path(m, &file->f_path, "\n");
49745+ seq_path(m, &file->f_path, "\n\\");
49746 goto done;
49747 }
49748
49749@@ -281,8 +309,9 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
49750 * Thread stack in /proc/PID/task/TID/maps or
49751 * the main process stack.
49752 */
49753- if (!is_pid || (vma->vm_start <= mm->start_stack &&
49754- vma->vm_end >= mm->start_stack)) {
49755+ if (!is_pid || (vma->vm_flags & (VM_GROWSDOWN | VM_GROWSUP)) ||
49756+ (vma->vm_start <= mm->start_stack &&
49757+ vma->vm_end >= mm->start_stack)) {
49758 name = "[stack]";
49759 } else {
49760 /* Thread stack in /proc/PID/maps */
49761@@ -306,6 +335,13 @@ static int show_map(struct seq_file *m, void *v, int is_pid)
49762 struct proc_maps_private *priv = m->private;
49763 struct task_struct *task = priv->task;
49764
49765+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
49766+ if (current->exec_id != m->exec_id) {
49767+ gr_log_badprocpid("maps");
49768+ return 0;
49769+ }
49770+#endif
49771+
49772 show_map_vma(m, vma, is_pid);
49773
49774 if (m->count < m->size) /* vma is copied successfully */
49775@@ -492,12 +528,23 @@ static int show_smap(struct seq_file *m, void *v, int is_pid)
49776 .private = &mss,
49777 };
49778
49779+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
49780+ if (current->exec_id != m->exec_id) {
49781+ gr_log_badprocpid("smaps");
49782+ return 0;
49783+ }
49784+#endif
49785 memset(&mss, 0, sizeof mss);
49786- mss.vma = vma;
49787- /* mmap_sem is held in m_start */
49788- if (vma->vm_mm && !is_vm_hugetlb_page(vma))
49789- walk_page_range(vma->vm_start, vma->vm_end, &smaps_walk);
49790-
49791+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
49792+ if (!PAX_RAND_FLAGS(vma->vm_mm)) {
49793+#endif
49794+ mss.vma = vma;
49795+ /* mmap_sem is held in m_start */
49796+ if (vma->vm_mm && !is_vm_hugetlb_page(vma))
49797+ walk_page_range(vma->vm_start, vma->vm_end, &smaps_walk);
49798+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
49799+ }
49800+#endif
49801 show_map_vma(m, vma, is_pid);
49802
49803 seq_printf(m,
49804@@ -515,7 +562,11 @@ static int show_smap(struct seq_file *m, void *v, int is_pid)
49805 "KernelPageSize: %8lu kB\n"
49806 "MMUPageSize: %8lu kB\n"
49807 "Locked: %8lu kB\n",
49808+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
49809+ PAX_RAND_FLAGS(vma->vm_mm) ? 0UL : (vma->vm_end - vma->vm_start) >> 10,
49810+#else
49811 (vma->vm_end - vma->vm_start) >> 10,
49812+#endif
49813 mss.resident >> 10,
49814 (unsigned long)(mss.pss >> (10 + PSS_SHIFT)),
49815 mss.shared_clean >> 10,
49816@@ -1164,6 +1215,13 @@ static int show_numa_map(struct seq_file *m, void *v, int is_pid)
49817 int n;
49818 char buffer[50];
49819
49820+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
49821+ if (current->exec_id != m->exec_id) {
49822+ gr_log_badprocpid("numa_maps");
49823+ return 0;
49824+ }
49825+#endif
49826+
49827 if (!mm)
49828 return 0;
49829
49830@@ -1181,11 +1239,15 @@ static int show_numa_map(struct seq_file *m, void *v, int is_pid)
49831 mpol_to_str(buffer, sizeof(buffer), pol, 0);
49832 mpol_cond_put(pol);
49833
49834+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
49835+ seq_printf(m, "%08lx %s", PAX_RAND_FLAGS(vma->vm_mm) ? 0UL : vma->vm_start, buffer);
49836+#else
49837 seq_printf(m, "%08lx %s", vma->vm_start, buffer);
49838+#endif
49839
49840 if (file) {
49841 seq_printf(m, " file=");
49842- seq_path(m, &file->f_path, "\n\t= ");
49843+ seq_path(m, &file->f_path, "\n\t\\= ");
49844 } else if (vma->vm_start <= mm->brk && vma->vm_end >= mm->start_brk) {
49845 seq_printf(m, " heap");
49846 } else {
49847diff --git a/fs/proc/task_nommu.c b/fs/proc/task_nommu.c
49848index 1ccfa53..0848f95 100644
49849--- a/fs/proc/task_nommu.c
49850+++ b/fs/proc/task_nommu.c
49851@@ -51,7 +51,7 @@ void task_mem(struct seq_file *m, struct mm_struct *mm)
49852 else
49853 bytes += kobjsize(mm);
49854
49855- if (current->fs && current->fs->users > 1)
49856+ if (current->fs && atomic_read(&current->fs->users) > 1)
49857 sbytes += kobjsize(current->fs);
49858 else
49859 bytes += kobjsize(current->fs);
49860@@ -168,7 +168,7 @@ static int nommu_vma_show(struct seq_file *m, struct vm_area_struct *vma,
49861
49862 if (file) {
49863 pad_len_spaces(m, len);
49864- seq_path(m, &file->f_path, "");
49865+ seq_path(m, &file->f_path, "\n\\");
49866 } else if (mm) {
49867 pid_t tid = vm_is_stack(priv->task, vma, is_pid);
49868
49869diff --git a/fs/quota/netlink.c b/fs/quota/netlink.c
49870index d67908b..d13f6a6 100644
49871--- a/fs/quota/netlink.c
49872+++ b/fs/quota/netlink.c
49873@@ -33,7 +33,7 @@ static struct genl_family quota_genl_family = {
49874 void quota_send_warning(short type, unsigned int id, dev_t dev,
49875 const char warntype)
49876 {
49877- static atomic_t seq;
49878+ static atomic_unchecked_t seq;
49879 struct sk_buff *skb;
49880 void *msg_head;
49881 int ret;
49882@@ -49,7 +49,7 @@ void quota_send_warning(short type, unsigned int id, dev_t dev,
49883 "VFS: Not enough memory to send quota warning.\n");
49884 return;
49885 }
49886- msg_head = genlmsg_put(skb, 0, atomic_add_return(1, &seq),
49887+ msg_head = genlmsg_put(skb, 0, atomic_add_return_unchecked(1, &seq),
49888 &quota_genl_family, 0, QUOTA_NL_C_WARNING);
49889 if (!msg_head) {
49890 printk(KERN_ERR
49891diff --git a/fs/readdir.c b/fs/readdir.c
49892index 39e3370..20d446d 100644
49893--- a/fs/readdir.c
49894+++ b/fs/readdir.c
49895@@ -17,6 +17,7 @@
49896 #include <linux/security.h>
49897 #include <linux/syscalls.h>
49898 #include <linux/unistd.h>
49899+#include <linux/namei.h>
49900
49901 #include <asm/uaccess.h>
49902
49903@@ -67,6 +68,7 @@ struct old_linux_dirent {
49904
49905 struct readdir_callback {
49906 struct old_linux_dirent __user * dirent;
49907+ struct file * file;
49908 int result;
49909 };
49910
49911@@ -84,6 +86,10 @@ static int fillonedir(void * __buf, const char * name, int namlen, loff_t offset
49912 buf->result = -EOVERFLOW;
49913 return -EOVERFLOW;
49914 }
49915+
49916+ if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
49917+ return 0;
49918+
49919 buf->result++;
49920 dirent = buf->dirent;
49921 if (!access_ok(VERIFY_WRITE, dirent,
49922@@ -116,6 +122,7 @@ SYSCALL_DEFINE3(old_readdir, unsigned int, fd,
49923
49924 buf.result = 0;
49925 buf.dirent = dirent;
49926+ buf.file = file;
49927
49928 error = vfs_readdir(file, fillonedir, &buf);
49929 if (buf.result)
49930@@ -141,6 +148,7 @@ struct linux_dirent {
49931 struct getdents_callback {
49932 struct linux_dirent __user * current_dir;
49933 struct linux_dirent __user * previous;
49934+ struct file * file;
49935 int count;
49936 int error;
49937 };
49938@@ -162,6 +170,10 @@ static int filldir(void * __buf, const char * name, int namlen, loff_t offset,
49939 buf->error = -EOVERFLOW;
49940 return -EOVERFLOW;
49941 }
49942+
49943+ if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
49944+ return 0;
49945+
49946 dirent = buf->previous;
49947 if (dirent) {
49948 if (__put_user(offset, &dirent->d_off))
49949@@ -208,6 +220,7 @@ SYSCALL_DEFINE3(getdents, unsigned int, fd,
49950 buf.previous = NULL;
49951 buf.count = count;
49952 buf.error = 0;
49953+ buf.file = file;
49954
49955 error = vfs_readdir(file, filldir, &buf);
49956 if (error >= 0)
49957@@ -226,6 +239,7 @@ SYSCALL_DEFINE3(getdents, unsigned int, fd,
49958 struct getdents_callback64 {
49959 struct linux_dirent64 __user * current_dir;
49960 struct linux_dirent64 __user * previous;
49961+ struct file *file;
49962 int count;
49963 int error;
49964 };
49965@@ -241,6 +255,10 @@ static int filldir64(void * __buf, const char * name, int namlen, loff_t offset,
49966 buf->error = -EINVAL; /* only used if we fail.. */
49967 if (reclen > buf->count)
49968 return -EINVAL;
49969+
49970+ if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
49971+ return 0;
49972+
49973 dirent = buf->previous;
49974 if (dirent) {
49975 if (__put_user(offset, &dirent->d_off))
49976@@ -287,6 +305,7 @@ SYSCALL_DEFINE3(getdents64, unsigned int, fd,
49977
49978 buf.current_dir = dirent;
49979 buf.previous = NULL;
49980+ buf.file = file;
49981 buf.count = count;
49982 buf.error = 0;
49983
49984@@ -295,7 +314,7 @@ SYSCALL_DEFINE3(getdents64, unsigned int, fd,
49985 error = buf.error;
49986 lastdirent = buf.previous;
49987 if (lastdirent) {
49988- typeof(lastdirent->d_off) d_off = file->f_pos;
49989+ typeof(((struct linux_dirent64 *)0)->d_off) d_off = file->f_pos;
49990 if (__put_user(d_off, &lastdirent->d_off))
49991 error = -EFAULT;
49992 else
49993diff --git a/fs/reiserfs/do_balan.c b/fs/reiserfs/do_balan.c
49994index 2b7882b..1c5ef48 100644
49995--- a/fs/reiserfs/do_balan.c
49996+++ b/fs/reiserfs/do_balan.c
49997@@ -2051,7 +2051,7 @@ void do_balance(struct tree_balance *tb, /* tree_balance structure */
49998 return;
49999 }
50000
50001- atomic_inc(&(fs_generation(tb->tb_sb)));
50002+ atomic_inc_unchecked(&(fs_generation(tb->tb_sb)));
50003 do_balance_starts(tb);
50004
50005 /* balance leaf returns 0 except if combining L R and S into
50006diff --git a/fs/reiserfs/procfs.c b/fs/reiserfs/procfs.c
50007index e60e870..f40ac16 100644
50008--- a/fs/reiserfs/procfs.c
50009+++ b/fs/reiserfs/procfs.c
50010@@ -112,7 +112,7 @@ static int show_super(struct seq_file *m, struct super_block *sb)
50011 "SMALL_TAILS " : "NO_TAILS ",
50012 replay_only(sb) ? "REPLAY_ONLY " : "",
50013 convert_reiserfs(sb) ? "CONV " : "",
50014- atomic_read(&r->s_generation_counter),
50015+ atomic_read_unchecked(&r->s_generation_counter),
50016 SF(s_disk_reads), SF(s_disk_writes), SF(s_fix_nodes),
50017 SF(s_do_balance), SF(s_unneeded_left_neighbor),
50018 SF(s_good_search_by_key_reada), SF(s_bmaps),
50019diff --git a/fs/reiserfs/reiserfs.h b/fs/reiserfs/reiserfs.h
50020index 33215f5..c5d427a 100644
50021--- a/fs/reiserfs/reiserfs.h
50022+++ b/fs/reiserfs/reiserfs.h
50023@@ -453,7 +453,7 @@ struct reiserfs_sb_info {
50024 /* Comment? -Hans */
50025 wait_queue_head_t s_wait;
50026 /* To be obsoleted soon by per buffer seals.. -Hans */
50027- atomic_t s_generation_counter; // increased by one every time the
50028+ atomic_unchecked_t s_generation_counter; // increased by one every time the
50029 // tree gets re-balanced
50030 unsigned long s_properties; /* File system properties. Currently holds
50031 on-disk FS format */
50032@@ -1978,7 +1978,7 @@ static inline loff_t max_reiserfs_offset(struct inode *inode)
50033 #define REISERFS_USER_MEM 1 /* reiserfs user memory mode */
50034
50035 #define fs_generation(s) (REISERFS_SB(s)->s_generation_counter)
50036-#define get_generation(s) atomic_read (&fs_generation(s))
50037+#define get_generation(s) atomic_read_unchecked (&fs_generation(s))
50038 #define FILESYSTEM_CHANGED_TB(tb) (get_generation((tb)->tb_sb) != (tb)->fs_gen)
50039 #define __fs_changed(gen,s) (gen != get_generation (s))
50040 #define fs_changed(gen,s) \
50041diff --git a/fs/select.c b/fs/select.c
50042index db14c78..3aae1bd 100644
50043--- a/fs/select.c
50044+++ b/fs/select.c
50045@@ -20,6 +20,7 @@
50046 #include <linux/export.h>
50047 #include <linux/slab.h>
50048 #include <linux/poll.h>
50049+#include <linux/security.h>
50050 #include <linux/personality.h> /* for STICKY_TIMEOUTS */
50051 #include <linux/file.h>
50052 #include <linux/fdtable.h>
50053@@ -831,6 +832,7 @@ int do_sys_poll(struct pollfd __user *ufds, unsigned int nfds,
50054 struct poll_list *walk = head;
50055 unsigned long todo = nfds;
50056
50057+ gr_learn_resource(current, RLIMIT_NOFILE, nfds, 1);
50058 if (nfds > rlimit(RLIMIT_NOFILE))
50059 return -EINVAL;
50060
50061diff --git a/fs/seq_file.c b/fs/seq_file.c
50062index 14cf9de..adc4d5b 100644
50063--- a/fs/seq_file.c
50064+++ b/fs/seq_file.c
50065@@ -9,6 +9,7 @@
50066 #include <linux/export.h>
50067 #include <linux/seq_file.h>
50068 #include <linux/slab.h>
50069+#include <linux/sched.h>
50070
50071 #include <asm/uaccess.h>
50072 #include <asm/page.h>
50073@@ -56,6 +57,9 @@ int seq_open(struct file *file, const struct seq_operations *op)
50074 memset(p, 0, sizeof(*p));
50075 mutex_init(&p->lock);
50076 p->op = op;
50077+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
50078+ p->exec_id = current->exec_id;
50079+#endif
50080
50081 /*
50082 * Wrappers around seq_open(e.g. swaps_open) need to be
50083@@ -92,7 +96,7 @@ static int traverse(struct seq_file *m, loff_t offset)
50084 return 0;
50085 }
50086 if (!m->buf) {
50087- m->buf = kmalloc(m->size = PAGE_SIZE, GFP_KERNEL);
50088+ m->buf = kmalloc(m->size = PAGE_SIZE, GFP_KERNEL | GFP_USERCOPY);
50089 if (!m->buf)
50090 return -ENOMEM;
50091 }
50092@@ -132,7 +136,7 @@ static int traverse(struct seq_file *m, loff_t offset)
50093 Eoverflow:
50094 m->op->stop(m, p);
50095 kfree(m->buf);
50096- m->buf = kmalloc(m->size <<= 1, GFP_KERNEL);
50097+ m->buf = kmalloc(m->size <<= 1, GFP_KERNEL | GFP_USERCOPY);
50098 return !m->buf ? -ENOMEM : -EAGAIN;
50099 }
50100
50101@@ -187,7 +191,7 @@ ssize_t seq_read(struct file *file, char __user *buf, size_t size, loff_t *ppos)
50102
50103 /* grab buffer if we didn't have one */
50104 if (!m->buf) {
50105- m->buf = kmalloc(m->size = PAGE_SIZE, GFP_KERNEL);
50106+ m->buf = kmalloc(m->size = PAGE_SIZE, GFP_KERNEL | GFP_USERCOPY);
50107 if (!m->buf)
50108 goto Enomem;
50109 }
50110@@ -228,7 +232,7 @@ ssize_t seq_read(struct file *file, char __user *buf, size_t size, loff_t *ppos)
50111 goto Fill;
50112 m->op->stop(m, p);
50113 kfree(m->buf);
50114- m->buf = kmalloc(m->size <<= 1, GFP_KERNEL);
50115+ m->buf = kmalloc(m->size <<= 1, GFP_KERNEL | GFP_USERCOPY);
50116 if (!m->buf)
50117 goto Enomem;
50118 m->count = 0;
50119@@ -577,7 +581,7 @@ static void single_stop(struct seq_file *p, void *v)
50120 int single_open(struct file *file, int (*show)(struct seq_file *, void *),
50121 void *data)
50122 {
50123- struct seq_operations *op = kmalloc(sizeof(*op), GFP_KERNEL);
50124+ seq_operations_no_const *op = kmalloc(sizeof(*op), GFP_KERNEL);
50125 int res = -ENOMEM;
50126
50127 if (op) {
50128diff --git a/fs/splice.c b/fs/splice.c
50129index 41514dd..6564a93 100644
50130--- a/fs/splice.c
50131+++ b/fs/splice.c
50132@@ -194,7 +194,7 @@ ssize_t splice_to_pipe(struct pipe_inode_info *pipe,
50133 pipe_lock(pipe);
50134
50135 for (;;) {
50136- if (!pipe->readers) {
50137+ if (!atomic_read(&pipe->readers)) {
50138 send_sig(SIGPIPE, current, 0);
50139 if (!ret)
50140 ret = -EPIPE;
50141@@ -248,9 +248,9 @@ ssize_t splice_to_pipe(struct pipe_inode_info *pipe,
50142 do_wakeup = 0;
50143 }
50144
50145- pipe->waiting_writers++;
50146+ atomic_inc(&pipe->waiting_writers);
50147 pipe_wait(pipe);
50148- pipe->waiting_writers--;
50149+ atomic_dec(&pipe->waiting_writers);
50150 }
50151
50152 pipe_unlock(pipe);
50153@@ -563,7 +563,7 @@ static ssize_t kernel_readv(struct file *file, const struct iovec *vec,
50154 old_fs = get_fs();
50155 set_fs(get_ds());
50156 /* The cast to a user pointer is valid due to the set_fs() */
50157- res = vfs_readv(file, (const struct iovec __user *)vec, vlen, &pos);
50158+ res = vfs_readv(file, (const struct iovec __force_user *)vec, vlen, &pos);
50159 set_fs(old_fs);
50160
50161 return res;
50162@@ -578,7 +578,7 @@ static ssize_t kernel_write(struct file *file, const char *buf, size_t count,
50163 old_fs = get_fs();
50164 set_fs(get_ds());
50165 /* The cast to a user pointer is valid due to the set_fs() */
50166- res = vfs_write(file, (const char __user *)buf, count, &pos);
50167+ res = vfs_write(file, (const char __force_user *)buf, count, &pos);
50168 set_fs(old_fs);
50169
50170 return res;
50171@@ -630,7 +630,7 @@ ssize_t default_file_splice_read(struct file *in, loff_t *ppos,
50172 goto err;
50173
50174 this_len = min_t(size_t, len, PAGE_CACHE_SIZE - offset);
50175- vec[i].iov_base = (void __user *) page_address(page);
50176+ vec[i].iov_base = (void __force_user *) page_address(page);
50177 vec[i].iov_len = this_len;
50178 spd.pages[i] = page;
50179 spd.nr_pages++;
50180@@ -849,10 +849,10 @@ EXPORT_SYMBOL(splice_from_pipe_feed);
50181 int splice_from_pipe_next(struct pipe_inode_info *pipe, struct splice_desc *sd)
50182 {
50183 while (!pipe->nrbufs) {
50184- if (!pipe->writers)
50185+ if (!atomic_read(&pipe->writers))
50186 return 0;
50187
50188- if (!pipe->waiting_writers && sd->num_spliced)
50189+ if (!atomic_read(&pipe->waiting_writers) && sd->num_spliced)
50190 return 0;
50191
50192 if (sd->flags & SPLICE_F_NONBLOCK)
50193@@ -1190,7 +1190,7 @@ ssize_t splice_direct_to_actor(struct file *in, struct splice_desc *sd,
50194 * out of the pipe right after the splice_to_pipe(). So set
50195 * PIPE_READERS appropriately.
50196 */
50197- pipe->readers = 1;
50198+ atomic_set(&pipe->readers, 1);
50199
50200 current->splice_pipe = pipe;
50201 }
50202@@ -1743,9 +1743,9 @@ static int ipipe_prep(struct pipe_inode_info *pipe, unsigned int flags)
50203 ret = -ERESTARTSYS;
50204 break;
50205 }
50206- if (!pipe->writers)
50207+ if (!atomic_read(&pipe->writers))
50208 break;
50209- if (!pipe->waiting_writers) {
50210+ if (!atomic_read(&pipe->waiting_writers)) {
50211 if (flags & SPLICE_F_NONBLOCK) {
50212 ret = -EAGAIN;
50213 break;
50214@@ -1777,7 +1777,7 @@ static int opipe_prep(struct pipe_inode_info *pipe, unsigned int flags)
50215 pipe_lock(pipe);
50216
50217 while (pipe->nrbufs >= pipe->buffers) {
50218- if (!pipe->readers) {
50219+ if (!atomic_read(&pipe->readers)) {
50220 send_sig(SIGPIPE, current, 0);
50221 ret = -EPIPE;
50222 break;
50223@@ -1790,9 +1790,9 @@ static int opipe_prep(struct pipe_inode_info *pipe, unsigned int flags)
50224 ret = -ERESTARTSYS;
50225 break;
50226 }
50227- pipe->waiting_writers++;
50228+ atomic_inc(&pipe->waiting_writers);
50229 pipe_wait(pipe);
50230- pipe->waiting_writers--;
50231+ atomic_dec(&pipe->waiting_writers);
50232 }
50233
50234 pipe_unlock(pipe);
50235@@ -1828,14 +1828,14 @@ retry:
50236 pipe_double_lock(ipipe, opipe);
50237
50238 do {
50239- if (!opipe->readers) {
50240+ if (!atomic_read(&opipe->readers)) {
50241 send_sig(SIGPIPE, current, 0);
50242 if (!ret)
50243 ret = -EPIPE;
50244 break;
50245 }
50246
50247- if (!ipipe->nrbufs && !ipipe->writers)
50248+ if (!ipipe->nrbufs && !atomic_read(&ipipe->writers))
50249 break;
50250
50251 /*
50252@@ -1932,7 +1932,7 @@ static int link_pipe(struct pipe_inode_info *ipipe,
50253 pipe_double_lock(ipipe, opipe);
50254
50255 do {
50256- if (!opipe->readers) {
50257+ if (!atomic_read(&opipe->readers)) {
50258 send_sig(SIGPIPE, current, 0);
50259 if (!ret)
50260 ret = -EPIPE;
50261@@ -1977,7 +1977,7 @@ static int link_pipe(struct pipe_inode_info *ipipe,
50262 * return EAGAIN if we have the potential of some data in the
50263 * future, otherwise just return 0
50264 */
50265- if (!ret && ipipe->waiting_writers && (flags & SPLICE_F_NONBLOCK))
50266+ if (!ret && atomic_read(&ipipe->waiting_writers) && (flags & SPLICE_F_NONBLOCK))
50267 ret = -EAGAIN;
50268
50269 pipe_unlock(ipipe);
50270diff --git a/fs/sysfs/dir.c b/fs/sysfs/dir.c
50271index 6b0bb00..75db2fe 100644
50272--- a/fs/sysfs/dir.c
50273+++ b/fs/sysfs/dir.c
50274@@ -685,6 +685,18 @@ static int create_dir(struct kobject *kobj, struct sysfs_dirent *parent_sd,
50275 struct sysfs_dirent *sd;
50276 int rc;
50277
50278+#ifdef CONFIG_GRKERNSEC_SYSFS_RESTRICT
50279+ const char *parent_name = parent_sd->s_name;
50280+
50281+ mode = S_IFDIR | S_IRWXU;
50282+
50283+ if ((!strcmp(parent_name, "") && (!strcmp(name, "devices") || !strcmp(name, "fs"))) ||
50284+ (!strcmp(parent_name, "devices") && !strcmp(name, "system")) ||
50285+ (!strcmp(parent_name, "fs") && (!strcmp(name, "selinux") || !strcmp(name, "fuse"))) ||
50286+ (!strcmp(parent_name, "system") && !strcmp(name, "cpu")))
50287+ mode = S_IFDIR | S_IRWXU | S_IRUGO | S_IXUGO;
50288+#endif
50289+
50290 /* allocate */
50291 sd = sysfs_new_dirent(name, mode, SYSFS_DIR);
50292 if (!sd)
50293diff --git a/fs/sysfs/file.c b/fs/sysfs/file.c
50294index 00012e3..8392349 100644
50295--- a/fs/sysfs/file.c
50296+++ b/fs/sysfs/file.c
50297@@ -37,7 +37,7 @@ static DEFINE_SPINLOCK(sysfs_open_dirent_lock);
50298
50299 struct sysfs_open_dirent {
50300 atomic_t refcnt;
50301- atomic_t event;
50302+ atomic_unchecked_t event;
50303 wait_queue_head_t poll;
50304 struct list_head buffers; /* goes through sysfs_buffer.list */
50305 };
50306@@ -81,7 +81,7 @@ static int fill_read_buffer(struct dentry * dentry, struct sysfs_buffer * buffer
50307 if (!sysfs_get_active(attr_sd))
50308 return -ENODEV;
50309
50310- buffer->event = atomic_read(&attr_sd->s_attr.open->event);
50311+ buffer->event = atomic_read_unchecked(&attr_sd->s_attr.open->event);
50312 count = ops->show(kobj, attr_sd->s_attr.attr, buffer->page);
50313
50314 sysfs_put_active(attr_sd);
50315@@ -287,7 +287,7 @@ static int sysfs_get_open_dirent(struct sysfs_dirent *sd,
50316 return -ENOMEM;
50317
50318 atomic_set(&new_od->refcnt, 0);
50319- atomic_set(&new_od->event, 1);
50320+ atomic_set_unchecked(&new_od->event, 1);
50321 init_waitqueue_head(&new_od->poll);
50322 INIT_LIST_HEAD(&new_od->buffers);
50323 goto retry;
50324@@ -432,7 +432,7 @@ static unsigned int sysfs_poll(struct file *filp, poll_table *wait)
50325
50326 sysfs_put_active(attr_sd);
50327
50328- if (buffer->event != atomic_read(&od->event))
50329+ if (buffer->event != atomic_read_unchecked(&od->event))
50330 goto trigger;
50331
50332 return DEFAULT_POLLMASK;
50333@@ -451,7 +451,7 @@ void sysfs_notify_dirent(struct sysfs_dirent *sd)
50334
50335 od = sd->s_attr.open;
50336 if (od) {
50337- atomic_inc(&od->event);
50338+ atomic_inc_unchecked(&od->event);
50339 wake_up_interruptible(&od->poll);
50340 }
50341
50342diff --git a/fs/sysfs/symlink.c b/fs/sysfs/symlink.c
50343index a7ac78f..02158e1 100644
50344--- a/fs/sysfs/symlink.c
50345+++ b/fs/sysfs/symlink.c
50346@@ -286,7 +286,7 @@ static void *sysfs_follow_link(struct dentry *dentry, struct nameidata *nd)
50347
50348 static void sysfs_put_link(struct dentry *dentry, struct nameidata *nd, void *cookie)
50349 {
50350- char *page = nd_get_link(nd);
50351+ const char *page = nd_get_link(nd);
50352 if (!IS_ERR(page))
50353 free_page((unsigned long)page);
50354 }
50355diff --git a/fs/udf/misc.c b/fs/udf/misc.c
50356index c175b4d..8f36a16 100644
50357--- a/fs/udf/misc.c
50358+++ b/fs/udf/misc.c
50359@@ -289,7 +289,7 @@ void udf_new_tag(char *data, uint16_t ident, uint16_t version, uint16_t snum,
50360
50361 u8 udf_tag_checksum(const struct tag *t)
50362 {
50363- u8 *data = (u8 *)t;
50364+ const u8 *data = (const u8 *)t;
50365 u8 checksum = 0;
50366 int i;
50367 for (i = 0; i < sizeof(struct tag); ++i)
50368diff --git a/fs/utimes.c b/fs/utimes.c
50369index fa4dbe4..e12d1b9 100644
50370--- a/fs/utimes.c
50371+++ b/fs/utimes.c
50372@@ -1,6 +1,7 @@
50373 #include <linux/compiler.h>
50374 #include <linux/file.h>
50375 #include <linux/fs.h>
50376+#include <linux/security.h>
50377 #include <linux/linkage.h>
50378 #include <linux/mount.h>
50379 #include <linux/namei.h>
50380@@ -101,6 +102,12 @@ static int utimes_common(struct path *path, struct timespec *times)
50381 goto mnt_drop_write_and_out;
50382 }
50383 }
50384+
50385+ if (!gr_acl_handle_utime(path->dentry, path->mnt)) {
50386+ error = -EACCES;
50387+ goto mnt_drop_write_and_out;
50388+ }
50389+
50390 mutex_lock(&inode->i_mutex);
50391 error = notify_change(path->dentry, &newattrs);
50392 mutex_unlock(&inode->i_mutex);
50393diff --git a/fs/xattr.c b/fs/xattr.c
50394index 4d45b71..2ec08e10 100644
50395--- a/fs/xattr.c
50396+++ b/fs/xattr.c
50397@@ -316,7 +316,7 @@ EXPORT_SYMBOL_GPL(vfs_removexattr);
50398 * Extended attribute SET operations
50399 */
50400 static long
50401-setxattr(struct dentry *d, const char __user *name, const void __user *value,
50402+setxattr(struct path *path, const char __user *name, const void __user *value,
50403 size_t size, int flags)
50404 {
50405 int error;
50406@@ -349,7 +349,12 @@ setxattr(struct dentry *d, const char __user *name, const void __user *value,
50407 }
50408 }
50409
50410- error = vfs_setxattr(d, kname, kvalue, size, flags);
50411+ if (!gr_acl_handle_setxattr(path->dentry, path->mnt)) {
50412+ error = -EACCES;
50413+ goto out;
50414+ }
50415+
50416+ error = vfs_setxattr(path->dentry, kname, kvalue, size, flags);
50417 out:
50418 if (vvalue)
50419 vfree(vvalue);
50420@@ -370,7 +375,7 @@ SYSCALL_DEFINE5(setxattr, const char __user *, pathname,
50421 return error;
50422 error = mnt_want_write(path.mnt);
50423 if (!error) {
50424- error = setxattr(path.dentry, name, value, size, flags);
50425+ error = setxattr(&path, name, value, size, flags);
50426 mnt_drop_write(path.mnt);
50427 }
50428 path_put(&path);
50429@@ -389,7 +394,7 @@ SYSCALL_DEFINE5(lsetxattr, const char __user *, pathname,
50430 return error;
50431 error = mnt_want_write(path.mnt);
50432 if (!error) {
50433- error = setxattr(path.dentry, name, value, size, flags);
50434+ error = setxattr(&path, name, value, size, flags);
50435 mnt_drop_write(path.mnt);
50436 }
50437 path_put(&path);
50438@@ -401,17 +406,15 @@ SYSCALL_DEFINE5(fsetxattr, int, fd, const char __user *, name,
50439 {
50440 int fput_needed;
50441 struct file *f;
50442- struct dentry *dentry;
50443 int error = -EBADF;
50444
50445 f = fget_light(fd, &fput_needed);
50446 if (!f)
50447 return error;
50448- dentry = f->f_path.dentry;
50449- audit_inode(NULL, dentry);
50450+ audit_inode(NULL, f->f_path.dentry);
50451 error = mnt_want_write_file(f);
50452 if (!error) {
50453- error = setxattr(dentry, name, value, size, flags);
50454+ error = setxattr(&f->f_path, name, value, size, flags);
50455 mnt_drop_write_file(f);
50456 }
50457 fput_light(f, fput_needed);
50458diff --git a/fs/xattr_acl.c b/fs/xattr_acl.c
50459index 69d06b0..c0996e5 100644
50460--- a/fs/xattr_acl.c
50461+++ b/fs/xattr_acl.c
50462@@ -17,8 +17,8 @@
50463 struct posix_acl *
50464 posix_acl_from_xattr(const void *value, size_t size)
50465 {
50466- posix_acl_xattr_header *header = (posix_acl_xattr_header *)value;
50467- posix_acl_xattr_entry *entry = (posix_acl_xattr_entry *)(header+1), *end;
50468+ const posix_acl_xattr_header *header = (const posix_acl_xattr_header *)value;
50469+ const posix_acl_xattr_entry *entry = (const posix_acl_xattr_entry *)(header+1), *end;
50470 int count;
50471 struct posix_acl *acl;
50472 struct posix_acl_entry *acl_e;
50473diff --git a/fs/xfs/xfs_bmap.c b/fs/xfs/xfs_bmap.c
50474index 848ffa7..1f249bf 100644
50475--- a/fs/xfs/xfs_bmap.c
50476+++ b/fs/xfs/xfs_bmap.c
50477@@ -189,7 +189,7 @@ xfs_bmap_validate_ret(
50478 int nmap,
50479 int ret_nmap);
50480 #else
50481-#define xfs_bmap_validate_ret(bno,len,flags,mval,onmap,nmap)
50482+#define xfs_bmap_validate_ret(bno,len,flags,mval,onmap,nmap) do {} while (0)
50483 #endif /* DEBUG */
50484
50485 STATIC int
50486diff --git a/fs/xfs/xfs_dir2_sf.c b/fs/xfs/xfs_dir2_sf.c
50487index 1b9fc3e..e1bdde0 100644
50488--- a/fs/xfs/xfs_dir2_sf.c
50489+++ b/fs/xfs/xfs_dir2_sf.c
50490@@ -851,7 +851,15 @@ xfs_dir2_sf_getdents(
50491 }
50492
50493 ino = xfs_dir2_sfe_get_ino(sfp, sfep);
50494- if (filldir(dirent, (char *)sfep->name, sfep->namelen,
50495+ if (dp->i_df.if_u1.if_data == dp->i_df.if_u2.if_inline_data) {
50496+ char name[sfep->namelen];
50497+ memcpy(name, sfep->name, sfep->namelen);
50498+ if (filldir(dirent, name, sfep->namelen,
50499+ off & 0x7fffffff, ino, DT_UNKNOWN)) {
50500+ *offset = off & 0x7fffffff;
50501+ return 0;
50502+ }
50503+ } else if (filldir(dirent, (char *)sfep->name, sfep->namelen,
50504 off & 0x7fffffff, ino, DT_UNKNOWN)) {
50505 *offset = off & 0x7fffffff;
50506 return 0;
50507diff --git a/fs/xfs/xfs_ioctl.c b/fs/xfs/xfs_ioctl.c
50508index 0e0232c..fa5c3fe 100644
50509--- a/fs/xfs/xfs_ioctl.c
50510+++ b/fs/xfs/xfs_ioctl.c
50511@@ -126,7 +126,7 @@ xfs_find_handle(
50512 }
50513
50514 error = -EFAULT;
50515- if (copy_to_user(hreq->ohandle, &handle, hsize) ||
50516+ if (hsize > sizeof handle || copy_to_user(hreq->ohandle, &handle, hsize) ||
50517 copy_to_user(hreq->ohandlen, &hsize, sizeof(__s32)))
50518 goto out_put;
50519
50520diff --git a/fs/xfs/xfs_iops.c b/fs/xfs/xfs_iops.c
50521index 4e00cf0..3374374 100644
50522--- a/fs/xfs/xfs_iops.c
50523+++ b/fs/xfs/xfs_iops.c
50524@@ -394,7 +394,7 @@ xfs_vn_put_link(
50525 struct nameidata *nd,
50526 void *p)
50527 {
50528- char *s = nd_get_link(nd);
50529+ const char *s = nd_get_link(nd);
50530
50531 if (!IS_ERR(s))
50532 kfree(s);
50533diff --git a/grsecurity/Kconfig b/grsecurity/Kconfig
50534new file mode 100644
50535index 0000000..d38b430
50536--- /dev/null
50537+++ b/grsecurity/Kconfig
50538@@ -0,0 +1,947 @@
50539+#
50540+# grecurity configuration
50541+#
50542+menu "Memory Protections"
50543+depends on GRKERNSEC
50544+
50545+config GRKERNSEC_KMEM
50546+ bool "Deny reading/writing to /dev/kmem, /dev/mem, and /dev/port"
50547+ default y if GRKERNSEC_CONFIG_AUTO
50548+ select STRICT_DEVMEM if (X86 || ARM || TILE || S390)
50549+ help
50550+ If you say Y here, /dev/kmem and /dev/mem won't be allowed to
50551+ be written to or read from to modify or leak the contents of the running
50552+ kernel. /dev/port will also not be allowed to be opened. If you have module
50553+ support disabled, enabling this will close up four ways that are
50554+ currently used to insert malicious code into the running kernel.
50555+ Even with all these features enabled, we still highly recommend that
50556+ you use the RBAC system, as it is still possible for an attacker to
50557+ modify the running kernel through privileged I/O granted by ioperm/iopl.
50558+ If you are not using XFree86, you may be able to stop this additional
50559+ case by enabling the 'Disable privileged I/O' option. Though nothing
50560+ legitimately writes to /dev/kmem, XFree86 does need to write to /dev/mem,
50561+ but only to video memory, which is the only writing we allow in this
50562+ case. If /dev/kmem or /dev/mem are mmaped without PROT_WRITE, they will
50563+ not be allowed to mprotect it with PROT_WRITE later.
50564+ It is highly recommended that you say Y here if you meet all the
50565+ conditions above.
50566+
50567+config GRKERNSEC_VM86
50568+ bool "Restrict VM86 mode"
50569+ default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER)
50570+ depends on X86_32
50571+
50572+ help
50573+ If you say Y here, only processes with CAP_SYS_RAWIO will be able to
50574+ make use of a special execution mode on 32bit x86 processors called
50575+ Virtual 8086 (VM86) mode. XFree86 may need vm86 mode for certain
50576+ video cards and will still work with this option enabled. The purpose
50577+ of the option is to prevent exploitation of emulation errors in
50578+ virtualization of vm86 mode like the one discovered in VMWare in 2009.
50579+ Nearly all users should be able to enable this option.
50580+
50581+config GRKERNSEC_IO
50582+ bool "Disable privileged I/O"
50583+ default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER)
50584+ depends on X86
50585+ select RTC_CLASS
50586+ select RTC_INTF_DEV
50587+ select RTC_DRV_CMOS
50588+
50589+ help
50590+ If you say Y here, all ioperm and iopl calls will return an error.
50591+ Ioperm and iopl can be used to modify the running kernel.
50592+ Unfortunately, some programs need this access to operate properly,
50593+ the most notable of which are XFree86 and hwclock. hwclock can be
50594+ remedied by having RTC support in the kernel, so real-time
50595+ clock support is enabled if this option is enabled, to ensure
50596+ that hwclock operates correctly. XFree86 still will not
50597+ operate correctly with this option enabled, so DO NOT CHOOSE Y
50598+ IF YOU USE XFree86. If you use XFree86 and you still want to
50599+ protect your kernel against modification, use the RBAC system.
50600+
50601+config GRKERNSEC_PROC_MEMMAP
50602+ bool "Harden ASLR against information leaks and entropy reduction"
50603+ default y if (GRKERNSEC_CONFIG_AUTO || PAX_NOEXEC || PAX_ASLR)
50604+ depends on PAX_NOEXEC || PAX_ASLR
50605+ help
50606+ If you say Y here, the /proc/<pid>/maps and /proc/<pid>/stat files will
50607+ give no information about the addresses of its mappings if
50608+ PaX features that rely on random addresses are enabled on the task.
50609+ In addition to sanitizing this information and disabling other
50610+ dangerous sources of information, this option causes reads of sensitive
50611+ /proc/<pid> entries where the file descriptor was opened in a different
50612+ task than the one performing the read. Such attempts are logged.
50613+ This option also limits argv/env strings for suid/sgid binaries
50614+ to 512KB to prevent a complete exhaustion of the stack entropy provided
50615+ by ASLR. Finally, it places an 8MB stack resource limit on suid/sgid
50616+ binaries to prevent alternative mmap layouts from being abused.
50617+
50618+ If you use PaX it is essential that you say Y here as it closes up
50619+ several holes that make full ASLR useless locally.
50620+
50621+config GRKERNSEC_BRUTE
50622+ bool "Deter exploit bruteforcing"
50623+ default y if GRKERNSEC_CONFIG_AUTO
50624+ help
50625+ If you say Y here, attempts to bruteforce exploits against forking
50626+ daemons such as apache or sshd, as well as against suid/sgid binaries
50627+ will be deterred. When a child of a forking daemon is killed by PaX
50628+ or crashes due to an illegal instruction or other suspicious signal,
50629+ the parent process will be delayed 30 seconds upon every subsequent
50630+ fork until the administrator is able to assess the situation and
50631+ restart the daemon.
50632+ In the suid/sgid case, the attempt is logged, the user has all their
50633+ processes terminated, and they are prevented from executing any further
50634+ processes for 15 minutes.
50635+ It is recommended that you also enable signal logging in the auditing
50636+ section so that logs are generated when a process triggers a suspicious
50637+ signal.
50638+ If the sysctl option is enabled, a sysctl option with name
50639+ "deter_bruteforce" is created.
50640+
50641+
50642+config GRKERNSEC_MODHARDEN
50643+ bool "Harden module auto-loading"
50644+ default y if GRKERNSEC_CONFIG_AUTO
50645+ depends on MODULES
50646+ help
50647+ If you say Y here, module auto-loading in response to use of some
50648+ feature implemented by an unloaded module will be restricted to
50649+ root users. Enabling this option helps defend against attacks
50650+ by unprivileged users who abuse the auto-loading behavior to
50651+ cause a vulnerable module to load that is then exploited.
50652+
50653+ If this option prevents a legitimate use of auto-loading for a
50654+ non-root user, the administrator can execute modprobe manually
50655+ with the exact name of the module mentioned in the alert log.
50656+ Alternatively, the administrator can add the module to the list
50657+ of modules loaded at boot by modifying init scripts.
50658+
50659+ Modification of init scripts will most likely be needed on
50660+ Ubuntu servers with encrypted home directory support enabled,
50661+ as the first non-root user logging in will cause the ecb(aes),
50662+ ecb(aes)-all, cbc(aes), and cbc(aes)-all modules to be loaded.
50663+
50664+config GRKERNSEC_HIDESYM
50665+ bool "Hide kernel symbols"
50666+ default y if GRKERNSEC_CONFIG_AUTO
50667+ select PAX_USERCOPY_SLABS
50668+ help
50669+ If you say Y here, getting information on loaded modules, and
50670+ displaying all kernel symbols through a syscall will be restricted
50671+ to users with CAP_SYS_MODULE. For software compatibility reasons,
50672+ /proc/kallsyms will be restricted to the root user. The RBAC
50673+ system can hide that entry even from root.
50674+
50675+ This option also prevents leaking of kernel addresses through
50676+ several /proc entries.
50677+
50678+ Note that this option is only effective provided the following
50679+ conditions are met:
50680+ 1) The kernel using grsecurity is not precompiled by some distribution
50681+ 2) You have also enabled GRKERNSEC_DMESG
50682+ 3) You are using the RBAC system and hiding other files such as your
50683+ kernel image and System.map. Alternatively, enabling this option
50684+ causes the permissions on /boot, /lib/modules, and the kernel
50685+ source directory to change at compile time to prevent
50686+ reading by non-root users.
50687+ If the above conditions are met, this option will aid in providing a
50688+ useful protection against local kernel exploitation of overflows
50689+ and arbitrary read/write vulnerabilities.
50690+
50691+config GRKERNSEC_KERN_LOCKOUT
50692+ bool "Active kernel exploit response"
50693+ default y if GRKERNSEC_CONFIG_AUTO
50694+ depends on X86 || ARM || PPC || SPARC
50695+ help
50696+ If you say Y here, when a PaX alert is triggered due to suspicious
50697+ activity in the kernel (from KERNEXEC/UDEREF/USERCOPY)
50698+ or an OOPS occurs due to bad memory accesses, instead of just
50699+ terminating the offending process (and potentially allowing
50700+ a subsequent exploit from the same user), we will take one of two
50701+ actions:
50702+ If the user was root, we will panic the system
50703+ If the user was non-root, we will log the attempt, terminate
50704+ all processes owned by the user, then prevent them from creating
50705+ any new processes until the system is restarted
50706+ This deters repeated kernel exploitation/bruteforcing attempts
50707+ and is useful for later forensics.
50708+
50709+endmenu
50710+menu "Role Based Access Control Options"
50711+depends on GRKERNSEC
50712+
50713+config GRKERNSEC_RBAC_DEBUG
50714+ bool
50715+
50716+config GRKERNSEC_NO_RBAC
50717+ bool "Disable RBAC system"
50718+ help
50719+ If you say Y here, the /dev/grsec device will be removed from the kernel,
50720+ preventing the RBAC system from being enabled. You should only say Y
50721+ here if you have no intention of using the RBAC system, so as to prevent
50722+ an attacker with root access from misusing the RBAC system to hide files
50723+ and processes when loadable module support and /dev/[k]mem have been
50724+ locked down.
50725+
50726+config GRKERNSEC_ACL_HIDEKERN
50727+ bool "Hide kernel processes"
50728+ help
50729+ If you say Y here, all kernel threads will be hidden to all
50730+ processes but those whose subject has the "view hidden processes"
50731+ flag.
50732+
50733+config GRKERNSEC_ACL_MAXTRIES
50734+ int "Maximum tries before password lockout"
50735+ default 3
50736+ help
50737+ This option enforces the maximum number of times a user can attempt
50738+ to authorize themselves with the grsecurity RBAC system before being
50739+ denied the ability to attempt authorization again for a specified time.
50740+ The lower the number, the harder it will be to brute-force a password.
50741+
50742+config GRKERNSEC_ACL_TIMEOUT
50743+ int "Time to wait after max password tries, in seconds"
50744+ default 30
50745+ help
50746+ This option specifies the time the user must wait after attempting to
50747+ authorize to the RBAC system with the maximum number of invalid
50748+ passwords. The higher the number, the harder it will be to brute-force
50749+ a password.
50750+
50751+endmenu
50752+menu "Filesystem Protections"
50753+depends on GRKERNSEC
50754+
50755+config GRKERNSEC_PROC
50756+ bool "Proc restrictions"
50757+ default y if GRKERNSEC_CONFIG_AUTO
50758+ help
50759+ If you say Y here, the permissions of the /proc filesystem
50760+ will be altered to enhance system security and privacy. You MUST
50761+ choose either a user only restriction or a user and group restriction.
50762+ Depending upon the option you choose, you can either restrict users to
50763+ see only the processes they themselves run, or choose a group that can
50764+ view all processes and files normally restricted to root if you choose
50765+ the "restrict to user only" option. NOTE: If you're running identd or
50766+ ntpd as a non-root user, you will have to run it as the group you
50767+ specify here.
50768+
50769+config GRKERNSEC_PROC_USER
50770+ bool "Restrict /proc to user only"
50771+ depends on GRKERNSEC_PROC
50772+ help
50773+ If you say Y here, non-root users will only be able to view their own
50774+ processes, and restricts them from viewing network-related information,
50775+ and viewing kernel symbol and module information.
50776+
50777+config GRKERNSEC_PROC_USERGROUP
50778+ bool "Allow special group"
50779+ default y if GRKERNSEC_CONFIG_AUTO
50780+ depends on GRKERNSEC_PROC && !GRKERNSEC_PROC_USER
50781+ help
50782+ If you say Y here, you will be able to select a group that will be
50783+ able to view all processes and network-related information. If you've
50784+ enabled GRKERNSEC_HIDESYM, kernel and symbol information may still
50785+ remain hidden. This option is useful if you want to run identd as
50786+ a non-root user. The group you select may also be chosen at boot time
50787+ via "grsec_proc_gid=" on the kernel commandline.
50788+
50789+config GRKERNSEC_PROC_GID
50790+ int "GID for special group"
50791+ depends on GRKERNSEC_PROC_USERGROUP
50792+ default 1001
50793+
50794+config GRKERNSEC_PROC_ADD
50795+ bool "Additional restrictions"
50796+ default y if GRKERNSEC_CONFIG_AUTO
50797+ depends on GRKERNSEC_PROC_USER || GRKERNSEC_PROC_USERGROUP
50798+ help
50799+ If you say Y here, additional restrictions will be placed on
50800+ /proc that keep normal users from viewing device information and
50801+ slabinfo information that could be useful for exploits.
50802+
50803+config GRKERNSEC_LINK
50804+ bool "Linking restrictions"
50805+ default y if GRKERNSEC_CONFIG_AUTO
50806+ help
50807+ If you say Y here, /tmp race exploits will be prevented, since users
50808+ will no longer be able to follow symlinks owned by other users in
50809+ world-writable +t directories (e.g. /tmp), unless the owner of the
50810+ symlink is the owner of the directory. users will also not be
50811+ able to hardlink to files they do not own. If the sysctl option is
50812+ enabled, a sysctl option with name "linking_restrictions" is created.
50813+
50814+config GRKERNSEC_SYMLINKOWN
50815+ bool "Kernel-enforced SymlinksIfOwnerMatch"
50816+ default y if GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER
50817+ help
50818+ Apache's SymlinksIfOwnerMatch option has an inherent race condition
50819+ that prevents it from being used as a security feature. As Apache
50820+ verifies the symlink by performing a stat() against the target of
50821+ the symlink before it is followed, an attacker can setup a symlink
50822+ to point to a same-owned file, then replace the symlink with one
50823+ that targets another user's file just after Apache "validates" the
50824+ symlink -- a classic TOCTOU race. If you say Y here, a complete,
50825+ race-free replacement for Apache's "SymlinksIfOwnerMatch" option
50826+ will be in place for the group you specify. If the sysctl option
50827+ is enabled, a sysctl option with name "enforce_symlinksifowner" is
50828+ created.
50829+
50830+config GRKERNSEC_SYMLINKOWN_GID
50831+ int "GID for users with kernel-enforced SymlinksIfOwnerMatch"
50832+ depends on GRKERNSEC_SYMLINKOWN
50833+ default 1006
50834+ help
50835+ Setting this GID determines what group kernel-enforced
50836+ SymlinksIfOwnerMatch will be enabled for. If the sysctl option
50837+ is enabled, a sysctl option with name "symlinkown_gid" is created.
50838+
50839+config GRKERNSEC_FIFO
50840+ bool "FIFO restrictions"
50841+ default y if GRKERNSEC_CONFIG_AUTO
50842+ help
50843+ If you say Y here, users will not be able to write to FIFOs they don't
50844+ own in world-writable +t directories (e.g. /tmp), unless the owner of
50845+ the FIFO is the same owner of the directory it's held in. If the sysctl
50846+ option is enabled, a sysctl option with name "fifo_restrictions" is
50847+ created.
50848+
50849+config GRKERNSEC_SYSFS_RESTRICT
50850+ bool "Sysfs/debugfs restriction"
50851+ default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER)
50852+ depends on SYSFS
50853+ help
50854+ If you say Y here, sysfs (the pseudo-filesystem mounted at /sys) and
50855+ any filesystem normally mounted under it (e.g. debugfs) will be
50856+ mostly accessible only by root. These filesystems generally provide access
50857+ to hardware and debug information that isn't appropriate for unprivileged
50858+ users of the system. Sysfs and debugfs have also become a large source
50859+ of new vulnerabilities, ranging from infoleaks to local compromise.
50860+ There has been very little oversight with an eye toward security involved
50861+ in adding new exporters of information to these filesystems, so their
50862+ use is discouraged.
50863+ For reasons of compatibility, a few directories have been whitelisted
50864+ for access by non-root users:
50865+ /sys/fs/selinux
50866+ /sys/fs/fuse
50867+ /sys/devices/system/cpu
50868+
50869+config GRKERNSEC_ROFS
50870+ bool "Runtime read-only mount protection"
50871+ help
50872+ If you say Y here, a sysctl option with name "romount_protect" will
50873+ be created. By setting this option to 1 at runtime, filesystems
50874+ will be protected in the following ways:
50875+ * No new writable mounts will be allowed
50876+ * Existing read-only mounts won't be able to be remounted read/write
50877+ * Write operations will be denied on all block devices
50878+ This option acts independently of grsec_lock: once it is set to 1,
50879+ it cannot be turned off. Therefore, please be mindful of the resulting
50880+ behavior if this option is enabled in an init script on a read-only
50881+ filesystem. This feature is mainly intended for secure embedded systems.
50882+
50883+config GRKERNSEC_CHROOT
50884+ bool "Chroot jail restrictions"
50885+ default y if GRKERNSEC_CONFIG_AUTO
50886+ help
50887+ If you say Y here, you will be able to choose several options that will
50888+ make breaking out of a chrooted jail much more difficult. If you
50889+ encounter no software incompatibilities with the following options, it
50890+ is recommended that you enable each one.
50891+
50892+config GRKERNSEC_CHROOT_MOUNT
50893+ bool "Deny mounts"
50894+ default y if GRKERNSEC_CONFIG_AUTO
50895+ depends on GRKERNSEC_CHROOT
50896+ help
50897+ If you say Y here, processes inside a chroot will not be able to
50898+ mount or remount filesystems. If the sysctl option is enabled, a
50899+ sysctl option with name "chroot_deny_mount" is created.
50900+
50901+config GRKERNSEC_CHROOT_DOUBLE
50902+ bool "Deny double-chroots"
50903+ default y if GRKERNSEC_CONFIG_AUTO
50904+ depends on GRKERNSEC_CHROOT
50905+ help
50906+ If you say Y here, processes inside a chroot will not be able to chroot
50907+ again outside the chroot. This is a widely used method of breaking
50908+ out of a chroot jail and should not be allowed. If the sysctl
50909+ option is enabled, a sysctl option with name
50910+ "chroot_deny_chroot" is created.
50911+
50912+config GRKERNSEC_CHROOT_PIVOT
50913+ bool "Deny pivot_root in chroot"
50914+ default y if GRKERNSEC_CONFIG_AUTO
50915+ depends on GRKERNSEC_CHROOT
50916+ help
50917+ If you say Y here, processes inside a chroot will not be able to use
50918+ a function called pivot_root() that was introduced in Linux 2.3.41. It
50919+ works similar to chroot in that it changes the root filesystem. This
50920+ function could be misused in a chrooted process to attempt to break out
50921+ of the chroot, and therefore should not be allowed. If the sysctl
50922+ option is enabled, a sysctl option with name "chroot_deny_pivot" is
50923+ created.
50924+
50925+config GRKERNSEC_CHROOT_CHDIR
50926+ bool "Enforce chdir(\"/\") on all chroots"
50927+ default y if GRKERNSEC_CONFIG_AUTO
50928+ depends on GRKERNSEC_CHROOT
50929+ help
50930+ If you say Y here, the current working directory of all newly-chrooted
50931+ applications will be set to the the root directory of the chroot.
50932+ The man page on chroot(2) states:
50933+ Note that this call does not change the current working
50934+ directory, so that `.' can be outside the tree rooted at
50935+ `/'. In particular, the super-user can escape from a
50936+ `chroot jail' by doing `mkdir foo; chroot foo; cd ..'.
50937+
50938+ It is recommended that you say Y here, since it's not known to break
50939+ any software. If the sysctl option is enabled, a sysctl option with
50940+ name "chroot_enforce_chdir" is created.
50941+
50942+config GRKERNSEC_CHROOT_CHMOD
50943+ bool "Deny (f)chmod +s"
50944+ default y if GRKERNSEC_CONFIG_AUTO
50945+ depends on GRKERNSEC_CHROOT
50946+ help
50947+ If you say Y here, processes inside a chroot will not be able to chmod
50948+ or fchmod files to make them have suid or sgid bits. This protects
50949+ against another published method of breaking a chroot. If the sysctl
50950+ option is enabled, a sysctl option with name "chroot_deny_chmod" is
50951+ created.
50952+
50953+config GRKERNSEC_CHROOT_FCHDIR
50954+ bool "Deny fchdir out of chroot"
50955+ default y if GRKERNSEC_CONFIG_AUTO
50956+ depends on GRKERNSEC_CHROOT
50957+ help
50958+ If you say Y here, a well-known method of breaking chroots by fchdir'ing
50959+ to a file descriptor of the chrooting process that points to a directory
50960+ outside the filesystem will be stopped. If the sysctl option
50961+ is enabled, a sysctl option with name "chroot_deny_fchdir" is created.
50962+
50963+config GRKERNSEC_CHROOT_MKNOD
50964+ bool "Deny mknod"
50965+ default y if GRKERNSEC_CONFIG_AUTO
50966+ depends on GRKERNSEC_CHROOT
50967+ help
50968+ If you say Y here, processes inside a chroot will not be allowed to
50969+ mknod. The problem with using mknod inside a chroot is that it
50970+ would allow an attacker to create a device entry that is the same
50971+ as one on the physical root of your system, which could range from
50972+ anything from the console device to a device for your harddrive (which
50973+ they could then use to wipe the drive or steal data). It is recommended
50974+ that you say Y here, unless you run into software incompatibilities.
50975+ If the sysctl option is enabled, a sysctl option with name
50976+ "chroot_deny_mknod" is created.
50977+
50978+config GRKERNSEC_CHROOT_SHMAT
50979+ bool "Deny shmat() out of chroot"
50980+ default y if GRKERNSEC_CONFIG_AUTO
50981+ depends on GRKERNSEC_CHROOT
50982+ help
50983+ If you say Y here, processes inside a chroot will not be able to attach
50984+ to shared memory segments that were created outside of the chroot jail.
50985+ It is recommended that you say Y here. If the sysctl option is enabled,
50986+ a sysctl option with name "chroot_deny_shmat" is created.
50987+
50988+config GRKERNSEC_CHROOT_UNIX
50989+ bool "Deny access to abstract AF_UNIX sockets out of chroot"
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 able to
50994+ connect to abstract (meaning not belonging to a filesystem) Unix
50995+ domain sockets that were bound outside of a chroot. It is recommended
50996+ that you say Y here. If the sysctl option is enabled, a sysctl option
50997+ with name "chroot_deny_unix" is created.
50998+
50999+config GRKERNSEC_CHROOT_FINDTASK
51000+ bool "Protect outside processes"
51001+ default y if GRKERNSEC_CONFIG_AUTO
51002+ depends on GRKERNSEC_CHROOT
51003+ help
51004+ If you say Y here, processes inside a chroot will not be able to
51005+ kill, send signals with fcntl, ptrace, capget, getpgid, setpgid,
51006+ getsid, or view any process outside of the chroot. If the sysctl
51007+ option is enabled, a sysctl option with name "chroot_findtask" is
51008+ created.
51009+
51010+config GRKERNSEC_CHROOT_NICE
51011+ bool "Restrict priority changes"
51012+ default y if GRKERNSEC_CONFIG_AUTO
51013+ depends on GRKERNSEC_CHROOT
51014+ help
51015+ If you say Y here, processes inside a chroot will not be able to raise
51016+ the priority of processes in the chroot, or alter the priority of
51017+ processes outside the chroot. This provides more security than simply
51018+ removing CAP_SYS_NICE from the process' capability set. If the
51019+ sysctl option is enabled, a sysctl option with name "chroot_restrict_nice"
51020+ is created.
51021+
51022+config GRKERNSEC_CHROOT_SYSCTL
51023+ bool "Deny sysctl writes"
51024+ default y if GRKERNSEC_CONFIG_AUTO
51025+ depends on GRKERNSEC_CHROOT
51026+ help
51027+ If you say Y here, an attacker in a chroot will not be able to
51028+ write to sysctl entries, either by sysctl(2) or through a /proc
51029+ interface. It is strongly recommended that you say Y here. If the
51030+ sysctl option is enabled, a sysctl option with name
51031+ "chroot_deny_sysctl" is created.
51032+
51033+config GRKERNSEC_CHROOT_CAPS
51034+ bool "Capability restrictions"
51035+ default y if GRKERNSEC_CONFIG_AUTO
51036+ depends on GRKERNSEC_CHROOT
51037+ help
51038+ If you say Y here, the capabilities on all processes within a
51039+ chroot jail will be lowered to stop module insertion, raw i/o,
51040+ system and net admin tasks, rebooting the system, modifying immutable
51041+ files, modifying IPC owned by another, and changing the system time.
51042+ This is left an option because it can break some apps. Disable this
51043+ if your chrooted apps are having problems performing those kinds of
51044+ tasks. If the sysctl option is enabled, a sysctl option with
51045+ name "chroot_caps" is created.
51046+
51047+endmenu
51048+menu "Kernel Auditing"
51049+depends on GRKERNSEC
51050+
51051+config GRKERNSEC_AUDIT_GROUP
51052+ bool "Single group for auditing"
51053+ help
51054+ If you say Y here, the exec, chdir, and (un)mount logging features
51055+ will only operate on a group you specify. This option is recommended
51056+ if you only want to watch certain users instead of having a large
51057+ amount of logs from the entire system. If the sysctl option is enabled,
51058+ a sysctl option with name "audit_group" is created.
51059+
51060+config GRKERNSEC_AUDIT_GID
51061+ int "GID for auditing"
51062+ depends on GRKERNSEC_AUDIT_GROUP
51063+ default 1007
51064+
51065+config GRKERNSEC_EXECLOG
51066+ bool "Exec logging"
51067+ help
51068+ If you say Y here, all execve() calls will be logged (since the
51069+ other exec*() calls are frontends to execve(), all execution
51070+ will be logged). Useful for shell-servers that like to keep track
51071+ of their users. If the sysctl option is enabled, a sysctl option with
51072+ name "exec_logging" is created.
51073+ WARNING: This option when enabled will produce a LOT of logs, especially
51074+ on an active system.
51075+
51076+config GRKERNSEC_RESLOG
51077+ bool "Resource logging"
51078+ default y if GRKERNSEC_CONFIG_AUTO
51079+ help
51080+ If you say Y here, all attempts to overstep resource limits will
51081+ be logged with the resource name, the requested size, and the current
51082+ limit. It is highly recommended that you say Y here. If the sysctl
51083+ option is enabled, a sysctl option with name "resource_logging" is
51084+ created. If the RBAC system is enabled, the sysctl value is ignored.
51085+
51086+config GRKERNSEC_CHROOT_EXECLOG
51087+ bool "Log execs within chroot"
51088+ help
51089+ If you say Y here, all executions inside a chroot jail will be logged
51090+ to syslog. This can cause a large amount of logs if certain
51091+ applications (eg. djb's daemontools) are installed on the system, and
51092+ is therefore left as an option. If the sysctl option is enabled, a
51093+ sysctl option with name "chroot_execlog" is created.
51094+
51095+config GRKERNSEC_AUDIT_PTRACE
51096+ bool "Ptrace logging"
51097+ help
51098+ If you say Y here, all attempts to attach to a process via ptrace
51099+ will be logged. If the sysctl option is enabled, a sysctl option
51100+ with name "audit_ptrace" is created.
51101+
51102+config GRKERNSEC_AUDIT_CHDIR
51103+ bool "Chdir logging"
51104+ help
51105+ If you say Y here, all chdir() calls will be logged. If the sysctl
51106+ option is enabled, a sysctl option with name "audit_chdir" is created.
51107+
51108+config GRKERNSEC_AUDIT_MOUNT
51109+ bool "(Un)Mount logging"
51110+ help
51111+ If you say Y here, all mounts and unmounts will be logged. If the
51112+ sysctl option is enabled, a sysctl option with name "audit_mount" is
51113+ created.
51114+
51115+config GRKERNSEC_SIGNAL
51116+ bool "Signal logging"
51117+ default y if GRKERNSEC_CONFIG_AUTO
51118+ help
51119+ If you say Y here, certain important signals will be logged, such as
51120+ SIGSEGV, which will as a result inform you of when a error in a program
51121+ occurred, which in some cases could mean a possible exploit attempt.
51122+ If the sysctl option is enabled, a sysctl option with name
51123+ "signal_logging" is created.
51124+
51125+config GRKERNSEC_FORKFAIL
51126+ bool "Fork failure logging"
51127+ help
51128+ If you say Y here, all failed fork() attempts will be logged.
51129+ This could suggest a fork bomb, or someone attempting to overstep
51130+ their process limit. If the sysctl option is enabled, a sysctl option
51131+ with name "forkfail_logging" is created.
51132+
51133+config GRKERNSEC_TIME
51134+ bool "Time change logging"
51135+ default y if GRKERNSEC_CONFIG_AUTO
51136+ help
51137+ If you say Y here, any changes of the system clock will be logged.
51138+ If the sysctl option is enabled, a sysctl option with name
51139+ "timechange_logging" is created.
51140+
51141+config GRKERNSEC_PROC_IPADDR
51142+ bool "/proc/<pid>/ipaddr support"
51143+ default y if GRKERNSEC_CONFIG_AUTO
51144+ help
51145+ If you say Y here, a new entry will be added to each /proc/<pid>
51146+ directory that contains the IP address of the person using the task.
51147+ The IP is carried across local TCP and AF_UNIX stream sockets.
51148+ This information can be useful for IDS/IPSes to perform remote response
51149+ to a local attack. The entry is readable by only the owner of the
51150+ process (and root if he has CAP_DAC_OVERRIDE, which can be removed via
51151+ the RBAC system), and thus does not create privacy concerns.
51152+
51153+config GRKERNSEC_RWXMAP_LOG
51154+ bool 'Denied RWX mmap/mprotect logging'
51155+ default y if GRKERNSEC_CONFIG_AUTO
51156+ depends on PAX_MPROTECT && !PAX_EMUPLT && !PAX_EMUSIGRT
51157+ help
51158+ If you say Y here, calls to mmap() and mprotect() with explicit
51159+ usage of PROT_WRITE and PROT_EXEC together will be logged when
51160+ denied by the PAX_MPROTECT feature. If the sysctl option is
51161+ enabled, a sysctl option with name "rwxmap_logging" is created.
51162+
51163+config GRKERNSEC_AUDIT_TEXTREL
51164+ bool 'ELF text relocations logging (READ HELP)'
51165+ depends on PAX_MPROTECT
51166+ help
51167+ If you say Y here, text relocations will be logged with the filename
51168+ of the offending library or binary. The purpose of the feature is
51169+ to help Linux distribution developers get rid of libraries and
51170+ binaries that need text relocations which hinder the future progress
51171+ of PaX. Only Linux distribution developers should say Y here, and
51172+ never on a production machine, as this option creates an information
51173+ leak that could aid an attacker in defeating the randomization of
51174+ a single memory region. If the sysctl option is enabled, a sysctl
51175+ option with name "audit_textrel" is created.
51176+
51177+endmenu
51178+
51179+menu "Executable Protections"
51180+depends on GRKERNSEC
51181+
51182+config GRKERNSEC_DMESG
51183+ bool "Dmesg(8) restriction"
51184+ default y if GRKERNSEC_CONFIG_AUTO
51185+ help
51186+ If you say Y here, non-root users will not be able to use dmesg(8)
51187+ to view up to the last 4kb of messages in the kernel's log buffer.
51188+ The kernel's log buffer often contains kernel addresses and other
51189+ identifying information useful to an attacker in fingerprinting a
51190+ system for a targeted exploit.
51191+ If the sysctl option is enabled, a sysctl option with name "dmesg" is
51192+ created.
51193+
51194+config GRKERNSEC_HARDEN_PTRACE
51195+ bool "Deter ptrace-based process snooping"
51196+ default y if GRKERNSEC_CONFIG_AUTO
51197+ help
51198+ If you say Y here, TTY sniffers and other malicious monitoring
51199+ programs implemented through ptrace will be defeated. If you
51200+ have been using the RBAC system, this option has already been
51201+ enabled for several years for all users, with the ability to make
51202+ fine-grained exceptions.
51203+
51204+ This option only affects the ability of non-root users to ptrace
51205+ processes that are not a descendent of the ptracing process.
51206+ This means that strace ./binary and gdb ./binary will still work,
51207+ but attaching to arbitrary processes will not. If the sysctl
51208+ option is enabled, a sysctl option with name "harden_ptrace" is
51209+ created.
51210+
51211+config GRKERNSEC_PTRACE_READEXEC
51212+ bool "Require read access to ptrace sensitive binaries"
51213+ default y if GRKERNSEC_CONFIG_AUTO
51214+ help
51215+ If you say Y here, unprivileged users will not be able to ptrace unreadable
51216+ binaries. This option is useful in environments that
51217+ remove the read bits (e.g. file mode 4711) from suid binaries to
51218+ prevent infoleaking of their contents. This option adds
51219+ consistency to the use of that file mode, as the binary could normally
51220+ be read out when run without privileges while ptracing.
51221+
51222+ If the sysctl option is enabled, a sysctl option with name "ptrace_readexec"
51223+ is created.
51224+
51225+config GRKERNSEC_SETXID
51226+ bool "Enforce consistent multithreaded privileges"
51227+ default y if GRKERNSEC_CONFIG_AUTO
51228+ depends on (X86 || SPARC64 || PPC || ARM || MIPS)
51229+ help
51230+ If you say Y here, a change from a root uid to a non-root uid
51231+ in a multithreaded application will cause the resulting uids,
51232+ gids, supplementary groups, and capabilities in that thread
51233+ to be propagated to the other threads of the process. In most
51234+ cases this is unnecessary, as glibc will emulate this behavior
51235+ on behalf of the application. Other libcs do not act in the
51236+ same way, allowing the other threads of the process to continue
51237+ running with root privileges. If the sysctl option is enabled,
51238+ a sysctl option with name "consistent_setxid" is created.
51239+
51240+config GRKERNSEC_TPE
51241+ bool "Trusted Path Execution (TPE)"
51242+ default y if GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER
51243+ help
51244+ If you say Y here, you will be able to choose a gid to add to the
51245+ supplementary groups of users you want to mark as "untrusted."
51246+ These users will not be able to execute any files that are not in
51247+ root-owned directories writable only by root. If the sysctl option
51248+ is enabled, a sysctl option with name "tpe" is created.
51249+
51250+config GRKERNSEC_TPE_ALL
51251+ bool "Partially restrict all non-root users"
51252+ depends on GRKERNSEC_TPE
51253+ help
51254+ If you say Y here, all non-root users will be covered under
51255+ a weaker TPE restriction. This is separate from, and in addition to,
51256+ the main TPE options that you have selected elsewhere. Thus, if a
51257+ "trusted" GID is chosen, this restriction applies to even that GID.
51258+ Under this restriction, all non-root users will only be allowed to
51259+ execute files in directories they own that are not group or
51260+ world-writable, or in directories owned by root and writable only by
51261+ root. If the sysctl option is enabled, a sysctl option with name
51262+ "tpe_restrict_all" is created.
51263+
51264+config GRKERNSEC_TPE_INVERT
51265+ bool "Invert GID option"
51266+ depends on GRKERNSEC_TPE
51267+ help
51268+ If you say Y here, the group you specify in the TPE configuration will
51269+ decide what group TPE restrictions will be *disabled* for. This
51270+ option is useful if you want TPE restrictions to be applied to most
51271+ users on the system. If the sysctl option is enabled, a sysctl option
51272+ with name "tpe_invert" is created. Unlike other sysctl options, this
51273+ entry will default to on for backward-compatibility.
51274+
51275+config GRKERNSEC_TPE_GID
51276+ int
51277+ default GRKERNSEC_TPE_UNTRUSTED_GID if (GRKERNSEC_TPE && !GRKERNSEC_TPE_INVERT)
51278+ default GRKERNSEC_TPE_TRUSTED_GID if (GRKERNSEC_TPE && GRKERNSEC_TPE_INVERT)
51279+
51280+config GRKERNSEC_TPE_UNTRUSTED_GID
51281+ int "GID for TPE-untrusted users"
51282+ depends on GRKERNSEC_TPE && !GRKERNSEC_TPE_INVERT
51283+ default 1005
51284+ help
51285+ Setting this GID determines what group TPE restrictions will be
51286+ *enabled* for. If the sysctl option is enabled, a sysctl option
51287+ with name "tpe_gid" is created.
51288+
51289+config GRKERNSEC_TPE_TRUSTED_GID
51290+ int "GID for TPE-trusted users"
51291+ depends on GRKERNSEC_TPE && GRKERNSEC_TPE_INVERT
51292+ default 1005
51293+ help
51294+ Setting this GID determines what group TPE restrictions will be
51295+ *disabled* for. If the sysctl option is enabled, a sysctl option
51296+ with name "tpe_gid" is created.
51297+
51298+endmenu
51299+menu "Network Protections"
51300+depends on GRKERNSEC
51301+
51302+config GRKERNSEC_RANDNET
51303+ bool "Larger entropy pools"
51304+ default y if GRKERNSEC_CONFIG_AUTO
51305+ help
51306+ If you say Y here, the entropy pools used for many features of Linux
51307+ and grsecurity will be doubled in size. Since several grsecurity
51308+ features use additional randomness, it is recommended that you say Y
51309+ here. Saying Y here has a similar effect as modifying
51310+ /proc/sys/kernel/random/poolsize.
51311+
51312+config GRKERNSEC_BLACKHOLE
51313+ bool "TCP/UDP blackhole and LAST_ACK DoS prevention"
51314+ default y if GRKERNSEC_CONFIG_AUTO
51315+ depends on NET
51316+ help
51317+ If you say Y here, neither TCP resets nor ICMP
51318+ destination-unreachable packets will be sent in response to packets
51319+ sent to ports for which no associated listening process exists.
51320+ This feature supports both IPV4 and IPV6 and exempts the
51321+ loopback interface from blackholing. Enabling this feature
51322+ makes a host more resilient to DoS attacks and reduces network
51323+ visibility against scanners.
51324+
51325+ The blackhole feature as-implemented is equivalent to the FreeBSD
51326+ blackhole feature, as it prevents RST responses to all packets, not
51327+ just SYNs. Under most application behavior this causes no
51328+ problems, but applications (like haproxy) may not close certain
51329+ connections in a way that cleanly terminates them on the remote
51330+ end, leaving the remote host in LAST_ACK state. Because of this
51331+ side-effect and to prevent intentional LAST_ACK DoSes, this
51332+ feature also adds automatic mitigation against such attacks.
51333+ The mitigation drastically reduces the amount of time a socket
51334+ can spend in LAST_ACK state. If you're using haproxy and not
51335+ all servers it connects to have this option enabled, consider
51336+ disabling this feature on the haproxy host.
51337+
51338+ If the sysctl option is enabled, two sysctl options with names
51339+ "ip_blackhole" and "lastack_retries" will be created.
51340+ While "ip_blackhole" takes the standard zero/non-zero on/off
51341+ toggle, "lastack_retries" uses the same kinds of values as
51342+ "tcp_retries1" and "tcp_retries2". The default value of 4
51343+ prevents a socket from lasting more than 45 seconds in LAST_ACK
51344+ state.
51345+
51346+config GRKERNSEC_SOCKET
51347+ bool "Socket restrictions"
51348+ depends on NET
51349+ help
51350+ If you say Y here, you will be able to choose from several options.
51351+ If you assign a GID on your system and add it to the supplementary
51352+ groups of users you want to restrict socket access to, this patch
51353+ will perform up to three things, based on the option(s) you choose.
51354+
51355+config GRKERNSEC_SOCKET_ALL
51356+ bool "Deny any sockets to group"
51357+ depends on GRKERNSEC_SOCKET
51358+ help
51359+ If you say Y here, you will be able to choose a GID of whose users will
51360+ be unable to connect to other hosts from your machine or run server
51361+ applications from your machine. If the sysctl option is enabled, a
51362+ sysctl option with name "socket_all" is created.
51363+
51364+config GRKERNSEC_SOCKET_ALL_GID
51365+ int "GID to deny all sockets for"
51366+ depends on GRKERNSEC_SOCKET_ALL
51367+ default 1004
51368+ help
51369+ Here you can choose the GID to disable socket access for. Remember to
51370+ add the users you want socket access disabled for to the GID
51371+ specified here. If the sysctl option is enabled, a sysctl option
51372+ with name "socket_all_gid" is created.
51373+
51374+config GRKERNSEC_SOCKET_CLIENT
51375+ bool "Deny client sockets to group"
51376+ depends on GRKERNSEC_SOCKET
51377+ help
51378+ If you say Y here, you will be able to choose a GID of whose users will
51379+ be unable to connect to other hosts from your machine, but will be
51380+ able to run servers. If this option is enabled, all users in the group
51381+ you specify will have to use passive mode when initiating ftp transfers
51382+ from the shell on your machine. If the sysctl option is enabled, a
51383+ sysctl option with name "socket_client" is created.
51384+
51385+config GRKERNSEC_SOCKET_CLIENT_GID
51386+ int "GID to deny client sockets for"
51387+ depends on GRKERNSEC_SOCKET_CLIENT
51388+ default 1003
51389+ help
51390+ Here you can choose the GID to disable client socket access for.
51391+ Remember to add the users you want client socket access disabled for to
51392+ the GID specified here. If the sysctl option is enabled, a sysctl
51393+ option with name "socket_client_gid" is created.
51394+
51395+config GRKERNSEC_SOCKET_SERVER
51396+ bool "Deny server sockets to group"
51397+ depends on GRKERNSEC_SOCKET
51398+ help
51399+ If you say Y here, you will be able to choose a GID of whose users will
51400+ be unable to run server applications from your machine. If the sysctl
51401+ option is enabled, a sysctl option with name "socket_server" is created.
51402+
51403+config GRKERNSEC_SOCKET_SERVER_GID
51404+ int "GID to deny server sockets for"
51405+ depends on GRKERNSEC_SOCKET_SERVER
51406+ default 1002
51407+ help
51408+ Here you can choose the GID to disable server socket access for.
51409+ Remember to add the users you want server socket access disabled for to
51410+ the GID specified here. If the sysctl option is enabled, a sysctl
51411+ option with name "socket_server_gid" is created.
51412+
51413+endmenu
51414+menu "Sysctl Support"
51415+depends on GRKERNSEC && SYSCTL
51416+
51417+config GRKERNSEC_SYSCTL
51418+ bool "Sysctl support"
51419+ default y if GRKERNSEC_CONFIG_AUTO
51420+ help
51421+ If you say Y here, you will be able to change the options that
51422+ grsecurity runs with at bootup, without having to recompile your
51423+ kernel. You can echo values to files in /proc/sys/kernel/grsecurity
51424+ to enable (1) or disable (0) various features. All the sysctl entries
51425+ are mutable until the "grsec_lock" entry is set to a non-zero value.
51426+ All features enabled in the kernel configuration are disabled at boot
51427+ if you do not say Y to the "Turn on features by default" option.
51428+ All options should be set at startup, and the grsec_lock entry should
51429+ be set to a non-zero value after all the options are set.
51430+ *THIS IS EXTREMELY IMPORTANT*
51431+
51432+config GRKERNSEC_SYSCTL_DISTRO
51433+ bool "Extra sysctl support for distro makers (READ HELP)"
51434+ depends on GRKERNSEC_SYSCTL && GRKERNSEC_IO
51435+ help
51436+ If you say Y here, additional sysctl options will be created
51437+ for features that affect processes running as root. Therefore,
51438+ it is critical when using this option that the grsec_lock entry be
51439+ enabled after boot. Only distros with prebuilt kernel packages
51440+ with this option enabled that can ensure grsec_lock is enabled
51441+ after boot should use this option.
51442+ *Failure to set grsec_lock after boot makes all grsec features
51443+ this option covers useless*
51444+
51445+ Currently this option creates the following sysctl entries:
51446+ "Disable Privileged I/O": "disable_priv_io"
51447+
51448+config GRKERNSEC_SYSCTL_ON
51449+ bool "Turn on features by default"
51450+ default y if GRKERNSEC_CONFIG_AUTO
51451+ depends on GRKERNSEC_SYSCTL
51452+ help
51453+ If you say Y here, instead of having all features enabled in the
51454+ kernel configuration disabled at boot time, the features will be
51455+ enabled at boot time. It is recommended you say Y here unless
51456+ there is some reason you would want all sysctl-tunable features to
51457+ be disabled by default. As mentioned elsewhere, it is important
51458+ to enable the grsec_lock entry once you have finished modifying
51459+ the sysctl entries.
51460+
51461+endmenu
51462+menu "Logging Options"
51463+depends on GRKERNSEC
51464+
51465+config GRKERNSEC_FLOODTIME
51466+ int "Seconds in between log messages (minimum)"
51467+ default 10
51468+ help
51469+ This option allows you to enforce the number of seconds between
51470+ grsecurity log messages. The default should be suitable for most
51471+ people, however, if you choose to change it, choose a value small enough
51472+ to allow informative logs to be produced, but large enough to
51473+ prevent flooding.
51474+
51475+config GRKERNSEC_FLOODBURST
51476+ int "Number of messages in a burst (maximum)"
51477+ default 6
51478+ help
51479+ This option allows you to choose the maximum number of messages allowed
51480+ within the flood time interval you chose in a separate option. The
51481+ default should be suitable for most people, however if you find that
51482+ many of your logs are being interpreted as flooding, you may want to
51483+ raise this value.
51484+
51485+endmenu
51486diff --git a/grsecurity/Makefile b/grsecurity/Makefile
51487new file mode 100644
51488index 0000000..1b9afa9
51489--- /dev/null
51490+++ b/grsecurity/Makefile
51491@@ -0,0 +1,38 @@
51492+# grsecurity's ACL system was originally written in 2001 by Michael Dalton
51493+# during 2001-2009 it has been completely redesigned by Brad Spengler
51494+# into an RBAC system
51495+#
51496+# All code in this directory and various hooks inserted throughout the kernel
51497+# are copyright Brad Spengler - Open Source Security, Inc., and released
51498+# under the GPL v2 or higher
51499+
51500+KBUILD_CFLAGS += -Werror
51501+
51502+obj-y = grsec_chdir.o grsec_chroot.o grsec_exec.o grsec_fifo.o grsec_fork.o \
51503+ grsec_mount.o grsec_sig.o grsec_sysctl.o \
51504+ grsec_time.o grsec_tpe.o grsec_link.o grsec_pax.o grsec_ptrace.o
51505+
51506+obj-$(CONFIG_GRKERNSEC) += grsec_init.o grsum.o gracl.o gracl_segv.o \
51507+ gracl_cap.o gracl_alloc.o gracl_shm.o grsec_mem.o gracl_fs.o \
51508+ gracl_learn.o grsec_log.o
51509+obj-$(CONFIG_GRKERNSEC_RESLOG) += gracl_res.o
51510+
51511+ifdef CONFIG_NET
51512+obj-y += grsec_sock.o
51513+obj-$(CONFIG_GRKERNSEC) += gracl_ip.o
51514+endif
51515+
51516+ifndef CONFIG_GRKERNSEC
51517+obj-y += grsec_disabled.o
51518+endif
51519+
51520+ifdef CONFIG_GRKERNSEC_HIDESYM
51521+extra-y := grsec_hidesym.o
51522+$(obj)/grsec_hidesym.o:
51523+ @-chmod -f 500 /boot
51524+ @-chmod -f 500 /lib/modules
51525+ @-chmod -f 500 /lib64/modules
51526+ @-chmod -f 500 /lib32/modules
51527+ @-chmod -f 700 .
51528+ @echo ' grsec: protected kernel image paths'
51529+endif
51530diff --git a/grsecurity/gracl.c b/grsecurity/gracl.c
51531new file mode 100644
51532index 0000000..3d58260
51533--- /dev/null
51534+++ b/grsecurity/gracl.c
51535@@ -0,0 +1,4029 @@
51536+#include <linux/kernel.h>
51537+#include <linux/module.h>
51538+#include <linux/sched.h>
51539+#include <linux/mm.h>
51540+#include <linux/file.h>
51541+#include <linux/fs.h>
51542+#include <linux/namei.h>
51543+#include <linux/mount.h>
51544+#include <linux/tty.h>
51545+#include <linux/proc_fs.h>
51546+#include <linux/lglock.h>
51547+#include <linux/slab.h>
51548+#include <linux/vmalloc.h>
51549+#include <linux/types.h>
51550+#include <linux/sysctl.h>
51551+#include <linux/netdevice.h>
51552+#include <linux/ptrace.h>
51553+#include <linux/gracl.h>
51554+#include <linux/gralloc.h>
51555+#include <linux/security.h>
51556+#include <linux/grinternal.h>
51557+#include <linux/pid_namespace.h>
51558+#include <linux/stop_machine.h>
51559+#include <linux/fdtable.h>
51560+#include <linux/percpu.h>
51561+#include <linux/lglock.h>
51562+#include "../fs/mount.h"
51563+
51564+#include <asm/uaccess.h>
51565+#include <asm/errno.h>
51566+#include <asm/mman.h>
51567+
51568+extern struct lglock vfsmount_lock;
51569+
51570+static struct acl_role_db acl_role_set;
51571+static struct name_db name_set;
51572+static struct inodev_db inodev_set;
51573+
51574+/* for keeping track of userspace pointers used for subjects, so we
51575+ can share references in the kernel as well
51576+*/
51577+
51578+static struct path real_root;
51579+
51580+static struct acl_subj_map_db subj_map_set;
51581+
51582+static struct acl_role_label *default_role;
51583+
51584+static struct acl_role_label *role_list;
51585+
51586+static u16 acl_sp_role_value;
51587+
51588+extern char *gr_shared_page[4];
51589+static DEFINE_MUTEX(gr_dev_mutex);
51590+DEFINE_RWLOCK(gr_inode_lock);
51591+
51592+struct gr_arg *gr_usermode;
51593+
51594+static unsigned int gr_status __read_only = GR_STATUS_INIT;
51595+
51596+extern int chkpw(struct gr_arg *entry, unsigned char *salt, unsigned char *sum);
51597+extern void gr_clear_learn_entries(void);
51598+
51599+#ifdef CONFIG_GRKERNSEC_RESLOG
51600+extern void gr_log_resource(const struct task_struct *task,
51601+ const int res, const unsigned long wanted, const int gt);
51602+#endif
51603+
51604+unsigned char *gr_system_salt;
51605+unsigned char *gr_system_sum;
51606+
51607+static struct sprole_pw **acl_special_roles = NULL;
51608+static __u16 num_sprole_pws = 0;
51609+
51610+static struct acl_role_label *kernel_role = NULL;
51611+
51612+static unsigned int gr_auth_attempts = 0;
51613+static unsigned long gr_auth_expires = 0UL;
51614+
51615+#ifdef CONFIG_NET
51616+extern struct vfsmount *sock_mnt;
51617+#endif
51618+
51619+extern struct vfsmount *pipe_mnt;
51620+extern struct vfsmount *shm_mnt;
51621+#ifdef CONFIG_HUGETLBFS
51622+extern struct vfsmount *hugetlbfs_vfsmount;
51623+#endif
51624+
51625+static struct acl_object_label *fakefs_obj_rw;
51626+static struct acl_object_label *fakefs_obj_rwx;
51627+
51628+extern int gr_init_uidset(void);
51629+extern void gr_free_uidset(void);
51630+extern void gr_remove_uid(uid_t uid);
51631+extern int gr_find_uid(uid_t uid);
51632+
51633+__inline__ int
51634+gr_acl_is_enabled(void)
51635+{
51636+ return (gr_status & GR_READY);
51637+}
51638+
51639+#ifdef CONFIG_BTRFS_FS
51640+extern dev_t get_btrfs_dev_from_inode(struct inode *inode);
51641+extern int btrfs_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat);
51642+#endif
51643+
51644+static inline dev_t __get_dev(const struct dentry *dentry)
51645+{
51646+#ifdef CONFIG_BTRFS_FS
51647+ if (dentry->d_inode->i_op && dentry->d_inode->i_op->getattr == &btrfs_getattr)
51648+ return get_btrfs_dev_from_inode(dentry->d_inode);
51649+ else
51650+#endif
51651+ return dentry->d_inode->i_sb->s_dev;
51652+}
51653+
51654+dev_t gr_get_dev_from_dentry(struct dentry *dentry)
51655+{
51656+ return __get_dev(dentry);
51657+}
51658+
51659+static char gr_task_roletype_to_char(struct task_struct *task)
51660+{
51661+ switch (task->role->roletype &
51662+ (GR_ROLE_DEFAULT | GR_ROLE_USER | GR_ROLE_GROUP |
51663+ GR_ROLE_SPECIAL)) {
51664+ case GR_ROLE_DEFAULT:
51665+ return 'D';
51666+ case GR_ROLE_USER:
51667+ return 'U';
51668+ case GR_ROLE_GROUP:
51669+ return 'G';
51670+ case GR_ROLE_SPECIAL:
51671+ return 'S';
51672+ }
51673+
51674+ return 'X';
51675+}
51676+
51677+char gr_roletype_to_char(void)
51678+{
51679+ return gr_task_roletype_to_char(current);
51680+}
51681+
51682+__inline__ int
51683+gr_acl_tpe_check(void)
51684+{
51685+ if (unlikely(!(gr_status & GR_READY)))
51686+ return 0;
51687+ if (current->role->roletype & GR_ROLE_TPE)
51688+ return 1;
51689+ else
51690+ return 0;
51691+}
51692+
51693+int
51694+gr_handle_rawio(const struct inode *inode)
51695+{
51696+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
51697+ if (inode && S_ISBLK(inode->i_mode) &&
51698+ grsec_enable_chroot_caps && proc_is_chrooted(current) &&
51699+ !capable(CAP_SYS_RAWIO))
51700+ return 1;
51701+#endif
51702+ return 0;
51703+}
51704+
51705+static int
51706+gr_streq(const char *a, const char *b, const unsigned int lena, const unsigned int lenb)
51707+{
51708+ if (likely(lena != lenb))
51709+ return 0;
51710+
51711+ return !memcmp(a, b, lena);
51712+}
51713+
51714+static int prepend(char **buffer, int *buflen, const char *str, int namelen)
51715+{
51716+ *buflen -= namelen;
51717+ if (*buflen < 0)
51718+ return -ENAMETOOLONG;
51719+ *buffer -= namelen;
51720+ memcpy(*buffer, str, namelen);
51721+ return 0;
51722+}
51723+
51724+static int prepend_name(char **buffer, int *buflen, struct qstr *name)
51725+{
51726+ return prepend(buffer, buflen, name->name, name->len);
51727+}
51728+
51729+static int prepend_path(const struct path *path, struct path *root,
51730+ char **buffer, int *buflen)
51731+{
51732+ struct dentry *dentry = path->dentry;
51733+ struct vfsmount *vfsmnt = path->mnt;
51734+ struct mount *mnt = real_mount(vfsmnt);
51735+ bool slash = false;
51736+ int error = 0;
51737+
51738+ while (dentry != root->dentry || vfsmnt != root->mnt) {
51739+ struct dentry * parent;
51740+
51741+ if (dentry == vfsmnt->mnt_root || IS_ROOT(dentry)) {
51742+ /* Global root? */
51743+ if (!mnt_has_parent(mnt)) {
51744+ goto out;
51745+ }
51746+ dentry = mnt->mnt_mountpoint;
51747+ mnt = mnt->mnt_parent;
51748+ vfsmnt = &mnt->mnt;
51749+ continue;
51750+ }
51751+ parent = dentry->d_parent;
51752+ prefetch(parent);
51753+ spin_lock(&dentry->d_lock);
51754+ error = prepend_name(buffer, buflen, &dentry->d_name);
51755+ spin_unlock(&dentry->d_lock);
51756+ if (!error)
51757+ error = prepend(buffer, buflen, "/", 1);
51758+ if (error)
51759+ break;
51760+
51761+ slash = true;
51762+ dentry = parent;
51763+ }
51764+
51765+out:
51766+ if (!error && !slash)
51767+ error = prepend(buffer, buflen, "/", 1);
51768+
51769+ return error;
51770+}
51771+
51772+/* this must be called with vfsmount_lock and rename_lock held */
51773+
51774+static char *__our_d_path(const struct path *path, struct path *root,
51775+ char *buf, int buflen)
51776+{
51777+ char *res = buf + buflen;
51778+ int error;
51779+
51780+ prepend(&res, &buflen, "\0", 1);
51781+ error = prepend_path(path, root, &res, &buflen);
51782+ if (error)
51783+ return ERR_PTR(error);
51784+
51785+ return res;
51786+}
51787+
51788+static char *
51789+gen_full_path(struct path *path, struct path *root, char *buf, int buflen)
51790+{
51791+ char *retval;
51792+
51793+ retval = __our_d_path(path, root, buf, buflen);
51794+ if (unlikely(IS_ERR(retval)))
51795+ retval = strcpy(buf, "<path too long>");
51796+ else if (unlikely(retval[1] == '/' && retval[2] == '\0'))
51797+ retval[1] = '\0';
51798+
51799+ return retval;
51800+}
51801+
51802+static char *
51803+__d_real_path(const struct dentry *dentry, const struct vfsmount *vfsmnt,
51804+ char *buf, int buflen)
51805+{
51806+ struct path path;
51807+ char *res;
51808+
51809+ path.dentry = (struct dentry *)dentry;
51810+ path.mnt = (struct vfsmount *)vfsmnt;
51811+
51812+ /* we can use real_root.dentry, real_root.mnt, because this is only called
51813+ by the RBAC system */
51814+ res = gen_full_path(&path, &real_root, buf, buflen);
51815+
51816+ return res;
51817+}
51818+
51819+static char *
51820+d_real_path(const struct dentry *dentry, const struct vfsmount *vfsmnt,
51821+ char *buf, int buflen)
51822+{
51823+ char *res;
51824+ struct path path;
51825+ struct path root;
51826+ struct task_struct *reaper = init_pid_ns.child_reaper;
51827+
51828+ path.dentry = (struct dentry *)dentry;
51829+ path.mnt = (struct vfsmount *)vfsmnt;
51830+
51831+ /* we can't use real_root.dentry, real_root.mnt, because they belong only to the RBAC system */
51832+ get_fs_root(reaper->fs, &root);
51833+
51834+ write_seqlock(&rename_lock);
51835+ br_read_lock(&vfsmount_lock);
51836+ res = gen_full_path(&path, &root, buf, buflen);
51837+ br_read_unlock(&vfsmount_lock);
51838+ write_sequnlock(&rename_lock);
51839+
51840+ path_put(&root);
51841+ return res;
51842+}
51843+
51844+static char *
51845+gr_to_filename_rbac(const struct dentry *dentry, const struct vfsmount *mnt)
51846+{
51847+ char *ret;
51848+ write_seqlock(&rename_lock);
51849+ br_read_lock(&vfsmount_lock);
51850+ ret = __d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0],smp_processor_id()),
51851+ PAGE_SIZE);
51852+ br_read_unlock(&vfsmount_lock);
51853+ write_sequnlock(&rename_lock);
51854+ return ret;
51855+}
51856+
51857+static char *
51858+gr_to_proc_filename_rbac(const struct dentry *dentry, const struct vfsmount *mnt)
51859+{
51860+ char *ret;
51861+ char *buf;
51862+ int buflen;
51863+
51864+ write_seqlock(&rename_lock);
51865+ br_read_lock(&vfsmount_lock);
51866+ buf = per_cpu_ptr(gr_shared_page[0], smp_processor_id());
51867+ ret = __d_real_path(dentry, mnt, buf, PAGE_SIZE - 6);
51868+ buflen = (int)(ret - buf);
51869+ if (buflen >= 5)
51870+ prepend(&ret, &buflen, "/proc", 5);
51871+ else
51872+ ret = strcpy(buf, "<path too long>");
51873+ br_read_unlock(&vfsmount_lock);
51874+ write_sequnlock(&rename_lock);
51875+ return ret;
51876+}
51877+
51878+char *
51879+gr_to_filename_nolock(const struct dentry *dentry, const struct vfsmount *mnt)
51880+{
51881+ return __d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0],smp_processor_id()),
51882+ PAGE_SIZE);
51883+}
51884+
51885+char *
51886+gr_to_filename(const struct dentry *dentry, const struct vfsmount *mnt)
51887+{
51888+ return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0], smp_processor_id()),
51889+ PAGE_SIZE);
51890+}
51891+
51892+char *
51893+gr_to_filename1(const struct dentry *dentry, const struct vfsmount *mnt)
51894+{
51895+ return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[1], smp_processor_id()),
51896+ PAGE_SIZE);
51897+}
51898+
51899+char *
51900+gr_to_filename2(const struct dentry *dentry, const struct vfsmount *mnt)
51901+{
51902+ return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[2], smp_processor_id()),
51903+ PAGE_SIZE);
51904+}
51905+
51906+char *
51907+gr_to_filename3(const struct dentry *dentry, const struct vfsmount *mnt)
51908+{
51909+ return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[3], smp_processor_id()),
51910+ PAGE_SIZE);
51911+}
51912+
51913+__inline__ __u32
51914+to_gr_audit(const __u32 reqmode)
51915+{
51916+ /* masks off auditable permission flags, then shifts them to create
51917+ auditing flags, and adds the special case of append auditing if
51918+ we're requesting write */
51919+ return (((reqmode & ~GR_AUDITS) << 10) | ((reqmode & GR_WRITE) ? GR_AUDIT_APPEND : 0));
51920+}
51921+
51922+struct acl_subject_label *
51923+lookup_subject_map(const struct acl_subject_label *userp)
51924+{
51925+ unsigned int index = shash(userp, subj_map_set.s_size);
51926+ struct subject_map *match;
51927+
51928+ match = subj_map_set.s_hash[index];
51929+
51930+ while (match && match->user != userp)
51931+ match = match->next;
51932+
51933+ if (match != NULL)
51934+ return match->kernel;
51935+ else
51936+ return NULL;
51937+}
51938+
51939+static void
51940+insert_subj_map_entry(struct subject_map *subjmap)
51941+{
51942+ unsigned int index = shash(subjmap->user, subj_map_set.s_size);
51943+ struct subject_map **curr;
51944+
51945+ subjmap->prev = NULL;
51946+
51947+ curr = &subj_map_set.s_hash[index];
51948+ if (*curr != NULL)
51949+ (*curr)->prev = subjmap;
51950+
51951+ subjmap->next = *curr;
51952+ *curr = subjmap;
51953+
51954+ return;
51955+}
51956+
51957+static struct acl_role_label *
51958+lookup_acl_role_label(const struct task_struct *task, const uid_t uid,
51959+ const gid_t gid)
51960+{
51961+ unsigned int index = rhash(uid, GR_ROLE_USER, acl_role_set.r_size);
51962+ struct acl_role_label *match;
51963+ struct role_allowed_ip *ipp;
51964+ unsigned int x;
51965+ u32 curr_ip = task->signal->curr_ip;
51966+
51967+ task->signal->saved_ip = curr_ip;
51968+
51969+ match = acl_role_set.r_hash[index];
51970+
51971+ while (match) {
51972+ if ((match->roletype & (GR_ROLE_DOMAIN | GR_ROLE_USER)) == (GR_ROLE_DOMAIN | GR_ROLE_USER)) {
51973+ for (x = 0; x < match->domain_child_num; x++) {
51974+ if (match->domain_children[x] == uid)
51975+ goto found;
51976+ }
51977+ } else if (match->uidgid == uid && match->roletype & GR_ROLE_USER)
51978+ break;
51979+ match = match->next;
51980+ }
51981+found:
51982+ if (match == NULL) {
51983+ try_group:
51984+ index = rhash(gid, GR_ROLE_GROUP, acl_role_set.r_size);
51985+ match = acl_role_set.r_hash[index];
51986+
51987+ while (match) {
51988+ if ((match->roletype & (GR_ROLE_DOMAIN | GR_ROLE_GROUP)) == (GR_ROLE_DOMAIN | GR_ROLE_GROUP)) {
51989+ for (x = 0; x < match->domain_child_num; x++) {
51990+ if (match->domain_children[x] == gid)
51991+ goto found2;
51992+ }
51993+ } else if (match->uidgid == gid && match->roletype & GR_ROLE_GROUP)
51994+ break;
51995+ match = match->next;
51996+ }
51997+found2:
51998+ if (match == NULL)
51999+ match = default_role;
52000+ if (match->allowed_ips == NULL)
52001+ return match;
52002+ else {
52003+ for (ipp = match->allowed_ips; ipp; ipp = ipp->next) {
52004+ if (likely
52005+ ((ntohl(curr_ip) & ipp->netmask) ==
52006+ (ntohl(ipp->addr) & ipp->netmask)))
52007+ return match;
52008+ }
52009+ match = default_role;
52010+ }
52011+ } else if (match->allowed_ips == NULL) {
52012+ return match;
52013+ } else {
52014+ for (ipp = match->allowed_ips; ipp; ipp = ipp->next) {
52015+ if (likely
52016+ ((ntohl(curr_ip) & ipp->netmask) ==
52017+ (ntohl(ipp->addr) & ipp->netmask)))
52018+ return match;
52019+ }
52020+ goto try_group;
52021+ }
52022+
52023+ return match;
52024+}
52025+
52026+struct acl_subject_label *
52027+lookup_acl_subj_label(const ino_t ino, const dev_t dev,
52028+ const struct acl_role_label *role)
52029+{
52030+ unsigned int index = fhash(ino, dev, role->subj_hash_size);
52031+ struct acl_subject_label *match;
52032+
52033+ match = role->subj_hash[index];
52034+
52035+ while (match && (match->inode != ino || match->device != dev ||
52036+ (match->mode & GR_DELETED))) {
52037+ match = match->next;
52038+ }
52039+
52040+ if (match && !(match->mode & GR_DELETED))
52041+ return match;
52042+ else
52043+ return NULL;
52044+}
52045+
52046+struct acl_subject_label *
52047+lookup_acl_subj_label_deleted(const ino_t ino, const dev_t dev,
52048+ const struct acl_role_label *role)
52049+{
52050+ unsigned int index = fhash(ino, dev, role->subj_hash_size);
52051+ struct acl_subject_label *match;
52052+
52053+ match = role->subj_hash[index];
52054+
52055+ while (match && (match->inode != ino || match->device != dev ||
52056+ !(match->mode & GR_DELETED))) {
52057+ match = match->next;
52058+ }
52059+
52060+ if (match && (match->mode & GR_DELETED))
52061+ return match;
52062+ else
52063+ return NULL;
52064+}
52065+
52066+static struct acl_object_label *
52067+lookup_acl_obj_label(const ino_t ino, const dev_t dev,
52068+ const struct acl_subject_label *subj)
52069+{
52070+ unsigned int index = fhash(ino, dev, subj->obj_hash_size);
52071+ struct acl_object_label *match;
52072+
52073+ match = subj->obj_hash[index];
52074+
52075+ while (match && (match->inode != ino || match->device != dev ||
52076+ (match->mode & GR_DELETED))) {
52077+ match = match->next;
52078+ }
52079+
52080+ if (match && !(match->mode & GR_DELETED))
52081+ return match;
52082+ else
52083+ return NULL;
52084+}
52085+
52086+static struct acl_object_label *
52087+lookup_acl_obj_label_create(const ino_t ino, const dev_t dev,
52088+ const struct acl_subject_label *subj)
52089+{
52090+ unsigned int index = fhash(ino, dev, subj->obj_hash_size);
52091+ struct acl_object_label *match;
52092+
52093+ match = subj->obj_hash[index];
52094+
52095+ while (match && (match->inode != ino || match->device != dev ||
52096+ !(match->mode & GR_DELETED))) {
52097+ match = match->next;
52098+ }
52099+
52100+ if (match && (match->mode & GR_DELETED))
52101+ return match;
52102+
52103+ match = subj->obj_hash[index];
52104+
52105+ while (match && (match->inode != ino || match->device != dev ||
52106+ (match->mode & GR_DELETED))) {
52107+ match = match->next;
52108+ }
52109+
52110+ if (match && !(match->mode & GR_DELETED))
52111+ return match;
52112+ else
52113+ return NULL;
52114+}
52115+
52116+static struct name_entry *
52117+lookup_name_entry(const char *name)
52118+{
52119+ unsigned int len = strlen(name);
52120+ unsigned int key = full_name_hash(name, len);
52121+ unsigned int index = key % name_set.n_size;
52122+ struct name_entry *match;
52123+
52124+ match = name_set.n_hash[index];
52125+
52126+ while (match && (match->key != key || !gr_streq(match->name, name, match->len, len)))
52127+ match = match->next;
52128+
52129+ return match;
52130+}
52131+
52132+static struct name_entry *
52133+lookup_name_entry_create(const char *name)
52134+{
52135+ unsigned int len = strlen(name);
52136+ unsigned int key = full_name_hash(name, len);
52137+ unsigned int index = key % name_set.n_size;
52138+ struct name_entry *match;
52139+
52140+ match = name_set.n_hash[index];
52141+
52142+ while (match && (match->key != key || !gr_streq(match->name, name, match->len, len) ||
52143+ !match->deleted))
52144+ match = match->next;
52145+
52146+ if (match && match->deleted)
52147+ return 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->deleted))
52153+ match = match->next;
52154+
52155+ if (match && !match->deleted)
52156+ return match;
52157+ else
52158+ return NULL;
52159+}
52160+
52161+static struct inodev_entry *
52162+lookup_inodev_entry(const ino_t ino, const dev_t dev)
52163+{
52164+ unsigned int index = fhash(ino, dev, inodev_set.i_size);
52165+ struct inodev_entry *match;
52166+
52167+ match = inodev_set.i_hash[index];
52168+
52169+ while (match && (match->nentry->inode != ino || match->nentry->device != dev))
52170+ match = match->next;
52171+
52172+ return match;
52173+}
52174+
52175+static void
52176+insert_inodev_entry(struct inodev_entry *entry)
52177+{
52178+ unsigned int index = fhash(entry->nentry->inode, entry->nentry->device,
52179+ inodev_set.i_size);
52180+ struct inodev_entry **curr;
52181+
52182+ entry->prev = NULL;
52183+
52184+ curr = &inodev_set.i_hash[index];
52185+ if (*curr != NULL)
52186+ (*curr)->prev = entry;
52187+
52188+ entry->next = *curr;
52189+ *curr = entry;
52190+
52191+ return;
52192+}
52193+
52194+static void
52195+__insert_acl_role_label(struct acl_role_label *role, uid_t uidgid)
52196+{
52197+ unsigned int index =
52198+ rhash(uidgid, role->roletype & (GR_ROLE_USER | GR_ROLE_GROUP), acl_role_set.r_size);
52199+ struct acl_role_label **curr;
52200+ struct acl_role_label *tmp, *tmp2;
52201+
52202+ curr = &acl_role_set.r_hash[index];
52203+
52204+ /* simple case, slot is empty, just set it to our role */
52205+ if (*curr == NULL) {
52206+ *curr = role;
52207+ } else {
52208+ /* example:
52209+ 1 -> 2 -> 3 (adding 2 -> 3 to here)
52210+ 2 -> 3
52211+ */
52212+ /* first check to see if we can already be reached via this slot */
52213+ tmp = *curr;
52214+ while (tmp && tmp != role)
52215+ tmp = tmp->next;
52216+ if (tmp == role) {
52217+ /* we don't need to add ourselves to this slot's chain */
52218+ return;
52219+ }
52220+ /* we need to add ourselves to this chain, two cases */
52221+ if (role->next == NULL) {
52222+ /* simple case, append the current chain to our role */
52223+ role->next = *curr;
52224+ *curr = role;
52225+ } else {
52226+ /* 1 -> 2 -> 3 -> 4
52227+ 2 -> 3 -> 4
52228+ 3 -> 4 (adding 1 -> 2 -> 3 -> 4 to here)
52229+ */
52230+ /* trickier case: walk our role's chain until we find
52231+ the role for the start of the current slot's chain */
52232+ tmp = role;
52233+ tmp2 = *curr;
52234+ while (tmp->next && tmp->next != tmp2)
52235+ tmp = tmp->next;
52236+ if (tmp->next == tmp2) {
52237+ /* from example above, we found 3, so just
52238+ replace this slot's chain with ours */
52239+ *curr = role;
52240+ } else {
52241+ /* we didn't find a subset of our role's chain
52242+ in the current slot's chain, so append their
52243+ chain to ours, and set us as the first role in
52244+ the slot's chain
52245+
52246+ we could fold this case with the case above,
52247+ but making it explicit for clarity
52248+ */
52249+ tmp->next = tmp2;
52250+ *curr = role;
52251+ }
52252+ }
52253+ }
52254+
52255+ return;
52256+}
52257+
52258+static void
52259+insert_acl_role_label(struct acl_role_label *role)
52260+{
52261+ int i;
52262+
52263+ if (role_list == NULL) {
52264+ role_list = role;
52265+ role->prev = NULL;
52266+ } else {
52267+ role->prev = role_list;
52268+ role_list = role;
52269+ }
52270+
52271+ /* used for hash chains */
52272+ role->next = NULL;
52273+
52274+ if (role->roletype & GR_ROLE_DOMAIN) {
52275+ for (i = 0; i < role->domain_child_num; i++)
52276+ __insert_acl_role_label(role, role->domain_children[i]);
52277+ } else
52278+ __insert_acl_role_label(role, role->uidgid);
52279+}
52280+
52281+static int
52282+insert_name_entry(char *name, const ino_t inode, const dev_t device, __u8 deleted)
52283+{
52284+ struct name_entry **curr, *nentry;
52285+ struct inodev_entry *ientry;
52286+ unsigned int len = strlen(name);
52287+ unsigned int key = full_name_hash(name, len);
52288+ unsigned int index = key % name_set.n_size;
52289+
52290+ curr = &name_set.n_hash[index];
52291+
52292+ while (*curr && ((*curr)->key != key || !gr_streq((*curr)->name, name, (*curr)->len, len)))
52293+ curr = &((*curr)->next);
52294+
52295+ if (*curr != NULL)
52296+ return 1;
52297+
52298+ nentry = acl_alloc(sizeof (struct name_entry));
52299+ if (nentry == NULL)
52300+ return 0;
52301+ ientry = acl_alloc(sizeof (struct inodev_entry));
52302+ if (ientry == NULL)
52303+ return 0;
52304+ ientry->nentry = nentry;
52305+
52306+ nentry->key = key;
52307+ nentry->name = name;
52308+ nentry->inode = inode;
52309+ nentry->device = device;
52310+ nentry->len = len;
52311+ nentry->deleted = deleted;
52312+
52313+ nentry->prev = NULL;
52314+ curr = &name_set.n_hash[index];
52315+ if (*curr != NULL)
52316+ (*curr)->prev = nentry;
52317+ nentry->next = *curr;
52318+ *curr = nentry;
52319+
52320+ /* insert us into the table searchable by inode/dev */
52321+ insert_inodev_entry(ientry);
52322+
52323+ return 1;
52324+}
52325+
52326+static void
52327+insert_acl_obj_label(struct acl_object_label *obj,
52328+ struct acl_subject_label *subj)
52329+{
52330+ unsigned int index =
52331+ fhash(obj->inode, obj->device, subj->obj_hash_size);
52332+ struct acl_object_label **curr;
52333+
52334+
52335+ obj->prev = NULL;
52336+
52337+ curr = &subj->obj_hash[index];
52338+ if (*curr != NULL)
52339+ (*curr)->prev = obj;
52340+
52341+ obj->next = *curr;
52342+ *curr = obj;
52343+
52344+ return;
52345+}
52346+
52347+static void
52348+insert_acl_subj_label(struct acl_subject_label *obj,
52349+ struct acl_role_label *role)
52350+{
52351+ unsigned int index = fhash(obj->inode, obj->device, role->subj_hash_size);
52352+ struct acl_subject_label **curr;
52353+
52354+ obj->prev = NULL;
52355+
52356+ curr = &role->subj_hash[index];
52357+ if (*curr != NULL)
52358+ (*curr)->prev = obj;
52359+
52360+ obj->next = *curr;
52361+ *curr = obj;
52362+
52363+ return;
52364+}
52365+
52366+/* allocating chained hash tables, so optimal size is where lambda ~ 1 */
52367+
52368+static void *
52369+create_table(__u32 * len, int elementsize)
52370+{
52371+ unsigned int table_sizes[] = {
52372+ 7, 13, 31, 61, 127, 251, 509, 1021, 2039, 4093, 8191, 16381,
52373+ 32749, 65521, 131071, 262139, 524287, 1048573, 2097143,
52374+ 4194301, 8388593, 16777213, 33554393, 67108859
52375+ };
52376+ void *newtable = NULL;
52377+ unsigned int pwr = 0;
52378+
52379+ while ((pwr < ((sizeof (table_sizes) / sizeof (table_sizes[0])) - 1)) &&
52380+ table_sizes[pwr] <= *len)
52381+ pwr++;
52382+
52383+ if (table_sizes[pwr] <= *len || (table_sizes[pwr] > ULONG_MAX / elementsize))
52384+ return newtable;
52385+
52386+ if ((table_sizes[pwr] * elementsize) <= PAGE_SIZE)
52387+ newtable =
52388+ kmalloc(table_sizes[pwr] * elementsize, GFP_KERNEL);
52389+ else
52390+ newtable = vmalloc(table_sizes[pwr] * elementsize);
52391+
52392+ *len = table_sizes[pwr];
52393+
52394+ return newtable;
52395+}
52396+
52397+static int
52398+init_variables(const struct gr_arg *arg)
52399+{
52400+ struct task_struct *reaper = init_pid_ns.child_reaper;
52401+ unsigned int stacksize;
52402+
52403+ subj_map_set.s_size = arg->role_db.num_subjects;
52404+ acl_role_set.r_size = arg->role_db.num_roles + arg->role_db.num_domain_children;
52405+ name_set.n_size = arg->role_db.num_objects;
52406+ inodev_set.i_size = arg->role_db.num_objects;
52407+
52408+ if (!subj_map_set.s_size || !acl_role_set.r_size ||
52409+ !name_set.n_size || !inodev_set.i_size)
52410+ return 1;
52411+
52412+ if (!gr_init_uidset())
52413+ return 1;
52414+
52415+ /* set up the stack that holds allocation info */
52416+
52417+ stacksize = arg->role_db.num_pointers + 5;
52418+
52419+ if (!acl_alloc_stack_init(stacksize))
52420+ return 1;
52421+
52422+ /* grab reference for the real root dentry and vfsmount */
52423+ get_fs_root(reaper->fs, &real_root);
52424+
52425+#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
52426+ printk(KERN_ALERT "Obtained real root device=%d, inode=%lu\n", __get_dev(real_root.dentry), real_root.dentry->d_inode->i_ino);
52427+#endif
52428+
52429+ fakefs_obj_rw = acl_alloc(sizeof(struct acl_object_label));
52430+ if (fakefs_obj_rw == NULL)
52431+ return 1;
52432+ fakefs_obj_rw->mode = GR_FIND | GR_READ | GR_WRITE;
52433+
52434+ fakefs_obj_rwx = acl_alloc(sizeof(struct acl_object_label));
52435+ if (fakefs_obj_rwx == NULL)
52436+ return 1;
52437+ fakefs_obj_rwx->mode = GR_FIND | GR_READ | GR_WRITE | GR_EXEC;
52438+
52439+ subj_map_set.s_hash =
52440+ (struct subject_map **) create_table(&subj_map_set.s_size, sizeof(void *));
52441+ acl_role_set.r_hash =
52442+ (struct acl_role_label **) create_table(&acl_role_set.r_size, sizeof(void *));
52443+ name_set.n_hash = (struct name_entry **) create_table(&name_set.n_size, sizeof(void *));
52444+ inodev_set.i_hash =
52445+ (struct inodev_entry **) create_table(&inodev_set.i_size, sizeof(void *));
52446+
52447+ if (!subj_map_set.s_hash || !acl_role_set.r_hash ||
52448+ !name_set.n_hash || !inodev_set.i_hash)
52449+ return 1;
52450+
52451+ memset(subj_map_set.s_hash, 0,
52452+ sizeof(struct subject_map *) * subj_map_set.s_size);
52453+ memset(acl_role_set.r_hash, 0,
52454+ sizeof (struct acl_role_label *) * acl_role_set.r_size);
52455+ memset(name_set.n_hash, 0,
52456+ sizeof (struct name_entry *) * name_set.n_size);
52457+ memset(inodev_set.i_hash, 0,
52458+ sizeof (struct inodev_entry *) * inodev_set.i_size);
52459+
52460+ return 0;
52461+}
52462+
52463+/* free information not needed after startup
52464+ currently contains user->kernel pointer mappings for subjects
52465+*/
52466+
52467+static void
52468+free_init_variables(void)
52469+{
52470+ __u32 i;
52471+
52472+ if (subj_map_set.s_hash) {
52473+ for (i = 0; i < subj_map_set.s_size; i++) {
52474+ if (subj_map_set.s_hash[i]) {
52475+ kfree(subj_map_set.s_hash[i]);
52476+ subj_map_set.s_hash[i] = NULL;
52477+ }
52478+ }
52479+
52480+ if ((subj_map_set.s_size * sizeof (struct subject_map *)) <=
52481+ PAGE_SIZE)
52482+ kfree(subj_map_set.s_hash);
52483+ else
52484+ vfree(subj_map_set.s_hash);
52485+ }
52486+
52487+ return;
52488+}
52489+
52490+static void
52491+free_variables(void)
52492+{
52493+ struct acl_subject_label *s;
52494+ struct acl_role_label *r;
52495+ struct task_struct *task, *task2;
52496+ unsigned int x;
52497+
52498+ gr_clear_learn_entries();
52499+
52500+ read_lock(&tasklist_lock);
52501+ do_each_thread(task2, task) {
52502+ task->acl_sp_role = 0;
52503+ task->acl_role_id = 0;
52504+ task->acl = NULL;
52505+ task->role = NULL;
52506+ } while_each_thread(task2, task);
52507+ read_unlock(&tasklist_lock);
52508+
52509+ /* release the reference to the real root dentry and vfsmount */
52510+ path_put(&real_root);
52511+ memset(&real_root, 0, sizeof(real_root));
52512+
52513+ /* free all object hash tables */
52514+
52515+ FOR_EACH_ROLE_START(r)
52516+ if (r->subj_hash == NULL)
52517+ goto next_role;
52518+ FOR_EACH_SUBJECT_START(r, s, x)
52519+ if (s->obj_hash == NULL)
52520+ break;
52521+ if ((s->obj_hash_size * sizeof (struct acl_object_label *)) <= PAGE_SIZE)
52522+ kfree(s->obj_hash);
52523+ else
52524+ vfree(s->obj_hash);
52525+ FOR_EACH_SUBJECT_END(s, x)
52526+ FOR_EACH_NESTED_SUBJECT_START(r, s)
52527+ if (s->obj_hash == NULL)
52528+ break;
52529+ if ((s->obj_hash_size * sizeof (struct acl_object_label *)) <= PAGE_SIZE)
52530+ kfree(s->obj_hash);
52531+ else
52532+ vfree(s->obj_hash);
52533+ FOR_EACH_NESTED_SUBJECT_END(s)
52534+ if ((r->subj_hash_size * sizeof (struct acl_subject_label *)) <= PAGE_SIZE)
52535+ kfree(r->subj_hash);
52536+ else
52537+ vfree(r->subj_hash);
52538+ r->subj_hash = NULL;
52539+next_role:
52540+ FOR_EACH_ROLE_END(r)
52541+
52542+ acl_free_all();
52543+
52544+ if (acl_role_set.r_hash) {
52545+ if ((acl_role_set.r_size * sizeof (struct acl_role_label *)) <=
52546+ PAGE_SIZE)
52547+ kfree(acl_role_set.r_hash);
52548+ else
52549+ vfree(acl_role_set.r_hash);
52550+ }
52551+ if (name_set.n_hash) {
52552+ if ((name_set.n_size * sizeof (struct name_entry *)) <=
52553+ PAGE_SIZE)
52554+ kfree(name_set.n_hash);
52555+ else
52556+ vfree(name_set.n_hash);
52557+ }
52558+
52559+ if (inodev_set.i_hash) {
52560+ if ((inodev_set.i_size * sizeof (struct inodev_entry *)) <=
52561+ PAGE_SIZE)
52562+ kfree(inodev_set.i_hash);
52563+ else
52564+ vfree(inodev_set.i_hash);
52565+ }
52566+
52567+ gr_free_uidset();
52568+
52569+ memset(&name_set, 0, sizeof (struct name_db));
52570+ memset(&inodev_set, 0, sizeof (struct inodev_db));
52571+ memset(&acl_role_set, 0, sizeof (struct acl_role_db));
52572+ memset(&subj_map_set, 0, sizeof (struct acl_subj_map_db));
52573+
52574+ default_role = NULL;
52575+ kernel_role = NULL;
52576+ role_list = NULL;
52577+
52578+ return;
52579+}
52580+
52581+static __u32
52582+count_user_objs(struct acl_object_label *userp)
52583+{
52584+ struct acl_object_label o_tmp;
52585+ __u32 num = 0;
52586+
52587+ while (userp) {
52588+ if (copy_from_user(&o_tmp, userp,
52589+ sizeof (struct acl_object_label)))
52590+ break;
52591+
52592+ userp = o_tmp.prev;
52593+ num++;
52594+ }
52595+
52596+ return num;
52597+}
52598+
52599+static struct acl_subject_label *
52600+do_copy_user_subj(struct acl_subject_label *userp, struct acl_role_label *role);
52601+
52602+static int
52603+copy_user_glob(struct acl_object_label *obj)
52604+{
52605+ struct acl_object_label *g_tmp, **guser;
52606+ unsigned int len;
52607+ char *tmp;
52608+
52609+ if (obj->globbed == NULL)
52610+ return 0;
52611+
52612+ guser = &obj->globbed;
52613+ while (*guser) {
52614+ g_tmp = (struct acl_object_label *)
52615+ acl_alloc(sizeof (struct acl_object_label));
52616+ if (g_tmp == NULL)
52617+ return -ENOMEM;
52618+
52619+ if (copy_from_user(g_tmp, *guser,
52620+ sizeof (struct acl_object_label)))
52621+ return -EFAULT;
52622+
52623+ len = strnlen_user(g_tmp->filename, PATH_MAX);
52624+
52625+ if (!len || len >= PATH_MAX)
52626+ return -EINVAL;
52627+
52628+ if ((tmp = (char *) acl_alloc(len)) == NULL)
52629+ return -ENOMEM;
52630+
52631+ if (copy_from_user(tmp, g_tmp->filename, len))
52632+ return -EFAULT;
52633+ tmp[len-1] = '\0';
52634+ g_tmp->filename = tmp;
52635+
52636+ *guser = g_tmp;
52637+ guser = &(g_tmp->next);
52638+ }
52639+
52640+ return 0;
52641+}
52642+
52643+static int
52644+copy_user_objs(struct acl_object_label *userp, struct acl_subject_label *subj,
52645+ struct acl_role_label *role)
52646+{
52647+ struct acl_object_label *o_tmp;
52648+ unsigned int len;
52649+ int ret;
52650+ char *tmp;
52651+
52652+ while (userp) {
52653+ if ((o_tmp = (struct acl_object_label *)
52654+ acl_alloc(sizeof (struct acl_object_label))) == NULL)
52655+ return -ENOMEM;
52656+
52657+ if (copy_from_user(o_tmp, userp,
52658+ sizeof (struct acl_object_label)))
52659+ return -EFAULT;
52660+
52661+ userp = o_tmp->prev;
52662+
52663+ len = strnlen_user(o_tmp->filename, PATH_MAX);
52664+
52665+ if (!len || len >= PATH_MAX)
52666+ return -EINVAL;
52667+
52668+ if ((tmp = (char *) acl_alloc(len)) == NULL)
52669+ return -ENOMEM;
52670+
52671+ if (copy_from_user(tmp, o_tmp->filename, len))
52672+ return -EFAULT;
52673+ tmp[len-1] = '\0';
52674+ o_tmp->filename = tmp;
52675+
52676+ insert_acl_obj_label(o_tmp, subj);
52677+ if (!insert_name_entry(o_tmp->filename, o_tmp->inode,
52678+ o_tmp->device, (o_tmp->mode & GR_DELETED) ? 1 : 0))
52679+ return -ENOMEM;
52680+
52681+ ret = copy_user_glob(o_tmp);
52682+ if (ret)
52683+ return ret;
52684+
52685+ if (o_tmp->nested) {
52686+ o_tmp->nested = do_copy_user_subj(o_tmp->nested, role);
52687+ if (IS_ERR(o_tmp->nested))
52688+ return PTR_ERR(o_tmp->nested);
52689+
52690+ /* insert into nested subject list */
52691+ o_tmp->nested->next = role->hash->first;
52692+ role->hash->first = o_tmp->nested;
52693+ }
52694+ }
52695+
52696+ return 0;
52697+}
52698+
52699+static __u32
52700+count_user_subjs(struct acl_subject_label *userp)
52701+{
52702+ struct acl_subject_label s_tmp;
52703+ __u32 num = 0;
52704+
52705+ while (userp) {
52706+ if (copy_from_user(&s_tmp, userp,
52707+ sizeof (struct acl_subject_label)))
52708+ break;
52709+
52710+ userp = s_tmp.prev;
52711+ /* do not count nested subjects against this count, since
52712+ they are not included in the hash table, but are
52713+ attached to objects. We have already counted
52714+ the subjects in userspace for the allocation
52715+ stack
52716+ */
52717+ if (!(s_tmp.mode & GR_NESTED))
52718+ num++;
52719+ }
52720+
52721+ return num;
52722+}
52723+
52724+static int
52725+copy_user_allowedips(struct acl_role_label *rolep)
52726+{
52727+ struct role_allowed_ip *ruserip, *rtmp = NULL, *rlast;
52728+
52729+ ruserip = rolep->allowed_ips;
52730+
52731+ while (ruserip) {
52732+ rlast = rtmp;
52733+
52734+ if ((rtmp = (struct role_allowed_ip *)
52735+ acl_alloc(sizeof (struct role_allowed_ip))) == NULL)
52736+ return -ENOMEM;
52737+
52738+ if (copy_from_user(rtmp, ruserip,
52739+ sizeof (struct role_allowed_ip)))
52740+ return -EFAULT;
52741+
52742+ ruserip = rtmp->prev;
52743+
52744+ if (!rlast) {
52745+ rtmp->prev = NULL;
52746+ rolep->allowed_ips = rtmp;
52747+ } else {
52748+ rlast->next = rtmp;
52749+ rtmp->prev = rlast;
52750+ }
52751+
52752+ if (!ruserip)
52753+ rtmp->next = NULL;
52754+ }
52755+
52756+ return 0;
52757+}
52758+
52759+static int
52760+copy_user_transitions(struct acl_role_label *rolep)
52761+{
52762+ struct role_transition *rusertp, *rtmp = NULL, *rlast;
52763+
52764+ unsigned int len;
52765+ char *tmp;
52766+
52767+ rusertp = rolep->transitions;
52768+
52769+ while (rusertp) {
52770+ rlast = rtmp;
52771+
52772+ if ((rtmp = (struct role_transition *)
52773+ acl_alloc(sizeof (struct role_transition))) == NULL)
52774+ return -ENOMEM;
52775+
52776+ if (copy_from_user(rtmp, rusertp,
52777+ sizeof (struct role_transition)))
52778+ return -EFAULT;
52779+
52780+ rusertp = rtmp->prev;
52781+
52782+ len = strnlen_user(rtmp->rolename, GR_SPROLE_LEN);
52783+
52784+ if (!len || len >= GR_SPROLE_LEN)
52785+ return -EINVAL;
52786+
52787+ if ((tmp = (char *) acl_alloc(len)) == NULL)
52788+ return -ENOMEM;
52789+
52790+ if (copy_from_user(tmp, rtmp->rolename, len))
52791+ return -EFAULT;
52792+ tmp[len-1] = '\0';
52793+ rtmp->rolename = tmp;
52794+
52795+ if (!rlast) {
52796+ rtmp->prev = NULL;
52797+ rolep->transitions = rtmp;
52798+ } else {
52799+ rlast->next = rtmp;
52800+ rtmp->prev = rlast;
52801+ }
52802+
52803+ if (!rusertp)
52804+ rtmp->next = NULL;
52805+ }
52806+
52807+ return 0;
52808+}
52809+
52810+static struct acl_subject_label *
52811+do_copy_user_subj(struct acl_subject_label *userp, struct acl_role_label *role)
52812+{
52813+ struct acl_subject_label *s_tmp = NULL, *s_tmp2;
52814+ unsigned int len;
52815+ char *tmp;
52816+ __u32 num_objs;
52817+ struct acl_ip_label **i_tmp, *i_utmp2;
52818+ struct gr_hash_struct ghash;
52819+ struct subject_map *subjmap;
52820+ unsigned int i_num;
52821+ int err;
52822+
52823+ s_tmp = lookup_subject_map(userp);
52824+
52825+ /* we've already copied this subject into the kernel, just return
52826+ the reference to it, and don't copy it over again
52827+ */
52828+ if (s_tmp)
52829+ return(s_tmp);
52830+
52831+ if ((s_tmp = (struct acl_subject_label *)
52832+ acl_alloc(sizeof (struct acl_subject_label))) == NULL)
52833+ return ERR_PTR(-ENOMEM);
52834+
52835+ subjmap = (struct subject_map *)kmalloc(sizeof (struct subject_map), GFP_KERNEL);
52836+ if (subjmap == NULL)
52837+ return ERR_PTR(-ENOMEM);
52838+
52839+ subjmap->user = userp;
52840+ subjmap->kernel = s_tmp;
52841+ insert_subj_map_entry(subjmap);
52842+
52843+ if (copy_from_user(s_tmp, userp,
52844+ sizeof (struct acl_subject_label)))
52845+ return ERR_PTR(-EFAULT);
52846+
52847+ len = strnlen_user(s_tmp->filename, PATH_MAX);
52848+
52849+ if (!len || len >= PATH_MAX)
52850+ return ERR_PTR(-EINVAL);
52851+
52852+ if ((tmp = (char *) acl_alloc(len)) == NULL)
52853+ return ERR_PTR(-ENOMEM);
52854+
52855+ if (copy_from_user(tmp, s_tmp->filename, len))
52856+ return ERR_PTR(-EFAULT);
52857+ tmp[len-1] = '\0';
52858+ s_tmp->filename = tmp;
52859+
52860+ if (!strcmp(s_tmp->filename, "/"))
52861+ role->root_label = s_tmp;
52862+
52863+ if (copy_from_user(&ghash, s_tmp->hash, sizeof(struct gr_hash_struct)))
52864+ return ERR_PTR(-EFAULT);
52865+
52866+ /* copy user and group transition tables */
52867+
52868+ if (s_tmp->user_trans_num) {
52869+ uid_t *uidlist;
52870+
52871+ uidlist = (uid_t *)acl_alloc_num(s_tmp->user_trans_num, sizeof(uid_t));
52872+ if (uidlist == NULL)
52873+ return ERR_PTR(-ENOMEM);
52874+ if (copy_from_user(uidlist, s_tmp->user_transitions, s_tmp->user_trans_num * sizeof(uid_t)))
52875+ return ERR_PTR(-EFAULT);
52876+
52877+ s_tmp->user_transitions = uidlist;
52878+ }
52879+
52880+ if (s_tmp->group_trans_num) {
52881+ gid_t *gidlist;
52882+
52883+ gidlist = (gid_t *)acl_alloc_num(s_tmp->group_trans_num, sizeof(gid_t));
52884+ if (gidlist == NULL)
52885+ return ERR_PTR(-ENOMEM);
52886+ if (copy_from_user(gidlist, s_tmp->group_transitions, s_tmp->group_trans_num * sizeof(gid_t)))
52887+ return ERR_PTR(-EFAULT);
52888+
52889+ s_tmp->group_transitions = gidlist;
52890+ }
52891+
52892+ /* set up object hash table */
52893+ num_objs = count_user_objs(ghash.first);
52894+
52895+ s_tmp->obj_hash_size = num_objs;
52896+ s_tmp->obj_hash =
52897+ (struct acl_object_label **)
52898+ create_table(&(s_tmp->obj_hash_size), sizeof(void *));
52899+
52900+ if (!s_tmp->obj_hash)
52901+ return ERR_PTR(-ENOMEM);
52902+
52903+ memset(s_tmp->obj_hash, 0,
52904+ s_tmp->obj_hash_size *
52905+ sizeof (struct acl_object_label *));
52906+
52907+ /* add in objects */
52908+ err = copy_user_objs(ghash.first, s_tmp, role);
52909+
52910+ if (err)
52911+ return ERR_PTR(err);
52912+
52913+ /* set pointer for parent subject */
52914+ if (s_tmp->parent_subject) {
52915+ s_tmp2 = do_copy_user_subj(s_tmp->parent_subject, role);
52916+
52917+ if (IS_ERR(s_tmp2))
52918+ return s_tmp2;
52919+
52920+ s_tmp->parent_subject = s_tmp2;
52921+ }
52922+
52923+ /* add in ip acls */
52924+
52925+ if (!s_tmp->ip_num) {
52926+ s_tmp->ips = NULL;
52927+ goto insert;
52928+ }
52929+
52930+ i_tmp =
52931+ (struct acl_ip_label **) acl_alloc_num(s_tmp->ip_num,
52932+ sizeof (struct acl_ip_label *));
52933+
52934+ if (!i_tmp)
52935+ return ERR_PTR(-ENOMEM);
52936+
52937+ for (i_num = 0; i_num < s_tmp->ip_num; i_num++) {
52938+ *(i_tmp + i_num) =
52939+ (struct acl_ip_label *)
52940+ acl_alloc(sizeof (struct acl_ip_label));
52941+ if (!*(i_tmp + i_num))
52942+ return ERR_PTR(-ENOMEM);
52943+
52944+ if (copy_from_user
52945+ (&i_utmp2, s_tmp->ips + i_num,
52946+ sizeof (struct acl_ip_label *)))
52947+ return ERR_PTR(-EFAULT);
52948+
52949+ if (copy_from_user
52950+ (*(i_tmp + i_num), i_utmp2,
52951+ sizeof (struct acl_ip_label)))
52952+ return ERR_PTR(-EFAULT);
52953+
52954+ if ((*(i_tmp + i_num))->iface == NULL)
52955+ continue;
52956+
52957+ len = strnlen_user((*(i_tmp + i_num))->iface, IFNAMSIZ);
52958+ if (!len || len >= IFNAMSIZ)
52959+ return ERR_PTR(-EINVAL);
52960+ tmp = acl_alloc(len);
52961+ if (tmp == NULL)
52962+ return ERR_PTR(-ENOMEM);
52963+ if (copy_from_user(tmp, (*(i_tmp + i_num))->iface, len))
52964+ return ERR_PTR(-EFAULT);
52965+ (*(i_tmp + i_num))->iface = tmp;
52966+ }
52967+
52968+ s_tmp->ips = i_tmp;
52969+
52970+insert:
52971+ if (!insert_name_entry(s_tmp->filename, s_tmp->inode,
52972+ s_tmp->device, (s_tmp->mode & GR_DELETED) ? 1 : 0))
52973+ return ERR_PTR(-ENOMEM);
52974+
52975+ return s_tmp;
52976+}
52977+
52978+static int
52979+copy_user_subjs(struct acl_subject_label *userp, struct acl_role_label *role)
52980+{
52981+ struct acl_subject_label s_pre;
52982+ struct acl_subject_label * ret;
52983+ int err;
52984+
52985+ while (userp) {
52986+ if (copy_from_user(&s_pre, userp,
52987+ sizeof (struct acl_subject_label)))
52988+ return -EFAULT;
52989+
52990+ /* do not add nested subjects here, add
52991+ while parsing objects
52992+ */
52993+
52994+ if (s_pre.mode & GR_NESTED) {
52995+ userp = s_pre.prev;
52996+ continue;
52997+ }
52998+
52999+ ret = do_copy_user_subj(userp, role);
53000+
53001+ err = PTR_ERR(ret);
53002+ if (IS_ERR(ret))
53003+ return err;
53004+
53005+ insert_acl_subj_label(ret, role);
53006+
53007+ userp = s_pre.prev;
53008+ }
53009+
53010+ return 0;
53011+}
53012+
53013+static int
53014+copy_user_acl(struct gr_arg *arg)
53015+{
53016+ struct acl_role_label *r_tmp = NULL, **r_utmp, *r_utmp2;
53017+ struct acl_subject_label *subj_list;
53018+ struct sprole_pw *sptmp;
53019+ struct gr_hash_struct *ghash;
53020+ uid_t *domainlist;
53021+ unsigned int r_num;
53022+ unsigned int len;
53023+ char *tmp;
53024+ int err = 0;
53025+ __u16 i;
53026+ __u32 num_subjs;
53027+
53028+ /* we need a default and kernel role */
53029+ if (arg->role_db.num_roles < 2)
53030+ return -EINVAL;
53031+
53032+ /* copy special role authentication info from userspace */
53033+
53034+ num_sprole_pws = arg->num_sprole_pws;
53035+ acl_special_roles = (struct sprole_pw **) acl_alloc_num(num_sprole_pws, sizeof(struct sprole_pw *));
53036+
53037+ if (!acl_special_roles && num_sprole_pws)
53038+ return -ENOMEM;
53039+
53040+ for (i = 0; i < num_sprole_pws; i++) {
53041+ sptmp = (struct sprole_pw *) acl_alloc(sizeof(struct sprole_pw));
53042+ if (!sptmp)
53043+ return -ENOMEM;
53044+ if (copy_from_user(sptmp, arg->sprole_pws + i,
53045+ sizeof (struct sprole_pw)))
53046+ return -EFAULT;
53047+
53048+ len = strnlen_user(sptmp->rolename, GR_SPROLE_LEN);
53049+
53050+ if (!len || len >= GR_SPROLE_LEN)
53051+ return -EINVAL;
53052+
53053+ if ((tmp = (char *) acl_alloc(len)) == NULL)
53054+ return -ENOMEM;
53055+
53056+ if (copy_from_user(tmp, sptmp->rolename, len))
53057+ return -EFAULT;
53058+
53059+ tmp[len-1] = '\0';
53060+#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
53061+ printk(KERN_ALERT "Copying special role %s\n", tmp);
53062+#endif
53063+ sptmp->rolename = tmp;
53064+ acl_special_roles[i] = sptmp;
53065+ }
53066+
53067+ r_utmp = (struct acl_role_label **) arg->role_db.r_table;
53068+
53069+ for (r_num = 0; r_num < arg->role_db.num_roles; r_num++) {
53070+ r_tmp = acl_alloc(sizeof (struct acl_role_label));
53071+
53072+ if (!r_tmp)
53073+ return -ENOMEM;
53074+
53075+ if (copy_from_user(&r_utmp2, r_utmp + r_num,
53076+ sizeof (struct acl_role_label *)))
53077+ return -EFAULT;
53078+
53079+ if (copy_from_user(r_tmp, r_utmp2,
53080+ sizeof (struct acl_role_label)))
53081+ return -EFAULT;
53082+
53083+ len = strnlen_user(r_tmp->rolename, GR_SPROLE_LEN);
53084+
53085+ if (!len || len >= PATH_MAX)
53086+ return -EINVAL;
53087+
53088+ if ((tmp = (char *) acl_alloc(len)) == NULL)
53089+ return -ENOMEM;
53090+
53091+ if (copy_from_user(tmp, r_tmp->rolename, len))
53092+ return -EFAULT;
53093+
53094+ tmp[len-1] = '\0';
53095+ r_tmp->rolename = tmp;
53096+
53097+ if (!strcmp(r_tmp->rolename, "default")
53098+ && (r_tmp->roletype & GR_ROLE_DEFAULT)) {
53099+ default_role = r_tmp;
53100+ } else if (!strcmp(r_tmp->rolename, ":::kernel:::")) {
53101+ kernel_role = r_tmp;
53102+ }
53103+
53104+ if ((ghash = (struct gr_hash_struct *) acl_alloc(sizeof(struct gr_hash_struct))) == NULL)
53105+ return -ENOMEM;
53106+
53107+ if (copy_from_user(ghash, r_tmp->hash, sizeof(struct gr_hash_struct)))
53108+ return -EFAULT;
53109+
53110+ r_tmp->hash = ghash;
53111+
53112+ num_subjs = count_user_subjs(r_tmp->hash->first);
53113+
53114+ r_tmp->subj_hash_size = num_subjs;
53115+ r_tmp->subj_hash =
53116+ (struct acl_subject_label **)
53117+ create_table(&(r_tmp->subj_hash_size), sizeof(void *));
53118+
53119+ if (!r_tmp->subj_hash)
53120+ return -ENOMEM;
53121+
53122+ err = copy_user_allowedips(r_tmp);
53123+ if (err)
53124+ return err;
53125+
53126+ /* copy domain info */
53127+ if (r_tmp->domain_children != NULL) {
53128+ domainlist = acl_alloc_num(r_tmp->domain_child_num, sizeof(uid_t));
53129+ if (domainlist == NULL)
53130+ return -ENOMEM;
53131+
53132+ if (copy_from_user(domainlist, r_tmp->domain_children, r_tmp->domain_child_num * sizeof(uid_t)))
53133+ return -EFAULT;
53134+
53135+ r_tmp->domain_children = domainlist;
53136+ }
53137+
53138+ err = copy_user_transitions(r_tmp);
53139+ if (err)
53140+ return err;
53141+
53142+ memset(r_tmp->subj_hash, 0,
53143+ r_tmp->subj_hash_size *
53144+ sizeof (struct acl_subject_label *));
53145+
53146+ /* acquire the list of subjects, then NULL out
53147+ the list prior to parsing the subjects for this role,
53148+ as during this parsing the list is replaced with a list
53149+ of *nested* subjects for the role
53150+ */
53151+ subj_list = r_tmp->hash->first;
53152+
53153+ /* set nested subject list to null */
53154+ r_tmp->hash->first = NULL;
53155+
53156+ err = copy_user_subjs(subj_list, r_tmp);
53157+
53158+ if (err)
53159+ return err;
53160+
53161+ insert_acl_role_label(r_tmp);
53162+ }
53163+
53164+ if (default_role == NULL || kernel_role == NULL)
53165+ return -EINVAL;
53166+
53167+ return err;
53168+}
53169+
53170+static int
53171+gracl_init(struct gr_arg *args)
53172+{
53173+ int error = 0;
53174+
53175+ memcpy(gr_system_salt, args->salt, GR_SALT_LEN);
53176+ memcpy(gr_system_sum, args->sum, GR_SHA_LEN);
53177+
53178+ if (init_variables(args)) {
53179+ gr_log_str(GR_DONT_AUDIT_GOOD, GR_INITF_ACL_MSG, GR_VERSION);
53180+ error = -ENOMEM;
53181+ free_variables();
53182+ goto out;
53183+ }
53184+
53185+ error = copy_user_acl(args);
53186+ free_init_variables();
53187+ if (error) {
53188+ free_variables();
53189+ goto out;
53190+ }
53191+
53192+ if ((error = gr_set_acls(0))) {
53193+ free_variables();
53194+ goto out;
53195+ }
53196+
53197+ pax_open_kernel();
53198+ gr_status |= GR_READY;
53199+ pax_close_kernel();
53200+
53201+ out:
53202+ return error;
53203+}
53204+
53205+/* derived from glibc fnmatch() 0: match, 1: no match*/
53206+
53207+static int
53208+glob_match(const char *p, const char *n)
53209+{
53210+ char c;
53211+
53212+ while ((c = *p++) != '\0') {
53213+ switch (c) {
53214+ case '?':
53215+ if (*n == '\0')
53216+ return 1;
53217+ else if (*n == '/')
53218+ return 1;
53219+ break;
53220+ case '\\':
53221+ if (*n != c)
53222+ return 1;
53223+ break;
53224+ case '*':
53225+ for (c = *p++; c == '?' || c == '*'; c = *p++) {
53226+ if (*n == '/')
53227+ return 1;
53228+ else if (c == '?') {
53229+ if (*n == '\0')
53230+ return 1;
53231+ else
53232+ ++n;
53233+ }
53234+ }
53235+ if (c == '\0') {
53236+ return 0;
53237+ } else {
53238+ const char *endp;
53239+
53240+ if ((endp = strchr(n, '/')) == NULL)
53241+ endp = n + strlen(n);
53242+
53243+ if (c == '[') {
53244+ for (--p; n < endp; ++n)
53245+ if (!glob_match(p, n))
53246+ return 0;
53247+ } else if (c == '/') {
53248+ while (*n != '\0' && *n != '/')
53249+ ++n;
53250+ if (*n == '/' && !glob_match(p, n + 1))
53251+ return 0;
53252+ } else {
53253+ for (--p; n < endp; ++n)
53254+ if (*n == c && !glob_match(p, n))
53255+ return 0;
53256+ }
53257+
53258+ return 1;
53259+ }
53260+ case '[':
53261+ {
53262+ int not;
53263+ char cold;
53264+
53265+ if (*n == '\0' || *n == '/')
53266+ return 1;
53267+
53268+ not = (*p == '!' || *p == '^');
53269+ if (not)
53270+ ++p;
53271+
53272+ c = *p++;
53273+ for (;;) {
53274+ unsigned char fn = (unsigned char)*n;
53275+
53276+ if (c == '\0')
53277+ return 1;
53278+ else {
53279+ if (c == fn)
53280+ goto matched;
53281+ cold = c;
53282+ c = *p++;
53283+
53284+ if (c == '-' && *p != ']') {
53285+ unsigned char cend = *p++;
53286+
53287+ if (cend == '\0')
53288+ return 1;
53289+
53290+ if (cold <= fn && fn <= cend)
53291+ goto matched;
53292+
53293+ c = *p++;
53294+ }
53295+ }
53296+
53297+ if (c == ']')
53298+ break;
53299+ }
53300+ if (!not)
53301+ return 1;
53302+ break;
53303+ matched:
53304+ while (c != ']') {
53305+ if (c == '\0')
53306+ return 1;
53307+
53308+ c = *p++;
53309+ }
53310+ if (not)
53311+ return 1;
53312+ }
53313+ break;
53314+ default:
53315+ if (c != *n)
53316+ return 1;
53317+ }
53318+
53319+ ++n;
53320+ }
53321+
53322+ if (*n == '\0')
53323+ return 0;
53324+
53325+ if (*n == '/')
53326+ return 0;
53327+
53328+ return 1;
53329+}
53330+
53331+static struct acl_object_label *
53332+chk_glob_label(struct acl_object_label *globbed,
53333+ const struct dentry *dentry, const struct vfsmount *mnt, char **path)
53334+{
53335+ struct acl_object_label *tmp;
53336+
53337+ if (*path == NULL)
53338+ *path = gr_to_filename_nolock(dentry, mnt);
53339+
53340+ tmp = globbed;
53341+
53342+ while (tmp) {
53343+ if (!glob_match(tmp->filename, *path))
53344+ return tmp;
53345+ tmp = tmp->next;
53346+ }
53347+
53348+ return NULL;
53349+}
53350+
53351+static struct acl_object_label *
53352+__full_lookup(const struct dentry *orig_dentry, const struct vfsmount *orig_mnt,
53353+ const ino_t curr_ino, const dev_t curr_dev,
53354+ const struct acl_subject_label *subj, char **path, const int checkglob)
53355+{
53356+ struct acl_subject_label *tmpsubj;
53357+ struct acl_object_label *retval;
53358+ struct acl_object_label *retval2;
53359+
53360+ tmpsubj = (struct acl_subject_label *) subj;
53361+ read_lock(&gr_inode_lock);
53362+ do {
53363+ retval = lookup_acl_obj_label(curr_ino, curr_dev, tmpsubj);
53364+ if (retval) {
53365+ if (checkglob && retval->globbed) {
53366+ retval2 = chk_glob_label(retval->globbed, orig_dentry, orig_mnt, path);
53367+ if (retval2)
53368+ retval = retval2;
53369+ }
53370+ break;
53371+ }
53372+ } while ((tmpsubj = tmpsubj->parent_subject));
53373+ read_unlock(&gr_inode_lock);
53374+
53375+ return retval;
53376+}
53377+
53378+static __inline__ struct acl_object_label *
53379+full_lookup(const struct dentry *orig_dentry, const struct vfsmount *orig_mnt,
53380+ struct dentry *curr_dentry,
53381+ const struct acl_subject_label *subj, char **path, const int checkglob)
53382+{
53383+ int newglob = checkglob;
53384+ ino_t inode;
53385+ dev_t device;
53386+
53387+ /* if we aren't checking a subdirectory of the original path yet, don't do glob checking
53388+ as we don't want a / * rule to match instead of the / object
53389+ don't do this for create lookups that call this function though, since they're looking up
53390+ on the parent and thus need globbing checks on all paths
53391+ */
53392+ if (orig_dentry == curr_dentry && newglob != GR_CREATE_GLOB)
53393+ newglob = GR_NO_GLOB;
53394+
53395+ spin_lock(&curr_dentry->d_lock);
53396+ inode = curr_dentry->d_inode->i_ino;
53397+ device = __get_dev(curr_dentry);
53398+ spin_unlock(&curr_dentry->d_lock);
53399+
53400+ return __full_lookup(orig_dentry, orig_mnt, inode, device, subj, path, newglob);
53401+}
53402+
53403+static struct acl_object_label *
53404+__chk_obj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
53405+ const struct acl_subject_label *subj, char *path, const int checkglob)
53406+{
53407+ struct dentry *dentry = (struct dentry *) l_dentry;
53408+ struct vfsmount *mnt = (struct vfsmount *) l_mnt;
53409+ struct mount *real_mnt = real_mount(mnt);
53410+ struct acl_object_label *retval;
53411+ struct dentry *parent;
53412+
53413+ write_seqlock(&rename_lock);
53414+ br_read_lock(&vfsmount_lock);
53415+
53416+ if (unlikely((mnt == shm_mnt && dentry->d_inode->i_nlink == 0) || mnt == pipe_mnt ||
53417+#ifdef CONFIG_NET
53418+ mnt == sock_mnt ||
53419+#endif
53420+#ifdef CONFIG_HUGETLBFS
53421+ (mnt == hugetlbfs_vfsmount && dentry->d_inode->i_nlink == 0) ||
53422+#endif
53423+ /* ignore Eric Biederman */
53424+ IS_PRIVATE(l_dentry->d_inode))) {
53425+ retval = (subj->mode & GR_SHMEXEC) ? fakefs_obj_rwx : fakefs_obj_rw;
53426+ goto out;
53427+ }
53428+
53429+ for (;;) {
53430+ if (dentry == real_root.dentry && mnt == real_root.mnt)
53431+ break;
53432+
53433+ if (dentry == mnt->mnt_root || IS_ROOT(dentry)) {
53434+ if (!mnt_has_parent(real_mnt))
53435+ break;
53436+
53437+ retval = full_lookup(l_dentry, l_mnt, dentry, subj, &path, checkglob);
53438+ if (retval != NULL)
53439+ goto out;
53440+
53441+ dentry = real_mnt->mnt_mountpoint;
53442+ real_mnt = real_mnt->mnt_parent;
53443+ mnt = &real_mnt->mnt;
53444+ continue;
53445+ }
53446+
53447+ parent = dentry->d_parent;
53448+ retval = full_lookup(l_dentry, l_mnt, dentry, subj, &path, checkglob);
53449+ if (retval != NULL)
53450+ goto out;
53451+
53452+ dentry = parent;
53453+ }
53454+
53455+ retval = full_lookup(l_dentry, l_mnt, dentry, subj, &path, checkglob);
53456+
53457+ /* real_root is pinned so we don't have to hold a reference */
53458+ if (retval == NULL)
53459+ retval = full_lookup(l_dentry, l_mnt, real_root.dentry, subj, &path, checkglob);
53460+out:
53461+ br_read_unlock(&vfsmount_lock);
53462+ write_sequnlock(&rename_lock);
53463+
53464+ BUG_ON(retval == NULL);
53465+
53466+ return retval;
53467+}
53468+
53469+static __inline__ struct acl_object_label *
53470+chk_obj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
53471+ const struct acl_subject_label *subj)
53472+{
53473+ char *path = NULL;
53474+ return __chk_obj_label(l_dentry, l_mnt, subj, path, GR_REG_GLOB);
53475+}
53476+
53477+static __inline__ struct acl_object_label *
53478+chk_obj_label_noglob(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
53479+ const struct acl_subject_label *subj)
53480+{
53481+ char *path = NULL;
53482+ return __chk_obj_label(l_dentry, l_mnt, subj, path, GR_NO_GLOB);
53483+}
53484+
53485+static __inline__ struct acl_object_label *
53486+chk_obj_create_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
53487+ const struct acl_subject_label *subj, char *path)
53488+{
53489+ return __chk_obj_label(l_dentry, l_mnt, subj, path, GR_CREATE_GLOB);
53490+}
53491+
53492+static struct acl_subject_label *
53493+chk_subj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
53494+ const struct acl_role_label *role)
53495+{
53496+ struct dentry *dentry = (struct dentry *) l_dentry;
53497+ struct vfsmount *mnt = (struct vfsmount *) l_mnt;
53498+ struct mount *real_mnt = real_mount(mnt);
53499+ struct acl_subject_label *retval;
53500+ struct dentry *parent;
53501+
53502+ write_seqlock(&rename_lock);
53503+ br_read_lock(&vfsmount_lock);
53504+
53505+ for (;;) {
53506+ if (dentry == real_root.dentry && mnt == real_root.mnt)
53507+ break;
53508+ if (dentry == mnt->mnt_root || IS_ROOT(dentry)) {
53509+ if (!mnt_has_parent(real_mnt))
53510+ break;
53511+
53512+ spin_lock(&dentry->d_lock);
53513+ read_lock(&gr_inode_lock);
53514+ retval =
53515+ lookup_acl_subj_label(dentry->d_inode->i_ino,
53516+ __get_dev(dentry), role);
53517+ read_unlock(&gr_inode_lock);
53518+ spin_unlock(&dentry->d_lock);
53519+ if (retval != NULL)
53520+ goto out;
53521+
53522+ dentry = real_mnt->mnt_mountpoint;
53523+ real_mnt = real_mnt->mnt_parent;
53524+ mnt = &real_mnt->mnt;
53525+ continue;
53526+ }
53527+
53528+ spin_lock(&dentry->d_lock);
53529+ read_lock(&gr_inode_lock);
53530+ retval = lookup_acl_subj_label(dentry->d_inode->i_ino,
53531+ __get_dev(dentry), role);
53532+ read_unlock(&gr_inode_lock);
53533+ parent = dentry->d_parent;
53534+ spin_unlock(&dentry->d_lock);
53535+
53536+ if (retval != NULL)
53537+ goto out;
53538+
53539+ dentry = parent;
53540+ }
53541+
53542+ spin_lock(&dentry->d_lock);
53543+ read_lock(&gr_inode_lock);
53544+ retval = lookup_acl_subj_label(dentry->d_inode->i_ino,
53545+ __get_dev(dentry), role);
53546+ read_unlock(&gr_inode_lock);
53547+ spin_unlock(&dentry->d_lock);
53548+
53549+ if (unlikely(retval == NULL)) {
53550+ /* real_root is pinned, we don't need to hold a reference */
53551+ read_lock(&gr_inode_lock);
53552+ retval = lookup_acl_subj_label(real_root.dentry->d_inode->i_ino,
53553+ __get_dev(real_root.dentry), role);
53554+ read_unlock(&gr_inode_lock);
53555+ }
53556+out:
53557+ br_read_unlock(&vfsmount_lock);
53558+ write_sequnlock(&rename_lock);
53559+
53560+ BUG_ON(retval == NULL);
53561+
53562+ return retval;
53563+}
53564+
53565+static void
53566+gr_log_learn(const struct dentry *dentry, const struct vfsmount *mnt, const __u32 mode)
53567+{
53568+ struct task_struct *task = current;
53569+ const struct cred *cred = current_cred();
53570+
53571+ security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename, task->role->roletype,
53572+ cred->uid, cred->gid, task->exec_file ? gr_to_filename1(task->exec_file->f_path.dentry,
53573+ task->exec_file->f_path.mnt) : task->acl->filename, task->acl->filename,
53574+ 1UL, 1UL, gr_to_filename(dentry, mnt), (unsigned long) mode, &task->signal->saved_ip);
53575+
53576+ return;
53577+}
53578+
53579+static void
53580+gr_log_learn_id_change(const char type, const unsigned int real,
53581+ const unsigned int effective, const unsigned int fs)
53582+{
53583+ struct task_struct *task = current;
53584+ const struct cred *cred = current_cred();
53585+
53586+ security_learn(GR_ID_LEARN_MSG, task->role->rolename, task->role->roletype,
53587+ cred->uid, cred->gid, task->exec_file ? gr_to_filename1(task->exec_file->f_path.dentry,
53588+ task->exec_file->f_path.mnt) : task->acl->filename, task->acl->filename,
53589+ type, real, effective, fs, &task->signal->saved_ip);
53590+
53591+ return;
53592+}
53593+
53594+__u32
53595+gr_search_file(const struct dentry * dentry, const __u32 mode,
53596+ const struct vfsmount * mnt)
53597+{
53598+ __u32 retval = mode;
53599+ struct acl_subject_label *curracl;
53600+ struct acl_object_label *currobj;
53601+
53602+ if (unlikely(!(gr_status & GR_READY)))
53603+ return (mode & ~GR_AUDITS);
53604+
53605+ curracl = current->acl;
53606+
53607+ currobj = chk_obj_label(dentry, mnt, curracl);
53608+ retval = currobj->mode & mode;
53609+
53610+ /* if we're opening a specified transfer file for writing
53611+ (e.g. /dev/initctl), then transfer our role to init
53612+ */
53613+ if (unlikely(currobj->mode & GR_INIT_TRANSFER && retval & GR_WRITE &&
53614+ current->role->roletype & GR_ROLE_PERSIST)) {
53615+ struct task_struct *task = init_pid_ns.child_reaper;
53616+
53617+ if (task->role != current->role) {
53618+ task->acl_sp_role = 0;
53619+ task->acl_role_id = current->acl_role_id;
53620+ task->role = current->role;
53621+ rcu_read_lock();
53622+ read_lock(&grsec_exec_file_lock);
53623+ gr_apply_subject_to_task(task);
53624+ read_unlock(&grsec_exec_file_lock);
53625+ rcu_read_unlock();
53626+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_INIT_TRANSFER_MSG);
53627+ }
53628+ }
53629+
53630+ if (unlikely
53631+ ((curracl->mode & (GR_LEARN | GR_INHERITLEARN)) && !(mode & GR_NOPTRACE)
53632+ && (retval != (mode & ~(GR_AUDITS | GR_SUPPRESS))))) {
53633+ __u32 new_mode = mode;
53634+
53635+ new_mode &= ~(GR_AUDITS | GR_SUPPRESS);
53636+
53637+ retval = new_mode;
53638+
53639+ if (new_mode & GR_EXEC && curracl->mode & GR_INHERITLEARN)
53640+ new_mode |= GR_INHERIT;
53641+
53642+ if (!(mode & GR_NOLEARN))
53643+ gr_log_learn(dentry, mnt, new_mode);
53644+ }
53645+
53646+ return retval;
53647+}
53648+
53649+struct acl_object_label *gr_get_create_object(const struct dentry *new_dentry,
53650+ const struct dentry *parent,
53651+ const struct vfsmount *mnt)
53652+{
53653+ struct name_entry *match;
53654+ struct acl_object_label *matchpo;
53655+ struct acl_subject_label *curracl;
53656+ char *path;
53657+
53658+ if (unlikely(!(gr_status & GR_READY)))
53659+ return NULL;
53660+
53661+ preempt_disable();
53662+ path = gr_to_filename_rbac(new_dentry, mnt);
53663+ match = lookup_name_entry_create(path);
53664+
53665+ curracl = current->acl;
53666+
53667+ if (match) {
53668+ read_lock(&gr_inode_lock);
53669+ matchpo = lookup_acl_obj_label_create(match->inode, match->device, curracl);
53670+ read_unlock(&gr_inode_lock);
53671+
53672+ if (matchpo) {
53673+ preempt_enable();
53674+ return matchpo;
53675+ }
53676+ }
53677+
53678+ // lookup parent
53679+
53680+ matchpo = chk_obj_create_label(parent, mnt, curracl, path);
53681+
53682+ preempt_enable();
53683+ return matchpo;
53684+}
53685+
53686+__u32
53687+gr_check_create(const struct dentry * new_dentry, const struct dentry * parent,
53688+ const struct vfsmount * mnt, const __u32 mode)
53689+{
53690+ struct acl_object_label *matchpo;
53691+ __u32 retval;
53692+
53693+ if (unlikely(!(gr_status & GR_READY)))
53694+ return (mode & ~GR_AUDITS);
53695+
53696+ matchpo = gr_get_create_object(new_dentry, parent, mnt);
53697+
53698+ retval = matchpo->mode & mode;
53699+
53700+ if ((retval != (mode & ~(GR_AUDITS | GR_SUPPRESS)))
53701+ && (current->acl->mode & (GR_LEARN | GR_INHERITLEARN))) {
53702+ __u32 new_mode = mode;
53703+
53704+ new_mode &= ~(GR_AUDITS | GR_SUPPRESS);
53705+
53706+ gr_log_learn(new_dentry, mnt, new_mode);
53707+ return new_mode;
53708+ }
53709+
53710+ return retval;
53711+}
53712+
53713+__u32
53714+gr_check_link(const struct dentry * new_dentry,
53715+ const struct dentry * parent_dentry,
53716+ const struct vfsmount * parent_mnt,
53717+ const struct dentry * old_dentry, const struct vfsmount * old_mnt)
53718+{
53719+ struct acl_object_label *obj;
53720+ __u32 oldmode, newmode;
53721+ __u32 needmode;
53722+ __u32 checkmodes = GR_FIND | GR_APPEND | GR_WRITE | GR_EXEC | GR_SETID | GR_READ |
53723+ GR_DELETE | GR_INHERIT;
53724+
53725+ if (unlikely(!(gr_status & GR_READY)))
53726+ return (GR_CREATE | GR_LINK);
53727+
53728+ obj = chk_obj_label(old_dentry, old_mnt, current->acl);
53729+ oldmode = obj->mode;
53730+
53731+ obj = gr_get_create_object(new_dentry, parent_dentry, parent_mnt);
53732+ newmode = obj->mode;
53733+
53734+ needmode = newmode & checkmodes;
53735+
53736+ // old name for hardlink must have at least the permissions of the new name
53737+ if ((oldmode & needmode) != needmode)
53738+ goto bad;
53739+
53740+ // if old name had restrictions/auditing, make sure the new name does as well
53741+ needmode = oldmode & (GR_NOPTRACE | GR_PTRACERD | GR_INHERIT | GR_AUDITS);
53742+
53743+ // don't allow hardlinking of suid/sgid/fcapped files without permission
53744+ if (is_privileged_binary(old_dentry))
53745+ needmode |= GR_SETID;
53746+
53747+ if ((newmode & needmode) != needmode)
53748+ goto bad;
53749+
53750+ // enforce minimum permissions
53751+ if ((newmode & (GR_CREATE | GR_LINK)) == (GR_CREATE | GR_LINK))
53752+ return newmode;
53753+bad:
53754+ needmode = oldmode;
53755+ if (is_privileged_binary(old_dentry))
53756+ needmode |= GR_SETID;
53757+
53758+ if (current->acl->mode & (GR_LEARN | GR_INHERITLEARN)) {
53759+ gr_log_learn(old_dentry, old_mnt, needmode | GR_CREATE | GR_LINK);
53760+ return (GR_CREATE | GR_LINK);
53761+ } else if (newmode & GR_SUPPRESS)
53762+ return GR_SUPPRESS;
53763+ else
53764+ return 0;
53765+}
53766+
53767+int
53768+gr_check_hidden_task(const struct task_struct *task)
53769+{
53770+ if (unlikely(!(gr_status & GR_READY)))
53771+ return 0;
53772+
53773+ if (!(task->acl->mode & GR_PROCFIND) && !(current->acl->mode & GR_VIEW))
53774+ return 1;
53775+
53776+ return 0;
53777+}
53778+
53779+int
53780+gr_check_protected_task(const struct task_struct *task)
53781+{
53782+ if (unlikely(!(gr_status & GR_READY) || !task))
53783+ return 0;
53784+
53785+ if ((task->acl->mode & GR_PROTECTED) && !(current->acl->mode & GR_KILL) &&
53786+ task->acl != current->acl)
53787+ return 1;
53788+
53789+ return 0;
53790+}
53791+
53792+int
53793+gr_check_protected_task_fowner(struct pid *pid, enum pid_type type)
53794+{
53795+ struct task_struct *p;
53796+ int ret = 0;
53797+
53798+ if (unlikely(!(gr_status & GR_READY) || !pid))
53799+ return ret;
53800+
53801+ read_lock(&tasklist_lock);
53802+ do_each_pid_task(pid, type, p) {
53803+ if ((p->acl->mode & GR_PROTECTED) && !(current->acl->mode & GR_KILL) &&
53804+ p->acl != current->acl) {
53805+ ret = 1;
53806+ goto out;
53807+ }
53808+ } while_each_pid_task(pid, type, p);
53809+out:
53810+ read_unlock(&tasklist_lock);
53811+
53812+ return ret;
53813+}
53814+
53815+void
53816+gr_copy_label(struct task_struct *tsk)
53817+{
53818+ tsk->signal->used_accept = 0;
53819+ tsk->acl_sp_role = 0;
53820+ tsk->acl_role_id = current->acl_role_id;
53821+ tsk->acl = current->acl;
53822+ tsk->role = current->role;
53823+ tsk->signal->curr_ip = current->signal->curr_ip;
53824+ tsk->signal->saved_ip = current->signal->saved_ip;
53825+ if (current->exec_file)
53826+ get_file(current->exec_file);
53827+ tsk->exec_file = current->exec_file;
53828+ tsk->is_writable = current->is_writable;
53829+ if (unlikely(current->signal->used_accept)) {
53830+ current->signal->curr_ip = 0;
53831+ current->signal->saved_ip = 0;
53832+ }
53833+
53834+ return;
53835+}
53836+
53837+static void
53838+gr_set_proc_res(struct task_struct *task)
53839+{
53840+ struct acl_subject_label *proc;
53841+ unsigned short i;
53842+
53843+ proc = task->acl;
53844+
53845+ if (proc->mode & (GR_LEARN | GR_INHERITLEARN))
53846+ return;
53847+
53848+ for (i = 0; i < RLIM_NLIMITS; i++) {
53849+ if (!(proc->resmask & (1 << i)))
53850+ continue;
53851+
53852+ task->signal->rlim[i].rlim_cur = proc->res[i].rlim_cur;
53853+ task->signal->rlim[i].rlim_max = proc->res[i].rlim_max;
53854+ }
53855+
53856+ return;
53857+}
53858+
53859+extern int __gr_process_user_ban(struct user_struct *user);
53860+
53861+int
53862+gr_check_user_change(int real, int effective, int fs)
53863+{
53864+ unsigned int i;
53865+ __u16 num;
53866+ uid_t *uidlist;
53867+ int curuid;
53868+ int realok = 0;
53869+ int effectiveok = 0;
53870+ int fsok = 0;
53871+
53872+#if defined(CONFIG_GRKERNSEC_KERN_LOCKOUT) || defined(CONFIG_GRKERNSEC_BRUTE)
53873+ struct user_struct *user;
53874+
53875+ if (real == -1)
53876+ goto skipit;
53877+
53878+ user = find_user(real);
53879+ if (user == NULL)
53880+ goto skipit;
53881+
53882+ if (__gr_process_user_ban(user)) {
53883+ /* for find_user */
53884+ free_uid(user);
53885+ return 1;
53886+ }
53887+
53888+ /* for find_user */
53889+ free_uid(user);
53890+
53891+skipit:
53892+#endif
53893+
53894+ if (unlikely(!(gr_status & GR_READY)))
53895+ return 0;
53896+
53897+ if (current->acl->mode & (GR_LEARN | GR_INHERITLEARN))
53898+ gr_log_learn_id_change('u', real, effective, fs);
53899+
53900+ num = current->acl->user_trans_num;
53901+ uidlist = current->acl->user_transitions;
53902+
53903+ if (uidlist == NULL)
53904+ return 0;
53905+
53906+ if (real == -1)
53907+ realok = 1;
53908+ if (effective == -1)
53909+ effectiveok = 1;
53910+ if (fs == -1)
53911+ fsok = 1;
53912+
53913+ if (current->acl->user_trans_type & GR_ID_ALLOW) {
53914+ for (i = 0; i < num; i++) {
53915+ curuid = (int)uidlist[i];
53916+ if (real == curuid)
53917+ realok = 1;
53918+ if (effective == curuid)
53919+ effectiveok = 1;
53920+ if (fs == curuid)
53921+ fsok = 1;
53922+ }
53923+ } else if (current->acl->user_trans_type & GR_ID_DENY) {
53924+ for (i = 0; i < num; i++) {
53925+ curuid = (int)uidlist[i];
53926+ if (real == curuid)
53927+ break;
53928+ if (effective == curuid)
53929+ break;
53930+ if (fs == curuid)
53931+ break;
53932+ }
53933+ /* not in deny list */
53934+ if (i == num) {
53935+ realok = 1;
53936+ effectiveok = 1;
53937+ fsok = 1;
53938+ }
53939+ }
53940+
53941+ if (realok && effectiveok && fsok)
53942+ return 0;
53943+ else {
53944+ gr_log_int(GR_DONT_AUDIT, GR_USRCHANGE_ACL_MSG, realok ? (effectiveok ? (fsok ? 0 : fs) : effective) : real);
53945+ return 1;
53946+ }
53947+}
53948+
53949+int
53950+gr_check_group_change(int real, int effective, int fs)
53951+{
53952+ unsigned int i;
53953+ __u16 num;
53954+ gid_t *gidlist;
53955+ int curgid;
53956+ int realok = 0;
53957+ int effectiveok = 0;
53958+ int fsok = 0;
53959+
53960+ if (unlikely(!(gr_status & GR_READY)))
53961+ return 0;
53962+
53963+ if (current->acl->mode & (GR_LEARN | GR_INHERITLEARN))
53964+ gr_log_learn_id_change('g', real, effective, fs);
53965+
53966+ num = current->acl->group_trans_num;
53967+ gidlist = current->acl->group_transitions;
53968+
53969+ if (gidlist == NULL)
53970+ return 0;
53971+
53972+ if (real == -1)
53973+ realok = 1;
53974+ if (effective == -1)
53975+ effectiveok = 1;
53976+ if (fs == -1)
53977+ fsok = 1;
53978+
53979+ if (current->acl->group_trans_type & GR_ID_ALLOW) {
53980+ for (i = 0; i < num; i++) {
53981+ curgid = (int)gidlist[i];
53982+ if (real == curgid)
53983+ realok = 1;
53984+ if (effective == curgid)
53985+ effectiveok = 1;
53986+ if (fs == curgid)
53987+ fsok = 1;
53988+ }
53989+ } else if (current->acl->group_trans_type & GR_ID_DENY) {
53990+ for (i = 0; i < num; i++) {
53991+ curgid = (int)gidlist[i];
53992+ if (real == curgid)
53993+ break;
53994+ if (effective == curgid)
53995+ break;
53996+ if (fs == curgid)
53997+ break;
53998+ }
53999+ /* not in deny list */
54000+ if (i == num) {
54001+ realok = 1;
54002+ effectiveok = 1;
54003+ fsok = 1;
54004+ }
54005+ }
54006+
54007+ if (realok && effectiveok && fsok)
54008+ return 0;
54009+ else {
54010+ gr_log_int(GR_DONT_AUDIT, GR_GRPCHANGE_ACL_MSG, realok ? (effectiveok ? (fsok ? 0 : fs) : effective) : real);
54011+ return 1;
54012+ }
54013+}
54014+
54015+extern int gr_acl_is_capable(const int cap);
54016+
54017+void
54018+gr_set_role_label(struct task_struct *task, const uid_t uid, const uid_t gid)
54019+{
54020+ struct acl_role_label *role = task->role;
54021+ struct acl_subject_label *subj = NULL;
54022+ struct acl_object_label *obj;
54023+ struct file *filp;
54024+
54025+ if (unlikely(!(gr_status & GR_READY)))
54026+ return;
54027+
54028+ filp = task->exec_file;
54029+
54030+ /* kernel process, we'll give them the kernel role */
54031+ if (unlikely(!filp)) {
54032+ task->role = kernel_role;
54033+ task->acl = kernel_role->root_label;
54034+ return;
54035+ } else if (!task->role || !(task->role->roletype & GR_ROLE_SPECIAL))
54036+ role = lookup_acl_role_label(task, uid, gid);
54037+
54038+ /* don't change the role if we're not a privileged process */
54039+ if (role && task->role != role &&
54040+ (((role->roletype & GR_ROLE_USER) && !gr_acl_is_capable(CAP_SETUID)) ||
54041+ ((role->roletype & GR_ROLE_GROUP) && !gr_acl_is_capable(CAP_SETGID))))
54042+ return;
54043+
54044+ /* perform subject lookup in possibly new role
54045+ we can use this result below in the case where role == task->role
54046+ */
54047+ subj = chk_subj_label(filp->f_path.dentry, filp->f_path.mnt, role);
54048+
54049+ /* if we changed uid/gid, but result in the same role
54050+ and are using inheritance, don't lose the inherited subject
54051+ if current subject is other than what normal lookup
54052+ would result in, we arrived via inheritance, don't
54053+ lose subject
54054+ */
54055+ if (role != task->role || (!(task->acl->mode & GR_INHERITLEARN) &&
54056+ (subj == task->acl)))
54057+ task->acl = subj;
54058+
54059+ task->role = role;
54060+
54061+ task->is_writable = 0;
54062+
54063+ /* ignore additional mmap checks for processes that are writable
54064+ by the default ACL */
54065+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, default_role->root_label);
54066+ if (unlikely(obj->mode & GR_WRITE))
54067+ task->is_writable = 1;
54068+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, task->role->root_label);
54069+ if (unlikely(obj->mode & GR_WRITE))
54070+ task->is_writable = 1;
54071+
54072+#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
54073+ printk(KERN_ALERT "Set role label for (%s:%d): role:%s, subject:%s\n", task->comm, task->pid, task->role->rolename, task->acl->filename);
54074+#endif
54075+
54076+ gr_set_proc_res(task);
54077+
54078+ return;
54079+}
54080+
54081+int
54082+gr_set_proc_label(const struct dentry *dentry, const struct vfsmount *mnt,
54083+ const int unsafe_flags)
54084+{
54085+ struct task_struct *task = current;
54086+ struct acl_subject_label *newacl;
54087+ struct acl_object_label *obj;
54088+ __u32 retmode;
54089+
54090+ if (unlikely(!(gr_status & GR_READY)))
54091+ return 0;
54092+
54093+ newacl = chk_subj_label(dentry, mnt, task->role);
54094+
54095+ /* special handling for if we did an strace -f -p <pid> from an admin role, where pid then
54096+ did an exec
54097+ */
54098+ rcu_read_lock();
54099+ read_lock(&tasklist_lock);
54100+ if (task->ptrace && task->parent && ((task->parent->role->roletype & GR_ROLE_GOD) ||
54101+ (task->parent->acl->mode & GR_POVERRIDE))) {
54102+ read_unlock(&tasklist_lock);
54103+ rcu_read_unlock();
54104+ goto skip_check;
54105+ }
54106+ read_unlock(&tasklist_lock);
54107+ rcu_read_unlock();
54108+
54109+ if (unsafe_flags && !(task->acl->mode & GR_POVERRIDE) && (task->acl != newacl) &&
54110+ !(task->role->roletype & GR_ROLE_GOD) &&
54111+ !gr_search_file(dentry, GR_PTRACERD, mnt) &&
54112+ !(task->acl->mode & (GR_LEARN | GR_INHERITLEARN))) {
54113+ if (unsafe_flags & LSM_UNSAFE_SHARE)
54114+ gr_log_fs_generic(GR_DONT_AUDIT, GR_UNSAFESHARE_EXEC_ACL_MSG, dentry, mnt);
54115+ else
54116+ gr_log_fs_generic(GR_DONT_AUDIT, GR_PTRACE_EXEC_ACL_MSG, dentry, mnt);
54117+ return -EACCES;
54118+ }
54119+
54120+skip_check:
54121+
54122+ obj = chk_obj_label(dentry, mnt, task->acl);
54123+ retmode = obj->mode & (GR_INHERIT | GR_AUDIT_INHERIT);
54124+
54125+ if (!(task->acl->mode & GR_INHERITLEARN) &&
54126+ ((newacl->mode & GR_LEARN) || !(retmode & GR_INHERIT))) {
54127+ if (obj->nested)
54128+ task->acl = obj->nested;
54129+ else
54130+ task->acl = newacl;
54131+ } else if (retmode & GR_INHERIT && retmode & GR_AUDIT_INHERIT)
54132+ gr_log_str_fs(GR_DO_AUDIT, GR_INHERIT_ACL_MSG, task->acl->filename, dentry, mnt);
54133+
54134+ task->is_writable = 0;
54135+
54136+ /* ignore additional mmap checks for processes that are writable
54137+ by the default ACL */
54138+ obj = chk_obj_label(dentry, mnt, default_role->root_label);
54139+ if (unlikely(obj->mode & GR_WRITE))
54140+ task->is_writable = 1;
54141+ obj = chk_obj_label(dentry, mnt, task->role->root_label);
54142+ if (unlikely(obj->mode & GR_WRITE))
54143+ task->is_writable = 1;
54144+
54145+ gr_set_proc_res(task);
54146+
54147+#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
54148+ printk(KERN_ALERT "Set subject label for (%s:%d): role:%s, subject:%s\n", task->comm, task->pid, task->role->rolename, task->acl->filename);
54149+#endif
54150+ return 0;
54151+}
54152+
54153+/* always called with valid inodev ptr */
54154+static void
54155+do_handle_delete(struct inodev_entry *inodev, const ino_t ino, const dev_t dev)
54156+{
54157+ struct acl_object_label *matchpo;
54158+ struct acl_subject_label *matchps;
54159+ struct acl_subject_label *subj;
54160+ struct acl_role_label *role;
54161+ unsigned int x;
54162+
54163+ FOR_EACH_ROLE_START(role)
54164+ FOR_EACH_SUBJECT_START(role, subj, x)
54165+ if ((matchpo = lookup_acl_obj_label(ino, dev, subj)) != NULL)
54166+ matchpo->mode |= GR_DELETED;
54167+ FOR_EACH_SUBJECT_END(subj,x)
54168+ FOR_EACH_NESTED_SUBJECT_START(role, subj)
54169+ /* nested subjects aren't in the role's subj_hash table */
54170+ if ((matchpo = lookup_acl_obj_label(ino, dev, subj)) != NULL)
54171+ matchpo->mode |= GR_DELETED;
54172+ FOR_EACH_NESTED_SUBJECT_END(subj)
54173+ if ((matchps = lookup_acl_subj_label(ino, dev, role)) != NULL)
54174+ matchps->mode |= GR_DELETED;
54175+ FOR_EACH_ROLE_END(role)
54176+
54177+ inodev->nentry->deleted = 1;
54178+
54179+ return;
54180+}
54181+
54182+void
54183+gr_handle_delete(const ino_t ino, const dev_t dev)
54184+{
54185+ struct inodev_entry *inodev;
54186+
54187+ if (unlikely(!(gr_status & GR_READY)))
54188+ return;
54189+
54190+ write_lock(&gr_inode_lock);
54191+ inodev = lookup_inodev_entry(ino, dev);
54192+ if (inodev != NULL)
54193+ do_handle_delete(inodev, ino, dev);
54194+ write_unlock(&gr_inode_lock);
54195+
54196+ return;
54197+}
54198+
54199+static void
54200+update_acl_obj_label(const ino_t oldinode, const dev_t olddevice,
54201+ const ino_t newinode, const dev_t newdevice,
54202+ struct acl_subject_label *subj)
54203+{
54204+ unsigned int index = fhash(oldinode, olddevice, subj->obj_hash_size);
54205+ struct acl_object_label *match;
54206+
54207+ match = subj->obj_hash[index];
54208+
54209+ while (match && (match->inode != oldinode ||
54210+ match->device != olddevice ||
54211+ !(match->mode & GR_DELETED)))
54212+ match = match->next;
54213+
54214+ if (match && (match->inode == oldinode)
54215+ && (match->device == olddevice)
54216+ && (match->mode & GR_DELETED)) {
54217+ if (match->prev == NULL) {
54218+ subj->obj_hash[index] = match->next;
54219+ if (match->next != NULL)
54220+ match->next->prev = NULL;
54221+ } else {
54222+ match->prev->next = match->next;
54223+ if (match->next != NULL)
54224+ match->next->prev = match->prev;
54225+ }
54226+ match->prev = NULL;
54227+ match->next = NULL;
54228+ match->inode = newinode;
54229+ match->device = newdevice;
54230+ match->mode &= ~GR_DELETED;
54231+
54232+ insert_acl_obj_label(match, subj);
54233+ }
54234+
54235+ return;
54236+}
54237+
54238+static void
54239+update_acl_subj_label(const ino_t oldinode, const dev_t olddevice,
54240+ const ino_t newinode, const dev_t newdevice,
54241+ struct acl_role_label *role)
54242+{
54243+ unsigned int index = fhash(oldinode, olddevice, role->subj_hash_size);
54244+ struct acl_subject_label *match;
54245+
54246+ match = role->subj_hash[index];
54247+
54248+ while (match && (match->inode != oldinode ||
54249+ match->device != olddevice ||
54250+ !(match->mode & GR_DELETED)))
54251+ match = match->next;
54252+
54253+ if (match && (match->inode == oldinode)
54254+ && (match->device == olddevice)
54255+ && (match->mode & GR_DELETED)) {
54256+ if (match->prev == NULL) {
54257+ role->subj_hash[index] = match->next;
54258+ if (match->next != NULL)
54259+ match->next->prev = NULL;
54260+ } else {
54261+ match->prev->next = match->next;
54262+ if (match->next != NULL)
54263+ match->next->prev = match->prev;
54264+ }
54265+ match->prev = NULL;
54266+ match->next = NULL;
54267+ match->inode = newinode;
54268+ match->device = newdevice;
54269+ match->mode &= ~GR_DELETED;
54270+
54271+ insert_acl_subj_label(match, role);
54272+ }
54273+
54274+ return;
54275+}
54276+
54277+static void
54278+update_inodev_entry(const ino_t oldinode, const dev_t olddevice,
54279+ const ino_t newinode, const dev_t newdevice)
54280+{
54281+ unsigned int index = fhash(oldinode, olddevice, inodev_set.i_size);
54282+ struct inodev_entry *match;
54283+
54284+ match = inodev_set.i_hash[index];
54285+
54286+ while (match && (match->nentry->inode != oldinode ||
54287+ match->nentry->device != olddevice || !match->nentry->deleted))
54288+ match = match->next;
54289+
54290+ if (match && (match->nentry->inode == oldinode)
54291+ && (match->nentry->device == olddevice) &&
54292+ match->nentry->deleted) {
54293+ if (match->prev == NULL) {
54294+ inodev_set.i_hash[index] = match->next;
54295+ if (match->next != NULL)
54296+ match->next->prev = NULL;
54297+ } else {
54298+ match->prev->next = match->next;
54299+ if (match->next != NULL)
54300+ match->next->prev = match->prev;
54301+ }
54302+ match->prev = NULL;
54303+ match->next = NULL;
54304+ match->nentry->inode = newinode;
54305+ match->nentry->device = newdevice;
54306+ match->nentry->deleted = 0;
54307+
54308+ insert_inodev_entry(match);
54309+ }
54310+
54311+ return;
54312+}
54313+
54314+static void
54315+__do_handle_create(const struct name_entry *matchn, ino_t ino, dev_t dev)
54316+{
54317+ struct acl_subject_label *subj;
54318+ struct acl_role_label *role;
54319+ unsigned int x;
54320+
54321+ FOR_EACH_ROLE_START(role)
54322+ update_acl_subj_label(matchn->inode, matchn->device, ino, dev, role);
54323+
54324+ FOR_EACH_NESTED_SUBJECT_START(role, subj)
54325+ if ((subj->inode == ino) && (subj->device == dev)) {
54326+ subj->inode = ino;
54327+ subj->device = dev;
54328+ }
54329+ /* nested subjects aren't in the role's subj_hash table */
54330+ update_acl_obj_label(matchn->inode, matchn->device,
54331+ ino, dev, subj);
54332+ FOR_EACH_NESTED_SUBJECT_END(subj)
54333+ FOR_EACH_SUBJECT_START(role, subj, x)
54334+ update_acl_obj_label(matchn->inode, matchn->device,
54335+ ino, dev, subj);
54336+ FOR_EACH_SUBJECT_END(subj,x)
54337+ FOR_EACH_ROLE_END(role)
54338+
54339+ update_inodev_entry(matchn->inode, matchn->device, ino, dev);
54340+
54341+ return;
54342+}
54343+
54344+static void
54345+do_handle_create(const struct name_entry *matchn, const struct dentry *dentry,
54346+ const struct vfsmount *mnt)
54347+{
54348+ ino_t ino = dentry->d_inode->i_ino;
54349+ dev_t dev = __get_dev(dentry);
54350+
54351+ __do_handle_create(matchn, ino, dev);
54352+
54353+ return;
54354+}
54355+
54356+void
54357+gr_handle_create(const struct dentry *dentry, const struct vfsmount *mnt)
54358+{
54359+ struct name_entry *matchn;
54360+
54361+ if (unlikely(!(gr_status & GR_READY)))
54362+ return;
54363+
54364+ preempt_disable();
54365+ matchn = lookup_name_entry(gr_to_filename_rbac(dentry, mnt));
54366+
54367+ if (unlikely((unsigned long)matchn)) {
54368+ write_lock(&gr_inode_lock);
54369+ do_handle_create(matchn, dentry, mnt);
54370+ write_unlock(&gr_inode_lock);
54371+ }
54372+ preempt_enable();
54373+
54374+ return;
54375+}
54376+
54377+void
54378+gr_handle_proc_create(const struct dentry *dentry, const struct inode *inode)
54379+{
54380+ struct name_entry *matchn;
54381+
54382+ if (unlikely(!(gr_status & GR_READY)))
54383+ return;
54384+
54385+ preempt_disable();
54386+ matchn = lookup_name_entry(gr_to_proc_filename_rbac(dentry, init_pid_ns.proc_mnt));
54387+
54388+ if (unlikely((unsigned long)matchn)) {
54389+ write_lock(&gr_inode_lock);
54390+ __do_handle_create(matchn, inode->i_ino, inode->i_sb->s_dev);
54391+ write_unlock(&gr_inode_lock);
54392+ }
54393+ preempt_enable();
54394+
54395+ return;
54396+}
54397+
54398+void
54399+gr_handle_rename(struct inode *old_dir, struct inode *new_dir,
54400+ struct dentry *old_dentry,
54401+ struct dentry *new_dentry,
54402+ struct vfsmount *mnt, const __u8 replace)
54403+{
54404+ struct name_entry *matchn;
54405+ struct inodev_entry *inodev;
54406+ struct inode *inode = new_dentry->d_inode;
54407+ ino_t old_ino = old_dentry->d_inode->i_ino;
54408+ dev_t old_dev = __get_dev(old_dentry);
54409+
54410+ /* vfs_rename swaps the name and parent link for old_dentry and
54411+ new_dentry
54412+ at this point, old_dentry has the new name, parent link, and inode
54413+ for the renamed file
54414+ if a file is being replaced by a rename, new_dentry has the inode
54415+ and name for the replaced file
54416+ */
54417+
54418+ if (unlikely(!(gr_status & GR_READY)))
54419+ return;
54420+
54421+ preempt_disable();
54422+ matchn = lookup_name_entry(gr_to_filename_rbac(old_dentry, mnt));
54423+
54424+ /* we wouldn't have to check d_inode if it weren't for
54425+ NFS silly-renaming
54426+ */
54427+
54428+ write_lock(&gr_inode_lock);
54429+ if (unlikely(replace && inode)) {
54430+ ino_t new_ino = inode->i_ino;
54431+ dev_t new_dev = __get_dev(new_dentry);
54432+
54433+ inodev = lookup_inodev_entry(new_ino, new_dev);
54434+ if (inodev != NULL && ((inode->i_nlink <= 1) || S_ISDIR(inode->i_mode)))
54435+ do_handle_delete(inodev, new_ino, new_dev);
54436+ }
54437+
54438+ inodev = lookup_inodev_entry(old_ino, old_dev);
54439+ if (inodev != NULL && ((old_dentry->d_inode->i_nlink <= 1) || S_ISDIR(old_dentry->d_inode->i_mode)))
54440+ do_handle_delete(inodev, old_ino, old_dev);
54441+
54442+ if (unlikely((unsigned long)matchn))
54443+ do_handle_create(matchn, old_dentry, mnt);
54444+
54445+ write_unlock(&gr_inode_lock);
54446+ preempt_enable();
54447+
54448+ return;
54449+}
54450+
54451+static int
54452+lookup_special_role_auth(__u16 mode, const char *rolename, unsigned char **salt,
54453+ unsigned char **sum)
54454+{
54455+ struct acl_role_label *r;
54456+ struct role_allowed_ip *ipp;
54457+ struct role_transition *trans;
54458+ unsigned int i;
54459+ int found = 0;
54460+ u32 curr_ip = current->signal->curr_ip;
54461+
54462+ current->signal->saved_ip = curr_ip;
54463+
54464+ /* check transition table */
54465+
54466+ for (trans = current->role->transitions; trans; trans = trans->next) {
54467+ if (!strcmp(rolename, trans->rolename)) {
54468+ found = 1;
54469+ break;
54470+ }
54471+ }
54472+
54473+ if (!found)
54474+ return 0;
54475+
54476+ /* handle special roles that do not require authentication
54477+ and check ip */
54478+
54479+ FOR_EACH_ROLE_START(r)
54480+ if (!strcmp(rolename, r->rolename) &&
54481+ (r->roletype & GR_ROLE_SPECIAL)) {
54482+ found = 0;
54483+ if (r->allowed_ips != NULL) {
54484+ for (ipp = r->allowed_ips; ipp; ipp = ipp->next) {
54485+ if ((ntohl(curr_ip) & ipp->netmask) ==
54486+ (ntohl(ipp->addr) & ipp->netmask))
54487+ found = 1;
54488+ }
54489+ } else
54490+ found = 2;
54491+ if (!found)
54492+ return 0;
54493+
54494+ if (((mode == GR_SPROLE) && (r->roletype & GR_ROLE_NOPW)) ||
54495+ ((mode == GR_SPROLEPAM) && (r->roletype & GR_ROLE_PAM))) {
54496+ *salt = NULL;
54497+ *sum = NULL;
54498+ return 1;
54499+ }
54500+ }
54501+ FOR_EACH_ROLE_END(r)
54502+
54503+ for (i = 0; i < num_sprole_pws; i++) {
54504+ if (!strcmp(rolename, acl_special_roles[i]->rolename)) {
54505+ *salt = acl_special_roles[i]->salt;
54506+ *sum = acl_special_roles[i]->sum;
54507+ return 1;
54508+ }
54509+ }
54510+
54511+ return 0;
54512+}
54513+
54514+static void
54515+assign_special_role(char *rolename)
54516+{
54517+ struct acl_object_label *obj;
54518+ struct acl_role_label *r;
54519+ struct acl_role_label *assigned = NULL;
54520+ struct task_struct *tsk;
54521+ struct file *filp;
54522+
54523+ FOR_EACH_ROLE_START(r)
54524+ if (!strcmp(rolename, r->rolename) &&
54525+ (r->roletype & GR_ROLE_SPECIAL)) {
54526+ assigned = r;
54527+ break;
54528+ }
54529+ FOR_EACH_ROLE_END(r)
54530+
54531+ if (!assigned)
54532+ return;
54533+
54534+ read_lock(&tasklist_lock);
54535+ read_lock(&grsec_exec_file_lock);
54536+
54537+ tsk = current->real_parent;
54538+ if (tsk == NULL)
54539+ goto out_unlock;
54540+
54541+ filp = tsk->exec_file;
54542+ if (filp == NULL)
54543+ goto out_unlock;
54544+
54545+ tsk->is_writable = 0;
54546+
54547+ tsk->acl_sp_role = 1;
54548+ tsk->acl_role_id = ++acl_sp_role_value;
54549+ tsk->role = assigned;
54550+ tsk->acl = chk_subj_label(filp->f_path.dentry, filp->f_path.mnt, tsk->role);
54551+
54552+ /* ignore additional mmap checks for processes that are writable
54553+ by the default ACL */
54554+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, default_role->root_label);
54555+ if (unlikely(obj->mode & GR_WRITE))
54556+ tsk->is_writable = 1;
54557+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, tsk->role->root_label);
54558+ if (unlikely(obj->mode & GR_WRITE))
54559+ tsk->is_writable = 1;
54560+
54561+#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
54562+ printk(KERN_ALERT "Assigning special role:%s subject:%s to process (%s:%d)\n", tsk->role->rolename, tsk->acl->filename, tsk->comm, tsk->pid);
54563+#endif
54564+
54565+out_unlock:
54566+ read_unlock(&grsec_exec_file_lock);
54567+ read_unlock(&tasklist_lock);
54568+ return;
54569+}
54570+
54571+int gr_check_secure_terminal(struct task_struct *task)
54572+{
54573+ struct task_struct *p, *p2, *p3;
54574+ struct files_struct *files;
54575+ struct fdtable *fdt;
54576+ struct file *our_file = NULL, *file;
54577+ int i;
54578+
54579+ if (task->signal->tty == NULL)
54580+ return 1;
54581+
54582+ files = get_files_struct(task);
54583+ if (files != NULL) {
54584+ rcu_read_lock();
54585+ fdt = files_fdtable(files);
54586+ for (i=0; i < fdt->max_fds; i++) {
54587+ file = fcheck_files(files, i);
54588+ if (file && (our_file == NULL) && (file->private_data == task->signal->tty)) {
54589+ get_file(file);
54590+ our_file = file;
54591+ }
54592+ }
54593+ rcu_read_unlock();
54594+ put_files_struct(files);
54595+ }
54596+
54597+ if (our_file == NULL)
54598+ return 1;
54599+
54600+ read_lock(&tasklist_lock);
54601+ do_each_thread(p2, p) {
54602+ files = get_files_struct(p);
54603+ if (files == NULL ||
54604+ (p->signal && p->signal->tty == task->signal->tty)) {
54605+ if (files != NULL)
54606+ put_files_struct(files);
54607+ continue;
54608+ }
54609+ rcu_read_lock();
54610+ fdt = files_fdtable(files);
54611+ for (i=0; i < fdt->max_fds; i++) {
54612+ file = fcheck_files(files, i);
54613+ if (file && S_ISCHR(file->f_path.dentry->d_inode->i_mode) &&
54614+ file->f_path.dentry->d_inode->i_rdev == our_file->f_path.dentry->d_inode->i_rdev) {
54615+ p3 = task;
54616+ while (p3->pid > 0) {
54617+ if (p3 == p)
54618+ break;
54619+ p3 = p3->real_parent;
54620+ }
54621+ if (p3 == p)
54622+ break;
54623+ gr_log_ttysniff(GR_DONT_AUDIT_GOOD, GR_TTYSNIFF_ACL_MSG, p);
54624+ gr_handle_alertkill(p);
54625+ rcu_read_unlock();
54626+ put_files_struct(files);
54627+ read_unlock(&tasklist_lock);
54628+ fput(our_file);
54629+ return 0;
54630+ }
54631+ }
54632+ rcu_read_unlock();
54633+ put_files_struct(files);
54634+ } while_each_thread(p2, p);
54635+ read_unlock(&tasklist_lock);
54636+
54637+ fput(our_file);
54638+ return 1;
54639+}
54640+
54641+static int gr_rbac_disable(void *unused)
54642+{
54643+ pax_open_kernel();
54644+ gr_status &= ~GR_READY;
54645+ pax_close_kernel();
54646+
54647+ return 0;
54648+}
54649+
54650+ssize_t
54651+write_grsec_handler(struct file *file, const char * buf, size_t count, loff_t *ppos)
54652+{
54653+ struct gr_arg_wrapper uwrap;
54654+ unsigned char *sprole_salt = NULL;
54655+ unsigned char *sprole_sum = NULL;
54656+ int error = sizeof (struct gr_arg_wrapper);
54657+ int error2 = 0;
54658+
54659+ mutex_lock(&gr_dev_mutex);
54660+
54661+ if ((gr_status & GR_READY) && !(current->acl->mode & GR_KERNELAUTH)) {
54662+ error = -EPERM;
54663+ goto out;
54664+ }
54665+
54666+ if (count != sizeof (struct gr_arg_wrapper)) {
54667+ gr_log_int_int(GR_DONT_AUDIT_GOOD, GR_DEV_ACL_MSG, (int)count, (int)sizeof(struct gr_arg_wrapper));
54668+ error = -EINVAL;
54669+ goto out;
54670+ }
54671+
54672+
54673+ if (gr_auth_expires && time_after_eq(get_seconds(), gr_auth_expires)) {
54674+ gr_auth_expires = 0;
54675+ gr_auth_attempts = 0;
54676+ }
54677+
54678+ if (copy_from_user(&uwrap, buf, sizeof (struct gr_arg_wrapper))) {
54679+ error = -EFAULT;
54680+ goto out;
54681+ }
54682+
54683+ if ((uwrap.version != GRSECURITY_VERSION) || (uwrap.size != sizeof(struct gr_arg))) {
54684+ error = -EINVAL;
54685+ goto out;
54686+ }
54687+
54688+ if (copy_from_user(gr_usermode, uwrap.arg, sizeof (struct gr_arg))) {
54689+ error = -EFAULT;
54690+ goto out;
54691+ }
54692+
54693+ if (gr_usermode->mode != GR_SPROLE && gr_usermode->mode != GR_SPROLEPAM &&
54694+ gr_auth_attempts >= CONFIG_GRKERNSEC_ACL_MAXTRIES &&
54695+ time_after(gr_auth_expires, get_seconds())) {
54696+ error = -EBUSY;
54697+ goto out;
54698+ }
54699+
54700+ /* if non-root trying to do anything other than use a special role,
54701+ do not attempt authentication, do not count towards authentication
54702+ locking
54703+ */
54704+
54705+ if (gr_usermode->mode != GR_SPROLE && gr_usermode->mode != GR_STATUS &&
54706+ gr_usermode->mode != GR_UNSPROLE && gr_usermode->mode != GR_SPROLEPAM &&
54707+ !uid_eq(current_uid(), GLOBAL_ROOT_UID)) {
54708+ error = -EPERM;
54709+ goto out;
54710+ }
54711+
54712+ /* ensure pw and special role name are null terminated */
54713+
54714+ gr_usermode->pw[GR_PW_LEN - 1] = '\0';
54715+ gr_usermode->sp_role[GR_SPROLE_LEN - 1] = '\0';
54716+
54717+ /* Okay.
54718+ * We have our enough of the argument structure..(we have yet
54719+ * to copy_from_user the tables themselves) . Copy the tables
54720+ * only if we need them, i.e. for loading operations. */
54721+
54722+ switch (gr_usermode->mode) {
54723+ case GR_STATUS:
54724+ if (gr_status & GR_READY) {
54725+ error = 1;
54726+ if (!gr_check_secure_terminal(current))
54727+ error = 3;
54728+ } else
54729+ error = 2;
54730+ goto out;
54731+ case GR_SHUTDOWN:
54732+ if ((gr_status & GR_READY)
54733+ && !(chkpw(gr_usermode, gr_system_salt, gr_system_sum))) {
54734+ stop_machine(gr_rbac_disable, NULL, NULL);
54735+ free_variables();
54736+ memset(gr_usermode, 0, sizeof (struct gr_arg));
54737+ memset(gr_system_salt, 0, GR_SALT_LEN);
54738+ memset(gr_system_sum, 0, GR_SHA_LEN);
54739+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SHUTS_ACL_MSG);
54740+ } else if (gr_status & GR_READY) {
54741+ gr_log_noargs(GR_DONT_AUDIT, GR_SHUTF_ACL_MSG);
54742+ error = -EPERM;
54743+ } else {
54744+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SHUTI_ACL_MSG);
54745+ error = -EAGAIN;
54746+ }
54747+ break;
54748+ case GR_ENABLE:
54749+ if (!(gr_status & GR_READY) && !(error2 = gracl_init(gr_usermode)))
54750+ gr_log_str(GR_DONT_AUDIT_GOOD, GR_ENABLE_ACL_MSG, GR_VERSION);
54751+ else {
54752+ if (gr_status & GR_READY)
54753+ error = -EAGAIN;
54754+ else
54755+ error = error2;
54756+ gr_log_str(GR_DONT_AUDIT, GR_ENABLEF_ACL_MSG, GR_VERSION);
54757+ }
54758+ break;
54759+ case GR_RELOAD:
54760+ if (!(gr_status & GR_READY)) {
54761+ gr_log_str(GR_DONT_AUDIT_GOOD, GR_RELOADI_ACL_MSG, GR_VERSION);
54762+ error = -EAGAIN;
54763+ } else if (!(chkpw(gr_usermode, gr_system_salt, gr_system_sum))) {
54764+ stop_machine(gr_rbac_disable, NULL, NULL);
54765+ free_variables();
54766+ error2 = gracl_init(gr_usermode);
54767+ if (!error2)
54768+ gr_log_str(GR_DONT_AUDIT_GOOD, GR_RELOAD_ACL_MSG, GR_VERSION);
54769+ else {
54770+ gr_log_str(GR_DONT_AUDIT, GR_RELOADF_ACL_MSG, GR_VERSION);
54771+ error = error2;
54772+ }
54773+ } else {
54774+ gr_log_str(GR_DONT_AUDIT, GR_RELOADF_ACL_MSG, GR_VERSION);
54775+ error = -EPERM;
54776+ }
54777+ break;
54778+ case GR_SEGVMOD:
54779+ if (unlikely(!(gr_status & GR_READY))) {
54780+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SEGVMODI_ACL_MSG);
54781+ error = -EAGAIN;
54782+ break;
54783+ }
54784+
54785+ if (!(chkpw(gr_usermode, gr_system_salt, gr_system_sum))) {
54786+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SEGVMODS_ACL_MSG);
54787+ if (gr_usermode->segv_device && gr_usermode->segv_inode) {
54788+ struct acl_subject_label *segvacl;
54789+ segvacl =
54790+ lookup_acl_subj_label(gr_usermode->segv_inode,
54791+ gr_usermode->segv_device,
54792+ current->role);
54793+ if (segvacl) {
54794+ segvacl->crashes = 0;
54795+ segvacl->expires = 0;
54796+ }
54797+ } else if (gr_find_uid(gr_usermode->segv_uid) >= 0) {
54798+ gr_remove_uid(gr_usermode->segv_uid);
54799+ }
54800+ } else {
54801+ gr_log_noargs(GR_DONT_AUDIT, GR_SEGVMODF_ACL_MSG);
54802+ error = -EPERM;
54803+ }
54804+ break;
54805+ case GR_SPROLE:
54806+ case GR_SPROLEPAM:
54807+ if (unlikely(!(gr_status & GR_READY))) {
54808+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SPROLEI_ACL_MSG);
54809+ error = -EAGAIN;
54810+ break;
54811+ }
54812+
54813+ if (current->role->expires && time_after_eq(get_seconds(), current->role->expires)) {
54814+ current->role->expires = 0;
54815+ current->role->auth_attempts = 0;
54816+ }
54817+
54818+ if (current->role->auth_attempts >= CONFIG_GRKERNSEC_ACL_MAXTRIES &&
54819+ time_after(current->role->expires, get_seconds())) {
54820+ error = -EBUSY;
54821+ goto out;
54822+ }
54823+
54824+ if (lookup_special_role_auth
54825+ (gr_usermode->mode, gr_usermode->sp_role, &sprole_salt, &sprole_sum)
54826+ && ((!sprole_salt && !sprole_sum)
54827+ || !(chkpw(gr_usermode, sprole_salt, sprole_sum)))) {
54828+ char *p = "";
54829+ assign_special_role(gr_usermode->sp_role);
54830+ read_lock(&tasklist_lock);
54831+ if (current->real_parent)
54832+ p = current->real_parent->role->rolename;
54833+ read_unlock(&tasklist_lock);
54834+ gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_SPROLES_ACL_MSG,
54835+ p, acl_sp_role_value);
54836+ } else {
54837+ gr_log_str(GR_DONT_AUDIT, GR_SPROLEF_ACL_MSG, gr_usermode->sp_role);
54838+ error = -EPERM;
54839+ if(!(current->role->auth_attempts++))
54840+ current->role->expires = get_seconds() + CONFIG_GRKERNSEC_ACL_TIMEOUT;
54841+
54842+ goto out;
54843+ }
54844+ break;
54845+ case GR_UNSPROLE:
54846+ if (unlikely(!(gr_status & GR_READY))) {
54847+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_UNSPROLEI_ACL_MSG);
54848+ error = -EAGAIN;
54849+ break;
54850+ }
54851+
54852+ if (current->role->roletype & GR_ROLE_SPECIAL) {
54853+ char *p = "";
54854+ int i = 0;
54855+
54856+ read_lock(&tasklist_lock);
54857+ if (current->real_parent) {
54858+ p = current->real_parent->role->rolename;
54859+ i = current->real_parent->acl_role_id;
54860+ }
54861+ read_unlock(&tasklist_lock);
54862+
54863+ gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_UNSPROLES_ACL_MSG, p, i);
54864+ gr_set_acls(1);
54865+ } else {
54866+ error = -EPERM;
54867+ goto out;
54868+ }
54869+ break;
54870+ default:
54871+ gr_log_int(GR_DONT_AUDIT, GR_INVMODE_ACL_MSG, gr_usermode->mode);
54872+ error = -EINVAL;
54873+ break;
54874+ }
54875+
54876+ if (error != -EPERM)
54877+ goto out;
54878+
54879+ if(!(gr_auth_attempts++))
54880+ gr_auth_expires = get_seconds() + CONFIG_GRKERNSEC_ACL_TIMEOUT;
54881+
54882+ out:
54883+ mutex_unlock(&gr_dev_mutex);
54884+ return error;
54885+}
54886+
54887+/* must be called with
54888+ rcu_read_lock();
54889+ read_lock(&tasklist_lock);
54890+ read_lock(&grsec_exec_file_lock);
54891+*/
54892+int gr_apply_subject_to_task(struct task_struct *task)
54893+{
54894+ struct acl_object_label *obj;
54895+ char *tmpname;
54896+ struct acl_subject_label *tmpsubj;
54897+ struct file *filp;
54898+ struct name_entry *nmatch;
54899+
54900+ filp = task->exec_file;
54901+ if (filp == NULL)
54902+ return 0;
54903+
54904+ /* the following is to apply the correct subject
54905+ on binaries running when the RBAC system
54906+ is enabled, when the binaries have been
54907+ replaced or deleted since their execution
54908+ -----
54909+ when the RBAC system starts, the inode/dev
54910+ from exec_file will be one the RBAC system
54911+ is unaware of. It only knows the inode/dev
54912+ of the present file on disk, or the absence
54913+ of it.
54914+ */
54915+ preempt_disable();
54916+ tmpname = gr_to_filename_rbac(filp->f_path.dentry, filp->f_path.mnt);
54917+
54918+ nmatch = lookup_name_entry(tmpname);
54919+ preempt_enable();
54920+ tmpsubj = NULL;
54921+ if (nmatch) {
54922+ if (nmatch->deleted)
54923+ tmpsubj = lookup_acl_subj_label_deleted(nmatch->inode, nmatch->device, task->role);
54924+ else
54925+ tmpsubj = lookup_acl_subj_label(nmatch->inode, nmatch->device, task->role);
54926+ if (tmpsubj != NULL)
54927+ task->acl = tmpsubj;
54928+ }
54929+ if (tmpsubj == NULL)
54930+ task->acl = chk_subj_label(filp->f_path.dentry, filp->f_path.mnt,
54931+ task->role);
54932+ if (task->acl) {
54933+ task->is_writable = 0;
54934+ /* ignore additional mmap checks for processes that are writable
54935+ by the default ACL */
54936+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, default_role->root_label);
54937+ if (unlikely(obj->mode & GR_WRITE))
54938+ task->is_writable = 1;
54939+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, task->role->root_label);
54940+ if (unlikely(obj->mode & GR_WRITE))
54941+ task->is_writable = 1;
54942+
54943+ gr_set_proc_res(task);
54944+
54945+#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
54946+ printk(KERN_ALERT "gr_set_acls for (%s:%d): role:%s, subject:%s\n", task->comm, task->pid, task->role->rolename, task->acl->filename);
54947+#endif
54948+ } else {
54949+ return 1;
54950+ }
54951+
54952+ return 0;
54953+}
54954+
54955+int
54956+gr_set_acls(const int type)
54957+{
54958+ struct task_struct *task, *task2;
54959+ struct acl_role_label *role = current->role;
54960+ __u16 acl_role_id = current->acl_role_id;
54961+ const struct cred *cred;
54962+ int ret;
54963+
54964+ rcu_read_lock();
54965+ read_lock(&tasklist_lock);
54966+ read_lock(&grsec_exec_file_lock);
54967+ do_each_thread(task2, task) {
54968+ /* check to see if we're called from the exit handler,
54969+ if so, only replace ACLs that have inherited the admin
54970+ ACL */
54971+
54972+ if (type && (task->role != role ||
54973+ task->acl_role_id != acl_role_id))
54974+ continue;
54975+
54976+ task->acl_role_id = 0;
54977+ task->acl_sp_role = 0;
54978+
54979+ if (task->exec_file) {
54980+ cred = __task_cred(task);
54981+ task->role = lookup_acl_role_label(task, cred->uid, cred->gid);
54982+ ret = gr_apply_subject_to_task(task);
54983+ if (ret) {
54984+ read_unlock(&grsec_exec_file_lock);
54985+ read_unlock(&tasklist_lock);
54986+ rcu_read_unlock();
54987+ gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_DEFACL_MSG, task->comm, task->pid);
54988+ return ret;
54989+ }
54990+ } else {
54991+ // it's a kernel process
54992+ task->role = kernel_role;
54993+ task->acl = kernel_role->root_label;
54994+#ifdef CONFIG_GRKERNSEC_ACL_HIDEKERN
54995+ task->acl->mode &= ~GR_PROCFIND;
54996+#endif
54997+ }
54998+ } while_each_thread(task2, task);
54999+ read_unlock(&grsec_exec_file_lock);
55000+ read_unlock(&tasklist_lock);
55001+ rcu_read_unlock();
55002+
55003+ return 0;
55004+}
55005+
55006+void
55007+gr_learn_resource(const struct task_struct *task,
55008+ const int res, const unsigned long wanted, const int gt)
55009+{
55010+ struct acl_subject_label *acl;
55011+ const struct cred *cred;
55012+
55013+ if (unlikely((gr_status & GR_READY) &&
55014+ task->acl && (task->acl->mode & (GR_LEARN | GR_INHERITLEARN))))
55015+ goto skip_reslog;
55016+
55017+#ifdef CONFIG_GRKERNSEC_RESLOG
55018+ gr_log_resource(task, res, wanted, gt);
55019+#endif
55020+ skip_reslog:
55021+
55022+ if (unlikely(!(gr_status & GR_READY) || !wanted || res >= GR_NLIMITS))
55023+ return;
55024+
55025+ acl = task->acl;
55026+
55027+ if (likely(!acl || !(acl->mode & (GR_LEARN | GR_INHERITLEARN)) ||
55028+ !(acl->resmask & (1 << (unsigned short) res))))
55029+ return;
55030+
55031+ if (wanted >= acl->res[res].rlim_cur) {
55032+ unsigned long res_add;
55033+
55034+ res_add = wanted;
55035+ switch (res) {
55036+ case RLIMIT_CPU:
55037+ res_add += GR_RLIM_CPU_BUMP;
55038+ break;
55039+ case RLIMIT_FSIZE:
55040+ res_add += GR_RLIM_FSIZE_BUMP;
55041+ break;
55042+ case RLIMIT_DATA:
55043+ res_add += GR_RLIM_DATA_BUMP;
55044+ break;
55045+ case RLIMIT_STACK:
55046+ res_add += GR_RLIM_STACK_BUMP;
55047+ break;
55048+ case RLIMIT_CORE:
55049+ res_add += GR_RLIM_CORE_BUMP;
55050+ break;
55051+ case RLIMIT_RSS:
55052+ res_add += GR_RLIM_RSS_BUMP;
55053+ break;
55054+ case RLIMIT_NPROC:
55055+ res_add += GR_RLIM_NPROC_BUMP;
55056+ break;
55057+ case RLIMIT_NOFILE:
55058+ res_add += GR_RLIM_NOFILE_BUMP;
55059+ break;
55060+ case RLIMIT_MEMLOCK:
55061+ res_add += GR_RLIM_MEMLOCK_BUMP;
55062+ break;
55063+ case RLIMIT_AS:
55064+ res_add += GR_RLIM_AS_BUMP;
55065+ break;
55066+ case RLIMIT_LOCKS:
55067+ res_add += GR_RLIM_LOCKS_BUMP;
55068+ break;
55069+ case RLIMIT_SIGPENDING:
55070+ res_add += GR_RLIM_SIGPENDING_BUMP;
55071+ break;
55072+ case RLIMIT_MSGQUEUE:
55073+ res_add += GR_RLIM_MSGQUEUE_BUMP;
55074+ break;
55075+ case RLIMIT_NICE:
55076+ res_add += GR_RLIM_NICE_BUMP;
55077+ break;
55078+ case RLIMIT_RTPRIO:
55079+ res_add += GR_RLIM_RTPRIO_BUMP;
55080+ break;
55081+ case RLIMIT_RTTIME:
55082+ res_add += GR_RLIM_RTTIME_BUMP;
55083+ break;
55084+ }
55085+
55086+ acl->res[res].rlim_cur = res_add;
55087+
55088+ if (wanted > acl->res[res].rlim_max)
55089+ acl->res[res].rlim_max = res_add;
55090+
55091+ /* only log the subject filename, since resource logging is supported for
55092+ single-subject learning only */
55093+ rcu_read_lock();
55094+ cred = __task_cred(task);
55095+ security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename,
55096+ task->role->roletype, cred->uid, cred->gid, acl->filename,
55097+ acl->filename, acl->res[res].rlim_cur, acl->res[res].rlim_max,
55098+ "", (unsigned long) res, &task->signal->saved_ip);
55099+ rcu_read_unlock();
55100+ }
55101+
55102+ return;
55103+}
55104+
55105+#if defined(CONFIG_PAX_HAVE_ACL_FLAGS) && (defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR))
55106+void
55107+pax_set_initial_flags(struct linux_binprm *bprm)
55108+{
55109+ struct task_struct *task = current;
55110+ struct acl_subject_label *proc;
55111+ unsigned long flags;
55112+
55113+ if (unlikely(!(gr_status & GR_READY)))
55114+ return;
55115+
55116+ flags = pax_get_flags(task);
55117+
55118+ proc = task->acl;
55119+
55120+ if (proc->pax_flags & GR_PAX_DISABLE_PAGEEXEC)
55121+ flags &= ~MF_PAX_PAGEEXEC;
55122+ if (proc->pax_flags & GR_PAX_DISABLE_SEGMEXEC)
55123+ flags &= ~MF_PAX_SEGMEXEC;
55124+ if (proc->pax_flags & GR_PAX_DISABLE_RANDMMAP)
55125+ flags &= ~MF_PAX_RANDMMAP;
55126+ if (proc->pax_flags & GR_PAX_DISABLE_EMUTRAMP)
55127+ flags &= ~MF_PAX_EMUTRAMP;
55128+ if (proc->pax_flags & GR_PAX_DISABLE_MPROTECT)
55129+ flags &= ~MF_PAX_MPROTECT;
55130+
55131+ if (proc->pax_flags & GR_PAX_ENABLE_PAGEEXEC)
55132+ flags |= MF_PAX_PAGEEXEC;
55133+ if (proc->pax_flags & GR_PAX_ENABLE_SEGMEXEC)
55134+ flags |= MF_PAX_SEGMEXEC;
55135+ if (proc->pax_flags & GR_PAX_ENABLE_RANDMMAP)
55136+ flags |= MF_PAX_RANDMMAP;
55137+ if (proc->pax_flags & GR_PAX_ENABLE_EMUTRAMP)
55138+ flags |= MF_PAX_EMUTRAMP;
55139+ if (proc->pax_flags & GR_PAX_ENABLE_MPROTECT)
55140+ flags |= MF_PAX_MPROTECT;
55141+
55142+ pax_set_flags(task, flags);
55143+
55144+ return;
55145+}
55146+#endif
55147+
55148+int
55149+gr_handle_proc_ptrace(struct task_struct *task)
55150+{
55151+ struct file *filp;
55152+ struct task_struct *tmp = task;
55153+ struct task_struct *curtemp = current;
55154+ __u32 retmode;
55155+
55156+#ifndef CONFIG_GRKERNSEC_HARDEN_PTRACE
55157+ if (unlikely(!(gr_status & GR_READY)))
55158+ return 0;
55159+#endif
55160+
55161+ read_lock(&tasklist_lock);
55162+ read_lock(&grsec_exec_file_lock);
55163+ filp = task->exec_file;
55164+
55165+ while (tmp->pid > 0) {
55166+ if (tmp == curtemp)
55167+ break;
55168+ tmp = tmp->real_parent;
55169+ }
55170+
55171+ if (!filp || (tmp->pid == 0 && ((grsec_enable_harden_ptrace && !uid_eq(current_uid(), GLOBAL_ROOT_UID) && !(gr_status & GR_READY)) ||
55172+ ((gr_status & GR_READY) && !(current->acl->mode & GR_RELAXPTRACE))))) {
55173+ read_unlock(&grsec_exec_file_lock);
55174+ read_unlock(&tasklist_lock);
55175+ return 1;
55176+ }
55177+
55178+#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
55179+ if (!(gr_status & GR_READY)) {
55180+ read_unlock(&grsec_exec_file_lock);
55181+ read_unlock(&tasklist_lock);
55182+ return 0;
55183+ }
55184+#endif
55185+
55186+ retmode = gr_search_file(filp->f_path.dentry, GR_NOPTRACE, filp->f_path.mnt);
55187+ read_unlock(&grsec_exec_file_lock);
55188+ read_unlock(&tasklist_lock);
55189+
55190+ if (retmode & GR_NOPTRACE)
55191+ return 1;
55192+
55193+ if (!(current->acl->mode & GR_POVERRIDE) && !(current->role->roletype & GR_ROLE_GOD)
55194+ && (current->acl != task->acl || (current->acl != current->role->root_label
55195+ && current->pid != task->pid)))
55196+ return 1;
55197+
55198+ return 0;
55199+}
55200+
55201+void task_grsec_rbac(struct seq_file *m, struct task_struct *p)
55202+{
55203+ if (unlikely(!(gr_status & GR_READY)))
55204+ return;
55205+
55206+ if (!(current->role->roletype & GR_ROLE_GOD))
55207+ return;
55208+
55209+ seq_printf(m, "RBAC:\t%.64s:%c:%.950s\n",
55210+ p->role->rolename, gr_task_roletype_to_char(p),
55211+ p->acl->filename);
55212+}
55213+
55214+int
55215+gr_handle_ptrace(struct task_struct *task, const long request)
55216+{
55217+ struct task_struct *tmp = task;
55218+ struct task_struct *curtemp = current;
55219+ __u32 retmode;
55220+
55221+#ifndef CONFIG_GRKERNSEC_HARDEN_PTRACE
55222+ if (unlikely(!(gr_status & GR_READY)))
55223+ return 0;
55224+#endif
55225+ if (request == PTRACE_ATTACH || request == PTRACE_SEIZE) {
55226+ read_lock(&tasklist_lock);
55227+ while (tmp->pid > 0) {
55228+ if (tmp == curtemp)
55229+ break;
55230+ tmp = tmp->real_parent;
55231+ }
55232+
55233+ if (tmp->pid == 0 && ((grsec_enable_harden_ptrace && !uid_eq(current_uid(), GLOBAL_ROOT_UID) && !(gr_status & GR_READY)) ||
55234+ ((gr_status & GR_READY) && !(current->acl->mode & GR_RELAXPTRACE)))) {
55235+ read_unlock(&tasklist_lock);
55236+ gr_log_ptrace(GR_DONT_AUDIT, GR_PTRACE_ACL_MSG, task);
55237+ return 1;
55238+ }
55239+ read_unlock(&tasklist_lock);
55240+ }
55241+
55242+#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
55243+ if (!(gr_status & GR_READY))
55244+ return 0;
55245+#endif
55246+
55247+ read_lock(&grsec_exec_file_lock);
55248+ if (unlikely(!task->exec_file)) {
55249+ read_unlock(&grsec_exec_file_lock);
55250+ return 0;
55251+ }
55252+
55253+ retmode = gr_search_file(task->exec_file->f_path.dentry, GR_PTRACERD | GR_NOPTRACE, task->exec_file->f_path.mnt);
55254+ read_unlock(&grsec_exec_file_lock);
55255+
55256+ if (retmode & GR_NOPTRACE) {
55257+ gr_log_ptrace(GR_DONT_AUDIT, GR_PTRACE_ACL_MSG, task);
55258+ return 1;
55259+ }
55260+
55261+ if (retmode & GR_PTRACERD) {
55262+ switch (request) {
55263+ case PTRACE_SEIZE:
55264+ case PTRACE_POKETEXT:
55265+ case PTRACE_POKEDATA:
55266+ case PTRACE_POKEUSR:
55267+#if !defined(CONFIG_PPC32) && !defined(CONFIG_PPC64) && !defined(CONFIG_PARISC) && !defined(CONFIG_ALPHA) && !defined(CONFIG_IA64)
55268+ case PTRACE_SETREGS:
55269+ case PTRACE_SETFPREGS:
55270+#endif
55271+#ifdef CONFIG_X86
55272+ case PTRACE_SETFPXREGS:
55273+#endif
55274+#ifdef CONFIG_ALTIVEC
55275+ case PTRACE_SETVRREGS:
55276+#endif
55277+ return 1;
55278+ default:
55279+ return 0;
55280+ }
55281+ } else if (!(current->acl->mode & GR_POVERRIDE) &&
55282+ !(current->role->roletype & GR_ROLE_GOD) &&
55283+ (current->acl != task->acl)) {
55284+ gr_log_ptrace(GR_DONT_AUDIT, GR_PTRACE_ACL_MSG, task);
55285+ return 1;
55286+ }
55287+
55288+ return 0;
55289+}
55290+
55291+static int is_writable_mmap(const struct file *filp)
55292+{
55293+ struct task_struct *task = current;
55294+ struct acl_object_label *obj, *obj2;
55295+
55296+ if (gr_status & GR_READY && !(task->acl->mode & GR_OVERRIDE) &&
55297+ !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))) {
55298+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, default_role->root_label);
55299+ obj2 = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt,
55300+ task->role->root_label);
55301+ if (unlikely((obj->mode & GR_WRITE) || (obj2->mode & GR_WRITE))) {
55302+ gr_log_fs_generic(GR_DONT_AUDIT, GR_WRITLIB_ACL_MSG, filp->f_path.dentry, filp->f_path.mnt);
55303+ return 1;
55304+ }
55305+ }
55306+ return 0;
55307+}
55308+
55309+int
55310+gr_acl_handle_mmap(const struct file *file, const unsigned long prot)
55311+{
55312+ __u32 mode;
55313+
55314+ if (unlikely(!file || !(prot & PROT_EXEC)))
55315+ return 1;
55316+
55317+ if (is_writable_mmap(file))
55318+ return 0;
55319+
55320+ mode =
55321+ gr_search_file(file->f_path.dentry,
55322+ GR_EXEC | GR_AUDIT_EXEC | GR_SUPPRESS,
55323+ file->f_path.mnt);
55324+
55325+ if (!gr_tpe_allow(file))
55326+ return 0;
55327+
55328+ if (unlikely(!(mode & GR_EXEC) && !(mode & GR_SUPPRESS))) {
55329+ gr_log_fs_rbac_generic(GR_DONT_AUDIT, GR_MMAP_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
55330+ return 0;
55331+ } else if (unlikely(!(mode & GR_EXEC))) {
55332+ return 0;
55333+ } else if (unlikely(mode & GR_EXEC && mode & GR_AUDIT_EXEC)) {
55334+ gr_log_fs_rbac_generic(GR_DO_AUDIT, GR_MMAP_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
55335+ return 1;
55336+ }
55337+
55338+ return 1;
55339+}
55340+
55341+int
55342+gr_acl_handle_mprotect(const struct file *file, const unsigned long prot)
55343+{
55344+ __u32 mode;
55345+
55346+ if (unlikely(!file || !(prot & PROT_EXEC)))
55347+ return 1;
55348+
55349+ if (is_writable_mmap(file))
55350+ return 0;
55351+
55352+ mode =
55353+ gr_search_file(file->f_path.dentry,
55354+ GR_EXEC | GR_AUDIT_EXEC | GR_SUPPRESS,
55355+ file->f_path.mnt);
55356+
55357+ if (!gr_tpe_allow(file))
55358+ return 0;
55359+
55360+ if (unlikely(!(mode & GR_EXEC) && !(mode & GR_SUPPRESS))) {
55361+ gr_log_fs_rbac_generic(GR_DONT_AUDIT, GR_MPROTECT_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
55362+ return 0;
55363+ } else if (unlikely(!(mode & GR_EXEC))) {
55364+ return 0;
55365+ } else if (unlikely(mode & GR_EXEC && mode & GR_AUDIT_EXEC)) {
55366+ gr_log_fs_rbac_generic(GR_DO_AUDIT, GR_MPROTECT_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
55367+ return 1;
55368+ }
55369+
55370+ return 1;
55371+}
55372+
55373+void
55374+gr_acl_handle_psacct(struct task_struct *task, const long code)
55375+{
55376+ unsigned long runtime;
55377+ unsigned long cputime;
55378+ unsigned int wday, cday;
55379+ __u8 whr, chr;
55380+ __u8 wmin, cmin;
55381+ __u8 wsec, csec;
55382+ struct timespec timeval;
55383+
55384+ if (unlikely(!(gr_status & GR_READY) || !task->acl ||
55385+ !(task->acl->mode & GR_PROCACCT)))
55386+ return;
55387+
55388+ do_posix_clock_monotonic_gettime(&timeval);
55389+ runtime = timeval.tv_sec - task->start_time.tv_sec;
55390+ wday = runtime / (3600 * 24);
55391+ runtime -= wday * (3600 * 24);
55392+ whr = runtime / 3600;
55393+ runtime -= whr * 3600;
55394+ wmin = runtime / 60;
55395+ runtime -= wmin * 60;
55396+ wsec = runtime;
55397+
55398+ cputime = (task->utime + task->stime) / HZ;
55399+ cday = cputime / (3600 * 24);
55400+ cputime -= cday * (3600 * 24);
55401+ chr = cputime / 3600;
55402+ cputime -= chr * 3600;
55403+ cmin = cputime / 60;
55404+ cputime -= cmin * 60;
55405+ csec = cputime;
55406+
55407+ gr_log_procacct(GR_DO_AUDIT, GR_ACL_PROCACCT_MSG, task, wday, whr, wmin, wsec, cday, chr, cmin, csec, code);
55408+
55409+ return;
55410+}
55411+
55412+void gr_set_kernel_label(struct task_struct *task)
55413+{
55414+ if (gr_status & GR_READY) {
55415+ task->role = kernel_role;
55416+ task->acl = kernel_role->root_label;
55417+ }
55418+ return;
55419+}
55420+
55421+#ifdef CONFIG_TASKSTATS
55422+int gr_is_taskstats_denied(int pid)
55423+{
55424+ struct task_struct *task;
55425+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
55426+ const struct cred *cred;
55427+#endif
55428+ int ret = 0;
55429+
55430+ /* restrict taskstats viewing to un-chrooted root users
55431+ who have the 'view' subject flag if the RBAC system is enabled
55432+ */
55433+
55434+ rcu_read_lock();
55435+ read_lock(&tasklist_lock);
55436+ task = find_task_by_vpid(pid);
55437+ if (task) {
55438+#ifdef CONFIG_GRKERNSEC_CHROOT
55439+ if (proc_is_chrooted(task))
55440+ ret = -EACCES;
55441+#endif
55442+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
55443+ cred = __task_cred(task);
55444+#ifdef CONFIG_GRKERNSEC_PROC_USER
55445+ if (!uid_eq(cred->uid, GLOBAL_ROOT_UID))
55446+ ret = -EACCES;
55447+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
55448+ if (!uid_eq(cred->uid, GLOBAL_ROOT_UID) && !groups_search(cred->group_info, grsec_proc_gid))
55449+ ret = -EACCES;
55450+#endif
55451+#endif
55452+ if (gr_status & GR_READY) {
55453+ if (!(task->acl->mode & GR_VIEW))
55454+ ret = -EACCES;
55455+ }
55456+ } else
55457+ ret = -ENOENT;
55458+
55459+ read_unlock(&tasklist_lock);
55460+ rcu_read_unlock();
55461+
55462+ return ret;
55463+}
55464+#endif
55465+
55466+/* AUXV entries are filled via a descendant of search_binary_handler
55467+ after we've already applied the subject for the target
55468+*/
55469+int gr_acl_enable_at_secure(void)
55470+{
55471+ if (unlikely(!(gr_status & GR_READY)))
55472+ return 0;
55473+
55474+ if (current->acl->mode & GR_ATSECURE)
55475+ return 1;
55476+
55477+ return 0;
55478+}
55479+
55480+int gr_acl_handle_filldir(const struct file *file, const char *name, const unsigned int namelen, const ino_t ino)
55481+{
55482+ struct task_struct *task = current;
55483+ struct dentry *dentry = file->f_path.dentry;
55484+ struct vfsmount *mnt = file->f_path.mnt;
55485+ struct acl_object_label *obj, *tmp;
55486+ struct acl_subject_label *subj;
55487+ unsigned int bufsize;
55488+ int is_not_root;
55489+ char *path;
55490+ dev_t dev = __get_dev(dentry);
55491+
55492+ if (unlikely(!(gr_status & GR_READY)))
55493+ return 1;
55494+
55495+ if (task->acl->mode & (GR_LEARN | GR_INHERITLEARN))
55496+ return 1;
55497+
55498+ /* ignore Eric Biederman */
55499+ if (IS_PRIVATE(dentry->d_inode))
55500+ return 1;
55501+
55502+ subj = task->acl;
55503+ read_lock(&gr_inode_lock);
55504+ do {
55505+ obj = lookup_acl_obj_label(ino, dev, subj);
55506+ if (obj != NULL) {
55507+ read_unlock(&gr_inode_lock);
55508+ return (obj->mode & GR_FIND) ? 1 : 0;
55509+ }
55510+ } while ((subj = subj->parent_subject));
55511+ read_unlock(&gr_inode_lock);
55512+
55513+ /* this is purely an optimization since we're looking for an object
55514+ for the directory we're doing a readdir on
55515+ if it's possible for any globbed object to match the entry we're
55516+ filling into the directory, then the object we find here will be
55517+ an anchor point with attached globbed objects
55518+ */
55519+ obj = chk_obj_label_noglob(dentry, mnt, task->acl);
55520+ if (obj->globbed == NULL)
55521+ return (obj->mode & GR_FIND) ? 1 : 0;
55522+
55523+ is_not_root = ((obj->filename[0] == '/') &&
55524+ (obj->filename[1] == '\0')) ? 0 : 1;
55525+ bufsize = PAGE_SIZE - namelen - is_not_root;
55526+
55527+ /* check bufsize > PAGE_SIZE || bufsize == 0 */
55528+ if (unlikely((bufsize - 1) > (PAGE_SIZE - 1)))
55529+ return 1;
55530+
55531+ preempt_disable();
55532+ path = d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0], smp_processor_id()),
55533+ bufsize);
55534+
55535+ bufsize = strlen(path);
55536+
55537+ /* if base is "/", don't append an additional slash */
55538+ if (is_not_root)
55539+ *(path + bufsize) = '/';
55540+ memcpy(path + bufsize + is_not_root, name, namelen);
55541+ *(path + bufsize + namelen + is_not_root) = '\0';
55542+
55543+ tmp = obj->globbed;
55544+ while (tmp) {
55545+ if (!glob_match(tmp->filename, path)) {
55546+ preempt_enable();
55547+ return (tmp->mode & GR_FIND) ? 1 : 0;
55548+ }
55549+ tmp = tmp->next;
55550+ }
55551+ preempt_enable();
55552+ return (obj->mode & GR_FIND) ? 1 : 0;
55553+}
55554+
55555+#ifdef CONFIG_NETFILTER_XT_MATCH_GRADM_MODULE
55556+EXPORT_SYMBOL(gr_acl_is_enabled);
55557+#endif
55558+EXPORT_SYMBOL(gr_learn_resource);
55559+EXPORT_SYMBOL(gr_set_kernel_label);
55560+#ifdef CONFIG_SECURITY
55561+EXPORT_SYMBOL(gr_check_user_change);
55562+EXPORT_SYMBOL(gr_check_group_change);
55563+#endif
55564+
55565diff --git a/grsecurity/gracl_alloc.c b/grsecurity/gracl_alloc.c
55566new file mode 100644
55567index 0000000..34fefda
55568--- /dev/null
55569+++ b/grsecurity/gracl_alloc.c
55570@@ -0,0 +1,105 @@
55571+#include <linux/kernel.h>
55572+#include <linux/mm.h>
55573+#include <linux/slab.h>
55574+#include <linux/vmalloc.h>
55575+#include <linux/gracl.h>
55576+#include <linux/grsecurity.h>
55577+
55578+static unsigned long alloc_stack_next = 1;
55579+static unsigned long alloc_stack_size = 1;
55580+static void **alloc_stack;
55581+
55582+static __inline__ int
55583+alloc_pop(void)
55584+{
55585+ if (alloc_stack_next == 1)
55586+ return 0;
55587+
55588+ kfree(alloc_stack[alloc_stack_next - 2]);
55589+
55590+ alloc_stack_next--;
55591+
55592+ return 1;
55593+}
55594+
55595+static __inline__ int
55596+alloc_push(void *buf)
55597+{
55598+ if (alloc_stack_next >= alloc_stack_size)
55599+ return 1;
55600+
55601+ alloc_stack[alloc_stack_next - 1] = buf;
55602+
55603+ alloc_stack_next++;
55604+
55605+ return 0;
55606+}
55607+
55608+void *
55609+acl_alloc(unsigned long len)
55610+{
55611+ void *ret = NULL;
55612+
55613+ if (!len || len > PAGE_SIZE)
55614+ goto out;
55615+
55616+ ret = kmalloc(len, GFP_KERNEL);
55617+
55618+ if (ret) {
55619+ if (alloc_push(ret)) {
55620+ kfree(ret);
55621+ ret = NULL;
55622+ }
55623+ }
55624+
55625+out:
55626+ return ret;
55627+}
55628+
55629+void *
55630+acl_alloc_num(unsigned long num, unsigned long len)
55631+{
55632+ if (!len || (num > (PAGE_SIZE / len)))
55633+ return NULL;
55634+
55635+ return acl_alloc(num * len);
55636+}
55637+
55638+void
55639+acl_free_all(void)
55640+{
55641+ if (gr_acl_is_enabled() || !alloc_stack)
55642+ return;
55643+
55644+ while (alloc_pop()) ;
55645+
55646+ if (alloc_stack) {
55647+ if ((alloc_stack_size * sizeof (void *)) <= PAGE_SIZE)
55648+ kfree(alloc_stack);
55649+ else
55650+ vfree(alloc_stack);
55651+ }
55652+
55653+ alloc_stack = NULL;
55654+ alloc_stack_size = 1;
55655+ alloc_stack_next = 1;
55656+
55657+ return;
55658+}
55659+
55660+int
55661+acl_alloc_stack_init(unsigned long size)
55662+{
55663+ if ((size * sizeof (void *)) <= PAGE_SIZE)
55664+ alloc_stack =
55665+ (void **) kmalloc(size * sizeof (void *), GFP_KERNEL);
55666+ else
55667+ alloc_stack = (void **) vmalloc(size * sizeof (void *));
55668+
55669+ alloc_stack_size = size;
55670+
55671+ if (!alloc_stack)
55672+ return 0;
55673+ else
55674+ return 1;
55675+}
55676diff --git a/grsecurity/gracl_cap.c b/grsecurity/gracl_cap.c
55677new file mode 100644
55678index 0000000..6d21049
55679--- /dev/null
55680+++ b/grsecurity/gracl_cap.c
55681@@ -0,0 +1,110 @@
55682+#include <linux/kernel.h>
55683+#include <linux/module.h>
55684+#include <linux/sched.h>
55685+#include <linux/gracl.h>
55686+#include <linux/grsecurity.h>
55687+#include <linux/grinternal.h>
55688+
55689+extern const char *captab_log[];
55690+extern int captab_log_entries;
55691+
55692+int gr_task_acl_is_capable(const struct task_struct *task, const struct cred *cred, const int cap)
55693+{
55694+ struct acl_subject_label *curracl;
55695+ kernel_cap_t cap_drop = __cap_empty_set, cap_mask = __cap_empty_set;
55696+ kernel_cap_t cap_audit = __cap_empty_set;
55697+
55698+ if (!gr_acl_is_enabled())
55699+ return 1;
55700+
55701+ curracl = task->acl;
55702+
55703+ cap_drop = curracl->cap_lower;
55704+ cap_mask = curracl->cap_mask;
55705+ cap_audit = curracl->cap_invert_audit;
55706+
55707+ while ((curracl = curracl->parent_subject)) {
55708+ /* if the cap isn't specified in the current computed mask but is specified in the
55709+ current level subject, and is lowered in the current level subject, then add
55710+ it to the set of dropped capabilities
55711+ otherwise, add the current level subject's mask to the current computed mask
55712+ */
55713+ if (!cap_raised(cap_mask, cap) && cap_raised(curracl->cap_mask, cap)) {
55714+ cap_raise(cap_mask, cap);
55715+ if (cap_raised(curracl->cap_lower, cap))
55716+ cap_raise(cap_drop, cap);
55717+ if (cap_raised(curracl->cap_invert_audit, cap))
55718+ cap_raise(cap_audit, cap);
55719+ }
55720+ }
55721+
55722+ if (!cap_raised(cap_drop, cap)) {
55723+ if (cap_raised(cap_audit, cap))
55724+ gr_log_cap(GR_DO_AUDIT, GR_CAP_ACL_MSG2, task, captab_log[cap]);
55725+ return 1;
55726+ }
55727+
55728+ curracl = task->acl;
55729+
55730+ if ((curracl->mode & (GR_LEARN | GR_INHERITLEARN))
55731+ && cap_raised(cred->cap_effective, cap)) {
55732+ security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename,
55733+ task->role->roletype, cred->uid,
55734+ cred->gid, task->exec_file ?
55735+ gr_to_filename(task->exec_file->f_path.dentry,
55736+ task->exec_file->f_path.mnt) : curracl->filename,
55737+ curracl->filename, 0UL,
55738+ 0UL, "", (unsigned long) cap, &task->signal->saved_ip);
55739+ return 1;
55740+ }
55741+
55742+ if ((cap >= 0) && (cap < captab_log_entries) && cap_raised(cred->cap_effective, cap) && !cap_raised(cap_audit, cap))
55743+ gr_log_cap(GR_DONT_AUDIT, GR_CAP_ACL_MSG, task, captab_log[cap]);
55744+
55745+ return 0;
55746+}
55747+
55748+int
55749+gr_acl_is_capable(const int cap)
55750+{
55751+ return gr_task_acl_is_capable(current, current_cred(), cap);
55752+}
55753+
55754+int gr_task_acl_is_capable_nolog(const struct task_struct *task, const int cap)
55755+{
55756+ struct acl_subject_label *curracl;
55757+ kernel_cap_t cap_drop = __cap_empty_set, cap_mask = __cap_empty_set;
55758+
55759+ if (!gr_acl_is_enabled())
55760+ return 1;
55761+
55762+ curracl = task->acl;
55763+
55764+ cap_drop = curracl->cap_lower;
55765+ cap_mask = curracl->cap_mask;
55766+
55767+ while ((curracl = curracl->parent_subject)) {
55768+ /* if the cap isn't specified in the current computed mask but is specified in the
55769+ current level subject, and is lowered in the current level subject, then add
55770+ it to the set of dropped capabilities
55771+ otherwise, add the current level subject's mask to the current computed mask
55772+ */
55773+ if (!cap_raised(cap_mask, cap) && cap_raised(curracl->cap_mask, cap)) {
55774+ cap_raise(cap_mask, cap);
55775+ if (cap_raised(curracl->cap_lower, cap))
55776+ cap_raise(cap_drop, cap);
55777+ }
55778+ }
55779+
55780+ if (!cap_raised(cap_drop, cap))
55781+ return 1;
55782+
55783+ return 0;
55784+}
55785+
55786+int
55787+gr_acl_is_capable_nolog(const int cap)
55788+{
55789+ return gr_task_acl_is_capable_nolog(current, cap);
55790+}
55791+
55792diff --git a/grsecurity/gracl_fs.c b/grsecurity/gracl_fs.c
55793new file mode 100644
55794index 0000000..d28e241
55795--- /dev/null
55796+++ b/grsecurity/gracl_fs.c
55797@@ -0,0 +1,437 @@
55798+#include <linux/kernel.h>
55799+#include <linux/sched.h>
55800+#include <linux/types.h>
55801+#include <linux/fs.h>
55802+#include <linux/file.h>
55803+#include <linux/stat.h>
55804+#include <linux/grsecurity.h>
55805+#include <linux/grinternal.h>
55806+#include <linux/gracl.h>
55807+
55808+umode_t
55809+gr_acl_umask(void)
55810+{
55811+ if (unlikely(!gr_acl_is_enabled()))
55812+ return 0;
55813+
55814+ return current->role->umask;
55815+}
55816+
55817+__u32
55818+gr_acl_handle_hidden_file(const struct dentry * dentry,
55819+ const struct vfsmount * mnt)
55820+{
55821+ __u32 mode;
55822+
55823+ if (unlikely(!dentry->d_inode))
55824+ return GR_FIND;
55825+
55826+ mode =
55827+ gr_search_file(dentry, GR_FIND | GR_AUDIT_FIND | GR_SUPPRESS, mnt);
55828+
55829+ if (unlikely(mode & GR_FIND && mode & GR_AUDIT_FIND)) {
55830+ gr_log_fs_rbac_generic(GR_DO_AUDIT, GR_HIDDEN_ACL_MSG, dentry, mnt);
55831+ return mode;
55832+ } else if (unlikely(!(mode & GR_FIND) && !(mode & GR_SUPPRESS))) {
55833+ gr_log_fs_rbac_generic(GR_DONT_AUDIT, GR_HIDDEN_ACL_MSG, dentry, mnt);
55834+ return 0;
55835+ } else if (unlikely(!(mode & GR_FIND)))
55836+ return 0;
55837+
55838+ return GR_FIND;
55839+}
55840+
55841+__u32
55842+gr_acl_handle_open(const struct dentry * dentry, const struct vfsmount * mnt,
55843+ int acc_mode)
55844+{
55845+ __u32 reqmode = GR_FIND;
55846+ __u32 mode;
55847+
55848+ if (unlikely(!dentry->d_inode))
55849+ return reqmode;
55850+
55851+ if (acc_mode & MAY_APPEND)
55852+ reqmode |= GR_APPEND;
55853+ else if (acc_mode & MAY_WRITE)
55854+ reqmode |= GR_WRITE;
55855+ if ((acc_mode & MAY_READ) && !S_ISDIR(dentry->d_inode->i_mode))
55856+ reqmode |= GR_READ;
55857+
55858+ mode =
55859+ gr_search_file(dentry, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS,
55860+ mnt);
55861+
55862+ if (unlikely(((mode & reqmode) == reqmode) && mode & GR_AUDITS)) {
55863+ gr_log_fs_rbac_mode2(GR_DO_AUDIT, GR_OPEN_ACL_MSG, dentry, mnt,
55864+ reqmode & GR_READ ? " reading" : "",
55865+ reqmode & GR_WRITE ? " writing" : reqmode &
55866+ GR_APPEND ? " appending" : "");
55867+ return reqmode;
55868+ } else
55869+ if (unlikely((mode & reqmode) != reqmode && !(mode & GR_SUPPRESS)))
55870+ {
55871+ gr_log_fs_rbac_mode2(GR_DONT_AUDIT, GR_OPEN_ACL_MSG, dentry, mnt,
55872+ reqmode & GR_READ ? " reading" : "",
55873+ reqmode & GR_WRITE ? " writing" : reqmode &
55874+ GR_APPEND ? " appending" : "");
55875+ return 0;
55876+ } else if (unlikely((mode & reqmode) != reqmode))
55877+ return 0;
55878+
55879+ return reqmode;
55880+}
55881+
55882+__u32
55883+gr_acl_handle_creat(const struct dentry * dentry,
55884+ const struct dentry * p_dentry,
55885+ const struct vfsmount * p_mnt, int open_flags, int acc_mode,
55886+ const int imode)
55887+{
55888+ __u32 reqmode = GR_WRITE | GR_CREATE;
55889+ __u32 mode;
55890+
55891+ if (acc_mode & MAY_APPEND)
55892+ reqmode |= GR_APPEND;
55893+ // if a directory was required or the directory already exists, then
55894+ // don't count this open as a read
55895+ if ((acc_mode & MAY_READ) &&
55896+ !((open_flags & O_DIRECTORY) || (dentry->d_inode && S_ISDIR(dentry->d_inode->i_mode))))
55897+ reqmode |= GR_READ;
55898+ if ((open_flags & O_CREAT) &&
55899+ ((imode & S_ISUID) || ((imode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))))
55900+ reqmode |= GR_SETID;
55901+
55902+ mode =
55903+ gr_check_create(dentry, p_dentry, p_mnt,
55904+ reqmode | to_gr_audit(reqmode) | GR_SUPPRESS);
55905+
55906+ if (unlikely(((mode & reqmode) == reqmode) && mode & GR_AUDITS)) {
55907+ gr_log_fs_rbac_mode2(GR_DO_AUDIT, GR_CREATE_ACL_MSG, dentry, p_mnt,
55908+ reqmode & GR_READ ? " reading" : "",
55909+ reqmode & GR_WRITE ? " writing" : reqmode &
55910+ GR_APPEND ? " appending" : "");
55911+ return reqmode;
55912+ } else
55913+ if (unlikely((mode & reqmode) != reqmode && !(mode & GR_SUPPRESS)))
55914+ {
55915+ gr_log_fs_rbac_mode2(GR_DONT_AUDIT, GR_CREATE_ACL_MSG, dentry, p_mnt,
55916+ reqmode & GR_READ ? " reading" : "",
55917+ reqmode & GR_WRITE ? " writing" : reqmode &
55918+ GR_APPEND ? " appending" : "");
55919+ return 0;
55920+ } else if (unlikely((mode & reqmode) != reqmode))
55921+ return 0;
55922+
55923+ return reqmode;
55924+}
55925+
55926+__u32
55927+gr_acl_handle_access(const struct dentry * dentry, const struct vfsmount * mnt,
55928+ const int fmode)
55929+{
55930+ __u32 mode, reqmode = GR_FIND;
55931+
55932+ if ((fmode & S_IXOTH) && !S_ISDIR(dentry->d_inode->i_mode))
55933+ reqmode |= GR_EXEC;
55934+ if (fmode & S_IWOTH)
55935+ reqmode |= GR_WRITE;
55936+ if (fmode & S_IROTH)
55937+ reqmode |= GR_READ;
55938+
55939+ mode =
55940+ gr_search_file(dentry, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS,
55941+ mnt);
55942+
55943+ if (unlikely(((mode & reqmode) == reqmode) && mode & GR_AUDITS)) {
55944+ gr_log_fs_rbac_mode3(GR_DO_AUDIT, GR_ACCESS_ACL_MSG, dentry, mnt,
55945+ reqmode & GR_READ ? " reading" : "",
55946+ reqmode & GR_WRITE ? " writing" : "",
55947+ reqmode & GR_EXEC ? " executing" : "");
55948+ return reqmode;
55949+ } else
55950+ if (unlikely((mode & reqmode) != reqmode && !(mode & GR_SUPPRESS)))
55951+ {
55952+ gr_log_fs_rbac_mode3(GR_DONT_AUDIT, GR_ACCESS_ACL_MSG, dentry, mnt,
55953+ reqmode & GR_READ ? " reading" : "",
55954+ reqmode & GR_WRITE ? " writing" : "",
55955+ reqmode & GR_EXEC ? " executing" : "");
55956+ return 0;
55957+ } else if (unlikely((mode & reqmode) != reqmode))
55958+ return 0;
55959+
55960+ return reqmode;
55961+}
55962+
55963+static __u32 generic_fs_handler(const struct dentry *dentry, const struct vfsmount *mnt, __u32 reqmode, const char *fmt)
55964+{
55965+ __u32 mode;
55966+
55967+ mode = gr_search_file(dentry, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS, mnt);
55968+
55969+ if (unlikely(((mode & (reqmode)) == (reqmode)) && mode & GR_AUDITS)) {
55970+ gr_log_fs_rbac_generic(GR_DO_AUDIT, fmt, dentry, mnt);
55971+ return mode;
55972+ } else if (unlikely((mode & (reqmode)) != (reqmode) && !(mode & GR_SUPPRESS))) {
55973+ gr_log_fs_rbac_generic(GR_DONT_AUDIT, fmt, dentry, mnt);
55974+ return 0;
55975+ } else if (unlikely((mode & (reqmode)) != (reqmode)))
55976+ return 0;
55977+
55978+ return (reqmode);
55979+}
55980+
55981+__u32
55982+gr_acl_handle_rmdir(const struct dentry * dentry, const struct vfsmount * mnt)
55983+{
55984+ return generic_fs_handler(dentry, mnt, GR_WRITE | GR_DELETE , GR_RMDIR_ACL_MSG);
55985+}
55986+
55987+__u32
55988+gr_acl_handle_unlink(const struct dentry *dentry, const struct vfsmount *mnt)
55989+{
55990+ return generic_fs_handler(dentry, mnt, GR_WRITE | GR_DELETE , GR_UNLINK_ACL_MSG);
55991+}
55992+
55993+__u32
55994+gr_acl_handle_truncate(const struct dentry *dentry, const struct vfsmount *mnt)
55995+{
55996+ return generic_fs_handler(dentry, mnt, GR_WRITE, GR_TRUNCATE_ACL_MSG);
55997+}
55998+
55999+__u32
56000+gr_acl_handle_utime(const struct dentry *dentry, const struct vfsmount *mnt)
56001+{
56002+ return generic_fs_handler(dentry, mnt, GR_WRITE, GR_ATIME_ACL_MSG);
56003+}
56004+
56005+__u32
56006+gr_acl_handle_chmod(const struct dentry *dentry, const struct vfsmount *mnt,
56007+ umode_t *modeptr)
56008+{
56009+ umode_t mode;
56010+
56011+ *modeptr &= ~gr_acl_umask();
56012+ mode = *modeptr;
56013+
56014+ if (unlikely(dentry->d_inode && S_ISSOCK(dentry->d_inode->i_mode)))
56015+ return 1;
56016+
56017+ if (unlikely(dentry->d_inode && !S_ISDIR(dentry->d_inode->i_mode) &&
56018+ ((mode & S_ISUID) || ((mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))))) {
56019+ return generic_fs_handler(dentry, mnt, GR_WRITE | GR_SETID,
56020+ GR_CHMOD_ACL_MSG);
56021+ } else {
56022+ return generic_fs_handler(dentry, mnt, GR_WRITE, GR_CHMOD_ACL_MSG);
56023+ }
56024+}
56025+
56026+__u32
56027+gr_acl_handle_chown(const struct dentry *dentry, const struct vfsmount *mnt)
56028+{
56029+ return generic_fs_handler(dentry, mnt, GR_WRITE, GR_CHOWN_ACL_MSG);
56030+}
56031+
56032+__u32
56033+gr_acl_handle_setxattr(const struct dentry *dentry, const struct vfsmount *mnt)
56034+{
56035+ return generic_fs_handler(dentry, mnt, GR_WRITE, GR_SETXATTR_ACL_MSG);
56036+}
56037+
56038+__u32
56039+gr_acl_handle_execve(const struct dentry *dentry, const struct vfsmount *mnt)
56040+{
56041+ return generic_fs_handler(dentry, mnt, GR_EXEC, GR_EXEC_ACL_MSG);
56042+}
56043+
56044+__u32
56045+gr_acl_handle_unix(const struct dentry *dentry, const struct vfsmount *mnt)
56046+{
56047+ return generic_fs_handler(dentry, mnt, GR_READ | GR_WRITE,
56048+ GR_UNIXCONNECT_ACL_MSG);
56049+}
56050+
56051+/* hardlinks require at minimum create and link permission,
56052+ any additional privilege required is based on the
56053+ privilege of the file being linked to
56054+*/
56055+__u32
56056+gr_acl_handle_link(const struct dentry * new_dentry,
56057+ const struct dentry * parent_dentry,
56058+ const struct vfsmount * parent_mnt,
56059+ const struct dentry * old_dentry,
56060+ const struct vfsmount * old_mnt, const char *to)
56061+{
56062+ __u32 mode;
56063+ __u32 needmode = GR_CREATE | GR_LINK;
56064+ __u32 needaudit = GR_AUDIT_CREATE | GR_AUDIT_LINK;
56065+
56066+ mode =
56067+ gr_check_link(new_dentry, parent_dentry, parent_mnt, old_dentry,
56068+ old_mnt);
56069+
56070+ if (unlikely(((mode & needmode) == needmode) && (mode & needaudit))) {
56071+ gr_log_fs_rbac_str(GR_DO_AUDIT, GR_LINK_ACL_MSG, old_dentry, old_mnt, to);
56072+ return mode;
56073+ } else if (unlikely(((mode & needmode) != needmode) && !(mode & GR_SUPPRESS))) {
56074+ gr_log_fs_rbac_str(GR_DONT_AUDIT, GR_LINK_ACL_MSG, old_dentry, old_mnt, to);
56075+ return 0;
56076+ } else if (unlikely((mode & needmode) != needmode))
56077+ return 0;
56078+
56079+ return 1;
56080+}
56081+
56082+__u32
56083+gr_acl_handle_symlink(const struct dentry * new_dentry,
56084+ const struct dentry * parent_dentry,
56085+ const struct vfsmount * parent_mnt, const char *from)
56086+{
56087+ __u32 needmode = GR_WRITE | GR_CREATE;
56088+ __u32 mode;
56089+
56090+ mode =
56091+ gr_check_create(new_dentry, parent_dentry, parent_mnt,
56092+ GR_CREATE | GR_AUDIT_CREATE |
56093+ GR_WRITE | GR_AUDIT_WRITE | GR_SUPPRESS);
56094+
56095+ if (unlikely(mode & GR_WRITE && mode & GR_AUDITS)) {
56096+ gr_log_fs_str_rbac(GR_DO_AUDIT, GR_SYMLINK_ACL_MSG, from, new_dentry, parent_mnt);
56097+ return mode;
56098+ } else if (unlikely(((mode & needmode) != needmode) && !(mode & GR_SUPPRESS))) {
56099+ gr_log_fs_str_rbac(GR_DONT_AUDIT, GR_SYMLINK_ACL_MSG, from, new_dentry, parent_mnt);
56100+ return 0;
56101+ } else if (unlikely((mode & needmode) != needmode))
56102+ return 0;
56103+
56104+ return (GR_WRITE | GR_CREATE);
56105+}
56106+
56107+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)
56108+{
56109+ __u32 mode;
56110+
56111+ mode = gr_check_create(new_dentry, parent_dentry, parent_mnt, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS);
56112+
56113+ if (unlikely(((mode & (reqmode)) == (reqmode)) && mode & GR_AUDITS)) {
56114+ gr_log_fs_rbac_generic(GR_DO_AUDIT, fmt, new_dentry, parent_mnt);
56115+ return mode;
56116+ } else if (unlikely((mode & (reqmode)) != (reqmode) && !(mode & GR_SUPPRESS))) {
56117+ gr_log_fs_rbac_generic(GR_DONT_AUDIT, fmt, new_dentry, parent_mnt);
56118+ return 0;
56119+ } else if (unlikely((mode & (reqmode)) != (reqmode)))
56120+ return 0;
56121+
56122+ return (reqmode);
56123+}
56124+
56125+__u32
56126+gr_acl_handle_mknod(const struct dentry * new_dentry,
56127+ const struct dentry * parent_dentry,
56128+ const struct vfsmount * parent_mnt,
56129+ const int mode)
56130+{
56131+ __u32 reqmode = GR_WRITE | GR_CREATE;
56132+ if (unlikely((mode & S_ISUID) || ((mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))))
56133+ reqmode |= GR_SETID;
56134+
56135+ return generic_fs_create_handler(new_dentry, parent_dentry, parent_mnt,
56136+ reqmode, GR_MKNOD_ACL_MSG);
56137+}
56138+
56139+__u32
56140+gr_acl_handle_mkdir(const struct dentry *new_dentry,
56141+ const struct dentry *parent_dentry,
56142+ const struct vfsmount *parent_mnt)
56143+{
56144+ return generic_fs_create_handler(new_dentry, parent_dentry, parent_mnt,
56145+ GR_WRITE | GR_CREATE, GR_MKDIR_ACL_MSG);
56146+}
56147+
56148+#define RENAME_CHECK_SUCCESS(old, new) \
56149+ (((old & (GR_WRITE | GR_READ)) == (GR_WRITE | GR_READ)) && \
56150+ ((new & (GR_WRITE | GR_READ)) == (GR_WRITE | GR_READ)))
56151+
56152+int
56153+gr_acl_handle_rename(struct dentry *new_dentry,
56154+ struct dentry *parent_dentry,
56155+ const struct vfsmount *parent_mnt,
56156+ struct dentry *old_dentry,
56157+ struct inode *old_parent_inode,
56158+ struct vfsmount *old_mnt, const char *newname)
56159+{
56160+ __u32 comp1, comp2;
56161+ int error = 0;
56162+
56163+ if (unlikely(!gr_acl_is_enabled()))
56164+ return 0;
56165+
56166+ if (!new_dentry->d_inode) {
56167+ comp1 = gr_check_create(new_dentry, parent_dentry, parent_mnt,
56168+ GR_READ | GR_WRITE | GR_CREATE | GR_AUDIT_READ |
56169+ GR_AUDIT_WRITE | GR_AUDIT_CREATE | GR_SUPPRESS);
56170+ comp2 = gr_search_file(old_dentry, GR_READ | GR_WRITE |
56171+ GR_DELETE | GR_AUDIT_DELETE |
56172+ GR_AUDIT_READ | GR_AUDIT_WRITE |
56173+ GR_SUPPRESS, old_mnt);
56174+ } else {
56175+ comp1 = gr_search_file(new_dentry, GR_READ | GR_WRITE |
56176+ GR_CREATE | GR_DELETE |
56177+ GR_AUDIT_CREATE | GR_AUDIT_DELETE |
56178+ GR_AUDIT_READ | GR_AUDIT_WRITE |
56179+ GR_SUPPRESS, parent_mnt);
56180+ comp2 =
56181+ gr_search_file(old_dentry,
56182+ GR_READ | GR_WRITE | GR_AUDIT_READ |
56183+ GR_DELETE | GR_AUDIT_DELETE |
56184+ GR_AUDIT_WRITE | GR_SUPPRESS, old_mnt);
56185+ }
56186+
56187+ if (RENAME_CHECK_SUCCESS(comp1, comp2) &&
56188+ ((comp1 & GR_AUDITS) || (comp2 & GR_AUDITS)))
56189+ gr_log_fs_rbac_str(GR_DO_AUDIT, GR_RENAME_ACL_MSG, old_dentry, old_mnt, newname);
56190+ else if (!RENAME_CHECK_SUCCESS(comp1, comp2) && !(comp1 & GR_SUPPRESS)
56191+ && !(comp2 & GR_SUPPRESS)) {
56192+ gr_log_fs_rbac_str(GR_DONT_AUDIT, GR_RENAME_ACL_MSG, old_dentry, old_mnt, newname);
56193+ error = -EACCES;
56194+ } else if (unlikely(!RENAME_CHECK_SUCCESS(comp1, comp2)))
56195+ error = -EACCES;
56196+
56197+ return error;
56198+}
56199+
56200+void
56201+gr_acl_handle_exit(void)
56202+{
56203+ u16 id;
56204+ char *rolename;
56205+ struct file *exec_file;
56206+
56207+ if (unlikely(current->acl_sp_role && gr_acl_is_enabled() &&
56208+ !(current->role->roletype & GR_ROLE_PERSIST))) {
56209+ id = current->acl_role_id;
56210+ rolename = current->role->rolename;
56211+ gr_set_acls(1);
56212+ gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_SPROLEL_ACL_MSG, rolename, id);
56213+ }
56214+
56215+ write_lock(&grsec_exec_file_lock);
56216+ exec_file = current->exec_file;
56217+ current->exec_file = NULL;
56218+ write_unlock(&grsec_exec_file_lock);
56219+
56220+ if (exec_file)
56221+ fput(exec_file);
56222+}
56223+
56224+int
56225+gr_acl_handle_procpidmem(const struct task_struct *task)
56226+{
56227+ if (unlikely(!gr_acl_is_enabled()))
56228+ return 0;
56229+
56230+ if (task != current && task->acl->mode & GR_PROTPROCFD)
56231+ return -EACCES;
56232+
56233+ return 0;
56234+}
56235diff --git a/grsecurity/gracl_ip.c b/grsecurity/gracl_ip.c
56236new file mode 100644
56237index 0000000..58800a7
56238--- /dev/null
56239+++ b/grsecurity/gracl_ip.c
56240@@ -0,0 +1,384 @@
56241+#include <linux/kernel.h>
56242+#include <asm/uaccess.h>
56243+#include <asm/errno.h>
56244+#include <net/sock.h>
56245+#include <linux/file.h>
56246+#include <linux/fs.h>
56247+#include <linux/net.h>
56248+#include <linux/in.h>
56249+#include <linux/skbuff.h>
56250+#include <linux/ip.h>
56251+#include <linux/udp.h>
56252+#include <linux/types.h>
56253+#include <linux/sched.h>
56254+#include <linux/netdevice.h>
56255+#include <linux/inetdevice.h>
56256+#include <linux/gracl.h>
56257+#include <linux/grsecurity.h>
56258+#include <linux/grinternal.h>
56259+
56260+#define GR_BIND 0x01
56261+#define GR_CONNECT 0x02
56262+#define GR_INVERT 0x04
56263+#define GR_BINDOVERRIDE 0x08
56264+#define GR_CONNECTOVERRIDE 0x10
56265+#define GR_SOCK_FAMILY 0x20
56266+
56267+static const char * gr_protocols[IPPROTO_MAX] = {
56268+ "ip", "icmp", "igmp", "ggp", "ipencap", "st", "tcp", "cbt",
56269+ "egp", "igp", "bbn-rcc", "nvp", "pup", "argus", "emcon", "xnet",
56270+ "chaos", "udp", "mux", "dcn", "hmp", "prm", "xns-idp", "trunk-1",
56271+ "trunk-2", "leaf-1", "leaf-2", "rdp", "irtp", "iso-tp4", "netblt", "mfe-nsp",
56272+ "merit-inp", "sep", "3pc", "idpr", "xtp", "ddp", "idpr-cmtp", "tp++",
56273+ "il", "ipv6", "sdrp", "ipv6-route", "ipv6-frag", "idrp", "rsvp", "gre",
56274+ "mhrp", "bna", "ipv6-crypt", "ipv6-auth", "i-nlsp", "swipe", "narp", "mobile",
56275+ "tlsp", "skip", "ipv6-icmp", "ipv6-nonxt", "ipv6-opts", "unknown:61", "cftp", "unknown:63",
56276+ "sat-expak", "kryptolan", "rvd", "ippc", "unknown:68", "sat-mon", "visa", "ipcv",
56277+ "cpnx", "cphb", "wsn", "pvp", "br-sat-mon", "sun-nd", "wb-mon", "wb-expak",
56278+ "iso-ip", "vmtp", "secure-vmtp", "vines", "ttp", "nfsnet-igp", "dgp", "tcf",
56279+ "eigrp", "ospf", "sprite-rpc", "larp", "mtp", "ax.25", "ipip", "micp",
56280+ "scc-sp", "etherip", "encap", "unknown:99", "gmtp", "ifmp", "pnni", "pim",
56281+ "aris", "scps", "qnx", "a/n", "ipcomp", "snp", "compaq-peer", "ipx-in-ip",
56282+ "vrrp", "pgm", "unknown:114", "l2tp", "ddx", "iatp", "stp", "srp",
56283+ "uti", "smp", "sm", "ptp", "isis", "fire", "crtp", "crdup",
56284+ "sscopmce", "iplt", "sps", "pipe", "sctp", "fc", "unkown:134", "unknown:135",
56285+ "unknown:136", "unknown:137", "unknown:138", "unknown:139", "unknown:140", "unknown:141", "unknown:142", "unknown:143",
56286+ "unknown:144", "unknown:145", "unknown:146", "unknown:147", "unknown:148", "unknown:149", "unknown:150", "unknown:151",
56287+ "unknown:152", "unknown:153", "unknown:154", "unknown:155", "unknown:156", "unknown:157", "unknown:158", "unknown:159",
56288+ "unknown:160", "unknown:161", "unknown:162", "unknown:163", "unknown:164", "unknown:165", "unknown:166", "unknown:167",
56289+ "unknown:168", "unknown:169", "unknown:170", "unknown:171", "unknown:172", "unknown:173", "unknown:174", "unknown:175",
56290+ "unknown:176", "unknown:177", "unknown:178", "unknown:179", "unknown:180", "unknown:181", "unknown:182", "unknown:183",
56291+ "unknown:184", "unknown:185", "unknown:186", "unknown:187", "unknown:188", "unknown:189", "unknown:190", "unknown:191",
56292+ "unknown:192", "unknown:193", "unknown:194", "unknown:195", "unknown:196", "unknown:197", "unknown:198", "unknown:199",
56293+ "unknown:200", "unknown:201", "unknown:202", "unknown:203", "unknown:204", "unknown:205", "unknown:206", "unknown:207",
56294+ "unknown:208", "unknown:209", "unknown:210", "unknown:211", "unknown:212", "unknown:213", "unknown:214", "unknown:215",
56295+ "unknown:216", "unknown:217", "unknown:218", "unknown:219", "unknown:220", "unknown:221", "unknown:222", "unknown:223",
56296+ "unknown:224", "unknown:225", "unknown:226", "unknown:227", "unknown:228", "unknown:229", "unknown:230", "unknown:231",
56297+ "unknown:232", "unknown:233", "unknown:234", "unknown:235", "unknown:236", "unknown:237", "unknown:238", "unknown:239",
56298+ "unknown:240", "unknown:241", "unknown:242", "unknown:243", "unknown:244", "unknown:245", "unknown:246", "unknown:247",
56299+ "unknown:248", "unknown:249", "unknown:250", "unknown:251", "unknown:252", "unknown:253", "unknown:254", "unknown:255",
56300+ };
56301+
56302+static const char * gr_socktypes[SOCK_MAX] = {
56303+ "unknown:0", "stream", "dgram", "raw", "rdm", "seqpacket", "unknown:6",
56304+ "unknown:7", "unknown:8", "unknown:9", "packet"
56305+ };
56306+
56307+static const char * gr_sockfamilies[AF_MAX+1] = {
56308+ "unspec", "unix", "inet", "ax25", "ipx", "appletalk", "netrom", "bridge", "atmpvc", "x25",
56309+ "inet6", "rose", "decnet", "netbeui", "security", "key", "netlink", "packet", "ash",
56310+ "econet", "atmsvc", "rds", "sna", "irda", "ppox", "wanpipe", "llc", "fam_27", "fam_28",
56311+ "tipc", "bluetooth", "iucv", "rxrpc", "isdn", "phonet", "ieee802154", "ciaf"
56312+ };
56313+
56314+const char *
56315+gr_proto_to_name(unsigned char proto)
56316+{
56317+ return gr_protocols[proto];
56318+}
56319+
56320+const char *
56321+gr_socktype_to_name(unsigned char type)
56322+{
56323+ return gr_socktypes[type];
56324+}
56325+
56326+const char *
56327+gr_sockfamily_to_name(unsigned char family)
56328+{
56329+ return gr_sockfamilies[family];
56330+}
56331+
56332+int
56333+gr_search_socket(const int domain, const int type, const int protocol)
56334+{
56335+ struct acl_subject_label *curr;
56336+ const struct cred *cred = current_cred();
56337+
56338+ if (unlikely(!gr_acl_is_enabled()))
56339+ goto exit;
56340+
56341+ if ((domain < 0) || (type < 0) || (protocol < 0) ||
56342+ (domain >= AF_MAX) || (type >= SOCK_MAX) || (protocol >= IPPROTO_MAX))
56343+ goto exit; // let the kernel handle it
56344+
56345+ curr = current->acl;
56346+
56347+ if (curr->sock_families[domain / 32] & (1 << (domain % 32))) {
56348+ /* the family is allowed, if this is PF_INET allow it only if
56349+ the extra sock type/protocol checks pass */
56350+ if (domain == PF_INET)
56351+ goto inet_check;
56352+ goto exit;
56353+ } else {
56354+ if (curr->mode & (GR_LEARN | GR_INHERITLEARN)) {
56355+ __u32 fakeip = 0;
56356+ security_learn(GR_IP_LEARN_MSG, current->role->rolename,
56357+ current->role->roletype, cred->uid,
56358+ cred->gid, current->exec_file ?
56359+ gr_to_filename(current->exec_file->f_path.dentry,
56360+ current->exec_file->f_path.mnt) :
56361+ curr->filename, curr->filename,
56362+ &fakeip, domain, 0, 0, GR_SOCK_FAMILY,
56363+ &current->signal->saved_ip);
56364+ goto exit;
56365+ }
56366+ goto exit_fail;
56367+ }
56368+
56369+inet_check:
56370+ /* the rest of this checking is for IPv4 only */
56371+ if (!curr->ips)
56372+ goto exit;
56373+
56374+ if ((curr->ip_type & (1 << type)) &&
56375+ (curr->ip_proto[protocol / 32] & (1 << (protocol % 32))))
56376+ goto exit;
56377+
56378+ if (curr->mode & (GR_LEARN | GR_INHERITLEARN)) {
56379+ /* we don't place acls on raw sockets , and sometimes
56380+ dgram/ip sockets are opened for ioctl and not
56381+ bind/connect, so we'll fake a bind learn log */
56382+ if (type == SOCK_RAW || type == SOCK_PACKET) {
56383+ __u32 fakeip = 0;
56384+ security_learn(GR_IP_LEARN_MSG, current->role->rolename,
56385+ current->role->roletype, cred->uid,
56386+ cred->gid, current->exec_file ?
56387+ gr_to_filename(current->exec_file->f_path.dentry,
56388+ current->exec_file->f_path.mnt) :
56389+ curr->filename, curr->filename,
56390+ &fakeip, 0, type,
56391+ protocol, GR_CONNECT, &current->signal->saved_ip);
56392+ } else if ((type == SOCK_DGRAM) && (protocol == IPPROTO_IP)) {
56393+ __u32 fakeip = 0;
56394+ security_learn(GR_IP_LEARN_MSG, current->role->rolename,
56395+ current->role->roletype, cred->uid,
56396+ cred->gid, current->exec_file ?
56397+ gr_to_filename(current->exec_file->f_path.dentry,
56398+ current->exec_file->f_path.mnt) :
56399+ curr->filename, curr->filename,
56400+ &fakeip, 0, type,
56401+ protocol, GR_BIND, &current->signal->saved_ip);
56402+ }
56403+ /* we'll log when they use connect or bind */
56404+ goto exit;
56405+ }
56406+
56407+exit_fail:
56408+ if (domain == PF_INET)
56409+ gr_log_str3(GR_DONT_AUDIT, GR_SOCK_MSG, gr_sockfamily_to_name(domain),
56410+ gr_socktype_to_name(type), gr_proto_to_name(protocol));
56411+ else
56412+ gr_log_str2_int(GR_DONT_AUDIT, GR_SOCK_NOINET_MSG, gr_sockfamily_to_name(domain),
56413+ gr_socktype_to_name(type), protocol);
56414+
56415+ return 0;
56416+exit:
56417+ return 1;
56418+}
56419+
56420+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)
56421+{
56422+ if ((ip->mode & mode) &&
56423+ (ip_port >= ip->low) &&
56424+ (ip_port <= ip->high) &&
56425+ ((ntohl(ip_addr) & our_netmask) ==
56426+ (ntohl(our_addr) & our_netmask))
56427+ && (ip->proto[protocol / 32] & (1 << (protocol % 32)))
56428+ && (ip->type & (1 << type))) {
56429+ if (ip->mode & GR_INVERT)
56430+ return 2; // specifically denied
56431+ else
56432+ return 1; // allowed
56433+ }
56434+
56435+ return 0; // not specifically allowed, may continue parsing
56436+}
56437+
56438+static int
56439+gr_search_connectbind(const int full_mode, struct sock *sk,
56440+ struct sockaddr_in *addr, const int type)
56441+{
56442+ char iface[IFNAMSIZ] = {0};
56443+ struct acl_subject_label *curr;
56444+ struct acl_ip_label *ip;
56445+ struct inet_sock *isk;
56446+ struct net_device *dev;
56447+ struct in_device *idev;
56448+ unsigned long i;
56449+ int ret;
56450+ int mode = full_mode & (GR_BIND | GR_CONNECT);
56451+ __u32 ip_addr = 0;
56452+ __u32 our_addr;
56453+ __u32 our_netmask;
56454+ char *p;
56455+ __u16 ip_port = 0;
56456+ const struct cred *cred = current_cred();
56457+
56458+ if (unlikely(!gr_acl_is_enabled() || sk->sk_family != PF_INET))
56459+ return 0;
56460+
56461+ curr = current->acl;
56462+ isk = inet_sk(sk);
56463+
56464+ /* INADDR_ANY overriding for binds, inaddr_any_override is already in network order */
56465+ if ((full_mode & GR_BINDOVERRIDE) && addr->sin_addr.s_addr == htonl(INADDR_ANY) && curr->inaddr_any_override != 0)
56466+ addr->sin_addr.s_addr = curr->inaddr_any_override;
56467+ if ((full_mode & GR_CONNECT) && isk->inet_saddr == htonl(INADDR_ANY) && curr->inaddr_any_override != 0) {
56468+ struct sockaddr_in saddr;
56469+ int err;
56470+
56471+ saddr.sin_family = AF_INET;
56472+ saddr.sin_addr.s_addr = curr->inaddr_any_override;
56473+ saddr.sin_port = isk->inet_sport;
56474+
56475+ err = security_socket_bind(sk->sk_socket, (struct sockaddr *)&saddr, sizeof(struct sockaddr_in));
56476+ if (err)
56477+ return err;
56478+
56479+ err = sk->sk_socket->ops->bind(sk->sk_socket, (struct sockaddr *)&saddr, sizeof(struct sockaddr_in));
56480+ if (err)
56481+ return err;
56482+ }
56483+
56484+ if (!curr->ips)
56485+ return 0;
56486+
56487+ ip_addr = addr->sin_addr.s_addr;
56488+ ip_port = ntohs(addr->sin_port);
56489+
56490+ if (curr->mode & (GR_LEARN | GR_INHERITLEARN)) {
56491+ security_learn(GR_IP_LEARN_MSG, current->role->rolename,
56492+ current->role->roletype, cred->uid,
56493+ cred->gid, current->exec_file ?
56494+ gr_to_filename(current->exec_file->f_path.dentry,
56495+ current->exec_file->f_path.mnt) :
56496+ curr->filename, curr->filename,
56497+ &ip_addr, ip_port, type,
56498+ sk->sk_protocol, mode, &current->signal->saved_ip);
56499+ return 0;
56500+ }
56501+
56502+ for (i = 0; i < curr->ip_num; i++) {
56503+ ip = *(curr->ips + i);
56504+ if (ip->iface != NULL) {
56505+ strncpy(iface, ip->iface, IFNAMSIZ - 1);
56506+ p = strchr(iface, ':');
56507+ if (p != NULL)
56508+ *p = '\0';
56509+ dev = dev_get_by_name(sock_net(sk), iface);
56510+ if (dev == NULL)
56511+ continue;
56512+ idev = in_dev_get(dev);
56513+ if (idev == NULL) {
56514+ dev_put(dev);
56515+ continue;
56516+ }
56517+ rcu_read_lock();
56518+ for_ifa(idev) {
56519+ if (!strcmp(ip->iface, ifa->ifa_label)) {
56520+ our_addr = ifa->ifa_address;
56521+ our_netmask = 0xffffffff;
56522+ ret = check_ip_policy(ip, ip_addr, ip_port, sk->sk_protocol, mode, type, our_addr, our_netmask);
56523+ if (ret == 1) {
56524+ rcu_read_unlock();
56525+ in_dev_put(idev);
56526+ dev_put(dev);
56527+ return 0;
56528+ } else if (ret == 2) {
56529+ rcu_read_unlock();
56530+ in_dev_put(idev);
56531+ dev_put(dev);
56532+ goto denied;
56533+ }
56534+ }
56535+ } endfor_ifa(idev);
56536+ rcu_read_unlock();
56537+ in_dev_put(idev);
56538+ dev_put(dev);
56539+ } else {
56540+ our_addr = ip->addr;
56541+ our_netmask = ip->netmask;
56542+ ret = check_ip_policy(ip, ip_addr, ip_port, sk->sk_protocol, mode, type, our_addr, our_netmask);
56543+ if (ret == 1)
56544+ return 0;
56545+ else if (ret == 2)
56546+ goto denied;
56547+ }
56548+ }
56549+
56550+denied:
56551+ if (mode == GR_BIND)
56552+ 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));
56553+ else if (mode == GR_CONNECT)
56554+ 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));
56555+
56556+ return -EACCES;
56557+}
56558+
56559+int
56560+gr_search_connect(struct socket *sock, struct sockaddr_in *addr)
56561+{
56562+ /* always allow disconnection of dgram sockets with connect */
56563+ if (addr->sin_family == AF_UNSPEC)
56564+ return 0;
56565+ return gr_search_connectbind(GR_CONNECT | GR_CONNECTOVERRIDE, sock->sk, addr, sock->type);
56566+}
56567+
56568+int
56569+gr_search_bind(struct socket *sock, struct sockaddr_in *addr)
56570+{
56571+ return gr_search_connectbind(GR_BIND | GR_BINDOVERRIDE, sock->sk, addr, sock->type);
56572+}
56573+
56574+int gr_search_listen(struct socket *sock)
56575+{
56576+ struct sock *sk = sock->sk;
56577+ struct sockaddr_in addr;
56578+
56579+ addr.sin_addr.s_addr = inet_sk(sk)->inet_saddr;
56580+ addr.sin_port = inet_sk(sk)->inet_sport;
56581+
56582+ return gr_search_connectbind(GR_BIND | GR_CONNECTOVERRIDE, sock->sk, &addr, sock->type);
56583+}
56584+
56585+int gr_search_accept(struct socket *sock)
56586+{
56587+ struct sock *sk = sock->sk;
56588+ struct sockaddr_in addr;
56589+
56590+ addr.sin_addr.s_addr = inet_sk(sk)->inet_saddr;
56591+ addr.sin_port = inet_sk(sk)->inet_sport;
56592+
56593+ return gr_search_connectbind(GR_BIND | GR_CONNECTOVERRIDE, sock->sk, &addr, sock->type);
56594+}
56595+
56596+int
56597+gr_search_udp_sendmsg(struct sock *sk, struct sockaddr_in *addr)
56598+{
56599+ if (addr)
56600+ return gr_search_connectbind(GR_CONNECT, sk, addr, SOCK_DGRAM);
56601+ else {
56602+ struct sockaddr_in sin;
56603+ const struct inet_sock *inet = inet_sk(sk);
56604+
56605+ sin.sin_addr.s_addr = inet->inet_daddr;
56606+ sin.sin_port = inet->inet_dport;
56607+
56608+ return gr_search_connectbind(GR_CONNECT | GR_CONNECTOVERRIDE, sk, &sin, SOCK_DGRAM);
56609+ }
56610+}
56611+
56612+int
56613+gr_search_udp_recvmsg(struct sock *sk, const struct sk_buff *skb)
56614+{
56615+ struct sockaddr_in sin;
56616+
56617+ if (unlikely(skb->len < sizeof (struct udphdr)))
56618+ return 0; // skip this packet
56619+
56620+ sin.sin_addr.s_addr = ip_hdr(skb)->saddr;
56621+ sin.sin_port = udp_hdr(skb)->source;
56622+
56623+ return gr_search_connectbind(GR_CONNECT | GR_CONNECTOVERRIDE, sk, &sin, SOCK_DGRAM);
56624+}
56625diff --git a/grsecurity/gracl_learn.c b/grsecurity/gracl_learn.c
56626new file mode 100644
56627index 0000000..25f54ef
56628--- /dev/null
56629+++ b/grsecurity/gracl_learn.c
56630@@ -0,0 +1,207 @@
56631+#include <linux/kernel.h>
56632+#include <linux/mm.h>
56633+#include <linux/sched.h>
56634+#include <linux/poll.h>
56635+#include <linux/string.h>
56636+#include <linux/file.h>
56637+#include <linux/types.h>
56638+#include <linux/vmalloc.h>
56639+#include <linux/grinternal.h>
56640+
56641+extern ssize_t write_grsec_handler(struct file * file, const char __user * buf,
56642+ size_t count, loff_t *ppos);
56643+extern int gr_acl_is_enabled(void);
56644+
56645+static DECLARE_WAIT_QUEUE_HEAD(learn_wait);
56646+static int gr_learn_attached;
56647+
56648+/* use a 512k buffer */
56649+#define LEARN_BUFFER_SIZE (512 * 1024)
56650+
56651+static DEFINE_SPINLOCK(gr_learn_lock);
56652+static DEFINE_MUTEX(gr_learn_user_mutex);
56653+
56654+/* we need to maintain two buffers, so that the kernel context of grlearn
56655+ uses a semaphore around the userspace copying, and the other kernel contexts
56656+ use a spinlock when copying into the buffer, since they cannot sleep
56657+*/
56658+static char *learn_buffer;
56659+static char *learn_buffer_user;
56660+static int learn_buffer_len;
56661+static int learn_buffer_user_len;
56662+
56663+static ssize_t
56664+read_learn(struct file *file, char __user * buf, size_t count, loff_t * ppos)
56665+{
56666+ DECLARE_WAITQUEUE(wait, current);
56667+ ssize_t retval = 0;
56668+
56669+ add_wait_queue(&learn_wait, &wait);
56670+ set_current_state(TASK_INTERRUPTIBLE);
56671+ do {
56672+ mutex_lock(&gr_learn_user_mutex);
56673+ spin_lock(&gr_learn_lock);
56674+ if (learn_buffer_len)
56675+ break;
56676+ spin_unlock(&gr_learn_lock);
56677+ mutex_unlock(&gr_learn_user_mutex);
56678+ if (file->f_flags & O_NONBLOCK) {
56679+ retval = -EAGAIN;
56680+ goto out;
56681+ }
56682+ if (signal_pending(current)) {
56683+ retval = -ERESTARTSYS;
56684+ goto out;
56685+ }
56686+
56687+ schedule();
56688+ } while (1);
56689+
56690+ memcpy(learn_buffer_user, learn_buffer, learn_buffer_len);
56691+ learn_buffer_user_len = learn_buffer_len;
56692+ retval = learn_buffer_len;
56693+ learn_buffer_len = 0;
56694+
56695+ spin_unlock(&gr_learn_lock);
56696+
56697+ if (copy_to_user(buf, learn_buffer_user, learn_buffer_user_len))
56698+ retval = -EFAULT;
56699+
56700+ mutex_unlock(&gr_learn_user_mutex);
56701+out:
56702+ set_current_state(TASK_RUNNING);
56703+ remove_wait_queue(&learn_wait, &wait);
56704+ return retval;
56705+}
56706+
56707+static unsigned int
56708+poll_learn(struct file * file, poll_table * wait)
56709+{
56710+ poll_wait(file, &learn_wait, wait);
56711+
56712+ if (learn_buffer_len)
56713+ return (POLLIN | POLLRDNORM);
56714+
56715+ return 0;
56716+}
56717+
56718+void
56719+gr_clear_learn_entries(void)
56720+{
56721+ char *tmp;
56722+
56723+ mutex_lock(&gr_learn_user_mutex);
56724+ spin_lock(&gr_learn_lock);
56725+ tmp = learn_buffer;
56726+ learn_buffer = NULL;
56727+ spin_unlock(&gr_learn_lock);
56728+ if (tmp)
56729+ vfree(tmp);
56730+ if (learn_buffer_user != NULL) {
56731+ vfree(learn_buffer_user);
56732+ learn_buffer_user = NULL;
56733+ }
56734+ learn_buffer_len = 0;
56735+ mutex_unlock(&gr_learn_user_mutex);
56736+
56737+ return;
56738+}
56739+
56740+void
56741+gr_add_learn_entry(const char *fmt, ...)
56742+{
56743+ va_list args;
56744+ unsigned int len;
56745+
56746+ if (!gr_learn_attached)
56747+ return;
56748+
56749+ spin_lock(&gr_learn_lock);
56750+
56751+ /* leave a gap at the end so we know when it's "full" but don't have to
56752+ compute the exact length of the string we're trying to append
56753+ */
56754+ if (learn_buffer_len > LEARN_BUFFER_SIZE - 16384) {
56755+ spin_unlock(&gr_learn_lock);
56756+ wake_up_interruptible(&learn_wait);
56757+ return;
56758+ }
56759+ if (learn_buffer == NULL) {
56760+ spin_unlock(&gr_learn_lock);
56761+ return;
56762+ }
56763+
56764+ va_start(args, fmt);
56765+ len = vsnprintf(learn_buffer + learn_buffer_len, LEARN_BUFFER_SIZE - learn_buffer_len, fmt, args);
56766+ va_end(args);
56767+
56768+ learn_buffer_len += len + 1;
56769+
56770+ spin_unlock(&gr_learn_lock);
56771+ wake_up_interruptible(&learn_wait);
56772+
56773+ return;
56774+}
56775+
56776+static int
56777+open_learn(struct inode *inode, struct file *file)
56778+{
56779+ if (file->f_mode & FMODE_READ && gr_learn_attached)
56780+ return -EBUSY;
56781+ if (file->f_mode & FMODE_READ) {
56782+ int retval = 0;
56783+ mutex_lock(&gr_learn_user_mutex);
56784+ if (learn_buffer == NULL)
56785+ learn_buffer = vmalloc(LEARN_BUFFER_SIZE);
56786+ if (learn_buffer_user == NULL)
56787+ learn_buffer_user = vmalloc(LEARN_BUFFER_SIZE);
56788+ if (learn_buffer == NULL) {
56789+ retval = -ENOMEM;
56790+ goto out_error;
56791+ }
56792+ if (learn_buffer_user == NULL) {
56793+ retval = -ENOMEM;
56794+ goto out_error;
56795+ }
56796+ learn_buffer_len = 0;
56797+ learn_buffer_user_len = 0;
56798+ gr_learn_attached = 1;
56799+out_error:
56800+ mutex_unlock(&gr_learn_user_mutex);
56801+ return retval;
56802+ }
56803+ return 0;
56804+}
56805+
56806+static int
56807+close_learn(struct inode *inode, struct file *file)
56808+{
56809+ if (file->f_mode & FMODE_READ) {
56810+ char *tmp = NULL;
56811+ mutex_lock(&gr_learn_user_mutex);
56812+ spin_lock(&gr_learn_lock);
56813+ tmp = learn_buffer;
56814+ learn_buffer = NULL;
56815+ spin_unlock(&gr_learn_lock);
56816+ if (tmp)
56817+ vfree(tmp);
56818+ if (learn_buffer_user != NULL) {
56819+ vfree(learn_buffer_user);
56820+ learn_buffer_user = NULL;
56821+ }
56822+ learn_buffer_len = 0;
56823+ learn_buffer_user_len = 0;
56824+ gr_learn_attached = 0;
56825+ mutex_unlock(&gr_learn_user_mutex);
56826+ }
56827+
56828+ return 0;
56829+}
56830+
56831+const struct file_operations grsec_fops = {
56832+ .read = read_learn,
56833+ .write = write_grsec_handler,
56834+ .open = open_learn,
56835+ .release = close_learn,
56836+ .poll = poll_learn,
56837+};
56838diff --git a/grsecurity/gracl_res.c b/grsecurity/gracl_res.c
56839new file mode 100644
56840index 0000000..39645c9
56841--- /dev/null
56842+++ b/grsecurity/gracl_res.c
56843@@ -0,0 +1,68 @@
56844+#include <linux/kernel.h>
56845+#include <linux/sched.h>
56846+#include <linux/gracl.h>
56847+#include <linux/grinternal.h>
56848+
56849+static const char *restab_log[] = {
56850+ [RLIMIT_CPU] = "RLIMIT_CPU",
56851+ [RLIMIT_FSIZE] = "RLIMIT_FSIZE",
56852+ [RLIMIT_DATA] = "RLIMIT_DATA",
56853+ [RLIMIT_STACK] = "RLIMIT_STACK",
56854+ [RLIMIT_CORE] = "RLIMIT_CORE",
56855+ [RLIMIT_RSS] = "RLIMIT_RSS",
56856+ [RLIMIT_NPROC] = "RLIMIT_NPROC",
56857+ [RLIMIT_NOFILE] = "RLIMIT_NOFILE",
56858+ [RLIMIT_MEMLOCK] = "RLIMIT_MEMLOCK",
56859+ [RLIMIT_AS] = "RLIMIT_AS",
56860+ [RLIMIT_LOCKS] = "RLIMIT_LOCKS",
56861+ [RLIMIT_SIGPENDING] = "RLIMIT_SIGPENDING",
56862+ [RLIMIT_MSGQUEUE] = "RLIMIT_MSGQUEUE",
56863+ [RLIMIT_NICE] = "RLIMIT_NICE",
56864+ [RLIMIT_RTPRIO] = "RLIMIT_RTPRIO",
56865+ [RLIMIT_RTTIME] = "RLIMIT_RTTIME",
56866+ [GR_CRASH_RES] = "RLIMIT_CRASH"
56867+};
56868+
56869+void
56870+gr_log_resource(const struct task_struct *task,
56871+ const int res, const unsigned long wanted, const int gt)
56872+{
56873+ const struct cred *cred;
56874+ unsigned long rlim;
56875+
56876+ if (!gr_acl_is_enabled() && !grsec_resource_logging)
56877+ return;
56878+
56879+ // not yet supported resource
56880+ if (unlikely(!restab_log[res]))
56881+ return;
56882+
56883+ if (res == RLIMIT_CPU || res == RLIMIT_RTTIME)
56884+ rlim = task_rlimit_max(task, res);
56885+ else
56886+ rlim = task_rlimit(task, res);
56887+
56888+ if (likely((rlim == RLIM_INFINITY) || (gt && wanted <= rlim) || (!gt && wanted < rlim)))
56889+ return;
56890+
56891+ rcu_read_lock();
56892+ cred = __task_cred(task);
56893+
56894+ if (res == RLIMIT_NPROC &&
56895+ (cap_raised(cred->cap_effective, CAP_SYS_ADMIN) ||
56896+ cap_raised(cred->cap_effective, CAP_SYS_RESOURCE)))
56897+ goto out_rcu_unlock;
56898+ else if (res == RLIMIT_MEMLOCK &&
56899+ cap_raised(cred->cap_effective, CAP_IPC_LOCK))
56900+ goto out_rcu_unlock;
56901+ else if (res == RLIMIT_NICE && cap_raised(cred->cap_effective, CAP_SYS_NICE))
56902+ goto out_rcu_unlock;
56903+ rcu_read_unlock();
56904+
56905+ gr_log_res_ulong2_str(GR_DONT_AUDIT, GR_RESOURCE_MSG, task, wanted, restab_log[res], rlim);
56906+
56907+ return;
56908+out_rcu_unlock:
56909+ rcu_read_unlock();
56910+ return;
56911+}
56912diff --git a/grsecurity/gracl_segv.c b/grsecurity/gracl_segv.c
56913new file mode 100644
56914index 0000000..25197e9
56915--- /dev/null
56916+++ b/grsecurity/gracl_segv.c
56917@@ -0,0 +1,299 @@
56918+#include <linux/kernel.h>
56919+#include <linux/mm.h>
56920+#include <asm/uaccess.h>
56921+#include <asm/errno.h>
56922+#include <asm/mman.h>
56923+#include <net/sock.h>
56924+#include <linux/file.h>
56925+#include <linux/fs.h>
56926+#include <linux/net.h>
56927+#include <linux/in.h>
56928+#include <linux/slab.h>
56929+#include <linux/types.h>
56930+#include <linux/sched.h>
56931+#include <linux/timer.h>
56932+#include <linux/gracl.h>
56933+#include <linux/grsecurity.h>
56934+#include <linux/grinternal.h>
56935+
56936+static struct crash_uid *uid_set;
56937+static unsigned short uid_used;
56938+static DEFINE_SPINLOCK(gr_uid_lock);
56939+extern rwlock_t gr_inode_lock;
56940+extern struct acl_subject_label *
56941+ lookup_acl_subj_label(const ino_t inode, const dev_t dev,
56942+ struct acl_role_label *role);
56943+
56944+#ifdef CONFIG_BTRFS_FS
56945+extern dev_t get_btrfs_dev_from_inode(struct inode *inode);
56946+extern int btrfs_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat);
56947+#endif
56948+
56949+static inline dev_t __get_dev(const struct dentry *dentry)
56950+{
56951+#ifdef CONFIG_BTRFS_FS
56952+ if (dentry->d_inode->i_op && dentry->d_inode->i_op->getattr == &btrfs_getattr)
56953+ return get_btrfs_dev_from_inode(dentry->d_inode);
56954+ else
56955+#endif
56956+ return dentry->d_inode->i_sb->s_dev;
56957+}
56958+
56959+int
56960+gr_init_uidset(void)
56961+{
56962+ uid_set =
56963+ kmalloc(GR_UIDTABLE_MAX * sizeof (struct crash_uid), GFP_KERNEL);
56964+ uid_used = 0;
56965+
56966+ return uid_set ? 1 : 0;
56967+}
56968+
56969+void
56970+gr_free_uidset(void)
56971+{
56972+ if (uid_set)
56973+ kfree(uid_set);
56974+
56975+ return;
56976+}
56977+
56978+int
56979+gr_find_uid(const uid_t uid)
56980+{
56981+ struct crash_uid *tmp = uid_set;
56982+ uid_t buid;
56983+ int low = 0, high = uid_used - 1, mid;
56984+
56985+ while (high >= low) {
56986+ mid = (low + high) >> 1;
56987+ buid = tmp[mid].uid;
56988+ if (buid == uid)
56989+ return mid;
56990+ if (buid > uid)
56991+ high = mid - 1;
56992+ if (buid < uid)
56993+ low = mid + 1;
56994+ }
56995+
56996+ return -1;
56997+}
56998+
56999+static __inline__ void
57000+gr_insertsort(void)
57001+{
57002+ unsigned short i, j;
57003+ struct crash_uid index;
57004+
57005+ for (i = 1; i < uid_used; i++) {
57006+ index = uid_set[i];
57007+ j = i;
57008+ while ((j > 0) && uid_set[j - 1].uid > index.uid) {
57009+ uid_set[j] = uid_set[j - 1];
57010+ j--;
57011+ }
57012+ uid_set[j] = index;
57013+ }
57014+
57015+ return;
57016+}
57017+
57018+static __inline__ void
57019+gr_insert_uid(const uid_t uid, const unsigned long expires)
57020+{
57021+ int loc;
57022+
57023+ if (uid_used == GR_UIDTABLE_MAX)
57024+ return;
57025+
57026+ loc = gr_find_uid(uid);
57027+
57028+ if (loc >= 0) {
57029+ uid_set[loc].expires = expires;
57030+ return;
57031+ }
57032+
57033+ uid_set[uid_used].uid = uid;
57034+ uid_set[uid_used].expires = expires;
57035+ uid_used++;
57036+
57037+ gr_insertsort();
57038+
57039+ return;
57040+}
57041+
57042+void
57043+gr_remove_uid(const unsigned short loc)
57044+{
57045+ unsigned short i;
57046+
57047+ for (i = loc + 1; i < uid_used; i++)
57048+ uid_set[i - 1] = uid_set[i];
57049+
57050+ uid_used--;
57051+
57052+ return;
57053+}
57054+
57055+int
57056+gr_check_crash_uid(const uid_t uid)
57057+{
57058+ int loc;
57059+ int ret = 0;
57060+
57061+ if (unlikely(!gr_acl_is_enabled()))
57062+ return 0;
57063+
57064+ spin_lock(&gr_uid_lock);
57065+ loc = gr_find_uid(uid);
57066+
57067+ if (loc < 0)
57068+ goto out_unlock;
57069+
57070+ if (time_before_eq(uid_set[loc].expires, get_seconds()))
57071+ gr_remove_uid(loc);
57072+ else
57073+ ret = 1;
57074+
57075+out_unlock:
57076+ spin_unlock(&gr_uid_lock);
57077+ return ret;
57078+}
57079+
57080+static __inline__ int
57081+proc_is_setxid(const struct cred *cred)
57082+{
57083+ if (!uid_eq(cred->uid, cred->euid) || !uid_eq(cred->uid, cred->suid) ||
57084+ !uid_eq(cred->uid, cred->fsuid))
57085+ return 1;
57086+ if (!uid_eq(cred->gid, cred->egid) || !uid_eq(cred->gid, cred->sgid) ||
57087+ !uid_eq(cred->gid, cred->fsgid))
57088+ return 1;
57089+
57090+ return 0;
57091+}
57092+
57093+extern int gr_fake_force_sig(int sig, struct task_struct *t);
57094+
57095+void
57096+gr_handle_crash(struct task_struct *task, const int sig)
57097+{
57098+ struct acl_subject_label *curr;
57099+ struct task_struct *tsk, *tsk2;
57100+ const struct cred *cred;
57101+ const struct cred *cred2;
57102+
57103+ if (sig != SIGSEGV && sig != SIGKILL && sig != SIGBUS && sig != SIGILL)
57104+ return;
57105+
57106+ if (unlikely(!gr_acl_is_enabled()))
57107+ return;
57108+
57109+ curr = task->acl;
57110+
57111+ if (!(curr->resmask & (1 << GR_CRASH_RES)))
57112+ return;
57113+
57114+ if (time_before_eq(curr->expires, get_seconds())) {
57115+ curr->expires = 0;
57116+ curr->crashes = 0;
57117+ }
57118+
57119+ curr->crashes++;
57120+
57121+ if (!curr->expires)
57122+ curr->expires = get_seconds() + curr->res[GR_CRASH_RES].rlim_max;
57123+
57124+ if ((curr->crashes >= curr->res[GR_CRASH_RES].rlim_cur) &&
57125+ time_after(curr->expires, get_seconds())) {
57126+ rcu_read_lock();
57127+ cred = __task_cred(task);
57128+ if (!uid_eq(cred->uid, GLOBAL_ROOT_UID) && proc_is_setxid(cred)) {
57129+ gr_log_crash1(GR_DONT_AUDIT, GR_SEGVSTART_ACL_MSG, task, curr->res[GR_CRASH_RES].rlim_max);
57130+ spin_lock(&gr_uid_lock);
57131+ gr_insert_uid(cred->uid, curr->expires);
57132+ spin_unlock(&gr_uid_lock);
57133+ curr->expires = 0;
57134+ curr->crashes = 0;
57135+ read_lock(&tasklist_lock);
57136+ do_each_thread(tsk2, tsk) {
57137+ cred2 = __task_cred(tsk);
57138+ if (tsk != task && uid_eq(cred2->uid, cred->uid))
57139+ gr_fake_force_sig(SIGKILL, tsk);
57140+ } while_each_thread(tsk2, tsk);
57141+ read_unlock(&tasklist_lock);
57142+ } else {
57143+ gr_log_crash2(GR_DONT_AUDIT, GR_SEGVNOSUID_ACL_MSG, task, curr->res[GR_CRASH_RES].rlim_max);
57144+ read_lock(&tasklist_lock);
57145+ read_lock(&grsec_exec_file_lock);
57146+ do_each_thread(tsk2, tsk) {
57147+ if (likely(tsk != task)) {
57148+ // if this thread has the same subject as the one that triggered
57149+ // RES_CRASH and it's the same binary, kill it
57150+ if (tsk->acl == task->acl && tsk->exec_file == task->exec_file)
57151+ gr_fake_force_sig(SIGKILL, tsk);
57152+ }
57153+ } while_each_thread(tsk2, tsk);
57154+ read_unlock(&grsec_exec_file_lock);
57155+ read_unlock(&tasklist_lock);
57156+ }
57157+ rcu_read_unlock();
57158+ }
57159+
57160+ return;
57161+}
57162+
57163+int
57164+gr_check_crash_exec(const struct file *filp)
57165+{
57166+ struct acl_subject_label *curr;
57167+
57168+ if (unlikely(!gr_acl_is_enabled()))
57169+ return 0;
57170+
57171+ read_lock(&gr_inode_lock);
57172+ curr = lookup_acl_subj_label(filp->f_path.dentry->d_inode->i_ino,
57173+ __get_dev(filp->f_path.dentry),
57174+ current->role);
57175+ read_unlock(&gr_inode_lock);
57176+
57177+ if (!curr || !(curr->resmask & (1 << GR_CRASH_RES)) ||
57178+ (!curr->crashes && !curr->expires))
57179+ return 0;
57180+
57181+ if ((curr->crashes >= curr->res[GR_CRASH_RES].rlim_cur) &&
57182+ time_after(curr->expires, get_seconds()))
57183+ return 1;
57184+ else if (time_before_eq(curr->expires, get_seconds())) {
57185+ curr->crashes = 0;
57186+ curr->expires = 0;
57187+ }
57188+
57189+ return 0;
57190+}
57191+
57192+void
57193+gr_handle_alertkill(struct task_struct *task)
57194+{
57195+ struct acl_subject_label *curracl;
57196+ __u32 curr_ip;
57197+ struct task_struct *p, *p2;
57198+
57199+ if (unlikely(!gr_acl_is_enabled()))
57200+ return;
57201+
57202+ curracl = task->acl;
57203+ curr_ip = task->signal->curr_ip;
57204+
57205+ if ((curracl->mode & GR_KILLIPPROC) && curr_ip) {
57206+ read_lock(&tasklist_lock);
57207+ do_each_thread(p2, p) {
57208+ if (p->signal->curr_ip == curr_ip)
57209+ gr_fake_force_sig(SIGKILL, p);
57210+ } while_each_thread(p2, p);
57211+ read_unlock(&tasklist_lock);
57212+ } else if (curracl->mode & GR_KILLPROC)
57213+ gr_fake_force_sig(SIGKILL, task);
57214+
57215+ return;
57216+}
57217diff --git a/grsecurity/gracl_shm.c b/grsecurity/gracl_shm.c
57218new file mode 100644
57219index 0000000..9d83a69
57220--- /dev/null
57221+++ b/grsecurity/gracl_shm.c
57222@@ -0,0 +1,40 @@
57223+#include <linux/kernel.h>
57224+#include <linux/mm.h>
57225+#include <linux/sched.h>
57226+#include <linux/file.h>
57227+#include <linux/ipc.h>
57228+#include <linux/gracl.h>
57229+#include <linux/grsecurity.h>
57230+#include <linux/grinternal.h>
57231+
57232+int
57233+gr_handle_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
57234+ const time_t shm_createtime, const uid_t cuid, const int shmid)
57235+{
57236+ struct task_struct *task;
57237+
57238+ if (!gr_acl_is_enabled())
57239+ return 1;
57240+
57241+ rcu_read_lock();
57242+ read_lock(&tasklist_lock);
57243+
57244+ task = find_task_by_vpid(shm_cprid);
57245+
57246+ if (unlikely(!task))
57247+ task = find_task_by_vpid(shm_lapid);
57248+
57249+ if (unlikely(task && (time_before_eq((unsigned long)task->start_time.tv_sec, (unsigned long)shm_createtime) ||
57250+ (task->pid == shm_lapid)) &&
57251+ (task->acl->mode & GR_PROTSHM) &&
57252+ (task->acl != current->acl))) {
57253+ read_unlock(&tasklist_lock);
57254+ rcu_read_unlock();
57255+ gr_log_int3(GR_DONT_AUDIT, GR_SHMAT_ACL_MSG, cuid, shm_cprid, shmid);
57256+ return 0;
57257+ }
57258+ read_unlock(&tasklist_lock);
57259+ rcu_read_unlock();
57260+
57261+ return 1;
57262+}
57263diff --git a/grsecurity/grsec_chdir.c b/grsecurity/grsec_chdir.c
57264new file mode 100644
57265index 0000000..bc0be01
57266--- /dev/null
57267+++ b/grsecurity/grsec_chdir.c
57268@@ -0,0 +1,19 @@
57269+#include <linux/kernel.h>
57270+#include <linux/sched.h>
57271+#include <linux/fs.h>
57272+#include <linux/file.h>
57273+#include <linux/grsecurity.h>
57274+#include <linux/grinternal.h>
57275+
57276+void
57277+gr_log_chdir(const struct dentry *dentry, const struct vfsmount *mnt)
57278+{
57279+#ifdef CONFIG_GRKERNSEC_AUDIT_CHDIR
57280+ if ((grsec_enable_chdir && grsec_enable_group &&
57281+ in_group_p(grsec_audit_gid)) || (grsec_enable_chdir &&
57282+ !grsec_enable_group)) {
57283+ gr_log_fs_generic(GR_DO_AUDIT, GR_CHDIR_AUDIT_MSG, dentry, mnt);
57284+ }
57285+#endif
57286+ return;
57287+}
57288diff --git a/grsecurity/grsec_chroot.c b/grsecurity/grsec_chroot.c
57289new file mode 100644
57290index 0000000..9807ee2
57291--- /dev/null
57292+++ b/grsecurity/grsec_chroot.c
57293@@ -0,0 +1,368 @@
57294+#include <linux/kernel.h>
57295+#include <linux/module.h>
57296+#include <linux/sched.h>
57297+#include <linux/file.h>
57298+#include <linux/fs.h>
57299+#include <linux/mount.h>
57300+#include <linux/types.h>
57301+#include "../fs/mount.h"
57302+#include <linux/grsecurity.h>
57303+#include <linux/grinternal.h>
57304+
57305+void gr_set_chroot_entries(struct task_struct *task, struct path *path)
57306+{
57307+#ifdef CONFIG_GRKERNSEC
57308+ if (task->pid > 1 && path->dentry != init_task.fs->root.dentry &&
57309+ path->dentry != task->nsproxy->mnt_ns->root->mnt.mnt_root)
57310+ task->gr_is_chrooted = 1;
57311+ else
57312+ task->gr_is_chrooted = 0;
57313+
57314+ task->gr_chroot_dentry = path->dentry;
57315+#endif
57316+ return;
57317+}
57318+
57319+void gr_clear_chroot_entries(struct task_struct *task)
57320+{
57321+#ifdef CONFIG_GRKERNSEC
57322+ task->gr_is_chrooted = 0;
57323+ task->gr_chroot_dentry = NULL;
57324+#endif
57325+ return;
57326+}
57327+
57328+int
57329+gr_handle_chroot_unix(const pid_t pid)
57330+{
57331+#ifdef CONFIG_GRKERNSEC_CHROOT_UNIX
57332+ struct task_struct *p;
57333+
57334+ if (unlikely(!grsec_enable_chroot_unix))
57335+ return 1;
57336+
57337+ if (likely(!proc_is_chrooted(current)))
57338+ return 1;
57339+
57340+ rcu_read_lock();
57341+ read_lock(&tasklist_lock);
57342+ p = find_task_by_vpid_unrestricted(pid);
57343+ if (unlikely(p && !have_same_root(current, p))) {
57344+ read_unlock(&tasklist_lock);
57345+ rcu_read_unlock();
57346+ gr_log_noargs(GR_DONT_AUDIT, GR_UNIX_CHROOT_MSG);
57347+ return 0;
57348+ }
57349+ read_unlock(&tasklist_lock);
57350+ rcu_read_unlock();
57351+#endif
57352+ return 1;
57353+}
57354+
57355+int
57356+gr_handle_chroot_nice(void)
57357+{
57358+#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
57359+ if (grsec_enable_chroot_nice && proc_is_chrooted(current)) {
57360+ gr_log_noargs(GR_DONT_AUDIT, GR_NICE_CHROOT_MSG);
57361+ return -EPERM;
57362+ }
57363+#endif
57364+ return 0;
57365+}
57366+
57367+int
57368+gr_handle_chroot_setpriority(struct task_struct *p, const int niceval)
57369+{
57370+#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
57371+ if (grsec_enable_chroot_nice && (niceval < task_nice(p))
57372+ && proc_is_chrooted(current)) {
57373+ gr_log_str_int(GR_DONT_AUDIT, GR_PRIORITY_CHROOT_MSG, p->comm, p->pid);
57374+ return -EACCES;
57375+ }
57376+#endif
57377+ return 0;
57378+}
57379+
57380+int
57381+gr_handle_chroot_rawio(const struct inode *inode)
57382+{
57383+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
57384+ if (grsec_enable_chroot_caps && proc_is_chrooted(current) &&
57385+ inode && S_ISBLK(inode->i_mode) && !capable(CAP_SYS_RAWIO))
57386+ return 1;
57387+#endif
57388+ return 0;
57389+}
57390+
57391+int
57392+gr_handle_chroot_fowner(struct pid *pid, enum pid_type type)
57393+{
57394+#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
57395+ struct task_struct *p;
57396+ int ret = 0;
57397+ if (!grsec_enable_chroot_findtask || !proc_is_chrooted(current) || !pid)
57398+ return ret;
57399+
57400+ read_lock(&tasklist_lock);
57401+ do_each_pid_task(pid, type, p) {
57402+ if (!have_same_root(current, p)) {
57403+ ret = 1;
57404+ goto out;
57405+ }
57406+ } while_each_pid_task(pid, type, p);
57407+out:
57408+ read_unlock(&tasklist_lock);
57409+ return ret;
57410+#endif
57411+ return 0;
57412+}
57413+
57414+int
57415+gr_pid_is_chrooted(struct task_struct *p)
57416+{
57417+#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
57418+ if (!grsec_enable_chroot_findtask || !proc_is_chrooted(current) || p == NULL)
57419+ return 0;
57420+
57421+ if ((p->exit_state & (EXIT_ZOMBIE | EXIT_DEAD)) ||
57422+ !have_same_root(current, p)) {
57423+ return 1;
57424+ }
57425+#endif
57426+ return 0;
57427+}
57428+
57429+EXPORT_SYMBOL(gr_pid_is_chrooted);
57430+
57431+#if defined(CONFIG_GRKERNSEC_CHROOT_DOUBLE) || defined(CONFIG_GRKERNSEC_CHROOT_FCHDIR)
57432+int gr_is_outside_chroot(const struct dentry *u_dentry, const struct vfsmount *u_mnt)
57433+{
57434+ struct path path, currentroot;
57435+ int ret = 0;
57436+
57437+ path.dentry = (struct dentry *)u_dentry;
57438+ path.mnt = (struct vfsmount *)u_mnt;
57439+ get_fs_root(current->fs, &currentroot);
57440+ if (path_is_under(&path, &currentroot))
57441+ ret = 1;
57442+ path_put(&currentroot);
57443+
57444+ return ret;
57445+}
57446+#endif
57447+
57448+int
57449+gr_chroot_fchdir(struct dentry *u_dentry, struct vfsmount *u_mnt)
57450+{
57451+#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
57452+ if (!grsec_enable_chroot_fchdir)
57453+ return 1;
57454+
57455+ if (!proc_is_chrooted(current))
57456+ return 1;
57457+ else if (!gr_is_outside_chroot(u_dentry, u_mnt)) {
57458+ gr_log_fs_generic(GR_DONT_AUDIT, GR_CHROOT_FCHDIR_MSG, u_dentry, u_mnt);
57459+ return 0;
57460+ }
57461+#endif
57462+ return 1;
57463+}
57464+
57465+int
57466+gr_chroot_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
57467+ const time_t shm_createtime)
57468+{
57469+#ifdef CONFIG_GRKERNSEC_CHROOT_SHMAT
57470+ struct task_struct *p;
57471+ time_t starttime;
57472+
57473+ if (unlikely(!grsec_enable_chroot_shmat))
57474+ return 1;
57475+
57476+ if (likely(!proc_is_chrooted(current)))
57477+ return 1;
57478+
57479+ rcu_read_lock();
57480+ read_lock(&tasklist_lock);
57481+
57482+ if ((p = find_task_by_vpid_unrestricted(shm_cprid))) {
57483+ starttime = p->start_time.tv_sec;
57484+ if (time_before_eq((unsigned long)starttime, (unsigned long)shm_createtime)) {
57485+ if (have_same_root(current, p)) {
57486+ goto allow;
57487+ } else {
57488+ read_unlock(&tasklist_lock);
57489+ rcu_read_unlock();
57490+ gr_log_noargs(GR_DONT_AUDIT, GR_SHMAT_CHROOT_MSG);
57491+ return 0;
57492+ }
57493+ }
57494+ /* creator exited, pid reuse, fall through to next check */
57495+ }
57496+ if ((p = find_task_by_vpid_unrestricted(shm_lapid))) {
57497+ if (unlikely(!have_same_root(current, p))) {
57498+ read_unlock(&tasklist_lock);
57499+ rcu_read_unlock();
57500+ gr_log_noargs(GR_DONT_AUDIT, GR_SHMAT_CHROOT_MSG);
57501+ return 0;
57502+ }
57503+ }
57504+
57505+allow:
57506+ read_unlock(&tasklist_lock);
57507+ rcu_read_unlock();
57508+#endif
57509+ return 1;
57510+}
57511+
57512+void
57513+gr_log_chroot_exec(const struct dentry *dentry, const struct vfsmount *mnt)
57514+{
57515+#ifdef CONFIG_GRKERNSEC_CHROOT_EXECLOG
57516+ if (grsec_enable_chroot_execlog && proc_is_chrooted(current))
57517+ gr_log_fs_generic(GR_DO_AUDIT, GR_EXEC_CHROOT_MSG, dentry, mnt);
57518+#endif
57519+ return;
57520+}
57521+
57522+int
57523+gr_handle_chroot_mknod(const struct dentry *dentry,
57524+ const struct vfsmount *mnt, const int mode)
57525+{
57526+#ifdef CONFIG_GRKERNSEC_CHROOT_MKNOD
57527+ if (grsec_enable_chroot_mknod && !S_ISFIFO(mode) && !S_ISREG(mode) &&
57528+ proc_is_chrooted(current)) {
57529+ gr_log_fs_generic(GR_DONT_AUDIT, GR_MKNOD_CHROOT_MSG, dentry, mnt);
57530+ return -EPERM;
57531+ }
57532+#endif
57533+ return 0;
57534+}
57535+
57536+int
57537+gr_handle_chroot_mount(const struct dentry *dentry,
57538+ const struct vfsmount *mnt, const char *dev_name)
57539+{
57540+#ifdef CONFIG_GRKERNSEC_CHROOT_MOUNT
57541+ if (grsec_enable_chroot_mount && proc_is_chrooted(current)) {
57542+ gr_log_str_fs(GR_DONT_AUDIT, GR_MOUNT_CHROOT_MSG, dev_name ? dev_name : "none", dentry, mnt);
57543+ return -EPERM;
57544+ }
57545+#endif
57546+ return 0;
57547+}
57548+
57549+int
57550+gr_handle_chroot_pivot(void)
57551+{
57552+#ifdef CONFIG_GRKERNSEC_CHROOT_PIVOT
57553+ if (grsec_enable_chroot_pivot && proc_is_chrooted(current)) {
57554+ gr_log_noargs(GR_DONT_AUDIT, GR_PIVOT_CHROOT_MSG);
57555+ return -EPERM;
57556+ }
57557+#endif
57558+ return 0;
57559+}
57560+
57561+int
57562+gr_handle_chroot_chroot(const struct dentry *dentry, const struct vfsmount *mnt)
57563+{
57564+#ifdef CONFIG_GRKERNSEC_CHROOT_DOUBLE
57565+ if (grsec_enable_chroot_double && proc_is_chrooted(current) &&
57566+ !gr_is_outside_chroot(dentry, mnt)) {
57567+ gr_log_fs_generic(GR_DONT_AUDIT, GR_CHROOT_CHROOT_MSG, dentry, mnt);
57568+ return -EPERM;
57569+ }
57570+#endif
57571+ return 0;
57572+}
57573+
57574+extern const char *captab_log[];
57575+extern int captab_log_entries;
57576+
57577+int
57578+gr_task_chroot_is_capable(const struct task_struct *task, const struct cred *cred, const int cap)
57579+{
57580+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
57581+ if (grsec_enable_chroot_caps && proc_is_chrooted(task)) {
57582+ kernel_cap_t chroot_caps = GR_CHROOT_CAPS;
57583+ if (cap_raised(chroot_caps, cap)) {
57584+ if (cap_raised(cred->cap_effective, cap) && cap < captab_log_entries) {
57585+ gr_log_cap(GR_DONT_AUDIT, GR_CAP_CHROOT_MSG, task, captab_log[cap]);
57586+ }
57587+ return 0;
57588+ }
57589+ }
57590+#endif
57591+ return 1;
57592+}
57593+
57594+int
57595+gr_chroot_is_capable(const int cap)
57596+{
57597+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
57598+ return gr_task_chroot_is_capable(current, current_cred(), cap);
57599+#endif
57600+ return 1;
57601+}
57602+
57603+int
57604+gr_task_chroot_is_capable_nolog(const struct task_struct *task, const int cap)
57605+{
57606+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
57607+ if (grsec_enable_chroot_caps && proc_is_chrooted(task)) {
57608+ kernel_cap_t chroot_caps = GR_CHROOT_CAPS;
57609+ if (cap_raised(chroot_caps, cap)) {
57610+ return 0;
57611+ }
57612+ }
57613+#endif
57614+ return 1;
57615+}
57616+
57617+int
57618+gr_chroot_is_capable_nolog(const int cap)
57619+{
57620+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
57621+ return gr_task_chroot_is_capable_nolog(current, cap);
57622+#endif
57623+ return 1;
57624+}
57625+
57626+int
57627+gr_handle_chroot_sysctl(const int op)
57628+{
57629+#ifdef CONFIG_GRKERNSEC_CHROOT_SYSCTL
57630+ if (grsec_enable_chroot_sysctl && (op & MAY_WRITE) &&
57631+ proc_is_chrooted(current))
57632+ return -EACCES;
57633+#endif
57634+ return 0;
57635+}
57636+
57637+void
57638+gr_handle_chroot_chdir(struct path *path)
57639+{
57640+#ifdef CONFIG_GRKERNSEC_CHROOT_CHDIR
57641+ if (grsec_enable_chroot_chdir)
57642+ set_fs_pwd(current->fs, path);
57643+#endif
57644+ return;
57645+}
57646+
57647+int
57648+gr_handle_chroot_chmod(const struct dentry *dentry,
57649+ const struct vfsmount *mnt, const int mode)
57650+{
57651+#ifdef CONFIG_GRKERNSEC_CHROOT_CHMOD
57652+ /* allow chmod +s on directories, but not files */
57653+ if (grsec_enable_chroot_chmod && !S_ISDIR(dentry->d_inode->i_mode) &&
57654+ ((mode & S_ISUID) || ((mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))) &&
57655+ proc_is_chrooted(current)) {
57656+ gr_log_fs_generic(GR_DONT_AUDIT, GR_CHMOD_CHROOT_MSG, dentry, mnt);
57657+ return -EPERM;
57658+ }
57659+#endif
57660+ return 0;
57661+}
57662diff --git a/grsecurity/grsec_disabled.c b/grsecurity/grsec_disabled.c
57663new file mode 100644
57664index 0000000..213ad8b
57665--- /dev/null
57666+++ b/grsecurity/grsec_disabled.c
57667@@ -0,0 +1,437 @@
57668+#include <linux/kernel.h>
57669+#include <linux/module.h>
57670+#include <linux/sched.h>
57671+#include <linux/file.h>
57672+#include <linux/fs.h>
57673+#include <linux/kdev_t.h>
57674+#include <linux/net.h>
57675+#include <linux/in.h>
57676+#include <linux/ip.h>
57677+#include <linux/skbuff.h>
57678+#include <linux/sysctl.h>
57679+
57680+#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
57681+void
57682+pax_set_initial_flags(struct linux_binprm *bprm)
57683+{
57684+ return;
57685+}
57686+#endif
57687+
57688+#ifdef CONFIG_SYSCTL
57689+__u32
57690+gr_handle_sysctl(const struct ctl_table * table, const int op)
57691+{
57692+ return 0;
57693+}
57694+#endif
57695+
57696+#ifdef CONFIG_TASKSTATS
57697+int gr_is_taskstats_denied(int pid)
57698+{
57699+ return 0;
57700+}
57701+#endif
57702+
57703+int
57704+gr_acl_is_enabled(void)
57705+{
57706+ return 0;
57707+}
57708+
57709+void
57710+gr_handle_proc_create(const struct dentry *dentry, const struct inode *inode)
57711+{
57712+ return;
57713+}
57714+
57715+int
57716+gr_handle_rawio(const struct inode *inode)
57717+{
57718+ return 0;
57719+}
57720+
57721+void
57722+gr_acl_handle_psacct(struct task_struct *task, const long code)
57723+{
57724+ return;
57725+}
57726+
57727+int
57728+gr_handle_ptrace(struct task_struct *task, const long request)
57729+{
57730+ return 0;
57731+}
57732+
57733+int
57734+gr_handle_proc_ptrace(struct task_struct *task)
57735+{
57736+ return 0;
57737+}
57738+
57739+void
57740+gr_learn_resource(const struct task_struct *task,
57741+ const int res, const unsigned long wanted, const int gt)
57742+{
57743+ return;
57744+}
57745+
57746+int
57747+gr_set_acls(const int type)
57748+{
57749+ return 0;
57750+}
57751+
57752+int
57753+gr_check_hidden_task(const struct task_struct *tsk)
57754+{
57755+ return 0;
57756+}
57757+
57758+int
57759+gr_check_protected_task(const struct task_struct *task)
57760+{
57761+ return 0;
57762+}
57763+
57764+int
57765+gr_check_protected_task_fowner(struct pid *pid, enum pid_type type)
57766+{
57767+ return 0;
57768+}
57769+
57770+void
57771+gr_copy_label(struct task_struct *tsk)
57772+{
57773+ return;
57774+}
57775+
57776+void
57777+gr_set_pax_flags(struct task_struct *task)
57778+{
57779+ return;
57780+}
57781+
57782+int
57783+gr_set_proc_label(const struct dentry *dentry, const struct vfsmount *mnt,
57784+ const int unsafe_share)
57785+{
57786+ return 0;
57787+}
57788+
57789+void
57790+gr_handle_delete(const ino_t ino, const dev_t dev)
57791+{
57792+ return;
57793+}
57794+
57795+void
57796+gr_handle_create(const struct dentry *dentry, const struct vfsmount *mnt)
57797+{
57798+ return;
57799+}
57800+
57801+void
57802+gr_handle_crash(struct task_struct *task, const int sig)
57803+{
57804+ return;
57805+}
57806+
57807+int
57808+gr_check_crash_exec(const struct file *filp)
57809+{
57810+ return 0;
57811+}
57812+
57813+int
57814+gr_check_crash_uid(const uid_t uid)
57815+{
57816+ return 0;
57817+}
57818+
57819+void
57820+gr_handle_rename(struct inode *old_dir, struct inode *new_dir,
57821+ struct dentry *old_dentry,
57822+ struct dentry *new_dentry,
57823+ struct vfsmount *mnt, const __u8 replace)
57824+{
57825+ return;
57826+}
57827+
57828+int
57829+gr_search_socket(const int family, const int type, const int protocol)
57830+{
57831+ return 1;
57832+}
57833+
57834+int
57835+gr_search_connectbind(const int mode, const struct socket *sock,
57836+ const struct sockaddr_in *addr)
57837+{
57838+ return 0;
57839+}
57840+
57841+void
57842+gr_handle_alertkill(struct task_struct *task)
57843+{
57844+ return;
57845+}
57846+
57847+__u32
57848+gr_acl_handle_execve(const struct dentry * dentry, const struct vfsmount * mnt)
57849+{
57850+ return 1;
57851+}
57852+
57853+__u32
57854+gr_acl_handle_hidden_file(const struct dentry * dentry,
57855+ const struct vfsmount * mnt)
57856+{
57857+ return 1;
57858+}
57859+
57860+__u32
57861+gr_acl_handle_open(const struct dentry * dentry, const struct vfsmount * mnt,
57862+ int acc_mode)
57863+{
57864+ return 1;
57865+}
57866+
57867+__u32
57868+gr_acl_handle_rmdir(const struct dentry * dentry, const struct vfsmount * mnt)
57869+{
57870+ return 1;
57871+}
57872+
57873+__u32
57874+gr_acl_handle_unlink(const struct dentry * dentry, const struct vfsmount * mnt)
57875+{
57876+ return 1;
57877+}
57878+
57879+int
57880+gr_acl_handle_mmap(const struct file *file, const unsigned long prot,
57881+ unsigned int *vm_flags)
57882+{
57883+ return 1;
57884+}
57885+
57886+__u32
57887+gr_acl_handle_truncate(const struct dentry * dentry,
57888+ const struct vfsmount * mnt)
57889+{
57890+ return 1;
57891+}
57892+
57893+__u32
57894+gr_acl_handle_utime(const struct dentry * dentry, const struct vfsmount * mnt)
57895+{
57896+ return 1;
57897+}
57898+
57899+__u32
57900+gr_acl_handle_access(const struct dentry * dentry,
57901+ const struct vfsmount * mnt, const int fmode)
57902+{
57903+ return 1;
57904+}
57905+
57906+__u32
57907+gr_acl_handle_chmod(const struct dentry * dentry, const struct vfsmount * mnt,
57908+ umode_t *mode)
57909+{
57910+ return 1;
57911+}
57912+
57913+__u32
57914+gr_acl_handle_chown(const struct dentry * dentry, const struct vfsmount * mnt)
57915+{
57916+ return 1;
57917+}
57918+
57919+__u32
57920+gr_acl_handle_setxattr(const struct dentry * dentry, const struct vfsmount * mnt)
57921+{
57922+ return 1;
57923+}
57924+
57925+void
57926+grsecurity_init(void)
57927+{
57928+ return;
57929+}
57930+
57931+umode_t gr_acl_umask(void)
57932+{
57933+ return 0;
57934+}
57935+
57936+__u32
57937+gr_acl_handle_mknod(const struct dentry * new_dentry,
57938+ const struct dentry * parent_dentry,
57939+ const struct vfsmount * parent_mnt,
57940+ const int mode)
57941+{
57942+ return 1;
57943+}
57944+
57945+__u32
57946+gr_acl_handle_mkdir(const struct dentry * new_dentry,
57947+ const struct dentry * parent_dentry,
57948+ const struct vfsmount * parent_mnt)
57949+{
57950+ return 1;
57951+}
57952+
57953+__u32
57954+gr_acl_handle_symlink(const struct dentry * new_dentry,
57955+ const struct dentry * parent_dentry,
57956+ const struct vfsmount * parent_mnt, const char *from)
57957+{
57958+ return 1;
57959+}
57960+
57961+__u32
57962+gr_acl_handle_link(const struct dentry * new_dentry,
57963+ const struct dentry * parent_dentry,
57964+ const struct vfsmount * parent_mnt,
57965+ const struct dentry * old_dentry,
57966+ const struct vfsmount * old_mnt, const char *to)
57967+{
57968+ return 1;
57969+}
57970+
57971+int
57972+gr_acl_handle_rename(const struct dentry *new_dentry,
57973+ const struct dentry *parent_dentry,
57974+ const struct vfsmount *parent_mnt,
57975+ const struct dentry *old_dentry,
57976+ const struct inode *old_parent_inode,
57977+ const struct vfsmount *old_mnt, const char *newname)
57978+{
57979+ return 0;
57980+}
57981+
57982+int
57983+gr_acl_handle_filldir(const struct file *file, const char *name,
57984+ const int namelen, const ino_t ino)
57985+{
57986+ return 1;
57987+}
57988+
57989+int
57990+gr_handle_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
57991+ const time_t shm_createtime, const uid_t cuid, const int shmid)
57992+{
57993+ return 1;
57994+}
57995+
57996+int
57997+gr_search_bind(const struct socket *sock, const struct sockaddr_in *addr)
57998+{
57999+ return 0;
58000+}
58001+
58002+int
58003+gr_search_accept(const struct socket *sock)
58004+{
58005+ return 0;
58006+}
58007+
58008+int
58009+gr_search_listen(const struct socket *sock)
58010+{
58011+ return 0;
58012+}
58013+
58014+int
58015+gr_search_connect(const struct socket *sock, const struct sockaddr_in *addr)
58016+{
58017+ return 0;
58018+}
58019+
58020+__u32
58021+gr_acl_handle_unix(const struct dentry * dentry, const struct vfsmount * mnt)
58022+{
58023+ return 1;
58024+}
58025+
58026+__u32
58027+gr_acl_handle_creat(const struct dentry * dentry,
58028+ const struct dentry * p_dentry,
58029+ const struct vfsmount * p_mnt, int open_flags, int acc_mode,
58030+ const int imode)
58031+{
58032+ return 1;
58033+}
58034+
58035+void
58036+gr_acl_handle_exit(void)
58037+{
58038+ return;
58039+}
58040+
58041+int
58042+gr_acl_handle_mprotect(const struct file *file, const unsigned long prot)
58043+{
58044+ return 1;
58045+}
58046+
58047+void
58048+gr_set_role_label(const uid_t uid, const gid_t gid)
58049+{
58050+ return;
58051+}
58052+
58053+int
58054+gr_acl_handle_procpidmem(const struct task_struct *task)
58055+{
58056+ return 0;
58057+}
58058+
58059+int
58060+gr_search_udp_recvmsg(const struct sock *sk, const struct sk_buff *skb)
58061+{
58062+ return 0;
58063+}
58064+
58065+int
58066+gr_search_udp_sendmsg(const struct sock *sk, const struct sockaddr_in *addr)
58067+{
58068+ return 0;
58069+}
58070+
58071+void
58072+gr_set_kernel_label(struct task_struct *task)
58073+{
58074+ return;
58075+}
58076+
58077+int
58078+gr_check_user_change(int real, int effective, int fs)
58079+{
58080+ return 0;
58081+}
58082+
58083+int
58084+gr_check_group_change(int real, int effective, int fs)
58085+{
58086+ return 0;
58087+}
58088+
58089+int gr_acl_enable_at_secure(void)
58090+{
58091+ return 0;
58092+}
58093+
58094+dev_t gr_get_dev_from_dentry(struct dentry *dentry)
58095+{
58096+ return dentry->d_inode->i_sb->s_dev;
58097+}
58098+
58099+EXPORT_SYMBOL(gr_learn_resource);
58100+EXPORT_SYMBOL(gr_set_kernel_label);
58101+#ifdef CONFIG_SECURITY
58102+EXPORT_SYMBOL(gr_check_user_change);
58103+EXPORT_SYMBOL(gr_check_group_change);
58104+#endif
58105diff --git a/grsecurity/grsec_exec.c b/grsecurity/grsec_exec.c
58106new file mode 100644
58107index 0000000..abfa971
58108--- /dev/null
58109+++ b/grsecurity/grsec_exec.c
58110@@ -0,0 +1,174 @@
58111+#include <linux/kernel.h>
58112+#include <linux/sched.h>
58113+#include <linux/file.h>
58114+#include <linux/binfmts.h>
58115+#include <linux/fs.h>
58116+#include <linux/types.h>
58117+#include <linux/grdefs.h>
58118+#include <linux/grsecurity.h>
58119+#include <linux/grinternal.h>
58120+#include <linux/capability.h>
58121+#include <linux/module.h>
58122+
58123+#include <asm/uaccess.h>
58124+
58125+#ifdef CONFIG_GRKERNSEC_EXECLOG
58126+static char gr_exec_arg_buf[132];
58127+static DEFINE_MUTEX(gr_exec_arg_mutex);
58128+#endif
58129+
58130+extern const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr);
58131+
58132+void
58133+gr_handle_exec_args(struct linux_binprm *bprm, struct user_arg_ptr argv)
58134+{
58135+#ifdef CONFIG_GRKERNSEC_EXECLOG
58136+ char *grarg = gr_exec_arg_buf;
58137+ unsigned int i, x, execlen = 0;
58138+ char c;
58139+
58140+ if (!((grsec_enable_execlog && grsec_enable_group &&
58141+ in_group_p(grsec_audit_gid))
58142+ || (grsec_enable_execlog && !grsec_enable_group)))
58143+ return;
58144+
58145+ mutex_lock(&gr_exec_arg_mutex);
58146+ memset(grarg, 0, sizeof(gr_exec_arg_buf));
58147+
58148+ for (i = 0; i < bprm->argc && execlen < 128; i++) {
58149+ const char __user *p;
58150+ unsigned int len;
58151+
58152+ p = get_user_arg_ptr(argv, i);
58153+ if (IS_ERR(p))
58154+ goto log;
58155+
58156+ len = strnlen_user(p, 128 - execlen);
58157+ if (len > 128 - execlen)
58158+ len = 128 - execlen;
58159+ else if (len > 0)
58160+ len--;
58161+ if (copy_from_user(grarg + execlen, p, len))
58162+ goto log;
58163+
58164+ /* rewrite unprintable characters */
58165+ for (x = 0; x < len; x++) {
58166+ c = *(grarg + execlen + x);
58167+ if (c < 32 || c > 126)
58168+ *(grarg + execlen + x) = ' ';
58169+ }
58170+
58171+ execlen += len;
58172+ *(grarg + execlen) = ' ';
58173+ *(grarg + execlen + 1) = '\0';
58174+ execlen++;
58175+ }
58176+
58177+ log:
58178+ gr_log_fs_str(GR_DO_AUDIT, GR_EXEC_AUDIT_MSG, bprm->file->f_path.dentry,
58179+ bprm->file->f_path.mnt, grarg);
58180+ mutex_unlock(&gr_exec_arg_mutex);
58181+#endif
58182+ return;
58183+}
58184+
58185+#ifdef CONFIG_GRKERNSEC
58186+extern int gr_acl_is_capable(const int cap);
58187+extern int gr_acl_is_capable_nolog(const int cap);
58188+extern int gr_task_acl_is_capable(const struct task_struct *task, const struct cred *cred, const int cap);
58189+extern int gr_task_acl_is_capable_nolog(const struct task_struct *task, const int cap);
58190+extern int gr_chroot_is_capable(const int cap);
58191+extern int gr_chroot_is_capable_nolog(const int cap);
58192+extern int gr_task_chroot_is_capable(const struct task_struct *task, const struct cred *cred, const int cap);
58193+extern int gr_task_chroot_is_capable_nolog(const struct task_struct *task, const int cap);
58194+#endif
58195+
58196+const char *captab_log[] = {
58197+ "CAP_CHOWN",
58198+ "CAP_DAC_OVERRIDE",
58199+ "CAP_DAC_READ_SEARCH",
58200+ "CAP_FOWNER",
58201+ "CAP_FSETID",
58202+ "CAP_KILL",
58203+ "CAP_SETGID",
58204+ "CAP_SETUID",
58205+ "CAP_SETPCAP",
58206+ "CAP_LINUX_IMMUTABLE",
58207+ "CAP_NET_BIND_SERVICE",
58208+ "CAP_NET_BROADCAST",
58209+ "CAP_NET_ADMIN",
58210+ "CAP_NET_RAW",
58211+ "CAP_IPC_LOCK",
58212+ "CAP_IPC_OWNER",
58213+ "CAP_SYS_MODULE",
58214+ "CAP_SYS_RAWIO",
58215+ "CAP_SYS_CHROOT",
58216+ "CAP_SYS_PTRACE",
58217+ "CAP_SYS_PACCT",
58218+ "CAP_SYS_ADMIN",
58219+ "CAP_SYS_BOOT",
58220+ "CAP_SYS_NICE",
58221+ "CAP_SYS_RESOURCE",
58222+ "CAP_SYS_TIME",
58223+ "CAP_SYS_TTY_CONFIG",
58224+ "CAP_MKNOD",
58225+ "CAP_LEASE",
58226+ "CAP_AUDIT_WRITE",
58227+ "CAP_AUDIT_CONTROL",
58228+ "CAP_SETFCAP",
58229+ "CAP_MAC_OVERRIDE",
58230+ "CAP_MAC_ADMIN",
58231+ "CAP_SYSLOG",
58232+ "CAP_WAKE_ALARM"
58233+};
58234+
58235+int captab_log_entries = sizeof(captab_log)/sizeof(captab_log[0]);
58236+
58237+int gr_is_capable(const int cap)
58238+{
58239+#ifdef CONFIG_GRKERNSEC
58240+ if (gr_acl_is_capable(cap) && gr_chroot_is_capable(cap))
58241+ return 1;
58242+ return 0;
58243+#else
58244+ return 1;
58245+#endif
58246+}
58247+
58248+int gr_task_is_capable(const struct task_struct *task, const struct cred *cred, const int cap)
58249+{
58250+#ifdef CONFIG_GRKERNSEC
58251+ if (gr_task_acl_is_capable(task, cred, cap) && gr_task_chroot_is_capable(task, cred, cap))
58252+ return 1;
58253+ return 0;
58254+#else
58255+ return 1;
58256+#endif
58257+}
58258+
58259+int gr_is_capable_nolog(const int cap)
58260+{
58261+#ifdef CONFIG_GRKERNSEC
58262+ if (gr_acl_is_capable_nolog(cap) && gr_chroot_is_capable_nolog(cap))
58263+ return 1;
58264+ return 0;
58265+#else
58266+ return 1;
58267+#endif
58268+}
58269+
58270+int gr_task_is_capable_nolog(const struct task_struct *task, const int cap)
58271+{
58272+#ifdef CONFIG_GRKERNSEC
58273+ if (gr_task_acl_is_capable_nolog(task, cap) && gr_task_chroot_is_capable_nolog(task, cap))
58274+ return 1;
58275+ return 0;
58276+#else
58277+ return 1;
58278+#endif
58279+}
58280+
58281+EXPORT_SYMBOL(gr_is_capable);
58282+EXPORT_SYMBOL(gr_is_capable_nolog);
58283+EXPORT_SYMBOL(gr_task_is_capable);
58284+EXPORT_SYMBOL(gr_task_is_capable_nolog);
58285diff --git a/grsecurity/grsec_fifo.c b/grsecurity/grsec_fifo.c
58286new file mode 100644
58287index 0000000..d3ee748
58288--- /dev/null
58289+++ b/grsecurity/grsec_fifo.c
58290@@ -0,0 +1,24 @@
58291+#include <linux/kernel.h>
58292+#include <linux/sched.h>
58293+#include <linux/fs.h>
58294+#include <linux/file.h>
58295+#include <linux/grinternal.h>
58296+
58297+int
58298+gr_handle_fifo(const struct dentry *dentry, const struct vfsmount *mnt,
58299+ const struct dentry *dir, const int flag, const int acc_mode)
58300+{
58301+#ifdef CONFIG_GRKERNSEC_FIFO
58302+ const struct cred *cred = current_cred();
58303+
58304+ if (grsec_enable_fifo && S_ISFIFO(dentry->d_inode->i_mode) &&
58305+ !(flag & O_EXCL) && (dir->d_inode->i_mode & S_ISVTX) &&
58306+ (dentry->d_inode->i_uid != dir->d_inode->i_uid) &&
58307+ (cred->fsuid != dentry->d_inode->i_uid)) {
58308+ if (!inode_permission(dentry->d_inode, acc_mode))
58309+ gr_log_fs_int2(GR_DONT_AUDIT, GR_FIFO_MSG, dentry, mnt, dentry->d_inode->i_uid, dentry->d_inode->i_gid);
58310+ return -EACCES;
58311+ }
58312+#endif
58313+ return 0;
58314+}
58315diff --git a/grsecurity/grsec_fork.c b/grsecurity/grsec_fork.c
58316new file mode 100644
58317index 0000000..8ca18bf
58318--- /dev/null
58319+++ b/grsecurity/grsec_fork.c
58320@@ -0,0 +1,23 @@
58321+#include <linux/kernel.h>
58322+#include <linux/sched.h>
58323+#include <linux/grsecurity.h>
58324+#include <linux/grinternal.h>
58325+#include <linux/errno.h>
58326+
58327+void
58328+gr_log_forkfail(const int retval)
58329+{
58330+#ifdef CONFIG_GRKERNSEC_FORKFAIL
58331+ if (grsec_enable_forkfail && (retval == -EAGAIN || retval == -ENOMEM)) {
58332+ switch (retval) {
58333+ case -EAGAIN:
58334+ gr_log_str(GR_DONT_AUDIT, GR_FAILFORK_MSG, "EAGAIN");
58335+ break;
58336+ case -ENOMEM:
58337+ gr_log_str(GR_DONT_AUDIT, GR_FAILFORK_MSG, "ENOMEM");
58338+ break;
58339+ }
58340+ }
58341+#endif
58342+ return;
58343+}
58344diff --git a/grsecurity/grsec_init.c b/grsecurity/grsec_init.c
58345new file mode 100644
58346index 0000000..05a6015
58347--- /dev/null
58348+++ b/grsecurity/grsec_init.c
58349@@ -0,0 +1,283 @@
58350+#include <linux/kernel.h>
58351+#include <linux/sched.h>
58352+#include <linux/mm.h>
58353+#include <linux/gracl.h>
58354+#include <linux/slab.h>
58355+#include <linux/vmalloc.h>
58356+#include <linux/percpu.h>
58357+#include <linux/module.h>
58358+
58359+int grsec_enable_ptrace_readexec;
58360+int grsec_enable_setxid;
58361+int grsec_enable_symlinkown;
58362+int grsec_symlinkown_gid;
58363+int grsec_enable_brute;
58364+int grsec_enable_link;
58365+int grsec_enable_dmesg;
58366+int grsec_enable_harden_ptrace;
58367+int grsec_enable_fifo;
58368+int grsec_enable_execlog;
58369+int grsec_enable_signal;
58370+int grsec_enable_forkfail;
58371+int grsec_enable_audit_ptrace;
58372+int grsec_enable_time;
58373+int grsec_enable_audit_textrel;
58374+int grsec_enable_group;
58375+int grsec_audit_gid;
58376+int grsec_enable_chdir;
58377+int grsec_enable_mount;
58378+int grsec_enable_rofs;
58379+int grsec_enable_chroot_findtask;
58380+int grsec_enable_chroot_mount;
58381+int grsec_enable_chroot_shmat;
58382+int grsec_enable_chroot_fchdir;
58383+int grsec_enable_chroot_double;
58384+int grsec_enable_chroot_pivot;
58385+int grsec_enable_chroot_chdir;
58386+int grsec_enable_chroot_chmod;
58387+int grsec_enable_chroot_mknod;
58388+int grsec_enable_chroot_nice;
58389+int grsec_enable_chroot_execlog;
58390+int grsec_enable_chroot_caps;
58391+int grsec_enable_chroot_sysctl;
58392+int grsec_enable_chroot_unix;
58393+int grsec_enable_tpe;
58394+int grsec_tpe_gid;
58395+int grsec_enable_blackhole;
58396+#ifdef CONFIG_IPV6_MODULE
58397+EXPORT_SYMBOL(grsec_enable_blackhole);
58398+#endif
58399+int grsec_lastack_retries;
58400+int grsec_enable_tpe_all;
58401+int grsec_enable_tpe_invert;
58402+int grsec_enable_socket_all;
58403+int grsec_socket_all_gid;
58404+int grsec_enable_socket_client;
58405+int grsec_socket_client_gid;
58406+int grsec_enable_socket_server;
58407+int grsec_socket_server_gid;
58408+int grsec_resource_logging;
58409+int grsec_disable_privio;
58410+int grsec_enable_log_rwxmaps;
58411+int grsec_lock;
58412+
58413+DEFINE_SPINLOCK(grsec_alert_lock);
58414+unsigned long grsec_alert_wtime = 0;
58415+unsigned long grsec_alert_fyet = 0;
58416+
58417+DEFINE_SPINLOCK(grsec_audit_lock);
58418+
58419+DEFINE_RWLOCK(grsec_exec_file_lock);
58420+
58421+char *gr_shared_page[4];
58422+
58423+char *gr_alert_log_fmt;
58424+char *gr_audit_log_fmt;
58425+char *gr_alert_log_buf;
58426+char *gr_audit_log_buf;
58427+
58428+extern struct gr_arg *gr_usermode;
58429+extern unsigned char *gr_system_salt;
58430+extern unsigned char *gr_system_sum;
58431+
58432+void __init
58433+grsecurity_init(void)
58434+{
58435+ int j;
58436+ /* create the per-cpu shared pages */
58437+
58438+#ifdef CONFIG_X86
58439+ memset((char *)(0x41a + PAGE_OFFSET), 0, 36);
58440+#endif
58441+
58442+ for (j = 0; j < 4; j++) {
58443+ gr_shared_page[j] = (char *)__alloc_percpu(PAGE_SIZE, __alignof__(unsigned long long));
58444+ if (gr_shared_page[j] == NULL) {
58445+ panic("Unable to allocate grsecurity shared page");
58446+ return;
58447+ }
58448+ }
58449+
58450+ /* allocate log buffers */
58451+ gr_alert_log_fmt = kmalloc(512, GFP_KERNEL);
58452+ if (!gr_alert_log_fmt) {
58453+ panic("Unable to allocate grsecurity alert log format buffer");
58454+ return;
58455+ }
58456+ gr_audit_log_fmt = kmalloc(512, GFP_KERNEL);
58457+ if (!gr_audit_log_fmt) {
58458+ panic("Unable to allocate grsecurity audit log format buffer");
58459+ return;
58460+ }
58461+ gr_alert_log_buf = (char *) get_zeroed_page(GFP_KERNEL);
58462+ if (!gr_alert_log_buf) {
58463+ panic("Unable to allocate grsecurity alert log buffer");
58464+ return;
58465+ }
58466+ gr_audit_log_buf = (char *) get_zeroed_page(GFP_KERNEL);
58467+ if (!gr_audit_log_buf) {
58468+ panic("Unable to allocate grsecurity audit log buffer");
58469+ return;
58470+ }
58471+
58472+ /* allocate memory for authentication structure */
58473+ gr_usermode = kmalloc(sizeof(struct gr_arg), GFP_KERNEL);
58474+ gr_system_salt = kmalloc(GR_SALT_LEN, GFP_KERNEL);
58475+ gr_system_sum = kmalloc(GR_SHA_LEN, GFP_KERNEL);
58476+
58477+ if (!gr_usermode || !gr_system_salt || !gr_system_sum) {
58478+ panic("Unable to allocate grsecurity authentication structure");
58479+ return;
58480+ }
58481+
58482+
58483+#ifdef CONFIG_GRKERNSEC_IO
58484+#if !defined(CONFIG_GRKERNSEC_SYSCTL_DISTRO)
58485+ grsec_disable_privio = 1;
58486+#elif defined(CONFIG_GRKERNSEC_SYSCTL_ON)
58487+ grsec_disable_privio = 1;
58488+#else
58489+ grsec_disable_privio = 0;
58490+#endif
58491+#endif
58492+
58493+#ifdef CONFIG_GRKERNSEC_TPE_INVERT
58494+ /* for backward compatibility, tpe_invert always defaults to on if
58495+ enabled in the kernel
58496+ */
58497+ grsec_enable_tpe_invert = 1;
58498+#endif
58499+
58500+#if !defined(CONFIG_GRKERNSEC_SYSCTL) || defined(CONFIG_GRKERNSEC_SYSCTL_ON)
58501+#ifndef CONFIG_GRKERNSEC_SYSCTL
58502+ grsec_lock = 1;
58503+#endif
58504+
58505+#ifdef CONFIG_GRKERNSEC_AUDIT_TEXTREL
58506+ grsec_enable_audit_textrel = 1;
58507+#endif
58508+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
58509+ grsec_enable_log_rwxmaps = 1;
58510+#endif
58511+#ifdef CONFIG_GRKERNSEC_AUDIT_GROUP
58512+ grsec_enable_group = 1;
58513+ grsec_audit_gid = CONFIG_GRKERNSEC_AUDIT_GID;
58514+#endif
58515+#ifdef CONFIG_GRKERNSEC_PTRACE_READEXEC
58516+ grsec_enable_ptrace_readexec = 1;
58517+#endif
58518+#ifdef CONFIG_GRKERNSEC_AUDIT_CHDIR
58519+ grsec_enable_chdir = 1;
58520+#endif
58521+#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
58522+ grsec_enable_harden_ptrace = 1;
58523+#endif
58524+#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
58525+ grsec_enable_mount = 1;
58526+#endif
58527+#ifdef CONFIG_GRKERNSEC_LINK
58528+ grsec_enable_link = 1;
58529+#endif
58530+#ifdef CONFIG_GRKERNSEC_BRUTE
58531+ grsec_enable_brute = 1;
58532+#endif
58533+#ifdef CONFIG_GRKERNSEC_DMESG
58534+ grsec_enable_dmesg = 1;
58535+#endif
58536+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
58537+ grsec_enable_blackhole = 1;
58538+ grsec_lastack_retries = 4;
58539+#endif
58540+#ifdef CONFIG_GRKERNSEC_FIFO
58541+ grsec_enable_fifo = 1;
58542+#endif
58543+#ifdef CONFIG_GRKERNSEC_EXECLOG
58544+ grsec_enable_execlog = 1;
58545+#endif
58546+#ifdef CONFIG_GRKERNSEC_SETXID
58547+ grsec_enable_setxid = 1;
58548+#endif
58549+#ifdef CONFIG_GRKERNSEC_SIGNAL
58550+ grsec_enable_signal = 1;
58551+#endif
58552+#ifdef CONFIG_GRKERNSEC_FORKFAIL
58553+ grsec_enable_forkfail = 1;
58554+#endif
58555+#ifdef CONFIG_GRKERNSEC_TIME
58556+ grsec_enable_time = 1;
58557+#endif
58558+#ifdef CONFIG_GRKERNSEC_RESLOG
58559+ grsec_resource_logging = 1;
58560+#endif
58561+#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
58562+ grsec_enable_chroot_findtask = 1;
58563+#endif
58564+#ifdef CONFIG_GRKERNSEC_CHROOT_UNIX
58565+ grsec_enable_chroot_unix = 1;
58566+#endif
58567+#ifdef CONFIG_GRKERNSEC_CHROOT_MOUNT
58568+ grsec_enable_chroot_mount = 1;
58569+#endif
58570+#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
58571+ grsec_enable_chroot_fchdir = 1;
58572+#endif
58573+#ifdef CONFIG_GRKERNSEC_CHROOT_SHMAT
58574+ grsec_enable_chroot_shmat = 1;
58575+#endif
58576+#ifdef CONFIG_GRKERNSEC_AUDIT_PTRACE
58577+ grsec_enable_audit_ptrace = 1;
58578+#endif
58579+#ifdef CONFIG_GRKERNSEC_CHROOT_DOUBLE
58580+ grsec_enable_chroot_double = 1;
58581+#endif
58582+#ifdef CONFIG_GRKERNSEC_CHROOT_PIVOT
58583+ grsec_enable_chroot_pivot = 1;
58584+#endif
58585+#ifdef CONFIG_GRKERNSEC_CHROOT_CHDIR
58586+ grsec_enable_chroot_chdir = 1;
58587+#endif
58588+#ifdef CONFIG_GRKERNSEC_CHROOT_CHMOD
58589+ grsec_enable_chroot_chmod = 1;
58590+#endif
58591+#ifdef CONFIG_GRKERNSEC_CHROOT_MKNOD
58592+ grsec_enable_chroot_mknod = 1;
58593+#endif
58594+#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
58595+ grsec_enable_chroot_nice = 1;
58596+#endif
58597+#ifdef CONFIG_GRKERNSEC_CHROOT_EXECLOG
58598+ grsec_enable_chroot_execlog = 1;
58599+#endif
58600+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
58601+ grsec_enable_chroot_caps = 1;
58602+#endif
58603+#ifdef CONFIG_GRKERNSEC_CHROOT_SYSCTL
58604+ grsec_enable_chroot_sysctl = 1;
58605+#endif
58606+#ifdef CONFIG_GRKERNSEC_SYMLINKOWN
58607+ grsec_enable_symlinkown = 1;
58608+ grsec_symlinkown_gid = CONFIG_GRKERNSEC_SYMLINKOWN_GID;
58609+#endif
58610+#ifdef CONFIG_GRKERNSEC_TPE
58611+ grsec_enable_tpe = 1;
58612+ grsec_tpe_gid = CONFIG_GRKERNSEC_TPE_GID;
58613+#ifdef CONFIG_GRKERNSEC_TPE_ALL
58614+ grsec_enable_tpe_all = 1;
58615+#endif
58616+#endif
58617+#ifdef CONFIG_GRKERNSEC_SOCKET_ALL
58618+ grsec_enable_socket_all = 1;
58619+ grsec_socket_all_gid = CONFIG_GRKERNSEC_SOCKET_ALL_GID;
58620+#endif
58621+#ifdef CONFIG_GRKERNSEC_SOCKET_CLIENT
58622+ grsec_enable_socket_client = 1;
58623+ grsec_socket_client_gid = CONFIG_GRKERNSEC_SOCKET_CLIENT_GID;
58624+#endif
58625+#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
58626+ grsec_enable_socket_server = 1;
58627+ grsec_socket_server_gid = CONFIG_GRKERNSEC_SOCKET_SERVER_GID;
58628+#endif
58629+#endif
58630+
58631+ return;
58632+}
58633diff --git a/grsecurity/grsec_link.c b/grsecurity/grsec_link.c
58634new file mode 100644
58635index 0000000..589481f
58636--- /dev/null
58637+++ b/grsecurity/grsec_link.c
58638@@ -0,0 +1,58 @@
58639+#include <linux/kernel.h>
58640+#include <linux/sched.h>
58641+#include <linux/fs.h>
58642+#include <linux/file.h>
58643+#include <linux/grinternal.h>
58644+
58645+int gr_handle_symlink_owner(const struct path *link, const struct inode *target)
58646+{
58647+#ifdef CONFIG_GRKERNSEC_SYMLINKOWN
58648+ const struct inode *link_inode = link->dentry->d_inode;
58649+
58650+ if (grsec_enable_symlinkown && in_group_p(grsec_symlinkown_gid) &&
58651+ /* ignore root-owned links, e.g. /proc/self */
58652+ !uid_eq(link_inode->i_uid, GLOBAL_ROOT_UID) && target &&
58653+ !uid_eq(link_inode->i_uid, target->i_uid)) {
58654+ gr_log_fs_int2(GR_DONT_AUDIT, GR_SYMLINKOWNER_MSG, link->dentry, link->mnt, link_inode->i_uid, target->i_uid);
58655+ return 1;
58656+ }
58657+#endif
58658+ return 0;
58659+}
58660+
58661+int
58662+gr_handle_follow_link(const struct inode *parent,
58663+ const struct inode *inode,
58664+ const struct dentry *dentry, const struct vfsmount *mnt)
58665+{
58666+#ifdef CONFIG_GRKERNSEC_LINK
58667+ const struct cred *cred = current_cred();
58668+
58669+ if (grsec_enable_link && S_ISLNK(inode->i_mode) &&
58670+ (parent->i_mode & S_ISVTX) && !uid_eq(parent->i_uid, inode->i_uid) &&
58671+ (parent->i_mode & S_IWOTH) && !uid_eq(cred->fsuid, inode->i_uid)) {
58672+ gr_log_fs_int2(GR_DONT_AUDIT, GR_SYMLINK_MSG, dentry, mnt, inode->i_uid, inode->i_gid);
58673+ return -EACCES;
58674+ }
58675+#endif
58676+ return 0;
58677+}
58678+
58679+int
58680+gr_handle_hardlink(const struct dentry *dentry,
58681+ const struct vfsmount *mnt,
58682+ struct inode *inode, const int mode, const char *to)
58683+{
58684+#ifdef CONFIG_GRKERNSEC_LINK
58685+ const struct cred *cred = current_cred();
58686+
58687+ if (grsec_enable_link && !uid_eq(cred->fsuid, inode->i_uid) &&
58688+ (!S_ISREG(mode) || is_privileged_binary(dentry) ||
58689+ (inode_permission(inode, MAY_READ | MAY_WRITE))) &&
58690+ !capable(CAP_FOWNER) && !uid_eq(cred->uid, GLOBAL_ROOT_UID)) {
58691+ gr_log_fs_int2_str(GR_DONT_AUDIT, GR_HARDLINK_MSG, dentry, mnt, inode->i_uid, inode->i_gid, to);
58692+ return -EPERM;
58693+ }
58694+#endif
58695+ return 0;
58696+}
58697diff --git a/grsecurity/grsec_log.c b/grsecurity/grsec_log.c
58698new file mode 100644
58699index 0000000..a45d2e9
58700--- /dev/null
58701+++ b/grsecurity/grsec_log.c
58702@@ -0,0 +1,322 @@
58703+#include <linux/kernel.h>
58704+#include <linux/sched.h>
58705+#include <linux/file.h>
58706+#include <linux/tty.h>
58707+#include <linux/fs.h>
58708+#include <linux/grinternal.h>
58709+
58710+#ifdef CONFIG_TREE_PREEMPT_RCU
58711+#define DISABLE_PREEMPT() preempt_disable()
58712+#define ENABLE_PREEMPT() preempt_enable()
58713+#else
58714+#define DISABLE_PREEMPT()
58715+#define ENABLE_PREEMPT()
58716+#endif
58717+
58718+#define BEGIN_LOCKS(x) \
58719+ DISABLE_PREEMPT(); \
58720+ rcu_read_lock(); \
58721+ read_lock(&tasklist_lock); \
58722+ read_lock(&grsec_exec_file_lock); \
58723+ if (x != GR_DO_AUDIT) \
58724+ spin_lock(&grsec_alert_lock); \
58725+ else \
58726+ spin_lock(&grsec_audit_lock)
58727+
58728+#define END_LOCKS(x) \
58729+ if (x != GR_DO_AUDIT) \
58730+ spin_unlock(&grsec_alert_lock); \
58731+ else \
58732+ spin_unlock(&grsec_audit_lock); \
58733+ read_unlock(&grsec_exec_file_lock); \
58734+ read_unlock(&tasklist_lock); \
58735+ rcu_read_unlock(); \
58736+ ENABLE_PREEMPT(); \
58737+ if (x == GR_DONT_AUDIT) \
58738+ gr_handle_alertkill(current)
58739+
58740+enum {
58741+ FLOODING,
58742+ NO_FLOODING
58743+};
58744+
58745+extern char *gr_alert_log_fmt;
58746+extern char *gr_audit_log_fmt;
58747+extern char *gr_alert_log_buf;
58748+extern char *gr_audit_log_buf;
58749+
58750+static int gr_log_start(int audit)
58751+{
58752+ char *loglevel = (audit == GR_DO_AUDIT) ? KERN_INFO : KERN_ALERT;
58753+ char *fmt = (audit == GR_DO_AUDIT) ? gr_audit_log_fmt : gr_alert_log_fmt;
58754+ char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
58755+#if (CONFIG_GRKERNSEC_FLOODTIME > 0 && CONFIG_GRKERNSEC_FLOODBURST > 0)
58756+ unsigned long curr_secs = get_seconds();
58757+
58758+ if (audit == GR_DO_AUDIT)
58759+ goto set_fmt;
58760+
58761+ if (!grsec_alert_wtime || time_after(curr_secs, grsec_alert_wtime + CONFIG_GRKERNSEC_FLOODTIME)) {
58762+ grsec_alert_wtime = curr_secs;
58763+ grsec_alert_fyet = 0;
58764+ } else if (time_before_eq(curr_secs, grsec_alert_wtime + CONFIG_GRKERNSEC_FLOODTIME)
58765+ && (grsec_alert_fyet < CONFIG_GRKERNSEC_FLOODBURST)) {
58766+ grsec_alert_fyet++;
58767+ } else if (grsec_alert_fyet == CONFIG_GRKERNSEC_FLOODBURST) {
58768+ grsec_alert_wtime = curr_secs;
58769+ grsec_alert_fyet++;
58770+ printk(KERN_ALERT "grsec: more alerts, logging disabled for %d seconds\n", CONFIG_GRKERNSEC_FLOODTIME);
58771+ return FLOODING;
58772+ }
58773+ else return FLOODING;
58774+
58775+set_fmt:
58776+#endif
58777+ memset(buf, 0, PAGE_SIZE);
58778+ if (current->signal->curr_ip && gr_acl_is_enabled()) {
58779+ sprintf(fmt, "%s%s", loglevel, "grsec: From %pI4: (%.64s:%c:%.950s) ");
58780+ snprintf(buf, PAGE_SIZE - 1, fmt, &current->signal->curr_ip, current->role->rolename, gr_roletype_to_char(), current->acl->filename);
58781+ } else if (current->signal->curr_ip) {
58782+ sprintf(fmt, "%s%s", loglevel, "grsec: From %pI4: ");
58783+ snprintf(buf, PAGE_SIZE - 1, fmt, &current->signal->curr_ip);
58784+ } else if (gr_acl_is_enabled()) {
58785+ sprintf(fmt, "%s%s", loglevel, "grsec: (%.64s:%c:%.950s) ");
58786+ snprintf(buf, PAGE_SIZE - 1, fmt, current->role->rolename, gr_roletype_to_char(), current->acl->filename);
58787+ } else {
58788+ sprintf(fmt, "%s%s", loglevel, "grsec: ");
58789+ strcpy(buf, fmt);
58790+ }
58791+
58792+ return NO_FLOODING;
58793+}
58794+
58795+static void gr_log_middle(int audit, const char *msg, va_list ap)
58796+ __attribute__ ((format (printf, 2, 0)));
58797+
58798+static void gr_log_middle(int audit, const char *msg, va_list ap)
58799+{
58800+ char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
58801+ unsigned int len = strlen(buf);
58802+
58803+ vsnprintf(buf + len, PAGE_SIZE - len - 1, msg, ap);
58804+
58805+ return;
58806+}
58807+
58808+static void gr_log_middle_varargs(int audit, const char *msg, ...)
58809+ __attribute__ ((format (printf, 2, 3)));
58810+
58811+static void gr_log_middle_varargs(int audit, const char *msg, ...)
58812+{
58813+ char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
58814+ unsigned int len = strlen(buf);
58815+ va_list ap;
58816+
58817+ va_start(ap, msg);
58818+ vsnprintf(buf + len, PAGE_SIZE - len - 1, msg, ap);
58819+ va_end(ap);
58820+
58821+ return;
58822+}
58823+
58824+static void gr_log_end(int audit, int append_default)
58825+{
58826+ char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
58827+
58828+ if (append_default) {
58829+ unsigned int len = strlen(buf);
58830+ snprintf(buf + len, PAGE_SIZE - len - 1, DEFAULTSECMSG, DEFAULTSECARGS(current, current_cred(), __task_cred(current->real_parent)));
58831+ }
58832+
58833+ printk("%s\n", buf);
58834+
58835+ return;
58836+}
58837+
58838+void gr_log_varargs(int audit, const char *msg, int argtypes, ...)
58839+{
58840+ int logtype;
58841+ char *result = (audit == GR_DO_AUDIT) ? "successful" : "denied";
58842+ char *str1 = NULL, *str2 = NULL, *str3 = NULL;
58843+ void *voidptr = NULL;
58844+ int num1 = 0, num2 = 0;
58845+ unsigned long ulong1 = 0, ulong2 = 0;
58846+ struct dentry *dentry = NULL;
58847+ struct vfsmount *mnt = NULL;
58848+ struct file *file = NULL;
58849+ struct task_struct *task = NULL;
58850+ const struct cred *cred, *pcred;
58851+ va_list ap;
58852+
58853+ BEGIN_LOCKS(audit);
58854+ logtype = gr_log_start(audit);
58855+ if (logtype == FLOODING) {
58856+ END_LOCKS(audit);
58857+ return;
58858+ }
58859+ va_start(ap, argtypes);
58860+ switch (argtypes) {
58861+ case GR_TTYSNIFF:
58862+ task = va_arg(ap, struct task_struct *);
58863+ 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);
58864+ break;
58865+ case GR_SYSCTL_HIDDEN:
58866+ str1 = va_arg(ap, char *);
58867+ gr_log_middle_varargs(audit, msg, result, str1);
58868+ break;
58869+ case GR_RBAC:
58870+ dentry = va_arg(ap, struct dentry *);
58871+ mnt = va_arg(ap, struct vfsmount *);
58872+ gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt));
58873+ break;
58874+ case GR_RBAC_STR:
58875+ dentry = va_arg(ap, struct dentry *);
58876+ mnt = va_arg(ap, struct vfsmount *);
58877+ str1 = va_arg(ap, char *);
58878+ gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt), str1);
58879+ break;
58880+ case GR_STR_RBAC:
58881+ str1 = va_arg(ap, char *);
58882+ dentry = va_arg(ap, struct dentry *);
58883+ mnt = va_arg(ap, struct vfsmount *);
58884+ gr_log_middle_varargs(audit, msg, result, str1, gr_to_filename(dentry, mnt));
58885+ break;
58886+ case GR_RBAC_MODE2:
58887+ dentry = va_arg(ap, struct dentry *);
58888+ mnt = va_arg(ap, struct vfsmount *);
58889+ str1 = va_arg(ap, char *);
58890+ str2 = va_arg(ap, char *);
58891+ gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt), str1, str2);
58892+ break;
58893+ case GR_RBAC_MODE3:
58894+ dentry = va_arg(ap, struct dentry *);
58895+ mnt = va_arg(ap, struct vfsmount *);
58896+ str1 = va_arg(ap, char *);
58897+ str2 = va_arg(ap, char *);
58898+ str3 = va_arg(ap, char *);
58899+ gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt), str1, str2, str3);
58900+ break;
58901+ case GR_FILENAME:
58902+ dentry = va_arg(ap, struct dentry *);
58903+ mnt = va_arg(ap, struct vfsmount *);
58904+ gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt));
58905+ break;
58906+ case GR_STR_FILENAME:
58907+ str1 = va_arg(ap, char *);
58908+ dentry = va_arg(ap, struct dentry *);
58909+ mnt = va_arg(ap, struct vfsmount *);
58910+ gr_log_middle_varargs(audit, msg, str1, gr_to_filename(dentry, mnt));
58911+ break;
58912+ case GR_FILENAME_STR:
58913+ dentry = va_arg(ap, struct dentry *);
58914+ mnt = va_arg(ap, struct vfsmount *);
58915+ str1 = va_arg(ap, char *);
58916+ gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt), str1);
58917+ break;
58918+ case GR_FILENAME_TWO_INT:
58919+ dentry = va_arg(ap, struct dentry *);
58920+ mnt = va_arg(ap, struct vfsmount *);
58921+ num1 = va_arg(ap, int);
58922+ num2 = va_arg(ap, int);
58923+ gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt), num1, num2);
58924+ break;
58925+ case GR_FILENAME_TWO_INT_STR:
58926+ dentry = va_arg(ap, struct dentry *);
58927+ mnt = va_arg(ap, struct vfsmount *);
58928+ num1 = va_arg(ap, int);
58929+ num2 = va_arg(ap, int);
58930+ str1 = va_arg(ap, char *);
58931+ gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt), num1, num2, str1);
58932+ break;
58933+ case GR_TEXTREL:
58934+ file = va_arg(ap, struct file *);
58935+ ulong1 = va_arg(ap, unsigned long);
58936+ ulong2 = va_arg(ap, unsigned long);
58937+ gr_log_middle_varargs(audit, msg, file ? gr_to_filename(file->f_path.dentry, file->f_path.mnt) : "<anonymous mapping>", ulong1, ulong2);
58938+ break;
58939+ case GR_PTRACE:
58940+ task = va_arg(ap, struct task_struct *);
58941+ 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);
58942+ break;
58943+ case GR_RESOURCE:
58944+ task = va_arg(ap, struct task_struct *);
58945+ cred = __task_cred(task);
58946+ pcred = __task_cred(task->real_parent);
58947+ ulong1 = va_arg(ap, unsigned long);
58948+ str1 = va_arg(ap, char *);
58949+ ulong2 = va_arg(ap, unsigned long);
58950+ 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);
58951+ break;
58952+ case GR_CAP:
58953+ task = va_arg(ap, struct task_struct *);
58954+ cred = __task_cred(task);
58955+ pcred = __task_cred(task->real_parent);
58956+ str1 = va_arg(ap, char *);
58957+ 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);
58958+ break;
58959+ case GR_SIG:
58960+ str1 = va_arg(ap, char *);
58961+ voidptr = va_arg(ap, void *);
58962+ gr_log_middle_varargs(audit, msg, str1, voidptr);
58963+ break;
58964+ case GR_SIG2:
58965+ task = va_arg(ap, struct task_struct *);
58966+ cred = __task_cred(task);
58967+ pcred = __task_cred(task->real_parent);
58968+ num1 = va_arg(ap, int);
58969+ 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);
58970+ break;
58971+ case GR_CRASH1:
58972+ task = va_arg(ap, struct task_struct *);
58973+ cred = __task_cred(task);
58974+ pcred = __task_cred(task->real_parent);
58975+ ulong1 = va_arg(ap, unsigned long);
58976+ 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);
58977+ break;
58978+ case GR_CRASH2:
58979+ task = va_arg(ap, struct task_struct *);
58980+ cred = __task_cred(task);
58981+ pcred = __task_cred(task->real_parent);
58982+ ulong1 = va_arg(ap, unsigned long);
58983+ 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);
58984+ break;
58985+ case GR_RWXMAP:
58986+ file = va_arg(ap, struct file *);
58987+ gr_log_middle_varargs(audit, msg, file ? gr_to_filename(file->f_path.dentry, file->f_path.mnt) : "<anonymous mapping>");
58988+ break;
58989+ case GR_PSACCT:
58990+ {
58991+ unsigned int wday, cday;
58992+ __u8 whr, chr;
58993+ __u8 wmin, cmin;
58994+ __u8 wsec, csec;
58995+ char cur_tty[64] = { 0 };
58996+ char parent_tty[64] = { 0 };
58997+
58998+ task = va_arg(ap, struct task_struct *);
58999+ wday = va_arg(ap, unsigned int);
59000+ cday = va_arg(ap, unsigned int);
59001+ whr = va_arg(ap, int);
59002+ chr = va_arg(ap, int);
59003+ wmin = va_arg(ap, int);
59004+ cmin = va_arg(ap, int);
59005+ wsec = va_arg(ap, int);
59006+ csec = va_arg(ap, int);
59007+ ulong1 = va_arg(ap, unsigned long);
59008+ cred = __task_cred(task);
59009+ pcred = __task_cred(task->real_parent);
59010+
59011+ 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);
59012+ }
59013+ break;
59014+ default:
59015+ gr_log_middle(audit, msg, ap);
59016+ }
59017+ va_end(ap);
59018+ // these don't need DEFAULTSECARGS printed on the end
59019+ if (argtypes == GR_CRASH1 || argtypes == GR_CRASH2)
59020+ gr_log_end(audit, 0);
59021+ else
59022+ gr_log_end(audit, 1);
59023+ END_LOCKS(audit);
59024+}
59025diff --git a/grsecurity/grsec_mem.c b/grsecurity/grsec_mem.c
59026new file mode 100644
59027index 0000000..f536303
59028--- /dev/null
59029+++ b/grsecurity/grsec_mem.c
59030@@ -0,0 +1,40 @@
59031+#include <linux/kernel.h>
59032+#include <linux/sched.h>
59033+#include <linux/mm.h>
59034+#include <linux/mman.h>
59035+#include <linux/grinternal.h>
59036+
59037+void
59038+gr_handle_ioperm(void)
59039+{
59040+ gr_log_noargs(GR_DONT_AUDIT, GR_IOPERM_MSG);
59041+ return;
59042+}
59043+
59044+void
59045+gr_handle_iopl(void)
59046+{
59047+ gr_log_noargs(GR_DONT_AUDIT, GR_IOPL_MSG);
59048+ return;
59049+}
59050+
59051+void
59052+gr_handle_mem_readwrite(u64 from, u64 to)
59053+{
59054+ gr_log_two_u64(GR_DONT_AUDIT, GR_MEM_READWRITE_MSG, from, to);
59055+ return;
59056+}
59057+
59058+void
59059+gr_handle_vm86(void)
59060+{
59061+ gr_log_noargs(GR_DONT_AUDIT, GR_VM86_MSG);
59062+ return;
59063+}
59064+
59065+void
59066+gr_log_badprocpid(const char *entry)
59067+{
59068+ gr_log_str(GR_DONT_AUDIT, GR_BADPROCPID_MSG, entry);
59069+ return;
59070+}
59071diff --git a/grsecurity/grsec_mount.c b/grsecurity/grsec_mount.c
59072new file mode 100644
59073index 0000000..2131422
59074--- /dev/null
59075+++ b/grsecurity/grsec_mount.c
59076@@ -0,0 +1,62 @@
59077+#include <linux/kernel.h>
59078+#include <linux/sched.h>
59079+#include <linux/mount.h>
59080+#include <linux/grsecurity.h>
59081+#include <linux/grinternal.h>
59082+
59083+void
59084+gr_log_remount(const char *devname, const int retval)
59085+{
59086+#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
59087+ if (grsec_enable_mount && (retval >= 0))
59088+ gr_log_str(GR_DO_AUDIT, GR_REMOUNT_AUDIT_MSG, devname ? devname : "none");
59089+#endif
59090+ return;
59091+}
59092+
59093+void
59094+gr_log_unmount(const char *devname, const int retval)
59095+{
59096+#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
59097+ if (grsec_enable_mount && (retval >= 0))
59098+ gr_log_str(GR_DO_AUDIT, GR_UNMOUNT_AUDIT_MSG, devname ? devname : "none");
59099+#endif
59100+ return;
59101+}
59102+
59103+void
59104+gr_log_mount(const char *from, const char *to, const int retval)
59105+{
59106+#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
59107+ if (grsec_enable_mount && (retval >= 0))
59108+ gr_log_str_str(GR_DO_AUDIT, GR_MOUNT_AUDIT_MSG, from ? from : "none", to);
59109+#endif
59110+ return;
59111+}
59112+
59113+int
59114+gr_handle_rofs_mount(struct dentry *dentry, struct vfsmount *mnt, int mnt_flags)
59115+{
59116+#ifdef CONFIG_GRKERNSEC_ROFS
59117+ if (grsec_enable_rofs && !(mnt_flags & MNT_READONLY)) {
59118+ gr_log_fs_generic(GR_DO_AUDIT, GR_ROFS_MOUNT_MSG, dentry, mnt);
59119+ return -EPERM;
59120+ } else
59121+ return 0;
59122+#endif
59123+ return 0;
59124+}
59125+
59126+int
59127+gr_handle_rofs_blockwrite(struct dentry *dentry, struct vfsmount *mnt, int acc_mode)
59128+{
59129+#ifdef CONFIG_GRKERNSEC_ROFS
59130+ if (grsec_enable_rofs && (acc_mode & MAY_WRITE) &&
59131+ dentry->d_inode && S_ISBLK(dentry->d_inode->i_mode)) {
59132+ gr_log_fs_generic(GR_DO_AUDIT, GR_ROFS_BLOCKWRITE_MSG, dentry, mnt);
59133+ return -EPERM;
59134+ } else
59135+ return 0;
59136+#endif
59137+ return 0;
59138+}
59139diff --git a/grsecurity/grsec_pax.c b/grsecurity/grsec_pax.c
59140new file mode 100644
59141index 0000000..a3b12a0
59142--- /dev/null
59143+++ b/grsecurity/grsec_pax.c
59144@@ -0,0 +1,36 @@
59145+#include <linux/kernel.h>
59146+#include <linux/sched.h>
59147+#include <linux/mm.h>
59148+#include <linux/file.h>
59149+#include <linux/grinternal.h>
59150+#include <linux/grsecurity.h>
59151+
59152+void
59153+gr_log_textrel(struct vm_area_struct * vma)
59154+{
59155+#ifdef CONFIG_GRKERNSEC_AUDIT_TEXTREL
59156+ if (grsec_enable_audit_textrel)
59157+ gr_log_textrel_ulong_ulong(GR_DO_AUDIT, GR_TEXTREL_AUDIT_MSG, vma->vm_file, vma->vm_start, vma->vm_pgoff);
59158+#endif
59159+ return;
59160+}
59161+
59162+void
59163+gr_log_rwxmmap(struct file *file)
59164+{
59165+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
59166+ if (grsec_enable_log_rwxmaps)
59167+ gr_log_rwxmap(GR_DONT_AUDIT, GR_RWXMMAP_MSG, file);
59168+#endif
59169+ return;
59170+}
59171+
59172+void
59173+gr_log_rwxmprotect(struct file *file)
59174+{
59175+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
59176+ if (grsec_enable_log_rwxmaps)
59177+ gr_log_rwxmap(GR_DONT_AUDIT, GR_RWXMPROTECT_MSG, file);
59178+#endif
59179+ return;
59180+}
59181diff --git a/grsecurity/grsec_ptrace.c b/grsecurity/grsec_ptrace.c
59182new file mode 100644
59183index 0000000..f7f29aa
59184--- /dev/null
59185+++ b/grsecurity/grsec_ptrace.c
59186@@ -0,0 +1,30 @@
59187+#include <linux/kernel.h>
59188+#include <linux/sched.h>
59189+#include <linux/grinternal.h>
59190+#include <linux/security.h>
59191+
59192+void
59193+gr_audit_ptrace(struct task_struct *task)
59194+{
59195+#ifdef CONFIG_GRKERNSEC_AUDIT_PTRACE
59196+ if (grsec_enable_audit_ptrace)
59197+ gr_log_ptrace(GR_DO_AUDIT, GR_PTRACE_AUDIT_MSG, task);
59198+#endif
59199+ return;
59200+}
59201+
59202+int
59203+gr_ptrace_readexec(struct file *file, int unsafe_flags)
59204+{
59205+#ifdef CONFIG_GRKERNSEC_PTRACE_READEXEC
59206+ const struct dentry *dentry = file->f_path.dentry;
59207+ const struct vfsmount *mnt = file->f_path.mnt;
59208+
59209+ if (grsec_enable_ptrace_readexec && (unsafe_flags & LSM_UNSAFE_PTRACE) &&
59210+ (inode_permission(dentry->d_inode, MAY_READ) || !gr_acl_handle_open(dentry, mnt, MAY_READ))) {
59211+ gr_log_fs_generic(GR_DONT_AUDIT, GR_PTRACE_READEXEC_MSG, dentry, mnt);
59212+ return -EACCES;
59213+ }
59214+#endif
59215+ return 0;
59216+}
59217diff --git a/grsecurity/grsec_sig.c b/grsecurity/grsec_sig.c
59218new file mode 100644
59219index 0000000..b4ac94c
59220--- /dev/null
59221+++ b/grsecurity/grsec_sig.c
59222@@ -0,0 +1,209 @@
59223+#include <linux/kernel.h>
59224+#include <linux/sched.h>
59225+#include <linux/delay.h>
59226+#include <linux/grsecurity.h>
59227+#include <linux/grinternal.h>
59228+#include <linux/hardirq.h>
59229+
59230+char *signames[] = {
59231+ [SIGSEGV] = "Segmentation fault",
59232+ [SIGILL] = "Illegal instruction",
59233+ [SIGABRT] = "Abort",
59234+ [SIGBUS] = "Invalid alignment/Bus error"
59235+};
59236+
59237+void
59238+gr_log_signal(const int sig, const void *addr, const struct task_struct *t)
59239+{
59240+#ifdef CONFIG_GRKERNSEC_SIGNAL
59241+ if (grsec_enable_signal && ((sig == SIGSEGV) || (sig == SIGILL) ||
59242+ (sig == SIGABRT) || (sig == SIGBUS))) {
59243+ if (t->pid == current->pid) {
59244+ gr_log_sig_addr(GR_DONT_AUDIT_GOOD, GR_UNISIGLOG_MSG, signames[sig], addr);
59245+ } else {
59246+ gr_log_sig_task(GR_DONT_AUDIT_GOOD, GR_DUALSIGLOG_MSG, t, sig);
59247+ }
59248+ }
59249+#endif
59250+ return;
59251+}
59252+
59253+int
59254+gr_handle_signal(const struct task_struct *p, const int sig)
59255+{
59256+#ifdef CONFIG_GRKERNSEC
59257+ /* ignore the 0 signal for protected task checks */
59258+ if (current->pid > 1 && sig && gr_check_protected_task(p)) {
59259+ gr_log_sig_task(GR_DONT_AUDIT, GR_SIG_ACL_MSG, p, sig);
59260+ return -EPERM;
59261+ } else if (gr_pid_is_chrooted((struct task_struct *)p)) {
59262+ return -EPERM;
59263+ }
59264+#endif
59265+ return 0;
59266+}
59267+
59268+#ifdef CONFIG_GRKERNSEC
59269+extern int specific_send_sig_info(int sig, struct siginfo *info, struct task_struct *t);
59270+
59271+int gr_fake_force_sig(int sig, struct task_struct *t)
59272+{
59273+ unsigned long int flags;
59274+ int ret, blocked, ignored;
59275+ struct k_sigaction *action;
59276+
59277+ spin_lock_irqsave(&t->sighand->siglock, flags);
59278+ action = &t->sighand->action[sig-1];
59279+ ignored = action->sa.sa_handler == SIG_IGN;
59280+ blocked = sigismember(&t->blocked, sig);
59281+ if (blocked || ignored) {
59282+ action->sa.sa_handler = SIG_DFL;
59283+ if (blocked) {
59284+ sigdelset(&t->blocked, sig);
59285+ recalc_sigpending_and_wake(t);
59286+ }
59287+ }
59288+ if (action->sa.sa_handler == SIG_DFL)
59289+ t->signal->flags &= ~SIGNAL_UNKILLABLE;
59290+ ret = specific_send_sig_info(sig, SEND_SIG_PRIV, t);
59291+
59292+ spin_unlock_irqrestore(&t->sighand->siglock, flags);
59293+
59294+ return ret;
59295+}
59296+#endif
59297+
59298+#ifdef CONFIG_GRKERNSEC_BRUTE
59299+#define GR_USER_BAN_TIME (15 * 60)
59300+
59301+static int __get_dumpable(unsigned long mm_flags)
59302+{
59303+ int ret;
59304+
59305+ ret = mm_flags & MMF_DUMPABLE_MASK;
59306+ return (ret >= 2) ? 2 : ret;
59307+}
59308+#endif
59309+
59310+void gr_handle_brute_attach(struct task_struct *p, unsigned long mm_flags)
59311+{
59312+#ifdef CONFIG_GRKERNSEC_BRUTE
59313+ kuid_t uid = GLOBAL_ROOT_UID;
59314+
59315+ if (!grsec_enable_brute)
59316+ return;
59317+
59318+ rcu_read_lock();
59319+ read_lock(&tasklist_lock);
59320+ read_lock(&grsec_exec_file_lock);
59321+ if (p->real_parent && p->real_parent->exec_file == p->exec_file)
59322+ p->real_parent->brute = 1;
59323+ else {
59324+ const struct cred *cred = __task_cred(p), *cred2;
59325+ struct task_struct *tsk, *tsk2;
59326+
59327+ if (!__get_dumpable(mm_flags) && !uid_eq(cred->uid, GLOBAL_ROOT_UID)) {
59328+ struct user_struct *user;
59329+
59330+ uid = cred->uid;
59331+
59332+ /* this is put upon execution past expiration */
59333+ user = find_user(uid);
59334+ if (user == NULL)
59335+ goto unlock;
59336+ user->banned = 1;
59337+ user->ban_expires = get_seconds() + GR_USER_BAN_TIME;
59338+ if (user->ban_expires == ~0UL)
59339+ user->ban_expires--;
59340+
59341+ do_each_thread(tsk2, tsk) {
59342+ cred2 = __task_cred(tsk);
59343+ if (tsk != p && uid_eq(cred2->uid, uid))
59344+ gr_fake_force_sig(SIGKILL, tsk);
59345+ } while_each_thread(tsk2, tsk);
59346+ }
59347+ }
59348+unlock:
59349+ read_unlock(&grsec_exec_file_lock);
59350+ read_unlock(&tasklist_lock);
59351+ rcu_read_unlock();
59352+
59353+ if (!uid_eq(uid, GLOBAL_ROOT_UID))
59354+ printk(KERN_ALERT "grsec: bruteforce prevention initiated against uid %u, banning for %d minutes\n",
59355+ from_kuid_munged(&init_user_ns, uid), GR_USER_BAN_TIME / 60);
59356+
59357+#endif
59358+ return;
59359+}
59360+
59361+void gr_handle_brute_check(void)
59362+{
59363+#ifdef CONFIG_GRKERNSEC_BRUTE
59364+ if (current->brute)
59365+ msleep(30 * 1000);
59366+#endif
59367+ return;
59368+}
59369+
59370+void gr_handle_kernel_exploit(void)
59371+{
59372+#ifdef CONFIG_GRKERNSEC_KERN_LOCKOUT
59373+ const struct cred *cred;
59374+ struct task_struct *tsk, *tsk2;
59375+ struct user_struct *user;
59376+ kuid_t uid;
59377+
59378+ if (in_irq() || in_serving_softirq() || in_nmi())
59379+ panic("grsec: halting the system due to suspicious kernel crash caused in interrupt context");
59380+
59381+ uid = current_uid();
59382+
59383+ if (uid_eq(uid, GLOBAL_ROOT_UID))
59384+ panic("grsec: halting the system due to suspicious kernel crash caused by root");
59385+ else {
59386+ /* kill all the processes of this user, hold a reference
59387+ to their creds struct, and prevent them from creating
59388+ another process until system reset
59389+ */
59390+ printk(KERN_ALERT "grsec: banning user with uid %u until system restart for suspicious kernel crash\n",
59391+ from_kuid_munged(&init_user_ns, uid));
59392+ /* we intentionally leak this ref */
59393+ user = get_uid(current->cred->user);
59394+ if (user) {
59395+ user->banned = 1;
59396+ user->ban_expires = ~0UL;
59397+ }
59398+
59399+ read_lock(&tasklist_lock);
59400+ do_each_thread(tsk2, tsk) {
59401+ cred = __task_cred(tsk);
59402+ if (uid_eq(cred->uid, uid))
59403+ gr_fake_force_sig(SIGKILL, tsk);
59404+ } while_each_thread(tsk2, tsk);
59405+ read_unlock(&tasklist_lock);
59406+ }
59407+#endif
59408+}
59409+
59410+int __gr_process_user_ban(struct user_struct *user)
59411+{
59412+#if defined(CONFIG_GRKERNSEC_KERN_LOCKOUT) || defined(CONFIG_GRKERNSEC_BRUTE)
59413+ if (unlikely(user->banned)) {
59414+ if (user->ban_expires != ~0UL && time_after_eq(get_seconds(), user->ban_expires)) {
59415+ user->banned = 0;
59416+ user->ban_expires = 0;
59417+ free_uid(user);
59418+ } else
59419+ return -EPERM;
59420+ }
59421+#endif
59422+ return 0;
59423+}
59424+
59425+int gr_process_user_ban(void)
59426+{
59427+#if defined(CONFIG_GRKERNSEC_KERN_LOCKOUT) || defined(CONFIG_GRKERNSEC_BRUTE)
59428+ return __gr_process_user_ban(current->cred->user);
59429+#endif
59430+ return 0;
59431+}
59432diff --git a/grsecurity/grsec_sock.c b/grsecurity/grsec_sock.c
59433new file mode 100644
59434index 0000000..4030d57
59435--- /dev/null
59436+++ b/grsecurity/grsec_sock.c
59437@@ -0,0 +1,244 @@
59438+#include <linux/kernel.h>
59439+#include <linux/module.h>
59440+#include <linux/sched.h>
59441+#include <linux/file.h>
59442+#include <linux/net.h>
59443+#include <linux/in.h>
59444+#include <linux/ip.h>
59445+#include <net/sock.h>
59446+#include <net/inet_sock.h>
59447+#include <linux/grsecurity.h>
59448+#include <linux/grinternal.h>
59449+#include <linux/gracl.h>
59450+
59451+extern int gr_search_udp_recvmsg(const struct sock *sk, const struct sk_buff *skb);
59452+extern int gr_search_udp_sendmsg(const struct sock *sk, const struct sockaddr_in *addr);
59453+
59454+EXPORT_SYMBOL(gr_search_udp_recvmsg);
59455+EXPORT_SYMBOL(gr_search_udp_sendmsg);
59456+
59457+#ifdef CONFIG_UNIX_MODULE
59458+EXPORT_SYMBOL(gr_acl_handle_unix);
59459+EXPORT_SYMBOL(gr_acl_handle_mknod);
59460+EXPORT_SYMBOL(gr_handle_chroot_unix);
59461+EXPORT_SYMBOL(gr_handle_create);
59462+#endif
59463+
59464+#ifdef CONFIG_GRKERNSEC
59465+#define gr_conn_table_size 32749
59466+struct conn_table_entry {
59467+ struct conn_table_entry *next;
59468+ struct signal_struct *sig;
59469+};
59470+
59471+struct conn_table_entry *gr_conn_table[gr_conn_table_size];
59472+DEFINE_SPINLOCK(gr_conn_table_lock);
59473+
59474+extern const char * gr_socktype_to_name(unsigned char type);
59475+extern const char * gr_proto_to_name(unsigned char proto);
59476+extern const char * gr_sockfamily_to_name(unsigned char family);
59477+
59478+static __inline__ int
59479+conn_hash(__u32 saddr, __u32 daddr, __u16 sport, __u16 dport, unsigned int size)
59480+{
59481+ return ((daddr + saddr + (sport << 8) + (dport << 16)) % size);
59482+}
59483+
59484+static __inline__ int
59485+conn_match(const struct signal_struct *sig, __u32 saddr, __u32 daddr,
59486+ __u16 sport, __u16 dport)
59487+{
59488+ if (unlikely(sig->gr_saddr == saddr && sig->gr_daddr == daddr &&
59489+ sig->gr_sport == sport && sig->gr_dport == dport))
59490+ return 1;
59491+ else
59492+ return 0;
59493+}
59494+
59495+static void gr_add_to_task_ip_table_nolock(struct signal_struct *sig, struct conn_table_entry *newent)
59496+{
59497+ struct conn_table_entry **match;
59498+ unsigned int index;
59499+
59500+ index = conn_hash(sig->gr_saddr, sig->gr_daddr,
59501+ sig->gr_sport, sig->gr_dport,
59502+ gr_conn_table_size);
59503+
59504+ newent->sig = sig;
59505+
59506+ match = &gr_conn_table[index];
59507+ newent->next = *match;
59508+ *match = newent;
59509+
59510+ return;
59511+}
59512+
59513+static void gr_del_task_from_ip_table_nolock(struct signal_struct *sig)
59514+{
59515+ struct conn_table_entry *match, *last = NULL;
59516+ unsigned int index;
59517+
59518+ index = conn_hash(sig->gr_saddr, sig->gr_daddr,
59519+ sig->gr_sport, sig->gr_dport,
59520+ gr_conn_table_size);
59521+
59522+ match = gr_conn_table[index];
59523+ while (match && !conn_match(match->sig,
59524+ sig->gr_saddr, sig->gr_daddr, sig->gr_sport,
59525+ sig->gr_dport)) {
59526+ last = match;
59527+ match = match->next;
59528+ }
59529+
59530+ if (match) {
59531+ if (last)
59532+ last->next = match->next;
59533+ else
59534+ gr_conn_table[index] = NULL;
59535+ kfree(match);
59536+ }
59537+
59538+ return;
59539+}
59540+
59541+static struct signal_struct * gr_lookup_task_ip_table(__u32 saddr, __u32 daddr,
59542+ __u16 sport, __u16 dport)
59543+{
59544+ struct conn_table_entry *match;
59545+ unsigned int index;
59546+
59547+ index = conn_hash(saddr, daddr, sport, dport, gr_conn_table_size);
59548+
59549+ match = gr_conn_table[index];
59550+ while (match && !conn_match(match->sig, saddr, daddr, sport, dport))
59551+ match = match->next;
59552+
59553+ if (match)
59554+ return match->sig;
59555+ else
59556+ return NULL;
59557+}
59558+
59559+#endif
59560+
59561+void gr_update_task_in_ip_table(struct task_struct *task, const struct inet_sock *inet)
59562+{
59563+#ifdef CONFIG_GRKERNSEC
59564+ struct signal_struct *sig = task->signal;
59565+ struct conn_table_entry *newent;
59566+
59567+ newent = kmalloc(sizeof(struct conn_table_entry), GFP_ATOMIC);
59568+ if (newent == NULL)
59569+ return;
59570+ /* no bh lock needed since we are called with bh disabled */
59571+ spin_lock(&gr_conn_table_lock);
59572+ gr_del_task_from_ip_table_nolock(sig);
59573+ sig->gr_saddr = inet->inet_rcv_saddr;
59574+ sig->gr_daddr = inet->inet_daddr;
59575+ sig->gr_sport = inet->inet_sport;
59576+ sig->gr_dport = inet->inet_dport;
59577+ gr_add_to_task_ip_table_nolock(sig, newent);
59578+ spin_unlock(&gr_conn_table_lock);
59579+#endif
59580+ return;
59581+}
59582+
59583+void gr_del_task_from_ip_table(struct task_struct *task)
59584+{
59585+#ifdef CONFIG_GRKERNSEC
59586+ spin_lock_bh(&gr_conn_table_lock);
59587+ gr_del_task_from_ip_table_nolock(task->signal);
59588+ spin_unlock_bh(&gr_conn_table_lock);
59589+#endif
59590+ return;
59591+}
59592+
59593+void
59594+gr_attach_curr_ip(const struct sock *sk)
59595+{
59596+#ifdef CONFIG_GRKERNSEC
59597+ struct signal_struct *p, *set;
59598+ const struct inet_sock *inet = inet_sk(sk);
59599+
59600+ if (unlikely(sk->sk_protocol != IPPROTO_TCP))
59601+ return;
59602+
59603+ set = current->signal;
59604+
59605+ spin_lock_bh(&gr_conn_table_lock);
59606+ p = gr_lookup_task_ip_table(inet->inet_daddr, inet->inet_rcv_saddr,
59607+ inet->inet_dport, inet->inet_sport);
59608+ if (unlikely(p != NULL)) {
59609+ set->curr_ip = p->curr_ip;
59610+ set->used_accept = 1;
59611+ gr_del_task_from_ip_table_nolock(p);
59612+ spin_unlock_bh(&gr_conn_table_lock);
59613+ return;
59614+ }
59615+ spin_unlock_bh(&gr_conn_table_lock);
59616+
59617+ set->curr_ip = inet->inet_daddr;
59618+ set->used_accept = 1;
59619+#endif
59620+ return;
59621+}
59622+
59623+int
59624+gr_handle_sock_all(const int family, const int type, const int protocol)
59625+{
59626+#ifdef CONFIG_GRKERNSEC_SOCKET_ALL
59627+ if (grsec_enable_socket_all && in_group_p(grsec_socket_all_gid) &&
59628+ (family != AF_UNIX)) {
59629+ if (family == AF_INET)
59630+ gr_log_str3(GR_DONT_AUDIT, GR_SOCK_MSG, gr_sockfamily_to_name(family), gr_socktype_to_name(type), gr_proto_to_name(protocol));
59631+ else
59632+ gr_log_str2_int(GR_DONT_AUDIT, GR_SOCK_NOINET_MSG, gr_sockfamily_to_name(family), gr_socktype_to_name(type), protocol);
59633+ return -EACCES;
59634+ }
59635+#endif
59636+ return 0;
59637+}
59638+
59639+int
59640+gr_handle_sock_server(const struct sockaddr *sck)
59641+{
59642+#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
59643+ if (grsec_enable_socket_server &&
59644+ in_group_p(grsec_socket_server_gid) &&
59645+ sck && (sck->sa_family != AF_UNIX) &&
59646+ (sck->sa_family != AF_LOCAL)) {
59647+ gr_log_noargs(GR_DONT_AUDIT, GR_BIND_MSG);
59648+ return -EACCES;
59649+ }
59650+#endif
59651+ return 0;
59652+}
59653+
59654+int
59655+gr_handle_sock_server_other(const struct sock *sck)
59656+{
59657+#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
59658+ if (grsec_enable_socket_server &&
59659+ in_group_p(grsec_socket_server_gid) &&
59660+ sck && (sck->sk_family != AF_UNIX) &&
59661+ (sck->sk_family != AF_LOCAL)) {
59662+ gr_log_noargs(GR_DONT_AUDIT, GR_BIND_MSG);
59663+ return -EACCES;
59664+ }
59665+#endif
59666+ return 0;
59667+}
59668+
59669+int
59670+gr_handle_sock_client(const struct sockaddr *sck)
59671+{
59672+#ifdef CONFIG_GRKERNSEC_SOCKET_CLIENT
59673+ if (grsec_enable_socket_client && in_group_p(grsec_socket_client_gid) &&
59674+ sck && (sck->sa_family != AF_UNIX) &&
59675+ (sck->sa_family != AF_LOCAL)) {
59676+ gr_log_noargs(GR_DONT_AUDIT, GR_CONNECT_MSG);
59677+ return -EACCES;
59678+ }
59679+#endif
59680+ return 0;
59681+}
59682diff --git a/grsecurity/grsec_sysctl.c b/grsecurity/grsec_sysctl.c
59683new file mode 100644
59684index 0000000..f55ef0f
59685--- /dev/null
59686+++ b/grsecurity/grsec_sysctl.c
59687@@ -0,0 +1,469 @@
59688+#include <linux/kernel.h>
59689+#include <linux/sched.h>
59690+#include <linux/sysctl.h>
59691+#include <linux/grsecurity.h>
59692+#include <linux/grinternal.h>
59693+
59694+int
59695+gr_handle_sysctl_mod(const char *dirname, const char *name, const int op)
59696+{
59697+#ifdef CONFIG_GRKERNSEC_SYSCTL
59698+ if (dirname == NULL || name == NULL)
59699+ return 0;
59700+ if (!strcmp(dirname, "grsecurity") && grsec_lock && (op & MAY_WRITE)) {
59701+ gr_log_str(GR_DONT_AUDIT, GR_SYSCTL_MSG, name);
59702+ return -EACCES;
59703+ }
59704+#endif
59705+ return 0;
59706+}
59707+
59708+#ifdef CONFIG_GRKERNSEC_ROFS
59709+static int __maybe_unused one = 1;
59710+#endif
59711+
59712+#if defined(CONFIG_GRKERNSEC_SYSCTL) || defined(CONFIG_GRKERNSEC_ROFS)
59713+struct ctl_table grsecurity_table[] = {
59714+#ifdef CONFIG_GRKERNSEC_SYSCTL
59715+#ifdef CONFIG_GRKERNSEC_SYSCTL_DISTRO
59716+#ifdef CONFIG_GRKERNSEC_IO
59717+ {
59718+ .procname = "disable_priv_io",
59719+ .data = &grsec_disable_privio,
59720+ .maxlen = sizeof(int),
59721+ .mode = 0600,
59722+ .proc_handler = &proc_dointvec,
59723+ },
59724+#endif
59725+#endif
59726+#ifdef CONFIG_GRKERNSEC_LINK
59727+ {
59728+ .procname = "linking_restrictions",
59729+ .data = &grsec_enable_link,
59730+ .maxlen = sizeof(int),
59731+ .mode = 0600,
59732+ .proc_handler = &proc_dointvec,
59733+ },
59734+#endif
59735+#ifdef CONFIG_GRKERNSEC_SYMLINKOWN
59736+ {
59737+ .procname = "enforce_symlinksifowner",
59738+ .data = &grsec_enable_symlinkown,
59739+ .maxlen = sizeof(int),
59740+ .mode = 0600,
59741+ .proc_handler = &proc_dointvec,
59742+ },
59743+ {
59744+ .procname = "symlinkown_gid",
59745+ .data = &grsec_symlinkown_gid,
59746+ .maxlen = sizeof(int),
59747+ .mode = 0600,
59748+ .proc_handler = &proc_dointvec,
59749+ },
59750+#endif
59751+#ifdef CONFIG_GRKERNSEC_BRUTE
59752+ {
59753+ .procname = "deter_bruteforce",
59754+ .data = &grsec_enable_brute,
59755+ .maxlen = sizeof(int),
59756+ .mode = 0600,
59757+ .proc_handler = &proc_dointvec,
59758+ },
59759+#endif
59760+#ifdef CONFIG_GRKERNSEC_FIFO
59761+ {
59762+ .procname = "fifo_restrictions",
59763+ .data = &grsec_enable_fifo,
59764+ .maxlen = sizeof(int),
59765+ .mode = 0600,
59766+ .proc_handler = &proc_dointvec,
59767+ },
59768+#endif
59769+#ifdef CONFIG_GRKERNSEC_PTRACE_READEXEC
59770+ {
59771+ .procname = "ptrace_readexec",
59772+ .data = &grsec_enable_ptrace_readexec,
59773+ .maxlen = sizeof(int),
59774+ .mode = 0600,
59775+ .proc_handler = &proc_dointvec,
59776+ },
59777+#endif
59778+#ifdef CONFIG_GRKERNSEC_SETXID
59779+ {
59780+ .procname = "consistent_setxid",
59781+ .data = &grsec_enable_setxid,
59782+ .maxlen = sizeof(int),
59783+ .mode = 0600,
59784+ .proc_handler = &proc_dointvec,
59785+ },
59786+#endif
59787+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
59788+ {
59789+ .procname = "ip_blackhole",
59790+ .data = &grsec_enable_blackhole,
59791+ .maxlen = sizeof(int),
59792+ .mode = 0600,
59793+ .proc_handler = &proc_dointvec,
59794+ },
59795+ {
59796+ .procname = "lastack_retries",
59797+ .data = &grsec_lastack_retries,
59798+ .maxlen = sizeof(int),
59799+ .mode = 0600,
59800+ .proc_handler = &proc_dointvec,
59801+ },
59802+#endif
59803+#ifdef CONFIG_GRKERNSEC_EXECLOG
59804+ {
59805+ .procname = "exec_logging",
59806+ .data = &grsec_enable_execlog,
59807+ .maxlen = sizeof(int),
59808+ .mode = 0600,
59809+ .proc_handler = &proc_dointvec,
59810+ },
59811+#endif
59812+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
59813+ {
59814+ .procname = "rwxmap_logging",
59815+ .data = &grsec_enable_log_rwxmaps,
59816+ .maxlen = sizeof(int),
59817+ .mode = 0600,
59818+ .proc_handler = &proc_dointvec,
59819+ },
59820+#endif
59821+#ifdef CONFIG_GRKERNSEC_SIGNAL
59822+ {
59823+ .procname = "signal_logging",
59824+ .data = &grsec_enable_signal,
59825+ .maxlen = sizeof(int),
59826+ .mode = 0600,
59827+ .proc_handler = &proc_dointvec,
59828+ },
59829+#endif
59830+#ifdef CONFIG_GRKERNSEC_FORKFAIL
59831+ {
59832+ .procname = "forkfail_logging",
59833+ .data = &grsec_enable_forkfail,
59834+ .maxlen = sizeof(int),
59835+ .mode = 0600,
59836+ .proc_handler = &proc_dointvec,
59837+ },
59838+#endif
59839+#ifdef CONFIG_GRKERNSEC_TIME
59840+ {
59841+ .procname = "timechange_logging",
59842+ .data = &grsec_enable_time,
59843+ .maxlen = sizeof(int),
59844+ .mode = 0600,
59845+ .proc_handler = &proc_dointvec,
59846+ },
59847+#endif
59848+#ifdef CONFIG_GRKERNSEC_CHROOT_SHMAT
59849+ {
59850+ .procname = "chroot_deny_shmat",
59851+ .data = &grsec_enable_chroot_shmat,
59852+ .maxlen = sizeof(int),
59853+ .mode = 0600,
59854+ .proc_handler = &proc_dointvec,
59855+ },
59856+#endif
59857+#ifdef CONFIG_GRKERNSEC_CHROOT_UNIX
59858+ {
59859+ .procname = "chroot_deny_unix",
59860+ .data = &grsec_enable_chroot_unix,
59861+ .maxlen = sizeof(int),
59862+ .mode = 0600,
59863+ .proc_handler = &proc_dointvec,
59864+ },
59865+#endif
59866+#ifdef CONFIG_GRKERNSEC_CHROOT_MOUNT
59867+ {
59868+ .procname = "chroot_deny_mount",
59869+ .data = &grsec_enable_chroot_mount,
59870+ .maxlen = sizeof(int),
59871+ .mode = 0600,
59872+ .proc_handler = &proc_dointvec,
59873+ },
59874+#endif
59875+#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
59876+ {
59877+ .procname = "chroot_deny_fchdir",
59878+ .data = &grsec_enable_chroot_fchdir,
59879+ .maxlen = sizeof(int),
59880+ .mode = 0600,
59881+ .proc_handler = &proc_dointvec,
59882+ },
59883+#endif
59884+#ifdef CONFIG_GRKERNSEC_CHROOT_DOUBLE
59885+ {
59886+ .procname = "chroot_deny_chroot",
59887+ .data = &grsec_enable_chroot_double,
59888+ .maxlen = sizeof(int),
59889+ .mode = 0600,
59890+ .proc_handler = &proc_dointvec,
59891+ },
59892+#endif
59893+#ifdef CONFIG_GRKERNSEC_CHROOT_PIVOT
59894+ {
59895+ .procname = "chroot_deny_pivot",
59896+ .data = &grsec_enable_chroot_pivot,
59897+ .maxlen = sizeof(int),
59898+ .mode = 0600,
59899+ .proc_handler = &proc_dointvec,
59900+ },
59901+#endif
59902+#ifdef CONFIG_GRKERNSEC_CHROOT_CHDIR
59903+ {
59904+ .procname = "chroot_enforce_chdir",
59905+ .data = &grsec_enable_chroot_chdir,
59906+ .maxlen = sizeof(int),
59907+ .mode = 0600,
59908+ .proc_handler = &proc_dointvec,
59909+ },
59910+#endif
59911+#ifdef CONFIG_GRKERNSEC_CHROOT_CHMOD
59912+ {
59913+ .procname = "chroot_deny_chmod",
59914+ .data = &grsec_enable_chroot_chmod,
59915+ .maxlen = sizeof(int),
59916+ .mode = 0600,
59917+ .proc_handler = &proc_dointvec,
59918+ },
59919+#endif
59920+#ifdef CONFIG_GRKERNSEC_CHROOT_MKNOD
59921+ {
59922+ .procname = "chroot_deny_mknod",
59923+ .data = &grsec_enable_chroot_mknod,
59924+ .maxlen = sizeof(int),
59925+ .mode = 0600,
59926+ .proc_handler = &proc_dointvec,
59927+ },
59928+#endif
59929+#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
59930+ {
59931+ .procname = "chroot_restrict_nice",
59932+ .data = &grsec_enable_chroot_nice,
59933+ .maxlen = sizeof(int),
59934+ .mode = 0600,
59935+ .proc_handler = &proc_dointvec,
59936+ },
59937+#endif
59938+#ifdef CONFIG_GRKERNSEC_CHROOT_EXECLOG
59939+ {
59940+ .procname = "chroot_execlog",
59941+ .data = &grsec_enable_chroot_execlog,
59942+ .maxlen = sizeof(int),
59943+ .mode = 0600,
59944+ .proc_handler = &proc_dointvec,
59945+ },
59946+#endif
59947+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
59948+ {
59949+ .procname = "chroot_caps",
59950+ .data = &grsec_enable_chroot_caps,
59951+ .maxlen = sizeof(int),
59952+ .mode = 0600,
59953+ .proc_handler = &proc_dointvec,
59954+ },
59955+#endif
59956+#ifdef CONFIG_GRKERNSEC_CHROOT_SYSCTL
59957+ {
59958+ .procname = "chroot_deny_sysctl",
59959+ .data = &grsec_enable_chroot_sysctl,
59960+ .maxlen = sizeof(int),
59961+ .mode = 0600,
59962+ .proc_handler = &proc_dointvec,
59963+ },
59964+#endif
59965+#ifdef CONFIG_GRKERNSEC_TPE
59966+ {
59967+ .procname = "tpe",
59968+ .data = &grsec_enable_tpe,
59969+ .maxlen = sizeof(int),
59970+ .mode = 0600,
59971+ .proc_handler = &proc_dointvec,
59972+ },
59973+ {
59974+ .procname = "tpe_gid",
59975+ .data = &grsec_tpe_gid,
59976+ .maxlen = sizeof(int),
59977+ .mode = 0600,
59978+ .proc_handler = &proc_dointvec,
59979+ },
59980+#endif
59981+#ifdef CONFIG_GRKERNSEC_TPE_INVERT
59982+ {
59983+ .procname = "tpe_invert",
59984+ .data = &grsec_enable_tpe_invert,
59985+ .maxlen = sizeof(int),
59986+ .mode = 0600,
59987+ .proc_handler = &proc_dointvec,
59988+ },
59989+#endif
59990+#ifdef CONFIG_GRKERNSEC_TPE_ALL
59991+ {
59992+ .procname = "tpe_restrict_all",
59993+ .data = &grsec_enable_tpe_all,
59994+ .maxlen = sizeof(int),
59995+ .mode = 0600,
59996+ .proc_handler = &proc_dointvec,
59997+ },
59998+#endif
59999+#ifdef CONFIG_GRKERNSEC_SOCKET_ALL
60000+ {
60001+ .procname = "socket_all",
60002+ .data = &grsec_enable_socket_all,
60003+ .maxlen = sizeof(int),
60004+ .mode = 0600,
60005+ .proc_handler = &proc_dointvec,
60006+ },
60007+ {
60008+ .procname = "socket_all_gid",
60009+ .data = &grsec_socket_all_gid,
60010+ .maxlen = sizeof(int),
60011+ .mode = 0600,
60012+ .proc_handler = &proc_dointvec,
60013+ },
60014+#endif
60015+#ifdef CONFIG_GRKERNSEC_SOCKET_CLIENT
60016+ {
60017+ .procname = "socket_client",
60018+ .data = &grsec_enable_socket_client,
60019+ .maxlen = sizeof(int),
60020+ .mode = 0600,
60021+ .proc_handler = &proc_dointvec,
60022+ },
60023+ {
60024+ .procname = "socket_client_gid",
60025+ .data = &grsec_socket_client_gid,
60026+ .maxlen = sizeof(int),
60027+ .mode = 0600,
60028+ .proc_handler = &proc_dointvec,
60029+ },
60030+#endif
60031+#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
60032+ {
60033+ .procname = "socket_server",
60034+ .data = &grsec_enable_socket_server,
60035+ .maxlen = sizeof(int),
60036+ .mode = 0600,
60037+ .proc_handler = &proc_dointvec,
60038+ },
60039+ {
60040+ .procname = "socket_server_gid",
60041+ .data = &grsec_socket_server_gid,
60042+ .maxlen = sizeof(int),
60043+ .mode = 0600,
60044+ .proc_handler = &proc_dointvec,
60045+ },
60046+#endif
60047+#ifdef CONFIG_GRKERNSEC_AUDIT_GROUP
60048+ {
60049+ .procname = "audit_group",
60050+ .data = &grsec_enable_group,
60051+ .maxlen = sizeof(int),
60052+ .mode = 0600,
60053+ .proc_handler = &proc_dointvec,
60054+ },
60055+ {
60056+ .procname = "audit_gid",
60057+ .data = &grsec_audit_gid,
60058+ .maxlen = sizeof(int),
60059+ .mode = 0600,
60060+ .proc_handler = &proc_dointvec,
60061+ },
60062+#endif
60063+#ifdef CONFIG_GRKERNSEC_AUDIT_CHDIR
60064+ {
60065+ .procname = "audit_chdir",
60066+ .data = &grsec_enable_chdir,
60067+ .maxlen = sizeof(int),
60068+ .mode = 0600,
60069+ .proc_handler = &proc_dointvec,
60070+ },
60071+#endif
60072+#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
60073+ {
60074+ .procname = "audit_mount",
60075+ .data = &grsec_enable_mount,
60076+ .maxlen = sizeof(int),
60077+ .mode = 0600,
60078+ .proc_handler = &proc_dointvec,
60079+ },
60080+#endif
60081+#ifdef CONFIG_GRKERNSEC_AUDIT_TEXTREL
60082+ {
60083+ .procname = "audit_textrel",
60084+ .data = &grsec_enable_audit_textrel,
60085+ .maxlen = sizeof(int),
60086+ .mode = 0600,
60087+ .proc_handler = &proc_dointvec,
60088+ },
60089+#endif
60090+#ifdef CONFIG_GRKERNSEC_DMESG
60091+ {
60092+ .procname = "dmesg",
60093+ .data = &grsec_enable_dmesg,
60094+ .maxlen = sizeof(int),
60095+ .mode = 0600,
60096+ .proc_handler = &proc_dointvec,
60097+ },
60098+#endif
60099+#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
60100+ {
60101+ .procname = "chroot_findtask",
60102+ .data = &grsec_enable_chroot_findtask,
60103+ .maxlen = sizeof(int),
60104+ .mode = 0600,
60105+ .proc_handler = &proc_dointvec,
60106+ },
60107+#endif
60108+#ifdef CONFIG_GRKERNSEC_RESLOG
60109+ {
60110+ .procname = "resource_logging",
60111+ .data = &grsec_resource_logging,
60112+ .maxlen = sizeof(int),
60113+ .mode = 0600,
60114+ .proc_handler = &proc_dointvec,
60115+ },
60116+#endif
60117+#ifdef CONFIG_GRKERNSEC_AUDIT_PTRACE
60118+ {
60119+ .procname = "audit_ptrace",
60120+ .data = &grsec_enable_audit_ptrace,
60121+ .maxlen = sizeof(int),
60122+ .mode = 0600,
60123+ .proc_handler = &proc_dointvec,
60124+ },
60125+#endif
60126+#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
60127+ {
60128+ .procname = "harden_ptrace",
60129+ .data = &grsec_enable_harden_ptrace,
60130+ .maxlen = sizeof(int),
60131+ .mode = 0600,
60132+ .proc_handler = &proc_dointvec,
60133+ },
60134+#endif
60135+ {
60136+ .procname = "grsec_lock",
60137+ .data = &grsec_lock,
60138+ .maxlen = sizeof(int),
60139+ .mode = 0600,
60140+ .proc_handler = &proc_dointvec,
60141+ },
60142+#endif
60143+#ifdef CONFIG_GRKERNSEC_ROFS
60144+ {
60145+ .procname = "romount_protect",
60146+ .data = &grsec_enable_rofs,
60147+ .maxlen = sizeof(int),
60148+ .mode = 0600,
60149+ .proc_handler = &proc_dointvec_minmax,
60150+ .extra1 = &one,
60151+ .extra2 = &one,
60152+ },
60153+#endif
60154+ { }
60155+};
60156+#endif
60157diff --git a/grsecurity/grsec_time.c b/grsecurity/grsec_time.c
60158new file mode 100644
60159index 0000000..0dc13c3
60160--- /dev/null
60161+++ b/grsecurity/grsec_time.c
60162@@ -0,0 +1,16 @@
60163+#include <linux/kernel.h>
60164+#include <linux/sched.h>
60165+#include <linux/grinternal.h>
60166+#include <linux/module.h>
60167+
60168+void
60169+gr_log_timechange(void)
60170+{
60171+#ifdef CONFIG_GRKERNSEC_TIME
60172+ if (grsec_enable_time)
60173+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_TIME_MSG);
60174+#endif
60175+ return;
60176+}
60177+
60178+EXPORT_SYMBOL(gr_log_timechange);
60179diff --git a/grsecurity/grsec_tpe.c b/grsecurity/grsec_tpe.c
60180new file mode 100644
60181index 0000000..07e0dc0
60182--- /dev/null
60183+++ b/grsecurity/grsec_tpe.c
60184@@ -0,0 +1,73 @@
60185+#include <linux/kernel.h>
60186+#include <linux/sched.h>
60187+#include <linux/file.h>
60188+#include <linux/fs.h>
60189+#include <linux/grinternal.h>
60190+
60191+extern int gr_acl_tpe_check(void);
60192+
60193+int
60194+gr_tpe_allow(const struct file *file)
60195+{
60196+#ifdef CONFIG_GRKERNSEC
60197+ struct inode *inode = file->f_path.dentry->d_parent->d_inode;
60198+ const struct cred *cred = current_cred();
60199+ char *msg = NULL;
60200+ char *msg2 = NULL;
60201+
60202+ // never restrict root
60203+ if (!cred->uid)
60204+ return 1;
60205+
60206+ if (grsec_enable_tpe) {
60207+#ifdef CONFIG_GRKERNSEC_TPE_INVERT
60208+ if (grsec_enable_tpe_invert && !in_group_p(grsec_tpe_gid))
60209+ msg = "not being in trusted group";
60210+ else if (!grsec_enable_tpe_invert && in_group_p(grsec_tpe_gid))
60211+ msg = "being in untrusted group";
60212+#else
60213+ if (in_group_p(grsec_tpe_gid))
60214+ msg = "being in untrusted group";
60215+#endif
60216+ }
60217+ if (!msg && gr_acl_tpe_check())
60218+ msg = "being in untrusted role";
60219+
60220+ // not in any affected group/role
60221+ if (!msg)
60222+ goto next_check;
60223+
60224+ if (inode->i_uid)
60225+ msg2 = "file in non-root-owned directory";
60226+ else if (inode->i_mode & S_IWOTH)
60227+ msg2 = "file in world-writable directory";
60228+ else if (inode->i_mode & S_IWGRP)
60229+ msg2 = "file in group-writable directory";
60230+
60231+ if (msg && msg2) {
60232+ char fullmsg[70] = {0};
60233+ snprintf(fullmsg, sizeof(fullmsg)-1, "%s and %s", msg, msg2);
60234+ gr_log_str_fs(GR_DONT_AUDIT, GR_EXEC_TPE_MSG, fullmsg, file->f_path.dentry, file->f_path.mnt);
60235+ return 0;
60236+ }
60237+ msg = NULL;
60238+next_check:
60239+#ifdef CONFIG_GRKERNSEC_TPE_ALL
60240+ if (!grsec_enable_tpe || !grsec_enable_tpe_all)
60241+ return 1;
60242+
60243+ if (inode->i_uid && (inode->i_uid != cred->uid))
60244+ msg = "directory not owned by user";
60245+ else if (inode->i_mode & S_IWOTH)
60246+ msg = "file in world-writable directory";
60247+ else if (inode->i_mode & S_IWGRP)
60248+ msg = "file in group-writable directory";
60249+
60250+ if (msg) {
60251+ gr_log_str_fs(GR_DONT_AUDIT, GR_EXEC_TPE_MSG, msg, file->f_path.dentry, file->f_path.mnt);
60252+ return 0;
60253+ }
60254+#endif
60255+#endif
60256+ return 1;
60257+}
60258diff --git a/grsecurity/grsum.c b/grsecurity/grsum.c
60259new file mode 100644
60260index 0000000..9f7b1ac
60261--- /dev/null
60262+++ b/grsecurity/grsum.c
60263@@ -0,0 +1,61 @@
60264+#include <linux/err.h>
60265+#include <linux/kernel.h>
60266+#include <linux/sched.h>
60267+#include <linux/mm.h>
60268+#include <linux/scatterlist.h>
60269+#include <linux/crypto.h>
60270+#include <linux/gracl.h>
60271+
60272+
60273+#if !defined(CONFIG_CRYPTO) || defined(CONFIG_CRYPTO_MODULE) || !defined(CONFIG_CRYPTO_SHA256) || defined(CONFIG_CRYPTO_SHA256_MODULE)
60274+#error "crypto and sha256 must be built into the kernel"
60275+#endif
60276+
60277+int
60278+chkpw(struct gr_arg *entry, unsigned char *salt, unsigned char *sum)
60279+{
60280+ char *p;
60281+ struct crypto_hash *tfm;
60282+ struct hash_desc desc;
60283+ struct scatterlist sg;
60284+ unsigned char temp_sum[GR_SHA_LEN];
60285+ volatile int retval = 0;
60286+ volatile int dummy = 0;
60287+ unsigned int i;
60288+
60289+ sg_init_table(&sg, 1);
60290+
60291+ tfm = crypto_alloc_hash("sha256", 0, CRYPTO_ALG_ASYNC);
60292+ if (IS_ERR(tfm)) {
60293+ /* should never happen, since sha256 should be built in */
60294+ return 1;
60295+ }
60296+
60297+ desc.tfm = tfm;
60298+ desc.flags = 0;
60299+
60300+ crypto_hash_init(&desc);
60301+
60302+ p = salt;
60303+ sg_set_buf(&sg, p, GR_SALT_LEN);
60304+ crypto_hash_update(&desc, &sg, sg.length);
60305+
60306+ p = entry->pw;
60307+ sg_set_buf(&sg, p, strlen(p));
60308+
60309+ crypto_hash_update(&desc, &sg, sg.length);
60310+
60311+ crypto_hash_final(&desc, temp_sum);
60312+
60313+ memset(entry->pw, 0, GR_PW_LEN);
60314+
60315+ for (i = 0; i < GR_SHA_LEN; i++)
60316+ if (sum[i] != temp_sum[i])
60317+ retval = 1;
60318+ else
60319+ dummy = 1; // waste a cycle
60320+
60321+ crypto_free_hash(tfm);
60322+
60323+ return retval;
60324+}
60325diff --git a/include/acpi/acpi_bus.h b/include/acpi/acpi_bus.h
60326index bde976e..a1cc32a 100644
60327--- a/include/acpi/acpi_bus.h
60328+++ b/include/acpi/acpi_bus.h
60329@@ -136,7 +136,7 @@ struct acpi_device_ops {
60330 acpi_op_bind bind;
60331 acpi_op_unbind unbind;
60332 acpi_op_notify notify;
60333-};
60334+} __no_const;
60335
60336 #define ACPI_DRIVER_ALL_NOTIFY_EVENTS 0x1 /* system AND device events */
60337
60338diff --git a/include/asm-generic/4level-fixup.h b/include/asm-generic/4level-fixup.h
60339index 77ff547..181834f 100644
60340--- a/include/asm-generic/4level-fixup.h
60341+++ b/include/asm-generic/4level-fixup.h
60342@@ -13,8 +13,10 @@
60343 #define pmd_alloc(mm, pud, address) \
60344 ((unlikely(pgd_none(*(pud))) && __pmd_alloc(mm, pud, address))? \
60345 NULL: pmd_offset(pud, address))
60346+#define pmd_alloc_kernel(mm, pud, address) pmd_alloc((mm), (pud), (address))
60347
60348 #define pud_alloc(mm, pgd, address) (pgd)
60349+#define pud_alloc_kernel(mm, pgd, address) pud_alloc((mm), (pgd), (address))
60350 #define pud_offset(pgd, start) (pgd)
60351 #define pud_none(pud) 0
60352 #define pud_bad(pud) 0
60353diff --git a/include/asm-generic/atomic-long.h b/include/asm-generic/atomic-long.h
60354index b7babf0..3ba8aee 100644
60355--- a/include/asm-generic/atomic-long.h
60356+++ b/include/asm-generic/atomic-long.h
60357@@ -22,6 +22,12 @@
60358
60359 typedef atomic64_t atomic_long_t;
60360
60361+#ifdef CONFIG_PAX_REFCOUNT
60362+typedef atomic64_unchecked_t atomic_long_unchecked_t;
60363+#else
60364+typedef atomic64_t atomic_long_unchecked_t;
60365+#endif
60366+
60367 #define ATOMIC_LONG_INIT(i) ATOMIC64_INIT(i)
60368
60369 static inline long atomic_long_read(atomic_long_t *l)
60370@@ -31,6 +37,15 @@ static inline long atomic_long_read(atomic_long_t *l)
60371 return (long)atomic64_read(v);
60372 }
60373
60374+#ifdef CONFIG_PAX_REFCOUNT
60375+static inline long atomic_long_read_unchecked(atomic_long_unchecked_t *l)
60376+{
60377+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
60378+
60379+ return (long)atomic64_read_unchecked(v);
60380+}
60381+#endif
60382+
60383 static inline void atomic_long_set(atomic_long_t *l, long i)
60384 {
60385 atomic64_t *v = (atomic64_t *)l;
60386@@ -38,6 +53,15 @@ static inline void atomic_long_set(atomic_long_t *l, long i)
60387 atomic64_set(v, i);
60388 }
60389
60390+#ifdef CONFIG_PAX_REFCOUNT
60391+static inline void atomic_long_set_unchecked(atomic_long_unchecked_t *l, long i)
60392+{
60393+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
60394+
60395+ atomic64_set_unchecked(v, i);
60396+}
60397+#endif
60398+
60399 static inline void atomic_long_inc(atomic_long_t *l)
60400 {
60401 atomic64_t *v = (atomic64_t *)l;
60402@@ -45,6 +69,15 @@ static inline void atomic_long_inc(atomic_long_t *l)
60403 atomic64_inc(v);
60404 }
60405
60406+#ifdef CONFIG_PAX_REFCOUNT
60407+static inline void atomic_long_inc_unchecked(atomic_long_unchecked_t *l)
60408+{
60409+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
60410+
60411+ atomic64_inc_unchecked(v);
60412+}
60413+#endif
60414+
60415 static inline void atomic_long_dec(atomic_long_t *l)
60416 {
60417 atomic64_t *v = (atomic64_t *)l;
60418@@ -52,6 +85,15 @@ static inline void atomic_long_dec(atomic_long_t *l)
60419 atomic64_dec(v);
60420 }
60421
60422+#ifdef CONFIG_PAX_REFCOUNT
60423+static inline void atomic_long_dec_unchecked(atomic_long_unchecked_t *l)
60424+{
60425+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
60426+
60427+ atomic64_dec_unchecked(v);
60428+}
60429+#endif
60430+
60431 static inline void atomic_long_add(long i, atomic_long_t *l)
60432 {
60433 atomic64_t *v = (atomic64_t *)l;
60434@@ -59,6 +101,15 @@ static inline void atomic_long_add(long i, atomic_long_t *l)
60435 atomic64_add(i, v);
60436 }
60437
60438+#ifdef CONFIG_PAX_REFCOUNT
60439+static inline void atomic_long_add_unchecked(long i, atomic_long_unchecked_t *l)
60440+{
60441+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
60442+
60443+ atomic64_add_unchecked(i, v);
60444+}
60445+#endif
60446+
60447 static inline void atomic_long_sub(long i, atomic_long_t *l)
60448 {
60449 atomic64_t *v = (atomic64_t *)l;
60450@@ -66,6 +117,15 @@ static inline void atomic_long_sub(long i, atomic_long_t *l)
60451 atomic64_sub(i, v);
60452 }
60453
60454+#ifdef CONFIG_PAX_REFCOUNT
60455+static inline void atomic_long_sub_unchecked(long i, atomic_long_unchecked_t *l)
60456+{
60457+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
60458+
60459+ atomic64_sub_unchecked(i, v);
60460+}
60461+#endif
60462+
60463 static inline int atomic_long_sub_and_test(long i, atomic_long_t *l)
60464 {
60465 atomic64_t *v = (atomic64_t *)l;
60466@@ -115,6 +175,15 @@ static inline long atomic_long_inc_return(atomic_long_t *l)
60467 return (long)atomic64_inc_return(v);
60468 }
60469
60470+#ifdef CONFIG_PAX_REFCOUNT
60471+static inline long atomic_long_inc_return_unchecked(atomic_long_unchecked_t *l)
60472+{
60473+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
60474+
60475+ return (long)atomic64_inc_return_unchecked(v);
60476+}
60477+#endif
60478+
60479 static inline long atomic_long_dec_return(atomic_long_t *l)
60480 {
60481 atomic64_t *v = (atomic64_t *)l;
60482@@ -140,6 +209,12 @@ static inline long atomic_long_add_unless(atomic_long_t *l, long a, long u)
60483
60484 typedef atomic_t atomic_long_t;
60485
60486+#ifdef CONFIG_PAX_REFCOUNT
60487+typedef atomic_unchecked_t atomic_long_unchecked_t;
60488+#else
60489+typedef atomic_t atomic_long_unchecked_t;
60490+#endif
60491+
60492 #define ATOMIC_LONG_INIT(i) ATOMIC_INIT(i)
60493 static inline long atomic_long_read(atomic_long_t *l)
60494 {
60495@@ -148,6 +223,15 @@ static inline long atomic_long_read(atomic_long_t *l)
60496 return (long)atomic_read(v);
60497 }
60498
60499+#ifdef CONFIG_PAX_REFCOUNT
60500+static inline long atomic_long_read_unchecked(atomic_long_unchecked_t *l)
60501+{
60502+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
60503+
60504+ return (long)atomic_read_unchecked(v);
60505+}
60506+#endif
60507+
60508 static inline void atomic_long_set(atomic_long_t *l, long i)
60509 {
60510 atomic_t *v = (atomic_t *)l;
60511@@ -155,6 +239,15 @@ static inline void atomic_long_set(atomic_long_t *l, long i)
60512 atomic_set(v, i);
60513 }
60514
60515+#ifdef CONFIG_PAX_REFCOUNT
60516+static inline void atomic_long_set_unchecked(atomic_long_unchecked_t *l, long i)
60517+{
60518+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
60519+
60520+ atomic_set_unchecked(v, i);
60521+}
60522+#endif
60523+
60524 static inline void atomic_long_inc(atomic_long_t *l)
60525 {
60526 atomic_t *v = (atomic_t *)l;
60527@@ -162,6 +255,15 @@ static inline void atomic_long_inc(atomic_long_t *l)
60528 atomic_inc(v);
60529 }
60530
60531+#ifdef CONFIG_PAX_REFCOUNT
60532+static inline void atomic_long_inc_unchecked(atomic_long_unchecked_t *l)
60533+{
60534+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
60535+
60536+ atomic_inc_unchecked(v);
60537+}
60538+#endif
60539+
60540 static inline void atomic_long_dec(atomic_long_t *l)
60541 {
60542 atomic_t *v = (atomic_t *)l;
60543@@ -169,6 +271,15 @@ static inline void atomic_long_dec(atomic_long_t *l)
60544 atomic_dec(v);
60545 }
60546
60547+#ifdef CONFIG_PAX_REFCOUNT
60548+static inline void atomic_long_dec_unchecked(atomic_long_unchecked_t *l)
60549+{
60550+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
60551+
60552+ atomic_dec_unchecked(v);
60553+}
60554+#endif
60555+
60556 static inline void atomic_long_add(long i, atomic_long_t *l)
60557 {
60558 atomic_t *v = (atomic_t *)l;
60559@@ -176,6 +287,15 @@ static inline void atomic_long_add(long i, atomic_long_t *l)
60560 atomic_add(i, v);
60561 }
60562
60563+#ifdef CONFIG_PAX_REFCOUNT
60564+static inline void atomic_long_add_unchecked(long i, atomic_long_unchecked_t *l)
60565+{
60566+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
60567+
60568+ atomic_add_unchecked(i, v);
60569+}
60570+#endif
60571+
60572 static inline void atomic_long_sub(long i, atomic_long_t *l)
60573 {
60574 atomic_t *v = (atomic_t *)l;
60575@@ -183,6 +303,15 @@ static inline void atomic_long_sub(long i, atomic_long_t *l)
60576 atomic_sub(i, v);
60577 }
60578
60579+#ifdef CONFIG_PAX_REFCOUNT
60580+static inline void atomic_long_sub_unchecked(long i, atomic_long_unchecked_t *l)
60581+{
60582+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
60583+
60584+ atomic_sub_unchecked(i, v);
60585+}
60586+#endif
60587+
60588 static inline int atomic_long_sub_and_test(long i, atomic_long_t *l)
60589 {
60590 atomic_t *v = (atomic_t *)l;
60591@@ -232,6 +361,15 @@ static inline long atomic_long_inc_return(atomic_long_t *l)
60592 return (long)atomic_inc_return(v);
60593 }
60594
60595+#ifdef CONFIG_PAX_REFCOUNT
60596+static inline long atomic_long_inc_return_unchecked(atomic_long_unchecked_t *l)
60597+{
60598+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
60599+
60600+ return (long)atomic_inc_return_unchecked(v);
60601+}
60602+#endif
60603+
60604 static inline long atomic_long_dec_return(atomic_long_t *l)
60605 {
60606 atomic_t *v = (atomic_t *)l;
60607@@ -255,4 +393,55 @@ static inline long atomic_long_add_unless(atomic_long_t *l, long a, long u)
60608
60609 #endif /* BITS_PER_LONG == 64 */
60610
60611+#ifdef CONFIG_PAX_REFCOUNT
60612+static inline void pax_refcount_needs_these_functions(void)
60613+{
60614+ atomic_read_unchecked((atomic_unchecked_t *)NULL);
60615+ atomic_set_unchecked((atomic_unchecked_t *)NULL, 0);
60616+ atomic_add_unchecked(0, (atomic_unchecked_t *)NULL);
60617+ atomic_sub_unchecked(0, (atomic_unchecked_t *)NULL);
60618+ atomic_inc_unchecked((atomic_unchecked_t *)NULL);
60619+ (void)atomic_inc_and_test_unchecked((atomic_unchecked_t *)NULL);
60620+ atomic_inc_return_unchecked((atomic_unchecked_t *)NULL);
60621+ atomic_add_return_unchecked(0, (atomic_unchecked_t *)NULL);
60622+ atomic_dec_unchecked((atomic_unchecked_t *)NULL);
60623+ atomic_cmpxchg_unchecked((atomic_unchecked_t *)NULL, 0, 0);
60624+ (void)atomic_xchg_unchecked((atomic_unchecked_t *)NULL, 0);
60625+#ifdef CONFIG_X86
60626+ atomic_clear_mask_unchecked(0, NULL);
60627+ atomic_set_mask_unchecked(0, NULL);
60628+#endif
60629+
60630+ atomic_long_read_unchecked((atomic_long_unchecked_t *)NULL);
60631+ atomic_long_set_unchecked((atomic_long_unchecked_t *)NULL, 0);
60632+ atomic_long_add_unchecked(0, (atomic_long_unchecked_t *)NULL);
60633+ atomic_long_sub_unchecked(0, (atomic_long_unchecked_t *)NULL);
60634+ atomic_long_inc_unchecked((atomic_long_unchecked_t *)NULL);
60635+ atomic_long_inc_return_unchecked((atomic_long_unchecked_t *)NULL);
60636+ atomic_long_dec_unchecked((atomic_long_unchecked_t *)NULL);
60637+}
60638+#else
60639+#define atomic_read_unchecked(v) atomic_read(v)
60640+#define atomic_set_unchecked(v, i) atomic_set((v), (i))
60641+#define atomic_add_unchecked(i, v) atomic_add((i), (v))
60642+#define atomic_sub_unchecked(i, v) atomic_sub((i), (v))
60643+#define atomic_inc_unchecked(v) atomic_inc(v)
60644+#define atomic_inc_and_test_unchecked(v) atomic_inc_and_test(v)
60645+#define atomic_inc_return_unchecked(v) atomic_inc_return(v)
60646+#define atomic_add_return_unchecked(i, v) atomic_add_return((i), (v))
60647+#define atomic_dec_unchecked(v) atomic_dec(v)
60648+#define atomic_cmpxchg_unchecked(v, o, n) atomic_cmpxchg((v), (o), (n))
60649+#define atomic_xchg_unchecked(v, i) atomic_xchg((v), (i))
60650+#define atomic_clear_mask_unchecked(mask, v) atomic_clear_mask((mask), (v))
60651+#define atomic_set_mask_unchecked(mask, v) atomic_set_mask((mask), (v))
60652+
60653+#define atomic_long_read_unchecked(v) atomic_long_read(v)
60654+#define atomic_long_set_unchecked(v, i) atomic_long_set((v), (i))
60655+#define atomic_long_add_unchecked(i, v) atomic_long_add((i), (v))
60656+#define atomic_long_sub_unchecked(i, v) atomic_long_sub((i), (v))
60657+#define atomic_long_inc_unchecked(v) atomic_long_inc(v)
60658+#define atomic_long_inc_return_unchecked(v) atomic_long_inc_return(v)
60659+#define atomic_long_dec_unchecked(v) atomic_long_dec(v)
60660+#endif
60661+
60662 #endif /* _ASM_GENERIC_ATOMIC_LONG_H */
60663diff --git a/include/asm-generic/atomic.h b/include/asm-generic/atomic.h
60664index 1ced641..c896ee8 100644
60665--- a/include/asm-generic/atomic.h
60666+++ b/include/asm-generic/atomic.h
60667@@ -159,7 +159,7 @@ static inline int __atomic_add_unless(atomic_t *v, int a, int u)
60668 * Atomically clears the bits set in @mask from @v
60669 */
60670 #ifndef atomic_clear_mask
60671-static inline void atomic_clear_mask(unsigned long mask, atomic_t *v)
60672+static inline void atomic_clear_mask(unsigned int mask, atomic_t *v)
60673 {
60674 unsigned long flags;
60675
60676diff --git a/include/asm-generic/atomic64.h b/include/asm-generic/atomic64.h
60677index b18ce4f..2ee2843 100644
60678--- a/include/asm-generic/atomic64.h
60679+++ b/include/asm-generic/atomic64.h
60680@@ -16,6 +16,8 @@ typedef struct {
60681 long long counter;
60682 } atomic64_t;
60683
60684+typedef atomic64_t atomic64_unchecked_t;
60685+
60686 #define ATOMIC64_INIT(i) { (i) }
60687
60688 extern long long atomic64_read(const atomic64_t *v);
60689@@ -39,4 +41,14 @@ extern int atomic64_add_unless(atomic64_t *v, long long a, long long u);
60690 #define atomic64_dec_and_test(v) (atomic64_dec_return((v)) == 0)
60691 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1LL, 0LL)
60692
60693+#define atomic64_read_unchecked(v) atomic64_read(v)
60694+#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
60695+#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
60696+#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
60697+#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
60698+#define atomic64_inc_unchecked(v) atomic64_inc(v)
60699+#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
60700+#define atomic64_dec_unchecked(v) atomic64_dec(v)
60701+#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
60702+
60703 #endif /* _ASM_GENERIC_ATOMIC64_H */
60704diff --git a/include/asm-generic/cache.h b/include/asm-generic/cache.h
60705index 1bfcfe5..e04c5c9 100644
60706--- a/include/asm-generic/cache.h
60707+++ b/include/asm-generic/cache.h
60708@@ -6,7 +6,7 @@
60709 * cache lines need to provide their own cache.h.
60710 */
60711
60712-#define L1_CACHE_SHIFT 5
60713-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
60714+#define L1_CACHE_SHIFT 5UL
60715+#define L1_CACHE_BYTES (1UL << L1_CACHE_SHIFT)
60716
60717 #endif /* __ASM_GENERIC_CACHE_H */
60718diff --git a/include/asm-generic/emergency-restart.h b/include/asm-generic/emergency-restart.h
60719index 0d68a1e..b74a761 100644
60720--- a/include/asm-generic/emergency-restart.h
60721+++ b/include/asm-generic/emergency-restart.h
60722@@ -1,7 +1,7 @@
60723 #ifndef _ASM_GENERIC_EMERGENCY_RESTART_H
60724 #define _ASM_GENERIC_EMERGENCY_RESTART_H
60725
60726-static inline void machine_emergency_restart(void)
60727+static inline __noreturn void machine_emergency_restart(void)
60728 {
60729 machine_restart(NULL);
60730 }
60731diff --git a/include/asm-generic/kmap_types.h b/include/asm-generic/kmap_types.h
60732index 90f99c7..00ce236 100644
60733--- a/include/asm-generic/kmap_types.h
60734+++ b/include/asm-generic/kmap_types.h
60735@@ -2,9 +2,9 @@
60736 #define _ASM_GENERIC_KMAP_TYPES_H
60737
60738 #ifdef __WITH_KM_FENCE
60739-# define KM_TYPE_NR 41
60740+# define KM_TYPE_NR 42
60741 #else
60742-# define KM_TYPE_NR 20
60743+# define KM_TYPE_NR 21
60744 #endif
60745
60746 #endif
60747diff --git a/include/asm-generic/local.h b/include/asm-generic/local.h
60748index 9ceb03b..2efbcbd 100644
60749--- a/include/asm-generic/local.h
60750+++ b/include/asm-generic/local.h
60751@@ -39,6 +39,7 @@ typedef struct
60752 #define local_add_return(i, l) atomic_long_add_return((i), (&(l)->a))
60753 #define local_sub_return(i, l) atomic_long_sub_return((i), (&(l)->a))
60754 #define local_inc_return(l) atomic_long_inc_return(&(l)->a)
60755+#define local_dec_return(l) atomic_long_dec_return(&(l)->a)
60756
60757 #define local_cmpxchg(l, o, n) atomic_long_cmpxchg((&(l)->a), (o), (n))
60758 #define local_xchg(l, n) atomic_long_xchg((&(l)->a), (n))
60759diff --git a/include/asm-generic/pgtable-nopmd.h b/include/asm-generic/pgtable-nopmd.h
60760index 725612b..9cc513a 100644
60761--- a/include/asm-generic/pgtable-nopmd.h
60762+++ b/include/asm-generic/pgtable-nopmd.h
60763@@ -1,14 +1,19 @@
60764 #ifndef _PGTABLE_NOPMD_H
60765 #define _PGTABLE_NOPMD_H
60766
60767-#ifndef __ASSEMBLY__
60768-
60769 #include <asm-generic/pgtable-nopud.h>
60770
60771-struct mm_struct;
60772-
60773 #define __PAGETABLE_PMD_FOLDED
60774
60775+#define PMD_SHIFT PUD_SHIFT
60776+#define PTRS_PER_PMD 1
60777+#define PMD_SIZE (_AC(1,UL) << PMD_SHIFT)
60778+#define PMD_MASK (~(PMD_SIZE-1))
60779+
60780+#ifndef __ASSEMBLY__
60781+
60782+struct mm_struct;
60783+
60784 /*
60785 * Having the pmd type consist of a pud gets the size right, and allows
60786 * us to conceptually access the pud entry that this pmd is folded into
60787@@ -16,11 +21,6 @@ struct mm_struct;
60788 */
60789 typedef struct { pud_t pud; } pmd_t;
60790
60791-#define PMD_SHIFT PUD_SHIFT
60792-#define PTRS_PER_PMD 1
60793-#define PMD_SIZE (1UL << PMD_SHIFT)
60794-#define PMD_MASK (~(PMD_SIZE-1))
60795-
60796 /*
60797 * The "pud_xxx()" functions here are trivial for a folded two-level
60798 * setup: the pmd is never bad, and a pmd always exists (as it's folded
60799diff --git a/include/asm-generic/pgtable-nopud.h b/include/asm-generic/pgtable-nopud.h
60800index 810431d..0ec4804f 100644
60801--- a/include/asm-generic/pgtable-nopud.h
60802+++ b/include/asm-generic/pgtable-nopud.h
60803@@ -1,10 +1,15 @@
60804 #ifndef _PGTABLE_NOPUD_H
60805 #define _PGTABLE_NOPUD_H
60806
60807-#ifndef __ASSEMBLY__
60808-
60809 #define __PAGETABLE_PUD_FOLDED
60810
60811+#define PUD_SHIFT PGDIR_SHIFT
60812+#define PTRS_PER_PUD 1
60813+#define PUD_SIZE (_AC(1,UL) << PUD_SHIFT)
60814+#define PUD_MASK (~(PUD_SIZE-1))
60815+
60816+#ifndef __ASSEMBLY__
60817+
60818 /*
60819 * Having the pud type consist of a pgd gets the size right, and allows
60820 * us to conceptually access the pgd entry that this pud is folded into
60821@@ -12,11 +17,6 @@
60822 */
60823 typedef struct { pgd_t pgd; } pud_t;
60824
60825-#define PUD_SHIFT PGDIR_SHIFT
60826-#define PTRS_PER_PUD 1
60827-#define PUD_SIZE (1UL << PUD_SHIFT)
60828-#define PUD_MASK (~(PUD_SIZE-1))
60829-
60830 /*
60831 * The "pgd_xxx()" functions here are trivial for a folded two-level
60832 * setup: the pud is never bad, and a pud always exists (as it's folded
60833@@ -29,6 +29,7 @@ static inline void pgd_clear(pgd_t *pgd) { }
60834 #define pud_ERROR(pud) (pgd_ERROR((pud).pgd))
60835
60836 #define pgd_populate(mm, pgd, pud) do { } while (0)
60837+#define pgd_populate_kernel(mm, pgd, pud) do { } while (0)
60838 /*
60839 * (puds are folded into pgds so this doesn't get actually called,
60840 * but the define is needed for a generic inline function.)
60841diff --git a/include/asm-generic/pgtable.h b/include/asm-generic/pgtable.h
60842index ff4947b..f48183f 100644
60843--- a/include/asm-generic/pgtable.h
60844+++ b/include/asm-generic/pgtable.h
60845@@ -530,6 +530,14 @@ static inline int pmd_trans_unstable(pmd_t *pmd)
60846 #endif
60847 }
60848
60849+#ifndef __HAVE_ARCH_PAX_OPEN_KERNEL
60850+static inline unsigned long pax_open_kernel(void) { return 0; }
60851+#endif
60852+
60853+#ifndef __HAVE_ARCH_PAX_CLOSE_KERNEL
60854+static inline unsigned long pax_close_kernel(void) { return 0; }
60855+#endif
60856+
60857 #endif /* CONFIG_MMU */
60858
60859 #endif /* !__ASSEMBLY__ */
60860diff --git a/include/asm-generic/vmlinux.lds.h b/include/asm-generic/vmlinux.lds.h
60861index 4e2e1cc..12c266b 100644
60862--- a/include/asm-generic/vmlinux.lds.h
60863+++ b/include/asm-generic/vmlinux.lds.h
60864@@ -218,6 +218,7 @@
60865 .rodata : AT(ADDR(.rodata) - LOAD_OFFSET) { \
60866 VMLINUX_SYMBOL(__start_rodata) = .; \
60867 *(.rodata) *(.rodata.*) \
60868+ *(.data..read_only) \
60869 *(__vermagic) /* Kernel version magic */ \
60870 . = ALIGN(8); \
60871 VMLINUX_SYMBOL(__start___tracepoints_ptrs) = .; \
60872@@ -716,17 +717,18 @@
60873 * section in the linker script will go there too. @phdr should have
60874 * a leading colon.
60875 *
60876- * Note that this macros defines __per_cpu_load as an absolute symbol.
60877+ * Note that this macros defines per_cpu_load as an absolute symbol.
60878 * If there is no need to put the percpu section at a predetermined
60879 * address, use PERCPU_SECTION.
60880 */
60881 #define PERCPU_VADDR(cacheline, vaddr, phdr) \
60882- VMLINUX_SYMBOL(__per_cpu_load) = .; \
60883- .data..percpu vaddr : AT(VMLINUX_SYMBOL(__per_cpu_load) \
60884+ per_cpu_load = .; \
60885+ .data..percpu vaddr : AT(VMLINUX_SYMBOL(per_cpu_load) \
60886 - LOAD_OFFSET) { \
60887+ VMLINUX_SYMBOL(__per_cpu_load) = . + per_cpu_load; \
60888 PERCPU_INPUT(cacheline) \
60889 } phdr \
60890- . = VMLINUX_SYMBOL(__per_cpu_load) + SIZEOF(.data..percpu);
60891+ . = VMLINUX_SYMBOL(per_cpu_load) + SIZEOF(.data..percpu);
60892
60893 /**
60894 * PERCPU_SECTION - define output section for percpu area, simple version
60895diff --git a/include/drm/drmP.h b/include/drm/drmP.h
60896index d6b67bb..a272c29 100644
60897--- a/include/drm/drmP.h
60898+++ b/include/drm/drmP.h
60899@@ -72,6 +72,7 @@
60900 #include <linux/workqueue.h>
60901 #include <linux/poll.h>
60902 #include <asm/pgalloc.h>
60903+#include <asm/local.h>
60904 #include "drm.h"
60905
60906 #include <linux/idr.h>
60907@@ -1067,7 +1068,7 @@ struct drm_device {
60908
60909 /** \name Usage Counters */
60910 /*@{ */
60911- int open_count; /**< Outstanding files open */
60912+ local_t open_count; /**< Outstanding files open */
60913 atomic_t ioctl_count; /**< Outstanding IOCTLs pending */
60914 atomic_t vma_count; /**< Outstanding vma areas open */
60915 int buf_use; /**< Buffers in use -- cannot alloc */
60916@@ -1078,7 +1079,7 @@ struct drm_device {
60917 /*@{ */
60918 unsigned long counters;
60919 enum drm_stat_type types[15];
60920- atomic_t counts[15];
60921+ atomic_unchecked_t counts[15];
60922 /*@} */
60923
60924 struct list_head filelist;
60925diff --git a/include/drm/drm_crtc_helper.h b/include/drm/drm_crtc_helper.h
60926index e01cc80..319855d 100644
60927--- a/include/drm/drm_crtc_helper.h
60928+++ b/include/drm/drm_crtc_helper.h
60929@@ -81,7 +81,7 @@ struct drm_crtc_helper_funcs {
60930
60931 /* disable crtc when not in use - more explicit than dpms off */
60932 void (*disable)(struct drm_crtc *crtc);
60933-};
60934+} __no_const;
60935
60936 /**
60937 * drm_encoder_helper_funcs - helper operations for encoders
60938@@ -109,7 +109,7 @@ struct drm_encoder_helper_funcs {
60939 struct drm_connector *connector);
60940 /* disable encoder when not in use - more explicit than dpms off */
60941 void (*disable)(struct drm_encoder *encoder);
60942-};
60943+} __no_const;
60944
60945 /**
60946 * drm_connector_helper_funcs - helper operations for connectors
60947diff --git a/include/drm/ttm/ttm_memory.h b/include/drm/ttm/ttm_memory.h
60948index d6d1da4..fdd1ac5 100644
60949--- a/include/drm/ttm/ttm_memory.h
60950+++ b/include/drm/ttm/ttm_memory.h
60951@@ -48,7 +48,7 @@
60952
60953 struct ttm_mem_shrink {
60954 int (*do_shrink) (struct ttm_mem_shrink *);
60955-};
60956+} __no_const;
60957
60958 /**
60959 * struct ttm_mem_global - Global memory accounting structure.
60960diff --git a/include/linux/a.out.h b/include/linux/a.out.h
60961index e86dfca..40cc55f 100644
60962--- a/include/linux/a.out.h
60963+++ b/include/linux/a.out.h
60964@@ -39,6 +39,14 @@ enum machine_type {
60965 M_MIPS2 = 152 /* MIPS R6000/R4000 binary */
60966 };
60967
60968+/* Constants for the N_FLAGS field */
60969+#define F_PAX_PAGEEXEC 1 /* Paging based non-executable pages */
60970+#define F_PAX_EMUTRAMP 2 /* Emulate trampolines */
60971+#define F_PAX_MPROTECT 4 /* Restrict mprotect() */
60972+#define F_PAX_RANDMMAP 8 /* Randomize mmap() base */
60973+/*#define F_PAX_RANDEXEC 16*/ /* Randomize ET_EXEC base */
60974+#define F_PAX_SEGMEXEC 32 /* Segmentation based non-executable pages */
60975+
60976 #if !defined (N_MAGIC)
60977 #define N_MAGIC(exec) ((exec).a_info & 0xffff)
60978 #endif
60979diff --git a/include/linux/atmdev.h b/include/linux/atmdev.h
60980index 06fd4bb..1caec0d 100644
60981--- a/include/linux/atmdev.h
60982+++ b/include/linux/atmdev.h
60983@@ -237,7 +237,7 @@ struct compat_atm_iobuf {
60984 #endif
60985
60986 struct k_atm_aal_stats {
60987-#define __HANDLE_ITEM(i) atomic_t i
60988+#define __HANDLE_ITEM(i) atomic_unchecked_t i
60989 __AAL_STAT_ITEMS
60990 #undef __HANDLE_ITEM
60991 };
60992diff --git a/include/linux/binfmts.h b/include/linux/binfmts.h
60993index 366422b..1fa7f84 100644
60994--- a/include/linux/binfmts.h
60995+++ b/include/linux/binfmts.h
60996@@ -89,6 +89,7 @@ struct linux_binfmt {
60997 int (*load_binary)(struct linux_binprm *, struct pt_regs * regs);
60998 int (*load_shlib)(struct file *);
60999 int (*core_dump)(struct coredump_params *cprm);
61000+ void (*handle_mprotect)(struct vm_area_struct *vma, unsigned long newflags);
61001 unsigned long min_coredump; /* minimal dump size */
61002 };
61003
61004diff --git a/include/linux/blkdev.h b/include/linux/blkdev.h
61005index 4a2ab7c..a2de7a8 100644
61006--- a/include/linux/blkdev.h
61007+++ b/include/linux/blkdev.h
61008@@ -1420,7 +1420,7 @@ struct block_device_operations {
61009 /* this callback is with swap_lock and sometimes page table lock held */
61010 void (*swap_slot_free_notify) (struct block_device *, unsigned long);
61011 struct module *owner;
61012-};
61013+} __do_const;
61014
61015 extern int __blkdev_driver_ioctl(struct block_device *, fmode_t, unsigned int,
61016 unsigned long);
61017diff --git a/include/linux/blktrace_api.h b/include/linux/blktrace_api.h
61018index 4d1a074..88f929a 100644
61019--- a/include/linux/blktrace_api.h
61020+++ b/include/linux/blktrace_api.h
61021@@ -162,7 +162,7 @@ struct blk_trace {
61022 struct dentry *dir;
61023 struct dentry *dropped_file;
61024 struct dentry *msg_file;
61025- atomic_t dropped;
61026+ atomic_unchecked_t dropped;
61027 };
61028
61029 extern int blk_trace_ioctl(struct block_device *, unsigned, char __user *);
61030diff --git a/include/linux/byteorder/little_endian.h b/include/linux/byteorder/little_endian.h
61031index 83195fb..0b0f77d 100644
61032--- a/include/linux/byteorder/little_endian.h
61033+++ b/include/linux/byteorder/little_endian.h
61034@@ -42,51 +42,51 @@
61035
61036 static inline __le64 __cpu_to_le64p(const __u64 *p)
61037 {
61038- return (__force __le64)*p;
61039+ return (__force const __le64)*p;
61040 }
61041 static inline __u64 __le64_to_cpup(const __le64 *p)
61042 {
61043- return (__force __u64)*p;
61044+ return (__force const __u64)*p;
61045 }
61046 static inline __le32 __cpu_to_le32p(const __u32 *p)
61047 {
61048- return (__force __le32)*p;
61049+ return (__force const __le32)*p;
61050 }
61051 static inline __u32 __le32_to_cpup(const __le32 *p)
61052 {
61053- return (__force __u32)*p;
61054+ return (__force const __u32)*p;
61055 }
61056 static inline __le16 __cpu_to_le16p(const __u16 *p)
61057 {
61058- return (__force __le16)*p;
61059+ return (__force const __le16)*p;
61060 }
61061 static inline __u16 __le16_to_cpup(const __le16 *p)
61062 {
61063- return (__force __u16)*p;
61064+ return (__force const __u16)*p;
61065 }
61066 static inline __be64 __cpu_to_be64p(const __u64 *p)
61067 {
61068- return (__force __be64)__swab64p(p);
61069+ return (__force const __be64)__swab64p(p);
61070 }
61071 static inline __u64 __be64_to_cpup(const __be64 *p)
61072 {
61073- return __swab64p((__u64 *)p);
61074+ return __swab64p((const __u64 *)p);
61075 }
61076 static inline __be32 __cpu_to_be32p(const __u32 *p)
61077 {
61078- return (__force __be32)__swab32p(p);
61079+ return (__force const __be32)__swab32p(p);
61080 }
61081 static inline __u32 __be32_to_cpup(const __be32 *p)
61082 {
61083- return __swab32p((__u32 *)p);
61084+ return __swab32p((const __u32 *)p);
61085 }
61086 static inline __be16 __cpu_to_be16p(const __u16 *p)
61087 {
61088- return (__force __be16)__swab16p(p);
61089+ return (__force const __be16)__swab16p(p);
61090 }
61091 static inline __u16 __be16_to_cpup(const __be16 *p)
61092 {
61093- return __swab16p((__u16 *)p);
61094+ return __swab16p((const __u16 *)p);
61095 }
61096 #define __cpu_to_le64s(x) do { (void)(x); } while (0)
61097 #define __le64_to_cpus(x) do { (void)(x); } while (0)
61098diff --git a/include/linux/cache.h b/include/linux/cache.h
61099index 4c57065..4307975 100644
61100--- a/include/linux/cache.h
61101+++ b/include/linux/cache.h
61102@@ -16,6 +16,10 @@
61103 #define __read_mostly
61104 #endif
61105
61106+#ifndef __read_only
61107+#define __read_only __read_mostly
61108+#endif
61109+
61110 #ifndef ____cacheline_aligned
61111 #define ____cacheline_aligned __attribute__((__aligned__(SMP_CACHE_BYTES)))
61112 #endif
61113diff --git a/include/linux/capability.h b/include/linux/capability.h
61114index d10b7ed..0288b79 100644
61115--- a/include/linux/capability.h
61116+++ b/include/linux/capability.h
61117@@ -553,10 +553,15 @@ extern bool capable(int cap);
61118 extern bool ns_capable(struct user_namespace *ns, int cap);
61119 extern bool nsown_capable(int cap);
61120 extern bool inode_capable(const struct inode *inode, int cap);
61121+extern bool capable_nolog(int cap);
61122+extern bool ns_capable_nolog(struct user_namespace *ns, int cap);
61123+extern bool inode_capable_nolog(const struct inode *inode, int cap);
61124
61125 /* audit system wants to get cap info from files as well */
61126 extern int get_vfs_caps_from_disk(const struct dentry *dentry, struct cpu_vfs_cap_data *cpu_caps);
61127
61128+extern int is_privileged_binary(const struct dentry *dentry);
61129+
61130 #endif /* __KERNEL__ */
61131
61132 #endif /* !_LINUX_CAPABILITY_H */
61133diff --git a/include/linux/cleancache.h b/include/linux/cleancache.h
61134index 42e55de..1cd0e66 100644
61135--- a/include/linux/cleancache.h
61136+++ b/include/linux/cleancache.h
61137@@ -31,7 +31,7 @@ struct cleancache_ops {
61138 void (*invalidate_page)(int, struct cleancache_filekey, pgoff_t);
61139 void (*invalidate_inode)(int, struct cleancache_filekey);
61140 void (*invalidate_fs)(int);
61141-};
61142+} __no_const;
61143
61144 extern struct cleancache_ops
61145 cleancache_register_ops(struct cleancache_ops *ops);
61146diff --git a/include/linux/clk-provider.h b/include/linux/clk-provider.h
61147index 77335fa..6cbe7dd 100644
61148--- a/include/linux/clk-provider.h
61149+++ b/include/linux/clk-provider.h
61150@@ -111,6 +111,7 @@ struct clk_ops {
61151 unsigned long);
61152 void (*init)(struct clk_hw *hw);
61153 };
61154+typedef struct clk_ops __no_const clk_ops_no_const;
61155
61156 /**
61157 * struct clk_init_data - holds init data that's common to all clocks and is
61158diff --git a/include/linux/compiler-gcc4.h b/include/linux/compiler-gcc4.h
61159index 934bc34..1b47129 100644
61160--- a/include/linux/compiler-gcc4.h
61161+++ b/include/linux/compiler-gcc4.h
61162@@ -32,6 +32,21 @@
61163 #define __linktime_error(message) __attribute__((__error__(message)))
61164
61165 #if __GNUC_MINOR__ >= 5
61166+
61167+#ifdef CONSTIFY_PLUGIN
61168+#define __no_const __attribute__((no_const))
61169+#define __do_const __attribute__((do_const))
61170+#endif
61171+
61172+#ifdef SIZE_OVERFLOW_PLUGIN
61173+#define __size_overflow(...) __attribute__((size_overflow(__VA_ARGS__)))
61174+#define __intentional_overflow(...) __attribute__((intentional_overflow(__VA_ARGS__)))
61175+#endif
61176+
61177+#ifdef LATENT_ENTROPY_PLUGIN
61178+#define __latent_entropy __attribute__((latent_entropy))
61179+#endif
61180+
61181 /*
61182 * Mark a position in code as unreachable. This can be used to
61183 * suppress control flow warnings after asm blocks that transfer
61184@@ -47,6 +62,11 @@
61185 #define __noclone __attribute__((__noclone__))
61186
61187 #endif
61188+
61189+#define __alloc_size(...) __attribute((alloc_size(__VA_ARGS__)))
61190+#define __bos(ptr, arg) __builtin_object_size((ptr), (arg))
61191+#define __bos0(ptr) __bos((ptr), 0)
61192+#define __bos1(ptr) __bos((ptr), 1)
61193 #endif
61194
61195 #if __GNUC_MINOR__ >= 6
61196diff --git a/include/linux/compiler.h b/include/linux/compiler.h
61197index f430e41..38be90f 100644
61198--- a/include/linux/compiler.h
61199+++ b/include/linux/compiler.h
61200@@ -5,31 +5,62 @@
61201
61202 #ifdef __CHECKER__
61203 # define __user __attribute__((noderef, address_space(1)))
61204+# define __force_user __force __user
61205 # define __kernel __attribute__((address_space(0)))
61206+# define __force_kernel __force __kernel
61207 # define __safe __attribute__((safe))
61208 # define __force __attribute__((force))
61209 # define __nocast __attribute__((nocast))
61210 # define __iomem __attribute__((noderef, address_space(2)))
61211+# define __force_iomem __force __iomem
61212 # define __acquires(x) __attribute__((context(x,0,1)))
61213 # define __releases(x) __attribute__((context(x,1,0)))
61214 # define __acquire(x) __context__(x,1)
61215 # define __release(x) __context__(x,-1)
61216 # define __cond_lock(x,c) ((c) ? ({ __acquire(x); 1; }) : 0)
61217 # define __percpu __attribute__((noderef, address_space(3)))
61218+# define __force_percpu __force __percpu
61219 #ifdef CONFIG_SPARSE_RCU_POINTER
61220 # define __rcu __attribute__((noderef, address_space(4)))
61221+# define __force_rcu __force __rcu
61222 #else
61223 # define __rcu
61224+# define __force_rcu
61225 #endif
61226 extern void __chk_user_ptr(const volatile void __user *);
61227 extern void __chk_io_ptr(const volatile void __iomem *);
61228+#elif defined(CHECKER_PLUGIN)
61229+//# define __user
61230+//# define __force_user
61231+//# define __kernel
61232+//# define __force_kernel
61233+# define __safe
61234+# define __force
61235+# define __nocast
61236+# define __iomem
61237+# define __force_iomem
61238+# define __chk_user_ptr(x) (void)0
61239+# define __chk_io_ptr(x) (void)0
61240+# define __builtin_warning(x, y...) (1)
61241+# define __acquires(x)
61242+# define __releases(x)
61243+# define __acquire(x) (void)0
61244+# define __release(x) (void)0
61245+# define __cond_lock(x,c) (c)
61246+# define __percpu
61247+# define __force_percpu
61248+# define __rcu
61249+# define __force_rcu
61250 #else
61251 # define __user
61252+# define __force_user
61253 # define __kernel
61254+# define __force_kernel
61255 # define __safe
61256 # define __force
61257 # define __nocast
61258 # define __iomem
61259+# define __force_iomem
61260 # define __chk_user_ptr(x) (void)0
61261 # define __chk_io_ptr(x) (void)0
61262 # define __builtin_warning(x, y...) (1)
61263@@ -39,7 +70,9 @@ extern void __chk_io_ptr(const volatile void __iomem *);
61264 # define __release(x) (void)0
61265 # define __cond_lock(x,c) (c)
61266 # define __percpu
61267+# define __force_percpu
61268 # define __rcu
61269+# define __force_rcu
61270 #endif
61271
61272 #ifdef __KERNEL__
61273@@ -264,6 +297,26 @@ void ftrace_likely_update(struct ftrace_branch_data *f, int val, int expect);
61274 # define __attribute_const__ /* unimplemented */
61275 #endif
61276
61277+#ifndef __no_const
61278+# define __no_const
61279+#endif
61280+
61281+#ifndef __do_const
61282+# define __do_const
61283+#endif
61284+
61285+#ifndef __size_overflow
61286+# define __size_overflow(...)
61287+#endif
61288+
61289+#ifndef __intentional_overflow
61290+# define __intentional_overflow(...)
61291+#endif
61292+
61293+#ifndef __latent_entropy
61294+# define __latent_entropy
61295+#endif
61296+
61297 /*
61298 * Tell gcc if a function is cold. The compiler will assume any path
61299 * directly leading to the call is unlikely.
61300@@ -273,6 +326,22 @@ void ftrace_likely_update(struct ftrace_branch_data *f, int val, int expect);
61301 #define __cold
61302 #endif
61303
61304+#ifndef __alloc_size
61305+#define __alloc_size(...)
61306+#endif
61307+
61308+#ifndef __bos
61309+#define __bos(ptr, arg)
61310+#endif
61311+
61312+#ifndef __bos0
61313+#define __bos0(ptr)
61314+#endif
61315+
61316+#ifndef __bos1
61317+#define __bos1(ptr)
61318+#endif
61319+
61320 /* Simple shorthand for a section definition */
61321 #ifndef __section
61322 # define __section(S) __attribute__ ((__section__(#S)))
61323@@ -312,6 +381,7 @@ void ftrace_likely_update(struct ftrace_branch_data *f, int val, int expect);
61324 * use is to mediate communication between process-level code and irq/NMI
61325 * handlers, all running on the same CPU.
61326 */
61327-#define ACCESS_ONCE(x) (*(volatile typeof(x) *)&(x))
61328+#define ACCESS_ONCE(x) (*(volatile const typeof(x) *)&(x))
61329+#define ACCESS_ONCE_RW(x) (*(volatile typeof(x) *)&(x))
61330
61331 #endif /* __LINUX_COMPILER_H */
61332diff --git a/include/linux/cred.h b/include/linux/cred.h
61333index ebbed2c..908cc2c 100644
61334--- a/include/linux/cred.h
61335+++ b/include/linux/cred.h
61336@@ -208,6 +208,9 @@ static inline void validate_creds_for_do_exit(struct task_struct *tsk)
61337 static inline void validate_process_creds(void)
61338 {
61339 }
61340+static inline void validate_task_creds(struct task_struct *task)
61341+{
61342+}
61343 #endif
61344
61345 /**
61346diff --git a/include/linux/crypto.h b/include/linux/crypto.h
61347index b92eadf..b4ecdc1 100644
61348--- a/include/linux/crypto.h
61349+++ b/include/linux/crypto.h
61350@@ -373,7 +373,7 @@ struct cipher_tfm {
61351 const u8 *key, unsigned int keylen);
61352 void (*cit_encrypt_one)(struct crypto_tfm *tfm, u8 *dst, const u8 *src);
61353 void (*cit_decrypt_one)(struct crypto_tfm *tfm, u8 *dst, const u8 *src);
61354-};
61355+} __no_const;
61356
61357 struct hash_tfm {
61358 int (*init)(struct hash_desc *desc);
61359@@ -394,13 +394,13 @@ struct compress_tfm {
61360 int (*cot_decompress)(struct crypto_tfm *tfm,
61361 const u8 *src, unsigned int slen,
61362 u8 *dst, unsigned int *dlen);
61363-};
61364+} __no_const;
61365
61366 struct rng_tfm {
61367 int (*rng_gen_random)(struct crypto_rng *tfm, u8 *rdata,
61368 unsigned int dlen);
61369 int (*rng_reset)(struct crypto_rng *tfm, u8 *seed, unsigned int slen);
61370-};
61371+} __no_const;
61372
61373 #define crt_ablkcipher crt_u.ablkcipher
61374 #define crt_aead crt_u.aead
61375diff --git a/include/linux/decompress/mm.h b/include/linux/decompress/mm.h
61376index 7925bf0..d5143d2 100644
61377--- a/include/linux/decompress/mm.h
61378+++ b/include/linux/decompress/mm.h
61379@@ -77,7 +77,7 @@ static void free(void *where)
61380 * warnings when not needed (indeed large_malloc / large_free are not
61381 * needed by inflate */
61382
61383-#define malloc(a) kmalloc(a, GFP_KERNEL)
61384+#define malloc(a) kmalloc((a), GFP_KERNEL)
61385 #define free(a) kfree(a)
61386
61387 #define large_malloc(a) vmalloc(a)
61388diff --git a/include/linux/dma-mapping.h b/include/linux/dma-mapping.h
61389index 94af418..b1ca7a2 100644
61390--- a/include/linux/dma-mapping.h
61391+++ b/include/linux/dma-mapping.h
61392@@ -54,7 +54,7 @@ struct dma_map_ops {
61393 u64 (*get_required_mask)(struct device *dev);
61394 #endif
61395 int is_phys;
61396-};
61397+} __do_const;
61398
61399 #define DMA_BIT_MASK(n) (((n) == 64) ? ~0ULL : ((1ULL<<(n))-1))
61400
61401diff --git a/include/linux/dmaengine.h b/include/linux/dmaengine.h
61402index 9c02a45..89fdd73 100644
61403--- a/include/linux/dmaengine.h
61404+++ b/include/linux/dmaengine.h
61405@@ -1017,9 +1017,9 @@ struct dma_pinned_list {
61406 struct dma_pinned_list *dma_pin_iovec_pages(struct iovec *iov, size_t len);
61407 void dma_unpin_iovec_pages(struct dma_pinned_list* pinned_list);
61408
61409-dma_cookie_t dma_memcpy_to_iovec(struct dma_chan *chan, struct iovec *iov,
61410+dma_cookie_t __intentional_overflow(0) dma_memcpy_to_iovec(struct dma_chan *chan, struct iovec *iov,
61411 struct dma_pinned_list *pinned_list, unsigned char *kdata, size_t len);
61412-dma_cookie_t dma_memcpy_pg_to_iovec(struct dma_chan *chan, struct iovec *iov,
61413+dma_cookie_t __intentional_overflow(0) dma_memcpy_pg_to_iovec(struct dma_chan *chan, struct iovec *iov,
61414 struct dma_pinned_list *pinned_list, struct page *page,
61415 unsigned int offset, size_t len);
61416
61417diff --git a/include/linux/efi.h b/include/linux/efi.h
61418index ec45ccd..9923c32 100644
61419--- a/include/linux/efi.h
61420+++ b/include/linux/efi.h
61421@@ -635,7 +635,7 @@ struct efivar_operations {
61422 efi_get_variable_t *get_variable;
61423 efi_get_next_variable_t *get_next_variable;
61424 efi_set_variable_t *set_variable;
61425-};
61426+} __no_const;
61427
61428 struct efivars {
61429 /*
61430diff --git a/include/linux/elf.h b/include/linux/elf.h
61431index 999b4f5..57753b4 100644
61432--- a/include/linux/elf.h
61433+++ b/include/linux/elf.h
61434@@ -40,6 +40,17 @@ typedef __s64 Elf64_Sxword;
61435 #define PT_GNU_EH_FRAME 0x6474e550
61436
61437 #define PT_GNU_STACK (PT_LOOS + 0x474e551)
61438+#define PT_GNU_RELRO (PT_LOOS + 0x474e552)
61439+
61440+#define PT_PAX_FLAGS (PT_LOOS + 0x5041580)
61441+
61442+/* Constants for the e_flags field */
61443+#define EF_PAX_PAGEEXEC 1 /* Paging based non-executable pages */
61444+#define EF_PAX_EMUTRAMP 2 /* Emulate trampolines */
61445+#define EF_PAX_MPROTECT 4 /* Restrict mprotect() */
61446+#define EF_PAX_RANDMMAP 8 /* Randomize mmap() base */
61447+/*#define EF_PAX_RANDEXEC 16*/ /* Randomize ET_EXEC base */
61448+#define EF_PAX_SEGMEXEC 32 /* Segmentation based non-executable pages */
61449
61450 /*
61451 * Extended Numbering
61452@@ -97,6 +108,8 @@ typedef __s64 Elf64_Sxword;
61453 #define DT_DEBUG 21
61454 #define DT_TEXTREL 22
61455 #define DT_JMPREL 23
61456+#define DT_FLAGS 30
61457+ #define DF_TEXTREL 0x00000004
61458 #define DT_ENCODING 32
61459 #define OLD_DT_LOOS 0x60000000
61460 #define DT_LOOS 0x6000000d
61461@@ -243,6 +256,19 @@ typedef struct elf64_hdr {
61462 #define PF_W 0x2
61463 #define PF_X 0x1
61464
61465+#define PF_PAGEEXEC (1U << 4) /* Enable PAGEEXEC */
61466+#define PF_NOPAGEEXEC (1U << 5) /* Disable PAGEEXEC */
61467+#define PF_SEGMEXEC (1U << 6) /* Enable SEGMEXEC */
61468+#define PF_NOSEGMEXEC (1U << 7) /* Disable SEGMEXEC */
61469+#define PF_MPROTECT (1U << 8) /* Enable MPROTECT */
61470+#define PF_NOMPROTECT (1U << 9) /* Disable MPROTECT */
61471+/*#define PF_RANDEXEC (1U << 10)*/ /* Enable RANDEXEC */
61472+/*#define PF_NORANDEXEC (1U << 11)*/ /* Disable RANDEXEC */
61473+#define PF_EMUTRAMP (1U << 12) /* Enable EMUTRAMP */
61474+#define PF_NOEMUTRAMP (1U << 13) /* Disable EMUTRAMP */
61475+#define PF_RANDMMAP (1U << 14) /* Enable RANDMMAP */
61476+#define PF_NORANDMMAP (1U << 15) /* Disable RANDMMAP */
61477+
61478 typedef struct elf32_phdr{
61479 Elf32_Word p_type;
61480 Elf32_Off p_offset;
61481@@ -335,6 +361,8 @@ typedef struct elf64_shdr {
61482 #define EI_OSABI 7
61483 #define EI_PAD 8
61484
61485+#define EI_PAX 14
61486+
61487 #define ELFMAG0 0x7f /* EI_MAG */
61488 #define ELFMAG1 'E'
61489 #define ELFMAG2 'L'
61490@@ -421,6 +449,7 @@ extern Elf32_Dyn _DYNAMIC [];
61491 #define elf_note elf32_note
61492 #define elf_addr_t Elf32_Off
61493 #define Elf_Half Elf32_Half
61494+#define elf_dyn Elf32_Dyn
61495
61496 #else
61497
61498@@ -431,6 +460,7 @@ extern Elf64_Dyn _DYNAMIC [];
61499 #define elf_note elf64_note
61500 #define elf_addr_t Elf64_Off
61501 #define Elf_Half Elf64_Half
61502+#define elf_dyn Elf64_Dyn
61503
61504 #endif
61505
61506diff --git a/include/linux/filter.h b/include/linux/filter.h
61507index 82b0135..917914d 100644
61508--- a/include/linux/filter.h
61509+++ b/include/linux/filter.h
61510@@ -146,6 +146,7 @@ struct compat_sock_fprog {
61511
61512 struct sk_buff;
61513 struct sock;
61514+struct bpf_jit_work;
61515
61516 struct sk_filter
61517 {
61518@@ -153,6 +154,9 @@ struct sk_filter
61519 unsigned int len; /* Number of filter blocks */
61520 unsigned int (*bpf_func)(const struct sk_buff *skb,
61521 const struct sock_filter *filter);
61522+#ifdef CONFIG_BPF_JIT
61523+ struct bpf_jit_work *work;
61524+#endif
61525 struct rcu_head rcu;
61526 struct sock_filter insns[0];
61527 };
61528diff --git a/include/linux/firewire.h b/include/linux/firewire.h
61529index db04ec5..f6ed627 100644
61530--- a/include/linux/firewire.h
61531+++ b/include/linux/firewire.h
61532@@ -430,7 +430,7 @@ struct fw_iso_context {
61533 union {
61534 fw_iso_callback_t sc;
61535 fw_iso_mc_callback_t mc;
61536- } callback;
61537+ } __no_const callback;
61538 void *callback_data;
61539 };
61540
61541diff --git a/include/linux/frontswap.h b/include/linux/frontswap.h
61542index 0e4e2ee..4ff4312 100644
61543--- a/include/linux/frontswap.h
61544+++ b/include/linux/frontswap.h
61545@@ -11,7 +11,7 @@ struct frontswap_ops {
61546 int (*load)(unsigned, pgoff_t, struct page *);
61547 void (*invalidate_page)(unsigned, pgoff_t);
61548 void (*invalidate_area)(unsigned);
61549-};
61550+} __no_const;
61551
61552 extern bool frontswap_enabled;
61553 extern struct frontswap_ops
61554diff --git a/include/linux/fs.h b/include/linux/fs.h
61555index aa11047..7d046d0 100644
61556--- a/include/linux/fs.h
61557+++ b/include/linux/fs.h
61558@@ -1802,7 +1802,8 @@ struct file_operations {
61559 int (*setlease)(struct file *, long, struct file_lock **);
61560 long (*fallocate)(struct file *file, int mode, loff_t offset,
61561 loff_t len);
61562-};
61563+} __do_const;
61564+typedef struct file_operations __no_const file_operations_no_const;
61565
61566 struct inode_operations {
61567 struct dentry * (*lookup) (struct inode *,struct dentry *, unsigned int);
61568diff --git a/include/linux/fs_struct.h b/include/linux/fs_struct.h
61569index 003dc0f..3c4ea97 100644
61570--- a/include/linux/fs_struct.h
61571+++ b/include/linux/fs_struct.h
61572@@ -6,7 +6,7 @@
61573 #include <linux/seqlock.h>
61574
61575 struct fs_struct {
61576- int users;
61577+ atomic_t users;
61578 spinlock_t lock;
61579 seqcount_t seq;
61580 int umask;
61581diff --git a/include/linux/fscache-cache.h b/include/linux/fscache-cache.h
61582index ce31408..b1ad003 100644
61583--- a/include/linux/fscache-cache.h
61584+++ b/include/linux/fscache-cache.h
61585@@ -102,7 +102,7 @@ struct fscache_operation {
61586 fscache_operation_release_t release;
61587 };
61588
61589-extern atomic_t fscache_op_debug_id;
61590+extern atomic_unchecked_t fscache_op_debug_id;
61591 extern void fscache_op_work_func(struct work_struct *work);
61592
61593 extern void fscache_enqueue_operation(struct fscache_operation *);
61594@@ -122,7 +122,7 @@ static inline void fscache_operation_init(struct fscache_operation *op,
61595 {
61596 INIT_WORK(&op->work, fscache_op_work_func);
61597 atomic_set(&op->usage, 1);
61598- op->debug_id = atomic_inc_return(&fscache_op_debug_id);
61599+ op->debug_id = atomic_inc_return_unchecked(&fscache_op_debug_id);
61600 op->processor = processor;
61601 op->release = release;
61602 INIT_LIST_HEAD(&op->pend_link);
61603diff --git a/include/linux/fsnotify.h b/include/linux/fsnotify.h
61604index a6dfe69..569586df 100644
61605--- a/include/linux/fsnotify.h
61606+++ b/include/linux/fsnotify.h
61607@@ -315,7 +315,7 @@ static inline void fsnotify_change(struct dentry *dentry, unsigned int ia_valid)
61608 */
61609 static inline const unsigned char *fsnotify_oldname_init(const unsigned char *name)
61610 {
61611- return kstrdup(name, GFP_KERNEL);
61612+ return (const unsigned char *)kstrdup((const char *)name, GFP_KERNEL);
61613 }
61614
61615 /*
61616diff --git a/include/linux/fsnotify_backend.h b/include/linux/fsnotify_backend.h
61617index 63d966d..cdcb717 100644
61618--- a/include/linux/fsnotify_backend.h
61619+++ b/include/linux/fsnotify_backend.h
61620@@ -105,6 +105,7 @@ struct fsnotify_ops {
61621 void (*freeing_mark)(struct fsnotify_mark *mark, struct fsnotify_group *group);
61622 void (*free_event_priv)(struct fsnotify_event_private_data *priv);
61623 };
61624+typedef struct fsnotify_ops __no_const fsnotify_ops_no_const;
61625
61626 /*
61627 * A group is a "thing" that wants to receive notification about filesystem
61628diff --git a/include/linux/ftrace_event.h b/include/linux/ftrace_event.h
61629index 642928c..e6c83a7 100644
61630--- a/include/linux/ftrace_event.h
61631+++ b/include/linux/ftrace_event.h
61632@@ -97,7 +97,7 @@ struct trace_event_functions {
61633 trace_print_func raw;
61634 trace_print_func hex;
61635 trace_print_func binary;
61636-};
61637+} __no_const;
61638
61639 struct trace_event {
61640 struct hlist_node node;
61641@@ -266,7 +266,7 @@ extern int trace_define_field(struct ftrace_event_call *call, const char *type,
61642 extern int trace_add_event_call(struct ftrace_event_call *call);
61643 extern void trace_remove_event_call(struct ftrace_event_call *call);
61644
61645-#define is_signed_type(type) (((type)(-1)) < 0)
61646+#define is_signed_type(type) (((type)(-1)) < (type)1)
61647
61648 int trace_set_clr_event(const char *system, const char *event, int set);
61649
61650diff --git a/include/linux/genhd.h b/include/linux/genhd.h
61651index 4f440b3..342233a 100644
61652--- a/include/linux/genhd.h
61653+++ b/include/linux/genhd.h
61654@@ -190,7 +190,7 @@ struct gendisk {
61655 struct kobject *slave_dir;
61656
61657 struct timer_rand_state *random;
61658- atomic_t sync_io; /* RAID */
61659+ atomic_unchecked_t sync_io; /* RAID */
61660 struct disk_events *ev;
61661 #ifdef CONFIG_BLK_DEV_INTEGRITY
61662 struct blk_integrity *integrity;
61663diff --git a/include/linux/gfp.h b/include/linux/gfp.h
61664index 4883f39..26688a8 100644
61665--- a/include/linux/gfp.h
61666+++ b/include/linux/gfp.h
61667@@ -39,6 +39,12 @@ struct vm_area_struct;
61668 #define ___GFP_OTHER_NODE 0x800000u
61669 #define ___GFP_WRITE 0x1000000u
61670
61671+#ifdef CONFIG_PAX_USERCOPY_SLABS
61672+#define ___GFP_USERCOPY 0x2000000u
61673+#else
61674+#define ___GFP_USERCOPY 0
61675+#endif
61676+
61677 /*
61678 * GFP bitmasks..
61679 *
61680@@ -93,6 +99,7 @@ struct vm_area_struct;
61681 #define __GFP_NO_KSWAPD ((__force gfp_t)___GFP_NO_KSWAPD)
61682 #define __GFP_OTHER_NODE ((__force gfp_t)___GFP_OTHER_NODE) /* On behalf of other node */
61683 #define __GFP_WRITE ((__force gfp_t)___GFP_WRITE) /* Allocator intends to dirty page */
61684+#define __GFP_USERCOPY ((__force gfp_t)___GFP_USERCOPY)/* Allocator intends to copy page to/from userland */
61685
61686 /*
61687 * This may seem redundant, but it's a way of annotating false positives vs.
61688@@ -100,7 +107,7 @@ struct vm_area_struct;
61689 */
61690 #define __GFP_NOTRACK_FALSE_POSITIVE (__GFP_NOTRACK)
61691
61692-#define __GFP_BITS_SHIFT 25 /* Room for N __GFP_FOO bits */
61693+#define __GFP_BITS_SHIFT 26 /* Room for N __GFP_FOO bits */
61694 #define __GFP_BITS_MASK ((__force gfp_t)((1 << __GFP_BITS_SHIFT) - 1))
61695
61696 /* This equals 0, but use constants in case they ever change */
61697@@ -154,6 +161,8 @@ struct vm_area_struct;
61698 /* 4GB DMA on some platforms */
61699 #define GFP_DMA32 __GFP_DMA32
61700
61701+#define GFP_USERCOPY __GFP_USERCOPY
61702+
61703 /* Convert GFP flags to their corresponding migrate type */
61704 static inline int allocflags_to_migratetype(gfp_t gfp_flags)
61705 {
61706diff --git a/include/linux/gracl.h b/include/linux/gracl.h
61707new file mode 100644
61708index 0000000..c938b1f
61709--- /dev/null
61710+++ b/include/linux/gracl.h
61711@@ -0,0 +1,319 @@
61712+#ifndef GR_ACL_H
61713+#define GR_ACL_H
61714+
61715+#include <linux/grdefs.h>
61716+#include <linux/resource.h>
61717+#include <linux/capability.h>
61718+#include <linux/dcache.h>
61719+#include <asm/resource.h>
61720+
61721+/* Major status information */
61722+
61723+#define GR_VERSION "grsecurity 2.9.1"
61724+#define GRSECURITY_VERSION 0x2901
61725+
61726+enum {
61727+ GR_SHUTDOWN = 0,
61728+ GR_ENABLE = 1,
61729+ GR_SPROLE = 2,
61730+ GR_RELOAD = 3,
61731+ GR_SEGVMOD = 4,
61732+ GR_STATUS = 5,
61733+ GR_UNSPROLE = 6,
61734+ GR_PASSSET = 7,
61735+ GR_SPROLEPAM = 8,
61736+};
61737+
61738+/* Password setup definitions
61739+ * kernel/grhash.c */
61740+enum {
61741+ GR_PW_LEN = 128,
61742+ GR_SALT_LEN = 16,
61743+ GR_SHA_LEN = 32,
61744+};
61745+
61746+enum {
61747+ GR_SPROLE_LEN = 64,
61748+};
61749+
61750+enum {
61751+ GR_NO_GLOB = 0,
61752+ GR_REG_GLOB,
61753+ GR_CREATE_GLOB
61754+};
61755+
61756+#define GR_NLIMITS 32
61757+
61758+/* Begin Data Structures */
61759+
61760+struct sprole_pw {
61761+ unsigned char *rolename;
61762+ unsigned char salt[GR_SALT_LEN];
61763+ unsigned char sum[GR_SHA_LEN]; /* 256-bit SHA hash of the password */
61764+};
61765+
61766+struct name_entry {
61767+ __u32 key;
61768+ ino_t inode;
61769+ dev_t device;
61770+ char *name;
61771+ __u16 len;
61772+ __u8 deleted;
61773+ struct name_entry *prev;
61774+ struct name_entry *next;
61775+};
61776+
61777+struct inodev_entry {
61778+ struct name_entry *nentry;
61779+ struct inodev_entry *prev;
61780+ struct inodev_entry *next;
61781+};
61782+
61783+struct acl_role_db {
61784+ struct acl_role_label **r_hash;
61785+ __u32 r_size;
61786+};
61787+
61788+struct inodev_db {
61789+ struct inodev_entry **i_hash;
61790+ __u32 i_size;
61791+};
61792+
61793+struct name_db {
61794+ struct name_entry **n_hash;
61795+ __u32 n_size;
61796+};
61797+
61798+struct crash_uid {
61799+ uid_t uid;
61800+ unsigned long expires;
61801+};
61802+
61803+struct gr_hash_struct {
61804+ void **table;
61805+ void **nametable;
61806+ void *first;
61807+ __u32 table_size;
61808+ __u32 used_size;
61809+ int type;
61810+};
61811+
61812+/* Userspace Grsecurity ACL data structures */
61813+
61814+struct acl_subject_label {
61815+ char *filename;
61816+ ino_t inode;
61817+ dev_t device;
61818+ __u32 mode;
61819+ kernel_cap_t cap_mask;
61820+ kernel_cap_t cap_lower;
61821+ kernel_cap_t cap_invert_audit;
61822+
61823+ struct rlimit res[GR_NLIMITS];
61824+ __u32 resmask;
61825+
61826+ __u8 user_trans_type;
61827+ __u8 group_trans_type;
61828+ uid_t *user_transitions;
61829+ gid_t *group_transitions;
61830+ __u16 user_trans_num;
61831+ __u16 group_trans_num;
61832+
61833+ __u32 sock_families[2];
61834+ __u32 ip_proto[8];
61835+ __u32 ip_type;
61836+ struct acl_ip_label **ips;
61837+ __u32 ip_num;
61838+ __u32 inaddr_any_override;
61839+
61840+ __u32 crashes;
61841+ unsigned long expires;
61842+
61843+ struct acl_subject_label *parent_subject;
61844+ struct gr_hash_struct *hash;
61845+ struct acl_subject_label *prev;
61846+ struct acl_subject_label *next;
61847+
61848+ struct acl_object_label **obj_hash;
61849+ __u32 obj_hash_size;
61850+ __u16 pax_flags;
61851+};
61852+
61853+struct role_allowed_ip {
61854+ __u32 addr;
61855+ __u32 netmask;
61856+
61857+ struct role_allowed_ip *prev;
61858+ struct role_allowed_ip *next;
61859+};
61860+
61861+struct role_transition {
61862+ char *rolename;
61863+
61864+ struct role_transition *prev;
61865+ struct role_transition *next;
61866+};
61867+
61868+struct acl_role_label {
61869+ char *rolename;
61870+ uid_t uidgid;
61871+ __u16 roletype;
61872+
61873+ __u16 auth_attempts;
61874+ unsigned long expires;
61875+
61876+ struct acl_subject_label *root_label;
61877+ struct gr_hash_struct *hash;
61878+
61879+ struct acl_role_label *prev;
61880+ struct acl_role_label *next;
61881+
61882+ struct role_transition *transitions;
61883+ struct role_allowed_ip *allowed_ips;
61884+ uid_t *domain_children;
61885+ __u16 domain_child_num;
61886+
61887+ umode_t umask;
61888+
61889+ struct acl_subject_label **subj_hash;
61890+ __u32 subj_hash_size;
61891+};
61892+
61893+struct user_acl_role_db {
61894+ struct acl_role_label **r_table;
61895+ __u32 num_pointers; /* Number of allocations to track */
61896+ __u32 num_roles; /* Number of roles */
61897+ __u32 num_domain_children; /* Number of domain children */
61898+ __u32 num_subjects; /* Number of subjects */
61899+ __u32 num_objects; /* Number of objects */
61900+};
61901+
61902+struct acl_object_label {
61903+ char *filename;
61904+ ino_t inode;
61905+ dev_t device;
61906+ __u32 mode;
61907+
61908+ struct acl_subject_label *nested;
61909+ struct acl_object_label *globbed;
61910+
61911+ /* next two structures not used */
61912+
61913+ struct acl_object_label *prev;
61914+ struct acl_object_label *next;
61915+};
61916+
61917+struct acl_ip_label {
61918+ char *iface;
61919+ __u32 addr;
61920+ __u32 netmask;
61921+ __u16 low, high;
61922+ __u8 mode;
61923+ __u32 type;
61924+ __u32 proto[8];
61925+
61926+ /* next two structures not used */
61927+
61928+ struct acl_ip_label *prev;
61929+ struct acl_ip_label *next;
61930+};
61931+
61932+struct gr_arg {
61933+ struct user_acl_role_db role_db;
61934+ unsigned char pw[GR_PW_LEN];
61935+ unsigned char salt[GR_SALT_LEN];
61936+ unsigned char sum[GR_SHA_LEN];
61937+ unsigned char sp_role[GR_SPROLE_LEN];
61938+ struct sprole_pw *sprole_pws;
61939+ dev_t segv_device;
61940+ ino_t segv_inode;
61941+ uid_t segv_uid;
61942+ __u16 num_sprole_pws;
61943+ __u16 mode;
61944+};
61945+
61946+struct gr_arg_wrapper {
61947+ struct gr_arg *arg;
61948+ __u32 version;
61949+ __u32 size;
61950+};
61951+
61952+struct subject_map {
61953+ struct acl_subject_label *user;
61954+ struct acl_subject_label *kernel;
61955+ struct subject_map *prev;
61956+ struct subject_map *next;
61957+};
61958+
61959+struct acl_subj_map_db {
61960+ struct subject_map **s_hash;
61961+ __u32 s_size;
61962+};
61963+
61964+/* End Data Structures Section */
61965+
61966+/* Hash functions generated by empirical testing by Brad Spengler
61967+ Makes good use of the low bits of the inode. Generally 0-1 times
61968+ in loop for successful match. 0-3 for unsuccessful match.
61969+ Shift/add algorithm with modulus of table size and an XOR*/
61970+
61971+static __inline__ unsigned int
61972+rhash(const uid_t uid, const __u16 type, const unsigned int sz)
61973+{
61974+ return ((((uid + type) << (16 + type)) ^ uid) % sz);
61975+}
61976+
61977+ static __inline__ unsigned int
61978+shash(const struct acl_subject_label *userp, const unsigned int sz)
61979+{
61980+ return ((const unsigned long)userp % sz);
61981+}
61982+
61983+static __inline__ unsigned int
61984+fhash(const ino_t ino, const dev_t dev, const unsigned int sz)
61985+{
61986+ return (((ino + dev) ^ ((ino << 13) + (ino << 23) + (dev << 9))) % sz);
61987+}
61988+
61989+static __inline__ unsigned int
61990+nhash(const char *name, const __u16 len, const unsigned int sz)
61991+{
61992+ return full_name_hash((const unsigned char *)name, len) % sz;
61993+}
61994+
61995+#define FOR_EACH_ROLE_START(role) \
61996+ role = role_list; \
61997+ while (role) {
61998+
61999+#define FOR_EACH_ROLE_END(role) \
62000+ role = role->prev; \
62001+ }
62002+
62003+#define FOR_EACH_SUBJECT_START(role,subj,iter) \
62004+ subj = NULL; \
62005+ iter = 0; \
62006+ while (iter < role->subj_hash_size) { \
62007+ if (subj == NULL) \
62008+ subj = role->subj_hash[iter]; \
62009+ if (subj == NULL) { \
62010+ iter++; \
62011+ continue; \
62012+ }
62013+
62014+#define FOR_EACH_SUBJECT_END(subj,iter) \
62015+ subj = subj->next; \
62016+ if (subj == NULL) \
62017+ iter++; \
62018+ }
62019+
62020+
62021+#define FOR_EACH_NESTED_SUBJECT_START(role,subj) \
62022+ subj = role->hash->first; \
62023+ while (subj != NULL) {
62024+
62025+#define FOR_EACH_NESTED_SUBJECT_END(subj) \
62026+ subj = subj->next; \
62027+ }
62028+
62029+#endif
62030+
62031diff --git a/include/linux/gralloc.h b/include/linux/gralloc.h
62032new file mode 100644
62033index 0000000..323ecf2
62034--- /dev/null
62035+++ b/include/linux/gralloc.h
62036@@ -0,0 +1,9 @@
62037+#ifndef __GRALLOC_H
62038+#define __GRALLOC_H
62039+
62040+void acl_free_all(void);
62041+int acl_alloc_stack_init(unsigned long size);
62042+void *acl_alloc(unsigned long len);
62043+void *acl_alloc_num(unsigned long num, unsigned long len);
62044+
62045+#endif
62046diff --git a/include/linux/grdefs.h b/include/linux/grdefs.h
62047new file mode 100644
62048index 0000000..b30e9bc
62049--- /dev/null
62050+++ b/include/linux/grdefs.h
62051@@ -0,0 +1,140 @@
62052+#ifndef GRDEFS_H
62053+#define GRDEFS_H
62054+
62055+/* Begin grsecurity status declarations */
62056+
62057+enum {
62058+ GR_READY = 0x01,
62059+ GR_STATUS_INIT = 0x00 // disabled state
62060+};
62061+
62062+/* Begin ACL declarations */
62063+
62064+/* Role flags */
62065+
62066+enum {
62067+ GR_ROLE_USER = 0x0001,
62068+ GR_ROLE_GROUP = 0x0002,
62069+ GR_ROLE_DEFAULT = 0x0004,
62070+ GR_ROLE_SPECIAL = 0x0008,
62071+ GR_ROLE_AUTH = 0x0010,
62072+ GR_ROLE_NOPW = 0x0020,
62073+ GR_ROLE_GOD = 0x0040,
62074+ GR_ROLE_LEARN = 0x0080,
62075+ GR_ROLE_TPE = 0x0100,
62076+ GR_ROLE_DOMAIN = 0x0200,
62077+ GR_ROLE_PAM = 0x0400,
62078+ GR_ROLE_PERSIST = 0x0800
62079+};
62080+
62081+/* ACL Subject and Object mode flags */
62082+enum {
62083+ GR_DELETED = 0x80000000
62084+};
62085+
62086+/* ACL Object-only mode flags */
62087+enum {
62088+ GR_READ = 0x00000001,
62089+ GR_APPEND = 0x00000002,
62090+ GR_WRITE = 0x00000004,
62091+ GR_EXEC = 0x00000008,
62092+ GR_FIND = 0x00000010,
62093+ GR_INHERIT = 0x00000020,
62094+ GR_SETID = 0x00000040,
62095+ GR_CREATE = 0x00000080,
62096+ GR_DELETE = 0x00000100,
62097+ GR_LINK = 0x00000200,
62098+ GR_AUDIT_READ = 0x00000400,
62099+ GR_AUDIT_APPEND = 0x00000800,
62100+ GR_AUDIT_WRITE = 0x00001000,
62101+ GR_AUDIT_EXEC = 0x00002000,
62102+ GR_AUDIT_FIND = 0x00004000,
62103+ GR_AUDIT_INHERIT= 0x00008000,
62104+ GR_AUDIT_SETID = 0x00010000,
62105+ GR_AUDIT_CREATE = 0x00020000,
62106+ GR_AUDIT_DELETE = 0x00040000,
62107+ GR_AUDIT_LINK = 0x00080000,
62108+ GR_PTRACERD = 0x00100000,
62109+ GR_NOPTRACE = 0x00200000,
62110+ GR_SUPPRESS = 0x00400000,
62111+ GR_NOLEARN = 0x00800000,
62112+ GR_INIT_TRANSFER= 0x01000000
62113+};
62114+
62115+#define GR_AUDITS (GR_AUDIT_READ | GR_AUDIT_WRITE | GR_AUDIT_APPEND | GR_AUDIT_EXEC | \
62116+ GR_AUDIT_FIND | GR_AUDIT_INHERIT | GR_AUDIT_SETID | \
62117+ GR_AUDIT_CREATE | GR_AUDIT_DELETE | GR_AUDIT_LINK)
62118+
62119+/* ACL subject-only mode flags */
62120+enum {
62121+ GR_KILL = 0x00000001,
62122+ GR_VIEW = 0x00000002,
62123+ GR_PROTECTED = 0x00000004,
62124+ GR_LEARN = 0x00000008,
62125+ GR_OVERRIDE = 0x00000010,
62126+ /* just a placeholder, this mode is only used in userspace */
62127+ GR_DUMMY = 0x00000020,
62128+ GR_PROTSHM = 0x00000040,
62129+ GR_KILLPROC = 0x00000080,
62130+ GR_KILLIPPROC = 0x00000100,
62131+ /* just a placeholder, this mode is only used in userspace */
62132+ GR_NOTROJAN = 0x00000200,
62133+ GR_PROTPROCFD = 0x00000400,
62134+ GR_PROCACCT = 0x00000800,
62135+ GR_RELAXPTRACE = 0x00001000,
62136+ GR_NESTED = 0x00002000,
62137+ GR_INHERITLEARN = 0x00004000,
62138+ GR_PROCFIND = 0x00008000,
62139+ GR_POVERRIDE = 0x00010000,
62140+ GR_KERNELAUTH = 0x00020000,
62141+ GR_ATSECURE = 0x00040000,
62142+ GR_SHMEXEC = 0x00080000
62143+};
62144+
62145+enum {
62146+ GR_PAX_ENABLE_SEGMEXEC = 0x0001,
62147+ GR_PAX_ENABLE_PAGEEXEC = 0x0002,
62148+ GR_PAX_ENABLE_MPROTECT = 0x0004,
62149+ GR_PAX_ENABLE_RANDMMAP = 0x0008,
62150+ GR_PAX_ENABLE_EMUTRAMP = 0x0010,
62151+ GR_PAX_DISABLE_SEGMEXEC = 0x0100,
62152+ GR_PAX_DISABLE_PAGEEXEC = 0x0200,
62153+ GR_PAX_DISABLE_MPROTECT = 0x0400,
62154+ GR_PAX_DISABLE_RANDMMAP = 0x0800,
62155+ GR_PAX_DISABLE_EMUTRAMP = 0x1000,
62156+};
62157+
62158+enum {
62159+ GR_ID_USER = 0x01,
62160+ GR_ID_GROUP = 0x02,
62161+};
62162+
62163+enum {
62164+ GR_ID_ALLOW = 0x01,
62165+ GR_ID_DENY = 0x02,
62166+};
62167+
62168+#define GR_CRASH_RES 31
62169+#define GR_UIDTABLE_MAX 500
62170+
62171+/* begin resource learning section */
62172+enum {
62173+ GR_RLIM_CPU_BUMP = 60,
62174+ GR_RLIM_FSIZE_BUMP = 50000,
62175+ GR_RLIM_DATA_BUMP = 10000,
62176+ GR_RLIM_STACK_BUMP = 1000,
62177+ GR_RLIM_CORE_BUMP = 10000,
62178+ GR_RLIM_RSS_BUMP = 500000,
62179+ GR_RLIM_NPROC_BUMP = 1,
62180+ GR_RLIM_NOFILE_BUMP = 5,
62181+ GR_RLIM_MEMLOCK_BUMP = 50000,
62182+ GR_RLIM_AS_BUMP = 500000,
62183+ GR_RLIM_LOCKS_BUMP = 2,
62184+ GR_RLIM_SIGPENDING_BUMP = 5,
62185+ GR_RLIM_MSGQUEUE_BUMP = 10000,
62186+ GR_RLIM_NICE_BUMP = 1,
62187+ GR_RLIM_RTPRIO_BUMP = 1,
62188+ GR_RLIM_RTTIME_BUMP = 1000000
62189+};
62190+
62191+#endif
62192diff --git a/include/linux/grinternal.h b/include/linux/grinternal.h
62193new file mode 100644
62194index 0000000..c9292f7
62195--- /dev/null
62196+++ b/include/linux/grinternal.h
62197@@ -0,0 +1,223 @@
62198+#ifndef __GRINTERNAL_H
62199+#define __GRINTERNAL_H
62200+
62201+#ifdef CONFIG_GRKERNSEC
62202+
62203+#include <linux/fs.h>
62204+#include <linux/mnt_namespace.h>
62205+#include <linux/nsproxy.h>
62206+#include <linux/gracl.h>
62207+#include <linux/grdefs.h>
62208+#include <linux/grmsg.h>
62209+
62210+void gr_add_learn_entry(const char *fmt, ...)
62211+ __attribute__ ((format (printf, 1, 2)));
62212+__u32 gr_search_file(const struct dentry *dentry, const __u32 mode,
62213+ const struct vfsmount *mnt);
62214+__u32 gr_check_create(const struct dentry *new_dentry,
62215+ const struct dentry *parent,
62216+ const struct vfsmount *mnt, const __u32 mode);
62217+int gr_check_protected_task(const struct task_struct *task);
62218+__u32 to_gr_audit(const __u32 reqmode);
62219+int gr_set_acls(const int type);
62220+int gr_apply_subject_to_task(struct task_struct *task);
62221+int gr_acl_is_enabled(void);
62222+char gr_roletype_to_char(void);
62223+
62224+void gr_handle_alertkill(struct task_struct *task);
62225+char *gr_to_filename(const struct dentry *dentry,
62226+ const struct vfsmount *mnt);
62227+char *gr_to_filename1(const struct dentry *dentry,
62228+ const struct vfsmount *mnt);
62229+char *gr_to_filename2(const struct dentry *dentry,
62230+ const struct vfsmount *mnt);
62231+char *gr_to_filename3(const struct dentry *dentry,
62232+ const struct vfsmount *mnt);
62233+
62234+extern int grsec_enable_ptrace_readexec;
62235+extern int grsec_enable_harden_ptrace;
62236+extern int grsec_enable_link;
62237+extern int grsec_enable_fifo;
62238+extern int grsec_enable_execve;
62239+extern int grsec_enable_shm;
62240+extern int grsec_enable_execlog;
62241+extern int grsec_enable_signal;
62242+extern int grsec_enable_audit_ptrace;
62243+extern int grsec_enable_forkfail;
62244+extern int grsec_enable_time;
62245+extern int grsec_enable_rofs;
62246+extern int grsec_enable_chroot_shmat;
62247+extern int grsec_enable_chroot_mount;
62248+extern int grsec_enable_chroot_double;
62249+extern int grsec_enable_chroot_pivot;
62250+extern int grsec_enable_chroot_chdir;
62251+extern int grsec_enable_chroot_chmod;
62252+extern int grsec_enable_chroot_mknod;
62253+extern int grsec_enable_chroot_fchdir;
62254+extern int grsec_enable_chroot_nice;
62255+extern int grsec_enable_chroot_execlog;
62256+extern int grsec_enable_chroot_caps;
62257+extern int grsec_enable_chroot_sysctl;
62258+extern int grsec_enable_chroot_unix;
62259+extern int grsec_enable_symlinkown;
62260+extern int grsec_symlinkown_gid;
62261+extern int grsec_enable_tpe;
62262+extern int grsec_tpe_gid;
62263+extern int grsec_enable_tpe_all;
62264+extern int grsec_enable_tpe_invert;
62265+extern int grsec_enable_socket_all;
62266+extern int grsec_socket_all_gid;
62267+extern int grsec_enable_socket_client;
62268+extern int grsec_socket_client_gid;
62269+extern int grsec_enable_socket_server;
62270+extern int grsec_socket_server_gid;
62271+extern int grsec_audit_gid;
62272+extern int grsec_enable_group;
62273+extern int grsec_enable_audit_textrel;
62274+extern int grsec_enable_log_rwxmaps;
62275+extern int grsec_enable_mount;
62276+extern int grsec_enable_chdir;
62277+extern int grsec_resource_logging;
62278+extern int grsec_enable_blackhole;
62279+extern int grsec_lastack_retries;
62280+extern int grsec_enable_brute;
62281+extern int grsec_lock;
62282+
62283+extern spinlock_t grsec_alert_lock;
62284+extern unsigned long grsec_alert_wtime;
62285+extern unsigned long grsec_alert_fyet;
62286+
62287+extern spinlock_t grsec_audit_lock;
62288+
62289+extern rwlock_t grsec_exec_file_lock;
62290+
62291+#define gr_task_fullpath(tsk) ((tsk)->exec_file ? \
62292+ gr_to_filename2((tsk)->exec_file->f_path.dentry, \
62293+ (tsk)->exec_file->f_vfsmnt) : "/")
62294+
62295+#define gr_parent_task_fullpath(tsk) ((tsk)->real_parent->exec_file ? \
62296+ gr_to_filename3((tsk)->real_parent->exec_file->f_path.dentry, \
62297+ (tsk)->real_parent->exec_file->f_vfsmnt) : "/")
62298+
62299+#define gr_task_fullpath0(tsk) ((tsk)->exec_file ? \
62300+ gr_to_filename((tsk)->exec_file->f_path.dentry, \
62301+ (tsk)->exec_file->f_vfsmnt) : "/")
62302+
62303+#define gr_parent_task_fullpath0(tsk) ((tsk)->real_parent->exec_file ? \
62304+ gr_to_filename1((tsk)->real_parent->exec_file->f_path.dentry, \
62305+ (tsk)->real_parent->exec_file->f_vfsmnt) : "/")
62306+
62307+#define proc_is_chrooted(tsk_a) ((tsk_a)->gr_is_chrooted)
62308+
62309+#define have_same_root(tsk_a,tsk_b) ((tsk_a)->gr_chroot_dentry == (tsk_b)->gr_chroot_dentry)
62310+
62311+#define DEFAULTSECARGS(task, cred, pcred) gr_task_fullpath(task), (task)->comm, \
62312+ (task)->pid, (cred)->uid, \
62313+ (cred)->euid, (cred)->gid, (cred)->egid, \
62314+ gr_parent_task_fullpath(task), \
62315+ (task)->real_parent->comm, (task)->real_parent->pid, \
62316+ (pcred)->uid, (pcred)->euid, \
62317+ (pcred)->gid, (pcred)->egid
62318+
62319+#define GR_CHROOT_CAPS {{ \
62320+ CAP_TO_MASK(CAP_LINUX_IMMUTABLE) | CAP_TO_MASK(CAP_NET_ADMIN) | \
62321+ CAP_TO_MASK(CAP_SYS_MODULE) | CAP_TO_MASK(CAP_SYS_RAWIO) | \
62322+ CAP_TO_MASK(CAP_SYS_PACCT) | CAP_TO_MASK(CAP_SYS_ADMIN) | \
62323+ CAP_TO_MASK(CAP_SYS_BOOT) | CAP_TO_MASK(CAP_SYS_TIME) | \
62324+ CAP_TO_MASK(CAP_NET_RAW) | CAP_TO_MASK(CAP_SYS_TTY_CONFIG) | \
62325+ CAP_TO_MASK(CAP_IPC_OWNER) | CAP_TO_MASK(CAP_SETFCAP), \
62326+ CAP_TO_MASK(CAP_SYSLOG) | CAP_TO_MASK(CAP_MAC_ADMIN) }}
62327+
62328+#define security_learn(normal_msg,args...) \
62329+({ \
62330+ read_lock(&grsec_exec_file_lock); \
62331+ gr_add_learn_entry(normal_msg "\n", ## args); \
62332+ read_unlock(&grsec_exec_file_lock); \
62333+})
62334+
62335+enum {
62336+ GR_DO_AUDIT,
62337+ GR_DONT_AUDIT,
62338+ /* used for non-audit messages that we shouldn't kill the task on */
62339+ GR_DONT_AUDIT_GOOD
62340+};
62341+
62342+enum {
62343+ GR_TTYSNIFF,
62344+ GR_RBAC,
62345+ GR_RBAC_STR,
62346+ GR_STR_RBAC,
62347+ GR_RBAC_MODE2,
62348+ GR_RBAC_MODE3,
62349+ GR_FILENAME,
62350+ GR_SYSCTL_HIDDEN,
62351+ GR_NOARGS,
62352+ GR_ONE_INT,
62353+ GR_ONE_INT_TWO_STR,
62354+ GR_ONE_STR,
62355+ GR_STR_INT,
62356+ GR_TWO_STR_INT,
62357+ GR_TWO_INT,
62358+ GR_TWO_U64,
62359+ GR_THREE_INT,
62360+ GR_FIVE_INT_TWO_STR,
62361+ GR_TWO_STR,
62362+ GR_THREE_STR,
62363+ GR_FOUR_STR,
62364+ GR_STR_FILENAME,
62365+ GR_FILENAME_STR,
62366+ GR_FILENAME_TWO_INT,
62367+ GR_FILENAME_TWO_INT_STR,
62368+ GR_TEXTREL,
62369+ GR_PTRACE,
62370+ GR_RESOURCE,
62371+ GR_CAP,
62372+ GR_SIG,
62373+ GR_SIG2,
62374+ GR_CRASH1,
62375+ GR_CRASH2,
62376+ GR_PSACCT,
62377+ GR_RWXMAP
62378+};
62379+
62380+#define gr_log_hidden_sysctl(audit, msg, str) gr_log_varargs(audit, msg, GR_SYSCTL_HIDDEN, str)
62381+#define gr_log_ttysniff(audit, msg, task) gr_log_varargs(audit, msg, GR_TTYSNIFF, task)
62382+#define gr_log_fs_rbac_generic(audit, msg, dentry, mnt) gr_log_varargs(audit, msg, GR_RBAC, dentry, mnt)
62383+#define gr_log_fs_rbac_str(audit, msg, dentry, mnt, str) gr_log_varargs(audit, msg, GR_RBAC_STR, dentry, mnt, str)
62384+#define gr_log_fs_str_rbac(audit, msg, str, dentry, mnt) gr_log_varargs(audit, msg, GR_STR_RBAC, str, dentry, mnt)
62385+#define gr_log_fs_rbac_mode2(audit, msg, dentry, mnt, str1, str2) gr_log_varargs(audit, msg, GR_RBAC_MODE2, dentry, mnt, str1, str2)
62386+#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)
62387+#define gr_log_fs_generic(audit, msg, dentry, mnt) gr_log_varargs(audit, msg, GR_FILENAME, dentry, mnt)
62388+#define gr_log_noargs(audit, msg) gr_log_varargs(audit, msg, GR_NOARGS)
62389+#define gr_log_int(audit, msg, num) gr_log_varargs(audit, msg, GR_ONE_INT, num)
62390+#define gr_log_int_str2(audit, msg, num, str1, str2) gr_log_varargs(audit, msg, GR_ONE_INT_TWO_STR, num, str1, str2)
62391+#define gr_log_str(audit, msg, str) gr_log_varargs(audit, msg, GR_ONE_STR, str)
62392+#define gr_log_str_int(audit, msg, str, num) gr_log_varargs(audit, msg, GR_STR_INT, str, num)
62393+#define gr_log_int_int(audit, msg, num1, num2) gr_log_varargs(audit, msg, GR_TWO_INT, num1, num2)
62394+#define gr_log_two_u64(audit, msg, num1, num2) gr_log_varargs(audit, msg, GR_TWO_U64, num1, num2)
62395+#define gr_log_int3(audit, msg, num1, num2, num3) gr_log_varargs(audit, msg, GR_THREE_INT, num1, num2, num3)
62396+#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)
62397+#define gr_log_str_str(audit, msg, str1, str2) gr_log_varargs(audit, msg, GR_TWO_STR, str1, str2)
62398+#define gr_log_str2_int(audit, msg, str1, str2, num) gr_log_varargs(audit, msg, GR_TWO_STR_INT, str1, str2, num)
62399+#define gr_log_str3(audit, msg, str1, str2, str3) gr_log_varargs(audit, msg, GR_THREE_STR, str1, str2, str3)
62400+#define gr_log_str4(audit, msg, str1, str2, str3, str4) gr_log_varargs(audit, msg, GR_FOUR_STR, str1, str2, str3, str4)
62401+#define gr_log_str_fs(audit, msg, str, dentry, mnt) gr_log_varargs(audit, msg, GR_STR_FILENAME, str, dentry, mnt)
62402+#define gr_log_fs_str(audit, msg, dentry, mnt, str) gr_log_varargs(audit, msg, GR_FILENAME_STR, dentry, mnt, str)
62403+#define gr_log_fs_int2(audit, msg, dentry, mnt, num1, num2) gr_log_varargs(audit, msg, GR_FILENAME_TWO_INT, dentry, mnt, num1, num2)
62404+#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)
62405+#define gr_log_textrel_ulong_ulong(audit, msg, file, ulong1, ulong2) gr_log_varargs(audit, msg, GR_TEXTREL, file, ulong1, ulong2)
62406+#define gr_log_ptrace(audit, msg, task) gr_log_varargs(audit, msg, GR_PTRACE, task)
62407+#define gr_log_res_ulong2_str(audit, msg, task, ulong1, str, ulong2) gr_log_varargs(audit, msg, GR_RESOURCE, task, ulong1, str, ulong2)
62408+#define gr_log_cap(audit, msg, task, str) gr_log_varargs(audit, msg, GR_CAP, task, str)
62409+#define gr_log_sig_addr(audit, msg, str, addr) gr_log_varargs(audit, msg, GR_SIG, str, addr)
62410+#define gr_log_sig_task(audit, msg, task, num) gr_log_varargs(audit, msg, GR_SIG2, task, num)
62411+#define gr_log_crash1(audit, msg, task, ulong) gr_log_varargs(audit, msg, GR_CRASH1, task, ulong)
62412+#define gr_log_crash2(audit, msg, task, ulong1) gr_log_varargs(audit, msg, GR_CRASH2, task, ulong1)
62413+#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)
62414+#define gr_log_rwxmap(audit, msg, str) gr_log_varargs(audit, msg, GR_RWXMAP, str)
62415+
62416+void gr_log_varargs(int audit, const char *msg, int argtypes, ...);
62417+
62418+#endif
62419+
62420+#endif
62421diff --git a/include/linux/grmsg.h b/include/linux/grmsg.h
62422new file mode 100644
62423index 0000000..54f4e85
62424--- /dev/null
62425+++ b/include/linux/grmsg.h
62426@@ -0,0 +1,110 @@
62427+#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"
62428+#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"
62429+#define GR_PTRACE_ACL_MSG "denied ptrace of %.950s(%.16s:%d) by "
62430+#define GR_STOPMOD_MSG "denied modification of module state by "
62431+#define GR_ROFS_BLOCKWRITE_MSG "denied write to block device %.950s by "
62432+#define GR_ROFS_MOUNT_MSG "denied writable mount of %.950s by "
62433+#define GR_IOPERM_MSG "denied use of ioperm() by "
62434+#define GR_IOPL_MSG "denied use of iopl() by "
62435+#define GR_SHMAT_ACL_MSG "denied attach of shared memory of UID %u, PID %d, ID %u by "
62436+#define GR_UNIX_CHROOT_MSG "denied connect() to abstract AF_UNIX socket outside of chroot by "
62437+#define GR_SHMAT_CHROOT_MSG "denied attach of shared memory outside of chroot by "
62438+#define GR_MEM_READWRITE_MSG "denied access of range %Lx -> %Lx in /dev/mem by "
62439+#define GR_SYMLINK_MSG "not following symlink %.950s owned by %d.%d by "
62440+#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"
62441+#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"
62442+#define GR_HIDDEN_ACL_MSG "%s access to hidden file %.950s by "
62443+#define GR_OPEN_ACL_MSG "%s open of %.950s for%s%s by "
62444+#define GR_CREATE_ACL_MSG "%s create of %.950s for%s%s by "
62445+#define GR_FIFO_MSG "denied writing FIFO %.950s of %d.%d by "
62446+#define GR_MKNOD_CHROOT_MSG "denied mknod of %.950s from chroot by "
62447+#define GR_MKNOD_ACL_MSG "%s mknod of %.950s by "
62448+#define GR_UNIXCONNECT_ACL_MSG "%s connect() to the unix domain socket %.950s by "
62449+#define GR_TTYSNIFF_ACL_MSG "terminal being sniffed by IP:%pI4 %.480s[%.16s:%d], parent %.480s[%.16s:%d] against "
62450+#define GR_MKDIR_ACL_MSG "%s mkdir of %.950s by "
62451+#define GR_RMDIR_ACL_MSG "%s rmdir of %.950s by "
62452+#define GR_UNLINK_ACL_MSG "%s unlink of %.950s by "
62453+#define GR_SYMLINK_ACL_MSG "%s symlink from %.480s to %.480s by "
62454+#define GR_HARDLINK_MSG "denied hardlink of %.930s (owned by %d.%d) to %.30s for "
62455+#define GR_LINK_ACL_MSG "%s link of %.480s to %.480s by "
62456+#define GR_INHERIT_ACL_MSG "successful inherit of %.480s's ACL for %.480s by "
62457+#define GR_RENAME_ACL_MSG "%s rename of %.480s to %.480s by "
62458+#define GR_UNSAFESHARE_EXEC_ACL_MSG "denied exec with cloned fs of %.950s by "
62459+#define GR_PTRACE_EXEC_ACL_MSG "denied ptrace of %.950s by "
62460+#define GR_EXEC_ACL_MSG "%s execution of %.950s by "
62461+#define GR_EXEC_TPE_MSG "denied untrusted exec (due to %.70s) of %.950s by "
62462+#define GR_SEGVSTART_ACL_MSG "possible exploit bruteforcing on " DEFAULTSECMSG " banning uid %u from login for %lu seconds"
62463+#define GR_SEGVNOSUID_ACL_MSG "possible exploit bruteforcing on " DEFAULTSECMSG " banning execution for %lu seconds"
62464+#define GR_MOUNT_CHROOT_MSG "denied mount of %.256s as %.930s from chroot by "
62465+#define GR_PIVOT_CHROOT_MSG "denied pivot_root from chroot by "
62466+#define GR_TRUNCATE_ACL_MSG "%s truncate of %.950s by "
62467+#define GR_ATIME_ACL_MSG "%s access time change of %.950s by "
62468+#define GR_ACCESS_ACL_MSG "%s access of %.950s for%s%s%s by "
62469+#define GR_CHROOT_CHROOT_MSG "denied double chroot to %.950s by "
62470+#define GR_CHMOD_CHROOT_MSG "denied chmod +s of %.950s by "
62471+#define GR_CHMOD_ACL_MSG "%s chmod of %.950s by "
62472+#define GR_CHROOT_FCHDIR_MSG "denied fchdir outside of chroot to %.950s by "
62473+#define GR_CHOWN_ACL_MSG "%s chown of %.950s by "
62474+#define GR_SETXATTR_ACL_MSG "%s setting extended attributes of %.950s by "
62475+#define GR_WRITLIB_ACL_MSG "denied load of writable library %.950s by "
62476+#define GR_INITF_ACL_MSG "init_variables() failed %s by "
62477+#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"
62478+#define GR_DEV_ACL_MSG "/dev/grsec: %d bytes sent %d required, being fed garbage by "
62479+#define GR_SHUTS_ACL_MSG "shutdown auth success for "
62480+#define GR_SHUTF_ACL_MSG "shutdown auth failure for "
62481+#define GR_SHUTI_ACL_MSG "ignoring shutdown for disabled RBAC system for "
62482+#define GR_SEGVMODS_ACL_MSG "segvmod auth success for "
62483+#define GR_SEGVMODF_ACL_MSG "segvmod auth failure for "
62484+#define GR_SEGVMODI_ACL_MSG "ignoring segvmod for disabled RBAC system for "
62485+#define GR_ENABLE_ACL_MSG "%s RBAC system loaded by "
62486+#define GR_ENABLEF_ACL_MSG "unable to load %s for "
62487+#define GR_RELOADI_ACL_MSG "ignoring reload request for disabled RBAC system"
62488+#define GR_RELOAD_ACL_MSG "%s RBAC system reloaded by "
62489+#define GR_RELOADF_ACL_MSG "failed reload of %s for "
62490+#define GR_SPROLEI_ACL_MSG "ignoring change to special role for disabled RBAC system for "
62491+#define GR_SPROLES_ACL_MSG "successful change to special role %s (id %d) by "
62492+#define GR_SPROLEL_ACL_MSG "special role %s (id %d) exited by "
62493+#define GR_SPROLEF_ACL_MSG "special role %s failure for "
62494+#define GR_UNSPROLEI_ACL_MSG "ignoring unauth of special role for disabled RBAC system for "
62495+#define GR_UNSPROLES_ACL_MSG "successful unauth of special role %s (id %d) by "
62496+#define GR_INVMODE_ACL_MSG "invalid mode %d by "
62497+#define GR_PRIORITY_CHROOT_MSG "denied priority change of process (%.16s:%d) by "
62498+#define GR_FAILFORK_MSG "failed fork with errno %s by "
62499+#define GR_NICE_CHROOT_MSG "denied priority change by "
62500+#define GR_UNISIGLOG_MSG "%.32s occurred at %p in "
62501+#define GR_DUALSIGLOG_MSG "signal %d sent to " DEFAULTSECMSG " by "
62502+#define GR_SIG_ACL_MSG "denied send of signal %d to protected task " DEFAULTSECMSG " by "
62503+#define GR_SYSCTL_MSG "denied modification of grsecurity sysctl value : %.32s by "
62504+#define GR_SYSCTL_ACL_MSG "%s sysctl of %.950s for%s%s by "
62505+#define GR_TIME_MSG "time set by "
62506+#define GR_DEFACL_MSG "fatal: unable to find subject for (%.16s:%d), loaded by "
62507+#define GR_MMAP_ACL_MSG "%s executable mmap of %.950s by "
62508+#define GR_MPROTECT_ACL_MSG "%s executable mprotect of %.950s by "
62509+#define GR_SOCK_MSG "denied socket(%.16s,%.16s,%.16s) by "
62510+#define GR_SOCK_NOINET_MSG "denied socket(%.16s,%.16s,%d) by "
62511+#define GR_BIND_MSG "denied bind() by "
62512+#define GR_CONNECT_MSG "denied connect() by "
62513+#define GR_BIND_ACL_MSG "denied bind() to %pI4 port %u sock type %.16s protocol %.16s by "
62514+#define GR_CONNECT_ACL_MSG "denied connect() to %pI4 port %u sock type %.16s protocol %.16s by "
62515+#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"
62516+#define GR_EXEC_CHROOT_MSG "exec of %.980s within chroot by process "
62517+#define GR_CAP_ACL_MSG "use of %s denied for "
62518+#define GR_CAP_CHROOT_MSG "use of %s in chroot denied for "
62519+#define GR_CAP_ACL_MSG2 "use of %s permitted for "
62520+#define GR_USRCHANGE_ACL_MSG "change to uid %u denied for "
62521+#define GR_GRPCHANGE_ACL_MSG "change to gid %u denied for "
62522+#define GR_REMOUNT_AUDIT_MSG "remount of %.256s by "
62523+#define GR_UNMOUNT_AUDIT_MSG "unmount of %.256s by "
62524+#define GR_MOUNT_AUDIT_MSG "mount of %.256s to %.256s by "
62525+#define GR_CHDIR_AUDIT_MSG "chdir to %.980s by "
62526+#define GR_EXEC_AUDIT_MSG "exec of %.930s (%.128s) by "
62527+#define GR_RESOURCE_MSG "denied resource overstep by requesting %lu for %.16s against limit %lu for "
62528+#define GR_RWXMMAP_MSG "denied RWX mmap of %.950s by "
62529+#define GR_RWXMPROTECT_MSG "denied RWX mprotect of %.950s by "
62530+#define GR_TEXTREL_AUDIT_MSG "text relocation in %s, VMA:0x%08lx 0x%08lx by "
62531+#define GR_VM86_MSG "denied use of vm86 by "
62532+#define GR_PTRACE_AUDIT_MSG "process %.950s(%.16s:%d) attached to via ptrace by "
62533+#define GR_PTRACE_READEXEC_MSG "denied ptrace of unreadable binary %.950s by "
62534+#define GR_INIT_TRANSFER_MSG "persistent special role transferred privilege to init by "
62535+#define GR_BADPROCPID_MSG "denied read of sensitive /proc/pid/%s entry via fd passed across exec by "
62536+#define GR_SYMLINKOWNER_MSG "denied following symlink %.950s since symlink owner %u does not match target owner %u, by "
62537diff --git a/include/linux/grsecurity.h b/include/linux/grsecurity.h
62538new file mode 100644
62539index 0000000..f9b9a21
62540--- /dev/null
62541+++ b/include/linux/grsecurity.h
62542@@ -0,0 +1,238 @@
62543+#ifndef GR_SECURITY_H
62544+#define GR_SECURITY_H
62545+#include <linux/fs.h>
62546+#include <linux/fs_struct.h>
62547+#include <linux/binfmts.h>
62548+#include <linux/gracl.h>
62549+
62550+/* notify of brain-dead configs */
62551+#if defined(CONFIG_GRKERNSEC_PROC_USER) && defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
62552+#error "CONFIG_GRKERNSEC_PROC_USER and CONFIG_GRKERNSEC_PROC_USERGROUP cannot both be enabled."
62553+#endif
62554+#if defined(CONFIG_PAX_NOEXEC) && !defined(CONFIG_PAX_PAGEEXEC) && !defined(CONFIG_PAX_SEGMEXEC) && !defined(CONFIG_PAX_KERNEXEC)
62555+#error "CONFIG_PAX_NOEXEC enabled, but PAGEEXEC, SEGMEXEC, and KERNEXEC are disabled."
62556+#endif
62557+#if defined(CONFIG_PAX_ASLR) && !defined(CONFIG_PAX_RANDKSTACK) && !defined(CONFIG_PAX_RANDUSTACK) && !defined(CONFIG_PAX_RANDMMAP)
62558+#error "CONFIG_PAX_ASLR enabled, but RANDKSTACK, RANDUSTACK, and RANDMMAP are disabled."
62559+#endif
62560+#if defined(CONFIG_PAX) && !defined(CONFIG_PAX_NOEXEC) && !defined(CONFIG_PAX_ASLR)
62561+#error "CONFIG_PAX enabled, but no PaX options are enabled."
62562+#endif
62563+
62564+#include <linux/compat.h>
62565+
62566+struct user_arg_ptr {
62567+#ifdef CONFIG_COMPAT
62568+ bool is_compat;
62569+#endif
62570+ union {
62571+ const char __user *const __user *native;
62572+#ifdef CONFIG_COMPAT
62573+ compat_uptr_t __user *compat;
62574+#endif
62575+ } ptr;
62576+};
62577+
62578+void gr_handle_brute_attach(struct task_struct *p, unsigned long mm_flags);
62579+void gr_handle_brute_check(void);
62580+void gr_handle_kernel_exploit(void);
62581+int gr_process_user_ban(void);
62582+
62583+char gr_roletype_to_char(void);
62584+
62585+int gr_acl_enable_at_secure(void);
62586+
62587+int gr_check_user_change(int real, int effective, int fs);
62588+int gr_check_group_change(int real, int effective, int fs);
62589+
62590+void gr_del_task_from_ip_table(struct task_struct *p);
62591+
62592+int gr_pid_is_chrooted(struct task_struct *p);
62593+int gr_handle_chroot_fowner(struct pid *pid, enum pid_type type);
62594+int gr_handle_chroot_nice(void);
62595+int gr_handle_chroot_sysctl(const int op);
62596+int gr_handle_chroot_setpriority(struct task_struct *p,
62597+ const int niceval);
62598+int gr_chroot_fchdir(struct dentry *u_dentry, struct vfsmount *u_mnt);
62599+int gr_handle_chroot_chroot(const struct dentry *dentry,
62600+ const struct vfsmount *mnt);
62601+void gr_handle_chroot_chdir(struct path *path);
62602+int gr_handle_chroot_chmod(const struct dentry *dentry,
62603+ const struct vfsmount *mnt, const int mode);
62604+int gr_handle_chroot_mknod(const struct dentry *dentry,
62605+ const struct vfsmount *mnt, const int mode);
62606+int gr_handle_chroot_mount(const struct dentry *dentry,
62607+ const struct vfsmount *mnt,
62608+ const char *dev_name);
62609+int gr_handle_chroot_pivot(void);
62610+int gr_handle_chroot_unix(const pid_t pid);
62611+
62612+int gr_handle_rawio(const struct inode *inode);
62613+
62614+void gr_handle_ioperm(void);
62615+void gr_handle_iopl(void);
62616+
62617+umode_t gr_acl_umask(void);
62618+
62619+int gr_tpe_allow(const struct file *file);
62620+
62621+void gr_set_chroot_entries(struct task_struct *task, struct path *path);
62622+void gr_clear_chroot_entries(struct task_struct *task);
62623+
62624+void gr_log_forkfail(const int retval);
62625+void gr_log_timechange(void);
62626+void gr_log_signal(const int sig, const void *addr, const struct task_struct *t);
62627+void gr_log_chdir(const struct dentry *dentry,
62628+ const struct vfsmount *mnt);
62629+void gr_log_chroot_exec(const struct dentry *dentry,
62630+ const struct vfsmount *mnt);
62631+void gr_handle_exec_args(struct linux_binprm *bprm, struct user_arg_ptr argv);
62632+void gr_log_remount(const char *devname, const int retval);
62633+void gr_log_unmount(const char *devname, const int retval);
62634+void gr_log_mount(const char *from, const char *to, const int retval);
62635+void gr_log_textrel(struct vm_area_struct *vma);
62636+void gr_log_rwxmmap(struct file *file);
62637+void gr_log_rwxmprotect(struct file *file);
62638+
62639+int gr_handle_follow_link(const struct inode *parent,
62640+ const struct inode *inode,
62641+ const struct dentry *dentry,
62642+ const struct vfsmount *mnt);
62643+int gr_handle_fifo(const struct dentry *dentry,
62644+ const struct vfsmount *mnt,
62645+ const struct dentry *dir, const int flag,
62646+ const int acc_mode);
62647+int gr_handle_hardlink(const struct dentry *dentry,
62648+ const struct vfsmount *mnt,
62649+ struct inode *inode,
62650+ const int mode, const char *to);
62651+
62652+int gr_is_capable(const int cap);
62653+int gr_is_capable_nolog(const int cap);
62654+int gr_task_is_capable(const struct task_struct *task, const struct cred *cred, const int cap);
62655+int gr_task_is_capable_nolog(const struct task_struct *task, const int cap);
62656+
62657+void gr_learn_resource(const struct task_struct *task, const int limit,
62658+ const unsigned long wanted, const int gt);
62659+void gr_copy_label(struct task_struct *tsk);
62660+void gr_handle_crash(struct task_struct *task, const int sig);
62661+int gr_handle_signal(const struct task_struct *p, const int sig);
62662+int gr_check_crash_uid(const uid_t uid);
62663+int gr_check_protected_task(const struct task_struct *task);
62664+int gr_check_protected_task_fowner(struct pid *pid, enum pid_type type);
62665+int gr_acl_handle_mmap(const struct file *file,
62666+ const unsigned long prot);
62667+int gr_acl_handle_mprotect(const struct file *file,
62668+ const unsigned long prot);
62669+int gr_check_hidden_task(const struct task_struct *tsk);
62670+__u32 gr_acl_handle_truncate(const struct dentry *dentry,
62671+ const struct vfsmount *mnt);
62672+__u32 gr_acl_handle_utime(const struct dentry *dentry,
62673+ const struct vfsmount *mnt);
62674+__u32 gr_acl_handle_access(const struct dentry *dentry,
62675+ const struct vfsmount *mnt, const int fmode);
62676+__u32 gr_acl_handle_chmod(const struct dentry *dentry,
62677+ const struct vfsmount *mnt, umode_t *mode);
62678+__u32 gr_acl_handle_chown(const struct dentry *dentry,
62679+ const struct vfsmount *mnt);
62680+__u32 gr_acl_handle_setxattr(const struct dentry *dentry,
62681+ const struct vfsmount *mnt);
62682+int gr_handle_ptrace(struct task_struct *task, const long request);
62683+int gr_handle_proc_ptrace(struct task_struct *task);
62684+__u32 gr_acl_handle_execve(const struct dentry *dentry,
62685+ const struct vfsmount *mnt);
62686+int gr_check_crash_exec(const struct file *filp);
62687+int gr_acl_is_enabled(void);
62688+void gr_set_kernel_label(struct task_struct *task);
62689+void gr_set_role_label(struct task_struct *task, const uid_t uid,
62690+ const gid_t gid);
62691+int gr_set_proc_label(const struct dentry *dentry,
62692+ const struct vfsmount *mnt,
62693+ const int unsafe_flags);
62694+__u32 gr_acl_handle_hidden_file(const struct dentry *dentry,
62695+ const struct vfsmount *mnt);
62696+__u32 gr_acl_handle_open(const struct dentry *dentry,
62697+ const struct vfsmount *mnt, int acc_mode);
62698+__u32 gr_acl_handle_creat(const struct dentry *dentry,
62699+ const struct dentry *p_dentry,
62700+ const struct vfsmount *p_mnt,
62701+ int open_flags, int acc_mode, const int imode);
62702+void gr_handle_create(const struct dentry *dentry,
62703+ const struct vfsmount *mnt);
62704+void gr_handle_proc_create(const struct dentry *dentry,
62705+ const struct inode *inode);
62706+__u32 gr_acl_handle_mknod(const struct dentry *new_dentry,
62707+ const struct dentry *parent_dentry,
62708+ const struct vfsmount *parent_mnt,
62709+ const int mode);
62710+__u32 gr_acl_handle_mkdir(const struct dentry *new_dentry,
62711+ const struct dentry *parent_dentry,
62712+ const struct vfsmount *parent_mnt);
62713+__u32 gr_acl_handle_rmdir(const struct dentry *dentry,
62714+ const struct vfsmount *mnt);
62715+void gr_handle_delete(const ino_t ino, const dev_t dev);
62716+__u32 gr_acl_handle_unlink(const struct dentry *dentry,
62717+ const struct vfsmount *mnt);
62718+__u32 gr_acl_handle_symlink(const struct dentry *new_dentry,
62719+ const struct dentry *parent_dentry,
62720+ const struct vfsmount *parent_mnt,
62721+ const char *from);
62722+__u32 gr_acl_handle_link(const struct dentry *new_dentry,
62723+ const struct dentry *parent_dentry,
62724+ const struct vfsmount *parent_mnt,
62725+ const struct dentry *old_dentry,
62726+ const struct vfsmount *old_mnt, const char *to);
62727+int gr_handle_symlink_owner(const struct path *link, const struct inode *target);
62728+int gr_acl_handle_rename(struct dentry *new_dentry,
62729+ struct dentry *parent_dentry,
62730+ const struct vfsmount *parent_mnt,
62731+ struct dentry *old_dentry,
62732+ struct inode *old_parent_inode,
62733+ struct vfsmount *old_mnt, const char *newname);
62734+void gr_handle_rename(struct inode *old_dir, struct inode *new_dir,
62735+ struct dentry *old_dentry,
62736+ struct dentry *new_dentry,
62737+ struct vfsmount *mnt, const __u8 replace);
62738+__u32 gr_check_link(const struct dentry *new_dentry,
62739+ const struct dentry *parent_dentry,
62740+ const struct vfsmount *parent_mnt,
62741+ const struct dentry *old_dentry,
62742+ const struct vfsmount *old_mnt);
62743+int gr_acl_handle_filldir(const struct file *file, const char *name,
62744+ const unsigned int namelen, const ino_t ino);
62745+
62746+__u32 gr_acl_handle_unix(const struct dentry *dentry,
62747+ const struct vfsmount *mnt);
62748+void gr_acl_handle_exit(void);
62749+void gr_acl_handle_psacct(struct task_struct *task, const long code);
62750+int gr_acl_handle_procpidmem(const struct task_struct *task);
62751+int gr_handle_rofs_mount(struct dentry *dentry, struct vfsmount *mnt, int mnt_flags);
62752+int gr_handle_rofs_blockwrite(struct dentry *dentry, struct vfsmount *mnt, int acc_mode);
62753+void gr_audit_ptrace(struct task_struct *task);
62754+dev_t gr_get_dev_from_dentry(struct dentry *dentry);
62755+
62756+int gr_ptrace_readexec(struct file *file, int unsafe_flags);
62757+
62758+#ifdef CONFIG_GRKERNSEC
62759+void task_grsec_rbac(struct seq_file *m, struct task_struct *p);
62760+void gr_handle_vm86(void);
62761+void gr_handle_mem_readwrite(u64 from, u64 to);
62762+
62763+void gr_log_badprocpid(const char *entry);
62764+
62765+extern int grsec_enable_dmesg;
62766+extern int grsec_disable_privio;
62767+
62768+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
62769+extern int grsec_proc_gid;
62770+#endif
62771+
62772+#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
62773+extern int grsec_enable_chroot_findtask;
62774+#endif
62775+#ifdef CONFIG_GRKERNSEC_SETXID
62776+extern int grsec_enable_setxid;
62777+#endif
62778+#endif
62779+
62780+#endif
62781diff --git a/include/linux/grsock.h b/include/linux/grsock.h
62782new file mode 100644
62783index 0000000..e7ffaaf
62784--- /dev/null
62785+++ b/include/linux/grsock.h
62786@@ -0,0 +1,19 @@
62787+#ifndef __GRSOCK_H
62788+#define __GRSOCK_H
62789+
62790+extern void gr_attach_curr_ip(const struct sock *sk);
62791+extern int gr_handle_sock_all(const int family, const int type,
62792+ const int protocol);
62793+extern int gr_handle_sock_server(const struct sockaddr *sck);
62794+extern int gr_handle_sock_server_other(const struct sock *sck);
62795+extern int gr_handle_sock_client(const struct sockaddr *sck);
62796+extern int gr_search_connect(struct socket * sock,
62797+ struct sockaddr_in * addr);
62798+extern int gr_search_bind(struct socket * sock,
62799+ struct sockaddr_in * addr);
62800+extern int gr_search_listen(struct socket * sock);
62801+extern int gr_search_accept(struct socket * sock);
62802+extern int gr_search_socket(const int domain, const int type,
62803+ const int protocol);
62804+
62805+#endif
62806diff --git a/include/linux/hid.h b/include/linux/hid.h
62807index 42970de..5db3c92 100644
62808--- a/include/linux/hid.h
62809+++ b/include/linux/hid.h
62810@@ -705,7 +705,7 @@ struct hid_ll_driver {
62811 unsigned int code, int value);
62812
62813 int (*parse)(struct hid_device *hdev);
62814-};
62815+} __no_const;
62816
62817 #define PM_HINT_FULLON 1<<5
62818 #define PM_HINT_NORMAL 1<<1
62819diff --git a/include/linux/highmem.h b/include/linux/highmem.h
62820index ef788b5..ac41b7b 100644
62821--- a/include/linux/highmem.h
62822+++ b/include/linux/highmem.h
62823@@ -189,6 +189,18 @@ static inline void clear_highpage(struct page *page)
62824 kunmap_atomic(kaddr);
62825 }
62826
62827+static inline void sanitize_highpage(struct page *page)
62828+{
62829+ void *kaddr;
62830+ unsigned long flags;
62831+
62832+ local_irq_save(flags);
62833+ kaddr = kmap_atomic(page);
62834+ clear_page(kaddr);
62835+ kunmap_atomic(kaddr);
62836+ local_irq_restore(flags);
62837+}
62838+
62839 static inline void zero_user_segments(struct page *page,
62840 unsigned start1, unsigned end1,
62841 unsigned start2, unsigned end2)
62842diff --git a/include/linux/i2c.h b/include/linux/i2c.h
62843index 5970266..1c48c3b 100644
62844--- a/include/linux/i2c.h
62845+++ b/include/linux/i2c.h
62846@@ -369,6 +369,7 @@ struct i2c_algorithm {
62847 /* To determine what the adapter supports */
62848 u32 (*functionality) (struct i2c_adapter *);
62849 };
62850+typedef struct i2c_algorithm __no_const i2c_algorithm_no_const;
62851
62852 /*
62853 * i2c_adapter is the structure used to identify a physical i2c bus along
62854diff --git a/include/linux/i2o.h b/include/linux/i2o.h
62855index d23c3c2..eb63c81 100644
62856--- a/include/linux/i2o.h
62857+++ b/include/linux/i2o.h
62858@@ -565,7 +565,7 @@ struct i2o_controller {
62859 struct i2o_device *exec; /* Executive */
62860 #if BITS_PER_LONG == 64
62861 spinlock_t context_list_lock; /* lock for context_list */
62862- atomic_t context_list_counter; /* needed for unique contexts */
62863+ atomic_unchecked_t context_list_counter; /* needed for unique contexts */
62864 struct list_head context_list; /* list of context id's
62865 and pointers */
62866 #endif
62867diff --git a/include/linux/if_team.h b/include/linux/if_team.h
62868index aa2e167..84024ce 100644
62869--- a/include/linux/if_team.h
62870+++ b/include/linux/if_team.h
62871@@ -109,6 +109,7 @@ struct team_mode_ops {
62872 void (*port_enabled)(struct team *team, struct team_port *port);
62873 void (*port_disabled)(struct team *team, struct team_port *port);
62874 };
62875+typedef struct team_mode_ops __no_const team_mode_ops_no_const;
62876
62877 enum team_option_type {
62878 TEAM_OPTION_TYPE_U32,
62879@@ -181,7 +182,7 @@ struct team {
62880 struct list_head option_inst_list; /* list of option instances */
62881
62882 const struct team_mode *mode;
62883- struct team_mode_ops ops;
62884+ team_mode_ops_no_const ops;
62885 long mode_priv[TEAM_MODE_PRIV_LONGS];
62886 };
62887
62888diff --git a/include/linux/init.h b/include/linux/init.h
62889index 5e664f6..0a1225c 100644
62890--- a/include/linux/init.h
62891+++ b/include/linux/init.h
62892@@ -39,9 +39,15 @@
62893 * Also note, that this data cannot be "const".
62894 */
62895
62896+#ifdef MODULE
62897+#define add_latent_entropy
62898+#else
62899+#define add_latent_entropy __latent_entropy
62900+#endif
62901+
62902 /* These are for everybody (although not all archs will actually
62903 discard it in modules) */
62904-#define __init __section(.init.text) __cold notrace
62905+#define __init __section(.init.text) __cold notrace add_latent_entropy
62906 #define __initdata __section(.init.data)
62907 #define __initconst __section(.init.rodata)
62908 #define __exitdata __section(.exit.data)
62909@@ -83,7 +89,7 @@
62910 #define __exit __section(.exit.text) __exitused __cold notrace
62911
62912 /* Used for HOTPLUG */
62913-#define __devinit __section(.devinit.text) __cold notrace
62914+#define __devinit __section(.devinit.text) __cold notrace add_latent_entropy
62915 #define __devinitdata __section(.devinit.data)
62916 #define __devinitconst __section(.devinit.rodata)
62917 #define __devexit __section(.devexit.text) __exitused __cold notrace
62918@@ -91,7 +97,7 @@
62919 #define __devexitconst __section(.devexit.rodata)
62920
62921 /* Used for HOTPLUG_CPU */
62922-#define __cpuinit __section(.cpuinit.text) __cold notrace
62923+#define __cpuinit __section(.cpuinit.text) __cold notrace add_latent_entropy
62924 #define __cpuinitdata __section(.cpuinit.data)
62925 #define __cpuinitconst __section(.cpuinit.rodata)
62926 #define __cpuexit __section(.cpuexit.text) __exitused __cold notrace
62927@@ -99,7 +105,7 @@
62928 #define __cpuexitconst __section(.cpuexit.rodata)
62929
62930 /* Used for MEMORY_HOTPLUG */
62931-#define __meminit __section(.meminit.text) __cold notrace
62932+#define __meminit __section(.meminit.text) __cold notrace add_latent_entropy
62933 #define __meminitdata __section(.meminit.data)
62934 #define __meminitconst __section(.meminit.rodata)
62935 #define __memexit __section(.memexit.text) __exitused __cold notrace
62936diff --git a/include/linux/init_task.h b/include/linux/init_task.h
62937index 89f1cb1..7986c0f 100644
62938--- a/include/linux/init_task.h
62939+++ b/include/linux/init_task.h
62940@@ -143,6 +143,12 @@ extern struct task_group root_task_group;
62941
62942 #define INIT_TASK_COMM "swapper"
62943
62944+#ifdef CONFIG_X86
62945+#define INIT_TASK_THREAD_INFO .tinfo = INIT_THREAD_INFO,
62946+#else
62947+#define INIT_TASK_THREAD_INFO
62948+#endif
62949+
62950 /*
62951 * INIT_TASK is used to set up the first task table, touch at
62952 * your own risk!. Base=0, limit=0x1fffff (=2MB)
62953@@ -182,6 +188,7 @@ extern struct task_group root_task_group;
62954 RCU_POINTER_INITIALIZER(cred, &init_cred), \
62955 .comm = INIT_TASK_COMM, \
62956 .thread = INIT_THREAD, \
62957+ INIT_TASK_THREAD_INFO \
62958 .fs = &init_fs, \
62959 .files = &init_files, \
62960 .signal = &init_signals, \
62961diff --git a/include/linux/intel-iommu.h b/include/linux/intel-iommu.h
62962index 78e2ada..745564d 100644
62963--- a/include/linux/intel-iommu.h
62964+++ b/include/linux/intel-iommu.h
62965@@ -296,7 +296,7 @@ struct iommu_flush {
62966 u8 fm, u64 type);
62967 void (*flush_iotlb)(struct intel_iommu *iommu, u16 did, u64 addr,
62968 unsigned int size_order, u64 type);
62969-};
62970+} __no_const;
62971
62972 enum {
62973 SR_DMAR_FECTL_REG,
62974diff --git a/include/linux/interrupt.h b/include/linux/interrupt.h
62975index c5f856a..d29c117 100644
62976--- a/include/linux/interrupt.h
62977+++ b/include/linux/interrupt.h
62978@@ -433,7 +433,7 @@ enum
62979 /* map softirq index to softirq name. update 'softirq_to_name' in
62980 * kernel/softirq.c when adding a new softirq.
62981 */
62982-extern char *softirq_to_name[NR_SOFTIRQS];
62983+extern const char * const softirq_to_name[NR_SOFTIRQS];
62984
62985 /* softirq mask and active fields moved to irq_cpustat_t in
62986 * asm/hardirq.h to get better cache usage. KAO
62987@@ -441,12 +441,12 @@ extern char *softirq_to_name[NR_SOFTIRQS];
62988
62989 struct softirq_action
62990 {
62991- void (*action)(struct softirq_action *);
62992+ void (*action)(void);
62993 };
62994
62995 asmlinkage void do_softirq(void);
62996 asmlinkage void __do_softirq(void);
62997-extern void open_softirq(int nr, void (*action)(struct softirq_action *));
62998+extern void open_softirq(int nr, void (*action)(void));
62999 extern void softirq_init(void);
63000 extern void __raise_softirq_irqoff(unsigned int nr);
63001
63002diff --git a/include/linux/kallsyms.h b/include/linux/kallsyms.h
63003index 6883e19..06992b1 100644
63004--- a/include/linux/kallsyms.h
63005+++ b/include/linux/kallsyms.h
63006@@ -15,7 +15,8 @@
63007
63008 struct module;
63009
63010-#ifdef CONFIG_KALLSYMS
63011+#if !defined(__INCLUDED_BY_HIDESYM) || !defined(CONFIG_KALLSYMS)
63012+#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
63013 /* Lookup the address for a symbol. Returns 0 if not found. */
63014 unsigned long kallsyms_lookup_name(const char *name);
63015
63016@@ -106,6 +107,17 @@ static inline int lookup_symbol_attrs(unsigned long addr, unsigned long *size, u
63017 /* Stupid that this does nothing, but I didn't create this mess. */
63018 #define __print_symbol(fmt, addr)
63019 #endif /*CONFIG_KALLSYMS*/
63020+#else /* when included by kallsyms.c, vsnprintf.c, or
63021+ arch/x86/kernel/dumpstack.c, with HIDESYM enabled */
63022+extern void __print_symbol(const char *fmt, unsigned long address);
63023+extern int sprint_backtrace(char *buffer, unsigned long address);
63024+extern int sprint_symbol(char *buffer, unsigned long address);
63025+extern int sprint_symbol_no_offset(char *buffer, unsigned long address);
63026+const char *kallsyms_lookup(unsigned long addr,
63027+ unsigned long *symbolsize,
63028+ unsigned long *offset,
63029+ char **modname, char *namebuf);
63030+#endif
63031
63032 /* This macro allows us to keep printk typechecking */
63033 static __printf(1, 2)
63034diff --git a/include/linux/kgdb.h b/include/linux/kgdb.h
63035index c4d2fc1..5df9c19 100644
63036--- a/include/linux/kgdb.h
63037+++ b/include/linux/kgdb.h
63038@@ -53,7 +53,7 @@ extern int kgdb_connected;
63039 extern int kgdb_io_module_registered;
63040
63041 extern atomic_t kgdb_setting_breakpoint;
63042-extern atomic_t kgdb_cpu_doing_single_step;
63043+extern atomic_unchecked_t kgdb_cpu_doing_single_step;
63044
63045 extern struct task_struct *kgdb_usethread;
63046 extern struct task_struct *kgdb_contthread;
63047@@ -252,7 +252,7 @@ struct kgdb_arch {
63048 void (*disable_hw_break)(struct pt_regs *regs);
63049 void (*remove_all_hw_break)(void);
63050 void (*correct_hw_break)(void);
63051-};
63052+} __do_const;
63053
63054 /**
63055 * struct kgdb_io - Describe the interface for an I/O driver to talk with KGDB.
63056@@ -277,7 +277,7 @@ struct kgdb_io {
63057 void (*pre_exception) (void);
63058 void (*post_exception) (void);
63059 int is_console;
63060-};
63061+} __do_const;
63062
63063 extern struct kgdb_arch arch_kgdb_ops;
63064
63065diff --git a/include/linux/kmod.h b/include/linux/kmod.h
63066index 5398d58..5883a34 100644
63067--- a/include/linux/kmod.h
63068+++ b/include/linux/kmod.h
63069@@ -34,6 +34,8 @@ extern char modprobe_path[]; /* for sysctl */
63070 * usually useless though. */
63071 extern __printf(2, 3)
63072 int __request_module(bool wait, const char *name, ...);
63073+extern __printf(3, 4)
63074+int ___request_module(bool wait, char *param_name, const char *name, ...);
63075 #define request_module(mod...) __request_module(true, mod)
63076 #define request_module_nowait(mod...) __request_module(false, mod)
63077 #define try_then_request_module(x, mod...) \
63078diff --git a/include/linux/kref.h b/include/linux/kref.h
63079index 65af688..0592677 100644
63080--- a/include/linux/kref.h
63081+++ b/include/linux/kref.h
63082@@ -64,7 +64,7 @@ static inline void kref_get(struct kref *kref)
63083 static inline int kref_sub(struct kref *kref, unsigned int count,
63084 void (*release)(struct kref *kref))
63085 {
63086- WARN_ON(release == NULL);
63087+ BUG_ON(release == NULL);
63088
63089 if (atomic_sub_and_test((int) count, &kref->refcount)) {
63090 release(kref);
63091diff --git a/include/linux/kvm_host.h b/include/linux/kvm_host.h
63092index b70b48b..0d7153b 100644
63093--- a/include/linux/kvm_host.h
63094+++ b/include/linux/kvm_host.h
63095@@ -351,7 +351,7 @@ void kvm_vcpu_uninit(struct kvm_vcpu *vcpu);
63096 void vcpu_load(struct kvm_vcpu *vcpu);
63097 void vcpu_put(struct kvm_vcpu *vcpu);
63098
63099-int kvm_init(void *opaque, unsigned vcpu_size, unsigned vcpu_align,
63100+int kvm_init(const void *opaque, unsigned vcpu_size, unsigned vcpu_align,
63101 struct module *module);
63102 void kvm_exit(void);
63103
63104@@ -517,7 +517,7 @@ int kvm_arch_vcpu_ioctl_set_guest_debug(struct kvm_vcpu *vcpu,
63105 struct kvm_guest_debug *dbg);
63106 int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu, struct kvm_run *kvm_run);
63107
63108-int kvm_arch_init(void *opaque);
63109+int kvm_arch_init(const void *opaque);
63110 void kvm_arch_exit(void);
63111
63112 int kvm_arch_vcpu_init(struct kvm_vcpu *vcpu);
63113diff --git a/include/linux/libata.h b/include/linux/libata.h
63114index 64f90e1..32b945b 100644
63115--- a/include/linux/libata.h
63116+++ b/include/linux/libata.h
63117@@ -909,7 +909,7 @@ struct ata_port_operations {
63118 * fields must be pointers.
63119 */
63120 const struct ata_port_operations *inherits;
63121-};
63122+} __do_const;
63123
63124 struct ata_port_info {
63125 unsigned long flags;
63126diff --git a/include/linux/memory.h b/include/linux/memory.h
63127index ff9a9f8..c715deb 100644
63128--- a/include/linux/memory.h
63129+++ b/include/linux/memory.h
63130@@ -143,7 +143,7 @@ struct memory_accessor {
63131 size_t count);
63132 ssize_t (*write)(struct memory_accessor *, const char *buf,
63133 off_t offset, size_t count);
63134-};
63135+} __no_const;
63136
63137 /*
63138 * Kernel text modification mutex, used for code patching. Users of this lock
63139diff --git a/include/linux/mfd/abx500.h b/include/linux/mfd/abx500.h
63140index 1318ca6..7521340 100644
63141--- a/include/linux/mfd/abx500.h
63142+++ b/include/linux/mfd/abx500.h
63143@@ -452,6 +452,7 @@ struct abx500_ops {
63144 int (*event_registers_startup_state_get) (struct device *, u8 *);
63145 int (*startup_irq_enabled) (struct device *, unsigned int);
63146 };
63147+typedef struct abx500_ops __no_const abx500_ops_no_const;
63148
63149 int abx500_register_ops(struct device *core_dev, struct abx500_ops *ops);
63150 void abx500_remove_ops(struct device *dev);
63151diff --git a/include/linux/mfd/abx500/ux500_chargalg.h b/include/linux/mfd/abx500/ux500_chargalg.h
63152index 9b07725..3d55001 100644
63153--- a/include/linux/mfd/abx500/ux500_chargalg.h
63154+++ b/include/linux/mfd/abx500/ux500_chargalg.h
63155@@ -19,7 +19,7 @@ struct ux500_charger_ops {
63156 int (*enable) (struct ux500_charger *, int, int, int);
63157 int (*kick_wd) (struct ux500_charger *);
63158 int (*update_curr) (struct ux500_charger *, int);
63159-};
63160+} __no_const;
63161
63162 /**
63163 * struct ux500_charger - power supply ux500 charger sub class
63164diff --git a/include/linux/mm.h b/include/linux/mm.h
63165index 311be90..5f1638c 100644
63166--- a/include/linux/mm.h
63167+++ b/include/linux/mm.h
63168@@ -116,7 +116,14 @@ extern unsigned int kobjsize(const void *objp);
63169
63170 #define VM_CAN_NONLINEAR 0x08000000 /* Has ->fault & does nonlinear pages */
63171 #define VM_MIXEDMAP 0x10000000 /* Can contain "struct page" and pure PFN pages */
63172+
63173+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
63174+#define VM_SAO 0x00000000 /* Strong Access Ordering (powerpc) */
63175+#define VM_PAGEEXEC 0x20000000 /* vma->vm_page_prot needs special handling */
63176+#else
63177 #define VM_SAO 0x20000000 /* Strong Access Ordering (powerpc) */
63178+#endif
63179+
63180 #define VM_PFN_AT_MMAP 0x40000000 /* PFNMAP vma that is fully mapped at mmap time */
63181 #define VM_MERGEABLE 0x80000000 /* KSM may merge identical pages */
63182
63183@@ -1038,34 +1045,6 @@ int set_page_dirty(struct page *page);
63184 int set_page_dirty_lock(struct page *page);
63185 int clear_page_dirty_for_io(struct page *page);
63186
63187-/* Is the vma a continuation of the stack vma above it? */
63188-static inline int vma_growsdown(struct vm_area_struct *vma, unsigned long addr)
63189-{
63190- return vma && (vma->vm_end == addr) && (vma->vm_flags & VM_GROWSDOWN);
63191-}
63192-
63193-static inline int stack_guard_page_start(struct vm_area_struct *vma,
63194- unsigned long addr)
63195-{
63196- return (vma->vm_flags & VM_GROWSDOWN) &&
63197- (vma->vm_start == addr) &&
63198- !vma_growsdown(vma->vm_prev, addr);
63199-}
63200-
63201-/* Is the vma a continuation of the stack vma below it? */
63202-static inline int vma_growsup(struct vm_area_struct *vma, unsigned long addr)
63203-{
63204- return vma && (vma->vm_start == addr) && (vma->vm_flags & VM_GROWSUP);
63205-}
63206-
63207-static inline int stack_guard_page_end(struct vm_area_struct *vma,
63208- unsigned long addr)
63209-{
63210- return (vma->vm_flags & VM_GROWSUP) &&
63211- (vma->vm_end == addr) &&
63212- !vma_growsup(vma->vm_next, addr);
63213-}
63214-
63215 extern pid_t
63216 vm_is_stack(struct task_struct *task, struct vm_area_struct *vma, int in_group);
63217
63218@@ -1164,6 +1143,15 @@ static inline void sync_mm_rss(struct mm_struct *mm)
63219 }
63220 #endif
63221
63222+#ifdef CONFIG_MMU
63223+pgprot_t vm_get_page_prot(vm_flags_t vm_flags);
63224+#else
63225+static inline pgprot_t vm_get_page_prot(vm_flags_t vm_flags)
63226+{
63227+ return __pgprot(0);
63228+}
63229+#endif
63230+
63231 int vma_wants_writenotify(struct vm_area_struct *vma);
63232
63233 extern pte_t *__get_locked_pte(struct mm_struct *mm, unsigned long addr,
63234@@ -1182,8 +1170,15 @@ static inline int __pud_alloc(struct mm_struct *mm, pgd_t *pgd,
63235 {
63236 return 0;
63237 }
63238+
63239+static inline int __pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd,
63240+ unsigned long address)
63241+{
63242+ return 0;
63243+}
63244 #else
63245 int __pud_alloc(struct mm_struct *mm, pgd_t *pgd, unsigned long address);
63246+int __pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd, unsigned long address);
63247 #endif
63248
63249 #ifdef __PAGETABLE_PMD_FOLDED
63250@@ -1192,8 +1187,15 @@ static inline int __pmd_alloc(struct mm_struct *mm, pud_t *pud,
63251 {
63252 return 0;
63253 }
63254+
63255+static inline int __pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud,
63256+ unsigned long address)
63257+{
63258+ return 0;
63259+}
63260 #else
63261 int __pmd_alloc(struct mm_struct *mm, pud_t *pud, unsigned long address);
63262+int __pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud, unsigned long address);
63263 #endif
63264
63265 int __pte_alloc(struct mm_struct *mm, struct vm_area_struct *vma,
63266@@ -1211,11 +1213,23 @@ static inline pud_t *pud_alloc(struct mm_struct *mm, pgd_t *pgd, unsigned long a
63267 NULL: pud_offset(pgd, address);
63268 }
63269
63270+static inline pud_t *pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd, unsigned long address)
63271+{
63272+ return (unlikely(pgd_none(*pgd)) && __pud_alloc_kernel(mm, pgd, address))?
63273+ NULL: pud_offset(pgd, address);
63274+}
63275+
63276 static inline pmd_t *pmd_alloc(struct mm_struct *mm, pud_t *pud, unsigned long address)
63277 {
63278 return (unlikely(pud_none(*pud)) && __pmd_alloc(mm, pud, address))?
63279 NULL: pmd_offset(pud, address);
63280 }
63281+
63282+static inline pmd_t *pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud, unsigned long address)
63283+{
63284+ return (unlikely(pud_none(*pud)) && __pmd_alloc_kernel(mm, pud, address))?
63285+ NULL: pmd_offset(pud, address);
63286+}
63287 #endif /* CONFIG_MMU && !__ARCH_HAS_4LEVEL_HACK */
63288
63289 #if USE_SPLIT_PTLOCKS
63290@@ -1426,6 +1440,7 @@ extern unsigned long do_mmap_pgoff(struct file *, unsigned long,
63291 unsigned long, unsigned long,
63292 unsigned long, unsigned long);
63293 extern int do_munmap(struct mm_struct *, unsigned long, size_t);
63294+extern int __do_munmap(struct mm_struct *, unsigned long, size_t);
63295
63296 /* These take the mm semaphore themselves */
63297 extern unsigned long vm_brk(unsigned long, unsigned long);
63298@@ -1489,6 +1504,10 @@ extern struct vm_area_struct * find_vma(struct mm_struct * mm, unsigned long add
63299 extern struct vm_area_struct * find_vma_prev(struct mm_struct * mm, unsigned long addr,
63300 struct vm_area_struct **pprev);
63301
63302+extern struct vm_area_struct *pax_find_mirror_vma(struct vm_area_struct *vma);
63303+extern __must_check long pax_mirror_vma(struct vm_area_struct *vma_m, struct vm_area_struct *vma);
63304+extern void pax_mirror_file_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m, spinlock_t *ptl);
63305+
63306 /* Look up the first VMA which intersects the interval start_addr..end_addr-1,
63307 NULL if none. Assume start_addr < end_addr. */
63308 static inline struct vm_area_struct * find_vma_intersection(struct mm_struct * mm, unsigned long start_addr, unsigned long end_addr)
63309@@ -1517,15 +1536,6 @@ static inline struct vm_area_struct *find_exact_vma(struct mm_struct *mm,
63310 return vma;
63311 }
63312
63313-#ifdef CONFIG_MMU
63314-pgprot_t vm_get_page_prot(unsigned long vm_flags);
63315-#else
63316-static inline pgprot_t vm_get_page_prot(unsigned long vm_flags)
63317-{
63318- return __pgprot(0);
63319-}
63320-#endif
63321-
63322 struct vm_area_struct *find_extend_vma(struct mm_struct *, unsigned long addr);
63323 int remap_pfn_range(struct vm_area_struct *, unsigned long addr,
63324 unsigned long pfn, unsigned long size, pgprot_t);
63325@@ -1631,7 +1641,7 @@ extern int unpoison_memory(unsigned long pfn);
63326 extern int sysctl_memory_failure_early_kill;
63327 extern int sysctl_memory_failure_recovery;
63328 extern void shake_page(struct page *p, int access);
63329-extern atomic_long_t mce_bad_pages;
63330+extern atomic_long_unchecked_t mce_bad_pages;
63331 extern int soft_offline_page(struct page *page, int flags);
63332
63333 extern void dump_page(struct page *page);
63334@@ -1662,5 +1672,11 @@ static inline unsigned int debug_guardpage_minorder(void) { return 0; }
63335 static inline bool page_is_guard(struct page *page) { return false; }
63336 #endif /* CONFIG_DEBUG_PAGEALLOC */
63337
63338+#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
63339+extern void track_exec_limit(struct mm_struct *mm, unsigned long start, unsigned long end, unsigned long prot);
63340+#else
63341+static inline void track_exec_limit(struct mm_struct *mm, unsigned long start, unsigned long end, unsigned long prot) {}
63342+#endif
63343+
63344 #endif /* __KERNEL__ */
63345 #endif /* _LINUX_MM_H */
63346diff --git a/include/linux/mm_types.h b/include/linux/mm_types.h
63347index bf78672..debc693 100644
63348--- a/include/linux/mm_types.h
63349+++ b/include/linux/mm_types.h
63350@@ -279,6 +279,8 @@ struct vm_area_struct {
63351 #ifdef CONFIG_NUMA
63352 struct mempolicy *vm_policy; /* NUMA policy for the VMA */
63353 #endif
63354+
63355+ struct vm_area_struct *vm_mirror;/* PaX: mirror vma or NULL */
63356 };
63357
63358 struct core_thread {
63359@@ -353,7 +355,7 @@ struct mm_struct {
63360 unsigned long def_flags;
63361 unsigned long nr_ptes; /* Page table pages */
63362 unsigned long start_code, end_code, start_data, end_data;
63363- unsigned long start_brk, brk, start_stack;
63364+ unsigned long brk_gap, start_brk, brk, start_stack;
63365 unsigned long arg_start, arg_end, env_start, env_end;
63366
63367 unsigned long saved_auxv[AT_VECTOR_SIZE]; /* for /proc/PID/auxv */
63368@@ -405,6 +407,24 @@ struct mm_struct {
63369 struct cpumask cpumask_allocation;
63370 #endif
63371 struct uprobes_state uprobes_state;
63372+
63373+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
63374+ unsigned long pax_flags;
63375+#endif
63376+
63377+#ifdef CONFIG_PAX_DLRESOLVE
63378+ unsigned long call_dl_resolve;
63379+#endif
63380+
63381+#if defined(CONFIG_PPC32) && defined(CONFIG_PAX_EMUSIGRT)
63382+ unsigned long call_syscall;
63383+#endif
63384+
63385+#ifdef CONFIG_PAX_ASLR
63386+ unsigned long delta_mmap; /* randomized offset */
63387+ unsigned long delta_stack; /* randomized offset */
63388+#endif
63389+
63390 };
63391
63392 static inline void mm_init_cpumask(struct mm_struct *mm)
63393diff --git a/include/linux/mmu_notifier.h b/include/linux/mmu_notifier.h
63394index 1d1b1e1..2a13c78 100644
63395--- a/include/linux/mmu_notifier.h
63396+++ b/include/linux/mmu_notifier.h
63397@@ -255,12 +255,12 @@ static inline void mmu_notifier_mm_destroy(struct mm_struct *mm)
63398 */
63399 #define ptep_clear_flush_notify(__vma, __address, __ptep) \
63400 ({ \
63401- pte_t __pte; \
63402+ pte_t ___pte; \
63403 struct vm_area_struct *___vma = __vma; \
63404 unsigned long ___address = __address; \
63405- __pte = ptep_clear_flush(___vma, ___address, __ptep); \
63406+ ___pte = ptep_clear_flush(___vma, ___address, __ptep); \
63407 mmu_notifier_invalidate_page(___vma->vm_mm, ___address); \
63408- __pte; \
63409+ ___pte; \
63410 })
63411
63412 #define pmdp_clear_flush_notify(__vma, __address, __pmdp) \
63413diff --git a/include/linux/mmzone.h b/include/linux/mmzone.h
63414index 2daa54f..bfdf2f5 100644
63415--- a/include/linux/mmzone.h
63416+++ b/include/linux/mmzone.h
63417@@ -414,7 +414,7 @@ struct zone {
63418 unsigned long flags; /* zone flags, see below */
63419
63420 /* Zone statistics */
63421- atomic_long_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
63422+ atomic_long_unchecked_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
63423
63424 /*
63425 * The target ratio of ACTIVE_ANON to INACTIVE_ANON pages on
63426diff --git a/include/linux/mod_devicetable.h b/include/linux/mod_devicetable.h
63427index 6955045..ebdb7cd 100644
63428--- a/include/linux/mod_devicetable.h
63429+++ b/include/linux/mod_devicetable.h
63430@@ -12,7 +12,7 @@
63431 typedef unsigned long kernel_ulong_t;
63432 #endif
63433
63434-#define PCI_ANY_ID (~0)
63435+#define PCI_ANY_ID ((__u16)~0)
63436
63437 struct pci_device_id {
63438 __u32 vendor, device; /* Vendor and device ID or PCI_ANY_ID*/
63439@@ -139,7 +139,7 @@ struct usb_device_id {
63440 #define USB_DEVICE_ID_MATCH_INT_PROTOCOL 0x0200
63441 #define USB_DEVICE_ID_MATCH_INT_NUMBER 0x0400
63442
63443-#define HID_ANY_ID (~0)
63444+#define HID_ANY_ID (~0U)
63445 #define HID_BUS_ANY 0xffff
63446 #define HID_GROUP_ANY 0x0000
63447
63448diff --git a/include/linux/module.h b/include/linux/module.h
63449index fbcafe2..e5d9587 100644
63450--- a/include/linux/module.h
63451+++ b/include/linux/module.h
63452@@ -17,6 +17,7 @@
63453 #include <linux/moduleparam.h>
63454 #include <linux/tracepoint.h>
63455 #include <linux/export.h>
63456+#include <linux/fs.h>
63457
63458 #include <linux/percpu.h>
63459 #include <asm/module.h>
63460@@ -273,19 +274,16 @@ struct module
63461 int (*init)(void);
63462
63463 /* If this is non-NULL, vfree after init() returns */
63464- void *module_init;
63465+ void *module_init_rx, *module_init_rw;
63466
63467 /* Here is the actual code + data, vfree'd on unload. */
63468- void *module_core;
63469+ void *module_core_rx, *module_core_rw;
63470
63471 /* Here are the sizes of the init and core sections */
63472- unsigned int init_size, core_size;
63473+ unsigned int init_size_rw, core_size_rw;
63474
63475 /* The size of the executable code in each section. */
63476- unsigned int init_text_size, core_text_size;
63477-
63478- /* Size of RO sections of the module (text+rodata) */
63479- unsigned int init_ro_size, core_ro_size;
63480+ unsigned int init_size_rx, core_size_rx;
63481
63482 /* Arch-specific module values */
63483 struct mod_arch_specific arch;
63484@@ -341,6 +339,10 @@ struct module
63485 #ifdef CONFIG_EVENT_TRACING
63486 struct ftrace_event_call **trace_events;
63487 unsigned int num_trace_events;
63488+ struct file_operations trace_id;
63489+ struct file_operations trace_enable;
63490+ struct file_operations trace_format;
63491+ struct file_operations trace_filter;
63492 #endif
63493 #ifdef CONFIG_FTRACE_MCOUNT_RECORD
63494 unsigned int num_ftrace_callsites;
63495@@ -388,16 +390,46 @@ bool is_module_address(unsigned long addr);
63496 bool is_module_percpu_address(unsigned long addr);
63497 bool is_module_text_address(unsigned long addr);
63498
63499+static inline int within_module_range(unsigned long addr, void *start, unsigned long size)
63500+{
63501+
63502+#ifdef CONFIG_PAX_KERNEXEC
63503+ if (ktla_ktva(addr) >= (unsigned long)start &&
63504+ ktla_ktva(addr) < (unsigned long)start + size)
63505+ return 1;
63506+#endif
63507+
63508+ return ((void *)addr >= start && (void *)addr < start + size);
63509+}
63510+
63511+static inline int within_module_core_rx(unsigned long addr, struct module *mod)
63512+{
63513+ return within_module_range(addr, mod->module_core_rx, mod->core_size_rx);
63514+}
63515+
63516+static inline int within_module_core_rw(unsigned long addr, struct module *mod)
63517+{
63518+ return within_module_range(addr, mod->module_core_rw, mod->core_size_rw);
63519+}
63520+
63521+static inline int within_module_init_rx(unsigned long addr, struct module *mod)
63522+{
63523+ return within_module_range(addr, mod->module_init_rx, mod->init_size_rx);
63524+}
63525+
63526+static inline int within_module_init_rw(unsigned long addr, struct module *mod)
63527+{
63528+ return within_module_range(addr, mod->module_init_rw, mod->init_size_rw);
63529+}
63530+
63531 static inline int within_module_core(unsigned long addr, struct module *mod)
63532 {
63533- return (unsigned long)mod->module_core <= addr &&
63534- addr < (unsigned long)mod->module_core + mod->core_size;
63535+ return within_module_core_rx(addr, mod) || within_module_core_rw(addr, mod);
63536 }
63537
63538 static inline int within_module_init(unsigned long addr, struct module *mod)
63539 {
63540- return (unsigned long)mod->module_init <= addr &&
63541- addr < (unsigned long)mod->module_init + mod->init_size;
63542+ return within_module_init_rx(addr, mod) || within_module_init_rw(addr, mod);
63543 }
63544
63545 /* Search for module by name: must hold module_mutex. */
63546diff --git a/include/linux/moduleloader.h b/include/linux/moduleloader.h
63547index b2be02e..72d2f78 100644
63548--- a/include/linux/moduleloader.h
63549+++ b/include/linux/moduleloader.h
63550@@ -23,11 +23,23 @@ unsigned int arch_mod_section_prepend(struct module *mod, unsigned int section);
63551
63552 /* Allocator used for allocating struct module, core sections and init
63553 sections. Returns NULL on failure. */
63554-void *module_alloc(unsigned long size);
63555+void *module_alloc(unsigned long size) __size_overflow(1);
63556+
63557+#ifdef CONFIG_PAX_KERNEXEC
63558+void *module_alloc_exec(unsigned long size) __size_overflow(1);
63559+#else
63560+#define module_alloc_exec(x) module_alloc(x)
63561+#endif
63562
63563 /* Free memory returned from module_alloc. */
63564 void module_free(struct module *mod, void *module_region);
63565
63566+#ifdef CONFIG_PAX_KERNEXEC
63567+void module_free_exec(struct module *mod, void *module_region);
63568+#else
63569+#define module_free_exec(x, y) module_free((x), (y))
63570+#endif
63571+
63572 /* Apply the given relocation to the (simplified) ELF. Return -error
63573 or 0. */
63574 int apply_relocate(Elf_Shdr *sechdrs,
63575diff --git a/include/linux/moduleparam.h b/include/linux/moduleparam.h
63576index d6a5806..7c13347 100644
63577--- a/include/linux/moduleparam.h
63578+++ b/include/linux/moduleparam.h
63579@@ -286,7 +286,7 @@ static inline void __kernel_param_unlock(void)
63580 * @len is usually just sizeof(string).
63581 */
63582 #define module_param_string(name, string, len, perm) \
63583- static const struct kparam_string __param_string_##name \
63584+ static const struct kparam_string __param_string_##name __used \
63585 = { len, string }; \
63586 __module_param_call(MODULE_PARAM_PREFIX, name, \
63587 &param_ops_string, \
63588@@ -425,7 +425,7 @@ extern int param_set_bint(const char *val, const struct kernel_param *kp);
63589 */
63590 #define module_param_array_named(name, array, type, nump, perm) \
63591 param_check_##type(name, &(array)[0]); \
63592- static const struct kparam_array __param_arr_##name \
63593+ static const struct kparam_array __param_arr_##name __used \
63594 = { .max = ARRAY_SIZE(array), .num = nump, \
63595 .ops = &param_ops_##type, \
63596 .elemsize = sizeof(array[0]), .elem = array }; \
63597diff --git a/include/linux/namei.h b/include/linux/namei.h
63598index 4bf19d8..5268cea 100644
63599--- a/include/linux/namei.h
63600+++ b/include/linux/namei.h
63601@@ -18,7 +18,7 @@ struct nameidata {
63602 unsigned seq;
63603 int last_type;
63604 unsigned depth;
63605- char *saved_names[MAX_NESTED_LINKS + 1];
63606+ const char *saved_names[MAX_NESTED_LINKS + 1];
63607 };
63608
63609 /*
63610@@ -83,12 +83,12 @@ extern void unlock_rename(struct dentry *, struct dentry *);
63611
63612 extern void nd_jump_link(struct nameidata *nd, struct path *path);
63613
63614-static inline void nd_set_link(struct nameidata *nd, char *path)
63615+static inline void nd_set_link(struct nameidata *nd, const char *path)
63616 {
63617 nd->saved_names[nd->depth] = path;
63618 }
63619
63620-static inline char *nd_get_link(struct nameidata *nd)
63621+static inline const char *nd_get_link(const struct nameidata *nd)
63622 {
63623 return nd->saved_names[nd->depth];
63624 }
63625diff --git a/include/linux/netdevice.h b/include/linux/netdevice.h
63626index 59dc05f3..c905a34 100644
63627--- a/include/linux/netdevice.h
63628+++ b/include/linux/netdevice.h
63629@@ -1027,6 +1027,7 @@ struct net_device_ops {
63630 struct net_device *dev,
63631 int idx);
63632 };
63633+typedef struct net_device_ops __no_const net_device_ops_no_const;
63634
63635 /*
63636 * The DEVICE structure.
63637@@ -1087,7 +1088,7 @@ struct net_device {
63638 int iflink;
63639
63640 struct net_device_stats stats;
63641- atomic_long_t rx_dropped; /* dropped packets by core network
63642+ atomic_long_unchecked_t rx_dropped; /* dropped packets by core network
63643 * Do not use this in drivers.
63644 */
63645
63646diff --git a/include/linux/netfilter/xt_gradm.h b/include/linux/netfilter/xt_gradm.h
63647new file mode 100644
63648index 0000000..33f4af8
63649--- /dev/null
63650+++ b/include/linux/netfilter/xt_gradm.h
63651@@ -0,0 +1,9 @@
63652+#ifndef _LINUX_NETFILTER_XT_GRADM_H
63653+#define _LINUX_NETFILTER_XT_GRADM_H 1
63654+
63655+struct xt_gradm_mtinfo {
63656+ __u16 flags;
63657+ __u16 invflags;
63658+};
63659+
63660+#endif
63661diff --git a/include/linux/of_pdt.h b/include/linux/of_pdt.h
63662index c65a18a..0c05f3a 100644
63663--- a/include/linux/of_pdt.h
63664+++ b/include/linux/of_pdt.h
63665@@ -32,7 +32,7 @@ struct of_pdt_ops {
63666
63667 /* return 0 on success; fill in 'len' with number of bytes in path */
63668 int (*pkg2path)(phandle node, char *buf, const int buflen, int *len);
63669-};
63670+} __no_const;
63671
63672 extern void *prom_early_alloc(unsigned long size);
63673
63674diff --git a/include/linux/oprofile.h b/include/linux/oprofile.h
63675index a4c5624..79d6d88 100644
63676--- a/include/linux/oprofile.h
63677+++ b/include/linux/oprofile.h
63678@@ -139,9 +139,9 @@ int oprofilefs_create_ulong(struct super_block * sb, struct dentry * root,
63679 int oprofilefs_create_ro_ulong(struct super_block * sb, struct dentry * root,
63680 char const * name, ulong * val);
63681
63682-/** Create a file for read-only access to an atomic_t. */
63683+/** Create a file for read-only access to an atomic_unchecked_t. */
63684 int oprofilefs_create_ro_atomic(struct super_block * sb, struct dentry * root,
63685- char const * name, atomic_t * val);
63686+ char const * name, atomic_unchecked_t * val);
63687
63688 /** create a directory */
63689 struct dentry * oprofilefs_mkdir(struct super_block * sb, struct dentry * root,
63690diff --git a/include/linux/perf_event.h b/include/linux/perf_event.h
63691index bdb4161..f373d41 100644
63692--- a/include/linux/perf_event.h
63693+++ b/include/linux/perf_event.h
63694@@ -882,8 +882,8 @@ struct perf_event {
63695
63696 enum perf_event_active_state state;
63697 unsigned int attach_state;
63698- local64_t count;
63699- atomic64_t child_count;
63700+ local64_t count; /* PaX: fix it one day */
63701+ atomic64_unchecked_t child_count;
63702
63703 /*
63704 * These are the total time in nanoseconds that the event
63705@@ -934,8 +934,8 @@ struct perf_event {
63706 * These accumulate total time (in nanoseconds) that children
63707 * events have been enabled and running, respectively.
63708 */
63709- atomic64_t child_total_time_enabled;
63710- atomic64_t child_total_time_running;
63711+ atomic64_unchecked_t child_total_time_enabled;
63712+ atomic64_unchecked_t child_total_time_running;
63713
63714 /*
63715 * Protect attach/detach and child_list:
63716diff --git a/include/linux/personality.h b/include/linux/personality.h
63717index 8fc7dd1a..c19d89e 100644
63718--- a/include/linux/personality.h
63719+++ b/include/linux/personality.h
63720@@ -44,6 +44,7 @@ enum {
63721 #define PER_CLEAR_ON_SETID (READ_IMPLIES_EXEC | \
63722 ADDR_NO_RANDOMIZE | \
63723 ADDR_COMPAT_LAYOUT | \
63724+ ADDR_LIMIT_3GB | \
63725 MMAP_PAGE_ZERO)
63726
63727 /*
63728diff --git a/include/linux/pipe_fs_i.h b/include/linux/pipe_fs_i.h
63729index ad1a427..6419649 100644
63730--- a/include/linux/pipe_fs_i.h
63731+++ b/include/linux/pipe_fs_i.h
63732@@ -45,9 +45,9 @@ struct pipe_buffer {
63733 struct pipe_inode_info {
63734 wait_queue_head_t wait;
63735 unsigned int nrbufs, curbuf, buffers;
63736- unsigned int readers;
63737- unsigned int writers;
63738- unsigned int waiting_writers;
63739+ atomic_t readers;
63740+ atomic_t writers;
63741+ atomic_t waiting_writers;
63742 unsigned int r_counter;
63743 unsigned int w_counter;
63744 struct page *tmp_page;
63745diff --git a/include/linux/pm_runtime.h b/include/linux/pm_runtime.h
63746index f271860..6b3bec5 100644
63747--- a/include/linux/pm_runtime.h
63748+++ b/include/linux/pm_runtime.h
63749@@ -97,7 +97,7 @@ static inline bool pm_runtime_callbacks_present(struct device *dev)
63750
63751 static inline void pm_runtime_mark_last_busy(struct device *dev)
63752 {
63753- ACCESS_ONCE(dev->power.last_busy) = jiffies;
63754+ ACCESS_ONCE_RW(dev->power.last_busy) = jiffies;
63755 }
63756
63757 #else /* !CONFIG_PM_RUNTIME */
63758diff --git a/include/linux/poison.h b/include/linux/poison.h
63759index 2110a81..13a11bb 100644
63760--- a/include/linux/poison.h
63761+++ b/include/linux/poison.h
63762@@ -19,8 +19,8 @@
63763 * under normal circumstances, used to verify that nobody uses
63764 * non-initialized list entries.
63765 */
63766-#define LIST_POISON1 ((void *) 0x00100100 + POISON_POINTER_DELTA)
63767-#define LIST_POISON2 ((void *) 0x00200200 + POISON_POINTER_DELTA)
63768+#define LIST_POISON1 ((void *) (long)0xFFFFFF01)
63769+#define LIST_POISON2 ((void *) (long)0xFFFFFF02)
63770
63771 /********** include/linux/timer.h **********/
63772 /*
63773diff --git a/include/linux/preempt.h b/include/linux/preempt.h
63774index 5a710b9..0b0dab9 100644
63775--- a/include/linux/preempt.h
63776+++ b/include/linux/preempt.h
63777@@ -126,7 +126,7 @@ struct preempt_ops {
63778 void (*sched_in)(struct preempt_notifier *notifier, int cpu);
63779 void (*sched_out)(struct preempt_notifier *notifier,
63780 struct task_struct *next);
63781-};
63782+} __no_const;
63783
63784 /**
63785 * preempt_notifier - key for installing preemption notifiers
63786diff --git a/include/linux/printk.h b/include/linux/printk.h
63787index 9afc01e..92c32e8 100644
63788--- a/include/linux/printk.h
63789+++ b/include/linux/printk.h
63790@@ -101,6 +101,8 @@ void early_printk(const char *fmt, ...);
63791 extern int printk_needs_cpu(int cpu);
63792 extern void printk_tick(void);
63793
63794+extern int kptr_restrict;
63795+
63796 #ifdef CONFIG_PRINTK
63797 asmlinkage __printf(5, 0)
63798 int vprintk_emit(int facility, int level,
63799@@ -135,7 +137,6 @@ extern bool printk_timed_ratelimit(unsigned long *caller_jiffies,
63800
63801 extern int printk_delay_msec;
63802 extern int dmesg_restrict;
63803-extern int kptr_restrict;
63804
63805 void log_buf_kexec_setup(void);
63806 void __init setup_log_buf(int early);
63807diff --git a/include/linux/proc_fs.h b/include/linux/proc_fs.h
63808index 3fd2e87..d93a721 100644
63809--- a/include/linux/proc_fs.h
63810+++ b/include/linux/proc_fs.h
63811@@ -155,6 +155,18 @@ static inline struct proc_dir_entry *proc_create(const char *name, umode_t mode,
63812 return proc_create_data(name, mode, parent, proc_fops, NULL);
63813 }
63814
63815+static inline struct proc_dir_entry *proc_create_grsec(const char *name, umode_t mode,
63816+ struct proc_dir_entry *parent, const struct file_operations *proc_fops)
63817+{
63818+#ifdef CONFIG_GRKERNSEC_PROC_USER
63819+ return proc_create_data(name, S_IRUSR, parent, proc_fops, NULL);
63820+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
63821+ return proc_create_data(name, S_IRUSR | S_IRGRP, parent, proc_fops, NULL);
63822+#else
63823+ return proc_create_data(name, mode, parent, proc_fops, NULL);
63824+#endif
63825+}
63826+
63827 static inline struct proc_dir_entry *create_proc_read_entry(const char *name,
63828 umode_t mode, struct proc_dir_entry *base,
63829 read_proc_t *read_proc, void * data)
63830@@ -258,7 +270,7 @@ union proc_op {
63831 int (*proc_show)(struct seq_file *m,
63832 struct pid_namespace *ns, struct pid *pid,
63833 struct task_struct *task);
63834-};
63835+} __no_const;
63836
63837 struct ctl_table_header;
63838 struct ctl_table;
63839diff --git a/include/linux/random.h b/include/linux/random.h
63840index ac621ce..c1215f3 100644
63841--- a/include/linux/random.h
63842+++ b/include/linux/random.h
63843@@ -53,6 +53,10 @@ extern void add_input_randomness(unsigned int type, unsigned int code,
63844 unsigned int value);
63845 extern void add_interrupt_randomness(int irq, int irq_flags);
63846
63847+#ifdef CONFIG_PAX_LATENT_ENTROPY
63848+extern void transfer_latent_entropy(void);
63849+#endif
63850+
63851 extern void get_random_bytes(void *buf, int nbytes);
63852 extern void get_random_bytes_arch(void *buf, int nbytes);
63853 void generate_random_uuid(unsigned char uuid_out[16]);
63854@@ -69,12 +73,17 @@ void srandom32(u32 seed);
63855
63856 u32 prandom32(struct rnd_state *);
63857
63858+static inline unsigned long pax_get_random_long(void)
63859+{
63860+ return random32() + (sizeof(long) > 4 ? (unsigned long)random32() << 32 : 0);
63861+}
63862+
63863 /*
63864 * Handle minimum values for seeds
63865 */
63866 static inline u32 __seed(u32 x, u32 m)
63867 {
63868- return (x < m) ? x + m : x;
63869+ return (x <= m) ? x + m + 1 : x;
63870 }
63871
63872 /**
63873diff --git a/include/linux/reboot.h b/include/linux/reboot.h
63874index e0879a7..a12f962 100644
63875--- a/include/linux/reboot.h
63876+++ b/include/linux/reboot.h
63877@@ -52,9 +52,9 @@ extern int unregister_reboot_notifier(struct notifier_block *);
63878 * Architecture-specific implementations of sys_reboot commands.
63879 */
63880
63881-extern void machine_restart(char *cmd);
63882-extern void machine_halt(void);
63883-extern void machine_power_off(void);
63884+extern void machine_restart(char *cmd) __noreturn;
63885+extern void machine_halt(void) __noreturn;
63886+extern void machine_power_off(void) __noreturn;
63887
63888 extern void machine_shutdown(void);
63889 struct pt_regs;
63890@@ -65,9 +65,9 @@ extern void machine_crash_shutdown(struct pt_regs *);
63891 */
63892
63893 extern void kernel_restart_prepare(char *cmd);
63894-extern void kernel_restart(char *cmd);
63895-extern void kernel_halt(void);
63896-extern void kernel_power_off(void);
63897+extern void kernel_restart(char *cmd) __noreturn;
63898+extern void kernel_halt(void) __noreturn;
63899+extern void kernel_power_off(void) __noreturn;
63900
63901 extern int C_A_D; /* for sysctl */
63902 void ctrl_alt_del(void);
63903@@ -81,7 +81,7 @@ extern int orderly_poweroff(bool force);
63904 * Emergency restart, callable from an interrupt handler.
63905 */
63906
63907-extern void emergency_restart(void);
63908+extern void emergency_restart(void) __noreturn;
63909 #include <asm/emergency-restart.h>
63910
63911 #endif
63912diff --git a/include/linux/relay.h b/include/linux/relay.h
63913index 91cacc3..b55ff74 100644
63914--- a/include/linux/relay.h
63915+++ b/include/linux/relay.h
63916@@ -160,7 +160,7 @@ struct rchan_callbacks
63917 * The callback should return 0 if successful, negative if not.
63918 */
63919 int (*remove_buf_file)(struct dentry *dentry);
63920-};
63921+} __no_const;
63922
63923 /*
63924 * CONFIG_RELAY kernel API, kernel/relay.c
63925diff --git a/include/linux/rfkill.h b/include/linux/rfkill.h
63926index 6fdf027..ff72610 100644
63927--- a/include/linux/rfkill.h
63928+++ b/include/linux/rfkill.h
63929@@ -147,6 +147,7 @@ struct rfkill_ops {
63930 void (*query)(struct rfkill *rfkill, void *data);
63931 int (*set_block)(void *data, bool blocked);
63932 };
63933+typedef struct rfkill_ops __no_const rfkill_ops_no_const;
63934
63935 #if defined(CONFIG_RFKILL) || defined(CONFIG_RFKILL_MODULE)
63936 /**
63937diff --git a/include/linux/rio.h b/include/linux/rio.h
63938index a90ebad..fd87b5d 100644
63939--- a/include/linux/rio.h
63940+++ b/include/linux/rio.h
63941@@ -321,7 +321,7 @@ struct rio_ops {
63942 int mbox, void *buffer, size_t len);
63943 int (*add_inb_buffer)(struct rio_mport *mport, int mbox, void *buf);
63944 void *(*get_inb_message)(struct rio_mport *mport, int mbox);
63945-};
63946+} __no_const;
63947
63948 #define RIO_RESOURCE_MEM 0x00000100
63949 #define RIO_RESOURCE_DOORBELL 0x00000200
63950diff --git a/include/linux/rmap.h b/include/linux/rmap.h
63951index 3fce545..b4fed6e 100644
63952--- a/include/linux/rmap.h
63953+++ b/include/linux/rmap.h
63954@@ -119,9 +119,9 @@ static inline void anon_vma_unlock(struct anon_vma *anon_vma)
63955 void anon_vma_init(void); /* create anon_vma_cachep */
63956 int anon_vma_prepare(struct vm_area_struct *);
63957 void unlink_anon_vmas(struct vm_area_struct *);
63958-int anon_vma_clone(struct vm_area_struct *, struct vm_area_struct *);
63959+int anon_vma_clone(struct vm_area_struct *, const struct vm_area_struct *);
63960 void anon_vma_moveto_tail(struct vm_area_struct *);
63961-int anon_vma_fork(struct vm_area_struct *, struct vm_area_struct *);
63962+int anon_vma_fork(struct vm_area_struct *, const struct vm_area_struct *);
63963
63964 static inline void anon_vma_merge(struct vm_area_struct *vma,
63965 struct vm_area_struct *next)
63966diff --git a/include/linux/sched.h b/include/linux/sched.h
63967index 23bddac..5976055 100644
63968--- a/include/linux/sched.h
63969+++ b/include/linux/sched.h
63970@@ -101,6 +101,7 @@ struct bio_list;
63971 struct fs_struct;
63972 struct perf_event_context;
63973 struct blk_plug;
63974+struct linux_binprm;
63975
63976 /*
63977 * List of flags we want to share for kernel threads,
63978@@ -384,10 +385,13 @@ struct user_namespace;
63979 #define DEFAULT_MAX_MAP_COUNT (USHRT_MAX - MAPCOUNT_ELF_CORE_MARGIN)
63980
63981 extern int sysctl_max_map_count;
63982+extern unsigned long sysctl_heap_stack_gap;
63983
63984 #include <linux/aio.h>
63985
63986 #ifdef CONFIG_MMU
63987+extern bool check_heap_stack_gap(const struct vm_area_struct *vma, unsigned long addr, unsigned long len);
63988+extern unsigned long skip_heap_stack_gap(const struct vm_area_struct *vma, unsigned long len);
63989 extern void arch_pick_mmap_layout(struct mm_struct *mm);
63990 extern unsigned long
63991 arch_get_unmapped_area(struct file *, unsigned long, unsigned long,
63992@@ -651,6 +655,17 @@ struct signal_struct {
63993 #ifdef CONFIG_TASKSTATS
63994 struct taskstats *stats;
63995 #endif
63996+
63997+#ifdef CONFIG_GRKERNSEC
63998+ u32 curr_ip;
63999+ u32 saved_ip;
64000+ u32 gr_saddr;
64001+ u32 gr_daddr;
64002+ u16 gr_sport;
64003+ u16 gr_dport;
64004+ u8 used_accept:1;
64005+#endif
64006+
64007 #ifdef CONFIG_AUDIT
64008 unsigned audit_tty;
64009 struct tty_audit_buf *tty_audit_buf;
64010@@ -734,6 +749,11 @@ struct user_struct {
64011 struct key *session_keyring; /* UID's default session keyring */
64012 #endif
64013
64014+#if defined(CONFIG_GRKERNSEC_KERN_LOCKOUT) || defined(CONFIG_GRKERNSEC_BRUTE)
64015+ unsigned int banned;
64016+ unsigned long ban_expires;
64017+#endif
64018+
64019 /* Hash table maintenance information */
64020 struct hlist_node uidhash_node;
64021 kuid_t uid;
64022@@ -1356,8 +1376,8 @@ struct task_struct {
64023 struct list_head thread_group;
64024
64025 struct completion *vfork_done; /* for vfork() */
64026- int __user *set_child_tid; /* CLONE_CHILD_SETTID */
64027- int __user *clear_child_tid; /* CLONE_CHILD_CLEARTID */
64028+ pid_t __user *set_child_tid; /* CLONE_CHILD_SETTID */
64029+ pid_t __user *clear_child_tid; /* CLONE_CHILD_CLEARTID */
64030
64031 cputime_t utime, stime, utimescaled, stimescaled;
64032 cputime_t gtime;
64033@@ -1373,11 +1393,6 @@ struct task_struct {
64034 struct task_cputime cputime_expires;
64035 struct list_head cpu_timers[3];
64036
64037-/* process credentials */
64038- const struct cred __rcu *real_cred; /* objective and real subjective task
64039- * credentials (COW) */
64040- const struct cred __rcu *cred; /* effective (overridable) subjective task
64041- * credentials (COW) */
64042 char comm[TASK_COMM_LEN]; /* executable name excluding path
64043 - access with [gs]et_task_comm (which lock
64044 it with task_lock())
64045@@ -1394,6 +1409,10 @@ struct task_struct {
64046 #endif
64047 /* CPU-specific state of this task */
64048 struct thread_struct thread;
64049+/* thread_info moved to task_struct */
64050+#ifdef CONFIG_X86
64051+ struct thread_info tinfo;
64052+#endif
64053 /* filesystem information */
64054 struct fs_struct *fs;
64055 /* open file information */
64056@@ -1467,6 +1486,10 @@ struct task_struct {
64057 gfp_t lockdep_reclaim_gfp;
64058 #endif
64059
64060+/* process credentials */
64061+ const struct cred __rcu *real_cred; /* objective and real subjective task
64062+ * credentials (COW) */
64063+
64064 /* journalling filesystem info */
64065 void *journal_info;
64066
64067@@ -1505,6 +1528,10 @@ struct task_struct {
64068 /* cg_list protected by css_set_lock and tsk->alloc_lock */
64069 struct list_head cg_list;
64070 #endif
64071+
64072+ const struct cred __rcu *cred; /* effective (overridable) subjective task
64073+ * credentials (COW) */
64074+
64075 #ifdef CONFIG_FUTEX
64076 struct robust_list_head __user *robust_list;
64077 #ifdef CONFIG_COMPAT
64078@@ -1589,8 +1616,74 @@ struct task_struct {
64079 #ifdef CONFIG_UPROBES
64080 struct uprobe_task *utask;
64081 #endif
64082+
64083+#ifdef CONFIG_GRKERNSEC
64084+ /* grsecurity */
64085+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
64086+ u64 exec_id;
64087+#endif
64088+#ifdef CONFIG_GRKERNSEC_SETXID
64089+ const struct cred *delayed_cred;
64090+#endif
64091+ struct dentry *gr_chroot_dentry;
64092+ struct acl_subject_label *acl;
64093+ struct acl_role_label *role;
64094+ struct file *exec_file;
64095+ u16 acl_role_id;
64096+ /* is this the task that authenticated to the special role */
64097+ u8 acl_sp_role;
64098+ u8 is_writable;
64099+ u8 brute;
64100+ u8 gr_is_chrooted;
64101+#endif
64102+
64103 };
64104
64105+#define MF_PAX_PAGEEXEC 0x01000000 /* Paging based non-executable pages */
64106+#define MF_PAX_EMUTRAMP 0x02000000 /* Emulate trampolines */
64107+#define MF_PAX_MPROTECT 0x04000000 /* Restrict mprotect() */
64108+#define MF_PAX_RANDMMAP 0x08000000 /* Randomize mmap() base */
64109+/*#define MF_PAX_RANDEXEC 0x10000000*/ /* Randomize ET_EXEC base */
64110+#define MF_PAX_SEGMEXEC 0x20000000 /* Segmentation based non-executable pages */
64111+
64112+#ifdef CONFIG_PAX_SOFTMODE
64113+extern int pax_softmode;
64114+#endif
64115+
64116+extern int pax_check_flags(unsigned long *);
64117+
64118+/* if tsk != current then task_lock must be held on it */
64119+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
64120+static inline unsigned long pax_get_flags(struct task_struct *tsk)
64121+{
64122+ if (likely(tsk->mm))
64123+ return tsk->mm->pax_flags;
64124+ else
64125+ return 0UL;
64126+}
64127+
64128+/* if tsk != current then task_lock must be held on it */
64129+static inline long pax_set_flags(struct task_struct *tsk, unsigned long flags)
64130+{
64131+ if (likely(tsk->mm)) {
64132+ tsk->mm->pax_flags = flags;
64133+ return 0;
64134+ }
64135+ return -EINVAL;
64136+}
64137+#endif
64138+
64139+#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
64140+extern void pax_set_initial_flags(struct linux_binprm *bprm);
64141+#elif defined(CONFIG_PAX_HOOK_ACL_FLAGS)
64142+extern void (*pax_set_initial_flags_func)(struct linux_binprm *bprm);
64143+#endif
64144+
64145+extern void pax_report_fault(struct pt_regs *regs, void *pc, void *sp);
64146+extern void pax_report_insns(struct pt_regs *regs, void *pc, void *sp);
64147+extern void pax_report_refcount_overflow(struct pt_regs *regs);
64148+extern void check_object_size(const void *ptr, unsigned long n, bool to);
64149+
64150 /* Future-safe accessor for struct task_struct's cpus_allowed. */
64151 #define tsk_cpus_allowed(tsk) (&(tsk)->cpus_allowed)
64152
64153@@ -2125,7 +2218,9 @@ void yield(void);
64154 extern struct exec_domain default_exec_domain;
64155
64156 union thread_union {
64157+#ifndef CONFIG_X86
64158 struct thread_info thread_info;
64159+#endif
64160 unsigned long stack[THREAD_SIZE/sizeof(long)];
64161 };
64162
64163@@ -2158,6 +2253,7 @@ extern struct pid_namespace init_pid_ns;
64164 */
64165
64166 extern struct task_struct *find_task_by_vpid(pid_t nr);
64167+extern struct task_struct *find_task_by_vpid_unrestricted(pid_t nr);
64168 extern struct task_struct *find_task_by_pid_ns(pid_t nr,
64169 struct pid_namespace *ns);
64170
64171@@ -2314,7 +2410,7 @@ extern void __cleanup_sighand(struct sighand_struct *);
64172 extern void exit_itimers(struct signal_struct *);
64173 extern void flush_itimer_signals(void);
64174
64175-extern void do_group_exit(int);
64176+extern __noreturn void do_group_exit(int);
64177
64178 extern void daemonize(const char *, ...);
64179 extern int allow_signal(int);
64180@@ -2515,9 +2611,9 @@ static inline unsigned long *end_of_stack(struct task_struct *p)
64181
64182 #endif
64183
64184-static inline int object_is_on_stack(void *obj)
64185+static inline int object_starts_on_stack(void *obj)
64186 {
64187- void *stack = task_stack_page(current);
64188+ const void *stack = task_stack_page(current);
64189
64190 return (obj >= stack) && (obj < (stack + THREAD_SIZE));
64191 }
64192diff --git a/include/linux/screen_info.h b/include/linux/screen_info.h
64193index 899fbb4..1cb4138 100644
64194--- a/include/linux/screen_info.h
64195+++ b/include/linux/screen_info.h
64196@@ -43,7 +43,8 @@ struct screen_info {
64197 __u16 pages; /* 0x32 */
64198 __u16 vesa_attributes; /* 0x34 */
64199 __u32 capabilities; /* 0x36 */
64200- __u8 _reserved[6]; /* 0x3a */
64201+ __u16 vesapm_size; /* 0x3a */
64202+ __u8 _reserved[4]; /* 0x3c */
64203 } __attribute__((packed));
64204
64205 #define VIDEO_TYPE_MDA 0x10 /* Monochrome Text Display */
64206diff --git a/include/linux/security.h b/include/linux/security.h
64207index d143b8e..9f27b95 100644
64208--- a/include/linux/security.h
64209+++ b/include/linux/security.h
64210@@ -26,6 +26,7 @@
64211 #include <linux/capability.h>
64212 #include <linux/slab.h>
64213 #include <linux/err.h>
64214+#include <linux/grsecurity.h>
64215
64216 struct linux_binprm;
64217 struct cred;
64218diff --git a/include/linux/seq_file.h b/include/linux/seq_file.h
64219index 83c44ee..e8a9eba 100644
64220--- a/include/linux/seq_file.h
64221+++ b/include/linux/seq_file.h
64222@@ -25,6 +25,9 @@ struct seq_file {
64223 struct mutex lock;
64224 const struct seq_operations *op;
64225 int poll_event;
64226+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
64227+ u64 exec_id;
64228+#endif
64229 void *private;
64230 };
64231
64232@@ -34,6 +37,7 @@ struct seq_operations {
64233 void * (*next) (struct seq_file *m, void *v, loff_t *pos);
64234 int (*show) (struct seq_file *m, void *v);
64235 };
64236+typedef struct seq_operations __no_const seq_operations_no_const;
64237
64238 #define SEQ_SKIP 1
64239
64240diff --git a/include/linux/shm.h b/include/linux/shm.h
64241index edd0868..f98feee 100644
64242--- a/include/linux/shm.h
64243+++ b/include/linux/shm.h
64244@@ -98,6 +98,10 @@ struct shmid_kernel /* private to the kernel */
64245
64246 /* The task created the shm object. NULL if the task is dead. */
64247 struct task_struct *shm_creator;
64248+#ifdef CONFIG_GRKERNSEC
64249+ time_t shm_createtime;
64250+ pid_t shm_lapid;
64251+#endif
64252 };
64253
64254 /* shm_mode upper byte flags */
64255diff --git a/include/linux/skbuff.h b/include/linux/skbuff.h
64256index f3165d2..2cb3cb7 100644
64257--- a/include/linux/skbuff.h
64258+++ b/include/linux/skbuff.h
64259@@ -577,7 +577,7 @@ extern bool skb_try_coalesce(struct sk_buff *to, struct sk_buff *from,
64260 extern struct sk_buff *__alloc_skb(unsigned int size,
64261 gfp_t priority, int flags, int node);
64262 extern struct sk_buff *build_skb(void *data, unsigned int frag_size);
64263-static inline struct sk_buff *alloc_skb(unsigned int size,
64264+static inline struct sk_buff * __intentional_overflow(0) alloc_skb(unsigned int size,
64265 gfp_t priority)
64266 {
64267 return __alloc_skb(size, priority, 0, NUMA_NO_NODE);
64268@@ -687,7 +687,7 @@ static inline struct skb_shared_hwtstamps *skb_hwtstamps(struct sk_buff *skb)
64269 */
64270 static inline int skb_queue_empty(const struct sk_buff_head *list)
64271 {
64272- return list->next == (struct sk_buff *)list;
64273+ return list->next == (const struct sk_buff *)list;
64274 }
64275
64276 /**
64277@@ -700,7 +700,7 @@ static inline int skb_queue_empty(const struct sk_buff_head *list)
64278 static inline bool skb_queue_is_last(const struct sk_buff_head *list,
64279 const struct sk_buff *skb)
64280 {
64281- return skb->next == (struct sk_buff *)list;
64282+ return skb->next == (const struct sk_buff *)list;
64283 }
64284
64285 /**
64286@@ -713,7 +713,7 @@ static inline bool skb_queue_is_last(const struct sk_buff_head *list,
64287 static inline bool skb_queue_is_first(const struct sk_buff_head *list,
64288 const struct sk_buff *skb)
64289 {
64290- return skb->prev == (struct sk_buff *)list;
64291+ return skb->prev == (const struct sk_buff *)list;
64292 }
64293
64294 /**
64295@@ -1623,7 +1623,7 @@ static inline int pskb_network_may_pull(struct sk_buff *skb, unsigned int len)
64296 * NET_IP_ALIGN(2) + ethernet_header(14) + IP_header(20/40) + ports(8)
64297 */
64298 #ifndef NET_SKB_PAD
64299-#define NET_SKB_PAD max(32, L1_CACHE_BYTES)
64300+#define NET_SKB_PAD max(_AC(32,UL), L1_CACHE_BYTES)
64301 #endif
64302
64303 extern int ___pskb_trim(struct sk_buff *skb, unsigned int len);
64304@@ -2201,7 +2201,7 @@ extern struct sk_buff *skb_recv_datagram(struct sock *sk, unsigned flags,
64305 int noblock, int *err);
64306 extern unsigned int datagram_poll(struct file *file, struct socket *sock,
64307 struct poll_table_struct *wait);
64308-extern int skb_copy_datagram_iovec(const struct sk_buff *from,
64309+extern int __intentional_overflow(0) skb_copy_datagram_iovec(const struct sk_buff *from,
64310 int offset, struct iovec *to,
64311 int size);
64312 extern int skb_copy_and_csum_datagram_iovec(struct sk_buff *skb,
64313diff --git a/include/linux/slab.h b/include/linux/slab.h
64314index 0dd2dfa..2b8677c 100644
64315--- a/include/linux/slab.h
64316+++ b/include/linux/slab.h
64317@@ -11,12 +11,20 @@
64318
64319 #include <linux/gfp.h>
64320 #include <linux/types.h>
64321+#include <linux/err.h>
64322
64323 /*
64324 * Flags to pass to kmem_cache_create().
64325 * The ones marked DEBUG are only valid if CONFIG_SLAB_DEBUG is set.
64326 */
64327 #define SLAB_DEBUG_FREE 0x00000100UL /* DEBUG: Perform (expensive) checks on free */
64328+
64329+#ifdef CONFIG_PAX_USERCOPY_SLABS
64330+#define SLAB_USERCOPY 0x00000200UL /* PaX: Allow copying objs to/from userland */
64331+#else
64332+#define SLAB_USERCOPY 0x00000000UL
64333+#endif
64334+
64335 #define SLAB_RED_ZONE 0x00000400UL /* DEBUG: Red zone objs in a cache */
64336 #define SLAB_POISON 0x00000800UL /* DEBUG: Poison objects */
64337 #define SLAB_HWCACHE_ALIGN 0x00002000UL /* Align objs on cache lines */
64338@@ -87,10 +95,13 @@
64339 * ZERO_SIZE_PTR can be passed to kfree though in the same way that NULL can.
64340 * Both make kfree a no-op.
64341 */
64342-#define ZERO_SIZE_PTR ((void *)16)
64343+#define ZERO_SIZE_PTR \
64344+({ \
64345+ BUILD_BUG_ON(!(MAX_ERRNO & ~PAGE_MASK));\
64346+ (void *)(-MAX_ERRNO-1L); \
64347+})
64348
64349-#define ZERO_OR_NULL_PTR(x) ((unsigned long)(x) <= \
64350- (unsigned long)ZERO_SIZE_PTR)
64351+#define ZERO_OR_NULL_PTR(x) ((unsigned long)(x) - 1 >= (unsigned long)ZERO_SIZE_PTR - 1)
64352
64353 /*
64354 * Common fields provided in kmem_cache by all slab allocators
64355@@ -185,6 +196,8 @@ void * __must_check krealloc(const void *, size_t, gfp_t);
64356 void kfree(const void *);
64357 void kzfree(const void *);
64358 size_t ksize(const void *);
64359+const char *check_heap_object(const void *ptr, unsigned long n, bool to);
64360+bool is_usercopy_object(const void *ptr);
64361
64362 /*
64363 * Allocator specific definitions. These are mainly used to establish optimized
64364@@ -322,7 +335,7 @@ static inline void *kmem_cache_alloc_node(struct kmem_cache *cachep,
64365 */
64366 #if defined(CONFIG_DEBUG_SLAB) || defined(CONFIG_SLUB) || \
64367 (defined(CONFIG_SLAB) && defined(CONFIG_TRACING))
64368-extern void *__kmalloc_track_caller(size_t, gfp_t, unsigned long);
64369+extern void *__kmalloc_track_caller(size_t, gfp_t, unsigned long) __size_overflow(1);
64370 #define kmalloc_track_caller(size, flags) \
64371 __kmalloc_track_caller(size, flags, _RET_IP_)
64372 #else
64373@@ -341,7 +354,7 @@ extern void *__kmalloc_track_caller(size_t, gfp_t, unsigned long);
64374 */
64375 #if defined(CONFIG_DEBUG_SLAB) || defined(CONFIG_SLUB) || \
64376 (defined(CONFIG_SLAB) && defined(CONFIG_TRACING))
64377-extern void *__kmalloc_node_track_caller(size_t, gfp_t, int, unsigned long);
64378+extern void *__kmalloc_node_track_caller(size_t, gfp_t, int, unsigned long) __size_overflow(1);
64379 #define kmalloc_node_track_caller(size, flags, node) \
64380 __kmalloc_node_track_caller(size, flags, node, \
64381 _RET_IP_)
64382diff --git a/include/linux/slab_def.h b/include/linux/slab_def.h
64383index 0c634fa..8616300 100644
64384--- a/include/linux/slab_def.h
64385+++ b/include/linux/slab_def.h
64386@@ -69,10 +69,10 @@ struct kmem_cache {
64387 unsigned long node_allocs;
64388 unsigned long node_frees;
64389 unsigned long node_overflow;
64390- atomic_t allochit;
64391- atomic_t allocmiss;
64392- atomic_t freehit;
64393- atomic_t freemiss;
64394+ atomic_unchecked_t allochit;
64395+ atomic_unchecked_t allocmiss;
64396+ atomic_unchecked_t freehit;
64397+ atomic_unchecked_t freemiss;
64398
64399 /*
64400 * If debugging is enabled, then the allocator can add additional
64401@@ -105,11 +105,16 @@ struct cache_sizes {
64402 #ifdef CONFIG_ZONE_DMA
64403 struct kmem_cache *cs_dmacachep;
64404 #endif
64405+
64406+#ifdef CONFIG_PAX_USERCOPY_SLABS
64407+ struct kmem_cache *cs_usercopycachep;
64408+#endif
64409+
64410 };
64411 extern struct cache_sizes malloc_sizes[];
64412
64413 void *kmem_cache_alloc(struct kmem_cache *, gfp_t);
64414-void *__kmalloc(size_t size, gfp_t flags);
64415+void *__kmalloc(size_t size, gfp_t flags) __size_overflow(1);
64416
64417 #ifdef CONFIG_TRACING
64418 extern void *kmem_cache_alloc_trace(size_t size,
64419@@ -152,6 +157,13 @@ found:
64420 cachep = malloc_sizes[i].cs_dmacachep;
64421 else
64422 #endif
64423+
64424+#ifdef CONFIG_PAX_USERCOPY_SLABS
64425+ if (flags & GFP_USERCOPY)
64426+ cachep = malloc_sizes[i].cs_usercopycachep;
64427+ else
64428+#endif
64429+
64430 cachep = malloc_sizes[i].cs_cachep;
64431
64432 ret = kmem_cache_alloc_trace(size, cachep, flags);
64433@@ -162,7 +174,7 @@ found:
64434 }
64435
64436 #ifdef CONFIG_NUMA
64437-extern void *__kmalloc_node(size_t size, gfp_t flags, int node);
64438+extern void *__kmalloc_node(size_t size, gfp_t flags, int node) __size_overflow(1);
64439 extern void *kmem_cache_alloc_node(struct kmem_cache *, gfp_t flags, int node);
64440
64441 #ifdef CONFIG_TRACING
64442@@ -205,6 +217,13 @@ found:
64443 cachep = malloc_sizes[i].cs_dmacachep;
64444 else
64445 #endif
64446+
64447+#ifdef CONFIG_PAX_USERCOPY_SLABS
64448+ if (flags & GFP_USERCOPY)
64449+ cachep = malloc_sizes[i].cs_usercopycachep;
64450+ else
64451+#endif
64452+
64453 cachep = malloc_sizes[i].cs_cachep;
64454
64455 return kmem_cache_alloc_node_trace(size, cachep, flags, node);
64456diff --git a/include/linux/slob_def.h b/include/linux/slob_def.h
64457index 0ec00b3..22b4715 100644
64458--- a/include/linux/slob_def.h
64459+++ b/include/linux/slob_def.h
64460@@ -9,7 +9,7 @@ static __always_inline void *kmem_cache_alloc(struct kmem_cache *cachep,
64461 return kmem_cache_alloc_node(cachep, flags, -1);
64462 }
64463
64464-void *__kmalloc_node(size_t size, gfp_t flags, int node);
64465+void *__kmalloc_node(size_t size, gfp_t flags, int node) __size_overflow(1);
64466
64467 static __always_inline void *kmalloc_node(size_t size, gfp_t flags, int node)
64468 {
64469@@ -29,7 +29,7 @@ static __always_inline void *kmalloc(size_t size, gfp_t flags)
64470 return __kmalloc_node(size, flags, -1);
64471 }
64472
64473-static __always_inline void *__kmalloc(size_t size, gfp_t flags)
64474+static __always_inline __size_overflow(1) void *__kmalloc(size_t size, gfp_t flags)
64475 {
64476 return kmalloc(size, flags);
64477 }
64478diff --git a/include/linux/slub_def.h b/include/linux/slub_def.h
64479index df448ad..b99e7f6 100644
64480--- a/include/linux/slub_def.h
64481+++ b/include/linux/slub_def.h
64482@@ -91,7 +91,7 @@ struct kmem_cache {
64483 struct kmem_cache_order_objects max;
64484 struct kmem_cache_order_objects min;
64485 gfp_t allocflags; /* gfp flags to use on each alloc */
64486- int refcount; /* Refcount for slab cache destroy */
64487+ atomic_t refcount; /* Refcount for slab cache destroy */
64488 void (*ctor)(void *);
64489 int inuse; /* Offset to metadata */
64490 int align; /* Alignment */
64491@@ -152,7 +152,7 @@ extern struct kmem_cache *kmalloc_caches[SLUB_PAGE_SHIFT];
64492 * Sorry that the following has to be that ugly but some versions of GCC
64493 * have trouble with constant propagation and loops.
64494 */
64495-static __always_inline int kmalloc_index(size_t size)
64496+static __always_inline __size_overflow(1) int kmalloc_index(size_t size)
64497 {
64498 if (!size)
64499 return 0;
64500@@ -217,7 +217,7 @@ static __always_inline struct kmem_cache *kmalloc_slab(size_t size)
64501 }
64502
64503 void *kmem_cache_alloc(struct kmem_cache *, gfp_t);
64504-void *__kmalloc(size_t size, gfp_t flags);
64505+void *__kmalloc(size_t size, gfp_t flags) __alloc_size(1) __size_overflow(1);
64506
64507 static __always_inline void *
64508 kmalloc_order(size_t size, gfp_t flags, unsigned int order)
64509@@ -258,7 +258,7 @@ kmalloc_order_trace(size_t size, gfp_t flags, unsigned int order)
64510 }
64511 #endif
64512
64513-static __always_inline void *kmalloc_large(size_t size, gfp_t flags)
64514+static __always_inline __size_overflow(1) void *kmalloc_large(size_t size, gfp_t flags)
64515 {
64516 unsigned int order = get_order(size);
64517 return kmalloc_order_trace(size, flags, order);
64518@@ -283,7 +283,7 @@ static __always_inline void *kmalloc(size_t size, gfp_t flags)
64519 }
64520
64521 #ifdef CONFIG_NUMA
64522-void *__kmalloc_node(size_t size, gfp_t flags, int node);
64523+void *__kmalloc_node(size_t size, gfp_t flags, int node) __size_overflow(1);
64524 void *kmem_cache_alloc_node(struct kmem_cache *, gfp_t flags, int node);
64525
64526 #ifdef CONFIG_TRACING
64527diff --git a/include/linux/sonet.h b/include/linux/sonet.h
64528index de8832d..0147b46 100644
64529--- a/include/linux/sonet.h
64530+++ b/include/linux/sonet.h
64531@@ -61,7 +61,7 @@ struct sonet_stats {
64532 #include <linux/atomic.h>
64533
64534 struct k_sonet_stats {
64535-#define __HANDLE_ITEM(i) atomic_t i
64536+#define __HANDLE_ITEM(i) atomic_unchecked_t i
64537 __SONET_ITEMS
64538 #undef __HANDLE_ITEM
64539 };
64540diff --git a/include/linux/sunrpc/clnt.h b/include/linux/sunrpc/clnt.h
64541index 523547e..2cb7140 100644
64542--- a/include/linux/sunrpc/clnt.h
64543+++ b/include/linux/sunrpc/clnt.h
64544@@ -174,9 +174,9 @@ static inline unsigned short rpc_get_port(const struct sockaddr *sap)
64545 {
64546 switch (sap->sa_family) {
64547 case AF_INET:
64548- return ntohs(((struct sockaddr_in *)sap)->sin_port);
64549+ return ntohs(((const struct sockaddr_in *)sap)->sin_port);
64550 case AF_INET6:
64551- return ntohs(((struct sockaddr_in6 *)sap)->sin6_port);
64552+ return ntohs(((const struct sockaddr_in6 *)sap)->sin6_port);
64553 }
64554 return 0;
64555 }
64556@@ -209,7 +209,7 @@ static inline bool __rpc_cmp_addr4(const struct sockaddr *sap1,
64557 static inline bool __rpc_copy_addr4(struct sockaddr *dst,
64558 const struct sockaddr *src)
64559 {
64560- const struct sockaddr_in *ssin = (struct sockaddr_in *) src;
64561+ const struct sockaddr_in *ssin = (const struct sockaddr_in *) src;
64562 struct sockaddr_in *dsin = (struct sockaddr_in *) dst;
64563
64564 dsin->sin_family = ssin->sin_family;
64565@@ -312,7 +312,7 @@ static inline u32 rpc_get_scope_id(const struct sockaddr *sa)
64566 if (sa->sa_family != AF_INET6)
64567 return 0;
64568
64569- return ((struct sockaddr_in6 *) sa)->sin6_scope_id;
64570+ return ((const struct sockaddr_in6 *) sa)->sin6_scope_id;
64571 }
64572
64573 #endif /* __KERNEL__ */
64574diff --git a/include/linux/sunrpc/sched.h b/include/linux/sunrpc/sched.h
64575index dc0c3cc..8503fb6 100644
64576--- a/include/linux/sunrpc/sched.h
64577+++ b/include/linux/sunrpc/sched.h
64578@@ -106,6 +106,7 @@ struct rpc_call_ops {
64579 void (*rpc_count_stats)(struct rpc_task *, void *);
64580 void (*rpc_release)(void *);
64581 };
64582+typedef struct rpc_call_ops __no_const rpc_call_ops_no_const;
64583
64584 struct rpc_task_setup {
64585 struct rpc_task *task;
64586diff --git a/include/linux/sunrpc/svc_rdma.h b/include/linux/sunrpc/svc_rdma.h
64587index 0b8e3e6..33e0a01 100644
64588--- a/include/linux/sunrpc/svc_rdma.h
64589+++ b/include/linux/sunrpc/svc_rdma.h
64590@@ -53,15 +53,15 @@ extern unsigned int svcrdma_ord;
64591 extern unsigned int svcrdma_max_requests;
64592 extern unsigned int svcrdma_max_req_size;
64593
64594-extern atomic_t rdma_stat_recv;
64595-extern atomic_t rdma_stat_read;
64596-extern atomic_t rdma_stat_write;
64597-extern atomic_t rdma_stat_sq_starve;
64598-extern atomic_t rdma_stat_rq_starve;
64599-extern atomic_t rdma_stat_rq_poll;
64600-extern atomic_t rdma_stat_rq_prod;
64601-extern atomic_t rdma_stat_sq_poll;
64602-extern atomic_t rdma_stat_sq_prod;
64603+extern atomic_unchecked_t rdma_stat_recv;
64604+extern atomic_unchecked_t rdma_stat_read;
64605+extern atomic_unchecked_t rdma_stat_write;
64606+extern atomic_unchecked_t rdma_stat_sq_starve;
64607+extern atomic_unchecked_t rdma_stat_rq_starve;
64608+extern atomic_unchecked_t rdma_stat_rq_poll;
64609+extern atomic_unchecked_t rdma_stat_rq_prod;
64610+extern atomic_unchecked_t rdma_stat_sq_poll;
64611+extern atomic_unchecked_t rdma_stat_sq_prod;
64612
64613 #define RPCRDMA_VERSION 1
64614
64615diff --git a/include/linux/sysctl.h b/include/linux/sysctl.h
64616index c34b4c8..a65b67d 100644
64617--- a/include/linux/sysctl.h
64618+++ b/include/linux/sysctl.h
64619@@ -155,7 +155,11 @@ enum
64620 KERN_PANIC_ON_NMI=76, /* int: whether we will panic on an unrecovered */
64621 };
64622
64623-
64624+#ifdef CONFIG_PAX_SOFTMODE
64625+enum {
64626+ PAX_SOFTMODE=1 /* PaX: disable/enable soft mode */
64627+};
64628+#endif
64629
64630 /* CTL_VM names: */
64631 enum
64632@@ -948,6 +952,8 @@ typedef int proc_handler (struct ctl_table *ctl, int write,
64633
64634 extern int proc_dostring(struct ctl_table *, int,
64635 void __user *, size_t *, loff_t *);
64636+extern int proc_dostring_modpriv(struct ctl_table *, int,
64637+ void __user *, size_t *, loff_t *);
64638 extern int proc_dointvec(struct ctl_table *, int,
64639 void __user *, size_t *, loff_t *);
64640 extern int proc_dointvec_minmax(struct ctl_table *, int,
64641diff --git a/include/linux/tty.h b/include/linux/tty.h
64642index 9f47ab5..73da944 100644
64643--- a/include/linux/tty.h
64644+++ b/include/linux/tty.h
64645@@ -225,7 +225,7 @@ struct tty_port {
64646 const struct tty_port_operations *ops; /* Port operations */
64647 spinlock_t lock; /* Lock protecting tty field */
64648 int blocked_open; /* Waiting to open */
64649- int count; /* Usage count */
64650+ atomic_t count; /* Usage count */
64651 wait_queue_head_t open_wait; /* Open waiters */
64652 wait_queue_head_t close_wait; /* Close waiters */
64653 wait_queue_head_t delta_msr_wait; /* Modem status change */
64654@@ -525,7 +525,7 @@ extern int tty_port_open(struct tty_port *port,
64655 struct tty_struct *tty, struct file *filp);
64656 static inline int tty_port_users(struct tty_port *port)
64657 {
64658- return port->count + port->blocked_open;
64659+ return atomic_read(&port->count) + port->blocked_open;
64660 }
64661
64662 extern int tty_register_ldisc(int disc, struct tty_ldisc_ops *new_ldisc);
64663diff --git a/include/linux/tty_ldisc.h b/include/linux/tty_ldisc.h
64664index fb79dd8d..07d4773 100644
64665--- a/include/linux/tty_ldisc.h
64666+++ b/include/linux/tty_ldisc.h
64667@@ -149,7 +149,7 @@ struct tty_ldisc_ops {
64668
64669 struct module *owner;
64670
64671- int refcount;
64672+ atomic_t refcount;
64673 };
64674
64675 struct tty_ldisc {
64676diff --git a/include/linux/types.h b/include/linux/types.h
64677index bf0dd75..a1f23aaa 100644
64678--- a/include/linux/types.h
64679+++ b/include/linux/types.h
64680@@ -220,10 +220,26 @@ typedef struct {
64681 int counter;
64682 } atomic_t;
64683
64684+#ifdef CONFIG_PAX_REFCOUNT
64685+typedef struct {
64686+ int counter;
64687+} atomic_unchecked_t;
64688+#else
64689+typedef atomic_t atomic_unchecked_t;
64690+#endif
64691+
64692 #ifdef CONFIG_64BIT
64693 typedef struct {
64694 long counter;
64695 } atomic64_t;
64696+
64697+#ifdef CONFIG_PAX_REFCOUNT
64698+typedef struct {
64699+ long counter;
64700+} atomic64_unchecked_t;
64701+#else
64702+typedef atomic64_t atomic64_unchecked_t;
64703+#endif
64704 #endif
64705
64706 struct list_head {
64707diff --git a/include/linux/uaccess.h b/include/linux/uaccess.h
64708index 5ca0951..ab496a5 100644
64709--- a/include/linux/uaccess.h
64710+++ b/include/linux/uaccess.h
64711@@ -76,11 +76,11 @@ static inline unsigned long __copy_from_user_nocache(void *to,
64712 long ret; \
64713 mm_segment_t old_fs = get_fs(); \
64714 \
64715- set_fs(KERNEL_DS); \
64716 pagefault_disable(); \
64717- ret = __copy_from_user_inatomic(&(retval), (__force typeof(retval) __user *)(addr), sizeof(retval)); \
64718- pagefault_enable(); \
64719+ set_fs(KERNEL_DS); \
64720+ ret = __copy_from_user_inatomic(&(retval), (typeof(retval) __force_user *)(addr), sizeof(retval)); \
64721 set_fs(old_fs); \
64722+ pagefault_enable(); \
64723 ret; \
64724 })
64725
64726diff --git a/include/linux/unaligned/access_ok.h b/include/linux/unaligned/access_ok.h
64727index 99c1b4d..bb94261 100644
64728--- a/include/linux/unaligned/access_ok.h
64729+++ b/include/linux/unaligned/access_ok.h
64730@@ -6,32 +6,32 @@
64731
64732 static inline u16 get_unaligned_le16(const void *p)
64733 {
64734- return le16_to_cpup((__le16 *)p);
64735+ return le16_to_cpup((const __le16 *)p);
64736 }
64737
64738 static inline u32 get_unaligned_le32(const void *p)
64739 {
64740- return le32_to_cpup((__le32 *)p);
64741+ return le32_to_cpup((const __le32 *)p);
64742 }
64743
64744 static inline u64 get_unaligned_le64(const void *p)
64745 {
64746- return le64_to_cpup((__le64 *)p);
64747+ return le64_to_cpup((const __le64 *)p);
64748 }
64749
64750 static inline u16 get_unaligned_be16(const void *p)
64751 {
64752- return be16_to_cpup((__be16 *)p);
64753+ return be16_to_cpup((const __be16 *)p);
64754 }
64755
64756 static inline u32 get_unaligned_be32(const void *p)
64757 {
64758- return be32_to_cpup((__be32 *)p);
64759+ return be32_to_cpup((const __be32 *)p);
64760 }
64761
64762 static inline u64 get_unaligned_be64(const void *p)
64763 {
64764- return be64_to_cpup((__be64 *)p);
64765+ return be64_to_cpup((const __be64 *)p);
64766 }
64767
64768 static inline void put_unaligned_le16(u16 val, void *p)
64769diff --git a/include/linux/usb/renesas_usbhs.h b/include/linux/usb/renesas_usbhs.h
64770index c5d36c6..8478c90 100644
64771--- a/include/linux/usb/renesas_usbhs.h
64772+++ b/include/linux/usb/renesas_usbhs.h
64773@@ -39,7 +39,7 @@ enum {
64774 */
64775 struct renesas_usbhs_driver_callback {
64776 int (*notify_hotplug)(struct platform_device *pdev);
64777-};
64778+} __no_const;
64779
64780 /*
64781 * callback functions for platform
64782@@ -97,7 +97,7 @@ struct renesas_usbhs_platform_callback {
64783 * VBUS control is needed for Host
64784 */
64785 int (*set_vbus)(struct platform_device *pdev, int enable);
64786-};
64787+} __no_const;
64788
64789 /*
64790 * parameters for renesas usbhs
64791diff --git a/include/linux/vermagic.h b/include/linux/vermagic.h
64792index 6f8fbcf..8259001 100644
64793--- a/include/linux/vermagic.h
64794+++ b/include/linux/vermagic.h
64795@@ -25,9 +25,35 @@
64796 #define MODULE_ARCH_VERMAGIC ""
64797 #endif
64798
64799+#ifdef CONFIG_PAX_REFCOUNT
64800+#define MODULE_PAX_REFCOUNT "REFCOUNT "
64801+#else
64802+#define MODULE_PAX_REFCOUNT ""
64803+#endif
64804+
64805+#ifdef CONSTIFY_PLUGIN
64806+#define MODULE_CONSTIFY_PLUGIN "CONSTIFY_PLUGIN "
64807+#else
64808+#define MODULE_CONSTIFY_PLUGIN ""
64809+#endif
64810+
64811+#ifdef STACKLEAK_PLUGIN
64812+#define MODULE_STACKLEAK_PLUGIN "STACKLEAK_PLUGIN "
64813+#else
64814+#define MODULE_STACKLEAK_PLUGIN ""
64815+#endif
64816+
64817+#ifdef CONFIG_GRKERNSEC
64818+#define MODULE_GRSEC "GRSEC "
64819+#else
64820+#define MODULE_GRSEC ""
64821+#endif
64822+
64823 #define VERMAGIC_STRING \
64824 UTS_RELEASE " " \
64825 MODULE_VERMAGIC_SMP MODULE_VERMAGIC_PREEMPT \
64826 MODULE_VERMAGIC_MODULE_UNLOAD MODULE_VERMAGIC_MODVERSIONS \
64827- MODULE_ARCH_VERMAGIC
64828+ MODULE_ARCH_VERMAGIC \
64829+ MODULE_PAX_REFCOUNT MODULE_CONSTIFY_PLUGIN MODULE_STACKLEAK_PLUGIN \
64830+ MODULE_GRSEC
64831
64832diff --git a/include/linux/vmalloc.h b/include/linux/vmalloc.h
64833index 6071e91..ca6a489 100644
64834--- a/include/linux/vmalloc.h
64835+++ b/include/linux/vmalloc.h
64836@@ -14,6 +14,11 @@ struct vm_area_struct; /* vma defining user mapping in mm_types.h */
64837 #define VM_USERMAP 0x00000008 /* suitable for remap_vmalloc_range */
64838 #define VM_VPAGES 0x00000010 /* buffer for pages was vmalloc'ed */
64839 #define VM_UNLIST 0x00000020 /* vm_struct is not listed in vmlist */
64840+
64841+#if defined(CONFIG_MODULES) && defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
64842+#define VM_KERNEXEC 0x00000040 /* allocate from executable kernel memory range */
64843+#endif
64844+
64845 /* bits [20..32] reserved for arch specific ioremap internals */
64846
64847 /*
64848@@ -62,7 +67,7 @@ extern void *vmalloc_32_user(unsigned long size);
64849 extern void *__vmalloc(unsigned long size, gfp_t gfp_mask, pgprot_t prot);
64850 extern void *__vmalloc_node_range(unsigned long size, unsigned long align,
64851 unsigned long start, unsigned long end, gfp_t gfp_mask,
64852- pgprot_t prot, int node, const void *caller);
64853+ pgprot_t prot, int node, const void *caller) __size_overflow(1);
64854 extern void vfree(const void *addr);
64855
64856 extern void *vmap(struct page **pages, unsigned int count,
64857@@ -124,8 +129,8 @@ extern struct vm_struct *alloc_vm_area(size_t size, pte_t **ptes);
64858 extern void free_vm_area(struct vm_struct *area);
64859
64860 /* for /dev/kmem */
64861-extern long vread(char *buf, char *addr, unsigned long count);
64862-extern long vwrite(char *buf, char *addr, unsigned long count);
64863+extern long vread(char *buf, char *addr, unsigned long count) __size_overflow(3);
64864+extern long vwrite(char *buf, char *addr, unsigned long count) __size_overflow(3);
64865
64866 /*
64867 * Internals. Dont't use..
64868diff --git a/include/linux/vmstat.h b/include/linux/vmstat.h
64869index ad2cfd5..74c94ad 100644
64870--- a/include/linux/vmstat.h
64871+++ b/include/linux/vmstat.h
64872@@ -87,18 +87,18 @@ static inline void vm_events_fold_cpu(int cpu)
64873 /*
64874 * Zone based page accounting with per cpu differentials.
64875 */
64876-extern atomic_long_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
64877+extern atomic_long_unchecked_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
64878
64879 static inline void zone_page_state_add(long x, struct zone *zone,
64880 enum zone_stat_item item)
64881 {
64882- atomic_long_add(x, &zone->vm_stat[item]);
64883- atomic_long_add(x, &vm_stat[item]);
64884+ atomic_long_add_unchecked(x, &zone->vm_stat[item]);
64885+ atomic_long_add_unchecked(x, &vm_stat[item]);
64886 }
64887
64888 static inline unsigned long global_page_state(enum zone_stat_item item)
64889 {
64890- long x = atomic_long_read(&vm_stat[item]);
64891+ long x = atomic_long_read_unchecked(&vm_stat[item]);
64892 #ifdef CONFIG_SMP
64893 if (x < 0)
64894 x = 0;
64895@@ -109,7 +109,7 @@ static inline unsigned long global_page_state(enum zone_stat_item item)
64896 static inline unsigned long zone_page_state(struct zone *zone,
64897 enum zone_stat_item item)
64898 {
64899- long x = atomic_long_read(&zone->vm_stat[item]);
64900+ long x = atomic_long_read_unchecked(&zone->vm_stat[item]);
64901 #ifdef CONFIG_SMP
64902 if (x < 0)
64903 x = 0;
64904@@ -126,7 +126,7 @@ static inline unsigned long zone_page_state(struct zone *zone,
64905 static inline unsigned long zone_page_state_snapshot(struct zone *zone,
64906 enum zone_stat_item item)
64907 {
64908- long x = atomic_long_read(&zone->vm_stat[item]);
64909+ long x = atomic_long_read_unchecked(&zone->vm_stat[item]);
64910
64911 #ifdef CONFIG_SMP
64912 int cpu;
64913@@ -216,8 +216,8 @@ static inline void __mod_zone_page_state(struct zone *zone,
64914
64915 static inline void __inc_zone_state(struct zone *zone, enum zone_stat_item item)
64916 {
64917- atomic_long_inc(&zone->vm_stat[item]);
64918- atomic_long_inc(&vm_stat[item]);
64919+ atomic_long_inc_unchecked(&zone->vm_stat[item]);
64920+ atomic_long_inc_unchecked(&vm_stat[item]);
64921 }
64922
64923 static inline void __inc_zone_page_state(struct page *page,
64924@@ -228,8 +228,8 @@ static inline void __inc_zone_page_state(struct page *page,
64925
64926 static inline void __dec_zone_state(struct zone *zone, enum zone_stat_item item)
64927 {
64928- atomic_long_dec(&zone->vm_stat[item]);
64929- atomic_long_dec(&vm_stat[item]);
64930+ atomic_long_dec_unchecked(&zone->vm_stat[item]);
64931+ atomic_long_dec_unchecked(&vm_stat[item]);
64932 }
64933
64934 static inline void __dec_zone_page_state(struct page *page,
64935diff --git a/include/linux/xattr.h b/include/linux/xattr.h
64936index e5d1220..ef6e406 100644
64937--- a/include/linux/xattr.h
64938+++ b/include/linux/xattr.h
64939@@ -57,6 +57,11 @@
64940 #define XATTR_POSIX_ACL_DEFAULT "posix_acl_default"
64941 #define XATTR_NAME_POSIX_ACL_DEFAULT XATTR_SYSTEM_PREFIX XATTR_POSIX_ACL_DEFAULT
64942
64943+/* User namespace */
64944+#define XATTR_PAX_PREFIX XATTR_USER_PREFIX "pax."
64945+#define XATTR_PAX_FLAGS_SUFFIX "flags"
64946+#define XATTR_NAME_PAX_FLAGS XATTR_PAX_PREFIX XATTR_PAX_FLAGS_SUFFIX
64947+
64948 #ifdef __KERNEL__
64949
64950 #include <linux/types.h>
64951diff --git a/include/media/saa7146_vv.h b/include/media/saa7146_vv.h
64952index 944ecdf..a3994fc 100644
64953--- a/include/media/saa7146_vv.h
64954+++ b/include/media/saa7146_vv.h
64955@@ -161,8 +161,8 @@ struct saa7146_ext_vv
64956 int (*std_callback)(struct saa7146_dev*, struct saa7146_standard *);
64957
64958 /* the extension can override this */
64959- struct v4l2_ioctl_ops vid_ops;
64960- struct v4l2_ioctl_ops vbi_ops;
64961+ v4l2_ioctl_ops_no_const vid_ops;
64962+ v4l2_ioctl_ops_no_const vbi_ops;
64963 /* pointer to the saa7146 core ops */
64964 const struct v4l2_ioctl_ops *core_ops;
64965
64966diff --git a/include/media/v4l2-dev.h b/include/media/v4l2-dev.h
64967index 5c416cd..20021aa 100644
64968--- a/include/media/v4l2-dev.h
64969+++ b/include/media/v4l2-dev.h
64970@@ -73,7 +73,8 @@ struct v4l2_file_operations {
64971 int (*mmap) (struct file *, struct vm_area_struct *);
64972 int (*open) (struct file *);
64973 int (*release) (struct file *);
64974-};
64975+} __do_const;
64976+typedef struct v4l2_file_operations __no_const v4l2_file_operations_no_const;
64977
64978 /*
64979 * Newer version of video_device, handled by videodev2.c
64980diff --git a/include/media/v4l2-ioctl.h b/include/media/v4l2-ioctl.h
64981index e614c9c..20602b7 100644
64982--- a/include/media/v4l2-ioctl.h
64983+++ b/include/media/v4l2-ioctl.h
64984@@ -289,7 +289,7 @@ struct v4l2_ioctl_ops {
64985 long (*vidioc_default) (struct file *file, void *fh,
64986 bool valid_prio, int cmd, void *arg);
64987 };
64988-
64989+typedef struct v4l2_ioctl_ops __no_const v4l2_ioctl_ops_no_const;
64990
64991 /* v4l debugging and diagnostics */
64992
64993diff --git a/include/net/caif/caif_hsi.h b/include/net/caif/caif_hsi.h
64994index bcb9cc3..f4ec722e 100644
64995--- a/include/net/caif/caif_hsi.h
64996+++ b/include/net/caif/caif_hsi.h
64997@@ -98,7 +98,7 @@ struct cfhsi_cb_ops {
64998 void (*rx_done_cb) (struct cfhsi_cb_ops *drv);
64999 void (*wake_up_cb) (struct cfhsi_cb_ops *drv);
65000 void (*wake_down_cb) (struct cfhsi_cb_ops *drv);
65001-};
65002+} __no_const;
65003
65004 /* Structure implemented by HSI device. */
65005 struct cfhsi_ops {
65006diff --git a/include/net/caif/cfctrl.h b/include/net/caif/cfctrl.h
65007index 9e5425b..8136ffc 100644
65008--- a/include/net/caif/cfctrl.h
65009+++ b/include/net/caif/cfctrl.h
65010@@ -52,7 +52,7 @@ struct cfctrl_rsp {
65011 void (*radioset_rsp)(void);
65012 void (*reject_rsp)(struct cflayer *layer, u8 linkid,
65013 struct cflayer *client_layer);
65014-};
65015+} __no_const;
65016
65017 /* Link Setup Parameters for CAIF-Links. */
65018 struct cfctrl_link_param {
65019@@ -101,8 +101,8 @@ struct cfctrl_request_info {
65020 struct cfctrl {
65021 struct cfsrvl serv;
65022 struct cfctrl_rsp res;
65023- atomic_t req_seq_no;
65024- atomic_t rsp_seq_no;
65025+ atomic_unchecked_t req_seq_no;
65026+ atomic_unchecked_t rsp_seq_no;
65027 struct list_head list;
65028 /* Protects from simultaneous access to first_req list */
65029 spinlock_t info_list_lock;
65030diff --git a/include/net/flow.h b/include/net/flow.h
65031index 628e11b..4c475df 100644
65032--- a/include/net/flow.h
65033+++ b/include/net/flow.h
65034@@ -221,6 +221,6 @@ extern struct flow_cache_object *flow_cache_lookup(
65035
65036 extern void flow_cache_flush(void);
65037 extern void flow_cache_flush_deferred(void);
65038-extern atomic_t flow_cache_genid;
65039+extern atomic_unchecked_t flow_cache_genid;
65040
65041 #endif
65042diff --git a/include/net/inetpeer.h b/include/net/inetpeer.h
65043index 53f464d..ba76aaa 100644
65044--- a/include/net/inetpeer.h
65045+++ b/include/net/inetpeer.h
65046@@ -47,8 +47,8 @@ struct inet_peer {
65047 */
65048 union {
65049 struct {
65050- atomic_t rid; /* Frag reception counter */
65051- atomic_t ip_id_count; /* IP ID for the next packet */
65052+ atomic_unchecked_t rid; /* Frag reception counter */
65053+ atomic_unchecked_t ip_id_count; /* IP ID for the next packet */
65054 };
65055 struct rcu_head rcu;
65056 struct inet_peer *gc_next;
65057@@ -182,11 +182,11 @@ static inline int inet_getid(struct inet_peer *p, int more)
65058 more++;
65059 inet_peer_refcheck(p);
65060 do {
65061- old = atomic_read(&p->ip_id_count);
65062+ old = atomic_read_unchecked(&p->ip_id_count);
65063 new = old + more;
65064 if (!new)
65065 new = 1;
65066- } while (atomic_cmpxchg(&p->ip_id_count, old, new) != old);
65067+ } while (atomic_cmpxchg_unchecked(&p->ip_id_count, old, new) != old);
65068 return new;
65069 }
65070
65071diff --git a/include/net/ip_fib.h b/include/net/ip_fib.h
65072index 9497be1..5a4fafe 100644
65073--- a/include/net/ip_fib.h
65074+++ b/include/net/ip_fib.h
65075@@ -169,7 +169,7 @@ extern __be32 fib_info_update_nh_saddr(struct net *net, struct fib_nh *nh);
65076
65077 #define FIB_RES_SADDR(net, res) \
65078 ((FIB_RES_NH(res).nh_saddr_genid == \
65079- atomic_read(&(net)->ipv4.dev_addr_genid)) ? \
65080+ atomic_read_unchecked(&(net)->ipv4.dev_addr_genid)) ? \
65081 FIB_RES_NH(res).nh_saddr : \
65082 fib_info_update_nh_saddr((net), &FIB_RES_NH(res)))
65083 #define FIB_RES_GW(res) (FIB_RES_NH(res).nh_gw)
65084diff --git a/include/net/ip_vs.h b/include/net/ip_vs.h
65085index 95374d1..2300e36 100644
65086--- a/include/net/ip_vs.h
65087+++ b/include/net/ip_vs.h
65088@@ -510,7 +510,7 @@ struct ip_vs_conn {
65089 struct ip_vs_conn *control; /* Master control connection */
65090 atomic_t n_control; /* Number of controlled ones */
65091 struct ip_vs_dest *dest; /* real server */
65092- atomic_t in_pkts; /* incoming packet counter */
65093+ atomic_unchecked_t in_pkts; /* incoming packet counter */
65094
65095 /* packet transmitter for different forwarding methods. If it
65096 mangles the packet, it must return NF_DROP or better NF_STOLEN,
65097@@ -648,7 +648,7 @@ struct ip_vs_dest {
65098 __be16 port; /* port number of the server */
65099 union nf_inet_addr addr; /* IP address of the server */
65100 volatile unsigned int flags; /* dest status flags */
65101- atomic_t conn_flags; /* flags to copy to conn */
65102+ atomic_unchecked_t conn_flags; /* flags to copy to conn */
65103 atomic_t weight; /* server weight */
65104
65105 atomic_t refcnt; /* reference counter */
65106diff --git a/include/net/irda/ircomm_core.h b/include/net/irda/ircomm_core.h
65107index 69b610a..fe3962c 100644
65108--- a/include/net/irda/ircomm_core.h
65109+++ b/include/net/irda/ircomm_core.h
65110@@ -51,7 +51,7 @@ typedef struct {
65111 int (*connect_response)(struct ircomm_cb *, struct sk_buff *);
65112 int (*disconnect_request)(struct ircomm_cb *, struct sk_buff *,
65113 struct ircomm_info *);
65114-} call_t;
65115+} __no_const call_t;
65116
65117 struct ircomm_cb {
65118 irda_queue_t queue;
65119diff --git a/include/net/irda/ircomm_tty.h b/include/net/irda/ircomm_tty.h
65120index 59ba38bc..d515662 100644
65121--- a/include/net/irda/ircomm_tty.h
65122+++ b/include/net/irda/ircomm_tty.h
65123@@ -35,6 +35,7 @@
65124 #include <linux/termios.h>
65125 #include <linux/timer.h>
65126 #include <linux/tty.h> /* struct tty_struct */
65127+#include <asm/local.h>
65128
65129 #include <net/irda/irias_object.h>
65130 #include <net/irda/ircomm_core.h>
65131@@ -105,8 +106,8 @@ struct ircomm_tty_cb {
65132 unsigned short close_delay;
65133 unsigned short closing_wait; /* time to wait before closing */
65134
65135- int open_count;
65136- int blocked_open; /* # of blocked opens */
65137+ local_t open_count;
65138+ local_t blocked_open; /* # of blocked opens */
65139
65140 /* Protect concurent access to :
65141 * o self->open_count
65142diff --git a/include/net/iucv/af_iucv.h b/include/net/iucv/af_iucv.h
65143index cc7c197..9f2da2a 100644
65144--- a/include/net/iucv/af_iucv.h
65145+++ b/include/net/iucv/af_iucv.h
65146@@ -141,7 +141,7 @@ struct iucv_sock {
65147 struct iucv_sock_list {
65148 struct hlist_head head;
65149 rwlock_t lock;
65150- atomic_t autobind_name;
65151+ atomic_unchecked_t autobind_name;
65152 };
65153
65154 unsigned int iucv_sock_poll(struct file *file, struct socket *sock,
65155diff --git a/include/net/neighbour.h b/include/net/neighbour.h
65156index 344d898..2ae1302 100644
65157--- a/include/net/neighbour.h
65158+++ b/include/net/neighbour.h
65159@@ -123,7 +123,7 @@ struct neigh_ops {
65160 void (*error_report)(struct neighbour *, struct sk_buff *);
65161 int (*output)(struct neighbour *, struct sk_buff *);
65162 int (*connected_output)(struct neighbour *, struct sk_buff *);
65163-};
65164+} __do_const;
65165
65166 struct pneigh_entry {
65167 struct pneigh_entry *next;
65168diff --git a/include/net/net_namespace.h b/include/net/net_namespace.h
65169index fd87963..312a11f 100644
65170--- a/include/net/net_namespace.h
65171+++ b/include/net/net_namespace.h
65172@@ -102,7 +102,7 @@ struct net {
65173 #endif
65174 struct netns_ipvs *ipvs;
65175 struct sock *diag_nlsk;
65176- atomic_t rt_genid;
65177+ atomic_unchecked_t rt_genid;
65178 };
65179
65180
65181@@ -303,12 +303,12 @@ static inline void unregister_net_sysctl_table(struct ctl_table_header *header)
65182
65183 static inline int rt_genid(struct net *net)
65184 {
65185- return atomic_read(&net->rt_genid);
65186+ return atomic_read_unchecked(&net->rt_genid);
65187 }
65188
65189 static inline void rt_genid_bump(struct net *net)
65190 {
65191- atomic_inc(&net->rt_genid);
65192+ atomic_inc_unchecked(&net->rt_genid);
65193 }
65194
65195 #endif /* __NET_NET_NAMESPACE_H */
65196diff --git a/include/net/netdma.h b/include/net/netdma.h
65197index 8ba8ce2..99b7fff 100644
65198--- a/include/net/netdma.h
65199+++ b/include/net/netdma.h
65200@@ -24,7 +24,7 @@
65201 #include <linux/dmaengine.h>
65202 #include <linux/skbuff.h>
65203
65204-int dma_skb_copy_datagram_iovec(struct dma_chan* chan,
65205+int __intentional_overflow(3,5) dma_skb_copy_datagram_iovec(struct dma_chan* chan,
65206 struct sk_buff *skb, int offset, struct iovec *to,
65207 size_t len, struct dma_pinned_list *pinned_list);
65208
65209diff --git a/include/net/netlink.h b/include/net/netlink.h
65210index 785f37a..c81dc0c 100644
65211--- a/include/net/netlink.h
65212+++ b/include/net/netlink.h
65213@@ -520,7 +520,7 @@ static inline void *nlmsg_get_pos(struct sk_buff *skb)
65214 static inline void nlmsg_trim(struct sk_buff *skb, const void *mark)
65215 {
65216 if (mark)
65217- skb_trim(skb, (unsigned char *) mark - skb->data);
65218+ skb_trim(skb, (const unsigned char *) mark - skb->data);
65219 }
65220
65221 /**
65222diff --git a/include/net/netns/ipv4.h b/include/net/netns/ipv4.h
65223index eb24dbc..567d6ed 100644
65224--- a/include/net/netns/ipv4.h
65225+++ b/include/net/netns/ipv4.h
65226@@ -65,7 +65,7 @@ struct netns_ipv4 {
65227 unsigned int sysctl_ping_group_range[2];
65228 long sysctl_tcp_mem[3];
65229
65230- atomic_t dev_addr_genid;
65231+ atomic_unchecked_t dev_addr_genid;
65232
65233 #ifdef CONFIG_IP_MROUTE
65234 #ifndef CONFIG_IP_MROUTE_MULTIPLE_TABLES
65235diff --git a/include/net/sctp/sctp.h b/include/net/sctp/sctp.h
65236index ff49964..1411fee 100644
65237--- a/include/net/sctp/sctp.h
65238+++ b/include/net/sctp/sctp.h
65239@@ -320,9 +320,9 @@ do { \
65240
65241 #else /* SCTP_DEBUG */
65242
65243-#define SCTP_DEBUG_PRINTK(whatever...)
65244-#define SCTP_DEBUG_PRINTK_CONT(fmt, args...)
65245-#define SCTP_DEBUG_PRINTK_IPADDR(whatever...)
65246+#define SCTP_DEBUG_PRINTK(whatever...) do {} while (0)
65247+#define SCTP_DEBUG_PRINTK_CONT(fmt, args...) do {} while (0)
65248+#define SCTP_DEBUG_PRINTK_IPADDR(whatever...) do {} while (0)
65249 #define SCTP_ENABLE_DEBUG
65250 #define SCTP_DISABLE_DEBUG
65251 #define SCTP_ASSERT(expr, str, func)
65252diff --git a/include/net/sock.h b/include/net/sock.h
65253index adb7da2..1100002 100644
65254--- a/include/net/sock.h
65255+++ b/include/net/sock.h
65256@@ -305,7 +305,7 @@ struct sock {
65257 #ifdef CONFIG_RPS
65258 __u32 sk_rxhash;
65259 #endif
65260- atomic_t sk_drops;
65261+ atomic_unchecked_t sk_drops;
65262 int sk_rcvbuf;
65263
65264 struct sk_filter __rcu *sk_filter;
65265@@ -1764,7 +1764,7 @@ static inline void sk_nocaps_add(struct sock *sk, netdev_features_t flags)
65266 }
65267
65268 static inline int skb_do_copy_data_nocache(struct sock *sk, struct sk_buff *skb,
65269- char __user *from, char *to,
65270+ char __user *from, unsigned char *to,
65271 int copy, int offset)
65272 {
65273 if (skb->ip_summed == CHECKSUM_NONE) {
65274@@ -2023,7 +2023,7 @@ static inline void sk_stream_moderate_sndbuf(struct sock *sk)
65275 }
65276 }
65277
65278-struct sk_buff *sk_stream_alloc_skb(struct sock *sk, int size, gfp_t gfp);
65279+struct sk_buff * __intentional_overflow(0) sk_stream_alloc_skb(struct sock *sk, int size, gfp_t gfp);
65280
65281 static inline struct page *sk_stream_alloc_page(struct sock *sk)
65282 {
65283diff --git a/include/net/tcp.h b/include/net/tcp.h
65284index 1f000ff..e5a8dfb 100644
65285--- a/include/net/tcp.h
65286+++ b/include/net/tcp.h
65287@@ -508,7 +508,7 @@ extern void tcp_retransmit_timer(struct sock *sk);
65288 extern void tcp_xmit_retransmit_queue(struct sock *);
65289 extern void tcp_simple_retransmit(struct sock *);
65290 extern int tcp_trim_head(struct sock *, struct sk_buff *, u32);
65291-extern int tcp_fragment(struct sock *, struct sk_buff *, u32, unsigned int);
65292+extern int __intentional_overflow(3) tcp_fragment(struct sock *, struct sk_buff *, u32, unsigned int);
65293
65294 extern void tcp_send_probe0(struct sock *);
65295 extern void tcp_send_partial(struct sock *);
65296@@ -677,8 +677,8 @@ struct tcp_skb_cb {
65297 struct inet6_skb_parm h6;
65298 #endif
65299 } header; /* For incoming frames */
65300- __u32 seq; /* Starting sequence number */
65301- __u32 end_seq; /* SEQ + FIN + SYN + datalen */
65302+ __u32 seq __intentional_overflow(0); /* Starting sequence number */
65303+ __u32 end_seq __intentional_overflow(0); /* SEQ + FIN + SYN + datalen */
65304 __u32 when; /* used to compute rtt's */
65305 __u8 tcp_flags; /* TCP header flags. (tcp[13]) */
65306
65307@@ -692,7 +692,7 @@ struct tcp_skb_cb {
65308
65309 __u8 ip_dsfield; /* IPv4 tos or IPv6 dsfield */
65310 /* 1 byte hole */
65311- __u32 ack_seq; /* Sequence number ACK'd */
65312+ __u32 ack_seq __intentional_overflow(0); /* Sequence number ACK'd */
65313 };
65314
65315 #define TCP_SKB_CB(__skb) ((struct tcp_skb_cb *)&((__skb)->cb[0]))
65316@@ -1502,7 +1502,7 @@ struct tcp_seq_afinfo {
65317 char *name;
65318 sa_family_t family;
65319 const struct file_operations *seq_fops;
65320- struct seq_operations seq_ops;
65321+ seq_operations_no_const seq_ops;
65322 };
65323
65324 struct tcp_iter_state {
65325diff --git a/include/net/udp.h b/include/net/udp.h
65326index 065f379..b661b40 100644
65327--- a/include/net/udp.h
65328+++ b/include/net/udp.h
65329@@ -244,7 +244,7 @@ struct udp_seq_afinfo {
65330 sa_family_t family;
65331 struct udp_table *udp_table;
65332 const struct file_operations *seq_fops;
65333- struct seq_operations seq_ops;
65334+ seq_operations_no_const seq_ops;
65335 };
65336
65337 struct udp_iter_state {
65338diff --git a/include/net/xfrm.h b/include/net/xfrm.h
65339index 639dd13..15b206c 100644
65340--- a/include/net/xfrm.h
65341+++ b/include/net/xfrm.h
65342@@ -514,7 +514,7 @@ struct xfrm_policy {
65343 struct timer_list timer;
65344
65345 struct flow_cache_object flo;
65346- atomic_t genid;
65347+ atomic_unchecked_t genid;
65348 u32 priority;
65349 u32 index;
65350 struct xfrm_mark mark;
65351diff --git a/include/rdma/iw_cm.h b/include/rdma/iw_cm.h
65352index 1a046b1..ee0bef0 100644
65353--- a/include/rdma/iw_cm.h
65354+++ b/include/rdma/iw_cm.h
65355@@ -122,7 +122,7 @@ struct iw_cm_verbs {
65356 int backlog);
65357
65358 int (*destroy_listen)(struct iw_cm_id *cm_id);
65359-};
65360+} __no_const;
65361
65362 /**
65363 * iw_create_cm_id - Create an IW CM identifier.
65364diff --git a/include/scsi/libfc.h b/include/scsi/libfc.h
65365index 399162b..b337f1a 100644
65366--- a/include/scsi/libfc.h
65367+++ b/include/scsi/libfc.h
65368@@ -762,6 +762,7 @@ struct libfc_function_template {
65369 */
65370 void (*disc_stop_final) (struct fc_lport *);
65371 };
65372+typedef struct libfc_function_template __no_const libfc_function_template_no_const;
65373
65374 /**
65375 * struct fc_disc - Discovery context
65376@@ -866,7 +867,7 @@ struct fc_lport {
65377 struct fc_vport *vport;
65378
65379 /* Operational Information */
65380- struct libfc_function_template tt;
65381+ libfc_function_template_no_const tt;
65382 u8 link_up;
65383 u8 qfull;
65384 enum fc_lport_state state;
65385diff --git a/include/scsi/scsi_device.h b/include/scsi/scsi_device.h
65386index 9895f69..f1418f0 100644
65387--- a/include/scsi/scsi_device.h
65388+++ b/include/scsi/scsi_device.h
65389@@ -166,9 +166,9 @@ struct scsi_device {
65390 unsigned int max_device_blocked; /* what device_blocked counts down from */
65391 #define SCSI_DEFAULT_DEVICE_BLOCKED 3
65392
65393- atomic_t iorequest_cnt;
65394- atomic_t iodone_cnt;
65395- atomic_t ioerr_cnt;
65396+ atomic_unchecked_t iorequest_cnt;
65397+ atomic_unchecked_t iodone_cnt;
65398+ atomic_unchecked_t ioerr_cnt;
65399
65400 struct device sdev_gendev,
65401 sdev_dev;
65402diff --git a/include/scsi/scsi_transport_fc.h b/include/scsi/scsi_transport_fc.h
65403index b797e8f..8e2c3aa 100644
65404--- a/include/scsi/scsi_transport_fc.h
65405+++ b/include/scsi/scsi_transport_fc.h
65406@@ -751,7 +751,8 @@ struct fc_function_template {
65407 unsigned long show_host_system_hostname:1;
65408
65409 unsigned long disable_target_scan:1;
65410-};
65411+} __do_const;
65412+typedef struct fc_function_template __no_const fc_function_template_no_const;
65413
65414
65415 /**
65416diff --git a/include/sound/ak4xxx-adda.h b/include/sound/ak4xxx-adda.h
65417index 030b87c..98a6954 100644
65418--- a/include/sound/ak4xxx-adda.h
65419+++ b/include/sound/ak4xxx-adda.h
65420@@ -35,7 +35,7 @@ struct snd_ak4xxx_ops {
65421 void (*write)(struct snd_akm4xxx *ak, int chip, unsigned char reg,
65422 unsigned char val);
65423 void (*set_rate_val)(struct snd_akm4xxx *ak, unsigned int rate);
65424-};
65425+} __no_const;
65426
65427 #define AK4XXX_IMAGE_SIZE (AK4XXX_MAX_CHIPS * 16) /* 64 bytes */
65428
65429diff --git a/include/sound/hwdep.h b/include/sound/hwdep.h
65430index 8c05e47..2b5df97 100644
65431--- a/include/sound/hwdep.h
65432+++ b/include/sound/hwdep.h
65433@@ -49,7 +49,7 @@ struct snd_hwdep_ops {
65434 struct snd_hwdep_dsp_status *status);
65435 int (*dsp_load)(struct snd_hwdep *hw,
65436 struct snd_hwdep_dsp_image *image);
65437-};
65438+} __no_const;
65439
65440 struct snd_hwdep {
65441 struct snd_card *card;
65442diff --git a/include/sound/info.h b/include/sound/info.h
65443index 9ca1a49..aba1728 100644
65444--- a/include/sound/info.h
65445+++ b/include/sound/info.h
65446@@ -44,7 +44,7 @@ struct snd_info_entry_text {
65447 struct snd_info_buffer *buffer);
65448 void (*write)(struct snd_info_entry *entry,
65449 struct snd_info_buffer *buffer);
65450-};
65451+} __no_const;
65452
65453 struct snd_info_entry_ops {
65454 int (*open)(struct snd_info_entry *entry,
65455diff --git a/include/sound/pcm.h b/include/sound/pcm.h
65456index cdca2ab..10bbe05 100644
65457--- a/include/sound/pcm.h
65458+++ b/include/sound/pcm.h
65459@@ -81,6 +81,7 @@ struct snd_pcm_ops {
65460 int (*mmap)(struct snd_pcm_substream *substream, struct vm_area_struct *vma);
65461 int (*ack)(struct snd_pcm_substream *substream);
65462 };
65463+typedef struct snd_pcm_ops __no_const snd_pcm_ops_no_const;
65464
65465 /*
65466 *
65467diff --git a/include/sound/sb16_csp.h b/include/sound/sb16_csp.h
65468index af1b49e..a5d55a5 100644
65469--- a/include/sound/sb16_csp.h
65470+++ b/include/sound/sb16_csp.h
65471@@ -146,7 +146,7 @@ struct snd_sb_csp_ops {
65472 int (*csp_start) (struct snd_sb_csp * p, int sample_width, int channels);
65473 int (*csp_stop) (struct snd_sb_csp * p);
65474 int (*csp_qsound_transfer) (struct snd_sb_csp * p);
65475-};
65476+} __no_const;
65477
65478 /*
65479 * CSP private data
65480diff --git a/include/sound/soc.h b/include/sound/soc.h
65481index e063380..e8077d5 100644
65482--- a/include/sound/soc.h
65483+++ b/include/sound/soc.h
65484@@ -801,7 +801,7 @@ struct snd_soc_platform_driver {
65485 unsigned int (*read)(struct snd_soc_platform *, unsigned int);
65486 int (*write)(struct snd_soc_platform *, unsigned int, unsigned int);
65487 int (*bespoke_trigger)(struct snd_pcm_substream *, int);
65488-};
65489+} __do_const;
65490
65491 struct snd_soc_platform {
65492 const char *name;
65493@@ -1016,7 +1016,7 @@ struct snd_soc_pcm_runtime {
65494 struct snd_soc_dai_link *dai_link;
65495 struct mutex pcm_mutex;
65496 enum snd_soc_pcm_subclass pcm_subclass;
65497- struct snd_pcm_ops ops;
65498+ snd_pcm_ops_no_const ops;
65499
65500 unsigned int dev_registered:1;
65501
65502diff --git a/include/sound/tea575x-tuner.h b/include/sound/tea575x-tuner.h
65503index fe8590c..aaed363 100644
65504--- a/include/sound/tea575x-tuner.h
65505+++ b/include/sound/tea575x-tuner.h
65506@@ -48,7 +48,7 @@ struct snd_tea575x_ops {
65507
65508 struct snd_tea575x {
65509 struct v4l2_device *v4l2_dev;
65510- struct v4l2_file_operations fops;
65511+ v4l2_file_operations_no_const fops;
65512 struct video_device vd; /* video device */
65513 int radio_nr; /* radio_nr */
65514 bool tea5759; /* 5759 chip is present */
65515diff --git a/include/target/target_core_base.h b/include/target/target_core_base.h
65516index 5be8937..a8e46e9 100644
65517--- a/include/target/target_core_base.h
65518+++ b/include/target/target_core_base.h
65519@@ -434,7 +434,7 @@ struct t10_reservation_ops {
65520 int (*t10_seq_non_holder)(struct se_cmd *, unsigned char *, u32);
65521 int (*t10_pr_register)(struct se_cmd *);
65522 int (*t10_pr_clear)(struct se_cmd *);
65523-};
65524+} __no_const;
65525
65526 struct t10_reservation {
65527 /* Reservation effects all target ports */
65528@@ -758,7 +758,7 @@ struct se_device {
65529 spinlock_t stats_lock;
65530 /* Active commands on this virtual SE device */
65531 atomic_t simple_cmds;
65532- atomic_t dev_ordered_id;
65533+ atomic_unchecked_t dev_ordered_id;
65534 atomic_t dev_ordered_sync;
65535 atomic_t dev_qf_count;
65536 struct se_obj dev_obj;
65537diff --git a/include/trace/events/fs.h b/include/trace/events/fs.h
65538new file mode 100644
65539index 0000000..2efe49d
65540--- /dev/null
65541+++ b/include/trace/events/fs.h
65542@@ -0,0 +1,53 @@
65543+#undef TRACE_SYSTEM
65544+#define TRACE_SYSTEM fs
65545+
65546+#if !defined(_TRACE_FS_H) || defined(TRACE_HEADER_MULTI_READ)
65547+#define _TRACE_FS_H
65548+
65549+#include <linux/fs.h>
65550+#include <linux/tracepoint.h>
65551+
65552+TRACE_EVENT(do_sys_open,
65553+
65554+ TP_PROTO(char *filename, int flags, int mode),
65555+
65556+ TP_ARGS(filename, flags, mode),
65557+
65558+ TP_STRUCT__entry(
65559+ __string( filename, filename )
65560+ __field( int, flags )
65561+ __field( int, mode )
65562+ ),
65563+
65564+ TP_fast_assign(
65565+ __assign_str(filename, filename);
65566+ __entry->flags = flags;
65567+ __entry->mode = mode;
65568+ ),
65569+
65570+ TP_printk("\"%s\" %x %o",
65571+ __get_str(filename), __entry->flags, __entry->mode)
65572+);
65573+
65574+TRACE_EVENT(open_exec,
65575+
65576+ TP_PROTO(const char *filename),
65577+
65578+ TP_ARGS(filename),
65579+
65580+ TP_STRUCT__entry(
65581+ __string( filename, filename )
65582+ ),
65583+
65584+ TP_fast_assign(
65585+ __assign_str(filename, filename);
65586+ ),
65587+
65588+ TP_printk("\"%s\"",
65589+ __get_str(filename))
65590+);
65591+
65592+#endif /* _TRACE_FS_H */
65593+
65594+/* This part must be outside protection */
65595+#include <trace/define_trace.h>
65596diff --git a/include/trace/events/irq.h b/include/trace/events/irq.h
65597index 1c09820..7f5ec79 100644
65598--- a/include/trace/events/irq.h
65599+++ b/include/trace/events/irq.h
65600@@ -36,7 +36,7 @@ struct softirq_action;
65601 */
65602 TRACE_EVENT(irq_handler_entry,
65603
65604- TP_PROTO(int irq, struct irqaction *action),
65605+ TP_PROTO(int irq, const struct irqaction *action),
65606
65607 TP_ARGS(irq, action),
65608
65609@@ -66,7 +66,7 @@ TRACE_EVENT(irq_handler_entry,
65610 */
65611 TRACE_EVENT(irq_handler_exit,
65612
65613- TP_PROTO(int irq, struct irqaction *action, int ret),
65614+ TP_PROTO(int irq, const struct irqaction *action, int ret),
65615
65616 TP_ARGS(irq, action, ret),
65617
65618diff --git a/include/video/udlfb.h b/include/video/udlfb.h
65619index f9466fa..f4e2b81 100644
65620--- a/include/video/udlfb.h
65621+++ b/include/video/udlfb.h
65622@@ -53,10 +53,10 @@ struct dlfb_data {
65623 u32 pseudo_palette[256];
65624 int blank_mode; /*one of FB_BLANK_ */
65625 /* blit-only rendering path metrics, exposed through sysfs */
65626- atomic_t bytes_rendered; /* raw pixel-bytes driver asked to render */
65627- atomic_t bytes_identical; /* saved effort with backbuffer comparison */
65628- atomic_t bytes_sent; /* to usb, after compression including overhead */
65629- atomic_t cpu_kcycles_used; /* transpired during pixel processing */
65630+ atomic_unchecked_t bytes_rendered; /* raw pixel-bytes driver asked to render */
65631+ atomic_unchecked_t bytes_identical; /* saved effort with backbuffer comparison */
65632+ atomic_unchecked_t bytes_sent; /* to usb, after compression including overhead */
65633+ atomic_unchecked_t cpu_kcycles_used; /* transpired during pixel processing */
65634 };
65635
65636 #define NR_USB_REQUEST_I2C_SUB_IO 0x02
65637diff --git a/include/video/uvesafb.h b/include/video/uvesafb.h
65638index 0993a22..32ba2fe 100644
65639--- a/include/video/uvesafb.h
65640+++ b/include/video/uvesafb.h
65641@@ -177,6 +177,7 @@ struct uvesafb_par {
65642 u8 ypan; /* 0 - nothing, 1 - ypan, 2 - ywrap */
65643 u8 pmi_setpal; /* PMI for palette changes */
65644 u16 *pmi_base; /* protected mode interface location */
65645+ u8 *pmi_code; /* protected mode code location */
65646 void *pmi_start;
65647 void *pmi_pal;
65648 u8 *vbe_state_orig; /*
65649diff --git a/init/Kconfig b/init/Kconfig
65650index af6c7f8..5c188f8 100644
65651--- a/init/Kconfig
65652+++ b/init/Kconfig
65653@@ -850,6 +850,7 @@ endif # CGROUPS
65654
65655 config CHECKPOINT_RESTORE
65656 bool "Checkpoint/restore support" if EXPERT
65657+ depends on !GRKERNSEC
65658 default n
65659 help
65660 Enables additional kernel features in a sake of checkpoint/restore.
65661@@ -1029,6 +1030,7 @@ config UIDGID_CONVERTED
65662 # Security modules
65663 depends on SECURITY_TOMOYO = n
65664 depends on SECURITY_APPARMOR = n
65665+ depends on GRKERNSEC = n
65666
65667 config UIDGID_STRICT_TYPE_CHECKS
65668 bool "Require conversions between uid/gids and their internal representation"
65669@@ -1416,7 +1418,7 @@ config SLUB_DEBUG
65670
65671 config COMPAT_BRK
65672 bool "Disable heap randomization"
65673- default y
65674+ default n
65675 help
65676 Randomizing heap placement makes heap exploits harder, but it
65677 also breaks ancient binaries (including anything libc5 based).
65678@@ -1599,7 +1601,7 @@ config INIT_ALL_POSSIBLE
65679 config STOP_MACHINE
65680 bool
65681 default y
65682- depends on (SMP && MODULE_UNLOAD) || HOTPLUG_CPU
65683+ depends on (SMP && MODULE_UNLOAD) || HOTPLUG_CPU || GRKERNSEC
65684 help
65685 Need stop_machine() primitive.
65686
65687diff --git a/init/Makefile b/init/Makefile
65688index 7bc47ee..6da2dc7 100644
65689--- a/init/Makefile
65690+++ b/init/Makefile
65691@@ -2,6 +2,9 @@
65692 # Makefile for the linux kernel.
65693 #
65694
65695+ccflags-y := $(GCC_PLUGINS_CFLAGS)
65696+asflags-y := $(GCC_PLUGINS_AFLAGS)
65697+
65698 obj-y := main.o version.o mounts.o
65699 ifneq ($(CONFIG_BLK_DEV_INITRD),y)
65700 obj-y += noinitramfs.o
65701diff --git a/init/do_mounts.c b/init/do_mounts.c
65702index d3f0aee..c9322f5 100644
65703--- a/init/do_mounts.c
65704+++ b/init/do_mounts.c
65705@@ -336,11 +336,11 @@ static void __init get_fs_names(char *page)
65706 static int __init do_mount_root(char *name, char *fs, int flags, void *data)
65707 {
65708 struct super_block *s;
65709- int err = sys_mount(name, "/root", fs, flags, data);
65710+ int err = sys_mount((char __force_user *)name, (char __force_user *)"/root", (char __force_user *)fs, flags, (void __force_user *)data);
65711 if (err)
65712 return err;
65713
65714- sys_chdir("/root");
65715+ sys_chdir((const char __force_user *)"/root");
65716 s = current->fs->pwd.dentry->d_sb;
65717 ROOT_DEV = s->s_dev;
65718 printk(KERN_INFO
65719@@ -460,18 +460,18 @@ void __init change_floppy(char *fmt, ...)
65720 va_start(args, fmt);
65721 vsprintf(buf, fmt, args);
65722 va_end(args);
65723- fd = sys_open("/dev/root", O_RDWR | O_NDELAY, 0);
65724+ fd = sys_open((char __user *)"/dev/root", O_RDWR | O_NDELAY, 0);
65725 if (fd >= 0) {
65726 sys_ioctl(fd, FDEJECT, 0);
65727 sys_close(fd);
65728 }
65729 printk(KERN_NOTICE "VFS: Insert %s and press ENTER\n", buf);
65730- fd = sys_open("/dev/console", O_RDWR, 0);
65731+ fd = sys_open((__force const char __user *)"/dev/console", O_RDWR, 0);
65732 if (fd >= 0) {
65733 sys_ioctl(fd, TCGETS, (long)&termios);
65734 termios.c_lflag &= ~ICANON;
65735 sys_ioctl(fd, TCSETSF, (long)&termios);
65736- sys_read(fd, &c, 1);
65737+ sys_read(fd, (char __user *)&c, 1);
65738 termios.c_lflag |= ICANON;
65739 sys_ioctl(fd, TCSETSF, (long)&termios);
65740 sys_close(fd);
65741@@ -565,6 +565,6 @@ void __init prepare_namespace(void)
65742 mount_root();
65743 out:
65744 devtmpfs_mount("dev");
65745- sys_mount(".", "/", NULL, MS_MOVE, NULL);
65746- sys_chroot(".");
65747+ sys_mount((char __force_user *)".", (char __force_user *)"/", NULL, MS_MOVE, NULL);
65748+ sys_chroot((const char __force_user *)".");
65749 }
65750diff --git a/init/do_mounts.h b/init/do_mounts.h
65751index f5b978a..69dbfe8 100644
65752--- a/init/do_mounts.h
65753+++ b/init/do_mounts.h
65754@@ -15,15 +15,15 @@ extern int root_mountflags;
65755
65756 static inline int create_dev(char *name, dev_t dev)
65757 {
65758- sys_unlink(name);
65759- return sys_mknod(name, S_IFBLK|0600, new_encode_dev(dev));
65760+ sys_unlink((char __force_user *)name);
65761+ return sys_mknod((char __force_user *)name, S_IFBLK|0600, new_encode_dev(dev));
65762 }
65763
65764 #if BITS_PER_LONG == 32
65765 static inline u32 bstat(char *name)
65766 {
65767 struct stat64 stat;
65768- if (sys_stat64(name, &stat) != 0)
65769+ if (sys_stat64((char __force_user *)name, (struct stat64 __force_user *)&stat) != 0)
65770 return 0;
65771 if (!S_ISBLK(stat.st_mode))
65772 return 0;
65773@@ -35,7 +35,7 @@ static inline u32 bstat(char *name)
65774 static inline u32 bstat(char *name)
65775 {
65776 struct stat stat;
65777- if (sys_newstat(name, &stat) != 0)
65778+ if (sys_newstat((const char __force_user *)name, (struct stat __force_user *)&stat) != 0)
65779 return 0;
65780 if (!S_ISBLK(stat.st_mode))
65781 return 0;
65782diff --git a/init/do_mounts_initrd.c b/init/do_mounts_initrd.c
65783index 135959a2..28a3f43 100644
65784--- a/init/do_mounts_initrd.c
65785+++ b/init/do_mounts_initrd.c
65786@@ -53,13 +53,13 @@ static void __init handle_initrd(void)
65787 create_dev("/dev/root.old", Root_RAM0);
65788 /* mount initrd on rootfs' /root */
65789 mount_block_root("/dev/root.old", root_mountflags & ~MS_RDONLY);
65790- sys_mkdir("/old", 0700);
65791- root_fd = sys_open("/", 0, 0);
65792- old_fd = sys_open("/old", 0, 0);
65793+ sys_mkdir((const char __force_user *)"/old", 0700);
65794+ root_fd = sys_open((const char __force_user *)"/", 0, 0);
65795+ old_fd = sys_open((const char __force_user *)"/old", 0, 0);
65796 /* move initrd over / and chdir/chroot in initrd root */
65797- sys_chdir("/root");
65798- sys_mount(".", "/", NULL, MS_MOVE, NULL);
65799- sys_chroot(".");
65800+ sys_chdir((const char __force_user *)"/root");
65801+ sys_mount((char __force_user *)".", (char __force_user *)"/", NULL, MS_MOVE, NULL);
65802+ sys_chroot((const char __force_user *)".");
65803
65804 /*
65805 * In case that a resume from disk is carried out by linuxrc or one of
65806@@ -76,15 +76,15 @@ static void __init handle_initrd(void)
65807
65808 /* move initrd to rootfs' /old */
65809 sys_fchdir(old_fd);
65810- sys_mount("/", ".", NULL, MS_MOVE, NULL);
65811+ sys_mount((char __force_user *)"/", (char __force_user *)".", NULL, MS_MOVE, NULL);
65812 /* switch root and cwd back to / of rootfs */
65813 sys_fchdir(root_fd);
65814- sys_chroot(".");
65815+ sys_chroot((const char __force_user *)".");
65816 sys_close(old_fd);
65817 sys_close(root_fd);
65818
65819 if (new_decode_dev(real_root_dev) == Root_RAM0) {
65820- sys_chdir("/old");
65821+ sys_chdir((const char __force_user *)"/old");
65822 return;
65823 }
65824
65825@@ -92,17 +92,17 @@ static void __init handle_initrd(void)
65826 mount_root();
65827
65828 printk(KERN_NOTICE "Trying to move old root to /initrd ... ");
65829- error = sys_mount("/old", "/root/initrd", NULL, MS_MOVE, NULL);
65830+ error = sys_mount((char __force_user *)"/old", (char __force_user *)"/root/initrd", NULL, MS_MOVE, NULL);
65831 if (!error)
65832 printk("okay\n");
65833 else {
65834- int fd = sys_open("/dev/root.old", O_RDWR, 0);
65835+ int fd = sys_open((const char __force_user *)"/dev/root.old", O_RDWR, 0);
65836 if (error == -ENOENT)
65837 printk("/initrd does not exist. Ignored.\n");
65838 else
65839 printk("failed\n");
65840 printk(KERN_NOTICE "Unmounting old root\n");
65841- sys_umount("/old", MNT_DETACH);
65842+ sys_umount((char __force_user *)"/old", MNT_DETACH);
65843 printk(KERN_NOTICE "Trying to free ramdisk memory ... ");
65844 if (fd < 0) {
65845 error = fd;
65846@@ -125,11 +125,11 @@ int __init initrd_load(void)
65847 * mounted in the normal path.
65848 */
65849 if (rd_load_image("/initrd.image") && ROOT_DEV != Root_RAM0) {
65850- sys_unlink("/initrd.image");
65851+ sys_unlink((const char __force_user *)"/initrd.image");
65852 handle_initrd();
65853 return 1;
65854 }
65855 }
65856- sys_unlink("/initrd.image");
65857+ sys_unlink((const char __force_user *)"/initrd.image");
65858 return 0;
65859 }
65860diff --git a/init/do_mounts_md.c b/init/do_mounts_md.c
65861index 8cb6db5..d729f50 100644
65862--- a/init/do_mounts_md.c
65863+++ b/init/do_mounts_md.c
65864@@ -180,7 +180,7 @@ static void __init md_setup_drive(void)
65865 partitioned ? "_d" : "", minor,
65866 md_setup_args[ent].device_names);
65867
65868- fd = sys_open(name, 0, 0);
65869+ fd = sys_open((char __force_user *)name, 0, 0);
65870 if (fd < 0) {
65871 printk(KERN_ERR "md: open failed - cannot start "
65872 "array %s\n", name);
65873@@ -243,7 +243,7 @@ static void __init md_setup_drive(void)
65874 * array without it
65875 */
65876 sys_close(fd);
65877- fd = sys_open(name, 0, 0);
65878+ fd = sys_open((char __force_user *)name, 0, 0);
65879 sys_ioctl(fd, BLKRRPART, 0);
65880 }
65881 sys_close(fd);
65882@@ -293,7 +293,7 @@ static void __init autodetect_raid(void)
65883
65884 wait_for_device_probe();
65885
65886- fd = sys_open("/dev/md0", 0, 0);
65887+ fd = sys_open((const char __force_user *) "/dev/md0", 0, 0);
65888 if (fd >= 0) {
65889 sys_ioctl(fd, RAID_AUTORUN, raid_autopart);
65890 sys_close(fd);
65891diff --git a/init/init_task.c b/init/init_task.c
65892index 8b2f399..f0797c9 100644
65893--- a/init/init_task.c
65894+++ b/init/init_task.c
65895@@ -20,5 +20,9 @@ EXPORT_SYMBOL(init_task);
65896 * Initial thread structure. Alignment of this is handled by a special
65897 * linker map entry.
65898 */
65899+#ifdef CONFIG_X86
65900+union thread_union init_thread_union __init_task_data;
65901+#else
65902 union thread_union init_thread_union __init_task_data =
65903 { INIT_THREAD_INFO(init_task) };
65904+#endif
65905diff --git a/init/initramfs.c b/init/initramfs.c
65906index 84c6bf1..8899338 100644
65907--- a/init/initramfs.c
65908+++ b/init/initramfs.c
65909@@ -84,7 +84,7 @@ static void __init free_hash(void)
65910 }
65911 }
65912
65913-static long __init do_utime(char *filename, time_t mtime)
65914+static long __init do_utime(char __force_user *filename, time_t mtime)
65915 {
65916 struct timespec t[2];
65917
65918@@ -119,7 +119,7 @@ static void __init dir_utime(void)
65919 struct dir_entry *de, *tmp;
65920 list_for_each_entry_safe(de, tmp, &dir_list, list) {
65921 list_del(&de->list);
65922- do_utime(de->name, de->mtime);
65923+ do_utime((char __force_user *)de->name, de->mtime);
65924 kfree(de->name);
65925 kfree(de);
65926 }
65927@@ -281,7 +281,7 @@ static int __init maybe_link(void)
65928 if (nlink >= 2) {
65929 char *old = find_link(major, minor, ino, mode, collected);
65930 if (old)
65931- return (sys_link(old, collected) < 0) ? -1 : 1;
65932+ return (sys_link((char __force_user *)old, (char __force_user *)collected) < 0) ? -1 : 1;
65933 }
65934 return 0;
65935 }
65936@@ -290,11 +290,11 @@ static void __init clean_path(char *path, umode_t mode)
65937 {
65938 struct stat st;
65939
65940- if (!sys_newlstat(path, &st) && (st.st_mode^mode) & S_IFMT) {
65941+ if (!sys_newlstat((char __force_user *)path, (struct stat __force_user *)&st) && (st.st_mode^mode) & S_IFMT) {
65942 if (S_ISDIR(st.st_mode))
65943- sys_rmdir(path);
65944+ sys_rmdir((char __force_user *)path);
65945 else
65946- sys_unlink(path);
65947+ sys_unlink((char __force_user *)path);
65948 }
65949 }
65950
65951@@ -315,7 +315,7 @@ static int __init do_name(void)
65952 int openflags = O_WRONLY|O_CREAT;
65953 if (ml != 1)
65954 openflags |= O_TRUNC;
65955- wfd = sys_open(collected, openflags, mode);
65956+ wfd = sys_open((char __force_user *)collected, openflags, mode);
65957
65958 if (wfd >= 0) {
65959 sys_fchown(wfd, uid, gid);
65960@@ -327,17 +327,17 @@ static int __init do_name(void)
65961 }
65962 }
65963 } else if (S_ISDIR(mode)) {
65964- sys_mkdir(collected, mode);
65965- sys_chown(collected, uid, gid);
65966- sys_chmod(collected, mode);
65967+ sys_mkdir((char __force_user *)collected, mode);
65968+ sys_chown((char __force_user *)collected, uid, gid);
65969+ sys_chmod((char __force_user *)collected, mode);
65970 dir_add(collected, mtime);
65971 } else if (S_ISBLK(mode) || S_ISCHR(mode) ||
65972 S_ISFIFO(mode) || S_ISSOCK(mode)) {
65973 if (maybe_link() == 0) {
65974- sys_mknod(collected, mode, rdev);
65975- sys_chown(collected, uid, gid);
65976- sys_chmod(collected, mode);
65977- do_utime(collected, mtime);
65978+ sys_mknod((char __force_user *)collected, mode, rdev);
65979+ sys_chown((char __force_user *)collected, uid, gid);
65980+ sys_chmod((char __force_user *)collected, mode);
65981+ do_utime((char __force_user *)collected, mtime);
65982 }
65983 }
65984 return 0;
65985@@ -346,15 +346,15 @@ static int __init do_name(void)
65986 static int __init do_copy(void)
65987 {
65988 if (count >= body_len) {
65989- sys_write(wfd, victim, body_len);
65990+ sys_write(wfd, (char __force_user *)victim, body_len);
65991 sys_close(wfd);
65992- do_utime(vcollected, mtime);
65993+ do_utime((char __force_user *)vcollected, mtime);
65994 kfree(vcollected);
65995 eat(body_len);
65996 state = SkipIt;
65997 return 0;
65998 } else {
65999- sys_write(wfd, victim, count);
66000+ sys_write(wfd, (char __force_user *)victim, count);
66001 body_len -= count;
66002 eat(count);
66003 return 1;
66004@@ -365,9 +365,9 @@ static int __init do_symlink(void)
66005 {
66006 collected[N_ALIGN(name_len) + body_len] = '\0';
66007 clean_path(collected, 0);
66008- sys_symlink(collected + N_ALIGN(name_len), collected);
66009- sys_lchown(collected, uid, gid);
66010- do_utime(collected, mtime);
66011+ sys_symlink((char __force_user *)collected + N_ALIGN(name_len), (char __force_user *)collected);
66012+ sys_lchown((char __force_user *)collected, uid, gid);
66013+ do_utime((char __force_user *)collected, mtime);
66014 state = SkipIt;
66015 next_state = Reset;
66016 return 0;
66017diff --git a/init/main.c b/init/main.c
66018index b286730..9ff6135 100644
66019--- a/init/main.c
66020+++ b/init/main.c
66021@@ -96,6 +96,8 @@ static inline void mark_rodata_ro(void) { }
66022 extern void tc_init(void);
66023 #endif
66024
66025+extern void grsecurity_init(void);
66026+
66027 /*
66028 * Debug helper: via this flag we know that we are in 'early bootup code'
66029 * where only the boot processor is running with IRQ disabled. This means
66030@@ -149,6 +151,61 @@ static int __init set_reset_devices(char *str)
66031
66032 __setup("reset_devices", set_reset_devices);
66033
66034+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
66035+int grsec_proc_gid = CONFIG_GRKERNSEC_PROC_GID;
66036+static int __init setup_grsec_proc_gid(char *str)
66037+{
66038+ grsec_proc_gid = (int)simple_strtol(str, NULL, 0);
66039+ return 1;
66040+}
66041+__setup("grsec_proc_gid=", setup_grsec_proc_gid);
66042+#endif
66043+
66044+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
66045+extern char pax_enter_kernel_user[];
66046+extern char pax_exit_kernel_user[];
66047+extern pgdval_t clone_pgd_mask;
66048+#endif
66049+
66050+#if defined(CONFIG_X86) && defined(CONFIG_PAX_MEMORY_UDEREF)
66051+static int __init setup_pax_nouderef(char *str)
66052+{
66053+#ifdef CONFIG_X86_32
66054+ unsigned int cpu;
66055+ struct desc_struct *gdt;
66056+
66057+ for (cpu = 0; cpu < nr_cpu_ids; cpu++) {
66058+ gdt = get_cpu_gdt_table(cpu);
66059+ gdt[GDT_ENTRY_KERNEL_DS].type = 3;
66060+ gdt[GDT_ENTRY_KERNEL_DS].limit = 0xf;
66061+ gdt[GDT_ENTRY_DEFAULT_USER_CS].limit = 0xf;
66062+ gdt[GDT_ENTRY_DEFAULT_USER_DS].limit = 0xf;
66063+ }
66064+ loadsegment(ds, __KERNEL_DS);
66065+ loadsegment(es, __KERNEL_DS);
66066+ loadsegment(ss, __KERNEL_DS);
66067+#else
66068+ memcpy(pax_enter_kernel_user, (unsigned char []){0xc3}, 1);
66069+ memcpy(pax_exit_kernel_user, (unsigned char []){0xc3}, 1);
66070+ clone_pgd_mask = ~(pgdval_t)0UL;
66071+#endif
66072+
66073+ return 0;
66074+}
66075+early_param("pax_nouderef", setup_pax_nouderef);
66076+#endif
66077+
66078+#ifdef CONFIG_PAX_SOFTMODE
66079+int pax_softmode;
66080+
66081+static int __init setup_pax_softmode(char *str)
66082+{
66083+ get_option(&str, &pax_softmode);
66084+ return 1;
66085+}
66086+__setup("pax_softmode=", setup_pax_softmode);
66087+#endif
66088+
66089 static const char * argv_init[MAX_INIT_ARGS+2] = { "init", NULL, };
66090 const char * envp_init[MAX_INIT_ENVS+2] = { "HOME=/", "TERM=linux", NULL, };
66091 static const char *panic_later, *panic_param;
66092@@ -675,6 +732,7 @@ int __init_or_module do_one_initcall(initcall_t fn)
66093 {
66094 int count = preempt_count();
66095 int ret;
66096+ const char *msg1 = "", *msg2 = "";
66097
66098 if (initcall_debug)
66099 ret = do_one_initcall_debug(fn);
66100@@ -687,15 +745,15 @@ int __init_or_module do_one_initcall(initcall_t fn)
66101 sprintf(msgbuf, "error code %d ", ret);
66102
66103 if (preempt_count() != count) {
66104- strlcat(msgbuf, "preemption imbalance ", sizeof(msgbuf));
66105+ msg1 = " preemption imbalance";
66106 preempt_count() = count;
66107 }
66108 if (irqs_disabled()) {
66109- strlcat(msgbuf, "disabled interrupts ", sizeof(msgbuf));
66110+ msg2 = " disabled interrupts";
66111 local_irq_enable();
66112 }
66113- if (msgbuf[0]) {
66114- printk("initcall %pF returned with %s\n", fn, msgbuf);
66115+ if (msgbuf[0] || *msg1 || *msg2) {
66116+ printk("initcall %pF returned with %s%s%s\n", fn, msgbuf, msg1, msg2);
66117 }
66118
66119 return ret;
66120@@ -749,8 +807,14 @@ static void __init do_initcall_level(int level)
66121 level, level,
66122 &repair_env_string);
66123
66124- for (fn = initcall_levels[level]; fn < initcall_levels[level+1]; fn++)
66125+ for (fn = initcall_levels[level]; fn < initcall_levels[level+1]; fn++) {
66126 do_one_initcall(*fn);
66127+
66128+#ifdef CONFIG_PAX_LATENT_ENTROPY
66129+ transfer_latent_entropy();
66130+#endif
66131+
66132+ }
66133 }
66134
66135 static void __init do_initcalls(void)
66136@@ -784,8 +848,14 @@ static void __init do_pre_smp_initcalls(void)
66137 {
66138 initcall_t *fn;
66139
66140- for (fn = __initcall_start; fn < __initcall0_start; fn++)
66141+ for (fn = __initcall_start; fn < __initcall0_start; fn++) {
66142 do_one_initcall(*fn);
66143+
66144+#ifdef CONFIG_PAX_LATENT_ENTROPY
66145+ transfer_latent_entropy();
66146+#endif
66147+
66148+ }
66149 }
66150
66151 static void run_init_process(const char *init_filename)
66152@@ -867,7 +937,7 @@ static int __init kernel_init(void * unused)
66153 do_basic_setup();
66154
66155 /* Open the /dev/console on the rootfs, this should never fail */
66156- if (sys_open((const char __user *) "/dev/console", O_RDWR, 0) < 0)
66157+ if (sys_open((const char __force_user *) "/dev/console", O_RDWR, 0) < 0)
66158 printk(KERN_WARNING "Warning: unable to open an initial console.\n");
66159
66160 (void) sys_dup(0);
66161@@ -880,11 +950,13 @@ static int __init kernel_init(void * unused)
66162 if (!ramdisk_execute_command)
66163 ramdisk_execute_command = "/init";
66164
66165- if (sys_access((const char __user *) ramdisk_execute_command, 0) != 0) {
66166+ if (sys_access((const char __force_user *) ramdisk_execute_command, 0) != 0) {
66167 ramdisk_execute_command = NULL;
66168 prepare_namespace();
66169 }
66170
66171+ grsecurity_init();
66172+
66173 /*
66174 * Ok, we have completed the initial bootup, and
66175 * we're essentially up and running. Get rid of the
66176diff --git a/ipc/mqueue.c b/ipc/mqueue.c
66177index 9a08acc..e65ebe7 100644
66178--- a/ipc/mqueue.c
66179+++ b/ipc/mqueue.c
66180@@ -279,6 +279,7 @@ static struct inode *mqueue_get_inode(struct super_block *sb,
66181 mq_bytes = mq_treesize + (info->attr.mq_maxmsg *
66182 info->attr.mq_msgsize);
66183
66184+ gr_learn_resource(current, RLIMIT_MSGQUEUE, u->mq_bytes + mq_bytes, 1);
66185 spin_lock(&mq_lock);
66186 if (u->mq_bytes + mq_bytes < u->mq_bytes ||
66187 u->mq_bytes + mq_bytes > rlimit(RLIMIT_MSGQUEUE)) {
66188diff --git a/ipc/msg.c b/ipc/msg.c
66189index 7385de2..a8180e08 100644
66190--- a/ipc/msg.c
66191+++ b/ipc/msg.c
66192@@ -309,18 +309,19 @@ static inline int msg_security(struct kern_ipc_perm *ipcp, int msgflg)
66193 return security_msg_queue_associate(msq, msgflg);
66194 }
66195
66196+static struct ipc_ops msg_ops = {
66197+ .getnew = newque,
66198+ .associate = msg_security,
66199+ .more_checks = NULL
66200+};
66201+
66202 SYSCALL_DEFINE2(msgget, key_t, key, int, msgflg)
66203 {
66204 struct ipc_namespace *ns;
66205- struct ipc_ops msg_ops;
66206 struct ipc_params msg_params;
66207
66208 ns = current->nsproxy->ipc_ns;
66209
66210- msg_ops.getnew = newque;
66211- msg_ops.associate = msg_security;
66212- msg_ops.more_checks = NULL;
66213-
66214 msg_params.key = key;
66215 msg_params.flg = msgflg;
66216
66217diff --git a/ipc/sem.c b/ipc/sem.c
66218index 5215a81..cfc0cac 100644
66219--- a/ipc/sem.c
66220+++ b/ipc/sem.c
66221@@ -364,10 +364,15 @@ static inline int sem_more_checks(struct kern_ipc_perm *ipcp,
66222 return 0;
66223 }
66224
66225+static struct ipc_ops sem_ops = {
66226+ .getnew = newary,
66227+ .associate = sem_security,
66228+ .more_checks = sem_more_checks
66229+};
66230+
66231 SYSCALL_DEFINE3(semget, key_t, key, int, nsems, int, semflg)
66232 {
66233 struct ipc_namespace *ns;
66234- struct ipc_ops sem_ops;
66235 struct ipc_params sem_params;
66236
66237 ns = current->nsproxy->ipc_ns;
66238@@ -375,10 +380,6 @@ SYSCALL_DEFINE3(semget, key_t, key, int, nsems, int, semflg)
66239 if (nsems < 0 || nsems > ns->sc_semmsl)
66240 return -EINVAL;
66241
66242- sem_ops.getnew = newary;
66243- sem_ops.associate = sem_security;
66244- sem_ops.more_checks = sem_more_checks;
66245-
66246 sem_params.key = key;
66247 sem_params.flg = semflg;
66248 sem_params.u.nsems = nsems;
66249diff --git a/ipc/shm.c b/ipc/shm.c
66250index 00faa05..7040960 100644
66251--- a/ipc/shm.c
66252+++ b/ipc/shm.c
66253@@ -69,6 +69,14 @@ static void shm_destroy (struct ipc_namespace *ns, struct shmid_kernel *shp);
66254 static int sysvipc_shm_proc_show(struct seq_file *s, void *it);
66255 #endif
66256
66257+#ifdef CONFIG_GRKERNSEC
66258+extern int gr_handle_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
66259+ const time_t shm_createtime, const uid_t cuid,
66260+ const int shmid);
66261+extern int gr_chroot_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
66262+ const time_t shm_createtime);
66263+#endif
66264+
66265 void shm_init_ns(struct ipc_namespace *ns)
66266 {
66267 ns->shm_ctlmax = SHMMAX;
66268@@ -520,6 +528,14 @@ static int newseg(struct ipc_namespace *ns, struct ipc_params *params)
66269 shp->shm_lprid = 0;
66270 shp->shm_atim = shp->shm_dtim = 0;
66271 shp->shm_ctim = get_seconds();
66272+#ifdef CONFIG_GRKERNSEC
66273+ {
66274+ struct timespec timeval;
66275+ do_posix_clock_monotonic_gettime(&timeval);
66276+
66277+ shp->shm_createtime = timeval.tv_sec;
66278+ }
66279+#endif
66280 shp->shm_segsz = size;
66281 shp->shm_nattch = 0;
66282 shp->shm_file = file;
66283@@ -571,18 +587,19 @@ static inline int shm_more_checks(struct kern_ipc_perm *ipcp,
66284 return 0;
66285 }
66286
66287+static struct ipc_ops shm_ops = {
66288+ .getnew = newseg,
66289+ .associate = shm_security,
66290+ .more_checks = shm_more_checks
66291+};
66292+
66293 SYSCALL_DEFINE3(shmget, key_t, key, size_t, size, int, shmflg)
66294 {
66295 struct ipc_namespace *ns;
66296- struct ipc_ops shm_ops;
66297 struct ipc_params shm_params;
66298
66299 ns = current->nsproxy->ipc_ns;
66300
66301- shm_ops.getnew = newseg;
66302- shm_ops.associate = shm_security;
66303- shm_ops.more_checks = shm_more_checks;
66304-
66305 shm_params.key = key;
66306 shm_params.flg = shmflg;
66307 shm_params.u.size = size;
66308@@ -1001,6 +1018,12 @@ long do_shmat(int shmid, char __user *shmaddr, int shmflg, ulong *raddr,
66309 f_mode = FMODE_READ | FMODE_WRITE;
66310 }
66311 if (shmflg & SHM_EXEC) {
66312+
66313+#ifdef CONFIG_PAX_MPROTECT
66314+ if (current->mm->pax_flags & MF_PAX_MPROTECT)
66315+ goto out;
66316+#endif
66317+
66318 prot |= PROT_EXEC;
66319 acc_mode |= S_IXUGO;
66320 }
66321@@ -1024,9 +1047,21 @@ long do_shmat(int shmid, char __user *shmaddr, int shmflg, ulong *raddr,
66322 if (err)
66323 goto out_unlock;
66324
66325+#ifdef CONFIG_GRKERNSEC
66326+ if (!gr_handle_shmat(shp->shm_cprid, shp->shm_lapid, shp->shm_createtime,
66327+ shp->shm_perm.cuid, shmid) ||
66328+ !gr_chroot_shmat(shp->shm_cprid, shp->shm_lapid, shp->shm_createtime)) {
66329+ err = -EACCES;
66330+ goto out_unlock;
66331+ }
66332+#endif
66333+
66334 path = shp->shm_file->f_path;
66335 path_get(&path);
66336 shp->shm_nattch++;
66337+#ifdef CONFIG_GRKERNSEC
66338+ shp->shm_lapid = current->pid;
66339+#endif
66340 size = i_size_read(path.dentry->d_inode);
66341 shm_unlock(shp);
66342
66343diff --git a/kernel/acct.c b/kernel/acct.c
66344index 02e6167..54824f7 100644
66345--- a/kernel/acct.c
66346+++ b/kernel/acct.c
66347@@ -550,7 +550,7 @@ static void do_acct_process(struct bsd_acct_struct *acct,
66348 */
66349 flim = current->signal->rlim[RLIMIT_FSIZE].rlim_cur;
66350 current->signal->rlim[RLIMIT_FSIZE].rlim_cur = RLIM_INFINITY;
66351- file->f_op->write(file, (char *)&ac,
66352+ file->f_op->write(file, (char __force_user *)&ac,
66353 sizeof(acct_t), &file->f_pos);
66354 current->signal->rlim[RLIMIT_FSIZE].rlim_cur = flim;
66355 set_fs(fs);
66356diff --git a/kernel/audit.c b/kernel/audit.c
66357index a8c84be..8bd034c 100644
66358--- a/kernel/audit.c
66359+++ b/kernel/audit.c
66360@@ -115,7 +115,7 @@ u32 audit_sig_sid = 0;
66361 3) suppressed due to audit_rate_limit
66362 4) suppressed due to audit_backlog_limit
66363 */
66364-static atomic_t audit_lost = ATOMIC_INIT(0);
66365+static atomic_unchecked_t audit_lost = ATOMIC_INIT(0);
66366
66367 /* The netlink socket. */
66368 static struct sock *audit_sock;
66369@@ -237,7 +237,7 @@ void audit_log_lost(const char *message)
66370 unsigned long now;
66371 int print;
66372
66373- atomic_inc(&audit_lost);
66374+ atomic_inc_unchecked(&audit_lost);
66375
66376 print = (audit_failure == AUDIT_FAIL_PANIC || !audit_rate_limit);
66377
66378@@ -256,7 +256,7 @@ void audit_log_lost(const char *message)
66379 printk(KERN_WARNING
66380 "audit: audit_lost=%d audit_rate_limit=%d "
66381 "audit_backlog_limit=%d\n",
66382- atomic_read(&audit_lost),
66383+ atomic_read_unchecked(&audit_lost),
66384 audit_rate_limit,
66385 audit_backlog_limit);
66386 audit_panic(message);
66387@@ -690,7 +690,7 @@ static int audit_receive_msg(struct sk_buff *skb, struct nlmsghdr *nlh)
66388 status_set.pid = audit_pid;
66389 status_set.rate_limit = audit_rate_limit;
66390 status_set.backlog_limit = audit_backlog_limit;
66391- status_set.lost = atomic_read(&audit_lost);
66392+ status_set.lost = atomic_read_unchecked(&audit_lost);
66393 status_set.backlog = skb_queue_len(&audit_skb_queue);
66394 audit_send_reply(NETLINK_CB(skb).pid, seq, AUDIT_GET, 0, 0,
66395 &status_set, sizeof(status_set));
66396diff --git a/kernel/auditsc.c b/kernel/auditsc.c
66397index 4b96415..d8c16ee 100644
66398--- a/kernel/auditsc.c
66399+++ b/kernel/auditsc.c
66400@@ -2289,7 +2289,7 @@ int auditsc_get_stamp(struct audit_context *ctx,
66401 }
66402
66403 /* global counter which is incremented every time something logs in */
66404-static atomic_t session_id = ATOMIC_INIT(0);
66405+static atomic_unchecked_t session_id = ATOMIC_INIT(0);
66406
66407 /**
66408 * audit_set_loginuid - set current task's audit_context loginuid
66409@@ -2313,7 +2313,7 @@ int audit_set_loginuid(uid_t loginuid)
66410 return -EPERM;
66411 #endif /* CONFIG_AUDIT_LOGINUID_IMMUTABLE */
66412
66413- sessionid = atomic_inc_return(&session_id);
66414+ sessionid = atomic_inc_return_unchecked(&session_id);
66415 if (context && context->in_syscall) {
66416 struct audit_buffer *ab;
66417
66418diff --git a/kernel/capability.c b/kernel/capability.c
66419index 493d972..ea17248 100644
66420--- a/kernel/capability.c
66421+++ b/kernel/capability.c
66422@@ -202,6 +202,9 @@ SYSCALL_DEFINE2(capget, cap_user_header_t, header, cap_user_data_t, dataptr)
66423 * before modification is attempted and the application
66424 * fails.
66425 */
66426+ if (tocopy > ARRAY_SIZE(kdata))
66427+ return -EFAULT;
66428+
66429 if (copy_to_user(dataptr, kdata, tocopy
66430 * sizeof(struct __user_cap_data_struct))) {
66431 return -EFAULT;
66432@@ -303,10 +306,11 @@ bool has_ns_capability(struct task_struct *t,
66433 int ret;
66434
66435 rcu_read_lock();
66436- ret = security_capable(__task_cred(t), ns, cap);
66437+ ret = security_capable(__task_cred(t), ns, cap) == 0 &&
66438+ gr_task_is_capable(t, __task_cred(t), cap);
66439 rcu_read_unlock();
66440
66441- return (ret == 0);
66442+ return ret;
66443 }
66444
66445 /**
66446@@ -343,10 +347,10 @@ bool has_ns_capability_noaudit(struct task_struct *t,
66447 int ret;
66448
66449 rcu_read_lock();
66450- ret = security_capable_noaudit(__task_cred(t), ns, cap);
66451+ ret = security_capable_noaudit(__task_cred(t), ns, cap) == 0 && gr_task_is_capable_nolog(t, cap);
66452 rcu_read_unlock();
66453
66454- return (ret == 0);
66455+ return ret;
66456 }
66457
66458 /**
66459@@ -384,7 +388,7 @@ bool ns_capable(struct user_namespace *ns, int cap)
66460 BUG();
66461 }
66462
66463- if (security_capable(current_cred(), ns, cap) == 0) {
66464+ if (security_capable(current_cred(), ns, cap) == 0 && gr_is_capable(cap)) {
66465 current->flags |= PF_SUPERPRIV;
66466 return true;
66467 }
66468@@ -392,6 +396,21 @@ bool ns_capable(struct user_namespace *ns, int cap)
66469 }
66470 EXPORT_SYMBOL(ns_capable);
66471
66472+bool ns_capable_nolog(struct user_namespace *ns, int cap)
66473+{
66474+ if (unlikely(!cap_valid(cap))) {
66475+ printk(KERN_CRIT "capable() called with invalid cap=%u\n", cap);
66476+ BUG();
66477+ }
66478+
66479+ if (security_capable(current_cred(), ns, cap) == 0 && gr_is_capable_nolog(cap)) {
66480+ current->flags |= PF_SUPERPRIV;
66481+ return true;
66482+ }
66483+ return false;
66484+}
66485+EXPORT_SYMBOL(ns_capable_nolog);
66486+
66487 /**
66488 * capable - Determine if the current task has a superior capability in effect
66489 * @cap: The capability to be tested for
66490@@ -408,6 +427,12 @@ bool capable(int cap)
66491 }
66492 EXPORT_SYMBOL(capable);
66493
66494+bool capable_nolog(int cap)
66495+{
66496+ return ns_capable_nolog(&init_user_ns, cap);
66497+}
66498+EXPORT_SYMBOL(capable_nolog);
66499+
66500 /**
66501 * nsown_capable - Check superior capability to one's own user_ns
66502 * @cap: The capability in question
66503@@ -440,3 +465,10 @@ bool inode_capable(const struct inode *inode, int cap)
66504
66505 return ns_capable(ns, cap) && kuid_has_mapping(ns, inode->i_uid);
66506 }
66507+
66508+bool inode_capable_nolog(const struct inode *inode, int cap)
66509+{
66510+ struct user_namespace *ns = current_user_ns();
66511+
66512+ return ns_capable_nolog(ns, cap) && kuid_has_mapping(ns, inode->i_uid);
66513+}
66514diff --git a/kernel/cgroup.c b/kernel/cgroup.c
66515index ff2bce5..a41e8f9 100644
66516--- a/kernel/cgroup.c
66517+++ b/kernel/cgroup.c
66518@@ -5390,7 +5390,7 @@ static int cgroup_css_links_read(struct cgroup *cont,
66519 struct css_set *cg = link->cg;
66520 struct task_struct *task;
66521 int count = 0;
66522- seq_printf(seq, "css_set %p\n", cg);
66523+ seq_printf(seq, "css_set %pK\n", cg);
66524 list_for_each_entry(task, &cg->tasks, cg_list) {
66525 if (count++ > MAX_TASKS_SHOWN_PER_CSS) {
66526 seq_puts(seq, " ...\n");
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/kcmp.c b/kernel/kcmp.c
67659index 30b7b22..c726387 100644
67660--- a/kernel/kcmp.c
67661+++ b/kernel/kcmp.c
67662@@ -98,6 +98,10 @@ SYSCALL_DEFINE5(kcmp, pid_t, pid1, pid_t, pid2, int, type,
67663 struct task_struct *task1, *task2;
67664 int ret;
67665
67666+#ifdef CONFIG_GRKERNSEC
67667+ return -ENOSYS;
67668+#endif
67669+
67670 rcu_read_lock();
67671
67672 /*
67673diff --git a/kernel/kexec.c b/kernel/kexec.c
67674index 0668d58..591b6fc 100644
67675--- a/kernel/kexec.c
67676+++ b/kernel/kexec.c
67677@@ -1046,7 +1046,8 @@ asmlinkage long compat_sys_kexec_load(unsigned long entry,
67678 unsigned long flags)
67679 {
67680 struct compat_kexec_segment in;
67681- struct kexec_segment out, __user *ksegments;
67682+ struct kexec_segment out;
67683+ struct kexec_segment __user *ksegments;
67684 unsigned long i, result;
67685
67686 /* Don't allow clients that don't understand the native
67687diff --git a/kernel/kmod.c b/kernel/kmod.c
67688index 6f99aea..eb6e3a0 100644
67689--- a/kernel/kmod.c
67690+++ b/kernel/kmod.c
67691@@ -73,7 +73,7 @@ static void free_modprobe_argv(struct subprocess_info *info)
67692 kfree(info->argv);
67693 }
67694
67695-static int call_modprobe(char *module_name, int wait)
67696+static int call_modprobe(char *module_name, char *module_param, int wait)
67697 {
67698 static char *envp[] = {
67699 "HOME=/",
67700@@ -82,7 +82,7 @@ static int call_modprobe(char *module_name, int wait)
67701 NULL
67702 };
67703
67704- char **argv = kmalloc(sizeof(char *[5]), GFP_KERNEL);
67705+ char **argv = kmalloc(sizeof(char *[6]), GFP_KERNEL);
67706 if (!argv)
67707 goto out;
67708
67709@@ -94,7 +94,8 @@ static int call_modprobe(char *module_name, int wait)
67710 argv[1] = "-q";
67711 argv[2] = "--";
67712 argv[3] = module_name; /* check free_modprobe_argv() */
67713- argv[4] = NULL;
67714+ argv[4] = module_param;
67715+ argv[5] = NULL;
67716
67717 return call_usermodehelper_fns(modprobe_path, argv, envp,
67718 wait | UMH_KILLABLE, NULL, free_modprobe_argv, NULL);
67719@@ -119,9 +120,8 @@ out:
67720 * If module auto-loading support is disabled then this function
67721 * becomes a no-operation.
67722 */
67723-int __request_module(bool wait, const char *fmt, ...)
67724+static int ____request_module(bool wait, char *module_param, const char *fmt, va_list ap)
67725 {
67726- va_list args;
67727 char module_name[MODULE_NAME_LEN];
67728 unsigned int max_modprobes;
67729 int ret;
67730@@ -129,9 +129,7 @@ int __request_module(bool wait, const char *fmt, ...)
67731 #define MAX_KMOD_CONCURRENT 50 /* Completely arbitrary value - KAO */
67732 static int kmod_loop_msg;
67733
67734- va_start(args, fmt);
67735- ret = vsnprintf(module_name, MODULE_NAME_LEN, fmt, args);
67736- va_end(args);
67737+ ret = vsnprintf(module_name, MODULE_NAME_LEN, fmt, ap);
67738 if (ret >= MODULE_NAME_LEN)
67739 return -ENAMETOOLONG;
67740
67741@@ -139,6 +137,20 @@ int __request_module(bool wait, const char *fmt, ...)
67742 if (ret)
67743 return ret;
67744
67745+#ifdef CONFIG_GRKERNSEC_MODHARDEN
67746+ if (!current_uid()) {
67747+ /* hack to workaround consolekit/udisks stupidity */
67748+ read_lock(&tasklist_lock);
67749+ if (!strcmp(current->comm, "mount") &&
67750+ current->real_parent && !strncmp(current->real_parent->comm, "udisk", 5)) {
67751+ read_unlock(&tasklist_lock);
67752+ printk(KERN_ALERT "grsec: denied attempt to auto-load fs module %.64s by udisks\n", module_name);
67753+ return -EPERM;
67754+ }
67755+ read_unlock(&tasklist_lock);
67756+ }
67757+#endif
67758+
67759 /* If modprobe needs a service that is in a module, we get a recursive
67760 * loop. Limit the number of running kmod threads to max_threads/2 or
67761 * MAX_KMOD_CONCURRENT, whichever is the smaller. A cleaner method
67762@@ -167,11 +179,52 @@ int __request_module(bool wait, const char *fmt, ...)
67763
67764 trace_module_request(module_name, wait, _RET_IP_);
67765
67766- ret = call_modprobe(module_name, wait ? UMH_WAIT_PROC : UMH_WAIT_EXEC);
67767+ ret = call_modprobe(module_name, module_param, wait ? UMH_WAIT_PROC : UMH_WAIT_EXEC);
67768
67769 atomic_dec(&kmod_concurrent);
67770 return ret;
67771 }
67772+
67773+int ___request_module(bool wait, char *module_param, const char *fmt, ...)
67774+{
67775+ va_list args;
67776+ int ret;
67777+
67778+ va_start(args, fmt);
67779+ ret = ____request_module(wait, module_param, fmt, args);
67780+ va_end(args);
67781+
67782+ return ret;
67783+}
67784+
67785+int __request_module(bool wait, const char *fmt, ...)
67786+{
67787+ va_list args;
67788+ int ret;
67789+
67790+#ifdef CONFIG_GRKERNSEC_MODHARDEN
67791+ if (current_uid()) {
67792+ char module_param[MODULE_NAME_LEN];
67793+
67794+ memset(module_param, 0, sizeof(module_param));
67795+
67796+ snprintf(module_param, sizeof(module_param) - 1, "grsec_modharden_normal%u_", current_uid());
67797+
67798+ va_start(args, fmt);
67799+ ret = ____request_module(wait, module_param, fmt, args);
67800+ va_end(args);
67801+
67802+ return ret;
67803+ }
67804+#endif
67805+
67806+ va_start(args, fmt);
67807+ ret = ____request_module(wait, NULL, fmt, args);
67808+ va_end(args);
67809+
67810+ return ret;
67811+}
67812+
67813 EXPORT_SYMBOL(__request_module);
67814 #endif /* CONFIG_MODULES */
67815
67816@@ -280,7 +333,7 @@ static int wait_for_helper(void *data)
67817 *
67818 * Thus the __user pointer cast is valid here.
67819 */
67820- sys_wait4(pid, (int __user *)&ret, 0, NULL);
67821+ sys_wait4(pid, (int __force_user *)&ret, 0, NULL);
67822
67823 /*
67824 * If ret is 0, either ____call_usermodehelper failed and the
67825diff --git a/kernel/kprobes.c b/kernel/kprobes.c
67826index c62b854..6fc810d 100644
67827--- a/kernel/kprobes.c
67828+++ b/kernel/kprobes.c
67829@@ -185,7 +185,7 @@ static kprobe_opcode_t __kprobes *__get_insn_slot(struct kprobe_insn_cache *c)
67830 * kernel image and loaded module images reside. This is required
67831 * so x86_64 can correctly handle the %rip-relative fixups.
67832 */
67833- kip->insns = module_alloc(PAGE_SIZE);
67834+ kip->insns = module_alloc_exec(PAGE_SIZE);
67835 if (!kip->insns) {
67836 kfree(kip);
67837 return NULL;
67838@@ -225,7 +225,7 @@ static int __kprobes collect_one_slot(struct kprobe_insn_page *kip, int idx)
67839 */
67840 if (!list_is_singular(&kip->list)) {
67841 list_del(&kip->list);
67842- module_free(NULL, kip->insns);
67843+ module_free_exec(NULL, kip->insns);
67844 kfree(kip);
67845 }
67846 return 1;
67847@@ -1955,7 +1955,7 @@ static int __init init_kprobes(void)
67848 {
67849 int i, err = 0;
67850 unsigned long offset = 0, size = 0;
67851- char *modname, namebuf[128];
67852+ char *modname, namebuf[KSYM_NAME_LEN];
67853 const char *symbol_name;
67854 void *addr;
67855 struct kprobe_blackpoint *kb;
67856@@ -2040,11 +2040,11 @@ static void __kprobes report_probe(struct seq_file *pi, struct kprobe *p,
67857 kprobe_type = "k";
67858
67859 if (sym)
67860- seq_printf(pi, "%p %s %s+0x%x %s ",
67861+ seq_printf(pi, "%pK %s %s+0x%x %s ",
67862 p->addr, kprobe_type, sym, offset,
67863 (modname ? modname : " "));
67864 else
67865- seq_printf(pi, "%p %s %p ",
67866+ seq_printf(pi, "%pK %s %pK ",
67867 p->addr, kprobe_type, p->addr);
67868
67869 if (!pp)
67870@@ -2081,7 +2081,7 @@ static int __kprobes show_kprobe_addr(struct seq_file *pi, void *v)
67871 const char *sym = NULL;
67872 unsigned int i = *(loff_t *) v;
67873 unsigned long offset = 0;
67874- char *modname, namebuf[128];
67875+ char *modname, namebuf[KSYM_NAME_LEN];
67876
67877 head = &kprobe_table[i];
67878 preempt_disable();
67879diff --git a/kernel/ksysfs.c b/kernel/ksysfs.c
67880index 4e316e1..5501eef 100644
67881--- a/kernel/ksysfs.c
67882+++ b/kernel/ksysfs.c
67883@@ -47,6 +47,8 @@ static ssize_t uevent_helper_store(struct kobject *kobj,
67884 {
67885 if (count+1 > UEVENT_HELPER_PATH_LEN)
67886 return -ENOENT;
67887+ if (!capable(CAP_SYS_ADMIN))
67888+ return -EPERM;
67889 memcpy(uevent_helper, buf, count);
67890 uevent_helper[count] = '\0';
67891 if (count && uevent_helper[count-1] == '\n')
67892diff --git a/kernel/lockdep.c b/kernel/lockdep.c
67893index ea9ee45..67ebc8f 100644
67894--- a/kernel/lockdep.c
67895+++ b/kernel/lockdep.c
67896@@ -590,6 +590,10 @@ static int static_obj(void *obj)
67897 end = (unsigned long) &_end,
67898 addr = (unsigned long) obj;
67899
67900+#ifdef CONFIG_PAX_KERNEXEC
67901+ start = ktla_ktva(start);
67902+#endif
67903+
67904 /*
67905 * static variable?
67906 */
67907@@ -730,6 +734,7 @@ register_lock_class(struct lockdep_map *lock, unsigned int subclass, int force)
67908 if (!static_obj(lock->key)) {
67909 debug_locks_off();
67910 printk("INFO: trying to register non-static key.\n");
67911+ printk("lock:%pS key:%pS.\n", lock, lock->key);
67912 printk("the code is fine but needs lockdep annotation.\n");
67913 printk("turning off the locking correctness validator.\n");
67914 dump_stack();
67915@@ -3042,7 +3047,7 @@ static int __lock_acquire(struct lockdep_map *lock, unsigned int subclass,
67916 if (!class)
67917 return 0;
67918 }
67919- atomic_inc((atomic_t *)&class->ops);
67920+ atomic_inc_unchecked((atomic_unchecked_t *)&class->ops);
67921 if (very_verbose(class)) {
67922 printk("\nacquire class [%p] %s", class->key, class->name);
67923 if (class->name_version > 1)
67924diff --git a/kernel/lockdep_proc.c b/kernel/lockdep_proc.c
67925index 91c32a0..7b88d63 100644
67926--- a/kernel/lockdep_proc.c
67927+++ b/kernel/lockdep_proc.c
67928@@ -39,7 +39,7 @@ static void l_stop(struct seq_file *m, void *v)
67929
67930 static void print_name(struct seq_file *m, struct lock_class *class)
67931 {
67932- char str[128];
67933+ char str[KSYM_NAME_LEN];
67934 const char *name = class->name;
67935
67936 if (!name) {
67937@@ -65,7 +65,7 @@ static int l_show(struct seq_file *m, void *v)
67938 return 0;
67939 }
67940
67941- seq_printf(m, "%p", class->key);
67942+ seq_printf(m, "%pK", class->key);
67943 #ifdef CONFIG_DEBUG_LOCKDEP
67944 seq_printf(m, " OPS:%8ld", class->ops);
67945 #endif
67946@@ -83,7 +83,7 @@ static int l_show(struct seq_file *m, void *v)
67947
67948 list_for_each_entry(entry, &class->locks_after, entry) {
67949 if (entry->distance == 1) {
67950- seq_printf(m, " -> [%p] ", entry->class->key);
67951+ seq_printf(m, " -> [%pK] ", entry->class->key);
67952 print_name(m, entry->class);
67953 seq_puts(m, "\n");
67954 }
67955@@ -152,7 +152,7 @@ static int lc_show(struct seq_file *m, void *v)
67956 if (!class->key)
67957 continue;
67958
67959- seq_printf(m, "[%p] ", class->key);
67960+ seq_printf(m, "[%pK] ", class->key);
67961 print_name(m, class);
67962 seq_puts(m, "\n");
67963 }
67964@@ -495,7 +495,7 @@ static void seq_stats(struct seq_file *m, struct lock_stat_data *data)
67965 if (!i)
67966 seq_line(m, '-', 40-namelen, namelen);
67967
67968- snprintf(ip, sizeof(ip), "[<%p>]",
67969+ snprintf(ip, sizeof(ip), "[<%pK>]",
67970 (void *)class->contention_point[i]);
67971 seq_printf(m, "%40s %14lu %29s %pS\n",
67972 name, stats->contention_point[i],
67973@@ -510,7 +510,7 @@ static void seq_stats(struct seq_file *m, struct lock_stat_data *data)
67974 if (!i)
67975 seq_line(m, '-', 40-namelen, namelen);
67976
67977- snprintf(ip, sizeof(ip), "[<%p>]",
67978+ snprintf(ip, sizeof(ip), "[<%pK>]",
67979 (void *)class->contending_point[i]);
67980 seq_printf(m, "%40s %14lu %29s %pS\n",
67981 name, stats->contending_point[i],
67982diff --git a/kernel/module.c b/kernel/module.c
67983index 9ad9ee9..de7a157 100644
67984--- a/kernel/module.c
67985+++ b/kernel/module.c
67986@@ -58,6 +58,7 @@
67987 #include <linux/jump_label.h>
67988 #include <linux/pfn.h>
67989 #include <linux/bsearch.h>
67990+#include <linux/grsecurity.h>
67991
67992 #define CREATE_TRACE_POINTS
67993 #include <trace/events/module.h>
67994@@ -114,7 +115,8 @@ static BLOCKING_NOTIFIER_HEAD(module_notify_list);
67995
67996 /* Bounds of module allocation, for speeding __module_address.
67997 * Protected by module_mutex. */
67998-static unsigned long module_addr_min = -1UL, module_addr_max = 0;
67999+static unsigned long module_addr_min_rw = -1UL, module_addr_max_rw = 0;
68000+static unsigned long module_addr_min_rx = -1UL, module_addr_max_rx = 0;
68001
68002 int register_module_notifier(struct notifier_block * nb)
68003 {
68004@@ -278,7 +280,7 @@ bool each_symbol_section(bool (*fn)(const struct symsearch *arr,
68005 return true;
68006
68007 list_for_each_entry_rcu(mod, &modules, list) {
68008- struct symsearch arr[] = {
68009+ struct symsearch modarr[] = {
68010 { mod->syms, mod->syms + mod->num_syms, mod->crcs,
68011 NOT_GPL_ONLY, false },
68012 { mod->gpl_syms, mod->gpl_syms + mod->num_gpl_syms,
68013@@ -300,7 +302,7 @@ bool each_symbol_section(bool (*fn)(const struct symsearch *arr,
68014 #endif
68015 };
68016
68017- if (each_symbol_in_section(arr, ARRAY_SIZE(arr), mod, fn, data))
68018+ if (each_symbol_in_section(modarr, ARRAY_SIZE(modarr), mod, fn, data))
68019 return true;
68020 }
68021 return false;
68022@@ -432,7 +434,7 @@ static inline void __percpu *mod_percpu(struct module *mod)
68023 static int percpu_modalloc(struct module *mod,
68024 unsigned long size, unsigned long align)
68025 {
68026- if (align > PAGE_SIZE) {
68027+ if (align-1 >= PAGE_SIZE) {
68028 printk(KERN_WARNING "%s: per-cpu alignment %li > %li\n",
68029 mod->name, align, PAGE_SIZE);
68030 align = PAGE_SIZE;
68031@@ -1032,7 +1034,7 @@ struct module_attribute module_uevent =
68032 static ssize_t show_coresize(struct module_attribute *mattr,
68033 struct module_kobject *mk, char *buffer)
68034 {
68035- return sprintf(buffer, "%u\n", mk->mod->core_size);
68036+ return sprintf(buffer, "%u\n", mk->mod->core_size_rx + mk->mod->core_size_rw);
68037 }
68038
68039 static struct module_attribute modinfo_coresize =
68040@@ -1041,7 +1043,7 @@ static struct module_attribute modinfo_coresize =
68041 static ssize_t show_initsize(struct module_attribute *mattr,
68042 struct module_kobject *mk, char *buffer)
68043 {
68044- return sprintf(buffer, "%u\n", mk->mod->init_size);
68045+ return sprintf(buffer, "%u\n", mk->mod->init_size_rx + mk->mod->init_size_rw);
68046 }
68047
68048 static struct module_attribute modinfo_initsize =
68049@@ -1255,7 +1257,7 @@ resolve_symbol_wait(struct module *mod,
68050 */
68051 #ifdef CONFIG_SYSFS
68052
68053-#ifdef CONFIG_KALLSYMS
68054+#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
68055 static inline bool sect_empty(const Elf_Shdr *sect)
68056 {
68057 return !(sect->sh_flags & SHF_ALLOC) || sect->sh_size == 0;
68058@@ -1721,21 +1723,21 @@ static void set_section_ro_nx(void *base,
68059
68060 static void unset_module_core_ro_nx(struct module *mod)
68061 {
68062- set_page_attributes(mod->module_core + mod->core_text_size,
68063- mod->module_core + mod->core_size,
68064+ set_page_attributes(mod->module_core_rw,
68065+ mod->module_core_rw + mod->core_size_rw,
68066 set_memory_x);
68067- set_page_attributes(mod->module_core,
68068- mod->module_core + mod->core_ro_size,
68069+ set_page_attributes(mod->module_core_rx,
68070+ mod->module_core_rx + mod->core_size_rx,
68071 set_memory_rw);
68072 }
68073
68074 static void unset_module_init_ro_nx(struct module *mod)
68075 {
68076- set_page_attributes(mod->module_init + mod->init_text_size,
68077- mod->module_init + mod->init_size,
68078+ set_page_attributes(mod->module_init_rw,
68079+ mod->module_init_rw + mod->init_size_rw,
68080 set_memory_x);
68081- set_page_attributes(mod->module_init,
68082- mod->module_init + mod->init_ro_size,
68083+ set_page_attributes(mod->module_init_rx,
68084+ mod->module_init_rx + mod->init_size_rx,
68085 set_memory_rw);
68086 }
68087
68088@@ -1746,14 +1748,14 @@ void set_all_modules_text_rw(void)
68089
68090 mutex_lock(&module_mutex);
68091 list_for_each_entry_rcu(mod, &modules, list) {
68092- if ((mod->module_core) && (mod->core_text_size)) {
68093- set_page_attributes(mod->module_core,
68094- mod->module_core + mod->core_text_size,
68095+ if ((mod->module_core_rx) && (mod->core_size_rx)) {
68096+ set_page_attributes(mod->module_core_rx,
68097+ mod->module_core_rx + mod->core_size_rx,
68098 set_memory_rw);
68099 }
68100- if ((mod->module_init) && (mod->init_text_size)) {
68101- set_page_attributes(mod->module_init,
68102- mod->module_init + mod->init_text_size,
68103+ if ((mod->module_init_rx) && (mod->init_size_rx)) {
68104+ set_page_attributes(mod->module_init_rx,
68105+ mod->module_init_rx + mod->init_size_rx,
68106 set_memory_rw);
68107 }
68108 }
68109@@ -1767,14 +1769,14 @@ void set_all_modules_text_ro(void)
68110
68111 mutex_lock(&module_mutex);
68112 list_for_each_entry_rcu(mod, &modules, list) {
68113- if ((mod->module_core) && (mod->core_text_size)) {
68114- set_page_attributes(mod->module_core,
68115- mod->module_core + mod->core_text_size,
68116+ if ((mod->module_core_rx) && (mod->core_size_rx)) {
68117+ set_page_attributes(mod->module_core_rx,
68118+ mod->module_core_rx + mod->core_size_rx,
68119 set_memory_ro);
68120 }
68121- if ((mod->module_init) && (mod->init_text_size)) {
68122- set_page_attributes(mod->module_init,
68123- mod->module_init + mod->init_text_size,
68124+ if ((mod->module_init_rx) && (mod->init_size_rx)) {
68125+ set_page_attributes(mod->module_init_rx,
68126+ mod->module_init_rx + mod->init_size_rx,
68127 set_memory_ro);
68128 }
68129 }
68130@@ -1820,16 +1822,19 @@ static void free_module(struct module *mod)
68131
68132 /* This may be NULL, but that's OK */
68133 unset_module_init_ro_nx(mod);
68134- module_free(mod, mod->module_init);
68135+ module_free(mod, mod->module_init_rw);
68136+ module_free_exec(mod, mod->module_init_rx);
68137 kfree(mod->args);
68138 percpu_modfree(mod);
68139
68140 /* Free lock-classes: */
68141- lockdep_free_key_range(mod->module_core, mod->core_size);
68142+ lockdep_free_key_range(mod->module_core_rx, mod->core_size_rx);
68143+ lockdep_free_key_range(mod->module_core_rw, mod->core_size_rw);
68144
68145 /* Finally, free the core (containing the module structure) */
68146 unset_module_core_ro_nx(mod);
68147- module_free(mod, mod->module_core);
68148+ module_free_exec(mod, mod->module_core_rx);
68149+ module_free(mod, mod->module_core_rw);
68150
68151 #ifdef CONFIG_MPU
68152 update_protections(current->mm);
68153@@ -1899,9 +1904,31 @@ static int simplify_symbols(struct module *mod, const struct load_info *info)
68154 int ret = 0;
68155 const struct kernel_symbol *ksym;
68156
68157+#ifdef CONFIG_GRKERNSEC_MODHARDEN
68158+ int is_fs_load = 0;
68159+ int register_filesystem_found = 0;
68160+ char *p;
68161+
68162+ p = strstr(mod->args, "grsec_modharden_fs");
68163+ if (p) {
68164+ char *endptr = p + strlen("grsec_modharden_fs");
68165+ /* copy \0 as well */
68166+ memmove(p, endptr, strlen(mod->args) - (unsigned int)(endptr - mod->args) + 1);
68167+ is_fs_load = 1;
68168+ }
68169+#endif
68170+
68171 for (i = 1; i < symsec->sh_size / sizeof(Elf_Sym); i++) {
68172 const char *name = info->strtab + sym[i].st_name;
68173
68174+#ifdef CONFIG_GRKERNSEC_MODHARDEN
68175+ /* it's a real shame this will never get ripped and copied
68176+ upstream! ;(
68177+ */
68178+ if (is_fs_load && !strcmp(name, "register_filesystem"))
68179+ register_filesystem_found = 1;
68180+#endif
68181+
68182 switch (sym[i].st_shndx) {
68183 case SHN_COMMON:
68184 /* We compiled with -fno-common. These are not
68185@@ -1922,7 +1949,9 @@ static int simplify_symbols(struct module *mod, const struct load_info *info)
68186 ksym = resolve_symbol_wait(mod, info, name);
68187 /* Ok if resolved. */
68188 if (ksym && !IS_ERR(ksym)) {
68189+ pax_open_kernel();
68190 sym[i].st_value = ksym->value;
68191+ pax_close_kernel();
68192 break;
68193 }
68194
68195@@ -1941,11 +1970,20 @@ static int simplify_symbols(struct module *mod, const struct load_info *info)
68196 secbase = (unsigned long)mod_percpu(mod);
68197 else
68198 secbase = info->sechdrs[sym[i].st_shndx].sh_addr;
68199+ pax_open_kernel();
68200 sym[i].st_value += secbase;
68201+ pax_close_kernel();
68202 break;
68203 }
68204 }
68205
68206+#ifdef CONFIG_GRKERNSEC_MODHARDEN
68207+ if (is_fs_load && !register_filesystem_found) {
68208+ printk(KERN_ALERT "grsec: Denied attempt to load non-fs module %.64s through mount\n", mod->name);
68209+ ret = -EPERM;
68210+ }
68211+#endif
68212+
68213 return ret;
68214 }
68215
68216@@ -2049,22 +2087,12 @@ static void layout_sections(struct module *mod, struct load_info *info)
68217 || s->sh_entsize != ~0UL
68218 || strstarts(sname, ".init"))
68219 continue;
68220- s->sh_entsize = get_offset(mod, &mod->core_size, s, i);
68221+ if ((s->sh_flags & SHF_WRITE) || !(s->sh_flags & SHF_ALLOC))
68222+ s->sh_entsize = get_offset(mod, &mod->core_size_rw, s, i);
68223+ else
68224+ s->sh_entsize = get_offset(mod, &mod->core_size_rx, s, i);
68225 pr_debug("\t%s\n", sname);
68226 }
68227- switch (m) {
68228- case 0: /* executable */
68229- mod->core_size = debug_align(mod->core_size);
68230- mod->core_text_size = mod->core_size;
68231- break;
68232- case 1: /* RO: text and ro-data */
68233- mod->core_size = debug_align(mod->core_size);
68234- mod->core_ro_size = mod->core_size;
68235- break;
68236- case 3: /* whole core */
68237- mod->core_size = debug_align(mod->core_size);
68238- break;
68239- }
68240 }
68241
68242 pr_debug("Init section allocation order:\n");
68243@@ -2078,23 +2106,13 @@ static void layout_sections(struct module *mod, struct load_info *info)
68244 || s->sh_entsize != ~0UL
68245 || !strstarts(sname, ".init"))
68246 continue;
68247- s->sh_entsize = (get_offset(mod, &mod->init_size, s, i)
68248- | INIT_OFFSET_MASK);
68249+ if ((s->sh_flags & SHF_WRITE) || !(s->sh_flags & SHF_ALLOC))
68250+ s->sh_entsize = get_offset(mod, &mod->init_size_rw, s, i);
68251+ else
68252+ s->sh_entsize = get_offset(mod, &mod->init_size_rx, s, i);
68253+ s->sh_entsize |= INIT_OFFSET_MASK;
68254 pr_debug("\t%s\n", sname);
68255 }
68256- switch (m) {
68257- case 0: /* executable */
68258- mod->init_size = debug_align(mod->init_size);
68259- mod->init_text_size = mod->init_size;
68260- break;
68261- case 1: /* RO: text and ro-data */
68262- mod->init_size = debug_align(mod->init_size);
68263- mod->init_ro_size = mod->init_size;
68264- break;
68265- case 3: /* whole init */
68266- mod->init_size = debug_align(mod->init_size);
68267- break;
68268- }
68269 }
68270 }
68271
68272@@ -2266,7 +2284,7 @@ static void layout_symtab(struct module *mod, struct load_info *info)
68273
68274 /* Put symbol section at end of init part of module. */
68275 symsect->sh_flags |= SHF_ALLOC;
68276- symsect->sh_entsize = get_offset(mod, &mod->init_size, symsect,
68277+ symsect->sh_entsize = get_offset(mod, &mod->init_size_rx, symsect,
68278 info->index.sym) | INIT_OFFSET_MASK;
68279 pr_debug("\t%s\n", info->secstrings + symsect->sh_name);
68280
68281@@ -2281,13 +2299,13 @@ static void layout_symtab(struct module *mod, struct load_info *info)
68282 }
68283
68284 /* Append room for core symbols at end of core part. */
68285- info->symoffs = ALIGN(mod->core_size, symsect->sh_addralign ?: 1);
68286- info->stroffs = mod->core_size = info->symoffs + ndst * sizeof(Elf_Sym);
68287- mod->core_size += strtab_size;
68288+ info->symoffs = ALIGN(mod->core_size_rx, symsect->sh_addralign ?: 1);
68289+ info->stroffs = mod->core_size_rx = info->symoffs + ndst * sizeof(Elf_Sym);
68290+ mod->core_size_rx += strtab_size;
68291
68292 /* Put string table section at end of init part of module. */
68293 strsect->sh_flags |= SHF_ALLOC;
68294- strsect->sh_entsize = get_offset(mod, &mod->init_size, strsect,
68295+ strsect->sh_entsize = get_offset(mod, &mod->init_size_rx, strsect,
68296 info->index.str) | INIT_OFFSET_MASK;
68297 pr_debug("\t%s\n", info->secstrings + strsect->sh_name);
68298 }
68299@@ -2305,12 +2323,14 @@ static void add_kallsyms(struct module *mod, const struct load_info *info)
68300 /* Make sure we get permanent strtab: don't use info->strtab. */
68301 mod->strtab = (void *)info->sechdrs[info->index.str].sh_addr;
68302
68303+ pax_open_kernel();
68304+
68305 /* Set types up while we still have access to sections. */
68306 for (i = 0; i < mod->num_symtab; i++)
68307 mod->symtab[i].st_info = elf_type(&mod->symtab[i], info);
68308
68309- mod->core_symtab = dst = mod->module_core + info->symoffs;
68310- mod->core_strtab = s = mod->module_core + info->stroffs;
68311+ mod->core_symtab = dst = mod->module_core_rx + info->symoffs;
68312+ mod->core_strtab = s = mod->module_core_rx + info->stroffs;
68313 src = mod->symtab;
68314 *dst = *src;
68315 *s++ = 0;
68316@@ -2323,6 +2343,8 @@ static void add_kallsyms(struct module *mod, const struct load_info *info)
68317 s += strlcpy(s, &mod->strtab[src->st_name], KSYM_NAME_LEN) + 1;
68318 }
68319 mod->core_num_syms = ndst;
68320+
68321+ pax_close_kernel();
68322 }
68323 #else
68324 static inline void layout_symtab(struct module *mod, struct load_info *info)
68325@@ -2356,17 +2378,33 @@ void * __weak module_alloc(unsigned long size)
68326 return size == 0 ? NULL : vmalloc_exec(size);
68327 }
68328
68329-static void *module_alloc_update_bounds(unsigned long size)
68330+static void *module_alloc_update_bounds_rw(unsigned long size)
68331 {
68332 void *ret = module_alloc(size);
68333
68334 if (ret) {
68335 mutex_lock(&module_mutex);
68336 /* Update module bounds. */
68337- if ((unsigned long)ret < module_addr_min)
68338- module_addr_min = (unsigned long)ret;
68339- if ((unsigned long)ret + size > module_addr_max)
68340- module_addr_max = (unsigned long)ret + size;
68341+ if ((unsigned long)ret < module_addr_min_rw)
68342+ module_addr_min_rw = (unsigned long)ret;
68343+ if ((unsigned long)ret + size > module_addr_max_rw)
68344+ module_addr_max_rw = (unsigned long)ret + size;
68345+ mutex_unlock(&module_mutex);
68346+ }
68347+ return ret;
68348+}
68349+
68350+static void *module_alloc_update_bounds_rx(unsigned long size)
68351+{
68352+ void *ret = module_alloc_exec(size);
68353+
68354+ if (ret) {
68355+ mutex_lock(&module_mutex);
68356+ /* Update module bounds. */
68357+ if ((unsigned long)ret < module_addr_min_rx)
68358+ module_addr_min_rx = (unsigned long)ret;
68359+ if ((unsigned long)ret + size > module_addr_max_rx)
68360+ module_addr_max_rx = (unsigned long)ret + size;
68361 mutex_unlock(&module_mutex);
68362 }
68363 return ret;
68364@@ -2544,8 +2582,14 @@ static struct module *setup_load_info(struct load_info *info)
68365 static int check_modinfo(struct module *mod, struct load_info *info)
68366 {
68367 const char *modmagic = get_modinfo(info, "vermagic");
68368+ const char *license = get_modinfo(info, "license");
68369 int err;
68370
68371+#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR
68372+ if (!license || !license_is_gpl_compatible(license))
68373+ return -ENOEXEC;
68374+#endif
68375+
68376 /* This is allowed: modprobe --force will invalidate it. */
68377 if (!modmagic) {
68378 err = try_to_force_load(mod, "bad vermagic");
68379@@ -2568,7 +2612,7 @@ static int check_modinfo(struct module *mod, struct load_info *info)
68380 }
68381
68382 /* Set up license info based on the info section */
68383- set_license(mod, get_modinfo(info, "license"));
68384+ set_license(mod, license);
68385
68386 return 0;
68387 }
68388@@ -2662,7 +2706,7 @@ static int move_module(struct module *mod, struct load_info *info)
68389 void *ptr;
68390
68391 /* Do the allocs. */
68392- ptr = module_alloc_update_bounds(mod->core_size);
68393+ ptr = module_alloc_update_bounds_rw(mod->core_size_rw);
68394 /*
68395 * The pointer to this block is stored in the module structure
68396 * which is inside the block. Just mark it as not being a
68397@@ -2672,23 +2716,50 @@ static int move_module(struct module *mod, struct load_info *info)
68398 if (!ptr)
68399 return -ENOMEM;
68400
68401- memset(ptr, 0, mod->core_size);
68402- mod->module_core = ptr;
68403+ memset(ptr, 0, mod->core_size_rw);
68404+ mod->module_core_rw = ptr;
68405
68406- ptr = module_alloc_update_bounds(mod->init_size);
68407+ ptr = module_alloc_update_bounds_rw(mod->init_size_rw);
68408 /*
68409 * The pointer to this block is stored in the module structure
68410 * which is inside the block. This block doesn't need to be
68411 * scanned as it contains data and code that will be freed
68412 * after the module is initialized.
68413 */
68414- kmemleak_ignore(ptr);
68415- if (!ptr && mod->init_size) {
68416- module_free(mod, mod->module_core);
68417+ kmemleak_not_leak(ptr);
68418+ if (!ptr && mod->init_size_rw) {
68419+ module_free(mod, mod->module_core_rw);
68420 return -ENOMEM;
68421 }
68422- memset(ptr, 0, mod->init_size);
68423- mod->module_init = ptr;
68424+ memset(ptr, 0, mod->init_size_rw);
68425+ mod->module_init_rw = ptr;
68426+
68427+ ptr = module_alloc_update_bounds_rx(mod->core_size_rx);
68428+ kmemleak_not_leak(ptr);
68429+ if (!ptr) {
68430+ module_free(mod, mod->module_init_rw);
68431+ module_free(mod, mod->module_core_rw);
68432+ return -ENOMEM;
68433+ }
68434+
68435+ pax_open_kernel();
68436+ memset(ptr, 0, mod->core_size_rx);
68437+ pax_close_kernel();
68438+ mod->module_core_rx = ptr;
68439+
68440+ ptr = module_alloc_update_bounds_rx(mod->init_size_rx);
68441+ kmemleak_not_leak(ptr);
68442+ if (!ptr && mod->init_size_rx) {
68443+ module_free_exec(mod, mod->module_core_rx);
68444+ module_free(mod, mod->module_init_rw);
68445+ module_free(mod, mod->module_core_rw);
68446+ return -ENOMEM;
68447+ }
68448+
68449+ pax_open_kernel();
68450+ memset(ptr, 0, mod->init_size_rx);
68451+ pax_close_kernel();
68452+ mod->module_init_rx = ptr;
68453
68454 /* Transfer each section which specifies SHF_ALLOC */
68455 pr_debug("final section addresses:\n");
68456@@ -2699,16 +2770,45 @@ static int move_module(struct module *mod, struct load_info *info)
68457 if (!(shdr->sh_flags & SHF_ALLOC))
68458 continue;
68459
68460- if (shdr->sh_entsize & INIT_OFFSET_MASK)
68461- dest = mod->module_init
68462- + (shdr->sh_entsize & ~INIT_OFFSET_MASK);
68463- else
68464- dest = mod->module_core + shdr->sh_entsize;
68465+ if (shdr->sh_entsize & INIT_OFFSET_MASK) {
68466+ if ((shdr->sh_flags & SHF_WRITE) || !(shdr->sh_flags & SHF_ALLOC))
68467+ dest = mod->module_init_rw
68468+ + (shdr->sh_entsize & ~INIT_OFFSET_MASK);
68469+ else
68470+ dest = mod->module_init_rx
68471+ + (shdr->sh_entsize & ~INIT_OFFSET_MASK);
68472+ } else {
68473+ if ((shdr->sh_flags & SHF_WRITE) || !(shdr->sh_flags & SHF_ALLOC))
68474+ dest = mod->module_core_rw + shdr->sh_entsize;
68475+ else
68476+ dest = mod->module_core_rx + shdr->sh_entsize;
68477+ }
68478+
68479+ if (shdr->sh_type != SHT_NOBITS) {
68480+
68481+#ifdef CONFIG_PAX_KERNEXEC
68482+#ifdef CONFIG_X86_64
68483+ if ((shdr->sh_flags & SHF_WRITE) && (shdr->sh_flags & SHF_EXECINSTR))
68484+ set_memory_x((unsigned long)dest, (shdr->sh_size + PAGE_SIZE) >> PAGE_SHIFT);
68485+#endif
68486+ if (!(shdr->sh_flags & SHF_WRITE) && (shdr->sh_flags & SHF_ALLOC)) {
68487+ pax_open_kernel();
68488+ memcpy(dest, (void *)shdr->sh_addr, shdr->sh_size);
68489+ pax_close_kernel();
68490+ } else
68491+#endif
68492
68493- if (shdr->sh_type != SHT_NOBITS)
68494 memcpy(dest, (void *)shdr->sh_addr, shdr->sh_size);
68495+ }
68496 /* Update sh_addr to point to copy in image. */
68497- shdr->sh_addr = (unsigned long)dest;
68498+
68499+#ifdef CONFIG_PAX_KERNEXEC
68500+ if (shdr->sh_flags & SHF_EXECINSTR)
68501+ shdr->sh_addr = ktva_ktla((unsigned long)dest);
68502+ else
68503+#endif
68504+
68505+ shdr->sh_addr = (unsigned long)dest;
68506 pr_debug("\t0x%lx %s\n",
68507 (long)shdr->sh_addr, info->secstrings + shdr->sh_name);
68508 }
68509@@ -2763,12 +2863,12 @@ static void flush_module_icache(const struct module *mod)
68510 * Do it before processing of module parameters, so the module
68511 * can provide parameter accessor functions of its own.
68512 */
68513- if (mod->module_init)
68514- flush_icache_range((unsigned long)mod->module_init,
68515- (unsigned long)mod->module_init
68516- + mod->init_size);
68517- flush_icache_range((unsigned long)mod->module_core,
68518- (unsigned long)mod->module_core + mod->core_size);
68519+ if (mod->module_init_rx)
68520+ flush_icache_range((unsigned long)mod->module_init_rx,
68521+ (unsigned long)mod->module_init_rx
68522+ + mod->init_size_rx);
68523+ flush_icache_range((unsigned long)mod->module_core_rx,
68524+ (unsigned long)mod->module_core_rx + mod->core_size_rx);
68525
68526 set_fs(old_fs);
68527 }
68528@@ -2838,8 +2938,10 @@ out:
68529 static void module_deallocate(struct module *mod, struct load_info *info)
68530 {
68531 percpu_modfree(mod);
68532- module_free(mod, mod->module_init);
68533- module_free(mod, mod->module_core);
68534+ module_free_exec(mod, mod->module_init_rx);
68535+ module_free_exec(mod, mod->module_core_rx);
68536+ module_free(mod, mod->module_init_rw);
68537+ module_free(mod, mod->module_core_rw);
68538 }
68539
68540 int __weak module_finalize(const Elf_Ehdr *hdr,
68541@@ -2852,7 +2954,9 @@ int __weak module_finalize(const Elf_Ehdr *hdr,
68542 static int post_relocation(struct module *mod, const struct load_info *info)
68543 {
68544 /* Sort exception table now relocations are done. */
68545+ pax_open_kernel();
68546 sort_extable(mod->extable, mod->extable + mod->num_exentries);
68547+ pax_close_kernel();
68548
68549 /* Copy relocated percpu area over. */
68550 percpu_modcopy(mod, (void *)info->sechdrs[info->index.pcpu].sh_addr,
68551@@ -2903,9 +3007,38 @@ static struct module *load_module(void __user *umod,
68552 if (err)
68553 goto free_unload;
68554
68555+ /* Now copy in args */
68556+ mod->args = strndup_user(uargs, ~0UL >> 1);
68557+ if (IS_ERR(mod->args)) {
68558+ err = PTR_ERR(mod->args);
68559+ goto free_unload;
68560+ }
68561+
68562 /* Set up MODINFO_ATTR fields */
68563 setup_modinfo(mod, &info);
68564
68565+#ifdef CONFIG_GRKERNSEC_MODHARDEN
68566+ {
68567+ char *p, *p2;
68568+
68569+ if (strstr(mod->args, "grsec_modharden_netdev")) {
68570+ 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);
68571+ err = -EPERM;
68572+ goto free_modinfo;
68573+ } else if ((p = strstr(mod->args, "grsec_modharden_normal"))) {
68574+ p += strlen("grsec_modharden_normal");
68575+ p2 = strstr(p, "_");
68576+ if (p2) {
68577+ *p2 = '\0';
68578+ printk(KERN_ALERT "grsec: denied kernel module auto-load of %.64s by uid %.9s\n", mod->name, p);
68579+ *p2 = '_';
68580+ }
68581+ err = -EPERM;
68582+ goto free_modinfo;
68583+ }
68584+ }
68585+#endif
68586+
68587 /* Fix up syms, so that st_value is a pointer to location. */
68588 err = simplify_symbols(mod, &info);
68589 if (err < 0)
68590@@ -2921,13 +3054,6 @@ static struct module *load_module(void __user *umod,
68591
68592 flush_module_icache(mod);
68593
68594- /* Now copy in args */
68595- mod->args = strndup_user(uargs, ~0UL >> 1);
68596- if (IS_ERR(mod->args)) {
68597- err = PTR_ERR(mod->args);
68598- goto free_arch_cleanup;
68599- }
68600-
68601 /* Mark state as coming so strong_try_module_get() ignores us. */
68602 mod->state = MODULE_STATE_COMING;
68603
68604@@ -2985,11 +3111,10 @@ static struct module *load_module(void __user *umod,
68605 unlock:
68606 mutex_unlock(&module_mutex);
68607 synchronize_sched();
68608- kfree(mod->args);
68609- free_arch_cleanup:
68610 module_arch_cleanup(mod);
68611 free_modinfo:
68612 free_modinfo(mod);
68613+ kfree(mod->args);
68614 free_unload:
68615 module_unload_free(mod);
68616 free_module:
68617@@ -3030,16 +3155,16 @@ SYSCALL_DEFINE3(init_module, void __user *, umod,
68618 MODULE_STATE_COMING, mod);
68619
68620 /* Set RO and NX regions for core */
68621- set_section_ro_nx(mod->module_core,
68622- mod->core_text_size,
68623- mod->core_ro_size,
68624- mod->core_size);
68625+ set_section_ro_nx(mod->module_core_rx,
68626+ mod->core_size_rx,
68627+ mod->core_size_rx,
68628+ mod->core_size_rx);
68629
68630 /* Set RO and NX regions for init */
68631- set_section_ro_nx(mod->module_init,
68632- mod->init_text_size,
68633- mod->init_ro_size,
68634- mod->init_size);
68635+ set_section_ro_nx(mod->module_init_rx,
68636+ mod->init_size_rx,
68637+ mod->init_size_rx,
68638+ mod->init_size_rx);
68639
68640 do_mod_ctors(mod);
68641 /* Start the module */
68642@@ -3085,11 +3210,12 @@ SYSCALL_DEFINE3(init_module, void __user *, umod,
68643 mod->strtab = mod->core_strtab;
68644 #endif
68645 unset_module_init_ro_nx(mod);
68646- module_free(mod, mod->module_init);
68647- mod->module_init = NULL;
68648- mod->init_size = 0;
68649- mod->init_ro_size = 0;
68650- mod->init_text_size = 0;
68651+ module_free(mod, mod->module_init_rw);
68652+ module_free_exec(mod, mod->module_init_rx);
68653+ mod->module_init_rw = NULL;
68654+ mod->module_init_rx = NULL;
68655+ mod->init_size_rw = 0;
68656+ mod->init_size_rx = 0;
68657 mutex_unlock(&module_mutex);
68658
68659 return 0;
68660@@ -3120,10 +3246,16 @@ static const char *get_ksymbol(struct module *mod,
68661 unsigned long nextval;
68662
68663 /* At worse, next value is at end of module */
68664- if (within_module_init(addr, mod))
68665- nextval = (unsigned long)mod->module_init+mod->init_text_size;
68666+ if (within_module_init_rx(addr, mod))
68667+ nextval = (unsigned long)mod->module_init_rx+mod->init_size_rx;
68668+ else if (within_module_init_rw(addr, mod))
68669+ nextval = (unsigned long)mod->module_init_rw+mod->init_size_rw;
68670+ else if (within_module_core_rx(addr, mod))
68671+ nextval = (unsigned long)mod->module_core_rx+mod->core_size_rx;
68672+ else if (within_module_core_rw(addr, mod))
68673+ nextval = (unsigned long)mod->module_core_rw+mod->core_size_rw;
68674 else
68675- nextval = (unsigned long)mod->module_core+mod->core_text_size;
68676+ return NULL;
68677
68678 /* Scan for closest preceding symbol, and next symbol. (ELF
68679 starts real symbols at 1). */
68680@@ -3358,7 +3490,7 @@ static int m_show(struct seq_file *m, void *p)
68681 char buf[8];
68682
68683 seq_printf(m, "%s %u",
68684- mod->name, mod->init_size + mod->core_size);
68685+ mod->name, mod->init_size_rx + mod->init_size_rw + mod->core_size_rx + mod->core_size_rw);
68686 print_unload_info(m, mod);
68687
68688 /* Informative for users. */
68689@@ -3367,7 +3499,7 @@ static int m_show(struct seq_file *m, void *p)
68690 mod->state == MODULE_STATE_COMING ? "Loading":
68691 "Live");
68692 /* Used by oprofile and other similar tools. */
68693- seq_printf(m, " 0x%pK", mod->module_core);
68694+ seq_printf(m, " 0x%pK 0x%pK", mod->module_core_rx, mod->module_core_rw);
68695
68696 /* Taints info */
68697 if (mod->taints)
68698@@ -3403,7 +3535,17 @@ static const struct file_operations proc_modules_operations = {
68699
68700 static int __init proc_modules_init(void)
68701 {
68702+#ifndef CONFIG_GRKERNSEC_HIDESYM
68703+#ifdef CONFIG_GRKERNSEC_PROC_USER
68704+ proc_create("modules", S_IRUSR, NULL, &proc_modules_operations);
68705+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
68706+ proc_create("modules", S_IRUSR | S_IRGRP, NULL, &proc_modules_operations);
68707+#else
68708 proc_create("modules", 0, NULL, &proc_modules_operations);
68709+#endif
68710+#else
68711+ proc_create("modules", S_IRUSR, NULL, &proc_modules_operations);
68712+#endif
68713 return 0;
68714 }
68715 module_init(proc_modules_init);
68716@@ -3462,12 +3604,12 @@ struct module *__module_address(unsigned long addr)
68717 {
68718 struct module *mod;
68719
68720- if (addr < module_addr_min || addr > module_addr_max)
68721+ if ((addr < module_addr_min_rx || addr > module_addr_max_rx) &&
68722+ (addr < module_addr_min_rw || addr > module_addr_max_rw))
68723 return NULL;
68724
68725 list_for_each_entry_rcu(mod, &modules, list)
68726- if (within_module_core(addr, mod)
68727- || within_module_init(addr, mod))
68728+ if (within_module_init(addr, mod) || within_module_core(addr, mod))
68729 return mod;
68730 return NULL;
68731 }
68732@@ -3501,11 +3643,20 @@ bool is_module_text_address(unsigned long addr)
68733 */
68734 struct module *__module_text_address(unsigned long addr)
68735 {
68736- struct module *mod = __module_address(addr);
68737+ struct module *mod;
68738+
68739+#ifdef CONFIG_X86_32
68740+ addr = ktla_ktva(addr);
68741+#endif
68742+
68743+ if (addr < module_addr_min_rx || addr > module_addr_max_rx)
68744+ return NULL;
68745+
68746+ mod = __module_address(addr);
68747+
68748 if (mod) {
68749 /* Make sure it's within the text section. */
68750- if (!within(addr, mod->module_init, mod->init_text_size)
68751- && !within(addr, mod->module_core, mod->core_text_size))
68752+ if (!within_module_init_rx(addr, mod) && !within_module_core_rx(addr, mod))
68753 mod = NULL;
68754 }
68755 return mod;
68756diff --git a/kernel/mutex-debug.c b/kernel/mutex-debug.c
68757index 7e3443f..b2a1e6b 100644
68758--- a/kernel/mutex-debug.c
68759+++ b/kernel/mutex-debug.c
68760@@ -49,21 +49,21 @@ void debug_mutex_free_waiter(struct mutex_waiter *waiter)
68761 }
68762
68763 void debug_mutex_add_waiter(struct mutex *lock, struct mutex_waiter *waiter,
68764- struct thread_info *ti)
68765+ struct task_struct *task)
68766 {
68767 SMP_DEBUG_LOCKS_WARN_ON(!spin_is_locked(&lock->wait_lock));
68768
68769 /* Mark the current thread as blocked on the lock: */
68770- ti->task->blocked_on = waiter;
68771+ task->blocked_on = waiter;
68772 }
68773
68774 void mutex_remove_waiter(struct mutex *lock, struct mutex_waiter *waiter,
68775- struct thread_info *ti)
68776+ struct task_struct *task)
68777 {
68778 DEBUG_LOCKS_WARN_ON(list_empty(&waiter->list));
68779- DEBUG_LOCKS_WARN_ON(waiter->task != ti->task);
68780- DEBUG_LOCKS_WARN_ON(ti->task->blocked_on != waiter);
68781- ti->task->blocked_on = NULL;
68782+ DEBUG_LOCKS_WARN_ON(waiter->task != task);
68783+ DEBUG_LOCKS_WARN_ON(task->blocked_on != waiter);
68784+ task->blocked_on = NULL;
68785
68786 list_del_init(&waiter->list);
68787 waiter->task = NULL;
68788diff --git a/kernel/mutex-debug.h b/kernel/mutex-debug.h
68789index 0799fd3..d06ae3b 100644
68790--- a/kernel/mutex-debug.h
68791+++ b/kernel/mutex-debug.h
68792@@ -20,9 +20,9 @@ extern void debug_mutex_wake_waiter(struct mutex *lock,
68793 extern void debug_mutex_free_waiter(struct mutex_waiter *waiter);
68794 extern void debug_mutex_add_waiter(struct mutex *lock,
68795 struct mutex_waiter *waiter,
68796- struct thread_info *ti);
68797+ struct task_struct *task);
68798 extern void mutex_remove_waiter(struct mutex *lock, struct mutex_waiter *waiter,
68799- struct thread_info *ti);
68800+ struct task_struct *task);
68801 extern void debug_mutex_unlock(struct mutex *lock);
68802 extern void debug_mutex_init(struct mutex *lock, const char *name,
68803 struct lock_class_key *key);
68804diff --git a/kernel/mutex.c b/kernel/mutex.c
68805index a307cc9..27fd2e9 100644
68806--- a/kernel/mutex.c
68807+++ b/kernel/mutex.c
68808@@ -198,7 +198,7 @@ __mutex_lock_common(struct mutex *lock, long state, unsigned int subclass,
68809 spin_lock_mutex(&lock->wait_lock, flags);
68810
68811 debug_mutex_lock_common(lock, &waiter);
68812- debug_mutex_add_waiter(lock, &waiter, task_thread_info(task));
68813+ debug_mutex_add_waiter(lock, &waiter, task);
68814
68815 /* add waiting tasks to the end of the waitqueue (FIFO): */
68816 list_add_tail(&waiter.list, &lock->wait_list);
68817@@ -227,8 +227,7 @@ __mutex_lock_common(struct mutex *lock, long state, unsigned int subclass,
68818 * TASK_UNINTERRUPTIBLE case.)
68819 */
68820 if (unlikely(signal_pending_state(state, task))) {
68821- mutex_remove_waiter(lock, &waiter,
68822- task_thread_info(task));
68823+ mutex_remove_waiter(lock, &waiter, task);
68824 mutex_release(&lock->dep_map, 1, ip);
68825 spin_unlock_mutex(&lock->wait_lock, flags);
68826
68827@@ -247,7 +246,7 @@ __mutex_lock_common(struct mutex *lock, long state, unsigned int subclass,
68828 done:
68829 lock_acquired(&lock->dep_map, ip);
68830 /* got the lock - rejoice! */
68831- mutex_remove_waiter(lock, &waiter, current_thread_info());
68832+ mutex_remove_waiter(lock, &waiter, task);
68833 mutex_set_owner(lock);
68834
68835 /* set it to 0 if there are no waiters left: */
68836diff --git a/kernel/panic.c b/kernel/panic.c
68837index e1b2822..5edc1d9 100644
68838--- a/kernel/panic.c
68839+++ b/kernel/panic.c
68840@@ -410,7 +410,7 @@ static void warn_slowpath_common(const char *file, int line, void *caller,
68841 const char *board;
68842
68843 printk(KERN_WARNING "------------[ cut here ]------------\n");
68844- printk(KERN_WARNING "WARNING: at %s:%d %pS()\n", file, line, caller);
68845+ printk(KERN_WARNING "WARNING: at %s:%d %pA()\n", file, line, caller);
68846 board = dmi_get_system_info(DMI_PRODUCT_NAME);
68847 if (board)
68848 printk(KERN_WARNING "Hardware name: %s\n", board);
68849@@ -465,7 +465,8 @@ EXPORT_SYMBOL(warn_slowpath_null);
68850 */
68851 void __stack_chk_fail(void)
68852 {
68853- panic("stack-protector: Kernel stack is corrupted in: %p\n",
68854+ dump_stack();
68855+ panic("stack-protector: Kernel stack is corrupted in: %pA\n",
68856 __builtin_return_address(0));
68857 }
68858 EXPORT_SYMBOL(__stack_chk_fail);
68859diff --git a/kernel/pid.c b/kernel/pid.c
68860index e86b291a..e8b0fb5 100644
68861--- a/kernel/pid.c
68862+++ b/kernel/pid.c
68863@@ -33,6 +33,7 @@
68864 #include <linux/rculist.h>
68865 #include <linux/bootmem.h>
68866 #include <linux/hash.h>
68867+#include <linux/security.h>
68868 #include <linux/pid_namespace.h>
68869 #include <linux/init_task.h>
68870 #include <linux/syscalls.h>
68871@@ -45,7 +46,7 @@ struct pid init_struct_pid = INIT_STRUCT_PID;
68872
68873 int pid_max = PID_MAX_DEFAULT;
68874
68875-#define RESERVED_PIDS 300
68876+#define RESERVED_PIDS 500
68877
68878 int pid_max_min = RESERVED_PIDS + 1;
68879 int pid_max_max = PID_MAX_LIMIT;
68880@@ -420,10 +421,18 @@ EXPORT_SYMBOL(pid_task);
68881 */
68882 struct task_struct *find_task_by_pid_ns(pid_t nr, struct pid_namespace *ns)
68883 {
68884+ struct task_struct *task;
68885+
68886 rcu_lockdep_assert(rcu_read_lock_held(),
68887 "find_task_by_pid_ns() needs rcu_read_lock()"
68888 " protection");
68889- return pid_task(find_pid_ns(nr, ns), PIDTYPE_PID);
68890+
68891+ task = pid_task(find_pid_ns(nr, ns), PIDTYPE_PID);
68892+
68893+ if (gr_pid_is_chrooted(task))
68894+ return NULL;
68895+
68896+ return task;
68897 }
68898
68899 struct task_struct *find_task_by_vpid(pid_t vnr)
68900@@ -431,6 +440,14 @@ struct task_struct *find_task_by_vpid(pid_t vnr)
68901 return find_task_by_pid_ns(vnr, current->nsproxy->pid_ns);
68902 }
68903
68904+struct task_struct *find_task_by_vpid_unrestricted(pid_t vnr)
68905+{
68906+ rcu_lockdep_assert(rcu_read_lock_held(),
68907+ "find_task_by_pid_ns() needs rcu_read_lock()"
68908+ " protection");
68909+ return pid_task(find_pid_ns(vnr, current->nsproxy->pid_ns), PIDTYPE_PID);
68910+}
68911+
68912 struct pid *get_task_pid(struct task_struct *task, enum pid_type type)
68913 {
68914 struct pid *pid;
68915diff --git a/kernel/posix-cpu-timers.c b/kernel/posix-cpu-timers.c
68916index 125cb67..a4d1c30 100644
68917--- a/kernel/posix-cpu-timers.c
68918+++ b/kernel/posix-cpu-timers.c
68919@@ -6,6 +6,7 @@
68920 #include <linux/posix-timers.h>
68921 #include <linux/errno.h>
68922 #include <linux/math64.h>
68923+#include <linux/security.h>
68924 #include <asm/uaccess.h>
68925 #include <linux/kernel_stat.h>
68926 #include <trace/events/timer.h>
68927@@ -1578,14 +1579,14 @@ struct k_clock clock_posix_cpu = {
68928
68929 static __init int init_posix_cpu_timers(void)
68930 {
68931- struct k_clock process = {
68932+ static struct k_clock process = {
68933 .clock_getres = process_cpu_clock_getres,
68934 .clock_get = process_cpu_clock_get,
68935 .timer_create = process_cpu_timer_create,
68936 .nsleep = process_cpu_nsleep,
68937 .nsleep_restart = process_cpu_nsleep_restart,
68938 };
68939- struct k_clock thread = {
68940+ static struct k_clock thread = {
68941 .clock_getres = thread_cpu_clock_getres,
68942 .clock_get = thread_cpu_clock_get,
68943 .timer_create = thread_cpu_timer_create,
68944diff --git a/kernel/posix-timers.c b/kernel/posix-timers.c
68945index 69185ae..cc2847a 100644
68946--- a/kernel/posix-timers.c
68947+++ b/kernel/posix-timers.c
68948@@ -43,6 +43,7 @@
68949 #include <linux/idr.h>
68950 #include <linux/posix-clock.h>
68951 #include <linux/posix-timers.h>
68952+#include <linux/grsecurity.h>
68953 #include <linux/syscalls.h>
68954 #include <linux/wait.h>
68955 #include <linux/workqueue.h>
68956@@ -129,7 +130,7 @@ static DEFINE_SPINLOCK(idr_lock);
68957 * which we beg off on and pass to do_sys_settimeofday().
68958 */
68959
68960-static struct k_clock posix_clocks[MAX_CLOCKS];
68961+static struct k_clock *posix_clocks[MAX_CLOCKS];
68962
68963 /*
68964 * These ones are defined below.
68965@@ -227,7 +228,7 @@ static int posix_get_boottime(const clockid_t which_clock, struct timespec *tp)
68966 */
68967 static __init int init_posix_timers(void)
68968 {
68969- struct k_clock clock_realtime = {
68970+ static struct k_clock clock_realtime = {
68971 .clock_getres = hrtimer_get_res,
68972 .clock_get = posix_clock_realtime_get,
68973 .clock_set = posix_clock_realtime_set,
68974@@ -239,7 +240,7 @@ static __init int init_posix_timers(void)
68975 .timer_get = common_timer_get,
68976 .timer_del = common_timer_del,
68977 };
68978- struct k_clock clock_monotonic = {
68979+ static struct k_clock clock_monotonic = {
68980 .clock_getres = hrtimer_get_res,
68981 .clock_get = posix_ktime_get_ts,
68982 .nsleep = common_nsleep,
68983@@ -249,19 +250,19 @@ static __init int init_posix_timers(void)
68984 .timer_get = common_timer_get,
68985 .timer_del = common_timer_del,
68986 };
68987- struct k_clock clock_monotonic_raw = {
68988+ static struct k_clock clock_monotonic_raw = {
68989 .clock_getres = hrtimer_get_res,
68990 .clock_get = posix_get_monotonic_raw,
68991 };
68992- struct k_clock clock_realtime_coarse = {
68993+ static struct k_clock clock_realtime_coarse = {
68994 .clock_getres = posix_get_coarse_res,
68995 .clock_get = posix_get_realtime_coarse,
68996 };
68997- struct k_clock clock_monotonic_coarse = {
68998+ static struct k_clock clock_monotonic_coarse = {
68999 .clock_getres = posix_get_coarse_res,
69000 .clock_get = posix_get_monotonic_coarse,
69001 };
69002- struct k_clock clock_boottime = {
69003+ static struct k_clock clock_boottime = {
69004 .clock_getres = hrtimer_get_res,
69005 .clock_get = posix_get_boottime,
69006 .nsleep = common_nsleep,
69007@@ -473,7 +474,7 @@ void posix_timers_register_clock(const clockid_t clock_id,
69008 return;
69009 }
69010
69011- posix_clocks[clock_id] = *new_clock;
69012+ posix_clocks[clock_id] = new_clock;
69013 }
69014 EXPORT_SYMBOL_GPL(posix_timers_register_clock);
69015
69016@@ -519,9 +520,9 @@ static struct k_clock *clockid_to_kclock(const clockid_t id)
69017 return (id & CLOCKFD_MASK) == CLOCKFD ?
69018 &clock_posix_dynamic : &clock_posix_cpu;
69019
69020- if (id >= MAX_CLOCKS || !posix_clocks[id].clock_getres)
69021+ if (id >= MAX_CLOCKS || !posix_clocks[id] || !posix_clocks[id]->clock_getres)
69022 return NULL;
69023- return &posix_clocks[id];
69024+ return posix_clocks[id];
69025 }
69026
69027 static int common_timer_create(struct k_itimer *new_timer)
69028@@ -959,6 +960,13 @@ SYSCALL_DEFINE2(clock_settime, const clockid_t, which_clock,
69029 if (copy_from_user(&new_tp, tp, sizeof (*tp)))
69030 return -EFAULT;
69031
69032+ /* only the CLOCK_REALTIME clock can be set, all other clocks
69033+ have their clock_set fptr set to a nosettime dummy function
69034+ CLOCK_REALTIME has a NULL clock_set fptr which causes it to
69035+ call common_clock_set, which calls do_sys_settimeofday, which
69036+ we hook
69037+ */
69038+
69039 return kc->clock_set(which_clock, &new_tp);
69040 }
69041
69042diff --git a/kernel/power/poweroff.c b/kernel/power/poweroff.c
69043index d523593..68197a4 100644
69044--- a/kernel/power/poweroff.c
69045+++ b/kernel/power/poweroff.c
69046@@ -37,7 +37,7 @@ static struct sysrq_key_op sysrq_poweroff_op = {
69047 .enable_mask = SYSRQ_ENABLE_BOOT,
69048 };
69049
69050-static int pm_sysrq_init(void)
69051+static int __init pm_sysrq_init(void)
69052 {
69053 register_sysrq_key('o', &sysrq_poweroff_op);
69054 return 0;
69055diff --git a/kernel/power/process.c b/kernel/power/process.c
69056index 19db29f..33b52b6 100644
69057--- a/kernel/power/process.c
69058+++ b/kernel/power/process.c
69059@@ -33,6 +33,7 @@ static int try_to_freeze_tasks(bool user_only)
69060 u64 elapsed_csecs64;
69061 unsigned int elapsed_csecs;
69062 bool wakeup = false;
69063+ bool timedout = false;
69064
69065 do_gettimeofday(&start);
69066
69067@@ -43,6 +44,8 @@ static int try_to_freeze_tasks(bool user_only)
69068
69069 while (true) {
69070 todo = 0;
69071+ if (time_after(jiffies, end_time))
69072+ timedout = true;
69073 read_lock(&tasklist_lock);
69074 do_each_thread(g, p) {
69075 if (p == current || !freeze_task(p))
69076@@ -58,9 +61,13 @@ static int try_to_freeze_tasks(bool user_only)
69077 * guaranteed that TASK_STOPPED/TRACED -> TASK_RUNNING
69078 * transition can't race with task state testing here.
69079 */
69080- if (!task_is_stopped_or_traced(p) &&
69081- !freezer_should_skip(p))
69082+ if (!task_is_stopped_or_traced(p) && !freezer_should_skip(p)) {
69083 todo++;
69084+ if (timedout) {
69085+ printk(KERN_ERR "Task refusing to freeze:\n");
69086+ sched_show_task(p);
69087+ }
69088+ }
69089 } while_each_thread(g, p);
69090 read_unlock(&tasklist_lock);
69091
69092@@ -69,7 +76,7 @@ static int try_to_freeze_tasks(bool user_only)
69093 todo += wq_busy;
69094 }
69095
69096- if (!todo || time_after(jiffies, end_time))
69097+ if (!todo || timedout)
69098 break;
69099
69100 if (pm_wakeup_pending()) {
69101diff --git a/kernel/printk.c b/kernel/printk.c
69102index 66a2ea3..10f3a01 100644
69103--- a/kernel/printk.c
69104+++ b/kernel/printk.c
69105@@ -817,6 +817,11 @@ static int check_syslog_permissions(int type, bool from_file)
69106 if (from_file && type != SYSLOG_ACTION_OPEN)
69107 return 0;
69108
69109+#ifdef CONFIG_GRKERNSEC_DMESG
69110+ if (grsec_enable_dmesg && !capable(CAP_SYSLOG) && !capable_nolog(CAP_SYS_ADMIN))
69111+ return -EPERM;
69112+#endif
69113+
69114 if (syslog_action_restricted(type)) {
69115 if (capable(CAP_SYSLOG))
69116 return 0;
69117diff --git a/kernel/profile.c b/kernel/profile.c
69118index 76b8e77..a2930e8 100644
69119--- a/kernel/profile.c
69120+++ b/kernel/profile.c
69121@@ -39,7 +39,7 @@ struct profile_hit {
69122 /* Oprofile timer tick hook */
69123 static int (*timer_hook)(struct pt_regs *) __read_mostly;
69124
69125-static atomic_t *prof_buffer;
69126+static atomic_unchecked_t *prof_buffer;
69127 static unsigned long prof_len, prof_shift;
69128
69129 int prof_on __read_mostly;
69130@@ -281,7 +281,7 @@ static void profile_flip_buffers(void)
69131 hits[i].pc = 0;
69132 continue;
69133 }
69134- atomic_add(hits[i].hits, &prof_buffer[hits[i].pc]);
69135+ atomic_add_unchecked(hits[i].hits, &prof_buffer[hits[i].pc]);
69136 hits[i].hits = hits[i].pc = 0;
69137 }
69138 }
69139@@ -342,9 +342,9 @@ static void do_profile_hits(int type, void *__pc, unsigned int nr_hits)
69140 * Add the current hit(s) and flush the write-queue out
69141 * to the global buffer:
69142 */
69143- atomic_add(nr_hits, &prof_buffer[pc]);
69144+ atomic_add_unchecked(nr_hits, &prof_buffer[pc]);
69145 for (i = 0; i < NR_PROFILE_HIT; ++i) {
69146- atomic_add(hits[i].hits, &prof_buffer[hits[i].pc]);
69147+ atomic_add_unchecked(hits[i].hits, &prof_buffer[hits[i].pc]);
69148 hits[i].pc = hits[i].hits = 0;
69149 }
69150 out:
69151@@ -419,7 +419,7 @@ static void do_profile_hits(int type, void *__pc, unsigned int nr_hits)
69152 {
69153 unsigned long pc;
69154 pc = ((unsigned long)__pc - (unsigned long)_stext) >> prof_shift;
69155- atomic_add(nr_hits, &prof_buffer[min(pc, prof_len - 1)]);
69156+ atomic_add_unchecked(nr_hits, &prof_buffer[min(pc, prof_len - 1)]);
69157 }
69158 #endif /* !CONFIG_SMP */
69159
69160@@ -517,7 +517,7 @@ read_profile(struct file *file, char __user *buf, size_t count, loff_t *ppos)
69161 return -EFAULT;
69162 buf++; p++; count--; read++;
69163 }
69164- pnt = (char *)prof_buffer + p - sizeof(atomic_t);
69165+ pnt = (char *)prof_buffer + p - sizeof(atomic_unchecked_t);
69166 if (copy_to_user(buf, (void *)pnt, count))
69167 return -EFAULT;
69168 read += count;
69169@@ -548,7 +548,7 @@ static ssize_t write_profile(struct file *file, const char __user *buf,
69170 }
69171 #endif
69172 profile_discard_flip_buffers();
69173- memset(prof_buffer, 0, prof_len * sizeof(atomic_t));
69174+ memset(prof_buffer, 0, prof_len * sizeof(atomic_unchecked_t));
69175 return count;
69176 }
69177
69178diff --git a/kernel/ptrace.c b/kernel/ptrace.c
69179index a232bb5..2a65ef9 100644
69180--- a/kernel/ptrace.c
69181+++ b/kernel/ptrace.c
69182@@ -279,7 +279,7 @@ static int ptrace_attach(struct task_struct *task, long request,
69183
69184 if (seize)
69185 flags |= PT_SEIZED;
69186- if (ns_capable(task_user_ns(task), CAP_SYS_PTRACE))
69187+ if (ns_capable_nolog(task_user_ns(task), CAP_SYS_PTRACE))
69188 flags |= PT_PTRACE_CAP;
69189 task->ptrace = flags;
69190
69191@@ -486,7 +486,7 @@ int ptrace_readdata(struct task_struct *tsk, unsigned long src, char __user *dst
69192 break;
69193 return -EIO;
69194 }
69195- if (copy_to_user(dst, buf, retval))
69196+ if (retval > sizeof(buf) || copy_to_user(dst, buf, retval))
69197 return -EFAULT;
69198 copied += retval;
69199 src += retval;
69200@@ -671,7 +671,7 @@ int ptrace_request(struct task_struct *child, long request,
69201 bool seized = child->ptrace & PT_SEIZED;
69202 int ret = -EIO;
69203 siginfo_t siginfo, *si;
69204- void __user *datavp = (void __user *) data;
69205+ void __user *datavp = (__force void __user *) data;
69206 unsigned long __user *datalp = datavp;
69207 unsigned long flags;
69208
69209@@ -873,14 +873,21 @@ SYSCALL_DEFINE4(ptrace, long, request, long, pid, unsigned long, addr,
69210 goto out;
69211 }
69212
69213+ if (gr_handle_ptrace(child, request)) {
69214+ ret = -EPERM;
69215+ goto out_put_task_struct;
69216+ }
69217+
69218 if (request == PTRACE_ATTACH || request == PTRACE_SEIZE) {
69219 ret = ptrace_attach(child, request, addr, data);
69220 /*
69221 * Some architectures need to do book-keeping after
69222 * a ptrace attach.
69223 */
69224- if (!ret)
69225+ if (!ret) {
69226 arch_ptrace_attach(child);
69227+ gr_audit_ptrace(child);
69228+ }
69229 goto out_put_task_struct;
69230 }
69231
69232@@ -906,7 +913,7 @@ int generic_ptrace_peekdata(struct task_struct *tsk, unsigned long addr,
69233 copied = access_process_vm(tsk, addr, &tmp, sizeof(tmp), 0);
69234 if (copied != sizeof(tmp))
69235 return -EIO;
69236- return put_user(tmp, (unsigned long __user *)data);
69237+ return put_user(tmp, (__force unsigned long __user *)data);
69238 }
69239
69240 int generic_ptrace_pokedata(struct task_struct *tsk, unsigned long addr,
69241@@ -1016,14 +1023,21 @@ asmlinkage long compat_sys_ptrace(compat_long_t request, compat_long_t pid,
69242 goto out;
69243 }
69244
69245+ if (gr_handle_ptrace(child, request)) {
69246+ ret = -EPERM;
69247+ goto out_put_task_struct;
69248+ }
69249+
69250 if (request == PTRACE_ATTACH || request == PTRACE_SEIZE) {
69251 ret = ptrace_attach(child, request, addr, data);
69252 /*
69253 * Some architectures need to do book-keeping after
69254 * a ptrace attach.
69255 */
69256- if (!ret)
69257+ if (!ret) {
69258 arch_ptrace_attach(child);
69259+ gr_audit_ptrace(child);
69260+ }
69261 goto out_put_task_struct;
69262 }
69263
69264diff --git a/kernel/rcutiny.c b/kernel/rcutiny.c
69265index 547b1fe..65e874e 100644
69266--- a/kernel/rcutiny.c
69267+++ b/kernel/rcutiny.c
69268@@ -46,7 +46,7 @@
69269 struct rcu_ctrlblk;
69270 static void invoke_rcu_callbacks(void);
69271 static void __rcu_process_callbacks(struct rcu_ctrlblk *rcp);
69272-static void rcu_process_callbacks(struct softirq_action *unused);
69273+static void rcu_process_callbacks(void);
69274 static void __call_rcu(struct rcu_head *head,
69275 void (*func)(struct rcu_head *rcu),
69276 struct rcu_ctrlblk *rcp);
69277@@ -307,7 +307,7 @@ static void __rcu_process_callbacks(struct rcu_ctrlblk *rcp)
69278 rcu_is_callbacks_kthread()));
69279 }
69280
69281-static void rcu_process_callbacks(struct softirq_action *unused)
69282+static void rcu_process_callbacks(void)
69283 {
69284 __rcu_process_callbacks(&rcu_sched_ctrlblk);
69285 __rcu_process_callbacks(&rcu_bh_ctrlblk);
69286diff --git a/kernel/rcutiny_plugin.h b/kernel/rcutiny_plugin.h
69287index 918fd1e..85089bb 100644
69288--- a/kernel/rcutiny_plugin.h
69289+++ b/kernel/rcutiny_plugin.h
69290@@ -893,7 +893,7 @@ static int rcu_kthread(void *arg)
69291 have_rcu_kthread_work = morework;
69292 local_irq_restore(flags);
69293 if (work)
69294- rcu_process_callbacks(NULL);
69295+ rcu_process_callbacks();
69296 schedule_timeout_interruptible(1); /* Leave CPU for others. */
69297 }
69298
69299diff --git a/kernel/rcutorture.c b/kernel/rcutorture.c
69300index 25b1503..1988a74 100644
69301--- a/kernel/rcutorture.c
69302+++ b/kernel/rcutorture.c
69303@@ -162,12 +162,12 @@ static DEFINE_PER_CPU(long [RCU_TORTURE_PIPE_LEN + 1], rcu_torture_count) =
69304 { 0 };
69305 static DEFINE_PER_CPU(long [RCU_TORTURE_PIPE_LEN + 1], rcu_torture_batch) =
69306 { 0 };
69307-static atomic_t rcu_torture_wcount[RCU_TORTURE_PIPE_LEN + 1];
69308-static atomic_t n_rcu_torture_alloc;
69309-static atomic_t n_rcu_torture_alloc_fail;
69310-static atomic_t n_rcu_torture_free;
69311-static atomic_t n_rcu_torture_mberror;
69312-static atomic_t n_rcu_torture_error;
69313+static atomic_unchecked_t rcu_torture_wcount[RCU_TORTURE_PIPE_LEN + 1];
69314+static atomic_unchecked_t n_rcu_torture_alloc;
69315+static atomic_unchecked_t n_rcu_torture_alloc_fail;
69316+static atomic_unchecked_t n_rcu_torture_free;
69317+static atomic_unchecked_t n_rcu_torture_mberror;
69318+static atomic_unchecked_t n_rcu_torture_error;
69319 static long n_rcu_torture_barrier_error;
69320 static long n_rcu_torture_boost_ktrerror;
69321 static long n_rcu_torture_boost_rterror;
69322@@ -265,11 +265,11 @@ rcu_torture_alloc(void)
69323
69324 spin_lock_bh(&rcu_torture_lock);
69325 if (list_empty(&rcu_torture_freelist)) {
69326- atomic_inc(&n_rcu_torture_alloc_fail);
69327+ atomic_inc_unchecked(&n_rcu_torture_alloc_fail);
69328 spin_unlock_bh(&rcu_torture_lock);
69329 return NULL;
69330 }
69331- atomic_inc(&n_rcu_torture_alloc);
69332+ atomic_inc_unchecked(&n_rcu_torture_alloc);
69333 p = rcu_torture_freelist.next;
69334 list_del_init(p);
69335 spin_unlock_bh(&rcu_torture_lock);
69336@@ -282,7 +282,7 @@ rcu_torture_alloc(void)
69337 static void
69338 rcu_torture_free(struct rcu_torture *p)
69339 {
69340- atomic_inc(&n_rcu_torture_free);
69341+ atomic_inc_unchecked(&n_rcu_torture_free);
69342 spin_lock_bh(&rcu_torture_lock);
69343 list_add_tail(&p->rtort_free, &rcu_torture_freelist);
69344 spin_unlock_bh(&rcu_torture_lock);
69345@@ -403,7 +403,7 @@ rcu_torture_cb(struct rcu_head *p)
69346 i = rp->rtort_pipe_count;
69347 if (i > RCU_TORTURE_PIPE_LEN)
69348 i = RCU_TORTURE_PIPE_LEN;
69349- atomic_inc(&rcu_torture_wcount[i]);
69350+ atomic_inc_unchecked(&rcu_torture_wcount[i]);
69351 if (++rp->rtort_pipe_count >= RCU_TORTURE_PIPE_LEN) {
69352 rp->rtort_mbtest = 0;
69353 rcu_torture_free(rp);
69354@@ -452,7 +452,7 @@ static void rcu_sync_torture_deferred_free(struct rcu_torture *p)
69355 i = rp->rtort_pipe_count;
69356 if (i > RCU_TORTURE_PIPE_LEN)
69357 i = RCU_TORTURE_PIPE_LEN;
69358- atomic_inc(&rcu_torture_wcount[i]);
69359+ atomic_inc_unchecked(&rcu_torture_wcount[i]);
69360 if (++rp->rtort_pipe_count >= RCU_TORTURE_PIPE_LEN) {
69361 rp->rtort_mbtest = 0;
69362 list_del(&rp->rtort_free);
69363@@ -995,7 +995,7 @@ rcu_torture_writer(void *arg)
69364 i = old_rp->rtort_pipe_count;
69365 if (i > RCU_TORTURE_PIPE_LEN)
69366 i = RCU_TORTURE_PIPE_LEN;
69367- atomic_inc(&rcu_torture_wcount[i]);
69368+ atomic_inc_unchecked(&rcu_torture_wcount[i]);
69369 old_rp->rtort_pipe_count++;
69370 cur_ops->deferred_free(old_rp);
69371 }
69372@@ -1080,7 +1080,7 @@ static void rcu_torture_timer(unsigned long unused)
69373 }
69374 do_trace_rcu_torture_read(cur_ops->name, &p->rtort_rcu);
69375 if (p->rtort_mbtest == 0)
69376- atomic_inc(&n_rcu_torture_mberror);
69377+ atomic_inc_unchecked(&n_rcu_torture_mberror);
69378 spin_lock(&rand_lock);
69379 cur_ops->read_delay(&rand);
69380 n_rcu_torture_timers++;
69381@@ -1144,7 +1144,7 @@ rcu_torture_reader(void *arg)
69382 }
69383 do_trace_rcu_torture_read(cur_ops->name, &p->rtort_rcu);
69384 if (p->rtort_mbtest == 0)
69385- atomic_inc(&n_rcu_torture_mberror);
69386+ atomic_inc_unchecked(&n_rcu_torture_mberror);
69387 cur_ops->read_delay(&rand);
69388 preempt_disable();
69389 pipe_count = p->rtort_pipe_count;
69390@@ -1203,11 +1203,11 @@ rcu_torture_printk(char *page)
69391 rcu_torture_current,
69392 rcu_torture_current_version,
69393 list_empty(&rcu_torture_freelist),
69394- atomic_read(&n_rcu_torture_alloc),
69395- atomic_read(&n_rcu_torture_alloc_fail),
69396- atomic_read(&n_rcu_torture_free));
69397+ atomic_read_unchecked(&n_rcu_torture_alloc),
69398+ atomic_read_unchecked(&n_rcu_torture_alloc_fail),
69399+ atomic_read_unchecked(&n_rcu_torture_free));
69400 cnt += sprintf(&page[cnt], "rtmbe: %d rtbke: %ld rtbre: %ld ",
69401- atomic_read(&n_rcu_torture_mberror),
69402+ atomic_read_unchecked(&n_rcu_torture_mberror),
69403 n_rcu_torture_boost_ktrerror,
69404 n_rcu_torture_boost_rterror);
69405 cnt += sprintf(&page[cnt], "rtbf: %ld rtb: %ld nt: %ld ",
69406@@ -1224,14 +1224,14 @@ rcu_torture_printk(char *page)
69407 n_barrier_attempts,
69408 n_rcu_torture_barrier_error);
69409 cnt += sprintf(&page[cnt], "\n%s%s ", torture_type, TORTURE_FLAG);
69410- if (atomic_read(&n_rcu_torture_mberror) != 0 ||
69411+ if (atomic_read_unchecked(&n_rcu_torture_mberror) != 0 ||
69412 n_rcu_torture_barrier_error != 0 ||
69413 n_rcu_torture_boost_ktrerror != 0 ||
69414 n_rcu_torture_boost_rterror != 0 ||
69415 n_rcu_torture_boost_failure != 0 ||
69416 i > 1) {
69417 cnt += sprintf(&page[cnt], "!!! ");
69418- atomic_inc(&n_rcu_torture_error);
69419+ atomic_inc_unchecked(&n_rcu_torture_error);
69420 WARN_ON_ONCE(1);
69421 }
69422 cnt += sprintf(&page[cnt], "Reader Pipe: ");
69423@@ -1245,7 +1245,7 @@ rcu_torture_printk(char *page)
69424 cnt += sprintf(&page[cnt], "Free-Block Circulation: ");
69425 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++) {
69426 cnt += sprintf(&page[cnt], " %d",
69427- atomic_read(&rcu_torture_wcount[i]));
69428+ atomic_read_unchecked(&rcu_torture_wcount[i]));
69429 }
69430 cnt += sprintf(&page[cnt], "\n");
69431 if (cur_ops->stats)
69432@@ -1905,7 +1905,7 @@ rcu_torture_cleanup(void)
69433
69434 if (cur_ops->cleanup)
69435 cur_ops->cleanup();
69436- if (atomic_read(&n_rcu_torture_error) || n_rcu_torture_barrier_error)
69437+ if (atomic_read_unchecked(&n_rcu_torture_error) || n_rcu_torture_barrier_error)
69438 rcu_torture_print_module_parms(cur_ops, "End of test: FAILURE");
69439 else if (n_online_successes != n_online_attempts ||
69440 n_offline_successes != n_offline_attempts)
69441@@ -1974,18 +1974,18 @@ rcu_torture_init(void)
69442
69443 rcu_torture_current = NULL;
69444 rcu_torture_current_version = 0;
69445- atomic_set(&n_rcu_torture_alloc, 0);
69446- atomic_set(&n_rcu_torture_alloc_fail, 0);
69447- atomic_set(&n_rcu_torture_free, 0);
69448- atomic_set(&n_rcu_torture_mberror, 0);
69449- atomic_set(&n_rcu_torture_error, 0);
69450+ atomic_set_unchecked(&n_rcu_torture_alloc, 0);
69451+ atomic_set_unchecked(&n_rcu_torture_alloc_fail, 0);
69452+ atomic_set_unchecked(&n_rcu_torture_free, 0);
69453+ atomic_set_unchecked(&n_rcu_torture_mberror, 0);
69454+ atomic_set_unchecked(&n_rcu_torture_error, 0);
69455 n_rcu_torture_barrier_error = 0;
69456 n_rcu_torture_boost_ktrerror = 0;
69457 n_rcu_torture_boost_rterror = 0;
69458 n_rcu_torture_boost_failure = 0;
69459 n_rcu_torture_boosts = 0;
69460 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++)
69461- atomic_set(&rcu_torture_wcount[i], 0);
69462+ atomic_set_unchecked(&rcu_torture_wcount[i], 0);
69463 for_each_possible_cpu(cpu) {
69464 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++) {
69465 per_cpu(rcu_torture_count, cpu)[i] = 0;
69466diff --git a/kernel/rcutree.c b/kernel/rcutree.c
69467index f7bcd9e..8973e14 100644
69468--- a/kernel/rcutree.c
69469+++ b/kernel/rcutree.c
69470@@ -369,9 +369,9 @@ static void rcu_idle_enter_common(struct rcu_dynticks *rdtp, long long oldval)
69471 rcu_prepare_for_idle(smp_processor_id());
69472 /* CPUs seeing atomic_inc() must see prior RCU read-side crit sects */
69473 smp_mb__before_atomic_inc(); /* See above. */
69474- atomic_inc(&rdtp->dynticks);
69475+ atomic_inc_unchecked(&rdtp->dynticks);
69476 smp_mb__after_atomic_inc(); /* Force ordering with next sojourn. */
69477- WARN_ON_ONCE(atomic_read(&rdtp->dynticks) & 0x1);
69478+ WARN_ON_ONCE(atomic_read_unchecked(&rdtp->dynticks) & 0x1);
69479
69480 /*
69481 * The idle task is not permitted to enter the idle loop while
69482@@ -460,10 +460,10 @@ void rcu_irq_exit(void)
69483 static void rcu_idle_exit_common(struct rcu_dynticks *rdtp, long long oldval)
69484 {
69485 smp_mb__before_atomic_inc(); /* Force ordering w/previous sojourn. */
69486- atomic_inc(&rdtp->dynticks);
69487+ atomic_inc_unchecked(&rdtp->dynticks);
69488 /* CPUs seeing atomic_inc() must see later RCU read-side crit sects */
69489 smp_mb__after_atomic_inc(); /* See above. */
69490- WARN_ON_ONCE(!(atomic_read(&rdtp->dynticks) & 0x1));
69491+ WARN_ON_ONCE(!(atomic_read_unchecked(&rdtp->dynticks) & 0x1));
69492 rcu_cleanup_after_idle(smp_processor_id());
69493 trace_rcu_dyntick("End", oldval, rdtp->dynticks_nesting);
69494 if (!is_idle_task(current)) {
69495@@ -557,14 +557,14 @@ void rcu_nmi_enter(void)
69496 struct rcu_dynticks *rdtp = &__get_cpu_var(rcu_dynticks);
69497
69498 if (rdtp->dynticks_nmi_nesting == 0 &&
69499- (atomic_read(&rdtp->dynticks) & 0x1))
69500+ (atomic_read_unchecked(&rdtp->dynticks) & 0x1))
69501 return;
69502 rdtp->dynticks_nmi_nesting++;
69503 smp_mb__before_atomic_inc(); /* Force delay from prior write. */
69504- atomic_inc(&rdtp->dynticks);
69505+ atomic_inc_unchecked(&rdtp->dynticks);
69506 /* CPUs seeing atomic_inc() must see later RCU read-side crit sects */
69507 smp_mb__after_atomic_inc(); /* See above. */
69508- WARN_ON_ONCE(!(atomic_read(&rdtp->dynticks) & 0x1));
69509+ WARN_ON_ONCE(!(atomic_read_unchecked(&rdtp->dynticks) & 0x1));
69510 }
69511
69512 /**
69513@@ -583,9 +583,9 @@ void rcu_nmi_exit(void)
69514 return;
69515 /* CPUs seeing atomic_inc() must see prior RCU read-side crit sects */
69516 smp_mb__before_atomic_inc(); /* See above. */
69517- atomic_inc(&rdtp->dynticks);
69518+ atomic_inc_unchecked(&rdtp->dynticks);
69519 smp_mb__after_atomic_inc(); /* Force delay to next write. */
69520- WARN_ON_ONCE(atomic_read(&rdtp->dynticks) & 0x1);
69521+ WARN_ON_ONCE(atomic_read_unchecked(&rdtp->dynticks) & 0x1);
69522 }
69523
69524 /**
69525@@ -599,7 +599,7 @@ int rcu_is_cpu_idle(void)
69526 int ret;
69527
69528 preempt_disable();
69529- ret = (atomic_read(&__get_cpu_var(rcu_dynticks).dynticks) & 0x1) == 0;
69530+ ret = (atomic_read_unchecked(&__get_cpu_var(rcu_dynticks).dynticks) & 0x1) == 0;
69531 preempt_enable();
69532 return ret;
69533 }
69534@@ -667,7 +667,7 @@ int rcu_is_cpu_rrupt_from_idle(void)
69535 */
69536 static int dyntick_save_progress_counter(struct rcu_data *rdp)
69537 {
69538- rdp->dynticks_snap = atomic_add_return(0, &rdp->dynticks->dynticks);
69539+ rdp->dynticks_snap = atomic_add_return_unchecked(0, &rdp->dynticks->dynticks);
69540 return (rdp->dynticks_snap & 0x1) == 0;
69541 }
69542
69543@@ -682,7 +682,7 @@ static int rcu_implicit_dynticks_qs(struct rcu_data *rdp)
69544 unsigned int curr;
69545 unsigned int snap;
69546
69547- curr = (unsigned int)atomic_add_return(0, &rdp->dynticks->dynticks);
69548+ curr = (unsigned int)atomic_add_return_unchecked(0, &rdp->dynticks->dynticks);
69549 snap = (unsigned int)rdp->dynticks_snap;
69550
69551 /*
69552@@ -712,10 +712,10 @@ static int jiffies_till_stall_check(void)
69553 * for CONFIG_RCU_CPU_STALL_TIMEOUT.
69554 */
69555 if (till_stall_check < 3) {
69556- ACCESS_ONCE(rcu_cpu_stall_timeout) = 3;
69557+ ACCESS_ONCE_RW(rcu_cpu_stall_timeout) = 3;
69558 till_stall_check = 3;
69559 } else if (till_stall_check > 300) {
69560- ACCESS_ONCE(rcu_cpu_stall_timeout) = 300;
69561+ ACCESS_ONCE_RW(rcu_cpu_stall_timeout) = 300;
69562 till_stall_check = 300;
69563 }
69564 return till_stall_check * HZ + RCU_STALL_DELAY_DELTA;
69565@@ -1351,7 +1351,7 @@ rcu_send_cbs_to_orphanage(int cpu, struct rcu_state *rsp,
69566 rsp->qlen += rdp->qlen;
69567 rdp->n_cbs_orphaned += rdp->qlen;
69568 rdp->qlen_lazy = 0;
69569- ACCESS_ONCE(rdp->qlen) = 0;
69570+ ACCESS_ONCE_RW(rdp->qlen) = 0;
69571 }
69572
69573 /*
69574@@ -1604,7 +1604,7 @@ static void rcu_do_batch(struct rcu_state *rsp, struct rcu_data *rdp)
69575 }
69576 smp_mb(); /* List handling before counting for rcu_barrier(). */
69577 rdp->qlen_lazy -= count_lazy;
69578- ACCESS_ONCE(rdp->qlen) -= count;
69579+ ACCESS_ONCE_RW(rdp->qlen) -= count;
69580 rdp->n_cbs_invoked += count;
69581
69582 /* Reinstate batch limit if we have worked down the excess. */
69583@@ -1836,7 +1836,7 @@ __rcu_process_callbacks(struct rcu_state *rsp)
69584 /*
69585 * Do RCU core processing for the current CPU.
69586 */
69587-static void rcu_process_callbacks(struct softirq_action *unused)
69588+static void rcu_process_callbacks(void)
69589 {
69590 struct rcu_state *rsp;
69591
69592@@ -1943,7 +1943,7 @@ __call_rcu(struct rcu_head *head, void (*func)(struct rcu_head *rcu),
69593 rdp = this_cpu_ptr(rsp->rda);
69594
69595 /* Add the callback to our list. */
69596- ACCESS_ONCE(rdp->qlen)++;
69597+ ACCESS_ONCE_RW(rdp->qlen)++;
69598 if (lazy)
69599 rdp->qlen_lazy++;
69600 else
69601@@ -2057,8 +2057,8 @@ void synchronize_rcu_bh(void)
69602 }
69603 EXPORT_SYMBOL_GPL(synchronize_rcu_bh);
69604
69605-static atomic_t sync_sched_expedited_started = ATOMIC_INIT(0);
69606-static atomic_t sync_sched_expedited_done = ATOMIC_INIT(0);
69607+static atomic_unchecked_t sync_sched_expedited_started = ATOMIC_INIT(0);
69608+static atomic_unchecked_t sync_sched_expedited_done = ATOMIC_INIT(0);
69609
69610 static int synchronize_sched_expedited_cpu_stop(void *data)
69611 {
69612@@ -2119,7 +2119,7 @@ void synchronize_sched_expedited(void)
69613 int firstsnap, s, snap, trycount = 0;
69614
69615 /* Note that atomic_inc_return() implies full memory barrier. */
69616- firstsnap = snap = atomic_inc_return(&sync_sched_expedited_started);
69617+ firstsnap = snap = atomic_inc_return_unchecked(&sync_sched_expedited_started);
69618 get_online_cpus();
69619 WARN_ON_ONCE(cpu_is_offline(raw_smp_processor_id()));
69620
69621@@ -2141,7 +2141,7 @@ void synchronize_sched_expedited(void)
69622 }
69623
69624 /* Check to see if someone else did our work for us. */
69625- s = atomic_read(&sync_sched_expedited_done);
69626+ s = atomic_read_unchecked(&sync_sched_expedited_done);
69627 if (UINT_CMP_GE((unsigned)s, (unsigned)firstsnap)) {
69628 smp_mb(); /* ensure test happens before caller kfree */
69629 return;
69630@@ -2156,7 +2156,7 @@ void synchronize_sched_expedited(void)
69631 * grace period works for us.
69632 */
69633 get_online_cpus();
69634- snap = atomic_read(&sync_sched_expedited_started);
69635+ snap = atomic_read_unchecked(&sync_sched_expedited_started);
69636 smp_mb(); /* ensure read is before try_stop_cpus(). */
69637 }
69638
69639@@ -2167,12 +2167,12 @@ void synchronize_sched_expedited(void)
69640 * than we did beat us to the punch.
69641 */
69642 do {
69643- s = atomic_read(&sync_sched_expedited_done);
69644+ s = atomic_read_unchecked(&sync_sched_expedited_done);
69645 if (UINT_CMP_GE((unsigned)s, (unsigned)snap)) {
69646 smp_mb(); /* ensure test happens before caller kfree */
69647 break;
69648 }
69649- } while (atomic_cmpxchg(&sync_sched_expedited_done, s, snap) != s);
69650+ } while (atomic_cmpxchg_unchecked(&sync_sched_expedited_done, s, snap) != s);
69651
69652 put_online_cpus();
69653 }
69654@@ -2366,7 +2366,7 @@ static void _rcu_barrier(struct rcu_state *rsp)
69655 * ACCESS_ONCE() to prevent the compiler from speculating
69656 * the increment to precede the early-exit check.
69657 */
69658- ACCESS_ONCE(rsp->n_barrier_done)++;
69659+ ACCESS_ONCE_RW(rsp->n_barrier_done)++;
69660 WARN_ON_ONCE((rsp->n_barrier_done & 0x1) != 1);
69661 _rcu_barrier_trace(rsp, "Inc1", -1, rsp->n_barrier_done);
69662 smp_mb(); /* Order ->n_barrier_done increment with below mechanism. */
69663@@ -2448,7 +2448,7 @@ static void _rcu_barrier(struct rcu_state *rsp)
69664
69665 /* Increment ->n_barrier_done to prevent duplicate work. */
69666 smp_mb(); /* Keep increment after above mechanism. */
69667- ACCESS_ONCE(rsp->n_barrier_done)++;
69668+ ACCESS_ONCE_RW(rsp->n_barrier_done)++;
69669 WARN_ON_ONCE((rsp->n_barrier_done & 0x1) != 0);
69670 _rcu_barrier_trace(rsp, "Inc2", -1, rsp->n_barrier_done);
69671 smp_mb(); /* Keep increment before caller's subsequent code. */
69672@@ -2495,10 +2495,10 @@ rcu_boot_init_percpu_data(int cpu, struct rcu_state *rsp)
69673 rdp->grpmask = 1UL << (cpu - rdp->mynode->grplo);
69674 init_callback_list(rdp);
69675 rdp->qlen_lazy = 0;
69676- ACCESS_ONCE(rdp->qlen) = 0;
69677+ ACCESS_ONCE_RW(rdp->qlen) = 0;
69678 rdp->dynticks = &per_cpu(rcu_dynticks, cpu);
69679 WARN_ON_ONCE(rdp->dynticks->dynticks_nesting != DYNTICK_TASK_EXIT_IDLE);
69680- WARN_ON_ONCE(atomic_read(&rdp->dynticks->dynticks) != 1);
69681+ WARN_ON_ONCE(atomic_read_unchecked(&rdp->dynticks->dynticks) != 1);
69682 rdp->cpu = cpu;
69683 rdp->rsp = rsp;
69684 raw_spin_unlock_irqrestore(&rnp->lock, flags);
69685@@ -2526,8 +2526,8 @@ rcu_init_percpu_data(int cpu, struct rcu_state *rsp, int preemptible)
69686 rdp->n_force_qs_snap = rsp->n_force_qs;
69687 rdp->blimit = blimit;
69688 rdp->dynticks->dynticks_nesting = DYNTICK_TASK_EXIT_IDLE;
69689- atomic_set(&rdp->dynticks->dynticks,
69690- (atomic_read(&rdp->dynticks->dynticks) & ~0x1) + 1);
69691+ atomic_set_unchecked(&rdp->dynticks->dynticks,
69692+ (atomic_read_unchecked(&rdp->dynticks->dynticks) & ~0x1) + 1);
69693 rcu_prepare_for_idle_init(cpu);
69694 raw_spin_unlock(&rnp->lock); /* irqs remain disabled. */
69695
69696diff --git a/kernel/rcutree.h b/kernel/rcutree.h
69697index 4d29169..d104a3c 100644
69698--- a/kernel/rcutree.h
69699+++ b/kernel/rcutree.h
69700@@ -86,7 +86,7 @@ struct rcu_dynticks {
69701 long long dynticks_nesting; /* Track irq/process nesting level. */
69702 /* Process level is worth LLONG_MAX/2. */
69703 int dynticks_nmi_nesting; /* Track NMI nesting level. */
69704- atomic_t dynticks; /* Even value for idle, else odd. */
69705+ atomic_unchecked_t dynticks;/* Even value for idle, else odd. */
69706 #ifdef CONFIG_RCU_FAST_NO_HZ
69707 int dyntick_drain; /* Prepare-for-idle state variable. */
69708 unsigned long dyntick_holdoff;
69709diff --git a/kernel/rcutree_plugin.h b/kernel/rcutree_plugin.h
69710index 7f3244c..417d606 100644
69711--- a/kernel/rcutree_plugin.h
69712+++ b/kernel/rcutree_plugin.h
69713@@ -843,7 +843,7 @@ void synchronize_rcu_expedited(void)
69714
69715 /* Clean up and exit. */
69716 smp_mb(); /* ensure expedited GP seen before counter increment. */
69717- ACCESS_ONCE(sync_rcu_preempt_exp_count)++;
69718+ ACCESS_ONCE_RW(sync_rcu_preempt_exp_count)++;
69719 unlock_mb_ret:
69720 mutex_unlock(&sync_rcu_preempt_exp_mutex);
69721 mb_ret:
69722diff --git a/kernel/rcutree_trace.c b/kernel/rcutree_trace.c
69723index abffb48..cbfa6d3 100644
69724--- a/kernel/rcutree_trace.c
69725+++ b/kernel/rcutree_trace.c
69726@@ -93,7 +93,7 @@ static void print_one_rcu_data(struct seq_file *m, struct rcu_data *rdp)
69727 rdp->passed_quiesce, rdp->passed_quiesce_gpnum,
69728 rdp->qs_pending);
69729 seq_printf(m, " dt=%d/%llx/%d df=%lu",
69730- atomic_read(&rdp->dynticks->dynticks),
69731+ atomic_read_unchecked(&rdp->dynticks->dynticks),
69732 rdp->dynticks->dynticks_nesting,
69733 rdp->dynticks->dynticks_nmi_nesting,
69734 rdp->dynticks_fqs);
69735@@ -157,7 +157,7 @@ static void print_one_rcu_data_csv(struct seq_file *m, struct rcu_data *rdp)
69736 rdp->passed_quiesce, rdp->passed_quiesce_gpnum,
69737 rdp->qs_pending);
69738 seq_printf(m, ",%d,%llx,%d,%lu",
69739- atomic_read(&rdp->dynticks->dynticks),
69740+ atomic_read_unchecked(&rdp->dynticks->dynticks),
69741 rdp->dynticks->dynticks_nesting,
69742 rdp->dynticks->dynticks_nmi_nesting,
69743 rdp->dynticks_fqs);
69744diff --git a/kernel/resource.c b/kernel/resource.c
69745index 34d4588..10baa6a 100644
69746--- a/kernel/resource.c
69747+++ b/kernel/resource.c
69748@@ -143,8 +143,18 @@ static const struct file_operations proc_iomem_operations = {
69749
69750 static int __init ioresources_init(void)
69751 {
69752+#ifdef CONFIG_GRKERNSEC_PROC_ADD
69753+#ifdef CONFIG_GRKERNSEC_PROC_USER
69754+ proc_create("ioports", S_IRUSR, NULL, &proc_ioports_operations);
69755+ proc_create("iomem", S_IRUSR, NULL, &proc_iomem_operations);
69756+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
69757+ proc_create("ioports", S_IRUSR | S_IRGRP, NULL, &proc_ioports_operations);
69758+ proc_create("iomem", S_IRUSR | S_IRGRP, NULL, &proc_iomem_operations);
69759+#endif
69760+#else
69761 proc_create("ioports", 0, NULL, &proc_ioports_operations);
69762 proc_create("iomem", 0, NULL, &proc_iomem_operations);
69763+#endif
69764 return 0;
69765 }
69766 __initcall(ioresources_init);
69767diff --git a/kernel/rtmutex-tester.c b/kernel/rtmutex-tester.c
69768index 98ec494..4241d6d 100644
69769--- a/kernel/rtmutex-tester.c
69770+++ b/kernel/rtmutex-tester.c
69771@@ -20,7 +20,7 @@
69772 #define MAX_RT_TEST_MUTEXES 8
69773
69774 static spinlock_t rttest_lock;
69775-static atomic_t rttest_event;
69776+static atomic_unchecked_t rttest_event;
69777
69778 struct test_thread_data {
69779 int opcode;
69780@@ -61,7 +61,7 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
69781
69782 case RTTEST_LOCKCONT:
69783 td->mutexes[td->opdata] = 1;
69784- td->event = atomic_add_return(1, &rttest_event);
69785+ td->event = atomic_add_return_unchecked(1, &rttest_event);
69786 return 0;
69787
69788 case RTTEST_RESET:
69789@@ -74,7 +74,7 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
69790 return 0;
69791
69792 case RTTEST_RESETEVENT:
69793- atomic_set(&rttest_event, 0);
69794+ atomic_set_unchecked(&rttest_event, 0);
69795 return 0;
69796
69797 default:
69798@@ -91,9 +91,9 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
69799 return ret;
69800
69801 td->mutexes[id] = 1;
69802- td->event = atomic_add_return(1, &rttest_event);
69803+ td->event = atomic_add_return_unchecked(1, &rttest_event);
69804 rt_mutex_lock(&mutexes[id]);
69805- td->event = atomic_add_return(1, &rttest_event);
69806+ td->event = atomic_add_return_unchecked(1, &rttest_event);
69807 td->mutexes[id] = 4;
69808 return 0;
69809
69810@@ -104,9 +104,9 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
69811 return ret;
69812
69813 td->mutexes[id] = 1;
69814- td->event = atomic_add_return(1, &rttest_event);
69815+ td->event = atomic_add_return_unchecked(1, &rttest_event);
69816 ret = rt_mutex_lock_interruptible(&mutexes[id], 0);
69817- td->event = atomic_add_return(1, &rttest_event);
69818+ td->event = atomic_add_return_unchecked(1, &rttest_event);
69819 td->mutexes[id] = ret ? 0 : 4;
69820 return ret ? -EINTR : 0;
69821
69822@@ -115,9 +115,9 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
69823 if (id < 0 || id >= MAX_RT_TEST_MUTEXES || td->mutexes[id] != 4)
69824 return ret;
69825
69826- td->event = atomic_add_return(1, &rttest_event);
69827+ td->event = atomic_add_return_unchecked(1, &rttest_event);
69828 rt_mutex_unlock(&mutexes[id]);
69829- td->event = atomic_add_return(1, &rttest_event);
69830+ td->event = atomic_add_return_unchecked(1, &rttest_event);
69831 td->mutexes[id] = 0;
69832 return 0;
69833
69834@@ -164,7 +164,7 @@ void schedule_rt_mutex_test(struct rt_mutex *mutex)
69835 break;
69836
69837 td->mutexes[dat] = 2;
69838- td->event = atomic_add_return(1, &rttest_event);
69839+ td->event = atomic_add_return_unchecked(1, &rttest_event);
69840 break;
69841
69842 default:
69843@@ -184,7 +184,7 @@ void schedule_rt_mutex_test(struct rt_mutex *mutex)
69844 return;
69845
69846 td->mutexes[dat] = 3;
69847- td->event = atomic_add_return(1, &rttest_event);
69848+ td->event = atomic_add_return_unchecked(1, &rttest_event);
69849 break;
69850
69851 case RTTEST_LOCKNOWAIT:
69852@@ -196,7 +196,7 @@ void schedule_rt_mutex_test(struct rt_mutex *mutex)
69853 return;
69854
69855 td->mutexes[dat] = 1;
69856- td->event = atomic_add_return(1, &rttest_event);
69857+ td->event = atomic_add_return_unchecked(1, &rttest_event);
69858 return;
69859
69860 default:
69861diff --git a/kernel/sched/auto_group.c b/kernel/sched/auto_group.c
69862index 0984a21..939f183 100644
69863--- a/kernel/sched/auto_group.c
69864+++ b/kernel/sched/auto_group.c
69865@@ -11,7 +11,7 @@
69866
69867 unsigned int __read_mostly sysctl_sched_autogroup_enabled = 1;
69868 static struct autogroup autogroup_default;
69869-static atomic_t autogroup_seq_nr;
69870+static atomic_unchecked_t autogroup_seq_nr;
69871
69872 void __init autogroup_init(struct task_struct *init_task)
69873 {
69874@@ -78,7 +78,7 @@ static inline struct autogroup *autogroup_create(void)
69875
69876 kref_init(&ag->kref);
69877 init_rwsem(&ag->lock);
69878- ag->id = atomic_inc_return(&autogroup_seq_nr);
69879+ ag->id = atomic_inc_return_unchecked(&autogroup_seq_nr);
69880 ag->tg = tg;
69881 #ifdef CONFIG_RT_GROUP_SCHED
69882 /*
69883diff --git a/kernel/sched/core.c b/kernel/sched/core.c
69884index 1a48cdb..d3949ff 100644
69885--- a/kernel/sched/core.c
69886+++ b/kernel/sched/core.c
69887@@ -4103,6 +4103,8 @@ int can_nice(const struct task_struct *p, const int nice)
69888 /* convert nice value [19,-20] to rlimit style value [1,40] */
69889 int nice_rlim = 20 - nice;
69890
69891+ gr_learn_resource(p, RLIMIT_NICE, nice_rlim, 1);
69892+
69893 return (nice_rlim <= task_rlimit(p, RLIMIT_NICE) ||
69894 capable(CAP_SYS_NICE));
69895 }
69896@@ -4136,7 +4138,8 @@ SYSCALL_DEFINE1(nice, int, increment)
69897 if (nice > 19)
69898 nice = 19;
69899
69900- if (increment < 0 && !can_nice(current, nice))
69901+ if (increment < 0 && (!can_nice(current, nice) ||
69902+ gr_handle_chroot_nice()))
69903 return -EPERM;
69904
69905 retval = security_task_setnice(current, nice);
69906@@ -4290,6 +4293,7 @@ recheck:
69907 unsigned long rlim_rtprio =
69908 task_rlimit(p, RLIMIT_RTPRIO);
69909
69910+ gr_learn_resource(p, RLIMIT_RTPRIO, param->sched_priority, 1);
69911 /* can't set/change the rt policy */
69912 if (policy != p->policy && !rlim_rtprio)
69913 return -EPERM;
69914diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c
69915index 96e2b18..bb31eec 100644
69916--- a/kernel/sched/fair.c
69917+++ b/kernel/sched/fair.c
69918@@ -4923,7 +4923,7 @@ static void nohz_idle_balance(int this_cpu, enum cpu_idle_type idle) { }
69919 * run_rebalance_domains is triggered when needed from the scheduler tick.
69920 * Also triggered for nohz idle balancing (with nohz_balancing_kick set).
69921 */
69922-static void run_rebalance_domains(struct softirq_action *h)
69923+static void run_rebalance_domains(void)
69924 {
69925 int this_cpu = smp_processor_id();
69926 struct rq *this_rq = cpu_rq(this_cpu);
69927diff --git a/kernel/signal.c b/kernel/signal.c
69928index be4f856..453401c 100644
69929--- a/kernel/signal.c
69930+++ b/kernel/signal.c
69931@@ -48,12 +48,12 @@ static struct kmem_cache *sigqueue_cachep;
69932
69933 int print_fatal_signals __read_mostly;
69934
69935-static void __user *sig_handler(struct task_struct *t, int sig)
69936+static __sighandler_t sig_handler(struct task_struct *t, int sig)
69937 {
69938 return t->sighand->action[sig - 1].sa.sa_handler;
69939 }
69940
69941-static int sig_handler_ignored(void __user *handler, int sig)
69942+static int sig_handler_ignored(__sighandler_t handler, int sig)
69943 {
69944 /* Is it explicitly or implicitly ignored? */
69945 return handler == SIG_IGN ||
69946@@ -62,7 +62,7 @@ static int sig_handler_ignored(void __user *handler, int sig)
69947
69948 static int sig_task_ignored(struct task_struct *t, int sig, bool force)
69949 {
69950- void __user *handler;
69951+ __sighandler_t handler;
69952
69953 handler = sig_handler(t, sig);
69954
69955@@ -366,6 +366,9 @@ __sigqueue_alloc(int sig, struct task_struct *t, gfp_t flags, int override_rlimi
69956 atomic_inc(&user->sigpending);
69957 rcu_read_unlock();
69958
69959+ if (!override_rlimit)
69960+ gr_learn_resource(t, RLIMIT_SIGPENDING, atomic_read(&user->sigpending), 1);
69961+
69962 if (override_rlimit ||
69963 atomic_read(&user->sigpending) <=
69964 task_rlimit(t, RLIMIT_SIGPENDING)) {
69965@@ -490,7 +493,7 @@ flush_signal_handlers(struct task_struct *t, int force_default)
69966
69967 int unhandled_signal(struct task_struct *tsk, int sig)
69968 {
69969- void __user *handler = tsk->sighand->action[sig-1].sa.sa_handler;
69970+ __sighandler_t handler = tsk->sighand->action[sig-1].sa.sa_handler;
69971 if (is_global_init(tsk))
69972 return 1;
69973 if (handler != SIG_IGN && handler != SIG_DFL)
69974@@ -816,6 +819,13 @@ static int check_kill_permission(int sig, struct siginfo *info,
69975 }
69976 }
69977
69978+ /* allow glibc communication via tgkill to other threads in our
69979+ thread group */
69980+ if ((info == SEND_SIG_NOINFO || info->si_code != SI_TKILL ||
69981+ sig != (SIGRTMIN+1) || task_tgid_vnr(t) != info->si_pid)
69982+ && gr_handle_signal(t, sig))
69983+ return -EPERM;
69984+
69985 return security_task_kill(t, info, sig, 0);
69986 }
69987
69988@@ -1197,7 +1207,7 @@ __group_send_sig_info(int sig, struct siginfo *info, struct task_struct *p)
69989 return send_signal(sig, info, p, 1);
69990 }
69991
69992-static int
69993+int
69994 specific_send_sig_info(int sig, struct siginfo *info, struct task_struct *t)
69995 {
69996 return send_signal(sig, info, t, 0);
69997@@ -1234,6 +1244,7 @@ force_sig_info(int sig, struct siginfo *info, struct task_struct *t)
69998 unsigned long int flags;
69999 int ret, blocked, ignored;
70000 struct k_sigaction *action;
70001+ int is_unhandled = 0;
70002
70003 spin_lock_irqsave(&t->sighand->siglock, flags);
70004 action = &t->sighand->action[sig-1];
70005@@ -1248,9 +1259,18 @@ force_sig_info(int sig, struct siginfo *info, struct task_struct *t)
70006 }
70007 if (action->sa.sa_handler == SIG_DFL)
70008 t->signal->flags &= ~SIGNAL_UNKILLABLE;
70009+ if (action->sa.sa_handler == SIG_IGN || action->sa.sa_handler == SIG_DFL)
70010+ is_unhandled = 1;
70011 ret = specific_send_sig_info(sig, info, t);
70012 spin_unlock_irqrestore(&t->sighand->siglock, flags);
70013
70014+ /* only deal with unhandled signals, java etc trigger SIGSEGV during
70015+ normal operation */
70016+ if (is_unhandled) {
70017+ gr_log_signal(sig, !is_si_special(info) ? info->si_addr : NULL, t);
70018+ gr_handle_crash(t, sig);
70019+ }
70020+
70021 return ret;
70022 }
70023
70024@@ -1317,8 +1337,11 @@ int group_send_sig_info(int sig, struct siginfo *info, struct task_struct *p)
70025 ret = check_kill_permission(sig, info, p);
70026 rcu_read_unlock();
70027
70028- if (!ret && sig)
70029+ if (!ret && sig) {
70030 ret = do_send_sig_info(sig, info, p, true);
70031+ if (!ret)
70032+ gr_log_signal(sig, !is_si_special(info) ? info->si_addr : NULL, p);
70033+ }
70034
70035 return ret;
70036 }
70037@@ -2873,7 +2896,15 @@ do_send_specific(pid_t tgid, pid_t pid, int sig, struct siginfo *info)
70038 int error = -ESRCH;
70039
70040 rcu_read_lock();
70041- p = find_task_by_vpid(pid);
70042+#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
70043+ /* allow glibc communication via tgkill to other threads in our
70044+ thread group */
70045+ if (grsec_enable_chroot_findtask && info->si_code == SI_TKILL &&
70046+ sig == (SIGRTMIN+1) && tgid == info->si_pid)
70047+ p = find_task_by_vpid_unrestricted(pid);
70048+ else
70049+#endif
70050+ p = find_task_by_vpid(pid);
70051 if (p && (tgid <= 0 || task_tgid_vnr(p) == tgid)) {
70052 error = check_kill_permission(sig, info, p);
70053 /*
70054diff --git a/kernel/softirq.c b/kernel/softirq.c
70055index b73e681..645ab62 100644
70056--- a/kernel/softirq.c
70057+++ b/kernel/softirq.c
70058@@ -56,7 +56,7 @@ static struct softirq_action softirq_vec[NR_SOFTIRQS] __cacheline_aligned_in_smp
70059
70060 DEFINE_PER_CPU(struct task_struct *, ksoftirqd);
70061
70062-char *softirq_to_name[NR_SOFTIRQS] = {
70063+const char * const softirq_to_name[NR_SOFTIRQS] = {
70064 "HI", "TIMER", "NET_TX", "NET_RX", "BLOCK", "BLOCK_IOPOLL",
70065 "TASKLET", "SCHED", "HRTIMER", "RCU"
70066 };
70067@@ -243,7 +243,7 @@ restart:
70068 kstat_incr_softirqs_this_cpu(vec_nr);
70069
70070 trace_softirq_entry(vec_nr);
70071- h->action(h);
70072+ h->action();
70073 trace_softirq_exit(vec_nr);
70074 if (unlikely(prev_count != preempt_count())) {
70075 printk(KERN_ERR "huh, entered softirq %u %s %p"
70076@@ -390,9 +390,11 @@ void __raise_softirq_irqoff(unsigned int nr)
70077 or_softirq_pending(1UL << nr);
70078 }
70079
70080-void open_softirq(int nr, void (*action)(struct softirq_action *))
70081+void open_softirq(int nr, void (*action)(void))
70082 {
70083- softirq_vec[nr].action = action;
70084+ pax_open_kernel();
70085+ *(void **)&softirq_vec[nr].action = action;
70086+ pax_close_kernel();
70087 }
70088
70089 /*
70090@@ -446,7 +448,7 @@ void __tasklet_hi_schedule_first(struct tasklet_struct *t)
70091
70092 EXPORT_SYMBOL(__tasklet_hi_schedule_first);
70093
70094-static void tasklet_action(struct softirq_action *a)
70095+static void tasklet_action(void)
70096 {
70097 struct tasklet_struct *list;
70098
70099@@ -481,7 +483,7 @@ static void tasklet_action(struct softirq_action *a)
70100 }
70101 }
70102
70103-static void tasklet_hi_action(struct softirq_action *a)
70104+static void tasklet_hi_action(void)
70105 {
70106 struct tasklet_struct *list;
70107
70108diff --git a/kernel/srcu.c b/kernel/srcu.c
70109index 2095be3..9a5b89d 100644
70110--- a/kernel/srcu.c
70111+++ b/kernel/srcu.c
70112@@ -302,9 +302,9 @@ int __srcu_read_lock(struct srcu_struct *sp)
70113 preempt_disable();
70114 idx = rcu_dereference_index_check(sp->completed,
70115 rcu_read_lock_sched_held()) & 0x1;
70116- ACCESS_ONCE(this_cpu_ptr(sp->per_cpu_ref)->c[idx]) += 1;
70117+ ACCESS_ONCE_RW(this_cpu_ptr(sp->per_cpu_ref)->c[idx]) += 1;
70118 smp_mb(); /* B */ /* Avoid leaking the critical section. */
70119- ACCESS_ONCE(this_cpu_ptr(sp->per_cpu_ref)->seq[idx]) += 1;
70120+ ACCESS_ONCE_RW(this_cpu_ptr(sp->per_cpu_ref)->seq[idx]) += 1;
70121 preempt_enable();
70122 return idx;
70123 }
70124@@ -320,7 +320,7 @@ void __srcu_read_unlock(struct srcu_struct *sp, int idx)
70125 {
70126 preempt_disable();
70127 smp_mb(); /* C */ /* Avoid leaking the critical section. */
70128- ACCESS_ONCE(this_cpu_ptr(sp->per_cpu_ref)->c[idx]) -= 1;
70129+ ACCESS_ONCE_RW(this_cpu_ptr(sp->per_cpu_ref)->c[idx]) -= 1;
70130 preempt_enable();
70131 }
70132 EXPORT_SYMBOL_GPL(__srcu_read_unlock);
70133diff --git a/kernel/sys.c b/kernel/sys.c
70134index 909148a..cd51acf 100644
70135--- a/kernel/sys.c
70136+++ b/kernel/sys.c
70137@@ -157,6 +157,12 @@ static int set_one_prio(struct task_struct *p, int niceval, int error)
70138 error = -EACCES;
70139 goto out;
70140 }
70141+
70142+ if (gr_handle_chroot_setpriority(p, niceval)) {
70143+ error = -EACCES;
70144+ goto out;
70145+ }
70146+
70147 no_nice = security_task_setnice(p, niceval);
70148 if (no_nice) {
70149 error = no_nice;
70150@@ -595,6 +601,9 @@ SYSCALL_DEFINE2(setregid, gid_t, rgid, gid_t, egid)
70151 goto error;
70152 }
70153
70154+ if (gr_check_group_change(new->gid, new->egid, -1))
70155+ goto error;
70156+
70157 if (rgid != (gid_t) -1 ||
70158 (egid != (gid_t) -1 && !gid_eq(kegid, old->gid)))
70159 new->sgid = new->egid;
70160@@ -630,6 +639,10 @@ SYSCALL_DEFINE1(setgid, gid_t, gid)
70161 old = current_cred();
70162
70163 retval = -EPERM;
70164+
70165+ if (gr_check_group_change(kgid, kgid, kgid))
70166+ goto error;
70167+
70168 if (nsown_capable(CAP_SETGID))
70169 new->gid = new->egid = new->sgid = new->fsgid = kgid;
70170 else if (gid_eq(kgid, old->gid) || gid_eq(kgid, old->sgid))
70171@@ -647,7 +660,7 @@ error:
70172 /*
70173 * change the user struct in a credentials set to match the new UID
70174 */
70175-static int set_user(struct cred *new)
70176+int set_user(struct cred *new)
70177 {
70178 struct user_struct *new_user;
70179
70180@@ -727,6 +740,9 @@ SYSCALL_DEFINE2(setreuid, uid_t, ruid, uid_t, euid)
70181 goto error;
70182 }
70183
70184+ if (gr_check_user_change(new->uid, new->euid, -1))
70185+ goto error;
70186+
70187 if (!uid_eq(new->uid, old->uid)) {
70188 retval = set_user(new);
70189 if (retval < 0)
70190@@ -777,6 +793,12 @@ SYSCALL_DEFINE1(setuid, uid_t, uid)
70191 old = current_cred();
70192
70193 retval = -EPERM;
70194+
70195+ if (gr_check_crash_uid(kuid))
70196+ goto error;
70197+ if (gr_check_user_change(kuid, kuid, kuid))
70198+ goto error;
70199+
70200 if (nsown_capable(CAP_SETUID)) {
70201 new->suid = new->uid = kuid;
70202 if (!uid_eq(kuid, old->uid)) {
70203@@ -846,6 +868,9 @@ SYSCALL_DEFINE3(setresuid, uid_t, ruid, uid_t, euid, uid_t, suid)
70204 goto error;
70205 }
70206
70207+ if (gr_check_user_change(kruid, keuid, -1))
70208+ goto error;
70209+
70210 if (ruid != (uid_t) -1) {
70211 new->uid = kruid;
70212 if (!uid_eq(kruid, old->uid)) {
70213@@ -928,6 +953,9 @@ SYSCALL_DEFINE3(setresgid, gid_t, rgid, gid_t, egid, gid_t, sgid)
70214 goto error;
70215 }
70216
70217+ if (gr_check_group_change(krgid, kegid, -1))
70218+ goto error;
70219+
70220 if (rgid != (gid_t) -1)
70221 new->gid = krgid;
70222 if (egid != (gid_t) -1)
70223@@ -981,6 +1009,9 @@ SYSCALL_DEFINE1(setfsuid, uid_t, uid)
70224 if (!uid_valid(kuid))
70225 return old_fsuid;
70226
70227+ if (gr_check_user_change(-1, -1, kuid))
70228+ goto error;
70229+
70230 new = prepare_creds();
70231 if (!new)
70232 return old_fsuid;
70233@@ -995,6 +1026,7 @@ SYSCALL_DEFINE1(setfsuid, uid_t, uid)
70234 }
70235 }
70236
70237+error:
70238 abort_creds(new);
70239 return old_fsuid;
70240
70241@@ -1027,12 +1059,16 @@ SYSCALL_DEFINE1(setfsgid, gid_t, gid)
70242 if (gid_eq(kgid, old->gid) || gid_eq(kgid, old->egid) ||
70243 gid_eq(kgid, old->sgid) || gid_eq(kgid, old->fsgid) ||
70244 nsown_capable(CAP_SETGID)) {
70245+ if (gr_check_group_change(-1, -1, kgid))
70246+ goto error;
70247+
70248 if (!gid_eq(kgid, old->fsgid)) {
70249 new->fsgid = kgid;
70250 goto change_okay;
70251 }
70252 }
70253
70254+error:
70255 abort_creds(new);
70256 return old_fsgid;
70257
70258@@ -1340,19 +1376,19 @@ SYSCALL_DEFINE1(olduname, struct oldold_utsname __user *, name)
70259 return -EFAULT;
70260
70261 down_read(&uts_sem);
70262- error = __copy_to_user(&name->sysname, &utsname()->sysname,
70263+ error = __copy_to_user(name->sysname, &utsname()->sysname,
70264 __OLD_UTS_LEN);
70265 error |= __put_user(0, name->sysname + __OLD_UTS_LEN);
70266- error |= __copy_to_user(&name->nodename, &utsname()->nodename,
70267+ error |= __copy_to_user(name->nodename, &utsname()->nodename,
70268 __OLD_UTS_LEN);
70269 error |= __put_user(0, name->nodename + __OLD_UTS_LEN);
70270- error |= __copy_to_user(&name->release, &utsname()->release,
70271+ error |= __copy_to_user(name->release, &utsname()->release,
70272 __OLD_UTS_LEN);
70273 error |= __put_user(0, name->release + __OLD_UTS_LEN);
70274- error |= __copy_to_user(&name->version, &utsname()->version,
70275+ error |= __copy_to_user(name->version, &utsname()->version,
70276 __OLD_UTS_LEN);
70277 error |= __put_user(0, name->version + __OLD_UTS_LEN);
70278- error |= __copy_to_user(&name->machine, &utsname()->machine,
70279+ error |= __copy_to_user(name->machine, &utsname()->machine,
70280 __OLD_UTS_LEN);
70281 error |= __put_user(0, name->machine + __OLD_UTS_LEN);
70282 up_read(&uts_sem);
70283@@ -2026,7 +2062,7 @@ SYSCALL_DEFINE5(prctl, int, option, unsigned long, arg2, unsigned long, arg3,
70284 error = get_dumpable(me->mm);
70285 break;
70286 case PR_SET_DUMPABLE:
70287- if (arg2 < 0 || arg2 > 1) {
70288+ if (arg2 > 1) {
70289 error = -EINVAL;
70290 break;
70291 }
70292diff --git a/kernel/sysctl.c b/kernel/sysctl.c
70293index 87174ef..68cbb82 100644
70294--- a/kernel/sysctl.c
70295+++ b/kernel/sysctl.c
70296@@ -92,7 +92,6 @@
70297
70298
70299 #if defined(CONFIG_SYSCTL)
70300-
70301 /* External variables not in a header file. */
70302 extern int sysctl_overcommit_memory;
70303 extern int sysctl_overcommit_ratio;
70304@@ -170,10 +169,8 @@ static int proc_taint(struct ctl_table *table, int write,
70305 void __user *buffer, size_t *lenp, loff_t *ppos);
70306 #endif
70307
70308-#ifdef CONFIG_PRINTK
70309 static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
70310 void __user *buffer, size_t *lenp, loff_t *ppos);
70311-#endif
70312
70313 static int proc_dointvec_minmax_coredump(struct ctl_table *table, int write,
70314 void __user *buffer, size_t *lenp, loff_t *ppos);
70315@@ -202,6 +199,8 @@ static int sysrq_sysctl_handler(ctl_table *table, int write,
70316
70317 #endif
70318
70319+extern struct ctl_table grsecurity_table[];
70320+
70321 static struct ctl_table kern_table[];
70322 static struct ctl_table vm_table[];
70323 static struct ctl_table fs_table[];
70324@@ -216,6 +215,20 @@ extern struct ctl_table epoll_table[];
70325 int sysctl_legacy_va_layout;
70326 #endif
70327
70328+#ifdef CONFIG_PAX_SOFTMODE
70329+static ctl_table pax_table[] = {
70330+ {
70331+ .procname = "softmode",
70332+ .data = &pax_softmode,
70333+ .maxlen = sizeof(unsigned int),
70334+ .mode = 0600,
70335+ .proc_handler = &proc_dointvec,
70336+ },
70337+
70338+ { }
70339+};
70340+#endif
70341+
70342 /* The default sysctl tables: */
70343
70344 static struct ctl_table sysctl_base_table[] = {
70345@@ -262,6 +275,22 @@ static int max_extfrag_threshold = 1000;
70346 #endif
70347
70348 static struct ctl_table kern_table[] = {
70349+#if defined(CONFIG_GRKERNSEC_SYSCTL) || defined(CONFIG_GRKERNSEC_ROFS)
70350+ {
70351+ .procname = "grsecurity",
70352+ .mode = 0500,
70353+ .child = grsecurity_table,
70354+ },
70355+#endif
70356+
70357+#ifdef CONFIG_PAX_SOFTMODE
70358+ {
70359+ .procname = "pax",
70360+ .mode = 0500,
70361+ .child = pax_table,
70362+ },
70363+#endif
70364+
70365 {
70366 .procname = "sched_child_runs_first",
70367 .data = &sysctl_sched_child_runs_first,
70368@@ -546,7 +575,7 @@ static struct ctl_table kern_table[] = {
70369 .data = &modprobe_path,
70370 .maxlen = KMOD_PATH_LEN,
70371 .mode = 0644,
70372- .proc_handler = proc_dostring,
70373+ .proc_handler = proc_dostring_modpriv,
70374 },
70375 {
70376 .procname = "modules_disabled",
70377@@ -713,16 +742,20 @@ static struct ctl_table kern_table[] = {
70378 .extra1 = &zero,
70379 .extra2 = &one,
70380 },
70381+#endif
70382 {
70383 .procname = "kptr_restrict",
70384 .data = &kptr_restrict,
70385 .maxlen = sizeof(int),
70386 .mode = 0644,
70387 .proc_handler = proc_dointvec_minmax_sysadmin,
70388+#ifdef CONFIG_GRKERNSEC_HIDESYM
70389+ .extra1 = &two,
70390+#else
70391 .extra1 = &zero,
70392+#endif
70393 .extra2 = &two,
70394 },
70395-#endif
70396 {
70397 .procname = "ngroups_max",
70398 .data = &ngroups_max,
70399@@ -1219,6 +1252,13 @@ static struct ctl_table vm_table[] = {
70400 .proc_handler = proc_dointvec_minmax,
70401 .extra1 = &zero,
70402 },
70403+ {
70404+ .procname = "heap_stack_gap",
70405+ .data = &sysctl_heap_stack_gap,
70406+ .maxlen = sizeof(sysctl_heap_stack_gap),
70407+ .mode = 0644,
70408+ .proc_handler = proc_doulongvec_minmax,
70409+ },
70410 #else
70411 {
70412 .procname = "nr_trim_pages",
70413@@ -1670,6 +1710,16 @@ int proc_dostring(struct ctl_table *table, int write,
70414 buffer, lenp, ppos);
70415 }
70416
70417+int proc_dostring_modpriv(struct ctl_table *table, int write,
70418+ void __user *buffer, size_t *lenp, loff_t *ppos)
70419+{
70420+ if (write && !capable(CAP_SYS_MODULE))
70421+ return -EPERM;
70422+
70423+ return _proc_do_string(table->data, table->maxlen, write,
70424+ buffer, lenp, ppos);
70425+}
70426+
70427 static size_t proc_skip_spaces(char **buf)
70428 {
70429 size_t ret;
70430@@ -1775,6 +1825,8 @@ static int proc_put_long(void __user **buf, size_t *size, unsigned long val,
70431 len = strlen(tmp);
70432 if (len > *size)
70433 len = *size;
70434+ if (len > sizeof(tmp))
70435+ len = sizeof(tmp);
70436 if (copy_to_user(*buf, tmp, len))
70437 return -EFAULT;
70438 *size -= len;
70439@@ -1967,7 +2019,6 @@ static int proc_taint(struct ctl_table *table, int write,
70440 return err;
70441 }
70442
70443-#ifdef CONFIG_PRINTK
70444 static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
70445 void __user *buffer, size_t *lenp, loff_t *ppos)
70446 {
70447@@ -1976,7 +2027,6 @@ static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
70448
70449 return proc_dointvec_minmax(table, write, buffer, lenp, ppos);
70450 }
70451-#endif
70452
70453 struct do_proc_dointvec_minmax_conv_param {
70454 int *min;
70455@@ -2119,8 +2169,11 @@ static int __do_proc_doulongvec_minmax(void *data, struct ctl_table *table, int
70456 *i = val;
70457 } else {
70458 val = convdiv * (*i) / convmul;
70459- if (!first)
70460+ if (!first) {
70461 err = proc_put_char(&buffer, &left, '\t');
70462+ if (err)
70463+ break;
70464+ }
70465 err = proc_put_long(&buffer, &left, val, false);
70466 if (err)
70467 break;
70468@@ -2512,6 +2565,12 @@ int proc_dostring(struct ctl_table *table, int write,
70469 return -ENOSYS;
70470 }
70471
70472+int proc_dostring_modpriv(struct ctl_table *table, int write,
70473+ void __user *buffer, size_t *lenp, loff_t *ppos)
70474+{
70475+ return -ENOSYS;
70476+}
70477+
70478 int proc_dointvec(struct ctl_table *table, int write,
70479 void __user *buffer, size_t *lenp, loff_t *ppos)
70480 {
70481@@ -2568,5 +2627,6 @@ EXPORT_SYMBOL(proc_dointvec_minmax);
70482 EXPORT_SYMBOL(proc_dointvec_userhz_jiffies);
70483 EXPORT_SYMBOL(proc_dointvec_ms_jiffies);
70484 EXPORT_SYMBOL(proc_dostring);
70485+EXPORT_SYMBOL(proc_dostring_modpriv);
70486 EXPORT_SYMBOL(proc_doulongvec_minmax);
70487 EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax);
70488diff --git a/kernel/sysctl_binary.c b/kernel/sysctl_binary.c
70489index 65bdcf1..21eb831 100644
70490--- a/kernel/sysctl_binary.c
70491+++ b/kernel/sysctl_binary.c
70492@@ -989,7 +989,7 @@ static ssize_t bin_intvec(struct file *file,
70493 int i;
70494
70495 set_fs(KERNEL_DS);
70496- result = vfs_read(file, buffer, BUFSZ - 1, &pos);
70497+ result = vfs_read(file, (char __force_user *)buffer, BUFSZ - 1, &pos);
70498 set_fs(old_fs);
70499 if (result < 0)
70500 goto out_kfree;
70501@@ -1034,7 +1034,7 @@ static ssize_t bin_intvec(struct file *file,
70502 }
70503
70504 set_fs(KERNEL_DS);
70505- result = vfs_write(file, buffer, str - buffer, &pos);
70506+ result = vfs_write(file, (const char __force_user *)buffer, str - buffer, &pos);
70507 set_fs(old_fs);
70508 if (result < 0)
70509 goto out_kfree;
70510@@ -1067,7 +1067,7 @@ static ssize_t bin_ulongvec(struct file *file,
70511 int i;
70512
70513 set_fs(KERNEL_DS);
70514- result = vfs_read(file, buffer, BUFSZ - 1, &pos);
70515+ result = vfs_read(file, (char __force_user *)buffer, BUFSZ - 1, &pos);
70516 set_fs(old_fs);
70517 if (result < 0)
70518 goto out_kfree;
70519@@ -1112,7 +1112,7 @@ static ssize_t bin_ulongvec(struct file *file,
70520 }
70521
70522 set_fs(KERNEL_DS);
70523- result = vfs_write(file, buffer, str - buffer, &pos);
70524+ result = vfs_write(file, (const char __force_user *)buffer, str - buffer, &pos);
70525 set_fs(old_fs);
70526 if (result < 0)
70527 goto out_kfree;
70528@@ -1138,7 +1138,7 @@ static ssize_t bin_uuid(struct file *file,
70529 int i;
70530
70531 set_fs(KERNEL_DS);
70532- result = vfs_read(file, buf, sizeof(buf) - 1, &pos);
70533+ result = vfs_read(file, (char __force_user *)buf, sizeof(buf) - 1, &pos);
70534 set_fs(old_fs);
70535 if (result < 0)
70536 goto out;
70537@@ -1185,7 +1185,7 @@ static ssize_t bin_dn_node_address(struct file *file,
70538 __le16 dnaddr;
70539
70540 set_fs(KERNEL_DS);
70541- result = vfs_read(file, buf, sizeof(buf) - 1, &pos);
70542+ result = vfs_read(file, (char __force_user *)buf, sizeof(buf) - 1, &pos);
70543 set_fs(old_fs);
70544 if (result < 0)
70545 goto out;
70546@@ -1233,7 +1233,7 @@ static ssize_t bin_dn_node_address(struct file *file,
70547 le16_to_cpu(dnaddr) & 0x3ff);
70548
70549 set_fs(KERNEL_DS);
70550- result = vfs_write(file, buf, len, &pos);
70551+ result = vfs_write(file, (const char __force_user *)buf, len, &pos);
70552 set_fs(old_fs);
70553 if (result < 0)
70554 goto out;
70555diff --git a/kernel/taskstats.c b/kernel/taskstats.c
70556index d0a3279..db0ad99 100644
70557--- a/kernel/taskstats.c
70558+++ b/kernel/taskstats.c
70559@@ -27,9 +27,12 @@
70560 #include <linux/cgroup.h>
70561 #include <linux/fs.h>
70562 #include <linux/file.h>
70563+#include <linux/grsecurity.h>
70564 #include <net/genetlink.h>
70565 #include <linux/atomic.h>
70566
70567+extern int gr_is_taskstats_denied(int pid);
70568+
70569 /*
70570 * Maximum length of a cpumask that can be specified in
70571 * the TASKSTATS_CMD_ATTR_REGISTER/DEREGISTER_CPUMASK attribute
70572@@ -561,6 +564,9 @@ err:
70573
70574 static int taskstats_user_cmd(struct sk_buff *skb, struct genl_info *info)
70575 {
70576+ if (gr_is_taskstats_denied(current->pid))
70577+ return -EACCES;
70578+
70579 if (info->attrs[TASKSTATS_CMD_ATTR_REGISTER_CPUMASK])
70580 return cmd_attr_register_cpumask(info);
70581 else if (info->attrs[TASKSTATS_CMD_ATTR_DEREGISTER_CPUMASK])
70582diff --git a/kernel/time.c b/kernel/time.c
70583index ba744cf..267b7c5 100644
70584--- a/kernel/time.c
70585+++ b/kernel/time.c
70586@@ -163,6 +163,11 @@ int do_sys_settimeofday(const struct timespec *tv, const struct timezone *tz)
70587 return error;
70588
70589 if (tz) {
70590+ /* we log in do_settimeofday called below, so don't log twice
70591+ */
70592+ if (!tv)
70593+ gr_log_timechange();
70594+
70595 sys_tz = *tz;
70596 update_vsyscall_tz();
70597 if (firsttime) {
70598diff --git a/kernel/time/alarmtimer.c b/kernel/time/alarmtimer.c
70599index aa27d39..34d221c 100644
70600--- a/kernel/time/alarmtimer.c
70601+++ b/kernel/time/alarmtimer.c
70602@@ -779,7 +779,7 @@ static int __init alarmtimer_init(void)
70603 struct platform_device *pdev;
70604 int error = 0;
70605 int i;
70606- struct k_clock alarm_clock = {
70607+ static struct k_clock alarm_clock = {
70608 .clock_getres = alarm_clock_getres,
70609 .clock_get = alarm_clock_get,
70610 .timer_create = alarm_timer_create,
70611diff --git a/kernel/time/tick-broadcast.c b/kernel/time/tick-broadcast.c
70612index f113755..ec24223 100644
70613--- a/kernel/time/tick-broadcast.c
70614+++ b/kernel/time/tick-broadcast.c
70615@@ -115,7 +115,7 @@ int tick_device_uses_broadcast(struct clock_event_device *dev, int cpu)
70616 * then clear the broadcast bit.
70617 */
70618 if (!(dev->features & CLOCK_EVT_FEAT_C3STOP)) {
70619- int cpu = smp_processor_id();
70620+ cpu = smp_processor_id();
70621
70622 cpumask_clear_cpu(cpu, tick_get_broadcast_mask());
70623 tick_broadcast_clear_oneshot(cpu);
70624diff --git a/kernel/time/timekeeping.c b/kernel/time/timekeeping.c
70625index f791637..00051de 100644
70626--- a/kernel/time/timekeeping.c
70627+++ b/kernel/time/timekeeping.c
70628@@ -14,6 +14,7 @@
70629 #include <linux/init.h>
70630 #include <linux/mm.h>
70631 #include <linux/sched.h>
70632+#include <linux/grsecurity.h>
70633 #include <linux/syscore_ops.h>
70634 #include <linux/clocksource.h>
70635 #include <linux/jiffies.h>
70636@@ -434,6 +435,8 @@ int do_settimeofday(const struct timespec *tv)
70637 if (!timespec_valid_strict(tv))
70638 return -EINVAL;
70639
70640+ gr_log_timechange();
70641+
70642 write_seqlock_irqsave(&tk->lock, flags);
70643
70644 timekeeping_forward_now(tk);
70645diff --git a/kernel/time/timer_list.c b/kernel/time/timer_list.c
70646index af5a7e9..715611a 100644
70647--- a/kernel/time/timer_list.c
70648+++ b/kernel/time/timer_list.c
70649@@ -38,12 +38,16 @@ DECLARE_PER_CPU(struct hrtimer_cpu_base, hrtimer_bases);
70650
70651 static void print_name_offset(struct seq_file *m, void *sym)
70652 {
70653+#ifdef CONFIG_GRKERNSEC_HIDESYM
70654+ SEQ_printf(m, "<%p>", NULL);
70655+#else
70656 char symname[KSYM_NAME_LEN];
70657
70658 if (lookup_symbol_name((unsigned long)sym, symname) < 0)
70659 SEQ_printf(m, "<%pK>", sym);
70660 else
70661 SEQ_printf(m, "%s", symname);
70662+#endif
70663 }
70664
70665 static void
70666@@ -112,7 +116,11 @@ next_one:
70667 static void
70668 print_base(struct seq_file *m, struct hrtimer_clock_base *base, u64 now)
70669 {
70670+#ifdef CONFIG_GRKERNSEC_HIDESYM
70671+ SEQ_printf(m, " .base: %p\n", NULL);
70672+#else
70673 SEQ_printf(m, " .base: %pK\n", base);
70674+#endif
70675 SEQ_printf(m, " .index: %d\n",
70676 base->index);
70677 SEQ_printf(m, " .resolution: %Lu nsecs\n",
70678@@ -293,7 +301,11 @@ static int __init init_timer_list_procfs(void)
70679 {
70680 struct proc_dir_entry *pe;
70681
70682+#ifdef CONFIG_GRKERNSEC_PROC_ADD
70683+ pe = proc_create("timer_list", 0400, NULL, &timer_list_fops);
70684+#else
70685 pe = proc_create("timer_list", 0444, NULL, &timer_list_fops);
70686+#endif
70687 if (!pe)
70688 return -ENOMEM;
70689 return 0;
70690diff --git a/kernel/time/timer_stats.c b/kernel/time/timer_stats.c
70691index 0b537f2..40d6c20 100644
70692--- a/kernel/time/timer_stats.c
70693+++ b/kernel/time/timer_stats.c
70694@@ -116,7 +116,7 @@ static ktime_t time_start, time_stop;
70695 static unsigned long nr_entries;
70696 static struct entry entries[MAX_ENTRIES];
70697
70698-static atomic_t overflow_count;
70699+static atomic_unchecked_t overflow_count;
70700
70701 /*
70702 * The entries are in a hash-table, for fast lookup:
70703@@ -140,7 +140,7 @@ static void reset_entries(void)
70704 nr_entries = 0;
70705 memset(entries, 0, sizeof(entries));
70706 memset(tstat_hash_table, 0, sizeof(tstat_hash_table));
70707- atomic_set(&overflow_count, 0);
70708+ atomic_set_unchecked(&overflow_count, 0);
70709 }
70710
70711 static struct entry *alloc_entry(void)
70712@@ -261,7 +261,7 @@ void timer_stats_update_stats(void *timer, pid_t pid, void *startf,
70713 if (likely(entry))
70714 entry->count++;
70715 else
70716- atomic_inc(&overflow_count);
70717+ atomic_inc_unchecked(&overflow_count);
70718
70719 out_unlock:
70720 raw_spin_unlock_irqrestore(lock, flags);
70721@@ -269,12 +269,16 @@ void timer_stats_update_stats(void *timer, pid_t pid, void *startf,
70722
70723 static void print_name_offset(struct seq_file *m, unsigned long addr)
70724 {
70725+#ifdef CONFIG_GRKERNSEC_HIDESYM
70726+ seq_printf(m, "<%p>", NULL);
70727+#else
70728 char symname[KSYM_NAME_LEN];
70729
70730 if (lookup_symbol_name(addr, symname) < 0)
70731- seq_printf(m, "<%p>", (void *)addr);
70732+ seq_printf(m, "<%pK>", (void *)addr);
70733 else
70734 seq_printf(m, "%s", symname);
70735+#endif
70736 }
70737
70738 static int tstats_show(struct seq_file *m, void *v)
70739@@ -300,9 +304,9 @@ static int tstats_show(struct seq_file *m, void *v)
70740
70741 seq_puts(m, "Timer Stats Version: v0.2\n");
70742 seq_printf(m, "Sample period: %ld.%03ld s\n", period.tv_sec, ms);
70743- if (atomic_read(&overflow_count))
70744+ if (atomic_read_unchecked(&overflow_count))
70745 seq_printf(m, "Overflow: %d entries\n",
70746- atomic_read(&overflow_count));
70747+ atomic_read_unchecked(&overflow_count));
70748
70749 for (i = 0; i < nr_entries; i++) {
70750 entry = entries + i;
70751@@ -417,7 +421,11 @@ static int __init init_tstats_procfs(void)
70752 {
70753 struct proc_dir_entry *pe;
70754
70755+#ifdef CONFIG_GRKERNSEC_PROC_ADD
70756+ pe = proc_create("timer_stats", 0600, NULL, &tstats_fops);
70757+#else
70758 pe = proc_create("timer_stats", 0644, NULL, &tstats_fops);
70759+#endif
70760 if (!pe)
70761 return -ENOMEM;
70762 return 0;
70763diff --git a/kernel/timer.c b/kernel/timer.c
70764index 46ef2b1..ad081f144 100644
70765--- a/kernel/timer.c
70766+++ b/kernel/timer.c
70767@@ -1377,7 +1377,7 @@ void update_process_times(int user_tick)
70768 /*
70769 * This function runs timers and the timer-tq in bottom half context.
70770 */
70771-static void run_timer_softirq(struct softirq_action *h)
70772+static void run_timer_softirq(void)
70773 {
70774 struct tvec_base *base = __this_cpu_read(tvec_bases);
70775
70776diff --git a/kernel/trace/blktrace.c b/kernel/trace/blktrace.c
70777index c0bd030..62a1927 100644
70778--- a/kernel/trace/blktrace.c
70779+++ b/kernel/trace/blktrace.c
70780@@ -317,7 +317,7 @@ static ssize_t blk_dropped_read(struct file *filp, char __user *buffer,
70781 struct blk_trace *bt = filp->private_data;
70782 char buf[16];
70783
70784- snprintf(buf, sizeof(buf), "%u\n", atomic_read(&bt->dropped));
70785+ snprintf(buf, sizeof(buf), "%u\n", atomic_read_unchecked(&bt->dropped));
70786
70787 return simple_read_from_buffer(buffer, count, ppos, buf, strlen(buf));
70788 }
70789@@ -375,7 +375,7 @@ static int blk_subbuf_start_callback(struct rchan_buf *buf, void *subbuf,
70790 return 1;
70791
70792 bt = buf->chan->private_data;
70793- atomic_inc(&bt->dropped);
70794+ atomic_inc_unchecked(&bt->dropped);
70795 return 0;
70796 }
70797
70798@@ -476,7 +476,7 @@ int do_blk_trace_setup(struct request_queue *q, char *name, dev_t dev,
70799
70800 bt->dir = dir;
70801 bt->dev = dev;
70802- atomic_set(&bt->dropped, 0);
70803+ atomic_set_unchecked(&bt->dropped, 0);
70804
70805 ret = -EIO;
70806 bt->dropped_file = debugfs_create_file("dropped", 0444, dir, bt,
70807diff --git a/kernel/trace/ftrace.c b/kernel/trace/ftrace.c
70808index b4f20fb..483c5fa 100644
70809--- a/kernel/trace/ftrace.c
70810+++ b/kernel/trace/ftrace.c
70811@@ -1785,12 +1785,17 @@ ftrace_code_disable(struct module *mod, struct dyn_ftrace *rec)
70812 if (unlikely(ftrace_disabled))
70813 return 0;
70814
70815+ ret = ftrace_arch_code_modify_prepare();
70816+ FTRACE_WARN_ON(ret);
70817+ if (ret)
70818+ return 0;
70819+
70820 ret = ftrace_make_nop(mod, rec, MCOUNT_ADDR);
70821+ FTRACE_WARN_ON(ftrace_arch_code_modify_post_process());
70822 if (ret) {
70823 ftrace_bug(ret, ip);
70824- return 0;
70825 }
70826- return 1;
70827+ return ret ? 0 : 1;
70828 }
70829
70830 /*
70831@@ -2885,7 +2890,7 @@ static void ftrace_free_entry_rcu(struct rcu_head *rhp)
70832
70833 int
70834 register_ftrace_function_probe(char *glob, struct ftrace_probe_ops *ops,
70835- void *data)
70836+ void *data)
70837 {
70838 struct ftrace_func_probe *entry;
70839 struct ftrace_page *pg;
70840@@ -3697,8 +3702,10 @@ static int ftrace_process_locs(struct module *mod,
70841 if (!count)
70842 return 0;
70843
70844+ pax_open_kernel();
70845 sort(start, count, sizeof(*start),
70846 ftrace_cmp_ips, ftrace_swap_ips);
70847+ pax_close_kernel();
70848
70849 start_pg = ftrace_allocate_pages(count);
70850 if (!start_pg)
70851diff --git a/kernel/trace/trace.c b/kernel/trace/trace.c
70852index 5c38c81..88012af 100644
70853--- a/kernel/trace/trace.c
70854+++ b/kernel/trace/trace.c
70855@@ -4437,10 +4437,9 @@ static const struct file_operations tracing_dyn_info_fops = {
70856 };
70857 #endif
70858
70859-static struct dentry *d_tracer;
70860-
70861 struct dentry *tracing_init_dentry(void)
70862 {
70863+ static struct dentry *d_tracer;
70864 static int once;
70865
70866 if (d_tracer)
70867@@ -4460,10 +4459,9 @@ struct dentry *tracing_init_dentry(void)
70868 return d_tracer;
70869 }
70870
70871-static struct dentry *d_percpu;
70872-
70873 struct dentry *tracing_dentry_percpu(void)
70874 {
70875+ static struct dentry *d_percpu;
70876 static int once;
70877 struct dentry *d_tracer;
70878
70879diff --git a/kernel/trace/trace_events.c b/kernel/trace/trace_events.c
70880index 29111da..d190fe2 100644
70881--- a/kernel/trace/trace_events.c
70882+++ b/kernel/trace/trace_events.c
70883@@ -1308,10 +1308,6 @@ static LIST_HEAD(ftrace_module_file_list);
70884 struct ftrace_module_file_ops {
70885 struct list_head list;
70886 struct module *mod;
70887- struct file_operations id;
70888- struct file_operations enable;
70889- struct file_operations format;
70890- struct file_operations filter;
70891 };
70892
70893 static struct ftrace_module_file_ops *
70894@@ -1332,17 +1328,12 @@ trace_create_file_ops(struct module *mod)
70895
70896 file_ops->mod = mod;
70897
70898- file_ops->id = ftrace_event_id_fops;
70899- file_ops->id.owner = mod;
70900-
70901- file_ops->enable = ftrace_enable_fops;
70902- file_ops->enable.owner = mod;
70903-
70904- file_ops->filter = ftrace_event_filter_fops;
70905- file_ops->filter.owner = mod;
70906-
70907- file_ops->format = ftrace_event_format_fops;
70908- file_ops->format.owner = mod;
70909+ pax_open_kernel();
70910+ *(void **)&mod->trace_id.owner = mod;
70911+ *(void **)&mod->trace_enable.owner = mod;
70912+ *(void **)&mod->trace_filter.owner = mod;
70913+ *(void **)&mod->trace_format.owner = mod;
70914+ pax_close_kernel();
70915
70916 list_add(&file_ops->list, &ftrace_module_file_list);
70917
70918@@ -1366,8 +1357,8 @@ static void trace_module_add_events(struct module *mod)
70919
70920 for_each_event(call, start, end) {
70921 __trace_add_event_call(*call, mod,
70922- &file_ops->id, &file_ops->enable,
70923- &file_ops->filter, &file_ops->format);
70924+ &mod->trace_id, &mod->trace_enable,
70925+ &mod->trace_filter, &mod->trace_format);
70926 }
70927 }
70928
70929diff --git a/kernel/trace/trace_mmiotrace.c b/kernel/trace/trace_mmiotrace.c
70930index fd3c8aa..5f324a6 100644
70931--- a/kernel/trace/trace_mmiotrace.c
70932+++ b/kernel/trace/trace_mmiotrace.c
70933@@ -24,7 +24,7 @@ struct header_iter {
70934 static struct trace_array *mmio_trace_array;
70935 static bool overrun_detected;
70936 static unsigned long prev_overruns;
70937-static atomic_t dropped_count;
70938+static atomic_unchecked_t dropped_count;
70939
70940 static void mmio_reset_data(struct trace_array *tr)
70941 {
70942@@ -127,7 +127,7 @@ static void mmio_close(struct trace_iterator *iter)
70943
70944 static unsigned long count_overruns(struct trace_iterator *iter)
70945 {
70946- unsigned long cnt = atomic_xchg(&dropped_count, 0);
70947+ unsigned long cnt = atomic_xchg_unchecked(&dropped_count, 0);
70948 unsigned long over = ring_buffer_overruns(iter->tr->buffer);
70949
70950 if (over > prev_overruns)
70951@@ -317,7 +317,7 @@ static void __trace_mmiotrace_rw(struct trace_array *tr,
70952 event = trace_buffer_lock_reserve(buffer, TRACE_MMIO_RW,
70953 sizeof(*entry), 0, pc);
70954 if (!event) {
70955- atomic_inc(&dropped_count);
70956+ atomic_inc_unchecked(&dropped_count);
70957 return;
70958 }
70959 entry = ring_buffer_event_data(event);
70960@@ -347,7 +347,7 @@ static void __trace_mmiotrace_map(struct trace_array *tr,
70961 event = trace_buffer_lock_reserve(buffer, TRACE_MMIO_MAP,
70962 sizeof(*entry), 0, pc);
70963 if (!event) {
70964- atomic_inc(&dropped_count);
70965+ atomic_inc_unchecked(&dropped_count);
70966 return;
70967 }
70968 entry = ring_buffer_event_data(event);
70969diff --git a/kernel/trace/trace_output.c b/kernel/trace/trace_output.c
70970index 123b189..97b81f5 100644
70971--- a/kernel/trace/trace_output.c
70972+++ b/kernel/trace/trace_output.c
70973@@ -278,7 +278,7 @@ int trace_seq_path(struct trace_seq *s, const struct path *path)
70974
70975 p = d_path(path, s->buffer + s->len, PAGE_SIZE - s->len);
70976 if (!IS_ERR(p)) {
70977- p = mangle_path(s->buffer + s->len, p, "\n");
70978+ p = mangle_path(s->buffer + s->len, p, "\n\\");
70979 if (p) {
70980 s->len = p - s->buffer;
70981 return 1;
70982diff --git a/kernel/trace/trace_stack.c b/kernel/trace/trace_stack.c
70983index d4545f4..a9010a1 100644
70984--- a/kernel/trace/trace_stack.c
70985+++ b/kernel/trace/trace_stack.c
70986@@ -53,7 +53,7 @@ static inline void check_stack(void)
70987 return;
70988
70989 /* we do not handle interrupt stacks yet */
70990- if (!object_is_on_stack(&this_size))
70991+ if (!object_starts_on_stack(&this_size))
70992 return;
70993
70994 local_irq_save(flags);
70995diff --git a/kernel/workqueue.c b/kernel/workqueue.c
70996index 872bd6d..31601a2 100644
70997--- a/kernel/workqueue.c
70998+++ b/kernel/workqueue.c
70999@@ -1422,7 +1422,7 @@ retry:
71000 /* morph UNBOUND to REBIND atomically */
71001 worker_flags &= ~WORKER_UNBOUND;
71002 worker_flags |= WORKER_REBIND;
71003- ACCESS_ONCE(worker->flags) = worker_flags;
71004+ ACCESS_ONCE_RW(worker->flags) = worker_flags;
71005
71006 idle_rebind.cnt++;
71007 worker->idle_rebind = &idle_rebind;
71008@@ -1448,7 +1448,7 @@ retry:
71009 /* morph UNBOUND to REBIND atomically */
71010 worker_flags &= ~WORKER_UNBOUND;
71011 worker_flags |= WORKER_REBIND;
71012- ACCESS_ONCE(worker->flags) = worker_flags;
71013+ ACCESS_ONCE_RW(worker->flags) = worker_flags;
71014
71015 if (test_and_set_bit(WORK_STRUCT_PENDING_BIT,
71016 work_data_bits(rebind_work)))
71017diff --git a/lib/Kconfig.debug b/lib/Kconfig.debug
71018index 2403a63..5c4be4c 100644
71019--- a/lib/Kconfig.debug
71020+++ b/lib/Kconfig.debug
71021@@ -1252,6 +1252,7 @@ config LATENCYTOP
71022 depends on DEBUG_KERNEL
71023 depends on STACKTRACE_SUPPORT
71024 depends on PROC_FS
71025+ depends on !GRKERNSEC_HIDESYM
71026 select FRAME_POINTER if !MIPS && !PPC && !S390 && !MICROBLAZE && !ARM_UNWIND
71027 select KALLSYMS
71028 select KALLSYMS_ALL
71029@@ -1267,7 +1268,7 @@ source kernel/trace/Kconfig
71030
71031 config PROVIDE_OHCI1394_DMA_INIT
71032 bool "Remote debugging over FireWire early on boot"
71033- depends on PCI && X86
71034+ depends on PCI && X86 && !GRKERNSEC
71035 help
71036 If you want to debug problems which hang or crash the kernel early
71037 on boot and the crashing machine has a FireWire port, you can use
71038@@ -1296,7 +1297,7 @@ config PROVIDE_OHCI1394_DMA_INIT
71039
71040 config FIREWIRE_OHCI_REMOTE_DMA
71041 bool "Remote debugging over FireWire with firewire-ohci"
71042- depends on FIREWIRE_OHCI
71043+ depends on FIREWIRE_OHCI && !GRKERNSEC
71044 help
71045 This option lets you use the FireWire bus for remote debugging
71046 with help of the firewire-ohci driver. It enables unfiltered
71047diff --git a/lib/bitmap.c b/lib/bitmap.c
71048index 06fdfa1..97c5c7d 100644
71049--- a/lib/bitmap.c
71050+++ b/lib/bitmap.c
71051@@ -422,7 +422,7 @@ int __bitmap_parse(const char *buf, unsigned int buflen,
71052 {
71053 int c, old_c, totaldigits, ndigits, nchunks, nbits;
71054 u32 chunk;
71055- const char __user __force *ubuf = (const char __user __force *)buf;
71056+ const char __user *ubuf = (const char __force_user *)buf;
71057
71058 bitmap_zero(maskp, nmaskbits);
71059
71060@@ -507,7 +507,7 @@ int bitmap_parse_user(const char __user *ubuf,
71061 {
71062 if (!access_ok(VERIFY_READ, ubuf, ulen))
71063 return -EFAULT;
71064- return __bitmap_parse((const char __force *)ubuf,
71065+ return __bitmap_parse((const char __force_kernel *)ubuf,
71066 ulen, 1, maskp, nmaskbits);
71067
71068 }
71069@@ -598,7 +598,7 @@ static int __bitmap_parselist(const char *buf, unsigned int buflen,
71070 {
71071 unsigned a, b;
71072 int c, old_c, totaldigits;
71073- const char __user __force *ubuf = (const char __user __force *)buf;
71074+ const char __user *ubuf = (const char __force_user *)buf;
71075 int exp_digit, in_range;
71076
71077 totaldigits = c = 0;
71078@@ -698,7 +698,7 @@ int bitmap_parselist_user(const char __user *ubuf,
71079 {
71080 if (!access_ok(VERIFY_READ, ubuf, ulen))
71081 return -EFAULT;
71082- return __bitmap_parselist((const char __force *)ubuf,
71083+ return __bitmap_parselist((const char __force_kernel *)ubuf,
71084 ulen, 1, maskp, nmaskbits);
71085 }
71086 EXPORT_SYMBOL(bitmap_parselist_user);
71087diff --git a/lib/bug.c b/lib/bug.c
71088index a28c141..2bd3d95 100644
71089--- a/lib/bug.c
71090+++ b/lib/bug.c
71091@@ -133,6 +133,8 @@ enum bug_trap_type report_bug(unsigned long bugaddr, struct pt_regs *regs)
71092 return BUG_TRAP_TYPE_NONE;
71093
71094 bug = find_bug(bugaddr);
71095+ if (!bug)
71096+ return BUG_TRAP_TYPE_NONE;
71097
71098 file = NULL;
71099 line = 0;
71100diff --git a/lib/debugobjects.c b/lib/debugobjects.c
71101index d11808c..dc2d6f8 100644
71102--- a/lib/debugobjects.c
71103+++ b/lib/debugobjects.c
71104@@ -287,7 +287,7 @@ static void debug_object_is_on_stack(void *addr, int onstack)
71105 if (limit > 4)
71106 return;
71107
71108- is_on_stack = object_is_on_stack(addr);
71109+ is_on_stack = object_starts_on_stack(addr);
71110 if (is_on_stack == onstack)
71111 return;
71112
71113diff --git a/lib/devres.c b/lib/devres.c
71114index 80b9c76..9e32279 100644
71115--- a/lib/devres.c
71116+++ b/lib/devres.c
71117@@ -80,7 +80,7 @@ EXPORT_SYMBOL(devm_ioremap_nocache);
71118 void devm_iounmap(struct device *dev, void __iomem *addr)
71119 {
71120 WARN_ON(devres_destroy(dev, devm_ioremap_release, devm_ioremap_match,
71121- (void *)addr));
71122+ (void __force *)addr));
71123 iounmap(addr);
71124 }
71125 EXPORT_SYMBOL(devm_iounmap);
71126@@ -192,7 +192,7 @@ void devm_ioport_unmap(struct device *dev, void __iomem *addr)
71127 {
71128 ioport_unmap(addr);
71129 WARN_ON(devres_destroy(dev, devm_ioport_map_release,
71130- devm_ioport_map_match, (void *)addr));
71131+ devm_ioport_map_match, (void __force *)addr));
71132 }
71133 EXPORT_SYMBOL(devm_ioport_unmap);
71134
71135diff --git a/lib/dma-debug.c b/lib/dma-debug.c
71136index 66ce414..6f0a0dd 100644
71137--- a/lib/dma-debug.c
71138+++ b/lib/dma-debug.c
71139@@ -924,7 +924,7 @@ out:
71140
71141 static void check_for_stack(struct device *dev, void *addr)
71142 {
71143- if (object_is_on_stack(addr))
71144+ if (object_starts_on_stack(addr))
71145 err_printk(dev, NULL, "DMA-API: device driver maps memory from"
71146 "stack [addr=%p]\n", addr);
71147 }
71148diff --git a/lib/inflate.c b/lib/inflate.c
71149index 013a761..c28f3fc 100644
71150--- a/lib/inflate.c
71151+++ b/lib/inflate.c
71152@@ -269,7 +269,7 @@ static void free(void *where)
71153 malloc_ptr = free_mem_ptr;
71154 }
71155 #else
71156-#define malloc(a) kmalloc(a, GFP_KERNEL)
71157+#define malloc(a) kmalloc((a), GFP_KERNEL)
71158 #define free(a) kfree(a)
71159 #endif
71160
71161diff --git a/lib/ioremap.c b/lib/ioremap.c
71162index 0c9216c..863bd89 100644
71163--- a/lib/ioremap.c
71164+++ b/lib/ioremap.c
71165@@ -38,7 +38,7 @@ static inline int ioremap_pmd_range(pud_t *pud, unsigned long addr,
71166 unsigned long next;
71167
71168 phys_addr -= addr;
71169- pmd = pmd_alloc(&init_mm, pud, addr);
71170+ pmd = pmd_alloc_kernel(&init_mm, pud, addr);
71171 if (!pmd)
71172 return -ENOMEM;
71173 do {
71174@@ -56,7 +56,7 @@ static inline int ioremap_pud_range(pgd_t *pgd, unsigned long addr,
71175 unsigned long next;
71176
71177 phys_addr -= addr;
71178- pud = pud_alloc(&init_mm, pgd, addr);
71179+ pud = pud_alloc_kernel(&init_mm, pgd, addr);
71180 if (!pud)
71181 return -ENOMEM;
71182 do {
71183diff --git a/lib/is_single_threaded.c b/lib/is_single_threaded.c
71184index bd2bea9..6b3c95e 100644
71185--- a/lib/is_single_threaded.c
71186+++ b/lib/is_single_threaded.c
71187@@ -22,6 +22,9 @@ bool current_is_single_threaded(void)
71188 struct task_struct *p, *t;
71189 bool ret;
71190
71191+ if (!mm)
71192+ return true;
71193+
71194 if (atomic_read(&task->signal->live) != 1)
71195 return false;
71196
71197diff --git a/lib/radix-tree.c b/lib/radix-tree.c
71198index e796429..6e38f9f 100644
71199--- a/lib/radix-tree.c
71200+++ b/lib/radix-tree.c
71201@@ -92,7 +92,7 @@ struct radix_tree_preload {
71202 int nr;
71203 struct radix_tree_node *nodes[RADIX_TREE_PRELOAD_SIZE];
71204 };
71205-static DEFINE_PER_CPU(struct radix_tree_preload, radix_tree_preloads) = { 0, };
71206+static DEFINE_PER_CPU(struct radix_tree_preload, radix_tree_preloads);
71207
71208 static inline void *ptr_to_indirect(void *ptr)
71209 {
71210diff --git a/lib/vsprintf.c b/lib/vsprintf.c
71211index 0e33754..50a0e63 100644
71212--- a/lib/vsprintf.c
71213+++ b/lib/vsprintf.c
71214@@ -16,6 +16,9 @@
71215 * - scnprintf and vscnprintf
71216 */
71217
71218+#ifdef CONFIG_GRKERNSEC_HIDESYM
71219+#define __INCLUDED_BY_HIDESYM 1
71220+#endif
71221 #include <stdarg.h>
71222 #include <linux/module.h> /* for KSYM_SYMBOL_LEN */
71223 #include <linux/types.h>
71224@@ -536,7 +539,7 @@ char *symbol_string(char *buf, char *end, void *ptr,
71225 char sym[KSYM_SYMBOL_LEN];
71226 if (ext == 'B')
71227 sprint_backtrace(sym, value);
71228- else if (ext != 'f' && ext != 's')
71229+ else if (ext != 'f' && ext != 's' && ext != 'a')
71230 sprint_symbol(sym, value);
71231 else
71232 sprint_symbol_no_offset(sym, value);
71233@@ -969,7 +972,11 @@ char *netdev_feature_string(char *buf, char *end, const u8 *addr,
71234 return number(buf, end, *(const netdev_features_t *)addr, spec);
71235 }
71236
71237+#ifdef CONFIG_GRKERNSEC_HIDESYM
71238+int kptr_restrict __read_mostly = 2;
71239+#else
71240 int kptr_restrict __read_mostly;
71241+#endif
71242
71243 /*
71244 * Show a '%p' thing. A kernel extension is that the '%p' is followed
71245@@ -983,6 +990,8 @@ int kptr_restrict __read_mostly;
71246 * - 'S' For symbolic direct pointers with offset
71247 * - 's' For symbolic direct pointers without offset
71248 * - 'B' For backtraced symbolic direct pointers with offset
71249+ * - 'A' For symbolic direct pointers with offset approved for use with GRKERNSEC_HIDESYM
71250+ * - 'a' For symbolic direct pointers without offset approved for use with GRKERNSEC_HIDESYM
71251 * - 'R' For decoded struct resource, e.g., [mem 0x0-0x1f 64bit pref]
71252 * - 'r' For raw struct resource, e.g., [mem 0x0-0x1f flags 0x201]
71253 * - 'M' For a 6-byte MAC address, it prints the address in the
71254@@ -1038,12 +1047,12 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
71255
71256 if (!ptr && *fmt != 'K') {
71257 /*
71258- * Print (null) with the same width as a pointer so it makes
71259+ * Print (nil) with the same width as a pointer so it makes
71260 * tabular output look nice.
71261 */
71262 if (spec.field_width == -1)
71263 spec.field_width = default_width;
71264- return string(buf, end, "(null)", spec);
71265+ return string(buf, end, "(nil)", spec);
71266 }
71267
71268 switch (*fmt) {
71269@@ -1053,6 +1062,13 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
71270 /* Fallthrough */
71271 case 'S':
71272 case 's':
71273+#ifdef CONFIG_GRKERNSEC_HIDESYM
71274+ break;
71275+#else
71276+ return symbol_string(buf, end, ptr, spec, *fmt);
71277+#endif
71278+ case 'A':
71279+ case 'a':
71280 case 'B':
71281 return symbol_string(buf, end, ptr, spec, *fmt);
71282 case 'R':
71283@@ -1093,6 +1109,8 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
71284 va_end(va);
71285 return buf;
71286 }
71287+ case 'P':
71288+ break;
71289 case 'K':
71290 /*
71291 * %pK cannot be used in IRQ context because its test
71292@@ -1116,6 +1134,21 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
71293 }
71294 break;
71295 }
71296+
71297+#ifdef CONFIG_GRKERNSEC_HIDESYM
71298+ /* 'P' = approved pointers to copy to userland,
71299+ as in the /proc/kallsyms case, as we make it display nothing
71300+ for non-root users, and the real contents for root users
71301+ Also ignore 'K' pointers, since we force their NULLing for non-root users
71302+ above
71303+ */
71304+ if (ptr > TASK_SIZE && *fmt != 'P' && *fmt != 'K' && is_usercopy_object(buf)) {
71305+ printk(KERN_ALERT "grsec: kernel infoleak detected! Please report this log to spender@grsecurity.net.\n");
71306+ dump_stack();
71307+ ptr = NULL;
71308+ }
71309+#endif
71310+
71311 spec.flags |= SMALL;
71312 if (spec.field_width == -1) {
71313 spec.field_width = default_width;
71314@@ -1831,11 +1864,11 @@ int bstr_printf(char *buf, size_t size, const char *fmt, const u32 *bin_buf)
71315 typeof(type) value; \
71316 if (sizeof(type) == 8) { \
71317 args = PTR_ALIGN(args, sizeof(u32)); \
71318- *(u32 *)&value = *(u32 *)args; \
71319- *((u32 *)&value + 1) = *(u32 *)(args + 4); \
71320+ *(u32 *)&value = *(const u32 *)args; \
71321+ *((u32 *)&value + 1) = *(const u32 *)(args + 4); \
71322 } else { \
71323 args = PTR_ALIGN(args, sizeof(type)); \
71324- value = *(typeof(type) *)args; \
71325+ value = *(const typeof(type) *)args; \
71326 } \
71327 args += sizeof(type); \
71328 value; \
71329@@ -1898,7 +1931,7 @@ int bstr_printf(char *buf, size_t size, const char *fmt, const u32 *bin_buf)
71330 case FORMAT_TYPE_STR: {
71331 const char *str_arg = args;
71332 args += strlen(str_arg) + 1;
71333- str = string(str, end, (char *)str_arg, spec);
71334+ str = string(str, end, str_arg, spec);
71335 break;
71336 }
71337
71338diff --git a/localversion-grsec b/localversion-grsec
71339new file mode 100644
71340index 0000000..7cd6065
71341--- /dev/null
71342+++ b/localversion-grsec
71343@@ -0,0 +1 @@
71344+-grsec
71345diff --git a/mm/Kconfig b/mm/Kconfig
71346index d5c8019..f513038 100644
71347--- a/mm/Kconfig
71348+++ b/mm/Kconfig
71349@@ -251,10 +251,10 @@ config KSM
71350 root has set /sys/kernel/mm/ksm/run to 1 (if CONFIG_SYSFS is set).
71351
71352 config DEFAULT_MMAP_MIN_ADDR
71353- int "Low address space to protect from user allocation"
71354+ int "Low address space to protect from user allocation"
71355 depends on MMU
71356- default 4096
71357- help
71358+ default 65536
71359+ help
71360 This is the portion of low virtual memory which should be protected
71361 from userspace allocation. Keeping a user from writing to low pages
71362 can help reduce the impact of kernel NULL pointer bugs.
71363@@ -285,7 +285,7 @@ config MEMORY_FAILURE
71364
71365 config HWPOISON_INJECT
71366 tristate "HWPoison pages injector"
71367- depends on MEMORY_FAILURE && DEBUG_KERNEL && PROC_FS
71368+ depends on MEMORY_FAILURE && DEBUG_KERNEL && PROC_FS && !GRKERNSEC
71369 select PROC_PAGE_MONITOR
71370
71371 config NOMMU_INITIAL_TRIM_EXCESS
71372diff --git a/mm/filemap.c b/mm/filemap.c
71373index 3843445..4fe6833 100644
71374--- a/mm/filemap.c
71375+++ b/mm/filemap.c
71376@@ -1746,7 +1746,7 @@ int generic_file_mmap(struct file * file, struct vm_area_struct * vma)
71377 struct address_space *mapping = file->f_mapping;
71378
71379 if (!mapping->a_ops->readpage)
71380- return -ENOEXEC;
71381+ return -ENODEV;
71382 file_accessed(file);
71383 vma->vm_ops = &generic_file_vm_ops;
71384 vma->vm_flags |= VM_CAN_NONLINEAR;
71385@@ -2087,6 +2087,7 @@ inline int generic_write_checks(struct file *file, loff_t *pos, size_t *count, i
71386 *pos = i_size_read(inode);
71387
71388 if (limit != RLIM_INFINITY) {
71389+ gr_learn_resource(current, RLIMIT_FSIZE,*pos, 0);
71390 if (*pos >= limit) {
71391 send_sig(SIGXFSZ, current, 0);
71392 return -EFBIG;
71393diff --git a/mm/fremap.c b/mm/fremap.c
71394index 9ed4fd4..c42648d 100644
71395--- a/mm/fremap.c
71396+++ b/mm/fremap.c
71397@@ -155,6 +155,11 @@ SYSCALL_DEFINE5(remap_file_pages, unsigned long, start, unsigned long, size,
71398 retry:
71399 vma = find_vma(mm, start);
71400
71401+#ifdef CONFIG_PAX_SEGMEXEC
71402+ if (vma && (mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_flags & VM_MAYEXEC))
71403+ goto out;
71404+#endif
71405+
71406 /*
71407 * Make sure the vma is shared, that it supports prefaulting,
71408 * and that the remapped range is valid and fully within
71409diff --git a/mm/highmem.c b/mm/highmem.c
71410index d517cd1..006a1c5 100644
71411--- a/mm/highmem.c
71412+++ b/mm/highmem.c
71413@@ -137,9 +137,10 @@ static void flush_all_zero_pkmaps(void)
71414 * So no dangers, even with speculative execution.
71415 */
71416 page = pte_page(pkmap_page_table[i]);
71417+ pax_open_kernel();
71418 pte_clear(&init_mm, (unsigned long)page_address(page),
71419 &pkmap_page_table[i]);
71420-
71421+ pax_close_kernel();
71422 set_page_address(page, NULL);
71423 need_flush = 1;
71424 }
71425@@ -198,9 +199,11 @@ start:
71426 }
71427 }
71428 vaddr = PKMAP_ADDR(last_pkmap_nr);
71429+
71430+ pax_open_kernel();
71431 set_pte_at(&init_mm, vaddr,
71432 &(pkmap_page_table[last_pkmap_nr]), mk_pte(page, kmap_prot));
71433-
71434+ pax_close_kernel();
71435 pkmap_count[last_pkmap_nr] = 1;
71436 set_page_address(page, (void *)vaddr);
71437
71438diff --git a/mm/huge_memory.c b/mm/huge_memory.c
71439index 141dbb6..ebff057 100644
71440--- a/mm/huge_memory.c
71441+++ b/mm/huge_memory.c
71442@@ -735,7 +735,7 @@ out:
71443 * run pte_offset_map on the pmd, if an huge pmd could
71444 * materialize from under us from a different thread.
71445 */
71446- if (unlikely(__pte_alloc(mm, vma, pmd, address)))
71447+ if (unlikely(pmd_none(*pmd) && __pte_alloc(mm, vma, pmd, address)))
71448 return VM_FAULT_OOM;
71449 /* if an huge pmd materialized from under us just retry later */
71450 if (unlikely(pmd_trans_huge(*pmd)))
71451diff --git a/mm/hugetlb.c b/mm/hugetlb.c
71452index 3adceaf..dccfea3 100644
71453--- a/mm/hugetlb.c
71454+++ b/mm/hugetlb.c
71455@@ -2512,6 +2512,27 @@ static int unmap_ref_private(struct mm_struct *mm, struct vm_area_struct *vma,
71456 return 1;
71457 }
71458
71459+#ifdef CONFIG_PAX_SEGMEXEC
71460+static void pax_mirror_huge_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m)
71461+{
71462+ struct mm_struct *mm = vma->vm_mm;
71463+ struct vm_area_struct *vma_m;
71464+ unsigned long address_m;
71465+ pte_t *ptep_m;
71466+
71467+ vma_m = pax_find_mirror_vma(vma);
71468+ if (!vma_m)
71469+ return;
71470+
71471+ BUG_ON(address >= SEGMEXEC_TASK_SIZE);
71472+ address_m = address + SEGMEXEC_TASK_SIZE;
71473+ ptep_m = huge_pte_offset(mm, address_m & HPAGE_MASK);
71474+ get_page(page_m);
71475+ hugepage_add_anon_rmap(page_m, vma_m, address_m);
71476+ set_huge_pte_at(mm, address_m, ptep_m, make_huge_pte(vma_m, page_m, 0));
71477+}
71478+#endif
71479+
71480 /*
71481 * Hugetlb_cow() should be called with page lock of the original hugepage held.
71482 * Called with hugetlb_instantiation_mutex held and pte_page locked so we
71483@@ -2628,6 +2649,11 @@ retry_avoidcopy:
71484 make_huge_pte(vma, new_page, 1));
71485 page_remove_rmap(old_page);
71486 hugepage_add_new_anon_rmap(new_page, vma, address);
71487+
71488+#ifdef CONFIG_PAX_SEGMEXEC
71489+ pax_mirror_huge_pte(vma, address, new_page);
71490+#endif
71491+
71492 /* Make the old page be freed below */
71493 new_page = old_page;
71494 mmu_notifier_invalidate_range_end(mm,
71495@@ -2786,6 +2812,10 @@ retry:
71496 && (vma->vm_flags & VM_SHARED)));
71497 set_huge_pte_at(mm, address, ptep, new_pte);
71498
71499+#ifdef CONFIG_PAX_SEGMEXEC
71500+ pax_mirror_huge_pte(vma, address, page);
71501+#endif
71502+
71503 if ((flags & FAULT_FLAG_WRITE) && !(vma->vm_flags & VM_SHARED)) {
71504 /* Optimization, do the COW without a second fault */
71505 ret = hugetlb_cow(mm, vma, address, ptep, new_pte, page);
71506@@ -2815,6 +2845,10 @@ int hugetlb_fault(struct mm_struct *mm, struct vm_area_struct *vma,
71507 static DEFINE_MUTEX(hugetlb_instantiation_mutex);
71508 struct hstate *h = hstate_vma(vma);
71509
71510+#ifdef CONFIG_PAX_SEGMEXEC
71511+ struct vm_area_struct *vma_m;
71512+#endif
71513+
71514 address &= huge_page_mask(h);
71515
71516 ptep = huge_pte_offset(mm, address);
71517@@ -2828,6 +2862,26 @@ int hugetlb_fault(struct mm_struct *mm, struct vm_area_struct *vma,
71518 VM_FAULT_SET_HINDEX(hstate_index(h));
71519 }
71520
71521+#ifdef CONFIG_PAX_SEGMEXEC
71522+ vma_m = pax_find_mirror_vma(vma);
71523+ if (vma_m) {
71524+ unsigned long address_m;
71525+
71526+ if (vma->vm_start > vma_m->vm_start) {
71527+ address_m = address;
71528+ address -= SEGMEXEC_TASK_SIZE;
71529+ vma = vma_m;
71530+ h = hstate_vma(vma);
71531+ } else
71532+ address_m = address + SEGMEXEC_TASK_SIZE;
71533+
71534+ if (!huge_pte_alloc(mm, address_m, huge_page_size(h)))
71535+ return VM_FAULT_OOM;
71536+ address_m &= HPAGE_MASK;
71537+ unmap_hugepage_range(vma, address_m, address_m + HPAGE_SIZE, NULL);
71538+ }
71539+#endif
71540+
71541 ptep = huge_pte_alloc(mm, address, huge_page_size(h));
71542 if (!ptep)
71543 return VM_FAULT_OOM;
71544diff --git a/mm/internal.h b/mm/internal.h
71545index b8c91b3..93e95a3 100644
71546--- a/mm/internal.h
71547+++ b/mm/internal.h
71548@@ -95,6 +95,7 @@ extern void putback_lru_page(struct page *page);
71549 * in mm/page_alloc.c
71550 */
71551 extern void __free_pages_bootmem(struct page *page, unsigned int order);
71552+extern void free_compound_page(struct page *page);
71553 extern void prep_compound_page(struct page *page, unsigned long order);
71554 #ifdef CONFIG_MEMORY_FAILURE
71555 extern bool is_free_buddy_page(struct page *page);
71556diff --git a/mm/kmemleak.c b/mm/kmemleak.c
71557index 45eb621..6ccd8ea 100644
71558--- a/mm/kmemleak.c
71559+++ b/mm/kmemleak.c
71560@@ -363,7 +363,7 @@ static void print_unreferenced(struct seq_file *seq,
71561
71562 for (i = 0; i < object->trace_len; i++) {
71563 void *ptr = (void *)object->trace[i];
71564- seq_printf(seq, " [<%p>] %pS\n", ptr, ptr);
71565+ seq_printf(seq, " [<%p>] %pA\n", ptr, ptr);
71566 }
71567 }
71568
71569diff --git a/mm/maccess.c b/mm/maccess.c
71570index d53adf9..03a24bf 100644
71571--- a/mm/maccess.c
71572+++ b/mm/maccess.c
71573@@ -26,7 +26,7 @@ long __probe_kernel_read(void *dst, const void *src, size_t size)
71574 set_fs(KERNEL_DS);
71575 pagefault_disable();
71576 ret = __copy_from_user_inatomic(dst,
71577- (__force const void __user *)src, size);
71578+ (const void __force_user *)src, size);
71579 pagefault_enable();
71580 set_fs(old_fs);
71581
71582@@ -53,7 +53,7 @@ long __probe_kernel_write(void *dst, const void *src, size_t size)
71583
71584 set_fs(KERNEL_DS);
71585 pagefault_disable();
71586- ret = __copy_to_user_inatomic((__force void __user *)dst, src, size);
71587+ ret = __copy_to_user_inatomic((void __force_user *)dst, src, size);
71588 pagefault_enable();
71589 set_fs(old_fs);
71590
71591diff --git a/mm/madvise.c b/mm/madvise.c
71592index 14d260f..b2a80fd 100644
71593--- a/mm/madvise.c
71594+++ b/mm/madvise.c
71595@@ -48,6 +48,10 @@ static long madvise_behavior(struct vm_area_struct * vma,
71596 pgoff_t pgoff;
71597 unsigned long new_flags = vma->vm_flags;
71598
71599+#ifdef CONFIG_PAX_SEGMEXEC
71600+ struct vm_area_struct *vma_m;
71601+#endif
71602+
71603 switch (behavior) {
71604 case MADV_NORMAL:
71605 new_flags = new_flags & ~VM_RAND_READ & ~VM_SEQ_READ;
71606@@ -119,6 +123,13 @@ success:
71607 /*
71608 * vm_flags is protected by the mmap_sem held in write mode.
71609 */
71610+
71611+#ifdef CONFIG_PAX_SEGMEXEC
71612+ vma_m = pax_find_mirror_vma(vma);
71613+ if (vma_m)
71614+ vma_m->vm_flags = new_flags & ~(VM_WRITE | VM_MAYWRITE | VM_ACCOUNT);
71615+#endif
71616+
71617 vma->vm_flags = new_flags;
71618
71619 out:
71620@@ -177,6 +188,11 @@ static long madvise_dontneed(struct vm_area_struct * vma,
71621 struct vm_area_struct ** prev,
71622 unsigned long start, unsigned long end)
71623 {
71624+
71625+#ifdef CONFIG_PAX_SEGMEXEC
71626+ struct vm_area_struct *vma_m;
71627+#endif
71628+
71629 *prev = vma;
71630 if (vma->vm_flags & (VM_LOCKED|VM_HUGETLB|VM_PFNMAP))
71631 return -EINVAL;
71632@@ -189,6 +205,21 @@ static long madvise_dontneed(struct vm_area_struct * vma,
71633 zap_page_range(vma, start, end - start, &details);
71634 } else
71635 zap_page_range(vma, start, end - start, NULL);
71636+
71637+#ifdef CONFIG_PAX_SEGMEXEC
71638+ vma_m = pax_find_mirror_vma(vma);
71639+ if (vma_m) {
71640+ if (unlikely(vma->vm_flags & VM_NONLINEAR)) {
71641+ struct zap_details details = {
71642+ .nonlinear_vma = vma_m,
71643+ .last_index = ULONG_MAX,
71644+ };
71645+ zap_page_range(vma, start + SEGMEXEC_TASK_SIZE, end - start, &details);
71646+ } else
71647+ zap_page_range(vma, start + SEGMEXEC_TASK_SIZE, end - start, NULL);
71648+ }
71649+#endif
71650+
71651 return 0;
71652 }
71653
71654@@ -393,6 +424,16 @@ SYSCALL_DEFINE3(madvise, unsigned long, start, size_t, len_in, int, behavior)
71655 if (end < start)
71656 goto out;
71657
71658+#ifdef CONFIG_PAX_SEGMEXEC
71659+ if (current->mm->pax_flags & MF_PAX_SEGMEXEC) {
71660+ if (end > SEGMEXEC_TASK_SIZE)
71661+ goto out;
71662+ } else
71663+#endif
71664+
71665+ if (end > TASK_SIZE)
71666+ goto out;
71667+
71668 error = 0;
71669 if (end == start)
71670 goto out;
71671diff --git a/mm/memory-failure.c b/mm/memory-failure.c
71672index a6e2141..eaf5aad 100644
71673--- a/mm/memory-failure.c
71674+++ b/mm/memory-failure.c
71675@@ -61,7 +61,7 @@ int sysctl_memory_failure_early_kill __read_mostly = 0;
71676
71677 int sysctl_memory_failure_recovery __read_mostly = 1;
71678
71679-atomic_long_t mce_bad_pages __read_mostly = ATOMIC_LONG_INIT(0);
71680+atomic_long_unchecked_t mce_bad_pages __read_mostly = ATOMIC_LONG_INIT(0);
71681
71682 #if defined(CONFIG_HWPOISON_INJECT) || defined(CONFIG_HWPOISON_INJECT_MODULE)
71683
71684@@ -202,7 +202,7 @@ static int kill_proc(struct task_struct *t, unsigned long addr, int trapno,
71685 pfn, t->comm, t->pid);
71686 si.si_signo = SIGBUS;
71687 si.si_errno = 0;
71688- si.si_addr = (void *)addr;
71689+ si.si_addr = (void __user *)addr;
71690 #ifdef __ARCH_SI_TRAPNO
71691 si.si_trapno = trapno;
71692 #endif
71693@@ -1038,7 +1038,7 @@ int memory_failure(unsigned long pfn, int trapno, int flags)
71694 }
71695
71696 nr_pages = 1 << compound_trans_order(hpage);
71697- atomic_long_add(nr_pages, &mce_bad_pages);
71698+ atomic_long_add_unchecked(nr_pages, &mce_bad_pages);
71699
71700 /*
71701 * We need/can do nothing about count=0 pages.
71702@@ -1068,7 +1068,7 @@ int memory_failure(unsigned long pfn, int trapno, int flags)
71703 if (!PageHWPoison(hpage)
71704 || (hwpoison_filter(p) && TestClearPageHWPoison(p))
71705 || (p != hpage && TestSetPageHWPoison(hpage))) {
71706- atomic_long_sub(nr_pages, &mce_bad_pages);
71707+ atomic_long_sub_unchecked(nr_pages, &mce_bad_pages);
71708 return 0;
71709 }
71710 set_page_hwpoison_huge_page(hpage);
71711@@ -1126,7 +1126,7 @@ int memory_failure(unsigned long pfn, int trapno, int flags)
71712 }
71713 if (hwpoison_filter(p)) {
71714 if (TestClearPageHWPoison(p))
71715- atomic_long_sub(nr_pages, &mce_bad_pages);
71716+ atomic_long_sub_unchecked(nr_pages, &mce_bad_pages);
71717 unlock_page(hpage);
71718 put_page(hpage);
71719 return 0;
71720@@ -1321,7 +1321,7 @@ int unpoison_memory(unsigned long pfn)
71721 return 0;
71722 }
71723 if (TestClearPageHWPoison(p))
71724- atomic_long_sub(nr_pages, &mce_bad_pages);
71725+ atomic_long_sub_unchecked(nr_pages, &mce_bad_pages);
71726 pr_info("MCE: Software-unpoisoned free page %#lx\n", pfn);
71727 return 0;
71728 }
71729@@ -1335,7 +1335,7 @@ int unpoison_memory(unsigned long pfn)
71730 */
71731 if (TestClearPageHWPoison(page)) {
71732 pr_info("MCE: Software-unpoisoned page %#lx\n", pfn);
71733- atomic_long_sub(nr_pages, &mce_bad_pages);
71734+ atomic_long_sub_unchecked(nr_pages, &mce_bad_pages);
71735 freeit = 1;
71736 if (PageHuge(page))
71737 clear_page_hwpoison_huge_page(page);
71738@@ -1440,7 +1440,7 @@ static int soft_offline_huge_page(struct page *page, int flags)
71739 }
71740 done:
71741 if (!PageHWPoison(hpage))
71742- atomic_long_add(1 << compound_trans_order(hpage),
71743+ atomic_long_add_unchecked(1 << compound_trans_order(hpage),
71744 &mce_bad_pages);
71745 set_page_hwpoison_huge_page(hpage);
71746 dequeue_hwpoisoned_huge_page(hpage);
71747@@ -1572,7 +1572,7 @@ int soft_offline_page(struct page *page, int flags)
71748 return ret;
71749
71750 done:
71751- atomic_long_add(1, &mce_bad_pages);
71752+ atomic_long_add_unchecked(1, &mce_bad_pages);
71753 SetPageHWPoison(page);
71754 /* keep elevated page count for bad page */
71755 return ret;
71756diff --git a/mm/memory.c b/mm/memory.c
71757index 5736170..8e04800 100644
71758--- a/mm/memory.c
71759+++ b/mm/memory.c
71760@@ -426,6 +426,7 @@ static inline void free_pmd_range(struct mmu_gather *tlb, pud_t *pud,
71761 free_pte_range(tlb, pmd, addr);
71762 } while (pmd++, addr = next, addr != end);
71763
71764+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_PER_CPU_PGD)
71765 start &= PUD_MASK;
71766 if (start < floor)
71767 return;
71768@@ -440,6 +441,8 @@ static inline void free_pmd_range(struct mmu_gather *tlb, pud_t *pud,
71769 pmd = pmd_offset(pud, start);
71770 pud_clear(pud);
71771 pmd_free_tlb(tlb, pmd, start);
71772+#endif
71773+
71774 }
71775
71776 static inline void free_pud_range(struct mmu_gather *tlb, pgd_t *pgd,
71777@@ -459,6 +462,7 @@ static inline void free_pud_range(struct mmu_gather *tlb, pgd_t *pgd,
71778 free_pmd_range(tlb, pud, addr, next, floor, ceiling);
71779 } while (pud++, addr = next, addr != end);
71780
71781+#if !defined(CONFIG_X86_64) || !defined(CONFIG_PAX_PER_CPU_PGD)
71782 start &= PGDIR_MASK;
71783 if (start < floor)
71784 return;
71785@@ -473,6 +477,8 @@ static inline void free_pud_range(struct mmu_gather *tlb, pgd_t *pgd,
71786 pud = pud_offset(pgd, start);
71787 pgd_clear(pgd);
71788 pud_free_tlb(tlb, pud, start);
71789+#endif
71790+
71791 }
71792
71793 /*
71794@@ -1614,12 +1620,6 @@ no_page_table:
71795 return page;
71796 }
71797
71798-static inline int stack_guard_page(struct vm_area_struct *vma, unsigned long addr)
71799-{
71800- return stack_guard_page_start(vma, addr) ||
71801- stack_guard_page_end(vma, addr+PAGE_SIZE);
71802-}
71803-
71804 /**
71805 * __get_user_pages() - pin user pages in memory
71806 * @tsk: task_struct of target task
71807@@ -1692,10 +1692,10 @@ int __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
71808 (VM_MAYREAD | VM_MAYWRITE) : (VM_READ | VM_WRITE);
71809 i = 0;
71810
71811- do {
71812+ while (nr_pages) {
71813 struct vm_area_struct *vma;
71814
71815- vma = find_extend_vma(mm, start);
71816+ vma = find_vma(mm, start);
71817 if (!vma && in_gate_area(mm, start)) {
71818 unsigned long pg = start & PAGE_MASK;
71819 pgd_t *pgd;
71820@@ -1743,7 +1743,7 @@ int __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
71821 goto next_page;
71822 }
71823
71824- if (!vma ||
71825+ if (!vma || start < vma->vm_start ||
71826 (vma->vm_flags & (VM_IO | VM_PFNMAP)) ||
71827 !(vm_flags & vma->vm_flags))
71828 return i ? : -EFAULT;
71829@@ -1770,11 +1770,6 @@ int __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
71830 int ret;
71831 unsigned int fault_flags = 0;
71832
71833- /* For mlock, just skip the stack guard page. */
71834- if (foll_flags & FOLL_MLOCK) {
71835- if (stack_guard_page(vma, start))
71836- goto next_page;
71837- }
71838 if (foll_flags & FOLL_WRITE)
71839 fault_flags |= FAULT_FLAG_WRITE;
71840 if (nonblocking)
71841@@ -1848,7 +1843,7 @@ next_page:
71842 start += PAGE_SIZE;
71843 nr_pages--;
71844 } while (nr_pages && start < vma->vm_end);
71845- } while (nr_pages);
71846+ }
71847 return i;
71848 }
71849 EXPORT_SYMBOL(__get_user_pages);
71850@@ -2055,6 +2050,10 @@ static int insert_page(struct vm_area_struct *vma, unsigned long addr,
71851 page_add_file_rmap(page);
71852 set_pte_at(mm, addr, pte, mk_pte(page, prot));
71853
71854+#ifdef CONFIG_PAX_SEGMEXEC
71855+ pax_mirror_file_pte(vma, addr, page, ptl);
71856+#endif
71857+
71858 retval = 0;
71859 pte_unmap_unlock(pte, ptl);
71860 return retval;
71861@@ -2089,10 +2088,22 @@ out:
71862 int vm_insert_page(struct vm_area_struct *vma, unsigned long addr,
71863 struct page *page)
71864 {
71865+
71866+#ifdef CONFIG_PAX_SEGMEXEC
71867+ struct vm_area_struct *vma_m;
71868+#endif
71869+
71870 if (addr < vma->vm_start || addr >= vma->vm_end)
71871 return -EFAULT;
71872 if (!page_count(page))
71873 return -EINVAL;
71874+
71875+#ifdef CONFIG_PAX_SEGMEXEC
71876+ vma_m = pax_find_mirror_vma(vma);
71877+ if (vma_m)
71878+ vma_m->vm_flags |= VM_INSERTPAGE;
71879+#endif
71880+
71881 vma->vm_flags |= VM_INSERTPAGE;
71882 return insert_page(vma, addr, page, vma->vm_page_prot);
71883 }
71884@@ -2178,6 +2189,7 @@ int vm_insert_mixed(struct vm_area_struct *vma, unsigned long addr,
71885 unsigned long pfn)
71886 {
71887 BUG_ON(!(vma->vm_flags & VM_MIXEDMAP));
71888+ BUG_ON(vma->vm_mirror);
71889
71890 if (addr < vma->vm_start || addr >= vma->vm_end)
71891 return -EFAULT;
71892@@ -2385,7 +2397,9 @@ static int apply_to_pmd_range(struct mm_struct *mm, pud_t *pud,
71893
71894 BUG_ON(pud_huge(*pud));
71895
71896- pmd = pmd_alloc(mm, pud, addr);
71897+ pmd = (mm == &init_mm) ?
71898+ pmd_alloc_kernel(mm, pud, addr) :
71899+ pmd_alloc(mm, pud, addr);
71900 if (!pmd)
71901 return -ENOMEM;
71902 do {
71903@@ -2405,7 +2419,9 @@ static int apply_to_pud_range(struct mm_struct *mm, pgd_t *pgd,
71904 unsigned long next;
71905 int err;
71906
71907- pud = pud_alloc(mm, pgd, addr);
71908+ pud = (mm == &init_mm) ?
71909+ pud_alloc_kernel(mm, pgd, addr) :
71910+ pud_alloc(mm, pgd, addr);
71911 if (!pud)
71912 return -ENOMEM;
71913 do {
71914@@ -2493,6 +2509,186 @@ static inline void cow_user_page(struct page *dst, struct page *src, unsigned lo
71915 copy_user_highpage(dst, src, va, vma);
71916 }
71917
71918+#ifdef CONFIG_PAX_SEGMEXEC
71919+static void pax_unmap_mirror_pte(struct vm_area_struct *vma, unsigned long address, pmd_t *pmd)
71920+{
71921+ struct mm_struct *mm = vma->vm_mm;
71922+ spinlock_t *ptl;
71923+ pte_t *pte, entry;
71924+
71925+ pte = pte_offset_map_lock(mm, pmd, address, &ptl);
71926+ entry = *pte;
71927+ if (!pte_present(entry)) {
71928+ if (!pte_none(entry)) {
71929+ BUG_ON(pte_file(entry));
71930+ free_swap_and_cache(pte_to_swp_entry(entry));
71931+ pte_clear_not_present_full(mm, address, pte, 0);
71932+ }
71933+ } else {
71934+ struct page *page;
71935+
71936+ flush_cache_page(vma, address, pte_pfn(entry));
71937+ entry = ptep_clear_flush(vma, address, pte);
71938+ BUG_ON(pte_dirty(entry));
71939+ page = vm_normal_page(vma, address, entry);
71940+ if (page) {
71941+ update_hiwater_rss(mm);
71942+ if (PageAnon(page))
71943+ dec_mm_counter_fast(mm, MM_ANONPAGES);
71944+ else
71945+ dec_mm_counter_fast(mm, MM_FILEPAGES);
71946+ page_remove_rmap(page);
71947+ page_cache_release(page);
71948+ }
71949+ }
71950+ pte_unmap_unlock(pte, ptl);
71951+}
71952+
71953+/* PaX: if vma is mirrored, synchronize the mirror's PTE
71954+ *
71955+ * the ptl of the lower mapped page is held on entry and is not released on exit
71956+ * or inside to ensure atomic changes to the PTE states (swapout, mremap, munmap, etc)
71957+ */
71958+static void pax_mirror_anon_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m, spinlock_t *ptl)
71959+{
71960+ struct mm_struct *mm = vma->vm_mm;
71961+ unsigned long address_m;
71962+ spinlock_t *ptl_m;
71963+ struct vm_area_struct *vma_m;
71964+ pmd_t *pmd_m;
71965+ pte_t *pte_m, entry_m;
71966+
71967+ BUG_ON(!page_m || !PageAnon(page_m));
71968+
71969+ vma_m = pax_find_mirror_vma(vma);
71970+ if (!vma_m)
71971+ return;
71972+
71973+ BUG_ON(!PageLocked(page_m));
71974+ BUG_ON(address >= SEGMEXEC_TASK_SIZE);
71975+ address_m = address + SEGMEXEC_TASK_SIZE;
71976+ pmd_m = pmd_offset(pud_offset(pgd_offset(mm, address_m), address_m), address_m);
71977+ pte_m = pte_offset_map(pmd_m, address_m);
71978+ ptl_m = pte_lockptr(mm, pmd_m);
71979+ if (ptl != ptl_m) {
71980+ spin_lock_nested(ptl_m, SINGLE_DEPTH_NESTING);
71981+ if (!pte_none(*pte_m))
71982+ goto out;
71983+ }
71984+
71985+ entry_m = pfn_pte(page_to_pfn(page_m), vma_m->vm_page_prot);
71986+ page_cache_get(page_m);
71987+ page_add_anon_rmap(page_m, vma_m, address_m);
71988+ inc_mm_counter_fast(mm, MM_ANONPAGES);
71989+ set_pte_at(mm, address_m, pte_m, entry_m);
71990+ update_mmu_cache(vma_m, address_m, entry_m);
71991+out:
71992+ if (ptl != ptl_m)
71993+ spin_unlock(ptl_m);
71994+ pte_unmap(pte_m);
71995+ unlock_page(page_m);
71996+}
71997+
71998+void pax_mirror_file_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m, spinlock_t *ptl)
71999+{
72000+ struct mm_struct *mm = vma->vm_mm;
72001+ unsigned long address_m;
72002+ spinlock_t *ptl_m;
72003+ struct vm_area_struct *vma_m;
72004+ pmd_t *pmd_m;
72005+ pte_t *pte_m, entry_m;
72006+
72007+ BUG_ON(!page_m || PageAnon(page_m));
72008+
72009+ vma_m = pax_find_mirror_vma(vma);
72010+ if (!vma_m)
72011+ return;
72012+
72013+ BUG_ON(address >= SEGMEXEC_TASK_SIZE);
72014+ address_m = address + SEGMEXEC_TASK_SIZE;
72015+ pmd_m = pmd_offset(pud_offset(pgd_offset(mm, address_m), address_m), address_m);
72016+ pte_m = pte_offset_map(pmd_m, address_m);
72017+ ptl_m = pte_lockptr(mm, pmd_m);
72018+ if (ptl != ptl_m) {
72019+ spin_lock_nested(ptl_m, SINGLE_DEPTH_NESTING);
72020+ if (!pte_none(*pte_m))
72021+ goto out;
72022+ }
72023+
72024+ entry_m = pfn_pte(page_to_pfn(page_m), vma_m->vm_page_prot);
72025+ page_cache_get(page_m);
72026+ page_add_file_rmap(page_m);
72027+ inc_mm_counter_fast(mm, MM_FILEPAGES);
72028+ set_pte_at(mm, address_m, pte_m, entry_m);
72029+ update_mmu_cache(vma_m, address_m, entry_m);
72030+out:
72031+ if (ptl != ptl_m)
72032+ spin_unlock(ptl_m);
72033+ pte_unmap(pte_m);
72034+}
72035+
72036+static void pax_mirror_pfn_pte(struct vm_area_struct *vma, unsigned long address, unsigned long pfn_m, spinlock_t *ptl)
72037+{
72038+ struct mm_struct *mm = vma->vm_mm;
72039+ unsigned long address_m;
72040+ spinlock_t *ptl_m;
72041+ struct vm_area_struct *vma_m;
72042+ pmd_t *pmd_m;
72043+ pte_t *pte_m, entry_m;
72044+
72045+ vma_m = pax_find_mirror_vma(vma);
72046+ if (!vma_m)
72047+ return;
72048+
72049+ BUG_ON(address >= SEGMEXEC_TASK_SIZE);
72050+ address_m = address + SEGMEXEC_TASK_SIZE;
72051+ pmd_m = pmd_offset(pud_offset(pgd_offset(mm, address_m), address_m), address_m);
72052+ pte_m = pte_offset_map(pmd_m, address_m);
72053+ ptl_m = pte_lockptr(mm, pmd_m);
72054+ if (ptl != ptl_m) {
72055+ spin_lock_nested(ptl_m, SINGLE_DEPTH_NESTING);
72056+ if (!pte_none(*pte_m))
72057+ goto out;
72058+ }
72059+
72060+ entry_m = pfn_pte(pfn_m, vma_m->vm_page_prot);
72061+ set_pte_at(mm, address_m, pte_m, entry_m);
72062+out:
72063+ if (ptl != ptl_m)
72064+ spin_unlock(ptl_m);
72065+ pte_unmap(pte_m);
72066+}
72067+
72068+static void pax_mirror_pte(struct vm_area_struct *vma, unsigned long address, pte_t *pte, pmd_t *pmd, spinlock_t *ptl)
72069+{
72070+ struct page *page_m;
72071+ pte_t entry;
72072+
72073+ if (!(vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC))
72074+ goto out;
72075+
72076+ entry = *pte;
72077+ page_m = vm_normal_page(vma, address, entry);
72078+ if (!page_m)
72079+ pax_mirror_pfn_pte(vma, address, pte_pfn(entry), ptl);
72080+ else if (PageAnon(page_m)) {
72081+ if (pax_find_mirror_vma(vma)) {
72082+ pte_unmap_unlock(pte, ptl);
72083+ lock_page(page_m);
72084+ pte = pte_offset_map_lock(vma->vm_mm, pmd, address, &ptl);
72085+ if (pte_same(entry, *pte))
72086+ pax_mirror_anon_pte(vma, address, page_m, ptl);
72087+ else
72088+ unlock_page(page_m);
72089+ }
72090+ } else
72091+ pax_mirror_file_pte(vma, address, page_m, ptl);
72092+
72093+out:
72094+ pte_unmap_unlock(pte, ptl);
72095+}
72096+#endif
72097+
72098 /*
72099 * This routine handles present pages, when users try to write
72100 * to a shared page. It is done by copying the page to a new address
72101@@ -2703,6 +2899,12 @@ gotten:
72102 */
72103 page_table = pte_offset_map_lock(mm, pmd, address, &ptl);
72104 if (likely(pte_same(*page_table, orig_pte))) {
72105+
72106+#ifdef CONFIG_PAX_SEGMEXEC
72107+ if (pax_find_mirror_vma(vma))
72108+ BUG_ON(!trylock_page(new_page));
72109+#endif
72110+
72111 if (old_page) {
72112 if (!PageAnon(old_page)) {
72113 dec_mm_counter_fast(mm, MM_FILEPAGES);
72114@@ -2754,6 +2956,10 @@ gotten:
72115 page_remove_rmap(old_page);
72116 }
72117
72118+#ifdef CONFIG_PAX_SEGMEXEC
72119+ pax_mirror_anon_pte(vma, address, new_page, ptl);
72120+#endif
72121+
72122 /* Free the old page.. */
72123 new_page = old_page;
72124 ret |= VM_FAULT_WRITE;
72125@@ -3033,6 +3239,11 @@ static int do_swap_page(struct mm_struct *mm, struct vm_area_struct *vma,
72126 swap_free(entry);
72127 if (vm_swap_full() || (vma->vm_flags & VM_LOCKED) || PageMlocked(page))
72128 try_to_free_swap(page);
72129+
72130+#ifdef CONFIG_PAX_SEGMEXEC
72131+ if ((flags & FAULT_FLAG_WRITE) || !pax_find_mirror_vma(vma))
72132+#endif
72133+
72134 unlock_page(page);
72135 if (swapcache) {
72136 /*
72137@@ -3056,6 +3267,11 @@ static int do_swap_page(struct mm_struct *mm, struct vm_area_struct *vma,
72138
72139 /* No need to invalidate - it was non-present before */
72140 update_mmu_cache(vma, address, page_table);
72141+
72142+#ifdef CONFIG_PAX_SEGMEXEC
72143+ pax_mirror_anon_pte(vma, address, page, ptl);
72144+#endif
72145+
72146 unlock:
72147 pte_unmap_unlock(page_table, ptl);
72148 out:
72149@@ -3075,40 +3291,6 @@ out_release:
72150 }
72151
72152 /*
72153- * This is like a special single-page "expand_{down|up}wards()",
72154- * except we must first make sure that 'address{-|+}PAGE_SIZE'
72155- * doesn't hit another vma.
72156- */
72157-static inline int check_stack_guard_page(struct vm_area_struct *vma, unsigned long address)
72158-{
72159- address &= PAGE_MASK;
72160- if ((vma->vm_flags & VM_GROWSDOWN) && address == vma->vm_start) {
72161- struct vm_area_struct *prev = vma->vm_prev;
72162-
72163- /*
72164- * Is there a mapping abutting this one below?
72165- *
72166- * That's only ok if it's the same stack mapping
72167- * that has gotten split..
72168- */
72169- if (prev && prev->vm_end == address)
72170- return prev->vm_flags & VM_GROWSDOWN ? 0 : -ENOMEM;
72171-
72172- expand_downwards(vma, address - PAGE_SIZE);
72173- }
72174- if ((vma->vm_flags & VM_GROWSUP) && address + PAGE_SIZE == vma->vm_end) {
72175- struct vm_area_struct *next = vma->vm_next;
72176-
72177- /* As VM_GROWSDOWN but s/below/above/ */
72178- if (next && next->vm_start == address + PAGE_SIZE)
72179- return next->vm_flags & VM_GROWSUP ? 0 : -ENOMEM;
72180-
72181- expand_upwards(vma, address + PAGE_SIZE);
72182- }
72183- return 0;
72184-}
72185-
72186-/*
72187 * We enter with non-exclusive mmap_sem (to exclude vma changes,
72188 * but allow concurrent faults), and pte mapped but not yet locked.
72189 * We return with mmap_sem still held, but pte unmapped and unlocked.
72190@@ -3117,27 +3299,23 @@ static int do_anonymous_page(struct mm_struct *mm, struct vm_area_struct *vma,
72191 unsigned long address, pte_t *page_table, pmd_t *pmd,
72192 unsigned int flags)
72193 {
72194- struct page *page;
72195+ struct page *page = NULL;
72196 spinlock_t *ptl;
72197 pte_t entry;
72198
72199- pte_unmap(page_table);
72200-
72201- /* Check if we need to add a guard page to the stack */
72202- if (check_stack_guard_page(vma, address) < 0)
72203- return VM_FAULT_SIGBUS;
72204-
72205- /* Use the zero-page for reads */
72206 if (!(flags & FAULT_FLAG_WRITE)) {
72207 entry = pte_mkspecial(pfn_pte(my_zero_pfn(address),
72208 vma->vm_page_prot));
72209- page_table = pte_offset_map_lock(mm, pmd, address, &ptl);
72210+ ptl = pte_lockptr(mm, pmd);
72211+ spin_lock(ptl);
72212 if (!pte_none(*page_table))
72213 goto unlock;
72214 goto setpte;
72215 }
72216
72217 /* Allocate our own private page. */
72218+ pte_unmap(page_table);
72219+
72220 if (unlikely(anon_vma_prepare(vma)))
72221 goto oom;
72222 page = alloc_zeroed_user_highpage_movable(vma, address);
72223@@ -3156,6 +3334,11 @@ static int do_anonymous_page(struct mm_struct *mm, struct vm_area_struct *vma,
72224 if (!pte_none(*page_table))
72225 goto release;
72226
72227+#ifdef CONFIG_PAX_SEGMEXEC
72228+ if (pax_find_mirror_vma(vma))
72229+ BUG_ON(!trylock_page(page));
72230+#endif
72231+
72232 inc_mm_counter_fast(mm, MM_ANONPAGES);
72233 page_add_new_anon_rmap(page, vma, address);
72234 setpte:
72235@@ -3163,6 +3346,12 @@ setpte:
72236
72237 /* No need to invalidate - it was non-present before */
72238 update_mmu_cache(vma, address, page_table);
72239+
72240+#ifdef CONFIG_PAX_SEGMEXEC
72241+ if (page)
72242+ pax_mirror_anon_pte(vma, address, page, ptl);
72243+#endif
72244+
72245 unlock:
72246 pte_unmap_unlock(page_table, ptl);
72247 return 0;
72248@@ -3306,6 +3495,12 @@ static int __do_fault(struct mm_struct *mm, struct vm_area_struct *vma,
72249 */
72250 /* Only go through if we didn't race with anybody else... */
72251 if (likely(pte_same(*page_table, orig_pte))) {
72252+
72253+#ifdef CONFIG_PAX_SEGMEXEC
72254+ if (anon && pax_find_mirror_vma(vma))
72255+ BUG_ON(!trylock_page(page));
72256+#endif
72257+
72258 flush_icache_page(vma, page);
72259 entry = mk_pte(page, vma->vm_page_prot);
72260 if (flags & FAULT_FLAG_WRITE)
72261@@ -3325,6 +3520,14 @@ static int __do_fault(struct mm_struct *mm, struct vm_area_struct *vma,
72262
72263 /* no need to invalidate: a not-present page won't be cached */
72264 update_mmu_cache(vma, address, page_table);
72265+
72266+#ifdef CONFIG_PAX_SEGMEXEC
72267+ if (anon)
72268+ pax_mirror_anon_pte(vma, address, page, ptl);
72269+ else
72270+ pax_mirror_file_pte(vma, address, page, ptl);
72271+#endif
72272+
72273 } else {
72274 if (cow_page)
72275 mem_cgroup_uncharge_page(cow_page);
72276@@ -3479,6 +3682,12 @@ int handle_pte_fault(struct mm_struct *mm,
72277 if (flags & FAULT_FLAG_WRITE)
72278 flush_tlb_fix_spurious_fault(vma, address);
72279 }
72280+
72281+#ifdef CONFIG_PAX_SEGMEXEC
72282+ pax_mirror_pte(vma, address, pte, pmd, ptl);
72283+ return 0;
72284+#endif
72285+
72286 unlock:
72287 pte_unmap_unlock(pte, ptl);
72288 return 0;
72289@@ -3495,6 +3704,10 @@ int handle_mm_fault(struct mm_struct *mm, struct vm_area_struct *vma,
72290 pmd_t *pmd;
72291 pte_t *pte;
72292
72293+#ifdef CONFIG_PAX_SEGMEXEC
72294+ struct vm_area_struct *vma_m;
72295+#endif
72296+
72297 __set_current_state(TASK_RUNNING);
72298
72299 count_vm_event(PGFAULT);
72300@@ -3506,6 +3719,34 @@ int handle_mm_fault(struct mm_struct *mm, struct vm_area_struct *vma,
72301 if (unlikely(is_vm_hugetlb_page(vma)))
72302 return hugetlb_fault(mm, vma, address, flags);
72303
72304+#ifdef CONFIG_PAX_SEGMEXEC
72305+ vma_m = pax_find_mirror_vma(vma);
72306+ if (vma_m) {
72307+ unsigned long address_m;
72308+ pgd_t *pgd_m;
72309+ pud_t *pud_m;
72310+ pmd_t *pmd_m;
72311+
72312+ if (vma->vm_start > vma_m->vm_start) {
72313+ address_m = address;
72314+ address -= SEGMEXEC_TASK_SIZE;
72315+ vma = vma_m;
72316+ } else
72317+ address_m = address + SEGMEXEC_TASK_SIZE;
72318+
72319+ pgd_m = pgd_offset(mm, address_m);
72320+ pud_m = pud_alloc(mm, pgd_m, address_m);
72321+ if (!pud_m)
72322+ return VM_FAULT_OOM;
72323+ pmd_m = pmd_alloc(mm, pud_m, address_m);
72324+ if (!pmd_m)
72325+ return VM_FAULT_OOM;
72326+ if (!pmd_present(*pmd_m) && __pte_alloc(mm, vma_m, pmd_m, address_m))
72327+ return VM_FAULT_OOM;
72328+ pax_unmap_mirror_pte(vma_m, address_m, pmd_m);
72329+ }
72330+#endif
72331+
72332 retry:
72333 pgd = pgd_offset(mm, address);
72334 pud = pud_alloc(mm, pgd, address);
72335@@ -3547,7 +3788,7 @@ retry:
72336 * run pte_offset_map on the pmd, if an huge pmd could
72337 * materialize from under us from a different thread.
72338 */
72339- if (unlikely(pmd_none(*pmd)) && __pte_alloc(mm, vma, pmd, address))
72340+ if (unlikely(pmd_none(*pmd) && __pte_alloc(mm, vma, pmd, address)))
72341 return VM_FAULT_OOM;
72342 /* if an huge pmd materialized from under us just retry later */
72343 if (unlikely(pmd_trans_huge(*pmd)))
72344@@ -3584,6 +3825,23 @@ int __pud_alloc(struct mm_struct *mm, pgd_t *pgd, unsigned long address)
72345 spin_unlock(&mm->page_table_lock);
72346 return 0;
72347 }
72348+
72349+int __pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd, unsigned long address)
72350+{
72351+ pud_t *new = pud_alloc_one(mm, address);
72352+ if (!new)
72353+ return -ENOMEM;
72354+
72355+ smp_wmb(); /* See comment in __pte_alloc */
72356+
72357+ spin_lock(&mm->page_table_lock);
72358+ if (pgd_present(*pgd)) /* Another has populated it */
72359+ pud_free(mm, new);
72360+ else
72361+ pgd_populate_kernel(mm, pgd, new);
72362+ spin_unlock(&mm->page_table_lock);
72363+ return 0;
72364+}
72365 #endif /* __PAGETABLE_PUD_FOLDED */
72366
72367 #ifndef __PAGETABLE_PMD_FOLDED
72368@@ -3614,6 +3872,30 @@ int __pmd_alloc(struct mm_struct *mm, pud_t *pud, unsigned long address)
72369 spin_unlock(&mm->page_table_lock);
72370 return 0;
72371 }
72372+
72373+int __pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud, unsigned long address)
72374+{
72375+ pmd_t *new = pmd_alloc_one(mm, address);
72376+ if (!new)
72377+ return -ENOMEM;
72378+
72379+ smp_wmb(); /* See comment in __pte_alloc */
72380+
72381+ spin_lock(&mm->page_table_lock);
72382+#ifndef __ARCH_HAS_4LEVEL_HACK
72383+ if (pud_present(*pud)) /* Another has populated it */
72384+ pmd_free(mm, new);
72385+ else
72386+ pud_populate_kernel(mm, pud, new);
72387+#else
72388+ if (pgd_present(*pud)) /* Another has populated it */
72389+ pmd_free(mm, new);
72390+ else
72391+ pgd_populate_kernel(mm, pud, new);
72392+#endif /* __ARCH_HAS_4LEVEL_HACK */
72393+ spin_unlock(&mm->page_table_lock);
72394+ return 0;
72395+}
72396 #endif /* __PAGETABLE_PMD_FOLDED */
72397
72398 int make_pages_present(unsigned long addr, unsigned long end)
72399@@ -3651,7 +3933,7 @@ static int __init gate_vma_init(void)
72400 gate_vma.vm_start = FIXADDR_USER_START;
72401 gate_vma.vm_end = FIXADDR_USER_END;
72402 gate_vma.vm_flags = VM_READ | VM_MAYREAD | VM_EXEC | VM_MAYEXEC;
72403- gate_vma.vm_page_prot = __P101;
72404+ gate_vma.vm_page_prot = vm_get_page_prot(gate_vma.vm_flags);
72405
72406 return 0;
72407 }
72408diff --git a/mm/mempolicy.c b/mm/mempolicy.c
72409index 3d64b36..dbab433 100644
72410--- a/mm/mempolicy.c
72411+++ b/mm/mempolicy.c
72412@@ -655,6 +655,10 @@ static int mbind_range(struct mm_struct *mm, unsigned long start,
72413 unsigned long vmstart;
72414 unsigned long vmend;
72415
72416+#ifdef CONFIG_PAX_SEGMEXEC
72417+ struct vm_area_struct *vma_m;
72418+#endif
72419+
72420 vma = find_vma(mm, start);
72421 if (!vma || vma->vm_start > start)
72422 return -EFAULT;
72423@@ -691,9 +695,18 @@ static int mbind_range(struct mm_struct *mm, unsigned long start,
72424 if (err)
72425 goto out;
72426 }
72427+
72428 err = vma_replace_policy(vma, new_pol);
72429 if (err)
72430 goto out;
72431+
72432+#ifdef CONFIG_PAX_SEGMEXEC
72433+ vma_m = pax_find_mirror_vma(vma);
72434+ err = vma_replace_policy(vma_m, new_pol);
72435+ if (err)
72436+ goto out;
72437+#endif
72438+
72439 }
72440
72441 out:
72442@@ -1147,6 +1160,17 @@ static long do_mbind(unsigned long start, unsigned long len,
72443
72444 if (end < start)
72445 return -EINVAL;
72446+
72447+#ifdef CONFIG_PAX_SEGMEXEC
72448+ if (mm->pax_flags & MF_PAX_SEGMEXEC) {
72449+ if (end > SEGMEXEC_TASK_SIZE)
72450+ return -EINVAL;
72451+ } else
72452+#endif
72453+
72454+ if (end > TASK_SIZE)
72455+ return -EINVAL;
72456+
72457 if (end == start)
72458 return 0;
72459
72460@@ -1370,8 +1394,7 @@ SYSCALL_DEFINE4(migrate_pages, pid_t, pid, unsigned long, maxnode,
72461 */
72462 tcred = __task_cred(task);
72463 if (!uid_eq(cred->euid, tcred->suid) && !uid_eq(cred->euid, tcred->uid) &&
72464- !uid_eq(cred->uid, tcred->suid) && !uid_eq(cred->uid, tcred->uid) &&
72465- !capable(CAP_SYS_NICE)) {
72466+ !uid_eq(cred->uid, tcred->suid) && !capable(CAP_SYS_NICE)) {
72467 rcu_read_unlock();
72468 err = -EPERM;
72469 goto out_put;
72470@@ -1402,6 +1425,15 @@ SYSCALL_DEFINE4(migrate_pages, pid_t, pid, unsigned long, maxnode,
72471 goto out;
72472 }
72473
72474+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
72475+ if (mm != current->mm &&
72476+ (mm->pax_flags & MF_PAX_RANDMMAP || mm->pax_flags & MF_PAX_SEGMEXEC)) {
72477+ mmput(mm);
72478+ err = -EPERM;
72479+ goto out;
72480+ }
72481+#endif
72482+
72483 err = do_migrate_pages(mm, old, new,
72484 capable(CAP_SYS_NICE) ? MPOL_MF_MOVE_ALL : MPOL_MF_MOVE);
72485
72486diff --git a/mm/migrate.c b/mm/migrate.c
72487index 77ed2d7..317d528 100644
72488--- a/mm/migrate.c
72489+++ b/mm/migrate.c
72490@@ -1350,8 +1350,7 @@ SYSCALL_DEFINE6(move_pages, pid_t, pid, unsigned long, nr_pages,
72491 */
72492 tcred = __task_cred(task);
72493 if (!uid_eq(cred->euid, tcred->suid) && !uid_eq(cred->euid, tcred->uid) &&
72494- !uid_eq(cred->uid, tcred->suid) && !uid_eq(cred->uid, tcred->uid) &&
72495- !capable(CAP_SYS_NICE)) {
72496+ !uid_eq(cred->uid, tcred->suid) && !capable(CAP_SYS_NICE)) {
72497 rcu_read_unlock();
72498 err = -EPERM;
72499 goto out;
72500diff --git a/mm/mlock.c b/mm/mlock.c
72501index ef726e8..cd7f1ec 100644
72502--- a/mm/mlock.c
72503+++ b/mm/mlock.c
72504@@ -13,6 +13,7 @@
72505 #include <linux/pagemap.h>
72506 #include <linux/mempolicy.h>
72507 #include <linux/syscalls.h>
72508+#include <linux/security.h>
72509 #include <linux/sched.h>
72510 #include <linux/export.h>
72511 #include <linux/rmap.h>
72512@@ -376,7 +377,7 @@ static int do_mlock(unsigned long start, size_t len, int on)
72513 {
72514 unsigned long nstart, end, tmp;
72515 struct vm_area_struct * vma, * prev;
72516- int error;
72517+ int error = 0;
72518
72519 VM_BUG_ON(start & ~PAGE_MASK);
72520 VM_BUG_ON(len != PAGE_ALIGN(len));
72521@@ -385,6 +386,9 @@ static int do_mlock(unsigned long start, size_t len, int on)
72522 return -EINVAL;
72523 if (end == start)
72524 return 0;
72525+ if (end > TASK_SIZE)
72526+ return -EINVAL;
72527+
72528 vma = find_vma(current->mm, start);
72529 if (!vma || vma->vm_start > start)
72530 return -ENOMEM;
72531@@ -396,6 +400,11 @@ static int do_mlock(unsigned long start, size_t len, int on)
72532 for (nstart = start ; ; ) {
72533 vm_flags_t newflags;
72534
72535+#ifdef CONFIG_PAX_SEGMEXEC
72536+ if ((current->mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_start >= SEGMEXEC_TASK_SIZE))
72537+ break;
72538+#endif
72539+
72540 /* Here we know that vma->vm_start <= nstart < vma->vm_end. */
72541
72542 newflags = vma->vm_flags | VM_LOCKED;
72543@@ -501,6 +510,7 @@ SYSCALL_DEFINE2(mlock, unsigned long, start, size_t, len)
72544 lock_limit >>= PAGE_SHIFT;
72545
72546 /* check against resource limits */
72547+ gr_learn_resource(current, RLIMIT_MEMLOCK, (current->mm->locked_vm << PAGE_SHIFT) + len, 1);
72548 if ((locked <= lock_limit) || capable(CAP_IPC_LOCK))
72549 error = do_mlock(start, len, 1);
72550 up_write(&current->mm->mmap_sem);
72551@@ -524,17 +534,23 @@ SYSCALL_DEFINE2(munlock, unsigned long, start, size_t, len)
72552 static int do_mlockall(int flags)
72553 {
72554 struct vm_area_struct * vma, * prev = NULL;
72555- unsigned int def_flags = 0;
72556
72557 if (flags & MCL_FUTURE)
72558- def_flags = VM_LOCKED;
72559- current->mm->def_flags = def_flags;
72560+ current->mm->def_flags |= VM_LOCKED;
72561+ else
72562+ current->mm->def_flags &= ~VM_LOCKED;
72563 if (flags == MCL_FUTURE)
72564 goto out;
72565
72566 for (vma = current->mm->mmap; vma ; vma = prev->vm_next) {
72567 vm_flags_t newflags;
72568
72569+#ifdef CONFIG_PAX_SEGMEXEC
72570+ if ((current->mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_start >= SEGMEXEC_TASK_SIZE))
72571+ break;
72572+#endif
72573+
72574+ BUG_ON(vma->vm_end > TASK_SIZE);
72575 newflags = vma->vm_flags | VM_LOCKED;
72576 if (!(flags & MCL_CURRENT))
72577 newflags &= ~VM_LOCKED;
72578@@ -567,6 +583,7 @@ SYSCALL_DEFINE1(mlockall, int, flags)
72579 lock_limit >>= PAGE_SHIFT;
72580
72581 ret = -ENOMEM;
72582+ gr_learn_resource(current, RLIMIT_MEMLOCK, current->mm->total_vm << PAGE_SHIFT, 1);
72583 if (!(flags & MCL_CURRENT) || (current->mm->total_vm <= lock_limit) ||
72584 capable(CAP_IPC_LOCK))
72585 ret = do_mlockall(flags);
72586diff --git a/mm/mmap.c b/mm/mmap.c
72587index ae18a48..86cf99e 100644
72588--- a/mm/mmap.c
72589+++ b/mm/mmap.c
72590@@ -47,6 +47,16 @@
72591 #define arch_rebalance_pgtables(addr, len) (addr)
72592 #endif
72593
72594+static inline void verify_mm_writelocked(struct mm_struct *mm)
72595+{
72596+#if defined(CONFIG_DEBUG_VM) || defined(CONFIG_PAX)
72597+ if (unlikely(down_read_trylock(&mm->mmap_sem))) {
72598+ up_read(&mm->mmap_sem);
72599+ BUG();
72600+ }
72601+#endif
72602+}
72603+
72604 static void unmap_region(struct mm_struct *mm,
72605 struct vm_area_struct *vma, struct vm_area_struct *prev,
72606 unsigned long start, unsigned long end);
72607@@ -72,22 +82,32 @@ static void unmap_region(struct mm_struct *mm,
72608 * x: (no) no x: (no) yes x: (no) yes x: (yes) yes
72609 *
72610 */
72611-pgprot_t protection_map[16] = {
72612+pgprot_t protection_map[16] __read_only = {
72613 __P000, __P001, __P010, __P011, __P100, __P101, __P110, __P111,
72614 __S000, __S001, __S010, __S011, __S100, __S101, __S110, __S111
72615 };
72616
72617-pgprot_t vm_get_page_prot(unsigned long vm_flags)
72618+pgprot_t vm_get_page_prot(vm_flags_t vm_flags)
72619 {
72620- return __pgprot(pgprot_val(protection_map[vm_flags &
72621+ pgprot_t prot = __pgprot(pgprot_val(protection_map[vm_flags &
72622 (VM_READ|VM_WRITE|VM_EXEC|VM_SHARED)]) |
72623 pgprot_val(arch_vm_get_page_prot(vm_flags)));
72624+
72625+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
72626+ if (!(__supported_pte_mask & _PAGE_NX) &&
72627+ (vm_flags & (VM_PAGEEXEC | VM_EXEC)) == VM_PAGEEXEC &&
72628+ (vm_flags & (VM_READ | VM_WRITE)))
72629+ prot = __pgprot(pte_val(pte_exprotect(__pte(pgprot_val(prot)))));
72630+#endif
72631+
72632+ return prot;
72633 }
72634 EXPORT_SYMBOL(vm_get_page_prot);
72635
72636 int sysctl_overcommit_memory __read_mostly = OVERCOMMIT_GUESS; /* heuristic overcommit */
72637 int sysctl_overcommit_ratio __read_mostly = 50; /* default is 50% */
72638 int sysctl_max_map_count __read_mostly = DEFAULT_MAX_MAP_COUNT;
72639+unsigned long sysctl_heap_stack_gap __read_mostly = 64*1024;
72640 /*
72641 * Make sure vm_committed_as in one cacheline and not cacheline shared with
72642 * other variables. It can be updated by several CPUs frequently.
72643@@ -229,6 +249,7 @@ static struct vm_area_struct *remove_vma(struct vm_area_struct *vma)
72644 struct vm_area_struct *next = vma->vm_next;
72645
72646 might_sleep();
72647+ BUG_ON(vma->vm_mirror);
72648 if (vma->vm_ops && vma->vm_ops->close)
72649 vma->vm_ops->close(vma);
72650 if (vma->vm_file) {
72651@@ -275,6 +296,7 @@ SYSCALL_DEFINE1(brk, unsigned long, brk)
72652 * not page aligned -Ram Gupta
72653 */
72654 rlim = rlimit(RLIMIT_DATA);
72655+ gr_learn_resource(current, RLIMIT_DATA, (brk - mm->start_brk) + (mm->end_data - mm->start_data), 1);
72656 if (rlim < RLIM_INFINITY && (brk - mm->start_brk) +
72657 (mm->end_data - mm->start_data) > rlim)
72658 goto out;
72659@@ -708,6 +730,12 @@ static int
72660 can_vma_merge_before(struct vm_area_struct *vma, unsigned long vm_flags,
72661 struct anon_vma *anon_vma, struct file *file, pgoff_t vm_pgoff)
72662 {
72663+
72664+#ifdef CONFIG_PAX_SEGMEXEC
72665+ if ((vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) && vma->vm_start == SEGMEXEC_TASK_SIZE)
72666+ return 0;
72667+#endif
72668+
72669 if (is_mergeable_vma(vma, file, vm_flags) &&
72670 is_mergeable_anon_vma(anon_vma, vma->anon_vma, vma)) {
72671 if (vma->vm_pgoff == vm_pgoff)
72672@@ -727,6 +755,12 @@ static int
72673 can_vma_merge_after(struct vm_area_struct *vma, unsigned long vm_flags,
72674 struct anon_vma *anon_vma, struct file *file, pgoff_t vm_pgoff)
72675 {
72676+
72677+#ifdef CONFIG_PAX_SEGMEXEC
72678+ if ((vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) && vma->vm_end == SEGMEXEC_TASK_SIZE)
72679+ return 0;
72680+#endif
72681+
72682 if (is_mergeable_vma(vma, file, vm_flags) &&
72683 is_mergeable_anon_vma(anon_vma, vma->anon_vma, vma)) {
72684 pgoff_t vm_pglen;
72685@@ -769,13 +803,20 @@ can_vma_merge_after(struct vm_area_struct *vma, unsigned long vm_flags,
72686 struct vm_area_struct *vma_merge(struct mm_struct *mm,
72687 struct vm_area_struct *prev, unsigned long addr,
72688 unsigned long end, unsigned long vm_flags,
72689- struct anon_vma *anon_vma, struct file *file,
72690+ struct anon_vma *anon_vma, struct file *file,
72691 pgoff_t pgoff, struct mempolicy *policy)
72692 {
72693 pgoff_t pglen = (end - addr) >> PAGE_SHIFT;
72694 struct vm_area_struct *area, *next;
72695 int err;
72696
72697+#ifdef CONFIG_PAX_SEGMEXEC
72698+ unsigned long addr_m = addr + SEGMEXEC_TASK_SIZE, end_m = end + SEGMEXEC_TASK_SIZE;
72699+ struct vm_area_struct *area_m = NULL, *next_m = NULL, *prev_m = NULL;
72700+
72701+ BUG_ON((mm->pax_flags & MF_PAX_SEGMEXEC) && SEGMEXEC_TASK_SIZE < end);
72702+#endif
72703+
72704 /*
72705 * We later require that vma->vm_flags == vm_flags,
72706 * so this tests vma->vm_flags & VM_SPECIAL, too.
72707@@ -791,6 +832,15 @@ struct vm_area_struct *vma_merge(struct mm_struct *mm,
72708 if (next && next->vm_end == end) /* cases 6, 7, 8 */
72709 next = next->vm_next;
72710
72711+#ifdef CONFIG_PAX_SEGMEXEC
72712+ if (prev)
72713+ prev_m = pax_find_mirror_vma(prev);
72714+ if (area)
72715+ area_m = pax_find_mirror_vma(area);
72716+ if (next)
72717+ next_m = pax_find_mirror_vma(next);
72718+#endif
72719+
72720 /*
72721 * Can it merge with the predecessor?
72722 */
72723@@ -810,9 +860,24 @@ struct vm_area_struct *vma_merge(struct mm_struct *mm,
72724 /* cases 1, 6 */
72725 err = vma_adjust(prev, prev->vm_start,
72726 next->vm_end, prev->vm_pgoff, NULL);
72727- } else /* cases 2, 5, 7 */
72728+
72729+#ifdef CONFIG_PAX_SEGMEXEC
72730+ if (!err && prev_m)
72731+ err = vma_adjust(prev_m, prev_m->vm_start,
72732+ next_m->vm_end, prev_m->vm_pgoff, NULL);
72733+#endif
72734+
72735+ } else { /* cases 2, 5, 7 */
72736 err = vma_adjust(prev, prev->vm_start,
72737 end, prev->vm_pgoff, NULL);
72738+
72739+#ifdef CONFIG_PAX_SEGMEXEC
72740+ if (!err && prev_m)
72741+ err = vma_adjust(prev_m, prev_m->vm_start,
72742+ end_m, prev_m->vm_pgoff, NULL);
72743+#endif
72744+
72745+ }
72746 if (err)
72747 return NULL;
72748 khugepaged_enter_vma_merge(prev);
72749@@ -826,12 +891,27 @@ struct vm_area_struct *vma_merge(struct mm_struct *mm,
72750 mpol_equal(policy, vma_policy(next)) &&
72751 can_vma_merge_before(next, vm_flags,
72752 anon_vma, file, pgoff+pglen)) {
72753- if (prev && addr < prev->vm_end) /* case 4 */
72754+ if (prev && addr < prev->vm_end) { /* case 4 */
72755 err = vma_adjust(prev, prev->vm_start,
72756 addr, prev->vm_pgoff, NULL);
72757- else /* cases 3, 8 */
72758+
72759+#ifdef CONFIG_PAX_SEGMEXEC
72760+ if (!err && prev_m)
72761+ err = vma_adjust(prev_m, prev_m->vm_start,
72762+ addr_m, prev_m->vm_pgoff, NULL);
72763+#endif
72764+
72765+ } else { /* cases 3, 8 */
72766 err = vma_adjust(area, addr, next->vm_end,
72767 next->vm_pgoff - pglen, NULL);
72768+
72769+#ifdef CONFIG_PAX_SEGMEXEC
72770+ if (!err && area_m)
72771+ err = vma_adjust(area_m, addr_m, next_m->vm_end,
72772+ next_m->vm_pgoff - pglen, NULL);
72773+#endif
72774+
72775+ }
72776 if (err)
72777 return NULL;
72778 khugepaged_enter_vma_merge(area);
72779@@ -940,16 +1020,13 @@ none:
72780 void vm_stat_account(struct mm_struct *mm, unsigned long flags,
72781 struct file *file, long pages)
72782 {
72783- const unsigned long stack_flags
72784- = VM_STACK_FLAGS & (VM_GROWSUP|VM_GROWSDOWN);
72785-
72786 mm->total_vm += pages;
72787
72788 if (file) {
72789 mm->shared_vm += pages;
72790 if ((flags & (VM_EXEC|VM_WRITE)) == VM_EXEC)
72791 mm->exec_vm += pages;
72792- } else if (flags & stack_flags)
72793+ } else if (flags & (VM_GROWSUP|VM_GROWSDOWN))
72794 mm->stack_vm += pages;
72795 if (flags & (VM_RESERVED|VM_IO))
72796 mm->reserved_vm += pages;
72797@@ -987,7 +1064,7 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
72798 * (the exception is when the underlying filesystem is noexec
72799 * mounted, in which case we dont add PROT_EXEC.)
72800 */
72801- if ((prot & PROT_READ) && (current->personality & READ_IMPLIES_EXEC))
72802+ if ((prot & (PROT_READ | PROT_WRITE)) && (current->personality & READ_IMPLIES_EXEC))
72803 if (!(file && (file->f_path.mnt->mnt_flags & MNT_NOEXEC)))
72804 prot |= PROT_EXEC;
72805
72806@@ -1013,7 +1090,7 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
72807 /* Obtain the address to map to. we verify (or select) it and ensure
72808 * that it represents a valid section of the address space.
72809 */
72810- addr = get_unmapped_area(file, addr, len, pgoff, flags);
72811+ addr = get_unmapped_area(file, addr, len, pgoff, flags | ((prot & PROT_EXEC) ? MAP_EXECUTABLE : 0));
72812 if (addr & ~PAGE_MASK)
72813 return addr;
72814
72815@@ -1024,6 +1101,36 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
72816 vm_flags = calc_vm_prot_bits(prot) | calc_vm_flag_bits(flags) |
72817 mm->def_flags | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC;
72818
72819+#ifdef CONFIG_PAX_MPROTECT
72820+ if (mm->pax_flags & MF_PAX_MPROTECT) {
72821+#ifndef CONFIG_PAX_MPROTECT_COMPAT
72822+ if ((vm_flags & (VM_WRITE | VM_EXEC)) == (VM_WRITE | VM_EXEC)) {
72823+ gr_log_rwxmmap(file);
72824+
72825+#ifdef CONFIG_PAX_EMUPLT
72826+ vm_flags &= ~VM_EXEC;
72827+#else
72828+ return -EPERM;
72829+#endif
72830+
72831+ }
72832+
72833+ if (!(vm_flags & VM_EXEC))
72834+ vm_flags &= ~VM_MAYEXEC;
72835+#else
72836+ if ((vm_flags & (VM_WRITE | VM_EXEC)) != VM_EXEC)
72837+ vm_flags &= ~(VM_EXEC | VM_MAYEXEC);
72838+#endif
72839+ else
72840+ vm_flags &= ~VM_MAYWRITE;
72841+ }
72842+#endif
72843+
72844+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
72845+ if ((mm->pax_flags & MF_PAX_PAGEEXEC) && file)
72846+ vm_flags &= ~VM_PAGEEXEC;
72847+#endif
72848+
72849 if (flags & MAP_LOCKED)
72850 if (!can_do_mlock())
72851 return -EPERM;
72852@@ -1035,6 +1142,7 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
72853 locked += mm->locked_vm;
72854 lock_limit = rlimit(RLIMIT_MEMLOCK);
72855 lock_limit >>= PAGE_SHIFT;
72856+ gr_learn_resource(current, RLIMIT_MEMLOCK, locked << PAGE_SHIFT, 1);
72857 if (locked > lock_limit && !capable(CAP_IPC_LOCK))
72858 return -EAGAIN;
72859 }
72860@@ -1101,6 +1209,9 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
72861 }
72862 }
72863
72864+ if (!gr_acl_handle_mmap(file, prot))
72865+ return -EACCES;
72866+
72867 return mmap_region(file, addr, len, flags, vm_flags, pgoff);
72868 }
72869
72870@@ -1177,7 +1288,7 @@ int vma_wants_writenotify(struct vm_area_struct *vma)
72871 vm_flags_t vm_flags = vma->vm_flags;
72872
72873 /* If it was private or non-writable, the write bit is already clear */
72874- if ((vm_flags & (VM_WRITE|VM_SHARED)) != ((VM_WRITE|VM_SHARED)))
72875+ if ((vm_flags & (VM_WRITE|VM_SHARED)) != (VM_WRITE|VM_SHARED))
72876 return 0;
72877
72878 /* The backer wishes to know when pages are first written to? */
72879@@ -1226,14 +1337,24 @@ unsigned long mmap_region(struct file *file, unsigned long addr,
72880 unsigned long charged = 0;
72881 struct inode *inode = file ? file->f_path.dentry->d_inode : NULL;
72882
72883+#ifdef CONFIG_PAX_SEGMEXEC
72884+ struct vm_area_struct *vma_m = NULL;
72885+#endif
72886+
72887+ /*
72888+ * mm->mmap_sem is required to protect against another thread
72889+ * changing the mappings in case we sleep.
72890+ */
72891+ verify_mm_writelocked(mm);
72892+
72893 /* Clear old maps */
72894 error = -ENOMEM;
72895-munmap_back:
72896 vma = find_vma_prepare(mm, addr, &prev, &rb_link, &rb_parent);
72897 if (vma && vma->vm_start < addr + len) {
72898 if (do_munmap(mm, addr, len))
72899 return -ENOMEM;
72900- goto munmap_back;
72901+ vma = find_vma_prepare(mm, addr, &prev, &rb_link, &rb_parent);
72902+ BUG_ON(vma && vma->vm_start < addr + len);
72903 }
72904
72905 /* Check against address space limit. */
72906@@ -1282,6 +1403,16 @@ munmap_back:
72907 goto unacct_error;
72908 }
72909
72910+#ifdef CONFIG_PAX_SEGMEXEC
72911+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (vm_flags & VM_EXEC)) {
72912+ vma_m = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
72913+ if (!vma_m) {
72914+ error = -ENOMEM;
72915+ goto free_vma;
72916+ }
72917+ }
72918+#endif
72919+
72920 vma->vm_mm = mm;
72921 vma->vm_start = addr;
72922 vma->vm_end = addr + len;
72923@@ -1306,6 +1437,19 @@ munmap_back:
72924 error = file->f_op->mmap(file, vma);
72925 if (error)
72926 goto unmap_and_free_vma;
72927+
72928+#ifdef CONFIG_PAX_SEGMEXEC
72929+ if (vma_m && (vm_flags & VM_EXECUTABLE))
72930+ added_exe_file_vma(mm);
72931+#endif
72932+
72933+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
72934+ if ((mm->pax_flags & MF_PAX_PAGEEXEC) && !(vma->vm_flags & VM_SPECIAL)) {
72935+ vma->vm_flags |= VM_PAGEEXEC;
72936+ vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
72937+ }
72938+#endif
72939+
72940 if (vm_flags & VM_EXECUTABLE)
72941 added_exe_file_vma(mm);
72942
72943@@ -1343,6 +1487,11 @@ munmap_back:
72944 vma_link(mm, vma, prev, rb_link, rb_parent);
72945 file = vma->vm_file;
72946
72947+#ifdef CONFIG_PAX_SEGMEXEC
72948+ if (vma_m)
72949+ BUG_ON(pax_mirror_vma(vma_m, vma));
72950+#endif
72951+
72952 /* Once vma denies write, undo our temporary denial count */
72953 if (correct_wcount)
72954 atomic_inc(&inode->i_writecount);
72955@@ -1350,6 +1499,7 @@ out:
72956 perf_event_mmap(vma);
72957
72958 vm_stat_account(mm, vm_flags, file, len >> PAGE_SHIFT);
72959+ track_exec_limit(mm, addr, addr + len, vm_flags);
72960 if (vm_flags & VM_LOCKED) {
72961 if (!mlock_vma_pages_range(vma, addr, addr + len))
72962 mm->locked_vm += (len >> PAGE_SHIFT);
72963@@ -1371,6 +1521,12 @@ unmap_and_free_vma:
72964 unmap_region(mm, vma, prev, vma->vm_start, vma->vm_end);
72965 charged = 0;
72966 free_vma:
72967+
72968+#ifdef CONFIG_PAX_SEGMEXEC
72969+ if (vma_m)
72970+ kmem_cache_free(vm_area_cachep, vma_m);
72971+#endif
72972+
72973 kmem_cache_free(vm_area_cachep, vma);
72974 unacct_error:
72975 if (charged)
72976@@ -1378,6 +1534,44 @@ unacct_error:
72977 return error;
72978 }
72979
72980+bool check_heap_stack_gap(const struct vm_area_struct *vma, unsigned long addr, unsigned long len)
72981+{
72982+ if (!vma) {
72983+#ifdef CONFIG_STACK_GROWSUP
72984+ if (addr > sysctl_heap_stack_gap)
72985+ vma = find_vma(current->mm, addr - sysctl_heap_stack_gap);
72986+ else
72987+ vma = find_vma(current->mm, 0);
72988+ if (vma && (vma->vm_flags & VM_GROWSUP))
72989+ return false;
72990+#endif
72991+ return true;
72992+ }
72993+
72994+ if (addr + len > vma->vm_start)
72995+ return false;
72996+
72997+ if (vma->vm_flags & VM_GROWSDOWN)
72998+ return sysctl_heap_stack_gap <= vma->vm_start - addr - len;
72999+#ifdef CONFIG_STACK_GROWSUP
73000+ else if (vma->vm_prev && (vma->vm_prev->vm_flags & VM_GROWSUP))
73001+ return addr - vma->vm_prev->vm_end <= sysctl_heap_stack_gap;
73002+#endif
73003+
73004+ return true;
73005+}
73006+
73007+unsigned long skip_heap_stack_gap(const struct vm_area_struct *vma, unsigned long len)
73008+{
73009+ if (vma->vm_start < len)
73010+ return -ENOMEM;
73011+ if (!(vma->vm_flags & VM_GROWSDOWN))
73012+ return vma->vm_start - len;
73013+ if (sysctl_heap_stack_gap <= vma->vm_start - len)
73014+ return vma->vm_start - len - sysctl_heap_stack_gap;
73015+ return -ENOMEM;
73016+}
73017+
73018 /* Get an address range which is currently unmapped.
73019 * For shmat() with addr=0.
73020 *
73021@@ -1404,18 +1598,23 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
73022 if (flags & MAP_FIXED)
73023 return addr;
73024
73025+#ifdef CONFIG_PAX_RANDMMAP
73026+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
73027+#endif
73028+
73029 if (addr) {
73030 addr = PAGE_ALIGN(addr);
73031- vma = find_vma(mm, addr);
73032- if (TASK_SIZE - len >= addr &&
73033- (!vma || addr + len <= vma->vm_start))
73034- return addr;
73035+ if (TASK_SIZE - len >= addr) {
73036+ vma = find_vma(mm, addr);
73037+ if (check_heap_stack_gap(vma, addr, len))
73038+ return addr;
73039+ }
73040 }
73041 if (len > mm->cached_hole_size) {
73042- start_addr = addr = mm->free_area_cache;
73043+ start_addr = addr = mm->free_area_cache;
73044 } else {
73045- start_addr = addr = TASK_UNMAPPED_BASE;
73046- mm->cached_hole_size = 0;
73047+ start_addr = addr = mm->mmap_base;
73048+ mm->cached_hole_size = 0;
73049 }
73050
73051 full_search:
73052@@ -1426,34 +1625,40 @@ full_search:
73053 * Start a new search - just in case we missed
73054 * some holes.
73055 */
73056- if (start_addr != TASK_UNMAPPED_BASE) {
73057- addr = TASK_UNMAPPED_BASE;
73058- start_addr = addr;
73059+ if (start_addr != mm->mmap_base) {
73060+ start_addr = addr = mm->mmap_base;
73061 mm->cached_hole_size = 0;
73062 goto full_search;
73063 }
73064 return -ENOMEM;
73065 }
73066- if (!vma || addr + len <= vma->vm_start) {
73067- /*
73068- * Remember the place where we stopped the search:
73069- */
73070- mm->free_area_cache = addr + len;
73071- return addr;
73072- }
73073+ if (check_heap_stack_gap(vma, addr, len))
73074+ break;
73075 if (addr + mm->cached_hole_size < vma->vm_start)
73076 mm->cached_hole_size = vma->vm_start - addr;
73077 addr = vma->vm_end;
73078 }
73079+
73080+ /*
73081+ * Remember the place where we stopped the search:
73082+ */
73083+ mm->free_area_cache = addr + len;
73084+ return addr;
73085 }
73086 #endif
73087
73088 void arch_unmap_area(struct mm_struct *mm, unsigned long addr)
73089 {
73090+
73091+#ifdef CONFIG_PAX_SEGMEXEC
73092+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && SEGMEXEC_TASK_SIZE <= addr)
73093+ return;
73094+#endif
73095+
73096 /*
73097 * Is this a new hole at the lowest possible address?
73098 */
73099- if (addr >= TASK_UNMAPPED_BASE && addr < mm->free_area_cache)
73100+ if (addr >= mm->mmap_base && addr < mm->free_area_cache)
73101 mm->free_area_cache = addr;
73102 }
73103
73104@@ -1469,7 +1674,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
73105 {
73106 struct vm_area_struct *vma;
73107 struct mm_struct *mm = current->mm;
73108- unsigned long addr = addr0, start_addr;
73109+ unsigned long base = mm->mmap_base, addr = addr0, start_addr;
73110
73111 /* requested length too big for entire address space */
73112 if (len > TASK_SIZE)
73113@@ -1478,13 +1683,18 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
73114 if (flags & MAP_FIXED)
73115 return addr;
73116
73117+#ifdef CONFIG_PAX_RANDMMAP
73118+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
73119+#endif
73120+
73121 /* requesting a specific address */
73122 if (addr) {
73123 addr = PAGE_ALIGN(addr);
73124- vma = find_vma(mm, addr);
73125- if (TASK_SIZE - len >= addr &&
73126- (!vma || addr + len <= vma->vm_start))
73127- return addr;
73128+ if (TASK_SIZE - len >= addr) {
73129+ vma = find_vma(mm, addr);
73130+ if (check_heap_stack_gap(vma, addr, len))
73131+ return addr;
73132+ }
73133 }
73134
73135 /* check if free_area_cache is useful for us */
73136@@ -1508,7 +1718,7 @@ try_again:
73137 * return with success:
73138 */
73139 vma = find_vma(mm, addr);
73140- if (!vma || addr+len <= vma->vm_start)
73141+ if (check_heap_stack_gap(vma, addr, len))
73142 /* remember the address as a hint for next time */
73143 return (mm->free_area_cache = addr);
73144
73145@@ -1517,8 +1727,8 @@ try_again:
73146 mm->cached_hole_size = vma->vm_start - addr;
73147
73148 /* try just below the current vma->vm_start */
73149- addr = vma->vm_start-len;
73150- } while (len < vma->vm_start);
73151+ addr = skip_heap_stack_gap(vma, len);
73152+ } while (!IS_ERR_VALUE(addr));
73153
73154 fail:
73155 /*
73156@@ -1541,13 +1751,21 @@ fail:
73157 * can happen with large stack limits and large mmap()
73158 * allocations.
73159 */
73160+ mm->mmap_base = TASK_UNMAPPED_BASE;
73161+
73162+#ifdef CONFIG_PAX_RANDMMAP
73163+ if (mm->pax_flags & MF_PAX_RANDMMAP)
73164+ mm->mmap_base += mm->delta_mmap;
73165+#endif
73166+
73167+ mm->free_area_cache = mm->mmap_base;
73168 mm->cached_hole_size = ~0UL;
73169- mm->free_area_cache = TASK_UNMAPPED_BASE;
73170 addr = arch_get_unmapped_area(filp, addr0, len, pgoff, flags);
73171 /*
73172 * Restore the topdown base:
73173 */
73174- mm->free_area_cache = mm->mmap_base;
73175+ mm->mmap_base = base;
73176+ mm->free_area_cache = base;
73177 mm->cached_hole_size = ~0UL;
73178
73179 return addr;
73180@@ -1556,6 +1774,12 @@ fail:
73181
73182 void arch_unmap_area_topdown(struct mm_struct *mm, unsigned long addr)
73183 {
73184+
73185+#ifdef CONFIG_PAX_SEGMEXEC
73186+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && SEGMEXEC_TASK_SIZE <= addr)
73187+ return;
73188+#endif
73189+
73190 /*
73191 * Is this a new hole at the highest possible address?
73192 */
73193@@ -1563,8 +1787,10 @@ void arch_unmap_area_topdown(struct mm_struct *mm, unsigned long addr)
73194 mm->free_area_cache = addr;
73195
73196 /* dont allow allocations above current base */
73197- if (mm->free_area_cache > mm->mmap_base)
73198+ if (mm->free_area_cache > mm->mmap_base) {
73199 mm->free_area_cache = mm->mmap_base;
73200+ mm->cached_hole_size = ~0UL;
73201+ }
73202 }
73203
73204 unsigned long
73205@@ -1663,6 +1889,28 @@ find_vma_prev(struct mm_struct *mm, unsigned long addr,
73206 return vma;
73207 }
73208
73209+#ifdef CONFIG_PAX_SEGMEXEC
73210+struct vm_area_struct *pax_find_mirror_vma(struct vm_area_struct *vma)
73211+{
73212+ struct vm_area_struct *vma_m;
73213+
73214+ BUG_ON(!vma || vma->vm_start >= vma->vm_end);
73215+ if (!(vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) || !(vma->vm_flags & VM_EXEC)) {
73216+ BUG_ON(vma->vm_mirror);
73217+ return NULL;
73218+ }
73219+ BUG_ON(vma->vm_start < SEGMEXEC_TASK_SIZE && SEGMEXEC_TASK_SIZE < vma->vm_end);
73220+ vma_m = vma->vm_mirror;
73221+ BUG_ON(!vma_m || vma_m->vm_mirror != vma);
73222+ BUG_ON(vma->vm_file != vma_m->vm_file);
73223+ BUG_ON(vma->vm_end - vma->vm_start != vma_m->vm_end - vma_m->vm_start);
73224+ BUG_ON(vma->vm_pgoff != vma_m->vm_pgoff);
73225+ BUG_ON(vma->anon_vma != vma_m->anon_vma && vma->anon_vma->root != vma_m->anon_vma->root);
73226+ BUG_ON((vma->vm_flags ^ vma_m->vm_flags) & ~(VM_WRITE | VM_MAYWRITE | VM_ACCOUNT | VM_LOCKED | VM_RESERVED));
73227+ return vma_m;
73228+}
73229+#endif
73230+
73231 /*
73232 * Verify that the stack growth is acceptable and
73233 * update accounting. This is shared with both the
73234@@ -1679,6 +1927,7 @@ static int acct_stack_growth(struct vm_area_struct *vma, unsigned long size, uns
73235 return -ENOMEM;
73236
73237 /* Stack limit test */
73238+ gr_learn_resource(current, RLIMIT_STACK, size, 1);
73239 if (size > ACCESS_ONCE(rlim[RLIMIT_STACK].rlim_cur))
73240 return -ENOMEM;
73241
73242@@ -1689,6 +1938,7 @@ static int acct_stack_growth(struct vm_area_struct *vma, unsigned long size, uns
73243 locked = mm->locked_vm + grow;
73244 limit = ACCESS_ONCE(rlim[RLIMIT_MEMLOCK].rlim_cur);
73245 limit >>= PAGE_SHIFT;
73246+ gr_learn_resource(current, RLIMIT_MEMLOCK, locked << PAGE_SHIFT, 1);
73247 if (locked > limit && !capable(CAP_IPC_LOCK))
73248 return -ENOMEM;
73249 }
73250@@ -1718,37 +1968,48 @@ static int acct_stack_growth(struct vm_area_struct *vma, unsigned long size, uns
73251 * PA-RISC uses this for its stack; IA64 for its Register Backing Store.
73252 * vma is the last one with address > vma->vm_end. Have to extend vma.
73253 */
73254+#ifndef CONFIG_IA64
73255+static
73256+#endif
73257 int expand_upwards(struct vm_area_struct *vma, unsigned long address)
73258 {
73259 int error;
73260+ bool locknext;
73261
73262 if (!(vma->vm_flags & VM_GROWSUP))
73263 return -EFAULT;
73264
73265+ /* Also guard against wrapping around to address 0. */
73266+ if (address < PAGE_ALIGN(address+1))
73267+ address = PAGE_ALIGN(address+1);
73268+ else
73269+ return -ENOMEM;
73270+
73271 /*
73272 * We must make sure the anon_vma is allocated
73273 * so that the anon_vma locking is not a noop.
73274 */
73275 if (unlikely(anon_vma_prepare(vma)))
73276 return -ENOMEM;
73277+ locknext = vma->vm_next && (vma->vm_next->vm_flags & VM_GROWSDOWN);
73278+ if (locknext && anon_vma_prepare(vma->vm_next))
73279+ return -ENOMEM;
73280 vma_lock_anon_vma(vma);
73281+ if (locknext)
73282+ vma_lock_anon_vma(vma->vm_next);
73283
73284 /*
73285 * vma->vm_start/vm_end cannot change under us because the caller
73286 * is required to hold the mmap_sem in read mode. We need the
73287- * anon_vma lock to serialize against concurrent expand_stacks.
73288- * Also guard against wrapping around to address 0.
73289+ * anon_vma locks to serialize against concurrent expand_stacks
73290+ * and expand_upwards.
73291 */
73292- if (address < PAGE_ALIGN(address+4))
73293- address = PAGE_ALIGN(address+4);
73294- else {
73295- vma_unlock_anon_vma(vma);
73296- return -ENOMEM;
73297- }
73298 error = 0;
73299
73300 /* Somebody else might have raced and expanded it already */
73301- if (address > vma->vm_end) {
73302+ 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)
73303+ error = -ENOMEM;
73304+ else if (address > vma->vm_end && (!locknext || vma->vm_next->vm_start >= address)) {
73305 unsigned long size, grow;
73306
73307 size = address - vma->vm_start;
73308@@ -1763,6 +2024,8 @@ int expand_upwards(struct vm_area_struct *vma, unsigned long address)
73309 }
73310 }
73311 }
73312+ if (locknext)
73313+ vma_unlock_anon_vma(vma->vm_next);
73314 vma_unlock_anon_vma(vma);
73315 khugepaged_enter_vma_merge(vma);
73316 return error;
73317@@ -1776,6 +2039,8 @@ int expand_downwards(struct vm_area_struct *vma,
73318 unsigned long address)
73319 {
73320 int error;
73321+ bool lockprev = false;
73322+ struct vm_area_struct *prev;
73323
73324 /*
73325 * We must make sure the anon_vma is allocated
73326@@ -1789,6 +2054,15 @@ int expand_downwards(struct vm_area_struct *vma,
73327 if (error)
73328 return error;
73329
73330+ prev = vma->vm_prev;
73331+#if defined(CONFIG_STACK_GROWSUP) || defined(CONFIG_IA64)
73332+ lockprev = prev && (prev->vm_flags & VM_GROWSUP);
73333+#endif
73334+ if (lockprev && anon_vma_prepare(prev))
73335+ return -ENOMEM;
73336+ if (lockprev)
73337+ vma_lock_anon_vma(prev);
73338+
73339 vma_lock_anon_vma(vma);
73340
73341 /*
73342@@ -1798,9 +2072,17 @@ int expand_downwards(struct vm_area_struct *vma,
73343 */
73344
73345 /* Somebody else might have raced and expanded it already */
73346- if (address < vma->vm_start) {
73347+ if (prev && (prev->vm_flags & (VM_READ | VM_WRITE | VM_EXEC)) && address - prev->vm_end < sysctl_heap_stack_gap)
73348+ error = -ENOMEM;
73349+ else if (address < vma->vm_start && (!lockprev || prev->vm_end <= address)) {
73350 unsigned long size, grow;
73351
73352+#ifdef CONFIG_PAX_SEGMEXEC
73353+ struct vm_area_struct *vma_m;
73354+
73355+ vma_m = pax_find_mirror_vma(vma);
73356+#endif
73357+
73358 size = vma->vm_end - address;
73359 grow = (vma->vm_start - address) >> PAGE_SHIFT;
73360
73361@@ -1810,11 +2092,22 @@ int expand_downwards(struct vm_area_struct *vma,
73362 if (!error) {
73363 vma->vm_start = address;
73364 vma->vm_pgoff -= grow;
73365+ track_exec_limit(vma->vm_mm, vma->vm_start, vma->vm_end, vma->vm_flags);
73366+
73367+#ifdef CONFIG_PAX_SEGMEXEC
73368+ if (vma_m) {
73369+ vma_m->vm_start -= grow << PAGE_SHIFT;
73370+ vma_m->vm_pgoff -= grow;
73371+ }
73372+#endif
73373+
73374 perf_event_mmap(vma);
73375 }
73376 }
73377 }
73378 vma_unlock_anon_vma(vma);
73379+ if (lockprev)
73380+ vma_unlock_anon_vma(prev);
73381 khugepaged_enter_vma_merge(vma);
73382 return error;
73383 }
73384@@ -1886,6 +2179,13 @@ static void remove_vma_list(struct mm_struct *mm, struct vm_area_struct *vma)
73385 do {
73386 long nrpages = vma_pages(vma);
73387
73388+#ifdef CONFIG_PAX_SEGMEXEC
73389+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_start >= SEGMEXEC_TASK_SIZE)) {
73390+ vma = remove_vma(vma);
73391+ continue;
73392+ }
73393+#endif
73394+
73395 if (vma->vm_flags & VM_ACCOUNT)
73396 nr_accounted += nrpages;
73397 vm_stat_account(mm, vma->vm_flags, vma->vm_file, -nrpages);
73398@@ -1931,6 +2231,16 @@ detach_vmas_to_be_unmapped(struct mm_struct *mm, struct vm_area_struct *vma,
73399 insertion_point = (prev ? &prev->vm_next : &mm->mmap);
73400 vma->vm_prev = NULL;
73401 do {
73402+
73403+#ifdef CONFIG_PAX_SEGMEXEC
73404+ if (vma->vm_mirror) {
73405+ BUG_ON(!vma->vm_mirror->vm_mirror || vma->vm_mirror->vm_mirror != vma);
73406+ vma->vm_mirror->vm_mirror = NULL;
73407+ vma->vm_mirror->vm_flags &= ~VM_EXEC;
73408+ vma->vm_mirror = NULL;
73409+ }
73410+#endif
73411+
73412 rb_erase(&vma->vm_rb, &mm->mm_rb);
73413 mm->map_count--;
73414 tail_vma = vma;
73415@@ -1959,14 +2269,33 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
73416 struct vm_area_struct *new;
73417 int err = -ENOMEM;
73418
73419+#ifdef CONFIG_PAX_SEGMEXEC
73420+ struct vm_area_struct *vma_m, *new_m = NULL;
73421+ unsigned long addr_m = addr + SEGMEXEC_TASK_SIZE;
73422+#endif
73423+
73424 if (is_vm_hugetlb_page(vma) && (addr &
73425 ~(huge_page_mask(hstate_vma(vma)))))
73426 return -EINVAL;
73427
73428+#ifdef CONFIG_PAX_SEGMEXEC
73429+ vma_m = pax_find_mirror_vma(vma);
73430+#endif
73431+
73432 new = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
73433 if (!new)
73434 goto out_err;
73435
73436+#ifdef CONFIG_PAX_SEGMEXEC
73437+ if (vma_m) {
73438+ new_m = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
73439+ if (!new_m) {
73440+ kmem_cache_free(vm_area_cachep, new);
73441+ goto out_err;
73442+ }
73443+ }
73444+#endif
73445+
73446 /* most fields are the same, copy all, and then fixup */
73447 *new = *vma;
73448
73449@@ -1979,6 +2308,22 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
73450 new->vm_pgoff += ((addr - vma->vm_start) >> PAGE_SHIFT);
73451 }
73452
73453+#ifdef CONFIG_PAX_SEGMEXEC
73454+ if (vma_m) {
73455+ *new_m = *vma_m;
73456+ INIT_LIST_HEAD(&new_m->anon_vma_chain);
73457+ new_m->vm_mirror = new;
73458+ new->vm_mirror = new_m;
73459+
73460+ if (new_below)
73461+ new_m->vm_end = addr_m;
73462+ else {
73463+ new_m->vm_start = addr_m;
73464+ new_m->vm_pgoff += ((addr_m - vma_m->vm_start) >> PAGE_SHIFT);
73465+ }
73466+ }
73467+#endif
73468+
73469 pol = mpol_dup(vma_policy(vma));
73470 if (IS_ERR(pol)) {
73471 err = PTR_ERR(pol);
73472@@ -2004,6 +2349,42 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
73473 else
73474 err = vma_adjust(vma, vma->vm_start, addr, vma->vm_pgoff, new);
73475
73476+#ifdef CONFIG_PAX_SEGMEXEC
73477+ if (!err && vma_m) {
73478+ if (anon_vma_clone(new_m, vma_m))
73479+ goto out_free_mpol;
73480+
73481+ mpol_get(pol);
73482+ vma_set_policy(new_m, pol);
73483+
73484+ if (new_m->vm_file) {
73485+ get_file(new_m->vm_file);
73486+ if (vma_m->vm_flags & VM_EXECUTABLE)
73487+ added_exe_file_vma(mm);
73488+ }
73489+
73490+ if (new_m->vm_ops && new_m->vm_ops->open)
73491+ new_m->vm_ops->open(new_m);
73492+
73493+ if (new_below)
73494+ err = vma_adjust(vma_m, addr_m, vma_m->vm_end, vma_m->vm_pgoff +
73495+ ((addr_m - new_m->vm_start) >> PAGE_SHIFT), new_m);
73496+ else
73497+ err = vma_adjust(vma_m, vma_m->vm_start, addr_m, vma_m->vm_pgoff, new_m);
73498+
73499+ if (err) {
73500+ if (new_m->vm_ops && new_m->vm_ops->close)
73501+ new_m->vm_ops->close(new_m);
73502+ if (new_m->vm_file) {
73503+ if (vma_m->vm_flags & VM_EXECUTABLE)
73504+ removed_exe_file_vma(mm);
73505+ fput(new_m->vm_file);
73506+ }
73507+ mpol_put(pol);
73508+ }
73509+ }
73510+#endif
73511+
73512 /* Success. */
73513 if (!err)
73514 return 0;
73515@@ -2016,10 +2397,18 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
73516 removed_exe_file_vma(mm);
73517 fput(new->vm_file);
73518 }
73519- unlink_anon_vmas(new);
73520 out_free_mpol:
73521 mpol_put(pol);
73522 out_free_vma:
73523+
73524+#ifdef CONFIG_PAX_SEGMEXEC
73525+ if (new_m) {
73526+ unlink_anon_vmas(new_m);
73527+ kmem_cache_free(vm_area_cachep, new_m);
73528+ }
73529+#endif
73530+
73531+ unlink_anon_vmas(new);
73532 kmem_cache_free(vm_area_cachep, new);
73533 out_err:
73534 return err;
73535@@ -2032,6 +2421,15 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
73536 int split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
73537 unsigned long addr, int new_below)
73538 {
73539+
73540+#ifdef CONFIG_PAX_SEGMEXEC
73541+ if (mm->pax_flags & MF_PAX_SEGMEXEC) {
73542+ BUG_ON(vma->vm_end > SEGMEXEC_TASK_SIZE);
73543+ if (mm->map_count >= sysctl_max_map_count-1)
73544+ return -ENOMEM;
73545+ } else
73546+#endif
73547+
73548 if (mm->map_count >= sysctl_max_map_count)
73549 return -ENOMEM;
73550
73551@@ -2043,11 +2441,30 @@ int split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
73552 * work. This now handles partial unmappings.
73553 * Jeremy Fitzhardinge <jeremy@goop.org>
73554 */
73555+#ifdef CONFIG_PAX_SEGMEXEC
73556 int do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
73557 {
73558+ int ret = __do_munmap(mm, start, len);
73559+ if (ret || !(mm->pax_flags & MF_PAX_SEGMEXEC))
73560+ return ret;
73561+
73562+ return __do_munmap(mm, start + SEGMEXEC_TASK_SIZE, len);
73563+}
73564+
73565+int __do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
73566+#else
73567+int do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
73568+#endif
73569+{
73570 unsigned long end;
73571 struct vm_area_struct *vma, *prev, *last;
73572
73573+ /*
73574+ * mm->mmap_sem is required to protect against another thread
73575+ * changing the mappings in case we sleep.
73576+ */
73577+ verify_mm_writelocked(mm);
73578+
73579 if ((start & ~PAGE_MASK) || start > TASK_SIZE || len > TASK_SIZE-start)
73580 return -EINVAL;
73581
73582@@ -2122,6 +2539,8 @@ int do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
73583 /* Fix up all other VM information */
73584 remove_vma_list(mm, vma);
73585
73586+ track_exec_limit(mm, start, end, 0UL);
73587+
73588 return 0;
73589 }
73590
73591@@ -2130,6 +2549,13 @@ int vm_munmap(unsigned long start, size_t len)
73592 int ret;
73593 struct mm_struct *mm = current->mm;
73594
73595+
73596+#ifdef CONFIG_PAX_SEGMEXEC
73597+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) &&
73598+ (len > SEGMEXEC_TASK_SIZE || start > SEGMEXEC_TASK_SIZE-len))
73599+ return -EINVAL;
73600+#endif
73601+
73602 down_write(&mm->mmap_sem);
73603 ret = do_munmap(mm, start, len);
73604 up_write(&mm->mmap_sem);
73605@@ -2143,16 +2569,6 @@ SYSCALL_DEFINE2(munmap, unsigned long, addr, size_t, len)
73606 return vm_munmap(addr, len);
73607 }
73608
73609-static inline void verify_mm_writelocked(struct mm_struct *mm)
73610-{
73611-#ifdef CONFIG_DEBUG_VM
73612- if (unlikely(down_read_trylock(&mm->mmap_sem))) {
73613- WARN_ON(1);
73614- up_read(&mm->mmap_sem);
73615- }
73616-#endif
73617-}
73618-
73619 /*
73620 * this is really a simplified "do_mmap". it only handles
73621 * anonymous maps. eventually we may be able to do some
73622@@ -2166,6 +2582,7 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
73623 struct rb_node ** rb_link, * rb_parent;
73624 pgoff_t pgoff = addr >> PAGE_SHIFT;
73625 int error;
73626+ unsigned long charged;
73627
73628 len = PAGE_ALIGN(len);
73629 if (!len)
73630@@ -2173,16 +2590,30 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
73631
73632 flags = VM_DATA_DEFAULT_FLAGS | VM_ACCOUNT | mm->def_flags;
73633
73634+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
73635+ if (mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
73636+ flags &= ~VM_EXEC;
73637+
73638+#ifdef CONFIG_PAX_MPROTECT
73639+ if (mm->pax_flags & MF_PAX_MPROTECT)
73640+ flags &= ~VM_MAYEXEC;
73641+#endif
73642+
73643+ }
73644+#endif
73645+
73646 error = get_unmapped_area(NULL, addr, len, 0, MAP_FIXED);
73647 if (error & ~PAGE_MASK)
73648 return error;
73649
73650+ charged = len >> PAGE_SHIFT;
73651+
73652 /*
73653 * mlock MCL_FUTURE?
73654 */
73655 if (mm->def_flags & VM_LOCKED) {
73656 unsigned long locked, lock_limit;
73657- locked = len >> PAGE_SHIFT;
73658+ locked = charged;
73659 locked += mm->locked_vm;
73660 lock_limit = rlimit(RLIMIT_MEMLOCK);
73661 lock_limit >>= PAGE_SHIFT;
73662@@ -2199,22 +2630,22 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
73663 /*
73664 * Clear old maps. this also does some error checking for us
73665 */
73666- munmap_back:
73667 vma = find_vma_prepare(mm, addr, &prev, &rb_link, &rb_parent);
73668 if (vma && vma->vm_start < addr + len) {
73669 if (do_munmap(mm, addr, len))
73670 return -ENOMEM;
73671- goto munmap_back;
73672- }
73673+ vma = find_vma_prepare(mm, addr, &prev, &rb_link, &rb_parent);
73674+ BUG_ON(vma && vma->vm_start < addr + len);
73675+ }
73676
73677 /* Check against address space limits *after* clearing old maps... */
73678- if (!may_expand_vm(mm, len >> PAGE_SHIFT))
73679+ if (!may_expand_vm(mm, charged))
73680 return -ENOMEM;
73681
73682 if (mm->map_count > sysctl_max_map_count)
73683 return -ENOMEM;
73684
73685- if (security_vm_enough_memory_mm(mm, len >> PAGE_SHIFT))
73686+ if (security_vm_enough_memory_mm(mm, charged))
73687 return -ENOMEM;
73688
73689 /* Can we just expand an old private anonymous mapping? */
73690@@ -2228,7 +2659,7 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
73691 */
73692 vma = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
73693 if (!vma) {
73694- vm_unacct_memory(len >> PAGE_SHIFT);
73695+ vm_unacct_memory(charged);
73696 return -ENOMEM;
73697 }
73698
73699@@ -2242,11 +2673,12 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
73700 vma_link(mm, vma, prev, rb_link, rb_parent);
73701 out:
73702 perf_event_mmap(vma);
73703- mm->total_vm += len >> PAGE_SHIFT;
73704+ mm->total_vm += charged;
73705 if (flags & VM_LOCKED) {
73706 if (!mlock_vma_pages_range(vma, addr, addr + len))
73707- mm->locked_vm += (len >> PAGE_SHIFT);
73708+ mm->locked_vm += charged;
73709 }
73710+ track_exec_limit(mm, addr, addr + len, flags);
73711 return addr;
73712 }
73713
73714@@ -2304,6 +2736,7 @@ void exit_mmap(struct mm_struct *mm)
73715 while (vma) {
73716 if (vma->vm_flags & VM_ACCOUNT)
73717 nr_accounted += vma_pages(vma);
73718+ vma->vm_mirror = NULL;
73719 vma = remove_vma(vma);
73720 }
73721 vm_unacct_memory(nr_accounted);
73722@@ -2320,6 +2753,13 @@ int insert_vm_struct(struct mm_struct * mm, struct vm_area_struct * vma)
73723 struct vm_area_struct * __vma, * prev;
73724 struct rb_node ** rb_link, * rb_parent;
73725
73726+#ifdef CONFIG_PAX_SEGMEXEC
73727+ struct vm_area_struct *vma_m = NULL;
73728+#endif
73729+
73730+ if (security_mmap_addr(vma->vm_start))
73731+ return -EPERM;
73732+
73733 /*
73734 * The vm_pgoff of a purely anonymous vma should be irrelevant
73735 * until its first write fault, when page's anon_vma and index
73736@@ -2343,7 +2783,21 @@ int insert_vm_struct(struct mm_struct * mm, struct vm_area_struct * vma)
73737 security_vm_enough_memory_mm(mm, vma_pages(vma)))
73738 return -ENOMEM;
73739
73740+#ifdef CONFIG_PAX_SEGMEXEC
73741+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_flags & VM_EXEC)) {
73742+ vma_m = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
73743+ if (!vma_m)
73744+ return -ENOMEM;
73745+ }
73746+#endif
73747+
73748 vma_link(mm, vma, prev, rb_link, rb_parent);
73749+
73750+#ifdef CONFIG_PAX_SEGMEXEC
73751+ if (vma_m)
73752+ BUG_ON(pax_mirror_vma(vma_m, vma));
73753+#endif
73754+
73755 return 0;
73756 }
73757
73758@@ -2362,6 +2816,8 @@ struct vm_area_struct *copy_vma(struct vm_area_struct **vmap,
73759 struct mempolicy *pol;
73760 bool faulted_in_anon_vma = true;
73761
73762+ BUG_ON(vma->vm_mirror);
73763+
73764 /*
73765 * If anonymous vma has not yet been faulted, update new pgoff
73766 * to match new location, to increase its chance of merging.
73767@@ -2430,6 +2886,39 @@ struct vm_area_struct *copy_vma(struct vm_area_struct **vmap,
73768 return NULL;
73769 }
73770
73771+#ifdef CONFIG_PAX_SEGMEXEC
73772+long pax_mirror_vma(struct vm_area_struct *vma_m, struct vm_area_struct *vma)
73773+{
73774+ struct vm_area_struct *prev_m;
73775+ struct rb_node **rb_link_m, *rb_parent_m;
73776+ struct mempolicy *pol_m;
73777+
73778+ BUG_ON(!(vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) || !(vma->vm_flags & VM_EXEC));
73779+ BUG_ON(vma->vm_mirror || vma_m->vm_mirror);
73780+ BUG_ON(!mpol_equal(vma_policy(vma), vma_policy(vma_m)));
73781+ *vma_m = *vma;
73782+ INIT_LIST_HEAD(&vma_m->anon_vma_chain);
73783+ if (anon_vma_clone(vma_m, vma))
73784+ return -ENOMEM;
73785+ pol_m = vma_policy(vma_m);
73786+ mpol_get(pol_m);
73787+ vma_set_policy(vma_m, pol_m);
73788+ vma_m->vm_start += SEGMEXEC_TASK_SIZE;
73789+ vma_m->vm_end += SEGMEXEC_TASK_SIZE;
73790+ vma_m->vm_flags &= ~(VM_WRITE | VM_MAYWRITE | VM_ACCOUNT | VM_LOCKED);
73791+ vma_m->vm_page_prot = vm_get_page_prot(vma_m->vm_flags);
73792+ if (vma_m->vm_file)
73793+ get_file(vma_m->vm_file);
73794+ if (vma_m->vm_ops && vma_m->vm_ops->open)
73795+ vma_m->vm_ops->open(vma_m);
73796+ find_vma_prepare(vma->vm_mm, vma_m->vm_start, &prev_m, &rb_link_m, &rb_parent_m);
73797+ vma_link(vma->vm_mm, vma_m, prev_m, rb_link_m, rb_parent_m);
73798+ vma_m->vm_mirror = vma;
73799+ vma->vm_mirror = vma_m;
73800+ return 0;
73801+}
73802+#endif
73803+
73804 /*
73805 * Return true if the calling process may expand its vm space by the passed
73806 * number of pages
73807@@ -2441,6 +2930,12 @@ int may_expand_vm(struct mm_struct *mm, unsigned long npages)
73808
73809 lim = rlimit(RLIMIT_AS) >> PAGE_SHIFT;
73810
73811+#ifdef CONFIG_PAX_RANDMMAP
73812+ if (mm->pax_flags & MF_PAX_RANDMMAP)
73813+ cur -= mm->brk_gap;
73814+#endif
73815+
73816+ gr_learn_resource(current, RLIMIT_AS, (cur + npages) << PAGE_SHIFT, 1);
73817 if (cur + npages > lim)
73818 return 0;
73819 return 1;
73820@@ -2511,6 +3006,22 @@ int install_special_mapping(struct mm_struct *mm,
73821 vma->vm_start = addr;
73822 vma->vm_end = addr + len;
73823
73824+#ifdef CONFIG_PAX_MPROTECT
73825+ if (mm->pax_flags & MF_PAX_MPROTECT) {
73826+#ifndef CONFIG_PAX_MPROTECT_COMPAT
73827+ if ((vm_flags & (VM_WRITE | VM_EXEC)) == (VM_WRITE | VM_EXEC))
73828+ return -EPERM;
73829+ if (!(vm_flags & VM_EXEC))
73830+ vm_flags &= ~VM_MAYEXEC;
73831+#else
73832+ if ((vm_flags & (VM_WRITE | VM_EXEC)) != VM_EXEC)
73833+ vm_flags &= ~(VM_EXEC | VM_MAYEXEC);
73834+#endif
73835+ else
73836+ vm_flags &= ~VM_MAYWRITE;
73837+ }
73838+#endif
73839+
73840 vma->vm_flags = vm_flags | mm->def_flags | VM_DONTEXPAND;
73841 vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
73842
73843diff --git a/mm/mprotect.c b/mm/mprotect.c
73844index a409926..8b32e6d 100644
73845--- a/mm/mprotect.c
73846+++ b/mm/mprotect.c
73847@@ -23,10 +23,17 @@
73848 #include <linux/mmu_notifier.h>
73849 #include <linux/migrate.h>
73850 #include <linux/perf_event.h>
73851+
73852+#ifdef CONFIG_PAX_MPROTECT
73853+#include <linux/elf.h>
73854+#include <linux/binfmts.h>
73855+#endif
73856+
73857 #include <asm/uaccess.h>
73858 #include <asm/pgtable.h>
73859 #include <asm/cacheflush.h>
73860 #include <asm/tlbflush.h>
73861+#include <asm/mmu_context.h>
73862
73863 #ifndef pgprot_modify
73864 static inline pgprot_t pgprot_modify(pgprot_t oldprot, pgprot_t newprot)
73865@@ -141,6 +148,48 @@ static void change_protection(struct vm_area_struct *vma,
73866 flush_tlb_range(vma, start, end);
73867 }
73868
73869+#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
73870+/* called while holding the mmap semaphor for writing except stack expansion */
73871+void track_exec_limit(struct mm_struct *mm, unsigned long start, unsigned long end, unsigned long prot)
73872+{
73873+ unsigned long oldlimit, newlimit = 0UL;
73874+
73875+ if (!(mm->pax_flags & MF_PAX_PAGEEXEC) || (__supported_pte_mask & _PAGE_NX))
73876+ return;
73877+
73878+ spin_lock(&mm->page_table_lock);
73879+ oldlimit = mm->context.user_cs_limit;
73880+ if ((prot & VM_EXEC) && oldlimit < end)
73881+ /* USER_CS limit moved up */
73882+ newlimit = end;
73883+ else if (!(prot & VM_EXEC) && start < oldlimit && oldlimit <= end)
73884+ /* USER_CS limit moved down */
73885+ newlimit = start;
73886+
73887+ if (newlimit) {
73888+ mm->context.user_cs_limit = newlimit;
73889+
73890+#ifdef CONFIG_SMP
73891+ wmb();
73892+ cpus_clear(mm->context.cpu_user_cs_mask);
73893+ cpu_set(smp_processor_id(), mm->context.cpu_user_cs_mask);
73894+#endif
73895+
73896+ set_user_cs(mm->context.user_cs_base, mm->context.user_cs_limit, smp_processor_id());
73897+ }
73898+ spin_unlock(&mm->page_table_lock);
73899+ if (newlimit == end) {
73900+ struct vm_area_struct *vma = find_vma(mm, oldlimit);
73901+
73902+ for (; vma && vma->vm_start < end; vma = vma->vm_next)
73903+ if (is_vm_hugetlb_page(vma))
73904+ hugetlb_change_protection(vma, vma->vm_start, vma->vm_end, vma->vm_page_prot);
73905+ else
73906+ change_protection(vma, vma->vm_start, vma->vm_end, vma->vm_page_prot, vma_wants_writenotify(vma));
73907+ }
73908+}
73909+#endif
73910+
73911 int
73912 mprotect_fixup(struct vm_area_struct *vma, struct vm_area_struct **pprev,
73913 unsigned long start, unsigned long end, unsigned long newflags)
73914@@ -153,11 +202,29 @@ mprotect_fixup(struct vm_area_struct *vma, struct vm_area_struct **pprev,
73915 int error;
73916 int dirty_accountable = 0;
73917
73918+#ifdef CONFIG_PAX_SEGMEXEC
73919+ struct vm_area_struct *vma_m = NULL;
73920+ unsigned long start_m, end_m;
73921+
73922+ start_m = start + SEGMEXEC_TASK_SIZE;
73923+ end_m = end + SEGMEXEC_TASK_SIZE;
73924+#endif
73925+
73926 if (newflags == oldflags) {
73927 *pprev = vma;
73928 return 0;
73929 }
73930
73931+ if (newflags & (VM_READ | VM_WRITE | VM_EXEC)) {
73932+ struct vm_area_struct *prev = vma->vm_prev, *next = vma->vm_next;
73933+
73934+ if (next && (next->vm_flags & VM_GROWSDOWN) && sysctl_heap_stack_gap > next->vm_start - end)
73935+ return -ENOMEM;
73936+
73937+ if (prev && (prev->vm_flags & VM_GROWSUP) && sysctl_heap_stack_gap > start - prev->vm_end)
73938+ return -ENOMEM;
73939+ }
73940+
73941 /*
73942 * If we make a private mapping writable we increase our commit;
73943 * but (without finer accounting) cannot reduce our commit if we
73944@@ -174,6 +241,42 @@ mprotect_fixup(struct vm_area_struct *vma, struct vm_area_struct **pprev,
73945 }
73946 }
73947
73948+#ifdef CONFIG_PAX_SEGMEXEC
73949+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && ((oldflags ^ newflags) & VM_EXEC)) {
73950+ if (start != vma->vm_start) {
73951+ error = split_vma(mm, vma, start, 1);
73952+ if (error)
73953+ goto fail;
73954+ BUG_ON(!*pprev || (*pprev)->vm_next == vma);
73955+ *pprev = (*pprev)->vm_next;
73956+ }
73957+
73958+ if (end != vma->vm_end) {
73959+ error = split_vma(mm, vma, end, 0);
73960+ if (error)
73961+ goto fail;
73962+ }
73963+
73964+ if (pax_find_mirror_vma(vma)) {
73965+ error = __do_munmap(mm, start_m, end_m - start_m);
73966+ if (error)
73967+ goto fail;
73968+ } else {
73969+ vma_m = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
73970+ if (!vma_m) {
73971+ error = -ENOMEM;
73972+ goto fail;
73973+ }
73974+ vma->vm_flags = newflags;
73975+ error = pax_mirror_vma(vma_m, vma);
73976+ if (error) {
73977+ vma->vm_flags = oldflags;
73978+ goto fail;
73979+ }
73980+ }
73981+ }
73982+#endif
73983+
73984 /*
73985 * First try to merge with previous and/or next vma.
73986 */
73987@@ -204,9 +307,21 @@ success:
73988 * vm_flags and vm_page_prot are protected by the mmap_sem
73989 * held in write mode.
73990 */
73991+
73992+#ifdef CONFIG_PAX_SEGMEXEC
73993+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (newflags & VM_EXEC) && ((vma->vm_flags ^ newflags) & VM_READ))
73994+ pax_find_mirror_vma(vma)->vm_flags ^= VM_READ;
73995+#endif
73996+
73997 vma->vm_flags = newflags;
73998+
73999+#ifdef CONFIG_PAX_MPROTECT
74000+ if (mm->binfmt && mm->binfmt->handle_mprotect)
74001+ mm->binfmt->handle_mprotect(vma, newflags);
74002+#endif
74003+
74004 vma->vm_page_prot = pgprot_modify(vma->vm_page_prot,
74005- vm_get_page_prot(newflags));
74006+ vm_get_page_prot(vma->vm_flags));
74007
74008 if (vma_wants_writenotify(vma)) {
74009 vma->vm_page_prot = vm_get_page_prot(newflags & ~VM_SHARED);
74010@@ -248,6 +363,17 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
74011 end = start + len;
74012 if (end <= start)
74013 return -ENOMEM;
74014+
74015+#ifdef CONFIG_PAX_SEGMEXEC
74016+ if (current->mm->pax_flags & MF_PAX_SEGMEXEC) {
74017+ if (end > SEGMEXEC_TASK_SIZE)
74018+ return -EINVAL;
74019+ } else
74020+#endif
74021+
74022+ if (end > TASK_SIZE)
74023+ return -EINVAL;
74024+
74025 if (!arch_validate_prot(prot))
74026 return -EINVAL;
74027
74028@@ -255,7 +381,7 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
74029 /*
74030 * Does the application expect PROT_READ to imply PROT_EXEC:
74031 */
74032- if ((prot & PROT_READ) && (current->personality & READ_IMPLIES_EXEC))
74033+ if ((prot & (PROT_READ | PROT_WRITE)) && (current->personality & READ_IMPLIES_EXEC))
74034 prot |= PROT_EXEC;
74035
74036 vm_flags = calc_vm_prot_bits(prot);
74037@@ -288,6 +414,11 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
74038 if (start > vma->vm_start)
74039 prev = vma;
74040
74041+#ifdef CONFIG_PAX_MPROTECT
74042+ if (current->mm->binfmt && current->mm->binfmt->handle_mprotect)
74043+ current->mm->binfmt->handle_mprotect(vma, vm_flags);
74044+#endif
74045+
74046 for (nstart = start ; ; ) {
74047 unsigned long newflags;
74048
74049@@ -297,6 +428,14 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
74050
74051 /* newflags >> 4 shift VM_MAY% in place of VM_% */
74052 if ((newflags & ~(newflags >> 4)) & (VM_READ | VM_WRITE | VM_EXEC)) {
74053+ if (prot & (PROT_WRITE | PROT_EXEC))
74054+ gr_log_rwxmprotect(vma->vm_file);
74055+
74056+ error = -EACCES;
74057+ goto out;
74058+ }
74059+
74060+ if (!gr_acl_handle_mprotect(vma->vm_file, prot)) {
74061 error = -EACCES;
74062 goto out;
74063 }
74064@@ -311,6 +450,9 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
74065 error = mprotect_fixup(vma, &prev, nstart, tmp, newflags);
74066 if (error)
74067 goto out;
74068+
74069+ track_exec_limit(current->mm, nstart, tmp, vm_flags);
74070+
74071 nstart = tmp;
74072
74073 if (nstart < prev->vm_end)
74074diff --git a/mm/mremap.c b/mm/mremap.c
74075index cc06d0e..40b5d18 100644
74076--- a/mm/mremap.c
74077+++ b/mm/mremap.c
74078@@ -106,6 +106,12 @@ static void move_ptes(struct vm_area_struct *vma, pmd_t *old_pmd,
74079 continue;
74080 pte = ptep_get_and_clear(mm, old_addr, old_pte);
74081 pte = move_pte(pte, new_vma->vm_page_prot, old_addr, new_addr);
74082+
74083+#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
74084+ if (!(__supported_pte_mask & _PAGE_NX) && (new_vma->vm_flags & (VM_PAGEEXEC | VM_EXEC)) == VM_PAGEEXEC)
74085+ pte = pte_exprotect(pte);
74086+#endif
74087+
74088 set_pte_at(mm, new_addr, new_pte, pte);
74089 }
74090
74091@@ -298,6 +304,11 @@ static struct vm_area_struct *vma_to_resize(unsigned long addr,
74092 if (is_vm_hugetlb_page(vma))
74093 goto Einval;
74094
74095+#ifdef CONFIG_PAX_SEGMEXEC
74096+ if (pax_find_mirror_vma(vma))
74097+ goto Einval;
74098+#endif
74099+
74100 /* We can't remap across vm area boundaries */
74101 if (old_len > vma->vm_end - addr)
74102 goto Efault;
74103@@ -354,20 +365,25 @@ static unsigned long mremap_to(unsigned long addr,
74104 unsigned long ret = -EINVAL;
74105 unsigned long charged = 0;
74106 unsigned long map_flags;
74107+ unsigned long pax_task_size = TASK_SIZE;
74108
74109 if (new_addr & ~PAGE_MASK)
74110 goto out;
74111
74112- if (new_len > TASK_SIZE || new_addr > TASK_SIZE - new_len)
74113+#ifdef CONFIG_PAX_SEGMEXEC
74114+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
74115+ pax_task_size = SEGMEXEC_TASK_SIZE;
74116+#endif
74117+
74118+ pax_task_size -= PAGE_SIZE;
74119+
74120+ if (new_len > TASK_SIZE || new_addr > pax_task_size - new_len)
74121 goto out;
74122
74123 /* Check if the location we're moving into overlaps the
74124 * old location at all, and fail if it does.
74125 */
74126- if ((new_addr <= addr) && (new_addr+new_len) > addr)
74127- goto out;
74128-
74129- if ((addr <= new_addr) && (addr+old_len) > new_addr)
74130+ if (addr + old_len > new_addr && new_addr + new_len > addr)
74131 goto out;
74132
74133 ret = do_munmap(mm, new_addr, new_len);
74134@@ -435,6 +451,7 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
74135 struct vm_area_struct *vma;
74136 unsigned long ret = -EINVAL;
74137 unsigned long charged = 0;
74138+ unsigned long pax_task_size = TASK_SIZE;
74139
74140 down_write(&current->mm->mmap_sem);
74141
74142@@ -455,6 +472,17 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
74143 if (!new_len)
74144 goto out;
74145
74146+#ifdef CONFIG_PAX_SEGMEXEC
74147+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
74148+ pax_task_size = SEGMEXEC_TASK_SIZE;
74149+#endif
74150+
74151+ pax_task_size -= PAGE_SIZE;
74152+
74153+ if (new_len > pax_task_size || addr > pax_task_size-new_len ||
74154+ old_len > pax_task_size || addr > pax_task_size-old_len)
74155+ goto out;
74156+
74157 if (flags & MREMAP_FIXED) {
74158 if (flags & MREMAP_MAYMOVE)
74159 ret = mremap_to(addr, old_len, new_addr, new_len);
74160@@ -503,6 +531,7 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
74161 addr + new_len);
74162 }
74163 ret = addr;
74164+ track_exec_limit(vma->vm_mm, vma->vm_start, addr + new_len, vma->vm_flags);
74165 goto out;
74166 }
74167 }
74168@@ -526,7 +555,12 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
74169 goto out;
74170 }
74171
74172+ map_flags = vma->vm_flags;
74173 ret = move_vma(vma, addr, old_len, new_len, new_addr);
74174+ if (!(ret & ~PAGE_MASK)) {
74175+ track_exec_limit(current->mm, addr, addr + old_len, 0UL);
74176+ track_exec_limit(current->mm, new_addr, new_addr + new_len, map_flags);
74177+ }
74178 }
74179 out:
74180 if (ret & ~PAGE_MASK)
74181diff --git a/mm/nommu.c b/mm/nommu.c
74182index d4b0c10..ed421b5 100644
74183--- a/mm/nommu.c
74184+++ b/mm/nommu.c
74185@@ -62,7 +62,6 @@ int sysctl_overcommit_memory = OVERCOMMIT_GUESS; /* heuristic overcommit */
74186 int sysctl_overcommit_ratio = 50; /* default is 50% */
74187 int sysctl_max_map_count = DEFAULT_MAX_MAP_COUNT;
74188 int sysctl_nr_trim_pages = CONFIG_NOMMU_INITIAL_TRIM_EXCESS;
74189-int heap_stack_gap = 0;
74190
74191 atomic_long_t mmap_pages_allocated;
74192
74193@@ -827,15 +826,6 @@ struct vm_area_struct *find_vma(struct mm_struct *mm, unsigned long addr)
74194 EXPORT_SYMBOL(find_vma);
74195
74196 /*
74197- * find a VMA
74198- * - we don't extend stack VMAs under NOMMU conditions
74199- */
74200-struct vm_area_struct *find_extend_vma(struct mm_struct *mm, unsigned long addr)
74201-{
74202- return find_vma(mm, addr);
74203-}
74204-
74205-/*
74206 * expand a stack to a given address
74207 * - not supported under NOMMU conditions
74208 */
74209@@ -1551,6 +1541,7 @@ int split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
74210
74211 /* most fields are the same, copy all, and then fixup */
74212 *new = *vma;
74213+ INIT_LIST_HEAD(&new->anon_vma_chain);
74214 *region = *vma->vm_region;
74215 new->vm_region = region;
74216
74217diff --git a/mm/page_alloc.c b/mm/page_alloc.c
74218index c13ea75..081ab2c 100644
74219--- a/mm/page_alloc.c
74220+++ b/mm/page_alloc.c
74221@@ -340,7 +340,7 @@ out:
74222 * This usage means that zero-order pages may not be compound.
74223 */
74224
74225-static void free_compound_page(struct page *page)
74226+void free_compound_page(struct page *page)
74227 {
74228 __free_pages_ok(page, compound_order(page));
74229 }
74230@@ -697,6 +697,10 @@ static bool free_pages_prepare(struct page *page, unsigned int order)
74231 int i;
74232 int bad = 0;
74233
74234+#ifdef CONFIG_PAX_MEMORY_SANITIZE
74235+ unsigned long index = 1UL << order;
74236+#endif
74237+
74238 trace_mm_page_free(page, order);
74239 kmemcheck_free_shadow(page, order);
74240
74241@@ -712,6 +716,12 @@ static bool free_pages_prepare(struct page *page, unsigned int order)
74242 debug_check_no_obj_freed(page_address(page),
74243 PAGE_SIZE << order);
74244 }
74245+
74246+#ifdef CONFIG_PAX_MEMORY_SANITIZE
74247+ for (; index; --index)
74248+ sanitize_highpage(page + index - 1);
74249+#endif
74250+
74251 arch_free_page(page, order);
74252 kernel_map_pages(page, 1 << order, 0);
74253
74254@@ -853,8 +863,10 @@ static int prep_new_page(struct page *page, int order, gfp_t gfp_flags)
74255 arch_alloc_page(page, order);
74256 kernel_map_pages(page, 1 << order, 1);
74257
74258+#ifndef CONFIG_PAX_MEMORY_SANITIZE
74259 if (gfp_flags & __GFP_ZERO)
74260 prep_zero_page(page, order, gfp_flags);
74261+#endif
74262
74263 if (order && (gfp_flags & __GFP_COMP))
74264 prep_compound_page(page, order);
74265@@ -3648,7 +3660,13 @@ static int pageblock_is_reserved(unsigned long start_pfn, unsigned long end_pfn)
74266 unsigned long pfn;
74267
74268 for (pfn = start_pfn; pfn < end_pfn; pfn++) {
74269+#ifdef CONFIG_X86_32
74270+ /* boot failures in VMware 8 on 32bit vanilla since
74271+ this change */
74272+ if (!pfn_valid(pfn) || PageReserved(pfn_to_page(pfn)))
74273+#else
74274 if (!pfn_valid_within(pfn) || PageReserved(pfn_to_page(pfn)))
74275+#endif
74276 return 1;
74277 }
74278 return 0;
74279diff --git a/mm/percpu.c b/mm/percpu.c
74280index bb4be74..a43ea85 100644
74281--- a/mm/percpu.c
74282+++ b/mm/percpu.c
74283@@ -122,7 +122,7 @@ static unsigned int pcpu_low_unit_cpu __read_mostly;
74284 static unsigned int pcpu_high_unit_cpu __read_mostly;
74285
74286 /* the address of the first chunk which starts with the kernel static area */
74287-void *pcpu_base_addr __read_mostly;
74288+void *pcpu_base_addr __read_only;
74289 EXPORT_SYMBOL_GPL(pcpu_base_addr);
74290
74291 static const int *pcpu_unit_map __read_mostly; /* cpu -> unit */
74292diff --git a/mm/process_vm_access.c b/mm/process_vm_access.c
74293index 926b466..b23df53 100644
74294--- a/mm/process_vm_access.c
74295+++ b/mm/process_vm_access.c
74296@@ -13,6 +13,7 @@
74297 #include <linux/uio.h>
74298 #include <linux/sched.h>
74299 #include <linux/highmem.h>
74300+#include <linux/security.h>
74301 #include <linux/ptrace.h>
74302 #include <linux/slab.h>
74303 #include <linux/syscalls.h>
74304@@ -258,19 +259,19 @@ static ssize_t process_vm_rw_core(pid_t pid, const struct iovec *lvec,
74305 size_t iov_l_curr_offset = 0;
74306 ssize_t iov_len;
74307
74308+ return -ENOSYS; // PaX: until properly audited
74309+
74310 /*
74311 * Work out how many pages of struct pages we're going to need
74312 * when eventually calling get_user_pages
74313 */
74314 for (i = 0; i < riovcnt; i++) {
74315 iov_len = rvec[i].iov_len;
74316- if (iov_len > 0) {
74317- nr_pages_iov = ((unsigned long)rvec[i].iov_base
74318- + iov_len)
74319- / PAGE_SIZE - (unsigned long)rvec[i].iov_base
74320- / PAGE_SIZE + 1;
74321- nr_pages = max(nr_pages, nr_pages_iov);
74322- }
74323+ if (iov_len <= 0)
74324+ continue;
74325+ nr_pages_iov = ((unsigned long)rvec[i].iov_base + iov_len) / PAGE_SIZE -
74326+ (unsigned long)rvec[i].iov_base / PAGE_SIZE + 1;
74327+ nr_pages = max(nr_pages, nr_pages_iov);
74328 }
74329
74330 if (nr_pages == 0)
74331@@ -298,6 +299,11 @@ static ssize_t process_vm_rw_core(pid_t pid, const struct iovec *lvec,
74332 goto free_proc_pages;
74333 }
74334
74335+ if (gr_handle_ptrace(task, vm_write ? PTRACE_POKETEXT : PTRACE_ATTACH)) {
74336+ rc = -EPERM;
74337+ goto put_task_struct;
74338+ }
74339+
74340 mm = mm_access(task, PTRACE_MODE_ATTACH);
74341 if (!mm || IS_ERR(mm)) {
74342 rc = IS_ERR(mm) ? PTR_ERR(mm) : -ESRCH;
74343diff --git a/mm/rmap.c b/mm/rmap.c
74344index 0f3b7cd..c5652b6 100644
74345--- a/mm/rmap.c
74346+++ b/mm/rmap.c
74347@@ -167,6 +167,10 @@ int anon_vma_prepare(struct vm_area_struct *vma)
74348 struct anon_vma *anon_vma = vma->anon_vma;
74349 struct anon_vma_chain *avc;
74350
74351+#ifdef CONFIG_PAX_SEGMEXEC
74352+ struct anon_vma_chain *avc_m = NULL;
74353+#endif
74354+
74355 might_sleep();
74356 if (unlikely(!anon_vma)) {
74357 struct mm_struct *mm = vma->vm_mm;
74358@@ -176,6 +180,12 @@ int anon_vma_prepare(struct vm_area_struct *vma)
74359 if (!avc)
74360 goto out_enomem;
74361
74362+#ifdef CONFIG_PAX_SEGMEXEC
74363+ avc_m = anon_vma_chain_alloc(GFP_KERNEL);
74364+ if (!avc_m)
74365+ goto out_enomem_free_avc;
74366+#endif
74367+
74368 anon_vma = find_mergeable_anon_vma(vma);
74369 allocated = NULL;
74370 if (!anon_vma) {
74371@@ -189,6 +199,18 @@ int anon_vma_prepare(struct vm_area_struct *vma)
74372 /* page_table_lock to protect against threads */
74373 spin_lock(&mm->page_table_lock);
74374 if (likely(!vma->anon_vma)) {
74375+
74376+#ifdef CONFIG_PAX_SEGMEXEC
74377+ struct vm_area_struct *vma_m = pax_find_mirror_vma(vma);
74378+
74379+ if (vma_m) {
74380+ BUG_ON(vma_m->anon_vma);
74381+ vma_m->anon_vma = anon_vma;
74382+ anon_vma_chain_link(vma_m, avc_m, anon_vma);
74383+ avc_m = NULL;
74384+ }
74385+#endif
74386+
74387 vma->anon_vma = anon_vma;
74388 anon_vma_chain_link(vma, avc, anon_vma);
74389 allocated = NULL;
74390@@ -199,12 +221,24 @@ int anon_vma_prepare(struct vm_area_struct *vma)
74391
74392 if (unlikely(allocated))
74393 put_anon_vma(allocated);
74394+
74395+#ifdef CONFIG_PAX_SEGMEXEC
74396+ if (unlikely(avc_m))
74397+ anon_vma_chain_free(avc_m);
74398+#endif
74399+
74400 if (unlikely(avc))
74401 anon_vma_chain_free(avc);
74402 }
74403 return 0;
74404
74405 out_enomem_free_avc:
74406+
74407+#ifdef CONFIG_PAX_SEGMEXEC
74408+ if (avc_m)
74409+ anon_vma_chain_free(avc_m);
74410+#endif
74411+
74412 anon_vma_chain_free(avc);
74413 out_enomem:
74414 return -ENOMEM;
74415@@ -240,7 +274,7 @@ static inline void unlock_anon_vma_root(struct anon_vma *root)
74416 * Attach the anon_vmas from src to dst.
74417 * Returns 0 on success, -ENOMEM on failure.
74418 */
74419-int anon_vma_clone(struct vm_area_struct *dst, struct vm_area_struct *src)
74420+int anon_vma_clone(struct vm_area_struct *dst, const struct vm_area_struct *src)
74421 {
74422 struct anon_vma_chain *avc, *pavc;
74423 struct anon_vma *root = NULL;
74424@@ -318,7 +352,7 @@ void anon_vma_moveto_tail(struct vm_area_struct *dst)
74425 * the corresponding VMA in the parent process is attached to.
74426 * Returns 0 on success, non-zero on failure.
74427 */
74428-int anon_vma_fork(struct vm_area_struct *vma, struct vm_area_struct *pvma)
74429+int anon_vma_fork(struct vm_area_struct *vma, const struct vm_area_struct *pvma)
74430 {
74431 struct anon_vma_chain *avc;
74432 struct anon_vma *anon_vma;
74433diff --git a/mm/shmem.c b/mm/shmem.c
74434index d2eeca1..3f160be 100644
74435--- a/mm/shmem.c
74436+++ b/mm/shmem.c
74437@@ -31,7 +31,7 @@
74438 #include <linux/export.h>
74439 #include <linux/swap.h>
74440
74441-static struct vfsmount *shm_mnt;
74442+struct vfsmount *shm_mnt;
74443
74444 #ifdef CONFIG_SHMEM
74445 /*
74446@@ -75,7 +75,7 @@ static struct vfsmount *shm_mnt;
74447 #define BOGO_DIRENT_SIZE 20
74448
74449 /* Symlink up to this size is kmalloc'ed instead of using a swappable page */
74450-#define SHORT_SYMLINK_LEN 128
74451+#define SHORT_SYMLINK_LEN 64
74452
74453 struct shmem_xattr {
74454 struct list_head list; /* anchored by shmem_inode_info->xattr_list */
74455@@ -2594,8 +2594,7 @@ int shmem_fill_super(struct super_block *sb, void *data, int silent)
74456 int err = -ENOMEM;
74457
74458 /* Round up to L1_CACHE_BYTES to resist false sharing */
74459- sbinfo = kzalloc(max((int)sizeof(struct shmem_sb_info),
74460- L1_CACHE_BYTES), GFP_KERNEL);
74461+ sbinfo = kzalloc(max(sizeof(struct shmem_sb_info), L1_CACHE_BYTES), GFP_KERNEL);
74462 if (!sbinfo)
74463 return -ENOMEM;
74464
74465diff --git a/mm/slab.c b/mm/slab.c
74466index d066037..5bb78d9 100644
74467--- a/mm/slab.c
74468+++ b/mm/slab.c
74469@@ -164,7 +164,7 @@ static bool pfmemalloc_active __read_mostly;
74470
74471 /* Legal flag mask for kmem_cache_create(). */
74472 #if DEBUG
74473-# define CREATE_MASK (SLAB_RED_ZONE | \
74474+# define CREATE_MASK (SLAB_USERCOPY | SLAB_RED_ZONE | \
74475 SLAB_POISON | SLAB_HWCACHE_ALIGN | \
74476 SLAB_CACHE_DMA | \
74477 SLAB_STORE_USER | \
74478@@ -172,7 +172,7 @@ static bool pfmemalloc_active __read_mostly;
74479 SLAB_DESTROY_BY_RCU | SLAB_MEM_SPREAD | \
74480 SLAB_DEBUG_OBJECTS | SLAB_NOLEAKTRACE | SLAB_NOTRACK)
74481 #else
74482-# define CREATE_MASK (SLAB_HWCACHE_ALIGN | \
74483+# define CREATE_MASK (SLAB_USERCOPY | SLAB_HWCACHE_ALIGN | \
74484 SLAB_CACHE_DMA | \
74485 SLAB_RECLAIM_ACCOUNT | SLAB_PANIC | \
74486 SLAB_DESTROY_BY_RCU | SLAB_MEM_SPREAD | \
74487@@ -322,7 +322,7 @@ struct kmem_list3 {
74488 * Need this for bootstrapping a per node allocator.
74489 */
74490 #define NUM_INIT_LISTS (3 * MAX_NUMNODES)
74491-static struct kmem_list3 __initdata initkmem_list3[NUM_INIT_LISTS];
74492+static struct kmem_list3 initkmem_list3[NUM_INIT_LISTS];
74493 #define CACHE_CACHE 0
74494 #define SIZE_AC MAX_NUMNODES
74495 #define SIZE_L3 (2 * MAX_NUMNODES)
74496@@ -423,10 +423,10 @@ static void kmem_list3_init(struct kmem_list3 *parent)
74497 if ((x)->max_freeable < i) \
74498 (x)->max_freeable = i; \
74499 } while (0)
74500-#define STATS_INC_ALLOCHIT(x) atomic_inc(&(x)->allochit)
74501-#define STATS_INC_ALLOCMISS(x) atomic_inc(&(x)->allocmiss)
74502-#define STATS_INC_FREEHIT(x) atomic_inc(&(x)->freehit)
74503-#define STATS_INC_FREEMISS(x) atomic_inc(&(x)->freemiss)
74504+#define STATS_INC_ALLOCHIT(x) atomic_inc_unchecked(&(x)->allochit)
74505+#define STATS_INC_ALLOCMISS(x) atomic_inc_unchecked(&(x)->allocmiss)
74506+#define STATS_INC_FREEHIT(x) atomic_inc_unchecked(&(x)->freehit)
74507+#define STATS_INC_FREEMISS(x) atomic_inc_unchecked(&(x)->freemiss)
74508 #else
74509 #define STATS_INC_ACTIVE(x) do { } while (0)
74510 #define STATS_DEC_ACTIVE(x) do { } while (0)
74511@@ -549,7 +549,7 @@ static inline void *index_to_obj(struct kmem_cache *cache, struct slab *slab,
74512 * reciprocal_divide(offset, cache->reciprocal_buffer_size)
74513 */
74514 static inline unsigned int obj_to_index(const struct kmem_cache *cache,
74515- const struct slab *slab, void *obj)
74516+ const struct slab *slab, const void *obj)
74517 {
74518 u32 offset = (obj - slab->s_mem);
74519 return reciprocal_divide(offset, cache->reciprocal_buffer_size);
74520@@ -570,12 +570,13 @@ EXPORT_SYMBOL(malloc_sizes);
74521 struct cache_names {
74522 char *name;
74523 char *name_dma;
74524+ char *name_usercopy;
74525 };
74526
74527 static struct cache_names __initdata cache_names[] = {
74528-#define CACHE(x) { .name = "size-" #x, .name_dma = "size-" #x "(DMA)" },
74529+#define CACHE(x) { .name = "size-" #x, .name_dma = "size-" #x "(DMA)", .name_usercopy = "size-" #x "(USERCOPY)" },
74530 #include <linux/kmalloc_sizes.h>
74531- {NULL,}
74532+ {NULL}
74533 #undef CACHE
74534 };
74535
74536@@ -736,6 +737,12 @@ static inline struct kmem_cache *__find_general_cachep(size_t size,
74537 if (unlikely(gfpflags & GFP_DMA))
74538 return csizep->cs_dmacachep;
74539 #endif
74540+
74541+#ifdef CONFIG_PAX_USERCOPY_SLABS
74542+ if (unlikely(gfpflags & GFP_USERCOPY))
74543+ return csizep->cs_usercopycachep;
74544+#endif
74545+
74546 return csizep->cs_cachep;
74547 }
74548
74549@@ -1684,7 +1691,7 @@ void __init kmem_cache_init(void)
74550 sizes[INDEX_AC].cs_cachep = __kmem_cache_create(names[INDEX_AC].name,
74551 sizes[INDEX_AC].cs_size,
74552 ARCH_KMALLOC_MINALIGN,
74553- ARCH_KMALLOC_FLAGS|SLAB_PANIC,
74554+ ARCH_KMALLOC_FLAGS|SLAB_PANIC|SLAB_USERCOPY,
74555 NULL);
74556
74557 if (INDEX_AC != INDEX_L3) {
74558@@ -1692,7 +1699,7 @@ void __init kmem_cache_init(void)
74559 __kmem_cache_create(names[INDEX_L3].name,
74560 sizes[INDEX_L3].cs_size,
74561 ARCH_KMALLOC_MINALIGN,
74562- ARCH_KMALLOC_FLAGS|SLAB_PANIC,
74563+ ARCH_KMALLOC_FLAGS|SLAB_PANIC|SLAB_USERCOPY,
74564 NULL);
74565 }
74566
74567@@ -1710,7 +1717,7 @@ void __init kmem_cache_init(void)
74568 sizes->cs_cachep = __kmem_cache_create(names->name,
74569 sizes->cs_size,
74570 ARCH_KMALLOC_MINALIGN,
74571- ARCH_KMALLOC_FLAGS|SLAB_PANIC,
74572+ ARCH_KMALLOC_FLAGS|SLAB_PANIC|SLAB_USERCOPY,
74573 NULL);
74574 }
74575 #ifdef CONFIG_ZONE_DMA
74576@@ -1722,6 +1729,16 @@ void __init kmem_cache_init(void)
74577 SLAB_PANIC,
74578 NULL);
74579 #endif
74580+
74581+#ifdef CONFIG_PAX_USERCOPY_SLABS
74582+ sizes->cs_usercopycachep = kmem_cache_create(
74583+ names->name_usercopy,
74584+ sizes->cs_size,
74585+ ARCH_KMALLOC_MINALIGN,
74586+ ARCH_KMALLOC_FLAGS|SLAB_PANIC|SLAB_USERCOPY,
74587+ NULL);
74588+#endif
74589+
74590 sizes++;
74591 names++;
74592 }
74593@@ -4467,10 +4484,10 @@ static int s_show(struct seq_file *m, void *p)
74594 }
74595 /* cpu stats */
74596 {
74597- unsigned long allochit = atomic_read(&cachep->allochit);
74598- unsigned long allocmiss = atomic_read(&cachep->allocmiss);
74599- unsigned long freehit = atomic_read(&cachep->freehit);
74600- unsigned long freemiss = atomic_read(&cachep->freemiss);
74601+ unsigned long allochit = atomic_read_unchecked(&cachep->allochit);
74602+ unsigned long allocmiss = atomic_read_unchecked(&cachep->allocmiss);
74603+ unsigned long freehit = atomic_read_unchecked(&cachep->freehit);
74604+ unsigned long freemiss = atomic_read_unchecked(&cachep->freemiss);
74605
74606 seq_printf(m, " : cpustat %6lu %6lu %6lu %6lu",
74607 allochit, allocmiss, freehit, freemiss);
74608@@ -4729,13 +4746,71 @@ static int __init slab_proc_init(void)
74609 {
74610 proc_create("slabinfo",S_IWUSR|S_IRUSR,NULL,&proc_slabinfo_operations);
74611 #ifdef CONFIG_DEBUG_SLAB_LEAK
74612- proc_create("slab_allocators", 0, NULL, &proc_slabstats_operations);
74613+ proc_create("slab_allocators", S_IRUSR, NULL, &proc_slabstats_operations);
74614 #endif
74615 return 0;
74616 }
74617 module_init(slab_proc_init);
74618 #endif
74619
74620+bool is_usercopy_object(const void *ptr)
74621+{
74622+ struct page *page;
74623+ struct kmem_cache *cachep;
74624+
74625+ if (ZERO_OR_NULL_PTR(ptr))
74626+ return false;
74627+
74628+ if (!slab_is_available())
74629+ return false;
74630+
74631+ if (!virt_addr_valid(ptr))
74632+ return false;
74633+
74634+ page = virt_to_head_page(ptr);
74635+
74636+ if (!PageSlab(page))
74637+ return false;
74638+
74639+ cachep = page_get_cache(page);
74640+ return cachep->flags & SLAB_USERCOPY;
74641+}
74642+
74643+#ifdef CONFIG_PAX_USERCOPY
74644+const char *check_heap_object(const void *ptr, unsigned long n, bool to)
74645+{
74646+ struct page *page;
74647+ struct kmem_cache *cachep;
74648+ struct slab *slabp;
74649+ unsigned int objnr;
74650+ unsigned long offset;
74651+
74652+ if (ZERO_OR_NULL_PTR(ptr))
74653+ return "<null>";
74654+
74655+ if (!virt_addr_valid(ptr))
74656+ return NULL;
74657+
74658+ page = virt_to_head_page(ptr);
74659+
74660+ if (!PageSlab(page))
74661+ return NULL;
74662+
74663+ cachep = page_get_cache(page);
74664+ if (!(cachep->flags & SLAB_USERCOPY))
74665+ return cachep->name;
74666+
74667+ slabp = page->slab_page;
74668+ objnr = obj_to_index(cachep, slabp, ptr);
74669+ BUG_ON(objnr >= cachep->num);
74670+ offset = ptr - index_to_obj(cachep, slabp, objnr) - obj_offset(cachep);
74671+ if (offset <= cachep->object_size && n <= cachep->object_size - offset)
74672+ return NULL;
74673+
74674+ return cachep->name;
74675+}
74676+#endif
74677+
74678 /**
74679 * ksize - get the actual amount of memory allocated for a given object
74680 * @objp: Pointer to the object
74681diff --git a/mm/slob.c b/mm/slob.c
74682index 45d4ca7..88943c1 100644
74683--- a/mm/slob.c
74684+++ b/mm/slob.c
74685@@ -159,7 +159,7 @@ static void set_slob(slob_t *s, slobidx_t size, slob_t *next)
74686 /*
74687 * Return the size of a slob block.
74688 */
74689-static slobidx_t slob_units(slob_t *s)
74690+static slobidx_t slob_units(const slob_t *s)
74691 {
74692 if (s->units > 0)
74693 return s->units;
74694@@ -169,7 +169,7 @@ static slobidx_t slob_units(slob_t *s)
74695 /*
74696 * Return the next free slob block pointer after this one.
74697 */
74698-static slob_t *slob_next(slob_t *s)
74699+static slob_t *slob_next(const slob_t *s)
74700 {
74701 slob_t *base = (slob_t *)((unsigned long)s & PAGE_MASK);
74702 slobidx_t next;
74703@@ -184,14 +184,14 @@ static slob_t *slob_next(slob_t *s)
74704 /*
74705 * Returns true if s is the last free block in its page.
74706 */
74707-static int slob_last(slob_t *s)
74708+static int slob_last(const slob_t *s)
74709 {
74710 return !((unsigned long)slob_next(s) & ~PAGE_MASK);
74711 }
74712
74713-static void *slob_new_pages(gfp_t gfp, int order, int node)
74714+static struct page *slob_new_pages(gfp_t gfp, unsigned int order, int node)
74715 {
74716- void *page;
74717+ struct page *page;
74718
74719 #ifdef CONFIG_NUMA
74720 if (node != -1)
74721@@ -203,14 +203,18 @@ static void *slob_new_pages(gfp_t gfp, int order, int node)
74722 if (!page)
74723 return NULL;
74724
74725- return page_address(page);
74726+ __SetPageSlab(page);
74727+ return page;
74728 }
74729
74730-static void slob_free_pages(void *b, int order)
74731+static void slob_free_pages(struct page *sp, int order)
74732 {
74733 if (current->reclaim_state)
74734 current->reclaim_state->reclaimed_slab += 1 << order;
74735- free_pages((unsigned long)b, order);
74736+ __ClearPageSlab(sp);
74737+ reset_page_mapcount(sp);
74738+ sp->private = 0;
74739+ __free_pages(sp, order);
74740 }
74741
74742 /*
74743@@ -315,15 +319,15 @@ static void *slob_alloc(size_t size, gfp_t gfp, int align, int node)
74744
74745 /* Not enough space: must allocate a new page */
74746 if (!b) {
74747- b = slob_new_pages(gfp & ~__GFP_ZERO, 0, node);
74748- if (!b)
74749+ sp = slob_new_pages(gfp & ~__GFP_ZERO, 0, node);
74750+ if (!sp)
74751 return NULL;
74752- sp = virt_to_page(b);
74753- __SetPageSlab(sp);
74754+ b = page_address(sp);
74755
74756 spin_lock_irqsave(&slob_lock, flags);
74757 sp->units = SLOB_UNITS(PAGE_SIZE);
74758 sp->freelist = b;
74759+ sp->private = 0;
74760 INIT_LIST_HEAD(&sp->list);
74761 set_slob(b, SLOB_UNITS(PAGE_SIZE), b + SLOB_UNITS(PAGE_SIZE));
74762 set_slob_page_free(sp, slob_list);
74763@@ -361,9 +365,7 @@ static void slob_free(void *block, int size)
74764 if (slob_page_free(sp))
74765 clear_slob_page_free(sp);
74766 spin_unlock_irqrestore(&slob_lock, flags);
74767- __ClearPageSlab(sp);
74768- reset_page_mapcount(sp);
74769- slob_free_pages(b, 0);
74770+ slob_free_pages(sp, 0);
74771 return;
74772 }
74773
74774@@ -425,11 +427,10 @@ out:
74775 * End of slob allocator proper. Begin kmem_cache_alloc and kmalloc frontend.
74776 */
74777
74778-void *__kmalloc_node(size_t size, gfp_t gfp, int node)
74779+static void *__kmalloc_node_align(size_t size, gfp_t gfp, int node, int align)
74780 {
74781- unsigned int *m;
74782- int align = max(ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
74783- void *ret;
74784+ slob_t *m;
74785+ void *ret = NULL;
74786
74787 gfp &= gfp_allowed_mask;
74788
74789@@ -443,20 +444,23 @@ void *__kmalloc_node(size_t size, gfp_t gfp, int node)
74790
74791 if (!m)
74792 return NULL;
74793- *m = size;
74794+ BUILD_BUG_ON(ARCH_KMALLOC_MINALIGN < 2 * SLOB_UNIT);
74795+ BUILD_BUG_ON(ARCH_SLAB_MINALIGN < 2 * SLOB_UNIT);
74796+ m[0].units = size;
74797+ m[1].units = align;
74798 ret = (void *)m + align;
74799
74800 trace_kmalloc_node(_RET_IP_, ret,
74801 size, size + align, gfp, node);
74802 } else {
74803 unsigned int order = get_order(size);
74804+ struct page *page;
74805
74806 if (likely(order))
74807 gfp |= __GFP_COMP;
74808- ret = slob_new_pages(gfp, order, node);
74809- if (ret) {
74810- struct page *page;
74811- page = virt_to_page(ret);
74812+ page = slob_new_pages(gfp, order, node);
74813+ if (page) {
74814+ ret = page_address(page);
74815 page->private = size;
74816 }
74817
74818@@ -464,7 +468,16 @@ void *__kmalloc_node(size_t size, gfp_t gfp, int node)
74819 size, PAGE_SIZE << order, gfp, node);
74820 }
74821
74822- kmemleak_alloc(ret, size, 1, gfp);
74823+ return ret;
74824+}
74825+
74826+void *__kmalloc_node(size_t size, gfp_t gfp, int node)
74827+{
74828+ int align = max(ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
74829+ void *ret = __kmalloc_node_align(size, gfp, node, align);
74830+
74831+ if (!ZERO_OR_NULL_PTR(ret))
74832+ kmemleak_alloc(ret, size, 1, gfp);
74833 return ret;
74834 }
74835 EXPORT_SYMBOL(__kmalloc_node);
74836@@ -480,15 +493,91 @@ void kfree(const void *block)
74837 kmemleak_free(block);
74838
74839 sp = virt_to_page(block);
74840- if (PageSlab(sp)) {
74841+ VM_BUG_ON(!PageSlab(sp));
74842+ if (!sp->private) {
74843 int align = max(ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
74844- unsigned int *m = (unsigned int *)(block - align);
74845- slob_free(m, *m + align);
74846- } else
74847+ slob_t *m = (slob_t *)(block - align);
74848+ slob_free(m, m[0].units + align);
74849+ } else {
74850+ __ClearPageSlab(sp);
74851+ reset_page_mapcount(sp);
74852+ sp->private = 0;
74853 put_page(sp);
74854+ }
74855 }
74856 EXPORT_SYMBOL(kfree);
74857
74858+bool is_usercopy_object(const void *ptr)
74859+{
74860+ if (!slab_is_available())
74861+ return false;
74862+
74863+ // PAX: TODO
74864+
74865+ return false;
74866+}
74867+
74868+#ifdef CONFIG_PAX_USERCOPY
74869+const char *check_heap_object(const void *ptr, unsigned long n, bool to)
74870+{
74871+ struct page *page;
74872+ const slob_t *free;
74873+ const void *base;
74874+ unsigned long flags;
74875+
74876+ if (ZERO_OR_NULL_PTR(ptr))
74877+ return "<null>";
74878+
74879+ if (!virt_addr_valid(ptr))
74880+ return NULL;
74881+
74882+ page = virt_to_head_page(ptr);
74883+ if (!PageSlab(page))
74884+ return NULL;
74885+
74886+ if (page->private) {
74887+ base = page;
74888+ if (base <= ptr && n <= page->private - (ptr - base))
74889+ return NULL;
74890+ return "<slob>";
74891+ }
74892+
74893+ /* some tricky double walking to find the chunk */
74894+ spin_lock_irqsave(&slob_lock, flags);
74895+ base = (void *)((unsigned long)ptr & PAGE_MASK);
74896+ free = page->freelist;
74897+
74898+ while (!slob_last(free) && (void *)free <= ptr) {
74899+ base = free + slob_units(free);
74900+ free = slob_next(free);
74901+ }
74902+
74903+ while (base < (void *)free) {
74904+ slobidx_t m = ((slob_t *)base)[0].units, align = ((slob_t *)base)[1].units;
74905+ int size = SLOB_UNIT * SLOB_UNITS(m + align);
74906+ int offset;
74907+
74908+ if (ptr < base + align)
74909+ break;
74910+
74911+ offset = ptr - base - align;
74912+ if (offset >= m) {
74913+ base += size;
74914+ continue;
74915+ }
74916+
74917+ if (n > m - offset)
74918+ break;
74919+
74920+ spin_unlock_irqrestore(&slob_lock, flags);
74921+ return NULL;
74922+ }
74923+
74924+ spin_unlock_irqrestore(&slob_lock, flags);
74925+ return "<slob>";
74926+}
74927+#endif
74928+
74929 /* can't use ksize for kmem_cache_alloc memory, only kmalloc */
74930 size_t ksize(const void *block)
74931 {
74932@@ -499,10 +588,11 @@ size_t ksize(const void *block)
74933 return 0;
74934
74935 sp = virt_to_page(block);
74936- if (PageSlab(sp)) {
74937+ VM_BUG_ON(!PageSlab(sp));
74938+ if (!sp->private) {
74939 int align = max(ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
74940- unsigned int *m = (unsigned int *)(block - align);
74941- return SLOB_UNITS(*m) * SLOB_UNIT;
74942+ slob_t *m = (slob_t *)(block - align);
74943+ return SLOB_UNITS(m[0].units) * SLOB_UNIT;
74944 } else
74945 return sp->private;
74946 }
74947@@ -513,8 +603,13 @@ struct kmem_cache *__kmem_cache_create(const char *name, size_t size,
74948 {
74949 struct kmem_cache *c;
74950
74951+#ifdef CONFIG_PAX_USERCOPY_SLABS
74952+ c = __kmalloc_node_align(sizeof(struct kmem_cache),
74953+ GFP_KERNEL, -1, ARCH_KMALLOC_MINALIGN);
74954+#else
74955 c = slob_alloc(sizeof(struct kmem_cache),
74956 GFP_KERNEL, ARCH_KMALLOC_MINALIGN, -1);
74957+#endif
74958
74959 if (c) {
74960 c->name = name;
74961@@ -549,23 +644,33 @@ EXPORT_SYMBOL(kmem_cache_destroy);
74962
74963 void *kmem_cache_alloc_node(struct kmem_cache *c, gfp_t flags, int node)
74964 {
74965- void *b;
74966+ void *b = NULL;
74967
74968 flags &= gfp_allowed_mask;
74969
74970 lockdep_trace_alloc(flags);
74971
74972+#ifdef CONFIG_PAX_USERCOPY_SLABS
74973+ b = __kmalloc_node_align(c->size, flags, node, c->align);
74974+#else
74975 if (c->size < PAGE_SIZE) {
74976 b = slob_alloc(c->size, flags, c->align, node);
74977 trace_kmem_cache_alloc_node(_RET_IP_, b, c->size,
74978 SLOB_UNITS(c->size) * SLOB_UNIT,
74979 flags, node);
74980 } else {
74981- b = slob_new_pages(flags, get_order(c->size), node);
74982+ struct page *sp;
74983+
74984+ sp = slob_new_pages(flags, get_order(c->size), node);
74985+ if (sp) {
74986+ b = page_address(sp);
74987+ sp->private = c->size;
74988+ }
74989 trace_kmem_cache_alloc_node(_RET_IP_, b, c->size,
74990 PAGE_SIZE << get_order(c->size),
74991 flags, node);
74992 }
74993+#endif
74994
74995 if (c->ctor)
74996 c->ctor(b);
74997@@ -577,10 +682,14 @@ EXPORT_SYMBOL(kmem_cache_alloc_node);
74998
74999 static void __kmem_cache_free(void *b, int size)
75000 {
75001- if (size < PAGE_SIZE)
75002+ struct page *sp;
75003+
75004+ sp = virt_to_page(b);
75005+ BUG_ON(!PageSlab(sp));
75006+ if (!sp->private)
75007 slob_free(b, size);
75008 else
75009- slob_free_pages(b, get_order(size));
75010+ slob_free_pages(sp, get_order(size));
75011 }
75012
75013 static void kmem_rcu_free(struct rcu_head *head)
75014@@ -593,17 +702,31 @@ static void kmem_rcu_free(struct rcu_head *head)
75015
75016 void kmem_cache_free(struct kmem_cache *c, void *b)
75017 {
75018+ int size = c->size;
75019+
75020+#ifdef CONFIG_PAX_USERCOPY_SLABS
75021+ if (size + c->align < PAGE_SIZE) {
75022+ size += c->align;
75023+ b -= c->align;
75024+ }
75025+#endif
75026+
75027 kmemleak_free_recursive(b, c->flags);
75028 if (unlikely(c->flags & SLAB_DESTROY_BY_RCU)) {
75029 struct slob_rcu *slob_rcu;
75030- slob_rcu = b + (c->size - sizeof(struct slob_rcu));
75031- slob_rcu->size = c->size;
75032+ slob_rcu = b + (size - sizeof(struct slob_rcu));
75033+ slob_rcu->size = size;
75034 call_rcu(&slob_rcu->head, kmem_rcu_free);
75035 } else {
75036- __kmem_cache_free(b, c->size);
75037+ __kmem_cache_free(b, size);
75038 }
75039
75040+#ifdef CONFIG_PAX_USERCOPY_SLABS
75041+ trace_kfree(_RET_IP_, b);
75042+#else
75043 trace_kmem_cache_free(_RET_IP_, b);
75044+#endif
75045+
75046 }
75047 EXPORT_SYMBOL(kmem_cache_free);
75048
75049diff --git a/mm/slub.c b/mm/slub.c
75050index 2fdd96f..1e2f893 100644
75051--- a/mm/slub.c
75052+++ b/mm/slub.c
75053@@ -201,7 +201,7 @@ struct track {
75054
75055 enum track_item { TRACK_ALLOC, TRACK_FREE };
75056
75057-#ifdef CONFIG_SYSFS
75058+#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
75059 static int sysfs_slab_add(struct kmem_cache *);
75060 static int sysfs_slab_alias(struct kmem_cache *, const char *);
75061 static void sysfs_slab_remove(struct kmem_cache *);
75062@@ -525,7 +525,7 @@ static void print_track(const char *s, struct track *t)
75063 if (!t->addr)
75064 return;
75065
75066- printk(KERN_ERR "INFO: %s in %pS age=%lu cpu=%u pid=%d\n",
75067+ printk(KERN_ERR "INFO: %s in %pA age=%lu cpu=%u pid=%d\n",
75068 s, (void *)t->addr, jiffies - t->when, t->cpu, t->pid);
75069 #ifdef CONFIG_STACKTRACE
75070 {
75071@@ -2612,6 +2612,8 @@ void kmem_cache_free(struct kmem_cache *s, void *x)
75072
75073 page = virt_to_head_page(x);
75074
75075+ BUG_ON(!PageSlab(page));
75076+
75077 slab_free(s, page, x, _RET_IP_);
75078
75079 trace_kmem_cache_free(_RET_IP_, x);
75080@@ -2645,7 +2647,7 @@ static int slub_min_objects;
75081 * Merge control. If this is set then no merging of slab caches will occur.
75082 * (Could be removed. This was introduced to pacify the merge skeptics.)
75083 */
75084-static int slub_nomerge;
75085+static int slub_nomerge = 1;
75086
75087 /*
75088 * Calculate the order of allocation given an slab object size.
75089@@ -3098,7 +3100,7 @@ static int kmem_cache_open(struct kmem_cache *s,
75090 else
75091 s->cpu_partial = 30;
75092
75093- s->refcount = 1;
75094+ atomic_set(&s->refcount, 1);
75095 #ifdef CONFIG_NUMA
75096 s->remote_node_defrag_ratio = 1000;
75097 #endif
75098@@ -3202,8 +3204,7 @@ static inline int kmem_cache_close(struct kmem_cache *s)
75099 void kmem_cache_destroy(struct kmem_cache *s)
75100 {
75101 mutex_lock(&slab_mutex);
75102- s->refcount--;
75103- if (!s->refcount) {
75104+ if (atomic_dec_and_test(&s->refcount)) {
75105 list_del(&s->list);
75106 mutex_unlock(&slab_mutex);
75107 if (kmem_cache_close(s)) {
75108@@ -3232,6 +3233,10 @@ static struct kmem_cache *kmem_cache;
75109 static struct kmem_cache *kmalloc_dma_caches[SLUB_PAGE_SHIFT];
75110 #endif
75111
75112+#ifdef CONFIG_PAX_USERCOPY_SLABS
75113+static struct kmem_cache *kmalloc_usercopy_caches[SLUB_PAGE_SHIFT];
75114+#endif
75115+
75116 static int __init setup_slub_min_order(char *str)
75117 {
75118 get_option(&str, &slub_min_order);
75119@@ -3346,6 +3351,13 @@ static struct kmem_cache *get_slab(size_t size, gfp_t flags)
75120 return kmalloc_dma_caches[index];
75121
75122 #endif
75123+
75124+#ifdef CONFIG_PAX_USERCOPY_SLABS
75125+ if (flags & SLAB_USERCOPY)
75126+ return kmalloc_usercopy_caches[index];
75127+
75128+#endif
75129+
75130 return kmalloc_caches[index];
75131 }
75132
75133@@ -3414,6 +3426,59 @@ void *__kmalloc_node(size_t size, gfp_t flags, int node)
75134 EXPORT_SYMBOL(__kmalloc_node);
75135 #endif
75136
75137+bool is_usercopy_object(const void *ptr)
75138+{
75139+ struct page *page;
75140+ struct kmem_cache *s;
75141+
75142+ if (ZERO_OR_NULL_PTR(ptr))
75143+ return false;
75144+
75145+ if (!slab_is_available())
75146+ return false;
75147+
75148+ if (!virt_addr_valid(ptr))
75149+ return false;
75150+
75151+ page = virt_to_head_page(ptr);
75152+
75153+ if (!PageSlab(page))
75154+ return false;
75155+
75156+ s = page->slab;
75157+ return s->flags & SLAB_USERCOPY;
75158+}
75159+
75160+#ifdef CONFIG_PAX_USERCOPY
75161+const char *check_heap_object(const void *ptr, unsigned long n, bool to)
75162+{
75163+ struct page *page;
75164+ struct kmem_cache *s;
75165+ unsigned long offset;
75166+
75167+ if (ZERO_OR_NULL_PTR(ptr))
75168+ return "<null>";
75169+
75170+ if (!virt_addr_valid(ptr))
75171+ return NULL;
75172+
75173+ page = virt_to_head_page(ptr);
75174+
75175+ if (!PageSlab(page))
75176+ return NULL;
75177+
75178+ s = page->slab;
75179+ if (!(s->flags & SLAB_USERCOPY))
75180+ return s->name;
75181+
75182+ offset = (ptr - page_address(page)) % s->size;
75183+ if (offset <= s->object_size && n <= s->object_size - offset)
75184+ return NULL;
75185+
75186+ return s->name;
75187+}
75188+#endif
75189+
75190 size_t ksize(const void *object)
75191 {
75192 struct page *page;
75193@@ -3688,7 +3753,7 @@ static void __init kmem_cache_bootstrap_fixup(struct kmem_cache *s)
75194 int node;
75195
75196 list_add(&s->list, &slab_caches);
75197- s->refcount = -1;
75198+ atomic_set(&s->refcount, -1);
75199
75200 for_each_node_state(node, N_NORMAL_MEMORY) {
75201 struct kmem_cache_node *n = get_node(s, node);
75202@@ -3808,17 +3873,17 @@ void __init kmem_cache_init(void)
75203
75204 /* Caches that are not of the two-to-the-power-of size */
75205 if (KMALLOC_MIN_SIZE <= 32) {
75206- kmalloc_caches[1] = create_kmalloc_cache("kmalloc-96", 96, 0);
75207+ kmalloc_caches[1] = create_kmalloc_cache("kmalloc-96", 96, SLAB_USERCOPY);
75208 caches++;
75209 }
75210
75211 if (KMALLOC_MIN_SIZE <= 64) {
75212- kmalloc_caches[2] = create_kmalloc_cache("kmalloc-192", 192, 0);
75213+ kmalloc_caches[2] = create_kmalloc_cache("kmalloc-192", 192, SLAB_USERCOPY);
75214 caches++;
75215 }
75216
75217 for (i = KMALLOC_SHIFT_LOW; i < SLUB_PAGE_SHIFT; i++) {
75218- kmalloc_caches[i] = create_kmalloc_cache("kmalloc", 1 << i, 0);
75219+ kmalloc_caches[i] = create_kmalloc_cache("kmalloc", 1 << i, SLAB_USERCOPY);
75220 caches++;
75221 }
75222
75223@@ -3860,6 +3925,22 @@ void __init kmem_cache_init(void)
75224 }
75225 }
75226 #endif
75227+
75228+#ifdef CONFIG_PAX_USERCOPY_SLABS
75229+ for (i = 0; i < SLUB_PAGE_SHIFT; i++) {
75230+ struct kmem_cache *s = kmalloc_caches[i];
75231+
75232+ if (s && s->size) {
75233+ char *name = kasprintf(GFP_NOWAIT,
75234+ "usercopy-kmalloc-%d", s->object_size);
75235+
75236+ BUG_ON(!name);
75237+ kmalloc_usercopy_caches[i] = create_kmalloc_cache(name,
75238+ s->object_size, SLAB_USERCOPY);
75239+ }
75240+ }
75241+#endif
75242+
75243 printk(KERN_INFO
75244 "SLUB: Genslabs=%d, HWalign=%d, Order=%d-%d, MinObjects=%d,"
75245 " CPUs=%d, Nodes=%d\n",
75246@@ -3886,7 +3967,7 @@ static int slab_unmergeable(struct kmem_cache *s)
75247 /*
75248 * We may have set a slab to be unmergeable during bootstrap.
75249 */
75250- if (s->refcount < 0)
75251+ if (atomic_read(&s->refcount) < 0)
75252 return 1;
75253
75254 return 0;
75255@@ -3941,7 +4022,7 @@ struct kmem_cache *__kmem_cache_create(const char *name, size_t size,
75256
75257 s = find_mergeable(size, align, flags, name, ctor);
75258 if (s) {
75259- s->refcount++;
75260+ atomic_inc(&s->refcount);
75261 /*
75262 * Adjust the object sizes so that we clear
75263 * the complete object on kzalloc.
75264@@ -3950,7 +4031,7 @@ struct kmem_cache *__kmem_cache_create(const char *name, size_t size,
75265 s->inuse = max_t(int, s->inuse, ALIGN(size, sizeof(void *)));
75266
75267 if (sysfs_slab_alias(s, name)) {
75268- s->refcount--;
75269+ atomic_dec(&s->refcount);
75270 return NULL;
75271 }
75272 return s;
75273@@ -4072,7 +4153,7 @@ void *__kmalloc_node_track_caller(size_t size, gfp_t gfpflags,
75274 }
75275 #endif
75276
75277-#ifdef CONFIG_SYSFS
75278+#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
75279 static int count_inuse(struct page *page)
75280 {
75281 return page->inuse;
75282@@ -4459,12 +4540,12 @@ static void resiliency_test(void)
75283 validate_slab_cache(kmalloc_caches[9]);
75284 }
75285 #else
75286-#ifdef CONFIG_SYSFS
75287+#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
75288 static void resiliency_test(void) {};
75289 #endif
75290 #endif
75291
75292-#ifdef CONFIG_SYSFS
75293+#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
75294 enum slab_stat_type {
75295 SL_ALL, /* All slabs */
75296 SL_PARTIAL, /* Only partially allocated slabs */
75297@@ -4708,7 +4789,7 @@ SLAB_ATTR_RO(ctor);
75298
75299 static ssize_t aliases_show(struct kmem_cache *s, char *buf)
75300 {
75301- return sprintf(buf, "%d\n", s->refcount - 1);
75302+ return sprintf(buf, "%d\n", atomic_read(&s->refcount) - 1);
75303 }
75304 SLAB_ATTR_RO(aliases);
75305
75306@@ -5279,6 +5360,7 @@ static char *create_unique_id(struct kmem_cache *s)
75307 return name;
75308 }
75309
75310+#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
75311 static int sysfs_slab_add(struct kmem_cache *s)
75312 {
75313 int err;
75314@@ -5341,6 +5423,7 @@ static void sysfs_slab_remove(struct kmem_cache *s)
75315 kobject_del(&s->kobj);
75316 kobject_put(&s->kobj);
75317 }
75318+#endif
75319
75320 /*
75321 * Need to buffer aliases during bootup until sysfs becomes
75322@@ -5354,6 +5437,7 @@ struct saved_alias {
75323
75324 static struct saved_alias *alias_list;
75325
75326+#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
75327 static int sysfs_slab_alias(struct kmem_cache *s, const char *name)
75328 {
75329 struct saved_alias *al;
75330@@ -5376,6 +5460,7 @@ static int sysfs_slab_alias(struct kmem_cache *s, const char *name)
75331 alias_list = al;
75332 return 0;
75333 }
75334+#endif
75335
75336 static int __init slab_sysfs_init(void)
75337 {
75338diff --git a/mm/sparse-vmemmap.c b/mm/sparse-vmemmap.c
75339index 1b7e22a..3fcd4f3 100644
75340--- a/mm/sparse-vmemmap.c
75341+++ b/mm/sparse-vmemmap.c
75342@@ -128,7 +128,7 @@ pud_t * __meminit vmemmap_pud_populate(pgd_t *pgd, unsigned long addr, int node)
75343 void *p = vmemmap_alloc_block(PAGE_SIZE, node);
75344 if (!p)
75345 return NULL;
75346- pud_populate(&init_mm, pud, p);
75347+ pud_populate_kernel(&init_mm, pud, p);
75348 }
75349 return pud;
75350 }
75351@@ -140,7 +140,7 @@ pgd_t * __meminit vmemmap_pgd_populate(unsigned long addr, int node)
75352 void *p = vmemmap_alloc_block(PAGE_SIZE, node);
75353 if (!p)
75354 return NULL;
75355- pgd_populate(&init_mm, pgd, p);
75356+ pgd_populate_kernel(&init_mm, pgd, p);
75357 }
75358 return pgd;
75359 }
75360diff --git a/mm/swap.c b/mm/swap.c
75361index 7782588..228c784 100644
75362--- a/mm/swap.c
75363+++ b/mm/swap.c
75364@@ -30,6 +30,7 @@
75365 #include <linux/backing-dev.h>
75366 #include <linux/memcontrol.h>
75367 #include <linux/gfp.h>
75368+#include <linux/hugetlb.h>
75369
75370 #include "internal.h"
75371
75372@@ -72,6 +73,8 @@ static void __put_compound_page(struct page *page)
75373
75374 __page_cache_release(page);
75375 dtor = get_compound_page_dtor(page);
75376+ if (!PageHuge(page))
75377+ BUG_ON(dtor != free_compound_page);
75378 (*dtor)(page);
75379 }
75380
75381diff --git a/mm/swapfile.c b/mm/swapfile.c
75382index 14e254c..a6af32c 100644
75383--- a/mm/swapfile.c
75384+++ b/mm/swapfile.c
75385@@ -64,7 +64,7 @@ static DEFINE_MUTEX(swapon_mutex);
75386
75387 static DECLARE_WAIT_QUEUE_HEAD(proc_poll_wait);
75388 /* Activity counter to indicate that a swapon or swapoff has occurred */
75389-static atomic_t proc_poll_event = ATOMIC_INIT(0);
75390+static atomic_unchecked_t proc_poll_event = ATOMIC_INIT(0);
75391
75392 static inline unsigned char swap_count(unsigned char ent)
75393 {
75394@@ -1603,7 +1603,7 @@ SYSCALL_DEFINE1(swapoff, const char __user *, specialfile)
75395 }
75396 filp_close(swap_file, NULL);
75397 err = 0;
75398- atomic_inc(&proc_poll_event);
75399+ atomic_inc_unchecked(&proc_poll_event);
75400 wake_up_interruptible(&proc_poll_wait);
75401
75402 out_dput:
75403@@ -1619,8 +1619,8 @@ static unsigned swaps_poll(struct file *file, poll_table *wait)
75404
75405 poll_wait(file, &proc_poll_wait, wait);
75406
75407- if (seq->poll_event != atomic_read(&proc_poll_event)) {
75408- seq->poll_event = atomic_read(&proc_poll_event);
75409+ if (seq->poll_event != atomic_read_unchecked(&proc_poll_event)) {
75410+ seq->poll_event = atomic_read_unchecked(&proc_poll_event);
75411 return POLLIN | POLLRDNORM | POLLERR | POLLPRI;
75412 }
75413
75414@@ -1718,7 +1718,7 @@ static int swaps_open(struct inode *inode, struct file *file)
75415 return ret;
75416
75417 seq = file->private_data;
75418- seq->poll_event = atomic_read(&proc_poll_event);
75419+ seq->poll_event = atomic_read_unchecked(&proc_poll_event);
75420 return 0;
75421 }
75422
75423@@ -2060,7 +2060,7 @@ SYSCALL_DEFINE2(swapon, const char __user *, specialfile, int, swap_flags)
75424 (frontswap_map) ? "FS" : "");
75425
75426 mutex_unlock(&swapon_mutex);
75427- atomic_inc(&proc_poll_event);
75428+ atomic_inc_unchecked(&proc_poll_event);
75429 wake_up_interruptible(&proc_poll_wait);
75430
75431 if (S_ISREG(inode->i_mode))
75432diff --git a/mm/util.c b/mm/util.c
75433index 8c7265a..c96d884 100644
75434--- a/mm/util.c
75435+++ b/mm/util.c
75436@@ -285,6 +285,12 @@ done:
75437 void arch_pick_mmap_layout(struct mm_struct *mm)
75438 {
75439 mm->mmap_base = TASK_UNMAPPED_BASE;
75440+
75441+#ifdef CONFIG_PAX_RANDMMAP
75442+ if (mm->pax_flags & MF_PAX_RANDMMAP)
75443+ mm->mmap_base += mm->delta_mmap;
75444+#endif
75445+
75446 mm->get_unmapped_area = arch_get_unmapped_area;
75447 mm->unmap_area = arch_unmap_area;
75448 }
75449diff --git a/mm/vmalloc.c b/mm/vmalloc.c
75450index 2bb90b1..ed47e53 100644
75451--- a/mm/vmalloc.c
75452+++ b/mm/vmalloc.c
75453@@ -39,8 +39,19 @@ static void vunmap_pte_range(pmd_t *pmd, unsigned long addr, unsigned long end)
75454
75455 pte = pte_offset_kernel(pmd, addr);
75456 do {
75457- pte_t ptent = ptep_get_and_clear(&init_mm, addr, pte);
75458- WARN_ON(!pte_none(ptent) && !pte_present(ptent));
75459+
75460+#if defined(CONFIG_MODULES) && defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
75461+ if ((unsigned long)MODULES_EXEC_VADDR <= addr && addr < (unsigned long)MODULES_EXEC_END) {
75462+ BUG_ON(!pte_exec(*pte));
75463+ set_pte_at(&init_mm, addr, pte, pfn_pte(__pa(addr) >> PAGE_SHIFT, PAGE_KERNEL_EXEC));
75464+ continue;
75465+ }
75466+#endif
75467+
75468+ {
75469+ pte_t ptent = ptep_get_and_clear(&init_mm, addr, pte);
75470+ WARN_ON(!pte_none(ptent) && !pte_present(ptent));
75471+ }
75472 } while (pte++, addr += PAGE_SIZE, addr != end);
75473 }
75474
75475@@ -91,6 +102,7 @@ static int vmap_pte_range(pmd_t *pmd, unsigned long addr,
75476 unsigned long end, pgprot_t prot, struct page **pages, int *nr)
75477 {
75478 pte_t *pte;
75479+ int ret = -ENOMEM;
75480
75481 /*
75482 * nr is a running index into the array which helps higher level
75483@@ -100,17 +112,30 @@ static int vmap_pte_range(pmd_t *pmd, unsigned long addr,
75484 pte = pte_alloc_kernel(pmd, addr);
75485 if (!pte)
75486 return -ENOMEM;
75487+
75488+ pax_open_kernel();
75489 do {
75490 struct page *page = pages[*nr];
75491
75492- if (WARN_ON(!pte_none(*pte)))
75493- return -EBUSY;
75494- if (WARN_ON(!page))
75495- return -ENOMEM;
75496+#if defined(CONFIG_MODULES) && defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
75497+ if (pgprot_val(prot) & _PAGE_NX)
75498+#endif
75499+
75500+ if (WARN_ON(!pte_none(*pte))) {
75501+ ret = -EBUSY;
75502+ goto out;
75503+ }
75504+ if (WARN_ON(!page)) {
75505+ ret = -ENOMEM;
75506+ goto out;
75507+ }
75508 set_pte_at(&init_mm, addr, pte, mk_pte(page, prot));
75509 (*nr)++;
75510 } while (pte++, addr += PAGE_SIZE, addr != end);
75511- return 0;
75512+ ret = 0;
75513+out:
75514+ pax_close_kernel();
75515+ return ret;
75516 }
75517
75518 static int vmap_pmd_range(pud_t *pud, unsigned long addr,
75519@@ -119,7 +144,7 @@ static int vmap_pmd_range(pud_t *pud, unsigned long addr,
75520 pmd_t *pmd;
75521 unsigned long next;
75522
75523- pmd = pmd_alloc(&init_mm, pud, addr);
75524+ pmd = pmd_alloc_kernel(&init_mm, pud, addr);
75525 if (!pmd)
75526 return -ENOMEM;
75527 do {
75528@@ -136,7 +161,7 @@ static int vmap_pud_range(pgd_t *pgd, unsigned long addr,
75529 pud_t *pud;
75530 unsigned long next;
75531
75532- pud = pud_alloc(&init_mm, pgd, addr);
75533+ pud = pud_alloc_kernel(&init_mm, pgd, addr);
75534 if (!pud)
75535 return -ENOMEM;
75536 do {
75537@@ -191,11 +216,20 @@ int is_vmalloc_or_module_addr(const void *x)
75538 * and fall back on vmalloc() if that fails. Others
75539 * just put it in the vmalloc space.
75540 */
75541-#if defined(CONFIG_MODULES) && defined(MODULES_VADDR)
75542+#ifdef CONFIG_MODULES
75543+#ifdef MODULES_VADDR
75544 unsigned long addr = (unsigned long)x;
75545 if (addr >= MODULES_VADDR && addr < MODULES_END)
75546 return 1;
75547 #endif
75548+
75549+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
75550+ if (x >= (const void *)MODULES_EXEC_VADDR && x < (const void *)MODULES_EXEC_END)
75551+ return 1;
75552+#endif
75553+
75554+#endif
75555+
75556 return is_vmalloc_addr(x);
75557 }
75558
75559@@ -216,8 +250,14 @@ struct page *vmalloc_to_page(const void *vmalloc_addr)
75560
75561 if (!pgd_none(*pgd)) {
75562 pud_t *pud = pud_offset(pgd, addr);
75563+#ifdef CONFIG_X86
75564+ if (!pud_large(*pud))
75565+#endif
75566 if (!pud_none(*pud)) {
75567 pmd_t *pmd = pmd_offset(pud, addr);
75568+#ifdef CONFIG_X86
75569+ if (!pmd_large(*pmd))
75570+#endif
75571 if (!pmd_none(*pmd)) {
75572 pte_t *ptep, pte;
75573
75574@@ -329,7 +369,7 @@ static void purge_vmap_area_lazy(void);
75575 * Allocate a region of KVA of the specified size and alignment, within the
75576 * vstart and vend.
75577 */
75578-static struct vmap_area *alloc_vmap_area(unsigned long size,
75579+static __size_overflow(1) struct vmap_area *alloc_vmap_area(unsigned long size,
75580 unsigned long align,
75581 unsigned long vstart, unsigned long vend,
75582 int node, gfp_t gfp_mask)
75583@@ -1328,6 +1368,16 @@ static struct vm_struct *__get_vm_area_node(unsigned long size,
75584 struct vm_struct *area;
75585
75586 BUG_ON(in_interrupt());
75587+
75588+#if defined(CONFIG_MODULES) && defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
75589+ if (flags & VM_KERNEXEC) {
75590+ if (start != VMALLOC_START || end != VMALLOC_END)
75591+ return NULL;
75592+ start = (unsigned long)MODULES_EXEC_VADDR;
75593+ end = (unsigned long)MODULES_EXEC_END;
75594+ }
75595+#endif
75596+
75597 if (flags & VM_IOREMAP) {
75598 int bit = fls(size);
75599
75600@@ -1568,6 +1618,11 @@ void *vmap(struct page **pages, unsigned int count,
75601 if (count > totalram_pages)
75602 return NULL;
75603
75604+#if defined(CONFIG_MODULES) && defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
75605+ if (!(pgprot_val(prot) & _PAGE_NX))
75606+ flags |= VM_KERNEXEC;
75607+#endif
75608+
75609 area = get_vm_area_caller((count << PAGE_SHIFT), flags,
75610 __builtin_return_address(0));
75611 if (!area)
75612@@ -1669,6 +1724,13 @@ void *__vmalloc_node_range(unsigned long size, unsigned long align,
75613 if (!size || (size >> PAGE_SHIFT) > totalram_pages)
75614 goto fail;
75615
75616+#if defined(CONFIG_MODULES) && defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
75617+ if (!(pgprot_val(prot) & _PAGE_NX))
75618+ area = __get_vm_area_node(size, align, VM_ALLOC | VM_UNLIST | VM_KERNEXEC,
75619+ VMALLOC_START, VMALLOC_END, node, gfp_mask, caller);
75620+ else
75621+#endif
75622+
75623 area = __get_vm_area_node(size, align, VM_ALLOC | VM_UNLIST,
75624 start, end, node, gfp_mask, caller);
75625 if (!area)
75626@@ -1842,10 +1904,9 @@ EXPORT_SYMBOL(vzalloc_node);
75627 * For tight control over page level allocator and protection flags
75628 * use __vmalloc() instead.
75629 */
75630-
75631 void *vmalloc_exec(unsigned long size)
75632 {
75633- return __vmalloc_node(size, 1, GFP_KERNEL | __GFP_HIGHMEM, PAGE_KERNEL_EXEC,
75634+ return __vmalloc_node(size, 1, GFP_KERNEL | __GFP_HIGHMEM | __GFP_ZERO, PAGE_KERNEL_EXEC,
75635 -1, __builtin_return_address(0));
75636 }
75637
75638@@ -2136,6 +2197,8 @@ int remap_vmalloc_range(struct vm_area_struct *vma, void *addr,
75639 unsigned long uaddr = vma->vm_start;
75640 unsigned long usize = vma->vm_end - vma->vm_start;
75641
75642+ BUG_ON(vma->vm_mirror);
75643+
75644 if ((PAGE_SIZE-1) & (unsigned long)addr)
75645 return -EINVAL;
75646
75647@@ -2572,7 +2635,7 @@ static int s_show(struct seq_file *m, void *p)
75648 {
75649 struct vm_struct *v = p;
75650
75651- seq_printf(m, "0x%p-0x%p %7ld",
75652+ seq_printf(m, "0x%pK-0x%pK %7ld",
75653 v->addr, v->addr + v->size, v->size);
75654
75655 if (v->caller)
75656diff --git a/mm/vmstat.c b/mm/vmstat.c
75657index df7a674..8b4a4f3 100644
75658--- a/mm/vmstat.c
75659+++ b/mm/vmstat.c
75660@@ -78,7 +78,7 @@ void vm_events_fold_cpu(int cpu)
75661 *
75662 * vm_stat contains the global counters
75663 */
75664-atomic_long_t vm_stat[NR_VM_ZONE_STAT_ITEMS] __cacheline_aligned_in_smp;
75665+atomic_long_unchecked_t vm_stat[NR_VM_ZONE_STAT_ITEMS] __cacheline_aligned_in_smp;
75666 EXPORT_SYMBOL(vm_stat);
75667
75668 #ifdef CONFIG_SMP
75669@@ -454,7 +454,7 @@ void refresh_cpu_vm_stats(int cpu)
75670 v = p->vm_stat_diff[i];
75671 p->vm_stat_diff[i] = 0;
75672 local_irq_restore(flags);
75673- atomic_long_add(v, &zone->vm_stat[i]);
75674+ atomic_long_add_unchecked(v, &zone->vm_stat[i]);
75675 global_diff[i] += v;
75676 #ifdef CONFIG_NUMA
75677 /* 3 seconds idle till flush */
75678@@ -492,7 +492,7 @@ void refresh_cpu_vm_stats(int cpu)
75679
75680 for (i = 0; i < NR_VM_ZONE_STAT_ITEMS; i++)
75681 if (global_diff[i])
75682- atomic_long_add(global_diff[i], &vm_stat[i]);
75683+ atomic_long_add_unchecked(global_diff[i], &vm_stat[i]);
75684 }
75685
75686 #endif
75687@@ -1212,10 +1212,20 @@ static int __init setup_vmstat(void)
75688 start_cpu_timer(cpu);
75689 #endif
75690 #ifdef CONFIG_PROC_FS
75691- proc_create("buddyinfo", S_IRUGO, NULL, &fragmentation_file_operations);
75692- proc_create("pagetypeinfo", S_IRUGO, NULL, &pagetypeinfo_file_ops);
75693- proc_create("vmstat", S_IRUGO, NULL, &proc_vmstat_file_operations);
75694- proc_create("zoneinfo", S_IRUGO, NULL, &proc_zoneinfo_file_operations);
75695+ {
75696+ mode_t gr_mode = S_IRUGO;
75697+#ifdef CONFIG_GRKERNSEC_PROC_ADD
75698+ gr_mode = S_IRUSR;
75699+#endif
75700+ proc_create("buddyinfo", gr_mode, NULL, &fragmentation_file_operations);
75701+ proc_create("pagetypeinfo", gr_mode, NULL, &pagetypeinfo_file_ops);
75702+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
75703+ proc_create("vmstat", gr_mode | S_IRGRP, NULL, &proc_vmstat_file_operations);
75704+#else
75705+ proc_create("vmstat", gr_mode, NULL, &proc_vmstat_file_operations);
75706+#endif
75707+ proc_create("zoneinfo", gr_mode, NULL, &proc_zoneinfo_file_operations);
75708+ }
75709 #endif
75710 return 0;
75711 }
75712diff --git a/net/8021q/vlan.c b/net/8021q/vlan.c
75713index 9096bcb..43ed7bb 100644
75714--- a/net/8021q/vlan.c
75715+++ b/net/8021q/vlan.c
75716@@ -557,8 +557,7 @@ static int vlan_ioctl_handler(struct net *net, void __user *arg)
75717 err = -EPERM;
75718 if (!capable(CAP_NET_ADMIN))
75719 break;
75720- if ((args.u.name_type >= 0) &&
75721- (args.u.name_type < VLAN_NAME_TYPE_HIGHEST)) {
75722+ if (args.u.name_type < VLAN_NAME_TYPE_HIGHEST) {
75723 struct vlan_net *vn;
75724
75725 vn = net_generic(net, vlan_net_id);
75726diff --git a/net/9p/trans_fd.c b/net/9p/trans_fd.c
75727index 6449bae..8c1f454 100644
75728--- a/net/9p/trans_fd.c
75729+++ b/net/9p/trans_fd.c
75730@@ -425,7 +425,7 @@ static int p9_fd_write(struct p9_client *client, void *v, int len)
75731 oldfs = get_fs();
75732 set_fs(get_ds());
75733 /* The cast to a user pointer is valid due to the set_fs() */
75734- ret = vfs_write(ts->wr, (__force void __user *)v, len, &ts->wr->f_pos);
75735+ ret = vfs_write(ts->wr, (void __force_user *)v, len, &ts->wr->f_pos);
75736 set_fs(oldfs);
75737
75738 if (ret <= 0 && ret != -ERESTARTSYS && ret != -EAGAIN)
75739diff --git a/net/atm/atm_misc.c b/net/atm/atm_misc.c
75740index 876fbe8..8bbea9f 100644
75741--- a/net/atm/atm_misc.c
75742+++ b/net/atm/atm_misc.c
75743@@ -17,7 +17,7 @@ int atm_charge(struct atm_vcc *vcc, int truesize)
75744 if (atomic_read(&sk_atm(vcc)->sk_rmem_alloc) <= sk_atm(vcc)->sk_rcvbuf)
75745 return 1;
75746 atm_return(vcc, truesize);
75747- atomic_inc(&vcc->stats->rx_drop);
75748+ atomic_inc_unchecked(&vcc->stats->rx_drop);
75749 return 0;
75750 }
75751 EXPORT_SYMBOL(atm_charge);
75752@@ -39,7 +39,7 @@ struct sk_buff *atm_alloc_charge(struct atm_vcc *vcc, int pdu_size,
75753 }
75754 }
75755 atm_return(vcc, guess);
75756- atomic_inc(&vcc->stats->rx_drop);
75757+ atomic_inc_unchecked(&vcc->stats->rx_drop);
75758 return NULL;
75759 }
75760 EXPORT_SYMBOL(atm_alloc_charge);
75761@@ -86,7 +86,7 @@ EXPORT_SYMBOL(atm_pcr_goal);
75762
75763 void sonet_copy_stats(struct k_sonet_stats *from, struct sonet_stats *to)
75764 {
75765-#define __HANDLE_ITEM(i) to->i = atomic_read(&from->i)
75766+#define __HANDLE_ITEM(i) to->i = atomic_read_unchecked(&from->i)
75767 __SONET_ITEMS
75768 #undef __HANDLE_ITEM
75769 }
75770@@ -94,7 +94,7 @@ EXPORT_SYMBOL(sonet_copy_stats);
75771
75772 void sonet_subtract_stats(struct k_sonet_stats *from, struct sonet_stats *to)
75773 {
75774-#define __HANDLE_ITEM(i) atomic_sub(to->i, &from->i)
75775+#define __HANDLE_ITEM(i) atomic_sub_unchecked(to->i,&from->i)
75776 __SONET_ITEMS
75777 #undef __HANDLE_ITEM
75778 }
75779diff --git a/net/atm/lec.h b/net/atm/lec.h
75780index a86aff9..3a0d6f6 100644
75781--- a/net/atm/lec.h
75782+++ b/net/atm/lec.h
75783@@ -48,7 +48,7 @@ struct lane2_ops {
75784 const u8 *tlvs, u32 sizeoftlvs);
75785 void (*associate_indicator) (struct net_device *dev, const u8 *mac_addr,
75786 const u8 *tlvs, u32 sizeoftlvs);
75787-};
75788+} __no_const;
75789
75790 /*
75791 * ATM LAN Emulation supports both LLC & Dix Ethernet EtherType
75792diff --git a/net/atm/mpc.h b/net/atm/mpc.h
75793index 0919a88..a23d54e 100644
75794--- a/net/atm/mpc.h
75795+++ b/net/atm/mpc.h
75796@@ -33,7 +33,7 @@ struct mpoa_client {
75797 struct mpc_parameters parameters; /* parameters for this client */
75798
75799 const struct net_device_ops *old_ops;
75800- struct net_device_ops new_ops;
75801+ net_device_ops_no_const new_ops;
75802 };
75803
75804
75805diff --git a/net/atm/proc.c b/net/atm/proc.c
75806index 0d020de..011c7bb 100644
75807--- a/net/atm/proc.c
75808+++ b/net/atm/proc.c
75809@@ -45,9 +45,9 @@ static void add_stats(struct seq_file *seq, const char *aal,
75810 const struct k_atm_aal_stats *stats)
75811 {
75812 seq_printf(seq, "%s ( %d %d %d %d %d )", aal,
75813- atomic_read(&stats->tx), atomic_read(&stats->tx_err),
75814- atomic_read(&stats->rx), atomic_read(&stats->rx_err),
75815- atomic_read(&stats->rx_drop));
75816+ atomic_read_unchecked(&stats->tx),atomic_read_unchecked(&stats->tx_err),
75817+ atomic_read_unchecked(&stats->rx),atomic_read_unchecked(&stats->rx_err),
75818+ atomic_read_unchecked(&stats->rx_drop));
75819 }
75820
75821 static void atm_dev_info(struct seq_file *seq, const struct atm_dev *dev)
75822diff --git a/net/atm/resources.c b/net/atm/resources.c
75823index 23f45ce..c748f1a 100644
75824--- a/net/atm/resources.c
75825+++ b/net/atm/resources.c
75826@@ -160,7 +160,7 @@ EXPORT_SYMBOL(atm_dev_deregister);
75827 static void copy_aal_stats(struct k_atm_aal_stats *from,
75828 struct atm_aal_stats *to)
75829 {
75830-#define __HANDLE_ITEM(i) to->i = atomic_read(&from->i)
75831+#define __HANDLE_ITEM(i) to->i = atomic_read_unchecked(&from->i)
75832 __AAL_STAT_ITEMS
75833 #undef __HANDLE_ITEM
75834 }
75835@@ -168,7 +168,7 @@ static void copy_aal_stats(struct k_atm_aal_stats *from,
75836 static void subtract_aal_stats(struct k_atm_aal_stats *from,
75837 struct atm_aal_stats *to)
75838 {
75839-#define __HANDLE_ITEM(i) atomic_sub(to->i, &from->i)
75840+#define __HANDLE_ITEM(i) atomic_sub_unchecked(to->i, &from->i)
75841 __AAL_STAT_ITEMS
75842 #undef __HANDLE_ITEM
75843 }
75844diff --git a/net/batman-adv/bat_iv_ogm.c b/net/batman-adv/bat_iv_ogm.c
75845index 469daab..9fc7f8d 100644
75846--- a/net/batman-adv/bat_iv_ogm.c
75847+++ b/net/batman-adv/bat_iv_ogm.c
75848@@ -62,7 +62,7 @@ static int batadv_iv_ogm_iface_enable(struct batadv_hard_iface *hard_iface)
75849
75850 /* randomize initial seqno to avoid collision */
75851 get_random_bytes(&random_seqno, sizeof(random_seqno));
75852- atomic_set(&hard_iface->seqno, random_seqno);
75853+ atomic_set_unchecked(&hard_iface->seqno, random_seqno);
75854
75855 hard_iface->packet_len = BATADV_OGM_HLEN;
75856 hard_iface->packet_buff = kmalloc(hard_iface->packet_len, GFP_ATOMIC);
75857@@ -191,7 +191,7 @@ static void batadv_iv_ogm_send_to_if(struct batadv_forw_packet *forw_packet,
75858 "Sending own" :
75859 "Forwarding"));
75860 batadv_dbg(BATADV_DBG_BATMAN, bat_priv,
75861- "%s %spacket (originator %pM, seqno %u, TQ %d, TTL %d, IDF %s, ttvn %d) on interface %s [%pM]\n",
75862+ "%s %spacket (originator %pM, s_uncheckedeqno %u, TQ %d, TTL %d, IDF %s, ttvn %d) on interface %s [%pM]\n",
75863 fwd_str, (packet_num > 0 ? "aggregated " : ""),
75864 batadv_ogm_packet->orig,
75865 ntohl(batadv_ogm_packet->seqno),
75866@@ -600,8 +600,8 @@ static void batadv_iv_ogm_schedule(struct batadv_hard_iface *hard_iface)
75867
75868 /* change sequence number to network order */
75869 batadv_ogm_packet->seqno =
75870- htonl((uint32_t)atomic_read(&hard_iface->seqno));
75871- atomic_inc(&hard_iface->seqno);
75872+ htonl((uint32_t)atomic_read_unchecked(&hard_iface->seqno));
75873+ atomic_inc_unchecked(&hard_iface->seqno);
75874
75875 batadv_ogm_packet->ttvn = atomic_read(&bat_priv->ttvn);
75876 batadv_ogm_packet->tt_crc = htons(bat_priv->tt_crc);
75877@@ -1001,7 +1001,7 @@ static void batadv_iv_ogm_process(const struct ethhdr *ethhdr,
75878 return;
75879
75880 /* could be changed by schedule_own_packet() */
75881- if_incoming_seqno = atomic_read(&if_incoming->seqno);
75882+ if_incoming_seqno = atomic_read_unchecked(&if_incoming->seqno);
75883
75884 if (batadv_ogm_packet->flags & BATADV_DIRECTLINK)
75885 has_directlink_flag = 1;
75886diff --git a/net/batman-adv/hard-interface.c b/net/batman-adv/hard-interface.c
75887index 282bf6e..4b2603d 100644
75888--- a/net/batman-adv/hard-interface.c
75889+++ b/net/batman-adv/hard-interface.c
75890@@ -320,7 +320,7 @@ int batadv_hardif_enable_interface(struct batadv_hard_iface *hard_iface,
75891 hard_iface->batman_adv_ptype.dev = hard_iface->net_dev;
75892 dev_add_pack(&hard_iface->batman_adv_ptype);
75893
75894- atomic_set(&hard_iface->frag_seqno, 1);
75895+ atomic_set_unchecked(&hard_iface->frag_seqno, 1);
75896 batadv_info(hard_iface->soft_iface, "Adding interface: %s\n",
75897 hard_iface->net_dev->name);
75898
75899@@ -443,7 +443,7 @@ batadv_hardif_add_interface(struct net_device *net_dev)
75900 /* This can't be called via a bat_priv callback because
75901 * we have no bat_priv yet.
75902 */
75903- atomic_set(&hard_iface->seqno, 1);
75904+ atomic_set_unchecked(&hard_iface->seqno, 1);
75905 hard_iface->packet_buff = NULL;
75906
75907 return hard_iface;
75908diff --git a/net/batman-adv/soft-interface.c b/net/batman-adv/soft-interface.c
75909index 21c5357..768be1a 100644
75910--- a/net/batman-adv/soft-interface.c
75911+++ b/net/batman-adv/soft-interface.c
75912@@ -227,7 +227,7 @@ static int batadv_interface_tx(struct sk_buff *skb,
75913
75914 /* set broadcast sequence number */
75915 bcast_packet->seqno =
75916- htonl(atomic_inc_return(&bat_priv->bcast_seqno));
75917+ htonl(atomic_inc_return_unchecked(&bat_priv->bcast_seqno));
75918
75919 batadv_add_bcast_packet_to_list(bat_priv, skb, 1);
75920
75921@@ -407,7 +407,7 @@ struct net_device *batadv_softif_create(const char *name)
75922 atomic_set(&bat_priv->batman_queue_left, BATADV_BATMAN_QUEUE_LEN);
75923
75924 atomic_set(&bat_priv->mesh_state, BATADV_MESH_INACTIVE);
75925- atomic_set(&bat_priv->bcast_seqno, 1);
75926+ atomic_set_unchecked(&bat_priv->bcast_seqno, 1);
75927 atomic_set(&bat_priv->ttvn, 0);
75928 atomic_set(&bat_priv->tt_local_changes, 0);
75929 atomic_set(&bat_priv->tt_ogm_append_cnt, 0);
75930diff --git a/net/batman-adv/types.h b/net/batman-adv/types.h
75931index 12635fd..d99d837 100644
75932--- a/net/batman-adv/types.h
75933+++ b/net/batman-adv/types.h
75934@@ -33,8 +33,8 @@ struct batadv_hard_iface {
75935 int16_t if_num;
75936 char if_status;
75937 struct net_device *net_dev;
75938- atomic_t seqno;
75939- atomic_t frag_seqno;
75940+ atomic_unchecked_t seqno;
75941+ atomic_unchecked_t frag_seqno;
75942 unsigned char *packet_buff;
75943 int packet_len;
75944 struct kobject *hardif_obj;
75945@@ -176,7 +176,7 @@ struct batadv_priv {
75946 atomic_t orig_interval; /* uint */
75947 atomic_t hop_penalty; /* uint */
75948 atomic_t log_level; /* uint */
75949- atomic_t bcast_seqno;
75950+ atomic_unchecked_t bcast_seqno;
75951 atomic_t bcast_queue_left;
75952 atomic_t batman_queue_left;
75953 atomic_t ttvn; /* translation table version number */
75954diff --git a/net/batman-adv/unicast.c b/net/batman-adv/unicast.c
75955index 0016464..0ef3e53 100644
75956--- a/net/batman-adv/unicast.c
75957+++ b/net/batman-adv/unicast.c
75958@@ -269,7 +269,7 @@ int batadv_frag_send_skb(struct sk_buff *skb, struct batadv_priv *bat_priv,
75959 frag1->flags = BATADV_UNI_FRAG_HEAD | large_tail;
75960 frag2->flags = large_tail;
75961
75962- seqno = atomic_add_return(2, &hard_iface->frag_seqno);
75963+ seqno = atomic_add_return_unchecked(2, &hard_iface->frag_seqno);
75964 frag1->seqno = htons(seqno - 1);
75965 frag2->seqno = htons(seqno);
75966
75967diff --git a/net/bluetooth/hci_sock.c b/net/bluetooth/hci_sock.c
75968index d5ace1e..231c4bf 100644
75969--- a/net/bluetooth/hci_sock.c
75970+++ b/net/bluetooth/hci_sock.c
75971@@ -934,7 +934,7 @@ static int hci_sock_setsockopt(struct socket *sock, int level, int optname,
75972 uf.event_mask[1] = *((u32 *) f->event_mask + 1);
75973 }
75974
75975- len = min_t(unsigned int, len, sizeof(uf));
75976+ len = min((size_t)len, sizeof(uf));
75977 if (copy_from_user(&uf, optval, len)) {
75978 err = -EFAULT;
75979 break;
75980diff --git a/net/bluetooth/l2cap_core.c b/net/bluetooth/l2cap_core.c
75981index 38c00f1..e9d566e 100644
75982--- a/net/bluetooth/l2cap_core.c
75983+++ b/net/bluetooth/l2cap_core.c
75984@@ -3165,8 +3165,10 @@ static int l2cap_parse_conf_rsp(struct l2cap_chan *chan, void *rsp, int len, voi
75985 break;
75986
75987 case L2CAP_CONF_RFC:
75988- if (olen == sizeof(rfc))
75989- memcpy(&rfc, (void *)val, olen);
75990+ if (olen != sizeof(rfc))
75991+ break;
75992+
75993+ memcpy(&rfc, (void *)val, olen);
75994
75995 if (test_bit(CONF_STATE2_DEVICE, &chan->conf_state) &&
75996 rfc.mode != chan->mode)
75997diff --git a/net/bluetooth/l2cap_sock.c b/net/bluetooth/l2cap_sock.c
75998index 34bbe1c..451c19b 100644
75999--- a/net/bluetooth/l2cap_sock.c
76000+++ b/net/bluetooth/l2cap_sock.c
76001@@ -467,7 +467,8 @@ static int l2cap_sock_setsockopt_old(struct socket *sock, int optname, char __us
76002 struct sock *sk = sock->sk;
76003 struct l2cap_chan *chan = l2cap_pi(sk)->chan;
76004 struct l2cap_options opts;
76005- int len, err = 0;
76006+ int err = 0;
76007+ size_t len = optlen;
76008 u32 opt;
76009
76010 BT_DBG("sk %p", sk);
76011@@ -489,7 +490,7 @@ static int l2cap_sock_setsockopt_old(struct socket *sock, int optname, char __us
76012 opts.max_tx = chan->max_tx;
76013 opts.txwin_size = chan->tx_win;
76014
76015- len = min_t(unsigned int, sizeof(opts), optlen);
76016+ len = min(sizeof(opts), len);
76017 if (copy_from_user((char *) &opts, optval, len)) {
76018 err = -EFAULT;
76019 break;
76020@@ -567,7 +568,8 @@ static int l2cap_sock_setsockopt(struct socket *sock, int level, int optname, ch
76021 struct bt_security sec;
76022 struct bt_power pwr;
76023 struct l2cap_conn *conn;
76024- int len, err = 0;
76025+ int err = 0;
76026+ size_t len = optlen;
76027 u32 opt;
76028
76029 BT_DBG("sk %p", sk);
76030@@ -590,7 +592,7 @@ static int l2cap_sock_setsockopt(struct socket *sock, int level, int optname, ch
76031
76032 sec.level = BT_SECURITY_LOW;
76033
76034- len = min_t(unsigned int, sizeof(sec), optlen);
76035+ len = min(sizeof(sec), len);
76036 if (copy_from_user((char *) &sec, optval, len)) {
76037 err = -EFAULT;
76038 break;
76039@@ -687,7 +689,7 @@ static int l2cap_sock_setsockopt(struct socket *sock, int level, int optname, ch
76040
76041 pwr.force_active = BT_POWER_FORCE_ACTIVE_ON;
76042
76043- len = min_t(unsigned int, sizeof(pwr), optlen);
76044+ len = min(sizeof(pwr), len);
76045 if (copy_from_user((char *) &pwr, optval, len)) {
76046 err = -EFAULT;
76047 break;
76048diff --git a/net/bluetooth/rfcomm/sock.c b/net/bluetooth/rfcomm/sock.c
76049index 1a17850..65a3129 100644
76050--- a/net/bluetooth/rfcomm/sock.c
76051+++ b/net/bluetooth/rfcomm/sock.c
76052@@ -667,7 +667,7 @@ static int rfcomm_sock_setsockopt(struct socket *sock, int level, int optname, c
76053 struct sock *sk = sock->sk;
76054 struct bt_security sec;
76055 int err = 0;
76056- size_t len;
76057+ size_t len = optlen;
76058 u32 opt;
76059
76060 BT_DBG("sk %p", sk);
76061@@ -689,7 +689,7 @@ static int rfcomm_sock_setsockopt(struct socket *sock, int level, int optname, c
76062
76063 sec.level = BT_SECURITY_LOW;
76064
76065- len = min_t(unsigned int, sizeof(sec), optlen);
76066+ len = min(sizeof(sec), len);
76067 if (copy_from_user((char *) &sec, optval, len)) {
76068 err = -EFAULT;
76069 break;
76070diff --git a/net/bluetooth/rfcomm/tty.c b/net/bluetooth/rfcomm/tty.c
76071index 56f1823..da44330 100644
76072--- a/net/bluetooth/rfcomm/tty.c
76073+++ b/net/bluetooth/rfcomm/tty.c
76074@@ -309,7 +309,7 @@ static void rfcomm_dev_del(struct rfcomm_dev *dev)
76075 BUG_ON(test_and_set_bit(RFCOMM_TTY_RELEASED, &dev->flags));
76076
76077 spin_lock_irqsave(&dev->port.lock, flags);
76078- if (dev->port.count > 0) {
76079+ if (atomic_read(&dev->port.count) > 0) {
76080 spin_unlock_irqrestore(&dev->port.lock, flags);
76081 return;
76082 }
76083@@ -664,10 +664,10 @@ static int rfcomm_tty_open(struct tty_struct *tty, struct file *filp)
76084 return -ENODEV;
76085
76086 BT_DBG("dev %p dst %s channel %d opened %d", dev, batostr(&dev->dst),
76087- dev->channel, dev->port.count);
76088+ dev->channel, atomic_read(&dev->port.count));
76089
76090 spin_lock_irqsave(&dev->port.lock, flags);
76091- if (++dev->port.count > 1) {
76092+ if (atomic_inc_return(&dev->port.count) > 1) {
76093 spin_unlock_irqrestore(&dev->port.lock, flags);
76094 return 0;
76095 }
76096@@ -732,10 +732,10 @@ static void rfcomm_tty_close(struct tty_struct *tty, struct file *filp)
76097 return;
76098
76099 BT_DBG("tty %p dev %p dlc %p opened %d", tty, dev, dev->dlc,
76100- dev->port.count);
76101+ atomic_read(&dev->port.count));
76102
76103 spin_lock_irqsave(&dev->port.lock, flags);
76104- if (!--dev->port.count) {
76105+ if (!atomic_dec_return(&dev->port.count)) {
76106 spin_unlock_irqrestore(&dev->port.lock, flags);
76107 if (dev->tty_dev->parent)
76108 device_move(dev->tty_dev, NULL, DPM_ORDER_DEV_LAST);
76109diff --git a/net/bridge/netfilter/ebtables.c b/net/bridge/netfilter/ebtables.c
76110index 5fe2ff3..121d696 100644
76111--- a/net/bridge/netfilter/ebtables.c
76112+++ b/net/bridge/netfilter/ebtables.c
76113@@ -1523,7 +1523,7 @@ static int do_ebt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
76114 tmp.valid_hooks = t->table->valid_hooks;
76115 }
76116 mutex_unlock(&ebt_mutex);
76117- if (copy_to_user(user, &tmp, *len) != 0){
76118+ if (*len > sizeof(tmp) || copy_to_user(user, &tmp, *len) != 0){
76119 BUGPRINT("c2u Didn't work\n");
76120 ret = -EFAULT;
76121 break;
76122@@ -2327,7 +2327,7 @@ static int compat_do_ebt_get_ctl(struct sock *sk, int cmd,
76123 goto out;
76124 tmp.valid_hooks = t->valid_hooks;
76125
76126- if (copy_to_user(user, &tmp, *len) != 0) {
76127+ if (*len > sizeof(tmp) || copy_to_user(user, &tmp, *len) != 0) {
76128 ret = -EFAULT;
76129 break;
76130 }
76131@@ -2338,7 +2338,7 @@ static int compat_do_ebt_get_ctl(struct sock *sk, int cmd,
76132 tmp.entries_size = t->table->entries_size;
76133 tmp.valid_hooks = t->table->valid_hooks;
76134
76135- if (copy_to_user(user, &tmp, *len) != 0) {
76136+ if (*len > sizeof(tmp) || copy_to_user(user, &tmp, *len) != 0) {
76137 ret = -EFAULT;
76138 break;
76139 }
76140diff --git a/net/caif/cfctrl.c b/net/caif/cfctrl.c
76141index 44f270f..1f5602d 100644
76142--- a/net/caif/cfctrl.c
76143+++ b/net/caif/cfctrl.c
76144@@ -10,6 +10,7 @@
76145 #include <linux/spinlock.h>
76146 #include <linux/slab.h>
76147 #include <linux/pkt_sched.h>
76148+#include <linux/sched.h>
76149 #include <net/caif/caif_layer.h>
76150 #include <net/caif/cfpkt.h>
76151 #include <net/caif/cfctrl.h>
76152@@ -43,8 +44,8 @@ struct cflayer *cfctrl_create(void)
76153 memset(&dev_info, 0, sizeof(dev_info));
76154 dev_info.id = 0xff;
76155 cfsrvl_init(&this->serv, 0, &dev_info, false);
76156- atomic_set(&this->req_seq_no, 1);
76157- atomic_set(&this->rsp_seq_no, 1);
76158+ atomic_set_unchecked(&this->req_seq_no, 1);
76159+ atomic_set_unchecked(&this->rsp_seq_no, 1);
76160 this->serv.layer.receive = cfctrl_recv;
76161 sprintf(this->serv.layer.name, "ctrl");
76162 this->serv.layer.ctrlcmd = cfctrl_ctrlcmd;
76163@@ -130,8 +131,8 @@ static void cfctrl_insert_req(struct cfctrl *ctrl,
76164 struct cfctrl_request_info *req)
76165 {
76166 spin_lock_bh(&ctrl->info_list_lock);
76167- atomic_inc(&ctrl->req_seq_no);
76168- req->sequence_no = atomic_read(&ctrl->req_seq_no);
76169+ atomic_inc_unchecked(&ctrl->req_seq_no);
76170+ req->sequence_no = atomic_read_unchecked(&ctrl->req_seq_no);
76171 list_add_tail(&req->list, &ctrl->list);
76172 spin_unlock_bh(&ctrl->info_list_lock);
76173 }
76174@@ -149,7 +150,7 @@ static struct cfctrl_request_info *cfctrl_remove_req(struct cfctrl *ctrl,
76175 if (p != first)
76176 pr_warn("Requests are not received in order\n");
76177
76178- atomic_set(&ctrl->rsp_seq_no,
76179+ atomic_set_unchecked(&ctrl->rsp_seq_no,
76180 p->sequence_no);
76181 list_del(&p->list);
76182 goto out;
76183diff --git a/net/can/gw.c b/net/can/gw.c
76184index b54d5e6..91c3b25 100644
76185--- a/net/can/gw.c
76186+++ b/net/can/gw.c
76187@@ -96,7 +96,7 @@ struct cf_mod {
76188 struct {
76189 void (*xor)(struct can_frame *cf, struct cgw_csum_xor *xor);
76190 void (*crc8)(struct can_frame *cf, struct cgw_csum_crc8 *crc8);
76191- } csumfunc;
76192+ } __no_const csumfunc;
76193 };
76194
76195
76196diff --git a/net/compat.c b/net/compat.c
76197index 74ed1d7..3695bd9 100644
76198--- a/net/compat.c
76199+++ b/net/compat.c
76200@@ -71,9 +71,9 @@ int get_compat_msghdr(struct msghdr *kmsg, struct compat_msghdr __user *umsg)
76201 __get_user(kmsg->msg_controllen, &umsg->msg_controllen) ||
76202 __get_user(kmsg->msg_flags, &umsg->msg_flags))
76203 return -EFAULT;
76204- kmsg->msg_name = compat_ptr(tmp1);
76205- kmsg->msg_iov = compat_ptr(tmp2);
76206- kmsg->msg_control = compat_ptr(tmp3);
76207+ kmsg->msg_name = (void __force_kernel *)compat_ptr(tmp1);
76208+ kmsg->msg_iov = (void __force_kernel *)compat_ptr(tmp2);
76209+ kmsg->msg_control = (void __force_kernel *)compat_ptr(tmp3);
76210 return 0;
76211 }
76212
76213@@ -85,7 +85,7 @@ int verify_compat_iovec(struct msghdr *kern_msg, struct iovec *kern_iov,
76214
76215 if (kern_msg->msg_namelen) {
76216 if (mode == VERIFY_READ) {
76217- int err = move_addr_to_kernel(kern_msg->msg_name,
76218+ int err = move_addr_to_kernel((void __force_user *)kern_msg->msg_name,
76219 kern_msg->msg_namelen,
76220 kern_address);
76221 if (err < 0)
76222@@ -96,7 +96,7 @@ int verify_compat_iovec(struct msghdr *kern_msg, struct iovec *kern_iov,
76223 kern_msg->msg_name = NULL;
76224
76225 tot_len = iov_from_user_compat_to_kern(kern_iov,
76226- (struct compat_iovec __user *)kern_msg->msg_iov,
76227+ (struct compat_iovec __force_user *)kern_msg->msg_iov,
76228 kern_msg->msg_iovlen);
76229 if (tot_len >= 0)
76230 kern_msg->msg_iov = kern_iov;
76231@@ -116,20 +116,20 @@ int verify_compat_iovec(struct msghdr *kern_msg, struct iovec *kern_iov,
76232
76233 #define CMSG_COMPAT_FIRSTHDR(msg) \
76234 (((msg)->msg_controllen) >= sizeof(struct compat_cmsghdr) ? \
76235- (struct compat_cmsghdr __user *)((msg)->msg_control) : \
76236+ (struct compat_cmsghdr __force_user *)((msg)->msg_control) : \
76237 (struct compat_cmsghdr __user *)NULL)
76238
76239 #define CMSG_COMPAT_OK(ucmlen, ucmsg, mhdr) \
76240 ((ucmlen) >= sizeof(struct compat_cmsghdr) && \
76241 (ucmlen) <= (unsigned long) \
76242 ((mhdr)->msg_controllen - \
76243- ((char *)(ucmsg) - (char *)(mhdr)->msg_control)))
76244+ ((char __force_kernel *)(ucmsg) - (char *)(mhdr)->msg_control)))
76245
76246 static inline struct compat_cmsghdr __user *cmsg_compat_nxthdr(struct msghdr *msg,
76247 struct compat_cmsghdr __user *cmsg, int cmsg_len)
76248 {
76249 char __user *ptr = (char __user *)cmsg + CMSG_COMPAT_ALIGN(cmsg_len);
76250- if ((unsigned long)(ptr + 1 - (char __user *)msg->msg_control) >
76251+ if ((unsigned long)(ptr + 1 - (char __force_user *)msg->msg_control) >
76252 msg->msg_controllen)
76253 return NULL;
76254 return (struct compat_cmsghdr __user *)ptr;
76255@@ -219,7 +219,7 @@ Efault:
76256
76257 int put_cmsg_compat(struct msghdr *kmsg, int level, int type, int len, void *data)
76258 {
76259- struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __user *) kmsg->msg_control;
76260+ struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __force_user *) kmsg->msg_control;
76261 struct compat_cmsghdr cmhdr;
76262 struct compat_timeval ctv;
76263 struct compat_timespec cts[3];
76264@@ -275,7 +275,7 @@ int put_cmsg_compat(struct msghdr *kmsg, int level, int type, int len, void *dat
76265
76266 void scm_detach_fds_compat(struct msghdr *kmsg, struct scm_cookie *scm)
76267 {
76268- struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __user *) kmsg->msg_control;
76269+ struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __force_user *) kmsg->msg_control;
76270 int fdmax = (kmsg->msg_controllen - sizeof(struct compat_cmsghdr)) / sizeof(int);
76271 int fdnum = scm->fp->count;
76272 struct file **fp = scm->fp->fp;
76273@@ -364,7 +364,7 @@ static int do_set_sock_timeout(struct socket *sock, int level,
76274 return -EFAULT;
76275 old_fs = get_fs();
76276 set_fs(KERNEL_DS);
76277- err = sock_setsockopt(sock, level, optname, (char *)&ktime, sizeof(ktime));
76278+ err = sock_setsockopt(sock, level, optname, (char __force_user *)&ktime, sizeof(ktime));
76279 set_fs(old_fs);
76280
76281 return err;
76282@@ -425,7 +425,7 @@ static int do_get_sock_timeout(struct socket *sock, int level, int optname,
76283 len = sizeof(ktime);
76284 old_fs = get_fs();
76285 set_fs(KERNEL_DS);
76286- err = sock_getsockopt(sock, level, optname, (char *) &ktime, &len);
76287+ err = sock_getsockopt(sock, level, optname, (char __force_user *) &ktime, (int __force_user *)&len);
76288 set_fs(old_fs);
76289
76290 if (!err) {
76291@@ -568,7 +568,7 @@ int compat_mc_setsockopt(struct sock *sock, int level, int optname,
76292 case MCAST_JOIN_GROUP:
76293 case MCAST_LEAVE_GROUP:
76294 {
76295- struct compat_group_req __user *gr32 = (void *)optval;
76296+ struct compat_group_req __user *gr32 = (void __user *)optval;
76297 struct group_req __user *kgr =
76298 compat_alloc_user_space(sizeof(struct group_req));
76299 u32 interface;
76300@@ -589,7 +589,7 @@ int compat_mc_setsockopt(struct sock *sock, int level, int optname,
76301 case MCAST_BLOCK_SOURCE:
76302 case MCAST_UNBLOCK_SOURCE:
76303 {
76304- struct compat_group_source_req __user *gsr32 = (void *)optval;
76305+ struct compat_group_source_req __user *gsr32 = (void __user *)optval;
76306 struct group_source_req __user *kgsr = compat_alloc_user_space(
76307 sizeof(struct group_source_req));
76308 u32 interface;
76309@@ -610,7 +610,7 @@ int compat_mc_setsockopt(struct sock *sock, int level, int optname,
76310 }
76311 case MCAST_MSFILTER:
76312 {
76313- struct compat_group_filter __user *gf32 = (void *)optval;
76314+ struct compat_group_filter __user *gf32 = (void __user *)optval;
76315 struct group_filter __user *kgf;
76316 u32 interface, fmode, numsrc;
76317
76318@@ -648,7 +648,7 @@ int compat_mc_getsockopt(struct sock *sock, int level, int optname,
76319 char __user *optval, int __user *optlen,
76320 int (*getsockopt)(struct sock *, int, int, char __user *, int __user *))
76321 {
76322- struct compat_group_filter __user *gf32 = (void *)optval;
76323+ struct compat_group_filter __user *gf32 = (void __user *)optval;
76324 struct group_filter __user *kgf;
76325 int __user *koptlen;
76326 u32 interface, fmode, numsrc;
76327@@ -797,7 +797,7 @@ asmlinkage long compat_sys_socketcall(int call, u32 __user *args)
76328
76329 if (call < SYS_SOCKET || call > SYS_SENDMMSG)
76330 return -EINVAL;
76331- if (copy_from_user(a, args, nas[call]))
76332+ if (nas[call] > sizeof a || copy_from_user(a, args, nas[call]))
76333 return -EFAULT;
76334 a0 = a[0];
76335 a1 = a[1];
76336diff --git a/net/core/datagram.c b/net/core/datagram.c
76337index 0337e2b..47914a0 100644
76338--- a/net/core/datagram.c
76339+++ b/net/core/datagram.c
76340@@ -289,7 +289,7 @@ int skb_kill_datagram(struct sock *sk, struct sk_buff *skb, unsigned int flags)
76341 }
76342
76343 kfree_skb(skb);
76344- atomic_inc(&sk->sk_drops);
76345+ atomic_inc_unchecked(&sk->sk_drops);
76346 sk_mem_reclaim_partial(sk);
76347
76348 return err;
76349diff --git a/net/core/dev.c b/net/core/dev.c
76350index 2fb9f59..d9a07df 100644
76351--- a/net/core/dev.c
76352+++ b/net/core/dev.c
76353@@ -1138,9 +1138,13 @@ void dev_load(struct net *net, const char *name)
76354 if (no_module && capable(CAP_NET_ADMIN))
76355 no_module = request_module("netdev-%s", name);
76356 if (no_module && capable(CAP_SYS_MODULE)) {
76357+#ifdef CONFIG_GRKERNSEC_MODHARDEN
76358+ ___request_module(true, "grsec_modharden_netdev", "%s", name);
76359+#else
76360 if (!request_module("%s", name))
76361 pr_warn("Loading kernel module for a network device with CAP_SYS_MODULE (deprecated). Use CAP_NET_ADMIN and alias netdev-%s instead.\n",
76362 name);
76363+#endif
76364 }
76365 }
76366 EXPORT_SYMBOL(dev_load);
76367@@ -1605,7 +1609,7 @@ int dev_forward_skb(struct net_device *dev, struct sk_buff *skb)
76368 {
76369 if (skb_shinfo(skb)->tx_flags & SKBTX_DEV_ZEROCOPY) {
76370 if (skb_copy_ubufs(skb, GFP_ATOMIC)) {
76371- atomic_long_inc(&dev->rx_dropped);
76372+ atomic_long_inc_unchecked(&dev->rx_dropped);
76373 kfree_skb(skb);
76374 return NET_RX_DROP;
76375 }
76376@@ -1615,7 +1619,7 @@ int dev_forward_skb(struct net_device *dev, struct sk_buff *skb)
76377 nf_reset(skb);
76378
76379 if (unlikely(!is_skb_forwardable(dev, skb))) {
76380- atomic_long_inc(&dev->rx_dropped);
76381+ atomic_long_inc_unchecked(&dev->rx_dropped);
76382 kfree_skb(skb);
76383 return NET_RX_DROP;
76384 }
76385@@ -2071,7 +2075,7 @@ static int illegal_highdma(struct net_device *dev, struct sk_buff *skb)
76386
76387 struct dev_gso_cb {
76388 void (*destructor)(struct sk_buff *skb);
76389-};
76390+} __no_const;
76391
76392 #define DEV_GSO_CB(skb) ((struct dev_gso_cb *)(skb)->cb)
76393
76394@@ -2928,7 +2932,7 @@ enqueue:
76395
76396 local_irq_restore(flags);
76397
76398- atomic_long_inc(&skb->dev->rx_dropped);
76399+ atomic_long_inc_unchecked(&skb->dev->rx_dropped);
76400 kfree_skb(skb);
76401 return NET_RX_DROP;
76402 }
76403@@ -3000,7 +3004,7 @@ int netif_rx_ni(struct sk_buff *skb)
76404 }
76405 EXPORT_SYMBOL(netif_rx_ni);
76406
76407-static void net_tx_action(struct softirq_action *h)
76408+static void net_tx_action(void)
76409 {
76410 struct softnet_data *sd = &__get_cpu_var(softnet_data);
76411
76412@@ -3331,7 +3335,7 @@ ncls:
76413 ret = pt_prev->func(skb, skb->dev, pt_prev, orig_dev);
76414 } else {
76415 drop:
76416- atomic_long_inc(&skb->dev->rx_dropped);
76417+ atomic_long_inc_unchecked(&skb->dev->rx_dropped);
76418 kfree_skb(skb);
76419 /* Jamal, now you will not able to escape explaining
76420 * me how you were going to use this. :-)
76421@@ -3898,7 +3902,7 @@ void netif_napi_del(struct napi_struct *napi)
76422 }
76423 EXPORT_SYMBOL(netif_napi_del);
76424
76425-static void net_rx_action(struct softirq_action *h)
76426+static void net_rx_action(void)
76427 {
76428 struct softnet_data *sd = &__get_cpu_var(softnet_data);
76429 unsigned long time_limit = jiffies + 2;
76430@@ -4368,8 +4372,13 @@ static int ptype_seq_show(struct seq_file *seq, void *v)
76431 else
76432 seq_printf(seq, "%04x", ntohs(pt->type));
76433
76434+#ifdef CONFIG_GRKERNSEC_HIDESYM
76435+ seq_printf(seq, " %-8s %p\n",
76436+ pt->dev ? pt->dev->name : "", NULL);
76437+#else
76438 seq_printf(seq, " %-8s %pF\n",
76439 pt->dev ? pt->dev->name : "", pt->func);
76440+#endif
76441 }
76442
76443 return 0;
76444@@ -5922,7 +5931,7 @@ struct rtnl_link_stats64 *dev_get_stats(struct net_device *dev,
76445 } else {
76446 netdev_stats_to_stats64(storage, &dev->stats);
76447 }
76448- storage->rx_dropped += atomic_long_read(&dev->rx_dropped);
76449+ storage->rx_dropped += atomic_long_read_unchecked(&dev->rx_dropped);
76450 return storage;
76451 }
76452 EXPORT_SYMBOL(dev_get_stats);
76453diff --git a/net/core/flow.c b/net/core/flow.c
76454index e318c7e..168b1d0 100644
76455--- a/net/core/flow.c
76456+++ b/net/core/flow.c
76457@@ -61,7 +61,7 @@ struct flow_cache {
76458 struct timer_list rnd_timer;
76459 };
76460
76461-atomic_t flow_cache_genid = ATOMIC_INIT(0);
76462+atomic_unchecked_t flow_cache_genid = ATOMIC_INIT(0);
76463 EXPORT_SYMBOL(flow_cache_genid);
76464 static struct flow_cache flow_cache_global;
76465 static struct kmem_cache *flow_cachep __read_mostly;
76466@@ -86,7 +86,7 @@ static void flow_cache_new_hashrnd(unsigned long arg)
76467
76468 static int flow_entry_valid(struct flow_cache_entry *fle)
76469 {
76470- if (atomic_read(&flow_cache_genid) != fle->genid)
76471+ if (atomic_read_unchecked(&flow_cache_genid) != fle->genid)
76472 return 0;
76473 if (fle->object && !fle->object->ops->check(fle->object))
76474 return 0;
76475@@ -259,7 +259,7 @@ flow_cache_lookup(struct net *net, const struct flowi *key, u16 family, u8 dir,
76476 hlist_add_head(&fle->u.hlist, &fcp->hash_table[hash]);
76477 fcp->hash_count++;
76478 }
76479- } else if (likely(fle->genid == atomic_read(&flow_cache_genid))) {
76480+ } else if (likely(fle->genid == atomic_read_unchecked(&flow_cache_genid))) {
76481 flo = fle->object;
76482 if (!flo)
76483 goto ret_object;
76484@@ -280,7 +280,7 @@ nocache:
76485 }
76486 flo = resolver(net, key, family, dir, flo, ctx);
76487 if (fle) {
76488- fle->genid = atomic_read(&flow_cache_genid);
76489+ fle->genid = atomic_read_unchecked(&flow_cache_genid);
76490 if (!IS_ERR(flo))
76491 fle->object = flo;
76492 else
76493diff --git a/net/core/iovec.c b/net/core/iovec.c
76494index 7e7aeb0..2a998cb 100644
76495--- a/net/core/iovec.c
76496+++ b/net/core/iovec.c
76497@@ -42,7 +42,7 @@ int verify_iovec(struct msghdr *m, struct iovec *iov, struct sockaddr_storage *a
76498 if (m->msg_namelen) {
76499 if (mode == VERIFY_READ) {
76500 void __user *namep;
76501- namep = (void __user __force *) m->msg_name;
76502+ namep = (void __force_user *) m->msg_name;
76503 err = move_addr_to_kernel(namep, m->msg_namelen,
76504 address);
76505 if (err < 0)
76506@@ -54,7 +54,7 @@ int verify_iovec(struct msghdr *m, struct iovec *iov, struct sockaddr_storage *a
76507 }
76508
76509 size = m->msg_iovlen * sizeof(struct iovec);
76510- if (copy_from_user(iov, (void __user __force *) m->msg_iov, size))
76511+ if (copy_from_user(iov, (void __force_user *) m->msg_iov, size))
76512 return -EFAULT;
76513
76514 m->msg_iov = iov;
76515diff --git a/net/core/rtnetlink.c b/net/core/rtnetlink.c
76516index 2c5a0a0..a45f90c 100644
76517--- a/net/core/rtnetlink.c
76518+++ b/net/core/rtnetlink.c
76519@@ -58,7 +58,7 @@ struct rtnl_link {
76520 rtnl_doit_func doit;
76521 rtnl_dumpit_func dumpit;
76522 rtnl_calcit_func calcit;
76523-};
76524+} __no_const;
76525
76526 static DEFINE_MUTEX(rtnl_mutex);
76527
76528diff --git a/net/core/scm.c b/net/core/scm.c
76529index 040cebe..5b1e312 100644
76530--- a/net/core/scm.c
76531+++ b/net/core/scm.c
76532@@ -203,7 +203,7 @@ EXPORT_SYMBOL(__scm_send);
76533 int put_cmsg(struct msghdr * msg, int level, int type, int len, void *data)
76534 {
76535 struct cmsghdr __user *cm
76536- = (__force struct cmsghdr __user *)msg->msg_control;
76537+ = (struct cmsghdr __force_user *)msg->msg_control;
76538 struct cmsghdr cmhdr;
76539 int cmlen = CMSG_LEN(len);
76540 int err;
76541@@ -226,7 +226,7 @@ int put_cmsg(struct msghdr * msg, int level, int type, int len, void *data)
76542 err = -EFAULT;
76543 if (copy_to_user(cm, &cmhdr, sizeof cmhdr))
76544 goto out;
76545- if (copy_to_user(CMSG_DATA(cm), data, cmlen - sizeof(struct cmsghdr)))
76546+ if (copy_to_user((void __force_user *)CMSG_DATA((void __force_kernel *)cm), data, cmlen - sizeof(struct cmsghdr)))
76547 goto out;
76548 cmlen = CMSG_SPACE(len);
76549 if (msg->msg_controllen < cmlen)
76550@@ -242,7 +242,7 @@ EXPORT_SYMBOL(put_cmsg);
76551 void scm_detach_fds(struct msghdr *msg, struct scm_cookie *scm)
76552 {
76553 struct cmsghdr __user *cm
76554- = (__force struct cmsghdr __user*)msg->msg_control;
76555+ = (struct cmsghdr __force_user *)msg->msg_control;
76556
76557 int fdmax = 0;
76558 int fdnum = scm->fp->count;
76559@@ -262,7 +262,7 @@ void scm_detach_fds(struct msghdr *msg, struct scm_cookie *scm)
76560 if (fdnum < fdmax)
76561 fdmax = fdnum;
76562
76563- for (i=0, cmfptr=(__force int __user *)CMSG_DATA(cm); i<fdmax;
76564+ for (i=0, cmfptr=(int __force_user *)CMSG_DATA((void __force_kernel *)cm); i<fdmax;
76565 i++, cmfptr++)
76566 {
76567 struct socket *sock;
76568diff --git a/net/core/sock.c b/net/core/sock.c
76569index a6000fb..d4aee72 100644
76570--- a/net/core/sock.c
76571+++ b/net/core/sock.c
76572@@ -399,7 +399,7 @@ int sock_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
76573 struct sk_buff_head *list = &sk->sk_receive_queue;
76574
76575 if (atomic_read(&sk->sk_rmem_alloc) >= sk->sk_rcvbuf) {
76576- atomic_inc(&sk->sk_drops);
76577+ atomic_inc_unchecked(&sk->sk_drops);
76578 trace_sock_rcvqueue_full(sk, skb);
76579 return -ENOMEM;
76580 }
76581@@ -409,7 +409,7 @@ int sock_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
76582 return err;
76583
76584 if (!sk_rmem_schedule(sk, skb, skb->truesize)) {
76585- atomic_inc(&sk->sk_drops);
76586+ atomic_inc_unchecked(&sk->sk_drops);
76587 return -ENOBUFS;
76588 }
76589
76590@@ -429,7 +429,7 @@ int sock_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
76591 skb_dst_force(skb);
76592
76593 spin_lock_irqsave(&list->lock, flags);
76594- skb->dropcount = atomic_read(&sk->sk_drops);
76595+ skb->dropcount = atomic_read_unchecked(&sk->sk_drops);
76596 __skb_queue_tail(list, skb);
76597 spin_unlock_irqrestore(&list->lock, flags);
76598
76599@@ -449,7 +449,7 @@ int sk_receive_skb(struct sock *sk, struct sk_buff *skb, const int nested)
76600 skb->dev = NULL;
76601
76602 if (sk_rcvqueues_full(sk, skb, sk->sk_rcvbuf)) {
76603- atomic_inc(&sk->sk_drops);
76604+ atomic_inc_unchecked(&sk->sk_drops);
76605 goto discard_and_relse;
76606 }
76607 if (nested)
76608@@ -467,7 +467,7 @@ int sk_receive_skb(struct sock *sk, struct sk_buff *skb, const int nested)
76609 mutex_release(&sk->sk_lock.dep_map, 1, _RET_IP_);
76610 } else if (sk_add_backlog(sk, skb, sk->sk_rcvbuf)) {
76611 bh_unlock_sock(sk);
76612- atomic_inc(&sk->sk_drops);
76613+ atomic_inc_unchecked(&sk->sk_drops);
76614 goto discard_and_relse;
76615 }
76616
76617@@ -886,12 +886,12 @@ int sock_getsockopt(struct socket *sock, int level, int optname,
76618 struct timeval tm;
76619 } v;
76620
76621- int lv = sizeof(int);
76622- int len;
76623+ unsigned int lv = sizeof(int);
76624+ unsigned int len;
76625
76626 if (get_user(len, optlen))
76627 return -EFAULT;
76628- if (len < 0)
76629+ if (len > INT_MAX)
76630 return -EINVAL;
76631
76632 memset(&v, 0, sizeof(v));
76633@@ -1039,11 +1039,11 @@ int sock_getsockopt(struct socket *sock, int level, int optname,
76634
76635 case SO_PEERNAME:
76636 {
76637- char address[128];
76638+ char address[_K_SS_MAXSIZE];
76639
76640 if (sock->ops->getname(sock, (struct sockaddr *)address, &lv, 2))
76641 return -ENOTCONN;
76642- if (lv < len)
76643+ if (lv < len || sizeof address < len)
76644 return -EINVAL;
76645 if (copy_to_user(optval, address, len))
76646 return -EFAULT;
76647@@ -1091,7 +1091,7 @@ int sock_getsockopt(struct socket *sock, int level, int optname,
76648
76649 if (len > lv)
76650 len = lv;
76651- if (copy_to_user(optval, &v, len))
76652+ if (len > sizeof(v) || copy_to_user(optval, &v, len))
76653 return -EFAULT;
76654 lenout:
76655 if (put_user(len, optlen))
76656@@ -2193,7 +2193,7 @@ void sock_init_data(struct socket *sock, struct sock *sk)
76657 */
76658 smp_wmb();
76659 atomic_set(&sk->sk_refcnt, 1);
76660- atomic_set(&sk->sk_drops, 0);
76661+ atomic_set_unchecked(&sk->sk_drops, 0);
76662 }
76663 EXPORT_SYMBOL(sock_init_data);
76664
76665diff --git a/net/core/sock_diag.c b/net/core/sock_diag.c
76666index 9d8755e..26de8bc 100644
76667--- a/net/core/sock_diag.c
76668+++ b/net/core/sock_diag.c
76669@@ -15,20 +15,27 @@ static DEFINE_MUTEX(sock_diag_table_mutex);
76670
76671 int sock_diag_check_cookie(void *sk, __u32 *cookie)
76672 {
76673+#ifndef CONFIG_GRKERNSEC_HIDESYM
76674 if ((cookie[0] != INET_DIAG_NOCOOKIE ||
76675 cookie[1] != INET_DIAG_NOCOOKIE) &&
76676 ((u32)(unsigned long)sk != cookie[0] ||
76677 (u32)((((unsigned long)sk) >> 31) >> 1) != cookie[1]))
76678 return -ESTALE;
76679 else
76680+#endif
76681 return 0;
76682 }
76683 EXPORT_SYMBOL_GPL(sock_diag_check_cookie);
76684
76685 void sock_diag_save_cookie(void *sk, __u32 *cookie)
76686 {
76687+#ifdef CONFIG_GRKERNSEC_HIDESYM
76688+ cookie[0] = 0;
76689+ cookie[1] = 0;
76690+#else
76691 cookie[0] = (u32)(unsigned long)sk;
76692 cookie[1] = (u32)(((unsigned long)sk >> 31) >> 1);
76693+#endif
76694 }
76695 EXPORT_SYMBOL_GPL(sock_diag_save_cookie);
76696
76697diff --git a/net/decnet/sysctl_net_decnet.c b/net/decnet/sysctl_net_decnet.c
76698index a55eecc..dd8428c 100644
76699--- a/net/decnet/sysctl_net_decnet.c
76700+++ b/net/decnet/sysctl_net_decnet.c
76701@@ -174,7 +174,7 @@ static int dn_node_address_handler(ctl_table *table, int write,
76702
76703 if (len > *lenp) len = *lenp;
76704
76705- if (copy_to_user(buffer, addr, len))
76706+ if (len > sizeof addr || copy_to_user(buffer, addr, len))
76707 return -EFAULT;
76708
76709 *lenp = len;
76710@@ -237,7 +237,7 @@ static int dn_def_dev_handler(ctl_table *table, int write,
76711
76712 if (len > *lenp) len = *lenp;
76713
76714- if (copy_to_user(buffer, devname, len))
76715+ if (len > sizeof devname || copy_to_user(buffer, devname, len))
76716 return -EFAULT;
76717
76718 *lenp = len;
76719diff --git a/net/ipv4/fib_frontend.c b/net/ipv4/fib_frontend.c
76720index f444ac7..b7bdda9 100644
76721--- a/net/ipv4/fib_frontend.c
76722+++ b/net/ipv4/fib_frontend.c
76723@@ -1020,12 +1020,12 @@ static int fib_inetaddr_event(struct notifier_block *this, unsigned long event,
76724 #ifdef CONFIG_IP_ROUTE_MULTIPATH
76725 fib_sync_up(dev);
76726 #endif
76727- atomic_inc(&net->ipv4.dev_addr_genid);
76728+ atomic_inc_unchecked(&net->ipv4.dev_addr_genid);
76729 rt_cache_flush(dev_net(dev));
76730 break;
76731 case NETDEV_DOWN:
76732 fib_del_ifaddr(ifa, NULL);
76733- atomic_inc(&net->ipv4.dev_addr_genid);
76734+ atomic_inc_unchecked(&net->ipv4.dev_addr_genid);
76735 if (ifa->ifa_dev->ifa_list == NULL) {
76736 /* Last address was deleted from this interface.
76737 * Disable IP.
76738@@ -1062,7 +1062,7 @@ static int fib_netdev_event(struct notifier_block *this, unsigned long event, vo
76739 #ifdef CONFIG_IP_ROUTE_MULTIPATH
76740 fib_sync_up(dev);
76741 #endif
76742- atomic_inc(&net->ipv4.dev_addr_genid);
76743+ atomic_inc_unchecked(&net->ipv4.dev_addr_genid);
76744 rt_cache_flush(dev_net(dev));
76745 break;
76746 case NETDEV_DOWN:
76747diff --git a/net/ipv4/fib_semantics.c b/net/ipv4/fib_semantics.c
76748index 9633661..4e0bc08 100644
76749--- a/net/ipv4/fib_semantics.c
76750+++ b/net/ipv4/fib_semantics.c
76751@@ -767,7 +767,7 @@ __be32 fib_info_update_nh_saddr(struct net *net, struct fib_nh *nh)
76752 nh->nh_saddr = inet_select_addr(nh->nh_dev,
76753 nh->nh_gw,
76754 nh->nh_parent->fib_scope);
76755- nh->nh_saddr_genid = atomic_read(&net->ipv4.dev_addr_genid);
76756+ nh->nh_saddr_genid = atomic_read_unchecked(&net->ipv4.dev_addr_genid);
76757
76758 return nh->nh_saddr;
76759 }
76760diff --git a/net/ipv4/inet_hashtables.c b/net/ipv4/inet_hashtables.c
76761index 7880af9..70f92a3 100644
76762--- a/net/ipv4/inet_hashtables.c
76763+++ b/net/ipv4/inet_hashtables.c
76764@@ -18,12 +18,15 @@
76765 #include <linux/sched.h>
76766 #include <linux/slab.h>
76767 #include <linux/wait.h>
76768+#include <linux/security.h>
76769
76770 #include <net/inet_connection_sock.h>
76771 #include <net/inet_hashtables.h>
76772 #include <net/secure_seq.h>
76773 #include <net/ip.h>
76774
76775+extern void gr_update_task_in_ip_table(struct task_struct *task, const struct inet_sock *inet);
76776+
76777 /*
76778 * Allocate and initialize a new local port bind bucket.
76779 * The bindhash mutex for snum's hash chain must be held here.
76780@@ -530,6 +533,8 @@ ok:
76781 twrefcnt += inet_twsk_bind_unhash(tw, hinfo);
76782 spin_unlock(&head->lock);
76783
76784+ gr_update_task_in_ip_table(current, inet_sk(sk));
76785+
76786 if (tw) {
76787 inet_twsk_deschedule(tw, death_row);
76788 while (twrefcnt) {
76789diff --git a/net/ipv4/inetpeer.c b/net/ipv4/inetpeer.c
76790index c7527f6..d8bba61 100644
76791--- a/net/ipv4/inetpeer.c
76792+++ b/net/ipv4/inetpeer.c
76793@@ -503,8 +503,8 @@ relookup:
76794 if (p) {
76795 p->daddr = *daddr;
76796 atomic_set(&p->refcnt, 1);
76797- atomic_set(&p->rid, 0);
76798- atomic_set(&p->ip_id_count,
76799+ atomic_set_unchecked(&p->rid, 0);
76800+ atomic_set_unchecked(&p->ip_id_count,
76801 (daddr->family == AF_INET) ?
76802 secure_ip_id(daddr->addr.a4) :
76803 secure_ipv6_id(daddr->addr.a6));
76804diff --git a/net/ipv4/ip_fragment.c b/net/ipv4/ip_fragment.c
76805index 8d07c97..d0812ef 100644
76806--- a/net/ipv4/ip_fragment.c
76807+++ b/net/ipv4/ip_fragment.c
76808@@ -322,7 +322,7 @@ static inline int ip_frag_too_far(struct ipq *qp)
76809 return 0;
76810
76811 start = qp->rid;
76812- end = atomic_inc_return(&peer->rid);
76813+ end = atomic_inc_return_unchecked(&peer->rid);
76814 qp->rid = end;
76815
76816 rc = qp->q.fragments && (end - start) > max;
76817diff --git a/net/ipv4/ip_sockglue.c b/net/ipv4/ip_sockglue.c
76818index 5eea4a8..49819c2 100644
76819--- a/net/ipv4/ip_sockglue.c
76820+++ b/net/ipv4/ip_sockglue.c
76821@@ -1142,7 +1142,8 @@ static int do_ip_getsockopt(struct sock *sk, int level, int optname,
76822 len = min_t(unsigned int, len, opt->optlen);
76823 if (put_user(len, optlen))
76824 return -EFAULT;
76825- if (copy_to_user(optval, opt->__data, len))
76826+ if ((len > (sizeof(optbuf) - sizeof(struct ip_options))) ||
76827+ copy_to_user(optval, opt->__data, len))
76828 return -EFAULT;
76829 return 0;
76830 }
76831@@ -1273,7 +1274,7 @@ static int do_ip_getsockopt(struct sock *sk, int level, int optname,
76832 if (sk->sk_type != SOCK_STREAM)
76833 return -ENOPROTOOPT;
76834
76835- msg.msg_control = optval;
76836+ msg.msg_control = (void __force_kernel *)optval;
76837 msg.msg_controllen = len;
76838 msg.msg_flags = flags;
76839
76840diff --git a/net/ipv4/ipconfig.c b/net/ipv4/ipconfig.c
76841index 67e8a6b..386764d 100644
76842--- a/net/ipv4/ipconfig.c
76843+++ b/net/ipv4/ipconfig.c
76844@@ -321,7 +321,7 @@ static int __init ic_devinet_ioctl(unsigned int cmd, struct ifreq *arg)
76845
76846 mm_segment_t oldfs = get_fs();
76847 set_fs(get_ds());
76848- res = devinet_ioctl(&init_net, cmd, (struct ifreq __user *) arg);
76849+ res = devinet_ioctl(&init_net, cmd, (struct ifreq __force_user *) arg);
76850 set_fs(oldfs);
76851 return res;
76852 }
76853@@ -332,7 +332,7 @@ static int __init ic_dev_ioctl(unsigned int cmd, struct ifreq *arg)
76854
76855 mm_segment_t oldfs = get_fs();
76856 set_fs(get_ds());
76857- res = dev_ioctl(&init_net, cmd, (struct ifreq __user *) arg);
76858+ res = dev_ioctl(&init_net, cmd, (struct ifreq __force_user *) arg);
76859 set_fs(oldfs);
76860 return res;
76861 }
76862@@ -343,7 +343,7 @@ static int __init ic_route_ioctl(unsigned int cmd, struct rtentry *arg)
76863
76864 mm_segment_t oldfs = get_fs();
76865 set_fs(get_ds());
76866- res = ip_rt_ioctl(&init_net, cmd, (void __user *) arg);
76867+ res = ip_rt_ioctl(&init_net, cmd, (void __force_user *) arg);
76868 set_fs(oldfs);
76869 return res;
76870 }
76871diff --git a/net/ipv4/netfilter/arp_tables.c b/net/ipv4/netfilter/arp_tables.c
76872index 97e61ea..cac1bbb 100644
76873--- a/net/ipv4/netfilter/arp_tables.c
76874+++ b/net/ipv4/netfilter/arp_tables.c
76875@@ -879,14 +879,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 arpt_getinfo)) {
76887- duprintf("length %u != %Zu\n", *len,
76888+ if (len != sizeof(struct arpt_getinfo)) {
76889+ duprintf("length %u != %Zu\n", len,
76890 sizeof(struct arpt_getinfo));
76891 return -EINVAL;
76892 }
76893@@ -923,7 +923,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@@ -1682,7 +1682,7 @@ static int compat_do_arpt_get_ctl(struct sock *sk, int cmd, void __user *user,
76903
76904 switch (cmd) {
76905 case ARPT_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 ARPT_SO_GET_ENTRIES:
76910 ret = compat_get_entries(sock_net(sk), user, len);
76911@@ -1727,7 +1727,7 @@ static int do_arpt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len
76912
76913 switch (cmd) {
76914 case ARPT_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 ARPT_SO_GET_ENTRIES:
76920diff --git a/net/ipv4/netfilter/ip_tables.c b/net/ipv4/netfilter/ip_tables.c
76921index 170b1fd..6105b91 100644
76922--- a/net/ipv4/netfilter/ip_tables.c
76923+++ b/net/ipv4/netfilter/ip_tables.c
76924@@ -1068,14 +1068,14 @@ static int compat_table_info(const struct xt_table_info *info,
76925 #endif
76926
76927 static int get_info(struct net *net, void __user *user,
76928- const int *len, int compat)
76929+ int len, int compat)
76930 {
76931 char name[XT_TABLE_MAXNAMELEN];
76932 struct xt_table *t;
76933 int ret;
76934
76935- if (*len != sizeof(struct ipt_getinfo)) {
76936- duprintf("length %u != %zu\n", *len,
76937+ if (len != sizeof(struct ipt_getinfo)) {
76938+ duprintf("length %u != %zu\n", len,
76939 sizeof(struct ipt_getinfo));
76940 return -EINVAL;
76941 }
76942@@ -1112,7 +1112,7 @@ static int get_info(struct net *net, void __user *user,
76943 info.size = private->size;
76944 strcpy(info.name, name);
76945
76946- if (copy_to_user(user, &info, *len) != 0)
76947+ if (copy_to_user(user, &info, len) != 0)
76948 ret = -EFAULT;
76949 else
76950 ret = 0;
76951@@ -1966,7 +1966,7 @@ compat_do_ipt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
76952
76953 switch (cmd) {
76954 case IPT_SO_GET_INFO:
76955- ret = get_info(sock_net(sk), user, len, 1);
76956+ ret = get_info(sock_net(sk), user, *len, 1);
76957 break;
76958 case IPT_SO_GET_ENTRIES:
76959 ret = compat_get_entries(sock_net(sk), user, len);
76960@@ -2013,7 +2013,7 @@ do_ipt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
76961
76962 switch (cmd) {
76963 case IPT_SO_GET_INFO:
76964- ret = get_info(sock_net(sk), user, len, 0);
76965+ ret = get_info(sock_net(sk), user, *len, 0);
76966 break;
76967
76968 case IPT_SO_GET_ENTRIES:
76969diff --git a/net/ipv4/ping.c b/net/ipv4/ping.c
76970index 6232d47..6b88607 100644
76971--- a/net/ipv4/ping.c
76972+++ b/net/ipv4/ping.c
76973@@ -847,7 +847,7 @@ static void ping_format_sock(struct sock *sp, struct seq_file *f,
76974 sk_rmem_alloc_get(sp),
76975 0, 0L, 0, sock_i_uid(sp), 0, sock_i_ino(sp),
76976 atomic_read(&sp->sk_refcnt), sp,
76977- atomic_read(&sp->sk_drops), len);
76978+ atomic_read_unchecked(&sp->sk_drops), len);
76979 }
76980
76981 static int ping_seq_show(struct seq_file *seq, void *v)
76982diff --git a/net/ipv4/raw.c b/net/ipv4/raw.c
76983index d23c657..cb69cc2 100644
76984--- a/net/ipv4/raw.c
76985+++ b/net/ipv4/raw.c
76986@@ -311,7 +311,7 @@ static int raw_rcv_skb(struct sock *sk, struct sk_buff *skb)
76987 int raw_rcv(struct sock *sk, struct sk_buff *skb)
76988 {
76989 if (!xfrm4_policy_check(sk, XFRM_POLICY_IN, skb)) {
76990- atomic_inc(&sk->sk_drops);
76991+ atomic_inc_unchecked(&sk->sk_drops);
76992 kfree_skb(skb);
76993 return NET_RX_DROP;
76994 }
76995@@ -747,16 +747,20 @@ static int raw_init(struct sock *sk)
76996
76997 static int raw_seticmpfilter(struct sock *sk, char __user *optval, int optlen)
76998 {
76999+ struct icmp_filter filter;
77000+
77001 if (optlen > sizeof(struct icmp_filter))
77002 optlen = sizeof(struct icmp_filter);
77003- if (copy_from_user(&raw_sk(sk)->filter, optval, optlen))
77004+ if (copy_from_user(&filter, optval, optlen))
77005 return -EFAULT;
77006+ raw_sk(sk)->filter = filter;
77007 return 0;
77008 }
77009
77010 static int raw_geticmpfilter(struct sock *sk, char __user *optval, int __user *optlen)
77011 {
77012 int len, ret = -EFAULT;
77013+ struct icmp_filter filter;
77014
77015 if (get_user(len, optlen))
77016 goto out;
77017@@ -766,8 +770,8 @@ static int raw_geticmpfilter(struct sock *sk, char __user *optval, int __user *o
77018 if (len > sizeof(struct icmp_filter))
77019 len = sizeof(struct icmp_filter);
77020 ret = -EFAULT;
77021- if (put_user(len, optlen) ||
77022- copy_to_user(optval, &raw_sk(sk)->filter, len))
77023+ filter = raw_sk(sk)->filter;
77024+ if (put_user(len, optlen) || len > sizeof filter || copy_to_user(optval, &filter, len))
77025 goto out;
77026 ret = 0;
77027 out: return ret;
77028@@ -995,7 +999,13 @@ static void raw_sock_seq_show(struct seq_file *seq, struct sock *sp, int i)
77029 sk_wmem_alloc_get(sp),
77030 sk_rmem_alloc_get(sp),
77031 0, 0L, 0, sock_i_uid(sp), 0, sock_i_ino(sp),
77032- atomic_read(&sp->sk_refcnt), sp, atomic_read(&sp->sk_drops));
77033+ atomic_read(&sp->sk_refcnt),
77034+#ifdef CONFIG_GRKERNSEC_HIDESYM
77035+ NULL,
77036+#else
77037+ sp,
77038+#endif
77039+ atomic_read_unchecked(&sp->sk_drops));
77040 }
77041
77042 static int raw_seq_show(struct seq_file *seq, void *v)
77043diff --git a/net/ipv4/route.c b/net/ipv4/route.c
77044index 2a1383c..ff99572 100644
77045--- a/net/ipv4/route.c
77046+++ b/net/ipv4/route.c
77047@@ -2523,7 +2523,7 @@ static __net_initdata struct pernet_operations sysctl_route_ops = {
77048
77049 static __net_init int rt_genid_init(struct net *net)
77050 {
77051- atomic_set(&net->rt_genid, 0);
77052+ atomic_set_unchecked(&net->rt_genid, 0);
77053 get_random_bytes(&net->ipv4.dev_addr_genid,
77054 sizeof(net->ipv4.dev_addr_genid));
77055 return 0;
77056diff --git a/net/ipv4/tcp_input.c b/net/ipv4/tcp_input.c
77057index d377f48..c2211ed 100644
77058--- a/net/ipv4/tcp_input.c
77059+++ b/net/ipv4/tcp_input.c
77060@@ -4728,7 +4728,7 @@ static struct sk_buff *tcp_collapse_one(struct sock *sk, struct sk_buff *skb,
77061 * simplifies code)
77062 */
77063 static void
77064-tcp_collapse(struct sock *sk, struct sk_buff_head *list,
77065+__intentional_overflow(5,6) tcp_collapse(struct sock *sk, struct sk_buff_head *list,
77066 struct sk_buff *head, struct sk_buff *tail,
77067 u32 start, u32 end)
77068 {
77069diff --git a/net/ipv4/tcp_ipv4.c b/net/ipv4/tcp_ipv4.c
77070index db7bfad..bfea796 100644
77071--- a/net/ipv4/tcp_ipv4.c
77072+++ b/net/ipv4/tcp_ipv4.c
77073@@ -90,6 +90,10 @@ int sysctl_tcp_low_latency __read_mostly;
77074 EXPORT_SYMBOL(sysctl_tcp_low_latency);
77075
77076
77077+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
77078+extern int grsec_enable_blackhole;
77079+#endif
77080+
77081 #ifdef CONFIG_TCP_MD5SIG
77082 static int tcp_v4_md5_hash_hdr(char *md5_hash, const struct tcp_md5sig_key *key,
77083 __be32 daddr, __be32 saddr, const struct tcphdr *th);
77084@@ -1664,6 +1668,9 @@ int tcp_v4_do_rcv(struct sock *sk, struct sk_buff *skb)
77085 return 0;
77086
77087 reset:
77088+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
77089+ if (!grsec_enable_blackhole)
77090+#endif
77091 tcp_v4_send_reset(rsk, skb);
77092 discard:
77093 kfree_skb(skb);
77094@@ -1764,12 +1771,19 @@ int tcp_v4_rcv(struct sk_buff *skb)
77095 TCP_SKB_CB(skb)->sacked = 0;
77096
77097 sk = __inet_lookup_skb(&tcp_hashinfo, skb, th->source, th->dest);
77098- if (!sk)
77099+ if (!sk) {
77100+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
77101+ ret = 1;
77102+#endif
77103 goto no_tcp_socket;
77104-
77105+ }
77106 process:
77107- if (sk->sk_state == TCP_TIME_WAIT)
77108+ if (sk->sk_state == TCP_TIME_WAIT) {
77109+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
77110+ ret = 2;
77111+#endif
77112 goto do_time_wait;
77113+ }
77114
77115 if (unlikely(iph->ttl < inet_sk(sk)->min_ttl)) {
77116 NET_INC_STATS_BH(net, LINUX_MIB_TCPMINTTLDROP);
77117@@ -1820,6 +1834,10 @@ no_tcp_socket:
77118 bad_packet:
77119 TCP_INC_STATS_BH(net, TCP_MIB_INERRS);
77120 } else {
77121+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
77122+ if (!grsec_enable_blackhole || (ret == 1 &&
77123+ (skb->dev->flags & IFF_LOOPBACK)))
77124+#endif
77125 tcp_v4_send_reset(NULL, skb);
77126 }
77127
77128@@ -2415,7 +2433,11 @@ static void get_openreq4(const struct sock *sk, const struct request_sock *req,
77129 0, /* non standard timer */
77130 0, /* open_requests have no inode */
77131 atomic_read(&sk->sk_refcnt),
77132+#ifdef CONFIG_GRKERNSEC_HIDESYM
77133+ NULL,
77134+#else
77135 req,
77136+#endif
77137 len);
77138 }
77139
77140@@ -2465,7 +2487,12 @@ static void get_tcp4_sock(struct sock *sk, struct seq_file *f, int i, int *len)
77141 sock_i_uid(sk),
77142 icsk->icsk_probes_out,
77143 sock_i_ino(sk),
77144- atomic_read(&sk->sk_refcnt), sk,
77145+ atomic_read(&sk->sk_refcnt),
77146+#ifdef CONFIG_GRKERNSEC_HIDESYM
77147+ NULL,
77148+#else
77149+ sk,
77150+#endif
77151 jiffies_to_clock_t(icsk->icsk_rto),
77152 jiffies_to_clock_t(icsk->icsk_ack.ato),
77153 (icsk->icsk_ack.quick << 1) | icsk->icsk_ack.pingpong,
77154@@ -2493,7 +2520,13 @@ static void get_timewait4_sock(const struct inet_timewait_sock *tw,
77155 " %02X %08X:%08X %02X:%08lX %08X %5d %8d %d %d %pK%n",
77156 i, src, srcp, dest, destp, tw->tw_substate, 0, 0,
77157 3, jiffies_to_clock_t(ttd), 0, 0, 0, 0,
77158- atomic_read(&tw->tw_refcnt), tw, len);
77159+ atomic_read(&tw->tw_refcnt),
77160+#ifdef CONFIG_GRKERNSEC_HIDESYM
77161+ NULL,
77162+#else
77163+ tw,
77164+#endif
77165+ len);
77166 }
77167
77168 #define TMPSZ 150
77169diff --git a/net/ipv4/tcp_minisocks.c b/net/ipv4/tcp_minisocks.c
77170index 6ff7f10..38de56e 100644
77171--- a/net/ipv4/tcp_minisocks.c
77172+++ b/net/ipv4/tcp_minisocks.c
77173@@ -27,6 +27,10 @@
77174 #include <net/inet_common.h>
77175 #include <net/xfrm.h>
77176
77177+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
77178+extern int grsec_enable_blackhole;
77179+#endif
77180+
77181 int sysctl_tcp_syncookies __read_mostly = 1;
77182 EXPORT_SYMBOL(sysctl_tcp_syncookies);
77183
77184@@ -707,6 +711,10 @@ listen_overflow:
77185
77186 embryonic_reset:
77187 NET_INC_STATS_BH(sock_net(sk), LINUX_MIB_EMBRYONICRSTS);
77188+
77189+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
77190+ if (!grsec_enable_blackhole)
77191+#endif
77192 if (!(flg & TCP_FLAG_RST))
77193 req->rsk_ops->send_reset(sk, skb);
77194
77195diff --git a/net/ipv4/tcp_probe.c b/net/ipv4/tcp_probe.c
77196index 4526fe6..1a34e43 100644
77197--- a/net/ipv4/tcp_probe.c
77198+++ b/net/ipv4/tcp_probe.c
77199@@ -204,7 +204,7 @@ static ssize_t tcpprobe_read(struct file *file, char __user *buf,
77200 if (cnt + width >= len)
77201 break;
77202
77203- if (copy_to_user(buf + cnt, tbuf, width))
77204+ if (width > sizeof tbuf || copy_to_user(buf + cnt, tbuf, width))
77205 return -EFAULT;
77206 cnt += width;
77207 }
77208diff --git a/net/ipv4/tcp_timer.c b/net/ipv4/tcp_timer.c
77209index b774a03..3873efe 100644
77210--- a/net/ipv4/tcp_timer.c
77211+++ b/net/ipv4/tcp_timer.c
77212@@ -22,6 +22,10 @@
77213 #include <linux/gfp.h>
77214 #include <net/tcp.h>
77215
77216+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
77217+extern int grsec_lastack_retries;
77218+#endif
77219+
77220 int sysctl_tcp_syn_retries __read_mostly = TCP_SYN_RETRIES;
77221 int sysctl_tcp_synack_retries __read_mostly = TCP_SYNACK_RETRIES;
77222 int sysctl_tcp_keepalive_time __read_mostly = TCP_KEEPALIVE_TIME;
77223@@ -185,6 +189,13 @@ static int tcp_write_timeout(struct sock *sk)
77224 }
77225 }
77226
77227+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
77228+ if ((sk->sk_state == TCP_LAST_ACK) &&
77229+ (grsec_lastack_retries > 0) &&
77230+ (grsec_lastack_retries < retry_until))
77231+ retry_until = grsec_lastack_retries;
77232+#endif
77233+
77234 if (retransmits_timed_out(sk, retry_until,
77235 syn_set ? 0 : icsk->icsk_user_timeout, syn_set)) {
77236 /* Has it gone just too far? */
77237diff --git a/net/ipv4/udp.c b/net/ipv4/udp.c
77238index 2814f66..fa2b223 100644
77239--- a/net/ipv4/udp.c
77240+++ b/net/ipv4/udp.c
77241@@ -87,6 +87,7 @@
77242 #include <linux/types.h>
77243 #include <linux/fcntl.h>
77244 #include <linux/module.h>
77245+#include <linux/security.h>
77246 #include <linux/socket.h>
77247 #include <linux/sockios.h>
77248 #include <linux/igmp.h>
77249@@ -111,6 +112,10 @@
77250 #include <trace/events/skb.h>
77251 #include "udp_impl.h"
77252
77253+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
77254+extern int grsec_enable_blackhole;
77255+#endif
77256+
77257 struct udp_table udp_table __read_mostly;
77258 EXPORT_SYMBOL(udp_table);
77259
77260@@ -569,6 +574,9 @@ found:
77261 return s;
77262 }
77263
77264+extern int gr_search_udp_recvmsg(struct sock *sk, const struct sk_buff *skb);
77265+extern int gr_search_udp_sendmsg(struct sock *sk, struct sockaddr_in *addr);
77266+
77267 /*
77268 * This routine is called by the ICMP module when it gets some
77269 * sort of error condition. If err < 0 then the socket should
77270@@ -864,9 +872,18 @@ int udp_sendmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg,
77271 dport = usin->sin_port;
77272 if (dport == 0)
77273 return -EINVAL;
77274+
77275+ err = gr_search_udp_sendmsg(sk, usin);
77276+ if (err)
77277+ return err;
77278 } else {
77279 if (sk->sk_state != TCP_ESTABLISHED)
77280 return -EDESTADDRREQ;
77281+
77282+ err = gr_search_udp_sendmsg(sk, NULL);
77283+ if (err)
77284+ return err;
77285+
77286 daddr = inet->inet_daddr;
77287 dport = inet->inet_dport;
77288 /* Open fast path for connected socket.
77289@@ -1108,7 +1125,7 @@ static unsigned int first_packet_length(struct sock *sk)
77290 udp_lib_checksum_complete(skb)) {
77291 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS,
77292 IS_UDPLITE(sk));
77293- atomic_inc(&sk->sk_drops);
77294+ atomic_inc_unchecked(&sk->sk_drops);
77295 __skb_unlink(skb, rcvq);
77296 __skb_queue_tail(&list_kill, skb);
77297 }
77298@@ -1194,6 +1211,10 @@ try_again:
77299 if (!skb)
77300 goto out;
77301
77302+ err = gr_search_udp_recvmsg(sk, skb);
77303+ if (err)
77304+ goto out_free;
77305+
77306 ulen = skb->len - sizeof(struct udphdr);
77307 copied = len;
77308 if (copied > ulen)
77309@@ -1227,7 +1248,7 @@ try_again:
77310 if (unlikely(err)) {
77311 trace_kfree_skb(skb, udp_recvmsg);
77312 if (!peeked) {
77313- atomic_inc(&sk->sk_drops);
77314+ atomic_inc_unchecked(&sk->sk_drops);
77315 UDP_INC_STATS_USER(sock_net(sk),
77316 UDP_MIB_INERRORS, is_udplite);
77317 }
77318@@ -1510,7 +1531,7 @@ int udp_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
77319
77320 drop:
77321 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS, is_udplite);
77322- atomic_inc(&sk->sk_drops);
77323+ atomic_inc_unchecked(&sk->sk_drops);
77324 kfree_skb(skb);
77325 return -1;
77326 }
77327@@ -1529,7 +1550,7 @@ static void flush_stack(struct sock **stack, unsigned int count,
77328 skb1 = (i == final) ? skb : skb_clone(skb, GFP_ATOMIC);
77329
77330 if (!skb1) {
77331- atomic_inc(&sk->sk_drops);
77332+ atomic_inc_unchecked(&sk->sk_drops);
77333 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_RCVBUFERRORS,
77334 IS_UDPLITE(sk));
77335 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS,
77336@@ -1698,6 +1719,9 @@ int __udp4_lib_rcv(struct sk_buff *skb, struct udp_table *udptable,
77337 goto csum_error;
77338
77339 UDP_INC_STATS_BH(net, UDP_MIB_NOPORTS, proto == IPPROTO_UDPLITE);
77340+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
77341+ if (!grsec_enable_blackhole || (skb->dev->flags & IFF_LOOPBACK))
77342+#endif
77343 icmp_send(skb, ICMP_DEST_UNREACH, ICMP_PORT_UNREACH, 0);
77344
77345 /*
77346@@ -2116,8 +2140,13 @@ static void udp4_format_sock(struct sock *sp, struct seq_file *f,
77347 sk_wmem_alloc_get(sp),
77348 sk_rmem_alloc_get(sp),
77349 0, 0L, 0, sock_i_uid(sp), 0, sock_i_ino(sp),
77350- atomic_read(&sp->sk_refcnt), sp,
77351- atomic_read(&sp->sk_drops), len);
77352+ atomic_read(&sp->sk_refcnt),
77353+#ifdef CONFIG_GRKERNSEC_HIDESYM
77354+ NULL,
77355+#else
77356+ sp,
77357+#endif
77358+ atomic_read_unchecked(&sp->sk_drops), len);
77359 }
77360
77361 int udp4_seq_show(struct seq_file *seq, void *v)
77362diff --git a/net/ipv6/addrconf.c b/net/ipv6/addrconf.c
77363index b10374d..0baa1f9 100644
77364--- a/net/ipv6/addrconf.c
77365+++ b/net/ipv6/addrconf.c
77366@@ -2144,7 +2144,7 @@ int addrconf_set_dstaddr(struct net *net, void __user *arg)
77367 p.iph.ihl = 5;
77368 p.iph.protocol = IPPROTO_IPV6;
77369 p.iph.ttl = 64;
77370- ifr.ifr_ifru.ifru_data = (__force void __user *)&p;
77371+ ifr.ifr_ifru.ifru_data = (void __force_user *)&p;
77372
77373 if (ops->ndo_do_ioctl) {
77374 mm_segment_t oldfs = get_fs();
77375diff --git a/net/ipv6/ipv6_sockglue.c b/net/ipv6/ipv6_sockglue.c
77376index ba6d13d..6899122 100644
77377--- a/net/ipv6/ipv6_sockglue.c
77378+++ b/net/ipv6/ipv6_sockglue.c
77379@@ -989,7 +989,7 @@ static int do_ipv6_getsockopt(struct sock *sk, int level, int optname,
77380 if (sk->sk_type != SOCK_STREAM)
77381 return -ENOPROTOOPT;
77382
77383- msg.msg_control = optval;
77384+ msg.msg_control = (void __force_kernel *)optval;
77385 msg.msg_controllen = len;
77386 msg.msg_flags = flags;
77387
77388diff --git a/net/ipv6/netfilter/ip6_tables.c b/net/ipv6/netfilter/ip6_tables.c
77389index d7cb045..8c0ded6 100644
77390--- a/net/ipv6/netfilter/ip6_tables.c
77391+++ b/net/ipv6/netfilter/ip6_tables.c
77392@@ -1078,14 +1078,14 @@ static int compat_table_info(const struct xt_table_info *info,
77393 #endif
77394
77395 static int get_info(struct net *net, void __user *user,
77396- const int *len, int compat)
77397+ int len, int compat)
77398 {
77399 char name[XT_TABLE_MAXNAMELEN];
77400 struct xt_table *t;
77401 int ret;
77402
77403- if (*len != sizeof(struct ip6t_getinfo)) {
77404- duprintf("length %u != %zu\n", *len,
77405+ if (len != sizeof(struct ip6t_getinfo)) {
77406+ duprintf("length %u != %zu\n", len,
77407 sizeof(struct ip6t_getinfo));
77408 return -EINVAL;
77409 }
77410@@ -1122,7 +1122,7 @@ static int get_info(struct net *net, void __user *user,
77411 info.size = private->size;
77412 strcpy(info.name, name);
77413
77414- if (copy_to_user(user, &info, *len) != 0)
77415+ if (copy_to_user(user, &info, len) != 0)
77416 ret = -EFAULT;
77417 else
77418 ret = 0;
77419@@ -1976,7 +1976,7 @@ compat_do_ip6t_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
77420
77421 switch (cmd) {
77422 case IP6T_SO_GET_INFO:
77423- ret = get_info(sock_net(sk), user, len, 1);
77424+ ret = get_info(sock_net(sk), user, *len, 1);
77425 break;
77426 case IP6T_SO_GET_ENTRIES:
77427 ret = compat_get_entries(sock_net(sk), user, len);
77428@@ -2023,7 +2023,7 @@ do_ip6t_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
77429
77430 switch (cmd) {
77431 case IP6T_SO_GET_INFO:
77432- ret = get_info(sock_net(sk), user, len, 0);
77433+ ret = get_info(sock_net(sk), user, *len, 0);
77434 break;
77435
77436 case IP6T_SO_GET_ENTRIES:
77437diff --git a/net/ipv6/raw.c b/net/ipv6/raw.c
77438index 4a5f78b..3f22ebe 100644
77439--- a/net/ipv6/raw.c
77440+++ b/net/ipv6/raw.c
77441@@ -379,7 +379,7 @@ static inline int rawv6_rcv_skb(struct sock *sk, struct sk_buff *skb)
77442 {
77443 if ((raw6_sk(sk)->checksum || rcu_access_pointer(sk->sk_filter)) &&
77444 skb_checksum_complete(skb)) {
77445- atomic_inc(&sk->sk_drops);
77446+ atomic_inc_unchecked(&sk->sk_drops);
77447 kfree_skb(skb);
77448 return NET_RX_DROP;
77449 }
77450@@ -407,7 +407,7 @@ int rawv6_rcv(struct sock *sk, struct sk_buff *skb)
77451 struct raw6_sock *rp = raw6_sk(sk);
77452
77453 if (!xfrm6_policy_check(sk, XFRM_POLICY_IN, skb)) {
77454- atomic_inc(&sk->sk_drops);
77455+ atomic_inc_unchecked(&sk->sk_drops);
77456 kfree_skb(skb);
77457 return NET_RX_DROP;
77458 }
77459@@ -431,7 +431,7 @@ int rawv6_rcv(struct sock *sk, struct sk_buff *skb)
77460
77461 if (inet->hdrincl) {
77462 if (skb_checksum_complete(skb)) {
77463- atomic_inc(&sk->sk_drops);
77464+ atomic_inc_unchecked(&sk->sk_drops);
77465 kfree_skb(skb);
77466 return NET_RX_DROP;
77467 }
77468@@ -604,7 +604,7 @@ out:
77469 return err;
77470 }
77471
77472-static int rawv6_send_hdrinc(struct sock *sk, void *from, int length,
77473+static int rawv6_send_hdrinc(struct sock *sk, void *from, unsigned int length,
77474 struct flowi6 *fl6, struct dst_entry **dstp,
77475 unsigned int flags)
77476 {
77477@@ -916,12 +916,15 @@ do_confirm:
77478 static int rawv6_seticmpfilter(struct sock *sk, int level, int optname,
77479 char __user *optval, int optlen)
77480 {
77481+ struct icmp6_filter filter;
77482+
77483 switch (optname) {
77484 case ICMPV6_FILTER:
77485 if (optlen > sizeof(struct icmp6_filter))
77486 optlen = sizeof(struct icmp6_filter);
77487- if (copy_from_user(&raw6_sk(sk)->filter, optval, optlen))
77488+ if (copy_from_user(&filter, optval, optlen))
77489 return -EFAULT;
77490+ raw6_sk(sk)->filter = filter;
77491 return 0;
77492 default:
77493 return -ENOPROTOOPT;
77494@@ -934,6 +937,7 @@ static int rawv6_geticmpfilter(struct sock *sk, int level, int optname,
77495 char __user *optval, int __user *optlen)
77496 {
77497 int len;
77498+ struct icmp6_filter filter;
77499
77500 switch (optname) {
77501 case ICMPV6_FILTER:
77502@@ -945,7 +949,8 @@ static int rawv6_geticmpfilter(struct sock *sk, int level, int optname,
77503 len = sizeof(struct icmp6_filter);
77504 if (put_user(len, optlen))
77505 return -EFAULT;
77506- if (copy_to_user(optval, &raw6_sk(sk)->filter, len))
77507+ filter = raw6_sk(sk)->filter;
77508+ if (len > sizeof filter || copy_to_user(optval, &filter, len))
77509 return -EFAULT;
77510 return 0;
77511 default:
77512@@ -1252,7 +1257,13 @@ static void raw6_sock_seq_show(struct seq_file *seq, struct sock *sp, int i)
77513 0, 0L, 0,
77514 sock_i_uid(sp), 0,
77515 sock_i_ino(sp),
77516- atomic_read(&sp->sk_refcnt), sp, atomic_read(&sp->sk_drops));
77517+ atomic_read(&sp->sk_refcnt),
77518+#ifdef CONFIG_GRKERNSEC_HIDESYM
77519+ NULL,
77520+#else
77521+ sp,
77522+#endif
77523+ atomic_read_unchecked(&sp->sk_drops));
77524 }
77525
77526 static int raw6_seq_show(struct seq_file *seq, void *v)
77527diff --git a/net/ipv6/tcp_ipv6.c b/net/ipv6/tcp_ipv6.c
77528index 7e32d42..5d975ba 100644
77529--- a/net/ipv6/tcp_ipv6.c
77530+++ b/net/ipv6/tcp_ipv6.c
77531@@ -106,6 +106,10 @@ static void inet6_sk_rx_dst_set(struct sock *sk, const struct sk_buff *skb)
77532 inet6_sk(sk)->rx_dst_cookie = rt->rt6i_node->fn_sernum;
77533 }
77534
77535+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
77536+extern int grsec_enable_blackhole;
77537+#endif
77538+
77539 static void tcp_v6_hash(struct sock *sk)
77540 {
77541 if (sk->sk_state != TCP_CLOSE) {
77542@@ -1511,6 +1515,9 @@ static int tcp_v6_do_rcv(struct sock *sk, struct sk_buff *skb)
77543 return 0;
77544
77545 reset:
77546+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
77547+ if (!grsec_enable_blackhole)
77548+#endif
77549 tcp_v6_send_reset(sk, skb);
77550 discard:
77551 if (opt_skb)
77552@@ -1592,12 +1599,20 @@ static int tcp_v6_rcv(struct sk_buff *skb)
77553 TCP_SKB_CB(skb)->sacked = 0;
77554
77555 sk = __inet6_lookup_skb(&tcp_hashinfo, skb, th->source, th->dest);
77556- if (!sk)
77557+ if (!sk) {
77558+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
77559+ ret = 1;
77560+#endif
77561 goto no_tcp_socket;
77562+ }
77563
77564 process:
77565- if (sk->sk_state == TCP_TIME_WAIT)
77566+ if (sk->sk_state == TCP_TIME_WAIT) {
77567+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
77568+ ret = 2;
77569+#endif
77570 goto do_time_wait;
77571+ }
77572
77573 if (hdr->hop_limit < inet6_sk(sk)->min_hopcount) {
77574 NET_INC_STATS_BH(net, LINUX_MIB_TCPMINTTLDROP);
77575@@ -1646,6 +1661,10 @@ no_tcp_socket:
77576 bad_packet:
77577 TCP_INC_STATS_BH(net, TCP_MIB_INERRS);
77578 } else {
77579+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
77580+ if (!grsec_enable_blackhole || (ret == 1 &&
77581+ (skb->dev->flags & IFF_LOOPBACK)))
77582+#endif
77583 tcp_v6_send_reset(NULL, skb);
77584 }
77585
77586@@ -1857,7 +1876,13 @@ static void get_openreq6(struct seq_file *seq,
77587 uid,
77588 0, /* non standard timer */
77589 0, /* open_requests have no inode */
77590- 0, req);
77591+ 0,
77592+#ifdef CONFIG_GRKERNSEC_HIDESYM
77593+ NULL
77594+#else
77595+ req
77596+#endif
77597+ );
77598 }
77599
77600 static void get_tcp6_sock(struct seq_file *seq, struct sock *sp, int i)
77601@@ -1907,7 +1932,12 @@ static void get_tcp6_sock(struct seq_file *seq, struct sock *sp, int i)
77602 sock_i_uid(sp),
77603 icsk->icsk_probes_out,
77604 sock_i_ino(sp),
77605- atomic_read(&sp->sk_refcnt), sp,
77606+ atomic_read(&sp->sk_refcnt),
77607+#ifdef CONFIG_GRKERNSEC_HIDESYM
77608+ NULL,
77609+#else
77610+ sp,
77611+#endif
77612 jiffies_to_clock_t(icsk->icsk_rto),
77613 jiffies_to_clock_t(icsk->icsk_ack.ato),
77614 (icsk->icsk_ack.quick << 1 ) | icsk->icsk_ack.pingpong,
77615@@ -1942,7 +1972,13 @@ static void get_timewait6_sock(struct seq_file *seq,
77616 dest->s6_addr32[2], dest->s6_addr32[3], destp,
77617 tw->tw_substate, 0, 0,
77618 3, jiffies_to_clock_t(ttd), 0, 0, 0, 0,
77619- atomic_read(&tw->tw_refcnt), tw);
77620+ atomic_read(&tw->tw_refcnt),
77621+#ifdef CONFIG_GRKERNSEC_HIDESYM
77622+ NULL
77623+#else
77624+ tw
77625+#endif
77626+ );
77627 }
77628
77629 static int tcp6_seq_show(struct seq_file *seq, void *v)
77630diff --git a/net/ipv6/udp.c b/net/ipv6/udp.c
77631index 07e2bfe..328dae8 100644
77632--- a/net/ipv6/udp.c
77633+++ b/net/ipv6/udp.c
77634@@ -51,6 +51,10 @@
77635 #include <trace/events/skb.h>
77636 #include "udp_impl.h"
77637
77638+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
77639+extern int grsec_enable_blackhole;
77640+#endif
77641+
77642 int ipv6_rcv_saddr_equal(const struct sock *sk, const struct sock *sk2)
77643 {
77644 const struct in6_addr *sk_rcv_saddr6 = &inet6_sk(sk)->rcv_saddr;
77645@@ -395,7 +399,7 @@ try_again:
77646 if (unlikely(err)) {
77647 trace_kfree_skb(skb, udpv6_recvmsg);
77648 if (!peeked) {
77649- atomic_inc(&sk->sk_drops);
77650+ atomic_inc_unchecked(&sk->sk_drops);
77651 if (is_udp4)
77652 UDP_INC_STATS_USER(sock_net(sk),
77653 UDP_MIB_INERRORS,
77654@@ -633,7 +637,7 @@ int udpv6_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
77655 return rc;
77656 drop:
77657 UDP6_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS, is_udplite);
77658- atomic_inc(&sk->sk_drops);
77659+ atomic_inc_unchecked(&sk->sk_drops);
77660 kfree_skb(skb);
77661 return -1;
77662 }
77663@@ -691,7 +695,7 @@ static void flush_stack(struct sock **stack, unsigned int count,
77664 if (likely(skb1 == NULL))
77665 skb1 = (i == final) ? skb : skb_clone(skb, GFP_ATOMIC);
77666 if (!skb1) {
77667- atomic_inc(&sk->sk_drops);
77668+ atomic_inc_unchecked(&sk->sk_drops);
77669 UDP6_INC_STATS_BH(sock_net(sk), UDP_MIB_RCVBUFERRORS,
77670 IS_UDPLITE(sk));
77671 UDP6_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS,
77672@@ -862,6 +866,9 @@ int __udp6_lib_rcv(struct sk_buff *skb, struct udp_table *udptable,
77673 goto discard;
77674
77675 UDP6_INC_STATS_BH(net, UDP_MIB_NOPORTS, proto == IPPROTO_UDPLITE);
77676+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
77677+ if (!grsec_enable_blackhole || (skb->dev->flags & IFF_LOOPBACK))
77678+#endif
77679 icmpv6_send(skb, ICMPV6_DEST_UNREACH, ICMPV6_PORT_UNREACH, 0);
77680
77681 kfree_skb(skb);
77682@@ -1471,8 +1478,13 @@ static void udp6_sock_seq_show(struct seq_file *seq, struct sock *sp, int bucket
77683 0, 0L, 0,
77684 sock_i_uid(sp), 0,
77685 sock_i_ino(sp),
77686- atomic_read(&sp->sk_refcnt), sp,
77687- atomic_read(&sp->sk_drops));
77688+ atomic_read(&sp->sk_refcnt),
77689+#ifdef CONFIG_GRKERNSEC_HIDESYM
77690+ NULL,
77691+#else
77692+ sp,
77693+#endif
77694+ atomic_read_unchecked(&sp->sk_drops));
77695 }
77696
77697 int udp6_seq_show(struct seq_file *seq, void *v)
77698diff --git a/net/irda/ircomm/ircomm_tty.c b/net/irda/ircomm/ircomm_tty.c
77699index 6b9d5a0..4dffaf1 100644
77700--- a/net/irda/ircomm/ircomm_tty.c
77701+++ b/net/irda/ircomm/ircomm_tty.c
77702@@ -281,16 +281,16 @@ static int ircomm_tty_block_til_ready(struct ircomm_tty_cb *self,
77703 add_wait_queue(&self->open_wait, &wait);
77704
77705 IRDA_DEBUG(2, "%s(%d):block_til_ready before block on %s open_count=%d\n",
77706- __FILE__,__LINE__, tty->driver->name, self->open_count );
77707+ __FILE__,__LINE__, tty->driver->name, local_read(&self->open_count) );
77708
77709 /* As far as I can see, we protect open_count - Jean II */
77710 spin_lock_irqsave(&self->spinlock, flags);
77711 if (!tty_hung_up_p(filp)) {
77712 extra_count = 1;
77713- self->open_count--;
77714+ local_dec(&self->open_count);
77715 }
77716 spin_unlock_irqrestore(&self->spinlock, flags);
77717- self->blocked_open++;
77718+ local_inc(&self->blocked_open);
77719
77720 while (1) {
77721 if (tty->termios->c_cflag & CBAUD) {
77722@@ -330,7 +330,7 @@ static int ircomm_tty_block_til_ready(struct ircomm_tty_cb *self,
77723 }
77724
77725 IRDA_DEBUG(1, "%s(%d):block_til_ready blocking on %s open_count=%d\n",
77726- __FILE__,__LINE__, tty->driver->name, self->open_count );
77727+ __FILE__,__LINE__, tty->driver->name, local_read(&self->open_count) );
77728
77729 schedule();
77730 }
77731@@ -341,13 +341,13 @@ static int ircomm_tty_block_til_ready(struct ircomm_tty_cb *self,
77732 if (extra_count) {
77733 /* ++ is not atomic, so this should be protected - Jean II */
77734 spin_lock_irqsave(&self->spinlock, flags);
77735- self->open_count++;
77736+ local_inc(&self->open_count);
77737 spin_unlock_irqrestore(&self->spinlock, flags);
77738 }
77739- self->blocked_open--;
77740+ local_dec(&self->blocked_open);
77741
77742 IRDA_DEBUG(1, "%s(%d):block_til_ready after blocking on %s open_count=%d\n",
77743- __FILE__,__LINE__, tty->driver->name, self->open_count);
77744+ __FILE__,__LINE__, tty->driver->name, local_read(&self->open_count));
77745
77746 if (!retval)
77747 self->flags |= ASYNC_NORMAL_ACTIVE;
77748@@ -412,14 +412,14 @@ static int ircomm_tty_open(struct tty_struct *tty, struct file *filp)
77749 }
77750 /* ++ is not atomic, so this should be protected - Jean II */
77751 spin_lock_irqsave(&self->spinlock, flags);
77752- self->open_count++;
77753+ local_inc(&self->open_count);
77754
77755 tty->driver_data = self;
77756 self->tty = tty;
77757 spin_unlock_irqrestore(&self->spinlock, flags);
77758
77759 IRDA_DEBUG(1, "%s(), %s%d, count = %d\n", __func__ , tty->driver->name,
77760- self->line, self->open_count);
77761+ self->line, local_read(&self->open_count));
77762
77763 /* Not really used by us, but lets do it anyway */
77764 self->tty->low_latency = (self->flags & ASYNC_LOW_LATENCY) ? 1 : 0;
77765@@ -505,7 +505,7 @@ static void ircomm_tty_close(struct tty_struct *tty, struct file *filp)
77766 return;
77767 }
77768
77769- if ((tty->count == 1) && (self->open_count != 1)) {
77770+ if ((tty->count == 1) && (local_read(&self->open_count) != 1)) {
77771 /*
77772 * Uh, oh. tty->count is 1, which means that the tty
77773 * structure will be freed. state->count should always
77774@@ -515,16 +515,16 @@ static void ircomm_tty_close(struct tty_struct *tty, struct file *filp)
77775 */
77776 IRDA_DEBUG(0, "%s(), bad serial port count; "
77777 "tty->count is 1, state->count is %d\n", __func__ ,
77778- self->open_count);
77779- self->open_count = 1;
77780+ local_read(&self->open_count));
77781+ local_set(&self->open_count, 1);
77782 }
77783
77784- if (--self->open_count < 0) {
77785+ if (local_dec_return(&self->open_count) < 0) {
77786 IRDA_ERROR("%s(), bad serial port count for ttys%d: %d\n",
77787- __func__, self->line, self->open_count);
77788- self->open_count = 0;
77789+ __func__, self->line, local_read(&self->open_count));
77790+ local_set(&self->open_count, 0);
77791 }
77792- if (self->open_count) {
77793+ if (local_read(&self->open_count)) {
77794 spin_unlock_irqrestore(&self->spinlock, flags);
77795
77796 IRDA_DEBUG(0, "%s(), open count > 0\n", __func__ );
77797@@ -556,7 +556,7 @@ static void ircomm_tty_close(struct tty_struct *tty, struct file *filp)
77798 tty->closing = 0;
77799 self->tty = NULL;
77800
77801- if (self->blocked_open) {
77802+ if (local_read(&self->blocked_open)) {
77803 if (self->close_delay)
77804 schedule_timeout_interruptible(self->close_delay);
77805 wake_up_interruptible(&self->open_wait);
77806@@ -1008,7 +1008,7 @@ static void ircomm_tty_hangup(struct tty_struct *tty)
77807 spin_lock_irqsave(&self->spinlock, flags);
77808 self->flags &= ~ASYNC_NORMAL_ACTIVE;
77809 self->tty = NULL;
77810- self->open_count = 0;
77811+ local_set(&self->open_count, 0);
77812 spin_unlock_irqrestore(&self->spinlock, flags);
77813
77814 wake_up_interruptible(&self->open_wait);
77815@@ -1355,7 +1355,7 @@ static void ircomm_tty_line_info(struct ircomm_tty_cb *self, struct seq_file *m)
77816 seq_putc(m, '\n');
77817
77818 seq_printf(m, "Role: %s\n", self->client ? "client" : "server");
77819- seq_printf(m, "Open count: %d\n", self->open_count);
77820+ seq_printf(m, "Open count: %d\n", local_read(&self->open_count));
77821 seq_printf(m, "Max data size: %d\n", self->max_data_size);
77822 seq_printf(m, "Max header size: %d\n", self->max_header_size);
77823
77824diff --git a/net/iucv/af_iucv.c b/net/iucv/af_iucv.c
77825index cd6f7a9..e63fe89 100644
77826--- a/net/iucv/af_iucv.c
77827+++ b/net/iucv/af_iucv.c
77828@@ -782,10 +782,10 @@ static int iucv_sock_autobind(struct sock *sk)
77829
77830 write_lock_bh(&iucv_sk_list.lock);
77831
77832- sprintf(name, "%08x", atomic_inc_return(&iucv_sk_list.autobind_name));
77833+ sprintf(name, "%08x", atomic_inc_return_unchecked(&iucv_sk_list.autobind_name));
77834 while (__iucv_get_sock_by_name(name)) {
77835 sprintf(name, "%08x",
77836- atomic_inc_return(&iucv_sk_list.autobind_name));
77837+ atomic_inc_return_unchecked(&iucv_sk_list.autobind_name));
77838 }
77839
77840 write_unlock_bh(&iucv_sk_list.lock);
77841diff --git a/net/key/af_key.c b/net/key/af_key.c
77842index 34e4185..8823368 100644
77843--- a/net/key/af_key.c
77844+++ b/net/key/af_key.c
77845@@ -3016,10 +3016,10 @@ static int pfkey_send_policy_notify(struct xfrm_policy *xp, int dir, const struc
77846 static u32 get_acqseq(void)
77847 {
77848 u32 res;
77849- static atomic_t acqseq;
77850+ static atomic_unchecked_t acqseq;
77851
77852 do {
77853- res = atomic_inc_return(&acqseq);
77854+ res = atomic_inc_return_unchecked(&acqseq);
77855 } while (!res);
77856 return res;
77857 }
77858diff --git a/net/mac80211/ieee80211_i.h b/net/mac80211/ieee80211_i.h
77859index bb61f77..3788d63 100644
77860--- a/net/mac80211/ieee80211_i.h
77861+++ b/net/mac80211/ieee80211_i.h
77862@@ -28,6 +28,7 @@
77863 #include <net/ieee80211_radiotap.h>
77864 #include <net/cfg80211.h>
77865 #include <net/mac80211.h>
77866+#include <asm/local.h>
77867 #include "key.h"
77868 #include "sta_info.h"
77869 #include "debug.h"
77870@@ -840,7 +841,7 @@ struct ieee80211_local {
77871 /* also used to protect ampdu_ac_queue and amdpu_ac_stop_refcnt */
77872 spinlock_t queue_stop_reason_lock;
77873
77874- int open_count;
77875+ local_t open_count;
77876 int monitors, cooked_mntrs;
77877 /* number of interfaces with corresponding FIF_ flags */
77878 int fif_fcsfail, fif_plcpfail, fif_control, fif_other_bss, fif_pspoll,
77879diff --git a/net/mac80211/iface.c b/net/mac80211/iface.c
77880index bfb57dc..77c4b81 100644
77881--- a/net/mac80211/iface.c
77882+++ b/net/mac80211/iface.c
77883@@ -454,7 +454,7 @@ static int ieee80211_do_open(struct net_device *dev, bool coming_up)
77884 break;
77885 }
77886
77887- if (local->open_count == 0) {
77888+ if (local_read(&local->open_count) == 0) {
77889 res = drv_start(local);
77890 if (res)
77891 goto err_del_bss;
77892@@ -497,7 +497,7 @@ static int ieee80211_do_open(struct net_device *dev, bool coming_up)
77893 break;
77894 }
77895
77896- if (local->monitors == 0 && local->open_count == 0) {
77897+ if (local->monitors == 0 && local_read(&local->open_count) == 0) {
77898 res = ieee80211_add_virtual_monitor(local);
77899 if (res)
77900 goto err_stop;
77901@@ -594,7 +594,7 @@ static int ieee80211_do_open(struct net_device *dev, bool coming_up)
77902 mutex_unlock(&local->mtx);
77903
77904 if (coming_up)
77905- local->open_count++;
77906+ local_inc(&local->open_count);
77907
77908 if (hw_reconf_flags)
77909 ieee80211_hw_config(local, hw_reconf_flags);
77910@@ -607,7 +607,7 @@ static int ieee80211_do_open(struct net_device *dev, bool coming_up)
77911 err_del_interface:
77912 drv_remove_interface(local, sdata);
77913 err_stop:
77914- if (!local->open_count)
77915+ if (!local_read(&local->open_count))
77916 drv_stop(local);
77917 err_del_bss:
77918 sdata->bss = NULL;
77919@@ -736,7 +736,7 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
77920 }
77921
77922 if (going_down)
77923- local->open_count--;
77924+ local_dec(&local->open_count);
77925
77926 switch (sdata->vif.type) {
77927 case NL80211_IFTYPE_AP_VLAN:
77928@@ -796,7 +796,7 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
77929
77930 ieee80211_recalc_ps(local, -1);
77931
77932- if (local->open_count == 0) {
77933+ if (local_read(&local->open_count) == 0) {
77934 if (local->ops->napi_poll)
77935 napi_disable(&local->napi);
77936 ieee80211_clear_tx_pending(local);
77937@@ -828,7 +828,7 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
77938 }
77939 spin_unlock_irqrestore(&local->queue_stop_reason_lock, flags);
77940
77941- if (local->monitors == local->open_count && local->monitors > 0)
77942+ if (local->monitors == local_read(&local->open_count) && local->monitors > 0)
77943 ieee80211_add_virtual_monitor(local);
77944 }
77945
77946diff --git a/net/mac80211/main.c b/net/mac80211/main.c
77947index c26e231..8916637 100644
77948--- a/net/mac80211/main.c
77949+++ b/net/mac80211/main.c
77950@@ -166,7 +166,7 @@ int ieee80211_hw_config(struct ieee80211_local *local, u32 changed)
77951 local->hw.conf.power_level = power;
77952 }
77953
77954- if (changed && local->open_count) {
77955+ if (changed && local_read(&local->open_count)) {
77956 ret = drv_config(local, changed);
77957 /*
77958 * Goal:
77959diff --git a/net/mac80211/pm.c b/net/mac80211/pm.c
77960index 5c572e7..ecf75ce 100644
77961--- a/net/mac80211/pm.c
77962+++ b/net/mac80211/pm.c
77963@@ -34,7 +34,7 @@ int __ieee80211_suspend(struct ieee80211_hw *hw, struct cfg80211_wowlan *wowlan)
77964 struct ieee80211_sub_if_data *sdata;
77965 struct sta_info *sta;
77966
77967- if (!local->open_count)
77968+ if (!local_read(&local->open_count))
77969 goto suspend;
77970
77971 ieee80211_scan_cancel(local);
77972@@ -72,7 +72,7 @@ int __ieee80211_suspend(struct ieee80211_hw *hw, struct cfg80211_wowlan *wowlan)
77973 cancel_work_sync(&local->dynamic_ps_enable_work);
77974 del_timer_sync(&local->dynamic_ps_timer);
77975
77976- local->wowlan = wowlan && local->open_count;
77977+ local->wowlan = wowlan && local_read(&local->open_count);
77978 if (local->wowlan) {
77979 int err = drv_suspend(local, wowlan);
77980 if (err < 0) {
77981@@ -143,7 +143,7 @@ int __ieee80211_suspend(struct ieee80211_hw *hw, struct cfg80211_wowlan *wowlan)
77982 drv_remove_interface(local, sdata);
77983
77984 /* stop hardware - this must stop RX */
77985- if (local->open_count)
77986+ if (local_read(&local->open_count))
77987 ieee80211_stop_device(local);
77988
77989 suspend:
77990diff --git a/net/mac80211/rate.c b/net/mac80211/rate.c
77991index 3313c11..bec9f17 100644
77992--- a/net/mac80211/rate.c
77993+++ b/net/mac80211/rate.c
77994@@ -494,7 +494,7 @@ int ieee80211_init_rate_ctrl_alg(struct ieee80211_local *local,
77995
77996 ASSERT_RTNL();
77997
77998- if (local->open_count)
77999+ if (local_read(&local->open_count))
78000 return -EBUSY;
78001
78002 if (local->hw.flags & IEEE80211_HW_HAS_RATE_CONTROL) {
78003diff --git a/net/mac80211/rc80211_pid_debugfs.c b/net/mac80211/rc80211_pid_debugfs.c
78004index c97a065..ff61928 100644
78005--- a/net/mac80211/rc80211_pid_debugfs.c
78006+++ b/net/mac80211/rc80211_pid_debugfs.c
78007@@ -193,7 +193,7 @@ static ssize_t rate_control_pid_events_read(struct file *file, char __user *buf,
78008
78009 spin_unlock_irqrestore(&events->lock, status);
78010
78011- if (copy_to_user(buf, pb, p))
78012+ if (p > sizeof(pb) || copy_to_user(buf, pb, p))
78013 return -EFAULT;
78014
78015 return p;
78016diff --git a/net/mac80211/util.c b/net/mac80211/util.c
78017index 39b82fe..5469ef4 100644
78018--- a/net/mac80211/util.c
78019+++ b/net/mac80211/util.c
78020@@ -1251,7 +1251,7 @@ int ieee80211_reconfig(struct ieee80211_local *local)
78021 }
78022 #endif
78023 /* everything else happens only if HW was up & running */
78024- if (!local->open_count)
78025+ if (!local_read(&local->open_count))
78026 goto wake_up;
78027
78028 /*
78029diff --git a/net/netfilter/Kconfig b/net/netfilter/Kconfig
78030index c19b214..471fad1 100644
78031--- a/net/netfilter/Kconfig
78032+++ b/net/netfilter/Kconfig
78033@@ -872,6 +872,16 @@ config NETFILTER_XT_MATCH_ESP
78034
78035 To compile it as a module, choose M here. If unsure, say N.
78036
78037+config NETFILTER_XT_MATCH_GRADM
78038+ tristate '"gradm" match support'
78039+ depends on NETFILTER_XTABLES && NETFILTER_ADVANCED
78040+ depends on GRKERNSEC && !GRKERNSEC_NO_RBAC
78041+ ---help---
78042+ The gradm match allows to match on grsecurity RBAC being enabled.
78043+ It is useful when iptables rules are applied early on bootup to
78044+ prevent connections to the machine (except from a trusted host)
78045+ while the RBAC system is disabled.
78046+
78047 config NETFILTER_XT_MATCH_HASHLIMIT
78048 tristate '"hashlimit" match support'
78049 depends on (IP6_NF_IPTABLES || IP6_NF_IPTABLES=n)
78050diff --git a/net/netfilter/Makefile b/net/netfilter/Makefile
78051index 1c5160f..145ae21 100644
78052--- a/net/netfilter/Makefile
78053+++ b/net/netfilter/Makefile
78054@@ -90,6 +90,7 @@ obj-$(CONFIG_NETFILTER_XT_MATCH_DEVGROUP) += xt_devgroup.o
78055 obj-$(CONFIG_NETFILTER_XT_MATCH_DSCP) += xt_dscp.o
78056 obj-$(CONFIG_NETFILTER_XT_MATCH_ECN) += xt_ecn.o
78057 obj-$(CONFIG_NETFILTER_XT_MATCH_ESP) += xt_esp.o
78058+obj-$(CONFIG_NETFILTER_XT_MATCH_GRADM) += xt_gradm.o
78059 obj-$(CONFIG_NETFILTER_XT_MATCH_HASHLIMIT) += xt_hashlimit.o
78060 obj-$(CONFIG_NETFILTER_XT_MATCH_HELPER) += xt_helper.o
78061 obj-$(CONFIG_NETFILTER_XT_MATCH_HL) += xt_hl.o
78062diff --git a/net/netfilter/ipvs/ip_vs_conn.c b/net/netfilter/ipvs/ip_vs_conn.c
78063index 1548df9..98ad9b4 100644
78064--- a/net/netfilter/ipvs/ip_vs_conn.c
78065+++ b/net/netfilter/ipvs/ip_vs_conn.c
78066@@ -557,7 +557,7 @@ ip_vs_bind_dest(struct ip_vs_conn *cp, struct ip_vs_dest *dest)
78067 /* Increase the refcnt counter of the dest */
78068 atomic_inc(&dest->refcnt);
78069
78070- conn_flags = atomic_read(&dest->conn_flags);
78071+ conn_flags = atomic_read_unchecked(&dest->conn_flags);
78072 if (cp->protocol != IPPROTO_UDP)
78073 conn_flags &= ~IP_VS_CONN_F_ONE_PACKET;
78074 flags = cp->flags;
78075@@ -902,7 +902,7 @@ ip_vs_conn_new(const struct ip_vs_conn_param *p,
78076 atomic_set(&cp->refcnt, 1);
78077
78078 atomic_set(&cp->n_control, 0);
78079- atomic_set(&cp->in_pkts, 0);
78080+ atomic_set_unchecked(&cp->in_pkts, 0);
78081
78082 atomic_inc(&ipvs->conn_count);
78083 if (flags & IP_VS_CONN_F_NO_CPORT)
78084@@ -1183,7 +1183,7 @@ static inline int todrop_entry(struct ip_vs_conn *cp)
78085
78086 /* Don't drop the entry if its number of incoming packets is not
78087 located in [0, 8] */
78088- i = atomic_read(&cp->in_pkts);
78089+ i = atomic_read_unchecked(&cp->in_pkts);
78090 if (i > 8 || i < 0) return 0;
78091
78092 if (!todrop_rate[i]) return 0;
78093diff --git a/net/netfilter/ipvs/ip_vs_core.c b/net/netfilter/ipvs/ip_vs_core.c
78094index b54ecce..fc5f6cf 100644
78095--- a/net/netfilter/ipvs/ip_vs_core.c
78096+++ b/net/netfilter/ipvs/ip_vs_core.c
78097@@ -562,7 +562,7 @@ int ip_vs_leave(struct ip_vs_service *svc, struct sk_buff *skb,
78098 ret = cp->packet_xmit(skb, cp, pd->pp);
78099 /* do not touch skb anymore */
78100
78101- atomic_inc(&cp->in_pkts);
78102+ atomic_inc_unchecked(&cp->in_pkts);
78103 ip_vs_conn_put(cp);
78104 return ret;
78105 }
78106@@ -1611,7 +1611,7 @@ ip_vs_in(unsigned int hooknum, struct sk_buff *skb, int af)
78107 if (cp->flags & IP_VS_CONN_F_ONE_PACKET)
78108 pkts = sysctl_sync_threshold(ipvs);
78109 else
78110- pkts = atomic_add_return(1, &cp->in_pkts);
78111+ pkts = atomic_add_return_unchecked(1, &cp->in_pkts);
78112
78113 if (ipvs->sync_state & IP_VS_STATE_MASTER)
78114 ip_vs_sync_conn(net, cp, pkts);
78115diff --git a/net/netfilter/ipvs/ip_vs_ctl.c b/net/netfilter/ipvs/ip_vs_ctl.c
78116index f51013c..c99ee52 100644
78117--- a/net/netfilter/ipvs/ip_vs_ctl.c
78118+++ b/net/netfilter/ipvs/ip_vs_ctl.c
78119@@ -788,7 +788,7 @@ __ip_vs_update_dest(struct ip_vs_service *svc, struct ip_vs_dest *dest,
78120 ip_vs_rs_hash(ipvs, dest);
78121 write_unlock_bh(&ipvs->rs_lock);
78122 }
78123- atomic_set(&dest->conn_flags, conn_flags);
78124+ atomic_set_unchecked(&dest->conn_flags, conn_flags);
78125
78126 /* bind the service */
78127 if (!dest->svc) {
78128@@ -2076,7 +2076,7 @@ static int ip_vs_info_seq_show(struct seq_file *seq, void *v)
78129 " %-7s %-6d %-10d %-10d\n",
78130 &dest->addr.in6,
78131 ntohs(dest->port),
78132- ip_vs_fwd_name(atomic_read(&dest->conn_flags)),
78133+ ip_vs_fwd_name(atomic_read_unchecked(&dest->conn_flags)),
78134 atomic_read(&dest->weight),
78135 atomic_read(&dest->activeconns),
78136 atomic_read(&dest->inactconns));
78137@@ -2087,7 +2087,7 @@ static int ip_vs_info_seq_show(struct seq_file *seq, void *v)
78138 "%-7s %-6d %-10d %-10d\n",
78139 ntohl(dest->addr.ip),
78140 ntohs(dest->port),
78141- ip_vs_fwd_name(atomic_read(&dest->conn_flags)),
78142+ ip_vs_fwd_name(atomic_read_unchecked(&dest->conn_flags)),
78143 atomic_read(&dest->weight),
78144 atomic_read(&dest->activeconns),
78145 atomic_read(&dest->inactconns));
78146@@ -2557,7 +2557,7 @@ __ip_vs_get_dest_entries(struct net *net, const struct ip_vs_get_dests *get,
78147
78148 entry.addr = dest->addr.ip;
78149 entry.port = dest->port;
78150- entry.conn_flags = atomic_read(&dest->conn_flags);
78151+ entry.conn_flags = atomic_read_unchecked(&dest->conn_flags);
78152 entry.weight = atomic_read(&dest->weight);
78153 entry.u_threshold = dest->u_threshold;
78154 entry.l_threshold = dest->l_threshold;
78155@@ -3092,7 +3092,7 @@ static int ip_vs_genl_fill_dest(struct sk_buff *skb, struct ip_vs_dest *dest)
78156 if (nla_put(skb, IPVS_DEST_ATTR_ADDR, sizeof(dest->addr), &dest->addr) ||
78157 nla_put_u16(skb, IPVS_DEST_ATTR_PORT, dest->port) ||
78158 nla_put_u32(skb, IPVS_DEST_ATTR_FWD_METHOD,
78159- (atomic_read(&dest->conn_flags) &
78160+ (atomic_read_unchecked(&dest->conn_flags) &
78161 IP_VS_CONN_F_FWD_MASK)) ||
78162 nla_put_u32(skb, IPVS_DEST_ATTR_WEIGHT,
78163 atomic_read(&dest->weight)) ||
78164diff --git a/net/netfilter/ipvs/ip_vs_sync.c b/net/netfilter/ipvs/ip_vs_sync.c
78165index effa10c..9058928 100644
78166--- a/net/netfilter/ipvs/ip_vs_sync.c
78167+++ b/net/netfilter/ipvs/ip_vs_sync.c
78168@@ -596,7 +596,7 @@ static void ip_vs_sync_conn_v0(struct net *net, struct ip_vs_conn *cp,
78169 cp = cp->control;
78170 if (cp) {
78171 if (cp->flags & IP_VS_CONN_F_TEMPLATE)
78172- pkts = atomic_add_return(1, &cp->in_pkts);
78173+ pkts = atomic_add_return_unchecked(1, &cp->in_pkts);
78174 else
78175 pkts = sysctl_sync_threshold(ipvs);
78176 ip_vs_sync_conn(net, cp->control, pkts);
78177@@ -758,7 +758,7 @@ control:
78178 if (!cp)
78179 return;
78180 if (cp->flags & IP_VS_CONN_F_TEMPLATE)
78181- pkts = atomic_add_return(1, &cp->in_pkts);
78182+ pkts = atomic_add_return_unchecked(1, &cp->in_pkts);
78183 else
78184 pkts = sysctl_sync_threshold(ipvs);
78185 goto sloop;
78186@@ -885,7 +885,7 @@ static void ip_vs_proc_conn(struct net *net, struct ip_vs_conn_param *param,
78187
78188 if (opt)
78189 memcpy(&cp->in_seq, opt, sizeof(*opt));
78190- atomic_set(&cp->in_pkts, sysctl_sync_threshold(ipvs));
78191+ atomic_set_unchecked(&cp->in_pkts, sysctl_sync_threshold(ipvs));
78192 cp->state = state;
78193 cp->old_state = cp->state;
78194 /*
78195diff --git a/net/netfilter/ipvs/ip_vs_xmit.c b/net/netfilter/ipvs/ip_vs_xmit.c
78196index c3c6291..3376d73 100644
78197--- a/net/netfilter/ipvs/ip_vs_xmit.c
78198+++ b/net/netfilter/ipvs/ip_vs_xmit.c
78199@@ -1157,7 +1157,7 @@ ip_vs_icmp_xmit(struct sk_buff *skb, struct ip_vs_conn *cp,
78200 else
78201 rc = NF_ACCEPT;
78202 /* do not touch skb anymore */
78203- atomic_inc(&cp->in_pkts);
78204+ atomic_inc_unchecked(&cp->in_pkts);
78205 goto out;
78206 }
78207
78208@@ -1278,7 +1278,7 @@ ip_vs_icmp_xmit_v6(struct sk_buff *skb, struct ip_vs_conn *cp,
78209 else
78210 rc = NF_ACCEPT;
78211 /* do not touch skb anymore */
78212- atomic_inc(&cp->in_pkts);
78213+ atomic_inc_unchecked(&cp->in_pkts);
78214 goto out;
78215 }
78216
78217diff --git a/net/netfilter/nf_conntrack_core.c b/net/netfilter/nf_conntrack_core.c
78218index 2ceec64..a5b8a61 100644
78219--- a/net/netfilter/nf_conntrack_core.c
78220+++ b/net/netfilter/nf_conntrack_core.c
78221@@ -1529,6 +1529,10 @@ err_extend:
78222 #define UNCONFIRMED_NULLS_VAL ((1<<30)+0)
78223 #define DYING_NULLS_VAL ((1<<30)+1)
78224
78225+#ifdef CONFIG_GRKERNSEC_HIDESYM
78226+static atomic_unchecked_t conntrack_cache_id = ATOMIC_INIT(0);
78227+#endif
78228+
78229 static int nf_conntrack_init_net(struct net *net)
78230 {
78231 int ret;
78232@@ -1542,7 +1546,11 @@ static int nf_conntrack_init_net(struct net *net)
78233 goto err_stat;
78234 }
78235
78236+#ifdef CONFIG_GRKERNSEC_HIDESYM
78237+ net->ct.slabname = kasprintf(GFP_KERNEL, "nf_conntrack_%08lx", atomic_inc_return_unchecked(&conntrack_cache_id));
78238+#else
78239 net->ct.slabname = kasprintf(GFP_KERNEL, "nf_conntrack_%p", net);
78240+#endif
78241 if (!net->ct.slabname) {
78242 ret = -ENOMEM;
78243 goto err_slabname;
78244diff --git a/net/netfilter/nfnetlink_log.c b/net/netfilter/nfnetlink_log.c
78245index 5cfb5be..217c6d8 100644
78246--- a/net/netfilter/nfnetlink_log.c
78247+++ b/net/netfilter/nfnetlink_log.c
78248@@ -70,7 +70,7 @@ struct nfulnl_instance {
78249 };
78250
78251 static DEFINE_SPINLOCK(instances_lock);
78252-static atomic_t global_seq;
78253+static atomic_unchecked_t global_seq;
78254
78255 #define INSTANCE_BUCKETS 16
78256 static struct hlist_head instance_table[INSTANCE_BUCKETS];
78257@@ -523,7 +523,7 @@ __build_packet_message(struct nfulnl_instance *inst,
78258 /* global sequence number */
78259 if ((inst->flags & NFULNL_CFG_F_SEQ_GLOBAL) &&
78260 nla_put_be32(inst->skb, NFULA_SEQ_GLOBAL,
78261- htonl(atomic_inc_return(&global_seq))))
78262+ htonl(atomic_inc_return_unchecked(&global_seq))))
78263 goto nla_put_failure;
78264
78265 if (data_len) {
78266diff --git a/net/netfilter/xt_gradm.c b/net/netfilter/xt_gradm.c
78267new file mode 100644
78268index 0000000..6905327
78269--- /dev/null
78270+++ b/net/netfilter/xt_gradm.c
78271@@ -0,0 +1,51 @@
78272+/*
78273+ * gradm match for netfilter
78274