]> git.ipfire.org Git - thirdparty/grsecurity-scrape.git/blame - test/grsecurity-2.9.1-3.6.8-201212011309.patch
Auto commit, 1 new patch{es}.
[thirdparty/grsecurity-scrape.git] / test / grsecurity-2.9.1-3.6.8-201212011309.patch
CommitLineData
a4ad6177
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 c5cc2f0..6570abb 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/mach-omap2/omap_hwmod.c b/arch/arm/mach-omap2/omap_hwmod.c
1853index 37afbd1..c22ad7c 100644
1854--- a/arch/arm/mach-omap2/omap_hwmod.c
1855+++ b/arch/arm/mach-omap2/omap_hwmod.c
1856@@ -187,10 +187,10 @@ struct omap_hwmod_soc_ops {
1857 int (*is_hardreset_asserted)(struct omap_hwmod *oh,
1858 struct omap_hwmod_rst_info *ohri);
1859 int (*init_clkdm)(struct omap_hwmod *oh);
1860-};
1861+} __no_const;
1862
1863 /* soc_ops: adapts the omap_hwmod code to the currently-booted SoC */
1864-static struct omap_hwmod_soc_ops soc_ops;
1865+static struct omap_hwmod_soc_ops soc_ops __read_only;
1866
1867 /* omap_hwmod_list contains all registered struct omap_hwmods */
1868 static LIST_HEAD(omap_hwmod_list);
1869diff --git a/arch/arm/mm/fault.c b/arch/arm/mm/fault.c
1870index c3bd834..e81ef02 100644
1871--- a/arch/arm/mm/fault.c
1872+++ b/arch/arm/mm/fault.c
1873@@ -174,6 +174,13 @@ __do_user_fault(struct task_struct *tsk, unsigned long addr,
1874 }
1875 #endif
1876
1877+#ifdef CONFIG_PAX_PAGEEXEC
1878+ if (fsr & FSR_LNX_PF) {
1879+ pax_report_fault(regs, (void *)regs->ARM_pc, (void *)regs->ARM_sp);
1880+ do_group_exit(SIGKILL);
1881+ }
1882+#endif
1883+
1884 tsk->thread.address = addr;
1885 tsk->thread.error_code = fsr;
1886 tsk->thread.trap_no = 14;
1887@@ -397,6 +404,33 @@ do_page_fault(unsigned long addr, unsigned int fsr, struct pt_regs *regs)
1888 }
1889 #endif /* CONFIG_MMU */
1890
1891+#ifdef CONFIG_PAX_PAGEEXEC
1892+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
1893+{
1894+ long i;
1895+
1896+ printk(KERN_ERR "PAX: bytes at PC: ");
1897+ for (i = 0; i < 20; i++) {
1898+ unsigned char c;
1899+ if (get_user(c, (__force unsigned char __user *)pc+i))
1900+ printk(KERN_CONT "?? ");
1901+ else
1902+ printk(KERN_CONT "%02x ", c);
1903+ }
1904+ printk("\n");
1905+
1906+ printk(KERN_ERR "PAX: bytes at SP-4: ");
1907+ for (i = -1; i < 20; i++) {
1908+ unsigned long c;
1909+ if (get_user(c, (__force unsigned long __user *)sp+i))
1910+ printk(KERN_CONT "???????? ");
1911+ else
1912+ printk(KERN_CONT "%08lx ", c);
1913+ }
1914+ printk("\n");
1915+}
1916+#endif
1917+
1918 /*
1919 * First Level Translation Fault Handler
1920 *
1921@@ -574,6 +608,20 @@ do_PrefetchAbort(unsigned long addr, unsigned int ifsr, struct pt_regs *regs)
1922 const struct fsr_info *inf = ifsr_info + fsr_fs(ifsr);
1923 struct siginfo info;
1924
1925+#ifdef CONFIG_PAX_REFCOUNT
1926+ if (fsr_fs(ifsr) == 2) {
1927+ unsigned int bkpt;
1928+
1929+ if (!probe_kernel_address((unsigned int *)addr, bkpt) && bkpt == 0xe12f1073) {
1930+ current->thread.error_code = ifsr;
1931+ current->thread.trap_no = 0;
1932+ pax_report_refcount_overflow(regs);
1933+ fixup_exception(regs);
1934+ return;
1935+ }
1936+ }
1937+#endif
1938+
1939 if (!inf->fn(addr, ifsr | FSR_LNX_PF, regs))
1940 return;
1941
1942diff --git a/arch/arm/mm/mmap.c b/arch/arm/mm/mmap.c
1943index ce8cb19..3ec539d 100644
1944--- a/arch/arm/mm/mmap.c
1945+++ b/arch/arm/mm/mmap.c
1946@@ -93,6 +93,10 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
1947 if (len > TASK_SIZE)
1948 return -ENOMEM;
1949
1950+#ifdef CONFIG_PAX_RANDMMAP
1951+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
1952+#endif
1953+
1954 if (addr) {
1955 if (do_align)
1956 addr = COLOUR_ALIGN(addr, pgoff);
1957@@ -100,15 +104,14 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
1958 addr = PAGE_ALIGN(addr);
1959
1960 vma = find_vma(mm, addr);
1961- if (TASK_SIZE - len >= addr &&
1962- (!vma || addr + len <= vma->vm_start))
1963+ if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len))
1964 return addr;
1965 }
1966 if (len > mm->cached_hole_size) {
1967- start_addr = addr = mm->free_area_cache;
1968+ start_addr = addr = mm->free_area_cache;
1969 } else {
1970- start_addr = addr = mm->mmap_base;
1971- mm->cached_hole_size = 0;
1972+ start_addr = addr = mm->mmap_base;
1973+ mm->cached_hole_size = 0;
1974 }
1975
1976 full_search:
1977@@ -124,14 +127,14 @@ full_search:
1978 * Start a new search - just in case we missed
1979 * some holes.
1980 */
1981- if (start_addr != TASK_UNMAPPED_BASE) {
1982- start_addr = addr = TASK_UNMAPPED_BASE;
1983+ if (start_addr != mm->mmap_base) {
1984+ start_addr = addr = mm->mmap_base;
1985 mm->cached_hole_size = 0;
1986 goto full_search;
1987 }
1988 return -ENOMEM;
1989 }
1990- if (!vma || addr + len <= vma->vm_start) {
1991+ if (check_heap_stack_gap(vma, addr, len)) {
1992 /*
1993 * Remember the place where we stopped the search:
1994 */
1995@@ -266,10 +269,22 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
1996
1997 if (mmap_is_legacy()) {
1998 mm->mmap_base = TASK_UNMAPPED_BASE + random_factor;
1999+
2000+#ifdef CONFIG_PAX_RANDMMAP
2001+ if (mm->pax_flags & MF_PAX_RANDMMAP)
2002+ mm->mmap_base += mm->delta_mmap;
2003+#endif
2004+
2005 mm->get_unmapped_area = arch_get_unmapped_area;
2006 mm->unmap_area = arch_unmap_area;
2007 } else {
2008 mm->mmap_base = mmap_base(random_factor);
2009+
2010+#ifdef CONFIG_PAX_RANDMMAP
2011+ if (mm->pax_flags & MF_PAX_RANDMMAP)
2012+ mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
2013+#endif
2014+
2015 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
2016 mm->unmap_area = arch_unmap_area_topdown;
2017 }
2018diff --git a/arch/arm/plat-orion/include/plat/addr-map.h b/arch/arm/plat-orion/include/plat/addr-map.h
2019index fd556f7..af2e7d2 100644
2020--- a/arch/arm/plat-orion/include/plat/addr-map.h
2021+++ b/arch/arm/plat-orion/include/plat/addr-map.h
2022@@ -26,7 +26,7 @@ struct orion_addr_map_cfg {
2023 value in bridge_virt_base */
2024 void __iomem *(*win_cfg_base) (const struct orion_addr_map_cfg *cfg,
2025 const int win);
2026-};
2027+} __no_const;
2028
2029 /*
2030 * Information needed to setup one address mapping.
2031diff --git a/arch/arm/plat-samsung/include/plat/dma-ops.h b/arch/arm/plat-samsung/include/plat/dma-ops.h
2032index f5144cd..71f6d1f 100644
2033--- a/arch/arm/plat-samsung/include/plat/dma-ops.h
2034+++ b/arch/arm/plat-samsung/include/plat/dma-ops.h
2035@@ -47,7 +47,7 @@ struct samsung_dma_ops {
2036 int (*started)(unsigned ch);
2037 int (*flush)(unsigned ch);
2038 int (*stop)(unsigned ch);
2039-};
2040+} __no_const;
2041
2042 extern void *samsung_dmadev_get_ops(void);
2043 extern void *s3c_dma_get_ops(void);
2044diff --git a/arch/arm/plat-samsung/include/plat/ehci.h b/arch/arm/plat-samsung/include/plat/ehci.h
2045index 5f28cae..3d23723 100644
2046--- a/arch/arm/plat-samsung/include/plat/ehci.h
2047+++ b/arch/arm/plat-samsung/include/plat/ehci.h
2048@@ -14,7 +14,7 @@
2049 struct s5p_ehci_platdata {
2050 int (*phy_init)(struct platform_device *pdev, int type);
2051 int (*phy_exit)(struct platform_device *pdev, int type);
2052-};
2053+} __no_const;
2054
2055 extern void s5p_ehci_set_platdata(struct s5p_ehci_platdata *pd);
2056
2057diff --git a/arch/avr32/include/asm/cache.h b/arch/avr32/include/asm/cache.h
2058index c3a58a1..78fbf54 100644
2059--- a/arch/avr32/include/asm/cache.h
2060+++ b/arch/avr32/include/asm/cache.h
2061@@ -1,8 +1,10 @@
2062 #ifndef __ASM_AVR32_CACHE_H
2063 #define __ASM_AVR32_CACHE_H
2064
2065+#include <linux/const.h>
2066+
2067 #define L1_CACHE_SHIFT 5
2068-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
2069+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
2070
2071 /*
2072 * Memory returned by kmalloc() may be used for DMA, so we must make
2073diff --git a/arch/avr32/include/asm/elf.h b/arch/avr32/include/asm/elf.h
2074index 3b3159b..425ea94 100644
2075--- a/arch/avr32/include/asm/elf.h
2076+++ b/arch/avr32/include/asm/elf.h
2077@@ -84,8 +84,14 @@ typedef struct user_fpu_struct elf_fpregset_t;
2078 the loader. We need to make sure that it is out of the way of the program
2079 that it will "exec", and that there is sufficient room for the brk. */
2080
2081-#define ELF_ET_DYN_BASE (2 * TASK_SIZE / 3)
2082+#define ELF_ET_DYN_BASE (TASK_SIZE / 3 * 2)
2083
2084+#ifdef CONFIG_PAX_ASLR
2085+#define PAX_ELF_ET_DYN_BASE 0x00001000UL
2086+
2087+#define PAX_DELTA_MMAP_LEN 15
2088+#define PAX_DELTA_STACK_LEN 15
2089+#endif
2090
2091 /* This yields a mask that user programs can use to figure out what
2092 instruction set this CPU supports. This could be done in user space,
2093diff --git a/arch/avr32/include/asm/kmap_types.h b/arch/avr32/include/asm/kmap_types.h
2094index 479330b..53717a8 100644
2095--- a/arch/avr32/include/asm/kmap_types.h
2096+++ b/arch/avr32/include/asm/kmap_types.h
2097@@ -2,9 +2,9 @@
2098 #define __ASM_AVR32_KMAP_TYPES_H
2099
2100 #ifdef CONFIG_DEBUG_HIGHMEM
2101-# define KM_TYPE_NR 29
2102+# define KM_TYPE_NR 30
2103 #else
2104-# define KM_TYPE_NR 14
2105+# define KM_TYPE_NR 15
2106 #endif
2107
2108 #endif /* __ASM_AVR32_KMAP_TYPES_H */
2109diff --git a/arch/avr32/mm/fault.c b/arch/avr32/mm/fault.c
2110index b92e609..b69c101 100644
2111--- a/arch/avr32/mm/fault.c
2112+++ b/arch/avr32/mm/fault.c
2113@@ -41,6 +41,23 @@ static inline int notify_page_fault(struct pt_regs *regs, int trap)
2114
2115 int exception_trace = 1;
2116
2117+#ifdef CONFIG_PAX_PAGEEXEC
2118+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
2119+{
2120+ unsigned long i;
2121+
2122+ printk(KERN_ERR "PAX: bytes at PC: ");
2123+ for (i = 0; i < 20; i++) {
2124+ unsigned char c;
2125+ if (get_user(c, (unsigned char *)pc+i))
2126+ printk(KERN_CONT "???????? ");
2127+ else
2128+ printk(KERN_CONT "%02x ", c);
2129+ }
2130+ printk("\n");
2131+}
2132+#endif
2133+
2134 /*
2135 * This routine handles page faults. It determines the address and the
2136 * problem, and then passes it off to one of the appropriate routines.
2137@@ -173,6 +190,16 @@ bad_area:
2138 up_read(&mm->mmap_sem);
2139
2140 if (user_mode(regs)) {
2141+
2142+#ifdef CONFIG_PAX_PAGEEXEC
2143+ if (mm->pax_flags & MF_PAX_PAGEEXEC) {
2144+ if (ecr == ECR_PROTECTION_X || ecr == ECR_TLB_MISS_X) {
2145+ pax_report_fault(regs, (void *)regs->pc, (void *)regs->sp);
2146+ do_group_exit(SIGKILL);
2147+ }
2148+ }
2149+#endif
2150+
2151 if (exception_trace && printk_ratelimit())
2152 printk("%s%s[%d]: segfault at %08lx pc %08lx "
2153 "sp %08lx ecr %lu\n",
2154diff --git a/arch/blackfin/include/asm/cache.h b/arch/blackfin/include/asm/cache.h
2155index 568885a..f8008df 100644
2156--- a/arch/blackfin/include/asm/cache.h
2157+++ b/arch/blackfin/include/asm/cache.h
2158@@ -7,6 +7,7 @@
2159 #ifndef __ARCH_BLACKFIN_CACHE_H
2160 #define __ARCH_BLACKFIN_CACHE_H
2161
2162+#include <linux/const.h>
2163 #include <linux/linkage.h> /* for asmlinkage */
2164
2165 /*
2166@@ -14,7 +15,7 @@
2167 * Blackfin loads 32 bytes for cache
2168 */
2169 #define L1_CACHE_SHIFT 5
2170-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
2171+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
2172 #define SMP_CACHE_BYTES L1_CACHE_BYTES
2173
2174 #define ARCH_DMA_MINALIGN L1_CACHE_BYTES
2175diff --git a/arch/cris/include/arch-v10/arch/cache.h b/arch/cris/include/arch-v10/arch/cache.h
2176index aea2718..3639a60 100644
2177--- a/arch/cris/include/arch-v10/arch/cache.h
2178+++ b/arch/cris/include/arch-v10/arch/cache.h
2179@@ -1,8 +1,9 @@
2180 #ifndef _ASM_ARCH_CACHE_H
2181 #define _ASM_ARCH_CACHE_H
2182
2183+#include <linux/const.h>
2184 /* Etrax 100LX have 32-byte cache-lines. */
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 #endif /* _ASM_ARCH_CACHE_H */
2190diff --git a/arch/cris/include/arch-v32/arch/cache.h b/arch/cris/include/arch-v32/arch/cache.h
2191index 7caf25d..ee65ac5 100644
2192--- a/arch/cris/include/arch-v32/arch/cache.h
2193+++ b/arch/cris/include/arch-v32/arch/cache.h
2194@@ -1,11 +1,12 @@
2195 #ifndef _ASM_CRIS_ARCH_CACHE_H
2196 #define _ASM_CRIS_ARCH_CACHE_H
2197
2198+#include <linux/const.h>
2199 #include <arch/hwregs/dma.h>
2200
2201 /* A cache-line is 32 bytes. */
2202-#define L1_CACHE_BYTES 32
2203 #define L1_CACHE_SHIFT 5
2204+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
2205
2206 #define __read_mostly __attribute__((__section__(".data..read_mostly")))
2207
2208diff --git a/arch/frv/include/asm/atomic.h b/arch/frv/include/asm/atomic.h
2209index b86329d..6709906 100644
2210--- a/arch/frv/include/asm/atomic.h
2211+++ b/arch/frv/include/asm/atomic.h
2212@@ -186,6 +186,16 @@ static inline void atomic64_dec(atomic64_t *v)
2213 #define atomic64_cmpxchg(v, old, new) (__cmpxchg_64(old, new, &(v)->counter))
2214 #define atomic64_xchg(v, new) (__xchg_64(new, &(v)->counter))
2215
2216+#define atomic64_read_unchecked(v) atomic64_read(v)
2217+#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
2218+#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
2219+#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
2220+#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
2221+#define atomic64_inc_unchecked(v) atomic64_inc(v)
2222+#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
2223+#define atomic64_dec_unchecked(v) atomic64_dec(v)
2224+#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
2225+
2226 static __inline__ int __atomic_add_unless(atomic_t *v, int a, int u)
2227 {
2228 int c, old;
2229diff --git a/arch/frv/include/asm/cache.h b/arch/frv/include/asm/cache.h
2230index 2797163..c2a401d 100644
2231--- a/arch/frv/include/asm/cache.h
2232+++ b/arch/frv/include/asm/cache.h
2233@@ -12,10 +12,11 @@
2234 #ifndef __ASM_CACHE_H
2235 #define __ASM_CACHE_H
2236
2237+#include <linux/const.h>
2238
2239 /* bytes per L1 cache line */
2240 #define L1_CACHE_SHIFT (CONFIG_FRV_L1_CACHE_SHIFT)
2241-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
2242+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
2243
2244 #define __cacheline_aligned __attribute__((aligned(L1_CACHE_BYTES)))
2245 #define ____cacheline_aligned __attribute__((aligned(L1_CACHE_BYTES)))
2246diff --git a/arch/frv/include/asm/kmap_types.h b/arch/frv/include/asm/kmap_types.h
2247index 43901f2..0d8b865 100644
2248--- a/arch/frv/include/asm/kmap_types.h
2249+++ b/arch/frv/include/asm/kmap_types.h
2250@@ -2,6 +2,6 @@
2251 #ifndef _ASM_KMAP_TYPES_H
2252 #define _ASM_KMAP_TYPES_H
2253
2254-#define KM_TYPE_NR 17
2255+#define KM_TYPE_NR 18
2256
2257 #endif
2258diff --git a/arch/frv/mm/elf-fdpic.c b/arch/frv/mm/elf-fdpic.c
2259index 385fd30..6c3d97e 100644
2260--- a/arch/frv/mm/elf-fdpic.c
2261+++ b/arch/frv/mm/elf-fdpic.c
2262@@ -73,8 +73,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
2263 if (addr) {
2264 addr = PAGE_ALIGN(addr);
2265 vma = find_vma(current->mm, addr);
2266- if (TASK_SIZE - len >= addr &&
2267- (!vma || addr + len <= vma->vm_start))
2268+ if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len))
2269 goto success;
2270 }
2271
2272@@ -89,7 +88,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
2273 for (; vma; vma = vma->vm_next) {
2274 if (addr > limit)
2275 break;
2276- if (addr + len <= vma->vm_start)
2277+ if (check_heap_stack_gap(vma, addr, len))
2278 goto success;
2279 addr = vma->vm_end;
2280 }
2281@@ -104,7 +103,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
2282 for (; vma; vma = vma->vm_next) {
2283 if (addr > limit)
2284 break;
2285- if (addr + len <= vma->vm_start)
2286+ if (check_heap_stack_gap(vma, addr, len))
2287 goto success;
2288 addr = vma->vm_end;
2289 }
2290diff --git a/arch/h8300/include/asm/cache.h b/arch/h8300/include/asm/cache.h
2291index c635028..6d9445a 100644
2292--- a/arch/h8300/include/asm/cache.h
2293+++ b/arch/h8300/include/asm/cache.h
2294@@ -1,8 +1,10 @@
2295 #ifndef __ARCH_H8300_CACHE_H
2296 #define __ARCH_H8300_CACHE_H
2297
2298+#include <linux/const.h>
2299+
2300 /* bytes per L1 cache line */
2301-#define L1_CACHE_BYTES 4
2302+#define L1_CACHE_BYTES _AC(4,UL)
2303
2304 /* m68k-elf-gcc 2.95.2 doesn't like these */
2305
2306diff --git a/arch/hexagon/include/asm/cache.h b/arch/hexagon/include/asm/cache.h
2307index 0f01de2..d37d309 100644
2308--- a/arch/hexagon/include/asm/cache.h
2309+++ b/arch/hexagon/include/asm/cache.h
2310@@ -21,9 +21,11 @@
2311 #ifndef __ASM_CACHE_H
2312 #define __ASM_CACHE_H
2313
2314+#include <linux/const.h>
2315+
2316 /* Bytes per L1 cache line */
2317-#define L1_CACHE_SHIFT (5)
2318-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
2319+#define L1_CACHE_SHIFT 5
2320+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
2321
2322 #define __cacheline_aligned __aligned(L1_CACHE_BYTES)
2323 #define ____cacheline_aligned __aligned(L1_CACHE_BYTES)
2324diff --git a/arch/ia64/include/asm/atomic.h b/arch/ia64/include/asm/atomic.h
2325index 6e6fe18..a6ae668 100644
2326--- a/arch/ia64/include/asm/atomic.h
2327+++ b/arch/ia64/include/asm/atomic.h
2328@@ -208,6 +208,16 @@ atomic64_add_negative (__s64 i, atomic64_t *v)
2329 #define atomic64_inc(v) atomic64_add(1, (v))
2330 #define atomic64_dec(v) atomic64_sub(1, (v))
2331
2332+#define atomic64_read_unchecked(v) atomic64_read(v)
2333+#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
2334+#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
2335+#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
2336+#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
2337+#define atomic64_inc_unchecked(v) atomic64_inc(v)
2338+#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
2339+#define atomic64_dec_unchecked(v) atomic64_dec(v)
2340+#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
2341+
2342 /* Atomic operations are already serializing */
2343 #define smp_mb__before_atomic_dec() barrier()
2344 #define smp_mb__after_atomic_dec() barrier()
2345diff --git a/arch/ia64/include/asm/cache.h b/arch/ia64/include/asm/cache.h
2346index 988254a..e1ee885 100644
2347--- a/arch/ia64/include/asm/cache.h
2348+++ b/arch/ia64/include/asm/cache.h
2349@@ -1,6 +1,7 @@
2350 #ifndef _ASM_IA64_CACHE_H
2351 #define _ASM_IA64_CACHE_H
2352
2353+#include <linux/const.h>
2354
2355 /*
2356 * Copyright (C) 1998-2000 Hewlett-Packard Co
2357@@ -9,7 +10,7 @@
2358
2359 /* Bytes per L1 (data) cache line. */
2360 #define L1_CACHE_SHIFT CONFIG_IA64_L1_CACHE_SHIFT
2361-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
2362+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
2363
2364 #ifdef CONFIG_SMP
2365 # define SMP_CACHE_SHIFT L1_CACHE_SHIFT
2366diff --git a/arch/ia64/include/asm/elf.h b/arch/ia64/include/asm/elf.h
2367index b5298eb..67c6e62 100644
2368--- a/arch/ia64/include/asm/elf.h
2369+++ b/arch/ia64/include/asm/elf.h
2370@@ -42,6 +42,13 @@
2371 */
2372 #define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE + 0x800000000UL)
2373
2374+#ifdef CONFIG_PAX_ASLR
2375+#define PAX_ELF_ET_DYN_BASE (current->personality == PER_LINUX32 ? 0x08048000UL : 0x4000000000000000UL)
2376+
2377+#define PAX_DELTA_MMAP_LEN (current->personality == PER_LINUX32 ? 16 : 3*PAGE_SHIFT - 13)
2378+#define PAX_DELTA_STACK_LEN (current->personality == PER_LINUX32 ? 16 : 3*PAGE_SHIFT - 13)
2379+#endif
2380+
2381 #define PT_IA_64_UNWIND 0x70000001
2382
2383 /* IA-64 relocations: */
2384diff --git a/arch/ia64/include/asm/pgalloc.h b/arch/ia64/include/asm/pgalloc.h
2385index 96a8d92..617a1cf 100644
2386--- a/arch/ia64/include/asm/pgalloc.h
2387+++ b/arch/ia64/include/asm/pgalloc.h
2388@@ -39,6 +39,12 @@ pgd_populate(struct mm_struct *mm, pgd_t * pgd_entry, pud_t * pud)
2389 pgd_val(*pgd_entry) = __pa(pud);
2390 }
2391
2392+static inline void
2393+pgd_populate_kernel(struct mm_struct *mm, pgd_t * pgd_entry, pud_t * pud)
2394+{
2395+ pgd_populate(mm, pgd_entry, pud);
2396+}
2397+
2398 static inline pud_t *pud_alloc_one(struct mm_struct *mm, unsigned long addr)
2399 {
2400 return quicklist_alloc(0, GFP_KERNEL, NULL);
2401@@ -57,6 +63,12 @@ pud_populate(struct mm_struct *mm, pud_t * pud_entry, pmd_t * pmd)
2402 pud_val(*pud_entry) = __pa(pmd);
2403 }
2404
2405+static inline void
2406+pud_populate_kernel(struct mm_struct *mm, pud_t * pud_entry, pmd_t * pmd)
2407+{
2408+ pud_populate(mm, pud_entry, pmd);
2409+}
2410+
2411 static inline pmd_t *pmd_alloc_one(struct mm_struct *mm, unsigned long addr)
2412 {
2413 return quicklist_alloc(0, GFP_KERNEL, NULL);
2414diff --git a/arch/ia64/include/asm/pgtable.h b/arch/ia64/include/asm/pgtable.h
2415index 815810c..d60bd4c 100644
2416--- a/arch/ia64/include/asm/pgtable.h
2417+++ b/arch/ia64/include/asm/pgtable.h
2418@@ -12,7 +12,7 @@
2419 * David Mosberger-Tang <davidm@hpl.hp.com>
2420 */
2421
2422-
2423+#include <linux/const.h>
2424 #include <asm/mman.h>
2425 #include <asm/page.h>
2426 #include <asm/processor.h>
2427@@ -142,6 +142,17 @@
2428 #define PAGE_READONLY __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_R)
2429 #define PAGE_COPY __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_R)
2430 #define PAGE_COPY_EXEC __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_RX)
2431+
2432+#ifdef CONFIG_PAX_PAGEEXEC
2433+# define PAGE_SHARED_NOEXEC __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_RW)
2434+# define PAGE_READONLY_NOEXEC __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_R)
2435+# define PAGE_COPY_NOEXEC __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_R)
2436+#else
2437+# define PAGE_SHARED_NOEXEC PAGE_SHARED
2438+# define PAGE_READONLY_NOEXEC PAGE_READONLY
2439+# define PAGE_COPY_NOEXEC PAGE_COPY
2440+#endif
2441+
2442 #define PAGE_GATE __pgprot(__ACCESS_BITS | _PAGE_PL_0 | _PAGE_AR_X_RX)
2443 #define PAGE_KERNEL __pgprot(__DIRTY_BITS | _PAGE_PL_0 | _PAGE_AR_RWX)
2444 #define PAGE_KERNELRX __pgprot(__ACCESS_BITS | _PAGE_PL_0 | _PAGE_AR_RX)
2445diff --git a/arch/ia64/include/asm/spinlock.h b/arch/ia64/include/asm/spinlock.h
2446index 54ff557..70c88b7 100644
2447--- a/arch/ia64/include/asm/spinlock.h
2448+++ b/arch/ia64/include/asm/spinlock.h
2449@@ -71,7 +71,7 @@ static __always_inline void __ticket_spin_unlock(arch_spinlock_t *lock)
2450 unsigned short *p = (unsigned short *)&lock->lock + 1, tmp;
2451
2452 asm volatile ("ld2.bias %0=[%1]" : "=r"(tmp) : "r"(p));
2453- ACCESS_ONCE(*p) = (tmp + 2) & ~1;
2454+ ACCESS_ONCE_RW(*p) = (tmp + 2) & ~1;
2455 }
2456
2457 static __always_inline void __ticket_spin_unlock_wait(arch_spinlock_t *lock)
2458diff --git a/arch/ia64/include/asm/uaccess.h b/arch/ia64/include/asm/uaccess.h
2459index 449c8c0..432a3d2 100644
2460--- a/arch/ia64/include/asm/uaccess.h
2461+++ b/arch/ia64/include/asm/uaccess.h
2462@@ -257,7 +257,7 @@ __copy_from_user (void *to, const void __user *from, unsigned long count)
2463 const void *__cu_from = (from); \
2464 long __cu_len = (n); \
2465 \
2466- if (__access_ok(__cu_to, __cu_len, get_fs())) \
2467+ if (__cu_len > 0 && __cu_len <= INT_MAX && __access_ok(__cu_to, __cu_len, get_fs())) \
2468 __cu_len = __copy_user(__cu_to, (__force void __user *) __cu_from, __cu_len); \
2469 __cu_len; \
2470 })
2471@@ -269,7 +269,7 @@ __copy_from_user (void *to, const void __user *from, unsigned long count)
2472 long __cu_len = (n); \
2473 \
2474 __chk_user_ptr(__cu_from); \
2475- if (__access_ok(__cu_from, __cu_len, get_fs())) \
2476+ if (__cu_len > 0 && __cu_len <= INT_MAX && __access_ok(__cu_from, __cu_len, get_fs())) \
2477 __cu_len = __copy_user((__force void __user *) __cu_to, __cu_from, __cu_len); \
2478 __cu_len; \
2479 })
2480diff --git a/arch/ia64/kernel/module.c b/arch/ia64/kernel/module.c
2481index 24603be..948052d 100644
2482--- a/arch/ia64/kernel/module.c
2483+++ b/arch/ia64/kernel/module.c
2484@@ -307,8 +307,7 @@ plt_target (struct plt_entry *plt)
2485 void
2486 module_free (struct module *mod, void *module_region)
2487 {
2488- if (mod && mod->arch.init_unw_table &&
2489- module_region == mod->module_init) {
2490+ if (mod && mod->arch.init_unw_table && module_region == mod->module_init_rx) {
2491 unw_remove_unwind_table(mod->arch.init_unw_table);
2492 mod->arch.init_unw_table = NULL;
2493 }
2494@@ -494,15 +493,39 @@ module_frob_arch_sections (Elf_Ehdr *ehdr, Elf_Shdr *sechdrs, char *secstrings,
2495 }
2496
2497 static inline int
2498+in_init_rx (const struct module *mod, uint64_t addr)
2499+{
2500+ return addr - (uint64_t) mod->module_init_rx < mod->init_size_rx;
2501+}
2502+
2503+static inline int
2504+in_init_rw (const struct module *mod, uint64_t addr)
2505+{
2506+ return addr - (uint64_t) mod->module_init_rw < mod->init_size_rw;
2507+}
2508+
2509+static inline int
2510 in_init (const struct module *mod, uint64_t addr)
2511 {
2512- return addr - (uint64_t) mod->module_init < mod->init_size;
2513+ return in_init_rx(mod, addr) || in_init_rw(mod, addr);
2514+}
2515+
2516+static inline int
2517+in_core_rx (const struct module *mod, uint64_t addr)
2518+{
2519+ return addr - (uint64_t) mod->module_core_rx < mod->core_size_rx;
2520+}
2521+
2522+static inline int
2523+in_core_rw (const struct module *mod, uint64_t addr)
2524+{
2525+ return addr - (uint64_t) mod->module_core_rw < mod->core_size_rw;
2526 }
2527
2528 static inline int
2529 in_core (const struct module *mod, uint64_t addr)
2530 {
2531- return addr - (uint64_t) mod->module_core < mod->core_size;
2532+ return in_core_rx(mod, addr) || in_core_rw(mod, addr);
2533 }
2534
2535 static inline int
2536@@ -685,7 +708,14 @@ do_reloc (struct module *mod, uint8_t r_type, Elf64_Sym *sym, uint64_t addend,
2537 break;
2538
2539 case RV_BDREL:
2540- val -= (uint64_t) (in_init(mod, val) ? mod->module_init : mod->module_core);
2541+ if (in_init_rx(mod, val))
2542+ val -= (uint64_t) mod->module_init_rx;
2543+ else if (in_init_rw(mod, val))
2544+ val -= (uint64_t) mod->module_init_rw;
2545+ else if (in_core_rx(mod, val))
2546+ val -= (uint64_t) mod->module_core_rx;
2547+ else if (in_core_rw(mod, val))
2548+ val -= (uint64_t) mod->module_core_rw;
2549 break;
2550
2551 case RV_LTV:
2552@@ -820,15 +850,15 @@ apply_relocate_add (Elf64_Shdr *sechdrs, const char *strtab, unsigned int symind
2553 * addresses have been selected...
2554 */
2555 uint64_t gp;
2556- if (mod->core_size > MAX_LTOFF)
2557+ if (mod->core_size_rx + mod->core_size_rw > MAX_LTOFF)
2558 /*
2559 * This takes advantage of fact that SHF_ARCH_SMALL gets allocated
2560 * at the end of the module.
2561 */
2562- gp = mod->core_size - MAX_LTOFF / 2;
2563+ gp = mod->core_size_rx + mod->core_size_rw - MAX_LTOFF / 2;
2564 else
2565- gp = mod->core_size / 2;
2566- gp = (uint64_t) mod->module_core + ((gp + 7) & -8);
2567+ gp = (mod->core_size_rx + mod->core_size_rw) / 2;
2568+ gp = (uint64_t) mod->module_core_rx + ((gp + 7) & -8);
2569 mod->arch.gp = gp;
2570 DEBUGP("%s: placing gp at 0x%lx\n", __func__, gp);
2571 }
2572diff --git a/arch/ia64/kernel/sys_ia64.c b/arch/ia64/kernel/sys_ia64.c
2573index d9439ef..b9a4303 100644
2574--- a/arch/ia64/kernel/sys_ia64.c
2575+++ b/arch/ia64/kernel/sys_ia64.c
2576@@ -43,6 +43,13 @@ arch_get_unmapped_area (struct file *filp, unsigned long addr, unsigned long len
2577 if (REGION_NUMBER(addr) == RGN_HPAGE)
2578 addr = 0;
2579 #endif
2580+
2581+#ifdef CONFIG_PAX_RANDMMAP
2582+ if (mm->pax_flags & MF_PAX_RANDMMAP)
2583+ addr = mm->free_area_cache;
2584+ else
2585+#endif
2586+
2587 if (!addr)
2588 addr = mm->free_area_cache;
2589
2590@@ -61,14 +68,14 @@ arch_get_unmapped_area (struct file *filp, unsigned long addr, unsigned long len
2591 for (vma = find_vma(mm, addr); ; vma = vma->vm_next) {
2592 /* At this point: (!vma || addr < vma->vm_end). */
2593 if (TASK_SIZE - len < addr || RGN_MAP_LIMIT - len < REGION_OFFSET(addr)) {
2594- if (start_addr != TASK_UNMAPPED_BASE) {
2595+ if (start_addr != mm->mmap_base) {
2596 /* Start a new search --- just in case we missed some holes. */
2597- addr = TASK_UNMAPPED_BASE;
2598+ addr = mm->mmap_base;
2599 goto full_search;
2600 }
2601 return -ENOMEM;
2602 }
2603- if (!vma || addr + len <= vma->vm_start) {
2604+ if (check_heap_stack_gap(vma, addr, len)) {
2605 /* Remember the address where we stopped this search: */
2606 mm->free_area_cache = addr + len;
2607 return addr;
2608diff --git a/arch/ia64/kernel/vmlinux.lds.S b/arch/ia64/kernel/vmlinux.lds.S
2609index 0ccb28f..8992469 100644
2610--- a/arch/ia64/kernel/vmlinux.lds.S
2611+++ b/arch/ia64/kernel/vmlinux.lds.S
2612@@ -198,7 +198,7 @@ SECTIONS {
2613 /* Per-cpu data: */
2614 . = ALIGN(PERCPU_PAGE_SIZE);
2615 PERCPU_VADDR(SMP_CACHE_BYTES, PERCPU_ADDR, :percpu)
2616- __phys_per_cpu_start = __per_cpu_load;
2617+ __phys_per_cpu_start = per_cpu_load;
2618 /*
2619 * ensure percpu data fits
2620 * into percpu page size
2621diff --git a/arch/ia64/mm/fault.c b/arch/ia64/mm/fault.c
2622index 8443daf..0a01e30 100644
2623--- a/arch/ia64/mm/fault.c
2624+++ b/arch/ia64/mm/fault.c
2625@@ -72,6 +72,23 @@ mapped_kernel_page_is_present (unsigned long address)
2626 return pte_present(pte);
2627 }
2628
2629+#ifdef CONFIG_PAX_PAGEEXEC
2630+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
2631+{
2632+ unsigned long i;
2633+
2634+ printk(KERN_ERR "PAX: bytes at PC: ");
2635+ for (i = 0; i < 8; i++) {
2636+ unsigned int c;
2637+ if (get_user(c, (unsigned int *)pc+i))
2638+ printk(KERN_CONT "???????? ");
2639+ else
2640+ printk(KERN_CONT "%08x ", c);
2641+ }
2642+ printk("\n");
2643+}
2644+#endif
2645+
2646 # define VM_READ_BIT 0
2647 # define VM_WRITE_BIT 1
2648 # define VM_EXEC_BIT 2
2649@@ -149,8 +166,21 @@ retry:
2650 if (((isr >> IA64_ISR_R_BIT) & 1UL) && (!(vma->vm_flags & (VM_READ | VM_WRITE))))
2651 goto bad_area;
2652
2653- if ((vma->vm_flags & mask) != mask)
2654+ if ((vma->vm_flags & mask) != mask) {
2655+
2656+#ifdef CONFIG_PAX_PAGEEXEC
2657+ if (!(vma->vm_flags & VM_EXEC) && (mask & VM_EXEC)) {
2658+ if (!(mm->pax_flags & MF_PAX_PAGEEXEC) || address != regs->cr_iip)
2659+ goto bad_area;
2660+
2661+ up_read(&mm->mmap_sem);
2662+ pax_report_fault(regs, (void *)regs->cr_iip, (void *)regs->r12);
2663+ do_group_exit(SIGKILL);
2664+ }
2665+#endif
2666+
2667 goto bad_area;
2668+ }
2669
2670 /*
2671 * If for any reason at all we couldn't handle the fault, make
2672diff --git a/arch/ia64/mm/hugetlbpage.c b/arch/ia64/mm/hugetlbpage.c
2673index 5ca674b..e0e1b70 100644
2674--- a/arch/ia64/mm/hugetlbpage.c
2675+++ b/arch/ia64/mm/hugetlbpage.c
2676@@ -171,7 +171,7 @@ unsigned long hugetlb_get_unmapped_area(struct file *file, unsigned long addr, u
2677 /* At this point: (!vmm || addr < vmm->vm_end). */
2678 if (REGION_OFFSET(addr) + len > RGN_MAP_LIMIT)
2679 return -ENOMEM;
2680- if (!vmm || (addr + len) <= vmm->vm_start)
2681+ if (check_heap_stack_gap(vmm, addr, len))
2682 return addr;
2683 addr = ALIGN(vmm->vm_end, HPAGE_SIZE);
2684 }
2685diff --git a/arch/ia64/mm/init.c b/arch/ia64/mm/init.c
2686index 0eab454..bd794f2 100644
2687--- a/arch/ia64/mm/init.c
2688+++ b/arch/ia64/mm/init.c
2689@@ -120,6 +120,19 @@ ia64_init_addr_space (void)
2690 vma->vm_start = current->thread.rbs_bot & PAGE_MASK;
2691 vma->vm_end = vma->vm_start + PAGE_SIZE;
2692 vma->vm_flags = VM_DATA_DEFAULT_FLAGS|VM_GROWSUP|VM_ACCOUNT;
2693+
2694+#ifdef CONFIG_PAX_PAGEEXEC
2695+ if (current->mm->pax_flags & MF_PAX_PAGEEXEC) {
2696+ vma->vm_flags &= ~VM_EXEC;
2697+
2698+#ifdef CONFIG_PAX_MPROTECT
2699+ if (current->mm->pax_flags & MF_PAX_MPROTECT)
2700+ vma->vm_flags &= ~VM_MAYEXEC;
2701+#endif
2702+
2703+ }
2704+#endif
2705+
2706 vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
2707 down_write(&current->mm->mmap_sem);
2708 if (insert_vm_struct(current->mm, vma)) {
2709diff --git a/arch/m32r/include/asm/cache.h b/arch/m32r/include/asm/cache.h
2710index 40b3ee9..8c2c112 100644
2711--- a/arch/m32r/include/asm/cache.h
2712+++ b/arch/m32r/include/asm/cache.h
2713@@ -1,8 +1,10 @@
2714 #ifndef _ASM_M32R_CACHE_H
2715 #define _ASM_M32R_CACHE_H
2716
2717+#include <linux/const.h>
2718+
2719 /* L1 cache line size */
2720 #define L1_CACHE_SHIFT 4
2721-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
2722+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
2723
2724 #endif /* _ASM_M32R_CACHE_H */
2725diff --git a/arch/m32r/lib/usercopy.c b/arch/m32r/lib/usercopy.c
2726index 82abd15..d95ae5d 100644
2727--- a/arch/m32r/lib/usercopy.c
2728+++ b/arch/m32r/lib/usercopy.c
2729@@ -14,6 +14,9 @@
2730 unsigned long
2731 __generic_copy_to_user(void __user *to, const void *from, unsigned long n)
2732 {
2733+ if ((long)n < 0)
2734+ return n;
2735+
2736 prefetch(from);
2737 if (access_ok(VERIFY_WRITE, to, n))
2738 __copy_user(to,from,n);
2739@@ -23,6 +26,9 @@ __generic_copy_to_user(void __user *to, const void *from, unsigned long n)
2740 unsigned long
2741 __generic_copy_from_user(void *to, const void __user *from, unsigned long n)
2742 {
2743+ if ((long)n < 0)
2744+ return n;
2745+
2746 prefetchw(to);
2747 if (access_ok(VERIFY_READ, from, n))
2748 __copy_user_zeroing(to,from,n);
2749diff --git a/arch/m68k/include/asm/cache.h b/arch/m68k/include/asm/cache.h
2750index 0395c51..5f26031 100644
2751--- a/arch/m68k/include/asm/cache.h
2752+++ b/arch/m68k/include/asm/cache.h
2753@@ -4,9 +4,11 @@
2754 #ifndef __ARCH_M68K_CACHE_H
2755 #define __ARCH_M68K_CACHE_H
2756
2757+#include <linux/const.h>
2758+
2759 /* bytes per L1 cache line */
2760 #define L1_CACHE_SHIFT 4
2761-#define L1_CACHE_BYTES (1<< L1_CACHE_SHIFT)
2762+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
2763
2764 #define ARCH_DMA_MINALIGN L1_CACHE_BYTES
2765
2766diff --git a/arch/microblaze/include/asm/cache.h b/arch/microblaze/include/asm/cache.h
2767index 4efe96a..60e8699 100644
2768--- a/arch/microblaze/include/asm/cache.h
2769+++ b/arch/microblaze/include/asm/cache.h
2770@@ -13,11 +13,12 @@
2771 #ifndef _ASM_MICROBLAZE_CACHE_H
2772 #define _ASM_MICROBLAZE_CACHE_H
2773
2774+#include <linux/const.h>
2775 #include <asm/registers.h>
2776
2777 #define L1_CACHE_SHIFT 5
2778 /* word-granular cache in microblaze */
2779-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
2780+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
2781
2782 #define SMP_CACHE_BYTES L1_CACHE_BYTES
2783
2784diff --git a/arch/mips/include/asm/atomic.h b/arch/mips/include/asm/atomic.h
2785index 3f4c5cb..3439c6e 100644
2786--- a/arch/mips/include/asm/atomic.h
2787+++ b/arch/mips/include/asm/atomic.h
2788@@ -21,6 +21,10 @@
2789 #include <asm/cmpxchg.h>
2790 #include <asm/war.h>
2791
2792+#ifdef CONFIG_GENERIC_ATOMIC64
2793+#include <asm-generic/atomic64.h>
2794+#endif
2795+
2796 #define ATOMIC_INIT(i) { (i) }
2797
2798 /*
2799@@ -765,6 +769,16 @@ static __inline__ int atomic64_add_unless(atomic64_t *v, long a, long u)
2800 */
2801 #define atomic64_add_negative(i, v) (atomic64_add_return(i, (v)) < 0)
2802
2803+#define atomic64_read_unchecked(v) atomic64_read(v)
2804+#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
2805+#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
2806+#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
2807+#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
2808+#define atomic64_inc_unchecked(v) atomic64_inc(v)
2809+#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
2810+#define atomic64_dec_unchecked(v) atomic64_dec(v)
2811+#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
2812+
2813 #endif /* CONFIG_64BIT */
2814
2815 /*
2816diff --git a/arch/mips/include/asm/cache.h b/arch/mips/include/asm/cache.h
2817index b4db69f..8f3b093 100644
2818--- a/arch/mips/include/asm/cache.h
2819+++ b/arch/mips/include/asm/cache.h
2820@@ -9,10 +9,11 @@
2821 #ifndef _ASM_CACHE_H
2822 #define _ASM_CACHE_H
2823
2824+#include <linux/const.h>
2825 #include <kmalloc.h>
2826
2827 #define L1_CACHE_SHIFT CONFIG_MIPS_L1_CACHE_SHIFT
2828-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
2829+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
2830
2831 #define SMP_CACHE_SHIFT L1_CACHE_SHIFT
2832 #define SMP_CACHE_BYTES L1_CACHE_BYTES
2833diff --git a/arch/mips/include/asm/elf.h b/arch/mips/include/asm/elf.h
2834index 455c0ac..ad65fbe 100644
2835--- a/arch/mips/include/asm/elf.h
2836+++ b/arch/mips/include/asm/elf.h
2837@@ -372,13 +372,16 @@ extern const char *__elf_platform;
2838 #define ELF_ET_DYN_BASE (TASK_SIZE / 3 * 2)
2839 #endif
2840
2841+#ifdef CONFIG_PAX_ASLR
2842+#define PAX_ELF_ET_DYN_BASE (TASK_IS_32BIT_ADDR ? 0x00400000UL : 0x00400000UL)
2843+
2844+#define PAX_DELTA_MMAP_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
2845+#define PAX_DELTA_STACK_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
2846+#endif
2847+
2848 #define ARCH_HAS_SETUP_ADDITIONAL_PAGES 1
2849 struct linux_binprm;
2850 extern int arch_setup_additional_pages(struct linux_binprm *bprm,
2851 int uses_interp);
2852
2853-struct mm_struct;
2854-extern unsigned long arch_randomize_brk(struct mm_struct *mm);
2855-#define arch_randomize_brk arch_randomize_brk
2856-
2857 #endif /* _ASM_ELF_H */
2858diff --git a/arch/mips/include/asm/exec.h b/arch/mips/include/asm/exec.h
2859index c1f6afa..38cc6e9 100644
2860--- a/arch/mips/include/asm/exec.h
2861+++ b/arch/mips/include/asm/exec.h
2862@@ -12,6 +12,6 @@
2863 #ifndef _ASM_EXEC_H
2864 #define _ASM_EXEC_H
2865
2866-extern unsigned long arch_align_stack(unsigned long sp);
2867+#define arch_align_stack(x) ((x) & ~0xfUL)
2868
2869 #endif /* _ASM_EXEC_H */
2870diff --git a/arch/mips/include/asm/page.h b/arch/mips/include/asm/page.h
2871index da9bd7d..91aa7ab 100644
2872--- a/arch/mips/include/asm/page.h
2873+++ b/arch/mips/include/asm/page.h
2874@@ -98,7 +98,7 @@ extern void copy_user_highpage(struct page *to, struct page *from,
2875 #ifdef CONFIG_CPU_MIPS32
2876 typedef struct { unsigned long pte_low, pte_high; } pte_t;
2877 #define pte_val(x) ((x).pte_low | ((unsigned long long)(x).pte_high << 32))
2878- #define __pte(x) ({ pte_t __pte = {(x), ((unsigned long long)(x)) >> 32}; __pte; })
2879+ #define __pte(x) ({ pte_t __pte = {(x), (x) >> 32}; __pte; })
2880 #else
2881 typedef struct { unsigned long long pte; } pte_t;
2882 #define pte_val(x) ((x).pte)
2883diff --git a/arch/mips/include/asm/pgalloc.h b/arch/mips/include/asm/pgalloc.h
2884index 881d18b..cea38bc 100644
2885--- a/arch/mips/include/asm/pgalloc.h
2886+++ b/arch/mips/include/asm/pgalloc.h
2887@@ -37,6 +37,11 @@ static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
2888 {
2889 set_pud(pud, __pud((unsigned long)pmd));
2890 }
2891+
2892+static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
2893+{
2894+ pud_populate(mm, pud, pmd);
2895+}
2896 #endif
2897
2898 /*
2899diff --git a/arch/mips/include/asm/thread_info.h b/arch/mips/include/asm/thread_info.h
2900index ca97e0e..cd08920 100644
2901--- a/arch/mips/include/asm/thread_info.h
2902+++ b/arch/mips/include/asm/thread_info.h
2903@@ -111,6 +111,8 @@ register struct thread_info *__current_thread_info __asm__("$28");
2904 #define TIF_32BIT_ADDR 23 /* 32-bit address space (o32/n32) */
2905 #define TIF_FPUBOUND 24 /* thread bound to FPU-full CPU set */
2906 #define TIF_LOAD_WATCH 25 /* If set, load watch registers */
2907+/* li takes a 32bit immediate */
2908+#define TIF_GRSEC_SETXID 29 /* update credentials on syscall entry/exit */
2909 #define TIF_SYSCALL_TRACE 31 /* syscall trace active */
2910
2911 #ifdef CONFIG_MIPS32_O32
2912@@ -134,15 +136,18 @@ register struct thread_info *__current_thread_info __asm__("$28");
2913 #define _TIF_32BIT_ADDR (1<<TIF_32BIT_ADDR)
2914 #define _TIF_FPUBOUND (1<<TIF_FPUBOUND)
2915 #define _TIF_LOAD_WATCH (1<<TIF_LOAD_WATCH)
2916+#define _TIF_GRSEC_SETXID (1<<TIF_GRSEC_SETXID)
2917+
2918+#define _TIF_SYSCALL_WORK (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | _TIF_GRSEC_SETXID)
2919
2920 /* work to do in syscall_trace_leave() */
2921-#define _TIF_WORK_SYSCALL_EXIT (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT)
2922+#define _TIF_WORK_SYSCALL_EXIT (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | _TIF_GRSEC_SETXID)
2923
2924 /* work to do on interrupt/exception return */
2925 #define _TIF_WORK_MASK (0x0000ffef & \
2926 ~(_TIF_SECCOMP | _TIF_SYSCALL_AUDIT))
2927 /* work to do on any return to u-space */
2928-#define _TIF_ALLWORK_MASK (0x8000ffff & ~_TIF_SECCOMP)
2929+#define _TIF_ALLWORK_MASK ((0x8000ffff & ~_TIF_SECCOMP) | _TIF_GRSEC_SETXID)
2930
2931 #endif /* __KERNEL__ */
2932
2933diff --git a/arch/mips/kernel/binfmt_elfn32.c b/arch/mips/kernel/binfmt_elfn32.c
2934index 9fdd8bc..4bd7f1a 100644
2935--- a/arch/mips/kernel/binfmt_elfn32.c
2936+++ b/arch/mips/kernel/binfmt_elfn32.c
2937@@ -50,6 +50,13 @@ typedef elf_fpreg_t elf_fpregset_t[ELF_NFPREG];
2938 #undef ELF_ET_DYN_BASE
2939 #define ELF_ET_DYN_BASE (TASK32_SIZE / 3 * 2)
2940
2941+#ifdef CONFIG_PAX_ASLR
2942+#define PAX_ELF_ET_DYN_BASE (TASK_IS_32BIT_ADDR ? 0x00400000UL : 0x00400000UL)
2943+
2944+#define PAX_DELTA_MMAP_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
2945+#define PAX_DELTA_STACK_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
2946+#endif
2947+
2948 #include <asm/processor.h>
2949 #include <linux/module.h>
2950 #include <linux/elfcore.h>
2951diff --git a/arch/mips/kernel/binfmt_elfo32.c b/arch/mips/kernel/binfmt_elfo32.c
2952index ff44823..97f8906 100644
2953--- a/arch/mips/kernel/binfmt_elfo32.c
2954+++ b/arch/mips/kernel/binfmt_elfo32.c
2955@@ -52,6 +52,13 @@ typedef elf_fpreg_t elf_fpregset_t[ELF_NFPREG];
2956 #undef ELF_ET_DYN_BASE
2957 #define ELF_ET_DYN_BASE (TASK32_SIZE / 3 * 2)
2958
2959+#ifdef CONFIG_PAX_ASLR
2960+#define PAX_ELF_ET_DYN_BASE (TASK_IS_32BIT_ADDR ? 0x00400000UL : 0x00400000UL)
2961+
2962+#define PAX_DELTA_MMAP_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
2963+#define PAX_DELTA_STACK_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
2964+#endif
2965+
2966 #include <asm/processor.h>
2967
2968 /*
2969diff --git a/arch/mips/kernel/process.c b/arch/mips/kernel/process.c
2970index e9a5fd7..378809a 100644
2971--- a/arch/mips/kernel/process.c
2972+++ b/arch/mips/kernel/process.c
2973@@ -480,15 +480,3 @@ unsigned long get_wchan(struct task_struct *task)
2974 out:
2975 return pc;
2976 }
2977-
2978-/*
2979- * Don't forget that the stack pointer must be aligned on a 8 bytes
2980- * boundary for 32-bits ABI and 16 bytes for 64-bits ABI.
2981- */
2982-unsigned long arch_align_stack(unsigned long sp)
2983-{
2984- if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
2985- sp -= get_random_int() & ~PAGE_MASK;
2986-
2987- return sp & ALMASK;
2988-}
2989diff --git a/arch/mips/kernel/ptrace.c b/arch/mips/kernel/ptrace.c
2990index 4812c6d..2069554 100644
2991--- a/arch/mips/kernel/ptrace.c
2992+++ b/arch/mips/kernel/ptrace.c
2993@@ -528,6 +528,10 @@ static inline int audit_arch(void)
2994 return arch;
2995 }
2996
2997+#ifdef CONFIG_GRKERNSEC_SETXID
2998+extern void gr_delayed_cred_worker(void);
2999+#endif
3000+
3001 /*
3002 * Notification of system call entry/exit
3003 * - triggered by current->work.syscall_trace
3004@@ -537,6 +541,11 @@ asmlinkage void syscall_trace_enter(struct pt_regs *regs)
3005 /* do the secure computing check first */
3006 secure_computing_strict(regs->regs[2]);
3007
3008+#ifdef CONFIG_GRKERNSEC_SETXID
3009+ if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
3010+ gr_delayed_cred_worker();
3011+#endif
3012+
3013 if (!(current->ptrace & PT_PTRACED))
3014 goto out;
3015
3016diff --git a/arch/mips/kernel/scall32-o32.S b/arch/mips/kernel/scall32-o32.S
3017index a632bc1..0b77c7c 100644
3018--- a/arch/mips/kernel/scall32-o32.S
3019+++ b/arch/mips/kernel/scall32-o32.S
3020@@ -52,7 +52,7 @@ NESTED(handle_sys, PT_SIZE, sp)
3021
3022 stack_done:
3023 lw t0, TI_FLAGS($28) # syscall tracing enabled?
3024- li t1, _TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT
3025+ li t1, _TIF_SYSCALL_WORK
3026 and t0, t1
3027 bnez t0, syscall_trace_entry # -> yes
3028
3029diff --git a/arch/mips/kernel/scall64-64.S b/arch/mips/kernel/scall64-64.S
3030index 3b5a5e9..e1ee86d 100644
3031--- a/arch/mips/kernel/scall64-64.S
3032+++ b/arch/mips/kernel/scall64-64.S
3033@@ -54,7 +54,7 @@ NESTED(handle_sys64, PT_SIZE, sp)
3034
3035 sd a3, PT_R26(sp) # save a3 for syscall restarting
3036
3037- li t1, _TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT
3038+ li t1, _TIF_SYSCALL_WORK
3039 LONG_L t0, TI_FLAGS($28) # syscall tracing enabled?
3040 and t0, t1, t0
3041 bnez t0, syscall_trace_entry
3042diff --git a/arch/mips/kernel/scall64-n32.S b/arch/mips/kernel/scall64-n32.S
3043index 6be6f70..1859577 100644
3044--- a/arch/mips/kernel/scall64-n32.S
3045+++ b/arch/mips/kernel/scall64-n32.S
3046@@ -53,7 +53,7 @@ NESTED(handle_sysn32, PT_SIZE, sp)
3047
3048 sd a3, PT_R26(sp) # save a3 for syscall restarting
3049
3050- li t1, _TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT
3051+ li t1, _TIF_SYSCALL_WORK
3052 LONG_L t0, TI_FLAGS($28) # syscall tracing enabled?
3053 and t0, t1, t0
3054 bnez t0, n32_syscall_trace_entry
3055diff --git a/arch/mips/kernel/scall64-o32.S b/arch/mips/kernel/scall64-o32.S
3056index 5422855..74e63a3 100644
3057--- a/arch/mips/kernel/scall64-o32.S
3058+++ b/arch/mips/kernel/scall64-o32.S
3059@@ -81,7 +81,7 @@ NESTED(handle_sys, PT_SIZE, sp)
3060 PTR 4b, bad_stack
3061 .previous
3062
3063- li t1, _TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT
3064+ li t1, _TIF_SYSCALL_WORK
3065 LONG_L t0, TI_FLAGS($28) # syscall tracing enabled?
3066 and t0, t1, t0
3067 bnez t0, trace_a_syscall
3068diff --git a/arch/mips/mm/fault.c b/arch/mips/mm/fault.c
3069index c14f6df..537e729 100644
3070--- a/arch/mips/mm/fault.c
3071+++ b/arch/mips/mm/fault.c
3072@@ -27,6 +27,23 @@
3073 #include <asm/highmem.h> /* For VMALLOC_END */
3074 #include <linux/kdebug.h>
3075
3076+#ifdef CONFIG_PAX_PAGEEXEC
3077+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
3078+{
3079+ unsigned long i;
3080+
3081+ printk(KERN_ERR "PAX: bytes at PC: ");
3082+ for (i = 0; i < 5; i++) {
3083+ unsigned int c;
3084+ if (get_user(c, (unsigned int *)pc+i))
3085+ printk(KERN_CONT "???????? ");
3086+ else
3087+ printk(KERN_CONT "%08x ", c);
3088+ }
3089+ printk("\n");
3090+}
3091+#endif
3092+
3093 /*
3094 * This routine handles page faults. It determines the address,
3095 * and the problem, and then passes it off to one of the appropriate
3096diff --git a/arch/mips/mm/mmap.c b/arch/mips/mm/mmap.c
3097index 302d779..7d35bf8 100644
3098--- a/arch/mips/mm/mmap.c
3099+++ b/arch/mips/mm/mmap.c
3100@@ -95,6 +95,11 @@ static unsigned long arch_get_unmapped_area_common(struct file *filp,
3101 do_color_align = 1;
3102
3103 /* requesting a specific address */
3104+
3105+#ifdef CONFIG_PAX_RANDMMAP
3106+ if (!(current->mm->pax_flags & MF_PAX_RANDMMAP))
3107+#endif
3108+
3109 if (addr) {
3110 if (do_color_align)
3111 addr = COLOUR_ALIGN(addr, pgoff);
3112@@ -102,8 +107,7 @@ static unsigned long arch_get_unmapped_area_common(struct file *filp,
3113 addr = PAGE_ALIGN(addr);
3114
3115 vma = find_vma(mm, addr);
3116- if (TASK_SIZE - len >= addr &&
3117- (!vma || addr + len <= vma->vm_start))
3118+ if (TASK_SIZE - len >= addr && check_heap_stack_gap(vmm, addr, len))
3119 return addr;
3120 }
3121
3122@@ -118,7 +122,7 @@ static unsigned long arch_get_unmapped_area_common(struct file *filp,
3123 /* At this point: (!vma || addr < vma->vm_end). */
3124 if (TASK_SIZE - len < addr)
3125 return -ENOMEM;
3126- if (!vma || addr + len <= vma->vm_start)
3127+ if (check_heap_stack_gap(vmm, addr, len))
3128 return addr;
3129 addr = vma->vm_end;
3130 if (do_color_align)
3131@@ -145,7 +149,7 @@ static unsigned long arch_get_unmapped_area_common(struct file *filp,
3132 /* make sure it can fit in the remaining address space */
3133 if (likely(addr > len)) {
3134 vma = find_vma(mm, addr - len);
3135- if (!vma || addr <= vma->vm_start) {
3136+ if (check_heap_stack_gap(vmm, addr - len, len))
3137 /* cache the address as a hint for next time */
3138 return mm->free_area_cache = addr - len;
3139 }
3140@@ -165,7 +169,7 @@ static unsigned long arch_get_unmapped_area_common(struct file *filp,
3141 * return with success:
3142 */
3143 vma = find_vma(mm, addr);
3144- if (likely(!vma || addr + len <= vma->vm_start)) {
3145+ if (check_heap_stack_gap(vmm, addr, len)) {
3146 /* cache the address as a hint for next time */
3147 return mm->free_area_cache = addr;
3148 }
3149@@ -242,30 +246,3 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
3150 mm->unmap_area = arch_unmap_area_topdown;
3151 }
3152 }
3153-
3154-static inline unsigned long brk_rnd(void)
3155-{
3156- unsigned long rnd = get_random_int();
3157-
3158- rnd = rnd << PAGE_SHIFT;
3159- /* 8MB for 32bit, 256MB for 64bit */
3160- if (TASK_IS_32BIT_ADDR)
3161- rnd = rnd & 0x7ffffful;
3162- else
3163- rnd = rnd & 0xffffffful;
3164-
3165- return rnd;
3166-}
3167-
3168-unsigned long arch_randomize_brk(struct mm_struct *mm)
3169-{
3170- unsigned long base = mm->brk;
3171- unsigned long ret;
3172-
3173- ret = PAGE_ALIGN(base + brk_rnd());
3174-
3175- if (ret < mm->brk)
3176- return mm->brk;
3177-
3178- return ret;
3179-}
3180diff --git a/arch/mn10300/proc-mn103e010/include/proc/cache.h b/arch/mn10300/proc-mn103e010/include/proc/cache.h
3181index 967d144..db12197 100644
3182--- a/arch/mn10300/proc-mn103e010/include/proc/cache.h
3183+++ b/arch/mn10300/proc-mn103e010/include/proc/cache.h
3184@@ -11,12 +11,14 @@
3185 #ifndef _ASM_PROC_CACHE_H
3186 #define _ASM_PROC_CACHE_H
3187
3188+#include <linux/const.h>
3189+
3190 /* L1 cache */
3191
3192 #define L1_CACHE_NWAYS 4 /* number of ways in caches */
3193 #define L1_CACHE_NENTRIES 256 /* number of entries in each way */
3194-#define L1_CACHE_BYTES 16 /* bytes per entry */
3195 #define L1_CACHE_SHIFT 4 /* shift for bytes per entry */
3196+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT) /* bytes per entry */
3197 #define L1_CACHE_WAYDISP 0x1000 /* displacement of one way from the next */
3198
3199 #define L1_CACHE_TAG_VALID 0x00000001 /* cache tag valid bit */
3200diff --git a/arch/mn10300/proc-mn2ws0050/include/proc/cache.h b/arch/mn10300/proc-mn2ws0050/include/proc/cache.h
3201index bcb5df2..84fabd2 100644
3202--- a/arch/mn10300/proc-mn2ws0050/include/proc/cache.h
3203+++ b/arch/mn10300/proc-mn2ws0050/include/proc/cache.h
3204@@ -16,13 +16,15 @@
3205 #ifndef _ASM_PROC_CACHE_H
3206 #define _ASM_PROC_CACHE_H
3207
3208+#include <linux/const.h>
3209+
3210 /*
3211 * L1 cache
3212 */
3213 #define L1_CACHE_NWAYS 4 /* number of ways in caches */
3214 #define L1_CACHE_NENTRIES 128 /* number of entries in each way */
3215-#define L1_CACHE_BYTES 32 /* bytes per entry */
3216 #define L1_CACHE_SHIFT 5 /* shift for bytes per entry */
3217+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT) /* bytes per entry */
3218 #define L1_CACHE_WAYDISP 0x1000 /* distance from one way to the next */
3219
3220 #define L1_CACHE_TAG_VALID 0x00000001 /* cache tag valid bit */
3221diff --git a/arch/openrisc/include/asm/cache.h b/arch/openrisc/include/asm/cache.h
3222index 4ce7a01..449202a 100644
3223--- a/arch/openrisc/include/asm/cache.h
3224+++ b/arch/openrisc/include/asm/cache.h
3225@@ -19,11 +19,13 @@
3226 #ifndef __ASM_OPENRISC_CACHE_H
3227 #define __ASM_OPENRISC_CACHE_H
3228
3229+#include <linux/const.h>
3230+
3231 /* FIXME: How can we replace these with values from the CPU...
3232 * they shouldn't be hard-coded!
3233 */
3234
3235-#define L1_CACHE_BYTES 16
3236 #define L1_CACHE_SHIFT 4
3237+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
3238
3239 #endif /* __ASM_OPENRISC_CACHE_H */
3240diff --git a/arch/parisc/include/asm/atomic.h b/arch/parisc/include/asm/atomic.h
3241index af9cf30..2aae9b2 100644
3242--- a/arch/parisc/include/asm/atomic.h
3243+++ b/arch/parisc/include/asm/atomic.h
3244@@ -229,6 +229,16 @@ static __inline__ int atomic64_add_unless(atomic64_t *v, long a, long u)
3245
3246 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
3247
3248+#define atomic64_read_unchecked(v) atomic64_read(v)
3249+#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
3250+#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
3251+#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
3252+#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
3253+#define atomic64_inc_unchecked(v) atomic64_inc(v)
3254+#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
3255+#define atomic64_dec_unchecked(v) atomic64_dec(v)
3256+#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
3257+
3258 #endif /* !CONFIG_64BIT */
3259
3260
3261diff --git a/arch/parisc/include/asm/cache.h b/arch/parisc/include/asm/cache.h
3262index 47f11c7..3420df2 100644
3263--- a/arch/parisc/include/asm/cache.h
3264+++ b/arch/parisc/include/asm/cache.h
3265@@ -5,6 +5,7 @@
3266 #ifndef __ARCH_PARISC_CACHE_H
3267 #define __ARCH_PARISC_CACHE_H
3268
3269+#include <linux/const.h>
3270
3271 /*
3272 * PA 2.0 processors have 64-byte cachelines; PA 1.1 processors have
3273@@ -15,13 +16,13 @@
3274 * just ruin performance.
3275 */
3276 #ifdef CONFIG_PA20
3277-#define L1_CACHE_BYTES 64
3278 #define L1_CACHE_SHIFT 6
3279 #else
3280-#define L1_CACHE_BYTES 32
3281 #define L1_CACHE_SHIFT 5
3282 #endif
3283
3284+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
3285+
3286 #ifndef __ASSEMBLY__
3287
3288 #define SMP_CACHE_BYTES L1_CACHE_BYTES
3289diff --git a/arch/parisc/include/asm/elf.h b/arch/parisc/include/asm/elf.h
3290index 19f6cb1..6c78cf2 100644
3291--- a/arch/parisc/include/asm/elf.h
3292+++ b/arch/parisc/include/asm/elf.h
3293@@ -342,6 +342,13 @@ struct pt_regs; /* forward declaration... */
3294
3295 #define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE + 0x01000000)
3296
3297+#ifdef CONFIG_PAX_ASLR
3298+#define PAX_ELF_ET_DYN_BASE 0x10000UL
3299+
3300+#define PAX_DELTA_MMAP_LEN 16
3301+#define PAX_DELTA_STACK_LEN 16
3302+#endif
3303+
3304 /* This yields a mask that user programs can use to figure out what
3305 instruction set this CPU supports. This could be done in user space,
3306 but it's not easy, and we've already done it here. */
3307diff --git a/arch/parisc/include/asm/pgalloc.h b/arch/parisc/include/asm/pgalloc.h
3308index fc987a1..6e068ef 100644
3309--- a/arch/parisc/include/asm/pgalloc.h
3310+++ b/arch/parisc/include/asm/pgalloc.h
3311@@ -61,6 +61,11 @@ static inline void pgd_populate(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmd)
3312 (__u32)(__pa((unsigned long)pmd) >> PxD_VALUE_SHIFT));
3313 }
3314
3315+static inline void pgd_populate_kernel(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmd)
3316+{
3317+ pgd_populate(mm, pgd, pmd);
3318+}
3319+
3320 static inline pmd_t *pmd_alloc_one(struct mm_struct *mm, unsigned long address)
3321 {
3322 pmd_t *pmd = (pmd_t *)__get_free_pages(GFP_KERNEL|__GFP_REPEAT,
3323@@ -93,6 +98,7 @@ static inline void pmd_free(struct mm_struct *mm, pmd_t *pmd)
3324 #define pmd_alloc_one(mm, addr) ({ BUG(); ((pmd_t *)2); })
3325 #define pmd_free(mm, x) do { } while (0)
3326 #define pgd_populate(mm, pmd, pte) BUG()
3327+#define pgd_populate_kernel(mm, pmd, pte) BUG()
3328
3329 #endif
3330
3331diff --git a/arch/parisc/include/asm/pgtable.h b/arch/parisc/include/asm/pgtable.h
3332index ee99f23..802b0a1 100644
3333--- a/arch/parisc/include/asm/pgtable.h
3334+++ b/arch/parisc/include/asm/pgtable.h
3335@@ -212,6 +212,17 @@ struct vm_area_struct;
3336 #define PAGE_EXECREAD __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_EXEC |_PAGE_ACCESSED)
3337 #define PAGE_COPY PAGE_EXECREAD
3338 #define PAGE_RWX __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_WRITE | _PAGE_EXEC |_PAGE_ACCESSED)
3339+
3340+#ifdef CONFIG_PAX_PAGEEXEC
3341+# define PAGE_SHARED_NOEXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_WRITE | _PAGE_ACCESSED)
3342+# define PAGE_COPY_NOEXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_ACCESSED)
3343+# define PAGE_READONLY_NOEXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_ACCESSED)
3344+#else
3345+# define PAGE_SHARED_NOEXEC PAGE_SHARED
3346+# define PAGE_COPY_NOEXEC PAGE_COPY
3347+# define PAGE_READONLY_NOEXEC PAGE_READONLY
3348+#endif
3349+
3350 #define PAGE_KERNEL __pgprot(_PAGE_KERNEL)
3351 #define PAGE_KERNEL_EXEC __pgprot(_PAGE_KERNEL_EXEC)
3352 #define PAGE_KERNEL_RWX __pgprot(_PAGE_KERNEL_RWX)
3353diff --git a/arch/parisc/include/asm/uaccess.h b/arch/parisc/include/asm/uaccess.h
3354index 4ba2c93..f5e3974 100644
3355--- a/arch/parisc/include/asm/uaccess.h
3356+++ b/arch/parisc/include/asm/uaccess.h
3357@@ -251,10 +251,10 @@ static inline unsigned long __must_check copy_from_user(void *to,
3358 const void __user *from,
3359 unsigned long n)
3360 {
3361- int sz = __compiletime_object_size(to);
3362+ size_t sz = __compiletime_object_size(to);
3363 int ret = -EFAULT;
3364
3365- if (likely(sz == -1 || !__builtin_constant_p(n) || sz >= n))
3366+ if (likely(sz == (size_t)-1 || !__builtin_constant_p(n) || sz >= n))
3367 ret = __copy_from_user(to, from, n);
3368 else
3369 copy_from_user_overflow();
3370diff --git a/arch/parisc/kernel/module.c b/arch/parisc/kernel/module.c
3371index 5e34ccf..672bc9c 100644
3372--- a/arch/parisc/kernel/module.c
3373+++ b/arch/parisc/kernel/module.c
3374@@ -98,16 +98,38 @@
3375
3376 /* three functions to determine where in the module core
3377 * or init pieces the location is */
3378+static inline int in_init_rx(struct module *me, void *loc)
3379+{
3380+ return (loc >= me->module_init_rx &&
3381+ loc < (me->module_init_rx + me->init_size_rx));
3382+}
3383+
3384+static inline int in_init_rw(struct module *me, void *loc)
3385+{
3386+ return (loc >= me->module_init_rw &&
3387+ loc < (me->module_init_rw + me->init_size_rw));
3388+}
3389+
3390 static inline int in_init(struct module *me, void *loc)
3391 {
3392- return (loc >= me->module_init &&
3393- loc <= (me->module_init + me->init_size));
3394+ return in_init_rx(me, loc) || in_init_rw(me, loc);
3395+}
3396+
3397+static inline int in_core_rx(struct module *me, void *loc)
3398+{
3399+ return (loc >= me->module_core_rx &&
3400+ loc < (me->module_core_rx + me->core_size_rx));
3401+}
3402+
3403+static inline int in_core_rw(struct module *me, void *loc)
3404+{
3405+ return (loc >= me->module_core_rw &&
3406+ loc < (me->module_core_rw + me->core_size_rw));
3407 }
3408
3409 static inline int in_core(struct module *me, void *loc)
3410 {
3411- return (loc >= me->module_core &&
3412- loc <= (me->module_core + me->core_size));
3413+ return in_core_rx(me, loc) || in_core_rw(me, loc);
3414 }
3415
3416 static inline int in_local(struct module *me, void *loc)
3417@@ -373,13 +395,13 @@ int module_frob_arch_sections(CONST Elf_Ehdr *hdr,
3418 }
3419
3420 /* align things a bit */
3421- me->core_size = ALIGN(me->core_size, 16);
3422- me->arch.got_offset = me->core_size;
3423- me->core_size += gots * sizeof(struct got_entry);
3424+ me->core_size_rw = ALIGN(me->core_size_rw, 16);
3425+ me->arch.got_offset = me->core_size_rw;
3426+ me->core_size_rw += gots * sizeof(struct got_entry);
3427
3428- me->core_size = ALIGN(me->core_size, 16);
3429- me->arch.fdesc_offset = me->core_size;
3430- me->core_size += fdescs * sizeof(Elf_Fdesc);
3431+ me->core_size_rw = ALIGN(me->core_size_rw, 16);
3432+ me->arch.fdesc_offset = me->core_size_rw;
3433+ me->core_size_rw += fdescs * sizeof(Elf_Fdesc);
3434
3435 me->arch.got_max = gots;
3436 me->arch.fdesc_max = fdescs;
3437@@ -397,7 +419,7 @@ static Elf64_Word get_got(struct module *me, unsigned long value, long addend)
3438
3439 BUG_ON(value == 0);
3440
3441- got = me->module_core + me->arch.got_offset;
3442+ got = me->module_core_rw + me->arch.got_offset;
3443 for (i = 0; got[i].addr; i++)
3444 if (got[i].addr == value)
3445 goto out;
3446@@ -415,7 +437,7 @@ static Elf64_Word get_got(struct module *me, unsigned long value, long addend)
3447 #ifdef CONFIG_64BIT
3448 static Elf_Addr get_fdesc(struct module *me, unsigned long value)
3449 {
3450- Elf_Fdesc *fdesc = me->module_core + me->arch.fdesc_offset;
3451+ Elf_Fdesc *fdesc = me->module_core_rw + me->arch.fdesc_offset;
3452
3453 if (!value) {
3454 printk(KERN_ERR "%s: zero OPD requested!\n", me->name);
3455@@ -433,7 +455,7 @@ static Elf_Addr get_fdesc(struct module *me, unsigned long value)
3456
3457 /* Create new one */
3458 fdesc->addr = value;
3459- fdesc->gp = (Elf_Addr)me->module_core + me->arch.got_offset;
3460+ fdesc->gp = (Elf_Addr)me->module_core_rw + me->arch.got_offset;
3461 return (Elf_Addr)fdesc;
3462 }
3463 #endif /* CONFIG_64BIT */
3464@@ -845,7 +867,7 @@ register_unwind_table(struct module *me,
3465
3466 table = (unsigned char *)sechdrs[me->arch.unwind_section].sh_addr;
3467 end = table + sechdrs[me->arch.unwind_section].sh_size;
3468- gp = (Elf_Addr)me->module_core + me->arch.got_offset;
3469+ gp = (Elf_Addr)me->module_core_rw + me->arch.got_offset;
3470
3471 DEBUGP("register_unwind_table(), sect = %d at 0x%p - 0x%p (gp=0x%lx)\n",
3472 me->arch.unwind_section, table, end, gp);
3473diff --git a/arch/parisc/kernel/signal32.c b/arch/parisc/kernel/signal32.c
3474index fd49aed..5dede04 100644
3475--- a/arch/parisc/kernel/signal32.c
3476+++ b/arch/parisc/kernel/signal32.c
3477@@ -65,7 +65,8 @@ put_sigset32(compat_sigset_t __user *up, sigset_t *set, size_t sz)
3478 {
3479 compat_sigset_t s;
3480
3481- if (sz != sizeof *set) panic("put_sigset32()");
3482+ if (sz != sizeof *set)
3483+ return -EINVAL;
3484 sigset_64to32(&s, set);
3485
3486 return copy_to_user(up, &s, sizeof s);
3487@@ -77,7 +78,8 @@ get_sigset32(compat_sigset_t __user *up, sigset_t *set, size_t sz)
3488 compat_sigset_t s;
3489 int r;
3490
3491- if (sz != sizeof *set) panic("put_sigset32()");
3492+ if (sz != sizeof *set)
3493+ return -EINVAL;
3494
3495 if ((r = copy_from_user(&s, up, sz)) == 0) {
3496 sigset_32to64(set, &s);
3497diff --git a/arch/parisc/kernel/sys_parisc.c b/arch/parisc/kernel/sys_parisc.c
3498index 7426e40..30c8dbe 100644
3499--- a/arch/parisc/kernel/sys_parisc.c
3500+++ b/arch/parisc/kernel/sys_parisc.c
3501@@ -43,7 +43,7 @@ static unsigned long get_unshared_area(unsigned long addr, unsigned long len)
3502 /* At this point: (!vma || addr < vma->vm_end). */
3503 if (TASK_SIZE - len < addr)
3504 return -ENOMEM;
3505- if (!vma || addr + len <= vma->vm_start)
3506+ if (check_heap_stack_gap(vma, addr, len))
3507 return addr;
3508 addr = vma->vm_end;
3509 }
3510@@ -79,7 +79,7 @@ static unsigned long get_shared_area(struct address_space *mapping,
3511 /* At this point: (!vma || addr < vma->vm_end). */
3512 if (TASK_SIZE - len < addr)
3513 return -ENOMEM;
3514- if (!vma || addr + len <= vma->vm_start)
3515+ if (check_heap_stack_gap(vma, addr, len))
3516 return addr;
3517 addr = DCACHE_ALIGN(vma->vm_end - offset) + offset;
3518 if (addr < vma->vm_end) /* handle wraparound */
3519@@ -98,7 +98,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr,
3520 if (flags & MAP_FIXED)
3521 return addr;
3522 if (!addr)
3523- addr = TASK_UNMAPPED_BASE;
3524+ addr = current->mm->mmap_base;
3525
3526 if (filp) {
3527 addr = get_shared_area(filp->f_mapping, addr, len, pgoff);
3528diff --git a/arch/parisc/kernel/traps.c b/arch/parisc/kernel/traps.c
3529index 45ba99f..8e22c33 100644
3530--- a/arch/parisc/kernel/traps.c
3531+++ b/arch/parisc/kernel/traps.c
3532@@ -732,9 +732,7 @@ void notrace handle_interruption(int code, struct pt_regs *regs)
3533
3534 down_read(&current->mm->mmap_sem);
3535 vma = find_vma(current->mm,regs->iaoq[0]);
3536- if (vma && (regs->iaoq[0] >= vma->vm_start)
3537- && (vma->vm_flags & VM_EXEC)) {
3538-
3539+ if (vma && (regs->iaoq[0] >= vma->vm_start)) {
3540 fault_address = regs->iaoq[0];
3541 fault_space = regs->iasq[0];
3542
3543diff --git a/arch/parisc/mm/fault.c b/arch/parisc/mm/fault.c
3544index 18162ce..94de376 100644
3545--- a/arch/parisc/mm/fault.c
3546+++ b/arch/parisc/mm/fault.c
3547@@ -15,6 +15,7 @@
3548 #include <linux/sched.h>
3549 #include <linux/interrupt.h>
3550 #include <linux/module.h>
3551+#include <linux/unistd.h>
3552
3553 #include <asm/uaccess.h>
3554 #include <asm/traps.h>
3555@@ -52,7 +53,7 @@ DEFINE_PER_CPU(struct exception_data, exception_data);
3556 static unsigned long
3557 parisc_acctyp(unsigned long code, unsigned int inst)
3558 {
3559- if (code == 6 || code == 16)
3560+ if (code == 6 || code == 7 || code == 16)
3561 return VM_EXEC;
3562
3563 switch (inst & 0xf0000000) {
3564@@ -138,6 +139,116 @@ parisc_acctyp(unsigned long code, unsigned int inst)
3565 }
3566 #endif
3567
3568+#ifdef CONFIG_PAX_PAGEEXEC
3569+/*
3570+ * PaX: decide what to do with offenders (instruction_pointer(regs) = fault address)
3571+ *
3572+ * returns 1 when task should be killed
3573+ * 2 when rt_sigreturn trampoline was detected
3574+ * 3 when unpatched PLT trampoline was detected
3575+ */
3576+static int pax_handle_fetch_fault(struct pt_regs *regs)
3577+{
3578+
3579+#ifdef CONFIG_PAX_EMUPLT
3580+ int err;
3581+
3582+ do { /* PaX: unpatched PLT emulation */
3583+ unsigned int bl, depwi;
3584+
3585+ err = get_user(bl, (unsigned int *)instruction_pointer(regs));
3586+ err |= get_user(depwi, (unsigned int *)(instruction_pointer(regs)+4));
3587+
3588+ if (err)
3589+ break;
3590+
3591+ if (bl == 0xEA9F1FDDU && depwi == 0xD6801C1EU) {
3592+ unsigned int ldw, bv, ldw2, addr = instruction_pointer(regs)-12;
3593+
3594+ err = get_user(ldw, (unsigned int *)addr);
3595+ err |= get_user(bv, (unsigned int *)(addr+4));
3596+ err |= get_user(ldw2, (unsigned int *)(addr+8));
3597+
3598+ if (err)
3599+ break;
3600+
3601+ if (ldw == 0x0E801096U &&
3602+ bv == 0xEAC0C000U &&
3603+ ldw2 == 0x0E881095U)
3604+ {
3605+ unsigned int resolver, map;
3606+
3607+ err = get_user(resolver, (unsigned int *)(instruction_pointer(regs)+8));
3608+ err |= get_user(map, (unsigned int *)(instruction_pointer(regs)+12));
3609+ if (err)
3610+ break;
3611+
3612+ regs->gr[20] = instruction_pointer(regs)+8;
3613+ regs->gr[21] = map;
3614+ regs->gr[22] = resolver;
3615+ regs->iaoq[0] = resolver | 3UL;
3616+ regs->iaoq[1] = regs->iaoq[0] + 4;
3617+ return 3;
3618+ }
3619+ }
3620+ } while (0);
3621+#endif
3622+
3623+#ifdef CONFIG_PAX_EMUTRAMP
3624+
3625+#ifndef CONFIG_PAX_EMUSIGRT
3626+ if (!(current->mm->pax_flags & MF_PAX_EMUTRAMP))
3627+ return 1;
3628+#endif
3629+
3630+ do { /* PaX: rt_sigreturn emulation */
3631+ unsigned int ldi1, ldi2, bel, nop;
3632+
3633+ err = get_user(ldi1, (unsigned int *)instruction_pointer(regs));
3634+ err |= get_user(ldi2, (unsigned int *)(instruction_pointer(regs)+4));
3635+ err |= get_user(bel, (unsigned int *)(instruction_pointer(regs)+8));
3636+ err |= get_user(nop, (unsigned int *)(instruction_pointer(regs)+12));
3637+
3638+ if (err)
3639+ break;
3640+
3641+ if ((ldi1 == 0x34190000U || ldi1 == 0x34190002U) &&
3642+ ldi2 == 0x3414015AU &&
3643+ bel == 0xE4008200U &&
3644+ nop == 0x08000240U)
3645+ {
3646+ regs->gr[25] = (ldi1 & 2) >> 1;
3647+ regs->gr[20] = __NR_rt_sigreturn;
3648+ regs->gr[31] = regs->iaoq[1] + 16;
3649+ regs->sr[0] = regs->iasq[1];
3650+ regs->iaoq[0] = 0x100UL;
3651+ regs->iaoq[1] = regs->iaoq[0] + 4;
3652+ regs->iasq[0] = regs->sr[2];
3653+ regs->iasq[1] = regs->sr[2];
3654+ return 2;
3655+ }
3656+ } while (0);
3657+#endif
3658+
3659+ return 1;
3660+}
3661+
3662+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
3663+{
3664+ unsigned long i;
3665+
3666+ printk(KERN_ERR "PAX: bytes at PC: ");
3667+ for (i = 0; i < 5; i++) {
3668+ unsigned int c;
3669+ if (get_user(c, (unsigned int *)pc+i))
3670+ printk(KERN_CONT "???????? ");
3671+ else
3672+ printk(KERN_CONT "%08x ", c);
3673+ }
3674+ printk("\n");
3675+}
3676+#endif
3677+
3678 int fixup_exception(struct pt_regs *regs)
3679 {
3680 const struct exception_table_entry *fix;
3681@@ -192,8 +303,33 @@ good_area:
3682
3683 acc_type = parisc_acctyp(code,regs->iir);
3684
3685- if ((vma->vm_flags & acc_type) != acc_type)
3686+ if ((vma->vm_flags & acc_type) != acc_type) {
3687+
3688+#ifdef CONFIG_PAX_PAGEEXEC
3689+ if ((mm->pax_flags & MF_PAX_PAGEEXEC) && (acc_type & VM_EXEC) &&
3690+ (address & ~3UL) == instruction_pointer(regs))
3691+ {
3692+ up_read(&mm->mmap_sem);
3693+ switch (pax_handle_fetch_fault(regs)) {
3694+
3695+#ifdef CONFIG_PAX_EMUPLT
3696+ case 3:
3697+ return;
3698+#endif
3699+
3700+#ifdef CONFIG_PAX_EMUTRAMP
3701+ case 2:
3702+ return;
3703+#endif
3704+
3705+ }
3706+ pax_report_fault(regs, (void *)instruction_pointer(regs), (void *)regs->gr[30]);
3707+ do_group_exit(SIGKILL);
3708+ }
3709+#endif
3710+
3711 goto bad_area;
3712+ }
3713
3714 /*
3715 * If for any reason at all we couldn't handle the fault, make
3716diff --git a/arch/powerpc/include/asm/atomic.h b/arch/powerpc/include/asm/atomic.h
3717index da29032..f76c24c 100644
3718--- a/arch/powerpc/include/asm/atomic.h
3719+++ b/arch/powerpc/include/asm/atomic.h
3720@@ -522,6 +522,16 @@ static __inline__ long atomic64_inc_not_zero(atomic64_t *v)
3721 return t1;
3722 }
3723
3724+#define atomic64_read_unchecked(v) atomic64_read(v)
3725+#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
3726+#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
3727+#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
3728+#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
3729+#define atomic64_inc_unchecked(v) atomic64_inc(v)
3730+#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
3731+#define atomic64_dec_unchecked(v) atomic64_dec(v)
3732+#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
3733+
3734 #endif /* __powerpc64__ */
3735
3736 #endif /* __KERNEL__ */
3737diff --git a/arch/powerpc/include/asm/cache.h b/arch/powerpc/include/asm/cache.h
3738index 9e495c9..b6878e5 100644
3739--- a/arch/powerpc/include/asm/cache.h
3740+++ b/arch/powerpc/include/asm/cache.h
3741@@ -3,6 +3,7 @@
3742
3743 #ifdef __KERNEL__
3744
3745+#include <linux/const.h>
3746
3747 /* bytes per L1 cache line */
3748 #if defined(CONFIG_8xx) || defined(CONFIG_403GCX)
3749@@ -22,7 +23,7 @@
3750 #define L1_CACHE_SHIFT 7
3751 #endif
3752
3753-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
3754+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
3755
3756 #define SMP_CACHE_BYTES L1_CACHE_BYTES
3757
3758diff --git a/arch/powerpc/include/asm/elf.h b/arch/powerpc/include/asm/elf.h
3759index 3bf9cca..e7457d0 100644
3760--- a/arch/powerpc/include/asm/elf.h
3761+++ b/arch/powerpc/include/asm/elf.h
3762@@ -178,8 +178,19 @@ typedef elf_fpreg_t elf_vsrreghalf_t32[ELF_NVSRHALFREG];
3763 the loader. We need to make sure that it is out of the way of the program
3764 that it will "exec", and that there is sufficient room for the brk. */
3765
3766-extern unsigned long randomize_et_dyn(unsigned long base);
3767-#define ELF_ET_DYN_BASE (randomize_et_dyn(0x20000000))
3768+#define ELF_ET_DYN_BASE (0x20000000)
3769+
3770+#ifdef CONFIG_PAX_ASLR
3771+#define PAX_ELF_ET_DYN_BASE (0x10000000UL)
3772+
3773+#ifdef __powerpc64__
3774+#define PAX_DELTA_MMAP_LEN (is_32bit_task() ? 16 : 28)
3775+#define PAX_DELTA_STACK_LEN (is_32bit_task() ? 16 : 28)
3776+#else
3777+#define PAX_DELTA_MMAP_LEN 15
3778+#define PAX_DELTA_STACK_LEN 15
3779+#endif
3780+#endif
3781
3782 /*
3783 * Our registers are always unsigned longs, whether we're a 32 bit
3784@@ -274,9 +285,6 @@ extern int arch_setup_additional_pages(struct linux_binprm *bprm,
3785 (0x7ff >> (PAGE_SHIFT - 12)) : \
3786 (0x3ffff >> (PAGE_SHIFT - 12)))
3787
3788-extern unsigned long arch_randomize_brk(struct mm_struct *mm);
3789-#define arch_randomize_brk arch_randomize_brk
3790-
3791 #endif /* __KERNEL__ */
3792
3793 /*
3794diff --git a/arch/powerpc/include/asm/exec.h b/arch/powerpc/include/asm/exec.h
3795index 8196e9c..d83a9f3 100644
3796--- a/arch/powerpc/include/asm/exec.h
3797+++ b/arch/powerpc/include/asm/exec.h
3798@@ -4,6 +4,6 @@
3799 #ifndef _ASM_POWERPC_EXEC_H
3800 #define _ASM_POWERPC_EXEC_H
3801
3802-extern unsigned long arch_align_stack(unsigned long sp);
3803+#define arch_align_stack(x) ((x) & ~0xfUL)
3804
3805 #endif /* _ASM_POWERPC_EXEC_H */
3806diff --git a/arch/powerpc/include/asm/kmap_types.h b/arch/powerpc/include/asm/kmap_types.h
3807index 5acabbd..7ea14fa 100644
3808--- a/arch/powerpc/include/asm/kmap_types.h
3809+++ b/arch/powerpc/include/asm/kmap_types.h
3810@@ -10,7 +10,7 @@
3811 * 2 of the License, or (at your option) any later version.
3812 */
3813
3814-#define KM_TYPE_NR 16
3815+#define KM_TYPE_NR 17
3816
3817 #endif /* __KERNEL__ */
3818 #endif /* _ASM_POWERPC_KMAP_TYPES_H */
3819diff --git a/arch/powerpc/include/asm/mman.h b/arch/powerpc/include/asm/mman.h
3820index d4a7f64..451de1c 100644
3821--- a/arch/powerpc/include/asm/mman.h
3822+++ b/arch/powerpc/include/asm/mman.h
3823@@ -44,7 +44,7 @@ static inline unsigned long arch_calc_vm_prot_bits(unsigned long prot)
3824 }
3825 #define arch_calc_vm_prot_bits(prot) arch_calc_vm_prot_bits(prot)
3826
3827-static inline pgprot_t arch_vm_get_page_prot(unsigned long vm_flags)
3828+static inline pgprot_t arch_vm_get_page_prot(vm_flags_t vm_flags)
3829 {
3830 return (vm_flags & VM_SAO) ? __pgprot(_PAGE_SAO) : __pgprot(0);
3831 }
3832diff --git a/arch/powerpc/include/asm/page.h b/arch/powerpc/include/asm/page.h
3833index f072e97..b436dee 100644
3834--- a/arch/powerpc/include/asm/page.h
3835+++ b/arch/powerpc/include/asm/page.h
3836@@ -220,8 +220,9 @@ extern long long virt_phys_offset;
3837 * and needs to be executable. This means the whole heap ends
3838 * up being executable.
3839 */
3840-#define VM_DATA_DEFAULT_FLAGS32 (VM_READ | VM_WRITE | VM_EXEC | \
3841- VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
3842+#define VM_DATA_DEFAULT_FLAGS32 \
3843+ (((current->personality & READ_IMPLIES_EXEC) ? VM_EXEC : 0) | \
3844+ VM_READ | VM_WRITE | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
3845
3846 #define VM_DATA_DEFAULT_FLAGS64 (VM_READ | VM_WRITE | \
3847 VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
3848@@ -249,6 +250,9 @@ extern long long virt_phys_offset;
3849 #define is_kernel_addr(x) ((x) >= PAGE_OFFSET)
3850 #endif
3851
3852+#define ktla_ktva(addr) (addr)
3853+#define ktva_ktla(addr) (addr)
3854+
3855 /*
3856 * Use the top bit of the higher-level page table entries to indicate whether
3857 * the entries we point to contain hugepages. This works because we know that
3858diff --git a/arch/powerpc/include/asm/page_64.h b/arch/powerpc/include/asm/page_64.h
3859index fed85e6..da5c71b 100644
3860--- a/arch/powerpc/include/asm/page_64.h
3861+++ b/arch/powerpc/include/asm/page_64.h
3862@@ -146,15 +146,18 @@ do { \
3863 * stack by default, so in the absence of a PT_GNU_STACK program header
3864 * we turn execute permission off.
3865 */
3866-#define VM_STACK_DEFAULT_FLAGS32 (VM_READ | VM_WRITE | VM_EXEC | \
3867- VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
3868+#define VM_STACK_DEFAULT_FLAGS32 \
3869+ (((current->personality & READ_IMPLIES_EXEC) ? VM_EXEC : 0) | \
3870+ VM_READ | VM_WRITE | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
3871
3872 #define VM_STACK_DEFAULT_FLAGS64 (VM_READ | VM_WRITE | \
3873 VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
3874
3875+#ifndef CONFIG_PAX_PAGEEXEC
3876 #define VM_STACK_DEFAULT_FLAGS \
3877 (is_32bit_task() ? \
3878 VM_STACK_DEFAULT_FLAGS32 : VM_STACK_DEFAULT_FLAGS64)
3879+#endif
3880
3881 #include <asm-generic/getorder.h>
3882
3883diff --git a/arch/powerpc/include/asm/pgalloc-64.h b/arch/powerpc/include/asm/pgalloc-64.h
3884index 292725c..f87ae14 100644
3885--- a/arch/powerpc/include/asm/pgalloc-64.h
3886+++ b/arch/powerpc/include/asm/pgalloc-64.h
3887@@ -50,6 +50,7 @@ static inline void pgd_free(struct mm_struct *mm, pgd_t *pgd)
3888 #ifndef CONFIG_PPC_64K_PAGES
3889
3890 #define pgd_populate(MM, PGD, PUD) pgd_set(PGD, PUD)
3891+#define pgd_populate_kernel(MM, PGD, PUD) pgd_populate((MM), (PGD), (PUD))
3892
3893 static inline pud_t *pud_alloc_one(struct mm_struct *mm, unsigned long addr)
3894 {
3895@@ -67,6 +68,11 @@ static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
3896 pud_set(pud, (unsigned long)pmd);
3897 }
3898
3899+static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
3900+{
3901+ pud_populate(mm, pud, pmd);
3902+}
3903+
3904 #define pmd_populate(mm, pmd, pte_page) \
3905 pmd_populate_kernel(mm, pmd, page_address(pte_page))
3906 #define pmd_populate_kernel(mm, pmd, pte) pmd_set(pmd, (unsigned long)(pte))
3907@@ -76,6 +82,7 @@ static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
3908 #else /* CONFIG_PPC_64K_PAGES */
3909
3910 #define pud_populate(mm, pud, pmd) pud_set(pud, (unsigned long)pmd)
3911+#define pud_populate_kernel(mm, pud, pmd) pud_populate((mm), (pud), (pmd))
3912
3913 static inline void pmd_populate_kernel(struct mm_struct *mm, pmd_t *pmd,
3914 pte_t *pte)
3915diff --git a/arch/powerpc/include/asm/pgtable.h b/arch/powerpc/include/asm/pgtable.h
3916index 2e0e411..7899c68 100644
3917--- a/arch/powerpc/include/asm/pgtable.h
3918+++ b/arch/powerpc/include/asm/pgtable.h
3919@@ -2,6 +2,7 @@
3920 #define _ASM_POWERPC_PGTABLE_H
3921 #ifdef __KERNEL__
3922
3923+#include <linux/const.h>
3924 #ifndef __ASSEMBLY__
3925 #include <asm/processor.h> /* For TASK_SIZE */
3926 #include <asm/mmu.h>
3927diff --git a/arch/powerpc/include/asm/pte-hash32.h b/arch/powerpc/include/asm/pte-hash32.h
3928index 4aad413..85d86bf 100644
3929--- a/arch/powerpc/include/asm/pte-hash32.h
3930+++ b/arch/powerpc/include/asm/pte-hash32.h
3931@@ -21,6 +21,7 @@
3932 #define _PAGE_FILE 0x004 /* when !present: nonlinear file mapping */
3933 #define _PAGE_USER 0x004 /* usermode access allowed */
3934 #define _PAGE_GUARDED 0x008 /* G: prohibit speculative access */
3935+#define _PAGE_EXEC _PAGE_GUARDED
3936 #define _PAGE_COHERENT 0x010 /* M: enforce memory coherence (SMP systems) */
3937 #define _PAGE_NO_CACHE 0x020 /* I: cache inhibit */
3938 #define _PAGE_WRITETHRU 0x040 /* W: cache write-through */
3939diff --git a/arch/powerpc/include/asm/reg.h b/arch/powerpc/include/asm/reg.h
3940index 6386086..6982225 100644
3941--- a/arch/powerpc/include/asm/reg.h
3942+++ b/arch/powerpc/include/asm/reg.h
3943@@ -212,6 +212,7 @@
3944 #define SPRN_DBCR 0x136 /* e300 Data Breakpoint Control Reg */
3945 #define SPRN_DSISR 0x012 /* Data Storage Interrupt Status Register */
3946 #define DSISR_NOHPTE 0x40000000 /* no translation found */
3947+#define DSISR_GUARDED 0x10000000 /* fetch from guarded storage */
3948 #define DSISR_PROTFAULT 0x08000000 /* protection fault */
3949 #define DSISR_ISSTORE 0x02000000 /* access was a store */
3950 #define DSISR_DABRMATCH 0x00400000 /* hit data breakpoint */
3951diff --git a/arch/powerpc/include/asm/thread_info.h b/arch/powerpc/include/asm/thread_info.h
3952index faf9352..ab2ccec 100644
3953--- a/arch/powerpc/include/asm/thread_info.h
3954+++ b/arch/powerpc/include/asm/thread_info.h
3955@@ -97,12 +97,14 @@ static inline struct thread_info *current_thread_info(void)
3956 #define TIF_PERFMON_CTXSW 6 /* perfmon needs ctxsw calls */
3957 #define TIF_SYSCALL_AUDIT 7 /* syscall auditing active */
3958 #define TIF_SINGLESTEP 8 /* singlestepping active */
3959-#define TIF_MEMDIE 9 /* is terminating due to OOM killer */
3960 #define TIF_SECCOMP 10 /* secure computing */
3961 #define TIF_RESTOREALL 11 /* Restore all regs (implies NOERROR) */
3962 #define TIF_NOERROR 12 /* Force successful syscall return */
3963 #define TIF_NOTIFY_RESUME 13 /* callback before returning to user */
3964 #define TIF_SYSCALL_TRACEPOINT 15 /* syscall tracepoint instrumentation */
3965+#define TIF_MEMDIE 16 /* is terminating due to OOM killer */
3966+/* mask must be expressable within 16 bits to satisfy 'andi' instruction reqs */
3967+#define TIF_GRSEC_SETXID 9 /* update credentials on syscall entry/exit */
3968
3969 /* as above, but as bit values */
3970 #define _TIF_SYSCALL_TRACE (1<<TIF_SYSCALL_TRACE)
3971@@ -119,8 +121,10 @@ static inline struct thread_info *current_thread_info(void)
3972 #define _TIF_NOERROR (1<<TIF_NOERROR)
3973 #define _TIF_NOTIFY_RESUME (1<<TIF_NOTIFY_RESUME)
3974 #define _TIF_SYSCALL_TRACEPOINT (1<<TIF_SYSCALL_TRACEPOINT)
3975+#define _TIF_GRSEC_SETXID (1<<TIF_GRSEC_SETXID)
3976 #define _TIF_SYSCALL_T_OR_A (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | \
3977- _TIF_SECCOMP | _TIF_SYSCALL_TRACEPOINT)
3978+ _TIF_SECCOMP | _TIF_SYSCALL_TRACEPOINT | \
3979+ _TIF_GRSEC_SETXID)
3980
3981 #define _TIF_USER_WORK_MASK (_TIF_SIGPENDING | _TIF_NEED_RESCHED | \
3982 _TIF_NOTIFY_RESUME)
3983diff --git a/arch/powerpc/include/asm/uaccess.h b/arch/powerpc/include/asm/uaccess.h
3984index 17bb40c..353c98b 100644
3985--- a/arch/powerpc/include/asm/uaccess.h
3986+++ b/arch/powerpc/include/asm/uaccess.h
3987@@ -13,6 +13,8 @@
3988 #define VERIFY_READ 0
3989 #define VERIFY_WRITE 1
3990
3991+extern void check_object_size(const void *ptr, unsigned long n, bool to);
3992+
3993 /*
3994 * The fs value determines whether argument validity checking should be
3995 * performed or not. If get_fs() == USER_DS, checking is performed, with
3996@@ -329,52 +331,6 @@ do { \
3997 extern unsigned long __copy_tofrom_user(void __user *to,
3998 const void __user *from, unsigned long size);
3999
4000-#ifndef __powerpc64__
4001-
4002-static inline unsigned long copy_from_user(void *to,
4003- const void __user *from, unsigned long n)
4004-{
4005- unsigned long over;
4006-
4007- if (access_ok(VERIFY_READ, from, n))
4008- return __copy_tofrom_user((__force void __user *)to, from, n);
4009- if ((unsigned long)from < TASK_SIZE) {
4010- over = (unsigned long)from + n - TASK_SIZE;
4011- return __copy_tofrom_user((__force void __user *)to, from,
4012- n - over) + over;
4013- }
4014- return n;
4015-}
4016-
4017-static inline unsigned long copy_to_user(void __user *to,
4018- const void *from, unsigned long n)
4019-{
4020- unsigned long over;
4021-
4022- if (access_ok(VERIFY_WRITE, to, n))
4023- return __copy_tofrom_user(to, (__force void __user *)from, n);
4024- if ((unsigned long)to < TASK_SIZE) {
4025- over = (unsigned long)to + n - TASK_SIZE;
4026- return __copy_tofrom_user(to, (__force void __user *)from,
4027- n - over) + over;
4028- }
4029- return n;
4030-}
4031-
4032-#else /* __powerpc64__ */
4033-
4034-#define __copy_in_user(to, from, size) \
4035- __copy_tofrom_user((to), (from), (size))
4036-
4037-extern unsigned long copy_from_user(void *to, const void __user *from,
4038- unsigned long n);
4039-extern unsigned long copy_to_user(void __user *to, const void *from,
4040- unsigned long n);
4041-extern unsigned long copy_in_user(void __user *to, const void __user *from,
4042- unsigned long n);
4043-
4044-#endif /* __powerpc64__ */
4045-
4046 static inline unsigned long __copy_from_user_inatomic(void *to,
4047 const void __user *from, unsigned long n)
4048 {
4049@@ -398,6 +354,10 @@ static inline unsigned long __copy_from_user_inatomic(void *to,
4050 if (ret == 0)
4051 return 0;
4052 }
4053+
4054+ if (!__builtin_constant_p(n))
4055+ check_object_size(to, n, false);
4056+
4057 return __copy_tofrom_user((__force void __user *)to, from, n);
4058 }
4059
4060@@ -424,6 +384,10 @@ static inline unsigned long __copy_to_user_inatomic(void __user *to,
4061 if (ret == 0)
4062 return 0;
4063 }
4064+
4065+ if (!__builtin_constant_p(n))
4066+ check_object_size(from, n, true);
4067+
4068 return __copy_tofrom_user(to, (__force const void __user *)from, n);
4069 }
4070
4071@@ -441,6 +405,92 @@ static inline unsigned long __copy_to_user(void __user *to,
4072 return __copy_to_user_inatomic(to, from, size);
4073 }
4074
4075+#ifndef __powerpc64__
4076+
4077+static inline unsigned long __must_check copy_from_user(void *to,
4078+ const void __user *from, unsigned long n)
4079+{
4080+ unsigned long over;
4081+
4082+ if ((long)n < 0)
4083+ return n;
4084+
4085+ if (access_ok(VERIFY_READ, from, n)) {
4086+ if (!__builtin_constant_p(n))
4087+ check_object_size(to, n, false);
4088+ return __copy_tofrom_user((__force void __user *)to, from, n);
4089+ }
4090+ if ((unsigned long)from < TASK_SIZE) {
4091+ over = (unsigned long)from + n - TASK_SIZE;
4092+ if (!__builtin_constant_p(n - over))
4093+ check_object_size(to, n - over, false);
4094+ return __copy_tofrom_user((__force void __user *)to, from,
4095+ n - over) + over;
4096+ }
4097+ return n;
4098+}
4099+
4100+static inline unsigned long __must_check copy_to_user(void __user *to,
4101+ const void *from, unsigned long n)
4102+{
4103+ unsigned long over;
4104+
4105+ if ((long)n < 0)
4106+ return n;
4107+
4108+ if (access_ok(VERIFY_WRITE, to, n)) {
4109+ if (!__builtin_constant_p(n))
4110+ check_object_size(from, n, true);
4111+ return __copy_tofrom_user(to, (__force void __user *)from, n);
4112+ }
4113+ if ((unsigned long)to < TASK_SIZE) {
4114+ over = (unsigned long)to + n - TASK_SIZE;
4115+ if (!__builtin_constant_p(n))
4116+ check_object_size(from, n - over, true);
4117+ return __copy_tofrom_user(to, (__force void __user *)from,
4118+ n - over) + over;
4119+ }
4120+ return n;
4121+}
4122+
4123+#else /* __powerpc64__ */
4124+
4125+#define __copy_in_user(to, from, size) \
4126+ __copy_tofrom_user((to), (from), (size))
4127+
4128+static inline unsigned long __must_check copy_from_user(void *to, const void __user *from, unsigned long n)
4129+{
4130+ if ((long)n < 0 || n > INT_MAX)
4131+ return n;
4132+
4133+ if (!__builtin_constant_p(n))
4134+ check_object_size(to, n, false);
4135+
4136+ if (likely(access_ok(VERIFY_READ, from, n)))
4137+ n = __copy_from_user(to, from, n);
4138+ else
4139+ memset(to, 0, n);
4140+ return n;
4141+}
4142+
4143+static inline unsigned long __must_check copy_to_user(void __user *to, const void *from, unsigned long n)
4144+{
4145+ if ((long)n < 0 || n > INT_MAX)
4146+ return n;
4147+
4148+ if (likely(access_ok(VERIFY_WRITE, to, n))) {
4149+ if (!__builtin_constant_p(n))
4150+ check_object_size(from, n, true);
4151+ n = __copy_to_user(to, from, n);
4152+ }
4153+ return n;
4154+}
4155+
4156+extern unsigned long copy_in_user(void __user *to, const void __user *from,
4157+ unsigned long n);
4158+
4159+#endif /* __powerpc64__ */
4160+
4161 extern unsigned long __clear_user(void __user *addr, unsigned long size);
4162
4163 static inline unsigned long clear_user(void __user *addr, unsigned long size)
4164diff --git a/arch/powerpc/kernel/exceptions-64e.S b/arch/powerpc/kernel/exceptions-64e.S
4165index 98be7f0..8ef62de 100644
4166--- a/arch/powerpc/kernel/exceptions-64e.S
4167+++ b/arch/powerpc/kernel/exceptions-64e.S
4168@@ -661,6 +661,7 @@ storage_fault_common:
4169 std r14,_DAR(r1)
4170 std r15,_DSISR(r1)
4171 addi r3,r1,STACK_FRAME_OVERHEAD
4172+ bl .save_nvgprs
4173 mr r4,r14
4174 mr r5,r15
4175 ld r14,PACA_EXGEN+EX_R14(r13)
4176@@ -669,8 +670,7 @@ storage_fault_common:
4177 cmpdi r3,0
4178 bne- 1f
4179 b .ret_from_except_lite
4180-1: bl .save_nvgprs
4181- mr r5,r3
4182+1: mr r5,r3
4183 addi r3,r1,STACK_FRAME_OVERHEAD
4184 ld r4,_DAR(r1)
4185 bl .bad_page_fault
4186diff --git a/arch/powerpc/kernel/exceptions-64s.S b/arch/powerpc/kernel/exceptions-64s.S
4187index 39aa97d..dc916ee 100644
4188--- a/arch/powerpc/kernel/exceptions-64s.S
4189+++ b/arch/powerpc/kernel/exceptions-64s.S
4190@@ -890,10 +890,10 @@ handle_page_fault:
4191 11: ld r4,_DAR(r1)
4192 ld r5,_DSISR(r1)
4193 addi r3,r1,STACK_FRAME_OVERHEAD
4194+ bl .save_nvgprs
4195 bl .do_page_fault
4196 cmpdi r3,0
4197 beq+ 12f
4198- bl .save_nvgprs
4199 mr r5,r3
4200 addi r3,r1,STACK_FRAME_OVERHEAD
4201 lwz r4,_DAR(r1)
4202diff --git a/arch/powerpc/kernel/module_32.c b/arch/powerpc/kernel/module_32.c
4203index 2e3200c..72095ce 100644
4204--- a/arch/powerpc/kernel/module_32.c
4205+++ b/arch/powerpc/kernel/module_32.c
4206@@ -162,7 +162,7 @@ int module_frob_arch_sections(Elf32_Ehdr *hdr,
4207 me->arch.core_plt_section = i;
4208 }
4209 if (!me->arch.core_plt_section || !me->arch.init_plt_section) {
4210- printk("Module doesn't contain .plt or .init.plt sections.\n");
4211+ printk("Module %s doesn't contain .plt or .init.plt sections.\n", me->name);
4212 return -ENOEXEC;
4213 }
4214
4215@@ -192,11 +192,16 @@ static uint32_t do_plt_call(void *location,
4216
4217 DEBUGP("Doing plt for call to 0x%x at 0x%x\n", val, (unsigned int)location);
4218 /* Init, or core PLT? */
4219- if (location >= mod->module_core
4220- && location < mod->module_core + mod->core_size)
4221+ if ((location >= mod->module_core_rx && location < mod->module_core_rx + mod->core_size_rx) ||
4222+ (location >= mod->module_core_rw && location < mod->module_core_rw + mod->core_size_rw))
4223 entry = (void *)sechdrs[mod->arch.core_plt_section].sh_addr;
4224- else
4225+ else if ((location >= mod->module_init_rx && location < mod->module_init_rx + mod->init_size_rx) ||
4226+ (location >= mod->module_init_rw && location < mod->module_init_rw + mod->init_size_rw))
4227 entry = (void *)sechdrs[mod->arch.init_plt_section].sh_addr;
4228+ else {
4229+ printk(KERN_ERR "%s: invalid R_PPC_REL24 entry found\n", mod->name);
4230+ return ~0UL;
4231+ }
4232
4233 /* Find this entry, or if that fails, the next avail. entry */
4234 while (entry->jump[0]) {
4235diff --git a/arch/powerpc/kernel/process.c b/arch/powerpc/kernel/process.c
4236index 1a1f2dd..f4d1bb4 100644
4237--- a/arch/powerpc/kernel/process.c
4238+++ b/arch/powerpc/kernel/process.c
4239@@ -681,8 +681,8 @@ void show_regs(struct pt_regs * regs)
4240 * Lookup NIP late so we have the best change of getting the
4241 * above info out without failing
4242 */
4243- printk("NIP ["REG"] %pS\n", regs->nip, (void *)regs->nip);
4244- printk("LR ["REG"] %pS\n", regs->link, (void *)regs->link);
4245+ printk("NIP ["REG"] %pA\n", regs->nip, (void *)regs->nip);
4246+ printk("LR ["REG"] %pA\n", regs->link, (void *)regs->link);
4247 #endif
4248 show_stack(current, (unsigned long *) regs->gpr[1]);
4249 if (!user_mode(regs))
4250@@ -1181,10 +1181,10 @@ void show_stack(struct task_struct *tsk, unsigned long *stack)
4251 newsp = stack[0];
4252 ip = stack[STACK_FRAME_LR_SAVE];
4253 if (!firstframe || ip != lr) {
4254- printk("["REG"] ["REG"] %pS", sp, ip, (void *)ip);
4255+ printk("["REG"] ["REG"] %pA", sp, ip, (void *)ip);
4256 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
4257 if ((ip == rth || ip == mrth) && curr_frame >= 0) {
4258- printk(" (%pS)",
4259+ printk(" (%pA)",
4260 (void *)current->ret_stack[curr_frame].ret);
4261 curr_frame--;
4262 }
4263@@ -1204,7 +1204,7 @@ void show_stack(struct task_struct *tsk, unsigned long *stack)
4264 struct pt_regs *regs = (struct pt_regs *)
4265 (sp + STACK_FRAME_OVERHEAD);
4266 lr = regs->link;
4267- printk("--- Exception: %lx at %pS\n LR = %pS\n",
4268+ printk("--- Exception: %lx at %pA\n LR = %pA\n",
4269 regs->trap, (void *)regs->nip, (void *)lr);
4270 firstframe = 1;
4271 }
4272@@ -1246,58 +1246,3 @@ void __ppc64_runlatch_off(void)
4273 mtspr(SPRN_CTRLT, ctrl);
4274 }
4275 #endif /* CONFIG_PPC64 */
4276-
4277-unsigned long arch_align_stack(unsigned long sp)
4278-{
4279- if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
4280- sp -= get_random_int() & ~PAGE_MASK;
4281- return sp & ~0xf;
4282-}
4283-
4284-static inline unsigned long brk_rnd(void)
4285-{
4286- unsigned long rnd = 0;
4287-
4288- /* 8MB for 32bit, 1GB for 64bit */
4289- if (is_32bit_task())
4290- rnd = (long)(get_random_int() % (1<<(23-PAGE_SHIFT)));
4291- else
4292- rnd = (long)(get_random_int() % (1<<(30-PAGE_SHIFT)));
4293-
4294- return rnd << PAGE_SHIFT;
4295-}
4296-
4297-unsigned long arch_randomize_brk(struct mm_struct *mm)
4298-{
4299- unsigned long base = mm->brk;
4300- unsigned long ret;
4301-
4302-#ifdef CONFIG_PPC_STD_MMU_64
4303- /*
4304- * If we are using 1TB segments and we are allowed to randomise
4305- * the heap, we can put it above 1TB so it is backed by a 1TB
4306- * segment. Otherwise the heap will be in the bottom 1TB
4307- * which always uses 256MB segments and this may result in a
4308- * performance penalty.
4309- */
4310- if (!is_32bit_task() && (mmu_highuser_ssize == MMU_SEGSIZE_1T))
4311- base = max_t(unsigned long, mm->brk, 1UL << SID_SHIFT_1T);
4312-#endif
4313-
4314- ret = PAGE_ALIGN(base + brk_rnd());
4315-
4316- if (ret < mm->brk)
4317- return mm->brk;
4318-
4319- return ret;
4320-}
4321-
4322-unsigned long randomize_et_dyn(unsigned long base)
4323-{
4324- unsigned long ret = PAGE_ALIGN(base + brk_rnd());
4325-
4326- if (ret < base)
4327- return base;
4328-
4329- return ret;
4330-}
4331diff --git a/arch/powerpc/kernel/ptrace.c b/arch/powerpc/kernel/ptrace.c
4332index c10fc28..c4ef063 100644
4333--- a/arch/powerpc/kernel/ptrace.c
4334+++ b/arch/powerpc/kernel/ptrace.c
4335@@ -1660,6 +1660,10 @@ long arch_ptrace(struct task_struct *child, long request,
4336 return ret;
4337 }
4338
4339+#ifdef CONFIG_GRKERNSEC_SETXID
4340+extern void gr_delayed_cred_worker(void);
4341+#endif
4342+
4343 /*
4344 * We must return the syscall number to actually look up in the table.
4345 * This can be -1L to skip running any syscall at all.
4346@@ -1670,6 +1674,11 @@ long do_syscall_trace_enter(struct pt_regs *regs)
4347
4348 secure_computing_strict(regs->gpr[0]);
4349
4350+#ifdef CONFIG_GRKERNSEC_SETXID
4351+ if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
4352+ gr_delayed_cred_worker();
4353+#endif
4354+
4355 if (test_thread_flag(TIF_SYSCALL_TRACE) &&
4356 tracehook_report_syscall_entry(regs))
4357 /*
4358@@ -1704,6 +1713,11 @@ void do_syscall_trace_leave(struct pt_regs *regs)
4359 {
4360 int step;
4361
4362+#ifdef CONFIG_GRKERNSEC_SETXID
4363+ if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
4364+ gr_delayed_cred_worker();
4365+#endif
4366+
4367 audit_syscall_exit(regs);
4368
4369 if (unlikely(test_thread_flag(TIF_SYSCALL_TRACEPOINT)))
4370diff --git a/arch/powerpc/kernel/signal_32.c b/arch/powerpc/kernel/signal_32.c
4371index 8b4c049..dcd6ef3 100644
4372--- a/arch/powerpc/kernel/signal_32.c
4373+++ b/arch/powerpc/kernel/signal_32.c
4374@@ -852,7 +852,7 @@ int handle_rt_signal32(unsigned long sig, struct k_sigaction *ka,
4375 /* Save user registers on the stack */
4376 frame = &rt_sf->uc.uc_mcontext;
4377 addr = frame;
4378- if (vdso32_rt_sigtramp && current->mm->context.vdso_base) {
4379+ if (vdso32_rt_sigtramp && current->mm->context.vdso_base != ~0UL) {
4380 if (save_user_regs(regs, frame, 0, 1))
4381 goto badframe;
4382 regs->link = current->mm->context.vdso_base + vdso32_rt_sigtramp;
4383diff --git a/arch/powerpc/kernel/signal_64.c b/arch/powerpc/kernel/signal_64.c
4384index d183f87..1867f1a 100644
4385--- a/arch/powerpc/kernel/signal_64.c
4386+++ b/arch/powerpc/kernel/signal_64.c
4387@@ -430,7 +430,7 @@ int handle_rt_signal64(int signr, struct k_sigaction *ka, siginfo_t *info,
4388 current->thread.fpscr.val = 0;
4389
4390 /* Set up to return from userspace. */
4391- if (vdso64_rt_sigtramp && current->mm->context.vdso_base) {
4392+ if (vdso64_rt_sigtramp && current->mm->context.vdso_base != ~0UL) {
4393 regs->link = current->mm->context.vdso_base + vdso64_rt_sigtramp;
4394 } else {
4395 err |= setup_trampoline(__NR_rt_sigreturn, &frame->tramp[0]);
4396diff --git a/arch/powerpc/kernel/traps.c b/arch/powerpc/kernel/traps.c
4397index ae0843f..f16372c 100644
4398--- a/arch/powerpc/kernel/traps.c
4399+++ b/arch/powerpc/kernel/traps.c
4400@@ -133,6 +133,8 @@ static unsigned __kprobes long oops_begin(struct pt_regs *regs)
4401 return flags;
4402 }
4403
4404+extern void gr_handle_kernel_exploit(void);
4405+
4406 static void __kprobes oops_end(unsigned long flags, struct pt_regs *regs,
4407 int signr)
4408 {
4409@@ -182,6 +184,9 @@ static void __kprobes oops_end(unsigned long flags, struct pt_regs *regs,
4410 panic("Fatal exception in interrupt");
4411 if (panic_on_oops)
4412 panic("Fatal exception");
4413+
4414+ gr_handle_kernel_exploit();
4415+
4416 do_exit(signr);
4417 }
4418
4419diff --git a/arch/powerpc/kernel/vdso.c b/arch/powerpc/kernel/vdso.c
4420index b67db22..38825d2 100644
4421--- a/arch/powerpc/kernel/vdso.c
4422+++ b/arch/powerpc/kernel/vdso.c
4423@@ -34,6 +34,7 @@
4424 #include <asm/firmware.h>
4425 #include <asm/vdso.h>
4426 #include <asm/vdso_datapage.h>
4427+#include <asm/mman.h>
4428
4429 #include "setup.h"
4430
4431@@ -218,7 +219,7 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
4432 vdso_base = VDSO32_MBASE;
4433 #endif
4434
4435- current->mm->context.vdso_base = 0;
4436+ current->mm->context.vdso_base = ~0UL;
4437
4438 /* vDSO has a problem and was disabled, just don't "enable" it for the
4439 * process
4440@@ -238,7 +239,7 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
4441 vdso_base = get_unmapped_area(NULL, vdso_base,
4442 (vdso_pages << PAGE_SHIFT) +
4443 ((VDSO_ALIGNMENT - 1) & PAGE_MASK),
4444- 0, 0);
4445+ 0, MAP_PRIVATE | MAP_EXECUTABLE);
4446 if (IS_ERR_VALUE(vdso_base)) {
4447 rc = vdso_base;
4448 goto fail_mmapsem;
4449diff --git a/arch/powerpc/lib/usercopy_64.c b/arch/powerpc/lib/usercopy_64.c
4450index 5eea6f3..5d10396 100644
4451--- a/arch/powerpc/lib/usercopy_64.c
4452+++ b/arch/powerpc/lib/usercopy_64.c
4453@@ -9,22 +9,6 @@
4454 #include <linux/module.h>
4455 #include <asm/uaccess.h>
4456
4457-unsigned long copy_from_user(void *to, const void __user *from, unsigned long n)
4458-{
4459- if (likely(access_ok(VERIFY_READ, from, n)))
4460- n = __copy_from_user(to, from, n);
4461- else
4462- memset(to, 0, n);
4463- return n;
4464-}
4465-
4466-unsigned long copy_to_user(void __user *to, const void *from, unsigned long n)
4467-{
4468- if (likely(access_ok(VERIFY_WRITE, to, n)))
4469- n = __copy_to_user(to, from, n);
4470- return n;
4471-}
4472-
4473 unsigned long copy_in_user(void __user *to, const void __user *from,
4474 unsigned long n)
4475 {
4476@@ -35,7 +19,5 @@ unsigned long copy_in_user(void __user *to, const void __user *from,
4477 return n;
4478 }
4479
4480-EXPORT_SYMBOL(copy_from_user);
4481-EXPORT_SYMBOL(copy_to_user);
4482 EXPORT_SYMBOL(copy_in_user);
4483
4484diff --git a/arch/powerpc/mm/fault.c b/arch/powerpc/mm/fault.c
4485index 08ffcf5..a0ab912 100644
4486--- a/arch/powerpc/mm/fault.c
4487+++ b/arch/powerpc/mm/fault.c
4488@@ -32,6 +32,10 @@
4489 #include <linux/perf_event.h>
4490 #include <linux/magic.h>
4491 #include <linux/ratelimit.h>
4492+#include <linux/slab.h>
4493+#include <linux/pagemap.h>
4494+#include <linux/compiler.h>
4495+#include <linux/unistd.h>
4496
4497 #include <asm/firmware.h>
4498 #include <asm/page.h>
4499@@ -68,6 +72,33 @@ static inline int notify_page_fault(struct pt_regs *regs)
4500 }
4501 #endif
4502
4503+#ifdef CONFIG_PAX_PAGEEXEC
4504+/*
4505+ * PaX: decide what to do with offenders (regs->nip = fault address)
4506+ *
4507+ * returns 1 when task should be killed
4508+ */
4509+static int pax_handle_fetch_fault(struct pt_regs *regs)
4510+{
4511+ return 1;
4512+}
4513+
4514+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
4515+{
4516+ unsigned long i;
4517+
4518+ printk(KERN_ERR "PAX: bytes at PC: ");
4519+ for (i = 0; i < 5; i++) {
4520+ unsigned int c;
4521+ if (get_user(c, (unsigned int __user *)pc+i))
4522+ printk(KERN_CONT "???????? ");
4523+ else
4524+ printk(KERN_CONT "%08x ", c);
4525+ }
4526+ printk("\n");
4527+}
4528+#endif
4529+
4530 /*
4531 * Check whether the instruction at regs->nip is a store using
4532 * an update addressing form which will update r1.
4533@@ -215,7 +246,7 @@ int __kprobes do_page_fault(struct pt_regs *regs, unsigned long address,
4534 * indicate errors in DSISR but can validly be set in SRR1.
4535 */
4536 if (trap == 0x400)
4537- error_code &= 0x48200000;
4538+ error_code &= 0x58200000;
4539 else
4540 is_write = error_code & DSISR_ISSTORE;
4541 #else
4542@@ -366,7 +397,7 @@ good_area:
4543 * "undefined". Of those that can be set, this is the only
4544 * one which seems bad.
4545 */
4546- if (error_code & 0x10000000)
4547+ if (error_code & DSISR_GUARDED)
4548 /* Guarded storage error. */
4549 goto bad_area;
4550 #endif /* CONFIG_8xx */
4551@@ -381,7 +412,7 @@ good_area:
4552 * processors use the same I/D cache coherency mechanism
4553 * as embedded.
4554 */
4555- if (error_code & DSISR_PROTFAULT)
4556+ if (error_code & (DSISR_PROTFAULT | DSISR_GUARDED))
4557 goto bad_area;
4558 #endif /* CONFIG_PPC_STD_MMU */
4559
4560@@ -463,6 +494,23 @@ bad_area:
4561 bad_area_nosemaphore:
4562 /* User mode accesses cause a SIGSEGV */
4563 if (user_mode(regs)) {
4564+
4565+#ifdef CONFIG_PAX_PAGEEXEC
4566+ if (mm->pax_flags & MF_PAX_PAGEEXEC) {
4567+#ifdef CONFIG_PPC_STD_MMU
4568+ if (is_exec && (error_code & (DSISR_PROTFAULT | DSISR_GUARDED))) {
4569+#else
4570+ if (is_exec && regs->nip == address) {
4571+#endif
4572+ switch (pax_handle_fetch_fault(regs)) {
4573+ }
4574+
4575+ pax_report_fault(regs, (void *)regs->nip, (void *)regs->gpr[PT_R1]);
4576+ do_group_exit(SIGKILL);
4577+ }
4578+ }
4579+#endif
4580+
4581 _exception(SIGSEGV, regs, code, address);
4582 return 0;
4583 }
4584diff --git a/arch/powerpc/mm/mmap_64.c b/arch/powerpc/mm/mmap_64.c
4585index 67a42ed..1c7210c 100644
4586--- a/arch/powerpc/mm/mmap_64.c
4587+++ b/arch/powerpc/mm/mmap_64.c
4588@@ -91,10 +91,22 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
4589 */
4590 if (mmap_is_legacy()) {
4591 mm->mmap_base = TASK_UNMAPPED_BASE;
4592+
4593+#ifdef CONFIG_PAX_RANDMMAP
4594+ if (mm->pax_flags & MF_PAX_RANDMMAP)
4595+ mm->mmap_base += mm->delta_mmap;
4596+#endif
4597+
4598 mm->get_unmapped_area = arch_get_unmapped_area;
4599 mm->unmap_area = arch_unmap_area;
4600 } else {
4601 mm->mmap_base = mmap_base();
4602+
4603+#ifdef CONFIG_PAX_RANDMMAP
4604+ if (mm->pax_flags & MF_PAX_RANDMMAP)
4605+ mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
4606+#endif
4607+
4608 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
4609 mm->unmap_area = arch_unmap_area_topdown;
4610 }
4611diff --git a/arch/powerpc/mm/slice.c b/arch/powerpc/mm/slice.c
4612index 73709f7..6b90313 100644
4613--- a/arch/powerpc/mm/slice.c
4614+++ b/arch/powerpc/mm/slice.c
4615@@ -98,7 +98,7 @@ static int slice_area_is_free(struct mm_struct *mm, unsigned long addr,
4616 if ((mm->task_size - len) < addr)
4617 return 0;
4618 vma = find_vma(mm, addr);
4619- return (!vma || (addr + len) <= vma->vm_start);
4620+ return check_heap_stack_gap(vma, addr, len);
4621 }
4622
4623 static int slice_low_has_vma(struct mm_struct *mm, unsigned long slice)
4624@@ -256,7 +256,7 @@ full_search:
4625 addr = _ALIGN_UP(addr + 1, 1ul << SLICE_HIGH_SHIFT);
4626 continue;
4627 }
4628- if (!vma || addr + len <= vma->vm_start) {
4629+ if (check_heap_stack_gap(vma, addr, len)) {
4630 /*
4631 * Remember the place where we stopped the search:
4632 */
4633@@ -313,10 +313,14 @@ static unsigned long slice_find_area_topdown(struct mm_struct *mm,
4634 }
4635 }
4636
4637- addr = mm->mmap_base;
4638- while (addr > len) {
4639+ if (mm->mmap_base < len)
4640+ addr = -ENOMEM;
4641+ else
4642+ addr = mm->mmap_base - len;
4643+
4644+ while (!IS_ERR_VALUE(addr)) {
4645 /* Go down by chunk size */
4646- addr = _ALIGN_DOWN(addr - len, 1ul << pshift);
4647+ addr = _ALIGN_DOWN(addr, 1ul << pshift);
4648
4649 /* Check for hit with different page size */
4650 mask = slice_range_to_mask(addr, len);
4651@@ -336,7 +340,7 @@ static unsigned long slice_find_area_topdown(struct mm_struct *mm,
4652 * return with success:
4653 */
4654 vma = find_vma(mm, addr);
4655- if (!vma || (addr + len) <= vma->vm_start) {
4656+ if (check_heap_stack_gap(vma, addr, len)) {
4657 /* remember the address as a hint for next time */
4658 if (use_cache)
4659 mm->free_area_cache = addr;
4660@@ -348,7 +352,7 @@ static unsigned long slice_find_area_topdown(struct mm_struct *mm,
4661 mm->cached_hole_size = vma->vm_start - addr;
4662
4663 /* try just below the current vma->vm_start */
4664- addr = vma->vm_start;
4665+ addr = skip_heap_stack_gap(vma, len);
4666 }
4667
4668 /*
4669@@ -426,6 +430,11 @@ unsigned long slice_get_unmapped_area(unsigned long addr, unsigned long len,
4670 if (fixed && addr > (mm->task_size - len))
4671 return -EINVAL;
4672
4673+#ifdef CONFIG_PAX_RANDMMAP
4674+ if (!fixed && (mm->pax_flags & MF_PAX_RANDMMAP))
4675+ addr = 0;
4676+#endif
4677+
4678 /* If hint, make sure it matches our alignment restrictions */
4679 if (!fixed && addr) {
4680 addr = _ALIGN_UP(addr, 1ul << pshift);
4681diff --git a/arch/s390/include/asm/atomic.h b/arch/s390/include/asm/atomic.h
4682index c797832..ce575c8 100644
4683--- a/arch/s390/include/asm/atomic.h
4684+++ b/arch/s390/include/asm/atomic.h
4685@@ -326,6 +326,16 @@ static inline long long atomic64_dec_if_positive(atomic64_t *v)
4686 #define atomic64_dec_and_test(_v) (atomic64_sub_return(1, _v) == 0)
4687 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
4688
4689+#define atomic64_read_unchecked(v) atomic64_read(v)
4690+#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
4691+#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
4692+#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
4693+#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
4694+#define atomic64_inc_unchecked(v) atomic64_inc(v)
4695+#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
4696+#define atomic64_dec_unchecked(v) atomic64_dec(v)
4697+#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
4698+
4699 #define smp_mb__before_atomic_dec() smp_mb()
4700 #define smp_mb__after_atomic_dec() smp_mb()
4701 #define smp_mb__before_atomic_inc() smp_mb()
4702diff --git a/arch/s390/include/asm/cache.h b/arch/s390/include/asm/cache.h
4703index 4d7ccac..d03d0ad 100644
4704--- a/arch/s390/include/asm/cache.h
4705+++ b/arch/s390/include/asm/cache.h
4706@@ -9,8 +9,10 @@
4707 #ifndef __ARCH_S390_CACHE_H
4708 #define __ARCH_S390_CACHE_H
4709
4710-#define L1_CACHE_BYTES 256
4711+#include <linux/const.h>
4712+
4713 #define L1_CACHE_SHIFT 8
4714+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
4715 #define NET_SKB_PAD 32
4716
4717 #define __read_mostly __attribute__((__section__(".data..read_mostly")))
4718diff --git a/arch/s390/include/asm/elf.h b/arch/s390/include/asm/elf.h
4719index 9b94a16..63d4034 100644
4720--- a/arch/s390/include/asm/elf.h
4721+++ b/arch/s390/include/asm/elf.h
4722@@ -159,8 +159,14 @@ extern unsigned int vdso_enabled;
4723 the loader. We need to make sure that it is out of the way of the program
4724 that it will "exec", and that there is sufficient room for the brk. */
4725
4726-extern unsigned long randomize_et_dyn(unsigned long base);
4727-#define ELF_ET_DYN_BASE (randomize_et_dyn(STACK_TOP / 3 * 2))
4728+#define ELF_ET_DYN_BASE (STACK_TOP / 3 * 2)
4729+
4730+#ifdef CONFIG_PAX_ASLR
4731+#define PAX_ELF_ET_DYN_BASE (test_thread_flag(TIF_31BIT) ? 0x10000UL : 0x80000000UL)
4732+
4733+#define PAX_DELTA_MMAP_LEN (test_thread_flag(TIF_31BIT) ? 15 : 26)
4734+#define PAX_DELTA_STACK_LEN (test_thread_flag(TIF_31BIT) ? 15 : 26)
4735+#endif
4736
4737 /* This yields a mask that user programs can use to figure out what
4738 instruction set this CPU supports. */
4739@@ -209,7 +215,4 @@ struct linux_binprm;
4740 #define ARCH_HAS_SETUP_ADDITIONAL_PAGES 1
4741 int arch_setup_additional_pages(struct linux_binprm *, int);
4742
4743-extern unsigned long arch_randomize_brk(struct mm_struct *mm);
4744-#define arch_randomize_brk arch_randomize_brk
4745-
4746 #endif
4747diff --git a/arch/s390/include/asm/exec.h b/arch/s390/include/asm/exec.h
4748index c4a93d6..4d2a9b4 100644
4749--- a/arch/s390/include/asm/exec.h
4750+++ b/arch/s390/include/asm/exec.h
4751@@ -7,6 +7,6 @@
4752 #ifndef __ASM_EXEC_H
4753 #define __ASM_EXEC_H
4754
4755-extern unsigned long arch_align_stack(unsigned long sp);
4756+#define arch_align_stack(x) ((x) & ~0xfUL)
4757
4758 #endif /* __ASM_EXEC_H */
4759diff --git a/arch/s390/include/asm/uaccess.h b/arch/s390/include/asm/uaccess.h
4760index a8ab18b..75ddbf0 100644
4761--- a/arch/s390/include/asm/uaccess.h
4762+++ b/arch/s390/include/asm/uaccess.h
4763@@ -239,6 +239,10 @@ static inline unsigned long __must_check
4764 copy_to_user(void __user *to, const void *from, unsigned long n)
4765 {
4766 might_fault();
4767+
4768+ if ((long)n < 0)
4769+ return n;
4770+
4771 if (access_ok(VERIFY_WRITE, to, n))
4772 n = __copy_to_user(to, from, n);
4773 return n;
4774@@ -264,6 +268,9 @@ copy_to_user(void __user *to, const void *from, unsigned long n)
4775 static inline unsigned long __must_check
4776 __copy_from_user(void *to, const void __user *from, unsigned long n)
4777 {
4778+ if ((long)n < 0)
4779+ return n;
4780+
4781 if (__builtin_constant_p(n) && (n <= 256))
4782 return uaccess.copy_from_user_small(n, from, to);
4783 else
4784@@ -295,10 +302,14 @@ __compiletime_warning("copy_from_user() buffer size is not provably correct")
4785 static inline unsigned long __must_check
4786 copy_from_user(void *to, const void __user *from, unsigned long n)
4787 {
4788- unsigned int sz = __compiletime_object_size(to);
4789+ size_t sz = __compiletime_object_size(to);
4790
4791 might_fault();
4792- if (unlikely(sz != -1 && sz < n)) {
4793+
4794+ if ((long)n < 0)
4795+ return n;
4796+
4797+ if (unlikely(sz != (size_t)-1 && sz < n)) {
4798 copy_from_user_overflow();
4799 return n;
4800 }
4801diff --git a/arch/s390/kernel/module.c b/arch/s390/kernel/module.c
4802index 46412b1..e32874f 100644
4803--- a/arch/s390/kernel/module.c
4804+++ b/arch/s390/kernel/module.c
4805@@ -160,11 +160,11 @@ module_frob_arch_sections(Elf_Ehdr *hdr, Elf_Shdr *sechdrs,
4806
4807 /* Increase core size by size of got & plt and set start
4808 offsets for got and plt. */
4809- me->core_size = ALIGN(me->core_size, 4);
4810- me->arch.got_offset = me->core_size;
4811- me->core_size += me->arch.got_size;
4812- me->arch.plt_offset = me->core_size;
4813- me->core_size += me->arch.plt_size;
4814+ me->core_size_rw = ALIGN(me->core_size_rw, 4);
4815+ me->arch.got_offset = me->core_size_rw;
4816+ me->core_size_rw += me->arch.got_size;
4817+ me->arch.plt_offset = me->core_size_rx;
4818+ me->core_size_rx += me->arch.plt_size;
4819 return 0;
4820 }
4821
4822@@ -241,7 +241,7 @@ apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
4823 if (info->got_initialized == 0) {
4824 Elf_Addr *gotent;
4825
4826- gotent = me->module_core + me->arch.got_offset +
4827+ gotent = me->module_core_rw + me->arch.got_offset +
4828 info->got_offset;
4829 *gotent = val;
4830 info->got_initialized = 1;
4831@@ -265,7 +265,7 @@ apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
4832 else if (r_type == R_390_GOTENT ||
4833 r_type == R_390_GOTPLTENT)
4834 *(unsigned int *) loc =
4835- (val + (Elf_Addr) me->module_core - loc) >> 1;
4836+ (val + (Elf_Addr) me->module_core_rw - loc) >> 1;
4837 else if (r_type == R_390_GOT64 ||
4838 r_type == R_390_GOTPLT64)
4839 *(unsigned long *) loc = val;
4840@@ -279,7 +279,7 @@ apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
4841 case R_390_PLTOFF64: /* 16 bit offset from GOT to PLT. */
4842 if (info->plt_initialized == 0) {
4843 unsigned int *ip;
4844- ip = me->module_core + me->arch.plt_offset +
4845+ ip = me->module_core_rx + me->arch.plt_offset +
4846 info->plt_offset;
4847 #ifndef CONFIG_64BIT
4848 ip[0] = 0x0d105810; /* basr 1,0; l 1,6(1); br 1 */
4849@@ -304,7 +304,7 @@ apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
4850 val - loc + 0xffffUL < 0x1ffffeUL) ||
4851 (r_type == R_390_PLT32DBL &&
4852 val - loc + 0xffffffffULL < 0x1fffffffeULL)))
4853- val = (Elf_Addr) me->module_core +
4854+ val = (Elf_Addr) me->module_core_rx +
4855 me->arch.plt_offset +
4856 info->plt_offset;
4857 val += rela->r_addend - loc;
4858@@ -326,7 +326,7 @@ apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
4859 case R_390_GOTOFF32: /* 32 bit offset to GOT. */
4860 case R_390_GOTOFF64: /* 64 bit offset to GOT. */
4861 val = val + rela->r_addend -
4862- ((Elf_Addr) me->module_core + me->arch.got_offset);
4863+ ((Elf_Addr) me->module_core_rw + me->arch.got_offset);
4864 if (r_type == R_390_GOTOFF16)
4865 *(unsigned short *) loc = val;
4866 else if (r_type == R_390_GOTOFF32)
4867@@ -336,7 +336,7 @@ apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
4868 break;
4869 case R_390_GOTPC: /* 32 bit PC relative offset to GOT. */
4870 case R_390_GOTPCDBL: /* 32 bit PC rel. off. to GOT shifted by 1. */
4871- val = (Elf_Addr) me->module_core + me->arch.got_offset +
4872+ val = (Elf_Addr) me->module_core_rw + me->arch.got_offset +
4873 rela->r_addend - loc;
4874 if (r_type == R_390_GOTPC)
4875 *(unsigned int *) loc = val;
4876diff --git a/arch/s390/kernel/process.c b/arch/s390/kernel/process.c
4877index 7331753..dd71de4 100644
4878--- a/arch/s390/kernel/process.c
4879+++ b/arch/s390/kernel/process.c
4880@@ -316,39 +316,3 @@ unsigned long get_wchan(struct task_struct *p)
4881 }
4882 return 0;
4883 }
4884-
4885-unsigned long arch_align_stack(unsigned long sp)
4886-{
4887- if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
4888- sp -= get_random_int() & ~PAGE_MASK;
4889- return sp & ~0xf;
4890-}
4891-
4892-static inline unsigned long brk_rnd(void)
4893-{
4894- /* 8MB for 32bit, 1GB for 64bit */
4895- if (is_32bit_task())
4896- return (get_random_int() & 0x7ffUL) << PAGE_SHIFT;
4897- else
4898- return (get_random_int() & 0x3ffffUL) << PAGE_SHIFT;
4899-}
4900-
4901-unsigned long arch_randomize_brk(struct mm_struct *mm)
4902-{
4903- unsigned long ret = PAGE_ALIGN(mm->brk + brk_rnd());
4904-
4905- if (ret < mm->brk)
4906- return mm->brk;
4907- return ret;
4908-}
4909-
4910-unsigned long randomize_et_dyn(unsigned long base)
4911-{
4912- unsigned long ret = PAGE_ALIGN(base + brk_rnd());
4913-
4914- if (!(current->flags & PF_RANDOMIZE))
4915- return base;
4916- if (ret < base)
4917- return base;
4918- return ret;
4919-}
4920diff --git a/arch/s390/mm/mmap.c b/arch/s390/mm/mmap.c
4921index c59a5ef..3fae59c 100644
4922--- a/arch/s390/mm/mmap.c
4923+++ b/arch/s390/mm/mmap.c
4924@@ -90,10 +90,22 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
4925 */
4926 if (mmap_is_legacy()) {
4927 mm->mmap_base = TASK_UNMAPPED_BASE;
4928+
4929+#ifdef CONFIG_PAX_RANDMMAP
4930+ if (mm->pax_flags & MF_PAX_RANDMMAP)
4931+ mm->mmap_base += mm->delta_mmap;
4932+#endif
4933+
4934 mm->get_unmapped_area = arch_get_unmapped_area;
4935 mm->unmap_area = arch_unmap_area;
4936 } else {
4937 mm->mmap_base = mmap_base();
4938+
4939+#ifdef CONFIG_PAX_RANDMMAP
4940+ if (mm->pax_flags & MF_PAX_RANDMMAP)
4941+ mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
4942+#endif
4943+
4944 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
4945 mm->unmap_area = arch_unmap_area_topdown;
4946 }
4947@@ -172,10 +184,22 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
4948 */
4949 if (mmap_is_legacy()) {
4950 mm->mmap_base = TASK_UNMAPPED_BASE;
4951+
4952+#ifdef CONFIG_PAX_RANDMMAP
4953+ if (mm->pax_flags & MF_PAX_RANDMMAP)
4954+ mm->mmap_base += mm->delta_mmap;
4955+#endif
4956+
4957 mm->get_unmapped_area = s390_get_unmapped_area;
4958 mm->unmap_area = arch_unmap_area;
4959 } else {
4960 mm->mmap_base = mmap_base();
4961+
4962+#ifdef CONFIG_PAX_RANDMMAP
4963+ if (mm->pax_flags & MF_PAX_RANDMMAP)
4964+ mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
4965+#endif
4966+
4967 mm->get_unmapped_area = s390_get_unmapped_area_topdown;
4968 mm->unmap_area = arch_unmap_area_topdown;
4969 }
4970diff --git a/arch/score/include/asm/cache.h b/arch/score/include/asm/cache.h
4971index ae3d59f..f65f075 100644
4972--- a/arch/score/include/asm/cache.h
4973+++ b/arch/score/include/asm/cache.h
4974@@ -1,7 +1,9 @@
4975 #ifndef _ASM_SCORE_CACHE_H
4976 #define _ASM_SCORE_CACHE_H
4977
4978+#include <linux/const.h>
4979+
4980 #define L1_CACHE_SHIFT 4
4981-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
4982+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
4983
4984 #endif /* _ASM_SCORE_CACHE_H */
4985diff --git a/arch/score/include/asm/exec.h b/arch/score/include/asm/exec.h
4986index f9f3cd5..58ff438 100644
4987--- a/arch/score/include/asm/exec.h
4988+++ b/arch/score/include/asm/exec.h
4989@@ -1,6 +1,6 @@
4990 #ifndef _ASM_SCORE_EXEC_H
4991 #define _ASM_SCORE_EXEC_H
4992
4993-extern unsigned long arch_align_stack(unsigned long sp);
4994+#define arch_align_stack(x) (x)
4995
4996 #endif /* _ASM_SCORE_EXEC_H */
4997diff --git a/arch/score/kernel/process.c b/arch/score/kernel/process.c
4998index 637970c..0b6556b 100644
4999--- a/arch/score/kernel/process.c
5000+++ b/arch/score/kernel/process.c
5001@@ -161,8 +161,3 @@ unsigned long get_wchan(struct task_struct *task)
5002
5003 return task_pt_regs(task)->cp0_epc;
5004 }
5005-
5006-unsigned long arch_align_stack(unsigned long sp)
5007-{
5008- return sp;
5009-}
5010diff --git a/arch/sh/include/asm/cache.h b/arch/sh/include/asm/cache.h
5011index ef9e555..331bd29 100644
5012--- a/arch/sh/include/asm/cache.h
5013+++ b/arch/sh/include/asm/cache.h
5014@@ -9,10 +9,11 @@
5015 #define __ASM_SH_CACHE_H
5016 #ifdef __KERNEL__
5017
5018+#include <linux/const.h>
5019 #include <linux/init.h>
5020 #include <cpu/cache.h>
5021
5022-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
5023+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
5024
5025 #define __read_mostly __attribute__((__section__(".data..read_mostly")))
5026
5027diff --git a/arch/sh/mm/mmap.c b/arch/sh/mm/mmap.c
5028index afeb710..d1d1289 100644
5029--- a/arch/sh/mm/mmap.c
5030+++ b/arch/sh/mm/mmap.c
5031@@ -74,8 +74,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr,
5032 addr = PAGE_ALIGN(addr);
5033
5034 vma = find_vma(mm, addr);
5035- if (TASK_SIZE - len >= addr &&
5036- (!vma || addr + len <= vma->vm_start))
5037+ if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len))
5038 return addr;
5039 }
5040
5041@@ -106,7 +105,7 @@ full_search:
5042 }
5043 return -ENOMEM;
5044 }
5045- if (likely(!vma || addr + len <= vma->vm_start)) {
5046+ if (likely(check_heap_stack_gap(vma, addr, len))) {
5047 /*
5048 * Remember the place where we stopped the search:
5049 */
5050@@ -157,8 +156,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
5051 addr = PAGE_ALIGN(addr);
5052
5053 vma = find_vma(mm, addr);
5054- if (TASK_SIZE - len >= addr &&
5055- (!vma || addr + len <= vma->vm_start))
5056+ if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len))
5057 return addr;
5058 }
5059
5060@@ -179,7 +177,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
5061 /* make sure it can fit in the remaining address space */
5062 if (likely(addr > len)) {
5063 vma = find_vma(mm, addr-len);
5064- if (!vma || addr <= vma->vm_start) {
5065+ if (check_heap_stack_gap(vma, addr - len, len)) {
5066 /* remember the address as a hint for next time */
5067 return (mm->free_area_cache = addr-len);
5068 }
5069@@ -188,18 +186,18 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
5070 if (unlikely(mm->mmap_base < len))
5071 goto bottomup;
5072
5073- addr = mm->mmap_base-len;
5074- if (do_colour_align)
5075- addr = COLOUR_ALIGN_DOWN(addr, pgoff);
5076+ addr = mm->mmap_base - len;
5077
5078 do {
5079+ if (do_colour_align)
5080+ addr = COLOUR_ALIGN_DOWN(addr, pgoff);
5081 /*
5082 * Lookup failure means no vma is above this address,
5083 * else if new region fits below vma->vm_start,
5084 * return with success:
5085 */
5086 vma = find_vma(mm, addr);
5087- if (likely(!vma || addr+len <= vma->vm_start)) {
5088+ if (likely(check_heap_stack_gap(vma, addr, len))) {
5089 /* remember the address as a hint for next time */
5090 return (mm->free_area_cache = addr);
5091 }
5092@@ -209,10 +207,8 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
5093 mm->cached_hole_size = vma->vm_start - addr;
5094
5095 /* try just below the current vma->vm_start */
5096- addr = vma->vm_start-len;
5097- if (do_colour_align)
5098- addr = COLOUR_ALIGN_DOWN(addr, pgoff);
5099- } while (likely(len < vma->vm_start));
5100+ addr = skip_heap_stack_gap(vma, len);
5101+ } while (!IS_ERR_VALUE(addr));
5102
5103 bottomup:
5104 /*
5105diff --git a/arch/sparc/include/asm/atomic_64.h b/arch/sparc/include/asm/atomic_64.h
5106index ce35a1c..2e7b8f9 100644
5107--- a/arch/sparc/include/asm/atomic_64.h
5108+++ b/arch/sparc/include/asm/atomic_64.h
5109@@ -14,18 +14,40 @@
5110 #define ATOMIC64_INIT(i) { (i) }
5111
5112 #define atomic_read(v) (*(volatile int *)&(v)->counter)
5113+static inline int atomic_read_unchecked(const atomic_unchecked_t *v)
5114+{
5115+ return v->counter;
5116+}
5117 #define atomic64_read(v) (*(volatile long *)&(v)->counter)
5118+static inline long atomic64_read_unchecked(const atomic64_unchecked_t *v)
5119+{
5120+ return v->counter;
5121+}
5122
5123 #define atomic_set(v, i) (((v)->counter) = i)
5124+static inline void atomic_set_unchecked(atomic_unchecked_t *v, int i)
5125+{
5126+ v->counter = i;
5127+}
5128 #define atomic64_set(v, i) (((v)->counter) = i)
5129+static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, long i)
5130+{
5131+ v->counter = i;
5132+}
5133
5134 extern void atomic_add(int, atomic_t *);
5135+extern void atomic_add_unchecked(int, atomic_unchecked_t *);
5136 extern void atomic64_add(long, atomic64_t *);
5137+extern void atomic64_add_unchecked(long, atomic64_unchecked_t *);
5138 extern void atomic_sub(int, atomic_t *);
5139+extern void atomic_sub_unchecked(int, atomic_unchecked_t *);
5140 extern void atomic64_sub(long, atomic64_t *);
5141+extern void atomic64_sub_unchecked(long, atomic64_unchecked_t *);
5142
5143 extern int atomic_add_ret(int, atomic_t *);
5144+extern int atomic_add_ret_unchecked(int, atomic_unchecked_t *);
5145 extern long atomic64_add_ret(long, atomic64_t *);
5146+extern long atomic64_add_ret_unchecked(long, atomic64_unchecked_t *);
5147 extern int atomic_sub_ret(int, atomic_t *);
5148 extern long atomic64_sub_ret(long, atomic64_t *);
5149
5150@@ -33,13 +55,29 @@ extern long atomic64_sub_ret(long, atomic64_t *);
5151 #define atomic64_dec_return(v) atomic64_sub_ret(1, v)
5152
5153 #define atomic_inc_return(v) atomic_add_ret(1, v)
5154+static inline int atomic_inc_return_unchecked(atomic_unchecked_t *v)
5155+{
5156+ return atomic_add_ret_unchecked(1, v);
5157+}
5158 #define atomic64_inc_return(v) atomic64_add_ret(1, v)
5159+static inline long atomic64_inc_return_unchecked(atomic64_unchecked_t *v)
5160+{
5161+ return atomic64_add_ret_unchecked(1, v);
5162+}
5163
5164 #define atomic_sub_return(i, v) atomic_sub_ret(i, v)
5165 #define atomic64_sub_return(i, v) atomic64_sub_ret(i, v)
5166
5167 #define atomic_add_return(i, v) atomic_add_ret(i, v)
5168+static inline int atomic_add_return_unchecked(int i, atomic_unchecked_t *v)
5169+{
5170+ return atomic_add_ret_unchecked(i, v);
5171+}
5172 #define atomic64_add_return(i, v) atomic64_add_ret(i, v)
5173+static inline long atomic64_add_return_unchecked(long i, atomic64_unchecked_t *v)
5174+{
5175+ return atomic64_add_ret_unchecked(i, v);
5176+}
5177
5178 /*
5179 * atomic_inc_and_test - increment and test
5180@@ -50,6 +88,10 @@ extern long atomic64_sub_ret(long, atomic64_t *);
5181 * other cases.
5182 */
5183 #define atomic_inc_and_test(v) (atomic_inc_return(v) == 0)
5184+static inline int atomic_inc_and_test_unchecked(atomic_unchecked_t *v)
5185+{
5186+ return atomic_inc_return_unchecked(v) == 0;
5187+}
5188 #define atomic64_inc_and_test(v) (atomic64_inc_return(v) == 0)
5189
5190 #define atomic_sub_and_test(i, v) (atomic_sub_ret(i, v) == 0)
5191@@ -59,25 +101,60 @@ extern long atomic64_sub_ret(long, atomic64_t *);
5192 #define atomic64_dec_and_test(v) (atomic64_sub_ret(1, v) == 0)
5193
5194 #define atomic_inc(v) atomic_add(1, v)
5195+static inline void atomic_inc_unchecked(atomic_unchecked_t *v)
5196+{
5197+ atomic_add_unchecked(1, v);
5198+}
5199 #define atomic64_inc(v) atomic64_add(1, v)
5200+static inline void atomic64_inc_unchecked(atomic64_unchecked_t *v)
5201+{
5202+ atomic64_add_unchecked(1, v);
5203+}
5204
5205 #define atomic_dec(v) atomic_sub(1, v)
5206+static inline void atomic_dec_unchecked(atomic_unchecked_t *v)
5207+{
5208+ atomic_sub_unchecked(1, v);
5209+}
5210 #define atomic64_dec(v) atomic64_sub(1, v)
5211+static inline void atomic64_dec_unchecked(atomic64_unchecked_t *v)
5212+{
5213+ atomic64_sub_unchecked(1, v);
5214+}
5215
5216 #define atomic_add_negative(i, v) (atomic_add_ret(i, v) < 0)
5217 #define atomic64_add_negative(i, v) (atomic64_add_ret(i, v) < 0)
5218
5219 #define atomic_cmpxchg(v, o, n) (cmpxchg(&((v)->counter), (o), (n)))
5220+static inline int atomic_cmpxchg_unchecked(atomic_unchecked_t *v, int old, int new)
5221+{
5222+ return cmpxchg(&v->counter, old, new);
5223+}
5224 #define atomic_xchg(v, new) (xchg(&((v)->counter), new))
5225+static inline int atomic_xchg_unchecked(atomic_unchecked_t *v, int new)
5226+{
5227+ return xchg(&v->counter, new);
5228+}
5229
5230 static inline int __atomic_add_unless(atomic_t *v, int a, int u)
5231 {
5232- int c, old;
5233+ int c, old, new;
5234 c = atomic_read(v);
5235 for (;;) {
5236- if (unlikely(c == (u)))
5237+ if (unlikely(c == u))
5238 break;
5239- old = atomic_cmpxchg((v), c, c + (a));
5240+
5241+ asm volatile("addcc %2, %0, %0\n"
5242+
5243+#ifdef CONFIG_PAX_REFCOUNT
5244+ "tvs %%icc, 6\n"
5245+#endif
5246+
5247+ : "=r" (new)
5248+ : "0" (c), "ir" (a)
5249+ : "cc");
5250+
5251+ old = atomic_cmpxchg(v, c, new);
5252 if (likely(old == c))
5253 break;
5254 c = old;
5255@@ -88,20 +165,35 @@ static inline int __atomic_add_unless(atomic_t *v, int a, int u)
5256 #define atomic64_cmpxchg(v, o, n) \
5257 ((__typeof__((v)->counter))cmpxchg(&((v)->counter), (o), (n)))
5258 #define atomic64_xchg(v, new) (xchg(&((v)->counter), new))
5259+static inline long atomic64_xchg_unchecked(atomic64_unchecked_t *v, long new)
5260+{
5261+ return xchg(&v->counter, new);
5262+}
5263
5264 static inline long atomic64_add_unless(atomic64_t *v, long a, long u)
5265 {
5266- long c, old;
5267+ long c, old, new;
5268 c = atomic64_read(v);
5269 for (;;) {
5270- if (unlikely(c == (u)))
5271+ if (unlikely(c == u))
5272 break;
5273- old = atomic64_cmpxchg((v), c, c + (a));
5274+
5275+ asm volatile("addcc %2, %0, %0\n"
5276+
5277+#ifdef CONFIG_PAX_REFCOUNT
5278+ "tvs %%xcc, 6\n"
5279+#endif
5280+
5281+ : "=r" (new)
5282+ : "0" (c), "ir" (a)
5283+ : "cc");
5284+
5285+ old = atomic64_cmpxchg(v, c, new);
5286 if (likely(old == c))
5287 break;
5288 c = old;
5289 }
5290- return c != (u);
5291+ return c != u;
5292 }
5293
5294 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
5295diff --git a/arch/sparc/include/asm/cache.h b/arch/sparc/include/asm/cache.h
5296index 5bb6991..5c2132e 100644
5297--- a/arch/sparc/include/asm/cache.h
5298+++ b/arch/sparc/include/asm/cache.h
5299@@ -7,10 +7,12 @@
5300 #ifndef _SPARC_CACHE_H
5301 #define _SPARC_CACHE_H
5302
5303+#include <linux/const.h>
5304+
5305 #define ARCH_SLAB_MINALIGN __alignof__(unsigned long long)
5306
5307 #define L1_CACHE_SHIFT 5
5308-#define L1_CACHE_BYTES 32
5309+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
5310
5311 #ifdef CONFIG_SPARC32
5312 #define SMP_CACHE_BYTES_SHIFT 5
5313diff --git a/arch/sparc/include/asm/elf_32.h b/arch/sparc/include/asm/elf_32.h
5314index 2d4d755..81b6662 100644
5315--- a/arch/sparc/include/asm/elf_32.h
5316+++ b/arch/sparc/include/asm/elf_32.h
5317@@ -114,6 +114,13 @@ typedef struct {
5318
5319 #define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE)
5320
5321+#ifdef CONFIG_PAX_ASLR
5322+#define PAX_ELF_ET_DYN_BASE 0x10000UL
5323+
5324+#define PAX_DELTA_MMAP_LEN 16
5325+#define PAX_DELTA_STACK_LEN 16
5326+#endif
5327+
5328 /* This yields a mask that user programs can use to figure out what
5329 instruction set this cpu supports. This can NOT be done in userspace
5330 on Sparc. */
5331diff --git a/arch/sparc/include/asm/elf_64.h b/arch/sparc/include/asm/elf_64.h
5332index 7df8b7f..4946269 100644
5333--- a/arch/sparc/include/asm/elf_64.h
5334+++ b/arch/sparc/include/asm/elf_64.h
5335@@ -180,6 +180,13 @@ typedef struct {
5336 #define ELF_ET_DYN_BASE 0x0000010000000000UL
5337 #define COMPAT_ELF_ET_DYN_BASE 0x0000000070000000UL
5338
5339+#ifdef CONFIG_PAX_ASLR
5340+#define PAX_ELF_ET_DYN_BASE (test_thread_flag(TIF_32BIT) ? 0x10000UL : 0x100000UL)
5341+
5342+#define PAX_DELTA_MMAP_LEN (test_thread_flag(TIF_32BIT) ? 14 : 28)
5343+#define PAX_DELTA_STACK_LEN (test_thread_flag(TIF_32BIT) ? 15 : 29)
5344+#endif
5345+
5346 extern unsigned long sparc64_elf_hwcap;
5347 #define ELF_HWCAP sparc64_elf_hwcap
5348
5349diff --git a/arch/sparc/include/asm/pgalloc_32.h b/arch/sparc/include/asm/pgalloc_32.h
5350index 9b1c36d..209298b 100644
5351--- a/arch/sparc/include/asm/pgalloc_32.h
5352+++ b/arch/sparc/include/asm/pgalloc_32.h
5353@@ -33,6 +33,7 @@ static inline void pgd_set(pgd_t * pgdp, pmd_t * pmdp)
5354 }
5355
5356 #define pgd_populate(MM, PGD, PMD) pgd_set(PGD, PMD)
5357+#define pgd_populate_kernel(MM, PGD, PMD) pgd_populate((MM), (PGD), (PMD))
5358
5359 static inline pmd_t *pmd_alloc_one(struct mm_struct *mm,
5360 unsigned long address)
5361diff --git a/arch/sparc/include/asm/pgalloc_64.h b/arch/sparc/include/asm/pgalloc_64.h
5362index 40b2d7a..22a665b 100644
5363--- a/arch/sparc/include/asm/pgalloc_64.h
5364+++ b/arch/sparc/include/asm/pgalloc_64.h
5365@@ -26,6 +26,7 @@ static inline void pgd_free(struct mm_struct *mm, pgd_t *pgd)
5366 }
5367
5368 #define pud_populate(MM, PUD, PMD) pud_set(PUD, PMD)
5369+#define pud_populate_kernel(MM, PUD, PMD) pud_populate((MM), (PUD), (PMD))
5370
5371 static inline pmd_t *pmd_alloc_one(struct mm_struct *mm, unsigned long addr)
5372 {
5373diff --git a/arch/sparc/include/asm/pgtable_32.h b/arch/sparc/include/asm/pgtable_32.h
5374index 6fc1348..390c50a 100644
5375--- a/arch/sparc/include/asm/pgtable_32.h
5376+++ b/arch/sparc/include/asm/pgtable_32.h
5377@@ -50,6 +50,9 @@ extern unsigned long calc_highpages(void);
5378 #define PAGE_SHARED SRMMU_PAGE_SHARED
5379 #define PAGE_COPY SRMMU_PAGE_COPY
5380 #define PAGE_READONLY SRMMU_PAGE_RDONLY
5381+#define PAGE_SHARED_NOEXEC SRMMU_PAGE_SHARED_NOEXEC
5382+#define PAGE_COPY_NOEXEC SRMMU_PAGE_COPY_NOEXEC
5383+#define PAGE_READONLY_NOEXEC SRMMU_PAGE_RDONLY_NOEXEC
5384 #define PAGE_KERNEL SRMMU_PAGE_KERNEL
5385
5386 /* Top-level page directory - dummy used by init-mm.
5387@@ -62,18 +65,18 @@ extern unsigned long ptr_in_current_pgd;
5388
5389 /* xwr */
5390 #define __P000 PAGE_NONE
5391-#define __P001 PAGE_READONLY
5392-#define __P010 PAGE_COPY
5393-#define __P011 PAGE_COPY
5394+#define __P001 PAGE_READONLY_NOEXEC
5395+#define __P010 PAGE_COPY_NOEXEC
5396+#define __P011 PAGE_COPY_NOEXEC
5397 #define __P100 PAGE_READONLY
5398 #define __P101 PAGE_READONLY
5399 #define __P110 PAGE_COPY
5400 #define __P111 PAGE_COPY
5401
5402 #define __S000 PAGE_NONE
5403-#define __S001 PAGE_READONLY
5404-#define __S010 PAGE_SHARED
5405-#define __S011 PAGE_SHARED
5406+#define __S001 PAGE_READONLY_NOEXEC
5407+#define __S010 PAGE_SHARED_NOEXEC
5408+#define __S011 PAGE_SHARED_NOEXEC
5409 #define __S100 PAGE_READONLY
5410 #define __S101 PAGE_READONLY
5411 #define __S110 PAGE_SHARED
5412diff --git a/arch/sparc/include/asm/pgtsrmmu.h b/arch/sparc/include/asm/pgtsrmmu.h
5413index 79da178..c2eede8 100644
5414--- a/arch/sparc/include/asm/pgtsrmmu.h
5415+++ b/arch/sparc/include/asm/pgtsrmmu.h
5416@@ -115,6 +115,11 @@
5417 SRMMU_EXEC | SRMMU_REF)
5418 #define SRMMU_PAGE_RDONLY __pgprot(SRMMU_VALID | SRMMU_CACHE | \
5419 SRMMU_EXEC | SRMMU_REF)
5420+
5421+#define SRMMU_PAGE_SHARED_NOEXEC __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_WRITE | SRMMU_REF)
5422+#define SRMMU_PAGE_COPY_NOEXEC __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_REF)
5423+#define SRMMU_PAGE_RDONLY_NOEXEC __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_REF)
5424+
5425 #define SRMMU_PAGE_KERNEL __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_PRIV | \
5426 SRMMU_DIRTY | SRMMU_REF)
5427
5428diff --git a/arch/sparc/include/asm/spinlock_64.h b/arch/sparc/include/asm/spinlock_64.h
5429index 9689176..63c18ea 100644
5430--- a/arch/sparc/include/asm/spinlock_64.h
5431+++ b/arch/sparc/include/asm/spinlock_64.h
5432@@ -92,14 +92,19 @@ static inline void arch_spin_lock_flags(arch_spinlock_t *lock, unsigned long fla
5433
5434 /* Multi-reader locks, these are much saner than the 32-bit Sparc ones... */
5435
5436-static void inline arch_read_lock(arch_rwlock_t *lock)
5437+static inline void arch_read_lock(arch_rwlock_t *lock)
5438 {
5439 unsigned long tmp1, tmp2;
5440
5441 __asm__ __volatile__ (
5442 "1: ldsw [%2], %0\n"
5443 " brlz,pn %0, 2f\n"
5444-"4: add %0, 1, %1\n"
5445+"4: addcc %0, 1, %1\n"
5446+
5447+#ifdef CONFIG_PAX_REFCOUNT
5448+" tvs %%icc, 6\n"
5449+#endif
5450+
5451 " cas [%2], %0, %1\n"
5452 " cmp %0, %1\n"
5453 " bne,pn %%icc, 1b\n"
5454@@ -112,10 +117,10 @@ static void inline arch_read_lock(arch_rwlock_t *lock)
5455 " .previous"
5456 : "=&r" (tmp1), "=&r" (tmp2)
5457 : "r" (lock)
5458- : "memory");
5459+ : "memory", "cc");
5460 }
5461
5462-static int inline arch_read_trylock(arch_rwlock_t *lock)
5463+static inline int arch_read_trylock(arch_rwlock_t *lock)
5464 {
5465 int tmp1, tmp2;
5466
5467@@ -123,7 +128,12 @@ static int inline arch_read_trylock(arch_rwlock_t *lock)
5468 "1: ldsw [%2], %0\n"
5469 " brlz,a,pn %0, 2f\n"
5470 " mov 0, %0\n"
5471-" add %0, 1, %1\n"
5472+" addcc %0, 1, %1\n"
5473+
5474+#ifdef CONFIG_PAX_REFCOUNT
5475+" tvs %%icc, 6\n"
5476+#endif
5477+
5478 " cas [%2], %0, %1\n"
5479 " cmp %0, %1\n"
5480 " bne,pn %%icc, 1b\n"
5481@@ -136,13 +146,18 @@ static int inline arch_read_trylock(arch_rwlock_t *lock)
5482 return tmp1;
5483 }
5484
5485-static void inline arch_read_unlock(arch_rwlock_t *lock)
5486+static inline void arch_read_unlock(arch_rwlock_t *lock)
5487 {
5488 unsigned long tmp1, tmp2;
5489
5490 __asm__ __volatile__(
5491 "1: lduw [%2], %0\n"
5492-" sub %0, 1, %1\n"
5493+" subcc %0, 1, %1\n"
5494+
5495+#ifdef CONFIG_PAX_REFCOUNT
5496+" tvs %%icc, 6\n"
5497+#endif
5498+
5499 " cas [%2], %0, %1\n"
5500 " cmp %0, %1\n"
5501 " bne,pn %%xcc, 1b\n"
5502@@ -152,7 +167,7 @@ static void inline arch_read_unlock(arch_rwlock_t *lock)
5503 : "memory");
5504 }
5505
5506-static void inline arch_write_lock(arch_rwlock_t *lock)
5507+static inline void arch_write_lock(arch_rwlock_t *lock)
5508 {
5509 unsigned long mask, tmp1, tmp2;
5510
5511@@ -177,7 +192,7 @@ static void inline arch_write_lock(arch_rwlock_t *lock)
5512 : "memory");
5513 }
5514
5515-static void inline arch_write_unlock(arch_rwlock_t *lock)
5516+static inline void arch_write_unlock(arch_rwlock_t *lock)
5517 {
5518 __asm__ __volatile__(
5519 " stw %%g0, [%0]"
5520@@ -186,7 +201,7 @@ static void inline arch_write_unlock(arch_rwlock_t *lock)
5521 : "memory");
5522 }
5523
5524-static int inline arch_write_trylock(arch_rwlock_t *lock)
5525+static inline int arch_write_trylock(arch_rwlock_t *lock)
5526 {
5527 unsigned long mask, tmp1, tmp2, result;
5528
5529diff --git a/arch/sparc/include/asm/thread_info_32.h b/arch/sparc/include/asm/thread_info_32.h
5530index e6cd224..3a71793 100644
5531--- a/arch/sparc/include/asm/thread_info_32.h
5532+++ b/arch/sparc/include/asm/thread_info_32.h
5533@@ -49,6 +49,8 @@ struct thread_info {
5534 unsigned long w_saved;
5535
5536 struct restart_block restart_block;
5537+
5538+ unsigned long lowest_stack;
5539 };
5540
5541 /*
5542diff --git a/arch/sparc/include/asm/thread_info_64.h b/arch/sparc/include/asm/thread_info_64.h
5543index cfa8c38..13f30d3 100644
5544--- a/arch/sparc/include/asm/thread_info_64.h
5545+++ b/arch/sparc/include/asm/thread_info_64.h
5546@@ -63,6 +63,8 @@ struct thread_info {
5547 struct pt_regs *kern_una_regs;
5548 unsigned int kern_una_insn;
5549
5550+ unsigned long lowest_stack;
5551+
5552 unsigned long fpregs[0] __attribute__ ((aligned(64)));
5553 };
5554
5555@@ -193,10 +195,11 @@ register struct thread_info *current_thread_info_reg asm("g6");
5556 #define TIF_UNALIGNED 5 /* allowed to do unaligned accesses */
5557 /* flag bit 6 is available */
5558 #define TIF_32BIT 7 /* 32-bit binary */
5559-/* flag bit 8 is available */
5560+#define TIF_GRSEC_SETXID 8 /* update credentials on syscall entry/exit */
5561 #define TIF_SECCOMP 9 /* secure computing */
5562 #define TIF_SYSCALL_AUDIT 10 /* syscall auditing active */
5563 #define TIF_SYSCALL_TRACEPOINT 11 /* syscall tracepoint instrumentation */
5564+
5565 /* NOTE: Thread flags >= 12 should be ones we have no interest
5566 * in using in assembly, else we can't use the mask as
5567 * an immediate value in instructions such as andcc.
5568@@ -215,12 +218,18 @@ register struct thread_info *current_thread_info_reg asm("g6");
5569 #define _TIF_SYSCALL_AUDIT (1<<TIF_SYSCALL_AUDIT)
5570 #define _TIF_SYSCALL_TRACEPOINT (1<<TIF_SYSCALL_TRACEPOINT)
5571 #define _TIF_POLLING_NRFLAG (1<<TIF_POLLING_NRFLAG)
5572+#define _TIF_GRSEC_SETXID (1<<TIF_GRSEC_SETXID)
5573
5574 #define _TIF_USER_WORK_MASK ((0xff << TI_FLAG_WSAVED_SHIFT) | \
5575 _TIF_DO_NOTIFY_RESUME_MASK | \
5576 _TIF_NEED_RESCHED)
5577 #define _TIF_DO_NOTIFY_RESUME_MASK (_TIF_NOTIFY_RESUME | _TIF_SIGPENDING)
5578
5579+#define _TIF_WORK_SYSCALL \
5580+ (_TIF_SYSCALL_TRACE | _TIF_SECCOMP | _TIF_SYSCALL_AUDIT | \
5581+ _TIF_SYSCALL_TRACEPOINT | _TIF_GRSEC_SETXID)
5582+
5583+
5584 /*
5585 * Thread-synchronous status.
5586 *
5587diff --git a/arch/sparc/include/asm/uaccess.h b/arch/sparc/include/asm/uaccess.h
5588index 0167d26..9acd8ed 100644
5589--- a/arch/sparc/include/asm/uaccess.h
5590+++ b/arch/sparc/include/asm/uaccess.h
5591@@ -1,5 +1,13 @@
5592 #ifndef ___ASM_SPARC_UACCESS_H
5593 #define ___ASM_SPARC_UACCESS_H
5594+
5595+#ifdef __KERNEL__
5596+#ifndef __ASSEMBLY__
5597+#include <linux/types.h>
5598+extern void check_object_size(const void *ptr, unsigned long n, bool to);
5599+#endif
5600+#endif
5601+
5602 #if defined(__sparc__) && defined(__arch64__)
5603 #include <asm/uaccess_64.h>
5604 #else
5605diff --git a/arch/sparc/include/asm/uaccess_32.h b/arch/sparc/include/asm/uaccess_32.h
5606index 53a28dd..50c38c3 100644
5607--- a/arch/sparc/include/asm/uaccess_32.h
5608+++ b/arch/sparc/include/asm/uaccess_32.h
5609@@ -250,27 +250,46 @@ extern unsigned long __copy_user(void __user *to, const void __user *from, unsig
5610
5611 static inline unsigned long copy_to_user(void __user *to, const void *from, unsigned long n)
5612 {
5613- if (n && __access_ok((unsigned long) to, n))
5614+ if ((long)n < 0)
5615+ return n;
5616+
5617+ if (n && __access_ok((unsigned long) to, n)) {
5618+ if (!__builtin_constant_p(n))
5619+ check_object_size(from, n, true);
5620 return __copy_user(to, (__force void __user *) from, n);
5621- else
5622+ } else
5623 return n;
5624 }
5625
5626 static inline unsigned long __copy_to_user(void __user *to, const void *from, unsigned long n)
5627 {
5628+ if ((long)n < 0)
5629+ return n;
5630+
5631+ if (!__builtin_constant_p(n))
5632+ check_object_size(from, n, true);
5633+
5634 return __copy_user(to, (__force void __user *) from, n);
5635 }
5636
5637 static inline unsigned long copy_from_user(void *to, const void __user *from, unsigned long n)
5638 {
5639- if (n && __access_ok((unsigned long) from, n))
5640+ if ((long)n < 0)
5641+ return n;
5642+
5643+ if (n && __access_ok((unsigned long) from, n)) {
5644+ if (!__builtin_constant_p(n))
5645+ check_object_size(to, n, false);
5646 return __copy_user((__force void __user *) to, from, n);
5647- else
5648+ } else
5649 return n;
5650 }
5651
5652 static inline unsigned long __copy_from_user(void *to, const void __user *from, unsigned long n)
5653 {
5654+ if ((long)n < 0)
5655+ return n;
5656+
5657 return __copy_user((__force void __user *) to, from, n);
5658 }
5659
5660diff --git a/arch/sparc/include/asm/uaccess_64.h b/arch/sparc/include/asm/uaccess_64.h
5661index 7c831d8..d440ca7 100644
5662--- a/arch/sparc/include/asm/uaccess_64.h
5663+++ b/arch/sparc/include/asm/uaccess_64.h
5664@@ -10,6 +10,7 @@
5665 #include <linux/compiler.h>
5666 #include <linux/string.h>
5667 #include <linux/thread_info.h>
5668+#include <linux/kernel.h>
5669 #include <asm/asi.h>
5670 #include <asm/spitfire.h>
5671 #include <asm-generic/uaccess-unaligned.h>
5672@@ -214,8 +215,15 @@ extern unsigned long copy_from_user_fixup(void *to, const void __user *from,
5673 static inline unsigned long __must_check
5674 copy_from_user(void *to, const void __user *from, unsigned long size)
5675 {
5676- unsigned long ret = ___copy_from_user(to, from, size);
5677+ unsigned long ret;
5678
5679+ if ((long)size < 0 || size > INT_MAX)
5680+ return size;
5681+
5682+ if (!__builtin_constant_p(size))
5683+ check_object_size(to, size, false);
5684+
5685+ ret = ___copy_from_user(to, from, size);
5686 if (unlikely(ret))
5687 ret = copy_from_user_fixup(to, from, size);
5688
5689@@ -231,8 +239,15 @@ extern unsigned long copy_to_user_fixup(void __user *to, const void *from,
5690 static inline unsigned long __must_check
5691 copy_to_user(void __user *to, const void *from, unsigned long size)
5692 {
5693- unsigned long ret = ___copy_to_user(to, from, size);
5694+ unsigned long ret;
5695
5696+ if ((long)size < 0 || size > INT_MAX)
5697+ return size;
5698+
5699+ if (!__builtin_constant_p(size))
5700+ check_object_size(from, size, true);
5701+
5702+ ret = ___copy_to_user(to, from, size);
5703 if (unlikely(ret))
5704 ret = copy_to_user_fixup(to, from, size);
5705 return ret;
5706diff --git a/arch/sparc/kernel/Makefile b/arch/sparc/kernel/Makefile
5707index 6cf591b..b49e65a 100644
5708--- a/arch/sparc/kernel/Makefile
5709+++ b/arch/sparc/kernel/Makefile
5710@@ -3,7 +3,7 @@
5711 #
5712
5713 asflags-y := -ansi
5714-ccflags-y := -Werror
5715+#ccflags-y := -Werror
5716
5717 extra-y := head_$(BITS).o
5718
5719diff --git a/arch/sparc/kernel/leon_kernel.c b/arch/sparc/kernel/leon_kernel.c
5720index f8b6eee..87f60ee 100644
5721--- a/arch/sparc/kernel/leon_kernel.c
5722+++ b/arch/sparc/kernel/leon_kernel.c
5723@@ -56,11 +56,13 @@ static inline unsigned int leon_eirq_get(int cpu)
5724 static void leon_handle_ext_irq(unsigned int irq, struct irq_desc *desc)
5725 {
5726 unsigned int eirq;
5727+ struct irq_bucket *p;
5728 int cpu = sparc_leon3_cpuid();
5729
5730 eirq = leon_eirq_get(cpu);
5731- if ((eirq & 0x10) && irq_map[eirq]->irq) /* bit4 tells if IRQ happened */
5732- generic_handle_irq(irq_map[eirq]->irq);
5733+ p = irq_map[eirq];
5734+ if ((eirq & 0x10) && p && p->irq) /* bit4 tells if IRQ happened */
5735+ generic_handle_irq(p->irq);
5736 }
5737
5738 /* The extended IRQ controller has been found, this function registers it */
5739diff --git a/arch/sparc/kernel/process_32.c b/arch/sparc/kernel/process_32.c
5740index 14006d8..8146238 100644
5741--- a/arch/sparc/kernel/process_32.c
5742+++ b/arch/sparc/kernel/process_32.c
5743@@ -126,14 +126,14 @@ void show_regs(struct pt_regs *r)
5744
5745 printk("PSR: %08lx PC: %08lx NPC: %08lx Y: %08lx %s\n",
5746 r->psr, r->pc, r->npc, r->y, print_tainted());
5747- printk("PC: <%pS>\n", (void *) r->pc);
5748+ printk("PC: <%pA>\n", (void *) r->pc);
5749 printk("%%G: %08lx %08lx %08lx %08lx %08lx %08lx %08lx %08lx\n",
5750 r->u_regs[0], r->u_regs[1], r->u_regs[2], r->u_regs[3],
5751 r->u_regs[4], r->u_regs[5], r->u_regs[6], r->u_regs[7]);
5752 printk("%%O: %08lx %08lx %08lx %08lx %08lx %08lx %08lx %08lx\n",
5753 r->u_regs[8], r->u_regs[9], r->u_regs[10], r->u_regs[11],
5754 r->u_regs[12], r->u_regs[13], r->u_regs[14], r->u_regs[15]);
5755- printk("RPC: <%pS>\n", (void *) r->u_regs[15]);
5756+ printk("RPC: <%pA>\n", (void *) r->u_regs[15]);
5757
5758 printk("%%L: %08lx %08lx %08lx %08lx %08lx %08lx %08lx %08lx\n",
5759 rw->locals[0], rw->locals[1], rw->locals[2], rw->locals[3],
5760@@ -168,7 +168,7 @@ void show_stack(struct task_struct *tsk, unsigned long *_ksp)
5761 rw = (struct reg_window32 *) fp;
5762 pc = rw->ins[7];
5763 printk("[%08lx : ", pc);
5764- printk("%pS ] ", (void *) pc);
5765+ printk("%pA ] ", (void *) pc);
5766 fp = rw->ins[6];
5767 } while (++count < 16);
5768 printk("\n");
5769diff --git a/arch/sparc/kernel/process_64.c b/arch/sparc/kernel/process_64.c
5770index aff0c72..9067b39 100644
5771--- a/arch/sparc/kernel/process_64.c
5772+++ b/arch/sparc/kernel/process_64.c
5773@@ -179,14 +179,14 @@ static void show_regwindow(struct pt_regs *regs)
5774 printk("i4: %016lx i5: %016lx i6: %016lx i7: %016lx\n",
5775 rwk->ins[4], rwk->ins[5], rwk->ins[6], rwk->ins[7]);
5776 if (regs->tstate & TSTATE_PRIV)
5777- printk("I7: <%pS>\n", (void *) rwk->ins[7]);
5778+ printk("I7: <%pA>\n", (void *) rwk->ins[7]);
5779 }
5780
5781 void show_regs(struct pt_regs *regs)
5782 {
5783 printk("TSTATE: %016lx TPC: %016lx TNPC: %016lx Y: %08x %s\n", regs->tstate,
5784 regs->tpc, regs->tnpc, regs->y, print_tainted());
5785- printk("TPC: <%pS>\n", (void *) regs->tpc);
5786+ printk("TPC: <%pA>\n", (void *) regs->tpc);
5787 printk("g0: %016lx g1: %016lx g2: %016lx g3: %016lx\n",
5788 regs->u_regs[0], regs->u_regs[1], regs->u_regs[2],
5789 regs->u_regs[3]);
5790@@ -199,7 +199,7 @@ void show_regs(struct pt_regs *regs)
5791 printk("o4: %016lx o5: %016lx sp: %016lx ret_pc: %016lx\n",
5792 regs->u_regs[12], regs->u_regs[13], regs->u_regs[14],
5793 regs->u_regs[15]);
5794- printk("RPC: <%pS>\n", (void *) regs->u_regs[15]);
5795+ printk("RPC: <%pA>\n", (void *) regs->u_regs[15]);
5796 show_regwindow(regs);
5797 show_stack(current, (unsigned long *) regs->u_regs[UREG_FP]);
5798 }
5799@@ -284,7 +284,7 @@ void arch_trigger_all_cpu_backtrace(void)
5800 ((tp && tp->task) ? tp->task->pid : -1));
5801
5802 if (gp->tstate & TSTATE_PRIV) {
5803- printk(" TPC[%pS] O7[%pS] I7[%pS] RPC[%pS]\n",
5804+ printk(" TPC[%pA] O7[%pA] I7[%pA] RPC[%pA]\n",
5805 (void *) gp->tpc,
5806 (void *) gp->o7,
5807 (void *) gp->i7,
5808diff --git a/arch/sparc/kernel/ptrace_64.c b/arch/sparc/kernel/ptrace_64.c
5809index 484daba..0674139 100644
5810--- a/arch/sparc/kernel/ptrace_64.c
5811+++ b/arch/sparc/kernel/ptrace_64.c
5812@@ -1057,6 +1057,10 @@ long arch_ptrace(struct task_struct *child, long request,
5813 return ret;
5814 }
5815
5816+#ifdef CONFIG_GRKERNSEC_SETXID
5817+extern void gr_delayed_cred_worker(void);
5818+#endif
5819+
5820 asmlinkage int syscall_trace_enter(struct pt_regs *regs)
5821 {
5822 int ret = 0;
5823@@ -1064,6 +1068,11 @@ asmlinkage int syscall_trace_enter(struct pt_regs *regs)
5824 /* do the secure computing check first */
5825 secure_computing_strict(regs->u_regs[UREG_G1]);
5826
5827+#ifdef CONFIG_GRKERNSEC_SETXID
5828+ if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
5829+ gr_delayed_cred_worker();
5830+#endif
5831+
5832 if (test_thread_flag(TIF_SYSCALL_TRACE))
5833 ret = tracehook_report_syscall_entry(regs);
5834
5835@@ -1084,6 +1093,11 @@ asmlinkage int syscall_trace_enter(struct pt_regs *regs)
5836
5837 asmlinkage void syscall_trace_leave(struct pt_regs *regs)
5838 {
5839+#ifdef CONFIG_GRKERNSEC_SETXID
5840+ if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
5841+ gr_delayed_cred_worker();
5842+#endif
5843+
5844 audit_syscall_exit(regs);
5845
5846 if (unlikely(test_thread_flag(TIF_SYSCALL_TRACEPOINT)))
5847diff --git a/arch/sparc/kernel/sys_sparc_32.c b/arch/sparc/kernel/sys_sparc_32.c
5848index 0c9b31b..7cb7aee 100644
5849--- a/arch/sparc/kernel/sys_sparc_32.c
5850+++ b/arch/sparc/kernel/sys_sparc_32.c
5851@@ -54,7 +54,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
5852 if (len > TASK_SIZE - PAGE_SIZE)
5853 return -ENOMEM;
5854 if (!addr)
5855- addr = TASK_UNMAPPED_BASE;
5856+ addr = current->mm->mmap_base;
5857
5858 if (flags & MAP_SHARED)
5859 addr = COLOUR_ALIGN(addr);
5860@@ -65,7 +65,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
5861 /* At this point: (!vmm || addr < vmm->vm_end). */
5862 if (TASK_SIZE - PAGE_SIZE - len < addr)
5863 return -ENOMEM;
5864- if (!vmm || addr + len <= vmm->vm_start)
5865+ if (check_heap_stack_gap(vmm, addr, len))
5866 return addr;
5867 addr = vmm->vm_end;
5868 if (flags & MAP_SHARED)
5869diff --git a/arch/sparc/kernel/sys_sparc_64.c b/arch/sparc/kernel/sys_sparc_64.c
5870index 11c6c96..3ec33e8 100644
5871--- a/arch/sparc/kernel/sys_sparc_64.c
5872+++ b/arch/sparc/kernel/sys_sparc_64.c
5873@@ -107,7 +107,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
5874 /* We do not accept a shared mapping if it would violate
5875 * cache aliasing constraints.
5876 */
5877- if ((flags & MAP_SHARED) &&
5878+ if ((filp || (flags & MAP_SHARED)) &&
5879 ((addr - (pgoff << PAGE_SHIFT)) & (SHMLBA - 1)))
5880 return -EINVAL;
5881 return addr;
5882@@ -122,6 +122,10 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
5883 if (filp || (flags & MAP_SHARED))
5884 do_color_align = 1;
5885
5886+#ifdef CONFIG_PAX_RANDMMAP
5887+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
5888+#endif
5889+
5890 if (addr) {
5891 if (do_color_align)
5892 addr = COLOUR_ALIGN(addr, pgoff);
5893@@ -129,15 +133,14 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
5894 addr = PAGE_ALIGN(addr);
5895
5896 vma = find_vma(mm, addr);
5897- if (task_size - len >= addr &&
5898- (!vma || addr + len <= vma->vm_start))
5899+ if (task_size - len >= addr && check_heap_stack_gap(vma, addr, len))
5900 return addr;
5901 }
5902
5903 if (len > mm->cached_hole_size) {
5904- start_addr = addr = mm->free_area_cache;
5905+ start_addr = addr = mm->free_area_cache;
5906 } else {
5907- start_addr = addr = TASK_UNMAPPED_BASE;
5908+ start_addr = addr = mm->mmap_base;
5909 mm->cached_hole_size = 0;
5910 }
5911
5912@@ -157,14 +160,14 @@ full_search:
5913 vma = find_vma(mm, VA_EXCLUDE_END);
5914 }
5915 if (unlikely(task_size < addr)) {
5916- if (start_addr != TASK_UNMAPPED_BASE) {
5917- start_addr = addr = TASK_UNMAPPED_BASE;
5918+ if (start_addr != mm->mmap_base) {
5919+ start_addr = addr = mm->mmap_base;
5920 mm->cached_hole_size = 0;
5921 goto full_search;
5922 }
5923 return -ENOMEM;
5924 }
5925- if (likely(!vma || addr + len <= vma->vm_start)) {
5926+ if (likely(check_heap_stack_gap(vma, addr, len))) {
5927 /*
5928 * Remember the place where we stopped the search:
5929 */
5930@@ -198,7 +201,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
5931 /* We do not accept a shared mapping if it would violate
5932 * cache aliasing constraints.
5933 */
5934- if ((flags & MAP_SHARED) &&
5935+ if ((filp || (flags & MAP_SHARED)) &&
5936 ((addr - (pgoff << PAGE_SHIFT)) & (SHMLBA - 1)))
5937 return -EINVAL;
5938 return addr;
5939@@ -219,8 +222,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
5940 addr = PAGE_ALIGN(addr);
5941
5942 vma = find_vma(mm, addr);
5943- if (task_size - len >= addr &&
5944- (!vma || addr + len <= vma->vm_start))
5945+ if (task_size - len >= addr && check_heap_stack_gap(vma, addr, len))
5946 return addr;
5947 }
5948
5949@@ -241,7 +243,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
5950 /* make sure it can fit in the remaining address space */
5951 if (likely(addr > len)) {
5952 vma = find_vma(mm, addr-len);
5953- if (!vma || addr <= vma->vm_start) {
5954+ if (check_heap_stack_gap(vma, addr - len, len)) {
5955 /* remember the address as a hint for next time */
5956 return (mm->free_area_cache = addr-len);
5957 }
5958@@ -250,18 +252,18 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
5959 if (unlikely(mm->mmap_base < len))
5960 goto bottomup;
5961
5962- addr = mm->mmap_base-len;
5963- if (do_color_align)
5964- addr = COLOUR_ALIGN_DOWN(addr, pgoff);
5965+ addr = mm->mmap_base - len;
5966
5967 do {
5968+ if (do_color_align)
5969+ addr = COLOUR_ALIGN_DOWN(addr, pgoff);
5970 /*
5971 * Lookup failure means no vma is above this address,
5972 * else if new region fits below vma->vm_start,
5973 * return with success:
5974 */
5975 vma = find_vma(mm, addr);
5976- if (likely(!vma || addr+len <= vma->vm_start)) {
5977+ if (likely(check_heap_stack_gap(vma, addr, len))) {
5978 /* remember the address as a hint for next time */
5979 return (mm->free_area_cache = addr);
5980 }
5981@@ -271,10 +273,8 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
5982 mm->cached_hole_size = vma->vm_start - addr;
5983
5984 /* try just below the current vma->vm_start */
5985- addr = vma->vm_start-len;
5986- if (do_color_align)
5987- addr = COLOUR_ALIGN_DOWN(addr, pgoff);
5988- } while (likely(len < vma->vm_start));
5989+ addr = skip_heap_stack_gap(vma, len);
5990+ } while (!IS_ERR_VALUE(addr));
5991
5992 bottomup:
5993 /*
5994@@ -373,6 +373,12 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
5995 gap == RLIM_INFINITY ||
5996 sysctl_legacy_va_layout) {
5997 mm->mmap_base = TASK_UNMAPPED_BASE + random_factor;
5998+
5999+#ifdef CONFIG_PAX_RANDMMAP
6000+ if (mm->pax_flags & MF_PAX_RANDMMAP)
6001+ mm->mmap_base += mm->delta_mmap;
6002+#endif
6003+
6004 mm->get_unmapped_area = arch_get_unmapped_area;
6005 mm->unmap_area = arch_unmap_area;
6006 } else {
6007@@ -385,6 +391,12 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
6008 gap = (task_size / 6 * 5);
6009
6010 mm->mmap_base = PAGE_ALIGN(task_size - gap - random_factor);
6011+
6012+#ifdef CONFIG_PAX_RANDMMAP
6013+ if (mm->pax_flags & MF_PAX_RANDMMAP)
6014+ mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
6015+#endif
6016+
6017 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
6018 mm->unmap_area = arch_unmap_area_topdown;
6019 }
6020diff --git a/arch/sparc/kernel/syscalls.S b/arch/sparc/kernel/syscalls.S
6021index 7f5f65d..3308382 100644
6022--- a/arch/sparc/kernel/syscalls.S
6023+++ b/arch/sparc/kernel/syscalls.S
6024@@ -62,7 +62,7 @@ sys32_rt_sigreturn:
6025 #endif
6026 .align 32
6027 1: ldx [%g6 + TI_FLAGS], %l5
6028- andcc %l5, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT|_TIF_SYSCALL_TRACEPOINT), %g0
6029+ andcc %l5, _TIF_WORK_SYSCALL, %g0
6030 be,pt %icc, rtrap
6031 nop
6032 call syscall_trace_leave
6033@@ -179,7 +179,7 @@ linux_sparc_syscall32:
6034
6035 srl %i5, 0, %o5 ! IEU1
6036 srl %i2, 0, %o2 ! IEU0 Group
6037- andcc %l0, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT|_TIF_SYSCALL_TRACEPOINT), %g0
6038+ andcc %l0, _TIF_WORK_SYSCALL, %g0
6039 bne,pn %icc, linux_syscall_trace32 ! CTI
6040 mov %i0, %l5 ! IEU1
6041 call %l7 ! CTI Group brk forced
6042@@ -202,7 +202,7 @@ linux_sparc_syscall:
6043
6044 mov %i3, %o3 ! IEU1
6045 mov %i4, %o4 ! IEU0 Group
6046- andcc %l0, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT|_TIF_SYSCALL_TRACEPOINT), %g0
6047+ andcc %l0, _TIF_WORK_SYSCALL, %g0
6048 bne,pn %icc, linux_syscall_trace ! CTI Group
6049 mov %i0, %l5 ! IEU0
6050 2: call %l7 ! CTI Group brk forced
6051@@ -218,7 +218,7 @@ ret_sys_call:
6052
6053 cmp %o0, -ERESTART_RESTARTBLOCK
6054 bgeu,pn %xcc, 1f
6055- andcc %l0, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT|_TIF_SYSCALL_TRACEPOINT), %g0
6056+ andcc %l0, _TIF_WORK_SYSCALL, %g0
6057 ldx [%sp + PTREGS_OFF + PT_V9_TNPC], %l1 ! pc = npc
6058
6059 2:
6060diff --git a/arch/sparc/kernel/traps_32.c b/arch/sparc/kernel/traps_32.c
6061index a5785ea..405c5f7 100644
6062--- a/arch/sparc/kernel/traps_32.c
6063+++ b/arch/sparc/kernel/traps_32.c
6064@@ -44,6 +44,8 @@ static void instruction_dump(unsigned long *pc)
6065 #define __SAVE __asm__ __volatile__("save %sp, -0x40, %sp\n\t")
6066 #define __RESTORE __asm__ __volatile__("restore %g0, %g0, %g0\n\t")
6067
6068+extern void gr_handle_kernel_exploit(void);
6069+
6070 void die_if_kernel(char *str, struct pt_regs *regs)
6071 {
6072 static int die_counter;
6073@@ -76,15 +78,17 @@ void die_if_kernel(char *str, struct pt_regs *regs)
6074 count++ < 30 &&
6075 (((unsigned long) rw) >= PAGE_OFFSET) &&
6076 !(((unsigned long) rw) & 0x7)) {
6077- printk("Caller[%08lx]: %pS\n", rw->ins[7],
6078+ printk("Caller[%08lx]: %pA\n", rw->ins[7],
6079 (void *) rw->ins[7]);
6080 rw = (struct reg_window32 *)rw->ins[6];
6081 }
6082 }
6083 printk("Instruction DUMP:");
6084 instruction_dump ((unsigned long *) regs->pc);
6085- if(regs->psr & PSR_PS)
6086+ if(regs->psr & PSR_PS) {
6087+ gr_handle_kernel_exploit();
6088 do_exit(SIGKILL);
6089+ }
6090 do_exit(SIGSEGV);
6091 }
6092
6093diff --git a/arch/sparc/kernel/traps_64.c b/arch/sparc/kernel/traps_64.c
6094index 3b05e66..6ea2917 100644
6095--- a/arch/sparc/kernel/traps_64.c
6096+++ b/arch/sparc/kernel/traps_64.c
6097@@ -75,7 +75,7 @@ static void dump_tl1_traplog(struct tl1_traplog *p)
6098 i + 1,
6099 p->trapstack[i].tstate, p->trapstack[i].tpc,
6100 p->trapstack[i].tnpc, p->trapstack[i].tt);
6101- printk("TRAPLOG: TPC<%pS>\n", (void *) p->trapstack[i].tpc);
6102+ printk("TRAPLOG: TPC<%pA>\n", (void *) p->trapstack[i].tpc);
6103 }
6104 }
6105
6106@@ -95,6 +95,12 @@ void bad_trap(struct pt_regs *regs, long lvl)
6107
6108 lvl -= 0x100;
6109 if (regs->tstate & TSTATE_PRIV) {
6110+
6111+#ifdef CONFIG_PAX_REFCOUNT
6112+ if (lvl == 6)
6113+ pax_report_refcount_overflow(regs);
6114+#endif
6115+
6116 sprintf(buffer, "Kernel bad sw trap %lx", lvl);
6117 die_if_kernel(buffer, regs);
6118 }
6119@@ -113,11 +119,16 @@ void bad_trap(struct pt_regs *regs, long lvl)
6120 void bad_trap_tl1(struct pt_regs *regs, long lvl)
6121 {
6122 char buffer[32];
6123-
6124+
6125 if (notify_die(DIE_TRAP_TL1, "bad trap tl1", regs,
6126 0, lvl, SIGTRAP) == NOTIFY_STOP)
6127 return;
6128
6129+#ifdef CONFIG_PAX_REFCOUNT
6130+ if (lvl == 6)
6131+ pax_report_refcount_overflow(regs);
6132+#endif
6133+
6134 dump_tl1_traplog((struct tl1_traplog *)(regs + 1));
6135
6136 sprintf (buffer, "Bad trap %lx at tl>0", lvl);
6137@@ -1141,7 +1152,7 @@ static void cheetah_log_errors(struct pt_regs *regs, struct cheetah_err_info *in
6138 regs->tpc, regs->tnpc, regs->u_regs[UREG_I7], regs->tstate);
6139 printk("%s" "ERROR(%d): ",
6140 (recoverable ? KERN_WARNING : KERN_CRIT), smp_processor_id());
6141- printk("TPC<%pS>\n", (void *) regs->tpc);
6142+ printk("TPC<%pA>\n", (void *) regs->tpc);
6143 printk("%s" "ERROR(%d): M_SYND(%lx), E_SYND(%lx)%s%s\n",
6144 (recoverable ? KERN_WARNING : KERN_CRIT), smp_processor_id(),
6145 (afsr & CHAFSR_M_SYNDROME) >> CHAFSR_M_SYNDROME_SHIFT,
6146@@ -1748,7 +1759,7 @@ void cheetah_plus_parity_error(int type, struct pt_regs *regs)
6147 smp_processor_id(),
6148 (type & 0x1) ? 'I' : 'D',
6149 regs->tpc);
6150- printk(KERN_EMERG "TPC<%pS>\n", (void *) regs->tpc);
6151+ printk(KERN_EMERG "TPC<%pA>\n", (void *) regs->tpc);
6152 panic("Irrecoverable Cheetah+ parity error.");
6153 }
6154
6155@@ -1756,7 +1767,7 @@ void cheetah_plus_parity_error(int type, struct pt_regs *regs)
6156 smp_processor_id(),
6157 (type & 0x1) ? 'I' : 'D',
6158 regs->tpc);
6159- printk(KERN_WARNING "TPC<%pS>\n", (void *) regs->tpc);
6160+ printk(KERN_WARNING "TPC<%pA>\n", (void *) regs->tpc);
6161 }
6162
6163 struct sun4v_error_entry {
6164@@ -1963,9 +1974,9 @@ void sun4v_itlb_error_report(struct pt_regs *regs, int tl)
6165
6166 printk(KERN_EMERG "SUN4V-ITLB: Error at TPC[%lx], tl %d\n",
6167 regs->tpc, tl);
6168- printk(KERN_EMERG "SUN4V-ITLB: TPC<%pS>\n", (void *) regs->tpc);
6169+ printk(KERN_EMERG "SUN4V-ITLB: TPC<%pA>\n", (void *) regs->tpc);
6170 printk(KERN_EMERG "SUN4V-ITLB: O7[%lx]\n", regs->u_regs[UREG_I7]);
6171- printk(KERN_EMERG "SUN4V-ITLB: O7<%pS>\n",
6172+ printk(KERN_EMERG "SUN4V-ITLB: O7<%pA>\n",
6173 (void *) regs->u_regs[UREG_I7]);
6174 printk(KERN_EMERG "SUN4V-ITLB: vaddr[%lx] ctx[%lx] "
6175 "pte[%lx] error[%lx]\n",
6176@@ -1987,9 +1998,9 @@ void sun4v_dtlb_error_report(struct pt_regs *regs, int tl)
6177
6178 printk(KERN_EMERG "SUN4V-DTLB: Error at TPC[%lx], tl %d\n",
6179 regs->tpc, tl);
6180- printk(KERN_EMERG "SUN4V-DTLB: TPC<%pS>\n", (void *) regs->tpc);
6181+ printk(KERN_EMERG "SUN4V-DTLB: TPC<%pA>\n", (void *) regs->tpc);
6182 printk(KERN_EMERG "SUN4V-DTLB: O7[%lx]\n", regs->u_regs[UREG_I7]);
6183- printk(KERN_EMERG "SUN4V-DTLB: O7<%pS>\n",
6184+ printk(KERN_EMERG "SUN4V-DTLB: O7<%pA>\n",
6185 (void *) regs->u_regs[UREG_I7]);
6186 printk(KERN_EMERG "SUN4V-DTLB: vaddr[%lx] ctx[%lx] "
6187 "pte[%lx] error[%lx]\n",
6188@@ -2195,13 +2206,13 @@ void show_stack(struct task_struct *tsk, unsigned long *_ksp)
6189 fp = (unsigned long)sf->fp + STACK_BIAS;
6190 }
6191
6192- printk(" [%016lx] %pS\n", pc, (void *) pc);
6193+ printk(" [%016lx] %pA\n", pc, (void *) pc);
6194 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
6195 if ((pc + 8UL) == (unsigned long) &return_to_handler) {
6196 int index = tsk->curr_ret_stack;
6197 if (tsk->ret_stack && index >= graph) {
6198 pc = tsk->ret_stack[index - graph].ret;
6199- printk(" [%016lx] %pS\n", pc, (void *) pc);
6200+ printk(" [%016lx] %pA\n", pc, (void *) pc);
6201 graph++;
6202 }
6203 }
6204@@ -2226,6 +2237,8 @@ static inline struct reg_window *kernel_stack_up(struct reg_window *rw)
6205 return (struct reg_window *) (fp + STACK_BIAS);
6206 }
6207
6208+extern void gr_handle_kernel_exploit(void);
6209+
6210 void die_if_kernel(char *str, struct pt_regs *regs)
6211 {
6212 static int die_counter;
6213@@ -2254,7 +2267,7 @@ void die_if_kernel(char *str, struct pt_regs *regs)
6214 while (rw &&
6215 count++ < 30 &&
6216 kstack_valid(tp, (unsigned long) rw)) {
6217- printk("Caller[%016lx]: %pS\n", rw->ins[7],
6218+ printk("Caller[%016lx]: %pA\n", rw->ins[7],
6219 (void *) rw->ins[7]);
6220
6221 rw = kernel_stack_up(rw);
6222@@ -2267,8 +2280,10 @@ void die_if_kernel(char *str, struct pt_regs *regs)
6223 }
6224 user_instruction_dump ((unsigned int __user *) regs->tpc);
6225 }
6226- if (regs->tstate & TSTATE_PRIV)
6227+ if (regs->tstate & TSTATE_PRIV) {
6228+ gr_handle_kernel_exploit();
6229 do_exit(SIGKILL);
6230+ }
6231 do_exit(SIGSEGV);
6232 }
6233 EXPORT_SYMBOL(die_if_kernel);
6234diff --git a/arch/sparc/kernel/unaligned_64.c b/arch/sparc/kernel/unaligned_64.c
6235index f81d038..e7a4680 100644
6236--- a/arch/sparc/kernel/unaligned_64.c
6237+++ b/arch/sparc/kernel/unaligned_64.c
6238@@ -278,7 +278,7 @@ static void log_unaligned(struct pt_regs *regs)
6239 static DEFINE_RATELIMIT_STATE(ratelimit, 5 * HZ, 5);
6240
6241 if (__ratelimit(&ratelimit)) {
6242- printk("Kernel unaligned access at TPC[%lx] %pS\n",
6243+ printk("Kernel unaligned access at TPC[%lx] %pA\n",
6244 regs->tpc, (void *) regs->tpc);
6245 }
6246 }
6247diff --git a/arch/sparc/lib/Makefile b/arch/sparc/lib/Makefile
6248index dff4096..bd9a388 100644
6249--- a/arch/sparc/lib/Makefile
6250+++ b/arch/sparc/lib/Makefile
6251@@ -2,7 +2,7 @@
6252 #
6253
6254 asflags-y := -ansi -DST_DIV0=0x02
6255-ccflags-y := -Werror
6256+#ccflags-y := -Werror
6257
6258 lib-$(CONFIG_SPARC32) += ashrdi3.o
6259 lib-$(CONFIG_SPARC32) += memcpy.o memset.o
6260diff --git a/arch/sparc/lib/atomic_64.S b/arch/sparc/lib/atomic_64.S
6261index 4d502da..527c48d 100644
6262--- a/arch/sparc/lib/atomic_64.S
6263+++ b/arch/sparc/lib/atomic_64.S
6264@@ -17,7 +17,12 @@
6265 ENTRY(atomic_add) /* %o0 = increment, %o1 = atomic_ptr */
6266 BACKOFF_SETUP(%o2)
6267 1: lduw [%o1], %g1
6268- add %g1, %o0, %g7
6269+ addcc %g1, %o0, %g7
6270+
6271+#ifdef CONFIG_PAX_REFCOUNT
6272+ tvs %icc, 6
6273+#endif
6274+
6275 cas [%o1], %g1, %g7
6276 cmp %g1, %g7
6277 bne,pn %icc, BACKOFF_LABEL(2f, 1b)
6278@@ -27,10 +32,28 @@ ENTRY(atomic_add) /* %o0 = increment, %o1 = atomic_ptr */
6279 2: BACKOFF_SPIN(%o2, %o3, 1b)
6280 ENDPROC(atomic_add)
6281
6282+ENTRY(atomic_add_unchecked) /* %o0 = increment, %o1 = atomic_ptr */
6283+ BACKOFF_SETUP(%o2)
6284+1: lduw [%o1], %g1
6285+ add %g1, %o0, %g7
6286+ cas [%o1], %g1, %g7
6287+ cmp %g1, %g7
6288+ bne,pn %icc, 2f
6289+ nop
6290+ retl
6291+ nop
6292+2: BACKOFF_SPIN(%o2, %o3, 1b)
6293+ENDPROC(atomic_add_unchecked)
6294+
6295 ENTRY(atomic_sub) /* %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@@ -40,10 +63,28 @@ ENTRY(atomic_sub) /* %o0 = decrement, %o1 = atomic_ptr */
6309 2: BACKOFF_SPIN(%o2, %o3, 1b)
6310 ENDPROC(atomic_sub)
6311
6312+ENTRY(atomic_sub_unchecked) /* %o0 = decrement, %o1 = atomic_ptr */
6313+ BACKOFF_SETUP(%o2)
6314+1: lduw [%o1], %g1
6315+ sub %g1, %o0, %g7
6316+ cas [%o1], %g1, %g7
6317+ cmp %g1, %g7
6318+ bne,pn %icc, 2f
6319+ nop
6320+ retl
6321+ nop
6322+2: BACKOFF_SPIN(%o2, %o3, 1b)
6323+ENDPROC(atomic_sub_unchecked)
6324+
6325 ENTRY(atomic_add_ret) /* %o0 = increment, %o1 = atomic_ptr */
6326 BACKOFF_SETUP(%o2)
6327 1: lduw [%o1], %g1
6328- add %g1, %o0, %g7
6329+ addcc %g1, %o0, %g7
6330+
6331+#ifdef CONFIG_PAX_REFCOUNT
6332+ tvs %icc, 6
6333+#endif
6334+
6335 cas [%o1], %g1, %g7
6336 cmp %g1, %g7
6337 bne,pn %icc, BACKOFF_LABEL(2f, 1b)
6338@@ -53,10 +94,29 @@ ENTRY(atomic_add_ret) /* %o0 = increment, %o1 = atomic_ptr */
6339 2: BACKOFF_SPIN(%o2, %o3, 1b)
6340 ENDPROC(atomic_add_ret)
6341
6342+ENTRY(atomic_add_ret_unchecked) /* %o0 = increment, %o1 = atomic_ptr */
6343+ BACKOFF_SETUP(%o2)
6344+1: lduw [%o1], %g1
6345+ addcc %g1, %o0, %g7
6346+ cas [%o1], %g1, %g7
6347+ cmp %g1, %g7
6348+ bne,pn %icc, 2f
6349+ add %g7, %o0, %g7
6350+ sra %g7, 0, %o0
6351+ retl
6352+ nop
6353+2: BACKOFF_SPIN(%o2, %o3, 1b)
6354+ENDPROC(atomic_add_ret_unchecked)
6355+
6356 ENTRY(atomic_sub_ret) /* %o0 = decrement, %o1 = atomic_ptr */
6357 BACKOFF_SETUP(%o2)
6358 1: lduw [%o1], %g1
6359- sub %g1, %o0, %g7
6360+ subcc %g1, %o0, %g7
6361+
6362+#ifdef CONFIG_PAX_REFCOUNT
6363+ tvs %icc, 6
6364+#endif
6365+
6366 cas [%o1], %g1, %g7
6367 cmp %g1, %g7
6368 bne,pn %icc, BACKOFF_LABEL(2f, 1b)
6369@@ -69,7 +129,12 @@ ENDPROC(atomic_sub_ret)
6370 ENTRY(atomic64_add) /* %o0 = increment, %o1 = atomic_ptr */
6371 BACKOFF_SETUP(%o2)
6372 1: ldx [%o1], %g1
6373- add %g1, %o0, %g7
6374+ addcc %g1, %o0, %g7
6375+
6376+#ifdef CONFIG_PAX_REFCOUNT
6377+ tvs %xcc, 6
6378+#endif
6379+
6380 casx [%o1], %g1, %g7
6381 cmp %g1, %g7
6382 bne,pn %xcc, BACKOFF_LABEL(2f, 1b)
6383@@ -79,10 +144,28 @@ ENTRY(atomic64_add) /* %o0 = increment, %o1 = atomic_ptr */
6384 2: BACKOFF_SPIN(%o2, %o3, 1b)
6385 ENDPROC(atomic64_add)
6386
6387+ENTRY(atomic64_add_unchecked) /* %o0 = increment, %o1 = atomic_ptr */
6388+ BACKOFF_SETUP(%o2)
6389+1: ldx [%o1], %g1
6390+ addcc %g1, %o0, %g7
6391+ casx [%o1], %g1, %g7
6392+ cmp %g1, %g7
6393+ bne,pn %xcc, 2f
6394+ nop
6395+ retl
6396+ nop
6397+2: BACKOFF_SPIN(%o2, %o3, 1b)
6398+ENDPROC(atomic64_add_unchecked)
6399+
6400 ENTRY(atomic64_sub) /* %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)
6413@@ -92,10 +175,28 @@ ENTRY(atomic64_sub) /* %o0 = decrement, %o1 = atomic_ptr */
6414 2: BACKOFF_SPIN(%o2, %o3, 1b)
6415 ENDPROC(atomic64_sub)
6416
6417+ENTRY(atomic64_sub_unchecked) /* %o0 = decrement, %o1 = atomic_ptr */
6418+ BACKOFF_SETUP(%o2)
6419+1: ldx [%o1], %g1
6420+ subcc %g1, %o0, %g7
6421+ casx [%o1], %g1, %g7
6422+ cmp %g1, %g7
6423+ bne,pn %xcc, 2f
6424+ nop
6425+ retl
6426+ nop
6427+2: BACKOFF_SPIN(%o2, %o3, 1b)
6428+ENDPROC(atomic64_sub_unchecked)
6429+
6430 ENTRY(atomic64_add_ret) /* %o0 = increment, %o1 = atomic_ptr */
6431 BACKOFF_SETUP(%o2)
6432 1: ldx [%o1], %g1
6433- add %g1, %o0, %g7
6434+ addcc %g1, %o0, %g7
6435+
6436+#ifdef CONFIG_PAX_REFCOUNT
6437+ tvs %xcc, 6
6438+#endif
6439+
6440 casx [%o1], %g1, %g7
6441 cmp %g1, %g7
6442 bne,pn %xcc, BACKOFF_LABEL(2f, 1b)
6443@@ -105,10 +206,29 @@ ENTRY(atomic64_add_ret) /* %o0 = increment, %o1 = atomic_ptr */
6444 2: BACKOFF_SPIN(%o2, %o3, 1b)
6445 ENDPROC(atomic64_add_ret)
6446
6447+ENTRY(atomic64_add_ret_unchecked) /* %o0 = increment, %o1 = atomic_ptr */
6448+ BACKOFF_SETUP(%o2)
6449+1: ldx [%o1], %g1
6450+ addcc %g1, %o0, %g7
6451+ casx [%o1], %g1, %g7
6452+ cmp %g1, %g7
6453+ bne,pn %xcc, 2f
6454+ add %g7, %o0, %g7
6455+ mov %g7, %o0
6456+ retl
6457+ nop
6458+2: BACKOFF_SPIN(%o2, %o3, 1b)
6459+ENDPROC(atomic64_add_ret_unchecked)
6460+
6461 ENTRY(atomic64_sub_ret) /* %o0 = decrement, %o1 = atomic_ptr */
6462 BACKOFF_SETUP(%o2)
6463 1: ldx [%o1], %g1
6464- sub %g1, %o0, %g7
6465+ subcc %g1, %o0, %g7
6466+
6467+#ifdef CONFIG_PAX_REFCOUNT
6468+ tvs %xcc, 6
6469+#endif
6470+
6471 casx [%o1], %g1, %g7
6472 cmp %g1, %g7
6473 bne,pn %xcc, BACKOFF_LABEL(2f, 1b)
6474diff --git a/arch/sparc/lib/ksyms.c b/arch/sparc/lib/ksyms.c
6475index 3b31218..345c609 100644
6476--- a/arch/sparc/lib/ksyms.c
6477+++ b/arch/sparc/lib/ksyms.c
6478@@ -109,12 +109,18 @@ EXPORT_SYMBOL(__downgrade_write);
6479
6480 /* Atomic counter implementation. */
6481 EXPORT_SYMBOL(atomic_add);
6482+EXPORT_SYMBOL(atomic_add_unchecked);
6483 EXPORT_SYMBOL(atomic_add_ret);
6484+EXPORT_SYMBOL(atomic_add_ret_unchecked);
6485 EXPORT_SYMBOL(atomic_sub);
6486+EXPORT_SYMBOL(atomic_sub_unchecked);
6487 EXPORT_SYMBOL(atomic_sub_ret);
6488 EXPORT_SYMBOL(atomic64_add);
6489+EXPORT_SYMBOL(atomic64_add_unchecked);
6490 EXPORT_SYMBOL(atomic64_add_ret);
6491+EXPORT_SYMBOL(atomic64_add_ret_unchecked);
6492 EXPORT_SYMBOL(atomic64_sub);
6493+EXPORT_SYMBOL(atomic64_sub_unchecked);
6494 EXPORT_SYMBOL(atomic64_sub_ret);
6495
6496 /* Atomic bit operations. */
6497diff --git a/arch/sparc/mm/Makefile b/arch/sparc/mm/Makefile
6498index 30c3ecc..736f015 100644
6499--- a/arch/sparc/mm/Makefile
6500+++ b/arch/sparc/mm/Makefile
6501@@ -2,7 +2,7 @@
6502 #
6503
6504 asflags-y := -ansi
6505-ccflags-y := -Werror
6506+#ccflags-y := -Werror
6507
6508 obj-$(CONFIG_SPARC64) += ultra.o tlb.o tsb.o gup.o
6509 obj-y += fault_$(BITS).o
6510diff --git a/arch/sparc/mm/fault_32.c b/arch/sparc/mm/fault_32.c
6511index 77ac917..baf45db 100644
6512--- a/arch/sparc/mm/fault_32.c
6513+++ b/arch/sparc/mm/fault_32.c
6514@@ -21,6 +21,9 @@
6515 #include <linux/perf_event.h>
6516 #include <linux/interrupt.h>
6517 #include <linux/kdebug.h>
6518+#include <linux/slab.h>
6519+#include <linux/pagemap.h>
6520+#include <linux/compiler.h>
6521
6522 #include <asm/page.h>
6523 #include <asm/pgtable.h>
6524@@ -159,6 +162,277 @@ static unsigned long compute_si_addr(struct pt_regs *regs, int text_fault)
6525 return safe_compute_effective_address(regs, insn);
6526 }
6527
6528+#ifdef CONFIG_PAX_PAGEEXEC
6529+#ifdef CONFIG_PAX_DLRESOLVE
6530+static void pax_emuplt_close(struct vm_area_struct *vma)
6531+{
6532+ vma->vm_mm->call_dl_resolve = 0UL;
6533+}
6534+
6535+static int pax_emuplt_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
6536+{
6537+ unsigned int *kaddr;
6538+
6539+ vmf->page = alloc_page(GFP_HIGHUSER);
6540+ if (!vmf->page)
6541+ return VM_FAULT_OOM;
6542+
6543+ kaddr = kmap(vmf->page);
6544+ memset(kaddr, 0, PAGE_SIZE);
6545+ kaddr[0] = 0x9DE3BFA8U; /* save */
6546+ flush_dcache_page(vmf->page);
6547+ kunmap(vmf->page);
6548+ return VM_FAULT_MAJOR;
6549+}
6550+
6551+static const struct vm_operations_struct pax_vm_ops = {
6552+ .close = pax_emuplt_close,
6553+ .fault = pax_emuplt_fault
6554+};
6555+
6556+static int pax_insert_vma(struct vm_area_struct *vma, unsigned long addr)
6557+{
6558+ int ret;
6559+
6560+ INIT_LIST_HEAD(&vma->anon_vma_chain);
6561+ vma->vm_mm = current->mm;
6562+ vma->vm_start = addr;
6563+ vma->vm_end = addr + PAGE_SIZE;
6564+ vma->vm_flags = VM_READ | VM_EXEC | VM_MAYREAD | VM_MAYEXEC;
6565+ vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
6566+ vma->vm_ops = &pax_vm_ops;
6567+
6568+ ret = insert_vm_struct(current->mm, vma);
6569+ if (ret)
6570+ return ret;
6571+
6572+ ++current->mm->total_vm;
6573+ return 0;
6574+}
6575+#endif
6576+
6577+/*
6578+ * PaX: decide what to do with offenders (regs->pc = fault address)
6579+ *
6580+ * returns 1 when task should be killed
6581+ * 2 when patched PLT trampoline was detected
6582+ * 3 when unpatched PLT trampoline was detected
6583+ */
6584+static int pax_handle_fetch_fault(struct pt_regs *regs)
6585+{
6586+
6587+#ifdef CONFIG_PAX_EMUPLT
6588+ int err;
6589+
6590+ do { /* PaX: patched PLT emulation #1 */
6591+ unsigned int sethi1, sethi2, jmpl;
6592+
6593+ err = get_user(sethi1, (unsigned int *)regs->pc);
6594+ err |= get_user(sethi2, (unsigned int *)(regs->pc+4));
6595+ err |= get_user(jmpl, (unsigned int *)(regs->pc+8));
6596+
6597+ if (err)
6598+ break;
6599+
6600+ if ((sethi1 & 0xFFC00000U) == 0x03000000U &&
6601+ (sethi2 & 0xFFC00000U) == 0x03000000U &&
6602+ (jmpl & 0xFFFFE000U) == 0x81C06000U)
6603+ {
6604+ unsigned int addr;
6605+
6606+ regs->u_regs[UREG_G1] = (sethi2 & 0x003FFFFFU) << 10;
6607+ addr = regs->u_regs[UREG_G1];
6608+ addr += (((jmpl | 0xFFFFE000U) ^ 0x00001000U) + 0x00001000U);
6609+ regs->pc = addr;
6610+ regs->npc = addr+4;
6611+ return 2;
6612+ }
6613+ } while (0);
6614+
6615+ do { /* PaX: patched PLT emulation #2 */
6616+ unsigned int ba;
6617+
6618+ err = get_user(ba, (unsigned int *)regs->pc);
6619+
6620+ if (err)
6621+ break;
6622+
6623+ if ((ba & 0xFFC00000U) == 0x30800000U || (ba & 0xFFF80000U) == 0x30480000U) {
6624+ unsigned int addr;
6625+
6626+ if ((ba & 0xFFC00000U) == 0x30800000U)
6627+ addr = regs->pc + ((((ba | 0xFFC00000U) ^ 0x00200000U) + 0x00200000U) << 2);
6628+ else
6629+ addr = regs->pc + ((((ba | 0xFFF80000U) ^ 0x00040000U) + 0x00040000U) << 2);
6630+ regs->pc = addr;
6631+ regs->npc = addr+4;
6632+ return 2;
6633+ }
6634+ } while (0);
6635+
6636+ do { /* PaX: patched PLT emulation #3 */
6637+ unsigned int sethi, bajmpl, nop;
6638+
6639+ err = get_user(sethi, (unsigned int *)regs->pc);
6640+ err |= get_user(bajmpl, (unsigned int *)(regs->pc+4));
6641+ err |= get_user(nop, (unsigned int *)(regs->pc+8));
6642+
6643+ if (err)
6644+ break;
6645+
6646+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
6647+ ((bajmpl & 0xFFFFE000U) == 0x81C06000U || (bajmpl & 0xFFF80000U) == 0x30480000U) &&
6648+ nop == 0x01000000U)
6649+ {
6650+ unsigned int addr;
6651+
6652+ addr = (sethi & 0x003FFFFFU) << 10;
6653+ regs->u_regs[UREG_G1] = addr;
6654+ if ((bajmpl & 0xFFFFE000U) == 0x81C06000U)
6655+ addr += (((bajmpl | 0xFFFFE000U) ^ 0x00001000U) + 0x00001000U);
6656+ else
6657+ addr = regs->pc + ((((bajmpl | 0xFFF80000U) ^ 0x00040000U) + 0x00040000U) << 2);
6658+ regs->pc = addr;
6659+ regs->npc = addr+4;
6660+ return 2;
6661+ }
6662+ } while (0);
6663+
6664+ do { /* PaX: unpatched PLT emulation step 1 */
6665+ unsigned int sethi, ba, nop;
6666+
6667+ err = get_user(sethi, (unsigned int *)regs->pc);
6668+ err |= get_user(ba, (unsigned int *)(regs->pc+4));
6669+ err |= get_user(nop, (unsigned int *)(regs->pc+8));
6670+
6671+ if (err)
6672+ break;
6673+
6674+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
6675+ ((ba & 0xFFC00000U) == 0x30800000U || (ba & 0xFFF80000U) == 0x30680000U) &&
6676+ nop == 0x01000000U)
6677+ {
6678+ unsigned int addr, save, call;
6679+
6680+ if ((ba & 0xFFC00000U) == 0x30800000U)
6681+ addr = regs->pc + 4 + ((((ba | 0xFFC00000U) ^ 0x00200000U) + 0x00200000U) << 2);
6682+ else
6683+ addr = regs->pc + 4 + ((((ba | 0xFFF80000U) ^ 0x00040000U) + 0x00040000U) << 2);
6684+
6685+ err = get_user(save, (unsigned int *)addr);
6686+ err |= get_user(call, (unsigned int *)(addr+4));
6687+ err |= get_user(nop, (unsigned int *)(addr+8));
6688+ if (err)
6689+ break;
6690+
6691+#ifdef CONFIG_PAX_DLRESOLVE
6692+ if (save == 0x9DE3BFA8U &&
6693+ (call & 0xC0000000U) == 0x40000000U &&
6694+ nop == 0x01000000U)
6695+ {
6696+ struct vm_area_struct *vma;
6697+ unsigned long call_dl_resolve;
6698+
6699+ down_read(&current->mm->mmap_sem);
6700+ call_dl_resolve = current->mm->call_dl_resolve;
6701+ up_read(&current->mm->mmap_sem);
6702+ if (likely(call_dl_resolve))
6703+ goto emulate;
6704+
6705+ vma = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
6706+
6707+ down_write(&current->mm->mmap_sem);
6708+ if (current->mm->call_dl_resolve) {
6709+ call_dl_resolve = current->mm->call_dl_resolve;
6710+ up_write(&current->mm->mmap_sem);
6711+ if (vma)
6712+ kmem_cache_free(vm_area_cachep, vma);
6713+ goto emulate;
6714+ }
6715+
6716+ call_dl_resolve = get_unmapped_area(NULL, 0UL, PAGE_SIZE, 0UL, MAP_PRIVATE);
6717+ if (!vma || (call_dl_resolve & ~PAGE_MASK)) {
6718+ up_write(&current->mm->mmap_sem);
6719+ if (vma)
6720+ kmem_cache_free(vm_area_cachep, vma);
6721+ return 1;
6722+ }
6723+
6724+ if (pax_insert_vma(vma, call_dl_resolve)) {
6725+ up_write(&current->mm->mmap_sem);
6726+ kmem_cache_free(vm_area_cachep, vma);
6727+ return 1;
6728+ }
6729+
6730+ current->mm->call_dl_resolve = call_dl_resolve;
6731+ up_write(&current->mm->mmap_sem);
6732+
6733+emulate:
6734+ regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
6735+ regs->pc = call_dl_resolve;
6736+ regs->npc = addr+4;
6737+ return 3;
6738+ }
6739+#endif
6740+
6741+ /* PaX: glibc 2.4+ generates sethi/jmpl instead of save/call */
6742+ if ((save & 0xFFC00000U) == 0x05000000U &&
6743+ (call & 0xFFFFE000U) == 0x85C0A000U &&
6744+ nop == 0x01000000U)
6745+ {
6746+ regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
6747+ regs->u_regs[UREG_G2] = addr + 4;
6748+ addr = (save & 0x003FFFFFU) << 10;
6749+ addr += (((call | 0xFFFFE000U) ^ 0x00001000U) + 0x00001000U);
6750+ regs->pc = addr;
6751+ regs->npc = addr+4;
6752+ return 3;
6753+ }
6754+ }
6755+ } while (0);
6756+
6757+ do { /* PaX: unpatched PLT emulation step 2 */
6758+ unsigned int save, call, nop;
6759+
6760+ err = get_user(save, (unsigned int *)(regs->pc-4));
6761+ err |= get_user(call, (unsigned int *)regs->pc);
6762+ err |= get_user(nop, (unsigned int *)(regs->pc+4));
6763+ if (err)
6764+ break;
6765+
6766+ if (save == 0x9DE3BFA8U &&
6767+ (call & 0xC0000000U) == 0x40000000U &&
6768+ nop == 0x01000000U)
6769+ {
6770+ unsigned int dl_resolve = regs->pc + ((((call | 0xC0000000U) ^ 0x20000000U) + 0x20000000U) << 2);
6771+
6772+ regs->u_regs[UREG_RETPC] = regs->pc;
6773+ regs->pc = dl_resolve;
6774+ regs->npc = dl_resolve+4;
6775+ return 3;
6776+ }
6777+ } while (0);
6778+#endif
6779+
6780+ return 1;
6781+}
6782+
6783+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
6784+{
6785+ unsigned long i;
6786+
6787+ printk(KERN_ERR "PAX: bytes at PC: ");
6788+ for (i = 0; i < 8; i++) {
6789+ unsigned int c;
6790+ if (get_user(c, (unsigned int *)pc+i))
6791+ printk(KERN_CONT "???????? ");
6792+ else
6793+ printk(KERN_CONT "%08x ", c);
6794+ }
6795+ printk("\n");
6796+}
6797+#endif
6798+
6799 static noinline void do_fault_siginfo(int code, int sig, struct pt_regs *regs,
6800 int text_fault)
6801 {
6802@@ -230,6 +504,24 @@ good_area:
6803 if (!(vma->vm_flags & VM_WRITE))
6804 goto bad_area;
6805 } else {
6806+
6807+#ifdef CONFIG_PAX_PAGEEXEC
6808+ if ((mm->pax_flags & MF_PAX_PAGEEXEC) && text_fault && !(vma->vm_flags & VM_EXEC)) {
6809+ up_read(&mm->mmap_sem);
6810+ switch (pax_handle_fetch_fault(regs)) {
6811+
6812+#ifdef CONFIG_PAX_EMUPLT
6813+ case 2:
6814+ case 3:
6815+ return;
6816+#endif
6817+
6818+ }
6819+ pax_report_fault(regs, (void *)regs->pc, (void *)regs->u_regs[UREG_FP]);
6820+ do_group_exit(SIGKILL);
6821+ }
6822+#endif
6823+
6824 /* Allow reads even for write-only mappings */
6825 if (!(vma->vm_flags & (VM_READ | VM_EXEC)))
6826 goto bad_area;
6827diff --git a/arch/sparc/mm/fault_64.c b/arch/sparc/mm/fault_64.c
6828index 1fe0429..8dd5dd5 100644
6829--- a/arch/sparc/mm/fault_64.c
6830+++ b/arch/sparc/mm/fault_64.c
6831@@ -21,6 +21,9 @@
6832 #include <linux/kprobes.h>
6833 #include <linux/kdebug.h>
6834 #include <linux/percpu.h>
6835+#include <linux/slab.h>
6836+#include <linux/pagemap.h>
6837+#include <linux/compiler.h>
6838
6839 #include <asm/page.h>
6840 #include <asm/pgtable.h>
6841@@ -74,7 +77,7 @@ static void __kprobes bad_kernel_pc(struct pt_regs *regs, unsigned long vaddr)
6842 printk(KERN_CRIT "OOPS: Bogus kernel PC [%016lx] in fault handler\n",
6843 regs->tpc);
6844 printk(KERN_CRIT "OOPS: RPC [%016lx]\n", regs->u_regs[15]);
6845- printk("OOPS: RPC <%pS>\n", (void *) regs->u_regs[15]);
6846+ printk("OOPS: RPC <%pA>\n", (void *) regs->u_regs[15]);
6847 printk(KERN_CRIT "OOPS: Fault was to vaddr[%lx]\n", vaddr);
6848 dump_stack();
6849 unhandled_fault(regs->tpc, current, regs);
6850@@ -272,6 +275,466 @@ static void noinline __kprobes bogus_32bit_fault_address(struct pt_regs *regs,
6851 show_regs(regs);
6852 }
6853
6854+#ifdef CONFIG_PAX_PAGEEXEC
6855+#ifdef CONFIG_PAX_DLRESOLVE
6856+static void pax_emuplt_close(struct vm_area_struct *vma)
6857+{
6858+ vma->vm_mm->call_dl_resolve = 0UL;
6859+}
6860+
6861+static int pax_emuplt_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
6862+{
6863+ unsigned int *kaddr;
6864+
6865+ vmf->page = alloc_page(GFP_HIGHUSER);
6866+ if (!vmf->page)
6867+ return VM_FAULT_OOM;
6868+
6869+ kaddr = kmap(vmf->page);
6870+ memset(kaddr, 0, PAGE_SIZE);
6871+ kaddr[0] = 0x9DE3BFA8U; /* save */
6872+ flush_dcache_page(vmf->page);
6873+ kunmap(vmf->page);
6874+ return VM_FAULT_MAJOR;
6875+}
6876+
6877+static const struct vm_operations_struct pax_vm_ops = {
6878+ .close = pax_emuplt_close,
6879+ .fault = pax_emuplt_fault
6880+};
6881+
6882+static int pax_insert_vma(struct vm_area_struct *vma, unsigned long addr)
6883+{
6884+ int ret;
6885+
6886+ INIT_LIST_HEAD(&vma->anon_vma_chain);
6887+ vma->vm_mm = current->mm;
6888+ vma->vm_start = addr;
6889+ vma->vm_end = addr + PAGE_SIZE;
6890+ vma->vm_flags = VM_READ | VM_EXEC | VM_MAYREAD | VM_MAYEXEC;
6891+ vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
6892+ vma->vm_ops = &pax_vm_ops;
6893+
6894+ ret = insert_vm_struct(current->mm, vma);
6895+ if (ret)
6896+ return ret;
6897+
6898+ ++current->mm->total_vm;
6899+ return 0;
6900+}
6901+#endif
6902+
6903+/*
6904+ * PaX: decide what to do with offenders (regs->tpc = fault address)
6905+ *
6906+ * returns 1 when task should be killed
6907+ * 2 when patched PLT trampoline was detected
6908+ * 3 when unpatched PLT trampoline was detected
6909+ */
6910+static int pax_handle_fetch_fault(struct pt_regs *regs)
6911+{
6912+
6913+#ifdef CONFIG_PAX_EMUPLT
6914+ int err;
6915+
6916+ do { /* PaX: patched PLT emulation #1 */
6917+ unsigned int sethi1, sethi2, jmpl;
6918+
6919+ err = get_user(sethi1, (unsigned int *)regs->tpc);
6920+ err |= get_user(sethi2, (unsigned int *)(regs->tpc+4));
6921+ err |= get_user(jmpl, (unsigned int *)(regs->tpc+8));
6922+
6923+ if (err)
6924+ break;
6925+
6926+ if ((sethi1 & 0xFFC00000U) == 0x03000000U &&
6927+ (sethi2 & 0xFFC00000U) == 0x03000000U &&
6928+ (jmpl & 0xFFFFE000U) == 0x81C06000U)
6929+ {
6930+ unsigned long addr;
6931+
6932+ regs->u_regs[UREG_G1] = (sethi2 & 0x003FFFFFU) << 10;
6933+ addr = regs->u_regs[UREG_G1];
6934+ addr += (((jmpl | 0xFFFFFFFFFFFFE000UL) ^ 0x00001000UL) + 0x00001000UL);
6935+
6936+ if (test_thread_flag(TIF_32BIT))
6937+ addr &= 0xFFFFFFFFUL;
6938+
6939+ regs->tpc = addr;
6940+ regs->tnpc = addr+4;
6941+ return 2;
6942+ }
6943+ } while (0);
6944+
6945+ do { /* PaX: patched PLT emulation #2 */
6946+ unsigned int ba;
6947+
6948+ err = get_user(ba, (unsigned int *)regs->tpc);
6949+
6950+ if (err)
6951+ break;
6952+
6953+ if ((ba & 0xFFC00000U) == 0x30800000U || (ba & 0xFFF80000U) == 0x30480000U) {
6954+ unsigned long addr;
6955+
6956+ if ((ba & 0xFFC00000U) == 0x30800000U)
6957+ addr = regs->tpc + ((((ba | 0xFFFFFFFFFFC00000UL) ^ 0x00200000UL) + 0x00200000UL) << 2);
6958+ else
6959+ addr = regs->tpc + ((((ba | 0xFFFFFFFFFFF80000UL) ^ 0x00040000UL) + 0x00040000UL) << 2);
6960+
6961+ if (test_thread_flag(TIF_32BIT))
6962+ addr &= 0xFFFFFFFFUL;
6963+
6964+ regs->tpc = addr;
6965+ regs->tnpc = addr+4;
6966+ return 2;
6967+ }
6968+ } while (0);
6969+
6970+ do { /* PaX: patched PLT emulation #3 */
6971+ unsigned int sethi, bajmpl, nop;
6972+
6973+ err = get_user(sethi, (unsigned int *)regs->tpc);
6974+ err |= get_user(bajmpl, (unsigned int *)(regs->tpc+4));
6975+ err |= get_user(nop, (unsigned int *)(regs->tpc+8));
6976+
6977+ if (err)
6978+ break;
6979+
6980+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
6981+ ((bajmpl & 0xFFFFE000U) == 0x81C06000U || (bajmpl & 0xFFF80000U) == 0x30480000U) &&
6982+ nop == 0x01000000U)
6983+ {
6984+ unsigned long addr;
6985+
6986+ addr = (sethi & 0x003FFFFFU) << 10;
6987+ regs->u_regs[UREG_G1] = addr;
6988+ if ((bajmpl & 0xFFFFE000U) == 0x81C06000U)
6989+ addr += (((bajmpl | 0xFFFFFFFFFFFFE000UL) ^ 0x00001000UL) + 0x00001000UL);
6990+ else
6991+ addr = regs->tpc + ((((bajmpl | 0xFFFFFFFFFFF80000UL) ^ 0x00040000UL) + 0x00040000UL) << 2);
6992+
6993+ if (test_thread_flag(TIF_32BIT))
6994+ addr &= 0xFFFFFFFFUL;
6995+
6996+ regs->tpc = addr;
6997+ regs->tnpc = addr+4;
6998+ return 2;
6999+ }
7000+ } while (0);
7001+
7002+ do { /* PaX: patched PLT emulation #4 */
7003+ unsigned int sethi, mov1, call, mov2;
7004+
7005+ err = get_user(sethi, (unsigned int *)regs->tpc);
7006+ err |= get_user(mov1, (unsigned int *)(regs->tpc+4));
7007+ err |= get_user(call, (unsigned int *)(regs->tpc+8));
7008+ err |= get_user(mov2, (unsigned int *)(regs->tpc+12));
7009+
7010+ if (err)
7011+ break;
7012+
7013+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
7014+ mov1 == 0x8210000FU &&
7015+ (call & 0xC0000000U) == 0x40000000U &&
7016+ mov2 == 0x9E100001U)
7017+ {
7018+ unsigned long addr;
7019+
7020+ regs->u_regs[UREG_G1] = regs->u_regs[UREG_RETPC];
7021+ addr = regs->tpc + 4 + ((((call | 0xFFFFFFFFC0000000UL) ^ 0x20000000UL) + 0x20000000UL) << 2);
7022+
7023+ if (test_thread_flag(TIF_32BIT))
7024+ addr &= 0xFFFFFFFFUL;
7025+
7026+ regs->tpc = addr;
7027+ regs->tnpc = addr+4;
7028+ return 2;
7029+ }
7030+ } while (0);
7031+
7032+ do { /* PaX: patched PLT emulation #5 */
7033+ unsigned int sethi, sethi1, sethi2, or1, or2, sllx, jmpl, nop;
7034+
7035+ err = get_user(sethi, (unsigned int *)regs->tpc);
7036+ err |= get_user(sethi1, (unsigned int *)(regs->tpc+4));
7037+ err |= get_user(sethi2, (unsigned int *)(regs->tpc+8));
7038+ err |= get_user(or1, (unsigned int *)(regs->tpc+12));
7039+ err |= get_user(or2, (unsigned int *)(regs->tpc+16));
7040+ err |= get_user(sllx, (unsigned int *)(regs->tpc+20));
7041+ err |= get_user(jmpl, (unsigned int *)(regs->tpc+24));
7042+ err |= get_user(nop, (unsigned int *)(regs->tpc+28));
7043+
7044+ if (err)
7045+ break;
7046+
7047+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
7048+ (sethi1 & 0xFFC00000U) == 0x03000000U &&
7049+ (sethi2 & 0xFFC00000U) == 0x0B000000U &&
7050+ (or1 & 0xFFFFE000U) == 0x82106000U &&
7051+ (or2 & 0xFFFFE000U) == 0x8A116000U &&
7052+ sllx == 0x83287020U &&
7053+ jmpl == 0x81C04005U &&
7054+ nop == 0x01000000U)
7055+ {
7056+ unsigned long addr;
7057+
7058+ regs->u_regs[UREG_G1] = ((sethi1 & 0x003FFFFFU) << 10) | (or1 & 0x000003FFU);
7059+ regs->u_regs[UREG_G1] <<= 32;
7060+ regs->u_regs[UREG_G5] = ((sethi2 & 0x003FFFFFU) << 10) | (or2 & 0x000003FFU);
7061+ addr = regs->u_regs[UREG_G1] + regs->u_regs[UREG_G5];
7062+ regs->tpc = addr;
7063+ regs->tnpc = addr+4;
7064+ return 2;
7065+ }
7066+ } while (0);
7067+
7068+ do { /* PaX: patched PLT emulation #6 */
7069+ unsigned int sethi, sethi1, sethi2, sllx, or, jmpl, nop;
7070+
7071+ err = get_user(sethi, (unsigned int *)regs->tpc);
7072+ err |= get_user(sethi1, (unsigned int *)(regs->tpc+4));
7073+ err |= get_user(sethi2, (unsigned int *)(regs->tpc+8));
7074+ err |= get_user(sllx, (unsigned int *)(regs->tpc+12));
7075+ err |= get_user(or, (unsigned int *)(regs->tpc+16));
7076+ err |= get_user(jmpl, (unsigned int *)(regs->tpc+20));
7077+ err |= get_user(nop, (unsigned int *)(regs->tpc+24));
7078+
7079+ if (err)
7080+ break;
7081+
7082+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
7083+ (sethi1 & 0xFFC00000U) == 0x03000000U &&
7084+ (sethi2 & 0xFFC00000U) == 0x0B000000U &&
7085+ sllx == 0x83287020U &&
7086+ (or & 0xFFFFE000U) == 0x8A116000U &&
7087+ jmpl == 0x81C04005U &&
7088+ nop == 0x01000000U)
7089+ {
7090+ unsigned long addr;
7091+
7092+ regs->u_regs[UREG_G1] = (sethi1 & 0x003FFFFFU) << 10;
7093+ regs->u_regs[UREG_G1] <<= 32;
7094+ regs->u_regs[UREG_G5] = ((sethi2 & 0x003FFFFFU) << 10) | (or & 0x3FFU);
7095+ addr = regs->u_regs[UREG_G1] + regs->u_regs[UREG_G5];
7096+ regs->tpc = addr;
7097+ regs->tnpc = addr+4;
7098+ return 2;
7099+ }
7100+ } while (0);
7101+
7102+ do { /* PaX: unpatched PLT emulation step 1 */
7103+ unsigned int sethi, ba, nop;
7104+
7105+ err = get_user(sethi, (unsigned int *)regs->tpc);
7106+ err |= get_user(ba, (unsigned int *)(regs->tpc+4));
7107+ err |= get_user(nop, (unsigned int *)(regs->tpc+8));
7108+
7109+ if (err)
7110+ break;
7111+
7112+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
7113+ ((ba & 0xFFC00000U) == 0x30800000U || (ba & 0xFFF80000U) == 0x30680000U) &&
7114+ nop == 0x01000000U)
7115+ {
7116+ unsigned long addr;
7117+ unsigned int save, call;
7118+ unsigned int sethi1, sethi2, or1, or2, sllx, add, jmpl;
7119+
7120+ if ((ba & 0xFFC00000U) == 0x30800000U)
7121+ addr = regs->tpc + 4 + ((((ba | 0xFFFFFFFFFFC00000UL) ^ 0x00200000UL) + 0x00200000UL) << 2);
7122+ else
7123+ addr = regs->tpc + 4 + ((((ba | 0xFFFFFFFFFFF80000UL) ^ 0x00040000UL) + 0x00040000UL) << 2);
7124+
7125+ if (test_thread_flag(TIF_32BIT))
7126+ addr &= 0xFFFFFFFFUL;
7127+
7128+ err = get_user(save, (unsigned int *)addr);
7129+ err |= get_user(call, (unsigned int *)(addr+4));
7130+ err |= get_user(nop, (unsigned int *)(addr+8));
7131+ if (err)
7132+ break;
7133+
7134+#ifdef CONFIG_PAX_DLRESOLVE
7135+ if (save == 0x9DE3BFA8U &&
7136+ (call & 0xC0000000U) == 0x40000000U &&
7137+ nop == 0x01000000U)
7138+ {
7139+ struct vm_area_struct *vma;
7140+ unsigned long call_dl_resolve;
7141+
7142+ down_read(&current->mm->mmap_sem);
7143+ call_dl_resolve = current->mm->call_dl_resolve;
7144+ up_read(&current->mm->mmap_sem);
7145+ if (likely(call_dl_resolve))
7146+ goto emulate;
7147+
7148+ vma = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
7149+
7150+ down_write(&current->mm->mmap_sem);
7151+ if (current->mm->call_dl_resolve) {
7152+ call_dl_resolve = current->mm->call_dl_resolve;
7153+ up_write(&current->mm->mmap_sem);
7154+ if (vma)
7155+ kmem_cache_free(vm_area_cachep, vma);
7156+ goto emulate;
7157+ }
7158+
7159+ call_dl_resolve = get_unmapped_area(NULL, 0UL, PAGE_SIZE, 0UL, MAP_PRIVATE);
7160+ if (!vma || (call_dl_resolve & ~PAGE_MASK)) {
7161+ up_write(&current->mm->mmap_sem);
7162+ if (vma)
7163+ kmem_cache_free(vm_area_cachep, vma);
7164+ return 1;
7165+ }
7166+
7167+ if (pax_insert_vma(vma, call_dl_resolve)) {
7168+ up_write(&current->mm->mmap_sem);
7169+ kmem_cache_free(vm_area_cachep, vma);
7170+ return 1;
7171+ }
7172+
7173+ current->mm->call_dl_resolve = call_dl_resolve;
7174+ up_write(&current->mm->mmap_sem);
7175+
7176+emulate:
7177+ regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
7178+ regs->tpc = call_dl_resolve;
7179+ regs->tnpc = addr+4;
7180+ return 3;
7181+ }
7182+#endif
7183+
7184+ /* PaX: glibc 2.4+ generates sethi/jmpl instead of save/call */
7185+ if ((save & 0xFFC00000U) == 0x05000000U &&
7186+ (call & 0xFFFFE000U) == 0x85C0A000U &&
7187+ nop == 0x01000000U)
7188+ {
7189+ regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
7190+ regs->u_regs[UREG_G2] = addr + 4;
7191+ addr = (save & 0x003FFFFFU) << 10;
7192+ addr += (((call | 0xFFFFFFFFFFFFE000UL) ^ 0x00001000UL) + 0x00001000UL);
7193+
7194+ if (test_thread_flag(TIF_32BIT))
7195+ addr &= 0xFFFFFFFFUL;
7196+
7197+ regs->tpc = addr;
7198+ regs->tnpc = addr+4;
7199+ return 3;
7200+ }
7201+
7202+ /* PaX: 64-bit PLT stub */
7203+ err = get_user(sethi1, (unsigned int *)addr);
7204+ err |= get_user(sethi2, (unsigned int *)(addr+4));
7205+ err |= get_user(or1, (unsigned int *)(addr+8));
7206+ err |= get_user(or2, (unsigned int *)(addr+12));
7207+ err |= get_user(sllx, (unsigned int *)(addr+16));
7208+ err |= get_user(add, (unsigned int *)(addr+20));
7209+ err |= get_user(jmpl, (unsigned int *)(addr+24));
7210+ err |= get_user(nop, (unsigned int *)(addr+28));
7211+ if (err)
7212+ break;
7213+
7214+ if ((sethi1 & 0xFFC00000U) == 0x09000000U &&
7215+ (sethi2 & 0xFFC00000U) == 0x0B000000U &&
7216+ (or1 & 0xFFFFE000U) == 0x88112000U &&
7217+ (or2 & 0xFFFFE000U) == 0x8A116000U &&
7218+ sllx == 0x89293020U &&
7219+ add == 0x8A010005U &&
7220+ jmpl == 0x89C14000U &&
7221+ nop == 0x01000000U)
7222+ {
7223+ regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
7224+ regs->u_regs[UREG_G4] = ((sethi1 & 0x003FFFFFU) << 10) | (or1 & 0x000003FFU);
7225+ regs->u_regs[UREG_G4] <<= 32;
7226+ regs->u_regs[UREG_G5] = ((sethi2 & 0x003FFFFFU) << 10) | (or2 & 0x000003FFU);
7227+ regs->u_regs[UREG_G5] += regs->u_regs[UREG_G4];
7228+ regs->u_regs[UREG_G4] = addr + 24;
7229+ addr = regs->u_regs[UREG_G5];
7230+ regs->tpc = addr;
7231+ regs->tnpc = addr+4;
7232+ return 3;
7233+ }
7234+ }
7235+ } while (0);
7236+
7237+#ifdef CONFIG_PAX_DLRESOLVE
7238+ do { /* PaX: unpatched PLT emulation step 2 */
7239+ unsigned int save, call, nop;
7240+
7241+ err = get_user(save, (unsigned int *)(regs->tpc-4));
7242+ err |= get_user(call, (unsigned int *)regs->tpc);
7243+ err |= get_user(nop, (unsigned int *)(regs->tpc+4));
7244+ if (err)
7245+ break;
7246+
7247+ if (save == 0x9DE3BFA8U &&
7248+ (call & 0xC0000000U) == 0x40000000U &&
7249+ nop == 0x01000000U)
7250+ {
7251+ unsigned long dl_resolve = regs->tpc + ((((call | 0xFFFFFFFFC0000000UL) ^ 0x20000000UL) + 0x20000000UL) << 2);
7252+
7253+ if (test_thread_flag(TIF_32BIT))
7254+ dl_resolve &= 0xFFFFFFFFUL;
7255+
7256+ regs->u_regs[UREG_RETPC] = regs->tpc;
7257+ regs->tpc = dl_resolve;
7258+ regs->tnpc = dl_resolve+4;
7259+ return 3;
7260+ }
7261+ } while (0);
7262+#endif
7263+
7264+ do { /* PaX: patched PLT emulation #7, must be AFTER the unpatched PLT emulation */
7265+ unsigned int sethi, ba, nop;
7266+
7267+ err = get_user(sethi, (unsigned int *)regs->tpc);
7268+ err |= get_user(ba, (unsigned int *)(regs->tpc+4));
7269+ err |= get_user(nop, (unsigned int *)(regs->tpc+8));
7270+
7271+ if (err)
7272+ break;
7273+
7274+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
7275+ (ba & 0xFFF00000U) == 0x30600000U &&
7276+ nop == 0x01000000U)
7277+ {
7278+ unsigned long addr;
7279+
7280+ addr = (sethi & 0x003FFFFFU) << 10;
7281+ regs->u_regs[UREG_G1] = addr;
7282+ addr = regs->tpc + ((((ba | 0xFFFFFFFFFFF80000UL) ^ 0x00040000UL) + 0x00040000UL) << 2);
7283+
7284+ if (test_thread_flag(TIF_32BIT))
7285+ addr &= 0xFFFFFFFFUL;
7286+
7287+ regs->tpc = addr;
7288+ regs->tnpc = addr+4;
7289+ return 2;
7290+ }
7291+ } while (0);
7292+
7293+#endif
7294+
7295+ return 1;
7296+}
7297+
7298+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
7299+{
7300+ unsigned long i;
7301+
7302+ printk(KERN_ERR "PAX: bytes at PC: ");
7303+ for (i = 0; i < 8; i++) {
7304+ unsigned int c;
7305+ if (get_user(c, (unsigned int *)pc+i))
7306+ printk(KERN_CONT "???????? ");
7307+ else
7308+ printk(KERN_CONT "%08x ", c);
7309+ }
7310+ printk("\n");
7311+}
7312+#endif
7313+
7314 asmlinkage void __kprobes do_sparc64_fault(struct pt_regs *regs)
7315 {
7316 struct mm_struct *mm = current->mm;
7317@@ -343,6 +806,29 @@ retry:
7318 if (!vma)
7319 goto bad_area;
7320
7321+#ifdef CONFIG_PAX_PAGEEXEC
7322+ /* PaX: detect ITLB misses on non-exec pages */
7323+ if ((mm->pax_flags & MF_PAX_PAGEEXEC) && vma->vm_start <= address &&
7324+ !(vma->vm_flags & VM_EXEC) && (fault_code & FAULT_CODE_ITLB))
7325+ {
7326+ if (address != regs->tpc)
7327+ goto good_area;
7328+
7329+ up_read(&mm->mmap_sem);
7330+ switch (pax_handle_fetch_fault(regs)) {
7331+
7332+#ifdef CONFIG_PAX_EMUPLT
7333+ case 2:
7334+ case 3:
7335+ return;
7336+#endif
7337+
7338+ }
7339+ pax_report_fault(regs, (void *)regs->tpc, (void *)(regs->u_regs[UREG_FP] + STACK_BIAS));
7340+ do_group_exit(SIGKILL);
7341+ }
7342+#endif
7343+
7344 /* Pure DTLB misses do not tell us whether the fault causing
7345 * load/store/atomic was a write or not, it only says that there
7346 * was no match. So in such a case we (carefully) read the
7347diff --git a/arch/sparc/mm/hugetlbpage.c b/arch/sparc/mm/hugetlbpage.c
7348index 07e1453..0a7d9e9 100644
7349--- a/arch/sparc/mm/hugetlbpage.c
7350+++ b/arch/sparc/mm/hugetlbpage.c
7351@@ -67,7 +67,7 @@ full_search:
7352 }
7353 return -ENOMEM;
7354 }
7355- if (likely(!vma || addr + len <= vma->vm_start)) {
7356+ if (likely(check_heap_stack_gap(vma, addr, len))) {
7357 /*
7358 * Remember the place where we stopped the search:
7359 */
7360@@ -106,7 +106,7 @@ hugetlb_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
7361 /* make sure it can fit in the remaining address space */
7362 if (likely(addr > len)) {
7363 vma = find_vma(mm, addr-len);
7364- if (!vma || addr <= vma->vm_start) {
7365+ if (check_heap_stack_gap(vma, addr - len, len)) {
7366 /* remember the address as a hint for next time */
7367 return (mm->free_area_cache = addr-len);
7368 }
7369@@ -115,16 +115,17 @@ hugetlb_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
7370 if (unlikely(mm->mmap_base < len))
7371 goto bottomup;
7372
7373- addr = (mm->mmap_base-len) & HPAGE_MASK;
7374+ addr = mm->mmap_base - len;
7375
7376 do {
7377+ addr &= HPAGE_MASK;
7378 /*
7379 * Lookup failure means no vma is above this address,
7380 * else if new region fits below vma->vm_start,
7381 * return with success:
7382 */
7383 vma = find_vma(mm, addr);
7384- if (likely(!vma || addr+len <= vma->vm_start)) {
7385+ if (likely(check_heap_stack_gap(vma, addr, len))) {
7386 /* remember the address as a hint for next time */
7387 return (mm->free_area_cache = addr);
7388 }
7389@@ -134,8 +135,8 @@ hugetlb_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
7390 mm->cached_hole_size = vma->vm_start - addr;
7391
7392 /* try just below the current vma->vm_start */
7393- addr = (vma->vm_start-len) & HPAGE_MASK;
7394- } while (likely(len < vma->vm_start));
7395+ addr = skip_heap_stack_gap(vma, len);
7396+ } while (!IS_ERR_VALUE(addr));
7397
7398 bottomup:
7399 /*
7400@@ -181,8 +182,7 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
7401 if (addr) {
7402 addr = ALIGN(addr, HPAGE_SIZE);
7403 vma = find_vma(mm, addr);
7404- if (task_size - len >= addr &&
7405- (!vma || addr + len <= vma->vm_start))
7406+ if (task_size - len >= addr && check_heap_stack_gap(vma, addr, len))
7407 return addr;
7408 }
7409 if (mm->get_unmapped_area == arch_get_unmapped_area)
7410diff --git a/arch/tile/include/asm/atomic_64.h b/arch/tile/include/asm/atomic_64.h
7411index f4500c6..889656c 100644
7412--- a/arch/tile/include/asm/atomic_64.h
7413+++ b/arch/tile/include/asm/atomic_64.h
7414@@ -143,6 +143,16 @@ static inline long atomic64_add_unless(atomic64_t *v, long a, long u)
7415
7416 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
7417
7418+#define atomic64_read_unchecked(v) atomic64_read(v)
7419+#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
7420+#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
7421+#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
7422+#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
7423+#define atomic64_inc_unchecked(v) atomic64_inc(v)
7424+#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
7425+#define atomic64_dec_unchecked(v) atomic64_dec(v)
7426+#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
7427+
7428 /* Atomic dec and inc don't implement barrier, so provide them if needed. */
7429 #define smp_mb__before_atomic_dec() smp_mb()
7430 #define smp_mb__after_atomic_dec() smp_mb()
7431diff --git a/arch/tile/include/asm/cache.h b/arch/tile/include/asm/cache.h
7432index a9a5299..0fce79e 100644
7433--- a/arch/tile/include/asm/cache.h
7434+++ b/arch/tile/include/asm/cache.h
7435@@ -15,11 +15,12 @@
7436 #ifndef _ASM_TILE_CACHE_H
7437 #define _ASM_TILE_CACHE_H
7438
7439+#include <linux/const.h>
7440 #include <arch/chip.h>
7441
7442 /* bytes per L1 data cache line */
7443 #define L1_CACHE_SHIFT CHIP_L1D_LOG_LINE_SIZE()
7444-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
7445+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
7446
7447 /* bytes per L2 cache line */
7448 #define L2_CACHE_SHIFT CHIP_L2_LOG_LINE_SIZE()
7449diff --git a/arch/tile/include/asm/uaccess.h b/arch/tile/include/asm/uaccess.h
7450index 9ab078a..d6635c2 100644
7451--- a/arch/tile/include/asm/uaccess.h
7452+++ b/arch/tile/include/asm/uaccess.h
7453@@ -403,9 +403,9 @@ static inline unsigned long __must_check copy_from_user(void *to,
7454 const void __user *from,
7455 unsigned long n)
7456 {
7457- int sz = __compiletime_object_size(to);
7458+ size_t sz = __compiletime_object_size(to);
7459
7460- if (likely(sz == -1 || sz >= n))
7461+ if (likely(sz == (size_t)-1 || sz >= n))
7462 n = _copy_from_user(to, from, n);
7463 else
7464 copy_from_user_overflow();
7465diff --git a/arch/um/Makefile b/arch/um/Makefile
7466index 0970910..9f65c40 100644
7467--- a/arch/um/Makefile
7468+++ b/arch/um/Makefile
7469@@ -62,6 +62,10 @@ USER_CFLAGS = $(patsubst $(KERNEL_DEFINES),,$(patsubst -D__KERNEL__,,\
7470 $(patsubst -I%,,$(KBUILD_CFLAGS)))) $(ARCH_INCLUDE) $(MODE_INCLUDE) \
7471 $(filter -I%,$(CFLAGS)) -D_FILE_OFFSET_BITS=64 -idirafter include
7472
7473+ifdef CONSTIFY_PLUGIN
7474+USER_CFLAGS += -fplugin-arg-constify_plugin-no-constify
7475+endif
7476+
7477 #This will adjust *FLAGS accordingly to the platform.
7478 include $(srctree)/$(ARCH_DIR)/Makefile-os-$(OS)
7479
7480diff --git a/arch/um/include/asm/cache.h b/arch/um/include/asm/cache.h
7481index 19e1bdd..3665b77 100644
7482--- a/arch/um/include/asm/cache.h
7483+++ b/arch/um/include/asm/cache.h
7484@@ -1,6 +1,7 @@
7485 #ifndef __UM_CACHE_H
7486 #define __UM_CACHE_H
7487
7488+#include <linux/const.h>
7489
7490 #if defined(CONFIG_UML_X86) && !defined(CONFIG_64BIT)
7491 # define L1_CACHE_SHIFT (CONFIG_X86_L1_CACHE_SHIFT)
7492@@ -12,6 +13,6 @@
7493 # define L1_CACHE_SHIFT 5
7494 #endif
7495
7496-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
7497+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
7498
7499 #endif
7500diff --git a/arch/um/include/asm/kmap_types.h b/arch/um/include/asm/kmap_types.h
7501index 2e0a6b1..a64d0f5 100644
7502--- a/arch/um/include/asm/kmap_types.h
7503+++ b/arch/um/include/asm/kmap_types.h
7504@@ -8,6 +8,6 @@
7505
7506 /* No more #include "asm/arch/kmap_types.h" ! */
7507
7508-#define KM_TYPE_NR 14
7509+#define KM_TYPE_NR 15
7510
7511 #endif
7512diff --git a/arch/um/include/asm/page.h b/arch/um/include/asm/page.h
7513index 7cfc3ce..cbd1a58 100644
7514--- a/arch/um/include/asm/page.h
7515+++ b/arch/um/include/asm/page.h
7516@@ -14,6 +14,9 @@
7517 #define PAGE_SIZE (_AC(1, UL) << PAGE_SHIFT)
7518 #define PAGE_MASK (~(PAGE_SIZE-1))
7519
7520+#define ktla_ktva(addr) (addr)
7521+#define ktva_ktla(addr) (addr)
7522+
7523 #ifndef __ASSEMBLY__
7524
7525 struct page;
7526diff --git a/arch/um/include/asm/pgtable-3level.h b/arch/um/include/asm/pgtable-3level.h
7527index 0032f92..cd151e0 100644
7528--- a/arch/um/include/asm/pgtable-3level.h
7529+++ b/arch/um/include/asm/pgtable-3level.h
7530@@ -58,6 +58,7 @@
7531 #define pud_present(x) (pud_val(x) & _PAGE_PRESENT)
7532 #define pud_populate(mm, pud, pmd) \
7533 set_pud(pud, __pud(_PAGE_TABLE + __pa(pmd)))
7534+#define pud_populate_kernel(mm, pud, pmd) pud_populate((mm), (pud), (pmd))
7535
7536 #ifdef CONFIG_64BIT
7537 #define set_pud(pudptr, pudval) set_64bit((u64 *) (pudptr), pud_val(pudval))
7538diff --git a/arch/um/kernel/process.c b/arch/um/kernel/process.c
7539index c5f5afa..6abce4b 100644
7540--- a/arch/um/kernel/process.c
7541+++ b/arch/um/kernel/process.c
7542@@ -402,22 +402,6 @@ int singlestepping(void * t)
7543 return 2;
7544 }
7545
7546-/*
7547- * Only x86 and x86_64 have an arch_align_stack().
7548- * All other arches have "#define arch_align_stack(x) (x)"
7549- * in their asm/system.h
7550- * As this is included in UML from asm-um/system-generic.h,
7551- * we can use it to behave as the subarch does.
7552- */
7553-#ifndef arch_align_stack
7554-unsigned long arch_align_stack(unsigned long sp)
7555-{
7556- if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
7557- sp -= get_random_int() % 8192;
7558- return sp & ~0xf;
7559-}
7560-#endif
7561-
7562 unsigned long get_wchan(struct task_struct *p)
7563 {
7564 unsigned long stack_page, sp, ip;
7565diff --git a/arch/unicore32/include/asm/cache.h b/arch/unicore32/include/asm/cache.h
7566index ad8f795..2c7eec6 100644
7567--- a/arch/unicore32/include/asm/cache.h
7568+++ b/arch/unicore32/include/asm/cache.h
7569@@ -12,8 +12,10 @@
7570 #ifndef __UNICORE_CACHE_H__
7571 #define __UNICORE_CACHE_H__
7572
7573-#define L1_CACHE_SHIFT (5)
7574-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
7575+#include <linux/const.h>
7576+
7577+#define L1_CACHE_SHIFT 5
7578+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
7579
7580 /*
7581 * Memory returned by kmalloc() may be used for DMA, so we must make
7582diff --git a/arch/x86/Kconfig b/arch/x86/Kconfig
7583index 50a1d1f..c26369f 100644
7584--- a/arch/x86/Kconfig
7585+++ b/arch/x86/Kconfig
7586@@ -220,7 +220,7 @@ config X86_HT
7587
7588 config X86_32_LAZY_GS
7589 def_bool y
7590- depends on X86_32 && !CC_STACKPROTECTOR
7591+ depends on X86_32 && !CC_STACKPROTECTOR && !PAX_MEMORY_UDEREF
7592
7593 config ARCH_HWEIGHT_CFLAGS
7594 string
7595@@ -1049,7 +1049,7 @@ choice
7596
7597 config NOHIGHMEM
7598 bool "off"
7599- depends on !X86_NUMAQ
7600+ depends on !X86_NUMAQ && !(PAX_PAGEEXEC && PAX_ENABLE_PAE)
7601 ---help---
7602 Linux can use up to 64 Gigabytes of physical memory on x86 systems.
7603 However, the address space of 32-bit x86 processors is only 4
7604@@ -1086,7 +1086,7 @@ config NOHIGHMEM
7605
7606 config HIGHMEM4G
7607 bool "4GB"
7608- depends on !X86_NUMAQ
7609+ depends on !X86_NUMAQ && !(PAX_PAGEEXEC && PAX_ENABLE_PAE)
7610 ---help---
7611 Select this if you have a 32-bit processor and between 1 and 4
7612 gigabytes of physical RAM.
7613@@ -1140,7 +1140,7 @@ config PAGE_OFFSET
7614 hex
7615 default 0xB0000000 if VMSPLIT_3G_OPT
7616 default 0x80000000 if VMSPLIT_2G
7617- default 0x78000000 if VMSPLIT_2G_OPT
7618+ default 0x70000000 if VMSPLIT_2G_OPT
7619 default 0x40000000 if VMSPLIT_1G
7620 default 0xC0000000
7621 depends on X86_32
7622@@ -1528,6 +1528,7 @@ config SECCOMP
7623
7624 config CC_STACKPROTECTOR
7625 bool "Enable -fstack-protector buffer overflow detection"
7626+ depends on X86_64 || !PAX_MEMORY_UDEREF
7627 ---help---
7628 This option turns on the -fstack-protector GCC feature. This
7629 feature puts, at the beginning of functions, a canary value on
7630@@ -1585,6 +1586,7 @@ config KEXEC_JUMP
7631 config PHYSICAL_START
7632 hex "Physical address where the kernel is loaded" if (EXPERT || CRASH_DUMP)
7633 default "0x1000000"
7634+ range 0x400000 0x40000000
7635 ---help---
7636 This gives the physical address where the kernel is loaded.
7637
7638@@ -1648,6 +1650,7 @@ config X86_NEED_RELOCS
7639 config PHYSICAL_ALIGN
7640 hex "Alignment value to which kernel should be aligned" if X86_32
7641 default "0x1000000"
7642+ range 0x400000 0x1000000 if PAX_KERNEXEC
7643 range 0x2000 0x1000000
7644 ---help---
7645 This value puts the alignment restrictions on physical address
7646@@ -1679,9 +1682,10 @@ config HOTPLUG_CPU
7647 Say N if you want to disable CPU hotplug.
7648
7649 config COMPAT_VDSO
7650- def_bool y
7651+ def_bool n
7652 prompt "Compat VDSO support"
7653 depends on X86_32 || IA32_EMULATION
7654+ depends on !PAX_NOEXEC && !PAX_MEMORY_UDEREF
7655 ---help---
7656 Map the 32-bit VDSO to the predictable old-style address too.
7657
7658diff --git a/arch/x86/Kconfig.cpu b/arch/x86/Kconfig.cpu
7659index 706e12e..62e4feb 100644
7660--- a/arch/x86/Kconfig.cpu
7661+++ b/arch/x86/Kconfig.cpu
7662@@ -334,7 +334,7 @@ config X86_PPRO_FENCE
7663
7664 config X86_F00F_BUG
7665 def_bool y
7666- depends on M586MMX || M586TSC || M586 || M486 || M386
7667+ depends on (M586MMX || M586TSC || M586 || M486 || M386) && !PAX_KERNEXEC
7668
7669 config X86_INVD_BUG
7670 def_bool y
7671@@ -358,7 +358,7 @@ config X86_POPAD_OK
7672
7673 config X86_ALIGNMENT_16
7674 def_bool y
7675- depends on MWINCHIP3D || MWINCHIPC6 || MCYRIXIII || MELAN || MK6 || M586MMX || M586TSC || M586 || M486 || MVIAC3_2 || MGEODEGX1
7676+ depends on MWINCHIP3D || MWINCHIPC6 || MCYRIXIII || X86_ELAN || MK8 || MK7 || MK6 || MCORE2 || MPENTIUM4 || MPENTIUMIII || MPENTIUMII || M686 || M586MMX || M586TSC || M586 || M486 || MVIAC3_2 || MGEODEGX1
7677
7678 config X86_INTEL_USERCOPY
7679 def_bool y
7680@@ -404,7 +404,7 @@ config X86_CMPXCHG64
7681 # generates cmov.
7682 config X86_CMOV
7683 def_bool y
7684- depends on (MK8 || MK7 || MCORE2 || MPENTIUM4 || MPENTIUMM || MPENTIUMIII || MPENTIUMII || M686 || MVIAC3_2 || MVIAC7 || MCRUSOE || MEFFICEON || X86_64 || MATOM || MGEODE_LX)
7685+ depends on (MK8 || MK7 || MCORE2 || MPSC || MPENTIUM4 || MPENTIUMM || MPENTIUMIII || MPENTIUMII || M686 || MVIAC3_2 || MVIAC7 || MCRUSOE || MEFFICEON || X86_64 || MATOM || MGEODE_LX)
7686
7687 config X86_MINIMUM_CPU_FAMILY
7688 int
7689diff --git a/arch/x86/Kconfig.debug b/arch/x86/Kconfig.debug
7690index b322f12..652d0d9 100644
7691--- a/arch/x86/Kconfig.debug
7692+++ b/arch/x86/Kconfig.debug
7693@@ -84,7 +84,7 @@ config X86_PTDUMP
7694 config DEBUG_RODATA
7695 bool "Write protect kernel read-only data structures"
7696 default y
7697- depends on DEBUG_KERNEL
7698+ depends on DEBUG_KERNEL && BROKEN
7699 ---help---
7700 Mark the kernel read-only data as write-protected in the pagetables,
7701 in order to catch accidental (and incorrect) writes to such const
7702@@ -102,7 +102,7 @@ config DEBUG_RODATA_TEST
7703
7704 config DEBUG_SET_MODULE_RONX
7705 bool "Set loadable kernel module data as NX and text as RO"
7706- depends on MODULES
7707+ depends on MODULES && BROKEN
7708 ---help---
7709 This option helps catch unintended modifications to loadable
7710 kernel module's text and read-only data. It also prevents execution
7711@@ -294,7 +294,7 @@ config OPTIMIZE_INLINING
7712
7713 config DEBUG_STRICT_USER_COPY_CHECKS
7714 bool "Strict copy size checks"
7715- depends on DEBUG_KERNEL && !TRACE_BRANCH_PROFILING
7716+ depends on DEBUG_KERNEL && !TRACE_BRANCH_PROFILING && !PAX_SIZE_OVERFLOW
7717 ---help---
7718 Enabling this option turns a certain set of sanity checks for user
7719 copy operations into compile time failures.
7720diff --git a/arch/x86/Makefile b/arch/x86/Makefile
7721index 05afcca..b6ecb51 100644
7722--- a/arch/x86/Makefile
7723+++ b/arch/x86/Makefile
7724@@ -50,6 +50,7 @@ else
7725 UTS_MACHINE := x86_64
7726 CHECKFLAGS += -D__x86_64__ -m64
7727
7728+ biarch := $(call cc-option,-m64)
7729 KBUILD_AFLAGS += -m64
7730 KBUILD_CFLAGS += -m64
7731
7732@@ -229,3 +230,12 @@ define archhelp
7733 echo ' FDARGS="..." arguments for the booted kernel'
7734 echo ' FDINITRD=file initrd for the booted kernel'
7735 endef
7736+
7737+define OLD_LD
7738+
7739+*** ${VERSION}.${PATCHLEVEL} PaX kernels no longer build correctly with old versions of binutils.
7740+*** Please upgrade your binutils to 2.18 or newer
7741+endef
7742+
7743+archprepare:
7744+ $(if $(LDFLAGS_BUILD_ID),,$(error $(OLD_LD)))
7745diff --git a/arch/x86/boot/Makefile b/arch/x86/boot/Makefile
7746index f7535be..37db2d1 100644
7747--- a/arch/x86/boot/Makefile
7748+++ b/arch/x86/boot/Makefile
7749@@ -64,6 +64,9 @@ KBUILD_CFLAGS := $(LINUXINCLUDE) -g -Os -D_SETUP -D__KERNEL__ \
7750 $(call cc-option, -fno-stack-protector) \
7751 $(call cc-option, -mpreferred-stack-boundary=2)
7752 KBUILD_CFLAGS += $(call cc-option, -m32)
7753+ifdef CONSTIFY_PLUGIN
7754+KBUILD_CFLAGS += -fplugin-arg-constify_plugin-no-constify
7755+endif
7756 KBUILD_AFLAGS := $(KBUILD_CFLAGS) -D__ASSEMBLY__
7757 GCOV_PROFILE := n
7758
7759diff --git a/arch/x86/boot/bitops.h b/arch/x86/boot/bitops.h
7760index 878e4b9..20537ab 100644
7761--- a/arch/x86/boot/bitops.h
7762+++ b/arch/x86/boot/bitops.h
7763@@ -26,7 +26,7 @@ static inline int variable_test_bit(int nr, const void *addr)
7764 u8 v;
7765 const u32 *p = (const u32 *)addr;
7766
7767- asm("btl %2,%1; setc %0" : "=qm" (v) : "m" (*p), "Ir" (nr));
7768+ asm volatile("btl %2,%1; setc %0" : "=qm" (v) : "m" (*p), "Ir" (nr));
7769 return v;
7770 }
7771
7772@@ -37,7 +37,7 @@ static inline int variable_test_bit(int nr, const void *addr)
7773
7774 static inline void set_bit(int nr, void *addr)
7775 {
7776- asm("btsl %1,%0" : "+m" (*(u32 *)addr) : "Ir" (nr));
7777+ asm volatile("btsl %1,%0" : "+m" (*(u32 *)addr) : "Ir" (nr));
7778 }
7779
7780 #endif /* BOOT_BITOPS_H */
7781diff --git a/arch/x86/boot/boot.h b/arch/x86/boot/boot.h
7782index 18997e5..83d9c67 100644
7783--- a/arch/x86/boot/boot.h
7784+++ b/arch/x86/boot/boot.h
7785@@ -85,7 +85,7 @@ static inline void io_delay(void)
7786 static inline u16 ds(void)
7787 {
7788 u16 seg;
7789- asm("movw %%ds,%0" : "=rm" (seg));
7790+ asm volatile("movw %%ds,%0" : "=rm" (seg));
7791 return seg;
7792 }
7793
7794@@ -181,7 +181,7 @@ static inline void wrgs32(u32 v, addr_t addr)
7795 static inline int memcmp(const void *s1, const void *s2, size_t len)
7796 {
7797 u8 diff;
7798- asm("repe; cmpsb; setnz %0"
7799+ asm volatile("repe; cmpsb; setnz %0"
7800 : "=qm" (diff), "+D" (s1), "+S" (s2), "+c" (len));
7801 return diff;
7802 }
7803diff --git a/arch/x86/boot/compressed/Makefile b/arch/x86/boot/compressed/Makefile
7804index 8a84501..b2d165f 100644
7805--- a/arch/x86/boot/compressed/Makefile
7806+++ b/arch/x86/boot/compressed/Makefile
7807@@ -14,6 +14,9 @@ cflags-$(CONFIG_X86_64) := -mcmodel=small
7808 KBUILD_CFLAGS += $(cflags-y)
7809 KBUILD_CFLAGS += $(call cc-option,-ffreestanding)
7810 KBUILD_CFLAGS += $(call cc-option,-fno-stack-protector)
7811+ifdef CONSTIFY_PLUGIN
7812+KBUILD_CFLAGS += -fplugin-arg-constify_plugin-no-constify
7813+endif
7814
7815 KBUILD_AFLAGS := $(KBUILD_CFLAGS) -D__ASSEMBLY__
7816 GCOV_PROFILE := n
7817diff --git a/arch/x86/boot/compressed/eboot.c b/arch/x86/boot/compressed/eboot.c
7818index b3e0227..f2c02d5 100644
7819--- a/arch/x86/boot/compressed/eboot.c
7820+++ b/arch/x86/boot/compressed/eboot.c
7821@@ -142,7 +142,6 @@ again:
7822 *addr = max_addr;
7823 }
7824
7825-free_pool:
7826 efi_call_phys1(sys_table->boottime->free_pool, map);
7827
7828 fail:
7829@@ -206,7 +205,6 @@ static efi_status_t low_alloc(unsigned long size, unsigned long align,
7830 if (i == map_size / desc_size)
7831 status = EFI_NOT_FOUND;
7832
7833-free_pool:
7834 efi_call_phys1(sys_table->boottime->free_pool, map);
7835 fail:
7836 return status;
7837diff --git a/arch/x86/boot/compressed/head_32.S b/arch/x86/boot/compressed/head_32.S
7838index aa4aaf1..6656f2f 100644
7839--- a/arch/x86/boot/compressed/head_32.S
7840+++ b/arch/x86/boot/compressed/head_32.S
7841@@ -116,7 +116,7 @@ preferred_addr:
7842 notl %eax
7843 andl %eax, %ebx
7844 #else
7845- movl $LOAD_PHYSICAL_ADDR, %ebx
7846+ movl $____LOAD_PHYSICAL_ADDR, %ebx
7847 #endif
7848
7849 /* Target address to relocate to for decompression */
7850@@ -202,7 +202,7 @@ relocated:
7851 * and where it was actually loaded.
7852 */
7853 movl %ebp, %ebx
7854- subl $LOAD_PHYSICAL_ADDR, %ebx
7855+ subl $____LOAD_PHYSICAL_ADDR, %ebx
7856 jz 2f /* Nothing to be done if loaded at compiled addr. */
7857 /*
7858 * Process relocations.
7859@@ -210,8 +210,7 @@ relocated:
7860
7861 1: subl $4, %edi
7862 movl (%edi), %ecx
7863- testl %ecx, %ecx
7864- jz 2f
7865+ jecxz 2f
7866 addl %ebx, -__PAGE_OFFSET(%ebx, %ecx)
7867 jmp 1b
7868 2:
7869diff --git a/arch/x86/boot/compressed/head_64.S b/arch/x86/boot/compressed/head_64.S
7870index 2c4b171..e1fa5b1 100644
7871--- a/arch/x86/boot/compressed/head_64.S
7872+++ b/arch/x86/boot/compressed/head_64.S
7873@@ -91,7 +91,7 @@ ENTRY(startup_32)
7874 notl %eax
7875 andl %eax, %ebx
7876 #else
7877- movl $LOAD_PHYSICAL_ADDR, %ebx
7878+ movl $____LOAD_PHYSICAL_ADDR, %ebx
7879 #endif
7880
7881 /* Target address to relocate to for decompression */
7882@@ -273,7 +273,7 @@ preferred_addr:
7883 notq %rax
7884 andq %rax, %rbp
7885 #else
7886- movq $LOAD_PHYSICAL_ADDR, %rbp
7887+ movq $____LOAD_PHYSICAL_ADDR, %rbp
7888 #endif
7889
7890 /* Target address to relocate to for decompression */
7891diff --git a/arch/x86/boot/compressed/misc.c b/arch/x86/boot/compressed/misc.c
7892index 88f7ff6..ed695dd 100644
7893--- a/arch/x86/boot/compressed/misc.c
7894+++ b/arch/x86/boot/compressed/misc.c
7895@@ -303,7 +303,7 @@ static void parse_elf(void *output)
7896 case PT_LOAD:
7897 #ifdef CONFIG_RELOCATABLE
7898 dest = output;
7899- dest += (phdr->p_paddr - LOAD_PHYSICAL_ADDR);
7900+ dest += (phdr->p_paddr - ____LOAD_PHYSICAL_ADDR);
7901 #else
7902 dest = (void *)(phdr->p_paddr);
7903 #endif
7904@@ -352,7 +352,7 @@ asmlinkage void decompress_kernel(void *rmode, memptr heap,
7905 error("Destination address too large");
7906 #endif
7907 #ifndef CONFIG_RELOCATABLE
7908- if ((unsigned long)output != LOAD_PHYSICAL_ADDR)
7909+ if ((unsigned long)output != ____LOAD_PHYSICAL_ADDR)
7910 error("Wrong destination address");
7911 #endif
7912
7913diff --git a/arch/x86/boot/cpucheck.c b/arch/x86/boot/cpucheck.c
7914index 4d3ff03..e4972ff 100644
7915--- a/arch/x86/boot/cpucheck.c
7916+++ b/arch/x86/boot/cpucheck.c
7917@@ -74,7 +74,7 @@ static int has_fpu(void)
7918 u16 fcw = -1, fsw = -1;
7919 u32 cr0;
7920
7921- asm("movl %%cr0,%0" : "=r" (cr0));
7922+ asm volatile("movl %%cr0,%0" : "=r" (cr0));
7923 if (cr0 & (X86_CR0_EM|X86_CR0_TS)) {
7924 cr0 &= ~(X86_CR0_EM|X86_CR0_TS);
7925 asm volatile("movl %0,%%cr0" : : "r" (cr0));
7926@@ -90,7 +90,7 @@ static int has_eflag(u32 mask)
7927 {
7928 u32 f0, f1;
7929
7930- asm("pushfl ; "
7931+ asm volatile("pushfl ; "
7932 "pushfl ; "
7933 "popl %0 ; "
7934 "movl %0,%1 ; "
7935@@ -115,7 +115,7 @@ static void get_flags(void)
7936 set_bit(X86_FEATURE_FPU, cpu.flags);
7937
7938 if (has_eflag(X86_EFLAGS_ID)) {
7939- asm("cpuid"
7940+ asm volatile("cpuid"
7941 : "=a" (max_intel_level),
7942 "=b" (cpu_vendor[0]),
7943 "=d" (cpu_vendor[1]),
7944@@ -124,7 +124,7 @@ static void get_flags(void)
7945
7946 if (max_intel_level >= 0x00000001 &&
7947 max_intel_level <= 0x0000ffff) {
7948- asm("cpuid"
7949+ asm volatile("cpuid"
7950 : "=a" (tfms),
7951 "=c" (cpu.flags[4]),
7952 "=d" (cpu.flags[0])
7953@@ -136,7 +136,7 @@ static void get_flags(void)
7954 cpu.model += ((tfms >> 16) & 0xf) << 4;
7955 }
7956
7957- asm("cpuid"
7958+ asm volatile("cpuid"
7959 : "=a" (max_amd_level)
7960 : "a" (0x80000000)
7961 : "ebx", "ecx", "edx");
7962@@ -144,7 +144,7 @@ static void get_flags(void)
7963 if (max_amd_level >= 0x80000001 &&
7964 max_amd_level <= 0x8000ffff) {
7965 u32 eax = 0x80000001;
7966- asm("cpuid"
7967+ asm volatile("cpuid"
7968 : "+a" (eax),
7969 "=c" (cpu.flags[6]),
7970 "=d" (cpu.flags[1])
7971@@ -203,9 +203,9 @@ int check_cpu(int *cpu_level_ptr, int *req_level_ptr, u32 **err_flags_ptr)
7972 u32 ecx = MSR_K7_HWCR;
7973 u32 eax, edx;
7974
7975- asm("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
7976+ asm volatile("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
7977 eax &= ~(1 << 15);
7978- asm("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
7979+ asm volatile("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
7980
7981 get_flags(); /* Make sure it really did something */
7982 err = check_flags();
7983@@ -218,9 +218,9 @@ int check_cpu(int *cpu_level_ptr, int *req_level_ptr, u32 **err_flags_ptr)
7984 u32 ecx = MSR_VIA_FCR;
7985 u32 eax, edx;
7986
7987- asm("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
7988+ asm volatile("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
7989 eax |= (1<<1)|(1<<7);
7990- asm("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
7991+ asm volatile("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
7992
7993 set_bit(X86_FEATURE_CX8, cpu.flags);
7994 err = check_flags();
7995@@ -231,12 +231,12 @@ int check_cpu(int *cpu_level_ptr, int *req_level_ptr, u32 **err_flags_ptr)
7996 u32 eax, edx;
7997 u32 level = 1;
7998
7999- asm("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
8000- asm("wrmsr" : : "a" (~0), "d" (edx), "c" (ecx));
8001- asm("cpuid"
8002+ asm volatile("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
8003+ asm volatile("wrmsr" : : "a" (~0), "d" (edx), "c" (ecx));
8004+ asm volatile("cpuid"
8005 : "+a" (level), "=d" (cpu.flags[0])
8006 : : "ecx", "ebx");
8007- asm("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
8008+ asm volatile("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
8009
8010 err = check_flags();
8011 }
8012diff --git a/arch/x86/boot/header.S b/arch/x86/boot/header.S
8013index b4e15dd..8ac59ce 100644
8014--- a/arch/x86/boot/header.S
8015+++ b/arch/x86/boot/header.S
8016@@ -391,10 +391,14 @@ setup_data: .quad 0 # 64-bit physical pointer to
8017 # single linked list of
8018 # struct setup_data
8019
8020-pref_address: .quad LOAD_PHYSICAL_ADDR # preferred load addr
8021+pref_address: .quad ____LOAD_PHYSICAL_ADDR # preferred load addr
8022
8023 #define ZO_INIT_SIZE (ZO__end - ZO_startup_32 + ZO_z_extract_offset)
8024+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
8025+#define VO_INIT_SIZE (VO__end - VO__text - __PAGE_OFFSET - ____LOAD_PHYSICAL_ADDR)
8026+#else
8027 #define VO_INIT_SIZE (VO__end - VO__text)
8028+#endif
8029 #if ZO_INIT_SIZE > VO_INIT_SIZE
8030 #define INIT_SIZE ZO_INIT_SIZE
8031 #else
8032diff --git a/arch/x86/boot/memory.c b/arch/x86/boot/memory.c
8033index db75d07..8e6d0af 100644
8034--- a/arch/x86/boot/memory.c
8035+++ b/arch/x86/boot/memory.c
8036@@ -19,7 +19,7 @@
8037
8038 static int detect_memory_e820(void)
8039 {
8040- int count = 0;
8041+ unsigned int count = 0;
8042 struct biosregs ireg, oreg;
8043 struct e820entry *desc = boot_params.e820_map;
8044 static struct e820entry buf; /* static so it is zeroed */
8045diff --git a/arch/x86/boot/video-vesa.c b/arch/x86/boot/video-vesa.c
8046index 11e8c6e..fdbb1ed 100644
8047--- a/arch/x86/boot/video-vesa.c
8048+++ b/arch/x86/boot/video-vesa.c
8049@@ -200,6 +200,7 @@ static void vesa_store_pm_info(void)
8050
8051 boot_params.screen_info.vesapm_seg = oreg.es;
8052 boot_params.screen_info.vesapm_off = oreg.di;
8053+ boot_params.screen_info.vesapm_size = oreg.cx;
8054 }
8055
8056 /*
8057diff --git a/arch/x86/boot/video.c b/arch/x86/boot/video.c
8058index 43eda28..5ab5fdb 100644
8059--- a/arch/x86/boot/video.c
8060+++ b/arch/x86/boot/video.c
8061@@ -96,7 +96,7 @@ static void store_mode_params(void)
8062 static unsigned int get_entry(void)
8063 {
8064 char entry_buf[4];
8065- int i, len = 0;
8066+ unsigned int i, len = 0;
8067 int key;
8068 unsigned int v;
8069
8070diff --git a/arch/x86/crypto/aes-x86_64-asm_64.S b/arch/x86/crypto/aes-x86_64-asm_64.S
8071index 5b577d5..3c1fed4 100644
8072--- a/arch/x86/crypto/aes-x86_64-asm_64.S
8073+++ b/arch/x86/crypto/aes-x86_64-asm_64.S
8074@@ -8,6 +8,8 @@
8075 * including this sentence is retained in full.
8076 */
8077
8078+#include <asm/alternative-asm.h>
8079+
8080 .extern crypto_ft_tab
8081 .extern crypto_it_tab
8082 .extern crypto_fl_tab
8083@@ -71,6 +73,8 @@ FUNC: movq r1,r2; \
8084 je B192; \
8085 leaq 32(r9),r9;
8086
8087+#define ret pax_force_retaddr 0, 1; ret
8088+
8089 #define epilogue(r1,r2,r3,r4,r5,r6,r7,r8,r9) \
8090 movq r1,r2; \
8091 movq r3,r4; \
8092diff --git a/arch/x86/crypto/aesni-intel_asm.S b/arch/x86/crypto/aesni-intel_asm.S
8093index 3470624..201259d 100644
8094--- a/arch/x86/crypto/aesni-intel_asm.S
8095+++ b/arch/x86/crypto/aesni-intel_asm.S
8096@@ -31,6 +31,7 @@
8097
8098 #include <linux/linkage.h>
8099 #include <asm/inst.h>
8100+#include <asm/alternative-asm.h>
8101
8102 #ifdef __x86_64__
8103 .data
8104@@ -1436,7 +1437,9 @@ _return_T_done_decrypt:
8105 pop %r14
8106 pop %r13
8107 pop %r12
8108+ pax_force_retaddr 0, 1
8109 ret
8110+ENDPROC(aesni_gcm_dec)
8111
8112
8113 /*****************************************************************************
8114@@ -1699,7 +1702,9 @@ _return_T_done_encrypt:
8115 pop %r14
8116 pop %r13
8117 pop %r12
8118+ pax_force_retaddr 0, 1
8119 ret
8120+ENDPROC(aesni_gcm_enc)
8121
8122 #endif
8123
8124@@ -1714,6 +1719,7 @@ _key_expansion_256a:
8125 pxor %xmm1, %xmm0
8126 movaps %xmm0, (TKEYP)
8127 add $0x10, TKEYP
8128+ pax_force_retaddr_bts
8129 ret
8130
8131 .align 4
8132@@ -1738,6 +1744,7 @@ _key_expansion_192a:
8133 shufps $0b01001110, %xmm2, %xmm1
8134 movaps %xmm1, 0x10(TKEYP)
8135 add $0x20, TKEYP
8136+ pax_force_retaddr_bts
8137 ret
8138
8139 .align 4
8140@@ -1757,6 +1764,7 @@ _key_expansion_192b:
8141
8142 movaps %xmm0, (TKEYP)
8143 add $0x10, TKEYP
8144+ pax_force_retaddr_bts
8145 ret
8146
8147 .align 4
8148@@ -1769,6 +1777,7 @@ _key_expansion_256b:
8149 pxor %xmm1, %xmm2
8150 movaps %xmm2, (TKEYP)
8151 add $0x10, TKEYP
8152+ pax_force_retaddr_bts
8153 ret
8154
8155 /*
8156@@ -1881,7 +1890,9 @@ ENTRY(aesni_set_key)
8157 #ifndef __x86_64__
8158 popl KEYP
8159 #endif
8160+ pax_force_retaddr 0, 1
8161 ret
8162+ENDPROC(aesni_set_key)
8163
8164 /*
8165 * void aesni_enc(struct crypto_aes_ctx *ctx, u8 *dst, const u8 *src)
8166@@ -1902,7 +1913,9 @@ ENTRY(aesni_enc)
8167 popl KLEN
8168 popl KEYP
8169 #endif
8170+ pax_force_retaddr 0, 1
8171 ret
8172+ENDPROC(aesni_enc)
8173
8174 /*
8175 * _aesni_enc1: internal ABI
8176@@ -1959,6 +1972,7 @@ _aesni_enc1:
8177 AESENC KEY STATE
8178 movaps 0x70(TKEYP), KEY
8179 AESENCLAST KEY STATE
8180+ pax_force_retaddr_bts
8181 ret
8182
8183 /*
8184@@ -2067,6 +2081,7 @@ _aesni_enc4:
8185 AESENCLAST KEY STATE2
8186 AESENCLAST KEY STATE3
8187 AESENCLAST KEY STATE4
8188+ pax_force_retaddr_bts
8189 ret
8190
8191 /*
8192@@ -2089,7 +2104,9 @@ ENTRY(aesni_dec)
8193 popl KLEN
8194 popl KEYP
8195 #endif
8196+ pax_force_retaddr 0, 1
8197 ret
8198+ENDPROC(aesni_dec)
8199
8200 /*
8201 * _aesni_dec1: internal ABI
8202@@ -2146,6 +2163,7 @@ _aesni_dec1:
8203 AESDEC KEY STATE
8204 movaps 0x70(TKEYP), KEY
8205 AESDECLAST KEY STATE
8206+ pax_force_retaddr_bts
8207 ret
8208
8209 /*
8210@@ -2254,6 +2272,7 @@ _aesni_dec4:
8211 AESDECLAST KEY STATE2
8212 AESDECLAST KEY STATE3
8213 AESDECLAST KEY STATE4
8214+ pax_force_retaddr_bts
8215 ret
8216
8217 /*
8218@@ -2311,7 +2330,9 @@ ENTRY(aesni_ecb_enc)
8219 popl KEYP
8220 popl LEN
8221 #endif
8222+ pax_force_retaddr 0, 1
8223 ret
8224+ENDPROC(aesni_ecb_enc)
8225
8226 /*
8227 * void aesni_ecb_dec(struct crypto_aes_ctx *ctx, const u8 *dst, u8 *src,
8228@@ -2369,7 +2390,9 @@ ENTRY(aesni_ecb_dec)
8229 popl KEYP
8230 popl LEN
8231 #endif
8232+ pax_force_retaddr 0, 1
8233 ret
8234+ENDPROC(aesni_ecb_dec)
8235
8236 /*
8237 * void aesni_cbc_enc(struct crypto_aes_ctx *ctx, const u8 *dst, u8 *src,
8238@@ -2410,7 +2433,9 @@ ENTRY(aesni_cbc_enc)
8239 popl LEN
8240 popl IVP
8241 #endif
8242+ pax_force_retaddr 0, 1
8243 ret
8244+ENDPROC(aesni_cbc_enc)
8245
8246 /*
8247 * void aesni_cbc_dec(struct crypto_aes_ctx *ctx, const u8 *dst, u8 *src,
8248@@ -2500,7 +2525,9 @@ ENTRY(aesni_cbc_dec)
8249 popl LEN
8250 popl IVP
8251 #endif
8252+ pax_force_retaddr 0, 1
8253 ret
8254+ENDPROC(aesni_cbc_dec)
8255
8256 #ifdef __x86_64__
8257 .align 16
8258@@ -2526,6 +2553,7 @@ _aesni_inc_init:
8259 mov $1, TCTR_LOW
8260 MOVQ_R64_XMM TCTR_LOW INC
8261 MOVQ_R64_XMM CTR TCTR_LOW
8262+ pax_force_retaddr_bts
8263 ret
8264
8265 /*
8266@@ -2554,6 +2582,7 @@ _aesni_inc:
8267 .Linc_low:
8268 movaps CTR, IV
8269 PSHUFB_XMM BSWAP_MASK IV
8270+ pax_force_retaddr_bts
8271 ret
8272
8273 /*
8274@@ -2614,5 +2643,7 @@ ENTRY(aesni_ctr_enc)
8275 .Lctr_enc_ret:
8276 movups IV, (IVP)
8277 .Lctr_enc_just_ret:
8278+ pax_force_retaddr 0, 1
8279 ret
8280+ENDPROC(aesni_ctr_enc)
8281 #endif
8282diff --git a/arch/x86/crypto/blowfish-x86_64-asm_64.S b/arch/x86/crypto/blowfish-x86_64-asm_64.S
8283index 391d245..67f35c2 100644
8284--- a/arch/x86/crypto/blowfish-x86_64-asm_64.S
8285+++ b/arch/x86/crypto/blowfish-x86_64-asm_64.S
8286@@ -20,6 +20,8 @@
8287 *
8288 */
8289
8290+#include <asm/alternative-asm.h>
8291+
8292 .file "blowfish-x86_64-asm.S"
8293 .text
8294
8295@@ -151,9 +153,11 @@ __blowfish_enc_blk:
8296 jnz __enc_xor;
8297
8298 write_block();
8299+ pax_force_retaddr 0, 1
8300 ret;
8301 __enc_xor:
8302 xor_block();
8303+ pax_force_retaddr 0, 1
8304 ret;
8305
8306 .align 8
8307@@ -188,6 +192,7 @@ blowfish_dec_blk:
8308
8309 movq %r11, %rbp;
8310
8311+ pax_force_retaddr 0, 1
8312 ret;
8313
8314 /**********************************************************************
8315@@ -342,6 +347,7 @@ __blowfish_enc_blk_4way:
8316
8317 popq %rbx;
8318 popq %rbp;
8319+ pax_force_retaddr 0, 1
8320 ret;
8321
8322 __enc_xor4:
8323@@ -349,6 +355,7 @@ __enc_xor4:
8324
8325 popq %rbx;
8326 popq %rbp;
8327+ pax_force_retaddr 0, 1
8328 ret;
8329
8330 .align 8
8331@@ -386,5 +393,6 @@ blowfish_dec_blk_4way:
8332 popq %rbx;
8333 popq %rbp;
8334
8335+ pax_force_retaddr 0, 1
8336 ret;
8337
8338diff --git a/arch/x86/crypto/camellia-x86_64-asm_64.S b/arch/x86/crypto/camellia-x86_64-asm_64.S
8339index 0b33743..7a56206 100644
8340--- a/arch/x86/crypto/camellia-x86_64-asm_64.S
8341+++ b/arch/x86/crypto/camellia-x86_64-asm_64.S
8342@@ -20,6 +20,8 @@
8343 *
8344 */
8345
8346+#include <asm/alternative-asm.h>
8347+
8348 .file "camellia-x86_64-asm_64.S"
8349 .text
8350
8351@@ -229,12 +231,14 @@ __enc_done:
8352 enc_outunpack(mov, RT1);
8353
8354 movq RRBP, %rbp;
8355+ pax_force_retaddr 0, 1
8356 ret;
8357
8358 __enc_xor:
8359 enc_outunpack(xor, RT1);
8360
8361 movq RRBP, %rbp;
8362+ pax_force_retaddr 0, 1
8363 ret;
8364
8365 .global camellia_dec_blk;
8366@@ -275,6 +279,7 @@ __dec_rounds16:
8367 dec_outunpack();
8368
8369 movq RRBP, %rbp;
8370+ pax_force_retaddr 0, 1
8371 ret;
8372
8373 /**********************************************************************
8374@@ -468,6 +473,7 @@ __enc2_done:
8375
8376 movq RRBP, %rbp;
8377 popq %rbx;
8378+ pax_force_retaddr 0, 1
8379 ret;
8380
8381 __enc2_xor:
8382@@ -475,6 +481,7 @@ __enc2_xor:
8383
8384 movq RRBP, %rbp;
8385 popq %rbx;
8386+ pax_force_retaddr 0, 1
8387 ret;
8388
8389 .global camellia_dec_blk_2way;
8390@@ -517,4 +524,5 @@ __dec2_rounds16:
8391
8392 movq RRBP, %rbp;
8393 movq RXOR, %rbx;
8394+ pax_force_retaddr 0, 1
8395 ret;
8396diff --git a/arch/x86/crypto/salsa20-x86_64-asm_64.S b/arch/x86/crypto/salsa20-x86_64-asm_64.S
8397index 6214a9b..1f4fc9a 100644
8398--- a/arch/x86/crypto/salsa20-x86_64-asm_64.S
8399+++ b/arch/x86/crypto/salsa20-x86_64-asm_64.S
8400@@ -1,3 +1,5 @@
8401+#include <asm/alternative-asm.h>
8402+
8403 # enter ECRYPT_encrypt_bytes
8404 .text
8405 .p2align 5
8406@@ -790,6 +792,7 @@ ECRYPT_encrypt_bytes:
8407 add %r11,%rsp
8408 mov %rdi,%rax
8409 mov %rsi,%rdx
8410+ pax_force_retaddr 0, 1
8411 ret
8412 # bytesatleast65:
8413 ._bytesatleast65:
8414@@ -891,6 +894,7 @@ ECRYPT_keysetup:
8415 add %r11,%rsp
8416 mov %rdi,%rax
8417 mov %rsi,%rdx
8418+ pax_force_retaddr
8419 ret
8420 # enter ECRYPT_ivsetup
8421 .text
8422@@ -917,4 +921,5 @@ ECRYPT_ivsetup:
8423 add %r11,%rsp
8424 mov %rdi,%rax
8425 mov %rsi,%rdx
8426+ pax_force_retaddr
8427 ret
8428diff --git a/arch/x86/crypto/serpent-avx-x86_64-asm_64.S b/arch/x86/crypto/serpent-avx-x86_64-asm_64.S
8429index 504106b..4e50951 100644
8430--- a/arch/x86/crypto/serpent-avx-x86_64-asm_64.S
8431+++ b/arch/x86/crypto/serpent-avx-x86_64-asm_64.S
8432@@ -24,6 +24,8 @@
8433 *
8434 */
8435
8436+#include <asm/alternative-asm.h>
8437+
8438 .file "serpent-avx-x86_64-asm_64.S"
8439 .text
8440
8441@@ -638,12 +640,14 @@ __serpent_enc_blk_8way_avx:
8442 write_blocks(%rsi, RA1, RB1, RC1, RD1, RK0, RK1, RK2);
8443 write_blocks(%rax, RA2, RB2, RC2, RD2, RK0, RK1, RK2);
8444
8445+ pax_force_retaddr
8446 ret;
8447
8448 __enc_xor8:
8449 xor_blocks(%rsi, RA1, RB1, RC1, RD1, RK0, RK1, RK2);
8450 xor_blocks(%rax, RA2, RB2, RC2, RD2, RK0, RK1, RK2);
8451
8452+ pax_force_retaddr
8453 ret;
8454
8455 .align 8
8456@@ -701,4 +705,5 @@ serpent_dec_blk_8way_avx:
8457 write_blocks(%rsi, RC1, RD1, RB1, RE1, RK0, RK1, RK2);
8458 write_blocks(%rax, RC2, RD2, RB2, RE2, RK0, RK1, RK2);
8459
8460+ pax_force_retaddr
8461 ret;
8462diff --git a/arch/x86/crypto/serpent-sse2-x86_64-asm_64.S b/arch/x86/crypto/serpent-sse2-x86_64-asm_64.S
8463index 3ee1ff0..cbc568b 100644
8464--- a/arch/x86/crypto/serpent-sse2-x86_64-asm_64.S
8465+++ b/arch/x86/crypto/serpent-sse2-x86_64-asm_64.S
8466@@ -24,6 +24,8 @@
8467 *
8468 */
8469
8470+#include <asm/alternative-asm.h>
8471+
8472 .file "serpent-sse2-x86_64-asm_64.S"
8473 .text
8474
8475@@ -692,12 +694,14 @@ __serpent_enc_blk_8way:
8476 write_blocks(%rsi, RA1, RB1, RC1, RD1, RK0, RK1, RK2);
8477 write_blocks(%rax, RA2, RB2, RC2, RD2, RK0, RK1, RK2);
8478
8479+ pax_force_retaddr
8480 ret;
8481
8482 __enc_xor8:
8483 xor_blocks(%rsi, RA1, RB1, RC1, RD1, RK0, RK1, RK2);
8484 xor_blocks(%rax, RA2, RB2, RC2, RD2, RK0, RK1, RK2);
8485
8486+ pax_force_retaddr
8487 ret;
8488
8489 .align 8
8490@@ -755,4 +759,5 @@ serpent_dec_blk_8way:
8491 write_blocks(%rsi, RC1, RD1, RB1, RE1, RK0, RK1, RK2);
8492 write_blocks(%rax, RC2, RD2, RB2, RE2, RK0, RK1, RK2);
8493
8494+ pax_force_retaddr
8495 ret;
8496diff --git a/arch/x86/crypto/sha1_ssse3_asm.S b/arch/x86/crypto/sha1_ssse3_asm.S
8497index 49d6987..df66bd4 100644
8498--- a/arch/x86/crypto/sha1_ssse3_asm.S
8499+++ b/arch/x86/crypto/sha1_ssse3_asm.S
8500@@ -28,6 +28,8 @@
8501 * (at your option) any later version.
8502 */
8503
8504+#include <asm/alternative-asm.h>
8505+
8506 #define CTX %rdi // arg1
8507 #define BUF %rsi // arg2
8508 #define CNT %rdx // arg3
8509@@ -104,6 +106,7 @@
8510 pop %r12
8511 pop %rbp
8512 pop %rbx
8513+ pax_force_retaddr 0, 1
8514 ret
8515
8516 .size \name, .-\name
8517diff --git a/arch/x86/crypto/twofish-avx-x86_64-asm_64.S b/arch/x86/crypto/twofish-avx-x86_64-asm_64.S
8518index 35f4557..16b379f 100644
8519--- a/arch/x86/crypto/twofish-avx-x86_64-asm_64.S
8520+++ b/arch/x86/crypto/twofish-avx-x86_64-asm_64.S
8521@@ -21,6 +21,8 @@
8522 *
8523 */
8524
8525+#include <asm/alternative-asm.h>
8526+
8527 .file "twofish-avx-x86_64-asm_64.S"
8528 .text
8529
8530@@ -250,12 +252,14 @@ __twofish_enc_blk_8way:
8531 outunpack_blocks(%rsi, RC1, RD1, RA1, RB1, RK1, RX, RY, RK2);
8532 outunpack_blocks(%rax, RC2, RD2, RA2, RB2, RK1, RX, RY, RK2);
8533
8534+ pax_force_retaddr
8535 ret;
8536
8537 __enc_xor8:
8538 outunpack_xor_blocks(%rsi, RC1, RD1, RA1, RB1, RK1, RX, RY, RK2);
8539 outunpack_xor_blocks(%rax, RC2, RD2, RA2, RB2, RK1, RX, RY, RK2);
8540
8541+ pax_force_retaddr
8542 ret;
8543
8544 .align 8
8545@@ -297,4 +301,5 @@ twofish_dec_blk_8way:
8546 outunpack_blocks(%rsi, RA1, RB1, RC1, RD1, RK1, RX, RY, RK2);
8547 outunpack_blocks(%rax, RA2, RB2, RC2, RD2, RK1, RX, RY, RK2);
8548
8549+ pax_force_retaddr
8550 ret;
8551diff --git a/arch/x86/crypto/twofish-x86_64-asm_64-3way.S b/arch/x86/crypto/twofish-x86_64-asm_64-3way.S
8552index 5b012a2..36d5364 100644
8553--- a/arch/x86/crypto/twofish-x86_64-asm_64-3way.S
8554+++ b/arch/x86/crypto/twofish-x86_64-asm_64-3way.S
8555@@ -20,6 +20,8 @@
8556 *
8557 */
8558
8559+#include <asm/alternative-asm.h>
8560+
8561 .file "twofish-x86_64-asm-3way.S"
8562 .text
8563
8564@@ -260,6 +262,7 @@ __twofish_enc_blk_3way:
8565 popq %r13;
8566 popq %r14;
8567 popq %r15;
8568+ pax_force_retaddr 0, 1
8569 ret;
8570
8571 __enc_xor3:
8572@@ -271,6 +274,7 @@ __enc_xor3:
8573 popq %r13;
8574 popq %r14;
8575 popq %r15;
8576+ pax_force_retaddr 0, 1
8577 ret;
8578
8579 .global twofish_dec_blk_3way
8580@@ -312,5 +316,6 @@ twofish_dec_blk_3way:
8581 popq %r13;
8582 popq %r14;
8583 popq %r15;
8584+ pax_force_retaddr 0, 1
8585 ret;
8586
8587diff --git a/arch/x86/crypto/twofish-x86_64-asm_64.S b/arch/x86/crypto/twofish-x86_64-asm_64.S
8588index 7bcf3fc..f53832f 100644
8589--- a/arch/x86/crypto/twofish-x86_64-asm_64.S
8590+++ b/arch/x86/crypto/twofish-x86_64-asm_64.S
8591@@ -21,6 +21,7 @@
8592 .text
8593
8594 #include <asm/asm-offsets.h>
8595+#include <asm/alternative-asm.h>
8596
8597 #define a_offset 0
8598 #define b_offset 4
8599@@ -268,6 +269,7 @@ twofish_enc_blk:
8600
8601 popq R1
8602 movq $1,%rax
8603+ pax_force_retaddr 0, 1
8604 ret
8605
8606 twofish_dec_blk:
8607@@ -319,4 +321,5 @@ twofish_dec_blk:
8608
8609 popq R1
8610 movq $1,%rax
8611+ pax_force_retaddr 0, 1
8612 ret
8613diff --git a/arch/x86/ia32/ia32_aout.c b/arch/x86/ia32/ia32_aout.c
8614index 07b3a68..bd2a388 100644
8615--- a/arch/x86/ia32/ia32_aout.c
8616+++ b/arch/x86/ia32/ia32_aout.c
8617@@ -159,6 +159,8 @@ static int aout_core_dump(long signr, struct pt_regs *regs, struct file *file,
8618 unsigned long dump_start, dump_size;
8619 struct user32 dump;
8620
8621+ memset(&dump, 0, sizeof(dump));
8622+
8623 fs = get_fs();
8624 set_fs(KERNEL_DS);
8625 has_dumped = 1;
8626diff --git a/arch/x86/ia32/ia32_signal.c b/arch/x86/ia32/ia32_signal.c
8627index 673ac9b..7a8c5df 100644
8628--- a/arch/x86/ia32/ia32_signal.c
8629+++ b/arch/x86/ia32/ia32_signal.c
8630@@ -162,7 +162,7 @@ asmlinkage long sys32_sigaltstack(const stack_ia32_t __user *uss_ptr,
8631 }
8632 seg = get_fs();
8633 set_fs(KERNEL_DS);
8634- ret = do_sigaltstack(uss_ptr ? &uss : NULL, &uoss, regs->sp);
8635+ ret = do_sigaltstack(uss_ptr ? (const stack_t __force_user *)&uss : NULL, (stack_t __force_user *)&uoss, regs->sp);
8636 set_fs(seg);
8637 if (ret >= 0 && uoss_ptr) {
8638 if (!access_ok(VERIFY_WRITE, uoss_ptr, sizeof(stack_ia32_t)))
8639@@ -361,7 +361,7 @@ static int ia32_setup_sigcontext(struct sigcontext_ia32 __user *sc,
8640 */
8641 static void __user *get_sigframe(struct k_sigaction *ka, struct pt_regs *regs,
8642 size_t frame_size,
8643- void **fpstate)
8644+ void __user **fpstate)
8645 {
8646 unsigned long sp;
8647
8648@@ -382,7 +382,7 @@ static void __user *get_sigframe(struct k_sigaction *ka, struct pt_regs *regs,
8649
8650 if (used_math()) {
8651 sp = sp - sig_xstate_ia32_size;
8652- *fpstate = (struct _fpstate_ia32 *) sp;
8653+ *fpstate = (struct _fpstate_ia32 __user *) sp;
8654 if (save_i387_xstate_ia32(*fpstate) < 0)
8655 return (void __user *) -1L;
8656 }
8657@@ -390,7 +390,7 @@ static void __user *get_sigframe(struct k_sigaction *ka, struct pt_regs *regs,
8658 sp -= frame_size;
8659 /* Align the stack pointer according to the i386 ABI,
8660 * i.e. so that on function entry ((sp + 4) & 15) == 0. */
8661- sp = ((sp + 4) & -16ul) - 4;
8662+ sp = ((sp - 12) & -16ul) - 4;
8663 return (void __user *) sp;
8664 }
8665
8666@@ -448,7 +448,7 @@ int ia32_setup_frame(int sig, struct k_sigaction *ka,
8667 * These are actually not used anymore, but left because some
8668 * gdb versions depend on them as a marker.
8669 */
8670- put_user_ex(*((u64 *)&code), (u64 *)frame->retcode);
8671+ put_user_ex(*((const u64 *)&code), (u64 __user *)frame->retcode);
8672 } put_user_catch(err);
8673
8674 if (err)
8675@@ -490,7 +490,7 @@ int ia32_setup_rt_frame(int sig, struct k_sigaction *ka, siginfo_t *info,
8676 0xb8,
8677 __NR_ia32_rt_sigreturn,
8678 0x80cd,
8679- 0,
8680+ 0
8681 };
8682
8683 frame = get_sigframe(ka, regs, sizeof(*frame), &fpstate);
8684@@ -520,16 +520,18 @@ int ia32_setup_rt_frame(int sig, struct k_sigaction *ka, siginfo_t *info,
8685
8686 if (ka->sa.sa_flags & SA_RESTORER)
8687 restorer = ka->sa.sa_restorer;
8688+ else if (current->mm->context.vdso)
8689+ /* Return stub is in 32bit vsyscall page */
8690+ restorer = VDSO32_SYMBOL(current->mm->context.vdso, rt_sigreturn);
8691 else
8692- restorer = VDSO32_SYMBOL(current->mm->context.vdso,
8693- rt_sigreturn);
8694+ restorer = &frame->retcode;
8695 put_user_ex(ptr_to_compat(restorer), &frame->pretcode);
8696
8697 /*
8698 * Not actually used anymore, but left because some gdb
8699 * versions need it.
8700 */
8701- put_user_ex(*((u64 *)&code), (u64 *)frame->retcode);
8702+ put_user_ex(*((const u64 *)&code), (u64 __user *)frame->retcode);
8703 } put_user_catch(err);
8704
8705 if (err)
8706diff --git a/arch/x86/ia32/ia32entry.S b/arch/x86/ia32/ia32entry.S
8707index 20e5f7b..f33c779 100644
8708--- a/arch/x86/ia32/ia32entry.S
8709+++ b/arch/x86/ia32/ia32entry.S
8710@@ -14,8 +14,10 @@
8711 #include <asm/segment.h>
8712 #include <asm/irqflags.h>
8713 #include <asm/asm.h>
8714+#include <asm/pgtable.h>
8715 #include <linux/linkage.h>
8716 #include <linux/err.h>
8717+#include <asm/alternative-asm.h>
8718
8719 /* Avoid __ASSEMBLER__'ifying <linux/audit.h> just for this. */
8720 #include <linux/elf-em.h>
8721@@ -95,6 +97,32 @@ ENTRY(native_irq_enable_sysexit)
8722 ENDPROC(native_irq_enable_sysexit)
8723 #endif
8724
8725+ .macro pax_enter_kernel_user
8726+ pax_set_fptr_mask
8727+#ifdef CONFIG_PAX_MEMORY_UDEREF
8728+ call pax_enter_kernel_user
8729+#endif
8730+ .endm
8731+
8732+ .macro pax_exit_kernel_user
8733+#ifdef CONFIG_PAX_MEMORY_UDEREF
8734+ call pax_exit_kernel_user
8735+#endif
8736+#ifdef CONFIG_PAX_RANDKSTACK
8737+ pushq %rax
8738+ pushq %r11
8739+ call pax_randomize_kstack
8740+ popq %r11
8741+ popq %rax
8742+#endif
8743+ .endm
8744+
8745+.macro pax_erase_kstack
8746+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
8747+ call pax_erase_kstack
8748+#endif
8749+.endm
8750+
8751 /*
8752 * 32bit SYSENTER instruction entry.
8753 *
8754@@ -121,12 +149,6 @@ ENTRY(ia32_sysenter_target)
8755 CFI_REGISTER rsp,rbp
8756 SWAPGS_UNSAFE_STACK
8757 movq PER_CPU_VAR(kernel_stack), %rsp
8758- addq $(KERNEL_STACK_OFFSET),%rsp
8759- /*
8760- * No need to follow this irqs on/off section: the syscall
8761- * disabled irqs, here we enable it straight after entry:
8762- */
8763- ENABLE_INTERRUPTS(CLBR_NONE)
8764 movl %ebp,%ebp /* zero extension */
8765 pushq_cfi $__USER32_DS
8766 /*CFI_REL_OFFSET ss,0*/
8767@@ -134,22 +156,42 @@ ENTRY(ia32_sysenter_target)
8768 CFI_REL_OFFSET rsp,0
8769 pushfq_cfi
8770 /*CFI_REL_OFFSET rflags,0*/
8771- movl TI_sysenter_return+THREAD_INFO(%rsp,3*8-KERNEL_STACK_OFFSET),%r10d
8772- CFI_REGISTER rip,r10
8773+ orl $X86_EFLAGS_IF,(%rsp)
8774+ GET_THREAD_INFO(%r11)
8775+ movl TI_sysenter_return(%r11), %r11d
8776+ CFI_REGISTER rip,r11
8777 pushq_cfi $__USER32_CS
8778 /*CFI_REL_OFFSET cs,0*/
8779 movl %eax, %eax
8780- pushq_cfi %r10
8781+ pushq_cfi %r11
8782 CFI_REL_OFFSET rip,0
8783 pushq_cfi %rax
8784 cld
8785 SAVE_ARGS 0,1,0
8786+ pax_enter_kernel_user
8787+
8788+#ifdef CONFIG_PAX_RANDKSTACK
8789+ pax_erase_kstack
8790+#endif
8791+
8792+ /*
8793+ * No need to follow this irqs on/off section: the syscall
8794+ * disabled irqs, here we enable it straight after entry:
8795+ */
8796+ ENABLE_INTERRUPTS(CLBR_NONE)
8797 /* no need to do an access_ok check here because rbp has been
8798 32bit zero extended */
8799+
8800+#ifdef CONFIG_PAX_MEMORY_UDEREF
8801+ mov $PAX_USER_SHADOW_BASE,%r11
8802+ add %r11,%rbp
8803+#endif
8804+
8805 1: movl (%rbp),%ebp
8806 _ASM_EXTABLE(1b,ia32_badarg)
8807- orl $TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
8808- testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
8809+ GET_THREAD_INFO(%r11)
8810+ orl $TS_COMPAT,TI_status(%r11)
8811+ testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%r11)
8812 CFI_REMEMBER_STATE
8813 jnz sysenter_tracesys
8814 cmpq $(IA32_NR_syscalls-1),%rax
8815@@ -159,12 +201,15 @@ sysenter_do_call:
8816 sysenter_dispatch:
8817 call *ia32_sys_call_table(,%rax,8)
8818 movq %rax,RAX-ARGOFFSET(%rsp)
8819+ GET_THREAD_INFO(%r11)
8820 DISABLE_INTERRUPTS(CLBR_NONE)
8821 TRACE_IRQS_OFF
8822- testl $_TIF_ALLWORK_MASK,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
8823+ testl $_TIF_ALLWORK_MASK,TI_flags(%r11)
8824 jnz sysexit_audit
8825 sysexit_from_sys_call:
8826- andl $~TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
8827+ pax_exit_kernel_user
8828+ pax_erase_kstack
8829+ andl $~TS_COMPAT,TI_status(%r11)
8830 /* clear IF, that popfq doesn't enable interrupts early */
8831 andl $~0x200,EFLAGS-R11(%rsp)
8832 movl RIP-R11(%rsp),%edx /* User %eip */
8833@@ -190,6 +235,9 @@ sysexit_from_sys_call:
8834 movl %eax,%esi /* 2nd arg: syscall number */
8835 movl $AUDIT_ARCH_I386,%edi /* 1st arg: audit arch */
8836 call __audit_syscall_entry
8837+
8838+ pax_erase_kstack
8839+
8840 movl RAX-ARGOFFSET(%rsp),%eax /* reload syscall number */
8841 cmpq $(IA32_NR_syscalls-1),%rax
8842 ja ia32_badsys
8843@@ -201,7 +249,7 @@ sysexit_from_sys_call:
8844 .endm
8845
8846 .macro auditsys_exit exit
8847- testl $(_TIF_ALLWORK_MASK & ~_TIF_SYSCALL_AUDIT),TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
8848+ testl $(_TIF_ALLWORK_MASK & ~_TIF_SYSCALL_AUDIT),TI_flags(%r11)
8849 jnz ia32_ret_from_sys_call
8850 TRACE_IRQS_ON
8851 sti
8852@@ -212,11 +260,12 @@ sysexit_from_sys_call:
8853 1: setbe %al /* 1 if error, 0 if not */
8854 movzbl %al,%edi /* zero-extend that into %edi */
8855 call __audit_syscall_exit
8856+ GET_THREAD_INFO(%r11)
8857 movq RAX-ARGOFFSET(%rsp),%rax /* reload syscall return value */
8858 movl $(_TIF_ALLWORK_MASK & ~_TIF_SYSCALL_AUDIT),%edi
8859 cli
8860 TRACE_IRQS_OFF
8861- testl %edi,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
8862+ testl %edi,TI_flags(%r11)
8863 jz \exit
8864 CLEAR_RREGS -ARGOFFSET
8865 jmp int_with_check
8866@@ -234,7 +283,7 @@ sysexit_audit:
8867
8868 sysenter_tracesys:
8869 #ifdef CONFIG_AUDITSYSCALL
8870- testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
8871+ testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags(%r11)
8872 jz sysenter_auditsys
8873 #endif
8874 SAVE_REST
8875@@ -246,6 +295,9 @@ sysenter_tracesys:
8876 RESTORE_REST
8877 cmpq $(IA32_NR_syscalls-1),%rax
8878 ja int_ret_from_sys_call /* sysenter_tracesys has set RAX(%rsp) */
8879+
8880+ pax_erase_kstack
8881+
8882 jmp sysenter_do_call
8883 CFI_ENDPROC
8884 ENDPROC(ia32_sysenter_target)
8885@@ -273,19 +325,25 @@ ENDPROC(ia32_sysenter_target)
8886 ENTRY(ia32_cstar_target)
8887 CFI_STARTPROC32 simple
8888 CFI_SIGNAL_FRAME
8889- CFI_DEF_CFA rsp,KERNEL_STACK_OFFSET
8890+ CFI_DEF_CFA rsp,0
8891 CFI_REGISTER rip,rcx
8892 /*CFI_REGISTER rflags,r11*/
8893 SWAPGS_UNSAFE_STACK
8894 movl %esp,%r8d
8895 CFI_REGISTER rsp,r8
8896 movq PER_CPU_VAR(kernel_stack),%rsp
8897+ SAVE_ARGS 8*6,0,0
8898+ pax_enter_kernel_user
8899+
8900+#ifdef CONFIG_PAX_RANDKSTACK
8901+ pax_erase_kstack
8902+#endif
8903+
8904 /*
8905 * No need to follow this irqs on/off section: the syscall
8906 * disabled irqs and here we enable it straight after entry:
8907 */
8908 ENABLE_INTERRUPTS(CLBR_NONE)
8909- SAVE_ARGS 8,0,0
8910 movl %eax,%eax /* zero extension */
8911 movq %rax,ORIG_RAX-ARGOFFSET(%rsp)
8912 movq %rcx,RIP-ARGOFFSET(%rsp)
8913@@ -301,10 +359,17 @@ ENTRY(ia32_cstar_target)
8914 /* no need to do an access_ok check here because r8 has been
8915 32bit zero extended */
8916 /* hardware stack frame is complete now */
8917+
8918+#ifdef CONFIG_PAX_MEMORY_UDEREF
8919+ mov $PAX_USER_SHADOW_BASE,%r11
8920+ add %r11,%r8
8921+#endif
8922+
8923 1: movl (%r8),%r9d
8924 _ASM_EXTABLE(1b,ia32_badarg)
8925- orl $TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
8926- testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
8927+ GET_THREAD_INFO(%r11)
8928+ orl $TS_COMPAT,TI_status(%r11)
8929+ testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%r11)
8930 CFI_REMEMBER_STATE
8931 jnz cstar_tracesys
8932 cmpq $IA32_NR_syscalls-1,%rax
8933@@ -314,12 +379,15 @@ cstar_do_call:
8934 cstar_dispatch:
8935 call *ia32_sys_call_table(,%rax,8)
8936 movq %rax,RAX-ARGOFFSET(%rsp)
8937+ GET_THREAD_INFO(%r11)
8938 DISABLE_INTERRUPTS(CLBR_NONE)
8939 TRACE_IRQS_OFF
8940- testl $_TIF_ALLWORK_MASK,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
8941+ testl $_TIF_ALLWORK_MASK,TI_flags(%r11)
8942 jnz sysretl_audit
8943 sysretl_from_sys_call:
8944- andl $~TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
8945+ pax_exit_kernel_user
8946+ pax_erase_kstack
8947+ andl $~TS_COMPAT,TI_status(%r11)
8948 RESTORE_ARGS 0,-ARG_SKIP,0,0,0
8949 movl RIP-ARGOFFSET(%rsp),%ecx
8950 CFI_REGISTER rip,rcx
8951@@ -347,7 +415,7 @@ sysretl_audit:
8952
8953 cstar_tracesys:
8954 #ifdef CONFIG_AUDITSYSCALL
8955- testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
8956+ testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags(%r11)
8957 jz cstar_auditsys
8958 #endif
8959 xchgl %r9d,%ebp
8960@@ -361,6 +429,9 @@ cstar_tracesys:
8961 xchgl %ebp,%r9d
8962 cmpq $(IA32_NR_syscalls-1),%rax
8963 ja int_ret_from_sys_call /* cstar_tracesys has set RAX(%rsp) */
8964+
8965+ pax_erase_kstack
8966+
8967 jmp cstar_do_call
8968 END(ia32_cstar_target)
8969
8970@@ -401,19 +472,26 @@ ENTRY(ia32_syscall)
8971 CFI_REL_OFFSET rip,RIP-RIP
8972 PARAVIRT_ADJUST_EXCEPTION_FRAME
8973 SWAPGS
8974- /*
8975- * No need to follow this irqs on/off section: the syscall
8976- * disabled irqs and here we enable it straight after entry:
8977- */
8978- ENABLE_INTERRUPTS(CLBR_NONE)
8979 movl %eax,%eax
8980 pushq_cfi %rax
8981 cld
8982 /* note the registers are not zero extended to the sf.
8983 this could be a problem. */
8984 SAVE_ARGS 0,1,0
8985- orl $TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
8986- testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
8987+ pax_enter_kernel_user
8988+
8989+#ifdef CONFIG_PAX_RANDKSTACK
8990+ pax_erase_kstack
8991+#endif
8992+
8993+ /*
8994+ * No need to follow this irqs on/off section: the syscall
8995+ * disabled irqs and here we enable it straight after entry:
8996+ */
8997+ ENABLE_INTERRUPTS(CLBR_NONE)
8998+ GET_THREAD_INFO(%r11)
8999+ orl $TS_COMPAT,TI_status(%r11)
9000+ testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%r11)
9001 jnz ia32_tracesys
9002 cmpq $(IA32_NR_syscalls-1),%rax
9003 ja ia32_badsys
9004@@ -436,6 +514,9 @@ ia32_tracesys:
9005 RESTORE_REST
9006 cmpq $(IA32_NR_syscalls-1),%rax
9007 ja int_ret_from_sys_call /* ia32_tracesys has set RAX(%rsp) */
9008+
9009+ pax_erase_kstack
9010+
9011 jmp ia32_do_call
9012 END(ia32_syscall)
9013
9014diff --git a/arch/x86/ia32/sys_ia32.c b/arch/x86/ia32/sys_ia32.c
9015index 4540bec..714d913 100644
9016--- a/arch/x86/ia32/sys_ia32.c
9017+++ b/arch/x86/ia32/sys_ia32.c
9018@@ -69,8 +69,8 @@ asmlinkage long sys32_ftruncate64(unsigned int fd, unsigned long offset_low,
9019 */
9020 static int cp_stat64(struct stat64 __user *ubuf, struct kstat *stat)
9021 {
9022- typeof(ubuf->st_uid) uid = 0;
9023- typeof(ubuf->st_gid) gid = 0;
9024+ typeof(((struct stat64 *)0)->st_uid) uid = 0;
9025+ typeof(((struct stat64 *)0)->st_gid) gid = 0;
9026 SET_UID(uid, from_kuid_munged(current_user_ns(), stat->uid));
9027 SET_GID(gid, from_kgid_munged(current_user_ns(), stat->gid));
9028 if (!access_ok(VERIFY_WRITE, ubuf, sizeof(struct stat64)) ||
9029@@ -287,7 +287,7 @@ asmlinkage long sys32_sigaction(int sig, struct old_sigaction32 __user *act,
9030 return ret;
9031 }
9032
9033-asmlinkage long sys32_waitpid(compat_pid_t pid, unsigned int *stat_addr,
9034+asmlinkage long sys32_waitpid(compat_pid_t pid, unsigned int __user *stat_addr,
9035 int options)
9036 {
9037 return compat_sys_wait4(pid, stat_addr, options, NULL);
9038@@ -303,7 +303,7 @@ asmlinkage long sys32_sched_rr_get_interval(compat_pid_t pid,
9039 mm_segment_t old_fs = get_fs();
9040
9041 set_fs(KERNEL_DS);
9042- ret = sys_sched_rr_get_interval(pid, (struct timespec __user *)&t);
9043+ ret = sys_sched_rr_get_interval(pid, (struct timespec __force_user *)&t);
9044 set_fs(old_fs);
9045 if (put_compat_timespec(&t, interval))
9046 return -EFAULT;
9047@@ -319,7 +319,7 @@ asmlinkage long sys32_rt_sigpending(compat_sigset_t __user *set,
9048 mm_segment_t old_fs = get_fs();
9049
9050 set_fs(KERNEL_DS);
9051- ret = sys_rt_sigpending((sigset_t __user *)&s, sigsetsize);
9052+ ret = sys_rt_sigpending((sigset_t __force_user *)&s, sigsetsize);
9053 set_fs(old_fs);
9054 if (!ret) {
9055 switch (_NSIG_WORDS) {
9056@@ -344,7 +344,7 @@ asmlinkage long sys32_rt_sigqueueinfo(int pid, int sig,
9057 if (copy_siginfo_from_user32(&info, uinfo))
9058 return -EFAULT;
9059 set_fs(KERNEL_DS);
9060- ret = sys_rt_sigqueueinfo(pid, sig, (siginfo_t __user *)&info);
9061+ ret = sys_rt_sigqueueinfo(pid, sig, (siginfo_t __force_user *)&info);
9062 set_fs(old_fs);
9063 return ret;
9064 }
9065@@ -376,7 +376,7 @@ asmlinkage long sys32_sendfile(int out_fd, int in_fd,
9066 return -EFAULT;
9067
9068 set_fs(KERNEL_DS);
9069- ret = sys_sendfile(out_fd, in_fd, offset ? (off_t __user *)&of : NULL,
9070+ ret = sys_sendfile(out_fd, in_fd, offset ? (off_t __force_user *)&of : NULL,
9071 count);
9072 set_fs(old_fs);
9073
9074diff --git a/arch/x86/include/asm/alternative-asm.h b/arch/x86/include/asm/alternative-asm.h
9075index 952bd01..7692c6f 100644
9076--- a/arch/x86/include/asm/alternative-asm.h
9077+++ b/arch/x86/include/asm/alternative-asm.h
9078@@ -15,6 +15,45 @@
9079 .endm
9080 #endif
9081
9082+#ifdef KERNEXEC_PLUGIN
9083+ .macro pax_force_retaddr_bts rip=0
9084+ btsq $63,\rip(%rsp)
9085+ .endm
9086+#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_BTS
9087+ .macro pax_force_retaddr rip=0, reload=0
9088+ btsq $63,\rip(%rsp)
9089+ .endm
9090+ .macro pax_force_fptr ptr
9091+ btsq $63,\ptr
9092+ .endm
9093+ .macro pax_set_fptr_mask
9094+ .endm
9095+#endif
9096+#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR
9097+ .macro pax_force_retaddr rip=0, reload=0
9098+ .if \reload
9099+ pax_set_fptr_mask
9100+ .endif
9101+ orq %r10,\rip(%rsp)
9102+ .endm
9103+ .macro pax_force_fptr ptr
9104+ orq %r10,\ptr
9105+ .endm
9106+ .macro pax_set_fptr_mask
9107+ movabs $0x8000000000000000,%r10
9108+ .endm
9109+#endif
9110+#else
9111+ .macro pax_force_retaddr rip=0, reload=0
9112+ .endm
9113+ .macro pax_force_fptr ptr
9114+ .endm
9115+ .macro pax_force_retaddr_bts rip=0
9116+ .endm
9117+ .macro pax_set_fptr_mask
9118+ .endm
9119+#endif
9120+
9121 .macro altinstruction_entry orig alt feature orig_len alt_len
9122 .long \orig - .
9123 .long \alt - .
9124diff --git a/arch/x86/include/asm/alternative.h b/arch/x86/include/asm/alternative.h
9125index 7078068..f58bcda 100644
9126--- a/arch/x86/include/asm/alternative.h
9127+++ b/arch/x86/include/asm/alternative.h
9128@@ -105,7 +105,7 @@ static inline int alternatives_text_reserved(void *start, void *end)
9129 ".section .discard,\"aw\",@progbits\n" \
9130 DISCARD_ENTRY(1) \
9131 ".previous\n" \
9132- ".section .altinstr_replacement, \"ax\"\n" \
9133+ ".section .altinstr_replacement, \"a\"\n" \
9134 ALTINSTR_REPLACEMENT(newinstr, feature, 1) \
9135 ".previous"
9136
9137@@ -119,7 +119,7 @@ static inline int alternatives_text_reserved(void *start, void *end)
9138 DISCARD_ENTRY(1) \
9139 DISCARD_ENTRY(2) \
9140 ".previous\n" \
9141- ".section .altinstr_replacement, \"ax\"\n" \
9142+ ".section .altinstr_replacement, \"a\"\n" \
9143 ALTINSTR_REPLACEMENT(newinstr1, feature1, 1) \
9144 ALTINSTR_REPLACEMENT(newinstr2, feature2, 2) \
9145 ".previous"
9146diff --git a/arch/x86/include/asm/apic.h b/arch/x86/include/asm/apic.h
9147index f342612..b3fe911 100644
9148--- a/arch/x86/include/asm/apic.h
9149+++ b/arch/x86/include/asm/apic.h
9150@@ -44,7 +44,7 @@ static inline void generic_apic_probe(void)
9151
9152 #ifdef CONFIG_X86_LOCAL_APIC
9153
9154-extern unsigned int apic_verbosity;
9155+extern int apic_verbosity;
9156 extern int local_apic_timer_c2_ok;
9157
9158 extern int disable_apic;
9159@@ -391,7 +391,7 @@ struct apic {
9160 */
9161 int (*x86_32_numa_cpu_node)(int cpu);
9162 #endif
9163-};
9164+} __do_const;
9165
9166 /*
9167 * Pointer to the local APIC driver in use on this system (there's
9168diff --git a/arch/x86/include/asm/apm.h b/arch/x86/include/asm/apm.h
9169index 20370c6..a2eb9b0 100644
9170--- a/arch/x86/include/asm/apm.h
9171+++ b/arch/x86/include/asm/apm.h
9172@@ -34,7 +34,7 @@ static inline void apm_bios_call_asm(u32 func, u32 ebx_in, u32 ecx_in,
9173 __asm__ __volatile__(APM_DO_ZERO_SEGS
9174 "pushl %%edi\n\t"
9175 "pushl %%ebp\n\t"
9176- "lcall *%%cs:apm_bios_entry\n\t"
9177+ "lcall *%%ss:apm_bios_entry\n\t"
9178 "setc %%al\n\t"
9179 "popl %%ebp\n\t"
9180 "popl %%edi\n\t"
9181@@ -58,7 +58,7 @@ static inline u8 apm_bios_call_simple_asm(u32 func, u32 ebx_in,
9182 __asm__ __volatile__(APM_DO_ZERO_SEGS
9183 "pushl %%edi\n\t"
9184 "pushl %%ebp\n\t"
9185- "lcall *%%cs:apm_bios_entry\n\t"
9186+ "lcall *%%ss:apm_bios_entry\n\t"
9187 "setc %%bl\n\t"
9188 "popl %%ebp\n\t"
9189 "popl %%edi\n\t"
9190diff --git a/arch/x86/include/asm/atomic.h b/arch/x86/include/asm/atomic.h
9191index 58cb6d4..a4b806c 100644
9192--- a/arch/x86/include/asm/atomic.h
9193+++ b/arch/x86/include/asm/atomic.h
9194@@ -22,7 +22,18 @@
9195 */
9196 static inline int atomic_read(const atomic_t *v)
9197 {
9198- return (*(volatile int *)&(v)->counter);
9199+ return (*(volatile const int *)&(v)->counter);
9200+}
9201+
9202+/**
9203+ * atomic_read_unchecked - read atomic variable
9204+ * @v: pointer of type atomic_unchecked_t
9205+ *
9206+ * Atomically reads the value of @v.
9207+ */
9208+static inline int atomic_read_unchecked(const atomic_unchecked_t *v)
9209+{
9210+ return (*(volatile const int *)&(v)->counter);
9211 }
9212
9213 /**
9214@@ -38,6 +49,18 @@ static inline void atomic_set(atomic_t *v, int i)
9215 }
9216
9217 /**
9218+ * atomic_set_unchecked - set atomic variable
9219+ * @v: pointer of type atomic_unchecked_t
9220+ * @i: required value
9221+ *
9222+ * Atomically sets the value of @v to @i.
9223+ */
9224+static inline void atomic_set_unchecked(atomic_unchecked_t *v, int i)
9225+{
9226+ v->counter = i;
9227+}
9228+
9229+/**
9230 * atomic_add - add integer to atomic variable
9231 * @i: integer value to add
9232 * @v: pointer of type atomic_t
9233@@ -46,7 +69,29 @@ static inline void atomic_set(atomic_t *v, int i)
9234 */
9235 static inline void atomic_add(int i, atomic_t *v)
9236 {
9237- asm volatile(LOCK_PREFIX "addl %1,%0"
9238+ asm volatile(LOCK_PREFIX "addl %1,%0\n"
9239+
9240+#ifdef CONFIG_PAX_REFCOUNT
9241+ "jno 0f\n"
9242+ LOCK_PREFIX "subl %1,%0\n"
9243+ "int $4\n0:\n"
9244+ _ASM_EXTABLE(0b, 0b)
9245+#endif
9246+
9247+ : "+m" (v->counter)
9248+ : "ir" (i));
9249+}
9250+
9251+/**
9252+ * atomic_add_unchecked - add integer to atomic variable
9253+ * @i: integer value to add
9254+ * @v: pointer of type atomic_unchecked_t
9255+ *
9256+ * Atomically adds @i to @v.
9257+ */
9258+static inline void atomic_add_unchecked(int i, atomic_unchecked_t *v)
9259+{
9260+ asm volatile(LOCK_PREFIX "addl %1,%0\n"
9261 : "+m" (v->counter)
9262 : "ir" (i));
9263 }
9264@@ -60,7 +105,29 @@ static inline void atomic_add(int i, atomic_t *v)
9265 */
9266 static inline void atomic_sub(int i, atomic_t *v)
9267 {
9268- asm volatile(LOCK_PREFIX "subl %1,%0"
9269+ asm volatile(LOCK_PREFIX "subl %1,%0\n"
9270+
9271+#ifdef CONFIG_PAX_REFCOUNT
9272+ "jno 0f\n"
9273+ LOCK_PREFIX "addl %1,%0\n"
9274+ "int $4\n0:\n"
9275+ _ASM_EXTABLE(0b, 0b)
9276+#endif
9277+
9278+ : "+m" (v->counter)
9279+ : "ir" (i));
9280+}
9281+
9282+/**
9283+ * atomic_sub_unchecked - subtract integer from atomic variable
9284+ * @i: integer value to subtract
9285+ * @v: pointer of type atomic_unchecked_t
9286+ *
9287+ * Atomically subtracts @i from @v.
9288+ */
9289+static inline void atomic_sub_unchecked(int i, atomic_unchecked_t *v)
9290+{
9291+ asm volatile(LOCK_PREFIX "subl %1,%0\n"
9292 : "+m" (v->counter)
9293 : "ir" (i));
9294 }
9295@@ -78,7 +145,16 @@ static inline int atomic_sub_and_test(int i, atomic_t *v)
9296 {
9297 unsigned char c;
9298
9299- asm volatile(LOCK_PREFIX "subl %2,%0; sete %1"
9300+ asm volatile(LOCK_PREFIX "subl %2,%0\n"
9301+
9302+#ifdef CONFIG_PAX_REFCOUNT
9303+ "jno 0f\n"
9304+ LOCK_PREFIX "addl %2,%0\n"
9305+ "int $4\n0:\n"
9306+ _ASM_EXTABLE(0b, 0b)
9307+#endif
9308+
9309+ "sete %1\n"
9310 : "+m" (v->counter), "=qm" (c)
9311 : "ir" (i) : "memory");
9312 return c;
9313@@ -92,7 +168,27 @@ static inline int atomic_sub_and_test(int i, atomic_t *v)
9314 */
9315 static inline void atomic_inc(atomic_t *v)
9316 {
9317- asm volatile(LOCK_PREFIX "incl %0"
9318+ asm volatile(LOCK_PREFIX "incl %0\n"
9319+
9320+#ifdef CONFIG_PAX_REFCOUNT
9321+ "jno 0f\n"
9322+ LOCK_PREFIX "decl %0\n"
9323+ "int $4\n0:\n"
9324+ _ASM_EXTABLE(0b, 0b)
9325+#endif
9326+
9327+ : "+m" (v->counter));
9328+}
9329+
9330+/**
9331+ * atomic_inc_unchecked - increment atomic variable
9332+ * @v: pointer of type atomic_unchecked_t
9333+ *
9334+ * Atomically increments @v by 1.
9335+ */
9336+static inline void atomic_inc_unchecked(atomic_unchecked_t *v)
9337+{
9338+ asm volatile(LOCK_PREFIX "incl %0\n"
9339 : "+m" (v->counter));
9340 }
9341
9342@@ -104,7 +200,27 @@ static inline void atomic_inc(atomic_t *v)
9343 */
9344 static inline void atomic_dec(atomic_t *v)
9345 {
9346- asm volatile(LOCK_PREFIX "decl %0"
9347+ asm volatile(LOCK_PREFIX "decl %0\n"
9348+
9349+#ifdef CONFIG_PAX_REFCOUNT
9350+ "jno 0f\n"
9351+ LOCK_PREFIX "incl %0\n"
9352+ "int $4\n0:\n"
9353+ _ASM_EXTABLE(0b, 0b)
9354+#endif
9355+
9356+ : "+m" (v->counter));
9357+}
9358+
9359+/**
9360+ * atomic_dec_unchecked - decrement atomic variable
9361+ * @v: pointer of type atomic_unchecked_t
9362+ *
9363+ * Atomically decrements @v by 1.
9364+ */
9365+static inline void atomic_dec_unchecked(atomic_unchecked_t *v)
9366+{
9367+ asm volatile(LOCK_PREFIX "decl %0\n"
9368 : "+m" (v->counter));
9369 }
9370
9371@@ -120,7 +236,16 @@ static inline int atomic_dec_and_test(atomic_t *v)
9372 {
9373 unsigned char c;
9374
9375- asm volatile(LOCK_PREFIX "decl %0; sete %1"
9376+ asm volatile(LOCK_PREFIX "decl %0\n"
9377+
9378+#ifdef CONFIG_PAX_REFCOUNT
9379+ "jno 0f\n"
9380+ LOCK_PREFIX "incl %0\n"
9381+ "int $4\n0:\n"
9382+ _ASM_EXTABLE(0b, 0b)
9383+#endif
9384+
9385+ "sete %1\n"
9386 : "+m" (v->counter), "=qm" (c)
9387 : : "memory");
9388 return c != 0;
9389@@ -138,7 +263,35 @@ static inline int atomic_inc_and_test(atomic_t *v)
9390 {
9391 unsigned char c;
9392
9393- asm volatile(LOCK_PREFIX "incl %0; sete %1"
9394+ asm volatile(LOCK_PREFIX "incl %0\n"
9395+
9396+#ifdef CONFIG_PAX_REFCOUNT
9397+ "jno 0f\n"
9398+ LOCK_PREFIX "decl %0\n"
9399+ "int $4\n0:\n"
9400+ _ASM_EXTABLE(0b, 0b)
9401+#endif
9402+
9403+ "sete %1\n"
9404+ : "+m" (v->counter), "=qm" (c)
9405+ : : "memory");
9406+ return c != 0;
9407+}
9408+
9409+/**
9410+ * atomic_inc_and_test_unchecked - increment and test
9411+ * @v: pointer of type atomic_unchecked_t
9412+ *
9413+ * Atomically increments @v by 1
9414+ * and returns true if the result is zero, or false for all
9415+ * other cases.
9416+ */
9417+static inline int atomic_inc_and_test_unchecked(atomic_unchecked_t *v)
9418+{
9419+ unsigned char c;
9420+
9421+ asm volatile(LOCK_PREFIX "incl %0\n"
9422+ "sete %1\n"
9423 : "+m" (v->counter), "=qm" (c)
9424 : : "memory");
9425 return c != 0;
9426@@ -157,7 +310,16 @@ static inline int atomic_add_negative(int i, atomic_t *v)
9427 {
9428 unsigned char c;
9429
9430- asm volatile(LOCK_PREFIX "addl %2,%0; sets %1"
9431+ asm volatile(LOCK_PREFIX "addl %2,%0\n"
9432+
9433+#ifdef CONFIG_PAX_REFCOUNT
9434+ "jno 0f\n"
9435+ LOCK_PREFIX "subl %2,%0\n"
9436+ "int $4\n0:\n"
9437+ _ASM_EXTABLE(0b, 0b)
9438+#endif
9439+
9440+ "sets %1\n"
9441 : "+m" (v->counter), "=qm" (c)
9442 : "ir" (i) : "memory");
9443 return c;
9444@@ -179,7 +341,7 @@ static inline int atomic_add_return(int i, atomic_t *v)
9445 goto no_xadd;
9446 #endif
9447 /* Modern 486+ processor */
9448- return i + xadd(&v->counter, i);
9449+ return i + xadd_check_overflow(&v->counter, i);
9450
9451 #ifdef CONFIG_M386
9452 no_xadd: /* Legacy 386 processor */
9453@@ -192,6 +354,34 @@ no_xadd: /* Legacy 386 processor */
9454 }
9455
9456 /**
9457+ * atomic_add_return_unchecked - add integer and return
9458+ * @i: integer value to add
9459+ * @v: pointer of type atomic_unchecked_t
9460+ *
9461+ * Atomically adds @i to @v and returns @i + @v
9462+ */
9463+static inline int atomic_add_return_unchecked(int i, atomic_unchecked_t *v)
9464+{
9465+#ifdef CONFIG_M386
9466+ int __i;
9467+ unsigned long flags;
9468+ if (unlikely(boot_cpu_data.x86 <= 3))
9469+ goto no_xadd;
9470+#endif
9471+ /* Modern 486+ processor */
9472+ return i + xadd(&v->counter, i);
9473+
9474+#ifdef CONFIG_M386
9475+no_xadd: /* Legacy 386 processor */
9476+ raw_local_irq_save(flags);
9477+ __i = atomic_read_unchecked(v);
9478+ atomic_set_unchecked(v, i + __i);
9479+ raw_local_irq_restore(flags);
9480+ return i + __i;
9481+#endif
9482+}
9483+
9484+/**
9485 * atomic_sub_return - subtract integer and return
9486 * @v: pointer of type atomic_t
9487 * @i: integer value to subtract
9488@@ -204,6 +394,10 @@ static inline int atomic_sub_return(int i, atomic_t *v)
9489 }
9490
9491 #define atomic_inc_return(v) (atomic_add_return(1, v))
9492+static inline int atomic_inc_return_unchecked(atomic_unchecked_t *v)
9493+{
9494+ return atomic_add_return_unchecked(1, v);
9495+}
9496 #define atomic_dec_return(v) (atomic_sub_return(1, v))
9497
9498 static inline int atomic_cmpxchg(atomic_t *v, int old, int new)
9499@@ -211,11 +405,21 @@ static inline int atomic_cmpxchg(atomic_t *v, int old, int new)
9500 return cmpxchg(&v->counter, old, new);
9501 }
9502
9503+static inline int atomic_cmpxchg_unchecked(atomic_unchecked_t *v, int old, int new)
9504+{
9505+ return cmpxchg(&v->counter, old, new);
9506+}
9507+
9508 static inline int atomic_xchg(atomic_t *v, int new)
9509 {
9510 return xchg(&v->counter, new);
9511 }
9512
9513+static inline int atomic_xchg_unchecked(atomic_unchecked_t *v, int new)
9514+{
9515+ return xchg(&v->counter, new);
9516+}
9517+
9518 /**
9519 * __atomic_add_unless - add unless the number is already a given value
9520 * @v: pointer of type atomic_t
9521@@ -227,12 +431,25 @@ static inline int atomic_xchg(atomic_t *v, int new)
9522 */
9523 static inline int __atomic_add_unless(atomic_t *v, int a, int u)
9524 {
9525- int c, old;
9526+ int c, old, new;
9527 c = atomic_read(v);
9528 for (;;) {
9529- if (unlikely(c == (u)))
9530+ if (unlikely(c == u))
9531 break;
9532- old = atomic_cmpxchg((v), c, c + (a));
9533+
9534+ asm volatile("addl %2,%0\n"
9535+
9536+#ifdef CONFIG_PAX_REFCOUNT
9537+ "jno 0f\n"
9538+ "subl %2,%0\n"
9539+ "int $4\n0:\n"
9540+ _ASM_EXTABLE(0b, 0b)
9541+#endif
9542+
9543+ : "=r" (new)
9544+ : "0" (c), "ir" (a));
9545+
9546+ old = atomic_cmpxchg(v, c, new);
9547 if (likely(old == c))
9548 break;
9549 c = old;
9550@@ -240,6 +457,48 @@ static inline int __atomic_add_unless(atomic_t *v, int a, int u)
9551 return c;
9552 }
9553
9554+/**
9555+ * atomic_inc_not_zero_hint - increment if not null
9556+ * @v: pointer of type atomic_t
9557+ * @hint: probable value of the atomic before the increment
9558+ *
9559+ * This version of atomic_inc_not_zero() gives a hint of probable
9560+ * value of the atomic. This helps processor to not read the memory
9561+ * before doing the atomic read/modify/write cycle, lowering
9562+ * number of bus transactions on some arches.
9563+ *
9564+ * Returns: 0 if increment was not done, 1 otherwise.
9565+ */
9566+#define atomic_inc_not_zero_hint atomic_inc_not_zero_hint
9567+static inline int atomic_inc_not_zero_hint(atomic_t *v, int hint)
9568+{
9569+ int val, c = hint, new;
9570+
9571+ /* sanity test, should be removed by compiler if hint is a constant */
9572+ if (!hint)
9573+ return __atomic_add_unless(v, 1, 0);
9574+
9575+ do {
9576+ asm volatile("incl %0\n"
9577+
9578+#ifdef CONFIG_PAX_REFCOUNT
9579+ "jno 0f\n"
9580+ "decl %0\n"
9581+ "int $4\n0:\n"
9582+ _ASM_EXTABLE(0b, 0b)
9583+#endif
9584+
9585+ : "=r" (new)
9586+ : "0" (c));
9587+
9588+ val = atomic_cmpxchg(v, c, new);
9589+ if (val == c)
9590+ return 1;
9591+ c = val;
9592+ } while (c);
9593+
9594+ return 0;
9595+}
9596
9597 /*
9598 * atomic_dec_if_positive - decrement by 1 if old value positive
9599@@ -293,14 +552,37 @@ static inline void atomic_or_long(unsigned long *v1, unsigned long v2)
9600 #endif
9601
9602 /* These are x86-specific, used by some header files */
9603-#define atomic_clear_mask(mask, addr) \
9604- asm volatile(LOCK_PREFIX "andl %0,%1" \
9605- : : "r" (~(mask)), "m" (*(addr)) : "memory")
9606+static inline void atomic_clear_mask(unsigned int mask, atomic_t *v)
9607+{
9608+ asm volatile(LOCK_PREFIX "andl %1,%0"
9609+ : "+m" (v->counter)
9610+ : "r" (~(mask))
9611+ : "memory");
9612+}
9613
9614-#define atomic_set_mask(mask, addr) \
9615- asm volatile(LOCK_PREFIX "orl %0,%1" \
9616- : : "r" ((unsigned)(mask)), "m" (*(addr)) \
9617- : "memory")
9618+static inline void atomic_clear_mask_unchecked(unsigned int mask, atomic_unchecked_t *v)
9619+{
9620+ asm volatile(LOCK_PREFIX "andl %1,%0"
9621+ : "+m" (v->counter)
9622+ : "r" (~(mask))
9623+ : "memory");
9624+}
9625+
9626+static inline void atomic_set_mask(unsigned int mask, atomic_t *v)
9627+{
9628+ asm volatile(LOCK_PREFIX "orl %1,%0"
9629+ : "+m" (v->counter)
9630+ : "r" (mask)
9631+ : "memory");
9632+}
9633+
9634+static inline void atomic_set_mask_unchecked(unsigned int mask, atomic_unchecked_t *v)
9635+{
9636+ asm volatile(LOCK_PREFIX "orl %1,%0"
9637+ : "+m" (v->counter)
9638+ : "r" (mask)
9639+ : "memory");
9640+}
9641
9642 /* Atomic operations are already serializing on x86 */
9643 #define smp_mb__before_atomic_dec() barrier()
9644diff --git a/arch/x86/include/asm/atomic64_32.h b/arch/x86/include/asm/atomic64_32.h
9645index b154de7..aadebd8 100644
9646--- a/arch/x86/include/asm/atomic64_32.h
9647+++ b/arch/x86/include/asm/atomic64_32.h
9648@@ -12,6 +12,14 @@ typedef struct {
9649 u64 __aligned(8) counter;
9650 } atomic64_t;
9651
9652+#ifdef CONFIG_PAX_REFCOUNT
9653+typedef struct {
9654+ u64 __aligned(8) counter;
9655+} atomic64_unchecked_t;
9656+#else
9657+typedef atomic64_t atomic64_unchecked_t;
9658+#endif
9659+
9660 #define ATOMIC64_INIT(val) { (val) }
9661
9662 #define __ATOMIC64_DECL(sym) void atomic64_##sym(atomic64_t *, ...)
9663@@ -37,21 +45,31 @@ typedef struct {
9664 ATOMIC64_DECL_ONE(sym##_386)
9665
9666 ATOMIC64_DECL_ONE(add_386);
9667+ATOMIC64_DECL_ONE(add_unchecked_386);
9668 ATOMIC64_DECL_ONE(sub_386);
9669+ATOMIC64_DECL_ONE(sub_unchecked_386);
9670 ATOMIC64_DECL_ONE(inc_386);
9671+ATOMIC64_DECL_ONE(inc_unchecked_386);
9672 ATOMIC64_DECL_ONE(dec_386);
9673+ATOMIC64_DECL_ONE(dec_unchecked_386);
9674 #endif
9675
9676 #define alternative_atomic64(f, out, in...) \
9677 __alternative_atomic64(f, f, ASM_OUTPUT2(out), ## in)
9678
9679 ATOMIC64_DECL(read);
9680+ATOMIC64_DECL(read_unchecked);
9681 ATOMIC64_DECL(set);
9682+ATOMIC64_DECL(set_unchecked);
9683 ATOMIC64_DECL(xchg);
9684 ATOMIC64_DECL(add_return);
9685+ATOMIC64_DECL(add_return_unchecked);
9686 ATOMIC64_DECL(sub_return);
9687+ATOMIC64_DECL(sub_return_unchecked);
9688 ATOMIC64_DECL(inc_return);
9689+ATOMIC64_DECL(inc_return_unchecked);
9690 ATOMIC64_DECL(dec_return);
9691+ATOMIC64_DECL(dec_return_unchecked);
9692 ATOMIC64_DECL(dec_if_positive);
9693 ATOMIC64_DECL(inc_not_zero);
9694 ATOMIC64_DECL(add_unless);
9695@@ -77,6 +95,21 @@ static inline long long atomic64_cmpxchg(atomic64_t *v, long long o, long long n
9696 }
9697
9698 /**
9699+ * atomic64_cmpxchg_unchecked - cmpxchg atomic64 variable
9700+ * @p: pointer to type atomic64_unchecked_t
9701+ * @o: expected value
9702+ * @n: new value
9703+ *
9704+ * Atomically sets @v to @n if it was equal to @o and returns
9705+ * the old value.
9706+ */
9707+
9708+static inline long long atomic64_cmpxchg_unchecked(atomic64_unchecked_t *v, long long o, long long n)
9709+{
9710+ return cmpxchg64(&v->counter, o, n);
9711+}
9712+
9713+/**
9714 * atomic64_xchg - xchg atomic64 variable
9715 * @v: pointer to type atomic64_t
9716 * @n: value to assign
9717@@ -112,6 +145,22 @@ static inline void atomic64_set(atomic64_t *v, long long i)
9718 }
9719
9720 /**
9721+ * atomic64_set_unchecked - set atomic64 variable
9722+ * @v: pointer to type atomic64_unchecked_t
9723+ * @n: value to assign
9724+ *
9725+ * Atomically sets the value of @v to @n.
9726+ */
9727+static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, long long i)
9728+{
9729+ unsigned high = (unsigned)(i >> 32);
9730+ unsigned low = (unsigned)i;
9731+ alternative_atomic64(set, /* no output */,
9732+ "S" (v), "b" (low), "c" (high)
9733+ : "eax", "edx", "memory");
9734+}
9735+
9736+/**
9737 * atomic64_read - read atomic64 variable
9738 * @v: pointer to type atomic64_t
9739 *
9740@@ -125,6 +174,19 @@ static inline long long atomic64_read(const atomic64_t *v)
9741 }
9742
9743 /**
9744+ * atomic64_read_unchecked - read atomic64 variable
9745+ * @v: pointer to type atomic64_unchecked_t
9746+ *
9747+ * Atomically reads the value of @v and returns it.
9748+ */
9749+static inline long long atomic64_read_unchecked(atomic64_unchecked_t *v)
9750+{
9751+ long long r;
9752+ alternative_atomic64(read, "=&A" (r), "c" (v) : "memory");
9753+ return r;
9754+ }
9755+
9756+/**
9757 * atomic64_add_return - add and return
9758 * @i: integer value to add
9759 * @v: pointer to type atomic64_t
9760@@ -139,6 +201,21 @@ static inline long long atomic64_add_return(long long i, atomic64_t *v)
9761 return i;
9762 }
9763
9764+/**
9765+ * atomic64_add_return_unchecked - add and return
9766+ * @i: integer value to add
9767+ * @v: pointer to type atomic64_unchecked_t
9768+ *
9769+ * Atomically adds @i to @v and returns @i + *@v
9770+ */
9771+static inline long long atomic64_add_return_unchecked(long long i, atomic64_unchecked_t *v)
9772+{
9773+ alternative_atomic64(add_return_unchecked,
9774+ ASM_OUTPUT2("+A" (i), "+c" (v)),
9775+ ASM_NO_INPUT_CLOBBER("memory"));
9776+ return i;
9777+}
9778+
9779 /*
9780 * Other variants with different arithmetic operators:
9781 */
9782@@ -158,6 +235,14 @@ static inline long long atomic64_inc_return(atomic64_t *v)
9783 return a;
9784 }
9785
9786+static inline long long atomic64_inc_return_unchecked(atomic64_unchecked_t *v)
9787+{
9788+ long long a;
9789+ alternative_atomic64(inc_return_unchecked, "=&A" (a),
9790+ "S" (v) : "memory", "ecx");
9791+ return a;
9792+}
9793+
9794 static inline long long atomic64_dec_return(atomic64_t *v)
9795 {
9796 long long a;
9797@@ -182,6 +267,21 @@ static inline long long atomic64_add(long long i, atomic64_t *v)
9798 }
9799
9800 /**
9801+ * atomic64_add_unchecked - add integer to atomic64 variable
9802+ * @i: integer value to add
9803+ * @v: pointer to type atomic64_unchecked_t
9804+ *
9805+ * Atomically adds @i to @v.
9806+ */
9807+static inline long long atomic64_add_unchecked(long long i, atomic64_unchecked_t *v)
9808+{
9809+ __alternative_atomic64(add_unchecked, add_return_unchecked,
9810+ ASM_OUTPUT2("+A" (i), "+c" (v)),
9811+ ASM_NO_INPUT_CLOBBER("memory"));
9812+ return i;
9813+}
9814+
9815+/**
9816 * atomic64_sub - subtract the atomic64 variable
9817 * @i: integer value to subtract
9818 * @v: pointer to type atomic64_t
9819diff --git a/arch/x86/include/asm/atomic64_64.h b/arch/x86/include/asm/atomic64_64.h
9820index 0e1cbfc..5623683 100644
9821--- a/arch/x86/include/asm/atomic64_64.h
9822+++ b/arch/x86/include/asm/atomic64_64.h
9823@@ -18,7 +18,19 @@
9824 */
9825 static inline long atomic64_read(const atomic64_t *v)
9826 {
9827- return (*(volatile long *)&(v)->counter);
9828+ return (*(volatile const long *)&(v)->counter);
9829+}
9830+
9831+/**
9832+ * atomic64_read_unchecked - read atomic64 variable
9833+ * @v: pointer of type atomic64_unchecked_t
9834+ *
9835+ * Atomically reads the value of @v.
9836+ * Doesn't imply a read memory barrier.
9837+ */
9838+static inline long atomic64_read_unchecked(const atomic64_unchecked_t *v)
9839+{
9840+ return (*(volatile const long *)&(v)->counter);
9841 }
9842
9843 /**
9844@@ -34,6 +46,18 @@ static inline void atomic64_set(atomic64_t *v, long i)
9845 }
9846
9847 /**
9848+ * atomic64_set_unchecked - set atomic64 variable
9849+ * @v: pointer to type atomic64_unchecked_t
9850+ * @i: required value
9851+ *
9852+ * Atomically sets the value of @v to @i.
9853+ */
9854+static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, long i)
9855+{
9856+ v->counter = i;
9857+}
9858+
9859+/**
9860 * atomic64_add - add integer to atomic64 variable
9861 * @i: integer value to add
9862 * @v: pointer to type atomic64_t
9863@@ -42,6 +66,28 @@ static inline void atomic64_set(atomic64_t *v, long i)
9864 */
9865 static inline void atomic64_add(long i, atomic64_t *v)
9866 {
9867+ asm volatile(LOCK_PREFIX "addq %1,%0\n"
9868+
9869+#ifdef CONFIG_PAX_REFCOUNT
9870+ "jno 0f\n"
9871+ LOCK_PREFIX "subq %1,%0\n"
9872+ "int $4\n0:\n"
9873+ _ASM_EXTABLE(0b, 0b)
9874+#endif
9875+
9876+ : "=m" (v->counter)
9877+ : "er" (i), "m" (v->counter));
9878+}
9879+
9880+/**
9881+ * atomic64_add_unchecked - add integer to atomic64 variable
9882+ * @i: integer value to add
9883+ * @v: pointer to type atomic64_unchecked_t
9884+ *
9885+ * Atomically adds @i to @v.
9886+ */
9887+static inline void atomic64_add_unchecked(long i, atomic64_unchecked_t *v)
9888+{
9889 asm volatile(LOCK_PREFIX "addq %1,%0"
9890 : "=m" (v->counter)
9891 : "er" (i), "m" (v->counter));
9892@@ -56,7 +102,29 @@ static inline void atomic64_add(long i, atomic64_t *v)
9893 */
9894 static inline void atomic64_sub(long i, atomic64_t *v)
9895 {
9896- asm volatile(LOCK_PREFIX "subq %1,%0"
9897+ asm volatile(LOCK_PREFIX "subq %1,%0\n"
9898+
9899+#ifdef CONFIG_PAX_REFCOUNT
9900+ "jno 0f\n"
9901+ LOCK_PREFIX "addq %1,%0\n"
9902+ "int $4\n0:\n"
9903+ _ASM_EXTABLE(0b, 0b)
9904+#endif
9905+
9906+ : "=m" (v->counter)
9907+ : "er" (i), "m" (v->counter));
9908+}
9909+
9910+/**
9911+ * atomic64_sub_unchecked - subtract the atomic64 variable
9912+ * @i: integer value to subtract
9913+ * @v: pointer to type atomic64_unchecked_t
9914+ *
9915+ * Atomically subtracts @i from @v.
9916+ */
9917+static inline void atomic64_sub_unchecked(long i, atomic64_unchecked_t *v)
9918+{
9919+ asm volatile(LOCK_PREFIX "subq %1,%0\n"
9920 : "=m" (v->counter)
9921 : "er" (i), "m" (v->counter));
9922 }
9923@@ -74,7 +142,16 @@ static inline int atomic64_sub_and_test(long i, atomic64_t *v)
9924 {
9925 unsigned char c;
9926
9927- asm volatile(LOCK_PREFIX "subq %2,%0; sete %1"
9928+ asm volatile(LOCK_PREFIX "subq %2,%0\n"
9929+
9930+#ifdef CONFIG_PAX_REFCOUNT
9931+ "jno 0f\n"
9932+ LOCK_PREFIX "addq %2,%0\n"
9933+ "int $4\n0:\n"
9934+ _ASM_EXTABLE(0b, 0b)
9935+#endif
9936+
9937+ "sete %1\n"
9938 : "=m" (v->counter), "=qm" (c)
9939 : "er" (i), "m" (v->counter) : "memory");
9940 return c;
9941@@ -88,6 +165,27 @@ static inline int atomic64_sub_and_test(long i, atomic64_t *v)
9942 */
9943 static inline void atomic64_inc(atomic64_t *v)
9944 {
9945+ asm volatile(LOCK_PREFIX "incq %0\n"
9946+
9947+#ifdef CONFIG_PAX_REFCOUNT
9948+ "jno 0f\n"
9949+ LOCK_PREFIX "decq %0\n"
9950+ "int $4\n0:\n"
9951+ _ASM_EXTABLE(0b, 0b)
9952+#endif
9953+
9954+ : "=m" (v->counter)
9955+ : "m" (v->counter));
9956+}
9957+
9958+/**
9959+ * atomic64_inc_unchecked - increment atomic64 variable
9960+ * @v: pointer to type atomic64_unchecked_t
9961+ *
9962+ * Atomically increments @v by 1.
9963+ */
9964+static inline void atomic64_inc_unchecked(atomic64_unchecked_t *v)
9965+{
9966 asm volatile(LOCK_PREFIX "incq %0"
9967 : "=m" (v->counter)
9968 : "m" (v->counter));
9969@@ -101,7 +199,28 @@ static inline void atomic64_inc(atomic64_t *v)
9970 */
9971 static inline void atomic64_dec(atomic64_t *v)
9972 {
9973- asm volatile(LOCK_PREFIX "decq %0"
9974+ asm volatile(LOCK_PREFIX "decq %0\n"
9975+
9976+#ifdef CONFIG_PAX_REFCOUNT
9977+ "jno 0f\n"
9978+ LOCK_PREFIX "incq %0\n"
9979+ "int $4\n0:\n"
9980+ _ASM_EXTABLE(0b, 0b)
9981+#endif
9982+
9983+ : "=m" (v->counter)
9984+ : "m" (v->counter));
9985+}
9986+
9987+/**
9988+ * atomic64_dec_unchecked - decrement atomic64 variable
9989+ * @v: pointer to type atomic64_t
9990+ *
9991+ * Atomically decrements @v by 1.
9992+ */
9993+static inline void atomic64_dec_unchecked(atomic64_unchecked_t *v)
9994+{
9995+ asm volatile(LOCK_PREFIX "decq %0\n"
9996 : "=m" (v->counter)
9997 : "m" (v->counter));
9998 }
9999@@ -118,7 +237,16 @@ static inline int atomic64_dec_and_test(atomic64_t *v)
10000 {
10001 unsigned char c;
10002
10003- asm volatile(LOCK_PREFIX "decq %0; sete %1"
10004+ asm volatile(LOCK_PREFIX "decq %0\n"
10005+
10006+#ifdef CONFIG_PAX_REFCOUNT
10007+ "jno 0f\n"
10008+ LOCK_PREFIX "incq %0\n"
10009+ "int $4\n0:\n"
10010+ _ASM_EXTABLE(0b, 0b)
10011+#endif
10012+
10013+ "sete %1\n"
10014 : "=m" (v->counter), "=qm" (c)
10015 : "m" (v->counter) : "memory");
10016 return c != 0;
10017@@ -136,7 +264,16 @@ static inline int atomic64_inc_and_test(atomic64_t *v)
10018 {
10019 unsigned char c;
10020
10021- asm volatile(LOCK_PREFIX "incq %0; sete %1"
10022+ asm volatile(LOCK_PREFIX "incq %0\n"
10023+
10024+#ifdef CONFIG_PAX_REFCOUNT
10025+ "jno 0f\n"
10026+ LOCK_PREFIX "decq %0\n"
10027+ "int $4\n0:\n"
10028+ _ASM_EXTABLE(0b, 0b)
10029+#endif
10030+
10031+ "sete %1\n"
10032 : "=m" (v->counter), "=qm" (c)
10033 : "m" (v->counter) : "memory");
10034 return c != 0;
10035@@ -155,7 +292,16 @@ static inline int atomic64_add_negative(long i, atomic64_t *v)
10036 {
10037 unsigned char c;
10038
10039- asm volatile(LOCK_PREFIX "addq %2,%0; sets %1"
10040+ asm volatile(LOCK_PREFIX "addq %2,%0\n"
10041+
10042+#ifdef CONFIG_PAX_REFCOUNT
10043+ "jno 0f\n"
10044+ LOCK_PREFIX "subq %2,%0\n"
10045+ "int $4\n0:\n"
10046+ _ASM_EXTABLE(0b, 0b)
10047+#endif
10048+
10049+ "sets %1\n"
10050 : "=m" (v->counter), "=qm" (c)
10051 : "er" (i), "m" (v->counter) : "memory");
10052 return c;
10053@@ -170,6 +316,18 @@ static inline int atomic64_add_negative(long i, atomic64_t *v)
10054 */
10055 static inline long atomic64_add_return(long i, atomic64_t *v)
10056 {
10057+ return i + xadd_check_overflow(&v->counter, i);
10058+}
10059+
10060+/**
10061+ * atomic64_add_return_unchecked - add and return
10062+ * @i: integer value to add
10063+ * @v: pointer to type atomic64_unchecked_t
10064+ *
10065+ * Atomically adds @i to @v and returns @i + @v
10066+ */
10067+static inline long atomic64_add_return_unchecked(long i, atomic64_unchecked_t *v)
10068+{
10069 return i + xadd(&v->counter, i);
10070 }
10071
10072@@ -179,6 +337,10 @@ static inline long atomic64_sub_return(long i, atomic64_t *v)
10073 }
10074
10075 #define atomic64_inc_return(v) (atomic64_add_return(1, (v)))
10076+static inline long atomic64_inc_return_unchecked(atomic64_unchecked_t *v)
10077+{
10078+ return atomic64_add_return_unchecked(1, v);
10079+}
10080 #define atomic64_dec_return(v) (atomic64_sub_return(1, (v)))
10081
10082 static inline long atomic64_cmpxchg(atomic64_t *v, long old, long new)
10083@@ -186,6 +348,11 @@ static inline long atomic64_cmpxchg(atomic64_t *v, long old, long new)
10084 return cmpxchg(&v->counter, old, new);
10085 }
10086
10087+static inline long atomic64_cmpxchg_unchecked(atomic64_unchecked_t *v, long old, long new)
10088+{
10089+ return cmpxchg(&v->counter, old, new);
10090+}
10091+
10092 static inline long atomic64_xchg(atomic64_t *v, long new)
10093 {
10094 return xchg(&v->counter, new);
10095@@ -202,17 +369,30 @@ static inline long atomic64_xchg(atomic64_t *v, long new)
10096 */
10097 static inline int atomic64_add_unless(atomic64_t *v, long a, long u)
10098 {
10099- long c, old;
10100+ long c, old, new;
10101 c = atomic64_read(v);
10102 for (;;) {
10103- if (unlikely(c == (u)))
10104+ if (unlikely(c == u))
10105 break;
10106- old = atomic64_cmpxchg((v), c, c + (a));
10107+
10108+ asm volatile("add %2,%0\n"
10109+
10110+#ifdef CONFIG_PAX_REFCOUNT
10111+ "jno 0f\n"
10112+ "sub %2,%0\n"
10113+ "int $4\n0:\n"
10114+ _ASM_EXTABLE(0b, 0b)
10115+#endif
10116+
10117+ : "=r" (new)
10118+ : "0" (c), "ir" (a));
10119+
10120+ old = atomic64_cmpxchg(v, c, new);
10121 if (likely(old == c))
10122 break;
10123 c = old;
10124 }
10125- return c != (u);
10126+ return c != u;
10127 }
10128
10129 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
10130diff --git a/arch/x86/include/asm/bitops.h b/arch/x86/include/asm/bitops.h
10131index 72f5009..2f8b9a9 100644
10132--- a/arch/x86/include/asm/bitops.h
10133+++ b/arch/x86/include/asm/bitops.h
10134@@ -40,7 +40,7 @@
10135 * a mask operation on a byte.
10136 */
10137 #define IS_IMMEDIATE(nr) (__builtin_constant_p(nr))
10138-#define CONST_MASK_ADDR(nr, addr) BITOP_ADDR((void *)(addr) + ((nr)>>3))
10139+#define CONST_MASK_ADDR(nr, addr) BITOP_ADDR((volatile void *)(addr) + ((nr)>>3))
10140 #define CONST_MASK(nr) (1 << ((nr) & 7))
10141
10142 /**
10143diff --git a/arch/x86/include/asm/boot.h b/arch/x86/include/asm/boot.h
10144index b13fe63..0dab13a 100644
10145--- a/arch/x86/include/asm/boot.h
10146+++ b/arch/x86/include/asm/boot.h
10147@@ -11,10 +11,15 @@
10148 #include <asm/pgtable_types.h>
10149
10150 /* Physical address where kernel should be loaded. */
10151-#define LOAD_PHYSICAL_ADDR ((CONFIG_PHYSICAL_START \
10152+#define ____LOAD_PHYSICAL_ADDR ((CONFIG_PHYSICAL_START \
10153 + (CONFIG_PHYSICAL_ALIGN - 1)) \
10154 & ~(CONFIG_PHYSICAL_ALIGN - 1))
10155
10156+#ifndef __ASSEMBLY__
10157+extern unsigned char __LOAD_PHYSICAL_ADDR[];
10158+#define LOAD_PHYSICAL_ADDR ((unsigned long)__LOAD_PHYSICAL_ADDR)
10159+#endif
10160+
10161 /* Minimum kernel alignment, as a power of two */
10162 #ifdef CONFIG_X86_64
10163 #define MIN_KERNEL_ALIGN_LG2 PMD_SHIFT
10164diff --git a/arch/x86/include/asm/cache.h b/arch/x86/include/asm/cache.h
10165index 48f99f1..d78ebf9 100644
10166--- a/arch/x86/include/asm/cache.h
10167+++ b/arch/x86/include/asm/cache.h
10168@@ -5,12 +5,13 @@
10169
10170 /* L1 cache line size */
10171 #define L1_CACHE_SHIFT (CONFIG_X86_L1_CACHE_SHIFT)
10172-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
10173+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
10174
10175 #define __read_mostly __attribute__((__section__(".data..read_mostly")))
10176+#define __read_only __attribute__((__section__(".data..read_only")))
10177
10178 #define INTERNODE_CACHE_SHIFT CONFIG_X86_INTERNODE_CACHE_SHIFT
10179-#define INTERNODE_CACHE_BYTES (1 << INTERNODE_CACHE_SHIFT)
10180+#define INTERNODE_CACHE_BYTES (_AC(1,UL) << INTERNODE_CACHE_SHIFT)
10181
10182 #ifdef CONFIG_X86_VSMP
10183 #ifdef CONFIG_SMP
10184diff --git a/arch/x86/include/asm/cacheflush.h b/arch/x86/include/asm/cacheflush.h
10185index 9863ee3..4a1f8e1 100644
10186--- a/arch/x86/include/asm/cacheflush.h
10187+++ b/arch/x86/include/asm/cacheflush.h
10188@@ -27,7 +27,7 @@ static inline unsigned long get_page_memtype(struct page *pg)
10189 unsigned long pg_flags = pg->flags & _PGMT_MASK;
10190
10191 if (pg_flags == _PGMT_DEFAULT)
10192- return -1;
10193+ return ~0UL;
10194 else if (pg_flags == _PGMT_WC)
10195 return _PAGE_CACHE_WC;
10196 else if (pg_flags == _PGMT_UC_MINUS)
10197diff --git a/arch/x86/include/asm/checksum_32.h b/arch/x86/include/asm/checksum_32.h
10198index 46fc474..b02b0f9 100644
10199--- a/arch/x86/include/asm/checksum_32.h
10200+++ b/arch/x86/include/asm/checksum_32.h
10201@@ -31,6 +31,14 @@ asmlinkage __wsum csum_partial_copy_generic(const void *src, void *dst,
10202 int len, __wsum sum,
10203 int *src_err_ptr, int *dst_err_ptr);
10204
10205+asmlinkage __wsum csum_partial_copy_generic_to_user(const void *src, void *dst,
10206+ int len, __wsum sum,
10207+ int *src_err_ptr, int *dst_err_ptr);
10208+
10209+asmlinkage __wsum csum_partial_copy_generic_from_user(const void *src, void *dst,
10210+ int len, __wsum sum,
10211+ int *src_err_ptr, int *dst_err_ptr);
10212+
10213 /*
10214 * Note: when you get a NULL pointer exception here this means someone
10215 * passed in an incorrect kernel address to one of these functions.
10216@@ -50,7 +58,7 @@ static inline __wsum csum_partial_copy_from_user(const void __user *src,
10217 int *err_ptr)
10218 {
10219 might_sleep();
10220- return csum_partial_copy_generic((__force void *)src, dst,
10221+ return csum_partial_copy_generic_from_user((__force void *)src, dst,
10222 len, sum, err_ptr, NULL);
10223 }
10224
10225@@ -178,7 +186,7 @@ static inline __wsum csum_and_copy_to_user(const void *src,
10226 {
10227 might_sleep();
10228 if (access_ok(VERIFY_WRITE, dst, len))
10229- return csum_partial_copy_generic(src, (__force void *)dst,
10230+ return csum_partial_copy_generic_to_user(src, (__force void *)dst,
10231 len, sum, NULL, err_ptr);
10232
10233 if (len)
10234diff --git a/arch/x86/include/asm/cmpxchg.h b/arch/x86/include/asm/cmpxchg.h
10235index 99480e5..d81165b 100644
10236--- a/arch/x86/include/asm/cmpxchg.h
10237+++ b/arch/x86/include/asm/cmpxchg.h
10238@@ -14,8 +14,12 @@ extern void __cmpxchg_wrong_size(void)
10239 __compiletime_error("Bad argument size for cmpxchg");
10240 extern void __xadd_wrong_size(void)
10241 __compiletime_error("Bad argument size for xadd");
10242+extern void __xadd_check_overflow_wrong_size(void)
10243+ __compiletime_error("Bad argument size for xadd_check_overflow");
10244 extern void __add_wrong_size(void)
10245 __compiletime_error("Bad argument size for add");
10246+extern void __add_check_overflow_wrong_size(void)
10247+ __compiletime_error("Bad argument size for add_check_overflow");
10248
10249 /*
10250 * Constants for operation sizes. On 32-bit, the 64-bit size it set to
10251@@ -67,6 +71,34 @@ extern void __add_wrong_size(void)
10252 __ret; \
10253 })
10254
10255+#define __xchg_op_check_overflow(ptr, arg, op, lock) \
10256+ ({ \
10257+ __typeof__ (*(ptr)) __ret = (arg); \
10258+ switch (sizeof(*(ptr))) { \
10259+ case __X86_CASE_L: \
10260+ asm volatile (lock #op "l %0, %1\n" \
10261+ "jno 0f\n" \
10262+ "mov %0,%1\n" \
10263+ "int $4\n0:\n" \
10264+ _ASM_EXTABLE(0b, 0b) \
10265+ : "+r" (__ret), "+m" (*(ptr)) \
10266+ : : "memory", "cc"); \
10267+ break; \
10268+ case __X86_CASE_Q: \
10269+ asm volatile (lock #op "q %q0, %1\n" \
10270+ "jno 0f\n" \
10271+ "mov %0,%1\n" \
10272+ "int $4\n0:\n" \
10273+ _ASM_EXTABLE(0b, 0b) \
10274+ : "+r" (__ret), "+m" (*(ptr)) \
10275+ : : "memory", "cc"); \
10276+ break; \
10277+ default: \
10278+ __ ## op ## _check_overflow_wrong_size(); \
10279+ } \
10280+ __ret; \
10281+ })
10282+
10283 /*
10284 * Note: no "lock" prefix even on SMP: xchg always implies lock anyway.
10285 * Since this is generally used to protect other memory information, we
10286@@ -167,6 +199,9 @@ extern void __add_wrong_size(void)
10287 #define xadd_sync(ptr, inc) __xadd((ptr), (inc), "lock; ")
10288 #define xadd_local(ptr, inc) __xadd((ptr), (inc), "")
10289
10290+#define __xadd_check_overflow(ptr, inc, lock) __xchg_op_check_overflow((ptr), (inc), xadd, lock)
10291+#define xadd_check_overflow(ptr, inc) __xadd_check_overflow((ptr), (inc), LOCK_PREFIX)
10292+
10293 #define __add(ptr, inc, lock) \
10294 ({ \
10295 __typeof__ (*(ptr)) __ret = (inc); \
10296diff --git a/arch/x86/include/asm/cpufeature.h b/arch/x86/include/asm/cpufeature.h
10297index 6b7ee5f..9d664b3 100644
10298--- a/arch/x86/include/asm/cpufeature.h
10299+++ b/arch/x86/include/asm/cpufeature.h
10300@@ -202,13 +202,14 @@
10301 #define X86_FEATURE_BMI1 (9*32+ 3) /* 1st group bit manipulation extensions */
10302 #define X86_FEATURE_HLE (9*32+ 4) /* Hardware Lock Elision */
10303 #define X86_FEATURE_AVX2 (9*32+ 5) /* AVX2 instructions */
10304-#define X86_FEATURE_SMEP (9*32+ 7) /* Supervisor Mode Execution Protection */
10305+#define X86_FEATURE_SMEP (9*32+ 7) /* Supervisor Mode Execution Prevention */
10306 #define X86_FEATURE_BMI2 (9*32+ 8) /* 2nd group bit manipulation extensions */
10307 #define X86_FEATURE_ERMS (9*32+ 9) /* Enhanced REP MOVSB/STOSB */
10308 #define X86_FEATURE_INVPCID (9*32+10) /* Invalidate Processor Context ID */
10309 #define X86_FEATURE_RTM (9*32+11) /* Restricted Transactional Memory */
10310 #define X86_FEATURE_RDSEED (9*32+18) /* The RDSEED instruction */
10311 #define X86_FEATURE_ADX (9*32+19) /* The ADCX and ADOX instructions */
10312+#define X86_FEATURE_SMAP (9*32+20) /* Supervisor Mode Access Prevention */
10313
10314 #if defined(__KERNEL__) && !defined(__ASSEMBLY__)
10315
10316@@ -373,7 +374,7 @@ static __always_inline __pure bool __static_cpu_has(u16 bit)
10317 ".section .discard,\"aw\",@progbits\n"
10318 " .byte 0xff + (4f-3f) - (2b-1b)\n" /* size check */
10319 ".previous\n"
10320- ".section .altinstr_replacement,\"ax\"\n"
10321+ ".section .altinstr_replacement,\"a\"\n"
10322 "3: movb $1,%0\n"
10323 "4:\n"
10324 ".previous\n"
10325diff --git a/arch/x86/include/asm/desc.h b/arch/x86/include/asm/desc.h
10326index 8bf1c06..f723dfd 100644
10327--- a/arch/x86/include/asm/desc.h
10328+++ b/arch/x86/include/asm/desc.h
10329@@ -4,6 +4,7 @@
10330 #include <asm/desc_defs.h>
10331 #include <asm/ldt.h>
10332 #include <asm/mmu.h>
10333+#include <asm/pgtable.h>
10334
10335 #include <linux/smp.h>
10336 #include <linux/percpu.h>
10337@@ -17,6 +18,7 @@ static inline void fill_ldt(struct desc_struct *desc, const struct user_desc *in
10338
10339 desc->type = (info->read_exec_only ^ 1) << 1;
10340 desc->type |= info->contents << 2;
10341+ desc->type |= info->seg_not_present ^ 1;
10342
10343 desc->s = 1;
10344 desc->dpl = 0x3;
10345@@ -35,19 +37,14 @@ static inline void fill_ldt(struct desc_struct *desc, const struct user_desc *in
10346 }
10347
10348 extern struct desc_ptr idt_descr;
10349-extern gate_desc idt_table[];
10350 extern struct desc_ptr nmi_idt_descr;
10351-extern gate_desc nmi_idt_table[];
10352-
10353-struct gdt_page {
10354- struct desc_struct gdt[GDT_ENTRIES];
10355-} __attribute__((aligned(PAGE_SIZE)));
10356-
10357-DECLARE_PER_CPU_PAGE_ALIGNED(struct gdt_page, gdt_page);
10358+extern gate_desc idt_table[256];
10359+extern gate_desc nmi_idt_table[256];
10360
10361+extern struct desc_struct cpu_gdt_table[NR_CPUS][PAGE_SIZE / sizeof(struct desc_struct)];
10362 static inline struct desc_struct *get_cpu_gdt_table(unsigned int cpu)
10363 {
10364- return per_cpu(gdt_page, cpu).gdt;
10365+ return cpu_gdt_table[cpu];
10366 }
10367
10368 #ifdef CONFIG_X86_64
10369@@ -72,8 +69,14 @@ static inline void pack_gate(gate_desc *gate, unsigned char type,
10370 unsigned long base, unsigned dpl, unsigned flags,
10371 unsigned short seg)
10372 {
10373- gate->a = (seg << 16) | (base & 0xffff);
10374- gate->b = (base & 0xffff0000) | (((0x80 | type | (dpl << 5)) & 0xff) << 8);
10375+ gate->gate.offset_low = base;
10376+ gate->gate.seg = seg;
10377+ gate->gate.reserved = 0;
10378+ gate->gate.type = type;
10379+ gate->gate.s = 0;
10380+ gate->gate.dpl = dpl;
10381+ gate->gate.p = 1;
10382+ gate->gate.offset_high = base >> 16;
10383 }
10384
10385 #endif
10386@@ -118,12 +121,16 @@ static inline void paravirt_free_ldt(struct desc_struct *ldt, unsigned entries)
10387
10388 static inline void native_write_idt_entry(gate_desc *idt, int entry, const gate_desc *gate)
10389 {
10390+ pax_open_kernel();
10391 memcpy(&idt[entry], gate, sizeof(*gate));
10392+ pax_close_kernel();
10393 }
10394
10395 static inline void native_write_ldt_entry(struct desc_struct *ldt, int entry, const void *desc)
10396 {
10397+ pax_open_kernel();
10398 memcpy(&ldt[entry], desc, 8);
10399+ pax_close_kernel();
10400 }
10401
10402 static inline void
10403@@ -137,7 +144,9 @@ native_write_gdt_entry(struct desc_struct *gdt, int entry, const void *desc, int
10404 default: size = sizeof(*gdt); break;
10405 }
10406
10407+ pax_open_kernel();
10408 memcpy(&gdt[entry], desc, size);
10409+ pax_close_kernel();
10410 }
10411
10412 static inline void pack_descriptor(struct desc_struct *desc, unsigned long base,
10413@@ -210,7 +219,9 @@ static inline void native_set_ldt(const void *addr, unsigned int entries)
10414
10415 static inline void native_load_tr_desc(void)
10416 {
10417+ pax_open_kernel();
10418 asm volatile("ltr %w0"::"q" (GDT_ENTRY_TSS*8));
10419+ pax_close_kernel();
10420 }
10421
10422 static inline void native_load_gdt(const struct desc_ptr *dtr)
10423@@ -247,8 +258,10 @@ static inline void native_load_tls(struct thread_struct *t, unsigned int cpu)
10424 struct desc_struct *gdt = get_cpu_gdt_table(cpu);
10425 unsigned int i;
10426
10427+ pax_open_kernel();
10428 for (i = 0; i < GDT_ENTRY_TLS_ENTRIES; i++)
10429 gdt[GDT_ENTRY_TLS_MIN + i] = t->tls_array[i];
10430+ pax_close_kernel();
10431 }
10432
10433 #define _LDT_empty(info) \
10434@@ -311,7 +324,7 @@ static inline void set_desc_limit(struct desc_struct *desc, unsigned long limit)
10435 }
10436
10437 #ifdef CONFIG_X86_64
10438-static inline void set_nmi_gate(int gate, void *addr)
10439+static inline void set_nmi_gate(int gate, const void *addr)
10440 {
10441 gate_desc s;
10442
10443@@ -320,7 +333,7 @@ static inline void set_nmi_gate(int gate, void *addr)
10444 }
10445 #endif
10446
10447-static inline void _set_gate(int gate, unsigned type, void *addr,
10448+static inline void _set_gate(int gate, unsigned type, const void *addr,
10449 unsigned dpl, unsigned ist, unsigned seg)
10450 {
10451 gate_desc s;
10452@@ -339,7 +352,7 @@ static inline void _set_gate(int gate, unsigned type, void *addr,
10453 * Pentium F0 0F bugfix can have resulted in the mapped
10454 * IDT being write-protected.
10455 */
10456-static inline void set_intr_gate(unsigned int n, void *addr)
10457+static inline void set_intr_gate(unsigned int n, const void *addr)
10458 {
10459 BUG_ON((unsigned)n > 0xFF);
10460 _set_gate(n, GATE_INTERRUPT, addr, 0, 0, __KERNEL_CS);
10461@@ -369,19 +382,19 @@ static inline void alloc_intr_gate(unsigned int n, void *addr)
10462 /*
10463 * This routine sets up an interrupt gate at directory privilege level 3.
10464 */
10465-static inline void set_system_intr_gate(unsigned int n, void *addr)
10466+static inline void set_system_intr_gate(unsigned int n, const void *addr)
10467 {
10468 BUG_ON((unsigned)n > 0xFF);
10469 _set_gate(n, GATE_INTERRUPT, addr, 0x3, 0, __KERNEL_CS);
10470 }
10471
10472-static inline void set_system_trap_gate(unsigned int n, void *addr)
10473+static inline void set_system_trap_gate(unsigned int n, const void *addr)
10474 {
10475 BUG_ON((unsigned)n > 0xFF);
10476 _set_gate(n, GATE_TRAP, addr, 0x3, 0, __KERNEL_CS);
10477 }
10478
10479-static inline void set_trap_gate(unsigned int n, void *addr)
10480+static inline void set_trap_gate(unsigned int n, const void *addr)
10481 {
10482 BUG_ON((unsigned)n > 0xFF);
10483 _set_gate(n, GATE_TRAP, addr, 0, 0, __KERNEL_CS);
10484@@ -390,19 +403,31 @@ static inline void set_trap_gate(unsigned int n, void *addr)
10485 static inline void set_task_gate(unsigned int n, unsigned int gdt_entry)
10486 {
10487 BUG_ON((unsigned)n > 0xFF);
10488- _set_gate(n, GATE_TASK, (void *)0, 0, 0, (gdt_entry<<3));
10489+ _set_gate(n, GATE_TASK, (const void *)0, 0, 0, (gdt_entry<<3));
10490 }
10491
10492-static inline void set_intr_gate_ist(int n, void *addr, unsigned ist)
10493+static inline void set_intr_gate_ist(int n, const void *addr, unsigned ist)
10494 {
10495 BUG_ON((unsigned)n > 0xFF);
10496 _set_gate(n, GATE_INTERRUPT, addr, 0, ist, __KERNEL_CS);
10497 }
10498
10499-static inline void set_system_intr_gate_ist(int n, void *addr, unsigned ist)
10500+static inline void set_system_intr_gate_ist(int n, const void *addr, unsigned ist)
10501 {
10502 BUG_ON((unsigned)n > 0xFF);
10503 _set_gate(n, GATE_INTERRUPT, addr, 0x3, ist, __KERNEL_CS);
10504 }
10505
10506+#ifdef CONFIG_X86_32
10507+static inline void set_user_cs(unsigned long base, unsigned long limit, int cpu)
10508+{
10509+ struct desc_struct d;
10510+
10511+ if (likely(limit))
10512+ limit = (limit - 1UL) >> PAGE_SHIFT;
10513+ pack_descriptor(&d, base, limit, 0xFB, 0xC);
10514+ write_gdt_entry(get_cpu_gdt_table(cpu), GDT_ENTRY_DEFAULT_USER_CS, &d, DESCTYPE_S);
10515+}
10516+#endif
10517+
10518 #endif /* _ASM_X86_DESC_H */
10519diff --git a/arch/x86/include/asm/desc_defs.h b/arch/x86/include/asm/desc_defs.h
10520index 278441f..b95a174 100644
10521--- a/arch/x86/include/asm/desc_defs.h
10522+++ b/arch/x86/include/asm/desc_defs.h
10523@@ -31,6 +31,12 @@ struct desc_struct {
10524 unsigned base1: 8, type: 4, s: 1, dpl: 2, p: 1;
10525 unsigned limit: 4, avl: 1, l: 1, d: 1, g: 1, base2: 8;
10526 };
10527+ struct {
10528+ u16 offset_low;
10529+ u16 seg;
10530+ unsigned reserved: 8, type: 4, s: 1, dpl: 2, p: 1;
10531+ unsigned offset_high: 16;
10532+ } gate;
10533 };
10534 } __attribute__((packed));
10535
10536diff --git a/arch/x86/include/asm/e820.h b/arch/x86/include/asm/e820.h
10537index 3778256..c5d4fce 100644
10538--- a/arch/x86/include/asm/e820.h
10539+++ b/arch/x86/include/asm/e820.h
10540@@ -69,7 +69,7 @@ struct e820map {
10541 #define ISA_START_ADDRESS 0xa0000
10542 #define ISA_END_ADDRESS 0x100000
10543
10544-#define BIOS_BEGIN 0x000a0000
10545+#define BIOS_BEGIN 0x000c0000
10546 #define BIOS_END 0x00100000
10547
10548 #define BIOS_ROM_BASE 0xffe00000
10549diff --git a/arch/x86/include/asm/elf.h b/arch/x86/include/asm/elf.h
10550index 5939f44..f8845f6 100644
10551--- a/arch/x86/include/asm/elf.h
10552+++ b/arch/x86/include/asm/elf.h
10553@@ -243,7 +243,25 @@ extern int force_personality32;
10554 the loader. We need to make sure that it is out of the way of the program
10555 that it will "exec", and that there is sufficient room for the brk. */
10556
10557+#ifdef CONFIG_PAX_SEGMEXEC
10558+#define ELF_ET_DYN_BASE ((current->mm->pax_flags & MF_PAX_SEGMEXEC) ? SEGMEXEC_TASK_SIZE/3*2 : TASK_SIZE/3*2)
10559+#else
10560 #define ELF_ET_DYN_BASE (TASK_SIZE / 3 * 2)
10561+#endif
10562+
10563+#ifdef CONFIG_PAX_ASLR
10564+#ifdef CONFIG_X86_32
10565+#define PAX_ELF_ET_DYN_BASE 0x10000000UL
10566+
10567+#define PAX_DELTA_MMAP_LEN (current->mm->pax_flags & MF_PAX_SEGMEXEC ? 15 : 16)
10568+#define PAX_DELTA_STACK_LEN (current->mm->pax_flags & MF_PAX_SEGMEXEC ? 15 : 16)
10569+#else
10570+#define PAX_ELF_ET_DYN_BASE 0x400000UL
10571+
10572+#define PAX_DELTA_MMAP_LEN ((test_thread_flag(TIF_ADDR32)) ? 16 : TASK_SIZE_MAX_SHIFT - PAGE_SHIFT - 3)
10573+#define PAX_DELTA_STACK_LEN ((test_thread_flag(TIF_ADDR32)) ? 16 : TASK_SIZE_MAX_SHIFT - PAGE_SHIFT - 3)
10574+#endif
10575+#endif
10576
10577 /* This yields a mask that user programs can use to figure out what
10578 instruction set this CPU supports. This could be done in user space,
10579@@ -296,16 +314,12 @@ do { \
10580
10581 #define ARCH_DLINFO \
10582 do { \
10583- if (vdso_enabled) \
10584- NEW_AUX_ENT(AT_SYSINFO_EHDR, \
10585- (unsigned long)current->mm->context.vdso); \
10586+ NEW_AUX_ENT(AT_SYSINFO_EHDR, current->mm->context.vdso); \
10587 } while (0)
10588
10589 #define ARCH_DLINFO_X32 \
10590 do { \
10591- if (vdso_enabled) \
10592- NEW_AUX_ENT(AT_SYSINFO_EHDR, \
10593- (unsigned long)current->mm->context.vdso); \
10594+ NEW_AUX_ENT(AT_SYSINFO_EHDR, current->mm->context.vdso); \
10595 } while (0)
10596
10597 #define AT_SYSINFO 32
10598@@ -320,7 +334,7 @@ else \
10599
10600 #endif /* !CONFIG_X86_32 */
10601
10602-#define VDSO_CURRENT_BASE ((unsigned long)current->mm->context.vdso)
10603+#define VDSO_CURRENT_BASE (current->mm->context.vdso)
10604
10605 #define VDSO_ENTRY \
10606 ((unsigned long)VDSO32_SYMBOL(VDSO_CURRENT_BASE, vsyscall))
10607@@ -336,9 +350,6 @@ extern int x32_setup_additional_pages(struct linux_binprm *bprm,
10608 extern int syscall32_setup_pages(struct linux_binprm *, int exstack);
10609 #define compat_arch_setup_additional_pages syscall32_setup_pages
10610
10611-extern unsigned long arch_randomize_brk(struct mm_struct *mm);
10612-#define arch_randomize_brk arch_randomize_brk
10613-
10614 /*
10615 * True on X86_32 or when emulating IA32 on X86_64
10616 */
10617diff --git a/arch/x86/include/asm/emergency-restart.h b/arch/x86/include/asm/emergency-restart.h
10618index 75ce3f4..882e801 100644
10619--- a/arch/x86/include/asm/emergency-restart.h
10620+++ b/arch/x86/include/asm/emergency-restart.h
10621@@ -13,6 +13,6 @@ enum reboot_type {
10622
10623 extern enum reboot_type reboot_type;
10624
10625-extern void machine_emergency_restart(void);
10626+extern void machine_emergency_restart(void) __noreturn;
10627
10628 #endif /* _ASM_X86_EMERGENCY_RESTART_H */
10629diff --git a/arch/x86/include/asm/fpu-internal.h b/arch/x86/include/asm/fpu-internal.h
10630index 75f4c6d..70e60c0 100644
10631--- a/arch/x86/include/asm/fpu-internal.h
10632+++ b/arch/x86/include/asm/fpu-internal.h
10633@@ -82,10 +82,12 @@ static inline void sanitize_i387_state(struct task_struct *tsk)
10634 }
10635
10636 #ifdef CONFIG_X86_64
10637-static inline int fxrstor_checking(struct i387_fxsave_struct *fx)
10638+static inline int fxrstor_checking(struct i387_fxsave_struct __user *fx)
10639 {
10640 int err;
10641
10642+ fx = (struct i387_fxsave_struct __user *)____m(fx);
10643+
10644 /* See comment in fxsave() below. */
10645 #ifdef CONFIG_AS_FXSAVEQ
10646 asm volatile("1: fxrstorq %[fx]\n\t"
10647@@ -115,6 +117,8 @@ static inline int fxsave_user(struct i387_fxsave_struct __user *fx)
10648 {
10649 int err;
10650
10651+ fx = (struct i387_fxsave_struct __user *)____m(fx);
10652+
10653 /*
10654 * Clear the bytes not touched by the fxsave and reserved
10655 * for the SW usage.
10656@@ -183,15 +187,15 @@ static inline void fpu_fxsave(struct fpu *fpu)
10657 #else /* CONFIG_X86_32 */
10658
10659 /* perform fxrstor iff the processor has extended states, otherwise frstor */
10660-static inline int fxrstor_checking(struct i387_fxsave_struct *fx)
10661+static inline int fxrstor_checking(struct i387_fxsave_struct __user *fx)
10662 {
10663 /*
10664 * The "nop" is needed to make the instructions the same
10665 * length.
10666 */
10667 alternative_input(
10668- "nop ; frstor %1",
10669- "fxrstor %1",
10670+ __copyuser_seg" frstor %1; nop",
10671+ __copyuser_seg" fxrstor %1",
10672 X86_FEATURE_FXSR,
10673 "m" (*fx));
10674
10675@@ -271,7 +275,7 @@ static inline int restore_fpu_checking(struct task_struct *tsk)
10676 "emms\n\t" /* clear stack tags */
10677 "fildl %P[addr]", /* set F?P to defined value */
10678 X86_FEATURE_FXSAVE_LEAK,
10679- [addr] "m" (tsk->thread.fpu.has_fpu));
10680+ [addr] "m" (init_tss[smp_processor_id()].x86_tss.sp0));
10681
10682 return fpu_restore_checking(&tsk->thread.fpu);
10683 }
10684diff --git a/arch/x86/include/asm/futex.h b/arch/x86/include/asm/futex.h
10685index 71ecbcb..11df950 100644
10686--- a/arch/x86/include/asm/futex.h
10687+++ b/arch/x86/include/asm/futex.h
10688@@ -11,20 +11,22 @@
10689 #include <asm/processor.h>
10690
10691 #define __futex_atomic_op1(insn, ret, oldval, uaddr, oparg) \
10692+ typecheck(u32 __user *, uaddr); \
10693 asm volatile("1:\t" insn "\n" \
10694 "2:\t.section .fixup,\"ax\"\n" \
10695 "3:\tmov\t%3, %1\n" \
10696 "\tjmp\t2b\n" \
10697 "\t.previous\n" \
10698 _ASM_EXTABLE(1b, 3b) \
10699- : "=r" (oldval), "=r" (ret), "+m" (*uaddr) \
10700+ : "=r" (oldval), "=r" (ret), "+m" (*(u32 __user *)____m(uaddr))\
10701 : "i" (-EFAULT), "0" (oparg), "1" (0))
10702
10703 #define __futex_atomic_op2(insn, ret, oldval, uaddr, oparg) \
10704+ typecheck(u32 __user *, uaddr); \
10705 asm volatile("1:\tmovl %2, %0\n" \
10706 "\tmovl\t%0, %3\n" \
10707 "\t" insn "\n" \
10708- "2:\t" LOCK_PREFIX "cmpxchgl %3, %2\n" \
10709+ "2:\t" LOCK_PREFIX __copyuser_seg"cmpxchgl %3, %2\n" \
10710 "\tjnz\t1b\n" \
10711 "3:\t.section .fixup,\"ax\"\n" \
10712 "4:\tmov\t%5, %1\n" \
10713@@ -33,7 +35,7 @@
10714 _ASM_EXTABLE(1b, 4b) \
10715 _ASM_EXTABLE(2b, 4b) \
10716 : "=&a" (oldval), "=&r" (ret), \
10717- "+m" (*uaddr), "=&r" (tem) \
10718+ "+m" (*(u32 __user *)____m(uaddr)), "=&r" (tem) \
10719 : "r" (oparg), "i" (-EFAULT), "1" (0))
10720
10721 static inline int futex_atomic_op_inuser(int encoded_op, u32 __user *uaddr)
10722@@ -60,10 +62,10 @@ static inline int futex_atomic_op_inuser(int encoded_op, u32 __user *uaddr)
10723
10724 switch (op) {
10725 case FUTEX_OP_SET:
10726- __futex_atomic_op1("xchgl %0, %2", ret, oldval, uaddr, oparg);
10727+ __futex_atomic_op1(__copyuser_seg"xchgl %0, %2", ret, oldval, uaddr, oparg);
10728 break;
10729 case FUTEX_OP_ADD:
10730- __futex_atomic_op1(LOCK_PREFIX "xaddl %0, %2", ret, oldval,
10731+ __futex_atomic_op1(LOCK_PREFIX __copyuser_seg"xaddl %0, %2", ret, oldval,
10732 uaddr, oparg);
10733 break;
10734 case FUTEX_OP_OR:
10735@@ -122,13 +124,13 @@ static inline int futex_atomic_cmpxchg_inatomic(u32 *uval, u32 __user *uaddr,
10736 if (!access_ok(VERIFY_WRITE, uaddr, sizeof(u32)))
10737 return -EFAULT;
10738
10739- asm volatile("1:\t" LOCK_PREFIX "cmpxchgl %4, %2\n"
10740+ asm volatile("1:\t" LOCK_PREFIX __copyuser_seg"cmpxchgl %4, %2\n"
10741 "2:\t.section .fixup, \"ax\"\n"
10742 "3:\tmov %3, %0\n"
10743 "\tjmp 2b\n"
10744 "\t.previous\n"
10745 _ASM_EXTABLE(1b, 3b)
10746- : "+r" (ret), "=a" (oldval), "+m" (*uaddr)
10747+ : "+r" (ret), "=a" (oldval), "+m" (*(u32 __user *)____m(uaddr))
10748 : "i" (-EFAULT), "r" (newval), "1" (oldval)
10749 : "memory"
10750 );
10751diff --git a/arch/x86/include/asm/hw_irq.h b/arch/x86/include/asm/hw_irq.h
10752index eb92a6e..b98b2f4 100644
10753--- a/arch/x86/include/asm/hw_irq.h
10754+++ b/arch/x86/include/asm/hw_irq.h
10755@@ -136,8 +136,8 @@ extern void setup_ioapic_dest(void);
10756 extern void enable_IO_APIC(void);
10757
10758 /* Statistics */
10759-extern atomic_t irq_err_count;
10760-extern atomic_t irq_mis_count;
10761+extern atomic_unchecked_t irq_err_count;
10762+extern atomic_unchecked_t irq_mis_count;
10763
10764 /* EISA */
10765 extern void eisa_set_level_irq(unsigned int irq);
10766diff --git a/arch/x86/include/asm/io.h b/arch/x86/include/asm/io.h
10767index d8e8eef..99f81ae 100644
10768--- a/arch/x86/include/asm/io.h
10769+++ b/arch/x86/include/asm/io.h
10770@@ -194,6 +194,17 @@ extern void set_iounmap_nonlazy(void);
10771
10772 #include <linux/vmalloc.h>
10773
10774+#define ARCH_HAS_VALID_PHYS_ADDR_RANGE
10775+static inline int valid_phys_addr_range(unsigned long addr, size_t count)
10776+{
10777+ return ((addr + count + PAGE_SIZE - 1) >> PAGE_SHIFT) < (1ULL << (boot_cpu_data.x86_phys_bits - PAGE_SHIFT)) ? 1 : 0;
10778+}
10779+
10780+static inline int valid_mmap_phys_addr_range(unsigned long pfn, size_t count)
10781+{
10782+ return (pfn + (count >> PAGE_SHIFT)) < (1ULL << (boot_cpu_data.x86_phys_bits - PAGE_SHIFT)) ? 1 : 0;
10783+}
10784+
10785 /*
10786 * Convert a virtual cached pointer to an uncached pointer
10787 */
10788diff --git a/arch/x86/include/asm/irqflags.h b/arch/x86/include/asm/irqflags.h
10789index bba3cf8..06bc8da 100644
10790--- a/arch/x86/include/asm/irqflags.h
10791+++ b/arch/x86/include/asm/irqflags.h
10792@@ -141,6 +141,11 @@ static inline notrace unsigned long arch_local_irq_save(void)
10793 sti; \
10794 sysexit
10795
10796+#define GET_CR0_INTO_RDI mov %cr0, %rdi
10797+#define SET_RDI_INTO_CR0 mov %rdi, %cr0
10798+#define GET_CR3_INTO_RDI mov %cr3, %rdi
10799+#define SET_RDI_INTO_CR3 mov %rdi, %cr3
10800+
10801 #else
10802 #define INTERRUPT_RETURN iret
10803 #define ENABLE_INTERRUPTS_SYSEXIT sti; sysexit
10804diff --git a/arch/x86/include/asm/kprobes.h b/arch/x86/include/asm/kprobes.h
10805index 5478825..839e88c 100644
10806--- a/arch/x86/include/asm/kprobes.h
10807+++ b/arch/x86/include/asm/kprobes.h
10808@@ -37,13 +37,8 @@ typedef u8 kprobe_opcode_t;
10809 #define RELATIVEJUMP_SIZE 5
10810 #define RELATIVECALL_OPCODE 0xe8
10811 #define RELATIVE_ADDR_SIZE 4
10812-#define MAX_STACK_SIZE 64
10813-#define MIN_STACK_SIZE(ADDR) \
10814- (((MAX_STACK_SIZE) < (((unsigned long)current_thread_info()) + \
10815- THREAD_SIZE - (unsigned long)(ADDR))) \
10816- ? (MAX_STACK_SIZE) \
10817- : (((unsigned long)current_thread_info()) + \
10818- THREAD_SIZE - (unsigned long)(ADDR)))
10819+#define MAX_STACK_SIZE 64UL
10820+#define MIN_STACK_SIZE(ADDR) min(MAX_STACK_SIZE, current->thread.sp0 - (unsigned long)(ADDR))
10821
10822 #define flush_insn_slot(p) do { } while (0)
10823
10824diff --git a/arch/x86/include/asm/kvm_host.h b/arch/x86/include/asm/kvm_host.h
10825index 09155d6..d2e6df9 100644
10826--- a/arch/x86/include/asm/kvm_host.h
10827+++ b/arch/x86/include/asm/kvm_host.h
10828@@ -694,7 +694,7 @@ struct kvm_x86_ops {
10829 int (*check_intercept)(struct kvm_vcpu *vcpu,
10830 struct x86_instruction_info *info,
10831 enum x86_intercept_stage stage);
10832-};
10833+} __do_const;
10834
10835 struct kvm_arch_async_pf {
10836 u32 token;
10837diff --git a/arch/x86/include/asm/local.h b/arch/x86/include/asm/local.h
10838index c8bed0d..e5721fa 100644
10839--- a/arch/x86/include/asm/local.h
10840+++ b/arch/x86/include/asm/local.h
10841@@ -17,26 +17,58 @@ typedef struct {
10842
10843 static inline void local_inc(local_t *l)
10844 {
10845- asm volatile(_ASM_INC "%0"
10846+ asm volatile(_ASM_INC "%0\n"
10847+
10848+#ifdef CONFIG_PAX_REFCOUNT
10849+ "jno 0f\n"
10850+ _ASM_DEC "%0\n"
10851+ "int $4\n0:\n"
10852+ _ASM_EXTABLE(0b, 0b)
10853+#endif
10854+
10855 : "+m" (l->a.counter));
10856 }
10857
10858 static inline void local_dec(local_t *l)
10859 {
10860- asm volatile(_ASM_DEC "%0"
10861+ asm volatile(_ASM_DEC "%0\n"
10862+
10863+#ifdef CONFIG_PAX_REFCOUNT
10864+ "jno 0f\n"
10865+ _ASM_INC "%0\n"
10866+ "int $4\n0:\n"
10867+ _ASM_EXTABLE(0b, 0b)
10868+#endif
10869+
10870 : "+m" (l->a.counter));
10871 }
10872
10873 static inline void local_add(long i, local_t *l)
10874 {
10875- asm volatile(_ASM_ADD "%1,%0"
10876+ asm volatile(_ASM_ADD "%1,%0\n"
10877+
10878+#ifdef CONFIG_PAX_REFCOUNT
10879+ "jno 0f\n"
10880+ _ASM_SUB "%1,%0\n"
10881+ "int $4\n0:\n"
10882+ _ASM_EXTABLE(0b, 0b)
10883+#endif
10884+
10885 : "+m" (l->a.counter)
10886 : "ir" (i));
10887 }
10888
10889 static inline void local_sub(long i, local_t *l)
10890 {
10891- asm volatile(_ASM_SUB "%1,%0"
10892+ asm volatile(_ASM_SUB "%1,%0\n"
10893+
10894+#ifdef CONFIG_PAX_REFCOUNT
10895+ "jno 0f\n"
10896+ _ASM_ADD "%1,%0\n"
10897+ "int $4\n0:\n"
10898+ _ASM_EXTABLE(0b, 0b)
10899+#endif
10900+
10901 : "+m" (l->a.counter)
10902 : "ir" (i));
10903 }
10904@@ -54,7 +86,16 @@ static inline int local_sub_and_test(long i, local_t *l)
10905 {
10906 unsigned char c;
10907
10908- asm volatile(_ASM_SUB "%2,%0; sete %1"
10909+ asm volatile(_ASM_SUB "%2,%0\n"
10910+
10911+#ifdef CONFIG_PAX_REFCOUNT
10912+ "jno 0f\n"
10913+ _ASM_ADD "%2,%0\n"
10914+ "int $4\n0:\n"
10915+ _ASM_EXTABLE(0b, 0b)
10916+#endif
10917+
10918+ "sete %1\n"
10919 : "+m" (l->a.counter), "=qm" (c)
10920 : "ir" (i) : "memory");
10921 return c;
10922@@ -72,7 +113,16 @@ static inline int local_dec_and_test(local_t *l)
10923 {
10924 unsigned char c;
10925
10926- asm volatile(_ASM_DEC "%0; sete %1"
10927+ asm volatile(_ASM_DEC "%0\n"
10928+
10929+#ifdef CONFIG_PAX_REFCOUNT
10930+ "jno 0f\n"
10931+ _ASM_INC "%0\n"
10932+ "int $4\n0:\n"
10933+ _ASM_EXTABLE(0b, 0b)
10934+#endif
10935+
10936+ "sete %1\n"
10937 : "+m" (l->a.counter), "=qm" (c)
10938 : : "memory");
10939 return c != 0;
10940@@ -90,7 +140,16 @@ static inline int local_inc_and_test(local_t *l)
10941 {
10942 unsigned char c;
10943
10944- asm volatile(_ASM_INC "%0; sete %1"
10945+ asm volatile(_ASM_INC "%0\n"
10946+
10947+#ifdef CONFIG_PAX_REFCOUNT
10948+ "jno 0f\n"
10949+ _ASM_DEC "%0\n"
10950+ "int $4\n0:\n"
10951+ _ASM_EXTABLE(0b, 0b)
10952+#endif
10953+
10954+ "sete %1\n"
10955 : "+m" (l->a.counter), "=qm" (c)
10956 : : "memory");
10957 return c != 0;
10958@@ -109,7 +168,16 @@ static inline int local_add_negative(long i, local_t *l)
10959 {
10960 unsigned char c;
10961
10962- asm volatile(_ASM_ADD "%2,%0; sets %1"
10963+ asm volatile(_ASM_ADD "%2,%0\n"
10964+
10965+#ifdef CONFIG_PAX_REFCOUNT
10966+ "jno 0f\n"
10967+ _ASM_SUB "%2,%0\n"
10968+ "int $4\n0:\n"
10969+ _ASM_EXTABLE(0b, 0b)
10970+#endif
10971+
10972+ "sets %1\n"
10973 : "+m" (l->a.counter), "=qm" (c)
10974 : "ir" (i) : "memory");
10975 return c;
10976@@ -132,7 +200,15 @@ static inline long local_add_return(long i, local_t *l)
10977 #endif
10978 /* Modern 486+ processor */
10979 __i = i;
10980- asm volatile(_ASM_XADD "%0, %1;"
10981+ asm volatile(_ASM_XADD "%0, %1\n"
10982+
10983+#ifdef CONFIG_PAX_REFCOUNT
10984+ "jno 0f\n"
10985+ _ASM_MOV "%0,%1\n"
10986+ "int $4\n0:\n"
10987+ _ASM_EXTABLE(0b, 0b)
10988+#endif
10989+
10990 : "+r" (i), "+m" (l->a.counter)
10991 : : "memory");
10992 return i + __i;
10993diff --git a/arch/x86/include/asm/mman.h b/arch/x86/include/asm/mman.h
10994index 593e51d..fa69c9a 100644
10995--- a/arch/x86/include/asm/mman.h
10996+++ b/arch/x86/include/asm/mman.h
10997@@ -5,4 +5,14 @@
10998
10999 #include <asm-generic/mman.h>
11000
11001+#ifdef __KERNEL__
11002+#ifndef __ASSEMBLY__
11003+#ifdef CONFIG_X86_32
11004+#define arch_mmap_check i386_mmap_check
11005+int i386_mmap_check(unsigned long addr, unsigned long len,
11006+ unsigned long flags);
11007+#endif
11008+#endif
11009+#endif
11010+
11011 #endif /* _ASM_X86_MMAN_H */
11012diff --git a/arch/x86/include/asm/mmu.h b/arch/x86/include/asm/mmu.h
11013index 5f55e69..e20bfb1 100644
11014--- a/arch/x86/include/asm/mmu.h
11015+++ b/arch/x86/include/asm/mmu.h
11016@@ -9,7 +9,7 @@
11017 * we put the segment information here.
11018 */
11019 typedef struct {
11020- void *ldt;
11021+ struct desc_struct *ldt;
11022 int size;
11023
11024 #ifdef CONFIG_X86_64
11025@@ -18,7 +18,19 @@ typedef struct {
11026 #endif
11027
11028 struct mutex lock;
11029- void *vdso;
11030+ unsigned long vdso;
11031+
11032+#ifdef CONFIG_X86_32
11033+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
11034+ unsigned long user_cs_base;
11035+ unsigned long user_cs_limit;
11036+
11037+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_SMP)
11038+ cpumask_t cpu_user_cs_mask;
11039+#endif
11040+
11041+#endif
11042+#endif
11043 } mm_context_t;
11044
11045 #ifdef CONFIG_SMP
11046diff --git a/arch/x86/include/asm/mmu_context.h b/arch/x86/include/asm/mmu_context.h
11047index cdbf367..adb37ac 100644
11048--- a/arch/x86/include/asm/mmu_context.h
11049+++ b/arch/x86/include/asm/mmu_context.h
11050@@ -24,6 +24,18 @@ void destroy_context(struct mm_struct *mm);
11051
11052 static inline void enter_lazy_tlb(struct mm_struct *mm, struct task_struct *tsk)
11053 {
11054+
11055+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
11056+ unsigned int i;
11057+ pgd_t *pgd;
11058+
11059+ pax_open_kernel();
11060+ pgd = get_cpu_pgd(smp_processor_id());
11061+ for (i = USER_PGD_PTRS; i < 2 * USER_PGD_PTRS; ++i)
11062+ set_pgd_batched(pgd+i, native_make_pgd(0));
11063+ pax_close_kernel();
11064+#endif
11065+
11066 #ifdef CONFIG_SMP
11067 if (this_cpu_read(cpu_tlbstate.state) == TLBSTATE_OK)
11068 this_cpu_write(cpu_tlbstate.state, TLBSTATE_LAZY);
11069@@ -34,16 +46,30 @@ static inline void switch_mm(struct mm_struct *prev, struct mm_struct *next,
11070 struct task_struct *tsk)
11071 {
11072 unsigned cpu = smp_processor_id();
11073+#if defined(CONFIG_X86_32) && defined(CONFIG_SMP) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
11074+ int tlbstate = TLBSTATE_OK;
11075+#endif
11076
11077 if (likely(prev != next)) {
11078 #ifdef CONFIG_SMP
11079+#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
11080+ tlbstate = this_cpu_read(cpu_tlbstate.state);
11081+#endif
11082 this_cpu_write(cpu_tlbstate.state, TLBSTATE_OK);
11083 this_cpu_write(cpu_tlbstate.active_mm, next);
11084 #endif
11085 cpumask_set_cpu(cpu, mm_cpumask(next));
11086
11087 /* Re-load page tables */
11088+#ifdef CONFIG_PAX_PER_CPU_PGD
11089+ pax_open_kernel();
11090+ __clone_user_pgds(get_cpu_pgd(cpu), next->pgd);
11091+ __shadow_user_pgds(get_cpu_pgd(cpu) + USER_PGD_PTRS, next->pgd);
11092+ pax_close_kernel();
11093+ load_cr3(get_cpu_pgd(cpu));
11094+#else
11095 load_cr3(next->pgd);
11096+#endif
11097
11098 /* stop flush ipis for the previous mm */
11099 cpumask_clear_cpu(cpu, mm_cpumask(prev));
11100@@ -53,9 +79,38 @@ static inline void switch_mm(struct mm_struct *prev, struct mm_struct *next,
11101 */
11102 if (unlikely(prev->context.ldt != next->context.ldt))
11103 load_LDT_nolock(&next->context);
11104- }
11105+
11106+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_SMP)
11107+ if (!(__supported_pte_mask & _PAGE_NX)) {
11108+ smp_mb__before_clear_bit();
11109+ cpu_clear(cpu, prev->context.cpu_user_cs_mask);
11110+ smp_mb__after_clear_bit();
11111+ cpu_set(cpu, next->context.cpu_user_cs_mask);
11112+ }
11113+#endif
11114+
11115+#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
11116+ if (unlikely(prev->context.user_cs_base != next->context.user_cs_base ||
11117+ prev->context.user_cs_limit != next->context.user_cs_limit))
11118+ set_user_cs(next->context.user_cs_base, next->context.user_cs_limit, cpu);
11119 #ifdef CONFIG_SMP
11120+ else if (unlikely(tlbstate != TLBSTATE_OK))
11121+ set_user_cs(next->context.user_cs_base, next->context.user_cs_limit, cpu);
11122+#endif
11123+#endif
11124+
11125+ }
11126 else {
11127+
11128+#ifdef CONFIG_PAX_PER_CPU_PGD
11129+ pax_open_kernel();
11130+ __clone_user_pgds(get_cpu_pgd(cpu), next->pgd);
11131+ __shadow_user_pgds(get_cpu_pgd(cpu) + USER_PGD_PTRS, next->pgd);
11132+ pax_close_kernel();
11133+ load_cr3(get_cpu_pgd(cpu));
11134+#endif
11135+
11136+#ifdef CONFIG_SMP
11137 this_cpu_write(cpu_tlbstate.state, TLBSTATE_OK);
11138 BUG_ON(this_cpu_read(cpu_tlbstate.active_mm) != next);
11139
11140@@ -64,11 +119,28 @@ static inline void switch_mm(struct mm_struct *prev, struct mm_struct *next,
11141 * tlb flush IPI delivery. We must reload CR3
11142 * to make sure to use no freed page tables.
11143 */
11144+
11145+#ifndef CONFIG_PAX_PER_CPU_PGD
11146 load_cr3(next->pgd);
11147+#endif
11148+
11149 load_LDT_nolock(&next->context);
11150+
11151+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
11152+ if (!(__supported_pte_mask & _PAGE_NX))
11153+ cpu_set(cpu, next->context.cpu_user_cs_mask);
11154+#endif
11155+
11156+#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
11157+#ifdef CONFIG_PAX_PAGEEXEC
11158+ if (!((next->pax_flags & MF_PAX_PAGEEXEC) && (__supported_pte_mask & _PAGE_NX)))
11159+#endif
11160+ set_user_cs(next->context.user_cs_base, next->context.user_cs_limit, cpu);
11161+#endif
11162+
11163 }
11164+#endif
11165 }
11166-#endif
11167 }
11168
11169 #define activate_mm(prev, next) \
11170diff --git a/arch/x86/include/asm/module.h b/arch/x86/include/asm/module.h
11171index 9eae775..c914fea 100644
11172--- a/arch/x86/include/asm/module.h
11173+++ b/arch/x86/include/asm/module.h
11174@@ -5,6 +5,7 @@
11175
11176 #ifdef CONFIG_X86_64
11177 /* X86_64 does not define MODULE_PROC_FAMILY */
11178+#define MODULE_PROC_FAMILY ""
11179 #elif defined CONFIG_M386
11180 #define MODULE_PROC_FAMILY "386 "
11181 #elif defined CONFIG_M486
11182@@ -59,8 +60,20 @@
11183 #error unknown processor family
11184 #endif
11185
11186-#ifdef CONFIG_X86_32
11187-# define MODULE_ARCH_VERMAGIC MODULE_PROC_FAMILY
11188+#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_BTS
11189+#define MODULE_PAX_KERNEXEC "KERNEXEC_BTS "
11190+#elif defined(CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR)
11191+#define MODULE_PAX_KERNEXEC "KERNEXEC_OR "
11192+#else
11193+#define MODULE_PAX_KERNEXEC ""
11194 #endif
11195
11196+#ifdef CONFIG_PAX_MEMORY_UDEREF
11197+#define MODULE_PAX_UDEREF "UDEREF "
11198+#else
11199+#define MODULE_PAX_UDEREF ""
11200+#endif
11201+
11202+#define MODULE_ARCH_VERMAGIC MODULE_PROC_FAMILY MODULE_PAX_KERNEXEC MODULE_PAX_UDEREF
11203+
11204 #endif /* _ASM_X86_MODULE_H */
11205diff --git a/arch/x86/include/asm/page_64_types.h b/arch/x86/include/asm/page_64_types.h
11206index 320f7bb..e89f8f8 100644
11207--- a/arch/x86/include/asm/page_64_types.h
11208+++ b/arch/x86/include/asm/page_64_types.h
11209@@ -56,7 +56,7 @@ void copy_page(void *to, void *from);
11210
11211 /* duplicated to the one in bootmem.h */
11212 extern unsigned long max_pfn;
11213-extern unsigned long phys_base;
11214+extern const unsigned long phys_base;
11215
11216 extern unsigned long __phys_addr(unsigned long);
11217 #define __phys_reloc_hide(x) (x)
11218diff --git a/arch/x86/include/asm/paravirt.h b/arch/x86/include/asm/paravirt.h
11219index a0facf3..c017b15 100644
11220--- a/arch/x86/include/asm/paravirt.h
11221+++ b/arch/x86/include/asm/paravirt.h
11222@@ -632,6 +632,18 @@ static inline void set_pgd(pgd_t *pgdp, pgd_t pgd)
11223 val);
11224 }
11225
11226+static inline void set_pgd_batched(pgd_t *pgdp, pgd_t pgd)
11227+{
11228+ pgdval_t val = native_pgd_val(pgd);
11229+
11230+ if (sizeof(pgdval_t) > sizeof(long))
11231+ PVOP_VCALL3(pv_mmu_ops.set_pgd_batched, pgdp,
11232+ val, (u64)val >> 32);
11233+ else
11234+ PVOP_VCALL2(pv_mmu_ops.set_pgd_batched, pgdp,
11235+ val);
11236+}
11237+
11238 static inline void pgd_clear(pgd_t *pgdp)
11239 {
11240 set_pgd(pgdp, __pgd(0));
11241@@ -713,6 +725,21 @@ static inline void __set_fixmap(unsigned /* enum fixed_addresses */ idx,
11242 pv_mmu_ops.set_fixmap(idx, phys, flags);
11243 }
11244
11245+#ifdef CONFIG_PAX_KERNEXEC
11246+static inline unsigned long pax_open_kernel(void)
11247+{
11248+ return PVOP_CALL0(unsigned long, pv_mmu_ops.pax_open_kernel);
11249+}
11250+
11251+static inline unsigned long pax_close_kernel(void)
11252+{
11253+ return PVOP_CALL0(unsigned long, pv_mmu_ops.pax_close_kernel);
11254+}
11255+#else
11256+static inline unsigned long pax_open_kernel(void) { return 0; }
11257+static inline unsigned long pax_close_kernel(void) { return 0; }
11258+#endif
11259+
11260 #if defined(CONFIG_SMP) && defined(CONFIG_PARAVIRT_SPINLOCKS)
11261
11262 static inline int arch_spin_is_locked(struct arch_spinlock *lock)
11263@@ -929,7 +956,7 @@ extern void default_banner(void);
11264
11265 #define PARA_PATCH(struct, off) ((PARAVIRT_PATCH_##struct + (off)) / 4)
11266 #define PARA_SITE(ptype, clobbers, ops) _PVSITE(ptype, clobbers, ops, .long, 4)
11267-#define PARA_INDIRECT(addr) *%cs:addr
11268+#define PARA_INDIRECT(addr) *%ss:addr
11269 #endif
11270
11271 #define INTERRUPT_RETURN \
11272@@ -1004,6 +1031,21 @@ extern void default_banner(void);
11273 PARA_SITE(PARA_PATCH(pv_cpu_ops, PV_CPU_irq_enable_sysexit), \
11274 CLBR_NONE, \
11275 jmp PARA_INDIRECT(pv_cpu_ops+PV_CPU_irq_enable_sysexit))
11276+
11277+#define GET_CR0_INTO_RDI \
11278+ call PARA_INDIRECT(pv_cpu_ops+PV_CPU_read_cr0); \
11279+ mov %rax,%rdi
11280+
11281+#define SET_RDI_INTO_CR0 \
11282+ call PARA_INDIRECT(pv_cpu_ops+PV_CPU_write_cr0)
11283+
11284+#define GET_CR3_INTO_RDI \
11285+ call PARA_INDIRECT(pv_mmu_ops+PV_MMU_read_cr3); \
11286+ mov %rax,%rdi
11287+
11288+#define SET_RDI_INTO_CR3 \
11289+ call PARA_INDIRECT(pv_mmu_ops+PV_MMU_write_cr3)
11290+
11291 #endif /* CONFIG_X86_32 */
11292
11293 #endif /* __ASSEMBLY__ */
11294diff --git a/arch/x86/include/asm/paravirt_types.h b/arch/x86/include/asm/paravirt_types.h
11295index 142236e..6a6b4a6 100644
11296--- a/arch/x86/include/asm/paravirt_types.h
11297+++ b/arch/x86/include/asm/paravirt_types.h
11298@@ -84,20 +84,20 @@ struct pv_init_ops {
11299 */
11300 unsigned (*patch)(u8 type, u16 clobber, void *insnbuf,
11301 unsigned long addr, unsigned len);
11302-};
11303+} __no_const;
11304
11305
11306 struct pv_lazy_ops {
11307 /* Set deferred update mode, used for batching operations. */
11308 void (*enter)(void);
11309 void (*leave)(void);
11310-};
11311+} __no_const;
11312
11313 struct pv_time_ops {
11314 unsigned long long (*sched_clock)(void);
11315 unsigned long long (*steal_clock)(int cpu);
11316 unsigned long (*get_tsc_khz)(void);
11317-};
11318+} __no_const;
11319
11320 struct pv_cpu_ops {
11321 /* hooks for various privileged instructions */
11322@@ -191,7 +191,7 @@ struct pv_cpu_ops {
11323
11324 void (*start_context_switch)(struct task_struct *prev);
11325 void (*end_context_switch)(struct task_struct *next);
11326-};
11327+} __no_const;
11328
11329 struct pv_irq_ops {
11330 /*
11331@@ -222,7 +222,7 @@ struct pv_apic_ops {
11332 unsigned long start_eip,
11333 unsigned long start_esp);
11334 #endif
11335-};
11336+} __no_const;
11337
11338 struct pv_mmu_ops {
11339 unsigned long (*read_cr2)(void);
11340@@ -312,6 +312,7 @@ struct pv_mmu_ops {
11341 struct paravirt_callee_save make_pud;
11342
11343 void (*set_pgd)(pgd_t *pudp, pgd_t pgdval);
11344+ void (*set_pgd_batched)(pgd_t *pudp, pgd_t pgdval);
11345 #endif /* PAGETABLE_LEVELS == 4 */
11346 #endif /* PAGETABLE_LEVELS >= 3 */
11347
11348@@ -323,6 +324,12 @@ struct pv_mmu_ops {
11349 an mfn. We can tell which is which from the index. */
11350 void (*set_fixmap)(unsigned /* enum fixed_addresses */ idx,
11351 phys_addr_t phys, pgprot_t flags);
11352+
11353+#ifdef CONFIG_PAX_KERNEXEC
11354+ unsigned long (*pax_open_kernel)(void);
11355+ unsigned long (*pax_close_kernel)(void);
11356+#endif
11357+
11358 };
11359
11360 struct arch_spinlock;
11361@@ -333,7 +340,7 @@ struct pv_lock_ops {
11362 void (*spin_lock_flags)(struct arch_spinlock *lock, unsigned long flags);
11363 int (*spin_trylock)(struct arch_spinlock *lock);
11364 void (*spin_unlock)(struct arch_spinlock *lock);
11365-};
11366+} __no_const;
11367
11368 /* This contains all the paravirt structures: we get a convenient
11369 * number for each function using the offset which we use to indicate
11370diff --git a/arch/x86/include/asm/pgalloc.h b/arch/x86/include/asm/pgalloc.h
11371index b4389a4..7024269 100644
11372--- a/arch/x86/include/asm/pgalloc.h
11373+++ b/arch/x86/include/asm/pgalloc.h
11374@@ -63,6 +63,13 @@ static inline void pmd_populate_kernel(struct mm_struct *mm,
11375 pmd_t *pmd, pte_t *pte)
11376 {
11377 paravirt_alloc_pte(mm, __pa(pte) >> PAGE_SHIFT);
11378+ set_pmd(pmd, __pmd(__pa(pte) | _KERNPG_TABLE));
11379+}
11380+
11381+static inline void pmd_populate_user(struct mm_struct *mm,
11382+ pmd_t *pmd, pte_t *pte)
11383+{
11384+ paravirt_alloc_pte(mm, __pa(pte) >> PAGE_SHIFT);
11385 set_pmd(pmd, __pmd(__pa(pte) | _PAGE_TABLE));
11386 }
11387
11388@@ -99,12 +106,22 @@ static inline void __pmd_free_tlb(struct mmu_gather *tlb, pmd_t *pmd,
11389
11390 #ifdef CONFIG_X86_PAE
11391 extern void pud_populate(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd);
11392+static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd)
11393+{
11394+ pud_populate(mm, pudp, pmd);
11395+}
11396 #else /* !CONFIG_X86_PAE */
11397 static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
11398 {
11399 paravirt_alloc_pmd(mm, __pa(pmd) >> PAGE_SHIFT);
11400 set_pud(pud, __pud(_PAGE_TABLE | __pa(pmd)));
11401 }
11402+
11403+static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
11404+{
11405+ paravirt_alloc_pmd(mm, __pa(pmd) >> PAGE_SHIFT);
11406+ set_pud(pud, __pud(_KERNPG_TABLE | __pa(pmd)));
11407+}
11408 #endif /* CONFIG_X86_PAE */
11409
11410 #if PAGETABLE_LEVELS > 3
11411@@ -114,6 +131,12 @@ static inline void pgd_populate(struct mm_struct *mm, pgd_t *pgd, pud_t *pud)
11412 set_pgd(pgd, __pgd(_PAGE_TABLE | __pa(pud)));
11413 }
11414
11415+static inline void pgd_populate_kernel(struct mm_struct *mm, pgd_t *pgd, pud_t *pud)
11416+{
11417+ paravirt_alloc_pud(mm, __pa(pud) >> PAGE_SHIFT);
11418+ set_pgd(pgd, __pgd(_KERNPG_TABLE | __pa(pud)));
11419+}
11420+
11421 static inline pud_t *pud_alloc_one(struct mm_struct *mm, unsigned long addr)
11422 {
11423 return (pud_t *)get_zeroed_page(GFP_KERNEL|__GFP_REPEAT);
11424diff --git a/arch/x86/include/asm/pgtable-2level.h b/arch/x86/include/asm/pgtable-2level.h
11425index f2b489c..4f7e2e5 100644
11426--- a/arch/x86/include/asm/pgtable-2level.h
11427+++ b/arch/x86/include/asm/pgtable-2level.h
11428@@ -18,7 +18,9 @@ static inline void native_set_pte(pte_t *ptep , pte_t pte)
11429
11430 static inline void native_set_pmd(pmd_t *pmdp, pmd_t pmd)
11431 {
11432+ pax_open_kernel();
11433 *pmdp = pmd;
11434+ pax_close_kernel();
11435 }
11436
11437 static inline void native_set_pte_atomic(pte_t *ptep, pte_t pte)
11438diff --git a/arch/x86/include/asm/pgtable-3level.h b/arch/x86/include/asm/pgtable-3level.h
11439index 4cc9f2b..5fd9226 100644
11440--- a/arch/x86/include/asm/pgtable-3level.h
11441+++ b/arch/x86/include/asm/pgtable-3level.h
11442@@ -92,12 +92,16 @@ static inline void native_set_pte_atomic(pte_t *ptep, pte_t pte)
11443
11444 static inline void native_set_pmd(pmd_t *pmdp, pmd_t pmd)
11445 {
11446+ pax_open_kernel();
11447 set_64bit((unsigned long long *)(pmdp), native_pmd_val(pmd));
11448+ pax_close_kernel();
11449 }
11450
11451 static inline void native_set_pud(pud_t *pudp, pud_t pud)
11452 {
11453+ pax_open_kernel();
11454 set_64bit((unsigned long long *)(pudp), native_pud_val(pud));
11455+ pax_close_kernel();
11456 }
11457
11458 /*
11459diff --git a/arch/x86/include/asm/pgtable.h b/arch/x86/include/asm/pgtable.h
11460index c3520d7..cf742ef 100644
11461--- a/arch/x86/include/asm/pgtable.h
11462+++ b/arch/x86/include/asm/pgtable.h
11463@@ -44,6 +44,7 @@ extern struct mm_struct *pgd_page_get_mm(struct page *page);
11464
11465 #ifndef __PAGETABLE_PUD_FOLDED
11466 #define set_pgd(pgdp, pgd) native_set_pgd(pgdp, pgd)
11467+#define set_pgd_batched(pgdp, pgd) native_set_pgd_batched(pgdp, pgd)
11468 #define pgd_clear(pgd) native_pgd_clear(pgd)
11469 #endif
11470
11471@@ -81,12 +82,51 @@ extern struct mm_struct *pgd_page_get_mm(struct page *page);
11472
11473 #define arch_end_context_switch(prev) do {} while(0)
11474
11475+#define pax_open_kernel() native_pax_open_kernel()
11476+#define pax_close_kernel() native_pax_close_kernel()
11477 #endif /* CONFIG_PARAVIRT */
11478
11479+#define __HAVE_ARCH_PAX_OPEN_KERNEL
11480+#define __HAVE_ARCH_PAX_CLOSE_KERNEL
11481+
11482+#ifdef CONFIG_PAX_KERNEXEC
11483+static inline unsigned long native_pax_open_kernel(void)
11484+{
11485+ unsigned long cr0;
11486+
11487+ preempt_disable();
11488+ barrier();
11489+ cr0 = read_cr0() ^ X86_CR0_WP;
11490+ BUG_ON(unlikely(cr0 & X86_CR0_WP));
11491+ write_cr0(cr0);
11492+ return cr0 ^ X86_CR0_WP;
11493+}
11494+
11495+static inline unsigned long native_pax_close_kernel(void)
11496+{
11497+ unsigned long cr0;
11498+
11499+ cr0 = read_cr0() ^ X86_CR0_WP;
11500+ BUG_ON(unlikely(!(cr0 & X86_CR0_WP)));
11501+ write_cr0(cr0);
11502+ barrier();
11503+ preempt_enable_no_resched();
11504+ return cr0 ^ X86_CR0_WP;
11505+}
11506+#else
11507+static inline unsigned long native_pax_open_kernel(void) { return 0; }
11508+static inline unsigned long native_pax_close_kernel(void) { return 0; }
11509+#endif
11510+
11511 /*
11512 * The following only work if pte_present() is true.
11513 * Undefined behaviour if not..
11514 */
11515+static inline int pte_user(pte_t pte)
11516+{
11517+ return pte_val(pte) & _PAGE_USER;
11518+}
11519+
11520 static inline int pte_dirty(pte_t pte)
11521 {
11522 return pte_flags(pte) & _PAGE_DIRTY;
11523@@ -195,9 +235,29 @@ static inline pte_t pte_wrprotect(pte_t pte)
11524 return pte_clear_flags(pte, _PAGE_RW);
11525 }
11526
11527+static inline pte_t pte_mkread(pte_t pte)
11528+{
11529+ return __pte(pte_val(pte) | _PAGE_USER);
11530+}
11531+
11532 static inline pte_t pte_mkexec(pte_t pte)
11533 {
11534- return pte_clear_flags(pte, _PAGE_NX);
11535+#ifdef CONFIG_X86_PAE
11536+ if (__supported_pte_mask & _PAGE_NX)
11537+ return pte_clear_flags(pte, _PAGE_NX);
11538+ else
11539+#endif
11540+ return pte_set_flags(pte, _PAGE_USER);
11541+}
11542+
11543+static inline pte_t pte_exprotect(pte_t pte)
11544+{
11545+#ifdef CONFIG_X86_PAE
11546+ if (__supported_pte_mask & _PAGE_NX)
11547+ return pte_set_flags(pte, _PAGE_NX);
11548+ else
11549+#endif
11550+ return pte_clear_flags(pte, _PAGE_USER);
11551 }
11552
11553 static inline pte_t pte_mkdirty(pte_t pte)
11554@@ -389,6 +449,15 @@ pte_t *populate_extra_pte(unsigned long vaddr);
11555 #endif
11556
11557 #ifndef __ASSEMBLY__
11558+
11559+#ifdef CONFIG_PAX_PER_CPU_PGD
11560+extern pgd_t cpu_pgd[NR_CPUS][PTRS_PER_PGD];
11561+static inline pgd_t *get_cpu_pgd(unsigned int cpu)
11562+{
11563+ return cpu_pgd[cpu];
11564+}
11565+#endif
11566+
11567 #include <linux/mm_types.h>
11568
11569 static inline int pte_none(pte_t pte)
11570@@ -565,7 +634,7 @@ static inline pud_t *pud_offset(pgd_t *pgd, unsigned long address)
11571
11572 static inline int pgd_bad(pgd_t pgd)
11573 {
11574- return (pgd_flags(pgd) & ~_PAGE_USER) != _KERNPG_TABLE;
11575+ return (pgd_flags(pgd) & ~(_PAGE_USER | _PAGE_NX)) != _KERNPG_TABLE;
11576 }
11577
11578 static inline int pgd_none(pgd_t pgd)
11579@@ -588,7 +657,12 @@ static inline int pgd_none(pgd_t pgd)
11580 * pgd_offset() returns a (pgd_t *)
11581 * pgd_index() is used get the offset into the pgd page's array of pgd_t's;
11582 */
11583-#define pgd_offset(mm, address) ((mm)->pgd + pgd_index((address)))
11584+#define pgd_offset(mm, address) ((mm)->pgd + pgd_index(address))
11585+
11586+#ifdef CONFIG_PAX_PER_CPU_PGD
11587+#define pgd_offset_cpu(cpu, address) (get_cpu_pgd(cpu) + pgd_index(address))
11588+#endif
11589+
11590 /*
11591 * a shortcut which implies the use of the kernel's pgd, instead
11592 * of a process's
11593@@ -599,6 +673,20 @@ static inline int pgd_none(pgd_t pgd)
11594 #define KERNEL_PGD_BOUNDARY pgd_index(PAGE_OFFSET)
11595 #define KERNEL_PGD_PTRS (PTRS_PER_PGD - KERNEL_PGD_BOUNDARY)
11596
11597+#ifdef CONFIG_X86_32
11598+#define USER_PGD_PTRS KERNEL_PGD_BOUNDARY
11599+#else
11600+#define TASK_SIZE_MAX_SHIFT CONFIG_TASK_SIZE_MAX_SHIFT
11601+#define USER_PGD_PTRS (_AC(1,UL) << (TASK_SIZE_MAX_SHIFT - PGDIR_SHIFT))
11602+
11603+#ifdef CONFIG_PAX_MEMORY_UDEREF
11604+#define PAX_USER_SHADOW_BASE (_AC(1,UL) << TASK_SIZE_MAX_SHIFT)
11605+#else
11606+#define PAX_USER_SHADOW_BASE (_AC(0,UL))
11607+#endif
11608+
11609+#endif
11610+
11611 #ifndef __ASSEMBLY__
11612
11613 extern int direct_gbpages;
11614@@ -763,11 +851,23 @@ static inline void pmdp_set_wrprotect(struct mm_struct *mm,
11615 * dst and src can be on the same page, but the range must not overlap,
11616 * and must not cross a page boundary.
11617 */
11618-static inline void clone_pgd_range(pgd_t *dst, pgd_t *src, int count)
11619+static inline void clone_pgd_range(pgd_t *dst, const pgd_t *src, int count)
11620 {
11621- memcpy(dst, src, count * sizeof(pgd_t));
11622+ pax_open_kernel();
11623+ while (count--)
11624+ *dst++ = *src++;
11625+ pax_close_kernel();
11626 }
11627
11628+#ifdef CONFIG_PAX_PER_CPU_PGD
11629+extern void __clone_user_pgds(pgd_t *dst, const pgd_t *src);
11630+#endif
11631+
11632+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
11633+extern void __shadow_user_pgds(pgd_t *dst, const pgd_t *src);
11634+#else
11635+static inline void __shadow_user_pgds(pgd_t *dst, const pgd_t *src) {}
11636+#endif
11637
11638 #include <asm-generic/pgtable.h>
11639 #endif /* __ASSEMBLY__ */
11640diff --git a/arch/x86/include/asm/pgtable_32.h b/arch/x86/include/asm/pgtable_32.h
11641index 0c92113..34a77c6 100644
11642--- a/arch/x86/include/asm/pgtable_32.h
11643+++ b/arch/x86/include/asm/pgtable_32.h
11644@@ -25,9 +25,6 @@
11645 struct mm_struct;
11646 struct vm_area_struct;
11647
11648-extern pgd_t swapper_pg_dir[1024];
11649-extern pgd_t initial_page_table[1024];
11650-
11651 static inline void pgtable_cache_init(void) { }
11652 static inline void check_pgt_cache(void) { }
11653 void paging_init(void);
11654@@ -48,6 +45,12 @@ extern void set_pmd_pfn(unsigned long, unsigned long, pgprot_t);
11655 # include <asm/pgtable-2level.h>
11656 #endif
11657
11658+extern pgd_t swapper_pg_dir[PTRS_PER_PGD];
11659+extern pgd_t initial_page_table[PTRS_PER_PGD];
11660+#ifdef CONFIG_X86_PAE
11661+extern pmd_t swapper_pm_dir[PTRS_PER_PGD][PTRS_PER_PMD];
11662+#endif
11663+
11664 #if defined(CONFIG_HIGHPTE)
11665 #define pte_offset_map(dir, address) \
11666 ((pte_t *)kmap_atomic(pmd_page(*(dir))) + \
11667@@ -62,7 +65,9 @@ extern void set_pmd_pfn(unsigned long, unsigned long, pgprot_t);
11668 /* Clear a kernel PTE and flush it from the TLB */
11669 #define kpte_clear_flush(ptep, vaddr) \
11670 do { \
11671+ pax_open_kernel(); \
11672 pte_clear(&init_mm, (vaddr), (ptep)); \
11673+ pax_close_kernel(); \
11674 __flush_tlb_one((vaddr)); \
11675 } while (0)
11676
11677@@ -74,6 +79,9 @@ do { \
11678
11679 #endif /* !__ASSEMBLY__ */
11680
11681+#define HAVE_ARCH_UNMAPPED_AREA
11682+#define HAVE_ARCH_UNMAPPED_AREA_TOPDOWN
11683+
11684 /*
11685 * kern_addr_valid() is (1) for FLATMEM and (0) for
11686 * SPARSEMEM and DISCONTIGMEM
11687diff --git a/arch/x86/include/asm/pgtable_32_types.h b/arch/x86/include/asm/pgtable_32_types.h
11688index ed5903b..c7fe163 100644
11689--- a/arch/x86/include/asm/pgtable_32_types.h
11690+++ b/arch/x86/include/asm/pgtable_32_types.h
11691@@ -8,7 +8,7 @@
11692 */
11693 #ifdef CONFIG_X86_PAE
11694 # include <asm/pgtable-3level_types.h>
11695-# define PMD_SIZE (1UL << PMD_SHIFT)
11696+# define PMD_SIZE (_AC(1, UL) << PMD_SHIFT)
11697 # define PMD_MASK (~(PMD_SIZE - 1))
11698 #else
11699 # include <asm/pgtable-2level_types.h>
11700@@ -46,6 +46,19 @@ extern bool __vmalloc_start_set; /* set once high_memory is set */
11701 # define VMALLOC_END (FIXADDR_START - 2 * PAGE_SIZE)
11702 #endif
11703
11704+#ifdef CONFIG_PAX_KERNEXEC
11705+#ifndef __ASSEMBLY__
11706+extern unsigned char MODULES_EXEC_VADDR[];
11707+extern unsigned char MODULES_EXEC_END[];
11708+#endif
11709+#include <asm/boot.h>
11710+#define ktla_ktva(addr) (addr + LOAD_PHYSICAL_ADDR + PAGE_OFFSET)
11711+#define ktva_ktla(addr) (addr - LOAD_PHYSICAL_ADDR - PAGE_OFFSET)
11712+#else
11713+#define ktla_ktva(addr) (addr)
11714+#define ktva_ktla(addr) (addr)
11715+#endif
11716+
11717 #define MODULES_VADDR VMALLOC_START
11718 #define MODULES_END VMALLOC_END
11719 #define MODULES_LEN (MODULES_VADDR - MODULES_END)
11720diff --git a/arch/x86/include/asm/pgtable_64.h b/arch/x86/include/asm/pgtable_64.h
11721index 8251be0..4ea8b46 100644
11722--- a/arch/x86/include/asm/pgtable_64.h
11723+++ b/arch/x86/include/asm/pgtable_64.h
11724@@ -16,10 +16,14 @@
11725
11726 extern pud_t level3_kernel_pgt[512];
11727 extern pud_t level3_ident_pgt[512];
11728+extern pud_t level3_vmalloc_start_pgt[512];
11729+extern pud_t level3_vmalloc_end_pgt[512];
11730+extern pud_t level3_vmemmap_pgt[512];
11731+extern pud_t level2_vmemmap_pgt[512];
11732 extern pmd_t level2_kernel_pgt[512];
11733 extern pmd_t level2_fixmap_pgt[512];
11734-extern pmd_t level2_ident_pgt[512];
11735-extern pgd_t init_level4_pgt[];
11736+extern pmd_t level2_ident_pgt[512*2];
11737+extern pgd_t init_level4_pgt[512];
11738
11739 #define swapper_pg_dir init_level4_pgt
11740
11741@@ -61,7 +65,9 @@ static inline void native_set_pte_atomic(pte_t *ptep, pte_t pte)
11742
11743 static inline void native_set_pmd(pmd_t *pmdp, pmd_t pmd)
11744 {
11745+ pax_open_kernel();
11746 *pmdp = pmd;
11747+ pax_close_kernel();
11748 }
11749
11750 static inline void native_pmd_clear(pmd_t *pmd)
11751@@ -97,7 +103,9 @@ static inline pmd_t native_pmdp_get_and_clear(pmd_t *xp)
11752
11753 static inline void native_set_pud(pud_t *pudp, pud_t pud)
11754 {
11755+ pax_open_kernel();
11756 *pudp = pud;
11757+ pax_close_kernel();
11758 }
11759
11760 static inline void native_pud_clear(pud_t *pud)
11761@@ -107,6 +115,13 @@ static inline void native_pud_clear(pud_t *pud)
11762
11763 static inline void native_set_pgd(pgd_t *pgdp, pgd_t pgd)
11764 {
11765+ pax_open_kernel();
11766+ *pgdp = pgd;
11767+ pax_close_kernel();
11768+}
11769+
11770+static inline void native_set_pgd_batched(pgd_t *pgdp, pgd_t pgd)
11771+{
11772 *pgdp = pgd;
11773 }
11774
11775diff --git a/arch/x86/include/asm/pgtable_64_types.h b/arch/x86/include/asm/pgtable_64_types.h
11776index 766ea16..5b96cb3 100644
11777--- a/arch/x86/include/asm/pgtable_64_types.h
11778+++ b/arch/x86/include/asm/pgtable_64_types.h
11779@@ -59,5 +59,10 @@ typedef struct { pteval_t pte; } pte_t;
11780 #define MODULES_VADDR _AC(0xffffffffa0000000, UL)
11781 #define MODULES_END _AC(0xffffffffff000000, UL)
11782 #define MODULES_LEN (MODULES_END - MODULES_VADDR)
11783+#define MODULES_EXEC_VADDR MODULES_VADDR
11784+#define MODULES_EXEC_END MODULES_END
11785+
11786+#define ktla_ktva(addr) (addr)
11787+#define ktva_ktla(addr) (addr)
11788
11789 #endif /* _ASM_X86_PGTABLE_64_DEFS_H */
11790diff --git a/arch/x86/include/asm/pgtable_types.h b/arch/x86/include/asm/pgtable_types.h
11791index 013286a..8b42f4f 100644
11792--- a/arch/x86/include/asm/pgtable_types.h
11793+++ b/arch/x86/include/asm/pgtable_types.h
11794@@ -16,13 +16,12 @@
11795 #define _PAGE_BIT_PSE 7 /* 4 MB (or 2MB) page */
11796 #define _PAGE_BIT_PAT 7 /* on 4KB pages */
11797 #define _PAGE_BIT_GLOBAL 8 /* Global TLB entry PPro+ */
11798-#define _PAGE_BIT_UNUSED1 9 /* available for programmer */
11799+#define _PAGE_BIT_SPECIAL 9 /* special mappings, no associated struct page */
11800 #define _PAGE_BIT_IOMAP 10 /* flag used to indicate IO mapping */
11801 #define _PAGE_BIT_HIDDEN 11 /* hidden by kmemcheck */
11802 #define _PAGE_BIT_PAT_LARGE 12 /* On 2MB or 1GB pages */
11803-#define _PAGE_BIT_SPECIAL _PAGE_BIT_UNUSED1
11804-#define _PAGE_BIT_CPA_TEST _PAGE_BIT_UNUSED1
11805-#define _PAGE_BIT_SPLITTING _PAGE_BIT_UNUSED1 /* only valid on a PSE pmd */
11806+#define _PAGE_BIT_CPA_TEST _PAGE_BIT_SPECIAL
11807+#define _PAGE_BIT_SPLITTING _PAGE_BIT_SPECIAL /* only valid on a PSE pmd */
11808 #define _PAGE_BIT_NX 63 /* No execute: only valid after cpuid check */
11809
11810 /* If _PAGE_BIT_PRESENT is clear, we use these: */
11811@@ -40,7 +39,6 @@
11812 #define _PAGE_DIRTY (_AT(pteval_t, 1) << _PAGE_BIT_DIRTY)
11813 #define _PAGE_PSE (_AT(pteval_t, 1) << _PAGE_BIT_PSE)
11814 #define _PAGE_GLOBAL (_AT(pteval_t, 1) << _PAGE_BIT_GLOBAL)
11815-#define _PAGE_UNUSED1 (_AT(pteval_t, 1) << _PAGE_BIT_UNUSED1)
11816 #define _PAGE_IOMAP (_AT(pteval_t, 1) << _PAGE_BIT_IOMAP)
11817 #define _PAGE_PAT (_AT(pteval_t, 1) << _PAGE_BIT_PAT)
11818 #define _PAGE_PAT_LARGE (_AT(pteval_t, 1) << _PAGE_BIT_PAT_LARGE)
11819@@ -57,8 +55,10 @@
11820
11821 #if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
11822 #define _PAGE_NX (_AT(pteval_t, 1) << _PAGE_BIT_NX)
11823-#else
11824+#elif defined(CONFIG_KMEMCHECK)
11825 #define _PAGE_NX (_AT(pteval_t, 0))
11826+#else
11827+#define _PAGE_NX (_AT(pteval_t, 1) << _PAGE_BIT_HIDDEN)
11828 #endif
11829
11830 #define _PAGE_FILE (_AT(pteval_t, 1) << _PAGE_BIT_FILE)
11831@@ -96,6 +96,9 @@
11832 #define PAGE_READONLY_EXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | \
11833 _PAGE_ACCESSED)
11834
11835+#define PAGE_READONLY_NOEXEC PAGE_READONLY
11836+#define PAGE_SHARED_NOEXEC PAGE_SHARED
11837+
11838 #define __PAGE_KERNEL_EXEC \
11839 (_PAGE_PRESENT | _PAGE_RW | _PAGE_DIRTY | _PAGE_ACCESSED | _PAGE_GLOBAL)
11840 #define __PAGE_KERNEL (__PAGE_KERNEL_EXEC | _PAGE_NX)
11841@@ -106,7 +109,7 @@
11842 #define __PAGE_KERNEL_WC (__PAGE_KERNEL | _PAGE_CACHE_WC)
11843 #define __PAGE_KERNEL_NOCACHE (__PAGE_KERNEL | _PAGE_PCD | _PAGE_PWT)
11844 #define __PAGE_KERNEL_UC_MINUS (__PAGE_KERNEL | _PAGE_PCD)
11845-#define __PAGE_KERNEL_VSYSCALL (__PAGE_KERNEL_RX | _PAGE_USER)
11846+#define __PAGE_KERNEL_VSYSCALL (__PAGE_KERNEL_RO | _PAGE_USER)
11847 #define __PAGE_KERNEL_VVAR (__PAGE_KERNEL_RO | _PAGE_USER)
11848 #define __PAGE_KERNEL_VVAR_NOCACHE (__PAGE_KERNEL_VVAR | _PAGE_PCD | _PAGE_PWT)
11849 #define __PAGE_KERNEL_LARGE (__PAGE_KERNEL | _PAGE_PSE)
11850@@ -168,8 +171,8 @@
11851 * bits are combined, this will alow user to access the high address mapped
11852 * VDSO in the presence of CONFIG_COMPAT_VDSO
11853 */
11854-#define PTE_IDENT_ATTR 0x003 /* PRESENT+RW */
11855-#define PDE_IDENT_ATTR 0x067 /* PRESENT+RW+USER+DIRTY+ACCESSED */
11856+#define PTE_IDENT_ATTR 0x063 /* PRESENT+RW+DIRTY+ACCESSED */
11857+#define PDE_IDENT_ATTR 0x063 /* PRESENT+RW+DIRTY+ACCESSED */
11858 #define PGD_IDENT_ATTR 0x001 /* PRESENT (no other attributes) */
11859 #endif
11860
11861@@ -207,7 +210,17 @@ static inline pgdval_t pgd_flags(pgd_t pgd)
11862 {
11863 return native_pgd_val(pgd) & PTE_FLAGS_MASK;
11864 }
11865+#endif
11866
11867+#if PAGETABLE_LEVELS == 3
11868+#include <asm-generic/pgtable-nopud.h>
11869+#endif
11870+
11871+#if PAGETABLE_LEVELS == 2
11872+#include <asm-generic/pgtable-nopmd.h>
11873+#endif
11874+
11875+#ifndef __ASSEMBLY__
11876 #if PAGETABLE_LEVELS > 3
11877 typedef struct { pudval_t pud; } pud_t;
11878
11879@@ -221,8 +234,6 @@ static inline pudval_t native_pud_val(pud_t pud)
11880 return pud.pud;
11881 }
11882 #else
11883-#include <asm-generic/pgtable-nopud.h>
11884-
11885 static inline pudval_t native_pud_val(pud_t pud)
11886 {
11887 return native_pgd_val(pud.pgd);
11888@@ -242,8 +253,6 @@ static inline pmdval_t native_pmd_val(pmd_t pmd)
11889 return pmd.pmd;
11890 }
11891 #else
11892-#include <asm-generic/pgtable-nopmd.h>
11893-
11894 static inline pmdval_t native_pmd_val(pmd_t pmd)
11895 {
11896 return native_pgd_val(pmd.pud.pgd);
11897@@ -283,7 +292,6 @@ typedef struct page *pgtable_t;
11898
11899 extern pteval_t __supported_pte_mask;
11900 extern void set_nx(void);
11901-extern int nx_enabled;
11902
11903 #define pgprot_writecombine pgprot_writecombine
11904 extern pgprot_t pgprot_writecombine(pgprot_t prot);
11905diff --git a/arch/x86/include/asm/processor-flags.h b/arch/x86/include/asm/processor-flags.h
11906index aea1d1d..680cf09 100644
11907--- a/arch/x86/include/asm/processor-flags.h
11908+++ b/arch/x86/include/asm/processor-flags.h
11909@@ -65,6 +65,7 @@
11910 #define X86_CR4_PCIDE 0x00020000 /* enable PCID support */
11911 #define X86_CR4_OSXSAVE 0x00040000 /* enable xsave and xrestore */
11912 #define X86_CR4_SMEP 0x00100000 /* enable SMEP support */
11913+#define X86_CR4_SMAP 0x00200000 /* enable SMAP support */
11914
11915 /*
11916 * x86-64 Task Priority Register, CR8
11917diff --git a/arch/x86/include/asm/processor.h b/arch/x86/include/asm/processor.h
11918index d048cad..45e350f 100644
11919--- a/arch/x86/include/asm/processor.h
11920+++ b/arch/x86/include/asm/processor.h
11921@@ -289,7 +289,7 @@ struct tss_struct {
11922
11923 } ____cacheline_aligned;
11924
11925-DECLARE_PER_CPU_SHARED_ALIGNED(struct tss_struct, init_tss);
11926+extern struct tss_struct init_tss[NR_CPUS];
11927
11928 /*
11929 * Save the original ist values for checking stack pointers during debugging
11930@@ -822,11 +822,18 @@ static inline void spin_lock_prefetch(const void *x)
11931 */
11932 #define TASK_SIZE PAGE_OFFSET
11933 #define TASK_SIZE_MAX TASK_SIZE
11934+
11935+#ifdef CONFIG_PAX_SEGMEXEC
11936+#define SEGMEXEC_TASK_SIZE (TASK_SIZE / 2)
11937+#define STACK_TOP ((current->mm->pax_flags & MF_PAX_SEGMEXEC)?SEGMEXEC_TASK_SIZE:TASK_SIZE)
11938+#else
11939 #define STACK_TOP TASK_SIZE
11940-#define STACK_TOP_MAX STACK_TOP
11941+#endif
11942+
11943+#define STACK_TOP_MAX TASK_SIZE
11944
11945 #define INIT_THREAD { \
11946- .sp0 = sizeof(init_stack) + (long)&init_stack, \
11947+ .sp0 = sizeof(init_stack) + (long)&init_stack - 8, \
11948 .vm86_info = NULL, \
11949 .sysenter_cs = __KERNEL_CS, \
11950 .io_bitmap_ptr = NULL, \
11951@@ -840,7 +847,7 @@ static inline void spin_lock_prefetch(const void *x)
11952 */
11953 #define INIT_TSS { \
11954 .x86_tss = { \
11955- .sp0 = sizeof(init_stack) + (long)&init_stack, \
11956+ .sp0 = sizeof(init_stack) + (long)&init_stack - 8, \
11957 .ss0 = __KERNEL_DS, \
11958 .ss1 = __KERNEL_CS, \
11959 .io_bitmap_base = INVALID_IO_BITMAP_OFFSET, \
11960@@ -851,11 +858,7 @@ static inline void spin_lock_prefetch(const void *x)
11961 extern unsigned long thread_saved_pc(struct task_struct *tsk);
11962
11963 #define THREAD_SIZE_LONGS (THREAD_SIZE/sizeof(unsigned long))
11964-#define KSTK_TOP(info) \
11965-({ \
11966- unsigned long *__ptr = (unsigned long *)(info); \
11967- (unsigned long)(&__ptr[THREAD_SIZE_LONGS]); \
11968-})
11969+#define KSTK_TOP(info) ((container_of(info, struct task_struct, tinfo))->thread.sp0)
11970
11971 /*
11972 * The below -8 is to reserve 8 bytes on top of the ring0 stack.
11973@@ -870,7 +873,7 @@ extern unsigned long thread_saved_pc(struct task_struct *tsk);
11974 #define task_pt_regs(task) \
11975 ({ \
11976 struct pt_regs *__regs__; \
11977- __regs__ = (struct pt_regs *)(KSTK_TOP(task_stack_page(task))-8); \
11978+ __regs__ = (struct pt_regs *)((task)->thread.sp0); \
11979 __regs__ - 1; \
11980 })
11981
11982@@ -880,13 +883,13 @@ extern unsigned long thread_saved_pc(struct task_struct *tsk);
11983 /*
11984 * User space process size. 47bits minus one guard page.
11985 */
11986-#define TASK_SIZE_MAX ((1UL << 47) - PAGE_SIZE)
11987+#define TASK_SIZE_MAX ((1UL << TASK_SIZE_MAX_SHIFT) - PAGE_SIZE)
11988
11989 /* This decides where the kernel will search for a free chunk of vm
11990 * space during mmap's.
11991 */
11992 #define IA32_PAGE_OFFSET ((current->personality & ADDR_LIMIT_3GB) ? \
11993- 0xc0000000 : 0xFFFFe000)
11994+ 0xc0000000 : 0xFFFFf000)
11995
11996 #define TASK_SIZE (test_thread_flag(TIF_ADDR32) ? \
11997 IA32_PAGE_OFFSET : TASK_SIZE_MAX)
11998@@ -897,11 +900,11 @@ extern unsigned long thread_saved_pc(struct task_struct *tsk);
11999 #define STACK_TOP_MAX TASK_SIZE_MAX
12000
12001 #define INIT_THREAD { \
12002- .sp0 = (unsigned long)&init_stack + sizeof(init_stack) \
12003+ .sp0 = (unsigned long)&init_stack + sizeof(init_stack) - 16 \
12004 }
12005
12006 #define INIT_TSS { \
12007- .x86_tss.sp0 = (unsigned long)&init_stack + sizeof(init_stack) \
12008+ .x86_tss.sp0 = (unsigned long)&init_stack + sizeof(init_stack) - 16 \
12009 }
12010
12011 /*
12012@@ -929,6 +932,10 @@ extern void start_thread(struct pt_regs *regs, unsigned long new_ip,
12013 */
12014 #define TASK_UNMAPPED_BASE (PAGE_ALIGN(TASK_SIZE / 3))
12015
12016+#ifdef CONFIG_PAX_SEGMEXEC
12017+#define SEGMEXEC_TASK_UNMAPPED_BASE (PAGE_ALIGN(SEGMEXEC_TASK_SIZE / 3))
12018+#endif
12019+
12020 #define KSTK_EIP(task) (task_pt_regs(task)->ip)
12021
12022 /* Get/set a process' ability to use the timestamp counter instruction */
12023@@ -989,12 +996,12 @@ extern bool cpu_has_amd_erratum(const int *);
12024 #define cpu_has_amd_erratum(x) (false)
12025 #endif /* CONFIG_CPU_SUP_AMD */
12026
12027-extern unsigned long arch_align_stack(unsigned long sp);
12028+#define arch_align_stack(x) ((x) & ~0xfUL)
12029 extern void free_init_pages(char *what, unsigned long begin, unsigned long end);
12030
12031 void default_idle(void);
12032 bool set_pm_idle_to_default(void);
12033
12034-void stop_this_cpu(void *dummy);
12035+void stop_this_cpu(void *dummy) __noreturn;
12036
12037 #endif /* _ASM_X86_PROCESSOR_H */
12038diff --git a/arch/x86/include/asm/ptrace.h b/arch/x86/include/asm/ptrace.h
12039index dcfde52..dbfea06 100644
12040--- a/arch/x86/include/asm/ptrace.h
12041+++ b/arch/x86/include/asm/ptrace.h
12042@@ -155,28 +155,29 @@ static inline unsigned long regs_return_value(struct pt_regs *regs)
12043 }
12044
12045 /*
12046- * user_mode_vm(regs) determines whether a register set came from user mode.
12047+ * user_mode(regs) determines whether a register set came from user mode.
12048 * This is true if V8086 mode was enabled OR if the register set was from
12049 * protected mode with RPL-3 CS value. This tricky test checks that with
12050 * one comparison. Many places in the kernel can bypass this full check
12051- * if they have already ruled out V8086 mode, so user_mode(regs) can be used.
12052+ * if they have already ruled out V8086 mode, so user_mode_novm(regs) can
12053+ * be used.
12054 */
12055-static inline int user_mode(struct pt_regs *regs)
12056+static inline int user_mode_novm(struct pt_regs *regs)
12057 {
12058 #ifdef CONFIG_X86_32
12059 return (regs->cs & SEGMENT_RPL_MASK) == USER_RPL;
12060 #else
12061- return !!(regs->cs & 3);
12062+ return !!(regs->cs & SEGMENT_RPL_MASK);
12063 #endif
12064 }
12065
12066-static inline int user_mode_vm(struct pt_regs *regs)
12067+static inline int user_mode(struct pt_regs *regs)
12068 {
12069 #ifdef CONFIG_X86_32
12070 return ((regs->cs & SEGMENT_RPL_MASK) | (regs->flags & X86_VM_MASK)) >=
12071 USER_RPL;
12072 #else
12073- return user_mode(regs);
12074+ return user_mode_novm(regs);
12075 #endif
12076 }
12077
12078@@ -192,15 +193,16 @@ static inline int v8086_mode(struct pt_regs *regs)
12079 #ifdef CONFIG_X86_64
12080 static inline bool user_64bit_mode(struct pt_regs *regs)
12081 {
12082+ unsigned long cs = regs->cs & 0xffff;
12083 #ifndef CONFIG_PARAVIRT
12084 /*
12085 * On non-paravirt systems, this is the only long mode CPL 3
12086 * selector. We do not allow long mode selectors in the LDT.
12087 */
12088- return regs->cs == __USER_CS;
12089+ return cs == __USER_CS;
12090 #else
12091 /* Headers are too twisted for this to go in paravirt.h. */
12092- return regs->cs == __USER_CS || regs->cs == pv_info.extra_user_64bit_cs;
12093+ return cs == __USER_CS || cs == pv_info.extra_user_64bit_cs;
12094 #endif
12095 }
12096 #endif
12097diff --git a/arch/x86/include/asm/realmode.h b/arch/x86/include/asm/realmode.h
12098index fe1ec5b..dc5c3fe 100644
12099--- a/arch/x86/include/asm/realmode.h
12100+++ b/arch/x86/include/asm/realmode.h
12101@@ -22,16 +22,14 @@ struct real_mode_header {
12102 #endif
12103 /* APM/BIOS reboot */
12104 u32 machine_real_restart_asm;
12105-#ifdef CONFIG_X86_64
12106 u32 machine_real_restart_seg;
12107-#endif
12108 };
12109
12110 /* This must match data at trampoline_32/64.S */
12111 struct trampoline_header {
12112 #ifdef CONFIG_X86_32
12113 u32 start;
12114- u16 gdt_pad;
12115+ u16 boot_cs;
12116 u16 gdt_limit;
12117 u32 gdt_base;
12118 #else
12119diff --git a/arch/x86/include/asm/reboot.h b/arch/x86/include/asm/reboot.h
12120index a82c4f1..ac45053 100644
12121--- a/arch/x86/include/asm/reboot.h
12122+++ b/arch/x86/include/asm/reboot.h
12123@@ -6,13 +6,13 @@
12124 struct pt_regs;
12125
12126 struct machine_ops {
12127- void (*restart)(char *cmd);
12128- void (*halt)(void);
12129- void (*power_off)(void);
12130+ void (* __noreturn restart)(char *cmd);
12131+ void (* __noreturn halt)(void);
12132+ void (* __noreturn power_off)(void);
12133 void (*shutdown)(void);
12134 void (*crash_shutdown)(struct pt_regs *);
12135- void (*emergency_restart)(void);
12136-};
12137+ void (* __noreturn emergency_restart)(void);
12138+} __no_const;
12139
12140 extern struct machine_ops machine_ops;
12141
12142diff --git a/arch/x86/include/asm/rwsem.h b/arch/x86/include/asm/rwsem.h
12143index 2dbe4a7..ce1db00 100644
12144--- a/arch/x86/include/asm/rwsem.h
12145+++ b/arch/x86/include/asm/rwsem.h
12146@@ -64,6 +64,14 @@ static inline void __down_read(struct rw_semaphore *sem)
12147 {
12148 asm volatile("# beginning down_read\n\t"
12149 LOCK_PREFIX _ASM_INC "(%1)\n\t"
12150+
12151+#ifdef CONFIG_PAX_REFCOUNT
12152+ "jno 0f\n"
12153+ LOCK_PREFIX _ASM_DEC "(%1)\n"
12154+ "int $4\n0:\n"
12155+ _ASM_EXTABLE(0b, 0b)
12156+#endif
12157+
12158 /* adds 0x00000001 */
12159 " jns 1f\n"
12160 " call call_rwsem_down_read_failed\n"
12161@@ -85,6 +93,14 @@ static inline int __down_read_trylock(struct rw_semaphore *sem)
12162 "1:\n\t"
12163 " mov %1,%2\n\t"
12164 " add %3,%2\n\t"
12165+
12166+#ifdef CONFIG_PAX_REFCOUNT
12167+ "jno 0f\n"
12168+ "sub %3,%2\n"
12169+ "int $4\n0:\n"
12170+ _ASM_EXTABLE(0b, 0b)
12171+#endif
12172+
12173 " jle 2f\n\t"
12174 LOCK_PREFIX " cmpxchg %2,%0\n\t"
12175 " jnz 1b\n\t"
12176@@ -104,6 +120,14 @@ static inline void __down_write_nested(struct rw_semaphore *sem, int subclass)
12177 long tmp;
12178 asm volatile("# beginning down_write\n\t"
12179 LOCK_PREFIX " xadd %1,(%2)\n\t"
12180+
12181+#ifdef CONFIG_PAX_REFCOUNT
12182+ "jno 0f\n"
12183+ "mov %1,(%2)\n"
12184+ "int $4\n0:\n"
12185+ _ASM_EXTABLE(0b, 0b)
12186+#endif
12187+
12188 /* adds 0xffff0001, returns the old value */
12189 " test %1,%1\n\t"
12190 /* was the count 0 before? */
12191@@ -141,6 +165,14 @@ static inline void __up_read(struct rw_semaphore *sem)
12192 long tmp;
12193 asm volatile("# beginning __up_read\n\t"
12194 LOCK_PREFIX " xadd %1,(%2)\n\t"
12195+
12196+#ifdef CONFIG_PAX_REFCOUNT
12197+ "jno 0f\n"
12198+ "mov %1,(%2)\n"
12199+ "int $4\n0:\n"
12200+ _ASM_EXTABLE(0b, 0b)
12201+#endif
12202+
12203 /* subtracts 1, returns the old value */
12204 " jns 1f\n\t"
12205 " call call_rwsem_wake\n" /* expects old value in %edx */
12206@@ -159,6 +191,14 @@ static inline void __up_write(struct rw_semaphore *sem)
12207 long tmp;
12208 asm volatile("# beginning __up_write\n\t"
12209 LOCK_PREFIX " xadd %1,(%2)\n\t"
12210+
12211+#ifdef CONFIG_PAX_REFCOUNT
12212+ "jno 0f\n"
12213+ "mov %1,(%2)\n"
12214+ "int $4\n0:\n"
12215+ _ASM_EXTABLE(0b, 0b)
12216+#endif
12217+
12218 /* subtracts 0xffff0001, returns the old value */
12219 " jns 1f\n\t"
12220 " call call_rwsem_wake\n" /* expects old value in %edx */
12221@@ -176,6 +216,14 @@ static inline void __downgrade_write(struct rw_semaphore *sem)
12222 {
12223 asm volatile("# beginning __downgrade_write\n\t"
12224 LOCK_PREFIX _ASM_ADD "%2,(%1)\n\t"
12225+
12226+#ifdef CONFIG_PAX_REFCOUNT
12227+ "jno 0f\n"
12228+ LOCK_PREFIX _ASM_SUB "%2,(%1)\n"
12229+ "int $4\n0:\n"
12230+ _ASM_EXTABLE(0b, 0b)
12231+#endif
12232+
12233 /*
12234 * transitions 0xZZZZ0001 -> 0xYYYY0001 (i386)
12235 * 0xZZZZZZZZ00000001 -> 0xYYYYYYYY00000001 (x86_64)
12236@@ -194,7 +242,15 @@ static inline void __downgrade_write(struct rw_semaphore *sem)
12237 */
12238 static inline void rwsem_atomic_add(long delta, struct rw_semaphore *sem)
12239 {
12240- asm volatile(LOCK_PREFIX _ASM_ADD "%1,%0"
12241+ asm volatile(LOCK_PREFIX _ASM_ADD "%1,%0\n"
12242+
12243+#ifdef CONFIG_PAX_REFCOUNT
12244+ "jno 0f\n"
12245+ LOCK_PREFIX _ASM_SUB "%1,%0\n"
12246+ "int $4\n0:\n"
12247+ _ASM_EXTABLE(0b, 0b)
12248+#endif
12249+
12250 : "+m" (sem->count)
12251 : "er" (delta));
12252 }
12253@@ -204,7 +260,7 @@ static inline void rwsem_atomic_add(long delta, struct rw_semaphore *sem)
12254 */
12255 static inline long rwsem_atomic_update(long delta, struct rw_semaphore *sem)
12256 {
12257- return delta + xadd(&sem->count, delta);
12258+ return delta + xadd_check_overflow(&sem->count, delta);
12259 }
12260
12261 #endif /* __KERNEL__ */
12262diff --git a/arch/x86/include/asm/segment.h b/arch/x86/include/asm/segment.h
12263index c48a950..c6d7468 100644
12264--- a/arch/x86/include/asm/segment.h
12265+++ b/arch/x86/include/asm/segment.h
12266@@ -64,10 +64,15 @@
12267 * 26 - ESPFIX small SS
12268 * 27 - per-cpu [ offset to per-cpu data area ]
12269 * 28 - stack_canary-20 [ for stack protector ]
12270- * 29 - unused
12271- * 30 - unused
12272+ * 29 - PCI BIOS CS
12273+ * 30 - PCI BIOS DS
12274 * 31 - TSS for double fault handler
12275 */
12276+#define GDT_ENTRY_KERNEXEC_EFI_CS (1)
12277+#define GDT_ENTRY_KERNEXEC_EFI_DS (2)
12278+#define __KERNEXEC_EFI_CS (GDT_ENTRY_KERNEXEC_EFI_CS*8)
12279+#define __KERNEXEC_EFI_DS (GDT_ENTRY_KERNEXEC_EFI_DS*8)
12280+
12281 #define GDT_ENTRY_TLS_MIN 6
12282 #define GDT_ENTRY_TLS_MAX (GDT_ENTRY_TLS_MIN + GDT_ENTRY_TLS_ENTRIES - 1)
12283
12284@@ -79,6 +84,8 @@
12285
12286 #define GDT_ENTRY_KERNEL_CS (GDT_ENTRY_KERNEL_BASE+0)
12287
12288+#define GDT_ENTRY_KERNEXEC_KERNEL_CS (4)
12289+
12290 #define GDT_ENTRY_KERNEL_DS (GDT_ENTRY_KERNEL_BASE+1)
12291
12292 #define GDT_ENTRY_TSS (GDT_ENTRY_KERNEL_BASE+4)
12293@@ -104,6 +111,12 @@
12294 #define __KERNEL_STACK_CANARY 0
12295 #endif
12296
12297+#define GDT_ENTRY_PCIBIOS_CS (GDT_ENTRY_KERNEL_BASE+17)
12298+#define __PCIBIOS_CS (GDT_ENTRY_PCIBIOS_CS * 8)
12299+
12300+#define GDT_ENTRY_PCIBIOS_DS (GDT_ENTRY_KERNEL_BASE+18)
12301+#define __PCIBIOS_DS (GDT_ENTRY_PCIBIOS_DS * 8)
12302+
12303 #define GDT_ENTRY_DOUBLEFAULT_TSS 31
12304
12305 /*
12306@@ -141,7 +154,7 @@
12307 */
12308
12309 /* Matches PNP_CS32 and PNP_CS16 (they must be consecutive) */
12310-#define SEGMENT_IS_PNP_CODE(x) (((x) & 0xf4) == GDT_ENTRY_PNPBIOS_BASE * 8)
12311+#define SEGMENT_IS_PNP_CODE(x) (((x) & 0xFFFCU) == PNP_CS32 || ((x) & 0xFFFCU) == PNP_CS16)
12312
12313
12314 #else
12315@@ -165,6 +178,8 @@
12316 #define __USER32_CS (GDT_ENTRY_DEFAULT_USER32_CS*8+3)
12317 #define __USER32_DS __USER_DS
12318
12319+#define GDT_ENTRY_KERNEXEC_KERNEL_CS 7
12320+
12321 #define GDT_ENTRY_TSS 8 /* needs two entries */
12322 #define GDT_ENTRY_LDT 10 /* needs two entries */
12323 #define GDT_ENTRY_TLS_MIN 12
12324@@ -185,6 +200,7 @@
12325 #endif
12326
12327 #define __KERNEL_CS (GDT_ENTRY_KERNEL_CS*8)
12328+#define __KERNEXEC_KERNEL_CS (GDT_ENTRY_KERNEXEC_KERNEL_CS*8)
12329 #define __KERNEL_DS (GDT_ENTRY_KERNEL_DS*8)
12330 #define __USER_DS (GDT_ENTRY_DEFAULT_USER_DS*8+3)
12331 #define __USER_CS (GDT_ENTRY_DEFAULT_USER_CS*8+3)
12332@@ -265,7 +281,7 @@ static inline unsigned long get_limit(unsigned long segment)
12333 {
12334 unsigned long __limit;
12335 asm("lsll %1,%0" : "=r" (__limit) : "r" (segment));
12336- return __limit + 1;
12337+ return __limit;
12338 }
12339
12340 #endif /* !__ASSEMBLY__ */
12341diff --git a/arch/x86/include/asm/smp.h b/arch/x86/include/asm/smp.h
12342index 4f19a15..9e14f27 100644
12343--- a/arch/x86/include/asm/smp.h
12344+++ b/arch/x86/include/asm/smp.h
12345@@ -36,7 +36,7 @@ DECLARE_PER_CPU_READ_MOSTLY(cpumask_var_t, cpu_core_map);
12346 /* cpus sharing the last level cache: */
12347 DECLARE_PER_CPU_READ_MOSTLY(cpumask_var_t, cpu_llc_shared_map);
12348 DECLARE_PER_CPU_READ_MOSTLY(u16, cpu_llc_id);
12349-DECLARE_PER_CPU_READ_MOSTLY(int, cpu_number);
12350+DECLARE_PER_CPU_READ_MOSTLY(unsigned int, cpu_number);
12351
12352 static inline struct cpumask *cpu_sibling_mask(int cpu)
12353 {
12354@@ -79,7 +79,7 @@ struct smp_ops {
12355
12356 void (*send_call_func_ipi)(const struct cpumask *mask);
12357 void (*send_call_func_single_ipi)(int cpu);
12358-};
12359+} __no_const;
12360
12361 /* Globals due to paravirt */
12362 extern void set_cpu_sibling_map(int cpu);
12363@@ -190,14 +190,8 @@ extern unsigned disabled_cpus __cpuinitdata;
12364 extern int safe_smp_processor_id(void);
12365
12366 #elif defined(CONFIG_X86_64_SMP)
12367-#define raw_smp_processor_id() (this_cpu_read(cpu_number))
12368-
12369-#define stack_smp_processor_id() \
12370-({ \
12371- struct thread_info *ti; \
12372- __asm__("andq %%rsp,%0; ":"=r" (ti) : "0" (CURRENT_MASK)); \
12373- ti->cpu; \
12374-})
12375+#define raw_smp_processor_id() (this_cpu_read(cpu_number))
12376+#define stack_smp_processor_id() raw_smp_processor_id()
12377 #define safe_smp_processor_id() smp_processor_id()
12378
12379 #endif
12380diff --git a/arch/x86/include/asm/spinlock.h b/arch/x86/include/asm/spinlock.h
12381index 33692ea..350a534 100644
12382--- a/arch/x86/include/asm/spinlock.h
12383+++ b/arch/x86/include/asm/spinlock.h
12384@@ -172,6 +172,14 @@ static inline int arch_write_can_lock(arch_rwlock_t *lock)
12385 static inline void arch_read_lock(arch_rwlock_t *rw)
12386 {
12387 asm volatile(LOCK_PREFIX READ_LOCK_SIZE(dec) " (%0)\n\t"
12388+
12389+#ifdef CONFIG_PAX_REFCOUNT
12390+ "jno 0f\n"
12391+ LOCK_PREFIX READ_LOCK_SIZE(inc) " (%0)\n"
12392+ "int $4\n0:\n"
12393+ _ASM_EXTABLE(0b, 0b)
12394+#endif
12395+
12396 "jns 1f\n"
12397 "call __read_lock_failed\n\t"
12398 "1:\n"
12399@@ -181,6 +189,14 @@ static inline void arch_read_lock(arch_rwlock_t *rw)
12400 static inline void arch_write_lock(arch_rwlock_t *rw)
12401 {
12402 asm volatile(LOCK_PREFIX WRITE_LOCK_SUB(%1) "(%0)\n\t"
12403+
12404+#ifdef CONFIG_PAX_REFCOUNT
12405+ "jno 0f\n"
12406+ LOCK_PREFIX WRITE_LOCK_ADD(%1) "(%0)\n"
12407+ "int $4\n0:\n"
12408+ _ASM_EXTABLE(0b, 0b)
12409+#endif
12410+
12411 "jz 1f\n"
12412 "call __write_lock_failed\n\t"
12413 "1:\n"
12414@@ -210,13 +226,29 @@ static inline int arch_write_trylock(arch_rwlock_t *lock)
12415
12416 static inline void arch_read_unlock(arch_rwlock_t *rw)
12417 {
12418- asm volatile(LOCK_PREFIX READ_LOCK_SIZE(inc) " %0"
12419+ asm volatile(LOCK_PREFIX READ_LOCK_SIZE(inc) " %0\n"
12420+
12421+#ifdef CONFIG_PAX_REFCOUNT
12422+ "jno 0f\n"
12423+ LOCK_PREFIX READ_LOCK_SIZE(dec) " %0\n"
12424+ "int $4\n0:\n"
12425+ _ASM_EXTABLE(0b, 0b)
12426+#endif
12427+
12428 :"+m" (rw->lock) : : "memory");
12429 }
12430
12431 static inline void arch_write_unlock(arch_rwlock_t *rw)
12432 {
12433- asm volatile(LOCK_PREFIX WRITE_LOCK_ADD(%1) "%0"
12434+ asm volatile(LOCK_PREFIX WRITE_LOCK_ADD(%1) "%0\n"
12435+
12436+#ifdef CONFIG_PAX_REFCOUNT
12437+ "jno 0f\n"
12438+ LOCK_PREFIX WRITE_LOCK_SUB(%1) "%0\n"
12439+ "int $4\n0:\n"
12440+ _ASM_EXTABLE(0b, 0b)
12441+#endif
12442+
12443 : "+m" (rw->write) : "i" (RW_LOCK_BIAS) : "memory");
12444 }
12445
12446diff --git a/arch/x86/include/asm/stackprotector.h b/arch/x86/include/asm/stackprotector.h
12447index 6a99859..03cb807 100644
12448--- a/arch/x86/include/asm/stackprotector.h
12449+++ b/arch/x86/include/asm/stackprotector.h
12450@@ -47,7 +47,7 @@
12451 * head_32 for boot CPU and setup_per_cpu_areas() for others.
12452 */
12453 #define GDT_STACK_CANARY_INIT \
12454- [GDT_ENTRY_STACK_CANARY] = GDT_ENTRY_INIT(0x4090, 0, 0x18),
12455+ [GDT_ENTRY_STACK_CANARY] = GDT_ENTRY_INIT(0x4090, 0, 0x17),
12456
12457 /*
12458 * Initialize the stackprotector canary value.
12459@@ -112,7 +112,7 @@ static inline void setup_stack_canary_segment(int cpu)
12460
12461 static inline void load_stack_canary_segment(void)
12462 {
12463-#ifdef CONFIG_X86_32
12464+#if defined(CONFIG_X86_32) && !defined(CONFIG_PAX_MEMORY_UDEREF)
12465 asm volatile ("mov %0, %%gs" : : "r" (0));
12466 #endif
12467 }
12468diff --git a/arch/x86/include/asm/stacktrace.h b/arch/x86/include/asm/stacktrace.h
12469index 70bbe39..4ae2bd4 100644
12470--- a/arch/x86/include/asm/stacktrace.h
12471+++ b/arch/x86/include/asm/stacktrace.h
12472@@ -11,28 +11,20 @@
12473
12474 extern int kstack_depth_to_print;
12475
12476-struct thread_info;
12477+struct task_struct;
12478 struct stacktrace_ops;
12479
12480-typedef unsigned long (*walk_stack_t)(struct thread_info *tinfo,
12481- unsigned long *stack,
12482- unsigned long bp,
12483- const struct stacktrace_ops *ops,
12484- void *data,
12485- unsigned long *end,
12486- int *graph);
12487+typedef unsigned long walk_stack_t(struct task_struct *task,
12488+ void *stack_start,
12489+ unsigned long *stack,
12490+ unsigned long bp,
12491+ const struct stacktrace_ops *ops,
12492+ void *data,
12493+ unsigned long *end,
12494+ int *graph);
12495
12496-extern unsigned long
12497-print_context_stack(struct thread_info *tinfo,
12498- unsigned long *stack, unsigned long bp,
12499- const struct stacktrace_ops *ops, void *data,
12500- unsigned long *end, int *graph);
12501-
12502-extern unsigned long
12503-print_context_stack_bp(struct thread_info *tinfo,
12504- unsigned long *stack, unsigned long bp,
12505- const struct stacktrace_ops *ops, void *data,
12506- unsigned long *end, int *graph);
12507+extern walk_stack_t print_context_stack;
12508+extern walk_stack_t print_context_stack_bp;
12509
12510 /* Generic stack tracer with callbacks */
12511
12512@@ -40,7 +32,7 @@ struct stacktrace_ops {
12513 void (*address)(void *data, unsigned long address, int reliable);
12514 /* On negative return stop dumping */
12515 int (*stack)(void *data, char *name);
12516- walk_stack_t walk_stack;
12517+ walk_stack_t *walk_stack;
12518 };
12519
12520 void dump_trace(struct task_struct *tsk, struct pt_regs *regs,
12521diff --git a/arch/x86/include/asm/switch_to.h b/arch/x86/include/asm/switch_to.h
12522index 4ec45b3..a4f0a8a 100644
12523--- a/arch/x86/include/asm/switch_to.h
12524+++ b/arch/x86/include/asm/switch_to.h
12525@@ -108,7 +108,7 @@ do { \
12526 "call __switch_to\n\t" \
12527 "movq "__percpu_arg([current_task])",%%rsi\n\t" \
12528 __switch_canary \
12529- "movq %P[thread_info](%%rsi),%%r8\n\t" \
12530+ "movq "__percpu_arg([thread_info])",%%r8\n\t" \
12531 "movq %%rax,%%rdi\n\t" \
12532 "testl %[_tif_fork],%P[ti_flags](%%r8)\n\t" \
12533 "jnz ret_from_fork\n\t" \
12534@@ -119,7 +119,7 @@ do { \
12535 [threadrsp] "i" (offsetof(struct task_struct, thread.sp)), \
12536 [ti_flags] "i" (offsetof(struct thread_info, flags)), \
12537 [_tif_fork] "i" (_TIF_FORK), \
12538- [thread_info] "i" (offsetof(struct task_struct, stack)), \
12539+ [thread_info] "m" (current_tinfo), \
12540 [current_task] "m" (current_task) \
12541 __switch_canary_iparam \
12542 : "memory", "cc" __EXTRA_CLOBBER)
12543diff --git a/arch/x86/include/asm/sys_ia32.h b/arch/x86/include/asm/sys_ia32.h
12544index 3fda9db4..4ca1c61 100644
12545--- a/arch/x86/include/asm/sys_ia32.h
12546+++ b/arch/x86/include/asm/sys_ia32.h
12547@@ -40,7 +40,7 @@ asmlinkage long sys32_sigaction(int, struct old_sigaction32 __user *,
12548 struct old_sigaction32 __user *);
12549 asmlinkage long sys32_alarm(unsigned int);
12550
12551-asmlinkage long sys32_waitpid(compat_pid_t, unsigned int *, int);
12552+asmlinkage long sys32_waitpid(compat_pid_t, unsigned int __user *, int);
12553 asmlinkage long sys32_sysfs(int, u32, u32);
12554
12555 asmlinkage long sys32_sched_rr_get_interval(compat_pid_t,
12556diff --git a/arch/x86/include/asm/thread_info.h b/arch/x86/include/asm/thread_info.h
12557index 89f794f..1422765 100644
12558--- a/arch/x86/include/asm/thread_info.h
12559+++ b/arch/x86/include/asm/thread_info.h
12560@@ -10,6 +10,7 @@
12561 #include <linux/compiler.h>
12562 #include <asm/page.h>
12563 #include <asm/types.h>
12564+#include <asm/percpu.h>
12565
12566 /*
12567 * low level task data that entry.S needs immediate access to
12568@@ -24,7 +25,6 @@ struct exec_domain;
12569 #include <linux/atomic.h>
12570
12571 struct thread_info {
12572- struct task_struct *task; /* main task structure */
12573 struct exec_domain *exec_domain; /* execution domain */
12574 __u32 flags; /* low level flags */
12575 __u32 status; /* thread synchronous flags */
12576@@ -34,19 +34,13 @@ struct thread_info {
12577 mm_segment_t addr_limit;
12578 struct restart_block restart_block;
12579 void __user *sysenter_return;
12580-#ifdef CONFIG_X86_32
12581- unsigned long previous_esp; /* ESP of the previous stack in
12582- case of nested (IRQ) stacks
12583- */
12584- __u8 supervisor_stack[0];
12585-#endif
12586+ unsigned long lowest_stack;
12587 unsigned int sig_on_uaccess_error:1;
12588 unsigned int uaccess_err:1; /* uaccess failed */
12589 };
12590
12591-#define INIT_THREAD_INFO(tsk) \
12592+#define INIT_THREAD_INFO \
12593 { \
12594- .task = &tsk, \
12595 .exec_domain = &default_exec_domain, \
12596 .flags = 0, \
12597 .cpu = 0, \
12598@@ -57,7 +51,7 @@ struct thread_info {
12599 }, \
12600 }
12601
12602-#define init_thread_info (init_thread_union.thread_info)
12603+#define init_thread_info (init_thread_union.stack)
12604 #define init_stack (init_thread_union.stack)
12605
12606 #else /* !__ASSEMBLY__ */
12607@@ -98,6 +92,7 @@ struct thread_info {
12608 #define TIF_SYSCALL_TRACEPOINT 28 /* syscall tracepoint instrumentation */
12609 #define TIF_ADDR32 29 /* 32-bit address space on 64 bits */
12610 #define TIF_X32 30 /* 32-bit native x86-64 binary */
12611+#define TIF_GRSEC_SETXID 31 /* update credentials on syscall entry/exit */
12612
12613 #define _TIF_SYSCALL_TRACE (1 << TIF_SYSCALL_TRACE)
12614 #define _TIF_NOTIFY_RESUME (1 << TIF_NOTIFY_RESUME)
12615@@ -122,16 +117,18 @@ struct thread_info {
12616 #define _TIF_SYSCALL_TRACEPOINT (1 << TIF_SYSCALL_TRACEPOINT)
12617 #define _TIF_ADDR32 (1 << TIF_ADDR32)
12618 #define _TIF_X32 (1 << TIF_X32)
12619+#define _TIF_GRSEC_SETXID (1 << TIF_GRSEC_SETXID)
12620
12621 /* work to do in syscall_trace_enter() */
12622 #define _TIF_WORK_SYSCALL_ENTRY \
12623 (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_EMU | _TIF_SYSCALL_AUDIT | \
12624- _TIF_SECCOMP | _TIF_SINGLESTEP | _TIF_SYSCALL_TRACEPOINT)
12625+ _TIF_SECCOMP | _TIF_SINGLESTEP | _TIF_SYSCALL_TRACEPOINT | \
12626+ _TIF_GRSEC_SETXID)
12627
12628 /* work to do in syscall_trace_leave() */
12629 #define _TIF_WORK_SYSCALL_EXIT \
12630 (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | _TIF_SINGLESTEP | \
12631- _TIF_SYSCALL_TRACEPOINT)
12632+ _TIF_SYSCALL_TRACEPOINT | _TIF_GRSEC_SETXID)
12633
12634 /* work to do on interrupt/exception return */
12635 #define _TIF_WORK_MASK \
12636@@ -141,7 +138,8 @@ struct thread_info {
12637
12638 /* work to do on any return to user space */
12639 #define _TIF_ALLWORK_MASK \
12640- ((0x0000FFFF & ~_TIF_SECCOMP) | _TIF_SYSCALL_TRACEPOINT)
12641+ ((0x0000FFFF & ~_TIF_SECCOMP) | _TIF_SYSCALL_TRACEPOINT | \
12642+ _TIF_GRSEC_SETXID)
12643
12644 /* Only used for 64 bit */
12645 #define _TIF_DO_NOTIFY_MASK \
12646@@ -157,45 +155,40 @@ struct thread_info {
12647
12648 #define PREEMPT_ACTIVE 0x10000000
12649
12650-#ifdef CONFIG_X86_32
12651-
12652-#define STACK_WARN (THREAD_SIZE/8)
12653-/*
12654- * macros/functions for gaining access to the thread information structure
12655- *
12656- * preempt_count needs to be 1 initially, until the scheduler is functional.
12657- */
12658-#ifndef __ASSEMBLY__
12659-
12660-
12661-/* how to get the current stack pointer from C */
12662-register unsigned long current_stack_pointer asm("esp") __used;
12663-
12664-/* how to get the thread information struct from C */
12665-static inline struct thread_info *current_thread_info(void)
12666-{
12667- return (struct thread_info *)
12668- (current_stack_pointer & ~(THREAD_SIZE - 1));
12669-}
12670-
12671-#else /* !__ASSEMBLY__ */
12672-
12673+#ifdef __ASSEMBLY__
12674 /* how to get the thread information struct from ASM */
12675 #define GET_THREAD_INFO(reg) \
12676- movl $-THREAD_SIZE, reg; \
12677- andl %esp, reg
12678+ mov PER_CPU_VAR(current_tinfo), reg
12679
12680 /* use this one if reg already contains %esp */
12681-#define GET_THREAD_INFO_WITH_ESP(reg) \
12682- andl $-THREAD_SIZE, reg
12683+#define GET_THREAD_INFO_WITH_ESP(reg) GET_THREAD_INFO(reg)
12684+#else
12685+/* how to get the thread information struct from C */
12686+DECLARE_PER_CPU(struct thread_info *, current_tinfo);
12687+
12688+static __always_inline struct thread_info *current_thread_info(void)
12689+{
12690+ return this_cpu_read_stable(current_tinfo);
12691+}
12692+#endif
12693+
12694+#ifdef CONFIG_X86_32
12695+
12696+#define STACK_WARN (THREAD_SIZE/8)
12697+/*
12698+ * macros/functions for gaining access to the thread information structure
12699+ *
12700+ * preempt_count needs to be 1 initially, until the scheduler is functional.
12701+ */
12702+#ifndef __ASSEMBLY__
12703+
12704+/* how to get the current stack pointer from C */
12705+register unsigned long current_stack_pointer asm("esp") __used;
12706
12707 #endif
12708
12709 #else /* X86_32 */
12710
12711-#include <asm/percpu.h>
12712-#define KERNEL_STACK_OFFSET (5*8)
12713-
12714 /*
12715 * macros/functions for gaining access to the thread information structure
12716 * preempt_count needs to be 1 initially, until the scheduler is functional.
12717@@ -203,27 +196,8 @@ static inline struct thread_info *current_thread_info(void)
12718 #ifndef __ASSEMBLY__
12719 DECLARE_PER_CPU(unsigned long, kernel_stack);
12720
12721-static inline struct thread_info *current_thread_info(void)
12722-{
12723- struct thread_info *ti;
12724- ti = (void *)(this_cpu_read_stable(kernel_stack) +
12725- KERNEL_STACK_OFFSET - THREAD_SIZE);
12726- return ti;
12727-}
12728-
12729-#else /* !__ASSEMBLY__ */
12730-
12731-/* how to get the thread information struct from ASM */
12732-#define GET_THREAD_INFO(reg) \
12733- movq PER_CPU_VAR(kernel_stack),reg ; \
12734- subq $(THREAD_SIZE-KERNEL_STACK_OFFSET),reg
12735-
12736-/*
12737- * Same if PER_CPU_VAR(kernel_stack) is, perhaps with some offset, already in
12738- * a certain register (to be used in assembler memory operands).
12739- */
12740-#define THREAD_INFO(reg, off) KERNEL_STACK_OFFSET+(off)-THREAD_SIZE(reg)
12741-
12742+/* how to get the current stack pointer from C */
12743+register unsigned long current_stack_pointer asm("rsp") __used;
12744 #endif
12745
12746 #endif /* !X86_32 */
12747@@ -284,5 +258,12 @@ static inline bool is_ia32_task(void)
12748 extern void arch_task_cache_init(void);
12749 extern int arch_dup_task_struct(struct task_struct *dst, struct task_struct *src);
12750 extern void arch_release_task_struct(struct task_struct *tsk);
12751+
12752+#define __HAVE_THREAD_FUNCTIONS
12753+#define task_thread_info(task) (&(task)->tinfo)
12754+#define task_stack_page(task) ((task)->stack)
12755+#define setup_thread_stack(p, org) do {} while (0)
12756+#define end_of_stack(p) ((unsigned long *)task_stack_page(p) + 1)
12757+
12758 #endif
12759 #endif /* _ASM_X86_THREAD_INFO_H */
12760diff --git a/arch/x86/include/asm/uaccess.h b/arch/x86/include/asm/uaccess.h
12761index e1f3a17..1ab364d 100644
12762--- a/arch/x86/include/asm/uaccess.h
12763+++ b/arch/x86/include/asm/uaccess.h
12764@@ -7,12 +7,15 @@
12765 #include <linux/compiler.h>
12766 #include <linux/thread_info.h>
12767 #include <linux/string.h>
12768+#include <linux/sched.h>
12769 #include <asm/asm.h>
12770 #include <asm/page.h>
12771
12772 #define VERIFY_READ 0
12773 #define VERIFY_WRITE 1
12774
12775+extern void check_object_size(const void *ptr, unsigned long n, bool to);
12776+
12777 /*
12778 * The fs value determines whether argument validity checking should be
12779 * performed or not. If get_fs() == USER_DS, checking is performed, with
12780@@ -28,7 +31,12 @@
12781
12782 #define get_ds() (KERNEL_DS)
12783 #define get_fs() (current_thread_info()->addr_limit)
12784+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
12785+void __set_fs(mm_segment_t x);
12786+void set_fs(mm_segment_t x);
12787+#else
12788 #define set_fs(x) (current_thread_info()->addr_limit = (x))
12789+#endif
12790
12791 #define segment_eq(a, b) ((a).seg == (b).seg)
12792
12793@@ -76,8 +84,33 @@
12794 * checks that the pointer is in the user space range - after calling
12795 * this function, memory access functions may still return -EFAULT.
12796 */
12797-#define access_ok(type, addr, size) \
12798- (likely(__range_not_ok(addr, size, user_addr_max()) == 0))
12799+#define __access_ok(type, addr, size) (likely(__range_not_ok(addr, size, user_addr_max()) == 0))
12800+#define access_ok(type, addr, size) \
12801+({ \
12802+ long __size = size; \
12803+ unsigned long __addr = (unsigned long)addr; \
12804+ unsigned long __addr_ao = __addr & PAGE_MASK; \
12805+ unsigned long __end_ao = __addr + __size - 1; \
12806+ bool __ret_ao = __range_not_ok(__addr, __size, user_addr_max()) == 0;\
12807+ if (__ret_ao && unlikely((__end_ao ^ __addr_ao) & PAGE_MASK)) { \
12808+ while(__addr_ao <= __end_ao) { \
12809+ char __c_ao; \
12810+ __addr_ao += PAGE_SIZE; \
12811+ if (__size > PAGE_SIZE) \
12812+ cond_resched(); \
12813+ if (__get_user(__c_ao, (char __user *)__addr)) \
12814+ break; \
12815+ if (type != VERIFY_WRITE) { \
12816+ __addr = __addr_ao; \
12817+ continue; \
12818+ } \
12819+ if (__put_user(__c_ao, (char __user *)__addr)) \
12820+ break; \
12821+ __addr = __addr_ao; \
12822+ } \
12823+ } \
12824+ __ret_ao; \
12825+})
12826
12827 /*
12828 * The exception table consists of pairs of addresses relative to the
12829@@ -188,12 +221,20 @@ extern int __get_user_bad(void);
12830 asm volatile("call __put_user_" #size : "=a" (__ret_pu) \
12831 : "0" ((typeof(*(ptr)))(x)), "c" (ptr) : "ebx")
12832
12833-
12834+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
12835+#define __copyuser_seg "gs;"
12836+#define __COPYUSER_SET_ES "pushl %%gs; popl %%es\n"
12837+#define __COPYUSER_RESTORE_ES "pushl %%ss; popl %%es\n"
12838+#else
12839+#define __copyuser_seg
12840+#define __COPYUSER_SET_ES
12841+#define __COPYUSER_RESTORE_ES
12842+#endif
12843
12844 #ifdef CONFIG_X86_32
12845 #define __put_user_asm_u64(x, addr, err, errret) \
12846- asm volatile("1: movl %%eax,0(%2)\n" \
12847- "2: movl %%edx,4(%2)\n" \
12848+ asm volatile("1: "__copyuser_seg"movl %%eax,0(%2)\n" \
12849+ "2: "__copyuser_seg"movl %%edx,4(%2)\n" \
12850 "3:\n" \
12851 ".section .fixup,\"ax\"\n" \
12852 "4: movl %3,%0\n" \
12853@@ -205,8 +246,8 @@ extern int __get_user_bad(void);
12854 : "A" (x), "r" (addr), "i" (errret), "0" (err))
12855
12856 #define __put_user_asm_ex_u64(x, addr) \
12857- asm volatile("1: movl %%eax,0(%1)\n" \
12858- "2: movl %%edx,4(%1)\n" \
12859+ asm volatile("1: "__copyuser_seg"movl %%eax,0(%1)\n" \
12860+ "2: "__copyuser_seg"movl %%edx,4(%1)\n" \
12861 "3:\n" \
12862 _ASM_EXTABLE_EX(1b, 2b) \
12863 _ASM_EXTABLE_EX(2b, 3b) \
12864@@ -258,7 +299,7 @@ extern void __put_user_8(void);
12865 __typeof__(*(ptr)) __pu_val; \
12866 __chk_user_ptr(ptr); \
12867 might_fault(); \
12868- __pu_val = x; \
12869+ __pu_val = (x); \
12870 switch (sizeof(*(ptr))) { \
12871 case 1: \
12872 __put_user_x(1, __pu_val, ptr, __ret_pu); \
12873@@ -379,7 +420,7 @@ do { \
12874 } while (0)
12875
12876 #define __get_user_asm(x, addr, err, itype, rtype, ltype, errret) \
12877- asm volatile("1: mov"itype" %2,%"rtype"1\n" \
12878+ asm volatile("1: "__copyuser_seg"mov"itype" %2,%"rtype"1\n"\
12879 "2:\n" \
12880 ".section .fixup,\"ax\"\n" \
12881 "3: mov %3,%0\n" \
12882@@ -387,7 +428,7 @@ do { \
12883 " jmp 2b\n" \
12884 ".previous\n" \
12885 _ASM_EXTABLE(1b, 3b) \
12886- : "=r" (err), ltype(x) \
12887+ : "=r" (err), ltype (x) \
12888 : "m" (__m(addr)), "i" (errret), "0" (err))
12889
12890 #define __get_user_size_ex(x, ptr, size) \
12891@@ -412,7 +453,7 @@ do { \
12892 } while (0)
12893
12894 #define __get_user_asm_ex(x, addr, itype, rtype, ltype) \
12895- asm volatile("1: mov"itype" %1,%"rtype"0\n" \
12896+ asm volatile("1: "__copyuser_seg"mov"itype" %1,%"rtype"0\n"\
12897 "2:\n" \
12898 _ASM_EXTABLE_EX(1b, 2b) \
12899 : ltype(x) : "m" (__m(addr)))
12900@@ -429,13 +470,24 @@ do { \
12901 int __gu_err; \
12902 unsigned long __gu_val; \
12903 __get_user_size(__gu_val, (ptr), (size), __gu_err, -EFAULT); \
12904- (x) = (__force __typeof__(*(ptr)))__gu_val; \
12905+ (x) = (__typeof__(*(ptr)))__gu_val; \
12906 __gu_err; \
12907 })
12908
12909 /* FIXME: this hack is definitely wrong -AK */
12910 struct __large_struct { unsigned long buf[100]; };
12911-#define __m(x) (*(struct __large_struct __user *)(x))
12912+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
12913+#define ____m(x) \
12914+({ \
12915+ unsigned long ____x = (unsigned long)(x); \
12916+ if (____x < PAX_USER_SHADOW_BASE) \
12917+ ____x += PAX_USER_SHADOW_BASE; \
12918+ (void __user *)____x; \
12919+})
12920+#else
12921+#define ____m(x) (x)
12922+#endif
12923+#define __m(x) (*(struct __large_struct __user *)____m(x))
12924
12925 /*
12926 * Tell gcc we read from memory instead of writing: this is because
12927@@ -443,7 +495,7 @@ struct __large_struct { unsigned long buf[100]; };
12928 * aliasing issues.
12929 */
12930 #define __put_user_asm(x, addr, err, itype, rtype, ltype, errret) \
12931- asm volatile("1: mov"itype" %"rtype"1,%2\n" \
12932+ asm volatile("1: "__copyuser_seg"mov"itype" %"rtype"1,%2\n"\
12933 "2:\n" \
12934 ".section .fixup,\"ax\"\n" \
12935 "3: mov %3,%0\n" \
12936@@ -451,10 +503,10 @@ struct __large_struct { unsigned long buf[100]; };
12937 ".previous\n" \
12938 _ASM_EXTABLE(1b, 3b) \
12939 : "=r"(err) \
12940- : ltype(x), "m" (__m(addr)), "i" (errret), "0" (err))
12941+ : ltype (x), "m" (__m(addr)), "i" (errret), "0" (err))
12942
12943 #define __put_user_asm_ex(x, addr, itype, rtype, ltype) \
12944- asm volatile("1: mov"itype" %"rtype"0,%1\n" \
12945+ asm volatile("1: "__copyuser_seg"mov"itype" %"rtype"0,%1\n"\
12946 "2:\n" \
12947 _ASM_EXTABLE_EX(1b, 2b) \
12948 : : ltype(x), "m" (__m(addr)))
12949@@ -493,8 +545,12 @@ struct __large_struct { unsigned long buf[100]; };
12950 * On error, the variable @x is set to zero.
12951 */
12952
12953+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
12954+#define __get_user(x, ptr) get_user((x), (ptr))
12955+#else
12956 #define __get_user(x, ptr) \
12957 __get_user_nocheck((x), (ptr), sizeof(*(ptr)))
12958+#endif
12959
12960 /**
12961 * __put_user: - Write a simple value into user space, with less checking.
12962@@ -516,8 +572,12 @@ struct __large_struct { unsigned long buf[100]; };
12963 * Returns zero on success, or -EFAULT on error.
12964 */
12965
12966+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
12967+#define __put_user(x, ptr) put_user((x), (ptr))
12968+#else
12969 #define __put_user(x, ptr) \
12970 __put_user_nocheck((__typeof__(*(ptr)))(x), (ptr), sizeof(*(ptr)))
12971+#endif
12972
12973 #define __get_user_unaligned __get_user
12974 #define __put_user_unaligned __put_user
12975@@ -535,7 +595,7 @@ struct __large_struct { unsigned long buf[100]; };
12976 #define get_user_ex(x, ptr) do { \
12977 unsigned long __gue_val; \
12978 __get_user_size_ex((__gue_val), (ptr), (sizeof(*(ptr)))); \
12979- (x) = (__force __typeof__(*(ptr)))__gue_val; \
12980+ (x) = (__typeof__(*(ptr)))__gue_val; \
12981 } while (0)
12982
12983 #ifdef CONFIG_X86_WP_WORKS_OK
12984diff --git a/arch/x86/include/asm/uaccess_32.h b/arch/x86/include/asm/uaccess_32.h
12985index 576e39b..ccd0a39 100644
12986--- a/arch/x86/include/asm/uaccess_32.h
12987+++ b/arch/x86/include/asm/uaccess_32.h
12988@@ -11,15 +11,15 @@
12989 #include <asm/page.h>
12990
12991 unsigned long __must_check __copy_to_user_ll
12992- (void __user *to, const void *from, unsigned long n);
12993+ (void __user *to, const void *from, unsigned long n) __size_overflow(3);
12994 unsigned long __must_check __copy_from_user_ll
12995- (void *to, const void __user *from, unsigned long n);
12996+ (void *to, const void __user *from, unsigned long n) __size_overflow(3);
12997 unsigned long __must_check __copy_from_user_ll_nozero
12998- (void *to, const void __user *from, unsigned long n);
12999+ (void *to, const void __user *from, unsigned long n) __size_overflow(3);
13000 unsigned long __must_check __copy_from_user_ll_nocache
13001- (void *to, const void __user *from, unsigned long n);
13002+ (void *to, const void __user *from, unsigned long n) __size_overflow(3);
13003 unsigned long __must_check __copy_from_user_ll_nocache_nozero
13004- (void *to, const void __user *from, unsigned long n);
13005+ (void *to, const void __user *from, unsigned long n) __size_overflow(3);
13006
13007 /**
13008 * __copy_to_user_inatomic: - Copy a block of data into user space, with less checking.
13009@@ -43,6 +43,9 @@ unsigned long __must_check __copy_from_user_ll_nocache_nozero
13010 static __always_inline unsigned long __must_check
13011 __copy_to_user_inatomic(void __user *to, const void *from, unsigned long n)
13012 {
13013+ if ((long)n < 0)
13014+ return n;
13015+
13016 if (__builtin_constant_p(n)) {
13017 unsigned long ret;
13018
13019@@ -61,6 +64,8 @@ __copy_to_user_inatomic(void __user *to, const void *from, unsigned long n)
13020 return ret;
13021 }
13022 }
13023+ if (!__builtin_constant_p(n))
13024+ check_object_size(from, n, true);
13025 return __copy_to_user_ll(to, from, n);
13026 }
13027
13028@@ -82,12 +87,16 @@ static __always_inline unsigned long __must_check
13029 __copy_to_user(void __user *to, const void *from, unsigned long n)
13030 {
13031 might_fault();
13032+
13033 return __copy_to_user_inatomic(to, from, n);
13034 }
13035
13036 static __always_inline unsigned long
13037 __copy_from_user_inatomic(void *to, const void __user *from, unsigned long n)
13038 {
13039+ if ((long)n < 0)
13040+ return n;
13041+
13042 /* Avoid zeroing the tail if the copy fails..
13043 * If 'n' is constant and 1, 2, or 4, we do still zero on a failure,
13044 * but as the zeroing behaviour is only significant when n is not
13045@@ -137,6 +146,10 @@ static __always_inline unsigned long
13046 __copy_from_user(void *to, const void __user *from, unsigned long n)
13047 {
13048 might_fault();
13049+
13050+ if ((long)n < 0)
13051+ return n;
13052+
13053 if (__builtin_constant_p(n)) {
13054 unsigned long ret;
13055
13056@@ -152,6 +165,8 @@ __copy_from_user(void *to, const void __user *from, unsigned long n)
13057 return ret;
13058 }
13059 }
13060+ if (!__builtin_constant_p(n))
13061+ check_object_size(to, n, false);
13062 return __copy_from_user_ll(to, from, n);
13063 }
13064
13065@@ -159,6 +174,10 @@ static __always_inline unsigned long __copy_from_user_nocache(void *to,
13066 const void __user *from, unsigned long n)
13067 {
13068 might_fault();
13069+
13070+ if ((long)n < 0)
13071+ return n;
13072+
13073 if (__builtin_constant_p(n)) {
13074 unsigned long ret;
13075
13076@@ -181,15 +200,19 @@ static __always_inline unsigned long
13077 __copy_from_user_inatomic_nocache(void *to, const void __user *from,
13078 unsigned long n)
13079 {
13080- return __copy_from_user_ll_nocache_nozero(to, from, n);
13081+ if ((long)n < 0)
13082+ return n;
13083+
13084+ return __copy_from_user_ll_nocache_nozero(to, from, n);
13085 }
13086
13087-unsigned long __must_check copy_to_user(void __user *to,
13088- const void *from, unsigned long n);
13089-unsigned long __must_check _copy_from_user(void *to,
13090- const void __user *from,
13091- unsigned long n);
13092-
13093+extern void copy_to_user_overflow(void)
13094+#ifdef CONFIG_DEBUG_STRICT_USER_COPY_CHECKS
13095+ __compiletime_error("copy_to_user() buffer size is not provably correct")
13096+#else
13097+ __compiletime_warning("copy_to_user() buffer size is not provably correct")
13098+#endif
13099+;
13100
13101 extern void copy_from_user_overflow(void)
13102 #ifdef CONFIG_DEBUG_STRICT_USER_COPY_CHECKS
13103@@ -199,21 +222,65 @@ extern void copy_from_user_overflow(void)
13104 #endif
13105 ;
13106
13107-static inline unsigned long __must_check copy_from_user(void *to,
13108- const void __user *from,
13109- unsigned long n)
13110+/**
13111+ * copy_to_user: - Copy a block of data into user space.
13112+ * @to: Destination address, in user space.
13113+ * @from: Source address, in kernel space.
13114+ * @n: Number of bytes to copy.
13115+ *
13116+ * Context: User context only. This function may sleep.
13117+ *
13118+ * Copy data from kernel space to user space.
13119+ *
13120+ * Returns number of bytes that could not be copied.
13121+ * On success, this will be zero.
13122+ */
13123+static inline unsigned long __must_check
13124+copy_to_user(void __user *to, const void *from, unsigned long n)
13125 {
13126- int sz = __compiletime_object_size(to);
13127+ size_t sz = __compiletime_object_size(from);
13128
13129- if (likely(sz == -1 || sz >= n))
13130- n = _copy_from_user(to, from, n);
13131- else
13132+ if (unlikely(sz != (size_t)-1 && sz < n))
13133+ copy_to_user_overflow();
13134+ else if (access_ok(VERIFY_WRITE, to, n))
13135+ n = __copy_to_user(to, from, n);
13136+ return n;
13137+}
13138+
13139+/**
13140+ * copy_from_user: - Copy a block of data from user space.
13141+ * @to: Destination address, in kernel space.
13142+ * @from: Source address, in user space.
13143+ * @n: Number of bytes to copy.
13144+ *
13145+ * Context: User context only. This function may sleep.
13146+ *
13147+ * Copy data from user space to kernel space.
13148+ *
13149+ * Returns number of bytes that could not be copied.
13150+ * On success, this will be zero.
13151+ *
13152+ * If some data could not be copied, this function will pad the copied
13153+ * data to the requested size using zero bytes.
13154+ */
13155+static inline unsigned long __must_check
13156+copy_from_user(void *to, const void __user *from, unsigned long n)
13157+{
13158+ size_t sz = __compiletime_object_size(to);
13159+
13160+ if (unlikely(sz != (size_t)-1 && sz < n))
13161 copy_from_user_overflow();
13162-
13163+ else if (access_ok(VERIFY_READ, from, n))
13164+ n = __copy_from_user(to, from, n);
13165+ else if ((long)n > 0) {
13166+ if (!__builtin_constant_p(n))
13167+ check_object_size(to, n, false);
13168+ memset(to, 0, n);
13169+ }
13170 return n;
13171 }
13172
13173-unsigned long __must_check clear_user(void __user *mem, unsigned long len);
13174-unsigned long __must_check __clear_user(void __user *mem, unsigned long len);
13175+unsigned long __must_check clear_user(void __user *mem, unsigned long len) __size_overflow(2);
13176+unsigned long __must_check __clear_user(void __user *mem, unsigned long len) __size_overflow(2);
13177
13178 #endif /* _ASM_X86_UACCESS_32_H */
13179diff --git a/arch/x86/include/asm/uaccess_64.h b/arch/x86/include/asm/uaccess_64.h
13180index d8def8b..6052b20 100644
13181--- a/arch/x86/include/asm/uaccess_64.h
13182+++ b/arch/x86/include/asm/uaccess_64.h
13183@@ -10,6 +10,9 @@
13184 #include <asm/alternative.h>
13185 #include <asm/cpufeature.h>
13186 #include <asm/page.h>
13187+#include <asm/pgtable.h>
13188+
13189+#define set_fs(x) (current_thread_info()->addr_limit = (x))
13190
13191 /*
13192 * Copy To/From Userspace
13193@@ -17,13 +20,13 @@
13194
13195 /* Handles exceptions in both to and from, but doesn't do access_ok */
13196 __must_check unsigned long
13197-copy_user_enhanced_fast_string(void *to, const void *from, unsigned len);
13198+copy_user_enhanced_fast_string(void *to, const void *from, unsigned len) __size_overflow(3);
13199 __must_check unsigned long
13200-copy_user_generic_string(void *to, const void *from, unsigned len);
13201+copy_user_generic_string(void *to, const void *from, unsigned len) __size_overflow(3);
13202 __must_check unsigned long
13203-copy_user_generic_unrolled(void *to, const void *from, unsigned len);
13204+copy_user_generic_unrolled(void *to, const void *from, unsigned len) __size_overflow(3);
13205
13206-static __always_inline __must_check unsigned long
13207+static __always_inline __must_check __size_overflow(3) unsigned long
13208 copy_user_generic(void *to, const void *from, unsigned len)
13209 {
13210 unsigned ret;
13211@@ -41,142 +44,205 @@ copy_user_generic(void *to, const void *from, unsigned len)
13212 ASM_OUTPUT2("=a" (ret), "=D" (to), "=S" (from),
13213 "=d" (len)),
13214 "1" (to), "2" (from), "3" (len)
13215- : "memory", "rcx", "r8", "r9", "r10", "r11");
13216+ : "memory", "rcx", "r8", "r9", "r11");
13217 return ret;
13218 }
13219
13220+static __always_inline __must_check unsigned long
13221+__copy_to_user(void __user *to, const void *from, unsigned long len) __size_overflow(3);
13222+static __always_inline __must_check unsigned long
13223+__copy_from_user(void *to, const void __user *from, unsigned long len) __size_overflow(3);
13224 __must_check unsigned long
13225-_copy_to_user(void __user *to, const void *from, unsigned len);
13226-__must_check unsigned long
13227-_copy_from_user(void *to, const void __user *from, unsigned len);
13228-__must_check unsigned long
13229-copy_in_user(void __user *to, const void __user *from, unsigned len);
13230+copy_in_user(void __user *to, const void __user *from, unsigned long len) __size_overflow(3);
13231+
13232+extern void copy_to_user_overflow(void)
13233+#ifdef CONFIG_DEBUG_STRICT_USER_COPY_CHECKS
13234+ __compiletime_error("copy_to_user() buffer size is not provably correct")
13235+#else
13236+ __compiletime_warning("copy_to_user() buffer size is not provably correct")
13237+#endif
13238+;
13239+
13240+extern void copy_from_user_overflow(void)
13241+#ifdef CONFIG_DEBUG_STRICT_USER_COPY_CHECKS
13242+ __compiletime_error("copy_from_user() buffer size is not provably correct")
13243+#else
13244+ __compiletime_warning("copy_from_user() buffer size is not provably correct")
13245+#endif
13246+;
13247
13248 static inline unsigned long __must_check copy_from_user(void *to,
13249 const void __user *from,
13250 unsigned long n)
13251 {
13252- int sz = __compiletime_object_size(to);
13253-
13254 might_fault();
13255- if (likely(sz == -1 || sz >= n))
13256- n = _copy_from_user(to, from, n);
13257-#ifdef CONFIG_DEBUG_VM
13258- else
13259- WARN(1, "Buffer overflow detected!\n");
13260-#endif
13261+
13262+ if (access_ok(VERIFY_READ, from, n))
13263+ n = __copy_from_user(to, from, n);
13264+ else if (n < INT_MAX) {
13265+ if (!__builtin_constant_p(n))
13266+ check_object_size(to, n, false);
13267+ memset(to, 0, n);
13268+ }
13269 return n;
13270 }
13271
13272 static __always_inline __must_check
13273-int copy_to_user(void __user *dst, const void *src, unsigned size)
13274+int copy_to_user(void __user *dst, const void *src, unsigned long size)
13275 {
13276 might_fault();
13277
13278- return _copy_to_user(dst, src, size);
13279+ if (access_ok(VERIFY_WRITE, dst, size))
13280+ size = __copy_to_user(dst, src, size);
13281+ return size;
13282 }
13283
13284 static __always_inline __must_check
13285-int __copy_from_user(void *dst, const void __user *src, unsigned size)
13286+unsigned long __copy_from_user(void *dst, const void __user *src, unsigned long size)
13287 {
13288- int ret = 0;
13289+ size_t sz = __compiletime_object_size(dst);
13290+ unsigned ret = 0;
13291
13292 might_fault();
13293- if (!__builtin_constant_p(size))
13294- return copy_user_generic(dst, (__force void *)src, size);
13295+
13296+ if (size > INT_MAX)
13297+ return size;
13298+
13299+#ifdef CONFIG_PAX_MEMORY_UDEREF
13300+ if (!__access_ok(VERIFY_READ, src, size))
13301+ return size;
13302+#endif
13303+
13304+ if (unlikely(sz != (size_t)-1 && sz < size)) {
13305+ copy_from_user_overflow();
13306+ return size;
13307+ }
13308+
13309+ if (!__builtin_constant_p(size)) {
13310+ check_object_size(dst, size, false);
13311+ return copy_user_generic(dst, (__force_kernel const void *)____m(src), size);
13312+ }
13313 switch (size) {
13314- case 1:__get_user_asm(*(u8 *)dst, (u8 __user *)src,
13315+ case 1:__get_user_asm(*(u8 *)dst, (const u8 __user *)src,
13316 ret, "b", "b", "=q", 1);
13317 return ret;
13318- case 2:__get_user_asm(*(u16 *)dst, (u16 __user *)src,
13319+ case 2:__get_user_asm(*(u16 *)dst, (const u16 __user *)src,
13320 ret, "w", "w", "=r", 2);
13321 return ret;
13322- case 4:__get_user_asm(*(u32 *)dst, (u32 __user *)src,
13323+ case 4:__get_user_asm(*(u32 *)dst, (const u32 __user *)src,
13324 ret, "l", "k", "=r", 4);
13325 return ret;
13326- case 8:__get_user_asm(*(u64 *)dst, (u64 __user *)src,
13327+ case 8:__get_user_asm(*(u64 *)dst, (const u64 __user *)src,
13328 ret, "q", "", "=r", 8);
13329 return ret;
13330 case 10:
13331- __get_user_asm(*(u64 *)dst, (u64 __user *)src,
13332+ __get_user_asm(*(u64 *)dst, (const u64 __user *)src,
13333 ret, "q", "", "=r", 10);
13334 if (unlikely(ret))
13335 return ret;
13336 __get_user_asm(*(u16 *)(8 + (char *)dst),
13337- (u16 __user *)(8 + (char __user *)src),
13338+ (const u16 __user *)(8 + (const char __user *)src),
13339 ret, "w", "w", "=r", 2);
13340 return ret;
13341 case 16:
13342- __get_user_asm(*(u64 *)dst, (u64 __user *)src,
13343+ __get_user_asm(*(u64 *)dst, (const u64 __user *)src,
13344 ret, "q", "", "=r", 16);
13345 if (unlikely(ret))
13346 return ret;
13347 __get_user_asm(*(u64 *)(8 + (char *)dst),
13348- (u64 __user *)(8 + (char __user *)src),
13349+ (const u64 __user *)(8 + (const char __user *)src),
13350 ret, "q", "", "=r", 8);
13351 return ret;
13352 default:
13353- return copy_user_generic(dst, (__force void *)src, size);
13354+ return copy_user_generic(dst, (__force_kernel const void *)____m(src), size);
13355 }
13356 }
13357
13358 static __always_inline __must_check
13359-int __copy_to_user(void __user *dst, const void *src, unsigned size)
13360+unsigned long __copy_to_user(void __user *dst, const void *src, unsigned long size)
13361 {
13362- int ret = 0;
13363+ size_t sz = __compiletime_object_size(src);
13364+ unsigned ret = 0;
13365
13366 might_fault();
13367- if (!__builtin_constant_p(size))
13368- return copy_user_generic((__force void *)dst, src, size);
13369+
13370+ if (size > INT_MAX)
13371+ return size;
13372+
13373+#ifdef CONFIG_PAX_MEMORY_UDEREF
13374+ if (!__access_ok(VERIFY_WRITE, dst, size))
13375+ return size;
13376+#endif
13377+
13378+ if (unlikely(sz != (size_t)-1 && sz < size)) {
13379+ copy_to_user_overflow();
13380+ return size;
13381+ }
13382+
13383+ if (!__builtin_constant_p(size)) {
13384+ check_object_size(src, size, true);
13385+ return copy_user_generic((__force_kernel void *)____m(dst), src, size);
13386+ }
13387 switch (size) {
13388- case 1:__put_user_asm(*(u8 *)src, (u8 __user *)dst,
13389+ case 1:__put_user_asm(*(const u8 *)src, (u8 __user *)dst,
13390 ret, "b", "b", "iq", 1);
13391 return ret;
13392- case 2:__put_user_asm(*(u16 *)src, (u16 __user *)dst,
13393+ case 2:__put_user_asm(*(const u16 *)src, (u16 __user *)dst,
13394 ret, "w", "w", "ir", 2);
13395 return ret;
13396- case 4:__put_user_asm(*(u32 *)src, (u32 __user *)dst,
13397+ case 4:__put_user_asm(*(const u32 *)src, (u32 __user *)dst,
13398 ret, "l", "k", "ir", 4);
13399 return ret;
13400- case 8:__put_user_asm(*(u64 *)src, (u64 __user *)dst,
13401+ case 8:__put_user_asm(*(const u64 *)src, (u64 __user *)dst,
13402 ret, "q", "", "er", 8);
13403 return ret;
13404 case 10:
13405- __put_user_asm(*(u64 *)src, (u64 __user *)dst,
13406+ __put_user_asm(*(const u64 *)src, (u64 __user *)dst,
13407 ret, "q", "", "er", 10);
13408 if (unlikely(ret))
13409 return ret;
13410 asm("":::"memory");
13411- __put_user_asm(4[(u16 *)src], 4 + (u16 __user *)dst,
13412+ __put_user_asm(4[(const u16 *)src], 4 + (u16 __user *)dst,
13413 ret, "w", "w", "ir", 2);
13414 return ret;
13415 case 16:
13416- __put_user_asm(*(u64 *)src, (u64 __user *)dst,
13417+ __put_user_asm(*(const u64 *)src, (u64 __user *)dst,
13418 ret, "q", "", "er", 16);
13419 if (unlikely(ret))
13420 return ret;
13421 asm("":::"memory");
13422- __put_user_asm(1[(u64 *)src], 1 + (u64 __user *)dst,
13423+ __put_user_asm(1[(const u64 *)src], 1 + (u64 __user *)dst,
13424 ret, "q", "", "er", 8);
13425 return ret;
13426 default:
13427- return copy_user_generic((__force void *)dst, src, size);
13428+ return copy_user_generic((__force_kernel void *)____m(dst), src, size);
13429 }
13430 }
13431
13432 static __always_inline __must_check
13433-int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
13434+unsigned long __copy_in_user(void __user *dst, const void __user *src, unsigned long size)
13435 {
13436- int ret = 0;
13437+ unsigned ret = 0;
13438
13439 might_fault();
13440+
13441+ if (size > INT_MAX)
13442+ return size;
13443+
13444+#ifdef CONFIG_PAX_MEMORY_UDEREF
13445+ if (!__access_ok(VERIFY_READ, src, size))
13446+ return size;
13447+ if (!__access_ok(VERIFY_WRITE, dst, size))
13448+ return size;
13449+#endif
13450+
13451 if (!__builtin_constant_p(size))
13452- return copy_user_generic((__force void *)dst,
13453- (__force void *)src, size);
13454+ return copy_user_generic((__force_kernel void *)____m(dst),
13455+ (__force_kernel const void *)____m(src), size);
13456 switch (size) {
13457 case 1: {
13458 u8 tmp;
13459- __get_user_asm(tmp, (u8 __user *)src,
13460+ __get_user_asm(tmp, (const u8 __user *)src,
13461 ret, "b", "b", "=q", 1);
13462 if (likely(!ret))
13463 __put_user_asm(tmp, (u8 __user *)dst,
13464@@ -185,7 +251,7 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
13465 }
13466 case 2: {
13467 u16 tmp;
13468- __get_user_asm(tmp, (u16 __user *)src,
13469+ __get_user_asm(tmp, (const u16 __user *)src,
13470 ret, "w", "w", "=r", 2);
13471 if (likely(!ret))
13472 __put_user_asm(tmp, (u16 __user *)dst,
13473@@ -195,7 +261,7 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
13474
13475 case 4: {
13476 u32 tmp;
13477- __get_user_asm(tmp, (u32 __user *)src,
13478+ __get_user_asm(tmp, (const u32 __user *)src,
13479 ret, "l", "k", "=r", 4);
13480 if (likely(!ret))
13481 __put_user_asm(tmp, (u32 __user *)dst,
13482@@ -204,7 +270,7 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
13483 }
13484 case 8: {
13485 u64 tmp;
13486- __get_user_asm(tmp, (u64 __user *)src,
13487+ __get_user_asm(tmp, (const u64 __user *)src,
13488 ret, "q", "", "=r", 8);
13489 if (likely(!ret))
13490 __put_user_asm(tmp, (u64 __user *)dst,
13491@@ -212,44 +278,65 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
13492 return ret;
13493 }
13494 default:
13495- return copy_user_generic((__force void *)dst,
13496- (__force void *)src, size);
13497+ return copy_user_generic((__force_kernel void *)____m(dst),
13498+ (__force_kernel const void *)____m(src), size);
13499 }
13500 }
13501
13502-__must_check unsigned long clear_user(void __user *mem, unsigned long len);
13503-__must_check unsigned long __clear_user(void __user *mem, unsigned long len);
13504+__must_check unsigned long clear_user(void __user *mem, unsigned long len) __size_overflow(2);
13505+__must_check unsigned long __clear_user(void __user *mem, unsigned long len) __size_overflow(2);
13506
13507 static __must_check __always_inline int
13508-__copy_from_user_inatomic(void *dst, const void __user *src, unsigned size)
13509+__copy_from_user_inatomic(void *dst, const void __user *src, unsigned long size)
13510 {
13511- return copy_user_generic(dst, (__force const void *)src, size);
13512+ if (size > INT_MAX)
13513+ return size;
13514+
13515+ return copy_user_generic(dst, (__force_kernel const void *)____m(src), size);
13516 }
13517
13518-static __must_check __always_inline int
13519-__copy_to_user_inatomic(void __user *dst, const void *src, unsigned size)
13520+static __must_check __always_inline unsigned long
13521+__copy_to_user_inatomic(void __user *dst, const void *src, unsigned long size)
13522 {
13523- return copy_user_generic((__force void *)dst, src, size);
13524+ if (size > INT_MAX)
13525+ return size;
13526+
13527+ return copy_user_generic((__force_kernel void *)____m(dst), src, size);
13528 }
13529
13530-extern long __copy_user_nocache(void *dst, const void __user *src,
13531- unsigned size, int zerorest);
13532+extern unsigned long __copy_user_nocache(void *dst, const void __user *src,
13533+ unsigned long size, int zerorest) __size_overflow(3);
13534
13535-static inline int
13536-__copy_from_user_nocache(void *dst, const void __user *src, unsigned size)
13537+static inline unsigned long __copy_from_user_nocache(void *dst, const void __user *src, unsigned long size)
13538 {
13539 might_sleep();
13540+
13541+ if (size > INT_MAX)
13542+ return size;
13543+
13544+#ifdef CONFIG_PAX_MEMORY_UDEREF
13545+ if (!__access_ok(VERIFY_READ, src, size))
13546+ return size;
13547+#endif
13548+
13549 return __copy_user_nocache(dst, src, size, 1);
13550 }
13551
13552-static inline int
13553-__copy_from_user_inatomic_nocache(void *dst, const void __user *src,
13554- unsigned size)
13555+static inline unsigned long __copy_from_user_inatomic_nocache(void *dst, const void __user *src,
13556+ unsigned long size)
13557 {
13558+ if (size > INT_MAX)
13559+ return size;
13560+
13561+#ifdef CONFIG_PAX_MEMORY_UDEREF
13562+ if (!__access_ok(VERIFY_READ, src, size))
13563+ return size;
13564+#endif
13565+
13566 return __copy_user_nocache(dst, src, size, 0);
13567 }
13568
13569-unsigned long
13570-copy_user_handle_tail(char *to, char *from, unsigned len, unsigned zerorest);
13571+extern unsigned long
13572+copy_user_handle_tail(char __user *to, char __user *from, unsigned long len, unsigned zerorest) __size_overflow(3);
13573
13574 #endif /* _ASM_X86_UACCESS_64_H */
13575diff --git a/arch/x86/include/asm/vdso.h b/arch/x86/include/asm/vdso.h
13576index bb05228..d763d5b 100644
13577--- a/arch/x86/include/asm/vdso.h
13578+++ b/arch/x86/include/asm/vdso.h
13579@@ -11,7 +11,7 @@ extern const char VDSO32_PRELINK[];
13580 #define VDSO32_SYMBOL(base, name) \
13581 ({ \
13582 extern const char VDSO32_##name[]; \
13583- (void *)(VDSO32_##name - VDSO32_PRELINK + (unsigned long)(base)); \
13584+ (void __user *)(VDSO32_##name - VDSO32_PRELINK + (unsigned long)(base)); \
13585 })
13586 #endif
13587
13588diff --git a/arch/x86/include/asm/word-at-a-time.h b/arch/x86/include/asm/word-at-a-time.h
13589index 5b238981..77fdd78 100644
13590--- a/arch/x86/include/asm/word-at-a-time.h
13591+++ b/arch/x86/include/asm/word-at-a-time.h
13592@@ -11,7 +11,7 @@
13593 * and shift, for example.
13594 */
13595 struct word_at_a_time {
13596- const unsigned long one_bits, high_bits;
13597+ unsigned long one_bits, high_bits;
13598 };
13599
13600 #define WORD_AT_A_TIME_CONSTANTS { REPEAT_BYTE(0x01), REPEAT_BYTE(0x80) }
13601diff --git a/arch/x86/include/asm/x86_init.h b/arch/x86/include/asm/x86_init.h
13602index 38155f6..e4184ba 100644
13603--- a/arch/x86/include/asm/x86_init.h
13604+++ b/arch/x86/include/asm/x86_init.h
13605@@ -29,7 +29,7 @@ struct x86_init_mpparse {
13606 void (*mpc_oem_bus_info)(struct mpc_bus *m, char *name);
13607 void (*find_smp_config)(void);
13608 void (*get_smp_config)(unsigned int early);
13609-};
13610+} __no_const;
13611
13612 /**
13613 * struct x86_init_resources - platform specific resource related ops
13614@@ -43,7 +43,7 @@ struct x86_init_resources {
13615 void (*probe_roms)(void);
13616 void (*reserve_resources)(void);
13617 char *(*memory_setup)(void);
13618-};
13619+} __no_const;
13620
13621 /**
13622 * struct x86_init_irqs - platform specific interrupt setup
13623@@ -56,7 +56,7 @@ struct x86_init_irqs {
13624 void (*pre_vector_init)(void);
13625 void (*intr_init)(void);
13626 void (*trap_init)(void);
13627-};
13628+} __no_const;
13629
13630 /**
13631 * struct x86_init_oem - oem platform specific customizing functions
13632@@ -66,7 +66,7 @@ struct x86_init_irqs {
13633 struct x86_init_oem {
13634 void (*arch_setup)(void);
13635 void (*banner)(void);
13636-};
13637+} __no_const;
13638
13639 /**
13640 * struct x86_init_mapping - platform specific initial kernel pagetable setup
13641@@ -77,7 +77,7 @@ struct x86_init_oem {
13642 */
13643 struct x86_init_mapping {
13644 void (*pagetable_reserve)(u64 start, u64 end);
13645-};
13646+} __no_const;
13647
13648 /**
13649 * struct x86_init_paging - platform specific paging functions
13650@@ -87,7 +87,7 @@ struct x86_init_mapping {
13651 struct x86_init_paging {
13652 void (*pagetable_setup_start)(pgd_t *base);
13653 void (*pagetable_setup_done)(pgd_t *base);
13654-};
13655+} __no_const;
13656
13657 /**
13658 * struct x86_init_timers - platform specific timer setup
13659@@ -102,7 +102,7 @@ struct x86_init_timers {
13660 void (*tsc_pre_init)(void);
13661 void (*timer_init)(void);
13662 void (*wallclock_init)(void);
13663-};
13664+} __no_const;
13665
13666 /**
13667 * struct x86_init_iommu - platform specific iommu setup
13668@@ -110,7 +110,7 @@ struct x86_init_timers {
13669 */
13670 struct x86_init_iommu {
13671 int (*iommu_init)(void);
13672-};
13673+} __no_const;
13674
13675 /**
13676 * struct x86_init_pci - platform specific pci init functions
13677@@ -124,7 +124,7 @@ struct x86_init_pci {
13678 int (*init)(void);
13679 void (*init_irq)(void);
13680 void (*fixup_irqs)(void);
13681-};
13682+} __no_const;
13683
13684 /**
13685 * struct x86_init_ops - functions for platform specific setup
13686@@ -140,7 +140,7 @@ struct x86_init_ops {
13687 struct x86_init_timers timers;
13688 struct x86_init_iommu iommu;
13689 struct x86_init_pci pci;
13690-};
13691+} __no_const;
13692
13693 /**
13694 * struct x86_cpuinit_ops - platform specific cpu hotplug setups
13695@@ -151,7 +151,7 @@ struct x86_cpuinit_ops {
13696 void (*setup_percpu_clockev)(void);
13697 void (*early_percpu_clock_init)(void);
13698 void (*fixup_cpu_id)(struct cpuinfo_x86 *c, int node);
13699-};
13700+} __no_const;
13701
13702 /**
13703 * struct x86_platform_ops - platform specific runtime functions
13704@@ -177,7 +177,7 @@ struct x86_platform_ops {
13705 void (*save_sched_clock_state)(void);
13706 void (*restore_sched_clock_state)(void);
13707 void (*apic_post_init)(void);
13708-};
13709+} __no_const;
13710
13711 struct pci_dev;
13712
13713@@ -186,14 +186,14 @@ struct x86_msi_ops {
13714 void (*teardown_msi_irq)(unsigned int irq);
13715 void (*teardown_msi_irqs)(struct pci_dev *dev);
13716 void (*restore_msi_irqs)(struct pci_dev *dev, int irq);
13717-};
13718+} __no_const;
13719
13720 struct x86_io_apic_ops {
13721 void (*init) (void);
13722 unsigned int (*read) (unsigned int apic, unsigned int reg);
13723 void (*write) (unsigned int apic, unsigned int reg, unsigned int value);
13724 void (*modify)(unsigned int apic, unsigned int reg, unsigned int value);
13725-};
13726+} __no_const;
13727
13728 extern struct x86_init_ops x86_init;
13729 extern struct x86_cpuinit_ops x86_cpuinit;
13730diff --git a/arch/x86/include/asm/xsave.h b/arch/x86/include/asm/xsave.h
13731index 8a1b6f9..d47ba6d 100644
13732--- a/arch/x86/include/asm/xsave.h
13733+++ b/arch/x86/include/asm/xsave.h
13734@@ -65,6 +65,8 @@ static inline int xsave_user(struct xsave_struct __user *buf)
13735 {
13736 int err;
13737
13738+ buf = (struct xsave_struct __user *)____m(buf);
13739+
13740 /*
13741 * Clear the xsave header first, so that reserved fields are
13742 * initialized to zero.
13743@@ -74,7 +76,9 @@ static inline int xsave_user(struct xsave_struct __user *buf)
13744 if (unlikely(err))
13745 return -EFAULT;
13746
13747- __asm__ __volatile__("1: .byte " REX_PREFIX "0x0f,0xae,0x27\n"
13748+ __asm__ __volatile__("1:"
13749+ __copyuser_seg
13750+ ".byte " REX_PREFIX "0x0f,0xae,0x27\n"
13751 "2:\n"
13752 ".section .fixup,\"ax\"\n"
13753 "3: movl $-1,%[err]\n"
13754@@ -93,11 +97,13 @@ static inline int xsave_user(struct xsave_struct __user *buf)
13755 static inline int xrestore_user(struct xsave_struct __user *buf, u64 mask)
13756 {
13757 int err;
13758- struct xsave_struct *xstate = ((__force struct xsave_struct *)buf);
13759+ struct xsave_struct *xstate = ((__force_kernel struct xsave_struct *)____m(buf));
13760 u32 lmask = mask;
13761 u32 hmask = mask >> 32;
13762
13763- __asm__ __volatile__("1: .byte " REX_PREFIX "0x0f,0xae,0x2f\n"
13764+ __asm__ __volatile__("1:"
13765+ __copyuser_seg
13766+ ".byte " REX_PREFIX "0x0f,0xae,0x2f\n"
13767 "2:\n"
13768 ".section .fixup,\"ax\"\n"
13769 "3: movl $-1,%[err]\n"
13770diff --git a/arch/x86/kernel/acpi/sleep.c b/arch/x86/kernel/acpi/sleep.c
13771index 1b8e5a0..354fd59 100644
13772--- a/arch/x86/kernel/acpi/sleep.c
13773+++ b/arch/x86/kernel/acpi/sleep.c
13774@@ -69,8 +69,12 @@ int acpi_suspend_lowlevel(void)
13775 #else /* CONFIG_64BIT */
13776 #ifdef CONFIG_SMP
13777 stack_start = (unsigned long)temp_stack + sizeof(temp_stack);
13778+
13779+ pax_open_kernel();
13780 early_gdt_descr.address =
13781 (unsigned long)get_cpu_gdt_table(smp_processor_id());
13782+ pax_close_kernel();
13783+
13784 initial_gs = per_cpu_offset(smp_processor_id());
13785 #endif
13786 initial_code = (unsigned long)wakeup_long64;
13787diff --git a/arch/x86/kernel/acpi/wakeup_32.S b/arch/x86/kernel/acpi/wakeup_32.S
13788index 13ab720..95d5442 100644
13789--- a/arch/x86/kernel/acpi/wakeup_32.S
13790+++ b/arch/x86/kernel/acpi/wakeup_32.S
13791@@ -30,13 +30,11 @@ wakeup_pmode_return:
13792 # and restore the stack ... but you need gdt for this to work
13793 movl saved_context_esp, %esp
13794
13795- movl %cs:saved_magic, %eax
13796- cmpl $0x12345678, %eax
13797+ cmpl $0x12345678, saved_magic
13798 jne bogus_magic
13799
13800 # jump to place where we left off
13801- movl saved_eip, %eax
13802- jmp *%eax
13803+ jmp *(saved_eip)
13804
13805 bogus_magic:
13806 jmp bogus_magic
13807diff --git a/arch/x86/kernel/alternative.c b/arch/x86/kernel/alternative.c
13808index ced4534..3e75d69 100644
13809--- a/arch/x86/kernel/alternative.c
13810+++ b/arch/x86/kernel/alternative.c
13811@@ -281,6 +281,13 @@ void __init_or_module apply_alternatives(struct alt_instr *start,
13812 */
13813 for (a = start; a < end; a++) {
13814 instr = (u8 *)&a->instr_offset + a->instr_offset;
13815+
13816+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
13817+ instr += ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
13818+ if (instr < (u8 *)_text || (u8 *)_einittext <= instr)
13819+ instr -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
13820+#endif
13821+
13822 replacement = (u8 *)&a->repl_offset + a->repl_offset;
13823 BUG_ON(a->replacementlen > a->instrlen);
13824 BUG_ON(a->instrlen > sizeof(insnbuf));
13825@@ -312,10 +319,16 @@ static void alternatives_smp_lock(const s32 *start, const s32 *end,
13826 for (poff = start; poff < end; poff++) {
13827 u8 *ptr = (u8 *)poff + *poff;
13828
13829+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
13830+ ptr += ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
13831+ if (ptr < (u8 *)_text || (u8 *)_einittext <= ptr)
13832+ ptr -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
13833+#endif
13834+
13835 if (!*poff || ptr < text || ptr >= text_end)
13836 continue;
13837 /* turn DS segment override prefix into lock prefix */
13838- if (*ptr == 0x3e)
13839+ if (*ktla_ktva(ptr) == 0x3e)
13840 text_poke(ptr, ((unsigned char []){0xf0}), 1);
13841 };
13842 mutex_unlock(&text_mutex);
13843@@ -333,10 +346,16 @@ static void alternatives_smp_unlock(const s32 *start, const s32 *end,
13844 for (poff = start; poff < end; poff++) {
13845 u8 *ptr = (u8 *)poff + *poff;
13846
13847+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
13848+ ptr += ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
13849+ if (ptr < (u8 *)_text || (u8 *)_einittext <= ptr)
13850+ ptr -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
13851+#endif
13852+
13853 if (!*poff || ptr < text || ptr >= text_end)
13854 continue;
13855 /* turn lock prefix into DS segment override prefix */
13856- if (*ptr == 0xf0)
13857+ if (*ktla_ktva(ptr) == 0xf0)
13858 text_poke(ptr, ((unsigned char []){0x3E}), 1);
13859 };
13860 mutex_unlock(&text_mutex);
13861@@ -505,7 +524,7 @@ void __init_or_module apply_paravirt(struct paravirt_patch_site *start,
13862
13863 BUG_ON(p->len > MAX_PATCH_LEN);
13864 /* prep the buffer with the original instructions */
13865- memcpy(insnbuf, p->instr, p->len);
13866+ memcpy(insnbuf, ktla_ktva(p->instr), p->len);
13867 used = pv_init_ops.patch(p->instrtype, p->clobbers, insnbuf,
13868 (unsigned long)p->instr, p->len);
13869
13870@@ -573,7 +592,7 @@ void __init alternative_instructions(void)
13871 if (smp_alt_once)
13872 free_init_pages("SMP alternatives",
13873 (unsigned long)__smp_locks,
13874- (unsigned long)__smp_locks_end);
13875+ PAGE_ALIGN((unsigned long)__smp_locks_end));
13876
13877 restart_nmi();
13878 }
13879@@ -590,13 +609,17 @@ void __init alternative_instructions(void)
13880 * instructions. And on the local CPU you need to be protected again NMI or MCE
13881 * handlers seeing an inconsistent instruction while you patch.
13882 */
13883-void *__init_or_module text_poke_early(void *addr, const void *opcode,
13884+void *__kprobes text_poke_early(void *addr, const void *opcode,
13885 size_t len)
13886 {
13887 unsigned long flags;
13888 local_irq_save(flags);
13889- memcpy(addr, opcode, len);
13890+
13891+ pax_open_kernel();
13892+ memcpy(ktla_ktva(addr), opcode, len);
13893 sync_core();
13894+ pax_close_kernel();
13895+
13896 local_irq_restore(flags);
13897 /* Could also do a CLFLUSH here to speed up CPU recovery; but
13898 that causes hangs on some VIA CPUs. */
13899@@ -618,36 +641,22 @@ void *__init_or_module text_poke_early(void *addr, const void *opcode,
13900 */
13901 void *__kprobes text_poke(void *addr, const void *opcode, size_t len)
13902 {
13903- unsigned long flags;
13904- char *vaddr;
13905+ unsigned char *vaddr = ktla_ktva(addr);
13906 struct page *pages[2];
13907- int i;
13908+ size_t i;
13909
13910 if (!core_kernel_text((unsigned long)addr)) {
13911- pages[0] = vmalloc_to_page(addr);
13912- pages[1] = vmalloc_to_page(addr + PAGE_SIZE);
13913+ pages[0] = vmalloc_to_page(vaddr);
13914+ pages[1] = vmalloc_to_page(vaddr + PAGE_SIZE);
13915 } else {
13916- pages[0] = virt_to_page(addr);
13917+ pages[0] = virt_to_page(vaddr);
13918 WARN_ON(!PageReserved(pages[0]));
13919- pages[1] = virt_to_page(addr + PAGE_SIZE);
13920+ pages[1] = virt_to_page(vaddr + PAGE_SIZE);
13921 }
13922 BUG_ON(!pages[0]);
13923- local_irq_save(flags);
13924- set_fixmap(FIX_TEXT_POKE0, page_to_phys(pages[0]));
13925- if (pages[1])
13926- set_fixmap(FIX_TEXT_POKE1, page_to_phys(pages[1]));
13927- vaddr = (char *)fix_to_virt(FIX_TEXT_POKE0);
13928- memcpy(&vaddr[(unsigned long)addr & ~PAGE_MASK], opcode, len);
13929- clear_fixmap(FIX_TEXT_POKE0);
13930- if (pages[1])
13931- clear_fixmap(FIX_TEXT_POKE1);
13932- local_flush_tlb();
13933- sync_core();
13934- /* Could also do a CLFLUSH here to speed up CPU recovery; but
13935- that causes hangs on some VIA CPUs. */
13936+ text_poke_early(addr, opcode, len);
13937 for (i = 0; i < len; i++)
13938- BUG_ON(((char *)addr)[i] != ((char *)opcode)[i]);
13939- local_irq_restore(flags);
13940+ BUG_ON((vaddr)[i] != ((const unsigned char *)opcode)[i]);
13941 return addr;
13942 }
13943
13944diff --git a/arch/x86/kernel/apic/apic.c b/arch/x86/kernel/apic/apic.c
13945index 24deb30..94a3426 100644
13946--- a/arch/x86/kernel/apic/apic.c
13947+++ b/arch/x86/kernel/apic/apic.c
13948@@ -185,7 +185,7 @@ int first_system_vector = 0xfe;
13949 /*
13950 * Debug level, exported for io_apic.c
13951 */
13952-unsigned int apic_verbosity;
13953+int apic_verbosity;
13954
13955 int pic_mode;
13956
13957@@ -1923,7 +1923,7 @@ void smp_error_interrupt(struct pt_regs *regs)
13958 apic_write(APIC_ESR, 0);
13959 v1 = apic_read(APIC_ESR);
13960 ack_APIC_irq();
13961- atomic_inc(&irq_err_count);
13962+ atomic_inc_unchecked(&irq_err_count);
13963
13964 apic_printk(APIC_DEBUG, KERN_DEBUG "APIC error on CPU%d: %02x(%02x)",
13965 smp_processor_id(), v0 , v1);
13966@@ -2155,7 +2155,9 @@ void __init apic_set_eoi_write(void (*eoi_write)(u32 reg, u32 v))
13967 for (drv = __apicdrivers; drv < __apicdrivers_end; drv++) {
13968 /* Should happen once for each apic */
13969 WARN_ON((*drv)->eoi_write == eoi_write);
13970- (*drv)->eoi_write = eoi_write;
13971+ pax_open_kernel();
13972+ *(void **)&(*drv)->eoi_write = eoi_write;
13973+ pax_close_kernel();
13974 }
13975 }
13976
13977diff --git a/arch/x86/kernel/apic/io_apic.c b/arch/x86/kernel/apic/io_apic.c
13978index c265593..137c4ac 100644
13979--- a/arch/x86/kernel/apic/io_apic.c
13980+++ b/arch/x86/kernel/apic/io_apic.c
13981@@ -1084,7 +1084,7 @@ int IO_APIC_get_PCI_irq_vector(int bus, int slot, int pin,
13982 }
13983 EXPORT_SYMBOL(IO_APIC_get_PCI_irq_vector);
13984
13985-void lock_vector_lock(void)
13986+void lock_vector_lock(void) __acquires(vector_lock)
13987 {
13988 /* Used to the online set of cpus does not change
13989 * during assign_irq_vector.
13990@@ -1092,7 +1092,7 @@ void lock_vector_lock(void)
13991 raw_spin_lock(&vector_lock);
13992 }
13993
13994-void unlock_vector_lock(void)
13995+void unlock_vector_lock(void) __releases(vector_lock)
13996 {
13997 raw_spin_unlock(&vector_lock);
13998 }
13999@@ -2408,7 +2408,7 @@ static void ack_apic_edge(struct irq_data *data)
14000 ack_APIC_irq();
14001 }
14002
14003-atomic_t irq_mis_count;
14004+atomic_unchecked_t irq_mis_count;
14005
14006 #ifdef CONFIG_GENERIC_PENDING_IRQ
14007 static bool io_apic_level_ack_pending(struct irq_cfg *cfg)
14008@@ -2549,7 +2549,7 @@ static void ack_apic_level(struct irq_data *data)
14009 * at the cpu.
14010 */
14011 if (!(v & (1 << (i & 0x1f)))) {
14012- atomic_inc(&irq_mis_count);
14013+ atomic_inc_unchecked(&irq_mis_count);
14014
14015 eoi_ioapic_irq(irq, cfg);
14016 }
14017diff --git a/arch/x86/kernel/apm_32.c b/arch/x86/kernel/apm_32.c
14018index d65464e..1035d31 100644
14019--- a/arch/x86/kernel/apm_32.c
14020+++ b/arch/x86/kernel/apm_32.c
14021@@ -412,7 +412,7 @@ static DEFINE_MUTEX(apm_mutex);
14022 * This is for buggy BIOS's that refer to (real mode) segment 0x40
14023 * even though they are called in protected mode.
14024 */
14025-static struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4092,
14026+static const struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4093,
14027 (unsigned long)__va(0x400UL), PAGE_SIZE - 0x400 - 1);
14028
14029 static const char driver_version[] = "1.16ac"; /* no spaces */
14030@@ -590,7 +590,10 @@ static long __apm_bios_call(void *_call)
14031 BUG_ON(cpu != 0);
14032 gdt = get_cpu_gdt_table(cpu);
14033 save_desc_40 = gdt[0x40 / 8];
14034+
14035+ pax_open_kernel();
14036 gdt[0x40 / 8] = bad_bios_desc;
14037+ pax_close_kernel();
14038
14039 apm_irq_save(flags);
14040 APM_DO_SAVE_SEGS;
14041@@ -599,7 +602,11 @@ static long __apm_bios_call(void *_call)
14042 &call->esi);
14043 APM_DO_RESTORE_SEGS;
14044 apm_irq_restore(flags);
14045+
14046+ pax_open_kernel();
14047 gdt[0x40 / 8] = save_desc_40;
14048+ pax_close_kernel();
14049+
14050 put_cpu();
14051
14052 return call->eax & 0xff;
14053@@ -666,7 +673,10 @@ static long __apm_bios_call_simple(void *_call)
14054 BUG_ON(cpu != 0);
14055 gdt = get_cpu_gdt_table(cpu);
14056 save_desc_40 = gdt[0x40 / 8];
14057+
14058+ pax_open_kernel();
14059 gdt[0x40 / 8] = bad_bios_desc;
14060+ pax_close_kernel();
14061
14062 apm_irq_save(flags);
14063 APM_DO_SAVE_SEGS;
14064@@ -674,7 +684,11 @@ static long __apm_bios_call_simple(void *_call)
14065 &call->eax);
14066 APM_DO_RESTORE_SEGS;
14067 apm_irq_restore(flags);
14068+
14069+ pax_open_kernel();
14070 gdt[0x40 / 8] = save_desc_40;
14071+ pax_close_kernel();
14072+
14073 put_cpu();
14074 return error;
14075 }
14076@@ -2345,12 +2359,15 @@ static int __init apm_init(void)
14077 * code to that CPU.
14078 */
14079 gdt = get_cpu_gdt_table(0);
14080+
14081+ pax_open_kernel();
14082 set_desc_base(&gdt[APM_CS >> 3],
14083 (unsigned long)__va((unsigned long)apm_info.bios.cseg << 4));
14084 set_desc_base(&gdt[APM_CS_16 >> 3],
14085 (unsigned long)__va((unsigned long)apm_info.bios.cseg_16 << 4));
14086 set_desc_base(&gdt[APM_DS >> 3],
14087 (unsigned long)__va((unsigned long)apm_info.bios.dseg << 4));
14088+ pax_close_kernel();
14089
14090 proc_create("apm", 0, NULL, &apm_file_ops);
14091
14092diff --git a/arch/x86/kernel/asm-offsets.c b/arch/x86/kernel/asm-offsets.c
14093index 68de2dc..1f3c720 100644
14094--- a/arch/x86/kernel/asm-offsets.c
14095+++ b/arch/x86/kernel/asm-offsets.c
14096@@ -33,6 +33,8 @@ void common(void) {
14097 OFFSET(TI_status, thread_info, status);
14098 OFFSET(TI_addr_limit, thread_info, addr_limit);
14099 OFFSET(TI_preempt_count, thread_info, preempt_count);
14100+ OFFSET(TI_lowest_stack, thread_info, lowest_stack);
14101+ DEFINE(TI_task_thread_sp0, offsetof(struct task_struct, thread.sp0) - offsetof(struct task_struct, tinfo));
14102
14103 BLANK();
14104 OFFSET(crypto_tfm_ctx_offset, crypto_tfm, __crt_ctx);
14105@@ -53,8 +55,26 @@ void common(void) {
14106 OFFSET(PV_CPU_irq_enable_sysexit, pv_cpu_ops, irq_enable_sysexit);
14107 OFFSET(PV_CPU_read_cr0, pv_cpu_ops, read_cr0);
14108 OFFSET(PV_MMU_read_cr2, pv_mmu_ops, read_cr2);
14109+
14110+#ifdef CONFIG_PAX_KERNEXEC
14111+ OFFSET(PV_CPU_write_cr0, pv_cpu_ops, write_cr0);
14112 #endif
14113
14114+#ifdef CONFIG_PAX_MEMORY_UDEREF
14115+ OFFSET(PV_MMU_read_cr3, pv_mmu_ops, read_cr3);
14116+ OFFSET(PV_MMU_write_cr3, pv_mmu_ops, write_cr3);
14117+#ifdef CONFIG_X86_64
14118+ OFFSET(PV_MMU_set_pgd_batched, pv_mmu_ops, set_pgd_batched);
14119+#endif
14120+#endif
14121+
14122+#endif
14123+
14124+ BLANK();
14125+ DEFINE(PAGE_SIZE_asm, PAGE_SIZE);
14126+ DEFINE(PAGE_SHIFT_asm, PAGE_SHIFT);
14127+ DEFINE(THREAD_SIZE_asm, THREAD_SIZE);
14128+
14129 #ifdef CONFIG_XEN
14130 BLANK();
14131 OFFSET(XEN_vcpu_info_mask, vcpu_info, evtchn_upcall_mask);
14132diff --git a/arch/x86/kernel/asm-offsets_64.c b/arch/x86/kernel/asm-offsets_64.c
14133index 1b4754f..fbb4227 100644
14134--- a/arch/x86/kernel/asm-offsets_64.c
14135+++ b/arch/x86/kernel/asm-offsets_64.c
14136@@ -76,6 +76,7 @@ int main(void)
14137 BLANK();
14138 #undef ENTRY
14139
14140+ DEFINE(TSS_size, sizeof(struct tss_struct));
14141 OFFSET(TSS_ist, tss_struct, x86_tss.ist);
14142 BLANK();
14143
14144diff --git a/arch/x86/kernel/cpu/Makefile b/arch/x86/kernel/cpu/Makefile
14145index d30a6a9..79becab 100644
14146--- a/arch/x86/kernel/cpu/Makefile
14147+++ b/arch/x86/kernel/cpu/Makefile
14148@@ -8,10 +8,6 @@ CFLAGS_REMOVE_common.o = -pg
14149 CFLAGS_REMOVE_perf_event.o = -pg
14150 endif
14151
14152-# Make sure load_percpu_segment has no stackprotector
14153-nostackp := $(call cc-option, -fno-stack-protector)
14154-CFLAGS_common.o := $(nostackp)
14155-
14156 obj-y := intel_cacheinfo.o scattered.o topology.o
14157 obj-y += proc.o capflags.o powerflags.o common.o
14158 obj-y += vmware.o hypervisor.o mshyperv.o
14159diff --git a/arch/x86/kernel/cpu/amd.c b/arch/x86/kernel/cpu/amd.c
14160index 9d92e19..49d7d79 100644
14161--- a/arch/x86/kernel/cpu/amd.c
14162+++ b/arch/x86/kernel/cpu/amd.c
14163@@ -724,7 +724,7 @@ static unsigned int __cpuinit amd_size_cache(struct cpuinfo_x86 *c,
14164 unsigned int size)
14165 {
14166 /* AMD errata T13 (order #21922) */
14167- if ((c->x86 == 6)) {
14168+ if (c->x86 == 6) {
14169 /* Duron Rev A0 */
14170 if (c->x86_model == 3 && c->x86_mask == 0)
14171 size = 64;
14172diff --git a/arch/x86/kernel/cpu/common.c b/arch/x86/kernel/cpu/common.c
14173index a5fbc3c..2254849 100644
14174--- a/arch/x86/kernel/cpu/common.c
14175+++ b/arch/x86/kernel/cpu/common.c
14176@@ -86,60 +86,6 @@ static const struct cpu_dev __cpuinitconst default_cpu = {
14177
14178 static const struct cpu_dev *this_cpu __cpuinitdata = &default_cpu;
14179
14180-DEFINE_PER_CPU_PAGE_ALIGNED(struct gdt_page, gdt_page) = { .gdt = {
14181-#ifdef CONFIG_X86_64
14182- /*
14183- * We need valid kernel segments for data and code in long mode too
14184- * IRET will check the segment types kkeil 2000/10/28
14185- * Also sysret mandates a special GDT layout
14186- *
14187- * TLS descriptors are currently at a different place compared to i386.
14188- * Hopefully nobody expects them at a fixed place (Wine?)
14189- */
14190- [GDT_ENTRY_KERNEL32_CS] = GDT_ENTRY_INIT(0xc09b, 0, 0xfffff),
14191- [GDT_ENTRY_KERNEL_CS] = GDT_ENTRY_INIT(0xa09b, 0, 0xfffff),
14192- [GDT_ENTRY_KERNEL_DS] = GDT_ENTRY_INIT(0xc093, 0, 0xfffff),
14193- [GDT_ENTRY_DEFAULT_USER32_CS] = GDT_ENTRY_INIT(0xc0fb, 0, 0xfffff),
14194- [GDT_ENTRY_DEFAULT_USER_DS] = GDT_ENTRY_INIT(0xc0f3, 0, 0xfffff),
14195- [GDT_ENTRY_DEFAULT_USER_CS] = GDT_ENTRY_INIT(0xa0fb, 0, 0xfffff),
14196-#else
14197- [GDT_ENTRY_KERNEL_CS] = GDT_ENTRY_INIT(0xc09a, 0, 0xfffff),
14198- [GDT_ENTRY_KERNEL_DS] = GDT_ENTRY_INIT(0xc092, 0, 0xfffff),
14199- [GDT_ENTRY_DEFAULT_USER_CS] = GDT_ENTRY_INIT(0xc0fa, 0, 0xfffff),
14200- [GDT_ENTRY_DEFAULT_USER_DS] = GDT_ENTRY_INIT(0xc0f2, 0, 0xfffff),
14201- /*
14202- * Segments used for calling PnP BIOS have byte granularity.
14203- * They code segments and data segments have fixed 64k limits,
14204- * the transfer segment sizes are set at run time.
14205- */
14206- /* 32-bit code */
14207- [GDT_ENTRY_PNPBIOS_CS32] = GDT_ENTRY_INIT(0x409a, 0, 0xffff),
14208- /* 16-bit code */
14209- [GDT_ENTRY_PNPBIOS_CS16] = GDT_ENTRY_INIT(0x009a, 0, 0xffff),
14210- /* 16-bit data */
14211- [GDT_ENTRY_PNPBIOS_DS] = GDT_ENTRY_INIT(0x0092, 0, 0xffff),
14212- /* 16-bit data */
14213- [GDT_ENTRY_PNPBIOS_TS1] = GDT_ENTRY_INIT(0x0092, 0, 0),
14214- /* 16-bit data */
14215- [GDT_ENTRY_PNPBIOS_TS2] = GDT_ENTRY_INIT(0x0092, 0, 0),
14216- /*
14217- * The APM segments have byte granularity and their bases
14218- * are set at run time. All have 64k limits.
14219- */
14220- /* 32-bit code */
14221- [GDT_ENTRY_APMBIOS_BASE] = GDT_ENTRY_INIT(0x409a, 0, 0xffff),
14222- /* 16-bit code */
14223- [GDT_ENTRY_APMBIOS_BASE+1] = GDT_ENTRY_INIT(0x009a, 0, 0xffff),
14224- /* data */
14225- [GDT_ENTRY_APMBIOS_BASE+2] = GDT_ENTRY_INIT(0x4092, 0, 0xffff),
14226-
14227- [GDT_ENTRY_ESPFIX_SS] = GDT_ENTRY_INIT(0xc092, 0, 0xfffff),
14228- [GDT_ENTRY_PERCPU] = GDT_ENTRY_INIT(0xc092, 0, 0xfffff),
14229- GDT_STACK_CANARY_INIT
14230-#endif
14231-} };
14232-EXPORT_PER_CPU_SYMBOL_GPL(gdt_page);
14233-
14234 static int __init x86_xsave_setup(char *s)
14235 {
14236 setup_clear_cpu_cap(X86_FEATURE_XSAVE);
14237@@ -376,7 +322,7 @@ void switch_to_new_gdt(int cpu)
14238 {
14239 struct desc_ptr gdt_descr;
14240
14241- gdt_descr.address = (long)get_cpu_gdt_table(cpu);
14242+ gdt_descr.address = (unsigned long)get_cpu_gdt_table(cpu);
14243 gdt_descr.size = GDT_SIZE - 1;
14244 load_gdt(&gdt_descr);
14245 /* Reload the per-cpu base */
14246@@ -872,6 +818,10 @@ static void __cpuinit identify_cpu(struct cpuinfo_x86 *c)
14247 /* Filter out anything that depends on CPUID levels we don't have */
14248 filter_cpuid_features(c, true);
14249
14250+#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_SEGMEXEC) || defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF))
14251+ setup_clear_cpu_cap(X86_FEATURE_SEP);
14252+#endif
14253+
14254 /* If the model name is still unset, do table lookup. */
14255 if (!c->x86_model_id[0]) {
14256 const char *p;
14257@@ -1054,10 +1004,12 @@ static __init int setup_disablecpuid(char *arg)
14258 }
14259 __setup("clearcpuid=", setup_disablecpuid);
14260
14261+DEFINE_PER_CPU(struct thread_info *, current_tinfo) = &init_task.tinfo;
14262+EXPORT_PER_CPU_SYMBOL(current_tinfo);
14263+
14264 #ifdef CONFIG_X86_64
14265 struct desc_ptr idt_descr = { NR_VECTORS * 16 - 1, (unsigned long) idt_table };
14266-struct desc_ptr nmi_idt_descr = { NR_VECTORS * 16 - 1,
14267- (unsigned long) nmi_idt_table };
14268+struct desc_ptr nmi_idt_descr = { NR_VECTORS * 16 - 1, (unsigned long) nmi_idt_table };
14269
14270 DEFINE_PER_CPU_FIRST(union irq_stack_union,
14271 irq_stack_union) __aligned(PAGE_SIZE);
14272@@ -1071,7 +1023,7 @@ DEFINE_PER_CPU(struct task_struct *, current_task) ____cacheline_aligned =
14273 EXPORT_PER_CPU_SYMBOL(current_task);
14274
14275 DEFINE_PER_CPU(unsigned long, kernel_stack) =
14276- (unsigned long)&init_thread_union - KERNEL_STACK_OFFSET + THREAD_SIZE;
14277+ (unsigned long)&init_thread_union - 16 + THREAD_SIZE;
14278 EXPORT_PER_CPU_SYMBOL(kernel_stack);
14279
14280 DEFINE_PER_CPU(char *, irq_stack_ptr) =
14281@@ -1165,7 +1117,7 @@ struct pt_regs * __cpuinit idle_regs(struct pt_regs *regs)
14282 {
14283 memset(regs, 0, sizeof(struct pt_regs));
14284 regs->fs = __KERNEL_PERCPU;
14285- regs->gs = __KERNEL_STACK_CANARY;
14286+ savesegment(gs, regs->gs);
14287
14288 return regs;
14289 }
14290@@ -1220,7 +1172,7 @@ void __cpuinit cpu_init(void)
14291 int i;
14292
14293 cpu = stack_smp_processor_id();
14294- t = &per_cpu(init_tss, cpu);
14295+ t = init_tss + cpu;
14296 oist = &per_cpu(orig_ist, cpu);
14297
14298 #ifdef CONFIG_NUMA
14299@@ -1246,7 +1198,7 @@ void __cpuinit cpu_init(void)
14300 switch_to_new_gdt(cpu);
14301 loadsegment(fs, 0);
14302
14303- load_idt((const struct desc_ptr *)&idt_descr);
14304+ load_idt(&idt_descr);
14305
14306 memset(me->thread.tls_array, 0, GDT_ENTRY_TLS_ENTRIES * 8);
14307 syscall_init();
14308@@ -1255,7 +1207,6 @@ void __cpuinit cpu_init(void)
14309 wrmsrl(MSR_KERNEL_GS_BASE, 0);
14310 barrier();
14311
14312- x86_configure_nx();
14313 if (cpu != 0)
14314 enable_x2apic();
14315
14316@@ -1311,7 +1262,7 @@ void __cpuinit cpu_init(void)
14317 {
14318 int cpu = smp_processor_id();
14319 struct task_struct *curr = current;
14320- struct tss_struct *t = &per_cpu(init_tss, cpu);
14321+ struct tss_struct *t = init_tss + cpu;
14322 struct thread_struct *thread = &curr->thread;
14323
14324 if (cpumask_test_and_set_cpu(cpu, cpu_initialized_mask)) {
14325diff --git a/arch/x86/kernel/cpu/intel.c b/arch/x86/kernel/cpu/intel.c
14326index 0a4ce29..f211176 100644
14327--- a/arch/x86/kernel/cpu/intel.c
14328+++ b/arch/x86/kernel/cpu/intel.c
14329@@ -174,7 +174,7 @@ static void __cpuinit trap_init_f00f_bug(void)
14330 * Update the IDT descriptor and reload the IDT so that
14331 * it uses the read-only mapped virtual address.
14332 */
14333- idt_descr.address = fix_to_virt(FIX_F00F_IDT);
14334+ idt_descr.address = (struct desc_struct *)fix_to_virt(FIX_F00F_IDT);
14335 load_idt(&idt_descr);
14336 }
14337 #endif
14338diff --git a/arch/x86/kernel/cpu/mcheck/mce.c b/arch/x86/kernel/cpu/mcheck/mce.c
14339index 292d025..b520c94 100644
14340--- a/arch/x86/kernel/cpu/mcheck/mce.c
14341+++ b/arch/x86/kernel/cpu/mcheck/mce.c
14342@@ -45,6 +45,7 @@
14343 #include <asm/processor.h>
14344 #include <asm/mce.h>
14345 #include <asm/msr.h>
14346+#include <asm/local.h>
14347
14348 #include "mce-internal.h"
14349
14350@@ -253,7 +254,7 @@ static void print_mce(struct mce *m)
14351 !(m->mcgstatus & MCG_STATUS_EIPV) ? " !INEXACT!" : "",
14352 m->cs, m->ip);
14353
14354- if (m->cs == __KERNEL_CS)
14355+ if (m->cs == __KERNEL_CS || m->cs == __KERNEXEC_KERNEL_CS)
14356 print_symbol("{%s}", m->ip);
14357 pr_cont("\n");
14358 }
14359@@ -286,10 +287,10 @@ static void print_mce(struct mce *m)
14360
14361 #define PANIC_TIMEOUT 5 /* 5 seconds */
14362
14363-static atomic_t mce_paniced;
14364+static atomic_unchecked_t mce_paniced;
14365
14366 static int fake_panic;
14367-static atomic_t mce_fake_paniced;
14368+static atomic_unchecked_t mce_fake_paniced;
14369
14370 /* Panic in progress. Enable interrupts and wait for final IPI */
14371 static void wait_for_panic(void)
14372@@ -313,7 +314,7 @@ static void mce_panic(char *msg, struct mce *final, char *exp)
14373 /*
14374 * Make sure only one CPU runs in machine check panic
14375 */
14376- if (atomic_inc_return(&mce_paniced) > 1)
14377+ if (atomic_inc_return_unchecked(&mce_paniced) > 1)
14378 wait_for_panic();
14379 barrier();
14380
14381@@ -321,7 +322,7 @@ static void mce_panic(char *msg, struct mce *final, char *exp)
14382 console_verbose();
14383 } else {
14384 /* Don't log too much for fake panic */
14385- if (atomic_inc_return(&mce_fake_paniced) > 1)
14386+ if (atomic_inc_return_unchecked(&mce_fake_paniced) > 1)
14387 return;
14388 }
14389 /* First print corrected ones that are still unlogged */
14390@@ -693,7 +694,7 @@ static int mce_timed_out(u64 *t)
14391 * might have been modified by someone else.
14392 */
14393 rmb();
14394- if (atomic_read(&mce_paniced))
14395+ if (atomic_read_unchecked(&mce_paniced))
14396 wait_for_panic();
14397 if (!monarch_timeout)
14398 goto out;
14399@@ -1619,7 +1620,7 @@ static void unexpected_machine_check(struct pt_regs *regs, long error_code)
14400 }
14401
14402 /* Call the installed machine check handler for this CPU setup. */
14403-void (*machine_check_vector)(struct pt_regs *, long error_code) =
14404+void (*machine_check_vector)(struct pt_regs *, long error_code) __read_only =
14405 unexpected_machine_check;
14406
14407 /*
14408@@ -1642,7 +1643,9 @@ void __cpuinit mcheck_cpu_init(struct cpuinfo_x86 *c)
14409 return;
14410 }
14411
14412+ pax_open_kernel();
14413 machine_check_vector = do_machine_check;
14414+ pax_close_kernel();
14415
14416 __mcheck_cpu_init_generic();
14417 __mcheck_cpu_init_vendor(c);
14418@@ -1656,7 +1659,7 @@ void __cpuinit mcheck_cpu_init(struct cpuinfo_x86 *c)
14419 */
14420
14421 static DEFINE_SPINLOCK(mce_chrdev_state_lock);
14422-static int mce_chrdev_open_count; /* #times opened */
14423+static local_t mce_chrdev_open_count; /* #times opened */
14424 static int mce_chrdev_open_exclu; /* already open exclusive? */
14425
14426 static int mce_chrdev_open(struct inode *inode, struct file *file)
14427@@ -1664,7 +1667,7 @@ static int mce_chrdev_open(struct inode *inode, struct file *file)
14428 spin_lock(&mce_chrdev_state_lock);
14429
14430 if (mce_chrdev_open_exclu ||
14431- (mce_chrdev_open_count && (file->f_flags & O_EXCL))) {
14432+ (local_read(&mce_chrdev_open_count) && (file->f_flags & O_EXCL))) {
14433 spin_unlock(&mce_chrdev_state_lock);
14434
14435 return -EBUSY;
14436@@ -1672,7 +1675,7 @@ static int mce_chrdev_open(struct inode *inode, struct file *file)
14437
14438 if (file->f_flags & O_EXCL)
14439 mce_chrdev_open_exclu = 1;
14440- mce_chrdev_open_count++;
14441+ local_inc(&mce_chrdev_open_count);
14442
14443 spin_unlock(&mce_chrdev_state_lock);
14444
14445@@ -1683,7 +1686,7 @@ static int mce_chrdev_release(struct inode *inode, struct file *file)
14446 {
14447 spin_lock(&mce_chrdev_state_lock);
14448
14449- mce_chrdev_open_count--;
14450+ local_dec(&mce_chrdev_open_count);
14451 mce_chrdev_open_exclu = 0;
14452
14453 spin_unlock(&mce_chrdev_state_lock);
14454@@ -2407,7 +2410,7 @@ struct dentry *mce_get_debugfs_dir(void)
14455 static void mce_reset(void)
14456 {
14457 cpu_missing = 0;
14458- atomic_set(&mce_fake_paniced, 0);
14459+ atomic_set_unchecked(&mce_fake_paniced, 0);
14460 atomic_set(&mce_executing, 0);
14461 atomic_set(&mce_callin, 0);
14462 atomic_set(&global_nwo, 0);
14463diff --git a/arch/x86/kernel/cpu/mcheck/p5.c b/arch/x86/kernel/cpu/mcheck/p5.c
14464index 2d5454c..51987eb 100644
14465--- a/arch/x86/kernel/cpu/mcheck/p5.c
14466+++ b/arch/x86/kernel/cpu/mcheck/p5.c
14467@@ -11,6 +11,7 @@
14468 #include <asm/processor.h>
14469 #include <asm/mce.h>
14470 #include <asm/msr.h>
14471+#include <asm/pgtable.h>
14472
14473 /* By default disabled */
14474 int mce_p5_enabled __read_mostly;
14475@@ -49,7 +50,9 @@ void intel_p5_mcheck_init(struct cpuinfo_x86 *c)
14476 if (!cpu_has(c, X86_FEATURE_MCE))
14477 return;
14478
14479+ pax_open_kernel();
14480 machine_check_vector = pentium_machine_check;
14481+ pax_close_kernel();
14482 /* Make sure the vector pointer is visible before we enable MCEs: */
14483 wmb();
14484
14485diff --git a/arch/x86/kernel/cpu/mcheck/winchip.c b/arch/x86/kernel/cpu/mcheck/winchip.c
14486index 2d7998f..17c9de1 100644
14487--- a/arch/x86/kernel/cpu/mcheck/winchip.c
14488+++ b/arch/x86/kernel/cpu/mcheck/winchip.c
14489@@ -10,6 +10,7 @@
14490 #include <asm/processor.h>
14491 #include <asm/mce.h>
14492 #include <asm/msr.h>
14493+#include <asm/pgtable.h>
14494
14495 /* Machine check handler for WinChip C6: */
14496 static void winchip_machine_check(struct pt_regs *regs, long error_code)
14497@@ -23,7 +24,9 @@ void winchip_mcheck_init(struct cpuinfo_x86 *c)
14498 {
14499 u32 lo, hi;
14500
14501+ pax_open_kernel();
14502 machine_check_vector = winchip_machine_check;
14503+ pax_close_kernel();
14504 /* Make sure the vector pointer is visible before we enable MCEs: */
14505 wmb();
14506
14507diff --git a/arch/x86/kernel/cpu/mtrr/main.c b/arch/x86/kernel/cpu/mtrr/main.c
14508index 6b96110..0da73eb 100644
14509--- a/arch/x86/kernel/cpu/mtrr/main.c
14510+++ b/arch/x86/kernel/cpu/mtrr/main.c
14511@@ -62,7 +62,7 @@ static DEFINE_MUTEX(mtrr_mutex);
14512 u64 size_or_mask, size_and_mask;
14513 static bool mtrr_aps_delayed_init;
14514
14515-static const struct mtrr_ops *mtrr_ops[X86_VENDOR_NUM];
14516+static const struct mtrr_ops *mtrr_ops[X86_VENDOR_NUM] __read_only;
14517
14518 const struct mtrr_ops *mtrr_if;
14519
14520diff --git a/arch/x86/kernel/cpu/mtrr/mtrr.h b/arch/x86/kernel/cpu/mtrr/mtrr.h
14521index df5e41f..816c719 100644
14522--- a/arch/x86/kernel/cpu/mtrr/mtrr.h
14523+++ b/arch/x86/kernel/cpu/mtrr/mtrr.h
14524@@ -25,7 +25,7 @@ struct mtrr_ops {
14525 int (*validate_add_page)(unsigned long base, unsigned long size,
14526 unsigned int type);
14527 int (*have_wrcomb)(void);
14528-};
14529+} __do_const;
14530
14531 extern int generic_get_free_region(unsigned long base, unsigned long size,
14532 int replace_reg);
14533diff --git a/arch/x86/kernel/cpu/perf_event.c b/arch/x86/kernel/cpu/perf_event.c
14534index 915b876..171f845 100644
14535--- a/arch/x86/kernel/cpu/perf_event.c
14536+++ b/arch/x86/kernel/cpu/perf_event.c
14537@@ -1757,7 +1757,7 @@ static unsigned long get_segment_base(unsigned int segment)
14538 if (idx > GDT_ENTRIES)
14539 return 0;
14540
14541- desc = __this_cpu_ptr(&gdt_page.gdt[0]);
14542+ desc = get_cpu_gdt_table(smp_processor_id());
14543 }
14544
14545 return get_desc_base(desc + idx);
14546@@ -1847,7 +1847,7 @@ perf_callchain_user(struct perf_callchain_entry *entry, struct pt_regs *regs)
14547 break;
14548
14549 perf_callchain_store(entry, frame.return_address);
14550- fp = frame.next_frame;
14551+ fp = (const void __force_user *)frame.next_frame;
14552 }
14553 }
14554
14555diff --git a/arch/x86/kernel/cpu/perf_event_intel.c b/arch/x86/kernel/cpu/perf_event_intel.c
14556index 6bca492..36e4496 100644
14557--- a/arch/x86/kernel/cpu/perf_event_intel.c
14558+++ b/arch/x86/kernel/cpu/perf_event_intel.c
14559@@ -1947,10 +1947,10 @@ __init int intel_pmu_init(void)
14560 * v2 and above have a perf capabilities MSR
14561 */
14562 if (version > 1) {
14563- u64 capabilities;
14564+ u64 capabilities = x86_pmu.intel_cap.capabilities;
14565
14566- rdmsrl(MSR_IA32_PERF_CAPABILITIES, capabilities);
14567- x86_pmu.intel_cap.capabilities = capabilities;
14568+ if (rdmsrl_safe(MSR_IA32_PERF_CAPABILITIES, &x86_pmu.intel_cap.capabilities))
14569+ x86_pmu.intel_cap.capabilities = capabilities;
14570 }
14571
14572 intel_ds_init();
14573diff --git a/arch/x86/kernel/crash.c b/arch/x86/kernel/crash.c
14574index 13ad899..f642b9a 100644
14575--- a/arch/x86/kernel/crash.c
14576+++ b/arch/x86/kernel/crash.c
14577@@ -36,10 +36,8 @@ static void kdump_nmi_callback(int cpu, struct pt_regs *regs)
14578 {
14579 #ifdef CONFIG_X86_32
14580 struct pt_regs fixed_regs;
14581-#endif
14582
14583-#ifdef CONFIG_X86_32
14584- if (!user_mode_vm(regs)) {
14585+ if (!user_mode(regs)) {
14586 crash_fixup_ss_esp(&fixed_regs, regs);
14587 regs = &fixed_regs;
14588 }
14589diff --git a/arch/x86/kernel/doublefault_32.c b/arch/x86/kernel/doublefault_32.c
14590index 37250fe..bf2ec74 100644
14591--- a/arch/x86/kernel/doublefault_32.c
14592+++ b/arch/x86/kernel/doublefault_32.c
14593@@ -11,7 +11,7 @@
14594
14595 #define DOUBLEFAULT_STACKSIZE (1024)
14596 static unsigned long doublefault_stack[DOUBLEFAULT_STACKSIZE];
14597-#define STACK_START (unsigned long)(doublefault_stack+DOUBLEFAULT_STACKSIZE)
14598+#define STACK_START (unsigned long)(doublefault_stack+DOUBLEFAULT_STACKSIZE-2)
14599
14600 #define ptr_ok(x) ((x) > PAGE_OFFSET && (x) < PAGE_OFFSET + MAXMEM)
14601
14602@@ -21,7 +21,7 @@ static void doublefault_fn(void)
14603 unsigned long gdt, tss;
14604
14605 store_gdt(&gdt_desc);
14606- gdt = gdt_desc.address;
14607+ gdt = (unsigned long)gdt_desc.address;
14608
14609 printk(KERN_EMERG "PANIC: double fault, gdt at %08lx [%d bytes]\n", gdt, gdt_desc.size);
14610
14611@@ -58,10 +58,10 @@ struct tss_struct doublefault_tss __cacheline_aligned = {
14612 /* 0x2 bit is always set */
14613 .flags = X86_EFLAGS_SF | 0x2,
14614 .sp = STACK_START,
14615- .es = __USER_DS,
14616+ .es = __KERNEL_DS,
14617 .cs = __KERNEL_CS,
14618 .ss = __KERNEL_DS,
14619- .ds = __USER_DS,
14620+ .ds = __KERNEL_DS,
14621 .fs = __KERNEL_PERCPU,
14622
14623 .__cr3 = __pa_nodebug(swapper_pg_dir),
14624diff --git a/arch/x86/kernel/dumpstack.c b/arch/x86/kernel/dumpstack.c
14625index ae42418b..787c16b 100644
14626--- a/arch/x86/kernel/dumpstack.c
14627+++ b/arch/x86/kernel/dumpstack.c
14628@@ -2,6 +2,9 @@
14629 * Copyright (C) 1991, 1992 Linus Torvalds
14630 * Copyright (C) 2000, 2001, 2002 Andi Kleen, SuSE Labs
14631 */
14632+#ifdef CONFIG_GRKERNSEC_HIDESYM
14633+#define __INCLUDED_BY_HIDESYM 1
14634+#endif
14635 #include <linux/kallsyms.h>
14636 #include <linux/kprobes.h>
14637 #include <linux/uaccess.h>
14638@@ -35,16 +38,14 @@ void printk_address(unsigned long address, int reliable)
14639 static void
14640 print_ftrace_graph_addr(unsigned long addr, void *data,
14641 const struct stacktrace_ops *ops,
14642- struct thread_info *tinfo, int *graph)
14643+ struct task_struct *task, int *graph)
14644 {
14645- struct task_struct *task;
14646 unsigned long ret_addr;
14647 int index;
14648
14649 if (addr != (unsigned long)return_to_handler)
14650 return;
14651
14652- task = tinfo->task;
14653 index = task->curr_ret_stack;
14654
14655 if (!task->ret_stack || index < *graph)
14656@@ -61,7 +62,7 @@ print_ftrace_graph_addr(unsigned long addr, void *data,
14657 static inline void
14658 print_ftrace_graph_addr(unsigned long addr, void *data,
14659 const struct stacktrace_ops *ops,
14660- struct thread_info *tinfo, int *graph)
14661+ struct task_struct *task, int *graph)
14662 { }
14663 #endif
14664
14665@@ -72,10 +73,8 @@ print_ftrace_graph_addr(unsigned long addr, void *data,
14666 * severe exception (double fault, nmi, stack fault, debug, mce) hardware stack
14667 */
14668
14669-static inline int valid_stack_ptr(struct thread_info *tinfo,
14670- void *p, unsigned int size, void *end)
14671+static inline int valid_stack_ptr(void *t, void *p, unsigned int size, void *end)
14672 {
14673- void *t = tinfo;
14674 if (end) {
14675 if (p < end && p >= (end-THREAD_SIZE))
14676 return 1;
14677@@ -86,14 +85,14 @@ static inline int valid_stack_ptr(struct thread_info *tinfo,
14678 }
14679
14680 unsigned long
14681-print_context_stack(struct thread_info *tinfo,
14682+print_context_stack(struct task_struct *task, void *stack_start,
14683 unsigned long *stack, unsigned long bp,
14684 const struct stacktrace_ops *ops, void *data,
14685 unsigned long *end, int *graph)
14686 {
14687 struct stack_frame *frame = (struct stack_frame *)bp;
14688
14689- while (valid_stack_ptr(tinfo, stack, sizeof(*stack), end)) {
14690+ while (valid_stack_ptr(stack_start, stack, sizeof(*stack), end)) {
14691 unsigned long addr;
14692
14693 addr = *stack;
14694@@ -105,7 +104,7 @@ print_context_stack(struct thread_info *tinfo,
14695 } else {
14696 ops->address(data, addr, 0);
14697 }
14698- print_ftrace_graph_addr(addr, data, ops, tinfo, graph);
14699+ print_ftrace_graph_addr(addr, data, ops, task, graph);
14700 }
14701 stack++;
14702 }
14703@@ -114,7 +113,7 @@ print_context_stack(struct thread_info *tinfo,
14704 EXPORT_SYMBOL_GPL(print_context_stack);
14705
14706 unsigned long
14707-print_context_stack_bp(struct thread_info *tinfo,
14708+print_context_stack_bp(struct task_struct *task, void *stack_start,
14709 unsigned long *stack, unsigned long bp,
14710 const struct stacktrace_ops *ops, void *data,
14711 unsigned long *end, int *graph)
14712@@ -122,7 +121,7 @@ print_context_stack_bp(struct thread_info *tinfo,
14713 struct stack_frame *frame = (struct stack_frame *)bp;
14714 unsigned long *ret_addr = &frame->return_address;
14715
14716- while (valid_stack_ptr(tinfo, ret_addr, sizeof(*ret_addr), end)) {
14717+ while (valid_stack_ptr(stack_start, ret_addr, sizeof(*ret_addr), end)) {
14718 unsigned long addr = *ret_addr;
14719
14720 if (!__kernel_text_address(addr))
14721@@ -131,7 +130,7 @@ print_context_stack_bp(struct thread_info *tinfo,
14722 ops->address(data, addr, 1);
14723 frame = frame->next_frame;
14724 ret_addr = &frame->return_address;
14725- print_ftrace_graph_addr(addr, data, ops, tinfo, graph);
14726+ print_ftrace_graph_addr(addr, data, ops, task, graph);
14727 }
14728
14729 return (unsigned long)frame;
14730@@ -189,7 +188,7 @@ void dump_stack(void)
14731
14732 bp = stack_frame(current, NULL);
14733 printk("Pid: %d, comm: %.20s %s %s %.*s\n",
14734- current->pid, current->comm, print_tainted(),
14735+ task_pid_nr(current), current->comm, print_tainted(),
14736 init_utsname()->release,
14737 (int)strcspn(init_utsname()->version, " "),
14738 init_utsname()->version);
14739@@ -225,6 +224,8 @@ unsigned __kprobes long oops_begin(void)
14740 }
14741 EXPORT_SYMBOL_GPL(oops_begin);
14742
14743+extern void gr_handle_kernel_exploit(void);
14744+
14745 void __kprobes oops_end(unsigned long flags, struct pt_regs *regs, int signr)
14746 {
14747 if (regs && kexec_should_crash(current))
14748@@ -246,7 +247,10 @@ void __kprobes oops_end(unsigned long flags, struct pt_regs *regs, int signr)
14749 panic("Fatal exception in interrupt");
14750 if (panic_on_oops)
14751 panic("Fatal exception");
14752- do_exit(signr);
14753+
14754+ gr_handle_kernel_exploit();
14755+
14756+ do_group_exit(signr);
14757 }
14758
14759 int __kprobes __die(const char *str, struct pt_regs *regs, long err)
14760@@ -274,7 +278,7 @@ int __kprobes __die(const char *str, struct pt_regs *regs, long err)
14761 print_modules();
14762 show_regs(regs);
14763 #ifdef CONFIG_X86_32
14764- if (user_mode_vm(regs)) {
14765+ if (user_mode(regs)) {
14766 sp = regs->sp;
14767 ss = regs->ss & 0xffff;
14768 } else {
14769@@ -302,7 +306,7 @@ void die(const char *str, struct pt_regs *regs, long err)
14770 unsigned long flags = oops_begin();
14771 int sig = SIGSEGV;
14772
14773- if (!user_mode_vm(regs))
14774+ if (!user_mode(regs))
14775 report_bug(regs->ip, regs);
14776
14777 if (__die(str, regs, err))
14778diff --git a/arch/x86/kernel/dumpstack_32.c b/arch/x86/kernel/dumpstack_32.c
14779index 1038a41..db2c12b 100644
14780--- a/arch/x86/kernel/dumpstack_32.c
14781+++ b/arch/x86/kernel/dumpstack_32.c
14782@@ -38,15 +38,13 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
14783 bp = stack_frame(task, regs);
14784
14785 for (;;) {
14786- struct thread_info *context;
14787+ void *stack_start = (void *)((unsigned long)stack & ~(THREAD_SIZE-1));
14788
14789- context = (struct thread_info *)
14790- ((unsigned long)stack & (~(THREAD_SIZE - 1)));
14791- bp = ops->walk_stack(context, stack, bp, ops, data, NULL, &graph);
14792+ bp = ops->walk_stack(task, stack_start, stack, bp, ops, data, NULL, &graph);
14793
14794- stack = (unsigned long *)context->previous_esp;
14795- if (!stack)
14796+ if (stack_start == task_stack_page(task))
14797 break;
14798+ stack = *(unsigned long **)stack_start;
14799 if (ops->stack(data, "IRQ") < 0)
14800 break;
14801 touch_nmi_watchdog();
14802@@ -86,7 +84,7 @@ void show_regs(struct pt_regs *regs)
14803 {
14804 int i;
14805
14806- __show_regs(regs, !user_mode_vm(regs));
14807+ __show_regs(regs, !user_mode(regs));
14808
14809 pr_emerg("Process %.*s (pid: %d, ti=%p task=%p task.ti=%p)\n",
14810 TASK_COMM_LEN, current->comm, task_pid_nr(current),
14811@@ -95,21 +93,22 @@ void show_regs(struct pt_regs *regs)
14812 * When in-kernel, we also print out the stack and code at the
14813 * time of the fault..
14814 */
14815- if (!user_mode_vm(regs)) {
14816+ if (!user_mode(regs)) {
14817 unsigned int code_prologue = code_bytes * 43 / 64;
14818 unsigned int code_len = code_bytes;
14819 unsigned char c;
14820 u8 *ip;
14821+ unsigned long cs_base = get_desc_base(&get_cpu_gdt_table(0)[(0xffff & regs->cs) >> 3]);
14822
14823 pr_emerg("Stack:\n");
14824 show_stack_log_lvl(NULL, regs, &regs->sp, 0, KERN_EMERG);
14825
14826 pr_emerg("Code:");
14827
14828- ip = (u8 *)regs->ip - code_prologue;
14829+ ip = (u8 *)regs->ip - code_prologue + cs_base;
14830 if (ip < (u8 *)PAGE_OFFSET || probe_kernel_address(ip, c)) {
14831 /* try starting at IP */
14832- ip = (u8 *)regs->ip;
14833+ ip = (u8 *)regs->ip + cs_base;
14834 code_len = code_len - code_prologue + 1;
14835 }
14836 for (i = 0; i < code_len; i++, ip++) {
14837@@ -118,7 +117,7 @@ void show_regs(struct pt_regs *regs)
14838 pr_cont(" Bad EIP value.");
14839 break;
14840 }
14841- if (ip == (u8 *)regs->ip)
14842+ if (ip == (u8 *)regs->ip + cs_base)
14843 pr_cont(" <%02x>", c);
14844 else
14845 pr_cont(" %02x", c);
14846@@ -131,6 +130,7 @@ int is_valid_bugaddr(unsigned long ip)
14847 {
14848 unsigned short ud2;
14849
14850+ ip = ktla_ktva(ip);
14851 if (ip < PAGE_OFFSET)
14852 return 0;
14853 if (probe_kernel_address((unsigned short *)ip, ud2))
14854@@ -138,3 +138,15 @@ int is_valid_bugaddr(unsigned long ip)
14855
14856 return ud2 == 0x0b0f;
14857 }
14858+
14859+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
14860+void pax_check_alloca(unsigned long size)
14861+{
14862+ unsigned long sp = (unsigned long)&sp, stack_left;
14863+
14864+ /* all kernel stacks are of the same size */
14865+ stack_left = sp & (THREAD_SIZE - 1);
14866+ BUG_ON(stack_left < 256 || size >= stack_left - 256);
14867+}
14868+EXPORT_SYMBOL(pax_check_alloca);
14869+#endif
14870diff --git a/arch/x86/kernel/dumpstack_64.c b/arch/x86/kernel/dumpstack_64.c
14871index b653675..51cc8c0 100644
14872--- a/arch/x86/kernel/dumpstack_64.c
14873+++ b/arch/x86/kernel/dumpstack_64.c
14874@@ -119,9 +119,9 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
14875 unsigned long *irq_stack_end =
14876 (unsigned long *)per_cpu(irq_stack_ptr, cpu);
14877 unsigned used = 0;
14878- struct thread_info *tinfo;
14879 int graph = 0;
14880 unsigned long dummy;
14881+ void *stack_start;
14882
14883 if (!task)
14884 task = current;
14885@@ -142,10 +142,10 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
14886 * current stack address. If the stacks consist of nested
14887 * exceptions
14888 */
14889- tinfo = task_thread_info(task);
14890 for (;;) {
14891 char *id;
14892 unsigned long *estack_end;
14893+
14894 estack_end = in_exception_stack(cpu, (unsigned long)stack,
14895 &used, &id);
14896
14897@@ -153,7 +153,7 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
14898 if (ops->stack(data, id) < 0)
14899 break;
14900
14901- bp = ops->walk_stack(tinfo, stack, bp, ops,
14902+ bp = ops->walk_stack(task, estack_end - EXCEPTION_STKSZ, stack, bp, ops,
14903 data, estack_end, &graph);
14904 ops->stack(data, "<EOE>");
14905 /*
14906@@ -161,6 +161,8 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
14907 * second-to-last pointer (index -2 to end) in the
14908 * exception stack:
14909 */
14910+ if ((u16)estack_end[-1] != __KERNEL_DS)
14911+ goto out;
14912 stack = (unsigned long *) estack_end[-2];
14913 continue;
14914 }
14915@@ -172,7 +174,7 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
14916 if (in_irq_stack(stack, irq_stack, irq_stack_end)) {
14917 if (ops->stack(data, "IRQ") < 0)
14918 break;
14919- bp = ops->walk_stack(tinfo, stack, bp,
14920+ bp = ops->walk_stack(task, irq_stack, stack, bp,
14921 ops, data, irq_stack_end, &graph);
14922 /*
14923 * We link to the next stack (which would be
14924@@ -191,7 +193,9 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
14925 /*
14926 * This handles the process stack:
14927 */
14928- bp = ops->walk_stack(tinfo, stack, bp, ops, data, NULL, &graph);
14929+ stack_start = (void *)((unsigned long)stack & ~(THREAD_SIZE-1));
14930+ bp = ops->walk_stack(task, stack_start, stack, bp, ops, data, NULL, &graph);
14931+out:
14932 put_cpu();
14933 }
14934 EXPORT_SYMBOL(dump_trace);
14935@@ -249,7 +253,7 @@ void show_regs(struct pt_regs *regs)
14936 {
14937 int i;
14938 unsigned long sp;
14939- const int cpu = smp_processor_id();
14940+ const int cpu = raw_smp_processor_id();
14941 struct task_struct *cur = current;
14942
14943 sp = regs->sp;
14944@@ -304,3 +308,50 @@ int is_valid_bugaddr(unsigned long ip)
14945
14946 return ud2 == 0x0b0f;
14947 }
14948+
14949+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
14950+void pax_check_alloca(unsigned long size)
14951+{
14952+ unsigned long sp = (unsigned long)&sp, stack_start, stack_end;
14953+ unsigned cpu, used;
14954+ char *id;
14955+
14956+ /* check the process stack first */
14957+ stack_start = (unsigned long)task_stack_page(current);
14958+ stack_end = stack_start + THREAD_SIZE;
14959+ if (likely(stack_start <= sp && sp < stack_end)) {
14960+ unsigned long stack_left = sp & (THREAD_SIZE - 1);
14961+ BUG_ON(stack_left < 256 || size >= stack_left - 256);
14962+ return;
14963+ }
14964+
14965+ cpu = get_cpu();
14966+
14967+ /* check the irq stacks */
14968+ stack_end = (unsigned long)per_cpu(irq_stack_ptr, cpu);
14969+ stack_start = stack_end - IRQ_STACK_SIZE;
14970+ if (stack_start <= sp && sp < stack_end) {
14971+ unsigned long stack_left = sp & (IRQ_STACK_SIZE - 1);
14972+ put_cpu();
14973+ BUG_ON(stack_left < 256 || size >= stack_left - 256);
14974+ return;
14975+ }
14976+
14977+ /* check the exception stacks */
14978+ used = 0;
14979+ stack_end = (unsigned long)in_exception_stack(cpu, sp, &used, &id);
14980+ stack_start = stack_end - EXCEPTION_STKSZ;
14981+ if (stack_end && stack_start <= sp && sp < stack_end) {
14982+ unsigned long stack_left = sp & (EXCEPTION_STKSZ - 1);
14983+ put_cpu();
14984+ BUG_ON(stack_left < 256 || size >= stack_left - 256);
14985+ return;
14986+ }
14987+
14988+ put_cpu();
14989+
14990+ /* unknown stack */
14991+ BUG();
14992+}
14993+EXPORT_SYMBOL(pax_check_alloca);
14994+#endif
14995diff --git a/arch/x86/kernel/early_printk.c b/arch/x86/kernel/early_printk.c
14996index 9b9f18b..9fcaa04 100644
14997--- a/arch/x86/kernel/early_printk.c
14998+++ b/arch/x86/kernel/early_printk.c
14999@@ -7,6 +7,7 @@
15000 #include <linux/pci_regs.h>
15001 #include <linux/pci_ids.h>
15002 #include <linux/errno.h>
15003+#include <linux/sched.h>
15004 #include <asm/io.h>
15005 #include <asm/processor.h>
15006 #include <asm/fcntl.h>
15007diff --git a/arch/x86/kernel/entry_32.S b/arch/x86/kernel/entry_32.S
15008index 8f8e8ee..3617d6e 100644
15009--- a/arch/x86/kernel/entry_32.S
15010+++ b/arch/x86/kernel/entry_32.S
15011@@ -176,13 +176,153 @@
15012 /*CFI_REL_OFFSET gs, PT_GS*/
15013 .endm
15014 .macro SET_KERNEL_GS reg
15015+
15016+#ifdef CONFIG_CC_STACKPROTECTOR
15017 movl $(__KERNEL_STACK_CANARY), \reg
15018+#elif defined(CONFIG_PAX_MEMORY_UDEREF)
15019+ movl $(__USER_DS), \reg
15020+#else
15021+ xorl \reg, \reg
15022+#endif
15023+
15024 movl \reg, %gs
15025 .endm
15026
15027 #endif /* CONFIG_X86_32_LAZY_GS */
15028
15029-.macro SAVE_ALL
15030+.macro pax_enter_kernel
15031+#ifdef CONFIG_PAX_KERNEXEC
15032+ call pax_enter_kernel
15033+#endif
15034+.endm
15035+
15036+.macro pax_exit_kernel
15037+#ifdef CONFIG_PAX_KERNEXEC
15038+ call pax_exit_kernel
15039+#endif
15040+.endm
15041+
15042+#ifdef CONFIG_PAX_KERNEXEC
15043+ENTRY(pax_enter_kernel)
15044+#ifdef CONFIG_PARAVIRT
15045+ pushl %eax
15046+ pushl %ecx
15047+ call PARA_INDIRECT(pv_cpu_ops+PV_CPU_read_cr0)
15048+ mov %eax, %esi
15049+#else
15050+ mov %cr0, %esi
15051+#endif
15052+ bts $16, %esi
15053+ jnc 1f
15054+ mov %cs, %esi
15055+ cmp $__KERNEL_CS, %esi
15056+ jz 3f
15057+ ljmp $__KERNEL_CS, $3f
15058+1: ljmp $__KERNEXEC_KERNEL_CS, $2f
15059+2:
15060+#ifdef CONFIG_PARAVIRT
15061+ mov %esi, %eax
15062+ call PARA_INDIRECT(pv_cpu_ops+PV_CPU_write_cr0)
15063+#else
15064+ mov %esi, %cr0
15065+#endif
15066+3:
15067+#ifdef CONFIG_PARAVIRT
15068+ popl %ecx
15069+ popl %eax
15070+#endif
15071+ ret
15072+ENDPROC(pax_enter_kernel)
15073+
15074+ENTRY(pax_exit_kernel)
15075+#ifdef CONFIG_PARAVIRT
15076+ pushl %eax
15077+ pushl %ecx
15078+#endif
15079+ mov %cs, %esi
15080+ cmp $__KERNEXEC_KERNEL_CS, %esi
15081+ jnz 2f
15082+#ifdef CONFIG_PARAVIRT
15083+ call PARA_INDIRECT(pv_cpu_ops+PV_CPU_read_cr0);
15084+ mov %eax, %esi
15085+#else
15086+ mov %cr0, %esi
15087+#endif
15088+ btr $16, %esi
15089+ ljmp $__KERNEL_CS, $1f
15090+1:
15091+#ifdef CONFIG_PARAVIRT
15092+ mov %esi, %eax
15093+ call PARA_INDIRECT(pv_cpu_ops+PV_CPU_write_cr0);
15094+#else
15095+ mov %esi, %cr0
15096+#endif
15097+2:
15098+#ifdef CONFIG_PARAVIRT
15099+ popl %ecx
15100+ popl %eax
15101+#endif
15102+ ret
15103+ENDPROC(pax_exit_kernel)
15104+#endif
15105+
15106+.macro pax_erase_kstack
15107+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
15108+ call pax_erase_kstack
15109+#endif
15110+.endm
15111+
15112+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
15113+/*
15114+ * ebp: thread_info
15115+ */
15116+ENTRY(pax_erase_kstack)
15117+ pushl %edi
15118+ pushl %ecx
15119+ pushl %eax
15120+
15121+ mov TI_lowest_stack(%ebp), %edi
15122+ mov $-0xBEEF, %eax
15123+ std
15124+
15125+1: mov %edi, %ecx
15126+ and $THREAD_SIZE_asm - 1, %ecx
15127+ shr $2, %ecx
15128+ repne scasl
15129+ jecxz 2f
15130+
15131+ cmp $2*16, %ecx
15132+ jc 2f
15133+
15134+ mov $2*16, %ecx
15135+ repe scasl
15136+ jecxz 2f
15137+ jne 1b
15138+
15139+2: cld
15140+ mov %esp, %ecx
15141+ sub %edi, %ecx
15142+
15143+ cmp $THREAD_SIZE_asm, %ecx
15144+ jb 3f
15145+ ud2
15146+3:
15147+
15148+ shr $2, %ecx
15149+ rep stosl
15150+
15151+ mov TI_task_thread_sp0(%ebp), %edi
15152+ sub $128, %edi
15153+ mov %edi, TI_lowest_stack(%ebp)
15154+
15155+ popl %eax
15156+ popl %ecx
15157+ popl %edi
15158+ ret
15159+ENDPROC(pax_erase_kstack)
15160+#endif
15161+
15162+.macro __SAVE_ALL _DS
15163 cld
15164 PUSH_GS
15165 pushl_cfi %fs
15166@@ -205,7 +345,7 @@
15167 CFI_REL_OFFSET ecx, 0
15168 pushl_cfi %ebx
15169 CFI_REL_OFFSET ebx, 0
15170- movl $(__USER_DS), %edx
15171+ movl $\_DS, %edx
15172 movl %edx, %ds
15173 movl %edx, %es
15174 movl $(__KERNEL_PERCPU), %edx
15175@@ -213,6 +353,15 @@
15176 SET_KERNEL_GS %edx
15177 .endm
15178
15179+.macro SAVE_ALL
15180+#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
15181+ __SAVE_ALL __KERNEL_DS
15182+ pax_enter_kernel
15183+#else
15184+ __SAVE_ALL __USER_DS
15185+#endif
15186+.endm
15187+
15188 .macro RESTORE_INT_REGS
15189 popl_cfi %ebx
15190 CFI_RESTORE ebx
15191@@ -296,7 +445,7 @@ ENTRY(ret_from_fork)
15192 popfl_cfi
15193 jmp syscall_exit
15194 CFI_ENDPROC
15195-END(ret_from_fork)
15196+ENDPROC(ret_from_fork)
15197
15198 /*
15199 * Interrupt exit functions should be protected against kprobes
15200@@ -329,7 +478,15 @@ ret_from_intr:
15201 andl $SEGMENT_RPL_MASK, %eax
15202 #endif
15203 cmpl $USER_RPL, %eax
15204+
15205+#ifdef CONFIG_PAX_KERNEXEC
15206+ jae resume_userspace
15207+
15208+ pax_exit_kernel
15209+ jmp resume_kernel
15210+#else
15211 jb resume_kernel # not returning to v8086 or userspace
15212+#endif
15213
15214 ENTRY(resume_userspace)
15215 LOCKDEP_SYS_EXIT
15216@@ -341,8 +498,8 @@ ENTRY(resume_userspace)
15217 andl $_TIF_WORK_MASK, %ecx # is there any work to be done on
15218 # int/exception return?
15219 jne work_pending
15220- jmp restore_all
15221-END(ret_from_exception)
15222+ jmp restore_all_pax
15223+ENDPROC(ret_from_exception)
15224
15225 #ifdef CONFIG_PREEMPT
15226 ENTRY(resume_kernel)
15227@@ -357,7 +514,7 @@ need_resched:
15228 jz restore_all
15229 call preempt_schedule_irq
15230 jmp need_resched
15231-END(resume_kernel)
15232+ENDPROC(resume_kernel)
15233 #endif
15234 CFI_ENDPROC
15235 /*
15236@@ -391,28 +548,43 @@ sysenter_past_esp:
15237 /*CFI_REL_OFFSET cs, 0*/
15238 /*
15239 * Push current_thread_info()->sysenter_return to the stack.
15240- * A tiny bit of offset fixup is necessary - 4*4 means the 4 words
15241- * pushed above; +8 corresponds to copy_thread's esp0 setting.
15242 */
15243- pushl_cfi ((TI_sysenter_return)-THREAD_SIZE+8+4*4)(%esp)
15244+ pushl_cfi $0
15245 CFI_REL_OFFSET eip, 0
15246
15247 pushl_cfi %eax
15248 SAVE_ALL
15249+ GET_THREAD_INFO(%ebp)
15250+ movl TI_sysenter_return(%ebp),%ebp
15251+ movl %ebp,PT_EIP(%esp)
15252 ENABLE_INTERRUPTS(CLBR_NONE)
15253
15254 /*
15255 * Load the potential sixth argument from user stack.
15256 * Careful about security.
15257 */
15258+ movl PT_OLDESP(%esp),%ebp
15259+
15260+#ifdef CONFIG_PAX_MEMORY_UDEREF
15261+ mov PT_OLDSS(%esp),%ds
15262+1: movl %ds:(%ebp),%ebp
15263+ push %ss
15264+ pop %ds
15265+#else
15266 cmpl $__PAGE_OFFSET-3,%ebp
15267 jae syscall_fault
15268 1: movl (%ebp),%ebp
15269+#endif
15270+
15271 movl %ebp,PT_EBP(%esp)
15272 _ASM_EXTABLE(1b,syscall_fault)
15273
15274 GET_THREAD_INFO(%ebp)
15275
15276+#ifdef CONFIG_PAX_RANDKSTACK
15277+ pax_erase_kstack
15278+#endif
15279+
15280 testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%ebp)
15281 jnz sysenter_audit
15282 sysenter_do_call:
15283@@ -427,12 +599,24 @@ sysenter_do_call:
15284 testl $_TIF_ALLWORK_MASK, %ecx
15285 jne sysexit_audit
15286 sysenter_exit:
15287+
15288+#ifdef CONFIG_PAX_RANDKSTACK
15289+ pushl_cfi %eax
15290+ movl %esp, %eax
15291+ call pax_randomize_kstack
15292+ popl_cfi %eax
15293+#endif
15294+
15295+ pax_erase_kstack
15296+
15297 /* if something modifies registers it must also disable sysexit */
15298 movl PT_EIP(%esp), %edx
15299 movl PT_OLDESP(%esp), %ecx
15300 xorl %ebp,%ebp
15301 TRACE_IRQS_ON
15302 1: mov PT_FS(%esp), %fs
15303+2: mov PT_DS(%esp), %ds
15304+3: mov PT_ES(%esp), %es
15305 PTGS_TO_GS
15306 ENABLE_INTERRUPTS_SYSEXIT
15307
15308@@ -449,6 +633,9 @@ sysenter_audit:
15309 movl %eax,%edx /* 2nd arg: syscall number */
15310 movl $AUDIT_ARCH_I386,%eax /* 1st arg: audit arch */
15311 call __audit_syscall_entry
15312+
15313+ pax_erase_kstack
15314+
15315 pushl_cfi %ebx
15316 movl PT_EAX(%esp),%eax /* reload syscall number */
15317 jmp sysenter_do_call
15318@@ -474,10 +661,16 @@ sysexit_audit:
15319
15320 CFI_ENDPROC
15321 .pushsection .fixup,"ax"
15322-2: movl $0,PT_FS(%esp)
15323+4: movl $0,PT_FS(%esp)
15324+ jmp 1b
15325+5: movl $0,PT_DS(%esp)
15326+ jmp 1b
15327+6: movl $0,PT_ES(%esp)
15328 jmp 1b
15329 .popsection
15330- _ASM_EXTABLE(1b,2b)
15331+ _ASM_EXTABLE(1b,4b)
15332+ _ASM_EXTABLE(2b,5b)
15333+ _ASM_EXTABLE(3b,6b)
15334 PTGS_TO_GS_EX
15335 ENDPROC(ia32_sysenter_target)
15336
15337@@ -491,6 +684,11 @@ ENTRY(system_call)
15338 pushl_cfi %eax # save orig_eax
15339 SAVE_ALL
15340 GET_THREAD_INFO(%ebp)
15341+
15342+#ifdef CONFIG_PAX_RANDKSTACK
15343+ pax_erase_kstack
15344+#endif
15345+
15346 # system call tracing in operation / emulation
15347 testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%ebp)
15348 jnz syscall_trace_entry
15349@@ -509,6 +707,15 @@ syscall_exit:
15350 testl $_TIF_ALLWORK_MASK, %ecx # current->work
15351 jne syscall_exit_work
15352
15353+restore_all_pax:
15354+
15355+#ifdef CONFIG_PAX_RANDKSTACK
15356+ movl %esp, %eax
15357+ call pax_randomize_kstack
15358+#endif
15359+
15360+ pax_erase_kstack
15361+
15362 restore_all:
15363 TRACE_IRQS_IRET
15364 restore_all_notrace:
15365@@ -565,14 +772,34 @@ ldt_ss:
15366 * compensating for the offset by changing to the ESPFIX segment with
15367 * a base address that matches for the difference.
15368 */
15369-#define GDT_ESPFIX_SS PER_CPU_VAR(gdt_page) + (GDT_ENTRY_ESPFIX_SS * 8)
15370+#define GDT_ESPFIX_SS (GDT_ENTRY_ESPFIX_SS * 8)(%ebx)
15371 mov %esp, %edx /* load kernel esp */
15372 mov PT_OLDESP(%esp), %eax /* load userspace esp */
15373 mov %dx, %ax /* eax: new kernel esp */
15374 sub %eax, %edx /* offset (low word is 0) */
15375+#ifdef CONFIG_SMP
15376+ movl PER_CPU_VAR(cpu_number), %ebx
15377+ shll $PAGE_SHIFT_asm, %ebx
15378+ addl $cpu_gdt_table, %ebx
15379+#else
15380+ movl $cpu_gdt_table, %ebx
15381+#endif
15382 shr $16, %edx
15383- mov %dl, GDT_ESPFIX_SS + 4 /* bits 16..23 */
15384- mov %dh, GDT_ESPFIX_SS + 7 /* bits 24..31 */
15385+
15386+#ifdef CONFIG_PAX_KERNEXEC
15387+ mov %cr0, %esi
15388+ btr $16, %esi
15389+ mov %esi, %cr0
15390+#endif
15391+
15392+ mov %dl, 4 + GDT_ESPFIX_SS /* bits 16..23 */
15393+ mov %dh, 7 + GDT_ESPFIX_SS /* bits 24..31 */
15394+
15395+#ifdef CONFIG_PAX_KERNEXEC
15396+ bts $16, %esi
15397+ mov %esi, %cr0
15398+#endif
15399+
15400 pushl_cfi $__ESPFIX_SS
15401 pushl_cfi %eax /* new kernel esp */
15402 /* Disable interrupts, but do not irqtrace this section: we
15403@@ -601,35 +828,23 @@ work_resched:
15404 movl TI_flags(%ebp), %ecx
15405 andl $_TIF_WORK_MASK, %ecx # is there any work to be done other
15406 # than syscall tracing?
15407- jz restore_all
15408+ jz restore_all_pax
15409 testb $_TIF_NEED_RESCHED, %cl
15410 jnz work_resched
15411
15412 work_notifysig: # deal with pending signals and
15413 # notify-resume requests
15414+ movl %esp, %eax
15415 #ifdef CONFIG_VM86
15416 testl $X86_EFLAGS_VM, PT_EFLAGS(%esp)
15417- movl %esp, %eax
15418- jne work_notifysig_v86 # returning to kernel-space or
15419+ jz 1f # returning to kernel-space or
15420 # vm86-space
15421- TRACE_IRQS_ON
15422- ENABLE_INTERRUPTS(CLBR_NONE)
15423- movb PT_CS(%esp), %bl
15424- andb $SEGMENT_RPL_MASK, %bl
15425- cmpb $USER_RPL, %bl
15426- jb resume_kernel
15427- xorl %edx, %edx
15428- call do_notify_resume
15429- jmp resume_userspace
15430
15431- ALIGN
15432-work_notifysig_v86:
15433 pushl_cfi %ecx # save ti_flags for do_notify_resume
15434 call save_v86_state # %eax contains pt_regs pointer
15435 popl_cfi %ecx
15436 movl %eax, %esp
15437-#else
15438- movl %esp, %eax
15439+1:
15440 #endif
15441 TRACE_IRQS_ON
15442 ENABLE_INTERRUPTS(CLBR_NONE)
15443@@ -640,7 +855,7 @@ work_notifysig_v86:
15444 xorl %edx, %edx
15445 call do_notify_resume
15446 jmp resume_userspace
15447-END(work_pending)
15448+ENDPROC(work_pending)
15449
15450 # perform syscall exit tracing
15451 ALIGN
15452@@ -648,11 +863,14 @@ syscall_trace_entry:
15453 movl $-ENOSYS,PT_EAX(%esp)
15454 movl %esp, %eax
15455 call syscall_trace_enter
15456+
15457+ pax_erase_kstack
15458+
15459 /* What it returned is what we'll actually use. */
15460 cmpl $(NR_syscalls), %eax
15461 jnae syscall_call
15462 jmp syscall_exit
15463-END(syscall_trace_entry)
15464+ENDPROC(syscall_trace_entry)
15465
15466 # perform syscall exit tracing
15467 ALIGN
15468@@ -665,20 +883,24 @@ syscall_exit_work:
15469 movl %esp, %eax
15470 call syscall_trace_leave
15471 jmp resume_userspace
15472-END(syscall_exit_work)
15473+ENDPROC(syscall_exit_work)
15474 CFI_ENDPROC
15475
15476 RING0_INT_FRAME # can't unwind into user space anyway
15477 syscall_fault:
15478+#ifdef CONFIG_PAX_MEMORY_UDEREF
15479+ push %ss
15480+ pop %ds
15481+#endif
15482 GET_THREAD_INFO(%ebp)
15483 movl $-EFAULT,PT_EAX(%esp)
15484 jmp resume_userspace
15485-END(syscall_fault)
15486+ENDPROC(syscall_fault)
15487
15488 syscall_badsys:
15489 movl $-ENOSYS,PT_EAX(%esp)
15490 jmp resume_userspace
15491-END(syscall_badsys)
15492+ENDPROC(syscall_badsys)
15493 CFI_ENDPROC
15494 /*
15495 * End of kprobes section
15496@@ -750,6 +972,36 @@ ENTRY(ptregs_clone)
15497 CFI_ENDPROC
15498 ENDPROC(ptregs_clone)
15499
15500+ ALIGN;
15501+ENTRY(kernel_execve)
15502+ CFI_STARTPROC
15503+ pushl_cfi %ebp
15504+ sub $PT_OLDSS+4,%esp
15505+ pushl_cfi %edi
15506+ pushl_cfi %ecx
15507+ pushl_cfi %eax
15508+ lea 3*4(%esp),%edi
15509+ mov $PT_OLDSS/4+1,%ecx
15510+ xorl %eax,%eax
15511+ rep stosl
15512+ popl_cfi %eax
15513+ popl_cfi %ecx
15514+ popl_cfi %edi
15515+ movl $X86_EFLAGS_IF,PT_EFLAGS(%esp)
15516+ pushl_cfi %esp
15517+ call sys_execve
15518+ add $4,%esp
15519+ CFI_ADJUST_CFA_OFFSET -4
15520+ GET_THREAD_INFO(%ebp)
15521+ test %eax,%eax
15522+ jz syscall_exit
15523+ add $PT_OLDSS+4,%esp
15524+ CFI_ADJUST_CFA_OFFSET -PT_OLDSS-4
15525+ popl_cfi %ebp
15526+ ret
15527+ CFI_ENDPROC
15528+ENDPROC(kernel_execve)
15529+
15530 .macro FIXUP_ESPFIX_STACK
15531 /*
15532 * Switch back for ESPFIX stack to the normal zerobased stack
15533@@ -759,8 +1011,15 @@ ENDPROC(ptregs_clone)
15534 * normal stack and adjusts ESP with the matching offset.
15535 */
15536 /* fixup the stack */
15537- mov GDT_ESPFIX_SS + 4, %al /* bits 16..23 */
15538- mov GDT_ESPFIX_SS + 7, %ah /* bits 24..31 */
15539+#ifdef CONFIG_SMP
15540+ movl PER_CPU_VAR(cpu_number), %ebx
15541+ shll $PAGE_SHIFT_asm, %ebx
15542+ addl $cpu_gdt_table, %ebx
15543+#else
15544+ movl $cpu_gdt_table, %ebx
15545+#endif
15546+ mov 4 + GDT_ESPFIX_SS, %al /* bits 16..23 */
15547+ mov 7 + GDT_ESPFIX_SS, %ah /* bits 24..31 */
15548 shl $16, %eax
15549 addl %esp, %eax /* the adjusted stack pointer */
15550 pushl_cfi $__KERNEL_DS
15551@@ -813,7 +1072,7 @@ vector=vector+1
15552 .endr
15553 2: jmp common_interrupt
15554 .endr
15555-END(irq_entries_start)
15556+ENDPROC(irq_entries_start)
15557
15558 .previous
15559 END(interrupt)
15560@@ -861,7 +1120,7 @@ ENTRY(coprocessor_error)
15561 pushl_cfi $do_coprocessor_error
15562 jmp error_code
15563 CFI_ENDPROC
15564-END(coprocessor_error)
15565+ENDPROC(coprocessor_error)
15566
15567 ENTRY(simd_coprocessor_error)
15568 RING0_INT_FRAME
15569@@ -882,7 +1141,7 @@ ENTRY(simd_coprocessor_error)
15570 #endif
15571 jmp error_code
15572 CFI_ENDPROC
15573-END(simd_coprocessor_error)
15574+ENDPROC(simd_coprocessor_error)
15575
15576 ENTRY(device_not_available)
15577 RING0_INT_FRAME
15578@@ -890,18 +1149,18 @@ ENTRY(device_not_available)
15579 pushl_cfi $do_device_not_available
15580 jmp error_code
15581 CFI_ENDPROC
15582-END(device_not_available)
15583+ENDPROC(device_not_available)
15584
15585 #ifdef CONFIG_PARAVIRT
15586 ENTRY(native_iret)
15587 iret
15588 _ASM_EXTABLE(native_iret, iret_exc)
15589-END(native_iret)
15590+ENDPROC(native_iret)
15591
15592 ENTRY(native_irq_enable_sysexit)
15593 sti
15594 sysexit
15595-END(native_irq_enable_sysexit)
15596+ENDPROC(native_irq_enable_sysexit)
15597 #endif
15598
15599 ENTRY(overflow)
15600@@ -910,7 +1169,7 @@ ENTRY(overflow)
15601 pushl_cfi $do_overflow
15602 jmp error_code
15603 CFI_ENDPROC
15604-END(overflow)
15605+ENDPROC(overflow)
15606
15607 ENTRY(bounds)
15608 RING0_INT_FRAME
15609@@ -918,7 +1177,7 @@ ENTRY(bounds)
15610 pushl_cfi $do_bounds
15611 jmp error_code
15612 CFI_ENDPROC
15613-END(bounds)
15614+ENDPROC(bounds)
15615
15616 ENTRY(invalid_op)
15617 RING0_INT_FRAME
15618@@ -926,7 +1185,7 @@ ENTRY(invalid_op)
15619 pushl_cfi $do_invalid_op
15620 jmp error_code
15621 CFI_ENDPROC
15622-END(invalid_op)
15623+ENDPROC(invalid_op)
15624
15625 ENTRY(coprocessor_segment_overrun)
15626 RING0_INT_FRAME
15627@@ -934,35 +1193,35 @@ ENTRY(coprocessor_segment_overrun)
15628 pushl_cfi $do_coprocessor_segment_overrun
15629 jmp error_code
15630 CFI_ENDPROC
15631-END(coprocessor_segment_overrun)
15632+ENDPROC(coprocessor_segment_overrun)
15633
15634 ENTRY(invalid_TSS)
15635 RING0_EC_FRAME
15636 pushl_cfi $do_invalid_TSS
15637 jmp error_code
15638 CFI_ENDPROC
15639-END(invalid_TSS)
15640+ENDPROC(invalid_TSS)
15641
15642 ENTRY(segment_not_present)
15643 RING0_EC_FRAME
15644 pushl_cfi $do_segment_not_present
15645 jmp error_code
15646 CFI_ENDPROC
15647-END(segment_not_present)
15648+ENDPROC(segment_not_present)
15649
15650 ENTRY(stack_segment)
15651 RING0_EC_FRAME
15652 pushl_cfi $do_stack_segment
15653 jmp error_code
15654 CFI_ENDPROC
15655-END(stack_segment)
15656+ENDPROC(stack_segment)
15657
15658 ENTRY(alignment_check)
15659 RING0_EC_FRAME
15660 pushl_cfi $do_alignment_check
15661 jmp error_code
15662 CFI_ENDPROC
15663-END(alignment_check)
15664+ENDPROC(alignment_check)
15665
15666 ENTRY(divide_error)
15667 RING0_INT_FRAME
15668@@ -970,7 +1229,7 @@ ENTRY(divide_error)
15669 pushl_cfi $do_divide_error
15670 jmp error_code
15671 CFI_ENDPROC
15672-END(divide_error)
15673+ENDPROC(divide_error)
15674
15675 #ifdef CONFIG_X86_MCE
15676 ENTRY(machine_check)
15677@@ -979,7 +1238,7 @@ ENTRY(machine_check)
15678 pushl_cfi machine_check_vector
15679 jmp error_code
15680 CFI_ENDPROC
15681-END(machine_check)
15682+ENDPROC(machine_check)
15683 #endif
15684
15685 ENTRY(spurious_interrupt_bug)
15686@@ -988,7 +1247,7 @@ ENTRY(spurious_interrupt_bug)
15687 pushl_cfi $do_spurious_interrupt_bug
15688 jmp error_code
15689 CFI_ENDPROC
15690-END(spurious_interrupt_bug)
15691+ENDPROC(spurious_interrupt_bug)
15692 /*
15693 * End of kprobes section
15694 */
15695@@ -1102,7 +1361,7 @@ BUILD_INTERRUPT3(xen_hvm_callback_vector, XEN_HVM_EVTCHN_CALLBACK,
15696
15697 ENTRY(mcount)
15698 ret
15699-END(mcount)
15700+ENDPROC(mcount)
15701
15702 ENTRY(ftrace_caller)
15703 cmpl $0, function_trace_stop
15704@@ -1131,7 +1390,7 @@ ftrace_graph_call:
15705 .globl ftrace_stub
15706 ftrace_stub:
15707 ret
15708-END(ftrace_caller)
15709+ENDPROC(ftrace_caller)
15710
15711 #else /* ! CONFIG_DYNAMIC_FTRACE */
15712
15713@@ -1167,7 +1426,7 @@ trace:
15714 popl %ecx
15715 popl %eax
15716 jmp ftrace_stub
15717-END(mcount)
15718+ENDPROC(mcount)
15719 #endif /* CONFIG_DYNAMIC_FTRACE */
15720 #endif /* CONFIG_FUNCTION_TRACER */
15721
15722@@ -1188,7 +1447,7 @@ ENTRY(ftrace_graph_caller)
15723 popl %ecx
15724 popl %eax
15725 ret
15726-END(ftrace_graph_caller)
15727+ENDPROC(ftrace_graph_caller)
15728
15729 .globl return_to_handler
15730 return_to_handler:
15731@@ -1243,15 +1502,18 @@ error_code:
15732 movl $-1, PT_ORIG_EAX(%esp) # no syscall to restart
15733 REG_TO_PTGS %ecx
15734 SET_KERNEL_GS %ecx
15735- movl $(__USER_DS), %ecx
15736+ movl $(__KERNEL_DS), %ecx
15737 movl %ecx, %ds
15738 movl %ecx, %es
15739+
15740+ pax_enter_kernel
15741+
15742 TRACE_IRQS_OFF
15743 movl %esp,%eax # pt_regs pointer
15744 call *%edi
15745 jmp ret_from_exception
15746 CFI_ENDPROC
15747-END(page_fault)
15748+ENDPROC(page_fault)
15749
15750 /*
15751 * Debug traps and NMI can happen at the one SYSENTER instruction
15752@@ -1293,7 +1555,7 @@ debug_stack_correct:
15753 call do_debug
15754 jmp ret_from_exception
15755 CFI_ENDPROC
15756-END(debug)
15757+ENDPROC(debug)
15758
15759 /*
15760 * NMI is doubly nasty. It can happen _while_ we're handling
15761@@ -1330,6 +1592,9 @@ nmi_stack_correct:
15762 xorl %edx,%edx # zero error code
15763 movl %esp,%eax # pt_regs pointer
15764 call do_nmi
15765+
15766+ pax_exit_kernel
15767+
15768 jmp restore_all_notrace
15769 CFI_ENDPROC
15770
15771@@ -1366,12 +1631,15 @@ nmi_espfix_stack:
15772 FIXUP_ESPFIX_STACK # %eax == %esp
15773 xorl %edx,%edx # zero error code
15774 call do_nmi
15775+
15776+ pax_exit_kernel
15777+
15778 RESTORE_REGS
15779 lss 12+4(%esp), %esp # back to espfix stack
15780 CFI_ADJUST_CFA_OFFSET -24
15781 jmp irq_return
15782 CFI_ENDPROC
15783-END(nmi)
15784+ENDPROC(nmi)
15785
15786 ENTRY(int3)
15787 RING0_INT_FRAME
15788@@ -1383,14 +1651,14 @@ ENTRY(int3)
15789 call do_int3
15790 jmp ret_from_exception
15791 CFI_ENDPROC
15792-END(int3)
15793+ENDPROC(int3)
15794
15795 ENTRY(general_protection)
15796 RING0_EC_FRAME
15797 pushl_cfi $do_general_protection
15798 jmp error_code
15799 CFI_ENDPROC
15800-END(general_protection)
15801+ENDPROC(general_protection)
15802
15803 #ifdef CONFIG_KVM_GUEST
15804 ENTRY(async_page_fault)
15805@@ -1398,7 +1666,7 @@ ENTRY(async_page_fault)
15806 pushl_cfi $do_async_page_fault
15807 jmp error_code
15808 CFI_ENDPROC
15809-END(async_page_fault)
15810+ENDPROC(async_page_fault)
15811 #endif
15812
15813 /*
15814diff --git a/arch/x86/kernel/entry_64.S b/arch/x86/kernel/entry_64.S
15815index dcdd0ea..a520f76 100644
15816--- a/arch/x86/kernel/entry_64.S
15817+++ b/arch/x86/kernel/entry_64.S
15818@@ -57,6 +57,8 @@
15819 #include <asm/percpu.h>
15820 #include <asm/asm.h>
15821 #include <linux/err.h>
15822+#include <asm/pgtable.h>
15823+#include <asm/alternative-asm.h>
15824
15825 /* Avoid __ASSEMBLER__'ifying <linux/audit.h> just for this. */
15826 #include <linux/elf-em.h>
15827@@ -70,8 +72,9 @@
15828 #ifdef CONFIG_FUNCTION_TRACER
15829 #ifdef CONFIG_DYNAMIC_FTRACE
15830 ENTRY(mcount)
15831+ pax_force_retaddr
15832 retq
15833-END(mcount)
15834+ENDPROC(mcount)
15835
15836 ENTRY(ftrace_caller)
15837 cmpl $0, function_trace_stop
15838@@ -94,8 +97,9 @@ GLOBAL(ftrace_graph_call)
15839 #endif
15840
15841 GLOBAL(ftrace_stub)
15842+ pax_force_retaddr
15843 retq
15844-END(ftrace_caller)
15845+ENDPROC(ftrace_caller)
15846
15847 #else /* ! CONFIG_DYNAMIC_FTRACE */
15848 ENTRY(mcount)
15849@@ -114,6 +118,7 @@ ENTRY(mcount)
15850 #endif
15851
15852 GLOBAL(ftrace_stub)
15853+ pax_force_retaddr
15854 retq
15855
15856 trace:
15857@@ -123,12 +128,13 @@ trace:
15858 movq 8(%rbp), %rsi
15859 subq $MCOUNT_INSN_SIZE, %rdi
15860
15861+ pax_force_fptr ftrace_trace_function
15862 call *ftrace_trace_function
15863
15864 MCOUNT_RESTORE_FRAME
15865
15866 jmp ftrace_stub
15867-END(mcount)
15868+ENDPROC(mcount)
15869 #endif /* CONFIG_DYNAMIC_FTRACE */
15870 #endif /* CONFIG_FUNCTION_TRACER */
15871
15872@@ -148,8 +154,9 @@ ENTRY(ftrace_graph_caller)
15873
15874 MCOUNT_RESTORE_FRAME
15875
15876+ pax_force_retaddr
15877 retq
15878-END(ftrace_graph_caller)
15879+ENDPROC(ftrace_graph_caller)
15880
15881 GLOBAL(return_to_handler)
15882 subq $24, %rsp
15883@@ -165,6 +172,7 @@ GLOBAL(return_to_handler)
15884 movq 8(%rsp), %rdx
15885 movq (%rsp), %rax
15886 addq $24, %rsp
15887+ pax_force_fptr %rdi
15888 jmp *%rdi
15889 #endif
15890
15891@@ -180,6 +188,273 @@ ENTRY(native_usergs_sysret64)
15892 ENDPROC(native_usergs_sysret64)
15893 #endif /* CONFIG_PARAVIRT */
15894
15895+ .macro ljmpq sel, off
15896+#if defined(CONFIG_MPSC) || defined(CONFIG_MCORE2) || defined (CONFIG_MATOM)
15897+ .byte 0x48; ljmp *1234f(%rip)
15898+ .pushsection .rodata
15899+ .align 16
15900+ 1234: .quad \off; .word \sel
15901+ .popsection
15902+#else
15903+ pushq $\sel
15904+ pushq $\off
15905+ lretq
15906+#endif
15907+ .endm
15908+
15909+ .macro pax_enter_kernel
15910+ pax_set_fptr_mask
15911+#ifdef CONFIG_PAX_KERNEXEC
15912+ call pax_enter_kernel
15913+#endif
15914+ .endm
15915+
15916+ .macro pax_exit_kernel
15917+#ifdef CONFIG_PAX_KERNEXEC
15918+ call pax_exit_kernel
15919+#endif
15920+ .endm
15921+
15922+#ifdef CONFIG_PAX_KERNEXEC
15923+ENTRY(pax_enter_kernel)
15924+ pushq %rdi
15925+
15926+#ifdef CONFIG_PARAVIRT
15927+ PV_SAVE_REGS(CLBR_RDI)
15928+#endif
15929+
15930+ GET_CR0_INTO_RDI
15931+ bts $16,%rdi
15932+ jnc 3f
15933+ mov %cs,%edi
15934+ cmp $__KERNEL_CS,%edi
15935+ jnz 2f
15936+1:
15937+
15938+#ifdef CONFIG_PARAVIRT
15939+ PV_RESTORE_REGS(CLBR_RDI)
15940+#endif
15941+
15942+ popq %rdi
15943+ pax_force_retaddr
15944+ retq
15945+
15946+2: ljmpq __KERNEL_CS,1f
15947+3: ljmpq __KERNEXEC_KERNEL_CS,4f
15948+4: SET_RDI_INTO_CR0
15949+ jmp 1b
15950+ENDPROC(pax_enter_kernel)
15951+
15952+ENTRY(pax_exit_kernel)
15953+ pushq %rdi
15954+
15955+#ifdef CONFIG_PARAVIRT
15956+ PV_SAVE_REGS(CLBR_RDI)
15957+#endif
15958+
15959+ mov %cs,%rdi
15960+ cmp $__KERNEXEC_KERNEL_CS,%edi
15961+ jz 2f
15962+1:
15963+
15964+#ifdef CONFIG_PARAVIRT
15965+ PV_RESTORE_REGS(CLBR_RDI);
15966+#endif
15967+
15968+ popq %rdi
15969+ pax_force_retaddr
15970+ retq
15971+
15972+2: GET_CR0_INTO_RDI
15973+ btr $16,%rdi
15974+ ljmpq __KERNEL_CS,3f
15975+3: SET_RDI_INTO_CR0
15976+ jmp 1b
15977+ENDPROC(pax_exit_kernel)
15978+#endif
15979+
15980+ .macro pax_enter_kernel_user
15981+ pax_set_fptr_mask
15982+#ifdef CONFIG_PAX_MEMORY_UDEREF
15983+ call pax_enter_kernel_user
15984+#endif
15985+ .endm
15986+
15987+ .macro pax_exit_kernel_user
15988+#ifdef CONFIG_PAX_MEMORY_UDEREF
15989+ call pax_exit_kernel_user
15990+#endif
15991+#ifdef CONFIG_PAX_RANDKSTACK
15992+ pushq %rax
15993+ call pax_randomize_kstack
15994+ popq %rax
15995+#endif
15996+ .endm
15997+
15998+#ifdef CONFIG_PAX_MEMORY_UDEREF
15999+ENTRY(pax_enter_kernel_user)
16000+ pushq %rdi
16001+ pushq %rbx
16002+
16003+#ifdef CONFIG_PARAVIRT
16004+ PV_SAVE_REGS(CLBR_RDI)
16005+#endif
16006+
16007+ GET_CR3_INTO_RDI
16008+ mov %rdi,%rbx
16009+ add $__START_KERNEL_map,%rbx
16010+ sub phys_base(%rip),%rbx
16011+
16012+#ifdef CONFIG_PARAVIRT
16013+ pushq %rdi
16014+ cmpl $0, pv_info+PARAVIRT_enabled
16015+ jz 1f
16016+ i = 0
16017+ .rept USER_PGD_PTRS
16018+ mov i*8(%rbx),%rsi
16019+ mov $0,%sil
16020+ lea i*8(%rbx),%rdi
16021+ call PARA_INDIRECT(pv_mmu_ops+PV_MMU_set_pgd_batched)
16022+ i = i + 1
16023+ .endr
16024+ jmp 2f
16025+1:
16026+#endif
16027+
16028+ i = 0
16029+ .rept USER_PGD_PTRS
16030+ movb $0,i*8(%rbx)
16031+ i = i + 1
16032+ .endr
16033+
16034+#ifdef CONFIG_PARAVIRT
16035+2: popq %rdi
16036+#endif
16037+ SET_RDI_INTO_CR3
16038+
16039+#ifdef CONFIG_PAX_KERNEXEC
16040+ GET_CR0_INTO_RDI
16041+ bts $16,%rdi
16042+ SET_RDI_INTO_CR0
16043+#endif
16044+
16045+#ifdef CONFIG_PARAVIRT
16046+ PV_RESTORE_REGS(CLBR_RDI)
16047+#endif
16048+
16049+ popq %rbx
16050+ popq %rdi
16051+ pax_force_retaddr
16052+ retq
16053+ENDPROC(pax_enter_kernel_user)
16054+
16055+ENTRY(pax_exit_kernel_user)
16056+ push %rdi
16057+
16058+#ifdef CONFIG_PARAVIRT
16059+ pushq %rbx
16060+ PV_SAVE_REGS(CLBR_RDI)
16061+#endif
16062+
16063+#ifdef CONFIG_PAX_KERNEXEC
16064+ GET_CR0_INTO_RDI
16065+ btr $16,%rdi
16066+ SET_RDI_INTO_CR0
16067+#endif
16068+
16069+ GET_CR3_INTO_RDI
16070+ add $__START_KERNEL_map,%rdi
16071+ sub phys_base(%rip),%rdi
16072+
16073+#ifdef CONFIG_PARAVIRT
16074+ cmpl $0, pv_info+PARAVIRT_enabled
16075+ jz 1f
16076+ mov %rdi,%rbx
16077+ i = 0
16078+ .rept USER_PGD_PTRS
16079+ mov i*8(%rbx),%rsi
16080+ mov $0x67,%sil
16081+ lea i*8(%rbx),%rdi
16082+ call PARA_INDIRECT(pv_mmu_ops+PV_MMU_set_pgd_batched)
16083+ i = i + 1
16084+ .endr
16085+ jmp 2f
16086+1:
16087+#endif
16088+
16089+ i = 0
16090+ .rept USER_PGD_PTRS
16091+ movb $0x67,i*8(%rdi)
16092+ i = i + 1
16093+ .endr
16094+
16095+#ifdef CONFIG_PARAVIRT
16096+2: PV_RESTORE_REGS(CLBR_RDI)
16097+ popq %rbx
16098+#endif
16099+
16100+ popq %rdi
16101+ pax_force_retaddr
16102+ retq
16103+ENDPROC(pax_exit_kernel_user)
16104+#endif
16105+
16106+.macro pax_erase_kstack
16107+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
16108+ call pax_erase_kstack
16109+#endif
16110+.endm
16111+
16112+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
16113+ENTRY(pax_erase_kstack)
16114+ pushq %rdi
16115+ pushq %rcx
16116+ pushq %rax
16117+ pushq %r11
16118+
16119+ GET_THREAD_INFO(%r11)
16120+ mov TI_lowest_stack(%r11), %rdi
16121+ mov $-0xBEEF, %rax
16122+ std
16123+
16124+1: mov %edi, %ecx
16125+ and $THREAD_SIZE_asm - 1, %ecx
16126+ shr $3, %ecx
16127+ repne scasq
16128+ jecxz 2f
16129+
16130+ cmp $2*8, %ecx
16131+ jc 2f
16132+
16133+ mov $2*8, %ecx
16134+ repe scasq
16135+ jecxz 2f
16136+ jne 1b
16137+
16138+2: cld
16139+ mov %esp, %ecx
16140+ sub %edi, %ecx
16141+
16142+ cmp $THREAD_SIZE_asm, %rcx
16143+ jb 3f
16144+ ud2
16145+3:
16146+
16147+ shr $3, %ecx
16148+ rep stosq
16149+
16150+ mov TI_task_thread_sp0(%r11), %rdi
16151+ sub $256, %rdi
16152+ mov %rdi, TI_lowest_stack(%r11)
16153+
16154+ popq %r11
16155+ popq %rax
16156+ popq %rcx
16157+ popq %rdi
16158+ pax_force_retaddr
16159+ ret
16160+ENDPROC(pax_erase_kstack)
16161+#endif
16162
16163 .macro TRACE_IRQS_IRETQ offset=ARGOFFSET
16164 #ifdef CONFIG_TRACE_IRQFLAGS
16165@@ -271,8 +546,8 @@ ENDPROC(native_usergs_sysret64)
16166 .endm
16167
16168 .macro UNFAKE_STACK_FRAME
16169- addq $8*6, %rsp
16170- CFI_ADJUST_CFA_OFFSET -(6*8)
16171+ addq $8*6 + ARG_SKIP, %rsp
16172+ CFI_ADJUST_CFA_OFFSET -(6*8 + ARG_SKIP)
16173 .endm
16174
16175 /*
16176@@ -359,7 +634,7 @@ ENDPROC(native_usergs_sysret64)
16177 movq %rsp, %rsi
16178
16179 leaq -RBP(%rsp),%rdi /* arg1 for handler */
16180- testl $3, CS-RBP(%rsi)
16181+ testb $3, CS-RBP(%rsi)
16182 je 1f
16183 SWAPGS
16184 /*
16185@@ -394,9 +669,10 @@ ENTRY(save_rest)
16186 movq_cfi r15, R15+16
16187 movq %r11, 8(%rsp) /* return address */
16188 FIXUP_TOP_OF_STACK %r11, 16
16189+ pax_force_retaddr
16190 ret
16191 CFI_ENDPROC
16192-END(save_rest)
16193+ENDPROC(save_rest)
16194
16195 /* save complete stack frame */
16196 .pushsection .kprobes.text, "ax"
16197@@ -425,9 +701,10 @@ ENTRY(save_paranoid)
16198 js 1f /* negative -> in kernel */
16199 SWAPGS
16200 xorl %ebx,%ebx
16201-1: ret
16202+1: pax_force_retaddr_bts
16203+ ret
16204 CFI_ENDPROC
16205-END(save_paranoid)
16206+ENDPROC(save_paranoid)
16207 .popsection
16208
16209 /*
16210@@ -449,7 +726,7 @@ ENTRY(ret_from_fork)
16211
16212 RESTORE_REST
16213
16214- testl $3, CS-ARGOFFSET(%rsp) # from kernel_thread?
16215+ testb $3, CS-ARGOFFSET(%rsp) # from kernel_thread?
16216 jz retint_restore_args
16217
16218 testl $_TIF_IA32, TI_flags(%rcx) # 32-bit compat task needs IRET
16219@@ -459,7 +736,7 @@ ENTRY(ret_from_fork)
16220 jmp ret_from_sys_call # go to the SYSRET fastpath
16221
16222 CFI_ENDPROC
16223-END(ret_from_fork)
16224+ENDPROC(ret_from_fork)
16225
16226 /*
16227 * System call entry. Up to 6 arguments in registers are supported.
16228@@ -495,7 +772,7 @@ END(ret_from_fork)
16229 ENTRY(system_call)
16230 CFI_STARTPROC simple
16231 CFI_SIGNAL_FRAME
16232- CFI_DEF_CFA rsp,KERNEL_STACK_OFFSET
16233+ CFI_DEF_CFA rsp,0
16234 CFI_REGISTER rip,rcx
16235 /*CFI_REGISTER rflags,r11*/
16236 SWAPGS_UNSAFE_STACK
16237@@ -508,16 +785,23 @@ GLOBAL(system_call_after_swapgs)
16238
16239 movq %rsp,PER_CPU_VAR(old_rsp)
16240 movq PER_CPU_VAR(kernel_stack),%rsp
16241+ SAVE_ARGS 8*6,0
16242+ pax_enter_kernel_user
16243+
16244+#ifdef CONFIG_PAX_RANDKSTACK
16245+ pax_erase_kstack
16246+#endif
16247+
16248 /*
16249 * No need to follow this irqs off/on section - it's straight
16250 * and short:
16251 */
16252 ENABLE_INTERRUPTS(CLBR_NONE)
16253- SAVE_ARGS 8,0
16254 movq %rax,ORIG_RAX-ARGOFFSET(%rsp)
16255 movq %rcx,RIP-ARGOFFSET(%rsp)
16256 CFI_REL_OFFSET rip,RIP-ARGOFFSET
16257- testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
16258+ GET_THREAD_INFO(%rcx)
16259+ testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%rcx)
16260 jnz tracesys
16261 system_call_fastpath:
16262 #if __SYSCALL_MASK == ~0
16263@@ -527,7 +811,7 @@ system_call_fastpath:
16264 cmpl $__NR_syscall_max,%eax
16265 #endif
16266 ja badsys
16267- movq %r10,%rcx
16268+ movq R10-ARGOFFSET(%rsp),%rcx
16269 call *sys_call_table(,%rax,8) # XXX: rip relative
16270 movq %rax,RAX-ARGOFFSET(%rsp)
16271 /*
16272@@ -541,10 +825,13 @@ sysret_check:
16273 LOCKDEP_SYS_EXIT
16274 DISABLE_INTERRUPTS(CLBR_NONE)
16275 TRACE_IRQS_OFF
16276- movl TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET),%edx
16277+ GET_THREAD_INFO(%rcx)
16278+ movl TI_flags(%rcx),%edx
16279 andl %edi,%edx
16280 jnz sysret_careful
16281 CFI_REMEMBER_STATE
16282+ pax_exit_kernel_user
16283+ pax_erase_kstack
16284 /*
16285 * sysretq will re-enable interrupts:
16286 */
16287@@ -596,14 +883,18 @@ badsys:
16288 * jump back to the normal fast path.
16289 */
16290 auditsys:
16291- movq %r10,%r9 /* 6th arg: 4th syscall arg */
16292+ movq R10-ARGOFFSET(%rsp),%r9 /* 6th arg: 4th syscall arg */
16293 movq %rdx,%r8 /* 5th arg: 3rd syscall arg */
16294 movq %rsi,%rcx /* 4th arg: 2nd syscall arg */
16295 movq %rdi,%rdx /* 3rd arg: 1st syscall arg */
16296 movq %rax,%rsi /* 2nd arg: syscall number */
16297 movl $AUDIT_ARCH_X86_64,%edi /* 1st arg: audit arch */
16298 call __audit_syscall_entry
16299+
16300+ pax_erase_kstack
16301+
16302 LOAD_ARGS 0 /* reload call-clobbered registers */
16303+ pax_set_fptr_mask
16304 jmp system_call_fastpath
16305
16306 /*
16307@@ -624,7 +915,7 @@ sysret_audit:
16308 /* Do syscall tracing */
16309 tracesys:
16310 #ifdef CONFIG_AUDITSYSCALL
16311- testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
16312+ testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags(%rcx)
16313 jz auditsys
16314 #endif
16315 SAVE_REST
16316@@ -632,12 +923,16 @@ tracesys:
16317 FIXUP_TOP_OF_STACK %rdi
16318 movq %rsp,%rdi
16319 call syscall_trace_enter
16320+
16321+ pax_erase_kstack
16322+
16323 /*
16324 * Reload arg registers from stack in case ptrace changed them.
16325 * We don't reload %rax because syscall_trace_enter() returned
16326 * the value it wants us to use in the table lookup.
16327 */
16328 LOAD_ARGS ARGOFFSET, 1
16329+ pax_set_fptr_mask
16330 RESTORE_REST
16331 #if __SYSCALL_MASK == ~0
16332 cmpq $__NR_syscall_max,%rax
16333@@ -646,7 +941,7 @@ tracesys:
16334 cmpl $__NR_syscall_max,%eax
16335 #endif
16336 ja int_ret_from_sys_call /* RAX(%rsp) set to -ENOSYS above */
16337- movq %r10,%rcx /* fixup for C */
16338+ movq R10-ARGOFFSET(%rsp),%rcx /* fixup for C */
16339 call *sys_call_table(,%rax,8)
16340 movq %rax,RAX-ARGOFFSET(%rsp)
16341 /* Use IRET because user could have changed frame */
16342@@ -667,7 +962,9 @@ GLOBAL(int_with_check)
16343 andl %edi,%edx
16344 jnz int_careful
16345 andl $~TS_COMPAT,TI_status(%rcx)
16346- jmp retint_swapgs
16347+ pax_exit_kernel_user
16348+ pax_erase_kstack
16349+ jmp retint_swapgs_pax
16350
16351 /* Either reschedule or signal or syscall exit tracking needed. */
16352 /* First do a reschedule test. */
16353@@ -713,7 +1010,7 @@ int_restore_rest:
16354 TRACE_IRQS_OFF
16355 jmp int_with_check
16356 CFI_ENDPROC
16357-END(system_call)
16358+ENDPROC(system_call)
16359
16360 /*
16361 * Certain special system calls that need to save a complete full stack frame.
16362@@ -729,7 +1026,7 @@ ENTRY(\label)
16363 call \func
16364 jmp ptregscall_common
16365 CFI_ENDPROC
16366-END(\label)
16367+ENDPROC(\label)
16368 .endm
16369
16370 PTREGSCALL stub_clone, sys_clone, %r8
16371@@ -747,9 +1044,10 @@ ENTRY(ptregscall_common)
16372 movq_cfi_restore R12+8, r12
16373 movq_cfi_restore RBP+8, rbp
16374 movq_cfi_restore RBX+8, rbx
16375+ pax_force_retaddr
16376 ret $REST_SKIP /* pop extended registers */
16377 CFI_ENDPROC
16378-END(ptregscall_common)
16379+ENDPROC(ptregscall_common)
16380
16381 ENTRY(stub_execve)
16382 CFI_STARTPROC
16383@@ -764,7 +1062,7 @@ ENTRY(stub_execve)
16384 RESTORE_REST
16385 jmp int_ret_from_sys_call
16386 CFI_ENDPROC
16387-END(stub_execve)
16388+ENDPROC(stub_execve)
16389
16390 /*
16391 * sigreturn is special because it needs to restore all registers on return.
16392@@ -782,7 +1080,7 @@ ENTRY(stub_rt_sigreturn)
16393 RESTORE_REST
16394 jmp int_ret_from_sys_call
16395 CFI_ENDPROC
16396-END(stub_rt_sigreturn)
16397+ENDPROC(stub_rt_sigreturn)
16398
16399 #ifdef CONFIG_X86_X32_ABI
16400 PTREGSCALL stub_x32_sigaltstack, sys32_sigaltstack, %rdx
16401@@ -851,7 +1149,7 @@ vector=vector+1
16402 2: jmp common_interrupt
16403 .endr
16404 CFI_ENDPROC
16405-END(irq_entries_start)
16406+ENDPROC(irq_entries_start)
16407
16408 .previous
16409 END(interrupt)
16410@@ -871,6 +1169,16 @@ END(interrupt)
16411 subq $ORIG_RAX-RBP, %rsp
16412 CFI_ADJUST_CFA_OFFSET ORIG_RAX-RBP
16413 SAVE_ARGS_IRQ
16414+#ifdef CONFIG_PAX_MEMORY_UDEREF
16415+ testb $3, CS(%rdi)
16416+ jnz 1f
16417+ pax_enter_kernel
16418+ jmp 2f
16419+1: pax_enter_kernel_user
16420+2:
16421+#else
16422+ pax_enter_kernel
16423+#endif
16424 call \func
16425 .endm
16426
16427@@ -902,7 +1210,7 @@ ret_from_intr:
16428
16429 exit_intr:
16430 GET_THREAD_INFO(%rcx)
16431- testl $3,CS-ARGOFFSET(%rsp)
16432+ testb $3,CS-ARGOFFSET(%rsp)
16433 je retint_kernel
16434
16435 /* Interrupt came from user space */
16436@@ -924,12 +1232,16 @@ retint_swapgs: /* return to user-space */
16437 * The iretq could re-enable interrupts:
16438 */
16439 DISABLE_INTERRUPTS(CLBR_ANY)
16440+ pax_exit_kernel_user
16441+retint_swapgs_pax:
16442 TRACE_IRQS_IRETQ
16443 SWAPGS
16444 jmp restore_args
16445
16446 retint_restore_args: /* return to kernel space */
16447 DISABLE_INTERRUPTS(CLBR_ANY)
16448+ pax_exit_kernel
16449+ pax_force_retaddr (RIP-ARGOFFSET)
16450 /*
16451 * The iretq could re-enable interrupts:
16452 */
16453@@ -1012,7 +1324,7 @@ ENTRY(retint_kernel)
16454 #endif
16455
16456 CFI_ENDPROC
16457-END(common_interrupt)
16458+ENDPROC(common_interrupt)
16459 /*
16460 * End of kprobes section
16461 */
16462@@ -1029,7 +1341,7 @@ ENTRY(\sym)
16463 interrupt \do_sym
16464 jmp ret_from_intr
16465 CFI_ENDPROC
16466-END(\sym)
16467+ENDPROC(\sym)
16468 .endm
16469
16470 #ifdef CONFIG_SMP
16471@@ -1084,12 +1396,22 @@ ENTRY(\sym)
16472 CFI_ADJUST_CFA_OFFSET ORIG_RAX-R15
16473 call error_entry
16474 DEFAULT_FRAME 0
16475+#ifdef CONFIG_PAX_MEMORY_UDEREF
16476+ testb $3, CS(%rsp)
16477+ jnz 1f
16478+ pax_enter_kernel
16479+ jmp 2f
16480+1: pax_enter_kernel_user
16481+2:
16482+#else
16483+ pax_enter_kernel
16484+#endif
16485 movq %rsp,%rdi /* pt_regs pointer */
16486 xorl %esi,%esi /* no error code */
16487 call \do_sym
16488 jmp error_exit /* %ebx: no swapgs flag */
16489 CFI_ENDPROC
16490-END(\sym)
16491+ENDPROC(\sym)
16492 .endm
16493
16494 .macro paranoidzeroentry sym do_sym
16495@@ -1101,15 +1423,25 @@ ENTRY(\sym)
16496 CFI_ADJUST_CFA_OFFSET ORIG_RAX-R15
16497 call save_paranoid
16498 TRACE_IRQS_OFF
16499+#ifdef CONFIG_PAX_MEMORY_UDEREF
16500+ testb $3, CS(%rsp)
16501+ jnz 1f
16502+ pax_enter_kernel
16503+ jmp 2f
16504+1: pax_enter_kernel_user
16505+2:
16506+#else
16507+ pax_enter_kernel
16508+#endif
16509 movq %rsp,%rdi /* pt_regs pointer */
16510 xorl %esi,%esi /* no error code */
16511 call \do_sym
16512 jmp paranoid_exit /* %ebx: no swapgs flag */
16513 CFI_ENDPROC
16514-END(\sym)
16515+ENDPROC(\sym)
16516 .endm
16517
16518-#define INIT_TSS_IST(x) PER_CPU_VAR(init_tss) + (TSS_ist + ((x) - 1) * 8)
16519+#define INIT_TSS_IST(x) (TSS_ist + ((x) - 1) * 8)(%r12)
16520 .macro paranoidzeroentry_ist sym do_sym ist
16521 ENTRY(\sym)
16522 INTR_FRAME
16523@@ -1119,14 +1451,30 @@ ENTRY(\sym)
16524 CFI_ADJUST_CFA_OFFSET ORIG_RAX-R15
16525 call save_paranoid
16526 TRACE_IRQS_OFF_DEBUG
16527+#ifdef CONFIG_PAX_MEMORY_UDEREF
16528+ testb $3, CS(%rsp)
16529+ jnz 1f
16530+ pax_enter_kernel
16531+ jmp 2f
16532+1: pax_enter_kernel_user
16533+2:
16534+#else
16535+ pax_enter_kernel
16536+#endif
16537 movq %rsp,%rdi /* pt_regs pointer */
16538 xorl %esi,%esi /* no error code */
16539+#ifdef CONFIG_SMP
16540+ imul $TSS_size, PER_CPU_VAR(cpu_number), %r12d
16541+ lea init_tss(%r12), %r12
16542+#else
16543+ lea init_tss(%rip), %r12
16544+#endif
16545 subq $EXCEPTION_STKSZ, INIT_TSS_IST(\ist)
16546 call \do_sym
16547 addq $EXCEPTION_STKSZ, INIT_TSS_IST(\ist)
16548 jmp paranoid_exit /* %ebx: no swapgs flag */
16549 CFI_ENDPROC
16550-END(\sym)
16551+ENDPROC(\sym)
16552 .endm
16553
16554 .macro errorentry sym do_sym
16555@@ -1137,13 +1485,23 @@ ENTRY(\sym)
16556 CFI_ADJUST_CFA_OFFSET ORIG_RAX-R15
16557 call error_entry
16558 DEFAULT_FRAME 0
16559+#ifdef CONFIG_PAX_MEMORY_UDEREF
16560+ testb $3, CS(%rsp)
16561+ jnz 1f
16562+ pax_enter_kernel
16563+ jmp 2f
16564+1: pax_enter_kernel_user
16565+2:
16566+#else
16567+ pax_enter_kernel
16568+#endif
16569 movq %rsp,%rdi /* pt_regs pointer */
16570 movq ORIG_RAX(%rsp),%rsi /* get error code */
16571 movq $-1,ORIG_RAX(%rsp) /* no syscall to restart */
16572 call \do_sym
16573 jmp error_exit /* %ebx: no swapgs flag */
16574 CFI_ENDPROC
16575-END(\sym)
16576+ENDPROC(\sym)
16577 .endm
16578
16579 /* error code is on the stack already */
16580@@ -1156,13 +1514,23 @@ ENTRY(\sym)
16581 call save_paranoid
16582 DEFAULT_FRAME 0
16583 TRACE_IRQS_OFF
16584+#ifdef CONFIG_PAX_MEMORY_UDEREF
16585+ testb $3, CS(%rsp)
16586+ jnz 1f
16587+ pax_enter_kernel
16588+ jmp 2f
16589+1: pax_enter_kernel_user
16590+2:
16591+#else
16592+ pax_enter_kernel
16593+#endif
16594 movq %rsp,%rdi /* pt_regs pointer */
16595 movq ORIG_RAX(%rsp),%rsi /* get error code */
16596 movq $-1,ORIG_RAX(%rsp) /* no syscall to restart */
16597 call \do_sym
16598 jmp paranoid_exit /* %ebx: no swapgs flag */
16599 CFI_ENDPROC
16600-END(\sym)
16601+ENDPROC(\sym)
16602 .endm
16603
16604 zeroentry divide_error do_divide_error
16605@@ -1192,9 +1560,10 @@ gs_change:
16606 2: mfence /* workaround */
16607 SWAPGS
16608 popfq_cfi
16609+ pax_force_retaddr
16610 ret
16611 CFI_ENDPROC
16612-END(native_load_gs_index)
16613+ENDPROC(native_load_gs_index)
16614
16615 _ASM_EXTABLE(gs_change,bad_gs)
16616 .section .fixup,"ax"
16617@@ -1213,13 +1582,14 @@ ENTRY(kernel_thread_helper)
16618 * Here we are in the child and the registers are set as they were
16619 * at kernel_thread() invocation in the parent.
16620 */
16621+ pax_force_fptr %rsi
16622 call *%rsi
16623 # exit
16624 mov %eax, %edi
16625 call do_exit
16626 ud2 # padding for call trace
16627 CFI_ENDPROC
16628-END(kernel_thread_helper)
16629+ENDPROC(kernel_thread_helper)
16630
16631 /*
16632 * execve(). This function needs to use IRET, not SYSRET, to set up all state properly.
16633@@ -1246,11 +1616,11 @@ ENTRY(kernel_execve)
16634 RESTORE_REST
16635 testq %rax,%rax
16636 je int_ret_from_sys_call
16637- RESTORE_ARGS
16638 UNFAKE_STACK_FRAME
16639+ pax_force_retaddr
16640 ret
16641 CFI_ENDPROC
16642-END(kernel_execve)
16643+ENDPROC(kernel_execve)
16644
16645 /* Call softirq on interrupt stack. Interrupts are off. */
16646 ENTRY(call_softirq)
16647@@ -1268,9 +1638,10 @@ ENTRY(call_softirq)
16648 CFI_DEF_CFA_REGISTER rsp
16649 CFI_ADJUST_CFA_OFFSET -8
16650 decl PER_CPU_VAR(irq_count)
16651+ pax_force_retaddr
16652 ret
16653 CFI_ENDPROC
16654-END(call_softirq)
16655+ENDPROC(call_softirq)
16656
16657 #ifdef CONFIG_XEN
16658 zeroentry xen_hypervisor_callback xen_do_hypervisor_callback
16659@@ -1308,7 +1679,7 @@ ENTRY(xen_do_hypervisor_callback) # do_hypervisor_callback(struct *pt_regs)
16660 decl PER_CPU_VAR(irq_count)
16661 jmp error_exit
16662 CFI_ENDPROC
16663-END(xen_do_hypervisor_callback)
16664+ENDPROC(xen_do_hypervisor_callback)
16665
16666 /*
16667 * Hypervisor uses this for application faults while it executes.
16668@@ -1367,7 +1738,7 @@ ENTRY(xen_failsafe_callback)
16669 SAVE_ALL
16670 jmp error_exit
16671 CFI_ENDPROC
16672-END(xen_failsafe_callback)
16673+ENDPROC(xen_failsafe_callback)
16674
16675 apicinterrupt XEN_HVM_EVTCHN_CALLBACK \
16676 xen_hvm_callback_vector xen_evtchn_do_upcall
16677@@ -1416,16 +1787,31 @@ ENTRY(paranoid_exit)
16678 TRACE_IRQS_OFF_DEBUG
16679 testl %ebx,%ebx /* swapgs needed? */
16680 jnz paranoid_restore
16681- testl $3,CS(%rsp)
16682+ testb $3,CS(%rsp)
16683 jnz paranoid_userspace
16684+#ifdef CONFIG_PAX_MEMORY_UDEREF
16685+ pax_exit_kernel
16686+ TRACE_IRQS_IRETQ 0
16687+ SWAPGS_UNSAFE_STACK
16688+ RESTORE_ALL 8
16689+ pax_force_retaddr_bts
16690+ jmp irq_return
16691+#endif
16692 paranoid_swapgs:
16693+#ifdef CONFIG_PAX_MEMORY_UDEREF
16694+ pax_exit_kernel_user
16695+#else
16696+ pax_exit_kernel
16697+#endif
16698 TRACE_IRQS_IRETQ 0
16699 SWAPGS_UNSAFE_STACK
16700 RESTORE_ALL 8
16701 jmp irq_return
16702 paranoid_restore:
16703+ pax_exit_kernel
16704 TRACE_IRQS_IRETQ_DEBUG 0
16705 RESTORE_ALL 8
16706+ pax_force_retaddr_bts
16707 jmp irq_return
16708 paranoid_userspace:
16709 GET_THREAD_INFO(%rcx)
16710@@ -1454,7 +1840,7 @@ paranoid_schedule:
16711 TRACE_IRQS_OFF
16712 jmp paranoid_userspace
16713 CFI_ENDPROC
16714-END(paranoid_exit)
16715+ENDPROC(paranoid_exit)
16716
16717 /*
16718 * Exception entry point. This expects an error code/orig_rax on the stack.
16719@@ -1481,12 +1867,13 @@ ENTRY(error_entry)
16720 movq_cfi r14, R14+8
16721 movq_cfi r15, R15+8
16722 xorl %ebx,%ebx
16723- testl $3,CS+8(%rsp)
16724+ testb $3,CS+8(%rsp)
16725 je error_kernelspace
16726 error_swapgs:
16727 SWAPGS
16728 error_sti:
16729 TRACE_IRQS_OFF
16730+ pax_force_retaddr_bts
16731 ret
16732
16733 /*
16734@@ -1513,7 +1900,7 @@ bstep_iret:
16735 movq %rcx,RIP+8(%rsp)
16736 jmp error_swapgs
16737 CFI_ENDPROC
16738-END(error_entry)
16739+ENDPROC(error_entry)
16740
16741
16742 /* ebx: no swapgs flag (1: don't need swapgs, 0: need it) */
16743@@ -1533,7 +1920,7 @@ ENTRY(error_exit)
16744 jnz retint_careful
16745 jmp retint_swapgs
16746 CFI_ENDPROC
16747-END(error_exit)
16748+ENDPROC(error_exit)
16749
16750 /*
16751 * Test if a given stack is an NMI stack or not.
16752@@ -1591,9 +1978,11 @@ ENTRY(nmi)
16753 * If %cs was not the kernel segment, then the NMI triggered in user
16754 * space, which means it is definitely not nested.
16755 */
16756+ cmpl $__KERNEXEC_KERNEL_CS, 16(%rsp)
16757+ je 1f
16758 cmpl $__KERNEL_CS, 16(%rsp)
16759 jne first_nmi
16760-
16761+1:
16762 /*
16763 * Check the special variable on the stack to see if NMIs are
16764 * executing.
16765@@ -1752,6 +2141,17 @@ end_repeat_nmi:
16766 */
16767 movq %cr2, %r12
16768
16769+#ifdef CONFIG_PAX_MEMORY_UDEREF
16770+ testb $3, CS(%rsp)
16771+ jnz 1f
16772+ pax_enter_kernel
16773+ jmp 2f
16774+1: pax_enter_kernel_user
16775+2:
16776+#else
16777+ pax_enter_kernel
16778+#endif
16779+
16780 /* paranoidentry do_nmi, 0; without TRACE_IRQS_OFF */
16781 movq %rsp,%rdi
16782 movq $-1,%rsi
16783@@ -1767,21 +2167,32 @@ end_repeat_nmi:
16784 testl %ebx,%ebx /* swapgs needed? */
16785 jnz nmi_restore
16786 nmi_swapgs:
16787+#ifdef CONFIG_PAX_MEMORY_UDEREF
16788+ pax_exit_kernel_user
16789+#else
16790+ pax_exit_kernel
16791+#endif
16792 SWAPGS_UNSAFE_STACK
16793+ RESTORE_ALL 8
16794+ /* Clear the NMI executing stack variable */
16795+ movq $0, 10*8(%rsp)
16796+ jmp irq_return
16797 nmi_restore:
16798+ pax_exit_kernel
16799 RESTORE_ALL 8
16800+ pax_force_retaddr_bts
16801 /* Clear the NMI executing stack variable */
16802 movq $0, 10*8(%rsp)
16803 jmp irq_return
16804 CFI_ENDPROC
16805-END(nmi)
16806+ENDPROC(nmi)
16807
16808 ENTRY(ignore_sysret)
16809 CFI_STARTPROC
16810 mov $-ENOSYS,%eax
16811 sysret
16812 CFI_ENDPROC
16813-END(ignore_sysret)
16814+ENDPROC(ignore_sysret)
16815
16816 /*
16817 * End of kprobes section
16818diff --git a/arch/x86/kernel/ftrace.c b/arch/x86/kernel/ftrace.c
16819index c3a7cb4..3ad00dc 100644
16820--- a/arch/x86/kernel/ftrace.c
16821+++ b/arch/x86/kernel/ftrace.c
16822@@ -105,6 +105,8 @@ ftrace_modify_code_direct(unsigned long ip, unsigned const char *old_code,
16823 {
16824 unsigned char replaced[MCOUNT_INSN_SIZE];
16825
16826+ ip = ktla_ktva(ip);
16827+
16828 /*
16829 * Note: Due to modules and __init, code can
16830 * disappear and change, we need to protect against faulting
16831@@ -212,7 +214,7 @@ int ftrace_update_ftrace_func(ftrace_func_t func)
16832 unsigned char old[MCOUNT_INSN_SIZE], *new;
16833 int ret;
16834
16835- memcpy(old, &ftrace_call, MCOUNT_INSN_SIZE);
16836+ memcpy(old, (void *)ktla_ktva((unsigned long)ftrace_call), MCOUNT_INSN_SIZE);
16837 new = ftrace_call_replace(ip, (unsigned long)func);
16838
16839 /* See comment above by declaration of modifying_ftrace_code */
16840@@ -605,6 +607,8 @@ static int ftrace_mod_jmp(unsigned long ip,
16841 {
16842 unsigned char code[MCOUNT_INSN_SIZE];
16843
16844+ ip = ktla_ktva(ip);
16845+
16846 if (probe_kernel_read(code, (void *)ip, MCOUNT_INSN_SIZE))
16847 return -EFAULT;
16848
16849diff --git a/arch/x86/kernel/head32.c b/arch/x86/kernel/head32.c
16850index c18f59d..9c0c9f6 100644
16851--- a/arch/x86/kernel/head32.c
16852+++ b/arch/x86/kernel/head32.c
16853@@ -18,6 +18,7 @@
16854 #include <asm/io_apic.h>
16855 #include <asm/bios_ebda.h>
16856 #include <asm/tlbflush.h>
16857+#include <asm/boot.h>
16858
16859 static void __init i386_default_early_setup(void)
16860 {
16861@@ -30,8 +31,7 @@ static void __init i386_default_early_setup(void)
16862
16863 void __init i386_start_kernel(void)
16864 {
16865- memblock_reserve(__pa_symbol(&_text),
16866- __pa_symbol(&__bss_stop) - __pa_symbol(&_text));
16867+ memblock_reserve(LOAD_PHYSICAL_ADDR, __pa_symbol(&__bss_stop) - LOAD_PHYSICAL_ADDR);
16868
16869 #ifdef CONFIG_BLK_DEV_INITRD
16870 /* Reserve INITRD */
16871diff --git a/arch/x86/kernel/head_32.S b/arch/x86/kernel/head_32.S
16872index d42ab17..87b9555 100644
16873--- a/arch/x86/kernel/head_32.S
16874+++ b/arch/x86/kernel/head_32.S
16875@@ -26,6 +26,12 @@
16876 /* Physical address */
16877 #define pa(X) ((X) - __PAGE_OFFSET)
16878
16879+#ifdef CONFIG_PAX_KERNEXEC
16880+#define ta(X) (X)
16881+#else
16882+#define ta(X) ((X) - __PAGE_OFFSET)
16883+#endif
16884+
16885 /*
16886 * References to members of the new_cpu_data structure.
16887 */
16888@@ -55,11 +61,7 @@
16889 * and small than max_low_pfn, otherwise will waste some page table entries
16890 */
16891
16892-#if PTRS_PER_PMD > 1
16893-#define PAGE_TABLE_SIZE(pages) (((pages) / PTRS_PER_PMD) + PTRS_PER_PGD)
16894-#else
16895-#define PAGE_TABLE_SIZE(pages) ((pages) / PTRS_PER_PGD)
16896-#endif
16897+#define PAGE_TABLE_SIZE(pages) ((pages) / PTRS_PER_PTE)
16898
16899 /* Number of possible pages in the lowmem region */
16900 LOWMEM_PAGES = (((1<<32) - __PAGE_OFFSET) >> PAGE_SHIFT)
16901@@ -78,6 +80,12 @@ INIT_MAP_SIZE = PAGE_TABLE_SIZE(KERNEL_PAGES) * PAGE_SIZE
16902 RESERVE_BRK(pagetables, INIT_MAP_SIZE)
16903
16904 /*
16905+ * Real beginning of normal "text" segment
16906+ */
16907+ENTRY(stext)
16908+ENTRY(_stext)
16909+
16910+/*
16911 * 32-bit kernel entrypoint; only used by the boot CPU. On entry,
16912 * %esi points to the real-mode code as a 32-bit pointer.
16913 * CS and DS must be 4 GB flat segments, but we don't depend on
16914@@ -85,6 +93,13 @@ RESERVE_BRK(pagetables, INIT_MAP_SIZE)
16915 * can.
16916 */
16917 __HEAD
16918+
16919+#ifdef CONFIG_PAX_KERNEXEC
16920+ jmp startup_32
16921+/* PaX: fill first page in .text with int3 to catch NULL derefs in kernel mode */
16922+.fill PAGE_SIZE-5,1,0xcc
16923+#endif
16924+
16925 ENTRY(startup_32)
16926 movl pa(stack_start),%ecx
16927
16928@@ -106,6 +121,59 @@ ENTRY(startup_32)
16929 2:
16930 leal -__PAGE_OFFSET(%ecx),%esp
16931
16932+#ifdef CONFIG_SMP
16933+ movl $pa(cpu_gdt_table),%edi
16934+ movl $__per_cpu_load,%eax
16935+ movw %ax,GDT_ENTRY_PERCPU * 8 + 2(%edi)
16936+ rorl $16,%eax
16937+ movb %al,GDT_ENTRY_PERCPU * 8 + 4(%edi)
16938+ movb %ah,GDT_ENTRY_PERCPU * 8 + 7(%edi)
16939+ movl $__per_cpu_end - 1,%eax
16940+ subl $__per_cpu_start,%eax
16941+ movw %ax,GDT_ENTRY_PERCPU * 8 + 0(%edi)
16942+#endif
16943+
16944+#ifdef CONFIG_PAX_MEMORY_UDEREF
16945+ movl $NR_CPUS,%ecx
16946+ movl $pa(cpu_gdt_table),%edi
16947+1:
16948+ movl $((((__PAGE_OFFSET-1) & 0xf0000000) >> 12) | 0x00c09700),GDT_ENTRY_KERNEL_DS * 8 + 4(%edi)
16949+ movl $((((__PAGE_OFFSET-1) & 0xf0000000) >> 12) | 0x00c0fb00),GDT_ENTRY_DEFAULT_USER_CS * 8 + 4(%edi)
16950+ movl $((((__PAGE_OFFSET-1) & 0xf0000000) >> 12) | 0x00c0f300),GDT_ENTRY_DEFAULT_USER_DS * 8 + 4(%edi)
16951+ addl $PAGE_SIZE_asm,%edi
16952+ loop 1b
16953+#endif
16954+
16955+#ifdef CONFIG_PAX_KERNEXEC
16956+ movl $pa(boot_gdt),%edi
16957+ movl $__LOAD_PHYSICAL_ADDR,%eax
16958+ movw %ax,GDT_ENTRY_BOOT_CS * 8 + 2(%edi)
16959+ rorl $16,%eax
16960+ movb %al,GDT_ENTRY_BOOT_CS * 8 + 4(%edi)
16961+ movb %ah,GDT_ENTRY_BOOT_CS * 8 + 7(%edi)
16962+ rorl $16,%eax
16963+
16964+ ljmp $(__BOOT_CS),$1f
16965+1:
16966+
16967+ movl $NR_CPUS,%ecx
16968+ movl $pa(cpu_gdt_table),%edi
16969+ addl $__PAGE_OFFSET,%eax
16970+1:
16971+ movb $0xc0,GDT_ENTRY_KERNEL_CS * 8 + 6(%edi)
16972+ movb $0xc0,GDT_ENTRY_KERNEXEC_KERNEL_CS * 8 + 6(%edi)
16973+ movw %ax,GDT_ENTRY_KERNEL_CS * 8 + 2(%edi)
16974+ movw %ax,GDT_ENTRY_KERNEXEC_KERNEL_CS * 8 + 2(%edi)
16975+ rorl $16,%eax
16976+ movb %al,GDT_ENTRY_KERNEL_CS * 8 + 4(%edi)
16977+ movb %al,GDT_ENTRY_KERNEXEC_KERNEL_CS * 8 + 4(%edi)
16978+ movb %ah,GDT_ENTRY_KERNEL_CS * 8 + 7(%edi)
16979+ movb %ah,GDT_ENTRY_KERNEXEC_KERNEL_CS * 8 + 7(%edi)
16980+ rorl $16,%eax
16981+ addl $PAGE_SIZE_asm,%edi
16982+ loop 1b
16983+#endif
16984+
16985 /*
16986 * Clear BSS first so that there are no surprises...
16987 */
16988@@ -196,8 +264,11 @@ ENTRY(startup_32)
16989 movl %eax, pa(max_pfn_mapped)
16990
16991 /* Do early initialization of the fixmap area */
16992- movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,%eax
16993- movl %eax,pa(initial_pg_pmd+0x1000*KPMDS-8)
16994+#ifdef CONFIG_COMPAT_VDSO
16995+ movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR+_PAGE_USER,pa(initial_pg_pmd+0x1000*KPMDS-8)
16996+#else
16997+ movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,pa(initial_pg_pmd+0x1000*KPMDS-8)
16998+#endif
16999 #else /* Not PAE */
17000
17001 page_pde_offset = (__PAGE_OFFSET >> 20);
17002@@ -227,8 +298,11 @@ page_pde_offset = (__PAGE_OFFSET >> 20);
17003 movl %eax, pa(max_pfn_mapped)
17004
17005 /* Do early initialization of the fixmap area */
17006- movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,%eax
17007- movl %eax,pa(initial_page_table+0xffc)
17008+#ifdef CONFIG_COMPAT_VDSO
17009+ movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR+_PAGE_USER,pa(initial_page_table+0xffc)
17010+#else
17011+ movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,pa(initial_page_table+0xffc)
17012+#endif
17013 #endif
17014
17015 #ifdef CONFIG_PARAVIRT
17016@@ -242,9 +316,7 @@ page_pde_offset = (__PAGE_OFFSET >> 20);
17017 cmpl $num_subarch_entries, %eax
17018 jae bad_subarch
17019
17020- movl pa(subarch_entries)(,%eax,4), %eax
17021- subl $__PAGE_OFFSET, %eax
17022- jmp *%eax
17023+ jmp *pa(subarch_entries)(,%eax,4)
17024
17025 bad_subarch:
17026 WEAK(lguest_entry)
17027@@ -256,10 +328,10 @@ WEAK(xen_entry)
17028 __INITDATA
17029
17030 subarch_entries:
17031- .long default_entry /* normal x86/PC */
17032- .long lguest_entry /* lguest hypervisor */
17033- .long xen_entry /* Xen hypervisor */
17034- .long default_entry /* Moorestown MID */
17035+ .long ta(default_entry) /* normal x86/PC */
17036+ .long ta(lguest_entry) /* lguest hypervisor */
17037+ .long ta(xen_entry) /* Xen hypervisor */
17038+ .long ta(default_entry) /* Moorestown MID */
17039 num_subarch_entries = (. - subarch_entries) / 4
17040 .previous
17041 #else
17042@@ -310,6 +382,7 @@ default_entry:
17043 orl %edx,%eax
17044 movl %eax,%cr4
17045
17046+#ifdef CONFIG_X86_PAE
17047 testb $X86_CR4_PAE, %al # check if PAE is enabled
17048 jz 6f
17049
17050@@ -338,6 +411,9 @@ default_entry:
17051 /* Make changes effective */
17052 wrmsr
17053
17054+ btsl $_PAGE_BIT_NX-32,pa(__supported_pte_mask+4)
17055+#endif
17056+
17057 6:
17058
17059 /*
17060@@ -436,14 +512,20 @@ is386: movl $2,%ecx # set MP
17061 1: movl $(__KERNEL_DS),%eax # reload all the segment registers
17062 movl %eax,%ss # after changing gdt.
17063
17064- movl $(__USER_DS),%eax # DS/ES contains default USER segment
17065+# movl $(__KERNEL_DS),%eax # DS/ES contains default KERNEL segment
17066 movl %eax,%ds
17067 movl %eax,%es
17068
17069 movl $(__KERNEL_PERCPU), %eax
17070 movl %eax,%fs # set this cpu's percpu
17071
17072+#ifdef CONFIG_CC_STACKPROTECTOR
17073 movl $(__KERNEL_STACK_CANARY),%eax
17074+#elif defined(CONFIG_PAX_MEMORY_UDEREF)
17075+ movl $(__USER_DS),%eax
17076+#else
17077+ xorl %eax,%eax
17078+#endif
17079 movl %eax,%gs
17080
17081 xorl %eax,%eax # Clear LDT
17082@@ -520,8 +602,11 @@ setup_once:
17083 * relocation. Manually set base address in stack canary
17084 * segment descriptor.
17085 */
17086- movl $gdt_page,%eax
17087+ movl $cpu_gdt_table,%eax
17088 movl $stack_canary,%ecx
17089+#ifdef CONFIG_SMP
17090+ addl $__per_cpu_load,%ecx
17091+#endif
17092 movw %cx, 8 * GDT_ENTRY_STACK_CANARY + 2(%eax)
17093 shrl $16, %ecx
17094 movb %cl, 8 * GDT_ENTRY_STACK_CANARY + 4(%eax)
17095@@ -552,7 +637,7 @@ ENDPROC(early_idt_handlers)
17096 /* This is global to keep gas from relaxing the jumps */
17097 ENTRY(early_idt_handler)
17098 cld
17099- cmpl $2,%ss:early_recursion_flag
17100+ cmpl $1,%ss:early_recursion_flag
17101 je hlt_loop
17102 incl %ss:early_recursion_flag
17103
17104@@ -590,8 +675,8 @@ ENTRY(early_idt_handler)
17105 pushl (20+6*4)(%esp) /* trapno */
17106 pushl $fault_msg
17107 call printk
17108-#endif
17109 call dump_stack
17110+#endif
17111 hlt_loop:
17112 hlt
17113 jmp hlt_loop
17114@@ -610,8 +695,11 @@ ENDPROC(early_idt_handler)
17115 /* This is the default interrupt "handler" :-) */
17116 ALIGN
17117 ignore_int:
17118- cld
17119 #ifdef CONFIG_PRINTK
17120+ cmpl $2,%ss:early_recursion_flag
17121+ je hlt_loop
17122+ incl %ss:early_recursion_flag
17123+ cld
17124 pushl %eax
17125 pushl %ecx
17126 pushl %edx
17127@@ -620,9 +708,6 @@ ignore_int:
17128 movl $(__KERNEL_DS),%eax
17129 movl %eax,%ds
17130 movl %eax,%es
17131- cmpl $2,early_recursion_flag
17132- je hlt_loop
17133- incl early_recursion_flag
17134 pushl 16(%esp)
17135 pushl 24(%esp)
17136 pushl 32(%esp)
17137@@ -656,29 +741,43 @@ ENTRY(setup_once_ref)
17138 /*
17139 * BSS section
17140 */
17141-__PAGE_ALIGNED_BSS
17142- .align PAGE_SIZE
17143 #ifdef CONFIG_X86_PAE
17144+.section .initial_pg_pmd,"a",@progbits
17145 initial_pg_pmd:
17146 .fill 1024*KPMDS,4,0
17147 #else
17148+.section .initial_page_table,"a",@progbits
17149 ENTRY(initial_page_table)
17150 .fill 1024,4,0
17151 #endif
17152+.section .initial_pg_fixmap,"a",@progbits
17153 initial_pg_fixmap:
17154 .fill 1024,4,0
17155+.section .empty_zero_page,"a",@progbits
17156 ENTRY(empty_zero_page)
17157 .fill 4096,1,0
17158+.section .swapper_pg_dir,"a",@progbits
17159 ENTRY(swapper_pg_dir)
17160+#ifdef CONFIG_X86_PAE
17161+ .fill 4,8,0
17162+#else
17163 .fill 1024,4,0
17164+#endif
17165+
17166+/*
17167+ * The IDT has to be page-aligned to simplify the Pentium
17168+ * F0 0F bug workaround.. We have a special link segment
17169+ * for this.
17170+ */
17171+.section .idt,"a",@progbits
17172+ENTRY(idt_table)
17173+ .fill 256,8,0
17174
17175 /*
17176 * This starts the data section.
17177 */
17178 #ifdef CONFIG_X86_PAE
17179-__PAGE_ALIGNED_DATA
17180- /* Page-aligned for the benefit of paravirt? */
17181- .align PAGE_SIZE
17182+.section .initial_page_table,"a",@progbits
17183 ENTRY(initial_page_table)
17184 .long pa(initial_pg_pmd+PGD_IDENT_ATTR),0 /* low identity map */
17185 # if KPMDS == 3
17186@@ -697,12 +796,20 @@ ENTRY(initial_page_table)
17187 # error "Kernel PMDs should be 1, 2 or 3"
17188 # endif
17189 .align PAGE_SIZE /* needs to be page-sized too */
17190+
17191+#ifdef CONFIG_PAX_PER_CPU_PGD
17192+ENTRY(cpu_pgd)
17193+ .rept NR_CPUS
17194+ .fill 4,8,0
17195+ .endr
17196+#endif
17197+
17198 #endif
17199
17200 .data
17201 .balign 4
17202 ENTRY(stack_start)
17203- .long init_thread_union+THREAD_SIZE
17204+ .long init_thread_union+THREAD_SIZE-8
17205
17206 __INITRODATA
17207 int_msg:
17208@@ -730,7 +837,7 @@ fault_msg:
17209 * segment size, and 32-bit linear address value:
17210 */
17211
17212- .data
17213+.section .rodata,"a",@progbits
17214 .globl boot_gdt_descr
17215 .globl idt_descr
17216
17217@@ -739,7 +846,7 @@ fault_msg:
17218 .word 0 # 32 bit align gdt_desc.address
17219 boot_gdt_descr:
17220 .word __BOOT_DS+7
17221- .long boot_gdt - __PAGE_OFFSET
17222+ .long pa(boot_gdt)
17223
17224 .word 0 # 32-bit align idt_desc.address
17225 idt_descr:
17226@@ -750,7 +857,7 @@ idt_descr:
17227 .word 0 # 32 bit align gdt_desc.address
17228 ENTRY(early_gdt_descr)
17229 .word GDT_ENTRIES*8-1
17230- .long gdt_page /* Overwritten for secondary CPUs */
17231+ .long cpu_gdt_table /* Overwritten for secondary CPUs */
17232
17233 /*
17234 * The boot_gdt must mirror the equivalent in setup.S and is
17235@@ -759,5 +866,65 @@ ENTRY(early_gdt_descr)
17236 .align L1_CACHE_BYTES
17237 ENTRY(boot_gdt)
17238 .fill GDT_ENTRY_BOOT_CS,8,0
17239- .quad 0x00cf9a000000ffff /* kernel 4GB code at 0x00000000 */
17240- .quad 0x00cf92000000ffff /* kernel 4GB data at 0x00000000 */
17241+ .quad 0x00cf9b000000ffff /* kernel 4GB code at 0x00000000 */
17242+ .quad 0x00cf93000000ffff /* kernel 4GB data at 0x00000000 */
17243+
17244+ .align PAGE_SIZE_asm
17245+ENTRY(cpu_gdt_table)
17246+ .rept NR_CPUS
17247+ .quad 0x0000000000000000 /* NULL descriptor */
17248+ .quad 0x0000000000000000 /* 0x0b reserved */
17249+ .quad 0x0000000000000000 /* 0x13 reserved */
17250+ .quad 0x0000000000000000 /* 0x1b reserved */
17251+
17252+#ifdef CONFIG_PAX_KERNEXEC
17253+ .quad 0x00cf9b000000ffff /* 0x20 alternate kernel 4GB code at 0x00000000 */
17254+#else
17255+ .quad 0x0000000000000000 /* 0x20 unused */
17256+#endif
17257+
17258+ .quad 0x0000000000000000 /* 0x28 unused */
17259+ .quad 0x0000000000000000 /* 0x33 TLS entry 1 */
17260+ .quad 0x0000000000000000 /* 0x3b TLS entry 2 */
17261+ .quad 0x0000000000000000 /* 0x43 TLS entry 3 */
17262+ .quad 0x0000000000000000 /* 0x4b reserved */
17263+ .quad 0x0000000000000000 /* 0x53 reserved */
17264+ .quad 0x0000000000000000 /* 0x5b reserved */
17265+
17266+ .quad 0x00cf9b000000ffff /* 0x60 kernel 4GB code at 0x00000000 */
17267+ .quad 0x00cf93000000ffff /* 0x68 kernel 4GB data at 0x00000000 */
17268+ .quad 0x00cffb000000ffff /* 0x73 user 4GB code at 0x00000000 */
17269+ .quad 0x00cff3000000ffff /* 0x7b user 4GB data at 0x00000000 */
17270+
17271+ .quad 0x0000000000000000 /* 0x80 TSS descriptor */
17272+ .quad 0x0000000000000000 /* 0x88 LDT descriptor */
17273+
17274+ /*
17275+ * Segments used for calling PnP BIOS have byte granularity.
17276+ * The code segments and data segments have fixed 64k limits,
17277+ * the transfer segment sizes are set at run time.
17278+ */
17279+ .quad 0x00409b000000ffff /* 0x90 32-bit code */
17280+ .quad 0x00009b000000ffff /* 0x98 16-bit code */
17281+ .quad 0x000093000000ffff /* 0xa0 16-bit data */
17282+ .quad 0x0000930000000000 /* 0xa8 16-bit data */
17283+ .quad 0x0000930000000000 /* 0xb0 16-bit data */
17284+
17285+ /*
17286+ * The APM segments have byte granularity and their bases
17287+ * are set at run time. All have 64k limits.
17288+ */
17289+ .quad 0x00409b000000ffff /* 0xb8 APM CS code */
17290+ .quad 0x00009b000000ffff /* 0xc0 APM CS 16 code (16 bit) */
17291+ .quad 0x004093000000ffff /* 0xc8 APM DS data */
17292+
17293+ .quad 0x00c0930000000000 /* 0xd0 - ESPFIX SS */
17294+ .quad 0x0040930000000000 /* 0xd8 - PERCPU */
17295+ .quad 0x0040910000000017 /* 0xe0 - STACK_CANARY */
17296+ .quad 0x0000000000000000 /* 0xe8 - PCIBIOS_CS */
17297+ .quad 0x0000000000000000 /* 0xf0 - PCIBIOS_DS */
17298+ .quad 0x0000000000000000 /* 0xf8 - GDT entry 31: double-fault TSS */
17299+
17300+ /* Be sure this is zeroed to avoid false validations in Xen */
17301+ .fill PAGE_SIZE_asm - GDT_SIZE,1,0
17302+ .endr
17303diff --git a/arch/x86/kernel/head_64.S b/arch/x86/kernel/head_64.S
17304index 94bf9cc..400455a 100644
17305--- a/arch/x86/kernel/head_64.S
17306+++ b/arch/x86/kernel/head_64.S
17307@@ -20,6 +20,8 @@
17308 #include <asm/processor-flags.h>
17309 #include <asm/percpu.h>
17310 #include <asm/nops.h>
17311+#include <asm/cpufeature.h>
17312+#include <asm/alternative-asm.h>
17313
17314 #ifdef CONFIG_PARAVIRT
17315 #include <asm/asm-offsets.h>
17316@@ -41,6 +43,12 @@ L4_PAGE_OFFSET = pgd_index(__PAGE_OFFSET)
17317 L3_PAGE_OFFSET = pud_index(__PAGE_OFFSET)
17318 L4_START_KERNEL = pgd_index(__START_KERNEL_map)
17319 L3_START_KERNEL = pud_index(__START_KERNEL_map)
17320+L4_VMALLOC_START = pgd_index(VMALLOC_START)
17321+L3_VMALLOC_START = pud_index(VMALLOC_START)
17322+L4_VMALLOC_END = pgd_index(VMALLOC_END)
17323+L3_VMALLOC_END = pud_index(VMALLOC_END)
17324+L4_VMEMMAP_START = pgd_index(VMEMMAP_START)
17325+L3_VMEMMAP_START = pud_index(VMEMMAP_START)
17326
17327 .text
17328 __HEAD
17329@@ -88,35 +96,23 @@ startup_64:
17330 */
17331 addq %rbp, init_level4_pgt + 0(%rip)
17332 addq %rbp, init_level4_pgt + (L4_PAGE_OFFSET*8)(%rip)
17333+ addq %rbp, init_level4_pgt + (L4_VMALLOC_START*8)(%rip)
17334+ addq %rbp, init_level4_pgt + (L4_VMALLOC_END*8)(%rip)
17335+ addq %rbp, init_level4_pgt + (L4_VMEMMAP_START*8)(%rip)
17336 addq %rbp, init_level4_pgt + (L4_START_KERNEL*8)(%rip)
17337
17338 addq %rbp, level3_ident_pgt + 0(%rip)
17339+#ifndef CONFIG_XEN
17340+ addq %rbp, level3_ident_pgt + 8(%rip)
17341+#endif
17342
17343- addq %rbp, level3_kernel_pgt + (510*8)(%rip)
17344- addq %rbp, level3_kernel_pgt + (511*8)(%rip)
17345+ addq %rbp, level3_vmemmap_pgt + (L3_VMEMMAP_START*8)(%rip)
17346+
17347+ addq %rbp, level3_kernel_pgt + (L3_START_KERNEL*8)(%rip)
17348+ addq %rbp, level3_kernel_pgt + (L3_START_KERNEL*8+8)(%rip)
17349
17350 addq %rbp, level2_fixmap_pgt + (506*8)(%rip)
17351-
17352- /* Add an Identity mapping if I am above 1G */
17353- leaq _text(%rip), %rdi
17354- andq $PMD_PAGE_MASK, %rdi
17355-
17356- movq %rdi, %rax
17357- shrq $PUD_SHIFT, %rax
17358- andq $(PTRS_PER_PUD - 1), %rax
17359- jz ident_complete
17360-
17361- leaq (level2_spare_pgt - __START_KERNEL_map + _KERNPG_TABLE)(%rbp), %rdx
17362- leaq level3_ident_pgt(%rip), %rbx
17363- movq %rdx, 0(%rbx, %rax, 8)
17364-
17365- movq %rdi, %rax
17366- shrq $PMD_SHIFT, %rax
17367- andq $(PTRS_PER_PMD - 1), %rax
17368- leaq __PAGE_KERNEL_IDENT_LARGE_EXEC(%rdi), %rdx
17369- leaq level2_spare_pgt(%rip), %rbx
17370- movq %rdx, 0(%rbx, %rax, 8)
17371-ident_complete:
17372+ addq %rbp, level2_fixmap_pgt + (507*8)(%rip)
17373
17374 /*
17375 * Fixup the kernel text+data virtual addresses. Note that
17376@@ -159,8 +155,8 @@ ENTRY(secondary_startup_64)
17377 * after the boot processor executes this code.
17378 */
17379
17380- /* Enable PAE mode and PGE */
17381- movl $(X86_CR4_PAE | X86_CR4_PGE), %eax
17382+ /* Enable PAE mode and PSE/PGE */
17383+ movl $(X86_CR4_PSE | X86_CR4_PAE | X86_CR4_PGE), %eax
17384 movq %rax, %cr4
17385
17386 /* Setup early boot stage 4 level pagetables. */
17387@@ -182,9 +178,17 @@ ENTRY(secondary_startup_64)
17388 movl $MSR_EFER, %ecx
17389 rdmsr
17390 btsl $_EFER_SCE, %eax /* Enable System Call */
17391- btl $20,%edi /* No Execute supported? */
17392+ btl $(X86_FEATURE_NX & 31),%edi /* No Execute supported? */
17393 jnc 1f
17394 btsl $_EFER_NX, %eax
17395+ leaq init_level4_pgt(%rip), %rdi
17396+#ifndef CONFIG_EFI
17397+ btsq $_PAGE_BIT_NX, 8*L4_PAGE_OFFSET(%rdi)
17398+#endif
17399+ btsq $_PAGE_BIT_NX, 8*L4_VMALLOC_START(%rdi)
17400+ btsq $_PAGE_BIT_NX, 8*L4_VMALLOC_END(%rdi)
17401+ btsq $_PAGE_BIT_NX, 8*L4_VMEMMAP_START(%rdi)
17402+ btsq $_PAGE_BIT_NX, __supported_pte_mask(%rip)
17403 1: wrmsr /* Make changes effective */
17404
17405 /* Setup cr0 */
17406@@ -246,6 +250,7 @@ ENTRY(secondary_startup_64)
17407 * jump. In addition we need to ensure %cs is set so we make this
17408 * a far return.
17409 */
17410+ pax_set_fptr_mask
17411 movq initial_code(%rip),%rax
17412 pushq $0 # fake return address to stop unwinder
17413 pushq $__KERNEL_CS # set correct cs
17414@@ -268,7 +273,7 @@ ENTRY(secondary_startup_64)
17415 bad_address:
17416 jmp bad_address
17417
17418- .section ".init.text","ax"
17419+ __INIT
17420 .globl early_idt_handlers
17421 early_idt_handlers:
17422 # 104(%rsp) %rflags
17423@@ -347,11 +352,15 @@ ENTRY(early_idt_handler)
17424 addq $16,%rsp # drop vector number and error code
17425 decl early_recursion_flag(%rip)
17426 INTERRUPT_RETURN
17427+ .previous
17428
17429+ __INITDATA
17430 .balign 4
17431 early_recursion_flag:
17432 .long 0
17433+ .previous
17434
17435+ .section .rodata,"a",@progbits
17436 #ifdef CONFIG_EARLY_PRINTK
17437 early_idt_msg:
17438 .asciz "PANIC: early exception %02lx rip %lx:%lx error %lx cr2 %lx\n"
17439@@ -360,6 +369,7 @@ early_idt_ripmsg:
17440 #endif /* CONFIG_EARLY_PRINTK */
17441 .previous
17442
17443+ .section .rodata,"a",@progbits
17444 #define NEXT_PAGE(name) \
17445 .balign PAGE_SIZE; \
17446 ENTRY(name)
17447@@ -372,7 +382,6 @@ ENTRY(name)
17448 i = i + 1 ; \
17449 .endr
17450
17451- .data
17452 /*
17453 * This default setting generates an ident mapping at address 0x100000
17454 * and a mapping for the kernel that precisely maps virtual address
17455@@ -383,13 +392,41 @@ NEXT_PAGE(init_level4_pgt)
17456 .quad level3_ident_pgt - __START_KERNEL_map + _KERNPG_TABLE
17457 .org init_level4_pgt + L4_PAGE_OFFSET*8, 0
17458 .quad level3_ident_pgt - __START_KERNEL_map + _KERNPG_TABLE
17459+ .org init_level4_pgt + L4_VMALLOC_START*8, 0
17460+ .quad level3_vmalloc_start_pgt - __START_KERNEL_map + _KERNPG_TABLE
17461+ .org init_level4_pgt + L4_VMALLOC_END*8, 0
17462+ .quad level3_vmalloc_end_pgt - __START_KERNEL_map + _KERNPG_TABLE
17463+ .org init_level4_pgt + L4_VMEMMAP_START*8, 0
17464+ .quad level3_vmemmap_pgt - __START_KERNEL_map + _KERNPG_TABLE
17465 .org init_level4_pgt + L4_START_KERNEL*8, 0
17466 /* (2^48-(2*1024*1024*1024))/(2^39) = 511 */
17467 .quad level3_kernel_pgt - __START_KERNEL_map + _PAGE_TABLE
17468
17469+#ifdef CONFIG_PAX_PER_CPU_PGD
17470+NEXT_PAGE(cpu_pgd)
17471+ .rept NR_CPUS
17472+ .fill 512,8,0
17473+ .endr
17474+#endif
17475+
17476 NEXT_PAGE(level3_ident_pgt)
17477 .quad level2_ident_pgt - __START_KERNEL_map + _KERNPG_TABLE
17478+#ifdef CONFIG_XEN
17479 .fill 511,8,0
17480+#else
17481+ .quad level2_ident_pgt + PAGE_SIZE - __START_KERNEL_map + _KERNPG_TABLE
17482+ .fill 510,8,0
17483+#endif
17484+
17485+NEXT_PAGE(level3_vmalloc_start_pgt)
17486+ .fill 512,8,0
17487+
17488+NEXT_PAGE(level3_vmalloc_end_pgt)
17489+ .fill 512,8,0
17490+
17491+NEXT_PAGE(level3_vmemmap_pgt)
17492+ .fill L3_VMEMMAP_START,8,0
17493+ .quad level2_vmemmap_pgt - __START_KERNEL_map + _KERNPG_TABLE
17494
17495 NEXT_PAGE(level3_kernel_pgt)
17496 .fill L3_START_KERNEL,8,0
17497@@ -397,20 +434,23 @@ NEXT_PAGE(level3_kernel_pgt)
17498 .quad level2_kernel_pgt - __START_KERNEL_map + _KERNPG_TABLE
17499 .quad level2_fixmap_pgt - __START_KERNEL_map + _PAGE_TABLE
17500
17501+NEXT_PAGE(level2_vmemmap_pgt)
17502+ .fill 512,8,0
17503+
17504 NEXT_PAGE(level2_fixmap_pgt)
17505- .fill 506,8,0
17506- .quad level1_fixmap_pgt - __START_KERNEL_map + _PAGE_TABLE
17507- /* 8MB reserved for vsyscalls + a 2MB hole = 4 + 1 entries */
17508- .fill 5,8,0
17509+ .fill 507,8,0
17510+ .quad level1_vsyscall_pgt - __START_KERNEL_map + _PAGE_TABLE
17511+ /* 6MB reserved for vsyscalls + a 2MB hole = 3 + 1 entries */
17512+ .fill 4,8,0
17513
17514-NEXT_PAGE(level1_fixmap_pgt)
17515+NEXT_PAGE(level1_vsyscall_pgt)
17516 .fill 512,8,0
17517
17518-NEXT_PAGE(level2_ident_pgt)
17519- /* Since I easily can, map the first 1G.
17520+ /* Since I easily can, map the first 2G.
17521 * Don't set NX because code runs from these pages.
17522 */
17523- PMDS(0, __PAGE_KERNEL_IDENT_LARGE_EXEC, PTRS_PER_PMD)
17524+NEXT_PAGE(level2_ident_pgt)
17525+ PMDS(0, __PAGE_KERNEL_IDENT_LARGE_EXEC, 2*PTRS_PER_PMD)
17526
17527 NEXT_PAGE(level2_kernel_pgt)
17528 /*
17529@@ -423,37 +463,59 @@ NEXT_PAGE(level2_kernel_pgt)
17530 * If you want to increase this then increase MODULES_VADDR
17531 * too.)
17532 */
17533- PMDS(0, __PAGE_KERNEL_LARGE_EXEC,
17534- KERNEL_IMAGE_SIZE/PMD_SIZE)
17535-
17536-NEXT_PAGE(level2_spare_pgt)
17537- .fill 512, 8, 0
17538+ PMDS(0, __PAGE_KERNEL_LARGE_EXEC, KERNEL_IMAGE_SIZE/PMD_SIZE)
17539
17540 #undef PMDS
17541 #undef NEXT_PAGE
17542
17543- .data
17544+ .align PAGE_SIZE
17545+ENTRY(cpu_gdt_table)
17546+ .rept NR_CPUS
17547+ .quad 0x0000000000000000 /* NULL descriptor */
17548+ .quad 0x00cf9b000000ffff /* __KERNEL32_CS */
17549+ .quad 0x00af9b000000ffff /* __KERNEL_CS */
17550+ .quad 0x00cf93000000ffff /* __KERNEL_DS */
17551+ .quad 0x00cffb000000ffff /* __USER32_CS */
17552+ .quad 0x00cff3000000ffff /* __USER_DS, __USER32_DS */
17553+ .quad 0x00affb000000ffff /* __USER_CS */
17554+
17555+#ifdef CONFIG_PAX_KERNEXEC
17556+ .quad 0x00af9b000000ffff /* __KERNEXEC_KERNEL_CS */
17557+#else
17558+ .quad 0x0 /* unused */
17559+#endif
17560+
17561+ .quad 0,0 /* TSS */
17562+ .quad 0,0 /* LDT */
17563+ .quad 0,0,0 /* three TLS descriptors */
17564+ .quad 0x0000f40000000000 /* node/CPU stored in limit */
17565+ /* asm/segment.h:GDT_ENTRIES must match this */
17566+
17567+ /* zero the remaining page */
17568+ .fill PAGE_SIZE / 8 - GDT_ENTRIES,8,0
17569+ .endr
17570+
17571 .align 16
17572 .globl early_gdt_descr
17573 early_gdt_descr:
17574 .word GDT_ENTRIES*8-1
17575 early_gdt_descr_base:
17576- .quad INIT_PER_CPU_VAR(gdt_page)
17577+ .quad cpu_gdt_table
17578
17579 ENTRY(phys_base)
17580 /* This must match the first entry in level2_kernel_pgt */
17581 .quad 0x0000000000000000
17582
17583 #include "../../x86/xen/xen-head.S"
17584-
17585- .section .bss, "aw", @nobits
17586+
17587+ .section .rodata,"a",@progbits
17588 .align L1_CACHE_BYTES
17589 ENTRY(idt_table)
17590- .skip IDT_ENTRIES * 16
17591+ .fill 512,8,0
17592
17593 .align L1_CACHE_BYTES
17594 ENTRY(nmi_idt_table)
17595- .skip IDT_ENTRIES * 16
17596+ .fill 512,8,0
17597
17598 __PAGE_ALIGNED_BSS
17599 .align PAGE_SIZE
17600diff --git a/arch/x86/kernel/i386_ksyms_32.c b/arch/x86/kernel/i386_ksyms_32.c
17601index 9c3bd4a..e1d9b35 100644
17602--- a/arch/x86/kernel/i386_ksyms_32.c
17603+++ b/arch/x86/kernel/i386_ksyms_32.c
17604@@ -20,8 +20,12 @@ extern void cmpxchg8b_emu(void);
17605 EXPORT_SYMBOL(cmpxchg8b_emu);
17606 #endif
17607
17608+EXPORT_SYMBOL_GPL(cpu_gdt_table);
17609+
17610 /* Networking helper routines. */
17611 EXPORT_SYMBOL(csum_partial_copy_generic);
17612+EXPORT_SYMBOL(csum_partial_copy_generic_to_user);
17613+EXPORT_SYMBOL(csum_partial_copy_generic_from_user);
17614
17615 EXPORT_SYMBOL(__get_user_1);
17616 EXPORT_SYMBOL(__get_user_2);
17617@@ -36,3 +40,7 @@ EXPORT_SYMBOL(strstr);
17618
17619 EXPORT_SYMBOL(csum_partial);
17620 EXPORT_SYMBOL(empty_zero_page);
17621+
17622+#ifdef CONFIG_PAX_KERNEXEC
17623+EXPORT_SYMBOL(__LOAD_PHYSICAL_ADDR);
17624+#endif
17625diff --git a/arch/x86/kernel/i387.c b/arch/x86/kernel/i387.c
17626index f250431..54097e7 100644
17627--- a/arch/x86/kernel/i387.c
17628+++ b/arch/x86/kernel/i387.c
17629@@ -59,7 +59,7 @@ static inline bool interrupted_kernel_fpu_idle(void)
17630 static inline bool interrupted_user_mode(void)
17631 {
17632 struct pt_regs *regs = get_irq_regs();
17633- return regs && user_mode_vm(regs);
17634+ return regs && user_mode(regs);
17635 }
17636
17637 /*
17638diff --git a/arch/x86/kernel/i8259.c b/arch/x86/kernel/i8259.c
17639index 36d1853..bf25736 100644
17640--- a/arch/x86/kernel/i8259.c
17641+++ b/arch/x86/kernel/i8259.c
17642@@ -209,7 +209,7 @@ spurious_8259A_irq:
17643 "spurious 8259A interrupt: IRQ%d.\n", irq);
17644 spurious_irq_mask |= irqmask;
17645 }
17646- atomic_inc(&irq_err_count);
17647+ atomic_inc_unchecked(&irq_err_count);
17648 /*
17649 * Theoretically we do not have to handle this IRQ,
17650 * but in Linux this does not cause problems and is
17651diff --git a/arch/x86/kernel/ioport.c b/arch/x86/kernel/ioport.c
17652index 8c96897..be66bfa 100644
17653--- a/arch/x86/kernel/ioport.c
17654+++ b/arch/x86/kernel/ioport.c
17655@@ -6,6 +6,7 @@
17656 #include <linux/sched.h>
17657 #include <linux/kernel.h>
17658 #include <linux/capability.h>
17659+#include <linux/security.h>
17660 #include <linux/errno.h>
17661 #include <linux/types.h>
17662 #include <linux/ioport.h>
17663@@ -28,6 +29,12 @@ asmlinkage long sys_ioperm(unsigned long from, unsigned long num, int turn_on)
17664
17665 if ((from + num <= from) || (from + num > IO_BITMAP_BITS))
17666 return -EINVAL;
17667+#ifdef CONFIG_GRKERNSEC_IO
17668+ if (turn_on && grsec_disable_privio) {
17669+ gr_handle_ioperm();
17670+ return -EPERM;
17671+ }
17672+#endif
17673 if (turn_on && !capable(CAP_SYS_RAWIO))
17674 return -EPERM;
17675
17676@@ -54,7 +61,7 @@ asmlinkage long sys_ioperm(unsigned long from, unsigned long num, int turn_on)
17677 * because the ->io_bitmap_max value must match the bitmap
17678 * contents:
17679 */
17680- tss = &per_cpu(init_tss, get_cpu());
17681+ tss = init_tss + get_cpu();
17682
17683 if (turn_on)
17684 bitmap_clear(t->io_bitmap_ptr, from, num);
17685@@ -102,6 +109,12 @@ long sys_iopl(unsigned int level, struct pt_regs *regs)
17686 return -EINVAL;
17687 /* Trying to gain more privileges? */
17688 if (level > old) {
17689+#ifdef CONFIG_GRKERNSEC_IO
17690+ if (grsec_disable_privio) {
17691+ gr_handle_iopl();
17692+ return -EPERM;
17693+ }
17694+#endif
17695 if (!capable(CAP_SYS_RAWIO))
17696 return -EPERM;
17697 }
17698diff --git a/arch/x86/kernel/irq.c b/arch/x86/kernel/irq.c
17699index d44f782..31ab01e 100644
17700--- a/arch/x86/kernel/irq.c
17701+++ b/arch/x86/kernel/irq.c
17702@@ -18,7 +18,7 @@
17703 #include <asm/mce.h>
17704 #include <asm/hw_irq.h>
17705
17706-atomic_t irq_err_count;
17707+atomic_unchecked_t irq_err_count;
17708
17709 /* Function pointer for generic interrupt vector handling */
17710 void (*x86_platform_ipi_callback)(void) = NULL;
17711@@ -121,9 +121,9 @@ int arch_show_interrupts(struct seq_file *p, int prec)
17712 seq_printf(p, "%10u ", per_cpu(mce_poll_count, j));
17713 seq_printf(p, " Machine check polls\n");
17714 #endif
17715- seq_printf(p, "%*s: %10u\n", prec, "ERR", atomic_read(&irq_err_count));
17716+ seq_printf(p, "%*s: %10u\n", prec, "ERR", atomic_read_unchecked(&irq_err_count));
17717 #if defined(CONFIG_X86_IO_APIC)
17718- seq_printf(p, "%*s: %10u\n", prec, "MIS", atomic_read(&irq_mis_count));
17719+ seq_printf(p, "%*s: %10u\n", prec, "MIS", atomic_read_unchecked(&irq_mis_count));
17720 #endif
17721 return 0;
17722 }
17723@@ -164,10 +164,10 @@ u64 arch_irq_stat_cpu(unsigned int cpu)
17724
17725 u64 arch_irq_stat(void)
17726 {
17727- u64 sum = atomic_read(&irq_err_count);
17728+ u64 sum = atomic_read_unchecked(&irq_err_count);
17729
17730 #ifdef CONFIG_X86_IO_APIC
17731- sum += atomic_read(&irq_mis_count);
17732+ sum += atomic_read_unchecked(&irq_mis_count);
17733 #endif
17734 return sum;
17735 }
17736diff --git a/arch/x86/kernel/irq_32.c b/arch/x86/kernel/irq_32.c
17737index 344faf8..355f60d 100644
17738--- a/arch/x86/kernel/irq_32.c
17739+++ b/arch/x86/kernel/irq_32.c
17740@@ -39,7 +39,7 @@ static int check_stack_overflow(void)
17741 __asm__ __volatile__("andl %%esp,%0" :
17742 "=r" (sp) : "0" (THREAD_SIZE - 1));
17743
17744- return sp < (sizeof(struct thread_info) + STACK_WARN);
17745+ return sp < STACK_WARN;
17746 }
17747
17748 static void print_stack_overflow(void)
17749@@ -59,8 +59,8 @@ static inline void print_stack_overflow(void) { }
17750 * per-CPU IRQ handling contexts (thread information and stack)
17751 */
17752 union irq_ctx {
17753- struct thread_info tinfo;
17754- u32 stack[THREAD_SIZE/sizeof(u32)];
17755+ unsigned long previous_esp;
17756+ u32 stack[THREAD_SIZE/sizeof(u32)];
17757 } __attribute__((aligned(THREAD_SIZE)));
17758
17759 static DEFINE_PER_CPU(union irq_ctx *, hardirq_ctx);
17760@@ -80,10 +80,9 @@ static void call_on_stack(void *func, void *stack)
17761 static inline int
17762 execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
17763 {
17764- union irq_ctx *curctx, *irqctx;
17765+ union irq_ctx *irqctx;
17766 u32 *isp, arg1, arg2;
17767
17768- curctx = (union irq_ctx *) current_thread_info();
17769 irqctx = __this_cpu_read(hardirq_ctx);
17770
17771 /*
17772@@ -92,16 +91,16 @@ execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
17773 * handler) we can't do that and just have to keep using the
17774 * current stack (which is the irq stack already after all)
17775 */
17776- if (unlikely(curctx == irqctx))
17777+ if (unlikely((void *)current_stack_pointer - (void *)irqctx < THREAD_SIZE))
17778 return 0;
17779
17780 /* build the stack frame on the IRQ stack */
17781- isp = (u32 *) ((char *)irqctx + sizeof(*irqctx));
17782- irqctx->tinfo.task = curctx->tinfo.task;
17783- irqctx->tinfo.previous_esp = current_stack_pointer;
17784+ isp = (u32 *) ((char *)irqctx + sizeof(*irqctx) - 8);
17785+ irqctx->previous_esp = current_stack_pointer;
17786
17787- /* Copy the preempt_count so that the [soft]irq checks work. */
17788- irqctx->tinfo.preempt_count = curctx->tinfo.preempt_count;
17789+#ifdef CONFIG_PAX_MEMORY_UDEREF
17790+ __set_fs(MAKE_MM_SEG(0));
17791+#endif
17792
17793 if (unlikely(overflow))
17794 call_on_stack(print_stack_overflow, isp);
17795@@ -113,6 +112,11 @@ execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
17796 : "0" (irq), "1" (desc), "2" (isp),
17797 "D" (desc->handle_irq)
17798 : "memory", "cc", "ecx");
17799+
17800+#ifdef CONFIG_PAX_MEMORY_UDEREF
17801+ __set_fs(current_thread_info()->addr_limit);
17802+#endif
17803+
17804 return 1;
17805 }
17806
17807@@ -121,29 +125,14 @@ execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
17808 */
17809 void __cpuinit irq_ctx_init(int cpu)
17810 {
17811- union irq_ctx *irqctx;
17812-
17813 if (per_cpu(hardirq_ctx, cpu))
17814 return;
17815
17816- irqctx = page_address(alloc_pages_node(cpu_to_node(cpu),
17817- THREADINFO_GFP,
17818- THREAD_SIZE_ORDER));
17819- memset(&irqctx->tinfo, 0, sizeof(struct thread_info));
17820- irqctx->tinfo.cpu = cpu;
17821- irqctx->tinfo.preempt_count = HARDIRQ_OFFSET;
17822- irqctx->tinfo.addr_limit = MAKE_MM_SEG(0);
17823-
17824- per_cpu(hardirq_ctx, cpu) = irqctx;
17825-
17826- irqctx = page_address(alloc_pages_node(cpu_to_node(cpu),
17827- THREADINFO_GFP,
17828- THREAD_SIZE_ORDER));
17829- memset(&irqctx->tinfo, 0, sizeof(struct thread_info));
17830- irqctx->tinfo.cpu = cpu;
17831- irqctx->tinfo.addr_limit = MAKE_MM_SEG(0);
17832-
17833- per_cpu(softirq_ctx, cpu) = irqctx;
17834+ per_cpu(hardirq_ctx, cpu) = page_address(alloc_pages_node(cpu_to_node(cpu), THREADINFO_GFP, THREAD_SIZE_ORDER));
17835+ per_cpu(softirq_ctx, cpu) = page_address(alloc_pages_node(cpu_to_node(cpu), THREADINFO_GFP, THREAD_SIZE_ORDER));
17836+
17837+ printk(KERN_DEBUG "CPU %u irqstacks, hard=%p soft=%p\n",
17838+ cpu, per_cpu(hardirq_ctx, cpu), per_cpu(softirq_ctx, cpu));
17839
17840 printk(KERN_DEBUG "CPU %u irqstacks, hard=%p soft=%p\n",
17841 cpu, per_cpu(hardirq_ctx, cpu), per_cpu(softirq_ctx, cpu));
17842@@ -152,7 +141,6 @@ void __cpuinit irq_ctx_init(int cpu)
17843 asmlinkage void do_softirq(void)
17844 {
17845 unsigned long flags;
17846- struct thread_info *curctx;
17847 union irq_ctx *irqctx;
17848 u32 *isp;
17849
17850@@ -162,15 +150,22 @@ asmlinkage void do_softirq(void)
17851 local_irq_save(flags);
17852
17853 if (local_softirq_pending()) {
17854- curctx = current_thread_info();
17855 irqctx = __this_cpu_read(softirq_ctx);
17856- irqctx->tinfo.task = curctx->task;
17857- irqctx->tinfo.previous_esp = current_stack_pointer;
17858+ irqctx->previous_esp = current_stack_pointer;
17859
17860 /* build the stack frame on the softirq stack */
17861- isp = (u32 *) ((char *)irqctx + sizeof(*irqctx));
17862+ isp = (u32 *) ((char *)irqctx + sizeof(*irqctx) - 8);
17863+
17864+#ifdef CONFIG_PAX_MEMORY_UDEREF
17865+ __set_fs(MAKE_MM_SEG(0));
17866+#endif
17867
17868 call_on_stack(__do_softirq, isp);
17869+
17870+#ifdef CONFIG_PAX_MEMORY_UDEREF
17871+ __set_fs(current_thread_info()->addr_limit);
17872+#endif
17873+
17874 /*
17875 * Shouldn't happen, we returned above if in_interrupt():
17876 */
17877@@ -191,7 +186,7 @@ bool handle_irq(unsigned irq, struct pt_regs *regs)
17878 if (unlikely(!desc))
17879 return false;
17880
17881- if (user_mode_vm(regs) || !execute_on_irq_stack(overflow, desc, irq)) {
17882+ if (user_mode(regs) || !execute_on_irq_stack(overflow, desc, irq)) {
17883 if (unlikely(overflow))
17884 print_stack_overflow();
17885 desc->handle_irq(irq, desc);
17886diff --git a/arch/x86/kernel/irq_64.c b/arch/x86/kernel/irq_64.c
17887index d04d3ec..ea4b374 100644
17888--- a/arch/x86/kernel/irq_64.c
17889+++ b/arch/x86/kernel/irq_64.c
17890@@ -44,7 +44,7 @@ static inline void stack_overflow_check(struct pt_regs *regs)
17891 u64 estack_top, estack_bottom;
17892 u64 curbase = (u64)task_stack_page(current);
17893
17894- if (user_mode_vm(regs))
17895+ if (user_mode(regs))
17896 return;
17897
17898 if (regs->sp >= curbase + sizeof(struct thread_info) +
17899diff --git a/arch/x86/kernel/kdebugfs.c b/arch/x86/kernel/kdebugfs.c
17900index dc1404b..bbc43e7 100644
17901--- a/arch/x86/kernel/kdebugfs.c
17902+++ b/arch/x86/kernel/kdebugfs.c
17903@@ -27,7 +27,7 @@ struct setup_data_node {
17904 u32 len;
17905 };
17906
17907-static ssize_t setup_data_read(struct file *file, char __user *user_buf,
17908+static ssize_t __size_overflow(3) setup_data_read(struct file *file, char __user *user_buf,
17909 size_t count, loff_t *ppos)
17910 {
17911 struct setup_data_node *node = file->private_data;
17912diff --git a/arch/x86/kernel/kgdb.c b/arch/x86/kernel/kgdb.c
17913index 3f61904..873cea9 100644
17914--- a/arch/x86/kernel/kgdb.c
17915+++ b/arch/x86/kernel/kgdb.c
17916@@ -127,11 +127,11 @@ char *dbg_get_reg(int regno, void *mem, struct pt_regs *regs)
17917 #ifdef CONFIG_X86_32
17918 switch (regno) {
17919 case GDB_SS:
17920- if (!user_mode_vm(regs))
17921+ if (!user_mode(regs))
17922 *(unsigned long *)mem = __KERNEL_DS;
17923 break;
17924 case GDB_SP:
17925- if (!user_mode_vm(regs))
17926+ if (!user_mode(regs))
17927 *(unsigned long *)mem = kernel_stack_pointer(regs);
17928 break;
17929 case GDB_GS:
17930@@ -476,12 +476,12 @@ int kgdb_arch_handle_exception(int e_vector, int signo, int err_code,
17931 case 'k':
17932 /* clear the trace bit */
17933 linux_regs->flags &= ~X86_EFLAGS_TF;
17934- atomic_set(&kgdb_cpu_doing_single_step, -1);
17935+ atomic_set_unchecked(&kgdb_cpu_doing_single_step, -1);
17936
17937 /* set the trace bit if we're stepping */
17938 if (remcomInBuffer[0] == 's') {
17939 linux_regs->flags |= X86_EFLAGS_TF;
17940- atomic_set(&kgdb_cpu_doing_single_step,
17941+ atomic_set_unchecked(&kgdb_cpu_doing_single_step,
17942 raw_smp_processor_id());
17943 }
17944
17945@@ -546,7 +546,7 @@ static int __kgdb_notify(struct die_args *args, unsigned long cmd)
17946
17947 switch (cmd) {
17948 case DIE_DEBUG:
17949- if (atomic_read(&kgdb_cpu_doing_single_step) != -1) {
17950+ if (atomic_read_unchecked(&kgdb_cpu_doing_single_step) != -1) {
17951 if (user_mode(regs))
17952 return single_step_cont(regs, args);
17953 break;
17954diff --git a/arch/x86/kernel/kprobes-opt.c b/arch/x86/kernel/kprobes-opt.c
17955index c5e410e..da6aaf9 100644
17956--- a/arch/x86/kernel/kprobes-opt.c
17957+++ b/arch/x86/kernel/kprobes-opt.c
17958@@ -338,7 +338,7 @@ int __kprobes arch_prepare_optimized_kprobe(struct optimized_kprobe *op)
17959 * Verify if the address gap is in 2GB range, because this uses
17960 * a relative jump.
17961 */
17962- rel = (long)op->optinsn.insn - (long)op->kp.addr + RELATIVEJUMP_SIZE;
17963+ rel = (long)op->optinsn.insn - ktla_ktva((long)op->kp.addr) + RELATIVEJUMP_SIZE;
17964 if (abs(rel) > 0x7fffffff)
17965 return -ERANGE;
17966
17967@@ -359,11 +359,11 @@ int __kprobes arch_prepare_optimized_kprobe(struct optimized_kprobe *op)
17968 synthesize_set_arg1(buf + TMPL_MOVE_IDX, (unsigned long)op);
17969
17970 /* Set probe function call */
17971- synthesize_relcall(buf + TMPL_CALL_IDX, optimized_callback);
17972+ synthesize_relcall(buf + TMPL_CALL_IDX, ktla_ktva(optimized_callback));
17973
17974 /* Set returning jmp instruction at the tail of out-of-line buffer */
17975 synthesize_reljump(buf + TMPL_END_IDX + op->optinsn.size,
17976- (u8 *)op->kp.addr + op->optinsn.size);
17977+ (u8 *)ktla_ktva(op->kp.addr) + op->optinsn.size);
17978
17979 flush_icache_range((unsigned long) buf,
17980 (unsigned long) buf + TMPL_END_IDX +
17981@@ -385,7 +385,7 @@ static void __kprobes setup_optimize_kprobe(struct text_poke_param *tprm,
17982 ((long)op->kp.addr + RELATIVEJUMP_SIZE));
17983
17984 /* Backup instructions which will be replaced by jump address */
17985- memcpy(op->optinsn.copied_insn, op->kp.addr + INT3_SIZE,
17986+ memcpy(op->optinsn.copied_insn, ktla_ktva(op->kp.addr) + INT3_SIZE,
17987 RELATIVE_ADDR_SIZE);
17988
17989 insn_buf[0] = RELATIVEJUMP_OPCODE;
17990diff --git a/arch/x86/kernel/kprobes.c b/arch/x86/kernel/kprobes.c
17991index e2f751e..dffa2a0 100644
17992--- a/arch/x86/kernel/kprobes.c
17993+++ b/arch/x86/kernel/kprobes.c
17994@@ -120,8 +120,11 @@ static void __kprobes __synthesize_relative_insn(void *from, void *to, u8 op)
17995 } __attribute__((packed)) *insn;
17996
17997 insn = (struct __arch_relative_insn *)from;
17998+
17999+ pax_open_kernel();
18000 insn->raddr = (s32)((long)(to) - ((long)(from) + 5));
18001 insn->op = op;
18002+ pax_close_kernel();
18003 }
18004
18005 /* Insert a jump instruction at address 'from', which jumps to address 'to'.*/
18006@@ -164,7 +167,7 @@ int __kprobes can_boost(kprobe_opcode_t *opcodes)
18007 kprobe_opcode_t opcode;
18008 kprobe_opcode_t *orig_opcodes = opcodes;
18009
18010- if (search_exception_tables((unsigned long)opcodes))
18011+ if (search_exception_tables(ktva_ktla((unsigned long)opcodes)))
18012 return 0; /* Page fault may occur on this address. */
18013
18014 retry:
18015@@ -332,7 +335,9 @@ int __kprobes __copy_instruction(u8 *dest, u8 *src)
18016 /* Another subsystem puts a breakpoint, failed to recover */
18017 if (insn.opcode.bytes[0] == BREAKPOINT_INSTRUCTION)
18018 return 0;
18019+ pax_open_kernel();
18020 memcpy(dest, insn.kaddr, insn.length);
18021+ pax_close_kernel();
18022
18023 #ifdef CONFIG_X86_64
18024 if (insn_rip_relative(&insn)) {
18025@@ -355,7 +360,9 @@ int __kprobes __copy_instruction(u8 *dest, u8 *src)
18026 newdisp = (u8 *) src + (s64) insn.displacement.value - (u8 *) dest;
18027 BUG_ON((s64) (s32) newdisp != newdisp); /* Sanity check. */
18028 disp = (u8 *) dest + insn_offset_displacement(&insn);
18029+ pax_open_kernel();
18030 *(s32 *) disp = (s32) newdisp;
18031+ pax_close_kernel();
18032 }
18033 #endif
18034 return insn.length;
18035@@ -485,7 +492,7 @@ setup_singlestep(struct kprobe *p, struct pt_regs *regs, struct kprobe_ctlblk *k
18036 * nor set current_kprobe, because it doesn't use single
18037 * stepping.
18038 */
18039- regs->ip = (unsigned long)p->ainsn.insn;
18040+ regs->ip = ktva_ktla((unsigned long)p->ainsn.insn);
18041 preempt_enable_no_resched();
18042 return;
18043 }
18044@@ -504,7 +511,7 @@ setup_singlestep(struct kprobe *p, struct pt_regs *regs, struct kprobe_ctlblk *k
18045 if (p->opcode == BREAKPOINT_INSTRUCTION)
18046 regs->ip = (unsigned long)p->addr;
18047 else
18048- regs->ip = (unsigned long)p->ainsn.insn;
18049+ regs->ip = ktva_ktla((unsigned long)p->ainsn.insn);
18050 }
18051
18052 /*
18053@@ -583,7 +590,7 @@ static int __kprobes kprobe_handler(struct pt_regs *regs)
18054 setup_singlestep(p, regs, kcb, 0);
18055 return 1;
18056 }
18057- } else if (*addr != BREAKPOINT_INSTRUCTION) {
18058+ } else if (*(kprobe_opcode_t *)ktla_ktva((unsigned long)addr) != BREAKPOINT_INSTRUCTION) {
18059 /*
18060 * The breakpoint instruction was removed right
18061 * after we hit it. Another cpu has removed
18062@@ -628,6 +635,9 @@ static void __used __kprobes kretprobe_trampoline_holder(void)
18063 " movq %rax, 152(%rsp)\n"
18064 RESTORE_REGS_STRING
18065 " popfq\n"
18066+#ifdef KERNEXEC_PLUGIN
18067+ " btsq $63,(%rsp)\n"
18068+#endif
18069 #else
18070 " pushf\n"
18071 SAVE_REGS_STRING
18072@@ -765,7 +775,7 @@ static void __kprobes
18073 resume_execution(struct kprobe *p, struct pt_regs *regs, struct kprobe_ctlblk *kcb)
18074 {
18075 unsigned long *tos = stack_addr(regs);
18076- unsigned long copy_ip = (unsigned long)p->ainsn.insn;
18077+ unsigned long copy_ip = ktva_ktla((unsigned long)p->ainsn.insn);
18078 unsigned long orig_ip = (unsigned long)p->addr;
18079 kprobe_opcode_t *insn = p->ainsn.insn;
18080
18081@@ -947,7 +957,7 @@ kprobe_exceptions_notify(struct notifier_block *self, unsigned long val, void *d
18082 struct die_args *args = data;
18083 int ret = NOTIFY_DONE;
18084
18085- if (args->regs && user_mode_vm(args->regs))
18086+ if (args->regs && user_mode(args->regs))
18087 return ret;
18088
18089 switch (val) {
18090diff --git a/arch/x86/kernel/ldt.c b/arch/x86/kernel/ldt.c
18091index ebc9873..1b9724b 100644
18092--- a/arch/x86/kernel/ldt.c
18093+++ b/arch/x86/kernel/ldt.c
18094@@ -66,13 +66,13 @@ static int alloc_ldt(mm_context_t *pc, int mincount, int reload)
18095 if (reload) {
18096 #ifdef CONFIG_SMP
18097 preempt_disable();
18098- load_LDT(pc);
18099+ load_LDT_nolock(pc);
18100 if (!cpumask_equal(mm_cpumask(current->mm),
18101 cpumask_of(smp_processor_id())))
18102 smp_call_function(flush_ldt, current->mm, 1);
18103 preempt_enable();
18104 #else
18105- load_LDT(pc);
18106+ load_LDT_nolock(pc);
18107 #endif
18108 }
18109 if (oldsize) {
18110@@ -94,7 +94,7 @@ static inline int copy_ldt(mm_context_t *new, mm_context_t *old)
18111 return err;
18112
18113 for (i = 0; i < old->size; i++)
18114- write_ldt_entry(new->ldt, i, old->ldt + i * LDT_ENTRY_SIZE);
18115+ write_ldt_entry(new->ldt, i, old->ldt + i);
18116 return 0;
18117 }
18118
18119@@ -115,6 +115,24 @@ int init_new_context(struct task_struct *tsk, struct mm_struct *mm)
18120 retval = copy_ldt(&mm->context, &old_mm->context);
18121 mutex_unlock(&old_mm->context.lock);
18122 }
18123+
18124+ if (tsk == current) {
18125+ mm->context.vdso = 0;
18126+
18127+#ifdef CONFIG_X86_32
18128+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
18129+ mm->context.user_cs_base = 0UL;
18130+ mm->context.user_cs_limit = ~0UL;
18131+
18132+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_SMP)
18133+ cpus_clear(mm->context.cpu_user_cs_mask);
18134+#endif
18135+
18136+#endif
18137+#endif
18138+
18139+ }
18140+
18141 return retval;
18142 }
18143
18144@@ -229,6 +247,13 @@ static int write_ldt(void __user *ptr, unsigned long bytecount, int oldmode)
18145 }
18146 }
18147
18148+#ifdef CONFIG_PAX_SEGMEXEC
18149+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (ldt_info.contents & MODIFY_LDT_CONTENTS_CODE)) {
18150+ error = -EINVAL;
18151+ goto out_unlock;
18152+ }
18153+#endif
18154+
18155 fill_ldt(&ldt, &ldt_info);
18156 if (oldmode)
18157 ldt.avl = 0;
18158diff --git a/arch/x86/kernel/machine_kexec_32.c b/arch/x86/kernel/machine_kexec_32.c
18159index 5b19e4d..6476a76 100644
18160--- a/arch/x86/kernel/machine_kexec_32.c
18161+++ b/arch/x86/kernel/machine_kexec_32.c
18162@@ -26,7 +26,7 @@
18163 #include <asm/cacheflush.h>
18164 #include <asm/debugreg.h>
18165
18166-static void set_idt(void *newidt, __u16 limit)
18167+static void set_idt(struct desc_struct *newidt, __u16 limit)
18168 {
18169 struct desc_ptr curidt;
18170
18171@@ -38,7 +38,7 @@ static void set_idt(void *newidt, __u16 limit)
18172 }
18173
18174
18175-static void set_gdt(void *newgdt, __u16 limit)
18176+static void set_gdt(struct desc_struct *newgdt, __u16 limit)
18177 {
18178 struct desc_ptr curgdt;
18179
18180@@ -216,7 +216,7 @@ void machine_kexec(struct kimage *image)
18181 }
18182
18183 control_page = page_address(image->control_code_page);
18184- memcpy(control_page, relocate_kernel, KEXEC_CONTROL_CODE_MAX_SIZE);
18185+ memcpy(control_page, (void *)ktla_ktva((unsigned long)relocate_kernel), KEXEC_CONTROL_CODE_MAX_SIZE);
18186
18187 relocate_kernel_ptr = control_page;
18188 page_list[PA_CONTROL_PAGE] = __pa(control_page);
18189diff --git a/arch/x86/kernel/microcode_intel.c b/arch/x86/kernel/microcode_intel.c
18190index 0327e2b..e43737b 100644
18191--- a/arch/x86/kernel/microcode_intel.c
18192+++ b/arch/x86/kernel/microcode_intel.c
18193@@ -430,13 +430,13 @@ static enum ucode_state request_microcode_fw(int cpu, struct device *device)
18194
18195 static int get_ucode_user(void *to, const void *from, size_t n)
18196 {
18197- return copy_from_user(to, from, n);
18198+ return copy_from_user(to, (const void __force_user *)from, n);
18199 }
18200
18201 static enum ucode_state
18202 request_microcode_user(int cpu, const void __user *buf, size_t size)
18203 {
18204- return generic_load_microcode(cpu, (void *)buf, size, &get_ucode_user);
18205+ return generic_load_microcode(cpu, (__force_kernel void *)buf, size, &get_ucode_user);
18206 }
18207
18208 static void microcode_fini_cpu(int cpu)
18209diff --git a/arch/x86/kernel/module.c b/arch/x86/kernel/module.c
18210index 216a4d7..b328f09 100644
18211--- a/arch/x86/kernel/module.c
18212+++ b/arch/x86/kernel/module.c
18213@@ -43,15 +43,60 @@ do { \
18214 } while (0)
18215 #endif
18216
18217-void *module_alloc(unsigned long size)
18218+static inline void *__module_alloc(unsigned long size, pgprot_t prot)
18219 {
18220- if (PAGE_ALIGN(size) > MODULES_LEN)
18221+ if (size == 0 || PAGE_ALIGN(size) > MODULES_LEN)
18222 return NULL;
18223 return __vmalloc_node_range(size, 1, MODULES_VADDR, MODULES_END,
18224- GFP_KERNEL | __GFP_HIGHMEM, PAGE_KERNEL_EXEC,
18225+ GFP_KERNEL | __GFP_HIGHMEM | __GFP_ZERO, prot,
18226 -1, __builtin_return_address(0));
18227 }
18228
18229+void *module_alloc(unsigned long size)
18230+{
18231+
18232+#ifdef CONFIG_PAX_KERNEXEC
18233+ return __module_alloc(size, PAGE_KERNEL);
18234+#else
18235+ return __module_alloc(size, PAGE_KERNEL_EXEC);
18236+#endif
18237+
18238+}
18239+
18240+#ifdef CONFIG_PAX_KERNEXEC
18241+#ifdef CONFIG_X86_32
18242+void *module_alloc_exec(unsigned long size)
18243+{
18244+ struct vm_struct *area;
18245+
18246+ if (size == 0)
18247+ return NULL;
18248+
18249+ area = __get_vm_area(size, VM_ALLOC, (unsigned long)&MODULES_EXEC_VADDR, (unsigned long)&MODULES_EXEC_END);
18250+ return area ? area->addr : NULL;
18251+}
18252+EXPORT_SYMBOL(module_alloc_exec);
18253+
18254+void module_free_exec(struct module *mod, void *module_region)
18255+{
18256+ vunmap(module_region);
18257+}
18258+EXPORT_SYMBOL(module_free_exec);
18259+#else
18260+void module_free_exec(struct module *mod, void *module_region)
18261+{
18262+ module_free(mod, module_region);
18263+}
18264+EXPORT_SYMBOL(module_free_exec);
18265+
18266+void *module_alloc_exec(unsigned long size)
18267+{
18268+ return __module_alloc(size, PAGE_KERNEL_RX);
18269+}
18270+EXPORT_SYMBOL(module_alloc_exec);
18271+#endif
18272+#endif
18273+
18274 #ifdef CONFIG_X86_32
18275 int apply_relocate(Elf32_Shdr *sechdrs,
18276 const char *strtab,
18277@@ -62,14 +107,16 @@ int apply_relocate(Elf32_Shdr *sechdrs,
18278 unsigned int i;
18279 Elf32_Rel *rel = (void *)sechdrs[relsec].sh_addr;
18280 Elf32_Sym *sym;
18281- uint32_t *location;
18282+ uint32_t *plocation, location;
18283
18284 DEBUGP("Applying relocate section %u to %u\n",
18285 relsec, sechdrs[relsec].sh_info);
18286 for (i = 0; i < sechdrs[relsec].sh_size / sizeof(*rel); i++) {
18287 /* This is where to make the change */
18288- location = (void *)sechdrs[sechdrs[relsec].sh_info].sh_addr
18289- + rel[i].r_offset;
18290+ plocation = (void *)sechdrs[sechdrs[relsec].sh_info].sh_addr + rel[i].r_offset;
18291+ location = (uint32_t)plocation;
18292+ if (sechdrs[sechdrs[relsec].sh_info].sh_flags & SHF_EXECINSTR)
18293+ plocation = ktla_ktva((void *)plocation);
18294 /* This is the symbol it is referring to. Note that all
18295 undefined symbols have been resolved. */
18296 sym = (Elf32_Sym *)sechdrs[symindex].sh_addr
18297@@ -78,11 +125,15 @@ int apply_relocate(Elf32_Shdr *sechdrs,
18298 switch (ELF32_R_TYPE(rel[i].r_info)) {
18299 case R_386_32:
18300 /* We add the value into the location given */
18301- *location += sym->st_value;
18302+ pax_open_kernel();
18303+ *plocation += sym->st_value;
18304+ pax_close_kernel();
18305 break;
18306 case R_386_PC32:
18307 /* Add the value, subtract its position */
18308- *location += sym->st_value - (uint32_t)location;
18309+ pax_open_kernel();
18310+ *plocation += sym->st_value - location;
18311+ pax_close_kernel();
18312 break;
18313 default:
18314 pr_err("%s: Unknown relocation: %u\n",
18315@@ -127,21 +178,30 @@ int apply_relocate_add(Elf64_Shdr *sechdrs,
18316 case R_X86_64_NONE:
18317 break;
18318 case R_X86_64_64:
18319+ pax_open_kernel();
18320 *(u64 *)loc = val;
18321+ pax_close_kernel();
18322 break;
18323 case R_X86_64_32:
18324+ pax_open_kernel();
18325 *(u32 *)loc = val;
18326+ pax_close_kernel();
18327 if (val != *(u32 *)loc)
18328 goto overflow;
18329 break;
18330 case R_X86_64_32S:
18331+ pax_open_kernel();
18332 *(s32 *)loc = val;
18333+ pax_close_kernel();
18334 if ((s64)val != *(s32 *)loc)
18335 goto overflow;
18336 break;
18337 case R_X86_64_PC32:
18338 val -= (u64)loc;
18339+ pax_open_kernel();
18340 *(u32 *)loc = val;
18341+ pax_close_kernel();
18342+
18343 #if 0
18344 if ((s64)val != *(s32 *)loc)
18345 goto overflow;
18346diff --git a/arch/x86/kernel/nmi.c b/arch/x86/kernel/nmi.c
18347index f84f5c5..e27e54b 100644
18348--- a/arch/x86/kernel/nmi.c
18349+++ b/arch/x86/kernel/nmi.c
18350@@ -479,6 +479,17 @@ static inline void nmi_nesting_postprocess(void)
18351 dotraplinkage notrace __kprobes void
18352 do_nmi(struct pt_regs *regs, long error_code)
18353 {
18354+
18355+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
18356+ if (!user_mode(regs)) {
18357+ unsigned long cs = regs->cs & 0xFFFF;
18358+ unsigned long ip = ktva_ktla(regs->ip);
18359+
18360+ if ((cs == __KERNEL_CS || cs == __KERNEXEC_KERNEL_CS) && ip <= (unsigned long)_etext)
18361+ regs->ip = ip;
18362+ }
18363+#endif
18364+
18365 nmi_nesting_preprocess(regs);
18366
18367 nmi_enter();
18368diff --git a/arch/x86/kernel/paravirt-spinlocks.c b/arch/x86/kernel/paravirt-spinlocks.c
18369index 676b8c7..870ba04 100644
18370--- a/arch/x86/kernel/paravirt-spinlocks.c
18371+++ b/arch/x86/kernel/paravirt-spinlocks.c
18372@@ -13,7 +13,7 @@ default_spin_lock_flags(arch_spinlock_t *lock, unsigned long flags)
18373 arch_spin_lock(lock);
18374 }
18375
18376-struct pv_lock_ops pv_lock_ops = {
18377+struct pv_lock_ops pv_lock_ops __read_only = {
18378 #ifdef CONFIG_SMP
18379 .spin_is_locked = __ticket_spin_is_locked,
18380 .spin_is_contended = __ticket_spin_is_contended,
18381diff --git a/arch/x86/kernel/paravirt.c b/arch/x86/kernel/paravirt.c
18382index 17fff18..7bb2088 100644
18383--- a/arch/x86/kernel/paravirt.c
18384+++ b/arch/x86/kernel/paravirt.c
18385@@ -55,6 +55,9 @@ u64 _paravirt_ident_64(u64 x)
18386 {
18387 return x;
18388 }
18389+#if defined(CONFIG_X86_32) && defined(CONFIG_X86_PAE)
18390+PV_CALLEE_SAVE_REGS_THUNK(_paravirt_ident_64);
18391+#endif
18392
18393 void __init default_banner(void)
18394 {
18395@@ -147,15 +150,19 @@ unsigned paravirt_patch_default(u8 type, u16 clobbers, void *insnbuf,
18396 if (opfunc == NULL)
18397 /* If there's no function, patch it with a ud2a (BUG) */
18398 ret = paravirt_patch_insns(insnbuf, len, ud2a, ud2a+sizeof(ud2a));
18399- else if (opfunc == _paravirt_nop)
18400+ else if (opfunc == (void *)_paravirt_nop)
18401 /* If the operation is a nop, then nop the callsite */
18402 ret = paravirt_patch_nop();
18403
18404 /* identity functions just return their single argument */
18405- else if (opfunc == _paravirt_ident_32)
18406+ else if (opfunc == (void *)_paravirt_ident_32)
18407 ret = paravirt_patch_ident_32(insnbuf, len);
18408- else if (opfunc == _paravirt_ident_64)
18409+ else if (opfunc == (void *)_paravirt_ident_64)
18410 ret = paravirt_patch_ident_64(insnbuf, len);
18411+#if defined(CONFIG_X86_32) && defined(CONFIG_X86_PAE)
18412+ else if (opfunc == (void *)__raw_callee_save__paravirt_ident_64)
18413+ ret = paravirt_patch_ident_64(insnbuf, len);
18414+#endif
18415
18416 else if (type == PARAVIRT_PATCH(pv_cpu_ops.iret) ||
18417 type == PARAVIRT_PATCH(pv_cpu_ops.irq_enable_sysexit) ||
18418@@ -180,7 +187,7 @@ unsigned paravirt_patch_insns(void *insnbuf, unsigned len,
18419 if (insn_len > len || start == NULL)
18420 insn_len = len;
18421 else
18422- memcpy(insnbuf, start, insn_len);
18423+ memcpy(insnbuf, ktla_ktva(start), insn_len);
18424
18425 return insn_len;
18426 }
18427@@ -304,7 +311,7 @@ void arch_flush_lazy_mmu_mode(void)
18428 preempt_enable();
18429 }
18430
18431-struct pv_info pv_info = {
18432+struct pv_info pv_info __read_only = {
18433 .name = "bare hardware",
18434 .paravirt_enabled = 0,
18435 .kernel_rpl = 0,
18436@@ -315,16 +322,16 @@ struct pv_info pv_info = {
18437 #endif
18438 };
18439
18440-struct pv_init_ops pv_init_ops = {
18441+struct pv_init_ops pv_init_ops __read_only = {
18442 .patch = native_patch,
18443 };
18444
18445-struct pv_time_ops pv_time_ops = {
18446+struct pv_time_ops pv_time_ops __read_only = {
18447 .sched_clock = native_sched_clock,
18448 .steal_clock = native_steal_clock,
18449 };
18450
18451-struct pv_irq_ops pv_irq_ops = {
18452+struct pv_irq_ops pv_irq_ops __read_only = {
18453 .save_fl = __PV_IS_CALLEE_SAVE(native_save_fl),
18454 .restore_fl = __PV_IS_CALLEE_SAVE(native_restore_fl),
18455 .irq_disable = __PV_IS_CALLEE_SAVE(native_irq_disable),
18456@@ -336,7 +343,7 @@ struct pv_irq_ops pv_irq_ops = {
18457 #endif
18458 };
18459
18460-struct pv_cpu_ops pv_cpu_ops = {
18461+struct pv_cpu_ops pv_cpu_ops __read_only = {
18462 .cpuid = native_cpuid,
18463 .get_debugreg = native_get_debugreg,
18464 .set_debugreg = native_set_debugreg,
18465@@ -395,21 +402,26 @@ struct pv_cpu_ops pv_cpu_ops = {
18466 .end_context_switch = paravirt_nop,
18467 };
18468
18469-struct pv_apic_ops pv_apic_ops = {
18470+struct pv_apic_ops pv_apic_ops __read_only = {
18471 #ifdef CONFIG_X86_LOCAL_APIC
18472 .startup_ipi_hook = paravirt_nop,
18473 #endif
18474 };
18475
18476-#if defined(CONFIG_X86_32) && !defined(CONFIG_X86_PAE)
18477+#ifdef CONFIG_X86_32
18478+#ifdef CONFIG_X86_PAE
18479+/* 64-bit pagetable entries */
18480+#define PTE_IDENT PV_CALLEE_SAVE(_paravirt_ident_64)
18481+#else
18482 /* 32-bit pagetable entries */
18483 #define PTE_IDENT __PV_IS_CALLEE_SAVE(_paravirt_ident_32)
18484+#endif
18485 #else
18486 /* 64-bit pagetable entries */
18487 #define PTE_IDENT __PV_IS_CALLEE_SAVE(_paravirt_ident_64)
18488 #endif
18489
18490-struct pv_mmu_ops pv_mmu_ops = {
18491+struct pv_mmu_ops pv_mmu_ops __read_only = {
18492
18493 .read_cr2 = native_read_cr2,
18494 .write_cr2 = native_write_cr2,
18495@@ -459,6 +471,7 @@ struct pv_mmu_ops pv_mmu_ops = {
18496 .make_pud = PTE_IDENT,
18497
18498 .set_pgd = native_set_pgd,
18499+ .set_pgd_batched = native_set_pgd_batched,
18500 #endif
18501 #endif /* PAGETABLE_LEVELS >= 3 */
18502
18503@@ -478,6 +491,12 @@ struct pv_mmu_ops pv_mmu_ops = {
18504 },
18505
18506 .set_fixmap = native_set_fixmap,
18507+
18508+#ifdef CONFIG_PAX_KERNEXEC
18509+ .pax_open_kernel = native_pax_open_kernel,
18510+ .pax_close_kernel = native_pax_close_kernel,
18511+#endif
18512+
18513 };
18514
18515 EXPORT_SYMBOL_GPL(pv_time_ops);
18516diff --git a/arch/x86/kernel/pci-iommu_table.c b/arch/x86/kernel/pci-iommu_table.c
18517index 35ccf75..7a15747 100644
18518--- a/arch/x86/kernel/pci-iommu_table.c
18519+++ b/arch/x86/kernel/pci-iommu_table.c
18520@@ -2,7 +2,7 @@
18521 #include <asm/iommu_table.h>
18522 #include <linux/string.h>
18523 #include <linux/kallsyms.h>
18524-
18525+#include <linux/sched.h>
18526
18527 #define DEBUG 1
18528
18529diff --git a/arch/x86/kernel/process.c b/arch/x86/kernel/process.c
18530index ef6a845..8028ed3 100644
18531--- a/arch/x86/kernel/process.c
18532+++ b/arch/x86/kernel/process.c
18533@@ -36,7 +36,8 @@
18534 * section. Since TSS's are completely CPU-local, we want them
18535 * on exact cacheline boundaries, to eliminate cacheline ping-pong.
18536 */
18537-DEFINE_PER_CPU_SHARED_ALIGNED(struct tss_struct, init_tss) = INIT_TSS;
18538+struct tss_struct init_tss[NR_CPUS] ____cacheline_internodealigned_in_smp = { [0 ... NR_CPUS-1] = INIT_TSS };
18539+EXPORT_SYMBOL(init_tss);
18540
18541 #ifdef CONFIG_X86_64
18542 static DEFINE_PER_CPU(unsigned char, is_idle);
18543@@ -94,7 +95,7 @@ void arch_task_cache_init(void)
18544 task_xstate_cachep =
18545 kmem_cache_create("task_xstate", xstate_size,
18546 __alignof__(union thread_xstate),
18547- SLAB_PANIC | SLAB_NOTRACK, NULL);
18548+ SLAB_PANIC | SLAB_NOTRACK | SLAB_USERCOPY, NULL);
18549 }
18550
18551 static inline void drop_fpu(struct task_struct *tsk)
18552@@ -117,7 +118,7 @@ void exit_thread(void)
18553 unsigned long *bp = t->io_bitmap_ptr;
18554
18555 if (bp) {
18556- struct tss_struct *tss = &per_cpu(init_tss, get_cpu());
18557+ struct tss_struct *tss = init_tss + get_cpu();
18558
18559 t->io_bitmap_ptr = NULL;
18560 clear_thread_flag(TIF_IO_BITMAP);
18561@@ -148,7 +149,7 @@ void show_regs_common(void)
18562 board = dmi_get_system_info(DMI_BOARD_NAME);
18563
18564 printk(KERN_DEFAULT "Pid: %d, comm: %.20s %s %s %.*s %s %s%s%s\n",
18565- current->pid, current->comm, print_tainted(),
18566+ task_pid_nr(current), current->comm, print_tainted(),
18567 init_utsname()->release,
18568 (int)strcspn(init_utsname()->version, " "),
18569 init_utsname()->version,
18570@@ -161,6 +162,9 @@ void flush_thread(void)
18571 {
18572 struct task_struct *tsk = current;
18573
18574+#if defined(CONFIG_X86_32) && !defined(CONFIG_CC_STACKPROTECTOR) && !defined(CONFIG_PAX_MEMORY_UDEREF)
18575+ loadsegment(gs, 0);
18576+#endif
18577 flush_ptrace_hw_breakpoint(tsk);
18578 memset(tsk->thread.tls_array, 0, sizeof(tsk->thread.tls_array));
18579 drop_fpu(tsk);
18580@@ -318,10 +322,10 @@ int kernel_thread(int (*fn)(void *), void *arg, unsigned long flags)
18581 regs.di = (unsigned long) arg;
18582
18583 #ifdef CONFIG_X86_32
18584- regs.ds = __USER_DS;
18585- regs.es = __USER_DS;
18586+ regs.ds = __KERNEL_DS;
18587+ regs.es = __KERNEL_DS;
18588 regs.fs = __KERNEL_PERCPU;
18589- regs.gs = __KERNEL_STACK_CANARY;
18590+ savesegment(gs, regs.gs);
18591 #else
18592 regs.ss = __KERNEL_DS;
18593 #endif
18594@@ -407,7 +411,7 @@ static void __exit_idle(void)
18595 void exit_idle(void)
18596 {
18597 /* idle loop has pid 0 */
18598- if (current->pid)
18599+ if (task_pid_nr(current))
18600 return;
18601 __exit_idle();
18602 }
18603@@ -516,7 +520,7 @@ bool set_pm_idle_to_default(void)
18604
18605 return ret;
18606 }
18607-void stop_this_cpu(void *dummy)
18608+__noreturn void stop_this_cpu(void *dummy)
18609 {
18610 local_irq_disable();
18611 /*
18612@@ -744,16 +748,37 @@ static int __init idle_setup(char *str)
18613 }
18614 early_param("idle", idle_setup);
18615
18616-unsigned long arch_align_stack(unsigned long sp)
18617+#ifdef CONFIG_PAX_RANDKSTACK
18618+void pax_randomize_kstack(struct pt_regs *regs)
18619 {
18620- if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
18621- sp -= get_random_int() % 8192;
18622- return sp & ~0xf;
18623-}
18624+ struct thread_struct *thread = &current->thread;
18625+ unsigned long time;
18626
18627-unsigned long arch_randomize_brk(struct mm_struct *mm)
18628-{
18629- unsigned long range_end = mm->brk + 0x02000000;
18630- return randomize_range(mm->brk, range_end, 0) ? : mm->brk;
18631-}
18632+ if (!randomize_va_space)
18633+ return;
18634+
18635+ if (v8086_mode(regs))
18636+ return;
18637
18638+ rdtscl(time);
18639+
18640+ /* P4 seems to return a 0 LSB, ignore it */
18641+#ifdef CONFIG_MPENTIUM4
18642+ time &= 0x3EUL;
18643+ time <<= 2;
18644+#elif defined(CONFIG_X86_64)
18645+ time &= 0xFUL;
18646+ time <<= 4;
18647+#else
18648+ time &= 0x1FUL;
18649+ time <<= 3;
18650+#endif
18651+
18652+ thread->sp0 ^= time;
18653+ load_sp0(init_tss + smp_processor_id(), thread);
18654+
18655+#ifdef CONFIG_X86_64
18656+ this_cpu_write(kernel_stack, thread->sp0);
18657+#endif
18658+}
18659+#endif
18660diff --git a/arch/x86/kernel/process_32.c b/arch/x86/kernel/process_32.c
18661index 516fa18..d3a7099 100644
18662--- a/arch/x86/kernel/process_32.c
18663+++ b/arch/x86/kernel/process_32.c
18664@@ -64,6 +64,7 @@ asmlinkage void ret_from_fork(void) __asm__("ret_from_fork");
18665 unsigned long thread_saved_pc(struct task_struct *tsk)
18666 {
18667 return ((unsigned long *)tsk->thread.sp)[3];
18668+//XXX return tsk->thread.eip;
18669 }
18670
18671 void __show_regs(struct pt_regs *regs, int all)
18672@@ -73,21 +74,20 @@ void __show_regs(struct pt_regs *regs, int all)
18673 unsigned long sp;
18674 unsigned short ss, gs;
18675
18676- if (user_mode_vm(regs)) {
18677+ if (user_mode(regs)) {
18678 sp = regs->sp;
18679 ss = regs->ss & 0xffff;
18680- gs = get_user_gs(regs);
18681 } else {
18682 sp = kernel_stack_pointer(regs);
18683 savesegment(ss, ss);
18684- savesegment(gs, gs);
18685 }
18686+ gs = get_user_gs(regs);
18687
18688 show_regs_common();
18689
18690 printk(KERN_DEFAULT "EIP: %04x:[<%08lx>] EFLAGS: %08lx CPU: %d\n",
18691 (u16)regs->cs, regs->ip, regs->flags,
18692- smp_processor_id());
18693+ raw_smp_processor_id());
18694 print_symbol("EIP is at %s\n", regs->ip);
18695
18696 printk(KERN_DEFAULT "EAX: %08lx EBX: %08lx ECX: %08lx EDX: %08lx\n",
18697@@ -134,13 +134,14 @@ int copy_thread(unsigned long clone_flags, unsigned long sp,
18698 struct task_struct *tsk;
18699 int err;
18700
18701- childregs = task_pt_regs(p);
18702+ childregs = task_stack_page(p) + THREAD_SIZE - sizeof(struct pt_regs) - 8;
18703 *childregs = *regs;
18704 childregs->ax = 0;
18705 childregs->sp = sp;
18706
18707 p->thread.sp = (unsigned long) childregs;
18708 p->thread.sp0 = (unsigned long) (childregs+1);
18709+ p->tinfo.lowest_stack = (unsigned long)task_stack_page(p);
18710
18711 p->thread.ip = (unsigned long) ret_from_fork;
18712
18713@@ -231,7 +232,7 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
18714 struct thread_struct *prev = &prev_p->thread,
18715 *next = &next_p->thread;
18716 int cpu = smp_processor_id();
18717- struct tss_struct *tss = &per_cpu(init_tss, cpu);
18718+ struct tss_struct *tss = init_tss + cpu;
18719 fpu_switch_t fpu;
18720
18721 /* never put a printk in __switch_to... printk() calls wake_up*() indirectly */
18722@@ -255,6 +256,10 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
18723 */
18724 lazy_save_gs(prev->gs);
18725
18726+#ifdef CONFIG_PAX_MEMORY_UDEREF
18727+ __set_fs(task_thread_info(next_p)->addr_limit);
18728+#endif
18729+
18730 /*
18731 * Load the per-thread Thread-Local Storage descriptor.
18732 */
18733@@ -285,6 +290,9 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
18734 */
18735 arch_end_context_switch(next_p);
18736
18737+ this_cpu_write(current_task, next_p);
18738+ this_cpu_write(current_tinfo, &next_p->tinfo);
18739+
18740 /*
18741 * Restore %gs if needed (which is common)
18742 */
18743@@ -293,8 +301,6 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
18744
18745 switch_fpu_finish(next_p, fpu);
18746
18747- this_cpu_write(current_task, next_p);
18748-
18749 return prev_p;
18750 }
18751
18752@@ -324,4 +330,3 @@ unsigned long get_wchan(struct task_struct *p)
18753 } while (count++ < 16);
18754 return 0;
18755 }
18756-
18757diff --git a/arch/x86/kernel/process_64.c b/arch/x86/kernel/process_64.c
18758index 0a980c9..1d0e689 100644
18759--- a/arch/x86/kernel/process_64.c
18760+++ b/arch/x86/kernel/process_64.c
18761@@ -153,8 +153,7 @@ int copy_thread(unsigned long clone_flags, unsigned long sp,
18762 struct pt_regs *childregs;
18763 struct task_struct *me = current;
18764
18765- childregs = ((struct pt_regs *)
18766- (THREAD_SIZE + task_stack_page(p))) - 1;
18767+ childregs = task_stack_page(p) + THREAD_SIZE - sizeof(struct pt_regs) - 16;
18768 *childregs = *regs;
18769
18770 childregs->ax = 0;
18771@@ -166,6 +165,7 @@ int copy_thread(unsigned long clone_flags, unsigned long sp,
18772 p->thread.sp = (unsigned long) childregs;
18773 p->thread.sp0 = (unsigned long) (childregs+1);
18774 p->thread.usersp = me->thread.usersp;
18775+ p->tinfo.lowest_stack = (unsigned long)task_stack_page(p);
18776
18777 set_tsk_thread_flag(p, TIF_FORK);
18778
18779@@ -271,7 +271,7 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
18780 struct thread_struct *prev = &prev_p->thread;
18781 struct thread_struct *next = &next_p->thread;
18782 int cpu = smp_processor_id();
18783- struct tss_struct *tss = &per_cpu(init_tss, cpu);
18784+ struct tss_struct *tss = init_tss + cpu;
18785 unsigned fsindex, gsindex;
18786 fpu_switch_t fpu;
18787
18788@@ -353,10 +353,9 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
18789 prev->usersp = this_cpu_read(old_rsp);
18790 this_cpu_write(old_rsp, next->usersp);
18791 this_cpu_write(current_task, next_p);
18792+ this_cpu_write(current_tinfo, &next_p->tinfo);
18793
18794- this_cpu_write(kernel_stack,
18795- (unsigned long)task_stack_page(next_p) +
18796- THREAD_SIZE - KERNEL_STACK_OFFSET);
18797+ this_cpu_write(kernel_stack, next->sp0);
18798
18799 /*
18800 * Now maybe reload the debug registers and handle I/O bitmaps
18801@@ -425,12 +424,11 @@ unsigned long get_wchan(struct task_struct *p)
18802 if (!p || p == current || p->state == TASK_RUNNING)
18803 return 0;
18804 stack = (unsigned long)task_stack_page(p);
18805- if (p->thread.sp < stack || p->thread.sp >= stack+THREAD_SIZE)
18806+ if (p->thread.sp < stack || p->thread.sp > stack+THREAD_SIZE-16-sizeof(u64))
18807 return 0;
18808 fp = *(u64 *)(p->thread.sp);
18809 do {
18810- if (fp < (unsigned long)stack ||
18811- fp >= (unsigned long)stack+THREAD_SIZE)
18812+ if (fp < stack || fp > stack+THREAD_SIZE-16-sizeof(u64))
18813 return 0;
18814 ip = *(u64 *)(fp+8);
18815 if (!in_sched_functions(ip))
18816diff --git a/arch/x86/kernel/ptrace.c b/arch/x86/kernel/ptrace.c
18817index c4c6a5c..905f440 100644
18818--- a/arch/x86/kernel/ptrace.c
18819+++ b/arch/x86/kernel/ptrace.c
18820@@ -824,7 +824,7 @@ long arch_ptrace(struct task_struct *child, long request,
18821 unsigned long addr, unsigned long data)
18822 {
18823 int ret;
18824- unsigned long __user *datap = (unsigned long __user *)data;
18825+ unsigned long __user *datap = (__force unsigned long __user *)data;
18826
18827 switch (request) {
18828 /* read the word at location addr in the USER area. */
18829@@ -909,14 +909,14 @@ long arch_ptrace(struct task_struct *child, long request,
18830 if ((int) addr < 0)
18831 return -EIO;
18832 ret = do_get_thread_area(child, addr,
18833- (struct user_desc __user *)data);
18834+ (__force struct user_desc __user *) data);
18835 break;
18836
18837 case PTRACE_SET_THREAD_AREA:
18838 if ((int) addr < 0)
18839 return -EIO;
18840 ret = do_set_thread_area(child, addr,
18841- (struct user_desc __user *)data, 0);
18842+ (__force struct user_desc __user *) data, 0);
18843 break;
18844 #endif
18845
18846@@ -1426,7 +1426,7 @@ static void fill_sigtrap_info(struct task_struct *tsk,
18847 memset(info, 0, sizeof(*info));
18848 info->si_signo = SIGTRAP;
18849 info->si_code = si_code;
18850- info->si_addr = user_mode_vm(regs) ? (void __user *)regs->ip : NULL;
18851+ info->si_addr = user_mode(regs) ? (__force void __user *)regs->ip : NULL;
18852 }
18853
18854 void user_single_step_siginfo(struct task_struct *tsk,
18855@@ -1455,6 +1455,10 @@ void send_sigtrap(struct task_struct *tsk, struct pt_regs *regs,
18856 # define IS_IA32 0
18857 #endif
18858
18859+#ifdef CONFIG_GRKERNSEC_SETXID
18860+extern void gr_delayed_cred_worker(void);
18861+#endif
18862+
18863 /*
18864 * We must return the syscall number to actually look up in the table.
18865 * This can be -1L to skip running any syscall at all.
18866@@ -1463,6 +1467,11 @@ long syscall_trace_enter(struct pt_regs *regs)
18867 {
18868 long ret = 0;
18869
18870+#ifdef CONFIG_GRKERNSEC_SETXID
18871+ if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
18872+ gr_delayed_cred_worker();
18873+#endif
18874+
18875 /*
18876 * If we stepped into a sysenter/syscall insn, it trapped in
18877 * kernel mode; do_debug() cleared TF and set TIF_SINGLESTEP.
18878@@ -1511,6 +1520,11 @@ void syscall_trace_leave(struct pt_regs *regs)
18879 {
18880 bool step;
18881
18882+#ifdef CONFIG_GRKERNSEC_SETXID
18883+ if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
18884+ gr_delayed_cred_worker();
18885+#endif
18886+
18887 audit_syscall_exit(regs);
18888
18889 if (unlikely(test_thread_flag(TIF_SYSCALL_TRACEPOINT)))
18890diff --git a/arch/x86/kernel/pvclock.c b/arch/x86/kernel/pvclock.c
18891index 42eb330..139955c 100644
18892--- a/arch/x86/kernel/pvclock.c
18893+++ b/arch/x86/kernel/pvclock.c
18894@@ -81,11 +81,11 @@ unsigned long pvclock_tsc_khz(struct pvclock_vcpu_time_info *src)
18895 return pv_tsc_khz;
18896 }
18897
18898-static atomic64_t last_value = ATOMIC64_INIT(0);
18899+static atomic64_unchecked_t last_value = ATOMIC64_INIT(0);
18900
18901 void pvclock_resume(void)
18902 {
18903- atomic64_set(&last_value, 0);
18904+ atomic64_set_unchecked(&last_value, 0);
18905 }
18906
18907 cycle_t pvclock_clocksource_read(struct pvclock_vcpu_time_info *src)
18908@@ -121,11 +121,11 @@ cycle_t pvclock_clocksource_read(struct pvclock_vcpu_time_info *src)
18909 * updating at the same time, and one of them could be slightly behind,
18910 * making the assumption that last_value always go forward fail to hold.
18911 */
18912- last = atomic64_read(&last_value);
18913+ last = atomic64_read_unchecked(&last_value);
18914 do {
18915 if (ret < last)
18916 return last;
18917- last = atomic64_cmpxchg(&last_value, last, ret);
18918+ last = atomic64_cmpxchg_unchecked(&last_value, last, ret);
18919 } while (unlikely(last != ret));
18920
18921 return ret;
18922diff --git a/arch/x86/kernel/reboot.c b/arch/x86/kernel/reboot.c
18923index 52190a9..8074389 100644
18924--- a/arch/x86/kernel/reboot.c
18925+++ b/arch/x86/kernel/reboot.c
18926@@ -36,7 +36,7 @@ void (*pm_power_off)(void);
18927 EXPORT_SYMBOL(pm_power_off);
18928
18929 static const struct desc_ptr no_idt = {};
18930-static int reboot_mode;
18931+static unsigned short reboot_mode;
18932 enum reboot_type reboot_type = BOOT_ACPI;
18933 int reboot_force;
18934
18935@@ -157,6 +157,11 @@ static int __init set_bios_reboot(const struct dmi_system_id *d)
18936
18937 void __noreturn machine_real_restart(unsigned int type)
18938 {
18939+
18940+#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF))
18941+ struct desc_struct *gdt;
18942+#endif
18943+
18944 local_irq_disable();
18945
18946 /*
18947@@ -184,7 +189,29 @@ void __noreturn machine_real_restart(unsigned int type)
18948
18949 /* Jump to the identity-mapped low memory code */
18950 #ifdef CONFIG_X86_32
18951- asm volatile("jmpl *%0" : :
18952+
18953+#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
18954+ gdt = get_cpu_gdt_table(smp_processor_id());
18955+ pax_open_kernel();
18956+#ifdef CONFIG_PAX_MEMORY_UDEREF
18957+ gdt[GDT_ENTRY_KERNEL_DS].type = 3;
18958+ gdt[GDT_ENTRY_KERNEL_DS].limit = 0xf;
18959+ loadsegment(ds, __KERNEL_DS);
18960+ loadsegment(es, __KERNEL_DS);
18961+ loadsegment(ss, __KERNEL_DS);
18962+#endif
18963+#ifdef CONFIG_PAX_KERNEXEC
18964+ gdt[GDT_ENTRY_KERNEL_CS].base0 = 0;
18965+ gdt[GDT_ENTRY_KERNEL_CS].base1 = 0;
18966+ gdt[GDT_ENTRY_KERNEL_CS].base2 = 0;
18967+ gdt[GDT_ENTRY_KERNEL_CS].limit0 = 0xffff;
18968+ gdt[GDT_ENTRY_KERNEL_CS].limit = 0xf;
18969+ gdt[GDT_ENTRY_KERNEL_CS].g = 1;
18970+#endif
18971+ pax_close_kernel();
18972+#endif
18973+
18974+ asm volatile("ljmpl *%0" : :
18975 "rm" (real_mode_header->machine_real_restart_asm),
18976 "a" (type));
18977 #else
18978@@ -539,7 +566,7 @@ void __attribute__((weak)) mach_reboot_fixups(void)
18979 * try to force a triple fault and then cycle between hitting the keyboard
18980 * controller and doing that
18981 */
18982-static void native_machine_emergency_restart(void)
18983+static void __noreturn native_machine_emergency_restart(void)
18984 {
18985 int i;
18986 int attempt = 0;
18987@@ -662,13 +689,13 @@ void native_machine_shutdown(void)
18988 #endif
18989 }
18990
18991-static void __machine_emergency_restart(int emergency)
18992+static void __noreturn __machine_emergency_restart(int emergency)
18993 {
18994 reboot_emergency = emergency;
18995 machine_ops.emergency_restart();
18996 }
18997
18998-static void native_machine_restart(char *__unused)
18999+static void __noreturn native_machine_restart(char *__unused)
19000 {
19001 pr_notice("machine restart\n");
19002
19003@@ -677,7 +704,7 @@ static void native_machine_restart(char *__unused)
19004 __machine_emergency_restart(0);
19005 }
19006
19007-static void native_machine_halt(void)
19008+static void __noreturn native_machine_halt(void)
19009 {
19010 /* Stop other cpus and apics */
19011 machine_shutdown();
19012@@ -687,7 +714,7 @@ static void native_machine_halt(void)
19013 stop_this_cpu(NULL);
19014 }
19015
19016-static void native_machine_power_off(void)
19017+static void __noreturn native_machine_power_off(void)
19018 {
19019 if (pm_power_off) {
19020 if (!reboot_force)
19021@@ -696,6 +723,7 @@ static void native_machine_power_off(void)
19022 }
19023 /* A fallback in case there is no PM info available */
19024 tboot_shutdown(TB_SHUTDOWN_HALT);
19025+ unreachable();
19026 }
19027
19028 struct machine_ops machine_ops = {
19029diff --git a/arch/x86/kernel/relocate_kernel_64.S b/arch/x86/kernel/relocate_kernel_64.S
19030index 7a6f3b3..bed145d7 100644
19031--- a/arch/x86/kernel/relocate_kernel_64.S
19032+++ b/arch/x86/kernel/relocate_kernel_64.S
19033@@ -11,6 +11,7 @@
19034 #include <asm/kexec.h>
19035 #include <asm/processor-flags.h>
19036 #include <asm/pgtable_types.h>
19037+#include <asm/alternative-asm.h>
19038
19039 /*
19040 * Must be relocatable PIC code callable as a C function
19041@@ -160,13 +161,14 @@ identity_mapped:
19042 xorq %rbp, %rbp
19043 xorq %r8, %r8
19044 xorq %r9, %r9
19045- xorq %r10, %r9
19046+ xorq %r10, %r10
19047 xorq %r11, %r11
19048 xorq %r12, %r12
19049 xorq %r13, %r13
19050 xorq %r14, %r14
19051 xorq %r15, %r15
19052
19053+ pax_force_retaddr 0, 1
19054 ret
19055
19056 1:
19057diff --git a/arch/x86/kernel/setup.c b/arch/x86/kernel/setup.c
19058index 5cee802..bc22bc3 100644
19059--- a/arch/x86/kernel/setup.c
19060+++ b/arch/x86/kernel/setup.c
19061@@ -440,7 +440,7 @@ static void __init parse_setup_data(void)
19062
19063 switch (data->type) {
19064 case SETUP_E820_EXT:
19065- parse_e820_ext(data);
19066+ parse_e820_ext((struct setup_data __force_kernel *)data);
19067 break;
19068 case SETUP_DTB:
19069 add_dtb(pa_data);
19070@@ -632,7 +632,7 @@ static void __init trim_bios_range(void)
19071 * area (640->1Mb) as ram even though it is not.
19072 * take them out.
19073 */
19074- e820_remove_range(BIOS_BEGIN, BIOS_END - BIOS_BEGIN, E820_RAM, 1);
19075+ e820_remove_range(ISA_START_ADDRESS, ISA_END_ADDRESS - ISA_START_ADDRESS, E820_RAM, 1);
19076 sanitize_e820_map(e820.map, ARRAY_SIZE(e820.map), &e820.nr_map);
19077 }
19078
19079@@ -755,14 +755,14 @@ void __init setup_arch(char **cmdline_p)
19080
19081 if (!boot_params.hdr.root_flags)
19082 root_mountflags &= ~MS_RDONLY;
19083- init_mm.start_code = (unsigned long) _text;
19084- init_mm.end_code = (unsigned long) _etext;
19085+ init_mm.start_code = ktla_ktva((unsigned long) _text);
19086+ init_mm.end_code = ktla_ktva((unsigned long) _etext);
19087 init_mm.end_data = (unsigned long) _edata;
19088 init_mm.brk = _brk_end;
19089
19090- code_resource.start = virt_to_phys(_text);
19091- code_resource.end = virt_to_phys(_etext)-1;
19092- data_resource.start = virt_to_phys(_etext);
19093+ code_resource.start = virt_to_phys(ktla_ktva(_text));
19094+ code_resource.end = virt_to_phys(ktla_ktva(_etext))-1;
19095+ data_resource.start = virt_to_phys(_sdata);
19096 data_resource.end = virt_to_phys(_edata)-1;
19097 bss_resource.start = virt_to_phys(&__bss_start);
19098 bss_resource.end = virt_to_phys(&__bss_stop)-1;
19099diff --git a/arch/x86/kernel/setup_percpu.c b/arch/x86/kernel/setup_percpu.c
19100index 5cdff03..5810740 100644
19101--- a/arch/x86/kernel/setup_percpu.c
19102+++ b/arch/x86/kernel/setup_percpu.c
19103@@ -21,19 +21,17 @@
19104 #include <asm/cpu.h>
19105 #include <asm/stackprotector.h>
19106
19107-DEFINE_PER_CPU_READ_MOSTLY(int, cpu_number);
19108+#ifdef CONFIG_SMP
19109+DEFINE_PER_CPU_READ_MOSTLY(unsigned int, cpu_number);
19110 EXPORT_PER_CPU_SYMBOL(cpu_number);
19111+#endif
19112
19113-#ifdef CONFIG_X86_64
19114 #define BOOT_PERCPU_OFFSET ((unsigned long)__per_cpu_load)
19115-#else
19116-#define BOOT_PERCPU_OFFSET 0
19117-#endif
19118
19119 DEFINE_PER_CPU(unsigned long, this_cpu_off) = BOOT_PERCPU_OFFSET;
19120 EXPORT_PER_CPU_SYMBOL(this_cpu_off);
19121
19122-unsigned long __per_cpu_offset[NR_CPUS] __read_mostly = {
19123+unsigned long __per_cpu_offset[NR_CPUS] __read_only = {
19124 [0 ... NR_CPUS-1] = BOOT_PERCPU_OFFSET,
19125 };
19126 EXPORT_SYMBOL(__per_cpu_offset);
19127@@ -155,10 +153,10 @@ static inline void setup_percpu_segment(int cpu)
19128 {
19129 #ifdef CONFIG_X86_32
19130 struct desc_struct gdt;
19131+ unsigned long base = per_cpu_offset(cpu);
19132
19133- pack_descriptor(&gdt, per_cpu_offset(cpu), 0xFFFFF,
19134- 0x2 | DESCTYPE_S, 0x8);
19135- gdt.s = 1;
19136+ pack_descriptor(&gdt, base, (VMALLOC_END - base - 1) >> PAGE_SHIFT,
19137+ 0x83 | DESCTYPE_S, 0xC);
19138 write_gdt_entry(get_cpu_gdt_table(cpu),
19139 GDT_ENTRY_PERCPU, &gdt, DESCTYPE_S);
19140 #endif
19141@@ -219,6 +217,11 @@ void __init setup_per_cpu_areas(void)
19142 /* alrighty, percpu areas up and running */
19143 delta = (unsigned long)pcpu_base_addr - (unsigned long)__per_cpu_start;
19144 for_each_possible_cpu(cpu) {
19145+#ifdef CONFIG_CC_STACKPROTECTOR
19146+#ifdef CONFIG_X86_32
19147+ unsigned long canary = per_cpu(stack_canary.canary, cpu);
19148+#endif
19149+#endif
19150 per_cpu_offset(cpu) = delta + pcpu_unit_offsets[cpu];
19151 per_cpu(this_cpu_off, cpu) = per_cpu_offset(cpu);
19152 per_cpu(cpu_number, cpu) = cpu;
19153@@ -259,6 +262,12 @@ void __init setup_per_cpu_areas(void)
19154 */
19155 set_cpu_numa_node(cpu, early_cpu_to_node(cpu));
19156 #endif
19157+#ifdef CONFIG_CC_STACKPROTECTOR
19158+#ifdef CONFIG_X86_32
19159+ if (!cpu)
19160+ per_cpu(stack_canary.canary, cpu) = canary;
19161+#endif
19162+#endif
19163 /*
19164 * Up to this point, the boot CPU has been using .init.data
19165 * area. Reload any changed state for the boot CPU.
19166diff --git a/arch/x86/kernel/signal.c b/arch/x86/kernel/signal.c
19167index b280908..6de349e 100644
19168--- a/arch/x86/kernel/signal.c
19169+++ b/arch/x86/kernel/signal.c
19170@@ -194,7 +194,7 @@ static unsigned long align_sigframe(unsigned long sp)
19171 * Align the stack pointer according to the i386 ABI,
19172 * i.e. so that on function entry ((sp + 4) & 15) == 0.
19173 */
19174- sp = ((sp + 4) & -16ul) - 4;
19175+ sp = ((sp - 12) & -16ul) - 4;
19176 #else /* !CONFIG_X86_32 */
19177 sp = round_down(sp, 16) - 8;
19178 #endif
19179@@ -245,11 +245,11 @@ get_sigframe(struct k_sigaction *ka, struct pt_regs *regs, size_t frame_size,
19180 * Return an always-bogus address instead so we will die with SIGSEGV.
19181 */
19182 if (onsigstack && !likely(on_sig_stack(sp)))
19183- return (void __user *)-1L;
19184+ return (__force void __user *)-1L;
19185
19186 /* save i387 state */
19187 if (used_math() && save_i387_xstate(*fpstate) < 0)
19188- return (void __user *)-1L;
19189+ return (__force void __user *)-1L;
19190
19191 return (void __user *)sp;
19192 }
19193@@ -304,9 +304,9 @@ __setup_frame(int sig, struct k_sigaction *ka, sigset_t *set,
19194 }
19195
19196 if (current->mm->context.vdso)
19197- restorer = VDSO32_SYMBOL(current->mm->context.vdso, sigreturn);
19198+ restorer = (__force void __user *)VDSO32_SYMBOL(current->mm->context.vdso, sigreturn);
19199 else
19200- restorer = &frame->retcode;
19201+ restorer = (void __user *)&frame->retcode;
19202 if (ka->sa.sa_flags & SA_RESTORER)
19203 restorer = ka->sa.sa_restorer;
19204
19205@@ -320,7 +320,7 @@ __setup_frame(int sig, struct k_sigaction *ka, sigset_t *set,
19206 * reasons and because gdb uses it as a signature to notice
19207 * signal handler stack frames.
19208 */
19209- err |= __put_user(*((u64 *)&retcode), (u64 *)frame->retcode);
19210+ err |= __put_user(*((u64 *)&retcode), (u64 __user *)frame->retcode);
19211
19212 if (err)
19213 return -EFAULT;
19214@@ -374,7 +374,10 @@ static int __setup_rt_frame(int sig, struct k_sigaction *ka, siginfo_t *info,
19215 err |= __copy_to_user(&frame->uc.uc_sigmask, set, sizeof(*set));
19216
19217 /* Set up to return from userspace. */
19218- restorer = VDSO32_SYMBOL(current->mm->context.vdso, rt_sigreturn);
19219+ if (current->mm->context.vdso)
19220+ restorer = (__force void __user *)VDSO32_SYMBOL(current->mm->context.vdso, rt_sigreturn);
19221+ else
19222+ restorer = (void __user *)&frame->retcode;
19223 if (ka->sa.sa_flags & SA_RESTORER)
19224 restorer = ka->sa.sa_restorer;
19225 put_user_ex(restorer, &frame->pretcode);
19226@@ -386,7 +389,7 @@ static int __setup_rt_frame(int sig, struct k_sigaction *ka, siginfo_t *info,
19227 * reasons and because gdb uses it as a signature to notice
19228 * signal handler stack frames.
19229 */
19230- put_user_ex(*((u64 *)&rt_retcode), (u64 *)frame->retcode);
19231+ put_user_ex(*((u64 *)&rt_retcode), (u64 __user *)frame->retcode);
19232 } put_user_catch(err);
19233
19234 if (err)
19235diff --git a/arch/x86/kernel/smpboot.c b/arch/x86/kernel/smpboot.c
19236index 7c5a8c3..88d422f 100644
19237--- a/arch/x86/kernel/smpboot.c
19238+++ b/arch/x86/kernel/smpboot.c
19239@@ -670,6 +670,7 @@ static int __cpuinit do_boot_cpu(int apicid, int cpu, struct task_struct *idle)
19240 idle->thread.sp = (unsigned long) (((struct pt_regs *)
19241 (THREAD_SIZE + task_stack_page(idle))) - 1);
19242 per_cpu(current_task, cpu) = idle;
19243+ per_cpu(current_tinfo, cpu) = &idle->tinfo;
19244
19245 #ifdef CONFIG_X86_32
19246 /* Stack for startup_32 can be just as for start_secondary onwards */
19247@@ -677,11 +678,13 @@ static int __cpuinit do_boot_cpu(int apicid, int cpu, struct task_struct *idle)
19248 #else
19249 clear_tsk_thread_flag(idle, TIF_FORK);
19250 initial_gs = per_cpu_offset(cpu);
19251- per_cpu(kernel_stack, cpu) =
19252- (unsigned long)task_stack_page(idle) -
19253- KERNEL_STACK_OFFSET + THREAD_SIZE;
19254+ per_cpu(kernel_stack, cpu) = (unsigned long)task_stack_page(idle) - 16 + THREAD_SIZE;
19255 #endif
19256+
19257+ pax_open_kernel();
19258 early_gdt_descr.address = (unsigned long)get_cpu_gdt_table(cpu);
19259+ pax_close_kernel();
19260+
19261 initial_code = (unsigned long)start_secondary;
19262 stack_start = idle->thread.sp;
19263
19264@@ -817,6 +820,12 @@ int __cpuinit native_cpu_up(unsigned int cpu, struct task_struct *tidle)
19265
19266 per_cpu(cpu_state, cpu) = CPU_UP_PREPARE;
19267
19268+#ifdef CONFIG_PAX_PER_CPU_PGD
19269+ clone_pgd_range(get_cpu_pgd(cpu) + KERNEL_PGD_BOUNDARY,
19270+ swapper_pg_dir + KERNEL_PGD_BOUNDARY,
19271+ KERNEL_PGD_PTRS);
19272+#endif
19273+
19274 err = do_boot_cpu(apicid, cpu, tidle);
19275 if (err) {
19276 pr_debug("do_boot_cpu failed %d\n", err);
19277diff --git a/arch/x86/kernel/step.c b/arch/x86/kernel/step.c
19278index c346d11..d43b163 100644
19279--- a/arch/x86/kernel/step.c
19280+++ b/arch/x86/kernel/step.c
19281@@ -27,10 +27,10 @@ unsigned long convert_ip_to_linear(struct task_struct *child, struct pt_regs *re
19282 struct desc_struct *desc;
19283 unsigned long base;
19284
19285- seg &= ~7UL;
19286+ seg >>= 3;
19287
19288 mutex_lock(&child->mm->context.lock);
19289- if (unlikely((seg >> 3) >= child->mm->context.size))
19290+ if (unlikely(seg >= child->mm->context.size))
19291 addr = -1L; /* bogus selector, access would fault */
19292 else {
19293 desc = child->mm->context.ldt + seg;
19294@@ -42,7 +42,8 @@ unsigned long convert_ip_to_linear(struct task_struct *child, struct pt_regs *re
19295 addr += base;
19296 }
19297 mutex_unlock(&child->mm->context.lock);
19298- }
19299+ } else if (seg == __KERNEL_CS || seg == __KERNEXEC_KERNEL_CS)
19300+ addr = ktla_ktva(addr);
19301
19302 return addr;
19303 }
19304@@ -53,6 +54,9 @@ static int is_setting_trap_flag(struct task_struct *child, struct pt_regs *regs)
19305 unsigned char opcode[15];
19306 unsigned long addr = convert_ip_to_linear(child, regs);
19307
19308+ if (addr == -EINVAL)
19309+ return 0;
19310+
19311 copied = access_process_vm(child, addr, opcode, sizeof(opcode), 0);
19312 for (i = 0; i < copied; i++) {
19313 switch (opcode[i]) {
19314diff --git a/arch/x86/kernel/sys_i386_32.c b/arch/x86/kernel/sys_i386_32.c
19315index 0b0cb5f..db6b9ed 100644
19316--- a/arch/x86/kernel/sys_i386_32.c
19317+++ b/arch/x86/kernel/sys_i386_32.c
19318@@ -24,17 +24,224 @@
19319
19320 #include <asm/syscalls.h>
19321
19322-/*
19323- * Do a system call from kernel instead of calling sys_execve so we
19324- * end up with proper pt_regs.
19325- */
19326-int kernel_execve(const char *filename,
19327- const char *const argv[],
19328- const char *const envp[])
19329+int i386_mmap_check(unsigned long addr, unsigned long len, unsigned long flags)
19330 {
19331- long __res;
19332- asm volatile ("int $0x80"
19333- : "=a" (__res)
19334- : "0" (__NR_execve), "b" (filename), "c" (argv), "d" (envp) : "memory");
19335- return __res;
19336+ unsigned long pax_task_size = TASK_SIZE;
19337+
19338+#ifdef CONFIG_PAX_SEGMEXEC
19339+ if (current->mm->pax_flags & MF_PAX_SEGMEXEC)
19340+ pax_task_size = SEGMEXEC_TASK_SIZE;
19341+#endif
19342+
19343+ if (len > pax_task_size || addr > pax_task_size - len)
19344+ return -EINVAL;
19345+
19346+ return 0;
19347+}
19348+
19349+unsigned long
19350+arch_get_unmapped_area(struct file *filp, unsigned long addr,
19351+ unsigned long len, unsigned long pgoff, unsigned long flags)
19352+{
19353+ struct mm_struct *mm = current->mm;
19354+ struct vm_area_struct *vma;
19355+ unsigned long start_addr, pax_task_size = TASK_SIZE;
19356+
19357+#ifdef CONFIG_PAX_SEGMEXEC
19358+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
19359+ pax_task_size = SEGMEXEC_TASK_SIZE;
19360+#endif
19361+
19362+ pax_task_size -= PAGE_SIZE;
19363+
19364+ if (len > pax_task_size)
19365+ return -ENOMEM;
19366+
19367+ if (flags & MAP_FIXED)
19368+ return addr;
19369+
19370+#ifdef CONFIG_PAX_RANDMMAP
19371+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
19372+#endif
19373+
19374+ if (addr) {
19375+ addr = PAGE_ALIGN(addr);
19376+ if (pax_task_size - len >= addr) {
19377+ vma = find_vma(mm, addr);
19378+ if (check_heap_stack_gap(vma, addr, len))
19379+ return addr;
19380+ }
19381+ }
19382+ if (len > mm->cached_hole_size) {
19383+ start_addr = addr = mm->free_area_cache;
19384+ } else {
19385+ start_addr = addr = mm->mmap_base;
19386+ mm->cached_hole_size = 0;
19387+ }
19388+
19389+#ifdef CONFIG_PAX_PAGEEXEC
19390+ if (!(__supported_pte_mask & _PAGE_NX) && (mm->pax_flags & MF_PAX_PAGEEXEC) && (flags & MAP_EXECUTABLE) && start_addr >= mm->mmap_base) {
19391+ start_addr = 0x00110000UL;
19392+
19393+#ifdef CONFIG_PAX_RANDMMAP
19394+ if (mm->pax_flags & MF_PAX_RANDMMAP)
19395+ start_addr += mm->delta_mmap & 0x03FFF000UL;
19396+#endif
19397+
19398+ if (mm->start_brk <= start_addr && start_addr < mm->mmap_base)
19399+ start_addr = addr = mm->mmap_base;
19400+ else
19401+ addr = start_addr;
19402+ }
19403+#endif
19404+
19405+full_search:
19406+ for (vma = find_vma(mm, addr); ; vma = vma->vm_next) {
19407+ /* At this point: (!vma || addr < vma->vm_end). */
19408+ if (pax_task_size - len < addr) {
19409+ /*
19410+ * Start a new search - just in case we missed
19411+ * some holes.
19412+ */
19413+ if (start_addr != mm->mmap_base) {
19414+ start_addr = addr = mm->mmap_base;
19415+ mm->cached_hole_size = 0;
19416+ goto full_search;
19417+ }
19418+ return -ENOMEM;
19419+ }
19420+ if (check_heap_stack_gap(vma, addr, len))
19421+ break;
19422+ if (addr + mm->cached_hole_size < vma->vm_start)
19423+ mm->cached_hole_size = vma->vm_start - addr;
19424+ addr = vma->vm_end;
19425+ if (mm->start_brk <= addr && addr < mm->mmap_base) {
19426+ start_addr = addr = mm->mmap_base;
19427+ mm->cached_hole_size = 0;
19428+ goto full_search;
19429+ }
19430+ }
19431+
19432+ /*
19433+ * Remember the place where we stopped the search:
19434+ */
19435+ mm->free_area_cache = addr + len;
19436+ return addr;
19437+}
19438+
19439+unsigned long
19440+arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
19441+ const unsigned long len, const unsigned long pgoff,
19442+ const unsigned long flags)
19443+{
19444+ struct vm_area_struct *vma;
19445+ struct mm_struct *mm = current->mm;
19446+ unsigned long base = mm->mmap_base, addr = addr0, pax_task_size = TASK_SIZE;
19447+
19448+#ifdef CONFIG_PAX_SEGMEXEC
19449+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
19450+ pax_task_size = SEGMEXEC_TASK_SIZE;
19451+#endif
19452+
19453+ pax_task_size -= PAGE_SIZE;
19454+
19455+ /* requested length too big for entire address space */
19456+ if (len > pax_task_size)
19457+ return -ENOMEM;
19458+
19459+ if (flags & MAP_FIXED)
19460+ return addr;
19461+
19462+#ifdef CONFIG_PAX_PAGEEXEC
19463+ if (!(__supported_pte_mask & _PAGE_NX) && (mm->pax_flags & MF_PAX_PAGEEXEC) && (flags & MAP_EXECUTABLE))
19464+ goto bottomup;
19465+#endif
19466+
19467+#ifdef CONFIG_PAX_RANDMMAP
19468+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
19469+#endif
19470+
19471+ /* requesting a specific address */
19472+ if (addr) {
19473+ addr = PAGE_ALIGN(addr);
19474+ if (pax_task_size - len >= addr) {
19475+ vma = find_vma(mm, addr);
19476+ if (check_heap_stack_gap(vma, addr, len))
19477+ return addr;
19478+ }
19479+ }
19480+
19481+ /* check if free_area_cache is useful for us */
19482+ if (len <= mm->cached_hole_size) {
19483+ mm->cached_hole_size = 0;
19484+ mm->free_area_cache = mm->mmap_base;
19485+ }
19486+
19487+ /* either no address requested or can't fit in requested address hole */
19488+ addr = mm->free_area_cache;
19489+
19490+ /* make sure it can fit in the remaining address space */
19491+ if (addr > len) {
19492+ vma = find_vma(mm, addr-len);
19493+ if (check_heap_stack_gap(vma, addr - len, len))
19494+ /* remember the address as a hint for next time */
19495+ return (mm->free_area_cache = addr-len);
19496+ }
19497+
19498+ if (mm->mmap_base < len)
19499+ goto bottomup;
19500+
19501+ addr = mm->mmap_base-len;
19502+
19503+ do {
19504+ /*
19505+ * Lookup failure means no vma is above this address,
19506+ * else if new region fits below vma->vm_start,
19507+ * return with success:
19508+ */
19509+ vma = find_vma(mm, addr);
19510+ if (check_heap_stack_gap(vma, addr, len))
19511+ /* remember the address as a hint for next time */
19512+ return (mm->free_area_cache = addr);
19513+
19514+ /* remember the largest hole we saw so far */
19515+ if (addr + mm->cached_hole_size < vma->vm_start)
19516+ mm->cached_hole_size = vma->vm_start - addr;
19517+
19518+ /* try just below the current vma->vm_start */
19519+ addr = skip_heap_stack_gap(vma, len);
19520+ } while (!IS_ERR_VALUE(addr));
19521+
19522+bottomup:
19523+ /*
19524+ * A failed mmap() very likely causes application failure,
19525+ * so fall back to the bottom-up function here. This scenario
19526+ * can happen with large stack limits and large mmap()
19527+ * allocations.
19528+ */
19529+
19530+#ifdef CONFIG_PAX_SEGMEXEC
19531+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
19532+ mm->mmap_base = SEGMEXEC_TASK_UNMAPPED_BASE;
19533+ else
19534+#endif
19535+
19536+ mm->mmap_base = TASK_UNMAPPED_BASE;
19537+
19538+#ifdef CONFIG_PAX_RANDMMAP
19539+ if (mm->pax_flags & MF_PAX_RANDMMAP)
19540+ mm->mmap_base += mm->delta_mmap;
19541+#endif
19542+
19543+ mm->free_area_cache = mm->mmap_base;
19544+ mm->cached_hole_size = ~0UL;
19545+ addr = arch_get_unmapped_area(filp, addr0, len, pgoff, flags);
19546+ /*
19547+ * Restore the topdown base:
19548+ */
19549+ mm->mmap_base = base;
19550+ mm->free_area_cache = base;
19551+ mm->cached_hole_size = ~0UL;
19552+
19553+ return addr;
19554 }
19555diff --git a/arch/x86/kernel/sys_x86_64.c b/arch/x86/kernel/sys_x86_64.c
19556index b4d3c39..82bb73b 100644
19557--- a/arch/x86/kernel/sys_x86_64.c
19558+++ b/arch/x86/kernel/sys_x86_64.c
19559@@ -95,8 +95,8 @@ out:
19560 return error;
19561 }
19562
19563-static void find_start_end(unsigned long flags, unsigned long *begin,
19564- unsigned long *end)
19565+static void find_start_end(struct mm_struct *mm, unsigned long flags,
19566+ unsigned long *begin, unsigned long *end)
19567 {
19568 if (!test_thread_flag(TIF_ADDR32) && (flags & MAP_32BIT)) {
19569 unsigned long new_begin;
19570@@ -115,7 +115,7 @@ static void find_start_end(unsigned long flags, unsigned long *begin,
19571 *begin = new_begin;
19572 }
19573 } else {
19574- *begin = TASK_UNMAPPED_BASE;
19575+ *begin = mm->mmap_base;
19576 *end = TASK_SIZE;
19577 }
19578 }
19579@@ -132,16 +132,19 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
19580 if (flags & MAP_FIXED)
19581 return addr;
19582
19583- find_start_end(flags, &begin, &end);
19584+ find_start_end(mm, flags, &begin, &end);
19585
19586 if (len > end)
19587 return -ENOMEM;
19588
19589+#ifdef CONFIG_PAX_RANDMMAP
19590+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
19591+#endif
19592+
19593 if (addr) {
19594 addr = PAGE_ALIGN(addr);
19595 vma = find_vma(mm, addr);
19596- if (end - len >= addr &&
19597- (!vma || addr + len <= vma->vm_start))
19598+ if (end - len >= addr && check_heap_stack_gap(vma, addr, len))
19599 return addr;
19600 }
19601 if (((flags & MAP_32BIT) || test_thread_flag(TIF_ADDR32))
19602@@ -172,7 +175,7 @@ full_search:
19603 }
19604 return -ENOMEM;
19605 }
19606- if (!vma || addr + len <= vma->vm_start) {
19607+ if (check_heap_stack_gap(vma, addr, len)) {
19608 /*
19609 * Remember the place where we stopped the search:
19610 */
19611@@ -195,7 +198,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
19612 {
19613 struct vm_area_struct *vma;
19614 struct mm_struct *mm = current->mm;
19615- unsigned long addr = addr0, start_addr;
19616+ unsigned long base = mm->mmap_base, addr = addr0, start_addr;
19617
19618 /* requested length too big for entire address space */
19619 if (len > TASK_SIZE)
19620@@ -208,13 +211,18 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
19621 if (!test_thread_flag(TIF_ADDR32) && (flags & MAP_32BIT))
19622 goto bottomup;
19623
19624+#ifdef CONFIG_PAX_RANDMMAP
19625+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
19626+#endif
19627+
19628 /* requesting a specific address */
19629 if (addr) {
19630 addr = PAGE_ALIGN(addr);
19631- vma = find_vma(mm, addr);
19632- if (TASK_SIZE - len >= addr &&
19633- (!vma || addr + len <= vma->vm_start))
19634- return addr;
19635+ if (TASK_SIZE - len >= addr) {
19636+ vma = find_vma(mm, addr);
19637+ if (check_heap_stack_gap(vma, addr, len))
19638+ return addr;
19639+ }
19640 }
19641
19642 /* check if free_area_cache is useful for us */
19643@@ -240,7 +248,7 @@ try_again:
19644 * return with success:
19645 */
19646 vma = find_vma(mm, addr);
19647- if (!vma || addr+len <= vma->vm_start)
19648+ if (check_heap_stack_gap(vma, addr, len))
19649 /* remember the address as a hint for next time */
19650 return mm->free_area_cache = addr;
19651
19652@@ -249,8 +257,8 @@ try_again:
19653 mm->cached_hole_size = vma->vm_start - addr;
19654
19655 /* try just below the current vma->vm_start */
19656- addr = vma->vm_start-len;
19657- } while (len < vma->vm_start);
19658+ addr = skip_heap_stack_gap(vma, len);
19659+ } while (!IS_ERR_VALUE(addr));
19660
19661 fail:
19662 /*
19663@@ -270,13 +278,21 @@ bottomup:
19664 * can happen with large stack limits and large mmap()
19665 * allocations.
19666 */
19667+ mm->mmap_base = TASK_UNMAPPED_BASE;
19668+
19669+#ifdef CONFIG_PAX_RANDMMAP
19670+ if (mm->pax_flags & MF_PAX_RANDMMAP)
19671+ mm->mmap_base += mm->delta_mmap;
19672+#endif
19673+
19674+ mm->free_area_cache = mm->mmap_base;
19675 mm->cached_hole_size = ~0UL;
19676- mm->free_area_cache = TASK_UNMAPPED_BASE;
19677 addr = arch_get_unmapped_area(filp, addr0, len, pgoff, flags);
19678 /*
19679 * Restore the topdown base:
19680 */
19681- mm->free_area_cache = mm->mmap_base;
19682+ mm->mmap_base = base;
19683+ mm->free_area_cache = base;
19684 mm->cached_hole_size = ~0UL;
19685
19686 return addr;
19687diff --git a/arch/x86/kernel/tboot.c b/arch/x86/kernel/tboot.c
19688index f84fe00..93fe08f 100644
19689--- a/arch/x86/kernel/tboot.c
19690+++ b/arch/x86/kernel/tboot.c
19691@@ -220,7 +220,7 @@ static int tboot_setup_sleep(void)
19692
19693 void tboot_shutdown(u32 shutdown_type)
19694 {
19695- void (*shutdown)(void);
19696+ void (* __noreturn shutdown)(void);
19697
19698 if (!tboot_enabled())
19699 return;
19700@@ -242,7 +242,7 @@ void tboot_shutdown(u32 shutdown_type)
19701
19702 switch_to_tboot_pt();
19703
19704- shutdown = (void(*)(void))(unsigned long)tboot->shutdown_entry;
19705+ shutdown = (void *)tboot->shutdown_entry;
19706 shutdown();
19707
19708 /* should not reach here */
19709@@ -300,7 +300,7 @@ static int tboot_sleep(u8 sleep_state, u32 pm1a_control, u32 pm1b_control)
19710 return 0;
19711 }
19712
19713-static atomic_t ap_wfs_count;
19714+static atomic_unchecked_t ap_wfs_count;
19715
19716 static int tboot_wait_for_aps(int num_aps)
19717 {
19718@@ -324,9 +324,9 @@ static int __cpuinit tboot_cpu_callback(struct notifier_block *nfb,
19719 {
19720 switch (action) {
19721 case CPU_DYING:
19722- atomic_inc(&ap_wfs_count);
19723+ atomic_inc_unchecked(&ap_wfs_count);
19724 if (num_online_cpus() == 1)
19725- if (tboot_wait_for_aps(atomic_read(&ap_wfs_count)))
19726+ if (tboot_wait_for_aps(atomic_read_unchecked(&ap_wfs_count)))
19727 return NOTIFY_BAD;
19728 break;
19729 }
19730@@ -345,7 +345,7 @@ static __init int tboot_late_init(void)
19731
19732 tboot_create_trampoline();
19733
19734- atomic_set(&ap_wfs_count, 0);
19735+ atomic_set_unchecked(&ap_wfs_count, 0);
19736 register_hotcpu_notifier(&tboot_cpu_notifier);
19737
19738 acpi_os_set_prepare_sleep(&tboot_sleep);
19739diff --git a/arch/x86/kernel/time.c b/arch/x86/kernel/time.c
19740index 24d3c91..d06b473 100644
19741--- a/arch/x86/kernel/time.c
19742+++ b/arch/x86/kernel/time.c
19743@@ -30,9 +30,9 @@ unsigned long profile_pc(struct pt_regs *regs)
19744 {
19745 unsigned long pc = instruction_pointer(regs);
19746
19747- if (!user_mode_vm(regs) && in_lock_functions(pc)) {
19748+ if (!user_mode(regs) && in_lock_functions(pc)) {
19749 #ifdef CONFIG_FRAME_POINTER
19750- return *(unsigned long *)(regs->bp + sizeof(long));
19751+ return ktla_ktva(*(unsigned long *)(regs->bp + sizeof(long)));
19752 #else
19753 unsigned long *sp =
19754 (unsigned long *)kernel_stack_pointer(regs);
19755@@ -41,11 +41,17 @@ unsigned long profile_pc(struct pt_regs *regs)
19756 * or above a saved flags. Eflags has bits 22-31 zero,
19757 * kernel addresses don't.
19758 */
19759+
19760+#ifdef CONFIG_PAX_KERNEXEC
19761+ return ktla_ktva(sp[0]);
19762+#else
19763 if (sp[0] >> 22)
19764 return sp[0];
19765 if (sp[1] >> 22)
19766 return sp[1];
19767 #endif
19768+
19769+#endif
19770 }
19771 return pc;
19772 }
19773diff --git a/arch/x86/kernel/tls.c b/arch/x86/kernel/tls.c
19774index 9d9d2f9..cad418a 100644
19775--- a/arch/x86/kernel/tls.c
19776+++ b/arch/x86/kernel/tls.c
19777@@ -84,6 +84,11 @@ int do_set_thread_area(struct task_struct *p, int idx,
19778 if (idx < GDT_ENTRY_TLS_MIN || idx > GDT_ENTRY_TLS_MAX)
19779 return -EINVAL;
19780
19781+#ifdef CONFIG_PAX_SEGMEXEC
19782+ if ((p->mm->pax_flags & MF_PAX_SEGMEXEC) && (info.contents & MODIFY_LDT_CONTENTS_CODE))
19783+ return -EINVAL;
19784+#endif
19785+
19786 set_tls_desc(p, idx, &info, 1);
19787
19788 return 0;
19789@@ -204,7 +209,7 @@ int regset_tls_set(struct task_struct *target, const struct user_regset *regset,
19790
19791 if (kbuf)
19792 info = kbuf;
19793- else if (__copy_from_user(infobuf, ubuf, count))
19794+ else if (count > sizeof infobuf || __copy_from_user(infobuf, ubuf, count))
19795 return -EFAULT;
19796 else
19797 info = infobuf;
19798diff --git a/arch/x86/kernel/traps.c b/arch/x86/kernel/traps.c
19799index b481341..5918bbe 100644
19800--- a/arch/x86/kernel/traps.c
19801+++ b/arch/x86/kernel/traps.c
19802@@ -70,12 +70,6 @@ asmlinkage int system_call(void);
19803
19804 /* Do we ignore FPU interrupts ? */
19805 char ignore_fpu_irq;
19806-
19807-/*
19808- * The IDT has to be page-aligned to simplify the Pentium
19809- * F0 0F bug workaround.
19810- */
19811-gate_desc idt_table[NR_VECTORS] __page_aligned_data = { { { { 0, 0 } } }, };
19812 #endif
19813
19814 DECLARE_BITMAP(used_vectors, NR_VECTORS);
19815@@ -108,13 +102,13 @@ static inline void preempt_conditional_cli(struct pt_regs *regs)
19816 }
19817
19818 static void __kprobes
19819-do_trap(int trapnr, int signr, char *str, struct pt_regs *regs,
19820+do_trap(int trapnr, int signr, const char *str, struct pt_regs *regs,
19821 long error_code, siginfo_t *info)
19822 {
19823 struct task_struct *tsk = current;
19824
19825 #ifdef CONFIG_X86_32
19826- if (regs->flags & X86_VM_MASK) {
19827+ if (v8086_mode(regs)) {
19828 /*
19829 * traps 0, 1, 3, 4, and 5 should be forwarded to vm86.
19830 * On nmi (interrupt 2), do_trap should not be called.
19831@@ -125,7 +119,7 @@ do_trap(int trapnr, int signr, char *str, struct pt_regs *regs,
19832 }
19833 #endif
19834
19835- if (!user_mode(regs))
19836+ if (!user_mode_novm(regs))
19837 goto kernel_trap;
19838
19839 #ifdef CONFIG_X86_32
19840@@ -147,7 +141,7 @@ trap_signal:
19841 if (show_unhandled_signals && unhandled_signal(tsk, signr) &&
19842 printk_ratelimit()) {
19843 pr_info("%s[%d] trap %s ip:%lx sp:%lx error:%lx",
19844- tsk->comm, tsk->pid, str,
19845+ tsk->comm, task_pid_nr(tsk), str,
19846 regs->ip, regs->sp, error_code);
19847 print_vma_addr(" in ", regs->ip);
19848 pr_cont("\n");
19849@@ -164,8 +158,20 @@ kernel_trap:
19850 if (!fixup_exception(regs)) {
19851 tsk->thread.error_code = error_code;
19852 tsk->thread.trap_nr = trapnr;
19853+
19854+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
19855+ if (trapnr == 12 && ((regs->cs & 0xFFFF) == __KERNEL_CS || (regs->cs & 0xFFFF) == __KERNEXEC_KERNEL_CS))
19856+ str = "PAX: suspicious stack segment fault";
19857+#endif
19858+
19859 die(str, regs, error_code);
19860 }
19861+
19862+#ifdef CONFIG_PAX_REFCOUNT
19863+ if (trapnr == 4)
19864+ pax_report_refcount_overflow(regs);
19865+#endif
19866+
19867 return;
19868
19869 #ifdef CONFIG_X86_32
19870@@ -258,14 +264,30 @@ do_general_protection(struct pt_regs *regs, long error_code)
19871 conditional_sti(regs);
19872
19873 #ifdef CONFIG_X86_32
19874- if (regs->flags & X86_VM_MASK)
19875+ if (v8086_mode(regs))
19876 goto gp_in_vm86;
19877 #endif
19878
19879 tsk = current;
19880- if (!user_mode(regs))
19881+ if (!user_mode_novm(regs))
19882 goto gp_in_kernel;
19883
19884+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
19885+ if (!(__supported_pte_mask & _PAGE_NX) && tsk->mm && (tsk->mm->pax_flags & MF_PAX_PAGEEXEC)) {
19886+ struct mm_struct *mm = tsk->mm;
19887+ unsigned long limit;
19888+
19889+ down_write(&mm->mmap_sem);
19890+ limit = mm->context.user_cs_limit;
19891+ if (limit < TASK_SIZE) {
19892+ track_exec_limit(mm, limit, TASK_SIZE, VM_EXEC);
19893+ up_write(&mm->mmap_sem);
19894+ return;
19895+ }
19896+ up_write(&mm->mmap_sem);
19897+ }
19898+#endif
19899+
19900 tsk->thread.error_code = error_code;
19901 tsk->thread.trap_nr = X86_TRAP_GP;
19902
19903@@ -297,6 +319,13 @@ gp_in_kernel:
19904 if (notify_die(DIE_GPF, "general protection fault", regs, error_code,
19905 X86_TRAP_GP, SIGSEGV) == NOTIFY_STOP)
19906 return;
19907+
19908+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
19909+ if ((regs->cs & 0xFFFF) == __KERNEL_CS || (regs->cs & 0xFFFF) == __KERNEXEC_KERNEL_CS)
19910+ die("PAX: suspicious general protection fault", regs, error_code);
19911+ else
19912+#endif
19913+
19914 die("general protection fault", regs, error_code);
19915 }
19916
19917@@ -432,7 +461,7 @@ dotraplinkage void __kprobes do_debug(struct pt_regs *regs, long error_code)
19918 /* It's safe to allow irq's after DR6 has been saved */
19919 preempt_conditional_sti(regs);
19920
19921- if (regs->flags & X86_VM_MASK) {
19922+ if (v8086_mode(regs)) {
19923 handle_vm86_trap((struct kernel_vm86_regs *) regs, error_code,
19924 X86_TRAP_DB);
19925 preempt_conditional_cli(regs);
19926@@ -447,7 +476,7 @@ dotraplinkage void __kprobes do_debug(struct pt_regs *regs, long error_code)
19927 * We already checked v86 mode above, so we can check for kernel mode
19928 * by just checking the CPL of CS.
19929 */
19930- if ((dr6 & DR_STEP) && !user_mode(regs)) {
19931+ if ((dr6 & DR_STEP) && !user_mode_novm(regs)) {
19932 tsk->thread.debugreg6 &= ~DR_STEP;
19933 set_tsk_thread_flag(tsk, TIF_SINGLESTEP);
19934 regs->flags &= ~X86_EFLAGS_TF;
19935@@ -478,7 +507,7 @@ void math_error(struct pt_regs *regs, int error_code, int trapnr)
19936 return;
19937 conditional_sti(regs);
19938
19939- if (!user_mode_vm(regs))
19940+ if (!user_mode(regs))
19941 {
19942 if (!fixup_exception(regs)) {
19943 task->thread.error_code = error_code;
19944diff --git a/arch/x86/kernel/uprobes.c b/arch/x86/kernel/uprobes.c
19945index 36fd420..7e5892d 100644
19946--- a/arch/x86/kernel/uprobes.c
19947+++ b/arch/x86/kernel/uprobes.c
19948@@ -607,7 +607,7 @@ int arch_uprobe_exception_notify(struct notifier_block *self, unsigned long val,
19949 int ret = NOTIFY_DONE;
19950
19951 /* We are only interested in userspace traps */
19952- if (regs && !user_mode_vm(regs))
19953+ if (regs && !user_mode(regs))
19954 return NOTIFY_DONE;
19955
19956 switch (val) {
19957diff --git a/arch/x86/kernel/verify_cpu.S b/arch/x86/kernel/verify_cpu.S
19958index b9242ba..50c5edd 100644
19959--- a/arch/x86/kernel/verify_cpu.S
19960+++ b/arch/x86/kernel/verify_cpu.S
19961@@ -20,6 +20,7 @@
19962 * arch/x86/boot/compressed/head_64.S: Boot cpu verification
19963 * arch/x86/kernel/trampoline_64.S: secondary processor verification
19964 * arch/x86/kernel/head_32.S: processor startup
19965+ * arch/x86/kernel/acpi/realmode/wakeup.S: 32bit processor resume
19966 *
19967 * verify_cpu, returns the status of longmode and SSE in register %eax.
19968 * 0: Success 1: Failure
19969diff --git a/arch/x86/kernel/vm86_32.c b/arch/x86/kernel/vm86_32.c
19970index 54abcc0..eb6c848 100644
19971--- a/arch/x86/kernel/vm86_32.c
19972+++ b/arch/x86/kernel/vm86_32.c
19973@@ -43,6 +43,7 @@
19974 #include <linux/ptrace.h>
19975 #include <linux/audit.h>
19976 #include <linux/stddef.h>
19977+#include <linux/grsecurity.h>
19978
19979 #include <asm/uaccess.h>
19980 #include <asm/io.h>
19981@@ -150,7 +151,7 @@ struct pt_regs *save_v86_state(struct kernel_vm86_regs *regs)
19982 do_exit(SIGSEGV);
19983 }
19984
19985- tss = &per_cpu(init_tss, get_cpu());
19986+ tss = init_tss + get_cpu();
19987 current->thread.sp0 = current->thread.saved_sp0;
19988 current->thread.sysenter_cs = __KERNEL_CS;
19989 load_sp0(tss, &current->thread);
19990@@ -212,6 +213,13 @@ int sys_vm86old(struct vm86_struct __user *v86, struct pt_regs *regs)
19991 struct task_struct *tsk;
19992 int tmp, ret = -EPERM;
19993
19994+#ifdef CONFIG_GRKERNSEC_VM86
19995+ if (!capable(CAP_SYS_RAWIO)) {
19996+ gr_handle_vm86();
19997+ goto out;
19998+ }
19999+#endif
20000+
20001 tsk = current;
20002 if (tsk->thread.saved_sp0)
20003 goto out;
20004@@ -242,6 +250,14 @@ int sys_vm86(unsigned long cmd, unsigned long arg, struct pt_regs *regs)
20005 int tmp, ret;
20006 struct vm86plus_struct __user *v86;
20007
20008+#ifdef CONFIG_GRKERNSEC_VM86
20009+ if (!capable(CAP_SYS_RAWIO)) {
20010+ gr_handle_vm86();
20011+ ret = -EPERM;
20012+ goto out;
20013+ }
20014+#endif
20015+
20016 tsk = current;
20017 switch (cmd) {
20018 case VM86_REQUEST_IRQ:
20019@@ -328,7 +344,7 @@ static void do_sys_vm86(struct kernel_vm86_struct *info, struct task_struct *tsk
20020 tsk->thread.saved_fs = info->regs32->fs;
20021 tsk->thread.saved_gs = get_user_gs(info->regs32);
20022
20023- tss = &per_cpu(init_tss, get_cpu());
20024+ tss = init_tss + get_cpu();
20025 tsk->thread.sp0 = (unsigned long) &info->VM86_TSS_ESP0;
20026 if (cpu_has_sep)
20027 tsk->thread.sysenter_cs = 0;
20028@@ -535,7 +551,7 @@ static void do_int(struct kernel_vm86_regs *regs, int i,
20029 goto cannot_handle;
20030 if (i == 0x21 && is_revectored(AH(regs), &KVM86->int21_revectored))
20031 goto cannot_handle;
20032- intr_ptr = (unsigned long __user *) (i << 2);
20033+ intr_ptr = (__force unsigned long __user *) (i << 2);
20034 if (get_user(segoffs, intr_ptr))
20035 goto cannot_handle;
20036 if ((segoffs >> 16) == BIOSSEG)
20037diff --git a/arch/x86/kernel/vmlinux.lds.S b/arch/x86/kernel/vmlinux.lds.S
20038index 22a1530..8fbaaad 100644
20039--- a/arch/x86/kernel/vmlinux.lds.S
20040+++ b/arch/x86/kernel/vmlinux.lds.S
20041@@ -26,6 +26,13 @@
20042 #include <asm/page_types.h>
20043 #include <asm/cache.h>
20044 #include <asm/boot.h>
20045+#include <asm/segment.h>
20046+
20047+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
20048+#define __KERNEL_TEXT_OFFSET (LOAD_OFFSET + ____LOAD_PHYSICAL_ADDR)
20049+#else
20050+#define __KERNEL_TEXT_OFFSET 0
20051+#endif
20052
20053 #undef i386 /* in case the preprocessor is a 32bit one */
20054
20055@@ -69,30 +76,43 @@ jiffies_64 = jiffies;
20056
20057 PHDRS {
20058 text PT_LOAD FLAGS(5); /* R_E */
20059+#ifdef CONFIG_X86_32
20060+ module PT_LOAD FLAGS(5); /* R_E */
20061+#endif
20062+#ifdef CONFIG_XEN
20063+ rodata PT_LOAD FLAGS(5); /* R_E */
20064+#else
20065+ rodata PT_LOAD FLAGS(4); /* R__ */
20066+#endif
20067 data PT_LOAD FLAGS(6); /* RW_ */
20068-#ifdef CONFIG_X86_64
20069+ init.begin PT_LOAD FLAGS(6); /* RW_ */
20070 #ifdef CONFIG_SMP
20071 percpu PT_LOAD FLAGS(6); /* RW_ */
20072 #endif
20073+ text.init PT_LOAD FLAGS(5); /* R_E */
20074+ text.exit PT_LOAD FLAGS(5); /* R_E */
20075 init PT_LOAD FLAGS(7); /* RWE */
20076-#endif
20077 note PT_NOTE FLAGS(0); /* ___ */
20078 }
20079
20080 SECTIONS
20081 {
20082 #ifdef CONFIG_X86_32
20083- . = LOAD_OFFSET + LOAD_PHYSICAL_ADDR;
20084- phys_startup_32 = startup_32 - LOAD_OFFSET;
20085+ . = LOAD_OFFSET + ____LOAD_PHYSICAL_ADDR;
20086 #else
20087- . = __START_KERNEL;
20088- phys_startup_64 = startup_64 - LOAD_OFFSET;
20089+ . = __START_KERNEL;
20090 #endif
20091
20092 /* Text and read-only data */
20093- .text : AT(ADDR(.text) - LOAD_OFFSET) {
20094- _text = .;
20095+ .text (. - __KERNEL_TEXT_OFFSET): AT(ADDR(.text) - LOAD_OFFSET + __KERNEL_TEXT_OFFSET) {
20096 /* bootstrapping code */
20097+#ifdef CONFIG_X86_32
20098+ phys_startup_32 = startup_32 - LOAD_OFFSET + __KERNEL_TEXT_OFFSET;
20099+#else
20100+ phys_startup_64 = startup_64 - LOAD_OFFSET + __KERNEL_TEXT_OFFSET;
20101+#endif
20102+ __LOAD_PHYSICAL_ADDR = . - LOAD_OFFSET + __KERNEL_TEXT_OFFSET;
20103+ _text = .;
20104 HEAD_TEXT
20105 #ifdef CONFIG_X86_32
20106 . = ALIGN(PAGE_SIZE);
20107@@ -108,13 +128,48 @@ SECTIONS
20108 IRQENTRY_TEXT
20109 *(.fixup)
20110 *(.gnu.warning)
20111- /* End of text section */
20112- _etext = .;
20113 } :text = 0x9090
20114
20115- NOTES :text :note
20116+ . += __KERNEL_TEXT_OFFSET;
20117
20118- EXCEPTION_TABLE(16) :text = 0x9090
20119+#ifdef CONFIG_X86_32
20120+ . = ALIGN(PAGE_SIZE);
20121+ .module.text : AT(ADDR(.module.text) - LOAD_OFFSET) {
20122+
20123+#if defined(CONFIG_PAX_KERNEXEC) && defined(CONFIG_MODULES)
20124+ MODULES_EXEC_VADDR = .;
20125+ BYTE(0)
20126+ . += (CONFIG_PAX_KERNEXEC_MODULE_TEXT * 1024 * 1024);
20127+ . = ALIGN(HPAGE_SIZE) - 1;
20128+ MODULES_EXEC_END = .;
20129+#endif
20130+
20131+ } :module
20132+#endif
20133+
20134+ .text.end : AT(ADDR(.text.end) - LOAD_OFFSET) {
20135+ /* End of text section */
20136+ BYTE(0)
20137+ _etext = . - __KERNEL_TEXT_OFFSET;
20138+ }
20139+
20140+#ifdef CONFIG_X86_32
20141+ . = ALIGN(PAGE_SIZE);
20142+ .rodata.page_aligned : AT(ADDR(.rodata.page_aligned) - LOAD_OFFSET) {
20143+ *(.idt)
20144+ . = ALIGN(PAGE_SIZE);
20145+ *(.empty_zero_page)
20146+ *(.initial_pg_fixmap)
20147+ *(.initial_pg_pmd)
20148+ *(.initial_page_table)
20149+ *(.swapper_pg_dir)
20150+ } :rodata
20151+#endif
20152+
20153+ . = ALIGN(PAGE_SIZE);
20154+ NOTES :rodata :note
20155+
20156+ EXCEPTION_TABLE(16) :rodata
20157
20158 #if defined(CONFIG_DEBUG_RODATA)
20159 /* .text should occupy whole number of pages */
20160@@ -126,16 +181,20 @@ SECTIONS
20161
20162 /* Data */
20163 .data : AT(ADDR(.data) - LOAD_OFFSET) {
20164+
20165+#ifdef CONFIG_PAX_KERNEXEC
20166+ . = ALIGN(HPAGE_SIZE);
20167+#else
20168+ . = ALIGN(PAGE_SIZE);
20169+#endif
20170+
20171 /* Start of data section */
20172 _sdata = .;
20173
20174 /* init_task */
20175 INIT_TASK_DATA(THREAD_SIZE)
20176
20177-#ifdef CONFIG_X86_32
20178- /* 32 bit has nosave before _edata */
20179 NOSAVE_DATA
20180-#endif
20181
20182 PAGE_ALIGNED_DATA(PAGE_SIZE)
20183
20184@@ -176,12 +235,19 @@ SECTIONS
20185 #endif /* CONFIG_X86_64 */
20186
20187 /* Init code and data - will be freed after init */
20188- . = ALIGN(PAGE_SIZE);
20189 .init.begin : AT(ADDR(.init.begin) - LOAD_OFFSET) {
20190+ BYTE(0)
20191+
20192+#ifdef CONFIG_PAX_KERNEXEC
20193+ . = ALIGN(HPAGE_SIZE);
20194+#else
20195+ . = ALIGN(PAGE_SIZE);
20196+#endif
20197+
20198 __init_begin = .; /* paired with __init_end */
20199- }
20200+ } :init.begin
20201
20202-#if defined(CONFIG_X86_64) && defined(CONFIG_SMP)
20203+#ifdef CONFIG_SMP
20204 /*
20205 * percpu offsets are zero-based on SMP. PERCPU_VADDR() changes the
20206 * output PHDR, so the next output section - .init.text - should
20207@@ -190,12 +256,27 @@ SECTIONS
20208 PERCPU_VADDR(INTERNODE_CACHE_BYTES, 0, :percpu)
20209 #endif
20210
20211- INIT_TEXT_SECTION(PAGE_SIZE)
20212-#ifdef CONFIG_X86_64
20213- :init
20214-#endif
20215+ . = ALIGN(PAGE_SIZE);
20216+ init_begin = .;
20217+ .init.text (. - __KERNEL_TEXT_OFFSET): AT(init_begin - LOAD_OFFSET) {
20218+ VMLINUX_SYMBOL(_sinittext) = .;
20219+ INIT_TEXT
20220+ VMLINUX_SYMBOL(_einittext) = .;
20221+ . = ALIGN(PAGE_SIZE);
20222+ } :text.init
20223
20224- INIT_DATA_SECTION(16)
20225+ /*
20226+ * .exit.text is discard at runtime, not link time, to deal with
20227+ * references from .altinstructions and .eh_frame
20228+ */
20229+ .exit.text : AT(ADDR(.exit.text) - LOAD_OFFSET + __KERNEL_TEXT_OFFSET) {
20230+ EXIT_TEXT
20231+ . = ALIGN(16);
20232+ } :text.exit
20233+ . = init_begin + SIZEOF(.init.text) + SIZEOF(.exit.text);
20234+
20235+ . = ALIGN(PAGE_SIZE);
20236+ INIT_DATA_SECTION(16) :init
20237
20238 .x86_cpu_dev.init : AT(ADDR(.x86_cpu_dev.init) - LOAD_OFFSET) {
20239 __x86_cpu_dev_start = .;
20240@@ -257,19 +338,12 @@ SECTIONS
20241 }
20242
20243 . = ALIGN(8);
20244- /*
20245- * .exit.text is discard at runtime, not link time, to deal with
20246- * references from .altinstructions and .eh_frame
20247- */
20248- .exit.text : AT(ADDR(.exit.text) - LOAD_OFFSET) {
20249- EXIT_TEXT
20250- }
20251
20252 .exit.data : AT(ADDR(.exit.data) - LOAD_OFFSET) {
20253 EXIT_DATA
20254 }
20255
20256-#if !defined(CONFIG_X86_64) || !defined(CONFIG_SMP)
20257+#ifndef CONFIG_SMP
20258 PERCPU_SECTION(INTERNODE_CACHE_BYTES)
20259 #endif
20260
20261@@ -288,16 +362,10 @@ SECTIONS
20262 .smp_locks : AT(ADDR(.smp_locks) - LOAD_OFFSET) {
20263 __smp_locks = .;
20264 *(.smp_locks)
20265- . = ALIGN(PAGE_SIZE);
20266 __smp_locks_end = .;
20267+ . = ALIGN(PAGE_SIZE);
20268 }
20269
20270-#ifdef CONFIG_X86_64
20271- .data_nosave : AT(ADDR(.data_nosave) - LOAD_OFFSET) {
20272- NOSAVE_DATA
20273- }
20274-#endif
20275-
20276 /* BSS */
20277 . = ALIGN(PAGE_SIZE);
20278 .bss : AT(ADDR(.bss) - LOAD_OFFSET) {
20279@@ -313,6 +381,7 @@ SECTIONS
20280 __brk_base = .;
20281 . += 64 * 1024; /* 64k alignment slop space */
20282 *(.brk_reservation) /* areas brk users have reserved */
20283+ . = ALIGN(HPAGE_SIZE);
20284 __brk_limit = .;
20285 }
20286
20287@@ -339,13 +408,12 @@ SECTIONS
20288 * for the boot processor.
20289 */
20290 #define INIT_PER_CPU(x) init_per_cpu__##x = x + __per_cpu_load
20291-INIT_PER_CPU(gdt_page);
20292 INIT_PER_CPU(irq_stack_union);
20293
20294 /*
20295 * Build-time check on the image size:
20296 */
20297-. = ASSERT((_end - _text <= KERNEL_IMAGE_SIZE),
20298+. = ASSERT((_end - _text - __KERNEL_TEXT_OFFSET <= KERNEL_IMAGE_SIZE),
20299 "kernel image bigger than KERNEL_IMAGE_SIZE");
20300
20301 #ifdef CONFIG_SMP
20302diff --git a/arch/x86/kernel/vsmp_64.c b/arch/x86/kernel/vsmp_64.c
20303index 992f890..fc38904 100644
20304--- a/arch/x86/kernel/vsmp_64.c
20305+++ b/arch/x86/kernel/vsmp_64.c
20306@@ -217,8 +217,8 @@ static void fill_vector_allocation_domain(int cpu, struct cpumask *retmask,
20307 static void vsmp_apic_post_init(void)
20308 {
20309 /* need to update phys_pkg_id */
20310- apic->phys_pkg_id = apicid_phys_pkg_id;
20311- apic->vector_allocation_domain = fill_vector_allocation_domain;
20312+ *(void **)&apic->phys_pkg_id = apicid_phys_pkg_id;
20313+ *(void **)&apic->vector_allocation_domain = fill_vector_allocation_domain;
20314 }
20315
20316 void __init vsmp_init(void)
20317diff --git a/arch/x86/kernel/vsyscall_64.c b/arch/x86/kernel/vsyscall_64.c
20318index 8d141b3..40a0fe4 100644
20319--- a/arch/x86/kernel/vsyscall_64.c
20320+++ b/arch/x86/kernel/vsyscall_64.c
20321@@ -56,15 +56,13 @@
20322 DEFINE_VVAR(int, vgetcpu_mode);
20323 DEFINE_VVAR(struct vsyscall_gtod_data, vsyscall_gtod_data);
20324
20325-static enum { EMULATE, NATIVE, NONE } vsyscall_mode = EMULATE;
20326+static enum { EMULATE, NONE } vsyscall_mode = EMULATE;
20327
20328 static int __init vsyscall_setup(char *str)
20329 {
20330 if (str) {
20331 if (!strcmp("emulate", str))
20332 vsyscall_mode = EMULATE;
20333- else if (!strcmp("native", str))
20334- vsyscall_mode = NATIVE;
20335 else if (!strcmp("none", str))
20336 vsyscall_mode = NONE;
20337 else
20338@@ -306,8 +304,7 @@ done:
20339 return true;
20340
20341 sigsegv:
20342- force_sig(SIGSEGV, current);
20343- return true;
20344+ do_group_exit(SIGKILL);
20345 }
20346
20347 /*
20348@@ -360,10 +357,7 @@ void __init map_vsyscall(void)
20349 extern char __vvar_page;
20350 unsigned long physaddr_vvar_page = __pa_symbol(&__vvar_page);
20351
20352- __set_fixmap(VSYSCALL_FIRST_PAGE, physaddr_vsyscall,
20353- vsyscall_mode == NATIVE
20354- ? PAGE_KERNEL_VSYSCALL
20355- : PAGE_KERNEL_VVAR);
20356+ __set_fixmap(VSYSCALL_FIRST_PAGE, physaddr_vsyscall, PAGE_KERNEL_VVAR);
20357 BUILD_BUG_ON((unsigned long)__fix_to_virt(VSYSCALL_FIRST_PAGE) !=
20358 (unsigned long)VSYSCALL_START);
20359
20360diff --git a/arch/x86/kernel/x8664_ksyms_64.c b/arch/x86/kernel/x8664_ksyms_64.c
20361index 6020f6f..bedd6e3 100644
20362--- a/arch/x86/kernel/x8664_ksyms_64.c
20363+++ b/arch/x86/kernel/x8664_ksyms_64.c
20364@@ -30,8 +30,6 @@ EXPORT_SYMBOL(copy_user_generic_string);
20365 EXPORT_SYMBOL(copy_user_generic_unrolled);
20366 EXPORT_SYMBOL(copy_user_enhanced_fast_string);
20367 EXPORT_SYMBOL(__copy_user_nocache);
20368-EXPORT_SYMBOL(_copy_from_user);
20369-EXPORT_SYMBOL(_copy_to_user);
20370
20371 EXPORT_SYMBOL(copy_page);
20372 EXPORT_SYMBOL(clear_page);
20373diff --git a/arch/x86/kernel/xsave.c b/arch/x86/kernel/xsave.c
20374index 3d3e207..316a7e0 100644
20375--- a/arch/x86/kernel/xsave.c
20376+++ b/arch/x86/kernel/xsave.c
20377@@ -132,7 +132,7 @@ int check_for_xstate(struct i387_fxsave_struct __user *buf,
20378 fx_sw_user->xstate_size > fx_sw_user->extended_size)
20379 return -EINVAL;
20380
20381- err = __get_user(magic2, (__u32 *) (((void *)fpstate) +
20382+ err = __get_user(magic2, (__u32 __user *) (((void __user *)fpstate) +
20383 fx_sw_user->extended_size -
20384 FP_XSTATE_MAGIC2_SIZE));
20385 if (err)
20386@@ -268,7 +268,7 @@ fx_only:
20387 * the other extended state.
20388 */
20389 xrstor_state(init_xstate_buf, pcntxt_mask & ~XSTATE_FPSSE);
20390- return fxrstor_checking((__force struct i387_fxsave_struct *)buf);
20391+ return fxrstor_checking((struct i387_fxsave_struct __user *)buf);
20392 }
20393
20394 /*
20395@@ -297,8 +297,7 @@ int restore_i387_xstate(void __user *buf)
20396 if (use_xsave())
20397 err = restore_user_xstate(buf);
20398 else
20399- err = fxrstor_checking((__force struct i387_fxsave_struct *)
20400- buf);
20401+ err = fxrstor_checking((struct i387_fxsave_struct __user *)buf);
20402 if (unlikely(err)) {
20403 /*
20404 * Encountered an error while doing the restore from the
20405diff --git a/arch/x86/kvm/cpuid.c b/arch/x86/kvm/cpuid.c
20406index 0595f13..b544fa3 100644
20407--- a/arch/x86/kvm/cpuid.c
20408+++ b/arch/x86/kvm/cpuid.c
20409@@ -124,15 +124,20 @@ int kvm_vcpu_ioctl_set_cpuid2(struct kvm_vcpu *vcpu,
20410 struct kvm_cpuid2 *cpuid,
20411 struct kvm_cpuid_entry2 __user *entries)
20412 {
20413- int r;
20414+ int r, i;
20415
20416 r = -E2BIG;
20417 if (cpuid->nent > KVM_MAX_CPUID_ENTRIES)
20418 goto out;
20419 r = -EFAULT;
20420- if (copy_from_user(&vcpu->arch.cpuid_entries, entries,
20421- cpuid->nent * sizeof(struct kvm_cpuid_entry2)))
20422+ if (!access_ok(VERIFY_READ, entries, cpuid->nent * sizeof(struct kvm_cpuid_entry2)))
20423 goto out;
20424+ for (i = 0; i < cpuid->nent; ++i) {
20425+ struct kvm_cpuid_entry2 cpuid_entry;
20426+ if (__copy_from_user(&cpuid_entry, entries + i, sizeof(cpuid_entry)))
20427+ goto out;
20428+ vcpu->arch.cpuid_entries[i] = cpuid_entry;
20429+ }
20430 vcpu->arch.cpuid_nent = cpuid->nent;
20431 kvm_apic_set_version(vcpu);
20432 kvm_x86_ops->cpuid_update(vcpu);
20433@@ -147,15 +152,19 @@ int kvm_vcpu_ioctl_get_cpuid2(struct kvm_vcpu *vcpu,
20434 struct kvm_cpuid2 *cpuid,
20435 struct kvm_cpuid_entry2 __user *entries)
20436 {
20437- int r;
20438+ int r, i;
20439
20440 r = -E2BIG;
20441 if (cpuid->nent < vcpu->arch.cpuid_nent)
20442 goto out;
20443 r = -EFAULT;
20444- if (copy_to_user(entries, &vcpu->arch.cpuid_entries,
20445- vcpu->arch.cpuid_nent * sizeof(struct kvm_cpuid_entry2)))
20446+ if (!access_ok(VERIFY_WRITE, entries, vcpu->arch.cpuid_nent * sizeof(struct kvm_cpuid_entry2)))
20447 goto out;
20448+ for (i = 0; i < vcpu->arch.cpuid_nent; ++i) {
20449+ struct kvm_cpuid_entry2 cpuid_entry = vcpu->arch.cpuid_entries[i];
20450+ if (__copy_to_user(entries + i, &cpuid_entry, sizeof(cpuid_entry)))
20451+ goto out;
20452+ }
20453 return 0;
20454
20455 out:
20456diff --git a/arch/x86/kvm/cpuid.h b/arch/x86/kvm/cpuid.h
20457index a10e460..58fc514 100644
20458--- a/arch/x86/kvm/cpuid.h
20459+++ b/arch/x86/kvm/cpuid.h
20460@@ -24,6 +24,9 @@ static inline bool guest_cpuid_has_xsave(struct kvm_vcpu *vcpu)
20461 {
20462 struct kvm_cpuid_entry2 *best;
20463
20464+ if (!static_cpu_has(X86_FEATURE_XSAVE))
20465+ return 0;
20466+
20467 best = kvm_find_cpuid_entry(vcpu, 1, 0);
20468 return best && (best->ecx & bit(X86_FEATURE_XSAVE));
20469 }
20470diff --git a/arch/x86/kvm/emulate.c b/arch/x86/kvm/emulate.c
20471index a3b57a2..ebbe732 100644
20472--- a/arch/x86/kvm/emulate.c
20473+++ b/arch/x86/kvm/emulate.c
20474@@ -256,6 +256,7 @@ struct gprefix {
20475
20476 #define ____emulate_2op(ctxt, _op, _x, _y, _suffix, _dsttype) \
20477 do { \
20478+ unsigned long _tmp; \
20479 __asm__ __volatile__ ( \
20480 _PRE_EFLAGS("0", "4", "2") \
20481 _op _suffix " %"_x"3,%1; " \
20482@@ -270,8 +271,6 @@ struct gprefix {
20483 /* Raw emulation: instruction has two explicit operands. */
20484 #define __emulate_2op_nobyte(ctxt,_op,_wx,_wy,_lx,_ly,_qx,_qy) \
20485 do { \
20486- unsigned long _tmp; \
20487- \
20488 switch ((ctxt)->dst.bytes) { \
20489 case 2: \
20490 ____emulate_2op(ctxt,_op,_wx,_wy,"w",u16); \
20491@@ -287,7 +286,6 @@ struct gprefix {
20492
20493 #define __emulate_2op(ctxt,_op,_bx,_by,_wx,_wy,_lx,_ly,_qx,_qy) \
20494 do { \
20495- unsigned long _tmp; \
20496 switch ((ctxt)->dst.bytes) { \
20497 case 1: \
20498 ____emulate_2op(ctxt,_op,_bx,_by,"b",u8); \
20499diff --git a/arch/x86/kvm/lapic.c b/arch/x86/kvm/lapic.c
20500index ce87878..ab48aa3 100644
20501--- a/arch/x86/kvm/lapic.c
20502+++ b/arch/x86/kvm/lapic.c
20503@@ -54,7 +54,7 @@
20504 #define APIC_BUS_CYCLE_NS 1
20505
20506 /* #define apic_debug(fmt,arg...) printk(KERN_WARNING fmt,##arg) */
20507-#define apic_debug(fmt, arg...)
20508+#define apic_debug(fmt, arg...) do {} while (0)
20509
20510 #define APIC_LVT_NUM 6
20511 /* 14 is the version for Xeon and Pentium 8.4.8*/
20512diff --git a/arch/x86/kvm/paging_tmpl.h b/arch/x86/kvm/paging_tmpl.h
20513index bb7cf01..0348a05 100644
20514--- a/arch/x86/kvm/paging_tmpl.h
20515+++ b/arch/x86/kvm/paging_tmpl.h
20516@@ -196,7 +196,7 @@ retry_walk:
20517 if (unlikely(kvm_is_error_hva(host_addr)))
20518 goto error;
20519
20520- ptep_user = (pt_element_t __user *)((void *)host_addr + offset);
20521+ ptep_user = (pt_element_t __force_user *)((void *)host_addr + offset);
20522 if (unlikely(__copy_from_user(&pte, ptep_user, sizeof(pte))))
20523 goto error;
20524
20525diff --git a/arch/x86/kvm/svm.c b/arch/x86/kvm/svm.c
20526index baead95..90feeb4 100644
20527--- a/arch/x86/kvm/svm.c
20528+++ b/arch/x86/kvm/svm.c
20529@@ -3516,7 +3516,11 @@ static void reload_tss(struct kvm_vcpu *vcpu)
20530 int cpu = raw_smp_processor_id();
20531
20532 struct svm_cpu_data *sd = per_cpu(svm_data, cpu);
20533+
20534+ pax_open_kernel();
20535 sd->tss_desc->type = 9; /* available 32/64-bit TSS */
20536+ pax_close_kernel();
20537+
20538 load_TR_desc();
20539 }
20540
20541@@ -3894,6 +3898,10 @@ static void svm_vcpu_run(struct kvm_vcpu *vcpu)
20542 #endif
20543 #endif
20544
20545+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
20546+ __set_fs(current_thread_info()->addr_limit);
20547+#endif
20548+
20549 reload_tss(vcpu);
20550
20551 local_irq_disable();
20552diff --git a/arch/x86/kvm/vmx.c b/arch/x86/kvm/vmx.c
20553index ff66a3b..48ad872 100644
20554--- a/arch/x86/kvm/vmx.c
20555+++ b/arch/x86/kvm/vmx.c
20556@@ -1331,7 +1331,11 @@ static void reload_tss(void)
20557 struct desc_struct *descs;
20558
20559 descs = (void *)gdt->address;
20560+
20561+ pax_open_kernel();
20562 descs[GDT_ENTRY_TSS].type = 9; /* available TSS */
20563+ pax_close_kernel();
20564+
20565 load_TR_desc();
20566 }
20567
20568@@ -1541,6 +1545,10 @@ static void vmx_vcpu_load(struct kvm_vcpu *vcpu, int cpu)
20569 vmcs_writel(HOST_TR_BASE, kvm_read_tr_base()); /* 22.2.4 */
20570 vmcs_writel(HOST_GDTR_BASE, gdt->address); /* 22.2.4 */
20571
20572+#ifdef CONFIG_PAX_PER_CPU_PGD
20573+ vmcs_writel(HOST_CR3, read_cr3()); /* 22.2.3 FIXME: shadow tables */
20574+#endif
20575+
20576 rdmsrl(MSR_IA32_SYSENTER_ESP, sysenter_esp);
20577 vmcs_writel(HOST_IA32_SYSENTER_ESP, sysenter_esp); /* 22.2.3 */
20578 vmx->loaded_vmcs->cpu = cpu;
20579@@ -2674,8 +2682,11 @@ static __init int hardware_setup(void)
20580 if (!cpu_has_vmx_flexpriority())
20581 flexpriority_enabled = 0;
20582
20583- if (!cpu_has_vmx_tpr_shadow())
20584- kvm_x86_ops->update_cr8_intercept = NULL;
20585+ if (!cpu_has_vmx_tpr_shadow()) {
20586+ pax_open_kernel();
20587+ *(void **)&kvm_x86_ops->update_cr8_intercept = NULL;
20588+ pax_close_kernel();
20589+ }
20590
20591 if (enable_ept && !cpu_has_vmx_ept_2m_page())
20592 kvm_disable_largepages();
20593@@ -3745,7 +3756,10 @@ static void vmx_set_constant_host_state(void)
20594
20595 vmcs_writel(HOST_CR0, read_cr0() | X86_CR0_TS); /* 22.2.3 */
20596 vmcs_writel(HOST_CR4, read_cr4()); /* 22.2.3, 22.2.5 */
20597+
20598+#ifndef CONFIG_PAX_PER_CPU_PGD
20599 vmcs_writel(HOST_CR3, read_cr3()); /* 22.2.3 FIXME: shadow tables */
20600+#endif
20601
20602 vmcs_write16(HOST_CS_SELECTOR, __KERNEL_CS); /* 22.2.4 */
20603 #ifdef CONFIG_X86_64
20604@@ -3767,7 +3781,7 @@ static void vmx_set_constant_host_state(void)
20605 vmcs_writel(HOST_IDTR_BASE, dt.address); /* 22.2.4 */
20606
20607 asm("mov $.Lkvm_vmx_return, %0" : "=r"(tmpl));
20608- vmcs_writel(HOST_RIP, tmpl); /* 22.2.5 */
20609+ vmcs_writel(HOST_RIP, ktla_ktva(tmpl)); /* 22.2.5 */
20610
20611 rdmsr(MSR_IA32_SYSENTER_CS, low32, high32);
20612 vmcs_write32(HOST_IA32_SYSENTER_CS, low32);
20613@@ -6321,6 +6335,12 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
20614 "jmp .Lkvm_vmx_return \n\t"
20615 ".Llaunched: " __ex(ASM_VMX_VMRESUME) "\n\t"
20616 ".Lkvm_vmx_return: "
20617+
20618+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
20619+ "ljmp %[cs],$.Lkvm_vmx_return2\n\t"
20620+ ".Lkvm_vmx_return2: "
20621+#endif
20622+
20623 /* Save guest registers, load host registers, keep flags */
20624 "mov %0, %c[wordsize](%%"R"sp) \n\t"
20625 "pop %0 \n\t"
20626@@ -6369,6 +6389,11 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
20627 #endif
20628 [cr2]"i"(offsetof(struct vcpu_vmx, vcpu.arch.cr2)),
20629 [wordsize]"i"(sizeof(ulong))
20630+
20631+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
20632+ ,[cs]"i"(__KERNEL_CS)
20633+#endif
20634+
20635 : "cc", "memory"
20636 , R"ax", R"bx", R"di", R"si"
20637 #ifdef CONFIG_X86_64
20638@@ -6376,7 +6401,7 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
20639 #endif
20640 );
20641
20642-#ifndef CONFIG_X86_64
20643+#ifdef CONFIG_X86_32
20644 /*
20645 * The sysexit path does not restore ds/es, so we must set them to
20646 * a reasonable value ourselves.
20647@@ -6385,8 +6410,18 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
20648 * may be executed in interrupt context, which saves and restore segments
20649 * around it, nullifying its effect.
20650 */
20651- loadsegment(ds, __USER_DS);
20652- loadsegment(es, __USER_DS);
20653+ loadsegment(ds, __KERNEL_DS);
20654+ loadsegment(es, __KERNEL_DS);
20655+ loadsegment(ss, __KERNEL_DS);
20656+
20657+#ifdef CONFIG_PAX_KERNEXEC
20658+ loadsegment(fs, __KERNEL_PERCPU);
20659+#endif
20660+
20661+#ifdef CONFIG_PAX_MEMORY_UDEREF
20662+ __set_fs(current_thread_info()->addr_limit);
20663+#endif
20664+
20665 #endif
20666
20667 vcpu->arch.regs_avail = ~((1 << VCPU_REGS_RIP) | (1 << VCPU_REGS_RSP)
20668diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
20669index 2966c84..9ac0c3c 100644
20670--- a/arch/x86/kvm/x86.c
20671+++ b/arch/x86/kvm/x86.c
20672@@ -1379,8 +1379,8 @@ static int xen_hvm_config(struct kvm_vcpu *vcpu, u64 data)
20673 {
20674 struct kvm *kvm = vcpu->kvm;
20675 int lm = is_long_mode(vcpu);
20676- u8 *blob_addr = lm ? (u8 *)(long)kvm->arch.xen_hvm_config.blob_addr_64
20677- : (u8 *)(long)kvm->arch.xen_hvm_config.blob_addr_32;
20678+ u8 __user *blob_addr = lm ? (u8 __user *)(long)kvm->arch.xen_hvm_config.blob_addr_64
20679+ : (u8 __user *)(long)kvm->arch.xen_hvm_config.blob_addr_32;
20680 u8 blob_size = lm ? kvm->arch.xen_hvm_config.blob_size_64
20681 : kvm->arch.xen_hvm_config.blob_size_32;
20682 u32 page_num = data & ~PAGE_MASK;
20683@@ -2243,6 +2243,8 @@ long kvm_arch_dev_ioctl(struct file *filp,
20684 if (n < msr_list.nmsrs)
20685 goto out;
20686 r = -EFAULT;
20687+ if (num_msrs_to_save > ARRAY_SIZE(msrs_to_save))
20688+ goto out;
20689 if (copy_to_user(user_msr_list->indices, &msrs_to_save,
20690 num_msrs_to_save * sizeof(u32)))
20691 goto out;
20692@@ -2368,7 +2370,7 @@ static int kvm_vcpu_ioctl_set_lapic(struct kvm_vcpu *vcpu,
20693 static int kvm_vcpu_ioctl_interrupt(struct kvm_vcpu *vcpu,
20694 struct kvm_interrupt *irq)
20695 {
20696- if (irq->irq < 0 || irq->irq >= 256)
20697+ if (irq->irq >= 256)
20698 return -EINVAL;
20699 if (irqchip_in_kernel(vcpu->kvm))
20700 return -ENXIO;
20701@@ -4889,7 +4891,7 @@ static void kvm_set_mmio_spte_mask(void)
20702 kvm_mmu_set_mmio_spte_mask(mask);
20703 }
20704
20705-int kvm_arch_init(void *opaque)
20706+int kvm_arch_init(const void *opaque)
20707 {
20708 int r;
20709 struct kvm_x86_ops *ops = (struct kvm_x86_ops *)opaque;
20710@@ -5762,6 +5764,9 @@ int kvm_arch_vcpu_ioctl_set_sregs(struct kvm_vcpu *vcpu,
20711 int pending_vec, max_bits, idx;
20712 struct desc_ptr dt;
20713
20714+ if (!guest_cpuid_has_xsave(vcpu) && (sregs->cr4 & X86_CR4_OSXSAVE))
20715+ return -EINVAL;
20716+
20717 dt.size = sregs->idt.limit;
20718 dt.address = sregs->idt.base;
20719 kvm_x86_ops->set_idt(vcpu, &dt);
20720diff --git a/arch/x86/lguest/boot.c b/arch/x86/lguest/boot.c
20721index 642d880..cc9ebac 100644
20722--- a/arch/x86/lguest/boot.c
20723+++ b/arch/x86/lguest/boot.c
20724@@ -1116,12 +1116,12 @@ static u32 lguest_apic_safe_wait_icr_idle(void)
20725
20726 static void set_lguest_basic_apic_ops(void)
20727 {
20728- apic->read = lguest_apic_read;
20729- apic->write = lguest_apic_write;
20730- apic->icr_read = lguest_apic_icr_read;
20731- apic->icr_write = lguest_apic_icr_write;
20732- apic->wait_icr_idle = lguest_apic_wait_icr_idle;
20733- apic->safe_wait_icr_idle = lguest_apic_safe_wait_icr_idle;
20734+ *(void **)&apic->read = lguest_apic_read;
20735+ *(void **)&apic->write = lguest_apic_write;
20736+ *(void **)&apic->icr_read = lguest_apic_icr_read;
20737+ *(void **)&apic->icr_write = lguest_apic_icr_write;
20738+ *(void **)&apic->wait_icr_idle = lguest_apic_wait_icr_idle;
20739+ *(void **)&apic->safe_wait_icr_idle = lguest_apic_safe_wait_icr_idle;
20740 };
20741 #endif
20742
20743@@ -1200,9 +1200,10 @@ static __init int early_put_chars(u32 vtermno, const char *buf, int count)
20744 * Rebooting also tells the Host we're finished, but the RESTART flag tells the
20745 * Launcher to reboot us.
20746 */
20747-static void lguest_restart(char *reason)
20748+static __noreturn void lguest_restart(char *reason)
20749 {
20750 hcall(LHCALL_SHUTDOWN, __pa(reason), LGUEST_SHUTDOWN_RESTART, 0, 0);
20751+ BUG();
20752 }
20753
20754 /*G:050
20755diff --git a/arch/x86/lib/atomic64_386_32.S b/arch/x86/lib/atomic64_386_32.S
20756index 00933d5..3a64af9 100644
20757--- a/arch/x86/lib/atomic64_386_32.S
20758+++ b/arch/x86/lib/atomic64_386_32.S
20759@@ -48,6 +48,10 @@ BEGIN(read)
20760 movl (v), %eax
20761 movl 4(v), %edx
20762 RET_ENDP
20763+BEGIN(read_unchecked)
20764+ movl (v), %eax
20765+ movl 4(v), %edx
20766+RET_ENDP
20767 #undef v
20768
20769 #define v %esi
20770@@ -55,6 +59,10 @@ BEGIN(set)
20771 movl %ebx, (v)
20772 movl %ecx, 4(v)
20773 RET_ENDP
20774+BEGIN(set_unchecked)
20775+ movl %ebx, (v)
20776+ movl %ecx, 4(v)
20777+RET_ENDP
20778 #undef v
20779
20780 #define v %esi
20781@@ -70,6 +78,20 @@ RET_ENDP
20782 BEGIN(add)
20783 addl %eax, (v)
20784 adcl %edx, 4(v)
20785+
20786+#ifdef CONFIG_PAX_REFCOUNT
20787+ jno 0f
20788+ subl %eax, (v)
20789+ sbbl %edx, 4(v)
20790+ int $4
20791+0:
20792+ _ASM_EXTABLE(0b, 0b)
20793+#endif
20794+
20795+RET_ENDP
20796+BEGIN(add_unchecked)
20797+ addl %eax, (v)
20798+ adcl %edx, 4(v)
20799 RET_ENDP
20800 #undef v
20801
20802@@ -77,6 +99,24 @@ RET_ENDP
20803 BEGIN(add_return)
20804 addl (v), %eax
20805 adcl 4(v), %edx
20806+
20807+#ifdef CONFIG_PAX_REFCOUNT
20808+ into
20809+1234:
20810+ _ASM_EXTABLE(1234b, 2f)
20811+#endif
20812+
20813+ movl %eax, (v)
20814+ movl %edx, 4(v)
20815+
20816+#ifdef CONFIG_PAX_REFCOUNT
20817+2:
20818+#endif
20819+
20820+RET_ENDP
20821+BEGIN(add_return_unchecked)
20822+ addl (v), %eax
20823+ adcl 4(v), %edx
20824 movl %eax, (v)
20825 movl %edx, 4(v)
20826 RET_ENDP
20827@@ -86,6 +126,20 @@ RET_ENDP
20828 BEGIN(sub)
20829 subl %eax, (v)
20830 sbbl %edx, 4(v)
20831+
20832+#ifdef CONFIG_PAX_REFCOUNT
20833+ jno 0f
20834+ addl %eax, (v)
20835+ adcl %edx, 4(v)
20836+ int $4
20837+0:
20838+ _ASM_EXTABLE(0b, 0b)
20839+#endif
20840+
20841+RET_ENDP
20842+BEGIN(sub_unchecked)
20843+ subl %eax, (v)
20844+ sbbl %edx, 4(v)
20845 RET_ENDP
20846 #undef v
20847
20848@@ -96,6 +150,27 @@ BEGIN(sub_return)
20849 sbbl $0, %edx
20850 addl (v), %eax
20851 adcl 4(v), %edx
20852+
20853+#ifdef CONFIG_PAX_REFCOUNT
20854+ into
20855+1234:
20856+ _ASM_EXTABLE(1234b, 2f)
20857+#endif
20858+
20859+ movl %eax, (v)
20860+ movl %edx, 4(v)
20861+
20862+#ifdef CONFIG_PAX_REFCOUNT
20863+2:
20864+#endif
20865+
20866+RET_ENDP
20867+BEGIN(sub_return_unchecked)
20868+ negl %edx
20869+ negl %eax
20870+ sbbl $0, %edx
20871+ addl (v), %eax
20872+ adcl 4(v), %edx
20873 movl %eax, (v)
20874 movl %edx, 4(v)
20875 RET_ENDP
20876@@ -105,6 +180,20 @@ RET_ENDP
20877 BEGIN(inc)
20878 addl $1, (v)
20879 adcl $0, 4(v)
20880+
20881+#ifdef CONFIG_PAX_REFCOUNT
20882+ jno 0f
20883+ subl $1, (v)
20884+ sbbl $0, 4(v)
20885+ int $4
20886+0:
20887+ _ASM_EXTABLE(0b, 0b)
20888+#endif
20889+
20890+RET_ENDP
20891+BEGIN(inc_unchecked)
20892+ addl $1, (v)
20893+ adcl $0, 4(v)
20894 RET_ENDP
20895 #undef v
20896
20897@@ -114,6 +203,26 @@ BEGIN(inc_return)
20898 movl 4(v), %edx
20899 addl $1, %eax
20900 adcl $0, %edx
20901+
20902+#ifdef CONFIG_PAX_REFCOUNT
20903+ into
20904+1234:
20905+ _ASM_EXTABLE(1234b, 2f)
20906+#endif
20907+
20908+ movl %eax, (v)
20909+ movl %edx, 4(v)
20910+
20911+#ifdef CONFIG_PAX_REFCOUNT
20912+2:
20913+#endif
20914+
20915+RET_ENDP
20916+BEGIN(inc_return_unchecked)
20917+ movl (v), %eax
20918+ movl 4(v), %edx
20919+ addl $1, %eax
20920+ adcl $0, %edx
20921 movl %eax, (v)
20922 movl %edx, 4(v)
20923 RET_ENDP
20924@@ -123,6 +232,20 @@ RET_ENDP
20925 BEGIN(dec)
20926 subl $1, (v)
20927 sbbl $0, 4(v)
20928+
20929+#ifdef CONFIG_PAX_REFCOUNT
20930+ jno 0f
20931+ addl $1, (v)
20932+ adcl $0, 4(v)
20933+ int $4
20934+0:
20935+ _ASM_EXTABLE(0b, 0b)
20936+#endif
20937+
20938+RET_ENDP
20939+BEGIN(dec_unchecked)
20940+ subl $1, (v)
20941+ sbbl $0, 4(v)
20942 RET_ENDP
20943 #undef v
20944
20945@@ -132,6 +255,26 @@ BEGIN(dec_return)
20946 movl 4(v), %edx
20947 subl $1, %eax
20948 sbbl $0, %edx
20949+
20950+#ifdef CONFIG_PAX_REFCOUNT
20951+ into
20952+1234:
20953+ _ASM_EXTABLE(1234b, 2f)
20954+#endif
20955+
20956+ movl %eax, (v)
20957+ movl %edx, 4(v)
20958+
20959+#ifdef CONFIG_PAX_REFCOUNT
20960+2:
20961+#endif
20962+
20963+RET_ENDP
20964+BEGIN(dec_return_unchecked)
20965+ movl (v), %eax
20966+ movl 4(v), %edx
20967+ subl $1, %eax
20968+ sbbl $0, %edx
20969 movl %eax, (v)
20970 movl %edx, 4(v)
20971 RET_ENDP
20972@@ -143,6 +286,13 @@ BEGIN(add_unless)
20973 adcl %edx, %edi
20974 addl (v), %eax
20975 adcl 4(v), %edx
20976+
20977+#ifdef CONFIG_PAX_REFCOUNT
20978+ into
20979+1234:
20980+ _ASM_EXTABLE(1234b, 2f)
20981+#endif
20982+
20983 cmpl %eax, %ecx
20984 je 3f
20985 1:
20986@@ -168,6 +318,13 @@ BEGIN(inc_not_zero)
20987 1:
20988 addl $1, %eax
20989 adcl $0, %edx
20990+
20991+#ifdef CONFIG_PAX_REFCOUNT
20992+ into
20993+1234:
20994+ _ASM_EXTABLE(1234b, 2f)
20995+#endif
20996+
20997 movl %eax, (v)
20998 movl %edx, 4(v)
20999 movl $1, %eax
21000@@ -186,6 +343,13 @@ BEGIN(dec_if_positive)
21001 movl 4(v), %edx
21002 subl $1, %eax
21003 sbbl $0, %edx
21004+
21005+#ifdef CONFIG_PAX_REFCOUNT
21006+ into
21007+1234:
21008+ _ASM_EXTABLE(1234b, 1f)
21009+#endif
21010+
21011 js 1f
21012 movl %eax, (v)
21013 movl %edx, 4(v)
21014diff --git a/arch/x86/lib/atomic64_cx8_32.S b/arch/x86/lib/atomic64_cx8_32.S
21015index f5cc9eb..51fa319 100644
21016--- a/arch/x86/lib/atomic64_cx8_32.S
21017+++ b/arch/x86/lib/atomic64_cx8_32.S
21018@@ -35,10 +35,20 @@ ENTRY(atomic64_read_cx8)
21019 CFI_STARTPROC
21020
21021 read64 %ecx
21022+ pax_force_retaddr
21023 ret
21024 CFI_ENDPROC
21025 ENDPROC(atomic64_read_cx8)
21026
21027+ENTRY(atomic64_read_unchecked_cx8)
21028+ CFI_STARTPROC
21029+
21030+ read64 %ecx
21031+ pax_force_retaddr
21032+ ret
21033+ CFI_ENDPROC
21034+ENDPROC(atomic64_read_unchecked_cx8)
21035+
21036 ENTRY(atomic64_set_cx8)
21037 CFI_STARTPROC
21038
21039@@ -48,10 +58,25 @@ ENTRY(atomic64_set_cx8)
21040 cmpxchg8b (%esi)
21041 jne 1b
21042
21043+ pax_force_retaddr
21044 ret
21045 CFI_ENDPROC
21046 ENDPROC(atomic64_set_cx8)
21047
21048+ENTRY(atomic64_set_unchecked_cx8)
21049+ CFI_STARTPROC
21050+
21051+1:
21052+/* we don't need LOCK_PREFIX since aligned 64-bit writes
21053+ * are atomic on 586 and newer */
21054+ cmpxchg8b (%esi)
21055+ jne 1b
21056+
21057+ pax_force_retaddr
21058+ ret
21059+ CFI_ENDPROC
21060+ENDPROC(atomic64_set_unchecked_cx8)
21061+
21062 ENTRY(atomic64_xchg_cx8)
21063 CFI_STARTPROC
21064
21065@@ -60,12 +85,13 @@ ENTRY(atomic64_xchg_cx8)
21066 cmpxchg8b (%esi)
21067 jne 1b
21068
21069+ pax_force_retaddr
21070 ret
21071 CFI_ENDPROC
21072 ENDPROC(atomic64_xchg_cx8)
21073
21074-.macro addsub_return func ins insc
21075-ENTRY(atomic64_\func\()_return_cx8)
21076+.macro addsub_return func ins insc unchecked=""
21077+ENTRY(atomic64_\func\()_return\unchecked\()_cx8)
21078 CFI_STARTPROC
21079 SAVE ebp
21080 SAVE ebx
21081@@ -82,27 +108,44 @@ ENTRY(atomic64_\func\()_return_cx8)
21082 movl %edx, %ecx
21083 \ins\()l %esi, %ebx
21084 \insc\()l %edi, %ecx
21085+
21086+.ifb \unchecked
21087+#ifdef CONFIG_PAX_REFCOUNT
21088+ into
21089+2:
21090+ _ASM_EXTABLE(2b, 3f)
21091+#endif
21092+.endif
21093+
21094 LOCK_PREFIX
21095 cmpxchg8b (%ebp)
21096 jne 1b
21097-
21098-10:
21099 movl %ebx, %eax
21100 movl %ecx, %edx
21101+
21102+.ifb \unchecked
21103+#ifdef CONFIG_PAX_REFCOUNT
21104+3:
21105+#endif
21106+.endif
21107+
21108 RESTORE edi
21109 RESTORE esi
21110 RESTORE ebx
21111 RESTORE ebp
21112+ pax_force_retaddr
21113 ret
21114 CFI_ENDPROC
21115-ENDPROC(atomic64_\func\()_return_cx8)
21116+ENDPROC(atomic64_\func\()_return\unchecked\()_cx8)
21117 .endm
21118
21119 addsub_return add add adc
21120 addsub_return sub sub sbb
21121+addsub_return add add adc _unchecked
21122+addsub_return sub sub sbb _unchecked
21123
21124-.macro incdec_return func ins insc
21125-ENTRY(atomic64_\func\()_return_cx8)
21126+.macro incdec_return func ins insc unchecked=""
21127+ENTRY(atomic64_\func\()_return\unchecked\()_cx8)
21128 CFI_STARTPROC
21129 SAVE ebx
21130
21131@@ -112,21 +155,39 @@ ENTRY(atomic64_\func\()_return_cx8)
21132 movl %edx, %ecx
21133 \ins\()l $1, %ebx
21134 \insc\()l $0, %ecx
21135+
21136+.ifb \unchecked
21137+#ifdef CONFIG_PAX_REFCOUNT
21138+ into
21139+2:
21140+ _ASM_EXTABLE(2b, 3f)
21141+#endif
21142+.endif
21143+
21144 LOCK_PREFIX
21145 cmpxchg8b (%esi)
21146 jne 1b
21147
21148-10:
21149 movl %ebx, %eax
21150 movl %ecx, %edx
21151+
21152+.ifb \unchecked
21153+#ifdef CONFIG_PAX_REFCOUNT
21154+3:
21155+#endif
21156+.endif
21157+
21158 RESTORE ebx
21159+ pax_force_retaddr
21160 ret
21161 CFI_ENDPROC
21162-ENDPROC(atomic64_\func\()_return_cx8)
21163+ENDPROC(atomic64_\func\()_return\unchecked\()_cx8)
21164 .endm
21165
21166 incdec_return inc add adc
21167 incdec_return dec sub sbb
21168+incdec_return inc add adc _unchecked
21169+incdec_return dec sub sbb _unchecked
21170
21171 ENTRY(atomic64_dec_if_positive_cx8)
21172 CFI_STARTPROC
21173@@ -138,6 +199,13 @@ ENTRY(atomic64_dec_if_positive_cx8)
21174 movl %edx, %ecx
21175 subl $1, %ebx
21176 sbb $0, %ecx
21177+
21178+#ifdef CONFIG_PAX_REFCOUNT
21179+ into
21180+1234:
21181+ _ASM_EXTABLE(1234b, 2f)
21182+#endif
21183+
21184 js 2f
21185 LOCK_PREFIX
21186 cmpxchg8b (%esi)
21187@@ -147,6 +215,7 @@ ENTRY(atomic64_dec_if_positive_cx8)
21188 movl %ebx, %eax
21189 movl %ecx, %edx
21190 RESTORE ebx
21191+ pax_force_retaddr
21192 ret
21193 CFI_ENDPROC
21194 ENDPROC(atomic64_dec_if_positive_cx8)
21195@@ -171,6 +240,13 @@ ENTRY(atomic64_add_unless_cx8)
21196 movl %edx, %ecx
21197 addl %ebp, %ebx
21198 adcl %edi, %ecx
21199+
21200+#ifdef CONFIG_PAX_REFCOUNT
21201+ into
21202+1234:
21203+ _ASM_EXTABLE(1234b, 3f)
21204+#endif
21205+
21206 LOCK_PREFIX
21207 cmpxchg8b (%esi)
21208 jne 1b
21209@@ -181,6 +257,7 @@ ENTRY(atomic64_add_unless_cx8)
21210 CFI_ADJUST_CFA_OFFSET -8
21211 RESTORE ebx
21212 RESTORE ebp
21213+ pax_force_retaddr
21214 ret
21215 4:
21216 cmpl %edx, 4(%esp)
21217@@ -203,6 +280,13 @@ ENTRY(atomic64_inc_not_zero_cx8)
21218 xorl %ecx, %ecx
21219 addl $1, %ebx
21220 adcl %edx, %ecx
21221+
21222+#ifdef CONFIG_PAX_REFCOUNT
21223+ into
21224+1234:
21225+ _ASM_EXTABLE(1234b, 3f)
21226+#endif
21227+
21228 LOCK_PREFIX
21229 cmpxchg8b (%esi)
21230 jne 1b
21231@@ -210,6 +294,7 @@ ENTRY(atomic64_inc_not_zero_cx8)
21232 movl $1, %eax
21233 3:
21234 RESTORE ebx
21235+ pax_force_retaddr
21236 ret
21237 CFI_ENDPROC
21238 ENDPROC(atomic64_inc_not_zero_cx8)
21239diff --git a/arch/x86/lib/checksum_32.S b/arch/x86/lib/checksum_32.S
21240index 2af5df3..62b1a5a 100644
21241--- a/arch/x86/lib/checksum_32.S
21242+++ b/arch/x86/lib/checksum_32.S
21243@@ -29,7 +29,8 @@
21244 #include <asm/dwarf2.h>
21245 #include <asm/errno.h>
21246 #include <asm/asm.h>
21247-
21248+#include <asm/segment.h>
21249+
21250 /*
21251 * computes a partial checksum, e.g. for TCP/UDP fragments
21252 */
21253@@ -293,9 +294,24 @@ unsigned int csum_partial_copy_generic (const char *src, char *dst,
21254
21255 #define ARGBASE 16
21256 #define FP 12
21257-
21258-ENTRY(csum_partial_copy_generic)
21259+
21260+ENTRY(csum_partial_copy_generic_to_user)
21261 CFI_STARTPROC
21262+
21263+#ifdef CONFIG_PAX_MEMORY_UDEREF
21264+ pushl_cfi %gs
21265+ popl_cfi %es
21266+ jmp csum_partial_copy_generic
21267+#endif
21268+
21269+ENTRY(csum_partial_copy_generic_from_user)
21270+
21271+#ifdef CONFIG_PAX_MEMORY_UDEREF
21272+ pushl_cfi %gs
21273+ popl_cfi %ds
21274+#endif
21275+
21276+ENTRY(csum_partial_copy_generic)
21277 subl $4,%esp
21278 CFI_ADJUST_CFA_OFFSET 4
21279 pushl_cfi %edi
21280@@ -317,7 +333,7 @@ ENTRY(csum_partial_copy_generic)
21281 jmp 4f
21282 SRC(1: movw (%esi), %bx )
21283 addl $2, %esi
21284-DST( movw %bx, (%edi) )
21285+DST( movw %bx, %es:(%edi) )
21286 addl $2, %edi
21287 addw %bx, %ax
21288 adcl $0, %eax
21289@@ -329,30 +345,30 @@ DST( movw %bx, (%edi) )
21290 SRC(1: movl (%esi), %ebx )
21291 SRC( movl 4(%esi), %edx )
21292 adcl %ebx, %eax
21293-DST( movl %ebx, (%edi) )
21294+DST( movl %ebx, %es:(%edi) )
21295 adcl %edx, %eax
21296-DST( movl %edx, 4(%edi) )
21297+DST( movl %edx, %es:4(%edi) )
21298
21299 SRC( movl 8(%esi), %ebx )
21300 SRC( movl 12(%esi), %edx )
21301 adcl %ebx, %eax
21302-DST( movl %ebx, 8(%edi) )
21303+DST( movl %ebx, %es:8(%edi) )
21304 adcl %edx, %eax
21305-DST( movl %edx, 12(%edi) )
21306+DST( movl %edx, %es:12(%edi) )
21307
21308 SRC( movl 16(%esi), %ebx )
21309 SRC( movl 20(%esi), %edx )
21310 adcl %ebx, %eax
21311-DST( movl %ebx, 16(%edi) )
21312+DST( movl %ebx, %es:16(%edi) )
21313 adcl %edx, %eax
21314-DST( movl %edx, 20(%edi) )
21315+DST( movl %edx, %es:20(%edi) )
21316
21317 SRC( movl 24(%esi), %ebx )
21318 SRC( movl 28(%esi), %edx )
21319 adcl %ebx, %eax
21320-DST( movl %ebx, 24(%edi) )
21321+DST( movl %ebx, %es:24(%edi) )
21322 adcl %edx, %eax
21323-DST( movl %edx, 28(%edi) )
21324+DST( movl %edx, %es:28(%edi) )
21325
21326 lea 32(%esi), %esi
21327 lea 32(%edi), %edi
21328@@ -366,7 +382,7 @@ DST( movl %edx, 28(%edi) )
21329 shrl $2, %edx # This clears CF
21330 SRC(3: movl (%esi), %ebx )
21331 adcl %ebx, %eax
21332-DST( movl %ebx, (%edi) )
21333+DST( movl %ebx, %es:(%edi) )
21334 lea 4(%esi), %esi
21335 lea 4(%edi), %edi
21336 dec %edx
21337@@ -378,12 +394,12 @@ DST( movl %ebx, (%edi) )
21338 jb 5f
21339 SRC( movw (%esi), %cx )
21340 leal 2(%esi), %esi
21341-DST( movw %cx, (%edi) )
21342+DST( movw %cx, %es:(%edi) )
21343 leal 2(%edi), %edi
21344 je 6f
21345 shll $16,%ecx
21346 SRC(5: movb (%esi), %cl )
21347-DST( movb %cl, (%edi) )
21348+DST( movb %cl, %es:(%edi) )
21349 6: addl %ecx, %eax
21350 adcl $0, %eax
21351 7:
21352@@ -394,7 +410,7 @@ DST( movb %cl, (%edi) )
21353
21354 6001:
21355 movl ARGBASE+20(%esp), %ebx # src_err_ptr
21356- movl $-EFAULT, (%ebx)
21357+ movl $-EFAULT, %ss:(%ebx)
21358
21359 # zero the complete destination - computing the rest
21360 # is too much work
21361@@ -407,11 +423,15 @@ DST( movb %cl, (%edi) )
21362
21363 6002:
21364 movl ARGBASE+24(%esp), %ebx # dst_err_ptr
21365- movl $-EFAULT,(%ebx)
21366+ movl $-EFAULT,%ss:(%ebx)
21367 jmp 5000b
21368
21369 .previous
21370
21371+ pushl_cfi %ss
21372+ popl_cfi %ds
21373+ pushl_cfi %ss
21374+ popl_cfi %es
21375 popl_cfi %ebx
21376 CFI_RESTORE ebx
21377 popl_cfi %esi
21378@@ -421,26 +441,43 @@ DST( movb %cl, (%edi) )
21379 popl_cfi %ecx # equivalent to addl $4,%esp
21380 ret
21381 CFI_ENDPROC
21382-ENDPROC(csum_partial_copy_generic)
21383+ENDPROC(csum_partial_copy_generic_to_user)
21384
21385 #else
21386
21387 /* Version for PentiumII/PPro */
21388
21389 #define ROUND1(x) \
21390+ nop; nop; nop; \
21391 SRC(movl x(%esi), %ebx ) ; \
21392 addl %ebx, %eax ; \
21393- DST(movl %ebx, x(%edi) ) ;
21394+ DST(movl %ebx, %es:x(%edi)) ;
21395
21396 #define ROUND(x) \
21397+ nop; nop; nop; \
21398 SRC(movl x(%esi), %ebx ) ; \
21399 adcl %ebx, %eax ; \
21400- DST(movl %ebx, x(%edi) ) ;
21401+ DST(movl %ebx, %es:x(%edi)) ;
21402
21403 #define ARGBASE 12
21404-
21405-ENTRY(csum_partial_copy_generic)
21406+
21407+ENTRY(csum_partial_copy_generic_to_user)
21408 CFI_STARTPROC
21409+
21410+#ifdef CONFIG_PAX_MEMORY_UDEREF
21411+ pushl_cfi %gs
21412+ popl_cfi %es
21413+ jmp csum_partial_copy_generic
21414+#endif
21415+
21416+ENTRY(csum_partial_copy_generic_from_user)
21417+
21418+#ifdef CONFIG_PAX_MEMORY_UDEREF
21419+ pushl_cfi %gs
21420+ popl_cfi %ds
21421+#endif
21422+
21423+ENTRY(csum_partial_copy_generic)
21424 pushl_cfi %ebx
21425 CFI_REL_OFFSET ebx, 0
21426 pushl_cfi %edi
21427@@ -461,7 +498,7 @@ ENTRY(csum_partial_copy_generic)
21428 subl %ebx, %edi
21429 lea -1(%esi),%edx
21430 andl $-32,%edx
21431- lea 3f(%ebx,%ebx), %ebx
21432+ lea 3f(%ebx,%ebx,2), %ebx
21433 testl %esi, %esi
21434 jmp *%ebx
21435 1: addl $64,%esi
21436@@ -482,19 +519,19 @@ ENTRY(csum_partial_copy_generic)
21437 jb 5f
21438 SRC( movw (%esi), %dx )
21439 leal 2(%esi), %esi
21440-DST( movw %dx, (%edi) )
21441+DST( movw %dx, %es:(%edi) )
21442 leal 2(%edi), %edi
21443 je 6f
21444 shll $16,%edx
21445 5:
21446 SRC( movb (%esi), %dl )
21447-DST( movb %dl, (%edi) )
21448+DST( movb %dl, %es:(%edi) )
21449 6: addl %edx, %eax
21450 adcl $0, %eax
21451 7:
21452 .section .fixup, "ax"
21453 6001: movl ARGBASE+20(%esp), %ebx # src_err_ptr
21454- movl $-EFAULT, (%ebx)
21455+ movl $-EFAULT, %ss:(%ebx)
21456 # zero the complete destination (computing the rest is too much work)
21457 movl ARGBASE+8(%esp),%edi # dst
21458 movl ARGBASE+12(%esp),%ecx # len
21459@@ -502,10 +539,17 @@ DST( movb %dl, (%edi) )
21460 rep; stosb
21461 jmp 7b
21462 6002: movl ARGBASE+24(%esp), %ebx # dst_err_ptr
21463- movl $-EFAULT, (%ebx)
21464+ movl $-EFAULT, %ss:(%ebx)
21465 jmp 7b
21466 .previous
21467
21468+#ifdef CONFIG_PAX_MEMORY_UDEREF
21469+ pushl_cfi %ss
21470+ popl_cfi %ds
21471+ pushl_cfi %ss
21472+ popl_cfi %es
21473+#endif
21474+
21475 popl_cfi %esi
21476 CFI_RESTORE esi
21477 popl_cfi %edi
21478@@ -514,7 +558,7 @@ DST( movb %dl, (%edi) )
21479 CFI_RESTORE ebx
21480 ret
21481 CFI_ENDPROC
21482-ENDPROC(csum_partial_copy_generic)
21483+ENDPROC(csum_partial_copy_generic_to_user)
21484
21485 #undef ROUND
21486 #undef ROUND1
21487diff --git a/arch/x86/lib/clear_page_64.S b/arch/x86/lib/clear_page_64.S
21488index f2145cf..cea889d 100644
21489--- a/arch/x86/lib/clear_page_64.S
21490+++ b/arch/x86/lib/clear_page_64.S
21491@@ -11,6 +11,7 @@ ENTRY(clear_page_c)
21492 movl $4096/8,%ecx
21493 xorl %eax,%eax
21494 rep stosq
21495+ pax_force_retaddr
21496 ret
21497 CFI_ENDPROC
21498 ENDPROC(clear_page_c)
21499@@ -20,6 +21,7 @@ ENTRY(clear_page_c_e)
21500 movl $4096,%ecx
21501 xorl %eax,%eax
21502 rep stosb
21503+ pax_force_retaddr
21504 ret
21505 CFI_ENDPROC
21506 ENDPROC(clear_page_c_e)
21507@@ -43,6 +45,7 @@ ENTRY(clear_page)
21508 leaq 64(%rdi),%rdi
21509 jnz .Lloop
21510 nop
21511+ pax_force_retaddr
21512 ret
21513 CFI_ENDPROC
21514 .Lclear_page_end:
21515@@ -58,7 +61,7 @@ ENDPROC(clear_page)
21516
21517 #include <asm/cpufeature.h>
21518
21519- .section .altinstr_replacement,"ax"
21520+ .section .altinstr_replacement,"a"
21521 1: .byte 0xeb /* jmp <disp8> */
21522 .byte (clear_page_c - clear_page) - (2f - 1b) /* offset */
21523 2: .byte 0xeb /* jmp <disp8> */
21524diff --git a/arch/x86/lib/cmpxchg16b_emu.S b/arch/x86/lib/cmpxchg16b_emu.S
21525index 1e572c5..2a162cd 100644
21526--- a/arch/x86/lib/cmpxchg16b_emu.S
21527+++ b/arch/x86/lib/cmpxchg16b_emu.S
21528@@ -53,11 +53,13 @@ this_cpu_cmpxchg16b_emu:
21529
21530 popf
21531 mov $1, %al
21532+ pax_force_retaddr
21533 ret
21534
21535 not_same:
21536 popf
21537 xor %al,%al
21538+ pax_force_retaddr
21539 ret
21540
21541 CFI_ENDPROC
21542diff --git a/arch/x86/lib/copy_page_64.S b/arch/x86/lib/copy_page_64.S
21543index 6b34d04..dccb07f 100644
21544--- a/arch/x86/lib/copy_page_64.S
21545+++ b/arch/x86/lib/copy_page_64.S
21546@@ -9,6 +9,7 @@ copy_page_c:
21547 CFI_STARTPROC
21548 movl $4096/8,%ecx
21549 rep movsq
21550+ pax_force_retaddr
21551 ret
21552 CFI_ENDPROC
21553 ENDPROC(copy_page_c)
21554@@ -20,12 +21,14 @@ ENDPROC(copy_page_c)
21555
21556 ENTRY(copy_page)
21557 CFI_STARTPROC
21558- subq $2*8,%rsp
21559- CFI_ADJUST_CFA_OFFSET 2*8
21560+ subq $3*8,%rsp
21561+ CFI_ADJUST_CFA_OFFSET 3*8
21562 movq %rbx,(%rsp)
21563 CFI_REL_OFFSET rbx, 0
21564 movq %r12,1*8(%rsp)
21565 CFI_REL_OFFSET r12, 1*8
21566+ movq %r13,2*8(%rsp)
21567+ CFI_REL_OFFSET r13, 2*8
21568
21569 movl $(4096/64)-5,%ecx
21570 .p2align 4
21571@@ -37,7 +40,7 @@ ENTRY(copy_page)
21572 movq 16 (%rsi), %rdx
21573 movq 24 (%rsi), %r8
21574 movq 32 (%rsi), %r9
21575- movq 40 (%rsi), %r10
21576+ movq 40 (%rsi), %r13
21577 movq 48 (%rsi), %r11
21578 movq 56 (%rsi), %r12
21579
21580@@ -48,7 +51,7 @@ ENTRY(copy_page)
21581 movq %rdx, 16 (%rdi)
21582 movq %r8, 24 (%rdi)
21583 movq %r9, 32 (%rdi)
21584- movq %r10, 40 (%rdi)
21585+ movq %r13, 40 (%rdi)
21586 movq %r11, 48 (%rdi)
21587 movq %r12, 56 (%rdi)
21588
21589@@ -67,7 +70,7 @@ ENTRY(copy_page)
21590 movq 16 (%rsi), %rdx
21591 movq 24 (%rsi), %r8
21592 movq 32 (%rsi), %r9
21593- movq 40 (%rsi), %r10
21594+ movq 40 (%rsi), %r13
21595 movq 48 (%rsi), %r11
21596 movq 56 (%rsi), %r12
21597
21598@@ -76,7 +79,7 @@ ENTRY(copy_page)
21599 movq %rdx, 16 (%rdi)
21600 movq %r8, 24 (%rdi)
21601 movq %r9, 32 (%rdi)
21602- movq %r10, 40 (%rdi)
21603+ movq %r13, 40 (%rdi)
21604 movq %r11, 48 (%rdi)
21605 movq %r12, 56 (%rdi)
21606
21607@@ -89,8 +92,11 @@ ENTRY(copy_page)
21608 CFI_RESTORE rbx
21609 movq 1*8(%rsp),%r12
21610 CFI_RESTORE r12
21611- addq $2*8,%rsp
21612- CFI_ADJUST_CFA_OFFSET -2*8
21613+ movq 2*8(%rsp),%r13
21614+ CFI_RESTORE r13
21615+ addq $3*8,%rsp
21616+ CFI_ADJUST_CFA_OFFSET -3*8
21617+ pax_force_retaddr
21618 ret
21619 .Lcopy_page_end:
21620 CFI_ENDPROC
21621@@ -101,7 +107,7 @@ ENDPROC(copy_page)
21622
21623 #include <asm/cpufeature.h>
21624
21625- .section .altinstr_replacement,"ax"
21626+ .section .altinstr_replacement,"a"
21627 1: .byte 0xeb /* jmp <disp8> */
21628 .byte (copy_page_c - copy_page) - (2f - 1b) /* offset */
21629 2:
21630diff --git a/arch/x86/lib/copy_user_64.S b/arch/x86/lib/copy_user_64.S
21631index 5b2995f..78e7644 100644
21632--- a/arch/x86/lib/copy_user_64.S
21633+++ b/arch/x86/lib/copy_user_64.S
21634@@ -17,6 +17,7 @@
21635 #include <asm/cpufeature.h>
21636 #include <asm/alternative-asm.h>
21637 #include <asm/asm.h>
21638+#include <asm/pgtable.h>
21639
21640 /*
21641 * By placing feature2 after feature1 in altinstructions section, we logically
21642@@ -30,7 +31,7 @@
21643 .byte 0xe9 /* 32bit jump */
21644 .long \orig-1f /* by default jump to orig */
21645 1:
21646- .section .altinstr_replacement,"ax"
21647+ .section .altinstr_replacement,"a"
21648 2: .byte 0xe9 /* near jump with 32bit immediate */
21649 .long \alt1-1b /* offset */ /* or alternatively to alt1 */
21650 3: .byte 0xe9 /* near jump with 32bit immediate */
21651@@ -69,47 +70,20 @@
21652 #endif
21653 .endm
21654
21655-/* Standard copy_to_user with segment limit checking */
21656-ENTRY(_copy_to_user)
21657- CFI_STARTPROC
21658- GET_THREAD_INFO(%rax)
21659- movq %rdi,%rcx
21660- addq %rdx,%rcx
21661- jc bad_to_user
21662- cmpq TI_addr_limit(%rax),%rcx
21663- ja bad_to_user
21664- ALTERNATIVE_JUMP X86_FEATURE_REP_GOOD,X86_FEATURE_ERMS, \
21665- copy_user_generic_unrolled,copy_user_generic_string, \
21666- copy_user_enhanced_fast_string
21667- CFI_ENDPROC
21668-ENDPROC(_copy_to_user)
21669-
21670-/* Standard copy_from_user with segment limit checking */
21671-ENTRY(_copy_from_user)
21672- CFI_STARTPROC
21673- GET_THREAD_INFO(%rax)
21674- movq %rsi,%rcx
21675- addq %rdx,%rcx
21676- jc bad_from_user
21677- cmpq TI_addr_limit(%rax),%rcx
21678- ja bad_from_user
21679- ALTERNATIVE_JUMP X86_FEATURE_REP_GOOD,X86_FEATURE_ERMS, \
21680- copy_user_generic_unrolled,copy_user_generic_string, \
21681- copy_user_enhanced_fast_string
21682- CFI_ENDPROC
21683-ENDPROC(_copy_from_user)
21684-
21685 .section .fixup,"ax"
21686 /* must zero dest */
21687 ENTRY(bad_from_user)
21688 bad_from_user:
21689 CFI_STARTPROC
21690+ testl %edx,%edx
21691+ js bad_to_user
21692 movl %edx,%ecx
21693 xorl %eax,%eax
21694 rep
21695 stosb
21696 bad_to_user:
21697 movl %edx,%eax
21698+ pax_force_retaddr
21699 ret
21700 CFI_ENDPROC
21701 ENDPROC(bad_from_user)
21702@@ -139,19 +113,19 @@ ENTRY(copy_user_generic_unrolled)
21703 jz 17f
21704 1: movq (%rsi),%r8
21705 2: movq 1*8(%rsi),%r9
21706-3: movq 2*8(%rsi),%r10
21707+3: movq 2*8(%rsi),%rax
21708 4: movq 3*8(%rsi),%r11
21709 5: movq %r8,(%rdi)
21710 6: movq %r9,1*8(%rdi)
21711-7: movq %r10,2*8(%rdi)
21712+7: movq %rax,2*8(%rdi)
21713 8: movq %r11,3*8(%rdi)
21714 9: movq 4*8(%rsi),%r8
21715 10: movq 5*8(%rsi),%r9
21716-11: movq 6*8(%rsi),%r10
21717+11: movq 6*8(%rsi),%rax
21718 12: movq 7*8(%rsi),%r11
21719 13: movq %r8,4*8(%rdi)
21720 14: movq %r9,5*8(%rdi)
21721-15: movq %r10,6*8(%rdi)
21722+15: movq %rax,6*8(%rdi)
21723 16: movq %r11,7*8(%rdi)
21724 leaq 64(%rsi),%rsi
21725 leaq 64(%rdi),%rdi
21726@@ -177,6 +151,7 @@ ENTRY(copy_user_generic_unrolled)
21727 decl %ecx
21728 jnz 21b
21729 23: xor %eax,%eax
21730+ pax_force_retaddr
21731 ret
21732
21733 .section .fixup,"ax"
21734@@ -246,6 +221,7 @@ ENTRY(copy_user_generic_string)
21735 3: rep
21736 movsb
21737 4: xorl %eax,%eax
21738+ pax_force_retaddr
21739 ret
21740
21741 .section .fixup,"ax"
21742@@ -279,6 +255,7 @@ ENTRY(copy_user_enhanced_fast_string)
21743 1: rep
21744 movsb
21745 2: xorl %eax,%eax
21746+ pax_force_retaddr
21747 ret
21748
21749 .section .fixup,"ax"
21750diff --git a/arch/x86/lib/copy_user_nocache_64.S b/arch/x86/lib/copy_user_nocache_64.S
21751index cacddc7..09d49e4 100644
21752--- a/arch/x86/lib/copy_user_nocache_64.S
21753+++ b/arch/x86/lib/copy_user_nocache_64.S
21754@@ -8,6 +8,7 @@
21755
21756 #include <linux/linkage.h>
21757 #include <asm/dwarf2.h>
21758+#include <asm/alternative-asm.h>
21759
21760 #define FIX_ALIGNMENT 1
21761
21762@@ -15,6 +16,7 @@
21763 #include <asm/asm-offsets.h>
21764 #include <asm/thread_info.h>
21765 #include <asm/asm.h>
21766+#include <asm/pgtable.h>
21767
21768 .macro ALIGN_DESTINATION
21769 #ifdef FIX_ALIGNMENT
21770@@ -48,6 +50,15 @@
21771 */
21772 ENTRY(__copy_user_nocache)
21773 CFI_STARTPROC
21774+
21775+#ifdef CONFIG_PAX_MEMORY_UDEREF
21776+ mov $PAX_USER_SHADOW_BASE,%rcx
21777+ cmp %rcx,%rsi
21778+ jae 1f
21779+ add %rcx,%rsi
21780+1:
21781+#endif
21782+
21783 cmpl $8,%edx
21784 jb 20f /* less then 8 bytes, go to byte copy loop */
21785 ALIGN_DESTINATION
21786@@ -57,19 +68,19 @@ ENTRY(__copy_user_nocache)
21787 jz 17f
21788 1: movq (%rsi),%r8
21789 2: movq 1*8(%rsi),%r9
21790-3: movq 2*8(%rsi),%r10
21791+3: movq 2*8(%rsi),%rax
21792 4: movq 3*8(%rsi),%r11
21793 5: movnti %r8,(%rdi)
21794 6: movnti %r9,1*8(%rdi)
21795-7: movnti %r10,2*8(%rdi)
21796+7: movnti %rax,2*8(%rdi)
21797 8: movnti %r11,3*8(%rdi)
21798 9: movq 4*8(%rsi),%r8
21799 10: movq 5*8(%rsi),%r9
21800-11: movq 6*8(%rsi),%r10
21801+11: movq 6*8(%rsi),%rax
21802 12: movq 7*8(%rsi),%r11
21803 13: movnti %r8,4*8(%rdi)
21804 14: movnti %r9,5*8(%rdi)
21805-15: movnti %r10,6*8(%rdi)
21806+15: movnti %rax,6*8(%rdi)
21807 16: movnti %r11,7*8(%rdi)
21808 leaq 64(%rsi),%rsi
21809 leaq 64(%rdi),%rdi
21810@@ -96,6 +107,7 @@ ENTRY(__copy_user_nocache)
21811 jnz 21b
21812 23: xorl %eax,%eax
21813 sfence
21814+ pax_force_retaddr
21815 ret
21816
21817 .section .fixup,"ax"
21818diff --git a/arch/x86/lib/csum-copy_64.S b/arch/x86/lib/csum-copy_64.S
21819index 2419d5f..953ee51 100644
21820--- a/arch/x86/lib/csum-copy_64.S
21821+++ b/arch/x86/lib/csum-copy_64.S
21822@@ -9,6 +9,7 @@
21823 #include <asm/dwarf2.h>
21824 #include <asm/errno.h>
21825 #include <asm/asm.h>
21826+#include <asm/alternative-asm.h>
21827
21828 /*
21829 * Checksum copy with exception handling.
21830@@ -220,6 +221,7 @@ ENTRY(csum_partial_copy_generic)
21831 CFI_RESTORE rbp
21832 addq $7*8, %rsp
21833 CFI_ADJUST_CFA_OFFSET -7*8
21834+ pax_force_retaddr 0, 1
21835 ret
21836 CFI_RESTORE_STATE
21837
21838diff --git a/arch/x86/lib/csum-wrappers_64.c b/arch/x86/lib/csum-wrappers_64.c
21839index 25b7ae8..169fafc 100644
21840--- a/arch/x86/lib/csum-wrappers_64.c
21841+++ b/arch/x86/lib/csum-wrappers_64.c
21842@@ -52,7 +52,7 @@ csum_partial_copy_from_user(const void __user *src, void *dst,
21843 len -= 2;
21844 }
21845 }
21846- isum = csum_partial_copy_generic((__force const void *)src,
21847+ isum = csum_partial_copy_generic((const void __force_kernel *)____m(src),
21848 dst, len, isum, errp, NULL);
21849 if (unlikely(*errp))
21850 goto out_err;
21851@@ -105,7 +105,7 @@ csum_partial_copy_to_user(const void *src, void __user *dst,
21852 }
21853
21854 *errp = 0;
21855- return csum_partial_copy_generic(src, (void __force *)dst,
21856+ return csum_partial_copy_generic(src, (void __force_kernel *)____m(dst),
21857 len, isum, NULL, errp);
21858 }
21859 EXPORT_SYMBOL(csum_partial_copy_to_user);
21860diff --git a/arch/x86/lib/getuser.S b/arch/x86/lib/getuser.S
21861index b33b1fb..219f389 100644
21862--- a/arch/x86/lib/getuser.S
21863+++ b/arch/x86/lib/getuser.S
21864@@ -33,15 +33,38 @@
21865 #include <asm/asm-offsets.h>
21866 #include <asm/thread_info.h>
21867 #include <asm/asm.h>
21868+#include <asm/segment.h>
21869+#include <asm/pgtable.h>
21870+#include <asm/alternative-asm.h>
21871+
21872+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
21873+#define __copyuser_seg gs;
21874+#else
21875+#define __copyuser_seg
21876+#endif
21877
21878 .text
21879 ENTRY(__get_user_1)
21880 CFI_STARTPROC
21881+
21882+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
21883 GET_THREAD_INFO(%_ASM_DX)
21884 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
21885 jae bad_get_user
21886-1: movzb (%_ASM_AX),%edx
21887+
21888+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
21889+ mov $PAX_USER_SHADOW_BASE,%_ASM_DX
21890+ cmp %_ASM_DX,%_ASM_AX
21891+ jae 1234f
21892+ add %_ASM_DX,%_ASM_AX
21893+1234:
21894+#endif
21895+
21896+#endif
21897+
21898+1: __copyuser_seg movzb (%_ASM_AX),%edx
21899 xor %eax,%eax
21900+ pax_force_retaddr
21901 ret
21902 CFI_ENDPROC
21903 ENDPROC(__get_user_1)
21904@@ -49,12 +72,26 @@ ENDPROC(__get_user_1)
21905 ENTRY(__get_user_2)
21906 CFI_STARTPROC
21907 add $1,%_ASM_AX
21908+
21909+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
21910 jc bad_get_user
21911 GET_THREAD_INFO(%_ASM_DX)
21912 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
21913 jae bad_get_user
21914-2: movzwl -1(%_ASM_AX),%edx
21915+
21916+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
21917+ mov $PAX_USER_SHADOW_BASE,%_ASM_DX
21918+ cmp %_ASM_DX,%_ASM_AX
21919+ jae 1234f
21920+ add %_ASM_DX,%_ASM_AX
21921+1234:
21922+#endif
21923+
21924+#endif
21925+
21926+2: __copyuser_seg movzwl -1(%_ASM_AX),%edx
21927 xor %eax,%eax
21928+ pax_force_retaddr
21929 ret
21930 CFI_ENDPROC
21931 ENDPROC(__get_user_2)
21932@@ -62,12 +99,26 @@ ENDPROC(__get_user_2)
21933 ENTRY(__get_user_4)
21934 CFI_STARTPROC
21935 add $3,%_ASM_AX
21936+
21937+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
21938 jc bad_get_user
21939 GET_THREAD_INFO(%_ASM_DX)
21940 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
21941 jae bad_get_user
21942-3: mov -3(%_ASM_AX),%edx
21943+
21944+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
21945+ mov $PAX_USER_SHADOW_BASE,%_ASM_DX
21946+ cmp %_ASM_DX,%_ASM_AX
21947+ jae 1234f
21948+ add %_ASM_DX,%_ASM_AX
21949+1234:
21950+#endif
21951+
21952+#endif
21953+
21954+3: __copyuser_seg mov -3(%_ASM_AX),%edx
21955 xor %eax,%eax
21956+ pax_force_retaddr
21957 ret
21958 CFI_ENDPROC
21959 ENDPROC(__get_user_4)
21960@@ -80,8 +131,18 @@ ENTRY(__get_user_8)
21961 GET_THREAD_INFO(%_ASM_DX)
21962 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
21963 jae bad_get_user
21964+
21965+#ifdef CONFIG_PAX_MEMORY_UDEREF
21966+ mov $PAX_USER_SHADOW_BASE,%_ASM_DX
21967+ cmp %_ASM_DX,%_ASM_AX
21968+ jae 1234f
21969+ add %_ASM_DX,%_ASM_AX
21970+1234:
21971+#endif
21972+
21973 4: movq -7(%_ASM_AX),%_ASM_DX
21974 xor %eax,%eax
21975+ pax_force_retaddr
21976 ret
21977 CFI_ENDPROC
21978 ENDPROC(__get_user_8)
21979@@ -91,6 +152,7 @@ bad_get_user:
21980 CFI_STARTPROC
21981 xor %edx,%edx
21982 mov $(-EFAULT),%_ASM_AX
21983+ pax_force_retaddr
21984 ret
21985 CFI_ENDPROC
21986 END(bad_get_user)
21987diff --git a/arch/x86/lib/insn.c b/arch/x86/lib/insn.c
21988index b1e6c4b..21ae8fc 100644
21989--- a/arch/x86/lib/insn.c
21990+++ b/arch/x86/lib/insn.c
21991@@ -21,6 +21,11 @@
21992 #include <linux/string.h>
21993 #include <asm/inat.h>
21994 #include <asm/insn.h>
21995+#ifdef __KERNEL__
21996+#include <asm/pgtable_types.h>
21997+#else
21998+#define ktla_ktva(addr) addr
21999+#endif
22000
22001 /* Verify next sizeof(t) bytes can be on the same instruction */
22002 #define validate_next(t, insn, n) \
22003@@ -49,8 +54,8 @@
22004 void insn_init(struct insn *insn, const void *kaddr, int x86_64)
22005 {
22006 memset(insn, 0, sizeof(*insn));
22007- insn->kaddr = kaddr;
22008- insn->next_byte = kaddr;
22009+ insn->kaddr = ktla_ktva(kaddr);
22010+ insn->next_byte = ktla_ktva(kaddr);
22011 insn->x86_64 = x86_64 ? 1 : 0;
22012 insn->opnd_bytes = 4;
22013 if (x86_64)
22014diff --git a/arch/x86/lib/iomap_copy_64.S b/arch/x86/lib/iomap_copy_64.S
22015index 05a95e7..326f2fa 100644
22016--- a/arch/x86/lib/iomap_copy_64.S
22017+++ b/arch/x86/lib/iomap_copy_64.S
22018@@ -17,6 +17,7 @@
22019
22020 #include <linux/linkage.h>
22021 #include <asm/dwarf2.h>
22022+#include <asm/alternative-asm.h>
22023
22024 /*
22025 * override generic version in lib/iomap_copy.c
22026@@ -25,6 +26,7 @@ ENTRY(__iowrite32_copy)
22027 CFI_STARTPROC
22028 movl %edx,%ecx
22029 rep movsd
22030+ pax_force_retaddr
22031 ret
22032 CFI_ENDPROC
22033 ENDPROC(__iowrite32_copy)
22034diff --git a/arch/x86/lib/memcpy_64.S b/arch/x86/lib/memcpy_64.S
22035index 1c273be..da9cc0e 100644
22036--- a/arch/x86/lib/memcpy_64.S
22037+++ b/arch/x86/lib/memcpy_64.S
22038@@ -33,6 +33,7 @@
22039 rep movsq
22040 movl %edx, %ecx
22041 rep movsb
22042+ pax_force_retaddr
22043 ret
22044 .Lmemcpy_e:
22045 .previous
22046@@ -49,6 +50,7 @@
22047 movq %rdi, %rax
22048 movq %rdx, %rcx
22049 rep movsb
22050+ pax_force_retaddr
22051 ret
22052 .Lmemcpy_e_e:
22053 .previous
22054@@ -76,13 +78,13 @@ ENTRY(memcpy)
22055 */
22056 movq 0*8(%rsi), %r8
22057 movq 1*8(%rsi), %r9
22058- movq 2*8(%rsi), %r10
22059+ movq 2*8(%rsi), %rcx
22060 movq 3*8(%rsi), %r11
22061 leaq 4*8(%rsi), %rsi
22062
22063 movq %r8, 0*8(%rdi)
22064 movq %r9, 1*8(%rdi)
22065- movq %r10, 2*8(%rdi)
22066+ movq %rcx, 2*8(%rdi)
22067 movq %r11, 3*8(%rdi)
22068 leaq 4*8(%rdi), %rdi
22069 jae .Lcopy_forward_loop
22070@@ -105,12 +107,12 @@ ENTRY(memcpy)
22071 subq $0x20, %rdx
22072 movq -1*8(%rsi), %r8
22073 movq -2*8(%rsi), %r9
22074- movq -3*8(%rsi), %r10
22075+ movq -3*8(%rsi), %rcx
22076 movq -4*8(%rsi), %r11
22077 leaq -4*8(%rsi), %rsi
22078 movq %r8, -1*8(%rdi)
22079 movq %r9, -2*8(%rdi)
22080- movq %r10, -3*8(%rdi)
22081+ movq %rcx, -3*8(%rdi)
22082 movq %r11, -4*8(%rdi)
22083 leaq -4*8(%rdi), %rdi
22084 jae .Lcopy_backward_loop
22085@@ -130,12 +132,13 @@ ENTRY(memcpy)
22086 */
22087 movq 0*8(%rsi), %r8
22088 movq 1*8(%rsi), %r9
22089- movq -2*8(%rsi, %rdx), %r10
22090+ movq -2*8(%rsi, %rdx), %rcx
22091 movq -1*8(%rsi, %rdx), %r11
22092 movq %r8, 0*8(%rdi)
22093 movq %r9, 1*8(%rdi)
22094- movq %r10, -2*8(%rdi, %rdx)
22095+ movq %rcx, -2*8(%rdi, %rdx)
22096 movq %r11, -1*8(%rdi, %rdx)
22097+ pax_force_retaddr
22098 retq
22099 .p2align 4
22100 .Lless_16bytes:
22101@@ -148,6 +151,7 @@ ENTRY(memcpy)
22102 movq -1*8(%rsi, %rdx), %r9
22103 movq %r8, 0*8(%rdi)
22104 movq %r9, -1*8(%rdi, %rdx)
22105+ pax_force_retaddr
22106 retq
22107 .p2align 4
22108 .Lless_8bytes:
22109@@ -161,6 +165,7 @@ ENTRY(memcpy)
22110 movl -4(%rsi, %rdx), %r8d
22111 movl %ecx, (%rdi)
22112 movl %r8d, -4(%rdi, %rdx)
22113+ pax_force_retaddr
22114 retq
22115 .p2align 4
22116 .Lless_3bytes:
22117@@ -179,6 +184,7 @@ ENTRY(memcpy)
22118 movb %cl, (%rdi)
22119
22120 .Lend:
22121+ pax_force_retaddr
22122 retq
22123 CFI_ENDPROC
22124 ENDPROC(memcpy)
22125diff --git a/arch/x86/lib/memmove_64.S b/arch/x86/lib/memmove_64.S
22126index ee16461..c39c199 100644
22127--- a/arch/x86/lib/memmove_64.S
22128+++ b/arch/x86/lib/memmove_64.S
22129@@ -61,13 +61,13 @@ ENTRY(memmove)
22130 5:
22131 sub $0x20, %rdx
22132 movq 0*8(%rsi), %r11
22133- movq 1*8(%rsi), %r10
22134+ movq 1*8(%rsi), %rcx
22135 movq 2*8(%rsi), %r9
22136 movq 3*8(%rsi), %r8
22137 leaq 4*8(%rsi), %rsi
22138
22139 movq %r11, 0*8(%rdi)
22140- movq %r10, 1*8(%rdi)
22141+ movq %rcx, 1*8(%rdi)
22142 movq %r9, 2*8(%rdi)
22143 movq %r8, 3*8(%rdi)
22144 leaq 4*8(%rdi), %rdi
22145@@ -81,10 +81,10 @@ ENTRY(memmove)
22146 4:
22147 movq %rdx, %rcx
22148 movq -8(%rsi, %rdx), %r11
22149- lea -8(%rdi, %rdx), %r10
22150+ lea -8(%rdi, %rdx), %r9
22151 shrq $3, %rcx
22152 rep movsq
22153- movq %r11, (%r10)
22154+ movq %r11, (%r9)
22155 jmp 13f
22156 .Lmemmove_end_forward:
22157
22158@@ -95,14 +95,14 @@ ENTRY(memmove)
22159 7:
22160 movq %rdx, %rcx
22161 movq (%rsi), %r11
22162- movq %rdi, %r10
22163+ movq %rdi, %r9
22164 leaq -8(%rsi, %rdx), %rsi
22165 leaq -8(%rdi, %rdx), %rdi
22166 shrq $3, %rcx
22167 std
22168 rep movsq
22169 cld
22170- movq %r11, (%r10)
22171+ movq %r11, (%r9)
22172 jmp 13f
22173
22174 /*
22175@@ -127,13 +127,13 @@ ENTRY(memmove)
22176 8:
22177 subq $0x20, %rdx
22178 movq -1*8(%rsi), %r11
22179- movq -2*8(%rsi), %r10
22180+ movq -2*8(%rsi), %rcx
22181 movq -3*8(%rsi), %r9
22182 movq -4*8(%rsi), %r8
22183 leaq -4*8(%rsi), %rsi
22184
22185 movq %r11, -1*8(%rdi)
22186- movq %r10, -2*8(%rdi)
22187+ movq %rcx, -2*8(%rdi)
22188 movq %r9, -3*8(%rdi)
22189 movq %r8, -4*8(%rdi)
22190 leaq -4*8(%rdi), %rdi
22191@@ -151,11 +151,11 @@ ENTRY(memmove)
22192 * Move data from 16 bytes to 31 bytes.
22193 */
22194 movq 0*8(%rsi), %r11
22195- movq 1*8(%rsi), %r10
22196+ movq 1*8(%rsi), %rcx
22197 movq -2*8(%rsi, %rdx), %r9
22198 movq -1*8(%rsi, %rdx), %r8
22199 movq %r11, 0*8(%rdi)
22200- movq %r10, 1*8(%rdi)
22201+ movq %rcx, 1*8(%rdi)
22202 movq %r9, -2*8(%rdi, %rdx)
22203 movq %r8, -1*8(%rdi, %rdx)
22204 jmp 13f
22205@@ -167,9 +167,9 @@ ENTRY(memmove)
22206 * Move data from 8 bytes to 15 bytes.
22207 */
22208 movq 0*8(%rsi), %r11
22209- movq -1*8(%rsi, %rdx), %r10
22210+ movq -1*8(%rsi, %rdx), %r9
22211 movq %r11, 0*8(%rdi)
22212- movq %r10, -1*8(%rdi, %rdx)
22213+ movq %r9, -1*8(%rdi, %rdx)
22214 jmp 13f
22215 10:
22216 cmpq $4, %rdx
22217@@ -178,9 +178,9 @@ ENTRY(memmove)
22218 * Move data from 4 bytes to 7 bytes.
22219 */
22220 movl (%rsi), %r11d
22221- movl -4(%rsi, %rdx), %r10d
22222+ movl -4(%rsi, %rdx), %r9d
22223 movl %r11d, (%rdi)
22224- movl %r10d, -4(%rdi, %rdx)
22225+ movl %r9d, -4(%rdi, %rdx)
22226 jmp 13f
22227 11:
22228 cmp $2, %rdx
22229@@ -189,9 +189,9 @@ ENTRY(memmove)
22230 * Move data from 2 bytes to 3 bytes.
22231 */
22232 movw (%rsi), %r11w
22233- movw -2(%rsi, %rdx), %r10w
22234+ movw -2(%rsi, %rdx), %r9w
22235 movw %r11w, (%rdi)
22236- movw %r10w, -2(%rdi, %rdx)
22237+ movw %r9w, -2(%rdi, %rdx)
22238 jmp 13f
22239 12:
22240 cmp $1, %rdx
22241@@ -202,6 +202,7 @@ ENTRY(memmove)
22242 movb (%rsi), %r11b
22243 movb %r11b, (%rdi)
22244 13:
22245+ pax_force_retaddr
22246 retq
22247 CFI_ENDPROC
22248
22249@@ -210,6 +211,7 @@ ENTRY(memmove)
22250 /* Forward moving data. */
22251 movq %rdx, %rcx
22252 rep movsb
22253+ pax_force_retaddr
22254 retq
22255 .Lmemmove_end_forward_efs:
22256 .previous
22257diff --git a/arch/x86/lib/memset_64.S b/arch/x86/lib/memset_64.S
22258index 2dcb380..963660a 100644
22259--- a/arch/x86/lib/memset_64.S
22260+++ b/arch/x86/lib/memset_64.S
22261@@ -30,6 +30,7 @@
22262 movl %edx,%ecx
22263 rep stosb
22264 movq %r9,%rax
22265+ pax_force_retaddr
22266 ret
22267 .Lmemset_e:
22268 .previous
22269@@ -52,6 +53,7 @@
22270 movq %rdx,%rcx
22271 rep stosb
22272 movq %r9,%rax
22273+ pax_force_retaddr
22274 ret
22275 .Lmemset_e_e:
22276 .previous
22277@@ -59,7 +61,7 @@
22278 ENTRY(memset)
22279 ENTRY(__memset)
22280 CFI_STARTPROC
22281- movq %rdi,%r10
22282+ movq %rdi,%r11
22283
22284 /* expand byte value */
22285 movzbl %sil,%ecx
22286@@ -117,7 +119,8 @@ ENTRY(__memset)
22287 jnz .Lloop_1
22288
22289 .Lende:
22290- movq %r10,%rax
22291+ movq %r11,%rax
22292+ pax_force_retaddr
22293 ret
22294
22295 CFI_RESTORE_STATE
22296diff --git a/arch/x86/lib/mmx_32.c b/arch/x86/lib/mmx_32.c
22297index c9f2d9b..e7fd2c0 100644
22298--- a/arch/x86/lib/mmx_32.c
22299+++ b/arch/x86/lib/mmx_32.c
22300@@ -29,6 +29,7 @@ void *_mmx_memcpy(void *to, const void *from, size_t len)
22301 {
22302 void *p;
22303 int i;
22304+ unsigned long cr0;
22305
22306 if (unlikely(in_interrupt()))
22307 return __memcpy(to, from, len);
22308@@ -39,44 +40,72 @@ void *_mmx_memcpy(void *to, const void *from, size_t len)
22309 kernel_fpu_begin();
22310
22311 __asm__ __volatile__ (
22312- "1: prefetch (%0)\n" /* This set is 28 bytes */
22313- " prefetch 64(%0)\n"
22314- " prefetch 128(%0)\n"
22315- " prefetch 192(%0)\n"
22316- " prefetch 256(%0)\n"
22317+ "1: prefetch (%1)\n" /* This set is 28 bytes */
22318+ " prefetch 64(%1)\n"
22319+ " prefetch 128(%1)\n"
22320+ " prefetch 192(%1)\n"
22321+ " prefetch 256(%1)\n"
22322 "2: \n"
22323 ".section .fixup, \"ax\"\n"
22324- "3: movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
22325+ "3: \n"
22326+
22327+#ifdef CONFIG_PAX_KERNEXEC
22328+ " movl %%cr0, %0\n"
22329+ " movl %0, %%eax\n"
22330+ " andl $0xFFFEFFFF, %%eax\n"
22331+ " movl %%eax, %%cr0\n"
22332+#endif
22333+
22334+ " movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
22335+
22336+#ifdef CONFIG_PAX_KERNEXEC
22337+ " movl %0, %%cr0\n"
22338+#endif
22339+
22340 " jmp 2b\n"
22341 ".previous\n"
22342 _ASM_EXTABLE(1b, 3b)
22343- : : "r" (from));
22344+ : "=&r" (cr0) : "r" (from) : "ax");
22345
22346 for ( ; i > 5; i--) {
22347 __asm__ __volatile__ (
22348- "1: prefetch 320(%0)\n"
22349- "2: movq (%0), %%mm0\n"
22350- " movq 8(%0), %%mm1\n"
22351- " movq 16(%0), %%mm2\n"
22352- " movq 24(%0), %%mm3\n"
22353- " movq %%mm0, (%1)\n"
22354- " movq %%mm1, 8(%1)\n"
22355- " movq %%mm2, 16(%1)\n"
22356- " movq %%mm3, 24(%1)\n"
22357- " movq 32(%0), %%mm0\n"
22358- " movq 40(%0), %%mm1\n"
22359- " movq 48(%0), %%mm2\n"
22360- " movq 56(%0), %%mm3\n"
22361- " movq %%mm0, 32(%1)\n"
22362- " movq %%mm1, 40(%1)\n"
22363- " movq %%mm2, 48(%1)\n"
22364- " movq %%mm3, 56(%1)\n"
22365+ "1: prefetch 320(%1)\n"
22366+ "2: movq (%1), %%mm0\n"
22367+ " movq 8(%1), %%mm1\n"
22368+ " movq 16(%1), %%mm2\n"
22369+ " movq 24(%1), %%mm3\n"
22370+ " movq %%mm0, (%2)\n"
22371+ " movq %%mm1, 8(%2)\n"
22372+ " movq %%mm2, 16(%2)\n"
22373+ " movq %%mm3, 24(%2)\n"
22374+ " movq 32(%1), %%mm0\n"
22375+ " movq 40(%1), %%mm1\n"
22376+ " movq 48(%1), %%mm2\n"
22377+ " movq 56(%1), %%mm3\n"
22378+ " movq %%mm0, 32(%2)\n"
22379+ " movq %%mm1, 40(%2)\n"
22380+ " movq %%mm2, 48(%2)\n"
22381+ " movq %%mm3, 56(%2)\n"
22382 ".section .fixup, \"ax\"\n"
22383- "3: movw $0x05EB, 1b\n" /* jmp on 5 bytes */
22384+ "3:\n"
22385+
22386+#ifdef CONFIG_PAX_KERNEXEC
22387+ " movl %%cr0, %0\n"
22388+ " movl %0, %%eax\n"
22389+ " andl $0xFFFEFFFF, %%eax\n"
22390+ " movl %%eax, %%cr0\n"
22391+#endif
22392+
22393+ " movw $0x05EB, 1b\n" /* jmp on 5 bytes */
22394+
22395+#ifdef CONFIG_PAX_KERNEXEC
22396+ " movl %0, %%cr0\n"
22397+#endif
22398+
22399 " jmp 2b\n"
22400 ".previous\n"
22401 _ASM_EXTABLE(1b, 3b)
22402- : : "r" (from), "r" (to) : "memory");
22403+ : "=&r" (cr0) : "r" (from), "r" (to) : "memory", "ax");
22404
22405 from += 64;
22406 to += 64;
22407@@ -158,6 +187,7 @@ static void fast_clear_page(void *page)
22408 static void fast_copy_page(void *to, void *from)
22409 {
22410 int i;
22411+ unsigned long cr0;
22412
22413 kernel_fpu_begin();
22414
22415@@ -166,42 +196,70 @@ static void fast_copy_page(void *to, void *from)
22416 * but that is for later. -AV
22417 */
22418 __asm__ __volatile__(
22419- "1: prefetch (%0)\n"
22420- " prefetch 64(%0)\n"
22421- " prefetch 128(%0)\n"
22422- " prefetch 192(%0)\n"
22423- " prefetch 256(%0)\n"
22424+ "1: prefetch (%1)\n"
22425+ " prefetch 64(%1)\n"
22426+ " prefetch 128(%1)\n"
22427+ " prefetch 192(%1)\n"
22428+ " prefetch 256(%1)\n"
22429 "2: \n"
22430 ".section .fixup, \"ax\"\n"
22431- "3: movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
22432+ "3: \n"
22433+
22434+#ifdef CONFIG_PAX_KERNEXEC
22435+ " movl %%cr0, %0\n"
22436+ " movl %0, %%eax\n"
22437+ " andl $0xFFFEFFFF, %%eax\n"
22438+ " movl %%eax, %%cr0\n"
22439+#endif
22440+
22441+ " movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
22442+
22443+#ifdef CONFIG_PAX_KERNEXEC
22444+ " movl %0, %%cr0\n"
22445+#endif
22446+
22447 " jmp 2b\n"
22448 ".previous\n"
22449- _ASM_EXTABLE(1b, 3b) : : "r" (from));
22450+ _ASM_EXTABLE(1b, 3b) : "=&r" (cr0) : "r" (from) : "ax");
22451
22452 for (i = 0; i < (4096-320)/64; i++) {
22453 __asm__ __volatile__ (
22454- "1: prefetch 320(%0)\n"
22455- "2: movq (%0), %%mm0\n"
22456- " movntq %%mm0, (%1)\n"
22457- " movq 8(%0), %%mm1\n"
22458- " movntq %%mm1, 8(%1)\n"
22459- " movq 16(%0), %%mm2\n"
22460- " movntq %%mm2, 16(%1)\n"
22461- " movq 24(%0), %%mm3\n"
22462- " movntq %%mm3, 24(%1)\n"
22463- " movq 32(%0), %%mm4\n"
22464- " movntq %%mm4, 32(%1)\n"
22465- " movq 40(%0), %%mm5\n"
22466- " movntq %%mm5, 40(%1)\n"
22467- " movq 48(%0), %%mm6\n"
22468- " movntq %%mm6, 48(%1)\n"
22469- " movq 56(%0), %%mm7\n"
22470- " movntq %%mm7, 56(%1)\n"
22471+ "1: prefetch 320(%1)\n"
22472+ "2: movq (%1), %%mm0\n"
22473+ " movntq %%mm0, (%2)\n"
22474+ " movq 8(%1), %%mm1\n"
22475+ " movntq %%mm1, 8(%2)\n"
22476+ " movq 16(%1), %%mm2\n"
22477+ " movntq %%mm2, 16(%2)\n"
22478+ " movq 24(%1), %%mm3\n"
22479+ " movntq %%mm3, 24(%2)\n"
22480+ " movq 32(%1), %%mm4\n"
22481+ " movntq %%mm4, 32(%2)\n"
22482+ " movq 40(%1), %%mm5\n"
22483+ " movntq %%mm5, 40(%2)\n"
22484+ " movq 48(%1), %%mm6\n"
22485+ " movntq %%mm6, 48(%2)\n"
22486+ " movq 56(%1), %%mm7\n"
22487+ " movntq %%mm7, 56(%2)\n"
22488 ".section .fixup, \"ax\"\n"
22489- "3: movw $0x05EB, 1b\n" /* jmp on 5 bytes */
22490+ "3:\n"
22491+
22492+#ifdef CONFIG_PAX_KERNEXEC
22493+ " movl %%cr0, %0\n"
22494+ " movl %0, %%eax\n"
22495+ " andl $0xFFFEFFFF, %%eax\n"
22496+ " movl %%eax, %%cr0\n"
22497+#endif
22498+
22499+ " movw $0x05EB, 1b\n" /* jmp on 5 bytes */
22500+
22501+#ifdef CONFIG_PAX_KERNEXEC
22502+ " movl %0, %%cr0\n"
22503+#endif
22504+
22505 " jmp 2b\n"
22506 ".previous\n"
22507- _ASM_EXTABLE(1b, 3b) : : "r" (from), "r" (to) : "memory");
22508+ _ASM_EXTABLE(1b, 3b) : "=&r" (cr0) : "r" (from), "r" (to) : "memory", "ax");
22509
22510 from += 64;
22511 to += 64;
22512@@ -280,47 +338,76 @@ static void fast_clear_page(void *page)
22513 static void fast_copy_page(void *to, void *from)
22514 {
22515 int i;
22516+ unsigned long cr0;
22517
22518 kernel_fpu_begin();
22519
22520 __asm__ __volatile__ (
22521- "1: prefetch (%0)\n"
22522- " prefetch 64(%0)\n"
22523- " prefetch 128(%0)\n"
22524- " prefetch 192(%0)\n"
22525- " prefetch 256(%0)\n"
22526+ "1: prefetch (%1)\n"
22527+ " prefetch 64(%1)\n"
22528+ " prefetch 128(%1)\n"
22529+ " prefetch 192(%1)\n"
22530+ " prefetch 256(%1)\n"
22531 "2: \n"
22532 ".section .fixup, \"ax\"\n"
22533- "3: movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
22534+ "3: \n"
22535+
22536+#ifdef CONFIG_PAX_KERNEXEC
22537+ " movl %%cr0, %0\n"
22538+ " movl %0, %%eax\n"
22539+ " andl $0xFFFEFFFF, %%eax\n"
22540+ " movl %%eax, %%cr0\n"
22541+#endif
22542+
22543+ " movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
22544+
22545+#ifdef CONFIG_PAX_KERNEXEC
22546+ " movl %0, %%cr0\n"
22547+#endif
22548+
22549 " jmp 2b\n"
22550 ".previous\n"
22551- _ASM_EXTABLE(1b, 3b) : : "r" (from));
22552+ _ASM_EXTABLE(1b, 3b) : "=&r" (cr0) : "r" (from) : "ax");
22553
22554 for (i = 0; i < 4096/64; i++) {
22555 __asm__ __volatile__ (
22556- "1: prefetch 320(%0)\n"
22557- "2: movq (%0), %%mm0\n"
22558- " movq 8(%0), %%mm1\n"
22559- " movq 16(%0), %%mm2\n"
22560- " movq 24(%0), %%mm3\n"
22561- " movq %%mm0, (%1)\n"
22562- " movq %%mm1, 8(%1)\n"
22563- " movq %%mm2, 16(%1)\n"
22564- " movq %%mm3, 24(%1)\n"
22565- " movq 32(%0), %%mm0\n"
22566- " movq 40(%0), %%mm1\n"
22567- " movq 48(%0), %%mm2\n"
22568- " movq 56(%0), %%mm3\n"
22569- " movq %%mm0, 32(%1)\n"
22570- " movq %%mm1, 40(%1)\n"
22571- " movq %%mm2, 48(%1)\n"
22572- " movq %%mm3, 56(%1)\n"
22573+ "1: prefetch 320(%1)\n"
22574+ "2: movq (%1), %%mm0\n"
22575+ " movq 8(%1), %%mm1\n"
22576+ " movq 16(%1), %%mm2\n"
22577+ " movq 24(%1), %%mm3\n"
22578+ " movq %%mm0, (%2)\n"
22579+ " movq %%mm1, 8(%2)\n"
22580+ " movq %%mm2, 16(%2)\n"
22581+ " movq %%mm3, 24(%2)\n"
22582+ " movq 32(%1), %%mm0\n"
22583+ " movq 40(%1), %%mm1\n"
22584+ " movq 48(%1), %%mm2\n"
22585+ " movq 56(%1), %%mm3\n"
22586+ " movq %%mm0, 32(%2)\n"
22587+ " movq %%mm1, 40(%2)\n"
22588+ " movq %%mm2, 48(%2)\n"
22589+ " movq %%mm3, 56(%2)\n"
22590 ".section .fixup, \"ax\"\n"
22591- "3: movw $0x05EB, 1b\n" /* jmp on 5 bytes */
22592+ "3:\n"
22593+
22594+#ifdef CONFIG_PAX_KERNEXEC
22595+ " movl %%cr0, %0\n"
22596+ " movl %0, %%eax\n"
22597+ " andl $0xFFFEFFFF, %%eax\n"
22598+ " movl %%eax, %%cr0\n"
22599+#endif
22600+
22601+ " movw $0x05EB, 1b\n" /* jmp on 5 bytes */
22602+
22603+#ifdef CONFIG_PAX_KERNEXEC
22604+ " movl %0, %%cr0\n"
22605+#endif
22606+
22607 " jmp 2b\n"
22608 ".previous\n"
22609 _ASM_EXTABLE(1b, 3b)
22610- : : "r" (from), "r" (to) : "memory");
22611+ : "=&r" (cr0) : "r" (from), "r" (to) : "memory", "ax");
22612
22613 from += 64;
22614 to += 64;
22615diff --git a/arch/x86/lib/msr-reg.S b/arch/x86/lib/msr-reg.S
22616index f6d13ee..aca5f0b 100644
22617--- a/arch/x86/lib/msr-reg.S
22618+++ b/arch/x86/lib/msr-reg.S
22619@@ -3,6 +3,7 @@
22620 #include <asm/dwarf2.h>
22621 #include <asm/asm.h>
22622 #include <asm/msr.h>
22623+#include <asm/alternative-asm.h>
22624
22625 #ifdef CONFIG_X86_64
22626 /*
22627@@ -16,7 +17,7 @@ ENTRY(\op\()_safe_regs)
22628 CFI_STARTPROC
22629 pushq_cfi %rbx
22630 pushq_cfi %rbp
22631- movq %rdi, %r10 /* Save pointer */
22632+ movq %rdi, %r9 /* Save pointer */
22633 xorl %r11d, %r11d /* Return value */
22634 movl (%rdi), %eax
22635 movl 4(%rdi), %ecx
22636@@ -27,16 +28,17 @@ ENTRY(\op\()_safe_regs)
22637 movl 28(%rdi), %edi
22638 CFI_REMEMBER_STATE
22639 1: \op
22640-2: movl %eax, (%r10)
22641+2: movl %eax, (%r9)
22642 movl %r11d, %eax /* Return value */
22643- movl %ecx, 4(%r10)
22644- movl %edx, 8(%r10)
22645- movl %ebx, 12(%r10)
22646- movl %ebp, 20(%r10)
22647- movl %esi, 24(%r10)
22648- movl %edi, 28(%r10)
22649+ movl %ecx, 4(%r9)
22650+ movl %edx, 8(%r9)
22651+ movl %ebx, 12(%r9)
22652+ movl %ebp, 20(%r9)
22653+ movl %esi, 24(%r9)
22654+ movl %edi, 28(%r9)
22655 popq_cfi %rbp
22656 popq_cfi %rbx
22657+ pax_force_retaddr
22658 ret
22659 3:
22660 CFI_RESTORE_STATE
22661diff --git a/arch/x86/lib/putuser.S b/arch/x86/lib/putuser.S
22662index 7f951c8..ebd573a 100644
22663--- a/arch/x86/lib/putuser.S
22664+++ b/arch/x86/lib/putuser.S
22665@@ -15,7 +15,9 @@
22666 #include <asm/thread_info.h>
22667 #include <asm/errno.h>
22668 #include <asm/asm.h>
22669-
22670+#include <asm/segment.h>
22671+#include <asm/pgtable.h>
22672+#include <asm/alternative-asm.h>
22673
22674 /*
22675 * __put_user_X
22676@@ -29,52 +31,119 @@
22677 * as they get called from within inline assembly.
22678 */
22679
22680-#define ENTER CFI_STARTPROC ; \
22681- GET_THREAD_INFO(%_ASM_BX)
22682-#define EXIT ret ; \
22683+#define ENTER CFI_STARTPROC
22684+#define EXIT pax_force_retaddr; ret ; \
22685 CFI_ENDPROC
22686
22687+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
22688+#define _DEST %_ASM_CX,%_ASM_BX
22689+#else
22690+#define _DEST %_ASM_CX
22691+#endif
22692+
22693+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
22694+#define __copyuser_seg gs;
22695+#else
22696+#define __copyuser_seg
22697+#endif
22698+
22699 .text
22700 ENTRY(__put_user_1)
22701 ENTER
22702+
22703+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
22704+ GET_THREAD_INFO(%_ASM_BX)
22705 cmp TI_addr_limit(%_ASM_BX),%_ASM_CX
22706 jae bad_put_user
22707-1: movb %al,(%_ASM_CX)
22708+
22709+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
22710+ mov $PAX_USER_SHADOW_BASE,%_ASM_BX
22711+ cmp %_ASM_BX,%_ASM_CX
22712+ jb 1234f
22713+ xor %ebx,%ebx
22714+1234:
22715+#endif
22716+
22717+#endif
22718+
22719+1: __copyuser_seg movb %al,(_DEST)
22720 xor %eax,%eax
22721 EXIT
22722 ENDPROC(__put_user_1)
22723
22724 ENTRY(__put_user_2)
22725 ENTER
22726+
22727+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
22728+ GET_THREAD_INFO(%_ASM_BX)
22729 mov TI_addr_limit(%_ASM_BX),%_ASM_BX
22730 sub $1,%_ASM_BX
22731 cmp %_ASM_BX,%_ASM_CX
22732 jae bad_put_user
22733-2: movw %ax,(%_ASM_CX)
22734+
22735+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
22736+ mov $PAX_USER_SHADOW_BASE,%_ASM_BX
22737+ cmp %_ASM_BX,%_ASM_CX
22738+ jb 1234f
22739+ xor %ebx,%ebx
22740+1234:
22741+#endif
22742+
22743+#endif
22744+
22745+2: __copyuser_seg movw %ax,(_DEST)
22746 xor %eax,%eax
22747 EXIT
22748 ENDPROC(__put_user_2)
22749
22750 ENTRY(__put_user_4)
22751 ENTER
22752+
22753+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
22754+ GET_THREAD_INFO(%_ASM_BX)
22755 mov TI_addr_limit(%_ASM_BX),%_ASM_BX
22756 sub $3,%_ASM_BX
22757 cmp %_ASM_BX,%_ASM_CX
22758 jae bad_put_user
22759-3: movl %eax,(%_ASM_CX)
22760+
22761+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
22762+ mov $PAX_USER_SHADOW_BASE,%_ASM_BX
22763+ cmp %_ASM_BX,%_ASM_CX
22764+ jb 1234f
22765+ xor %ebx,%ebx
22766+1234:
22767+#endif
22768+
22769+#endif
22770+
22771+3: __copyuser_seg movl %eax,(_DEST)
22772 xor %eax,%eax
22773 EXIT
22774 ENDPROC(__put_user_4)
22775
22776 ENTRY(__put_user_8)
22777 ENTER
22778+
22779+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
22780+ GET_THREAD_INFO(%_ASM_BX)
22781 mov TI_addr_limit(%_ASM_BX),%_ASM_BX
22782 sub $7,%_ASM_BX
22783 cmp %_ASM_BX,%_ASM_CX
22784 jae bad_put_user
22785-4: mov %_ASM_AX,(%_ASM_CX)
22786+
22787+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
22788+ mov $PAX_USER_SHADOW_BASE,%_ASM_BX
22789+ cmp %_ASM_BX,%_ASM_CX
22790+ jb 1234f
22791+ xor %ebx,%ebx
22792+1234:
22793+#endif
22794+
22795+#endif
22796+
22797+4: __copyuser_seg mov %_ASM_AX,(_DEST)
22798 #ifdef CONFIG_X86_32
22799-5: movl %edx,4(%_ASM_CX)
22800+5: __copyuser_seg movl %edx,4(_DEST)
22801 #endif
22802 xor %eax,%eax
22803 EXIT
22804diff --git a/arch/x86/lib/rwlock.S b/arch/x86/lib/rwlock.S
22805index 1cad221..de671ee 100644
22806--- a/arch/x86/lib/rwlock.S
22807+++ b/arch/x86/lib/rwlock.S
22808@@ -16,13 +16,34 @@ ENTRY(__write_lock_failed)
22809 FRAME
22810 0: LOCK_PREFIX
22811 WRITE_LOCK_ADD($RW_LOCK_BIAS) (%__lock_ptr)
22812+
22813+#ifdef CONFIG_PAX_REFCOUNT
22814+ jno 1234f
22815+ LOCK_PREFIX
22816+ WRITE_LOCK_SUB($RW_LOCK_BIAS) (%__lock_ptr)
22817+ int $4
22818+1234:
22819+ _ASM_EXTABLE(1234b, 1234b)
22820+#endif
22821+
22822 1: rep; nop
22823 cmpl $WRITE_LOCK_CMP, (%__lock_ptr)
22824 jne 1b
22825 LOCK_PREFIX
22826 WRITE_LOCK_SUB($RW_LOCK_BIAS) (%__lock_ptr)
22827+
22828+#ifdef CONFIG_PAX_REFCOUNT
22829+ jno 1234f
22830+ LOCK_PREFIX
22831+ WRITE_LOCK_ADD($RW_LOCK_BIAS) (%__lock_ptr)
22832+ int $4
22833+1234:
22834+ _ASM_EXTABLE(1234b, 1234b)
22835+#endif
22836+
22837 jnz 0b
22838 ENDFRAME
22839+ pax_force_retaddr
22840 ret
22841 CFI_ENDPROC
22842 END(__write_lock_failed)
22843@@ -32,13 +53,34 @@ ENTRY(__read_lock_failed)
22844 FRAME
22845 0: LOCK_PREFIX
22846 READ_LOCK_SIZE(inc) (%__lock_ptr)
22847+
22848+#ifdef CONFIG_PAX_REFCOUNT
22849+ jno 1234f
22850+ LOCK_PREFIX
22851+ READ_LOCK_SIZE(dec) (%__lock_ptr)
22852+ int $4
22853+1234:
22854+ _ASM_EXTABLE(1234b, 1234b)
22855+#endif
22856+
22857 1: rep; nop
22858 READ_LOCK_SIZE(cmp) $1, (%__lock_ptr)
22859 js 1b
22860 LOCK_PREFIX
22861 READ_LOCK_SIZE(dec) (%__lock_ptr)
22862+
22863+#ifdef CONFIG_PAX_REFCOUNT
22864+ jno 1234f
22865+ LOCK_PREFIX
22866+ READ_LOCK_SIZE(inc) (%__lock_ptr)
22867+ int $4
22868+1234:
22869+ _ASM_EXTABLE(1234b, 1234b)
22870+#endif
22871+
22872 js 0b
22873 ENDFRAME
22874+ pax_force_retaddr
22875 ret
22876 CFI_ENDPROC
22877 END(__read_lock_failed)
22878diff --git a/arch/x86/lib/rwsem.S b/arch/x86/lib/rwsem.S
22879index 5dff5f0..cadebf4 100644
22880--- a/arch/x86/lib/rwsem.S
22881+++ b/arch/x86/lib/rwsem.S
22882@@ -94,6 +94,7 @@ ENTRY(call_rwsem_down_read_failed)
22883 __ASM_SIZE(pop,_cfi) %__ASM_REG(dx)
22884 CFI_RESTORE __ASM_REG(dx)
22885 restore_common_regs
22886+ pax_force_retaddr
22887 ret
22888 CFI_ENDPROC
22889 ENDPROC(call_rwsem_down_read_failed)
22890@@ -104,6 +105,7 @@ ENTRY(call_rwsem_down_write_failed)
22891 movq %rax,%rdi
22892 call rwsem_down_write_failed
22893 restore_common_regs
22894+ pax_force_retaddr
22895 ret
22896 CFI_ENDPROC
22897 ENDPROC(call_rwsem_down_write_failed)
22898@@ -117,7 +119,8 @@ ENTRY(call_rwsem_wake)
22899 movq %rax,%rdi
22900 call rwsem_wake
22901 restore_common_regs
22902-1: ret
22903+1: pax_force_retaddr
22904+ ret
22905 CFI_ENDPROC
22906 ENDPROC(call_rwsem_wake)
22907
22908@@ -131,6 +134,7 @@ ENTRY(call_rwsem_downgrade_wake)
22909 __ASM_SIZE(pop,_cfi) %__ASM_REG(dx)
22910 CFI_RESTORE __ASM_REG(dx)
22911 restore_common_regs
22912+ pax_force_retaddr
22913 ret
22914 CFI_ENDPROC
22915 ENDPROC(call_rwsem_downgrade_wake)
22916diff --git a/arch/x86/lib/thunk_64.S b/arch/x86/lib/thunk_64.S
22917index a63efd6..ccecad8 100644
22918--- a/arch/x86/lib/thunk_64.S
22919+++ b/arch/x86/lib/thunk_64.S
22920@@ -8,6 +8,7 @@
22921 #include <linux/linkage.h>
22922 #include <asm/dwarf2.h>
22923 #include <asm/calling.h>
22924+#include <asm/alternative-asm.h>
22925
22926 /* rdi: arg1 ... normal C conventions. rax is saved/restored. */
22927 .macro THUNK name, func, put_ret_addr_in_rdi=0
22928@@ -41,5 +42,6 @@
22929 SAVE_ARGS
22930 restore:
22931 RESTORE_ARGS
22932+ pax_force_retaddr
22933 ret
22934 CFI_ENDPROC
22935diff --git a/arch/x86/lib/usercopy_32.c b/arch/x86/lib/usercopy_32.c
22936index 1781b2f..90368dd 100644
22937--- a/arch/x86/lib/usercopy_32.c
22938+++ b/arch/x86/lib/usercopy_32.c
22939@@ -42,10 +42,12 @@ do { \
22940 int __d0; \
22941 might_fault(); \
22942 __asm__ __volatile__( \
22943+ __COPYUSER_SET_ES \
22944 "0: rep; stosl\n" \
22945 " movl %2,%0\n" \
22946 "1: rep; stosb\n" \
22947 "2:\n" \
22948+ __COPYUSER_RESTORE_ES \
22949 ".section .fixup,\"ax\"\n" \
22950 "3: lea 0(%2,%0,4),%0\n" \
22951 " jmp 2b\n" \
22952@@ -97,7 +99,7 @@ EXPORT_SYMBOL(__clear_user);
22953
22954 #ifdef CONFIG_X86_INTEL_USERCOPY
22955 static unsigned long
22956-__copy_user_intel(void __user *to, const void *from, unsigned long size)
22957+__generic_copy_to_user_intel(void __user *to, const void *from, unsigned long size)
22958 {
22959 int d0, d1;
22960 __asm__ __volatile__(
22961@@ -109,36 +111,36 @@ __copy_user_intel(void __user *to, const void *from, unsigned long size)
22962 " .align 2,0x90\n"
22963 "3: movl 0(%4), %%eax\n"
22964 "4: movl 4(%4), %%edx\n"
22965- "5: movl %%eax, 0(%3)\n"
22966- "6: movl %%edx, 4(%3)\n"
22967+ "5: "__copyuser_seg" movl %%eax, 0(%3)\n"
22968+ "6: "__copyuser_seg" movl %%edx, 4(%3)\n"
22969 "7: movl 8(%4), %%eax\n"
22970 "8: movl 12(%4),%%edx\n"
22971- "9: movl %%eax, 8(%3)\n"
22972- "10: movl %%edx, 12(%3)\n"
22973+ "9: "__copyuser_seg" movl %%eax, 8(%3)\n"
22974+ "10: "__copyuser_seg" movl %%edx, 12(%3)\n"
22975 "11: movl 16(%4), %%eax\n"
22976 "12: movl 20(%4), %%edx\n"
22977- "13: movl %%eax, 16(%3)\n"
22978- "14: movl %%edx, 20(%3)\n"
22979+ "13: "__copyuser_seg" movl %%eax, 16(%3)\n"
22980+ "14: "__copyuser_seg" movl %%edx, 20(%3)\n"
22981 "15: movl 24(%4), %%eax\n"
22982 "16: movl 28(%4), %%edx\n"
22983- "17: movl %%eax, 24(%3)\n"
22984- "18: movl %%edx, 28(%3)\n"
22985+ "17: "__copyuser_seg" movl %%eax, 24(%3)\n"
22986+ "18: "__copyuser_seg" movl %%edx, 28(%3)\n"
22987 "19: movl 32(%4), %%eax\n"
22988 "20: movl 36(%4), %%edx\n"
22989- "21: movl %%eax, 32(%3)\n"
22990- "22: movl %%edx, 36(%3)\n"
22991+ "21: "__copyuser_seg" movl %%eax, 32(%3)\n"
22992+ "22: "__copyuser_seg" movl %%edx, 36(%3)\n"
22993 "23: movl 40(%4), %%eax\n"
22994 "24: movl 44(%4), %%edx\n"
22995- "25: movl %%eax, 40(%3)\n"
22996- "26: movl %%edx, 44(%3)\n"
22997+ "25: "__copyuser_seg" movl %%eax, 40(%3)\n"
22998+ "26: "__copyuser_seg" movl %%edx, 44(%3)\n"
22999 "27: movl 48(%4), %%eax\n"
23000 "28: movl 52(%4), %%edx\n"
23001- "29: movl %%eax, 48(%3)\n"
23002- "30: movl %%edx, 52(%3)\n"
23003+ "29: "__copyuser_seg" movl %%eax, 48(%3)\n"
23004+ "30: "__copyuser_seg" movl %%edx, 52(%3)\n"
23005 "31: movl 56(%4), %%eax\n"
23006 "32: movl 60(%4), %%edx\n"
23007- "33: movl %%eax, 56(%3)\n"
23008- "34: movl %%edx, 60(%3)\n"
23009+ "33: "__copyuser_seg" movl %%eax, 56(%3)\n"
23010+ "34: "__copyuser_seg" movl %%edx, 60(%3)\n"
23011 " addl $-64, %0\n"
23012 " addl $64, %4\n"
23013 " addl $64, %3\n"
23014@@ -148,10 +150,12 @@ __copy_user_intel(void __user *to, const void *from, unsigned long size)
23015 " shrl $2, %0\n"
23016 " andl $3, %%eax\n"
23017 " cld\n"
23018+ __COPYUSER_SET_ES
23019 "99: rep; movsl\n"
23020 "36: movl %%eax, %0\n"
23021 "37: rep; movsb\n"
23022 "100:\n"
23023+ __COPYUSER_RESTORE_ES
23024 ".section .fixup,\"ax\"\n"
23025 "101: lea 0(%%eax,%0,4),%0\n"
23026 " jmp 100b\n"
23027@@ -201,46 +205,150 @@ __copy_user_intel(void __user *to, const void *from, unsigned long size)
23028 }
23029
23030 static unsigned long
23031+__generic_copy_from_user_intel(void *to, const void __user *from, unsigned long size)
23032+{
23033+ int d0, d1;
23034+ __asm__ __volatile__(
23035+ " .align 2,0x90\n"
23036+ "1: "__copyuser_seg" movl 32(%4), %%eax\n"
23037+ " cmpl $67, %0\n"
23038+ " jbe 3f\n"
23039+ "2: "__copyuser_seg" movl 64(%4), %%eax\n"
23040+ " .align 2,0x90\n"
23041+ "3: "__copyuser_seg" movl 0(%4), %%eax\n"
23042+ "4: "__copyuser_seg" movl 4(%4), %%edx\n"
23043+ "5: movl %%eax, 0(%3)\n"
23044+ "6: movl %%edx, 4(%3)\n"
23045+ "7: "__copyuser_seg" movl 8(%4), %%eax\n"
23046+ "8: "__copyuser_seg" movl 12(%4),%%edx\n"
23047+ "9: movl %%eax, 8(%3)\n"
23048+ "10: movl %%edx, 12(%3)\n"
23049+ "11: "__copyuser_seg" movl 16(%4), %%eax\n"
23050+ "12: "__copyuser_seg" movl 20(%4), %%edx\n"
23051+ "13: movl %%eax, 16(%3)\n"
23052+ "14: movl %%edx, 20(%3)\n"
23053+ "15: "__copyuser_seg" movl 24(%4), %%eax\n"
23054+ "16: "__copyuser_seg" movl 28(%4), %%edx\n"
23055+ "17: movl %%eax, 24(%3)\n"
23056+ "18: movl %%edx, 28(%3)\n"
23057+ "19: "__copyuser_seg" movl 32(%4), %%eax\n"
23058+ "20: "__copyuser_seg" movl 36(%4), %%edx\n"
23059+ "21: movl %%eax, 32(%3)\n"
23060+ "22: movl %%edx, 36(%3)\n"
23061+ "23: "__copyuser_seg" movl 40(%4), %%eax\n"
23062+ "24: "__copyuser_seg" movl 44(%4), %%edx\n"
23063+ "25: movl %%eax, 40(%3)\n"
23064+ "26: movl %%edx, 44(%3)\n"
23065+ "27: "__copyuser_seg" movl 48(%4), %%eax\n"
23066+ "28: "__copyuser_seg" movl 52(%4), %%edx\n"
23067+ "29: movl %%eax, 48(%3)\n"
23068+ "30: movl %%edx, 52(%3)\n"
23069+ "31: "__copyuser_seg" movl 56(%4), %%eax\n"
23070+ "32: "__copyuser_seg" movl 60(%4), %%edx\n"
23071+ "33: movl %%eax, 56(%3)\n"
23072+ "34: movl %%edx, 60(%3)\n"
23073+ " addl $-64, %0\n"
23074+ " addl $64, %4\n"
23075+ " addl $64, %3\n"
23076+ " cmpl $63, %0\n"
23077+ " ja 1b\n"
23078+ "35: movl %0, %%eax\n"
23079+ " shrl $2, %0\n"
23080+ " andl $3, %%eax\n"
23081+ " cld\n"
23082+ "99: rep; "__copyuser_seg" movsl\n"
23083+ "36: movl %%eax, %0\n"
23084+ "37: rep; "__copyuser_seg" movsb\n"
23085+ "100:\n"
23086+ ".section .fixup,\"ax\"\n"
23087+ "101: lea 0(%%eax,%0,4),%0\n"
23088+ " jmp 100b\n"
23089+ ".previous\n"
23090+ _ASM_EXTABLE(1b,100b)
23091+ _ASM_EXTABLE(2b,100b)
23092+ _ASM_EXTABLE(3b,100b)
23093+ _ASM_EXTABLE(4b,100b)
23094+ _ASM_EXTABLE(5b,100b)
23095+ _ASM_EXTABLE(6b,100b)
23096+ _ASM_EXTABLE(7b,100b)
23097+ _ASM_EXTABLE(8b,100b)
23098+ _ASM_EXTABLE(9b,100b)
23099+ _ASM_EXTABLE(10b,100b)
23100+ _ASM_EXTABLE(11b,100b)
23101+ _ASM_EXTABLE(12b,100b)
23102+ _ASM_EXTABLE(13b,100b)
23103+ _ASM_EXTABLE(14b,100b)
23104+ _ASM_EXTABLE(15b,100b)
23105+ _ASM_EXTABLE(16b,100b)
23106+ _ASM_EXTABLE(17b,100b)
23107+ _ASM_EXTABLE(18b,100b)
23108+ _ASM_EXTABLE(19b,100b)
23109+ _ASM_EXTABLE(20b,100b)
23110+ _ASM_EXTABLE(21b,100b)
23111+ _ASM_EXTABLE(22b,100b)
23112+ _ASM_EXTABLE(23b,100b)
23113+ _ASM_EXTABLE(24b,100b)
23114+ _ASM_EXTABLE(25b,100b)
23115+ _ASM_EXTABLE(26b,100b)
23116+ _ASM_EXTABLE(27b,100b)
23117+ _ASM_EXTABLE(28b,100b)
23118+ _ASM_EXTABLE(29b,100b)
23119+ _ASM_EXTABLE(30b,100b)
23120+ _ASM_EXTABLE(31b,100b)
23121+ _ASM_EXTABLE(32b,100b)
23122+ _ASM_EXTABLE(33b,100b)
23123+ _ASM_EXTABLE(34b,100b)
23124+ _ASM_EXTABLE(35b,100b)
23125+ _ASM_EXTABLE(36b,100b)
23126+ _ASM_EXTABLE(37b,100b)
23127+ _ASM_EXTABLE(99b,101b)
23128+ : "=&c"(size), "=&D" (d0), "=&S" (d1)
23129+ : "1"(to), "2"(from), "0"(size)
23130+ : "eax", "edx", "memory");
23131+ return size;
23132+}
23133+
23134+static unsigned long __size_overflow(3)
23135 __copy_user_zeroing_intel(void *to, const void __user *from, unsigned long size)
23136 {
23137 int d0, d1;
23138 __asm__ __volatile__(
23139 " .align 2,0x90\n"
23140- "0: movl 32(%4), %%eax\n"
23141+ "0: "__copyuser_seg" movl 32(%4), %%eax\n"
23142 " cmpl $67, %0\n"
23143 " jbe 2f\n"
23144- "1: movl 64(%4), %%eax\n"
23145+ "1: "__copyuser_seg" movl 64(%4), %%eax\n"
23146 " .align 2,0x90\n"
23147- "2: movl 0(%4), %%eax\n"
23148- "21: movl 4(%4), %%edx\n"
23149+ "2: "__copyuser_seg" movl 0(%4), %%eax\n"
23150+ "21: "__copyuser_seg" movl 4(%4), %%edx\n"
23151 " movl %%eax, 0(%3)\n"
23152 " movl %%edx, 4(%3)\n"
23153- "3: movl 8(%4), %%eax\n"
23154- "31: movl 12(%4),%%edx\n"
23155+ "3: "__copyuser_seg" movl 8(%4), %%eax\n"
23156+ "31: "__copyuser_seg" movl 12(%4),%%edx\n"
23157 " movl %%eax, 8(%3)\n"
23158 " movl %%edx, 12(%3)\n"
23159- "4: movl 16(%4), %%eax\n"
23160- "41: movl 20(%4), %%edx\n"
23161+ "4: "__copyuser_seg" movl 16(%4), %%eax\n"
23162+ "41: "__copyuser_seg" movl 20(%4), %%edx\n"
23163 " movl %%eax, 16(%3)\n"
23164 " movl %%edx, 20(%3)\n"
23165- "10: movl 24(%4), %%eax\n"
23166- "51: movl 28(%4), %%edx\n"
23167+ "10: "__copyuser_seg" movl 24(%4), %%eax\n"
23168+ "51: "__copyuser_seg" movl 28(%4), %%edx\n"
23169 " movl %%eax, 24(%3)\n"
23170 " movl %%edx, 28(%3)\n"
23171- "11: movl 32(%4), %%eax\n"
23172- "61: movl 36(%4), %%edx\n"
23173+ "11: "__copyuser_seg" movl 32(%4), %%eax\n"
23174+ "61: "__copyuser_seg" movl 36(%4), %%edx\n"
23175 " movl %%eax, 32(%3)\n"
23176 " movl %%edx, 36(%3)\n"
23177- "12: movl 40(%4), %%eax\n"
23178- "71: movl 44(%4), %%edx\n"
23179+ "12: "__copyuser_seg" movl 40(%4), %%eax\n"
23180+ "71: "__copyuser_seg" movl 44(%4), %%edx\n"
23181 " movl %%eax, 40(%3)\n"
23182 " movl %%edx, 44(%3)\n"
23183- "13: movl 48(%4), %%eax\n"
23184- "81: movl 52(%4), %%edx\n"
23185+ "13: "__copyuser_seg" movl 48(%4), %%eax\n"
23186+ "81: "__copyuser_seg" movl 52(%4), %%edx\n"
23187 " movl %%eax, 48(%3)\n"
23188 " movl %%edx, 52(%3)\n"
23189- "14: movl 56(%4), %%eax\n"
23190- "91: movl 60(%4), %%edx\n"
23191+ "14: "__copyuser_seg" movl 56(%4), %%eax\n"
23192+ "91: "__copyuser_seg" movl 60(%4), %%edx\n"
23193 " movl %%eax, 56(%3)\n"
23194 " movl %%edx, 60(%3)\n"
23195 " addl $-64, %0\n"
23196@@ -252,9 +360,9 @@ __copy_user_zeroing_intel(void *to, const void __user *from, unsigned long size)
23197 " shrl $2, %0\n"
23198 " andl $3, %%eax\n"
23199 " cld\n"
23200- "6: rep; movsl\n"
23201+ "6: rep; "__copyuser_seg" movsl\n"
23202 " movl %%eax,%0\n"
23203- "7: rep; movsb\n"
23204+ "7: rep; "__copyuser_seg" movsb\n"
23205 "8:\n"
23206 ".section .fixup,\"ax\"\n"
23207 "9: lea 0(%%eax,%0,4),%0\n"
23208@@ -297,48 +405,48 @@ __copy_user_zeroing_intel(void *to, const void __user *from, unsigned long size)
23209 * hyoshiok@miraclelinux.com
23210 */
23211
23212-static unsigned long __copy_user_zeroing_intel_nocache(void *to,
23213+static unsigned long __size_overflow(3) __copy_user_zeroing_intel_nocache(void *to,
23214 const void __user *from, unsigned long size)
23215 {
23216 int d0, d1;
23217
23218 __asm__ __volatile__(
23219 " .align 2,0x90\n"
23220- "0: movl 32(%4), %%eax\n"
23221+ "0: "__copyuser_seg" movl 32(%4), %%eax\n"
23222 " cmpl $67, %0\n"
23223 " jbe 2f\n"
23224- "1: movl 64(%4), %%eax\n"
23225+ "1: "__copyuser_seg" movl 64(%4), %%eax\n"
23226 " .align 2,0x90\n"
23227- "2: movl 0(%4), %%eax\n"
23228- "21: movl 4(%4), %%edx\n"
23229+ "2: "__copyuser_seg" movl 0(%4), %%eax\n"
23230+ "21: "__copyuser_seg" movl 4(%4), %%edx\n"
23231 " movnti %%eax, 0(%3)\n"
23232 " movnti %%edx, 4(%3)\n"
23233- "3: movl 8(%4), %%eax\n"
23234- "31: movl 12(%4),%%edx\n"
23235+ "3: "__copyuser_seg" movl 8(%4), %%eax\n"
23236+ "31: "__copyuser_seg" movl 12(%4),%%edx\n"
23237 " movnti %%eax, 8(%3)\n"
23238 " movnti %%edx, 12(%3)\n"
23239- "4: movl 16(%4), %%eax\n"
23240- "41: movl 20(%4), %%edx\n"
23241+ "4: "__copyuser_seg" movl 16(%4), %%eax\n"
23242+ "41: "__copyuser_seg" movl 20(%4), %%edx\n"
23243 " movnti %%eax, 16(%3)\n"
23244 " movnti %%edx, 20(%3)\n"
23245- "10: movl 24(%4), %%eax\n"
23246- "51: movl 28(%4), %%edx\n"
23247+ "10: "__copyuser_seg" movl 24(%4), %%eax\n"
23248+ "51: "__copyuser_seg" movl 28(%4), %%edx\n"
23249 " movnti %%eax, 24(%3)\n"
23250 " movnti %%edx, 28(%3)\n"
23251- "11: movl 32(%4), %%eax\n"
23252- "61: movl 36(%4), %%edx\n"
23253+ "11: "__copyuser_seg" movl 32(%4), %%eax\n"
23254+ "61: "__copyuser_seg" movl 36(%4), %%edx\n"
23255 " movnti %%eax, 32(%3)\n"
23256 " movnti %%edx, 36(%3)\n"
23257- "12: movl 40(%4), %%eax\n"
23258- "71: movl 44(%4), %%edx\n"
23259+ "12: "__copyuser_seg" movl 40(%4), %%eax\n"
23260+ "71: "__copyuser_seg" movl 44(%4), %%edx\n"
23261 " movnti %%eax, 40(%3)\n"
23262 " movnti %%edx, 44(%3)\n"
23263- "13: movl 48(%4), %%eax\n"
23264- "81: movl 52(%4), %%edx\n"
23265+ "13: "__copyuser_seg" movl 48(%4), %%eax\n"
23266+ "81: "__copyuser_seg" movl 52(%4), %%edx\n"
23267 " movnti %%eax, 48(%3)\n"
23268 " movnti %%edx, 52(%3)\n"
23269- "14: movl 56(%4), %%eax\n"
23270- "91: movl 60(%4), %%edx\n"
23271+ "14: "__copyuser_seg" movl 56(%4), %%eax\n"
23272+ "91: "__copyuser_seg" movl 60(%4), %%edx\n"
23273 " movnti %%eax, 56(%3)\n"
23274 " movnti %%edx, 60(%3)\n"
23275 " addl $-64, %0\n"
23276@@ -351,9 +459,9 @@ static unsigned long __copy_user_zeroing_intel_nocache(void *to,
23277 " shrl $2, %0\n"
23278 " andl $3, %%eax\n"
23279 " cld\n"
23280- "6: rep; movsl\n"
23281+ "6: rep; "__copyuser_seg" movsl\n"
23282 " movl %%eax,%0\n"
23283- "7: rep; movsb\n"
23284+ "7: rep; "__copyuser_seg" movsb\n"
23285 "8:\n"
23286 ".section .fixup,\"ax\"\n"
23287 "9: lea 0(%%eax,%0,4),%0\n"
23288@@ -391,48 +499,48 @@ static unsigned long __copy_user_zeroing_intel_nocache(void *to,
23289 return size;
23290 }
23291
23292-static unsigned long __copy_user_intel_nocache(void *to,
23293+static unsigned long __size_overflow(3) __copy_user_intel_nocache(void *to,
23294 const void __user *from, unsigned long size)
23295 {
23296 int d0, d1;
23297
23298 __asm__ __volatile__(
23299 " .align 2,0x90\n"
23300- "0: movl 32(%4), %%eax\n"
23301+ "0: "__copyuser_seg" movl 32(%4), %%eax\n"
23302 " cmpl $67, %0\n"
23303 " jbe 2f\n"
23304- "1: movl 64(%4), %%eax\n"
23305+ "1: "__copyuser_seg" movl 64(%4), %%eax\n"
23306 " .align 2,0x90\n"
23307- "2: movl 0(%4), %%eax\n"
23308- "21: movl 4(%4), %%edx\n"
23309+ "2: "__copyuser_seg" movl 0(%4), %%eax\n"
23310+ "21: "__copyuser_seg" movl 4(%4), %%edx\n"
23311 " movnti %%eax, 0(%3)\n"
23312 " movnti %%edx, 4(%3)\n"
23313- "3: movl 8(%4), %%eax\n"
23314- "31: movl 12(%4),%%edx\n"
23315+ "3: "__copyuser_seg" movl 8(%4), %%eax\n"
23316+ "31: "__copyuser_seg" movl 12(%4),%%edx\n"
23317 " movnti %%eax, 8(%3)\n"
23318 " movnti %%edx, 12(%3)\n"
23319- "4: movl 16(%4), %%eax\n"
23320- "41: movl 20(%4), %%edx\n"
23321+ "4: "__copyuser_seg" movl 16(%4), %%eax\n"
23322+ "41: "__copyuser_seg" movl 20(%4), %%edx\n"
23323 " movnti %%eax, 16(%3)\n"
23324 " movnti %%edx, 20(%3)\n"
23325- "10: movl 24(%4), %%eax\n"
23326- "51: movl 28(%4), %%edx\n"
23327+ "10: "__copyuser_seg" movl 24(%4), %%eax\n"
23328+ "51: "__copyuser_seg" movl 28(%4), %%edx\n"
23329 " movnti %%eax, 24(%3)\n"
23330 " movnti %%edx, 28(%3)\n"
23331- "11: movl 32(%4), %%eax\n"
23332- "61: movl 36(%4), %%edx\n"
23333+ "11: "__copyuser_seg" movl 32(%4), %%eax\n"
23334+ "61: "__copyuser_seg" movl 36(%4), %%edx\n"
23335 " movnti %%eax, 32(%3)\n"
23336 " movnti %%edx, 36(%3)\n"
23337- "12: movl 40(%4), %%eax\n"
23338- "71: movl 44(%4), %%edx\n"
23339+ "12: "__copyuser_seg" movl 40(%4), %%eax\n"
23340+ "71: "__copyuser_seg" movl 44(%4), %%edx\n"
23341 " movnti %%eax, 40(%3)\n"
23342 " movnti %%edx, 44(%3)\n"
23343- "13: movl 48(%4), %%eax\n"
23344- "81: movl 52(%4), %%edx\n"
23345+ "13: "__copyuser_seg" movl 48(%4), %%eax\n"
23346+ "81: "__copyuser_seg" movl 52(%4), %%edx\n"
23347 " movnti %%eax, 48(%3)\n"
23348 " movnti %%edx, 52(%3)\n"
23349- "14: movl 56(%4), %%eax\n"
23350- "91: movl 60(%4), %%edx\n"
23351+ "14: "__copyuser_seg" movl 56(%4), %%eax\n"
23352+ "91: "__copyuser_seg" movl 60(%4), %%edx\n"
23353 " movnti %%eax, 56(%3)\n"
23354 " movnti %%edx, 60(%3)\n"
23355 " addl $-64, %0\n"
23356@@ -445,9 +553,9 @@ static unsigned long __copy_user_intel_nocache(void *to,
23357 " shrl $2, %0\n"
23358 " andl $3, %%eax\n"
23359 " cld\n"
23360- "6: rep; movsl\n"
23361+ "6: rep; "__copyuser_seg" movsl\n"
23362 " movl %%eax,%0\n"
23363- "7: rep; movsb\n"
23364+ "7: rep; "__copyuser_seg" movsb\n"
23365 "8:\n"
23366 ".section .fixup,\"ax\"\n"
23367 "9: lea 0(%%eax,%0,4),%0\n"
23368@@ -487,32 +595,36 @@ static unsigned long __copy_user_intel_nocache(void *to,
23369 */
23370 unsigned long __copy_user_zeroing_intel(void *to, const void __user *from,
23371 unsigned long size);
23372-unsigned long __copy_user_intel(void __user *to, const void *from,
23373+unsigned long __generic_copy_to_user_intel(void __user *to, const void *from,
23374+ unsigned long size);
23375+unsigned long __generic_copy_from_user_intel(void *to, const void __user *from,
23376 unsigned long size);
23377 unsigned long __copy_user_zeroing_intel_nocache(void *to,
23378 const void __user *from, unsigned long size);
23379 #endif /* CONFIG_X86_INTEL_USERCOPY */
23380
23381 /* Generic arbitrary sized copy. */
23382-#define __copy_user(to, from, size) \
23383+#define __copy_user(to, from, size, prefix, set, restore) \
23384 do { \
23385 int __d0, __d1, __d2; \
23386 __asm__ __volatile__( \
23387+ set \
23388 " cmp $7,%0\n" \
23389 " jbe 1f\n" \
23390 " movl %1,%0\n" \
23391 " negl %0\n" \
23392 " andl $7,%0\n" \
23393 " subl %0,%3\n" \
23394- "4: rep; movsb\n" \
23395+ "4: rep; "prefix"movsb\n" \
23396 " movl %3,%0\n" \
23397 " shrl $2,%0\n" \
23398 " andl $3,%3\n" \
23399 " .align 2,0x90\n" \
23400- "0: rep; movsl\n" \
23401+ "0: rep; "prefix"movsl\n" \
23402 " movl %3,%0\n" \
23403- "1: rep; movsb\n" \
23404+ "1: rep; "prefix"movsb\n" \
23405 "2:\n" \
23406+ restore \
23407 ".section .fixup,\"ax\"\n" \
23408 "5: addl %3,%0\n" \
23409 " jmp 2b\n" \
23410@@ -537,14 +649,14 @@ do { \
23411 " negl %0\n" \
23412 " andl $7,%0\n" \
23413 " subl %0,%3\n" \
23414- "4: rep; movsb\n" \
23415+ "4: rep; "__copyuser_seg"movsb\n" \
23416 " movl %3,%0\n" \
23417 " shrl $2,%0\n" \
23418 " andl $3,%3\n" \
23419 " .align 2,0x90\n" \
23420- "0: rep; movsl\n" \
23421+ "0: rep; "__copyuser_seg"movsl\n" \
23422 " movl %3,%0\n" \
23423- "1: rep; movsb\n" \
23424+ "1: rep; "__copyuser_seg"movsb\n" \
23425 "2:\n" \
23426 ".section .fixup,\"ax\"\n" \
23427 "5: addl %3,%0\n" \
23428@@ -627,9 +739,9 @@ survive:
23429 }
23430 #endif
23431 if (movsl_is_ok(to, from, n))
23432- __copy_user(to, from, n);
23433+ __copy_user(to, from, n, "", __COPYUSER_SET_ES, __COPYUSER_RESTORE_ES);
23434 else
23435- n = __copy_user_intel(to, from, n);
23436+ n = __generic_copy_to_user_intel(to, from, n);
23437 return n;
23438 }
23439 EXPORT_SYMBOL(__copy_to_user_ll);
23440@@ -649,10 +761,9 @@ unsigned long __copy_from_user_ll_nozero(void *to, const void __user *from,
23441 unsigned long n)
23442 {
23443 if (movsl_is_ok(to, from, n))
23444- __copy_user(to, from, n);
23445+ __copy_user(to, from, n, __copyuser_seg, "", "");
23446 else
23447- n = __copy_user_intel((void __user *)to,
23448- (const void *)from, n);
23449+ n = __generic_copy_from_user_intel(to, from, n);
23450 return n;
23451 }
23452 EXPORT_SYMBOL(__copy_from_user_ll_nozero);
23453@@ -679,65 +790,50 @@ unsigned long __copy_from_user_ll_nocache_nozero(void *to, const void __user *fr
23454 if (n > 64 && cpu_has_xmm2)
23455 n = __copy_user_intel_nocache(to, from, n);
23456 else
23457- __copy_user(to, from, n);
23458+ __copy_user(to, from, n, __copyuser_seg, "", "");
23459 #else
23460- __copy_user(to, from, n);
23461+ __copy_user(to, from, n, __copyuser_seg, "", "");
23462 #endif
23463 return n;
23464 }
23465 EXPORT_SYMBOL(__copy_from_user_ll_nocache_nozero);
23466
23467-/**
23468- * copy_to_user: - Copy a block of data into user space.
23469- * @to: Destination address, in user space.
23470- * @from: Source address, in kernel space.
23471- * @n: Number of bytes to copy.
23472- *
23473- * Context: User context only. This function may sleep.
23474- *
23475- * Copy data from kernel space to user space.
23476- *
23477- * Returns number of bytes that could not be copied.
23478- * On success, this will be zero.
23479- */
23480-unsigned long
23481-copy_to_user(void __user *to, const void *from, unsigned long n)
23482-{
23483- if (access_ok(VERIFY_WRITE, to, n))
23484- n = __copy_to_user(to, from, n);
23485- return n;
23486-}
23487-EXPORT_SYMBOL(copy_to_user);
23488-
23489-/**
23490- * copy_from_user: - Copy a block of data from user space.
23491- * @to: Destination address, in kernel space.
23492- * @from: Source address, in user space.
23493- * @n: Number of bytes to copy.
23494- *
23495- * Context: User context only. This function may sleep.
23496- *
23497- * Copy data from user space to kernel space.
23498- *
23499- * Returns number of bytes that could not be copied.
23500- * On success, this will be zero.
23501- *
23502- * If some data could not be copied, this function will pad the copied
23503- * data to the requested size using zero bytes.
23504- */
23505-unsigned long
23506-_copy_from_user(void *to, const void __user *from, unsigned long n)
23507-{
23508- if (access_ok(VERIFY_READ, from, n))
23509- n = __copy_from_user(to, from, n);
23510- else
23511- memset(to, 0, n);
23512- return n;
23513-}
23514-EXPORT_SYMBOL(_copy_from_user);
23515-
23516 void copy_from_user_overflow(void)
23517 {
23518 WARN(1, "Buffer overflow detected!\n");
23519 }
23520 EXPORT_SYMBOL(copy_from_user_overflow);
23521+
23522+void copy_to_user_overflow(void)
23523+{
23524+ WARN(1, "Buffer overflow detected!\n");
23525+}
23526+EXPORT_SYMBOL(copy_to_user_overflow);
23527+
23528+#ifdef CONFIG_PAX_MEMORY_UDEREF
23529+void __set_fs(mm_segment_t x)
23530+{
23531+ switch (x.seg) {
23532+ case 0:
23533+ loadsegment(gs, 0);
23534+ break;
23535+ case TASK_SIZE_MAX:
23536+ loadsegment(gs, __USER_DS);
23537+ break;
23538+ case -1UL:
23539+ loadsegment(gs, __KERNEL_DS);
23540+ break;
23541+ default:
23542+ BUG();
23543+ }
23544+ return;
23545+}
23546+EXPORT_SYMBOL(__set_fs);
23547+
23548+void set_fs(mm_segment_t x)
23549+{
23550+ current_thread_info()->addr_limit = x;
23551+ __set_fs(x);
23552+}
23553+EXPORT_SYMBOL(set_fs);
23554+#endif
23555diff --git a/arch/x86/lib/usercopy_64.c b/arch/x86/lib/usercopy_64.c
23556index e5b130b..7d33980 100644
23557--- a/arch/x86/lib/usercopy_64.c
23558+++ b/arch/x86/lib/usercopy_64.c
23559@@ -38,7 +38,7 @@ unsigned long __clear_user(void __user *addr, unsigned long size)
23560 _ASM_EXTABLE(0b,3b)
23561 _ASM_EXTABLE(1b,2b)
23562 : [size8] "=&c"(size), [dst] "=&D" (__d0)
23563- : [size1] "r"(size & 7), "[size8]" (size / 8), "[dst]"(addr),
23564+ : [size1] "r"(size & 7), "[size8]" (size / 8), "[dst]"(____m(addr)),
23565 [zero] "r" (0UL), [eight] "r" (8UL));
23566 return size;
23567 }
23568@@ -52,12 +52,11 @@ unsigned long clear_user(void __user *to, unsigned long n)
23569 }
23570 EXPORT_SYMBOL(clear_user);
23571
23572-unsigned long copy_in_user(void __user *to, const void __user *from, unsigned len)
23573+unsigned long copy_in_user(void __user *to, const void __user *from, unsigned long len)
23574 {
23575- if (access_ok(VERIFY_WRITE, to, len) && access_ok(VERIFY_READ, from, len)) {
23576- return copy_user_generic((__force void *)to, (__force void *)from, len);
23577- }
23578- return len;
23579+ if (access_ok(VERIFY_WRITE, to, len) && access_ok(VERIFY_READ, from, len))
23580+ return copy_user_generic((void __force_kernel *)____m(to), (void __force_kernel *)____m(from), len);
23581+ return len;
23582 }
23583 EXPORT_SYMBOL(copy_in_user);
23584
23585@@ -67,7 +66,7 @@ EXPORT_SYMBOL(copy_in_user);
23586 * it is not necessary to optimize tail handling.
23587 */
23588 unsigned long
23589-copy_user_handle_tail(char *to, char *from, unsigned len, unsigned zerorest)
23590+copy_user_handle_tail(char __user *to, char __user *from, unsigned long len, unsigned zerorest)
23591 {
23592 char c;
23593 unsigned zero_len;
23594@@ -84,3 +83,15 @@ copy_user_handle_tail(char *to, char *from, unsigned len, unsigned zerorest)
23595 break;
23596 return len;
23597 }
23598+
23599+void copy_from_user_overflow(void)
23600+{
23601+ WARN(1, "Buffer overflow detected!\n");
23602+}
23603+EXPORT_SYMBOL(copy_from_user_overflow);
23604+
23605+void copy_to_user_overflow(void)
23606+{
23607+ WARN(1, "Buffer overflow detected!\n");
23608+}
23609+EXPORT_SYMBOL(copy_to_user_overflow);
23610diff --git a/arch/x86/mm/extable.c b/arch/x86/mm/extable.c
23611index 903ec1e..c4166b2 100644
23612--- a/arch/x86/mm/extable.c
23613+++ b/arch/x86/mm/extable.c
23614@@ -6,12 +6,24 @@
23615 static inline unsigned long
23616 ex_insn_addr(const struct exception_table_entry *x)
23617 {
23618- return (unsigned long)&x->insn + x->insn;
23619+ unsigned long reloc = 0;
23620+
23621+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
23622+ reloc = ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
23623+#endif
23624+
23625+ return (unsigned long)&x->insn + x->insn + reloc;
23626 }
23627 static inline unsigned long
23628 ex_fixup_addr(const struct exception_table_entry *x)
23629 {
23630- return (unsigned long)&x->fixup + x->fixup;
23631+ unsigned long reloc = 0;
23632+
23633+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
23634+ reloc = ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
23635+#endif
23636+
23637+ return (unsigned long)&x->fixup + x->fixup + reloc;
23638 }
23639
23640 int fixup_exception(struct pt_regs *regs)
23641@@ -20,7 +32,7 @@ int fixup_exception(struct pt_regs *regs)
23642 unsigned long new_ip;
23643
23644 #ifdef CONFIG_PNPBIOS
23645- if (unlikely(SEGMENT_IS_PNP_CODE(regs->cs))) {
23646+ if (unlikely(!v8086_mode(regs) && SEGMENT_IS_PNP_CODE(regs->cs))) {
23647 extern u32 pnp_bios_fault_eip, pnp_bios_fault_esp;
23648 extern u32 pnp_bios_is_utter_crap;
23649 pnp_bios_is_utter_crap = 1;
23650@@ -145,6 +157,13 @@ void sort_extable(struct exception_table_entry *start,
23651 i += 4;
23652 p->fixup -= i;
23653 i += 4;
23654+
23655+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
23656+ BUILD_BUG_ON(!IS_ENABLED(CONFIG_BUILDTIME_EXTABLE_SORT));
23657+ p->insn -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
23658+ p->fixup -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
23659+#endif
23660+
23661 }
23662 }
23663
23664diff --git a/arch/x86/mm/fault.c b/arch/x86/mm/fault.c
23665index 76dcd9d..e9dffde 100644
23666--- a/arch/x86/mm/fault.c
23667+++ b/arch/x86/mm/fault.c
23668@@ -13,11 +13,18 @@
23669 #include <linux/perf_event.h> /* perf_sw_event */
23670 #include <linux/hugetlb.h> /* hstate_index_to_shift */
23671 #include <linux/prefetch.h> /* prefetchw */
23672+#include <linux/unistd.h>
23673+#include <linux/compiler.h>
23674
23675 #include <asm/traps.h> /* dotraplinkage, ... */
23676 #include <asm/pgalloc.h> /* pgd_*(), ... */
23677 #include <asm/kmemcheck.h> /* kmemcheck_*(), ... */
23678 #include <asm/fixmap.h> /* VSYSCALL_START */
23679+#include <asm/tlbflush.h>
23680+
23681+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
23682+#include <asm/stacktrace.h>
23683+#endif
23684
23685 /*
23686 * Page fault error code bits:
23687@@ -55,7 +62,7 @@ static inline int __kprobes notify_page_fault(struct pt_regs *regs)
23688 int ret = 0;
23689
23690 /* kprobe_running() needs smp_processor_id() */
23691- if (kprobes_built_in() && !user_mode_vm(regs)) {
23692+ if (kprobes_built_in() && !user_mode(regs)) {
23693 preempt_disable();
23694 if (kprobe_running() && kprobe_fault_handler(regs, 14))
23695 ret = 1;
23696@@ -116,7 +123,10 @@ check_prefetch_opcode(struct pt_regs *regs, unsigned char *instr,
23697 return !instr_lo || (instr_lo>>1) == 1;
23698 case 0x00:
23699 /* Prefetch instruction is 0x0F0D or 0x0F18 */
23700- if (probe_kernel_address(instr, opcode))
23701+ if (user_mode(regs)) {
23702+ if (__copy_from_user_inatomic(&opcode, (unsigned char __force_user *)(instr), 1))
23703+ return 0;
23704+ } else if (probe_kernel_address(instr, opcode))
23705 return 0;
23706
23707 *prefetch = (instr_lo == 0xF) &&
23708@@ -150,7 +160,10 @@ is_prefetch(struct pt_regs *regs, unsigned long error_code, unsigned long addr)
23709 while (instr < max_instr) {
23710 unsigned char opcode;
23711
23712- if (probe_kernel_address(instr, opcode))
23713+ if (user_mode(regs)) {
23714+ if (__copy_from_user_inatomic(&opcode, (unsigned char __force_user *)(instr), 1))
23715+ break;
23716+ } else if (probe_kernel_address(instr, opcode))
23717 break;
23718
23719 instr++;
23720@@ -181,6 +194,34 @@ force_sig_info_fault(int si_signo, int si_code, unsigned long address,
23721 force_sig_info(si_signo, &info, tsk);
23722 }
23723
23724+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
23725+static bool pax_is_fetch_fault(struct pt_regs *regs, unsigned long error_code, unsigned long address);
23726+#endif
23727+
23728+#ifdef CONFIG_PAX_EMUTRAMP
23729+static int pax_handle_fetch_fault(struct pt_regs *regs);
23730+#endif
23731+
23732+#ifdef CONFIG_PAX_PAGEEXEC
23733+static inline pmd_t * pax_get_pmd(struct mm_struct *mm, unsigned long address)
23734+{
23735+ pgd_t *pgd;
23736+ pud_t *pud;
23737+ pmd_t *pmd;
23738+
23739+ pgd = pgd_offset(mm, address);
23740+ if (!pgd_present(*pgd))
23741+ return NULL;
23742+ pud = pud_offset(pgd, address);
23743+ if (!pud_present(*pud))
23744+ return NULL;
23745+ pmd = pmd_offset(pud, address);
23746+ if (!pmd_present(*pmd))
23747+ return NULL;
23748+ return pmd;
23749+}
23750+#endif
23751+
23752 DEFINE_SPINLOCK(pgd_lock);
23753 LIST_HEAD(pgd_list);
23754
23755@@ -231,10 +272,22 @@ void vmalloc_sync_all(void)
23756 for (address = VMALLOC_START & PMD_MASK;
23757 address >= TASK_SIZE && address < FIXADDR_TOP;
23758 address += PMD_SIZE) {
23759+
23760+#ifdef CONFIG_PAX_PER_CPU_PGD
23761+ unsigned long cpu;
23762+#else
23763 struct page *page;
23764+#endif
23765
23766 spin_lock(&pgd_lock);
23767+
23768+#ifdef CONFIG_PAX_PER_CPU_PGD
23769+ for (cpu = 0; cpu < nr_cpu_ids; ++cpu) {
23770+ pgd_t *pgd = get_cpu_pgd(cpu);
23771+ pmd_t *ret;
23772+#else
23773 list_for_each_entry(page, &pgd_list, lru) {
23774+ pgd_t *pgd = page_address(page);
23775 spinlock_t *pgt_lock;
23776 pmd_t *ret;
23777
23778@@ -242,8 +295,13 @@ void vmalloc_sync_all(void)
23779 pgt_lock = &pgd_page_get_mm(page)->page_table_lock;
23780
23781 spin_lock(pgt_lock);
23782- ret = vmalloc_sync_one(page_address(page), address);
23783+#endif
23784+
23785+ ret = vmalloc_sync_one(pgd, address);
23786+
23787+#ifndef CONFIG_PAX_PER_CPU_PGD
23788 spin_unlock(pgt_lock);
23789+#endif
23790
23791 if (!ret)
23792 break;
23793@@ -277,6 +335,11 @@ static noinline __kprobes int vmalloc_fault(unsigned long address)
23794 * an interrupt in the middle of a task switch..
23795 */
23796 pgd_paddr = read_cr3();
23797+
23798+#ifdef CONFIG_PAX_PER_CPU_PGD
23799+ BUG_ON(__pa(get_cpu_pgd(smp_processor_id())) != (pgd_paddr & PHYSICAL_PAGE_MASK));
23800+#endif
23801+
23802 pmd_k = vmalloc_sync_one(__va(pgd_paddr), address);
23803 if (!pmd_k)
23804 return -1;
23805@@ -372,7 +435,14 @@ static noinline __kprobes int vmalloc_fault(unsigned long address)
23806 * happen within a race in page table update. In the later
23807 * case just flush:
23808 */
23809+
23810+#ifdef CONFIG_PAX_PER_CPU_PGD
23811+ BUG_ON(__pa(get_cpu_pgd(smp_processor_id())) != (read_cr3() & PHYSICAL_PAGE_MASK));
23812+ pgd = pgd_offset_cpu(smp_processor_id(), address);
23813+#else
23814 pgd = pgd_offset(current->active_mm, address);
23815+#endif
23816+
23817 pgd_ref = pgd_offset_k(address);
23818 if (pgd_none(*pgd_ref))
23819 return -1;
23820@@ -540,7 +610,7 @@ static int is_errata93(struct pt_regs *regs, unsigned long address)
23821 static int is_errata100(struct pt_regs *regs, unsigned long address)
23822 {
23823 #ifdef CONFIG_X86_64
23824- if ((regs->cs == __USER32_CS || (regs->cs & (1<<2))) && (address >> 32))
23825+ if ((regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT)) && (address >> 32))
23826 return 1;
23827 #endif
23828 return 0;
23829@@ -567,7 +637,7 @@ static int is_f00f_bug(struct pt_regs *regs, unsigned long address)
23830 }
23831
23832 static const char nx_warning[] = KERN_CRIT
23833-"kernel tried to execute NX-protected page - exploit attempt? (uid: %d)\n";
23834+"kernel tried to execute NX-protected page - exploit attempt? (uid: %d, task: %s, pid: %d)\n";
23835
23836 static void
23837 show_fault_oops(struct pt_regs *regs, unsigned long error_code,
23838@@ -576,15 +646,26 @@ show_fault_oops(struct pt_regs *regs, unsigned long error_code,
23839 if (!oops_may_print())
23840 return;
23841
23842- if (error_code & PF_INSTR) {
23843+ if ((__supported_pte_mask & _PAGE_NX) && (error_code & PF_INSTR)) {
23844 unsigned int level;
23845
23846 pte_t *pte = lookup_address(address, &level);
23847
23848 if (pte && pte_present(*pte) && !pte_exec(*pte))
23849- printk(nx_warning, from_kuid(&init_user_ns, current_uid()));
23850+ printk(nx_warning, from_kuid(&init_user_ns, current_uid()), current->comm, task_pid_nr(current));
23851 }
23852
23853+#ifdef CONFIG_PAX_KERNEXEC
23854+ if (init_mm.start_code <= address && address < init_mm.end_code) {
23855+ if (current->signal->curr_ip)
23856+ printk(KERN_ERR "PAX: From %pI4: %s:%d, uid/euid: %u/%u, attempted to modify kernel code\n",
23857+ &current->signal->curr_ip, current->comm, task_pid_nr(current), current_uid(), current_euid());
23858+ else
23859+ printk(KERN_ERR "PAX: %s:%d, uid/euid: %u/%u, attempted to modify kernel code\n",
23860+ current->comm, task_pid_nr(current), current_uid(), current_euid());
23861+ }
23862+#endif
23863+
23864 printk(KERN_ALERT "BUG: unable to handle kernel ");
23865 if (address < PAGE_SIZE)
23866 printk(KERN_CONT "NULL pointer dereference");
23867@@ -748,6 +829,21 @@ __bad_area_nosemaphore(struct pt_regs *regs, unsigned long error_code,
23868 }
23869 #endif
23870
23871+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
23872+ if (pax_is_fetch_fault(regs, error_code, address)) {
23873+
23874+#ifdef CONFIG_PAX_EMUTRAMP
23875+ switch (pax_handle_fetch_fault(regs)) {
23876+ case 2:
23877+ return;
23878+ }
23879+#endif
23880+
23881+ pax_report_fault(regs, (void *)regs->ip, (void *)regs->sp);
23882+ do_group_exit(SIGKILL);
23883+ }
23884+#endif
23885+
23886 if (unlikely(show_unhandled_signals))
23887 show_signal_msg(regs, error_code, address, tsk);
23888
23889@@ -844,7 +940,7 @@ do_sigbus(struct pt_regs *regs, unsigned long error_code, unsigned long address,
23890 if (fault & (VM_FAULT_HWPOISON|VM_FAULT_HWPOISON_LARGE)) {
23891 printk(KERN_ERR
23892 "MCE: Killing %s:%d due to hardware memory corruption fault at %lx\n",
23893- tsk->comm, tsk->pid, address);
23894+ tsk->comm, task_pid_nr(tsk), address);
23895 code = BUS_MCEERR_AR;
23896 }
23897 #endif
23898@@ -900,6 +996,99 @@ static int spurious_fault_check(unsigned long error_code, pte_t *pte)
23899 return 1;
23900 }
23901
23902+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
23903+static int pax_handle_pageexec_fault(struct pt_regs *regs, struct mm_struct *mm, unsigned long address, unsigned long error_code)
23904+{
23905+ pte_t *pte;
23906+ pmd_t *pmd;
23907+ spinlock_t *ptl;
23908+ unsigned char pte_mask;
23909+
23910+ if ((__supported_pte_mask & _PAGE_NX) || (error_code & (PF_PROT|PF_USER)) != (PF_PROT|PF_USER) || v8086_mode(regs) ||
23911+ !(mm->pax_flags & MF_PAX_PAGEEXEC))
23912+ return 0;
23913+
23914+ /* PaX: it's our fault, let's handle it if we can */
23915+
23916+ /* PaX: take a look at read faults before acquiring any locks */
23917+ if (unlikely(!(error_code & PF_WRITE) && (regs->ip == address))) {
23918+ /* instruction fetch attempt from a protected page in user mode */
23919+ up_read(&mm->mmap_sem);
23920+
23921+#ifdef CONFIG_PAX_EMUTRAMP
23922+ switch (pax_handle_fetch_fault(regs)) {
23923+ case 2:
23924+ return 1;
23925+ }
23926+#endif
23927+
23928+ pax_report_fault(regs, (void *)regs->ip, (void *)regs->sp);
23929+ do_group_exit(SIGKILL);
23930+ }
23931+
23932+ pmd = pax_get_pmd(mm, address);
23933+ if (unlikely(!pmd))
23934+ return 0;
23935+
23936+ pte = pte_offset_map_lock(mm, pmd, address, &ptl);
23937+ if (unlikely(!(pte_val(*pte) & _PAGE_PRESENT) || pte_user(*pte))) {
23938+ pte_unmap_unlock(pte, ptl);
23939+ return 0;
23940+ }
23941+
23942+ if (unlikely((error_code & PF_WRITE) && !pte_write(*pte))) {
23943+ /* write attempt to a protected page in user mode */
23944+ pte_unmap_unlock(pte, ptl);
23945+ return 0;
23946+ }
23947+
23948+#ifdef CONFIG_SMP
23949+ if (likely(address > get_limit(regs->cs) && cpu_isset(smp_processor_id(), mm->context.cpu_user_cs_mask)))
23950+#else
23951+ if (likely(address > get_limit(regs->cs)))
23952+#endif
23953+ {
23954+ set_pte(pte, pte_mkread(*pte));
23955+ __flush_tlb_one(address);
23956+ pte_unmap_unlock(pte, ptl);
23957+ up_read(&mm->mmap_sem);
23958+ return 1;
23959+ }
23960+
23961+ pte_mask = _PAGE_ACCESSED | _PAGE_USER | ((error_code & PF_WRITE) << (_PAGE_BIT_DIRTY-1));
23962+
23963+ /*
23964+ * PaX: fill DTLB with user rights and retry
23965+ */
23966+ __asm__ __volatile__ (
23967+ "orb %2,(%1)\n"
23968+#if defined(CONFIG_M586) || defined(CONFIG_M586TSC)
23969+/*
23970+ * PaX: let this uncommented 'invlpg' remind us on the behaviour of Intel's
23971+ * (and AMD's) TLBs. namely, they do not cache PTEs that would raise *any*
23972+ * page fault when examined during a TLB load attempt. this is true not only
23973+ * for PTEs holding a non-present entry but also present entries that will
23974+ * raise a page fault (such as those set up by PaX, or the copy-on-write
23975+ * mechanism). in effect it means that we do *not* need to flush the TLBs
23976+ * for our target pages since their PTEs are simply not in the TLBs at all.
23977+
23978+ * the best thing in omitting it is that we gain around 15-20% speed in the
23979+ * fast path of the page fault handler and can get rid of tracing since we
23980+ * can no longer flush unintended entries.
23981+ */
23982+ "invlpg (%0)\n"
23983+#endif
23984+ __copyuser_seg"testb $0,(%0)\n"
23985+ "xorb %3,(%1)\n"
23986+ :
23987+ : "r" (address), "r" (pte), "q" (pte_mask), "i" (_PAGE_USER)
23988+ : "memory", "cc");
23989+ pte_unmap_unlock(pte, ptl);
23990+ up_read(&mm->mmap_sem);
23991+ return 1;
23992+}
23993+#endif
23994+
23995 /*
23996 * Handle a spurious fault caused by a stale TLB entry.
23997 *
23998@@ -972,6 +1161,9 @@ int show_unhandled_signals = 1;
23999 static inline int
24000 access_error(unsigned long error_code, struct vm_area_struct *vma)
24001 {
24002+ if ((__supported_pte_mask & _PAGE_NX) && (error_code & PF_INSTR) && !(vma->vm_flags & VM_EXEC))
24003+ return 1;
24004+
24005 if (error_code & PF_WRITE) {
24006 /* write, present and write, not present: */
24007 if (unlikely(!(vma->vm_flags & VM_WRITE)))
24008@@ -1005,18 +1197,33 @@ do_page_fault(struct pt_regs *regs, unsigned long error_code)
24009 {
24010 struct vm_area_struct *vma;
24011 struct task_struct *tsk;
24012- unsigned long address;
24013 struct mm_struct *mm;
24014 int fault;
24015 int write = error_code & PF_WRITE;
24016 unsigned int flags = FAULT_FLAG_ALLOW_RETRY | FAULT_FLAG_KILLABLE |
24017 (write ? FAULT_FLAG_WRITE : 0);
24018
24019- tsk = current;
24020- mm = tsk->mm;
24021-
24022 /* Get the faulting address: */
24023- address = read_cr2();
24024+ unsigned long address = read_cr2();
24025+
24026+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
24027+ if (!user_mode(regs) && address < 2 * PAX_USER_SHADOW_BASE) {
24028+ if (!search_exception_tables(regs->ip)) {
24029+ printk(KERN_ERR "PAX: please report this to pageexec@freemail.hu\n");
24030+ bad_area_nosemaphore(regs, error_code, address);
24031+ return;
24032+ }
24033+ if (address < PAX_USER_SHADOW_BASE) {
24034+ printk(KERN_ERR "PAX: please report this to pageexec@freemail.hu\n");
24035+ printk(KERN_ERR "PAX: faulting IP: %pS\n", (void *)regs->ip);
24036+ show_trace_log_lvl(NULL, NULL, (void *)regs->sp, regs->bp, KERN_ERR);
24037+ } else
24038+ address -= PAX_USER_SHADOW_BASE;
24039+ }
24040+#endif
24041+
24042+ tsk = current;
24043+ mm = tsk->mm;
24044
24045 /*
24046 * Detect and handle instructions that would cause a page fault for
24047@@ -1077,7 +1284,7 @@ do_page_fault(struct pt_regs *regs, unsigned long error_code)
24048 * User-mode registers count as a user access even for any
24049 * potential system fault or CPU buglet:
24050 */
24051- if (user_mode_vm(regs)) {
24052+ if (user_mode(regs)) {
24053 local_irq_enable();
24054 error_code |= PF_USER;
24055 } else {
24056@@ -1132,6 +1339,11 @@ retry:
24057 might_sleep();
24058 }
24059
24060+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
24061+ if (pax_handle_pageexec_fault(regs, mm, address, error_code))
24062+ return;
24063+#endif
24064+
24065 vma = find_vma(mm, address);
24066 if (unlikely(!vma)) {
24067 bad_area(regs, error_code, address);
24068@@ -1143,18 +1355,24 @@ retry:
24069 bad_area(regs, error_code, address);
24070 return;
24071 }
24072- if (error_code & PF_USER) {
24073- /*
24074- * Accessing the stack below %sp is always a bug.
24075- * The large cushion allows instructions like enter
24076- * and pusha to work. ("enter $65535, $31" pushes
24077- * 32 pointers and then decrements %sp by 65535.)
24078- */
24079- if (unlikely(address + 65536 + 32 * sizeof(unsigned long) < regs->sp)) {
24080- bad_area(regs, error_code, address);
24081- return;
24082- }
24083+ /*
24084+ * Accessing the stack below %sp is always a bug.
24085+ * The large cushion allows instructions like enter
24086+ * and pusha to work. ("enter $65535, $31" pushes
24087+ * 32 pointers and then decrements %sp by 65535.)
24088+ */
24089+ if (unlikely(address + 65536 + 32 * sizeof(unsigned long) < task_pt_regs(tsk)->sp)) {
24090+ bad_area(regs, error_code, address);
24091+ return;
24092 }
24093+
24094+#ifdef CONFIG_PAX_SEGMEXEC
24095+ if (unlikely((mm->pax_flags & MF_PAX_SEGMEXEC) && vma->vm_end - SEGMEXEC_TASK_SIZE - 1 < address - SEGMEXEC_TASK_SIZE - 1)) {
24096+ bad_area(regs, error_code, address);
24097+ return;
24098+ }
24099+#endif
24100+
24101 if (unlikely(expand_stack(vma, address))) {
24102 bad_area(regs, error_code, address);
24103 return;
24104@@ -1209,3 +1427,292 @@ good_area:
24105
24106 up_read(&mm->mmap_sem);
24107 }
24108+
24109+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
24110+static bool pax_is_fetch_fault(struct pt_regs *regs, unsigned long error_code, unsigned long address)
24111+{
24112+ struct mm_struct *mm = current->mm;
24113+ unsigned long ip = regs->ip;
24114+
24115+ if (v8086_mode(regs))
24116+ ip = ((regs->cs & 0xffff) << 4) + (ip & 0xffff);
24117+
24118+#ifdef CONFIG_PAX_PAGEEXEC
24119+ if (mm->pax_flags & MF_PAX_PAGEEXEC) {
24120+ if ((__supported_pte_mask & _PAGE_NX) && (error_code & PF_INSTR))
24121+ return true;
24122+ if (!(error_code & (PF_PROT | PF_WRITE)) && ip == address)
24123+ return true;
24124+ return false;
24125+ }
24126+#endif
24127+
24128+#ifdef CONFIG_PAX_SEGMEXEC
24129+ if (mm->pax_flags & MF_PAX_SEGMEXEC) {
24130+ if (!(error_code & (PF_PROT | PF_WRITE)) && (ip + SEGMEXEC_TASK_SIZE == address))
24131+ return true;
24132+ return false;
24133+ }
24134+#endif
24135+
24136+ return false;
24137+}
24138+#endif
24139+
24140+#ifdef CONFIG_PAX_EMUTRAMP
24141+static int pax_handle_fetch_fault_32(struct pt_regs *regs)
24142+{
24143+ int err;
24144+
24145+ do { /* PaX: libffi trampoline emulation */
24146+ unsigned char mov, jmp;
24147+ unsigned int addr1, addr2;
24148+
24149+#ifdef CONFIG_X86_64
24150+ if ((regs->ip + 9) >> 32)
24151+ break;
24152+#endif
24153+
24154+ err = get_user(mov, (unsigned char __user *)regs->ip);
24155+ err |= get_user(addr1, (unsigned int __user *)(regs->ip + 1));
24156+ err |= get_user(jmp, (unsigned char __user *)(regs->ip + 5));
24157+ err |= get_user(addr2, (unsigned int __user *)(regs->ip + 6));
24158+
24159+ if (err)
24160+ break;
24161+
24162+ if (mov == 0xB8 && jmp == 0xE9) {
24163+ regs->ax = addr1;
24164+ regs->ip = (unsigned int)(regs->ip + addr2 + 10);
24165+ return 2;
24166+ }
24167+ } while (0);
24168+
24169+ do { /* PaX: gcc trampoline emulation #1 */
24170+ unsigned char mov1, mov2;
24171+ unsigned short jmp;
24172+ unsigned int addr1, addr2;
24173+
24174+#ifdef CONFIG_X86_64
24175+ if ((regs->ip + 11) >> 32)
24176+ break;
24177+#endif
24178+
24179+ err = get_user(mov1, (unsigned char __user *)regs->ip);
24180+ err |= get_user(addr1, (unsigned int __user *)(regs->ip + 1));
24181+ err |= get_user(mov2, (unsigned char __user *)(regs->ip + 5));
24182+ err |= get_user(addr2, (unsigned int __user *)(regs->ip + 6));
24183+ err |= get_user(jmp, (unsigned short __user *)(regs->ip + 10));
24184+
24185+ if (err)
24186+ break;
24187+
24188+ if (mov1 == 0xB9 && mov2 == 0xB8 && jmp == 0xE0FF) {
24189+ regs->cx = addr1;
24190+ regs->ax = addr2;
24191+ regs->ip = addr2;
24192+ return 2;
24193+ }
24194+ } while (0);
24195+
24196+ do { /* PaX: gcc trampoline emulation #2 */
24197+ unsigned char mov, jmp;
24198+ unsigned int addr1, addr2;
24199+
24200+#ifdef CONFIG_X86_64
24201+ if ((regs->ip + 9) >> 32)
24202+ break;
24203+#endif
24204+
24205+ err = get_user(mov, (unsigned char __user *)regs->ip);
24206+ err |= get_user(addr1, (unsigned int __user *)(regs->ip + 1));
24207+ err |= get_user(jmp, (unsigned char __user *)(regs->ip + 5));
24208+ err |= get_user(addr2, (unsigned int __user *)(regs->ip + 6));
24209+
24210+ if (err)
24211+ break;
24212+
24213+ if (mov == 0xB9 && jmp == 0xE9) {
24214+ regs->cx = addr1;
24215+ regs->ip = (unsigned int)(regs->ip + addr2 + 10);
24216+ return 2;
24217+ }
24218+ } while (0);
24219+
24220+ return 1; /* PaX in action */
24221+}
24222+
24223+#ifdef CONFIG_X86_64
24224+static int pax_handle_fetch_fault_64(struct pt_regs *regs)
24225+{
24226+ int err;
24227+
24228+ do { /* PaX: libffi trampoline emulation */
24229+ unsigned short mov1, mov2, jmp1;
24230+ unsigned char stcclc, jmp2;
24231+ unsigned long addr1, addr2;
24232+
24233+ err = get_user(mov1, (unsigned short __user *)regs->ip);
24234+ err |= get_user(addr1, (unsigned long __user *)(regs->ip + 2));
24235+ err |= get_user(mov2, (unsigned short __user *)(regs->ip + 10));
24236+ err |= get_user(addr2, (unsigned long __user *)(regs->ip + 12));
24237+ err |= get_user(stcclc, (unsigned char __user *)(regs->ip + 20));
24238+ err |= get_user(jmp1, (unsigned short __user *)(regs->ip + 21));
24239+ err |= get_user(jmp2, (unsigned char __user *)(regs->ip + 23));
24240+
24241+ if (err)
24242+ break;
24243+
24244+ if (mov1 == 0xBB49 && mov2 == 0xBA49 && (stcclc == 0xF8 || stcclc == 0xF9) && jmp1 == 0xFF49 && jmp2 == 0xE3) {
24245+ regs->r11 = addr1;
24246+ regs->r10 = addr2;
24247+ if (stcclc == 0xF8)
24248+ regs->flags &= ~X86_EFLAGS_CF;
24249+ else
24250+ regs->flags |= X86_EFLAGS_CF;
24251+ regs->ip = addr1;
24252+ return 2;
24253+ }
24254+ } while (0);
24255+
24256+ do { /* PaX: gcc trampoline emulation #1 */
24257+ unsigned short mov1, mov2, jmp1;
24258+ unsigned char jmp2;
24259+ unsigned int addr1;
24260+ unsigned long addr2;
24261+
24262+ err = get_user(mov1, (unsigned short __user *)regs->ip);
24263+ err |= get_user(addr1, (unsigned int __user *)(regs->ip + 2));
24264+ err |= get_user(mov2, (unsigned short __user *)(regs->ip + 6));
24265+ err |= get_user(addr2, (unsigned long __user *)(regs->ip + 8));
24266+ err |= get_user(jmp1, (unsigned short __user *)(regs->ip + 16));
24267+ err |= get_user(jmp2, (unsigned char __user *)(regs->ip + 18));
24268+
24269+ if (err)
24270+ break;
24271+
24272+ if (mov1 == 0xBB41 && mov2 == 0xBA49 && jmp1 == 0xFF49 && jmp2 == 0xE3) {
24273+ regs->r11 = addr1;
24274+ regs->r10 = addr2;
24275+ regs->ip = addr1;
24276+ return 2;
24277+ }
24278+ } while (0);
24279+
24280+ do { /* PaX: gcc trampoline emulation #2 */
24281+ unsigned short mov1, mov2, jmp1;
24282+ unsigned char jmp2;
24283+ unsigned long addr1, addr2;
24284+
24285+ err = get_user(mov1, (unsigned short __user *)regs->ip);
24286+ err |= get_user(addr1, (unsigned long __user *)(regs->ip + 2));
24287+ err |= get_user(mov2, (unsigned short __user *)(regs->ip + 10));
24288+ err |= get_user(addr2, (unsigned long __user *)(regs->ip + 12));
24289+ err |= get_user(jmp1, (unsigned short __user *)(regs->ip + 20));
24290+ err |= get_user(jmp2, (unsigned char __user *)(regs->ip + 22));
24291+
24292+ if (err)
24293+ break;
24294+
24295+ if (mov1 == 0xBB49 && mov2 == 0xBA49 && jmp1 == 0xFF49 && jmp2 == 0xE3) {
24296+ regs->r11 = addr1;
24297+ regs->r10 = addr2;
24298+ regs->ip = addr1;
24299+ return 2;
24300+ }
24301+ } while (0);
24302+
24303+ return 1; /* PaX in action */
24304+}
24305+#endif
24306+
24307+/*
24308+ * PaX: decide what to do with offenders (regs->ip = fault address)
24309+ *
24310+ * returns 1 when task should be killed
24311+ * 2 when gcc trampoline was detected
24312+ */
24313+static int pax_handle_fetch_fault(struct pt_regs *regs)
24314+{
24315+ if (v8086_mode(regs))
24316+ return 1;
24317+
24318+ if (!(current->mm->pax_flags & MF_PAX_EMUTRAMP))
24319+ return 1;
24320+
24321+#ifdef CONFIG_X86_32
24322+ return pax_handle_fetch_fault_32(regs);
24323+#else
24324+ if (regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT))
24325+ return pax_handle_fetch_fault_32(regs);
24326+ else
24327+ return pax_handle_fetch_fault_64(regs);
24328+#endif
24329+}
24330+#endif
24331+
24332+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
24333+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
24334+{
24335+ long i;
24336+
24337+ printk(KERN_ERR "PAX: bytes at PC: ");
24338+ for (i = 0; i < 20; i++) {
24339+ unsigned char c;
24340+ if (get_user(c, (unsigned char __force_user *)pc+i))
24341+ printk(KERN_CONT "?? ");
24342+ else
24343+ printk(KERN_CONT "%02x ", c);
24344+ }
24345+ printk("\n");
24346+
24347+ printk(KERN_ERR "PAX: bytes at SP-%lu: ", (unsigned long)sizeof(long));
24348+ for (i = -1; i < 80 / (long)sizeof(long); i++) {
24349+ unsigned long c;
24350+ if (get_user(c, (unsigned long __force_user *)sp+i)) {
24351+#ifdef CONFIG_X86_32
24352+ printk(KERN_CONT "???????? ");
24353+#else
24354+ if ((regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT)))
24355+ printk(KERN_CONT "???????? ???????? ");
24356+ else
24357+ printk(KERN_CONT "???????????????? ");
24358+#endif
24359+ } else {
24360+#ifdef CONFIG_X86_64
24361+ if ((regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT))) {
24362+ printk(KERN_CONT "%08x ", (unsigned int)c);
24363+ printk(KERN_CONT "%08x ", (unsigned int)(c >> 32));
24364+ } else
24365+#endif
24366+ printk(KERN_CONT "%0*lx ", 2 * (int)sizeof(long), c);
24367+ }
24368+ }
24369+ printk("\n");
24370+}
24371+#endif
24372+
24373+/**
24374+ * probe_kernel_write(): safely attempt to write to a location
24375+ * @dst: address to write to
24376+ * @src: pointer to the data that shall be written
24377+ * @size: size of the data chunk
24378+ *
24379+ * Safely write to address @dst from the buffer at @src. If a kernel fault
24380+ * happens, handle that and return -EFAULT.
24381+ */
24382+long notrace probe_kernel_write(void *dst, const void *src, size_t size)
24383+{
24384+ long ret;
24385+ mm_segment_t old_fs = get_fs();
24386+
24387+ set_fs(KERNEL_DS);
24388+ pagefault_disable();
24389+ pax_open_kernel();
24390+ ret = __copy_to_user_inatomic((void __force_user *)dst, src, size);
24391+ pax_close_kernel();
24392+ pagefault_enable();
24393+ set_fs(old_fs);
24394+
24395+ return ret ? -EFAULT : 0;
24396+}
24397diff --git a/arch/x86/mm/gup.c b/arch/x86/mm/gup.c
24398index dd74e46..7d26398 100644
24399--- a/arch/x86/mm/gup.c
24400+++ b/arch/x86/mm/gup.c
24401@@ -255,7 +255,7 @@ int __get_user_pages_fast(unsigned long start, int nr_pages, int write,
24402 addr = start;
24403 len = (unsigned long) nr_pages << PAGE_SHIFT;
24404 end = start + len;
24405- if (unlikely(!access_ok(write ? VERIFY_WRITE : VERIFY_READ,
24406+ if (unlikely(!__access_ok(write ? VERIFY_WRITE : VERIFY_READ,
24407 (void __user *)start, len)))
24408 return 0;
24409
24410diff --git a/arch/x86/mm/highmem_32.c b/arch/x86/mm/highmem_32.c
24411index 6f31ee5..8ee4164 100644
24412--- a/arch/x86/mm/highmem_32.c
24413+++ b/arch/x86/mm/highmem_32.c
24414@@ -44,7 +44,11 @@ void *kmap_atomic_prot(struct page *page, pgprot_t prot)
24415 idx = type + KM_TYPE_NR*smp_processor_id();
24416 vaddr = __fix_to_virt(FIX_KMAP_BEGIN + idx);
24417 BUG_ON(!pte_none(*(kmap_pte-idx)));
24418+
24419+ pax_open_kernel();
24420 set_pte(kmap_pte-idx, mk_pte(page, prot));
24421+ pax_close_kernel();
24422+
24423 arch_flush_lazy_mmu_mode();
24424
24425 return (void *)vaddr;
24426diff --git a/arch/x86/mm/hugetlbpage.c b/arch/x86/mm/hugetlbpage.c
24427index b91e485..d00e7c9 100644
24428--- a/arch/x86/mm/hugetlbpage.c
24429+++ b/arch/x86/mm/hugetlbpage.c
24430@@ -277,13 +277,20 @@ static unsigned long hugetlb_get_unmapped_area_bottomup(struct file *file,
24431 struct hstate *h = hstate_file(file);
24432 struct mm_struct *mm = current->mm;
24433 struct vm_area_struct *vma;
24434- unsigned long start_addr;
24435+ unsigned long start_addr, pax_task_size = TASK_SIZE;
24436+
24437+#ifdef CONFIG_PAX_SEGMEXEC
24438+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
24439+ pax_task_size = SEGMEXEC_TASK_SIZE;
24440+#endif
24441+
24442+ pax_task_size -= PAGE_SIZE;
24443
24444 if (len > mm->cached_hole_size) {
24445- start_addr = mm->free_area_cache;
24446+ start_addr = mm->free_area_cache;
24447 } else {
24448- start_addr = TASK_UNMAPPED_BASE;
24449- mm->cached_hole_size = 0;
24450+ start_addr = mm->mmap_base;
24451+ mm->cached_hole_size = 0;
24452 }
24453
24454 full_search:
24455@@ -291,26 +298,27 @@ full_search:
24456
24457 for (vma = find_vma(mm, addr); ; vma = vma->vm_next) {
24458 /* At this point: (!vma || addr < vma->vm_end). */
24459- if (TASK_SIZE - len < addr) {
24460+ if (pax_task_size - len < addr) {
24461 /*
24462 * Start a new search - just in case we missed
24463 * some holes.
24464 */
24465- if (start_addr != TASK_UNMAPPED_BASE) {
24466- start_addr = TASK_UNMAPPED_BASE;
24467+ if (start_addr != mm->mmap_base) {
24468+ start_addr = mm->mmap_base;
24469 mm->cached_hole_size = 0;
24470 goto full_search;
24471 }
24472 return -ENOMEM;
24473 }
24474- if (!vma || addr + len <= vma->vm_start) {
24475- mm->free_area_cache = addr + len;
24476- return addr;
24477- }
24478+ if (check_heap_stack_gap(vma, addr, len))
24479+ break;
24480 if (addr + mm->cached_hole_size < vma->vm_start)
24481 mm->cached_hole_size = vma->vm_start - addr;
24482 addr = ALIGN(vma->vm_end, huge_page_size(h));
24483 }
24484+
24485+ mm->free_area_cache = addr + len;
24486+ return addr;
24487 }
24488
24489 static unsigned long hugetlb_get_unmapped_area_topdown(struct file *file,
24490@@ -321,9 +329,8 @@ static unsigned long hugetlb_get_unmapped_area_topdown(struct file *file,
24491 struct mm_struct *mm = current->mm;
24492 struct vm_area_struct *vma;
24493 unsigned long base = mm->mmap_base;
24494- unsigned long addr = addr0;
24495+ unsigned long addr;
24496 unsigned long largest_hole = mm->cached_hole_size;
24497- unsigned long start_addr;
24498
24499 /* don't allow allocations above current base */
24500 if (mm->free_area_cache > base)
24501@@ -333,16 +340,15 @@ static unsigned long hugetlb_get_unmapped_area_topdown(struct file *file,
24502 largest_hole = 0;
24503 mm->free_area_cache = base;
24504 }
24505-try_again:
24506- start_addr = mm->free_area_cache;
24507
24508 /* make sure it can fit in the remaining address space */
24509 if (mm->free_area_cache < len)
24510 goto fail;
24511
24512 /* either no address requested or can't fit in requested address hole */
24513- addr = (mm->free_area_cache - len) & huge_page_mask(h);
24514+ addr = mm->free_area_cache - len;
24515 do {
24516+ addr &= huge_page_mask(h);
24517 /*
24518 * Lookup failure means no vma is above this address,
24519 * i.e. return with success:
24520@@ -351,10 +357,10 @@ try_again:
24521 if (!vma)
24522 return addr;
24523
24524- if (addr + len <= vma->vm_start) {
24525+ if (check_heap_stack_gap(vma, addr, len)) {
24526 /* remember the address as a hint for next time */
24527- mm->cached_hole_size = largest_hole;
24528- return (mm->free_area_cache = addr);
24529+ mm->cached_hole_size = largest_hole;
24530+ return (mm->free_area_cache = addr);
24531 } else if (mm->free_area_cache == vma->vm_end) {
24532 /* pull free_area_cache down to the first hole */
24533 mm->free_area_cache = vma->vm_start;
24534@@ -363,29 +369,34 @@ try_again:
24535
24536 /* remember the largest hole we saw so far */
24537 if (addr + largest_hole < vma->vm_start)
24538- largest_hole = vma->vm_start - addr;
24539+ largest_hole = vma->vm_start - addr;
24540
24541 /* try just below the current vma->vm_start */
24542- addr = (vma->vm_start - len) & huge_page_mask(h);
24543- } while (len <= vma->vm_start);
24544+ addr = skip_heap_stack_gap(vma, len);
24545+ } while (!IS_ERR_VALUE(addr));
24546
24547 fail:
24548 /*
24549- * if hint left us with no space for the requested
24550- * mapping then try again:
24551- */
24552- if (start_addr != base) {
24553- mm->free_area_cache = base;
24554- largest_hole = 0;
24555- goto try_again;
24556- }
24557- /*
24558 * A failed mmap() very likely causes application failure,
24559 * so fall back to the bottom-up function here. This scenario
24560 * can happen with large stack limits and large mmap()
24561 * allocations.
24562 */
24563- mm->free_area_cache = TASK_UNMAPPED_BASE;
24564+
24565+#ifdef CONFIG_PAX_SEGMEXEC
24566+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
24567+ mm->mmap_base = SEGMEXEC_TASK_UNMAPPED_BASE;
24568+ else
24569+#endif
24570+
24571+ mm->mmap_base = TASK_UNMAPPED_BASE;
24572+
24573+#ifdef CONFIG_PAX_RANDMMAP
24574+ if (mm->pax_flags & MF_PAX_RANDMMAP)
24575+ mm->mmap_base += mm->delta_mmap;
24576+#endif
24577+
24578+ mm->free_area_cache = mm->mmap_base;
24579 mm->cached_hole_size = ~0UL;
24580 addr = hugetlb_get_unmapped_area_bottomup(file, addr0,
24581 len, pgoff, flags);
24582@@ -393,6 +404,7 @@ fail:
24583 /*
24584 * Restore the topdown base:
24585 */
24586+ mm->mmap_base = base;
24587 mm->free_area_cache = base;
24588 mm->cached_hole_size = ~0UL;
24589
24590@@ -406,10 +418,19 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
24591 struct hstate *h = hstate_file(file);
24592 struct mm_struct *mm = current->mm;
24593 struct vm_area_struct *vma;
24594+ unsigned long pax_task_size = TASK_SIZE;
24595
24596 if (len & ~huge_page_mask(h))
24597 return -EINVAL;
24598- if (len > TASK_SIZE)
24599+
24600+#ifdef CONFIG_PAX_SEGMEXEC
24601+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
24602+ pax_task_size = SEGMEXEC_TASK_SIZE;
24603+#endif
24604+
24605+ pax_task_size -= PAGE_SIZE;
24606+
24607+ if (len > pax_task_size)
24608 return -ENOMEM;
24609
24610 if (flags & MAP_FIXED) {
24611@@ -421,8 +442,7 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
24612 if (addr) {
24613 addr = ALIGN(addr, huge_page_size(h));
24614 vma = find_vma(mm, addr);
24615- if (TASK_SIZE - len >= addr &&
24616- (!vma || addr + len <= vma->vm_start))
24617+ if (pax_task_size - len >= addr && check_heap_stack_gap(vma, addr, len))
24618 return addr;
24619 }
24620 if (mm->get_unmapped_area == arch_get_unmapped_area)
24621diff --git a/arch/x86/mm/init.c b/arch/x86/mm/init.c
24622index d7aea41..0fc945b 100644
24623--- a/arch/x86/mm/init.c
24624+++ b/arch/x86/mm/init.c
24625@@ -4,6 +4,7 @@
24626 #include <linux/swap.h>
24627 #include <linux/memblock.h>
24628 #include <linux/bootmem.h> /* for max_low_pfn */
24629+#include <linux/tboot.h>
24630
24631 #include <asm/cacheflush.h>
24632 #include <asm/e820.h>
24633@@ -16,6 +17,8 @@
24634 #include <asm/tlb.h>
24635 #include <asm/proto.h>
24636 #include <asm/dma.h> /* for MAX_DMA_PFN */
24637+#include <asm/desc.h>
24638+#include <asm/bios_ebda.h>
24639
24640 unsigned long __initdata pgt_buf_start;
24641 unsigned long __meminitdata pgt_buf_end;
24642@@ -44,7 +47,7 @@ static void __init find_early_table_space(struct map_range *mr, int nr_range)
24643 {
24644 int i;
24645 unsigned long puds = 0, pmds = 0, ptes = 0, tables;
24646- unsigned long start = 0, good_end;
24647+ unsigned long start = 0x100000, good_end;
24648 phys_addr_t base;
24649
24650 for (i = 0; i < nr_range; i++) {
24651@@ -321,10 +324,40 @@ unsigned long __init_refok init_memory_mapping(unsigned long start,
24652 * Access has to be given to non-kernel-ram areas as well, these contain the PCI
24653 * mmio resources as well as potential bios/acpi data regions.
24654 */
24655+
24656+#ifdef CONFIG_GRKERNSEC_KMEM
24657+static unsigned int ebda_start __read_only;
24658+static unsigned int ebda_end __read_only;
24659+#endif
24660+
24661 int devmem_is_allowed(unsigned long pagenr)
24662 {
24663- if (pagenr < 256)
24664+#ifdef CONFIG_GRKERNSEC_KMEM
24665+ /* allow BDA */
24666+ if (!pagenr)
24667 return 1;
24668+ /* allow EBDA */
24669+ if (pagenr >= ebda_start && pagenr < ebda_end)
24670+ return 1;
24671+ /* if tboot is in use, allow access to its hardcoded serial log range */
24672+ if (tboot_enabled() && ((0x60000 >> PAGE_SHIFT) <= pagenr) && (pagenr < (0x68000 >> PAGE_SHIFT)))
24673+ return 1;
24674+#else
24675+ if (!pagenr)
24676+ return 1;
24677+#ifdef CONFIG_VM86
24678+ if (pagenr < (ISA_START_ADDRESS >> PAGE_SHIFT))
24679+ return 1;
24680+#endif
24681+#endif
24682+
24683+ if ((ISA_START_ADDRESS >> PAGE_SHIFT) <= pagenr && pagenr < (ISA_END_ADDRESS >> PAGE_SHIFT))
24684+ return 1;
24685+#ifdef CONFIG_GRKERNSEC_KMEM
24686+ /* throw out everything else below 1MB */
24687+ if (pagenr <= 256)
24688+ return 0;
24689+#endif
24690 if (iomem_is_exclusive(pagenr << PAGE_SHIFT))
24691 return 0;
24692 if (!page_is_ram(pagenr))
24693@@ -381,8 +414,117 @@ void free_init_pages(char *what, unsigned long begin, unsigned long end)
24694 #endif
24695 }
24696
24697+#ifdef CONFIG_GRKERNSEC_KMEM
24698+static inline void gr_init_ebda(void)
24699+{
24700+ unsigned int ebda_addr;
24701+ unsigned int ebda_size = 0;
24702+
24703+ ebda_addr = get_bios_ebda();
24704+ if (ebda_addr) {
24705+ ebda_size = *(unsigned char *)phys_to_virt(ebda_addr);
24706+ ebda_size <<= 10;
24707+ }
24708+ if (ebda_addr && ebda_size) {
24709+ ebda_start = ebda_addr >> PAGE_SHIFT;
24710+ ebda_end = min((unsigned int)PAGE_ALIGN(ebda_addr + ebda_size), (unsigned int)0xa0000) >> PAGE_SHIFT;
24711+ } else {
24712+ ebda_start = 0x9f000 >> PAGE_SHIFT;
24713+ ebda_end = 0xa0000 >> PAGE_SHIFT;
24714+ }
24715+}
24716+#else
24717+static inline void gr_init_ebda(void) { }
24718+#endif
24719+
24720 void free_initmem(void)
24721 {
24722+#ifdef CONFIG_PAX_KERNEXEC
24723+#ifdef CONFIG_X86_32
24724+ /* PaX: limit KERNEL_CS to actual size */
24725+ unsigned long addr, limit;
24726+ struct desc_struct d;
24727+ int cpu;
24728+#else
24729+ pgd_t *pgd;
24730+ pud_t *pud;
24731+ pmd_t *pmd;
24732+ unsigned long addr, end;
24733+#endif
24734+#endif
24735+
24736+ gr_init_ebda();
24737+
24738+#ifdef CONFIG_PAX_KERNEXEC
24739+#ifdef CONFIG_X86_32
24740+ limit = paravirt_enabled() ? ktva_ktla(0xffffffff) : (unsigned long)&_etext;
24741+ limit = (limit - 1UL) >> PAGE_SHIFT;
24742+
24743+ memset(__LOAD_PHYSICAL_ADDR + PAGE_OFFSET, POISON_FREE_INITMEM, PAGE_SIZE);
24744+ for (cpu = 0; cpu < nr_cpu_ids; cpu++) {
24745+ pack_descriptor(&d, get_desc_base(&get_cpu_gdt_table(cpu)[GDT_ENTRY_KERNEL_CS]), limit, 0x9B, 0xC);
24746+ write_gdt_entry(get_cpu_gdt_table(cpu), GDT_ENTRY_KERNEL_CS, &d, DESCTYPE_S);
24747+ write_gdt_entry(get_cpu_gdt_table(cpu), GDT_ENTRY_KERNEXEC_KERNEL_CS, &d, DESCTYPE_S);
24748+ }
24749+
24750+ /* PaX: make KERNEL_CS read-only */
24751+ addr = PFN_ALIGN(ktla_ktva((unsigned long)&_text));
24752+ if (!paravirt_enabled())
24753+ set_memory_ro(addr, (PFN_ALIGN(_sdata) - addr) >> PAGE_SHIFT);
24754+/*
24755+ for (addr = ktla_ktva((unsigned long)&_text); addr < (unsigned long)&_sdata; addr += PMD_SIZE) {
24756+ pgd = pgd_offset_k(addr);
24757+ pud = pud_offset(pgd, addr);
24758+ pmd = pmd_offset(pud, addr);
24759+ set_pmd(pmd, __pmd(pmd_val(*pmd) & ~_PAGE_RW));
24760+ }
24761+*/
24762+#ifdef CONFIG_X86_PAE
24763+ set_memory_nx(PFN_ALIGN(__init_begin), (PFN_ALIGN(__init_end) - PFN_ALIGN(__init_begin)) >> PAGE_SHIFT);
24764+/*
24765+ for (addr = (unsigned long)&__init_begin; addr < (unsigned long)&__init_end; addr += PMD_SIZE) {
24766+ pgd = pgd_offset_k(addr);
24767+ pud = pud_offset(pgd, addr);
24768+ pmd = pmd_offset(pud, addr);
24769+ set_pmd(pmd, __pmd(pmd_val(*pmd) | (_PAGE_NX & __supported_pte_mask)));
24770+ }
24771+*/
24772+#endif
24773+
24774+#ifdef CONFIG_MODULES
24775+ set_memory_4k((unsigned long)MODULES_EXEC_VADDR, (MODULES_EXEC_END - MODULES_EXEC_VADDR) >> PAGE_SHIFT);
24776+#endif
24777+
24778+#else
24779+ /* PaX: make kernel code/rodata read-only, rest non-executable */
24780+ for (addr = __START_KERNEL_map; addr < __START_KERNEL_map + KERNEL_IMAGE_SIZE; addr += PMD_SIZE) {
24781+ pgd = pgd_offset_k(addr);
24782+ pud = pud_offset(pgd, addr);
24783+ pmd = pmd_offset(pud, addr);
24784+ if (!pmd_present(*pmd))
24785+ continue;
24786+ if ((unsigned long)_text <= addr && addr < (unsigned long)_sdata)
24787+ set_pmd(pmd, __pmd(pmd_val(*pmd) & ~_PAGE_RW));
24788+ else
24789+ set_pmd(pmd, __pmd(pmd_val(*pmd) | (_PAGE_NX & __supported_pte_mask)));
24790+ }
24791+
24792+ addr = (unsigned long)__va(__pa(__START_KERNEL_map));
24793+ end = addr + KERNEL_IMAGE_SIZE;
24794+ for (; addr < end; addr += PMD_SIZE) {
24795+ pgd = pgd_offset_k(addr);
24796+ pud = pud_offset(pgd, addr);
24797+ pmd = pmd_offset(pud, addr);
24798+ if (!pmd_present(*pmd))
24799+ continue;
24800+ if ((unsigned long)__va(__pa(_text)) <= addr && addr < (unsigned long)__va(__pa(_sdata)))
24801+ set_pmd(pmd, __pmd(pmd_val(*pmd) & ~_PAGE_RW));
24802+ }
24803+#endif
24804+
24805+ flush_tlb_all();
24806+#endif
24807+
24808 free_init_pages("unused kernel memory",
24809 (unsigned long)(&__init_begin),
24810 (unsigned long)(&__init_end));
24811diff --git a/arch/x86/mm/init_32.c b/arch/x86/mm/init_32.c
24812index 575d86f..4987469 100644
24813--- a/arch/x86/mm/init_32.c
24814+++ b/arch/x86/mm/init_32.c
24815@@ -73,36 +73,6 @@ static __init void *alloc_low_page(void)
24816 }
24817
24818 /*
24819- * Creates a middle page table and puts a pointer to it in the
24820- * given global directory entry. This only returns the gd entry
24821- * in non-PAE compilation mode, since the middle layer is folded.
24822- */
24823-static pmd_t * __init one_md_table_init(pgd_t *pgd)
24824-{
24825- pud_t *pud;
24826- pmd_t *pmd_table;
24827-
24828-#ifdef CONFIG_X86_PAE
24829- if (!(pgd_val(*pgd) & _PAGE_PRESENT)) {
24830- if (after_bootmem)
24831- pmd_table = (pmd_t *)alloc_bootmem_pages(PAGE_SIZE);
24832- else
24833- pmd_table = (pmd_t *)alloc_low_page();
24834- paravirt_alloc_pmd(&init_mm, __pa(pmd_table) >> PAGE_SHIFT);
24835- set_pgd(pgd, __pgd(__pa(pmd_table) | _PAGE_PRESENT));
24836- pud = pud_offset(pgd, 0);
24837- BUG_ON(pmd_table != pmd_offset(pud, 0));
24838-
24839- return pmd_table;
24840- }
24841-#endif
24842- pud = pud_offset(pgd, 0);
24843- pmd_table = pmd_offset(pud, 0);
24844-
24845- return pmd_table;
24846-}
24847-
24848-/*
24849 * Create a page table and place a pointer to it in a middle page
24850 * directory entry:
24851 */
24852@@ -122,13 +92,28 @@ static pte_t * __init one_page_table_init(pmd_t *pmd)
24853 page_table = (pte_t *)alloc_low_page();
24854
24855 paravirt_alloc_pte(&init_mm, __pa(page_table) >> PAGE_SHIFT);
24856+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
24857+ set_pmd(pmd, __pmd(__pa(page_table) | _KERNPG_TABLE));
24858+#else
24859 set_pmd(pmd, __pmd(__pa(page_table) | _PAGE_TABLE));
24860+#endif
24861 BUG_ON(page_table != pte_offset_kernel(pmd, 0));
24862 }
24863
24864 return pte_offset_kernel(pmd, 0);
24865 }
24866
24867+static pmd_t * __init one_md_table_init(pgd_t *pgd)
24868+{
24869+ pud_t *pud;
24870+ pmd_t *pmd_table;
24871+
24872+ pud = pud_offset(pgd, 0);
24873+ pmd_table = pmd_offset(pud, 0);
24874+
24875+ return pmd_table;
24876+}
24877+
24878 pmd_t * __init populate_extra_pmd(unsigned long vaddr)
24879 {
24880 int pgd_idx = pgd_index(vaddr);
24881@@ -202,6 +187,7 @@ page_table_range_init(unsigned long start, unsigned long end, pgd_t *pgd_base)
24882 int pgd_idx, pmd_idx;
24883 unsigned long vaddr;
24884 pgd_t *pgd;
24885+ pud_t *pud;
24886 pmd_t *pmd;
24887 pte_t *pte = NULL;
24888
24889@@ -211,8 +197,13 @@ page_table_range_init(unsigned long start, unsigned long end, pgd_t *pgd_base)
24890 pgd = pgd_base + pgd_idx;
24891
24892 for ( ; (pgd_idx < PTRS_PER_PGD) && (vaddr != end); pgd++, pgd_idx++) {
24893- pmd = one_md_table_init(pgd);
24894- pmd = pmd + pmd_index(vaddr);
24895+ pud = pud_offset(pgd, vaddr);
24896+ pmd = pmd_offset(pud, vaddr);
24897+
24898+#ifdef CONFIG_X86_PAE
24899+ paravirt_alloc_pmd(&init_mm, __pa(pmd) >> PAGE_SHIFT);
24900+#endif
24901+
24902 for (; (pmd_idx < PTRS_PER_PMD) && (vaddr != end);
24903 pmd++, pmd_idx++) {
24904 pte = page_table_kmap_check(one_page_table_init(pmd),
24905@@ -224,11 +215,20 @@ page_table_range_init(unsigned long start, unsigned long end, pgd_t *pgd_base)
24906 }
24907 }
24908
24909-static inline int is_kernel_text(unsigned long addr)
24910+static inline int is_kernel_text(unsigned long start, unsigned long end)
24911 {
24912- if (addr >= (unsigned long)_text && addr <= (unsigned long)__init_end)
24913- return 1;
24914- return 0;
24915+ if ((start > ktla_ktva((unsigned long)_etext) ||
24916+ end <= ktla_ktva((unsigned long)_stext)) &&
24917+ (start > ktla_ktva((unsigned long)_einittext) ||
24918+ end <= ktla_ktva((unsigned long)_sinittext)) &&
24919+
24920+#ifdef CONFIG_ACPI_SLEEP
24921+ (start > (unsigned long)__va(acpi_wakeup_address) + 0x4000 || end <= (unsigned long)__va(acpi_wakeup_address)) &&
24922+#endif
24923+
24924+ (start > (unsigned long)__va(0xfffff) || end <= (unsigned long)__va(0xc0000)))
24925+ return 0;
24926+ return 1;
24927 }
24928
24929 /*
24930@@ -245,9 +245,10 @@ kernel_physical_mapping_init(unsigned long start,
24931 unsigned long last_map_addr = end;
24932 unsigned long start_pfn, end_pfn;
24933 pgd_t *pgd_base = swapper_pg_dir;
24934- int pgd_idx, pmd_idx, pte_ofs;
24935+ unsigned int pgd_idx, pmd_idx, pte_ofs;
24936 unsigned long pfn;
24937 pgd_t *pgd;
24938+ pud_t *pud;
24939 pmd_t *pmd;
24940 pte_t *pte;
24941 unsigned pages_2m, pages_4k;
24942@@ -280,8 +281,13 @@ repeat:
24943 pfn = start_pfn;
24944 pgd_idx = pgd_index((pfn<<PAGE_SHIFT) + PAGE_OFFSET);
24945 pgd = pgd_base + pgd_idx;
24946- for (; pgd_idx < PTRS_PER_PGD; pgd++, pgd_idx++) {
24947- pmd = one_md_table_init(pgd);
24948+ for (; pgd_idx < PTRS_PER_PGD && pfn < max_low_pfn; pgd++, pgd_idx++) {
24949+ pud = pud_offset(pgd, 0);
24950+ pmd = pmd_offset(pud, 0);
24951+
24952+#ifdef CONFIG_X86_PAE
24953+ paravirt_alloc_pmd(&init_mm, __pa(pmd) >> PAGE_SHIFT);
24954+#endif
24955
24956 if (pfn >= end_pfn)
24957 continue;
24958@@ -293,14 +299,13 @@ repeat:
24959 #endif
24960 for (; pmd_idx < PTRS_PER_PMD && pfn < end_pfn;
24961 pmd++, pmd_idx++) {
24962- unsigned int addr = pfn * PAGE_SIZE + PAGE_OFFSET;
24963+ unsigned long address = pfn * PAGE_SIZE + PAGE_OFFSET;
24964
24965 /*
24966 * Map with big pages if possible, otherwise
24967 * create normal page tables:
24968 */
24969 if (use_pse) {
24970- unsigned int addr2;
24971 pgprot_t prot = PAGE_KERNEL_LARGE;
24972 /*
24973 * first pass will use the same initial
24974@@ -310,11 +315,7 @@ repeat:
24975 __pgprot(PTE_IDENT_ATTR |
24976 _PAGE_PSE);
24977
24978- addr2 = (pfn + PTRS_PER_PTE-1) * PAGE_SIZE +
24979- PAGE_OFFSET + PAGE_SIZE-1;
24980-
24981- if (is_kernel_text(addr) ||
24982- is_kernel_text(addr2))
24983+ if (is_kernel_text(address, address + PMD_SIZE))
24984 prot = PAGE_KERNEL_LARGE_EXEC;
24985
24986 pages_2m++;
24987@@ -331,7 +332,7 @@ repeat:
24988 pte_ofs = pte_index((pfn<<PAGE_SHIFT) + PAGE_OFFSET);
24989 pte += pte_ofs;
24990 for (; pte_ofs < PTRS_PER_PTE && pfn < end_pfn;
24991- pte++, pfn++, pte_ofs++, addr += PAGE_SIZE) {
24992+ pte++, pfn++, pte_ofs++, address += PAGE_SIZE) {
24993 pgprot_t prot = PAGE_KERNEL;
24994 /*
24995 * first pass will use the same initial
24996@@ -339,7 +340,7 @@ repeat:
24997 */
24998 pgprot_t init_prot = __pgprot(PTE_IDENT_ATTR);
24999
25000- if (is_kernel_text(addr))
25001+ if (is_kernel_text(address, address + PAGE_SIZE))
25002 prot = PAGE_KERNEL_EXEC;
25003
25004 pages_4k++;
25005@@ -465,7 +466,7 @@ void __init native_pagetable_setup_start(pgd_t *base)
25006
25007 pud = pud_offset(pgd, va);
25008 pmd = pmd_offset(pud, va);
25009- if (!pmd_present(*pmd))
25010+ if (!pmd_present(*pmd) || pmd_huge(*pmd))
25011 break;
25012
25013 pte = pte_offset_kernel(pmd, va);
25014@@ -517,12 +518,10 @@ void __init early_ioremap_page_table_range_init(void)
25015
25016 static void __init pagetable_init(void)
25017 {
25018- pgd_t *pgd_base = swapper_pg_dir;
25019-
25020- permanent_kmaps_init(pgd_base);
25021+ permanent_kmaps_init(swapper_pg_dir);
25022 }
25023
25024-pteval_t __supported_pte_mask __read_mostly = ~(_PAGE_NX | _PAGE_GLOBAL | _PAGE_IOMAP);
25025+pteval_t __supported_pte_mask __read_only = ~(_PAGE_NX | _PAGE_GLOBAL | _PAGE_IOMAP);
25026 EXPORT_SYMBOL_GPL(__supported_pte_mask);
25027
25028 /* user-defined highmem size */
25029@@ -734,6 +733,12 @@ void __init mem_init(void)
25030
25031 pci_iommu_alloc();
25032
25033+#ifdef CONFIG_PAX_PER_CPU_PGD
25034+ clone_pgd_range(get_cpu_pgd(0) + KERNEL_PGD_BOUNDARY,
25035+ swapper_pg_dir + KERNEL_PGD_BOUNDARY,
25036+ KERNEL_PGD_PTRS);
25037+#endif
25038+
25039 #ifdef CONFIG_FLATMEM
25040 BUG_ON(!mem_map);
25041 #endif
25042@@ -760,7 +765,7 @@ void __init mem_init(void)
25043 reservedpages++;
25044
25045 codesize = (unsigned long) &_etext - (unsigned long) &_text;
25046- datasize = (unsigned long) &_edata - (unsigned long) &_etext;
25047+ datasize = (unsigned long) &_edata - (unsigned long) &_sdata;
25048 initsize = (unsigned long) &__init_end - (unsigned long) &__init_begin;
25049
25050 printk(KERN_INFO "Memory: %luk/%luk available (%dk kernel code, "
25051@@ -801,10 +806,10 @@ void __init mem_init(void)
25052 ((unsigned long)&__init_end -
25053 (unsigned long)&__init_begin) >> 10,
25054
25055- (unsigned long)&_etext, (unsigned long)&_edata,
25056- ((unsigned long)&_edata - (unsigned long)&_etext) >> 10,
25057+ (unsigned long)&_sdata, (unsigned long)&_edata,
25058+ ((unsigned long)&_edata - (unsigned long)&_sdata) >> 10,
25059
25060- (unsigned long)&_text, (unsigned long)&_etext,
25061+ ktla_ktva((unsigned long)&_text), ktla_ktva((unsigned long)&_etext),
25062 ((unsigned long)&_etext - (unsigned long)&_text) >> 10);
25063
25064 /*
25065@@ -882,6 +887,7 @@ void set_kernel_text_rw(void)
25066 if (!kernel_set_to_readonly)
25067 return;
25068
25069+ start = ktla_ktva(start);
25070 pr_debug("Set kernel text: %lx - %lx for read write\n",
25071 start, start+size);
25072
25073@@ -896,6 +902,7 @@ void set_kernel_text_ro(void)
25074 if (!kernel_set_to_readonly)
25075 return;
25076
25077+ start = ktla_ktva(start);
25078 pr_debug("Set kernel text: %lx - %lx for read only\n",
25079 start, start+size);
25080
25081@@ -924,6 +931,7 @@ void mark_rodata_ro(void)
25082 unsigned long start = PFN_ALIGN(_text);
25083 unsigned long size = PFN_ALIGN(_etext) - start;
25084
25085+ start = ktla_ktva(start);
25086 set_pages_ro(virt_to_page(start), size >> PAGE_SHIFT);
25087 printk(KERN_INFO "Write protecting the kernel text: %luk\n",
25088 size >> 10);
25089diff --git a/arch/x86/mm/init_64.c b/arch/x86/mm/init_64.c
25090index 3baff25..8b37564 100644
25091--- a/arch/x86/mm/init_64.c
25092+++ b/arch/x86/mm/init_64.c
25093@@ -74,7 +74,7 @@ early_param("gbpages", parse_direct_gbpages_on);
25094 * around without checking the pgd every time.
25095 */
25096
25097-pteval_t __supported_pte_mask __read_mostly = ~_PAGE_IOMAP;
25098+pteval_t __supported_pte_mask __read_only = ~(_PAGE_NX | _PAGE_IOMAP);
25099 EXPORT_SYMBOL_GPL(__supported_pte_mask);
25100
25101 int force_personality32;
25102@@ -107,12 +107,22 @@ void sync_global_pgds(unsigned long start, unsigned long end)
25103
25104 for (address = start; address <= end; address += PGDIR_SIZE) {
25105 const pgd_t *pgd_ref = pgd_offset_k(address);
25106+
25107+#ifdef CONFIG_PAX_PER_CPU_PGD
25108+ unsigned long cpu;
25109+#else
25110 struct page *page;
25111+#endif
25112
25113 if (pgd_none(*pgd_ref))
25114 continue;
25115
25116 spin_lock(&pgd_lock);
25117+
25118+#ifdef CONFIG_PAX_PER_CPU_PGD
25119+ for (cpu = 0; cpu < nr_cpu_ids; ++cpu) {
25120+ pgd_t *pgd = pgd_offset_cpu(cpu, address);
25121+#else
25122 list_for_each_entry(page, &pgd_list, lru) {
25123 pgd_t *pgd;
25124 spinlock_t *pgt_lock;
25125@@ -121,6 +131,7 @@ void sync_global_pgds(unsigned long start, unsigned long end)
25126 /* the pgt_lock only for Xen */
25127 pgt_lock = &pgd_page_get_mm(page)->page_table_lock;
25128 spin_lock(pgt_lock);
25129+#endif
25130
25131 if (pgd_none(*pgd))
25132 set_pgd(pgd, *pgd_ref);
25133@@ -128,7 +139,10 @@ void sync_global_pgds(unsigned long start, unsigned long end)
25134 BUG_ON(pgd_page_vaddr(*pgd)
25135 != pgd_page_vaddr(*pgd_ref));
25136
25137+#ifndef CONFIG_PAX_PER_CPU_PGD
25138 spin_unlock(pgt_lock);
25139+#endif
25140+
25141 }
25142 spin_unlock(&pgd_lock);
25143 }
25144@@ -161,7 +175,7 @@ static pud_t *fill_pud(pgd_t *pgd, unsigned long vaddr)
25145 {
25146 if (pgd_none(*pgd)) {
25147 pud_t *pud = (pud_t *)spp_getpage();
25148- pgd_populate(&init_mm, pgd, pud);
25149+ pgd_populate_kernel(&init_mm, pgd, pud);
25150 if (pud != pud_offset(pgd, 0))
25151 printk(KERN_ERR "PAGETABLE BUG #00! %p <-> %p\n",
25152 pud, pud_offset(pgd, 0));
25153@@ -173,7 +187,7 @@ static pmd_t *fill_pmd(pud_t *pud, unsigned long vaddr)
25154 {
25155 if (pud_none(*pud)) {
25156 pmd_t *pmd = (pmd_t *) spp_getpage();
25157- pud_populate(&init_mm, pud, pmd);
25158+ pud_populate_kernel(&init_mm, pud, pmd);
25159 if (pmd != pmd_offset(pud, 0))
25160 printk(KERN_ERR "PAGETABLE BUG #01! %p <-> %p\n",
25161 pmd, pmd_offset(pud, 0));
25162@@ -202,7 +216,9 @@ void set_pte_vaddr_pud(pud_t *pud_page, unsigned long vaddr, pte_t new_pte)
25163 pmd = fill_pmd(pud, vaddr);
25164 pte = fill_pte(pmd, vaddr);
25165
25166+ pax_open_kernel();
25167 set_pte(pte, new_pte);
25168+ pax_close_kernel();
25169
25170 /*
25171 * It's enough to flush this one mapping.
25172@@ -261,14 +277,12 @@ static void __init __init_extra_mapping(unsigned long phys, unsigned long size,
25173 pgd = pgd_offset_k((unsigned long)__va(phys));
25174 if (pgd_none(*pgd)) {
25175 pud = (pud_t *) spp_getpage();
25176- set_pgd(pgd, __pgd(__pa(pud) | _KERNPG_TABLE |
25177- _PAGE_USER));
25178+ set_pgd(pgd, __pgd(__pa(pud) | _PAGE_TABLE));
25179 }
25180 pud = pud_offset(pgd, (unsigned long)__va(phys));
25181 if (pud_none(*pud)) {
25182 pmd = (pmd_t *) spp_getpage();
25183- set_pud(pud, __pud(__pa(pmd) | _KERNPG_TABLE |
25184- _PAGE_USER));
25185+ set_pud(pud, __pud(__pa(pmd) | _PAGE_TABLE));
25186 }
25187 pmd = pmd_offset(pud, phys);
25188 BUG_ON(!pmd_none(*pmd));
25189@@ -329,7 +343,7 @@ static __ref void *alloc_low_page(unsigned long *phys)
25190 if (pfn >= pgt_buf_top)
25191 panic("alloc_low_page: ran out of memory");
25192
25193- adr = early_memremap(pfn * PAGE_SIZE, PAGE_SIZE);
25194+ adr = (void __force_kernel *)early_memremap(pfn * PAGE_SIZE, PAGE_SIZE);
25195 clear_page(adr);
25196 *phys = pfn * PAGE_SIZE;
25197 return adr;
25198@@ -345,7 +359,7 @@ static __ref void *map_low_page(void *virt)
25199
25200 phys = __pa(virt);
25201 left = phys & (PAGE_SIZE - 1);
25202- adr = early_memremap(phys & PAGE_MASK, PAGE_SIZE);
25203+ adr = (void __force_kernel *)early_memremap(phys & PAGE_MASK, PAGE_SIZE);
25204 adr = (void *)(((unsigned long)adr) | left);
25205
25206 return adr;
25207@@ -553,7 +567,7 @@ phys_pud_init(pud_t *pud_page, unsigned long addr, unsigned long end,
25208 unmap_low_page(pmd);
25209
25210 spin_lock(&init_mm.page_table_lock);
25211- pud_populate(&init_mm, pud, __va(pmd_phys));
25212+ pud_populate_kernel(&init_mm, pud, __va(pmd_phys));
25213 spin_unlock(&init_mm.page_table_lock);
25214 }
25215 __flush_tlb_all();
25216@@ -599,7 +613,7 @@ kernel_physical_mapping_init(unsigned long start,
25217 unmap_low_page(pud);
25218
25219 spin_lock(&init_mm.page_table_lock);
25220- pgd_populate(&init_mm, pgd, __va(pud_phys));
25221+ pgd_populate_kernel(&init_mm, pgd, __va(pud_phys));
25222 spin_unlock(&init_mm.page_table_lock);
25223 pgd_changed = true;
25224 }
25225@@ -691,6 +705,12 @@ void __init mem_init(void)
25226
25227 pci_iommu_alloc();
25228
25229+#ifdef CONFIG_PAX_PER_CPU_PGD
25230+ clone_pgd_range(get_cpu_pgd(0) + KERNEL_PGD_BOUNDARY,
25231+ swapper_pg_dir + KERNEL_PGD_BOUNDARY,
25232+ KERNEL_PGD_PTRS);
25233+#endif
25234+
25235 /* clear_bss() already clear the empty_zero_page */
25236
25237 reservedpages = 0;
25238@@ -851,8 +871,8 @@ int kern_addr_valid(unsigned long addr)
25239 static struct vm_area_struct gate_vma = {
25240 .vm_start = VSYSCALL_START,
25241 .vm_end = VSYSCALL_START + (VSYSCALL_MAPPED_PAGES * PAGE_SIZE),
25242- .vm_page_prot = PAGE_READONLY_EXEC,
25243- .vm_flags = VM_READ | VM_EXEC
25244+ .vm_page_prot = PAGE_READONLY,
25245+ .vm_flags = VM_READ
25246 };
25247
25248 struct vm_area_struct *get_gate_vma(struct mm_struct *mm)
25249@@ -886,7 +906,7 @@ int in_gate_area_no_mm(unsigned long addr)
25250
25251 const char *arch_vma_name(struct vm_area_struct *vma)
25252 {
25253- if (vma->vm_mm && vma->vm_start == (long)vma->vm_mm->context.vdso)
25254+ if (vma->vm_mm && vma->vm_start == vma->vm_mm->context.vdso)
25255 return "[vdso]";
25256 if (vma == &gate_vma)
25257 return "[vsyscall]";
25258diff --git a/arch/x86/mm/iomap_32.c b/arch/x86/mm/iomap_32.c
25259index 7b179b4..6bd1777 100644
25260--- a/arch/x86/mm/iomap_32.c
25261+++ b/arch/x86/mm/iomap_32.c
25262@@ -64,7 +64,11 @@ void *kmap_atomic_prot_pfn(unsigned long pfn, pgprot_t prot)
25263 type = kmap_atomic_idx_push();
25264 idx = type + KM_TYPE_NR * smp_processor_id();
25265 vaddr = __fix_to_virt(FIX_KMAP_BEGIN + idx);
25266+
25267+ pax_open_kernel();
25268 set_pte(kmap_pte - idx, pfn_pte(pfn, prot));
25269+ pax_close_kernel();
25270+
25271 arch_flush_lazy_mmu_mode();
25272
25273 return (void *)vaddr;
25274diff --git a/arch/x86/mm/ioremap.c b/arch/x86/mm/ioremap.c
25275index 78fe3f1..8293b6f 100644
25276--- a/arch/x86/mm/ioremap.c
25277+++ b/arch/x86/mm/ioremap.c
25278@@ -97,7 +97,7 @@ static void __iomem *__ioremap_caller(resource_size_t phys_addr,
25279 for (pfn = phys_addr >> PAGE_SHIFT; pfn <= last_pfn; pfn++) {
25280 int is_ram = page_is_ram(pfn);
25281
25282- if (is_ram && pfn_valid(pfn) && !PageReserved(pfn_to_page(pfn)))
25283+ if (is_ram && pfn_valid(pfn) && (pfn >= 0x100 || !PageReserved(pfn_to_page(pfn))))
25284 return NULL;
25285 WARN_ON_ONCE(is_ram);
25286 }
25287@@ -315,6 +315,9 @@ void *xlate_dev_mem_ptr(unsigned long phys)
25288
25289 /* If page is RAM, we can use __va. Otherwise ioremap and unmap. */
25290 if (page_is_ram(start >> PAGE_SHIFT))
25291+#ifdef CONFIG_HIGHMEM
25292+ if ((start >> PAGE_SHIFT) < max_low_pfn)
25293+#endif
25294 return __va(phys);
25295
25296 addr = (void __force *)ioremap_cache(start, PAGE_SIZE);
25297@@ -344,7 +347,7 @@ static int __init early_ioremap_debug_setup(char *str)
25298 early_param("early_ioremap_debug", early_ioremap_debug_setup);
25299
25300 static __initdata int after_paging_init;
25301-static pte_t bm_pte[PAGE_SIZE/sizeof(pte_t)] __page_aligned_bss;
25302+static pte_t bm_pte[PAGE_SIZE/sizeof(pte_t)] __read_only __aligned(PAGE_SIZE);
25303
25304 static inline pmd_t * __init early_ioremap_pmd(unsigned long addr)
25305 {
25306@@ -381,8 +384,7 @@ void __init early_ioremap_init(void)
25307 slot_virt[i] = __fix_to_virt(FIX_BTMAP_BEGIN - NR_FIX_BTMAPS*i);
25308
25309 pmd = early_ioremap_pmd(fix_to_virt(FIX_BTMAP_BEGIN));
25310- memset(bm_pte, 0, sizeof(bm_pte));
25311- pmd_populate_kernel(&init_mm, pmd, bm_pte);
25312+ pmd_populate_user(&init_mm, pmd, bm_pte);
25313
25314 /*
25315 * The boot-ioremap range spans multiple pmds, for which
25316diff --git a/arch/x86/mm/kmemcheck/kmemcheck.c b/arch/x86/mm/kmemcheck/kmemcheck.c
25317index d87dd6d..bf3fa66 100644
25318--- a/arch/x86/mm/kmemcheck/kmemcheck.c
25319+++ b/arch/x86/mm/kmemcheck/kmemcheck.c
25320@@ -622,9 +622,9 @@ bool kmemcheck_fault(struct pt_regs *regs, unsigned long address,
25321 * memory (e.g. tracked pages)? For now, we need this to avoid
25322 * invoking kmemcheck for PnP BIOS calls.
25323 */
25324- if (regs->flags & X86_VM_MASK)
25325+ if (v8086_mode(regs))
25326 return false;
25327- if (regs->cs != __KERNEL_CS)
25328+ if (regs->cs != __KERNEL_CS && regs->cs != __KERNEXEC_KERNEL_CS)
25329 return false;
25330
25331 pte = kmemcheck_pte_lookup(address);
25332diff --git a/arch/x86/mm/mmap.c b/arch/x86/mm/mmap.c
25333index 845df68..1d8d29f 100644
25334--- a/arch/x86/mm/mmap.c
25335+++ b/arch/x86/mm/mmap.c
25336@@ -52,7 +52,7 @@ static unsigned int stack_maxrandom_size(void)
25337 * Leave an at least ~128 MB hole with possible stack randomization.
25338 */
25339 #define MIN_GAP (128*1024*1024UL + stack_maxrandom_size())
25340-#define MAX_GAP (TASK_SIZE/6*5)
25341+#define MAX_GAP (pax_task_size/6*5)
25342
25343 static int mmap_is_legacy(void)
25344 {
25345@@ -82,27 +82,40 @@ static unsigned long mmap_rnd(void)
25346 return rnd << PAGE_SHIFT;
25347 }
25348
25349-static unsigned long mmap_base(void)
25350+static unsigned long mmap_base(struct mm_struct *mm)
25351 {
25352 unsigned long gap = rlimit(RLIMIT_STACK);
25353+ unsigned long pax_task_size = TASK_SIZE;
25354+
25355+#ifdef CONFIG_PAX_SEGMEXEC
25356+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
25357+ pax_task_size = SEGMEXEC_TASK_SIZE;
25358+#endif
25359
25360 if (gap < MIN_GAP)
25361 gap = MIN_GAP;
25362 else if (gap > MAX_GAP)
25363 gap = MAX_GAP;
25364
25365- return PAGE_ALIGN(TASK_SIZE - gap - mmap_rnd());
25366+ return PAGE_ALIGN(pax_task_size - gap - mmap_rnd());
25367 }
25368
25369 /*
25370 * Bottom-up (legacy) layout on X86_32 did not support randomization, X86_64
25371 * does, but not when emulating X86_32
25372 */
25373-static unsigned long mmap_legacy_base(void)
25374+static unsigned long mmap_legacy_base(struct mm_struct *mm)
25375 {
25376- if (mmap_is_ia32())
25377+ if (mmap_is_ia32()) {
25378+
25379+#ifdef CONFIG_PAX_SEGMEXEC
25380+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
25381+ return SEGMEXEC_TASK_UNMAPPED_BASE;
25382+ else
25383+#endif
25384+
25385 return TASK_UNMAPPED_BASE;
25386- else
25387+ } else
25388 return TASK_UNMAPPED_BASE + mmap_rnd();
25389 }
25390
25391@@ -113,11 +126,23 @@ static unsigned long mmap_legacy_base(void)
25392 void arch_pick_mmap_layout(struct mm_struct *mm)
25393 {
25394 if (mmap_is_legacy()) {
25395- mm->mmap_base = mmap_legacy_base();
25396+ mm->mmap_base = mmap_legacy_base(mm);
25397+
25398+#ifdef CONFIG_PAX_RANDMMAP
25399+ if (mm->pax_flags & MF_PAX_RANDMMAP)
25400+ mm->mmap_base += mm->delta_mmap;
25401+#endif
25402+
25403 mm->get_unmapped_area = arch_get_unmapped_area;
25404 mm->unmap_area = arch_unmap_area;
25405 } else {
25406- mm->mmap_base = mmap_base();
25407+ mm->mmap_base = mmap_base(mm);
25408+
25409+#ifdef CONFIG_PAX_RANDMMAP
25410+ if (mm->pax_flags & MF_PAX_RANDMMAP)
25411+ mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
25412+#endif
25413+
25414 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
25415 mm->unmap_area = arch_unmap_area_topdown;
25416 }
25417diff --git a/arch/x86/mm/mmio-mod.c b/arch/x86/mm/mmio-mod.c
25418index dc0b727..dc9d71a 100644
25419--- a/arch/x86/mm/mmio-mod.c
25420+++ b/arch/x86/mm/mmio-mod.c
25421@@ -194,7 +194,7 @@ static void pre(struct kmmio_probe *p, struct pt_regs *regs,
25422 break;
25423 default:
25424 {
25425- unsigned char *ip = (unsigned char *)instptr;
25426+ unsigned char *ip = (unsigned char *)ktla_ktva(instptr);
25427 my_trace->opcode = MMIO_UNKNOWN_OP;
25428 my_trace->width = 0;
25429 my_trace->value = (*ip) << 16 | *(ip + 1) << 8 |
25430@@ -234,7 +234,7 @@ static void post(struct kmmio_probe *p, unsigned long condition,
25431 static void ioremap_trace_core(resource_size_t offset, unsigned long size,
25432 void __iomem *addr)
25433 {
25434- static atomic_t next_id;
25435+ static atomic_unchecked_t next_id;
25436 struct remap_trace *trace = kmalloc(sizeof(*trace), GFP_KERNEL);
25437 /* These are page-unaligned. */
25438 struct mmiotrace_map map = {
25439@@ -258,7 +258,7 @@ static void ioremap_trace_core(resource_size_t offset, unsigned long size,
25440 .private = trace
25441 },
25442 .phys = offset,
25443- .id = atomic_inc_return(&next_id)
25444+ .id = atomic_inc_return_unchecked(&next_id)
25445 };
25446 map.map_id = trace->id;
25447
25448diff --git a/arch/x86/mm/pageattr-test.c b/arch/x86/mm/pageattr-test.c
25449index b008656..773eac2 100644
25450--- a/arch/x86/mm/pageattr-test.c
25451+++ b/arch/x86/mm/pageattr-test.c
25452@@ -36,7 +36,7 @@ enum {
25453
25454 static int pte_testbit(pte_t pte)
25455 {
25456- return pte_flags(pte) & _PAGE_UNUSED1;
25457+ return pte_flags(pte) & _PAGE_CPA_TEST;
25458 }
25459
25460 struct split_state {
25461diff --git a/arch/x86/mm/pageattr.c b/arch/x86/mm/pageattr.c
25462index a718e0d..45efc32 100644
25463--- a/arch/x86/mm/pageattr.c
25464+++ b/arch/x86/mm/pageattr.c
25465@@ -261,7 +261,7 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
25466 */
25467 #ifdef CONFIG_PCI_BIOS
25468 if (pcibios_enabled && within(pfn, BIOS_BEGIN >> PAGE_SHIFT, BIOS_END >> PAGE_SHIFT))
25469- pgprot_val(forbidden) |= _PAGE_NX;
25470+ pgprot_val(forbidden) |= _PAGE_NX & __supported_pte_mask;
25471 #endif
25472
25473 /*
25474@@ -269,9 +269,10 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
25475 * Does not cover __inittext since that is gone later on. On
25476 * 64bit we do not enforce !NX on the low mapping
25477 */
25478- if (within(address, (unsigned long)_text, (unsigned long)_etext))
25479- pgprot_val(forbidden) |= _PAGE_NX;
25480+ if (within(address, ktla_ktva((unsigned long)_text), ktla_ktva((unsigned long)_etext)))
25481+ pgprot_val(forbidden) |= _PAGE_NX & __supported_pte_mask;
25482
25483+#ifdef CONFIG_DEBUG_RODATA
25484 /*
25485 * The .rodata section needs to be read-only. Using the pfn
25486 * catches all aliases.
25487@@ -279,6 +280,7 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
25488 if (within(pfn, __pa((unsigned long)__start_rodata) >> PAGE_SHIFT,
25489 __pa((unsigned long)__end_rodata) >> PAGE_SHIFT))
25490 pgprot_val(forbidden) |= _PAGE_RW;
25491+#endif
25492
25493 #if defined(CONFIG_X86_64) && defined(CONFIG_DEBUG_RODATA)
25494 /*
25495@@ -317,6 +319,13 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
25496 }
25497 #endif
25498
25499+#ifdef CONFIG_PAX_KERNEXEC
25500+ if (within(pfn, __pa((unsigned long)&_text), __pa((unsigned long)&_sdata))) {
25501+ pgprot_val(forbidden) |= _PAGE_RW;
25502+ pgprot_val(forbidden) |= _PAGE_NX & __supported_pte_mask;
25503+ }
25504+#endif
25505+
25506 prot = __pgprot(pgprot_val(prot) & ~pgprot_val(forbidden));
25507
25508 return prot;
25509@@ -369,23 +378,37 @@ EXPORT_SYMBOL_GPL(lookup_address);
25510 static void __set_pmd_pte(pte_t *kpte, unsigned long address, pte_t pte)
25511 {
25512 /* change init_mm */
25513+ pax_open_kernel();
25514 set_pte_atomic(kpte, pte);
25515+
25516 #ifdef CONFIG_X86_32
25517 if (!SHARED_KERNEL_PMD) {
25518+
25519+#ifdef CONFIG_PAX_PER_CPU_PGD
25520+ unsigned long cpu;
25521+#else
25522 struct page *page;
25523+#endif
25524
25525+#ifdef CONFIG_PAX_PER_CPU_PGD
25526+ for (cpu = 0; cpu < nr_cpu_ids; ++cpu) {
25527+ pgd_t *pgd = get_cpu_pgd(cpu);
25528+#else
25529 list_for_each_entry(page, &pgd_list, lru) {
25530- pgd_t *pgd;
25531+ pgd_t *pgd = (pgd_t *)page_address(page);
25532+#endif
25533+
25534 pud_t *pud;
25535 pmd_t *pmd;
25536
25537- pgd = (pgd_t *)page_address(page) + pgd_index(address);
25538+ pgd += pgd_index(address);
25539 pud = pud_offset(pgd, address);
25540 pmd = pmd_offset(pud, address);
25541 set_pte_atomic((pte_t *)pmd, pte);
25542 }
25543 }
25544 #endif
25545+ pax_close_kernel();
25546 }
25547
25548 static int
25549diff --git a/arch/x86/mm/pat.c b/arch/x86/mm/pat.c
25550index 3d68ef6..7f69136 100644
25551--- a/arch/x86/mm/pat.c
25552+++ b/arch/x86/mm/pat.c
25553@@ -376,7 +376,7 @@ int free_memtype(u64 start, u64 end)
25554
25555 if (!entry) {
25556 printk(KERN_INFO "%s:%d freeing invalid memtype [mem %#010Lx-%#010Lx]\n",
25557- current->comm, current->pid, start, end - 1);
25558+ current->comm, task_pid_nr(current), start, end - 1);
25559 return -EINVAL;
25560 }
25561
25562@@ -506,8 +506,8 @@ static inline int range_is_allowed(unsigned long pfn, unsigned long size)
25563
25564 while (cursor < to) {
25565 if (!devmem_is_allowed(pfn)) {
25566- printk(KERN_INFO "Program %s tried to access /dev/mem between [mem %#010Lx-%#010Lx]\n",
25567- current->comm, from, to - 1);
25568+ printk(KERN_INFO "Program %s tried to access /dev/mem between [mem %#010Lx-%#010Lx] (%#010Lx)\n",
25569+ current->comm, from, to - 1, cursor);
25570 return 0;
25571 }
25572 cursor += PAGE_SIZE;
25573@@ -570,7 +570,7 @@ int kernel_map_sync_memtype(u64 base, unsigned long size, unsigned long flags)
25574 if (ioremap_change_attr((unsigned long)__va(base), id_sz, flags) < 0) {
25575 printk(KERN_INFO "%s:%d ioremap_change_attr failed %s "
25576 "for [mem %#010Lx-%#010Lx]\n",
25577- current->comm, current->pid,
25578+ current->comm, task_pid_nr(current),
25579 cattr_name(flags),
25580 base, (unsigned long long)(base + size-1));
25581 return -EINVAL;
25582@@ -605,7 +605,7 @@ static int reserve_pfn_range(u64 paddr, unsigned long size, pgprot_t *vma_prot,
25583 flags = lookup_memtype(paddr);
25584 if (want_flags != flags) {
25585 printk(KERN_WARNING "%s:%d map pfn RAM range req %s for [mem %#010Lx-%#010Lx], got %s\n",
25586- current->comm, current->pid,
25587+ current->comm, task_pid_nr(current),
25588 cattr_name(want_flags),
25589 (unsigned long long)paddr,
25590 (unsigned long long)(paddr + size - 1),
25591@@ -627,7 +627,7 @@ static int reserve_pfn_range(u64 paddr, unsigned long size, pgprot_t *vma_prot,
25592 free_memtype(paddr, paddr + size);
25593 printk(KERN_ERR "%s:%d map pfn expected mapping type %s"
25594 " for [mem %#010Lx-%#010Lx], got %s\n",
25595- current->comm, current->pid,
25596+ current->comm, task_pid_nr(current),
25597 cattr_name(want_flags),
25598 (unsigned long long)paddr,
25599 (unsigned long long)(paddr + size - 1),
25600diff --git a/arch/x86/mm/pf_in.c b/arch/x86/mm/pf_in.c
25601index 9f0614d..92ae64a 100644
25602--- a/arch/x86/mm/pf_in.c
25603+++ b/arch/x86/mm/pf_in.c
25604@@ -148,7 +148,7 @@ enum reason_type get_ins_type(unsigned long ins_addr)
25605 int i;
25606 enum reason_type rv = OTHERS;
25607
25608- p = (unsigned char *)ins_addr;
25609+ p = (unsigned char *)ktla_ktva(ins_addr);
25610 p += skip_prefix(p, &prf);
25611 p += get_opcode(p, &opcode);
25612
25613@@ -168,7 +168,7 @@ static unsigned int get_ins_reg_width(unsigned long ins_addr)
25614 struct prefix_bits prf;
25615 int i;
25616
25617- p = (unsigned char *)ins_addr;
25618+ p = (unsigned char *)ktla_ktva(ins_addr);
25619 p += skip_prefix(p, &prf);
25620 p += get_opcode(p, &opcode);
25621
25622@@ -191,7 +191,7 @@ unsigned int get_ins_mem_width(unsigned long ins_addr)
25623 struct prefix_bits prf;
25624 int i;
25625
25626- p = (unsigned char *)ins_addr;
25627+ p = (unsigned char *)ktla_ktva(ins_addr);
25628 p += skip_prefix(p, &prf);
25629 p += get_opcode(p, &opcode);
25630
25631@@ -415,7 +415,7 @@ unsigned long get_ins_reg_val(unsigned long ins_addr, struct pt_regs *regs)
25632 struct prefix_bits prf;
25633 int i;
25634
25635- p = (unsigned char *)ins_addr;
25636+ p = (unsigned char *)ktla_ktva(ins_addr);
25637 p += skip_prefix(p, &prf);
25638 p += get_opcode(p, &opcode);
25639 for (i = 0; i < ARRAY_SIZE(reg_rop); i++)
25640@@ -470,7 +470,7 @@ unsigned long get_ins_imm_val(unsigned long ins_addr)
25641 struct prefix_bits prf;
25642 int i;
25643
25644- p = (unsigned char *)ins_addr;
25645+ p = (unsigned char *)ktla_ktva(ins_addr);
25646 p += skip_prefix(p, &prf);
25647 p += get_opcode(p, &opcode);
25648 for (i = 0; i < ARRAY_SIZE(imm_wop); i++)
25649diff --git a/arch/x86/mm/pgtable.c b/arch/x86/mm/pgtable.c
25650index 8573b83..4f3ed7e 100644
25651--- a/arch/x86/mm/pgtable.c
25652+++ b/arch/x86/mm/pgtable.c
25653@@ -84,10 +84,64 @@ static inline void pgd_list_del(pgd_t *pgd)
25654 list_del(&page->lru);
25655 }
25656
25657-#define UNSHARED_PTRS_PER_PGD \
25658- (SHARED_KERNEL_PMD ? KERNEL_PGD_BOUNDARY : PTRS_PER_PGD)
25659+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
25660+pgdval_t clone_pgd_mask __read_only = ~_PAGE_PRESENT;
25661
25662+void __shadow_user_pgds(pgd_t *dst, const pgd_t *src)
25663+{
25664+ unsigned int count = USER_PGD_PTRS;
25665
25666+ while (count--)
25667+ *dst++ = __pgd((pgd_val(*src++) | (_PAGE_NX & __supported_pte_mask)) & ~_PAGE_USER);
25668+}
25669+#endif
25670+
25671+#ifdef CONFIG_PAX_PER_CPU_PGD
25672+void __clone_user_pgds(pgd_t *dst, const pgd_t *src)
25673+{
25674+ unsigned int count = USER_PGD_PTRS;
25675+
25676+ while (count--) {
25677+ pgd_t pgd;
25678+
25679+#ifdef CONFIG_X86_64
25680+ pgd = __pgd(pgd_val(*src++) | _PAGE_USER);
25681+#else
25682+ pgd = *src++;
25683+#endif
25684+
25685+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
25686+ pgd = __pgd(pgd_val(pgd) & clone_pgd_mask);
25687+#endif
25688+
25689+ *dst++ = pgd;
25690+ }
25691+
25692+}
25693+#endif
25694+
25695+#ifdef CONFIG_X86_64
25696+#define pxd_t pud_t
25697+#define pyd_t pgd_t
25698+#define paravirt_release_pxd(pfn) paravirt_release_pud(pfn)
25699+#define pxd_free(mm, pud) pud_free((mm), (pud))
25700+#define pyd_populate(mm, pgd, pud) pgd_populate((mm), (pgd), (pud))
25701+#define pyd_offset(mm, address) pgd_offset((mm), (address))
25702+#define PYD_SIZE PGDIR_SIZE
25703+#else
25704+#define pxd_t pmd_t
25705+#define pyd_t pud_t
25706+#define paravirt_release_pxd(pfn) paravirt_release_pmd(pfn)
25707+#define pxd_free(mm, pud) pmd_free((mm), (pud))
25708+#define pyd_populate(mm, pgd, pud) pud_populate((mm), (pgd), (pud))
25709+#define pyd_offset(mm, address) pud_offset((mm), (address))
25710+#define PYD_SIZE PUD_SIZE
25711+#endif
25712+
25713+#ifdef CONFIG_PAX_PER_CPU_PGD
25714+static inline void pgd_ctor(struct mm_struct *mm, pgd_t *pgd) {}
25715+static inline void pgd_dtor(pgd_t *pgd) {}
25716+#else
25717 static void pgd_set_mm(pgd_t *pgd, struct mm_struct *mm)
25718 {
25719 BUILD_BUG_ON(sizeof(virt_to_page(pgd)->index) < sizeof(mm));
25720@@ -128,6 +182,7 @@ static void pgd_dtor(pgd_t *pgd)
25721 pgd_list_del(pgd);
25722 spin_unlock(&pgd_lock);
25723 }
25724+#endif
25725
25726 /*
25727 * List of all pgd's needed for non-PAE so it can invalidate entries
25728@@ -140,7 +195,7 @@ static void pgd_dtor(pgd_t *pgd)
25729 * -- wli
25730 */
25731
25732-#ifdef CONFIG_X86_PAE
25733+#if defined(CONFIG_X86_32) && defined(CONFIG_X86_PAE)
25734 /*
25735 * In PAE mode, we need to do a cr3 reload (=tlb flush) when
25736 * updating the top-level pagetable entries to guarantee the
25737@@ -152,7 +207,7 @@ static void pgd_dtor(pgd_t *pgd)
25738 * not shared between pagetables (!SHARED_KERNEL_PMDS), we allocate
25739 * and initialize the kernel pmds here.
25740 */
25741-#define PREALLOCATED_PMDS UNSHARED_PTRS_PER_PGD
25742+#define PREALLOCATED_PXDS (SHARED_KERNEL_PMD ? KERNEL_PGD_BOUNDARY : PTRS_PER_PGD)
25743
25744 void pud_populate(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd)
25745 {
25746@@ -170,36 +225,38 @@ void pud_populate(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd)
25747 */
25748 flush_tlb_mm(mm);
25749 }
25750+#elif defined(CONFIG_X86_64) && defined(CONFIG_PAX_PER_CPU_PGD)
25751+#define PREALLOCATED_PXDS USER_PGD_PTRS
25752 #else /* !CONFIG_X86_PAE */
25753
25754 /* No need to prepopulate any pagetable entries in non-PAE modes. */
25755-#define PREALLOCATED_PMDS 0
25756+#define PREALLOCATED_PXDS 0
25757
25758 #endif /* CONFIG_X86_PAE */
25759
25760-static void free_pmds(pmd_t *pmds[])
25761+static void free_pxds(pxd_t *pxds[])
25762 {
25763 int i;
25764
25765- for(i = 0; i < PREALLOCATED_PMDS; i++)
25766- if (pmds[i])
25767- free_page((unsigned long)pmds[i]);
25768+ for(i = 0; i < PREALLOCATED_PXDS; i++)
25769+ if (pxds[i])
25770+ free_page((unsigned long)pxds[i]);
25771 }
25772
25773-static int preallocate_pmds(pmd_t *pmds[])
25774+static int preallocate_pxds(pxd_t *pxds[])
25775 {
25776 int i;
25777 bool failed = false;
25778
25779- for(i = 0; i < PREALLOCATED_PMDS; i++) {
25780- pmd_t *pmd = (pmd_t *)__get_free_page(PGALLOC_GFP);
25781- if (pmd == NULL)
25782+ for(i = 0; i < PREALLOCATED_PXDS; i++) {
25783+ pxd_t *pxd = (pxd_t *)__get_free_page(PGALLOC_GFP);
25784+ if (pxd == NULL)
25785 failed = true;
25786- pmds[i] = pmd;
25787+ pxds[i] = pxd;
25788 }
25789
25790 if (failed) {
25791- free_pmds(pmds);
25792+ free_pxds(pxds);
25793 return -ENOMEM;
25794 }
25795
25796@@ -212,51 +269,55 @@ static int preallocate_pmds(pmd_t *pmds[])
25797 * preallocate which never got a corresponding vma will need to be
25798 * freed manually.
25799 */
25800-static void pgd_mop_up_pmds(struct mm_struct *mm, pgd_t *pgdp)
25801+static void pgd_mop_up_pxds(struct mm_struct *mm, pgd_t *pgdp)
25802 {
25803 int i;
25804
25805- for(i = 0; i < PREALLOCATED_PMDS; i++) {
25806+ for(i = 0; i < PREALLOCATED_PXDS; i++) {
25807 pgd_t pgd = pgdp[i];
25808
25809 if (pgd_val(pgd) != 0) {
25810- pmd_t *pmd = (pmd_t *)pgd_page_vaddr(pgd);
25811+ pxd_t *pxd = (pxd_t *)pgd_page_vaddr(pgd);
25812
25813- pgdp[i] = native_make_pgd(0);
25814+ set_pgd(pgdp + i, native_make_pgd(0));
25815
25816- paravirt_release_pmd(pgd_val(pgd) >> PAGE_SHIFT);
25817- pmd_free(mm, pmd);
25818+ paravirt_release_pxd(pgd_val(pgd) >> PAGE_SHIFT);
25819+ pxd_free(mm, pxd);
25820 }
25821 }
25822 }
25823
25824-static void pgd_prepopulate_pmd(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmds[])
25825+static void pgd_prepopulate_pxd(struct mm_struct *mm, pgd_t *pgd, pxd_t *pxds[])
25826 {
25827- pud_t *pud;
25828+ pyd_t *pyd;
25829 unsigned long addr;
25830 int i;
25831
25832- if (PREALLOCATED_PMDS == 0) /* Work around gcc-3.4.x bug */
25833+ if (PREALLOCATED_PXDS == 0) /* Work around gcc-3.4.x bug */
25834 return;
25835
25836- pud = pud_offset(pgd, 0);
25837+#ifdef CONFIG_X86_64
25838+ pyd = pyd_offset(mm, 0L);
25839+#else
25840+ pyd = pyd_offset(pgd, 0L);
25841+#endif
25842
25843- for (addr = i = 0; i < PREALLOCATED_PMDS;
25844- i++, pud++, addr += PUD_SIZE) {
25845- pmd_t *pmd = pmds[i];
25846+ for (addr = i = 0; i < PREALLOCATED_PXDS;
25847+ i++, pyd++, addr += PYD_SIZE) {
25848+ pxd_t *pxd = pxds[i];
25849
25850 if (i >= KERNEL_PGD_BOUNDARY)
25851- memcpy(pmd, (pmd_t *)pgd_page_vaddr(swapper_pg_dir[i]),
25852- sizeof(pmd_t) * PTRS_PER_PMD);
25853+ memcpy(pxd, (pxd_t *)pgd_page_vaddr(swapper_pg_dir[i]),
25854+ sizeof(pxd_t) * PTRS_PER_PMD);
25855
25856- pud_populate(mm, pud, pmd);
25857+ pyd_populate(mm, pyd, pxd);
25858 }
25859 }
25860
25861 pgd_t *pgd_alloc(struct mm_struct *mm)
25862 {
25863 pgd_t *pgd;
25864- pmd_t *pmds[PREALLOCATED_PMDS];
25865+ pxd_t *pxds[PREALLOCATED_PXDS];
25866
25867 pgd = (pgd_t *)__get_free_page(PGALLOC_GFP);
25868
25869@@ -265,11 +326,11 @@ pgd_t *pgd_alloc(struct mm_struct *mm)
25870
25871 mm->pgd = pgd;
25872
25873- if (preallocate_pmds(pmds) != 0)
25874+ if (preallocate_pxds(pxds) != 0)
25875 goto out_free_pgd;
25876
25877 if (paravirt_pgd_alloc(mm) != 0)
25878- goto out_free_pmds;
25879+ goto out_free_pxds;
25880
25881 /*
25882 * Make sure that pre-populating the pmds is atomic with
25883@@ -279,14 +340,14 @@ pgd_t *pgd_alloc(struct mm_struct *mm)
25884 spin_lock(&pgd_lock);
25885
25886 pgd_ctor(mm, pgd);
25887- pgd_prepopulate_pmd(mm, pgd, pmds);
25888+ pgd_prepopulate_pxd(mm, pgd, pxds);
25889
25890 spin_unlock(&pgd_lock);
25891
25892 return pgd;
25893
25894-out_free_pmds:
25895- free_pmds(pmds);
25896+out_free_pxds:
25897+ free_pxds(pxds);
25898 out_free_pgd:
25899 free_page((unsigned long)pgd);
25900 out:
25901@@ -295,7 +356,7 @@ out:
25902
25903 void pgd_free(struct mm_struct *mm, pgd_t *pgd)
25904 {
25905- pgd_mop_up_pmds(mm, pgd);
25906+ pgd_mop_up_pxds(mm, pgd);
25907 pgd_dtor(pgd);
25908 paravirt_pgd_free(mm, pgd);
25909 free_page((unsigned long)pgd);
25910diff --git a/arch/x86/mm/pgtable_32.c b/arch/x86/mm/pgtable_32.c
25911index a69bcb8..19068ab 100644
25912--- a/arch/x86/mm/pgtable_32.c
25913+++ b/arch/x86/mm/pgtable_32.c
25914@@ -47,10 +47,13 @@ void set_pte_vaddr(unsigned long vaddr, pte_t pteval)
25915 return;
25916 }
25917 pte = pte_offset_kernel(pmd, vaddr);
25918+
25919+ pax_open_kernel();
25920 if (pte_val(pteval))
25921 set_pte_at(&init_mm, vaddr, pte, pteval);
25922 else
25923 pte_clear(&init_mm, vaddr, pte);
25924+ pax_close_kernel();
25925
25926 /*
25927 * It's enough to flush this one mapping.
25928diff --git a/arch/x86/mm/setup_nx.c b/arch/x86/mm/setup_nx.c
25929index 410531d..0f16030 100644
25930--- a/arch/x86/mm/setup_nx.c
25931+++ b/arch/x86/mm/setup_nx.c
25932@@ -5,8 +5,10 @@
25933 #include <asm/pgtable.h>
25934 #include <asm/proto.h>
25935
25936+#if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
25937 static int disable_nx __cpuinitdata;
25938
25939+#ifndef CONFIG_PAX_PAGEEXEC
25940 /*
25941 * noexec = on|off
25942 *
25943@@ -28,12 +30,17 @@ static int __init noexec_setup(char *str)
25944 return 0;
25945 }
25946 early_param("noexec", noexec_setup);
25947+#endif
25948+
25949+#endif
25950
25951 void __cpuinit x86_configure_nx(void)
25952 {
25953+#if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
25954 if (cpu_has_nx && !disable_nx)
25955 __supported_pte_mask |= _PAGE_NX;
25956 else
25957+#endif
25958 __supported_pte_mask &= ~_PAGE_NX;
25959 }
25960
25961diff --git a/arch/x86/mm/tlb.c b/arch/x86/mm/tlb.c
25962index 613cd83..3a21f1c 100644
25963--- a/arch/x86/mm/tlb.c
25964+++ b/arch/x86/mm/tlb.c
25965@@ -48,7 +48,11 @@ void leave_mm(int cpu)
25966 BUG();
25967 if (cpumask_test_cpu(cpu, mm_cpumask(active_mm))) {
25968 cpumask_clear_cpu(cpu, mm_cpumask(active_mm));
25969+
25970+#ifndef CONFIG_PAX_PER_CPU_PGD
25971 load_cr3(swapper_pg_dir);
25972+#endif
25973+
25974 }
25975 }
25976 EXPORT_SYMBOL_GPL(leave_mm);
25977diff --git a/arch/x86/net/bpf_jit.S b/arch/x86/net/bpf_jit.S
25978index 877b9a1..a8ecf42 100644
25979--- a/arch/x86/net/bpf_jit.S
25980+++ b/arch/x86/net/bpf_jit.S
25981@@ -9,6 +9,7 @@
25982 */
25983 #include <linux/linkage.h>
25984 #include <asm/dwarf2.h>
25985+#include <asm/alternative-asm.h>
25986
25987 /*
25988 * Calling convention :
25989@@ -35,6 +36,7 @@ sk_load_word_positive_offset:
25990 jle bpf_slow_path_word
25991 mov (SKBDATA,%rsi),%eax
25992 bswap %eax /* ntohl() */
25993+ pax_force_retaddr
25994 ret
25995
25996 sk_load_half:
25997@@ -52,6 +54,7 @@ sk_load_half_positive_offset:
25998 jle bpf_slow_path_half
25999 movzwl (SKBDATA,%rsi),%eax
26000 rol $8,%ax # ntohs()
26001+ pax_force_retaddr
26002 ret
26003
26004 sk_load_byte:
26005@@ -66,6 +69,7 @@ sk_load_byte_positive_offset:
26006 cmp %esi,%r9d /* if (offset >= hlen) goto bpf_slow_path_byte */
26007 jle bpf_slow_path_byte
26008 movzbl (SKBDATA,%rsi),%eax
26009+ pax_force_retaddr
26010 ret
26011
26012 /**
26013@@ -87,6 +91,7 @@ sk_load_byte_msh_positive_offset:
26014 movzbl (SKBDATA,%rsi),%ebx
26015 and $15,%bl
26016 shl $2,%bl
26017+ pax_force_retaddr
26018 ret
26019
26020 /* rsi contains offset and can be scratched */
26021@@ -109,6 +114,7 @@ bpf_slow_path_word:
26022 js bpf_error
26023 mov -12(%rbp),%eax
26024 bswap %eax
26025+ pax_force_retaddr
26026 ret
26027
26028 bpf_slow_path_half:
26029@@ -117,12 +123,14 @@ bpf_slow_path_half:
26030 mov -12(%rbp),%ax
26031 rol $8,%ax
26032 movzwl %ax,%eax
26033+ pax_force_retaddr
26034 ret
26035
26036 bpf_slow_path_byte:
26037 bpf_slow_path_common(1)
26038 js bpf_error
26039 movzbl -12(%rbp),%eax
26040+ pax_force_retaddr
26041 ret
26042
26043 bpf_slow_path_byte_msh:
26044@@ -133,6 +141,7 @@ bpf_slow_path_byte_msh:
26045 and $15,%al
26046 shl $2,%al
26047 xchg %eax,%ebx
26048+ pax_force_retaddr
26049 ret
26050
26051 #define sk_negative_common(SIZE) \
26052@@ -157,6 +166,7 @@ sk_load_word_negative_offset:
26053 sk_negative_common(4)
26054 mov (%rax), %eax
26055 bswap %eax
26056+ pax_force_retaddr
26057 ret
26058
26059 bpf_slow_path_half_neg:
26060@@ -168,6 +178,7 @@ sk_load_half_negative_offset:
26061 mov (%rax),%ax
26062 rol $8,%ax
26063 movzwl %ax,%eax
26064+ pax_force_retaddr
26065 ret
26066
26067 bpf_slow_path_byte_neg:
26068@@ -177,6 +188,7 @@ sk_load_byte_negative_offset:
26069 .globl sk_load_byte_negative_offset
26070 sk_negative_common(1)
26071 movzbl (%rax), %eax
26072+ pax_force_retaddr
26073 ret
26074
26075 bpf_slow_path_byte_msh_neg:
26076@@ -190,6 +202,7 @@ sk_load_byte_msh_negative_offset:
26077 and $15,%al
26078 shl $2,%al
26079 xchg %eax,%ebx
26080+ pax_force_retaddr
26081 ret
26082
26083 bpf_error:
26084@@ -197,4 +210,5 @@ bpf_error:
26085 xor %eax,%eax
26086 mov -8(%rbp),%rbx
26087 leaveq
26088+ pax_force_retaddr
26089 ret
26090diff --git a/arch/x86/net/bpf_jit_comp.c b/arch/x86/net/bpf_jit_comp.c
26091index 33643a8..f6211a0 100644
26092--- a/arch/x86/net/bpf_jit_comp.c
26093+++ b/arch/x86/net/bpf_jit_comp.c
26094@@ -11,6 +11,7 @@
26095 #include <asm/cacheflush.h>
26096 #include <linux/netdevice.h>
26097 #include <linux/filter.h>
26098+#include <linux/random.h>
26099
26100 /*
26101 * Conventions :
26102@@ -48,13 +49,87 @@ static inline u8 *emit_code(u8 *ptr, u32 bytes, unsigned int len)
26103 return ptr + len;
26104 }
26105
26106+#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
26107+#define MAX_INSTR_CODE_SIZE 96
26108+#else
26109+#define MAX_INSTR_CODE_SIZE 64
26110+#endif
26111+
26112 #define EMIT(bytes, len) do { prog = emit_code(prog, bytes, len); } while (0)
26113
26114 #define EMIT1(b1) EMIT(b1, 1)
26115 #define EMIT2(b1, b2) EMIT((b1) + ((b2) << 8), 2)
26116 #define EMIT3(b1, b2, b3) EMIT((b1) + ((b2) << 8) + ((b3) << 16), 3)
26117 #define EMIT4(b1, b2, b3, b4) EMIT((b1) + ((b2) << 8) + ((b3) << 16) + ((b4) << 24), 4)
26118+
26119+#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
26120+/* original constant will appear in ecx */
26121+#define DILUTE_CONST_SEQUENCE(_off, _key) \
26122+do { \
26123+ /* mov ecx, randkey */ \
26124+ EMIT1(0xb9); \
26125+ EMIT(_key, 4); \
26126+ /* xor ecx, randkey ^ off */ \
26127+ EMIT2(0x81, 0xf1); \
26128+ EMIT((_key) ^ (_off), 4); \
26129+} while (0)
26130+
26131+#define EMIT1_off32(b1, _off) \
26132+do { \
26133+ switch (b1) { \
26134+ case 0x05: /* add eax, imm32 */ \
26135+ case 0x2d: /* sub eax, imm32 */ \
26136+ case 0x25: /* and eax, imm32 */ \
26137+ case 0x0d: /* or eax, imm32 */ \
26138+ case 0xb8: /* mov eax, imm32 */ \
26139+ case 0x3d: /* cmp eax, imm32 */ \
26140+ case 0xa9: /* test eax, imm32 */ \
26141+ DILUTE_CONST_SEQUENCE(_off, randkey); \
26142+ EMIT2((b1) - 4, 0xc8); /* convert imm instruction to eax, ecx */\
26143+ break; \
26144+ case 0xbb: /* mov ebx, imm32 */ \
26145+ DILUTE_CONST_SEQUENCE(_off, randkey); \
26146+ /* mov ebx, ecx */ \
26147+ EMIT2(0x89, 0xcb); \
26148+ break; \
26149+ case 0xbe: /* mov esi, imm32 */ \
26150+ DILUTE_CONST_SEQUENCE(_off, randkey); \
26151+ /* mov esi, ecx */ \
26152+ EMIT2(0x89, 0xce); \
26153+ break; \
26154+ case 0xe9: /* jmp rel imm32 */ \
26155+ EMIT1(b1); \
26156+ EMIT(_off, 4); \
26157+ /* prevent fall-through, we're not called if off = 0 */ \
26158+ EMIT(0xcccccccc, 4); \
26159+ EMIT(0xcccccccc, 4); \
26160+ break; \
26161+ default: \
26162+ EMIT1(b1); \
26163+ EMIT(_off, 4); \
26164+ } \
26165+} while (0)
26166+
26167+#define EMIT2_off32(b1, b2, _off) \
26168+do { \
26169+ if ((b1) == 0x8d && (b2) == 0xb3) { /* lea esi, [rbx+imm32] */ \
26170+ EMIT2(0x8d, 0xb3); /* lea esi, [rbx+randkey] */ \
26171+ EMIT(randkey, 4); \
26172+ EMIT2(0x8d, 0xb6); /* lea esi, [esi+off-randkey] */ \
26173+ EMIT((_off) - randkey, 4); \
26174+ } else if ((b1) == 0x69 && (b2) == 0xc0) { /* imul eax, imm32 */\
26175+ DILUTE_CONST_SEQUENCE(_off, randkey); \
26176+ /* imul eax, ecx */ \
26177+ EMIT3(0x0f, 0xaf, 0xc1); \
26178+ } else { \
26179+ EMIT2(b1, b2); \
26180+ EMIT(_off, 4); \
26181+ } \
26182+} while (0)
26183+#else
26184 #define EMIT1_off32(b1, off) do { EMIT1(b1); EMIT(off, 4);} while (0)
26185+#define EMIT2_off32(b1, b2, off) do { EMIT2(b1, b2); EMIT(off, 4);} while (0)
26186+#endif
26187
26188 #define CLEAR_A() EMIT2(0x31, 0xc0) /* xor %eax,%eax */
26189 #define CLEAR_X() EMIT2(0x31, 0xdb) /* xor %ebx,%ebx */
26190@@ -89,6 +164,24 @@ do { \
26191 #define X86_JBE 0x76
26192 #define X86_JA 0x77
26193
26194+#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
26195+#define APPEND_FLOW_VERIFY() \
26196+do { \
26197+ /* mov ecx, randkey */ \
26198+ EMIT1(0xb9); \
26199+ EMIT(randkey, 4); \
26200+ /* cmp ecx, randkey */ \
26201+ EMIT2(0x81, 0xf9); \
26202+ EMIT(randkey, 4); \
26203+ /* jz after 8 int 3s */ \
26204+ EMIT2(0x74, 0x08); \
26205+ EMIT(0xcccccccc, 4); \
26206+ EMIT(0xcccccccc, 4); \
26207+} while (0)
26208+#else
26209+#define APPEND_FLOW_VERIFY() do { } while (0)
26210+#endif
26211+
26212 #define EMIT_COND_JMP(op, offset) \
26213 do { \
26214 if (is_near(offset)) \
26215@@ -96,6 +189,7 @@ do { \
26216 else { \
26217 EMIT2(0x0f, op + 0x10); \
26218 EMIT(offset, 4); /* jxx .+off32 */ \
26219+ APPEND_FLOW_VERIFY(); \
26220 } \
26221 } while (0)
26222
26223@@ -120,12 +214,17 @@ static inline void bpf_flush_icache(void *start, void *end)
26224 set_fs(old_fs);
26225 }
26226
26227+struct bpf_jit_work {
26228+ struct work_struct work;
26229+ void *image;
26230+};
26231+
26232 #define CHOOSE_LOAD_FUNC(K, func) \
26233 ((int)K < 0 ? ((int)K >= SKF_LL_OFF ? func##_negative_offset : func) : func##_positive_offset)
26234
26235 void bpf_jit_compile(struct sk_filter *fp)
26236 {
26237- u8 temp[64];
26238+ u8 temp[MAX_INSTR_CODE_SIZE];
26239 u8 *prog;
26240 unsigned int proglen, oldproglen = 0;
26241 int ilen, i;
26242@@ -138,6 +237,9 @@ void bpf_jit_compile(struct sk_filter *fp)
26243 unsigned int *addrs;
26244 const struct sock_filter *filter = fp->insns;
26245 int flen = fp->len;
26246+#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
26247+ unsigned int randkey;
26248+#endif
26249
26250 if (!bpf_jit_enable)
26251 return;
26252@@ -146,11 +248,19 @@ void bpf_jit_compile(struct sk_filter *fp)
26253 if (addrs == NULL)
26254 return;
26255
26256+ fp->work = kmalloc(sizeof(*fp->work), GFP_KERNEL);
26257+ if (!fp->work)
26258+ goto out;
26259+
26260+#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
26261+ randkey = get_random_int();
26262+#endif
26263+
26264 /* Before first pass, make a rough estimation of addrs[]
26265- * each bpf instruction is translated to less than 64 bytes
26266+ * each bpf instruction is translated to less than MAX_INSTR_CODE_SIZE bytes
26267 */
26268 for (proglen = 0, i = 0; i < flen; i++) {
26269- proglen += 64;
26270+ proglen += MAX_INSTR_CODE_SIZE;
26271 addrs[i] = proglen;
26272 }
26273 cleanup_addr = proglen; /* epilogue address */
26274@@ -258,10 +368,8 @@ void bpf_jit_compile(struct sk_filter *fp)
26275 case BPF_S_ALU_MUL_K: /* A *= K */
26276 if (is_imm8(K))
26277 EMIT3(0x6b, 0xc0, K); /* imul imm8,%eax,%eax */
26278- else {
26279- EMIT2(0x69, 0xc0); /* imul imm32,%eax */
26280- EMIT(K, 4);
26281- }
26282+ else
26283+ EMIT2_off32(0x69, 0xc0, K); /* imul imm32,%eax */
26284 break;
26285 case BPF_S_ALU_DIV_X: /* A /= X; */
26286 seen |= SEEN_XREG;
26287@@ -281,8 +389,14 @@ void bpf_jit_compile(struct sk_filter *fp)
26288 EMIT4(0x31, 0xd2, 0xf7, 0xf3); /* xor %edx,%edx; div %ebx */
26289 break;
26290 case BPF_S_ALU_DIV_K: /* A = reciprocal_divide(A, K); */
26291+#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
26292+ DILUTE_CONST_SEQUENCE(K, randkey);
26293+ // imul rax, rcx
26294+ EMIT4(0x48, 0x0f, 0xaf, 0xc1);
26295+#else
26296 EMIT3(0x48, 0x69, 0xc0); /* imul imm32,%rax,%rax */
26297 EMIT(K, 4);
26298+#endif
26299 EMIT4(0x48, 0xc1, 0xe8, 0x20); /* shr $0x20,%rax */
26300 break;
26301 case BPF_S_ALU_AND_X:
26302@@ -509,8 +623,7 @@ common_load_ind: seen |= SEEN_DATAREF | SEEN_XREG;
26303 if (is_imm8(K)) {
26304 EMIT3(0x8d, 0x73, K); /* lea imm8(%rbx), %esi */
26305 } else {
26306- EMIT2(0x8d, 0xb3); /* lea imm32(%rbx),%esi */
26307- EMIT(K, 4);
26308+ EMIT2_off32(0x8d, 0xb3, K); /* lea imm32(%rbx),%esi */
26309 }
26310 } else {
26311 EMIT2(0x89,0xde); /* mov %ebx,%esi */
26312@@ -593,17 +706,18 @@ cond_branch: f_offset = addrs[i + filter[i].jf] - addrs[i];
26313 break;
26314 default:
26315 /* hmm, too complex filter, give up with jit compiler */
26316- goto out;
26317+ goto error;
26318 }
26319 ilen = prog - temp;
26320 if (image) {
26321 if (unlikely(proglen + ilen > oldproglen)) {
26322 pr_err("bpb_jit_compile fatal error\n");
26323- kfree(addrs);
26324- module_free(NULL, image);
26325- return;
26326+ module_free_exec(NULL, image);
26327+ goto error;
26328 }
26329+ pax_open_kernel();
26330 memcpy(image + proglen, temp, ilen);
26331+ pax_close_kernel();
26332 }
26333 proglen += ilen;
26334 addrs[i] = proglen;
26335@@ -624,11 +738,9 @@ cond_branch: f_offset = addrs[i + filter[i].jf] - addrs[i];
26336 break;
26337 }
26338 if (proglen == oldproglen) {
26339- image = module_alloc(max_t(unsigned int,
26340- proglen,
26341- sizeof(struct work_struct)));
26342+ image = module_alloc_exec(proglen);
26343 if (!image)
26344- goto out;
26345+ goto error;
26346 }
26347 oldproglen = proglen;
26348 }
26349@@ -644,7 +756,10 @@ cond_branch: f_offset = addrs[i + filter[i].jf] - addrs[i];
26350 bpf_flush_icache(image, image + proglen);
26351
26352 fp->bpf_func = (void *)image;
26353- }
26354+ } else
26355+error:
26356+ kfree(fp->work);
26357+
26358 out:
26359 kfree(addrs);
26360 return;
26361@@ -652,18 +767,20 @@ out:
26362
26363 static void jit_free_defer(struct work_struct *arg)
26364 {
26365- module_free(NULL, arg);
26366+ module_free_exec(NULL, ((struct bpf_jit_work *)arg)->image);
26367+ kfree(arg);
26368 }
26369
26370 /* run from softirq, we must use a work_struct to call
26371- * module_free() from process context
26372+ * module_free_exec() from process context
26373 */
26374 void bpf_jit_free(struct sk_filter *fp)
26375 {
26376 if (fp->bpf_func != sk_run_filter) {
26377- struct work_struct *work = (struct work_struct *)fp->bpf_func;
26378+ struct work_struct *work = &fp->work->work;
26379
26380 INIT_WORK(work, jit_free_defer);
26381+ fp->work->image = fp->bpf_func;
26382 schedule_work(work);
26383 }
26384 }
26385diff --git a/arch/x86/oprofile/backtrace.c b/arch/x86/oprofile/backtrace.c
26386index d6aa6e8..266395a 100644
26387--- a/arch/x86/oprofile/backtrace.c
26388+++ b/arch/x86/oprofile/backtrace.c
26389@@ -46,11 +46,11 @@ dump_user_backtrace_32(struct stack_frame_ia32 *head)
26390 struct stack_frame_ia32 *fp;
26391 unsigned long bytes;
26392
26393- bytes = copy_from_user_nmi(bufhead, head, sizeof(bufhead));
26394+ bytes = copy_from_user_nmi(bufhead, (const char __force_user *)head, sizeof(bufhead));
26395 if (bytes != sizeof(bufhead))
26396 return NULL;
26397
26398- fp = (struct stack_frame_ia32 *) compat_ptr(bufhead[0].next_frame);
26399+ fp = (struct stack_frame_ia32 __force_kernel *) compat_ptr(bufhead[0].next_frame);
26400
26401 oprofile_add_trace(bufhead[0].return_address);
26402
26403@@ -92,7 +92,7 @@ static struct stack_frame *dump_user_backtrace(struct stack_frame *head)
26404 struct stack_frame bufhead[2];
26405 unsigned long bytes;
26406
26407- bytes = copy_from_user_nmi(bufhead, head, sizeof(bufhead));
26408+ bytes = copy_from_user_nmi(bufhead, (const char __force_user *)head, sizeof(bufhead));
26409 if (bytes != sizeof(bufhead))
26410 return NULL;
26411
26412@@ -111,7 +111,7 @@ x86_backtrace(struct pt_regs * const regs, unsigned int depth)
26413 {
26414 struct stack_frame *head = (struct stack_frame *)frame_pointer(regs);
26415
26416- if (!user_mode_vm(regs)) {
26417+ if (!user_mode(regs)) {
26418 unsigned long stack = kernel_stack_pointer(regs);
26419 if (depth)
26420 dump_trace(NULL, regs, (unsigned long *)stack, 0,
26421diff --git a/arch/x86/pci/mrst.c b/arch/x86/pci/mrst.c
26422index e14a2ff..3fd6b58 100644
26423--- a/arch/x86/pci/mrst.c
26424+++ b/arch/x86/pci/mrst.c
26425@@ -238,7 +238,9 @@ int __init pci_mrst_init(void)
26426 printk(KERN_INFO "Intel MID platform detected, using MID PCI ops\n");
26427 pci_mmcfg_late_init();
26428 pcibios_enable_irq = mrst_pci_irq_enable;
26429- pci_root_ops = pci_mrst_ops;
26430+ pax_open_kernel();
26431+ memcpy((void *)&pci_root_ops, &pci_mrst_ops, sizeof(pci_mrst_ops));
26432+ pax_close_kernel();
26433 pci_soc_mode = 1;
26434 /* Continue with standard init */
26435 return 1;
26436diff --git a/arch/x86/pci/pcbios.c b/arch/x86/pci/pcbios.c
26437index da8fe05..7ee6704 100644
26438--- a/arch/x86/pci/pcbios.c
26439+++ b/arch/x86/pci/pcbios.c
26440@@ -79,50 +79,93 @@ union bios32 {
26441 static struct {
26442 unsigned long address;
26443 unsigned short segment;
26444-} bios32_indirect = { 0, __KERNEL_CS };
26445+} bios32_indirect __read_only = { 0, __PCIBIOS_CS };
26446
26447 /*
26448 * Returns the entry point for the given service, NULL on error
26449 */
26450
26451-static unsigned long bios32_service(unsigned long service)
26452+static unsigned long __devinit bios32_service(unsigned long service)
26453 {
26454 unsigned char return_code; /* %al */
26455 unsigned long address; /* %ebx */
26456 unsigned long length; /* %ecx */
26457 unsigned long entry; /* %edx */
26458 unsigned long flags;
26459+ struct desc_struct d, *gdt;
26460
26461 local_irq_save(flags);
26462- __asm__("lcall *(%%edi); cld"
26463+
26464+ gdt = get_cpu_gdt_table(smp_processor_id());
26465+
26466+ pack_descriptor(&d, 0UL, 0xFFFFFUL, 0x9B, 0xC);
26467+ write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_CS, &d, DESCTYPE_S);
26468+ pack_descriptor(&d, 0UL, 0xFFFFFUL, 0x93, 0xC);
26469+ write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_DS, &d, DESCTYPE_S);
26470+
26471+ __asm__("movw %w7, %%ds; lcall *(%%edi); push %%ss; pop %%ds; cld"
26472 : "=a" (return_code),
26473 "=b" (address),
26474 "=c" (length),
26475 "=d" (entry)
26476 : "0" (service),
26477 "1" (0),
26478- "D" (&bios32_indirect));
26479+ "D" (&bios32_indirect),
26480+ "r"(__PCIBIOS_DS)
26481+ : "memory");
26482+
26483+ pax_open_kernel();
26484+ gdt[GDT_ENTRY_PCIBIOS_CS].a = 0;
26485+ gdt[GDT_ENTRY_PCIBIOS_CS].b = 0;
26486+ gdt[GDT_ENTRY_PCIBIOS_DS].a = 0;
26487+ gdt[GDT_ENTRY_PCIBIOS_DS].b = 0;
26488+ pax_close_kernel();
26489+
26490 local_irq_restore(flags);
26491
26492 switch (return_code) {
26493- case 0:
26494- return address + entry;
26495- case 0x80: /* Not present */
26496- printk(KERN_WARNING "bios32_service(0x%lx): not present\n", service);
26497- return 0;
26498- default: /* Shouldn't happen */
26499- printk(KERN_WARNING "bios32_service(0x%lx): returned 0x%x -- BIOS bug!\n",
26500- service, return_code);
26501+ case 0: {
26502+ int cpu;
26503+ unsigned char flags;
26504+
26505+ printk(KERN_INFO "bios32_service: base:%08lx length:%08lx entry:%08lx\n", address, length, entry);
26506+ if (address >= 0xFFFF0 || length > 0x100000 - address || length <= entry) {
26507+ printk(KERN_WARNING "bios32_service: not valid\n");
26508 return 0;
26509+ }
26510+ address = address + PAGE_OFFSET;
26511+ length += 16UL; /* some BIOSs underreport this... */
26512+ flags = 4;
26513+ if (length >= 64*1024*1024) {
26514+ length >>= PAGE_SHIFT;
26515+ flags |= 8;
26516+ }
26517+
26518+ for (cpu = 0; cpu < nr_cpu_ids; cpu++) {
26519+ gdt = get_cpu_gdt_table(cpu);
26520+ pack_descriptor(&d, address, length, 0x9b, flags);
26521+ write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_CS, &d, DESCTYPE_S);
26522+ pack_descriptor(&d, address, length, 0x93, flags);
26523+ write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_DS, &d, DESCTYPE_S);
26524+ }
26525+ return entry;
26526+ }
26527+ case 0x80: /* Not present */
26528+ printk(KERN_WARNING "bios32_service(0x%lx): not present\n", service);
26529+ return 0;
26530+ default: /* Shouldn't happen */
26531+ printk(KERN_WARNING "bios32_service(0x%lx): returned 0x%x -- BIOS bug!\n",
26532+ service, return_code);
26533+ return 0;
26534 }
26535 }
26536
26537 static struct {
26538 unsigned long address;
26539 unsigned short segment;
26540-} pci_indirect = { 0, __KERNEL_CS };
26541+} pci_indirect __read_only = { 0, __PCIBIOS_CS };
26542
26543-static int pci_bios_present;
26544+static int pci_bios_present __read_only;
26545
26546 static int __devinit check_pcibios(void)
26547 {
26548@@ -131,11 +174,13 @@ static int __devinit check_pcibios(void)
26549 unsigned long flags, pcibios_entry;
26550
26551 if ((pcibios_entry = bios32_service(PCI_SERVICE))) {
26552- pci_indirect.address = pcibios_entry + PAGE_OFFSET;
26553+ pci_indirect.address = pcibios_entry;
26554
26555 local_irq_save(flags);
26556- __asm__(
26557- "lcall *(%%edi); cld\n\t"
26558+ __asm__("movw %w6, %%ds\n\t"
26559+ "lcall *%%ss:(%%edi); cld\n\t"
26560+ "push %%ss\n\t"
26561+ "pop %%ds\n\t"
26562 "jc 1f\n\t"
26563 "xor %%ah, %%ah\n"
26564 "1:"
26565@@ -144,7 +189,8 @@ static int __devinit check_pcibios(void)
26566 "=b" (ebx),
26567 "=c" (ecx)
26568 : "1" (PCIBIOS_PCI_BIOS_PRESENT),
26569- "D" (&pci_indirect)
26570+ "D" (&pci_indirect),
26571+ "r" (__PCIBIOS_DS)
26572 : "memory");
26573 local_irq_restore(flags);
26574
26575@@ -189,7 +235,10 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
26576
26577 switch (len) {
26578 case 1:
26579- __asm__("lcall *(%%esi); cld\n\t"
26580+ __asm__("movw %w6, %%ds\n\t"
26581+ "lcall *%%ss:(%%esi); cld\n\t"
26582+ "push %%ss\n\t"
26583+ "pop %%ds\n\t"
26584 "jc 1f\n\t"
26585 "xor %%ah, %%ah\n"
26586 "1:"
26587@@ -198,7 +247,8 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
26588 : "1" (PCIBIOS_READ_CONFIG_BYTE),
26589 "b" (bx),
26590 "D" ((long)reg),
26591- "S" (&pci_indirect));
26592+ "S" (&pci_indirect),
26593+ "r" (__PCIBIOS_DS));
26594 /*
26595 * Zero-extend the result beyond 8 bits, do not trust the
26596 * BIOS having done it:
26597@@ -206,7 +256,10 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
26598 *value &= 0xff;
26599 break;
26600 case 2:
26601- __asm__("lcall *(%%esi); cld\n\t"
26602+ __asm__("movw %w6, %%ds\n\t"
26603+ "lcall *%%ss:(%%esi); cld\n\t"
26604+ "push %%ss\n\t"
26605+ "pop %%ds\n\t"
26606 "jc 1f\n\t"
26607 "xor %%ah, %%ah\n"
26608 "1:"
26609@@ -215,7 +268,8 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
26610 : "1" (PCIBIOS_READ_CONFIG_WORD),
26611 "b" (bx),
26612 "D" ((long)reg),
26613- "S" (&pci_indirect));
26614+ "S" (&pci_indirect),
26615+ "r" (__PCIBIOS_DS));
26616 /*
26617 * Zero-extend the result beyond 16 bits, do not trust the
26618 * BIOS having done it:
26619@@ -223,7 +277,10 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
26620 *value &= 0xffff;
26621 break;
26622 case 4:
26623- __asm__("lcall *(%%esi); cld\n\t"
26624+ __asm__("movw %w6, %%ds\n\t"
26625+ "lcall *%%ss:(%%esi); cld\n\t"
26626+ "push %%ss\n\t"
26627+ "pop %%ds\n\t"
26628 "jc 1f\n\t"
26629 "xor %%ah, %%ah\n"
26630 "1:"
26631@@ -232,7 +289,8 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
26632 : "1" (PCIBIOS_READ_CONFIG_DWORD),
26633 "b" (bx),
26634 "D" ((long)reg),
26635- "S" (&pci_indirect));
26636+ "S" (&pci_indirect),
26637+ "r" (__PCIBIOS_DS));
26638 break;
26639 }
26640
26641@@ -256,7 +314,10 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
26642
26643 switch (len) {
26644 case 1:
26645- __asm__("lcall *(%%esi); cld\n\t"
26646+ __asm__("movw %w6, %%ds\n\t"
26647+ "lcall *%%ss:(%%esi); cld\n\t"
26648+ "push %%ss\n\t"
26649+ "pop %%ds\n\t"
26650 "jc 1f\n\t"
26651 "xor %%ah, %%ah\n"
26652 "1:"
26653@@ -265,10 +326,14 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
26654 "c" (value),
26655 "b" (bx),
26656 "D" ((long)reg),
26657- "S" (&pci_indirect));
26658+ "S" (&pci_indirect),
26659+ "r" (__PCIBIOS_DS));
26660 break;
26661 case 2:
26662- __asm__("lcall *(%%esi); cld\n\t"
26663+ __asm__("movw %w6, %%ds\n\t"
26664+ "lcall *%%ss:(%%esi); cld\n\t"
26665+ "push %%ss\n\t"
26666+ "pop %%ds\n\t"
26667 "jc 1f\n\t"
26668 "xor %%ah, %%ah\n"
26669 "1:"
26670@@ -277,10 +342,14 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
26671 "c" (value),
26672 "b" (bx),
26673 "D" ((long)reg),
26674- "S" (&pci_indirect));
26675+ "S" (&pci_indirect),
26676+ "r" (__PCIBIOS_DS));
26677 break;
26678 case 4:
26679- __asm__("lcall *(%%esi); cld\n\t"
26680+ __asm__("movw %w6, %%ds\n\t"
26681+ "lcall *%%ss:(%%esi); cld\n\t"
26682+ "push %%ss\n\t"
26683+ "pop %%ds\n\t"
26684 "jc 1f\n\t"
26685 "xor %%ah, %%ah\n"
26686 "1:"
26687@@ -289,7 +358,8 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
26688 "c" (value),
26689 "b" (bx),
26690 "D" ((long)reg),
26691- "S" (&pci_indirect));
26692+ "S" (&pci_indirect),
26693+ "r" (__PCIBIOS_DS));
26694 break;
26695 }
26696
26697@@ -394,10 +464,13 @@ struct irq_routing_table * pcibios_get_irq_routing_table(void)
26698
26699 DBG("PCI: Fetching IRQ routing table... ");
26700 __asm__("push %%es\n\t"
26701+ "movw %w8, %%ds\n\t"
26702 "push %%ds\n\t"
26703 "pop %%es\n\t"
26704- "lcall *(%%esi); cld\n\t"
26705+ "lcall *%%ss:(%%esi); cld\n\t"
26706 "pop %%es\n\t"
26707+ "push %%ss\n\t"
26708+ "pop %%ds\n"
26709 "jc 1f\n\t"
26710 "xor %%ah, %%ah\n"
26711 "1:"
26712@@ -408,7 +481,8 @@ struct irq_routing_table * pcibios_get_irq_routing_table(void)
26713 "1" (0),
26714 "D" ((long) &opt),
26715 "S" (&pci_indirect),
26716- "m" (opt)
26717+ "m" (opt),
26718+ "r" (__PCIBIOS_DS)
26719 : "memory");
26720 DBG("OK ret=%d, size=%d, map=%x\n", ret, opt.size, map);
26721 if (ret & 0xff00)
26722@@ -432,7 +506,10 @@ int pcibios_set_irq_routing(struct pci_dev *dev, int pin, int irq)
26723 {
26724 int ret;
26725
26726- __asm__("lcall *(%%esi); cld\n\t"
26727+ __asm__("movw %w5, %%ds\n\t"
26728+ "lcall *%%ss:(%%esi); cld\n\t"
26729+ "push %%ss\n\t"
26730+ "pop %%ds\n"
26731 "jc 1f\n\t"
26732 "xor %%ah, %%ah\n"
26733 "1:"
26734@@ -440,7 +517,8 @@ int pcibios_set_irq_routing(struct pci_dev *dev, int pin, int irq)
26735 : "0" (PCIBIOS_SET_PCI_HW_INT),
26736 "b" ((dev->bus->number << 8) | dev->devfn),
26737 "c" ((irq << 8) | (pin + 10)),
26738- "S" (&pci_indirect));
26739+ "S" (&pci_indirect),
26740+ "r" (__PCIBIOS_DS));
26741 return !(ret & 0xff00);
26742 }
26743 EXPORT_SYMBOL(pcibios_set_irq_routing);
26744diff --git a/arch/x86/platform/efi/efi_32.c b/arch/x86/platform/efi/efi_32.c
26745index 40e4469..1ab536e 100644
26746--- a/arch/x86/platform/efi/efi_32.c
26747+++ b/arch/x86/platform/efi/efi_32.c
26748@@ -44,11 +44,22 @@ void efi_call_phys_prelog(void)
26749 {
26750 struct desc_ptr gdt_descr;
26751
26752+#ifdef CONFIG_PAX_KERNEXEC
26753+ struct desc_struct d;
26754+#endif
26755+
26756 local_irq_save(efi_rt_eflags);
26757
26758 load_cr3(initial_page_table);
26759 __flush_tlb_all();
26760
26761+#ifdef CONFIG_PAX_KERNEXEC
26762+ pack_descriptor(&d, 0, 0xFFFFF, 0x9B, 0xC);
26763+ write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_CS, &d, DESCTYPE_S);
26764+ pack_descriptor(&d, 0, 0xFFFFF, 0x93, 0xC);
26765+ write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_DS, &d, DESCTYPE_S);
26766+#endif
26767+
26768 gdt_descr.address = __pa(get_cpu_gdt_table(0));
26769 gdt_descr.size = GDT_SIZE - 1;
26770 load_gdt(&gdt_descr);
26771@@ -58,6 +69,14 @@ void efi_call_phys_epilog(void)
26772 {
26773 struct desc_ptr gdt_descr;
26774
26775+#ifdef CONFIG_PAX_KERNEXEC
26776+ struct desc_struct d;
26777+
26778+ memset(&d, 0, sizeof d);
26779+ write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_CS, &d, DESCTYPE_S);
26780+ write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_DS, &d, DESCTYPE_S);
26781+#endif
26782+
26783 gdt_descr.address = (unsigned long)get_cpu_gdt_table(0);
26784 gdt_descr.size = GDT_SIZE - 1;
26785 load_gdt(&gdt_descr);
26786diff --git a/arch/x86/platform/efi/efi_stub_32.S b/arch/x86/platform/efi/efi_stub_32.S
26787index fbe66e6..eae5e38 100644
26788--- a/arch/x86/platform/efi/efi_stub_32.S
26789+++ b/arch/x86/platform/efi/efi_stub_32.S
26790@@ -6,7 +6,9 @@
26791 */
26792
26793 #include <linux/linkage.h>
26794+#include <linux/init.h>
26795 #include <asm/page_types.h>
26796+#include <asm/segment.h>
26797
26798 /*
26799 * efi_call_phys(void *, ...) is a function with variable parameters.
26800@@ -20,7 +22,7 @@
26801 * service functions will comply with gcc calling convention, too.
26802 */
26803
26804-.text
26805+__INIT
26806 ENTRY(efi_call_phys)
26807 /*
26808 * 0. The function can only be called in Linux kernel. So CS has been
26809@@ -36,10 +38,24 @@ ENTRY(efi_call_phys)
26810 * The mapping of lower virtual memory has been created in prelog and
26811 * epilog.
26812 */
26813- movl $1f, %edx
26814- subl $__PAGE_OFFSET, %edx
26815- jmp *%edx
26816+#ifdef CONFIG_PAX_KERNEXEC
26817+ movl $(__KERNEXEC_EFI_DS), %edx
26818+ mov %edx, %ds
26819+ mov %edx, %es
26820+ mov %edx, %ss
26821+ addl $2f,(1f)
26822+ ljmp *(1f)
26823+
26824+__INITDATA
26825+1: .long __LOAD_PHYSICAL_ADDR, __KERNEXEC_EFI_CS
26826+.previous
26827+
26828+2:
26829+ subl $2b,(1b)
26830+#else
26831+ jmp 1f-__PAGE_OFFSET
26832 1:
26833+#endif
26834
26835 /*
26836 * 2. Now on the top of stack is the return
26837@@ -47,14 +63,8 @@ ENTRY(efi_call_phys)
26838 * parameter 2, ..., param n. To make things easy, we save the return
26839 * address of efi_call_phys in a global variable.
26840 */
26841- popl %edx
26842- movl %edx, saved_return_addr
26843- /* get the function pointer into ECX*/
26844- popl %ecx
26845- movl %ecx, efi_rt_function_ptr
26846- movl $2f, %edx
26847- subl $__PAGE_OFFSET, %edx
26848- pushl %edx
26849+ popl (saved_return_addr)
26850+ popl (efi_rt_function_ptr)
26851
26852 /*
26853 * 3. Clear PG bit in %CR0.
26854@@ -73,9 +83,8 @@ ENTRY(efi_call_phys)
26855 /*
26856 * 5. Call the physical function.
26857 */
26858- jmp *%ecx
26859+ call *(efi_rt_function_ptr-__PAGE_OFFSET)
26860
26861-2:
26862 /*
26863 * 6. After EFI runtime service returns, control will return to
26864 * following instruction. We'd better readjust stack pointer first.
26865@@ -88,35 +97,36 @@ ENTRY(efi_call_phys)
26866 movl %cr0, %edx
26867 orl $0x80000000, %edx
26868 movl %edx, %cr0
26869- jmp 1f
26870-1:
26871+
26872 /*
26873 * 8. Now restore the virtual mode from flat mode by
26874 * adding EIP with PAGE_OFFSET.
26875 */
26876- movl $1f, %edx
26877- jmp *%edx
26878+#ifdef CONFIG_PAX_KERNEXEC
26879+ movl $(__KERNEL_DS), %edx
26880+ mov %edx, %ds
26881+ mov %edx, %es
26882+ mov %edx, %ss
26883+ ljmp $(__KERNEL_CS),$1f
26884+#else
26885+ jmp 1f+__PAGE_OFFSET
26886+#endif
26887 1:
26888
26889 /*
26890 * 9. Balance the stack. And because EAX contain the return value,
26891 * we'd better not clobber it.
26892 */
26893- leal efi_rt_function_ptr, %edx
26894- movl (%edx), %ecx
26895- pushl %ecx
26896+ pushl (efi_rt_function_ptr)
26897
26898 /*
26899- * 10. Push the saved return address onto the stack and return.
26900+ * 10. Return to the saved return address.
26901 */
26902- leal saved_return_addr, %edx
26903- movl (%edx), %ecx
26904- pushl %ecx
26905- ret
26906+ jmpl *(saved_return_addr)
26907 ENDPROC(efi_call_phys)
26908 .previous
26909
26910-.data
26911+__INITDATA
26912 saved_return_addr:
26913 .long 0
26914 efi_rt_function_ptr:
26915diff --git a/arch/x86/platform/efi/efi_stub_64.S b/arch/x86/platform/efi/efi_stub_64.S
26916index 4c07cca..2c8427d 100644
26917--- a/arch/x86/platform/efi/efi_stub_64.S
26918+++ b/arch/x86/platform/efi/efi_stub_64.S
26919@@ -7,6 +7,7 @@
26920 */
26921
26922 #include <linux/linkage.h>
26923+#include <asm/alternative-asm.h>
26924
26925 #define SAVE_XMM \
26926 mov %rsp, %rax; \
26927@@ -40,6 +41,7 @@ ENTRY(efi_call0)
26928 call *%rdi
26929 addq $32, %rsp
26930 RESTORE_XMM
26931+ pax_force_retaddr 0, 1
26932 ret
26933 ENDPROC(efi_call0)
26934
26935@@ -50,6 +52,7 @@ ENTRY(efi_call1)
26936 call *%rdi
26937 addq $32, %rsp
26938 RESTORE_XMM
26939+ pax_force_retaddr 0, 1
26940 ret
26941 ENDPROC(efi_call1)
26942
26943@@ -60,6 +63,7 @@ ENTRY(efi_call2)
26944 call *%rdi
26945 addq $32, %rsp
26946 RESTORE_XMM
26947+ pax_force_retaddr 0, 1
26948 ret
26949 ENDPROC(efi_call2)
26950
26951@@ -71,6 +75,7 @@ ENTRY(efi_call3)
26952 call *%rdi
26953 addq $32, %rsp
26954 RESTORE_XMM
26955+ pax_force_retaddr 0, 1
26956 ret
26957 ENDPROC(efi_call3)
26958
26959@@ -83,6 +88,7 @@ ENTRY(efi_call4)
26960 call *%rdi
26961 addq $32, %rsp
26962 RESTORE_XMM
26963+ pax_force_retaddr 0, 1
26964 ret
26965 ENDPROC(efi_call4)
26966
26967@@ -96,6 +102,7 @@ ENTRY(efi_call5)
26968 call *%rdi
26969 addq $48, %rsp
26970 RESTORE_XMM
26971+ pax_force_retaddr 0, 1
26972 ret
26973 ENDPROC(efi_call5)
26974
26975@@ -112,5 +119,6 @@ ENTRY(efi_call6)
26976 call *%rdi
26977 addq $48, %rsp
26978 RESTORE_XMM
26979+ pax_force_retaddr 0, 1
26980 ret
26981 ENDPROC(efi_call6)
26982diff --git a/arch/x86/platform/mrst/mrst.c b/arch/x86/platform/mrst/mrst.c
26983index fd41a92..9c33628 100644
26984--- a/arch/x86/platform/mrst/mrst.c
26985+++ b/arch/x86/platform/mrst/mrst.c
26986@@ -78,13 +78,15 @@ struct sfi_rtc_table_entry sfi_mrtc_array[SFI_MRTC_MAX];
26987 EXPORT_SYMBOL_GPL(sfi_mrtc_array);
26988 int sfi_mrtc_num;
26989
26990-static void mrst_power_off(void)
26991+static __noreturn void mrst_power_off(void)
26992 {
26993+ BUG();
26994 }
26995
26996-static void mrst_reboot(void)
26997+static __noreturn void mrst_reboot(void)
26998 {
26999 intel_scu_ipc_simple_command(IPCMSG_COLD_BOOT, 0);
27000+ BUG();
27001 }
27002
27003 /* parse all the mtimer info to a static mtimer array */
27004diff --git a/arch/x86/power/cpu.c b/arch/x86/power/cpu.c
27005index 218cdb1..fd55c08 100644
27006--- a/arch/x86/power/cpu.c
27007+++ b/arch/x86/power/cpu.c
27008@@ -132,7 +132,7 @@ static void do_fpu_end(void)
27009 static void fix_processor_context(void)
27010 {
27011 int cpu = smp_processor_id();
27012- struct tss_struct *t = &per_cpu(init_tss, cpu);
27013+ struct tss_struct *t = init_tss + cpu;
27014
27015 set_tss_desc(cpu, t); /*
27016 * This just modifies memory; should not be
27017@@ -142,7 +142,9 @@ static void fix_processor_context(void)
27018 */
27019
27020 #ifdef CONFIG_X86_64
27021+ pax_open_kernel();
27022 get_cpu_gdt_table(cpu)[GDT_ENTRY_TSS].type = 9;
27023+ pax_close_kernel();
27024
27025 syscall_init(); /* This sets MSR_*STAR and related */
27026 #endif
27027diff --git a/arch/x86/realmode/init.c b/arch/x86/realmode/init.c
27028index cbca565..bae7133 100644
27029--- a/arch/x86/realmode/init.c
27030+++ b/arch/x86/realmode/init.c
27031@@ -62,7 +62,13 @@ void __init setup_real_mode(void)
27032 __va(real_mode_header->trampoline_header);
27033
27034 #ifdef CONFIG_X86_32
27035- trampoline_header->start = __pa(startup_32_smp);
27036+ trampoline_header->start = __pa(ktla_ktva(startup_32_smp));
27037+
27038+#ifdef CONFIG_PAX_KERNEXEC
27039+ trampoline_header->start -= LOAD_PHYSICAL_ADDR;
27040+#endif
27041+
27042+ trampoline_header->boot_cs = __BOOT_CS;
27043 trampoline_header->gdt_limit = __BOOT_DS + 7;
27044 trampoline_header->gdt_base = __pa(boot_gdt);
27045 #else
27046diff --git a/arch/x86/realmode/rm/Makefile b/arch/x86/realmode/rm/Makefile
27047index 8869287..d577672 100644
27048--- a/arch/x86/realmode/rm/Makefile
27049+++ b/arch/x86/realmode/rm/Makefile
27050@@ -78,5 +78,8 @@ KBUILD_CFLAGS := $(LINUXINCLUDE) -m32 -g -Os -D_SETUP -D__KERNEL__ -D_WAKEUP \
27051 $(call cc-option, -fno-unit-at-a-time)) \
27052 $(call cc-option, -fno-stack-protector) \
27053 $(call cc-option, -mpreferred-stack-boundary=2)
27054+ifdef CONSTIFY_PLUGIN
27055+KBUILD_CFLAGS += -fplugin-arg-constify_plugin-no-constify
27056+endif
27057 KBUILD_AFLAGS := $(KBUILD_CFLAGS) -D__ASSEMBLY__
27058 GCOV_PROFILE := n
27059diff --git a/arch/x86/realmode/rm/header.S b/arch/x86/realmode/rm/header.S
27060index a28221d..93c40f1 100644
27061--- a/arch/x86/realmode/rm/header.S
27062+++ b/arch/x86/realmode/rm/header.S
27063@@ -30,7 +30,9 @@ GLOBAL(real_mode_header)
27064 #endif
27065 /* APM/BIOS reboot */
27066 .long pa_machine_real_restart_asm
27067-#ifdef CONFIG_X86_64
27068+#ifdef CONFIG_X86_32
27069+ .long __KERNEL_CS
27070+#else
27071 .long __KERNEL32_CS
27072 #endif
27073 END(real_mode_header)
27074diff --git a/arch/x86/realmode/rm/trampoline_32.S b/arch/x86/realmode/rm/trampoline_32.S
27075index c1b2791..f9e31c7 100644
27076--- a/arch/x86/realmode/rm/trampoline_32.S
27077+++ b/arch/x86/realmode/rm/trampoline_32.S
27078@@ -25,6 +25,12 @@
27079 #include <asm/page_types.h>
27080 #include "realmode.h"
27081
27082+#ifdef CONFIG_PAX_KERNEXEC
27083+#define ta(X) (X)
27084+#else
27085+#define ta(X) (pa_ ## X)
27086+#endif
27087+
27088 .text
27089 .code16
27090
27091@@ -39,8 +45,6 @@ ENTRY(trampoline_start)
27092
27093 cli # We should be safe anyway
27094
27095- movl tr_start, %eax # where we need to go
27096-
27097 movl $0xA5A5A5A5, trampoline_status
27098 # write marker for master knows we're running
27099
27100@@ -56,7 +60,7 @@ ENTRY(trampoline_start)
27101 movw $1, %dx # protected mode (PE) bit
27102 lmsw %dx # into protected mode
27103
27104- ljmpl $__BOOT_CS, $pa_startup_32
27105+ ljmpl *(trampoline_header)
27106
27107 .section ".text32","ax"
27108 .code32
27109@@ -67,7 +71,7 @@ ENTRY(startup_32) # note: also used from wakeup_asm.S
27110 .balign 8
27111 GLOBAL(trampoline_header)
27112 tr_start: .space 4
27113- tr_gdt_pad: .space 2
27114+ tr_boot_cs: .space 2
27115 tr_gdt: .space 6
27116 END(trampoline_header)
27117
27118diff --git a/arch/x86/realmode/rm/trampoline_64.S b/arch/x86/realmode/rm/trampoline_64.S
27119index bb360dc..3e5945f 100644
27120--- a/arch/x86/realmode/rm/trampoline_64.S
27121+++ b/arch/x86/realmode/rm/trampoline_64.S
27122@@ -107,7 +107,7 @@ ENTRY(startup_32)
27123 wrmsr
27124
27125 # Enable paging and in turn activate Long Mode
27126- movl $(X86_CR0_PG | X86_CR0_WP | X86_CR0_PE), %eax
27127+ movl $(X86_CR0_PG | X86_CR0_PE), %eax
27128 movl %eax, %cr0
27129
27130 /*
27131diff --git a/arch/x86/tools/relocs.c b/arch/x86/tools/relocs.c
27132index 5a1847d..deccb30 100644
27133--- a/arch/x86/tools/relocs.c
27134+++ b/arch/x86/tools/relocs.c
27135@@ -12,10 +12,13 @@
27136 #include <regex.h>
27137 #include <tools/le_byteshift.h>
27138
27139+#include "../../../include/generated/autoconf.h"
27140+
27141 static void die(char *fmt, ...);
27142
27143 #define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
27144 static Elf32_Ehdr ehdr;
27145+static Elf32_Phdr *phdr;
27146 static unsigned long reloc_count, reloc_idx;
27147 static unsigned long *relocs;
27148 static unsigned long reloc16_count, reloc16_idx;
27149@@ -330,9 +333,39 @@ static void read_ehdr(FILE *fp)
27150 }
27151 }
27152
27153+static void read_phdrs(FILE *fp)
27154+{
27155+ unsigned int i;
27156+
27157+ phdr = calloc(ehdr.e_phnum, sizeof(Elf32_Phdr));
27158+ if (!phdr) {
27159+ die("Unable to allocate %d program headers\n",
27160+ ehdr.e_phnum);
27161+ }
27162+ if (fseek(fp, ehdr.e_phoff, SEEK_SET) < 0) {
27163+ die("Seek to %d failed: %s\n",
27164+ ehdr.e_phoff, strerror(errno));
27165+ }
27166+ if (fread(phdr, sizeof(*phdr), ehdr.e_phnum, fp) != ehdr.e_phnum) {
27167+ die("Cannot read ELF program headers: %s\n",
27168+ strerror(errno));
27169+ }
27170+ for(i = 0; i < ehdr.e_phnum; i++) {
27171+ phdr[i].p_type = elf32_to_cpu(phdr[i].p_type);
27172+ phdr[i].p_offset = elf32_to_cpu(phdr[i].p_offset);
27173+ phdr[i].p_vaddr = elf32_to_cpu(phdr[i].p_vaddr);
27174+ phdr[i].p_paddr = elf32_to_cpu(phdr[i].p_paddr);
27175+ phdr[i].p_filesz = elf32_to_cpu(phdr[i].p_filesz);
27176+ phdr[i].p_memsz = elf32_to_cpu(phdr[i].p_memsz);
27177+ phdr[i].p_flags = elf32_to_cpu(phdr[i].p_flags);
27178+ phdr[i].p_align = elf32_to_cpu(phdr[i].p_align);
27179+ }
27180+
27181+}
27182+
27183 static void read_shdrs(FILE *fp)
27184 {
27185- int i;
27186+ unsigned int i;
27187 Elf32_Shdr shdr;
27188
27189 secs = calloc(ehdr.e_shnum, sizeof(struct section));
27190@@ -367,7 +400,7 @@ static void read_shdrs(FILE *fp)
27191
27192 static void read_strtabs(FILE *fp)
27193 {
27194- int i;
27195+ unsigned int i;
27196 for (i = 0; i < ehdr.e_shnum; i++) {
27197 struct section *sec = &secs[i];
27198 if (sec->shdr.sh_type != SHT_STRTAB) {
27199@@ -392,7 +425,7 @@ static void read_strtabs(FILE *fp)
27200
27201 static void read_symtabs(FILE *fp)
27202 {
27203- int i,j;
27204+ unsigned int i,j;
27205 for (i = 0; i < ehdr.e_shnum; i++) {
27206 struct section *sec = &secs[i];
27207 if (sec->shdr.sh_type != SHT_SYMTAB) {
27208@@ -423,9 +456,11 @@ static void read_symtabs(FILE *fp)
27209 }
27210
27211
27212-static void read_relocs(FILE *fp)
27213+static void read_relocs(FILE *fp, int use_real_mode)
27214 {
27215- int i,j;
27216+ unsigned int i,j;
27217+ uint32_t base;
27218+
27219 for (i = 0; i < ehdr.e_shnum; i++) {
27220 struct section *sec = &secs[i];
27221 if (sec->shdr.sh_type != SHT_REL) {
27222@@ -445,9 +480,22 @@ static void read_relocs(FILE *fp)
27223 die("Cannot read symbol table: %s\n",
27224 strerror(errno));
27225 }
27226+ base = 0;
27227+
27228+#ifdef CONFIG_X86_32
27229+ for (j = 0; !use_real_mode && j < ehdr.e_phnum; j++) {
27230+ if (phdr[j].p_type != PT_LOAD )
27231+ continue;
27232+ 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)
27233+ continue;
27234+ base = CONFIG_PAGE_OFFSET + phdr[j].p_paddr - phdr[j].p_vaddr;
27235+ break;
27236+ }
27237+#endif
27238+
27239 for (j = 0; j < sec->shdr.sh_size/sizeof(Elf32_Rel); j++) {
27240 Elf32_Rel *rel = &sec->reltab[j];
27241- rel->r_offset = elf32_to_cpu(rel->r_offset);
27242+ rel->r_offset = elf32_to_cpu(rel->r_offset) + base;
27243 rel->r_info = elf32_to_cpu(rel->r_info);
27244 }
27245 }
27246@@ -456,13 +504,13 @@ static void read_relocs(FILE *fp)
27247
27248 static void print_absolute_symbols(void)
27249 {
27250- int i;
27251+ unsigned int i;
27252 printf("Absolute symbols\n");
27253 printf(" Num: Value Size Type Bind Visibility Name\n");
27254 for (i = 0; i < ehdr.e_shnum; i++) {
27255 struct section *sec = &secs[i];
27256 char *sym_strtab;
27257- int j;
27258+ unsigned int j;
27259
27260 if (sec->shdr.sh_type != SHT_SYMTAB) {
27261 continue;
27262@@ -489,14 +537,14 @@ static void print_absolute_symbols(void)
27263
27264 static void print_absolute_relocs(void)
27265 {
27266- int i, printed = 0;
27267+ unsigned int i, printed = 0;
27268
27269 for (i = 0; i < ehdr.e_shnum; i++) {
27270 struct section *sec = &secs[i];
27271 struct section *sec_applies, *sec_symtab;
27272 char *sym_strtab;
27273 Elf32_Sym *sh_symtab;
27274- int j;
27275+ unsigned int j;
27276 if (sec->shdr.sh_type != SHT_REL) {
27277 continue;
27278 }
27279@@ -558,13 +606,13 @@ static void print_absolute_relocs(void)
27280 static void walk_relocs(void (*visit)(Elf32_Rel *rel, Elf32_Sym *sym),
27281 int use_real_mode)
27282 {
27283- int i;
27284+ unsigned int i;
27285 /* Walk through the relocations */
27286 for (i = 0; i < ehdr.e_shnum; i++) {
27287 char *sym_strtab;
27288 Elf32_Sym *sh_symtab;
27289 struct section *sec_applies, *sec_symtab;
27290- int j;
27291+ unsigned int j;
27292 struct section *sec = &secs[i];
27293
27294 if (sec->shdr.sh_type != SHT_REL) {
27295@@ -588,6 +636,24 @@ static void walk_relocs(void (*visit)(Elf32_Rel *rel, Elf32_Sym *sym),
27296 sym = &sh_symtab[ELF32_R_SYM(rel->r_info)];
27297 r_type = ELF32_R_TYPE(rel->r_info);
27298
27299+ if (!use_real_mode) {
27300+ /* Don't relocate actual per-cpu variables, they are absolute indices, not addresses */
27301+ if (!strcmp(sec_name(sym->st_shndx), ".data..percpu") && strcmp(sym_name(sym_strtab, sym), "__per_cpu_load"))
27302+ continue;
27303+
27304+#if defined(CONFIG_PAX_KERNEXEC) && defined(CONFIG_X86_32)
27305+ /* Don't relocate actual code, they are relocated implicitly by the base address of KERNEL_CS */
27306+ if (!strcmp(sec_name(sym->st_shndx), ".text.end") && !strcmp(sym_name(sym_strtab, sym), "_etext"))
27307+ continue;
27308+ if (!strcmp(sec_name(sym->st_shndx), ".init.text"))
27309+ continue;
27310+ if (!strcmp(sec_name(sym->st_shndx), ".exit.text"))
27311+ continue;
27312+ if (!strcmp(sec_name(sym->st_shndx), ".text") && strcmp(sym_name(sym_strtab, sym), "__LOAD_PHYSICAL_ADDR"))
27313+ continue;
27314+#endif
27315+ }
27316+
27317 shn_abs = sym->st_shndx == SHN_ABS;
27318
27319 switch (r_type) {
27320@@ -681,7 +747,7 @@ static int write32(unsigned int v, FILE *f)
27321
27322 static void emit_relocs(int as_text, int use_real_mode)
27323 {
27324- int i;
27325+ unsigned int i;
27326 /* Count how many relocations I have and allocate space for them. */
27327 reloc_count = 0;
27328 walk_relocs(count_reloc, use_real_mode);
27329@@ -808,10 +874,11 @@ int main(int argc, char **argv)
27330 fname, strerror(errno));
27331 }
27332 read_ehdr(fp);
27333+ read_phdrs(fp);
27334 read_shdrs(fp);
27335 read_strtabs(fp);
27336 read_symtabs(fp);
27337- read_relocs(fp);
27338+ read_relocs(fp, use_real_mode);
27339 if (show_absolute_syms) {
27340 print_absolute_symbols();
27341 return 0;
27342diff --git a/arch/x86/vdso/Makefile b/arch/x86/vdso/Makefile
27343index fd14be1..e3c79c0 100644
27344--- a/arch/x86/vdso/Makefile
27345+++ b/arch/x86/vdso/Makefile
27346@@ -181,7 +181,7 @@ quiet_cmd_vdso = VDSO $@
27347 -Wl,-T,$(filter %.lds,$^) $(filter %.o,$^) && \
27348 sh $(srctree)/$(src)/checkundef.sh '$(NM)' '$@'
27349
27350-VDSO_LDFLAGS = -fPIC -shared $(call cc-ldoption, -Wl$(comma)--hash-style=sysv)
27351+VDSO_LDFLAGS = -fPIC -shared -Wl,--no-undefined $(call cc-ldoption, -Wl$(comma)--hash-style=sysv)
27352 GCOV_PROFILE := n
27353
27354 #
27355diff --git a/arch/x86/vdso/vdso32-setup.c b/arch/x86/vdso/vdso32-setup.c
27356index 0faad64..39ef157 100644
27357--- a/arch/x86/vdso/vdso32-setup.c
27358+++ b/arch/x86/vdso/vdso32-setup.c
27359@@ -25,6 +25,7 @@
27360 #include <asm/tlbflush.h>
27361 #include <asm/vdso.h>
27362 #include <asm/proto.h>
27363+#include <asm/mman.h>
27364
27365 enum {
27366 VDSO_DISABLED = 0,
27367@@ -226,7 +227,7 @@ static inline void map_compat_vdso(int map)
27368 void enable_sep_cpu(void)
27369 {
27370 int cpu = get_cpu();
27371- struct tss_struct *tss = &per_cpu(init_tss, cpu);
27372+ struct tss_struct *tss = init_tss + cpu;
27373
27374 if (!boot_cpu_has(X86_FEATURE_SEP)) {
27375 put_cpu();
27376@@ -249,7 +250,7 @@ static int __init gate_vma_init(void)
27377 gate_vma.vm_start = FIXADDR_USER_START;
27378 gate_vma.vm_end = FIXADDR_USER_END;
27379 gate_vma.vm_flags = VM_READ | VM_MAYREAD | VM_EXEC | VM_MAYEXEC;
27380- gate_vma.vm_page_prot = __P101;
27381+ gate_vma.vm_page_prot = vm_get_page_prot(gate_vma.vm_flags);
27382
27383 return 0;
27384 }
27385@@ -330,14 +331,14 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
27386 if (compat)
27387 addr = VDSO_HIGH_BASE;
27388 else {
27389- addr = get_unmapped_area(NULL, 0, PAGE_SIZE, 0, 0);
27390+ addr = get_unmapped_area(NULL, 0, PAGE_SIZE, 0, MAP_EXECUTABLE);
27391 if (IS_ERR_VALUE(addr)) {
27392 ret = addr;
27393 goto up_fail;
27394 }
27395 }
27396
27397- current->mm->context.vdso = (void *)addr;
27398+ current->mm->context.vdso = addr;
27399
27400 if (compat_uses_vma || !compat) {
27401 /*
27402@@ -353,11 +354,11 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
27403 }
27404
27405 current_thread_info()->sysenter_return =
27406- VDSO32_SYMBOL(addr, SYSENTER_RETURN);
27407+ (__force void __user *)VDSO32_SYMBOL(addr, SYSENTER_RETURN);
27408
27409 up_fail:
27410 if (ret)
27411- current->mm->context.vdso = NULL;
27412+ current->mm->context.vdso = 0;
27413
27414 up_write(&mm->mmap_sem);
27415
27416@@ -404,8 +405,14 @@ __initcall(ia32_binfmt_init);
27417
27418 const char *arch_vma_name(struct vm_area_struct *vma)
27419 {
27420- if (vma->vm_mm && vma->vm_start == (long)vma->vm_mm->context.vdso)
27421+ if (vma->vm_mm && vma->vm_start == vma->vm_mm->context.vdso)
27422 return "[vdso]";
27423+
27424+#ifdef CONFIG_PAX_SEGMEXEC
27425+ if (vma->vm_mm && vma->vm_mirror && vma->vm_mirror->vm_start == vma->vm_mm->context.vdso)
27426+ return "[vdso]";
27427+#endif
27428+
27429 return NULL;
27430 }
27431
27432@@ -415,7 +422,7 @@ struct vm_area_struct *get_gate_vma(struct mm_struct *mm)
27433 * Check to see if the corresponding task was created in compat vdso
27434 * mode.
27435 */
27436- if (mm && mm->context.vdso == (void *)VDSO_HIGH_BASE)
27437+ if (mm && mm->context.vdso == VDSO_HIGH_BASE)
27438 return &gate_vma;
27439 return NULL;
27440 }
27441diff --git a/arch/x86/vdso/vma.c b/arch/x86/vdso/vma.c
27442index 00aaf04..4a26505 100644
27443--- a/arch/x86/vdso/vma.c
27444+++ b/arch/x86/vdso/vma.c
27445@@ -16,8 +16,6 @@
27446 #include <asm/vdso.h>
27447 #include <asm/page.h>
27448
27449-unsigned int __read_mostly vdso_enabled = 1;
27450-
27451 extern char vdso_start[], vdso_end[];
27452 extern unsigned short vdso_sync_cpuid;
27453
27454@@ -141,7 +139,6 @@ static unsigned long vdso_addr(unsigned long start, unsigned len)
27455 * unaligned here as a result of stack start randomization.
27456 */
27457 addr = PAGE_ALIGN(addr);
27458- addr = align_addr(addr, NULL, ALIGN_VDSO);
27459
27460 return addr;
27461 }
27462@@ -154,30 +151,31 @@ static int setup_additional_pages(struct linux_binprm *bprm,
27463 unsigned size)
27464 {
27465 struct mm_struct *mm = current->mm;
27466- unsigned long addr;
27467+ unsigned long addr = 0;
27468 int ret;
27469
27470- if (!vdso_enabled)
27471- return 0;
27472-
27473 down_write(&mm->mmap_sem);
27474+
27475+#ifdef CONFIG_PAX_RANDMMAP
27476+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
27477+#endif
27478+
27479 addr = vdso_addr(mm->start_stack, size);
27480+ addr = align_addr(addr, NULL, ALIGN_VDSO);
27481 addr = get_unmapped_area(NULL, addr, size, 0, 0);
27482 if (IS_ERR_VALUE(addr)) {
27483 ret = addr;
27484 goto up_fail;
27485 }
27486
27487- current->mm->context.vdso = (void *)addr;
27488+ mm->context.vdso = addr;
27489
27490 ret = install_special_mapping(mm, addr, size,
27491 VM_READ|VM_EXEC|
27492 VM_MAYREAD|VM_MAYWRITE|VM_MAYEXEC,
27493 pages);
27494- if (ret) {
27495- current->mm->context.vdso = NULL;
27496- goto up_fail;
27497- }
27498+ if (ret)
27499+ mm->context.vdso = 0;
27500
27501 up_fail:
27502 up_write(&mm->mmap_sem);
27503@@ -197,10 +195,3 @@ int x32_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
27504 vdsox32_size);
27505 }
27506 #endif
27507-
27508-static __init int vdso_setup(char *s)
27509-{
27510- vdso_enabled = simple_strtoul(s, NULL, 0);
27511- return 0;
27512-}
27513-__setup("vdso=", vdso_setup);
27514diff --git a/arch/x86/xen/enlighten.c b/arch/x86/xen/enlighten.c
27515index c1461de..355f120 100644
27516--- a/arch/x86/xen/enlighten.c
27517+++ b/arch/x86/xen/enlighten.c
27518@@ -98,8 +98,6 @@ EXPORT_SYMBOL_GPL(xen_start_info);
27519
27520 struct shared_info xen_dummy_shared_info;
27521
27522-void *xen_initial_gdt;
27523-
27524 RESERVE_BRK(shared_info_page_brk, PAGE_SIZE);
27525 __read_mostly int xen_have_vector_callback;
27526 EXPORT_SYMBOL_GPL(xen_have_vector_callback);
27527@@ -917,21 +915,21 @@ static u32 xen_safe_apic_wait_icr_idle(void)
27528
27529 static void set_xen_basic_apic_ops(void)
27530 {
27531- apic->read = xen_apic_read;
27532- apic->write = xen_apic_write;
27533- apic->icr_read = xen_apic_icr_read;
27534- apic->icr_write = xen_apic_icr_write;
27535- apic->wait_icr_idle = xen_apic_wait_icr_idle;
27536- apic->safe_wait_icr_idle = xen_safe_apic_wait_icr_idle;
27537- apic->set_apic_id = xen_set_apic_id;
27538- apic->get_apic_id = xen_get_apic_id;
27539+ *(void **)&apic->read = xen_apic_read;
27540+ *(void **)&apic->write = xen_apic_write;
27541+ *(void **)&apic->icr_read = xen_apic_icr_read;
27542+ *(void **)&apic->icr_write = xen_apic_icr_write;
27543+ *(void **)&apic->wait_icr_idle = xen_apic_wait_icr_idle;
27544+ *(void **)&apic->safe_wait_icr_idle = xen_safe_apic_wait_icr_idle;
27545+ *(void **)&apic->set_apic_id = xen_set_apic_id;
27546+ *(void **)&apic->get_apic_id = xen_get_apic_id;
27547
27548 #ifdef CONFIG_SMP
27549- apic->send_IPI_allbutself = xen_send_IPI_allbutself;
27550- apic->send_IPI_mask_allbutself = xen_send_IPI_mask_allbutself;
27551- apic->send_IPI_mask = xen_send_IPI_mask;
27552- apic->send_IPI_all = xen_send_IPI_all;
27553- apic->send_IPI_self = xen_send_IPI_self;
27554+ *(void **)&apic->send_IPI_allbutself = xen_send_IPI_allbutself;
27555+ *(void **)&apic->send_IPI_mask_allbutself = xen_send_IPI_mask_allbutself;
27556+ *(void **)&apic->send_IPI_mask = xen_send_IPI_mask;
27557+ *(void **)&apic->send_IPI_all = xen_send_IPI_all;
27558+ *(void **)&apic->send_IPI_self = xen_send_IPI_self;
27559 #endif
27560 }
27561
27562@@ -1221,30 +1219,30 @@ static const struct pv_apic_ops xen_apic_ops __initconst = {
27563 #endif
27564 };
27565
27566-static void xen_reboot(int reason)
27567+static __noreturn void xen_reboot(int reason)
27568 {
27569 struct sched_shutdown r = { .reason = reason };
27570
27571- if (HYPERVISOR_sched_op(SCHEDOP_shutdown, &r))
27572- BUG();
27573+ HYPERVISOR_sched_op(SCHEDOP_shutdown, &r);
27574+ BUG();
27575 }
27576
27577-static void xen_restart(char *msg)
27578+static __noreturn void xen_restart(char *msg)
27579 {
27580 xen_reboot(SHUTDOWN_reboot);
27581 }
27582
27583-static void xen_emergency_restart(void)
27584+static __noreturn void xen_emergency_restart(void)
27585 {
27586 xen_reboot(SHUTDOWN_reboot);
27587 }
27588
27589-static void xen_machine_halt(void)
27590+static __noreturn void xen_machine_halt(void)
27591 {
27592 xen_reboot(SHUTDOWN_poweroff);
27593 }
27594
27595-static void xen_machine_power_off(void)
27596+static __noreturn void xen_machine_power_off(void)
27597 {
27598 if (pm_power_off)
27599 pm_power_off();
27600@@ -1347,7 +1345,17 @@ asmlinkage void __init xen_start_kernel(void)
27601 __userpte_alloc_gfp &= ~__GFP_HIGHMEM;
27602
27603 /* Work out if we support NX */
27604- x86_configure_nx();
27605+#if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
27606+ if ((cpuid_eax(0x80000000) & 0xffff0000) == 0x80000000 &&
27607+ (cpuid_edx(0x80000001) & (1U << (X86_FEATURE_NX & 31)))) {
27608+ unsigned l, h;
27609+
27610+ __supported_pte_mask |= _PAGE_NX;
27611+ rdmsr(MSR_EFER, l, h);
27612+ l |= EFER_NX;
27613+ wrmsr(MSR_EFER, l, h);
27614+ }
27615+#endif
27616
27617 xen_setup_features();
27618
27619@@ -1378,13 +1386,6 @@ asmlinkage void __init xen_start_kernel(void)
27620
27621 machine_ops = xen_machine_ops;
27622
27623- /*
27624- * The only reliable way to retain the initial address of the
27625- * percpu gdt_page is to remember it here, so we can go and
27626- * mark it RW later, when the initial percpu area is freed.
27627- */
27628- xen_initial_gdt = &per_cpu(gdt_page, 0);
27629-
27630 xen_smp_init();
27631
27632 #ifdef CONFIG_ACPI_NUMA
27633diff --git a/arch/x86/xen/mmu.c b/arch/x86/xen/mmu.c
27634index dde1a3f..6b663e6 100644
27635--- a/arch/x86/xen/mmu.c
27636+++ b/arch/x86/xen/mmu.c
27637@@ -1784,6 +1784,9 @@ pgd_t * __init xen_setup_kernel_pagetable(pgd_t *pgd,
27638 convert_pfn_mfn(init_level4_pgt);
27639 convert_pfn_mfn(level3_ident_pgt);
27640 convert_pfn_mfn(level3_kernel_pgt);
27641+ convert_pfn_mfn(level3_vmalloc_start_pgt);
27642+ convert_pfn_mfn(level3_vmalloc_end_pgt);
27643+ convert_pfn_mfn(level3_vmemmap_pgt);
27644
27645 l3 = m2v(pgd[pgd_index(__START_KERNEL_map)].pgd);
27646 l2 = m2v(l3[pud_index(__START_KERNEL_map)].pud);
27647@@ -1802,7 +1805,11 @@ pgd_t * __init xen_setup_kernel_pagetable(pgd_t *pgd,
27648 set_page_prot(init_level4_pgt, PAGE_KERNEL_RO);
27649 set_page_prot(level3_ident_pgt, PAGE_KERNEL_RO);
27650 set_page_prot(level3_kernel_pgt, PAGE_KERNEL_RO);
27651+ set_page_prot(level3_vmalloc_start_pgt, PAGE_KERNEL_RO);
27652+ set_page_prot(level3_vmalloc_end_pgt, PAGE_KERNEL_RO);
27653+ set_page_prot(level3_vmemmap_pgt, PAGE_KERNEL_RO);
27654 set_page_prot(level3_user_vsyscall, PAGE_KERNEL_RO);
27655+ set_page_prot(level2_vmemmap_pgt, PAGE_KERNEL_RO);
27656 set_page_prot(level2_kernel_pgt, PAGE_KERNEL_RO);
27657 set_page_prot(level2_fixmap_pgt, PAGE_KERNEL_RO);
27658
27659@@ -1986,6 +1993,7 @@ static void __init xen_post_allocator_init(void)
27660 pv_mmu_ops.set_pud = xen_set_pud;
27661 #if PAGETABLE_LEVELS == 4
27662 pv_mmu_ops.set_pgd = xen_set_pgd;
27663+ pv_mmu_ops.set_pgd_batched = xen_set_pgd;
27664 #endif
27665
27666 /* This will work as long as patching hasn't happened yet
27667@@ -2067,6 +2075,7 @@ static const struct pv_mmu_ops xen_mmu_ops __initconst = {
27668 .pud_val = PV_CALLEE_SAVE(xen_pud_val),
27669 .make_pud = PV_CALLEE_SAVE(xen_make_pud),
27670 .set_pgd = xen_set_pgd_hyper,
27671+ .set_pgd_batched = xen_set_pgd_hyper,
27672
27673 .alloc_pud = xen_alloc_pmd_init,
27674 .release_pud = xen_release_pmd_init,
27675diff --git a/arch/x86/xen/smp.c b/arch/x86/xen/smp.c
27676index f58dca7..ad21f52 100644
27677--- a/arch/x86/xen/smp.c
27678+++ b/arch/x86/xen/smp.c
27679@@ -229,11 +229,6 @@ static void __init xen_smp_prepare_boot_cpu(void)
27680 {
27681 BUG_ON(smp_processor_id() != 0);
27682 native_smp_prepare_boot_cpu();
27683-
27684- /* We've switched to the "real" per-cpu gdt, so make sure the
27685- old memory can be recycled */
27686- make_lowmem_page_readwrite(xen_initial_gdt);
27687-
27688 xen_filter_cpu_maps();
27689 xen_setup_vcpu_info_placement();
27690 }
27691@@ -300,12 +295,12 @@ cpu_initialize_context(unsigned int cpu, struct task_struct *idle)
27692 gdt = get_cpu_gdt_table(cpu);
27693
27694 ctxt->flags = VGCF_IN_KERNEL;
27695- ctxt->user_regs.ds = __USER_DS;
27696- ctxt->user_regs.es = __USER_DS;
27697+ ctxt->user_regs.ds = __KERNEL_DS;
27698+ ctxt->user_regs.es = __KERNEL_DS;
27699 ctxt->user_regs.ss = __KERNEL_DS;
27700 #ifdef CONFIG_X86_32
27701 ctxt->user_regs.fs = __KERNEL_PERCPU;
27702- ctxt->user_regs.gs = __KERNEL_STACK_CANARY;
27703+ savesegment(gs, ctxt->user_regs.gs);
27704 #else
27705 ctxt->gs_base_kernel = per_cpu_offset(cpu);
27706 #endif
27707@@ -355,13 +350,12 @@ static int __cpuinit xen_cpu_up(unsigned int cpu, struct task_struct *idle)
27708 int rc;
27709
27710 per_cpu(current_task, cpu) = idle;
27711+ per_cpu(current_tinfo, cpu) = &idle->tinfo;
27712 #ifdef CONFIG_X86_32
27713 irq_ctx_init(cpu);
27714 #else
27715 clear_tsk_thread_flag(idle, TIF_FORK);
27716- per_cpu(kernel_stack, cpu) =
27717- (unsigned long)task_stack_page(idle) -
27718- KERNEL_STACK_OFFSET + THREAD_SIZE;
27719+ per_cpu(kernel_stack, cpu) = (unsigned long)task_stack_page(idle) - 16 + THREAD_SIZE;
27720 #endif
27721 xen_setup_runstate_info(cpu);
27722 xen_setup_timer(cpu);
27723diff --git a/arch/x86/xen/xen-asm_32.S b/arch/x86/xen/xen-asm_32.S
27724index f9643fc..602e8af 100644
27725--- a/arch/x86/xen/xen-asm_32.S
27726+++ b/arch/x86/xen/xen-asm_32.S
27727@@ -84,14 +84,14 @@ ENTRY(xen_iret)
27728 ESP_OFFSET=4 # bytes pushed onto stack
27729
27730 /*
27731- * Store vcpu_info pointer for easy access. Do it this way to
27732- * avoid having to reload %fs
27733+ * Store vcpu_info pointer for easy access.
27734 */
27735 #ifdef CONFIG_SMP
27736- GET_THREAD_INFO(%eax)
27737- movl TI_cpu(%eax), %eax
27738- movl __per_cpu_offset(,%eax,4), %eax
27739- mov xen_vcpu(%eax), %eax
27740+ push %fs
27741+ mov $(__KERNEL_PERCPU), %eax
27742+ mov %eax, %fs
27743+ mov PER_CPU_VAR(xen_vcpu), %eax
27744+ pop %fs
27745 #else
27746 movl xen_vcpu, %eax
27747 #endif
27748diff --git a/arch/x86/xen/xen-head.S b/arch/x86/xen/xen-head.S
27749index aaa7291..3f77960 100644
27750--- a/arch/x86/xen/xen-head.S
27751+++ b/arch/x86/xen/xen-head.S
27752@@ -19,6 +19,17 @@ ENTRY(startup_xen)
27753 #ifdef CONFIG_X86_32
27754 mov %esi,xen_start_info
27755 mov $init_thread_union+THREAD_SIZE,%esp
27756+#ifdef CONFIG_SMP
27757+ movl $cpu_gdt_table,%edi
27758+ movl $__per_cpu_load,%eax
27759+ movw %ax,__KERNEL_PERCPU + 2(%edi)
27760+ rorl $16,%eax
27761+ movb %al,__KERNEL_PERCPU + 4(%edi)
27762+ movb %ah,__KERNEL_PERCPU + 7(%edi)
27763+ movl $__per_cpu_end - 1,%eax
27764+ subl $__per_cpu_start,%eax
27765+ movw %ax,__KERNEL_PERCPU + 0(%edi)
27766+#endif
27767 #else
27768 mov %rsi,xen_start_info
27769 mov $init_thread_union+THREAD_SIZE,%rsp
27770diff --git a/arch/x86/xen/xen-ops.h b/arch/x86/xen/xen-ops.h
27771index 202d4c1..99b072a 100644
27772--- a/arch/x86/xen/xen-ops.h
27773+++ b/arch/x86/xen/xen-ops.h
27774@@ -10,8 +10,6 @@
27775 extern const char xen_hypervisor_callback[];
27776 extern const char xen_failsafe_callback[];
27777
27778-extern void *xen_initial_gdt;
27779-
27780 struct trap_info;
27781 void xen_copy_trap_info(struct trap_info *traps);
27782
27783diff --git a/arch/xtensa/variants/dc232b/include/variant/core.h b/arch/xtensa/variants/dc232b/include/variant/core.h
27784index 525bd3d..ef888b1 100644
27785--- a/arch/xtensa/variants/dc232b/include/variant/core.h
27786+++ b/arch/xtensa/variants/dc232b/include/variant/core.h
27787@@ -119,9 +119,9 @@
27788 ----------------------------------------------------------------------*/
27789
27790 #define XCHAL_ICACHE_LINESIZE 32 /* I-cache line size in bytes */
27791-#define XCHAL_DCACHE_LINESIZE 32 /* D-cache line size in bytes */
27792 #define XCHAL_ICACHE_LINEWIDTH 5 /* log2(I line size in bytes) */
27793 #define XCHAL_DCACHE_LINEWIDTH 5 /* log2(D line size in bytes) */
27794+#define XCHAL_DCACHE_LINESIZE (_AC(1,UL) << XCHAL_DCACHE_LINEWIDTH) /* D-cache line size in bytes */
27795
27796 #define XCHAL_ICACHE_SIZE 16384 /* I-cache size in bytes or 0 */
27797 #define XCHAL_DCACHE_SIZE 16384 /* D-cache size in bytes or 0 */
27798diff --git a/arch/xtensa/variants/fsf/include/variant/core.h b/arch/xtensa/variants/fsf/include/variant/core.h
27799index 2f33760..835e50a 100644
27800--- a/arch/xtensa/variants/fsf/include/variant/core.h
27801+++ b/arch/xtensa/variants/fsf/include/variant/core.h
27802@@ -11,6 +11,7 @@
27803 #ifndef _XTENSA_CORE_H
27804 #define _XTENSA_CORE_H
27805
27806+#include <linux/const.h>
27807
27808 /****************************************************************************
27809 Parameters Useful for Any Code, USER or PRIVILEGED
27810@@ -112,9 +113,9 @@
27811 ----------------------------------------------------------------------*/
27812
27813 #define XCHAL_ICACHE_LINESIZE 16 /* I-cache line size in bytes */
27814-#define XCHAL_DCACHE_LINESIZE 16 /* D-cache line size in bytes */
27815 #define XCHAL_ICACHE_LINEWIDTH 4 /* log2(I line size in bytes) */
27816 #define XCHAL_DCACHE_LINEWIDTH 4 /* log2(D line size in bytes) */
27817+#define XCHAL_DCACHE_LINESIZE (_AC(1,UL) << XCHAL_DCACHE_LINEWIDTH) /* D-cache line size in bytes */
27818
27819 #define XCHAL_ICACHE_SIZE 8192 /* I-cache size in bytes or 0 */
27820 #define XCHAL_DCACHE_SIZE 8192 /* D-cache size in bytes or 0 */
27821diff --git a/arch/xtensa/variants/s6000/include/variant/core.h b/arch/xtensa/variants/s6000/include/variant/core.h
27822index af00795..2bb8105 100644
27823--- a/arch/xtensa/variants/s6000/include/variant/core.h
27824+++ b/arch/xtensa/variants/s6000/include/variant/core.h
27825@@ -11,6 +11,7 @@
27826 #ifndef _XTENSA_CORE_CONFIGURATION_H
27827 #define _XTENSA_CORE_CONFIGURATION_H
27828
27829+#include <linux/const.h>
27830
27831 /****************************************************************************
27832 Parameters Useful for Any Code, USER or PRIVILEGED
27833@@ -118,9 +119,9 @@
27834 ----------------------------------------------------------------------*/
27835
27836 #define XCHAL_ICACHE_LINESIZE 16 /* I-cache line size in bytes */
27837-#define XCHAL_DCACHE_LINESIZE 16 /* D-cache line size in bytes */
27838 #define XCHAL_ICACHE_LINEWIDTH 4 /* log2(I line size in bytes) */
27839 #define XCHAL_DCACHE_LINEWIDTH 4 /* log2(D line size in bytes) */
27840+#define XCHAL_DCACHE_LINESIZE (_AC(1,UL) << XCHAL_DCACHE_LINEWIDTH) /* D-cache line size in bytes */
27841
27842 #define XCHAL_ICACHE_SIZE 32768 /* I-cache size in bytes or 0 */
27843 #define XCHAL_DCACHE_SIZE 32768 /* D-cache size in bytes or 0 */
27844diff --git a/block/blk-iopoll.c b/block/blk-iopoll.c
27845index 58916af..9cb880b 100644
27846--- a/block/blk-iopoll.c
27847+++ b/block/blk-iopoll.c
27848@@ -77,7 +77,7 @@ void blk_iopoll_complete(struct blk_iopoll *iopoll)
27849 }
27850 EXPORT_SYMBOL(blk_iopoll_complete);
27851
27852-static void blk_iopoll_softirq(struct softirq_action *h)
27853+static void blk_iopoll_softirq(void)
27854 {
27855 struct list_head *list = &__get_cpu_var(blk_cpu_iopoll);
27856 int rearm = 0, budget = blk_iopoll_budget;
27857diff --git a/block/blk-map.c b/block/blk-map.c
27858index 623e1cd..ca1e109 100644
27859--- a/block/blk-map.c
27860+++ b/block/blk-map.c
27861@@ -302,7 +302,7 @@ int blk_rq_map_kern(struct request_queue *q, struct request *rq, void *kbuf,
27862 if (!len || !kbuf)
27863 return -EINVAL;
27864
27865- do_copy = !blk_rq_aligned(q, addr, len) || object_is_on_stack(kbuf);
27866+ do_copy = !blk_rq_aligned(q, addr, len) || object_starts_on_stack(kbuf);
27867 if (do_copy)
27868 bio = bio_copy_kern(q, kbuf, len, gfp_mask, reading);
27869 else
27870diff --git a/block/blk-softirq.c b/block/blk-softirq.c
27871index 467c8de..4bddc6d 100644
27872--- a/block/blk-softirq.c
27873+++ b/block/blk-softirq.c
27874@@ -18,7 +18,7 @@ static DEFINE_PER_CPU(struct list_head, blk_cpu_done);
27875 * Softirq action handler - move entries to local list and loop over them
27876 * while passing them to the queue registered handler.
27877 */
27878-static void blk_done_softirq(struct softirq_action *h)
27879+static void blk_done_softirq(void)
27880 {
27881 struct list_head *cpu_list, local_list;
27882
27883diff --git a/block/bsg.c b/block/bsg.c
27884index ff64ae3..593560c 100644
27885--- a/block/bsg.c
27886+++ b/block/bsg.c
27887@@ -176,16 +176,24 @@ static int blk_fill_sgv4_hdr_rq(struct request_queue *q, struct request *rq,
27888 struct sg_io_v4 *hdr, struct bsg_device *bd,
27889 fmode_t has_write_perm)
27890 {
27891+ unsigned char tmpcmd[sizeof(rq->__cmd)];
27892+ unsigned char *cmdptr;
27893+
27894 if (hdr->request_len > BLK_MAX_CDB) {
27895 rq->cmd = kzalloc(hdr->request_len, GFP_KERNEL);
27896 if (!rq->cmd)
27897 return -ENOMEM;
27898- }
27899+ cmdptr = rq->cmd;
27900+ } else
27901+ cmdptr = tmpcmd;
27902
27903- if (copy_from_user(rq->cmd, (void __user *)(unsigned long)hdr->request,
27904+ if (copy_from_user(cmdptr, (void __user *)(unsigned long)hdr->request,
27905 hdr->request_len))
27906 return -EFAULT;
27907
27908+ if (cmdptr != rq->cmd)
27909+ memcpy(rq->cmd, cmdptr, hdr->request_len);
27910+
27911 if (hdr->subprotocol == BSG_SUB_PROTOCOL_SCSI_CMD) {
27912 if (blk_verify_command(rq->cmd, has_write_perm))
27913 return -EPERM;
27914diff --git a/block/compat_ioctl.c b/block/compat_ioctl.c
27915index 7c668c8..db3521c 100644
27916--- a/block/compat_ioctl.c
27917+++ b/block/compat_ioctl.c
27918@@ -340,7 +340,7 @@ static int compat_fd_ioctl(struct block_device *bdev, fmode_t mode,
27919 err |= __get_user(f->spec1, &uf->spec1);
27920 err |= __get_user(f->fmt_gap, &uf->fmt_gap);
27921 err |= __get_user(name, &uf->name);
27922- f->name = compat_ptr(name);
27923+ f->name = (void __force_kernel *)compat_ptr(name);
27924 if (err) {
27925 err = -EFAULT;
27926 goto out;
27927diff --git a/block/partitions/efi.c b/block/partitions/efi.c
27928index 6296b40..417c00f 100644
27929--- a/block/partitions/efi.c
27930+++ b/block/partitions/efi.c
27931@@ -234,14 +234,14 @@ static gpt_entry *alloc_read_gpt_entries(struct parsed_partitions *state,
27932 if (!gpt)
27933 return NULL;
27934
27935+ if (!le32_to_cpu(gpt->num_partition_entries))
27936+ return NULL;
27937+ pte = kcalloc(le32_to_cpu(gpt->num_partition_entries), le32_to_cpu(gpt->sizeof_partition_entry), GFP_KERNEL);
27938+ if (!pte)
27939+ return NULL;
27940+
27941 count = le32_to_cpu(gpt->num_partition_entries) *
27942 le32_to_cpu(gpt->sizeof_partition_entry);
27943- if (!count)
27944- return NULL;
27945- pte = kzalloc(count, GFP_KERNEL);
27946- if (!pte)
27947- return NULL;
27948-
27949 if (read_lba(state, le64_to_cpu(gpt->partition_entry_lba),
27950 (u8 *) pte,
27951 count) < count) {
27952diff --git a/block/scsi_ioctl.c b/block/scsi_ioctl.c
27953index 9a87daa..fb17486 100644
27954--- a/block/scsi_ioctl.c
27955+++ b/block/scsi_ioctl.c
27956@@ -223,8 +223,20 @@ EXPORT_SYMBOL(blk_verify_command);
27957 static int blk_fill_sghdr_rq(struct request_queue *q, struct request *rq,
27958 struct sg_io_hdr *hdr, fmode_t mode)
27959 {
27960- if (copy_from_user(rq->cmd, hdr->cmdp, hdr->cmd_len))
27961+ unsigned char tmpcmd[sizeof(rq->__cmd)];
27962+ unsigned char *cmdptr;
27963+
27964+ if (rq->cmd != rq->__cmd)
27965+ cmdptr = rq->cmd;
27966+ else
27967+ cmdptr = tmpcmd;
27968+
27969+ if (copy_from_user(cmdptr, hdr->cmdp, hdr->cmd_len))
27970 return -EFAULT;
27971+
27972+ if (cmdptr != rq->cmd)
27973+ memcpy(rq->cmd, cmdptr, hdr->cmd_len);
27974+
27975 if (blk_verify_command(rq->cmd, mode & FMODE_WRITE))
27976 return -EPERM;
27977
27978@@ -433,6 +445,8 @@ int sg_scsi_ioctl(struct request_queue *q, struct gendisk *disk, fmode_t mode,
27979 int err;
27980 unsigned int in_len, out_len, bytes, opcode, cmdlen;
27981 char *buffer = NULL, sense[SCSI_SENSE_BUFFERSIZE];
27982+ unsigned char tmpcmd[sizeof(rq->__cmd)];
27983+ unsigned char *cmdptr;
27984
27985 if (!sic)
27986 return -EINVAL;
27987@@ -466,9 +480,18 @@ int sg_scsi_ioctl(struct request_queue *q, struct gendisk *disk, fmode_t mode,
27988 */
27989 err = -EFAULT;
27990 rq->cmd_len = cmdlen;
27991- if (copy_from_user(rq->cmd, sic->data, cmdlen))
27992+
27993+ if (rq->cmd != rq->__cmd)
27994+ cmdptr = rq->cmd;
27995+ else
27996+ cmdptr = tmpcmd;
27997+
27998+ if (copy_from_user(cmdptr, sic->data, cmdlen))
27999 goto error;
28000
28001+ if (rq->cmd != cmdptr)
28002+ memcpy(rq->cmd, cmdptr, cmdlen);
28003+
28004 if (in_len && copy_from_user(buffer, sic->data + cmdlen, in_len))
28005 goto error;
28006
28007diff --git a/crypto/cryptd.c b/crypto/cryptd.c
28008index 7bdd61b..afec999 100644
28009--- a/crypto/cryptd.c
28010+++ b/crypto/cryptd.c
28011@@ -63,7 +63,7 @@ struct cryptd_blkcipher_ctx {
28012
28013 struct cryptd_blkcipher_request_ctx {
28014 crypto_completion_t complete;
28015-};
28016+} __no_const;
28017
28018 struct cryptd_hash_ctx {
28019 struct crypto_shash *child;
28020@@ -80,7 +80,7 @@ struct cryptd_aead_ctx {
28021
28022 struct cryptd_aead_request_ctx {
28023 crypto_completion_t complete;
28024-};
28025+} __no_const;
28026
28027 static void cryptd_queue_worker(struct work_struct *work);
28028
28029diff --git a/drivers/acpi/apei/cper.c b/drivers/acpi/apei/cper.c
28030index e6defd8..c26a225 100644
28031--- a/drivers/acpi/apei/cper.c
28032+++ b/drivers/acpi/apei/cper.c
28033@@ -38,12 +38,12 @@
28034 */
28035 u64 cper_next_record_id(void)
28036 {
28037- static atomic64_t seq;
28038+ static atomic64_unchecked_t seq;
28039
28040- if (!atomic64_read(&seq))
28041- atomic64_set(&seq, ((u64)get_seconds()) << 32);
28042+ if (!atomic64_read_unchecked(&seq))
28043+ atomic64_set_unchecked(&seq, ((u64)get_seconds()) << 32);
28044
28045- return atomic64_inc_return(&seq);
28046+ return atomic64_inc_return_unchecked(&seq);
28047 }
28048 EXPORT_SYMBOL_GPL(cper_next_record_id);
28049
28050diff --git a/drivers/acpi/ec_sys.c b/drivers/acpi/ec_sys.c
28051index 7586544..636a2f0 100644
28052--- a/drivers/acpi/ec_sys.c
28053+++ b/drivers/acpi/ec_sys.c
28054@@ -12,6 +12,7 @@
28055 #include <linux/acpi.h>
28056 #include <linux/debugfs.h>
28057 #include <linux/module.h>
28058+#include <linux/uaccess.h>
28059 #include "internal.h"
28060
28061 MODULE_AUTHOR("Thomas Renninger <trenn@suse.de>");
28062@@ -34,7 +35,7 @@ static ssize_t acpi_ec_read_io(struct file *f, char __user *buf,
28063 * struct acpi_ec *ec = ((struct seq_file *)f->private_data)->private;
28064 */
28065 unsigned int size = EC_SPACE_SIZE;
28066- u8 *data = (u8 *) buf;
28067+ u8 data;
28068 loff_t init_off = *off;
28069 int err = 0;
28070
28071@@ -47,9 +48,11 @@ static ssize_t acpi_ec_read_io(struct file *f, char __user *buf,
28072 size = count;
28073
28074 while (size) {
28075- err = ec_read(*off, &data[*off - init_off]);
28076+ err = ec_read(*off, &data);
28077 if (err)
28078 return err;
28079+ if (put_user(data, &buf[*off - init_off]))
28080+ return -EFAULT;
28081 *off += 1;
28082 size--;
28083 }
28084@@ -65,7 +68,6 @@ static ssize_t acpi_ec_write_io(struct file *f, const char __user *buf,
28085
28086 unsigned int size = count;
28087 loff_t init_off = *off;
28088- u8 *data = (u8 *) buf;
28089 int err = 0;
28090
28091 if (*off >= EC_SPACE_SIZE)
28092@@ -76,7 +78,9 @@ static ssize_t acpi_ec_write_io(struct file *f, const char __user *buf,
28093 }
28094
28095 while (size) {
28096- u8 byte_write = data[*off - init_off];
28097+ u8 byte_write;
28098+ if (get_user(byte_write, &buf[*off - init_off]))
28099+ return -EFAULT;
28100 err = ec_write(*off, byte_write);
28101 if (err)
28102 return err;
28103diff --git a/drivers/acpi/proc.c b/drivers/acpi/proc.c
28104index 251c7b62..000462d 100644
28105--- a/drivers/acpi/proc.c
28106+++ b/drivers/acpi/proc.c
28107@@ -343,19 +343,13 @@ acpi_system_write_wakeup_device(struct file *file,
28108 size_t count, loff_t * ppos)
28109 {
28110 struct list_head *node, *next;
28111- char strbuf[5];
28112- char str[5] = "";
28113- unsigned int len = count;
28114+ char strbuf[5] = {0};
28115
28116- if (len > 4)
28117- len = 4;
28118- if (len < 0)
28119+ if (count > 4)
28120+ count = 4;
28121+ if (copy_from_user(strbuf, buffer, count))
28122 return -EFAULT;
28123-
28124- if (copy_from_user(strbuf, buffer, len))
28125- return -EFAULT;
28126- strbuf[len] = '\0';
28127- sscanf(strbuf, "%s", str);
28128+ strbuf[count] = '\0';
28129
28130 mutex_lock(&acpi_device_lock);
28131 list_for_each_safe(node, next, &acpi_wakeup_device_list) {
28132@@ -364,7 +358,7 @@ acpi_system_write_wakeup_device(struct file *file,
28133 if (!dev->wakeup.flags.valid)
28134 continue;
28135
28136- if (!strncmp(dev->pnp.bus_id, str, 4)) {
28137+ if (!strncmp(dev->pnp.bus_id, strbuf, 4)) {
28138 if (device_can_wakeup(&dev->dev)) {
28139 bool enable = !device_may_wakeup(&dev->dev);
28140 device_set_wakeup_enable(&dev->dev, enable);
28141diff --git a/drivers/acpi/processor_driver.c b/drivers/acpi/processor_driver.c
28142index bfc31cb..8213ce1 100644
28143--- a/drivers/acpi/processor_driver.c
28144+++ b/drivers/acpi/processor_driver.c
28145@@ -551,7 +551,7 @@ static int __cpuinit acpi_processor_add(struct acpi_device *device)
28146 return 0;
28147 #endif
28148
28149- BUG_ON((pr->id >= nr_cpu_ids) || (pr->id < 0));
28150+ BUG_ON(pr->id >= nr_cpu_ids);
28151
28152 /*
28153 * Buggy BIOS check
28154diff --git a/drivers/ata/libata-core.c b/drivers/ata/libata-core.c
28155index 8e1039c..ea9cbd4 100644
28156--- a/drivers/ata/libata-core.c
28157+++ b/drivers/ata/libata-core.c
28158@@ -4750,7 +4750,7 @@ void ata_qc_free(struct ata_queued_cmd *qc)
28159 struct ata_port *ap;
28160 unsigned int tag;
28161
28162- WARN_ON_ONCE(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
28163+ BUG_ON(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
28164 ap = qc->ap;
28165
28166 qc->flags = 0;
28167@@ -4766,7 +4766,7 @@ void __ata_qc_complete(struct ata_queued_cmd *qc)
28168 struct ata_port *ap;
28169 struct ata_link *link;
28170
28171- WARN_ON_ONCE(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
28172+ BUG_ON(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
28173 WARN_ON_ONCE(!(qc->flags & ATA_QCFLAG_ACTIVE));
28174 ap = qc->ap;
28175 link = qc->dev->link;
28176@@ -5828,6 +5828,7 @@ static void ata_finalize_port_ops(struct ata_port_operations *ops)
28177 return;
28178
28179 spin_lock(&lock);
28180+ pax_open_kernel();
28181
28182 for (cur = ops->inherits; cur; cur = cur->inherits) {
28183 void **inherit = (void **)cur;
28184@@ -5841,8 +5842,9 @@ static void ata_finalize_port_ops(struct ata_port_operations *ops)
28185 if (IS_ERR(*pp))
28186 *pp = NULL;
28187
28188- ops->inherits = NULL;
28189+ *(struct ata_port_operations **)&ops->inherits = NULL;
28190
28191+ pax_close_kernel();
28192 spin_unlock(&lock);
28193 }
28194
28195diff --git a/drivers/ata/pata_arasan_cf.c b/drivers/ata/pata_arasan_cf.c
28196index bfaa5cb..3ba1cc3 100644
28197--- a/drivers/ata/pata_arasan_cf.c
28198+++ b/drivers/ata/pata_arasan_cf.c
28199@@ -854,7 +854,9 @@ static int __devinit arasan_cf_probe(struct platform_device *pdev)
28200 /* Handle platform specific quirks */
28201 if (pdata->quirk) {
28202 if (pdata->quirk & CF_BROKEN_PIO) {
28203- ap->ops->set_piomode = NULL;
28204+ pax_open_kernel();
28205+ *(void **)&ap->ops->set_piomode = NULL;
28206+ pax_close_kernel();
28207 ap->pio_mask = 0;
28208 }
28209 if (pdata->quirk & CF_BROKEN_MWDMA)
28210diff --git a/drivers/atm/adummy.c b/drivers/atm/adummy.c
28211index f9b983a..887b9d8 100644
28212--- a/drivers/atm/adummy.c
28213+++ b/drivers/atm/adummy.c
28214@@ -114,7 +114,7 @@ adummy_send(struct atm_vcc *vcc, struct sk_buff *skb)
28215 vcc->pop(vcc, skb);
28216 else
28217 dev_kfree_skb_any(skb);
28218- atomic_inc(&vcc->stats->tx);
28219+ atomic_inc_unchecked(&vcc->stats->tx);
28220
28221 return 0;
28222 }
28223diff --git a/drivers/atm/ambassador.c b/drivers/atm/ambassador.c
28224index 89b30f3..7964211 100644
28225--- a/drivers/atm/ambassador.c
28226+++ b/drivers/atm/ambassador.c
28227@@ -454,7 +454,7 @@ static void tx_complete (amb_dev * dev, tx_out * tx) {
28228 PRINTD (DBG_FLOW|DBG_TX, "tx_complete %p %p", dev, tx);
28229
28230 // VC layer stats
28231- atomic_inc(&ATM_SKB(skb)->vcc->stats->tx);
28232+ atomic_inc_unchecked(&ATM_SKB(skb)->vcc->stats->tx);
28233
28234 // free the descriptor
28235 kfree (tx_descr);
28236@@ -495,7 +495,7 @@ static void rx_complete (amb_dev * dev, rx_out * rx) {
28237 dump_skb ("<<<", vc, skb);
28238
28239 // VC layer stats
28240- atomic_inc(&atm_vcc->stats->rx);
28241+ atomic_inc_unchecked(&atm_vcc->stats->rx);
28242 __net_timestamp(skb);
28243 // end of our responsibility
28244 atm_vcc->push (atm_vcc, skb);
28245@@ -510,7 +510,7 @@ static void rx_complete (amb_dev * dev, rx_out * rx) {
28246 } else {
28247 PRINTK (KERN_INFO, "dropped over-size frame");
28248 // should we count this?
28249- atomic_inc(&atm_vcc->stats->rx_drop);
28250+ atomic_inc_unchecked(&atm_vcc->stats->rx_drop);
28251 }
28252
28253 } else {
28254@@ -1338,7 +1338,7 @@ static int amb_send (struct atm_vcc * atm_vcc, struct sk_buff * skb) {
28255 }
28256
28257 if (check_area (skb->data, skb->len)) {
28258- atomic_inc(&atm_vcc->stats->tx_err);
28259+ atomic_inc_unchecked(&atm_vcc->stats->tx_err);
28260 return -ENOMEM; // ?
28261 }
28262
28263diff --git a/drivers/atm/atmtcp.c b/drivers/atm/atmtcp.c
28264index b22d71c..d6e1049 100644
28265--- a/drivers/atm/atmtcp.c
28266+++ b/drivers/atm/atmtcp.c
28267@@ -207,7 +207,7 @@ static int atmtcp_v_send(struct atm_vcc *vcc,struct sk_buff *skb)
28268 if (vcc->pop) vcc->pop(vcc,skb);
28269 else dev_kfree_skb(skb);
28270 if (dev_data) return 0;
28271- atomic_inc(&vcc->stats->tx_err);
28272+ atomic_inc_unchecked(&vcc->stats->tx_err);
28273 return -ENOLINK;
28274 }
28275 size = skb->len+sizeof(struct atmtcp_hdr);
28276@@ -215,7 +215,7 @@ static int atmtcp_v_send(struct atm_vcc *vcc,struct sk_buff *skb)
28277 if (!new_skb) {
28278 if (vcc->pop) vcc->pop(vcc,skb);
28279 else dev_kfree_skb(skb);
28280- atomic_inc(&vcc->stats->tx_err);
28281+ atomic_inc_unchecked(&vcc->stats->tx_err);
28282 return -ENOBUFS;
28283 }
28284 hdr = (void *) skb_put(new_skb,sizeof(struct atmtcp_hdr));
28285@@ -226,8 +226,8 @@ static int atmtcp_v_send(struct atm_vcc *vcc,struct sk_buff *skb)
28286 if (vcc->pop) vcc->pop(vcc,skb);
28287 else dev_kfree_skb(skb);
28288 out_vcc->push(out_vcc,new_skb);
28289- atomic_inc(&vcc->stats->tx);
28290- atomic_inc(&out_vcc->stats->rx);
28291+ atomic_inc_unchecked(&vcc->stats->tx);
28292+ atomic_inc_unchecked(&out_vcc->stats->rx);
28293 return 0;
28294 }
28295
28296@@ -301,7 +301,7 @@ static int atmtcp_c_send(struct atm_vcc *vcc,struct sk_buff *skb)
28297 out_vcc = find_vcc(dev, ntohs(hdr->vpi), ntohs(hdr->vci));
28298 read_unlock(&vcc_sklist_lock);
28299 if (!out_vcc) {
28300- atomic_inc(&vcc->stats->tx_err);
28301+ atomic_inc_unchecked(&vcc->stats->tx_err);
28302 goto done;
28303 }
28304 skb_pull(skb,sizeof(struct atmtcp_hdr));
28305@@ -313,8 +313,8 @@ static int atmtcp_c_send(struct atm_vcc *vcc,struct sk_buff *skb)
28306 __net_timestamp(new_skb);
28307 skb_copy_from_linear_data(skb, skb_put(new_skb, skb->len), skb->len);
28308 out_vcc->push(out_vcc,new_skb);
28309- atomic_inc(&vcc->stats->tx);
28310- atomic_inc(&out_vcc->stats->rx);
28311+ atomic_inc_unchecked(&vcc->stats->tx);
28312+ atomic_inc_unchecked(&out_vcc->stats->rx);
28313 done:
28314 if (vcc->pop) vcc->pop(vcc,skb);
28315 else dev_kfree_skb(skb);
28316diff --git a/drivers/atm/eni.c b/drivers/atm/eni.c
28317index 2059ee4..faf51c7 100644
28318--- a/drivers/atm/eni.c
28319+++ b/drivers/atm/eni.c
28320@@ -522,7 +522,7 @@ static int rx_aal0(struct atm_vcc *vcc)
28321 DPRINTK(DEV_LABEL "(itf %d): trashing empty cell\n",
28322 vcc->dev->number);
28323 length = 0;
28324- atomic_inc(&vcc->stats->rx_err);
28325+ atomic_inc_unchecked(&vcc->stats->rx_err);
28326 }
28327 else {
28328 length = ATM_CELL_SIZE-1; /* no HEC */
28329@@ -577,7 +577,7 @@ static int rx_aal5(struct atm_vcc *vcc)
28330 size);
28331 }
28332 eff = length = 0;
28333- atomic_inc(&vcc->stats->rx_err);
28334+ atomic_inc_unchecked(&vcc->stats->rx_err);
28335 }
28336 else {
28337 size = (descr & MID_RED_COUNT)*(ATM_CELL_PAYLOAD >> 2);
28338@@ -594,7 +594,7 @@ static int rx_aal5(struct atm_vcc *vcc)
28339 "(VCI=%d,length=%ld,size=%ld (descr 0x%lx))\n",
28340 vcc->dev->number,vcc->vci,length,size << 2,descr);
28341 length = eff = 0;
28342- atomic_inc(&vcc->stats->rx_err);
28343+ atomic_inc_unchecked(&vcc->stats->rx_err);
28344 }
28345 }
28346 skb = eff ? atm_alloc_charge(vcc,eff << 2,GFP_ATOMIC) : NULL;
28347@@ -767,7 +767,7 @@ rx_dequeued++;
28348 vcc->push(vcc,skb);
28349 pushed++;
28350 }
28351- atomic_inc(&vcc->stats->rx);
28352+ atomic_inc_unchecked(&vcc->stats->rx);
28353 }
28354 wake_up(&eni_dev->rx_wait);
28355 }
28356@@ -1227,7 +1227,7 @@ static void dequeue_tx(struct atm_dev *dev)
28357 PCI_DMA_TODEVICE);
28358 if (vcc->pop) vcc->pop(vcc,skb);
28359 else dev_kfree_skb_irq(skb);
28360- atomic_inc(&vcc->stats->tx);
28361+ atomic_inc_unchecked(&vcc->stats->tx);
28362 wake_up(&eni_dev->tx_wait);
28363 dma_complete++;
28364 }
28365@@ -1567,7 +1567,7 @@ tx_complete++;
28366 /*--------------------------------- entries ---------------------------------*/
28367
28368
28369-static const char *media_name[] __devinitdata = {
28370+static const char *media_name[] __devinitconst = {
28371 "MMF", "SMF", "MMF", "03?", /* 0- 3 */
28372 "UTP", "05?", "06?", "07?", /* 4- 7 */
28373 "TAXI","09?", "10?", "11?", /* 8-11 */
28374diff --git a/drivers/atm/firestream.c b/drivers/atm/firestream.c
28375index 86fed1b..6dc4721 100644
28376--- a/drivers/atm/firestream.c
28377+++ b/drivers/atm/firestream.c
28378@@ -749,7 +749,7 @@ static void process_txdone_queue (struct fs_dev *dev, struct queue *q)
28379 }
28380 }
28381
28382- atomic_inc(&ATM_SKB(skb)->vcc->stats->tx);
28383+ atomic_inc_unchecked(&ATM_SKB(skb)->vcc->stats->tx);
28384
28385 fs_dprintk (FS_DEBUG_TXMEM, "i");
28386 fs_dprintk (FS_DEBUG_ALLOC, "Free t-skb: %p\n", skb);
28387@@ -816,7 +816,7 @@ static void process_incoming (struct fs_dev *dev, struct queue *q)
28388 #endif
28389 skb_put (skb, qe->p1 & 0xffff);
28390 ATM_SKB(skb)->vcc = atm_vcc;
28391- atomic_inc(&atm_vcc->stats->rx);
28392+ atomic_inc_unchecked(&atm_vcc->stats->rx);
28393 __net_timestamp(skb);
28394 fs_dprintk (FS_DEBUG_ALLOC, "Free rec-skb: %p (pushed)\n", skb);
28395 atm_vcc->push (atm_vcc, skb);
28396@@ -837,12 +837,12 @@ static void process_incoming (struct fs_dev *dev, struct queue *q)
28397 kfree (pe);
28398 }
28399 if (atm_vcc)
28400- atomic_inc(&atm_vcc->stats->rx_drop);
28401+ atomic_inc_unchecked(&atm_vcc->stats->rx_drop);
28402 break;
28403 case 0x1f: /* Reassembly abort: no buffers. */
28404 /* Silently increment error counter. */
28405 if (atm_vcc)
28406- atomic_inc(&atm_vcc->stats->rx_drop);
28407+ atomic_inc_unchecked(&atm_vcc->stats->rx_drop);
28408 break;
28409 default: /* Hmm. Haven't written the code to handle the others yet... -- REW */
28410 printk (KERN_WARNING "Don't know what to do with RX status %x: %s.\n",
28411diff --git a/drivers/atm/fore200e.c b/drivers/atm/fore200e.c
28412index 361f5ae..7fc552d 100644
28413--- a/drivers/atm/fore200e.c
28414+++ b/drivers/atm/fore200e.c
28415@@ -933,9 +933,9 @@ fore200e_tx_irq(struct fore200e* fore200e)
28416 #endif
28417 /* check error condition */
28418 if (*entry->status & STATUS_ERROR)
28419- atomic_inc(&vcc->stats->tx_err);
28420+ atomic_inc_unchecked(&vcc->stats->tx_err);
28421 else
28422- atomic_inc(&vcc->stats->tx);
28423+ atomic_inc_unchecked(&vcc->stats->tx);
28424 }
28425 }
28426
28427@@ -1084,7 +1084,7 @@ fore200e_push_rpd(struct fore200e* fore200e, struct atm_vcc* vcc, struct rpd* rp
28428 if (skb == NULL) {
28429 DPRINTK(2, "unable to alloc new skb, rx PDU length = %d\n", pdu_len);
28430
28431- atomic_inc(&vcc->stats->rx_drop);
28432+ atomic_inc_unchecked(&vcc->stats->rx_drop);
28433 return -ENOMEM;
28434 }
28435
28436@@ -1127,14 +1127,14 @@ fore200e_push_rpd(struct fore200e* fore200e, struct atm_vcc* vcc, struct rpd* rp
28437
28438 dev_kfree_skb_any(skb);
28439
28440- atomic_inc(&vcc->stats->rx_drop);
28441+ atomic_inc_unchecked(&vcc->stats->rx_drop);
28442 return -ENOMEM;
28443 }
28444
28445 ASSERT(atomic_read(&sk_atm(vcc)->sk_wmem_alloc) >= 0);
28446
28447 vcc->push(vcc, skb);
28448- atomic_inc(&vcc->stats->rx);
28449+ atomic_inc_unchecked(&vcc->stats->rx);
28450
28451 ASSERT(atomic_read(&sk_atm(vcc)->sk_wmem_alloc) >= 0);
28452
28453@@ -1212,7 +1212,7 @@ fore200e_rx_irq(struct fore200e* fore200e)
28454 DPRINTK(2, "damaged PDU on %d.%d.%d\n",
28455 fore200e->atm_dev->number,
28456 entry->rpd->atm_header.vpi, entry->rpd->atm_header.vci);
28457- atomic_inc(&vcc->stats->rx_err);
28458+ atomic_inc_unchecked(&vcc->stats->rx_err);
28459 }
28460 }
28461
28462@@ -1657,7 +1657,7 @@ fore200e_send(struct atm_vcc *vcc, struct sk_buff *skb)
28463 goto retry_here;
28464 }
28465
28466- atomic_inc(&vcc->stats->tx_err);
28467+ atomic_inc_unchecked(&vcc->stats->tx_err);
28468
28469 fore200e->tx_sat++;
28470 DPRINTK(2, "tx queue of device %s is saturated, PDU dropped - heartbeat is %08x\n",
28471diff --git a/drivers/atm/he.c b/drivers/atm/he.c
28472index b182c2f..1c6fa8a 100644
28473--- a/drivers/atm/he.c
28474+++ b/drivers/atm/he.c
28475@@ -1709,7 +1709,7 @@ he_service_rbrq(struct he_dev *he_dev, int group)
28476
28477 if (RBRQ_HBUF_ERR(he_dev->rbrq_head)) {
28478 hprintk("HBUF_ERR! (cid 0x%x)\n", cid);
28479- atomic_inc(&vcc->stats->rx_drop);
28480+ atomic_inc_unchecked(&vcc->stats->rx_drop);
28481 goto return_host_buffers;
28482 }
28483
28484@@ -1736,7 +1736,7 @@ he_service_rbrq(struct he_dev *he_dev, int group)
28485 RBRQ_LEN_ERR(he_dev->rbrq_head)
28486 ? "LEN_ERR" : "",
28487 vcc->vpi, vcc->vci);
28488- atomic_inc(&vcc->stats->rx_err);
28489+ atomic_inc_unchecked(&vcc->stats->rx_err);
28490 goto return_host_buffers;
28491 }
28492
28493@@ -1788,7 +1788,7 @@ he_service_rbrq(struct he_dev *he_dev, int group)
28494 vcc->push(vcc, skb);
28495 spin_lock(&he_dev->global_lock);
28496
28497- atomic_inc(&vcc->stats->rx);
28498+ atomic_inc_unchecked(&vcc->stats->rx);
28499
28500 return_host_buffers:
28501 ++pdus_assembled;
28502@@ -2114,7 +2114,7 @@ __enqueue_tpd(struct he_dev *he_dev, struct he_tpd *tpd, unsigned cid)
28503 tpd->vcc->pop(tpd->vcc, tpd->skb);
28504 else
28505 dev_kfree_skb_any(tpd->skb);
28506- atomic_inc(&tpd->vcc->stats->tx_err);
28507+ atomic_inc_unchecked(&tpd->vcc->stats->tx_err);
28508 }
28509 pci_pool_free(he_dev->tpd_pool, tpd, TPD_ADDR(tpd->status));
28510 return;
28511@@ -2526,7 +2526,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
28512 vcc->pop(vcc, skb);
28513 else
28514 dev_kfree_skb_any(skb);
28515- atomic_inc(&vcc->stats->tx_err);
28516+ atomic_inc_unchecked(&vcc->stats->tx_err);
28517 return -EINVAL;
28518 }
28519
28520@@ -2537,7 +2537,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
28521 vcc->pop(vcc, skb);
28522 else
28523 dev_kfree_skb_any(skb);
28524- atomic_inc(&vcc->stats->tx_err);
28525+ atomic_inc_unchecked(&vcc->stats->tx_err);
28526 return -EINVAL;
28527 }
28528 #endif
28529@@ -2549,7 +2549,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
28530 vcc->pop(vcc, skb);
28531 else
28532 dev_kfree_skb_any(skb);
28533- atomic_inc(&vcc->stats->tx_err);
28534+ atomic_inc_unchecked(&vcc->stats->tx_err);
28535 spin_unlock_irqrestore(&he_dev->global_lock, flags);
28536 return -ENOMEM;
28537 }
28538@@ -2591,7 +2591,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
28539 vcc->pop(vcc, skb);
28540 else
28541 dev_kfree_skb_any(skb);
28542- atomic_inc(&vcc->stats->tx_err);
28543+ atomic_inc_unchecked(&vcc->stats->tx_err);
28544 spin_unlock_irqrestore(&he_dev->global_lock, flags);
28545 return -ENOMEM;
28546 }
28547@@ -2622,7 +2622,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
28548 __enqueue_tpd(he_dev, tpd, cid);
28549 spin_unlock_irqrestore(&he_dev->global_lock, flags);
28550
28551- atomic_inc(&vcc->stats->tx);
28552+ atomic_inc_unchecked(&vcc->stats->tx);
28553
28554 return 0;
28555 }
28556diff --git a/drivers/atm/horizon.c b/drivers/atm/horizon.c
28557index 7d01c2a..4e3ac01 100644
28558--- a/drivers/atm/horizon.c
28559+++ b/drivers/atm/horizon.c
28560@@ -1034,7 +1034,7 @@ static void rx_schedule (hrz_dev * dev, int irq) {
28561 {
28562 struct atm_vcc * vcc = ATM_SKB(skb)->vcc;
28563 // VC layer stats
28564- atomic_inc(&vcc->stats->rx);
28565+ atomic_inc_unchecked(&vcc->stats->rx);
28566 __net_timestamp(skb);
28567 // end of our responsibility
28568 vcc->push (vcc, skb);
28569@@ -1186,7 +1186,7 @@ static void tx_schedule (hrz_dev * const dev, int irq) {
28570 dev->tx_iovec = NULL;
28571
28572 // VC layer stats
28573- atomic_inc(&ATM_SKB(skb)->vcc->stats->tx);
28574+ atomic_inc_unchecked(&ATM_SKB(skb)->vcc->stats->tx);
28575
28576 // free the skb
28577 hrz_kfree_skb (skb);
28578diff --git a/drivers/atm/idt77252.c b/drivers/atm/idt77252.c
28579index 8974bd2..b856f85 100644
28580--- a/drivers/atm/idt77252.c
28581+++ b/drivers/atm/idt77252.c
28582@@ -812,7 +812,7 @@ drain_scq(struct idt77252_dev *card, struct vc_map *vc)
28583 else
28584 dev_kfree_skb(skb);
28585
28586- atomic_inc(&vcc->stats->tx);
28587+ atomic_inc_unchecked(&vcc->stats->tx);
28588 }
28589
28590 atomic_dec(&scq->used);
28591@@ -1075,13 +1075,13 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
28592 if ((sb = dev_alloc_skb(64)) == NULL) {
28593 printk("%s: Can't allocate buffers for aal0.\n",
28594 card->name);
28595- atomic_add(i, &vcc->stats->rx_drop);
28596+ atomic_add_unchecked(i, &vcc->stats->rx_drop);
28597 break;
28598 }
28599 if (!atm_charge(vcc, sb->truesize)) {
28600 RXPRINTK("%s: atm_charge() dropped aal0 packets.\n",
28601 card->name);
28602- atomic_add(i - 1, &vcc->stats->rx_drop);
28603+ atomic_add_unchecked(i - 1, &vcc->stats->rx_drop);
28604 dev_kfree_skb(sb);
28605 break;
28606 }
28607@@ -1098,7 +1098,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
28608 ATM_SKB(sb)->vcc = vcc;
28609 __net_timestamp(sb);
28610 vcc->push(vcc, sb);
28611- atomic_inc(&vcc->stats->rx);
28612+ atomic_inc_unchecked(&vcc->stats->rx);
28613
28614 cell += ATM_CELL_PAYLOAD;
28615 }
28616@@ -1135,13 +1135,13 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
28617 "(CDC: %08x)\n",
28618 card->name, len, rpp->len, readl(SAR_REG_CDC));
28619 recycle_rx_pool_skb(card, rpp);
28620- atomic_inc(&vcc->stats->rx_err);
28621+ atomic_inc_unchecked(&vcc->stats->rx_err);
28622 return;
28623 }
28624 if (stat & SAR_RSQE_CRC) {
28625 RXPRINTK("%s: AAL5 CRC error.\n", card->name);
28626 recycle_rx_pool_skb(card, rpp);
28627- atomic_inc(&vcc->stats->rx_err);
28628+ atomic_inc_unchecked(&vcc->stats->rx_err);
28629 return;
28630 }
28631 if (skb_queue_len(&rpp->queue) > 1) {
28632@@ -1152,7 +1152,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
28633 RXPRINTK("%s: Can't alloc RX skb.\n",
28634 card->name);
28635 recycle_rx_pool_skb(card, rpp);
28636- atomic_inc(&vcc->stats->rx_err);
28637+ atomic_inc_unchecked(&vcc->stats->rx_err);
28638 return;
28639 }
28640 if (!atm_charge(vcc, skb->truesize)) {
28641@@ -1171,7 +1171,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
28642 __net_timestamp(skb);
28643
28644 vcc->push(vcc, skb);
28645- atomic_inc(&vcc->stats->rx);
28646+ atomic_inc_unchecked(&vcc->stats->rx);
28647
28648 return;
28649 }
28650@@ -1193,7 +1193,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
28651 __net_timestamp(skb);
28652
28653 vcc->push(vcc, skb);
28654- atomic_inc(&vcc->stats->rx);
28655+ atomic_inc_unchecked(&vcc->stats->rx);
28656
28657 if (skb->truesize > SAR_FB_SIZE_3)
28658 add_rx_skb(card, 3, SAR_FB_SIZE_3, 1);
28659@@ -1304,14 +1304,14 @@ idt77252_rx_raw(struct idt77252_dev *card)
28660 if (vcc->qos.aal != ATM_AAL0) {
28661 RPRINTK("%s: raw cell for non AAL0 vc %u.%u\n",
28662 card->name, vpi, vci);
28663- atomic_inc(&vcc->stats->rx_drop);
28664+ atomic_inc_unchecked(&vcc->stats->rx_drop);
28665 goto drop;
28666 }
28667
28668 if ((sb = dev_alloc_skb(64)) == NULL) {
28669 printk("%s: Can't allocate buffers for AAL0.\n",
28670 card->name);
28671- atomic_inc(&vcc->stats->rx_err);
28672+ atomic_inc_unchecked(&vcc->stats->rx_err);
28673 goto drop;
28674 }
28675
28676@@ -1330,7 +1330,7 @@ idt77252_rx_raw(struct idt77252_dev *card)
28677 ATM_SKB(sb)->vcc = vcc;
28678 __net_timestamp(sb);
28679 vcc->push(vcc, sb);
28680- atomic_inc(&vcc->stats->rx);
28681+ atomic_inc_unchecked(&vcc->stats->rx);
28682
28683 drop:
28684 skb_pull(queue, 64);
28685@@ -1955,13 +1955,13 @@ idt77252_send_skb(struct atm_vcc *vcc, struct sk_buff *skb, int oam)
28686
28687 if (vc == NULL) {
28688 printk("%s: NULL connection in send().\n", card->name);
28689- atomic_inc(&vcc->stats->tx_err);
28690+ atomic_inc_unchecked(&vcc->stats->tx_err);
28691 dev_kfree_skb(skb);
28692 return -EINVAL;
28693 }
28694 if (!test_bit(VCF_TX, &vc->flags)) {
28695 printk("%s: Trying to transmit on a non-tx VC.\n", card->name);
28696- atomic_inc(&vcc->stats->tx_err);
28697+ atomic_inc_unchecked(&vcc->stats->tx_err);
28698 dev_kfree_skb(skb);
28699 return -EINVAL;
28700 }
28701@@ -1973,14 +1973,14 @@ idt77252_send_skb(struct atm_vcc *vcc, struct sk_buff *skb, int oam)
28702 break;
28703 default:
28704 printk("%s: Unsupported AAL: %d\n", card->name, vcc->qos.aal);
28705- atomic_inc(&vcc->stats->tx_err);
28706+ atomic_inc_unchecked(&vcc->stats->tx_err);
28707 dev_kfree_skb(skb);
28708 return -EINVAL;
28709 }
28710
28711 if (skb_shinfo(skb)->nr_frags != 0) {
28712 printk("%s: No scatter-gather yet.\n", card->name);
28713- atomic_inc(&vcc->stats->tx_err);
28714+ atomic_inc_unchecked(&vcc->stats->tx_err);
28715 dev_kfree_skb(skb);
28716 return -EINVAL;
28717 }
28718@@ -1988,7 +1988,7 @@ idt77252_send_skb(struct atm_vcc *vcc, struct sk_buff *skb, int oam)
28719
28720 err = queue_skb(card, vc, skb, oam);
28721 if (err) {
28722- atomic_inc(&vcc->stats->tx_err);
28723+ atomic_inc_unchecked(&vcc->stats->tx_err);
28724 dev_kfree_skb(skb);
28725 return err;
28726 }
28727@@ -2011,7 +2011,7 @@ idt77252_send_oam(struct atm_vcc *vcc, void *cell, int flags)
28728 skb = dev_alloc_skb(64);
28729 if (!skb) {
28730 printk("%s: Out of memory in send_oam().\n", card->name);
28731- atomic_inc(&vcc->stats->tx_err);
28732+ atomic_inc_unchecked(&vcc->stats->tx_err);
28733 return -ENOMEM;
28734 }
28735 atomic_add(skb->truesize, &sk_atm(vcc)->sk_wmem_alloc);
28736diff --git a/drivers/atm/iphase.c b/drivers/atm/iphase.c
28737index 96cce6d..62c3ec5 100644
28738--- a/drivers/atm/iphase.c
28739+++ b/drivers/atm/iphase.c
28740@@ -1145,7 +1145,7 @@ static int rx_pkt(struct atm_dev *dev)
28741 status = (u_short) (buf_desc_ptr->desc_mode);
28742 if (status & (RX_CER | RX_PTE | RX_OFL))
28743 {
28744- atomic_inc(&vcc->stats->rx_err);
28745+ atomic_inc_unchecked(&vcc->stats->rx_err);
28746 IF_ERR(printk("IA: bad packet, dropping it");)
28747 if (status & RX_CER) {
28748 IF_ERR(printk(" cause: packet CRC error\n");)
28749@@ -1168,7 +1168,7 @@ static int rx_pkt(struct atm_dev *dev)
28750 len = dma_addr - buf_addr;
28751 if (len > iadev->rx_buf_sz) {
28752 printk("Over %d bytes sdu received, dropped!!!\n", iadev->rx_buf_sz);
28753- atomic_inc(&vcc->stats->rx_err);
28754+ atomic_inc_unchecked(&vcc->stats->rx_err);
28755 goto out_free_desc;
28756 }
28757
28758@@ -1318,7 +1318,7 @@ static void rx_dle_intr(struct atm_dev *dev)
28759 ia_vcc = INPH_IA_VCC(vcc);
28760 if (ia_vcc == NULL)
28761 {
28762- atomic_inc(&vcc->stats->rx_err);
28763+ atomic_inc_unchecked(&vcc->stats->rx_err);
28764 atm_return(vcc, skb->truesize);
28765 dev_kfree_skb_any(skb);
28766 goto INCR_DLE;
28767@@ -1330,7 +1330,7 @@ static void rx_dle_intr(struct atm_dev *dev)
28768 if ((length > iadev->rx_buf_sz) || (length >
28769 (skb->len - sizeof(struct cpcs_trailer))))
28770 {
28771- atomic_inc(&vcc->stats->rx_err);
28772+ atomic_inc_unchecked(&vcc->stats->rx_err);
28773 IF_ERR(printk("rx_dle_intr: Bad AAL5 trailer %d (skb len %d)",
28774 length, skb->len);)
28775 atm_return(vcc, skb->truesize);
28776@@ -1346,7 +1346,7 @@ static void rx_dle_intr(struct atm_dev *dev)
28777
28778 IF_RX(printk("rx_dle_intr: skb push");)
28779 vcc->push(vcc,skb);
28780- atomic_inc(&vcc->stats->rx);
28781+ atomic_inc_unchecked(&vcc->stats->rx);
28782 iadev->rx_pkt_cnt++;
28783 }
28784 INCR_DLE:
28785@@ -2826,15 +2826,15 @@ static int ia_ioctl(struct atm_dev *dev, unsigned int cmd, void __user *arg)
28786 {
28787 struct k_sonet_stats *stats;
28788 stats = &PRIV(_ia_dev[board])->sonet_stats;
28789- printk("section_bip: %d\n", atomic_read(&stats->section_bip));
28790- printk("line_bip : %d\n", atomic_read(&stats->line_bip));
28791- printk("path_bip : %d\n", atomic_read(&stats->path_bip));
28792- printk("line_febe : %d\n", atomic_read(&stats->line_febe));
28793- printk("path_febe : %d\n", atomic_read(&stats->path_febe));
28794- printk("corr_hcs : %d\n", atomic_read(&stats->corr_hcs));
28795- printk("uncorr_hcs : %d\n", atomic_read(&stats->uncorr_hcs));
28796- printk("tx_cells : %d\n", atomic_read(&stats->tx_cells));
28797- printk("rx_cells : %d\n", atomic_read(&stats->rx_cells));
28798+ printk("section_bip: %d\n", atomic_read_unchecked(&stats->section_bip));
28799+ printk("line_bip : %d\n", atomic_read_unchecked(&stats->line_bip));
28800+ printk("path_bip : %d\n", atomic_read_unchecked(&stats->path_bip));
28801+ printk("line_febe : %d\n", atomic_read_unchecked(&stats->line_febe));
28802+ printk("path_febe : %d\n", atomic_read_unchecked(&stats->path_febe));
28803+ printk("corr_hcs : %d\n", atomic_read_unchecked(&stats->corr_hcs));
28804+ printk("uncorr_hcs : %d\n", atomic_read_unchecked(&stats->uncorr_hcs));
28805+ printk("tx_cells : %d\n", atomic_read_unchecked(&stats->tx_cells));
28806+ printk("rx_cells : %d\n", atomic_read_unchecked(&stats->rx_cells));
28807 }
28808 ia_cmds.status = 0;
28809 break;
28810@@ -2939,7 +2939,7 @@ static int ia_pkt_tx (struct atm_vcc *vcc, struct sk_buff *skb) {
28811 if ((desc == 0) || (desc > iadev->num_tx_desc))
28812 {
28813 IF_ERR(printk(DEV_LABEL "invalid desc for send: %d\n", desc);)
28814- atomic_inc(&vcc->stats->tx);
28815+ atomic_inc_unchecked(&vcc->stats->tx);
28816 if (vcc->pop)
28817 vcc->pop(vcc, skb);
28818 else
28819@@ -3044,14 +3044,14 @@ static int ia_pkt_tx (struct atm_vcc *vcc, struct sk_buff *skb) {
28820 ATM_DESC(skb) = vcc->vci;
28821 skb_queue_tail(&iadev->tx_dma_q, skb);
28822
28823- atomic_inc(&vcc->stats->tx);
28824+ atomic_inc_unchecked(&vcc->stats->tx);
28825 iadev->tx_pkt_cnt++;
28826 /* Increment transaction counter */
28827 writel(2, iadev->dma+IPHASE5575_TX_COUNTER);
28828
28829 #if 0
28830 /* add flow control logic */
28831- if (atomic_read(&vcc->stats->tx) % 20 == 0) {
28832+ if (atomic_read_unchecked(&vcc->stats->tx) % 20 == 0) {
28833 if (iavcc->vc_desc_cnt > 10) {
28834 vcc->tx_quota = vcc->tx_quota * 3 / 4;
28835 printk("Tx1: vcc->tx_quota = %d \n", (u32)vcc->tx_quota );
28836diff --git a/drivers/atm/lanai.c b/drivers/atm/lanai.c
28837index 68c7588..7036683 100644
28838--- a/drivers/atm/lanai.c
28839+++ b/drivers/atm/lanai.c
28840@@ -1303,7 +1303,7 @@ static void lanai_send_one_aal5(struct lanai_dev *lanai,
28841 vcc_tx_add_aal5_trailer(lvcc, skb->len, 0, 0);
28842 lanai_endtx(lanai, lvcc);
28843 lanai_free_skb(lvcc->tx.atmvcc, skb);
28844- atomic_inc(&lvcc->tx.atmvcc->stats->tx);
28845+ atomic_inc_unchecked(&lvcc->tx.atmvcc->stats->tx);
28846 }
28847
28848 /* Try to fill the buffer - don't call unless there is backlog */
28849@@ -1426,7 +1426,7 @@ static void vcc_rx_aal5(struct lanai_vcc *lvcc, int endptr)
28850 ATM_SKB(skb)->vcc = lvcc->rx.atmvcc;
28851 __net_timestamp(skb);
28852 lvcc->rx.atmvcc->push(lvcc->rx.atmvcc, skb);
28853- atomic_inc(&lvcc->rx.atmvcc->stats->rx);
28854+ atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx);
28855 out:
28856 lvcc->rx.buf.ptr = end;
28857 cardvcc_write(lvcc, endptr, vcc_rxreadptr);
28858@@ -1667,7 +1667,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
28859 DPRINTK("(itf %d) got RX service entry 0x%X for non-AAL5 "
28860 "vcc %d\n", lanai->number, (unsigned int) s, vci);
28861 lanai->stats.service_rxnotaal5++;
28862- atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
28863+ atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
28864 return 0;
28865 }
28866 if (likely(!(s & (SERVICE_TRASH | SERVICE_STREAM | SERVICE_CRCERR)))) {
28867@@ -1679,7 +1679,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
28868 int bytes;
28869 read_unlock(&vcc_sklist_lock);
28870 DPRINTK("got trashed rx pdu on vci %d\n", vci);
28871- atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
28872+ atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
28873 lvcc->stats.x.aal5.service_trash++;
28874 bytes = (SERVICE_GET_END(s) * 16) -
28875 (((unsigned long) lvcc->rx.buf.ptr) -
28876@@ -1691,7 +1691,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
28877 }
28878 if (s & SERVICE_STREAM) {
28879 read_unlock(&vcc_sklist_lock);
28880- atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
28881+ atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
28882 lvcc->stats.x.aal5.service_stream++;
28883 printk(KERN_ERR DEV_LABEL "(itf %d): Got AAL5 stream "
28884 "PDU on VCI %d!\n", lanai->number, vci);
28885@@ -1699,7 +1699,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
28886 return 0;
28887 }
28888 DPRINTK("got rx crc error on vci %d\n", vci);
28889- atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
28890+ atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
28891 lvcc->stats.x.aal5.service_rxcrc++;
28892 lvcc->rx.buf.ptr = &lvcc->rx.buf.start[SERVICE_GET_END(s) * 4];
28893 cardvcc_write(lvcc, SERVICE_GET_END(s), vcc_rxreadptr);
28894diff --git a/drivers/atm/nicstar.c b/drivers/atm/nicstar.c
28895index 1c70c45..300718d 100644
28896--- a/drivers/atm/nicstar.c
28897+++ b/drivers/atm/nicstar.c
28898@@ -1654,7 +1654,7 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
28899 if ((vc = (vc_map *) vcc->dev_data) == NULL) {
28900 printk("nicstar%d: vcc->dev_data == NULL on ns_send().\n",
28901 card->index);
28902- atomic_inc(&vcc->stats->tx_err);
28903+ atomic_inc_unchecked(&vcc->stats->tx_err);
28904 dev_kfree_skb_any(skb);
28905 return -EINVAL;
28906 }
28907@@ -1662,7 +1662,7 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
28908 if (!vc->tx) {
28909 printk("nicstar%d: Trying to transmit on a non-tx VC.\n",
28910 card->index);
28911- atomic_inc(&vcc->stats->tx_err);
28912+ atomic_inc_unchecked(&vcc->stats->tx_err);
28913 dev_kfree_skb_any(skb);
28914 return -EINVAL;
28915 }
28916@@ -1670,14 +1670,14 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
28917 if (vcc->qos.aal != ATM_AAL5 && vcc->qos.aal != ATM_AAL0) {
28918 printk("nicstar%d: Only AAL0 and AAL5 are supported.\n",
28919 card->index);
28920- atomic_inc(&vcc->stats->tx_err);
28921+ atomic_inc_unchecked(&vcc->stats->tx_err);
28922 dev_kfree_skb_any(skb);
28923 return -EINVAL;
28924 }
28925
28926 if (skb_shinfo(skb)->nr_frags != 0) {
28927 printk("nicstar%d: No scatter-gather yet.\n", card->index);
28928- atomic_inc(&vcc->stats->tx_err);
28929+ atomic_inc_unchecked(&vcc->stats->tx_err);
28930 dev_kfree_skb_any(skb);
28931 return -EINVAL;
28932 }
28933@@ -1725,11 +1725,11 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
28934 }
28935
28936 if (push_scqe(card, vc, scq, &scqe, skb) != 0) {
28937- atomic_inc(&vcc->stats->tx_err);
28938+ atomic_inc_unchecked(&vcc->stats->tx_err);
28939 dev_kfree_skb_any(skb);
28940 return -EIO;
28941 }
28942- atomic_inc(&vcc->stats->tx);
28943+ atomic_inc_unchecked(&vcc->stats->tx);
28944
28945 return 0;
28946 }
28947@@ -2046,14 +2046,14 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28948 printk
28949 ("nicstar%d: Can't allocate buffers for aal0.\n",
28950 card->index);
28951- atomic_add(i, &vcc->stats->rx_drop);
28952+ atomic_add_unchecked(i, &vcc->stats->rx_drop);
28953 break;
28954 }
28955 if (!atm_charge(vcc, sb->truesize)) {
28956 RXPRINTK
28957 ("nicstar%d: atm_charge() dropped aal0 packets.\n",
28958 card->index);
28959- atomic_add(i - 1, &vcc->stats->rx_drop); /* already increased by 1 */
28960+ atomic_add_unchecked(i - 1, &vcc->stats->rx_drop); /* already increased by 1 */
28961 dev_kfree_skb_any(sb);
28962 break;
28963 }
28964@@ -2068,7 +2068,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28965 ATM_SKB(sb)->vcc = vcc;
28966 __net_timestamp(sb);
28967 vcc->push(vcc, sb);
28968- atomic_inc(&vcc->stats->rx);
28969+ atomic_inc_unchecked(&vcc->stats->rx);
28970 cell += ATM_CELL_PAYLOAD;
28971 }
28972
28973@@ -2085,7 +2085,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28974 if (iovb == NULL) {
28975 printk("nicstar%d: Out of iovec buffers.\n",
28976 card->index);
28977- atomic_inc(&vcc->stats->rx_drop);
28978+ atomic_inc_unchecked(&vcc->stats->rx_drop);
28979 recycle_rx_buf(card, skb);
28980 return;
28981 }
28982@@ -2109,7 +2109,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28983 small or large buffer itself. */
28984 } else if (NS_PRV_IOVCNT(iovb) >= NS_MAX_IOVECS) {
28985 printk("nicstar%d: received too big AAL5 SDU.\n", card->index);
28986- atomic_inc(&vcc->stats->rx_err);
28987+ atomic_inc_unchecked(&vcc->stats->rx_err);
28988 recycle_iovec_rx_bufs(card, (struct iovec *)iovb->data,
28989 NS_MAX_IOVECS);
28990 NS_PRV_IOVCNT(iovb) = 0;
28991@@ -2129,7 +2129,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28992 ("nicstar%d: Expected a small buffer, and this is not one.\n",
28993 card->index);
28994 which_list(card, skb);
28995- atomic_inc(&vcc->stats->rx_err);
28996+ atomic_inc_unchecked(&vcc->stats->rx_err);
28997 recycle_rx_buf(card, skb);
28998 vc->rx_iov = NULL;
28999 recycle_iov_buf(card, iovb);
29000@@ -2142,7 +2142,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
29001 ("nicstar%d: Expected a large buffer, and this is not one.\n",
29002 card->index);
29003 which_list(card, skb);
29004- atomic_inc(&vcc->stats->rx_err);
29005+ atomic_inc_unchecked(&vcc->stats->rx_err);
29006 recycle_iovec_rx_bufs(card, (struct iovec *)iovb->data,
29007 NS_PRV_IOVCNT(iovb));
29008 vc->rx_iov = NULL;
29009@@ -2165,7 +2165,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
29010 printk(" - PDU size mismatch.\n");
29011 else
29012 printk(".\n");
29013- atomic_inc(&vcc->stats->rx_err);
29014+ atomic_inc_unchecked(&vcc->stats->rx_err);
29015 recycle_iovec_rx_bufs(card, (struct iovec *)iovb->data,
29016 NS_PRV_IOVCNT(iovb));
29017 vc->rx_iov = NULL;
29018@@ -2179,7 +2179,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
29019 /* skb points to a small buffer */
29020 if (!atm_charge(vcc, skb->truesize)) {
29021 push_rxbufs(card, skb);
29022- atomic_inc(&vcc->stats->rx_drop);
29023+ atomic_inc_unchecked(&vcc->stats->rx_drop);
29024 } else {
29025 skb_put(skb, len);
29026 dequeue_sm_buf(card, skb);
29027@@ -2189,7 +2189,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
29028 ATM_SKB(skb)->vcc = vcc;
29029 __net_timestamp(skb);
29030 vcc->push(vcc, skb);
29031- atomic_inc(&vcc->stats->rx);
29032+ atomic_inc_unchecked(&vcc->stats->rx);
29033 }
29034 } else if (NS_PRV_IOVCNT(iovb) == 2) { /* One small plus one large buffer */
29035 struct sk_buff *sb;
29036@@ -2200,7 +2200,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
29037 if (len <= NS_SMBUFSIZE) {
29038 if (!atm_charge(vcc, sb->truesize)) {
29039 push_rxbufs(card, sb);
29040- atomic_inc(&vcc->stats->rx_drop);
29041+ atomic_inc_unchecked(&vcc->stats->rx_drop);
29042 } else {
29043 skb_put(sb, len);
29044 dequeue_sm_buf(card, sb);
29045@@ -2210,7 +2210,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
29046 ATM_SKB(sb)->vcc = vcc;
29047 __net_timestamp(sb);
29048 vcc->push(vcc, sb);
29049- atomic_inc(&vcc->stats->rx);
29050+ atomic_inc_unchecked(&vcc->stats->rx);
29051 }
29052
29053 push_rxbufs(card, skb);
29054@@ -2219,7 +2219,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
29055
29056 if (!atm_charge(vcc, skb->truesize)) {
29057 push_rxbufs(card, skb);
29058- atomic_inc(&vcc->stats->rx_drop);
29059+ atomic_inc_unchecked(&vcc->stats->rx_drop);
29060 } else {
29061 dequeue_lg_buf(card, skb);
29062 #ifdef NS_USE_DESTRUCTORS
29063@@ -2232,7 +2232,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
29064 ATM_SKB(skb)->vcc = vcc;
29065 __net_timestamp(skb);
29066 vcc->push(vcc, skb);
29067- atomic_inc(&vcc->stats->rx);
29068+ atomic_inc_unchecked(&vcc->stats->rx);
29069 }
29070
29071 push_rxbufs(card, sb);
29072@@ -2253,7 +2253,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
29073 printk
29074 ("nicstar%d: Out of huge buffers.\n",
29075 card->index);
29076- atomic_inc(&vcc->stats->rx_drop);
29077+ atomic_inc_unchecked(&vcc->stats->rx_drop);
29078 recycle_iovec_rx_bufs(card,
29079 (struct iovec *)
29080 iovb->data,
29081@@ -2304,7 +2304,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
29082 card->hbpool.count++;
29083 } else
29084 dev_kfree_skb_any(hb);
29085- atomic_inc(&vcc->stats->rx_drop);
29086+ atomic_inc_unchecked(&vcc->stats->rx_drop);
29087 } else {
29088 /* Copy the small buffer to the huge buffer */
29089 sb = (struct sk_buff *)iov->iov_base;
29090@@ -2341,7 +2341,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
29091 #endif /* NS_USE_DESTRUCTORS */
29092 __net_timestamp(hb);
29093 vcc->push(vcc, hb);
29094- atomic_inc(&vcc->stats->rx);
29095+ atomic_inc_unchecked(&vcc->stats->rx);
29096 }
29097 }
29098
29099diff --git a/drivers/atm/solos-pci.c b/drivers/atm/solos-pci.c
29100index 9851093..adb2b1e 100644
29101--- a/drivers/atm/solos-pci.c
29102+++ b/drivers/atm/solos-pci.c
29103@@ -714,7 +714,7 @@ void solos_bh(unsigned long card_arg)
29104 }
29105 atm_charge(vcc, skb->truesize);
29106 vcc->push(vcc, skb);
29107- atomic_inc(&vcc->stats->rx);
29108+ atomic_inc_unchecked(&vcc->stats->rx);
29109 break;
29110
29111 case PKT_STATUS:
29112@@ -1009,7 +1009,7 @@ static uint32_t fpga_tx(struct solos_card *card)
29113 vcc = SKB_CB(oldskb)->vcc;
29114
29115 if (vcc) {
29116- atomic_inc(&vcc->stats->tx);
29117+ atomic_inc_unchecked(&vcc->stats->tx);
29118 solos_pop(vcc, oldskb);
29119 } else
29120 dev_kfree_skb_irq(oldskb);
29121diff --git a/drivers/atm/suni.c b/drivers/atm/suni.c
29122index 0215934..ce9f5b1 100644
29123--- a/drivers/atm/suni.c
29124+++ b/drivers/atm/suni.c
29125@@ -49,8 +49,8 @@ static DEFINE_SPINLOCK(sunis_lock);
29126
29127
29128 #define ADD_LIMITED(s,v) \
29129- atomic_add((v),&stats->s); \
29130- if (atomic_read(&stats->s) < 0) atomic_set(&stats->s,INT_MAX);
29131+ atomic_add_unchecked((v),&stats->s); \
29132+ if (atomic_read_unchecked(&stats->s) < 0) atomic_set_unchecked(&stats->s,INT_MAX);
29133
29134
29135 static void suni_hz(unsigned long from_timer)
29136diff --git a/drivers/atm/uPD98402.c b/drivers/atm/uPD98402.c
29137index 5120a96..e2572bd 100644
29138--- a/drivers/atm/uPD98402.c
29139+++ b/drivers/atm/uPD98402.c
29140@@ -42,7 +42,7 @@ static int fetch_stats(struct atm_dev *dev,struct sonet_stats __user *arg,int ze
29141 struct sonet_stats tmp;
29142 int error = 0;
29143
29144- atomic_add(GET(HECCT),&PRIV(dev)->sonet_stats.uncorr_hcs);
29145+ atomic_add_unchecked(GET(HECCT),&PRIV(dev)->sonet_stats.uncorr_hcs);
29146 sonet_copy_stats(&PRIV(dev)->sonet_stats,&tmp);
29147 if (arg) error = copy_to_user(arg,&tmp,sizeof(tmp));
29148 if (zero && !error) {
29149@@ -161,9 +161,9 @@ static int uPD98402_ioctl(struct atm_dev *dev,unsigned int cmd,void __user *arg)
29150
29151
29152 #define ADD_LIMITED(s,v) \
29153- { atomic_add(GET(v),&PRIV(dev)->sonet_stats.s); \
29154- if (atomic_read(&PRIV(dev)->sonet_stats.s) < 0) \
29155- atomic_set(&PRIV(dev)->sonet_stats.s,INT_MAX); }
29156+ { atomic_add_unchecked(GET(v),&PRIV(dev)->sonet_stats.s); \
29157+ if (atomic_read_unchecked(&PRIV(dev)->sonet_stats.s) < 0) \
29158+ atomic_set_unchecked(&PRIV(dev)->sonet_stats.s,INT_MAX); }
29159
29160
29161 static void stat_event(struct atm_dev *dev)
29162@@ -194,7 +194,7 @@ static void uPD98402_int(struct atm_dev *dev)
29163 if (reason & uPD98402_INT_PFM) stat_event(dev);
29164 if (reason & uPD98402_INT_PCO) {
29165 (void) GET(PCOCR); /* clear interrupt cause */
29166- atomic_add(GET(HECCT),
29167+ atomic_add_unchecked(GET(HECCT),
29168 &PRIV(dev)->sonet_stats.uncorr_hcs);
29169 }
29170 if ((reason & uPD98402_INT_RFO) &&
29171@@ -222,9 +222,9 @@ static int uPD98402_start(struct atm_dev *dev)
29172 PUT(~(uPD98402_INT_PFM | uPD98402_INT_ALM | uPD98402_INT_RFO |
29173 uPD98402_INT_LOS),PIMR); /* enable them */
29174 (void) fetch_stats(dev,NULL,1); /* clear kernel counters */
29175- atomic_set(&PRIV(dev)->sonet_stats.corr_hcs,-1);
29176- atomic_set(&PRIV(dev)->sonet_stats.tx_cells,-1);
29177- atomic_set(&PRIV(dev)->sonet_stats.rx_cells,-1);
29178+ atomic_set_unchecked(&PRIV(dev)->sonet_stats.corr_hcs,-1);
29179+ atomic_set_unchecked(&PRIV(dev)->sonet_stats.tx_cells,-1);
29180+ atomic_set_unchecked(&PRIV(dev)->sonet_stats.rx_cells,-1);
29181 return 0;
29182 }
29183
29184diff --git a/drivers/atm/zatm.c b/drivers/atm/zatm.c
29185index abe4e20..83c4727 100644
29186--- a/drivers/atm/zatm.c
29187+++ b/drivers/atm/zatm.c
29188@@ -459,7 +459,7 @@ printk("dummy: 0x%08lx, 0x%08lx\n",dummy[0],dummy[1]);
29189 }
29190 if (!size) {
29191 dev_kfree_skb_irq(skb);
29192- if (vcc) atomic_inc(&vcc->stats->rx_err);
29193+ if (vcc) atomic_inc_unchecked(&vcc->stats->rx_err);
29194 continue;
29195 }
29196 if (!atm_charge(vcc,skb->truesize)) {
29197@@ -469,7 +469,7 @@ printk("dummy: 0x%08lx, 0x%08lx\n",dummy[0],dummy[1]);
29198 skb->len = size;
29199 ATM_SKB(skb)->vcc = vcc;
29200 vcc->push(vcc,skb);
29201- atomic_inc(&vcc->stats->rx);
29202+ atomic_inc_unchecked(&vcc->stats->rx);
29203 }
29204 zout(pos & 0xffff,MTA(mbx));
29205 #if 0 /* probably a stupid idea */
29206@@ -733,7 +733,7 @@ if (*ZATM_PRV_DSC(skb) != (uPD98401_TXPD_V | uPD98401_TXPD_DP |
29207 skb_queue_head(&zatm_vcc->backlog,skb);
29208 break;
29209 }
29210- atomic_inc(&vcc->stats->tx);
29211+ atomic_inc_unchecked(&vcc->stats->tx);
29212 wake_up(&zatm_vcc->tx_wait);
29213 }
29214
29215diff --git a/drivers/base/devtmpfs.c b/drivers/base/devtmpfs.c
29216index deb4a45..211eff2 100644
29217--- a/drivers/base/devtmpfs.c
29218+++ b/drivers/base/devtmpfs.c
29219@@ -347,7 +347,7 @@ int devtmpfs_mount(const char *mntdir)
29220 if (!thread)
29221 return 0;
29222
29223- err = sys_mount("devtmpfs", (char *)mntdir, "devtmpfs", MS_SILENT, NULL);
29224+ err = sys_mount((char __force_user *)"devtmpfs", (char __force_user *)mntdir, (char __force_user *)"devtmpfs", MS_SILENT, NULL);
29225 if (err)
29226 printk(KERN_INFO "devtmpfs: error mounting %i\n", err);
29227 else
29228diff --git a/drivers/base/power/wakeup.c b/drivers/base/power/wakeup.c
29229index cbb463b..babe2cf 100644
29230--- a/drivers/base/power/wakeup.c
29231+++ b/drivers/base/power/wakeup.c
29232@@ -29,14 +29,14 @@ bool events_check_enabled __read_mostly;
29233 * They need to be modified together atomically, so it's better to use one
29234 * atomic variable to hold them both.
29235 */
29236-static atomic_t combined_event_count = ATOMIC_INIT(0);
29237+static atomic_unchecked_t combined_event_count = ATOMIC_INIT(0);
29238
29239 #define IN_PROGRESS_BITS (sizeof(int) * 4)
29240 #define MAX_IN_PROGRESS ((1 << IN_PROGRESS_BITS) - 1)
29241
29242 static void split_counters(unsigned int *cnt, unsigned int *inpr)
29243 {
29244- unsigned int comb = atomic_read(&combined_event_count);
29245+ unsigned int comb = atomic_read_unchecked(&combined_event_count);
29246
29247 *cnt = (comb >> IN_PROGRESS_BITS);
29248 *inpr = comb & MAX_IN_PROGRESS;
29249@@ -385,7 +385,7 @@ static void wakeup_source_activate(struct wakeup_source *ws)
29250 ws->start_prevent_time = ws->last_time;
29251
29252 /* Increment the counter of events in progress. */
29253- cec = atomic_inc_return(&combined_event_count);
29254+ cec = atomic_inc_return_unchecked(&combined_event_count);
29255
29256 trace_wakeup_source_activate(ws->name, cec);
29257 }
29258@@ -511,7 +511,7 @@ static void wakeup_source_deactivate(struct wakeup_source *ws)
29259 * Increment the counter of registered wakeup events and decrement the
29260 * couter of wakeup events in progress simultaneously.
29261 */
29262- cec = atomic_add_return(MAX_IN_PROGRESS, &combined_event_count);
29263+ cec = atomic_add_return_unchecked(MAX_IN_PROGRESS, &combined_event_count);
29264 trace_wakeup_source_deactivate(ws->name, cec);
29265
29266 split_counters(&cnt, &inpr);
29267diff --git a/drivers/block/cciss.c b/drivers/block/cciss.c
29268index b0f553b..77b928b 100644
29269--- a/drivers/block/cciss.c
29270+++ b/drivers/block/cciss.c
29271@@ -1198,6 +1198,8 @@ static int cciss_ioctl32_passthru(struct block_device *bdev, fmode_t mode,
29272 int err;
29273 u32 cp;
29274
29275+ memset(&arg64, 0, sizeof(arg64));
29276+
29277 err = 0;
29278 err |=
29279 copy_from_user(&arg64.LUN_info, &arg32->LUN_info,
29280@@ -3007,7 +3009,7 @@ static void start_io(ctlr_info_t *h)
29281 while (!list_empty(&h->reqQ)) {
29282 c = list_entry(h->reqQ.next, CommandList_struct, list);
29283 /* can't do anything if fifo is full */
29284- if ((h->access.fifo_full(h))) {
29285+ if ((h->access->fifo_full(h))) {
29286 dev_warn(&h->pdev->dev, "fifo full\n");
29287 break;
29288 }
29289@@ -3017,7 +3019,7 @@ static void start_io(ctlr_info_t *h)
29290 h->Qdepth--;
29291
29292 /* Tell the controller execute command */
29293- h->access.submit_command(h, c);
29294+ h->access->submit_command(h, c);
29295
29296 /* Put job onto the completed Q */
29297 addQ(&h->cmpQ, c);
29298@@ -3443,17 +3445,17 @@ startio:
29299
29300 static inline unsigned long get_next_completion(ctlr_info_t *h)
29301 {
29302- return h->access.command_completed(h);
29303+ return h->access->command_completed(h);
29304 }
29305
29306 static inline int interrupt_pending(ctlr_info_t *h)
29307 {
29308- return h->access.intr_pending(h);
29309+ return h->access->intr_pending(h);
29310 }
29311
29312 static inline long interrupt_not_for_us(ctlr_info_t *h)
29313 {
29314- return ((h->access.intr_pending(h) == 0) ||
29315+ return ((h->access->intr_pending(h) == 0) ||
29316 (h->interrupts_enabled == 0));
29317 }
29318
29319@@ -3486,7 +3488,7 @@ static inline u32 next_command(ctlr_info_t *h)
29320 u32 a;
29321
29322 if (unlikely(!(h->transMethod & CFGTBL_Trans_Performant)))
29323- return h->access.command_completed(h);
29324+ return h->access->command_completed(h);
29325
29326 if ((*(h->reply_pool_head) & 1) == (h->reply_pool_wraparound)) {
29327 a = *(h->reply_pool_head); /* Next cmd in ring buffer */
29328@@ -4044,7 +4046,7 @@ static void __devinit cciss_put_controller_into_performant_mode(ctlr_info_t *h)
29329 trans_support & CFGTBL_Trans_use_short_tags);
29330
29331 /* Change the access methods to the performant access methods */
29332- h->access = SA5_performant_access;
29333+ h->access = &SA5_performant_access;
29334 h->transMethod = CFGTBL_Trans_Performant;
29335
29336 return;
29337@@ -4316,7 +4318,7 @@ static int __devinit cciss_pci_init(ctlr_info_t *h)
29338 if (prod_index < 0)
29339 return -ENODEV;
29340 h->product_name = products[prod_index].product_name;
29341- h->access = *(products[prod_index].access);
29342+ h->access = products[prod_index].access;
29343
29344 if (cciss_board_disabled(h)) {
29345 dev_warn(&h->pdev->dev, "controller appears to be disabled\n");
29346@@ -5041,7 +5043,7 @@ reinit_after_soft_reset:
29347 }
29348
29349 /* make sure the board interrupts are off */
29350- h->access.set_intr_mask(h, CCISS_INTR_OFF);
29351+ h->access->set_intr_mask(h, CCISS_INTR_OFF);
29352 rc = cciss_request_irq(h, do_cciss_msix_intr, do_cciss_intx);
29353 if (rc)
29354 goto clean2;
29355@@ -5093,7 +5095,7 @@ reinit_after_soft_reset:
29356 * fake ones to scoop up any residual completions.
29357 */
29358 spin_lock_irqsave(&h->lock, flags);
29359- h->access.set_intr_mask(h, CCISS_INTR_OFF);
29360+ h->access->set_intr_mask(h, CCISS_INTR_OFF);
29361 spin_unlock_irqrestore(&h->lock, flags);
29362 free_irq(h->intr[h->intr_mode], h);
29363 rc = cciss_request_irq(h, cciss_msix_discard_completions,
29364@@ -5113,9 +5115,9 @@ reinit_after_soft_reset:
29365 dev_info(&h->pdev->dev, "Board READY.\n");
29366 dev_info(&h->pdev->dev,
29367 "Waiting for stale completions to drain.\n");
29368- h->access.set_intr_mask(h, CCISS_INTR_ON);
29369+ h->access->set_intr_mask(h, CCISS_INTR_ON);
29370 msleep(10000);
29371- h->access.set_intr_mask(h, CCISS_INTR_OFF);
29372+ h->access->set_intr_mask(h, CCISS_INTR_OFF);
29373
29374 rc = controller_reset_failed(h->cfgtable);
29375 if (rc)
29376@@ -5138,7 +5140,7 @@ reinit_after_soft_reset:
29377 cciss_scsi_setup(h);
29378
29379 /* Turn the interrupts on so we can service requests */
29380- h->access.set_intr_mask(h, CCISS_INTR_ON);
29381+ h->access->set_intr_mask(h, CCISS_INTR_ON);
29382
29383 /* Get the firmware version */
29384 inq_buff = kzalloc(sizeof(InquiryData_struct), GFP_KERNEL);
29385@@ -5211,7 +5213,7 @@ static void cciss_shutdown(struct pci_dev *pdev)
29386 kfree(flush_buf);
29387 if (return_code != IO_OK)
29388 dev_warn(&h->pdev->dev, "Error flushing cache\n");
29389- h->access.set_intr_mask(h, CCISS_INTR_OFF);
29390+ h->access->set_intr_mask(h, CCISS_INTR_OFF);
29391 free_irq(h->intr[h->intr_mode], h);
29392 }
29393
29394diff --git a/drivers/block/cciss.h b/drivers/block/cciss.h
29395index 7fda30e..eb5dfe0 100644
29396--- a/drivers/block/cciss.h
29397+++ b/drivers/block/cciss.h
29398@@ -101,7 +101,7 @@ struct ctlr_info
29399 /* information about each logical volume */
29400 drive_info_struct *drv[CISS_MAX_LUN];
29401
29402- struct access_method access;
29403+ struct access_method *access;
29404
29405 /* queue and queue Info */
29406 struct list_head reqQ;
29407diff --git a/drivers/block/cpqarray.c b/drivers/block/cpqarray.c
29408index 9125bbe..eede5c8 100644
29409--- a/drivers/block/cpqarray.c
29410+++ b/drivers/block/cpqarray.c
29411@@ -404,7 +404,7 @@ static int __devinit cpqarray_register_ctlr( int i, struct pci_dev *pdev)
29412 if (register_blkdev(COMPAQ_SMART2_MAJOR+i, hba[i]->devname)) {
29413 goto Enomem4;
29414 }
29415- hba[i]->access.set_intr_mask(hba[i], 0);
29416+ hba[i]->access->set_intr_mask(hba[i], 0);
29417 if (request_irq(hba[i]->intr, do_ida_intr,
29418 IRQF_DISABLED|IRQF_SHARED, hba[i]->devname, hba[i]))
29419 {
29420@@ -459,7 +459,7 @@ static int __devinit cpqarray_register_ctlr( int i, struct pci_dev *pdev)
29421 add_timer(&hba[i]->timer);
29422
29423 /* Enable IRQ now that spinlock and rate limit timer are set up */
29424- hba[i]->access.set_intr_mask(hba[i], FIFO_NOT_EMPTY);
29425+ hba[i]->access->set_intr_mask(hba[i], FIFO_NOT_EMPTY);
29426
29427 for(j=0; j<NWD; j++) {
29428 struct gendisk *disk = ida_gendisk[i][j];
29429@@ -694,7 +694,7 @@ DBGINFO(
29430 for(i=0; i<NR_PRODUCTS; i++) {
29431 if (board_id == products[i].board_id) {
29432 c->product_name = products[i].product_name;
29433- c->access = *(products[i].access);
29434+ c->access = products[i].access;
29435 break;
29436 }
29437 }
29438@@ -792,7 +792,7 @@ static int __devinit cpqarray_eisa_detect(void)
29439 hba[ctlr]->intr = intr;
29440 sprintf(hba[ctlr]->devname, "ida%d", nr_ctlr);
29441 hba[ctlr]->product_name = products[j].product_name;
29442- hba[ctlr]->access = *(products[j].access);
29443+ hba[ctlr]->access = products[j].access;
29444 hba[ctlr]->ctlr = ctlr;
29445 hba[ctlr]->board_id = board_id;
29446 hba[ctlr]->pci_dev = NULL; /* not PCI */
29447@@ -980,7 +980,7 @@ static void start_io(ctlr_info_t *h)
29448
29449 while((c = h->reqQ) != NULL) {
29450 /* Can't do anything if we're busy */
29451- if (h->access.fifo_full(h) == 0)
29452+ if (h->access->fifo_full(h) == 0)
29453 return;
29454
29455 /* Get the first entry from the request Q */
29456@@ -988,7 +988,7 @@ static void start_io(ctlr_info_t *h)
29457 h->Qdepth--;
29458
29459 /* Tell the controller to do our bidding */
29460- h->access.submit_command(h, c);
29461+ h->access->submit_command(h, c);
29462
29463 /* Get onto the completion Q */
29464 addQ(&h->cmpQ, c);
29465@@ -1050,7 +1050,7 @@ static irqreturn_t do_ida_intr(int irq, void *dev_id)
29466 unsigned long flags;
29467 __u32 a,a1;
29468
29469- istat = h->access.intr_pending(h);
29470+ istat = h->access->intr_pending(h);
29471 /* Is this interrupt for us? */
29472 if (istat == 0)
29473 return IRQ_NONE;
29474@@ -1061,7 +1061,7 @@ static irqreturn_t do_ida_intr(int irq, void *dev_id)
29475 */
29476 spin_lock_irqsave(IDA_LOCK(h->ctlr), flags);
29477 if (istat & FIFO_NOT_EMPTY) {
29478- while((a = h->access.command_completed(h))) {
29479+ while((a = h->access->command_completed(h))) {
29480 a1 = a; a &= ~3;
29481 if ((c = h->cmpQ) == NULL)
29482 {
29483@@ -1449,11 +1449,11 @@ static int sendcmd(
29484 /*
29485 * Disable interrupt
29486 */
29487- info_p->access.set_intr_mask(info_p, 0);
29488+ info_p->access->set_intr_mask(info_p, 0);
29489 /* Make sure there is room in the command FIFO */
29490 /* Actually it should be completely empty at this time. */
29491 for (i = 200000; i > 0; i--) {
29492- temp = info_p->access.fifo_full(info_p);
29493+ temp = info_p->access->fifo_full(info_p);
29494 if (temp != 0) {
29495 break;
29496 }
29497@@ -1466,7 +1466,7 @@ DBG(
29498 /*
29499 * Send the cmd
29500 */
29501- info_p->access.submit_command(info_p, c);
29502+ info_p->access->submit_command(info_p, c);
29503 complete = pollcomplete(ctlr);
29504
29505 pci_unmap_single(info_p->pci_dev, (dma_addr_t) c->req.sg[0].addr,
29506@@ -1549,9 +1549,9 @@ static int revalidate_allvol(ctlr_info_t *host)
29507 * we check the new geometry. Then turn interrupts back on when
29508 * we're done.
29509 */
29510- host->access.set_intr_mask(host, 0);
29511+ host->access->set_intr_mask(host, 0);
29512 getgeometry(ctlr);
29513- host->access.set_intr_mask(host, FIFO_NOT_EMPTY);
29514+ host->access->set_intr_mask(host, FIFO_NOT_EMPTY);
29515
29516 for(i=0; i<NWD; i++) {
29517 struct gendisk *disk = ida_gendisk[ctlr][i];
29518@@ -1591,7 +1591,7 @@ static int pollcomplete(int ctlr)
29519 /* Wait (up to 2 seconds) for a command to complete */
29520
29521 for (i = 200000; i > 0; i--) {
29522- done = hba[ctlr]->access.command_completed(hba[ctlr]);
29523+ done = hba[ctlr]->access->command_completed(hba[ctlr]);
29524 if (done == 0) {
29525 udelay(10); /* a short fixed delay */
29526 } else
29527diff --git a/drivers/block/cpqarray.h b/drivers/block/cpqarray.h
29528index be73e9d..7fbf140 100644
29529--- a/drivers/block/cpqarray.h
29530+++ b/drivers/block/cpqarray.h
29531@@ -99,7 +99,7 @@ struct ctlr_info {
29532 drv_info_t drv[NWD];
29533 struct proc_dir_entry *proc;
29534
29535- struct access_method access;
29536+ struct access_method *access;
29537
29538 cmdlist_t *reqQ;
29539 cmdlist_t *cmpQ;
29540diff --git a/drivers/block/drbd/drbd_int.h b/drivers/block/drbd/drbd_int.h
29541index b953cc7..e3dc580 100644
29542--- a/drivers/block/drbd/drbd_int.h
29543+++ b/drivers/block/drbd/drbd_int.h
29544@@ -735,7 +735,7 @@ struct drbd_request;
29545 struct drbd_epoch {
29546 struct list_head list;
29547 unsigned int barrier_nr;
29548- atomic_t epoch_size; /* increased on every request added. */
29549+ atomic_unchecked_t epoch_size; /* increased on every request added. */
29550 atomic_t active; /* increased on every req. added, and dec on every finished. */
29551 unsigned long flags;
29552 };
29553@@ -1116,7 +1116,7 @@ struct drbd_conf {
29554 void *int_dig_in;
29555 void *int_dig_vv;
29556 wait_queue_head_t seq_wait;
29557- atomic_t packet_seq;
29558+ atomic_unchecked_t packet_seq;
29559 unsigned int peer_seq;
29560 spinlock_t peer_seq_lock;
29561 unsigned int minor;
29562@@ -1658,30 +1658,30 @@ static inline int drbd_setsockopt(struct socket *sock, int level, int optname,
29563
29564 static inline void drbd_tcp_cork(struct socket *sock)
29565 {
29566- int __user val = 1;
29567+ int val = 1;
29568 (void) drbd_setsockopt(sock, SOL_TCP, TCP_CORK,
29569- (char __user *)&val, sizeof(val));
29570+ (char __force_user *)&val, sizeof(val));
29571 }
29572
29573 static inline void drbd_tcp_uncork(struct socket *sock)
29574 {
29575- int __user val = 0;
29576+ int val = 0;
29577 (void) drbd_setsockopt(sock, SOL_TCP, TCP_CORK,
29578- (char __user *)&val, sizeof(val));
29579+ (char __force_user *)&val, sizeof(val));
29580 }
29581
29582 static inline void drbd_tcp_nodelay(struct socket *sock)
29583 {
29584- int __user val = 1;
29585+ int val = 1;
29586 (void) drbd_setsockopt(sock, SOL_TCP, TCP_NODELAY,
29587- (char __user *)&val, sizeof(val));
29588+ (char __force_user *)&val, sizeof(val));
29589 }
29590
29591 static inline void drbd_tcp_quickack(struct socket *sock)
29592 {
29593- int __user val = 2;
29594+ int val = 2;
29595 (void) drbd_setsockopt(sock, SOL_TCP, TCP_QUICKACK,
29596- (char __user *)&val, sizeof(val));
29597+ (char __force_user *)&val, sizeof(val));
29598 }
29599
29600 void drbd_bump_write_ordering(struct drbd_conf *mdev, enum write_ordering_e wo);
29601diff --git a/drivers/block/drbd/drbd_main.c b/drivers/block/drbd/drbd_main.c
29602index f93a032..71c87bf 100644
29603--- a/drivers/block/drbd/drbd_main.c
29604+++ b/drivers/block/drbd/drbd_main.c
29605@@ -2567,7 +2567,7 @@ static int _drbd_send_ack(struct drbd_conf *mdev, enum drbd_packets cmd,
29606 p.sector = sector;
29607 p.block_id = block_id;
29608 p.blksize = blksize;
29609- p.seq_num = cpu_to_be32(atomic_add_return(1, &mdev->packet_seq));
29610+ p.seq_num = cpu_to_be32(atomic_add_return_unchecked(1, &mdev->packet_seq));
29611
29612 if (!mdev->meta.socket || mdev->state.conn < C_CONNECTED)
29613 return false;
29614@@ -2865,7 +2865,7 @@ int drbd_send_dblock(struct drbd_conf *mdev, struct drbd_request *req)
29615
29616 p.sector = cpu_to_be64(req->sector);
29617 p.block_id = (unsigned long)req;
29618- p.seq_num = cpu_to_be32(atomic_add_return(1, &mdev->packet_seq));
29619+ p.seq_num = cpu_to_be32(atomic_add_return_unchecked(1, &mdev->packet_seq));
29620
29621 dp_flags = bio_flags_to_wire(mdev, req->master_bio->bi_rw);
29622
29623@@ -3150,7 +3150,7 @@ void drbd_init_set_defaults(struct drbd_conf *mdev)
29624 atomic_set(&mdev->unacked_cnt, 0);
29625 atomic_set(&mdev->local_cnt, 0);
29626 atomic_set(&mdev->net_cnt, 0);
29627- atomic_set(&mdev->packet_seq, 0);
29628+ atomic_set_unchecked(&mdev->packet_seq, 0);
29629 atomic_set(&mdev->pp_in_use, 0);
29630 atomic_set(&mdev->pp_in_use_by_net, 0);
29631 atomic_set(&mdev->rs_sect_in, 0);
29632@@ -3232,8 +3232,8 @@ void drbd_mdev_cleanup(struct drbd_conf *mdev)
29633 mdev->receiver.t_state);
29634
29635 /* no need to lock it, I'm the only thread alive */
29636- if (atomic_read(&mdev->current_epoch->epoch_size) != 0)
29637- dev_err(DEV, "epoch_size:%d\n", atomic_read(&mdev->current_epoch->epoch_size));
29638+ if (atomic_read_unchecked(&mdev->current_epoch->epoch_size) != 0)
29639+ dev_err(DEV, "epoch_size:%d\n", atomic_read_unchecked(&mdev->current_epoch->epoch_size));
29640 mdev->al_writ_cnt =
29641 mdev->bm_writ_cnt =
29642 mdev->read_cnt =
29643diff --git a/drivers/block/drbd/drbd_nl.c b/drivers/block/drbd/drbd_nl.c
29644index edb490a..ecd69da 100644
29645--- a/drivers/block/drbd/drbd_nl.c
29646+++ b/drivers/block/drbd/drbd_nl.c
29647@@ -2407,7 +2407,7 @@ static void drbd_connector_callback(struct cn_msg *req, struct netlink_skb_parms
29648 module_put(THIS_MODULE);
29649 }
29650
29651-static atomic_t drbd_nl_seq = ATOMIC_INIT(2); /* two. */
29652+static atomic_unchecked_t drbd_nl_seq = ATOMIC_INIT(2); /* two. */
29653
29654 static unsigned short *
29655 __tl_add_blob(unsigned short *tl, enum drbd_tags tag, const void *data,
29656@@ -2478,7 +2478,7 @@ void drbd_bcast_state(struct drbd_conf *mdev, union drbd_state state)
29657 cn_reply->id.idx = CN_IDX_DRBD;
29658 cn_reply->id.val = CN_VAL_DRBD;
29659
29660- cn_reply->seq = atomic_add_return(1, &drbd_nl_seq);
29661+ cn_reply->seq = atomic_add_return_unchecked(1, &drbd_nl_seq);
29662 cn_reply->ack = 0; /* not used here. */
29663 cn_reply->len = sizeof(struct drbd_nl_cfg_reply) +
29664 (int)((char *)tl - (char *)reply->tag_list);
29665@@ -2510,7 +2510,7 @@ void drbd_bcast_ev_helper(struct drbd_conf *mdev, char *helper_name)
29666 cn_reply->id.idx = CN_IDX_DRBD;
29667 cn_reply->id.val = CN_VAL_DRBD;
29668
29669- cn_reply->seq = atomic_add_return(1, &drbd_nl_seq);
29670+ cn_reply->seq = atomic_add_return_unchecked(1, &drbd_nl_seq);
29671 cn_reply->ack = 0; /* not used here. */
29672 cn_reply->len = sizeof(struct drbd_nl_cfg_reply) +
29673 (int)((char *)tl - (char *)reply->tag_list);
29674@@ -2588,7 +2588,7 @@ void drbd_bcast_ee(struct drbd_conf *mdev,
29675 cn_reply->id.idx = CN_IDX_DRBD;
29676 cn_reply->id.val = CN_VAL_DRBD;
29677
29678- cn_reply->seq = atomic_add_return(1,&drbd_nl_seq);
29679+ cn_reply->seq = atomic_add_return_unchecked(1,&drbd_nl_seq);
29680 cn_reply->ack = 0; // not used here.
29681 cn_reply->len = sizeof(struct drbd_nl_cfg_reply) +
29682 (int)((char*)tl - (char*)reply->tag_list);
29683@@ -2627,7 +2627,7 @@ void drbd_bcast_sync_progress(struct drbd_conf *mdev)
29684 cn_reply->id.idx = CN_IDX_DRBD;
29685 cn_reply->id.val = CN_VAL_DRBD;
29686
29687- cn_reply->seq = atomic_add_return(1, &drbd_nl_seq);
29688+ cn_reply->seq = atomic_add_return_unchecked(1, &drbd_nl_seq);
29689 cn_reply->ack = 0; /* not used here. */
29690 cn_reply->len = sizeof(struct drbd_nl_cfg_reply) +
29691 (int)((char *)tl - (char *)reply->tag_list);
29692diff --git a/drivers/block/drbd/drbd_receiver.c b/drivers/block/drbd/drbd_receiver.c
29693index c74ca2d..860c819 100644
29694--- a/drivers/block/drbd/drbd_receiver.c
29695+++ b/drivers/block/drbd/drbd_receiver.c
29696@@ -898,7 +898,7 @@ retry:
29697 sock->sk->sk_sndtimeo = mdev->net_conf->timeout*HZ/10;
29698 sock->sk->sk_rcvtimeo = MAX_SCHEDULE_TIMEOUT;
29699
29700- atomic_set(&mdev->packet_seq, 0);
29701+ atomic_set_unchecked(&mdev->packet_seq, 0);
29702 mdev->peer_seq = 0;
29703
29704 if (drbd_send_protocol(mdev) == -1)
29705@@ -999,7 +999,7 @@ static enum finish_epoch drbd_may_finish_epoch(struct drbd_conf *mdev,
29706 do {
29707 next_epoch = NULL;
29708
29709- epoch_size = atomic_read(&epoch->epoch_size);
29710+ epoch_size = atomic_read_unchecked(&epoch->epoch_size);
29711
29712 switch (ev & ~EV_CLEANUP) {
29713 case EV_PUT:
29714@@ -1035,7 +1035,7 @@ static enum finish_epoch drbd_may_finish_epoch(struct drbd_conf *mdev,
29715 rv = FE_DESTROYED;
29716 } else {
29717 epoch->flags = 0;
29718- atomic_set(&epoch->epoch_size, 0);
29719+ atomic_set_unchecked(&epoch->epoch_size, 0);
29720 /* atomic_set(&epoch->active, 0); is already zero */
29721 if (rv == FE_STILL_LIVE)
29722 rv = FE_RECYCLED;
29723@@ -1210,14 +1210,14 @@ static int receive_Barrier(struct drbd_conf *mdev, enum drbd_packets cmd, unsign
29724 drbd_wait_ee_list_empty(mdev, &mdev->active_ee);
29725 drbd_flush(mdev);
29726
29727- if (atomic_read(&mdev->current_epoch->epoch_size)) {
29728+ if (atomic_read_unchecked(&mdev->current_epoch->epoch_size)) {
29729 epoch = kmalloc(sizeof(struct drbd_epoch), GFP_NOIO);
29730 if (epoch)
29731 break;
29732 }
29733
29734 epoch = mdev->current_epoch;
29735- wait_event(mdev->ee_wait, atomic_read(&epoch->epoch_size) == 0);
29736+ wait_event(mdev->ee_wait, atomic_read_unchecked(&epoch->epoch_size) == 0);
29737
29738 D_ASSERT(atomic_read(&epoch->active) == 0);
29739 D_ASSERT(epoch->flags == 0);
29740@@ -1229,11 +1229,11 @@ static int receive_Barrier(struct drbd_conf *mdev, enum drbd_packets cmd, unsign
29741 }
29742
29743 epoch->flags = 0;
29744- atomic_set(&epoch->epoch_size, 0);
29745+ atomic_set_unchecked(&epoch->epoch_size, 0);
29746 atomic_set(&epoch->active, 0);
29747
29748 spin_lock(&mdev->epoch_lock);
29749- if (atomic_read(&mdev->current_epoch->epoch_size)) {
29750+ if (atomic_read_unchecked(&mdev->current_epoch->epoch_size)) {
29751 list_add(&epoch->list, &mdev->current_epoch->list);
29752 mdev->current_epoch = epoch;
29753 mdev->epochs++;
29754@@ -1702,7 +1702,7 @@ static int receive_Data(struct drbd_conf *mdev, enum drbd_packets cmd, unsigned
29755 spin_unlock(&mdev->peer_seq_lock);
29756
29757 drbd_send_ack_dp(mdev, P_NEG_ACK, p, data_size);
29758- atomic_inc(&mdev->current_epoch->epoch_size);
29759+ atomic_inc_unchecked(&mdev->current_epoch->epoch_size);
29760 return drbd_drain_block(mdev, data_size);
29761 }
29762
29763@@ -1732,7 +1732,7 @@ static int receive_Data(struct drbd_conf *mdev, enum drbd_packets cmd, unsigned
29764
29765 spin_lock(&mdev->epoch_lock);
29766 e->epoch = mdev->current_epoch;
29767- atomic_inc(&e->epoch->epoch_size);
29768+ atomic_inc_unchecked(&e->epoch->epoch_size);
29769 atomic_inc(&e->epoch->active);
29770 spin_unlock(&mdev->epoch_lock);
29771
29772@@ -3954,7 +3954,7 @@ static void drbd_disconnect(struct drbd_conf *mdev)
29773 D_ASSERT(list_empty(&mdev->done_ee));
29774
29775 /* ok, no more ee's on the fly, it is safe to reset the epoch_size */
29776- atomic_set(&mdev->current_epoch->epoch_size, 0);
29777+ atomic_set_unchecked(&mdev->current_epoch->epoch_size, 0);
29778 D_ASSERT(list_empty(&mdev->current_epoch->list));
29779 }
29780
29781diff --git a/drivers/block/loop.c b/drivers/block/loop.c
29782index 3bba655..6151b66 100644
29783--- a/drivers/block/loop.c
29784+++ b/drivers/block/loop.c
29785@@ -226,7 +226,7 @@ static int __do_lo_send_write(struct file *file,
29786 mm_segment_t old_fs = get_fs();
29787
29788 set_fs(get_ds());
29789- bw = file->f_op->write(file, buf, len, &pos);
29790+ bw = file->f_op->write(file, (const char __force_user *)buf, len, &pos);
29791 set_fs(old_fs);
29792 if (likely(bw == len))
29793 return 0;
29794diff --git a/drivers/char/Kconfig b/drivers/char/Kconfig
29795index ea6f632..eafb192 100644
29796--- a/drivers/char/Kconfig
29797+++ b/drivers/char/Kconfig
29798@@ -8,7 +8,8 @@ source "drivers/tty/Kconfig"
29799
29800 config DEVKMEM
29801 bool "/dev/kmem virtual device support"
29802- default y
29803+ default n
29804+ depends on !GRKERNSEC_KMEM
29805 help
29806 Say Y here if you want to support the /dev/kmem device. The
29807 /dev/kmem device is rarely used, but can be used for certain
29808@@ -581,6 +582,7 @@ config DEVPORT
29809 bool
29810 depends on !M68K
29811 depends on ISA || PCI
29812+ depends on !GRKERNSEC_KMEM
29813 default y
29814
29815 source "drivers/s390/char/Kconfig"
29816diff --git a/drivers/char/agp/frontend.c b/drivers/char/agp/frontend.c
29817index 2e04433..22afc64 100644
29818--- a/drivers/char/agp/frontend.c
29819+++ b/drivers/char/agp/frontend.c
29820@@ -817,7 +817,7 @@ static int agpioc_reserve_wrap(struct agp_file_private *priv, void __user *arg)
29821 if (copy_from_user(&reserve, arg, sizeof(struct agp_region)))
29822 return -EFAULT;
29823
29824- if ((unsigned) reserve.seg_count >= ~0U/sizeof(struct agp_segment))
29825+ if ((unsigned) reserve.seg_count >= ~0U/sizeof(struct agp_segment_priv))
29826 return -EFAULT;
29827
29828 client = agp_find_client_by_pid(reserve.pid);
29829diff --git a/drivers/char/genrtc.c b/drivers/char/genrtc.c
29830index 21cb980..f15107c 100644
29831--- a/drivers/char/genrtc.c
29832+++ b/drivers/char/genrtc.c
29833@@ -272,6 +272,7 @@ static int gen_rtc_ioctl(struct file *file,
29834 switch (cmd) {
29835
29836 case RTC_PLL_GET:
29837+ memset(&pll, 0, sizeof(pll));
29838 if (get_rtc_pll(&pll))
29839 return -EINVAL;
29840 else
29841diff --git a/drivers/char/hpet.c b/drivers/char/hpet.c
29842index dfd7876..c0b0885 100644
29843--- a/drivers/char/hpet.c
29844+++ b/drivers/char/hpet.c
29845@@ -571,7 +571,7 @@ static inline unsigned long hpet_time_div(struct hpets *hpets,
29846 }
29847
29848 static int
29849-hpet_ioctl_common(struct hpet_dev *devp, int cmd, unsigned long arg,
29850+hpet_ioctl_common(struct hpet_dev *devp, unsigned int cmd, unsigned long arg,
29851 struct hpet_info *info)
29852 {
29853 struct hpet_timer __iomem *timer;
29854diff --git a/drivers/char/ipmi/ipmi_msghandler.c b/drivers/char/ipmi/ipmi_msghandler.c
29855index 2c29942..604c5ba 100644
29856--- a/drivers/char/ipmi/ipmi_msghandler.c
29857+++ b/drivers/char/ipmi/ipmi_msghandler.c
29858@@ -420,7 +420,7 @@ struct ipmi_smi {
29859 struct proc_dir_entry *proc_dir;
29860 char proc_dir_name[10];
29861
29862- atomic_t stats[IPMI_NUM_STATS];
29863+ atomic_unchecked_t stats[IPMI_NUM_STATS];
29864
29865 /*
29866 * run_to_completion duplicate of smb_info, smi_info
29867@@ -453,9 +453,9 @@ static DEFINE_MUTEX(smi_watchers_mutex);
29868
29869
29870 #define ipmi_inc_stat(intf, stat) \
29871- atomic_inc(&(intf)->stats[IPMI_STAT_ ## stat])
29872+ atomic_inc_unchecked(&(intf)->stats[IPMI_STAT_ ## stat])
29873 #define ipmi_get_stat(intf, stat) \
29874- ((unsigned int) atomic_read(&(intf)->stats[IPMI_STAT_ ## stat]))
29875+ ((unsigned int) atomic_read_unchecked(&(intf)->stats[IPMI_STAT_ ## stat]))
29876
29877 static int is_lan_addr(struct ipmi_addr *addr)
29878 {
29879@@ -2884,7 +2884,7 @@ int ipmi_register_smi(struct ipmi_smi_handlers *handlers,
29880 INIT_LIST_HEAD(&intf->cmd_rcvrs);
29881 init_waitqueue_head(&intf->waitq);
29882 for (i = 0; i < IPMI_NUM_STATS; i++)
29883- atomic_set(&intf->stats[i], 0);
29884+ atomic_set_unchecked(&intf->stats[i], 0);
29885
29886 intf->proc_dir = NULL;
29887
29888diff --git a/drivers/char/ipmi/ipmi_si_intf.c b/drivers/char/ipmi/ipmi_si_intf.c
29889index 83f85cf..279e63f 100644
29890--- a/drivers/char/ipmi/ipmi_si_intf.c
29891+++ b/drivers/char/ipmi/ipmi_si_intf.c
29892@@ -275,7 +275,7 @@ struct smi_info {
29893 unsigned char slave_addr;
29894
29895 /* Counters and things for the proc filesystem. */
29896- atomic_t stats[SI_NUM_STATS];
29897+ atomic_unchecked_t stats[SI_NUM_STATS];
29898
29899 struct task_struct *thread;
29900
29901@@ -284,9 +284,9 @@ struct smi_info {
29902 };
29903
29904 #define smi_inc_stat(smi, stat) \
29905- atomic_inc(&(smi)->stats[SI_STAT_ ## stat])
29906+ atomic_inc_unchecked(&(smi)->stats[SI_STAT_ ## stat])
29907 #define smi_get_stat(smi, stat) \
29908- ((unsigned int) atomic_read(&(smi)->stats[SI_STAT_ ## stat]))
29909+ ((unsigned int) atomic_read_unchecked(&(smi)->stats[SI_STAT_ ## stat]))
29910
29911 #define SI_MAX_PARMS 4
29912
29913@@ -3193,7 +3193,7 @@ static int try_smi_init(struct smi_info *new_smi)
29914 atomic_set(&new_smi->req_events, 0);
29915 new_smi->run_to_completion = 0;
29916 for (i = 0; i < SI_NUM_STATS; i++)
29917- atomic_set(&new_smi->stats[i], 0);
29918+ atomic_set_unchecked(&new_smi->stats[i], 0);
29919
29920 new_smi->interrupt_disabled = 1;
29921 atomic_set(&new_smi->stop_operation, 0);
29922diff --git a/drivers/char/mbcs.c b/drivers/char/mbcs.c
29923index 47ff7e4..0c7d340 100644
29924--- a/drivers/char/mbcs.c
29925+++ b/drivers/char/mbcs.c
29926@@ -799,7 +799,7 @@ static int mbcs_remove(struct cx_dev *dev)
29927 return 0;
29928 }
29929
29930-static const struct cx_device_id __devinitdata mbcs_id_table[] = {
29931+static const struct cx_device_id __devinitconst mbcs_id_table[] = {
29932 {
29933 .part_num = MBCS_PART_NUM,
29934 .mfg_num = MBCS_MFG_NUM,
29935diff --git a/drivers/char/mem.c b/drivers/char/mem.c
29936index e5eedfa..fcab50ea 100644
29937--- a/drivers/char/mem.c
29938+++ b/drivers/char/mem.c
29939@@ -18,6 +18,7 @@
29940 #include <linux/raw.h>
29941 #include <linux/tty.h>
29942 #include <linux/capability.h>
29943+#include <linux/security.h>
29944 #include <linux/ptrace.h>
29945 #include <linux/device.h>
29946 #include <linux/highmem.h>
29947@@ -37,6 +38,10 @@
29948
29949 #define DEVPORT_MINOR 4
29950
29951+#if defined(CONFIG_GRKERNSEC) && !defined(CONFIG_GRKERNSEC_NO_RBAC)
29952+extern const struct file_operations grsec_fops;
29953+#endif
29954+
29955 static inline unsigned long size_inside_page(unsigned long start,
29956 unsigned long size)
29957 {
29958@@ -68,9 +73,13 @@ static inline int range_is_allowed(unsigned long pfn, unsigned long size)
29959
29960 while (cursor < to) {
29961 if (!devmem_is_allowed(pfn)) {
29962+#ifdef CONFIG_GRKERNSEC_KMEM
29963+ gr_handle_mem_readwrite(from, to);
29964+#else
29965 printk(KERN_INFO
29966 "Program %s tried to access /dev/mem between %Lx->%Lx.\n",
29967 current->comm, from, to);
29968+#endif
29969 return 0;
29970 }
29971 cursor += PAGE_SIZE;
29972@@ -78,6 +87,11 @@ static inline int range_is_allowed(unsigned long pfn, unsigned long size)
29973 }
29974 return 1;
29975 }
29976+#elif defined(CONFIG_GRKERNSEC_KMEM)
29977+static inline int range_is_allowed(unsigned long pfn, unsigned long size)
29978+{
29979+ return 0;
29980+}
29981 #else
29982 static inline int range_is_allowed(unsigned long pfn, unsigned long size)
29983 {
29984@@ -120,6 +134,7 @@ static ssize_t read_mem(struct file *file, char __user *buf,
29985
29986 while (count > 0) {
29987 unsigned long remaining;
29988+ char *temp;
29989
29990 sz = size_inside_page(p, count);
29991
29992@@ -135,7 +150,23 @@ static ssize_t read_mem(struct file *file, char __user *buf,
29993 if (!ptr)
29994 return -EFAULT;
29995
29996- remaining = copy_to_user(buf, ptr, sz);
29997+#ifdef CONFIG_PAX_USERCOPY
29998+ temp = kmalloc(sz, GFP_KERNEL|GFP_USERCOPY);
29999+ if (!temp) {
30000+ unxlate_dev_mem_ptr(p, ptr);
30001+ return -ENOMEM;
30002+ }
30003+ memcpy(temp, ptr, sz);
30004+#else
30005+ temp = ptr;
30006+#endif
30007+
30008+ remaining = copy_to_user(buf, temp, sz);
30009+
30010+#ifdef CONFIG_PAX_USERCOPY
30011+ kfree(temp);
30012+#endif
30013+
30014 unxlate_dev_mem_ptr(p, ptr);
30015 if (remaining)
30016 return -EFAULT;
30017@@ -398,9 +429,8 @@ static ssize_t read_kmem(struct file *file, char __user *buf,
30018 size_t count, loff_t *ppos)
30019 {
30020 unsigned long p = *ppos;
30021- ssize_t low_count, read, sz;
30022+ ssize_t low_count, read, sz, err = 0;
30023 char * kbuf; /* k-addr because vread() takes vmlist_lock rwlock */
30024- int err = 0;
30025
30026 read = 0;
30027 if (p < (unsigned long) high_memory) {
30028@@ -422,6 +452,8 @@ static ssize_t read_kmem(struct file *file, char __user *buf,
30029 }
30030 #endif
30031 while (low_count > 0) {
30032+ char *temp;
30033+
30034 sz = size_inside_page(p, low_count);
30035
30036 /*
30037@@ -431,7 +463,22 @@ static ssize_t read_kmem(struct file *file, char __user *buf,
30038 */
30039 kbuf = xlate_dev_kmem_ptr((char *)p);
30040
30041- if (copy_to_user(buf, kbuf, sz))
30042+#ifdef CONFIG_PAX_USERCOPY
30043+ temp = kmalloc(sz, GFP_KERNEL|GFP_USERCOPY);
30044+ if (!temp)
30045+ return -ENOMEM;
30046+ memcpy(temp, kbuf, sz);
30047+#else
30048+ temp = kbuf;
30049+#endif
30050+
30051+ err = copy_to_user(buf, temp, sz);
30052+
30053+#ifdef CONFIG_PAX_USERCOPY
30054+ kfree(temp);
30055+#endif
30056+
30057+ if (err)
30058 return -EFAULT;
30059 buf += sz;
30060 p += sz;
30061@@ -833,6 +880,9 @@ static const struct memdev {
30062 #ifdef CONFIG_CRASH_DUMP
30063 [12] = { "oldmem", 0, &oldmem_fops, NULL },
30064 #endif
30065+#if defined(CONFIG_GRKERNSEC) && !defined(CONFIG_GRKERNSEC_NO_RBAC)
30066+ [13] = { "grsec",S_IRUSR | S_IWUGO, &grsec_fops, NULL },
30067+#endif
30068 };
30069
30070 static int memory_open(struct inode *inode, struct file *filp)
30071diff --git a/drivers/char/nvram.c b/drivers/char/nvram.c
30072index 9df78e2..01ba9ae 100644
30073--- a/drivers/char/nvram.c
30074+++ b/drivers/char/nvram.c
30075@@ -247,7 +247,7 @@ static ssize_t nvram_read(struct file *file, char __user *buf,
30076
30077 spin_unlock_irq(&rtc_lock);
30078
30079- if (copy_to_user(buf, contents, tmp - contents))
30080+ if (tmp - contents > sizeof(contents) || copy_to_user(buf, contents, tmp - contents))
30081 return -EFAULT;
30082
30083 *ppos = i;
30084diff --git a/drivers/char/pcmcia/synclink_cs.c b/drivers/char/pcmcia/synclink_cs.c
30085index 0a484b4..f48ccd1 100644
30086--- a/drivers/char/pcmcia/synclink_cs.c
30087+++ b/drivers/char/pcmcia/synclink_cs.c
30088@@ -2340,9 +2340,9 @@ static void mgslpc_close(struct tty_struct *tty, struct file * filp)
30089
30090 if (debug_level >= DEBUG_LEVEL_INFO)
30091 printk("%s(%d):mgslpc_close(%s) entry, count=%d\n",
30092- __FILE__,__LINE__, info->device_name, port->count);
30093+ __FILE__,__LINE__, info->device_name, atomic_read(&port->count));
30094
30095- WARN_ON(!port->count);
30096+ WARN_ON(!atomic_read(&port->count));
30097
30098 if (tty_port_close_start(port, tty, filp) == 0)
30099 goto cleanup;
30100@@ -2360,7 +2360,7 @@ static void mgslpc_close(struct tty_struct *tty, struct file * filp)
30101 cleanup:
30102 if (debug_level >= DEBUG_LEVEL_INFO)
30103 printk("%s(%d):mgslpc_close(%s) exit, count=%d\n", __FILE__,__LINE__,
30104- tty->driver->name, port->count);
30105+ tty->driver->name, atomic_read(&port->count));
30106 }
30107
30108 /* Wait until the transmitter is empty.
30109@@ -2502,7 +2502,7 @@ static int mgslpc_open(struct tty_struct *tty, struct file * filp)
30110
30111 if (debug_level >= DEBUG_LEVEL_INFO)
30112 printk("%s(%d):mgslpc_open(%s), old ref count = %d\n",
30113- __FILE__,__LINE__,tty->driver->name, port->count);
30114+ __FILE__,__LINE__,tty->driver->name, atomic_read(&port->count));
30115
30116 /* If port is closing, signal caller to try again */
30117 if (tty_hung_up_p(filp) || port->flags & ASYNC_CLOSING){
30118@@ -2522,11 +2522,11 @@ static int mgslpc_open(struct tty_struct *tty, struct file * filp)
30119 goto cleanup;
30120 }
30121 spin_lock(&port->lock);
30122- port->count++;
30123+ atomic_inc(&port->count);
30124 spin_unlock(&port->lock);
30125 spin_unlock_irqrestore(&info->netlock, flags);
30126
30127- if (port->count == 1) {
30128+ if (atomic_read(&port->count) == 1) {
30129 /* 1st open on this device, init hardware */
30130 retval = startup(info, tty);
30131 if (retval < 0)
30132@@ -3891,7 +3891,7 @@ static int hdlcdev_attach(struct net_device *dev, unsigned short encoding,
30133 unsigned short new_crctype;
30134
30135 /* return error if TTY interface open */
30136- if (info->port.count)
30137+ if (atomic_read(&info->port.count))
30138 return -EBUSY;
30139
30140 switch (encoding)
30141@@ -3994,7 +3994,7 @@ static int hdlcdev_open(struct net_device *dev)
30142
30143 /* arbitrate between network and tty opens */
30144 spin_lock_irqsave(&info->netlock, flags);
30145- if (info->port.count != 0 || info->netcount != 0) {
30146+ if (atomic_read(&info->port.count) != 0 || info->netcount != 0) {
30147 printk(KERN_WARNING "%s: hdlc_open returning busy\n", dev->name);
30148 spin_unlock_irqrestore(&info->netlock, flags);
30149 return -EBUSY;
30150@@ -4083,7 +4083,7 @@ static int hdlcdev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
30151 printk("%s:hdlcdev_ioctl(%s)\n",__FILE__,dev->name);
30152
30153 /* return error if TTY interface open */
30154- if (info->port.count)
30155+ if (atomic_read(&info->port.count))
30156 return -EBUSY;
30157
30158 if (cmd != SIOCWANDEV)
30159diff --git a/drivers/char/random.c b/drivers/char/random.c
30160index b86eae9..4192a7a 100644
30161--- a/drivers/char/random.c
30162+++ b/drivers/char/random.c
30163@@ -272,8 +272,13 @@
30164 /*
30165 * Configuration information
30166 */
30167+#ifdef CONFIG_GRKERNSEC_RANDNET
30168+#define INPUT_POOL_WORDS 512
30169+#define OUTPUT_POOL_WORDS 128
30170+#else
30171 #define INPUT_POOL_WORDS 128
30172 #define OUTPUT_POOL_WORDS 32
30173+#endif
30174 #define SEC_XFER_SIZE 512
30175 #define EXTRACT_SIZE 10
30176
30177@@ -313,10 +318,17 @@ static struct poolinfo {
30178 int poolwords;
30179 int tap1, tap2, tap3, tap4, tap5;
30180 } poolinfo_table[] = {
30181+#ifdef CONFIG_GRKERNSEC_RANDNET
30182+ /* x^512 + x^411 + x^308 + x^208 +x^104 + x + 1 -- 225 */
30183+ { 512, 411, 308, 208, 104, 1 },
30184+ /* x^128 + x^103 + x^76 + x^51 + x^25 + x + 1 -- 105 */
30185+ { 128, 103, 76, 51, 25, 1 },
30186+#else
30187 /* x^128 + x^103 + x^76 + x^51 +x^25 + x + 1 -- 105 */
30188 { 128, 103, 76, 51, 25, 1 },
30189 /* x^32 + x^26 + x^20 + x^14 + x^7 + x + 1 -- 15 */
30190 { 32, 26, 20, 14, 7, 1 },
30191+#endif
30192 #if 0
30193 /* x^2048 + x^1638 + x^1231 + x^819 + x^411 + x + 1 -- 115 */
30194 { 2048, 1638, 1231, 819, 411, 1 },
30195@@ -527,8 +539,8 @@ static void _mix_pool_bytes(struct entropy_store *r, const void *in,
30196 input_rotate += i ? 7 : 14;
30197 }
30198
30199- ACCESS_ONCE(r->input_rotate) = input_rotate;
30200- ACCESS_ONCE(r->add_ptr) = i;
30201+ ACCESS_ONCE_RW(r->input_rotate) = input_rotate;
30202+ ACCESS_ONCE_RW(r->add_ptr) = i;
30203 smp_wmb();
30204
30205 if (out)
30206@@ -799,6 +811,17 @@ void add_disk_randomness(struct gendisk *disk)
30207 }
30208 #endif
30209
30210+#ifdef CONFIG_PAX_LATENT_ENTROPY
30211+u64 latent_entropy;
30212+
30213+__init void transfer_latent_entropy(void)
30214+{
30215+ mix_pool_bytes(&input_pool, &latent_entropy, sizeof(latent_entropy), NULL);
30216+ mix_pool_bytes(&nonblocking_pool, &latent_entropy, sizeof(latent_entropy), NULL);
30217+// printk(KERN_INFO "PAX: transferring latent entropy: %16llx\n", latent_entropy);
30218+}
30219+#endif
30220+
30221 /*********************************************************************
30222 *
30223 * Entropy extraction routines
30224@@ -1008,7 +1031,7 @@ static ssize_t extract_entropy_user(struct entropy_store *r, void __user *buf,
30225
30226 extract_buf(r, tmp);
30227 i = min_t(int, nbytes, EXTRACT_SIZE);
30228- if (copy_to_user(buf, tmp, i)) {
30229+ if (i > sizeof(tmp) || copy_to_user(buf, tmp, i)) {
30230 ret = -EFAULT;
30231 break;
30232 }
30233@@ -1342,7 +1365,7 @@ EXPORT_SYMBOL(generate_random_uuid);
30234 #include <linux/sysctl.h>
30235
30236 static int min_read_thresh = 8, min_write_thresh;
30237-static int max_read_thresh = INPUT_POOL_WORDS * 32;
30238+static int max_read_thresh = OUTPUT_POOL_WORDS * 32;
30239 static int max_write_thresh = INPUT_POOL_WORDS * 32;
30240 static char sysctl_bootid[16];
30241
30242diff --git a/drivers/char/sonypi.c b/drivers/char/sonypi.c
30243index f877805..403375a 100644
30244--- a/drivers/char/sonypi.c
30245+++ b/drivers/char/sonypi.c
30246@@ -54,6 +54,7 @@
30247
30248 #include <asm/uaccess.h>
30249 #include <asm/io.h>
30250+#include <asm/local.h>
30251
30252 #include <linux/sonypi.h>
30253
30254@@ -490,7 +491,7 @@ static struct sonypi_device {
30255 spinlock_t fifo_lock;
30256 wait_queue_head_t fifo_proc_list;
30257 struct fasync_struct *fifo_async;
30258- int open_count;
30259+ local_t open_count;
30260 int model;
30261 struct input_dev *input_jog_dev;
30262 struct input_dev *input_key_dev;
30263@@ -897,7 +898,7 @@ static int sonypi_misc_fasync(int fd, struct file *filp, int on)
30264 static int sonypi_misc_release(struct inode *inode, struct file *file)
30265 {
30266 mutex_lock(&sonypi_device.lock);
30267- sonypi_device.open_count--;
30268+ local_dec(&sonypi_device.open_count);
30269 mutex_unlock(&sonypi_device.lock);
30270 return 0;
30271 }
30272@@ -906,9 +907,9 @@ static int sonypi_misc_open(struct inode *inode, struct file *file)
30273 {
30274 mutex_lock(&sonypi_device.lock);
30275 /* Flush input queue on first open */
30276- if (!sonypi_device.open_count)
30277+ if (!local_read(&sonypi_device.open_count))
30278 kfifo_reset(&sonypi_device.fifo);
30279- sonypi_device.open_count++;
30280+ local_inc(&sonypi_device.open_count);
30281 mutex_unlock(&sonypi_device.lock);
30282
30283 return 0;
30284diff --git a/drivers/char/tpm/tpm.c b/drivers/char/tpm/tpm.c
30285index 4dc8024..90108d1 100644
30286--- a/drivers/char/tpm/tpm.c
30287+++ b/drivers/char/tpm/tpm.c
30288@@ -415,7 +415,7 @@ static ssize_t tpm_transmit(struct tpm_chip *chip, const char *buf,
30289 chip->vendor.req_complete_val)
30290 goto out_recv;
30291
30292- if ((status == chip->vendor.req_canceled)) {
30293+ if (status == chip->vendor.req_canceled) {
30294 dev_err(chip->dev, "Operation Canceled\n");
30295 rc = -ECANCELED;
30296 goto out;
30297diff --git a/drivers/char/tpm/tpm_bios.c b/drivers/char/tpm/tpm_bios.c
30298index 0636520..169c1d0 100644
30299--- a/drivers/char/tpm/tpm_bios.c
30300+++ b/drivers/char/tpm/tpm_bios.c
30301@@ -173,7 +173,7 @@ static void *tpm_bios_measurements_start(struct seq_file *m, loff_t *pos)
30302 event = addr;
30303
30304 if ((event->event_type == 0 && event->event_size == 0) ||
30305- ((addr + sizeof(struct tcpa_event) + event->event_size) >= limit))
30306+ (event->event_size >= limit - addr - sizeof(struct tcpa_event)))
30307 return NULL;
30308
30309 return addr;
30310@@ -198,7 +198,7 @@ static void *tpm_bios_measurements_next(struct seq_file *m, void *v,
30311 return NULL;
30312
30313 if ((event->event_type == 0 && event->event_size == 0) ||
30314- ((v + sizeof(struct tcpa_event) + event->event_size) >= limit))
30315+ (event->event_size >= limit - v - sizeof(struct tcpa_event)))
30316 return NULL;
30317
30318 (*pos)++;
30319@@ -291,7 +291,8 @@ static int tpm_binary_bios_measurements_show(struct seq_file *m, void *v)
30320 int i;
30321
30322 for (i = 0; i < sizeof(struct tcpa_event) + event->event_size; i++)
30323- seq_putc(m, data[i]);
30324+ if (!seq_putc(m, data[i]))
30325+ return -EFAULT;
30326
30327 return 0;
30328 }
30329@@ -410,8 +411,13 @@ static int read_log(struct tpm_bios_log *log)
30330 log->bios_event_log_end = log->bios_event_log + len;
30331
30332 virt = acpi_os_map_memory(start, len);
30333+ if (!virt) {
30334+ kfree(log->bios_event_log);
30335+ log->bios_event_log = NULL;
30336+ return -EFAULT;
30337+ }
30338
30339- memcpy(log->bios_event_log, virt, len);
30340+ memcpy(log->bios_event_log, (const char __force_kernel *)virt, len);
30341
30342 acpi_os_unmap_memory(virt, len);
30343 return 0;
30344diff --git a/drivers/char/virtio_console.c b/drivers/char/virtio_console.c
30345index cdf2f54..e55c197 100644
30346--- a/drivers/char/virtio_console.c
30347+++ b/drivers/char/virtio_console.c
30348@@ -563,7 +563,7 @@ static ssize_t fill_readbuf(struct port *port, char *out_buf, size_t out_count,
30349 if (to_user) {
30350 ssize_t ret;
30351
30352- ret = copy_to_user(out_buf, buf->buf + buf->offset, out_count);
30353+ ret = copy_to_user((char __force_user *)out_buf, buf->buf + buf->offset, out_count);
30354 if (ret)
30355 return -EFAULT;
30356 } else {
30357@@ -662,7 +662,7 @@ static ssize_t port_fops_read(struct file *filp, char __user *ubuf,
30358 if (!port_has_data(port) && !port->host_connected)
30359 return 0;
30360
30361- return fill_readbuf(port, ubuf, count, true);
30362+ return fill_readbuf(port, (char __force_kernel *)ubuf, count, true);
30363 }
30364
30365 static ssize_t port_fops_write(struct file *filp, const char __user *ubuf,
30366diff --git a/drivers/edac/edac_pci_sysfs.c b/drivers/edac/edac_pci_sysfs.c
30367index e164c55..3aabb50 100644
30368--- a/drivers/edac/edac_pci_sysfs.c
30369+++ b/drivers/edac/edac_pci_sysfs.c
30370@@ -26,8 +26,8 @@ static int edac_pci_log_pe = 1; /* log PCI parity errors */
30371 static int edac_pci_log_npe = 1; /* log PCI non-parity error errors */
30372 static int edac_pci_poll_msec = 1000; /* one second workq period */
30373
30374-static atomic_t pci_parity_count = ATOMIC_INIT(0);
30375-static atomic_t pci_nonparity_count = ATOMIC_INIT(0);
30376+static atomic_unchecked_t pci_parity_count = ATOMIC_INIT(0);
30377+static atomic_unchecked_t pci_nonparity_count = ATOMIC_INIT(0);
30378
30379 static struct kobject *edac_pci_top_main_kobj;
30380 static atomic_t edac_pci_sysfs_refcount = ATOMIC_INIT(0);
30381@@ -579,7 +579,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
30382 edac_printk(KERN_CRIT, EDAC_PCI,
30383 "Signaled System Error on %s\n",
30384 pci_name(dev));
30385- atomic_inc(&pci_nonparity_count);
30386+ atomic_inc_unchecked(&pci_nonparity_count);
30387 }
30388
30389 if (status & (PCI_STATUS_PARITY)) {
30390@@ -587,7 +587,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
30391 "Master Data Parity Error on %s\n",
30392 pci_name(dev));
30393
30394- atomic_inc(&pci_parity_count);
30395+ atomic_inc_unchecked(&pci_parity_count);
30396 }
30397
30398 if (status & (PCI_STATUS_DETECTED_PARITY)) {
30399@@ -595,7 +595,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
30400 "Detected Parity Error on %s\n",
30401 pci_name(dev));
30402
30403- atomic_inc(&pci_parity_count);
30404+ atomic_inc_unchecked(&pci_parity_count);
30405 }
30406 }
30407
30408@@ -618,7 +618,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
30409 edac_printk(KERN_CRIT, EDAC_PCI, "Bridge "
30410 "Signaled System Error on %s\n",
30411 pci_name(dev));
30412- atomic_inc(&pci_nonparity_count);
30413+ atomic_inc_unchecked(&pci_nonparity_count);
30414 }
30415
30416 if (status & (PCI_STATUS_PARITY)) {
30417@@ -626,7 +626,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
30418 "Master Data Parity Error on "
30419 "%s\n", pci_name(dev));
30420
30421- atomic_inc(&pci_parity_count);
30422+ atomic_inc_unchecked(&pci_parity_count);
30423 }
30424
30425 if (status & (PCI_STATUS_DETECTED_PARITY)) {
30426@@ -634,7 +634,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
30427 "Detected Parity Error on %s\n",
30428 pci_name(dev));
30429
30430- atomic_inc(&pci_parity_count);
30431+ atomic_inc_unchecked(&pci_parity_count);
30432 }
30433 }
30434 }
30435@@ -676,7 +676,7 @@ void edac_pci_do_parity_check(void)
30436 if (!check_pci_errors)
30437 return;
30438
30439- before_count = atomic_read(&pci_parity_count);
30440+ before_count = atomic_read_unchecked(&pci_parity_count);
30441
30442 /* scan all PCI devices looking for a Parity Error on devices and
30443 * bridges.
30444@@ -688,7 +688,7 @@ void edac_pci_do_parity_check(void)
30445 /* Only if operator has selected panic on PCI Error */
30446 if (edac_pci_get_panic_on_pe()) {
30447 /* If the count is different 'after' from 'before' */
30448- if (before_count != atomic_read(&pci_parity_count))
30449+ if (before_count != atomic_read_unchecked(&pci_parity_count))
30450 panic("EDAC: PCI Parity Error");
30451 }
30452 }
30453diff --git a/drivers/edac/mce_amd.h b/drivers/edac/mce_amd.h
30454index 8c87a5e..a19cbd7 100644
30455--- a/drivers/edac/mce_amd.h
30456+++ b/drivers/edac/mce_amd.h
30457@@ -80,7 +80,7 @@ extern const char * const ii_msgs[];
30458 struct amd_decoder_ops {
30459 bool (*dc_mce)(u16, u8);
30460 bool (*ic_mce)(u16, u8);
30461-};
30462+} __no_const;
30463
30464 void amd_report_gart_errors(bool);
30465 void amd_register_ecc_decoder(void (*f)(int, struct mce *));
30466diff --git a/drivers/firewire/core-card.c b/drivers/firewire/core-card.c
30467index 57ea7f4..789e3c3 100644
30468--- a/drivers/firewire/core-card.c
30469+++ b/drivers/firewire/core-card.c
30470@@ -680,7 +680,7 @@ EXPORT_SYMBOL_GPL(fw_card_release);
30471
30472 void fw_core_remove_card(struct fw_card *card)
30473 {
30474- struct fw_card_driver dummy_driver = dummy_driver_template;
30475+ fw_card_driver_no_const dummy_driver = dummy_driver_template;
30476
30477 card->driver->update_phy_reg(card, 4,
30478 PHY_LINK_ACTIVE | PHY_CONTENDER, 0);
30479diff --git a/drivers/firewire/core-cdev.c b/drivers/firewire/core-cdev.c
30480index f8d2287..5aaf4db 100644
30481--- a/drivers/firewire/core-cdev.c
30482+++ b/drivers/firewire/core-cdev.c
30483@@ -1365,8 +1365,7 @@ static int init_iso_resource(struct client *client,
30484 int ret;
30485
30486 if ((request->channels == 0 && request->bandwidth == 0) ||
30487- request->bandwidth > BANDWIDTH_AVAILABLE_INITIAL ||
30488- request->bandwidth < 0)
30489+ request->bandwidth > BANDWIDTH_AVAILABLE_INITIAL)
30490 return -EINVAL;
30491
30492 r = kmalloc(sizeof(*r), GFP_KERNEL);
30493diff --git a/drivers/firewire/core-transaction.c b/drivers/firewire/core-transaction.c
30494index 87d6f2d..5bf9d90 100644
30495--- a/drivers/firewire/core-transaction.c
30496+++ b/drivers/firewire/core-transaction.c
30497@@ -37,6 +37,7 @@
30498 #include <linux/timer.h>
30499 #include <linux/types.h>
30500 #include <linux/workqueue.h>
30501+#include <linux/sched.h>
30502
30503 #include <asm/byteorder.h>
30504
30505diff --git a/drivers/firewire/core.h b/drivers/firewire/core.h
30506index 515a42c..5ecf3ba 100644
30507--- a/drivers/firewire/core.h
30508+++ b/drivers/firewire/core.h
30509@@ -111,6 +111,7 @@ struct fw_card_driver {
30510
30511 int (*stop_iso)(struct fw_iso_context *ctx);
30512 };
30513+typedef struct fw_card_driver __no_const fw_card_driver_no_const;
30514
30515 void fw_card_initialize(struct fw_card *card,
30516 const struct fw_card_driver *driver, struct device *device);
30517diff --git a/drivers/firmware/dmi_scan.c b/drivers/firmware/dmi_scan.c
30518index b298158..7ed8432 100644
30519--- a/drivers/firmware/dmi_scan.c
30520+++ b/drivers/firmware/dmi_scan.c
30521@@ -452,11 +452,6 @@ void __init dmi_scan_machine(void)
30522 }
30523 }
30524 else {
30525- /*
30526- * no iounmap() for that ioremap(); it would be a no-op, but
30527- * it's so early in setup that sucker gets confused into doing
30528- * what it shouldn't if we actually call it.
30529- */
30530 p = dmi_ioremap(0xF0000, 0x10000);
30531 if (p == NULL)
30532 goto error;
30533@@ -726,7 +721,7 @@ int dmi_walk(void (*decode)(const struct dmi_header *, void *),
30534 if (buf == NULL)
30535 return -1;
30536
30537- dmi_table(buf, dmi_len, dmi_num, decode, private_data);
30538+ dmi_table((char __force_kernel *)buf, dmi_len, dmi_num, decode, private_data);
30539
30540 iounmap(buf);
30541 return 0;
30542diff --git a/drivers/gpio/gpio-vr41xx.c b/drivers/gpio/gpio-vr41xx.c
30543index 82d5c20..44a7177 100644
30544--- a/drivers/gpio/gpio-vr41xx.c
30545+++ b/drivers/gpio/gpio-vr41xx.c
30546@@ -204,7 +204,7 @@ static int giu_get_irq(unsigned int irq)
30547 printk(KERN_ERR "spurious GIU interrupt: %04x(%04x),%04x(%04x)\n",
30548 maskl, pendl, maskh, pendh);
30549
30550- atomic_inc(&irq_err_count);
30551+ atomic_inc_unchecked(&irq_err_count);
30552
30553 return -EINVAL;
30554 }
30555diff --git a/drivers/gpu/drm/drm_crtc_helper.c b/drivers/gpu/drm/drm_crtc_helper.c
30556index 3252e70..b5314ace 100644
30557--- a/drivers/gpu/drm/drm_crtc_helper.c
30558+++ b/drivers/gpu/drm/drm_crtc_helper.c
30559@@ -286,7 +286,7 @@ static bool drm_encoder_crtc_ok(struct drm_encoder *encoder,
30560 struct drm_crtc *tmp;
30561 int crtc_mask = 1;
30562
30563- WARN(!crtc, "checking null crtc?\n");
30564+ BUG_ON(!crtc);
30565
30566 dev = crtc->dev;
30567
30568diff --git a/drivers/gpu/drm/drm_drv.c b/drivers/gpu/drm/drm_drv.c
30569index 9238de4..a27c72a 100644
30570--- a/drivers/gpu/drm/drm_drv.c
30571+++ b/drivers/gpu/drm/drm_drv.c
30572@@ -307,7 +307,7 @@ module_exit(drm_core_exit);
30573 /**
30574 * Copy and IOCTL return string to user space
30575 */
30576-static int drm_copy_field(char *buf, size_t *buf_len, const char *value)
30577+static int drm_copy_field(char __user *buf, size_t *buf_len, const char *value)
30578 {
30579 int len;
30580
30581@@ -390,7 +390,7 @@ long drm_ioctl(struct file *filp,
30582 return -ENODEV;
30583
30584 atomic_inc(&dev->ioctl_count);
30585- atomic_inc(&dev->counts[_DRM_STAT_IOCTLS]);
30586+ atomic_inc_unchecked(&dev->counts[_DRM_STAT_IOCTLS]);
30587 ++file_priv->ioctl_count;
30588
30589 DRM_DEBUG("pid=%d, cmd=0x%02x, nr=0x%02x, dev 0x%lx, auth=%d\n",
30590diff --git a/drivers/gpu/drm/drm_fops.c b/drivers/gpu/drm/drm_fops.c
30591index 7aff5c7..bee6c27 100644
30592--- a/drivers/gpu/drm/drm_fops.c
30593+++ b/drivers/gpu/drm/drm_fops.c
30594@@ -71,7 +71,7 @@ static int drm_setup(struct drm_device * dev)
30595 }
30596
30597 for (i = 0; i < ARRAY_SIZE(dev->counts); i++)
30598- atomic_set(&dev->counts[i], 0);
30599+ atomic_set_unchecked(&dev->counts[i], 0);
30600
30601 dev->sigdata.lock = NULL;
30602
30603@@ -134,7 +134,7 @@ int drm_open(struct inode *inode, struct file *filp)
30604 if (drm_device_is_unplugged(dev))
30605 return -ENODEV;
30606
30607- if (!dev->open_count++)
30608+ if (local_inc_return(&dev->open_count) == 1)
30609 need_setup = 1;
30610 mutex_lock(&dev->struct_mutex);
30611 old_mapping = dev->dev_mapping;
30612@@ -149,7 +149,7 @@ int drm_open(struct inode *inode, struct file *filp)
30613 retcode = drm_open_helper(inode, filp, dev);
30614 if (retcode)
30615 goto err_undo;
30616- atomic_inc(&dev->counts[_DRM_STAT_OPENS]);
30617+ atomic_inc_unchecked(&dev->counts[_DRM_STAT_OPENS]);
30618 if (need_setup) {
30619 retcode = drm_setup(dev);
30620 if (retcode)
30621@@ -164,7 +164,7 @@ err_undo:
30622 iput(container_of(dev->dev_mapping, struct inode, i_data));
30623 dev->dev_mapping = old_mapping;
30624 mutex_unlock(&dev->struct_mutex);
30625- dev->open_count--;
30626+ local_dec(&dev->open_count);
30627 return retcode;
30628 }
30629 EXPORT_SYMBOL(drm_open);
30630@@ -438,7 +438,7 @@ int drm_release(struct inode *inode, struct file *filp)
30631
30632 mutex_lock(&drm_global_mutex);
30633
30634- DRM_DEBUG("open_count = %d\n", dev->open_count);
30635+ DRM_DEBUG("open_count = %ld\n", local_read(&dev->open_count));
30636
30637 if (dev->driver->preclose)
30638 dev->driver->preclose(dev, file_priv);
30639@@ -447,10 +447,10 @@ int drm_release(struct inode *inode, struct file *filp)
30640 * Begin inline drm_release
30641 */
30642
30643- DRM_DEBUG("pid = %d, device = 0x%lx, open_count = %d\n",
30644+ DRM_DEBUG("pid = %d, device = 0x%lx, open_count = %ld\n",
30645 task_pid_nr(current),
30646 (long)old_encode_dev(file_priv->minor->device),
30647- dev->open_count);
30648+ local_read(&dev->open_count));
30649
30650 /* Release any auth tokens that might point to this file_priv,
30651 (do that under the drm_global_mutex) */
30652@@ -546,8 +546,8 @@ int drm_release(struct inode *inode, struct file *filp)
30653 * End inline drm_release
30654 */
30655
30656- atomic_inc(&dev->counts[_DRM_STAT_CLOSES]);
30657- if (!--dev->open_count) {
30658+ atomic_inc_unchecked(&dev->counts[_DRM_STAT_CLOSES]);
30659+ if (local_dec_and_test(&dev->open_count)) {
30660 if (atomic_read(&dev->ioctl_count)) {
30661 DRM_ERROR("Device busy: %d\n",
30662 atomic_read(&dev->ioctl_count));
30663diff --git a/drivers/gpu/drm/drm_global.c b/drivers/gpu/drm/drm_global.c
30664index c87dc96..326055d 100644
30665--- a/drivers/gpu/drm/drm_global.c
30666+++ b/drivers/gpu/drm/drm_global.c
30667@@ -36,7 +36,7 @@
30668 struct drm_global_item {
30669 struct mutex mutex;
30670 void *object;
30671- int refcount;
30672+ atomic_t refcount;
30673 };
30674
30675 static struct drm_global_item glob[DRM_GLOBAL_NUM];
30676@@ -49,7 +49,7 @@ void drm_global_init(void)
30677 struct drm_global_item *item = &glob[i];
30678 mutex_init(&item->mutex);
30679 item->object = NULL;
30680- item->refcount = 0;
30681+ atomic_set(&item->refcount, 0);
30682 }
30683 }
30684
30685@@ -59,7 +59,7 @@ void drm_global_release(void)
30686 for (i = 0; i < DRM_GLOBAL_NUM; ++i) {
30687 struct drm_global_item *item = &glob[i];
30688 BUG_ON(item->object != NULL);
30689- BUG_ON(item->refcount != 0);
30690+ BUG_ON(atomic_read(&item->refcount) != 0);
30691 }
30692 }
30693
30694@@ -70,7 +70,7 @@ int drm_global_item_ref(struct drm_global_reference *ref)
30695 void *object;
30696
30697 mutex_lock(&item->mutex);
30698- if (item->refcount == 0) {
30699+ if (atomic_read(&item->refcount) == 0) {
30700 item->object = kzalloc(ref->size, GFP_KERNEL);
30701 if (unlikely(item->object == NULL)) {
30702 ret = -ENOMEM;
30703@@ -83,7 +83,7 @@ int drm_global_item_ref(struct drm_global_reference *ref)
30704 goto out_err;
30705
30706 }
30707- ++item->refcount;
30708+ atomic_inc(&item->refcount);
30709 ref->object = item->object;
30710 object = item->object;
30711 mutex_unlock(&item->mutex);
30712@@ -100,9 +100,9 @@ void drm_global_item_unref(struct drm_global_reference *ref)
30713 struct drm_global_item *item = &glob[ref->global_type];
30714
30715 mutex_lock(&item->mutex);
30716- BUG_ON(item->refcount == 0);
30717+ BUG_ON(atomic_read(&item->refcount) == 0);
30718 BUG_ON(ref->object != item->object);
30719- if (--item->refcount == 0) {
30720+ if (atomic_dec_and_test(&item->refcount)) {
30721 ref->release(ref);
30722 item->object = NULL;
30723 }
30724diff --git a/drivers/gpu/drm/drm_info.c b/drivers/gpu/drm/drm_info.c
30725index 8928edb..0c79258 100644
30726--- a/drivers/gpu/drm/drm_info.c
30727+++ b/drivers/gpu/drm/drm_info.c
30728@@ -75,10 +75,14 @@ int drm_vm_info(struct seq_file *m, void *data)
30729 struct drm_local_map *map;
30730 struct drm_map_list *r_list;
30731
30732- /* Hardcoded from _DRM_FRAME_BUFFER,
30733- _DRM_REGISTERS, _DRM_SHM, _DRM_AGP, and
30734- _DRM_SCATTER_GATHER and _DRM_CONSISTENT */
30735- const char *types[] = { "FB", "REG", "SHM", "AGP", "SG", "PCI" };
30736+ static const char * const types[] = {
30737+ [_DRM_FRAME_BUFFER] = "FB",
30738+ [_DRM_REGISTERS] = "REG",
30739+ [_DRM_SHM] = "SHM",
30740+ [_DRM_AGP] = "AGP",
30741+ [_DRM_SCATTER_GATHER] = "SG",
30742+ [_DRM_CONSISTENT] = "PCI",
30743+ [_DRM_GEM] = "GEM" };
30744 const char *type;
30745 int i;
30746
30747@@ -89,7 +93,7 @@ int drm_vm_info(struct seq_file *m, void *data)
30748 map = r_list->map;
30749 if (!map)
30750 continue;
30751- if (map->type < 0 || map->type > 5)
30752+ if (map->type >= ARRAY_SIZE(types))
30753 type = "??";
30754 else
30755 type = types[map->type];
30756@@ -254,7 +258,11 @@ int drm_vma_info(struct seq_file *m, void *data)
30757 vma->vm_flags & VM_MAYSHARE ? 's' : 'p',
30758 vma->vm_flags & VM_LOCKED ? 'l' : '-',
30759 vma->vm_flags & VM_IO ? 'i' : '-',
30760+#ifdef CONFIG_GRKERNSEC_HIDESYM
30761+ 0);
30762+#else
30763 vma->vm_pgoff);
30764+#endif
30765
30766 #if defined(__i386__)
30767 pgprot = pgprot_val(vma->vm_page_prot);
30768diff --git a/drivers/gpu/drm/drm_ioc32.c b/drivers/gpu/drm/drm_ioc32.c
30769index 637fcc3..e890b33 100644
30770--- a/drivers/gpu/drm/drm_ioc32.c
30771+++ b/drivers/gpu/drm/drm_ioc32.c
30772@@ -457,7 +457,7 @@ static int compat_drm_infobufs(struct file *file, unsigned int cmd,
30773 request = compat_alloc_user_space(nbytes);
30774 if (!access_ok(VERIFY_WRITE, request, nbytes))
30775 return -EFAULT;
30776- list = (struct drm_buf_desc *) (request + 1);
30777+ list = (struct drm_buf_desc __user *) (request + 1);
30778
30779 if (__put_user(count, &request->count)
30780 || __put_user(list, &request->list))
30781@@ -518,7 +518,7 @@ static int compat_drm_mapbufs(struct file *file, unsigned int cmd,
30782 request = compat_alloc_user_space(nbytes);
30783 if (!access_ok(VERIFY_WRITE, request, nbytes))
30784 return -EFAULT;
30785- list = (struct drm_buf_pub *) (request + 1);
30786+ list = (struct drm_buf_pub __user *) (request + 1);
30787
30788 if (__put_user(count, &request->count)
30789 || __put_user(list, &request->list))
30790diff --git a/drivers/gpu/drm/drm_ioctl.c b/drivers/gpu/drm/drm_ioctl.c
30791index 64a62c6..ceab35e 100644
30792--- a/drivers/gpu/drm/drm_ioctl.c
30793+++ b/drivers/gpu/drm/drm_ioctl.c
30794@@ -252,7 +252,7 @@ int drm_getstats(struct drm_device *dev, void *data,
30795 stats->data[i].value =
30796 (file_priv->master->lock.hw_lock ? file_priv->master->lock.hw_lock->lock : 0);
30797 else
30798- stats->data[i].value = atomic_read(&dev->counts[i]);
30799+ stats->data[i].value = atomic_read_unchecked(&dev->counts[i]);
30800 stats->data[i].type = dev->types[i];
30801 }
30802
30803diff --git a/drivers/gpu/drm/drm_lock.c b/drivers/gpu/drm/drm_lock.c
30804index 3203955..c8090af 100644
30805--- a/drivers/gpu/drm/drm_lock.c
30806+++ b/drivers/gpu/drm/drm_lock.c
30807@@ -86,7 +86,7 @@ int drm_lock(struct drm_device *dev, void *data, struct drm_file *file_priv)
30808 if (drm_lock_take(&master->lock, lock->context)) {
30809 master->lock.file_priv = file_priv;
30810 master->lock.lock_time = jiffies;
30811- atomic_inc(&dev->counts[_DRM_STAT_LOCKS]);
30812+ atomic_inc_unchecked(&dev->counts[_DRM_STAT_LOCKS]);
30813 break; /* Got lock */
30814 }
30815
30816@@ -157,7 +157,7 @@ int drm_unlock(struct drm_device *dev, void *data, struct drm_file *file_priv)
30817 return -EINVAL;
30818 }
30819
30820- atomic_inc(&dev->counts[_DRM_STAT_UNLOCKS]);
30821+ atomic_inc_unchecked(&dev->counts[_DRM_STAT_UNLOCKS]);
30822
30823 if (drm_lock_free(&master->lock, lock->context)) {
30824 /* FIXME: Should really bail out here. */
30825diff --git a/drivers/gpu/drm/drm_stub.c b/drivers/gpu/drm/drm_stub.c
30826index 21bcd4a..8e074e0 100644
30827--- a/drivers/gpu/drm/drm_stub.c
30828+++ b/drivers/gpu/drm/drm_stub.c
30829@@ -511,7 +511,7 @@ void drm_unplug_dev(struct drm_device *dev)
30830
30831 drm_device_set_unplugged(dev);
30832
30833- if (dev->open_count == 0) {
30834+ if (local_read(&dev->open_count) == 0) {
30835 drm_put_dev(dev);
30836 }
30837 mutex_unlock(&drm_global_mutex);
30838diff --git a/drivers/gpu/drm/i810/i810_dma.c b/drivers/gpu/drm/i810/i810_dma.c
30839index 463ec68..f5bd2b5 100644
30840--- a/drivers/gpu/drm/i810/i810_dma.c
30841+++ b/drivers/gpu/drm/i810/i810_dma.c
30842@@ -946,8 +946,8 @@ static int i810_dma_vertex(struct drm_device *dev, void *data,
30843 dma->buflist[vertex->idx],
30844 vertex->discard, vertex->used);
30845
30846- atomic_add(vertex->used, &dev->counts[_DRM_STAT_SECONDARY]);
30847- atomic_inc(&dev->counts[_DRM_STAT_DMA]);
30848+ atomic_add_unchecked(vertex->used, &dev->counts[_DRM_STAT_SECONDARY]);
30849+ atomic_inc_unchecked(&dev->counts[_DRM_STAT_DMA]);
30850 sarea_priv->last_enqueue = dev_priv->counter - 1;
30851 sarea_priv->last_dispatch = (int)hw_status[5];
30852
30853@@ -1107,8 +1107,8 @@ static int i810_dma_mc(struct drm_device *dev, void *data,
30854 i810_dma_dispatch_mc(dev, dma->buflist[mc->idx], mc->used,
30855 mc->last_render);
30856
30857- atomic_add(mc->used, &dev->counts[_DRM_STAT_SECONDARY]);
30858- atomic_inc(&dev->counts[_DRM_STAT_DMA]);
30859+ atomic_add_unchecked(mc->used, &dev->counts[_DRM_STAT_SECONDARY]);
30860+ atomic_inc_unchecked(&dev->counts[_DRM_STAT_DMA]);
30861 sarea_priv->last_enqueue = dev_priv->counter - 1;
30862 sarea_priv->last_dispatch = (int)hw_status[5];
30863
30864diff --git a/drivers/gpu/drm/i810/i810_drv.h b/drivers/gpu/drm/i810/i810_drv.h
30865index 6e0acad..93c8289 100644
30866--- a/drivers/gpu/drm/i810/i810_drv.h
30867+++ b/drivers/gpu/drm/i810/i810_drv.h
30868@@ -108,8 +108,8 @@ typedef struct drm_i810_private {
30869 int page_flipping;
30870
30871 wait_queue_head_t irq_queue;
30872- atomic_t irq_received;
30873- atomic_t irq_emitted;
30874+ atomic_unchecked_t irq_received;
30875+ atomic_unchecked_t irq_emitted;
30876
30877 int front_offset;
30878 } drm_i810_private_t;
30879diff --git a/drivers/gpu/drm/i915/i915_debugfs.c b/drivers/gpu/drm/i915/i915_debugfs.c
30880index 359f6e8..ada68fd 100644
30881--- a/drivers/gpu/drm/i915/i915_debugfs.c
30882+++ b/drivers/gpu/drm/i915/i915_debugfs.c
30883@@ -518,7 +518,7 @@ static int i915_interrupt_info(struct seq_file *m, void *data)
30884 I915_READ(GTIMR));
30885 }
30886 seq_printf(m, "Interrupts received: %d\n",
30887- atomic_read(&dev_priv->irq_received));
30888+ atomic_read_unchecked(&dev_priv->irq_received));
30889 for (i = 0; i < I915_NUM_RINGS; i++) {
30890 if (IS_GEN6(dev) || IS_GEN7(dev)) {
30891 seq_printf(m, "Graphics Interrupt mask (%s): %08x\n",
30892diff --git a/drivers/gpu/drm/i915/i915_dma.c b/drivers/gpu/drm/i915/i915_dma.c
30893index 0969a7c..b9ffa45 100644
30894--- a/drivers/gpu/drm/i915/i915_dma.c
30895+++ b/drivers/gpu/drm/i915/i915_dma.c
30896@@ -1269,7 +1269,7 @@ static bool i915_switcheroo_can_switch(struct pci_dev *pdev)
30897 bool can_switch;
30898
30899 spin_lock(&dev->count_lock);
30900- can_switch = (dev->open_count == 0);
30901+ can_switch = (local_read(&dev->open_count) == 0);
30902 spin_unlock(&dev->count_lock);
30903 return can_switch;
30904 }
30905diff --git a/drivers/gpu/drm/i915/i915_drv.h b/drivers/gpu/drm/i915/i915_drv.h
30906index 627fe35..c9a7346 100644
30907--- a/drivers/gpu/drm/i915/i915_drv.h
30908+++ b/drivers/gpu/drm/i915/i915_drv.h
30909@@ -272,12 +272,12 @@ struct drm_i915_display_funcs {
30910 /* render clock increase/decrease */
30911 /* display clock increase/decrease */
30912 /* pll clock increase/decrease */
30913-};
30914+} __no_const;
30915
30916 struct drm_i915_gt_funcs {
30917 void (*force_wake_get)(struct drm_i915_private *dev_priv);
30918 void (*force_wake_put)(struct drm_i915_private *dev_priv);
30919-};
30920+} __no_const;
30921
30922 struct intel_device_info {
30923 u8 gen;
30924@@ -408,7 +408,7 @@ typedef struct drm_i915_private {
30925 int current_page;
30926 int page_flipping;
30927
30928- atomic_t irq_received;
30929+ atomic_unchecked_t irq_received;
30930
30931 /* protects the irq masks */
30932 spinlock_t irq_lock;
30933@@ -1014,7 +1014,7 @@ struct drm_i915_gem_object {
30934 * will be page flipped away on the next vblank. When it
30935 * reaches 0, dev_priv->pending_flip_queue will be woken up.
30936 */
30937- atomic_t pending_flip;
30938+ atomic_unchecked_t pending_flip;
30939 };
30940
30941 #define to_intel_bo(x) container_of(x, struct drm_i915_gem_object, base)
30942@@ -1482,7 +1482,7 @@ extern struct i2c_adapter *intel_gmbus_get_adapter(
30943 struct drm_i915_private *dev_priv, unsigned port);
30944 extern void intel_gmbus_set_speed(struct i2c_adapter *adapter, int speed);
30945 extern void intel_gmbus_force_bit(struct i2c_adapter *adapter, bool force_bit);
30946-extern inline bool intel_gmbus_is_forced_bit(struct i2c_adapter *adapter)
30947+static inline bool intel_gmbus_is_forced_bit(struct i2c_adapter *adapter)
30948 {
30949 return container_of(adapter, struct intel_gmbus, adapter)->force_bit;
30950 }
30951diff --git a/drivers/gpu/drm/i915/i915_gem_execbuffer.c b/drivers/gpu/drm/i915/i915_gem_execbuffer.c
30952index cdf46b5..e785624 100644
30953--- a/drivers/gpu/drm/i915/i915_gem_execbuffer.c
30954+++ b/drivers/gpu/drm/i915/i915_gem_execbuffer.c
30955@@ -189,7 +189,7 @@ i915_gem_object_set_to_gpu_domain(struct drm_i915_gem_object *obj,
30956 i915_gem_clflush_object(obj);
30957
30958 if (obj->base.pending_write_domain)
30959- cd->flips |= atomic_read(&obj->pending_flip);
30960+ cd->flips |= atomic_read_unchecked(&obj->pending_flip);
30961
30962 /* The actual obj->write_domain will be updated with
30963 * pending_write_domain after we emit the accumulated flush for all
30964@@ -907,9 +907,9 @@ i915_gem_check_execbuffer(struct drm_i915_gem_execbuffer2 *exec)
30965
30966 static int
30967 validate_exec_list(struct drm_i915_gem_exec_object2 *exec,
30968- int count)
30969+ unsigned int count)
30970 {
30971- int i;
30972+ unsigned int i;
30973
30974 for (i = 0; i < count; i++) {
30975 char __user *ptr = (char __user *)(uintptr_t)exec[i].relocs_ptr;
30976diff --git a/drivers/gpu/drm/i915/i915_irq.c b/drivers/gpu/drm/i915/i915_irq.c
30977index 73fa3e1..ab2e9b9 100644
30978--- a/drivers/gpu/drm/i915/i915_irq.c
30979+++ b/drivers/gpu/drm/i915/i915_irq.c
30980@@ -514,7 +514,7 @@ static irqreturn_t valleyview_irq_handler(DRM_IRQ_ARGS)
30981 u32 pipe_stats[I915_MAX_PIPES];
30982 bool blc_event;
30983
30984- atomic_inc(&dev_priv->irq_received);
30985+ atomic_inc_unchecked(&dev_priv->irq_received);
30986
30987 while (true) {
30988 iir = I915_READ(VLV_IIR);
30989@@ -661,7 +661,7 @@ static irqreturn_t ivybridge_irq_handler(DRM_IRQ_ARGS)
30990 irqreturn_t ret = IRQ_NONE;
30991 int i;
30992
30993- atomic_inc(&dev_priv->irq_received);
30994+ atomic_inc_unchecked(&dev_priv->irq_received);
30995
30996 /* disable master interrupt before clearing iir */
30997 de_ier = I915_READ(DEIER);
30998@@ -736,7 +736,7 @@ static irqreturn_t ironlake_irq_handler(DRM_IRQ_ARGS)
30999 u32 de_iir, gt_iir, de_ier, pch_iir, pm_iir;
31000 u32 hotplug_mask;
31001
31002- atomic_inc(&dev_priv->irq_received);
31003+ atomic_inc_unchecked(&dev_priv->irq_received);
31004
31005 /* disable master interrupt before clearing iir */
31006 de_ier = I915_READ(DEIER);
31007@@ -1717,7 +1717,7 @@ static void ironlake_irq_preinstall(struct drm_device *dev)
31008 {
31009 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
31010
31011- atomic_set(&dev_priv->irq_received, 0);
31012+ atomic_set_unchecked(&dev_priv->irq_received, 0);
31013
31014 I915_WRITE(HWSTAM, 0xeffe);
31015
31016@@ -1743,7 +1743,7 @@ static void valleyview_irq_preinstall(struct drm_device *dev)
31017 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
31018 int pipe;
31019
31020- atomic_set(&dev_priv->irq_received, 0);
31021+ atomic_set_unchecked(&dev_priv->irq_received, 0);
31022
31023 /* VLV magic */
31024 I915_WRITE(VLV_IMR, 0);
31025@@ -2048,7 +2048,7 @@ static void i8xx_irq_preinstall(struct drm_device * dev)
31026 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
31027 int pipe;
31028
31029- atomic_set(&dev_priv->irq_received, 0);
31030+ atomic_set_unchecked(&dev_priv->irq_received, 0);
31031
31032 for_each_pipe(pipe)
31033 I915_WRITE(PIPESTAT(pipe), 0);
31034@@ -2099,7 +2099,7 @@ static irqreturn_t i8xx_irq_handler(DRM_IRQ_ARGS)
31035 I915_DISPLAY_PLANE_A_FLIP_PENDING_INTERRUPT |
31036 I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT;
31037
31038- atomic_inc(&dev_priv->irq_received);
31039+ atomic_inc_unchecked(&dev_priv->irq_received);
31040
31041 iir = I915_READ16(IIR);
31042 if (iir == 0)
31043@@ -2184,7 +2184,7 @@ static void i915_irq_preinstall(struct drm_device * dev)
31044 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
31045 int pipe;
31046
31047- atomic_set(&dev_priv->irq_received, 0);
31048+ atomic_set_unchecked(&dev_priv->irq_received, 0);
31049
31050 if (I915_HAS_HOTPLUG(dev)) {
31051 I915_WRITE(PORT_HOTPLUG_EN, 0);
31052@@ -2279,7 +2279,7 @@ static irqreturn_t i915_irq_handler(DRM_IRQ_ARGS)
31053 };
31054 int pipe, ret = IRQ_NONE;
31055
31056- atomic_inc(&dev_priv->irq_received);
31057+ atomic_inc_unchecked(&dev_priv->irq_received);
31058
31059 iir = I915_READ(IIR);
31060 do {
31061@@ -2405,7 +2405,7 @@ static void i965_irq_preinstall(struct drm_device * dev)
31062 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
31063 int pipe;
31064
31065- atomic_set(&dev_priv->irq_received, 0);
31066+ atomic_set_unchecked(&dev_priv->irq_received, 0);
31067
31068 I915_WRITE(PORT_HOTPLUG_EN, 0);
31069 I915_WRITE(PORT_HOTPLUG_STAT, I915_READ(PORT_HOTPLUG_STAT));
31070@@ -2512,7 +2512,7 @@ static irqreturn_t i965_irq_handler(DRM_IRQ_ARGS)
31071 int irq_received;
31072 int ret = IRQ_NONE, pipe;
31073
31074- atomic_inc(&dev_priv->irq_received);
31075+ atomic_inc_unchecked(&dev_priv->irq_received);
31076
31077 iir = I915_READ(IIR);
31078
31079diff --git a/drivers/gpu/drm/i915/intel_display.c b/drivers/gpu/drm/i915/intel_display.c
31080index b634f6f..43c62f5 100644
31081--- a/drivers/gpu/drm/i915/intel_display.c
31082+++ b/drivers/gpu/drm/i915/intel_display.c
31083@@ -2182,7 +2182,7 @@ intel_finish_fb(struct drm_framebuffer *old_fb)
31084
31085 wait_event(dev_priv->pending_flip_queue,
31086 atomic_read(&dev_priv->mm.wedged) ||
31087- atomic_read(&obj->pending_flip) == 0);
31088+ atomic_read_unchecked(&obj->pending_flip) == 0);
31089
31090 /* Big Hammer, we also need to ensure that any pending
31091 * MI_WAIT_FOR_EVENT inside a user batch buffer on the
31092@@ -6168,8 +6168,7 @@ static void do_intel_finish_page_flip(struct drm_device *dev,
31093
31094 obj = work->old_fb_obj;
31095
31096- atomic_clear_mask(1 << intel_crtc->plane,
31097- &obj->pending_flip.counter);
31098+ atomic_clear_mask_unchecked(1 << intel_crtc->plane, &obj->pending_flip);
31099
31100 wake_up(&dev_priv->pending_flip_queue);
31101 schedule_work(&work->work);
31102@@ -6515,7 +6514,7 @@ static int intel_crtc_page_flip(struct drm_crtc *crtc,
31103 /* Block clients from rendering to the new back buffer until
31104 * the flip occurs and the object is no longer visible.
31105 */
31106- atomic_add(1 << intel_crtc->plane, &work->old_fb_obj->pending_flip);
31107+ atomic_add_unchecked(1 << intel_crtc->plane, &work->old_fb_obj->pending_flip);
31108
31109 ret = dev_priv->display.queue_flip(dev, crtc, fb, obj);
31110 if (ret)
31111@@ -6530,7 +6529,7 @@ static int intel_crtc_page_flip(struct drm_crtc *crtc,
31112 return 0;
31113
31114 cleanup_pending:
31115- atomic_sub(1 << intel_crtc->plane, &work->old_fb_obj->pending_flip);
31116+ atomic_sub_unchecked(1 << intel_crtc->plane, &work->old_fb_obj->pending_flip);
31117 drm_gem_object_unreference(&work->old_fb_obj->base);
31118 drm_gem_object_unreference(&obj->base);
31119 mutex_unlock(&dev->struct_mutex);
31120diff --git a/drivers/gpu/drm/mga/mga_drv.h b/drivers/gpu/drm/mga/mga_drv.h
31121index 54558a0..2d97005 100644
31122--- a/drivers/gpu/drm/mga/mga_drv.h
31123+++ b/drivers/gpu/drm/mga/mga_drv.h
31124@@ -120,9 +120,9 @@ typedef struct drm_mga_private {
31125 u32 clear_cmd;
31126 u32 maccess;
31127
31128- atomic_t vbl_received; /**< Number of vblanks received. */
31129+ atomic_unchecked_t vbl_received; /**< Number of vblanks received. */
31130 wait_queue_head_t fence_queue;
31131- atomic_t last_fence_retired;
31132+ atomic_unchecked_t last_fence_retired;
31133 u32 next_fence_to_post;
31134
31135 unsigned int fb_cpp;
31136diff --git a/drivers/gpu/drm/mga/mga_irq.c b/drivers/gpu/drm/mga/mga_irq.c
31137index 2581202..f230a8d9 100644
31138--- a/drivers/gpu/drm/mga/mga_irq.c
31139+++ b/drivers/gpu/drm/mga/mga_irq.c
31140@@ -44,7 +44,7 @@ u32 mga_get_vblank_counter(struct drm_device *dev, int crtc)
31141 if (crtc != 0)
31142 return 0;
31143
31144- return atomic_read(&dev_priv->vbl_received);
31145+ return atomic_read_unchecked(&dev_priv->vbl_received);
31146 }
31147
31148
31149@@ -60,7 +60,7 @@ irqreturn_t mga_driver_irq_handler(DRM_IRQ_ARGS)
31150 /* VBLANK interrupt */
31151 if (status & MGA_VLINEPEN) {
31152 MGA_WRITE(MGA_ICLEAR, MGA_VLINEICLR);
31153- atomic_inc(&dev_priv->vbl_received);
31154+ atomic_inc_unchecked(&dev_priv->vbl_received);
31155 drm_handle_vblank(dev, 0);
31156 handled = 1;
31157 }
31158@@ -79,7 +79,7 @@ irqreturn_t mga_driver_irq_handler(DRM_IRQ_ARGS)
31159 if ((prim_start & ~0x03) != (prim_end & ~0x03))
31160 MGA_WRITE(MGA_PRIMEND, prim_end);
31161
31162- atomic_inc(&dev_priv->last_fence_retired);
31163+ atomic_inc_unchecked(&dev_priv->last_fence_retired);
31164 DRM_WAKEUP(&dev_priv->fence_queue);
31165 handled = 1;
31166 }
31167@@ -130,7 +130,7 @@ int mga_driver_fence_wait(struct drm_device *dev, unsigned int *sequence)
31168 * using fences.
31169 */
31170 DRM_WAIT_ON(ret, dev_priv->fence_queue, 3 * DRM_HZ,
31171- (((cur_fence = atomic_read(&dev_priv->last_fence_retired))
31172+ (((cur_fence = atomic_read_unchecked(&dev_priv->last_fence_retired))
31173 - *sequence) <= (1 << 23)));
31174
31175 *sequence = cur_fence;
31176diff --git a/drivers/gpu/drm/nouveau/nouveau_bios.c b/drivers/gpu/drm/nouveau/nouveau_bios.c
31177index a0a3fe3..209bf10 100644
31178--- a/drivers/gpu/drm/nouveau/nouveau_bios.c
31179+++ b/drivers/gpu/drm/nouveau/nouveau_bios.c
31180@@ -5340,7 +5340,7 @@ parse_bit_U_tbl_entry(struct drm_device *dev, struct nvbios *bios,
31181 struct bit_table {
31182 const char id;
31183 int (* const parse_fn)(struct drm_device *, struct nvbios *, struct bit_entry *);
31184-};
31185+} __no_const;
31186
31187 #define BIT_TABLE(id, funcid) ((struct bit_table){ id, parse_bit_##funcid##_tbl_entry })
31188
31189diff --git a/drivers/gpu/drm/nouveau/nouveau_drv.h b/drivers/gpu/drm/nouveau/nouveau_drv.h
31190index 4f2cc95..9c6c510 100644
31191--- a/drivers/gpu/drm/nouveau/nouveau_drv.h
31192+++ b/drivers/gpu/drm/nouveau/nouveau_drv.h
31193@@ -302,7 +302,7 @@ struct nouveau_exec_engine {
31194 u32 handle, u16 class);
31195 void (*set_tile_region)(struct drm_device *dev, int i);
31196 void (*tlb_flush)(struct drm_device *, int engine);
31197-};
31198+} __no_const;
31199
31200 struct nouveau_instmem_engine {
31201 void *priv;
31202@@ -324,13 +324,13 @@ struct nouveau_instmem_engine {
31203 struct nouveau_mc_engine {
31204 int (*init)(struct drm_device *dev);
31205 void (*takedown)(struct drm_device *dev);
31206-};
31207+} __no_const;
31208
31209 struct nouveau_timer_engine {
31210 int (*init)(struct drm_device *dev);
31211 void (*takedown)(struct drm_device *dev);
31212 uint64_t (*read)(struct drm_device *dev);
31213-};
31214+} __no_const;
31215
31216 struct nouveau_fb_engine {
31217 int num_tiles;
31218@@ -547,7 +547,7 @@ struct nouveau_vram_engine {
31219 void (*put)(struct drm_device *, struct nouveau_mem **);
31220
31221 bool (*flags_valid)(struct drm_device *, u32 tile_flags);
31222-};
31223+} __no_const;
31224
31225 struct nouveau_engine {
31226 struct nouveau_instmem_engine instmem;
31227@@ -693,7 +693,7 @@ struct drm_nouveau_private {
31228 struct drm_global_reference mem_global_ref;
31229 struct ttm_bo_global_ref bo_global_ref;
31230 struct ttm_bo_device bdev;
31231- atomic_t validate_sequence;
31232+ atomic_unchecked_t validate_sequence;
31233 int (*move)(struct nouveau_channel *,
31234 struct ttm_buffer_object *,
31235 struct ttm_mem_reg *, struct ttm_mem_reg *);
31236diff --git a/drivers/gpu/drm/nouveau/nouveau_gem.c b/drivers/gpu/drm/nouveau/nouveau_gem.c
31237index af7cfb8..aadc2a3 100644
31238--- a/drivers/gpu/drm/nouveau/nouveau_gem.c
31239+++ b/drivers/gpu/drm/nouveau/nouveau_gem.c
31240@@ -318,7 +318,7 @@ validate_init(struct nouveau_channel *chan, struct drm_file *file_priv,
31241 int trycnt = 0;
31242 int ret, i;
31243
31244- sequence = atomic_add_return(1, &dev_priv->ttm.validate_sequence);
31245+ sequence = atomic_add_return_unchecked(1, &dev_priv->ttm.validate_sequence);
31246 retry:
31247 if (++trycnt > 100000) {
31248 NV_ERROR(dev, "%s failed and gave up.\n", __func__);
31249diff --git a/drivers/gpu/drm/nouveau/nouveau_state.c b/drivers/gpu/drm/nouveau/nouveau_state.c
31250index f5e9584..05934ba 100644
31251--- a/drivers/gpu/drm/nouveau/nouveau_state.c
31252+++ b/drivers/gpu/drm/nouveau/nouveau_state.c
31253@@ -492,7 +492,7 @@ static bool nouveau_switcheroo_can_switch(struct pci_dev *pdev)
31254 bool can_switch;
31255
31256 spin_lock(&dev->count_lock);
31257- can_switch = (dev->open_count == 0);
31258+ can_switch = (local_read(&dev->open_count) == 0);
31259 spin_unlock(&dev->count_lock);
31260 return can_switch;
31261 }
31262diff --git a/drivers/gpu/drm/nouveau/nv50_sor.c b/drivers/gpu/drm/nouveau/nv50_sor.c
31263index 93240bd..c490f60 100644
31264--- a/drivers/gpu/drm/nouveau/nv50_sor.c
31265+++ b/drivers/gpu/drm/nouveau/nv50_sor.c
31266@@ -304,7 +304,7 @@ nv50_sor_dpms(struct drm_encoder *encoder, int mode)
31267 }
31268
31269 if (nv_encoder->dcb->type == OUTPUT_DP) {
31270- struct dp_train_func func = {
31271+ static struct dp_train_func func = {
31272 .link_set = nv50_sor_dp_link_set,
31273 .train_set = nv50_sor_dp_train_set,
31274 .train_adj = nv50_sor_dp_train_adj
31275diff --git a/drivers/gpu/drm/nouveau/nvd0_display.c b/drivers/gpu/drm/nouveau/nvd0_display.c
31276index 8a2fc89..3a5cf40 100644
31277--- a/drivers/gpu/drm/nouveau/nvd0_display.c
31278+++ b/drivers/gpu/drm/nouveau/nvd0_display.c
31279@@ -1367,7 +1367,7 @@ nvd0_sor_dpms(struct drm_encoder *encoder, int mode)
31280 nv_wait(dev, 0x61c030 + (or * 0x0800), 0x10000000, 0x00000000);
31281
31282 if (nv_encoder->dcb->type == OUTPUT_DP) {
31283- struct dp_train_func func = {
31284+ static struct dp_train_func func = {
31285 .link_set = nvd0_sor_dp_link_set,
31286 .train_set = nvd0_sor_dp_train_set,
31287 .train_adj = nvd0_sor_dp_train_adj
31288diff --git a/drivers/gpu/drm/r128/r128_cce.c b/drivers/gpu/drm/r128/r128_cce.c
31289index bcac90b..53bfc76 100644
31290--- a/drivers/gpu/drm/r128/r128_cce.c
31291+++ b/drivers/gpu/drm/r128/r128_cce.c
31292@@ -378,7 +378,7 @@ static int r128_do_init_cce(struct drm_device *dev, drm_r128_init_t *init)
31293
31294 /* GH: Simple idle check.
31295 */
31296- atomic_set(&dev_priv->idle_count, 0);
31297+ atomic_set_unchecked(&dev_priv->idle_count, 0);
31298
31299 /* We don't support anything other than bus-mastering ring mode,
31300 * but the ring can be in either AGP or PCI space for the ring
31301diff --git a/drivers/gpu/drm/r128/r128_drv.h b/drivers/gpu/drm/r128/r128_drv.h
31302index 930c71b..499aded 100644
31303--- a/drivers/gpu/drm/r128/r128_drv.h
31304+++ b/drivers/gpu/drm/r128/r128_drv.h
31305@@ -90,14 +90,14 @@ typedef struct drm_r128_private {
31306 int is_pci;
31307 unsigned long cce_buffers_offset;
31308
31309- atomic_t idle_count;
31310+ atomic_unchecked_t idle_count;
31311
31312 int page_flipping;
31313 int current_page;
31314 u32 crtc_offset;
31315 u32 crtc_offset_cntl;
31316
31317- atomic_t vbl_received;
31318+ atomic_unchecked_t vbl_received;
31319
31320 u32 color_fmt;
31321 unsigned int front_offset;
31322diff --git a/drivers/gpu/drm/r128/r128_irq.c b/drivers/gpu/drm/r128/r128_irq.c
31323index 429d5a0..7e899ed 100644
31324--- a/drivers/gpu/drm/r128/r128_irq.c
31325+++ b/drivers/gpu/drm/r128/r128_irq.c
31326@@ -42,7 +42,7 @@ u32 r128_get_vblank_counter(struct drm_device *dev, int crtc)
31327 if (crtc != 0)
31328 return 0;
31329
31330- return atomic_read(&dev_priv->vbl_received);
31331+ return atomic_read_unchecked(&dev_priv->vbl_received);
31332 }
31333
31334 irqreturn_t r128_driver_irq_handler(DRM_IRQ_ARGS)
31335@@ -56,7 +56,7 @@ irqreturn_t r128_driver_irq_handler(DRM_IRQ_ARGS)
31336 /* VBLANK interrupt */
31337 if (status & R128_CRTC_VBLANK_INT) {
31338 R128_WRITE(R128_GEN_INT_STATUS, R128_CRTC_VBLANK_INT_AK);
31339- atomic_inc(&dev_priv->vbl_received);
31340+ atomic_inc_unchecked(&dev_priv->vbl_received);
31341 drm_handle_vblank(dev, 0);
31342 return IRQ_HANDLED;
31343 }
31344diff --git a/drivers/gpu/drm/r128/r128_state.c b/drivers/gpu/drm/r128/r128_state.c
31345index a9e33ce..09edd4b 100644
31346--- a/drivers/gpu/drm/r128/r128_state.c
31347+++ b/drivers/gpu/drm/r128/r128_state.c
31348@@ -321,10 +321,10 @@ static void r128_clear_box(drm_r128_private_t *dev_priv,
31349
31350 static void r128_cce_performance_boxes(drm_r128_private_t *dev_priv)
31351 {
31352- if (atomic_read(&dev_priv->idle_count) == 0)
31353+ if (atomic_read_unchecked(&dev_priv->idle_count) == 0)
31354 r128_clear_box(dev_priv, 64, 4, 8, 8, 0, 255, 0);
31355 else
31356- atomic_set(&dev_priv->idle_count, 0);
31357+ atomic_set_unchecked(&dev_priv->idle_count, 0);
31358 }
31359
31360 #endif
31361diff --git a/drivers/gpu/drm/radeon/mkregtable.c b/drivers/gpu/drm/radeon/mkregtable.c
31362index 5a82b6b..9e69c73 100644
31363--- a/drivers/gpu/drm/radeon/mkregtable.c
31364+++ b/drivers/gpu/drm/radeon/mkregtable.c
31365@@ -637,14 +637,14 @@ static int parser_auth(struct table *t, const char *filename)
31366 regex_t mask_rex;
31367 regmatch_t match[4];
31368 char buf[1024];
31369- size_t end;
31370+ long end;
31371 int len;
31372 int done = 0;
31373 int r;
31374 unsigned o;
31375 struct offset *offset;
31376 char last_reg_s[10];
31377- int last_reg;
31378+ unsigned long last_reg;
31379
31380 if (regcomp
31381 (&mask_rex, "(0x[0-9a-fA-F]*) *([_a-zA-Z0-9]*)", REG_EXTENDED)) {
31382diff --git a/drivers/gpu/drm/radeon/radeon.h b/drivers/gpu/drm/radeon/radeon.h
31383index 59a1531..3bab49b 100644
31384--- a/drivers/gpu/drm/radeon/radeon.h
31385+++ b/drivers/gpu/drm/radeon/radeon.h
31386@@ -711,7 +711,7 @@ struct r600_blit_cp_primitives {
31387 int x2, int y2);
31388 void (*draw_auto)(struct radeon_device *rdev);
31389 void (*set_default_state)(struct radeon_device *rdev);
31390-};
31391+} __no_const;
31392
31393 struct r600_blit {
31394 struct radeon_bo *shader_obj;
31395@@ -1216,7 +1216,7 @@ struct radeon_asic {
31396 u32 (*page_flip)(struct radeon_device *rdev, int crtc, u64 crtc_base);
31397 void (*post_page_flip)(struct radeon_device *rdev, int crtc);
31398 } pflip;
31399-};
31400+} __no_const;
31401
31402 /*
31403 * Asic structures
31404diff --git a/drivers/gpu/drm/radeon/radeon_device.c b/drivers/gpu/drm/radeon/radeon_device.c
31405index 7a3daeb..5016171 100644
31406--- a/drivers/gpu/drm/radeon/radeon_device.c
31407+++ b/drivers/gpu/drm/radeon/radeon_device.c
31408@@ -952,7 +952,7 @@ static bool radeon_switcheroo_can_switch(struct pci_dev *pdev)
31409 bool can_switch;
31410
31411 spin_lock(&dev->count_lock);
31412- can_switch = (dev->open_count == 0);
31413+ can_switch = (local_read(&dev->open_count) == 0);
31414 spin_unlock(&dev->count_lock);
31415 return can_switch;
31416 }
31417diff --git a/drivers/gpu/drm/radeon/radeon_drv.h b/drivers/gpu/drm/radeon/radeon_drv.h
31418index a1b59ca..86f2d44 100644
31419--- a/drivers/gpu/drm/radeon/radeon_drv.h
31420+++ b/drivers/gpu/drm/radeon/radeon_drv.h
31421@@ -255,7 +255,7 @@ typedef struct drm_radeon_private {
31422
31423 /* SW interrupt */
31424 wait_queue_head_t swi_queue;
31425- atomic_t swi_emitted;
31426+ atomic_unchecked_t swi_emitted;
31427 int vblank_crtc;
31428 uint32_t irq_enable_reg;
31429 uint32_t r500_disp_irq_reg;
31430diff --git a/drivers/gpu/drm/radeon/radeon_ioc32.c b/drivers/gpu/drm/radeon/radeon_ioc32.c
31431index 48b7cea..342236f 100644
31432--- a/drivers/gpu/drm/radeon/radeon_ioc32.c
31433+++ b/drivers/gpu/drm/radeon/radeon_ioc32.c
31434@@ -359,7 +359,7 @@ static int compat_radeon_cp_setparam(struct file *file, unsigned int cmd,
31435 request = compat_alloc_user_space(sizeof(*request));
31436 if (!access_ok(VERIFY_WRITE, request, sizeof(*request))
31437 || __put_user(req32.param, &request->param)
31438- || __put_user((void __user *)(unsigned long)req32.value,
31439+ || __put_user((unsigned long)req32.value,
31440 &request->value))
31441 return -EFAULT;
31442
31443diff --git a/drivers/gpu/drm/radeon/radeon_irq.c b/drivers/gpu/drm/radeon/radeon_irq.c
31444index 00da384..32f972d 100644
31445--- a/drivers/gpu/drm/radeon/radeon_irq.c
31446+++ b/drivers/gpu/drm/radeon/radeon_irq.c
31447@@ -225,8 +225,8 @@ static int radeon_emit_irq(struct drm_device * dev)
31448 unsigned int ret;
31449 RING_LOCALS;
31450
31451- atomic_inc(&dev_priv->swi_emitted);
31452- ret = atomic_read(&dev_priv->swi_emitted);
31453+ atomic_inc_unchecked(&dev_priv->swi_emitted);
31454+ ret = atomic_read_unchecked(&dev_priv->swi_emitted);
31455
31456 BEGIN_RING(4);
31457 OUT_RING_REG(RADEON_LAST_SWI_REG, ret);
31458@@ -352,7 +352,7 @@ int radeon_driver_irq_postinstall(struct drm_device *dev)
31459 drm_radeon_private_t *dev_priv =
31460 (drm_radeon_private_t *) dev->dev_private;
31461
31462- atomic_set(&dev_priv->swi_emitted, 0);
31463+ atomic_set_unchecked(&dev_priv->swi_emitted, 0);
31464 DRM_INIT_WAITQUEUE(&dev_priv->swi_queue);
31465
31466 dev->max_vblank_count = 0x001fffff;
31467diff --git a/drivers/gpu/drm/radeon/radeon_state.c b/drivers/gpu/drm/radeon/radeon_state.c
31468index e8422ae..d22d4a8 100644
31469--- a/drivers/gpu/drm/radeon/radeon_state.c
31470+++ b/drivers/gpu/drm/radeon/radeon_state.c
31471@@ -2168,7 +2168,7 @@ static int radeon_cp_clear(struct drm_device *dev, void *data, struct drm_file *
31472 if (sarea_priv->nbox > RADEON_NR_SAREA_CLIPRECTS)
31473 sarea_priv->nbox = RADEON_NR_SAREA_CLIPRECTS;
31474
31475- if (DRM_COPY_FROM_USER(&depth_boxes, clear->depth_boxes,
31476+ if (sarea_priv->nbox > RADEON_NR_SAREA_CLIPRECTS || DRM_COPY_FROM_USER(&depth_boxes, clear->depth_boxes,
31477 sarea_priv->nbox * sizeof(depth_boxes[0])))
31478 return -EFAULT;
31479
31480@@ -3031,7 +3031,7 @@ static int radeon_cp_getparam(struct drm_device *dev, void *data, struct drm_fil
31481 {
31482 drm_radeon_private_t *dev_priv = dev->dev_private;
31483 drm_radeon_getparam_t *param = data;
31484- int value;
31485+ int value = 0;
31486
31487 DRM_DEBUG("pid=%d\n", DRM_CURRENTPID);
31488
31489diff --git a/drivers/gpu/drm/radeon/radeon_ttm.c b/drivers/gpu/drm/radeon/radeon_ttm.c
31490index 5b71c71..650f9e4 100644
31491--- a/drivers/gpu/drm/radeon/radeon_ttm.c
31492+++ b/drivers/gpu/drm/radeon/radeon_ttm.c
31493@@ -822,8 +822,10 @@ int radeon_mmap(struct file *filp, struct vm_area_struct *vma)
31494 }
31495 if (unlikely(ttm_vm_ops == NULL)) {
31496 ttm_vm_ops = vma->vm_ops;
31497- radeon_ttm_vm_ops = *ttm_vm_ops;
31498- radeon_ttm_vm_ops.fault = &radeon_ttm_fault;
31499+ pax_open_kernel();
31500+ memcpy((void *)&radeon_ttm_vm_ops, ttm_vm_ops, sizeof(radeon_ttm_vm_ops));
31501+ *(void **)&radeon_ttm_vm_ops.fault = &radeon_ttm_fault;
31502+ pax_close_kernel();
31503 }
31504 vma->vm_ops = &radeon_ttm_vm_ops;
31505 return 0;
31506diff --git a/drivers/gpu/drm/radeon/rs690.c b/drivers/gpu/drm/radeon/rs690.c
31507index 3b663fc..57850f4 100644
31508--- a/drivers/gpu/drm/radeon/rs690.c
31509+++ b/drivers/gpu/drm/radeon/rs690.c
31510@@ -304,9 +304,11 @@ void rs690_crtc_bandwidth_compute(struct radeon_device *rdev,
31511 if (rdev->pm.max_bandwidth.full > rdev->pm.sideport_bandwidth.full &&
31512 rdev->pm.sideport_bandwidth.full)
31513 rdev->pm.max_bandwidth = rdev->pm.sideport_bandwidth;
31514- read_delay_latency.full = dfixed_const(370 * 800 * 1000);
31515+ read_delay_latency.full = dfixed_const(800 * 1000);
31516 read_delay_latency.full = dfixed_div(read_delay_latency,
31517 rdev->pm.igp_sideport_mclk);
31518+ a.full = dfixed_const(370);
31519+ read_delay_latency.full = dfixed_mul(read_delay_latency, a);
31520 } else {
31521 if (rdev->pm.max_bandwidth.full > rdev->pm.k8_bandwidth.full &&
31522 rdev->pm.k8_bandwidth.full)
31523diff --git a/drivers/gpu/drm/ttm/ttm_page_alloc.c b/drivers/gpu/drm/ttm/ttm_page_alloc.c
31524index 578207e..1073f25 100644
31525--- a/drivers/gpu/drm/ttm/ttm_page_alloc.c
31526+++ b/drivers/gpu/drm/ttm/ttm_page_alloc.c
31527@@ -394,9 +394,9 @@ static int ttm_pool_get_num_unused_pages(void)
31528 static int ttm_pool_mm_shrink(struct shrinker *shrink,
31529 struct shrink_control *sc)
31530 {
31531- static atomic_t start_pool = ATOMIC_INIT(0);
31532+ static atomic_unchecked_t start_pool = ATOMIC_INIT(0);
31533 unsigned i;
31534- unsigned pool_offset = atomic_add_return(1, &start_pool);
31535+ unsigned pool_offset = atomic_add_return_unchecked(1, &start_pool);
31536 struct ttm_page_pool *pool;
31537 int shrink_pages = sc->nr_to_scan;
31538
31539diff --git a/drivers/gpu/drm/via/via_drv.h b/drivers/gpu/drm/via/via_drv.h
31540index 88edacc..1e5412b 100644
31541--- a/drivers/gpu/drm/via/via_drv.h
31542+++ b/drivers/gpu/drm/via/via_drv.h
31543@@ -51,7 +51,7 @@ typedef struct drm_via_ring_buffer {
31544 typedef uint32_t maskarray_t[5];
31545
31546 typedef struct drm_via_irq {
31547- atomic_t irq_received;
31548+ atomic_unchecked_t irq_received;
31549 uint32_t pending_mask;
31550 uint32_t enable_mask;
31551 wait_queue_head_t irq_queue;
31552@@ -75,7 +75,7 @@ typedef struct drm_via_private {
31553 struct timeval last_vblank;
31554 int last_vblank_valid;
31555 unsigned usec_per_vblank;
31556- atomic_t vbl_received;
31557+ atomic_unchecked_t vbl_received;
31558 drm_via_state_t hc_state;
31559 char pci_buf[VIA_PCI_BUF_SIZE];
31560 const uint32_t *fire_offsets[VIA_FIRE_BUF_SIZE];
31561diff --git a/drivers/gpu/drm/via/via_irq.c b/drivers/gpu/drm/via/via_irq.c
31562index d391f48..10c8ca3 100644
31563--- a/drivers/gpu/drm/via/via_irq.c
31564+++ b/drivers/gpu/drm/via/via_irq.c
31565@@ -102,7 +102,7 @@ u32 via_get_vblank_counter(struct drm_device *dev, int crtc)
31566 if (crtc != 0)
31567 return 0;
31568
31569- return atomic_read(&dev_priv->vbl_received);
31570+ return atomic_read_unchecked(&dev_priv->vbl_received);
31571 }
31572
31573 irqreturn_t via_driver_irq_handler(DRM_IRQ_ARGS)
31574@@ -117,8 +117,8 @@ irqreturn_t via_driver_irq_handler(DRM_IRQ_ARGS)
31575
31576 status = VIA_READ(VIA_REG_INTERRUPT);
31577 if (status & VIA_IRQ_VBLANK_PENDING) {
31578- atomic_inc(&dev_priv->vbl_received);
31579- if (!(atomic_read(&dev_priv->vbl_received) & 0x0F)) {
31580+ atomic_inc_unchecked(&dev_priv->vbl_received);
31581+ if (!(atomic_read_unchecked(&dev_priv->vbl_received) & 0x0F)) {
31582 do_gettimeofday(&cur_vblank);
31583 if (dev_priv->last_vblank_valid) {
31584 dev_priv->usec_per_vblank =
31585@@ -128,7 +128,7 @@ irqreturn_t via_driver_irq_handler(DRM_IRQ_ARGS)
31586 dev_priv->last_vblank = cur_vblank;
31587 dev_priv->last_vblank_valid = 1;
31588 }
31589- if (!(atomic_read(&dev_priv->vbl_received) & 0xFF)) {
31590+ if (!(atomic_read_unchecked(&dev_priv->vbl_received) & 0xFF)) {
31591 DRM_DEBUG("US per vblank is: %u\n",
31592 dev_priv->usec_per_vblank);
31593 }
31594@@ -138,7 +138,7 @@ irqreturn_t via_driver_irq_handler(DRM_IRQ_ARGS)
31595
31596 for (i = 0; i < dev_priv->num_irqs; ++i) {
31597 if (status & cur_irq->pending_mask) {
31598- atomic_inc(&cur_irq->irq_received);
31599+ atomic_inc_unchecked(&cur_irq->irq_received);
31600 DRM_WAKEUP(&cur_irq->irq_queue);
31601 handled = 1;
31602 if (dev_priv->irq_map[drm_via_irq_dma0_td] == i)
31603@@ -243,11 +243,11 @@ via_driver_irq_wait(struct drm_device *dev, unsigned int irq, int force_sequence
31604 DRM_WAIT_ON(ret, cur_irq->irq_queue, 3 * DRM_HZ,
31605 ((VIA_READ(masks[irq][2]) & masks[irq][3]) ==
31606 masks[irq][4]));
31607- cur_irq_sequence = atomic_read(&cur_irq->irq_received);
31608+ cur_irq_sequence = atomic_read_unchecked(&cur_irq->irq_received);
31609 } else {
31610 DRM_WAIT_ON(ret, cur_irq->irq_queue, 3 * DRM_HZ,
31611 (((cur_irq_sequence =
31612- atomic_read(&cur_irq->irq_received)) -
31613+ atomic_read_unchecked(&cur_irq->irq_received)) -
31614 *sequence) <= (1 << 23)));
31615 }
31616 *sequence = cur_irq_sequence;
31617@@ -285,7 +285,7 @@ void via_driver_irq_preinstall(struct drm_device *dev)
31618 }
31619
31620 for (i = 0; i < dev_priv->num_irqs; ++i) {
31621- atomic_set(&cur_irq->irq_received, 0);
31622+ atomic_set_unchecked(&cur_irq->irq_received, 0);
31623 cur_irq->enable_mask = dev_priv->irq_masks[i][0];
31624 cur_irq->pending_mask = dev_priv->irq_masks[i][1];
31625 DRM_INIT_WAITQUEUE(&cur_irq->irq_queue);
31626@@ -367,7 +367,7 @@ int via_wait_irq(struct drm_device *dev, void *data, struct drm_file *file_priv)
31627 switch (irqwait->request.type & ~VIA_IRQ_FLAGS_MASK) {
31628 case VIA_IRQ_RELATIVE:
31629 irqwait->request.sequence +=
31630- atomic_read(&cur_irq->irq_received);
31631+ atomic_read_unchecked(&cur_irq->irq_received);
31632 irqwait->request.type &= ~_DRM_VBLANK_RELATIVE;
31633 case VIA_IRQ_ABSOLUTE:
31634 break;
31635diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h b/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
31636index 29c984f..4084f1a 100644
31637--- a/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
31638+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
31639@@ -263,7 +263,7 @@ struct vmw_private {
31640 * Fencing and IRQs.
31641 */
31642
31643- atomic_t marker_seq;
31644+ atomic_unchecked_t marker_seq;
31645 wait_queue_head_t fence_queue;
31646 wait_queue_head_t fifo_queue;
31647 int fence_queue_waiters; /* Protected by hw_mutex */
31648diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c b/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c
31649index a0c2f12..68ae6cb 100644
31650--- a/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c
31651+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c
31652@@ -137,7 +137,7 @@ int vmw_fifo_init(struct vmw_private *dev_priv, struct vmw_fifo_state *fifo)
31653 (unsigned int) min,
31654 (unsigned int) fifo->capabilities);
31655
31656- atomic_set(&dev_priv->marker_seq, dev_priv->last_read_seqno);
31657+ atomic_set_unchecked(&dev_priv->marker_seq, dev_priv->last_read_seqno);
31658 iowrite32(dev_priv->last_read_seqno, fifo_mem + SVGA_FIFO_FENCE);
31659 vmw_marker_queue_init(&fifo->marker_queue);
31660 return vmw_fifo_send_fence(dev_priv, &dummy);
31661@@ -355,7 +355,7 @@ void *vmw_fifo_reserve(struct vmw_private *dev_priv, uint32_t bytes)
31662 if (reserveable)
31663 iowrite32(bytes, fifo_mem +
31664 SVGA_FIFO_RESERVED);
31665- return fifo_mem + (next_cmd >> 2);
31666+ return (__le32 __force_kernel *)fifo_mem + (next_cmd >> 2);
31667 } else {
31668 need_bounce = true;
31669 }
31670@@ -475,7 +475,7 @@ int vmw_fifo_send_fence(struct vmw_private *dev_priv, uint32_t *seqno)
31671
31672 fm = vmw_fifo_reserve(dev_priv, bytes);
31673 if (unlikely(fm == NULL)) {
31674- *seqno = atomic_read(&dev_priv->marker_seq);
31675+ *seqno = atomic_read_unchecked(&dev_priv->marker_seq);
31676 ret = -ENOMEM;
31677 (void)vmw_fallback_wait(dev_priv, false, true, *seqno,
31678 false, 3*HZ);
31679@@ -483,7 +483,7 @@ int vmw_fifo_send_fence(struct vmw_private *dev_priv, uint32_t *seqno)
31680 }
31681
31682 do {
31683- *seqno = atomic_add_return(1, &dev_priv->marker_seq);
31684+ *seqno = atomic_add_return_unchecked(1, &dev_priv->marker_seq);
31685 } while (*seqno == 0);
31686
31687 if (!(fifo_state->capabilities & SVGA_FIFO_CAP_FENCE)) {
31688diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c b/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c
31689index cabc95f..14b3d77 100644
31690--- a/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c
31691+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c
31692@@ -107,7 +107,7 @@ bool vmw_seqno_passed(struct vmw_private *dev_priv,
31693 * emitted. Then the fence is stale and signaled.
31694 */
31695
31696- ret = ((atomic_read(&dev_priv->marker_seq) - seqno)
31697+ ret = ((atomic_read_unchecked(&dev_priv->marker_seq) - seqno)
31698 > VMW_FENCE_WRAP);
31699
31700 return ret;
31701@@ -138,7 +138,7 @@ int vmw_fallback_wait(struct vmw_private *dev_priv,
31702
31703 if (fifo_idle)
31704 down_read(&fifo_state->rwsem);
31705- signal_seq = atomic_read(&dev_priv->marker_seq);
31706+ signal_seq = atomic_read_unchecked(&dev_priv->marker_seq);
31707 ret = 0;
31708
31709 for (;;) {
31710diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c b/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c
31711index 8a8725c..afed796 100644
31712--- a/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c
31713+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c
31714@@ -151,7 +151,7 @@ int vmw_wait_lag(struct vmw_private *dev_priv,
31715 while (!vmw_lag_lt(queue, us)) {
31716 spin_lock(&queue->lock);
31717 if (list_empty(&queue->head))
31718- seqno = atomic_read(&dev_priv->marker_seq);
31719+ seqno = atomic_read_unchecked(&dev_priv->marker_seq);
31720 else {
31721 marker = list_first_entry(&queue->head,
31722 struct vmw_marker, head);
31723diff --git a/drivers/hid/hid-core.c b/drivers/hid/hid-core.c
31724index 5de3bb3..08e5063 100644
31725--- a/drivers/hid/hid-core.c
31726+++ b/drivers/hid/hid-core.c
31727@@ -2177,7 +2177,7 @@ static bool hid_ignore(struct hid_device *hdev)
31728
31729 int hid_add_device(struct hid_device *hdev)
31730 {
31731- static atomic_t id = ATOMIC_INIT(0);
31732+ static atomic_unchecked_t id = ATOMIC_INIT(0);
31733 int ret;
31734
31735 if (WARN_ON(hdev->status & HID_STAT_ADDED))
31736@@ -2212,7 +2212,7 @@ int hid_add_device(struct hid_device *hdev)
31737 /* XXX hack, any other cleaner solution after the driver core
31738 * is converted to allow more than 20 bytes as the device name? */
31739 dev_set_name(&hdev->dev, "%04X:%04X:%04X.%04X", hdev->bus,
31740- hdev->vendor, hdev->product, atomic_inc_return(&id));
31741+ hdev->vendor, hdev->product, atomic_inc_return_unchecked(&id));
31742
31743 hid_debug_register(hdev, dev_name(&hdev->dev));
31744 ret = device_add(&hdev->dev);
31745diff --git a/drivers/hid/hid-wiimote-debug.c b/drivers/hid/hid-wiimote-debug.c
31746index eec3291..8ed706b 100644
31747--- a/drivers/hid/hid-wiimote-debug.c
31748+++ b/drivers/hid/hid-wiimote-debug.c
31749@@ -66,7 +66,7 @@ static ssize_t wiidebug_eeprom_read(struct file *f, char __user *u, size_t s,
31750 else if (size == 0)
31751 return -EIO;
31752
31753- if (copy_to_user(u, buf, size))
31754+ if (size > sizeof(buf) || copy_to_user(u, buf, size))
31755 return -EFAULT;
31756
31757 *off += size;
31758diff --git a/drivers/hid/usbhid/hiddev.c b/drivers/hid/usbhid/hiddev.c
31759index 14599e2..711c965 100644
31760--- a/drivers/hid/usbhid/hiddev.c
31761+++ b/drivers/hid/usbhid/hiddev.c
31762@@ -625,7 +625,7 @@ static long hiddev_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
31763 break;
31764
31765 case HIDIOCAPPLICATION:
31766- if (arg < 0 || arg >= hid->maxapplication)
31767+ if (arg >= hid->maxapplication)
31768 break;
31769
31770 for (i = 0; i < hid->maxcollection; i++)
31771diff --git a/drivers/hv/channel.c b/drivers/hv/channel.c
31772index f4c3d28..82f45a9 100644
31773--- a/drivers/hv/channel.c
31774+++ b/drivers/hv/channel.c
31775@@ -402,8 +402,8 @@ int vmbus_establish_gpadl(struct vmbus_channel *channel, void *kbuffer,
31776 int ret = 0;
31777 int t;
31778
31779- next_gpadl_handle = atomic_read(&vmbus_connection.next_gpadl_handle);
31780- atomic_inc(&vmbus_connection.next_gpadl_handle);
31781+ next_gpadl_handle = atomic_read_unchecked(&vmbus_connection.next_gpadl_handle);
31782+ atomic_inc_unchecked(&vmbus_connection.next_gpadl_handle);
31783
31784 ret = create_gpadl_header(kbuffer, size, &msginfo, &msgcount);
31785 if (ret)
31786diff --git a/drivers/hv/hv.c b/drivers/hv/hv.c
31787index 86f8885..ab9cb2b 100644
31788--- a/drivers/hv/hv.c
31789+++ b/drivers/hv/hv.c
31790@@ -132,7 +132,7 @@ static u64 do_hypercall(u64 control, void *input, void *output)
31791 u64 output_address = (output) ? virt_to_phys(output) : 0;
31792 u32 output_address_hi = output_address >> 32;
31793 u32 output_address_lo = output_address & 0xFFFFFFFF;
31794- void *hypercall_page = hv_context.hypercall_page;
31795+ void *hypercall_page = ktva_ktla(hv_context.hypercall_page);
31796
31797 __asm__ __volatile__ ("call *%8" : "=d"(hv_status_hi),
31798 "=a"(hv_status_lo) : "d" (control_hi),
31799diff --git a/drivers/hv/hyperv_vmbus.h b/drivers/hv/hyperv_vmbus.h
31800index 0614ff3..f0b2b5c 100644
31801--- a/drivers/hv/hyperv_vmbus.h
31802+++ b/drivers/hv/hyperv_vmbus.h
31803@@ -555,7 +555,7 @@ enum vmbus_connect_state {
31804 struct vmbus_connection {
31805 enum vmbus_connect_state conn_state;
31806
31807- atomic_t next_gpadl_handle;
31808+ atomic_unchecked_t next_gpadl_handle;
31809
31810 /*
31811 * Represents channel interrupts. Each bit position represents a
31812diff --git a/drivers/hv/vmbus_drv.c b/drivers/hv/vmbus_drv.c
31813index 4748086..3abf845 100644
31814--- a/drivers/hv/vmbus_drv.c
31815+++ b/drivers/hv/vmbus_drv.c
31816@@ -662,10 +662,10 @@ int vmbus_device_register(struct hv_device *child_device_obj)
31817 {
31818 int ret = 0;
31819
31820- static atomic_t device_num = ATOMIC_INIT(0);
31821+ static atomic_unchecked_t device_num = ATOMIC_INIT(0);
31822
31823 dev_set_name(&child_device_obj->device, "vmbus_0_%d",
31824- atomic_inc_return(&device_num));
31825+ atomic_inc_return_unchecked(&device_num));
31826
31827 child_device_obj->device.bus = &hv_bus;
31828 child_device_obj->device.parent = &hv_acpi_dev->dev;
31829diff --git a/drivers/hwmon/sht15.c b/drivers/hwmon/sht15.c
31830index 8b011d0..3de24a1 100644
31831--- a/drivers/hwmon/sht15.c
31832+++ b/drivers/hwmon/sht15.c
31833@@ -166,7 +166,7 @@ struct sht15_data {
31834 int supply_uV;
31835 bool supply_uV_valid;
31836 struct work_struct update_supply_work;
31837- atomic_t interrupt_handled;
31838+ atomic_unchecked_t interrupt_handled;
31839 };
31840
31841 /**
31842@@ -509,13 +509,13 @@ static int sht15_measurement(struct sht15_data *data,
31843 return ret;
31844
31845 gpio_direction_input(data->pdata->gpio_data);
31846- atomic_set(&data->interrupt_handled, 0);
31847+ atomic_set_unchecked(&data->interrupt_handled, 0);
31848
31849 enable_irq(gpio_to_irq(data->pdata->gpio_data));
31850 if (gpio_get_value(data->pdata->gpio_data) == 0) {
31851 disable_irq_nosync(gpio_to_irq(data->pdata->gpio_data));
31852 /* Only relevant if the interrupt hasn't occurred. */
31853- if (!atomic_read(&data->interrupt_handled))
31854+ if (!atomic_read_unchecked(&data->interrupt_handled))
31855 schedule_work(&data->read_work);
31856 }
31857 ret = wait_event_timeout(data->wait_queue,
31858@@ -782,7 +782,7 @@ static irqreturn_t sht15_interrupt_fired(int irq, void *d)
31859
31860 /* First disable the interrupt */
31861 disable_irq_nosync(irq);
31862- atomic_inc(&data->interrupt_handled);
31863+ atomic_inc_unchecked(&data->interrupt_handled);
31864 /* Then schedule a reading work struct */
31865 if (data->state != SHT15_READING_NOTHING)
31866 schedule_work(&data->read_work);
31867@@ -804,11 +804,11 @@ static void sht15_bh_read_data(struct work_struct *work_s)
31868 * If not, then start the interrupt again - care here as could
31869 * have gone low in meantime so verify it hasn't!
31870 */
31871- atomic_set(&data->interrupt_handled, 0);
31872+ atomic_set_unchecked(&data->interrupt_handled, 0);
31873 enable_irq(gpio_to_irq(data->pdata->gpio_data));
31874 /* If still not occurred or another handler was scheduled */
31875 if (gpio_get_value(data->pdata->gpio_data)
31876- || atomic_read(&data->interrupt_handled))
31877+ || atomic_read_unchecked(&data->interrupt_handled))
31878 return;
31879 }
31880
31881diff --git a/drivers/i2c/busses/i2c-amd756-s4882.c b/drivers/i2c/busses/i2c-amd756-s4882.c
31882index 378fcb5..5e91fa8 100644
31883--- a/drivers/i2c/busses/i2c-amd756-s4882.c
31884+++ b/drivers/i2c/busses/i2c-amd756-s4882.c
31885@@ -43,7 +43,7 @@
31886 extern struct i2c_adapter amd756_smbus;
31887
31888 static struct i2c_adapter *s4882_adapter;
31889-static struct i2c_algorithm *s4882_algo;
31890+static i2c_algorithm_no_const *s4882_algo;
31891
31892 /* Wrapper access functions for multiplexed SMBus */
31893 static DEFINE_MUTEX(amd756_lock);
31894diff --git a/drivers/i2c/busses/i2c-nforce2-s4985.c b/drivers/i2c/busses/i2c-nforce2-s4985.c
31895index 29015eb..af2d8e9 100644
31896--- a/drivers/i2c/busses/i2c-nforce2-s4985.c
31897+++ b/drivers/i2c/busses/i2c-nforce2-s4985.c
31898@@ -41,7 +41,7 @@
31899 extern struct i2c_adapter *nforce2_smbus;
31900
31901 static struct i2c_adapter *s4985_adapter;
31902-static struct i2c_algorithm *s4985_algo;
31903+static i2c_algorithm_no_const *s4985_algo;
31904
31905 /* Wrapper access functions for multiplexed SMBus */
31906 static DEFINE_MUTEX(nforce2_lock);
31907diff --git a/drivers/i2c/i2c-mux.c b/drivers/i2c/i2c-mux.c
31908index 1038c38..eb92f51 100644
31909--- a/drivers/i2c/i2c-mux.c
31910+++ b/drivers/i2c/i2c-mux.c
31911@@ -30,7 +30,7 @@
31912 /* multiplexer per channel data */
31913 struct i2c_mux_priv {
31914 struct i2c_adapter adap;
31915- struct i2c_algorithm algo;
31916+ i2c_algorithm_no_const algo;
31917
31918 struct i2c_adapter *parent;
31919 void *mux_priv; /* the mux chip/device */
31920diff --git a/drivers/ide/aec62xx.c b/drivers/ide/aec62xx.c
31921index 57d00ca..0145194 100644
31922--- a/drivers/ide/aec62xx.c
31923+++ b/drivers/ide/aec62xx.c
31924@@ -181,7 +181,7 @@ static const struct ide_port_ops atp86x_port_ops = {
31925 .cable_detect = atp86x_cable_detect,
31926 };
31927
31928-static const struct ide_port_info aec62xx_chipsets[] __devinitdata = {
31929+static const struct ide_port_info aec62xx_chipsets[] __devinitconst = {
31930 { /* 0: AEC6210 */
31931 .name = DRV_NAME,
31932 .init_chipset = init_chipset_aec62xx,
31933diff --git a/drivers/ide/alim15x3.c b/drivers/ide/alim15x3.c
31934index 2c8016a..911a27c 100644
31935--- a/drivers/ide/alim15x3.c
31936+++ b/drivers/ide/alim15x3.c
31937@@ -512,7 +512,7 @@ static const struct ide_dma_ops ali_dma_ops = {
31938 .dma_sff_read_status = ide_dma_sff_read_status,
31939 };
31940
31941-static const struct ide_port_info ali15x3_chipset __devinitdata = {
31942+static const struct ide_port_info ali15x3_chipset __devinitconst = {
31943 .name = DRV_NAME,
31944 .init_chipset = init_chipset_ali15x3,
31945 .init_hwif = init_hwif_ali15x3,
31946diff --git a/drivers/ide/amd74xx.c b/drivers/ide/amd74xx.c
31947index 3747b25..56fc995 100644
31948--- a/drivers/ide/amd74xx.c
31949+++ b/drivers/ide/amd74xx.c
31950@@ -223,7 +223,7 @@ static const struct ide_port_ops amd_port_ops = {
31951 .udma_mask = udma, \
31952 }
31953
31954-static const struct ide_port_info amd74xx_chipsets[] __devinitdata = {
31955+static const struct ide_port_info amd74xx_chipsets[] __devinitconst = {
31956 /* 0: AMD7401 */ DECLARE_AMD_DEV(0x00, ATA_UDMA2),
31957 /* 1: AMD7409 */ DECLARE_AMD_DEV(ATA_SWDMA2, ATA_UDMA4),
31958 /* 2: AMD7411/7441 */ DECLARE_AMD_DEV(ATA_SWDMA2, ATA_UDMA5),
31959diff --git a/drivers/ide/atiixp.c b/drivers/ide/atiixp.c
31960index 15f0ead..cb43480 100644
31961--- a/drivers/ide/atiixp.c
31962+++ b/drivers/ide/atiixp.c
31963@@ -139,7 +139,7 @@ static const struct ide_port_ops atiixp_port_ops = {
31964 .cable_detect = atiixp_cable_detect,
31965 };
31966
31967-static const struct ide_port_info atiixp_pci_info[] __devinitdata = {
31968+static const struct ide_port_info atiixp_pci_info[] __devinitconst = {
31969 { /* 0: IXP200/300/400/700 */
31970 .name = DRV_NAME,
31971 .enablebits = {{0x48,0x01,0x00}, {0x48,0x08,0x00}},
31972diff --git a/drivers/ide/cmd64x.c b/drivers/ide/cmd64x.c
31973index 5f80312..d1fc438 100644
31974--- a/drivers/ide/cmd64x.c
31975+++ b/drivers/ide/cmd64x.c
31976@@ -327,7 +327,7 @@ static const struct ide_dma_ops cmd646_rev1_dma_ops = {
31977 .dma_sff_read_status = ide_dma_sff_read_status,
31978 };
31979
31980-static const struct ide_port_info cmd64x_chipsets[] __devinitdata = {
31981+static const struct ide_port_info cmd64x_chipsets[] __devinitconst = {
31982 { /* 0: CMD643 */
31983 .name = DRV_NAME,
31984 .init_chipset = init_chipset_cmd64x,
31985diff --git a/drivers/ide/cs5520.c b/drivers/ide/cs5520.c
31986index 2c1e5f7..1444762 100644
31987--- a/drivers/ide/cs5520.c
31988+++ b/drivers/ide/cs5520.c
31989@@ -94,7 +94,7 @@ static const struct ide_port_ops cs5520_port_ops = {
31990 .set_dma_mode = cs5520_set_dma_mode,
31991 };
31992
31993-static const struct ide_port_info cyrix_chipset __devinitdata = {
31994+static const struct ide_port_info cyrix_chipset __devinitconst = {
31995 .name = DRV_NAME,
31996 .enablebits = { { 0x60, 0x01, 0x01 }, { 0x60, 0x02, 0x02 } },
31997 .port_ops = &cs5520_port_ops,
31998diff --git a/drivers/ide/cs5530.c b/drivers/ide/cs5530.c
31999index 4dc4eb9..49b40ad 100644
32000--- a/drivers/ide/cs5530.c
32001+++ b/drivers/ide/cs5530.c
32002@@ -245,7 +245,7 @@ static const struct ide_port_ops cs5530_port_ops = {
32003 .udma_filter = cs5530_udma_filter,
32004 };
32005
32006-static const struct ide_port_info cs5530_chipset __devinitdata = {
32007+static const struct ide_port_info cs5530_chipset __devinitconst = {
32008 .name = DRV_NAME,
32009 .init_chipset = init_chipset_cs5530,
32010 .init_hwif = init_hwif_cs5530,
32011diff --git a/drivers/ide/cs5535.c b/drivers/ide/cs5535.c
32012index 5059faf..18d4c85 100644
32013--- a/drivers/ide/cs5535.c
32014+++ b/drivers/ide/cs5535.c
32015@@ -170,7 +170,7 @@ static const struct ide_port_ops cs5535_port_ops = {
32016 .cable_detect = cs5535_cable_detect,
32017 };
32018
32019-static const struct ide_port_info cs5535_chipset __devinitdata = {
32020+static const struct ide_port_info cs5535_chipset __devinitconst = {
32021 .name = DRV_NAME,
32022 .port_ops = &cs5535_port_ops,
32023 .host_flags = IDE_HFLAG_SINGLE | IDE_HFLAG_POST_SET_MODE,
32024diff --git a/drivers/ide/cy82c693.c b/drivers/ide/cy82c693.c
32025index 847553f..3ffb49d 100644
32026--- a/drivers/ide/cy82c693.c
32027+++ b/drivers/ide/cy82c693.c
32028@@ -163,7 +163,7 @@ static const struct ide_port_ops cy82c693_port_ops = {
32029 .set_dma_mode = cy82c693_set_dma_mode,
32030 };
32031
32032-static const struct ide_port_info cy82c693_chipset __devinitdata = {
32033+static const struct ide_port_info cy82c693_chipset __devinitconst = {
32034 .name = DRV_NAME,
32035 .init_iops = init_iops_cy82c693,
32036 .port_ops = &cy82c693_port_ops,
32037diff --git a/drivers/ide/hpt366.c b/drivers/ide/hpt366.c
32038index 58c51cd..4aec3b8 100644
32039--- a/drivers/ide/hpt366.c
32040+++ b/drivers/ide/hpt366.c
32041@@ -443,7 +443,7 @@ static struct hpt_timings hpt37x_timings = {
32042 }
32043 };
32044
32045-static const struct hpt_info hpt36x __devinitdata = {
32046+static const struct hpt_info hpt36x __devinitconst = {
32047 .chip_name = "HPT36x",
32048 .chip_type = HPT36x,
32049 .udma_mask = HPT366_ALLOW_ATA66_3 ? (HPT366_ALLOW_ATA66_4 ? ATA_UDMA4 : ATA_UDMA3) : ATA_UDMA2,
32050@@ -451,7 +451,7 @@ static const struct hpt_info hpt36x __devinitdata = {
32051 .timings = &hpt36x_timings
32052 };
32053
32054-static const struct hpt_info hpt370 __devinitdata = {
32055+static const struct hpt_info hpt370 __devinitconst = {
32056 .chip_name = "HPT370",
32057 .chip_type = HPT370,
32058 .udma_mask = HPT370_ALLOW_ATA100_5 ? ATA_UDMA5 : ATA_UDMA4,
32059@@ -459,7 +459,7 @@ static const struct hpt_info hpt370 __devinitdata = {
32060 .timings = &hpt37x_timings
32061 };
32062
32063-static const struct hpt_info hpt370a __devinitdata = {
32064+static const struct hpt_info hpt370a __devinitconst = {
32065 .chip_name = "HPT370A",
32066 .chip_type = HPT370A,
32067 .udma_mask = HPT370_ALLOW_ATA100_5 ? ATA_UDMA5 : ATA_UDMA4,
32068@@ -467,7 +467,7 @@ static const struct hpt_info hpt370a __devinitdata = {
32069 .timings = &hpt37x_timings
32070 };
32071
32072-static const struct hpt_info hpt374 __devinitdata = {
32073+static const struct hpt_info hpt374 __devinitconst = {
32074 .chip_name = "HPT374",
32075 .chip_type = HPT374,
32076 .udma_mask = ATA_UDMA5,
32077@@ -475,7 +475,7 @@ static const struct hpt_info hpt374 __devinitdata = {
32078 .timings = &hpt37x_timings
32079 };
32080
32081-static const struct hpt_info hpt372 __devinitdata = {
32082+static const struct hpt_info hpt372 __devinitconst = {
32083 .chip_name = "HPT372",
32084 .chip_type = HPT372,
32085 .udma_mask = HPT372_ALLOW_ATA133_6 ? ATA_UDMA6 : ATA_UDMA5,
32086@@ -483,7 +483,7 @@ static const struct hpt_info hpt372 __devinitdata = {
32087 .timings = &hpt37x_timings
32088 };
32089
32090-static const struct hpt_info hpt372a __devinitdata = {
32091+static const struct hpt_info hpt372a __devinitconst = {
32092 .chip_name = "HPT372A",
32093 .chip_type = HPT372A,
32094 .udma_mask = HPT372_ALLOW_ATA133_6 ? ATA_UDMA6 : ATA_UDMA5,
32095@@ -491,7 +491,7 @@ static const struct hpt_info hpt372a __devinitdata = {
32096 .timings = &hpt37x_timings
32097 };
32098
32099-static const struct hpt_info hpt302 __devinitdata = {
32100+static const struct hpt_info hpt302 __devinitconst = {
32101 .chip_name = "HPT302",
32102 .chip_type = HPT302,
32103 .udma_mask = HPT302_ALLOW_ATA133_6 ? ATA_UDMA6 : ATA_UDMA5,
32104@@ -499,7 +499,7 @@ static const struct hpt_info hpt302 __devinitdata = {
32105 .timings = &hpt37x_timings
32106 };
32107
32108-static const struct hpt_info hpt371 __devinitdata = {
32109+static const struct hpt_info hpt371 __devinitconst = {
32110 .chip_name = "HPT371",
32111 .chip_type = HPT371,
32112 .udma_mask = HPT371_ALLOW_ATA133_6 ? ATA_UDMA6 : ATA_UDMA5,
32113@@ -507,7 +507,7 @@ static const struct hpt_info hpt371 __devinitdata = {
32114 .timings = &hpt37x_timings
32115 };
32116
32117-static const struct hpt_info hpt372n __devinitdata = {
32118+static const struct hpt_info hpt372n __devinitconst = {
32119 .chip_name = "HPT372N",
32120 .chip_type = HPT372N,
32121 .udma_mask = HPT372_ALLOW_ATA133_6 ? ATA_UDMA6 : ATA_UDMA5,
32122@@ -515,7 +515,7 @@ static const struct hpt_info hpt372n __devinitdata = {
32123 .timings = &hpt37x_timings
32124 };
32125
32126-static const struct hpt_info hpt302n __devinitdata = {
32127+static const struct hpt_info hpt302n __devinitconst = {
32128 .chip_name = "HPT302N",
32129 .chip_type = HPT302N,
32130 .udma_mask = HPT302_ALLOW_ATA133_6 ? ATA_UDMA6 : ATA_UDMA5,
32131@@ -523,7 +523,7 @@ static const struct hpt_info hpt302n __devinitdata = {
32132 .timings = &hpt37x_timings
32133 };
32134
32135-static const struct hpt_info hpt371n __devinitdata = {
32136+static const struct hpt_info hpt371n __devinitconst = {
32137 .chip_name = "HPT371N",
32138 .chip_type = HPT371N,
32139 .udma_mask = HPT371_ALLOW_ATA133_6 ? ATA_UDMA6 : ATA_UDMA5,
32140@@ -1361,7 +1361,7 @@ static const struct ide_dma_ops hpt36x_dma_ops = {
32141 .dma_sff_read_status = ide_dma_sff_read_status,
32142 };
32143
32144-static const struct ide_port_info hpt366_chipsets[] __devinitdata = {
32145+static const struct ide_port_info hpt366_chipsets[] __devinitconst = {
32146 { /* 0: HPT36x */
32147 .name = DRV_NAME,
32148 .init_chipset = init_chipset_hpt366,
32149diff --git a/drivers/ide/ide-cd.c b/drivers/ide/ide-cd.c
32150index 8126824..55a2798 100644
32151--- a/drivers/ide/ide-cd.c
32152+++ b/drivers/ide/ide-cd.c
32153@@ -768,7 +768,7 @@ static void cdrom_do_block_pc(ide_drive_t *drive, struct request *rq)
32154 alignment = queue_dma_alignment(q) | q->dma_pad_mask;
32155 if ((unsigned long)buf & alignment
32156 || blk_rq_bytes(rq) & q->dma_pad_mask
32157- || object_is_on_stack(buf))
32158+ || object_starts_on_stack(buf))
32159 drive->dma = 0;
32160 }
32161 }
32162diff --git a/drivers/ide/ide-pci-generic.c b/drivers/ide/ide-pci-generic.c
32163index 7f56b73..dab5b67 100644
32164--- a/drivers/ide/ide-pci-generic.c
32165+++ b/drivers/ide/ide-pci-generic.c
32166@@ -53,7 +53,7 @@ static const struct ide_port_ops netcell_port_ops = {
32167 .udma_mask = ATA_UDMA6, \
32168 }
32169
32170-static const struct ide_port_info generic_chipsets[] __devinitdata = {
32171+static const struct ide_port_info generic_chipsets[] __devinitconst = {
32172 /* 0: Unknown */
32173 DECLARE_GENERIC_PCI_DEV(0),
32174
32175diff --git a/drivers/ide/it8172.c b/drivers/ide/it8172.c
32176index 560e66d..d5dd180 100644
32177--- a/drivers/ide/it8172.c
32178+++ b/drivers/ide/it8172.c
32179@@ -115,7 +115,7 @@ static const struct ide_port_ops it8172_port_ops = {
32180 .set_dma_mode = it8172_set_dma_mode,
32181 };
32182
32183-static const struct ide_port_info it8172_port_info __devinitdata = {
32184+static const struct ide_port_info it8172_port_info __devinitconst = {
32185 .name = DRV_NAME,
32186 .port_ops = &it8172_port_ops,
32187 .enablebits = { {0x41, 0x80, 0x80}, {0x00, 0x00, 0x00} },
32188diff --git a/drivers/ide/it8213.c b/drivers/ide/it8213.c
32189index 46816ba..1847aeb 100644
32190--- a/drivers/ide/it8213.c
32191+++ b/drivers/ide/it8213.c
32192@@ -156,7 +156,7 @@ static const struct ide_port_ops it8213_port_ops = {
32193 .cable_detect = it8213_cable_detect,
32194 };
32195
32196-static const struct ide_port_info it8213_chipset __devinitdata = {
32197+static const struct ide_port_info it8213_chipset __devinitconst = {
32198 .name = DRV_NAME,
32199 .enablebits = { {0x41, 0x80, 0x80} },
32200 .port_ops = &it8213_port_ops,
32201diff --git a/drivers/ide/it821x.c b/drivers/ide/it821x.c
32202index 2e3169f..c5611db 100644
32203--- a/drivers/ide/it821x.c
32204+++ b/drivers/ide/it821x.c
32205@@ -630,7 +630,7 @@ static const struct ide_port_ops it821x_port_ops = {
32206 .cable_detect = it821x_cable_detect,
32207 };
32208
32209-static const struct ide_port_info it821x_chipset __devinitdata = {
32210+static const struct ide_port_info it821x_chipset __devinitconst = {
32211 .name = DRV_NAME,
32212 .init_chipset = init_chipset_it821x,
32213 .init_hwif = init_hwif_it821x,
32214diff --git a/drivers/ide/jmicron.c b/drivers/ide/jmicron.c
32215index 74c2c4a..efddd7d 100644
32216--- a/drivers/ide/jmicron.c
32217+++ b/drivers/ide/jmicron.c
32218@@ -102,7 +102,7 @@ static const struct ide_port_ops jmicron_port_ops = {
32219 .cable_detect = jmicron_cable_detect,
32220 };
32221
32222-static const struct ide_port_info jmicron_chipset __devinitdata = {
32223+static const struct ide_port_info jmicron_chipset __devinitconst = {
32224 .name = DRV_NAME,
32225 .enablebits = { { 0x40, 0x01, 0x01 }, { 0x40, 0x10, 0x10 } },
32226 .port_ops = &jmicron_port_ops,
32227diff --git a/drivers/ide/ns87415.c b/drivers/ide/ns87415.c
32228index 95327a2..73f78d8 100644
32229--- a/drivers/ide/ns87415.c
32230+++ b/drivers/ide/ns87415.c
32231@@ -293,7 +293,7 @@ static const struct ide_dma_ops ns87415_dma_ops = {
32232 .dma_sff_read_status = superio_dma_sff_read_status,
32233 };
32234
32235-static const struct ide_port_info ns87415_chipset __devinitdata = {
32236+static const struct ide_port_info ns87415_chipset __devinitconst = {
32237 .name = DRV_NAME,
32238 .init_hwif = init_hwif_ns87415,
32239 .tp_ops = &ns87415_tp_ops,
32240diff --git a/drivers/ide/opti621.c b/drivers/ide/opti621.c
32241index 1a53a4c..39edc66 100644
32242--- a/drivers/ide/opti621.c
32243+++ b/drivers/ide/opti621.c
32244@@ -131,7 +131,7 @@ static const struct ide_port_ops opti621_port_ops = {
32245 .set_pio_mode = opti621_set_pio_mode,
32246 };
32247
32248-static const struct ide_port_info opti621_chipset __devinitdata = {
32249+static const struct ide_port_info opti621_chipset __devinitconst = {
32250 .name = DRV_NAME,
32251 .enablebits = { {0x45, 0x80, 0x00}, {0x40, 0x08, 0x00} },
32252 .port_ops = &opti621_port_ops,
32253diff --git a/drivers/ide/pdc202xx_new.c b/drivers/ide/pdc202xx_new.c
32254index 9546fe2..2e5ceb6 100644
32255--- a/drivers/ide/pdc202xx_new.c
32256+++ b/drivers/ide/pdc202xx_new.c
32257@@ -465,7 +465,7 @@ static const struct ide_port_ops pdcnew_port_ops = {
32258 .udma_mask = udma, \
32259 }
32260
32261-static const struct ide_port_info pdcnew_chipsets[] __devinitdata = {
32262+static const struct ide_port_info pdcnew_chipsets[] __devinitconst = {
32263 /* 0: PDC202{68,70} */ DECLARE_PDCNEW_DEV(ATA_UDMA5),
32264 /* 1: PDC202{69,71,75,76,77} */ DECLARE_PDCNEW_DEV(ATA_UDMA6),
32265 };
32266diff --git a/drivers/ide/pdc202xx_old.c b/drivers/ide/pdc202xx_old.c
32267index 3a35ec6..5634510 100644
32268--- a/drivers/ide/pdc202xx_old.c
32269+++ b/drivers/ide/pdc202xx_old.c
32270@@ -270,7 +270,7 @@ static const struct ide_dma_ops pdc2026x_dma_ops = {
32271 .max_sectors = sectors, \
32272 }
32273
32274-static const struct ide_port_info pdc202xx_chipsets[] __devinitdata = {
32275+static const struct ide_port_info pdc202xx_chipsets[] __devinitconst = {
32276 { /* 0: PDC20246 */
32277 .name = DRV_NAME,
32278 .init_chipset = init_chipset_pdc202xx,
32279diff --git a/drivers/ide/piix.c b/drivers/ide/piix.c
32280index 1892e81..fe0fd60 100644
32281--- a/drivers/ide/piix.c
32282+++ b/drivers/ide/piix.c
32283@@ -344,7 +344,7 @@ static const struct ide_port_ops ich_port_ops = {
32284 .udma_mask = udma, \
32285 }
32286
32287-static const struct ide_port_info piix_pci_info[] __devinitdata = {
32288+static const struct ide_port_info piix_pci_info[] __devinitconst = {
32289 /* 0: MPIIX */
32290 { /*
32291 * MPIIX actually has only a single IDE channel mapped to
32292diff --git a/drivers/ide/rz1000.c b/drivers/ide/rz1000.c
32293index a6414a8..c04173e 100644
32294--- a/drivers/ide/rz1000.c
32295+++ b/drivers/ide/rz1000.c
32296@@ -38,7 +38,7 @@ static int __devinit rz1000_disable_readahead(struct pci_dev *dev)
32297 }
32298 }
32299
32300-static const struct ide_port_info rz1000_chipset __devinitdata = {
32301+static const struct ide_port_info rz1000_chipset __devinitconst = {
32302 .name = DRV_NAME,
32303 .host_flags = IDE_HFLAG_NO_DMA,
32304 };
32305diff --git a/drivers/ide/sc1200.c b/drivers/ide/sc1200.c
32306index 356b9b5..d4758eb 100644
32307--- a/drivers/ide/sc1200.c
32308+++ b/drivers/ide/sc1200.c
32309@@ -291,7 +291,7 @@ static const struct ide_dma_ops sc1200_dma_ops = {
32310 .dma_sff_read_status = ide_dma_sff_read_status,
32311 };
32312
32313-static const struct ide_port_info sc1200_chipset __devinitdata = {
32314+static const struct ide_port_info sc1200_chipset __devinitconst = {
32315 .name = DRV_NAME,
32316 .port_ops = &sc1200_port_ops,
32317 .dma_ops = &sc1200_dma_ops,
32318diff --git a/drivers/ide/scc_pata.c b/drivers/ide/scc_pata.c
32319index b7f5b0c..9701038 100644
32320--- a/drivers/ide/scc_pata.c
32321+++ b/drivers/ide/scc_pata.c
32322@@ -811,7 +811,7 @@ static const struct ide_dma_ops scc_dma_ops = {
32323 .dma_sff_read_status = scc_dma_sff_read_status,
32324 };
32325
32326-static const struct ide_port_info scc_chipset __devinitdata = {
32327+static const struct ide_port_info scc_chipset __devinitconst = {
32328 .name = "sccIDE",
32329 .init_iops = init_iops_scc,
32330 .init_dma = scc_init_dma,
32331diff --git a/drivers/ide/serverworks.c b/drivers/ide/serverworks.c
32332index 35fb8da..24d72ef 100644
32333--- a/drivers/ide/serverworks.c
32334+++ b/drivers/ide/serverworks.c
32335@@ -337,7 +337,7 @@ static const struct ide_port_ops svwks_port_ops = {
32336 .cable_detect = svwks_cable_detect,
32337 };
32338
32339-static const struct ide_port_info serverworks_chipsets[] __devinitdata = {
32340+static const struct ide_port_info serverworks_chipsets[] __devinitconst = {
32341 { /* 0: OSB4 */
32342 .name = DRV_NAME,
32343 .init_chipset = init_chipset_svwks,
32344diff --git a/drivers/ide/siimage.c b/drivers/ide/siimage.c
32345index ddeda44..46f7e30 100644
32346--- a/drivers/ide/siimage.c
32347+++ b/drivers/ide/siimage.c
32348@@ -719,7 +719,7 @@ static const struct ide_dma_ops sil_dma_ops = {
32349 .udma_mask = ATA_UDMA6, \
32350 }
32351
32352-static const struct ide_port_info siimage_chipsets[] __devinitdata = {
32353+static const struct ide_port_info siimage_chipsets[] __devinitconst = {
32354 /* 0: SiI680 */ DECLARE_SII_DEV(&sil_pata_port_ops),
32355 /* 1: SiI3112 */ DECLARE_SII_DEV(&sil_sata_port_ops)
32356 };
32357diff --git a/drivers/ide/sis5513.c b/drivers/ide/sis5513.c
32358index 4a00225..09e61b4 100644
32359--- a/drivers/ide/sis5513.c
32360+++ b/drivers/ide/sis5513.c
32361@@ -563,7 +563,7 @@ static const struct ide_port_ops sis_ata133_port_ops = {
32362 .cable_detect = sis_cable_detect,
32363 };
32364
32365-static const struct ide_port_info sis5513_chipset __devinitdata = {
32366+static const struct ide_port_info sis5513_chipset __devinitconst = {
32367 .name = DRV_NAME,
32368 .init_chipset = init_chipset_sis5513,
32369 .enablebits = { {0x4a, 0x02, 0x02}, {0x4a, 0x04, 0x04} },
32370diff --git a/drivers/ide/sl82c105.c b/drivers/ide/sl82c105.c
32371index f21dc2a..d051cd2 100644
32372--- a/drivers/ide/sl82c105.c
32373+++ b/drivers/ide/sl82c105.c
32374@@ -299,7 +299,7 @@ static const struct ide_dma_ops sl82c105_dma_ops = {
32375 .dma_sff_read_status = ide_dma_sff_read_status,
32376 };
32377
32378-static const struct ide_port_info sl82c105_chipset __devinitdata = {
32379+static const struct ide_port_info sl82c105_chipset __devinitconst = {
32380 .name = DRV_NAME,
32381 .init_chipset = init_chipset_sl82c105,
32382 .enablebits = {{0x40,0x01,0x01}, {0x40,0x10,0x10}},
32383diff --git a/drivers/ide/slc90e66.c b/drivers/ide/slc90e66.c
32384index 864ffe0..863a5e9 100644
32385--- a/drivers/ide/slc90e66.c
32386+++ b/drivers/ide/slc90e66.c
32387@@ -132,7 +132,7 @@ static const struct ide_port_ops slc90e66_port_ops = {
32388 .cable_detect = slc90e66_cable_detect,
32389 };
32390
32391-static const struct ide_port_info slc90e66_chipset __devinitdata = {
32392+static const struct ide_port_info slc90e66_chipset __devinitconst = {
32393 .name = DRV_NAME,
32394 .enablebits = { {0x41, 0x80, 0x80}, {0x43, 0x80, 0x80} },
32395 .port_ops = &slc90e66_port_ops,
32396diff --git a/drivers/ide/tc86c001.c b/drivers/ide/tc86c001.c
32397index 4799d5c..1794678 100644
32398--- a/drivers/ide/tc86c001.c
32399+++ b/drivers/ide/tc86c001.c
32400@@ -192,7 +192,7 @@ static const struct ide_dma_ops tc86c001_dma_ops = {
32401 .dma_sff_read_status = ide_dma_sff_read_status,
32402 };
32403
32404-static const struct ide_port_info tc86c001_chipset __devinitdata = {
32405+static const struct ide_port_info tc86c001_chipset __devinitconst = {
32406 .name = DRV_NAME,
32407 .init_hwif = init_hwif_tc86c001,
32408 .port_ops = &tc86c001_port_ops,
32409diff --git a/drivers/ide/triflex.c b/drivers/ide/triflex.c
32410index 281c914..55ce1b8 100644
32411--- a/drivers/ide/triflex.c
32412+++ b/drivers/ide/triflex.c
32413@@ -92,7 +92,7 @@ static const struct ide_port_ops triflex_port_ops = {
32414 .set_dma_mode = triflex_set_mode,
32415 };
32416
32417-static const struct ide_port_info triflex_device __devinitdata = {
32418+static const struct ide_port_info triflex_device __devinitconst = {
32419 .name = DRV_NAME,
32420 .enablebits = {{0x80, 0x01, 0x01}, {0x80, 0x02, 0x02}},
32421 .port_ops = &triflex_port_ops,
32422diff --git a/drivers/ide/trm290.c b/drivers/ide/trm290.c
32423index 4b42ca0..e494a98 100644
32424--- a/drivers/ide/trm290.c
32425+++ b/drivers/ide/trm290.c
32426@@ -324,7 +324,7 @@ static struct ide_dma_ops trm290_dma_ops = {
32427 .dma_check = trm290_dma_check,
32428 };
32429
32430-static const struct ide_port_info trm290_chipset __devinitdata = {
32431+static const struct ide_port_info trm290_chipset __devinitconst = {
32432 .name = DRV_NAME,
32433 .init_hwif = init_hwif_trm290,
32434 .tp_ops = &trm290_tp_ops,
32435diff --git a/drivers/ide/via82cxxx.c b/drivers/ide/via82cxxx.c
32436index f46f49c..eb77678 100644
32437--- a/drivers/ide/via82cxxx.c
32438+++ b/drivers/ide/via82cxxx.c
32439@@ -403,7 +403,7 @@ static const struct ide_port_ops via_port_ops = {
32440 .cable_detect = via82cxxx_cable_detect,
32441 };
32442
32443-static const struct ide_port_info via82cxxx_chipset __devinitdata = {
32444+static const struct ide_port_info via82cxxx_chipset __devinitconst = {
32445 .name = DRV_NAME,
32446 .init_chipset = init_chipset_via82cxxx,
32447 .enablebits = { { 0x40, 0x02, 0x02 }, { 0x40, 0x01, 0x01 } },
32448diff --git a/drivers/ieee802154/fakehard.c b/drivers/ieee802154/fakehard.c
32449index 73d4531..c90cd2d 100644
32450--- a/drivers/ieee802154/fakehard.c
32451+++ b/drivers/ieee802154/fakehard.c
32452@@ -386,7 +386,7 @@ static int __devinit ieee802154fake_probe(struct platform_device *pdev)
32453 phy->transmit_power = 0xbf;
32454
32455 dev->netdev_ops = &fake_ops;
32456- dev->ml_priv = &fake_mlme;
32457+ dev->ml_priv = (void *)&fake_mlme;
32458
32459 priv = netdev_priv(dev);
32460 priv->phy = phy;
32461diff --git a/drivers/infiniband/core/cm.c b/drivers/infiniband/core/cm.c
32462index d67999f..4c5d083 100644
32463--- a/drivers/infiniband/core/cm.c
32464+++ b/drivers/infiniband/core/cm.c
32465@@ -114,7 +114,7 @@ static char const counter_group_names[CM_COUNTER_GROUPS]
32466
32467 struct cm_counter_group {
32468 struct kobject obj;
32469- atomic_long_t counter[CM_ATTR_COUNT];
32470+ atomic_long_unchecked_t counter[CM_ATTR_COUNT];
32471 };
32472
32473 struct cm_counter_attribute {
32474@@ -1394,7 +1394,7 @@ static void cm_dup_req_handler(struct cm_work *work,
32475 struct ib_mad_send_buf *msg = NULL;
32476 int ret;
32477
32478- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
32479+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
32480 counter[CM_REQ_COUNTER]);
32481
32482 /* Quick state check to discard duplicate REQs. */
32483@@ -1778,7 +1778,7 @@ static void cm_dup_rep_handler(struct cm_work *work)
32484 if (!cm_id_priv)
32485 return;
32486
32487- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
32488+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
32489 counter[CM_REP_COUNTER]);
32490 ret = cm_alloc_response_msg(work->port, work->mad_recv_wc, &msg);
32491 if (ret)
32492@@ -1945,7 +1945,7 @@ static int cm_rtu_handler(struct cm_work *work)
32493 if (cm_id_priv->id.state != IB_CM_REP_SENT &&
32494 cm_id_priv->id.state != IB_CM_MRA_REP_RCVD) {
32495 spin_unlock_irq(&cm_id_priv->lock);
32496- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
32497+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
32498 counter[CM_RTU_COUNTER]);
32499 goto out;
32500 }
32501@@ -2128,7 +2128,7 @@ static int cm_dreq_handler(struct cm_work *work)
32502 cm_id_priv = cm_acquire_id(dreq_msg->remote_comm_id,
32503 dreq_msg->local_comm_id);
32504 if (!cm_id_priv) {
32505- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
32506+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
32507 counter[CM_DREQ_COUNTER]);
32508 cm_issue_drep(work->port, work->mad_recv_wc);
32509 return -EINVAL;
32510@@ -2153,7 +2153,7 @@ static int cm_dreq_handler(struct cm_work *work)
32511 case IB_CM_MRA_REP_RCVD:
32512 break;
32513 case IB_CM_TIMEWAIT:
32514- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
32515+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
32516 counter[CM_DREQ_COUNTER]);
32517 if (cm_alloc_response_msg(work->port, work->mad_recv_wc, &msg))
32518 goto unlock;
32519@@ -2167,7 +2167,7 @@ static int cm_dreq_handler(struct cm_work *work)
32520 cm_free_msg(msg);
32521 goto deref;
32522 case IB_CM_DREQ_RCVD:
32523- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
32524+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
32525 counter[CM_DREQ_COUNTER]);
32526 goto unlock;
32527 default:
32528@@ -2534,7 +2534,7 @@ static int cm_mra_handler(struct cm_work *work)
32529 ib_modify_mad(cm_id_priv->av.port->mad_agent,
32530 cm_id_priv->msg, timeout)) {
32531 if (cm_id_priv->id.lap_state == IB_CM_MRA_LAP_RCVD)
32532- atomic_long_inc(&work->port->
32533+ atomic_long_inc_unchecked(&work->port->
32534 counter_group[CM_RECV_DUPLICATES].
32535 counter[CM_MRA_COUNTER]);
32536 goto out;
32537@@ -2543,7 +2543,7 @@ static int cm_mra_handler(struct cm_work *work)
32538 break;
32539 case IB_CM_MRA_REQ_RCVD:
32540 case IB_CM_MRA_REP_RCVD:
32541- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
32542+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
32543 counter[CM_MRA_COUNTER]);
32544 /* fall through */
32545 default:
32546@@ -2705,7 +2705,7 @@ static int cm_lap_handler(struct cm_work *work)
32547 case IB_CM_LAP_IDLE:
32548 break;
32549 case IB_CM_MRA_LAP_SENT:
32550- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
32551+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
32552 counter[CM_LAP_COUNTER]);
32553 if (cm_alloc_response_msg(work->port, work->mad_recv_wc, &msg))
32554 goto unlock;
32555@@ -2721,7 +2721,7 @@ static int cm_lap_handler(struct cm_work *work)
32556 cm_free_msg(msg);
32557 goto deref;
32558 case IB_CM_LAP_RCVD:
32559- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
32560+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
32561 counter[CM_LAP_COUNTER]);
32562 goto unlock;
32563 default:
32564@@ -3005,7 +3005,7 @@ static int cm_sidr_req_handler(struct cm_work *work)
32565 cur_cm_id_priv = cm_insert_remote_sidr(cm_id_priv);
32566 if (cur_cm_id_priv) {
32567 spin_unlock_irq(&cm.lock);
32568- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
32569+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
32570 counter[CM_SIDR_REQ_COUNTER]);
32571 goto out; /* Duplicate message. */
32572 }
32573@@ -3217,10 +3217,10 @@ static void cm_send_handler(struct ib_mad_agent *mad_agent,
32574 if (!msg->context[0] && (attr_index != CM_REJ_COUNTER))
32575 msg->retries = 1;
32576
32577- atomic_long_add(1 + msg->retries,
32578+ atomic_long_add_unchecked(1 + msg->retries,
32579 &port->counter_group[CM_XMIT].counter[attr_index]);
32580 if (msg->retries)
32581- atomic_long_add(msg->retries,
32582+ atomic_long_add_unchecked(msg->retries,
32583 &port->counter_group[CM_XMIT_RETRIES].
32584 counter[attr_index]);
32585
32586@@ -3430,7 +3430,7 @@ static void cm_recv_handler(struct ib_mad_agent *mad_agent,
32587 }
32588
32589 attr_id = be16_to_cpu(mad_recv_wc->recv_buf.mad->mad_hdr.attr_id);
32590- atomic_long_inc(&port->counter_group[CM_RECV].
32591+ atomic_long_inc_unchecked(&port->counter_group[CM_RECV].
32592 counter[attr_id - CM_ATTR_ID_OFFSET]);
32593
32594 work = kmalloc(sizeof *work + sizeof(struct ib_sa_path_rec) * paths,
32595@@ -3635,7 +3635,7 @@ static ssize_t cm_show_counter(struct kobject *obj, struct attribute *attr,
32596 cm_attr = container_of(attr, struct cm_counter_attribute, attr);
32597
32598 return sprintf(buf, "%ld\n",
32599- atomic_long_read(&group->counter[cm_attr->index]));
32600+ atomic_long_read_unchecked(&group->counter[cm_attr->index]));
32601 }
32602
32603 static const struct sysfs_ops cm_counter_ops = {
32604diff --git a/drivers/infiniband/core/fmr_pool.c b/drivers/infiniband/core/fmr_pool.c
32605index 176c8f9..2627b62 100644
32606--- a/drivers/infiniband/core/fmr_pool.c
32607+++ b/drivers/infiniband/core/fmr_pool.c
32608@@ -98,8 +98,8 @@ struct ib_fmr_pool {
32609
32610 struct task_struct *thread;
32611
32612- atomic_t req_ser;
32613- atomic_t flush_ser;
32614+ atomic_unchecked_t req_ser;
32615+ atomic_unchecked_t flush_ser;
32616
32617 wait_queue_head_t force_wait;
32618 };
32619@@ -180,10 +180,10 @@ static int ib_fmr_cleanup_thread(void *pool_ptr)
32620 struct ib_fmr_pool *pool = pool_ptr;
32621
32622 do {
32623- if (atomic_read(&pool->flush_ser) - atomic_read(&pool->req_ser) < 0) {
32624+ if (atomic_read_unchecked(&pool->flush_ser) - atomic_read_unchecked(&pool->req_ser) < 0) {
32625 ib_fmr_batch_release(pool);
32626
32627- atomic_inc(&pool->flush_ser);
32628+ atomic_inc_unchecked(&pool->flush_ser);
32629 wake_up_interruptible(&pool->force_wait);
32630
32631 if (pool->flush_function)
32632@@ -191,7 +191,7 @@ static int ib_fmr_cleanup_thread(void *pool_ptr)
32633 }
32634
32635 set_current_state(TASK_INTERRUPTIBLE);
32636- if (atomic_read(&pool->flush_ser) - atomic_read(&pool->req_ser) >= 0 &&
32637+ if (atomic_read_unchecked(&pool->flush_ser) - atomic_read_unchecked(&pool->req_ser) >= 0 &&
32638 !kthread_should_stop())
32639 schedule();
32640 __set_current_state(TASK_RUNNING);
32641@@ -283,8 +283,8 @@ struct ib_fmr_pool *ib_create_fmr_pool(struct ib_pd *pd,
32642 pool->dirty_watermark = params->dirty_watermark;
32643 pool->dirty_len = 0;
32644 spin_lock_init(&pool->pool_lock);
32645- atomic_set(&pool->req_ser, 0);
32646- atomic_set(&pool->flush_ser, 0);
32647+ atomic_set_unchecked(&pool->req_ser, 0);
32648+ atomic_set_unchecked(&pool->flush_ser, 0);
32649 init_waitqueue_head(&pool->force_wait);
32650
32651 pool->thread = kthread_run(ib_fmr_cleanup_thread,
32652@@ -412,11 +412,11 @@ int ib_flush_fmr_pool(struct ib_fmr_pool *pool)
32653 }
32654 spin_unlock_irq(&pool->pool_lock);
32655
32656- serial = atomic_inc_return(&pool->req_ser);
32657+ serial = atomic_inc_return_unchecked(&pool->req_ser);
32658 wake_up_process(pool->thread);
32659
32660 if (wait_event_interruptible(pool->force_wait,
32661- atomic_read(&pool->flush_ser) - serial >= 0))
32662+ atomic_read_unchecked(&pool->flush_ser) - serial >= 0))
32663 return -EINTR;
32664
32665 return 0;
32666@@ -526,7 +526,7 @@ int ib_fmr_pool_unmap(struct ib_pool_fmr *fmr)
32667 } else {
32668 list_add_tail(&fmr->list, &pool->dirty_list);
32669 if (++pool->dirty_len >= pool->dirty_watermark) {
32670- atomic_inc(&pool->req_ser);
32671+ atomic_inc_unchecked(&pool->req_ser);
32672 wake_up_process(pool->thread);
32673 }
32674 }
32675diff --git a/drivers/infiniband/hw/cxgb4/mem.c b/drivers/infiniband/hw/cxgb4/mem.c
32676index 57e07c6..56d09d4 100644
32677--- a/drivers/infiniband/hw/cxgb4/mem.c
32678+++ b/drivers/infiniband/hw/cxgb4/mem.c
32679@@ -122,7 +122,7 @@ static int write_tpt_entry(struct c4iw_rdev *rdev, u32 reset_tpt_entry,
32680 int err;
32681 struct fw_ri_tpte tpt;
32682 u32 stag_idx;
32683- static atomic_t key;
32684+ static atomic_unchecked_t key;
32685
32686 if (c4iw_fatal_error(rdev))
32687 return -EIO;
32688@@ -139,7 +139,7 @@ static int write_tpt_entry(struct c4iw_rdev *rdev, u32 reset_tpt_entry,
32689 if (rdev->stats.stag.cur > rdev->stats.stag.max)
32690 rdev->stats.stag.max = rdev->stats.stag.cur;
32691 mutex_unlock(&rdev->stats.lock);
32692- *stag = (stag_idx << 8) | (atomic_inc_return(&key) & 0xff);
32693+ *stag = (stag_idx << 8) | (atomic_inc_return_unchecked(&key) & 0xff);
32694 }
32695 PDBG("%s stag_state 0x%0x type 0x%0x pdid 0x%0x, stag_idx 0x%x\n",
32696 __func__, stag_state, type, pdid, stag_idx);
32697diff --git a/drivers/infiniband/hw/ipath/ipath_rc.c b/drivers/infiniband/hw/ipath/ipath_rc.c
32698index 79b3dbc..96e5fcc 100644
32699--- a/drivers/infiniband/hw/ipath/ipath_rc.c
32700+++ b/drivers/infiniband/hw/ipath/ipath_rc.c
32701@@ -1868,7 +1868,7 @@ void ipath_rc_rcv(struct ipath_ibdev *dev, struct ipath_ib_header *hdr,
32702 struct ib_atomic_eth *ateth;
32703 struct ipath_ack_entry *e;
32704 u64 vaddr;
32705- atomic64_t *maddr;
32706+ atomic64_unchecked_t *maddr;
32707 u64 sdata;
32708 u32 rkey;
32709 u8 next;
32710@@ -1903,11 +1903,11 @@ void ipath_rc_rcv(struct ipath_ibdev *dev, struct ipath_ib_header *hdr,
32711 IB_ACCESS_REMOTE_ATOMIC)))
32712 goto nack_acc_unlck;
32713 /* Perform atomic OP and save result. */
32714- maddr = (atomic64_t *) qp->r_sge.sge.vaddr;
32715+ maddr = (atomic64_unchecked_t *) qp->r_sge.sge.vaddr;
32716 sdata = be64_to_cpu(ateth->swap_data);
32717 e = &qp->s_ack_queue[qp->r_head_ack_queue];
32718 e->atomic_data = (opcode == OP(FETCH_ADD)) ?
32719- (u64) atomic64_add_return(sdata, maddr) - sdata :
32720+ (u64) atomic64_add_return_unchecked(sdata, maddr) - sdata :
32721 (u64) cmpxchg((u64 *) qp->r_sge.sge.vaddr,
32722 be64_to_cpu(ateth->compare_data),
32723 sdata);
32724diff --git a/drivers/infiniband/hw/ipath/ipath_ruc.c b/drivers/infiniband/hw/ipath/ipath_ruc.c
32725index 1f95bba..9530f87 100644
32726--- a/drivers/infiniband/hw/ipath/ipath_ruc.c
32727+++ b/drivers/infiniband/hw/ipath/ipath_ruc.c
32728@@ -266,7 +266,7 @@ static void ipath_ruc_loopback(struct ipath_qp *sqp)
32729 unsigned long flags;
32730 struct ib_wc wc;
32731 u64 sdata;
32732- atomic64_t *maddr;
32733+ atomic64_unchecked_t *maddr;
32734 enum ib_wc_status send_status;
32735
32736 /*
32737@@ -382,11 +382,11 @@ again:
32738 IB_ACCESS_REMOTE_ATOMIC)))
32739 goto acc_err;
32740 /* Perform atomic OP and save result. */
32741- maddr = (atomic64_t *) qp->r_sge.sge.vaddr;
32742+ maddr = (atomic64_unchecked_t *) qp->r_sge.sge.vaddr;
32743 sdata = wqe->wr.wr.atomic.compare_add;
32744 *(u64 *) sqp->s_sge.sge.vaddr =
32745 (wqe->wr.opcode == IB_WR_ATOMIC_FETCH_AND_ADD) ?
32746- (u64) atomic64_add_return(sdata, maddr) - sdata :
32747+ (u64) atomic64_add_return_unchecked(sdata, maddr) - sdata :
32748 (u64) cmpxchg((u64 *) qp->r_sge.sge.vaddr,
32749 sdata, wqe->wr.wr.atomic.swap);
32750 goto send_comp;
32751diff --git a/drivers/infiniband/hw/nes/nes.c b/drivers/infiniband/hw/nes/nes.c
32752index 7140199..da60063 100644
32753--- a/drivers/infiniband/hw/nes/nes.c
32754+++ b/drivers/infiniband/hw/nes/nes.c
32755@@ -103,7 +103,7 @@ MODULE_PARM_DESC(limit_maxrdreqsz, "Limit max read request size to 256 Bytes");
32756 LIST_HEAD(nes_adapter_list);
32757 static LIST_HEAD(nes_dev_list);
32758
32759-atomic_t qps_destroyed;
32760+atomic_unchecked_t qps_destroyed;
32761
32762 static unsigned int ee_flsh_adapter;
32763 static unsigned int sysfs_nonidx_addr;
32764@@ -272,7 +272,7 @@ static void nes_cqp_rem_ref_callback(struct nes_device *nesdev, struct nes_cqp_r
32765 struct nes_qp *nesqp = cqp_request->cqp_callback_pointer;
32766 struct nes_adapter *nesadapter = nesdev->nesadapter;
32767
32768- atomic_inc(&qps_destroyed);
32769+ atomic_inc_unchecked(&qps_destroyed);
32770
32771 /* Free the control structures */
32772
32773diff --git a/drivers/infiniband/hw/nes/nes.h b/drivers/infiniband/hw/nes/nes.h
32774index c438e46..ca30356 100644
32775--- a/drivers/infiniband/hw/nes/nes.h
32776+++ b/drivers/infiniband/hw/nes/nes.h
32777@@ -178,17 +178,17 @@ extern unsigned int nes_debug_level;
32778 extern unsigned int wqm_quanta;
32779 extern struct list_head nes_adapter_list;
32780
32781-extern atomic_t cm_connects;
32782-extern atomic_t cm_accepts;
32783-extern atomic_t cm_disconnects;
32784-extern atomic_t cm_closes;
32785-extern atomic_t cm_connecteds;
32786-extern atomic_t cm_connect_reqs;
32787-extern atomic_t cm_rejects;
32788-extern atomic_t mod_qp_timouts;
32789-extern atomic_t qps_created;
32790-extern atomic_t qps_destroyed;
32791-extern atomic_t sw_qps_destroyed;
32792+extern atomic_unchecked_t cm_connects;
32793+extern atomic_unchecked_t cm_accepts;
32794+extern atomic_unchecked_t cm_disconnects;
32795+extern atomic_unchecked_t cm_closes;
32796+extern atomic_unchecked_t cm_connecteds;
32797+extern atomic_unchecked_t cm_connect_reqs;
32798+extern atomic_unchecked_t cm_rejects;
32799+extern atomic_unchecked_t mod_qp_timouts;
32800+extern atomic_unchecked_t qps_created;
32801+extern atomic_unchecked_t qps_destroyed;
32802+extern atomic_unchecked_t sw_qps_destroyed;
32803 extern u32 mh_detected;
32804 extern u32 mh_pauses_sent;
32805 extern u32 cm_packets_sent;
32806@@ -197,16 +197,16 @@ extern u32 cm_packets_created;
32807 extern u32 cm_packets_received;
32808 extern u32 cm_packets_dropped;
32809 extern u32 cm_packets_retrans;
32810-extern atomic_t cm_listens_created;
32811-extern atomic_t cm_listens_destroyed;
32812+extern atomic_unchecked_t cm_listens_created;
32813+extern atomic_unchecked_t cm_listens_destroyed;
32814 extern u32 cm_backlog_drops;
32815-extern atomic_t cm_loopbacks;
32816-extern atomic_t cm_nodes_created;
32817-extern atomic_t cm_nodes_destroyed;
32818-extern atomic_t cm_accel_dropped_pkts;
32819-extern atomic_t cm_resets_recvd;
32820-extern atomic_t pau_qps_created;
32821-extern atomic_t pau_qps_destroyed;
32822+extern atomic_unchecked_t cm_loopbacks;
32823+extern atomic_unchecked_t cm_nodes_created;
32824+extern atomic_unchecked_t cm_nodes_destroyed;
32825+extern atomic_unchecked_t cm_accel_dropped_pkts;
32826+extern atomic_unchecked_t cm_resets_recvd;
32827+extern atomic_unchecked_t pau_qps_created;
32828+extern atomic_unchecked_t pau_qps_destroyed;
32829
32830 extern u32 int_mod_timer_init;
32831 extern u32 int_mod_cq_depth_256;
32832diff --git a/drivers/infiniband/hw/nes/nes_cm.c b/drivers/infiniband/hw/nes/nes_cm.c
32833index 020e95c..fbb3450 100644
32834--- a/drivers/infiniband/hw/nes/nes_cm.c
32835+++ b/drivers/infiniband/hw/nes/nes_cm.c
32836@@ -68,14 +68,14 @@ u32 cm_packets_dropped;
32837 u32 cm_packets_retrans;
32838 u32 cm_packets_created;
32839 u32 cm_packets_received;
32840-atomic_t cm_listens_created;
32841-atomic_t cm_listens_destroyed;
32842+atomic_unchecked_t cm_listens_created;
32843+atomic_unchecked_t cm_listens_destroyed;
32844 u32 cm_backlog_drops;
32845-atomic_t cm_loopbacks;
32846-atomic_t cm_nodes_created;
32847-atomic_t cm_nodes_destroyed;
32848-atomic_t cm_accel_dropped_pkts;
32849-atomic_t cm_resets_recvd;
32850+atomic_unchecked_t cm_loopbacks;
32851+atomic_unchecked_t cm_nodes_created;
32852+atomic_unchecked_t cm_nodes_destroyed;
32853+atomic_unchecked_t cm_accel_dropped_pkts;
32854+atomic_unchecked_t cm_resets_recvd;
32855
32856 static inline int mini_cm_accelerated(struct nes_cm_core *, struct nes_cm_node *);
32857 static struct nes_cm_listener *mini_cm_listen(struct nes_cm_core *, struct nes_vnic *, struct nes_cm_info *);
32858@@ -148,13 +148,13 @@ static struct nes_cm_ops nes_cm_api = {
32859
32860 static struct nes_cm_core *g_cm_core;
32861
32862-atomic_t cm_connects;
32863-atomic_t cm_accepts;
32864-atomic_t cm_disconnects;
32865-atomic_t cm_closes;
32866-atomic_t cm_connecteds;
32867-atomic_t cm_connect_reqs;
32868-atomic_t cm_rejects;
32869+atomic_unchecked_t cm_connects;
32870+atomic_unchecked_t cm_accepts;
32871+atomic_unchecked_t cm_disconnects;
32872+atomic_unchecked_t cm_closes;
32873+atomic_unchecked_t cm_connecteds;
32874+atomic_unchecked_t cm_connect_reqs;
32875+atomic_unchecked_t cm_rejects;
32876
32877 int nes_add_ref_cm_node(struct nes_cm_node *cm_node)
32878 {
32879@@ -1279,7 +1279,7 @@ static int mini_cm_dec_refcnt_listen(struct nes_cm_core *cm_core,
32880 kfree(listener);
32881 listener = NULL;
32882 ret = 0;
32883- atomic_inc(&cm_listens_destroyed);
32884+ atomic_inc_unchecked(&cm_listens_destroyed);
32885 } else {
32886 spin_unlock_irqrestore(&cm_core->listen_list_lock, flags);
32887 }
32888@@ -1482,7 +1482,7 @@ static struct nes_cm_node *make_cm_node(struct nes_cm_core *cm_core,
32889 cm_node->rem_mac);
32890
32891 add_hte_node(cm_core, cm_node);
32892- atomic_inc(&cm_nodes_created);
32893+ atomic_inc_unchecked(&cm_nodes_created);
32894
32895 return cm_node;
32896 }
32897@@ -1540,7 +1540,7 @@ static int rem_ref_cm_node(struct nes_cm_core *cm_core,
32898 }
32899
32900 atomic_dec(&cm_core->node_cnt);
32901- atomic_inc(&cm_nodes_destroyed);
32902+ atomic_inc_unchecked(&cm_nodes_destroyed);
32903 nesqp = cm_node->nesqp;
32904 if (nesqp) {
32905 nesqp->cm_node = NULL;
32906@@ -1604,7 +1604,7 @@ static int process_options(struct nes_cm_node *cm_node, u8 *optionsloc,
32907
32908 static void drop_packet(struct sk_buff *skb)
32909 {
32910- atomic_inc(&cm_accel_dropped_pkts);
32911+ atomic_inc_unchecked(&cm_accel_dropped_pkts);
32912 dev_kfree_skb_any(skb);
32913 }
32914
32915@@ -1667,7 +1667,7 @@ static void handle_rst_pkt(struct nes_cm_node *cm_node, struct sk_buff *skb,
32916 {
32917
32918 int reset = 0; /* whether to send reset in case of err.. */
32919- atomic_inc(&cm_resets_recvd);
32920+ atomic_inc_unchecked(&cm_resets_recvd);
32921 nes_debug(NES_DBG_CM, "Received Reset, cm_node = %p, state = %u."
32922 " refcnt=%d\n", cm_node, cm_node->state,
32923 atomic_read(&cm_node->ref_count));
32924@@ -2308,7 +2308,7 @@ static struct nes_cm_node *mini_cm_connect(struct nes_cm_core *cm_core,
32925 rem_ref_cm_node(cm_node->cm_core, cm_node);
32926 return NULL;
32927 }
32928- atomic_inc(&cm_loopbacks);
32929+ atomic_inc_unchecked(&cm_loopbacks);
32930 loopbackremotenode->loopbackpartner = cm_node;
32931 loopbackremotenode->tcp_cntxt.rcv_wscale =
32932 NES_CM_DEFAULT_RCV_WND_SCALE;
32933@@ -2583,7 +2583,7 @@ static int mini_cm_recv_pkt(struct nes_cm_core *cm_core,
32934 nes_queue_mgt_skbs(skb, nesvnic, cm_node->nesqp);
32935 else {
32936 rem_ref_cm_node(cm_core, cm_node);
32937- atomic_inc(&cm_accel_dropped_pkts);
32938+ atomic_inc_unchecked(&cm_accel_dropped_pkts);
32939 dev_kfree_skb_any(skb);
32940 }
32941 break;
32942@@ -2891,7 +2891,7 @@ static int nes_cm_disconn_true(struct nes_qp *nesqp)
32943
32944 if ((cm_id) && (cm_id->event_handler)) {
32945 if (issue_disconn) {
32946- atomic_inc(&cm_disconnects);
32947+ atomic_inc_unchecked(&cm_disconnects);
32948 cm_event.event = IW_CM_EVENT_DISCONNECT;
32949 cm_event.status = disconn_status;
32950 cm_event.local_addr = cm_id->local_addr;
32951@@ -2913,7 +2913,7 @@ static int nes_cm_disconn_true(struct nes_qp *nesqp)
32952 }
32953
32954 if (issue_close) {
32955- atomic_inc(&cm_closes);
32956+ atomic_inc_unchecked(&cm_closes);
32957 nes_disconnect(nesqp, 1);
32958
32959 cm_id->provider_data = nesqp;
32960@@ -3049,7 +3049,7 @@ int nes_accept(struct iw_cm_id *cm_id, struct iw_cm_conn_param *conn_param)
32961
32962 nes_debug(NES_DBG_CM, "QP%u, cm_node=%p, jiffies = %lu listener = %p\n",
32963 nesqp->hwqp.qp_id, cm_node, jiffies, cm_node->listener);
32964- atomic_inc(&cm_accepts);
32965+ atomic_inc_unchecked(&cm_accepts);
32966
32967 nes_debug(NES_DBG_CM, "netdev refcnt = %u.\n",
32968 netdev_refcnt_read(nesvnic->netdev));
32969@@ -3251,7 +3251,7 @@ int nes_reject(struct iw_cm_id *cm_id, const void *pdata, u8 pdata_len)
32970 struct nes_cm_core *cm_core;
32971 u8 *start_buff;
32972
32973- atomic_inc(&cm_rejects);
32974+ atomic_inc_unchecked(&cm_rejects);
32975 cm_node = (struct nes_cm_node *)cm_id->provider_data;
32976 loopback = cm_node->loopbackpartner;
32977 cm_core = cm_node->cm_core;
32978@@ -3311,7 +3311,7 @@ int nes_connect(struct iw_cm_id *cm_id, struct iw_cm_conn_param *conn_param)
32979 ntohl(cm_id->local_addr.sin_addr.s_addr),
32980 ntohs(cm_id->local_addr.sin_port));
32981
32982- atomic_inc(&cm_connects);
32983+ atomic_inc_unchecked(&cm_connects);
32984 nesqp->active_conn = 1;
32985
32986 /* cache the cm_id in the qp */
32987@@ -3421,7 +3421,7 @@ int nes_create_listen(struct iw_cm_id *cm_id, int backlog)
32988 g_cm_core->api->stop_listener(g_cm_core, (void *)cm_node);
32989 return err;
32990 }
32991- atomic_inc(&cm_listens_created);
32992+ atomic_inc_unchecked(&cm_listens_created);
32993 }
32994
32995 cm_id->add_ref(cm_id);
32996@@ -3522,7 +3522,7 @@ static void cm_event_connected(struct nes_cm_event *event)
32997
32998 if (nesqp->destroyed)
32999 return;
33000- atomic_inc(&cm_connecteds);
33001+ atomic_inc_unchecked(&cm_connecteds);
33002 nes_debug(NES_DBG_CM, "QP%u attempting to connect to 0x%08X:0x%04X on"
33003 " local port 0x%04X. jiffies = %lu.\n",
33004 nesqp->hwqp.qp_id,
33005@@ -3709,7 +3709,7 @@ static void cm_event_reset(struct nes_cm_event *event)
33006
33007 cm_id->add_ref(cm_id);
33008 ret = cm_id->event_handler(cm_id, &cm_event);
33009- atomic_inc(&cm_closes);
33010+ atomic_inc_unchecked(&cm_closes);
33011 cm_event.event = IW_CM_EVENT_CLOSE;
33012 cm_event.status = 0;
33013 cm_event.provider_data = cm_id->provider_data;
33014@@ -3745,7 +3745,7 @@ static void cm_event_mpa_req(struct nes_cm_event *event)
33015 return;
33016 cm_id = cm_node->cm_id;
33017
33018- atomic_inc(&cm_connect_reqs);
33019+ atomic_inc_unchecked(&cm_connect_reqs);
33020 nes_debug(NES_DBG_CM, "cm_node = %p - cm_id = %p, jiffies = %lu\n",
33021 cm_node, cm_id, jiffies);
33022
33023@@ -3785,7 +3785,7 @@ static void cm_event_mpa_reject(struct nes_cm_event *event)
33024 return;
33025 cm_id = cm_node->cm_id;
33026
33027- atomic_inc(&cm_connect_reqs);
33028+ atomic_inc_unchecked(&cm_connect_reqs);
33029 nes_debug(NES_DBG_CM, "cm_node = %p - cm_id = %p, jiffies = %lu\n",
33030 cm_node, cm_id, jiffies);
33031
33032diff --git a/drivers/infiniband/hw/nes/nes_mgt.c b/drivers/infiniband/hw/nes/nes_mgt.c
33033index 3ba7be3..c81f6ff 100644
33034--- a/drivers/infiniband/hw/nes/nes_mgt.c
33035+++ b/drivers/infiniband/hw/nes/nes_mgt.c
33036@@ -40,8 +40,8 @@
33037 #include "nes.h"
33038 #include "nes_mgt.h"
33039
33040-atomic_t pau_qps_created;
33041-atomic_t pau_qps_destroyed;
33042+atomic_unchecked_t pau_qps_created;
33043+atomic_unchecked_t pau_qps_destroyed;
33044
33045 static void nes_replenish_mgt_rq(struct nes_vnic_mgt *mgtvnic)
33046 {
33047@@ -621,7 +621,7 @@ void nes_destroy_pau_qp(struct nes_device *nesdev, struct nes_qp *nesqp)
33048 {
33049 struct sk_buff *skb;
33050 unsigned long flags;
33051- atomic_inc(&pau_qps_destroyed);
33052+ atomic_inc_unchecked(&pau_qps_destroyed);
33053
33054 /* Free packets that have not yet been forwarded */
33055 /* Lock is acquired by skb_dequeue when removing the skb */
33056@@ -812,7 +812,7 @@ static void nes_mgt_ce_handler(struct nes_device *nesdev, struct nes_hw_nic_cq *
33057 cq->cq_vbase[head].cqe_words[NES_NIC_CQE_HASH_RCVNXT]);
33058 skb_queue_head_init(&nesqp->pau_list);
33059 spin_lock_init(&nesqp->pau_lock);
33060- atomic_inc(&pau_qps_created);
33061+ atomic_inc_unchecked(&pau_qps_created);
33062 nes_change_quad_hash(nesdev, mgtvnic->nesvnic, nesqp);
33063 }
33064
33065diff --git a/drivers/infiniband/hw/nes/nes_nic.c b/drivers/infiniband/hw/nes/nes_nic.c
33066index f3a3ecf..57d311d 100644
33067--- a/drivers/infiniband/hw/nes/nes_nic.c
33068+++ b/drivers/infiniband/hw/nes/nes_nic.c
33069@@ -1277,39 +1277,39 @@ static void nes_netdev_get_ethtool_stats(struct net_device *netdev,
33070 target_stat_values[++index] = mh_detected;
33071 target_stat_values[++index] = mh_pauses_sent;
33072 target_stat_values[++index] = nesvnic->endnode_ipv4_tcp_retransmits;
33073- target_stat_values[++index] = atomic_read(&cm_connects);
33074- target_stat_values[++index] = atomic_read(&cm_accepts);
33075- target_stat_values[++index] = atomic_read(&cm_disconnects);
33076- target_stat_values[++index] = atomic_read(&cm_connecteds);
33077- target_stat_values[++index] = atomic_read(&cm_connect_reqs);
33078- target_stat_values[++index] = atomic_read(&cm_rejects);
33079- target_stat_values[++index] = atomic_read(&mod_qp_timouts);
33080- target_stat_values[++index] = atomic_read(&qps_created);
33081- target_stat_values[++index] = atomic_read(&sw_qps_destroyed);
33082- target_stat_values[++index] = atomic_read(&qps_destroyed);
33083- target_stat_values[++index] = atomic_read(&cm_closes);
33084+ target_stat_values[++index] = atomic_read_unchecked(&cm_connects);
33085+ target_stat_values[++index] = atomic_read_unchecked(&cm_accepts);
33086+ target_stat_values[++index] = atomic_read_unchecked(&cm_disconnects);
33087+ target_stat_values[++index] = atomic_read_unchecked(&cm_connecteds);
33088+ target_stat_values[++index] = atomic_read_unchecked(&cm_connect_reqs);
33089+ target_stat_values[++index] = atomic_read_unchecked(&cm_rejects);
33090+ target_stat_values[++index] = atomic_read_unchecked(&mod_qp_timouts);
33091+ target_stat_values[++index] = atomic_read_unchecked(&qps_created);
33092+ target_stat_values[++index] = atomic_read_unchecked(&sw_qps_destroyed);
33093+ target_stat_values[++index] = atomic_read_unchecked(&qps_destroyed);
33094+ target_stat_values[++index] = atomic_read_unchecked(&cm_closes);
33095 target_stat_values[++index] = cm_packets_sent;
33096 target_stat_values[++index] = cm_packets_bounced;
33097 target_stat_values[++index] = cm_packets_created;
33098 target_stat_values[++index] = cm_packets_received;
33099 target_stat_values[++index] = cm_packets_dropped;
33100 target_stat_values[++index] = cm_packets_retrans;
33101- target_stat_values[++index] = atomic_read(&cm_listens_created);
33102- target_stat_values[++index] = atomic_read(&cm_listens_destroyed);
33103+ target_stat_values[++index] = atomic_read_unchecked(&cm_listens_created);
33104+ target_stat_values[++index] = atomic_read_unchecked(&cm_listens_destroyed);
33105 target_stat_values[++index] = cm_backlog_drops;
33106- target_stat_values[++index] = atomic_read(&cm_loopbacks);
33107- target_stat_values[++index] = atomic_read(&cm_nodes_created);
33108- target_stat_values[++index] = atomic_read(&cm_nodes_destroyed);
33109- target_stat_values[++index] = atomic_read(&cm_accel_dropped_pkts);
33110- target_stat_values[++index] = atomic_read(&cm_resets_recvd);
33111+ target_stat_values[++index] = atomic_read_unchecked(&cm_loopbacks);
33112+ target_stat_values[++index] = atomic_read_unchecked(&cm_nodes_created);
33113+ target_stat_values[++index] = atomic_read_unchecked(&cm_nodes_destroyed);
33114+ target_stat_values[++index] = atomic_read_unchecked(&cm_accel_dropped_pkts);
33115+ target_stat_values[++index] = atomic_read_unchecked(&cm_resets_recvd);
33116 target_stat_values[++index] = nesadapter->free_4kpbl;
33117 target_stat_values[++index] = nesadapter->free_256pbl;
33118 target_stat_values[++index] = int_mod_timer_init;
33119 target_stat_values[++index] = nesvnic->lro_mgr.stats.aggregated;
33120 target_stat_values[++index] = nesvnic->lro_mgr.stats.flushed;
33121 target_stat_values[++index] = nesvnic->lro_mgr.stats.no_desc;
33122- target_stat_values[++index] = atomic_read(&pau_qps_created);
33123- target_stat_values[++index] = atomic_read(&pau_qps_destroyed);
33124+ target_stat_values[++index] = atomic_read_unchecked(&pau_qps_created);
33125+ target_stat_values[++index] = atomic_read_unchecked(&pau_qps_destroyed);
33126 }
33127
33128 /**
33129diff --git a/drivers/infiniband/hw/nes/nes_verbs.c b/drivers/infiniband/hw/nes/nes_verbs.c
33130index 8b8812d..a5e1133 100644
33131--- a/drivers/infiniband/hw/nes/nes_verbs.c
33132+++ b/drivers/infiniband/hw/nes/nes_verbs.c
33133@@ -46,9 +46,9 @@
33134
33135 #include <rdma/ib_umem.h>
33136
33137-atomic_t mod_qp_timouts;
33138-atomic_t qps_created;
33139-atomic_t sw_qps_destroyed;
33140+atomic_unchecked_t mod_qp_timouts;
33141+atomic_unchecked_t qps_created;
33142+atomic_unchecked_t sw_qps_destroyed;
33143
33144 static void nes_unregister_ofa_device(struct nes_ib_device *nesibdev);
33145
33146@@ -1131,7 +1131,7 @@ static struct ib_qp *nes_create_qp(struct ib_pd *ibpd,
33147 if (init_attr->create_flags)
33148 return ERR_PTR(-EINVAL);
33149
33150- atomic_inc(&qps_created);
33151+ atomic_inc_unchecked(&qps_created);
33152 switch (init_attr->qp_type) {
33153 case IB_QPT_RC:
33154 if (nes_drv_opt & NES_DRV_OPT_NO_INLINE_DATA) {
33155@@ -1460,7 +1460,7 @@ static int nes_destroy_qp(struct ib_qp *ibqp)
33156 struct iw_cm_event cm_event;
33157 int ret = 0;
33158
33159- atomic_inc(&sw_qps_destroyed);
33160+ atomic_inc_unchecked(&sw_qps_destroyed);
33161 nesqp->destroyed = 1;
33162
33163 /* Blow away the connection if it exists. */
33164diff --git a/drivers/infiniband/hw/qib/qib.h b/drivers/infiniband/hw/qib/qib.h
33165index 7b1b8669..4b69f85 100644
33166--- a/drivers/infiniband/hw/qib/qib.h
33167+++ b/drivers/infiniband/hw/qib/qib.h
33168@@ -51,6 +51,7 @@
33169 #include <linux/completion.h>
33170 #include <linux/kref.h>
33171 #include <linux/sched.h>
33172+#include <linux/slab.h>
33173
33174 #include "qib_common.h"
33175 #include "qib_verbs.h"
33176diff --git a/drivers/input/gameport/gameport.c b/drivers/input/gameport/gameport.c
33177index da739d9..da1c7f4 100644
33178--- a/drivers/input/gameport/gameport.c
33179+++ b/drivers/input/gameport/gameport.c
33180@@ -487,14 +487,14 @@ EXPORT_SYMBOL(gameport_set_phys);
33181 */
33182 static void gameport_init_port(struct gameport *gameport)
33183 {
33184- static atomic_t gameport_no = ATOMIC_INIT(0);
33185+ static atomic_unchecked_t gameport_no = ATOMIC_INIT(0);
33186
33187 __module_get(THIS_MODULE);
33188
33189 mutex_init(&gameport->drv_mutex);
33190 device_initialize(&gameport->dev);
33191 dev_set_name(&gameport->dev, "gameport%lu",
33192- (unsigned long)atomic_inc_return(&gameport_no) - 1);
33193+ (unsigned long)atomic_inc_return_unchecked(&gameport_no) - 1);
33194 gameport->dev.bus = &gameport_bus;
33195 gameport->dev.release = gameport_release_port;
33196 if (gameport->parent)
33197diff --git a/drivers/input/input.c b/drivers/input/input.c
33198index 8921c61..f5cd63d 100644
33199--- a/drivers/input/input.c
33200+++ b/drivers/input/input.c
33201@@ -1814,7 +1814,7 @@ static void input_cleanse_bitmasks(struct input_dev *dev)
33202 */
33203 int input_register_device(struct input_dev *dev)
33204 {
33205- static atomic_t input_no = ATOMIC_INIT(0);
33206+ static atomic_unchecked_t input_no = ATOMIC_INIT(0);
33207 struct input_handler *handler;
33208 const char *path;
33209 int error;
33210@@ -1851,7 +1851,7 @@ int input_register_device(struct input_dev *dev)
33211 dev->setkeycode = input_default_setkeycode;
33212
33213 dev_set_name(&dev->dev, "input%ld",
33214- (unsigned long) atomic_inc_return(&input_no) - 1);
33215+ (unsigned long) atomic_inc_return_unchecked(&input_no) - 1);
33216
33217 error = device_add(&dev->dev);
33218 if (error)
33219diff --git a/drivers/input/joystick/sidewinder.c b/drivers/input/joystick/sidewinder.c
33220index 04c69af..5f92d00 100644
33221--- a/drivers/input/joystick/sidewinder.c
33222+++ b/drivers/input/joystick/sidewinder.c
33223@@ -30,6 +30,7 @@
33224 #include <linux/kernel.h>
33225 #include <linux/module.h>
33226 #include <linux/slab.h>
33227+#include <linux/sched.h>
33228 #include <linux/init.h>
33229 #include <linux/input.h>
33230 #include <linux/gameport.h>
33231diff --git a/drivers/input/joystick/xpad.c b/drivers/input/joystick/xpad.c
33232index 83811e4..0822b90 100644
33233--- a/drivers/input/joystick/xpad.c
33234+++ b/drivers/input/joystick/xpad.c
33235@@ -726,7 +726,7 @@ static void xpad_led_set(struct led_classdev *led_cdev,
33236
33237 static int xpad_led_probe(struct usb_xpad *xpad)
33238 {
33239- static atomic_t led_seq = ATOMIC_INIT(0);
33240+ static atomic_unchecked_t led_seq = ATOMIC_INIT(0);
33241 long led_no;
33242 struct xpad_led *led;
33243 struct led_classdev *led_cdev;
33244@@ -739,7 +739,7 @@ static int xpad_led_probe(struct usb_xpad *xpad)
33245 if (!led)
33246 return -ENOMEM;
33247
33248- led_no = (long)atomic_inc_return(&led_seq) - 1;
33249+ led_no = (long)atomic_inc_return_unchecked(&led_seq) - 1;
33250
33251 snprintf(led->name, sizeof(led->name), "xpad%ld", led_no);
33252 led->xpad = xpad;
33253diff --git a/drivers/input/mousedev.c b/drivers/input/mousedev.c
33254index 0110b5a..d3ad144 100644
33255--- a/drivers/input/mousedev.c
33256+++ b/drivers/input/mousedev.c
33257@@ -763,7 +763,7 @@ static ssize_t mousedev_read(struct file *file, char __user *buffer,
33258
33259 spin_unlock_irq(&client->packet_lock);
33260
33261- if (copy_to_user(buffer, data, count))
33262+ if (count > sizeof(data) || copy_to_user(buffer, data, count))
33263 return -EFAULT;
33264
33265 return count;
33266diff --git a/drivers/input/serio/serio.c b/drivers/input/serio/serio.c
33267index d0f7533..fb8215b 100644
33268--- a/drivers/input/serio/serio.c
33269+++ b/drivers/input/serio/serio.c
33270@@ -496,7 +496,7 @@ static void serio_release_port(struct device *dev)
33271 */
33272 static void serio_init_port(struct serio *serio)
33273 {
33274- static atomic_t serio_no = ATOMIC_INIT(0);
33275+ static atomic_unchecked_t serio_no = ATOMIC_INIT(0);
33276
33277 __module_get(THIS_MODULE);
33278
33279@@ -507,7 +507,7 @@ static void serio_init_port(struct serio *serio)
33280 mutex_init(&serio->drv_mutex);
33281 device_initialize(&serio->dev);
33282 dev_set_name(&serio->dev, "serio%ld",
33283- (long)atomic_inc_return(&serio_no) - 1);
33284+ (long)atomic_inc_return_unchecked(&serio_no) - 1);
33285 serio->dev.bus = &serio_bus;
33286 serio->dev.release = serio_release_port;
33287 serio->dev.groups = serio_device_attr_groups;
33288diff --git a/drivers/isdn/capi/capi.c b/drivers/isdn/capi/capi.c
33289index 38c4bd8..58965d9 100644
33290--- a/drivers/isdn/capi/capi.c
33291+++ b/drivers/isdn/capi/capi.c
33292@@ -83,8 +83,8 @@ struct capiminor {
33293
33294 struct capi20_appl *ap;
33295 u32 ncci;
33296- atomic_t datahandle;
33297- atomic_t msgid;
33298+ atomic_unchecked_t datahandle;
33299+ atomic_unchecked_t msgid;
33300
33301 struct tty_port port;
33302 int ttyinstop;
33303@@ -392,7 +392,7 @@ gen_data_b3_resp_for(struct capiminor *mp, struct sk_buff *skb)
33304 capimsg_setu16(s, 2, mp->ap->applid);
33305 capimsg_setu8 (s, 4, CAPI_DATA_B3);
33306 capimsg_setu8 (s, 5, CAPI_RESP);
33307- capimsg_setu16(s, 6, atomic_inc_return(&mp->msgid));
33308+ capimsg_setu16(s, 6, atomic_inc_return_unchecked(&mp->msgid));
33309 capimsg_setu32(s, 8, mp->ncci);
33310 capimsg_setu16(s, 12, datahandle);
33311 }
33312@@ -513,14 +513,14 @@ static void handle_minor_send(struct capiminor *mp)
33313 mp->outbytes -= len;
33314 spin_unlock_bh(&mp->outlock);
33315
33316- datahandle = atomic_inc_return(&mp->datahandle);
33317+ datahandle = atomic_inc_return_unchecked(&mp->datahandle);
33318 skb_push(skb, CAPI_DATA_B3_REQ_LEN);
33319 memset(skb->data, 0, CAPI_DATA_B3_REQ_LEN);
33320 capimsg_setu16(skb->data, 0, CAPI_DATA_B3_REQ_LEN);
33321 capimsg_setu16(skb->data, 2, mp->ap->applid);
33322 capimsg_setu8 (skb->data, 4, CAPI_DATA_B3);
33323 capimsg_setu8 (skb->data, 5, CAPI_REQ);
33324- capimsg_setu16(skb->data, 6, atomic_inc_return(&mp->msgid));
33325+ capimsg_setu16(skb->data, 6, atomic_inc_return_unchecked(&mp->msgid));
33326 capimsg_setu32(skb->data, 8, mp->ncci); /* NCCI */
33327 capimsg_setu32(skb->data, 12, (u32)(long)skb->data);/* Data32 */
33328 capimsg_setu16(skb->data, 16, len); /* Data length */
33329diff --git a/drivers/isdn/gigaset/interface.c b/drivers/isdn/gigaset/interface.c
33330index a6d9fd2..afdb8a3 100644
33331--- a/drivers/isdn/gigaset/interface.c
33332+++ b/drivers/isdn/gigaset/interface.c
33333@@ -160,9 +160,9 @@ static int if_open(struct tty_struct *tty, struct file *filp)
33334 }
33335 tty->driver_data = cs;
33336
33337- ++cs->port.count;
33338+ atomic_inc(&cs->port.count);
33339
33340- if (cs->port.count == 1) {
33341+ if (atomic_read(&cs->port.count) == 1) {
33342 tty_port_tty_set(&cs->port, tty);
33343 tty->low_latency = 1;
33344 }
33345@@ -186,9 +186,9 @@ static void if_close(struct tty_struct *tty, struct file *filp)
33346
33347 if (!cs->connected)
33348 gig_dbg(DEBUG_IF, "not connected"); /* nothing to do */
33349- else if (!cs->port.count)
33350+ else if (!atomic_read(&cs->port.count))
33351 dev_warn(cs->dev, "%s: device not opened\n", __func__);
33352- else if (!--cs->port.count)
33353+ else if (!atomic_dec_return(&cs->port.count))
33354 tty_port_tty_set(&cs->port, NULL);
33355
33356 mutex_unlock(&cs->mutex);
33357diff --git a/drivers/isdn/hardware/avm/b1.c b/drivers/isdn/hardware/avm/b1.c
33358index 821f7ac..28d4030 100644
33359--- a/drivers/isdn/hardware/avm/b1.c
33360+++ b/drivers/isdn/hardware/avm/b1.c
33361@@ -176,7 +176,7 @@ int b1_load_t4file(avmcard *card, capiloaddatapart *t4file)
33362 }
33363 if (left) {
33364 if (t4file->user) {
33365- if (copy_from_user(buf, dp, left))
33366+ if (left > sizeof buf || copy_from_user(buf, dp, left))
33367 return -EFAULT;
33368 } else {
33369 memcpy(buf, dp, left);
33370@@ -224,7 +224,7 @@ int b1_load_config(avmcard *card, capiloaddatapart *config)
33371 }
33372 if (left) {
33373 if (config->user) {
33374- if (copy_from_user(buf, dp, left))
33375+ if (left > sizeof buf || copy_from_user(buf, dp, left))
33376 return -EFAULT;
33377 } else {
33378 memcpy(buf, dp, left);
33379diff --git a/drivers/isdn/hardware/eicon/divasync.h b/drivers/isdn/hardware/eicon/divasync.h
33380index dd6b53a..19d9ee6 100644
33381--- a/drivers/isdn/hardware/eicon/divasync.h
33382+++ b/drivers/isdn/hardware/eicon/divasync.h
33383@@ -146,7 +146,7 @@ typedef struct _diva_didd_add_adapter {
33384 } diva_didd_add_adapter_t;
33385 typedef struct _diva_didd_remove_adapter {
33386 IDI_CALL p_request;
33387-} diva_didd_remove_adapter_t;
33388+} __no_const diva_didd_remove_adapter_t;
33389 typedef struct _diva_didd_read_adapter_array {
33390 void *buffer;
33391 dword length;
33392diff --git a/drivers/isdn/hardware/eicon/xdi_adapter.h b/drivers/isdn/hardware/eicon/xdi_adapter.h
33393index d303e65..28bcb7b 100644
33394--- a/drivers/isdn/hardware/eicon/xdi_adapter.h
33395+++ b/drivers/isdn/hardware/eicon/xdi_adapter.h
33396@@ -44,7 +44,7 @@ typedef struct _xdi_mbox_t {
33397 typedef struct _diva_os_idi_adapter_interface {
33398 diva_init_card_proc_t cleanup_adapter_proc;
33399 diva_cmd_card_proc_t cmd_proc;
33400-} diva_os_idi_adapter_interface_t;
33401+} __no_const diva_os_idi_adapter_interface_t;
33402
33403 typedef struct _diva_os_xdi_adapter {
33404 struct list_head link;
33405diff --git a/drivers/isdn/i4l/isdn_tty.c b/drivers/isdn/i4l/isdn_tty.c
33406index 7bc5067..fd36232 100644
33407--- a/drivers/isdn/i4l/isdn_tty.c
33408+++ b/drivers/isdn/i4l/isdn_tty.c
33409@@ -1505,9 +1505,9 @@ isdn_tty_open(struct tty_struct *tty, struct file *filp)
33410 port = &info->port;
33411 #ifdef ISDN_DEBUG_MODEM_OPEN
33412 printk(KERN_DEBUG "isdn_tty_open %s, count = %d\n", tty->name,
33413- port->count);
33414+ atomic_read(&port->count))
33415 #endif
33416- port->count++;
33417+ atomic_inc(&port->count);
33418 tty->driver_data = info;
33419 port->tty = tty;
33420 tty->port = port;
33421@@ -1553,7 +1553,7 @@ isdn_tty_close(struct tty_struct *tty, struct file *filp)
33422 #endif
33423 return;
33424 }
33425- if ((tty->count == 1) && (port->count != 1)) {
33426+ if ((tty->count == 1) && (atomic_read(&port->count) != 1)) {
33427 /*
33428 * Uh, oh. tty->count is 1, which means that the tty
33429 * structure will be freed. Info->count should always
33430@@ -1562,15 +1562,15 @@ isdn_tty_close(struct tty_struct *tty, struct file *filp)
33431 * serial port won't be shutdown.
33432 */
33433 printk(KERN_ERR "isdn_tty_close: bad port count; tty->count is 1, "
33434- "info->count is %d\n", port->count);
33435- port->count = 1;
33436+ "info->count is %d\n", atomic_read(&port->count));
33437+ atomic_set(&port->count, 1);
33438 }
33439- if (--port->count < 0) {
33440+ if (atomic_dec_return(&port->count) < 0) {
33441 printk(KERN_ERR "isdn_tty_close: bad port count for ttyi%d: %d\n",
33442- info->line, port->count);
33443- port->count = 0;
33444+ info->line, atomic_read(&port->count));
33445+ atomic_set(&port->count, 0);
33446 }
33447- if (port->count) {
33448+ if (atomic_read(&port->count)) {
33449 #ifdef ISDN_DEBUG_MODEM_OPEN
33450 printk(KERN_DEBUG "isdn_tty_close after info->count != 0\n");
33451 #endif
33452@@ -1624,7 +1624,7 @@ isdn_tty_hangup(struct tty_struct *tty)
33453 if (isdn_tty_paranoia_check(info, tty->name, "isdn_tty_hangup"))
33454 return;
33455 isdn_tty_shutdown(info);
33456- port->count = 0;
33457+ atomic_set(&port->count, 0);
33458 port->flags &= ~ASYNC_NORMAL_ACTIVE;
33459 port->tty = NULL;
33460 wake_up_interruptible(&port->open_wait);
33461@@ -1964,7 +1964,7 @@ isdn_tty_find_icall(int di, int ch, setup_parm *setup)
33462 for (i = 0; i < ISDN_MAX_CHANNELS; i++) {
33463 modem_info *info = &dev->mdm.info[i];
33464
33465- if (info->port.count == 0)
33466+ if (atomic_read(&info->port.count) == 0)
33467 continue;
33468 if ((info->emu.mdmreg[REG_SI1] & si2bit[si1]) && /* SI1 is matching */
33469 (info->emu.mdmreg[REG_SI2] == si2)) { /* SI2 is matching */
33470diff --git a/drivers/isdn/icn/icn.c b/drivers/isdn/icn/icn.c
33471index e74df7c..03a03ba 100644
33472--- a/drivers/isdn/icn/icn.c
33473+++ b/drivers/isdn/icn/icn.c
33474@@ -1045,7 +1045,7 @@ icn_writecmd(const u_char *buf, int len, int user, icn_card *card)
33475 if (count > len)
33476 count = len;
33477 if (user) {
33478- if (copy_from_user(msg, buf, count))
33479+ if (count > sizeof msg || copy_from_user(msg, buf, count))
33480 return -EFAULT;
33481 } else
33482 memcpy(msg, buf, count);
33483diff --git a/drivers/lguest/core.c b/drivers/lguest/core.c
33484index b5fdcb7..5b6c59f 100644
33485--- a/drivers/lguest/core.c
33486+++ b/drivers/lguest/core.c
33487@@ -92,9 +92,17 @@ static __init int map_switcher(void)
33488 * it's worked so far. The end address needs +1 because __get_vm_area
33489 * allocates an extra guard page, so we need space for that.
33490 */
33491+
33492+#if defined(CONFIG_MODULES) && defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
33493+ switcher_vma = __get_vm_area(TOTAL_SWITCHER_PAGES * PAGE_SIZE,
33494+ VM_ALLOC | VM_KERNEXEC, SWITCHER_ADDR, SWITCHER_ADDR
33495+ + (TOTAL_SWITCHER_PAGES+1) * PAGE_SIZE);
33496+#else
33497 switcher_vma = __get_vm_area(TOTAL_SWITCHER_PAGES * PAGE_SIZE,
33498 VM_ALLOC, SWITCHER_ADDR, SWITCHER_ADDR
33499 + (TOTAL_SWITCHER_PAGES+1) * PAGE_SIZE);
33500+#endif
33501+
33502 if (!switcher_vma) {
33503 err = -ENOMEM;
33504 printk("lguest: could not map switcher pages high\n");
33505@@ -119,7 +127,7 @@ static __init int map_switcher(void)
33506 * Now the Switcher is mapped at the right address, we can't fail!
33507 * Copy in the compiled-in Switcher code (from x86/switcher_32.S).
33508 */
33509- memcpy(switcher_vma->addr, start_switcher_text,
33510+ memcpy(switcher_vma->addr, ktla_ktva(start_switcher_text),
33511 end_switcher_text - start_switcher_text);
33512
33513 printk(KERN_INFO "lguest: mapped switcher at %p\n",
33514diff --git a/drivers/lguest/x86/core.c b/drivers/lguest/x86/core.c
33515index 39809035..ce25c5e 100644
33516--- a/drivers/lguest/x86/core.c
33517+++ b/drivers/lguest/x86/core.c
33518@@ -59,7 +59,7 @@ static struct {
33519 /* Offset from where switcher.S was compiled to where we've copied it */
33520 static unsigned long switcher_offset(void)
33521 {
33522- return SWITCHER_ADDR - (unsigned long)start_switcher_text;
33523+ return SWITCHER_ADDR - (unsigned long)ktla_ktva(start_switcher_text);
33524 }
33525
33526 /* This cpu's struct lguest_pages. */
33527@@ -100,7 +100,13 @@ static void copy_in_guest_info(struct lg_cpu *cpu, struct lguest_pages *pages)
33528 * These copies are pretty cheap, so we do them unconditionally: */
33529 /* Save the current Host top-level page directory.
33530 */
33531+
33532+#ifdef CONFIG_PAX_PER_CPU_PGD
33533+ pages->state.host_cr3 = read_cr3();
33534+#else
33535 pages->state.host_cr3 = __pa(current->mm->pgd);
33536+#endif
33537+
33538 /*
33539 * Set up the Guest's page tables to see this CPU's pages (and no
33540 * other CPU's pages).
33541@@ -472,7 +478,7 @@ void __init lguest_arch_host_init(void)
33542 * compiled-in switcher code and the high-mapped copy we just made.
33543 */
33544 for (i = 0; i < IDT_ENTRIES; i++)
33545- default_idt_entries[i] += switcher_offset();
33546+ default_idt_entries[i] = ktla_ktva(default_idt_entries[i]) + switcher_offset();
33547
33548 /*
33549 * Set up the Switcher's per-cpu areas.
33550@@ -555,7 +561,7 @@ void __init lguest_arch_host_init(void)
33551 * it will be undisturbed when we switch. To change %cs and jump we
33552 * need this structure to feed to Intel's "lcall" instruction.
33553 */
33554- lguest_entry.offset = (long)switch_to_guest + switcher_offset();
33555+ lguest_entry.offset = (long)ktla_ktva(switch_to_guest) + switcher_offset();
33556 lguest_entry.segment = LGUEST_CS;
33557
33558 /*
33559diff --git a/drivers/lguest/x86/switcher_32.S b/drivers/lguest/x86/switcher_32.S
33560index 40634b0..4f5855e 100644
33561--- a/drivers/lguest/x86/switcher_32.S
33562+++ b/drivers/lguest/x86/switcher_32.S
33563@@ -87,6 +87,7 @@
33564 #include <asm/page.h>
33565 #include <asm/segment.h>
33566 #include <asm/lguest.h>
33567+#include <asm/processor-flags.h>
33568
33569 // We mark the start of the code to copy
33570 // It's placed in .text tho it's never run here
33571@@ -149,6 +150,13 @@ ENTRY(switch_to_guest)
33572 // Changes type when we load it: damn Intel!
33573 // For after we switch over our page tables
33574 // That entry will be read-only: we'd crash.
33575+
33576+#ifdef CONFIG_PAX_KERNEXEC
33577+ mov %cr0, %edx
33578+ xor $X86_CR0_WP, %edx
33579+ mov %edx, %cr0
33580+#endif
33581+
33582 movl $(GDT_ENTRY_TSS*8), %edx
33583 ltr %dx
33584
33585@@ -157,9 +165,15 @@ ENTRY(switch_to_guest)
33586 // Let's clear it again for our return.
33587 // The GDT descriptor of the Host
33588 // Points to the table after two "size" bytes
33589- movl (LGUEST_PAGES_host_gdt_desc+2)(%eax), %edx
33590+ movl (LGUEST_PAGES_host_gdt_desc+2)(%eax), %eax
33591 // Clear "used" from type field (byte 5, bit 2)
33592- andb $0xFD, (GDT_ENTRY_TSS*8 + 5)(%edx)
33593+ andb $0xFD, (GDT_ENTRY_TSS*8 + 5)(%eax)
33594+
33595+#ifdef CONFIG_PAX_KERNEXEC
33596+ mov %cr0, %eax
33597+ xor $X86_CR0_WP, %eax
33598+ mov %eax, %cr0
33599+#endif
33600
33601 // Once our page table's switched, the Guest is live!
33602 // The Host fades as we run this final step.
33603@@ -295,13 +309,12 @@ deliver_to_host:
33604 // I consulted gcc, and it gave
33605 // These instructions, which I gladly credit:
33606 leal (%edx,%ebx,8), %eax
33607- movzwl (%eax),%edx
33608- movl 4(%eax), %eax
33609- xorw %ax, %ax
33610- orl %eax, %edx
33611+ movl 4(%eax), %edx
33612+ movw (%eax), %dx
33613 // Now the address of the handler's in %edx
33614 // We call it now: its "iret" drops us home.
33615- jmp *%edx
33616+ ljmp $__KERNEL_CS, $1f
33617+1: jmp *%edx
33618
33619 // Every interrupt can come to us here
33620 // But we must truly tell each apart.
33621diff --git a/drivers/macintosh/macio_asic.c b/drivers/macintosh/macio_asic.c
33622index 20e5c2c..9e849a9 100644
33623--- a/drivers/macintosh/macio_asic.c
33624+++ b/drivers/macintosh/macio_asic.c
33625@@ -748,7 +748,7 @@ static void __devexit macio_pci_remove(struct pci_dev* pdev)
33626 * MacIO is matched against any Apple ID, it's probe() function
33627 * will then decide wether it applies or not
33628 */
33629-static const struct pci_device_id __devinitdata pci_ids [] = { {
33630+static const struct pci_device_id __devinitconst pci_ids [] = { {
33631 .vendor = PCI_VENDOR_ID_APPLE,
33632 .device = PCI_ANY_ID,
33633 .subvendor = PCI_ANY_ID,
33634diff --git a/drivers/md/bitmap.c b/drivers/md/bitmap.c
33635index 94e7f6b..2f4a0d8 100644
33636--- a/drivers/md/bitmap.c
33637+++ b/drivers/md/bitmap.c
33638@@ -1786,7 +1786,7 @@ void bitmap_status(struct seq_file *seq, struct bitmap *bitmap)
33639 chunk_kb ? "KB" : "B");
33640 if (bitmap->storage.file) {
33641 seq_printf(seq, ", file: ");
33642- seq_path(seq, &bitmap->storage.file->f_path, " \t\n");
33643+ seq_path(seq, &bitmap->storage.file->f_path, " \t\n\\");
33644 }
33645
33646 seq_printf(seq, "\n");
33647diff --git a/drivers/md/dm-ioctl.c b/drivers/md/dm-ioctl.c
33648index afd9598..528d8f9 100644
33649--- a/drivers/md/dm-ioctl.c
33650+++ b/drivers/md/dm-ioctl.c
33651@@ -1593,7 +1593,7 @@ static int validate_params(uint cmd, struct dm_ioctl *param)
33652 cmd == DM_LIST_VERSIONS_CMD)
33653 return 0;
33654
33655- if ((cmd == DM_DEV_CREATE_CMD)) {
33656+ if (cmd == DM_DEV_CREATE_CMD) {
33657 if (!*param->name) {
33658 DMWARN("name not supplied when creating device");
33659 return -EINVAL;
33660diff --git a/drivers/md/dm-raid1.c b/drivers/md/dm-raid1.c
33661index bc5ddba8..b961159 100644
33662--- a/drivers/md/dm-raid1.c
33663+++ b/drivers/md/dm-raid1.c
33664@@ -40,7 +40,7 @@ enum dm_raid1_error {
33665
33666 struct mirror {
33667 struct mirror_set *ms;
33668- atomic_t error_count;
33669+ atomic_unchecked_t error_count;
33670 unsigned long error_type;
33671 struct dm_dev *dev;
33672 sector_t offset;
33673@@ -185,7 +185,7 @@ static struct mirror *get_valid_mirror(struct mirror_set *ms)
33674 struct mirror *m;
33675
33676 for (m = ms->mirror; m < ms->mirror + ms->nr_mirrors; m++)
33677- if (!atomic_read(&m->error_count))
33678+ if (!atomic_read_unchecked(&m->error_count))
33679 return m;
33680
33681 return NULL;
33682@@ -217,7 +217,7 @@ static void fail_mirror(struct mirror *m, enum dm_raid1_error error_type)
33683 * simple way to tell if a device has encountered
33684 * errors.
33685 */
33686- atomic_inc(&m->error_count);
33687+ atomic_inc_unchecked(&m->error_count);
33688
33689 if (test_and_set_bit(error_type, &m->error_type))
33690 return;
33691@@ -408,7 +408,7 @@ static struct mirror *choose_mirror(struct mirror_set *ms, sector_t sector)
33692 struct mirror *m = get_default_mirror(ms);
33693
33694 do {
33695- if (likely(!atomic_read(&m->error_count)))
33696+ if (likely(!atomic_read_unchecked(&m->error_count)))
33697 return m;
33698
33699 if (m-- == ms->mirror)
33700@@ -422,7 +422,7 @@ static int default_ok(struct mirror *m)
33701 {
33702 struct mirror *default_mirror = get_default_mirror(m->ms);
33703
33704- return !atomic_read(&default_mirror->error_count);
33705+ return !atomic_read_unchecked(&default_mirror->error_count);
33706 }
33707
33708 static int mirror_available(struct mirror_set *ms, struct bio *bio)
33709@@ -559,7 +559,7 @@ static void do_reads(struct mirror_set *ms, struct bio_list *reads)
33710 */
33711 if (likely(region_in_sync(ms, region, 1)))
33712 m = choose_mirror(ms, bio->bi_sector);
33713- else if (m && atomic_read(&m->error_count))
33714+ else if (m && atomic_read_unchecked(&m->error_count))
33715 m = NULL;
33716
33717 if (likely(m))
33718@@ -938,7 +938,7 @@ static int get_mirror(struct mirror_set *ms, struct dm_target *ti,
33719 }
33720
33721 ms->mirror[mirror].ms = ms;
33722- atomic_set(&(ms->mirror[mirror].error_count), 0);
33723+ atomic_set_unchecked(&(ms->mirror[mirror].error_count), 0);
33724 ms->mirror[mirror].error_type = 0;
33725 ms->mirror[mirror].offset = offset;
33726
33727@@ -1356,7 +1356,7 @@ static void mirror_resume(struct dm_target *ti)
33728 */
33729 static char device_status_char(struct mirror *m)
33730 {
33731- if (!atomic_read(&(m->error_count)))
33732+ if (!atomic_read_unchecked(&(m->error_count)))
33733 return 'A';
33734
33735 return (test_bit(DM_RAID1_FLUSH_ERROR, &(m->error_type))) ? 'F' :
33736diff --git a/drivers/md/dm-stripe.c b/drivers/md/dm-stripe.c
33737index a087bf2..4c94786 100644
33738--- a/drivers/md/dm-stripe.c
33739+++ b/drivers/md/dm-stripe.c
33740@@ -20,7 +20,7 @@ struct stripe {
33741 struct dm_dev *dev;
33742 sector_t physical_start;
33743
33744- atomic_t error_count;
33745+ atomic_unchecked_t error_count;
33746 };
33747
33748 struct stripe_c {
33749@@ -183,7 +183,7 @@ static int stripe_ctr(struct dm_target *ti, unsigned int argc, char **argv)
33750 kfree(sc);
33751 return r;
33752 }
33753- atomic_set(&(sc->stripe[i].error_count), 0);
33754+ atomic_set_unchecked(&(sc->stripe[i].error_count), 0);
33755 }
33756
33757 ti->private = sc;
33758@@ -324,7 +324,7 @@ static int stripe_status(struct dm_target *ti, status_type_t type,
33759 DMEMIT("%d ", sc->stripes);
33760 for (i = 0; i < sc->stripes; i++) {
33761 DMEMIT("%s ", sc->stripe[i].dev->name);
33762- buffer[i] = atomic_read(&(sc->stripe[i].error_count)) ?
33763+ buffer[i] = atomic_read_unchecked(&(sc->stripe[i].error_count)) ?
33764 'D' : 'A';
33765 }
33766 buffer[i] = '\0';
33767@@ -371,8 +371,8 @@ static int stripe_end_io(struct dm_target *ti, struct bio *bio,
33768 */
33769 for (i = 0; i < sc->stripes; i++)
33770 if (!strcmp(sc->stripe[i].dev->name, major_minor)) {
33771- atomic_inc(&(sc->stripe[i].error_count));
33772- if (atomic_read(&(sc->stripe[i].error_count)) <
33773+ atomic_inc_unchecked(&(sc->stripe[i].error_count));
33774+ if (atomic_read_unchecked(&(sc->stripe[i].error_count)) <
33775 DM_IO_ERROR_THRESHOLD)
33776 schedule_work(&sc->trigger_event);
33777 }
33778diff --git a/drivers/md/dm-table.c b/drivers/md/dm-table.c
33779index 100368e..64262ce 100644
33780--- a/drivers/md/dm-table.c
33781+++ b/drivers/md/dm-table.c
33782@@ -390,7 +390,7 @@ static int device_area_is_invalid(struct dm_target *ti, struct dm_dev *dev,
33783 if (!dev_size)
33784 return 0;
33785
33786- if ((start >= dev_size) || (start + len > dev_size)) {
33787+ if ((start >= dev_size) || (len > dev_size - start)) {
33788 DMWARN("%s: %s too small for target: "
33789 "start=%llu, len=%llu, dev_size=%llu",
33790 dm_device_name(ti->table->md), bdevname(bdev, b),
33791diff --git a/drivers/md/dm-thin-metadata.c b/drivers/md/dm-thin-metadata.c
33792index 693e149..b7e0fde 100644
33793--- a/drivers/md/dm-thin-metadata.c
33794+++ b/drivers/md/dm-thin-metadata.c
33795@@ -397,7 +397,7 @@ static void __setup_btree_details(struct dm_pool_metadata *pmd)
33796 {
33797 pmd->info.tm = pmd->tm;
33798 pmd->info.levels = 2;
33799- pmd->info.value_type.context = pmd->data_sm;
33800+ pmd->info.value_type.context = (dm_space_map_no_const *)pmd->data_sm;
33801 pmd->info.value_type.size = sizeof(__le64);
33802 pmd->info.value_type.inc = data_block_inc;
33803 pmd->info.value_type.dec = data_block_dec;
33804@@ -416,7 +416,7 @@ static void __setup_btree_details(struct dm_pool_metadata *pmd)
33805
33806 pmd->bl_info.tm = pmd->tm;
33807 pmd->bl_info.levels = 1;
33808- pmd->bl_info.value_type.context = pmd->data_sm;
33809+ pmd->bl_info.value_type.context = (dm_space_map_no_const *)pmd->data_sm;
33810 pmd->bl_info.value_type.size = sizeof(__le64);
33811 pmd->bl_info.value_type.inc = data_block_inc;
33812 pmd->bl_info.value_type.dec = data_block_dec;
33813diff --git a/drivers/md/dm.c b/drivers/md/dm.c
33814index 67ffa39..cb3b1dd 100644
33815--- a/drivers/md/dm.c
33816+++ b/drivers/md/dm.c
33817@@ -176,9 +176,9 @@ struct mapped_device {
33818 /*
33819 * Event handling.
33820 */
33821- atomic_t event_nr;
33822+ atomic_unchecked_t event_nr;
33823 wait_queue_head_t eventq;
33824- atomic_t uevent_seq;
33825+ atomic_unchecked_t uevent_seq;
33826 struct list_head uevent_list;
33827 spinlock_t uevent_lock; /* Protect access to uevent_list */
33828
33829@@ -1887,8 +1887,8 @@ static struct mapped_device *alloc_dev(int minor)
33830 rwlock_init(&md->map_lock);
33831 atomic_set(&md->holders, 1);
33832 atomic_set(&md->open_count, 0);
33833- atomic_set(&md->event_nr, 0);
33834- atomic_set(&md->uevent_seq, 0);
33835+ atomic_set_unchecked(&md->event_nr, 0);
33836+ atomic_set_unchecked(&md->uevent_seq, 0);
33837 INIT_LIST_HEAD(&md->uevent_list);
33838 spin_lock_init(&md->uevent_lock);
33839
33840@@ -2022,7 +2022,7 @@ static void event_callback(void *context)
33841
33842 dm_send_uevents(&uevents, &disk_to_dev(md->disk)->kobj);
33843
33844- atomic_inc(&md->event_nr);
33845+ atomic_inc_unchecked(&md->event_nr);
33846 wake_up(&md->eventq);
33847 }
33848
33849@@ -2677,18 +2677,18 @@ int dm_kobject_uevent(struct mapped_device *md, enum kobject_action action,
33850
33851 uint32_t dm_next_uevent_seq(struct mapped_device *md)
33852 {
33853- return atomic_add_return(1, &md->uevent_seq);
33854+ return atomic_add_return_unchecked(1, &md->uevent_seq);
33855 }
33856
33857 uint32_t dm_get_event_nr(struct mapped_device *md)
33858 {
33859- return atomic_read(&md->event_nr);
33860+ return atomic_read_unchecked(&md->event_nr);
33861 }
33862
33863 int dm_wait_event(struct mapped_device *md, int event_nr)
33864 {
33865 return wait_event_interruptible(md->eventq,
33866- (event_nr != atomic_read(&md->event_nr)));
33867+ (event_nr != atomic_read_unchecked(&md->event_nr)));
33868 }
33869
33870 void dm_uevent_add(struct mapped_device *md, struct list_head *elist)
33871diff --git a/drivers/md/md.c b/drivers/md/md.c
33872index 308e87b..7f365d6 100644
33873--- a/drivers/md/md.c
33874+++ b/drivers/md/md.c
33875@@ -277,10 +277,10 @@ EXPORT_SYMBOL_GPL(md_trim_bio);
33876 * start build, activate spare
33877 */
33878 static DECLARE_WAIT_QUEUE_HEAD(md_event_waiters);
33879-static atomic_t md_event_count;
33880+static atomic_unchecked_t md_event_count;
33881 void md_new_event(struct mddev *mddev)
33882 {
33883- atomic_inc(&md_event_count);
33884+ atomic_inc_unchecked(&md_event_count);
33885 wake_up(&md_event_waiters);
33886 }
33887 EXPORT_SYMBOL_GPL(md_new_event);
33888@@ -290,7 +290,7 @@ EXPORT_SYMBOL_GPL(md_new_event);
33889 */
33890 static void md_new_event_inintr(struct mddev *mddev)
33891 {
33892- atomic_inc(&md_event_count);
33893+ atomic_inc_unchecked(&md_event_count);
33894 wake_up(&md_event_waiters);
33895 }
33896
33897@@ -1519,7 +1519,7 @@ static int super_1_load(struct md_rdev *rdev, struct md_rdev *refdev, int minor_
33898 if ((le32_to_cpu(sb->feature_map) & MD_FEATURE_RESHAPE_ACTIVE) &&
33899 (le32_to_cpu(sb->feature_map) & MD_FEATURE_NEW_OFFSET))
33900 rdev->new_data_offset += (s32)le32_to_cpu(sb->new_offset);
33901- atomic_set(&rdev->corrected_errors, le32_to_cpu(sb->cnt_corrected_read));
33902+ atomic_set_unchecked(&rdev->corrected_errors, le32_to_cpu(sb->cnt_corrected_read));
33903
33904 rdev->sb_size = le32_to_cpu(sb->max_dev) * 2 + 256;
33905 bmask = queue_logical_block_size(rdev->bdev->bd_disk->queue)-1;
33906@@ -1763,7 +1763,7 @@ static void super_1_sync(struct mddev *mddev, struct md_rdev *rdev)
33907 else
33908 sb->resync_offset = cpu_to_le64(0);
33909
33910- sb->cnt_corrected_read = cpu_to_le32(atomic_read(&rdev->corrected_errors));
33911+ sb->cnt_corrected_read = cpu_to_le32(atomic_read_unchecked(&rdev->corrected_errors));
33912
33913 sb->raid_disks = cpu_to_le32(mddev->raid_disks);
33914 sb->size = cpu_to_le64(mddev->dev_sectors);
33915@@ -2757,7 +2757,7 @@ __ATTR(state, S_IRUGO|S_IWUSR, state_show, state_store);
33916 static ssize_t
33917 errors_show(struct md_rdev *rdev, char *page)
33918 {
33919- return sprintf(page, "%d\n", atomic_read(&rdev->corrected_errors));
33920+ return sprintf(page, "%d\n", atomic_read_unchecked(&rdev->corrected_errors));
33921 }
33922
33923 static ssize_t
33924@@ -2766,7 +2766,7 @@ errors_store(struct md_rdev *rdev, const char *buf, size_t len)
33925 char *e;
33926 unsigned long n = simple_strtoul(buf, &e, 10);
33927 if (*buf && (*e == 0 || *e == '\n')) {
33928- atomic_set(&rdev->corrected_errors, n);
33929+ atomic_set_unchecked(&rdev->corrected_errors, n);
33930 return len;
33931 }
33932 return -EINVAL;
33933@@ -3213,8 +3213,8 @@ int md_rdev_init(struct md_rdev *rdev)
33934 rdev->sb_loaded = 0;
33935 rdev->bb_page = NULL;
33936 atomic_set(&rdev->nr_pending, 0);
33937- atomic_set(&rdev->read_errors, 0);
33938- atomic_set(&rdev->corrected_errors, 0);
33939+ atomic_set_unchecked(&rdev->read_errors, 0);
33940+ atomic_set_unchecked(&rdev->corrected_errors, 0);
33941
33942 INIT_LIST_HEAD(&rdev->same_set);
33943 init_waitqueue_head(&rdev->blocked_wait);
33944@@ -6947,7 +6947,7 @@ static int md_seq_show(struct seq_file *seq, void *v)
33945
33946 spin_unlock(&pers_lock);
33947 seq_printf(seq, "\n");
33948- seq->poll_event = atomic_read(&md_event_count);
33949+ seq->poll_event = atomic_read_unchecked(&md_event_count);
33950 return 0;
33951 }
33952 if (v == (void*)2) {
33953@@ -7050,7 +7050,7 @@ static int md_seq_open(struct inode *inode, struct file *file)
33954 return error;
33955
33956 seq = file->private_data;
33957- seq->poll_event = atomic_read(&md_event_count);
33958+ seq->poll_event = atomic_read_unchecked(&md_event_count);
33959 return error;
33960 }
33961
33962@@ -7064,7 +7064,7 @@ static unsigned int mdstat_poll(struct file *filp, poll_table *wait)
33963 /* always allow read */
33964 mask = POLLIN | POLLRDNORM;
33965
33966- if (seq->poll_event != atomic_read(&md_event_count))
33967+ if (seq->poll_event != atomic_read_unchecked(&md_event_count))
33968 mask |= POLLERR | POLLPRI;
33969 return mask;
33970 }
33971@@ -7108,7 +7108,7 @@ static int is_mddev_idle(struct mddev *mddev, int init)
33972 struct gendisk *disk = rdev->bdev->bd_contains->bd_disk;
33973 curr_events = (int)part_stat_read(&disk->part0, sectors[0]) +
33974 (int)part_stat_read(&disk->part0, sectors[1]) -
33975- atomic_read(&disk->sync_io);
33976+ atomic_read_unchecked(&disk->sync_io);
33977 /* sync IO will cause sync_io to increase before the disk_stats
33978 * as sync_io is counted when a request starts, and
33979 * disk_stats is counted when it completes.
33980diff --git a/drivers/md/md.h b/drivers/md/md.h
33981index f385b03..b600be8 100644
33982--- a/drivers/md/md.h
33983+++ b/drivers/md/md.h
33984@@ -94,13 +94,13 @@ struct md_rdev {
33985 * only maintained for arrays that
33986 * support hot removal
33987 */
33988- atomic_t read_errors; /* number of consecutive read errors that
33989+ atomic_unchecked_t read_errors; /* number of consecutive read errors that
33990 * we have tried to ignore.
33991 */
33992 struct timespec last_read_error; /* monotonic time since our
33993 * last read error
33994 */
33995- atomic_t corrected_errors; /* number of corrected read errors,
33996+ atomic_unchecked_t corrected_errors; /* number of corrected read errors,
33997 * for reporting to userspace and storing
33998 * in superblock.
33999 */
34000@@ -432,7 +432,7 @@ static inline void rdev_dec_pending(struct md_rdev *rdev, struct mddev *mddev)
34001
34002 static inline void md_sync_acct(struct block_device *bdev, unsigned long nr_sectors)
34003 {
34004- atomic_add(nr_sectors, &bdev->bd_contains->bd_disk->sync_io);
34005+ atomic_add_unchecked(nr_sectors, &bdev->bd_contains->bd_disk->sync_io);
34006 }
34007
34008 struct md_personality
34009diff --git a/drivers/md/persistent-data/dm-space-map-disk.c b/drivers/md/persistent-data/dm-space-map-disk.c
34010index f6d29e6..7917f5e 100644
34011--- a/drivers/md/persistent-data/dm-space-map-disk.c
34012+++ b/drivers/md/persistent-data/dm-space-map-disk.c
34013@@ -22,7 +22,7 @@
34014 * Space map interface.
34015 */
34016 struct sm_disk {
34017- struct dm_space_map sm;
34018+ dm_space_map_no_const sm;
34019
34020 struct ll_disk ll;
34021 struct ll_disk old_ll;
34022diff --git a/drivers/md/persistent-data/dm-space-map-metadata.c b/drivers/md/persistent-data/dm-space-map-metadata.c
34023index e89ae5e..062e4c2 100644
34024--- a/drivers/md/persistent-data/dm-space-map-metadata.c
34025+++ b/drivers/md/persistent-data/dm-space-map-metadata.c
34026@@ -43,7 +43,7 @@ struct block_op {
34027 };
34028
34029 struct sm_metadata {
34030- struct dm_space_map sm;
34031+ dm_space_map_no_const sm;
34032
34033 struct ll_disk ll;
34034 struct ll_disk old_ll;
34035diff --git a/drivers/md/persistent-data/dm-space-map.h b/drivers/md/persistent-data/dm-space-map.h
34036index 1cbfc6b..56e1dbb 100644
34037--- a/drivers/md/persistent-data/dm-space-map.h
34038+++ b/drivers/md/persistent-data/dm-space-map.h
34039@@ -60,6 +60,7 @@ struct dm_space_map {
34040 int (*root_size)(struct dm_space_map *sm, size_t *result);
34041 int (*copy_root)(struct dm_space_map *sm, void *copy_to_here_le, size_t len);
34042 };
34043+typedef struct dm_space_map __no_const dm_space_map_no_const;
34044
34045 /*----------------------------------------------------------------*/
34046
34047diff --git a/drivers/md/raid1.c b/drivers/md/raid1.c
34048index 05bb49e..84d7ce6 100644
34049--- a/drivers/md/raid1.c
34050+++ b/drivers/md/raid1.c
34051@@ -1810,7 +1810,7 @@ static int fix_sync_read_error(struct r1bio *r1_bio)
34052 if (r1_sync_page_io(rdev, sect, s,
34053 bio->bi_io_vec[idx].bv_page,
34054 READ) != 0)
34055- atomic_add(s, &rdev->corrected_errors);
34056+ atomic_add_unchecked(s, &rdev->corrected_errors);
34057 }
34058 sectors -= s;
34059 sect += s;
34060@@ -2032,7 +2032,7 @@ static void fix_read_error(struct r1conf *conf, int read_disk,
34061 test_bit(In_sync, &rdev->flags)) {
34062 if (r1_sync_page_io(rdev, sect, s,
34063 conf->tmppage, READ)) {
34064- atomic_add(s, &rdev->corrected_errors);
34065+ atomic_add_unchecked(s, &rdev->corrected_errors);
34066 printk(KERN_INFO
34067 "md/raid1:%s: read error corrected "
34068 "(%d sectors at %llu on %s)\n",
34069diff --git a/drivers/md/raid10.c b/drivers/md/raid10.c
34070index a48c215..6bda6f4 100644
34071--- a/drivers/md/raid10.c
34072+++ b/drivers/md/raid10.c
34073@@ -1810,7 +1810,7 @@ static void end_sync_read(struct bio *bio, int error)
34074 /* The write handler will notice the lack of
34075 * R10BIO_Uptodate and record any errors etc
34076 */
34077- atomic_add(r10_bio->sectors,
34078+ atomic_add_unchecked(r10_bio->sectors,
34079 &conf->mirrors[d].rdev->corrected_errors);
34080
34081 /* for reconstruct, we always reschedule after a read.
34082@@ -2159,7 +2159,7 @@ static void check_decay_read_errors(struct mddev *mddev, struct md_rdev *rdev)
34083 {
34084 struct timespec cur_time_mon;
34085 unsigned long hours_since_last;
34086- unsigned int read_errors = atomic_read(&rdev->read_errors);
34087+ unsigned int read_errors = atomic_read_unchecked(&rdev->read_errors);
34088
34089 ktime_get_ts(&cur_time_mon);
34090
34091@@ -2181,9 +2181,9 @@ static void check_decay_read_errors(struct mddev *mddev, struct md_rdev *rdev)
34092 * overflowing the shift of read_errors by hours_since_last.
34093 */
34094 if (hours_since_last >= 8 * sizeof(read_errors))
34095- atomic_set(&rdev->read_errors, 0);
34096+ atomic_set_unchecked(&rdev->read_errors, 0);
34097 else
34098- atomic_set(&rdev->read_errors, read_errors >> hours_since_last);
34099+ atomic_set_unchecked(&rdev->read_errors, read_errors >> hours_since_last);
34100 }
34101
34102 static int r10_sync_page_io(struct md_rdev *rdev, sector_t sector,
34103@@ -2237,8 +2237,8 @@ static void fix_read_error(struct r10conf *conf, struct mddev *mddev, struct r10
34104 return;
34105
34106 check_decay_read_errors(mddev, rdev);
34107- atomic_inc(&rdev->read_errors);
34108- if (atomic_read(&rdev->read_errors) > max_read_errors) {
34109+ atomic_inc_unchecked(&rdev->read_errors);
34110+ if (atomic_read_unchecked(&rdev->read_errors) > max_read_errors) {
34111 char b[BDEVNAME_SIZE];
34112 bdevname(rdev->bdev, b);
34113
34114@@ -2246,7 +2246,7 @@ static void fix_read_error(struct r10conf *conf, struct mddev *mddev, struct r10
34115 "md/raid10:%s: %s: Raid device exceeded "
34116 "read_error threshold [cur %d:max %d]\n",
34117 mdname(mddev), b,
34118- atomic_read(&rdev->read_errors), max_read_errors);
34119+ atomic_read_unchecked(&rdev->read_errors), max_read_errors);
34120 printk(KERN_NOTICE
34121 "md/raid10:%s: %s: Failing raid device\n",
34122 mdname(mddev), b);
34123@@ -2401,7 +2401,7 @@ static void fix_read_error(struct r10conf *conf, struct mddev *mddev, struct r10
34124 sect +
34125 choose_data_offset(r10_bio, rdev)),
34126 bdevname(rdev->bdev, b));
34127- atomic_add(s, &rdev->corrected_errors);
34128+ atomic_add_unchecked(s, &rdev->corrected_errors);
34129 }
34130
34131 rdev_dec_pending(rdev, mddev);
34132diff --git a/drivers/md/raid5.c b/drivers/md/raid5.c
34133index 0689173..35df76c 100644
34134--- a/drivers/md/raid5.c
34135+++ b/drivers/md/raid5.c
34136@@ -1756,21 +1756,21 @@ static void raid5_end_read_request(struct bio * bi, int error)
34137 mdname(conf->mddev), STRIPE_SECTORS,
34138 (unsigned long long)s,
34139 bdevname(rdev->bdev, b));
34140- atomic_add(STRIPE_SECTORS, &rdev->corrected_errors);
34141+ atomic_add_unchecked(STRIPE_SECTORS, &rdev->corrected_errors);
34142 clear_bit(R5_ReadError, &sh->dev[i].flags);
34143 clear_bit(R5_ReWrite, &sh->dev[i].flags);
34144 } else if (test_bit(R5_ReadNoMerge, &sh->dev[i].flags))
34145 clear_bit(R5_ReadNoMerge, &sh->dev[i].flags);
34146
34147- if (atomic_read(&rdev->read_errors))
34148- atomic_set(&rdev->read_errors, 0);
34149+ if (atomic_read_unchecked(&rdev->read_errors))
34150+ atomic_set_unchecked(&rdev->read_errors, 0);
34151 } else {
34152 const char *bdn = bdevname(rdev->bdev, b);
34153 int retry = 0;
34154 int set_bad = 0;
34155
34156 clear_bit(R5_UPTODATE, &sh->dev[i].flags);
34157- atomic_inc(&rdev->read_errors);
34158+ atomic_inc_unchecked(&rdev->read_errors);
34159 if (test_bit(R5_ReadRepl, &sh->dev[i].flags))
34160 printk_ratelimited(
34161 KERN_WARNING
34162@@ -1798,7 +1798,7 @@ static void raid5_end_read_request(struct bio * bi, int error)
34163 mdname(conf->mddev),
34164 (unsigned long long)s,
34165 bdn);
34166- } else if (atomic_read(&rdev->read_errors)
34167+ } else if (atomic_read_unchecked(&rdev->read_errors)
34168 > conf->max_nr_stripes)
34169 printk(KERN_WARNING
34170 "md/raid:%s: Too many read errors, failing device %s.\n",
34171diff --git a/drivers/media/dvb/ddbridge/ddbridge-core.c b/drivers/media/dvb/ddbridge/ddbridge-core.c
34172index ebf3f05..b1f3e77 100644
34173--- a/drivers/media/dvb/ddbridge/ddbridge-core.c
34174+++ b/drivers/media/dvb/ddbridge/ddbridge-core.c
34175@@ -1679,7 +1679,7 @@ static struct ddb_info ddb_v6 = {
34176 .subvendor = _subvend, .subdevice = _subdev, \
34177 .driver_data = (unsigned long)&_driverdata }
34178
34179-static const struct pci_device_id ddb_id_tbl[] __devinitdata = {
34180+static const struct pci_device_id ddb_id_tbl[] __devinitconst = {
34181 DDB_ID(DDVID, 0x0002, DDVID, 0x0001, ddb_octopus),
34182 DDB_ID(DDVID, 0x0003, DDVID, 0x0001, ddb_octopus),
34183 DDB_ID(DDVID, 0x0003, DDVID, 0x0002, ddb_octopus_le),
34184diff --git a/drivers/media/dvb/dvb-core/dvb_demux.h b/drivers/media/dvb/dvb-core/dvb_demux.h
34185index fa7188a..04a045e 100644
34186--- a/drivers/media/dvb/dvb-core/dvb_demux.h
34187+++ b/drivers/media/dvb/dvb-core/dvb_demux.h
34188@@ -73,7 +73,7 @@ struct dvb_demux_feed {
34189 union {
34190 dmx_ts_cb ts;
34191 dmx_section_cb sec;
34192- } cb;
34193+ } __no_const cb;
34194
34195 struct dvb_demux *demux;
34196 void *priv;
34197diff --git a/drivers/media/dvb/dvb-core/dvbdev.c b/drivers/media/dvb/dvb-core/dvbdev.c
34198index 39eab73..60033e7 100644
34199--- a/drivers/media/dvb/dvb-core/dvbdev.c
34200+++ b/drivers/media/dvb/dvb-core/dvbdev.c
34201@@ -192,7 +192,7 @@ int dvb_register_device(struct dvb_adapter *adap, struct dvb_device **pdvbdev,
34202 const struct dvb_device *template, void *priv, int type)
34203 {
34204 struct dvb_device *dvbdev;
34205- struct file_operations *dvbdevfops;
34206+ file_operations_no_const *dvbdevfops;
34207 struct device *clsdev;
34208 int minor;
34209 int id;
34210diff --git a/drivers/media/dvb/dvb-usb/cxusb.c b/drivers/media/dvb/dvb-usb/cxusb.c
34211index 3940bb0..fb3952a 100644
34212--- a/drivers/media/dvb/dvb-usb/cxusb.c
34213+++ b/drivers/media/dvb/dvb-usb/cxusb.c
34214@@ -1068,7 +1068,7 @@ static struct dib0070_config dib7070p_dib0070_config = {
34215
34216 struct dib0700_adapter_state {
34217 int (*set_param_save) (struct dvb_frontend *);
34218-};
34219+} __no_const;
34220
34221 static int dib7070_set_param_override(struct dvb_frontend *fe)
34222 {
34223diff --git a/drivers/media/dvb/dvb-usb/dw2102.c b/drivers/media/dvb/dvb-usb/dw2102.c
34224index 9382895..ac8093c 100644
34225--- a/drivers/media/dvb/dvb-usb/dw2102.c
34226+++ b/drivers/media/dvb/dvb-usb/dw2102.c
34227@@ -95,7 +95,7 @@ struct su3000_state {
34228
34229 struct s6x0_state {
34230 int (*old_set_voltage)(struct dvb_frontend *f, fe_sec_voltage_t v);
34231-};
34232+} __no_const;
34233
34234 /* debug */
34235 static int dvb_usb_dw2102_debug;
34236diff --git a/drivers/media/dvb/frontends/dib3000.h b/drivers/media/dvb/frontends/dib3000.h
34237index 404f63a..4796533 100644
34238--- a/drivers/media/dvb/frontends/dib3000.h
34239+++ b/drivers/media/dvb/frontends/dib3000.h
34240@@ -39,7 +39,7 @@ struct dib_fe_xfer_ops
34241 int (*fifo_ctrl)(struct dvb_frontend *fe, int onoff);
34242 int (*pid_ctrl)(struct dvb_frontend *fe, int index, int pid, int onoff);
34243 int (*tuner_pass_ctrl)(struct dvb_frontend *fe, int onoff, u8 pll_ctrl);
34244-};
34245+} __no_const;
34246
34247 #if defined(CONFIG_DVB_DIB3000MB) || (defined(CONFIG_DVB_DIB3000MB_MODULE) && defined(MODULE))
34248 extern struct dvb_frontend* dib3000mb_attach(const struct dib3000_config* config,
34249diff --git a/drivers/media/dvb/ngene/ngene-cards.c b/drivers/media/dvb/ngene/ngene-cards.c
34250index 72ee8de..eae0c80 100644
34251--- a/drivers/media/dvb/ngene/ngene-cards.c
34252+++ b/drivers/media/dvb/ngene/ngene-cards.c
34253@@ -479,7 +479,7 @@ static struct ngene_info ngene_info_m780 = {
34254
34255 /****************************************************************************/
34256
34257-static const struct pci_device_id ngene_id_tbl[] __devinitdata = {
34258+static const struct pci_device_id ngene_id_tbl[] __devinitconst = {
34259 NGENE_ID(0x18c3, 0xabc3, ngene_info_cineS2),
34260 NGENE_ID(0x18c3, 0xabc4, ngene_info_cineS2),
34261 NGENE_ID(0x18c3, 0xdb01, ngene_info_satixS2),
34262diff --git a/drivers/media/radio/radio-cadet.c b/drivers/media/radio/radio-cadet.c
34263index 697a421..16c5a5f 100644
34264--- a/drivers/media/radio/radio-cadet.c
34265+++ b/drivers/media/radio/radio-cadet.c
34266@@ -302,6 +302,8 @@ static ssize_t cadet_read(struct file *file, char __user *data, size_t count, lo
34267 unsigned char readbuf[RDS_BUFFER];
34268 int i = 0;
34269
34270+ if (count > RDS_BUFFER)
34271+ return -EFAULT;
34272 mutex_lock(&dev->lock);
34273 if (dev->rdsstat == 0)
34274 cadet_start_rds(dev);
34275@@ -317,7 +319,7 @@ static ssize_t cadet_read(struct file *file, char __user *data, size_t count, lo
34276 while (i < count && dev->rdsin != dev->rdsout)
34277 readbuf[i++] = dev->rdsbuf[dev->rdsout++];
34278
34279- if (i && copy_to_user(data, readbuf, i))
34280+ if (i > sizeof(readbuf) || copy_to_user(data, readbuf, i))
34281 i = -EFAULT;
34282 unlock:
34283 mutex_unlock(&dev->lock);
34284diff --git a/drivers/media/radio/radio-tea5777.h b/drivers/media/radio/radio-tea5777.h
34285index 55cbd78..428b0da 100644
34286--- a/drivers/media/radio/radio-tea5777.h
34287+++ b/drivers/media/radio/radio-tea5777.h
34288@@ -63,7 +63,7 @@ struct radio_tea5777_ops {
34289
34290 struct radio_tea5777 {
34291 struct v4l2_device *v4l2_dev;
34292- struct v4l2_file_operations fops;
34293+ v4l2_file_operations_no_const fops;
34294 struct video_device vd; /* video device */
34295 bool has_am; /* Device can tune to AM freqs */
34296 bool write_before_read; /* must write before read quirk */
34297diff --git a/drivers/media/video/au0828/au0828.h b/drivers/media/video/au0828/au0828.h
34298index 9cde353..8c6a1c3 100644
34299--- a/drivers/media/video/au0828/au0828.h
34300+++ b/drivers/media/video/au0828/au0828.h
34301@@ -191,7 +191,7 @@ struct au0828_dev {
34302
34303 /* I2C */
34304 struct i2c_adapter i2c_adap;
34305- struct i2c_algorithm i2c_algo;
34306+ i2c_algorithm_no_const i2c_algo;
34307 struct i2c_client i2c_client;
34308 u32 i2c_rc;
34309
34310diff --git a/drivers/media/video/cx88/cx88-alsa.c b/drivers/media/video/cx88/cx88-alsa.c
34311index dfac6e3..c26de31 100644
34312--- a/drivers/media/video/cx88/cx88-alsa.c
34313+++ b/drivers/media/video/cx88/cx88-alsa.c
34314@@ -749,7 +749,7 @@ static struct snd_kcontrol_new snd_cx88_alc_switch = {
34315 * Only boards with eeprom and byte 1 at eeprom=1 have it
34316 */
34317
34318-static const struct pci_device_id const cx88_audio_pci_tbl[] __devinitdata = {
34319+static const struct pci_device_id const cx88_audio_pci_tbl[] __devinitconst = {
34320 {0x14f1,0x8801,PCI_ANY_ID,PCI_ANY_ID,0,0,0},
34321 {0x14f1,0x8811,PCI_ANY_ID,PCI_ANY_ID,0,0,0},
34322 {0, }
34323diff --git a/drivers/media/video/omap/omap_vout.c b/drivers/media/video/omap/omap_vout.c
34324index 88cf9d9..bbc4b2c 100644
34325--- a/drivers/media/video/omap/omap_vout.c
34326+++ b/drivers/media/video/omap/omap_vout.c
34327@@ -64,7 +64,6 @@ enum omap_vout_channels {
34328 OMAP_VIDEO2,
34329 };
34330
34331-static struct videobuf_queue_ops video_vbq_ops;
34332 /* Variables configurable through module params*/
34333 static u32 video1_numbuffers = 3;
34334 static u32 video2_numbuffers = 3;
34335@@ -1000,6 +999,12 @@ static int omap_vout_open(struct file *file)
34336 {
34337 struct videobuf_queue *q;
34338 struct omap_vout_device *vout = NULL;
34339+ static struct videobuf_queue_ops video_vbq_ops = {
34340+ .buf_setup = omap_vout_buffer_setup,
34341+ .buf_prepare = omap_vout_buffer_prepare,
34342+ .buf_release = omap_vout_buffer_release,
34343+ .buf_queue = omap_vout_buffer_queue,
34344+ };
34345
34346 vout = video_drvdata(file);
34347 v4l2_dbg(1, debug, &vout->vid_dev->v4l2_dev, "Entering %s\n", __func__);
34348@@ -1017,10 +1022,6 @@ static int omap_vout_open(struct file *file)
34349 vout->type = V4L2_BUF_TYPE_VIDEO_OUTPUT;
34350
34351 q = &vout->vbq;
34352- video_vbq_ops.buf_setup = omap_vout_buffer_setup;
34353- video_vbq_ops.buf_prepare = omap_vout_buffer_prepare;
34354- video_vbq_ops.buf_release = omap_vout_buffer_release;
34355- video_vbq_ops.buf_queue = omap_vout_buffer_queue;
34356 spin_lock_init(&vout->vbq_lock);
34357
34358 videobuf_queue_dma_contig_init(q, &video_vbq_ops, q->dev,
34359diff --git a/drivers/media/video/pvrusb2/pvrusb2-hdw-internal.h b/drivers/media/video/pvrusb2/pvrusb2-hdw-internal.h
34360index 036952f..80d356d 100644
34361--- a/drivers/media/video/pvrusb2/pvrusb2-hdw-internal.h
34362+++ b/drivers/media/video/pvrusb2/pvrusb2-hdw-internal.h
34363@@ -196,7 +196,7 @@ struct pvr2_hdw {
34364
34365 /* I2C stuff */
34366 struct i2c_adapter i2c_adap;
34367- struct i2c_algorithm i2c_algo;
34368+ i2c_algorithm_no_const i2c_algo;
34369 pvr2_i2c_func i2c_func[PVR2_I2C_FUNC_CNT];
34370 int i2c_cx25840_hack_state;
34371 int i2c_linked;
34372diff --git a/drivers/media/video/timblogiw.c b/drivers/media/video/timblogiw.c
34373index 02194c0..091733b 100644
34374--- a/drivers/media/video/timblogiw.c
34375+++ b/drivers/media/video/timblogiw.c
34376@@ -745,7 +745,7 @@ static int timblogiw_mmap(struct file *file, struct vm_area_struct *vma)
34377
34378 /* Platform device functions */
34379
34380-static __devinitconst struct v4l2_ioctl_ops timblogiw_ioctl_ops = {
34381+static __devinitconst v4l2_ioctl_ops_no_const timblogiw_ioctl_ops = {
34382 .vidioc_querycap = timblogiw_querycap,
34383 .vidioc_enum_fmt_vid_cap = timblogiw_enum_fmt,
34384 .vidioc_g_fmt_vid_cap = timblogiw_g_fmt,
34385@@ -767,7 +767,7 @@ static __devinitconst struct v4l2_ioctl_ops timblogiw_ioctl_ops = {
34386 .vidioc_enum_framesizes = timblogiw_enum_framesizes,
34387 };
34388
34389-static __devinitconst struct v4l2_file_operations timblogiw_fops = {
34390+static __devinitconst v4l2_file_operations_no_const timblogiw_fops = {
34391 .owner = THIS_MODULE,
34392 .open = timblogiw_open,
34393 .release = timblogiw_close,
34394diff --git a/drivers/message/fusion/mptbase.c b/drivers/message/fusion/mptbase.c
34395index d99db56..a16b959 100644
34396--- a/drivers/message/fusion/mptbase.c
34397+++ b/drivers/message/fusion/mptbase.c
34398@@ -6751,8 +6751,13 @@ static int mpt_iocinfo_proc_show(struct seq_file *m, void *v)
34399 seq_printf(m, " MaxChainDepth = 0x%02x frames\n", ioc->facts.MaxChainDepth);
34400 seq_printf(m, " MinBlockSize = 0x%02x bytes\n", 4*ioc->facts.BlockSize);
34401
34402+#ifdef CONFIG_GRKERNSEC_HIDESYM
34403+ seq_printf(m, " RequestFrames @ 0x%p (Dma @ 0x%p)\n", NULL, NULL);
34404+#else
34405 seq_printf(m, " RequestFrames @ 0x%p (Dma @ 0x%p)\n",
34406 (void *)ioc->req_frames, (void *)(ulong)ioc->req_frames_dma);
34407+#endif
34408+
34409 /*
34410 * Rounding UP to nearest 4-kB boundary here...
34411 */
34412diff --git a/drivers/message/fusion/mptsas.c b/drivers/message/fusion/mptsas.c
34413index 551262e..7551198 100644
34414--- a/drivers/message/fusion/mptsas.c
34415+++ b/drivers/message/fusion/mptsas.c
34416@@ -446,6 +446,23 @@ mptsas_is_end_device(struct mptsas_devinfo * attached)
34417 return 0;
34418 }
34419
34420+static inline void
34421+mptsas_set_rphy(MPT_ADAPTER *ioc, struct mptsas_phyinfo *phy_info, struct sas_rphy *rphy)
34422+{
34423+ if (phy_info->port_details) {
34424+ phy_info->port_details->rphy = rphy;
34425+ dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "sas_rphy_add: rphy=%p\n",
34426+ ioc->name, rphy));
34427+ }
34428+
34429+ if (rphy) {
34430+ dsaswideprintk(ioc, dev_printk(KERN_DEBUG,
34431+ &rphy->dev, MYIOC_s_FMT "add:", ioc->name));
34432+ dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "rphy=%p release=%p\n",
34433+ ioc->name, rphy, rphy->dev.release));
34434+ }
34435+}
34436+
34437 /* no mutex */
34438 static void
34439 mptsas_port_delete(MPT_ADAPTER *ioc, struct mptsas_portinfo_details * port_details)
34440@@ -484,23 +501,6 @@ mptsas_get_rphy(struct mptsas_phyinfo *phy_info)
34441 return NULL;
34442 }
34443
34444-static inline void
34445-mptsas_set_rphy(MPT_ADAPTER *ioc, struct mptsas_phyinfo *phy_info, struct sas_rphy *rphy)
34446-{
34447- if (phy_info->port_details) {
34448- phy_info->port_details->rphy = rphy;
34449- dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "sas_rphy_add: rphy=%p\n",
34450- ioc->name, rphy));
34451- }
34452-
34453- if (rphy) {
34454- dsaswideprintk(ioc, dev_printk(KERN_DEBUG,
34455- &rphy->dev, MYIOC_s_FMT "add:", ioc->name));
34456- dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "rphy=%p release=%p\n",
34457- ioc->name, rphy, rphy->dev.release));
34458- }
34459-}
34460-
34461 static inline struct sas_port *
34462 mptsas_get_port(struct mptsas_phyinfo *phy_info)
34463 {
34464diff --git a/drivers/message/fusion/mptscsih.c b/drivers/message/fusion/mptscsih.c
34465index 0c3ced7..1fe34ec 100644
34466--- a/drivers/message/fusion/mptscsih.c
34467+++ b/drivers/message/fusion/mptscsih.c
34468@@ -1270,15 +1270,16 @@ mptscsih_info(struct Scsi_Host *SChost)
34469
34470 h = shost_priv(SChost);
34471
34472- if (h) {
34473- if (h->info_kbuf == NULL)
34474- if ((h->info_kbuf = kmalloc(0x1000 /* 4Kb */, GFP_KERNEL)) == NULL)
34475- return h->info_kbuf;
34476- h->info_kbuf[0] = '\0';
34477+ if (!h)
34478+ return NULL;
34479
34480- mpt_print_ioc_summary(h->ioc, h->info_kbuf, &size, 0, 0);
34481- h->info_kbuf[size-1] = '\0';
34482- }
34483+ if (h->info_kbuf == NULL)
34484+ if ((h->info_kbuf = kmalloc(0x1000 /* 4Kb */, GFP_KERNEL)) == NULL)
34485+ return h->info_kbuf;
34486+ h->info_kbuf[0] = '\0';
34487+
34488+ mpt_print_ioc_summary(h->ioc, h->info_kbuf, &size, 0, 0);
34489+ h->info_kbuf[size-1] = '\0';
34490
34491 return h->info_kbuf;
34492 }
34493diff --git a/drivers/message/i2o/i2o_proc.c b/drivers/message/i2o/i2o_proc.c
34494index 8001aa6..b137580 100644
34495--- a/drivers/message/i2o/i2o_proc.c
34496+++ b/drivers/message/i2o/i2o_proc.c
34497@@ -255,12 +255,6 @@ static char *scsi_devices[] = {
34498 "Array Controller Device"
34499 };
34500
34501-static char *chtostr(char *tmp, u8 *chars, int n)
34502-{
34503- tmp[0] = 0;
34504- return strncat(tmp, (char *)chars, n);
34505-}
34506-
34507 static int i2o_report_query_status(struct seq_file *seq, int block_status,
34508 char *group)
34509 {
34510@@ -790,7 +784,6 @@ static int i2o_seq_show_ddm_table(struct seq_file *seq, void *v)
34511 } *result;
34512
34513 i2o_exec_execute_ddm_table ddm_table;
34514- char tmp[28 + 1];
34515
34516 result = kmalloc(sizeof(*result), GFP_KERNEL);
34517 if (!result)
34518@@ -825,8 +818,7 @@ static int i2o_seq_show_ddm_table(struct seq_file *seq, void *v)
34519
34520 seq_printf(seq, "%-#7x", ddm_table.i2o_vendor_id);
34521 seq_printf(seq, "%-#8x", ddm_table.module_id);
34522- seq_printf(seq, "%-29s",
34523- chtostr(tmp, ddm_table.module_name_version, 28));
34524+ seq_printf(seq, "%-.28s", ddm_table.module_name_version);
34525 seq_printf(seq, "%9d ", ddm_table.data_size);
34526 seq_printf(seq, "%8d", ddm_table.code_size);
34527
34528@@ -893,7 +885,6 @@ static int i2o_seq_show_drivers_stored(struct seq_file *seq, void *v)
34529
34530 i2o_driver_result_table *result;
34531 i2o_driver_store_table *dst;
34532- char tmp[28 + 1];
34533
34534 result = kmalloc(sizeof(i2o_driver_result_table), GFP_KERNEL);
34535 if (result == NULL)
34536@@ -928,9 +919,8 @@ static int i2o_seq_show_drivers_stored(struct seq_file *seq, void *v)
34537
34538 seq_printf(seq, "%-#7x", dst->i2o_vendor_id);
34539 seq_printf(seq, "%-#8x", dst->module_id);
34540- seq_printf(seq, "%-29s",
34541- chtostr(tmp, dst->module_name_version, 28));
34542- seq_printf(seq, "%-9s", chtostr(tmp, dst->date, 8));
34543+ seq_printf(seq, "%-.28s", dst->module_name_version);
34544+ seq_printf(seq, "%-.8s", dst->date);
34545 seq_printf(seq, "%8d ", dst->module_size);
34546 seq_printf(seq, "%8d ", dst->mpb_size);
34547 seq_printf(seq, "0x%04x", dst->module_flags);
34548@@ -1250,7 +1240,6 @@ static int i2o_seq_show_dev_identity(struct seq_file *seq, void *v)
34549 // == (allow) 512d bytes (max)
34550 static u16 *work16 = (u16 *) work32;
34551 int token;
34552- char tmp[16 + 1];
34553
34554 token = i2o_parm_field_get(d, 0xF100, -1, &work32, sizeof(work32));
34555
34556@@ -1262,14 +1251,10 @@ static int i2o_seq_show_dev_identity(struct seq_file *seq, void *v)
34557 seq_printf(seq, "Device Class : %s\n", i2o_get_class_name(work16[0]));
34558 seq_printf(seq, "Owner TID : %0#5x\n", work16[2]);
34559 seq_printf(seq, "Parent TID : %0#5x\n", work16[3]);
34560- seq_printf(seq, "Vendor info : %s\n",
34561- chtostr(tmp, (u8 *) (work32 + 2), 16));
34562- seq_printf(seq, "Product info : %s\n",
34563- chtostr(tmp, (u8 *) (work32 + 6), 16));
34564- seq_printf(seq, "Description : %s\n",
34565- chtostr(tmp, (u8 *) (work32 + 10), 16));
34566- seq_printf(seq, "Product rev. : %s\n",
34567- chtostr(tmp, (u8 *) (work32 + 14), 8));
34568+ seq_printf(seq, "Vendor info : %.16s\n", (u8 *) (work32 + 2));
34569+ seq_printf(seq, "Product info : %.16s\n", (u8 *) (work32 + 6));
34570+ seq_printf(seq, "Description : %.16s\n", (u8 *) (work32 + 10));
34571+ seq_printf(seq, "Product rev. : %.8s\n", (u8 *) (work32 + 14));
34572
34573 seq_printf(seq, "Serial number : ");
34574 print_serial_number(seq, (u8 *) (work32 + 16),
34575@@ -1306,8 +1291,6 @@ static int i2o_seq_show_ddm_identity(struct seq_file *seq, void *v)
34576 u8 pad[256]; // allow up to 256 byte (max) serial number
34577 } result;
34578
34579- char tmp[24 + 1];
34580-
34581 token = i2o_parm_field_get(d, 0xF101, -1, &result, sizeof(result));
34582
34583 if (token < 0) {
34584@@ -1316,10 +1299,8 @@ static int i2o_seq_show_ddm_identity(struct seq_file *seq, void *v)
34585 }
34586
34587 seq_printf(seq, "Registering DDM TID : 0x%03x\n", result.ddm_tid);
34588- seq_printf(seq, "Module name : %s\n",
34589- chtostr(tmp, result.module_name, 24));
34590- seq_printf(seq, "Module revision : %s\n",
34591- chtostr(tmp, result.module_rev, 8));
34592+ seq_printf(seq, "Module name : %.24s\n", result.module_name);
34593+ seq_printf(seq, "Module revision : %.8s\n", result.module_rev);
34594
34595 seq_printf(seq, "Serial number : ");
34596 print_serial_number(seq, result.serial_number, sizeof(result) - 36);
34597@@ -1343,8 +1324,6 @@ static int i2o_seq_show_uinfo(struct seq_file *seq, void *v)
34598 u8 instance_number[4];
34599 } result;
34600
34601- char tmp[64 + 1];
34602-
34603 token = i2o_parm_field_get(d, 0xF102, -1, &result, sizeof(result));
34604
34605 if (token < 0) {
34606@@ -1352,14 +1331,10 @@ static int i2o_seq_show_uinfo(struct seq_file *seq, void *v)
34607 return 0;
34608 }
34609
34610- seq_printf(seq, "Device name : %s\n",
34611- chtostr(tmp, result.device_name, 64));
34612- seq_printf(seq, "Service name : %s\n",
34613- chtostr(tmp, result.service_name, 64));
34614- seq_printf(seq, "Physical name : %s\n",
34615- chtostr(tmp, result.physical_location, 64));
34616- seq_printf(seq, "Instance number : %s\n",
34617- chtostr(tmp, result.instance_number, 4));
34618+ seq_printf(seq, "Device name : %.64s\n", result.device_name);
34619+ seq_printf(seq, "Service name : %.64s\n", result.service_name);
34620+ seq_printf(seq, "Physical name : %.64s\n", result.physical_location);
34621+ seq_printf(seq, "Instance number : %.4s\n", result.instance_number);
34622
34623 return 0;
34624 }
34625diff --git a/drivers/message/i2o/iop.c b/drivers/message/i2o/iop.c
34626index a8c08f3..155fe3d 100644
34627--- a/drivers/message/i2o/iop.c
34628+++ b/drivers/message/i2o/iop.c
34629@@ -111,10 +111,10 @@ u32 i2o_cntxt_list_add(struct i2o_controller * c, void *ptr)
34630
34631 spin_lock_irqsave(&c->context_list_lock, flags);
34632
34633- if (unlikely(atomic_inc_and_test(&c->context_list_counter)))
34634- atomic_inc(&c->context_list_counter);
34635+ if (unlikely(atomic_inc_and_test_unchecked(&c->context_list_counter)))
34636+ atomic_inc_unchecked(&c->context_list_counter);
34637
34638- entry->context = atomic_read(&c->context_list_counter);
34639+ entry->context = atomic_read_unchecked(&c->context_list_counter);
34640
34641 list_add(&entry->list, &c->context_list);
34642
34643@@ -1077,7 +1077,7 @@ struct i2o_controller *i2o_iop_alloc(void)
34644
34645 #if BITS_PER_LONG == 64
34646 spin_lock_init(&c->context_list_lock);
34647- atomic_set(&c->context_list_counter, 0);
34648+ atomic_set_unchecked(&c->context_list_counter, 0);
34649 INIT_LIST_HEAD(&c->context_list);
34650 #endif
34651
34652diff --git a/drivers/mfd/abx500-core.c b/drivers/mfd/abx500-core.c
34653index 7ce65f4..e66e9bc 100644
34654--- a/drivers/mfd/abx500-core.c
34655+++ b/drivers/mfd/abx500-core.c
34656@@ -15,7 +15,7 @@ static LIST_HEAD(abx500_list);
34657
34658 struct abx500_device_entry {
34659 struct list_head list;
34660- struct abx500_ops ops;
34661+ abx500_ops_no_const ops;
34662 struct device *dev;
34663 };
34664
34665diff --git a/drivers/mfd/janz-cmodio.c b/drivers/mfd/janz-cmodio.c
34666index 965c480..71f2db9 100644
34667--- a/drivers/mfd/janz-cmodio.c
34668+++ b/drivers/mfd/janz-cmodio.c
34669@@ -13,6 +13,7 @@
34670
34671 #include <linux/kernel.h>
34672 #include <linux/module.h>
34673+#include <linux/slab.h>
34674 #include <linux/init.h>
34675 #include <linux/pci.h>
34676 #include <linux/interrupt.h>
34677diff --git a/drivers/misc/lis3lv02d/lis3lv02d.c b/drivers/misc/lis3lv02d/lis3lv02d.c
34678index a981e2a..5ca0c8b 100644
34679--- a/drivers/misc/lis3lv02d/lis3lv02d.c
34680+++ b/drivers/misc/lis3lv02d/lis3lv02d.c
34681@@ -466,7 +466,7 @@ static irqreturn_t lis302dl_interrupt(int irq, void *data)
34682 * the lid is closed. This leads to interrupts as soon as a little move
34683 * is done.
34684 */
34685- atomic_inc(&lis3->count);
34686+ atomic_inc_unchecked(&lis3->count);
34687
34688 wake_up_interruptible(&lis3->misc_wait);
34689 kill_fasync(&lis3->async_queue, SIGIO, POLL_IN);
34690@@ -552,7 +552,7 @@ static int lis3lv02d_misc_open(struct inode *inode, struct file *file)
34691 if (lis3->pm_dev)
34692 pm_runtime_get_sync(lis3->pm_dev);
34693
34694- atomic_set(&lis3->count, 0);
34695+ atomic_set_unchecked(&lis3->count, 0);
34696 return 0;
34697 }
34698
34699@@ -585,7 +585,7 @@ static ssize_t lis3lv02d_misc_read(struct file *file, char __user *buf,
34700 add_wait_queue(&lis3->misc_wait, &wait);
34701 while (true) {
34702 set_current_state(TASK_INTERRUPTIBLE);
34703- data = atomic_xchg(&lis3->count, 0);
34704+ data = atomic_xchg_unchecked(&lis3->count, 0);
34705 if (data)
34706 break;
34707
34708@@ -626,7 +626,7 @@ static unsigned int lis3lv02d_misc_poll(struct file *file, poll_table *wait)
34709 struct lis3lv02d, miscdev);
34710
34711 poll_wait(file, &lis3->misc_wait, wait);
34712- if (atomic_read(&lis3->count))
34713+ if (atomic_read_unchecked(&lis3->count))
34714 return POLLIN | POLLRDNORM;
34715 return 0;
34716 }
34717diff --git a/drivers/misc/lis3lv02d/lis3lv02d.h b/drivers/misc/lis3lv02d/lis3lv02d.h
34718index 2b1482a..5d33616 100644
34719--- a/drivers/misc/lis3lv02d/lis3lv02d.h
34720+++ b/drivers/misc/lis3lv02d/lis3lv02d.h
34721@@ -266,7 +266,7 @@ struct lis3lv02d {
34722 struct input_polled_dev *idev; /* input device */
34723 struct platform_device *pdev; /* platform device */
34724 struct regulator_bulk_data regulators[2];
34725- atomic_t count; /* interrupt count after last read */
34726+ atomic_unchecked_t count; /* interrupt count after last read */
34727 union axis_conversion ac; /* hw -> logical axis */
34728 int mapped_btns[3];
34729
34730diff --git a/drivers/misc/sgi-gru/gruhandles.c b/drivers/misc/sgi-gru/gruhandles.c
34731index 2f30bad..c4c13d0 100644
34732--- a/drivers/misc/sgi-gru/gruhandles.c
34733+++ b/drivers/misc/sgi-gru/gruhandles.c
34734@@ -44,8 +44,8 @@ static void update_mcs_stats(enum mcs_op op, unsigned long clks)
34735 unsigned long nsec;
34736
34737 nsec = CLKS2NSEC(clks);
34738- atomic_long_inc(&mcs_op_statistics[op].count);
34739- atomic_long_add(nsec, &mcs_op_statistics[op].total);
34740+ atomic_long_inc_unchecked(&mcs_op_statistics[op].count);
34741+ atomic_long_add_unchecked(nsec, &mcs_op_statistics[op].total);
34742 if (mcs_op_statistics[op].max < nsec)
34743 mcs_op_statistics[op].max = nsec;
34744 }
34745diff --git a/drivers/misc/sgi-gru/gruprocfs.c b/drivers/misc/sgi-gru/gruprocfs.c
34746index 950dbe9..eeef0f8 100644
34747--- a/drivers/misc/sgi-gru/gruprocfs.c
34748+++ b/drivers/misc/sgi-gru/gruprocfs.c
34749@@ -32,9 +32,9 @@
34750
34751 #define printstat(s, f) printstat_val(s, &gru_stats.f, #f)
34752
34753-static void printstat_val(struct seq_file *s, atomic_long_t *v, char *id)
34754+static void printstat_val(struct seq_file *s, atomic_long_unchecked_t *v, char *id)
34755 {
34756- unsigned long val = atomic_long_read(v);
34757+ unsigned long val = atomic_long_read_unchecked(v);
34758
34759 seq_printf(s, "%16lu %s\n", val, id);
34760 }
34761@@ -134,8 +134,8 @@ static int mcs_statistics_show(struct seq_file *s, void *p)
34762
34763 seq_printf(s, "%-20s%12s%12s%12s\n", "#id", "count", "aver-clks", "max-clks");
34764 for (op = 0; op < mcsop_last; op++) {
34765- count = atomic_long_read(&mcs_op_statistics[op].count);
34766- total = atomic_long_read(&mcs_op_statistics[op].total);
34767+ count = atomic_long_read_unchecked(&mcs_op_statistics[op].count);
34768+ total = atomic_long_read_unchecked(&mcs_op_statistics[op].total);
34769 max = mcs_op_statistics[op].max;
34770 seq_printf(s, "%-20s%12ld%12ld%12ld\n", id[op], count,
34771 count ? total / count : 0, max);
34772diff --git a/drivers/misc/sgi-gru/grutables.h b/drivers/misc/sgi-gru/grutables.h
34773index 5c3ce24..4915ccb 100644
34774--- a/drivers/misc/sgi-gru/grutables.h
34775+++ b/drivers/misc/sgi-gru/grutables.h
34776@@ -167,82 +167,82 @@ extern unsigned int gru_max_gids;
34777 * GRU statistics.
34778 */
34779 struct gru_stats_s {
34780- atomic_long_t vdata_alloc;
34781- atomic_long_t vdata_free;
34782- atomic_long_t gts_alloc;
34783- atomic_long_t gts_free;
34784- atomic_long_t gms_alloc;
34785- atomic_long_t gms_free;
34786- atomic_long_t gts_double_allocate;
34787- atomic_long_t assign_context;
34788- atomic_long_t assign_context_failed;
34789- atomic_long_t free_context;
34790- atomic_long_t load_user_context;
34791- atomic_long_t load_kernel_context;
34792- atomic_long_t lock_kernel_context;
34793- atomic_long_t unlock_kernel_context;
34794- atomic_long_t steal_user_context;
34795- atomic_long_t steal_kernel_context;
34796- atomic_long_t steal_context_failed;
34797- atomic_long_t nopfn;
34798- atomic_long_t asid_new;
34799- atomic_long_t asid_next;
34800- atomic_long_t asid_wrap;
34801- atomic_long_t asid_reuse;
34802- atomic_long_t intr;
34803- atomic_long_t intr_cbr;
34804- atomic_long_t intr_tfh;
34805- atomic_long_t intr_spurious;
34806- atomic_long_t intr_mm_lock_failed;
34807- atomic_long_t call_os;
34808- atomic_long_t call_os_wait_queue;
34809- atomic_long_t user_flush_tlb;
34810- atomic_long_t user_unload_context;
34811- atomic_long_t user_exception;
34812- atomic_long_t set_context_option;
34813- atomic_long_t check_context_retarget_intr;
34814- atomic_long_t check_context_unload;
34815- atomic_long_t tlb_dropin;
34816- atomic_long_t tlb_preload_page;
34817- atomic_long_t tlb_dropin_fail_no_asid;
34818- atomic_long_t tlb_dropin_fail_upm;
34819- atomic_long_t tlb_dropin_fail_invalid;
34820- atomic_long_t tlb_dropin_fail_range_active;
34821- atomic_long_t tlb_dropin_fail_idle;
34822- atomic_long_t tlb_dropin_fail_fmm;
34823- atomic_long_t tlb_dropin_fail_no_exception;
34824- atomic_long_t tfh_stale_on_fault;
34825- atomic_long_t mmu_invalidate_range;
34826- atomic_long_t mmu_invalidate_page;
34827- atomic_long_t flush_tlb;
34828- atomic_long_t flush_tlb_gru;
34829- atomic_long_t flush_tlb_gru_tgh;
34830- atomic_long_t flush_tlb_gru_zero_asid;
34831+ atomic_long_unchecked_t vdata_alloc;
34832+ atomic_long_unchecked_t vdata_free;
34833+ atomic_long_unchecked_t gts_alloc;
34834+ atomic_long_unchecked_t gts_free;
34835+ atomic_long_unchecked_t gms_alloc;
34836+ atomic_long_unchecked_t gms_free;
34837+ atomic_long_unchecked_t gts_double_allocate;
34838+ atomic_long_unchecked_t assign_context;
34839+ atomic_long_unchecked_t assign_context_failed;
34840+ atomic_long_unchecked_t free_context;
34841+ atomic_long_unchecked_t load_user_context;
34842+ atomic_long_unchecked_t load_kernel_context;
34843+ atomic_long_unchecked_t lock_kernel_context;
34844+ atomic_long_unchecked_t unlock_kernel_context;
34845+ atomic_long_unchecked_t steal_user_context;
34846+ atomic_long_unchecked_t steal_kernel_context;
34847+ atomic_long_unchecked_t steal_context_failed;
34848+ atomic_long_unchecked_t nopfn;
34849+ atomic_long_unchecked_t asid_new;
34850+ atomic_long_unchecked_t asid_next;
34851+ atomic_long_unchecked_t asid_wrap;
34852+ atomic_long_unchecked_t asid_reuse;
34853+ atomic_long_unchecked_t intr;
34854+ atomic_long_unchecked_t intr_cbr;
34855+ atomic_long_unchecked_t intr_tfh;
34856+ atomic_long_unchecked_t intr_spurious;
34857+ atomic_long_unchecked_t intr_mm_lock_failed;
34858+ atomic_long_unchecked_t call_os;
34859+ atomic_long_unchecked_t call_os_wait_queue;
34860+ atomic_long_unchecked_t user_flush_tlb;
34861+ atomic_long_unchecked_t user_unload_context;
34862+ atomic_long_unchecked_t user_exception;
34863+ atomic_long_unchecked_t set_context_option;
34864+ atomic_long_unchecked_t check_context_retarget_intr;
34865+ atomic_long_unchecked_t check_context_unload;
34866+ atomic_long_unchecked_t tlb_dropin;
34867+ atomic_long_unchecked_t tlb_preload_page;
34868+ atomic_long_unchecked_t tlb_dropin_fail_no_asid;
34869+ atomic_long_unchecked_t tlb_dropin_fail_upm;
34870+ atomic_long_unchecked_t tlb_dropin_fail_invalid;
34871+ atomic_long_unchecked_t tlb_dropin_fail_range_active;
34872+ atomic_long_unchecked_t tlb_dropin_fail_idle;
34873+ atomic_long_unchecked_t tlb_dropin_fail_fmm;
34874+ atomic_long_unchecked_t tlb_dropin_fail_no_exception;
34875+ atomic_long_unchecked_t tfh_stale_on_fault;
34876+ atomic_long_unchecked_t mmu_invalidate_range;
34877+ atomic_long_unchecked_t mmu_invalidate_page;
34878+ atomic_long_unchecked_t flush_tlb;
34879+ atomic_long_unchecked_t flush_tlb_gru;
34880+ atomic_long_unchecked_t flush_tlb_gru_tgh;
34881+ atomic_long_unchecked_t flush_tlb_gru_zero_asid;
34882
34883- atomic_long_t copy_gpa;
34884- atomic_long_t read_gpa;
34885+ atomic_long_unchecked_t copy_gpa;
34886+ atomic_long_unchecked_t read_gpa;
34887
34888- atomic_long_t mesq_receive;
34889- atomic_long_t mesq_receive_none;
34890- atomic_long_t mesq_send;
34891- atomic_long_t mesq_send_failed;
34892- atomic_long_t mesq_noop;
34893- atomic_long_t mesq_send_unexpected_error;
34894- atomic_long_t mesq_send_lb_overflow;
34895- atomic_long_t mesq_send_qlimit_reached;
34896- atomic_long_t mesq_send_amo_nacked;
34897- atomic_long_t mesq_send_put_nacked;
34898- atomic_long_t mesq_page_overflow;
34899- atomic_long_t mesq_qf_locked;
34900- atomic_long_t mesq_qf_noop_not_full;
34901- atomic_long_t mesq_qf_switch_head_failed;
34902- atomic_long_t mesq_qf_unexpected_error;
34903- atomic_long_t mesq_noop_unexpected_error;
34904- atomic_long_t mesq_noop_lb_overflow;
34905- atomic_long_t mesq_noop_qlimit_reached;
34906- atomic_long_t mesq_noop_amo_nacked;
34907- atomic_long_t mesq_noop_put_nacked;
34908- atomic_long_t mesq_noop_page_overflow;
34909+ atomic_long_unchecked_t mesq_receive;
34910+ atomic_long_unchecked_t mesq_receive_none;
34911+ atomic_long_unchecked_t mesq_send;
34912+ atomic_long_unchecked_t mesq_send_failed;
34913+ atomic_long_unchecked_t mesq_noop;
34914+ atomic_long_unchecked_t mesq_send_unexpected_error;
34915+ atomic_long_unchecked_t mesq_send_lb_overflow;
34916+ atomic_long_unchecked_t mesq_send_qlimit_reached;
34917+ atomic_long_unchecked_t mesq_send_amo_nacked;
34918+ atomic_long_unchecked_t mesq_send_put_nacked;
34919+ atomic_long_unchecked_t mesq_page_overflow;
34920+ atomic_long_unchecked_t mesq_qf_locked;
34921+ atomic_long_unchecked_t mesq_qf_noop_not_full;
34922+ atomic_long_unchecked_t mesq_qf_switch_head_failed;
34923+ atomic_long_unchecked_t mesq_qf_unexpected_error;
34924+ atomic_long_unchecked_t mesq_noop_unexpected_error;
34925+ atomic_long_unchecked_t mesq_noop_lb_overflow;
34926+ atomic_long_unchecked_t mesq_noop_qlimit_reached;
34927+ atomic_long_unchecked_t mesq_noop_amo_nacked;
34928+ atomic_long_unchecked_t mesq_noop_put_nacked;
34929+ atomic_long_unchecked_t mesq_noop_page_overflow;
34930
34931 };
34932
34933@@ -251,8 +251,8 @@ enum mcs_op {cchop_allocate, cchop_start, cchop_interrupt, cchop_interrupt_sync,
34934 tghop_invalidate, mcsop_last};
34935
34936 struct mcs_op_statistic {
34937- atomic_long_t count;
34938- atomic_long_t total;
34939+ atomic_long_unchecked_t count;
34940+ atomic_long_unchecked_t total;
34941 unsigned long max;
34942 };
34943
34944@@ -275,7 +275,7 @@ extern struct mcs_op_statistic mcs_op_statistics[mcsop_last];
34945
34946 #define STAT(id) do { \
34947 if (gru_options & OPT_STATS) \
34948- atomic_long_inc(&gru_stats.id); \
34949+ atomic_long_inc_unchecked(&gru_stats.id); \
34950 } while (0)
34951
34952 #ifdef CONFIG_SGI_GRU_DEBUG
34953diff --git a/drivers/misc/sgi-xp/xp.h b/drivers/misc/sgi-xp/xp.h
34954index c862cd4..0d176fe 100644
34955--- a/drivers/misc/sgi-xp/xp.h
34956+++ b/drivers/misc/sgi-xp/xp.h
34957@@ -288,7 +288,7 @@ struct xpc_interface {
34958 xpc_notify_func, void *);
34959 void (*received) (short, int, void *);
34960 enum xp_retval (*partid_to_nasids) (short, void *);
34961-};
34962+} __no_const;
34963
34964 extern struct xpc_interface xpc_interface;
34965
34966diff --git a/drivers/misc/sgi-xp/xpc.h b/drivers/misc/sgi-xp/xpc.h
34967index b94d5f7..7f494c5 100644
34968--- a/drivers/misc/sgi-xp/xpc.h
34969+++ b/drivers/misc/sgi-xp/xpc.h
34970@@ -835,6 +835,7 @@ struct xpc_arch_operations {
34971 void (*received_payload) (struct xpc_channel *, void *);
34972 void (*notify_senders_of_disconnect) (struct xpc_channel *);
34973 };
34974+typedef struct xpc_arch_operations __no_const xpc_arch_operations_no_const;
34975
34976 /* struct xpc_partition act_state values (for XPC HB) */
34977
34978@@ -876,7 +877,7 @@ extern struct xpc_registration xpc_registrations[];
34979 /* found in xpc_main.c */
34980 extern struct device *xpc_part;
34981 extern struct device *xpc_chan;
34982-extern struct xpc_arch_operations xpc_arch_ops;
34983+extern xpc_arch_operations_no_const xpc_arch_ops;
34984 extern int xpc_disengage_timelimit;
34985 extern int xpc_disengage_timedout;
34986 extern int xpc_activate_IRQ_rcvd;
34987diff --git a/drivers/misc/sgi-xp/xpc_main.c b/drivers/misc/sgi-xp/xpc_main.c
34988index 8d082b4..aa749ae 100644
34989--- a/drivers/misc/sgi-xp/xpc_main.c
34990+++ b/drivers/misc/sgi-xp/xpc_main.c
34991@@ -162,7 +162,7 @@ static struct notifier_block xpc_die_notifier = {
34992 .notifier_call = xpc_system_die,
34993 };
34994
34995-struct xpc_arch_operations xpc_arch_ops;
34996+xpc_arch_operations_no_const xpc_arch_ops;
34997
34998 /*
34999 * Timer function to enforce the timelimit on the partition disengage.
35000diff --git a/drivers/mmc/host/sdhci-pci.c b/drivers/mmc/host/sdhci-pci.c
35001index 504da71..9722d43 100644
35002--- a/drivers/mmc/host/sdhci-pci.c
35003+++ b/drivers/mmc/host/sdhci-pci.c
35004@@ -653,7 +653,7 @@ static const struct sdhci_pci_fixes sdhci_via = {
35005 .probe = via_probe,
35006 };
35007
35008-static const struct pci_device_id pci_ids[] __devinitdata = {
35009+static const struct pci_device_id pci_ids[] __devinitconst = {
35010 {
35011 .vendor = PCI_VENDOR_ID_RICOH,
35012 .device = PCI_DEVICE_ID_RICOH_R5C822,
35013diff --git a/drivers/mtd/devices/doc2000.c b/drivers/mtd/devices/doc2000.c
35014index a4eb8b5..8c0628f 100644
35015--- a/drivers/mtd/devices/doc2000.c
35016+++ b/drivers/mtd/devices/doc2000.c
35017@@ -753,7 +753,7 @@ static int doc_write(struct mtd_info *mtd, loff_t to, size_t len,
35018
35019 /* The ECC will not be calculated correctly if less than 512 is written */
35020 /* DBB-
35021- if (len != 0x200 && eccbuf)
35022+ if (len != 0x200)
35023 printk(KERN_WARNING
35024 "ECC needs a full sector write (adr: %lx size %lx)\n",
35025 (long) to, (long) len);
35026diff --git a/drivers/mtd/nand/denali.c b/drivers/mtd/nand/denali.c
35027index 0650aaf..7718762 100644
35028--- a/drivers/mtd/nand/denali.c
35029+++ b/drivers/mtd/nand/denali.c
35030@@ -26,6 +26,7 @@
35031 #include <linux/pci.h>
35032 #include <linux/mtd/mtd.h>
35033 #include <linux/module.h>
35034+#include <linux/slab.h>
35035
35036 #include "denali.h"
35037
35038diff --git a/drivers/mtd/nftlmount.c b/drivers/mtd/nftlmount.c
35039index 51b9d6a..52af9a7 100644
35040--- a/drivers/mtd/nftlmount.c
35041+++ b/drivers/mtd/nftlmount.c
35042@@ -24,6 +24,7 @@
35043 #include <asm/errno.h>
35044 #include <linux/delay.h>
35045 #include <linux/slab.h>
35046+#include <linux/sched.h>
35047 #include <linux/mtd/mtd.h>
35048 #include <linux/mtd/nand.h>
35049 #include <linux/mtd/nftl.h>
35050diff --git a/drivers/net/bonding/bond_sysfs.c b/drivers/net/bonding/bond_sysfs.c
35051index dc15d24..ef8d2a0 100644
35052--- a/drivers/net/bonding/bond_sysfs.c
35053+++ b/drivers/net/bonding/bond_sysfs.c
35054@@ -1060,7 +1060,7 @@ static ssize_t bonding_store_primary(struct device *d,
35055 goto out;
35056 }
35057
35058- sscanf(buf, "%16s", ifname); /* IFNAMSIZ */
35059+ sscanf(buf, "%15s", ifname); /* IFNAMSIZ */
35060
35061 /* check to see if we are clearing primary */
35062 if (!strlen(ifname) || buf[0] == '\n') {
35063@@ -1237,7 +1237,7 @@ static ssize_t bonding_store_active_slave(struct device *d,
35064 goto out;
35065 }
35066
35067- sscanf(buf, "%16s", ifname); /* IFNAMSIZ */
35068+ sscanf(buf, "%15s", ifname); /* IFNAMSIZ */
35069
35070 /* check to see if we are clearing active */
35071 if (!strlen(ifname) || buf[0] == '\n') {
35072diff --git a/drivers/net/ethernet/atheros/atlx/atl2.c b/drivers/net/ethernet/atheros/atlx/atl2.c
35073index 57d64b8..623dd86 100644
35074--- a/drivers/net/ethernet/atheros/atlx/atl2.c
35075+++ b/drivers/net/ethernet/atheros/atlx/atl2.c
35076@@ -2845,7 +2845,7 @@ static void atl2_force_ps(struct atl2_hw *hw)
35077 */
35078
35079 #define ATL2_PARAM(X, desc) \
35080- static const int __devinitdata X[ATL2_MAX_NIC + 1] = ATL2_PARAM_INIT; \
35081+ static const int __devinitconst X[ATL2_MAX_NIC + 1] = ATL2_PARAM_INIT; \
35082 MODULE_PARM(X, "1-" __MODULE_STRING(ATL2_MAX_NIC) "i"); \
35083 MODULE_PARM_DESC(X, desc);
35084 #else
35085diff --git a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_main.c b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_main.c
35086index 0875ecf..794cdf3 100644
35087--- a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_main.c
35088+++ b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_main.c
35089@@ -3051,9 +3051,8 @@ static void bnx2x_drv_info_ether_stat(struct bnx2x *bp)
35090 struct eth_stats_info *ether_stat =
35091 &bp->slowpath->drv_info_to_mcp.ether_stat;
35092
35093- /* leave last char as NULL */
35094- memcpy(ether_stat->version, DRV_MODULE_VERSION,
35095- ETH_STAT_INFO_VERSION_LEN - 1);
35096+ strlcpy(ether_stat->version, DRV_MODULE_VERSION,
35097+ ETH_STAT_INFO_VERSION_LEN);
35098
35099 bp->sp_objs[0].mac_obj.get_n_elements(bp, &bp->sp_objs[0].mac_obj,
35100 DRV_INFO_ETH_STAT_NUM_MACS_REQUIRED,
35101diff --git a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h
35102index f83e033..8b4f43a 100644
35103--- a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h
35104+++ b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h
35105@@ -486,7 +486,7 @@ struct bnx2x_rx_mode_obj {
35106
35107 int (*wait_comp)(struct bnx2x *bp,
35108 struct bnx2x_rx_mode_ramrod_params *p);
35109-};
35110+} __no_const;
35111
35112 /********************** Set multicast group ***********************************/
35113
35114diff --git a/drivers/net/ethernet/broadcom/tg3.h b/drivers/net/ethernet/broadcom/tg3.h
35115index 6d52cb2..bc95640 100644
35116--- a/drivers/net/ethernet/broadcom/tg3.h
35117+++ b/drivers/net/ethernet/broadcom/tg3.h
35118@@ -140,6 +140,7 @@
35119 #define CHIPREV_ID_5750_A0 0x4000
35120 #define CHIPREV_ID_5750_A1 0x4001
35121 #define CHIPREV_ID_5750_A3 0x4003
35122+#define CHIPREV_ID_5750_C1 0x4201
35123 #define CHIPREV_ID_5750_C2 0x4202
35124 #define CHIPREV_ID_5752_A0_HW 0x5000
35125 #define CHIPREV_ID_5752_A0 0x6000
35126diff --git a/drivers/net/ethernet/chelsio/cxgb3/l2t.h b/drivers/net/ethernet/chelsio/cxgb3/l2t.h
35127index 8cffcdf..aadf043 100644
35128--- a/drivers/net/ethernet/chelsio/cxgb3/l2t.h
35129+++ b/drivers/net/ethernet/chelsio/cxgb3/l2t.h
35130@@ -87,7 +87,7 @@ typedef void (*arp_failure_handler_func)(struct t3cdev * dev,
35131 */
35132 struct l2t_skb_cb {
35133 arp_failure_handler_func arp_failure_handler;
35134-};
35135+} __no_const;
35136
35137 #define L2T_SKB_CB(skb) ((struct l2t_skb_cb *)(skb)->cb)
35138
35139diff --git a/drivers/net/ethernet/dec/tulip/de4x5.c b/drivers/net/ethernet/dec/tulip/de4x5.c
35140index f879e92..726f20f 100644
35141--- a/drivers/net/ethernet/dec/tulip/de4x5.c
35142+++ b/drivers/net/ethernet/dec/tulip/de4x5.c
35143@@ -5388,7 +5388,7 @@ de4x5_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
35144 for (i=0; i<ETH_ALEN; i++) {
35145 tmp.addr[i] = dev->dev_addr[i];
35146 }
35147- if (copy_to_user(ioc->data, tmp.addr, ioc->len)) return -EFAULT;
35148+ if (ioc->len > sizeof tmp.addr || copy_to_user(ioc->data, tmp.addr, ioc->len)) return -EFAULT;
35149 break;
35150
35151 case DE4X5_SET_HWADDR: /* Set the hardware address */
35152@@ -5428,7 +5428,7 @@ de4x5_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
35153 spin_lock_irqsave(&lp->lock, flags);
35154 memcpy(&statbuf, &lp->pktStats, ioc->len);
35155 spin_unlock_irqrestore(&lp->lock, flags);
35156- if (copy_to_user(ioc->data, &statbuf, ioc->len))
35157+ if (ioc->len > sizeof statbuf || copy_to_user(ioc->data, &statbuf, ioc->len))
35158 return -EFAULT;
35159 break;
35160 }
35161diff --git a/drivers/net/ethernet/dec/tulip/eeprom.c b/drivers/net/ethernet/dec/tulip/eeprom.c
35162index ed7d1dc..d426748 100644
35163--- a/drivers/net/ethernet/dec/tulip/eeprom.c
35164+++ b/drivers/net/ethernet/dec/tulip/eeprom.c
35165@@ -79,7 +79,7 @@ static struct eeprom_fixup eeprom_fixups[] __devinitdata = {
35166 {NULL}};
35167
35168
35169-static const char *block_name[] __devinitdata = {
35170+static const char *block_name[] __devinitconst = {
35171 "21140 non-MII",
35172 "21140 MII PHY",
35173 "21142 Serial PHY",
35174diff --git a/drivers/net/ethernet/dec/tulip/uli526x.c b/drivers/net/ethernet/dec/tulip/uli526x.c
35175index 75d45f8..3d9c55b 100644
35176--- a/drivers/net/ethernet/dec/tulip/uli526x.c
35177+++ b/drivers/net/ethernet/dec/tulip/uli526x.c
35178@@ -129,7 +129,7 @@ struct uli526x_board_info {
35179 struct uli_phy_ops {
35180 void (*write)(struct uli526x_board_info *, u8, u8, u16);
35181 u16 (*read)(struct uli526x_board_info *, u8, u8);
35182- } phy;
35183+ } __no_const phy;
35184 struct net_device *next_dev; /* next device */
35185 struct pci_dev *pdev; /* PCI device */
35186 spinlock_t lock;
35187diff --git a/drivers/net/ethernet/dec/tulip/winbond-840.c b/drivers/net/ethernet/dec/tulip/winbond-840.c
35188index 4d1ffca..7c1ec4d 100644
35189--- a/drivers/net/ethernet/dec/tulip/winbond-840.c
35190+++ b/drivers/net/ethernet/dec/tulip/winbond-840.c
35191@@ -236,7 +236,7 @@ struct pci_id_info {
35192 int drv_flags; /* Driver use, intended as capability flags. */
35193 };
35194
35195-static const struct pci_id_info pci_id_tbl[] __devinitdata = {
35196+static const struct pci_id_info pci_id_tbl[] __devinitconst = {
35197 { /* Sometime a Level-One switch card. */
35198 "Winbond W89c840", CanHaveMII | HasBrokenTx | FDXOnNoMII},
35199 { "Winbond W89c840", CanHaveMII | HasBrokenTx},
35200diff --git a/drivers/net/ethernet/dlink/sundance.c b/drivers/net/ethernet/dlink/sundance.c
35201index d7bb52a..3b83588 100644
35202--- a/drivers/net/ethernet/dlink/sundance.c
35203+++ b/drivers/net/ethernet/dlink/sundance.c
35204@@ -218,7 +218,7 @@ enum {
35205 struct pci_id_info {
35206 const char *name;
35207 };
35208-static const struct pci_id_info pci_id_tbl[] __devinitdata = {
35209+static const struct pci_id_info pci_id_tbl[] __devinitconst = {
35210 {"D-Link DFE-550TX FAST Ethernet Adapter"},
35211 {"D-Link DFE-550FX 100Mbps Fiber-optics Adapter"},
35212 {"D-Link DFE-580TX 4 port Server Adapter"},
35213diff --git a/drivers/net/ethernet/emulex/benet/be_main.c b/drivers/net/ethernet/emulex/benet/be_main.c
35214index 78b8aa8..dd6323a 100644
35215--- a/drivers/net/ethernet/emulex/benet/be_main.c
35216+++ b/drivers/net/ethernet/emulex/benet/be_main.c
35217@@ -403,7 +403,7 @@ static void accumulate_16bit_val(u32 *acc, u16 val)
35218
35219 if (wrapped)
35220 newacc += 65536;
35221- ACCESS_ONCE(*acc) = newacc;
35222+ ACCESS_ONCE_RW(*acc) = newacc;
35223 }
35224
35225 void be_parse_stats(struct be_adapter *adapter)
35226diff --git a/drivers/net/ethernet/faraday/ftgmac100.c b/drivers/net/ethernet/faraday/ftgmac100.c
35227index 74d749e..eefb1bd 100644
35228--- a/drivers/net/ethernet/faraday/ftgmac100.c
35229+++ b/drivers/net/ethernet/faraday/ftgmac100.c
35230@@ -31,6 +31,8 @@
35231 #include <linux/netdevice.h>
35232 #include <linux/phy.h>
35233 #include <linux/platform_device.h>
35234+#include <linux/interrupt.h>
35235+#include <linux/irqreturn.h>
35236 #include <net/ip.h>
35237
35238 #include "ftgmac100.h"
35239diff --git a/drivers/net/ethernet/faraday/ftmac100.c b/drivers/net/ethernet/faraday/ftmac100.c
35240index b901a01..1ff32ee 100644
35241--- a/drivers/net/ethernet/faraday/ftmac100.c
35242+++ b/drivers/net/ethernet/faraday/ftmac100.c
35243@@ -31,6 +31,8 @@
35244 #include <linux/module.h>
35245 #include <linux/netdevice.h>
35246 #include <linux/platform_device.h>
35247+#include <linux/interrupt.h>
35248+#include <linux/irqreturn.h>
35249
35250 #include "ftmac100.h"
35251
35252diff --git a/drivers/net/ethernet/fealnx.c b/drivers/net/ethernet/fealnx.c
35253index 9d71c9c..0e4a0ac 100644
35254--- a/drivers/net/ethernet/fealnx.c
35255+++ b/drivers/net/ethernet/fealnx.c
35256@@ -150,7 +150,7 @@ struct chip_info {
35257 int flags;
35258 };
35259
35260-static const struct chip_info skel_netdrv_tbl[] __devinitdata = {
35261+static const struct chip_info skel_netdrv_tbl[] __devinitconst = {
35262 { "100/10M Ethernet PCI Adapter", HAS_MII_XCVR },
35263 { "100/10M Ethernet PCI Adapter", HAS_CHIP_XCVR },
35264 { "1000/100/10M Ethernet PCI Adapter", HAS_MII_XCVR },
35265diff --git a/drivers/net/ethernet/intel/e1000e/hw.h b/drivers/net/ethernet/intel/e1000e/hw.h
35266index ed5b409..ec37828 100644
35267--- a/drivers/net/ethernet/intel/e1000e/hw.h
35268+++ b/drivers/net/ethernet/intel/e1000e/hw.h
35269@@ -797,6 +797,7 @@ struct e1000_mac_operations {
35270 void (*rar_set)(struct e1000_hw *, u8 *, u32);
35271 s32 (*read_mac_addr)(struct e1000_hw *);
35272 };
35273+typedef struct e1000_mac_operations __no_const e1000_mac_operations_no_const;
35274
35275 /*
35276 * When to use various PHY register access functions:
35277@@ -837,6 +838,7 @@ struct e1000_phy_operations {
35278 void (*power_up)(struct e1000_hw *);
35279 void (*power_down)(struct e1000_hw *);
35280 };
35281+typedef struct e1000_phy_operations __no_const e1000_phy_operations_no_const;
35282
35283 /* Function pointers for the NVM. */
35284 struct e1000_nvm_operations {
35285@@ -849,9 +851,10 @@ struct e1000_nvm_operations {
35286 s32 (*validate)(struct e1000_hw *);
35287 s32 (*write)(struct e1000_hw *, u16, u16, u16 *);
35288 };
35289+typedef struct e1000_nvm_operations __no_const e1000_nvm_operations_no_const;
35290
35291 struct e1000_mac_info {
35292- struct e1000_mac_operations ops;
35293+ e1000_mac_operations_no_const ops;
35294 u8 addr[ETH_ALEN];
35295 u8 perm_addr[ETH_ALEN];
35296
35297@@ -892,7 +895,7 @@ struct e1000_mac_info {
35298 };
35299
35300 struct e1000_phy_info {
35301- struct e1000_phy_operations ops;
35302+ e1000_phy_operations_no_const ops;
35303
35304 enum e1000_phy_type type;
35305
35306@@ -926,7 +929,7 @@ struct e1000_phy_info {
35307 };
35308
35309 struct e1000_nvm_info {
35310- struct e1000_nvm_operations ops;
35311+ e1000_nvm_operations_no_const ops;
35312
35313 enum e1000_nvm_type type;
35314 enum e1000_nvm_override override;
35315diff --git a/drivers/net/ethernet/intel/igb/e1000_hw.h b/drivers/net/ethernet/intel/igb/e1000_hw.h
35316index c2a51dc..c2bd262 100644
35317--- a/drivers/net/ethernet/intel/igb/e1000_hw.h
35318+++ b/drivers/net/ethernet/intel/igb/e1000_hw.h
35319@@ -327,6 +327,7 @@ struct e1000_mac_operations {
35320 void (*release_swfw_sync)(struct e1000_hw *, u16);
35321
35322 };
35323+typedef struct e1000_mac_operations __no_const e1000_mac_operations_no_const;
35324
35325 struct e1000_phy_operations {
35326 s32 (*acquire)(struct e1000_hw *);
35327@@ -343,6 +344,7 @@ struct e1000_phy_operations {
35328 s32 (*set_d3_lplu_state)(struct e1000_hw *, bool);
35329 s32 (*write_reg)(struct e1000_hw *, u32, u16);
35330 };
35331+typedef struct e1000_phy_operations __no_const e1000_phy_operations_no_const;
35332
35333 struct e1000_nvm_operations {
35334 s32 (*acquire)(struct e1000_hw *);
35335@@ -353,6 +355,7 @@ struct e1000_nvm_operations {
35336 s32 (*validate)(struct e1000_hw *);
35337 s32 (*valid_led_default)(struct e1000_hw *, u16 *);
35338 };
35339+typedef struct e1000_nvm_operations __no_const e1000_nvm_operations_no_const;
35340
35341 struct e1000_info {
35342 s32 (*get_invariants)(struct e1000_hw *);
35343@@ -364,7 +367,7 @@ struct e1000_info {
35344 extern const struct e1000_info e1000_82575_info;
35345
35346 struct e1000_mac_info {
35347- struct e1000_mac_operations ops;
35348+ e1000_mac_operations_no_const ops;
35349
35350 u8 addr[6];
35351 u8 perm_addr[6];
35352@@ -402,7 +405,7 @@ struct e1000_mac_info {
35353 };
35354
35355 struct e1000_phy_info {
35356- struct e1000_phy_operations ops;
35357+ e1000_phy_operations_no_const ops;
35358
35359 enum e1000_phy_type type;
35360
35361@@ -437,7 +440,7 @@ struct e1000_phy_info {
35362 };
35363
35364 struct e1000_nvm_info {
35365- struct e1000_nvm_operations ops;
35366+ e1000_nvm_operations_no_const ops;
35367 enum e1000_nvm_type type;
35368 enum e1000_nvm_override override;
35369
35370@@ -482,6 +485,7 @@ struct e1000_mbx_operations {
35371 s32 (*check_for_ack)(struct e1000_hw *, u16);
35372 s32 (*check_for_rst)(struct e1000_hw *, u16);
35373 };
35374+typedef struct e1000_mbx_operations __no_const e1000_mbx_operations_no_const;
35375
35376 struct e1000_mbx_stats {
35377 u32 msgs_tx;
35378@@ -493,7 +497,7 @@ struct e1000_mbx_stats {
35379 };
35380
35381 struct e1000_mbx_info {
35382- struct e1000_mbx_operations ops;
35383+ e1000_mbx_operations_no_const ops;
35384 struct e1000_mbx_stats stats;
35385 u32 timeout;
35386 u32 usec_delay;
35387diff --git a/drivers/net/ethernet/intel/igbvf/vf.h b/drivers/net/ethernet/intel/igbvf/vf.h
35388index 57db3c6..aa825fc 100644
35389--- a/drivers/net/ethernet/intel/igbvf/vf.h
35390+++ b/drivers/net/ethernet/intel/igbvf/vf.h
35391@@ -189,9 +189,10 @@ struct e1000_mac_operations {
35392 s32 (*read_mac_addr)(struct e1000_hw *);
35393 s32 (*set_vfta)(struct e1000_hw *, u16, bool);
35394 };
35395+typedef struct e1000_mac_operations __no_const e1000_mac_operations_no_const;
35396
35397 struct e1000_mac_info {
35398- struct e1000_mac_operations ops;
35399+ e1000_mac_operations_no_const ops;
35400 u8 addr[6];
35401 u8 perm_addr[6];
35402
35403@@ -213,6 +214,7 @@ struct e1000_mbx_operations {
35404 s32 (*check_for_ack)(struct e1000_hw *);
35405 s32 (*check_for_rst)(struct e1000_hw *);
35406 };
35407+typedef struct e1000_mbx_operations __no_const e1000_mbx_operations_no_const;
35408
35409 struct e1000_mbx_stats {
35410 u32 msgs_tx;
35411@@ -224,7 +226,7 @@ struct e1000_mbx_stats {
35412 };
35413
35414 struct e1000_mbx_info {
35415- struct e1000_mbx_operations ops;
35416+ e1000_mbx_operations_no_const ops;
35417 struct e1000_mbx_stats stats;
35418 u32 timeout;
35419 u32 usec_delay;
35420diff --git a/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c b/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c
35421index 3456d56..b688d81 100644
35422--- a/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c
35423+++ b/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c
35424@@ -884,7 +884,7 @@ void ixgbe_ptp_start_cyclecounter(struct ixgbe_adapter *adapter)
35425 /* store the new cycle speed */
35426 adapter->cycle_speed = cycle_speed;
35427
35428- ACCESS_ONCE(adapter->base_incval) = incval;
35429+ ACCESS_ONCE_RW(adapter->base_incval) = incval;
35430 smp_mb();
35431
35432 /* grab the ptp lock */
35433diff --git a/drivers/net/ethernet/intel/ixgbe/ixgbe_type.h b/drivers/net/ethernet/intel/ixgbe/ixgbe_type.h
35434index 400f86a..7f2e062 100644
35435--- a/drivers/net/ethernet/intel/ixgbe/ixgbe_type.h
35436+++ b/drivers/net/ethernet/intel/ixgbe/ixgbe_type.h
35437@@ -2799,6 +2799,7 @@ struct ixgbe_eeprom_operations {
35438 s32 (*update_checksum)(struct ixgbe_hw *);
35439 u16 (*calc_checksum)(struct ixgbe_hw *);
35440 };
35441+typedef struct ixgbe_eeprom_operations __no_const ixgbe_eeprom_operations_no_const;
35442
35443 struct ixgbe_mac_operations {
35444 s32 (*init_hw)(struct ixgbe_hw *);
35445@@ -2865,6 +2866,7 @@ struct ixgbe_mac_operations {
35446 s32 (*get_thermal_sensor_data)(struct ixgbe_hw *);
35447 s32 (*init_thermal_sensor_thresh)(struct ixgbe_hw *hw);
35448 };
35449+typedef struct ixgbe_mac_operations __no_const ixgbe_mac_operations_no_const;
35450
35451 struct ixgbe_phy_operations {
35452 s32 (*identify)(struct ixgbe_hw *);
35453@@ -2884,9 +2886,10 @@ struct ixgbe_phy_operations {
35454 s32 (*write_i2c_eeprom)(struct ixgbe_hw *, u8, u8);
35455 s32 (*check_overtemp)(struct ixgbe_hw *);
35456 };
35457+typedef struct ixgbe_phy_operations __no_const ixgbe_phy_operations_no_const;
35458
35459 struct ixgbe_eeprom_info {
35460- struct ixgbe_eeprom_operations ops;
35461+ ixgbe_eeprom_operations_no_const ops;
35462 enum ixgbe_eeprom_type type;
35463 u32 semaphore_delay;
35464 u16 word_size;
35465@@ -2896,7 +2899,7 @@ struct ixgbe_eeprom_info {
35466
35467 #define IXGBE_FLAGS_DOUBLE_RESET_REQUIRED 0x01
35468 struct ixgbe_mac_info {
35469- struct ixgbe_mac_operations ops;
35470+ ixgbe_mac_operations_no_const ops;
35471 enum ixgbe_mac_type type;
35472 u8 addr[ETH_ALEN];
35473 u8 perm_addr[ETH_ALEN];
35474@@ -2926,7 +2929,7 @@ struct ixgbe_mac_info {
35475 };
35476
35477 struct ixgbe_phy_info {
35478- struct ixgbe_phy_operations ops;
35479+ ixgbe_phy_operations_no_const ops;
35480 struct mdio_if_info mdio;
35481 enum ixgbe_phy_type type;
35482 u32 id;
35483@@ -2954,6 +2957,7 @@ struct ixgbe_mbx_operations {
35484 s32 (*check_for_ack)(struct ixgbe_hw *, u16);
35485 s32 (*check_for_rst)(struct ixgbe_hw *, u16);
35486 };
35487+typedef struct ixgbe_mbx_operations __no_const ixgbe_mbx_operations_no_const;
35488
35489 struct ixgbe_mbx_stats {
35490 u32 msgs_tx;
35491@@ -2965,7 +2969,7 @@ struct ixgbe_mbx_stats {
35492 };
35493
35494 struct ixgbe_mbx_info {
35495- struct ixgbe_mbx_operations ops;
35496+ ixgbe_mbx_operations_no_const ops;
35497 struct ixgbe_mbx_stats stats;
35498 u32 timeout;
35499 u32 usec_delay;
35500diff --git a/drivers/net/ethernet/intel/ixgbevf/vf.h b/drivers/net/ethernet/intel/ixgbevf/vf.h
35501index 25c951d..cc7cf33 100644
35502--- a/drivers/net/ethernet/intel/ixgbevf/vf.h
35503+++ b/drivers/net/ethernet/intel/ixgbevf/vf.h
35504@@ -70,6 +70,7 @@ struct ixgbe_mac_operations {
35505 s32 (*clear_vfta)(struct ixgbe_hw *);
35506 s32 (*set_vfta)(struct ixgbe_hw *, u32, u32, bool);
35507 };
35508+typedef struct ixgbe_mac_operations __no_const ixgbe_mac_operations_no_const;
35509
35510 enum ixgbe_mac_type {
35511 ixgbe_mac_unknown = 0,
35512@@ -79,7 +80,7 @@ enum ixgbe_mac_type {
35513 };
35514
35515 struct ixgbe_mac_info {
35516- struct ixgbe_mac_operations ops;
35517+ ixgbe_mac_operations_no_const ops;
35518 u8 addr[6];
35519 u8 perm_addr[6];
35520
35521@@ -103,6 +104,7 @@ struct ixgbe_mbx_operations {
35522 s32 (*check_for_ack)(struct ixgbe_hw *);
35523 s32 (*check_for_rst)(struct ixgbe_hw *);
35524 };
35525+typedef struct ixgbe_mbx_operations __no_const ixgbe_mbx_operations_no_const;
35526
35527 struct ixgbe_mbx_stats {
35528 u32 msgs_tx;
35529@@ -114,7 +116,7 @@ struct ixgbe_mbx_stats {
35530 };
35531
35532 struct ixgbe_mbx_info {
35533- struct ixgbe_mbx_operations ops;
35534+ ixgbe_mbx_operations_no_const ops;
35535 struct ixgbe_mbx_stats stats;
35536 u32 timeout;
35537 u32 udelay;
35538diff --git a/drivers/net/ethernet/mellanox/mlx4/en_dcb_nl.c b/drivers/net/ethernet/mellanox/mlx4/en_dcb_nl.c
35539index 5d367958..b799ab12 100644
35540--- a/drivers/net/ethernet/mellanox/mlx4/en_dcb_nl.c
35541+++ b/drivers/net/ethernet/mellanox/mlx4/en_dcb_nl.c
35542@@ -237,7 +237,7 @@ static int mlx4_en_dcbnl_ieee_setmaxrate(struct net_device *dev,
35543 if (err)
35544 return err;
35545
35546- memcpy(priv->maxrate, tmp, sizeof(*priv->maxrate));
35547+ memcpy(priv->maxrate, tmp, sizeof(priv->maxrate));
35548
35549 return 0;
35550 }
35551diff --git a/drivers/net/ethernet/neterion/vxge/vxge-config.h b/drivers/net/ethernet/neterion/vxge/vxge-config.h
35552index 9e0c1ee..8471f77 100644
35553--- a/drivers/net/ethernet/neterion/vxge/vxge-config.h
35554+++ b/drivers/net/ethernet/neterion/vxge/vxge-config.h
35555@@ -514,7 +514,7 @@ struct vxge_hw_uld_cbs {
35556 void (*link_down)(struct __vxge_hw_device *devh);
35557 void (*crit_err)(struct __vxge_hw_device *devh,
35558 enum vxge_hw_event type, u64 ext_data);
35559-};
35560+} __no_const;
35561
35562 /*
35563 * struct __vxge_hw_blockpool_entry - Block private data structure
35564diff --git a/drivers/net/ethernet/neterion/vxge/vxge-traffic.h b/drivers/net/ethernet/neterion/vxge/vxge-traffic.h
35565index 4a518a3..936b334 100644
35566--- a/drivers/net/ethernet/neterion/vxge/vxge-traffic.h
35567+++ b/drivers/net/ethernet/neterion/vxge/vxge-traffic.h
35568@@ -2088,7 +2088,7 @@ struct vxge_hw_mempool_cbs {
35569 struct vxge_hw_mempool_dma *dma_object,
35570 u32 index,
35571 u32 is_last);
35572-};
35573+} __no_const;
35574
35575 #define VXGE_HW_VIRTUAL_PATH_HANDLE(vpath) \
35576 ((struct __vxge_hw_vpath_handle *)(vpath)->vpath_handles.next)
35577diff --git a/drivers/net/ethernet/realtek/r8169.c b/drivers/net/ethernet/realtek/r8169.c
35578index df7bbba..162f850 100644
35579--- a/drivers/net/ethernet/realtek/r8169.c
35580+++ b/drivers/net/ethernet/realtek/r8169.c
35581@@ -745,22 +745,22 @@ struct rtl8169_private {
35582 struct mdio_ops {
35583 void (*write)(struct rtl8169_private *, int, int);
35584 int (*read)(struct rtl8169_private *, int);
35585- } mdio_ops;
35586+ } __no_const mdio_ops;
35587
35588 struct pll_power_ops {
35589 void (*down)(struct rtl8169_private *);
35590 void (*up)(struct rtl8169_private *);
35591- } pll_power_ops;
35592+ } __no_const pll_power_ops;
35593
35594 struct jumbo_ops {
35595 void (*enable)(struct rtl8169_private *);
35596 void (*disable)(struct rtl8169_private *);
35597- } jumbo_ops;
35598+ } __no_const jumbo_ops;
35599
35600 struct csi_ops {
35601 void (*write)(struct rtl8169_private *, int, int);
35602 u32 (*read)(struct rtl8169_private *, int);
35603- } csi_ops;
35604+ } __no_const csi_ops;
35605
35606 int (*set_speed)(struct net_device *, u8 aneg, u16 sp, u8 dpx, u32 adv);
35607 int (*get_settings)(struct net_device *, struct ethtool_cmd *);
35608diff --git a/drivers/net/ethernet/sis/sis190.c b/drivers/net/ethernet/sis/sis190.c
35609index 4613591..d816601 100644
35610--- a/drivers/net/ethernet/sis/sis190.c
35611+++ b/drivers/net/ethernet/sis/sis190.c
35612@@ -1618,7 +1618,7 @@ static int __devinit sis190_get_mac_addr_from_eeprom(struct pci_dev *pdev,
35613 static int __devinit sis190_get_mac_addr_from_apc(struct pci_dev *pdev,
35614 struct net_device *dev)
35615 {
35616- static const u16 __devinitdata ids[] = { 0x0965, 0x0966, 0x0968 };
35617+ static const u16 __devinitconst ids[] = { 0x0965, 0x0966, 0x0968 };
35618 struct sis190_private *tp = netdev_priv(dev);
35619 struct pci_dev *isa_bridge;
35620 u8 reg, tmp8;
35621diff --git a/drivers/net/ethernet/stmicro/stmmac/mmc_core.c b/drivers/net/ethernet/stmicro/stmmac/mmc_core.c
35622index 0c74a70..3bc6f68 100644
35623--- a/drivers/net/ethernet/stmicro/stmmac/mmc_core.c
35624+++ b/drivers/net/ethernet/stmicro/stmmac/mmc_core.c
35625@@ -140,8 +140,8 @@ void dwmac_mmc_ctrl(void __iomem *ioaddr, unsigned int mode)
35626
35627 writel(value, ioaddr + MMC_CNTRL);
35628
35629- pr_debug("stmmac: MMC ctrl register (offset 0x%x): 0x%08x\n",
35630- MMC_CNTRL, value);
35631+// pr_debug("stmmac: MMC ctrl register (offset 0x%x): 0x%08x\n",
35632+// MMC_CNTRL, value);
35633 }
35634
35635 /* To mask all all interrupts.*/
35636diff --git a/drivers/net/hyperv/hyperv_net.h b/drivers/net/hyperv/hyperv_net.h
35637index 95ceb35..318fc12 100644
35638--- a/drivers/net/hyperv/hyperv_net.h
35639+++ b/drivers/net/hyperv/hyperv_net.h
35640@@ -99,7 +99,7 @@ struct rndis_device {
35641
35642 enum rndis_device_state state;
35643 bool link_state;
35644- atomic_t new_req_id;
35645+ atomic_unchecked_t new_req_id;
35646
35647 spinlock_t request_lock;
35648 struct list_head req_list;
35649diff --git a/drivers/net/hyperv/rndis_filter.c b/drivers/net/hyperv/rndis_filter.c
35650index 1e88a10..1b01736 100644
35651--- a/drivers/net/hyperv/rndis_filter.c
35652+++ b/drivers/net/hyperv/rndis_filter.c
35653@@ -99,7 +99,7 @@ static struct rndis_request *get_rndis_request(struct rndis_device *dev,
35654 * template
35655 */
35656 set = &rndis_msg->msg.set_req;
35657- set->req_id = atomic_inc_return(&dev->new_req_id);
35658+ set->req_id = atomic_inc_return_unchecked(&dev->new_req_id);
35659
35660 /* Add to the request list */
35661 spin_lock_irqsave(&dev->request_lock, flags);
35662@@ -730,7 +730,7 @@ static void rndis_filter_halt_device(struct rndis_device *dev)
35663
35664 /* Setup the rndis set */
35665 halt = &request->request_msg.msg.halt_req;
35666- halt->req_id = atomic_inc_return(&dev->new_req_id);
35667+ halt->req_id = atomic_inc_return_unchecked(&dev->new_req_id);
35668
35669 /* Ignore return since this msg is optional. */
35670 rndis_filter_send_request(dev, request);
35671diff --git a/drivers/net/phy/mdio-bitbang.c b/drivers/net/phy/mdio-bitbang.c
35672index daec9b0..6428fcb 100644
35673--- a/drivers/net/phy/mdio-bitbang.c
35674+++ b/drivers/net/phy/mdio-bitbang.c
35675@@ -234,6 +234,7 @@ void free_mdio_bitbang(struct mii_bus *bus)
35676 struct mdiobb_ctrl *ctrl = bus->priv;
35677
35678 module_put(ctrl->ops->owner);
35679+ mdiobus_unregister(bus);
35680 mdiobus_free(bus);
35681 }
35682 EXPORT_SYMBOL(free_mdio_bitbang);
35683diff --git a/drivers/net/ppp/ppp_generic.c b/drivers/net/ppp/ppp_generic.c
35684index 5c05572..389610b 100644
35685--- a/drivers/net/ppp/ppp_generic.c
35686+++ b/drivers/net/ppp/ppp_generic.c
35687@@ -986,7 +986,6 @@ ppp_net_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
35688 void __user *addr = (void __user *) ifr->ifr_ifru.ifru_data;
35689 struct ppp_stats stats;
35690 struct ppp_comp_stats cstats;
35691- char *vers;
35692
35693 switch (cmd) {
35694 case SIOCGPPPSTATS:
35695@@ -1008,8 +1007,7 @@ ppp_net_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
35696 break;
35697
35698 case SIOCGPPPVER:
35699- vers = PPP_VERSION;
35700- if (copy_to_user(addr, vers, strlen(vers) + 1))
35701+ if (copy_to_user(addr, PPP_VERSION, sizeof(PPP_VERSION)))
35702 break;
35703 err = 0;
35704 break;
35705diff --git a/drivers/net/tun.c b/drivers/net/tun.c
35706index 3a16d4f..a311cec 100644
35707--- a/drivers/net/tun.c
35708+++ b/drivers/net/tun.c
35709@@ -1367,7 +1367,7 @@ static int set_offload(struct tun_struct *tun, unsigned long arg)
35710 }
35711
35712 static long __tun_chr_ioctl(struct file *file, unsigned int cmd,
35713- unsigned long arg, int ifreq_len)
35714+ unsigned long arg, size_t ifreq_len)
35715 {
35716 struct tun_file *tfile = file->private_data;
35717 struct tun_struct *tun;
35718@@ -1378,6 +1378,9 @@ static long __tun_chr_ioctl(struct file *file, unsigned int cmd,
35719 int vnet_hdr_sz;
35720 int ret;
35721
35722+ if (ifreq_len > sizeof ifr)
35723+ return -EFAULT;
35724+
35725 if (cmd == TUNSETIFF || _IOC_TYPE(cmd) == 0x89) {
35726 if (copy_from_user(&ifr, argp, ifreq_len))
35727 return -EFAULT;
35728diff --git a/drivers/net/usb/hso.c b/drivers/net/usb/hso.c
35729index 62f30b4..ff99dfd 100644
35730--- a/drivers/net/usb/hso.c
35731+++ b/drivers/net/usb/hso.c
35732@@ -71,7 +71,7 @@
35733 #include <asm/byteorder.h>
35734 #include <linux/serial_core.h>
35735 #include <linux/serial.h>
35736-
35737+#include <asm/local.h>
35738
35739 #define MOD_AUTHOR "Option Wireless"
35740 #define MOD_DESCRIPTION "USB High Speed Option driver"
35741@@ -1182,7 +1182,7 @@ static void put_rxbuf_data_and_resubmit_ctrl_urb(struct hso_serial *serial)
35742 struct urb *urb;
35743
35744 urb = serial->rx_urb[0];
35745- if (serial->port.count > 0) {
35746+ if (atomic_read(&serial->port.count) > 0) {
35747 count = put_rxbuf_data(urb, serial);
35748 if (count == -1)
35749 return;
35750@@ -1218,7 +1218,7 @@ static void hso_std_serial_read_bulk_callback(struct urb *urb)
35751 DUMP1(urb->transfer_buffer, urb->actual_length);
35752
35753 /* Anyone listening? */
35754- if (serial->port.count == 0)
35755+ if (atomic_read(&serial->port.count) == 0)
35756 return;
35757
35758 if (status == 0) {
35759@@ -1300,8 +1300,7 @@ static int hso_serial_open(struct tty_struct *tty, struct file *filp)
35760 tty_port_tty_set(&serial->port, tty);
35761
35762 /* check for port already opened, if not set the termios */
35763- serial->port.count++;
35764- if (serial->port.count == 1) {
35765+ if (atomic_inc_return(&serial->port.count) == 1) {
35766 serial->rx_state = RX_IDLE;
35767 /* Force default termio settings */
35768 _hso_serial_set_termios(tty, NULL);
35769@@ -1313,7 +1312,7 @@ static int hso_serial_open(struct tty_struct *tty, struct file *filp)
35770 result = hso_start_serial_device(serial->parent, GFP_KERNEL);
35771 if (result) {
35772 hso_stop_serial_device(serial->parent);
35773- serial->port.count--;
35774+ atomic_dec(&serial->port.count);
35775 kref_put(&serial->parent->ref, hso_serial_ref_free);
35776 }
35777 } else {
35778@@ -1350,10 +1349,10 @@ static void hso_serial_close(struct tty_struct *tty, struct file *filp)
35779
35780 /* reset the rts and dtr */
35781 /* do the actual close */
35782- serial->port.count--;
35783+ atomic_dec(&serial->port.count);
35784
35785- if (serial->port.count <= 0) {
35786- serial->port.count = 0;
35787+ if (atomic_read(&serial->port.count) <= 0) {
35788+ atomic_set(&serial->port.count, 0);
35789 tty_port_tty_set(&serial->port, NULL);
35790 if (!usb_gone)
35791 hso_stop_serial_device(serial->parent);
35792@@ -1429,7 +1428,7 @@ static void hso_serial_set_termios(struct tty_struct *tty, struct ktermios *old)
35793
35794 /* the actual setup */
35795 spin_lock_irqsave(&serial->serial_lock, flags);
35796- if (serial->port.count)
35797+ if (atomic_read(&serial->port.count))
35798 _hso_serial_set_termios(tty, old);
35799 else
35800 tty->termios = old;
35801@@ -1888,7 +1887,7 @@ static void intr_callback(struct urb *urb)
35802 D1("Pending read interrupt on port %d\n", i);
35803 spin_lock(&serial->serial_lock);
35804 if (serial->rx_state == RX_IDLE &&
35805- serial->port.count > 0) {
35806+ atomic_read(&serial->port.count) > 0) {
35807 /* Setup and send a ctrl req read on
35808 * port i */
35809 if (!serial->rx_urb_filled[0]) {
35810@@ -3079,7 +3078,7 @@ static int hso_resume(struct usb_interface *iface)
35811 /* Start all serial ports */
35812 for (i = 0; i < HSO_SERIAL_TTY_MINORS; i++) {
35813 if (serial_table[i] && (serial_table[i]->interface == iface)) {
35814- if (dev2ser(serial_table[i])->port.count) {
35815+ if (atomic_read(&dev2ser(serial_table[i])->port.count)) {
35816 result =
35817 hso_start_serial_device(serial_table[i], GFP_NOIO);
35818 hso_kick_transmit(dev2ser(serial_table[i]));
35819diff --git a/drivers/net/wireless/ath/ath.h b/drivers/net/wireless/ath/ath.h
35820index 6169fbd..40e8422 100644
35821--- a/drivers/net/wireless/ath/ath.h
35822+++ b/drivers/net/wireless/ath/ath.h
35823@@ -119,6 +119,7 @@ struct ath_ops {
35824 void (*write_flush) (void *);
35825 u32 (*rmw)(void *, u32 reg_offset, u32 set, u32 clr);
35826 };
35827+typedef struct ath_ops __no_const ath_ops_no_const;
35828
35829 struct ath_common;
35830 struct ath_bus_ops;
35831diff --git a/drivers/net/wireless/ath/ath5k/base.c b/drivers/net/wireless/ath/ath5k/base.c
35832index 2aab20e..b761ef8 100644
35833--- a/drivers/net/wireless/ath/ath5k/base.c
35834+++ b/drivers/net/wireless/ath/ath5k/base.c
35835@@ -1803,7 +1803,7 @@ ath5k_beacon_update(struct ieee80211_hw *hw, struct ieee80211_vif *vif)
35836 {
35837 int ret;
35838 struct ath5k_hw *ah = hw->priv;
35839- struct ath5k_vif *avf = (void *)vif->drv_priv;
35840+ struct ath5k_vif *avf;
35841 struct sk_buff *skb;
35842
35843 if (WARN_ON(!vif)) {
35844@@ -1818,6 +1818,7 @@ ath5k_beacon_update(struct ieee80211_hw *hw, struct ieee80211_vif *vif)
35845 goto out;
35846 }
35847
35848+ avf = (void *)vif->drv_priv;
35849 ath5k_txbuf_free_skb(ah, avf->bbuf);
35850 avf->bbuf->skb = skb;
35851 ret = ath5k_beacon_setup(ah, avf->bbuf);
35852diff --git a/drivers/net/wireless/ath/ath9k/ar9002_mac.c b/drivers/net/wireless/ath/ath9k/ar9002_mac.c
35853index 8d78253..bebbb68 100644
35854--- a/drivers/net/wireless/ath/ath9k/ar9002_mac.c
35855+++ b/drivers/net/wireless/ath/ath9k/ar9002_mac.c
35856@@ -184,8 +184,8 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
35857 ads->ds_txstatus6 = ads->ds_txstatus7 = 0;
35858 ads->ds_txstatus8 = ads->ds_txstatus9 = 0;
35859
35860- ACCESS_ONCE(ads->ds_link) = i->link;
35861- ACCESS_ONCE(ads->ds_data) = i->buf_addr[0];
35862+ ACCESS_ONCE_RW(ads->ds_link) = i->link;
35863+ ACCESS_ONCE_RW(ads->ds_data) = i->buf_addr[0];
35864
35865 ctl1 = i->buf_len[0] | (i->is_last ? 0 : AR_TxMore);
35866 ctl6 = SM(i->keytype, AR_EncrType);
35867@@ -199,26 +199,26 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
35868
35869 if ((i->is_first || i->is_last) &&
35870 i->aggr != AGGR_BUF_MIDDLE && i->aggr != AGGR_BUF_LAST) {
35871- ACCESS_ONCE(ads->ds_ctl2) = set11nTries(i->rates, 0)
35872+ ACCESS_ONCE_RW(ads->ds_ctl2) = set11nTries(i->rates, 0)
35873 | set11nTries(i->rates, 1)
35874 | set11nTries(i->rates, 2)
35875 | set11nTries(i->rates, 3)
35876 | (i->dur_update ? AR_DurUpdateEna : 0)
35877 | SM(0, AR_BurstDur);
35878
35879- ACCESS_ONCE(ads->ds_ctl3) = set11nRate(i->rates, 0)
35880+ ACCESS_ONCE_RW(ads->ds_ctl3) = set11nRate(i->rates, 0)
35881 | set11nRate(i->rates, 1)
35882 | set11nRate(i->rates, 2)
35883 | set11nRate(i->rates, 3);
35884 } else {
35885- ACCESS_ONCE(ads->ds_ctl2) = 0;
35886- ACCESS_ONCE(ads->ds_ctl3) = 0;
35887+ ACCESS_ONCE_RW(ads->ds_ctl2) = 0;
35888+ ACCESS_ONCE_RW(ads->ds_ctl3) = 0;
35889 }
35890
35891 if (!i->is_first) {
35892- ACCESS_ONCE(ads->ds_ctl0) = 0;
35893- ACCESS_ONCE(ads->ds_ctl1) = ctl1;
35894- ACCESS_ONCE(ads->ds_ctl6) = ctl6;
35895+ ACCESS_ONCE_RW(ads->ds_ctl0) = 0;
35896+ ACCESS_ONCE_RW(ads->ds_ctl1) = ctl1;
35897+ ACCESS_ONCE_RW(ads->ds_ctl6) = ctl6;
35898 return;
35899 }
35900
35901@@ -243,7 +243,7 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
35902 break;
35903 }
35904
35905- ACCESS_ONCE(ads->ds_ctl0) = (i->pkt_len & AR_FrameLen)
35906+ ACCESS_ONCE_RW(ads->ds_ctl0) = (i->pkt_len & AR_FrameLen)
35907 | (i->flags & ATH9K_TXDESC_VMF ? AR_VirtMoreFrag : 0)
35908 | SM(i->txpower, AR_XmitPower)
35909 | (i->flags & ATH9K_TXDESC_VEOL ? AR_VEOL : 0)
35910@@ -253,19 +253,19 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
35911 | (i->flags & ATH9K_TXDESC_RTSENA ? AR_RTSEnable :
35912 (i->flags & ATH9K_TXDESC_CTSENA ? AR_CTSEnable : 0));
35913
35914- ACCESS_ONCE(ads->ds_ctl1) = ctl1;
35915- ACCESS_ONCE(ads->ds_ctl6) = ctl6;
35916+ ACCESS_ONCE_RW(ads->ds_ctl1) = ctl1;
35917+ ACCESS_ONCE_RW(ads->ds_ctl6) = ctl6;
35918
35919 if (i->aggr == AGGR_BUF_MIDDLE || i->aggr == AGGR_BUF_LAST)
35920 return;
35921
35922- ACCESS_ONCE(ads->ds_ctl4) = set11nPktDurRTSCTS(i->rates, 0)
35923+ ACCESS_ONCE_RW(ads->ds_ctl4) = set11nPktDurRTSCTS(i->rates, 0)
35924 | set11nPktDurRTSCTS(i->rates, 1);
35925
35926- ACCESS_ONCE(ads->ds_ctl5) = set11nPktDurRTSCTS(i->rates, 2)
35927+ ACCESS_ONCE_RW(ads->ds_ctl5) = set11nPktDurRTSCTS(i->rates, 2)
35928 | set11nPktDurRTSCTS(i->rates, 3);
35929
35930- ACCESS_ONCE(ads->ds_ctl7) = set11nRateFlags(i->rates, 0)
35931+ ACCESS_ONCE_RW(ads->ds_ctl7) = set11nRateFlags(i->rates, 0)
35932 | set11nRateFlags(i->rates, 1)
35933 | set11nRateFlags(i->rates, 2)
35934 | set11nRateFlags(i->rates, 3)
35935diff --git a/drivers/net/wireless/ath/ath9k/ar9003_mac.c b/drivers/net/wireless/ath/ath9k/ar9003_mac.c
35936index 78816b8..1fcdfae 100644
35937--- a/drivers/net/wireless/ath/ath9k/ar9003_mac.c
35938+++ b/drivers/net/wireless/ath/ath9k/ar9003_mac.c
35939@@ -39,47 +39,47 @@ ar9003_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
35940 (i->qcu << AR_TxQcuNum_S) | desc_len;
35941
35942 checksum += val;
35943- ACCESS_ONCE(ads->info) = val;
35944+ ACCESS_ONCE_RW(ads->info) = val;
35945
35946 checksum += i->link;
35947- ACCESS_ONCE(ads->link) = i->link;
35948+ ACCESS_ONCE_RW(ads->link) = i->link;
35949
35950 checksum += i->buf_addr[0];
35951- ACCESS_ONCE(ads->data0) = i->buf_addr[0];
35952+ ACCESS_ONCE_RW(ads->data0) = i->buf_addr[0];
35953 checksum += i->buf_addr[1];
35954- ACCESS_ONCE(ads->data1) = i->buf_addr[1];
35955+ ACCESS_ONCE_RW(ads->data1) = i->buf_addr[1];
35956 checksum += i->buf_addr[2];
35957- ACCESS_ONCE(ads->data2) = i->buf_addr[2];
35958+ ACCESS_ONCE_RW(ads->data2) = i->buf_addr[2];
35959 checksum += i->buf_addr[3];
35960- ACCESS_ONCE(ads->data3) = i->buf_addr[3];
35961+ ACCESS_ONCE_RW(ads->data3) = i->buf_addr[3];
35962
35963 checksum += (val = (i->buf_len[0] << AR_BufLen_S) & AR_BufLen);
35964- ACCESS_ONCE(ads->ctl3) = val;
35965+ ACCESS_ONCE_RW(ads->ctl3) = val;
35966 checksum += (val = (i->buf_len[1] << AR_BufLen_S) & AR_BufLen);
35967- ACCESS_ONCE(ads->ctl5) = val;
35968+ ACCESS_ONCE_RW(ads->ctl5) = val;
35969 checksum += (val = (i->buf_len[2] << AR_BufLen_S) & AR_BufLen);
35970- ACCESS_ONCE(ads->ctl7) = val;
35971+ ACCESS_ONCE_RW(ads->ctl7) = val;
35972 checksum += (val = (i->buf_len[3] << AR_BufLen_S) & AR_BufLen);
35973- ACCESS_ONCE(ads->ctl9) = val;
35974+ ACCESS_ONCE_RW(ads->ctl9) = val;
35975
35976 checksum = (u16) (((checksum & 0xffff) + (checksum >> 16)) & 0xffff);
35977- ACCESS_ONCE(ads->ctl10) = checksum;
35978+ ACCESS_ONCE_RW(ads->ctl10) = checksum;
35979
35980 if (i->is_first || i->is_last) {
35981- ACCESS_ONCE(ads->ctl13) = set11nTries(i->rates, 0)
35982+ ACCESS_ONCE_RW(ads->ctl13) = set11nTries(i->rates, 0)
35983 | set11nTries(i->rates, 1)
35984 | set11nTries(i->rates, 2)
35985 | set11nTries(i->rates, 3)
35986 | (i->dur_update ? AR_DurUpdateEna : 0)
35987 | SM(0, AR_BurstDur);
35988
35989- ACCESS_ONCE(ads->ctl14) = set11nRate(i->rates, 0)
35990+ ACCESS_ONCE_RW(ads->ctl14) = set11nRate(i->rates, 0)
35991 | set11nRate(i->rates, 1)
35992 | set11nRate(i->rates, 2)
35993 | set11nRate(i->rates, 3);
35994 } else {
35995- ACCESS_ONCE(ads->ctl13) = 0;
35996- ACCESS_ONCE(ads->ctl14) = 0;
35997+ ACCESS_ONCE_RW(ads->ctl13) = 0;
35998+ ACCESS_ONCE_RW(ads->ctl14) = 0;
35999 }
36000
36001 ads->ctl20 = 0;
36002@@ -89,17 +89,17 @@ ar9003_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
36003
36004 ctl17 = SM(i->keytype, AR_EncrType);
36005 if (!i->is_first) {
36006- ACCESS_ONCE(ads->ctl11) = 0;
36007- ACCESS_ONCE(ads->ctl12) = i->is_last ? 0 : AR_TxMore;
36008- ACCESS_ONCE(ads->ctl15) = 0;
36009- ACCESS_ONCE(ads->ctl16) = 0;
36010- ACCESS_ONCE(ads->ctl17) = ctl17;
36011- ACCESS_ONCE(ads->ctl18) = 0;
36012- ACCESS_ONCE(ads->ctl19) = 0;
36013+ ACCESS_ONCE_RW(ads->ctl11) = 0;
36014+ ACCESS_ONCE_RW(ads->ctl12) = i->is_last ? 0 : AR_TxMore;
36015+ ACCESS_ONCE_RW(ads->ctl15) = 0;
36016+ ACCESS_ONCE_RW(ads->ctl16) = 0;
36017+ ACCESS_ONCE_RW(ads->ctl17) = ctl17;
36018+ ACCESS_ONCE_RW(ads->ctl18) = 0;
36019+ ACCESS_ONCE_RW(ads->ctl19) = 0;
36020 return;
36021 }
36022
36023- ACCESS_ONCE(ads->ctl11) = (i->pkt_len & AR_FrameLen)
36024+ ACCESS_ONCE_RW(ads->ctl11) = (i->pkt_len & AR_FrameLen)
36025 | (i->flags & ATH9K_TXDESC_VMF ? AR_VirtMoreFrag : 0)
36026 | SM(i->txpower, AR_XmitPower)
36027 | (i->flags & ATH9K_TXDESC_VEOL ? AR_VEOL : 0)
36028@@ -135,22 +135,22 @@ ar9003_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
36029 val = (i->flags & ATH9K_TXDESC_PAPRD) >> ATH9K_TXDESC_PAPRD_S;
36030 ctl12 |= SM(val, AR_PAPRDChainMask);
36031
36032- ACCESS_ONCE(ads->ctl12) = ctl12;
36033- ACCESS_ONCE(ads->ctl17) = ctl17;
36034+ ACCESS_ONCE_RW(ads->ctl12) = ctl12;
36035+ ACCESS_ONCE_RW(ads->ctl17) = ctl17;
36036
36037- ACCESS_ONCE(ads->ctl15) = set11nPktDurRTSCTS(i->rates, 0)
36038+ ACCESS_ONCE_RW(ads->ctl15) = set11nPktDurRTSCTS(i->rates, 0)
36039 | set11nPktDurRTSCTS(i->rates, 1);
36040
36041- ACCESS_ONCE(ads->ctl16) = set11nPktDurRTSCTS(i->rates, 2)
36042+ ACCESS_ONCE_RW(ads->ctl16) = set11nPktDurRTSCTS(i->rates, 2)
36043 | set11nPktDurRTSCTS(i->rates, 3);
36044
36045- ACCESS_ONCE(ads->ctl18) = set11nRateFlags(i->rates, 0)
36046+ ACCESS_ONCE_RW(ads->ctl18) = set11nRateFlags(i->rates, 0)
36047 | set11nRateFlags(i->rates, 1)
36048 | set11nRateFlags(i->rates, 2)
36049 | set11nRateFlags(i->rates, 3)
36050 | SM(i->rtscts_rate, AR_RTSCTSRate);
36051
36052- ACCESS_ONCE(ads->ctl19) = AR_Not_Sounding;
36053+ ACCESS_ONCE_RW(ads->ctl19) = AR_Not_Sounding;
36054 }
36055
36056 static u16 ar9003_calc_ptr_chksum(struct ar9003_txc *ads)
36057diff --git a/drivers/net/wireless/ath/ath9k/hw.h b/drivers/net/wireless/ath/ath9k/hw.h
36058index de6968f..29ac4c1 100644
36059--- a/drivers/net/wireless/ath/ath9k/hw.h
36060+++ b/drivers/net/wireless/ath/ath9k/hw.h
36061@@ -656,7 +656,7 @@ struct ath_hw_private_ops {
36062
36063 /* ANI */
36064 void (*ani_cache_ini_regs)(struct ath_hw *ah);
36065-};
36066+} __no_const;
36067
36068 /**
36069 * struct ath_hw_ops - callbacks used by hardware code and driver code
36070@@ -686,7 +686,7 @@ struct ath_hw_ops {
36071 void (*antdiv_comb_conf_set)(struct ath_hw *ah,
36072 struct ath_hw_antcomb_conf *antconf);
36073
36074-};
36075+} __no_const;
36076
36077 struct ath_nf_limits {
36078 s16 max;
36079@@ -706,7 +706,7 @@ enum ath_cal_list {
36080 #define AH_FASTCC 0x4
36081
36082 struct ath_hw {
36083- struct ath_ops reg_ops;
36084+ ath_ops_no_const reg_ops;
36085
36086 struct ieee80211_hw *hw;
36087 struct ath_common common;
36088diff --git a/drivers/net/wireless/brcm80211/brcmsmac/phy/phy_int.h b/drivers/net/wireless/brcm80211/brcmsmac/phy/phy_int.h
36089index af00e2c..ab04d34 100644
36090--- a/drivers/net/wireless/brcm80211/brcmsmac/phy/phy_int.h
36091+++ b/drivers/net/wireless/brcm80211/brcmsmac/phy/phy_int.h
36092@@ -545,7 +545,7 @@ struct phy_func_ptr {
36093 void (*carrsuppr)(struct brcms_phy *);
36094 s32 (*rxsigpwr)(struct brcms_phy *, s32);
36095 void (*detach)(struct brcms_phy *);
36096-};
36097+} __no_const;
36098
36099 struct brcms_phy {
36100 struct brcms_phy_pub pubpi_ro;
36101diff --git a/drivers/net/wireless/iwlegacy/3945-mac.c b/drivers/net/wireless/iwlegacy/3945-mac.c
36102index faec404..a5277f1 100644
36103--- a/drivers/net/wireless/iwlegacy/3945-mac.c
36104+++ b/drivers/net/wireless/iwlegacy/3945-mac.c
36105@@ -3611,7 +3611,9 @@ il3945_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
36106 */
36107 if (il3945_mod_params.disable_hw_scan) {
36108 D_INFO("Disabling hw_scan\n");
36109- il3945_mac_ops.hw_scan = NULL;
36110+ pax_open_kernel();
36111+ *(void **)&il3945_mac_ops.hw_scan = NULL;
36112+ pax_close_kernel();
36113 }
36114
36115 D_INFO("*** LOAD DRIVER ***\n");
36116diff --git a/drivers/net/wireless/iwlwifi/dvm/debugfs.c b/drivers/net/wireless/iwlwifi/dvm/debugfs.c
36117index a47b306..297daf2 100644
36118--- a/drivers/net/wireless/iwlwifi/dvm/debugfs.c
36119+++ b/drivers/net/wireless/iwlwifi/dvm/debugfs.c
36120@@ -203,7 +203,7 @@ static ssize_t iwl_dbgfs_sram_write(struct file *file,
36121 {
36122 struct iwl_priv *priv = file->private_data;
36123 char buf[64];
36124- int buf_size;
36125+ size_t buf_size;
36126 u32 offset, len;
36127
36128 memset(buf, 0, sizeof(buf));
36129@@ -473,7 +473,7 @@ static ssize_t iwl_dbgfs_rx_handlers_write(struct file *file,
36130 struct iwl_priv *priv = file->private_data;
36131
36132 char buf[8];
36133- int buf_size;
36134+ size_t buf_size;
36135 u32 reset_flag;
36136
36137 memset(buf, 0, sizeof(buf));
36138@@ -554,7 +554,7 @@ static ssize_t iwl_dbgfs_disable_ht40_write(struct file *file,
36139 {
36140 struct iwl_priv *priv = file->private_data;
36141 char buf[8];
36142- int buf_size;
36143+ size_t buf_size;
36144 int ht40;
36145
36146 memset(buf, 0, sizeof(buf));
36147@@ -606,7 +606,7 @@ static ssize_t iwl_dbgfs_sleep_level_override_write(struct file *file,
36148 {
36149 struct iwl_priv *priv = file->private_data;
36150 char buf[8];
36151- int buf_size;
36152+ size_t buf_size;
36153 int value;
36154
36155 memset(buf, 0, sizeof(buf));
36156@@ -1871,7 +1871,7 @@ static ssize_t iwl_dbgfs_clear_ucode_statistics_write(struct file *file,
36157 {
36158 struct iwl_priv *priv = file->private_data;
36159 char buf[8];
36160- int buf_size;
36161+ size_t buf_size;
36162 int clear;
36163
36164 memset(buf, 0, sizeof(buf));
36165@@ -1916,7 +1916,7 @@ static ssize_t iwl_dbgfs_ucode_tracing_write(struct file *file,
36166 {
36167 struct iwl_priv *priv = file->private_data;
36168 char buf[8];
36169- int buf_size;
36170+ size_t buf_size;
36171 int trace;
36172
36173 memset(buf, 0, sizeof(buf));
36174@@ -1987,7 +1987,7 @@ static ssize_t iwl_dbgfs_missed_beacon_write(struct file *file,
36175 {
36176 struct iwl_priv *priv = file->private_data;
36177 char buf[8];
36178- int buf_size;
36179+ size_t buf_size;
36180 int missed;
36181
36182 memset(buf, 0, sizeof(buf));
36183@@ -2028,7 +2028,7 @@ static ssize_t iwl_dbgfs_plcp_delta_write(struct file *file,
36184
36185 struct iwl_priv *priv = file->private_data;
36186 char buf[8];
36187- int buf_size;
36188+ size_t buf_size;
36189 int plcp;
36190
36191 memset(buf, 0, sizeof(buf));
36192@@ -2088,7 +2088,7 @@ static ssize_t iwl_dbgfs_txfifo_flush_write(struct file *file,
36193
36194 struct iwl_priv *priv = file->private_data;
36195 char buf[8];
36196- int buf_size;
36197+ size_t buf_size;
36198 int flush;
36199
36200 memset(buf, 0, sizeof(buf));
36201@@ -2178,7 +2178,7 @@ static ssize_t iwl_dbgfs_protection_mode_write(struct file *file,
36202
36203 struct iwl_priv *priv = file->private_data;
36204 char buf[8];
36205- int buf_size;
36206+ size_t buf_size;
36207 int rts;
36208
36209 if (!priv->cfg->ht_params)
36210@@ -2220,7 +2220,7 @@ static ssize_t iwl_dbgfs_echo_test_write(struct file *file,
36211 {
36212 struct iwl_priv *priv = file->private_data;
36213 char buf[8];
36214- int buf_size;
36215+ size_t buf_size;
36216
36217 memset(buf, 0, sizeof(buf));
36218 buf_size = min(count, sizeof(buf) - 1);
36219@@ -2256,7 +2256,7 @@ static ssize_t iwl_dbgfs_log_event_write(struct file *file,
36220 struct iwl_priv *priv = file->private_data;
36221 u32 event_log_flag;
36222 char buf[8];
36223- int buf_size;
36224+ size_t buf_size;
36225
36226 /* check that the interface is up */
36227 if (!iwl_is_ready(priv))
36228@@ -2310,7 +2310,7 @@ static ssize_t iwl_dbgfs_calib_disabled_write(struct file *file,
36229 struct iwl_priv *priv = file->private_data;
36230 char buf[8];
36231 u32 calib_disabled;
36232- int buf_size;
36233+ size_t buf_size;
36234
36235 memset(buf, 0, sizeof(buf));
36236 buf_size = min(count, sizeof(buf) - 1);
36237diff --git a/drivers/net/wireless/iwlwifi/pcie/trans.c b/drivers/net/wireless/iwlwifi/pcie/trans.c
36238index dbeebef..b45a152 100644
36239--- a/drivers/net/wireless/iwlwifi/pcie/trans.c
36240+++ b/drivers/net/wireless/iwlwifi/pcie/trans.c
36241@@ -1944,7 +1944,7 @@ static ssize_t iwl_dbgfs_interrupt_write(struct file *file,
36242 struct isr_statistics *isr_stats = &trans_pcie->isr_stats;
36243
36244 char buf[8];
36245- int buf_size;
36246+ size_t buf_size;
36247 u32 reset_flag;
36248
36249 memset(buf, 0, sizeof(buf));
36250@@ -1965,7 +1965,7 @@ static ssize_t iwl_dbgfs_csr_write(struct file *file,
36251 {
36252 struct iwl_trans *trans = file->private_data;
36253 char buf[8];
36254- int buf_size;
36255+ size_t buf_size;
36256 int csr;
36257
36258 memset(buf, 0, sizeof(buf));
36259diff --git a/drivers/net/wireless/mac80211_hwsim.c b/drivers/net/wireless/mac80211_hwsim.c
36260index 0083839..fcb7225 100644
36261--- a/drivers/net/wireless/mac80211_hwsim.c
36262+++ b/drivers/net/wireless/mac80211_hwsim.c
36263@@ -1748,9 +1748,11 @@ static int __init init_mac80211_hwsim(void)
36264 return -EINVAL;
36265
36266 if (fake_hw_scan) {
36267- mac80211_hwsim_ops.hw_scan = mac80211_hwsim_hw_scan;
36268- mac80211_hwsim_ops.sw_scan_start = NULL;
36269- mac80211_hwsim_ops.sw_scan_complete = NULL;
36270+ pax_open_kernel();
36271+ *(void **)&mac80211_hwsim_ops.hw_scan = mac80211_hwsim_hw_scan;
36272+ *(void **)&mac80211_hwsim_ops.sw_scan_start = NULL;
36273+ *(void **)&mac80211_hwsim_ops.sw_scan_complete = NULL;
36274+ pax_close_kernel();
36275 }
36276
36277 spin_lock_init(&hwsim_radio_lock);
36278diff --git a/drivers/net/wireless/mwifiex/main.h b/drivers/net/wireless/mwifiex/main.h
36279index e7c2a82..582e228 100644
36280--- a/drivers/net/wireless/mwifiex/main.h
36281+++ b/drivers/net/wireless/mwifiex/main.h
36282@@ -571,7 +571,7 @@ struct mwifiex_if_ops {
36283 int (*event_complete) (struct mwifiex_adapter *, struct sk_buff *);
36284 int (*data_complete) (struct mwifiex_adapter *, struct sk_buff *);
36285 int (*dnld_fw) (struct mwifiex_adapter *, struct mwifiex_fw_image *);
36286-};
36287+} __no_const;
36288
36289 struct mwifiex_adapter {
36290 u8 iface_type;
36291diff --git a/drivers/net/wireless/rndis_wlan.c b/drivers/net/wireless/rndis_wlan.c
36292index 7a4ae9e..56e00bd 100644
36293--- a/drivers/net/wireless/rndis_wlan.c
36294+++ b/drivers/net/wireless/rndis_wlan.c
36295@@ -1235,7 +1235,7 @@ static int set_rts_threshold(struct usbnet *usbdev, u32 rts_threshold)
36296
36297 netdev_dbg(usbdev->net, "%s(): %i\n", __func__, rts_threshold);
36298
36299- if (rts_threshold < 0 || rts_threshold > 2347)
36300+ if (rts_threshold > 2347)
36301 rts_threshold = 2347;
36302
36303 tmp = cpu_to_le32(rts_threshold);
36304diff --git a/drivers/net/wireless/rt2x00/rt2x00.h b/drivers/net/wireless/rt2x00/rt2x00.h
36305index 8afb546..0c0dc5c 100644
36306--- a/drivers/net/wireless/rt2x00/rt2x00.h
36307+++ b/drivers/net/wireless/rt2x00/rt2x00.h
36308@@ -397,7 +397,7 @@ struct rt2x00_intf {
36309 * for hardware which doesn't support hardware
36310 * sequence counting.
36311 */
36312- atomic_t seqno;
36313+ atomic_unchecked_t seqno;
36314 };
36315
36316 static inline struct rt2x00_intf* vif_to_intf(struct ieee80211_vif *vif)
36317diff --git a/drivers/net/wireless/rt2x00/rt2x00queue.c b/drivers/net/wireless/rt2x00/rt2x00queue.c
36318index f7e74a0..da71431 100644
36319--- a/drivers/net/wireless/rt2x00/rt2x00queue.c
36320+++ b/drivers/net/wireless/rt2x00/rt2x00queue.c
36321@@ -240,9 +240,9 @@ static void rt2x00queue_create_tx_descriptor_seq(struct rt2x00_dev *rt2x00dev,
36322 * sequence counter given by mac80211.
36323 */
36324 if (test_bit(ENTRY_TXD_FIRST_FRAGMENT, &txdesc->flags))
36325- seqno = atomic_add_return(0x10, &intf->seqno);
36326+ seqno = atomic_add_return_unchecked(0x10, &intf->seqno);
36327 else
36328- seqno = atomic_read(&intf->seqno);
36329+ seqno = atomic_read_unchecked(&intf->seqno);
36330
36331 hdr->seq_ctrl &= cpu_to_le16(IEEE80211_SCTL_FRAG);
36332 hdr->seq_ctrl |= cpu_to_le16(seqno);
36333diff --git a/drivers/net/wireless/ti/wl1251/wl1251.h b/drivers/net/wireless/ti/wl1251/wl1251.h
36334index fd02060..74ee481 100644
36335--- a/drivers/net/wireless/ti/wl1251/wl1251.h
36336+++ b/drivers/net/wireless/ti/wl1251/wl1251.h
36337@@ -266,7 +266,7 @@ struct wl1251_if_operations {
36338 void (*reset)(struct wl1251 *wl);
36339 void (*enable_irq)(struct wl1251 *wl);
36340 void (*disable_irq)(struct wl1251 *wl);
36341-};
36342+} __no_const;
36343
36344 struct wl1251 {
36345 struct ieee80211_hw *hw;
36346diff --git a/drivers/net/wireless/ti/wlcore/wlcore.h b/drivers/net/wireless/ti/wlcore/wlcore.h
36347index 0ce7a8e..56a0ccf 100644
36348--- a/drivers/net/wireless/ti/wlcore/wlcore.h
36349+++ b/drivers/net/wireless/ti/wlcore/wlcore.h
36350@@ -81,7 +81,7 @@ struct wlcore_ops {
36351 struct ieee80211_sta *sta,
36352 struct ieee80211_key_conf *key_conf);
36353 u32 (*pre_pkt_send)(struct wl1271 *wl, u32 buf_offset, u32 last_len);
36354-};
36355+} __no_const;
36356
36357 enum wlcore_partitions {
36358 PART_DOWN,
36359diff --git a/drivers/oprofile/buffer_sync.c b/drivers/oprofile/buffer_sync.c
36360index f34b5b2..b5abb9f 100644
36361--- a/drivers/oprofile/buffer_sync.c
36362+++ b/drivers/oprofile/buffer_sync.c
36363@@ -343,7 +343,7 @@ static void add_data(struct op_entry *entry, struct mm_struct *mm)
36364 if (cookie == NO_COOKIE)
36365 offset = pc;
36366 if (cookie == INVALID_COOKIE) {
36367- atomic_inc(&oprofile_stats.sample_lost_no_mapping);
36368+ atomic_inc_unchecked(&oprofile_stats.sample_lost_no_mapping);
36369 offset = pc;
36370 }
36371 if (cookie != last_cookie) {
36372@@ -387,14 +387,14 @@ add_sample(struct mm_struct *mm, struct op_sample *s, int in_kernel)
36373 /* add userspace sample */
36374
36375 if (!mm) {
36376- atomic_inc(&oprofile_stats.sample_lost_no_mm);
36377+ atomic_inc_unchecked(&oprofile_stats.sample_lost_no_mm);
36378 return 0;
36379 }
36380
36381 cookie = lookup_dcookie(mm, s->eip, &offset);
36382
36383 if (cookie == INVALID_COOKIE) {
36384- atomic_inc(&oprofile_stats.sample_lost_no_mapping);
36385+ atomic_inc_unchecked(&oprofile_stats.sample_lost_no_mapping);
36386 return 0;
36387 }
36388
36389@@ -563,7 +563,7 @@ void sync_buffer(int cpu)
36390 /* ignore backtraces if failed to add a sample */
36391 if (state == sb_bt_start) {
36392 state = sb_bt_ignore;
36393- atomic_inc(&oprofile_stats.bt_lost_no_mapping);
36394+ atomic_inc_unchecked(&oprofile_stats.bt_lost_no_mapping);
36395 }
36396 }
36397 release_mm(mm);
36398diff --git a/drivers/oprofile/event_buffer.c b/drivers/oprofile/event_buffer.c
36399index c0cc4e7..44d4e54 100644
36400--- a/drivers/oprofile/event_buffer.c
36401+++ b/drivers/oprofile/event_buffer.c
36402@@ -53,7 +53,7 @@ void add_event_entry(unsigned long value)
36403 }
36404
36405 if (buffer_pos == buffer_size) {
36406- atomic_inc(&oprofile_stats.event_lost_overflow);
36407+ atomic_inc_unchecked(&oprofile_stats.event_lost_overflow);
36408 return;
36409 }
36410
36411diff --git a/drivers/oprofile/oprof.c b/drivers/oprofile/oprof.c
36412index ed2c3ec..deda85a 100644
36413--- a/drivers/oprofile/oprof.c
36414+++ b/drivers/oprofile/oprof.c
36415@@ -110,7 +110,7 @@ static void switch_worker(struct work_struct *work)
36416 if (oprofile_ops.switch_events())
36417 return;
36418
36419- atomic_inc(&oprofile_stats.multiplex_counter);
36420+ atomic_inc_unchecked(&oprofile_stats.multiplex_counter);
36421 start_switch_worker();
36422 }
36423
36424diff --git a/drivers/oprofile/oprofile_stats.c b/drivers/oprofile/oprofile_stats.c
36425index 917d28e..d62d981 100644
36426--- a/drivers/oprofile/oprofile_stats.c
36427+++ b/drivers/oprofile/oprofile_stats.c
36428@@ -30,11 +30,11 @@ void oprofile_reset_stats(void)
36429 cpu_buf->sample_invalid_eip = 0;
36430 }
36431
36432- atomic_set(&oprofile_stats.sample_lost_no_mm, 0);
36433- atomic_set(&oprofile_stats.sample_lost_no_mapping, 0);
36434- atomic_set(&oprofile_stats.event_lost_overflow, 0);
36435- atomic_set(&oprofile_stats.bt_lost_no_mapping, 0);
36436- atomic_set(&oprofile_stats.multiplex_counter, 0);
36437+ atomic_set_unchecked(&oprofile_stats.sample_lost_no_mm, 0);
36438+ atomic_set_unchecked(&oprofile_stats.sample_lost_no_mapping, 0);
36439+ atomic_set_unchecked(&oprofile_stats.event_lost_overflow, 0);
36440+ atomic_set_unchecked(&oprofile_stats.bt_lost_no_mapping, 0);
36441+ atomic_set_unchecked(&oprofile_stats.multiplex_counter, 0);
36442 }
36443
36444
36445diff --git a/drivers/oprofile/oprofile_stats.h b/drivers/oprofile/oprofile_stats.h
36446index 38b6fc0..b5cbfce 100644
36447--- a/drivers/oprofile/oprofile_stats.h
36448+++ b/drivers/oprofile/oprofile_stats.h
36449@@ -13,11 +13,11 @@
36450 #include <linux/atomic.h>
36451
36452 struct oprofile_stat_struct {
36453- atomic_t sample_lost_no_mm;
36454- atomic_t sample_lost_no_mapping;
36455- atomic_t bt_lost_no_mapping;
36456- atomic_t event_lost_overflow;
36457- atomic_t multiplex_counter;
36458+ atomic_unchecked_t sample_lost_no_mm;
36459+ atomic_unchecked_t sample_lost_no_mapping;
36460+ atomic_unchecked_t bt_lost_no_mapping;
36461+ atomic_unchecked_t event_lost_overflow;
36462+ atomic_unchecked_t multiplex_counter;
36463 };
36464
36465 extern struct oprofile_stat_struct oprofile_stats;
36466diff --git a/drivers/oprofile/oprofilefs.c b/drivers/oprofile/oprofilefs.c
36467index 849357c..b83c1e0 100644
36468--- a/drivers/oprofile/oprofilefs.c
36469+++ b/drivers/oprofile/oprofilefs.c
36470@@ -185,7 +185,7 @@ static const struct file_operations atomic_ro_fops = {
36471
36472
36473 int oprofilefs_create_ro_atomic(struct super_block *sb, struct dentry *root,
36474- char const *name, atomic_t *val)
36475+ char const *name, atomic_unchecked_t *val)
36476 {
36477 return __oprofilefs_create_file(sb, root, name,
36478 &atomic_ro_fops, 0444, val);
36479diff --git a/drivers/parport/procfs.c b/drivers/parport/procfs.c
36480index 3f56bc0..707d642 100644
36481--- a/drivers/parport/procfs.c
36482+++ b/drivers/parport/procfs.c
36483@@ -64,7 +64,7 @@ static int do_active_device(ctl_table *table, int write,
36484
36485 *ppos += len;
36486
36487- return copy_to_user(result, buffer, len) ? -EFAULT : 0;
36488+ return (len > sizeof buffer || copy_to_user(result, buffer, len)) ? -EFAULT : 0;
36489 }
36490
36491 #ifdef CONFIG_PARPORT_1284
36492@@ -106,7 +106,7 @@ static int do_autoprobe(ctl_table *table, int write,
36493
36494 *ppos += len;
36495
36496- return copy_to_user (result, buffer, len) ? -EFAULT : 0;
36497+ return (len > sizeof buffer || copy_to_user (result, buffer, len)) ? -EFAULT : 0;
36498 }
36499 #endif /* IEEE1284.3 support. */
36500
36501diff --git a/drivers/pci/hotplug/cpci_hotplug.h b/drivers/pci/hotplug/cpci_hotplug.h
36502index 9fff878..ad0ad53 100644
36503--- a/drivers/pci/hotplug/cpci_hotplug.h
36504+++ b/drivers/pci/hotplug/cpci_hotplug.h
36505@@ -59,7 +59,7 @@ struct cpci_hp_controller_ops {
36506 int (*hardware_test) (struct slot* slot, u32 value);
36507 u8 (*get_power) (struct slot* slot);
36508 int (*set_power) (struct slot* slot, int value);
36509-};
36510+} __no_const;
36511
36512 struct cpci_hp_controller {
36513 unsigned int irq;
36514diff --git a/drivers/pci/hotplug/cpqphp_nvram.c b/drivers/pci/hotplug/cpqphp_nvram.c
36515index 76ba8a1..20ca857 100644
36516--- a/drivers/pci/hotplug/cpqphp_nvram.c
36517+++ b/drivers/pci/hotplug/cpqphp_nvram.c
36518@@ -428,9 +428,13 @@ static u32 store_HRT (void __iomem *rom_start)
36519
36520 void compaq_nvram_init (void __iomem *rom_start)
36521 {
36522+
36523+#ifndef CONFIG_PAX_KERNEXEC
36524 if (rom_start) {
36525 compaq_int15_entry_point = (rom_start + ROM_INT15_PHY_ADDR - ROM_PHY_ADDR);
36526 }
36527+#endif
36528+
36529 dbg("int15 entry = %p\n", compaq_int15_entry_point);
36530
36531 /* initialize our int15 lock */
36532diff --git a/drivers/pci/pcie/aspm.c b/drivers/pci/pcie/aspm.c
36533index b500840..d7159d3 100644
36534--- a/drivers/pci/pcie/aspm.c
36535+++ b/drivers/pci/pcie/aspm.c
36536@@ -27,9 +27,9 @@
36537 #define MODULE_PARAM_PREFIX "pcie_aspm."
36538
36539 /* Note: those are not register definitions */
36540-#define ASPM_STATE_L0S_UP (1) /* Upstream direction L0s state */
36541-#define ASPM_STATE_L0S_DW (2) /* Downstream direction L0s state */
36542-#define ASPM_STATE_L1 (4) /* L1 state */
36543+#define ASPM_STATE_L0S_UP (1U) /* Upstream direction L0s state */
36544+#define ASPM_STATE_L0S_DW (2U) /* Downstream direction L0s state */
36545+#define ASPM_STATE_L1 (4U) /* L1 state */
36546 #define ASPM_STATE_L0S (ASPM_STATE_L0S_UP | ASPM_STATE_L0S_DW)
36547 #define ASPM_STATE_ALL (ASPM_STATE_L0S | ASPM_STATE_L1)
36548
36549diff --git a/drivers/pci/probe.c b/drivers/pci/probe.c
36550index 61859d0..124539e 100644
36551--- a/drivers/pci/probe.c
36552+++ b/drivers/pci/probe.c
36553@@ -173,7 +173,7 @@ int __pci_read_base(struct pci_dev *dev, enum pci_bar_type type,
36554 struct pci_bus_region region;
36555 bool bar_too_big = false, bar_disabled = false;
36556
36557- mask = type ? PCI_ROM_ADDRESS_MASK : ~0;
36558+ mask = type ? (u32)PCI_ROM_ADDRESS_MASK : ~0;
36559
36560 /* No printks while decoding is disabled! */
36561 if (!dev->mmio_always_on) {
36562diff --git a/drivers/pci/proc.c b/drivers/pci/proc.c
36563index af028c7..654cdfc 100644
36564--- a/drivers/pci/proc.c
36565+++ b/drivers/pci/proc.c
36566@@ -484,7 +484,16 @@ static const struct file_operations proc_bus_pci_dev_operations = {
36567 static int __init pci_proc_init(void)
36568 {
36569 struct pci_dev *dev = NULL;
36570+
36571+#ifdef CONFIG_GRKERNSEC_PROC_ADD
36572+#ifdef CONFIG_GRKERNSEC_PROC_USER
36573+ proc_bus_pci_dir = proc_mkdir_mode("bus/pci", S_IRUSR | S_IXUSR, NULL);
36574+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
36575+ proc_bus_pci_dir = proc_mkdir_mode("bus/pci", S_IRUSR | S_IXUSR | S_IRGRP | S_IXGRP, NULL);
36576+#endif
36577+#else
36578 proc_bus_pci_dir = proc_mkdir("bus/pci", NULL);
36579+#endif
36580 proc_create("devices", 0, proc_bus_pci_dir,
36581 &proc_bus_pci_dev_operations);
36582 proc_initialized = 1;
36583diff --git a/drivers/platform/x86/thinkpad_acpi.c b/drivers/platform/x86/thinkpad_acpi.c
36584index 52daaa8..d6b81eb 100644
36585--- a/drivers/platform/x86/thinkpad_acpi.c
36586+++ b/drivers/platform/x86/thinkpad_acpi.c
36587@@ -2097,7 +2097,7 @@ static int hotkey_mask_get(void)
36588 return 0;
36589 }
36590
36591-void static hotkey_mask_warn_incomplete_mask(void)
36592+static void hotkey_mask_warn_incomplete_mask(void)
36593 {
36594 /* log only what the user can fix... */
36595 const u32 wantedmask = hotkey_driver_mask &
36596@@ -2328,11 +2328,6 @@ static void hotkey_read_nvram(struct tp_nvram_state *n, const u32 m)
36597 }
36598 }
36599
36600-static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
36601- struct tp_nvram_state *newn,
36602- const u32 event_mask)
36603-{
36604-
36605 #define TPACPI_COMPARE_KEY(__scancode, __member) \
36606 do { \
36607 if ((event_mask & (1 << __scancode)) && \
36608@@ -2346,36 +2341,42 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
36609 tpacpi_hotkey_send_key(__scancode); \
36610 } while (0)
36611
36612- void issue_volchange(const unsigned int oldvol,
36613- const unsigned int newvol)
36614- {
36615- unsigned int i = oldvol;
36616+static void issue_volchange(const unsigned int oldvol,
36617+ const unsigned int newvol,
36618+ const u32 event_mask)
36619+{
36620+ unsigned int i = oldvol;
36621
36622- while (i > newvol) {
36623- TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEDOWN);
36624- i--;
36625- }
36626- while (i < newvol) {
36627- TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEUP);
36628- i++;
36629- }
36630+ while (i > newvol) {
36631+ TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEDOWN);
36632+ i--;
36633 }
36634+ while (i < newvol) {
36635+ TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEUP);
36636+ i++;
36637+ }
36638+}
36639
36640- void issue_brightnesschange(const unsigned int oldbrt,
36641- const unsigned int newbrt)
36642- {
36643- unsigned int i = oldbrt;
36644+static void issue_brightnesschange(const unsigned int oldbrt,
36645+ const unsigned int newbrt,
36646+ const u32 event_mask)
36647+{
36648+ unsigned int i = oldbrt;
36649
36650- while (i > newbrt) {
36651- TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNEND);
36652- i--;
36653- }
36654- while (i < newbrt) {
36655- TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNHOME);
36656- i++;
36657- }
36658+ while (i > newbrt) {
36659+ TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNEND);
36660+ i--;
36661+ }
36662+ while (i < newbrt) {
36663+ TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNHOME);
36664+ i++;
36665 }
36666+}
36667
36668+static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
36669+ struct tp_nvram_state *newn,
36670+ const u32 event_mask)
36671+{
36672 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_THINKPAD, thinkpad_toggle);
36673 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_FNSPACE, zoom_toggle);
36674 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_FNF7, display_toggle);
36675@@ -2409,7 +2410,7 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
36676 oldn->volume_level != newn->volume_level) {
36677 /* recently muted, or repeated mute keypress, or
36678 * multiple presses ending in mute */
36679- issue_volchange(oldn->volume_level, newn->volume_level);
36680+ issue_volchange(oldn->volume_level, newn->volume_level, event_mask);
36681 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_MUTE);
36682 }
36683 } else {
36684@@ -2419,7 +2420,7 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
36685 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEUP);
36686 }
36687 if (oldn->volume_level != newn->volume_level) {
36688- issue_volchange(oldn->volume_level, newn->volume_level);
36689+ issue_volchange(oldn->volume_level, newn->volume_level, event_mask);
36690 } else if (oldn->volume_toggle != newn->volume_toggle) {
36691 /* repeated vol up/down keypress at end of scale ? */
36692 if (newn->volume_level == 0)
36693@@ -2432,7 +2433,8 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
36694 /* handle brightness */
36695 if (oldn->brightness_level != newn->brightness_level) {
36696 issue_brightnesschange(oldn->brightness_level,
36697- newn->brightness_level);
36698+ newn->brightness_level,
36699+ event_mask);
36700 } else if (oldn->brightness_toggle != newn->brightness_toggle) {
36701 /* repeated key presses that didn't change state */
36702 if (newn->brightness_level == 0)
36703@@ -2441,10 +2443,10 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
36704 && !tp_features.bright_unkfw)
36705 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNHOME);
36706 }
36707+}
36708
36709 #undef TPACPI_COMPARE_KEY
36710 #undef TPACPI_MAY_SEND_KEY
36711-}
36712
36713 /*
36714 * Polling driver
36715diff --git a/drivers/pnp/pnpbios/bioscalls.c b/drivers/pnp/pnpbios/bioscalls.c
36716index 769d265..a3a05ca 100644
36717--- a/drivers/pnp/pnpbios/bioscalls.c
36718+++ b/drivers/pnp/pnpbios/bioscalls.c
36719@@ -58,7 +58,7 @@ do { \
36720 set_desc_limit(&gdt[(selname) >> 3], (size) - 1); \
36721 } while(0)
36722
36723-static struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4092,
36724+static const struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4093,
36725 (unsigned long)__va(0x400UL), PAGE_SIZE - 0x400 - 1);
36726
36727 /*
36728@@ -95,7 +95,10 @@ static inline u16 call_pnp_bios(u16 func, u16 arg1, u16 arg2, u16 arg3,
36729
36730 cpu = get_cpu();
36731 save_desc_40 = get_cpu_gdt_table(cpu)[0x40 / 8];
36732+
36733+ pax_open_kernel();
36734 get_cpu_gdt_table(cpu)[0x40 / 8] = bad_bios_desc;
36735+ pax_close_kernel();
36736
36737 /* On some boxes IRQ's during PnP BIOS calls are deadly. */
36738 spin_lock_irqsave(&pnp_bios_lock, flags);
36739@@ -133,7 +136,10 @@ static inline u16 call_pnp_bios(u16 func, u16 arg1, u16 arg2, u16 arg3,
36740 :"memory");
36741 spin_unlock_irqrestore(&pnp_bios_lock, flags);
36742
36743+ pax_open_kernel();
36744 get_cpu_gdt_table(cpu)[0x40 / 8] = save_desc_40;
36745+ pax_close_kernel();
36746+
36747 put_cpu();
36748
36749 /* If we get here and this is set then the PnP BIOS faulted on us. */
36750@@ -467,7 +473,7 @@ int pnp_bios_read_escd(char *data, u32 nvram_base)
36751 return status;
36752 }
36753
36754-void pnpbios_calls_init(union pnp_bios_install_struct *header)
36755+void __init pnpbios_calls_init(union pnp_bios_install_struct *header)
36756 {
36757 int i;
36758
36759@@ -475,6 +481,8 @@ void pnpbios_calls_init(union pnp_bios_install_struct *header)
36760 pnp_bios_callpoint.offset = header->fields.pm16offset;
36761 pnp_bios_callpoint.segment = PNP_CS16;
36762
36763+ pax_open_kernel();
36764+
36765 for_each_possible_cpu(i) {
36766 struct desc_struct *gdt = get_cpu_gdt_table(i);
36767 if (!gdt)
36768@@ -486,4 +494,6 @@ void pnpbios_calls_init(union pnp_bios_install_struct *header)
36769 set_desc_base(&gdt[GDT_ENTRY_PNPBIOS_DS],
36770 (unsigned long)__va(header->fields.pm16dseg));
36771 }
36772+
36773+ pax_close_kernel();
36774 }
36775diff --git a/drivers/pnp/resource.c b/drivers/pnp/resource.c
36776index b0ecacb..7c9da2e 100644
36777--- a/drivers/pnp/resource.c
36778+++ b/drivers/pnp/resource.c
36779@@ -360,7 +360,7 @@ int pnp_check_irq(struct pnp_dev *dev, struct resource *res)
36780 return 1;
36781
36782 /* check if the resource is valid */
36783- if (*irq < 0 || *irq > 15)
36784+ if (*irq > 15)
36785 return 0;
36786
36787 /* check if the resource is reserved */
36788@@ -424,7 +424,7 @@ int pnp_check_dma(struct pnp_dev *dev, struct resource *res)
36789 return 1;
36790
36791 /* check if the resource is valid */
36792- if (*dma < 0 || *dma == 4 || *dma > 7)
36793+ if (*dma == 4 || *dma > 7)
36794 return 0;
36795
36796 /* check if the resource is reserved */
36797diff --git a/drivers/power/bq27x00_battery.c b/drivers/power/bq27x00_battery.c
36798index 181ddec..774b6da 100644
36799--- a/drivers/power/bq27x00_battery.c
36800+++ b/drivers/power/bq27x00_battery.c
36801@@ -80,7 +80,7 @@
36802 struct bq27x00_device_info;
36803 struct bq27x00_access_methods {
36804 int (*read)(struct bq27x00_device_info *di, u8 reg, bool single);
36805-};
36806+} __no_const;
36807
36808 enum bq27x00_chip { BQ27000, BQ27500, BQ27425};
36809
36810diff --git a/drivers/regulator/max8660.c b/drivers/regulator/max8660.c
36811index 8d53174..04c65de 100644
36812--- a/drivers/regulator/max8660.c
36813+++ b/drivers/regulator/max8660.c
36814@@ -333,8 +333,10 @@ static int __devinit max8660_probe(struct i2c_client *client,
36815 max8660->shadow_regs[MAX8660_OVER1] = 5;
36816 } else {
36817 /* Otherwise devices can be toggled via software */
36818- max8660_dcdc_ops.enable = max8660_dcdc_enable;
36819- max8660_dcdc_ops.disable = max8660_dcdc_disable;
36820+ pax_open_kernel();
36821+ *(void **)&max8660_dcdc_ops.enable = max8660_dcdc_enable;
36822+ *(void **)&max8660_dcdc_ops.disable = max8660_dcdc_disable;
36823+ pax_close_kernel();
36824 }
36825
36826 /*
36827diff --git a/drivers/regulator/mc13892-regulator.c b/drivers/regulator/mc13892-regulator.c
36828index b388b74..ed82573 100644
36829--- a/drivers/regulator/mc13892-regulator.c
36830+++ b/drivers/regulator/mc13892-regulator.c
36831@@ -565,10 +565,12 @@ static int __devinit mc13892_regulator_probe(struct platform_device *pdev)
36832 }
36833 mc13xxx_unlock(mc13892);
36834
36835- mc13892_regulators[MC13892_VCAM].desc.ops->set_mode
36836+ pax_open_kernel();
36837+ *(void **)&mc13892_regulators[MC13892_VCAM].desc.ops->set_mode
36838 = mc13892_vcam_set_mode;
36839- mc13892_regulators[MC13892_VCAM].desc.ops->get_mode
36840+ *(void **)&mc13892_regulators[MC13892_VCAM].desc.ops->get_mode
36841 = mc13892_vcam_get_mode;
36842+ pax_close_kernel();
36843
36844 mc13xxx_data = mc13xxx_parse_regulators_dt(pdev, mc13892_regulators,
36845 ARRAY_SIZE(mc13892_regulators));
36846diff --git a/drivers/rtc/rtc-dev.c b/drivers/rtc/rtc-dev.c
36847index cace6d3..f623fda 100644
36848--- a/drivers/rtc/rtc-dev.c
36849+++ b/drivers/rtc/rtc-dev.c
36850@@ -14,6 +14,7 @@
36851 #include <linux/module.h>
36852 #include <linux/rtc.h>
36853 #include <linux/sched.h>
36854+#include <linux/grsecurity.h>
36855 #include "rtc-core.h"
36856
36857 static dev_t rtc_devt;
36858@@ -345,6 +346,8 @@ static long rtc_dev_ioctl(struct file *file,
36859 if (copy_from_user(&tm, uarg, sizeof(tm)))
36860 return -EFAULT;
36861
36862+ gr_log_timechange();
36863+
36864 return rtc_set_time(rtc, &tm);
36865
36866 case RTC_PIE_ON:
36867diff --git a/drivers/scsi/aacraid/aacraid.h b/drivers/scsi/aacraid/aacraid.h
36868index 9e933a8..4f969f7 100644
36869--- a/drivers/scsi/aacraid/aacraid.h
36870+++ b/drivers/scsi/aacraid/aacraid.h
36871@@ -503,7 +503,7 @@ struct adapter_ops
36872 int (*adapter_scsi)(struct fib * fib, struct scsi_cmnd * cmd);
36873 /* Administrative operations */
36874 int (*adapter_comm)(struct aac_dev * dev, int comm);
36875-};
36876+} __no_const;
36877
36878 /*
36879 * Define which interrupt handler needs to be installed
36880diff --git a/drivers/scsi/aacraid/linit.c b/drivers/scsi/aacraid/linit.c
36881index 7199534..cb7f158 100644
36882--- a/drivers/scsi/aacraid/linit.c
36883+++ b/drivers/scsi/aacraid/linit.c
36884@@ -93,7 +93,7 @@ static DECLARE_PCI_DEVICE_TABLE(aac_pci_tbl) = {
36885 #elif defined(__devinitconst)
36886 static const struct pci_device_id aac_pci_tbl[] __devinitconst = {
36887 #else
36888-static const struct pci_device_id aac_pci_tbl[] __devinitdata = {
36889+static const struct pci_device_id aac_pci_tbl[] __devinitconst = {
36890 #endif
36891 { 0x1028, 0x0001, 0x1028, 0x0001, 0, 0, 0 }, /* PERC 2/Si (Iguana/PERC2Si) */
36892 { 0x1028, 0x0002, 0x1028, 0x0002, 0, 0, 1 }, /* PERC 3/Di (Opal/PERC3Di) */
36893diff --git a/drivers/scsi/aic94xx/aic94xx_init.c b/drivers/scsi/aic94xx/aic94xx_init.c
36894index ff80552..1c4120c 100644
36895--- a/drivers/scsi/aic94xx/aic94xx_init.c
36896+++ b/drivers/scsi/aic94xx/aic94xx_init.c
36897@@ -1012,7 +1012,7 @@ static struct sas_domain_function_template aic94xx_transport_functions = {
36898 .lldd_ata_set_dmamode = asd_set_dmamode,
36899 };
36900
36901-static const struct pci_device_id aic94xx_pci_table[] __devinitdata = {
36902+static const struct pci_device_id aic94xx_pci_table[] __devinitconst = {
36903 {PCI_DEVICE(PCI_VENDOR_ID_ADAPTEC2, 0x410),0, 0, 1},
36904 {PCI_DEVICE(PCI_VENDOR_ID_ADAPTEC2, 0x412),0, 0, 1},
36905 {PCI_DEVICE(PCI_VENDOR_ID_ADAPTEC2, 0x416),0, 0, 1},
36906diff --git a/drivers/scsi/bfa/bfa.h b/drivers/scsi/bfa/bfa.h
36907index 4ad7e36..d004679 100644
36908--- a/drivers/scsi/bfa/bfa.h
36909+++ b/drivers/scsi/bfa/bfa.h
36910@@ -196,7 +196,7 @@ struct bfa_hwif_s {
36911 u32 *end);
36912 int cpe_vec_q0;
36913 int rme_vec_q0;
36914-};
36915+} __no_const;
36916 typedef void (*bfa_cb_iocfc_t) (void *cbarg, enum bfa_status status);
36917
36918 struct bfa_faa_cbfn_s {
36919diff --git a/drivers/scsi/bfa/bfa_fcpim.c b/drivers/scsi/bfa/bfa_fcpim.c
36920index f0f80e2..8ec946b 100644
36921--- a/drivers/scsi/bfa/bfa_fcpim.c
36922+++ b/drivers/scsi/bfa/bfa_fcpim.c
36923@@ -3715,7 +3715,7 @@ bfa_fcp_attach(struct bfa_s *bfa, void *bfad, struct bfa_iocfc_cfg_s *cfg,
36924
36925 bfa_iotag_attach(fcp);
36926
36927- fcp->itn_arr = (struct bfa_itn_s *) bfa_mem_kva_curp(fcp);
36928+ fcp->itn_arr = (bfa_itn_s_no_const *) bfa_mem_kva_curp(fcp);
36929 bfa_mem_kva_curp(fcp) = (u8 *)fcp->itn_arr +
36930 (fcp->num_itns * sizeof(struct bfa_itn_s));
36931 memset(fcp->itn_arr, 0,
36932@@ -3773,7 +3773,7 @@ bfa_itn_create(struct bfa_s *bfa, struct bfa_rport_s *rport,
36933 void (*isr)(struct bfa_s *bfa, struct bfi_msg_s *m))
36934 {
36935 struct bfa_fcp_mod_s *fcp = BFA_FCP_MOD(bfa);
36936- struct bfa_itn_s *itn;
36937+ bfa_itn_s_no_const *itn;
36938
36939 itn = BFA_ITN_FROM_TAG(fcp, rport->rport_tag);
36940 itn->isr = isr;
36941diff --git a/drivers/scsi/bfa/bfa_fcpim.h b/drivers/scsi/bfa/bfa_fcpim.h
36942index 36f26da..38a34a8 100644
36943--- a/drivers/scsi/bfa/bfa_fcpim.h
36944+++ b/drivers/scsi/bfa/bfa_fcpim.h
36945@@ -37,6 +37,7 @@ struct bfa_iotag_s {
36946 struct bfa_itn_s {
36947 bfa_isr_func_t isr;
36948 };
36949+typedef struct bfa_itn_s __no_const bfa_itn_s_no_const;
36950
36951 void bfa_itn_create(struct bfa_s *bfa, struct bfa_rport_s *rport,
36952 void (*isr)(struct bfa_s *bfa, struct bfi_msg_s *m));
36953@@ -147,7 +148,7 @@ struct bfa_fcp_mod_s {
36954 struct list_head iotag_tio_free_q; /* free IO resources */
36955 struct list_head iotag_unused_q; /* unused IO resources*/
36956 struct bfa_iotag_s *iotag_arr;
36957- struct bfa_itn_s *itn_arr;
36958+ bfa_itn_s_no_const *itn_arr;
36959 int num_ioim_reqs;
36960 int num_fwtio_reqs;
36961 int num_itns;
36962diff --git a/drivers/scsi/bfa/bfa_ioc.h b/drivers/scsi/bfa/bfa_ioc.h
36963index 1a99d4b..e85d64b 100644
36964--- a/drivers/scsi/bfa/bfa_ioc.h
36965+++ b/drivers/scsi/bfa/bfa_ioc.h
36966@@ -258,7 +258,7 @@ struct bfa_ioc_cbfn_s {
36967 bfa_ioc_disable_cbfn_t disable_cbfn;
36968 bfa_ioc_hbfail_cbfn_t hbfail_cbfn;
36969 bfa_ioc_reset_cbfn_t reset_cbfn;
36970-};
36971+} __no_const;
36972
36973 /*
36974 * IOC event notification mechanism.
36975@@ -346,7 +346,7 @@ struct bfa_ioc_hwif_s {
36976 void (*ioc_sync_ack) (struct bfa_ioc_s *ioc);
36977 bfa_boolean_t (*ioc_sync_complete) (struct bfa_ioc_s *ioc);
36978 bfa_boolean_t (*ioc_lpu_read_stat) (struct bfa_ioc_s *ioc);
36979-};
36980+} __no_const;
36981
36982 /*
36983 * Queue element to wait for room in request queue. FIFO order is
36984diff --git a/drivers/scsi/hosts.c b/drivers/scsi/hosts.c
36985index 593085a..47aa999 100644
36986--- a/drivers/scsi/hosts.c
36987+++ b/drivers/scsi/hosts.c
36988@@ -42,7 +42,7 @@
36989 #include "scsi_logging.h"
36990
36991
36992-static atomic_t scsi_host_next_hn = ATOMIC_INIT(0); /* host_no for next new host */
36993+static atomic_unchecked_t scsi_host_next_hn = ATOMIC_INIT(0); /* host_no for next new host */
36994
36995
36996 static void scsi_host_cls_release(struct device *dev)
36997@@ -361,7 +361,7 @@ struct Scsi_Host *scsi_host_alloc(struct scsi_host_template *sht, int privsize)
36998 * subtract one because we increment first then return, but we need to
36999 * know what the next host number was before increment
37000 */
37001- shost->host_no = atomic_inc_return(&scsi_host_next_hn) - 1;
37002+ shost->host_no = atomic_inc_return_unchecked(&scsi_host_next_hn) - 1;
37003 shost->dma_channel = 0xff;
37004
37005 /* These three are default values which can be overridden */
37006diff --git a/drivers/scsi/hpsa.c b/drivers/scsi/hpsa.c
37007index f9823f2..7bc3e81 100644
37008--- a/drivers/scsi/hpsa.c
37009+++ b/drivers/scsi/hpsa.c
37010@@ -536,7 +536,7 @@ static inline u32 next_command(struct ctlr_info *h, u8 q)
37011 unsigned long flags;
37012
37013 if (unlikely(!(h->transMethod & CFGTBL_Trans_Performant)))
37014- return h->access.command_completed(h, q);
37015+ return h->access->command_completed(h, q);
37016
37017 if ((rq->head[rq->current_entry] & 1) == rq->wraparound) {
37018 a = rq->head[rq->current_entry];
37019@@ -3355,7 +3355,7 @@ static void start_io(struct ctlr_info *h)
37020 while (!list_empty(&h->reqQ)) {
37021 c = list_entry(h->reqQ.next, struct CommandList, list);
37022 /* can't do anything if fifo is full */
37023- if ((h->access.fifo_full(h))) {
37024+ if ((h->access->fifo_full(h))) {
37025 dev_warn(&h->pdev->dev, "fifo full\n");
37026 break;
37027 }
37028@@ -3377,7 +3377,7 @@ static void start_io(struct ctlr_info *h)
37029
37030 /* Tell the controller execute command */
37031 spin_unlock_irqrestore(&h->lock, flags);
37032- h->access.submit_command(h, c);
37033+ h->access->submit_command(h, c);
37034 spin_lock_irqsave(&h->lock, flags);
37035 }
37036 spin_unlock_irqrestore(&h->lock, flags);
37037@@ -3385,17 +3385,17 @@ static void start_io(struct ctlr_info *h)
37038
37039 static inline unsigned long get_next_completion(struct ctlr_info *h, u8 q)
37040 {
37041- return h->access.command_completed(h, q);
37042+ return h->access->command_completed(h, q);
37043 }
37044
37045 static inline bool interrupt_pending(struct ctlr_info *h)
37046 {
37047- return h->access.intr_pending(h);
37048+ return h->access->intr_pending(h);
37049 }
37050
37051 static inline long interrupt_not_for_us(struct ctlr_info *h)
37052 {
37053- return (h->access.intr_pending(h) == 0) ||
37054+ return (h->access->intr_pending(h) == 0) ||
37055 (h->interrupts_enabled == 0);
37056 }
37057
37058@@ -4299,7 +4299,7 @@ static int __devinit hpsa_pci_init(struct ctlr_info *h)
37059 if (prod_index < 0)
37060 return -ENODEV;
37061 h->product_name = products[prod_index].product_name;
37062- h->access = *(products[prod_index].access);
37063+ h->access = products[prod_index].access;
37064
37065 pci_disable_link_state(h->pdev, PCIE_LINK_STATE_L0S |
37066 PCIE_LINK_STATE_L1 | PCIE_LINK_STATE_CLKPM);
37067@@ -4581,7 +4581,7 @@ static void controller_lockup_detected(struct ctlr_info *h)
37068
37069 assert_spin_locked(&lockup_detector_lock);
37070 remove_ctlr_from_lockup_detector_list(h);
37071- h->access.set_intr_mask(h, HPSA_INTR_OFF);
37072+ h->access->set_intr_mask(h, HPSA_INTR_OFF);
37073 spin_lock_irqsave(&h->lock, flags);
37074 h->lockup_detected = readl(h->vaddr + SA5_SCRATCHPAD_OFFSET);
37075 spin_unlock_irqrestore(&h->lock, flags);
37076@@ -4759,7 +4759,7 @@ reinit_after_soft_reset:
37077 }
37078
37079 /* make sure the board interrupts are off */
37080- h->access.set_intr_mask(h, HPSA_INTR_OFF);
37081+ h->access->set_intr_mask(h, HPSA_INTR_OFF);
37082
37083 if (hpsa_request_irq(h, do_hpsa_intr_msi, do_hpsa_intr_intx))
37084 goto clean2;
37085@@ -4793,7 +4793,7 @@ reinit_after_soft_reset:
37086 * fake ones to scoop up any residual completions.
37087 */
37088 spin_lock_irqsave(&h->lock, flags);
37089- h->access.set_intr_mask(h, HPSA_INTR_OFF);
37090+ h->access->set_intr_mask(h, HPSA_INTR_OFF);
37091 spin_unlock_irqrestore(&h->lock, flags);
37092 free_irqs(h);
37093 rc = hpsa_request_irq(h, hpsa_msix_discard_completions,
37094@@ -4812,9 +4812,9 @@ reinit_after_soft_reset:
37095 dev_info(&h->pdev->dev, "Board READY.\n");
37096 dev_info(&h->pdev->dev,
37097 "Waiting for stale completions to drain.\n");
37098- h->access.set_intr_mask(h, HPSA_INTR_ON);
37099+ h->access->set_intr_mask(h, HPSA_INTR_ON);
37100 msleep(10000);
37101- h->access.set_intr_mask(h, HPSA_INTR_OFF);
37102+ h->access->set_intr_mask(h, HPSA_INTR_OFF);
37103
37104 rc = controller_reset_failed(h->cfgtable);
37105 if (rc)
37106@@ -4835,7 +4835,7 @@ reinit_after_soft_reset:
37107 }
37108
37109 /* Turn the interrupts on so we can service requests */
37110- h->access.set_intr_mask(h, HPSA_INTR_ON);
37111+ h->access->set_intr_mask(h, HPSA_INTR_ON);
37112
37113 hpsa_hba_inquiry(h);
37114 hpsa_register_scsi(h); /* hook ourselves into SCSI subsystem */
37115@@ -4887,7 +4887,7 @@ static void hpsa_shutdown(struct pci_dev *pdev)
37116 * To write all data in the battery backed cache to disks
37117 */
37118 hpsa_flush_cache(h);
37119- h->access.set_intr_mask(h, HPSA_INTR_OFF);
37120+ h->access->set_intr_mask(h, HPSA_INTR_OFF);
37121 hpsa_free_irqs_and_disable_msix(h);
37122 }
37123
37124@@ -5056,7 +5056,7 @@ static __devinit void hpsa_enter_performant_mode(struct ctlr_info *h,
37125 return;
37126 }
37127 /* Change the access methods to the performant access methods */
37128- h->access = SA5_performant_access;
37129+ h->access = &SA5_performant_access;
37130 h->transMethod = CFGTBL_Trans_Performant;
37131 }
37132
37133diff --git a/drivers/scsi/hpsa.h b/drivers/scsi/hpsa.h
37134index 9816479..c5d4e97 100644
37135--- a/drivers/scsi/hpsa.h
37136+++ b/drivers/scsi/hpsa.h
37137@@ -79,7 +79,7 @@ struct ctlr_info {
37138 unsigned int msix_vector;
37139 unsigned int msi_vector;
37140 int intr_mode; /* either PERF_MODE_INT or SIMPLE_MODE_INT */
37141- struct access_method access;
37142+ struct access_method *access;
37143
37144 /* queue and queue Info */
37145 struct list_head reqQ;
37146diff --git a/drivers/scsi/ips.h b/drivers/scsi/ips.h
37147index f2df059..a3a9930 100644
37148--- a/drivers/scsi/ips.h
37149+++ b/drivers/scsi/ips.h
37150@@ -1027,7 +1027,7 @@ typedef struct {
37151 int (*intr)(struct ips_ha *);
37152 void (*enableint)(struct ips_ha *);
37153 uint32_t (*statupd)(struct ips_ha *);
37154-} ips_hw_func_t;
37155+} __no_const ips_hw_func_t;
37156
37157 typedef struct ips_ha {
37158 uint8_t ha_id[IPS_MAX_CHANNELS+1];
37159diff --git a/drivers/scsi/libfc/fc_exch.c b/drivers/scsi/libfc/fc_exch.c
37160index c772d8d..35c362c 100644
37161--- a/drivers/scsi/libfc/fc_exch.c
37162+++ b/drivers/scsi/libfc/fc_exch.c
37163@@ -100,12 +100,12 @@ struct fc_exch_mgr {
37164 u16 pool_max_index;
37165
37166 struct {
37167- atomic_t no_free_exch;
37168- atomic_t no_free_exch_xid;
37169- atomic_t xid_not_found;
37170- atomic_t xid_busy;
37171- atomic_t seq_not_found;
37172- atomic_t non_bls_resp;
37173+ atomic_unchecked_t no_free_exch;
37174+ atomic_unchecked_t no_free_exch_xid;
37175+ atomic_unchecked_t xid_not_found;
37176+ atomic_unchecked_t xid_busy;
37177+ atomic_unchecked_t seq_not_found;
37178+ atomic_unchecked_t non_bls_resp;
37179 } stats;
37180 };
37181
37182@@ -725,7 +725,7 @@ static struct fc_exch *fc_exch_em_alloc(struct fc_lport *lport,
37183 /* allocate memory for exchange */
37184 ep = mempool_alloc(mp->ep_pool, GFP_ATOMIC);
37185 if (!ep) {
37186- atomic_inc(&mp->stats.no_free_exch);
37187+ atomic_inc_unchecked(&mp->stats.no_free_exch);
37188 goto out;
37189 }
37190 memset(ep, 0, sizeof(*ep));
37191@@ -786,7 +786,7 @@ out:
37192 return ep;
37193 err:
37194 spin_unlock_bh(&pool->lock);
37195- atomic_inc(&mp->stats.no_free_exch_xid);
37196+ atomic_inc_unchecked(&mp->stats.no_free_exch_xid);
37197 mempool_free(ep, mp->ep_pool);
37198 return NULL;
37199 }
37200@@ -929,7 +929,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
37201 xid = ntohs(fh->fh_ox_id); /* we originated exch */
37202 ep = fc_exch_find(mp, xid);
37203 if (!ep) {
37204- atomic_inc(&mp->stats.xid_not_found);
37205+ atomic_inc_unchecked(&mp->stats.xid_not_found);
37206 reject = FC_RJT_OX_ID;
37207 goto out;
37208 }
37209@@ -959,7 +959,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
37210 ep = fc_exch_find(mp, xid);
37211 if ((f_ctl & FC_FC_FIRST_SEQ) && fc_sof_is_init(fr_sof(fp))) {
37212 if (ep) {
37213- atomic_inc(&mp->stats.xid_busy);
37214+ atomic_inc_unchecked(&mp->stats.xid_busy);
37215 reject = FC_RJT_RX_ID;
37216 goto rel;
37217 }
37218@@ -970,7 +970,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
37219 }
37220 xid = ep->xid; /* get our XID */
37221 } else if (!ep) {
37222- atomic_inc(&mp->stats.xid_not_found);
37223+ atomic_inc_unchecked(&mp->stats.xid_not_found);
37224 reject = FC_RJT_RX_ID; /* XID not found */
37225 goto out;
37226 }
37227@@ -987,7 +987,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
37228 } else {
37229 sp = &ep->seq;
37230 if (sp->id != fh->fh_seq_id) {
37231- atomic_inc(&mp->stats.seq_not_found);
37232+ atomic_inc_unchecked(&mp->stats.seq_not_found);
37233 if (f_ctl & FC_FC_END_SEQ) {
37234 /*
37235 * Update sequence_id based on incoming last
37236@@ -1437,22 +1437,22 @@ static void fc_exch_recv_seq_resp(struct fc_exch_mgr *mp, struct fc_frame *fp)
37237
37238 ep = fc_exch_find(mp, ntohs(fh->fh_ox_id));
37239 if (!ep) {
37240- atomic_inc(&mp->stats.xid_not_found);
37241+ atomic_inc_unchecked(&mp->stats.xid_not_found);
37242 goto out;
37243 }
37244 if (ep->esb_stat & ESB_ST_COMPLETE) {
37245- atomic_inc(&mp->stats.xid_not_found);
37246+ atomic_inc_unchecked(&mp->stats.xid_not_found);
37247 goto rel;
37248 }
37249 if (ep->rxid == FC_XID_UNKNOWN)
37250 ep->rxid = ntohs(fh->fh_rx_id);
37251 if (ep->sid != 0 && ep->sid != ntoh24(fh->fh_d_id)) {
37252- atomic_inc(&mp->stats.xid_not_found);
37253+ atomic_inc_unchecked(&mp->stats.xid_not_found);
37254 goto rel;
37255 }
37256 if (ep->did != ntoh24(fh->fh_s_id) &&
37257 ep->did != FC_FID_FLOGI) {
37258- atomic_inc(&mp->stats.xid_not_found);
37259+ atomic_inc_unchecked(&mp->stats.xid_not_found);
37260 goto rel;
37261 }
37262 sof = fr_sof(fp);
37263@@ -1461,7 +1461,7 @@ static void fc_exch_recv_seq_resp(struct fc_exch_mgr *mp, struct fc_frame *fp)
37264 sp->ssb_stat |= SSB_ST_RESP;
37265 sp->id = fh->fh_seq_id;
37266 } else if (sp->id != fh->fh_seq_id) {
37267- atomic_inc(&mp->stats.seq_not_found);
37268+ atomic_inc_unchecked(&mp->stats.seq_not_found);
37269 goto rel;
37270 }
37271
37272@@ -1525,9 +1525,9 @@ static void fc_exch_recv_resp(struct fc_exch_mgr *mp, struct fc_frame *fp)
37273 sp = fc_seq_lookup_orig(mp, fp); /* doesn't hold sequence */
37274
37275 if (!sp)
37276- atomic_inc(&mp->stats.xid_not_found);
37277+ atomic_inc_unchecked(&mp->stats.xid_not_found);
37278 else
37279- atomic_inc(&mp->stats.non_bls_resp);
37280+ atomic_inc_unchecked(&mp->stats.non_bls_resp);
37281
37282 fc_frame_free(fp);
37283 }
37284@@ -2174,13 +2174,13 @@ void fc_exch_update_stats(struct fc_lport *lport)
37285
37286 list_for_each_entry(ema, &lport->ema_list, ema_list) {
37287 mp = ema->mp;
37288- st->fc_no_free_exch += atomic_read(&mp->stats.no_free_exch);
37289+ st->fc_no_free_exch += atomic_read_unchecked(&mp->stats.no_free_exch);
37290 st->fc_no_free_exch_xid +=
37291- atomic_read(&mp->stats.no_free_exch_xid);
37292- st->fc_xid_not_found += atomic_read(&mp->stats.xid_not_found);
37293- st->fc_xid_busy += atomic_read(&mp->stats.xid_busy);
37294- st->fc_seq_not_found += atomic_read(&mp->stats.seq_not_found);
37295- st->fc_non_bls_resp += atomic_read(&mp->stats.non_bls_resp);
37296+ atomic_read_unchecked(&mp->stats.no_free_exch_xid);
37297+ st->fc_xid_not_found += atomic_read_unchecked(&mp->stats.xid_not_found);
37298+ st->fc_xid_busy += atomic_read_unchecked(&mp->stats.xid_busy);
37299+ st->fc_seq_not_found += atomic_read_unchecked(&mp->stats.seq_not_found);
37300+ st->fc_non_bls_resp += atomic_read_unchecked(&mp->stats.non_bls_resp);
37301 }
37302 }
37303 EXPORT_SYMBOL(fc_exch_update_stats);
37304diff --git a/drivers/scsi/libsas/sas_ata.c b/drivers/scsi/libsas/sas_ata.c
37305index a59fcdc..abe55f3 100644
37306--- a/drivers/scsi/libsas/sas_ata.c
37307+++ b/drivers/scsi/libsas/sas_ata.c
37308@@ -554,7 +554,7 @@ static struct ata_port_operations sas_sata_ops = {
37309 .postreset = ata_std_postreset,
37310 .error_handler = ata_std_error_handler,
37311 .post_internal_cmd = sas_ata_post_internal,
37312- .qc_defer = ata_std_qc_defer,
37313+ .qc_defer = ata_std_qc_defer,
37314 .qc_prep = ata_noop_qc_prep,
37315 .qc_issue = sas_ata_qc_issue,
37316 .qc_fill_rtf = sas_ata_qc_fill_rtf,
37317diff --git a/drivers/scsi/lpfc/lpfc.h b/drivers/scsi/lpfc/lpfc.h
37318index a65c05a..a39e402 100644
37319--- a/drivers/scsi/lpfc/lpfc.h
37320+++ b/drivers/scsi/lpfc/lpfc.h
37321@@ -420,7 +420,7 @@ struct lpfc_vport {
37322 struct dentry *debug_nodelist;
37323 struct dentry *vport_debugfs_root;
37324 struct lpfc_debugfs_trc *disc_trc;
37325- atomic_t disc_trc_cnt;
37326+ atomic_unchecked_t disc_trc_cnt;
37327 #endif
37328 uint8_t stat_data_enabled;
37329 uint8_t stat_data_blocked;
37330@@ -834,8 +834,8 @@ struct lpfc_hba {
37331 struct timer_list fabric_block_timer;
37332 unsigned long bit_flags;
37333 #define FABRIC_COMANDS_BLOCKED 0
37334- atomic_t num_rsrc_err;
37335- atomic_t num_cmd_success;
37336+ atomic_unchecked_t num_rsrc_err;
37337+ atomic_unchecked_t num_cmd_success;
37338 unsigned long last_rsrc_error_time;
37339 unsigned long last_ramp_down_time;
37340 unsigned long last_ramp_up_time;
37341@@ -871,7 +871,7 @@ struct lpfc_hba {
37342
37343 struct dentry *debug_slow_ring_trc;
37344 struct lpfc_debugfs_trc *slow_ring_trc;
37345- atomic_t slow_ring_trc_cnt;
37346+ atomic_unchecked_t slow_ring_trc_cnt;
37347 /* iDiag debugfs sub-directory */
37348 struct dentry *idiag_root;
37349 struct dentry *idiag_pci_cfg;
37350diff --git a/drivers/scsi/lpfc/lpfc_debugfs.c b/drivers/scsi/lpfc/lpfc_debugfs.c
37351index 3217d63..c417981 100644
37352--- a/drivers/scsi/lpfc/lpfc_debugfs.c
37353+++ b/drivers/scsi/lpfc/lpfc_debugfs.c
37354@@ -106,7 +106,7 @@ MODULE_PARM_DESC(lpfc_debugfs_mask_disc_trc,
37355
37356 #include <linux/debugfs.h>
37357
37358-static atomic_t lpfc_debugfs_seq_trc_cnt = ATOMIC_INIT(0);
37359+static atomic_unchecked_t lpfc_debugfs_seq_trc_cnt = ATOMIC_INIT(0);
37360 static unsigned long lpfc_debugfs_start_time = 0L;
37361
37362 /* iDiag */
37363@@ -147,7 +147,7 @@ lpfc_debugfs_disc_trc_data(struct lpfc_vport *vport, char *buf, int size)
37364 lpfc_debugfs_enable = 0;
37365
37366 len = 0;
37367- index = (atomic_read(&vport->disc_trc_cnt) + 1) &
37368+ index = (atomic_read_unchecked(&vport->disc_trc_cnt) + 1) &
37369 (lpfc_debugfs_max_disc_trc - 1);
37370 for (i = index; i < lpfc_debugfs_max_disc_trc; i++) {
37371 dtp = vport->disc_trc + i;
37372@@ -213,7 +213,7 @@ lpfc_debugfs_slow_ring_trc_data(struct lpfc_hba *phba, char *buf, int size)
37373 lpfc_debugfs_enable = 0;
37374
37375 len = 0;
37376- index = (atomic_read(&phba->slow_ring_trc_cnt) + 1) &
37377+ index = (atomic_read_unchecked(&phba->slow_ring_trc_cnt) + 1) &
37378 (lpfc_debugfs_max_slow_ring_trc - 1);
37379 for (i = index; i < lpfc_debugfs_max_slow_ring_trc; i++) {
37380 dtp = phba->slow_ring_trc + i;
37381@@ -636,14 +636,14 @@ lpfc_debugfs_disc_trc(struct lpfc_vport *vport, int mask, char *fmt,
37382 !vport || !vport->disc_trc)
37383 return;
37384
37385- index = atomic_inc_return(&vport->disc_trc_cnt) &
37386+ index = atomic_inc_return_unchecked(&vport->disc_trc_cnt) &
37387 (lpfc_debugfs_max_disc_trc - 1);
37388 dtp = vport->disc_trc + index;
37389 dtp->fmt = fmt;
37390 dtp->data1 = data1;
37391 dtp->data2 = data2;
37392 dtp->data3 = data3;
37393- dtp->seq_cnt = atomic_inc_return(&lpfc_debugfs_seq_trc_cnt);
37394+ dtp->seq_cnt = atomic_inc_return_unchecked(&lpfc_debugfs_seq_trc_cnt);
37395 dtp->jif = jiffies;
37396 #endif
37397 return;
37398@@ -674,14 +674,14 @@ lpfc_debugfs_slow_ring_trc(struct lpfc_hba *phba, char *fmt,
37399 !phba || !phba->slow_ring_trc)
37400 return;
37401
37402- index = atomic_inc_return(&phba->slow_ring_trc_cnt) &
37403+ index = atomic_inc_return_unchecked(&phba->slow_ring_trc_cnt) &
37404 (lpfc_debugfs_max_slow_ring_trc - 1);
37405 dtp = phba->slow_ring_trc + index;
37406 dtp->fmt = fmt;
37407 dtp->data1 = data1;
37408 dtp->data2 = data2;
37409 dtp->data3 = data3;
37410- dtp->seq_cnt = atomic_inc_return(&lpfc_debugfs_seq_trc_cnt);
37411+ dtp->seq_cnt = atomic_inc_return_unchecked(&lpfc_debugfs_seq_trc_cnt);
37412 dtp->jif = jiffies;
37413 #endif
37414 return;
37415@@ -4090,7 +4090,7 @@ lpfc_debugfs_initialize(struct lpfc_vport *vport)
37416 "slow_ring buffer\n");
37417 goto debug_failed;
37418 }
37419- atomic_set(&phba->slow_ring_trc_cnt, 0);
37420+ atomic_set_unchecked(&phba->slow_ring_trc_cnt, 0);
37421 memset(phba->slow_ring_trc, 0,
37422 (sizeof(struct lpfc_debugfs_trc) *
37423 lpfc_debugfs_max_slow_ring_trc));
37424@@ -4136,7 +4136,7 @@ lpfc_debugfs_initialize(struct lpfc_vport *vport)
37425 "buffer\n");
37426 goto debug_failed;
37427 }
37428- atomic_set(&vport->disc_trc_cnt, 0);
37429+ atomic_set_unchecked(&vport->disc_trc_cnt, 0);
37430
37431 snprintf(name, sizeof(name), "discovery_trace");
37432 vport->debug_disc_trc =
37433diff --git a/drivers/scsi/lpfc/lpfc_init.c b/drivers/scsi/lpfc/lpfc_init.c
37434index 45c1520..35ba744 100644
37435--- a/drivers/scsi/lpfc/lpfc_init.c
37436+++ b/drivers/scsi/lpfc/lpfc_init.c
37437@@ -10478,8 +10478,10 @@ lpfc_init(void)
37438 "misc_register returned with status %d", error);
37439
37440 if (lpfc_enable_npiv) {
37441- lpfc_transport_functions.vport_create = lpfc_vport_create;
37442- lpfc_transport_functions.vport_delete = lpfc_vport_delete;
37443+ pax_open_kernel();
37444+ *(void **)&lpfc_transport_functions.vport_create = lpfc_vport_create;
37445+ *(void **)&lpfc_transport_functions.vport_delete = lpfc_vport_delete;
37446+ pax_close_kernel();
37447 }
37448 lpfc_transport_template =
37449 fc_attach_transport(&lpfc_transport_functions);
37450diff --git a/drivers/scsi/lpfc/lpfc_scsi.c b/drivers/scsi/lpfc/lpfc_scsi.c
37451index 925975d..0f1fc07 100644
37452--- a/drivers/scsi/lpfc/lpfc_scsi.c
37453+++ b/drivers/scsi/lpfc/lpfc_scsi.c
37454@@ -311,7 +311,7 @@ lpfc_rampdown_queue_depth(struct lpfc_hba *phba)
37455 uint32_t evt_posted;
37456
37457 spin_lock_irqsave(&phba->hbalock, flags);
37458- atomic_inc(&phba->num_rsrc_err);
37459+ atomic_inc_unchecked(&phba->num_rsrc_err);
37460 phba->last_rsrc_error_time = jiffies;
37461
37462 if ((phba->last_ramp_down_time + QUEUE_RAMP_DOWN_INTERVAL) > jiffies) {
37463@@ -352,7 +352,7 @@ lpfc_rampup_queue_depth(struct lpfc_vport *vport,
37464 unsigned long flags;
37465 struct lpfc_hba *phba = vport->phba;
37466 uint32_t evt_posted;
37467- atomic_inc(&phba->num_cmd_success);
37468+ atomic_inc_unchecked(&phba->num_cmd_success);
37469
37470 if (vport->cfg_lun_queue_depth <= queue_depth)
37471 return;
37472@@ -396,8 +396,8 @@ lpfc_ramp_down_queue_handler(struct lpfc_hba *phba)
37473 unsigned long num_rsrc_err, num_cmd_success;
37474 int i;
37475
37476- num_rsrc_err = atomic_read(&phba->num_rsrc_err);
37477- num_cmd_success = atomic_read(&phba->num_cmd_success);
37478+ num_rsrc_err = atomic_read_unchecked(&phba->num_rsrc_err);
37479+ num_cmd_success = atomic_read_unchecked(&phba->num_cmd_success);
37480
37481 /*
37482 * The error and success command counters are global per
37483@@ -425,8 +425,8 @@ lpfc_ramp_down_queue_handler(struct lpfc_hba *phba)
37484 }
37485 }
37486 lpfc_destroy_vport_work_array(phba, vports);
37487- atomic_set(&phba->num_rsrc_err, 0);
37488- atomic_set(&phba->num_cmd_success, 0);
37489+ atomic_set_unchecked(&phba->num_rsrc_err, 0);
37490+ atomic_set_unchecked(&phba->num_cmd_success, 0);
37491 }
37492
37493 /**
37494@@ -460,8 +460,8 @@ lpfc_ramp_up_queue_handler(struct lpfc_hba *phba)
37495 }
37496 }
37497 lpfc_destroy_vport_work_array(phba, vports);
37498- atomic_set(&phba->num_rsrc_err, 0);
37499- atomic_set(&phba->num_cmd_success, 0);
37500+ atomic_set_unchecked(&phba->num_rsrc_err, 0);
37501+ atomic_set_unchecked(&phba->num_cmd_success, 0);
37502 }
37503
37504 /**
37505diff --git a/drivers/scsi/pmcraid.c b/drivers/scsi/pmcraid.c
37506index ea8a0b4..812a124 100644
37507--- a/drivers/scsi/pmcraid.c
37508+++ b/drivers/scsi/pmcraid.c
37509@@ -200,8 +200,8 @@ static int pmcraid_slave_alloc(struct scsi_device *scsi_dev)
37510 res->scsi_dev = scsi_dev;
37511 scsi_dev->hostdata = res;
37512 res->change_detected = 0;
37513- atomic_set(&res->read_failures, 0);
37514- atomic_set(&res->write_failures, 0);
37515+ atomic_set_unchecked(&res->read_failures, 0);
37516+ atomic_set_unchecked(&res->write_failures, 0);
37517 rc = 0;
37518 }
37519 spin_unlock_irqrestore(&pinstance->resource_lock, lock_flags);
37520@@ -2676,9 +2676,9 @@ static int pmcraid_error_handler(struct pmcraid_cmd *cmd)
37521
37522 /* If this was a SCSI read/write command keep count of errors */
37523 if (SCSI_CMD_TYPE(scsi_cmd->cmnd[0]) == SCSI_READ_CMD)
37524- atomic_inc(&res->read_failures);
37525+ atomic_inc_unchecked(&res->read_failures);
37526 else if (SCSI_CMD_TYPE(scsi_cmd->cmnd[0]) == SCSI_WRITE_CMD)
37527- atomic_inc(&res->write_failures);
37528+ atomic_inc_unchecked(&res->write_failures);
37529
37530 if (!RES_IS_GSCSI(res->cfg_entry) &&
37531 masked_ioasc != PMCRAID_IOASC_HW_DEVICE_BUS_STATUS_ERROR) {
37532@@ -3534,7 +3534,7 @@ static int pmcraid_queuecommand_lck(
37533 * block of scsi_cmd which is re-used (e.g. cancel/abort), which uses
37534 * hrrq_id assigned here in queuecommand
37535 */
37536- ioarcb->hrrq_id = atomic_add_return(1, &(pinstance->last_message_id)) %
37537+ ioarcb->hrrq_id = atomic_add_return_unchecked(1, &(pinstance->last_message_id)) %
37538 pinstance->num_hrrq;
37539 cmd->cmd_done = pmcraid_io_done;
37540
37541@@ -3859,7 +3859,7 @@ static long pmcraid_ioctl_passthrough(
37542 * block of scsi_cmd which is re-used (e.g. cancel/abort), which uses
37543 * hrrq_id assigned here in queuecommand
37544 */
37545- ioarcb->hrrq_id = atomic_add_return(1, &(pinstance->last_message_id)) %
37546+ ioarcb->hrrq_id = atomic_add_return_unchecked(1, &(pinstance->last_message_id)) %
37547 pinstance->num_hrrq;
37548
37549 if (request_size) {
37550@@ -4497,7 +4497,7 @@ static void pmcraid_worker_function(struct work_struct *workp)
37551
37552 pinstance = container_of(workp, struct pmcraid_instance, worker_q);
37553 /* add resources only after host is added into system */
37554- if (!atomic_read(&pinstance->expose_resources))
37555+ if (!atomic_read_unchecked(&pinstance->expose_resources))
37556 return;
37557
37558 fw_version = be16_to_cpu(pinstance->inq_data->fw_version);
37559@@ -5331,8 +5331,8 @@ static int __devinit pmcraid_init_instance(
37560 init_waitqueue_head(&pinstance->reset_wait_q);
37561
37562 atomic_set(&pinstance->outstanding_cmds, 0);
37563- atomic_set(&pinstance->last_message_id, 0);
37564- atomic_set(&pinstance->expose_resources, 0);
37565+ atomic_set_unchecked(&pinstance->last_message_id, 0);
37566+ atomic_set_unchecked(&pinstance->expose_resources, 0);
37567
37568 INIT_LIST_HEAD(&pinstance->free_res_q);
37569 INIT_LIST_HEAD(&pinstance->used_res_q);
37570@@ -6047,7 +6047,7 @@ static int __devinit pmcraid_probe(
37571 /* Schedule worker thread to handle CCN and take care of adding and
37572 * removing devices to OS
37573 */
37574- atomic_set(&pinstance->expose_resources, 1);
37575+ atomic_set_unchecked(&pinstance->expose_resources, 1);
37576 schedule_work(&pinstance->worker_q);
37577 return rc;
37578
37579diff --git a/drivers/scsi/pmcraid.h b/drivers/scsi/pmcraid.h
37580index e1d150f..6c6df44 100644
37581--- a/drivers/scsi/pmcraid.h
37582+++ b/drivers/scsi/pmcraid.h
37583@@ -748,7 +748,7 @@ struct pmcraid_instance {
37584 struct pmcraid_isr_param hrrq_vector[PMCRAID_NUM_MSIX_VECTORS];
37585
37586 /* Message id as filled in last fired IOARCB, used to identify HRRQ */
37587- atomic_t last_message_id;
37588+ atomic_unchecked_t last_message_id;
37589
37590 /* configuration table */
37591 struct pmcraid_config_table *cfg_table;
37592@@ -777,7 +777,7 @@ struct pmcraid_instance {
37593 atomic_t outstanding_cmds;
37594
37595 /* should add/delete resources to mid-layer now ?*/
37596- atomic_t expose_resources;
37597+ atomic_unchecked_t expose_resources;
37598
37599
37600
37601@@ -813,8 +813,8 @@ struct pmcraid_resource_entry {
37602 struct pmcraid_config_table_entry_ext cfg_entry_ext;
37603 };
37604 struct scsi_device *scsi_dev; /* Link scsi_device structure */
37605- atomic_t read_failures; /* count of failed READ commands */
37606- atomic_t write_failures; /* count of failed WRITE commands */
37607+ atomic_unchecked_t read_failures; /* count of failed READ commands */
37608+ atomic_unchecked_t write_failures; /* count of failed WRITE commands */
37609
37610 /* To indicate add/delete/modify during CCN */
37611 u8 change_detected;
37612diff --git a/drivers/scsi/qla2xxx/qla_attr.c b/drivers/scsi/qla2xxx/qla_attr.c
37613index 5ab9530..2dd80f7 100644
37614--- a/drivers/scsi/qla2xxx/qla_attr.c
37615+++ b/drivers/scsi/qla2xxx/qla_attr.c
37616@@ -1855,7 +1855,7 @@ qla24xx_vport_disable(struct fc_vport *fc_vport, bool disable)
37617 return 0;
37618 }
37619
37620-struct fc_function_template qla2xxx_transport_functions = {
37621+fc_function_template_no_const qla2xxx_transport_functions = {
37622
37623 .show_host_node_name = 1,
37624 .show_host_port_name = 1,
37625@@ -1902,7 +1902,7 @@ struct fc_function_template qla2xxx_transport_functions = {
37626 .bsg_timeout = qla24xx_bsg_timeout,
37627 };
37628
37629-struct fc_function_template qla2xxx_transport_vport_functions = {
37630+fc_function_template_no_const qla2xxx_transport_vport_functions = {
37631
37632 .show_host_node_name = 1,
37633 .show_host_port_name = 1,
37634diff --git a/drivers/scsi/qla2xxx/qla_def.h b/drivers/scsi/qla2xxx/qla_def.h
37635index 39007f5..7fafc64 100644
37636--- a/drivers/scsi/qla2xxx/qla_def.h
37637+++ b/drivers/scsi/qla2xxx/qla_def.h
37638@@ -2284,7 +2284,7 @@ struct isp_operations {
37639 int (*start_scsi) (srb_t *);
37640 int (*abort_isp) (struct scsi_qla_host *);
37641 int (*iospace_config)(struct qla_hw_data*);
37642-};
37643+} __no_const;
37644
37645 /* MSI-X Support *************************************************************/
37646
37647diff --git a/drivers/scsi/qla2xxx/qla_gbl.h b/drivers/scsi/qla2xxx/qla_gbl.h
37648index 9eacd2d..d79629c 100644
37649--- a/drivers/scsi/qla2xxx/qla_gbl.h
37650+++ b/drivers/scsi/qla2xxx/qla_gbl.h
37651@@ -484,8 +484,8 @@ extern void qla2x00_get_sym_node_name(scsi_qla_host_t *, uint8_t *);
37652 struct device_attribute;
37653 extern struct device_attribute *qla2x00_host_attrs[];
37654 struct fc_function_template;
37655-extern struct fc_function_template qla2xxx_transport_functions;
37656-extern struct fc_function_template qla2xxx_transport_vport_functions;
37657+extern fc_function_template_no_const qla2xxx_transport_functions;
37658+extern fc_function_template_no_const qla2xxx_transport_vport_functions;
37659 extern void qla2x00_alloc_sysfs_attr(scsi_qla_host_t *);
37660 extern void qla2x00_free_sysfs_attr(scsi_qla_host_t *);
37661 extern void qla2x00_init_host_attr(scsi_qla_host_t *);
37662diff --git a/drivers/scsi/qla4xxx/ql4_def.h b/drivers/scsi/qla4xxx/ql4_def.h
37663index 7fdba7f..1b4b2c2 100644
37664--- a/drivers/scsi/qla4xxx/ql4_def.h
37665+++ b/drivers/scsi/qla4xxx/ql4_def.h
37666@@ -268,7 +268,7 @@ struct ddb_entry {
37667 * (4000 only) */
37668 atomic_t relogin_timer; /* Max Time to wait for
37669 * relogin to complete */
37670- atomic_t relogin_retry_count; /* Num of times relogin has been
37671+ atomic_unchecked_t relogin_retry_count; /* Num of times relogin has been
37672 * retried */
37673 uint32_t default_time2wait; /* Default Min time between
37674 * relogins (+aens) */
37675diff --git a/drivers/scsi/qla4xxx/ql4_os.c b/drivers/scsi/qla4xxx/ql4_os.c
37676index 9da4266..377b3b6 100644
37677--- a/drivers/scsi/qla4xxx/ql4_os.c
37678+++ b/drivers/scsi/qla4xxx/ql4_os.c
37679@@ -2615,12 +2615,12 @@ static void qla4xxx_check_relogin_flash_ddb(struct iscsi_cls_session *cls_sess)
37680 */
37681 if (!iscsi_is_session_online(cls_sess)) {
37682 /* Reset retry relogin timer */
37683- atomic_inc(&ddb_entry->relogin_retry_count);
37684+ atomic_inc_unchecked(&ddb_entry->relogin_retry_count);
37685 DEBUG2(ql4_printk(KERN_INFO, ha,
37686 "%s: index[%d] relogin timed out-retrying"
37687 " relogin (%d), retry (%d)\n", __func__,
37688 ddb_entry->fw_ddb_index,
37689- atomic_read(&ddb_entry->relogin_retry_count),
37690+ atomic_read_unchecked(&ddb_entry->relogin_retry_count),
37691 ddb_entry->default_time2wait + 4));
37692 set_bit(DPC_RELOGIN_DEVICE, &ha->dpc_flags);
37693 atomic_set(&ddb_entry->retry_relogin_timer,
37694@@ -4635,7 +4635,7 @@ static void qla4xxx_setup_flash_ddb_entry(struct scsi_qla_host *ha,
37695
37696 atomic_set(&ddb_entry->retry_relogin_timer, INVALID_ENTRY);
37697 atomic_set(&ddb_entry->relogin_timer, 0);
37698- atomic_set(&ddb_entry->relogin_retry_count, 0);
37699+ atomic_set_unchecked(&ddb_entry->relogin_retry_count, 0);
37700 def_timeout = le16_to_cpu(ddb_entry->fw_ddb_entry.def_timeout);
37701 ddb_entry->default_relogin_timeout =
37702 (def_timeout > LOGIN_TOV) && (def_timeout < LOGIN_TOV * 10) ?
37703diff --git a/drivers/scsi/scsi.c b/drivers/scsi/scsi.c
37704index 2936b44..546ecdb 100644
37705--- a/drivers/scsi/scsi.c
37706+++ b/drivers/scsi/scsi.c
37707@@ -660,7 +660,7 @@ int scsi_dispatch_cmd(struct scsi_cmnd *cmd)
37708 unsigned long timeout;
37709 int rtn = 0;
37710
37711- atomic_inc(&cmd->device->iorequest_cnt);
37712+ atomic_inc_unchecked(&cmd->device->iorequest_cnt);
37713
37714 /* check if the device is still usable */
37715 if (unlikely(cmd->device->sdev_state == SDEV_DEL)) {
37716diff --git a/drivers/scsi/scsi_lib.c b/drivers/scsi/scsi_lib.c
37717index faa790f..7e351ddd 100644
37718--- a/drivers/scsi/scsi_lib.c
37719+++ b/drivers/scsi/scsi_lib.c
37720@@ -1442,7 +1442,7 @@ static void scsi_kill_request(struct request *req, struct request_queue *q)
37721 shost = sdev->host;
37722 scsi_init_cmd_errh(cmd);
37723 cmd->result = DID_NO_CONNECT << 16;
37724- atomic_inc(&cmd->device->iorequest_cnt);
37725+ atomic_inc_unchecked(&cmd->device->iorequest_cnt);
37726
37727 /*
37728 * SCSI request completion path will do scsi_device_unbusy(),
37729@@ -1468,9 +1468,9 @@ static void scsi_softirq_done(struct request *rq)
37730
37731 INIT_LIST_HEAD(&cmd->eh_entry);
37732
37733- atomic_inc(&cmd->device->iodone_cnt);
37734+ atomic_inc_unchecked(&cmd->device->iodone_cnt);
37735 if (cmd->result)
37736- atomic_inc(&cmd->device->ioerr_cnt);
37737+ atomic_inc_unchecked(&cmd->device->ioerr_cnt);
37738
37739 disposition = scsi_decide_disposition(cmd);
37740 if (disposition != SUCCESS &&
37741diff --git a/drivers/scsi/scsi_sysfs.c b/drivers/scsi/scsi_sysfs.c
37742index ce5224c..8c6d071 100644
37743--- a/drivers/scsi/scsi_sysfs.c
37744+++ b/drivers/scsi/scsi_sysfs.c
37745@@ -661,7 +661,7 @@ show_iostat_##field(struct device *dev, struct device_attribute *attr, \
37746 char *buf) \
37747 { \
37748 struct scsi_device *sdev = to_scsi_device(dev); \
37749- unsigned long long count = atomic_read(&sdev->field); \
37750+ unsigned long long count = atomic_read_unchecked(&sdev->field); \
37751 return snprintf(buf, 20, "0x%llx\n", count); \
37752 } \
37753 static DEVICE_ATTR(field, S_IRUGO, show_iostat_##field, NULL)
37754diff --git a/drivers/scsi/scsi_tgt_lib.c b/drivers/scsi/scsi_tgt_lib.c
37755index 84a1fdf..693b0d6 100644
37756--- a/drivers/scsi/scsi_tgt_lib.c
37757+++ b/drivers/scsi/scsi_tgt_lib.c
37758@@ -362,7 +362,7 @@ static int scsi_map_user_pages(struct scsi_tgt_cmd *tcmd, struct scsi_cmnd *cmd,
37759 int err;
37760
37761 dprintk("%lx %u\n", uaddr, len);
37762- err = blk_rq_map_user(q, rq, NULL, (void *)uaddr, len, GFP_KERNEL);
37763+ err = blk_rq_map_user(q, rq, NULL, (void __user *)uaddr, len, GFP_KERNEL);
37764 if (err) {
37765 /*
37766 * TODO: need to fixup sg_tablesize, max_segment_size,
37767diff --git a/drivers/scsi/scsi_transport_fc.c b/drivers/scsi/scsi_transport_fc.c
37768index e894ca7..de9d7660 100644
37769--- a/drivers/scsi/scsi_transport_fc.c
37770+++ b/drivers/scsi/scsi_transport_fc.c
37771@@ -498,7 +498,7 @@ static DECLARE_TRANSPORT_CLASS(fc_vport_class,
37772 * Netlink Infrastructure
37773 */
37774
37775-static atomic_t fc_event_seq;
37776+static atomic_unchecked_t fc_event_seq;
37777
37778 /**
37779 * fc_get_event_number - Obtain the next sequential FC event number
37780@@ -511,7 +511,7 @@ static atomic_t fc_event_seq;
37781 u32
37782 fc_get_event_number(void)
37783 {
37784- return atomic_add_return(1, &fc_event_seq);
37785+ return atomic_add_return_unchecked(1, &fc_event_seq);
37786 }
37787 EXPORT_SYMBOL(fc_get_event_number);
37788
37789@@ -659,7 +659,7 @@ static __init int fc_transport_init(void)
37790 {
37791 int error;
37792
37793- atomic_set(&fc_event_seq, 0);
37794+ atomic_set_unchecked(&fc_event_seq, 0);
37795
37796 error = transport_class_register(&fc_host_class);
37797 if (error)
37798@@ -849,7 +849,7 @@ static int fc_str_to_dev_loss(const char *buf, unsigned long *val)
37799 char *cp;
37800
37801 *val = simple_strtoul(buf, &cp, 0);
37802- if ((*cp && (*cp != '\n')) || (*val < 0))
37803+ if (*cp && (*cp != '\n'))
37804 return -EINVAL;
37805 /*
37806 * Check for overflow; dev_loss_tmo is u32
37807diff --git a/drivers/scsi/scsi_transport_iscsi.c b/drivers/scsi/scsi_transport_iscsi.c
37808index fa1dfaa..4bb620c 100644
37809--- a/drivers/scsi/scsi_transport_iscsi.c
37810+++ b/drivers/scsi/scsi_transport_iscsi.c
37811@@ -79,7 +79,7 @@ struct iscsi_internal {
37812 struct transport_container session_cont;
37813 };
37814
37815-static atomic_t iscsi_session_nr; /* sysfs session id for next new session */
37816+static atomic_unchecked_t iscsi_session_nr; /* sysfs session id for next new session */
37817 static struct workqueue_struct *iscsi_eh_timer_workq;
37818
37819 static DEFINE_IDA(iscsi_sess_ida);
37820@@ -1064,7 +1064,7 @@ int iscsi_add_session(struct iscsi_cls_session *session, unsigned int target_id)
37821 int err;
37822
37823 ihost = shost->shost_data;
37824- session->sid = atomic_add_return(1, &iscsi_session_nr);
37825+ session->sid = atomic_add_return_unchecked(1, &iscsi_session_nr);
37826
37827 if (target_id == ISCSI_MAX_TARGET) {
37828 id = ida_simple_get(&iscsi_sess_ida, 0, 0, GFP_KERNEL);
37829@@ -2943,7 +2943,7 @@ static __init int iscsi_transport_init(void)
37830 printk(KERN_INFO "Loading iSCSI transport class v%s.\n",
37831 ISCSI_TRANSPORT_VERSION);
37832
37833- atomic_set(&iscsi_session_nr, 0);
37834+ atomic_set_unchecked(&iscsi_session_nr, 0);
37835
37836 err = class_register(&iscsi_transport_class);
37837 if (err)
37838diff --git a/drivers/scsi/scsi_transport_srp.c b/drivers/scsi/scsi_transport_srp.c
37839index 21a045e..ec89e03 100644
37840--- a/drivers/scsi/scsi_transport_srp.c
37841+++ b/drivers/scsi/scsi_transport_srp.c
37842@@ -33,7 +33,7 @@
37843 #include "scsi_transport_srp_internal.h"
37844
37845 struct srp_host_attrs {
37846- atomic_t next_port_id;
37847+ atomic_unchecked_t next_port_id;
37848 };
37849 #define to_srp_host_attrs(host) ((struct srp_host_attrs *)(host)->shost_data)
37850
37851@@ -62,7 +62,7 @@ static int srp_host_setup(struct transport_container *tc, struct device *dev,
37852 struct Scsi_Host *shost = dev_to_shost(dev);
37853 struct srp_host_attrs *srp_host = to_srp_host_attrs(shost);
37854
37855- atomic_set(&srp_host->next_port_id, 0);
37856+ atomic_set_unchecked(&srp_host->next_port_id, 0);
37857 return 0;
37858 }
37859
37860@@ -211,7 +211,7 @@ struct srp_rport *srp_rport_add(struct Scsi_Host *shost,
37861 memcpy(rport->port_id, ids->port_id, sizeof(rport->port_id));
37862 rport->roles = ids->roles;
37863
37864- id = atomic_inc_return(&to_srp_host_attrs(shost)->next_port_id);
37865+ id = atomic_inc_return_unchecked(&to_srp_host_attrs(shost)->next_port_id);
37866 dev_set_name(&rport->dev, "port-%d:%d", shost->host_no, id);
37867
37868 transport_setup_device(&rport->dev);
37869diff --git a/drivers/scsi/sd.c b/drivers/scsi/sd.c
37870index 4df73e5..b691c58 100644
37871--- a/drivers/scsi/sd.c
37872+++ b/drivers/scsi/sd.c
37873@@ -2709,7 +2709,7 @@ static int sd_probe(struct device *dev)
37874 sdkp->disk = gd;
37875 sdkp->index = index;
37876 atomic_set(&sdkp->openers, 0);
37877- atomic_set(&sdkp->device->ioerr_cnt, 0);
37878+ atomic_set_unchecked(&sdkp->device->ioerr_cnt, 0);
37879
37880 if (!sdp->request_queue->rq_timeout) {
37881 if (sdp->type != TYPE_MOD)
37882diff --git a/drivers/scsi/sg.c b/drivers/scsi/sg.c
37883index 9c5c5f2..8414557 100644
37884--- a/drivers/scsi/sg.c
37885+++ b/drivers/scsi/sg.c
37886@@ -1101,7 +1101,7 @@ sg_ioctl(struct file *filp, unsigned int cmd_in, unsigned long arg)
37887 sdp->disk->disk_name,
37888 MKDEV(SCSI_GENERIC_MAJOR, sdp->index),
37889 NULL,
37890- (char *)arg);
37891+ (char __user *)arg);
37892 case BLKTRACESTART:
37893 return blk_trace_startstop(sdp->device->request_queue, 1);
37894 case BLKTRACESTOP:
37895diff --git a/drivers/spi/spi.c b/drivers/spi/spi.c
37896index 84c2861..ece0a31 100644
37897--- a/drivers/spi/spi.c
37898+++ b/drivers/spi/spi.c
37899@@ -1453,7 +1453,7 @@ int spi_bus_unlock(struct spi_master *master)
37900 EXPORT_SYMBOL_GPL(spi_bus_unlock);
37901
37902 /* portable code must never pass more than 32 bytes */
37903-#define SPI_BUFSIZ max(32,SMP_CACHE_BYTES)
37904+#define SPI_BUFSIZ max(32UL,SMP_CACHE_BYTES)
37905
37906 static u8 *buf;
37907
37908diff --git a/drivers/staging/octeon/ethernet-rx.c b/drivers/staging/octeon/ethernet-rx.c
37909index 34afc16..ffe44dd 100644
37910--- a/drivers/staging/octeon/ethernet-rx.c
37911+++ b/drivers/staging/octeon/ethernet-rx.c
37912@@ -421,11 +421,11 @@ static int cvm_oct_napi_poll(struct napi_struct *napi, int budget)
37913 /* Increment RX stats for virtual ports */
37914 if (work->ipprt >= CVMX_PIP_NUM_INPUT_PORTS) {
37915 #ifdef CONFIG_64BIT
37916- atomic64_add(1, (atomic64_t *)&priv->stats.rx_packets);
37917- atomic64_add(skb->len, (atomic64_t *)&priv->stats.rx_bytes);
37918+ atomic64_add_unchecked(1, (atomic64_unchecked_t *)&priv->stats.rx_packets);
37919+ atomic64_add_unchecked(skb->len, (atomic64_unchecked_t *)&priv->stats.rx_bytes);
37920 #else
37921- atomic_add(1, (atomic_t *)&priv->stats.rx_packets);
37922- atomic_add(skb->len, (atomic_t *)&priv->stats.rx_bytes);
37923+ atomic_add_unchecked(1, (atomic_unchecked_t *)&priv->stats.rx_packets);
37924+ atomic_add_unchecked(skb->len, (atomic_unchecked_t *)&priv->stats.rx_bytes);
37925 #endif
37926 }
37927 netif_receive_skb(skb);
37928@@ -437,9 +437,9 @@ static int cvm_oct_napi_poll(struct napi_struct *napi, int budget)
37929 dev->name);
37930 */
37931 #ifdef CONFIG_64BIT
37932- atomic64_add(1, (atomic64_t *)&priv->stats.rx_dropped);
37933+ atomic64_unchecked_add(1, (atomic64_unchecked_t *)&priv->stats.rx_dropped);
37934 #else
37935- atomic_add(1, (atomic_t *)&priv->stats.rx_dropped);
37936+ atomic_add_unchecked(1, (atomic_unchecked_t *)&priv->stats.rx_dropped);
37937 #endif
37938 dev_kfree_skb_irq(skb);
37939 }
37940diff --git a/drivers/staging/octeon/ethernet.c b/drivers/staging/octeon/ethernet.c
37941index 683bedc..86dba9a 100644
37942--- a/drivers/staging/octeon/ethernet.c
37943+++ b/drivers/staging/octeon/ethernet.c
37944@@ -252,11 +252,11 @@ static struct net_device_stats *cvm_oct_common_get_stats(struct net_device *dev)
37945 * since the RX tasklet also increments it.
37946 */
37947 #ifdef CONFIG_64BIT
37948- atomic64_add(rx_status.dropped_packets,
37949- (atomic64_t *)&priv->stats.rx_dropped);
37950+ atomic64_add_unchecked(rx_status.dropped_packets,
37951+ (atomic64_unchecked_t *)&priv->stats.rx_dropped);
37952 #else
37953- atomic_add(rx_status.dropped_packets,
37954- (atomic_t *)&priv->stats.rx_dropped);
37955+ atomic_add_unchecked(rx_status.dropped_packets,
37956+ (atomic_unchecked_t *)&priv->stats.rx_dropped);
37957 #endif
37958 }
37959
37960diff --git a/drivers/staging/omapdrm/omap_drv.c b/drivers/staging/omapdrm/omap_drv.c
37961index 4beab94..44149ee 100644
37962--- a/drivers/staging/omapdrm/omap_drv.c
37963+++ b/drivers/staging/omapdrm/omap_drv.c
37964@@ -761,7 +761,6 @@ static struct drm_driver omap_drm_driver = {
37965 .irq_postinstall = dev_irq_postinstall,
37966 .irq_uninstall = dev_irq_uninstall,
37967 .irq_handler = dev_irq_handler,
37968- .reclaim_buffers = drm_core_reclaim_buffers,
37969 #ifdef CONFIG_DEBUG_FS
37970 .debugfs_init = omap_debugfs_init,
37971 .debugfs_cleanup = omap_debugfs_cleanup,
37972diff --git a/drivers/staging/rtl8712/rtl871x_io.h b/drivers/staging/rtl8712/rtl871x_io.h
37973index dc23395..cf7e9b1 100644
37974--- a/drivers/staging/rtl8712/rtl871x_io.h
37975+++ b/drivers/staging/rtl8712/rtl871x_io.h
37976@@ -108,7 +108,7 @@ struct _io_ops {
37977 u8 *pmem);
37978 u32 (*_write_port)(struct intf_hdl *pintfhdl, u32 addr, u32 cnt,
37979 u8 *pmem);
37980-};
37981+} __no_const;
37982
37983 struct io_req {
37984 struct list_head list;
37985diff --git a/drivers/staging/sbe-2t3e3/netdev.c b/drivers/staging/sbe-2t3e3/netdev.c
37986index c7b5e8b..783d6cb 100644
37987--- a/drivers/staging/sbe-2t3e3/netdev.c
37988+++ b/drivers/staging/sbe-2t3e3/netdev.c
37989@@ -51,7 +51,7 @@ int t3e3_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
37990 t3e3_if_config(sc, cmd_2t3e3, (char *)&param, &resp, &rlen);
37991
37992 if (rlen)
37993- if (copy_to_user(data, &resp, rlen))
37994+ if (rlen > sizeof resp || copy_to_user(data, &resp, rlen))
37995 return -EFAULT;
37996
37997 return 0;
37998diff --git a/drivers/staging/usbip/usbip_common.h b/drivers/staging/usbip/usbip_common.h
37999index 5d89c0f..9261317 100644
38000--- a/drivers/staging/usbip/usbip_common.h
38001+++ b/drivers/staging/usbip/usbip_common.h
38002@@ -289,7 +289,7 @@ struct usbip_device {
38003 void (*shutdown)(struct usbip_device *);
38004 void (*reset)(struct usbip_device *);
38005 void (*unusable)(struct usbip_device *);
38006- } eh_ops;
38007+ } __no_const eh_ops;
38008 };
38009
38010 #define kthread_get_run(threadfn, data, namefmt, ...) \
38011diff --git a/drivers/staging/usbip/vhci.h b/drivers/staging/usbip/vhci.h
38012index c66b8b3..a4a035b 100644
38013--- a/drivers/staging/usbip/vhci.h
38014+++ b/drivers/staging/usbip/vhci.h
38015@@ -83,7 +83,7 @@ struct vhci_hcd {
38016 unsigned resuming:1;
38017 unsigned long re_timeout;
38018
38019- atomic_t seqnum;
38020+ atomic_unchecked_t seqnum;
38021
38022 /*
38023 * NOTE:
38024diff --git a/drivers/staging/usbip/vhci_hcd.c b/drivers/staging/usbip/vhci_hcd.c
38025index 12a9a5f..afd8295 100644
38026--- a/drivers/staging/usbip/vhci_hcd.c
38027+++ b/drivers/staging/usbip/vhci_hcd.c
38028@@ -471,7 +471,7 @@ static void vhci_tx_urb(struct urb *urb)
38029 return;
38030 }
38031
38032- priv->seqnum = atomic_inc_return(&the_controller->seqnum);
38033+ priv->seqnum = atomic_inc_return_unchecked(&the_controller->seqnum);
38034 if (priv->seqnum == 0xffff)
38035 dev_info(&urb->dev->dev, "seqnum max\n");
38036
38037@@ -723,7 +723,7 @@ static int vhci_urb_dequeue(struct usb_hcd *hcd, struct urb *urb, int status)
38038 return -ENOMEM;
38039 }
38040
38041- unlink->seqnum = atomic_inc_return(&the_controller->seqnum);
38042+ unlink->seqnum = atomic_inc_return_unchecked(&the_controller->seqnum);
38043 if (unlink->seqnum == 0xffff)
38044 pr_info("seqnum max\n");
38045
38046@@ -911,7 +911,7 @@ static int vhci_start(struct usb_hcd *hcd)
38047 vdev->rhport = rhport;
38048 }
38049
38050- atomic_set(&vhci->seqnum, 0);
38051+ atomic_set_unchecked(&vhci->seqnum, 0);
38052 spin_lock_init(&vhci->lock);
38053
38054 hcd->power_budget = 0; /* no limit */
38055diff --git a/drivers/staging/usbip/vhci_rx.c b/drivers/staging/usbip/vhci_rx.c
38056index f0eaf04..5a82e06 100644
38057--- a/drivers/staging/usbip/vhci_rx.c
38058+++ b/drivers/staging/usbip/vhci_rx.c
38059@@ -77,7 +77,7 @@ static void vhci_recv_ret_submit(struct vhci_device *vdev,
38060 if (!urb) {
38061 pr_err("cannot find a urb of seqnum %u\n", pdu->base.seqnum);
38062 pr_info("max seqnum %d\n",
38063- atomic_read(&the_controller->seqnum));
38064+ atomic_read_unchecked(&the_controller->seqnum));
38065 usbip_event_add(ud, VDEV_EVENT_ERROR_TCP);
38066 return;
38067 }
38068diff --git a/drivers/staging/vt6655/hostap.c b/drivers/staging/vt6655/hostap.c
38069index 6ac6f45..1b208ba 100644
38070--- a/drivers/staging/vt6655/hostap.c
38071+++ b/drivers/staging/vt6655/hostap.c
38072@@ -73,14 +73,13 @@ static int msglevel =MSG_LEVEL_INFO;
38073 *
38074 */
38075
38076+static net_device_ops_no_const apdev_netdev_ops;
38077+
38078 static int hostap_enable_hostapd(PSDevice pDevice, int rtnl_locked)
38079 {
38080 PSDevice apdev_priv;
38081 struct net_device *dev = pDevice->dev;
38082 int ret;
38083- const struct net_device_ops apdev_netdev_ops = {
38084- .ndo_start_xmit = pDevice->tx_80211,
38085- };
38086
38087 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "%s: Enabling hostapd mode\n", dev->name);
38088
38089@@ -92,6 +91,8 @@ static int hostap_enable_hostapd(PSDevice pDevice, int rtnl_locked)
38090 *apdev_priv = *pDevice;
38091 memcpy(pDevice->apdev->dev_addr, dev->dev_addr, ETH_ALEN);
38092
38093+ /* only half broken now */
38094+ apdev_netdev_ops.ndo_start_xmit = pDevice->tx_80211;
38095 pDevice->apdev->netdev_ops = &apdev_netdev_ops;
38096
38097 pDevice->apdev->type = ARPHRD_IEEE80211;
38098diff --git a/drivers/staging/vt6656/hostap.c b/drivers/staging/vt6656/hostap.c
38099index 682002a..35ed5cf 100644
38100--- a/drivers/staging/vt6656/hostap.c
38101+++ b/drivers/staging/vt6656/hostap.c
38102@@ -60,14 +60,13 @@ static int msglevel =MSG_LEVEL_INFO;
38103 *
38104 */
38105
38106+static net_device_ops_no_const apdev_netdev_ops;
38107+
38108 static int hostap_enable_hostapd(PSDevice pDevice, int rtnl_locked)
38109 {
38110 PSDevice apdev_priv;
38111 struct net_device *dev = pDevice->dev;
38112 int ret;
38113- const struct net_device_ops apdev_netdev_ops = {
38114- .ndo_start_xmit = pDevice->tx_80211,
38115- };
38116
38117 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "%s: Enabling hostapd mode\n", dev->name);
38118
38119@@ -79,6 +78,8 @@ static int hostap_enable_hostapd(PSDevice pDevice, int rtnl_locked)
38120 *apdev_priv = *pDevice;
38121 memcpy(pDevice->apdev->dev_addr, dev->dev_addr, ETH_ALEN);
38122
38123+ /* only half broken now */
38124+ apdev_netdev_ops.ndo_start_xmit = pDevice->tx_80211;
38125 pDevice->apdev->netdev_ops = &apdev_netdev_ops;
38126
38127 pDevice->apdev->type = ARPHRD_IEEE80211;
38128diff --git a/drivers/staging/wlan-ng/hfa384x_usb.c b/drivers/staging/wlan-ng/hfa384x_usb.c
38129index 7843dfd..3db105f 100644
38130--- a/drivers/staging/wlan-ng/hfa384x_usb.c
38131+++ b/drivers/staging/wlan-ng/hfa384x_usb.c
38132@@ -204,7 +204,7 @@ static void unlocked_usbctlx_complete(hfa384x_t *hw, hfa384x_usbctlx_t *ctlx);
38133
38134 struct usbctlx_completor {
38135 int (*complete) (struct usbctlx_completor *);
38136-};
38137+} __no_const;
38138
38139 static int
38140 hfa384x_usbctlx_complete_sync(hfa384x_t *hw,
38141diff --git a/drivers/staging/zcache/tmem.c b/drivers/staging/zcache/tmem.c
38142index eaa9021..43f023b 100644
38143--- a/drivers/staging/zcache/tmem.c
38144+++ b/drivers/staging/zcache/tmem.c
38145@@ -39,7 +39,7 @@
38146 * A tmem host implementation must use this function to register callbacks
38147 * for memory allocation.
38148 */
38149-static struct tmem_hostops tmem_hostops;
38150+static tmem_hostops_no_const tmem_hostops;
38151
38152 static void tmem_objnode_tree_init(void);
38153
38154@@ -53,7 +53,7 @@ void tmem_register_hostops(struct tmem_hostops *m)
38155 * A tmem host implementation must use this function to register
38156 * callbacks for a page-accessible memory (PAM) implementation
38157 */
38158-static struct tmem_pamops tmem_pamops;
38159+static tmem_pamops_no_const tmem_pamops;
38160
38161 void tmem_register_pamops(struct tmem_pamops *m)
38162 {
38163diff --git a/drivers/staging/zcache/tmem.h b/drivers/staging/zcache/tmem.h
38164index 0d4aa82..f7832d4 100644
38165--- a/drivers/staging/zcache/tmem.h
38166+++ b/drivers/staging/zcache/tmem.h
38167@@ -180,6 +180,7 @@ struct tmem_pamops {
38168 void (*new_obj)(struct tmem_obj *);
38169 int (*replace_in_obj)(void *, struct tmem_obj *);
38170 };
38171+typedef struct tmem_pamops __no_const tmem_pamops_no_const;
38172 extern void tmem_register_pamops(struct tmem_pamops *m);
38173
38174 /* memory allocation methods provided by the host implementation */
38175@@ -189,6 +190,7 @@ struct tmem_hostops {
38176 struct tmem_objnode *(*objnode_alloc)(struct tmem_pool *);
38177 void (*objnode_free)(struct tmem_objnode *, struct tmem_pool *);
38178 };
38179+typedef struct tmem_hostops __no_const tmem_hostops_no_const;
38180 extern void tmem_register_hostops(struct tmem_hostops *m);
38181
38182 /* core tmem accessor functions */
38183diff --git a/drivers/target/target_core_transport.c b/drivers/target/target_core_transport.c
38184index 7502660..f214d9f 100644
38185--- a/drivers/target/target_core_transport.c
38186+++ b/drivers/target/target_core_transport.c
38187@@ -1098,7 +1098,7 @@ struct se_device *transport_add_device_to_core_hba(
38188 spin_lock_init(&dev->se_port_lock);
38189 spin_lock_init(&dev->se_tmr_lock);
38190 spin_lock_init(&dev->qf_cmd_lock);
38191- atomic_set(&dev->dev_ordered_id, 0);
38192+ atomic_set_unchecked(&dev->dev_ordered_id, 0);
38193
38194 se_dev_set_default_attribs(dev, dev_limits);
38195
38196@@ -1288,7 +1288,7 @@ static int transport_check_alloc_task_attr(struct se_cmd *cmd)
38197 * Used to determine when ORDERED commands should go from
38198 * Dormant to Active status.
38199 */
38200- cmd->se_ordered_id = atomic_inc_return(&cmd->se_dev->dev_ordered_id);
38201+ cmd->se_ordered_id = atomic_inc_return_unchecked(&cmd->se_dev->dev_ordered_id);
38202 smp_mb__after_atomic_inc();
38203 pr_debug("Allocated se_ordered_id: %u for Task Attr: 0x%02x on %s\n",
38204 cmd->se_ordered_id, cmd->sam_task_attr,
38205diff --git a/drivers/tty/cyclades.c b/drivers/tty/cyclades.c
38206index e61cabd..7617d26 100644
38207--- a/drivers/tty/cyclades.c
38208+++ b/drivers/tty/cyclades.c
38209@@ -1589,10 +1589,10 @@ static int cy_open(struct tty_struct *tty, struct file *filp)
38210 printk(KERN_DEBUG "cyc:cy_open ttyC%d, count = %d\n", info->line,
38211 info->port.count);
38212 #endif
38213- info->port.count++;
38214+ atomic_inc(&info->port.count);
38215 #ifdef CY_DEBUG_COUNT
38216 printk(KERN_DEBUG "cyc:cy_open (%d): incrementing count to %d\n",
38217- current->pid, info->port.count);
38218+ current->pid, atomic_read(&info->port.count));
38219 #endif
38220
38221 /*
38222@@ -3987,7 +3987,7 @@ static int cyclades_proc_show(struct seq_file *m, void *v)
38223 for (j = 0; j < cy_card[i].nports; j++) {
38224 info = &cy_card[i].ports[j];
38225
38226- if (info->port.count) {
38227+ if (atomic_read(&info->port.count)) {
38228 /* XXX is the ldisc num worth this? */
38229 struct tty_struct *tty;
38230 struct tty_ldisc *ld;
38231diff --git a/drivers/tty/hvc/hvc_console.c b/drivers/tty/hvc/hvc_console.c
38232index 2d691eb..be02ebd 100644
38233--- a/drivers/tty/hvc/hvc_console.c
38234+++ b/drivers/tty/hvc/hvc_console.c
38235@@ -315,7 +315,7 @@ static int hvc_open(struct tty_struct *tty, struct file * filp)
38236
38237 spin_lock_irqsave(&hp->port.lock, flags);
38238 /* Check and then increment for fast path open. */
38239- if (hp->port.count++ > 0) {
38240+ if (atomic_inc_return(&hp->port.count) > 1) {
38241 spin_unlock_irqrestore(&hp->port.lock, flags);
38242 hvc_kick();
38243 return 0;
38244@@ -366,7 +366,7 @@ static void hvc_close(struct tty_struct *tty, struct file * filp)
38245
38246 spin_lock_irqsave(&hp->port.lock, flags);
38247
38248- if (--hp->port.count == 0) {
38249+ if (atomic_dec_return(&hp->port.count) == 0) {
38250 spin_unlock_irqrestore(&hp->port.lock, flags);
38251 /* We are done with the tty pointer now. */
38252 tty_port_tty_set(&hp->port, NULL);
38253@@ -384,9 +384,9 @@ static void hvc_close(struct tty_struct *tty, struct file * filp)
38254 */
38255 tty_wait_until_sent_from_close(tty, HVC_CLOSE_WAIT);
38256 } else {
38257- if (hp->port.count < 0)
38258+ if (atomic_read(&hp->port.count) < 0)
38259 printk(KERN_ERR "hvc_close %X: oops, count is %d\n",
38260- hp->vtermno, hp->port.count);
38261+ hp->vtermno, atomic_read(&hp->port.count));
38262 spin_unlock_irqrestore(&hp->port.lock, flags);
38263 }
38264
38265@@ -412,13 +412,13 @@ static void hvc_hangup(struct tty_struct *tty)
38266 * open->hangup case this can be called after the final close so prevent
38267 * that from happening for now.
38268 */
38269- if (hp->port.count <= 0) {
38270+ if (atomic_read(&hp->port.count) <= 0) {
38271 spin_unlock_irqrestore(&hp->port.lock, flags);
38272 return;
38273 }
38274
38275- temp_open_count = hp->port.count;
38276- hp->port.count = 0;
38277+ temp_open_count = atomic_read(&hp->port.count);
38278+ atomic_set(&hp->port.count, 0);
38279 spin_unlock_irqrestore(&hp->port.lock, flags);
38280 tty_port_tty_set(&hp->port, NULL);
38281
38282@@ -471,7 +471,7 @@ static int hvc_write(struct tty_struct *tty, const unsigned char *buf, int count
38283 return -EPIPE;
38284
38285 /* FIXME what's this (unprotected) check for? */
38286- if (hp->port.count <= 0)
38287+ if (atomic_read(&hp->port.count) <= 0)
38288 return -EIO;
38289
38290 spin_lock_irqsave(&hp->lock, flags);
38291diff --git a/drivers/tty/hvc/hvcs.c b/drivers/tty/hvc/hvcs.c
38292index d56788c..12d8f85 100644
38293--- a/drivers/tty/hvc/hvcs.c
38294+++ b/drivers/tty/hvc/hvcs.c
38295@@ -83,6 +83,7 @@
38296 #include <asm/hvcserver.h>
38297 #include <asm/uaccess.h>
38298 #include <asm/vio.h>
38299+#include <asm/local.h>
38300
38301 /*
38302 * 1.3.0 -> 1.3.1 In hvcs_open memset(..,0x00,..) instead of memset(..,0x3F,00).
38303@@ -416,7 +417,7 @@ static ssize_t hvcs_vterm_state_store(struct device *dev, struct device_attribut
38304
38305 spin_lock_irqsave(&hvcsd->lock, flags);
38306
38307- if (hvcsd->port.count > 0) {
38308+ if (atomic_read(&hvcsd->port.count) > 0) {
38309 spin_unlock_irqrestore(&hvcsd->lock, flags);
38310 printk(KERN_INFO "HVCS: vterm state unchanged. "
38311 "The hvcs device node is still in use.\n");
38312@@ -1134,7 +1135,7 @@ static int hvcs_open(struct tty_struct *tty, struct file *filp)
38313 if ((retval = hvcs_partner_connect(hvcsd)))
38314 goto error_release;
38315
38316- hvcsd->port.count = 1;
38317+ atomic_set(&hvcsd->port.count, 1);
38318 hvcsd->port.tty = tty;
38319 tty->driver_data = hvcsd;
38320
38321@@ -1168,7 +1169,7 @@ fast_open:
38322
38323 spin_lock_irqsave(&hvcsd->lock, flags);
38324 tty_port_get(&hvcsd->port);
38325- hvcsd->port.count++;
38326+ atomic_inc(&hvcsd->port.count);
38327 hvcsd->todo_mask |= HVCS_SCHED_READ;
38328 spin_unlock_irqrestore(&hvcsd->lock, flags);
38329
38330@@ -1212,7 +1213,7 @@ static void hvcs_close(struct tty_struct *tty, struct file *filp)
38331 hvcsd = tty->driver_data;
38332
38333 spin_lock_irqsave(&hvcsd->lock, flags);
38334- if (--hvcsd->port.count == 0) {
38335+ if (atomic_dec_and_test(&hvcsd->port.count)) {
38336
38337 vio_disable_interrupts(hvcsd->vdev);
38338
38339@@ -1238,10 +1239,10 @@ static void hvcs_close(struct tty_struct *tty, struct file *filp)
38340 free_irq(irq, hvcsd);
38341 tty_port_put(&hvcsd->port);
38342 return;
38343- } else if (hvcsd->port.count < 0) {
38344+ } else if (atomic_read(&hvcsd->port.count) < 0) {
38345 printk(KERN_ERR "HVCS: vty-server@%X open_count: %d"
38346 " is missmanaged.\n",
38347- hvcsd->vdev->unit_address, hvcsd->port.count);
38348+ hvcsd->vdev->unit_address, atomic_read(&hvcsd->port.count));
38349 }
38350
38351 spin_unlock_irqrestore(&hvcsd->lock, flags);
38352@@ -1257,7 +1258,7 @@ static void hvcs_hangup(struct tty_struct * tty)
38353
38354 spin_lock_irqsave(&hvcsd->lock, flags);
38355 /* Preserve this so that we know how many kref refs to put */
38356- temp_open_count = hvcsd->port.count;
38357+ temp_open_count = atomic_read(&hvcsd->port.count);
38358
38359 /*
38360 * Don't kref put inside the spinlock because the destruction
38361@@ -1272,7 +1273,7 @@ static void hvcs_hangup(struct tty_struct * tty)
38362 tty->driver_data = NULL;
38363 hvcsd->port.tty = NULL;
38364
38365- hvcsd->port.count = 0;
38366+ atomic_set(&hvcsd->port.count, 0);
38367
38368 /* This will drop any buffered data on the floor which is OK in a hangup
38369 * scenario. */
38370@@ -1343,7 +1344,7 @@ static int hvcs_write(struct tty_struct *tty,
38371 * the middle of a write operation? This is a crummy place to do this
38372 * but we want to keep it all in the spinlock.
38373 */
38374- if (hvcsd->port.count <= 0) {
38375+ if (atomic_read(&hvcsd->port.count) <= 0) {
38376 spin_unlock_irqrestore(&hvcsd->lock, flags);
38377 return -ENODEV;
38378 }
38379@@ -1417,7 +1418,7 @@ static int hvcs_write_room(struct tty_struct *tty)
38380 {
38381 struct hvcs_struct *hvcsd = tty->driver_data;
38382
38383- if (!hvcsd || hvcsd->port.count <= 0)
38384+ if (!hvcsd || atomic_read(&hvcsd->port.count) <= 0)
38385 return 0;
38386
38387 return HVCS_BUFF_LEN - hvcsd->chars_in_buffer;
38388diff --git a/drivers/tty/ipwireless/tty.c b/drivers/tty/ipwireless/tty.c
38389index f8b5fa0..4ba9f89 100644
38390--- a/drivers/tty/ipwireless/tty.c
38391+++ b/drivers/tty/ipwireless/tty.c
38392@@ -29,6 +29,7 @@
38393 #include <linux/tty_driver.h>
38394 #include <linux/tty_flip.h>
38395 #include <linux/uaccess.h>
38396+#include <asm/local.h>
38397
38398 #include "tty.h"
38399 #include "network.h"
38400@@ -99,10 +100,10 @@ static int ipw_open(struct tty_struct *linux_tty, struct file *filp)
38401 mutex_unlock(&tty->ipw_tty_mutex);
38402 return -ENODEV;
38403 }
38404- if (tty->port.count == 0)
38405+ if (atomic_read(&tty->port.count) == 0)
38406 tty->tx_bytes_queued = 0;
38407
38408- tty->port.count++;
38409+ atomic_inc(&tty->port.count);
38410
38411 tty->port.tty = linux_tty;
38412 linux_tty->driver_data = tty;
38413@@ -118,9 +119,7 @@ static int ipw_open(struct tty_struct *linux_tty, struct file *filp)
38414
38415 static void do_ipw_close(struct ipw_tty *tty)
38416 {
38417- tty->port.count--;
38418-
38419- if (tty->port.count == 0) {
38420+ if (atomic_dec_return(&tty->port.count) == 0) {
38421 struct tty_struct *linux_tty = tty->port.tty;
38422
38423 if (linux_tty != NULL) {
38424@@ -141,7 +140,7 @@ static void ipw_hangup(struct tty_struct *linux_tty)
38425 return;
38426
38427 mutex_lock(&tty->ipw_tty_mutex);
38428- if (tty->port.count == 0) {
38429+ if (atomic_read(&tty->port.count) == 0) {
38430 mutex_unlock(&tty->ipw_tty_mutex);
38431 return;
38432 }
38433@@ -170,7 +169,7 @@ void ipwireless_tty_received(struct ipw_tty *tty, unsigned char *data,
38434 return;
38435 }
38436
38437- if (!tty->port.count) {
38438+ if (!atomic_read(&tty->port.count)) {
38439 mutex_unlock(&tty->ipw_tty_mutex);
38440 return;
38441 }
38442@@ -212,7 +211,7 @@ static int ipw_write(struct tty_struct *linux_tty,
38443 return -ENODEV;
38444
38445 mutex_lock(&tty->ipw_tty_mutex);
38446- if (!tty->port.count) {
38447+ if (!atomic_read(&tty->port.count)) {
38448 mutex_unlock(&tty->ipw_tty_mutex);
38449 return -EINVAL;
38450 }
38451@@ -252,7 +251,7 @@ static int ipw_write_room(struct tty_struct *linux_tty)
38452 if (!tty)
38453 return -ENODEV;
38454
38455- if (!tty->port.count)
38456+ if (!atomic_read(&tty->port.count))
38457 return -EINVAL;
38458
38459 room = IPWIRELESS_TX_QUEUE_SIZE - tty->tx_bytes_queued;
38460@@ -294,7 +293,7 @@ static int ipw_chars_in_buffer(struct tty_struct *linux_tty)
38461 if (!tty)
38462 return 0;
38463
38464- if (!tty->port.count)
38465+ if (!atomic_read(&tty->port.count))
38466 return 0;
38467
38468 return tty->tx_bytes_queued;
38469@@ -375,7 +374,7 @@ static int ipw_tiocmget(struct tty_struct *linux_tty)
38470 if (!tty)
38471 return -ENODEV;
38472
38473- if (!tty->port.count)
38474+ if (!atomic_read(&tty->port.count))
38475 return -EINVAL;
38476
38477 return get_control_lines(tty);
38478@@ -391,7 +390,7 @@ ipw_tiocmset(struct tty_struct *linux_tty,
38479 if (!tty)
38480 return -ENODEV;
38481
38482- if (!tty->port.count)
38483+ if (!atomic_read(&tty->port.count))
38484 return -EINVAL;
38485
38486 return set_control_lines(tty, set, clear);
38487@@ -405,7 +404,7 @@ static int ipw_ioctl(struct tty_struct *linux_tty,
38488 if (!tty)
38489 return -ENODEV;
38490
38491- if (!tty->port.count)
38492+ if (!atomic_read(&tty->port.count))
38493 return -EINVAL;
38494
38495 /* FIXME: Exactly how is the tty object locked here .. */
38496@@ -561,7 +560,7 @@ void ipwireless_tty_free(struct ipw_tty *tty)
38497 * are gone */
38498 mutex_lock(&ttyj->ipw_tty_mutex);
38499 }
38500- while (ttyj->port.count)
38501+ while (atomic_read(&ttyj->port.count))
38502 do_ipw_close(ttyj);
38503 ipwireless_disassociate_network_ttys(network,
38504 ttyj->channel_idx);
38505diff --git a/drivers/tty/moxa.c b/drivers/tty/moxa.c
38506index 324467d..504cc25 100644
38507--- a/drivers/tty/moxa.c
38508+++ b/drivers/tty/moxa.c
38509@@ -1172,7 +1172,7 @@ static int moxa_open(struct tty_struct *tty, struct file *filp)
38510 }
38511
38512 ch = &brd->ports[port % MAX_PORTS_PER_BOARD];
38513- ch->port.count++;
38514+ atomic_inc(&ch->port.count);
38515 tty->driver_data = ch;
38516 tty_port_tty_set(&ch->port, tty);
38517 mutex_lock(&ch->port.mutex);
38518diff --git a/drivers/tty/n_gsm.c b/drivers/tty/n_gsm.c
38519index 90dff82..08119c3 100644
38520--- a/drivers/tty/n_gsm.c
38521+++ b/drivers/tty/n_gsm.c
38522@@ -1639,7 +1639,7 @@ static struct gsm_dlci *gsm_dlci_alloc(struct gsm_mux *gsm, int addr)
38523 kref_init(&dlci->ref);
38524 mutex_init(&dlci->mutex);
38525 dlci->fifo = &dlci->_fifo;
38526- if (kfifo_alloc(&dlci->_fifo, 4096, GFP_KERNEL) < 0) {
38527+ if (kfifo_alloc(&dlci->_fifo, 4096, GFP_KERNEL)) {
38528 kfree(dlci);
38529 return NULL;
38530 }
38531@@ -2909,7 +2909,7 @@ static int gsmtty_open(struct tty_struct *tty, struct file *filp)
38532 if (dlci == NULL)
38533 return -ENOMEM;
38534 port = &dlci->port;
38535- port->count++;
38536+ atomic_inc(&port->count);
38537 tty->driver_data = dlci;
38538 dlci_get(dlci);
38539 dlci_get(dlci->gsm->dlci[0]);
38540diff --git a/drivers/tty/n_tty.c b/drivers/tty/n_tty.c
38541index 26f0d0e..b7c4273 100644
38542--- a/drivers/tty/n_tty.c
38543+++ b/drivers/tty/n_tty.c
38544@@ -2124,6 +2124,7 @@ void n_tty_inherit_ops(struct tty_ldisc_ops *ops)
38545 {
38546 *ops = tty_ldisc_N_TTY;
38547 ops->owner = NULL;
38548- ops->refcount = ops->flags = 0;
38549+ atomic_set(&ops->refcount, 0);
38550+ ops->flags = 0;
38551 }
38552 EXPORT_SYMBOL_GPL(n_tty_inherit_ops);
38553diff --git a/drivers/tty/pty.c b/drivers/tty/pty.c
38554index 5505ffc..7affff9 100644
38555--- a/drivers/tty/pty.c
38556+++ b/drivers/tty/pty.c
38557@@ -718,8 +718,10 @@ static void __init unix98_pty_init(void)
38558 panic("Couldn't register Unix98 pts driver");
38559
38560 /* Now create the /dev/ptmx special device */
38561+ pax_open_kernel();
38562 tty_default_fops(&ptmx_fops);
38563- ptmx_fops.open = ptmx_open;
38564+ *(void **)&ptmx_fops.open = ptmx_open;
38565+ pax_close_kernel();
38566
38567 cdev_init(&ptmx_cdev, &ptmx_fops);
38568 if (cdev_add(&ptmx_cdev, MKDEV(TTYAUX_MAJOR, 2), 1) ||
38569diff --git a/drivers/tty/rocket.c b/drivers/tty/rocket.c
38570index 777d5f9..56d67ca 100644
38571--- a/drivers/tty/rocket.c
38572+++ b/drivers/tty/rocket.c
38573@@ -924,7 +924,7 @@ static int rp_open(struct tty_struct *tty, struct file *filp)
38574 tty->driver_data = info;
38575 tty_port_tty_set(port, tty);
38576
38577- if (port->count++ == 0) {
38578+ if (atomic_inc_return(&port->count) == 1) {
38579 atomic_inc(&rp_num_ports_open);
38580
38581 #ifdef ROCKET_DEBUG_OPEN
38582@@ -933,7 +933,7 @@ static int rp_open(struct tty_struct *tty, struct file *filp)
38583 #endif
38584 }
38585 #ifdef ROCKET_DEBUG_OPEN
38586- printk(KERN_INFO "rp_open ttyR%d, count=%d\n", info->line, info->port.count);
38587+ printk(KERN_INFO "rp_open ttyR%d, count=%d\n", info->line, atomic-read(&info->port.count));
38588 #endif
38589
38590 /*
38591@@ -1528,7 +1528,7 @@ static void rp_hangup(struct tty_struct *tty)
38592 spin_unlock_irqrestore(&info->port.lock, flags);
38593 return;
38594 }
38595- if (info->port.count)
38596+ if (atomic_read(&info->port.count))
38597 atomic_dec(&rp_num_ports_open);
38598 clear_bit((info->aiop * 8) + info->chan, (void *) &xmit_flags[info->board]);
38599 spin_unlock_irqrestore(&info->port.lock, flags);
38600diff --git a/drivers/tty/serial/kgdboc.c b/drivers/tty/serial/kgdboc.c
38601index 2b42a01..32a2ed3 100644
38602--- a/drivers/tty/serial/kgdboc.c
38603+++ b/drivers/tty/serial/kgdboc.c
38604@@ -24,8 +24,9 @@
38605 #define MAX_CONFIG_LEN 40
38606
38607 static struct kgdb_io kgdboc_io_ops;
38608+static struct kgdb_io kgdboc_io_ops_console;
38609
38610-/* -1 = init not run yet, 0 = unconfigured, 1 = configured. */
38611+/* -1 = init not run yet, 0 = unconfigured, 1/2 = configured. */
38612 static int configured = -1;
38613
38614 static char config[MAX_CONFIG_LEN];
38615@@ -148,6 +149,8 @@ static void cleanup_kgdboc(void)
38616 kgdboc_unregister_kbd();
38617 if (configured == 1)
38618 kgdb_unregister_io_module(&kgdboc_io_ops);
38619+ else if (configured == 2)
38620+ kgdb_unregister_io_module(&kgdboc_io_ops_console);
38621 }
38622
38623 static int configure_kgdboc(void)
38624@@ -157,13 +160,13 @@ static int configure_kgdboc(void)
38625 int err;
38626 char *cptr = config;
38627 struct console *cons;
38628+ int is_console = 0;
38629
38630 err = kgdboc_option_setup(config);
38631 if (err || !strlen(config) || isspace(config[0]))
38632 goto noconfig;
38633
38634 err = -ENODEV;
38635- kgdboc_io_ops.is_console = 0;
38636 kgdb_tty_driver = NULL;
38637
38638 kgdboc_use_kms = 0;
38639@@ -184,7 +187,7 @@ static int configure_kgdboc(void)
38640 int idx;
38641 if (cons->device && cons->device(cons, &idx) == p &&
38642 idx == tty_line) {
38643- kgdboc_io_ops.is_console = 1;
38644+ is_console = 1;
38645 break;
38646 }
38647 cons = cons->next;
38648@@ -194,12 +197,16 @@ static int configure_kgdboc(void)
38649 kgdb_tty_line = tty_line;
38650
38651 do_register:
38652- err = kgdb_register_io_module(&kgdboc_io_ops);
38653+ if (is_console) {
38654+ err = kgdb_register_io_module(&kgdboc_io_ops_console);
38655+ configured = 2;
38656+ } else {
38657+ err = kgdb_register_io_module(&kgdboc_io_ops);
38658+ configured = 1;
38659+ }
38660 if (err)
38661 goto noconfig;
38662
38663- configured = 1;
38664-
38665 return 0;
38666
38667 noconfig:
38668@@ -213,7 +220,7 @@ noconfig:
38669 static int __init init_kgdboc(void)
38670 {
38671 /* Already configured? */
38672- if (configured == 1)
38673+ if (configured >= 1)
38674 return 0;
38675
38676 return configure_kgdboc();
38677@@ -262,7 +269,7 @@ static int param_set_kgdboc_var(const char *kmessage, struct kernel_param *kp)
38678 if (config[len - 1] == '\n')
38679 config[len - 1] = '\0';
38680
38681- if (configured == 1)
38682+ if (configured >= 1)
38683 cleanup_kgdboc();
38684
38685 /* Go and configure with the new params. */
38686@@ -302,6 +309,15 @@ static struct kgdb_io kgdboc_io_ops = {
38687 .post_exception = kgdboc_post_exp_handler,
38688 };
38689
38690+static struct kgdb_io kgdboc_io_ops_console = {
38691+ .name = "kgdboc",
38692+ .read_char = kgdboc_get_char,
38693+ .write_char = kgdboc_put_char,
38694+ .pre_exception = kgdboc_pre_exp_handler,
38695+ .post_exception = kgdboc_post_exp_handler,
38696+ .is_console = 1
38697+};
38698+
38699 #ifdef CONFIG_KGDB_SERIAL_CONSOLE
38700 /* This is only available if kgdboc is a built in for early debugging */
38701 static int __init kgdboc_early_init(char *opt)
38702diff --git a/drivers/tty/serial/serial_core.c b/drivers/tty/serial/serial_core.c
38703index a21dc8e..fe43e9e 100644
38704--- a/drivers/tty/serial/serial_core.c
38705+++ b/drivers/tty/serial/serial_core.c
38706@@ -1392,7 +1392,7 @@ static void uart_hangup(struct tty_struct *tty)
38707 uart_flush_buffer(tty);
38708 uart_shutdown(tty, state);
38709 spin_lock_irqsave(&port->lock, flags);
38710- port->count = 0;
38711+ atomic_set(&port->count, 0);
38712 clear_bit(ASYNCB_NORMAL_ACTIVE, &port->flags);
38713 spin_unlock_irqrestore(&port->lock, flags);
38714 tty_port_tty_set(port, NULL);
38715@@ -1488,7 +1488,7 @@ static int uart_open(struct tty_struct *tty, struct file *filp)
38716 goto end;
38717 }
38718
38719- port->count++;
38720+ atomic_inc(&port->count);
38721 if (!state->uart_port || state->uart_port->flags & UPF_DEAD) {
38722 retval = -ENXIO;
38723 goto err_dec_count;
38724@@ -1515,7 +1515,7 @@ static int uart_open(struct tty_struct *tty, struct file *filp)
38725 /*
38726 * Make sure the device is in D0 state.
38727 */
38728- if (port->count == 1)
38729+ if (atomic_read(&port->count) == 1)
38730 uart_change_pm(state, 0);
38731
38732 /*
38733@@ -1533,7 +1533,7 @@ static int uart_open(struct tty_struct *tty, struct file *filp)
38734 end:
38735 return retval;
38736 err_dec_count:
38737- port->count--;
38738+ atomic_inc(&port->count);
38739 mutex_unlock(&port->mutex);
38740 goto end;
38741 }
38742diff --git a/drivers/tty/synclink.c b/drivers/tty/synclink.c
38743index 593d40a..bdc61f3 100644
38744--- a/drivers/tty/synclink.c
38745+++ b/drivers/tty/synclink.c
38746@@ -3095,7 +3095,7 @@ static void mgsl_close(struct tty_struct *tty, struct file * filp)
38747
38748 if (debug_level >= DEBUG_LEVEL_INFO)
38749 printk("%s(%d):mgsl_close(%s) entry, count=%d\n",
38750- __FILE__,__LINE__, info->device_name, info->port.count);
38751+ __FILE__,__LINE__, info->device_name, atomic_read(&info->port.count));
38752
38753 if (tty_port_close_start(&info->port, tty, filp) == 0)
38754 goto cleanup;
38755@@ -3113,7 +3113,7 @@ static void mgsl_close(struct tty_struct *tty, struct file * filp)
38756 cleanup:
38757 if (debug_level >= DEBUG_LEVEL_INFO)
38758 printk("%s(%d):mgsl_close(%s) exit, count=%d\n", __FILE__,__LINE__,
38759- tty->driver->name, info->port.count);
38760+ tty->driver->name, atomic_read(&info->port.count));
38761
38762 } /* end of mgsl_close() */
38763
38764@@ -3212,8 +3212,8 @@ static void mgsl_hangup(struct tty_struct *tty)
38765
38766 mgsl_flush_buffer(tty);
38767 shutdown(info);
38768-
38769- info->port.count = 0;
38770+
38771+ atomic_set(&info->port.count, 0);
38772 info->port.flags &= ~ASYNC_NORMAL_ACTIVE;
38773 info->port.tty = NULL;
38774
38775@@ -3302,12 +3302,12 @@ static int block_til_ready(struct tty_struct *tty, struct file * filp,
38776
38777 if (debug_level >= DEBUG_LEVEL_INFO)
38778 printk("%s(%d):block_til_ready before block on %s count=%d\n",
38779- __FILE__,__LINE__, tty->driver->name, port->count );
38780+ __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
38781
38782 spin_lock_irqsave(&info->irq_spinlock, flags);
38783 if (!tty_hung_up_p(filp)) {
38784 extra_count = true;
38785- port->count--;
38786+ atomic_dec(&port->count);
38787 }
38788 spin_unlock_irqrestore(&info->irq_spinlock, flags);
38789 port->blocked_open++;
38790@@ -3336,7 +3336,7 @@ static int block_til_ready(struct tty_struct *tty, struct file * filp,
38791
38792 if (debug_level >= DEBUG_LEVEL_INFO)
38793 printk("%s(%d):block_til_ready blocking on %s count=%d\n",
38794- __FILE__,__LINE__, tty->driver->name, port->count );
38795+ __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
38796
38797 tty_unlock();
38798 schedule();
38799@@ -3348,12 +3348,12 @@ static int block_til_ready(struct tty_struct *tty, struct file * filp,
38800
38801 /* FIXME: Racy on hangup during close wait */
38802 if (extra_count)
38803- port->count++;
38804+ atomic_inc(&port->count);
38805 port->blocked_open--;
38806
38807 if (debug_level >= DEBUG_LEVEL_INFO)
38808 printk("%s(%d):block_til_ready after blocking on %s count=%d\n",
38809- __FILE__,__LINE__, tty->driver->name, port->count );
38810+ __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
38811
38812 if (!retval)
38813 port->flags |= ASYNC_NORMAL_ACTIVE;
38814@@ -3398,7 +3398,7 @@ static int mgsl_open(struct tty_struct *tty, struct file * filp)
38815
38816 if (debug_level >= DEBUG_LEVEL_INFO)
38817 printk("%s(%d):mgsl_open(%s), old ref count = %d\n",
38818- __FILE__,__LINE__,tty->driver->name, info->port.count);
38819+ __FILE__,__LINE__,tty->driver->name, atomic_read(&info->port.count));
38820
38821 /* If port is closing, signal caller to try again */
38822 if (tty_hung_up_p(filp) || info->port.flags & ASYNC_CLOSING){
38823@@ -3417,10 +3417,10 @@ static int mgsl_open(struct tty_struct *tty, struct file * filp)
38824 spin_unlock_irqrestore(&info->netlock, flags);
38825 goto cleanup;
38826 }
38827- info->port.count++;
38828+ atomic_inc(&info->port.count);
38829 spin_unlock_irqrestore(&info->netlock, flags);
38830
38831- if (info->port.count == 1) {
38832+ if (atomic_read(&info->port.count) == 1) {
38833 /* 1st open on this device, init hardware */
38834 retval = startup(info);
38835 if (retval < 0)
38836@@ -3444,8 +3444,8 @@ cleanup:
38837 if (retval) {
38838 if (tty->count == 1)
38839 info->port.tty = NULL; /* tty layer will release tty struct */
38840- if(info->port.count)
38841- info->port.count--;
38842+ if (atomic_read(&info->port.count))
38843+ atomic_dec(&info->port.count);
38844 }
38845
38846 return retval;
38847@@ -7653,7 +7653,7 @@ static int hdlcdev_attach(struct net_device *dev, unsigned short encoding,
38848 unsigned short new_crctype;
38849
38850 /* return error if TTY interface open */
38851- if (info->port.count)
38852+ if (atomic_read(&info->port.count))
38853 return -EBUSY;
38854
38855 switch (encoding)
38856@@ -7748,7 +7748,7 @@ static int hdlcdev_open(struct net_device *dev)
38857
38858 /* arbitrate between network and tty opens */
38859 spin_lock_irqsave(&info->netlock, flags);
38860- if (info->port.count != 0 || info->netcount != 0) {
38861+ if (atomic_read(&info->port.count) != 0 || info->netcount != 0) {
38862 printk(KERN_WARNING "%s: hdlc_open returning busy\n", dev->name);
38863 spin_unlock_irqrestore(&info->netlock, flags);
38864 return -EBUSY;
38865@@ -7834,7 +7834,7 @@ static int hdlcdev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
38866 printk("%s:hdlcdev_ioctl(%s)\n",__FILE__,dev->name);
38867
38868 /* return error if TTY interface open */
38869- if (info->port.count)
38870+ if (atomic_read(&info->port.count))
38871 return -EBUSY;
38872
38873 if (cmd != SIOCWANDEV)
38874diff --git a/drivers/tty/synclink_gt.c b/drivers/tty/synclink_gt.c
38875index aa1debf..9297a16 100644
38876--- a/drivers/tty/synclink_gt.c
38877+++ b/drivers/tty/synclink_gt.c
38878@@ -671,7 +671,7 @@ static int open(struct tty_struct *tty, struct file *filp)
38879 tty->driver_data = info;
38880 info->port.tty = tty;
38881
38882- DBGINFO(("%s open, old ref count = %d\n", info->device_name, info->port.count));
38883+ DBGINFO(("%s open, old ref count = %d\n", info->device_name, atomic_read(&info->port.count)));
38884
38885 /* If port is closing, signal caller to try again */
38886 if (tty_hung_up_p(filp) || info->port.flags & ASYNC_CLOSING){
38887@@ -692,10 +692,10 @@ static int open(struct tty_struct *tty, struct file *filp)
38888 mutex_unlock(&info->port.mutex);
38889 goto cleanup;
38890 }
38891- info->port.count++;
38892+ atomic_inc(&info->port.count);
38893 spin_unlock_irqrestore(&info->netlock, flags);
38894
38895- if (info->port.count == 1) {
38896+ if (atomic_read(&info->port.count) == 1) {
38897 /* 1st open on this device, init hardware */
38898 retval = startup(info);
38899 if (retval < 0) {
38900@@ -716,8 +716,8 @@ cleanup:
38901 if (retval) {
38902 if (tty->count == 1)
38903 info->port.tty = NULL; /* tty layer will release tty struct */
38904- if(info->port.count)
38905- info->port.count--;
38906+ if(atomic_read(&info->port.count))
38907+ atomic_dec(&info->port.count);
38908 }
38909
38910 DBGINFO(("%s open rc=%d\n", info->device_name, retval));
38911@@ -730,7 +730,7 @@ static void close(struct tty_struct *tty, struct file *filp)
38912
38913 if (sanity_check(info, tty->name, "close"))
38914 return;
38915- DBGINFO(("%s close entry, count=%d\n", info->device_name, info->port.count));
38916+ DBGINFO(("%s close entry, count=%d\n", info->device_name, atomic_read(&info->port.count)));
38917
38918 if (tty_port_close_start(&info->port, tty, filp) == 0)
38919 goto cleanup;
38920@@ -747,7 +747,7 @@ static void close(struct tty_struct *tty, struct file *filp)
38921 tty_port_close_end(&info->port, tty);
38922 info->port.tty = NULL;
38923 cleanup:
38924- DBGINFO(("%s close exit, count=%d\n", tty->driver->name, info->port.count));
38925+ DBGINFO(("%s close exit, count=%d\n", tty->driver->name, atomic_read(&info->port.count)));
38926 }
38927
38928 static void hangup(struct tty_struct *tty)
38929@@ -765,7 +765,7 @@ static void hangup(struct tty_struct *tty)
38930 shutdown(info);
38931
38932 spin_lock_irqsave(&info->port.lock, flags);
38933- info->port.count = 0;
38934+ atomic_set(&info->port.count, 0);
38935 info->port.flags &= ~ASYNC_NORMAL_ACTIVE;
38936 info->port.tty = NULL;
38937 spin_unlock_irqrestore(&info->port.lock, flags);
38938@@ -1450,7 +1450,7 @@ static int hdlcdev_attach(struct net_device *dev, unsigned short encoding,
38939 unsigned short new_crctype;
38940
38941 /* return error if TTY interface open */
38942- if (info->port.count)
38943+ if (atomic_read(&info->port.count))
38944 return -EBUSY;
38945
38946 DBGINFO(("%s hdlcdev_attach\n", info->device_name));
38947@@ -1545,7 +1545,7 @@ static int hdlcdev_open(struct net_device *dev)
38948
38949 /* arbitrate between network and tty opens */
38950 spin_lock_irqsave(&info->netlock, flags);
38951- if (info->port.count != 0 || info->netcount != 0) {
38952+ if (atomic_read(&info->port.count) != 0 || info->netcount != 0) {
38953 DBGINFO(("%s hdlc_open busy\n", dev->name));
38954 spin_unlock_irqrestore(&info->netlock, flags);
38955 return -EBUSY;
38956@@ -1630,7 +1630,7 @@ static int hdlcdev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
38957 DBGINFO(("%s hdlcdev_ioctl\n", dev->name));
38958
38959 /* return error if TTY interface open */
38960- if (info->port.count)
38961+ if (atomic_read(&info->port.count))
38962 return -EBUSY;
38963
38964 if (cmd != SIOCWANDEV)
38965@@ -2419,7 +2419,7 @@ static irqreturn_t slgt_interrupt(int dummy, void *dev_id)
38966 if (port == NULL)
38967 continue;
38968 spin_lock(&port->lock);
38969- if ((port->port.count || port->netcount) &&
38970+ if ((atomic_read(&port->port.count) || port->netcount) &&
38971 port->pending_bh && !port->bh_running &&
38972 !port->bh_requested) {
38973 DBGISR(("%s bh queued\n", port->device_name));
38974@@ -3308,7 +3308,7 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
38975 spin_lock_irqsave(&info->lock, flags);
38976 if (!tty_hung_up_p(filp)) {
38977 extra_count = true;
38978- port->count--;
38979+ atomic_dec(&port->count);
38980 }
38981 spin_unlock_irqrestore(&info->lock, flags);
38982 port->blocked_open++;
38983@@ -3345,7 +3345,7 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
38984 remove_wait_queue(&port->open_wait, &wait);
38985
38986 if (extra_count)
38987- port->count++;
38988+ atomic_inc(&port->count);
38989 port->blocked_open--;
38990
38991 if (!retval)
38992diff --git a/drivers/tty/synclinkmp.c b/drivers/tty/synclinkmp.c
38993index a3dddc1..8905ab2 100644
38994--- a/drivers/tty/synclinkmp.c
38995+++ b/drivers/tty/synclinkmp.c
38996@@ -742,7 +742,7 @@ static int open(struct tty_struct *tty, struct file *filp)
38997
38998 if (debug_level >= DEBUG_LEVEL_INFO)
38999 printk("%s(%d):%s open(), old ref count = %d\n",
39000- __FILE__,__LINE__,tty->driver->name, info->port.count);
39001+ __FILE__,__LINE__,tty->driver->name, atomic_read(&info->port.count));
39002
39003 /* If port is closing, signal caller to try again */
39004 if (tty_hung_up_p(filp) || info->port.flags & ASYNC_CLOSING){
39005@@ -761,10 +761,10 @@ static int open(struct tty_struct *tty, struct file *filp)
39006 spin_unlock_irqrestore(&info->netlock, flags);
39007 goto cleanup;
39008 }
39009- info->port.count++;
39010+ atomic_inc(&info->port.count);
39011 spin_unlock_irqrestore(&info->netlock, flags);
39012
39013- if (info->port.count == 1) {
39014+ if (atomic_read(&info->port.count) == 1) {
39015 /* 1st open on this device, init hardware */
39016 retval = startup(info);
39017 if (retval < 0)
39018@@ -788,8 +788,8 @@ cleanup:
39019 if (retval) {
39020 if (tty->count == 1)
39021 info->port.tty = NULL; /* tty layer will release tty struct */
39022- if(info->port.count)
39023- info->port.count--;
39024+ if(atomic_read(&info->port.count))
39025+ atomic_dec(&info->port.count);
39026 }
39027
39028 return retval;
39029@@ -807,7 +807,7 @@ static void close(struct tty_struct *tty, struct file *filp)
39030
39031 if (debug_level >= DEBUG_LEVEL_INFO)
39032 printk("%s(%d):%s close() entry, count=%d\n",
39033- __FILE__,__LINE__, info->device_name, info->port.count);
39034+ __FILE__,__LINE__, info->device_name, atomic_read(&info->port.count));
39035
39036 if (tty_port_close_start(&info->port, tty, filp) == 0)
39037 goto cleanup;
39038@@ -826,7 +826,7 @@ static void close(struct tty_struct *tty, struct file *filp)
39039 cleanup:
39040 if (debug_level >= DEBUG_LEVEL_INFO)
39041 printk("%s(%d):%s close() exit, count=%d\n", __FILE__,__LINE__,
39042- tty->driver->name, info->port.count);
39043+ tty->driver->name, atomic_read(&info->port.count));
39044 }
39045
39046 /* Called by tty_hangup() when a hangup is signaled.
39047@@ -849,7 +849,7 @@ static void hangup(struct tty_struct *tty)
39048 shutdown(info);
39049
39050 spin_lock_irqsave(&info->port.lock, flags);
39051- info->port.count = 0;
39052+ atomic_set(&info->port.count, 0);
39053 info->port.flags &= ~ASYNC_NORMAL_ACTIVE;
39054 info->port.tty = NULL;
39055 spin_unlock_irqrestore(&info->port.lock, flags);
39056@@ -1557,7 +1557,7 @@ static int hdlcdev_attach(struct net_device *dev, unsigned short encoding,
39057 unsigned short new_crctype;
39058
39059 /* return error if TTY interface open */
39060- if (info->port.count)
39061+ if (atomic_read(&info->port.count))
39062 return -EBUSY;
39063
39064 switch (encoding)
39065@@ -1652,7 +1652,7 @@ static int hdlcdev_open(struct net_device *dev)
39066
39067 /* arbitrate between network and tty opens */
39068 spin_lock_irqsave(&info->netlock, flags);
39069- if (info->port.count != 0 || info->netcount != 0) {
39070+ if (atomic_read(&info->port.count) != 0 || info->netcount != 0) {
39071 printk(KERN_WARNING "%s: hdlc_open returning busy\n", dev->name);
39072 spin_unlock_irqrestore(&info->netlock, flags);
39073 return -EBUSY;
39074@@ -1738,7 +1738,7 @@ static int hdlcdev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
39075 printk("%s:hdlcdev_ioctl(%s)\n",__FILE__,dev->name);
39076
39077 /* return error if TTY interface open */
39078- if (info->port.count)
39079+ if (atomic_read(&info->port.count))
39080 return -EBUSY;
39081
39082 if (cmd != SIOCWANDEV)
39083@@ -2623,7 +2623,7 @@ static irqreturn_t synclinkmp_interrupt(int dummy, void *dev_id)
39084 * do not request bottom half processing if the
39085 * device is not open in a normal mode.
39086 */
39087- if ( port && (port->port.count || port->netcount) &&
39088+ if ( port && (atomic_read(&port->port.count) || port->netcount) &&
39089 port->pending_bh && !port->bh_running &&
39090 !port->bh_requested ) {
39091 if ( debug_level >= DEBUG_LEVEL_ISR )
39092@@ -3321,12 +3321,12 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
39093
39094 if (debug_level >= DEBUG_LEVEL_INFO)
39095 printk("%s(%d):%s block_til_ready() before block, count=%d\n",
39096- __FILE__,__LINE__, tty->driver->name, port->count );
39097+ __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
39098
39099 spin_lock_irqsave(&info->lock, flags);
39100 if (!tty_hung_up_p(filp)) {
39101 extra_count = true;
39102- port->count--;
39103+ atomic_dec(&port->count);
39104 }
39105 spin_unlock_irqrestore(&info->lock, flags);
39106 port->blocked_open++;
39107@@ -3355,7 +3355,7 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
39108
39109 if (debug_level >= DEBUG_LEVEL_INFO)
39110 printk("%s(%d):%s block_til_ready() count=%d\n",
39111- __FILE__,__LINE__, tty->driver->name, port->count );
39112+ __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
39113
39114 tty_unlock();
39115 schedule();
39116@@ -3366,12 +3366,12 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
39117 remove_wait_queue(&port->open_wait, &wait);
39118
39119 if (extra_count)
39120- port->count++;
39121+ atomic_inc(&port->count);
39122 port->blocked_open--;
39123
39124 if (debug_level >= DEBUG_LEVEL_INFO)
39125 printk("%s(%d):%s block_til_ready() after, count=%d\n",
39126- __FILE__,__LINE__, tty->driver->name, port->count );
39127+ __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
39128
39129 if (!retval)
39130 port->flags |= ASYNC_NORMAL_ACTIVE;
39131diff --git a/drivers/tty/sysrq.c b/drivers/tty/sysrq.c
39132index 05728894..b9d44c6 100644
39133--- a/drivers/tty/sysrq.c
39134+++ b/drivers/tty/sysrq.c
39135@@ -865,7 +865,7 @@ EXPORT_SYMBOL(unregister_sysrq_key);
39136 static ssize_t write_sysrq_trigger(struct file *file, const char __user *buf,
39137 size_t count, loff_t *ppos)
39138 {
39139- if (count) {
39140+ if (count && capable(CAP_SYS_ADMIN)) {
39141 char c;
39142
39143 if (get_user(c, buf))
39144diff --git a/drivers/tty/tty_io.c b/drivers/tty/tty_io.c
39145index b425c79..08a3f06 100644
39146--- a/drivers/tty/tty_io.c
39147+++ b/drivers/tty/tty_io.c
39148@@ -3283,7 +3283,7 @@ EXPORT_SYMBOL_GPL(get_current_tty);
39149
39150 void tty_default_fops(struct file_operations *fops)
39151 {
39152- *fops = tty_fops;
39153+ memcpy((void *)fops, &tty_fops, sizeof(tty_fops));
39154 }
39155
39156 /*
39157diff --git a/drivers/tty/tty_ldisc.c b/drivers/tty/tty_ldisc.c
39158index 6f99c99..8947bc4 100644
39159--- a/drivers/tty/tty_ldisc.c
39160+++ b/drivers/tty/tty_ldisc.c
39161@@ -56,7 +56,7 @@ static void put_ldisc(struct tty_ldisc *ld)
39162 if (atomic_dec_and_lock(&ld->users, &tty_ldisc_lock)) {
39163 struct tty_ldisc_ops *ldo = ld->ops;
39164
39165- ldo->refcount--;
39166+ atomic_dec(&ldo->refcount);
39167 module_put(ldo->owner);
39168 spin_unlock_irqrestore(&tty_ldisc_lock, flags);
39169
39170@@ -91,7 +91,7 @@ int tty_register_ldisc(int disc, struct tty_ldisc_ops *new_ldisc)
39171 spin_lock_irqsave(&tty_ldisc_lock, flags);
39172 tty_ldiscs[disc] = new_ldisc;
39173 new_ldisc->num = disc;
39174- new_ldisc->refcount = 0;
39175+ atomic_set(&new_ldisc->refcount, 0);
39176 spin_unlock_irqrestore(&tty_ldisc_lock, flags);
39177
39178 return ret;
39179@@ -119,7 +119,7 @@ int tty_unregister_ldisc(int disc)
39180 return -EINVAL;
39181
39182 spin_lock_irqsave(&tty_ldisc_lock, flags);
39183- if (tty_ldiscs[disc]->refcount)
39184+ if (atomic_read(&tty_ldiscs[disc]->refcount))
39185 ret = -EBUSY;
39186 else
39187 tty_ldiscs[disc] = NULL;
39188@@ -140,7 +140,7 @@ static struct tty_ldisc_ops *get_ldops(int disc)
39189 if (ldops) {
39190 ret = ERR_PTR(-EAGAIN);
39191 if (try_module_get(ldops->owner)) {
39192- ldops->refcount++;
39193+ atomic_inc(&ldops->refcount);
39194 ret = ldops;
39195 }
39196 }
39197@@ -153,7 +153,7 @@ static void put_ldops(struct tty_ldisc_ops *ldops)
39198 unsigned long flags;
39199
39200 spin_lock_irqsave(&tty_ldisc_lock, flags);
39201- ldops->refcount--;
39202+ atomic_dec(&ldops->refcount);
39203 module_put(ldops->owner);
39204 spin_unlock_irqrestore(&tty_ldisc_lock, flags);
39205 }
39206diff --git a/drivers/tty/tty_port.c b/drivers/tty/tty_port.c
39207index bf6e238..d401c04 100644
39208--- a/drivers/tty/tty_port.c
39209+++ b/drivers/tty/tty_port.c
39210@@ -138,7 +138,7 @@ void tty_port_hangup(struct tty_port *port)
39211 unsigned long flags;
39212
39213 spin_lock_irqsave(&port->lock, flags);
39214- port->count = 0;
39215+ atomic_set(&port->count, 0);
39216 port->flags &= ~ASYNC_NORMAL_ACTIVE;
39217 if (port->tty) {
39218 set_bit(TTY_IO_ERROR, &port->tty->flags);
39219@@ -264,7 +264,7 @@ int tty_port_block_til_ready(struct tty_port *port,
39220 /* The port lock protects the port counts */
39221 spin_lock_irqsave(&port->lock, flags);
39222 if (!tty_hung_up_p(filp))
39223- port->count--;
39224+ atomic_dec(&port->count);
39225 port->blocked_open++;
39226 spin_unlock_irqrestore(&port->lock, flags);
39227
39228@@ -306,7 +306,7 @@ int tty_port_block_til_ready(struct tty_port *port,
39229 we must not mess that up further */
39230 spin_lock_irqsave(&port->lock, flags);
39231 if (!tty_hung_up_p(filp))
39232- port->count++;
39233+ atomic_inc(&port->count);
39234 port->blocked_open--;
39235 if (retval == 0)
39236 port->flags |= ASYNC_NORMAL_ACTIVE;
39237@@ -326,19 +326,19 @@ int tty_port_close_start(struct tty_port *port,
39238 return 0;
39239 }
39240
39241- if (tty->count == 1 && port->count != 1) {
39242+ if (tty->count == 1 && atomic_read(&port->count) != 1) {
39243 printk(KERN_WARNING
39244 "tty_port_close_start: tty->count = 1 port count = %d.\n",
39245- port->count);
39246- port->count = 1;
39247+ atomic_read(&port->count));
39248+ atomic_set(&port->count, 1);
39249 }
39250- if (--port->count < 0) {
39251+ if (atomic_dec_return(&port->count) < 0) {
39252 printk(KERN_WARNING "tty_port_close_start: count = %d\n",
39253- port->count);
39254- port->count = 0;
39255+ atomic_read(&port->count));
39256+ atomic_set(&port->count, 0);
39257 }
39258
39259- if (port->count) {
39260+ if (atomic_read(&port->count)) {
39261 spin_unlock_irqrestore(&port->lock, flags);
39262 if (port->ops->drop)
39263 port->ops->drop(port);
39264@@ -418,7 +418,7 @@ int tty_port_open(struct tty_port *port, struct tty_struct *tty,
39265 {
39266 spin_lock_irq(&port->lock);
39267 if (!tty_hung_up_p(filp))
39268- ++port->count;
39269+ atomic_inc(&port->count);
39270 spin_unlock_irq(&port->lock);
39271 tty_port_tty_set(port, tty);
39272
39273diff --git a/drivers/tty/vt/keyboard.c b/drivers/tty/vt/keyboard.c
39274index 770a854..e5d3db3 100644
39275--- a/drivers/tty/vt/keyboard.c
39276+++ b/drivers/tty/vt/keyboard.c
39277@@ -659,6 +659,16 @@ static void k_spec(struct vc_data *vc, unsigned char value, char up_flag)
39278 kbd->kbdmode == VC_OFF) &&
39279 value != KVAL(K_SAK))
39280 return; /* SAK is allowed even in raw mode */
39281+
39282+#if defined(CONFIG_GRKERNSEC_PROC) || defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
39283+ {
39284+ void *func = fn_handler[value];
39285+ if (func == fn_show_state || func == fn_show_ptregs ||
39286+ func == fn_show_mem)
39287+ return;
39288+ }
39289+#endif
39290+
39291 fn_handler[value](vc);
39292 }
39293
39294@@ -1805,9 +1815,6 @@ int vt_do_kdsk_ioctl(int cmd, struct kbentry __user *user_kbe, int perm,
39295 if (copy_from_user(&tmp, user_kbe, sizeof(struct kbentry)))
39296 return -EFAULT;
39297
39298- if (!capable(CAP_SYS_TTY_CONFIG))
39299- perm = 0;
39300-
39301 switch (cmd) {
39302 case KDGKBENT:
39303 /* Ensure another thread doesn't free it under us */
39304@@ -1822,6 +1829,9 @@ int vt_do_kdsk_ioctl(int cmd, struct kbentry __user *user_kbe, int perm,
39305 spin_unlock_irqrestore(&kbd_event_lock, flags);
39306 return put_user(val, &user_kbe->kb_value);
39307 case KDSKBENT:
39308+ if (!capable(CAP_SYS_TTY_CONFIG))
39309+ perm = 0;
39310+
39311 if (!perm)
39312 return -EPERM;
39313 if (!i && v == K_NOSUCHMAP) {
39314@@ -1912,9 +1922,6 @@ int vt_do_kdgkb_ioctl(int cmd, struct kbsentry __user *user_kdgkb, int perm)
39315 int i, j, k;
39316 int ret;
39317
39318- if (!capable(CAP_SYS_TTY_CONFIG))
39319- perm = 0;
39320-
39321 kbs = kmalloc(sizeof(*kbs), GFP_KERNEL);
39322 if (!kbs) {
39323 ret = -ENOMEM;
39324@@ -1948,6 +1955,9 @@ int vt_do_kdgkb_ioctl(int cmd, struct kbsentry __user *user_kdgkb, int perm)
39325 kfree(kbs);
39326 return ((p && *p) ? -EOVERFLOW : 0);
39327 case KDSKBSENT:
39328+ if (!capable(CAP_SYS_TTY_CONFIG))
39329+ perm = 0;
39330+
39331 if (!perm) {
39332 ret = -EPERM;
39333 goto reterr;
39334diff --git a/drivers/uio/uio.c b/drivers/uio/uio.c
39335index a783d53..cb30d94 100644
39336--- a/drivers/uio/uio.c
39337+++ b/drivers/uio/uio.c
39338@@ -25,6 +25,7 @@
39339 #include <linux/kobject.h>
39340 #include <linux/cdev.h>
39341 #include <linux/uio_driver.h>
39342+#include <asm/local.h>
39343
39344 #define UIO_MAX_DEVICES (1U << MINORBITS)
39345
39346@@ -32,10 +33,10 @@ struct uio_device {
39347 struct module *owner;
39348 struct device *dev;
39349 int minor;
39350- atomic_t event;
39351+ atomic_unchecked_t event;
39352 struct fasync_struct *async_queue;
39353 wait_queue_head_t wait;
39354- int vma_count;
39355+ local_t vma_count;
39356 struct uio_info *info;
39357 struct kobject *map_dir;
39358 struct kobject *portio_dir;
39359@@ -242,7 +243,7 @@ static ssize_t show_event(struct device *dev,
39360 struct device_attribute *attr, char *buf)
39361 {
39362 struct uio_device *idev = dev_get_drvdata(dev);
39363- return sprintf(buf, "%u\n", (unsigned int)atomic_read(&idev->event));
39364+ return sprintf(buf, "%u\n", (unsigned int)atomic_read_unchecked(&idev->event));
39365 }
39366
39367 static struct device_attribute uio_class_attributes[] = {
39368@@ -408,7 +409,7 @@ void uio_event_notify(struct uio_info *info)
39369 {
39370 struct uio_device *idev = info->uio_dev;
39371
39372- atomic_inc(&idev->event);
39373+ atomic_inc_unchecked(&idev->event);
39374 wake_up_interruptible(&idev->wait);
39375 kill_fasync(&idev->async_queue, SIGIO, POLL_IN);
39376 }
39377@@ -461,7 +462,7 @@ static int uio_open(struct inode *inode, struct file *filep)
39378 }
39379
39380 listener->dev = idev;
39381- listener->event_count = atomic_read(&idev->event);
39382+ listener->event_count = atomic_read_unchecked(&idev->event);
39383 filep->private_data = listener;
39384
39385 if (idev->info->open) {
39386@@ -512,7 +513,7 @@ static unsigned int uio_poll(struct file *filep, poll_table *wait)
39387 return -EIO;
39388
39389 poll_wait(filep, &idev->wait, wait);
39390- if (listener->event_count != atomic_read(&idev->event))
39391+ if (listener->event_count != atomic_read_unchecked(&idev->event))
39392 return POLLIN | POLLRDNORM;
39393 return 0;
39394 }
39395@@ -537,7 +538,7 @@ static ssize_t uio_read(struct file *filep, char __user *buf,
39396 do {
39397 set_current_state(TASK_INTERRUPTIBLE);
39398
39399- event_count = atomic_read(&idev->event);
39400+ event_count = atomic_read_unchecked(&idev->event);
39401 if (event_count != listener->event_count) {
39402 if (copy_to_user(buf, &event_count, count))
39403 retval = -EFAULT;
39404@@ -606,13 +607,13 @@ static int uio_find_mem_index(struct vm_area_struct *vma)
39405 static void uio_vma_open(struct vm_area_struct *vma)
39406 {
39407 struct uio_device *idev = vma->vm_private_data;
39408- idev->vma_count++;
39409+ local_inc(&idev->vma_count);
39410 }
39411
39412 static void uio_vma_close(struct vm_area_struct *vma)
39413 {
39414 struct uio_device *idev = vma->vm_private_data;
39415- idev->vma_count--;
39416+ local_dec(&idev->vma_count);
39417 }
39418
39419 static int uio_vma_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
39420@@ -821,7 +822,7 @@ int __uio_register_device(struct module *owner,
39421 idev->owner = owner;
39422 idev->info = info;
39423 init_waitqueue_head(&idev->wait);
39424- atomic_set(&idev->event, 0);
39425+ atomic_set_unchecked(&idev->event, 0);
39426
39427 ret = uio_get_minor(idev);
39428 if (ret)
39429diff --git a/drivers/usb/atm/cxacru.c b/drivers/usb/atm/cxacru.c
39430index b7eb86a..36d28af 100644
39431--- a/drivers/usb/atm/cxacru.c
39432+++ b/drivers/usb/atm/cxacru.c
39433@@ -473,7 +473,7 @@ static ssize_t cxacru_sysfs_store_adsl_config(struct device *dev,
39434 ret = sscanf(buf + pos, "%x=%x%n", &index, &value, &tmp);
39435 if (ret < 2)
39436 return -EINVAL;
39437- if (index < 0 || index > 0x7f)
39438+ if (index > 0x7f)
39439 return -EINVAL;
39440 pos += tmp;
39441
39442diff --git a/drivers/usb/atm/usbatm.c b/drivers/usb/atm/usbatm.c
39443index ee62b35..b663594 100644
39444--- a/drivers/usb/atm/usbatm.c
39445+++ b/drivers/usb/atm/usbatm.c
39446@@ -333,7 +333,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
39447 if (printk_ratelimit())
39448 atm_warn(instance, "%s: OAM not supported (vpi %d, vci %d)!\n",
39449 __func__, vpi, vci);
39450- atomic_inc(&vcc->stats->rx_err);
39451+ atomic_inc_unchecked(&vcc->stats->rx_err);
39452 return;
39453 }
39454
39455@@ -361,7 +361,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
39456 if (length > ATM_MAX_AAL5_PDU) {
39457 atm_rldbg(instance, "%s: bogus length %u (vcc: 0x%p)!\n",
39458 __func__, length, vcc);
39459- atomic_inc(&vcc->stats->rx_err);
39460+ atomic_inc_unchecked(&vcc->stats->rx_err);
39461 goto out;
39462 }
39463
39464@@ -370,14 +370,14 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
39465 if (sarb->len < pdu_length) {
39466 atm_rldbg(instance, "%s: bogus pdu_length %u (sarb->len: %u, vcc: 0x%p)!\n",
39467 __func__, pdu_length, sarb->len, vcc);
39468- atomic_inc(&vcc->stats->rx_err);
39469+ atomic_inc_unchecked(&vcc->stats->rx_err);
39470 goto out;
39471 }
39472
39473 if (crc32_be(~0, skb_tail_pointer(sarb) - pdu_length, pdu_length) != 0xc704dd7b) {
39474 atm_rldbg(instance, "%s: packet failed crc check (vcc: 0x%p)!\n",
39475 __func__, vcc);
39476- atomic_inc(&vcc->stats->rx_err);
39477+ atomic_inc_unchecked(&vcc->stats->rx_err);
39478 goto out;
39479 }
39480
39481@@ -387,7 +387,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
39482 if (printk_ratelimit())
39483 atm_err(instance, "%s: no memory for skb (length: %u)!\n",
39484 __func__, length);
39485- atomic_inc(&vcc->stats->rx_drop);
39486+ atomic_inc_unchecked(&vcc->stats->rx_drop);
39487 goto out;
39488 }
39489
39490@@ -412,7 +412,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
39491
39492 vcc->push(vcc, skb);
39493
39494- atomic_inc(&vcc->stats->rx);
39495+ atomic_inc_unchecked(&vcc->stats->rx);
39496 out:
39497 skb_trim(sarb, 0);
39498 }
39499@@ -615,7 +615,7 @@ static void usbatm_tx_process(unsigned long data)
39500 struct atm_vcc *vcc = UDSL_SKB(skb)->atm.vcc;
39501
39502 usbatm_pop(vcc, skb);
39503- atomic_inc(&vcc->stats->tx);
39504+ atomic_inc_unchecked(&vcc->stats->tx);
39505
39506 skb = skb_dequeue(&instance->sndqueue);
39507 }
39508@@ -770,11 +770,11 @@ static int usbatm_atm_proc_read(struct atm_dev *atm_dev, loff_t * pos, char *pag
39509 if (!left--)
39510 return sprintf(page,
39511 "AAL5: tx %d ( %d err ), rx %d ( %d err, %d drop )\n",
39512- atomic_read(&atm_dev->stats.aal5.tx),
39513- atomic_read(&atm_dev->stats.aal5.tx_err),
39514- atomic_read(&atm_dev->stats.aal5.rx),
39515- atomic_read(&atm_dev->stats.aal5.rx_err),
39516- atomic_read(&atm_dev->stats.aal5.rx_drop));
39517+ atomic_read_unchecked(&atm_dev->stats.aal5.tx),
39518+ atomic_read_unchecked(&atm_dev->stats.aal5.tx_err),
39519+ atomic_read_unchecked(&atm_dev->stats.aal5.rx),
39520+ atomic_read_unchecked(&atm_dev->stats.aal5.rx_err),
39521+ atomic_read_unchecked(&atm_dev->stats.aal5.rx_drop));
39522
39523 if (!left--) {
39524 if (instance->disconnected)
39525diff --git a/drivers/usb/core/devices.c b/drivers/usb/core/devices.c
39526index 3440812..2a4ef1f 100644
39527--- a/drivers/usb/core/devices.c
39528+++ b/drivers/usb/core/devices.c
39529@@ -126,7 +126,7 @@ static const char format_endpt[] =
39530 * time it gets called.
39531 */
39532 static struct device_connect_event {
39533- atomic_t count;
39534+ atomic_unchecked_t count;
39535 wait_queue_head_t wait;
39536 } device_event = {
39537 .count = ATOMIC_INIT(1),
39538@@ -164,7 +164,7 @@ static const struct class_info clas_info[] = {
39539
39540 void usbfs_conn_disc_event(void)
39541 {
39542- atomic_add(2, &device_event.count);
39543+ atomic_add_unchecked(2, &device_event.count);
39544 wake_up(&device_event.wait);
39545 }
39546
39547@@ -648,7 +648,7 @@ static unsigned int usb_device_poll(struct file *file,
39548
39549 poll_wait(file, &device_event.wait, wait);
39550
39551- event_count = atomic_read(&device_event.count);
39552+ event_count = atomic_read_unchecked(&device_event.count);
39553 if (file->f_version != event_count) {
39554 file->f_version = event_count;
39555 return POLLIN | POLLRDNORM;
39556diff --git a/drivers/usb/early/ehci-dbgp.c b/drivers/usb/early/ehci-dbgp.c
39557index 89dcf15..481800b 100644
39558--- a/drivers/usb/early/ehci-dbgp.c
39559+++ b/drivers/usb/early/ehci-dbgp.c
39560@@ -97,7 +97,8 @@ static inline u32 dbgp_len_update(u32 x, u32 len)
39561
39562 #ifdef CONFIG_KGDB
39563 static struct kgdb_io kgdbdbgp_io_ops;
39564-#define dbgp_kgdb_mode (dbg_io_ops == &kgdbdbgp_io_ops)
39565+static struct kgdb_io kgdbdbgp_io_ops_console;
39566+#define dbgp_kgdb_mode (dbg_io_ops == &kgdbdbgp_io_ops || dbg_io_ops == &kgdbdbgp_io_ops_console)
39567 #else
39568 #define dbgp_kgdb_mode (0)
39569 #endif
39570@@ -1035,6 +1036,13 @@ static struct kgdb_io kgdbdbgp_io_ops = {
39571 .write_char = kgdbdbgp_write_char,
39572 };
39573
39574+static struct kgdb_io kgdbdbgp_io_ops_console = {
39575+ .name = "kgdbdbgp",
39576+ .read_char = kgdbdbgp_read_char,
39577+ .write_char = kgdbdbgp_write_char,
39578+ .is_console = 1
39579+};
39580+
39581 static int kgdbdbgp_wait_time;
39582
39583 static int __init kgdbdbgp_parse_config(char *str)
39584@@ -1050,8 +1058,10 @@ static int __init kgdbdbgp_parse_config(char *str)
39585 ptr++;
39586 kgdbdbgp_wait_time = simple_strtoul(ptr, &ptr, 10);
39587 }
39588- kgdb_register_io_module(&kgdbdbgp_io_ops);
39589- kgdbdbgp_io_ops.is_console = early_dbgp_console.index != -1;
39590+ if (early_dbgp_console.index != -1)
39591+ kgdb_register_io_module(&kgdbdbgp_io_ops_console);
39592+ else
39593+ kgdb_register_io_module(&kgdbdbgp_io_ops);
39594
39595 return 0;
39596 }
39597diff --git a/drivers/usb/gadget/u_serial.c b/drivers/usb/gadget/u_serial.c
39598index da6d479..80ed10b 100644
39599--- a/drivers/usb/gadget/u_serial.c
39600+++ b/drivers/usb/gadget/u_serial.c
39601@@ -735,9 +735,9 @@ static int gs_open(struct tty_struct *tty, struct file *file)
39602 spin_lock_irq(&port->port_lock);
39603
39604 /* already open? Great. */
39605- if (port->port.count) {
39606+ if (atomic_read(&port->port.count)) {
39607 status = 0;
39608- port->port.count++;
39609+ atomic_inc(&port->port.count);
39610
39611 /* currently opening/closing? wait ... */
39612 } else if (port->openclose) {
39613@@ -796,7 +796,7 @@ static int gs_open(struct tty_struct *tty, struct file *file)
39614 tty->driver_data = port;
39615 port->port.tty = tty;
39616
39617- port->port.count = 1;
39618+ atomic_set(&port->port.count, 1);
39619 port->openclose = false;
39620
39621 /* if connected, start the I/O stream */
39622@@ -838,11 +838,11 @@ static void gs_close(struct tty_struct *tty, struct file *file)
39623
39624 spin_lock_irq(&port->port_lock);
39625
39626- if (port->port.count != 1) {
39627- if (port->port.count == 0)
39628+ if (atomic_read(&port->port.count) != 1) {
39629+ if (atomic_read(&port->port.count) == 0)
39630 WARN_ON(1);
39631 else
39632- --port->port.count;
39633+ atomic_dec(&port->port.count);
39634 goto exit;
39635 }
39636
39637@@ -852,7 +852,7 @@ static void gs_close(struct tty_struct *tty, struct file *file)
39638 * and sleep if necessary
39639 */
39640 port->openclose = true;
39641- port->port.count = 0;
39642+ atomic_set(&port->port.count, 0);
39643
39644 gser = port->port_usb;
39645 if (gser && gser->disconnect)
39646@@ -1156,7 +1156,7 @@ static int gs_closed(struct gs_port *port)
39647 int cond;
39648
39649 spin_lock_irq(&port->port_lock);
39650- cond = (port->port.count == 0) && !port->openclose;
39651+ cond = (atomic_read(&port->port.count) == 0) && !port->openclose;
39652 spin_unlock_irq(&port->port_lock);
39653 return cond;
39654 }
39655@@ -1269,7 +1269,7 @@ int gserial_connect(struct gserial *gser, u8 port_num)
39656 /* if it's already open, start I/O ... and notify the serial
39657 * protocol about open/close status (connect/disconnect).
39658 */
39659- if (port->port.count) {
39660+ if (atomic_read(&port->port.count)) {
39661 pr_debug("gserial_connect: start ttyGS%d\n", port->port_num);
39662 gs_start_io(port);
39663 if (gser->connect)
39664@@ -1316,7 +1316,7 @@ void gserial_disconnect(struct gserial *gser)
39665
39666 port->port_usb = NULL;
39667 gser->ioport = NULL;
39668- if (port->port.count > 0 || port->openclose) {
39669+ if (atomic_read(&port->port.count) > 0 || port->openclose) {
39670 wake_up_interruptible(&port->drain_wait);
39671 if (port->port.tty)
39672 tty_hangup(port->port.tty);
39673@@ -1332,7 +1332,7 @@ void gserial_disconnect(struct gserial *gser)
39674
39675 /* finally, free any unused/unusable I/O buffers */
39676 spin_lock_irqsave(&port->port_lock, flags);
39677- if (port->port.count == 0 && !port->openclose)
39678+ if (atomic_read(&port->port.count) == 0 && !port->openclose)
39679 gs_buf_free(&port->port_write_buf);
39680 gs_free_requests(gser->out, &port->read_pool, NULL);
39681 gs_free_requests(gser->out, &port->read_queue, NULL);
39682diff --git a/drivers/usb/serial/console.c b/drivers/usb/serial/console.c
39683index b9cca6d..75c75df 100644
39684--- a/drivers/usb/serial/console.c
39685+++ b/drivers/usb/serial/console.c
39686@@ -127,7 +127,7 @@ static int usb_console_setup(struct console *co, char *options)
39687
39688 info->port = port;
39689
39690- ++port->port.count;
39691+ atomic_inc(&port->port.count);
39692 if (!test_bit(ASYNCB_INITIALIZED, &port->port.flags)) {
39693 if (serial->type->set_termios) {
39694 /*
39695@@ -177,7 +177,7 @@ static int usb_console_setup(struct console *co, char *options)
39696 }
39697 /* Now that any required fake tty operations are completed restore
39698 * the tty port count */
39699- --port->port.count;
39700+ atomic_dec(&port->port.count);
39701 /* The console is special in terms of closing the device so
39702 * indicate this port is now acting as a system console. */
39703 port->port.console = 1;
39704@@ -190,7 +190,7 @@ static int usb_console_setup(struct console *co, char *options)
39705 free_tty:
39706 kfree(tty);
39707 reset_open_count:
39708- port->port.count = 0;
39709+ atomic_set(&port->port.count, 0);
39710 usb_autopm_put_interface(serial->interface);
39711 error_get_interface:
39712 usb_serial_put(serial);
39713diff --git a/drivers/usb/wusbcore/wa-hc.h b/drivers/usb/wusbcore/wa-hc.h
39714index d6bea3e..60b250e 100644
39715--- a/drivers/usb/wusbcore/wa-hc.h
39716+++ b/drivers/usb/wusbcore/wa-hc.h
39717@@ -192,7 +192,7 @@ struct wahc {
39718 struct list_head xfer_delayed_list;
39719 spinlock_t xfer_list_lock;
39720 struct work_struct xfer_work;
39721- atomic_t xfer_id_count;
39722+ atomic_unchecked_t xfer_id_count;
39723 };
39724
39725
39726@@ -246,7 +246,7 @@ static inline void wa_init(struct wahc *wa)
39727 INIT_LIST_HEAD(&wa->xfer_delayed_list);
39728 spin_lock_init(&wa->xfer_list_lock);
39729 INIT_WORK(&wa->xfer_work, wa_urb_enqueue_run);
39730- atomic_set(&wa->xfer_id_count, 1);
39731+ atomic_set_unchecked(&wa->xfer_id_count, 1);
39732 }
39733
39734 /**
39735diff --git a/drivers/usb/wusbcore/wa-xfer.c b/drivers/usb/wusbcore/wa-xfer.c
39736index 57c01ab..8a05959 100644
39737--- a/drivers/usb/wusbcore/wa-xfer.c
39738+++ b/drivers/usb/wusbcore/wa-xfer.c
39739@@ -296,7 +296,7 @@ out:
39740 */
39741 static void wa_xfer_id_init(struct wa_xfer *xfer)
39742 {
39743- xfer->id = atomic_add_return(1, &xfer->wa->xfer_id_count);
39744+ xfer->id = atomic_add_return_unchecked(1, &xfer->wa->xfer_id_count);
39745 }
39746
39747 /*
39748diff --git a/drivers/vhost/vhost.c b/drivers/vhost/vhost.c
39749index ef82a0d..78a026b 100644
39750--- a/drivers/vhost/vhost.c
39751+++ b/drivers/vhost/vhost.c
39752@@ -634,7 +634,7 @@ static long vhost_set_memory(struct vhost_dev *d, struct vhost_memory __user *m)
39753 return 0;
39754 }
39755
39756-static long vhost_set_vring(struct vhost_dev *d, int ioctl, void __user *argp)
39757+static long vhost_set_vring(struct vhost_dev *d, unsigned int ioctl, void __user *argp)
39758 {
39759 struct file *eventfp, *filep = NULL,
39760 *pollstart = NULL, *pollstop = NULL;
39761@@ -1076,7 +1076,7 @@ static int translate_desc(struct vhost_dev *dev, u64 addr, u32 len,
39762 }
39763 _iov = iov + ret;
39764 size = reg->memory_size - addr + reg->guest_phys_addr;
39765- _iov->iov_len = min((u64)len, size);
39766+ _iov->iov_len = min((u64)len - s, size);
39767 _iov->iov_base = (void __user *)(unsigned long)
39768 (reg->userspace_addr + addr - reg->guest_phys_addr);
39769 s += size;
39770diff --git a/drivers/video/aty/aty128fb.c b/drivers/video/aty/aty128fb.c
39771index 747442d..7c0c434 100644
39772--- a/drivers/video/aty/aty128fb.c
39773+++ b/drivers/video/aty/aty128fb.c
39774@@ -149,7 +149,7 @@ enum {
39775 };
39776
39777 /* Must match above enum */
39778-static const char *r128_family[] __devinitdata = {
39779+static const char *r128_family[] __devinitconst = {
39780 "AGP",
39781 "PCI",
39782 "PRO AGP",
39783diff --git a/drivers/video/fbcmap.c b/drivers/video/fbcmap.c
39784index 5c3960d..15cf8fc 100644
39785--- a/drivers/video/fbcmap.c
39786+++ b/drivers/video/fbcmap.c
39787@@ -285,8 +285,7 @@ int fb_set_user_cmap(struct fb_cmap_user *cmap, struct fb_info *info)
39788 rc = -ENODEV;
39789 goto out;
39790 }
39791- if (cmap->start < 0 || (!info->fbops->fb_setcolreg &&
39792- !info->fbops->fb_setcmap)) {
39793+ if (!info->fbops->fb_setcolreg && !info->fbops->fb_setcmap) {
39794 rc = -EINVAL;
39795 goto out1;
39796 }
39797diff --git a/drivers/video/fbmem.c b/drivers/video/fbmem.c
39798index 0dff12a..2ef47b3 100644
39799--- a/drivers/video/fbmem.c
39800+++ b/drivers/video/fbmem.c
39801@@ -428,7 +428,7 @@ static void fb_do_show_logo(struct fb_info *info, struct fb_image *image,
39802 image->dx += image->width + 8;
39803 }
39804 } else if (rotate == FB_ROTATE_UD) {
39805- for (x = 0; x < num && image->dx >= 0; x++) {
39806+ for (x = 0; x < num && (__s32)image->dx >= 0; x++) {
39807 info->fbops->fb_imageblit(info, image);
39808 image->dx -= image->width + 8;
39809 }
39810@@ -440,7 +440,7 @@ static void fb_do_show_logo(struct fb_info *info, struct fb_image *image,
39811 image->dy += image->height + 8;
39812 }
39813 } else if (rotate == FB_ROTATE_CCW) {
39814- for (x = 0; x < num && image->dy >= 0; x++) {
39815+ for (x = 0; x < num && (__s32)image->dy >= 0; x++) {
39816 info->fbops->fb_imageblit(info, image);
39817 image->dy -= image->height + 8;
39818 }
39819@@ -1166,7 +1166,7 @@ static long do_fb_ioctl(struct fb_info *info, unsigned int cmd,
39820 return -EFAULT;
39821 if (con2fb.console < 1 || con2fb.console > MAX_NR_CONSOLES)
39822 return -EINVAL;
39823- if (con2fb.framebuffer < 0 || con2fb.framebuffer >= FB_MAX)
39824+ if (con2fb.framebuffer >= FB_MAX)
39825 return -EINVAL;
39826 if (!registered_fb[con2fb.framebuffer])
39827 request_module("fb%d", con2fb.framebuffer);
39828diff --git a/drivers/video/geode/gx1fb_core.c b/drivers/video/geode/gx1fb_core.c
39829index 5a5d092..265c5ed 100644
39830--- a/drivers/video/geode/gx1fb_core.c
39831+++ b/drivers/video/geode/gx1fb_core.c
39832@@ -29,7 +29,7 @@ static int crt_option = 1;
39833 static char panel_option[32] = "";
39834
39835 /* Modes relevant to the GX1 (taken from modedb.c) */
39836-static const struct fb_videomode __devinitdata gx1_modedb[] = {
39837+static const struct fb_videomode __devinitconst gx1_modedb[] = {
39838 /* 640x480-60 VESA */
39839 { NULL, 60, 640, 480, 39682, 48, 16, 33, 10, 96, 2,
39840 0, FB_VMODE_NONINTERLACED, FB_MODE_IS_VESA },
39841diff --git a/drivers/video/gxt4500.c b/drivers/video/gxt4500.c
39842index 0fad23f..0e9afa4 100644
39843--- a/drivers/video/gxt4500.c
39844+++ b/drivers/video/gxt4500.c
39845@@ -156,7 +156,7 @@ struct gxt4500_par {
39846 static char *mode_option;
39847
39848 /* default mode: 1280x1024 @ 60 Hz, 8 bpp */
39849-static const struct fb_videomode defaultmode __devinitdata = {
39850+static const struct fb_videomode defaultmode __devinitconst = {
39851 .refresh = 60,
39852 .xres = 1280,
39853 .yres = 1024,
39854@@ -581,7 +581,7 @@ static int gxt4500_blank(int blank, struct fb_info *info)
39855 return 0;
39856 }
39857
39858-static const struct fb_fix_screeninfo gxt4500_fix __devinitdata = {
39859+static const struct fb_fix_screeninfo gxt4500_fix __devinitconst = {
39860 .id = "IBM GXT4500P",
39861 .type = FB_TYPE_PACKED_PIXELS,
39862 .visual = FB_VISUAL_PSEUDOCOLOR,
39863diff --git a/drivers/video/i810/i810_accel.c b/drivers/video/i810/i810_accel.c
39864index 7672d2e..b56437f 100644
39865--- a/drivers/video/i810/i810_accel.c
39866+++ b/drivers/video/i810/i810_accel.c
39867@@ -73,6 +73,7 @@ static inline int wait_for_space(struct fb_info *info, u32 space)
39868 }
39869 }
39870 printk("ringbuffer lockup!!!\n");
39871+ printk("head:%u tail:%u iring.size:%u space:%u\n", head, tail, par->iring.size, space);
39872 i810_report_error(mmio);
39873 par->dev_flags |= LOCKUP;
39874 info->pixmap.scan_align = 1;
39875diff --git a/drivers/video/i810/i810_main.c b/drivers/video/i810/i810_main.c
39876index b83f361..2b05a91 100644
39877--- a/drivers/video/i810/i810_main.c
39878+++ b/drivers/video/i810/i810_main.c
39879@@ -97,7 +97,7 @@ static int i810fb_blank (int blank_mode, struct fb_info *info);
39880 static void i810fb_release_resource (struct fb_info *info, struct i810fb_par *par);
39881
39882 /* PCI */
39883-static const char *i810_pci_list[] __devinitdata = {
39884+static const char *i810_pci_list[] __devinitconst = {
39885 "Intel(R) 810 Framebuffer Device" ,
39886 "Intel(R) 810-DC100 Framebuffer Device" ,
39887 "Intel(R) 810E Framebuffer Device" ,
39888diff --git a/drivers/video/jz4740_fb.c b/drivers/video/jz4740_fb.c
39889index de36693..3c63fc2 100644
39890--- a/drivers/video/jz4740_fb.c
39891+++ b/drivers/video/jz4740_fb.c
39892@@ -136,7 +136,7 @@ struct jzfb {
39893 uint32_t pseudo_palette[16];
39894 };
39895
39896-static const struct fb_fix_screeninfo jzfb_fix __devinitdata = {
39897+static const struct fb_fix_screeninfo jzfb_fix __devinitconst = {
39898 .id = "JZ4740 FB",
39899 .type = FB_TYPE_PACKED_PIXELS,
39900 .visual = FB_VISUAL_TRUECOLOR,
39901diff --git a/drivers/video/logo/logo_linux_clut224.ppm b/drivers/video/logo/logo_linux_clut224.ppm
39902index 3c14e43..eafa544 100644
39903--- a/drivers/video/logo/logo_linux_clut224.ppm
39904+++ b/drivers/video/logo/logo_linux_clut224.ppm
39905@@ -1,1604 +1,1123 @@
39906 P3
39907-# Standard 224-color Linux logo
39908 80 80
39909 255
39910- 0 0 0 0 0 0 0 0 0 0 0 0
39911- 0 0 0 0 0 0 0 0 0 0 0 0
39912- 0 0 0 0 0 0 0 0 0 0 0 0
39913- 0 0 0 0 0 0 0 0 0 0 0 0
39914- 0 0 0 0 0 0 0 0 0 0 0 0
39915- 0 0 0 0 0 0 0 0 0 0 0 0
39916- 0 0 0 0 0 0 0 0 0 0 0 0
39917- 0 0 0 0 0 0 0 0 0 0 0 0
39918- 0 0 0 0 0 0 0 0 0 0 0 0
39919- 6 6 6 6 6 6 10 10 10 10 10 10
39920- 10 10 10 6 6 6 6 6 6 6 6 6
39921- 0 0 0 0 0 0 0 0 0 0 0 0
39922- 0 0 0 0 0 0 0 0 0 0 0 0
39923- 0 0 0 0 0 0 0 0 0 0 0 0
39924- 0 0 0 0 0 0 0 0 0 0 0 0
39925- 0 0 0 0 0 0 0 0 0 0 0 0
39926- 0 0 0 0 0 0 0 0 0 0 0 0
39927- 0 0 0 0 0 0 0 0 0 0 0 0
39928- 0 0 0 0 0 0 0 0 0 0 0 0
39929- 0 0 0 0 0 0 0 0 0 0 0 0
39930- 0 0 0 0 0 0 0 0 0 0 0 0
39931- 0 0 0 0 0 0 0 0 0 0 0 0
39932- 0 0 0 0 0 0 0 0 0 0 0 0
39933- 0 0 0 0 0 0 0 0 0 0 0 0
39934- 0 0 0 0 0 0 0 0 0 0 0 0
39935- 0 0 0 0 0 0 0 0 0 0 0 0
39936- 0 0 0 0 0 0 0 0 0 0 0 0
39937- 0 0 0 0 0 0 0 0 0 0 0 0
39938- 0 0 0 6 6 6 10 10 10 14 14 14
39939- 22 22 22 26 26 26 30 30 30 34 34 34
39940- 30 30 30 30 30 30 26 26 26 18 18 18
39941- 14 14 14 10 10 10 6 6 6 0 0 0
39942- 0 0 0 0 0 0 0 0 0 0 0 0
39943- 0 0 0 0 0 0 0 0 0 0 0 0
39944- 0 0 0 0 0 0 0 0 0 0 0 0
39945- 0 0 0 0 0 0 0 0 0 0 0 0
39946- 0 0 0 0 0 0 0 0 0 0 0 0
39947- 0 0 0 0 0 0 0 0 0 0 0 0
39948- 0 0 0 0 0 0 0 0 0 0 0 0
39949- 0 0 0 0 0 0 0 0 0 0 0 0
39950- 0 0 0 0 0 0 0 0 0 0 0 0
39951- 0 0 0 0 0 1 0 0 1 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- 6 6 6 14 14 14 26 26 26 42 42 42
39959- 54 54 54 66 66 66 78 78 78 78 78 78
39960- 78 78 78 74 74 74 66 66 66 54 54 54
39961- 42 42 42 26 26 26 18 18 18 10 10 10
39962- 6 6 6 0 0 0 0 0 0 0 0 0
39963- 0 0 0 0 0 0 0 0 0 0 0 0
39964- 0 0 0 0 0 0 0 0 0 0 0 0
39965- 0 0 0 0 0 0 0 0 0 0 0 0
39966- 0 0 0 0 0 0 0 0 0 0 0 0
39967- 0 0 0 0 0 0 0 0 0 0 0 0
39968- 0 0 0 0 0 0 0 0 0 0 0 0
39969- 0 0 0 0 0 0 0 0 0 0 0 0
39970- 0 0 0 0 0 0 0 0 0 0 0 0
39971- 0 0 1 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 10 10 10
39978- 22 22 22 42 42 42 66 66 66 86 86 86
39979- 66 66 66 38 38 38 38 38 38 22 22 22
39980- 26 26 26 34 34 34 54 54 54 66 66 66
39981- 86 86 86 70 70 70 46 46 46 26 26 26
39982- 14 14 14 6 6 6 0 0 0 0 0 0
39983- 0 0 0 0 0 0 0 0 0 0 0 0
39984- 0 0 0 0 0 0 0 0 0 0 0 0
39985- 0 0 0 0 0 0 0 0 0 0 0 0
39986- 0 0 0 0 0 0 0 0 0 0 0 0
39987- 0 0 0 0 0 0 0 0 0 0 0 0
39988- 0 0 0 0 0 0 0 0 0 0 0 0
39989- 0 0 0 0 0 0 0 0 0 0 0 0
39990- 0 0 0 0 0 0 0 0 0 0 0 0
39991- 0 0 1 0 0 1 0 0 1 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 10 10 10 26 26 26
39998- 50 50 50 82 82 82 58 58 58 6 6 6
39999- 2 2 6 2 2 6 2 2 6 2 2 6
40000- 2 2 6 2 2 6 2 2 6 2 2 6
40001- 6 6 6 54 54 54 86 86 86 66 66 66
40002- 38 38 38 18 18 18 6 6 6 0 0 0
40003- 0 0 0 0 0 0 0 0 0 0 0 0
40004- 0 0 0 0 0 0 0 0 0 0 0 0
40005- 0 0 0 0 0 0 0 0 0 0 0 0
40006- 0 0 0 0 0 0 0 0 0 0 0 0
40007- 0 0 0 0 0 0 0 0 0 0 0 0
40008- 0 0 0 0 0 0 0 0 0 0 0 0
40009- 0 0 0 0 0 0 0 0 0 0 0 0
40010- 0 0 0 0 0 0 0 0 0 0 0 0
40011- 0 0 0 0 0 0 0 0 0 0 0 0
40012- 0 0 0 0 0 0 0 0 0 0 0 0
40013- 0 0 0 0 0 0 0 0 0 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 6 6 6 22 22 22 50 50 50
40018- 78 78 78 34 34 34 2 2 6 2 2 6
40019- 2 2 6 2 2 6 2 2 6 2 2 6
40020- 2 2 6 2 2 6 2 2 6 2 2 6
40021- 2 2 6 2 2 6 6 6 6 70 70 70
40022- 78 78 78 46 46 46 22 22 22 6 6 6
40023- 0 0 0 0 0 0 0 0 0 0 0 0
40024- 0 0 0 0 0 0 0 0 0 0 0 0
40025- 0 0 0 0 0 0 0 0 0 0 0 0
40026- 0 0 0 0 0 0 0 0 0 0 0 0
40027- 0 0 0 0 0 0 0 0 0 0 0 0
40028- 0 0 0 0 0 0 0 0 0 0 0 0
40029- 0 0 0 0 0 0 0 0 0 0 0 0
40030- 0 0 0 0 0 0 0 0 0 0 0 0
40031- 0 0 1 0 0 1 0 0 1 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- 6 6 6 18 18 18 42 42 42 82 82 82
40038- 26 26 26 2 2 6 2 2 6 2 2 6
40039- 2 2 6 2 2 6 2 2 6 2 2 6
40040- 2 2 6 2 2 6 2 2 6 14 14 14
40041- 46 46 46 34 34 34 6 6 6 2 2 6
40042- 42 42 42 78 78 78 42 42 42 18 18 18
40043- 6 6 6 0 0 0 0 0 0 0 0 0
40044- 0 0 0 0 0 0 0 0 0 0 0 0
40045- 0 0 0 0 0 0 0 0 0 0 0 0
40046- 0 0 0 0 0 0 0 0 0 0 0 0
40047- 0 0 0 0 0 0 0 0 0 0 0 0
40048- 0 0 0 0 0 0 0 0 0 0 0 0
40049- 0 0 0 0 0 0 0 0 0 0 0 0
40050- 0 0 0 0 0 0 0 0 0 0 0 0
40051- 0 0 1 0 0 0 0 0 1 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- 10 10 10 30 30 30 66 66 66 58 58 58
40058- 2 2 6 2 2 6 2 2 6 2 2 6
40059- 2 2 6 2 2 6 2 2 6 2 2 6
40060- 2 2 6 2 2 6 2 2 6 26 26 26
40061- 86 86 86 101 101 101 46 46 46 10 10 10
40062- 2 2 6 58 58 58 70 70 70 34 34 34
40063- 10 10 10 0 0 0 0 0 0 0 0 0
40064- 0 0 0 0 0 0 0 0 0 0 0 0
40065- 0 0 0 0 0 0 0 0 0 0 0 0
40066- 0 0 0 0 0 0 0 0 0 0 0 0
40067- 0 0 0 0 0 0 0 0 0 0 0 0
40068- 0 0 0 0 0 0 0 0 0 0 0 0
40069- 0 0 0 0 0 0 0 0 0 0 0 0
40070- 0 0 0 0 0 0 0 0 0 0 0 0
40071- 0 0 1 0 0 1 0 0 1 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- 14 14 14 42 42 42 86 86 86 10 10 10
40078- 2 2 6 2 2 6 2 2 6 2 2 6
40079- 2 2 6 2 2 6 2 2 6 2 2 6
40080- 2 2 6 2 2 6 2 2 6 30 30 30
40081- 94 94 94 94 94 94 58 58 58 26 26 26
40082- 2 2 6 6 6 6 78 78 78 54 54 54
40083- 22 22 22 6 6 6 0 0 0 0 0 0
40084- 0 0 0 0 0 0 0 0 0 0 0 0
40085- 0 0 0 0 0 0 0 0 0 0 0 0
40086- 0 0 0 0 0 0 0 0 0 0 0 0
40087- 0 0 0 0 0 0 0 0 0 0 0 0
40088- 0 0 0 0 0 0 0 0 0 0 0 0
40089- 0 0 0 0 0 0 0 0 0 0 0 0
40090- 0 0 0 0 0 0 0 0 0 0 0 0
40091- 0 0 0 0 0 0 0 0 0 0 0 0
40092- 0 0 0 0 0 0 0 0 0 0 0 0
40093- 0 0 0 0 0 0 0 0 0 0 0 0
40094- 0 0 0 0 0 0 0 0 0 0 0 0
40095- 0 0 0 0 0 0 0 0 0 0 0 0
40096- 0 0 0 0 0 0 0 0 0 6 6 6
40097- 22 22 22 62 62 62 62 62 62 2 2 6
40098- 2 2 6 2 2 6 2 2 6 2 2 6
40099- 2 2 6 2 2 6 2 2 6 2 2 6
40100- 2 2 6 2 2 6 2 2 6 26 26 26
40101- 54 54 54 38 38 38 18 18 18 10 10 10
40102- 2 2 6 2 2 6 34 34 34 82 82 82
40103- 38 38 38 14 14 14 0 0 0 0 0 0
40104- 0 0 0 0 0 0 0 0 0 0 0 0
40105- 0 0 0 0 0 0 0 0 0 0 0 0
40106- 0 0 0 0 0 0 0 0 0 0 0 0
40107- 0 0 0 0 0 0 0 0 0 0 0 0
40108- 0 0 0 0 0 0 0 0 0 0 0 0
40109- 0 0 0 0 0 0 0 0 0 0 0 0
40110- 0 0 0 0 0 0 0 0 0 0 0 0
40111- 0 0 0 0 0 1 0 0 1 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 6 6 6
40117- 30 30 30 78 78 78 30 30 30 2 2 6
40118- 2 2 6 2 2 6 2 2 6 2 2 6
40119- 2 2 6 2 2 6 2 2 6 2 2 6
40120- 2 2 6 2 2 6 2 2 6 10 10 10
40121- 10 10 10 2 2 6 2 2 6 2 2 6
40122- 2 2 6 2 2 6 2 2 6 78 78 78
40123- 50 50 50 18 18 18 6 6 6 0 0 0
40124- 0 0 0 0 0 0 0 0 0 0 0 0
40125- 0 0 0 0 0 0 0 0 0 0 0 0
40126- 0 0 0 0 0 0 0 0 0 0 0 0
40127- 0 0 0 0 0 0 0 0 0 0 0 0
40128- 0 0 0 0 0 0 0 0 0 0 0 0
40129- 0 0 0 0 0 0 0 0 0 0 0 0
40130- 0 0 0 0 0 0 0 0 0 0 0 0
40131- 0 0 1 0 0 0 0 0 0 0 0 0
40132- 0 0 0 0 0 0 0 0 0 0 0 0
40133- 0 0 0 0 0 0 0 0 0 0 0 0
40134- 0 0 0 0 0 0 0 0 0 0 0 0
40135- 0 0 0 0 0 0 0 0 0 0 0 0
40136- 0 0 0 0 0 0 0 0 0 10 10 10
40137- 38 38 38 86 86 86 14 14 14 2 2 6
40138- 2 2 6 2 2 6 2 2 6 2 2 6
40139- 2 2 6 2 2 6 2 2 6 2 2 6
40140- 2 2 6 2 2 6 2 2 6 2 2 6
40141- 2 2 6 2 2 6 2 2 6 2 2 6
40142- 2 2 6 2 2 6 2 2 6 54 54 54
40143- 66 66 66 26 26 26 6 6 6 0 0 0
40144- 0 0 0 0 0 0 0 0 0 0 0 0
40145- 0 0 0 0 0 0 0 0 0 0 0 0
40146- 0 0 0 0 0 0 0 0 0 0 0 0
40147- 0 0 0 0 0 0 0 0 0 0 0 0
40148- 0 0 0 0 0 0 0 0 0 0 0 0
40149- 0 0 0 0 0 0 0 0 0 0 0 0
40150- 0 0 0 0 0 0 0 0 0 0 0 0
40151- 0 0 0 0 0 1 0 0 1 0 0 0
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 14 14 14
40157- 42 42 42 82 82 82 2 2 6 2 2 6
40158- 2 2 6 6 6 6 10 10 10 2 2 6
40159- 2 2 6 2 2 6 2 2 6 2 2 6
40160- 2 2 6 2 2 6 2 2 6 6 6 6
40161- 14 14 14 10 10 10 2 2 6 2 2 6
40162- 2 2 6 2 2 6 2 2 6 18 18 18
40163- 82 82 82 34 34 34 10 10 10 0 0 0
40164- 0 0 0 0 0 0 0 0 0 0 0 0
40165- 0 0 0 0 0 0 0 0 0 0 0 0
40166- 0 0 0 0 0 0 0 0 0 0 0 0
40167- 0 0 0 0 0 0 0 0 0 0 0 0
40168- 0 0 0 0 0 0 0 0 0 0 0 0
40169- 0 0 0 0 0 0 0 0 0 0 0 0
40170- 0 0 0 0 0 0 0 0 0 0 0 0
40171- 0 0 1 0 0 0 0 0 0 0 0 0
40172- 0 0 0 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 14 14 14
40177- 46 46 46 86 86 86 2 2 6 2 2 6
40178- 6 6 6 6 6 6 22 22 22 34 34 34
40179- 6 6 6 2 2 6 2 2 6 2 2 6
40180- 2 2 6 2 2 6 18 18 18 34 34 34
40181- 10 10 10 50 50 50 22 22 22 2 2 6
40182- 2 2 6 2 2 6 2 2 6 10 10 10
40183- 86 86 86 42 42 42 14 14 14 0 0 0
40184- 0 0 0 0 0 0 0 0 0 0 0 0
40185- 0 0 0 0 0 0 0 0 0 0 0 0
40186- 0 0 0 0 0 0 0 0 0 0 0 0
40187- 0 0 0 0 0 0 0 0 0 0 0 0
40188- 0 0 0 0 0 0 0 0 0 0 0 0
40189- 0 0 0 0 0 0 0 0 0 0 0 0
40190- 0 0 0 0 0 0 0 0 0 0 0 0
40191- 0 0 1 0 0 1 0 0 1 0 0 0
40192- 0 0 0 0 0 0 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 14 14 14
40197- 46 46 46 86 86 86 2 2 6 2 2 6
40198- 38 38 38 116 116 116 94 94 94 22 22 22
40199- 22 22 22 2 2 6 2 2 6 2 2 6
40200- 14 14 14 86 86 86 138 138 138 162 162 162
40201-154 154 154 38 38 38 26 26 26 6 6 6
40202- 2 2 6 2 2 6 2 2 6 2 2 6
40203- 86 86 86 46 46 46 14 14 14 0 0 0
40204- 0 0 0 0 0 0 0 0 0 0 0 0
40205- 0 0 0 0 0 0 0 0 0 0 0 0
40206- 0 0 0 0 0 0 0 0 0 0 0 0
40207- 0 0 0 0 0 0 0 0 0 0 0 0
40208- 0 0 0 0 0 0 0 0 0 0 0 0
40209- 0 0 0 0 0 0 0 0 0 0 0 0
40210- 0 0 0 0 0 0 0 0 0 0 0 0
40211- 0 0 0 0 0 0 0 0 0 0 0 0
40212- 0 0 0 0 0 0 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 14 14 14
40217- 46 46 46 86 86 86 2 2 6 14 14 14
40218-134 134 134 198 198 198 195 195 195 116 116 116
40219- 10 10 10 2 2 6 2 2 6 6 6 6
40220-101 98 89 187 187 187 210 210 210 218 218 218
40221-214 214 214 134 134 134 14 14 14 6 6 6
40222- 2 2 6 2 2 6 2 2 6 2 2 6
40223- 86 86 86 50 50 50 18 18 18 6 6 6
40224- 0 0 0 0 0 0 0 0 0 0 0 0
40225- 0 0 0 0 0 0 0 0 0 0 0 0
40226- 0 0 0 0 0 0 0 0 0 0 0 0
40227- 0 0 0 0 0 0 0 0 0 0 0 0
40228- 0 0 0 0 0 0 0 0 0 0 0 0
40229- 0 0 0 0 0 0 0 0 0 0 0 0
40230- 0 0 0 0 0 0 0 0 1 0 0 0
40231- 0 0 1 0 0 1 0 0 1 0 0 0
40232- 0 0 0 0 0 0 0 0 0 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 14 14 14
40237- 46 46 46 86 86 86 2 2 6 54 54 54
40238-218 218 218 195 195 195 226 226 226 246 246 246
40239- 58 58 58 2 2 6 2 2 6 30 30 30
40240-210 210 210 253 253 253 174 174 174 123 123 123
40241-221 221 221 234 234 234 74 74 74 2 2 6
40242- 2 2 6 2 2 6 2 2 6 2 2 6
40243- 70 70 70 58 58 58 22 22 22 6 6 6
40244- 0 0 0 0 0 0 0 0 0 0 0 0
40245- 0 0 0 0 0 0 0 0 0 0 0 0
40246- 0 0 0 0 0 0 0 0 0 0 0 0
40247- 0 0 0 0 0 0 0 0 0 0 0 0
40248- 0 0 0 0 0 0 0 0 0 0 0 0
40249- 0 0 0 0 0 0 0 0 0 0 0 0
40250- 0 0 0 0 0 0 0 0 0 0 0 0
40251- 0 0 0 0 0 0 0 0 0 0 0 0
40252- 0 0 0 0 0 0 0 0 0 0 0 0
40253- 0 0 0 0 0 0 0 0 0 0 0 0
40254- 0 0 0 0 0 0 0 0 0 0 0 0
40255- 0 0 0 0 0 0 0 0 0 0 0 0
40256- 0 0 0 0 0 0 0 0 0 14 14 14
40257- 46 46 46 82 82 82 2 2 6 106 106 106
40258-170 170 170 26 26 26 86 86 86 226 226 226
40259-123 123 123 10 10 10 14 14 14 46 46 46
40260-231 231 231 190 190 190 6 6 6 70 70 70
40261- 90 90 90 238 238 238 158 158 158 2 2 6
40262- 2 2 6 2 2 6 2 2 6 2 2 6
40263- 70 70 70 58 58 58 22 22 22 6 6 6
40264- 0 0 0 0 0 0 0 0 0 0 0 0
40265- 0 0 0 0 0 0 0 0 0 0 0 0
40266- 0 0 0 0 0 0 0 0 0 0 0 0
40267- 0 0 0 0 0 0 0 0 0 0 0 0
40268- 0 0 0 0 0 0 0 0 0 0 0 0
40269- 0 0 0 0 0 0 0 0 0 0 0 0
40270- 0 0 0 0 0 0 0 0 1 0 0 0
40271- 0 0 1 0 0 1 0 0 1 0 0 0
40272- 0 0 0 0 0 0 0 0 0 0 0 0
40273- 0 0 0 0 0 0 0 0 0 0 0 0
40274- 0 0 0 0 0 0 0 0 0 0 0 0
40275- 0 0 0 0 0 0 0 0 0 0 0 0
40276- 0 0 0 0 0 0 0 0 0 14 14 14
40277- 42 42 42 86 86 86 6 6 6 116 116 116
40278-106 106 106 6 6 6 70 70 70 149 149 149
40279-128 128 128 18 18 18 38 38 38 54 54 54
40280-221 221 221 106 106 106 2 2 6 14 14 14
40281- 46 46 46 190 190 190 198 198 198 2 2 6
40282- 2 2 6 2 2 6 2 2 6 2 2 6
40283- 74 74 74 62 62 62 22 22 22 6 6 6
40284- 0 0 0 0 0 0 0 0 0 0 0 0
40285- 0 0 0 0 0 0 0 0 0 0 0 0
40286- 0 0 0 0 0 0 0 0 0 0 0 0
40287- 0 0 0 0 0 0 0 0 0 0 0 0
40288- 0 0 0 0 0 0 0 0 0 0 0 0
40289- 0 0 0 0 0 0 0 0 0 0 0 0
40290- 0 0 0 0 0 0 0 0 1 0 0 0
40291- 0 0 1 0 0 0 0 0 1 0 0 0
40292- 0 0 0 0 0 0 0 0 0 0 0 0
40293- 0 0 0 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 14 14 14
40297- 42 42 42 94 94 94 14 14 14 101 101 101
40298-128 128 128 2 2 6 18 18 18 116 116 116
40299-118 98 46 121 92 8 121 92 8 98 78 10
40300-162 162 162 106 106 106 2 2 6 2 2 6
40301- 2 2 6 195 195 195 195 195 195 6 6 6
40302- 2 2 6 2 2 6 2 2 6 2 2 6
40303- 74 74 74 62 62 62 22 22 22 6 6 6
40304- 0 0 0 0 0 0 0 0 0 0 0 0
40305- 0 0 0 0 0 0 0 0 0 0 0 0
40306- 0 0 0 0 0 0 0 0 0 0 0 0
40307- 0 0 0 0 0 0 0 0 0 0 0 0
40308- 0 0 0 0 0 0 0 0 0 0 0 0
40309- 0 0 0 0 0 0 0 0 0 0 0 0
40310- 0 0 0 0 0 0 0 0 1 0 0 1
40311- 0 0 1 0 0 0 0 0 1 0 0 0
40312- 0 0 0 0 0 0 0 0 0 0 0 0
40313- 0 0 0 0 0 0 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 10 10 10
40317- 38 38 38 90 90 90 14 14 14 58 58 58
40318-210 210 210 26 26 26 54 38 6 154 114 10
40319-226 170 11 236 186 11 225 175 15 184 144 12
40320-215 174 15 175 146 61 37 26 9 2 2 6
40321- 70 70 70 246 246 246 138 138 138 2 2 6
40322- 2 2 6 2 2 6 2 2 6 2 2 6
40323- 70 70 70 66 66 66 26 26 26 6 6 6
40324- 0 0 0 0 0 0 0 0 0 0 0 0
40325- 0 0 0 0 0 0 0 0 0 0 0 0
40326- 0 0 0 0 0 0 0 0 0 0 0 0
40327- 0 0 0 0 0 0 0 0 0 0 0 0
40328- 0 0 0 0 0 0 0 0 0 0 0 0
40329- 0 0 0 0 0 0 0 0 0 0 0 0
40330- 0 0 0 0 0 0 0 0 0 0 0 0
40331- 0 0 0 0 0 0 0 0 0 0 0 0
40332- 0 0 0 0 0 0 0 0 0 0 0 0
40333- 0 0 0 0 0 0 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 10 10 10
40337- 38 38 38 86 86 86 14 14 14 10 10 10
40338-195 195 195 188 164 115 192 133 9 225 175 15
40339-239 182 13 234 190 10 232 195 16 232 200 30
40340-245 207 45 241 208 19 232 195 16 184 144 12
40341-218 194 134 211 206 186 42 42 42 2 2 6
40342- 2 2 6 2 2 6 2 2 6 2 2 6
40343- 50 50 50 74 74 74 30 30 30 6 6 6
40344- 0 0 0 0 0 0 0 0 0 0 0 0
40345- 0 0 0 0 0 0 0 0 0 0 0 0
40346- 0 0 0 0 0 0 0 0 0 0 0 0
40347- 0 0 0 0 0 0 0 0 0 0 0 0
40348- 0 0 0 0 0 0 0 0 0 0 0 0
40349- 0 0 0 0 0 0 0 0 0 0 0 0
40350- 0 0 0 0 0 0 0 0 0 0 0 0
40351- 0 0 0 0 0 0 0 0 0 0 0 0
40352- 0 0 0 0 0 0 0 0 0 0 0 0
40353- 0 0 0 0 0 0 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 10 10 10
40357- 34 34 34 86 86 86 14 14 14 2 2 6
40358-121 87 25 192 133 9 219 162 10 239 182 13
40359-236 186 11 232 195 16 241 208 19 244 214 54
40360-246 218 60 246 218 38 246 215 20 241 208 19
40361-241 208 19 226 184 13 121 87 25 2 2 6
40362- 2 2 6 2 2 6 2 2 6 2 2 6
40363- 50 50 50 82 82 82 34 34 34 10 10 10
40364- 0 0 0 0 0 0 0 0 0 0 0 0
40365- 0 0 0 0 0 0 0 0 0 0 0 0
40366- 0 0 0 0 0 0 0 0 0 0 0 0
40367- 0 0 0 0 0 0 0 0 0 0 0 0
40368- 0 0 0 0 0 0 0 0 0 0 0 0
40369- 0 0 0 0 0 0 0 0 0 0 0 0
40370- 0 0 0 0 0 0 0 0 0 0 0 0
40371- 0 0 0 0 0 0 0 0 0 0 0 0
40372- 0 0 0 0 0 0 0 0 0 0 0 0
40373- 0 0 0 0 0 0 0 0 0 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 10 10 10
40377- 34 34 34 82 82 82 30 30 30 61 42 6
40378-180 123 7 206 145 10 230 174 11 239 182 13
40379-234 190 10 238 202 15 241 208 19 246 218 74
40380-246 218 38 246 215 20 246 215 20 246 215 20
40381-226 184 13 215 174 15 184 144 12 6 6 6
40382- 2 2 6 2 2 6 2 2 6 2 2 6
40383- 26 26 26 94 94 94 42 42 42 14 14 14
40384- 0 0 0 0 0 0 0 0 0 0 0 0
40385- 0 0 0 0 0 0 0 0 0 0 0 0
40386- 0 0 0 0 0 0 0 0 0 0 0 0
40387- 0 0 0 0 0 0 0 0 0 0 0 0
40388- 0 0 0 0 0 0 0 0 0 0 0 0
40389- 0 0 0 0 0 0 0 0 0 0 0 0
40390- 0 0 0 0 0 0 0 0 0 0 0 0
40391- 0 0 0 0 0 0 0 0 0 0 0 0
40392- 0 0 0 0 0 0 0 0 0 0 0 0
40393- 0 0 0 0 0 0 0 0 0 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 10 10 10
40397- 30 30 30 78 78 78 50 50 50 104 69 6
40398-192 133 9 216 158 10 236 178 12 236 186 11
40399-232 195 16 241 208 19 244 214 54 245 215 43
40400-246 215 20 246 215 20 241 208 19 198 155 10
40401-200 144 11 216 158 10 156 118 10 2 2 6
40402- 2 2 6 2 2 6 2 2 6 2 2 6
40403- 6 6 6 90 90 90 54 54 54 18 18 18
40404- 6 6 6 0 0 0 0 0 0 0 0 0
40405- 0 0 0 0 0 0 0 0 0 0 0 0
40406- 0 0 0 0 0 0 0 0 0 0 0 0
40407- 0 0 0 0 0 0 0 0 0 0 0 0
40408- 0 0 0 0 0 0 0 0 0 0 0 0
40409- 0 0 0 0 0 0 0 0 0 0 0 0
40410- 0 0 0 0 0 0 0 0 0 0 0 0
40411- 0 0 0 0 0 0 0 0 0 0 0 0
40412- 0 0 0 0 0 0 0 0 0 0 0 0
40413- 0 0 0 0 0 0 0 0 0 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 10 10 10
40417- 30 30 30 78 78 78 46 46 46 22 22 22
40418-137 92 6 210 162 10 239 182 13 238 190 10
40419-238 202 15 241 208 19 246 215 20 246 215 20
40420-241 208 19 203 166 17 185 133 11 210 150 10
40421-216 158 10 210 150 10 102 78 10 2 2 6
40422- 6 6 6 54 54 54 14 14 14 2 2 6
40423- 2 2 6 62 62 62 74 74 74 30 30 30
40424- 10 10 10 0 0 0 0 0 0 0 0 0
40425- 0 0 0 0 0 0 0 0 0 0 0 0
40426- 0 0 0 0 0 0 0 0 0 0 0 0
40427- 0 0 0 0 0 0 0 0 0 0 0 0
40428- 0 0 0 0 0 0 0 0 0 0 0 0
40429- 0 0 0 0 0 0 0 0 0 0 0 0
40430- 0 0 0 0 0 0 0 0 0 0 0 0
40431- 0 0 0 0 0 0 0 0 0 0 0 0
40432- 0 0 0 0 0 0 0 0 0 0 0 0
40433- 0 0 0 0 0 0 0 0 0 0 0 0
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 10 10 10
40437- 34 34 34 78 78 78 50 50 50 6 6 6
40438- 94 70 30 139 102 15 190 146 13 226 184 13
40439-232 200 30 232 195 16 215 174 15 190 146 13
40440-168 122 10 192 133 9 210 150 10 213 154 11
40441-202 150 34 182 157 106 101 98 89 2 2 6
40442- 2 2 6 78 78 78 116 116 116 58 58 58
40443- 2 2 6 22 22 22 90 90 90 46 46 46
40444- 18 18 18 6 6 6 0 0 0 0 0 0
40445- 0 0 0 0 0 0 0 0 0 0 0 0
40446- 0 0 0 0 0 0 0 0 0 0 0 0
40447- 0 0 0 0 0 0 0 0 0 0 0 0
40448- 0 0 0 0 0 0 0 0 0 0 0 0
40449- 0 0 0 0 0 0 0 0 0 0 0 0
40450- 0 0 0 0 0 0 0 0 0 0 0 0
40451- 0 0 0 0 0 0 0 0 0 0 0 0
40452- 0 0 0 0 0 0 0 0 0 0 0 0
40453- 0 0 0 0 0 0 0 0 0 0 0 0
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 10 10 10
40457- 38 38 38 86 86 86 50 50 50 6 6 6
40458-128 128 128 174 154 114 156 107 11 168 122 10
40459-198 155 10 184 144 12 197 138 11 200 144 11
40460-206 145 10 206 145 10 197 138 11 188 164 115
40461-195 195 195 198 198 198 174 174 174 14 14 14
40462- 2 2 6 22 22 22 116 116 116 116 116 116
40463- 22 22 22 2 2 6 74 74 74 70 70 70
40464- 30 30 30 10 10 10 0 0 0 0 0 0
40465- 0 0 0 0 0 0 0 0 0 0 0 0
40466- 0 0 0 0 0 0 0 0 0 0 0 0
40467- 0 0 0 0 0 0 0 0 0 0 0 0
40468- 0 0 0 0 0 0 0 0 0 0 0 0
40469- 0 0 0 0 0 0 0 0 0 0 0 0
40470- 0 0 0 0 0 0 0 0 0 0 0 0
40471- 0 0 0 0 0 0 0 0 0 0 0 0
40472- 0 0 0 0 0 0 0 0 0 0 0 0
40473- 0 0 0 0 0 0 0 0 0 0 0 0
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 6 6 6 18 18 18
40477- 50 50 50 101 101 101 26 26 26 10 10 10
40478-138 138 138 190 190 190 174 154 114 156 107 11
40479-197 138 11 200 144 11 197 138 11 192 133 9
40480-180 123 7 190 142 34 190 178 144 187 187 187
40481-202 202 202 221 221 221 214 214 214 66 66 66
40482- 2 2 6 2 2 6 50 50 50 62 62 62
40483- 6 6 6 2 2 6 10 10 10 90 90 90
40484- 50 50 50 18 18 18 6 6 6 0 0 0
40485- 0 0 0 0 0 0 0 0 0 0 0 0
40486- 0 0 0 0 0 0 0 0 0 0 0 0
40487- 0 0 0 0 0 0 0 0 0 0 0 0
40488- 0 0 0 0 0 0 0 0 0 0 0 0
40489- 0 0 0 0 0 0 0 0 0 0 0 0
40490- 0 0 0 0 0 0 0 0 0 0 0 0
40491- 0 0 0 0 0 0 0 0 0 0 0 0
40492- 0 0 0 0 0 0 0 0 0 0 0 0
40493- 0 0 0 0 0 0 0 0 0 0 0 0
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 10 10 10 34 34 34
40497- 74 74 74 74 74 74 2 2 6 6 6 6
40498-144 144 144 198 198 198 190 190 190 178 166 146
40499-154 121 60 156 107 11 156 107 11 168 124 44
40500-174 154 114 187 187 187 190 190 190 210 210 210
40501-246 246 246 253 253 253 253 253 253 182 182 182
40502- 6 6 6 2 2 6 2 2 6 2 2 6
40503- 2 2 6 2 2 6 2 2 6 62 62 62
40504- 74 74 74 34 34 34 14 14 14 0 0 0
40505- 0 0 0 0 0 0 0 0 0 0 0 0
40506- 0 0 0 0 0 0 0 0 0 0 0 0
40507- 0 0 0 0 0 0 0 0 0 0 0 0
40508- 0 0 0 0 0 0 0 0 0 0 0 0
40509- 0 0 0 0 0 0 0 0 0 0 0 0
40510- 0 0 0 0 0 0 0 0 0 0 0 0
40511- 0 0 0 0 0 0 0 0 0 0 0 0
40512- 0 0 0 0 0 0 0 0 0 0 0 0
40513- 0 0 0 0 0 0 0 0 0 0 0 0
40514- 0 0 0 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 10 10 10 22 22 22 54 54 54
40517- 94 94 94 18 18 18 2 2 6 46 46 46
40518-234 234 234 221 221 221 190 190 190 190 190 190
40519-190 190 190 187 187 187 187 187 187 190 190 190
40520-190 190 190 195 195 195 214 214 214 242 242 242
40521-253 253 253 253 253 253 253 253 253 253 253 253
40522- 82 82 82 2 2 6 2 2 6 2 2 6
40523- 2 2 6 2 2 6 2 2 6 14 14 14
40524- 86 86 86 54 54 54 22 22 22 6 6 6
40525- 0 0 0 0 0 0 0 0 0 0 0 0
40526- 0 0 0 0 0 0 0 0 0 0 0 0
40527- 0 0 0 0 0 0 0 0 0 0 0 0
40528- 0 0 0 0 0 0 0 0 0 0 0 0
40529- 0 0 0 0 0 0 0 0 0 0 0 0
40530- 0 0 0 0 0 0 0 0 0 0 0 0
40531- 0 0 0 0 0 0 0 0 0 0 0 0
40532- 0 0 0 0 0 0 0 0 0 0 0 0
40533- 0 0 0 0 0 0 0 0 0 0 0 0
40534- 0 0 0 0 0 0 0 0 0 0 0 0
40535- 0 0 0 0 0 0 0 0 0 0 0 0
40536- 6 6 6 18 18 18 46 46 46 90 90 90
40537- 46 46 46 18 18 18 6 6 6 182 182 182
40538-253 253 253 246 246 246 206 206 206 190 190 190
40539-190 190 190 190 190 190 190 190 190 190 190 190
40540-206 206 206 231 231 231 250 250 250 253 253 253
40541-253 253 253 253 253 253 253 253 253 253 253 253
40542-202 202 202 14 14 14 2 2 6 2 2 6
40543- 2 2 6 2 2 6 2 2 6 2 2 6
40544- 42 42 42 86 86 86 42 42 42 18 18 18
40545- 6 6 6 0 0 0 0 0 0 0 0 0
40546- 0 0 0 0 0 0 0 0 0 0 0 0
40547- 0 0 0 0 0 0 0 0 0 0 0 0
40548- 0 0 0 0 0 0 0 0 0 0 0 0
40549- 0 0 0 0 0 0 0 0 0 0 0 0
40550- 0 0 0 0 0 0 0 0 0 0 0 0
40551- 0 0 0 0 0 0 0 0 0 0 0 0
40552- 0 0 0 0 0 0 0 0 0 0 0 0
40553- 0 0 0 0 0 0 0 0 0 0 0 0
40554- 0 0 0 0 0 0 0 0 0 0 0 0
40555- 0 0 0 0 0 0 0 0 0 6 6 6
40556- 14 14 14 38 38 38 74 74 74 66 66 66
40557- 2 2 6 6 6 6 90 90 90 250 250 250
40558-253 253 253 253 253 253 238 238 238 198 198 198
40559-190 190 190 190 190 190 195 195 195 221 221 221
40560-246 246 246 253 253 253 253 253 253 253 253 253
40561-253 253 253 253 253 253 253 253 253 253 253 253
40562-253 253 253 82 82 82 2 2 6 2 2 6
40563- 2 2 6 2 2 6 2 2 6 2 2 6
40564- 2 2 6 78 78 78 70 70 70 34 34 34
40565- 14 14 14 6 6 6 0 0 0 0 0 0
40566- 0 0 0 0 0 0 0 0 0 0 0 0
40567- 0 0 0 0 0 0 0 0 0 0 0 0
40568- 0 0 0 0 0 0 0 0 0 0 0 0
40569- 0 0 0 0 0 0 0 0 0 0 0 0
40570- 0 0 0 0 0 0 0 0 0 0 0 0
40571- 0 0 0 0 0 0 0 0 0 0 0 0
40572- 0 0 0 0 0 0 0 0 0 0 0 0
40573- 0 0 0 0 0 0 0 0 0 0 0 0
40574- 0 0 0 0 0 0 0 0 0 0 0 0
40575- 0 0 0 0 0 0 0 0 0 14 14 14
40576- 34 34 34 66 66 66 78 78 78 6 6 6
40577- 2 2 6 18 18 18 218 218 218 253 253 253
40578-253 253 253 253 253 253 253 253 253 246 246 246
40579-226 226 226 231 231 231 246 246 246 253 253 253
40580-253 253 253 253 253 253 253 253 253 253 253 253
40581-253 253 253 253 253 253 253 253 253 253 253 253
40582-253 253 253 178 178 178 2 2 6 2 2 6
40583- 2 2 6 2 2 6 2 2 6 2 2 6
40584- 2 2 6 18 18 18 90 90 90 62 62 62
40585- 30 30 30 10 10 10 0 0 0 0 0 0
40586- 0 0 0 0 0 0 0 0 0 0 0 0
40587- 0 0 0 0 0 0 0 0 0 0 0 0
40588- 0 0 0 0 0 0 0 0 0 0 0 0
40589- 0 0 0 0 0 0 0 0 0 0 0 0
40590- 0 0 0 0 0 0 0 0 0 0 0 0
40591- 0 0 0 0 0 0 0 0 0 0 0 0
40592- 0 0 0 0 0 0 0 0 0 0 0 0
40593- 0 0 0 0 0 0 0 0 0 0 0 0
40594- 0 0 0 0 0 0 0 0 0 0 0 0
40595- 0 0 0 0 0 0 10 10 10 26 26 26
40596- 58 58 58 90 90 90 18 18 18 2 2 6
40597- 2 2 6 110 110 110 253 253 253 253 253 253
40598-253 253 253 253 253 253 253 253 253 253 253 253
40599-250 250 250 253 253 253 253 253 253 253 253 253
40600-253 253 253 253 253 253 253 253 253 253 253 253
40601-253 253 253 253 253 253 253 253 253 253 253 253
40602-253 253 253 231 231 231 18 18 18 2 2 6
40603- 2 2 6 2 2 6 2 2 6 2 2 6
40604- 2 2 6 2 2 6 18 18 18 94 94 94
40605- 54 54 54 26 26 26 10 10 10 0 0 0
40606- 0 0 0 0 0 0 0 0 0 0 0 0
40607- 0 0 0 0 0 0 0 0 0 0 0 0
40608- 0 0 0 0 0 0 0 0 0 0 0 0
40609- 0 0 0 0 0 0 0 0 0 0 0 0
40610- 0 0 0 0 0 0 0 0 0 0 0 0
40611- 0 0 0 0 0 0 0 0 0 0 0 0
40612- 0 0 0 0 0 0 0 0 0 0 0 0
40613- 0 0 0 0 0 0 0 0 0 0 0 0
40614- 0 0 0 0 0 0 0 0 0 0 0 0
40615- 0 0 0 6 6 6 22 22 22 50 50 50
40616- 90 90 90 26 26 26 2 2 6 2 2 6
40617- 14 14 14 195 195 195 250 250 250 253 253 253
40618-253 253 253 253 253 253 253 253 253 253 253 253
40619-253 253 253 253 253 253 253 253 253 253 253 253
40620-253 253 253 253 253 253 253 253 253 253 253 253
40621-253 253 253 253 253 253 253 253 253 253 253 253
40622-250 250 250 242 242 242 54 54 54 2 2 6
40623- 2 2 6 2 2 6 2 2 6 2 2 6
40624- 2 2 6 2 2 6 2 2 6 38 38 38
40625- 86 86 86 50 50 50 22 22 22 6 6 6
40626- 0 0 0 0 0 0 0 0 0 0 0 0
40627- 0 0 0 0 0 0 0 0 0 0 0 0
40628- 0 0 0 0 0 0 0 0 0 0 0 0
40629- 0 0 0 0 0 0 0 0 0 0 0 0
40630- 0 0 0 0 0 0 0 0 0 0 0 0
40631- 0 0 0 0 0 0 0 0 0 0 0 0
40632- 0 0 0 0 0 0 0 0 0 0 0 0
40633- 0 0 0 0 0 0 0 0 0 0 0 0
40634- 0 0 0 0 0 0 0 0 0 0 0 0
40635- 6 6 6 14 14 14 38 38 38 82 82 82
40636- 34 34 34 2 2 6 2 2 6 2 2 6
40637- 42 42 42 195 195 195 246 246 246 253 253 253
40638-253 253 253 253 253 253 253 253 253 250 250 250
40639-242 242 242 242 242 242 250 250 250 253 253 253
40640-253 253 253 253 253 253 253 253 253 253 253 253
40641-253 253 253 250 250 250 246 246 246 238 238 238
40642-226 226 226 231 231 231 101 101 101 6 6 6
40643- 2 2 6 2 2 6 2 2 6 2 2 6
40644- 2 2 6 2 2 6 2 2 6 2 2 6
40645- 38 38 38 82 82 82 42 42 42 14 14 14
40646- 6 6 6 0 0 0 0 0 0 0 0 0
40647- 0 0 0 0 0 0 0 0 0 0 0 0
40648- 0 0 0 0 0 0 0 0 0 0 0 0
40649- 0 0 0 0 0 0 0 0 0 0 0 0
40650- 0 0 0 0 0 0 0 0 0 0 0 0
40651- 0 0 0 0 0 0 0 0 0 0 0 0
40652- 0 0 0 0 0 0 0 0 0 0 0 0
40653- 0 0 0 0 0 0 0 0 0 0 0 0
40654- 0 0 0 0 0 0 0 0 0 0 0 0
40655- 10 10 10 26 26 26 62 62 62 66 66 66
40656- 2 2 6 2 2 6 2 2 6 6 6 6
40657- 70 70 70 170 170 170 206 206 206 234 234 234
40658-246 246 246 250 250 250 250 250 250 238 238 238
40659-226 226 226 231 231 231 238 238 238 250 250 250
40660-250 250 250 250 250 250 246 246 246 231 231 231
40661-214 214 214 206 206 206 202 202 202 202 202 202
40662-198 198 198 202 202 202 182 182 182 18 18 18
40663- 2 2 6 2 2 6 2 2 6 2 2 6
40664- 2 2 6 2 2 6 2 2 6 2 2 6
40665- 2 2 6 62 62 62 66 66 66 30 30 30
40666- 10 10 10 0 0 0 0 0 0 0 0 0
40667- 0 0 0 0 0 0 0 0 0 0 0 0
40668- 0 0 0 0 0 0 0 0 0 0 0 0
40669- 0 0 0 0 0 0 0 0 0 0 0 0
40670- 0 0 0 0 0 0 0 0 0 0 0 0
40671- 0 0 0 0 0 0 0 0 0 0 0 0
40672- 0 0 0 0 0 0 0 0 0 0 0 0
40673- 0 0 0 0 0 0 0 0 0 0 0 0
40674- 0 0 0 0 0 0 0 0 0 0 0 0
40675- 14 14 14 42 42 42 82 82 82 18 18 18
40676- 2 2 6 2 2 6 2 2 6 10 10 10
40677- 94 94 94 182 182 182 218 218 218 242 242 242
40678-250 250 250 253 253 253 253 253 253 250 250 250
40679-234 234 234 253 253 253 253 253 253 253 253 253
40680-253 253 253 253 253 253 253 253 253 246 246 246
40681-238 238 238 226 226 226 210 210 210 202 202 202
40682-195 195 195 195 195 195 210 210 210 158 158 158
40683- 6 6 6 14 14 14 50 50 50 14 14 14
40684- 2 2 6 2 2 6 2 2 6 2 2 6
40685- 2 2 6 6 6 6 86 86 86 46 46 46
40686- 18 18 18 6 6 6 0 0 0 0 0 0
40687- 0 0 0 0 0 0 0 0 0 0 0 0
40688- 0 0 0 0 0 0 0 0 0 0 0 0
40689- 0 0 0 0 0 0 0 0 0 0 0 0
40690- 0 0 0 0 0 0 0 0 0 0 0 0
40691- 0 0 0 0 0 0 0 0 0 0 0 0
40692- 0 0 0 0 0 0 0 0 0 0 0 0
40693- 0 0 0 0 0 0 0 0 0 0 0 0
40694- 0 0 0 0 0 0 0 0 0 6 6 6
40695- 22 22 22 54 54 54 70 70 70 2 2 6
40696- 2 2 6 10 10 10 2 2 6 22 22 22
40697-166 166 166 231 231 231 250 250 250 253 253 253
40698-253 253 253 253 253 253 253 253 253 250 250 250
40699-242 242 242 253 253 253 253 253 253 253 253 253
40700-253 253 253 253 253 253 253 253 253 253 253 253
40701-253 253 253 253 253 253 253 253 253 246 246 246
40702-231 231 231 206 206 206 198 198 198 226 226 226
40703- 94 94 94 2 2 6 6 6 6 38 38 38
40704- 30 30 30 2 2 6 2 2 6 2 2 6
40705- 2 2 6 2 2 6 62 62 62 66 66 66
40706- 26 26 26 10 10 10 0 0 0 0 0 0
40707- 0 0 0 0 0 0 0 0 0 0 0 0
40708- 0 0 0 0 0 0 0 0 0 0 0 0
40709- 0 0 0 0 0 0 0 0 0 0 0 0
40710- 0 0 0 0 0 0 0 0 0 0 0 0
40711- 0 0 0 0 0 0 0 0 0 0 0 0
40712- 0 0 0 0 0 0 0 0 0 0 0 0
40713- 0 0 0 0 0 0 0 0 0 0 0 0
40714- 0 0 0 0 0 0 0 0 0 10 10 10
40715- 30 30 30 74 74 74 50 50 50 2 2 6
40716- 26 26 26 26 26 26 2 2 6 106 106 106
40717-238 238 238 253 253 253 253 253 253 253 253 253
40718-253 253 253 253 253 253 253 253 253 253 253 253
40719-253 253 253 253 253 253 253 253 253 253 253 253
40720-253 253 253 253 253 253 253 253 253 253 253 253
40721-253 253 253 253 253 253 253 253 253 253 253 253
40722-253 253 253 246 246 246 218 218 218 202 202 202
40723-210 210 210 14 14 14 2 2 6 2 2 6
40724- 30 30 30 22 22 22 2 2 6 2 2 6
40725- 2 2 6 2 2 6 18 18 18 86 86 86
40726- 42 42 42 14 14 14 0 0 0 0 0 0
40727- 0 0 0 0 0 0 0 0 0 0 0 0
40728- 0 0 0 0 0 0 0 0 0 0 0 0
40729- 0 0 0 0 0 0 0 0 0 0 0 0
40730- 0 0 0 0 0 0 0 0 0 0 0 0
40731- 0 0 0 0 0 0 0 0 0 0 0 0
40732- 0 0 0 0 0 0 0 0 0 0 0 0
40733- 0 0 0 0 0 0 0 0 0 0 0 0
40734- 0 0 0 0 0 0 0 0 0 14 14 14
40735- 42 42 42 90 90 90 22 22 22 2 2 6
40736- 42 42 42 2 2 6 18 18 18 218 218 218
40737-253 253 253 253 253 253 253 253 253 253 253 253
40738-253 253 253 253 253 253 253 253 253 253 253 253
40739-253 253 253 253 253 253 253 253 253 253 253 253
40740-253 253 253 253 253 253 253 253 253 253 253 253
40741-253 253 253 253 253 253 253 253 253 253 253 253
40742-253 253 253 253 253 253 250 250 250 221 221 221
40743-218 218 218 101 101 101 2 2 6 14 14 14
40744- 18 18 18 38 38 38 10 10 10 2 2 6
40745- 2 2 6 2 2 6 2 2 6 78 78 78
40746- 58 58 58 22 22 22 6 6 6 0 0 0
40747- 0 0 0 0 0 0 0 0 0 0 0 0
40748- 0 0 0 0 0 0 0 0 0 0 0 0
40749- 0 0 0 0 0 0 0 0 0 0 0 0
40750- 0 0 0 0 0 0 0 0 0 0 0 0
40751- 0 0 0 0 0 0 0 0 0 0 0 0
40752- 0 0 0 0 0 0 0 0 0 0 0 0
40753- 0 0 0 0 0 0 0 0 0 0 0 0
40754- 0 0 0 0 0 0 6 6 6 18 18 18
40755- 54 54 54 82 82 82 2 2 6 26 26 26
40756- 22 22 22 2 2 6 123 123 123 253 253 253
40757-253 253 253 253 253 253 253 253 253 253 253 253
40758-253 253 253 253 253 253 253 253 253 253 253 253
40759-253 253 253 253 253 253 253 253 253 253 253 253
40760-253 253 253 253 253 253 253 253 253 253 253 253
40761-253 253 253 253 253 253 253 253 253 253 253 253
40762-253 253 253 253 253 253 253 253 253 250 250 250
40763-238 238 238 198 198 198 6 6 6 38 38 38
40764- 58 58 58 26 26 26 38 38 38 2 2 6
40765- 2 2 6 2 2 6 2 2 6 46 46 46
40766- 78 78 78 30 30 30 10 10 10 0 0 0
40767- 0 0 0 0 0 0 0 0 0 0 0 0
40768- 0 0 0 0 0 0 0 0 0 0 0 0
40769- 0 0 0 0 0 0 0 0 0 0 0 0
40770- 0 0 0 0 0 0 0 0 0 0 0 0
40771- 0 0 0 0 0 0 0 0 0 0 0 0
40772- 0 0 0 0 0 0 0 0 0 0 0 0
40773- 0 0 0 0 0 0 0 0 0 0 0 0
40774- 0 0 0 0 0 0 10 10 10 30 30 30
40775- 74 74 74 58 58 58 2 2 6 42 42 42
40776- 2 2 6 22 22 22 231 231 231 253 253 253
40777-253 253 253 253 253 253 253 253 253 253 253 253
40778-253 253 253 253 253 253 253 253 253 250 250 250
40779-253 253 253 253 253 253 253 253 253 253 253 253
40780-253 253 253 253 253 253 253 253 253 253 253 253
40781-253 253 253 253 253 253 253 253 253 253 253 253
40782-253 253 253 253 253 253 253 253 253 253 253 253
40783-253 253 253 246 246 246 46 46 46 38 38 38
40784- 42 42 42 14 14 14 38 38 38 14 14 14
40785- 2 2 6 2 2 6 2 2 6 6 6 6
40786- 86 86 86 46 46 46 14 14 14 0 0 0
40787- 0 0 0 0 0 0 0 0 0 0 0 0
40788- 0 0 0 0 0 0 0 0 0 0 0 0
40789- 0 0 0 0 0 0 0 0 0 0 0 0
40790- 0 0 0 0 0 0 0 0 0 0 0 0
40791- 0 0 0 0 0 0 0 0 0 0 0 0
40792- 0 0 0 0 0 0 0 0 0 0 0 0
40793- 0 0 0 0 0 0 0 0 0 0 0 0
40794- 0 0 0 6 6 6 14 14 14 42 42 42
40795- 90 90 90 18 18 18 18 18 18 26 26 26
40796- 2 2 6 116 116 116 253 253 253 253 253 253
40797-253 253 253 253 253 253 253 253 253 253 253 253
40798-253 253 253 253 253 253 250 250 250 238 238 238
40799-253 253 253 253 253 253 253 253 253 253 253 253
40800-253 253 253 253 253 253 253 253 253 253 253 253
40801-253 253 253 253 253 253 253 253 253 253 253 253
40802-253 253 253 253 253 253 253 253 253 253 253 253
40803-253 253 253 253 253 253 94 94 94 6 6 6
40804- 2 2 6 2 2 6 10 10 10 34 34 34
40805- 2 2 6 2 2 6 2 2 6 2 2 6
40806- 74 74 74 58 58 58 22 22 22 6 6 6
40807- 0 0 0 0 0 0 0 0 0 0 0 0
40808- 0 0 0 0 0 0 0 0 0 0 0 0
40809- 0 0 0 0 0 0 0 0 0 0 0 0
40810- 0 0 0 0 0 0 0 0 0 0 0 0
40811- 0 0 0 0 0 0 0 0 0 0 0 0
40812- 0 0 0 0 0 0 0 0 0 0 0 0
40813- 0 0 0 0 0 0 0 0 0 0 0 0
40814- 0 0 0 10 10 10 26 26 26 66 66 66
40815- 82 82 82 2 2 6 38 38 38 6 6 6
40816- 14 14 14 210 210 210 253 253 253 253 253 253
40817-253 253 253 253 253 253 253 253 253 253 253 253
40818-253 253 253 253 253 253 246 246 246 242 242 242
40819-253 253 253 253 253 253 253 253 253 253 253 253
40820-253 253 253 253 253 253 253 253 253 253 253 253
40821-253 253 253 253 253 253 253 253 253 253 253 253
40822-253 253 253 253 253 253 253 253 253 253 253 253
40823-253 253 253 253 253 253 144 144 144 2 2 6
40824- 2 2 6 2 2 6 2 2 6 46 46 46
40825- 2 2 6 2 2 6 2 2 6 2 2 6
40826- 42 42 42 74 74 74 30 30 30 10 10 10
40827- 0 0 0 0 0 0 0 0 0 0 0 0
40828- 0 0 0 0 0 0 0 0 0 0 0 0
40829- 0 0 0 0 0 0 0 0 0 0 0 0
40830- 0 0 0 0 0 0 0 0 0 0 0 0
40831- 0 0 0 0 0 0 0 0 0 0 0 0
40832- 0 0 0 0 0 0 0 0 0 0 0 0
40833- 0 0 0 0 0 0 0 0 0 0 0 0
40834- 6 6 6 14 14 14 42 42 42 90 90 90
40835- 26 26 26 6 6 6 42 42 42 2 2 6
40836- 74 74 74 250 250 250 253 253 253 253 253 253
40837-253 253 253 253 253 253 253 253 253 253 253 253
40838-253 253 253 253 253 253 242 242 242 242 242 242
40839-253 253 253 253 253 253 253 253 253 253 253 253
40840-253 253 253 253 253 253 253 253 253 253 253 253
40841-253 253 253 253 253 253 253 253 253 253 253 253
40842-253 253 253 253 253 253 253 253 253 253 253 253
40843-253 253 253 253 253 253 182 182 182 2 2 6
40844- 2 2 6 2 2 6 2 2 6 46 46 46
40845- 2 2 6 2 2 6 2 2 6 2 2 6
40846- 10 10 10 86 86 86 38 38 38 10 10 10
40847- 0 0 0 0 0 0 0 0 0 0 0 0
40848- 0 0 0 0 0 0 0 0 0 0 0 0
40849- 0 0 0 0 0 0 0 0 0 0 0 0
40850- 0 0 0 0 0 0 0 0 0 0 0 0
40851- 0 0 0 0 0 0 0 0 0 0 0 0
40852- 0 0 0 0 0 0 0 0 0 0 0 0
40853- 0 0 0 0 0 0 0 0 0 0 0 0
40854- 10 10 10 26 26 26 66 66 66 82 82 82
40855- 2 2 6 22 22 22 18 18 18 2 2 6
40856-149 149 149 253 253 253 253 253 253 253 253 253
40857-253 253 253 253 253 253 253 253 253 253 253 253
40858-253 253 253 253 253 253 234 234 234 242 242 242
40859-253 253 253 253 253 253 253 253 253 253 253 253
40860-253 253 253 253 253 253 253 253 253 253 253 253
40861-253 253 253 253 253 253 253 253 253 253 253 253
40862-253 253 253 253 253 253 253 253 253 253 253 253
40863-253 253 253 253 253 253 206 206 206 2 2 6
40864- 2 2 6 2 2 6 2 2 6 38 38 38
40865- 2 2 6 2 2 6 2 2 6 2 2 6
40866- 6 6 6 86 86 86 46 46 46 14 14 14
40867- 0 0 0 0 0 0 0 0 0 0 0 0
40868- 0 0 0 0 0 0 0 0 0 0 0 0
40869- 0 0 0 0 0 0 0 0 0 0 0 0
40870- 0 0 0 0 0 0 0 0 0 0 0 0
40871- 0 0 0 0 0 0 0 0 0 0 0 0
40872- 0 0 0 0 0 0 0 0 0 0 0 0
40873- 0 0 0 0 0 0 0 0 0 6 6 6
40874- 18 18 18 46 46 46 86 86 86 18 18 18
40875- 2 2 6 34 34 34 10 10 10 6 6 6
40876-210 210 210 253 253 253 253 253 253 253 253 253
40877-253 253 253 253 253 253 253 253 253 253 253 253
40878-253 253 253 253 253 253 234 234 234 242 242 242
40879-253 253 253 253 253 253 253 253 253 253 253 253
40880-253 253 253 253 253 253 253 253 253 253 253 253
40881-253 253 253 253 253 253 253 253 253 253 253 253
40882-253 253 253 253 253 253 253 253 253 253 253 253
40883-253 253 253 253 253 253 221 221 221 6 6 6
40884- 2 2 6 2 2 6 6 6 6 30 30 30
40885- 2 2 6 2 2 6 2 2 6 2 2 6
40886- 2 2 6 82 82 82 54 54 54 18 18 18
40887- 6 6 6 0 0 0 0 0 0 0 0 0
40888- 0 0 0 0 0 0 0 0 0 0 0 0
40889- 0 0 0 0 0 0 0 0 0 0 0 0
40890- 0 0 0 0 0 0 0 0 0 0 0 0
40891- 0 0 0 0 0 0 0 0 0 0 0 0
40892- 0 0 0 0 0 0 0 0 0 0 0 0
40893- 0 0 0 0 0 0 0 0 0 10 10 10
40894- 26 26 26 66 66 66 62 62 62 2 2 6
40895- 2 2 6 38 38 38 10 10 10 26 26 26
40896-238 238 238 253 253 253 253 253 253 253 253 253
40897-253 253 253 253 253 253 253 253 253 253 253 253
40898-253 253 253 253 253 253 231 231 231 238 238 238
40899-253 253 253 253 253 253 253 253 253 253 253 253
40900-253 253 253 253 253 253 253 253 253 253 253 253
40901-253 253 253 253 253 253 253 253 253 253 253 253
40902-253 253 253 253 253 253 253 253 253 253 253 253
40903-253 253 253 253 253 253 231 231 231 6 6 6
40904- 2 2 6 2 2 6 10 10 10 30 30 30
40905- 2 2 6 2 2 6 2 2 6 2 2 6
40906- 2 2 6 66 66 66 58 58 58 22 22 22
40907- 6 6 6 0 0 0 0 0 0 0 0 0
40908- 0 0 0 0 0 0 0 0 0 0 0 0
40909- 0 0 0 0 0 0 0 0 0 0 0 0
40910- 0 0 0 0 0 0 0 0 0 0 0 0
40911- 0 0 0 0 0 0 0 0 0 0 0 0
40912- 0 0 0 0 0 0 0 0 0 0 0 0
40913- 0 0 0 0 0 0 0 0 0 10 10 10
40914- 38 38 38 78 78 78 6 6 6 2 2 6
40915- 2 2 6 46 46 46 14 14 14 42 42 42
40916-246 246 246 253 253 253 253 253 253 253 253 253
40917-253 253 253 253 253 253 253 253 253 253 253 253
40918-253 253 253 253 253 253 231 231 231 242 242 242
40919-253 253 253 253 253 253 253 253 253 253 253 253
40920-253 253 253 253 253 253 253 253 253 253 253 253
40921-253 253 253 253 253 253 253 253 253 253 253 253
40922-253 253 253 253 253 253 253 253 253 253 253 253
40923-253 253 253 253 253 253 234 234 234 10 10 10
40924- 2 2 6 2 2 6 22 22 22 14 14 14
40925- 2 2 6 2 2 6 2 2 6 2 2 6
40926- 2 2 6 66 66 66 62 62 62 22 22 22
40927- 6 6 6 0 0 0 0 0 0 0 0 0
40928- 0 0 0 0 0 0 0 0 0 0 0 0
40929- 0 0 0 0 0 0 0 0 0 0 0 0
40930- 0 0 0 0 0 0 0 0 0 0 0 0
40931- 0 0 0 0 0 0 0 0 0 0 0 0
40932- 0 0 0 0 0 0 0 0 0 0 0 0
40933- 0 0 0 0 0 0 6 6 6 18 18 18
40934- 50 50 50 74 74 74 2 2 6 2 2 6
40935- 14 14 14 70 70 70 34 34 34 62 62 62
40936-250 250 250 253 253 253 253 253 253 253 253 253
40937-253 253 253 253 253 253 253 253 253 253 253 253
40938-253 253 253 253 253 253 231 231 231 246 246 246
40939-253 253 253 253 253 253 253 253 253 253 253 253
40940-253 253 253 253 253 253 253 253 253 253 253 253
40941-253 253 253 253 253 253 253 253 253 253 253 253
40942-253 253 253 253 253 253 253 253 253 253 253 253
40943-253 253 253 253 253 253 234 234 234 14 14 14
40944- 2 2 6 2 2 6 30 30 30 2 2 6
40945- 2 2 6 2 2 6 2 2 6 2 2 6
40946- 2 2 6 66 66 66 62 62 62 22 22 22
40947- 6 6 6 0 0 0 0 0 0 0 0 0
40948- 0 0 0 0 0 0 0 0 0 0 0 0
40949- 0 0 0 0 0 0 0 0 0 0 0 0
40950- 0 0 0 0 0 0 0 0 0 0 0 0
40951- 0 0 0 0 0 0 0 0 0 0 0 0
40952- 0 0 0 0 0 0 0 0 0 0 0 0
40953- 0 0 0 0 0 0 6 6 6 18 18 18
40954- 54 54 54 62 62 62 2 2 6 2 2 6
40955- 2 2 6 30 30 30 46 46 46 70 70 70
40956-250 250 250 253 253 253 253 253 253 253 253 253
40957-253 253 253 253 253 253 253 253 253 253 253 253
40958-253 253 253 253 253 253 231 231 231 246 246 246
40959-253 253 253 253 253 253 253 253 253 253 253 253
40960-253 253 253 253 253 253 253 253 253 253 253 253
40961-253 253 253 253 253 253 253 253 253 253 253 253
40962-253 253 253 253 253 253 253 253 253 253 253 253
40963-253 253 253 253 253 253 226 226 226 10 10 10
40964- 2 2 6 6 6 6 30 30 30 2 2 6
40965- 2 2 6 2 2 6 2 2 6 2 2 6
40966- 2 2 6 66 66 66 58 58 58 22 22 22
40967- 6 6 6 0 0 0 0 0 0 0 0 0
40968- 0 0 0 0 0 0 0 0 0 0 0 0
40969- 0 0 0 0 0 0 0 0 0 0 0 0
40970- 0 0 0 0 0 0 0 0 0 0 0 0
40971- 0 0 0 0 0 0 0 0 0 0 0 0
40972- 0 0 0 0 0 0 0 0 0 0 0 0
40973- 0 0 0 0 0 0 6 6 6 22 22 22
40974- 58 58 58 62 62 62 2 2 6 2 2 6
40975- 2 2 6 2 2 6 30 30 30 78 78 78
40976-250 250 250 253 253 253 253 253 253 253 253 253
40977-253 253 253 253 253 253 253 253 253 253 253 253
40978-253 253 253 253 253 253 231 231 231 246 246 246
40979-253 253 253 253 253 253 253 253 253 253 253 253
40980-253 253 253 253 253 253 253 253 253 253 253 253
40981-253 253 253 253 253 253 253 253 253 253 253 253
40982-253 253 253 253 253 253 253 253 253 253 253 253
40983-253 253 253 253 253 253 206 206 206 2 2 6
40984- 22 22 22 34 34 34 18 14 6 22 22 22
40985- 26 26 26 18 18 18 6 6 6 2 2 6
40986- 2 2 6 82 82 82 54 54 54 18 18 18
40987- 6 6 6 0 0 0 0 0 0 0 0 0
40988- 0 0 0 0 0 0 0 0 0 0 0 0
40989- 0 0 0 0 0 0 0 0 0 0 0 0
40990- 0 0 0 0 0 0 0 0 0 0 0 0
40991- 0 0 0 0 0 0 0 0 0 0 0 0
40992- 0 0 0 0 0 0 0 0 0 0 0 0
40993- 0 0 0 0 0 0 6 6 6 26 26 26
40994- 62 62 62 106 106 106 74 54 14 185 133 11
40995-210 162 10 121 92 8 6 6 6 62 62 62
40996-238 238 238 253 253 253 253 253 253 253 253 253
40997-253 253 253 253 253 253 253 253 253 253 253 253
40998-253 253 253 253 253 253 231 231 231 246 246 246
40999-253 253 253 253 253 253 253 253 253 253 253 253
41000-253 253 253 253 253 253 253 253 253 253 253 253
41001-253 253 253 253 253 253 253 253 253 253 253 253
41002-253 253 253 253 253 253 253 253 253 253 253 253
41003-253 253 253 253 253 253 158 158 158 18 18 18
41004- 14 14 14 2 2 6 2 2 6 2 2 6
41005- 6 6 6 18 18 18 66 66 66 38 38 38
41006- 6 6 6 94 94 94 50 50 50 18 18 18
41007- 6 6 6 0 0 0 0 0 0 0 0 0
41008- 0 0 0 0 0 0 0 0 0 0 0 0
41009- 0 0 0 0 0 0 0 0 0 0 0 0
41010- 0 0 0 0 0 0 0 0 0 0 0 0
41011- 0 0 0 0 0 0 0 0 0 0 0 0
41012- 0 0 0 0 0 0 0 0 0 6 6 6
41013- 10 10 10 10 10 10 18 18 18 38 38 38
41014- 78 78 78 142 134 106 216 158 10 242 186 14
41015-246 190 14 246 190 14 156 118 10 10 10 10
41016- 90 90 90 238 238 238 253 253 253 253 253 253
41017-253 253 253 253 253 253 253 253 253 253 253 253
41018-253 253 253 253 253 253 231 231 231 250 250 250
41019-253 253 253 253 253 253 253 253 253 253 253 253
41020-253 253 253 253 253 253 253 253 253 253 253 253
41021-253 253 253 253 253 253 253 253 253 253 253 253
41022-253 253 253 253 253 253 253 253 253 246 230 190
41023-238 204 91 238 204 91 181 142 44 37 26 9
41024- 2 2 6 2 2 6 2 2 6 2 2 6
41025- 2 2 6 2 2 6 38 38 38 46 46 46
41026- 26 26 26 106 106 106 54 54 54 18 18 18
41027- 6 6 6 0 0 0 0 0 0 0 0 0
41028- 0 0 0 0 0 0 0 0 0 0 0 0
41029- 0 0 0 0 0 0 0 0 0 0 0 0
41030- 0 0 0 0 0 0 0 0 0 0 0 0
41031- 0 0 0 0 0 0 0 0 0 0 0 0
41032- 0 0 0 6 6 6 14 14 14 22 22 22
41033- 30 30 30 38 38 38 50 50 50 70 70 70
41034-106 106 106 190 142 34 226 170 11 242 186 14
41035-246 190 14 246 190 14 246 190 14 154 114 10
41036- 6 6 6 74 74 74 226 226 226 253 253 253
41037-253 253 253 253 253 253 253 253 253 253 253 253
41038-253 253 253 253 253 253 231 231 231 250 250 250
41039-253 253 253 253 253 253 253 253 253 253 253 253
41040-253 253 253 253 253 253 253 253 253 253 253 253
41041-253 253 253 253 253 253 253 253 253 253 253 253
41042-253 253 253 253 253 253 253 253 253 228 184 62
41043-241 196 14 241 208 19 232 195 16 38 30 10
41044- 2 2 6 2 2 6 2 2 6 2 2 6
41045- 2 2 6 6 6 6 30 30 30 26 26 26
41046-203 166 17 154 142 90 66 66 66 26 26 26
41047- 6 6 6 0 0 0 0 0 0 0 0 0
41048- 0 0 0 0 0 0 0 0 0 0 0 0
41049- 0 0 0 0 0 0 0 0 0 0 0 0
41050- 0 0 0 0 0 0 0 0 0 0 0 0
41051- 0 0 0 0 0 0 0 0 0 0 0 0
41052- 6 6 6 18 18 18 38 38 38 58 58 58
41053- 78 78 78 86 86 86 101 101 101 123 123 123
41054-175 146 61 210 150 10 234 174 13 246 186 14
41055-246 190 14 246 190 14 246 190 14 238 190 10
41056-102 78 10 2 2 6 46 46 46 198 198 198
41057-253 253 253 253 253 253 253 253 253 253 253 253
41058-253 253 253 253 253 253 234 234 234 242 242 242
41059-253 253 253 253 253 253 253 253 253 253 253 253
41060-253 253 253 253 253 253 253 253 253 253 253 253
41061-253 253 253 253 253 253 253 253 253 253 253 253
41062-253 253 253 253 253 253 253 253 253 224 178 62
41063-242 186 14 241 196 14 210 166 10 22 18 6
41064- 2 2 6 2 2 6 2 2 6 2 2 6
41065- 2 2 6 2 2 6 6 6 6 121 92 8
41066-238 202 15 232 195 16 82 82 82 34 34 34
41067- 10 10 10 0 0 0 0 0 0 0 0 0
41068- 0 0 0 0 0 0 0 0 0 0 0 0
41069- 0 0 0 0 0 0 0 0 0 0 0 0
41070- 0 0 0 0 0 0 0 0 0 0 0 0
41071- 0 0 0 0 0 0 0 0 0 0 0 0
41072- 14 14 14 38 38 38 70 70 70 154 122 46
41073-190 142 34 200 144 11 197 138 11 197 138 11
41074-213 154 11 226 170 11 242 186 14 246 190 14
41075-246 190 14 246 190 14 246 190 14 246 190 14
41076-225 175 15 46 32 6 2 2 6 22 22 22
41077-158 158 158 250 250 250 253 253 253 253 253 253
41078-253 253 253 253 253 253 253 253 253 253 253 253
41079-253 253 253 253 253 253 253 253 253 253 253 253
41080-253 253 253 253 253 253 253 253 253 253 253 253
41081-253 253 253 253 253 253 253 253 253 253 253 253
41082-253 253 253 250 250 250 242 242 242 224 178 62
41083-239 182 13 236 186 11 213 154 11 46 32 6
41084- 2 2 6 2 2 6 2 2 6 2 2 6
41085- 2 2 6 2 2 6 61 42 6 225 175 15
41086-238 190 10 236 186 11 112 100 78 42 42 42
41087- 14 14 14 0 0 0 0 0 0 0 0 0
41088- 0 0 0 0 0 0 0 0 0 0 0 0
41089- 0 0 0 0 0 0 0 0 0 0 0 0
41090- 0 0 0 0 0 0 0 0 0 0 0 0
41091- 0 0 0 0 0 0 0 0 0 6 6 6
41092- 22 22 22 54 54 54 154 122 46 213 154 11
41093-226 170 11 230 174 11 226 170 11 226 170 11
41094-236 178 12 242 186 14 246 190 14 246 190 14
41095-246 190 14 246 190 14 246 190 14 246 190 14
41096-241 196 14 184 144 12 10 10 10 2 2 6
41097- 6 6 6 116 116 116 242 242 242 253 253 253
41098-253 253 253 253 253 253 253 253 253 253 253 253
41099-253 253 253 253 253 253 253 253 253 253 253 253
41100-253 253 253 253 253 253 253 253 253 253 253 253
41101-253 253 253 253 253 253 253 253 253 253 253 253
41102-253 253 253 231 231 231 198 198 198 214 170 54
41103-236 178 12 236 178 12 210 150 10 137 92 6
41104- 18 14 6 2 2 6 2 2 6 2 2 6
41105- 6 6 6 70 47 6 200 144 11 236 178 12
41106-239 182 13 239 182 13 124 112 88 58 58 58
41107- 22 22 22 6 6 6 0 0 0 0 0 0
41108- 0 0 0 0 0 0 0 0 0 0 0 0
41109- 0 0 0 0 0 0 0 0 0 0 0 0
41110- 0 0 0 0 0 0 0 0 0 0 0 0
41111- 0 0 0 0 0 0 0 0 0 10 10 10
41112- 30 30 30 70 70 70 180 133 36 226 170 11
41113-239 182 13 242 186 14 242 186 14 246 186 14
41114-246 190 14 246 190 14 246 190 14 246 190 14
41115-246 190 14 246 190 14 246 190 14 246 190 14
41116-246 190 14 232 195 16 98 70 6 2 2 6
41117- 2 2 6 2 2 6 66 66 66 221 221 221
41118-253 253 253 253 253 253 253 253 253 253 253 253
41119-253 253 253 253 253 253 253 253 253 253 253 253
41120-253 253 253 253 253 253 253 253 253 253 253 253
41121-253 253 253 253 253 253 253 253 253 253 253 253
41122-253 253 253 206 206 206 198 198 198 214 166 58
41123-230 174 11 230 174 11 216 158 10 192 133 9
41124-163 110 8 116 81 8 102 78 10 116 81 8
41125-167 114 7 197 138 11 226 170 11 239 182 13
41126-242 186 14 242 186 14 162 146 94 78 78 78
41127- 34 34 34 14 14 14 6 6 6 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 0 0 0
41130- 0 0 0 0 0 0 0 0 0 0 0 0
41131- 0 0 0 0 0 0 0 0 0 6 6 6
41132- 30 30 30 78 78 78 190 142 34 226 170 11
41133-239 182 13 246 190 14 246 190 14 246 190 14
41134-246 190 14 246 190 14 246 190 14 246 190 14
41135-246 190 14 246 190 14 246 190 14 246 190 14
41136-246 190 14 241 196 14 203 166 17 22 18 6
41137- 2 2 6 2 2 6 2 2 6 38 38 38
41138-218 218 218 253 253 253 253 253 253 253 253 253
41139-253 253 253 253 253 253 253 253 253 253 253 253
41140-253 253 253 253 253 253 253 253 253 253 253 253
41141-253 253 253 253 253 253 253 253 253 253 253 253
41142-250 250 250 206 206 206 198 198 198 202 162 69
41143-226 170 11 236 178 12 224 166 10 210 150 10
41144-200 144 11 197 138 11 192 133 9 197 138 11
41145-210 150 10 226 170 11 242 186 14 246 190 14
41146-246 190 14 246 186 14 225 175 15 124 112 88
41147- 62 62 62 30 30 30 14 14 14 6 6 6
41148- 0 0 0 0 0 0 0 0 0 0 0 0
41149- 0 0 0 0 0 0 0 0 0 0 0 0
41150- 0 0 0 0 0 0 0 0 0 0 0 0
41151- 0 0 0 0 0 0 0 0 0 10 10 10
41152- 30 30 30 78 78 78 174 135 50 224 166 10
41153-239 182 13 246 190 14 246 190 14 246 190 14
41154-246 190 14 246 190 14 246 190 14 246 190 14
41155-246 190 14 246 190 14 246 190 14 246 190 14
41156-246 190 14 246 190 14 241 196 14 139 102 15
41157- 2 2 6 2 2 6 2 2 6 2 2 6
41158- 78 78 78 250 250 250 253 253 253 253 253 253
41159-253 253 253 253 253 253 253 253 253 253 253 253
41160-253 253 253 253 253 253 253 253 253 253 253 253
41161-253 253 253 253 253 253 253 253 253 253 253 253
41162-250 250 250 214 214 214 198 198 198 190 150 46
41163-219 162 10 236 178 12 234 174 13 224 166 10
41164-216 158 10 213 154 11 213 154 11 216 158 10
41165-226 170 11 239 182 13 246 190 14 246 190 14
41166-246 190 14 246 190 14 242 186 14 206 162 42
41167-101 101 101 58 58 58 30 30 30 14 14 14
41168- 6 6 6 0 0 0 0 0 0 0 0 0
41169- 0 0 0 0 0 0 0 0 0 0 0 0
41170- 0 0 0 0 0 0 0 0 0 0 0 0
41171- 0 0 0 0 0 0 0 0 0 10 10 10
41172- 30 30 30 74 74 74 174 135 50 216 158 10
41173-236 178 12 246 190 14 246 190 14 246 190 14
41174-246 190 14 246 190 14 246 190 14 246 190 14
41175-246 190 14 246 190 14 246 190 14 246 190 14
41176-246 190 14 246 190 14 241 196 14 226 184 13
41177- 61 42 6 2 2 6 2 2 6 2 2 6
41178- 22 22 22 238 238 238 253 253 253 253 253 253
41179-253 253 253 253 253 253 253 253 253 253 253 253
41180-253 253 253 253 253 253 253 253 253 253 253 253
41181-253 253 253 253 253 253 253 253 253 253 253 253
41182-253 253 253 226 226 226 187 187 187 180 133 36
41183-216 158 10 236 178 12 239 182 13 236 178 12
41184-230 174 11 226 170 11 226 170 11 230 174 11
41185-236 178 12 242 186 14 246 190 14 246 190 14
41186-246 190 14 246 190 14 246 186 14 239 182 13
41187-206 162 42 106 106 106 66 66 66 34 34 34
41188- 14 14 14 6 6 6 0 0 0 0 0 0
41189- 0 0 0 0 0 0 0 0 0 0 0 0
41190- 0 0 0 0 0 0 0 0 0 0 0 0
41191- 0 0 0 0 0 0 0 0 0 6 6 6
41192- 26 26 26 70 70 70 163 133 67 213 154 11
41193-236 178 12 246 190 14 246 190 14 246 190 14
41194-246 190 14 246 190 14 246 190 14 246 190 14
41195-246 190 14 246 190 14 246 190 14 246 190 14
41196-246 190 14 246 190 14 246 190 14 241 196 14
41197-190 146 13 18 14 6 2 2 6 2 2 6
41198- 46 46 46 246 246 246 253 253 253 253 253 253
41199-253 253 253 253 253 253 253 253 253 253 253 253
41200-253 253 253 253 253 253 253 253 253 253 253 253
41201-253 253 253 253 253 253 253 253 253 253 253 253
41202-253 253 253 221 221 221 86 86 86 156 107 11
41203-216 158 10 236 178 12 242 186 14 246 186 14
41204-242 186 14 239 182 13 239 182 13 242 186 14
41205-242 186 14 246 186 14 246 190 14 246 190 14
41206-246 190 14 246 190 14 246 190 14 246 190 14
41207-242 186 14 225 175 15 142 122 72 66 66 66
41208- 30 30 30 10 10 10 0 0 0 0 0 0
41209- 0 0 0 0 0 0 0 0 0 0 0 0
41210- 0 0 0 0 0 0 0 0 0 0 0 0
41211- 0 0 0 0 0 0 0 0 0 6 6 6
41212- 26 26 26 70 70 70 163 133 67 210 150 10
41213-236 178 12 246 190 14 246 190 14 246 190 14
41214-246 190 14 246 190 14 246 190 14 246 190 14
41215-246 190 14 246 190 14 246 190 14 246 190 14
41216-246 190 14 246 190 14 246 190 14 246 190 14
41217-232 195 16 121 92 8 34 34 34 106 106 106
41218-221 221 221 253 253 253 253 253 253 253 253 253
41219-253 253 253 253 253 253 253 253 253 253 253 253
41220-253 253 253 253 253 253 253 253 253 253 253 253
41221-253 253 253 253 253 253 253 253 253 253 253 253
41222-242 242 242 82 82 82 18 14 6 163 110 8
41223-216 158 10 236 178 12 242 186 14 246 190 14
41224-246 190 14 246 190 14 246 190 14 246 190 14
41225-246 190 14 246 190 14 246 190 14 246 190 14
41226-246 190 14 246 190 14 246 190 14 246 190 14
41227-246 190 14 246 190 14 242 186 14 163 133 67
41228- 46 46 46 18 18 18 6 6 6 0 0 0
41229- 0 0 0 0 0 0 0 0 0 0 0 0
41230- 0 0 0 0 0 0 0 0 0 0 0 0
41231- 0 0 0 0 0 0 0 0 0 10 10 10
41232- 30 30 30 78 78 78 163 133 67 210 150 10
41233-236 178 12 246 186 14 246 190 14 246 190 14
41234-246 190 14 246 190 14 246 190 14 246 190 14
41235-246 190 14 246 190 14 246 190 14 246 190 14
41236-246 190 14 246 190 14 246 190 14 246 190 14
41237-241 196 14 215 174 15 190 178 144 253 253 253
41238-253 253 253 253 253 253 253 253 253 253 253 253
41239-253 253 253 253 253 253 253 253 253 253 253 253
41240-253 253 253 253 253 253 253 253 253 253 253 253
41241-253 253 253 253 253 253 253 253 253 218 218 218
41242- 58 58 58 2 2 6 22 18 6 167 114 7
41243-216 158 10 236 178 12 246 186 14 246 190 14
41244-246 190 14 246 190 14 246 190 14 246 190 14
41245-246 190 14 246 190 14 246 190 14 246 190 14
41246-246 190 14 246 190 14 246 190 14 246 190 14
41247-246 190 14 246 186 14 242 186 14 190 150 46
41248- 54 54 54 22 22 22 6 6 6 0 0 0
41249- 0 0 0 0 0 0 0 0 0 0 0 0
41250- 0 0 0 0 0 0 0 0 0 0 0 0
41251- 0 0 0 0 0 0 0 0 0 14 14 14
41252- 38 38 38 86 86 86 180 133 36 213 154 11
41253-236 178 12 246 186 14 246 190 14 246 190 14
41254-246 190 14 246 190 14 246 190 14 246 190 14
41255-246 190 14 246 190 14 246 190 14 246 190 14
41256-246 190 14 246 190 14 246 190 14 246 190 14
41257-246 190 14 232 195 16 190 146 13 214 214 214
41258-253 253 253 253 253 253 253 253 253 253 253 253
41259-253 253 253 253 253 253 253 253 253 253 253 253
41260-253 253 253 253 253 253 253 253 253 253 253 253
41261-253 253 253 250 250 250 170 170 170 26 26 26
41262- 2 2 6 2 2 6 37 26 9 163 110 8
41263-219 162 10 239 182 13 246 186 14 246 190 14
41264-246 190 14 246 190 14 246 190 14 246 190 14
41265-246 190 14 246 190 14 246 190 14 246 190 14
41266-246 190 14 246 190 14 246 190 14 246 190 14
41267-246 186 14 236 178 12 224 166 10 142 122 72
41268- 46 46 46 18 18 18 6 6 6 0 0 0
41269- 0 0 0 0 0 0 0 0 0 0 0 0
41270- 0 0 0 0 0 0 0 0 0 0 0 0
41271- 0 0 0 0 0 0 6 6 6 18 18 18
41272- 50 50 50 109 106 95 192 133 9 224 166 10
41273-242 186 14 246 190 14 246 190 14 246 190 14
41274-246 190 14 246 190 14 246 190 14 246 190 14
41275-246 190 14 246 190 14 246 190 14 246 190 14
41276-246 190 14 246 190 14 246 190 14 246 190 14
41277-242 186 14 226 184 13 210 162 10 142 110 46
41278-226 226 226 253 253 253 253 253 253 253 253 253
41279-253 253 253 253 253 253 253 253 253 253 253 253
41280-253 253 253 253 253 253 253 253 253 253 253 253
41281-198 198 198 66 66 66 2 2 6 2 2 6
41282- 2 2 6 2 2 6 50 34 6 156 107 11
41283-219 162 10 239 182 13 246 186 14 246 190 14
41284-246 190 14 246 190 14 246 190 14 246 190 14
41285-246 190 14 246 190 14 246 190 14 246 190 14
41286-246 190 14 246 190 14 246 190 14 242 186 14
41287-234 174 13 213 154 11 154 122 46 66 66 66
41288- 30 30 30 10 10 10 0 0 0 0 0 0
41289- 0 0 0 0 0 0 0 0 0 0 0 0
41290- 0 0 0 0 0 0 0 0 0 0 0 0
41291- 0 0 0 0 0 0 6 6 6 22 22 22
41292- 58 58 58 154 121 60 206 145 10 234 174 13
41293-242 186 14 246 186 14 246 190 14 246 190 14
41294-246 190 14 246 190 14 246 190 14 246 190 14
41295-246 190 14 246 190 14 246 190 14 246 190 14
41296-246 190 14 246 190 14 246 190 14 246 190 14
41297-246 186 14 236 178 12 210 162 10 163 110 8
41298- 61 42 6 138 138 138 218 218 218 250 250 250
41299-253 253 253 253 253 253 253 253 253 250 250 250
41300-242 242 242 210 210 210 144 144 144 66 66 66
41301- 6 6 6 2 2 6 2 2 6 2 2 6
41302- 2 2 6 2 2 6 61 42 6 163 110 8
41303-216 158 10 236 178 12 246 190 14 246 190 14
41304-246 190 14 246 190 14 246 190 14 246 190 14
41305-246 190 14 246 190 14 246 190 14 246 190 14
41306-246 190 14 239 182 13 230 174 11 216 158 10
41307-190 142 34 124 112 88 70 70 70 38 38 38
41308- 18 18 18 6 6 6 0 0 0 0 0 0
41309- 0 0 0 0 0 0 0 0 0 0 0 0
41310- 0 0 0 0 0 0 0 0 0 0 0 0
41311- 0 0 0 0 0 0 6 6 6 22 22 22
41312- 62 62 62 168 124 44 206 145 10 224 166 10
41313-236 178 12 239 182 13 242 186 14 242 186 14
41314-246 186 14 246 190 14 246 190 14 246 190 14
41315-246 190 14 246 190 14 246 190 14 246 190 14
41316-246 190 14 246 190 14 246 190 14 246 190 14
41317-246 190 14 236 178 12 216 158 10 175 118 6
41318- 80 54 7 2 2 6 6 6 6 30 30 30
41319- 54 54 54 62 62 62 50 50 50 38 38 38
41320- 14 14 14 2 2 6 2 2 6 2 2 6
41321- 2 2 6 2 2 6 2 2 6 2 2 6
41322- 2 2 6 6 6 6 80 54 7 167 114 7
41323-213 154 11 236 178 12 246 190 14 246 190 14
41324-246 190 14 246 190 14 246 190 14 246 190 14
41325-246 190 14 242 186 14 239 182 13 239 182 13
41326-230 174 11 210 150 10 174 135 50 124 112 88
41327- 82 82 82 54 54 54 34 34 34 18 18 18
41328- 6 6 6 0 0 0 0 0 0 0 0 0
41329- 0 0 0 0 0 0 0 0 0 0 0 0
41330- 0 0 0 0 0 0 0 0 0 0 0 0
41331- 0 0 0 0 0 0 6 6 6 18 18 18
41332- 50 50 50 158 118 36 192 133 9 200 144 11
41333-216 158 10 219 162 10 224 166 10 226 170 11
41334-230 174 11 236 178 12 239 182 13 239 182 13
41335-242 186 14 246 186 14 246 190 14 246 190 14
41336-246 190 14 246 190 14 246 190 14 246 190 14
41337-246 186 14 230 174 11 210 150 10 163 110 8
41338-104 69 6 10 10 10 2 2 6 2 2 6
41339- 2 2 6 2 2 6 2 2 6 2 2 6
41340- 2 2 6 2 2 6 2 2 6 2 2 6
41341- 2 2 6 2 2 6 2 2 6 2 2 6
41342- 2 2 6 6 6 6 91 60 6 167 114 7
41343-206 145 10 230 174 11 242 186 14 246 190 14
41344-246 190 14 246 190 14 246 186 14 242 186 14
41345-239 182 13 230 174 11 224 166 10 213 154 11
41346-180 133 36 124 112 88 86 86 86 58 58 58
41347- 38 38 38 22 22 22 10 10 10 6 6 6
41348- 0 0 0 0 0 0 0 0 0 0 0 0
41349- 0 0 0 0 0 0 0 0 0 0 0 0
41350- 0 0 0 0 0 0 0 0 0 0 0 0
41351- 0 0 0 0 0 0 0 0 0 14 14 14
41352- 34 34 34 70 70 70 138 110 50 158 118 36
41353-167 114 7 180 123 7 192 133 9 197 138 11
41354-200 144 11 206 145 10 213 154 11 219 162 10
41355-224 166 10 230 174 11 239 182 13 242 186 14
41356-246 186 14 246 186 14 246 186 14 246 186 14
41357-239 182 13 216 158 10 185 133 11 152 99 6
41358-104 69 6 18 14 6 2 2 6 2 2 6
41359- 2 2 6 2 2 6 2 2 6 2 2 6
41360- 2 2 6 2 2 6 2 2 6 2 2 6
41361- 2 2 6 2 2 6 2 2 6 2 2 6
41362- 2 2 6 6 6 6 80 54 7 152 99 6
41363-192 133 9 219 162 10 236 178 12 239 182 13
41364-246 186 14 242 186 14 239 182 13 236 178 12
41365-224 166 10 206 145 10 192 133 9 154 121 60
41366- 94 94 94 62 62 62 42 42 42 22 22 22
41367- 14 14 14 6 6 6 0 0 0 0 0 0
41368- 0 0 0 0 0 0 0 0 0 0 0 0
41369- 0 0 0 0 0 0 0 0 0 0 0 0
41370- 0 0 0 0 0 0 0 0 0 0 0 0
41371- 0 0 0 0 0 0 0 0 0 6 6 6
41372- 18 18 18 34 34 34 58 58 58 78 78 78
41373-101 98 89 124 112 88 142 110 46 156 107 11
41374-163 110 8 167 114 7 175 118 6 180 123 7
41375-185 133 11 197 138 11 210 150 10 219 162 10
41376-226 170 11 236 178 12 236 178 12 234 174 13
41377-219 162 10 197 138 11 163 110 8 130 83 6
41378- 91 60 6 10 10 10 2 2 6 2 2 6
41379- 18 18 18 38 38 38 38 38 38 38 38 38
41380- 38 38 38 38 38 38 38 38 38 38 38 38
41381- 38 38 38 38 38 38 26 26 26 2 2 6
41382- 2 2 6 6 6 6 70 47 6 137 92 6
41383-175 118 6 200 144 11 219 162 10 230 174 11
41384-234 174 13 230 174 11 219 162 10 210 150 10
41385-192 133 9 163 110 8 124 112 88 82 82 82
41386- 50 50 50 30 30 30 14 14 14 6 6 6
41387- 0 0 0 0 0 0 0 0 0 0 0 0
41388- 0 0 0 0 0 0 0 0 0 0 0 0
41389- 0 0 0 0 0 0 0 0 0 0 0 0
41390- 0 0 0 0 0 0 0 0 0 0 0 0
41391- 0 0 0 0 0 0 0 0 0 0 0 0
41392- 6 6 6 14 14 14 22 22 22 34 34 34
41393- 42 42 42 58 58 58 74 74 74 86 86 86
41394-101 98 89 122 102 70 130 98 46 121 87 25
41395-137 92 6 152 99 6 163 110 8 180 123 7
41396-185 133 11 197 138 11 206 145 10 200 144 11
41397-180 123 7 156 107 11 130 83 6 104 69 6
41398- 50 34 6 54 54 54 110 110 110 101 98 89
41399- 86 86 86 82 82 82 78 78 78 78 78 78
41400- 78 78 78 78 78 78 78 78 78 78 78 78
41401- 78 78 78 82 82 82 86 86 86 94 94 94
41402-106 106 106 101 101 101 86 66 34 124 80 6
41403-156 107 11 180 123 7 192 133 9 200 144 11
41404-206 145 10 200 144 11 192 133 9 175 118 6
41405-139 102 15 109 106 95 70 70 70 42 42 42
41406- 22 22 22 10 10 10 0 0 0 0 0 0
41407- 0 0 0 0 0 0 0 0 0 0 0 0
41408- 0 0 0 0 0 0 0 0 0 0 0 0
41409- 0 0 0 0 0 0 0 0 0 0 0 0
41410- 0 0 0 0 0 0 0 0 0 0 0 0
41411- 0 0 0 0 0 0 0 0 0 0 0 0
41412- 0 0 0 0 0 0 6 6 6 10 10 10
41413- 14 14 14 22 22 22 30 30 30 38 38 38
41414- 50 50 50 62 62 62 74 74 74 90 90 90
41415-101 98 89 112 100 78 121 87 25 124 80 6
41416-137 92 6 152 99 6 152 99 6 152 99 6
41417-138 86 6 124 80 6 98 70 6 86 66 30
41418-101 98 89 82 82 82 58 58 58 46 46 46
41419- 38 38 38 34 34 34 34 34 34 34 34 34
41420- 34 34 34 34 34 34 34 34 34 34 34 34
41421- 34 34 34 34 34 34 38 38 38 42 42 42
41422- 54 54 54 82 82 82 94 86 76 91 60 6
41423-134 86 6 156 107 11 167 114 7 175 118 6
41424-175 118 6 167 114 7 152 99 6 121 87 25
41425-101 98 89 62 62 62 34 34 34 18 18 18
41426- 6 6 6 0 0 0 0 0 0 0 0 0
41427- 0 0 0 0 0 0 0 0 0 0 0 0
41428- 0 0 0 0 0 0 0 0 0 0 0 0
41429- 0 0 0 0 0 0 0 0 0 0 0 0
41430- 0 0 0 0 0 0 0 0 0 0 0 0
41431- 0 0 0 0 0 0 0 0 0 0 0 0
41432- 0 0 0 0 0 0 0 0 0 0 0 0
41433- 0 0 0 6 6 6 6 6 6 10 10 10
41434- 18 18 18 22 22 22 30 30 30 42 42 42
41435- 50 50 50 66 66 66 86 86 86 101 98 89
41436-106 86 58 98 70 6 104 69 6 104 69 6
41437-104 69 6 91 60 6 82 62 34 90 90 90
41438- 62 62 62 38 38 38 22 22 22 14 14 14
41439- 10 10 10 10 10 10 10 10 10 10 10 10
41440- 10 10 10 10 10 10 6 6 6 10 10 10
41441- 10 10 10 10 10 10 10 10 10 14 14 14
41442- 22 22 22 42 42 42 70 70 70 89 81 66
41443- 80 54 7 104 69 6 124 80 6 137 92 6
41444-134 86 6 116 81 8 100 82 52 86 86 86
41445- 58 58 58 30 30 30 14 14 14 6 6 6
41446- 0 0 0 0 0 0 0 0 0 0 0 0
41447- 0 0 0 0 0 0 0 0 0 0 0 0
41448- 0 0 0 0 0 0 0 0 0 0 0 0
41449- 0 0 0 0 0 0 0 0 0 0 0 0
41450- 0 0 0 0 0 0 0 0 0 0 0 0
41451- 0 0 0 0 0 0 0 0 0 0 0 0
41452- 0 0 0 0 0 0 0 0 0 0 0 0
41453- 0 0 0 0 0 0 0 0 0 0 0 0
41454- 0 0 0 6 6 6 10 10 10 14 14 14
41455- 18 18 18 26 26 26 38 38 38 54 54 54
41456- 70 70 70 86 86 86 94 86 76 89 81 66
41457- 89 81 66 86 86 86 74 74 74 50 50 50
41458- 30 30 30 14 14 14 6 6 6 0 0 0
41459- 0 0 0 0 0 0 0 0 0 0 0 0
41460- 0 0 0 0 0 0 0 0 0 0 0 0
41461- 0 0 0 0 0 0 0 0 0 0 0 0
41462- 6 6 6 18 18 18 34 34 34 58 58 58
41463- 82 82 82 89 81 66 89 81 66 89 81 66
41464- 94 86 66 94 86 76 74 74 74 50 50 50
41465- 26 26 26 14 14 14 6 6 6 0 0 0
41466- 0 0 0 0 0 0 0 0 0 0 0 0
41467- 0 0 0 0 0 0 0 0 0 0 0 0
41468- 0 0 0 0 0 0 0 0 0 0 0 0
41469- 0 0 0 0 0 0 0 0 0 0 0 0
41470- 0 0 0 0 0 0 0 0 0 0 0 0
41471- 0 0 0 0 0 0 0 0 0 0 0 0
41472- 0 0 0 0 0 0 0 0 0 0 0 0
41473- 0 0 0 0 0 0 0 0 0 0 0 0
41474- 0 0 0 0 0 0 0 0 0 0 0 0
41475- 6 6 6 6 6 6 14 14 14 18 18 18
41476- 30 30 30 38 38 38 46 46 46 54 54 54
41477- 50 50 50 42 42 42 30 30 30 18 18 18
41478- 10 10 10 0 0 0 0 0 0 0 0 0
41479- 0 0 0 0 0 0 0 0 0 0 0 0
41480- 0 0 0 0 0 0 0 0 0 0 0 0
41481- 0 0 0 0 0 0 0 0 0 0 0 0
41482- 0 0 0 6 6 6 14 14 14 26 26 26
41483- 38 38 38 50 50 50 58 58 58 58 58 58
41484- 54 54 54 42 42 42 30 30 30 18 18 18
41485- 10 10 10 0 0 0 0 0 0 0 0 0
41486- 0 0 0 0 0 0 0 0 0 0 0 0
41487- 0 0 0 0 0 0 0 0 0 0 0 0
41488- 0 0 0 0 0 0 0 0 0 0 0 0
41489- 0 0 0 0 0 0 0 0 0 0 0 0
41490- 0 0 0 0 0 0 0 0 0 0 0 0
41491- 0 0 0 0 0 0 0 0 0 0 0 0
41492- 0 0 0 0 0 0 0 0 0 0 0 0
41493- 0 0 0 0 0 0 0 0 0 0 0 0
41494- 0 0 0 0 0 0 0 0 0 0 0 0
41495- 0 0 0 0 0 0 0 0 0 6 6 6
41496- 6 6 6 10 10 10 14 14 14 18 18 18
41497- 18 18 18 14 14 14 10 10 10 6 6 6
41498- 0 0 0 0 0 0 0 0 0 0 0 0
41499- 0 0 0 0 0 0 0 0 0 0 0 0
41500- 0 0 0 0 0 0 0 0 0 0 0 0
41501- 0 0 0 0 0 0 0 0 0 0 0 0
41502- 0 0 0 0 0 0 0 0 0 6 6 6
41503- 14 14 14 18 18 18 22 22 22 22 22 22
41504- 18 18 18 14 14 14 10 10 10 6 6 6
41505- 0 0 0 0 0 0 0 0 0 0 0 0
41506- 0 0 0 0 0 0 0 0 0 0 0 0
41507- 0 0 0 0 0 0 0 0 0 0 0 0
41508- 0 0 0 0 0 0 0 0 0 0 0 0
41509- 0 0 0 0 0 0 0 0 0 0 0 0
41510+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41511+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41512+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41513+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41514+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41515+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41516+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41517+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41518+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41519+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41520+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41521+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41522+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41523+4 4 4 4 4 4
41524+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41525+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41526+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41527+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41528+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41529+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41530+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41531+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41532+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41533+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41534+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41535+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41536+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41537+4 4 4 4 4 4
41538+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41539+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41540+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41541+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41542+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41543+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41544+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41545+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41546+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41547+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41548+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41549+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41550+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41551+4 4 4 4 4 4
41552+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41553+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41554+4 4 4 4 4 4 4 4 4 4 4 4 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 4 4 4 4 4 4 4 4 4 4 4 4
41557+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41558+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41559+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41560+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41561+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41562+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41563+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41564+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41565+4 4 4 4 4 4
41566+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41567+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41568+4 4 4 4 4 4 4 4 4 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 4 4 4 4 4 4 4 4 4 4 4 4
41571+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41572+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41573+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41574+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41575+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41576+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41577+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41578+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41579+4 4 4 4 4 4
41580+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41581+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 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 4 4 4 4 4 4 4 4 4 4 4 4
41585+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41586+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41587+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41588+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41589+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41590+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41591+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41592+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41593+4 4 4 4 4 4
41594+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41595+4 4 4 4 4 4 4 4 4 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 4 4 4 3 3 3 0 0 0 0 0 0
41599+0 0 0 0 0 0 0 0 0 0 0 0 3 3 3 4 4 4
41600+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41601+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41602+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41603+4 4 4 4 4 4 4 4 4 4 4 4 1 1 1 0 0 0
41604+0 0 0 3 3 3 4 4 4 4 4 4 4 4 4 4 4 4
41605+4 4 4 4 4 4 4 4 4 2 1 0 2 1 0 3 2 2
41606+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41607+4 4 4 4 4 4
41608+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41609+4 4 4 4 4 4 4 4 4 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 2 2 2 0 0 0 3 4 3 26 28 28
41613+37 38 37 37 38 37 14 17 19 2 2 2 0 0 0 2 2 2
41614+5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41615+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41616+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41617+4 4 4 4 4 4 3 3 3 0 0 0 1 1 1 6 6 6
41618+2 2 2 0 0 0 3 3 3 4 4 4 4 4 4 4 4 4
41619+4 4 5 3 3 3 1 0 0 0 0 0 1 0 0 0 0 0
41620+1 1 1 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41621+4 4 4 4 4 4
41622+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41623+4 4 4 4 4 4 4 4 4 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+2 2 2 0 0 0 0 0 0 14 17 19 60 74 84 137 136 137
41627+153 152 153 137 136 137 125 124 125 60 73 81 6 6 6 3 1 0
41628+0 0 0 3 3 3 4 4 4 4 4 4 4 4 4 4 4 4
41629+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41630+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41631+4 4 4 4 4 4 0 0 0 4 4 4 41 54 63 125 124 125
41632+60 73 81 6 6 6 4 0 0 3 3 3 4 4 4 4 4 4
41633+4 4 4 0 0 0 6 9 11 41 54 63 41 65 82 22 30 35
41634+2 2 2 2 1 0 4 4 4 4 4 4 4 4 4 4 4 4
41635+4 4 4 4 4 4
41636+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41637+4 4 4 4 4 4 4 4 4 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 5 5 5 5 5 5 2 2 2 0 0 0
41640+4 0 0 6 6 6 41 54 63 137 136 137 174 174 174 167 166 167
41641+165 164 165 165 164 165 163 162 163 163 162 163 125 124 125 41 54 63
41642+1 1 1 0 0 0 0 0 0 3 3 3 5 5 5 4 4 4
41643+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41644+4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 5 5 5
41645+3 3 3 2 0 0 4 0 0 60 73 81 156 155 156 167 166 167
41646+163 162 163 85 115 134 5 7 8 0 0 0 4 4 4 5 5 5
41647+0 0 0 2 5 5 55 98 126 90 154 193 90 154 193 72 125 159
41648+37 51 59 2 0 0 1 1 1 4 5 5 4 4 4 4 4 4
41649+4 4 4 4 4 4
41650+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41651+4 4 4 4 4 4 4 4 4 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 5 5 5 4 4 4 1 1 1 0 0 0 3 3 3
41654+37 38 37 125 124 125 163 162 163 174 174 174 158 157 158 158 157 158
41655+156 155 156 156 155 156 158 157 158 165 164 165 174 174 174 166 165 166
41656+125 124 125 16 19 21 1 0 0 0 0 0 0 0 0 4 4 4
41657+5 5 5 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
41658+4 4 4 4 4 4 4 4 4 5 5 5 5 5 5 1 1 1
41659+0 0 0 0 0 0 37 38 37 153 152 153 174 174 174 158 157 158
41660+174 174 174 163 162 163 37 38 37 4 3 3 4 0 0 1 1 1
41661+0 0 0 22 40 52 101 161 196 101 161 196 90 154 193 101 161 196
41662+64 123 161 14 17 19 0 0 0 4 4 4 4 4 4 4 4 4
41663+4 4 4 4 4 4
41664+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41665+4 4 4 4 4 4 4 4 4 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 5 5 5
41667+5 5 5 2 2 2 0 0 0 4 0 0 24 26 27 85 115 134
41668+156 155 156 174 174 174 167 166 167 156 155 156 154 153 154 157 156 157
41669+156 155 156 156 155 156 155 154 155 153 152 153 158 157 158 167 166 167
41670+174 174 174 156 155 156 60 74 84 16 19 21 0 0 0 0 0 0
41671+1 1 1 5 5 5 5 5 5 4 4 4 4 4 4 4 4 4
41672+4 4 4 5 5 5 6 6 6 3 3 3 0 0 0 4 0 0
41673+13 16 17 60 73 81 137 136 137 165 164 165 156 155 156 153 152 153
41674+174 174 174 177 184 187 60 73 81 3 1 0 0 0 0 1 1 2
41675+22 30 35 64 123 161 136 185 209 90 154 193 90 154 193 90 154 193
41676+90 154 193 21 29 34 0 0 0 3 2 2 4 4 5 4 4 4
41677+4 4 4 4 4 4
41678+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41679+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41680+4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 3 3 3
41681+0 0 0 0 0 0 10 13 16 60 74 84 157 156 157 174 174 174
41682+174 174 174 158 157 158 153 152 153 154 153 154 156 155 156 155 154 155
41683+156 155 156 155 154 155 154 153 154 157 156 157 154 153 154 153 152 153
41684+163 162 163 174 174 174 177 184 187 137 136 137 60 73 81 13 16 17
41685+4 0 0 0 0 0 3 3 3 5 5 5 4 4 4 4 4 4
41686+5 5 5 4 4 4 1 1 1 0 0 0 3 3 3 41 54 63
41687+131 129 131 174 174 174 174 174 174 174 174 174 167 166 167 174 174 174
41688+190 197 201 137 136 137 24 26 27 4 0 0 16 21 25 50 82 103
41689+90 154 193 136 185 209 90 154 193 101 161 196 101 161 196 101 161 196
41690+31 91 132 3 6 7 0 0 0 4 4 4 4 4 4 4 4 4
41691+4 4 4 4 4 4
41692+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41693+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41694+4 4 4 4 4 4 4 4 4 2 2 2 0 0 0 4 0 0
41695+4 0 0 43 57 68 137 136 137 177 184 187 174 174 174 163 162 163
41696+155 154 155 155 154 155 156 155 156 155 154 155 158 157 158 165 164 165
41697+167 166 167 166 165 166 163 162 163 157 156 157 155 154 155 155 154 155
41698+153 152 153 156 155 156 167 166 167 174 174 174 174 174 174 131 129 131
41699+41 54 63 5 5 5 0 0 0 0 0 0 3 3 3 4 4 4
41700+1 1 1 0 0 0 1 0 0 26 28 28 125 124 125 174 174 174
41701+177 184 187 174 174 174 174 174 174 156 155 156 131 129 131 137 136 137
41702+125 124 125 24 26 27 4 0 0 41 65 82 90 154 193 136 185 209
41703+136 185 209 101 161 196 53 118 160 37 112 160 90 154 193 34 86 122
41704+7 12 15 0 0 0 4 4 4 4 4 4 4 4 4 4 4 4
41705+4 4 4 4 4 4
41706+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41707+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41708+4 4 4 3 3 3 0 0 0 0 0 0 5 5 5 37 38 37
41709+125 124 125 167 166 167 174 174 174 167 166 167 158 157 158 155 154 155
41710+156 155 156 156 155 156 156 155 156 163 162 163 167 166 167 155 154 155
41711+137 136 137 153 152 153 156 155 156 165 164 165 163 162 163 156 155 156
41712+156 155 156 156 155 156 155 154 155 158 157 158 166 165 166 174 174 174
41713+167 166 167 125 124 125 37 38 37 1 0 0 0 0 0 0 0 0
41714+0 0 0 24 26 27 60 74 84 158 157 158 174 174 174 174 174 174
41715+166 165 166 158 157 158 125 124 125 41 54 63 13 16 17 6 6 6
41716+6 6 6 37 38 37 80 127 157 136 185 209 101 161 196 101 161 196
41717+90 154 193 28 67 93 6 10 14 13 20 25 13 20 25 6 10 14
41718+1 1 2 4 3 3 4 4 4 4 4 4 4 4 4 4 4 4
41719+4 4 4 4 4 4
41720+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41721+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41722+1 1 1 1 0 0 4 3 3 37 38 37 60 74 84 153 152 153
41723+167 166 167 167 166 167 158 157 158 154 153 154 155 154 155 156 155 156
41724+157 156 157 158 157 158 167 166 167 167 166 167 131 129 131 43 57 68
41725+26 28 28 37 38 37 60 73 81 131 129 131 165 164 165 166 165 166
41726+158 157 158 155 154 155 156 155 156 156 155 156 156 155 156 158 157 158
41727+165 164 165 174 174 174 163 162 163 60 74 84 16 19 21 13 16 17
41728+60 73 81 131 129 131 174 174 174 174 174 174 167 166 167 165 164 165
41729+137 136 137 60 73 81 24 26 27 4 0 0 4 0 0 16 19 21
41730+52 104 138 101 161 196 136 185 209 136 185 209 90 154 193 27 99 146
41731+13 20 25 4 5 7 2 5 5 4 5 7 1 1 2 0 0 0
41732+4 4 4 4 4 4 3 3 3 2 2 2 2 2 2 4 4 4
41733+4 4 4 4 4 4
41734+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41735+4 4 4 4 4 4 4 4 4 4 4 4 3 3 3 0 0 0
41736+0 0 0 13 16 17 60 73 81 137 136 137 174 174 174 166 165 166
41737+158 157 158 156 155 156 157 156 157 156 155 156 155 154 155 158 157 158
41738+167 166 167 174 174 174 153 152 153 60 73 81 16 19 21 4 0 0
41739+4 0 0 4 0 0 6 6 6 26 28 28 60 74 84 158 157 158
41740+174 174 174 166 165 166 157 156 157 155 154 155 156 155 156 156 155 156
41741+155 154 155 158 157 158 167 166 167 167 166 167 131 129 131 125 124 125
41742+137 136 137 167 166 167 167 166 167 174 174 174 158 157 158 125 124 125
41743+16 19 21 4 0 0 4 0 0 10 13 16 49 76 92 107 159 188
41744+136 185 209 136 185 209 90 154 193 26 108 161 22 40 52 6 10 14
41745+2 3 3 1 1 2 1 1 2 4 4 5 4 4 5 4 4 5
41746+4 4 5 2 2 1 0 0 0 0 0 0 0 0 0 2 2 2
41747+4 4 4 4 4 4
41748+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41749+4 4 4 5 5 5 3 3 3 0 0 0 1 0 0 4 0 0
41750+37 51 59 131 129 131 167 166 167 167 166 167 163 162 163 157 156 157
41751+157 156 157 155 154 155 153 152 153 157 156 157 167 166 167 174 174 174
41752+153 152 153 125 124 125 37 38 37 4 0 0 4 0 0 4 0 0
41753+4 3 3 4 3 3 4 0 0 6 6 6 4 0 0 37 38 37
41754+125 124 125 174 174 174 174 174 174 165 164 165 156 155 156 154 153 154
41755+156 155 156 156 155 156 155 154 155 163 162 163 158 157 158 163 162 163
41756+174 174 174 174 174 174 174 174 174 125 124 125 37 38 37 0 0 0
41757+4 0 0 6 9 11 41 54 63 90 154 193 136 185 209 146 190 211
41758+136 185 209 37 112 160 22 40 52 6 10 14 3 6 7 1 1 2
41759+1 1 2 3 3 3 1 1 2 3 3 3 4 4 4 4 4 4
41760+2 2 2 2 0 0 16 19 21 37 38 37 24 26 27 0 0 0
41761+0 0 0 4 4 4
41762+4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 5 5 5
41763+4 4 4 0 0 0 0 0 0 0 0 0 26 28 28 120 125 127
41764+158 157 158 174 174 174 165 164 165 157 156 157 155 154 155 156 155 156
41765+153 152 153 153 152 153 167 166 167 174 174 174 174 174 174 125 124 125
41766+37 38 37 4 0 0 0 0 0 4 0 0 4 3 3 4 4 4
41767+4 4 4 4 4 4 5 5 5 4 0 0 4 0 0 4 0 0
41768+4 3 3 43 57 68 137 136 137 174 174 174 174 174 174 165 164 165
41769+154 153 154 153 152 153 153 152 153 153 152 153 163 162 163 174 174 174
41770+174 174 174 153 152 153 60 73 81 6 6 6 4 0 0 4 3 3
41771+32 43 50 80 127 157 136 185 209 146 190 211 146 190 211 90 154 193
41772+28 67 93 28 67 93 40 71 93 3 6 7 1 1 2 2 5 5
41773+50 82 103 79 117 143 26 37 45 0 0 0 3 3 3 1 1 1
41774+0 0 0 41 54 63 137 136 137 174 174 174 153 152 153 60 73 81
41775+2 0 0 0 0 0
41776+4 4 4 4 4 4 4 4 4 4 4 4 6 6 6 2 2 2
41777+0 0 0 2 0 0 24 26 27 60 74 84 153 152 153 174 174 174
41778+174 174 174 157 156 157 154 153 154 156 155 156 154 153 154 153 152 153
41779+165 164 165 174 174 174 177 184 187 137 136 137 43 57 68 6 6 6
41780+4 0 0 2 0 0 3 3 3 5 5 5 5 5 5 4 4 4
41781+4 4 4 4 4 4 4 4 4 5 5 5 6 6 6 4 3 3
41782+4 0 0 4 0 0 24 26 27 60 73 81 153 152 153 174 174 174
41783+174 174 174 158 157 158 158 157 158 174 174 174 174 174 174 158 157 158
41784+60 74 84 24 26 27 4 0 0 4 0 0 17 23 27 59 113 148
41785+136 185 209 191 222 234 146 190 211 136 185 209 31 91 132 7 11 13
41786+22 40 52 101 161 196 90 154 193 6 9 11 3 4 4 43 95 132
41787+136 185 209 172 205 220 55 98 126 0 0 0 0 0 0 2 0 0
41788+26 28 28 153 152 153 177 184 187 167 166 167 177 184 187 165 164 165
41789+37 38 37 0 0 0
41790+4 4 4 4 4 4 5 5 5 5 5 5 1 1 1 0 0 0
41791+13 16 17 60 73 81 137 136 137 174 174 174 174 174 174 165 164 165
41792+153 152 153 153 152 153 155 154 155 154 153 154 158 157 158 174 174 174
41793+177 184 187 163 162 163 60 73 81 16 19 21 4 0 0 4 0 0
41794+4 3 3 4 4 4 5 5 5 5 5 5 4 4 4 5 5 5
41795+5 5 5 5 5 5 5 5 5 4 4 4 4 4 4 5 5 5
41796+6 6 6 4 0 0 4 0 0 4 0 0 24 26 27 60 74 84
41797+166 165 166 174 174 174 177 184 187 165 164 165 125 124 125 24 26 27
41798+4 0 0 4 0 0 5 5 5 50 82 103 136 185 209 172 205 220
41799+146 190 211 136 185 209 26 108 161 22 40 52 7 12 15 44 81 103
41800+71 116 144 28 67 93 37 51 59 41 65 82 100 139 164 101 161 196
41801+90 154 193 90 154 193 28 67 93 0 0 0 0 0 0 26 28 28
41802+125 124 125 167 166 167 163 162 163 153 152 153 163 162 163 174 174 174
41803+85 115 134 4 0 0
41804+4 4 4 5 5 5 4 4 4 1 0 0 4 0 0 34 47 55
41805+125 124 125 174 174 174 174 174 174 167 166 167 157 156 157 153 152 153
41806+155 154 155 155 154 155 158 157 158 166 165 166 167 166 167 154 153 154
41807+125 124 125 26 28 28 4 0 0 4 0 0 4 0 0 5 5 5
41808+5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 1 1 1
41809+0 0 0 0 0 0 1 1 1 4 4 4 4 4 4 4 4 4
41810+5 5 5 5 5 5 4 3 3 4 0 0 4 0 0 6 6 6
41811+37 38 37 131 129 131 137 136 137 37 38 37 0 0 0 4 0 0
41812+4 5 5 43 61 72 90 154 193 172 205 220 146 190 211 136 185 209
41813+90 154 193 28 67 93 13 20 25 43 61 72 71 116 144 44 81 103
41814+2 5 5 7 11 13 59 113 148 101 161 196 90 154 193 28 67 93
41815+13 20 25 6 10 14 0 0 0 13 16 17 60 73 81 137 136 137
41816+166 165 166 158 157 158 156 155 156 154 153 154 167 166 167 174 174 174
41817+60 73 81 4 0 0
41818+4 4 4 4 4 4 0 0 0 3 3 3 60 74 84 174 174 174
41819+174 174 174 167 166 167 163 162 163 155 154 155 157 156 157 155 154 155
41820+156 155 156 163 162 163 167 166 167 158 157 158 125 124 125 37 38 37
41821+4 3 3 4 0 0 4 0 0 6 6 6 6 6 6 5 5 5
41822+4 4 4 4 4 4 4 4 4 1 1 1 0 0 0 2 3 3
41823+10 13 16 7 11 13 1 0 0 0 0 0 2 2 1 4 4 4
41824+4 4 4 4 4 4 4 4 4 5 5 5 4 3 3 4 0 0
41825+4 0 0 7 11 13 13 16 17 4 0 0 3 3 3 34 47 55
41826+80 127 157 146 190 211 172 205 220 136 185 209 136 185 209 136 185 209
41827+28 67 93 22 40 52 55 98 126 55 98 126 21 29 34 7 11 13
41828+50 82 103 101 161 196 101 161 196 35 83 115 13 20 25 2 2 1
41829+1 1 2 1 1 2 37 51 59 131 129 131 174 174 174 174 174 174
41830+167 166 167 163 162 163 163 162 163 167 166 167 174 174 174 125 124 125
41831+16 19 21 4 0 0
41832+4 4 4 4 0 0 4 0 0 60 74 84 174 174 174 174 174 174
41833+158 157 158 155 154 155 155 154 155 156 155 156 155 154 155 158 157 158
41834+167 166 167 165 164 165 131 129 131 60 73 81 13 16 17 4 0 0
41835+4 0 0 4 3 3 6 6 6 4 3 3 5 5 5 4 4 4
41836+4 4 4 3 2 2 0 0 0 0 0 0 7 11 13 45 69 86
41837+80 127 157 71 116 144 43 61 72 7 11 13 0 0 0 1 1 1
41838+4 3 3 4 4 4 4 4 4 4 4 4 6 6 6 5 5 5
41839+3 2 2 4 0 0 1 0 0 21 29 34 59 113 148 136 185 209
41840+146 190 211 136 185 209 136 185 209 136 185 209 136 185 209 136 185 209
41841+68 124 159 44 81 103 22 40 52 13 16 17 43 61 72 90 154 193
41842+136 185 209 59 113 148 21 29 34 3 4 3 1 1 1 0 0 0
41843+24 26 27 125 124 125 163 162 163 174 174 174 166 165 166 165 164 165
41844+163 162 163 125 124 125 125 124 125 125 124 125 125 124 125 26 28 28
41845+4 0 0 4 3 3
41846+3 3 3 0 0 0 24 26 27 153 152 153 177 184 187 158 157 158
41847+156 155 156 156 155 156 155 154 155 155 154 155 165 164 165 174 174 174
41848+155 154 155 60 74 84 26 28 28 4 0 0 4 0 0 3 1 0
41849+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 3 3
41850+2 0 0 0 0 0 0 0 0 32 43 50 72 125 159 101 161 196
41851+136 185 209 101 161 196 101 161 196 79 117 143 32 43 50 0 0 0
41852+0 0 0 2 2 2 4 4 4 4 4 4 3 3 3 1 0 0
41853+0 0 0 4 5 5 49 76 92 101 161 196 146 190 211 146 190 211
41854+136 185 209 136 185 209 136 185 209 136 185 209 136 185 209 90 154 193
41855+28 67 93 13 16 17 37 51 59 80 127 157 136 185 209 90 154 193
41856+22 40 52 6 9 11 3 4 3 2 2 1 16 19 21 60 73 81
41857+137 136 137 163 162 163 158 157 158 166 165 166 167 166 167 153 152 153
41858+60 74 84 37 38 37 6 6 6 13 16 17 4 0 0 1 0 0
41859+3 2 2 4 4 4
41860+3 2 2 4 0 0 37 38 37 137 136 137 167 166 167 158 157 158
41861+157 156 157 154 153 154 157 156 157 167 166 167 174 174 174 125 124 125
41862+37 38 37 4 0 0 4 0 0 4 0 0 4 3 3 4 4 4
41863+4 4 4 4 4 4 5 5 5 5 5 5 1 1 1 0 0 0
41864+0 0 0 16 21 25 55 98 126 90 154 193 136 185 209 101 161 196
41865+101 161 196 101 161 196 136 185 209 136 185 209 101 161 196 55 98 126
41866+14 17 19 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
41867+22 40 52 90 154 193 146 190 211 146 190 211 136 185 209 136 185 209
41868+136 185 209 136 185 209 136 185 209 101 161 196 35 83 115 7 11 13
41869+17 23 27 59 113 148 136 185 209 101 161 196 34 86 122 7 12 15
41870+2 5 5 3 4 3 6 6 6 60 73 81 131 129 131 163 162 163
41871+166 165 166 174 174 174 174 174 174 163 162 163 125 124 125 41 54 63
41872+13 16 17 4 0 0 4 0 0 4 0 0 1 0 0 2 2 2
41873+4 4 4 4 4 4
41874+1 1 1 2 1 0 43 57 68 137 136 137 153 152 153 153 152 153
41875+163 162 163 156 155 156 165 164 165 167 166 167 60 74 84 6 6 6
41876+4 0 0 4 0 0 5 5 5 4 4 4 4 4 4 4 4 4
41877+4 5 5 6 6 6 4 3 3 0 0 0 0 0 0 11 15 18
41878+40 71 93 100 139 164 101 161 196 101 161 196 101 161 196 101 161 196
41879+101 161 196 101 161 196 101 161 196 101 161 196 136 185 209 136 185 209
41880+101 161 196 45 69 86 6 6 6 0 0 0 17 23 27 55 98 126
41881+136 185 209 146 190 211 136 185 209 136 185 209 136 185 209 136 185 209
41882+136 185 209 136 185 209 90 154 193 22 40 52 7 11 13 50 82 103
41883+136 185 209 136 185 209 53 118 160 22 40 52 7 11 13 2 5 5
41884+3 4 3 37 38 37 125 124 125 157 156 157 166 165 166 167 166 167
41885+174 174 174 174 174 174 137 136 137 60 73 81 4 0 0 4 0 0
41886+4 0 0 4 0 0 5 5 5 3 3 3 3 3 3 4 4 4
41887+4 4 4 4 4 4
41888+4 0 0 4 0 0 41 54 63 137 136 137 125 124 125 131 129 131
41889+155 154 155 167 166 167 174 174 174 60 74 84 6 6 6 4 0 0
41890+4 3 3 6 6 6 4 4 4 4 4 4 4 4 4 5 5 5
41891+4 4 4 1 1 1 0 0 0 3 6 7 41 65 82 72 125 159
41892+101 161 196 101 161 196 101 161 196 90 154 193 90 154 193 101 161 196
41893+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 136 185 209
41894+136 185 209 136 185 209 80 127 157 55 98 126 101 161 196 146 190 211
41895+136 185 209 136 185 209 136 185 209 101 161 196 136 185 209 101 161 196
41896+136 185 209 101 161 196 35 83 115 22 30 35 101 161 196 172 205 220
41897+90 154 193 28 67 93 7 11 13 2 5 5 3 4 3 13 16 17
41898+85 115 134 167 166 167 174 174 174 174 174 174 174 174 174 174 174 174
41899+167 166 167 60 74 84 13 16 17 4 0 0 4 0 0 4 3 3
41900+6 6 6 5 5 5 4 4 4 5 5 5 4 4 4 5 5 5
41901+5 5 5 5 5 5
41902+1 1 1 4 0 0 41 54 63 137 136 137 137 136 137 125 124 125
41903+131 129 131 167 166 167 157 156 157 37 38 37 6 6 6 4 0 0
41904+6 6 6 5 5 5 4 4 4 4 4 4 4 5 5 2 2 1
41905+0 0 0 0 0 0 26 37 45 58 111 146 101 161 196 101 161 196
41906+101 161 196 90 154 193 90 154 193 90 154 193 101 161 196 101 161 196
41907+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
41908+101 161 196 136 185 209 136 185 209 136 185 209 146 190 211 136 185 209
41909+136 185 209 101 161 196 136 185 209 136 185 209 101 161 196 136 185 209
41910+101 161 196 136 185 209 136 185 209 136 185 209 136 185 209 16 89 141
41911+7 11 13 2 5 5 2 5 5 13 16 17 60 73 81 154 154 154
41912+174 174 174 174 174 174 174 174 174 174 174 174 163 162 163 125 124 125
41913+24 26 27 4 0 0 4 0 0 4 0 0 5 5 5 5 5 5
41914+4 4 4 4 4 4 4 4 4 5 5 5 5 5 5 5 5 5
41915+5 5 5 4 4 4
41916+4 0 0 6 6 6 37 38 37 137 136 137 137 136 137 131 129 131
41917+131 129 131 153 152 153 131 129 131 26 28 28 4 0 0 4 3 3
41918+6 6 6 4 4 4 4 4 4 4 4 4 0 0 0 0 0 0
41919+13 20 25 51 88 114 90 154 193 101 161 196 101 161 196 90 154 193
41920+90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 101 161 196
41921+101 161 196 101 161 196 101 161 196 101 161 196 136 185 209 101 161 196
41922+101 161 196 136 185 209 101 161 196 136 185 209 136 185 209 101 161 196
41923+136 185 209 101 161 196 136 185 209 101 161 196 101 161 196 101 161 196
41924+136 185 209 136 185 209 136 185 209 37 112 160 21 29 34 5 7 8
41925+2 5 5 13 16 17 43 57 68 131 129 131 174 174 174 174 174 174
41926+174 174 174 167 166 167 157 156 157 125 124 125 37 38 37 4 0 0
41927+4 0 0 4 0 0 5 5 5 5 5 5 4 4 4 4 4 4
41928+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41929+4 4 4 4 4 4
41930+1 1 1 4 0 0 41 54 63 153 152 153 137 136 137 137 136 137
41931+137 136 137 153 152 153 125 124 125 24 26 27 4 0 0 3 2 2
41932+4 4 4 4 4 4 4 3 3 4 0 0 3 6 7 43 61 72
41933+64 123 161 101 161 196 90 154 193 90 154 193 90 154 193 90 154 193
41934+90 154 193 90 154 193 90 154 193 90 154 193 101 161 196 90 154 193
41935+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
41936+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
41937+136 185 209 101 161 196 101 161 196 136 185 209 136 185 209 101 161 196
41938+101 161 196 90 154 193 28 67 93 13 16 17 7 11 13 3 6 7
41939+37 51 59 125 124 125 163 162 163 174 174 174 167 166 167 166 165 166
41940+167 166 167 131 129 131 60 73 81 4 0 0 4 0 0 4 0 0
41941+3 3 3 5 5 5 6 6 6 4 4 4 4 4 4 4 4 4
41942+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41943+4 4 4 4 4 4
41944+4 0 0 4 0 0 41 54 63 137 136 137 153 152 153 137 136 137
41945+153 152 153 157 156 157 125 124 125 24 26 27 0 0 0 2 2 2
41946+4 4 4 4 4 4 2 0 0 0 0 0 28 67 93 90 154 193
41947+90 154 193 90 154 193 90 154 193 90 154 193 64 123 161 90 154 193
41948+90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 101 161 196
41949+90 154 193 101 161 196 101 161 196 101 161 196 90 154 193 136 185 209
41950+101 161 196 101 161 196 136 185 209 101 161 196 136 185 209 101 161 196
41951+101 161 196 101 161 196 136 185 209 101 161 196 101 161 196 90 154 193
41952+35 83 115 13 16 17 3 6 7 2 5 5 13 16 17 60 74 84
41953+154 154 154 166 165 166 165 164 165 158 157 158 163 162 163 157 156 157
41954+60 74 84 13 16 17 4 0 0 4 0 0 3 2 2 4 4 4
41955+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41956+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41957+4 4 4 4 4 4
41958+1 1 1 4 0 0 41 54 63 157 156 157 155 154 155 137 136 137
41959+153 152 153 158 157 158 137 136 137 26 28 28 2 0 0 2 2 2
41960+4 4 4 4 4 4 1 0 0 6 10 14 34 86 122 90 154 193
41961+64 123 161 90 154 193 64 123 161 90 154 193 90 154 193 90 154 193
41962+64 123 161 90 154 193 90 154 193 90 154 193 90 154 193 90 154 193
41963+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
41964+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
41965+136 185 209 101 161 196 136 185 209 90 154 193 26 108 161 22 40 52
41966+13 16 17 5 7 8 2 5 5 2 5 5 37 38 37 165 164 165
41967+174 174 174 163 162 163 154 154 154 165 164 165 167 166 167 60 73 81
41968+6 6 6 4 0 0 4 0 0 4 4 4 4 4 4 4 4 4
41969+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41970+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41971+4 4 4 4 4 4
41972+4 0 0 6 6 6 41 54 63 156 155 156 158 157 158 153 152 153
41973+156 155 156 165 164 165 137 136 137 26 28 28 0 0 0 2 2 2
41974+4 4 5 4 4 4 2 0 0 7 12 15 31 96 139 64 123 161
41975+90 154 193 64 123 161 90 154 193 90 154 193 64 123 161 90 154 193
41976+90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 90 154 193
41977+90 154 193 90 154 193 90 154 193 101 161 196 101 161 196 101 161 196
41978+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 136 185 209
41979+101 161 196 136 185 209 26 108 161 22 40 52 7 11 13 5 7 8
41980+2 5 5 2 5 5 2 5 5 2 2 1 37 38 37 158 157 158
41981+174 174 174 154 154 154 156 155 156 167 166 167 165 164 165 37 38 37
41982+4 0 0 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41983+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41984+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41985+4 4 4 4 4 4
41986+3 1 0 4 0 0 60 73 81 157 156 157 163 162 163 153 152 153
41987+158 157 158 167 166 167 137 136 137 26 28 28 2 0 0 2 2 2
41988+4 5 5 4 4 4 4 0 0 7 12 15 24 86 132 26 108 161
41989+37 112 160 64 123 161 90 154 193 64 123 161 90 154 193 90 154 193
41990+90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 90 154 193
41991+90 154 193 101 161 196 90 154 193 101 161 196 101 161 196 101 161 196
41992+101 161 196 101 161 196 101 161 196 136 185 209 101 161 196 136 185 209
41993+90 154 193 35 83 115 13 16 17 13 16 17 7 11 13 3 6 7
41994+5 7 8 6 6 6 3 4 3 2 2 1 30 32 34 154 154 154
41995+167 166 167 154 154 154 154 154 154 174 174 174 165 164 165 37 38 37
41996+6 6 6 4 0 0 6 6 6 4 4 4 4 4 4 4 4 4
41997+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41998+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41999+4 4 4 4 4 4
42000+4 0 0 4 0 0 41 54 63 163 162 163 166 165 166 154 154 154
42001+163 162 163 174 174 174 137 136 137 26 28 28 0 0 0 2 2 2
42002+4 5 5 4 4 5 1 1 2 6 10 14 28 67 93 18 97 151
42003+18 97 151 18 97 151 26 108 161 37 112 160 37 112 160 90 154 193
42004+64 123 161 90 154 193 90 154 193 90 154 193 90 154 193 101 161 196
42005+90 154 193 101 161 196 101 161 196 90 154 193 101 161 196 101 161 196
42006+101 161 196 101 161 196 101 161 196 136 185 209 90 154 193 16 89 141
42007+13 20 25 7 11 13 5 7 8 5 7 8 2 5 5 4 5 5
42008+3 4 3 4 5 5 3 4 3 0 0 0 37 38 37 158 157 158
42009+174 174 174 158 157 158 158 157 158 167 166 167 174 174 174 41 54 63
42010+4 0 0 3 2 2 5 5 5 4 4 4 4 4 4 4 4 4
42011+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42012+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42013+4 4 4 4 4 4
42014+1 1 1 4 0 0 60 73 81 165 164 165 174 174 174 158 157 158
42015+167 166 167 174 174 174 153 152 153 26 28 28 2 0 0 2 2 2
42016+4 5 5 4 4 4 4 0 0 7 12 15 10 87 144 10 87 144
42017+18 97 151 18 97 151 18 97 151 26 108 161 26 108 161 26 108 161
42018+26 108 161 37 112 160 53 118 160 90 154 193 90 154 193 90 154 193
42019+90 154 193 90 154 193 101 161 196 101 161 196 101 161 196 101 161 196
42020+101 161 196 136 185 209 90 154 193 26 108 161 22 40 52 13 16 17
42021+7 11 13 3 6 7 5 7 8 5 7 8 2 5 5 4 5 5
42022+4 5 5 6 6 6 3 4 3 0 0 0 30 32 34 158 157 158
42023+174 174 174 156 155 156 155 154 155 165 164 165 154 153 154 37 38 37
42024+4 0 0 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
42025+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42026+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42027+4 4 4 4 4 4
42028+4 0 0 4 0 0 60 73 81 167 166 167 174 174 174 163 162 163
42029+174 174 174 174 174 174 153 152 153 26 28 28 0 0 0 3 3 3
42030+5 5 5 4 4 4 1 1 2 7 12 15 28 67 93 18 97 151
42031+18 97 151 18 97 151 18 97 151 18 97 151 18 97 151 26 108 161
42032+26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
42033+90 154 193 26 108 161 90 154 193 90 154 193 90 154 193 101 161 196
42034+101 161 196 26 108 161 22 40 52 13 16 17 7 11 13 2 5 5
42035+2 5 5 6 6 6 2 5 5 4 5 5 4 5 5 4 5 5
42036+3 4 3 5 5 5 3 4 3 2 0 0 30 32 34 137 136 137
42037+153 152 153 137 136 137 131 129 131 137 136 137 131 129 131 37 38 37
42038+4 0 0 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
42039+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42040+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42041+4 4 4 4 4 4
42042+1 1 1 4 0 0 60 73 81 167 166 167 174 174 174 166 165 166
42043+174 174 174 177 184 187 153 152 153 30 32 34 1 0 0 3 3 3
42044+5 5 5 4 3 3 4 0 0 7 12 15 10 87 144 10 87 144
42045+18 97 151 18 97 151 18 97 151 26 108 161 26 108 161 26 108 161
42046+26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
42047+26 108 161 26 108 161 26 108 161 90 154 193 90 154 193 26 108 161
42048+35 83 115 13 16 17 7 11 13 5 7 8 3 6 7 5 7 8
42049+2 5 5 6 6 6 4 5 5 4 5 5 3 4 3 4 5 5
42050+3 4 3 6 6 6 3 4 3 0 0 0 26 28 28 125 124 125
42051+131 129 131 125 124 125 125 124 125 131 129 131 131 129 131 37 38 37
42052+4 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
42053+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42054+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42055+4 4 4 4 4 4
42056+3 1 0 4 0 0 60 73 81 174 174 174 177 184 187 167 166 167
42057+174 174 174 177 184 187 153 152 153 30 32 34 0 0 0 3 3 3
42058+5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 18 97 151
42059+18 97 151 18 97 151 18 97 151 18 97 151 18 97 151 26 108 161
42060+26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
42061+26 108 161 90 154 193 26 108 161 26 108 161 24 86 132 13 20 25
42062+7 11 13 13 20 25 22 40 52 5 7 8 3 4 3 3 4 3
42063+4 5 5 3 4 3 4 5 5 3 4 3 4 5 5 3 4 3
42064+4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 125 124 125
42065+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
42066+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
42067+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42068+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42069+4 4 4 4 4 4
42070+1 1 1 4 0 0 60 73 81 174 174 174 177 184 187 174 174 174
42071+174 174 174 190 197 201 157 156 157 30 32 34 1 0 0 3 3 3
42072+5 5 5 4 3 3 4 0 0 7 12 15 10 87 144 10 87 144
42073+18 97 151 19 95 150 19 95 150 18 97 151 18 97 151 26 108 161
42074+18 97 151 26 108 161 26 108 161 26 108 161 26 108 161 90 154 193
42075+26 108 161 26 108 161 26 108 161 22 40 52 2 5 5 3 4 3
42076+28 67 93 37 112 160 34 86 122 2 5 5 3 4 3 3 4 3
42077+3 4 3 3 4 3 3 4 3 2 2 1 3 4 3 4 4 4
42078+4 5 5 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
42079+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
42080+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
42081+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42082+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42083+4 4 4 4 4 4
42084+4 0 0 4 0 0 60 73 81 174 174 174 177 184 187 174 174 174
42085+174 174 174 190 197 201 158 157 158 30 32 34 0 0 0 2 2 2
42086+5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 18 97 151
42087+10 87 144 19 95 150 19 95 150 18 97 151 18 97 151 18 97 151
42088+26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
42089+18 97 151 22 40 52 2 5 5 2 2 1 22 40 52 26 108 161
42090+90 154 193 37 112 160 22 40 52 3 4 3 13 20 25 22 30 35
42091+3 6 7 1 1 1 2 2 2 6 9 11 5 5 5 4 3 3
42092+4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 131 129 131
42093+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
42094+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
42095+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42096+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42097+4 4 4 4 4 4
42098+1 1 1 4 0 0 60 73 81 177 184 187 193 200 203 174 174 174
42099+177 184 187 193 200 203 163 162 163 30 32 34 4 0 0 2 2 2
42100+5 5 5 4 3 3 4 0 0 6 10 14 24 86 132 10 87 144
42101+10 87 144 10 87 144 19 95 150 19 95 150 19 95 150 18 97 151
42102+26 108 161 26 108 161 26 108 161 90 154 193 26 108 161 28 67 93
42103+6 10 14 2 5 5 13 20 25 24 86 132 37 112 160 90 154 193
42104+10 87 144 7 12 15 2 5 5 28 67 93 37 112 160 28 67 93
42105+2 2 1 7 12 15 35 83 115 28 67 93 3 6 7 1 0 0
42106+4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
42107+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
42108+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
42109+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42110+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42111+4 4 4 4 4 4
42112+4 0 0 4 0 0 60 73 81 174 174 174 190 197 201 174 174 174
42113+177 184 187 193 200 203 163 162 163 30 32 34 0 0 0 2 2 2
42114+5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 10 87 144
42115+10 87 144 16 89 141 19 95 150 10 87 144 26 108 161 26 108 161
42116+26 108 161 26 108 161 26 108 161 28 67 93 6 10 14 1 1 2
42117+7 12 15 28 67 93 26 108 161 16 89 141 24 86 132 21 29 34
42118+3 4 3 21 29 34 37 112 160 37 112 160 27 99 146 21 29 34
42119+21 29 34 26 108 161 90 154 193 35 83 115 1 1 2 2 0 0
42120+4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 125 124 125
42121+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
42122+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
42123+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42124+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42125+4 4 4 4 4 4
42126+3 1 0 4 0 0 60 73 81 193 200 203 193 200 203 174 174 174
42127+190 197 201 193 200 203 165 164 165 37 38 37 4 0 0 2 2 2
42128+5 5 5 4 3 3 4 0 0 6 10 14 24 86 132 10 87 144
42129+10 87 144 10 87 144 16 89 141 18 97 151 18 97 151 10 87 144
42130+24 86 132 24 86 132 13 20 25 4 5 7 4 5 7 22 40 52
42131+18 97 151 37 112 160 26 108 161 7 12 15 1 1 1 0 0 0
42132+28 67 93 37 112 160 26 108 161 28 67 93 22 40 52 28 67 93
42133+26 108 161 90 154 193 26 108 161 10 87 144 0 0 0 2 0 0
42134+4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
42135+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
42136+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
42137+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42138+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42139+4 4 4 4 4 4
42140+4 0 0 6 6 6 60 73 81 174 174 174 193 200 203 174 174 174
42141+190 197 201 193 200 203 165 164 165 30 32 34 0 0 0 2 2 2
42142+5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 10 87 144
42143+10 87 144 10 87 144 10 87 144 18 97 151 28 67 93 6 10 14
42144+0 0 0 1 1 2 4 5 7 13 20 25 16 89 141 26 108 161
42145+26 108 161 26 108 161 24 86 132 6 9 11 2 3 3 22 40 52
42146+37 112 160 16 89 141 22 40 52 28 67 93 26 108 161 26 108 161
42147+90 154 193 26 108 161 26 108 161 28 67 93 1 1 1 4 0 0
42148+4 4 4 5 5 5 3 3 3 4 0 0 26 28 28 124 126 130
42149+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
42150+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
42151+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42152+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42153+4 4 4 4 4 4
42154+4 0 0 4 0 0 60 73 81 193 200 203 193 200 203 174 174 174
42155+193 200 203 193 200 203 167 166 167 37 38 37 4 0 0 2 2 2
42156+5 5 5 4 4 4 4 0 0 6 10 14 28 67 93 10 87 144
42157+10 87 144 10 87 144 18 97 151 10 87 144 13 20 25 4 5 7
42158+1 1 2 1 1 1 22 40 52 26 108 161 26 108 161 26 108 161
42159+26 108 161 26 108 161 26 108 161 24 86 132 22 40 52 22 40 52
42160+22 40 52 22 40 52 10 87 144 26 108 161 26 108 161 26 108 161
42161+26 108 161 26 108 161 90 154 193 10 87 144 0 0 0 4 0 0
42162+4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
42163+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
42164+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
42165+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42166+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42167+4 4 4 4 4 4
42168+4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
42169+190 197 201 205 212 215 167 166 167 30 32 34 0 0 0 2 2 2
42170+5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 10 87 144
42171+10 87 144 10 87 144 10 87 144 10 87 144 22 40 52 1 1 2
42172+2 0 0 1 1 2 24 86 132 26 108 161 26 108 161 26 108 161
42173+26 108 161 19 95 150 16 89 141 10 87 144 22 40 52 22 40 52
42174+10 87 144 26 108 161 37 112 160 26 108 161 26 108 161 26 108 161
42175+26 108 161 26 108 161 26 108 161 28 67 93 2 0 0 3 1 0
42176+4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 131 129 131
42177+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
42178+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
42179+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42180+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42181+4 4 4 4 4 4
42182+4 0 0 4 0 0 60 73 81 220 221 221 190 197 201 174 174 174
42183+193 200 203 193 200 203 174 174 174 37 38 37 4 0 0 2 2 2
42184+5 5 5 4 4 4 3 2 2 1 1 2 13 20 25 10 87 144
42185+10 87 144 10 87 144 10 87 144 10 87 144 10 87 144 13 20 25
42186+13 20 25 22 40 52 10 87 144 18 97 151 18 97 151 26 108 161
42187+10 87 144 13 20 25 6 10 14 21 29 34 24 86 132 18 97 151
42188+26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
42189+26 108 161 90 154 193 18 97 151 13 20 25 0 0 0 4 3 3
42190+4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
42191+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
42192+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
42193+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42194+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42195+4 4 4 4 4 4
42196+4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
42197+190 197 201 220 221 221 167 166 167 30 32 34 1 0 0 2 2 2
42198+5 5 5 4 4 4 4 4 5 2 5 5 4 5 7 13 20 25
42199+28 67 93 10 87 144 10 87 144 10 87 144 10 87 144 10 87 144
42200+10 87 144 10 87 144 18 97 151 10 87 144 18 97 151 18 97 151
42201+28 67 93 2 3 3 0 0 0 28 67 93 26 108 161 26 108 161
42202+26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
42203+26 108 161 10 87 144 13 20 25 1 1 2 3 2 2 4 4 4
42204+4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 131 129 131
42205+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
42206+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
42207+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42208+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42209+4 4 4 4 4 4
42210+4 0 0 4 0 0 60 73 81 220 221 221 190 197 201 174 174 174
42211+193 200 203 193 200 203 174 174 174 26 28 28 4 0 0 4 3 3
42212+5 5 5 4 4 4 4 4 4 4 4 5 1 1 2 2 5 5
42213+4 5 7 22 40 52 10 87 144 10 87 144 18 97 151 10 87 144
42214+10 87 144 10 87 144 10 87 144 10 87 144 10 87 144 18 97 151
42215+10 87 144 28 67 93 22 40 52 10 87 144 26 108 161 18 97 151
42216+18 97 151 18 97 151 26 108 161 26 108 161 26 108 161 26 108 161
42217+22 40 52 1 1 2 0 0 0 2 3 3 4 4 4 4 4 4
42218+4 4 4 5 5 5 4 4 4 0 0 0 26 28 28 131 129 131
42219+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
42220+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
42221+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42222+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42223+4 4 4 4 4 4
42224+4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
42225+190 197 201 220 221 221 190 197 201 41 54 63 4 0 0 2 2 2
42226+6 6 6 4 4 4 4 4 4 4 4 5 4 4 5 3 3 3
42227+1 1 2 1 1 2 6 10 14 22 40 52 10 87 144 18 97 151
42228+18 97 151 10 87 144 10 87 144 10 87 144 18 97 151 10 87 144
42229+10 87 144 18 97 151 26 108 161 18 97 151 18 97 151 10 87 144
42230+26 108 161 26 108 161 26 108 161 10 87 144 28 67 93 6 10 14
42231+1 1 2 1 1 2 4 3 3 4 4 5 4 4 4 4 4 4
42232+5 5 5 5 5 5 1 1 1 4 0 0 37 51 59 137 136 137
42233+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
42234+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
42235+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42236+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42237+4 4 4 4 4 4
42238+4 0 0 4 0 0 60 73 81 220 221 221 193 200 203 174 174 174
42239+193 200 203 193 200 203 220 221 221 137 136 137 13 16 17 4 0 0
42240+2 2 2 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5
42241+4 4 5 4 3 3 1 1 2 4 5 7 13 20 25 28 67 93
42242+10 87 144 10 87 144 10 87 144 10 87 144 10 87 144 10 87 144
42243+10 87 144 18 97 151 18 97 151 10 87 144 18 97 151 26 108 161
42244+26 108 161 18 97 151 28 67 93 6 10 14 0 0 0 0 0 0
42245+2 3 3 4 5 5 4 4 5 4 4 4 4 4 4 5 5 5
42246+3 3 3 1 1 1 0 0 0 16 19 21 125 124 125 137 136 137
42247+131 129 131 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
42248+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
42249+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42250+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42251+4 4 4 4 4 4
42252+4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
42253+193 200 203 190 197 201 220 221 221 220 221 221 153 152 153 30 32 34
42254+0 0 0 0 0 0 2 2 2 4 4 4 4 4 4 4 4 4
42255+4 4 4 4 5 5 4 5 7 1 1 2 1 1 2 4 5 7
42256+13 20 25 28 67 93 10 87 144 18 97 151 10 87 144 10 87 144
42257+10 87 144 10 87 144 10 87 144 18 97 151 26 108 161 18 97 151
42258+28 67 93 7 12 15 0 0 0 0 0 0 2 2 1 4 4 4
42259+4 5 5 4 5 5 4 4 4 4 4 4 3 3 3 0 0 0
42260+0 0 0 0 0 0 37 38 37 125 124 125 158 157 158 131 129 131
42261+125 124 125 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
42262+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
42263+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42264+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42265+4 4 4 4 4 4
42266+4 3 3 4 0 0 41 54 63 193 200 203 220 221 221 174 174 174
42267+193 200 203 193 200 203 193 200 203 220 221 221 244 246 246 193 200 203
42268+120 125 127 5 5 5 1 0 0 0 0 0 1 1 1 4 4 4
42269+4 4 4 4 4 4 4 5 5 4 5 5 4 4 5 1 1 2
42270+4 5 7 4 5 7 22 40 52 10 87 144 10 87 144 10 87 144
42271+10 87 144 10 87 144 18 97 151 10 87 144 10 87 144 13 20 25
42272+4 5 7 2 3 3 1 1 2 4 4 4 4 5 5 4 4 4
42273+4 4 4 4 4 4 4 4 4 1 1 1 0 0 0 1 1 2
42274+24 26 27 60 74 84 153 152 153 163 162 163 137 136 137 125 124 125
42275+125 124 125 125 124 125 125 124 125 137 136 137 125 124 125 26 28 28
42276+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
42277+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42278+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42279+4 4 4 4 4 4
42280+4 0 0 6 6 6 26 28 28 156 155 156 220 221 221 220 221 221
42281+174 174 174 193 200 203 193 200 203 193 200 203 205 212 215 220 221 221
42282+220 221 221 167 166 167 60 73 81 7 11 13 0 0 0 0 0 0
42283+3 3 3 4 4 4 4 4 4 4 4 4 4 4 5 4 4 5
42284+4 4 5 1 1 2 1 1 2 4 5 7 22 40 52 10 87 144
42285+10 87 144 10 87 144 10 87 144 22 40 52 4 5 7 1 1 2
42286+1 1 2 4 4 5 4 4 4 4 4 4 4 4 4 4 4 4
42287+5 5 5 2 2 2 0 0 0 4 0 0 16 19 21 60 73 81
42288+137 136 137 167 166 167 158 157 158 137 136 137 131 129 131 131 129 131
42289+125 124 125 125 124 125 131 129 131 155 154 155 60 74 84 5 7 8
42290+0 0 0 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42291+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42292+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42293+4 4 4 4 4 4
42294+5 5 5 4 0 0 4 0 0 60 73 81 193 200 203 220 221 221
42295+193 200 203 193 200 203 193 200 203 193 200 203 205 212 215 220 221 221
42296+220 221 221 220 221 221 220 221 221 137 136 137 43 57 68 6 6 6
42297+4 0 0 1 1 1 4 4 4 4 4 4 4 4 4 4 4 4
42298+4 4 5 4 4 5 3 2 2 1 1 2 2 5 5 13 20 25
42299+22 40 52 22 40 52 13 20 25 2 3 3 1 1 2 3 3 3
42300+4 5 7 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42301+1 1 1 0 0 0 2 3 3 41 54 63 131 129 131 166 165 166
42302+166 165 166 155 154 155 153 152 153 137 136 137 137 136 137 125 124 125
42303+125 124 125 137 136 137 137 136 137 125 124 125 37 38 37 4 3 3
42304+4 3 3 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
42305+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42306+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42307+4 4 4 4 4 4
42308+4 3 3 6 6 6 6 6 6 13 16 17 60 73 81 167 166 167
42309+220 221 221 220 221 221 220 221 221 193 200 203 193 200 203 193 200 203
42310+205 212 215 220 221 221 220 221 221 244 246 246 205 212 215 125 124 125
42311+24 26 27 0 0 0 0 0 0 2 2 2 5 5 5 5 5 5
42312+4 4 4 4 4 4 4 4 4 4 4 5 1 1 2 4 5 7
42313+4 5 7 4 5 7 1 1 2 3 2 2 4 4 5 4 4 4
42314+4 4 4 4 4 4 5 5 5 4 4 4 0 0 0 0 0 0
42315+2 0 0 26 28 28 125 124 125 174 174 174 174 174 174 166 165 166
42316+156 155 156 153 152 153 137 136 137 137 136 137 131 129 131 137 136 137
42317+137 136 137 137 136 137 60 74 84 30 32 34 4 0 0 4 0 0
42318+5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42319+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42320+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42321+4 4 4 4 4 4
42322+5 5 5 6 6 6 4 0 0 4 0 0 6 6 6 26 28 28
42323+125 124 125 174 174 174 220 221 221 220 221 221 220 221 221 193 200 203
42324+205 212 215 220 221 221 205 212 215 220 221 221 220 221 221 244 246 246
42325+193 200 203 60 74 84 13 16 17 4 0 0 0 0 0 3 3 3
42326+5 5 5 5 5 5 4 4 4 4 4 4 4 4 5 3 3 3
42327+1 1 2 3 3 3 4 4 5 4 4 5 4 4 4 4 4 4
42328+5 5 5 5 5 5 2 2 2 0 0 0 0 0 0 13 16 17
42329+60 74 84 174 174 174 193 200 203 174 174 174 167 166 167 163 162 163
42330+153 152 153 153 152 153 137 136 137 137 136 137 153 152 153 137 136 137
42331+125 124 125 41 54 63 24 26 27 4 0 0 4 0 0 5 5 5
42332+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42333+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42334+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42335+4 4 4 4 4 4
42336+4 3 3 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6
42337+6 6 6 37 38 37 131 129 131 220 221 221 220 221 221 220 221 221
42338+193 200 203 193 200 203 220 221 221 205 212 215 220 221 221 244 246 246
42339+244 246 246 244 246 246 174 174 174 41 54 63 0 0 0 0 0 0
42340+0 0 0 4 4 4 5 5 5 5 5 5 4 4 4 4 4 5
42341+4 4 5 4 4 5 4 4 4 4 4 4 6 6 6 6 6 6
42342+3 3 3 0 0 0 2 0 0 13 16 17 60 73 81 156 155 156
42343+220 221 221 193 200 203 174 174 174 165 164 165 163 162 163 154 153 154
42344+153 152 153 153 152 153 158 157 158 163 162 163 137 136 137 60 73 81
42345+13 16 17 4 0 0 4 0 0 4 3 3 4 4 4 4 4 4
42346+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42347+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42348+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42349+4 4 4 4 4 4
42350+5 5 5 4 3 3 4 3 3 6 6 6 6 6 6 6 6 6
42351+6 6 6 6 6 6 6 6 6 37 38 37 167 166 167 244 246 246
42352+244 246 246 220 221 221 205 212 215 205 212 215 220 221 221 193 200 203
42353+220 221 221 244 246 246 244 246 246 244 246 246 137 136 137 37 38 37
42354+3 2 2 0 0 0 1 1 1 5 5 5 5 5 5 4 4 4
42355+4 4 4 4 4 4 4 4 4 5 5 5 4 4 4 1 1 1
42356+0 0 0 5 5 5 43 57 68 153 152 153 193 200 203 220 221 221
42357+177 184 187 174 174 174 167 166 167 166 165 166 158 157 158 157 156 157
42358+158 157 158 166 165 166 156 155 156 85 115 134 13 16 17 4 0 0
42359+4 0 0 4 0 0 5 5 5 5 5 5 4 4 4 4 4 4
42360+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42361+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42362+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42363+4 4 4 4 4 4
42364+5 5 5 4 3 3 6 6 6 6 6 6 4 0 0 6 6 6
42365+6 6 6 6 6 6 6 6 6 6 6 6 13 16 17 60 73 81
42366+177 184 187 220 221 221 220 221 221 220 221 221 205 212 215 220 221 221
42367+220 221 221 205 212 215 220 221 221 244 246 246 244 246 246 205 212 215
42368+125 124 125 30 32 34 0 0 0 0 0 0 2 2 2 5 5 5
42369+4 4 4 4 4 4 4 4 4 1 1 1 0 0 0 1 0 0
42370+37 38 37 131 129 131 205 212 215 220 221 221 193 200 203 174 174 174
42371+174 174 174 174 174 174 167 166 167 165 164 165 166 165 166 167 166 167
42372+158 157 158 125 124 125 37 38 37 4 0 0 4 0 0 4 0 0
42373+4 3 3 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
42374+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42375+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42376+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42377+4 4 4 4 4 4
42378+4 4 4 5 5 5 4 3 3 4 3 3 6 6 6 6 6 6
42379+4 0 0 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6
42380+26 28 28 125 124 125 205 212 215 220 221 221 220 221 221 220 221 221
42381+205 212 215 220 221 221 205 212 215 220 221 221 220 221 221 244 246 246
42382+244 246 246 190 197 201 60 74 84 16 19 21 4 0 0 0 0 0
42383+0 0 0 0 0 0 0 0 0 0 0 0 16 19 21 120 125 127
42384+177 184 187 220 221 221 205 212 215 177 184 187 174 174 174 177 184 187
42385+174 174 174 174 174 174 167 166 167 174 174 174 166 165 166 137 136 137
42386+60 73 81 13 16 17 4 0 0 4 0 0 4 3 3 6 6 6
42387+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42388+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42389+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42390+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42391+4 4 4 4 4 4
42392+5 5 5 4 3 3 5 5 5 4 3 3 6 6 6 4 0 0
42393+6 6 6 6 6 6 4 0 0 6 6 6 4 0 0 6 6 6
42394+6 6 6 6 6 6 37 38 37 137 136 137 193 200 203 220 221 221
42395+220 221 221 205 212 215 220 221 221 205 212 215 205 212 215 220 221 221
42396+220 221 221 220 221 221 244 246 246 166 165 166 43 57 68 2 2 2
42397+0 0 0 4 0 0 16 19 21 60 73 81 157 156 157 202 210 214
42398+220 221 221 193 200 203 177 184 187 177 184 187 177 184 187 174 174 174
42399+174 174 174 174 174 174 174 174 174 157 156 157 60 74 84 24 26 27
42400+4 0 0 4 0 0 4 0 0 6 6 6 4 4 4 4 4 4
42401+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42402+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42403+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42404+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42405+4 4 4 4 4 4
42406+4 4 4 4 4 4 5 5 5 4 3 3 5 5 5 6 6 6
42407+6 6 6 4 0 0 6 6 6 6 6 6 6 6 6 4 0 0
42408+4 0 0 4 0 0 6 6 6 24 26 27 60 73 81 167 166 167
42409+220 221 221 220 221 221 220 221 221 205 212 215 205 212 215 205 212 215
42410+205 212 215 220 221 221 220 221 221 220 221 221 205 212 215 137 136 137
42411+60 74 84 125 124 125 137 136 137 190 197 201 220 221 221 193 200 203
42412+177 184 187 177 184 187 177 184 187 174 174 174 174 174 174 177 184 187
42413+190 197 201 174 174 174 125 124 125 37 38 37 6 6 6 4 0 0
42414+4 0 0 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42415+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42416+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42417+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42418+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42419+4 4 4 4 4 4
42420+4 4 4 4 4 4 5 5 5 5 5 5 4 3 3 6 6 6
42421+4 0 0 6 6 6 6 6 6 6 6 6 4 0 0 6 6 6
42422+6 6 6 6 6 6 4 0 0 4 0 0 6 6 6 6 6 6
42423+125 124 125 193 200 203 244 246 246 220 221 221 205 212 215 205 212 215
42424+205 212 215 193 200 203 205 212 215 205 212 215 220 221 221 220 221 221
42425+193 200 203 193 200 203 205 212 215 193 200 203 193 200 203 177 184 187
42426+190 197 201 190 197 201 174 174 174 190 197 201 193 200 203 190 197 201
42427+153 152 153 60 73 81 4 0 0 4 0 0 4 0 0 3 2 2
42428+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42429+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42430+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42431+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42432+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42433+4 4 4 4 4 4
42434+4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 4 3 3
42435+6 6 6 4 3 3 4 3 3 4 3 3 6 6 6 6 6 6
42436+4 0 0 6 6 6 6 6 6 6 6 6 4 0 0 4 0 0
42437+4 0 0 26 28 28 131 129 131 220 221 221 244 246 246 220 221 221
42438+205 212 215 193 200 203 205 212 215 193 200 203 193 200 203 205 212 215
42439+220 221 221 193 200 203 193 200 203 193 200 203 190 197 201 174 174 174
42440+174 174 174 190 197 201 193 200 203 193 200 203 167 166 167 125 124 125
42441+6 6 6 4 0 0 4 0 0 4 3 3 4 4 4 4 4 4
42442+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42443+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42444+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42445+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42446+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42447+4 4 4 4 4 4
42448+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
42449+5 5 5 4 3 3 5 5 5 6 6 6 4 3 3 5 5 5
42450+6 6 6 6 6 6 4 0 0 6 6 6 6 6 6 6 6 6
42451+4 0 0 4 0 0 6 6 6 41 54 63 158 157 158 220 221 221
42452+220 221 221 220 221 221 193 200 203 193 200 203 193 200 203 190 197 201
42453+190 197 201 190 197 201 190 197 201 190 197 201 174 174 174 193 200 203
42454+193 200 203 220 221 221 174 174 174 125 124 125 37 38 37 4 0 0
42455+4 0 0 4 3 3 6 6 6 4 4 4 4 4 4 4 4 4
42456+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42457+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42458+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42459+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42460+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42461+4 4 4 4 4 4
42462+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42463+4 4 4 5 5 5 4 3 3 4 3 3 4 3 3 5 5 5
42464+4 3 3 6 6 6 5 5 5 4 3 3 6 6 6 6 6 6
42465+6 6 6 6 6 6 4 0 0 4 0 0 13 16 17 60 73 81
42466+174 174 174 220 221 221 220 221 221 205 212 215 190 197 201 174 174 174
42467+193 200 203 174 174 174 190 197 201 174 174 174 193 200 203 220 221 221
42468+193 200 203 131 129 131 37 38 37 6 6 6 4 0 0 4 0 0
42469+6 6 6 6 6 6 4 3 3 5 5 5 4 4 4 4 4 4
42470+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42471+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42472+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42473+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42474+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42475+4 4 4 4 4 4
42476+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42477+4 4 4 4 4 4 4 4 4 5 5 5 5 5 5 5 5 5
42478+5 5 5 4 3 3 4 3 3 5 5 5 4 3 3 4 3 3
42479+5 5 5 6 6 6 6 6 6 4 0 0 6 6 6 6 6 6
42480+6 6 6 125 124 125 174 174 174 220 221 221 220 221 221 193 200 203
42481+193 200 203 193 200 203 193 200 203 193 200 203 220 221 221 158 157 158
42482+60 73 81 6 6 6 4 0 0 4 0 0 5 5 5 6 6 6
42483+5 5 5 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
42484+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42485+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42486+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42487+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42488+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42489+4 4 4 4 4 4
42490+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42491+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42492+4 4 4 5 5 5 5 5 5 4 3 3 5 5 5 4 3 3
42493+5 5 5 5 5 5 6 6 6 6 6 6 4 0 0 4 0 0
42494+4 0 0 4 0 0 26 28 28 125 124 125 174 174 174 193 200 203
42495+193 200 203 174 174 174 193 200 203 167 166 167 125 124 125 6 6 6
42496+6 6 6 6 6 6 4 0 0 6 6 6 6 6 6 5 5 5
42497+4 3 3 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
42498+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42499+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42500+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42501+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42502+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42503+4 4 4 4 4 4
42504+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42505+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42506+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
42507+4 3 3 6 6 6 4 0 0 6 6 6 6 6 6 6 6 6
42508+6 6 6 4 0 0 4 0 0 6 6 6 37 38 37 125 124 125
42509+153 152 153 131 129 131 125 124 125 37 38 37 6 6 6 6 6 6
42510+6 6 6 4 0 0 6 6 6 6 6 6 4 3 3 5 5 5
42511+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42512+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42513+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42514+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42515+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42516+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42517+4 4 4 4 4 4
42518+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42519+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42520+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42521+4 4 4 5 5 5 5 5 5 4 3 3 5 5 5 4 3 3
42522+6 6 6 6 6 6 4 0 0 4 0 0 6 6 6 6 6 6
42523+24 26 27 24 26 27 6 6 6 6 6 6 6 6 6 4 0 0
42524+6 6 6 6 6 6 4 0 0 6 6 6 5 5 5 4 3 3
42525+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42526+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42527+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42528+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42529+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42530+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42531+4 4 4 4 4 4
42532+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42533+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42534+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42535+4 4 4 4 4 4 5 5 5 4 3 3 5 5 5 6 6 6
42536+4 0 0 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6
42537+6 6 6 6 6 6 6 6 6 4 0 0 6 6 6 6 6 6
42538+4 0 0 6 6 6 6 6 6 4 3 3 5 5 5 4 4 4
42539+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42540+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42541+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42542+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42543+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42544+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42545+4 4 4 4 4 4
42546+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42547+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42548+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42549+4 4 4 4 4 4 4 4 4 5 5 5 4 3 3 5 5 5
42550+5 5 5 5 5 5 4 0 0 6 6 6 4 0 0 6 6 6
42551+6 6 6 6 6 6 6 6 6 4 0 0 6 6 6 4 0 0
42552+6 6 6 4 3 3 5 5 5 4 3 3 5 5 5 4 4 4
42553+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42554+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42555+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42556+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42557+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42558+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42559+4 4 4 4 4 4
42560+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42561+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42562+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42563+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
42564+4 3 3 6 6 6 4 3 3 6 6 6 6 6 6 6 6 6
42565+4 0 0 6 6 6 4 0 0 6 6 6 6 6 6 6 6 6
42566+6 6 6 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
42567+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42568+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42569+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42570+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42571+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42572+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42573+4 4 4 4 4 4
42574+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42575+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42576+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42577+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42578+4 4 4 5 5 5 4 3 3 5 5 5 4 0 0 6 6 6
42579+6 6 6 4 0 0 6 6 6 6 6 6 4 0 0 6 6 6
42580+4 3 3 5 5 5 5 5 5 4 4 4 4 4 4 4 4 4
42581+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42582+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42583+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42584+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42585+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42586+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42587+4 4 4 4 4 4
42588+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42589+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42590+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42591+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42592+4 4 4 5 5 5 4 3 3 5 5 5 6 6 6 4 3 3
42593+4 3 3 6 6 6 6 6 6 4 3 3 6 6 6 4 3 3
42594+5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42595+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42596+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42597+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42598+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42599+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42600+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42601+4 4 4 4 4 4
42602+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42603+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42604+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42605+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42606+4 4 4 4 4 4 4 4 4 5 5 5 4 3 3 6 6 6
42607+5 5 5 4 3 3 4 3 3 4 3 3 5 5 5 5 5 5
42608+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42609+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42610+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42611+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42612+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42613+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42614+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42615+4 4 4 4 4 4
42616+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42617+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42618+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42619+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42620+4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 4 3 3
42621+5 5 5 4 3 3 5 5 5 5 5 5 4 4 4 4 4 4
42622+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42623+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42624+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42625+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42626+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42627+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42628+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42629+4 4 4 4 4 4
42630diff --git a/drivers/video/udlfb.c b/drivers/video/udlfb.c
42631index 38fcfff..0072dcd 100644
42632--- a/drivers/video/udlfb.c
42633+++ b/drivers/video/udlfb.c
42634@@ -620,11 +620,11 @@ int dlfb_handle_damage(struct dlfb_data *dev, int x, int y,
42635 dlfb_urb_completion(urb);
42636
42637 error:
42638- atomic_add(bytes_sent, &dev->bytes_sent);
42639- atomic_add(bytes_identical, &dev->bytes_identical);
42640- atomic_add(width*height*2, &dev->bytes_rendered);
42641+ atomic_add_unchecked(bytes_sent, &dev->bytes_sent);
42642+ atomic_add_unchecked(bytes_identical, &dev->bytes_identical);
42643+ atomic_add_unchecked(width*height*2, &dev->bytes_rendered);
42644 end_cycles = get_cycles();
42645- atomic_add(((unsigned int) ((end_cycles - start_cycles)
42646+ atomic_add_unchecked(((unsigned int) ((end_cycles - start_cycles)
42647 >> 10)), /* Kcycles */
42648 &dev->cpu_kcycles_used);
42649
42650@@ -745,11 +745,11 @@ static void dlfb_dpy_deferred_io(struct fb_info *info,
42651 dlfb_urb_completion(urb);
42652
42653 error:
42654- atomic_add(bytes_sent, &dev->bytes_sent);
42655- atomic_add(bytes_identical, &dev->bytes_identical);
42656- atomic_add(bytes_rendered, &dev->bytes_rendered);
42657+ atomic_add_unchecked(bytes_sent, &dev->bytes_sent);
42658+ atomic_add_unchecked(bytes_identical, &dev->bytes_identical);
42659+ atomic_add_unchecked(bytes_rendered, &dev->bytes_rendered);
42660 end_cycles = get_cycles();
42661- atomic_add(((unsigned int) ((end_cycles - start_cycles)
42662+ atomic_add_unchecked(((unsigned int) ((end_cycles - start_cycles)
42663 >> 10)), /* Kcycles */
42664 &dev->cpu_kcycles_used);
42665 }
42666@@ -1373,7 +1373,7 @@ static ssize_t metrics_bytes_rendered_show(struct device *fbdev,
42667 struct fb_info *fb_info = dev_get_drvdata(fbdev);
42668 struct dlfb_data *dev = fb_info->par;
42669 return snprintf(buf, PAGE_SIZE, "%u\n",
42670- atomic_read(&dev->bytes_rendered));
42671+ atomic_read_unchecked(&dev->bytes_rendered));
42672 }
42673
42674 static ssize_t metrics_bytes_identical_show(struct device *fbdev,
42675@@ -1381,7 +1381,7 @@ static ssize_t metrics_bytes_identical_show(struct device *fbdev,
42676 struct fb_info *fb_info = dev_get_drvdata(fbdev);
42677 struct dlfb_data *dev = fb_info->par;
42678 return snprintf(buf, PAGE_SIZE, "%u\n",
42679- atomic_read(&dev->bytes_identical));
42680+ atomic_read_unchecked(&dev->bytes_identical));
42681 }
42682
42683 static ssize_t metrics_bytes_sent_show(struct device *fbdev,
42684@@ -1389,7 +1389,7 @@ static ssize_t metrics_bytes_sent_show(struct device *fbdev,
42685 struct fb_info *fb_info = dev_get_drvdata(fbdev);
42686 struct dlfb_data *dev = fb_info->par;
42687 return snprintf(buf, PAGE_SIZE, "%u\n",
42688- atomic_read(&dev->bytes_sent));
42689+ atomic_read_unchecked(&dev->bytes_sent));
42690 }
42691
42692 static ssize_t metrics_cpu_kcycles_used_show(struct device *fbdev,
42693@@ -1397,7 +1397,7 @@ static ssize_t metrics_cpu_kcycles_used_show(struct device *fbdev,
42694 struct fb_info *fb_info = dev_get_drvdata(fbdev);
42695 struct dlfb_data *dev = fb_info->par;
42696 return snprintf(buf, PAGE_SIZE, "%u\n",
42697- atomic_read(&dev->cpu_kcycles_used));
42698+ atomic_read_unchecked(&dev->cpu_kcycles_used));
42699 }
42700
42701 static ssize_t edid_show(
42702@@ -1457,10 +1457,10 @@ static ssize_t metrics_reset_store(struct device *fbdev,
42703 struct fb_info *fb_info = dev_get_drvdata(fbdev);
42704 struct dlfb_data *dev = fb_info->par;
42705
42706- atomic_set(&dev->bytes_rendered, 0);
42707- atomic_set(&dev->bytes_identical, 0);
42708- atomic_set(&dev->bytes_sent, 0);
42709- atomic_set(&dev->cpu_kcycles_used, 0);
42710+ atomic_set_unchecked(&dev->bytes_rendered, 0);
42711+ atomic_set_unchecked(&dev->bytes_identical, 0);
42712+ atomic_set_unchecked(&dev->bytes_sent, 0);
42713+ atomic_set_unchecked(&dev->cpu_kcycles_used, 0);
42714
42715 return count;
42716 }
42717diff --git a/drivers/video/uvesafb.c b/drivers/video/uvesafb.c
42718index b0e2a42..e2df3ad 100644
42719--- a/drivers/video/uvesafb.c
42720+++ b/drivers/video/uvesafb.c
42721@@ -19,6 +19,7 @@
42722 #include <linux/io.h>
42723 #include <linux/mutex.h>
42724 #include <linux/slab.h>
42725+#include <linux/moduleloader.h>
42726 #include <video/edid.h>
42727 #include <video/uvesafb.h>
42728 #ifdef CONFIG_X86
42729@@ -569,10 +570,32 @@ static int __devinit uvesafb_vbe_getpmi(struct uvesafb_ktask *task,
42730 if ((task->t.regs.eax & 0xffff) != 0x4f || task->t.regs.es < 0xc000) {
42731 par->pmi_setpal = par->ypan = 0;
42732 } else {
42733+
42734+#ifdef CONFIG_PAX_KERNEXEC
42735+#ifdef CONFIG_MODULES
42736+ par->pmi_code = module_alloc_exec((u16)task->t.regs.ecx);
42737+#endif
42738+ if (!par->pmi_code) {
42739+ par->pmi_setpal = par->ypan = 0;
42740+ return 0;
42741+ }
42742+#endif
42743+
42744 par->pmi_base = (u16 *)phys_to_virt(((u32)task->t.regs.es << 4)
42745 + task->t.regs.edi);
42746+
42747+#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
42748+ pax_open_kernel();
42749+ memcpy(par->pmi_code, par->pmi_base, (u16)task->t.regs.ecx);
42750+ pax_close_kernel();
42751+
42752+ par->pmi_start = ktva_ktla(par->pmi_code + par->pmi_base[1]);
42753+ par->pmi_pal = ktva_ktla(par->pmi_code + par->pmi_base[2]);
42754+#else
42755 par->pmi_start = (u8 *)par->pmi_base + par->pmi_base[1];
42756 par->pmi_pal = (u8 *)par->pmi_base + par->pmi_base[2];
42757+#endif
42758+
42759 printk(KERN_INFO "uvesafb: protected mode interface info at "
42760 "%04x:%04x\n",
42761 (u16)task->t.regs.es, (u16)task->t.regs.edi);
42762@@ -816,13 +839,14 @@ static int __devinit uvesafb_vbe_init(struct fb_info *info)
42763 par->ypan = ypan;
42764
42765 if (par->pmi_setpal || par->ypan) {
42766+#if !defined(CONFIG_MODULES) || !defined(CONFIG_PAX_KERNEXEC)
42767 if (__supported_pte_mask & _PAGE_NX) {
42768 par->pmi_setpal = par->ypan = 0;
42769 printk(KERN_WARNING "uvesafb: NX protection is actively."
42770 "We have better not to use the PMI.\n");
42771- } else {
42772+ } else
42773+#endif
42774 uvesafb_vbe_getpmi(task, par);
42775- }
42776 }
42777 #else
42778 /* The protected mode interface is not available on non-x86. */
42779@@ -1836,6 +1860,11 @@ out:
42780 if (par->vbe_modes)
42781 kfree(par->vbe_modes);
42782
42783+#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
42784+ if (par->pmi_code)
42785+ module_free_exec(NULL, par->pmi_code);
42786+#endif
42787+
42788 framebuffer_release(info);
42789 return err;
42790 }
42791@@ -1862,6 +1891,12 @@ static int uvesafb_remove(struct platform_device *dev)
42792 kfree(par->vbe_state_orig);
42793 if (par->vbe_state_saved)
42794 kfree(par->vbe_state_saved);
42795+
42796+#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
42797+ if (par->pmi_code)
42798+ module_free_exec(NULL, par->pmi_code);
42799+#endif
42800+
42801 }
42802
42803 framebuffer_release(info);
42804diff --git a/drivers/video/vesafb.c b/drivers/video/vesafb.c
42805index 501b340..86bd4cf 100644
42806--- a/drivers/video/vesafb.c
42807+++ b/drivers/video/vesafb.c
42808@@ -9,6 +9,7 @@
42809 */
42810
42811 #include <linux/module.h>
42812+#include <linux/moduleloader.h>
42813 #include <linux/kernel.h>
42814 #include <linux/errno.h>
42815 #include <linux/string.h>
42816@@ -52,8 +53,8 @@ static int vram_remap __initdata; /* Set amount of memory to be used */
42817 static int vram_total __initdata; /* Set total amount of memory */
42818 static int pmi_setpal __read_mostly = 1; /* pmi for palette changes ??? */
42819 static int ypan __read_mostly; /* 0..nothing, 1..ypan, 2..ywrap */
42820-static void (*pmi_start)(void) __read_mostly;
42821-static void (*pmi_pal) (void) __read_mostly;
42822+static void (*pmi_start)(void) __read_only;
42823+static void (*pmi_pal) (void) __read_only;
42824 static int depth __read_mostly;
42825 static int vga_compat __read_mostly;
42826 /* --------------------------------------------------------------------- */
42827@@ -233,6 +234,7 @@ static int __init vesafb_probe(struct platform_device *dev)
42828 unsigned int size_vmode;
42829 unsigned int size_remap;
42830 unsigned int size_total;
42831+ void *pmi_code = NULL;
42832
42833 if (screen_info.orig_video_isVGA != VIDEO_TYPE_VLFB)
42834 return -ENODEV;
42835@@ -275,10 +277,6 @@ static int __init vesafb_probe(struct platform_device *dev)
42836 size_remap = size_total;
42837 vesafb_fix.smem_len = size_remap;
42838
42839-#ifndef __i386__
42840- screen_info.vesapm_seg = 0;
42841-#endif
42842-
42843 if (!request_mem_region(vesafb_fix.smem_start, size_total, "vesafb")) {
42844 printk(KERN_WARNING
42845 "vesafb: cannot reserve video memory at 0x%lx\n",
42846@@ -307,9 +305,21 @@ static int __init vesafb_probe(struct platform_device *dev)
42847 printk(KERN_INFO "vesafb: mode is %dx%dx%d, linelength=%d, pages=%d\n",
42848 vesafb_defined.xres, vesafb_defined.yres, vesafb_defined.bits_per_pixel, vesafb_fix.line_length, screen_info.pages);
42849
42850+#ifdef __i386__
42851+
42852+#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
42853+ pmi_code = module_alloc_exec(screen_info.vesapm_size);
42854+ if (!pmi_code)
42855+#elif !defined(CONFIG_PAX_KERNEXEC)
42856+ if (0)
42857+#endif
42858+
42859+#endif
42860+ screen_info.vesapm_seg = 0;
42861+
42862 if (screen_info.vesapm_seg) {
42863- printk(KERN_INFO "vesafb: protected mode interface info at %04x:%04x\n",
42864- screen_info.vesapm_seg,screen_info.vesapm_off);
42865+ printk(KERN_INFO "vesafb: protected mode interface info at %04x:%04x %04x bytes\n",
42866+ screen_info.vesapm_seg,screen_info.vesapm_off,screen_info.vesapm_size);
42867 }
42868
42869 if (screen_info.vesapm_seg < 0xc000)
42870@@ -317,9 +327,25 @@ static int __init vesafb_probe(struct platform_device *dev)
42871
42872 if (ypan || pmi_setpal) {
42873 unsigned short *pmi_base;
42874+
42875 pmi_base = (unsigned short*)phys_to_virt(((unsigned long)screen_info.vesapm_seg << 4) + screen_info.vesapm_off);
42876- pmi_start = (void*)((char*)pmi_base + pmi_base[1]);
42877- pmi_pal = (void*)((char*)pmi_base + pmi_base[2]);
42878+
42879+#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
42880+ pax_open_kernel();
42881+ memcpy(pmi_code, pmi_base, screen_info.vesapm_size);
42882+#else
42883+ pmi_code = pmi_base;
42884+#endif
42885+
42886+ pmi_start = (void*)((char*)pmi_code + pmi_base[1]);
42887+ pmi_pal = (void*)((char*)pmi_code + pmi_base[2]);
42888+
42889+#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
42890+ pmi_start = ktva_ktla(pmi_start);
42891+ pmi_pal = ktva_ktla(pmi_pal);
42892+ pax_close_kernel();
42893+#endif
42894+
42895 printk(KERN_INFO "vesafb: pmi: set display start = %p, set palette = %p\n",pmi_start,pmi_pal);
42896 if (pmi_base[3]) {
42897 printk(KERN_INFO "vesafb: pmi: ports = ");
42898@@ -488,6 +514,11 @@ static int __init vesafb_probe(struct platform_device *dev)
42899 info->node, info->fix.id);
42900 return 0;
42901 err:
42902+
42903+#if defined(__i386__) && defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
42904+ module_free_exec(NULL, pmi_code);
42905+#endif
42906+
42907 if (info->screen_base)
42908 iounmap(info->screen_base);
42909 framebuffer_release(info);
42910diff --git a/drivers/video/via/via_clock.h b/drivers/video/via/via_clock.h
42911index 88714ae..16c2e11 100644
42912--- a/drivers/video/via/via_clock.h
42913+++ b/drivers/video/via/via_clock.h
42914@@ -56,7 +56,7 @@ struct via_clock {
42915
42916 void (*set_engine_pll_state)(u8 state);
42917 void (*set_engine_pll)(struct via_pll_config config);
42918-};
42919+} __no_const;
42920
42921
42922 static inline u32 get_pll_internal_frequency(u32 ref_freq,
42923diff --git a/drivers/virtio/virtio_mmio.c b/drivers/virtio/virtio_mmio.c
42924index 453db0c..604973e 100644
42925--- a/drivers/virtio/virtio_mmio.c
42926+++ b/drivers/virtio/virtio_mmio.c
42927@@ -521,7 +521,7 @@ static int vm_cmdline_set(const char *device,
42928
42929 resources[0].end = memparse(device, &str) - 1;
42930
42931- processed = sscanf(str, "@%lli:%u%n:%d%n",
42932+ processed = sscanf(str, "@%lli:%llu%n:%d%n",
42933 &base, &resources[1].start, &consumed,
42934 &vm_cmdline_id, &consumed);
42935
42936diff --git a/drivers/xen/xen-pciback/conf_space.h b/drivers/xen/xen-pciback/conf_space.h
42937index e56c934..fc22f4b 100644
42938--- a/drivers/xen/xen-pciback/conf_space.h
42939+++ b/drivers/xen/xen-pciback/conf_space.h
42940@@ -44,15 +44,15 @@ struct config_field {
42941 struct {
42942 conf_dword_write write;
42943 conf_dword_read read;
42944- } dw;
42945+ } __no_const dw;
42946 struct {
42947 conf_word_write write;
42948 conf_word_read read;
42949- } w;
42950+ } __no_const w;
42951 struct {
42952 conf_byte_write write;
42953 conf_byte_read read;
42954- } b;
42955+ } __no_const b;
42956 } u;
42957 struct list_head list;
42958 };
42959diff --git a/drivers/xen/xenbus/xenbus_dev_frontend.c b/drivers/xen/xenbus/xenbus_dev_frontend.c
42960index 89f7625..ac72702 100644
42961--- a/drivers/xen/xenbus/xenbus_dev_frontend.c
42962+++ b/drivers/xen/xenbus/xenbus_dev_frontend.c
42963@@ -458,7 +458,7 @@ static ssize_t xenbus_file_write(struct file *filp,
42964 goto out;
42965
42966 /* Can't write a xenbus message larger we can buffer */
42967- if ((len + u->len) > sizeof(u->u.buffer)) {
42968+ if (len > sizeof(u->u.buffer) - u->len) {
42969 /* On error, dump existing buffer */
42970 u->len = 0;
42971 rc = -EINVAL;
42972diff --git a/drivers/xen/xenfs/xenstored.c b/drivers/xen/xenfs/xenstored.c
42973index fef20db..d28b1ab 100644
42974--- a/drivers/xen/xenfs/xenstored.c
42975+++ b/drivers/xen/xenfs/xenstored.c
42976@@ -24,7 +24,12 @@ static int xsd_release(struct inode *inode, struct file *file)
42977 static int xsd_kva_open(struct inode *inode, struct file *file)
42978 {
42979 file->private_data = (void *)kasprintf(GFP_KERNEL, "0x%p",
42980+#ifdef CONFIG_GRKERNSEC_HIDESYM
42981+ NULL);
42982+#else
42983 xen_store_interface);
42984+#endif
42985+
42986 if (!file->private_data)
42987 return -ENOMEM;
42988 return 0;
42989diff --git a/fs/9p/vfs_inode.c b/fs/9p/vfs_inode.c
42990index cbf9dbb..35c3af7 100644
42991--- a/fs/9p/vfs_inode.c
42992+++ b/fs/9p/vfs_inode.c
42993@@ -1329,7 +1329,7 @@ static void *v9fs_vfs_follow_link(struct dentry *dentry, struct nameidata *nd)
42994 void
42995 v9fs_vfs_put_link(struct dentry *dentry, struct nameidata *nd, void *p)
42996 {
42997- char *s = nd_get_link(nd);
42998+ const char *s = nd_get_link(nd);
42999
43000 p9_debug(P9_DEBUG_VFS, " %s %s\n",
43001 dentry->d_name.name, IS_ERR(s) ? "<error>" : s);
43002diff --git a/fs/Kconfig.binfmt b/fs/Kconfig.binfmt
43003index 0225742..1cd4732 100644
43004--- a/fs/Kconfig.binfmt
43005+++ b/fs/Kconfig.binfmt
43006@@ -89,7 +89,7 @@ config HAVE_AOUT
43007
43008 config BINFMT_AOUT
43009 tristate "Kernel support for a.out and ECOFF binaries"
43010- depends on HAVE_AOUT
43011+ depends on HAVE_AOUT && BROKEN
43012 ---help---
43013 A.out (Assembler.OUTput) is a set of formats for libraries and
43014 executables used in the earliest versions of UNIX. Linux used
43015diff --git a/fs/aio.c b/fs/aio.c
43016index 71f613c..9d01f1f 100644
43017--- a/fs/aio.c
43018+++ b/fs/aio.c
43019@@ -111,7 +111,7 @@ static int aio_setup_ring(struct kioctx *ctx)
43020 size += sizeof(struct io_event) * nr_events;
43021 nr_pages = (size + PAGE_SIZE-1) >> PAGE_SHIFT;
43022
43023- if (nr_pages < 0)
43024+ if (nr_pages <= 0)
43025 return -EINVAL;
43026
43027 nr_events = (PAGE_SIZE * nr_pages - sizeof(struct aio_ring)) / sizeof(struct io_event);
43028@@ -1373,18 +1373,19 @@ static ssize_t aio_fsync(struct kiocb *iocb)
43029 static ssize_t aio_setup_vectored_rw(int type, struct kiocb *kiocb, bool compat)
43030 {
43031 ssize_t ret;
43032+ struct iovec iovstack;
43033
43034 #ifdef CONFIG_COMPAT
43035 if (compat)
43036 ret = compat_rw_copy_check_uvector(type,
43037 (struct compat_iovec __user *)kiocb->ki_buf,
43038- kiocb->ki_nbytes, 1, &kiocb->ki_inline_vec,
43039+ kiocb->ki_nbytes, 1, &iovstack,
43040 &kiocb->ki_iovec);
43041 else
43042 #endif
43043 ret = rw_copy_check_uvector(type,
43044 (struct iovec __user *)kiocb->ki_buf,
43045- kiocb->ki_nbytes, 1, &kiocb->ki_inline_vec,
43046+ kiocb->ki_nbytes, 1, &iovstack,
43047 &kiocb->ki_iovec);
43048 if (ret < 0)
43049 goto out;
43050@@ -1393,6 +1394,10 @@ static ssize_t aio_setup_vectored_rw(int type, struct kiocb *kiocb, bool compat)
43051 if (ret < 0)
43052 goto out;
43053
43054+ if (kiocb->ki_iovec == &iovstack) {
43055+ kiocb->ki_inline_vec = iovstack;
43056+ kiocb->ki_iovec = &kiocb->ki_inline_vec;
43057+ }
43058 kiocb->ki_nr_segs = kiocb->ki_nbytes;
43059 kiocb->ki_cur_seg = 0;
43060 /* ki_nbytes/left now reflect bytes instead of segs */
43061diff --git a/fs/attr.c b/fs/attr.c
43062index 29e38a1..2bc037b 100644
43063--- a/fs/attr.c
43064+++ b/fs/attr.c
43065@@ -99,6 +99,7 @@ int inode_newsize_ok(const struct inode *inode, loff_t offset)
43066 unsigned long limit;
43067
43068 limit = rlimit(RLIMIT_FSIZE);
43069+ gr_learn_resource(current, RLIMIT_FSIZE, (unsigned long)offset, 1);
43070 if (limit != RLIM_INFINITY && offset > limit)
43071 goto out_sig;
43072 if (offset > inode->i_sb->s_maxbytes)
43073diff --git a/fs/autofs4/waitq.c b/fs/autofs4/waitq.c
43074index da8876d..4456166 100644
43075--- a/fs/autofs4/waitq.c
43076+++ b/fs/autofs4/waitq.c
43077@@ -61,7 +61,7 @@ static int autofs4_write(struct autofs_sb_info *sbi,
43078 {
43079 unsigned long sigpipe, flags;
43080 mm_segment_t fs;
43081- const char *data = (const char *)addr;
43082+ const char __user *data = (const char __force_user *)addr;
43083 ssize_t wr = 0;
43084
43085 sigpipe = sigismember(&current->pending.signal, SIGPIPE);
43086@@ -348,6 +348,10 @@ static int validate_request(struct autofs_wait_queue **wait,
43087 return 1;
43088 }
43089
43090+#ifdef CONFIG_GRKERNSEC_HIDESYM
43091+static atomic_unchecked_t autofs_dummy_name_id = ATOMIC_INIT(0);
43092+#endif
43093+
43094 int autofs4_wait(struct autofs_sb_info *sbi, struct dentry *dentry,
43095 enum autofs_notify notify)
43096 {
43097@@ -381,7 +385,12 @@ int autofs4_wait(struct autofs_sb_info *sbi, struct dentry *dentry,
43098
43099 /* If this is a direct mount request create a dummy name */
43100 if (IS_ROOT(dentry) && autofs_type_trigger(sbi->type))
43101+#ifdef CONFIG_GRKERNSEC_HIDESYM
43102+ /* this name does get written to userland via autofs4_write() */
43103+ qstr.len = sprintf(name, "%08lx", atomic_inc_return_unchecked(&autofs_dummy_name_id));
43104+#else
43105 qstr.len = sprintf(name, "%p", dentry);
43106+#endif
43107 else {
43108 qstr.len = autofs4_getpath(sbi, dentry, &name);
43109 if (!qstr.len) {
43110diff --git a/fs/befs/linuxvfs.c b/fs/befs/linuxvfs.c
43111index cf7f3c6..f61080d 100644
43112--- a/fs/befs/linuxvfs.c
43113+++ b/fs/befs/linuxvfs.c
43114@@ -502,7 +502,7 @@ static void befs_put_link(struct dentry *dentry, struct nameidata *nd, void *p)
43115 {
43116 befs_inode_info *befs_ino = BEFS_I(dentry->d_inode);
43117 if (befs_ino->i_flags & BEFS_LONG_SYMLINK) {
43118- char *link = nd_get_link(nd);
43119+ const char *link = nd_get_link(nd);
43120 if (!IS_ERR(link))
43121 kfree(link);
43122 }
43123diff --git a/fs/binfmt_aout.c b/fs/binfmt_aout.c
43124index d146e18..12d1bd1 100644
43125--- a/fs/binfmt_aout.c
43126+++ b/fs/binfmt_aout.c
43127@@ -16,6 +16,7 @@
43128 #include <linux/string.h>
43129 #include <linux/fs.h>
43130 #include <linux/file.h>
43131+#include <linux/security.h>
43132 #include <linux/stat.h>
43133 #include <linux/fcntl.h>
43134 #include <linux/ptrace.h>
43135@@ -83,6 +84,8 @@ static int aout_core_dump(struct coredump_params *cprm)
43136 #endif
43137 # define START_STACK(u) ((void __user *)u.start_stack)
43138
43139+ memset(&dump, 0, sizeof(dump));
43140+
43141 fs = get_fs();
43142 set_fs(KERNEL_DS);
43143 has_dumped = 1;
43144@@ -94,10 +97,12 @@ static int aout_core_dump(struct coredump_params *cprm)
43145
43146 /* If the size of the dump file exceeds the rlimit, then see what would happen
43147 if we wrote the stack, but not the data area. */
43148+ gr_learn_resource(current, RLIMIT_CORE, (dump.u_dsize + dump.u_ssize+1) * PAGE_SIZE, 1);
43149 if ((dump.u_dsize + dump.u_ssize+1) * PAGE_SIZE > cprm->limit)
43150 dump.u_dsize = 0;
43151
43152 /* Make sure we have enough room to write the stack and data areas. */
43153+ gr_learn_resource(current, RLIMIT_CORE, (dump.u_ssize + 1) * PAGE_SIZE, 1);
43154 if ((dump.u_ssize + 1) * PAGE_SIZE > cprm->limit)
43155 dump.u_ssize = 0;
43156
43157@@ -231,6 +236,8 @@ static int load_aout_binary(struct linux_binprm * bprm, struct pt_regs * regs)
43158 rlim = rlimit(RLIMIT_DATA);
43159 if (rlim >= RLIM_INFINITY)
43160 rlim = ~0;
43161+
43162+ gr_learn_resource(current, RLIMIT_DATA, ex.a_data + ex.a_bss, 1);
43163 if (ex.a_data + ex.a_bss > rlim)
43164 return -ENOMEM;
43165
43166@@ -265,6 +272,27 @@ static int load_aout_binary(struct linux_binprm * bprm, struct pt_regs * regs)
43167
43168 install_exec_creds(bprm);
43169
43170+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
43171+ current->mm->pax_flags = 0UL;
43172+#endif
43173+
43174+#ifdef CONFIG_PAX_PAGEEXEC
43175+ if (!(N_FLAGS(ex) & F_PAX_PAGEEXEC)) {
43176+ current->mm->pax_flags |= MF_PAX_PAGEEXEC;
43177+
43178+#ifdef CONFIG_PAX_EMUTRAMP
43179+ if (N_FLAGS(ex) & F_PAX_EMUTRAMP)
43180+ current->mm->pax_flags |= MF_PAX_EMUTRAMP;
43181+#endif
43182+
43183+#ifdef CONFIG_PAX_MPROTECT
43184+ if (!(N_FLAGS(ex) & F_PAX_MPROTECT))
43185+ current->mm->pax_flags |= MF_PAX_MPROTECT;
43186+#endif
43187+
43188+ }
43189+#endif
43190+
43191 if (N_MAGIC(ex) == OMAGIC) {
43192 unsigned long text_addr, map_size;
43193 loff_t pos;
43194@@ -330,7 +358,7 @@ static int load_aout_binary(struct linux_binprm * bprm, struct pt_regs * regs)
43195 }
43196
43197 error = vm_mmap(bprm->file, N_DATADDR(ex), ex.a_data,
43198- PROT_READ | PROT_WRITE | PROT_EXEC,
43199+ PROT_READ | PROT_WRITE,
43200 MAP_FIXED | MAP_PRIVATE | MAP_DENYWRITE | MAP_EXECUTABLE,
43201 fd_offset + ex.a_text);
43202 if (error != N_DATADDR(ex)) {
43203diff --git a/fs/binfmt_elf.c b/fs/binfmt_elf.c
43204index 0225fdd..0c0d35d 100644
43205--- a/fs/binfmt_elf.c
43206+++ b/fs/binfmt_elf.c
43207@@ -32,6 +32,7 @@
43208 #include <linux/elf.h>
43209 #include <linux/utsname.h>
43210 #include <linux/coredump.h>
43211+#include <linux/xattr.h>
43212 #include <asm/uaccess.h>
43213 #include <asm/param.h>
43214 #include <asm/page.h>
43215@@ -52,6 +53,10 @@ static int elf_core_dump(struct coredump_params *cprm);
43216 #define elf_core_dump NULL
43217 #endif
43218
43219+#ifdef CONFIG_PAX_MPROTECT
43220+static void elf_handle_mprotect(struct vm_area_struct *vma, unsigned long newflags);
43221+#endif
43222+
43223 #if ELF_EXEC_PAGESIZE > PAGE_SIZE
43224 #define ELF_MIN_ALIGN ELF_EXEC_PAGESIZE
43225 #else
43226@@ -71,6 +76,11 @@ static struct linux_binfmt elf_format = {
43227 .load_binary = load_elf_binary,
43228 .load_shlib = load_elf_library,
43229 .core_dump = elf_core_dump,
43230+
43231+#ifdef CONFIG_PAX_MPROTECT
43232+ .handle_mprotect= elf_handle_mprotect,
43233+#endif
43234+
43235 .min_coredump = ELF_EXEC_PAGESIZE,
43236 };
43237
43238@@ -78,6 +88,8 @@ static struct linux_binfmt elf_format = {
43239
43240 static int set_brk(unsigned long start, unsigned long end)
43241 {
43242+ unsigned long e = end;
43243+
43244 start = ELF_PAGEALIGN(start);
43245 end = ELF_PAGEALIGN(end);
43246 if (end > start) {
43247@@ -86,7 +98,7 @@ static int set_brk(unsigned long start, unsigned long end)
43248 if (BAD_ADDR(addr))
43249 return addr;
43250 }
43251- current->mm->start_brk = current->mm->brk = end;
43252+ current->mm->start_brk = current->mm->brk = e;
43253 return 0;
43254 }
43255
43256@@ -147,12 +159,13 @@ create_elf_tables(struct linux_binprm *bprm, struct elfhdr *exec,
43257 elf_addr_t __user *u_rand_bytes;
43258 const char *k_platform = ELF_PLATFORM;
43259 const char *k_base_platform = ELF_BASE_PLATFORM;
43260- unsigned char k_rand_bytes[16];
43261+ u32 k_rand_bytes[4];
43262 int items;
43263 elf_addr_t *elf_info;
43264 int ei_index = 0;
43265 const struct cred *cred = current_cred();
43266 struct vm_area_struct *vma;
43267+ unsigned long saved_auxv[AT_VECTOR_SIZE];
43268
43269 /*
43270 * In some cases (e.g. Hyper-Threading), we want to avoid L1
43271@@ -194,8 +207,12 @@ create_elf_tables(struct linux_binprm *bprm, struct elfhdr *exec,
43272 * Generate 16 random bytes for userspace PRNG seeding.
43273 */
43274 get_random_bytes(k_rand_bytes, sizeof(k_rand_bytes));
43275- u_rand_bytes = (elf_addr_t __user *)
43276- STACK_ALLOC(p, sizeof(k_rand_bytes));
43277+ srandom32(k_rand_bytes[0] ^ random32());
43278+ srandom32(k_rand_bytes[1] ^ random32());
43279+ srandom32(k_rand_bytes[2] ^ random32());
43280+ srandom32(k_rand_bytes[3] ^ random32());
43281+ p = STACK_ROUND(p, sizeof(k_rand_bytes));
43282+ u_rand_bytes = (elf_addr_t __user *) p;
43283 if (__copy_to_user(u_rand_bytes, k_rand_bytes, sizeof(k_rand_bytes)))
43284 return -EFAULT;
43285
43286@@ -307,9 +324,11 @@ create_elf_tables(struct linux_binprm *bprm, struct elfhdr *exec,
43287 return -EFAULT;
43288 current->mm->env_end = p;
43289
43290+ memcpy(saved_auxv, elf_info, ei_index * sizeof(elf_addr_t));
43291+
43292 /* Put the elf_info on the stack in the right place. */
43293 sp = (elf_addr_t __user *)envp + 1;
43294- if (copy_to_user(sp, elf_info, ei_index * sizeof(elf_addr_t)))
43295+ if (copy_to_user(sp, saved_auxv, ei_index * sizeof(elf_addr_t)))
43296 return -EFAULT;
43297 return 0;
43298 }
43299@@ -373,15 +392,14 @@ static unsigned long total_mapping_size(struct elf_phdr *cmds, int nr)
43300 an ELF header */
43301
43302 static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
43303- struct file *interpreter, unsigned long *interp_map_addr,
43304- unsigned long no_base)
43305+ struct file *interpreter, unsigned long no_base)
43306 {
43307 struct elf_phdr *elf_phdata;
43308 struct elf_phdr *eppnt;
43309- unsigned long load_addr = 0;
43310+ unsigned long load_addr = 0, pax_task_size = TASK_SIZE;
43311 int load_addr_set = 0;
43312 unsigned long last_bss = 0, elf_bss = 0;
43313- unsigned long error = ~0UL;
43314+ unsigned long error = -EINVAL;
43315 unsigned long total_size;
43316 int retval, i, size;
43317
43318@@ -427,6 +445,11 @@ static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
43319 goto out_close;
43320 }
43321
43322+#ifdef CONFIG_PAX_SEGMEXEC
43323+ if (current->mm->pax_flags & MF_PAX_SEGMEXEC)
43324+ pax_task_size = SEGMEXEC_TASK_SIZE;
43325+#endif
43326+
43327 eppnt = elf_phdata;
43328 for (i = 0; i < interp_elf_ex->e_phnum; i++, eppnt++) {
43329 if (eppnt->p_type == PT_LOAD) {
43330@@ -450,8 +473,6 @@ static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
43331 map_addr = elf_map(interpreter, load_addr + vaddr,
43332 eppnt, elf_prot, elf_type, total_size);
43333 total_size = 0;
43334- if (!*interp_map_addr)
43335- *interp_map_addr = map_addr;
43336 error = map_addr;
43337 if (BAD_ADDR(map_addr))
43338 goto out_close;
43339@@ -470,8 +491,8 @@ static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
43340 k = load_addr + eppnt->p_vaddr;
43341 if (BAD_ADDR(k) ||
43342 eppnt->p_filesz > eppnt->p_memsz ||
43343- eppnt->p_memsz > TASK_SIZE ||
43344- TASK_SIZE - eppnt->p_memsz < k) {
43345+ eppnt->p_memsz > pax_task_size ||
43346+ pax_task_size - eppnt->p_memsz < k) {
43347 error = -ENOMEM;
43348 goto out_close;
43349 }
43350@@ -523,6 +544,315 @@ out:
43351 return error;
43352 }
43353
43354+#ifdef CONFIG_PAX_PT_PAX_FLAGS
43355+#ifdef CONFIG_PAX_SOFTMODE
43356+static unsigned long pax_parse_pt_pax_softmode(const struct elf_phdr * const elf_phdata)
43357+{
43358+ unsigned long pax_flags = 0UL;
43359+
43360+#ifdef CONFIG_PAX_PAGEEXEC
43361+ if (elf_phdata->p_flags & PF_PAGEEXEC)
43362+ pax_flags |= MF_PAX_PAGEEXEC;
43363+#endif
43364+
43365+#ifdef CONFIG_PAX_SEGMEXEC
43366+ if (elf_phdata->p_flags & PF_SEGMEXEC)
43367+ pax_flags |= MF_PAX_SEGMEXEC;
43368+#endif
43369+
43370+#ifdef CONFIG_PAX_EMUTRAMP
43371+ if ((elf_phdata->p_flags & PF_EMUTRAMP) && (pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)))
43372+ pax_flags |= MF_PAX_EMUTRAMP;
43373+#endif
43374+
43375+#ifdef CONFIG_PAX_MPROTECT
43376+ if (elf_phdata->p_flags & PF_MPROTECT)
43377+ pax_flags |= MF_PAX_MPROTECT;
43378+#endif
43379+
43380+#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
43381+ if (randomize_va_space && (elf_phdata->p_flags & PF_RANDMMAP))
43382+ pax_flags |= MF_PAX_RANDMMAP;
43383+#endif
43384+
43385+ return pax_flags;
43386+}
43387+#endif
43388+
43389+static unsigned long pax_parse_pt_pax_hardmode(const struct elf_phdr * const elf_phdata)
43390+{
43391+ unsigned long pax_flags = 0UL;
43392+
43393+#ifdef CONFIG_PAX_PAGEEXEC
43394+ if (!(elf_phdata->p_flags & PF_NOPAGEEXEC))
43395+ pax_flags |= MF_PAX_PAGEEXEC;
43396+#endif
43397+
43398+#ifdef CONFIG_PAX_SEGMEXEC
43399+ if (!(elf_phdata->p_flags & PF_NOSEGMEXEC))
43400+ pax_flags |= MF_PAX_SEGMEXEC;
43401+#endif
43402+
43403+#ifdef CONFIG_PAX_EMUTRAMP
43404+ if (!(elf_phdata->p_flags & PF_NOEMUTRAMP))
43405+ pax_flags |= MF_PAX_EMUTRAMP;
43406+#endif
43407+
43408+#ifdef CONFIG_PAX_MPROTECT
43409+ if (!(elf_phdata->p_flags & PF_NOMPROTECT))
43410+ pax_flags |= MF_PAX_MPROTECT;
43411+#endif
43412+
43413+#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
43414+ if (randomize_va_space && !(elf_phdata->p_flags & PF_NORANDMMAP))
43415+ pax_flags |= MF_PAX_RANDMMAP;
43416+#endif
43417+
43418+ return pax_flags;
43419+}
43420+#endif
43421+
43422+#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
43423+#ifdef CONFIG_PAX_SOFTMODE
43424+static unsigned long pax_parse_xattr_pax_softmode(unsigned long pax_flags_softmode)
43425+{
43426+ unsigned long pax_flags = 0UL;
43427+
43428+#ifdef CONFIG_PAX_PAGEEXEC
43429+ if (pax_flags_softmode & MF_PAX_PAGEEXEC)
43430+ pax_flags |= MF_PAX_PAGEEXEC;
43431+#endif
43432+
43433+#ifdef CONFIG_PAX_SEGMEXEC
43434+ if (pax_flags_softmode & MF_PAX_SEGMEXEC)
43435+ pax_flags |= MF_PAX_SEGMEXEC;
43436+#endif
43437+
43438+#ifdef CONFIG_PAX_EMUTRAMP
43439+ if (pax_flags_softmode & MF_PAX_EMUTRAMP)
43440+ pax_flags |= MF_PAX_EMUTRAMP;
43441+#endif
43442+
43443+#ifdef CONFIG_PAX_MPROTECT
43444+ if (pax_flags_softmode & MF_PAX_MPROTECT)
43445+ pax_flags |= MF_PAX_MPROTECT;
43446+#endif
43447+
43448+#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
43449+ if (randomize_va_space && (pax_flags_softmode & MF_PAX_RANDMMAP))
43450+ pax_flags |= MF_PAX_RANDMMAP;
43451+#endif
43452+
43453+ return pax_flags;
43454+}
43455+#endif
43456+
43457+static unsigned long pax_parse_xattr_pax_hardmode(unsigned long pax_flags_hardmode)
43458+{
43459+ unsigned long pax_flags = 0UL;
43460+
43461+#ifdef CONFIG_PAX_PAGEEXEC
43462+ if (!(pax_flags_hardmode & MF_PAX_PAGEEXEC))
43463+ pax_flags |= MF_PAX_PAGEEXEC;
43464+#endif
43465+
43466+#ifdef CONFIG_PAX_SEGMEXEC
43467+ if (!(pax_flags_hardmode & MF_PAX_SEGMEXEC))
43468+ pax_flags |= MF_PAX_SEGMEXEC;
43469+#endif
43470+
43471+#ifdef CONFIG_PAX_EMUTRAMP
43472+ if (!(pax_flags_hardmode & MF_PAX_EMUTRAMP))
43473+ pax_flags |= MF_PAX_EMUTRAMP;
43474+#endif
43475+
43476+#ifdef CONFIG_PAX_MPROTECT
43477+ if (!(pax_flags_hardmode & MF_PAX_MPROTECT))
43478+ pax_flags |= MF_PAX_MPROTECT;
43479+#endif
43480+
43481+#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
43482+ if (randomize_va_space && !(pax_flags_hardmode & MF_PAX_RANDMMAP))
43483+ pax_flags |= MF_PAX_RANDMMAP;
43484+#endif
43485+
43486+ return pax_flags;
43487+}
43488+#endif
43489+
43490+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
43491+static unsigned long pax_parse_ei_pax(const struct elfhdr * const elf_ex)
43492+{
43493+ unsigned long pax_flags = 0UL;
43494+
43495+#ifdef CONFIG_PAX_EI_PAX
43496+
43497+#ifdef CONFIG_PAX_PAGEEXEC
43498+ if (!(elf_ex->e_ident[EI_PAX] & EF_PAX_PAGEEXEC))
43499+ pax_flags |= MF_PAX_PAGEEXEC;
43500+#endif
43501+
43502+#ifdef CONFIG_PAX_SEGMEXEC
43503+ if (!(elf_ex->e_ident[EI_PAX] & EF_PAX_SEGMEXEC))
43504+ pax_flags |= MF_PAX_SEGMEXEC;
43505+#endif
43506+
43507+#ifdef CONFIG_PAX_EMUTRAMP
43508+ if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) && (elf_ex->e_ident[EI_PAX] & EF_PAX_EMUTRAMP))
43509+ pax_flags |= MF_PAX_EMUTRAMP;
43510+#endif
43511+
43512+#ifdef CONFIG_PAX_MPROTECT
43513+ if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) && !(elf_ex->e_ident[EI_PAX] & EF_PAX_MPROTECT))
43514+ pax_flags |= MF_PAX_MPROTECT;
43515+#endif
43516+
43517+#ifdef CONFIG_PAX_ASLR
43518+ if (randomize_va_space && !(elf_ex->e_ident[EI_PAX] & EF_PAX_RANDMMAP))
43519+ pax_flags |= MF_PAX_RANDMMAP;
43520+#endif
43521+
43522+#else
43523+
43524+#ifdef CONFIG_PAX_PAGEEXEC
43525+ pax_flags |= MF_PAX_PAGEEXEC;
43526+#endif
43527+
43528+#ifdef CONFIG_PAX_SEGMEXEC
43529+ pax_flags |= MF_PAX_SEGMEXEC;
43530+#endif
43531+
43532+#ifdef CONFIG_PAX_MPROTECT
43533+ pax_flags |= MF_PAX_MPROTECT;
43534+#endif
43535+
43536+#ifdef CONFIG_PAX_RANDMMAP
43537+ if (randomize_va_space)
43538+ pax_flags |= MF_PAX_RANDMMAP;
43539+#endif
43540+
43541+#endif
43542+
43543+ return pax_flags;
43544+}
43545+
43546+static unsigned long pax_parse_pt_pax(const struct elfhdr * const elf_ex, const struct elf_phdr * const elf_phdata)
43547+{
43548+
43549+#ifdef CONFIG_PAX_PT_PAX_FLAGS
43550+ unsigned long i;
43551+
43552+ for (i = 0UL; i < elf_ex->e_phnum; i++)
43553+ if (elf_phdata[i].p_type == PT_PAX_FLAGS) {
43554+ if (((elf_phdata[i].p_flags & PF_PAGEEXEC) && (elf_phdata[i].p_flags & PF_NOPAGEEXEC)) ||
43555+ ((elf_phdata[i].p_flags & PF_SEGMEXEC) && (elf_phdata[i].p_flags & PF_NOSEGMEXEC)) ||
43556+ ((elf_phdata[i].p_flags & PF_EMUTRAMP) && (elf_phdata[i].p_flags & PF_NOEMUTRAMP)) ||
43557+ ((elf_phdata[i].p_flags & PF_MPROTECT) && (elf_phdata[i].p_flags & PF_NOMPROTECT)) ||
43558+ ((elf_phdata[i].p_flags & PF_RANDMMAP) && (elf_phdata[i].p_flags & PF_NORANDMMAP)))
43559+ return ~0UL;
43560+
43561+#ifdef CONFIG_PAX_SOFTMODE
43562+ if (pax_softmode)
43563+ return pax_parse_pt_pax_softmode(&elf_phdata[i]);
43564+ else
43565+#endif
43566+
43567+ return pax_parse_pt_pax_hardmode(&elf_phdata[i]);
43568+ break;
43569+ }
43570+#endif
43571+
43572+ return ~0UL;
43573+}
43574+
43575+static unsigned long pax_parse_xattr_pax(struct file * const file)
43576+{
43577+
43578+#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
43579+ ssize_t xattr_size, i;
43580+ unsigned char xattr_value[5];
43581+ unsigned long pax_flags_hardmode = 0UL, pax_flags_softmode = 0UL;
43582+
43583+ xattr_size = vfs_getxattr(file->f_path.dentry, XATTR_NAME_PAX_FLAGS, xattr_value, sizeof xattr_value);
43584+ if (xattr_size <= 0 || xattr_size > 5)
43585+ return ~0UL;
43586+
43587+ for (i = 0; i < xattr_size; i++)
43588+ switch (xattr_value[i]) {
43589+ default:
43590+ return ~0UL;
43591+
43592+#define parse_flag(option1, option2, flag) \
43593+ case option1: \
43594+ if (pax_flags_hardmode & MF_PAX_##flag) \
43595+ return ~0UL; \
43596+ pax_flags_hardmode |= MF_PAX_##flag; \
43597+ break; \
43598+ case option2: \
43599+ if (pax_flags_softmode & MF_PAX_##flag) \
43600+ return ~0UL; \
43601+ pax_flags_softmode |= MF_PAX_##flag; \
43602+ break;
43603+
43604+ parse_flag('p', 'P', PAGEEXEC);
43605+ parse_flag('e', 'E', EMUTRAMP);
43606+ parse_flag('m', 'M', MPROTECT);
43607+ parse_flag('r', 'R', RANDMMAP);
43608+ parse_flag('s', 'S', SEGMEXEC);
43609+
43610+#undef parse_flag
43611+ }
43612+
43613+ if (pax_flags_hardmode & pax_flags_softmode)
43614+ return ~0UL;
43615+
43616+#ifdef CONFIG_PAX_SOFTMODE
43617+ if (pax_softmode)
43618+ return pax_parse_xattr_pax_softmode(pax_flags_softmode);
43619+ else
43620+#endif
43621+
43622+ return pax_parse_xattr_pax_hardmode(pax_flags_hardmode);
43623+#else
43624+ return ~0UL;
43625+#endif
43626+
43627+}
43628+
43629+static long pax_parse_pax_flags(const struct elfhdr * const elf_ex, const struct elf_phdr * const elf_phdata, struct file * const file)
43630+{
43631+ unsigned long pax_flags, pt_pax_flags, xattr_pax_flags;
43632+
43633+ pax_flags = pax_parse_ei_pax(elf_ex);
43634+ pt_pax_flags = pax_parse_pt_pax(elf_ex, elf_phdata);
43635+ xattr_pax_flags = pax_parse_xattr_pax(file);
43636+
43637+ if (pt_pax_flags == ~0UL)
43638+ pt_pax_flags = xattr_pax_flags;
43639+ else if (xattr_pax_flags == ~0UL)
43640+ xattr_pax_flags = pt_pax_flags;
43641+ if (pt_pax_flags != xattr_pax_flags)
43642+ return -EINVAL;
43643+ if (pt_pax_flags != ~0UL)
43644+ pax_flags = pt_pax_flags;
43645+
43646+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_PAX_SEGMEXEC)
43647+ if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) == (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
43648+ if ((__supported_pte_mask & _PAGE_NX))
43649+ pax_flags &= ~MF_PAX_SEGMEXEC;
43650+ else
43651+ pax_flags &= ~MF_PAX_PAGEEXEC;
43652+ }
43653+#endif
43654+
43655+ if (0 > pax_check_flags(&pax_flags))
43656+ return -EINVAL;
43657+
43658+ current->mm->pax_flags = pax_flags;
43659+ return 0;
43660+}
43661+#endif
43662+
43663 /*
43664 * These are the functions used to load ELF style executables and shared
43665 * libraries. There is no binary dependent code anywhere else.
43666@@ -539,6 +869,11 @@ static unsigned long randomize_stack_top(unsigned long stack_top)
43667 {
43668 unsigned int random_variable = 0;
43669
43670+#ifdef CONFIG_PAX_RANDUSTACK
43671+ if (randomize_va_space)
43672+ return stack_top - current->mm->delta_stack;
43673+#endif
43674+
43675 if ((current->flags & PF_RANDOMIZE) &&
43676 !(current->personality & ADDR_NO_RANDOMIZE)) {
43677 random_variable = get_random_int() & STACK_RND_MASK;
43678@@ -557,7 +892,7 @@ static int load_elf_binary(struct linux_binprm *bprm, struct pt_regs *regs)
43679 unsigned long load_addr = 0, load_bias = 0;
43680 int load_addr_set = 0;
43681 char * elf_interpreter = NULL;
43682- unsigned long error;
43683+ unsigned long error = 0;
43684 struct elf_phdr *elf_ppnt, *elf_phdata;
43685 unsigned long elf_bss, elf_brk;
43686 int retval, i;
43687@@ -567,11 +902,11 @@ static int load_elf_binary(struct linux_binprm *bprm, struct pt_regs *regs)
43688 unsigned long start_code, end_code, start_data, end_data;
43689 unsigned long reloc_func_desc __maybe_unused = 0;
43690 int executable_stack = EXSTACK_DEFAULT;
43691- unsigned long def_flags = 0;
43692 struct {
43693 struct elfhdr elf_ex;
43694 struct elfhdr interp_elf_ex;
43695 } *loc;
43696+ unsigned long pax_task_size = TASK_SIZE;
43697
43698 loc = kmalloc(sizeof(*loc), GFP_KERNEL);
43699 if (!loc) {
43700@@ -707,11 +1042,81 @@ static int load_elf_binary(struct linux_binprm *bprm, struct pt_regs *regs)
43701 goto out_free_dentry;
43702
43703 /* OK, This is the point of no return */
43704- current->mm->def_flags = def_flags;
43705+
43706+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
43707+ current->mm->pax_flags = 0UL;
43708+#endif
43709+
43710+#ifdef CONFIG_PAX_DLRESOLVE
43711+ current->mm->call_dl_resolve = 0UL;
43712+#endif
43713+
43714+#if defined(CONFIG_PPC32) && defined(CONFIG_PAX_EMUSIGRT)
43715+ current->mm->call_syscall = 0UL;
43716+#endif
43717+
43718+#ifdef CONFIG_PAX_ASLR
43719+ current->mm->delta_mmap = 0UL;
43720+ current->mm->delta_stack = 0UL;
43721+#endif
43722+
43723+ current->mm->def_flags = 0;
43724+
43725+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
43726+ if (0 > pax_parse_pax_flags(&loc->elf_ex, elf_phdata, bprm->file)) {
43727+ send_sig(SIGKILL, current, 0);
43728+ goto out_free_dentry;
43729+ }
43730+#endif
43731+
43732+#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
43733+ pax_set_initial_flags(bprm);
43734+#elif defined(CONFIG_PAX_HOOK_ACL_FLAGS)
43735+ if (pax_set_initial_flags_func)
43736+ (pax_set_initial_flags_func)(bprm);
43737+#endif
43738+
43739+#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
43740+ if ((current->mm->pax_flags & MF_PAX_PAGEEXEC) && !(__supported_pte_mask & _PAGE_NX)) {
43741+ current->mm->context.user_cs_limit = PAGE_SIZE;
43742+ current->mm->def_flags |= VM_PAGEEXEC;
43743+ }
43744+#endif
43745+
43746+#ifdef CONFIG_PAX_SEGMEXEC
43747+ if (current->mm->pax_flags & MF_PAX_SEGMEXEC) {
43748+ current->mm->context.user_cs_base = SEGMEXEC_TASK_SIZE;
43749+ current->mm->context.user_cs_limit = TASK_SIZE-SEGMEXEC_TASK_SIZE;
43750+ pax_task_size = SEGMEXEC_TASK_SIZE;
43751+ current->mm->def_flags |= VM_NOHUGEPAGE;
43752+ }
43753+#endif
43754+
43755+#if defined(CONFIG_ARCH_TRACK_EXEC_LIMIT) || defined(CONFIG_PAX_SEGMEXEC)
43756+ if (current->mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
43757+ set_user_cs(current->mm->context.user_cs_base, current->mm->context.user_cs_limit, get_cpu());
43758+ put_cpu();
43759+ }
43760+#endif
43761
43762 /* Do this immediately, since STACK_TOP as used in setup_arg_pages
43763 may depend on the personality. */
43764 SET_PERSONALITY(loc->elf_ex);
43765+
43766+#ifdef CONFIG_PAX_ASLR
43767+ if (current->mm->pax_flags & MF_PAX_RANDMMAP) {
43768+ current->mm->delta_mmap = (pax_get_random_long() & ((1UL << PAX_DELTA_MMAP_LEN)-1)) << PAGE_SHIFT;
43769+ current->mm->delta_stack = (pax_get_random_long() & ((1UL << PAX_DELTA_STACK_LEN)-1)) << PAGE_SHIFT;
43770+ }
43771+#endif
43772+
43773+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
43774+ if (current->mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
43775+ executable_stack = EXSTACK_DISABLE_X;
43776+ current->personality &= ~READ_IMPLIES_EXEC;
43777+ } else
43778+#endif
43779+
43780 if (elf_read_implies_exec(loc->elf_ex, executable_stack))
43781 current->personality |= READ_IMPLIES_EXEC;
43782
43783@@ -802,6 +1207,20 @@ static int load_elf_binary(struct linux_binprm *bprm, struct pt_regs *regs)
43784 #else
43785 load_bias = ELF_PAGESTART(ELF_ET_DYN_BASE - vaddr);
43786 #endif
43787+
43788+#ifdef CONFIG_PAX_RANDMMAP
43789+ /* PaX: randomize base address at the default exe base if requested */
43790+ if ((current->mm->pax_flags & MF_PAX_RANDMMAP) && elf_interpreter) {
43791+#ifdef CONFIG_SPARC64
43792+ load_bias = (pax_get_random_long() & ((1UL << PAX_DELTA_MMAP_LEN) - 1)) << (PAGE_SHIFT+1);
43793+#else
43794+ load_bias = (pax_get_random_long() & ((1UL << PAX_DELTA_MMAP_LEN) - 1)) << PAGE_SHIFT;
43795+#endif
43796+ load_bias = ELF_PAGESTART(PAX_ELF_ET_DYN_BASE - vaddr + load_bias);
43797+ elf_flags |= MAP_FIXED;
43798+ }
43799+#endif
43800+
43801 }
43802
43803 error = elf_map(bprm->file, load_bias + vaddr, elf_ppnt,
43804@@ -834,9 +1253,9 @@ static int load_elf_binary(struct linux_binprm *bprm, struct pt_regs *regs)
43805 * allowed task size. Note that p_filesz must always be
43806 * <= p_memsz so it is only necessary to check p_memsz.
43807 */
43808- if (BAD_ADDR(k) || elf_ppnt->p_filesz > elf_ppnt->p_memsz ||
43809- elf_ppnt->p_memsz > TASK_SIZE ||
43810- TASK_SIZE - elf_ppnt->p_memsz < k) {
43811+ if (k >= pax_task_size || elf_ppnt->p_filesz > elf_ppnt->p_memsz ||
43812+ elf_ppnt->p_memsz > pax_task_size ||
43813+ pax_task_size - elf_ppnt->p_memsz < k) {
43814 /* set_brk can never work. Avoid overflows. */
43815 send_sig(SIGKILL, current, 0);
43816 retval = -EINVAL;
43817@@ -875,17 +1294,44 @@ static int load_elf_binary(struct linux_binprm *bprm, struct pt_regs *regs)
43818 goto out_free_dentry;
43819 }
43820 if (likely(elf_bss != elf_brk) && unlikely(padzero(elf_bss))) {
43821- send_sig(SIGSEGV, current, 0);
43822- retval = -EFAULT; /* Nobody gets to see this, but.. */
43823- goto out_free_dentry;
43824+ /*
43825+ * This bss-zeroing can fail if the ELF
43826+ * file specifies odd protections. So
43827+ * we don't check the return value
43828+ */
43829 }
43830
43831+#ifdef CONFIG_PAX_RANDMMAP
43832+ if (current->mm->pax_flags & MF_PAX_RANDMMAP) {
43833+ unsigned long start, size;
43834+
43835+ start = ELF_PAGEALIGN(elf_brk);
43836+ size = PAGE_SIZE + ((pax_get_random_long() & ((1UL << 22) - 1UL)) << 4);
43837+ down_read(&current->mm->mmap_sem);
43838+ retval = -ENOMEM;
43839+ if (!find_vma_intersection(current->mm, start, start + size + PAGE_SIZE)) {
43840+ unsigned long prot = PROT_NONE;
43841+
43842+ up_read(&current->mm->mmap_sem);
43843+ current->mm->brk_gap = PAGE_ALIGN(size) >> PAGE_SHIFT;
43844+// if (current->personality & ADDR_NO_RANDOMIZE)
43845+// prot = PROT_READ;
43846+ start = vm_mmap(NULL, start, size, prot, MAP_ANONYMOUS | MAP_FIXED | MAP_PRIVATE, 0);
43847+ retval = IS_ERR_VALUE(start) ? start : 0;
43848+ } else
43849+ up_read(&current->mm->mmap_sem);
43850+ if (retval == 0)
43851+ retval = set_brk(start + size, start + size + PAGE_SIZE);
43852+ if (retval < 0) {
43853+ send_sig(SIGKILL, current, 0);
43854+ goto out_free_dentry;
43855+ }
43856+ }
43857+#endif
43858+
43859 if (elf_interpreter) {
43860- unsigned long uninitialized_var(interp_map_addr);
43861-
43862 elf_entry = load_elf_interp(&loc->interp_elf_ex,
43863 interpreter,
43864- &interp_map_addr,
43865 load_bias);
43866 if (!IS_ERR((void *)elf_entry)) {
43867 /*
43868@@ -1107,7 +1553,7 @@ static bool always_dump_vma(struct vm_area_struct *vma)
43869 * Decide what to dump of a segment, part, all or none.
43870 */
43871 static unsigned long vma_dump_size(struct vm_area_struct *vma,
43872- unsigned long mm_flags)
43873+ unsigned long mm_flags, long signr)
43874 {
43875 #define FILTER(type) (mm_flags & (1UL << MMF_DUMP_##type))
43876
43877@@ -1144,7 +1590,7 @@ static unsigned long vma_dump_size(struct vm_area_struct *vma,
43878 if (vma->vm_file == NULL)
43879 return 0;
43880
43881- if (FILTER(MAPPED_PRIVATE))
43882+ if (signr == SIGKILL || FILTER(MAPPED_PRIVATE))
43883 goto whole;
43884
43885 /*
43886@@ -1366,9 +1812,9 @@ static void fill_auxv_note(struct memelfnote *note, struct mm_struct *mm)
43887 {
43888 elf_addr_t *auxv = (elf_addr_t *) mm->saved_auxv;
43889 int i = 0;
43890- do
43891+ do {
43892 i += 2;
43893- while (auxv[i - 2] != AT_NULL);
43894+ } while (auxv[i - 2] != AT_NULL);
43895 fill_note(note, "CORE", NT_AUXV, i * sizeof(elf_addr_t), auxv);
43896 }
43897
43898@@ -1879,14 +2325,14 @@ static void fill_extnum_info(struct elfhdr *elf, struct elf_shdr *shdr4extnum,
43899 }
43900
43901 static size_t elf_core_vma_data_size(struct vm_area_struct *gate_vma,
43902- unsigned long mm_flags)
43903+ struct coredump_params *cprm)
43904 {
43905 struct vm_area_struct *vma;
43906 size_t size = 0;
43907
43908 for (vma = first_vma(current, gate_vma); vma != NULL;
43909 vma = next_vma(vma, gate_vma))
43910- size += vma_dump_size(vma, mm_flags);
43911+ size += vma_dump_size(vma, cprm->mm_flags, cprm->signr);
43912 return size;
43913 }
43914
43915@@ -1980,7 +2426,7 @@ static int elf_core_dump(struct coredump_params *cprm)
43916
43917 dataoff = offset = roundup(offset, ELF_EXEC_PAGESIZE);
43918
43919- offset += elf_core_vma_data_size(gate_vma, cprm->mm_flags);
43920+ offset += elf_core_vma_data_size(gate_vma, cprm);
43921 offset += elf_core_extra_data_size();
43922 e_shoff = offset;
43923
43924@@ -1994,10 +2440,12 @@ static int elf_core_dump(struct coredump_params *cprm)
43925 offset = dataoff;
43926
43927 size += sizeof(*elf);
43928+ gr_learn_resource(current, RLIMIT_CORE, size, 1);
43929 if (size > cprm->limit || !dump_write(cprm->file, elf, sizeof(*elf)))
43930 goto end_coredump;
43931
43932 size += sizeof(*phdr4note);
43933+ gr_learn_resource(current, RLIMIT_CORE, size, 1);
43934 if (size > cprm->limit
43935 || !dump_write(cprm->file, phdr4note, sizeof(*phdr4note)))
43936 goto end_coredump;
43937@@ -2011,7 +2459,7 @@ static int elf_core_dump(struct coredump_params *cprm)
43938 phdr.p_offset = offset;
43939 phdr.p_vaddr = vma->vm_start;
43940 phdr.p_paddr = 0;
43941- phdr.p_filesz = vma_dump_size(vma, cprm->mm_flags);
43942+ phdr.p_filesz = vma_dump_size(vma, cprm->mm_flags, cprm->signr);
43943 phdr.p_memsz = vma->vm_end - vma->vm_start;
43944 offset += phdr.p_filesz;
43945 phdr.p_flags = vma->vm_flags & VM_READ ? PF_R : 0;
43946@@ -2022,6 +2470,7 @@ static int elf_core_dump(struct coredump_params *cprm)
43947 phdr.p_align = ELF_EXEC_PAGESIZE;
43948
43949 size += sizeof(phdr);
43950+ gr_learn_resource(current, RLIMIT_CORE, size, 1);
43951 if (size > cprm->limit
43952 || !dump_write(cprm->file, &phdr, sizeof(phdr)))
43953 goto end_coredump;
43954@@ -2046,7 +2495,7 @@ static int elf_core_dump(struct coredump_params *cprm)
43955 unsigned long addr;
43956 unsigned long end;
43957
43958- end = vma->vm_start + vma_dump_size(vma, cprm->mm_flags);
43959+ end = vma->vm_start + vma_dump_size(vma, cprm->mm_flags, cprm->signr);
43960
43961 for (addr = vma->vm_start; addr < end; addr += PAGE_SIZE) {
43962 struct page *page;
43963@@ -2055,6 +2504,7 @@ static int elf_core_dump(struct coredump_params *cprm)
43964 page = get_dump_page(addr);
43965 if (page) {
43966 void *kaddr = kmap(page);
43967+ gr_learn_resource(current, RLIMIT_CORE, size + PAGE_SIZE, 1);
43968 stop = ((size += PAGE_SIZE) > cprm->limit) ||
43969 !dump_write(cprm->file, kaddr,
43970 PAGE_SIZE);
43971@@ -2072,6 +2522,7 @@ static int elf_core_dump(struct coredump_params *cprm)
43972
43973 if (e_phnum == PN_XNUM) {
43974 size += sizeof(*shdr4extnum);
43975+ gr_learn_resource(current, RLIMIT_CORE, size, 1);
43976 if (size > cprm->limit
43977 || !dump_write(cprm->file, shdr4extnum,
43978 sizeof(*shdr4extnum)))
43979@@ -2092,6 +2543,97 @@ out:
43980
43981 #endif /* CONFIG_ELF_CORE */
43982
43983+#ifdef CONFIG_PAX_MPROTECT
43984+/* PaX: non-PIC ELF libraries need relocations on their executable segments
43985+ * therefore we'll grant them VM_MAYWRITE once during their life. Similarly
43986+ * we'll remove VM_MAYWRITE for good on RELRO segments.
43987+ *
43988+ * The checks favour ld-linux.so behaviour which operates on a per ELF segment
43989+ * basis because we want to allow the common case and not the special ones.
43990+ */
43991+static void elf_handle_mprotect(struct vm_area_struct *vma, unsigned long newflags)
43992+{
43993+ struct elfhdr elf_h;
43994+ struct elf_phdr elf_p;
43995+ unsigned long i;
43996+ unsigned long oldflags;
43997+ bool is_textrel_rw, is_textrel_rx, is_relro;
43998+
43999+ if (!(vma->vm_mm->pax_flags & MF_PAX_MPROTECT))
44000+ return;
44001+
44002+ oldflags = vma->vm_flags & (VM_MAYEXEC | VM_MAYWRITE | VM_MAYREAD | VM_EXEC | VM_WRITE | VM_READ);
44003+ newflags &= VM_MAYEXEC | VM_MAYWRITE | VM_MAYREAD | VM_EXEC | VM_WRITE | VM_READ;
44004+
44005+#ifdef CONFIG_PAX_ELFRELOCS
44006+ /* possible TEXTREL */
44007+ is_textrel_rw = vma->vm_file && !vma->anon_vma && oldflags == (VM_MAYEXEC | VM_MAYREAD | VM_EXEC | VM_READ) && newflags == (VM_WRITE | VM_READ);
44008+ 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);
44009+#else
44010+ is_textrel_rw = false;
44011+ is_textrel_rx = false;
44012+#endif
44013+
44014+ /* possible RELRO */
44015+ is_relro = vma->vm_file && vma->anon_vma && oldflags == (VM_MAYWRITE | VM_MAYREAD | VM_READ) && newflags == (VM_MAYWRITE | VM_MAYREAD | VM_READ);
44016+
44017+ if (!is_textrel_rw && !is_textrel_rx && !is_relro)
44018+ return;
44019+
44020+ if (sizeof(elf_h) != kernel_read(vma->vm_file, 0UL, (char *)&elf_h, sizeof(elf_h)) ||
44021+ memcmp(elf_h.e_ident, ELFMAG, SELFMAG) ||
44022+
44023+#ifdef CONFIG_PAX_ETEXECRELOCS
44024+ ((is_textrel_rw || is_textrel_rx) && (elf_h.e_type != ET_DYN && elf_h.e_type != ET_EXEC)) ||
44025+#else
44026+ ((is_textrel_rw || is_textrel_rx) && elf_h.e_type != ET_DYN) ||
44027+#endif
44028+
44029+ (is_relro && (elf_h.e_type != ET_DYN && elf_h.e_type != ET_EXEC)) ||
44030+ !elf_check_arch(&elf_h) ||
44031+ elf_h.e_phentsize != sizeof(struct elf_phdr) ||
44032+ elf_h.e_phnum > 65536UL / sizeof(struct elf_phdr))
44033+ return;
44034+
44035+ for (i = 0UL; i < elf_h.e_phnum; i++) {
44036+ if (sizeof(elf_p) != kernel_read(vma->vm_file, elf_h.e_phoff + i*sizeof(elf_p), (char *)&elf_p, sizeof(elf_p)))
44037+ return;
44038+ switch (elf_p.p_type) {
44039+ case PT_DYNAMIC:
44040+ if (!is_textrel_rw && !is_textrel_rx)
44041+ continue;
44042+ i = 0UL;
44043+ while ((i+1) * sizeof(elf_dyn) <= elf_p.p_filesz) {
44044+ elf_dyn dyn;
44045+
44046+ if (sizeof(dyn) != kernel_read(vma->vm_file, elf_p.p_offset + i*sizeof(dyn), (char *)&dyn, sizeof(dyn)))
44047+ return;
44048+ if (dyn.d_tag == DT_NULL)
44049+ return;
44050+ if (dyn.d_tag == DT_TEXTREL || (dyn.d_tag == DT_FLAGS && (dyn.d_un.d_val & DF_TEXTREL))) {
44051+ gr_log_textrel(vma);
44052+ if (is_textrel_rw)
44053+ vma->vm_flags |= VM_MAYWRITE;
44054+ else
44055+ /* PaX: disallow write access after relocs are done, hopefully noone else needs it... */
44056+ vma->vm_flags &= ~VM_MAYWRITE;
44057+ return;
44058+ }
44059+ i++;
44060+ }
44061+ return;
44062+
44063+ case PT_GNU_RELRO:
44064+ if (!is_relro)
44065+ continue;
44066+ if ((elf_p.p_offset >> PAGE_SHIFT) == vma->vm_pgoff && ELF_PAGEALIGN(elf_p.p_memsz) == vma->vm_end - vma->vm_start)
44067+ vma->vm_flags &= ~VM_MAYWRITE;
44068+ return;
44069+ }
44070+ }
44071+}
44072+#endif
44073+
44074 static int __init init_elf_binfmt(void)
44075 {
44076 register_binfmt(&elf_format);
44077diff --git a/fs/binfmt_flat.c b/fs/binfmt_flat.c
44078index 178cb70..8972997 100644
44079--- a/fs/binfmt_flat.c
44080+++ b/fs/binfmt_flat.c
44081@@ -562,7 +562,9 @@ static int load_flat_file(struct linux_binprm * bprm,
44082 realdatastart = (unsigned long) -ENOMEM;
44083 printk("Unable to allocate RAM for process data, errno %d\n",
44084 (int)-realdatastart);
44085+ down_write(&current->mm->mmap_sem);
44086 vm_munmap(textpos, text_len);
44087+ up_write(&current->mm->mmap_sem);
44088 ret = realdatastart;
44089 goto err;
44090 }
44091@@ -586,8 +588,10 @@ static int load_flat_file(struct linux_binprm * bprm,
44092 }
44093 if (IS_ERR_VALUE(result)) {
44094 printk("Unable to read data+bss, errno %d\n", (int)-result);
44095+ down_write(&current->mm->mmap_sem);
44096 vm_munmap(textpos, text_len);
44097 vm_munmap(realdatastart, len);
44098+ up_write(&current->mm->mmap_sem);
44099 ret = result;
44100 goto err;
44101 }
44102@@ -654,8 +658,10 @@ static int load_flat_file(struct linux_binprm * bprm,
44103 }
44104 if (IS_ERR_VALUE(result)) {
44105 printk("Unable to read code+data+bss, errno %d\n",(int)-result);
44106+ down_write(&current->mm->mmap_sem);
44107 vm_munmap(textpos, text_len + data_len + extra +
44108 MAX_SHARED_LIBS * sizeof(unsigned long));
44109+ up_write(&current->mm->mmap_sem);
44110 ret = result;
44111 goto err;
44112 }
44113diff --git a/fs/bio.c b/fs/bio.c
44114index 71072ab..439851b 100644
44115--- a/fs/bio.c
44116+++ b/fs/bio.c
44117@@ -842,7 +842,7 @@ struct bio *bio_copy_user_iov(struct request_queue *q,
44118 /*
44119 * Overflow, abort
44120 */
44121- if (end < start)
44122+ if (end < start || end - start > INT_MAX - nr_pages)
44123 return ERR_PTR(-EINVAL);
44124
44125 nr_pages += end - start;
44126@@ -976,7 +976,7 @@ static struct bio *__bio_map_user_iov(struct request_queue *q,
44127 /*
44128 * Overflow, abort
44129 */
44130- if (end < start)
44131+ if (end < start || end - start > INT_MAX - nr_pages)
44132 return ERR_PTR(-EINVAL);
44133
44134 nr_pages += end - start;
44135@@ -1238,7 +1238,7 @@ static void bio_copy_kern_endio(struct bio *bio, int err)
44136 const int read = bio_data_dir(bio) == READ;
44137 struct bio_map_data *bmd = bio->bi_private;
44138 int i;
44139- char *p = bmd->sgvecs[0].iov_base;
44140+ char *p = (char __force_kernel *)bmd->sgvecs[0].iov_base;
44141
44142 __bio_for_each_segment(bvec, bio, i, 0) {
44143 char *addr = page_address(bvec->bv_page);
44144diff --git a/fs/block_dev.c b/fs/block_dev.c
44145index 38e721b..7a9c5bc 100644
44146--- a/fs/block_dev.c
44147+++ b/fs/block_dev.c
44148@@ -704,7 +704,7 @@ static bool bd_may_claim(struct block_device *bdev, struct block_device *whole,
44149 else if (bdev->bd_contains == bdev)
44150 return true; /* is a whole device which isn't held */
44151
44152- else if (whole->bd_holder == bd_may_claim)
44153+ else if (whole->bd_holder == (void *)bd_may_claim)
44154 return true; /* is a partition of a device that is being partitioned */
44155 else if (whole->bd_holder != NULL)
44156 return false; /* is a partition of a held device */
44157diff --git a/fs/btrfs/check-integrity.c b/fs/btrfs/check-integrity.c
44158index 9197e2e..7f731f8 100644
44159--- a/fs/btrfs/check-integrity.c
44160+++ b/fs/btrfs/check-integrity.c
44161@@ -155,7 +155,7 @@ struct btrfsic_block {
44162 union {
44163 bio_end_io_t *bio;
44164 bh_end_io_t *bh;
44165- } orig_bio_bh_end_io;
44166+ } __no_const orig_bio_bh_end_io;
44167 int submit_bio_bh_rw;
44168 u64 flush_gen; /* only valid if !never_written */
44169 };
44170diff --git a/fs/btrfs/ctree.c b/fs/btrfs/ctree.c
44171index 6d183f6..f47cc7a 100644
44172--- a/fs/btrfs/ctree.c
44173+++ b/fs/btrfs/ctree.c
44174@@ -1037,9 +1037,12 @@ static noinline int __btrfs_cow_block(struct btrfs_trans_handle *trans,
44175 free_extent_buffer(buf);
44176 add_root_to_dirty_list(root);
44177 } else {
44178- if (root->root_key.objectid == BTRFS_TREE_RELOC_OBJECTID)
44179- parent_start = parent->start;
44180- else
44181+ if (root->root_key.objectid == BTRFS_TREE_RELOC_OBJECTID) {
44182+ if (parent)
44183+ parent_start = parent->start;
44184+ else
44185+ parent_start = 0;
44186+ } else
44187 parent_start = 0;
44188
44189 WARN_ON(trans->transid != btrfs_header_generation(parent));
44190diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c
44191index ec154f9..bf617a7 100644
44192--- a/fs/btrfs/inode.c
44193+++ b/fs/btrfs/inode.c
44194@@ -7126,7 +7126,7 @@ fail:
44195 return -ENOMEM;
44196 }
44197
44198-static int btrfs_getattr(struct vfsmount *mnt,
44199+int btrfs_getattr(struct vfsmount *mnt,
44200 struct dentry *dentry, struct kstat *stat)
44201 {
44202 struct inode *inode = dentry->d_inode;
44203@@ -7140,6 +7140,14 @@ static int btrfs_getattr(struct vfsmount *mnt,
44204 return 0;
44205 }
44206
44207+EXPORT_SYMBOL(btrfs_getattr);
44208+
44209+dev_t get_btrfs_dev_from_inode(struct inode *inode)
44210+{
44211+ return BTRFS_I(inode)->root->anon_dev;
44212+}
44213+EXPORT_SYMBOL(get_btrfs_dev_from_inode);
44214+
44215 /*
44216 * If a file is moved, it will inherit the cow and compression flags of the new
44217 * directory.
44218diff --git a/fs/btrfs/ioctl.c b/fs/btrfs/ioctl.c
44219index 9df50fa..6cd20d0 100644
44220--- a/fs/btrfs/ioctl.c
44221+++ b/fs/btrfs/ioctl.c
44222@@ -2942,9 +2942,12 @@ long btrfs_ioctl_space_info(struct btrfs_root *root, void __user *arg)
44223 for (i = 0; i < num_types; i++) {
44224 struct btrfs_space_info *tmp;
44225
44226+ /* Don't copy in more than we allocated */
44227 if (!slot_count)
44228 break;
44229
44230+ slot_count--;
44231+
44232 info = NULL;
44233 rcu_read_lock();
44234 list_for_each_entry_rcu(tmp, &root->fs_info->space_info,
44235@@ -2966,10 +2969,7 @@ long btrfs_ioctl_space_info(struct btrfs_root *root, void __user *arg)
44236 memcpy(dest, &space, sizeof(space));
44237 dest++;
44238 space_args.total_spaces++;
44239- slot_count--;
44240 }
44241- if (!slot_count)
44242- break;
44243 }
44244 up_read(&info->groups_sem);
44245 }
44246diff --git a/fs/btrfs/relocation.c b/fs/btrfs/relocation.c
44247index 4da0865..01c4778 100644
44248--- a/fs/btrfs/relocation.c
44249+++ b/fs/btrfs/relocation.c
44250@@ -1269,7 +1269,7 @@ static int __update_reloc_root(struct btrfs_root *root, int del)
44251 }
44252 spin_unlock(&rc->reloc_root_tree.lock);
44253
44254- BUG_ON((struct btrfs_root *)node->data != root);
44255+ BUG_ON(!node || (struct btrfs_root *)node->data != root);
44256
44257 if (!del) {
44258 spin_lock(&rc->reloc_root_tree.lock);
44259diff --git a/fs/cachefiles/bind.c b/fs/cachefiles/bind.c
44260index 622f469..e8d2d55 100644
44261--- a/fs/cachefiles/bind.c
44262+++ b/fs/cachefiles/bind.c
44263@@ -39,13 +39,11 @@ int cachefiles_daemon_bind(struct cachefiles_cache *cache, char *args)
44264 args);
44265
44266 /* start by checking things over */
44267- ASSERT(cache->fstop_percent >= 0 &&
44268- cache->fstop_percent < cache->fcull_percent &&
44269+ ASSERT(cache->fstop_percent < cache->fcull_percent &&
44270 cache->fcull_percent < cache->frun_percent &&
44271 cache->frun_percent < 100);
44272
44273- ASSERT(cache->bstop_percent >= 0 &&
44274- cache->bstop_percent < cache->bcull_percent &&
44275+ ASSERT(cache->bstop_percent < cache->bcull_percent &&
44276 cache->bcull_percent < cache->brun_percent &&
44277 cache->brun_percent < 100);
44278
44279diff --git a/fs/cachefiles/daemon.c b/fs/cachefiles/daemon.c
44280index 0a1467b..6a53245 100644
44281--- a/fs/cachefiles/daemon.c
44282+++ b/fs/cachefiles/daemon.c
44283@@ -196,7 +196,7 @@ static ssize_t cachefiles_daemon_read(struct file *file, char __user *_buffer,
44284 if (n > buflen)
44285 return -EMSGSIZE;
44286
44287- if (copy_to_user(_buffer, buffer, n) != 0)
44288+ if (n > sizeof(buffer) || copy_to_user(_buffer, buffer, n) != 0)
44289 return -EFAULT;
44290
44291 return n;
44292@@ -222,7 +222,7 @@ static ssize_t cachefiles_daemon_write(struct file *file,
44293 if (test_bit(CACHEFILES_DEAD, &cache->flags))
44294 return -EIO;
44295
44296- if (datalen < 0 || datalen > PAGE_SIZE - 1)
44297+ if (datalen > PAGE_SIZE - 1)
44298 return -EOPNOTSUPP;
44299
44300 /* drag the command string into the kernel so we can parse it */
44301@@ -386,7 +386,7 @@ static int cachefiles_daemon_fstop(struct cachefiles_cache *cache, char *args)
44302 if (args[0] != '%' || args[1] != '\0')
44303 return -EINVAL;
44304
44305- if (fstop < 0 || fstop >= cache->fcull_percent)
44306+ if (fstop >= cache->fcull_percent)
44307 return cachefiles_daemon_range_error(cache, args);
44308
44309 cache->fstop_percent = fstop;
44310@@ -458,7 +458,7 @@ static int cachefiles_daemon_bstop(struct cachefiles_cache *cache, char *args)
44311 if (args[0] != '%' || args[1] != '\0')
44312 return -EINVAL;
44313
44314- if (bstop < 0 || bstop >= cache->bcull_percent)
44315+ if (bstop >= cache->bcull_percent)
44316 return cachefiles_daemon_range_error(cache, args);
44317
44318 cache->bstop_percent = bstop;
44319diff --git a/fs/cachefiles/internal.h b/fs/cachefiles/internal.h
44320index bd6bc1b..b627b53 100644
44321--- a/fs/cachefiles/internal.h
44322+++ b/fs/cachefiles/internal.h
44323@@ -57,7 +57,7 @@ struct cachefiles_cache {
44324 wait_queue_head_t daemon_pollwq; /* poll waitqueue for daemon */
44325 struct rb_root active_nodes; /* active nodes (can't be culled) */
44326 rwlock_t active_lock; /* lock for active_nodes */
44327- atomic_t gravecounter; /* graveyard uniquifier */
44328+ atomic_unchecked_t gravecounter; /* graveyard uniquifier */
44329 unsigned frun_percent; /* when to stop culling (% files) */
44330 unsigned fcull_percent; /* when to start culling (% files) */
44331 unsigned fstop_percent; /* when to stop allocating (% files) */
44332@@ -169,19 +169,19 @@ extern int cachefiles_check_in_use(struct cachefiles_cache *cache,
44333 * proc.c
44334 */
44335 #ifdef CONFIG_CACHEFILES_HISTOGRAM
44336-extern atomic_t cachefiles_lookup_histogram[HZ];
44337-extern atomic_t cachefiles_mkdir_histogram[HZ];
44338-extern atomic_t cachefiles_create_histogram[HZ];
44339+extern atomic_unchecked_t cachefiles_lookup_histogram[HZ];
44340+extern atomic_unchecked_t cachefiles_mkdir_histogram[HZ];
44341+extern atomic_unchecked_t cachefiles_create_histogram[HZ];
44342
44343 extern int __init cachefiles_proc_init(void);
44344 extern void cachefiles_proc_cleanup(void);
44345 static inline
44346-void cachefiles_hist(atomic_t histogram[], unsigned long start_jif)
44347+void cachefiles_hist(atomic_unchecked_t histogram[], unsigned long start_jif)
44348 {
44349 unsigned long jif = jiffies - start_jif;
44350 if (jif >= HZ)
44351 jif = HZ - 1;
44352- atomic_inc(&histogram[jif]);
44353+ atomic_inc_unchecked(&histogram[jif]);
44354 }
44355
44356 #else
44357diff --git a/fs/cachefiles/namei.c b/fs/cachefiles/namei.c
44358index b0b5f7c..039bb26 100644
44359--- a/fs/cachefiles/namei.c
44360+++ b/fs/cachefiles/namei.c
44361@@ -318,7 +318,7 @@ try_again:
44362 /* first step is to make up a grave dentry in the graveyard */
44363 sprintf(nbuffer, "%08x%08x",
44364 (uint32_t) get_seconds(),
44365- (uint32_t) atomic_inc_return(&cache->gravecounter));
44366+ (uint32_t) atomic_inc_return_unchecked(&cache->gravecounter));
44367
44368 /* do the multiway lock magic */
44369 trap = lock_rename(cache->graveyard, dir);
44370diff --git a/fs/cachefiles/proc.c b/fs/cachefiles/proc.c
44371index eccd339..4c1d995 100644
44372--- a/fs/cachefiles/proc.c
44373+++ b/fs/cachefiles/proc.c
44374@@ -14,9 +14,9 @@
44375 #include <linux/seq_file.h>
44376 #include "internal.h"
44377
44378-atomic_t cachefiles_lookup_histogram[HZ];
44379-atomic_t cachefiles_mkdir_histogram[HZ];
44380-atomic_t cachefiles_create_histogram[HZ];
44381+atomic_unchecked_t cachefiles_lookup_histogram[HZ];
44382+atomic_unchecked_t cachefiles_mkdir_histogram[HZ];
44383+atomic_unchecked_t cachefiles_create_histogram[HZ];
44384
44385 /*
44386 * display the latency histogram
44387@@ -35,9 +35,9 @@ static int cachefiles_histogram_show(struct seq_file *m, void *v)
44388 return 0;
44389 default:
44390 index = (unsigned long) v - 3;
44391- x = atomic_read(&cachefiles_lookup_histogram[index]);
44392- y = atomic_read(&cachefiles_mkdir_histogram[index]);
44393- z = atomic_read(&cachefiles_create_histogram[index]);
44394+ x = atomic_read_unchecked(&cachefiles_lookup_histogram[index]);
44395+ y = atomic_read_unchecked(&cachefiles_mkdir_histogram[index]);
44396+ z = atomic_read_unchecked(&cachefiles_create_histogram[index]);
44397 if (x == 0 && y == 0 && z == 0)
44398 return 0;
44399
44400diff --git a/fs/cachefiles/rdwr.c b/fs/cachefiles/rdwr.c
44401index c994691..2a1537f 100644
44402--- a/fs/cachefiles/rdwr.c
44403+++ b/fs/cachefiles/rdwr.c
44404@@ -945,7 +945,7 @@ int cachefiles_write_page(struct fscache_storage *op, struct page *page)
44405 old_fs = get_fs();
44406 set_fs(KERNEL_DS);
44407 ret = file->f_op->write(
44408- file, (const void __user *) data, len, &pos);
44409+ file, (const void __force_user *) data, len, &pos);
44410 set_fs(old_fs);
44411 kunmap(page);
44412 if (ret != len)
44413diff --git a/fs/ceph/dir.c b/fs/ceph/dir.c
44414index e5b7731..b9c59fb 100644
44415--- a/fs/ceph/dir.c
44416+++ b/fs/ceph/dir.c
44417@@ -243,7 +243,7 @@ static int ceph_readdir(struct file *filp, void *dirent, filldir_t filldir)
44418 struct ceph_fs_client *fsc = ceph_inode_to_client(inode);
44419 struct ceph_mds_client *mdsc = fsc->mdsc;
44420 unsigned frag = fpos_frag(filp->f_pos);
44421- int off = fpos_off(filp->f_pos);
44422+ unsigned int off = fpos_off(filp->f_pos);
44423 int err;
44424 u32 ftype;
44425 struct ceph_mds_reply_info_parsed *rinfo;
44426diff --git a/fs/cifs/cifs_debug.c b/fs/cifs/cifs_debug.c
44427index d9ea6ed..1e6c8ac 100644
44428--- a/fs/cifs/cifs_debug.c
44429+++ b/fs/cifs/cifs_debug.c
44430@@ -267,8 +267,8 @@ static ssize_t cifs_stats_proc_write(struct file *file,
44431
44432 if (c == '1' || c == 'y' || c == 'Y' || c == '0') {
44433 #ifdef CONFIG_CIFS_STATS2
44434- atomic_set(&totBufAllocCount, 0);
44435- atomic_set(&totSmBufAllocCount, 0);
44436+ atomic_set_unchecked(&totBufAllocCount, 0);
44437+ atomic_set_unchecked(&totSmBufAllocCount, 0);
44438 #endif /* CONFIG_CIFS_STATS2 */
44439 spin_lock(&cifs_tcp_ses_lock);
44440 list_for_each(tmp1, &cifs_tcp_ses_list) {
44441@@ -281,7 +281,7 @@ static ssize_t cifs_stats_proc_write(struct file *file,
44442 tcon = list_entry(tmp3,
44443 struct cifs_tcon,
44444 tcon_list);
44445- atomic_set(&tcon->num_smbs_sent, 0);
44446+ atomic_set_unchecked(&tcon->num_smbs_sent, 0);
44447 if (server->ops->clear_stats)
44448 server->ops->clear_stats(tcon);
44449 }
44450@@ -313,8 +313,8 @@ static int cifs_stats_proc_show(struct seq_file *m, void *v)
44451 smBufAllocCount.counter, cifs_min_small);
44452 #ifdef CONFIG_CIFS_STATS2
44453 seq_printf(m, "Total Large %d Small %d Allocations\n",
44454- atomic_read(&totBufAllocCount),
44455- atomic_read(&totSmBufAllocCount));
44456+ atomic_read_unchecked(&totBufAllocCount),
44457+ atomic_read_unchecked(&totSmBufAllocCount));
44458 #endif /* CONFIG_CIFS_STATS2 */
44459
44460 seq_printf(m, "Operations (MIDs): %d\n", atomic_read(&midCount));
44461@@ -343,7 +343,7 @@ static int cifs_stats_proc_show(struct seq_file *m, void *v)
44462 if (tcon->need_reconnect)
44463 seq_puts(m, "\tDISCONNECTED ");
44464 seq_printf(m, "\nSMBs: %d",
44465- atomic_read(&tcon->num_smbs_sent));
44466+ atomic_read_unchecked(&tcon->num_smbs_sent));
44467 if (server->ops->print_stats)
44468 server->ops->print_stats(m, tcon);
44469 }
44470diff --git a/fs/cifs/cifsfs.c b/fs/cifs/cifsfs.c
44471index db8a404..c712e2e 100644
44472--- a/fs/cifs/cifsfs.c
44473+++ b/fs/cifs/cifsfs.c
44474@@ -1003,7 +1003,7 @@ cifs_init_request_bufs(void)
44475 /* cERROR(1, "CIFSMaxBufSize %d 0x%x",CIFSMaxBufSize,CIFSMaxBufSize); */
44476 cifs_req_cachep = kmem_cache_create("cifs_request",
44477 CIFSMaxBufSize + max_hdr_size, 0,
44478- SLAB_HWCACHE_ALIGN, NULL);
44479+ SLAB_HWCACHE_ALIGN | SLAB_USERCOPY, NULL);
44480 if (cifs_req_cachep == NULL)
44481 return -ENOMEM;
44482
44483@@ -1030,7 +1030,7 @@ cifs_init_request_bufs(void)
44484 efficient to alloc 1 per page off the slab compared to 17K (5page)
44485 alloc of large cifs buffers even when page debugging is on */
44486 cifs_sm_req_cachep = kmem_cache_create("cifs_small_rq",
44487- MAX_CIFS_SMALL_BUFFER_SIZE, 0, SLAB_HWCACHE_ALIGN,
44488+ MAX_CIFS_SMALL_BUFFER_SIZE, 0, SLAB_HWCACHE_ALIGN | SLAB_USERCOPY,
44489 NULL);
44490 if (cifs_sm_req_cachep == NULL) {
44491 mempool_destroy(cifs_req_poolp);
44492@@ -1115,8 +1115,8 @@ init_cifs(void)
44493 atomic_set(&bufAllocCount, 0);
44494 atomic_set(&smBufAllocCount, 0);
44495 #ifdef CONFIG_CIFS_STATS2
44496- atomic_set(&totBufAllocCount, 0);
44497- atomic_set(&totSmBufAllocCount, 0);
44498+ atomic_set_unchecked(&totBufAllocCount, 0);
44499+ atomic_set_unchecked(&totSmBufAllocCount, 0);
44500 #endif /* CONFIG_CIFS_STATS2 */
44501
44502 atomic_set(&midCount, 0);
44503diff --git a/fs/cifs/cifsglob.h b/fs/cifs/cifsglob.h
44504index 977dc0e..ba48ab9 100644
44505--- a/fs/cifs/cifsglob.h
44506+++ b/fs/cifs/cifsglob.h
44507@@ -590,35 +590,35 @@ struct cifs_tcon {
44508 __u16 Flags; /* optional support bits */
44509 enum statusEnum tidStatus;
44510 #ifdef CONFIG_CIFS_STATS
44511- atomic_t num_smbs_sent;
44512+ atomic_unchecked_t num_smbs_sent;
44513 union {
44514 struct {
44515- atomic_t num_writes;
44516- atomic_t num_reads;
44517- atomic_t num_flushes;
44518- atomic_t num_oplock_brks;
44519- atomic_t num_opens;
44520- atomic_t num_closes;
44521- atomic_t num_deletes;
44522- atomic_t num_mkdirs;
44523- atomic_t num_posixopens;
44524- atomic_t num_posixmkdirs;
44525- atomic_t num_rmdirs;
44526- atomic_t num_renames;
44527- atomic_t num_t2renames;
44528- atomic_t num_ffirst;
44529- atomic_t num_fnext;
44530- atomic_t num_fclose;
44531- atomic_t num_hardlinks;
44532- atomic_t num_symlinks;
44533- atomic_t num_locks;
44534- atomic_t num_acl_get;
44535- atomic_t num_acl_set;
44536+ atomic_unchecked_t num_writes;
44537+ atomic_unchecked_t num_reads;
44538+ atomic_unchecked_t num_flushes;
44539+ atomic_unchecked_t num_oplock_brks;
44540+ atomic_unchecked_t num_opens;
44541+ atomic_unchecked_t num_closes;
44542+ atomic_unchecked_t num_deletes;
44543+ atomic_unchecked_t num_mkdirs;
44544+ atomic_unchecked_t num_posixopens;
44545+ atomic_unchecked_t num_posixmkdirs;
44546+ atomic_unchecked_t num_rmdirs;
44547+ atomic_unchecked_t num_renames;
44548+ atomic_unchecked_t num_t2renames;
44549+ atomic_unchecked_t num_ffirst;
44550+ atomic_unchecked_t num_fnext;
44551+ atomic_unchecked_t num_fclose;
44552+ atomic_unchecked_t num_hardlinks;
44553+ atomic_unchecked_t num_symlinks;
44554+ atomic_unchecked_t num_locks;
44555+ atomic_unchecked_t num_acl_get;
44556+ atomic_unchecked_t num_acl_set;
44557 } cifs_stats;
44558 #ifdef CONFIG_CIFS_SMB2
44559 struct {
44560- atomic_t smb2_com_sent[NUMBER_OF_SMB2_COMMANDS];
44561- atomic_t smb2_com_failed[NUMBER_OF_SMB2_COMMANDS];
44562+ atomic_unchecked_t smb2_com_sent[NUMBER_OF_SMB2_COMMANDS];
44563+ atomic_unchecked_t smb2_com_failed[NUMBER_OF_SMB2_COMMANDS];
44564 } smb2_stats;
44565 #endif /* CONFIG_CIFS_SMB2 */
44566 } stats;
44567@@ -862,7 +862,7 @@ build_path_to_root(struct smb_vol *vol, struct cifs_sb_info *cifs_sb,
44568 }
44569
44570 #ifdef CONFIG_CIFS_STATS
44571-#define cifs_stats_inc atomic_inc
44572+#define cifs_stats_inc atomic_inc_unchecked
44573
44574 static inline void cifs_stats_bytes_written(struct cifs_tcon *tcon,
44575 unsigned int bytes)
44576@@ -1227,8 +1227,8 @@ GLOBAL_EXTERN atomic_t tconInfoReconnectCount;
44577 /* Various Debug counters */
44578 GLOBAL_EXTERN atomic_t bufAllocCount; /* current number allocated */
44579 #ifdef CONFIG_CIFS_STATS2
44580-GLOBAL_EXTERN atomic_t totBufAllocCount; /* total allocated over all time */
44581-GLOBAL_EXTERN atomic_t totSmBufAllocCount;
44582+GLOBAL_EXTERN atomic_unchecked_t totBufAllocCount; /* total allocated over all time */
44583+GLOBAL_EXTERN atomic_unchecked_t totSmBufAllocCount;
44584 #endif
44585 GLOBAL_EXTERN atomic_t smBufAllocCount;
44586 GLOBAL_EXTERN atomic_t midCount;
44587diff --git a/fs/cifs/link.c b/fs/cifs/link.c
44588index e6ce3b1..adc21fd 100644
44589--- a/fs/cifs/link.c
44590+++ b/fs/cifs/link.c
44591@@ -602,7 +602,7 @@ symlink_exit:
44592
44593 void cifs_put_link(struct dentry *direntry, struct nameidata *nd, void *cookie)
44594 {
44595- char *p = nd_get_link(nd);
44596+ const char *p = nd_get_link(nd);
44597 if (!IS_ERR(p))
44598 kfree(p);
44599 }
44600diff --git a/fs/cifs/misc.c b/fs/cifs/misc.c
44601index ce41fee..ac0d27a 100644
44602--- a/fs/cifs/misc.c
44603+++ b/fs/cifs/misc.c
44604@@ -169,7 +169,7 @@ cifs_buf_get(void)
44605 memset(ret_buf, 0, buf_size + 3);
44606 atomic_inc(&bufAllocCount);
44607 #ifdef CONFIG_CIFS_STATS2
44608- atomic_inc(&totBufAllocCount);
44609+ atomic_inc_unchecked(&totBufAllocCount);
44610 #endif /* CONFIG_CIFS_STATS2 */
44611 }
44612
44613@@ -204,7 +204,7 @@ cifs_small_buf_get(void)
44614 /* memset(ret_buf, 0, sizeof(struct smb_hdr) + 27);*/
44615 atomic_inc(&smBufAllocCount);
44616 #ifdef CONFIG_CIFS_STATS2
44617- atomic_inc(&totSmBufAllocCount);
44618+ atomic_inc_unchecked(&totSmBufAllocCount);
44619 #endif /* CONFIG_CIFS_STATS2 */
44620
44621 }
44622diff --git a/fs/cifs/smb1ops.c b/fs/cifs/smb1ops.c
44623index 3129ac7..cc4a948 100644
44624--- a/fs/cifs/smb1ops.c
44625+++ b/fs/cifs/smb1ops.c
44626@@ -524,27 +524,27 @@ static void
44627 cifs_clear_stats(struct cifs_tcon *tcon)
44628 {
44629 #ifdef CONFIG_CIFS_STATS
44630- atomic_set(&tcon->stats.cifs_stats.num_writes, 0);
44631- atomic_set(&tcon->stats.cifs_stats.num_reads, 0);
44632- atomic_set(&tcon->stats.cifs_stats.num_flushes, 0);
44633- atomic_set(&tcon->stats.cifs_stats.num_oplock_brks, 0);
44634- atomic_set(&tcon->stats.cifs_stats.num_opens, 0);
44635- atomic_set(&tcon->stats.cifs_stats.num_posixopens, 0);
44636- atomic_set(&tcon->stats.cifs_stats.num_posixmkdirs, 0);
44637- atomic_set(&tcon->stats.cifs_stats.num_closes, 0);
44638- atomic_set(&tcon->stats.cifs_stats.num_deletes, 0);
44639- atomic_set(&tcon->stats.cifs_stats.num_mkdirs, 0);
44640- atomic_set(&tcon->stats.cifs_stats.num_rmdirs, 0);
44641- atomic_set(&tcon->stats.cifs_stats.num_renames, 0);
44642- atomic_set(&tcon->stats.cifs_stats.num_t2renames, 0);
44643- atomic_set(&tcon->stats.cifs_stats.num_ffirst, 0);
44644- atomic_set(&tcon->stats.cifs_stats.num_fnext, 0);
44645- atomic_set(&tcon->stats.cifs_stats.num_fclose, 0);
44646- atomic_set(&tcon->stats.cifs_stats.num_hardlinks, 0);
44647- atomic_set(&tcon->stats.cifs_stats.num_symlinks, 0);
44648- atomic_set(&tcon->stats.cifs_stats.num_locks, 0);
44649- atomic_set(&tcon->stats.cifs_stats.num_acl_get, 0);
44650- atomic_set(&tcon->stats.cifs_stats.num_acl_set, 0);
44651+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_writes, 0);
44652+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_reads, 0);
44653+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_flushes, 0);
44654+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_oplock_brks, 0);
44655+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_opens, 0);
44656+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_posixopens, 0);
44657+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_posixmkdirs, 0);
44658+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_closes, 0);
44659+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_deletes, 0);
44660+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_mkdirs, 0);
44661+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_rmdirs, 0);
44662+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_renames, 0);
44663+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_t2renames, 0);
44664+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_ffirst, 0);
44665+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_fnext, 0);
44666+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_fclose, 0);
44667+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_hardlinks, 0);
44668+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_symlinks, 0);
44669+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_locks, 0);
44670+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_acl_get, 0);
44671+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_acl_set, 0);
44672 #endif
44673 }
44674
44675@@ -553,36 +553,36 @@ cifs_print_stats(struct seq_file *m, struct cifs_tcon *tcon)
44676 {
44677 #ifdef CONFIG_CIFS_STATS
44678 seq_printf(m, " Oplocks breaks: %d",
44679- atomic_read(&tcon->stats.cifs_stats.num_oplock_brks));
44680+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_oplock_brks));
44681 seq_printf(m, "\nReads: %d Bytes: %llu",
44682- atomic_read(&tcon->stats.cifs_stats.num_reads),
44683+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_reads),
44684 (long long)(tcon->bytes_read));
44685 seq_printf(m, "\nWrites: %d Bytes: %llu",
44686- atomic_read(&tcon->stats.cifs_stats.num_writes),
44687+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_writes),
44688 (long long)(tcon->bytes_written));
44689 seq_printf(m, "\nFlushes: %d",
44690- atomic_read(&tcon->stats.cifs_stats.num_flushes));
44691+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_flushes));
44692 seq_printf(m, "\nLocks: %d HardLinks: %d Symlinks: %d",
44693- atomic_read(&tcon->stats.cifs_stats.num_locks),
44694- atomic_read(&tcon->stats.cifs_stats.num_hardlinks),
44695- atomic_read(&tcon->stats.cifs_stats.num_symlinks));
44696+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_locks),
44697+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_hardlinks),
44698+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_symlinks));
44699 seq_printf(m, "\nOpens: %d Closes: %d Deletes: %d",
44700- atomic_read(&tcon->stats.cifs_stats.num_opens),
44701- atomic_read(&tcon->stats.cifs_stats.num_closes),
44702- atomic_read(&tcon->stats.cifs_stats.num_deletes));
44703+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_opens),
44704+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_closes),
44705+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_deletes));
44706 seq_printf(m, "\nPosix Opens: %d Posix Mkdirs: %d",
44707- atomic_read(&tcon->stats.cifs_stats.num_posixopens),
44708- atomic_read(&tcon->stats.cifs_stats.num_posixmkdirs));
44709+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_posixopens),
44710+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_posixmkdirs));
44711 seq_printf(m, "\nMkdirs: %d Rmdirs: %d",
44712- atomic_read(&tcon->stats.cifs_stats.num_mkdirs),
44713- atomic_read(&tcon->stats.cifs_stats.num_rmdirs));
44714+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_mkdirs),
44715+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_rmdirs));
44716 seq_printf(m, "\nRenames: %d T2 Renames %d",
44717- atomic_read(&tcon->stats.cifs_stats.num_renames),
44718- atomic_read(&tcon->stats.cifs_stats.num_t2renames));
44719+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_renames),
44720+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_t2renames));
44721 seq_printf(m, "\nFindFirst: %d FNext %d FClose %d",
44722- atomic_read(&tcon->stats.cifs_stats.num_ffirst),
44723- atomic_read(&tcon->stats.cifs_stats.num_fnext),
44724- atomic_read(&tcon->stats.cifs_stats.num_fclose));
44725+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_ffirst),
44726+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_fnext),
44727+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_fclose));
44728 #endif
44729 }
44730
44731diff --git a/fs/cifs/smb2ops.c b/fs/cifs/smb2ops.c
44732index 826209b..fa460f4 100644
44733--- a/fs/cifs/smb2ops.c
44734+++ b/fs/cifs/smb2ops.c
44735@@ -219,8 +219,8 @@ smb2_clear_stats(struct cifs_tcon *tcon)
44736 #ifdef CONFIG_CIFS_STATS
44737 int i;
44738 for (i = 0; i < NUMBER_OF_SMB2_COMMANDS; i++) {
44739- atomic_set(&tcon->stats.smb2_stats.smb2_com_sent[i], 0);
44740- atomic_set(&tcon->stats.smb2_stats.smb2_com_failed[i], 0);
44741+ atomic_set_unchecked(&tcon->stats.smb2_stats.smb2_com_sent[i], 0);
44742+ atomic_set_unchecked(&tcon->stats.smb2_stats.smb2_com_failed[i], 0);
44743 }
44744 #endif
44745 }
44746@@ -229,66 +229,66 @@ static void
44747 smb2_print_stats(struct seq_file *m, struct cifs_tcon *tcon)
44748 {
44749 #ifdef CONFIG_CIFS_STATS
44750- atomic_t *sent = tcon->stats.smb2_stats.smb2_com_sent;
44751- atomic_t *failed = tcon->stats.smb2_stats.smb2_com_failed;
44752+ atomic_unchecked_t *sent = tcon->stats.smb2_stats.smb2_com_sent;
44753+ atomic_unchecked_t *failed = tcon->stats.smb2_stats.smb2_com_failed;
44754 seq_printf(m, "\nNegotiates: %d sent %d failed",
44755- atomic_read(&sent[SMB2_NEGOTIATE_HE]),
44756- atomic_read(&failed[SMB2_NEGOTIATE_HE]));
44757+ atomic_read_unchecked(&sent[SMB2_NEGOTIATE_HE]),
44758+ atomic_read_unchecked(&failed[SMB2_NEGOTIATE_HE]));
44759 seq_printf(m, "\nSessionSetups: %d sent %d failed",
44760- atomic_read(&sent[SMB2_SESSION_SETUP_HE]),
44761- atomic_read(&failed[SMB2_SESSION_SETUP_HE]));
44762+ atomic_read_unchecked(&sent[SMB2_SESSION_SETUP_HE]),
44763+ atomic_read_unchecked(&failed[SMB2_SESSION_SETUP_HE]));
44764 #define SMB2LOGOFF 0x0002 /* trivial request/resp */
44765 seq_printf(m, "\nLogoffs: %d sent %d failed",
44766- atomic_read(&sent[SMB2_LOGOFF_HE]),
44767- atomic_read(&failed[SMB2_LOGOFF_HE]));
44768+ atomic_read_unchecked(&sent[SMB2_LOGOFF_HE]),
44769+ atomic_read_unchecked(&failed[SMB2_LOGOFF_HE]));
44770 seq_printf(m, "\nTreeConnects: %d sent %d failed",
44771- atomic_read(&sent[SMB2_TREE_CONNECT_HE]),
44772- atomic_read(&failed[SMB2_TREE_CONNECT_HE]));
44773+ atomic_read_unchecked(&sent[SMB2_TREE_CONNECT_HE]),
44774+ atomic_read_unchecked(&failed[SMB2_TREE_CONNECT_HE]));
44775 seq_printf(m, "\nTreeDisconnects: %d sent %d failed",
44776- atomic_read(&sent[SMB2_TREE_DISCONNECT_HE]),
44777- atomic_read(&failed[SMB2_TREE_DISCONNECT_HE]));
44778+ atomic_read_unchecked(&sent[SMB2_TREE_DISCONNECT_HE]),
44779+ atomic_read_unchecked(&failed[SMB2_TREE_DISCONNECT_HE]));
44780 seq_printf(m, "\nCreates: %d sent %d failed",
44781- atomic_read(&sent[SMB2_CREATE_HE]),
44782- atomic_read(&failed[SMB2_CREATE_HE]));
44783+ atomic_read_unchecked(&sent[SMB2_CREATE_HE]),
44784+ atomic_read_unchecked(&failed[SMB2_CREATE_HE]));
44785 seq_printf(m, "\nCloses: %d sent %d failed",
44786- atomic_read(&sent[SMB2_CLOSE_HE]),
44787- atomic_read(&failed[SMB2_CLOSE_HE]));
44788+ atomic_read_unchecked(&sent[SMB2_CLOSE_HE]),
44789+ atomic_read_unchecked(&failed[SMB2_CLOSE_HE]));
44790 seq_printf(m, "\nFlushes: %d sent %d failed",
44791- atomic_read(&sent[SMB2_FLUSH_HE]),
44792- atomic_read(&failed[SMB2_FLUSH_HE]));
44793+ atomic_read_unchecked(&sent[SMB2_FLUSH_HE]),
44794+ atomic_read_unchecked(&failed[SMB2_FLUSH_HE]));
44795 seq_printf(m, "\nReads: %d sent %d failed",
44796- atomic_read(&sent[SMB2_READ_HE]),
44797- atomic_read(&failed[SMB2_READ_HE]));
44798+ atomic_read_unchecked(&sent[SMB2_READ_HE]),
44799+ atomic_read_unchecked(&failed[SMB2_READ_HE]));
44800 seq_printf(m, "\nWrites: %d sent %d failed",
44801- atomic_read(&sent[SMB2_WRITE_HE]),
44802- atomic_read(&failed[SMB2_WRITE_HE]));
44803+ atomic_read_unchecked(&sent[SMB2_WRITE_HE]),
44804+ atomic_read_unchecked(&failed[SMB2_WRITE_HE]));
44805 seq_printf(m, "\nLocks: %d sent %d failed",
44806- atomic_read(&sent[SMB2_LOCK_HE]),
44807- atomic_read(&failed[SMB2_LOCK_HE]));
44808+ atomic_read_unchecked(&sent[SMB2_LOCK_HE]),
44809+ atomic_read_unchecked(&failed[SMB2_LOCK_HE]));
44810 seq_printf(m, "\nIOCTLs: %d sent %d failed",
44811- atomic_read(&sent[SMB2_IOCTL_HE]),
44812- atomic_read(&failed[SMB2_IOCTL_HE]));
44813+ atomic_read_unchecked(&sent[SMB2_IOCTL_HE]),
44814+ atomic_read_unchecked(&failed[SMB2_IOCTL_HE]));
44815 seq_printf(m, "\nCancels: %d sent %d failed",
44816- atomic_read(&sent[SMB2_CANCEL_HE]),
44817- atomic_read(&failed[SMB2_CANCEL_HE]));
44818+ atomic_read_unchecked(&sent[SMB2_CANCEL_HE]),
44819+ atomic_read_unchecked(&failed[SMB2_CANCEL_HE]));
44820 seq_printf(m, "\nEchos: %d sent %d failed",
44821- atomic_read(&sent[SMB2_ECHO_HE]),
44822- atomic_read(&failed[SMB2_ECHO_HE]));
44823+ atomic_read_unchecked(&sent[SMB2_ECHO_HE]),
44824+ atomic_read_unchecked(&failed[SMB2_ECHO_HE]));
44825 seq_printf(m, "\nQueryDirectories: %d sent %d failed",
44826- atomic_read(&sent[SMB2_QUERY_DIRECTORY_HE]),
44827- atomic_read(&failed[SMB2_QUERY_DIRECTORY_HE]));
44828+ atomic_read_unchecked(&sent[SMB2_QUERY_DIRECTORY_HE]),
44829+ atomic_read_unchecked(&failed[SMB2_QUERY_DIRECTORY_HE]));
44830 seq_printf(m, "\nChangeNotifies: %d sent %d failed",
44831- atomic_read(&sent[SMB2_CHANGE_NOTIFY_HE]),
44832- atomic_read(&failed[SMB2_CHANGE_NOTIFY_HE]));
44833+ atomic_read_unchecked(&sent[SMB2_CHANGE_NOTIFY_HE]),
44834+ atomic_read_unchecked(&failed[SMB2_CHANGE_NOTIFY_HE]));
44835 seq_printf(m, "\nQueryInfos: %d sent %d failed",
44836- atomic_read(&sent[SMB2_QUERY_INFO_HE]),
44837- atomic_read(&failed[SMB2_QUERY_INFO_HE]));
44838+ atomic_read_unchecked(&sent[SMB2_QUERY_INFO_HE]),
44839+ atomic_read_unchecked(&failed[SMB2_QUERY_INFO_HE]));
44840 seq_printf(m, "\nSetInfos: %d sent %d failed",
44841- atomic_read(&sent[SMB2_SET_INFO_HE]),
44842- atomic_read(&failed[SMB2_SET_INFO_HE]));
44843+ atomic_read_unchecked(&sent[SMB2_SET_INFO_HE]),
44844+ atomic_read_unchecked(&failed[SMB2_SET_INFO_HE]));
44845 seq_printf(m, "\nOplockBreaks: %d sent %d failed",
44846- atomic_read(&sent[SMB2_OPLOCK_BREAK_HE]),
44847- atomic_read(&failed[SMB2_OPLOCK_BREAK_HE]));
44848+ atomic_read_unchecked(&sent[SMB2_OPLOCK_BREAK_HE]),
44849+ atomic_read_unchecked(&failed[SMB2_OPLOCK_BREAK_HE]));
44850 #endif
44851 }
44852
44853diff --git a/fs/coda/cache.c b/fs/coda/cache.c
44854index 958ae0e..505c9d0 100644
44855--- a/fs/coda/cache.c
44856+++ b/fs/coda/cache.c
44857@@ -24,7 +24,7 @@
44858 #include "coda_linux.h"
44859 #include "coda_cache.h"
44860
44861-static atomic_t permission_epoch = ATOMIC_INIT(0);
44862+static atomic_unchecked_t permission_epoch = ATOMIC_INIT(0);
44863
44864 /* replace or extend an acl cache hit */
44865 void coda_cache_enter(struct inode *inode, int mask)
44866@@ -32,7 +32,7 @@ void coda_cache_enter(struct inode *inode, int mask)
44867 struct coda_inode_info *cii = ITOC(inode);
44868
44869 spin_lock(&cii->c_lock);
44870- cii->c_cached_epoch = atomic_read(&permission_epoch);
44871+ cii->c_cached_epoch = atomic_read_unchecked(&permission_epoch);
44872 if (cii->c_uid != current_fsuid()) {
44873 cii->c_uid = current_fsuid();
44874 cii->c_cached_perm = mask;
44875@@ -46,14 +46,14 @@ void coda_cache_clear_inode(struct inode *inode)
44876 {
44877 struct coda_inode_info *cii = ITOC(inode);
44878 spin_lock(&cii->c_lock);
44879- cii->c_cached_epoch = atomic_read(&permission_epoch) - 1;
44880+ cii->c_cached_epoch = atomic_read_unchecked(&permission_epoch) - 1;
44881 spin_unlock(&cii->c_lock);
44882 }
44883
44884 /* remove all acl caches */
44885 void coda_cache_clear_all(struct super_block *sb)
44886 {
44887- atomic_inc(&permission_epoch);
44888+ atomic_inc_unchecked(&permission_epoch);
44889 }
44890
44891
44892@@ -66,7 +66,7 @@ int coda_cache_check(struct inode *inode, int mask)
44893 spin_lock(&cii->c_lock);
44894 hit = (mask & cii->c_cached_perm) == mask &&
44895 cii->c_uid == current_fsuid() &&
44896- cii->c_cached_epoch == atomic_read(&permission_epoch);
44897+ cii->c_cached_epoch == atomic_read_unchecked(&permission_epoch);
44898 spin_unlock(&cii->c_lock);
44899
44900 return hit;
44901diff --git a/fs/compat.c b/fs/compat.c
44902index 1bdb350..9f28287 100644
44903--- a/fs/compat.c
44904+++ b/fs/compat.c
44905@@ -490,7 +490,7 @@ compat_sys_io_setup(unsigned nr_reqs, u32 __user *ctx32p)
44906
44907 set_fs(KERNEL_DS);
44908 /* The __user pointer cast is valid because of the set_fs() */
44909- ret = sys_io_setup(nr_reqs, (aio_context_t __user *) &ctx64);
44910+ ret = sys_io_setup(nr_reqs, (aio_context_t __force_user *) &ctx64);
44911 set_fs(oldfs);
44912 /* truncating is ok because it's a user address */
44913 if (!ret)
44914@@ -548,7 +548,7 @@ ssize_t compat_rw_copy_check_uvector(int type,
44915 goto out;
44916
44917 ret = -EINVAL;
44918- if (nr_segs > UIO_MAXIOV || nr_segs < 0)
44919+ if (nr_segs > UIO_MAXIOV)
44920 goto out;
44921 if (nr_segs > fast_segs) {
44922 ret = -ENOMEM;
44923@@ -831,6 +831,7 @@ struct compat_old_linux_dirent {
44924
44925 struct compat_readdir_callback {
44926 struct compat_old_linux_dirent __user *dirent;
44927+ struct file * file;
44928 int result;
44929 };
44930
44931@@ -848,6 +849,10 @@ static int compat_fillonedir(void *__buf, const char *name, int namlen,
44932 buf->result = -EOVERFLOW;
44933 return -EOVERFLOW;
44934 }
44935+
44936+ if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
44937+ return 0;
44938+
44939 buf->result++;
44940 dirent = buf->dirent;
44941 if (!access_ok(VERIFY_WRITE, dirent,
44942@@ -880,6 +885,7 @@ asmlinkage long compat_sys_old_readdir(unsigned int fd,
44943
44944 buf.result = 0;
44945 buf.dirent = dirent;
44946+ buf.file = file;
44947
44948 error = vfs_readdir(file, compat_fillonedir, &buf);
44949 if (buf.result)
44950@@ -899,6 +905,7 @@ struct compat_linux_dirent {
44951 struct compat_getdents_callback {
44952 struct compat_linux_dirent __user *current_dir;
44953 struct compat_linux_dirent __user *previous;
44954+ struct file * file;
44955 int count;
44956 int error;
44957 };
44958@@ -920,6 +927,10 @@ static int compat_filldir(void *__buf, const char *name, int namlen,
44959 buf->error = -EOVERFLOW;
44960 return -EOVERFLOW;
44961 }
44962+
44963+ if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
44964+ return 0;
44965+
44966 dirent = buf->previous;
44967 if (dirent) {
44968 if (__put_user(offset, &dirent->d_off))
44969@@ -966,6 +977,7 @@ asmlinkage long compat_sys_getdents(unsigned int fd,
44970 buf.previous = NULL;
44971 buf.count = count;
44972 buf.error = 0;
44973+ buf.file = file;
44974
44975 error = vfs_readdir(file, compat_filldir, &buf);
44976 if (error >= 0)
44977@@ -986,6 +998,7 @@ asmlinkage long compat_sys_getdents(unsigned int fd,
44978 struct compat_getdents_callback64 {
44979 struct linux_dirent64 __user *current_dir;
44980 struct linux_dirent64 __user *previous;
44981+ struct file * file;
44982 int count;
44983 int error;
44984 };
44985@@ -1002,6 +1015,10 @@ static int compat_filldir64(void * __buf, const char * name, int namlen, loff_t
44986 buf->error = -EINVAL; /* only used if we fail.. */
44987 if (reclen > buf->count)
44988 return -EINVAL;
44989+
44990+ if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
44991+ return 0;
44992+
44993 dirent = buf->previous;
44994
44995 if (dirent) {
44996@@ -1052,13 +1069,14 @@ asmlinkage long compat_sys_getdents64(unsigned int fd,
44997 buf.previous = NULL;
44998 buf.count = count;
44999 buf.error = 0;
45000+ buf.file = file;
45001
45002 error = vfs_readdir(file, compat_filldir64, &buf);
45003 if (error >= 0)
45004 error = buf.error;
45005 lastdirent = buf.previous;
45006 if (lastdirent) {
45007- typeof(lastdirent->d_off) d_off = file->f_pos;
45008+ typeof(((struct linux_dirent64 *)0)->d_off) d_off = file->f_pos;
45009 if (__put_user_unaligned(d_off, &lastdirent->d_off))
45010 error = -EFAULT;
45011 else
45012diff --git a/fs/compat_binfmt_elf.c b/fs/compat_binfmt_elf.c
45013index 112e45a..b59845b 100644
45014--- a/fs/compat_binfmt_elf.c
45015+++ b/fs/compat_binfmt_elf.c
45016@@ -30,11 +30,13 @@
45017 #undef elf_phdr
45018 #undef elf_shdr
45019 #undef elf_note
45020+#undef elf_dyn
45021 #undef elf_addr_t
45022 #define elfhdr elf32_hdr
45023 #define elf_phdr elf32_phdr
45024 #define elf_shdr elf32_shdr
45025 #define elf_note elf32_note
45026+#define elf_dyn Elf32_Dyn
45027 #define elf_addr_t Elf32_Addr
45028
45029 /*
45030diff --git a/fs/compat_ioctl.c b/fs/compat_ioctl.c
45031index 5d2069f..75d31d4 100644
45032--- a/fs/compat_ioctl.c
45033+++ b/fs/compat_ioctl.c
45034@@ -623,7 +623,7 @@ static int serial_struct_ioctl(unsigned fd, unsigned cmd,
45035 return -EFAULT;
45036 if (__get_user(udata, &ss32->iomem_base))
45037 return -EFAULT;
45038- ss.iomem_base = compat_ptr(udata);
45039+ ss.iomem_base = (unsigned char __force_kernel *)compat_ptr(udata);
45040 if (__get_user(ss.iomem_reg_shift, &ss32->iomem_reg_shift) ||
45041 __get_user(ss.port_high, &ss32->port_high))
45042 return -EFAULT;
45043@@ -798,7 +798,7 @@ static int compat_ioctl_preallocate(struct file *file,
45044 copy_in_user(&p->l_len, &p32->l_len, sizeof(s64)) ||
45045 copy_in_user(&p->l_sysid, &p32->l_sysid, sizeof(s32)) ||
45046 copy_in_user(&p->l_pid, &p32->l_pid, sizeof(u32)) ||
45047- copy_in_user(&p->l_pad, &p32->l_pad, 4*sizeof(u32)))
45048+ copy_in_user(p->l_pad, &p32->l_pad, 4*sizeof(u32)))
45049 return -EFAULT;
45050
45051 return ioctl_preallocate(file, p);
45052@@ -1612,8 +1612,8 @@ asmlinkage long compat_sys_ioctl(unsigned int fd, unsigned int cmd,
45053 static int __init init_sys32_ioctl_cmp(const void *p, const void *q)
45054 {
45055 unsigned int a, b;
45056- a = *(unsigned int *)p;
45057- b = *(unsigned int *)q;
45058+ a = *(const unsigned int *)p;
45059+ b = *(const unsigned int *)q;
45060 if (a > b)
45061 return 1;
45062 if (a < b)
45063diff --git a/fs/configfs/dir.c b/fs/configfs/dir.c
45064index 7414ae2..d98ad6d 100644
45065--- a/fs/configfs/dir.c
45066+++ b/fs/configfs/dir.c
45067@@ -1564,7 +1564,8 @@ static int configfs_readdir(struct file * filp, void * dirent, filldir_t filldir
45068 }
45069 for (p=q->next; p!= &parent_sd->s_children; p=p->next) {
45070 struct configfs_dirent *next;
45071- const char * name;
45072+ const unsigned char * name;
45073+ char d_name[sizeof(next->s_dentry->d_iname)];
45074 int len;
45075 struct inode *inode = NULL;
45076
45077@@ -1574,7 +1575,12 @@ static int configfs_readdir(struct file * filp, void * dirent, filldir_t filldir
45078 continue;
45079
45080 name = configfs_get_name(next);
45081- len = strlen(name);
45082+ if (next->s_dentry && name == next->s_dentry->d_iname) {
45083+ len = next->s_dentry->d_name.len;
45084+ memcpy(d_name, name, len);
45085+ name = d_name;
45086+ } else
45087+ len = strlen(name);
45088
45089 /*
45090 * We'll have a dentry and an inode for
45091diff --git a/fs/dcache.c b/fs/dcache.c
45092index 693f95b..95f1223 100644
45093--- a/fs/dcache.c
45094+++ b/fs/dcache.c
45095@@ -3164,7 +3164,7 @@ void __init vfs_caches_init(unsigned long mempages)
45096 mempages -= reserve;
45097
45098 names_cachep = kmem_cache_create("names_cache", PATH_MAX, 0,
45099- SLAB_HWCACHE_ALIGN|SLAB_PANIC, NULL);
45100+ SLAB_HWCACHE_ALIGN|SLAB_PANIC|SLAB_USERCOPY, NULL);
45101
45102 dcache_init();
45103 inode_init();
45104diff --git a/fs/debugfs/inode.c b/fs/debugfs/inode.c
45105index 4733eab..71ef6fa 100644
45106--- a/fs/debugfs/inode.c
45107+++ b/fs/debugfs/inode.c
45108@@ -406,7 +406,11 @@ EXPORT_SYMBOL_GPL(debugfs_create_file);
45109 */
45110 struct dentry *debugfs_create_dir(const char *name, struct dentry *parent)
45111 {
45112+#ifdef CONFIG_GRKERNSEC_SYSFS_RESTRICT
45113+ return __create_file(name, S_IFDIR | S_IRWXU,
45114+#else
45115 return __create_file(name, S_IFDIR | S_IRWXU | S_IRUGO | S_IXUGO,
45116+#endif
45117 parent, NULL, NULL);
45118 }
45119 EXPORT_SYMBOL_GPL(debugfs_create_dir);
45120diff --git a/fs/ecryptfs/inode.c b/fs/ecryptfs/inode.c
45121index cc7709e..7e7211f 100644
45122--- a/fs/ecryptfs/inode.c
45123+++ b/fs/ecryptfs/inode.c
45124@@ -674,7 +674,7 @@ static int ecryptfs_readlink_lower(struct dentry *dentry, char **buf,
45125 old_fs = get_fs();
45126 set_fs(get_ds());
45127 rc = lower_dentry->d_inode->i_op->readlink(lower_dentry,
45128- (char __user *)lower_buf,
45129+ (char __force_user *)lower_buf,
45130 PATH_MAX);
45131 set_fs(old_fs);
45132 if (rc < 0)
45133@@ -706,7 +706,7 @@ out:
45134 static void
45135 ecryptfs_put_link(struct dentry *dentry, struct nameidata *nd, void *ptr)
45136 {
45137- char *buf = nd_get_link(nd);
45138+ const char *buf = nd_get_link(nd);
45139 if (!IS_ERR(buf)) {
45140 /* Free the char* */
45141 kfree(buf);
45142diff --git a/fs/ecryptfs/miscdev.c b/fs/ecryptfs/miscdev.c
45143index 412e6ed..4292d22 100644
45144--- a/fs/ecryptfs/miscdev.c
45145+++ b/fs/ecryptfs/miscdev.c
45146@@ -315,7 +315,7 @@ check_list:
45147 goto out_unlock_msg_ctx;
45148 i = PKT_TYPE_SIZE + PKT_CTR_SIZE;
45149 if (msg_ctx->msg) {
45150- if (copy_to_user(&buf[i], packet_length, packet_length_size))
45151+ if (packet_length_size > sizeof(packet_length) || copy_to_user(&buf[i], packet_length, packet_length_size))
45152 goto out_unlock_msg_ctx;
45153 i += packet_length_size;
45154 if (copy_to_user(&buf[i], msg_ctx->msg, msg_ctx->msg_size))
45155diff --git a/fs/ecryptfs/read_write.c b/fs/ecryptfs/read_write.c
45156index b2a34a1..162fa69 100644
45157--- a/fs/ecryptfs/read_write.c
45158+++ b/fs/ecryptfs/read_write.c
45159@@ -48,7 +48,7 @@ int ecryptfs_write_lower(struct inode *ecryptfs_inode, char *data,
45160 return -EIO;
45161 fs_save = get_fs();
45162 set_fs(get_ds());
45163- rc = vfs_write(lower_file, data, size, &offset);
45164+ rc = vfs_write(lower_file, (const char __force_user *)data, size, &offset);
45165 set_fs(fs_save);
45166 mark_inode_dirty_sync(ecryptfs_inode);
45167 return rc;
45168@@ -244,7 +244,7 @@ int ecryptfs_read_lower(char *data, loff_t offset, size_t size,
45169 return -EIO;
45170 fs_save = get_fs();
45171 set_fs(get_ds());
45172- rc = vfs_read(lower_file, data, size, &offset);
45173+ rc = vfs_read(lower_file, (char __force_user *)data, size, &offset);
45174 set_fs(fs_save);
45175 return rc;
45176 }
45177diff --git a/fs/exec.c b/fs/exec.c
45178index fab2c6d..6a13dff 100644
45179--- a/fs/exec.c
45180+++ b/fs/exec.c
45181@@ -55,6 +55,15 @@
45182 #include <linux/pipe_fs_i.h>
45183 #include <linux/oom.h>
45184 #include <linux/compat.h>
45185+#include <linux/random.h>
45186+#include <linux/seq_file.h>
45187+
45188+#ifdef CONFIG_PAX_REFCOUNT
45189+#include <linux/kallsyms.h>
45190+#include <linux/kdebug.h>
45191+#endif
45192+
45193+#include <trace/events/fs.h>
45194
45195 #include <asm/uaccess.h>
45196 #include <asm/mmu_context.h>
45197@@ -66,6 +75,18 @@
45198
45199 #include <trace/events/sched.h>
45200
45201+#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
45202+void __weak pax_set_initial_flags(struct linux_binprm *bprm)
45203+{
45204+ pr_warn_once("PAX: PAX_HAVE_ACL_FLAGS was enabled without providing the pax_set_initial_flags callback, this is probably not what you wanted.\n");
45205+}
45206+#endif
45207+
45208+#ifdef CONFIG_PAX_HOOK_ACL_FLAGS
45209+void (*pax_set_initial_flags_func)(struct linux_binprm *bprm);
45210+EXPORT_SYMBOL(pax_set_initial_flags_func);
45211+#endif
45212+
45213 int core_uses_pid;
45214 char core_pattern[CORENAME_MAX_SIZE] = "core";
45215 unsigned int core_pipe_limit;
45216@@ -75,7 +96,7 @@ struct core_name {
45217 char *corename;
45218 int used, size;
45219 };
45220-static atomic_t call_count = ATOMIC_INIT(1);
45221+static atomic_unchecked_t call_count = ATOMIC_INIT(1);
45222
45223 /* The maximal length of core_pattern is also specified in sysctl.c */
45224
45225@@ -191,18 +212,10 @@ static struct page *get_arg_page(struct linux_binprm *bprm, unsigned long pos,
45226 int write)
45227 {
45228 struct page *page;
45229- int ret;
45230
45231-#ifdef CONFIG_STACK_GROWSUP
45232- if (write) {
45233- ret = expand_downwards(bprm->vma, pos);
45234- if (ret < 0)
45235- return NULL;
45236- }
45237-#endif
45238- ret = get_user_pages(current, bprm->mm, pos,
45239- 1, write, 1, &page, NULL);
45240- if (ret <= 0)
45241+ if (0 > expand_downwards(bprm->vma, pos))
45242+ return NULL;
45243+ if (0 >= get_user_pages(current, bprm->mm, pos, 1, write, 1, &page, NULL))
45244 return NULL;
45245
45246 if (write) {
45247@@ -218,6 +231,17 @@ static struct page *get_arg_page(struct linux_binprm *bprm, unsigned long pos,
45248 if (size <= ARG_MAX)
45249 return page;
45250
45251+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
45252+ // only allow 512KB for argv+env on suid/sgid binaries
45253+ // to prevent easy ASLR exhaustion
45254+ if (((bprm->cred->euid != current_euid()) ||
45255+ (bprm->cred->egid != current_egid())) &&
45256+ (size > (512 * 1024))) {
45257+ put_page(page);
45258+ return NULL;
45259+ }
45260+#endif
45261+
45262 /*
45263 * Limit to 1/4-th the stack size for the argv+env strings.
45264 * This ensures that:
45265@@ -277,6 +301,11 @@ static int __bprm_mm_init(struct linux_binprm *bprm)
45266 vma->vm_end = STACK_TOP_MAX;
45267 vma->vm_start = vma->vm_end - PAGE_SIZE;
45268 vma->vm_flags = VM_STACK_FLAGS | VM_STACK_INCOMPLETE_SETUP;
45269+
45270+#ifdef CONFIG_PAX_SEGMEXEC
45271+ vma->vm_flags &= ~(VM_EXEC | VM_MAYEXEC);
45272+#endif
45273+
45274 vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
45275 INIT_LIST_HEAD(&vma->anon_vma_chain);
45276
45277@@ -287,6 +316,12 @@ static int __bprm_mm_init(struct linux_binprm *bprm)
45278 mm->stack_vm = mm->total_vm = 1;
45279 up_write(&mm->mmap_sem);
45280 bprm->p = vma->vm_end - sizeof(void *);
45281+
45282+#ifdef CONFIG_PAX_RANDUSTACK
45283+ if (randomize_va_space)
45284+ bprm->p ^= random32() & ~PAGE_MASK;
45285+#endif
45286+
45287 return 0;
45288 err:
45289 up_write(&mm->mmap_sem);
45290@@ -395,19 +430,7 @@ err:
45291 return err;
45292 }
45293
45294-struct user_arg_ptr {
45295-#ifdef CONFIG_COMPAT
45296- bool is_compat;
45297-#endif
45298- union {
45299- const char __user *const __user *native;
45300-#ifdef CONFIG_COMPAT
45301- compat_uptr_t __user *compat;
45302-#endif
45303- } ptr;
45304-};
45305-
45306-static const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr)
45307+const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr)
45308 {
45309 const char __user *native;
45310
45311@@ -416,14 +439,14 @@ static const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr)
45312 compat_uptr_t compat;
45313
45314 if (get_user(compat, argv.ptr.compat + nr))
45315- return ERR_PTR(-EFAULT);
45316+ return (const char __force_user *)ERR_PTR(-EFAULT);
45317
45318 return compat_ptr(compat);
45319 }
45320 #endif
45321
45322 if (get_user(native, argv.ptr.native + nr))
45323- return ERR_PTR(-EFAULT);
45324+ return (const char __force_user *)ERR_PTR(-EFAULT);
45325
45326 return native;
45327 }
45328@@ -442,7 +465,7 @@ static int count(struct user_arg_ptr argv, int max)
45329 if (!p)
45330 break;
45331
45332- if (IS_ERR(p))
45333+ if (IS_ERR((const char __force_kernel *)p))
45334 return -EFAULT;
45335
45336 if (i++ >= max)
45337@@ -476,7 +499,7 @@ static int copy_strings(int argc, struct user_arg_ptr argv,
45338
45339 ret = -EFAULT;
45340 str = get_user_arg_ptr(argv, argc);
45341- if (IS_ERR(str))
45342+ if (IS_ERR((const char __force_kernel *)str))
45343 goto out;
45344
45345 len = strnlen_user(str, MAX_ARG_STRLEN);
45346@@ -558,7 +581,7 @@ int copy_strings_kernel(int argc, const char *const *__argv,
45347 int r;
45348 mm_segment_t oldfs = get_fs();
45349 struct user_arg_ptr argv = {
45350- .ptr.native = (const char __user *const __user *)__argv,
45351+ .ptr.native = (const char __force_user *const __force_user *)__argv,
45352 };
45353
45354 set_fs(KERNEL_DS);
45355@@ -593,7 +616,8 @@ static int shift_arg_pages(struct vm_area_struct *vma, unsigned long shift)
45356 unsigned long new_end = old_end - shift;
45357 struct mmu_gather tlb;
45358
45359- BUG_ON(new_start > new_end);
45360+ if (new_start >= new_end || new_start < mmap_min_addr)
45361+ return -ENOMEM;
45362
45363 /*
45364 * ensure there are no vmas between where we want to go
45365@@ -602,6 +626,10 @@ static int shift_arg_pages(struct vm_area_struct *vma, unsigned long shift)
45366 if (vma != find_vma(mm, new_start))
45367 return -EFAULT;
45368
45369+#ifdef CONFIG_PAX_SEGMEXEC
45370+ BUG_ON(pax_find_mirror_vma(vma));
45371+#endif
45372+
45373 /*
45374 * cover the whole range: [new_start, old_end)
45375 */
45376@@ -682,10 +710,6 @@ int setup_arg_pages(struct linux_binprm *bprm,
45377 stack_top = arch_align_stack(stack_top);
45378 stack_top = PAGE_ALIGN(stack_top);
45379
45380- if (unlikely(stack_top < mmap_min_addr) ||
45381- unlikely(vma->vm_end - vma->vm_start >= stack_top - mmap_min_addr))
45382- return -ENOMEM;
45383-
45384 stack_shift = vma->vm_end - stack_top;
45385
45386 bprm->p -= stack_shift;
45387@@ -697,8 +721,28 @@ int setup_arg_pages(struct linux_binprm *bprm,
45388 bprm->exec -= stack_shift;
45389
45390 down_write(&mm->mmap_sem);
45391+
45392+ /* Move stack pages down in memory. */
45393+ if (stack_shift) {
45394+ ret = shift_arg_pages(vma, stack_shift);
45395+ if (ret)
45396+ goto out_unlock;
45397+ }
45398+
45399 vm_flags = VM_STACK_FLAGS;
45400
45401+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
45402+ if (mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
45403+ vm_flags &= ~VM_EXEC;
45404+
45405+#ifdef CONFIG_PAX_MPROTECT
45406+ if (mm->pax_flags & MF_PAX_MPROTECT)
45407+ vm_flags &= ~VM_MAYEXEC;
45408+#endif
45409+
45410+ }
45411+#endif
45412+
45413 /*
45414 * Adjust stack execute permissions; explicitly enable for
45415 * EXSTACK_ENABLE_X, disable for EXSTACK_DISABLE_X and leave alone
45416@@ -717,13 +761,6 @@ int setup_arg_pages(struct linux_binprm *bprm,
45417 goto out_unlock;
45418 BUG_ON(prev != vma);
45419
45420- /* Move stack pages down in memory. */
45421- if (stack_shift) {
45422- ret = shift_arg_pages(vma, stack_shift);
45423- if (ret)
45424- goto out_unlock;
45425- }
45426-
45427 /* mprotect_fixup is overkill to remove the temporary stack flags */
45428 vma->vm_flags &= ~VM_STACK_INCOMPLETE_SETUP;
45429
45430@@ -781,6 +818,8 @@ struct file *open_exec(const char *name)
45431
45432 fsnotify_open(file);
45433
45434+ trace_open_exec(name);
45435+
45436 err = deny_write_access(file);
45437 if (err)
45438 goto exit;
45439@@ -804,7 +843,7 @@ int kernel_read(struct file *file, loff_t offset,
45440 old_fs = get_fs();
45441 set_fs(get_ds());
45442 /* The cast to a user pointer is valid due to the set_fs() */
45443- result = vfs_read(file, (void __user *)addr, count, &pos);
45444+ result = vfs_read(file, (void __force_user *)addr, count, &pos);
45445 set_fs(old_fs);
45446 return result;
45447 }
45448@@ -1258,7 +1297,7 @@ static int check_unsafe_exec(struct linux_binprm *bprm)
45449 }
45450 rcu_read_unlock();
45451
45452- if (p->fs->users > n_fs) {
45453+ if (atomic_read(&p->fs->users) > n_fs) {
45454 bprm->unsafe |= LSM_UNSAFE_SHARE;
45455 } else {
45456 res = -EAGAIN;
45457@@ -1461,6 +1500,28 @@ int search_binary_handler(struct linux_binprm *bprm,struct pt_regs *regs)
45458
45459 EXPORT_SYMBOL(search_binary_handler);
45460
45461+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
45462+static DEFINE_PER_CPU(u64, exec_counter);
45463+static int __init init_exec_counters(void)
45464+{
45465+ unsigned int cpu;
45466+
45467+ for_each_possible_cpu(cpu) {
45468+ per_cpu(exec_counter, cpu) = (u64)cpu;
45469+ }
45470+
45471+ return 0;
45472+}
45473+early_initcall(init_exec_counters);
45474+static inline void increment_exec_counter(void)
45475+{
45476+ BUILD_BUG_ON(NR_CPUS > (1 << 16));
45477+ current->exec_id = this_cpu_add_return(exec_counter, 1 << 16);
45478+}
45479+#else
45480+static inline void increment_exec_counter(void) {}
45481+#endif
45482+
45483 /*
45484 * sys_execve() executes a new program.
45485 */
45486@@ -1469,6 +1530,11 @@ static int do_execve_common(const char *filename,
45487 struct user_arg_ptr envp,
45488 struct pt_regs *regs)
45489 {
45490+#ifdef CONFIG_GRKERNSEC
45491+ struct file *old_exec_file;
45492+ struct acl_subject_label *old_acl;
45493+ struct rlimit old_rlim[RLIM_NLIMITS];
45494+#endif
45495 struct linux_binprm *bprm;
45496 struct file *file;
45497 struct files_struct *displaced;
45498@@ -1476,6 +1542,8 @@ static int do_execve_common(const char *filename,
45499 int retval;
45500 const struct cred *cred = current_cred();
45501
45502+ gr_learn_resource(current, RLIMIT_NPROC, atomic_read(&current->cred->user->processes), 1);
45503+
45504 /*
45505 * We move the actual failure in case of RLIMIT_NPROC excess from
45506 * set*uid() to execve() because too many poorly written programs
45507@@ -1516,12 +1584,27 @@ static int do_execve_common(const char *filename,
45508 if (IS_ERR(file))
45509 goto out_unmark;
45510
45511+ if (gr_ptrace_readexec(file, bprm->unsafe)) {
45512+ retval = -EPERM;
45513+ goto out_file;
45514+ }
45515+
45516 sched_exec();
45517
45518 bprm->file = file;
45519 bprm->filename = filename;
45520 bprm->interp = filename;
45521
45522+ if (gr_process_user_ban()) {
45523+ retval = -EPERM;
45524+ goto out_file;
45525+ }
45526+
45527+ if (!gr_acl_handle_execve(file->f_dentry, file->f_vfsmnt)) {
45528+ retval = -EACCES;
45529+ goto out_file;
45530+ }
45531+
45532 retval = bprm_mm_init(bprm);
45533 if (retval)
45534 goto out_file;
45535@@ -1538,24 +1621,65 @@ static int do_execve_common(const char *filename,
45536 if (retval < 0)
45537 goto out;
45538
45539+#ifdef CONFIG_GRKERNSEC
45540+ old_acl = current->acl;
45541+ memcpy(old_rlim, current->signal->rlim, sizeof(old_rlim));
45542+ old_exec_file = current->exec_file;
45543+ get_file(file);
45544+ current->exec_file = file;
45545+#endif
45546+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
45547+ /* limit suid stack to 8MB
45548+ we saved the old limits above and will restore them if this exec fails
45549+ */
45550+ if (((bprm->cred->euid != current_euid()) || (bprm->cred->egid != current_egid())) &&
45551+ (old_rlim[RLIMIT_STACK].rlim_cur > (8 * 1024 * 1024)))
45552+ current->signal->rlim[RLIMIT_STACK].rlim_cur = 8 * 1024 * 1024;
45553+#endif
45554+
45555+ if (!gr_tpe_allow(file)) {
45556+ retval = -EACCES;
45557+ goto out_fail;
45558+ }
45559+
45560+ if (gr_check_crash_exec(file)) {
45561+ retval = -EACCES;
45562+ goto out_fail;
45563+ }
45564+
45565+ retval = gr_set_proc_label(file->f_dentry, file->f_vfsmnt,
45566+ bprm->unsafe);
45567+ if (retval < 0)
45568+ goto out_fail;
45569+
45570 retval = copy_strings_kernel(1, &bprm->filename, bprm);
45571 if (retval < 0)
45572- goto out;
45573+ goto out_fail;
45574
45575 bprm->exec = bprm->p;
45576 retval = copy_strings(bprm->envc, envp, bprm);
45577 if (retval < 0)
45578- goto out;
45579+ goto out_fail;
45580
45581 retval = copy_strings(bprm->argc, argv, bprm);
45582 if (retval < 0)
45583- goto out;
45584+ goto out_fail;
45585+
45586+ gr_log_chroot_exec(file->f_dentry, file->f_vfsmnt);
45587+
45588+ gr_handle_exec_args(bprm, argv);
45589
45590 retval = search_binary_handler(bprm,regs);
45591 if (retval < 0)
45592- goto out;
45593+ goto out_fail;
45594+#ifdef CONFIG_GRKERNSEC
45595+ if (old_exec_file)
45596+ fput(old_exec_file);
45597+#endif
45598
45599 /* execve succeeded */
45600+
45601+ increment_exec_counter();
45602 current->fs->in_exec = 0;
45603 current->in_execve = 0;
45604 acct_update_integrals(current);
45605@@ -1564,6 +1688,14 @@ static int do_execve_common(const char *filename,
45606 put_files_struct(displaced);
45607 return retval;
45608
45609+out_fail:
45610+#ifdef CONFIG_GRKERNSEC
45611+ current->acl = old_acl;
45612+ memcpy(current->signal->rlim, old_rlim, sizeof(old_rlim));
45613+ fput(current->exec_file);
45614+ current->exec_file = old_exec_file;
45615+#endif
45616+
45617 out:
45618 if (bprm->mm) {
45619 acct_arg_size(bprm, 0);
45620@@ -1637,7 +1769,7 @@ static int expand_corename(struct core_name *cn)
45621 {
45622 char *old_corename = cn->corename;
45623
45624- cn->size = CORENAME_MAX_SIZE * atomic_inc_return(&call_count);
45625+ cn->size = CORENAME_MAX_SIZE * atomic_inc_return_unchecked(&call_count);
45626 cn->corename = krealloc(old_corename, cn->size, GFP_KERNEL);
45627
45628 if (!cn->corename) {
45629@@ -1734,7 +1866,7 @@ static int format_corename(struct core_name *cn, long signr)
45630 int pid_in_pattern = 0;
45631 int err = 0;
45632
45633- cn->size = CORENAME_MAX_SIZE * atomic_read(&call_count);
45634+ cn->size = CORENAME_MAX_SIZE * atomic_read_unchecked(&call_count);
45635 cn->corename = kmalloc(cn->size, GFP_KERNEL);
45636 cn->used = 0;
45637
45638@@ -1831,6 +1963,250 @@ out:
45639 return ispipe;
45640 }
45641
45642+int pax_check_flags(unsigned long *flags)
45643+{
45644+ int retval = 0;
45645+
45646+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_SEGMEXEC)
45647+ if (*flags & MF_PAX_SEGMEXEC)
45648+ {
45649+ *flags &= ~MF_PAX_SEGMEXEC;
45650+ retval = -EINVAL;
45651+ }
45652+#endif
45653+
45654+ if ((*flags & MF_PAX_PAGEEXEC)
45655+
45656+#ifdef CONFIG_PAX_PAGEEXEC
45657+ && (*flags & MF_PAX_SEGMEXEC)
45658+#endif
45659+
45660+ )
45661+ {
45662+ *flags &= ~MF_PAX_PAGEEXEC;
45663+ retval = -EINVAL;
45664+ }
45665+
45666+ if ((*flags & MF_PAX_MPROTECT)
45667+
45668+#ifdef CONFIG_PAX_MPROTECT
45669+ && !(*flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC))
45670+#endif
45671+
45672+ )
45673+ {
45674+ *flags &= ~MF_PAX_MPROTECT;
45675+ retval = -EINVAL;
45676+ }
45677+
45678+ if ((*flags & MF_PAX_EMUTRAMP)
45679+
45680+#ifdef CONFIG_PAX_EMUTRAMP
45681+ && !(*flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC))
45682+#endif
45683+
45684+ )
45685+ {
45686+ *flags &= ~MF_PAX_EMUTRAMP;
45687+ retval = -EINVAL;
45688+ }
45689+
45690+ return retval;
45691+}
45692+
45693+EXPORT_SYMBOL(pax_check_flags);
45694+
45695+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
45696+void pax_report_fault(struct pt_regs *regs, void *pc, void *sp)
45697+{
45698+ struct task_struct *tsk = current;
45699+ struct mm_struct *mm = current->mm;
45700+ char *buffer_exec = (char *)__get_free_page(GFP_KERNEL);
45701+ char *buffer_fault = (char *)__get_free_page(GFP_KERNEL);
45702+ char *path_exec = NULL;
45703+ char *path_fault = NULL;
45704+ unsigned long start = 0UL, end = 0UL, offset = 0UL;
45705+
45706+ if (buffer_exec && buffer_fault) {
45707+ struct vm_area_struct *vma, *vma_exec = NULL, *vma_fault = NULL;
45708+
45709+ down_read(&mm->mmap_sem);
45710+ vma = mm->mmap;
45711+ while (vma && (!vma_exec || !vma_fault)) {
45712+ if ((vma->vm_flags & VM_EXECUTABLE) && vma->vm_file)
45713+ vma_exec = vma;
45714+ if (vma->vm_start <= (unsigned long)pc && (unsigned long)pc < vma->vm_end)
45715+ vma_fault = vma;
45716+ vma = vma->vm_next;
45717+ }
45718+ if (vma_exec) {
45719+ path_exec = d_path(&vma_exec->vm_file->f_path, buffer_exec, PAGE_SIZE);
45720+ if (IS_ERR(path_exec))
45721+ path_exec = "<path too long>";
45722+ else {
45723+ path_exec = mangle_path(buffer_exec, path_exec, "\t\n\\");
45724+ if (path_exec) {
45725+ *path_exec = 0;
45726+ path_exec = buffer_exec;
45727+ } else
45728+ path_exec = "<path too long>";
45729+ }
45730+ }
45731+ if (vma_fault) {
45732+ start = vma_fault->vm_start;
45733+ end = vma_fault->vm_end;
45734+ offset = vma_fault->vm_pgoff << PAGE_SHIFT;
45735+ if (vma_fault->vm_file) {
45736+ path_fault = d_path(&vma_fault->vm_file->f_path, buffer_fault, PAGE_SIZE);
45737+ if (IS_ERR(path_fault))
45738+ path_fault = "<path too long>";
45739+ else {
45740+ path_fault = mangle_path(buffer_fault, path_fault, "\t\n\\");
45741+ if (path_fault) {
45742+ *path_fault = 0;
45743+ path_fault = buffer_fault;
45744+ } else
45745+ path_fault = "<path too long>";
45746+ }
45747+ } else
45748+ path_fault = "<anonymous mapping>";
45749+ }
45750+ up_read(&mm->mmap_sem);
45751+ }
45752+ if (tsk->signal->curr_ip)
45753+ printk(KERN_ERR "PAX: From %pI4: execution attempt in: %s, %08lx-%08lx %08lx\n", &tsk->signal->curr_ip, path_fault, start, end, offset);
45754+ else
45755+ printk(KERN_ERR "PAX: execution attempt in: %s, %08lx-%08lx %08lx\n", path_fault, start, end, offset);
45756+ printk(KERN_ERR "PAX: terminating task: %s(%s):%d, uid/euid: %u/%u, "
45757+ "PC: %p, SP: %p\n", path_exec, tsk->comm, task_pid_nr(tsk),
45758+ task_uid(tsk), task_euid(tsk), pc, sp);
45759+ free_page((unsigned long)buffer_exec);
45760+ free_page((unsigned long)buffer_fault);
45761+ pax_report_insns(regs, pc, sp);
45762+ do_coredump(SIGKILL, SIGKILL, regs);
45763+}
45764+#endif
45765+
45766+#ifdef CONFIG_PAX_REFCOUNT
45767+void pax_report_refcount_overflow(struct pt_regs *regs)
45768+{
45769+ if (current->signal->curr_ip)
45770+ printk(KERN_ERR "PAX: From %pI4: refcount overflow detected in: %s:%d, uid/euid: %u/%u\n",
45771+ &current->signal->curr_ip, current->comm, task_pid_nr(current), current_uid(), current_euid());
45772+ else
45773+ printk(KERN_ERR "PAX: refcount overflow detected in: %s:%d, uid/euid: %u/%u\n",
45774+ current->comm, task_pid_nr(current), current_uid(), current_euid());
45775+ print_symbol(KERN_ERR "PAX: refcount overflow occured at: %s\n", instruction_pointer(regs));
45776+ show_regs(regs);
45777+ force_sig_info(SIGKILL, SEND_SIG_FORCED, current);
45778+}
45779+#endif
45780+
45781+#ifdef CONFIG_PAX_USERCOPY
45782+/* 0: not at all, 1: fully, 2: fully inside frame, -1: partially (implies an error) */
45783+static noinline int check_stack_object(const void *obj, unsigned long len)
45784+{
45785+ const void * const stack = task_stack_page(current);
45786+ const void * const stackend = stack + THREAD_SIZE;
45787+
45788+#if defined(CONFIG_FRAME_POINTER) && defined(CONFIG_X86)
45789+ const void *frame = NULL;
45790+ const void *oldframe;
45791+#endif
45792+
45793+ if (obj + len < obj)
45794+ return -1;
45795+
45796+ if (obj + len <= stack || stackend <= obj)
45797+ return 0;
45798+
45799+ if (obj < stack || stackend < obj + len)
45800+ return -1;
45801+
45802+#if defined(CONFIG_FRAME_POINTER) && defined(CONFIG_X86)
45803+ oldframe = __builtin_frame_address(1);
45804+ if (oldframe)
45805+ frame = __builtin_frame_address(2);
45806+ /*
45807+ low ----------------------------------------------> high
45808+ [saved bp][saved ip][args][local vars][saved bp][saved ip]
45809+ ^----------------^
45810+ allow copies only within here
45811+ */
45812+ while (stack <= frame && frame < stackend) {
45813+ /* if obj + len extends past the last frame, this
45814+ check won't pass and the next frame will be 0,
45815+ causing us to bail out and correctly report
45816+ the copy as invalid
45817+ */
45818+ if (obj + len <= frame)
45819+ return obj >= oldframe + 2 * sizeof(void *) ? 2 : -1;
45820+ oldframe = frame;
45821+ frame = *(const void * const *)frame;
45822+ }
45823+ return -1;
45824+#else
45825+ return 1;
45826+#endif
45827+}
45828+
45829+static __noreturn void pax_report_usercopy(const void *ptr, unsigned long len, bool to, const char *type)
45830+{
45831+ if (current->signal->curr_ip)
45832+ printk(KERN_ERR "PAX: From %pI4: kernel memory %s attempt detected %s %p (%s) (%lu bytes)\n",
45833+ &current->signal->curr_ip, to ? "leak" : "overwrite", to ? "from" : "to", ptr, type ? : "unknown", len);
45834+ else
45835+ printk(KERN_ERR "PAX: kernel memory %s attempt detected %s %p (%s) (%lu bytes)\n",
45836+ to ? "leak" : "overwrite", to ? "from" : "to", ptr, type ? : "unknown", len);
45837+ dump_stack();
45838+ gr_handle_kernel_exploit();
45839+ do_group_exit(SIGKILL);
45840+}
45841+#endif
45842+
45843+void check_object_size(const void *ptr, unsigned long n, bool to)
45844+{
45845+
45846+#ifdef CONFIG_PAX_USERCOPY
45847+ const char *type;
45848+
45849+ if (!n)
45850+ return;
45851+
45852+ type = check_heap_object(ptr, n, to);
45853+ if (!type) {
45854+ if (check_stack_object(ptr, n) != -1)
45855+ return;
45856+ type = "<process stack>";
45857+ }
45858+
45859+ pax_report_usercopy(ptr, n, to, type);
45860+#endif
45861+
45862+}
45863+EXPORT_SYMBOL(check_object_size);
45864+
45865+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
45866+void pax_track_stack(void)
45867+{
45868+ unsigned long sp = (unsigned long)&sp;
45869+ if (sp < current_thread_info()->lowest_stack &&
45870+ sp > (unsigned long)task_stack_page(current))
45871+ current_thread_info()->lowest_stack = sp;
45872+}
45873+EXPORT_SYMBOL(pax_track_stack);
45874+#endif
45875+
45876+#ifdef CONFIG_PAX_SIZE_OVERFLOW
45877+void report_size_overflow(const char *file, unsigned int line, const char *func, const char *ssa_name)
45878+{
45879+ printk(KERN_ERR "PAX: size overflow detected in function %s %s:%u %s", func, file, line, ssa_name);
45880+ dump_stack();
45881+ do_group_exit(SIGKILL);
45882+}
45883+EXPORT_SYMBOL(report_size_overflow);
45884+#endif
45885+
45886 static int zap_process(struct task_struct *start, int exit_code)
45887 {
45888 struct task_struct *t;
45889@@ -2041,17 +2417,17 @@ static void wait_for_dump_helpers(struct file *file)
45890 pipe = file->f_path.dentry->d_inode->i_pipe;
45891
45892 pipe_lock(pipe);
45893- pipe->readers++;
45894- pipe->writers--;
45895+ atomic_inc(&pipe->readers);
45896+ atomic_dec(&pipe->writers);
45897
45898- while ((pipe->readers > 1) && (!signal_pending(current))) {
45899+ while ((atomic_read(&pipe->readers) > 1) && (!signal_pending(current))) {
45900 wake_up_interruptible_sync(&pipe->wait);
45901 kill_fasync(&pipe->fasync_readers, SIGIO, POLL_IN);
45902 pipe_wait(pipe);
45903 }
45904
45905- pipe->readers--;
45906- pipe->writers++;
45907+ atomic_dec(&pipe->readers);
45908+ atomic_inc(&pipe->writers);
45909 pipe_unlock(pipe);
45910
45911 }
45912@@ -2106,7 +2482,7 @@ void do_coredump(long signr, int exit_code, struct pt_regs *regs)
45913 int flag = 0;
45914 int ispipe;
45915 bool need_nonrelative = false;
45916- static atomic_t core_dump_count = ATOMIC_INIT(0);
45917+ static atomic_unchecked_t core_dump_count = ATOMIC_INIT(0);
45918 struct coredump_params cprm = {
45919 .signr = signr,
45920 .regs = regs,
45921@@ -2121,6 +2497,9 @@ void do_coredump(long signr, int exit_code, struct pt_regs *regs)
45922
45923 audit_core_dumps(signr);
45924
45925+ if (signr == SIGSEGV || signr == SIGBUS || signr == SIGKILL || signr == SIGILL)
45926+ gr_handle_brute_attach(current, cprm.mm_flags);
45927+
45928 binfmt = mm->binfmt;
45929 if (!binfmt || !binfmt->core_dump)
45930 goto fail;
45931@@ -2191,7 +2570,7 @@ void do_coredump(long signr, int exit_code, struct pt_regs *regs)
45932 }
45933 cprm.limit = RLIM_INFINITY;
45934
45935- dump_count = atomic_inc_return(&core_dump_count);
45936+ dump_count = atomic_inc_return_unchecked(&core_dump_count);
45937 if (core_pipe_limit && (core_pipe_limit < dump_count)) {
45938 printk(KERN_WARNING "Pid %d(%s) over core_pipe_limit\n",
45939 task_tgid_vnr(current), current->comm);
45940@@ -2218,6 +2597,8 @@ void do_coredump(long signr, int exit_code, struct pt_regs *regs)
45941 } else {
45942 struct inode *inode;
45943
45944+ gr_learn_resource(current, RLIMIT_CORE, binfmt->min_coredump, 1);
45945+
45946 if (cprm.limit < binfmt->min_coredump)
45947 goto fail_unlock;
45948
45949@@ -2269,7 +2650,7 @@ close_fail:
45950 filp_close(cprm.file, NULL);
45951 fail_dropcount:
45952 if (ispipe)
45953- atomic_dec(&core_dump_count);
45954+ atomic_dec_unchecked(&core_dump_count);
45955 fail_unlock:
45956 kfree(cn.corename);
45957 fail_corename:
45958@@ -2288,7 +2669,7 @@ fail:
45959 */
45960 int dump_write(struct file *file, const void *addr, int nr)
45961 {
45962- return access_ok(VERIFY_READ, addr, nr) && file->f_op->write(file, addr, nr, &file->f_pos) == nr;
45963+ return access_ok(VERIFY_READ, addr, nr) && file->f_op->write(file, (const char __force_user *)addr, nr, &file->f_pos) == nr;
45964 }
45965 EXPORT_SYMBOL(dump_write);
45966
45967diff --git a/fs/ext2/balloc.c b/fs/ext2/balloc.c
45968index 376aa77..59a129c 100644
45969--- a/fs/ext2/balloc.c
45970+++ b/fs/ext2/balloc.c
45971@@ -1190,10 +1190,10 @@ static int ext2_has_free_blocks(struct ext2_sb_info *sbi)
45972
45973 free_blocks = percpu_counter_read_positive(&sbi->s_freeblocks_counter);
45974 root_blocks = le32_to_cpu(sbi->s_es->s_r_blocks_count);
45975- if (free_blocks < root_blocks + 1 && !capable(CAP_SYS_RESOURCE) &&
45976+ if (free_blocks < root_blocks + 1 &&
45977 !uid_eq(sbi->s_resuid, current_fsuid()) &&
45978 (gid_eq(sbi->s_resgid, GLOBAL_ROOT_GID) ||
45979- !in_group_p (sbi->s_resgid))) {
45980+ !in_group_p (sbi->s_resgid)) && !capable_nolog(CAP_SYS_RESOURCE)) {
45981 return 0;
45982 }
45983 return 1;
45984diff --git a/fs/ext3/balloc.c b/fs/ext3/balloc.c
45985index 90d901f..159975f 100644
45986--- a/fs/ext3/balloc.c
45987+++ b/fs/ext3/balloc.c
45988@@ -1438,10 +1438,10 @@ static int ext3_has_free_blocks(struct ext3_sb_info *sbi, int use_reservation)
45989
45990 free_blocks = percpu_counter_read_positive(&sbi->s_freeblocks_counter);
45991 root_blocks = le32_to_cpu(sbi->s_es->s_r_blocks_count);
45992- if (free_blocks < root_blocks + 1 && !capable(CAP_SYS_RESOURCE) &&
45993+ if (free_blocks < root_blocks + 1 &&
45994 !use_reservation && !uid_eq(sbi->s_resuid, current_fsuid()) &&
45995 (gid_eq(sbi->s_resgid, GLOBAL_ROOT_GID) ||
45996- !in_group_p (sbi->s_resgid))) {
45997+ !in_group_p (sbi->s_resgid)) && !capable_nolog(CAP_SYS_RESOURCE)) {
45998 return 0;
45999 }
46000 return 1;
46001diff --git a/fs/ext4/balloc.c b/fs/ext4/balloc.c
46002index cf18217..8f6b9c3 100644
46003--- a/fs/ext4/balloc.c
46004+++ b/fs/ext4/balloc.c
46005@@ -498,8 +498,8 @@ static int ext4_has_free_clusters(struct ext4_sb_info *sbi,
46006 /* Hm, nope. Are (enough) root reserved clusters available? */
46007 if (uid_eq(sbi->s_resuid, current_fsuid()) ||
46008 (!gid_eq(sbi->s_resgid, GLOBAL_ROOT_GID) && in_group_p(sbi->s_resgid)) ||
46009- capable(CAP_SYS_RESOURCE) ||
46010- (flags & EXT4_MB_USE_ROOT_BLOCKS)) {
46011+ (flags & EXT4_MB_USE_ROOT_BLOCKS) ||
46012+ capable_nolog(CAP_SYS_RESOURCE)) {
46013
46014 if (free_clusters >= (nclusters + dirty_clusters))
46015 return 1;
46016diff --git a/fs/ext4/ext4.h b/fs/ext4/ext4.h
46017index b686b43..4b46d01 100644
46018--- a/fs/ext4/ext4.h
46019+++ b/fs/ext4/ext4.h
46020@@ -1248,19 +1248,19 @@ struct ext4_sb_info {
46021 unsigned long s_mb_last_start;
46022
46023 /* stats for buddy allocator */
46024- atomic_t s_bal_reqs; /* number of reqs with len > 1 */
46025- atomic_t s_bal_success; /* we found long enough chunks */
46026- atomic_t s_bal_allocated; /* in blocks */
46027- atomic_t s_bal_ex_scanned; /* total extents scanned */
46028- atomic_t s_bal_goals; /* goal hits */
46029- atomic_t s_bal_breaks; /* too long searches */
46030- atomic_t s_bal_2orders; /* 2^order hits */
46031+ atomic_unchecked_t s_bal_reqs; /* number of reqs with len > 1 */
46032+ atomic_unchecked_t s_bal_success; /* we found long enough chunks */
46033+ atomic_unchecked_t s_bal_allocated; /* in blocks */
46034+ atomic_unchecked_t s_bal_ex_scanned; /* total extents scanned */
46035+ atomic_unchecked_t s_bal_goals; /* goal hits */
46036+ atomic_unchecked_t s_bal_breaks; /* too long searches */
46037+ atomic_unchecked_t s_bal_2orders; /* 2^order hits */
46038 spinlock_t s_bal_lock;
46039 unsigned long s_mb_buddies_generated;
46040 unsigned long long s_mb_generation_time;
46041- atomic_t s_mb_lost_chunks;
46042- atomic_t s_mb_preallocated;
46043- atomic_t s_mb_discarded;
46044+ atomic_unchecked_t s_mb_lost_chunks;
46045+ atomic_unchecked_t s_mb_preallocated;
46046+ atomic_unchecked_t s_mb_discarded;
46047 atomic_t s_lock_busy;
46048
46049 /* locality groups */
46050diff --git a/fs/ext4/mballoc.c b/fs/ext4/mballoc.c
46051index b26410c..7383d90 100644
46052--- a/fs/ext4/mballoc.c
46053+++ b/fs/ext4/mballoc.c
46054@@ -1746,7 +1746,7 @@ void ext4_mb_simple_scan_group(struct ext4_allocation_context *ac,
46055 BUG_ON(ac->ac_b_ex.fe_len != ac->ac_g_ex.fe_len);
46056
46057 if (EXT4_SB(sb)->s_mb_stats)
46058- atomic_inc(&EXT4_SB(sb)->s_bal_2orders);
46059+ atomic_inc_unchecked(&EXT4_SB(sb)->s_bal_2orders);
46060
46061 break;
46062 }
46063@@ -2040,7 +2040,7 @@ repeat:
46064 ac->ac_status = AC_STATUS_CONTINUE;
46065 ac->ac_flags |= EXT4_MB_HINT_FIRST;
46066 cr = 3;
46067- atomic_inc(&sbi->s_mb_lost_chunks);
46068+ atomic_inc_unchecked(&sbi->s_mb_lost_chunks);
46069 goto repeat;
46070 }
46071 }
46072@@ -2551,25 +2551,25 @@ int ext4_mb_release(struct super_block *sb)
46073 if (sbi->s_mb_stats) {
46074 ext4_msg(sb, KERN_INFO,
46075 "mballoc: %u blocks %u reqs (%u success)",
46076- atomic_read(&sbi->s_bal_allocated),
46077- atomic_read(&sbi->s_bal_reqs),
46078- atomic_read(&sbi->s_bal_success));
46079+ atomic_read_unchecked(&sbi->s_bal_allocated),
46080+ atomic_read_unchecked(&sbi->s_bal_reqs),
46081+ atomic_read_unchecked(&sbi->s_bal_success));
46082 ext4_msg(sb, KERN_INFO,
46083 "mballoc: %u extents scanned, %u goal hits, "
46084 "%u 2^N hits, %u breaks, %u lost",
46085- atomic_read(&sbi->s_bal_ex_scanned),
46086- atomic_read(&sbi->s_bal_goals),
46087- atomic_read(&sbi->s_bal_2orders),
46088- atomic_read(&sbi->s_bal_breaks),
46089- atomic_read(&sbi->s_mb_lost_chunks));
46090+ atomic_read_unchecked(&sbi->s_bal_ex_scanned),
46091+ atomic_read_unchecked(&sbi->s_bal_goals),
46092+ atomic_read_unchecked(&sbi->s_bal_2orders),
46093+ atomic_read_unchecked(&sbi->s_bal_breaks),
46094+ atomic_read_unchecked(&sbi->s_mb_lost_chunks));
46095 ext4_msg(sb, KERN_INFO,
46096 "mballoc: %lu generated and it took %Lu",
46097 sbi->s_mb_buddies_generated,
46098 sbi->s_mb_generation_time);
46099 ext4_msg(sb, KERN_INFO,
46100 "mballoc: %u preallocated, %u discarded",
46101- atomic_read(&sbi->s_mb_preallocated),
46102- atomic_read(&sbi->s_mb_discarded));
46103+ atomic_read_unchecked(&sbi->s_mb_preallocated),
46104+ atomic_read_unchecked(&sbi->s_mb_discarded));
46105 }
46106
46107 free_percpu(sbi->s_locality_groups);
46108@@ -3051,16 +3051,16 @@ static void ext4_mb_collect_stats(struct ext4_allocation_context *ac)
46109 struct ext4_sb_info *sbi = EXT4_SB(ac->ac_sb);
46110
46111 if (sbi->s_mb_stats && ac->ac_g_ex.fe_len > 1) {
46112- atomic_inc(&sbi->s_bal_reqs);
46113- atomic_add(ac->ac_b_ex.fe_len, &sbi->s_bal_allocated);
46114+ atomic_inc_unchecked(&sbi->s_bal_reqs);
46115+ atomic_add_unchecked(ac->ac_b_ex.fe_len, &sbi->s_bal_allocated);
46116 if (ac->ac_b_ex.fe_len >= ac->ac_o_ex.fe_len)
46117- atomic_inc(&sbi->s_bal_success);
46118- atomic_add(ac->ac_found, &sbi->s_bal_ex_scanned);
46119+ atomic_inc_unchecked(&sbi->s_bal_success);
46120+ atomic_add_unchecked(ac->ac_found, &sbi->s_bal_ex_scanned);
46121 if (ac->ac_g_ex.fe_start == ac->ac_b_ex.fe_start &&
46122 ac->ac_g_ex.fe_group == ac->ac_b_ex.fe_group)
46123- atomic_inc(&sbi->s_bal_goals);
46124+ atomic_inc_unchecked(&sbi->s_bal_goals);
46125 if (ac->ac_found > sbi->s_mb_max_to_scan)
46126- atomic_inc(&sbi->s_bal_breaks);
46127+ atomic_inc_unchecked(&sbi->s_bal_breaks);
46128 }
46129
46130 if (ac->ac_op == EXT4_MB_HISTORY_ALLOC)
46131@@ -3460,7 +3460,7 @@ ext4_mb_new_inode_pa(struct ext4_allocation_context *ac)
46132 trace_ext4_mb_new_inode_pa(ac, pa);
46133
46134 ext4_mb_use_inode_pa(ac, pa);
46135- atomic_add(pa->pa_free, &sbi->s_mb_preallocated);
46136+ atomic_add_unchecked(pa->pa_free, &sbi->s_mb_preallocated);
46137
46138 ei = EXT4_I(ac->ac_inode);
46139 grp = ext4_get_group_info(sb, ac->ac_b_ex.fe_group);
46140@@ -3520,7 +3520,7 @@ ext4_mb_new_group_pa(struct ext4_allocation_context *ac)
46141 trace_ext4_mb_new_group_pa(ac, pa);
46142
46143 ext4_mb_use_group_pa(ac, pa);
46144- atomic_add(pa->pa_free, &EXT4_SB(sb)->s_mb_preallocated);
46145+ atomic_add_unchecked(pa->pa_free, &EXT4_SB(sb)->s_mb_preallocated);
46146
46147 grp = ext4_get_group_info(sb, ac->ac_b_ex.fe_group);
46148 lg = ac->ac_lg;
46149@@ -3609,7 +3609,7 @@ ext4_mb_release_inode_pa(struct ext4_buddy *e4b, struct buffer_head *bitmap_bh,
46150 * from the bitmap and continue.
46151 */
46152 }
46153- atomic_add(free, &sbi->s_mb_discarded);
46154+ atomic_add_unchecked(free, &sbi->s_mb_discarded);
46155
46156 return err;
46157 }
46158@@ -3627,7 +3627,7 @@ ext4_mb_release_group_pa(struct ext4_buddy *e4b,
46159 ext4_get_group_no_and_offset(sb, pa->pa_pstart, &group, &bit);
46160 BUG_ON(group != e4b->bd_group && pa->pa_len != 0);
46161 mb_free_blocks(pa->pa_inode, e4b, bit, pa->pa_len);
46162- atomic_add(pa->pa_len, &EXT4_SB(sb)->s_mb_discarded);
46163+ atomic_add_unchecked(pa->pa_len, &EXT4_SB(sb)->s_mb_discarded);
46164 trace_ext4_mballoc_discard(sb, NULL, group, bit, pa->pa_len);
46165
46166 return 0;
46167diff --git a/fs/fcntl.c b/fs/fcntl.c
46168index 887b5ba..0e3f2c3 100644
46169--- a/fs/fcntl.c
46170+++ b/fs/fcntl.c
46171@@ -225,6 +225,11 @@ int __f_setown(struct file *filp, struct pid *pid, enum pid_type type,
46172 if (err)
46173 return err;
46174
46175+ if (gr_handle_chroot_fowner(pid, type))
46176+ return -ENOENT;
46177+ if (gr_check_protected_task_fowner(pid, type))
46178+ return -EACCES;
46179+
46180 f_modown(filp, pid, type, force);
46181 return 0;
46182 }
46183@@ -267,7 +272,7 @@ pid_t f_getown(struct file *filp)
46184
46185 static int f_setown_ex(struct file *filp, unsigned long arg)
46186 {
46187- struct f_owner_ex * __user owner_p = (void * __user)arg;
46188+ struct f_owner_ex __user *owner_p = (void __user *)arg;
46189 struct f_owner_ex owner;
46190 struct pid *pid;
46191 int type;
46192@@ -307,7 +312,7 @@ static int f_setown_ex(struct file *filp, unsigned long arg)
46193
46194 static int f_getown_ex(struct file *filp, unsigned long arg)
46195 {
46196- struct f_owner_ex * __user owner_p = (void * __user)arg;
46197+ struct f_owner_ex __user *owner_p = (void __user *)arg;
46198 struct f_owner_ex owner;
46199 int ret = 0;
46200
46201@@ -374,6 +379,7 @@ static long do_fcntl(int fd, unsigned int cmd, unsigned long arg,
46202 switch (cmd) {
46203 case F_DUPFD:
46204 case F_DUPFD_CLOEXEC:
46205+ gr_learn_resource(current, RLIMIT_NOFILE, arg, 0);
46206 if (arg >= rlimit(RLIMIT_NOFILE))
46207 break;
46208 err = alloc_fd(arg, cmd == F_DUPFD_CLOEXEC ? O_CLOEXEC : 0);
46209diff --git a/fs/fifo.c b/fs/fifo.c
46210index cf6f434..3d7942c 100644
46211--- a/fs/fifo.c
46212+++ b/fs/fifo.c
46213@@ -59,10 +59,10 @@ static int fifo_open(struct inode *inode, struct file *filp)
46214 */
46215 filp->f_op = &read_pipefifo_fops;
46216 pipe->r_counter++;
46217- if (pipe->readers++ == 0)
46218+ if (atomic_inc_return(&pipe->readers) == 1)
46219 wake_up_partner(inode);
46220
46221- if (!pipe->writers) {
46222+ if (!atomic_read(&pipe->writers)) {
46223 if ((filp->f_flags & O_NONBLOCK)) {
46224 /* suppress POLLHUP until we have
46225 * seen a writer */
46226@@ -81,15 +81,15 @@ static int fifo_open(struct inode *inode, struct file *filp)
46227 * errno=ENXIO when there is no process reading the FIFO.
46228 */
46229 ret = -ENXIO;
46230- if ((filp->f_flags & O_NONBLOCK) && !pipe->readers)
46231+ if ((filp->f_flags & O_NONBLOCK) && !atomic_read(&pipe->readers))
46232 goto err;
46233
46234 filp->f_op = &write_pipefifo_fops;
46235 pipe->w_counter++;
46236- if (!pipe->writers++)
46237+ if (atomic_inc_return(&pipe->writers) == 1)
46238 wake_up_partner(inode);
46239
46240- if (!pipe->readers) {
46241+ if (!atomic_read(&pipe->readers)) {
46242 if (wait_for_partner(inode, &pipe->r_counter))
46243 goto err_wr;
46244 }
46245@@ -104,11 +104,11 @@ static int fifo_open(struct inode *inode, struct file *filp)
46246 */
46247 filp->f_op = &rdwr_pipefifo_fops;
46248
46249- pipe->readers++;
46250- pipe->writers++;
46251+ atomic_inc(&pipe->readers);
46252+ atomic_inc(&pipe->writers);
46253 pipe->r_counter++;
46254 pipe->w_counter++;
46255- if (pipe->readers == 1 || pipe->writers == 1)
46256+ if (atomic_read(&pipe->readers) == 1 || atomic_read(&pipe->writers) == 1)
46257 wake_up_partner(inode);
46258 break;
46259
46260@@ -122,19 +122,19 @@ static int fifo_open(struct inode *inode, struct file *filp)
46261 return 0;
46262
46263 err_rd:
46264- if (!--pipe->readers)
46265+ if (atomic_dec_and_test(&pipe->readers))
46266 wake_up_interruptible(&pipe->wait);
46267 ret = -ERESTARTSYS;
46268 goto err;
46269
46270 err_wr:
46271- if (!--pipe->writers)
46272+ if (atomic_dec_and_test(&pipe->writers))
46273 wake_up_interruptible(&pipe->wait);
46274 ret = -ERESTARTSYS;
46275 goto err;
46276
46277 err:
46278- if (!pipe->readers && !pipe->writers)
46279+ if (!atomic_read(&pipe->readers) && !atomic_read(&pipe->writers))
46280 free_pipe_info(inode);
46281
46282 err_nocleanup:
46283diff --git a/fs/file.c b/fs/file.c
46284index ba3f605..fade102 100644
46285--- a/fs/file.c
46286+++ b/fs/file.c
46287@@ -15,6 +15,7 @@
46288 #include <linux/slab.h>
46289 #include <linux/vmalloc.h>
46290 #include <linux/file.h>
46291+#include <linux/security.h>
46292 #include <linux/fdtable.h>
46293 #include <linux/bitops.h>
46294 #include <linux/interrupt.h>
46295@@ -255,6 +256,7 @@ int expand_files(struct files_struct *files, int nr)
46296 * N.B. For clone tasks sharing a files structure, this test
46297 * will limit the total number of files that can be opened.
46298 */
46299+ gr_learn_resource(current, RLIMIT_NOFILE, nr, 0);
46300 if (nr >= rlimit(RLIMIT_NOFILE))
46301 return -EMFILE;
46302
46303diff --git a/fs/filesystems.c b/fs/filesystems.c
46304index 96f2428..f5eeb8e 100644
46305--- a/fs/filesystems.c
46306+++ b/fs/filesystems.c
46307@@ -273,7 +273,12 @@ struct file_system_type *get_fs_type(const char *name)
46308 int len = dot ? dot - name : strlen(name);
46309
46310 fs = __get_fs_type(name, len);
46311+
46312+#ifdef CONFIG_GRKERNSEC_MODHARDEN
46313+ if (!fs && (___request_module(true, "grsec_modharden_fs", "%.*s", len, name) == 0))
46314+#else
46315 if (!fs && (request_module("%.*s", len, name) == 0))
46316+#endif
46317 fs = __get_fs_type(name, len);
46318
46319 if (dot && fs && !(fs->fs_flags & FS_HAS_SUBTYPE)) {
46320diff --git a/fs/fs_struct.c b/fs/fs_struct.c
46321index 5df4775..f656176 100644
46322--- a/fs/fs_struct.c
46323+++ b/fs/fs_struct.c
46324@@ -4,6 +4,7 @@
46325 #include <linux/path.h>
46326 #include <linux/slab.h>
46327 #include <linux/fs_struct.h>
46328+#include <linux/grsecurity.h>
46329 #include "internal.h"
46330
46331 /*
46332@@ -19,6 +20,7 @@ void set_fs_root(struct fs_struct *fs, struct path *path)
46333 write_seqcount_begin(&fs->seq);
46334 old_root = fs->root;
46335 fs->root = *path;
46336+ gr_set_chroot_entries(current, path);
46337 write_seqcount_end(&fs->seq);
46338 spin_unlock(&fs->lock);
46339 if (old_root.dentry)
46340@@ -53,6 +55,21 @@ static inline int replace_path(struct path *p, const struct path *old, const str
46341 return 1;
46342 }
46343
46344+static inline int replace_root_path(struct task_struct *task, struct path *p, const struct path *old, struct path *new)
46345+{
46346+ if (likely(p->dentry != old->dentry || p->mnt != old->mnt))
46347+ return 0;
46348+ *p = *new;
46349+
46350+ /* This function is only called from pivot_root(). Leave our
46351+ gr_chroot_dentry and is_chrooted flags as-is, so that a
46352+ pivoted root isn't treated as a chroot
46353+ */
46354+ //gr_set_chroot_entries(task, new);
46355+
46356+ return 1;
46357+}
46358+
46359 void chroot_fs_refs(struct path *old_root, struct path *new_root)
46360 {
46361 struct task_struct *g, *p;
46362@@ -67,7 +84,7 @@ void chroot_fs_refs(struct path *old_root, struct path *new_root)
46363 int hits = 0;
46364 spin_lock(&fs->lock);
46365 write_seqcount_begin(&fs->seq);
46366- hits += replace_path(&fs->root, old_root, new_root);
46367+ hits += replace_root_path(p, &fs->root, old_root, new_root);
46368 hits += replace_path(&fs->pwd, old_root, new_root);
46369 write_seqcount_end(&fs->seq);
46370 while (hits--) {
46371@@ -94,12 +111,15 @@ void exit_fs(struct task_struct *tsk)
46372 {
46373 struct fs_struct *fs = tsk->fs;
46374
46375+ gr_put_exec_file(tsk);
46376+
46377 if (fs) {
46378 int kill;
46379 task_lock(tsk);
46380 spin_lock(&fs->lock);
46381 tsk->fs = NULL;
46382- kill = !--fs->users;
46383+ gr_clear_chroot_entries(tsk);
46384+ kill = !atomic_dec_return(&fs->users);
46385 spin_unlock(&fs->lock);
46386 task_unlock(tsk);
46387 if (kill)
46388@@ -112,7 +132,7 @@ struct fs_struct *copy_fs_struct(struct fs_struct *old)
46389 struct fs_struct *fs = kmem_cache_alloc(fs_cachep, GFP_KERNEL);
46390 /* We don't need to lock fs - think why ;-) */
46391 if (fs) {
46392- fs->users = 1;
46393+ atomic_set(&fs->users, 1);
46394 fs->in_exec = 0;
46395 spin_lock_init(&fs->lock);
46396 seqcount_init(&fs->seq);
46397@@ -121,6 +141,9 @@ struct fs_struct *copy_fs_struct(struct fs_struct *old)
46398 spin_lock(&old->lock);
46399 fs->root = old->root;
46400 path_get(&fs->root);
46401+ /* instead of calling gr_set_chroot_entries here,
46402+ we call it from every caller of this function
46403+ */
46404 fs->pwd = old->pwd;
46405 path_get(&fs->pwd);
46406 spin_unlock(&old->lock);
46407@@ -139,8 +162,9 @@ int unshare_fs_struct(void)
46408
46409 task_lock(current);
46410 spin_lock(&fs->lock);
46411- kill = !--fs->users;
46412+ kill = !atomic_dec_return(&fs->users);
46413 current->fs = new_fs;
46414+ gr_set_chroot_entries(current, &new_fs->root);
46415 spin_unlock(&fs->lock);
46416 task_unlock(current);
46417
46418@@ -153,13 +177,13 @@ EXPORT_SYMBOL_GPL(unshare_fs_struct);
46419
46420 int current_umask(void)
46421 {
46422- return current->fs->umask;
46423+ return current->fs->umask | gr_acl_umask();
46424 }
46425 EXPORT_SYMBOL(current_umask);
46426
46427 /* to be mentioned only in INIT_TASK */
46428 struct fs_struct init_fs = {
46429- .users = 1,
46430+ .users = ATOMIC_INIT(1),
46431 .lock = __SPIN_LOCK_UNLOCKED(init_fs.lock),
46432 .seq = SEQCNT_ZERO,
46433 .umask = 0022,
46434@@ -169,18 +193,21 @@ void daemonize_fs_struct(void)
46435 {
46436 struct fs_struct *fs = current->fs;
46437
46438+ gr_put_exec_file(current);
46439+
46440 if (fs) {
46441 int kill;
46442
46443 task_lock(current);
46444
46445 spin_lock(&init_fs.lock);
46446- init_fs.users++;
46447+ atomic_inc(&init_fs.users);
46448 spin_unlock(&init_fs.lock);
46449
46450 spin_lock(&fs->lock);
46451 current->fs = &init_fs;
46452- kill = !--fs->users;
46453+ gr_set_chroot_entries(current, &current->fs->root);
46454+ kill = !atomic_dec_return(&fs->users);
46455 spin_unlock(&fs->lock);
46456
46457 task_unlock(current);
46458diff --git a/fs/fscache/cookie.c b/fs/fscache/cookie.c
46459index 9905350..02eaec4 100644
46460--- a/fs/fscache/cookie.c
46461+++ b/fs/fscache/cookie.c
46462@@ -68,11 +68,11 @@ struct fscache_cookie *__fscache_acquire_cookie(
46463 parent ? (char *) parent->def->name : "<no-parent>",
46464 def->name, netfs_data);
46465
46466- fscache_stat(&fscache_n_acquires);
46467+ fscache_stat_unchecked(&fscache_n_acquires);
46468
46469 /* if there's no parent cookie, then we don't create one here either */
46470 if (!parent) {
46471- fscache_stat(&fscache_n_acquires_null);
46472+ fscache_stat_unchecked(&fscache_n_acquires_null);
46473 _leave(" [no parent]");
46474 return NULL;
46475 }
46476@@ -87,7 +87,7 @@ struct fscache_cookie *__fscache_acquire_cookie(
46477 /* allocate and initialise a cookie */
46478 cookie = kmem_cache_alloc(fscache_cookie_jar, GFP_KERNEL);
46479 if (!cookie) {
46480- fscache_stat(&fscache_n_acquires_oom);
46481+ fscache_stat_unchecked(&fscache_n_acquires_oom);
46482 _leave(" [ENOMEM]");
46483 return NULL;
46484 }
46485@@ -109,13 +109,13 @@ struct fscache_cookie *__fscache_acquire_cookie(
46486
46487 switch (cookie->def->type) {
46488 case FSCACHE_COOKIE_TYPE_INDEX:
46489- fscache_stat(&fscache_n_cookie_index);
46490+ fscache_stat_unchecked(&fscache_n_cookie_index);
46491 break;
46492 case FSCACHE_COOKIE_TYPE_DATAFILE:
46493- fscache_stat(&fscache_n_cookie_data);
46494+ fscache_stat_unchecked(&fscache_n_cookie_data);
46495 break;
46496 default:
46497- fscache_stat(&fscache_n_cookie_special);
46498+ fscache_stat_unchecked(&fscache_n_cookie_special);
46499 break;
46500 }
46501
46502@@ -126,13 +126,13 @@ struct fscache_cookie *__fscache_acquire_cookie(
46503 if (fscache_acquire_non_index_cookie(cookie) < 0) {
46504 atomic_dec(&parent->n_children);
46505 __fscache_cookie_put(cookie);
46506- fscache_stat(&fscache_n_acquires_nobufs);
46507+ fscache_stat_unchecked(&fscache_n_acquires_nobufs);
46508 _leave(" = NULL");
46509 return NULL;
46510 }
46511 }
46512
46513- fscache_stat(&fscache_n_acquires_ok);
46514+ fscache_stat_unchecked(&fscache_n_acquires_ok);
46515 _leave(" = %p", cookie);
46516 return cookie;
46517 }
46518@@ -168,7 +168,7 @@ static int fscache_acquire_non_index_cookie(struct fscache_cookie *cookie)
46519 cache = fscache_select_cache_for_object(cookie->parent);
46520 if (!cache) {
46521 up_read(&fscache_addremove_sem);
46522- fscache_stat(&fscache_n_acquires_no_cache);
46523+ fscache_stat_unchecked(&fscache_n_acquires_no_cache);
46524 _leave(" = -ENOMEDIUM [no cache]");
46525 return -ENOMEDIUM;
46526 }
46527@@ -256,12 +256,12 @@ static int fscache_alloc_object(struct fscache_cache *cache,
46528 object = cache->ops->alloc_object(cache, cookie);
46529 fscache_stat_d(&fscache_n_cop_alloc_object);
46530 if (IS_ERR(object)) {
46531- fscache_stat(&fscache_n_object_no_alloc);
46532+ fscache_stat_unchecked(&fscache_n_object_no_alloc);
46533 ret = PTR_ERR(object);
46534 goto error;
46535 }
46536
46537- fscache_stat(&fscache_n_object_alloc);
46538+ fscache_stat_unchecked(&fscache_n_object_alloc);
46539
46540 object->debug_id = atomic_inc_return(&fscache_object_debug_id);
46541
46542@@ -377,10 +377,10 @@ void __fscache_update_cookie(struct fscache_cookie *cookie)
46543 struct fscache_object *object;
46544 struct hlist_node *_p;
46545
46546- fscache_stat(&fscache_n_updates);
46547+ fscache_stat_unchecked(&fscache_n_updates);
46548
46549 if (!cookie) {
46550- fscache_stat(&fscache_n_updates_null);
46551+ fscache_stat_unchecked(&fscache_n_updates_null);
46552 _leave(" [no cookie]");
46553 return;
46554 }
46555@@ -414,12 +414,12 @@ void __fscache_relinquish_cookie(struct fscache_cookie *cookie, int retire)
46556 struct fscache_object *object;
46557 unsigned long event;
46558
46559- fscache_stat(&fscache_n_relinquishes);
46560+ fscache_stat_unchecked(&fscache_n_relinquishes);
46561 if (retire)
46562- fscache_stat(&fscache_n_relinquishes_retire);
46563+ fscache_stat_unchecked(&fscache_n_relinquishes_retire);
46564
46565 if (!cookie) {
46566- fscache_stat(&fscache_n_relinquishes_null);
46567+ fscache_stat_unchecked(&fscache_n_relinquishes_null);
46568 _leave(" [no cookie]");
46569 return;
46570 }
46571@@ -435,7 +435,7 @@ void __fscache_relinquish_cookie(struct fscache_cookie *cookie, int retire)
46572
46573 /* wait for the cookie to finish being instantiated (or to fail) */
46574 if (test_bit(FSCACHE_COOKIE_CREATING, &cookie->flags)) {
46575- fscache_stat(&fscache_n_relinquishes_waitcrt);
46576+ fscache_stat_unchecked(&fscache_n_relinquishes_waitcrt);
46577 wait_on_bit(&cookie->flags, FSCACHE_COOKIE_CREATING,
46578 fscache_wait_bit, TASK_UNINTERRUPTIBLE);
46579 }
46580diff --git a/fs/fscache/internal.h b/fs/fscache/internal.h
46581index f6aad48..88dcf26 100644
46582--- a/fs/fscache/internal.h
46583+++ b/fs/fscache/internal.h
46584@@ -144,94 +144,94 @@ extern void fscache_proc_cleanup(void);
46585 extern atomic_t fscache_n_ops_processed[FSCACHE_MAX_THREADS];
46586 extern atomic_t fscache_n_objs_processed[FSCACHE_MAX_THREADS];
46587
46588-extern atomic_t fscache_n_op_pend;
46589-extern atomic_t fscache_n_op_run;
46590-extern atomic_t fscache_n_op_enqueue;
46591-extern atomic_t fscache_n_op_deferred_release;
46592-extern atomic_t fscache_n_op_release;
46593-extern atomic_t fscache_n_op_gc;
46594-extern atomic_t fscache_n_op_cancelled;
46595-extern atomic_t fscache_n_op_rejected;
46596+extern atomic_unchecked_t fscache_n_op_pend;
46597+extern atomic_unchecked_t fscache_n_op_run;
46598+extern atomic_unchecked_t fscache_n_op_enqueue;
46599+extern atomic_unchecked_t fscache_n_op_deferred_release;
46600+extern atomic_unchecked_t fscache_n_op_release;
46601+extern atomic_unchecked_t fscache_n_op_gc;
46602+extern atomic_unchecked_t fscache_n_op_cancelled;
46603+extern atomic_unchecked_t fscache_n_op_rejected;
46604
46605-extern atomic_t fscache_n_attr_changed;
46606-extern atomic_t fscache_n_attr_changed_ok;
46607-extern atomic_t fscache_n_attr_changed_nobufs;
46608-extern atomic_t fscache_n_attr_changed_nomem;
46609-extern atomic_t fscache_n_attr_changed_calls;
46610+extern atomic_unchecked_t fscache_n_attr_changed;
46611+extern atomic_unchecked_t fscache_n_attr_changed_ok;
46612+extern atomic_unchecked_t fscache_n_attr_changed_nobufs;
46613+extern atomic_unchecked_t fscache_n_attr_changed_nomem;
46614+extern atomic_unchecked_t fscache_n_attr_changed_calls;
46615
46616-extern atomic_t fscache_n_allocs;
46617-extern atomic_t fscache_n_allocs_ok;
46618-extern atomic_t fscache_n_allocs_wait;
46619-extern atomic_t fscache_n_allocs_nobufs;
46620-extern atomic_t fscache_n_allocs_intr;
46621-extern atomic_t fscache_n_allocs_object_dead;
46622-extern atomic_t fscache_n_alloc_ops;
46623-extern atomic_t fscache_n_alloc_op_waits;
46624+extern atomic_unchecked_t fscache_n_allocs;
46625+extern atomic_unchecked_t fscache_n_allocs_ok;
46626+extern atomic_unchecked_t fscache_n_allocs_wait;
46627+extern atomic_unchecked_t fscache_n_allocs_nobufs;
46628+extern atomic_unchecked_t fscache_n_allocs_intr;
46629+extern atomic_unchecked_t fscache_n_allocs_object_dead;
46630+extern atomic_unchecked_t fscache_n_alloc_ops;
46631+extern atomic_unchecked_t fscache_n_alloc_op_waits;
46632
46633-extern atomic_t fscache_n_retrievals;
46634-extern atomic_t fscache_n_retrievals_ok;
46635-extern atomic_t fscache_n_retrievals_wait;
46636-extern atomic_t fscache_n_retrievals_nodata;
46637-extern atomic_t fscache_n_retrievals_nobufs;
46638-extern atomic_t fscache_n_retrievals_intr;
46639-extern atomic_t fscache_n_retrievals_nomem;
46640-extern atomic_t fscache_n_retrievals_object_dead;
46641-extern atomic_t fscache_n_retrieval_ops;
46642-extern atomic_t fscache_n_retrieval_op_waits;
46643+extern atomic_unchecked_t fscache_n_retrievals;
46644+extern atomic_unchecked_t fscache_n_retrievals_ok;
46645+extern atomic_unchecked_t fscache_n_retrievals_wait;
46646+extern atomic_unchecked_t fscache_n_retrievals_nodata;
46647+extern atomic_unchecked_t fscache_n_retrievals_nobufs;
46648+extern atomic_unchecked_t fscache_n_retrievals_intr;
46649+extern atomic_unchecked_t fscache_n_retrievals_nomem;
46650+extern atomic_unchecked_t fscache_n_retrievals_object_dead;
46651+extern atomic_unchecked_t fscache_n_retrieval_ops;
46652+extern atomic_unchecked_t fscache_n_retrieval_op_waits;
46653
46654-extern atomic_t fscache_n_stores;
46655-extern atomic_t fscache_n_stores_ok;
46656-extern atomic_t fscache_n_stores_again;
46657-extern atomic_t fscache_n_stores_nobufs;
46658-extern atomic_t fscache_n_stores_oom;
46659-extern atomic_t fscache_n_store_ops;
46660-extern atomic_t fscache_n_store_calls;
46661-extern atomic_t fscache_n_store_pages;
46662-extern atomic_t fscache_n_store_radix_deletes;
46663-extern atomic_t fscache_n_store_pages_over_limit;
46664+extern atomic_unchecked_t fscache_n_stores;
46665+extern atomic_unchecked_t fscache_n_stores_ok;
46666+extern atomic_unchecked_t fscache_n_stores_again;
46667+extern atomic_unchecked_t fscache_n_stores_nobufs;
46668+extern atomic_unchecked_t fscache_n_stores_oom;
46669+extern atomic_unchecked_t fscache_n_store_ops;
46670+extern atomic_unchecked_t fscache_n_store_calls;
46671+extern atomic_unchecked_t fscache_n_store_pages;
46672+extern atomic_unchecked_t fscache_n_store_radix_deletes;
46673+extern atomic_unchecked_t fscache_n_store_pages_over_limit;
46674
46675-extern atomic_t fscache_n_store_vmscan_not_storing;
46676-extern atomic_t fscache_n_store_vmscan_gone;
46677-extern atomic_t fscache_n_store_vmscan_busy;
46678-extern atomic_t fscache_n_store_vmscan_cancelled;
46679+extern atomic_unchecked_t fscache_n_store_vmscan_not_storing;
46680+extern atomic_unchecked_t fscache_n_store_vmscan_gone;
46681+extern atomic_unchecked_t fscache_n_store_vmscan_busy;
46682+extern atomic_unchecked_t fscache_n_store_vmscan_cancelled;
46683
46684-extern atomic_t fscache_n_marks;
46685-extern atomic_t fscache_n_uncaches;
46686+extern atomic_unchecked_t fscache_n_marks;
46687+extern atomic_unchecked_t fscache_n_uncaches;
46688
46689-extern atomic_t fscache_n_acquires;
46690-extern atomic_t fscache_n_acquires_null;
46691-extern atomic_t fscache_n_acquires_no_cache;
46692-extern atomic_t fscache_n_acquires_ok;
46693-extern atomic_t fscache_n_acquires_nobufs;
46694-extern atomic_t fscache_n_acquires_oom;
46695+extern atomic_unchecked_t fscache_n_acquires;
46696+extern atomic_unchecked_t fscache_n_acquires_null;
46697+extern atomic_unchecked_t fscache_n_acquires_no_cache;
46698+extern atomic_unchecked_t fscache_n_acquires_ok;
46699+extern atomic_unchecked_t fscache_n_acquires_nobufs;
46700+extern atomic_unchecked_t fscache_n_acquires_oom;
46701
46702-extern atomic_t fscache_n_updates;
46703-extern atomic_t fscache_n_updates_null;
46704-extern atomic_t fscache_n_updates_run;
46705+extern atomic_unchecked_t fscache_n_updates;
46706+extern atomic_unchecked_t fscache_n_updates_null;
46707+extern atomic_unchecked_t fscache_n_updates_run;
46708
46709-extern atomic_t fscache_n_relinquishes;
46710-extern atomic_t fscache_n_relinquishes_null;
46711-extern atomic_t fscache_n_relinquishes_waitcrt;
46712-extern atomic_t fscache_n_relinquishes_retire;
46713+extern atomic_unchecked_t fscache_n_relinquishes;
46714+extern atomic_unchecked_t fscache_n_relinquishes_null;
46715+extern atomic_unchecked_t fscache_n_relinquishes_waitcrt;
46716+extern atomic_unchecked_t fscache_n_relinquishes_retire;
46717
46718-extern atomic_t fscache_n_cookie_index;
46719-extern atomic_t fscache_n_cookie_data;
46720-extern atomic_t fscache_n_cookie_special;
46721+extern atomic_unchecked_t fscache_n_cookie_index;
46722+extern atomic_unchecked_t fscache_n_cookie_data;
46723+extern atomic_unchecked_t fscache_n_cookie_special;
46724
46725-extern atomic_t fscache_n_object_alloc;
46726-extern atomic_t fscache_n_object_no_alloc;
46727-extern atomic_t fscache_n_object_lookups;
46728-extern atomic_t fscache_n_object_lookups_negative;
46729-extern atomic_t fscache_n_object_lookups_positive;
46730-extern atomic_t fscache_n_object_lookups_timed_out;
46731-extern atomic_t fscache_n_object_created;
46732-extern atomic_t fscache_n_object_avail;
46733-extern atomic_t fscache_n_object_dead;
46734+extern atomic_unchecked_t fscache_n_object_alloc;
46735+extern atomic_unchecked_t fscache_n_object_no_alloc;
46736+extern atomic_unchecked_t fscache_n_object_lookups;
46737+extern atomic_unchecked_t fscache_n_object_lookups_negative;
46738+extern atomic_unchecked_t fscache_n_object_lookups_positive;
46739+extern atomic_unchecked_t fscache_n_object_lookups_timed_out;
46740+extern atomic_unchecked_t fscache_n_object_created;
46741+extern atomic_unchecked_t fscache_n_object_avail;
46742+extern atomic_unchecked_t fscache_n_object_dead;
46743
46744-extern atomic_t fscache_n_checkaux_none;
46745-extern atomic_t fscache_n_checkaux_okay;
46746-extern atomic_t fscache_n_checkaux_update;
46747-extern atomic_t fscache_n_checkaux_obsolete;
46748+extern atomic_unchecked_t fscache_n_checkaux_none;
46749+extern atomic_unchecked_t fscache_n_checkaux_okay;
46750+extern atomic_unchecked_t fscache_n_checkaux_update;
46751+extern atomic_unchecked_t fscache_n_checkaux_obsolete;
46752
46753 extern atomic_t fscache_n_cop_alloc_object;
46754 extern atomic_t fscache_n_cop_lookup_object;
46755@@ -255,6 +255,11 @@ static inline void fscache_stat(atomic_t *stat)
46756 atomic_inc(stat);
46757 }
46758
46759+static inline void fscache_stat_unchecked(atomic_unchecked_t *stat)
46760+{
46761+ atomic_inc_unchecked(stat);
46762+}
46763+
46764 static inline void fscache_stat_d(atomic_t *stat)
46765 {
46766 atomic_dec(stat);
46767@@ -267,6 +272,7 @@ extern const struct file_operations fscache_stats_fops;
46768
46769 #define __fscache_stat(stat) (NULL)
46770 #define fscache_stat(stat) do {} while (0)
46771+#define fscache_stat_unchecked(stat) do {} while (0)
46772 #define fscache_stat_d(stat) do {} while (0)
46773 #endif
46774
46775diff --git a/fs/fscache/object.c b/fs/fscache/object.c
46776index b6b897c..0ffff9c 100644
46777--- a/fs/fscache/object.c
46778+++ b/fs/fscache/object.c
46779@@ -128,7 +128,7 @@ static void fscache_object_state_machine(struct fscache_object *object)
46780 /* update the object metadata on disk */
46781 case FSCACHE_OBJECT_UPDATING:
46782 clear_bit(FSCACHE_OBJECT_EV_UPDATE, &object->events);
46783- fscache_stat(&fscache_n_updates_run);
46784+ fscache_stat_unchecked(&fscache_n_updates_run);
46785 fscache_stat(&fscache_n_cop_update_object);
46786 object->cache->ops->update_object(object);
46787 fscache_stat_d(&fscache_n_cop_update_object);
46788@@ -217,7 +217,7 @@ static void fscache_object_state_machine(struct fscache_object *object)
46789 spin_lock(&object->lock);
46790 object->state = FSCACHE_OBJECT_DEAD;
46791 spin_unlock(&object->lock);
46792- fscache_stat(&fscache_n_object_dead);
46793+ fscache_stat_unchecked(&fscache_n_object_dead);
46794 goto terminal_transit;
46795
46796 /* handle the parent cache of this object being withdrawn from
46797@@ -232,7 +232,7 @@ static void fscache_object_state_machine(struct fscache_object *object)
46798 spin_lock(&object->lock);
46799 object->state = FSCACHE_OBJECT_DEAD;
46800 spin_unlock(&object->lock);
46801- fscache_stat(&fscache_n_object_dead);
46802+ fscache_stat_unchecked(&fscache_n_object_dead);
46803 goto terminal_transit;
46804
46805 /* complain about the object being woken up once it is
46806@@ -461,7 +461,7 @@ static void fscache_lookup_object(struct fscache_object *object)
46807 parent->cookie->def->name, cookie->def->name,
46808 object->cache->tag->name);
46809
46810- fscache_stat(&fscache_n_object_lookups);
46811+ fscache_stat_unchecked(&fscache_n_object_lookups);
46812 fscache_stat(&fscache_n_cop_lookup_object);
46813 ret = object->cache->ops->lookup_object(object);
46814 fscache_stat_d(&fscache_n_cop_lookup_object);
46815@@ -472,7 +472,7 @@ static void fscache_lookup_object(struct fscache_object *object)
46816 if (ret == -ETIMEDOUT) {
46817 /* probably stuck behind another object, so move this one to
46818 * the back of the queue */
46819- fscache_stat(&fscache_n_object_lookups_timed_out);
46820+ fscache_stat_unchecked(&fscache_n_object_lookups_timed_out);
46821 set_bit(FSCACHE_OBJECT_EV_REQUEUE, &object->events);
46822 }
46823
46824@@ -495,7 +495,7 @@ void fscache_object_lookup_negative(struct fscache_object *object)
46825
46826 spin_lock(&object->lock);
46827 if (object->state == FSCACHE_OBJECT_LOOKING_UP) {
46828- fscache_stat(&fscache_n_object_lookups_negative);
46829+ fscache_stat_unchecked(&fscache_n_object_lookups_negative);
46830
46831 /* transit here to allow write requests to begin stacking up
46832 * and read requests to begin returning ENODATA */
46833@@ -541,7 +541,7 @@ void fscache_obtained_object(struct fscache_object *object)
46834 * result, in which case there may be data available */
46835 spin_lock(&object->lock);
46836 if (object->state == FSCACHE_OBJECT_LOOKING_UP) {
46837- fscache_stat(&fscache_n_object_lookups_positive);
46838+ fscache_stat_unchecked(&fscache_n_object_lookups_positive);
46839
46840 clear_bit(FSCACHE_COOKIE_NO_DATA_YET, &cookie->flags);
46841
46842@@ -555,7 +555,7 @@ void fscache_obtained_object(struct fscache_object *object)
46843 set_bit(FSCACHE_OBJECT_EV_REQUEUE, &object->events);
46844 } else {
46845 ASSERTCMP(object->state, ==, FSCACHE_OBJECT_CREATING);
46846- fscache_stat(&fscache_n_object_created);
46847+ fscache_stat_unchecked(&fscache_n_object_created);
46848
46849 object->state = FSCACHE_OBJECT_AVAILABLE;
46850 spin_unlock(&object->lock);
46851@@ -602,7 +602,7 @@ static void fscache_object_available(struct fscache_object *object)
46852 fscache_enqueue_dependents(object);
46853
46854 fscache_hist(fscache_obj_instantiate_histogram, object->lookup_jif);
46855- fscache_stat(&fscache_n_object_avail);
46856+ fscache_stat_unchecked(&fscache_n_object_avail);
46857
46858 _leave("");
46859 }
46860@@ -861,7 +861,7 @@ enum fscache_checkaux fscache_check_aux(struct fscache_object *object,
46861 enum fscache_checkaux result;
46862
46863 if (!object->cookie->def->check_aux) {
46864- fscache_stat(&fscache_n_checkaux_none);
46865+ fscache_stat_unchecked(&fscache_n_checkaux_none);
46866 return FSCACHE_CHECKAUX_OKAY;
46867 }
46868
46869@@ -870,17 +870,17 @@ enum fscache_checkaux fscache_check_aux(struct fscache_object *object,
46870 switch (result) {
46871 /* entry okay as is */
46872 case FSCACHE_CHECKAUX_OKAY:
46873- fscache_stat(&fscache_n_checkaux_okay);
46874+ fscache_stat_unchecked(&fscache_n_checkaux_okay);
46875 break;
46876
46877 /* entry requires update */
46878 case FSCACHE_CHECKAUX_NEEDS_UPDATE:
46879- fscache_stat(&fscache_n_checkaux_update);
46880+ fscache_stat_unchecked(&fscache_n_checkaux_update);
46881 break;
46882
46883 /* entry requires deletion */
46884 case FSCACHE_CHECKAUX_OBSOLETE:
46885- fscache_stat(&fscache_n_checkaux_obsolete);
46886+ fscache_stat_unchecked(&fscache_n_checkaux_obsolete);
46887 break;
46888
46889 default:
46890diff --git a/fs/fscache/operation.c b/fs/fscache/operation.c
46891index 30afdfa..2256596 100644
46892--- a/fs/fscache/operation.c
46893+++ b/fs/fscache/operation.c
46894@@ -17,7 +17,7 @@
46895 #include <linux/slab.h>
46896 #include "internal.h"
46897
46898-atomic_t fscache_op_debug_id;
46899+atomic_unchecked_t fscache_op_debug_id;
46900 EXPORT_SYMBOL(fscache_op_debug_id);
46901
46902 /**
46903@@ -38,7 +38,7 @@ void fscache_enqueue_operation(struct fscache_operation *op)
46904 ASSERTCMP(op->object->state, >=, FSCACHE_OBJECT_AVAILABLE);
46905 ASSERTCMP(atomic_read(&op->usage), >, 0);
46906
46907- fscache_stat(&fscache_n_op_enqueue);
46908+ fscache_stat_unchecked(&fscache_n_op_enqueue);
46909 switch (op->flags & FSCACHE_OP_TYPE) {
46910 case FSCACHE_OP_ASYNC:
46911 _debug("queue async");
46912@@ -69,7 +69,7 @@ static void fscache_run_op(struct fscache_object *object,
46913 wake_up_bit(&op->flags, FSCACHE_OP_WAITING);
46914 if (op->processor)
46915 fscache_enqueue_operation(op);
46916- fscache_stat(&fscache_n_op_run);
46917+ fscache_stat_unchecked(&fscache_n_op_run);
46918 }
46919
46920 /*
46921@@ -98,11 +98,11 @@ int fscache_submit_exclusive_op(struct fscache_object *object,
46922 if (object->n_ops > 1) {
46923 atomic_inc(&op->usage);
46924 list_add_tail(&op->pend_link, &object->pending_ops);
46925- fscache_stat(&fscache_n_op_pend);
46926+ fscache_stat_unchecked(&fscache_n_op_pend);
46927 } else if (!list_empty(&object->pending_ops)) {
46928 atomic_inc(&op->usage);
46929 list_add_tail(&op->pend_link, &object->pending_ops);
46930- fscache_stat(&fscache_n_op_pend);
46931+ fscache_stat_unchecked(&fscache_n_op_pend);
46932 fscache_start_operations(object);
46933 } else {
46934 ASSERTCMP(object->n_in_progress, ==, 0);
46935@@ -118,7 +118,7 @@ int fscache_submit_exclusive_op(struct fscache_object *object,
46936 object->n_exclusive++; /* reads and writes must wait */
46937 atomic_inc(&op->usage);
46938 list_add_tail(&op->pend_link, &object->pending_ops);
46939- fscache_stat(&fscache_n_op_pend);
46940+ fscache_stat_unchecked(&fscache_n_op_pend);
46941 ret = 0;
46942 } else {
46943 /* not allowed to submit ops in any other state */
46944@@ -203,11 +203,11 @@ int fscache_submit_op(struct fscache_object *object,
46945 if (object->n_exclusive > 0) {
46946 atomic_inc(&op->usage);
46947 list_add_tail(&op->pend_link, &object->pending_ops);
46948- fscache_stat(&fscache_n_op_pend);
46949+ fscache_stat_unchecked(&fscache_n_op_pend);
46950 } else if (!list_empty(&object->pending_ops)) {
46951 atomic_inc(&op->usage);
46952 list_add_tail(&op->pend_link, &object->pending_ops);
46953- fscache_stat(&fscache_n_op_pend);
46954+ fscache_stat_unchecked(&fscache_n_op_pend);
46955 fscache_start_operations(object);
46956 } else {
46957 ASSERTCMP(object->n_exclusive, ==, 0);
46958@@ -219,12 +219,12 @@ int fscache_submit_op(struct fscache_object *object,
46959 object->n_ops++;
46960 atomic_inc(&op->usage);
46961 list_add_tail(&op->pend_link, &object->pending_ops);
46962- fscache_stat(&fscache_n_op_pend);
46963+ fscache_stat_unchecked(&fscache_n_op_pend);
46964 ret = 0;
46965 } else if (object->state == FSCACHE_OBJECT_DYING ||
46966 object->state == FSCACHE_OBJECT_LC_DYING ||
46967 object->state == FSCACHE_OBJECT_WITHDRAWING) {
46968- fscache_stat(&fscache_n_op_rejected);
46969+ fscache_stat_unchecked(&fscache_n_op_rejected);
46970 ret = -ENOBUFS;
46971 } else if (!test_bit(FSCACHE_IOERROR, &object->cache->flags)) {
46972 fscache_report_unexpected_submission(object, op, ostate);
46973@@ -294,7 +294,7 @@ int fscache_cancel_op(struct fscache_operation *op)
46974
46975 ret = -EBUSY;
46976 if (!list_empty(&op->pend_link)) {
46977- fscache_stat(&fscache_n_op_cancelled);
46978+ fscache_stat_unchecked(&fscache_n_op_cancelled);
46979 list_del_init(&op->pend_link);
46980 object->n_ops--;
46981 if (test_bit(FSCACHE_OP_EXCLUSIVE, &op->flags))
46982@@ -331,7 +331,7 @@ void fscache_put_operation(struct fscache_operation *op)
46983 if (test_and_set_bit(FSCACHE_OP_DEAD, &op->flags))
46984 BUG();
46985
46986- fscache_stat(&fscache_n_op_release);
46987+ fscache_stat_unchecked(&fscache_n_op_release);
46988
46989 if (op->release) {
46990 op->release(op);
46991@@ -348,7 +348,7 @@ void fscache_put_operation(struct fscache_operation *op)
46992 * lock, and defer it otherwise */
46993 if (!spin_trylock(&object->lock)) {
46994 _debug("defer put");
46995- fscache_stat(&fscache_n_op_deferred_release);
46996+ fscache_stat_unchecked(&fscache_n_op_deferred_release);
46997
46998 cache = object->cache;
46999 spin_lock(&cache->op_gc_list_lock);
47000@@ -410,7 +410,7 @@ void fscache_operation_gc(struct work_struct *work)
47001
47002 _debug("GC DEFERRED REL OBJ%x OP%x",
47003 object->debug_id, op->debug_id);
47004- fscache_stat(&fscache_n_op_gc);
47005+ fscache_stat_unchecked(&fscache_n_op_gc);
47006
47007 ASSERTCMP(atomic_read(&op->usage), ==, 0);
47008
47009diff --git a/fs/fscache/page.c b/fs/fscache/page.c
47010index 3f7a59b..cf196cc 100644
47011--- a/fs/fscache/page.c
47012+++ b/fs/fscache/page.c
47013@@ -60,7 +60,7 @@ bool __fscache_maybe_release_page(struct fscache_cookie *cookie,
47014 val = radix_tree_lookup(&cookie->stores, page->index);
47015 if (!val) {
47016 rcu_read_unlock();
47017- fscache_stat(&fscache_n_store_vmscan_not_storing);
47018+ fscache_stat_unchecked(&fscache_n_store_vmscan_not_storing);
47019 __fscache_uncache_page(cookie, page);
47020 return true;
47021 }
47022@@ -90,11 +90,11 @@ bool __fscache_maybe_release_page(struct fscache_cookie *cookie,
47023 spin_unlock(&cookie->stores_lock);
47024
47025 if (xpage) {
47026- fscache_stat(&fscache_n_store_vmscan_cancelled);
47027- fscache_stat(&fscache_n_store_radix_deletes);
47028+ fscache_stat_unchecked(&fscache_n_store_vmscan_cancelled);
47029+ fscache_stat_unchecked(&fscache_n_store_radix_deletes);
47030 ASSERTCMP(xpage, ==, page);
47031 } else {
47032- fscache_stat(&fscache_n_store_vmscan_gone);
47033+ fscache_stat_unchecked(&fscache_n_store_vmscan_gone);
47034 }
47035
47036 wake_up_bit(&cookie->flags, 0);
47037@@ -107,7 +107,7 @@ page_busy:
47038 /* we might want to wait here, but that could deadlock the allocator as
47039 * the work threads writing to the cache may all end up sleeping
47040 * on memory allocation */
47041- fscache_stat(&fscache_n_store_vmscan_busy);
47042+ fscache_stat_unchecked(&fscache_n_store_vmscan_busy);
47043 return false;
47044 }
47045 EXPORT_SYMBOL(__fscache_maybe_release_page);
47046@@ -131,7 +131,7 @@ static void fscache_end_page_write(struct fscache_object *object,
47047 FSCACHE_COOKIE_STORING_TAG);
47048 if (!radix_tree_tag_get(&cookie->stores, page->index,
47049 FSCACHE_COOKIE_PENDING_TAG)) {
47050- fscache_stat(&fscache_n_store_radix_deletes);
47051+ fscache_stat_unchecked(&fscache_n_store_radix_deletes);
47052 xpage = radix_tree_delete(&cookie->stores, page->index);
47053 }
47054 spin_unlock(&cookie->stores_lock);
47055@@ -152,7 +152,7 @@ static void fscache_attr_changed_op(struct fscache_operation *op)
47056
47057 _enter("{OBJ%x OP%x}", object->debug_id, op->debug_id);
47058
47059- fscache_stat(&fscache_n_attr_changed_calls);
47060+ fscache_stat_unchecked(&fscache_n_attr_changed_calls);
47061
47062 if (fscache_object_is_active(object)) {
47063 fscache_stat(&fscache_n_cop_attr_changed);
47064@@ -177,11 +177,11 @@ int __fscache_attr_changed(struct fscache_cookie *cookie)
47065
47066 ASSERTCMP(cookie->def->type, !=, FSCACHE_COOKIE_TYPE_INDEX);
47067
47068- fscache_stat(&fscache_n_attr_changed);
47069+ fscache_stat_unchecked(&fscache_n_attr_changed);
47070
47071 op = kzalloc(sizeof(*op), GFP_KERNEL);
47072 if (!op) {
47073- fscache_stat(&fscache_n_attr_changed_nomem);
47074+ fscache_stat_unchecked(&fscache_n_attr_changed_nomem);
47075 _leave(" = -ENOMEM");
47076 return -ENOMEM;
47077 }
47078@@ -199,7 +199,7 @@ int __fscache_attr_changed(struct fscache_cookie *cookie)
47079 if (fscache_submit_exclusive_op(object, op) < 0)
47080 goto nobufs;
47081 spin_unlock(&cookie->lock);
47082- fscache_stat(&fscache_n_attr_changed_ok);
47083+ fscache_stat_unchecked(&fscache_n_attr_changed_ok);
47084 fscache_put_operation(op);
47085 _leave(" = 0");
47086 return 0;
47087@@ -207,7 +207,7 @@ int __fscache_attr_changed(struct fscache_cookie *cookie)
47088 nobufs:
47089 spin_unlock(&cookie->lock);
47090 kfree(op);
47091- fscache_stat(&fscache_n_attr_changed_nobufs);
47092+ fscache_stat_unchecked(&fscache_n_attr_changed_nobufs);
47093 _leave(" = %d", -ENOBUFS);
47094 return -ENOBUFS;
47095 }
47096@@ -243,7 +243,7 @@ static struct fscache_retrieval *fscache_alloc_retrieval(
47097 /* allocate a retrieval operation and attempt to submit it */
47098 op = kzalloc(sizeof(*op), GFP_NOIO);
47099 if (!op) {
47100- fscache_stat(&fscache_n_retrievals_nomem);
47101+ fscache_stat_unchecked(&fscache_n_retrievals_nomem);
47102 return NULL;
47103 }
47104
47105@@ -271,13 +271,13 @@ static int fscache_wait_for_deferred_lookup(struct fscache_cookie *cookie)
47106 return 0;
47107 }
47108
47109- fscache_stat(&fscache_n_retrievals_wait);
47110+ fscache_stat_unchecked(&fscache_n_retrievals_wait);
47111
47112 jif = jiffies;
47113 if (wait_on_bit(&cookie->flags, FSCACHE_COOKIE_LOOKING_UP,
47114 fscache_wait_bit_interruptible,
47115 TASK_INTERRUPTIBLE) != 0) {
47116- fscache_stat(&fscache_n_retrievals_intr);
47117+ fscache_stat_unchecked(&fscache_n_retrievals_intr);
47118 _leave(" = -ERESTARTSYS");
47119 return -ERESTARTSYS;
47120 }
47121@@ -295,8 +295,8 @@ static int fscache_wait_for_deferred_lookup(struct fscache_cookie *cookie)
47122 */
47123 static int fscache_wait_for_retrieval_activation(struct fscache_object *object,
47124 struct fscache_retrieval *op,
47125- atomic_t *stat_op_waits,
47126- atomic_t *stat_object_dead)
47127+ atomic_unchecked_t *stat_op_waits,
47128+ atomic_unchecked_t *stat_object_dead)
47129 {
47130 int ret;
47131
47132@@ -304,7 +304,7 @@ static int fscache_wait_for_retrieval_activation(struct fscache_object *object,
47133 goto check_if_dead;
47134
47135 _debug(">>> WT");
47136- fscache_stat(stat_op_waits);
47137+ fscache_stat_unchecked(stat_op_waits);
47138 if (wait_on_bit(&op->op.flags, FSCACHE_OP_WAITING,
47139 fscache_wait_bit_interruptible,
47140 TASK_INTERRUPTIBLE) < 0) {
47141@@ -321,7 +321,7 @@ static int fscache_wait_for_retrieval_activation(struct fscache_object *object,
47142
47143 check_if_dead:
47144 if (unlikely(fscache_object_is_dead(object))) {
47145- fscache_stat(stat_object_dead);
47146+ fscache_stat_unchecked(stat_object_dead);
47147 return -ENOBUFS;
47148 }
47149 return 0;
47150@@ -348,7 +348,7 @@ int __fscache_read_or_alloc_page(struct fscache_cookie *cookie,
47151
47152 _enter("%p,%p,,,", cookie, page);
47153
47154- fscache_stat(&fscache_n_retrievals);
47155+ fscache_stat_unchecked(&fscache_n_retrievals);
47156
47157 if (hlist_empty(&cookie->backing_objects))
47158 goto nobufs;
47159@@ -381,7 +381,7 @@ int __fscache_read_or_alloc_page(struct fscache_cookie *cookie,
47160 goto nobufs_unlock;
47161 spin_unlock(&cookie->lock);
47162
47163- fscache_stat(&fscache_n_retrieval_ops);
47164+ fscache_stat_unchecked(&fscache_n_retrieval_ops);
47165
47166 /* pin the netfs read context in case we need to do the actual netfs
47167 * read because we've encountered a cache read failure */
47168@@ -411,15 +411,15 @@ int __fscache_read_or_alloc_page(struct fscache_cookie *cookie,
47169
47170 error:
47171 if (ret == -ENOMEM)
47172- fscache_stat(&fscache_n_retrievals_nomem);
47173+ fscache_stat_unchecked(&fscache_n_retrievals_nomem);
47174 else if (ret == -ERESTARTSYS)
47175- fscache_stat(&fscache_n_retrievals_intr);
47176+ fscache_stat_unchecked(&fscache_n_retrievals_intr);
47177 else if (ret == -ENODATA)
47178- fscache_stat(&fscache_n_retrievals_nodata);
47179+ fscache_stat_unchecked(&fscache_n_retrievals_nodata);
47180 else if (ret < 0)
47181- fscache_stat(&fscache_n_retrievals_nobufs);
47182+ fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
47183 else
47184- fscache_stat(&fscache_n_retrievals_ok);
47185+ fscache_stat_unchecked(&fscache_n_retrievals_ok);
47186
47187 fscache_put_retrieval(op);
47188 _leave(" = %d", ret);
47189@@ -429,7 +429,7 @@ nobufs_unlock:
47190 spin_unlock(&cookie->lock);
47191 kfree(op);
47192 nobufs:
47193- fscache_stat(&fscache_n_retrievals_nobufs);
47194+ fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
47195 _leave(" = -ENOBUFS");
47196 return -ENOBUFS;
47197 }
47198@@ -467,7 +467,7 @@ int __fscache_read_or_alloc_pages(struct fscache_cookie *cookie,
47199
47200 _enter("%p,,%d,,,", cookie, *nr_pages);
47201
47202- fscache_stat(&fscache_n_retrievals);
47203+ fscache_stat_unchecked(&fscache_n_retrievals);
47204
47205 if (hlist_empty(&cookie->backing_objects))
47206 goto nobufs;
47207@@ -497,7 +497,7 @@ int __fscache_read_or_alloc_pages(struct fscache_cookie *cookie,
47208 goto nobufs_unlock;
47209 spin_unlock(&cookie->lock);
47210
47211- fscache_stat(&fscache_n_retrieval_ops);
47212+ fscache_stat_unchecked(&fscache_n_retrieval_ops);
47213
47214 /* pin the netfs read context in case we need to do the actual netfs
47215 * read because we've encountered a cache read failure */
47216@@ -527,15 +527,15 @@ int __fscache_read_or_alloc_pages(struct fscache_cookie *cookie,
47217
47218 error:
47219 if (ret == -ENOMEM)
47220- fscache_stat(&fscache_n_retrievals_nomem);
47221+ fscache_stat_unchecked(&fscache_n_retrievals_nomem);
47222 else if (ret == -ERESTARTSYS)
47223- fscache_stat(&fscache_n_retrievals_intr);
47224+ fscache_stat_unchecked(&fscache_n_retrievals_intr);
47225 else if (ret == -ENODATA)
47226- fscache_stat(&fscache_n_retrievals_nodata);
47227+ fscache_stat_unchecked(&fscache_n_retrievals_nodata);
47228 else if (ret < 0)
47229- fscache_stat(&fscache_n_retrievals_nobufs);
47230+ fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
47231 else
47232- fscache_stat(&fscache_n_retrievals_ok);
47233+ fscache_stat_unchecked(&fscache_n_retrievals_ok);
47234
47235 fscache_put_retrieval(op);
47236 _leave(" = %d", ret);
47237@@ -545,7 +545,7 @@ nobufs_unlock:
47238 spin_unlock(&cookie->lock);
47239 kfree(op);
47240 nobufs:
47241- fscache_stat(&fscache_n_retrievals_nobufs);
47242+ fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
47243 _leave(" = -ENOBUFS");
47244 return -ENOBUFS;
47245 }
47246@@ -569,7 +569,7 @@ int __fscache_alloc_page(struct fscache_cookie *cookie,
47247
47248 _enter("%p,%p,,,", cookie, page);
47249
47250- fscache_stat(&fscache_n_allocs);
47251+ fscache_stat_unchecked(&fscache_n_allocs);
47252
47253 if (hlist_empty(&cookie->backing_objects))
47254 goto nobufs;
47255@@ -595,7 +595,7 @@ int __fscache_alloc_page(struct fscache_cookie *cookie,
47256 goto nobufs_unlock;
47257 spin_unlock(&cookie->lock);
47258
47259- fscache_stat(&fscache_n_alloc_ops);
47260+ fscache_stat_unchecked(&fscache_n_alloc_ops);
47261
47262 ret = fscache_wait_for_retrieval_activation(
47263 object, op,
47264@@ -611,11 +611,11 @@ int __fscache_alloc_page(struct fscache_cookie *cookie,
47265
47266 error:
47267 if (ret == -ERESTARTSYS)
47268- fscache_stat(&fscache_n_allocs_intr);
47269+ fscache_stat_unchecked(&fscache_n_allocs_intr);
47270 else if (ret < 0)
47271- fscache_stat(&fscache_n_allocs_nobufs);
47272+ fscache_stat_unchecked(&fscache_n_allocs_nobufs);
47273 else
47274- fscache_stat(&fscache_n_allocs_ok);
47275+ fscache_stat_unchecked(&fscache_n_allocs_ok);
47276
47277 fscache_put_retrieval(op);
47278 _leave(" = %d", ret);
47279@@ -625,7 +625,7 @@ nobufs_unlock:
47280 spin_unlock(&cookie->lock);
47281 kfree(op);
47282 nobufs:
47283- fscache_stat(&fscache_n_allocs_nobufs);
47284+ fscache_stat_unchecked(&fscache_n_allocs_nobufs);
47285 _leave(" = -ENOBUFS");
47286 return -ENOBUFS;
47287 }
47288@@ -666,7 +666,7 @@ static void fscache_write_op(struct fscache_operation *_op)
47289
47290 spin_lock(&cookie->stores_lock);
47291
47292- fscache_stat(&fscache_n_store_calls);
47293+ fscache_stat_unchecked(&fscache_n_store_calls);
47294
47295 /* find a page to store */
47296 page = NULL;
47297@@ -677,7 +677,7 @@ static void fscache_write_op(struct fscache_operation *_op)
47298 page = results[0];
47299 _debug("gang %d [%lx]", n, page->index);
47300 if (page->index > op->store_limit) {
47301- fscache_stat(&fscache_n_store_pages_over_limit);
47302+ fscache_stat_unchecked(&fscache_n_store_pages_over_limit);
47303 goto superseded;
47304 }
47305
47306@@ -689,7 +689,7 @@ static void fscache_write_op(struct fscache_operation *_op)
47307 spin_unlock(&cookie->stores_lock);
47308 spin_unlock(&object->lock);
47309
47310- fscache_stat(&fscache_n_store_pages);
47311+ fscache_stat_unchecked(&fscache_n_store_pages);
47312 fscache_stat(&fscache_n_cop_write_page);
47313 ret = object->cache->ops->write_page(op, page);
47314 fscache_stat_d(&fscache_n_cop_write_page);
47315@@ -757,7 +757,7 @@ int __fscache_write_page(struct fscache_cookie *cookie,
47316 ASSERTCMP(cookie->def->type, !=, FSCACHE_COOKIE_TYPE_INDEX);
47317 ASSERT(PageFsCache(page));
47318
47319- fscache_stat(&fscache_n_stores);
47320+ fscache_stat_unchecked(&fscache_n_stores);
47321
47322 op = kzalloc(sizeof(*op), GFP_NOIO);
47323 if (!op)
47324@@ -808,7 +808,7 @@ int __fscache_write_page(struct fscache_cookie *cookie,
47325 spin_unlock(&cookie->stores_lock);
47326 spin_unlock(&object->lock);
47327
47328- op->op.debug_id = atomic_inc_return(&fscache_op_debug_id);
47329+ op->op.debug_id = atomic_inc_return_unchecked(&fscache_op_debug_id);
47330 op->store_limit = object->store_limit;
47331
47332 if (fscache_submit_op(object, &op->op) < 0)
47333@@ -816,8 +816,8 @@ int __fscache_write_page(struct fscache_cookie *cookie,
47334
47335 spin_unlock(&cookie->lock);
47336 radix_tree_preload_end();
47337- fscache_stat(&fscache_n_store_ops);
47338- fscache_stat(&fscache_n_stores_ok);
47339+ fscache_stat_unchecked(&fscache_n_store_ops);
47340+ fscache_stat_unchecked(&fscache_n_stores_ok);
47341
47342 /* the work queue now carries its own ref on the object */
47343 fscache_put_operation(&op->op);
47344@@ -825,14 +825,14 @@ int __fscache_write_page(struct fscache_cookie *cookie,
47345 return 0;
47346
47347 already_queued:
47348- fscache_stat(&fscache_n_stores_again);
47349+ fscache_stat_unchecked(&fscache_n_stores_again);
47350 already_pending:
47351 spin_unlock(&cookie->stores_lock);
47352 spin_unlock(&object->lock);
47353 spin_unlock(&cookie->lock);
47354 radix_tree_preload_end();
47355 kfree(op);
47356- fscache_stat(&fscache_n_stores_ok);
47357+ fscache_stat_unchecked(&fscache_n_stores_ok);
47358 _leave(" = 0");
47359 return 0;
47360
47361@@ -851,14 +851,14 @@ nobufs:
47362 spin_unlock(&cookie->lock);
47363 radix_tree_preload_end();
47364 kfree(op);
47365- fscache_stat(&fscache_n_stores_nobufs);
47366+ fscache_stat_unchecked(&fscache_n_stores_nobufs);
47367 _leave(" = -ENOBUFS");
47368 return -ENOBUFS;
47369
47370 nomem_free:
47371 kfree(op);
47372 nomem:
47373- fscache_stat(&fscache_n_stores_oom);
47374+ fscache_stat_unchecked(&fscache_n_stores_oom);
47375 _leave(" = -ENOMEM");
47376 return -ENOMEM;
47377 }
47378@@ -876,7 +876,7 @@ void __fscache_uncache_page(struct fscache_cookie *cookie, struct page *page)
47379 ASSERTCMP(cookie->def->type, !=, FSCACHE_COOKIE_TYPE_INDEX);
47380 ASSERTCMP(page, !=, NULL);
47381
47382- fscache_stat(&fscache_n_uncaches);
47383+ fscache_stat_unchecked(&fscache_n_uncaches);
47384
47385 /* cache withdrawal may beat us to it */
47386 if (!PageFsCache(page))
47387@@ -929,7 +929,7 @@ void fscache_mark_pages_cached(struct fscache_retrieval *op,
47388 unsigned long loop;
47389
47390 #ifdef CONFIG_FSCACHE_STATS
47391- atomic_add(pagevec->nr, &fscache_n_marks);
47392+ atomic_add_unchecked(pagevec->nr, &fscache_n_marks);
47393 #endif
47394
47395 for (loop = 0; loop < pagevec->nr; loop++) {
47396diff --git a/fs/fscache/stats.c b/fs/fscache/stats.c
47397index 4765190..2a067f2 100644
47398--- a/fs/fscache/stats.c
47399+++ b/fs/fscache/stats.c
47400@@ -18,95 +18,95 @@
47401 /*
47402 * operation counters
47403 */
47404-atomic_t fscache_n_op_pend;
47405-atomic_t fscache_n_op_run;
47406-atomic_t fscache_n_op_enqueue;
47407-atomic_t fscache_n_op_requeue;
47408-atomic_t fscache_n_op_deferred_release;
47409-atomic_t fscache_n_op_release;
47410-atomic_t fscache_n_op_gc;
47411-atomic_t fscache_n_op_cancelled;
47412-atomic_t fscache_n_op_rejected;
47413+atomic_unchecked_t fscache_n_op_pend;
47414+atomic_unchecked_t fscache_n_op_run;
47415+atomic_unchecked_t fscache_n_op_enqueue;
47416+atomic_unchecked_t fscache_n_op_requeue;
47417+atomic_unchecked_t fscache_n_op_deferred_release;
47418+atomic_unchecked_t fscache_n_op_release;
47419+atomic_unchecked_t fscache_n_op_gc;
47420+atomic_unchecked_t fscache_n_op_cancelled;
47421+atomic_unchecked_t fscache_n_op_rejected;
47422
47423-atomic_t fscache_n_attr_changed;
47424-atomic_t fscache_n_attr_changed_ok;
47425-atomic_t fscache_n_attr_changed_nobufs;
47426-atomic_t fscache_n_attr_changed_nomem;
47427-atomic_t fscache_n_attr_changed_calls;
47428+atomic_unchecked_t fscache_n_attr_changed;
47429+atomic_unchecked_t fscache_n_attr_changed_ok;
47430+atomic_unchecked_t fscache_n_attr_changed_nobufs;
47431+atomic_unchecked_t fscache_n_attr_changed_nomem;
47432+atomic_unchecked_t fscache_n_attr_changed_calls;
47433
47434-atomic_t fscache_n_allocs;
47435-atomic_t fscache_n_allocs_ok;
47436-atomic_t fscache_n_allocs_wait;
47437-atomic_t fscache_n_allocs_nobufs;
47438-atomic_t fscache_n_allocs_intr;
47439-atomic_t fscache_n_allocs_object_dead;
47440-atomic_t fscache_n_alloc_ops;
47441-atomic_t fscache_n_alloc_op_waits;
47442+atomic_unchecked_t fscache_n_allocs;
47443+atomic_unchecked_t fscache_n_allocs_ok;
47444+atomic_unchecked_t fscache_n_allocs_wait;
47445+atomic_unchecked_t fscache_n_allocs_nobufs;
47446+atomic_unchecked_t fscache_n_allocs_intr;
47447+atomic_unchecked_t fscache_n_allocs_object_dead;
47448+atomic_unchecked_t fscache_n_alloc_ops;
47449+atomic_unchecked_t fscache_n_alloc_op_waits;
47450
47451-atomic_t fscache_n_retrievals;
47452-atomic_t fscache_n_retrievals_ok;
47453-atomic_t fscache_n_retrievals_wait;
47454-atomic_t fscache_n_retrievals_nodata;
47455-atomic_t fscache_n_retrievals_nobufs;
47456-atomic_t fscache_n_retrievals_intr;
47457-atomic_t fscache_n_retrievals_nomem;
47458-atomic_t fscache_n_retrievals_object_dead;
47459-atomic_t fscache_n_retrieval_ops;
47460-atomic_t fscache_n_retrieval_op_waits;
47461+atomic_unchecked_t fscache_n_retrievals;
47462+atomic_unchecked_t fscache_n_retrievals_ok;
47463+atomic_unchecked_t fscache_n_retrievals_wait;
47464+atomic_unchecked_t fscache_n_retrievals_nodata;
47465+atomic_unchecked_t fscache_n_retrievals_nobufs;
47466+atomic_unchecked_t fscache_n_retrievals_intr;
47467+atomic_unchecked_t fscache_n_retrievals_nomem;
47468+atomic_unchecked_t fscache_n_retrievals_object_dead;
47469+atomic_unchecked_t fscache_n_retrieval_ops;
47470+atomic_unchecked_t fscache_n_retrieval_op_waits;
47471
47472-atomic_t fscache_n_stores;
47473-atomic_t fscache_n_stores_ok;
47474-atomic_t fscache_n_stores_again;
47475-atomic_t fscache_n_stores_nobufs;
47476-atomic_t fscache_n_stores_oom;
47477-atomic_t fscache_n_store_ops;
47478-atomic_t fscache_n_store_calls;
47479-atomic_t fscache_n_store_pages;
47480-atomic_t fscache_n_store_radix_deletes;
47481-atomic_t fscache_n_store_pages_over_limit;
47482+atomic_unchecked_t fscache_n_stores;
47483+atomic_unchecked_t fscache_n_stores_ok;
47484+atomic_unchecked_t fscache_n_stores_again;
47485+atomic_unchecked_t fscache_n_stores_nobufs;
47486+atomic_unchecked_t fscache_n_stores_oom;
47487+atomic_unchecked_t fscache_n_store_ops;
47488+atomic_unchecked_t fscache_n_store_calls;
47489+atomic_unchecked_t fscache_n_store_pages;
47490+atomic_unchecked_t fscache_n_store_radix_deletes;
47491+atomic_unchecked_t fscache_n_store_pages_over_limit;
47492
47493-atomic_t fscache_n_store_vmscan_not_storing;
47494-atomic_t fscache_n_store_vmscan_gone;
47495-atomic_t fscache_n_store_vmscan_busy;
47496-atomic_t fscache_n_store_vmscan_cancelled;
47497+atomic_unchecked_t fscache_n_store_vmscan_not_storing;
47498+atomic_unchecked_t fscache_n_store_vmscan_gone;
47499+atomic_unchecked_t fscache_n_store_vmscan_busy;
47500+atomic_unchecked_t fscache_n_store_vmscan_cancelled;
47501
47502-atomic_t fscache_n_marks;
47503-atomic_t fscache_n_uncaches;
47504+atomic_unchecked_t fscache_n_marks;
47505+atomic_unchecked_t fscache_n_uncaches;
47506
47507-atomic_t fscache_n_acquires;
47508-atomic_t fscache_n_acquires_null;
47509-atomic_t fscache_n_acquires_no_cache;
47510-atomic_t fscache_n_acquires_ok;
47511-atomic_t fscache_n_acquires_nobufs;
47512-atomic_t fscache_n_acquires_oom;
47513+atomic_unchecked_t fscache_n_acquires;
47514+atomic_unchecked_t fscache_n_acquires_null;
47515+atomic_unchecked_t fscache_n_acquires_no_cache;
47516+atomic_unchecked_t fscache_n_acquires_ok;
47517+atomic_unchecked_t fscache_n_acquires_nobufs;
47518+atomic_unchecked_t fscache_n_acquires_oom;
47519
47520-atomic_t fscache_n_updates;
47521-atomic_t fscache_n_updates_null;
47522-atomic_t fscache_n_updates_run;
47523+atomic_unchecked_t fscache_n_updates;
47524+atomic_unchecked_t fscache_n_updates_null;
47525+atomic_unchecked_t fscache_n_updates_run;
47526
47527-atomic_t fscache_n_relinquishes;
47528-atomic_t fscache_n_relinquishes_null;
47529-atomic_t fscache_n_relinquishes_waitcrt;
47530-atomic_t fscache_n_relinquishes_retire;
47531+atomic_unchecked_t fscache_n_relinquishes;
47532+atomic_unchecked_t fscache_n_relinquishes_null;
47533+atomic_unchecked_t fscache_n_relinquishes_waitcrt;
47534+atomic_unchecked_t fscache_n_relinquishes_retire;
47535
47536-atomic_t fscache_n_cookie_index;
47537-atomic_t fscache_n_cookie_data;
47538-atomic_t fscache_n_cookie_special;
47539+atomic_unchecked_t fscache_n_cookie_index;
47540+atomic_unchecked_t fscache_n_cookie_data;
47541+atomic_unchecked_t fscache_n_cookie_special;
47542
47543-atomic_t fscache_n_object_alloc;
47544-atomic_t fscache_n_object_no_alloc;
47545-atomic_t fscache_n_object_lookups;
47546-atomic_t fscache_n_object_lookups_negative;
47547-atomic_t fscache_n_object_lookups_positive;
47548-atomic_t fscache_n_object_lookups_timed_out;
47549-atomic_t fscache_n_object_created;
47550-atomic_t fscache_n_object_avail;
47551-atomic_t fscache_n_object_dead;
47552+atomic_unchecked_t fscache_n_object_alloc;
47553+atomic_unchecked_t fscache_n_object_no_alloc;
47554+atomic_unchecked_t fscache_n_object_lookups;
47555+atomic_unchecked_t fscache_n_object_lookups_negative;
47556+atomic_unchecked_t fscache_n_object_lookups_positive;
47557+atomic_unchecked_t fscache_n_object_lookups_timed_out;
47558+atomic_unchecked_t fscache_n_object_created;
47559+atomic_unchecked_t fscache_n_object_avail;
47560+atomic_unchecked_t fscache_n_object_dead;
47561
47562-atomic_t fscache_n_checkaux_none;
47563-atomic_t fscache_n_checkaux_okay;
47564-atomic_t fscache_n_checkaux_update;
47565-atomic_t fscache_n_checkaux_obsolete;
47566+atomic_unchecked_t fscache_n_checkaux_none;
47567+atomic_unchecked_t fscache_n_checkaux_okay;
47568+atomic_unchecked_t fscache_n_checkaux_update;
47569+atomic_unchecked_t fscache_n_checkaux_obsolete;
47570
47571 atomic_t fscache_n_cop_alloc_object;
47572 atomic_t fscache_n_cop_lookup_object;
47573@@ -133,113 +133,113 @@ static int fscache_stats_show(struct seq_file *m, void *v)
47574 seq_puts(m, "FS-Cache statistics\n");
47575
47576 seq_printf(m, "Cookies: idx=%u dat=%u spc=%u\n",
47577- atomic_read(&fscache_n_cookie_index),
47578- atomic_read(&fscache_n_cookie_data),
47579- atomic_read(&fscache_n_cookie_special));
47580+ atomic_read_unchecked(&fscache_n_cookie_index),
47581+ atomic_read_unchecked(&fscache_n_cookie_data),
47582+ atomic_read_unchecked(&fscache_n_cookie_special));
47583
47584 seq_printf(m, "Objects: alc=%u nal=%u avl=%u ded=%u\n",
47585- atomic_read(&fscache_n_object_alloc),
47586- atomic_read(&fscache_n_object_no_alloc),
47587- atomic_read(&fscache_n_object_avail),
47588- atomic_read(&fscache_n_object_dead));
47589+ atomic_read_unchecked(&fscache_n_object_alloc),
47590+ atomic_read_unchecked(&fscache_n_object_no_alloc),
47591+ atomic_read_unchecked(&fscache_n_object_avail),
47592+ atomic_read_unchecked(&fscache_n_object_dead));
47593 seq_printf(m, "ChkAux : non=%u ok=%u upd=%u obs=%u\n",
47594- atomic_read(&fscache_n_checkaux_none),
47595- atomic_read(&fscache_n_checkaux_okay),
47596- atomic_read(&fscache_n_checkaux_update),
47597- atomic_read(&fscache_n_checkaux_obsolete));
47598+ atomic_read_unchecked(&fscache_n_checkaux_none),
47599+ atomic_read_unchecked(&fscache_n_checkaux_okay),
47600+ atomic_read_unchecked(&fscache_n_checkaux_update),
47601+ atomic_read_unchecked(&fscache_n_checkaux_obsolete));
47602
47603 seq_printf(m, "Pages : mrk=%u unc=%u\n",
47604- atomic_read(&fscache_n_marks),
47605- atomic_read(&fscache_n_uncaches));
47606+ atomic_read_unchecked(&fscache_n_marks),
47607+ atomic_read_unchecked(&fscache_n_uncaches));
47608
47609 seq_printf(m, "Acquire: n=%u nul=%u noc=%u ok=%u nbf=%u"
47610 " oom=%u\n",
47611- atomic_read(&fscache_n_acquires),
47612- atomic_read(&fscache_n_acquires_null),
47613- atomic_read(&fscache_n_acquires_no_cache),
47614- atomic_read(&fscache_n_acquires_ok),
47615- atomic_read(&fscache_n_acquires_nobufs),
47616- atomic_read(&fscache_n_acquires_oom));
47617+ atomic_read_unchecked(&fscache_n_acquires),
47618+ atomic_read_unchecked(&fscache_n_acquires_null),
47619+ atomic_read_unchecked(&fscache_n_acquires_no_cache),
47620+ atomic_read_unchecked(&fscache_n_acquires_ok),
47621+ atomic_read_unchecked(&fscache_n_acquires_nobufs),
47622+ atomic_read_unchecked(&fscache_n_acquires_oom));
47623
47624 seq_printf(m, "Lookups: n=%u neg=%u pos=%u crt=%u tmo=%u\n",
47625- atomic_read(&fscache_n_object_lookups),
47626- atomic_read(&fscache_n_object_lookups_negative),
47627- atomic_read(&fscache_n_object_lookups_positive),
47628- atomic_read(&fscache_n_object_created),
47629- atomic_read(&fscache_n_object_lookups_timed_out));
47630+ atomic_read_unchecked(&fscache_n_object_lookups),
47631+ atomic_read_unchecked(&fscache_n_object_lookups_negative),
47632+ atomic_read_unchecked(&fscache_n_object_lookups_positive),
47633+ atomic_read_unchecked(&fscache_n_object_created),
47634+ atomic_read_unchecked(&fscache_n_object_lookups_timed_out));
47635
47636 seq_printf(m, "Updates: n=%u nul=%u run=%u\n",
47637- atomic_read(&fscache_n_updates),
47638- atomic_read(&fscache_n_updates_null),
47639- atomic_read(&fscache_n_updates_run));
47640+ atomic_read_unchecked(&fscache_n_updates),
47641+ atomic_read_unchecked(&fscache_n_updates_null),
47642+ atomic_read_unchecked(&fscache_n_updates_run));
47643
47644 seq_printf(m, "Relinqs: n=%u nul=%u wcr=%u rtr=%u\n",
47645- atomic_read(&fscache_n_relinquishes),
47646- atomic_read(&fscache_n_relinquishes_null),
47647- atomic_read(&fscache_n_relinquishes_waitcrt),
47648- atomic_read(&fscache_n_relinquishes_retire));
47649+ atomic_read_unchecked(&fscache_n_relinquishes),
47650+ atomic_read_unchecked(&fscache_n_relinquishes_null),
47651+ atomic_read_unchecked(&fscache_n_relinquishes_waitcrt),
47652+ atomic_read_unchecked(&fscache_n_relinquishes_retire));
47653
47654 seq_printf(m, "AttrChg: n=%u ok=%u nbf=%u oom=%u run=%u\n",
47655- atomic_read(&fscache_n_attr_changed),
47656- atomic_read(&fscache_n_attr_changed_ok),
47657- atomic_read(&fscache_n_attr_changed_nobufs),
47658- atomic_read(&fscache_n_attr_changed_nomem),
47659- atomic_read(&fscache_n_attr_changed_calls));
47660+ atomic_read_unchecked(&fscache_n_attr_changed),
47661+ atomic_read_unchecked(&fscache_n_attr_changed_ok),
47662+ atomic_read_unchecked(&fscache_n_attr_changed_nobufs),
47663+ atomic_read_unchecked(&fscache_n_attr_changed_nomem),
47664+ atomic_read_unchecked(&fscache_n_attr_changed_calls));
47665
47666 seq_printf(m, "Allocs : n=%u ok=%u wt=%u nbf=%u int=%u\n",
47667- atomic_read(&fscache_n_allocs),
47668- atomic_read(&fscache_n_allocs_ok),
47669- atomic_read(&fscache_n_allocs_wait),
47670- atomic_read(&fscache_n_allocs_nobufs),
47671- atomic_read(&fscache_n_allocs_intr));
47672+ atomic_read_unchecked(&fscache_n_allocs),
47673+ atomic_read_unchecked(&fscache_n_allocs_ok),
47674+ atomic_read_unchecked(&fscache_n_allocs_wait),
47675+ atomic_read_unchecked(&fscache_n_allocs_nobufs),
47676+ atomic_read_unchecked(&fscache_n_allocs_intr));
47677 seq_printf(m, "Allocs : ops=%u owt=%u abt=%u\n",
47678- atomic_read(&fscache_n_alloc_ops),
47679- atomic_read(&fscache_n_alloc_op_waits),
47680- atomic_read(&fscache_n_allocs_object_dead));
47681+ atomic_read_unchecked(&fscache_n_alloc_ops),
47682+ atomic_read_unchecked(&fscache_n_alloc_op_waits),
47683+ atomic_read_unchecked(&fscache_n_allocs_object_dead));
47684
47685 seq_printf(m, "Retrvls: n=%u ok=%u wt=%u nod=%u nbf=%u"
47686 " int=%u oom=%u\n",
47687- atomic_read(&fscache_n_retrievals),
47688- atomic_read(&fscache_n_retrievals_ok),
47689- atomic_read(&fscache_n_retrievals_wait),
47690- atomic_read(&fscache_n_retrievals_nodata),
47691- atomic_read(&fscache_n_retrievals_nobufs),
47692- atomic_read(&fscache_n_retrievals_intr),
47693- atomic_read(&fscache_n_retrievals_nomem));
47694+ atomic_read_unchecked(&fscache_n_retrievals),
47695+ atomic_read_unchecked(&fscache_n_retrievals_ok),
47696+ atomic_read_unchecked(&fscache_n_retrievals_wait),
47697+ atomic_read_unchecked(&fscache_n_retrievals_nodata),
47698+ atomic_read_unchecked(&fscache_n_retrievals_nobufs),
47699+ atomic_read_unchecked(&fscache_n_retrievals_intr),
47700+ atomic_read_unchecked(&fscache_n_retrievals_nomem));
47701 seq_printf(m, "Retrvls: ops=%u owt=%u abt=%u\n",
47702- atomic_read(&fscache_n_retrieval_ops),
47703- atomic_read(&fscache_n_retrieval_op_waits),
47704- atomic_read(&fscache_n_retrievals_object_dead));
47705+ atomic_read_unchecked(&fscache_n_retrieval_ops),
47706+ atomic_read_unchecked(&fscache_n_retrieval_op_waits),
47707+ atomic_read_unchecked(&fscache_n_retrievals_object_dead));
47708
47709 seq_printf(m, "Stores : n=%u ok=%u agn=%u nbf=%u oom=%u\n",
47710- atomic_read(&fscache_n_stores),
47711- atomic_read(&fscache_n_stores_ok),
47712- atomic_read(&fscache_n_stores_again),
47713- atomic_read(&fscache_n_stores_nobufs),
47714- atomic_read(&fscache_n_stores_oom));
47715+ atomic_read_unchecked(&fscache_n_stores),
47716+ atomic_read_unchecked(&fscache_n_stores_ok),
47717+ atomic_read_unchecked(&fscache_n_stores_again),
47718+ atomic_read_unchecked(&fscache_n_stores_nobufs),
47719+ atomic_read_unchecked(&fscache_n_stores_oom));
47720 seq_printf(m, "Stores : ops=%u run=%u pgs=%u rxd=%u olm=%u\n",
47721- atomic_read(&fscache_n_store_ops),
47722- atomic_read(&fscache_n_store_calls),
47723- atomic_read(&fscache_n_store_pages),
47724- atomic_read(&fscache_n_store_radix_deletes),
47725- atomic_read(&fscache_n_store_pages_over_limit));
47726+ atomic_read_unchecked(&fscache_n_store_ops),
47727+ atomic_read_unchecked(&fscache_n_store_calls),
47728+ atomic_read_unchecked(&fscache_n_store_pages),
47729+ atomic_read_unchecked(&fscache_n_store_radix_deletes),
47730+ atomic_read_unchecked(&fscache_n_store_pages_over_limit));
47731
47732 seq_printf(m, "VmScan : nos=%u gon=%u bsy=%u can=%u\n",
47733- atomic_read(&fscache_n_store_vmscan_not_storing),
47734- atomic_read(&fscache_n_store_vmscan_gone),
47735- atomic_read(&fscache_n_store_vmscan_busy),
47736- atomic_read(&fscache_n_store_vmscan_cancelled));
47737+ atomic_read_unchecked(&fscache_n_store_vmscan_not_storing),
47738+ atomic_read_unchecked(&fscache_n_store_vmscan_gone),
47739+ atomic_read_unchecked(&fscache_n_store_vmscan_busy),
47740+ atomic_read_unchecked(&fscache_n_store_vmscan_cancelled));
47741
47742 seq_printf(m, "Ops : pend=%u run=%u enq=%u can=%u rej=%u\n",
47743- atomic_read(&fscache_n_op_pend),
47744- atomic_read(&fscache_n_op_run),
47745- atomic_read(&fscache_n_op_enqueue),
47746- atomic_read(&fscache_n_op_cancelled),
47747- atomic_read(&fscache_n_op_rejected));
47748+ atomic_read_unchecked(&fscache_n_op_pend),
47749+ atomic_read_unchecked(&fscache_n_op_run),
47750+ atomic_read_unchecked(&fscache_n_op_enqueue),
47751+ atomic_read_unchecked(&fscache_n_op_cancelled),
47752+ atomic_read_unchecked(&fscache_n_op_rejected));
47753 seq_printf(m, "Ops : dfr=%u rel=%u gc=%u\n",
47754- atomic_read(&fscache_n_op_deferred_release),
47755- atomic_read(&fscache_n_op_release),
47756- atomic_read(&fscache_n_op_gc));
47757+ atomic_read_unchecked(&fscache_n_op_deferred_release),
47758+ atomic_read_unchecked(&fscache_n_op_release),
47759+ atomic_read_unchecked(&fscache_n_op_gc));
47760
47761 seq_printf(m, "CacheOp: alo=%d luo=%d luc=%d gro=%d\n",
47762 atomic_read(&fscache_n_cop_alloc_object),
47763diff --git a/fs/fuse/cuse.c b/fs/fuse/cuse.c
47764index ee8d550..7189d8c 100644
47765--- a/fs/fuse/cuse.c
47766+++ b/fs/fuse/cuse.c
47767@@ -585,10 +585,12 @@ static int __init cuse_init(void)
47768 INIT_LIST_HEAD(&cuse_conntbl[i]);
47769
47770 /* inherit and extend fuse_dev_operations */
47771- cuse_channel_fops = fuse_dev_operations;
47772- cuse_channel_fops.owner = THIS_MODULE;
47773- cuse_channel_fops.open = cuse_channel_open;
47774- cuse_channel_fops.release = cuse_channel_release;
47775+ pax_open_kernel();
47776+ memcpy((void *)&cuse_channel_fops, &fuse_dev_operations, sizeof(fuse_dev_operations));
47777+ *(void **)&cuse_channel_fops.owner = THIS_MODULE;
47778+ *(void **)&cuse_channel_fops.open = cuse_channel_open;
47779+ *(void **)&cuse_channel_fops.release = cuse_channel_release;
47780+ pax_close_kernel();
47781
47782 cuse_class = class_create(THIS_MODULE, "cuse");
47783 if (IS_ERR(cuse_class))
47784diff --git a/fs/fuse/dev.c b/fs/fuse/dev.c
47785index f4246cf..b4aed1d 100644
47786--- a/fs/fuse/dev.c
47787+++ b/fs/fuse/dev.c
47788@@ -1242,7 +1242,7 @@ static ssize_t fuse_dev_splice_read(struct file *in, loff_t *ppos,
47789 ret = 0;
47790 pipe_lock(pipe);
47791
47792- if (!pipe->readers) {
47793+ if (!atomic_read(&pipe->readers)) {
47794 send_sig(SIGPIPE, current, 0);
47795 if (!ret)
47796 ret = -EPIPE;
47797diff --git a/fs/fuse/dir.c b/fs/fuse/dir.c
47798index 324bc08..4fdd56e 100644
47799--- a/fs/fuse/dir.c
47800+++ b/fs/fuse/dir.c
47801@@ -1226,7 +1226,7 @@ static char *read_link(struct dentry *dentry)
47802 return link;
47803 }
47804
47805-static void free_link(char *link)
47806+static void free_link(const char *link)
47807 {
47808 if (!IS_ERR(link))
47809 free_page((unsigned long) link);
47810diff --git a/fs/gfs2/inode.c b/fs/gfs2/inode.c
47811index 753af3d..f7b021a 100644
47812--- a/fs/gfs2/inode.c
47813+++ b/fs/gfs2/inode.c
47814@@ -1498,7 +1498,7 @@ out:
47815
47816 static void gfs2_put_link(struct dentry *dentry, struct nameidata *nd, void *p)
47817 {
47818- char *s = nd_get_link(nd);
47819+ const char *s = nd_get_link(nd);
47820 if (!IS_ERR(s))
47821 kfree(s);
47822 }
47823diff --git a/fs/gfs2/quota.c b/fs/gfs2/quota.c
47824index a3bde91..2524579 100644
47825--- a/fs/gfs2/quota.c
47826+++ b/fs/gfs2/quota.c
47827@@ -497,8 +497,11 @@ int gfs2_quota_hold(struct gfs2_inode *ip, u32 uid, u32 gid)
47828 struct gfs2_quota_data **qd;
47829 int error;
47830
47831- if (ip->i_res == NULL)
47832- gfs2_rs_alloc(ip);
47833+ if (ip->i_res == NULL) {
47834+ error = gfs2_rs_alloc(ip);
47835+ if (error)
47836+ return error;
47837+ }
47838
47839 qd = ip->i_res->rs_qa_qd;
47840
47841diff --git a/fs/gfs2/rgrp.c b/fs/gfs2/rgrp.c
47842index c9ed814..4a45d5f 100644
47843--- a/fs/gfs2/rgrp.c
47844+++ b/fs/gfs2/rgrp.c
47845@@ -477,7 +477,6 @@ void gfs2_free_clones(struct gfs2_rgrpd *rgd)
47846 */
47847 int gfs2_rs_alloc(struct gfs2_inode *ip)
47848 {
47849- int error = 0;
47850 struct gfs2_blkreserv *res;
47851
47852 if (ip->i_res)
47853@@ -485,7 +484,7 @@ int gfs2_rs_alloc(struct gfs2_inode *ip)
47854
47855 res = kmem_cache_zalloc(gfs2_rsrv_cachep, GFP_NOFS);
47856 if (!res)
47857- error = -ENOMEM;
47858+ return -ENOMEM;
47859
47860 down_write(&ip->i_rw_mutex);
47861 if (ip->i_res)
47862@@ -493,7 +492,7 @@ int gfs2_rs_alloc(struct gfs2_inode *ip)
47863 else
47864 ip->i_res = res;
47865 up_write(&ip->i_rw_mutex);
47866- return error;
47867+ return 0;
47868 }
47869
47870 static void dump_rs(struct seq_file *seq, struct gfs2_blkreserv *rs)
47871diff --git a/fs/hugetlbfs/inode.c b/fs/hugetlbfs/inode.c
47872index 8349a89..51a0254 100644
47873--- a/fs/hugetlbfs/inode.c
47874+++ b/fs/hugetlbfs/inode.c
47875@@ -920,7 +920,7 @@ static struct file_system_type hugetlbfs_fs_type = {
47876 .kill_sb = kill_litter_super,
47877 };
47878
47879-static struct vfsmount *hugetlbfs_vfsmount;
47880+struct vfsmount *hugetlbfs_vfsmount;
47881
47882 static int can_do_hugetlb_shm(void)
47883 {
47884diff --git a/fs/inode.c b/fs/inode.c
47885index ac8d904..9f45d40 100644
47886--- a/fs/inode.c
47887+++ b/fs/inode.c
47888@@ -867,8 +867,8 @@ unsigned int get_next_ino(void)
47889
47890 #ifdef CONFIG_SMP
47891 if (unlikely((res & (LAST_INO_BATCH-1)) == 0)) {
47892- static atomic_t shared_last_ino;
47893- int next = atomic_add_return(LAST_INO_BATCH, &shared_last_ino);
47894+ static atomic_unchecked_t shared_last_ino;
47895+ int next = atomic_add_return_unchecked(LAST_INO_BATCH, &shared_last_ino);
47896
47897 res = next - LAST_INO_BATCH;
47898 }
47899diff --git a/fs/jffs2/erase.c b/fs/jffs2/erase.c
47900index 4a6cf28..d3a29d3 100644
47901--- a/fs/jffs2/erase.c
47902+++ b/fs/jffs2/erase.c
47903@@ -452,7 +452,8 @@ static void jffs2_mark_erased_block(struct jffs2_sb_info *c, struct jffs2_eraseb
47904 struct jffs2_unknown_node marker = {
47905 .magic = cpu_to_je16(JFFS2_MAGIC_BITMASK),
47906 .nodetype = cpu_to_je16(JFFS2_NODETYPE_CLEANMARKER),
47907- .totlen = cpu_to_je32(c->cleanmarker_size)
47908+ .totlen = cpu_to_je32(c->cleanmarker_size),
47909+ .hdr_crc = cpu_to_je32(0)
47910 };
47911
47912 jffs2_prealloc_raw_node_refs(c, jeb, 1);
47913diff --git a/fs/jffs2/wbuf.c b/fs/jffs2/wbuf.c
47914index a6597d6..41b30ec 100644
47915--- a/fs/jffs2/wbuf.c
47916+++ b/fs/jffs2/wbuf.c
47917@@ -1023,7 +1023,8 @@ static const struct jffs2_unknown_node oob_cleanmarker =
47918 {
47919 .magic = constant_cpu_to_je16(JFFS2_MAGIC_BITMASK),
47920 .nodetype = constant_cpu_to_je16(JFFS2_NODETYPE_CLEANMARKER),
47921- .totlen = constant_cpu_to_je32(8)
47922+ .totlen = constant_cpu_to_je32(8),
47923+ .hdr_crc = constant_cpu_to_je32(0)
47924 };
47925
47926 /*
47927diff --git a/fs/jfs/super.c b/fs/jfs/super.c
47928index c55c745..f67ee56 100644
47929--- a/fs/jfs/super.c
47930+++ b/fs/jfs/super.c
47931@@ -806,7 +806,7 @@ static int __init init_jfs_fs(void)
47932
47933 jfs_inode_cachep =
47934 kmem_cache_create("jfs_ip", sizeof(struct jfs_inode_info), 0,
47935- SLAB_RECLAIM_ACCOUNT|SLAB_MEM_SPREAD,
47936+ SLAB_RECLAIM_ACCOUNT|SLAB_MEM_SPREAD|SLAB_USERCOPY,
47937 init_once);
47938 if (jfs_inode_cachep == NULL)
47939 return -ENOMEM;
47940diff --git a/fs/libfs.c b/fs/libfs.c
47941index a74cb17..37fcbe4 100644
47942--- a/fs/libfs.c
47943+++ b/fs/libfs.c
47944@@ -165,6 +165,9 @@ int dcache_readdir(struct file * filp, void * dirent, filldir_t filldir)
47945
47946 for (p=q->next; p != &dentry->d_subdirs; p=p->next) {
47947 struct dentry *next;
47948+ char d_name[sizeof(next->d_iname)];
47949+ const unsigned char *name;
47950+
47951 next = list_entry(p, struct dentry, d_u.d_child);
47952 spin_lock_nested(&next->d_lock, DENTRY_D_LOCK_NESTED);
47953 if (!simple_positive(next)) {
47954@@ -174,7 +177,12 @@ int dcache_readdir(struct file * filp, void * dirent, filldir_t filldir)
47955
47956 spin_unlock(&next->d_lock);
47957 spin_unlock(&dentry->d_lock);
47958- if (filldir(dirent, next->d_name.name,
47959+ name = next->d_name.name;
47960+ if (name == next->d_iname) {
47961+ memcpy(d_name, name, next->d_name.len);
47962+ name = d_name;
47963+ }
47964+ if (filldir(dirent, name,
47965 next->d_name.len, filp->f_pos,
47966 next->d_inode->i_ino,
47967 dt_type(next->d_inode)) < 0)
47968diff --git a/fs/lockd/clntproc.c b/fs/lockd/clntproc.c
47969index 05d2912..760abfa 100644
47970--- a/fs/lockd/clntproc.c
47971+++ b/fs/lockd/clntproc.c
47972@@ -36,11 +36,11 @@ static const struct rpc_call_ops nlmclnt_cancel_ops;
47973 /*
47974 * Cookie counter for NLM requests
47975 */
47976-static atomic_t nlm_cookie = ATOMIC_INIT(0x1234);
47977+static atomic_unchecked_t nlm_cookie = ATOMIC_INIT(0x1234);
47978
47979 void nlmclnt_next_cookie(struct nlm_cookie *c)
47980 {
47981- u32 cookie = atomic_inc_return(&nlm_cookie);
47982+ u32 cookie = atomic_inc_return_unchecked(&nlm_cookie);
47983
47984 memcpy(c->data, &cookie, 4);
47985 c->len=4;
47986diff --git a/fs/locks.c b/fs/locks.c
47987index 7e81bfc..c3649aa 100644
47988--- a/fs/locks.c
47989+++ b/fs/locks.c
47990@@ -2066,16 +2066,16 @@ void locks_remove_flock(struct file *filp)
47991 return;
47992
47993 if (filp->f_op && filp->f_op->flock) {
47994- struct file_lock fl = {
47995+ struct file_lock flock = {
47996 .fl_pid = current->tgid,
47997 .fl_file = filp,
47998 .fl_flags = FL_FLOCK,
47999 .fl_type = F_UNLCK,
48000 .fl_end = OFFSET_MAX,
48001 };
48002- filp->f_op->flock(filp, F_SETLKW, &fl);
48003- if (fl.fl_ops && fl.fl_ops->fl_release_private)
48004- fl.fl_ops->fl_release_private(&fl);
48005+ filp->f_op->flock(filp, F_SETLKW, &flock);
48006+ if (flock.fl_ops && flock.fl_ops->fl_release_private)
48007+ flock.fl_ops->fl_release_private(&flock);
48008 }
48009
48010 lock_flocks();
48011diff --git a/fs/namei.c b/fs/namei.c
48012index 091c4b7..fbcb268 100644
48013--- a/fs/namei.c
48014+++ b/fs/namei.c
48015@@ -265,16 +265,32 @@ int generic_permission(struct inode *inode, int mask)
48016 if (ret != -EACCES)
48017 return ret;
48018
48019+#ifdef CONFIG_GRKERNSEC
48020+ /* we'll block if we have to log due to a denied capability use */
48021+ if (mask & MAY_NOT_BLOCK)
48022+ return -ECHILD;
48023+#endif
48024+
48025 if (S_ISDIR(inode->i_mode)) {
48026 /* DACs are overridable for directories */
48027- if (inode_capable(inode, CAP_DAC_OVERRIDE))
48028- return 0;
48029 if (!(mask & MAY_WRITE))
48030- if (inode_capable(inode, CAP_DAC_READ_SEARCH))
48031+ if (inode_capable_nolog(inode, CAP_DAC_OVERRIDE) ||
48032+ inode_capable(inode, CAP_DAC_READ_SEARCH))
48033 return 0;
48034+ if (inode_capable(inode, CAP_DAC_OVERRIDE))
48035+ return 0;
48036 return -EACCES;
48037 }
48038 /*
48039+ * Searching includes executable on directories, else just read.
48040+ */
48041+ mask &= MAY_READ | MAY_WRITE | MAY_EXEC;
48042+ if (mask == MAY_READ)
48043+ if (inode_capable_nolog(inode, CAP_DAC_OVERRIDE) ||
48044+ inode_capable(inode, CAP_DAC_READ_SEARCH))
48045+ return 0;
48046+
48047+ /*
48048 * Read/write DACs are always overridable.
48049 * Executable DACs are overridable when there is
48050 * at least one exec bit set.
48051@@ -283,14 +299,6 @@ int generic_permission(struct inode *inode, int mask)
48052 if (inode_capable(inode, CAP_DAC_OVERRIDE))
48053 return 0;
48054
48055- /*
48056- * Searching includes executable on directories, else just read.
48057- */
48058- mask &= MAY_READ | MAY_WRITE | MAY_EXEC;
48059- if (mask == MAY_READ)
48060- if (inode_capable(inode, CAP_DAC_READ_SEARCH))
48061- return 0;
48062-
48063 return -EACCES;
48064 }
48065
48066@@ -772,7 +780,7 @@ follow_link(struct path *link, struct nameidata *nd, void **p)
48067 {
48068 struct dentry *dentry = link->dentry;
48069 int error;
48070- char *s;
48071+ const char *s;
48072
48073 BUG_ON(nd->flags & LOOKUP_RCU);
48074
48075@@ -793,6 +801,12 @@ follow_link(struct path *link, struct nameidata *nd, void **p)
48076 if (error)
48077 goto out_put_nd_path;
48078
48079+ if (gr_handle_follow_link(dentry->d_parent->d_inode,
48080+ dentry->d_inode, dentry, nd->path.mnt)) {
48081+ error = -EACCES;
48082+ goto out_put_nd_path;
48083+ }
48084+
48085 nd->last_type = LAST_BIND;
48086 *p = dentry->d_inode->i_op->follow_link(dentry, nd);
48087 error = PTR_ERR(*p);
48088@@ -1550,6 +1564,8 @@ static inline int nested_symlink(struct path *path, struct nameidata *nd)
48089 break;
48090 res = walk_component(nd, path, &nd->last,
48091 nd->last_type, LOOKUP_FOLLOW);
48092+ if (res >= 0 && gr_handle_symlink_owner(&link, nd->inode))
48093+ res = -EACCES;
48094 put_link(nd, &link, cookie);
48095 } while (res > 0);
48096
48097@@ -1648,7 +1664,7 @@ EXPORT_SYMBOL(full_name_hash);
48098 static inline unsigned long hash_name(const char *name, unsigned int *hashp)
48099 {
48100 unsigned long a, b, adata, bdata, mask, hash, len;
48101- const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
48102+ static const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
48103
48104 hash = a = 0;
48105 len = -sizeof(unsigned long);
48106@@ -1943,6 +1959,8 @@ static int path_lookupat(int dfd, const char *name,
48107 if (err)
48108 break;
48109 err = lookup_last(nd, &path);
48110+ if (!err && gr_handle_symlink_owner(&link, nd->inode))
48111+ err = -EACCES;
48112 put_link(nd, &link, cookie);
48113 }
48114 }
48115@@ -1950,6 +1968,21 @@ static int path_lookupat(int dfd, const char *name,
48116 if (!err)
48117 err = complete_walk(nd);
48118
48119+ if (!(nd->flags & LOOKUP_PARENT)) {
48120+#ifdef CONFIG_GRKERNSEC
48121+ if (flags & LOOKUP_RCU) {
48122+ if (!err)
48123+ path_put(&nd->path);
48124+ err = -ECHILD;
48125+ } else
48126+#endif
48127+ if (!gr_acl_handle_hidden_file(nd->path.dentry, nd->path.mnt)) {
48128+ if (!err)
48129+ path_put(&nd->path);
48130+ err = -ENOENT;
48131+ }
48132+ }
48133+
48134 if (!err && nd->flags & LOOKUP_DIRECTORY) {
48135 if (!nd->inode->i_op->lookup) {
48136 path_put(&nd->path);
48137@@ -1977,6 +2010,15 @@ static int do_path_lookup(int dfd, const char *name,
48138 retval = path_lookupat(dfd, name, flags | LOOKUP_REVAL, nd);
48139
48140 if (likely(!retval)) {
48141+ if (*name != '/' && nd->path.dentry && nd->inode) {
48142+#ifdef CONFIG_GRKERNSEC
48143+ if (flags & LOOKUP_RCU)
48144+ return -ECHILD;
48145+#endif
48146+ if (!gr_chroot_fchdir(nd->path.dentry, nd->path.mnt))
48147+ return -ENOENT;
48148+ }
48149+
48150 if (unlikely(!audit_dummy_context())) {
48151 if (nd->path.dentry && nd->inode)
48152 audit_inode(name, nd->path.dentry);
48153@@ -2336,6 +2378,13 @@ static int may_open(struct path *path, int acc_mode, int flag)
48154 if (flag & O_NOATIME && !inode_owner_or_capable(inode))
48155 return -EPERM;
48156
48157+ if (gr_handle_rofs_blockwrite(dentry, path->mnt, acc_mode))
48158+ return -EPERM;
48159+ if (gr_handle_rawio(inode))
48160+ return -EPERM;
48161+ if (!gr_acl_handle_open(dentry, path->mnt, acc_mode))
48162+ return -EACCES;
48163+
48164 return 0;
48165 }
48166
48167@@ -2557,7 +2606,7 @@ looked_up:
48168 * cleared otherwise prior to returning.
48169 */
48170 static int lookup_open(struct nameidata *nd, struct path *path,
48171- struct file *file,
48172+ struct path *link, struct file *file,
48173 const struct open_flags *op,
48174 bool got_write, int *opened)
48175 {
48176@@ -2592,6 +2641,17 @@ static int lookup_open(struct nameidata *nd, struct path *path,
48177 /* Negative dentry, just create the file */
48178 if (!dentry->d_inode && (op->open_flag & O_CREAT)) {
48179 umode_t mode = op->mode;
48180+
48181+ if (link && gr_handle_symlink_owner(link, dir->d_inode)) {
48182+ error = -EACCES;
48183+ goto out_dput;
48184+ }
48185+
48186+ if (!gr_acl_handle_creat(dentry, dir, nd->path.mnt, op->open_flag, op->acc_mode, mode)) {
48187+ error = -EACCES;
48188+ goto out_dput;
48189+ }
48190+
48191 if (!IS_POSIXACL(dir->d_inode))
48192 mode &= ~current_umask();
48193 /*
48194@@ -2613,6 +2673,8 @@ static int lookup_open(struct nameidata *nd, struct path *path,
48195 nd->flags & LOOKUP_EXCL);
48196 if (error)
48197 goto out_dput;
48198+ else
48199+ gr_handle_create(dentry, nd->path.mnt);
48200 }
48201 out_no_open:
48202 path->dentry = dentry;
48203@@ -2627,7 +2689,7 @@ out_dput:
48204 /*
48205 * Handle the last step of open()
48206 */
48207-static int do_last(struct nameidata *nd, struct path *path,
48208+static int do_last(struct nameidata *nd, struct path *path, struct path *link,
48209 struct file *file, const struct open_flags *op,
48210 int *opened, const char *pathname)
48211 {
48212@@ -2656,16 +2718,44 @@ static int do_last(struct nameidata *nd, struct path *path,
48213 error = complete_walk(nd);
48214 if (error)
48215 return error;
48216+#ifdef CONFIG_GRKERNSEC
48217+ if (nd->flags & LOOKUP_RCU) {
48218+ error = -ECHILD;
48219+ goto out;
48220+ }
48221+#endif
48222+ if (!gr_acl_handle_hidden_file(nd->path.dentry, nd->path.mnt)) {
48223+ error = -ENOENT;
48224+ goto out;
48225+ }
48226 audit_inode(pathname, nd->path.dentry);
48227 if (open_flag & O_CREAT) {
48228 error = -EISDIR;
48229 goto out;
48230 }
48231+ if (link && gr_handle_symlink_owner(link, nd->inode)) {
48232+ error = -EACCES;
48233+ goto out;
48234+ }
48235 goto finish_open;
48236 case LAST_BIND:
48237 error = complete_walk(nd);
48238 if (error)
48239 return error;
48240+#ifdef CONFIG_GRKERNSEC
48241+ if (nd->flags & LOOKUP_RCU) {
48242+ error = -ECHILD;
48243+ goto out;
48244+ }
48245+#endif
48246+ if (!gr_acl_handle_hidden_file(dir, nd->path.mnt)) {
48247+ error = -ENOENT;
48248+ goto out;
48249+ }
48250+ if (link && gr_handle_symlink_owner(link, nd->inode)) {
48251+ error = -EACCES;
48252+ goto out;
48253+ }
48254 audit_inode(pathname, dir);
48255 goto finish_open;
48256 }
48257@@ -2714,7 +2804,7 @@ retry_lookup:
48258 */
48259 }
48260 mutex_lock(&dir->d_inode->i_mutex);
48261- error = lookup_open(nd, path, file, op, got_write, opened);
48262+ error = lookup_open(nd, path, link, file, op, got_write, opened);
48263 mutex_unlock(&dir->d_inode->i_mutex);
48264
48265 if (error <= 0) {
48266@@ -2738,11 +2828,28 @@ retry_lookup:
48267 goto finish_open_created;
48268 }
48269
48270+ if (!gr_acl_handle_hidden_file(path->dentry, nd->path.mnt)) {
48271+ error = -ENOENT;
48272+ goto exit_dput;
48273+ }
48274+ if (link && gr_handle_symlink_owner(link, path->dentry->d_inode)) {
48275+ error = -EACCES;
48276+ goto exit_dput;
48277+ }
48278+
48279 /*
48280 * create/update audit record if it already exists.
48281 */
48282- if (path->dentry->d_inode)
48283+ if (path->dentry->d_inode) {
48284+ /* only check if O_CREAT is specified, all other checks need to go
48285+ into may_open */
48286+ if (gr_handle_fifo(path->dentry, path->mnt, dir, open_flag, acc_mode)) {
48287+ error = -EACCES;
48288+ goto exit_dput;
48289+ }
48290+
48291 audit_inode(pathname, path->dentry);
48292+ }
48293
48294 /*
48295 * If atomic_open() acquired write access it is dropped now due to
48296@@ -2783,6 +2890,11 @@ finish_lookup:
48297 }
48298 }
48299 BUG_ON(inode != path->dentry->d_inode);
48300+ /* if we're resolving a symlink to another symlink */
48301+ if (link && gr_handle_symlink_owner(link, inode)) {
48302+ error = -EACCES;
48303+ goto out;
48304+ }
48305 return 1;
48306 }
48307
48308@@ -2792,7 +2904,6 @@ finish_lookup:
48309 save_parent.dentry = nd->path.dentry;
48310 save_parent.mnt = mntget(path->mnt);
48311 nd->path.dentry = path->dentry;
48312-
48313 }
48314 nd->inode = inode;
48315 /* Why this, you ask? _Now_ we might have grown LOOKUP_JUMPED... */
48316@@ -2801,6 +2912,22 @@ finish_lookup:
48317 path_put(&save_parent);
48318 return error;
48319 }
48320+
48321+#ifdef CONFIG_GRKERNSEC
48322+ if (nd->flags & LOOKUP_RCU) {
48323+ error = -ECHILD;
48324+ goto out;
48325+ }
48326+#endif
48327+ if (!gr_acl_handle_hidden_file(nd->path.dentry, nd->path.mnt)) {
48328+ error = -ENOENT;
48329+ goto out;
48330+ }
48331+ if (link && gr_handle_symlink_owner(link, nd->inode)) {
48332+ error = -EACCES;
48333+ goto out;
48334+ }
48335+
48336 error = -EISDIR;
48337 if ((open_flag & O_CREAT) && S_ISDIR(nd->inode->i_mode))
48338 goto out;
48339@@ -2899,7 +3026,7 @@ static struct file *path_openat(int dfd, const char *pathname,
48340 if (unlikely(error))
48341 goto out;
48342
48343- error = do_last(nd, &path, file, op, &opened, pathname);
48344+ error = do_last(nd, &path, NULL, file, op, &opened, pathname);
48345 while (unlikely(error > 0)) { /* trailing symlink */
48346 struct path link = path;
48347 void *cookie;
48348@@ -2917,7 +3044,7 @@ static struct file *path_openat(int dfd, const char *pathname,
48349 error = follow_link(&link, nd, &cookie);
48350 if (unlikely(error))
48351 break;
48352- error = do_last(nd, &path, file, op, &opened, pathname);
48353+ error = do_last(nd, &path, &link, file, op, &opened, pathname);
48354 put_link(nd, &link, cookie);
48355 }
48356 out:
48357@@ -3006,8 +3133,12 @@ struct dentry *kern_path_create(int dfd, const char *pathname, struct path *path
48358 goto unlock;
48359
48360 error = -EEXIST;
48361- if (dentry->d_inode)
48362+ if (dentry->d_inode) {
48363+ if (!gr_acl_handle_hidden_file(dentry, nd.path.mnt)) {
48364+ error = -ENOENT;
48365+ }
48366 goto fail;
48367+ }
48368 /*
48369 * Special case - lookup gave negative, but... we had foo/bar/
48370 * From the vfs_mknod() POV we just have a negative dentry -
48371@@ -3058,6 +3189,20 @@ struct dentry *user_path_create(int dfd, const char __user *pathname, struct pat
48372 }
48373 EXPORT_SYMBOL(user_path_create);
48374
48375+static struct dentry *user_path_create_with_name(int dfd, const char __user *pathname, struct path *path, char **to, int is_dir)
48376+{
48377+ char *tmp = getname(pathname);
48378+ struct dentry *res;
48379+ if (IS_ERR(tmp))
48380+ return ERR_CAST(tmp);
48381+ res = kern_path_create(dfd, tmp, path, is_dir);
48382+ if (IS_ERR(res))
48383+ putname(tmp);
48384+ else
48385+ *to = tmp;
48386+ return res;
48387+}
48388+
48389 int vfs_mknod(struct inode *dir, struct dentry *dentry, umode_t mode, dev_t dev)
48390 {
48391 int error = may_create(dir, dentry);
48392@@ -3119,6 +3264,17 @@ SYSCALL_DEFINE4(mknodat, int, dfd, const char __user *, filename, umode_t, mode,
48393
48394 if (!IS_POSIXACL(path.dentry->d_inode))
48395 mode &= ~current_umask();
48396+
48397+ if (gr_handle_chroot_mknod(dentry, path.mnt, mode)) {
48398+ error = -EPERM;
48399+ goto out;
48400+ }
48401+
48402+ if (!gr_acl_handle_mknod(dentry, path.dentry, path.mnt, mode)) {
48403+ error = -EACCES;
48404+ goto out;
48405+ }
48406+
48407 error = security_path_mknod(&path, dentry, mode, dev);
48408 if (error)
48409 goto out;
48410@@ -3135,6 +3291,8 @@ SYSCALL_DEFINE4(mknodat, int, dfd, const char __user *, filename, umode_t, mode,
48411 break;
48412 }
48413 out:
48414+ if (!error)
48415+ gr_handle_create(dentry, path.mnt);
48416 done_path_create(&path, dentry);
48417 return error;
48418 }
48419@@ -3181,9 +3339,18 @@ SYSCALL_DEFINE3(mkdirat, int, dfd, const char __user *, pathname, umode_t, mode)
48420
48421 if (!IS_POSIXACL(path.dentry->d_inode))
48422 mode &= ~current_umask();
48423+
48424+ if (!gr_acl_handle_mkdir(dentry, path.dentry, path.mnt)) {
48425+ error = -EACCES;
48426+ goto out;
48427+ }
48428+
48429 error = security_path_mkdir(&path, dentry, mode);
48430 if (!error)
48431 error = vfs_mkdir(path.dentry->d_inode, dentry, mode);
48432+ if (!error)
48433+ gr_handle_create(dentry, path.mnt);
48434+out:
48435 done_path_create(&path, dentry);
48436 return error;
48437 }
48438@@ -3260,6 +3427,8 @@ static long do_rmdir(int dfd, const char __user *pathname)
48439 char * name;
48440 struct dentry *dentry;
48441 struct nameidata nd;
48442+ ino_t saved_ino = 0;
48443+ dev_t saved_dev = 0;
48444
48445 error = user_path_parent(dfd, pathname, &nd, &name);
48446 if (error)
48447@@ -3291,10 +3460,21 @@ static long do_rmdir(int dfd, const char __user *pathname)
48448 error = -ENOENT;
48449 goto exit3;
48450 }
48451+
48452+ saved_ino = dentry->d_inode->i_ino;
48453+ saved_dev = gr_get_dev_from_dentry(dentry);
48454+
48455+ if (!gr_acl_handle_rmdir(dentry, nd.path.mnt)) {
48456+ error = -EACCES;
48457+ goto exit3;
48458+ }
48459+
48460 error = security_path_rmdir(&nd.path, dentry);
48461 if (error)
48462 goto exit3;
48463 error = vfs_rmdir(nd.path.dentry->d_inode, dentry);
48464+ if (!error && (saved_dev || saved_ino))
48465+ gr_handle_delete(saved_ino, saved_dev);
48466 exit3:
48467 dput(dentry);
48468 exit2:
48469@@ -3356,6 +3536,8 @@ static long do_unlinkat(int dfd, const char __user *pathname)
48470 struct dentry *dentry;
48471 struct nameidata nd;
48472 struct inode *inode = NULL;
48473+ ino_t saved_ino = 0;
48474+ dev_t saved_dev = 0;
48475
48476 error = user_path_parent(dfd, pathname, &nd, &name);
48477 if (error)
48478@@ -3381,10 +3563,22 @@ static long do_unlinkat(int dfd, const char __user *pathname)
48479 if (!inode)
48480 goto slashes;
48481 ihold(inode);
48482+
48483+ if (inode->i_nlink <= 1) {
48484+ saved_ino = inode->i_ino;
48485+ saved_dev = gr_get_dev_from_dentry(dentry);
48486+ }
48487+ if (!gr_acl_handle_unlink(dentry, nd.path.mnt)) {
48488+ error = -EACCES;
48489+ goto exit2;
48490+ }
48491+
48492 error = security_path_unlink(&nd.path, dentry);
48493 if (error)
48494 goto exit2;
48495 error = vfs_unlink(nd.path.dentry->d_inode, dentry);
48496+ if (!error && (saved_ino || saved_dev))
48497+ gr_handle_delete(saved_ino, saved_dev);
48498 exit2:
48499 dput(dentry);
48500 }
48501@@ -3456,9 +3650,17 @@ SYSCALL_DEFINE3(symlinkat, const char __user *, oldname,
48502 if (IS_ERR(dentry))
48503 goto out_putname;
48504
48505+ if (!gr_acl_handle_symlink(dentry, path.dentry, path.mnt, from)) {
48506+ error = -EACCES;
48507+ goto out;
48508+ }
48509+
48510 error = security_path_symlink(&path, dentry, from);
48511 if (!error)
48512 error = vfs_symlink(path.dentry->d_inode, dentry, from);
48513+ if (!error)
48514+ gr_handle_create(dentry, path.mnt);
48515+out:
48516 done_path_create(&path, dentry);
48517 out_putname:
48518 putname(from);
48519@@ -3528,6 +3730,7 @@ SYSCALL_DEFINE5(linkat, int, olddfd, const char __user *, oldname,
48520 {
48521 struct dentry *new_dentry;
48522 struct path old_path, new_path;
48523+ char *to = NULL;
48524 int how = 0;
48525 int error;
48526
48527@@ -3551,7 +3754,7 @@ SYSCALL_DEFINE5(linkat, int, olddfd, const char __user *, oldname,
48528 if (error)
48529 return error;
48530
48531- new_dentry = user_path_create(newdfd, newname, &new_path, 0);
48532+ new_dentry = user_path_create_with_name(newdfd, newname, &new_path, &to, 0);
48533 error = PTR_ERR(new_dentry);
48534 if (IS_ERR(new_dentry))
48535 goto out;
48536@@ -3562,11 +3765,28 @@ SYSCALL_DEFINE5(linkat, int, olddfd, const char __user *, oldname,
48537 error = may_linkat(&old_path);
48538 if (unlikely(error))
48539 goto out_dput;
48540+
48541+ if (gr_handle_hardlink(old_path.dentry, old_path.mnt,
48542+ old_path.dentry->d_inode,
48543+ old_path.dentry->d_inode->i_mode, to)) {
48544+ error = -EACCES;
48545+ goto out_dput;
48546+ }
48547+
48548+ if (!gr_acl_handle_link(new_dentry, new_path.dentry, new_path.mnt,
48549+ old_path.dentry, old_path.mnt, to)) {
48550+ error = -EACCES;
48551+ goto out_dput;
48552+ }
48553+
48554 error = security_path_link(old_path.dentry, &new_path, new_dentry);
48555 if (error)
48556 goto out_dput;
48557 error = vfs_link(old_path.dentry, new_path.dentry->d_inode, new_dentry);
48558+ if (!error)
48559+ gr_handle_create(new_dentry, new_path.mnt);
48560 out_dput:
48561+ putname(to);
48562 done_path_create(&new_path, new_dentry);
48563 out:
48564 path_put(&old_path);
48565@@ -3802,12 +4022,21 @@ SYSCALL_DEFINE4(renameat, int, olddfd, const char __user *, oldname,
48566 if (new_dentry == trap)
48567 goto exit5;
48568
48569+ error = gr_acl_handle_rename(new_dentry, new_dir, newnd.path.mnt,
48570+ old_dentry, old_dir->d_inode, oldnd.path.mnt,
48571+ to);
48572+ if (error)
48573+ goto exit5;
48574+
48575 error = security_path_rename(&oldnd.path, old_dentry,
48576 &newnd.path, new_dentry);
48577 if (error)
48578 goto exit5;
48579 error = vfs_rename(old_dir->d_inode, old_dentry,
48580 new_dir->d_inode, new_dentry);
48581+ if (!error)
48582+ gr_handle_rename(old_dir->d_inode, new_dir->d_inode, old_dentry,
48583+ new_dentry, oldnd.path.mnt, new_dentry->d_inode ? 1 : 0);
48584 exit5:
48585 dput(new_dentry);
48586 exit4:
48587@@ -3832,6 +4061,8 @@ SYSCALL_DEFINE2(rename, const char __user *, oldname, const char __user *, newna
48588
48589 int vfs_readlink(struct dentry *dentry, char __user *buffer, int buflen, const char *link)
48590 {
48591+ char tmpbuf[64];
48592+ const char *newlink;
48593 int len;
48594
48595 len = PTR_ERR(link);
48596@@ -3841,7 +4072,14 @@ int vfs_readlink(struct dentry *dentry, char __user *buffer, int buflen, const c
48597 len = strlen(link);
48598 if (len > (unsigned) buflen)
48599 len = buflen;
48600- if (copy_to_user(buffer, link, len))
48601+
48602+ if (len < sizeof(tmpbuf)) {
48603+ memcpy(tmpbuf, link, len);
48604+ newlink = tmpbuf;
48605+ } else
48606+ newlink = link;
48607+
48608+ if (copy_to_user(buffer, newlink, len))
48609 len = -EFAULT;
48610 out:
48611 return len;
48612diff --git a/fs/namespace.c b/fs/namespace.c
48613index 7bdf790..eb79c4b 100644
48614--- a/fs/namespace.c
48615+++ b/fs/namespace.c
48616@@ -1212,6 +1212,9 @@ static int do_umount(struct mount *mnt, int flags)
48617 if (!(sb->s_flags & MS_RDONLY))
48618 retval = do_remount_sb(sb, MS_RDONLY, NULL, 0);
48619 up_write(&sb->s_umount);
48620+
48621+ gr_log_remount(mnt->mnt_devname, retval);
48622+
48623 return retval;
48624 }
48625
48626@@ -1231,6 +1234,9 @@ static int do_umount(struct mount *mnt, int flags)
48627 br_write_unlock(&vfsmount_lock);
48628 up_write(&namespace_sem);
48629 release_mounts(&umount_list);
48630+
48631+ gr_log_unmount(mnt->mnt_devname, retval);
48632+
48633 return retval;
48634 }
48635
48636@@ -2244,6 +2250,16 @@ long do_mount(char *dev_name, char *dir_name, char *type_page,
48637 MS_NOATIME | MS_NODIRATIME | MS_RELATIME| MS_KERNMOUNT |
48638 MS_STRICTATIME);
48639
48640+ if (gr_handle_rofs_mount(path.dentry, path.mnt, mnt_flags)) {
48641+ retval = -EPERM;
48642+ goto dput_out;
48643+ }
48644+
48645+ if (gr_handle_chroot_mount(path.dentry, path.mnt, dev_name)) {
48646+ retval = -EPERM;
48647+ goto dput_out;
48648+ }
48649+
48650 if (flags & MS_REMOUNT)
48651 retval = do_remount(&path, flags & ~MS_REMOUNT, mnt_flags,
48652 data_page);
48653@@ -2258,6 +2274,9 @@ long do_mount(char *dev_name, char *dir_name, char *type_page,
48654 dev_name, data_page);
48655 dput_out:
48656 path_put(&path);
48657+
48658+ gr_log_mount(dev_name, dir_name, retval);
48659+
48660 return retval;
48661 }
48662
48663@@ -2516,6 +2535,11 @@ SYSCALL_DEFINE2(pivot_root, const char __user *, new_root,
48664 if (error)
48665 goto out2;
48666
48667+ if (gr_handle_chroot_pivot()) {
48668+ error = -EPERM;
48669+ goto out2;
48670+ }
48671+
48672 get_fs_root(current->fs, &root);
48673 error = lock_mount(&old);
48674 if (error)
48675diff --git a/fs/nfs/inode.c b/fs/nfs/inode.c
48676index 9b47610..066975e 100644
48677--- a/fs/nfs/inode.c
48678+++ b/fs/nfs/inode.c
48679@@ -1026,16 +1026,16 @@ static int nfs_size_need_update(const struct inode *inode, const struct nfs_fatt
48680 return nfs_size_to_loff_t(fattr->size) > i_size_read(inode);
48681 }
48682
48683-static atomic_long_t nfs_attr_generation_counter;
48684+static atomic_long_unchecked_t nfs_attr_generation_counter;
48685
48686 static unsigned long nfs_read_attr_generation_counter(void)
48687 {
48688- return atomic_long_read(&nfs_attr_generation_counter);
48689+ return atomic_long_read_unchecked(&nfs_attr_generation_counter);
48690 }
48691
48692 unsigned long nfs_inc_attr_generation_counter(void)
48693 {
48694- return atomic_long_inc_return(&nfs_attr_generation_counter);
48695+ return atomic_long_inc_return_unchecked(&nfs_attr_generation_counter);
48696 }
48697
48698 void nfs_fattr_init(struct nfs_fattr *fattr)
48699diff --git a/fs/nfsd/vfs.c b/fs/nfsd/vfs.c
48700index a9269f1..5490437 100644
48701--- a/fs/nfsd/vfs.c
48702+++ b/fs/nfsd/vfs.c
48703@@ -941,7 +941,7 @@ nfsd_vfs_read(struct svc_rqst *rqstp, struct svc_fh *fhp, struct file *file,
48704 } else {
48705 oldfs = get_fs();
48706 set_fs(KERNEL_DS);
48707- host_err = vfs_readv(file, (struct iovec __user *)vec, vlen, &offset);
48708+ host_err = vfs_readv(file, (struct iovec __force_user *)vec, vlen, &offset);
48709 set_fs(oldfs);
48710 }
48711
48712@@ -1045,7 +1045,7 @@ nfsd_vfs_write(struct svc_rqst *rqstp, struct svc_fh *fhp, struct file *file,
48713
48714 /* Write the data. */
48715 oldfs = get_fs(); set_fs(KERNEL_DS);
48716- host_err = vfs_writev(file, (struct iovec __user *)vec, vlen, &offset);
48717+ host_err = vfs_writev(file, (struct iovec __force_user *)vec, vlen, &offset);
48718 set_fs(oldfs);
48719 if (host_err < 0)
48720 goto out_nfserr;
48721@@ -1581,7 +1581,7 @@ nfsd_readlink(struct svc_rqst *rqstp, struct svc_fh *fhp, char *buf, int *lenp)
48722 */
48723
48724 oldfs = get_fs(); set_fs(KERNEL_DS);
48725- host_err = inode->i_op->readlink(path.dentry, buf, *lenp);
48726+ host_err = inode->i_op->readlink(path.dentry, (char __force_user *)buf, *lenp);
48727 set_fs(oldfs);
48728
48729 if (host_err < 0)
48730diff --git a/fs/notify/fanotify/fanotify_user.c b/fs/notify/fanotify/fanotify_user.c
48731index d438036..0ecadde 100644
48732--- a/fs/notify/fanotify/fanotify_user.c
48733+++ b/fs/notify/fanotify/fanotify_user.c
48734@@ -274,7 +274,8 @@ static ssize_t copy_event_to_user(struct fsnotify_group *group,
48735 goto out_close_fd;
48736
48737 ret = -EFAULT;
48738- if (copy_to_user(buf, &fanotify_event_metadata,
48739+ if (fanotify_event_metadata.event_len > sizeof fanotify_event_metadata ||
48740+ copy_to_user(buf, &fanotify_event_metadata,
48741 fanotify_event_metadata.event_len))
48742 goto out_kill_access_response;
48743
48744diff --git a/fs/notify/notification.c b/fs/notify/notification.c
48745index c887b13..0fdf472 100644
48746--- a/fs/notify/notification.c
48747+++ b/fs/notify/notification.c
48748@@ -57,7 +57,7 @@ static struct kmem_cache *fsnotify_event_holder_cachep;
48749 * get set to 0 so it will never get 'freed'
48750 */
48751 static struct fsnotify_event *q_overflow_event;
48752-static atomic_t fsnotify_sync_cookie = ATOMIC_INIT(0);
48753+static atomic_unchecked_t fsnotify_sync_cookie = ATOMIC_INIT(0);
48754
48755 /**
48756 * fsnotify_get_cookie - return a unique cookie for use in synchronizing events.
48757@@ -65,7 +65,7 @@ static atomic_t fsnotify_sync_cookie = ATOMIC_INIT(0);
48758 */
48759 u32 fsnotify_get_cookie(void)
48760 {
48761- return atomic_inc_return(&fsnotify_sync_cookie);
48762+ return atomic_inc_return_unchecked(&fsnotify_sync_cookie);
48763 }
48764 EXPORT_SYMBOL_GPL(fsnotify_get_cookie);
48765
48766diff --git a/fs/ntfs/dir.c b/fs/ntfs/dir.c
48767index 99e3610..02c1068 100644
48768--- a/fs/ntfs/dir.c
48769+++ b/fs/ntfs/dir.c
48770@@ -1329,7 +1329,7 @@ find_next_index_buffer:
48771 ia = (INDEX_ALLOCATION*)(kaddr + (ia_pos & ~PAGE_CACHE_MASK &
48772 ~(s64)(ndir->itype.index.block_size - 1)));
48773 /* Bounds checks. */
48774- if (unlikely((u8*)ia < kaddr || (u8*)ia > kaddr + PAGE_CACHE_SIZE)) {
48775+ if (unlikely(!kaddr || (u8*)ia < kaddr || (u8*)ia > kaddr + PAGE_CACHE_SIZE)) {
48776 ntfs_error(sb, "Out of bounds check failed. Corrupt directory "
48777 "inode 0x%lx or driver bug.", vdir->i_ino);
48778 goto err_out;
48779diff --git a/fs/ntfs/file.c b/fs/ntfs/file.c
48780index 1ecf464..e1ff8bf 100644
48781--- a/fs/ntfs/file.c
48782+++ b/fs/ntfs/file.c
48783@@ -2232,6 +2232,6 @@ const struct inode_operations ntfs_file_inode_ops = {
48784 #endif /* NTFS_RW */
48785 };
48786
48787-const struct file_operations ntfs_empty_file_ops = {};
48788+const struct file_operations ntfs_empty_file_ops __read_only;
48789
48790-const struct inode_operations ntfs_empty_inode_ops = {};
48791+const struct inode_operations ntfs_empty_inode_ops __read_only;
48792diff --git a/fs/ocfs2/localalloc.c b/fs/ocfs2/localalloc.c
48793index a9f78c7..ed8a381 100644
48794--- a/fs/ocfs2/localalloc.c
48795+++ b/fs/ocfs2/localalloc.c
48796@@ -1279,7 +1279,7 @@ static int ocfs2_local_alloc_slide_window(struct ocfs2_super *osb,
48797 goto bail;
48798 }
48799
48800- atomic_inc(&osb->alloc_stats.moves);
48801+ atomic_inc_unchecked(&osb->alloc_stats.moves);
48802
48803 bail:
48804 if (handle)
48805diff --git a/fs/ocfs2/ocfs2.h b/fs/ocfs2/ocfs2.h
48806index d355e6e..578d905 100644
48807--- a/fs/ocfs2/ocfs2.h
48808+++ b/fs/ocfs2/ocfs2.h
48809@@ -235,11 +235,11 @@ enum ocfs2_vol_state
48810
48811 struct ocfs2_alloc_stats
48812 {
48813- atomic_t moves;
48814- atomic_t local_data;
48815- atomic_t bitmap_data;
48816- atomic_t bg_allocs;
48817- atomic_t bg_extends;
48818+ atomic_unchecked_t moves;
48819+ atomic_unchecked_t local_data;
48820+ atomic_unchecked_t bitmap_data;
48821+ atomic_unchecked_t bg_allocs;
48822+ atomic_unchecked_t bg_extends;
48823 };
48824
48825 enum ocfs2_local_alloc_state
48826diff --git a/fs/ocfs2/suballoc.c b/fs/ocfs2/suballoc.c
48827index f169da4..9112253 100644
48828--- a/fs/ocfs2/suballoc.c
48829+++ b/fs/ocfs2/suballoc.c
48830@@ -872,7 +872,7 @@ static int ocfs2_reserve_suballoc_bits(struct ocfs2_super *osb,
48831 mlog_errno(status);
48832 goto bail;
48833 }
48834- atomic_inc(&osb->alloc_stats.bg_extends);
48835+ atomic_inc_unchecked(&osb->alloc_stats.bg_extends);
48836
48837 /* You should never ask for this much metadata */
48838 BUG_ON(bits_wanted >
48839@@ -2008,7 +2008,7 @@ int ocfs2_claim_metadata(handle_t *handle,
48840 mlog_errno(status);
48841 goto bail;
48842 }
48843- atomic_inc(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
48844+ atomic_inc_unchecked(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
48845
48846 *suballoc_loc = res.sr_bg_blkno;
48847 *suballoc_bit_start = res.sr_bit_offset;
48848@@ -2172,7 +2172,7 @@ int ocfs2_claim_new_inode_at_loc(handle_t *handle,
48849 trace_ocfs2_claim_new_inode_at_loc((unsigned long long)di_blkno,
48850 res->sr_bits);
48851
48852- atomic_inc(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
48853+ atomic_inc_unchecked(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
48854
48855 BUG_ON(res->sr_bits != 1);
48856
48857@@ -2214,7 +2214,7 @@ int ocfs2_claim_new_inode(handle_t *handle,
48858 mlog_errno(status);
48859 goto bail;
48860 }
48861- atomic_inc(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
48862+ atomic_inc_unchecked(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
48863
48864 BUG_ON(res.sr_bits != 1);
48865
48866@@ -2318,7 +2318,7 @@ int __ocfs2_claim_clusters(handle_t *handle,
48867 cluster_start,
48868 num_clusters);
48869 if (!status)
48870- atomic_inc(&osb->alloc_stats.local_data);
48871+ atomic_inc_unchecked(&osb->alloc_stats.local_data);
48872 } else {
48873 if (min_clusters > (osb->bitmap_cpg - 1)) {
48874 /* The only paths asking for contiguousness
48875@@ -2344,7 +2344,7 @@ int __ocfs2_claim_clusters(handle_t *handle,
48876 ocfs2_desc_bitmap_to_cluster_off(ac->ac_inode,
48877 res.sr_bg_blkno,
48878 res.sr_bit_offset);
48879- atomic_inc(&osb->alloc_stats.bitmap_data);
48880+ atomic_inc_unchecked(&osb->alloc_stats.bitmap_data);
48881 *num_clusters = res.sr_bits;
48882 }
48883 }
48884diff --git a/fs/ocfs2/super.c b/fs/ocfs2/super.c
48885index 68f4541..89cfe6a 100644
48886--- a/fs/ocfs2/super.c
48887+++ b/fs/ocfs2/super.c
48888@@ -301,11 +301,11 @@ static int ocfs2_osb_dump(struct ocfs2_super *osb, char *buf, int len)
48889 "%10s => GlobalAllocs: %d LocalAllocs: %d "
48890 "SubAllocs: %d LAWinMoves: %d SAExtends: %d\n",
48891 "Stats",
48892- atomic_read(&osb->alloc_stats.bitmap_data),
48893- atomic_read(&osb->alloc_stats.local_data),
48894- atomic_read(&osb->alloc_stats.bg_allocs),
48895- atomic_read(&osb->alloc_stats.moves),
48896- atomic_read(&osb->alloc_stats.bg_extends));
48897+ atomic_read_unchecked(&osb->alloc_stats.bitmap_data),
48898+ atomic_read_unchecked(&osb->alloc_stats.local_data),
48899+ atomic_read_unchecked(&osb->alloc_stats.bg_allocs),
48900+ atomic_read_unchecked(&osb->alloc_stats.moves),
48901+ atomic_read_unchecked(&osb->alloc_stats.bg_extends));
48902
48903 out += snprintf(buf + out, len - out,
48904 "%10s => State: %u Descriptor: %llu Size: %u bits "
48905@@ -2116,11 +2116,11 @@ static int ocfs2_initialize_super(struct super_block *sb,
48906 spin_lock_init(&osb->osb_xattr_lock);
48907 ocfs2_init_steal_slots(osb);
48908
48909- atomic_set(&osb->alloc_stats.moves, 0);
48910- atomic_set(&osb->alloc_stats.local_data, 0);
48911- atomic_set(&osb->alloc_stats.bitmap_data, 0);
48912- atomic_set(&osb->alloc_stats.bg_allocs, 0);
48913- atomic_set(&osb->alloc_stats.bg_extends, 0);
48914+ atomic_set_unchecked(&osb->alloc_stats.moves, 0);
48915+ atomic_set_unchecked(&osb->alloc_stats.local_data, 0);
48916+ atomic_set_unchecked(&osb->alloc_stats.bitmap_data, 0);
48917+ atomic_set_unchecked(&osb->alloc_stats.bg_allocs, 0);
48918+ atomic_set_unchecked(&osb->alloc_stats.bg_extends, 0);
48919
48920 /* Copy the blockcheck stats from the superblock probe */
48921 osb->osb_ecc_stats = *stats;
48922diff --git a/fs/open.c b/fs/open.c
48923index e1f2cdb..3bd5f39 100644
48924--- a/fs/open.c
48925+++ b/fs/open.c
48926@@ -31,6 +31,8 @@
48927 #include <linux/ima.h>
48928 #include <linux/dnotify.h>
48929
48930+#define CREATE_TRACE_POINTS
48931+#include <trace/events/fs.h>
48932 #include "internal.h"
48933
48934 int do_truncate(struct dentry *dentry, loff_t length, unsigned int time_attrs,
48935@@ -112,6 +114,10 @@ static long do_sys_truncate(const char __user *pathname, loff_t length)
48936 error = locks_verify_truncate(inode, NULL, length);
48937 if (!error)
48938 error = security_path_truncate(&path);
48939+
48940+ if (!error && !gr_acl_handle_truncate(path.dentry, path.mnt))
48941+ error = -EACCES;
48942+
48943 if (!error)
48944 error = do_truncate(path.dentry, length, 0, NULL);
48945
48946@@ -364,6 +370,9 @@ SYSCALL_DEFINE3(faccessat, int, dfd, const char __user *, filename, int, mode)
48947 if (__mnt_is_readonly(path.mnt))
48948 res = -EROFS;
48949
48950+ if (!res && !gr_acl_handle_access(path.dentry, path.mnt, mode))
48951+ res = -EACCES;
48952+
48953 out_path_release:
48954 path_put(&path);
48955 out:
48956@@ -390,6 +399,8 @@ SYSCALL_DEFINE1(chdir, const char __user *, filename)
48957 if (error)
48958 goto dput_and_out;
48959
48960+ gr_log_chdir(path.dentry, path.mnt);
48961+
48962 set_fs_pwd(current->fs, &path);
48963
48964 dput_and_out:
48965@@ -416,6 +427,13 @@ SYSCALL_DEFINE1(fchdir, unsigned int, fd)
48966 goto out_putf;
48967
48968 error = inode_permission(inode, MAY_EXEC | MAY_CHDIR);
48969+
48970+ if (!error && !gr_chroot_fchdir(file->f_path.dentry, file->f_path.mnt))
48971+ error = -EPERM;
48972+
48973+ if (!error)
48974+ gr_log_chdir(file->f_path.dentry, file->f_path.mnt);
48975+
48976 if (!error)
48977 set_fs_pwd(current->fs, &file->f_path);
48978 out_putf:
48979@@ -444,7 +462,13 @@ SYSCALL_DEFINE1(chroot, const char __user *, filename)
48980 if (error)
48981 goto dput_and_out;
48982
48983+ if (gr_handle_chroot_chroot(path.dentry, path.mnt))
48984+ goto dput_and_out;
48985+
48986 set_fs_root(current->fs, &path);
48987+
48988+ gr_handle_chroot_chdir(&path);
48989+
48990 error = 0;
48991 dput_and_out:
48992 path_put(&path);
48993@@ -462,6 +486,16 @@ static int chmod_common(struct path *path, umode_t mode)
48994 if (error)
48995 return error;
48996 mutex_lock(&inode->i_mutex);
48997+
48998+ if (!gr_acl_handle_chmod(path->dentry, path->mnt, &mode)) {
48999+ error = -EACCES;
49000+ goto out_unlock;
49001+ }
49002+ if (gr_handle_chroot_chmod(path->dentry, path->mnt, mode)) {
49003+ error = -EACCES;
49004+ goto out_unlock;
49005+ }
49006+
49007 error = security_path_chmod(path, mode);
49008 if (error)
49009 goto out_unlock;
49010@@ -517,6 +551,9 @@ static int chown_common(struct path *path, uid_t user, gid_t group)
49011 uid = make_kuid(current_user_ns(), user);
49012 gid = make_kgid(current_user_ns(), group);
49013
49014+ if (!gr_acl_handle_chown(path->dentry, path->mnt))
49015+ return -EACCES;
49016+
49017 newattrs.ia_valid = ATTR_CTIME;
49018 if (user != (uid_t) -1) {
49019 if (!uid_valid(uid))
49020@@ -958,6 +995,7 @@ long do_sys_open(int dfd, const char __user *filename, int flags, umode_t mode)
49021 } else {
49022 fsnotify_open(f);
49023 fd_install(fd, f);
49024+ trace_do_sys_open(tmp, flags, mode);
49025 }
49026 }
49027 putname(tmp);
49028diff --git a/fs/pipe.c b/fs/pipe.c
49029index 8d85d70..581036b 100644
49030--- a/fs/pipe.c
49031+++ b/fs/pipe.c
49032@@ -438,9 +438,9 @@ redo:
49033 }
49034 if (bufs) /* More to do? */
49035 continue;
49036- if (!pipe->writers)
49037+ if (!atomic_read(&pipe->writers))
49038 break;
49039- if (!pipe->waiting_writers) {
49040+ if (!atomic_read(&pipe->waiting_writers)) {
49041 /* syscall merging: Usually we must not sleep
49042 * if O_NONBLOCK is set, or if we got some data.
49043 * But if a writer sleeps in kernel space, then
49044@@ -504,7 +504,7 @@ pipe_write(struct kiocb *iocb, const struct iovec *_iov,
49045 mutex_lock(&inode->i_mutex);
49046 pipe = inode->i_pipe;
49047
49048- if (!pipe->readers) {
49049+ if (!atomic_read(&pipe->readers)) {
49050 send_sig(SIGPIPE, current, 0);
49051 ret = -EPIPE;
49052 goto out;
49053@@ -553,7 +553,7 @@ redo1:
49054 for (;;) {
49055 int bufs;
49056
49057- if (!pipe->readers) {
49058+ if (!atomic_read(&pipe->readers)) {
49059 send_sig(SIGPIPE, current, 0);
49060 if (!ret)
49061 ret = -EPIPE;
49062@@ -644,9 +644,9 @@ redo2:
49063 kill_fasync(&pipe->fasync_readers, SIGIO, POLL_IN);
49064 do_wakeup = 0;
49065 }
49066- pipe->waiting_writers++;
49067+ atomic_inc(&pipe->waiting_writers);
49068 pipe_wait(pipe);
49069- pipe->waiting_writers--;
49070+ atomic_dec(&pipe->waiting_writers);
49071 }
49072 out:
49073 mutex_unlock(&inode->i_mutex);
49074@@ -716,7 +716,7 @@ pipe_poll(struct file *filp, poll_table *wait)
49075 mask = 0;
49076 if (filp->f_mode & FMODE_READ) {
49077 mask = (nrbufs > 0) ? POLLIN | POLLRDNORM : 0;
49078- if (!pipe->writers && filp->f_version != pipe->w_counter)
49079+ if (!atomic_read(&pipe->writers) && filp->f_version != pipe->w_counter)
49080 mask |= POLLHUP;
49081 }
49082
49083@@ -726,7 +726,7 @@ pipe_poll(struct file *filp, poll_table *wait)
49084 * Most Unices do not set POLLERR for FIFOs but on Linux they
49085 * behave exactly like pipes for poll().
49086 */
49087- if (!pipe->readers)
49088+ if (!atomic_read(&pipe->readers))
49089 mask |= POLLERR;
49090 }
49091
49092@@ -740,10 +740,10 @@ pipe_release(struct inode *inode, int decr, int decw)
49093
49094 mutex_lock(&inode->i_mutex);
49095 pipe = inode->i_pipe;
49096- pipe->readers -= decr;
49097- pipe->writers -= decw;
49098+ atomic_sub(decr, &pipe->readers);
49099+ atomic_sub(decw, &pipe->writers);
49100
49101- if (!pipe->readers && !pipe->writers) {
49102+ if (!atomic_read(&pipe->readers) && !atomic_read(&pipe->writers)) {
49103 free_pipe_info(inode);
49104 } else {
49105 wake_up_interruptible_sync_poll(&pipe->wait, POLLIN | POLLOUT | POLLRDNORM | POLLWRNORM | POLLERR | POLLHUP);
49106@@ -833,7 +833,7 @@ pipe_read_open(struct inode *inode, struct file *filp)
49107
49108 if (inode->i_pipe) {
49109 ret = 0;
49110- inode->i_pipe->readers++;
49111+ atomic_inc(&inode->i_pipe->readers);
49112 }
49113
49114 mutex_unlock(&inode->i_mutex);
49115@@ -850,7 +850,7 @@ pipe_write_open(struct inode *inode, struct file *filp)
49116
49117 if (inode->i_pipe) {
49118 ret = 0;
49119- inode->i_pipe->writers++;
49120+ atomic_inc(&inode->i_pipe->writers);
49121 }
49122
49123 mutex_unlock(&inode->i_mutex);
49124@@ -868,9 +868,9 @@ pipe_rdwr_open(struct inode *inode, struct file *filp)
49125 if (inode->i_pipe) {
49126 ret = 0;
49127 if (filp->f_mode & FMODE_READ)
49128- inode->i_pipe->readers++;
49129+ atomic_inc(&inode->i_pipe->readers);
49130 if (filp->f_mode & FMODE_WRITE)
49131- inode->i_pipe->writers++;
49132+ atomic_inc(&inode->i_pipe->writers);
49133 }
49134
49135 mutex_unlock(&inode->i_mutex);
49136@@ -962,7 +962,7 @@ void free_pipe_info(struct inode *inode)
49137 inode->i_pipe = NULL;
49138 }
49139
49140-static struct vfsmount *pipe_mnt __read_mostly;
49141+struct vfsmount *pipe_mnt __read_mostly;
49142
49143 /*
49144 * pipefs_dname() is called from d_path().
49145@@ -992,7 +992,8 @@ static struct inode * get_pipe_inode(void)
49146 goto fail_iput;
49147 inode->i_pipe = pipe;
49148
49149- pipe->readers = pipe->writers = 1;
49150+ atomic_set(&pipe->readers, 1);
49151+ atomic_set(&pipe->writers, 1);
49152 inode->i_fop = &rdwr_pipefifo_fops;
49153
49154 /*
49155diff --git a/fs/proc/Kconfig b/fs/proc/Kconfig
49156index 15af622..0e9f4467 100644
49157--- a/fs/proc/Kconfig
49158+++ b/fs/proc/Kconfig
49159@@ -30,12 +30,12 @@ config PROC_FS
49160
49161 config PROC_KCORE
49162 bool "/proc/kcore support" if !ARM
49163- depends on PROC_FS && MMU
49164+ depends on PROC_FS && MMU && !GRKERNSEC_PROC_ADD
49165
49166 config PROC_VMCORE
49167 bool "/proc/vmcore support"
49168- depends on PROC_FS && CRASH_DUMP
49169- default y
49170+ depends on PROC_FS && CRASH_DUMP && !GRKERNSEC
49171+ default n
49172 help
49173 Exports the dump image of crashed kernel in ELF format.
49174
49175@@ -59,8 +59,8 @@ config PROC_SYSCTL
49176 limited in memory.
49177
49178 config PROC_PAGE_MONITOR
49179- default y
49180- depends on PROC_FS && MMU
49181+ default n
49182+ depends on PROC_FS && MMU && !GRKERNSEC
49183 bool "Enable /proc page monitoring" if EXPERT
49184 help
49185 Various /proc files exist to monitor process memory utilization:
49186diff --git a/fs/proc/array.c b/fs/proc/array.c
49187index c1c207c..01ce725 100644
49188--- a/fs/proc/array.c
49189+++ b/fs/proc/array.c
49190@@ -60,6 +60,7 @@
49191 #include <linux/tty.h>
49192 #include <linux/string.h>
49193 #include <linux/mman.h>
49194+#include <linux/grsecurity.h>
49195 #include <linux/proc_fs.h>
49196 #include <linux/ioport.h>
49197 #include <linux/uaccess.h>
49198@@ -346,6 +347,21 @@ static void task_cpus_allowed(struct seq_file *m, struct task_struct *task)
49199 seq_putc(m, '\n');
49200 }
49201
49202+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
49203+static inline void task_pax(struct seq_file *m, struct task_struct *p)
49204+{
49205+ if (p->mm)
49206+ seq_printf(m, "PaX:\t%c%c%c%c%c\n",
49207+ p->mm->pax_flags & MF_PAX_PAGEEXEC ? 'P' : 'p',
49208+ p->mm->pax_flags & MF_PAX_EMUTRAMP ? 'E' : 'e',
49209+ p->mm->pax_flags & MF_PAX_MPROTECT ? 'M' : 'm',
49210+ p->mm->pax_flags & MF_PAX_RANDMMAP ? 'R' : 'r',
49211+ p->mm->pax_flags & MF_PAX_SEGMEXEC ? 'S' : 's');
49212+ else
49213+ seq_printf(m, "PaX:\t-----\n");
49214+}
49215+#endif
49216+
49217 int proc_pid_status(struct seq_file *m, struct pid_namespace *ns,
49218 struct pid *pid, struct task_struct *task)
49219 {
49220@@ -363,9 +379,24 @@ int proc_pid_status(struct seq_file *m, struct pid_namespace *ns,
49221 task_cpus_allowed(m, task);
49222 cpuset_task_status_allowed(m, task);
49223 task_context_switch_counts(m, task);
49224+
49225+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
49226+ task_pax(m, task);
49227+#endif
49228+
49229+#if defined(CONFIG_GRKERNSEC) && !defined(CONFIG_GRKERNSEC_NO_RBAC)
49230+ task_grsec_rbac(m, task);
49231+#endif
49232+
49233 return 0;
49234 }
49235
49236+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
49237+#define PAX_RAND_FLAGS(_mm) (_mm != NULL && _mm != current->mm && \
49238+ (_mm->pax_flags & MF_PAX_RANDMMAP || \
49239+ _mm->pax_flags & MF_PAX_SEGMEXEC))
49240+#endif
49241+
49242 static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
49243 struct pid *pid, struct task_struct *task, int whole)
49244 {
49245@@ -387,6 +418,13 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
49246 char tcomm[sizeof(task->comm)];
49247 unsigned long flags;
49248
49249+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
49250+ if (current->exec_id != m->exec_id) {
49251+ gr_log_badprocpid("stat");
49252+ return 0;
49253+ }
49254+#endif
49255+
49256 state = *get_task_state(task);
49257 vsize = eip = esp = 0;
49258 permitted = ptrace_may_access(task, PTRACE_MODE_READ | PTRACE_MODE_NOAUDIT);
49259@@ -458,6 +496,19 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
49260 gtime = task->gtime;
49261 }
49262
49263+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
49264+ if (PAX_RAND_FLAGS(mm)) {
49265+ eip = 0;
49266+ esp = 0;
49267+ wchan = 0;
49268+ }
49269+#endif
49270+#ifdef CONFIG_GRKERNSEC_HIDESYM
49271+ wchan = 0;
49272+ eip =0;
49273+ esp =0;
49274+#endif
49275+
49276 /* scale priority and nice values from timeslices to -20..20 */
49277 /* to make it look like a "normal" Unix priority/nice value */
49278 priority = task_prio(task);
49279@@ -494,9 +545,15 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
49280 seq_put_decimal_ull(m, ' ', vsize);
49281 seq_put_decimal_ull(m, ' ', mm ? get_mm_rss(mm) : 0);
49282 seq_put_decimal_ull(m, ' ', rsslim);
49283+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
49284+ seq_put_decimal_ull(m, ' ', PAX_RAND_FLAGS(mm) ? 1 : (mm ? (permitted ? mm->start_code : 1) : 0));
49285+ seq_put_decimal_ull(m, ' ', PAX_RAND_FLAGS(mm) ? 1 : (mm ? (permitted ? mm->end_code : 1) : 0));
49286+ seq_put_decimal_ull(m, ' ', PAX_RAND_FLAGS(mm) ? 0 : ((permitted && mm) ? mm->start_stack : 0));
49287+#else
49288 seq_put_decimal_ull(m, ' ', mm ? (permitted ? mm->start_code : 1) : 0);
49289 seq_put_decimal_ull(m, ' ', mm ? (permitted ? mm->end_code : 1) : 0);
49290 seq_put_decimal_ull(m, ' ', (permitted && mm) ? mm->start_stack : 0);
49291+#endif
49292 seq_put_decimal_ull(m, ' ', esp);
49293 seq_put_decimal_ull(m, ' ', eip);
49294 /* The signal information here is obsolete.
49295@@ -518,7 +575,11 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
49296 seq_put_decimal_ull(m, ' ', cputime_to_clock_t(gtime));
49297 seq_put_decimal_ll(m, ' ', cputime_to_clock_t(cgtime));
49298
49299- if (mm && permitted) {
49300+ if (mm && permitted
49301+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
49302+ && !PAX_RAND_FLAGS(mm)
49303+#endif
49304+ ) {
49305 seq_put_decimal_ull(m, ' ', mm->start_data);
49306 seq_put_decimal_ull(m, ' ', mm->end_data);
49307 seq_put_decimal_ull(m, ' ', mm->start_brk);
49308@@ -556,8 +617,15 @@ int proc_pid_statm(struct seq_file *m, struct pid_namespace *ns,
49309 struct pid *pid, struct task_struct *task)
49310 {
49311 unsigned long size = 0, resident = 0, shared = 0, text = 0, data = 0;
49312- struct mm_struct *mm = get_task_mm(task);
49313+ struct mm_struct *mm;
49314
49315+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
49316+ if (current->exec_id != m->exec_id) {
49317+ gr_log_badprocpid("statm");
49318+ return 0;
49319+ }
49320+#endif
49321+ mm = get_task_mm(task);
49322 if (mm) {
49323 size = task_statm(mm, &shared, &text, &data, &resident);
49324 mmput(mm);
49325@@ -580,6 +648,13 @@ int proc_pid_statm(struct seq_file *m, struct pid_namespace *ns,
49326 return 0;
49327 }
49328
49329+#ifdef CONFIG_GRKERNSEC_PROC_IPADDR
49330+int proc_pid_ipaddr(struct task_struct *task, char *buffer)
49331+{
49332+ return sprintf(buffer, "%pI4\n", &task->signal->curr_ip);
49333+}
49334+#endif
49335+
49336 #ifdef CONFIG_CHECKPOINT_RESTORE
49337 static struct pid *
49338 get_children_pid(struct inode *inode, struct pid *pid_prev, loff_t pos)
49339diff --git a/fs/proc/base.c b/fs/proc/base.c
49340index 1b6c84c..66b738b 100644
49341--- a/fs/proc/base.c
49342+++ b/fs/proc/base.c
49343@@ -110,6 +110,14 @@ struct pid_entry {
49344 union proc_op op;
49345 };
49346
49347+struct getdents_callback {
49348+ struct linux_dirent __user * current_dir;
49349+ struct linux_dirent __user * previous;
49350+ struct file * file;
49351+ int count;
49352+ int error;
49353+};
49354+
49355 #define NOD(NAME, MODE, IOP, FOP, OP) { \
49356 .name = (NAME), \
49357 .len = sizeof(NAME) - 1, \
49358@@ -209,6 +217,9 @@ static int proc_pid_cmdline(struct task_struct *task, char * buffer)
49359 if (!mm->arg_end)
49360 goto out_mm; /* Shh! No looking before we're done */
49361
49362+ if (gr_acl_handle_procpidmem(task))
49363+ goto out_mm;
49364+
49365 len = mm->arg_end - mm->arg_start;
49366
49367 if (len > PAGE_SIZE)
49368@@ -236,12 +247,28 @@ out:
49369 return res;
49370 }
49371
49372+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
49373+#define PAX_RAND_FLAGS(_mm) (_mm != NULL && _mm != current->mm && \
49374+ (_mm->pax_flags & MF_PAX_RANDMMAP || \
49375+ _mm->pax_flags & MF_PAX_SEGMEXEC))
49376+#endif
49377+
49378 static int proc_pid_auxv(struct task_struct *task, char *buffer)
49379 {
49380 struct mm_struct *mm = mm_access(task, PTRACE_MODE_READ);
49381 int res = PTR_ERR(mm);
49382 if (mm && !IS_ERR(mm)) {
49383 unsigned int nwords = 0;
49384+
49385+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
49386+ /* allow if we're currently ptracing this task */
49387+ if (PAX_RAND_FLAGS(mm) &&
49388+ (!(task->ptrace & PT_PTRACED) || (task->parent != current))) {
49389+ mmput(mm);
49390+ return 0;
49391+ }
49392+#endif
49393+
49394 do {
49395 nwords += 2;
49396 } while (mm->saved_auxv[nwords - 2] != 0); /* AT_NULL */
49397@@ -255,7 +282,7 @@ static int proc_pid_auxv(struct task_struct *task, char *buffer)
49398 }
49399
49400
49401-#ifdef CONFIG_KALLSYMS
49402+#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
49403 /*
49404 * Provides a wchan file via kallsyms in a proper one-value-per-file format.
49405 * Returns the resolved symbol. If that fails, simply return the address.
49406@@ -294,7 +321,7 @@ static void unlock_trace(struct task_struct *task)
49407 mutex_unlock(&task->signal->cred_guard_mutex);
49408 }
49409
49410-#ifdef CONFIG_STACKTRACE
49411+#if defined(CONFIG_STACKTRACE) && !defined(CONFIG_GRKERNSEC_HIDESYM)
49412
49413 #define MAX_STACK_TRACE_DEPTH 64
49414
49415@@ -486,7 +513,7 @@ static int proc_pid_limits(struct task_struct *task, char *buffer)
49416 return count;
49417 }
49418
49419-#ifdef CONFIG_HAVE_ARCH_TRACEHOOK
49420+#if defined(CONFIG_HAVE_ARCH_TRACEHOOK) && !defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
49421 static int proc_pid_syscall(struct task_struct *task, char *buffer)
49422 {
49423 long nr;
49424@@ -515,7 +542,7 @@ static int proc_pid_syscall(struct task_struct *task, char *buffer)
49425 /************************************************************************/
49426
49427 /* permission checks */
49428-static int proc_fd_access_allowed(struct inode *inode)
49429+static int proc_fd_access_allowed(struct inode *inode, unsigned int log)
49430 {
49431 struct task_struct *task;
49432 int allowed = 0;
49433@@ -525,7 +552,10 @@ static int proc_fd_access_allowed(struct inode *inode)
49434 */
49435 task = get_proc_task(inode);
49436 if (task) {
49437- allowed = ptrace_may_access(task, PTRACE_MODE_READ);
49438+ if (log)
49439+ allowed = ptrace_may_access(task, PTRACE_MODE_READ);
49440+ else
49441+ allowed = ptrace_may_access(task, PTRACE_MODE_READ | PTRACE_MODE_NOAUDIT);
49442 put_task_struct(task);
49443 }
49444 return allowed;
49445@@ -563,10 +593,35 @@ static bool has_pid_permissions(struct pid_namespace *pid,
49446 struct task_struct *task,
49447 int hide_pid_min)
49448 {
49449+ if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
49450+ return false;
49451+
49452+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
49453+ rcu_read_lock();
49454+ {
49455+ const struct cred *tmpcred = current_cred();
49456+ const struct cred *cred = __task_cred(task);
49457+
49458+ if (!tmpcred->uid || (tmpcred->uid == cred->uid)
49459+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
49460+ || in_group_p(grsec_proc_gid)
49461+#endif
49462+ ) {
49463+ rcu_read_unlock();
49464+ return true;
49465+ }
49466+ }
49467+ rcu_read_unlock();
49468+
49469+ if (!pid->hide_pid)
49470+ return false;
49471+#endif
49472+
49473 if (pid->hide_pid < hide_pid_min)
49474 return true;
49475 if (in_group_p(pid->pid_gid))
49476 return true;
49477+
49478 return ptrace_may_access(task, PTRACE_MODE_READ);
49479 }
49480
49481@@ -584,7 +639,11 @@ static int proc_pid_permission(struct inode *inode, int mask)
49482 put_task_struct(task);
49483
49484 if (!has_perms) {
49485+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
49486+ {
49487+#else
49488 if (pid->hide_pid == 2) {
49489+#endif
49490 /*
49491 * Let's make getdents(), stat(), and open()
49492 * consistent with each other. If a process
49493@@ -682,6 +741,11 @@ static int __mem_open(struct inode *inode, struct file *file, unsigned int mode)
49494 if (!task)
49495 return -ESRCH;
49496
49497+ if (gr_acl_handle_procpidmem(task)) {
49498+ put_task_struct(task);
49499+ return -EPERM;
49500+ }
49501+
49502 mm = mm_access(task, mode);
49503 put_task_struct(task);
49504
49505@@ -697,6 +761,10 @@ static int __mem_open(struct inode *inode, struct file *file, unsigned int mode)
49506
49507 file->private_data = mm;
49508
49509+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
49510+ file->f_version = current->exec_id;
49511+#endif
49512+
49513 return 0;
49514 }
49515
49516@@ -718,6 +786,17 @@ static ssize_t mem_rw(struct file *file, char __user *buf,
49517 ssize_t copied;
49518 char *page;
49519
49520+#ifdef CONFIG_GRKERNSEC
49521+ if (write)
49522+ return -EPERM;
49523+#endif
49524+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
49525+ if (file->f_version != current->exec_id) {
49526+ gr_log_badprocpid("mem");
49527+ return 0;
49528+ }
49529+#endif
49530+
49531 if (!mm)
49532 return 0;
49533
49534@@ -822,6 +901,13 @@ static ssize_t environ_read(struct file *file, char __user *buf,
49535 if (!mm)
49536 return 0;
49537
49538+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
49539+ if (file->f_version != current->exec_id) {
49540+ gr_log_badprocpid("environ");
49541+ return 0;
49542+ }
49543+#endif
49544+
49545 page = (char *)__get_free_page(GFP_TEMPORARY);
49546 if (!page)
49547 return -ENOMEM;
49548@@ -1435,7 +1521,7 @@ static void *proc_pid_follow_link(struct dentry *dentry, struct nameidata *nd)
49549 int error = -EACCES;
49550
49551 /* Are we allowed to snoop on the tasks file descriptors? */
49552- if (!proc_fd_access_allowed(inode))
49553+ if (!proc_fd_access_allowed(inode, 0))
49554 goto out;
49555
49556 error = PROC_I(inode)->op.proc_get_link(dentry, &path);
49557@@ -1479,8 +1565,18 @@ static int proc_pid_readlink(struct dentry * dentry, char __user * buffer, int b
49558 struct path path;
49559
49560 /* Are we allowed to snoop on the tasks file descriptors? */
49561- if (!proc_fd_access_allowed(inode))
49562- goto out;
49563+ /* logging this is needed for learning on chromium to work properly,
49564+ but we don't want to flood the logs from 'ps' which does a readlink
49565+ on /proc/fd/2 of tasks in the listing, nor do we want 'ps' to learn
49566+ CAP_SYS_PTRACE as it's not necessary for its basic functionality
49567+ */
49568+ if (dentry->d_name.name[0] == '2' && dentry->d_name.name[1] == '\0') {
49569+ if (!proc_fd_access_allowed(inode,0))
49570+ goto out;
49571+ } else {
49572+ if (!proc_fd_access_allowed(inode,1))
49573+ goto out;
49574+ }
49575
49576 error = PROC_I(inode)->op.proc_get_link(dentry, &path);
49577 if (error)
49578@@ -1545,7 +1641,11 @@ struct inode *proc_pid_make_inode(struct super_block * sb, struct task_struct *t
49579 rcu_read_lock();
49580 cred = __task_cred(task);
49581 inode->i_uid = cred->euid;
49582+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
49583+ inode->i_gid = grsec_proc_gid;
49584+#else
49585 inode->i_gid = cred->egid;
49586+#endif
49587 rcu_read_unlock();
49588 }
49589 security_task_to_inode(task, inode);
49590@@ -1581,10 +1681,19 @@ int pid_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat)
49591 return -ENOENT;
49592 }
49593 if ((inode->i_mode == (S_IFDIR|S_IRUGO|S_IXUGO)) ||
49594+#ifdef CONFIG_GRKERNSEC_PROC_USER
49595+ (inode->i_mode == (S_IFDIR|S_IRUSR|S_IXUSR)) ||
49596+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
49597+ (inode->i_mode == (S_IFDIR|S_IRUSR|S_IRGRP|S_IXUSR|S_IXGRP)) ||
49598+#endif
49599 task_dumpable(task)) {
49600 cred = __task_cred(task);
49601 stat->uid = cred->euid;
49602+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
49603+ stat->gid = grsec_proc_gid;
49604+#else
49605 stat->gid = cred->egid;
49606+#endif
49607 }
49608 }
49609 rcu_read_unlock();
49610@@ -1622,11 +1731,20 @@ int pid_revalidate(struct dentry *dentry, unsigned int flags)
49611
49612 if (task) {
49613 if ((inode->i_mode == (S_IFDIR|S_IRUGO|S_IXUGO)) ||
49614+#ifdef CONFIG_GRKERNSEC_PROC_USER
49615+ (inode->i_mode == (S_IFDIR|S_IRUSR|S_IXUSR)) ||
49616+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
49617+ (inode->i_mode == (S_IFDIR|S_IRUSR|S_IRGRP|S_IXUSR|S_IXGRP)) ||
49618+#endif
49619 task_dumpable(task)) {
49620 rcu_read_lock();
49621 cred = __task_cred(task);
49622 inode->i_uid = cred->euid;
49623+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
49624+ inode->i_gid = grsec_proc_gid;
49625+#else
49626 inode->i_gid = cred->egid;
49627+#endif
49628 rcu_read_unlock();
49629 } else {
49630 inode->i_uid = GLOBAL_ROOT_UID;
49631@@ -1744,7 +1862,8 @@ static int proc_fd_info(struct inode *inode, struct path *path, char *info)
49632 int fd = proc_fd(inode);
49633
49634 if (task) {
49635- files = get_files_struct(task);
49636+ if (!gr_acl_handle_procpidmem(task))
49637+ files = get_files_struct(task);
49638 put_task_struct(task);
49639 }
49640 if (files) {
49641@@ -2343,11 +2462,21 @@ static const struct file_operations proc_map_files_operations = {
49642 */
49643 static int proc_fd_permission(struct inode *inode, int mask)
49644 {
49645+ struct task_struct *task;
49646 int rv = generic_permission(inode, mask);
49647- if (rv == 0)
49648- return 0;
49649+
49650 if (task_pid(current) == proc_pid(inode))
49651 rv = 0;
49652+
49653+ task = get_proc_task(inode);
49654+ if (task == NULL)
49655+ return rv;
49656+
49657+ if (gr_acl_handle_procpidmem(task))
49658+ rv = -EACCES;
49659+
49660+ put_task_struct(task);
49661+
49662 return rv;
49663 }
49664
49665@@ -2457,6 +2586,9 @@ static struct dentry *proc_pident_lookup(struct inode *dir,
49666 if (!task)
49667 goto out_no_task;
49668
49669+ if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
49670+ goto out;
49671+
49672 /*
49673 * Yes, it does not scale. And it should not. Don't add
49674 * new entries into /proc/<tgid>/ without very good reasons.
49675@@ -2501,6 +2633,9 @@ static int proc_pident_readdir(struct file *filp,
49676 if (!task)
49677 goto out_no_task;
49678
49679+ if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
49680+ goto out;
49681+
49682 ret = 0;
49683 i = filp->f_pos;
49684 switch (i) {
49685@@ -2771,7 +2906,7 @@ static void *proc_self_follow_link(struct dentry *dentry, struct nameidata *nd)
49686 static void proc_self_put_link(struct dentry *dentry, struct nameidata *nd,
49687 void *cookie)
49688 {
49689- char *s = nd_get_link(nd);
49690+ const char *s = nd_get_link(nd);
49691 if (!IS_ERR(s))
49692 __putname(s);
49693 }
49694@@ -3040,7 +3175,7 @@ static const struct pid_entry tgid_base_stuff[] = {
49695 REG("autogroup", S_IRUGO|S_IWUSR, proc_pid_sched_autogroup_operations),
49696 #endif
49697 REG("comm", S_IRUGO|S_IWUSR, proc_pid_set_comm_operations),
49698-#ifdef CONFIG_HAVE_ARCH_TRACEHOOK
49699+#if defined(CONFIG_HAVE_ARCH_TRACEHOOK) && !defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
49700 INF("syscall", S_IRUGO, proc_pid_syscall),
49701 #endif
49702 INF("cmdline", S_IRUGO, proc_pid_cmdline),
49703@@ -3065,10 +3200,10 @@ static const struct pid_entry tgid_base_stuff[] = {
49704 #ifdef CONFIG_SECURITY
49705 DIR("attr", S_IRUGO|S_IXUGO, proc_attr_dir_inode_operations, proc_attr_dir_operations),
49706 #endif
49707-#ifdef CONFIG_KALLSYMS
49708+#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
49709 INF("wchan", S_IRUGO, proc_pid_wchan),
49710 #endif
49711-#ifdef CONFIG_STACKTRACE
49712+#if defined(CONFIG_STACKTRACE) && !defined(CONFIG_GRKERNSEC_HIDESYM)
49713 ONE("stack", S_IRUGO, proc_pid_stack),
49714 #endif
49715 #ifdef CONFIG_SCHEDSTATS
49716@@ -3102,6 +3237,9 @@ static const struct pid_entry tgid_base_stuff[] = {
49717 #ifdef CONFIG_HARDWALL
49718 INF("hardwall", S_IRUGO, proc_pid_hardwall),
49719 #endif
49720+#ifdef CONFIG_GRKERNSEC_PROC_IPADDR
49721+ INF("ipaddr", S_IRUSR, proc_pid_ipaddr),
49722+#endif
49723 #ifdef CONFIG_USER_NS
49724 REG("uid_map", S_IRUGO|S_IWUSR, proc_uid_map_operations),
49725 REG("gid_map", S_IRUGO|S_IWUSR, proc_gid_map_operations),
49726@@ -3233,7 +3371,14 @@ static struct dentry *proc_pid_instantiate(struct inode *dir,
49727 if (!inode)
49728 goto out;
49729
49730+#ifdef CONFIG_GRKERNSEC_PROC_USER
49731+ inode->i_mode = S_IFDIR|S_IRUSR|S_IXUSR;
49732+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
49733+ inode->i_gid = grsec_proc_gid;
49734+ inode->i_mode = S_IFDIR|S_IRUSR|S_IRGRP|S_IXUSR|S_IXGRP;
49735+#else
49736 inode->i_mode = S_IFDIR|S_IRUGO|S_IXUGO;
49737+#endif
49738 inode->i_op = &proc_tgid_base_inode_operations;
49739 inode->i_fop = &proc_tgid_base_operations;
49740 inode->i_flags|=S_IMMUTABLE;
49741@@ -3275,7 +3420,11 @@ struct dentry *proc_pid_lookup(struct inode *dir, struct dentry * dentry, unsign
49742 if (!task)
49743 goto out;
49744
49745+ if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
49746+ goto out_put_task;
49747+
49748 result = proc_pid_instantiate(dir, dentry, task, NULL);
49749+out_put_task:
49750 put_task_struct(task);
49751 out:
49752 return result;
49753@@ -3338,6 +3487,8 @@ static int proc_pid_fill_cache(struct file *filp, void *dirent, filldir_t filldi
49754 static int fake_filldir(void *buf, const char *name, int namelen,
49755 loff_t offset, u64 ino, unsigned d_type)
49756 {
49757+ struct getdents_callback * __buf = (struct getdents_callback *) buf;
49758+ __buf->error = -EINVAL;
49759 return 0;
49760 }
49761
49762@@ -3404,7 +3555,7 @@ static const struct pid_entry tid_base_stuff[] = {
49763 REG("sched", S_IRUGO|S_IWUSR, proc_pid_sched_operations),
49764 #endif
49765 REG("comm", S_IRUGO|S_IWUSR, proc_pid_set_comm_operations),
49766-#ifdef CONFIG_HAVE_ARCH_TRACEHOOK
49767+#if defined(CONFIG_HAVE_ARCH_TRACEHOOK) && !defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
49768 INF("syscall", S_IRUGO, proc_pid_syscall),
49769 #endif
49770 INF("cmdline", S_IRUGO, proc_pid_cmdline),
49771@@ -3431,10 +3582,10 @@ static const struct pid_entry tid_base_stuff[] = {
49772 #ifdef CONFIG_SECURITY
49773 DIR("attr", S_IRUGO|S_IXUGO, proc_attr_dir_inode_operations, proc_attr_dir_operations),
49774 #endif
49775-#ifdef CONFIG_KALLSYMS
49776+#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
49777 INF("wchan", S_IRUGO, proc_pid_wchan),
49778 #endif
49779-#ifdef CONFIG_STACKTRACE
49780+#if defined(CONFIG_STACKTRACE) && !defined(CONFIG_GRKERNSEC_HIDESYM)
49781 ONE("stack", S_IRUGO, proc_pid_stack),
49782 #endif
49783 #ifdef CONFIG_SCHEDSTATS
49784diff --git a/fs/proc/cmdline.c b/fs/proc/cmdline.c
49785index 82676e3..5f8518a 100644
49786--- a/fs/proc/cmdline.c
49787+++ b/fs/proc/cmdline.c
49788@@ -23,7 +23,11 @@ static const struct file_operations cmdline_proc_fops = {
49789
49790 static int __init proc_cmdline_init(void)
49791 {
49792+#ifdef CONFIG_GRKERNSEC_PROC_ADD
49793+ proc_create_grsec("cmdline", 0, NULL, &cmdline_proc_fops);
49794+#else
49795 proc_create("cmdline", 0, NULL, &cmdline_proc_fops);
49796+#endif
49797 return 0;
49798 }
49799 module_init(proc_cmdline_init);
49800diff --git a/fs/proc/devices.c b/fs/proc/devices.c
49801index b143471..bb105e5 100644
49802--- a/fs/proc/devices.c
49803+++ b/fs/proc/devices.c
49804@@ -64,7 +64,11 @@ static const struct file_operations proc_devinfo_operations = {
49805
49806 static int __init proc_devices_init(void)
49807 {
49808+#ifdef CONFIG_GRKERNSEC_PROC_ADD
49809+ proc_create_grsec("devices", 0, NULL, &proc_devinfo_operations);
49810+#else
49811 proc_create("devices", 0, NULL, &proc_devinfo_operations);
49812+#endif
49813 return 0;
49814 }
49815 module_init(proc_devices_init);
49816diff --git a/fs/proc/inode.c b/fs/proc/inode.c
49817index 7ac817b..c5c9eb0 100644
49818--- a/fs/proc/inode.c
49819+++ b/fs/proc/inode.c
49820@@ -21,11 +21,17 @@
49821 #include <linux/seq_file.h>
49822 #include <linux/slab.h>
49823 #include <linux/mount.h>
49824+#include <linux/grsecurity.h>
49825
49826 #include <asm/uaccess.h>
49827
49828 #include "internal.h"
49829
49830+#ifdef CONFIG_PROC_SYSCTL
49831+extern const struct inode_operations proc_sys_inode_operations;
49832+extern const struct inode_operations proc_sys_dir_operations;
49833+#endif
49834+
49835 static void proc_evict_inode(struct inode *inode)
49836 {
49837 struct proc_dir_entry *de;
49838@@ -51,6 +57,13 @@ static void proc_evict_inode(struct inode *inode)
49839 ns_ops = PROC_I(inode)->ns_ops;
49840 if (ns_ops && ns_ops->put)
49841 ns_ops->put(PROC_I(inode)->ns);
49842+
49843+#ifdef CONFIG_PROC_SYSCTL
49844+ if (inode->i_op == &proc_sys_inode_operations ||
49845+ inode->i_op == &proc_sys_dir_operations)
49846+ gr_handle_delete(inode->i_ino, inode->i_sb->s_dev);
49847+#endif
49848+
49849 }
49850
49851 static struct kmem_cache * proc_inode_cachep;
49852@@ -456,7 +469,11 @@ struct inode *proc_get_inode(struct super_block *sb, struct proc_dir_entry *de)
49853 if (de->mode) {
49854 inode->i_mode = de->mode;
49855 inode->i_uid = de->uid;
49856+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
49857+ inode->i_gid = grsec_proc_gid;
49858+#else
49859 inode->i_gid = de->gid;
49860+#endif
49861 }
49862 if (de->size)
49863 inode->i_size = de->size;
49864diff --git a/fs/proc/internal.h b/fs/proc/internal.h
49865index e1167a1..bd24f20 100644
49866--- a/fs/proc/internal.h
49867+++ b/fs/proc/internal.h
49868@@ -52,6 +52,9 @@ extern int proc_pid_status(struct seq_file *m, struct pid_namespace *ns,
49869 struct pid *pid, struct task_struct *task);
49870 extern int proc_pid_statm(struct seq_file *m, struct pid_namespace *ns,
49871 struct pid *pid, struct task_struct *task);
49872+#ifdef CONFIG_GRKERNSEC_PROC_IPADDR
49873+extern int proc_pid_ipaddr(struct task_struct *task, char *buffer);
49874+#endif
49875 extern loff_t mem_lseek(struct file *file, loff_t offset, int orig);
49876
49877 extern const struct file_operations proc_tid_children_operations;
49878diff --git a/fs/proc/kcore.c b/fs/proc/kcore.c
49879index 86c67ee..cdca321 100644
49880--- a/fs/proc/kcore.c
49881+++ b/fs/proc/kcore.c
49882@@ -480,9 +480,10 @@ read_kcore(struct file *file, char __user *buffer, size_t buflen, loff_t *fpos)
49883 * the addresses in the elf_phdr on our list.
49884 */
49885 start = kc_offset_to_vaddr(*fpos - elf_buflen);
49886- if ((tsz = (PAGE_SIZE - (start & ~PAGE_MASK))) > buflen)
49887+ tsz = PAGE_SIZE - (start & ~PAGE_MASK);
49888+ if (tsz > buflen)
49889 tsz = buflen;
49890-
49891+
49892 while (buflen) {
49893 struct kcore_list *m;
49894
49895@@ -511,20 +512,23 @@ read_kcore(struct file *file, char __user *buffer, size_t buflen, loff_t *fpos)
49896 kfree(elf_buf);
49897 } else {
49898 if (kern_addr_valid(start)) {
49899- unsigned long n;
49900+ char *elf_buf;
49901+ mm_segment_t oldfs;
49902
49903- n = copy_to_user(buffer, (char *)start, tsz);
49904- /*
49905- * We cannot distinguish between fault on source
49906- * and fault on destination. When this happens
49907- * we clear too and hope it will trigger the
49908- * EFAULT again.
49909- */
49910- if (n) {
49911- if (clear_user(buffer + tsz - n,
49912- n))
49913+ elf_buf = kmalloc(tsz, GFP_KERNEL);
49914+ if (!elf_buf)
49915+ return -ENOMEM;
49916+ oldfs = get_fs();
49917+ set_fs(KERNEL_DS);
49918+ if (!__copy_from_user(elf_buf, (const void __user *)start, tsz)) {
49919+ set_fs(oldfs);
49920+ if (copy_to_user(buffer, elf_buf, tsz)) {
49921+ kfree(elf_buf);
49922 return -EFAULT;
49923+ }
49924 }
49925+ set_fs(oldfs);
49926+ kfree(elf_buf);
49927 } else {
49928 if (clear_user(buffer, tsz))
49929 return -EFAULT;
49930@@ -544,6 +548,9 @@ read_kcore(struct file *file, char __user *buffer, size_t buflen, loff_t *fpos)
49931
49932 static int open_kcore(struct inode *inode, struct file *filp)
49933 {
49934+#if defined(CONFIG_GRKERNSEC_PROC_ADD) || defined(CONFIG_GRKERNSEC_HIDESYM)
49935+ return -EPERM;
49936+#endif
49937 if (!capable(CAP_SYS_RAWIO))
49938 return -EPERM;
49939 if (kcore_need_update)
49940diff --git a/fs/proc/meminfo.c b/fs/proc/meminfo.c
49941index 80e4645..53e5fcf 100644
49942--- a/fs/proc/meminfo.c
49943+++ b/fs/proc/meminfo.c
49944@@ -158,7 +158,7 @@ static int meminfo_proc_show(struct seq_file *m, void *v)
49945 vmi.used >> 10,
49946 vmi.largest_chunk >> 10
49947 #ifdef CONFIG_MEMORY_FAILURE
49948- ,atomic_long_read(&mce_bad_pages) << (PAGE_SHIFT - 10)
49949+ ,atomic_long_read_unchecked(&mce_bad_pages) << (PAGE_SHIFT - 10)
49950 #endif
49951 #ifdef CONFIG_TRANSPARENT_HUGEPAGE
49952 ,K(global_page_state(NR_ANON_TRANSPARENT_HUGEPAGES) *
49953diff --git a/fs/proc/nommu.c b/fs/proc/nommu.c
49954index b1822dd..df622cb 100644
49955--- a/fs/proc/nommu.c
49956+++ b/fs/proc/nommu.c
49957@@ -66,7 +66,7 @@ static int nommu_region_show(struct seq_file *m, struct vm_region *region)
49958 if (len < 1)
49959 len = 1;
49960 seq_printf(m, "%*c", len, ' ');
49961- seq_path(m, &file->f_path, "");
49962+ seq_path(m, &file->f_path, "\n\\");
49963 }
49964
49965 seq_putc(m, '\n');
49966diff --git a/fs/proc/proc_net.c b/fs/proc/proc_net.c
49967index fe72cd0..cb9b67d 100644
49968--- a/fs/proc/proc_net.c
49969+++ b/fs/proc/proc_net.c
49970@@ -23,6 +23,7 @@
49971 #include <linux/nsproxy.h>
49972 #include <net/net_namespace.h>
49973 #include <linux/seq_file.h>
49974+#include <linux/grsecurity.h>
49975
49976 #include "internal.h"
49977
49978@@ -105,6 +106,17 @@ static struct net *get_proc_task_net(struct inode *dir)
49979 struct task_struct *task;
49980 struct nsproxy *ns;
49981 struct net *net = NULL;
49982+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
49983+ const struct cred *cred = current_cred();
49984+#endif
49985+
49986+#ifdef CONFIG_GRKERNSEC_PROC_USER
49987+ if (cred->fsuid)
49988+ return net;
49989+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
49990+ if (cred->fsuid && !in_group_p(grsec_proc_gid))
49991+ return net;
49992+#endif
49993
49994 rcu_read_lock();
49995 task = pid_task(proc_pid(dir), PIDTYPE_PID);
49996diff --git a/fs/proc/proc_sysctl.c b/fs/proc/proc_sysctl.c
49997index eb7cc91..7327a46 100644
49998--- a/fs/proc/proc_sysctl.c
49999+++ b/fs/proc/proc_sysctl.c
50000@@ -12,11 +12,15 @@
50001 #include <linux/module.h>
50002 #include "internal.h"
50003
50004+extern int gr_handle_chroot_sysctl(const int op);
50005+extern int gr_handle_sysctl_mod(const char *dirname, const char *name,
50006+ const int op);
50007+
50008 static const struct dentry_operations proc_sys_dentry_operations;
50009 static const struct file_operations proc_sys_file_operations;
50010-static const struct inode_operations proc_sys_inode_operations;
50011+const struct inode_operations proc_sys_inode_operations;
50012 static const struct file_operations proc_sys_dir_file_operations;
50013-static const struct inode_operations proc_sys_dir_operations;
50014+const struct inode_operations proc_sys_dir_operations;
50015
50016 void proc_sys_poll_notify(struct ctl_table_poll *poll)
50017 {
50018@@ -467,6 +471,9 @@ static struct dentry *proc_sys_lookup(struct inode *dir, struct dentry *dentry,
50019
50020 err = NULL;
50021 d_set_d_op(dentry, &proc_sys_dentry_operations);
50022+
50023+ gr_handle_proc_create(dentry, inode);
50024+
50025 d_add(dentry, inode);
50026
50027 out:
50028@@ -482,18 +489,20 @@ static ssize_t proc_sys_call_handler(struct file *filp, void __user *buf,
50029 struct inode *inode = filp->f_path.dentry->d_inode;
50030 struct ctl_table_header *head = grab_header(inode);
50031 struct ctl_table *table = PROC_I(inode)->sysctl_entry;
50032+ int op = write ? MAY_WRITE : MAY_READ;
50033 ssize_t error;
50034 size_t res;
50035
50036 if (IS_ERR(head))
50037 return PTR_ERR(head);
50038
50039+
50040 /*
50041 * At this point we know that the sysctl was not unregistered
50042 * and won't be until we finish.
50043 */
50044 error = -EPERM;
50045- if (sysctl_perm(head->root, table, write ? MAY_WRITE : MAY_READ))
50046+ if (sysctl_perm(head->root, table, op))
50047 goto out;
50048
50049 /* if that can happen at all, it should be -EINVAL, not -EISDIR */
50050@@ -501,6 +510,22 @@ static ssize_t proc_sys_call_handler(struct file *filp, void __user *buf,
50051 if (!table->proc_handler)
50052 goto out;
50053
50054+#ifdef CONFIG_GRKERNSEC
50055+ error = -EPERM;
50056+ if (gr_handle_chroot_sysctl(op))
50057+ goto out;
50058+ dget(filp->f_path.dentry);
50059+ if (gr_handle_sysctl_mod(filp->f_path.dentry->d_parent->d_name.name, table->procname, op)) {
50060+ dput(filp->f_path.dentry);
50061+ goto out;
50062+ }
50063+ dput(filp->f_path.dentry);
50064+ if (!gr_acl_handle_open(filp->f_path.dentry, filp->f_path.mnt, op))
50065+ goto out;
50066+ if (write && !capable(CAP_SYS_ADMIN))
50067+ goto out;
50068+#endif
50069+
50070 /* careful: calling conventions are nasty here */
50071 res = count;
50072 error = table->proc_handler(table, write, buf, &res, ppos);
50073@@ -598,6 +623,9 @@ static int proc_sys_fill_cache(struct file *filp, void *dirent,
50074 return -ENOMEM;
50075 } else {
50076 d_set_d_op(child, &proc_sys_dentry_operations);
50077+
50078+ gr_handle_proc_create(child, inode);
50079+
50080 d_add(child, inode);
50081 }
50082 } else {
50083@@ -641,6 +669,9 @@ static int scan(struct ctl_table_header *head, ctl_table *table,
50084 if ((*pos)++ < file->f_pos)
50085 return 0;
50086
50087+ if (!gr_acl_handle_hidden_file(file->f_path.dentry, file->f_path.mnt))
50088+ return 0;
50089+
50090 if (unlikely(S_ISLNK(table->mode)))
50091 res = proc_sys_link_fill_cache(file, dirent, filldir, head, table);
50092 else
50093@@ -758,6 +789,9 @@ static int proc_sys_getattr(struct vfsmount *mnt, struct dentry *dentry, struct
50094 if (IS_ERR(head))
50095 return PTR_ERR(head);
50096
50097+ if (table && !gr_acl_handle_hidden_file(dentry, mnt))
50098+ return -ENOENT;
50099+
50100 generic_fillattr(inode, stat);
50101 if (table)
50102 stat->mode = (stat->mode & S_IFMT) | table->mode;
50103@@ -780,13 +814,13 @@ static const struct file_operations proc_sys_dir_file_operations = {
50104 .llseek = generic_file_llseek,
50105 };
50106
50107-static const struct inode_operations proc_sys_inode_operations = {
50108+const struct inode_operations proc_sys_inode_operations = {
50109 .permission = proc_sys_permission,
50110 .setattr = proc_sys_setattr,
50111 .getattr = proc_sys_getattr,
50112 };
50113
50114-static const struct inode_operations proc_sys_dir_operations = {
50115+const struct inode_operations proc_sys_dir_operations = {
50116 .lookup = proc_sys_lookup,
50117 .permission = proc_sys_permission,
50118 .setattr = proc_sys_setattr,
50119diff --git a/fs/proc/root.c b/fs/proc/root.c
50120index 9a2d9fd..ddfc92a 100644
50121--- a/fs/proc/root.c
50122+++ b/fs/proc/root.c
50123@@ -187,7 +187,15 @@ void __init proc_root_init(void)
50124 #ifdef CONFIG_PROC_DEVICETREE
50125 proc_device_tree_init();
50126 #endif
50127+#ifdef CONFIG_GRKERNSEC_PROC_ADD
50128+#ifdef CONFIG_GRKERNSEC_PROC_USER
50129+ proc_mkdir_mode("bus", S_IRUSR | S_IXUSR, NULL);
50130+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
50131+ proc_mkdir_mode("bus", S_IRUSR | S_IXUSR | S_IRGRP | S_IXGRP, NULL);
50132+#endif
50133+#else
50134 proc_mkdir("bus", NULL);
50135+#endif
50136 proc_sys_init();
50137 }
50138
50139diff --git a/fs/proc/task_mmu.c b/fs/proc/task_mmu.c
50140index 4540b8f..1b9772f 100644
50141--- a/fs/proc/task_mmu.c
50142+++ b/fs/proc/task_mmu.c
50143@@ -11,12 +11,19 @@
50144 #include <linux/rmap.h>
50145 #include <linux/swap.h>
50146 #include <linux/swapops.h>
50147+#include <linux/grsecurity.h>
50148
50149 #include <asm/elf.h>
50150 #include <asm/uaccess.h>
50151 #include <asm/tlbflush.h>
50152 #include "internal.h"
50153
50154+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
50155+#define PAX_RAND_FLAGS(_mm) (_mm != NULL && _mm != current->mm && \
50156+ (_mm->pax_flags & MF_PAX_RANDMMAP || \
50157+ _mm->pax_flags & MF_PAX_SEGMEXEC))
50158+#endif
50159+
50160 void task_mem(struct seq_file *m, struct mm_struct *mm)
50161 {
50162 unsigned long data, text, lib, swap;
50163@@ -52,8 +59,13 @@ void task_mem(struct seq_file *m, struct mm_struct *mm)
50164 "VmExe:\t%8lu kB\n"
50165 "VmLib:\t%8lu kB\n"
50166 "VmPTE:\t%8lu kB\n"
50167- "VmSwap:\t%8lu kB\n",
50168- hiwater_vm << (PAGE_SHIFT-10),
50169+ "VmSwap:\t%8lu kB\n"
50170+
50171+#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
50172+ "CsBase:\t%8lx\nCsLim:\t%8lx\n"
50173+#endif
50174+
50175+ ,hiwater_vm << (PAGE_SHIFT-10),
50176 (total_vm - mm->reserved_vm) << (PAGE_SHIFT-10),
50177 mm->locked_vm << (PAGE_SHIFT-10),
50178 mm->pinned_vm << (PAGE_SHIFT-10),
50179@@ -62,7 +74,19 @@ void task_mem(struct seq_file *m, struct mm_struct *mm)
50180 data << (PAGE_SHIFT-10),
50181 mm->stack_vm << (PAGE_SHIFT-10), text, lib,
50182 (PTRS_PER_PTE*sizeof(pte_t)*mm->nr_ptes) >> 10,
50183- swap << (PAGE_SHIFT-10));
50184+ swap << (PAGE_SHIFT-10)
50185+
50186+#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
50187+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
50188+ , PAX_RAND_FLAGS(mm) ? 0 : mm->context.user_cs_base
50189+ , PAX_RAND_FLAGS(mm) ? 0 : mm->context.user_cs_limit
50190+#else
50191+ , mm->context.user_cs_base
50192+ , mm->context.user_cs_limit
50193+#endif
50194+#endif
50195+
50196+ );
50197 }
50198
50199 unsigned long task_vsize(struct mm_struct *mm)
50200@@ -231,13 +255,13 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
50201 pgoff = ((loff_t)vma->vm_pgoff) << PAGE_SHIFT;
50202 }
50203
50204- /* We don't show the stack guard page in /proc/maps */
50205+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
50206+ start = PAX_RAND_FLAGS(mm) ? 0UL : vma->vm_start;
50207+ end = PAX_RAND_FLAGS(mm) ? 0UL : vma->vm_end;
50208+#else
50209 start = vma->vm_start;
50210- if (stack_guard_page_start(vma, start))
50211- start += PAGE_SIZE;
50212 end = vma->vm_end;
50213- if (stack_guard_page_end(vma, end))
50214- end -= PAGE_SIZE;
50215+#endif
50216
50217 seq_printf(m, "%08lx-%08lx %c%c%c%c %08llx %02x:%02x %lu %n",
50218 start,
50219@@ -246,7 +270,11 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
50220 flags & VM_WRITE ? 'w' : '-',
50221 flags & VM_EXEC ? 'x' : '-',
50222 flags & VM_MAYSHARE ? 's' : 'p',
50223+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
50224+ PAX_RAND_FLAGS(mm) ? 0UL : pgoff,
50225+#else
50226 pgoff,
50227+#endif
50228 MAJOR(dev), MINOR(dev), ino, &len);
50229
50230 /*
50231@@ -255,7 +283,7 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
50232 */
50233 if (file) {
50234 pad_len_spaces(m, len);
50235- seq_path(m, &file->f_path, "\n");
50236+ seq_path(m, &file->f_path, "\n\\");
50237 goto done;
50238 }
50239
50240@@ -281,8 +309,9 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
50241 * Thread stack in /proc/PID/task/TID/maps or
50242 * the main process stack.
50243 */
50244- if (!is_pid || (vma->vm_start <= mm->start_stack &&
50245- vma->vm_end >= mm->start_stack)) {
50246+ if (!is_pid || (vma->vm_flags & (VM_GROWSDOWN | VM_GROWSUP)) ||
50247+ (vma->vm_start <= mm->start_stack &&
50248+ vma->vm_end >= mm->start_stack)) {
50249 name = "[stack]";
50250 } else {
50251 /* Thread stack in /proc/PID/maps */
50252@@ -306,6 +335,13 @@ static int show_map(struct seq_file *m, void *v, int is_pid)
50253 struct proc_maps_private *priv = m->private;
50254 struct task_struct *task = priv->task;
50255
50256+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
50257+ if (current->exec_id != m->exec_id) {
50258+ gr_log_badprocpid("maps");
50259+ return 0;
50260+ }
50261+#endif
50262+
50263 show_map_vma(m, vma, is_pid);
50264
50265 if (m->count < m->size) /* vma is copied successfully */
50266@@ -492,12 +528,23 @@ static int show_smap(struct seq_file *m, void *v, int is_pid)
50267 .private = &mss,
50268 };
50269
50270+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
50271+ if (current->exec_id != m->exec_id) {
50272+ gr_log_badprocpid("smaps");
50273+ return 0;
50274+ }
50275+#endif
50276 memset(&mss, 0, sizeof mss);
50277- mss.vma = vma;
50278- /* mmap_sem is held in m_start */
50279- if (vma->vm_mm && !is_vm_hugetlb_page(vma))
50280- walk_page_range(vma->vm_start, vma->vm_end, &smaps_walk);
50281-
50282+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
50283+ if (!PAX_RAND_FLAGS(vma->vm_mm)) {
50284+#endif
50285+ mss.vma = vma;
50286+ /* mmap_sem is held in m_start */
50287+ if (vma->vm_mm && !is_vm_hugetlb_page(vma))
50288+ walk_page_range(vma->vm_start, vma->vm_end, &smaps_walk);
50289+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
50290+ }
50291+#endif
50292 show_map_vma(m, vma, is_pid);
50293
50294 seq_printf(m,
50295@@ -515,7 +562,11 @@ static int show_smap(struct seq_file *m, void *v, int is_pid)
50296 "KernelPageSize: %8lu kB\n"
50297 "MMUPageSize: %8lu kB\n"
50298 "Locked: %8lu kB\n",
50299+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
50300+ PAX_RAND_FLAGS(vma->vm_mm) ? 0UL : (vma->vm_end - vma->vm_start) >> 10,
50301+#else
50302 (vma->vm_end - vma->vm_start) >> 10,
50303+#endif
50304 mss.resident >> 10,
50305 (unsigned long)(mss.pss >> (10 + PSS_SHIFT)),
50306 mss.shared_clean >> 10,
50307@@ -1164,6 +1215,13 @@ static int show_numa_map(struct seq_file *m, void *v, int is_pid)
50308 int n;
50309 char buffer[50];
50310
50311+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
50312+ if (current->exec_id != m->exec_id) {
50313+ gr_log_badprocpid("numa_maps");
50314+ return 0;
50315+ }
50316+#endif
50317+
50318 if (!mm)
50319 return 0;
50320
50321@@ -1181,11 +1239,15 @@ static int show_numa_map(struct seq_file *m, void *v, int is_pid)
50322 mpol_to_str(buffer, sizeof(buffer), pol, 0);
50323 mpol_cond_put(pol);
50324
50325+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
50326+ seq_printf(m, "%08lx %s", PAX_RAND_FLAGS(vma->vm_mm) ? 0UL : vma->vm_start, buffer);
50327+#else
50328 seq_printf(m, "%08lx %s", vma->vm_start, buffer);
50329+#endif
50330
50331 if (file) {
50332 seq_printf(m, " file=");
50333- seq_path(m, &file->f_path, "\n\t= ");
50334+ seq_path(m, &file->f_path, "\n\t\\= ");
50335 } else if (vma->vm_start <= mm->brk && vma->vm_end >= mm->start_brk) {
50336 seq_printf(m, " heap");
50337 } else {
50338diff --git a/fs/proc/task_nommu.c b/fs/proc/task_nommu.c
50339index 1ccfa53..0848f95 100644
50340--- a/fs/proc/task_nommu.c
50341+++ b/fs/proc/task_nommu.c
50342@@ -51,7 +51,7 @@ void task_mem(struct seq_file *m, struct mm_struct *mm)
50343 else
50344 bytes += kobjsize(mm);
50345
50346- if (current->fs && current->fs->users > 1)
50347+ if (current->fs && atomic_read(&current->fs->users) > 1)
50348 sbytes += kobjsize(current->fs);
50349 else
50350 bytes += kobjsize(current->fs);
50351@@ -168,7 +168,7 @@ static int nommu_vma_show(struct seq_file *m, struct vm_area_struct *vma,
50352
50353 if (file) {
50354 pad_len_spaces(m, len);
50355- seq_path(m, &file->f_path, "");
50356+ seq_path(m, &file->f_path, "\n\\");
50357 } else if (mm) {
50358 pid_t tid = vm_is_stack(priv->task, vma, is_pid);
50359
50360diff --git a/fs/quota/netlink.c b/fs/quota/netlink.c
50361index d67908b..d13f6a6 100644
50362--- a/fs/quota/netlink.c
50363+++ b/fs/quota/netlink.c
50364@@ -33,7 +33,7 @@ static struct genl_family quota_genl_family = {
50365 void quota_send_warning(short type, unsigned int id, dev_t dev,
50366 const char warntype)
50367 {
50368- static atomic_t seq;
50369+ static atomic_unchecked_t seq;
50370 struct sk_buff *skb;
50371 void *msg_head;
50372 int ret;
50373@@ -49,7 +49,7 @@ void quota_send_warning(short type, unsigned int id, dev_t dev,
50374 "VFS: Not enough memory to send quota warning.\n");
50375 return;
50376 }
50377- msg_head = genlmsg_put(skb, 0, atomic_add_return(1, &seq),
50378+ msg_head = genlmsg_put(skb, 0, atomic_add_return_unchecked(1, &seq),
50379 &quota_genl_family, 0, QUOTA_NL_C_WARNING);
50380 if (!msg_head) {
50381 printk(KERN_ERR
50382diff --git a/fs/readdir.c b/fs/readdir.c
50383index 39e3370..20d446d 100644
50384--- a/fs/readdir.c
50385+++ b/fs/readdir.c
50386@@ -17,6 +17,7 @@
50387 #include <linux/security.h>
50388 #include <linux/syscalls.h>
50389 #include <linux/unistd.h>
50390+#include <linux/namei.h>
50391
50392 #include <asm/uaccess.h>
50393
50394@@ -67,6 +68,7 @@ struct old_linux_dirent {
50395
50396 struct readdir_callback {
50397 struct old_linux_dirent __user * dirent;
50398+ struct file * file;
50399 int result;
50400 };
50401
50402@@ -84,6 +86,10 @@ static int fillonedir(void * __buf, const char * name, int namlen, loff_t offset
50403 buf->result = -EOVERFLOW;
50404 return -EOVERFLOW;
50405 }
50406+
50407+ if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
50408+ return 0;
50409+
50410 buf->result++;
50411 dirent = buf->dirent;
50412 if (!access_ok(VERIFY_WRITE, dirent,
50413@@ -116,6 +122,7 @@ SYSCALL_DEFINE3(old_readdir, unsigned int, fd,
50414
50415 buf.result = 0;
50416 buf.dirent = dirent;
50417+ buf.file = file;
50418
50419 error = vfs_readdir(file, fillonedir, &buf);
50420 if (buf.result)
50421@@ -141,6 +148,7 @@ struct linux_dirent {
50422 struct getdents_callback {
50423 struct linux_dirent __user * current_dir;
50424 struct linux_dirent __user * previous;
50425+ struct file * file;
50426 int count;
50427 int error;
50428 };
50429@@ -162,6 +170,10 @@ static int filldir(void * __buf, const char * name, int namlen, loff_t offset,
50430 buf->error = -EOVERFLOW;
50431 return -EOVERFLOW;
50432 }
50433+
50434+ if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
50435+ return 0;
50436+
50437 dirent = buf->previous;
50438 if (dirent) {
50439 if (__put_user(offset, &dirent->d_off))
50440@@ -208,6 +220,7 @@ SYSCALL_DEFINE3(getdents, unsigned int, fd,
50441 buf.previous = NULL;
50442 buf.count = count;
50443 buf.error = 0;
50444+ buf.file = file;
50445
50446 error = vfs_readdir(file, filldir, &buf);
50447 if (error >= 0)
50448@@ -226,6 +239,7 @@ SYSCALL_DEFINE3(getdents, unsigned int, fd,
50449 struct getdents_callback64 {
50450 struct linux_dirent64 __user * current_dir;
50451 struct linux_dirent64 __user * previous;
50452+ struct file *file;
50453 int count;
50454 int error;
50455 };
50456@@ -241,6 +255,10 @@ static int filldir64(void * __buf, const char * name, int namlen, loff_t offset,
50457 buf->error = -EINVAL; /* only used if we fail.. */
50458 if (reclen > buf->count)
50459 return -EINVAL;
50460+
50461+ if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
50462+ return 0;
50463+
50464 dirent = buf->previous;
50465 if (dirent) {
50466 if (__put_user(offset, &dirent->d_off))
50467@@ -287,6 +305,7 @@ SYSCALL_DEFINE3(getdents64, unsigned int, fd,
50468
50469 buf.current_dir = dirent;
50470 buf.previous = NULL;
50471+ buf.file = file;
50472 buf.count = count;
50473 buf.error = 0;
50474
50475@@ -295,7 +314,7 @@ SYSCALL_DEFINE3(getdents64, unsigned int, fd,
50476 error = buf.error;
50477 lastdirent = buf.previous;
50478 if (lastdirent) {
50479- typeof(lastdirent->d_off) d_off = file->f_pos;
50480+ typeof(((struct linux_dirent64 *)0)->d_off) d_off = file->f_pos;
50481 if (__put_user(d_off, &lastdirent->d_off))
50482 error = -EFAULT;
50483 else
50484diff --git a/fs/reiserfs/do_balan.c b/fs/reiserfs/do_balan.c
50485index 2b7882b..1c5ef48 100644
50486--- a/fs/reiserfs/do_balan.c
50487+++ b/fs/reiserfs/do_balan.c
50488@@ -2051,7 +2051,7 @@ void do_balance(struct tree_balance *tb, /* tree_balance structure */
50489 return;
50490 }
50491
50492- atomic_inc(&(fs_generation(tb->tb_sb)));
50493+ atomic_inc_unchecked(&(fs_generation(tb->tb_sb)));
50494 do_balance_starts(tb);
50495
50496 /* balance leaf returns 0 except if combining L R and S into
50497diff --git a/fs/reiserfs/procfs.c b/fs/reiserfs/procfs.c
50498index e60e870..f40ac16 100644
50499--- a/fs/reiserfs/procfs.c
50500+++ b/fs/reiserfs/procfs.c
50501@@ -112,7 +112,7 @@ static int show_super(struct seq_file *m, struct super_block *sb)
50502 "SMALL_TAILS " : "NO_TAILS ",
50503 replay_only(sb) ? "REPLAY_ONLY " : "",
50504 convert_reiserfs(sb) ? "CONV " : "",
50505- atomic_read(&r->s_generation_counter),
50506+ atomic_read_unchecked(&r->s_generation_counter),
50507 SF(s_disk_reads), SF(s_disk_writes), SF(s_fix_nodes),
50508 SF(s_do_balance), SF(s_unneeded_left_neighbor),
50509 SF(s_good_search_by_key_reada), SF(s_bmaps),
50510diff --git a/fs/reiserfs/reiserfs.h b/fs/reiserfs/reiserfs.h
50511index 33215f5..c5d427a 100644
50512--- a/fs/reiserfs/reiserfs.h
50513+++ b/fs/reiserfs/reiserfs.h
50514@@ -453,7 +453,7 @@ struct reiserfs_sb_info {
50515 /* Comment? -Hans */
50516 wait_queue_head_t s_wait;
50517 /* To be obsoleted soon by per buffer seals.. -Hans */
50518- atomic_t s_generation_counter; // increased by one every time the
50519+ atomic_unchecked_t s_generation_counter; // increased by one every time the
50520 // tree gets re-balanced
50521 unsigned long s_properties; /* File system properties. Currently holds
50522 on-disk FS format */
50523@@ -1978,7 +1978,7 @@ static inline loff_t max_reiserfs_offset(struct inode *inode)
50524 #define REISERFS_USER_MEM 1 /* reiserfs user memory mode */
50525
50526 #define fs_generation(s) (REISERFS_SB(s)->s_generation_counter)
50527-#define get_generation(s) atomic_read (&fs_generation(s))
50528+#define get_generation(s) atomic_read_unchecked (&fs_generation(s))
50529 #define FILESYSTEM_CHANGED_TB(tb) (get_generation((tb)->tb_sb) != (tb)->fs_gen)
50530 #define __fs_changed(gen,s) (gen != get_generation (s))
50531 #define fs_changed(gen,s) \
50532diff --git a/fs/select.c b/fs/select.c
50533index db14c78..3aae1bd 100644
50534--- a/fs/select.c
50535+++ b/fs/select.c
50536@@ -20,6 +20,7 @@
50537 #include <linux/export.h>
50538 #include <linux/slab.h>
50539 #include <linux/poll.h>
50540+#include <linux/security.h>
50541 #include <linux/personality.h> /* for STICKY_TIMEOUTS */
50542 #include <linux/file.h>
50543 #include <linux/fdtable.h>
50544@@ -831,6 +832,7 @@ int do_sys_poll(struct pollfd __user *ufds, unsigned int nfds,
50545 struct poll_list *walk = head;
50546 unsigned long todo = nfds;
50547
50548+ gr_learn_resource(current, RLIMIT_NOFILE, nfds, 1);
50549 if (nfds > rlimit(RLIMIT_NOFILE))
50550 return -EINVAL;
50551
50552diff --git a/fs/seq_file.c b/fs/seq_file.c
50553index 14cf9de..adc4d5b 100644
50554--- a/fs/seq_file.c
50555+++ b/fs/seq_file.c
50556@@ -9,6 +9,7 @@
50557 #include <linux/export.h>
50558 #include <linux/seq_file.h>
50559 #include <linux/slab.h>
50560+#include <linux/sched.h>
50561
50562 #include <asm/uaccess.h>
50563 #include <asm/page.h>
50564@@ -56,6 +57,9 @@ int seq_open(struct file *file, const struct seq_operations *op)
50565 memset(p, 0, sizeof(*p));
50566 mutex_init(&p->lock);
50567 p->op = op;
50568+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
50569+ p->exec_id = current->exec_id;
50570+#endif
50571
50572 /*
50573 * Wrappers around seq_open(e.g. swaps_open) need to be
50574@@ -92,7 +96,7 @@ static int traverse(struct seq_file *m, loff_t offset)
50575 return 0;
50576 }
50577 if (!m->buf) {
50578- m->buf = kmalloc(m->size = PAGE_SIZE, GFP_KERNEL);
50579+ m->buf = kmalloc(m->size = PAGE_SIZE, GFP_KERNEL | GFP_USERCOPY);
50580 if (!m->buf)
50581 return -ENOMEM;
50582 }
50583@@ -132,7 +136,7 @@ static int traverse(struct seq_file *m, loff_t offset)
50584 Eoverflow:
50585 m->op->stop(m, p);
50586 kfree(m->buf);
50587- m->buf = kmalloc(m->size <<= 1, GFP_KERNEL);
50588+ m->buf = kmalloc(m->size <<= 1, GFP_KERNEL | GFP_USERCOPY);
50589 return !m->buf ? -ENOMEM : -EAGAIN;
50590 }
50591
50592@@ -187,7 +191,7 @@ ssize_t seq_read(struct file *file, char __user *buf, size_t size, loff_t *ppos)
50593
50594 /* grab buffer if we didn't have one */
50595 if (!m->buf) {
50596- m->buf = kmalloc(m->size = PAGE_SIZE, GFP_KERNEL);
50597+ m->buf = kmalloc(m->size = PAGE_SIZE, GFP_KERNEL | GFP_USERCOPY);
50598 if (!m->buf)
50599 goto Enomem;
50600 }
50601@@ -228,7 +232,7 @@ ssize_t seq_read(struct file *file, char __user *buf, size_t size, loff_t *ppos)
50602 goto Fill;
50603 m->op->stop(m, p);
50604 kfree(m->buf);
50605- m->buf = kmalloc(m->size <<= 1, GFP_KERNEL);
50606+ m->buf = kmalloc(m->size <<= 1, GFP_KERNEL | GFP_USERCOPY);
50607 if (!m->buf)
50608 goto Enomem;
50609 m->count = 0;
50610@@ -577,7 +581,7 @@ static void single_stop(struct seq_file *p, void *v)
50611 int single_open(struct file *file, int (*show)(struct seq_file *, void *),
50612 void *data)
50613 {
50614- struct seq_operations *op = kmalloc(sizeof(*op), GFP_KERNEL);
50615+ seq_operations_no_const *op = kmalloc(sizeof(*op), GFP_KERNEL);
50616 int res = -ENOMEM;
50617
50618 if (op) {
50619diff --git a/fs/splice.c b/fs/splice.c
50620index 41514dd..6564a93 100644
50621--- a/fs/splice.c
50622+++ b/fs/splice.c
50623@@ -194,7 +194,7 @@ ssize_t splice_to_pipe(struct pipe_inode_info *pipe,
50624 pipe_lock(pipe);
50625
50626 for (;;) {
50627- if (!pipe->readers) {
50628+ if (!atomic_read(&pipe->readers)) {
50629 send_sig(SIGPIPE, current, 0);
50630 if (!ret)
50631 ret = -EPIPE;
50632@@ -248,9 +248,9 @@ ssize_t splice_to_pipe(struct pipe_inode_info *pipe,
50633 do_wakeup = 0;
50634 }
50635
50636- pipe->waiting_writers++;
50637+ atomic_inc(&pipe->waiting_writers);
50638 pipe_wait(pipe);
50639- pipe->waiting_writers--;
50640+ atomic_dec(&pipe->waiting_writers);
50641 }
50642
50643 pipe_unlock(pipe);
50644@@ -563,7 +563,7 @@ static ssize_t kernel_readv(struct file *file, const struct iovec *vec,
50645 old_fs = get_fs();
50646 set_fs(get_ds());
50647 /* The cast to a user pointer is valid due to the set_fs() */
50648- res = vfs_readv(file, (const struct iovec __user *)vec, vlen, &pos);
50649+ res = vfs_readv(file, (const struct iovec __force_user *)vec, vlen, &pos);
50650 set_fs(old_fs);
50651
50652 return res;
50653@@ -578,7 +578,7 @@ static ssize_t kernel_write(struct file *file, const char *buf, size_t count,
50654 old_fs = get_fs();
50655 set_fs(get_ds());
50656 /* The cast to a user pointer is valid due to the set_fs() */
50657- res = vfs_write(file, (const char __user *)buf, count, &pos);
50658+ res = vfs_write(file, (const char __force_user *)buf, count, &pos);
50659 set_fs(old_fs);
50660
50661 return res;
50662@@ -630,7 +630,7 @@ ssize_t default_file_splice_read(struct file *in, loff_t *ppos,
50663 goto err;
50664
50665 this_len = min_t(size_t, len, PAGE_CACHE_SIZE - offset);
50666- vec[i].iov_base = (void __user *) page_address(page);
50667+ vec[i].iov_base = (void __force_user *) page_address(page);
50668 vec[i].iov_len = this_len;
50669 spd.pages[i] = page;
50670 spd.nr_pages++;
50671@@ -849,10 +849,10 @@ EXPORT_SYMBOL(splice_from_pipe_feed);
50672 int splice_from_pipe_next(struct pipe_inode_info *pipe, struct splice_desc *sd)
50673 {
50674 while (!pipe->nrbufs) {
50675- if (!pipe->writers)
50676+ if (!atomic_read(&pipe->writers))
50677 return 0;
50678
50679- if (!pipe->waiting_writers && sd->num_spliced)
50680+ if (!atomic_read(&pipe->waiting_writers) && sd->num_spliced)
50681 return 0;
50682
50683 if (sd->flags & SPLICE_F_NONBLOCK)
50684@@ -1190,7 +1190,7 @@ ssize_t splice_direct_to_actor(struct file *in, struct splice_desc *sd,
50685 * out of the pipe right after the splice_to_pipe(). So set
50686 * PIPE_READERS appropriately.
50687 */
50688- pipe->readers = 1;
50689+ atomic_set(&pipe->readers, 1);
50690
50691 current->splice_pipe = pipe;
50692 }
50693@@ -1743,9 +1743,9 @@ static int ipipe_prep(struct pipe_inode_info *pipe, unsigned int flags)
50694 ret = -ERESTARTSYS;
50695 break;
50696 }
50697- if (!pipe->writers)
50698+ if (!atomic_read(&pipe->writers))
50699 break;
50700- if (!pipe->waiting_writers) {
50701+ if (!atomic_read(&pipe->waiting_writers)) {
50702 if (flags & SPLICE_F_NONBLOCK) {
50703 ret = -EAGAIN;
50704 break;
50705@@ -1777,7 +1777,7 @@ static int opipe_prep(struct pipe_inode_info *pipe, unsigned int flags)
50706 pipe_lock(pipe);
50707
50708 while (pipe->nrbufs >= pipe->buffers) {
50709- if (!pipe->readers) {
50710+ if (!atomic_read(&pipe->readers)) {
50711 send_sig(SIGPIPE, current, 0);
50712 ret = -EPIPE;
50713 break;
50714@@ -1790,9 +1790,9 @@ static int opipe_prep(struct pipe_inode_info *pipe, unsigned int flags)
50715 ret = -ERESTARTSYS;
50716 break;
50717 }
50718- pipe->waiting_writers++;
50719+ atomic_inc(&pipe->waiting_writers);
50720 pipe_wait(pipe);
50721- pipe->waiting_writers--;
50722+ atomic_dec(&pipe->waiting_writers);
50723 }
50724
50725 pipe_unlock(pipe);
50726@@ -1828,14 +1828,14 @@ retry:
50727 pipe_double_lock(ipipe, opipe);
50728
50729 do {
50730- if (!opipe->readers) {
50731+ if (!atomic_read(&opipe->readers)) {
50732 send_sig(SIGPIPE, current, 0);
50733 if (!ret)
50734 ret = -EPIPE;
50735 break;
50736 }
50737
50738- if (!ipipe->nrbufs && !ipipe->writers)
50739+ if (!ipipe->nrbufs && !atomic_read(&ipipe->writers))
50740 break;
50741
50742 /*
50743@@ -1932,7 +1932,7 @@ static int link_pipe(struct pipe_inode_info *ipipe,
50744 pipe_double_lock(ipipe, opipe);
50745
50746 do {
50747- if (!opipe->readers) {
50748+ if (!atomic_read(&opipe->readers)) {
50749 send_sig(SIGPIPE, current, 0);
50750 if (!ret)
50751 ret = -EPIPE;
50752@@ -1977,7 +1977,7 @@ static int link_pipe(struct pipe_inode_info *ipipe,
50753 * return EAGAIN if we have the potential of some data in the
50754 * future, otherwise just return 0
50755 */
50756- if (!ret && ipipe->waiting_writers && (flags & SPLICE_F_NONBLOCK))
50757+ if (!ret && atomic_read(&ipipe->waiting_writers) && (flags & SPLICE_F_NONBLOCK))
50758 ret = -EAGAIN;
50759
50760 pipe_unlock(ipipe);
50761diff --git a/fs/sysfs/dir.c b/fs/sysfs/dir.c
50762index 2fbdff6..5530a61 100644
50763--- a/fs/sysfs/dir.c
50764+++ b/fs/sysfs/dir.c
50765@@ -685,6 +685,18 @@ static int create_dir(struct kobject *kobj, struct sysfs_dirent *parent_sd,
50766 struct sysfs_dirent *sd;
50767 int rc;
50768
50769+#ifdef CONFIG_GRKERNSEC_SYSFS_RESTRICT
50770+ const char *parent_name = parent_sd->s_name;
50771+
50772+ mode = S_IFDIR | S_IRWXU;
50773+
50774+ if ((!strcmp(parent_name, "") && (!strcmp(name, "devices") || !strcmp(name, "fs"))) ||
50775+ (!strcmp(parent_name, "devices") && !strcmp(name, "system")) ||
50776+ (!strcmp(parent_name, "fs") && (!strcmp(name, "selinux") || !strcmp(name, "fuse"))) ||
50777+ (!strcmp(parent_name, "system") && !strcmp(name, "cpu")))
50778+ mode = S_IFDIR | S_IRWXU | S_IRUGO | S_IXUGO;
50779+#endif
50780+
50781 /* allocate */
50782 sd = sysfs_new_dirent(name, mode, SYSFS_DIR);
50783 if (!sd)
50784diff --git a/fs/sysfs/file.c b/fs/sysfs/file.c
50785index 00012e3..8392349 100644
50786--- a/fs/sysfs/file.c
50787+++ b/fs/sysfs/file.c
50788@@ -37,7 +37,7 @@ static DEFINE_SPINLOCK(sysfs_open_dirent_lock);
50789
50790 struct sysfs_open_dirent {
50791 atomic_t refcnt;
50792- atomic_t event;
50793+ atomic_unchecked_t event;
50794 wait_queue_head_t poll;
50795 struct list_head buffers; /* goes through sysfs_buffer.list */
50796 };
50797@@ -81,7 +81,7 @@ static int fill_read_buffer(struct dentry * dentry, struct sysfs_buffer * buffer
50798 if (!sysfs_get_active(attr_sd))
50799 return -ENODEV;
50800
50801- buffer->event = atomic_read(&attr_sd->s_attr.open->event);
50802+ buffer->event = atomic_read_unchecked(&attr_sd->s_attr.open->event);
50803 count = ops->show(kobj, attr_sd->s_attr.attr, buffer->page);
50804
50805 sysfs_put_active(attr_sd);
50806@@ -287,7 +287,7 @@ static int sysfs_get_open_dirent(struct sysfs_dirent *sd,
50807 return -ENOMEM;
50808
50809 atomic_set(&new_od->refcnt, 0);
50810- atomic_set(&new_od->event, 1);
50811+ atomic_set_unchecked(&new_od->event, 1);
50812 init_waitqueue_head(&new_od->poll);
50813 INIT_LIST_HEAD(&new_od->buffers);
50814 goto retry;
50815@@ -432,7 +432,7 @@ static unsigned int sysfs_poll(struct file *filp, poll_table *wait)
50816
50817 sysfs_put_active(attr_sd);
50818
50819- if (buffer->event != atomic_read(&od->event))
50820+ if (buffer->event != atomic_read_unchecked(&od->event))
50821 goto trigger;
50822
50823 return DEFAULT_POLLMASK;
50824@@ -451,7 +451,7 @@ void sysfs_notify_dirent(struct sysfs_dirent *sd)
50825
50826 od = sd->s_attr.open;
50827 if (od) {
50828- atomic_inc(&od->event);
50829+ atomic_inc_unchecked(&od->event);
50830 wake_up_interruptible(&od->poll);
50831 }
50832
50833diff --git a/fs/sysfs/symlink.c b/fs/sysfs/symlink.c
50834index a7ac78f..02158e1 100644
50835--- a/fs/sysfs/symlink.c
50836+++ b/fs/sysfs/symlink.c
50837@@ -286,7 +286,7 @@ static void *sysfs_follow_link(struct dentry *dentry, struct nameidata *nd)
50838
50839 static void sysfs_put_link(struct dentry *dentry, struct nameidata *nd, void *cookie)
50840 {
50841- char *page = nd_get_link(nd);
50842+ const char *page = nd_get_link(nd);
50843 if (!IS_ERR(page))
50844 free_page((unsigned long)page);
50845 }
50846diff --git a/fs/udf/misc.c b/fs/udf/misc.c
50847index c175b4d..8f36a16 100644
50848--- a/fs/udf/misc.c
50849+++ b/fs/udf/misc.c
50850@@ -289,7 +289,7 @@ void udf_new_tag(char *data, uint16_t ident, uint16_t version, uint16_t snum,
50851
50852 u8 udf_tag_checksum(const struct tag *t)
50853 {
50854- u8 *data = (u8 *)t;
50855+ const u8 *data = (const u8 *)t;
50856 u8 checksum = 0;
50857 int i;
50858 for (i = 0; i < sizeof(struct tag); ++i)
50859diff --git a/fs/utimes.c b/fs/utimes.c
50860index fa4dbe4..e12d1b9 100644
50861--- a/fs/utimes.c
50862+++ b/fs/utimes.c
50863@@ -1,6 +1,7 @@
50864 #include <linux/compiler.h>
50865 #include <linux/file.h>
50866 #include <linux/fs.h>
50867+#include <linux/security.h>
50868 #include <linux/linkage.h>
50869 #include <linux/mount.h>
50870 #include <linux/namei.h>
50871@@ -101,6 +102,12 @@ static int utimes_common(struct path *path, struct timespec *times)
50872 goto mnt_drop_write_and_out;
50873 }
50874 }
50875+
50876+ if (!gr_acl_handle_utime(path->dentry, path->mnt)) {
50877+ error = -EACCES;
50878+ goto mnt_drop_write_and_out;
50879+ }
50880+
50881 mutex_lock(&inode->i_mutex);
50882 error = notify_change(path->dentry, &newattrs);
50883 mutex_unlock(&inode->i_mutex);
50884diff --git a/fs/xattr.c b/fs/xattr.c
50885index 4d45b71..2ec08e10 100644
50886--- a/fs/xattr.c
50887+++ b/fs/xattr.c
50888@@ -316,7 +316,7 @@ EXPORT_SYMBOL_GPL(vfs_removexattr);
50889 * Extended attribute SET operations
50890 */
50891 static long
50892-setxattr(struct dentry *d, const char __user *name, const void __user *value,
50893+setxattr(struct path *path, const char __user *name, const void __user *value,
50894 size_t size, int flags)
50895 {
50896 int error;
50897@@ -349,7 +349,12 @@ setxattr(struct dentry *d, const char __user *name, const void __user *value,
50898 }
50899 }
50900
50901- error = vfs_setxattr(d, kname, kvalue, size, flags);
50902+ if (!gr_acl_handle_setxattr(path->dentry, path->mnt)) {
50903+ error = -EACCES;
50904+ goto out;
50905+ }
50906+
50907+ error = vfs_setxattr(path->dentry, kname, kvalue, size, flags);
50908 out:
50909 if (vvalue)
50910 vfree(vvalue);
50911@@ -370,7 +375,7 @@ SYSCALL_DEFINE5(setxattr, const char __user *, pathname,
50912 return error;
50913 error = mnt_want_write(path.mnt);
50914 if (!error) {
50915- error = setxattr(path.dentry, name, value, size, flags);
50916+ error = setxattr(&path, name, value, size, flags);
50917 mnt_drop_write(path.mnt);
50918 }
50919 path_put(&path);
50920@@ -389,7 +394,7 @@ SYSCALL_DEFINE5(lsetxattr, const char __user *, pathname,
50921 return error;
50922 error = mnt_want_write(path.mnt);
50923 if (!error) {
50924- error = setxattr(path.dentry, name, value, size, flags);
50925+ error = setxattr(&path, name, value, size, flags);
50926 mnt_drop_write(path.mnt);
50927 }
50928 path_put(&path);
50929@@ -401,17 +406,15 @@ SYSCALL_DEFINE5(fsetxattr, int, fd, const char __user *, name,
50930 {
50931 int fput_needed;
50932 struct file *f;
50933- struct dentry *dentry;
50934 int error = -EBADF;
50935
50936 f = fget_light(fd, &fput_needed);
50937 if (!f)
50938 return error;
50939- dentry = f->f_path.dentry;
50940- audit_inode(NULL, dentry);
50941+ audit_inode(NULL, f->f_path.dentry);
50942 error = mnt_want_write_file(f);
50943 if (!error) {
50944- error = setxattr(dentry, name, value, size, flags);
50945+ error = setxattr(&f->f_path, name, value, size, flags);
50946 mnt_drop_write_file(f);
50947 }
50948 fput_light(f, fput_needed);
50949diff --git a/fs/xattr_acl.c b/fs/xattr_acl.c
50950index 69d06b0..c0996e5 100644
50951--- a/fs/xattr_acl.c
50952+++ b/fs/xattr_acl.c
50953@@ -17,8 +17,8 @@
50954 struct posix_acl *
50955 posix_acl_from_xattr(const void *value, size_t size)
50956 {
50957- posix_acl_xattr_header *header = (posix_acl_xattr_header *)value;
50958- posix_acl_xattr_entry *entry = (posix_acl_xattr_entry *)(header+1), *end;
50959+ const posix_acl_xattr_header *header = (const posix_acl_xattr_header *)value;
50960+ const posix_acl_xattr_entry *entry = (const posix_acl_xattr_entry *)(header+1), *end;
50961 int count;
50962 struct posix_acl *acl;
50963 struct posix_acl_entry *acl_e;
50964diff --git a/fs/xfs/xfs_bmap.c b/fs/xfs/xfs_bmap.c
50965index 848ffa7..1f249bf 100644
50966--- a/fs/xfs/xfs_bmap.c
50967+++ b/fs/xfs/xfs_bmap.c
50968@@ -189,7 +189,7 @@ xfs_bmap_validate_ret(
50969 int nmap,
50970 int ret_nmap);
50971 #else
50972-#define xfs_bmap_validate_ret(bno,len,flags,mval,onmap,nmap)
50973+#define xfs_bmap_validate_ret(bno,len,flags,mval,onmap,nmap) do {} while (0)
50974 #endif /* DEBUG */
50975
50976 STATIC int
50977diff --git a/fs/xfs/xfs_dir2_sf.c b/fs/xfs/xfs_dir2_sf.c
50978index 1b9fc3e..e1bdde0 100644
50979--- a/fs/xfs/xfs_dir2_sf.c
50980+++ b/fs/xfs/xfs_dir2_sf.c
50981@@ -851,7 +851,15 @@ xfs_dir2_sf_getdents(
50982 }
50983
50984 ino = xfs_dir2_sfe_get_ino(sfp, sfep);
50985- if (filldir(dirent, (char *)sfep->name, sfep->namelen,
50986+ if (dp->i_df.if_u1.if_data == dp->i_df.if_u2.if_inline_data) {
50987+ char name[sfep->namelen];
50988+ memcpy(name, sfep->name, sfep->namelen);
50989+ if (filldir(dirent, name, sfep->namelen,
50990+ off & 0x7fffffff, ino, DT_UNKNOWN)) {
50991+ *offset = off & 0x7fffffff;
50992+ return 0;
50993+ }
50994+ } else if (filldir(dirent, (char *)sfep->name, sfep->namelen,
50995 off & 0x7fffffff, ino, DT_UNKNOWN)) {
50996 *offset = off & 0x7fffffff;
50997 return 0;
50998diff --git a/fs/xfs/xfs_ioctl.c b/fs/xfs/xfs_ioctl.c
50999index 0e0232c..fa5c3fe 100644
51000--- a/fs/xfs/xfs_ioctl.c
51001+++ b/fs/xfs/xfs_ioctl.c
51002@@ -126,7 +126,7 @@ xfs_find_handle(
51003 }
51004
51005 error = -EFAULT;
51006- if (copy_to_user(hreq->ohandle, &handle, hsize) ||
51007+ if (hsize > sizeof handle || copy_to_user(hreq->ohandle, &handle, hsize) ||
51008 copy_to_user(hreq->ohandlen, &hsize, sizeof(__s32)))
51009 goto out_put;
51010
51011diff --git a/fs/xfs/xfs_iops.c b/fs/xfs/xfs_iops.c
51012index 4e00cf0..3374374 100644
51013--- a/fs/xfs/xfs_iops.c
51014+++ b/fs/xfs/xfs_iops.c
51015@@ -394,7 +394,7 @@ xfs_vn_put_link(
51016 struct nameidata *nd,
51017 void *p)
51018 {
51019- char *s = nd_get_link(nd);
51020+ const char *s = nd_get_link(nd);
51021
51022 if (!IS_ERR(s))
51023 kfree(s);
51024diff --git a/grsecurity/Kconfig b/grsecurity/Kconfig
51025new file mode 100644
51026index 0000000..10c36fb
51027--- /dev/null
51028+++ b/grsecurity/Kconfig
51029@@ -0,0 +1,964 @@
51030+#
51031+# grecurity configuration
51032+#
51033+menu "Memory Protections"
51034+depends on GRKERNSEC
51035+
51036+config GRKERNSEC_KMEM
51037+ bool "Deny reading/writing to /dev/kmem, /dev/mem, and /dev/port"
51038+ default y if GRKERNSEC_CONFIG_AUTO
51039+ select STRICT_DEVMEM if (X86 || ARM || TILE || S390)
51040+ help
51041+ If you say Y here, /dev/kmem and /dev/mem won't be allowed to
51042+ be written to or read from to modify or leak the contents of the running
51043+ kernel. /dev/port will also not be allowed to be opened. If you have module
51044+ support disabled, enabling this will close up four ways that are
51045+ currently used to insert malicious code into the running kernel.
51046+ Even with all these features enabled, we still highly recommend that
51047+ you use the RBAC system, as it is still possible for an attacker to
51048+ modify the running kernel through privileged I/O granted by ioperm/iopl.
51049+ If you are not using XFree86, you may be able to stop this additional
51050+ case by enabling the 'Disable privileged I/O' option. Though nothing
51051+ legitimately writes to /dev/kmem, XFree86 does need to write to /dev/mem,
51052+ but only to video memory, which is the only writing we allow in this
51053+ case. If /dev/kmem or /dev/mem are mmaped without PROT_WRITE, they will
51054+ not be allowed to mprotect it with PROT_WRITE later.
51055+ It is highly recommended that you say Y here if you meet all the
51056+ conditions above.
51057+
51058+config GRKERNSEC_VM86
51059+ bool "Restrict VM86 mode"
51060+ default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER)
51061+ depends on X86_32
51062+
51063+ help
51064+ If you say Y here, only processes with CAP_SYS_RAWIO will be able to
51065+ make use of a special execution mode on 32bit x86 processors called
51066+ Virtual 8086 (VM86) mode. XFree86 may need vm86 mode for certain
51067+ video cards and will still work with this option enabled. The purpose
51068+ of the option is to prevent exploitation of emulation errors in
51069+ virtualization of vm86 mode like the one discovered in VMWare in 2009.
51070+ Nearly all users should be able to enable this option.
51071+
51072+config GRKERNSEC_IO
51073+ bool "Disable privileged I/O"
51074+ default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER)
51075+ depends on X86
51076+ select RTC_CLASS
51077+ select RTC_INTF_DEV
51078+ select RTC_DRV_CMOS
51079+
51080+ help
51081+ If you say Y here, all ioperm and iopl calls will return an error.
51082+ Ioperm and iopl can be used to modify the running kernel.
51083+ Unfortunately, some programs need this access to operate properly,
51084+ the most notable of which are XFree86 and hwclock. hwclock can be
51085+ remedied by having RTC support in the kernel, so real-time
51086+ clock support is enabled if this option is enabled, to ensure
51087+ that hwclock operates correctly. XFree86 still will not
51088+ operate correctly with this option enabled, so DO NOT CHOOSE Y
51089+ IF YOU USE XFree86. If you use XFree86 and you still want to
51090+ protect your kernel against modification, use the RBAC system.
51091+
51092+config GRKERNSEC_JIT_HARDEN
51093+ bool "Harden BPF JIT against spray attacks"
51094+ default y if GRKERNSEC_CONFIG_AUTO
51095+ depends on BPF_JIT
51096+ help
51097+ If you say Y here, the native code generated by the kernel's Berkeley
51098+ Packet Filter (BPF) JIT engine will be hardened against JIT-spraying
51099+ attacks that attempt to fit attacker-beneficial instructions in
51100+ 32bit immediate fields of JIT-generated native instructions. The
51101+ attacker will generally aim to cause an unintended instruction sequence
51102+ of JIT-generated native code to execute by jumping into the middle of
51103+ a generated instruction. This feature effectively randomizes the 32bit
51104+ immediate constants present in the generated code to thwart such attacks.
51105+
51106+ If you're using KERNEXEC, it's recommended that you enable this option
51107+ to supplement the hardening of the kernel.
51108+
51109+config GRKERNSEC_PROC_MEMMAP
51110+ bool "Harden ASLR against information leaks and entropy reduction"
51111+ default y if (GRKERNSEC_CONFIG_AUTO || PAX_NOEXEC || PAX_ASLR)
51112+ depends on PAX_NOEXEC || PAX_ASLR
51113+ help
51114+ If you say Y here, the /proc/<pid>/maps and /proc/<pid>/stat files will
51115+ give no information about the addresses of its mappings if
51116+ PaX features that rely on random addresses are enabled on the task.
51117+ In addition to sanitizing this information and disabling other
51118+ dangerous sources of information, this option causes reads of sensitive
51119+ /proc/<pid> entries where the file descriptor was opened in a different
51120+ task than the one performing the read. Such attempts are logged.
51121+ This option also limits argv/env strings for suid/sgid binaries
51122+ to 512KB to prevent a complete exhaustion of the stack entropy provided
51123+ by ASLR. Finally, it places an 8MB stack resource limit on suid/sgid
51124+ binaries to prevent alternative mmap layouts from being abused.
51125+
51126+ If you use PaX it is essential that you say Y here as it closes up
51127+ several holes that make full ASLR useless locally.
51128+
51129+config GRKERNSEC_BRUTE
51130+ bool "Deter exploit bruteforcing"
51131+ default y if GRKERNSEC_CONFIG_AUTO
51132+ help
51133+ If you say Y here, attempts to bruteforce exploits against forking
51134+ daemons such as apache or sshd, as well as against suid/sgid binaries
51135+ will be deterred. When a child of a forking daemon is killed by PaX
51136+ or crashes due to an illegal instruction or other suspicious signal,
51137+ the parent process will be delayed 30 seconds upon every subsequent
51138+ fork until the administrator is able to assess the situation and
51139+ restart the daemon.
51140+ In the suid/sgid case, the attempt is logged, the user has all their
51141+ processes terminated, and they are prevented from executing any further
51142+ processes for 15 minutes.
51143+ It is recommended that you also enable signal logging in the auditing
51144+ section so that logs are generated when a process triggers a suspicious
51145+ signal.
51146+ If the sysctl option is enabled, a sysctl option with name
51147+ "deter_bruteforce" is created.
51148+
51149+
51150+config GRKERNSEC_MODHARDEN
51151+ bool "Harden module auto-loading"
51152+ default y if GRKERNSEC_CONFIG_AUTO
51153+ depends on MODULES
51154+ help
51155+ If you say Y here, module auto-loading in response to use of some
51156+ feature implemented by an unloaded module will be restricted to
51157+ root users. Enabling this option helps defend against attacks
51158+ by unprivileged users who abuse the auto-loading behavior to
51159+ cause a vulnerable module to load that is then exploited.
51160+
51161+ If this option prevents a legitimate use of auto-loading for a
51162+ non-root user, the administrator can execute modprobe manually
51163+ with the exact name of the module mentioned in the alert log.
51164+ Alternatively, the administrator can add the module to the list
51165+ of modules loaded at boot by modifying init scripts.
51166+
51167+ Modification of init scripts will most likely be needed on
51168+ Ubuntu servers with encrypted home directory support enabled,
51169+ as the first non-root user logging in will cause the ecb(aes),
51170+ ecb(aes)-all, cbc(aes), and cbc(aes)-all modules to be loaded.
51171+
51172+config GRKERNSEC_HIDESYM
51173+ bool "Hide kernel symbols"
51174+ default y if GRKERNSEC_CONFIG_AUTO
51175+ select PAX_USERCOPY_SLABS
51176+ help
51177+ If you say Y here, getting information on loaded modules, and
51178+ displaying all kernel symbols through a syscall will be restricted
51179+ to users with CAP_SYS_MODULE. For software compatibility reasons,
51180+ /proc/kallsyms will be restricted to the root user. The RBAC
51181+ system can hide that entry even from root.
51182+
51183+ This option also prevents leaking of kernel addresses through
51184+ several /proc entries.
51185+
51186+ Note that this option is only effective provided the following
51187+ conditions are met:
51188+ 1) The kernel using grsecurity is not precompiled by some distribution
51189+ 2) You have also enabled GRKERNSEC_DMESG
51190+ 3) You are using the RBAC system and hiding other files such as your
51191+ kernel image and System.map. Alternatively, enabling this option
51192+ causes the permissions on /boot, /lib/modules, and the kernel
51193+ source directory to change at compile time to prevent
51194+ reading by non-root users.
51195+ If the above conditions are met, this option will aid in providing a
51196+ useful protection against local kernel exploitation of overflows
51197+ and arbitrary read/write vulnerabilities.
51198+
51199+config GRKERNSEC_KERN_LOCKOUT
51200+ bool "Active kernel exploit response"
51201+ default y if GRKERNSEC_CONFIG_AUTO
51202+ depends on X86 || ARM || PPC || SPARC
51203+ help
51204+ If you say Y here, when a PaX alert is triggered due to suspicious
51205+ activity in the kernel (from KERNEXEC/UDEREF/USERCOPY)
51206+ or an OOPS occurs due to bad memory accesses, instead of just
51207+ terminating the offending process (and potentially allowing
51208+ a subsequent exploit from the same user), we will take one of two
51209+ actions:
51210+ If the user was root, we will panic the system
51211+ If the user was non-root, we will log the attempt, terminate
51212+ all processes owned by the user, then prevent them from creating
51213+ any new processes until the system is restarted
51214+ This deters repeated kernel exploitation/bruteforcing attempts
51215+ and is useful for later forensics.
51216+
51217+endmenu
51218+menu "Role Based Access Control Options"
51219+depends on GRKERNSEC
51220+
51221+config GRKERNSEC_RBAC_DEBUG
51222+ bool
51223+
51224+config GRKERNSEC_NO_RBAC
51225+ bool "Disable RBAC system"
51226+ help
51227+ If you say Y here, the /dev/grsec device will be removed from the kernel,
51228+ preventing the RBAC system from being enabled. You should only say Y
51229+ here if you have no intention of using the RBAC system, so as to prevent
51230+ an attacker with root access from misusing the RBAC system to hide files
51231+ and processes when loadable module support and /dev/[k]mem have been
51232+ locked down.
51233+
51234+config GRKERNSEC_ACL_HIDEKERN
51235+ bool "Hide kernel processes"
51236+ help
51237+ If you say Y here, all kernel threads will be hidden to all
51238+ processes but those whose subject has the "view hidden processes"
51239+ flag.
51240+
51241+config GRKERNSEC_ACL_MAXTRIES
51242+ int "Maximum tries before password lockout"
51243+ default 3
51244+ help
51245+ This option enforces the maximum number of times a user can attempt
51246+ to authorize themselves with the grsecurity RBAC system before being
51247+ denied the ability to attempt authorization again for a specified time.
51248+ The lower the number, the harder it will be to brute-force a password.
51249+
51250+config GRKERNSEC_ACL_TIMEOUT
51251+ int "Time to wait after max password tries, in seconds"
51252+ default 30
51253+ help
51254+ This option specifies the time the user must wait after attempting to
51255+ authorize to the RBAC system with the maximum number of invalid
51256+ passwords. The higher the number, the harder it will be to brute-force
51257+ a password.
51258+
51259+endmenu
51260+menu "Filesystem Protections"
51261+depends on GRKERNSEC
51262+
51263+config GRKERNSEC_PROC
51264+ bool "Proc restrictions"
51265+ default y if GRKERNSEC_CONFIG_AUTO
51266+ help
51267+ If you say Y here, the permissions of the /proc filesystem
51268+ will be altered to enhance system security and privacy. You MUST
51269+ choose either a user only restriction or a user and group restriction.
51270+ Depending upon the option you choose, you can either restrict users to
51271+ see only the processes they themselves run, or choose a group that can
51272+ view all processes and files normally restricted to root if you choose
51273+ the "restrict to user only" option. NOTE: If you're running identd or
51274+ ntpd as a non-root user, you will have to run it as the group you
51275+ specify here.
51276+
51277+config GRKERNSEC_PROC_USER
51278+ bool "Restrict /proc to user only"
51279+ depends on GRKERNSEC_PROC
51280+ help
51281+ If you say Y here, non-root users will only be able to view their own
51282+ processes, and restricts them from viewing network-related information,
51283+ and viewing kernel symbol and module information.
51284+
51285+config GRKERNSEC_PROC_USERGROUP
51286+ bool "Allow special group"
51287+ default y if GRKERNSEC_CONFIG_AUTO
51288+ depends on GRKERNSEC_PROC && !GRKERNSEC_PROC_USER
51289+ help
51290+ If you say Y here, you will be able to select a group that will be
51291+ able to view all processes and network-related information. If you've
51292+ enabled GRKERNSEC_HIDESYM, kernel and symbol information may still
51293+ remain hidden. This option is useful if you want to run identd as
51294+ a non-root user. The group you select may also be chosen at boot time
51295+ via "grsec_proc_gid=" on the kernel commandline.
51296+
51297+config GRKERNSEC_PROC_GID
51298+ int "GID for special group"
51299+ depends on GRKERNSEC_PROC_USERGROUP
51300+ default 1001
51301+
51302+config GRKERNSEC_PROC_ADD
51303+ bool "Additional restrictions"
51304+ default y if GRKERNSEC_CONFIG_AUTO
51305+ depends on GRKERNSEC_PROC_USER || GRKERNSEC_PROC_USERGROUP
51306+ help
51307+ If you say Y here, additional restrictions will be placed on
51308+ /proc that keep normal users from viewing device information and
51309+ slabinfo information that could be useful for exploits.
51310+
51311+config GRKERNSEC_LINK
51312+ bool "Linking restrictions"
51313+ default y if GRKERNSEC_CONFIG_AUTO
51314+ help
51315+ If you say Y here, /tmp race exploits will be prevented, since users
51316+ will no longer be able to follow symlinks owned by other users in
51317+ world-writable +t directories (e.g. /tmp), unless the owner of the
51318+ symlink is the owner of the directory. users will also not be
51319+ able to hardlink to files they do not own. If the sysctl option is
51320+ enabled, a sysctl option with name "linking_restrictions" is created.
51321+
51322+config GRKERNSEC_SYMLINKOWN
51323+ bool "Kernel-enforced SymlinksIfOwnerMatch"
51324+ default y if GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER
51325+ help
51326+ Apache's SymlinksIfOwnerMatch option has an inherent race condition
51327+ that prevents it from being used as a security feature. As Apache
51328+ verifies the symlink by performing a stat() against the target of
51329+ the symlink before it is followed, an attacker can setup a symlink
51330+ to point to a same-owned file, then replace the symlink with one
51331+ that targets another user's file just after Apache "validates" the
51332+ symlink -- a classic TOCTOU race. If you say Y here, a complete,
51333+ race-free replacement for Apache's "SymlinksIfOwnerMatch" option
51334+ will be in place for the group you specify. If the sysctl option
51335+ is enabled, a sysctl option with name "enforce_symlinksifowner" is
51336+ created.
51337+
51338+config GRKERNSEC_SYMLINKOWN_GID
51339+ int "GID for users with kernel-enforced SymlinksIfOwnerMatch"
51340+ depends on GRKERNSEC_SYMLINKOWN
51341+ default 1006
51342+ help
51343+ Setting this GID determines what group kernel-enforced
51344+ SymlinksIfOwnerMatch will be enabled for. If the sysctl option
51345+ is enabled, a sysctl option with name "symlinkown_gid" is created.
51346+
51347+config GRKERNSEC_FIFO
51348+ bool "FIFO restrictions"
51349+ default y if GRKERNSEC_CONFIG_AUTO
51350+ help
51351+ If you say Y here, users will not be able to write to FIFOs they don't
51352+ own in world-writable +t directories (e.g. /tmp), unless the owner of
51353+ the FIFO is the same owner of the directory it's held in. If the sysctl
51354+ option is enabled, a sysctl option with name "fifo_restrictions" is
51355+ created.
51356+
51357+config GRKERNSEC_SYSFS_RESTRICT
51358+ bool "Sysfs/debugfs restriction"
51359+ default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER)
51360+ depends on SYSFS
51361+ help
51362+ If you say Y here, sysfs (the pseudo-filesystem mounted at /sys) and
51363+ any filesystem normally mounted under it (e.g. debugfs) will be
51364+ mostly accessible only by root. These filesystems generally provide access
51365+ to hardware and debug information that isn't appropriate for unprivileged
51366+ users of the system. Sysfs and debugfs have also become a large source
51367+ of new vulnerabilities, ranging from infoleaks to local compromise.
51368+ There has been very little oversight with an eye toward security involved
51369+ in adding new exporters of information to these filesystems, so their
51370+ use is discouraged.
51371+ For reasons of compatibility, a few directories have been whitelisted
51372+ for access by non-root users:
51373+ /sys/fs/selinux
51374+ /sys/fs/fuse
51375+ /sys/devices/system/cpu
51376+
51377+config GRKERNSEC_ROFS
51378+ bool "Runtime read-only mount protection"
51379+ help
51380+ If you say Y here, a sysctl option with name "romount_protect" will
51381+ be created. By setting this option to 1 at runtime, filesystems
51382+ will be protected in the following ways:
51383+ * No new writable mounts will be allowed
51384+ * Existing read-only mounts won't be able to be remounted read/write
51385+ * Write operations will be denied on all block devices
51386+ This option acts independently of grsec_lock: once it is set to 1,
51387+ it cannot be turned off. Therefore, please be mindful of the resulting
51388+ behavior if this option is enabled in an init script on a read-only
51389+ filesystem. This feature is mainly intended for secure embedded systems.
51390+
51391+config GRKERNSEC_CHROOT
51392+ bool "Chroot jail restrictions"
51393+ default y if GRKERNSEC_CONFIG_AUTO
51394+ help
51395+ If you say Y here, you will be able to choose several options that will
51396+ make breaking out of a chrooted jail much more difficult. If you
51397+ encounter no software incompatibilities with the following options, it
51398+ is recommended that you enable each one.
51399+
51400+config GRKERNSEC_CHROOT_MOUNT
51401+ bool "Deny mounts"
51402+ default y if GRKERNSEC_CONFIG_AUTO
51403+ depends on GRKERNSEC_CHROOT
51404+ help
51405+ If you say Y here, processes inside a chroot will not be able to
51406+ mount or remount filesystems. If the sysctl option is enabled, a
51407+ sysctl option with name "chroot_deny_mount" is created.
51408+
51409+config GRKERNSEC_CHROOT_DOUBLE
51410+ bool "Deny double-chroots"
51411+ default y if GRKERNSEC_CONFIG_AUTO
51412+ depends on GRKERNSEC_CHROOT
51413+ help
51414+ If you say Y here, processes inside a chroot will not be able to chroot
51415+ again outside the chroot. This is a widely used method of breaking
51416+ out of a chroot jail and should not be allowed. If the sysctl
51417+ option is enabled, a sysctl option with name
51418+ "chroot_deny_chroot" is created.
51419+
51420+config GRKERNSEC_CHROOT_PIVOT
51421+ bool "Deny pivot_root in chroot"
51422+ default y if GRKERNSEC_CONFIG_AUTO
51423+ depends on GRKERNSEC_CHROOT
51424+ help
51425+ If you say Y here, processes inside a chroot will not be able to use
51426+ a function called pivot_root() that was introduced in Linux 2.3.41. It
51427+ works similar to chroot in that it changes the root filesystem. This
51428+ function could be misused in a chrooted process to attempt to break out
51429+ of the chroot, and therefore should not be allowed. If the sysctl
51430+ option is enabled, a sysctl option with name "chroot_deny_pivot" is
51431+ created.
51432+
51433+config GRKERNSEC_CHROOT_CHDIR
51434+ bool "Enforce chdir(\"/\") on all chroots"
51435+ default y if GRKERNSEC_CONFIG_AUTO
51436+ depends on GRKERNSEC_CHROOT
51437+ help
51438+ If you say Y here, the current working directory of all newly-chrooted
51439+ applications will be set to the the root directory of the chroot.
51440+ The man page on chroot(2) states:
51441+ Note that this call does not change the current working
51442+ directory, so that `.' can be outside the tree rooted at
51443+ `/'. In particular, the super-user can escape from a
51444+ `chroot jail' by doing `mkdir foo; chroot foo; cd ..'.
51445+
51446+ It is recommended that you say Y here, since it's not known to break
51447+ any software. If the sysctl option is enabled, a sysctl option with
51448+ name "chroot_enforce_chdir" is created.
51449+
51450+config GRKERNSEC_CHROOT_CHMOD
51451+ bool "Deny (f)chmod +s"
51452+ default y if GRKERNSEC_CONFIG_AUTO
51453+ depends on GRKERNSEC_CHROOT
51454+ help
51455+ If you say Y here, processes inside a chroot will not be able to chmod
51456+ or fchmod files to make them have suid or sgid bits. This protects
51457+ against another published method of breaking a chroot. If the sysctl
51458+ option is enabled, a sysctl option with name "chroot_deny_chmod" is
51459+ created.
51460+
51461+config GRKERNSEC_CHROOT_FCHDIR
51462+ bool "Deny fchdir out of chroot"
51463+ default y if GRKERNSEC_CONFIG_AUTO
51464+ depends on GRKERNSEC_CHROOT
51465+ help
51466+ If you say Y here, a well-known method of breaking chroots by fchdir'ing
51467+ to a file descriptor of the chrooting process that points to a directory
51468+ outside the filesystem will be stopped. If the sysctl option
51469+ is enabled, a sysctl option with name "chroot_deny_fchdir" is created.
51470+
51471+config GRKERNSEC_CHROOT_MKNOD
51472+ bool "Deny mknod"
51473+ default y if GRKERNSEC_CONFIG_AUTO
51474+ depends on GRKERNSEC_CHROOT
51475+ help
51476+ If you say Y here, processes inside a chroot will not be allowed to
51477+ mknod. The problem with using mknod inside a chroot is that it
51478+ would allow an attacker to create a device entry that is the same
51479+ as one on the physical root of your system, which could range from
51480+ anything from the console device to a device for your harddrive (which
51481+ they could then use to wipe the drive or steal data). It is recommended
51482+ that you say Y here, unless you run into software incompatibilities.
51483+ If the sysctl option is enabled, a sysctl option with name
51484+ "chroot_deny_mknod" is created.
51485+
51486+config GRKERNSEC_CHROOT_SHMAT
51487+ bool "Deny shmat() out of chroot"
51488+ default y if GRKERNSEC_CONFIG_AUTO
51489+ depends on GRKERNSEC_CHROOT
51490+ help
51491+ If you say Y here, processes inside a chroot will not be able to attach
51492+ to shared memory segments that were created outside of the chroot jail.
51493+ It is recommended that you say Y here. If the sysctl option is enabled,
51494+ a sysctl option with name "chroot_deny_shmat" is created.
51495+
51496+config GRKERNSEC_CHROOT_UNIX
51497+ bool "Deny access to abstract AF_UNIX sockets out of chroot"
51498+ default y if GRKERNSEC_CONFIG_AUTO
51499+ depends on GRKERNSEC_CHROOT
51500+ help
51501+ If you say Y here, processes inside a chroot will not be able to
51502+ connect to abstract (meaning not belonging to a filesystem) Unix
51503+ domain sockets that were bound outside of a chroot. It is recommended
51504+ that you say Y here. If the sysctl option is enabled, a sysctl option
51505+ with name "chroot_deny_unix" is created.
51506+
51507+config GRKERNSEC_CHROOT_FINDTASK
51508+ bool "Protect outside processes"
51509+ default y if GRKERNSEC_CONFIG_AUTO
51510+ depends on GRKERNSEC_CHROOT
51511+ help
51512+ If you say Y here, processes inside a chroot will not be able to
51513+ kill, send signals with fcntl, ptrace, capget, getpgid, setpgid,
51514+ getsid, or view any process outside of the chroot. If the sysctl
51515+ option is enabled, a sysctl option with name "chroot_findtask" is
51516+ created.
51517+
51518+config GRKERNSEC_CHROOT_NICE
51519+ bool "Restrict priority changes"
51520+ default y if GRKERNSEC_CONFIG_AUTO
51521+ depends on GRKERNSEC_CHROOT
51522+ help
51523+ If you say Y here, processes inside a chroot will not be able to raise
51524+ the priority of processes in the chroot, or alter the priority of
51525+ processes outside the chroot. This provides more security than simply
51526+ removing CAP_SYS_NICE from the process' capability set. If the
51527+ sysctl option is enabled, a sysctl option with name "chroot_restrict_nice"
51528+ is created.
51529+
51530+config GRKERNSEC_CHROOT_SYSCTL
51531+ bool "Deny sysctl writes"
51532+ default y if GRKERNSEC_CONFIG_AUTO
51533+ depends on GRKERNSEC_CHROOT
51534+ help
51535+ If you say Y here, an attacker in a chroot will not be able to
51536+ write to sysctl entries, either by sysctl(2) or through a /proc
51537+ interface. It is strongly recommended that you say Y here. If the
51538+ sysctl option is enabled, a sysctl option with name
51539+ "chroot_deny_sysctl" is created.
51540+
51541+config GRKERNSEC_CHROOT_CAPS
51542+ bool "Capability restrictions"
51543+ default y if GRKERNSEC_CONFIG_AUTO
51544+ depends on GRKERNSEC_CHROOT
51545+ help
51546+ If you say Y here, the capabilities on all processes within a
51547+ chroot jail will be lowered to stop module insertion, raw i/o,
51548+ system and net admin tasks, rebooting the system, modifying immutable
51549+ files, modifying IPC owned by another, and changing the system time.
51550+ This is left an option because it can break some apps. Disable this
51551+ if your chrooted apps are having problems performing those kinds of
51552+ tasks. If the sysctl option is enabled, a sysctl option with
51553+ name "chroot_caps" is created.
51554+
51555+endmenu
51556+menu "Kernel Auditing"
51557+depends on GRKERNSEC
51558+
51559+config GRKERNSEC_AUDIT_GROUP
51560+ bool "Single group for auditing"
51561+ help
51562+ If you say Y here, the exec, chdir, and (un)mount logging features
51563+ will only operate on a group you specify. This option is recommended
51564+ if you only want to watch certain users instead of having a large
51565+ amount of logs from the entire system. If the sysctl option is enabled,
51566+ a sysctl option with name "audit_group" is created.
51567+
51568+config GRKERNSEC_AUDIT_GID
51569+ int "GID for auditing"
51570+ depends on GRKERNSEC_AUDIT_GROUP
51571+ default 1007
51572+
51573+config GRKERNSEC_EXECLOG
51574+ bool "Exec logging"
51575+ help
51576+ If you say Y here, all execve() calls will be logged (since the
51577+ other exec*() calls are frontends to execve(), all execution
51578+ will be logged). Useful for shell-servers that like to keep track
51579+ of their users. If the sysctl option is enabled, a sysctl option with
51580+ name "exec_logging" is created.
51581+ WARNING: This option when enabled will produce a LOT of logs, especially
51582+ on an active system.
51583+
51584+config GRKERNSEC_RESLOG
51585+ bool "Resource logging"
51586+ default y if GRKERNSEC_CONFIG_AUTO
51587+ help
51588+ If you say Y here, all attempts to overstep resource limits will
51589+ be logged with the resource name, the requested size, and the current
51590+ limit. It is highly recommended that you say Y here. If the sysctl
51591+ option is enabled, a sysctl option with name "resource_logging" is
51592+ created. If the RBAC system is enabled, the sysctl value is ignored.
51593+
51594+config GRKERNSEC_CHROOT_EXECLOG
51595+ bool "Log execs within chroot"
51596+ help
51597+ If you say Y here, all executions inside a chroot jail will be logged
51598+ to syslog. This can cause a large amount of logs if certain
51599+ applications (eg. djb's daemontools) are installed on the system, and
51600+ is therefore left as an option. If the sysctl option is enabled, a
51601+ sysctl option with name "chroot_execlog" is created.
51602+
51603+config GRKERNSEC_AUDIT_PTRACE
51604+ bool "Ptrace logging"
51605+ help
51606+ If you say Y here, all attempts to attach to a process via ptrace
51607+ will be logged. If the sysctl option is enabled, a sysctl option
51608+ with name "audit_ptrace" is created.
51609+
51610+config GRKERNSEC_AUDIT_CHDIR
51611+ bool "Chdir logging"
51612+ help
51613+ If you say Y here, all chdir() calls will be logged. If the sysctl
51614+ option is enabled, a sysctl option with name "audit_chdir" is created.
51615+
51616+config GRKERNSEC_AUDIT_MOUNT
51617+ bool "(Un)Mount logging"
51618+ help
51619+ If you say Y here, all mounts and unmounts will be logged. If the
51620+ sysctl option is enabled, a sysctl option with name "audit_mount" is
51621+ created.
51622+
51623+config GRKERNSEC_SIGNAL
51624+ bool "Signal logging"
51625+ default y if GRKERNSEC_CONFIG_AUTO
51626+ help
51627+ If you say Y here, certain important signals will be logged, such as
51628+ SIGSEGV, which will as a result inform you of when a error in a program
51629+ occurred, which in some cases could mean a possible exploit attempt.
51630+ If the sysctl option is enabled, a sysctl option with name
51631+ "signal_logging" is created.
51632+
51633+config GRKERNSEC_FORKFAIL
51634+ bool "Fork failure logging"
51635+ help
51636+ If you say Y here, all failed fork() attempts will be logged.
51637+ This could suggest a fork bomb, or someone attempting to overstep
51638+ their process limit. If the sysctl option is enabled, a sysctl option
51639+ with name "forkfail_logging" is created.
51640+
51641+config GRKERNSEC_TIME
51642+ bool "Time change logging"
51643+ default y if GRKERNSEC_CONFIG_AUTO
51644+ help
51645+ If you say Y here, any changes of the system clock will be logged.
51646+ If the sysctl option is enabled, a sysctl option with name
51647+ "timechange_logging" is created.
51648+
51649+config GRKERNSEC_PROC_IPADDR
51650+ bool "/proc/<pid>/ipaddr support"
51651+ default y if GRKERNSEC_CONFIG_AUTO
51652+ help
51653+ If you say Y here, a new entry will be added to each /proc/<pid>
51654+ directory that contains the IP address of the person using the task.
51655+ The IP is carried across local TCP and AF_UNIX stream sockets.
51656+ This information can be useful for IDS/IPSes to perform remote response
51657+ to a local attack. The entry is readable by only the owner of the
51658+ process (and root if he has CAP_DAC_OVERRIDE, which can be removed via
51659+ the RBAC system), and thus does not create privacy concerns.
51660+
51661+config GRKERNSEC_RWXMAP_LOG
51662+ bool 'Denied RWX mmap/mprotect logging'
51663+ default y if GRKERNSEC_CONFIG_AUTO
51664+ depends on PAX_MPROTECT && !PAX_EMUPLT && !PAX_EMUSIGRT
51665+ help
51666+ If you say Y here, calls to mmap() and mprotect() with explicit
51667+ usage of PROT_WRITE and PROT_EXEC together will be logged when
51668+ denied by the PAX_MPROTECT feature. If the sysctl option is
51669+ enabled, a sysctl option with name "rwxmap_logging" is created.
51670+
51671+config GRKERNSEC_AUDIT_TEXTREL
51672+ bool 'ELF text relocations logging (READ HELP)'
51673+ depends on PAX_MPROTECT
51674+ help
51675+ If you say Y here, text relocations will be logged with the filename
51676+ of the offending library or binary. The purpose of the feature is
51677+ to help Linux distribution developers get rid of libraries and
51678+ binaries that need text relocations which hinder the future progress
51679+ of PaX. Only Linux distribution developers should say Y here, and
51680+ never on a production machine, as this option creates an information
51681+ leak that could aid an attacker in defeating the randomization of
51682+ a single memory region. If the sysctl option is enabled, a sysctl
51683+ option with name "audit_textrel" is created.
51684+
51685+endmenu
51686+
51687+menu "Executable Protections"
51688+depends on GRKERNSEC
51689+
51690+config GRKERNSEC_DMESG
51691+ bool "Dmesg(8) restriction"
51692+ default y if GRKERNSEC_CONFIG_AUTO
51693+ help
51694+ If you say Y here, non-root users will not be able to use dmesg(8)
51695+ to view up to the last 4kb of messages in the kernel's log buffer.
51696+ The kernel's log buffer often contains kernel addresses and other
51697+ identifying information useful to an attacker in fingerprinting a
51698+ system for a targeted exploit.
51699+ If the sysctl option is enabled, a sysctl option with name "dmesg" is
51700+ created.
51701+
51702+config GRKERNSEC_HARDEN_PTRACE
51703+ bool "Deter ptrace-based process snooping"
51704+ default y if GRKERNSEC_CONFIG_AUTO
51705+ help
51706+ If you say Y here, TTY sniffers and other malicious monitoring
51707+ programs implemented through ptrace will be defeated. If you
51708+ have been using the RBAC system, this option has already been
51709+ enabled for several years for all users, with the ability to make
51710+ fine-grained exceptions.
51711+
51712+ This option only affects the ability of non-root users to ptrace
51713+ processes that are not a descendent of the ptracing process.
51714+ This means that strace ./binary and gdb ./binary will still work,
51715+ but attaching to arbitrary processes will not. If the sysctl
51716+ option is enabled, a sysctl option with name "harden_ptrace" is
51717+ created.
51718+
51719+config GRKERNSEC_PTRACE_READEXEC
51720+ bool "Require read access to ptrace sensitive binaries"
51721+ default y if GRKERNSEC_CONFIG_AUTO
51722+ help
51723+ If you say Y here, unprivileged users will not be able to ptrace unreadable
51724+ binaries. This option is useful in environments that
51725+ remove the read bits (e.g. file mode 4711) from suid binaries to
51726+ prevent infoleaking of their contents. This option adds
51727+ consistency to the use of that file mode, as the binary could normally
51728+ be read out when run without privileges while ptracing.
51729+
51730+ If the sysctl option is enabled, a sysctl option with name "ptrace_readexec"
51731+ is created.
51732+
51733+config GRKERNSEC_SETXID
51734+ bool "Enforce consistent multithreaded privileges"
51735+ default y if GRKERNSEC_CONFIG_AUTO
51736+ depends on (X86 || SPARC64 || PPC || ARM || MIPS)
51737+ help
51738+ If you say Y here, a change from a root uid to a non-root uid
51739+ in a multithreaded application will cause the resulting uids,
51740+ gids, supplementary groups, and capabilities in that thread
51741+ to be propagated to the other threads of the process. In most
51742+ cases this is unnecessary, as glibc will emulate this behavior
51743+ on behalf of the application. Other libcs do not act in the
51744+ same way, allowing the other threads of the process to continue
51745+ running with root privileges. If the sysctl option is enabled,
51746+ a sysctl option with name "consistent_setxid" is created.
51747+
51748+config GRKERNSEC_TPE
51749+ bool "Trusted Path Execution (TPE)"
51750+ default y if GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER
51751+ help
51752+ If you say Y here, you will be able to choose a gid to add to the
51753+ supplementary groups of users you want to mark as "untrusted."
51754+ These users will not be able to execute any files that are not in
51755+ root-owned directories writable only by root. If the sysctl option
51756+ is enabled, a sysctl option with name "tpe" is created.
51757+
51758+config GRKERNSEC_TPE_ALL
51759+ bool "Partially restrict all non-root users"
51760+ depends on GRKERNSEC_TPE
51761+ help
51762+ If you say Y here, all non-root users will be covered under
51763+ a weaker TPE restriction. This is separate from, and in addition to,
51764+ the main TPE options that you have selected elsewhere. Thus, if a
51765+ "trusted" GID is chosen, this restriction applies to even that GID.
51766+ Under this restriction, all non-root users will only be allowed to
51767+ execute files in directories they own that are not group or
51768+ world-writable, or in directories owned by root and writable only by
51769+ root. If the sysctl option is enabled, a sysctl option with name
51770+ "tpe_restrict_all" is created.
51771+
51772+config GRKERNSEC_TPE_INVERT
51773+ bool "Invert GID option"
51774+ depends on GRKERNSEC_TPE
51775+ help
51776+ If you say Y here, the group you specify in the TPE configuration will
51777+ decide what group TPE restrictions will be *disabled* for. This
51778+ option is useful if you want TPE restrictions to be applied to most
51779+ users on the system. If the sysctl option is enabled, a sysctl option
51780+ with name "tpe_invert" is created. Unlike other sysctl options, this
51781+ entry will default to on for backward-compatibility.
51782+
51783+config GRKERNSEC_TPE_GID
51784+ int
51785+ default GRKERNSEC_TPE_UNTRUSTED_GID if (GRKERNSEC_TPE && !GRKERNSEC_TPE_INVERT)
51786+ default GRKERNSEC_TPE_TRUSTED_GID if (GRKERNSEC_TPE && GRKERNSEC_TPE_INVERT)
51787+
51788+config GRKERNSEC_TPE_UNTRUSTED_GID
51789+ int "GID for TPE-untrusted users"
51790+ depends on GRKERNSEC_TPE && !GRKERNSEC_TPE_INVERT
51791+ default 1005
51792+ help
51793+ Setting this GID determines what group TPE restrictions will be
51794+ *enabled* for. If the sysctl option is enabled, a sysctl option
51795+ with name "tpe_gid" is created.
51796+
51797+config GRKERNSEC_TPE_TRUSTED_GID
51798+ int "GID for TPE-trusted users"
51799+ depends on GRKERNSEC_TPE && GRKERNSEC_TPE_INVERT
51800+ default 1005
51801+ help
51802+ Setting this GID determines what group TPE restrictions will be
51803+ *disabled* for. If the sysctl option is enabled, a sysctl option
51804+ with name "tpe_gid" is created.
51805+
51806+endmenu
51807+menu "Network Protections"
51808+depends on GRKERNSEC
51809+
51810+config GRKERNSEC_RANDNET
51811+ bool "Larger entropy pools"
51812+ default y if GRKERNSEC_CONFIG_AUTO
51813+ help
51814+ If you say Y here, the entropy pools used for many features of Linux
51815+ and grsecurity will be doubled in size. Since several grsecurity
51816+ features use additional randomness, it is recommended that you say Y
51817+ here. Saying Y here has a similar effect as modifying
51818+ /proc/sys/kernel/random/poolsize.
51819+
51820+config GRKERNSEC_BLACKHOLE
51821+ bool "TCP/UDP blackhole and LAST_ACK DoS prevention"
51822+ default y if GRKERNSEC_CONFIG_AUTO
51823+ depends on NET
51824+ help
51825+ If you say Y here, neither TCP resets nor ICMP
51826+ destination-unreachable packets will be sent in response to packets
51827+ sent to ports for which no associated listening process exists.
51828+ This feature supports both IPV4 and IPV6 and exempts the
51829+ loopback interface from blackholing. Enabling this feature
51830+ makes a host more resilient to DoS attacks and reduces network
51831+ visibility against scanners.
51832+
51833+ The blackhole feature as-implemented is equivalent to the FreeBSD
51834+ blackhole feature, as it prevents RST responses to all packets, not
51835+ just SYNs. Under most application behavior this causes no
51836+ problems, but applications (like haproxy) may not close certain
51837+ connections in a way that cleanly terminates them on the remote
51838+ end, leaving the remote host in LAST_ACK state. Because of this
51839+ side-effect and to prevent intentional LAST_ACK DoSes, this
51840+ feature also adds automatic mitigation against such attacks.
51841+ The mitigation drastically reduces the amount of time a socket
51842+ can spend in LAST_ACK state. If you're using haproxy and not
51843+ all servers it connects to have this option enabled, consider
51844+ disabling this feature on the haproxy host.
51845+
51846+ If the sysctl option is enabled, two sysctl options with names
51847+ "ip_blackhole" and "lastack_retries" will be created.
51848+ While "ip_blackhole" takes the standard zero/non-zero on/off
51849+ toggle, "lastack_retries" uses the same kinds of values as
51850+ "tcp_retries1" and "tcp_retries2". The default value of 4
51851+ prevents a socket from lasting more than 45 seconds in LAST_ACK
51852+ state.
51853+
51854+config GRKERNSEC_SOCKET
51855+ bool "Socket restrictions"
51856+ depends on NET
51857+ help
51858+ If you say Y here, you will be able to choose from several options.
51859+ If you assign a GID on your system and add it to the supplementary
51860+ groups of users you want to restrict socket access to, this patch
51861+ will perform up to three things, based on the option(s) you choose.
51862+
51863+config GRKERNSEC_SOCKET_ALL
51864+ bool "Deny any sockets to group"
51865+ depends on GRKERNSEC_SOCKET
51866+ help
51867+ If you say Y here, you will be able to choose a GID of whose users will
51868+ be unable to connect to other hosts from your machine or run server
51869+ applications from your machine. If the sysctl option is enabled, a
51870+ sysctl option with name "socket_all" is created.
51871+
51872+config GRKERNSEC_SOCKET_ALL_GID
51873+ int "GID to deny all sockets for"
51874+ depends on GRKERNSEC_SOCKET_ALL
51875+ default 1004
51876+ help
51877+ Here you can choose the GID to disable socket access for. Remember to
51878+ add the users you want socket access disabled for to the GID
51879+ specified here. If the sysctl option is enabled, a sysctl option
51880+ with name "socket_all_gid" is created.
51881+
51882+config GRKERNSEC_SOCKET_CLIENT
51883+ bool "Deny client sockets to group"
51884+ depends on GRKERNSEC_SOCKET
51885+ help
51886+ If you say Y here, you will be able to choose a GID of whose users will
51887+ be unable to connect to other hosts from your machine, but will be
51888+ able to run servers. If this option is enabled, all users in the group
51889+ you specify will have to use passive mode when initiating ftp transfers
51890+ from the shell on your machine. If the sysctl option is enabled, a
51891+ sysctl option with name "socket_client" is created.
51892+
51893+config GRKERNSEC_SOCKET_CLIENT_GID
51894+ int "GID to deny client sockets for"
51895+ depends on GRKERNSEC_SOCKET_CLIENT
51896+ default 1003
51897+ help
51898+ Here you can choose the GID to disable client socket access for.
51899+ Remember to add the users you want client socket access disabled for to
51900+ the GID specified here. If the sysctl option is enabled, a sysctl
51901+ option with name "socket_client_gid" is created.
51902+
51903+config GRKERNSEC_SOCKET_SERVER
51904+ bool "Deny server sockets to group"
51905+ depends on GRKERNSEC_SOCKET
51906+ help
51907+ If you say Y here, you will be able to choose a GID of whose users will
51908+ be unable to run server applications from your machine. If the sysctl
51909+ option is enabled, a sysctl option with name "socket_server" is created.
51910+
51911+config GRKERNSEC_SOCKET_SERVER_GID
51912+ int "GID to deny server sockets for"
51913+ depends on GRKERNSEC_SOCKET_SERVER
51914+ default 1002
51915+ help
51916+ Here you can choose the GID to disable server socket access for.
51917+ Remember to add the users you want server socket access disabled for to
51918+ the GID specified here. If the sysctl option is enabled, a sysctl
51919+ option with name "socket_server_gid" is created.
51920+
51921+endmenu
51922+menu "Sysctl Support"
51923+depends on GRKERNSEC && SYSCTL
51924+
51925+config GRKERNSEC_SYSCTL
51926+ bool "Sysctl support"
51927+ default y if GRKERNSEC_CONFIG_AUTO
51928+ help
51929+ If you say Y here, you will be able to change the options that
51930+ grsecurity runs with at bootup, without having to recompile your
51931+ kernel. You can echo values to files in /proc/sys/kernel/grsecurity
51932+ to enable (1) or disable (0) various features. All the sysctl entries
51933+ are mutable until the "grsec_lock" entry is set to a non-zero value.
51934+ All features enabled in the kernel configuration are disabled at boot
51935+ if you do not say Y to the "Turn on features by default" option.
51936+ All options should be set at startup, and the grsec_lock entry should
51937+ be set to a non-zero value after all the options are set.
51938+ *THIS IS EXTREMELY IMPORTANT*
51939+
51940+config GRKERNSEC_SYSCTL_DISTRO
51941+ bool "Extra sysctl support for distro makers (READ HELP)"
51942+ depends on GRKERNSEC_SYSCTL && GRKERNSEC_IO
51943+ help
51944+ If you say Y here, additional sysctl options will be created
51945+ for features that affect processes running as root. Therefore,
51946+ it is critical when using this option that the grsec_lock entry be
51947+ enabled after boot. Only distros with prebuilt kernel packages
51948+ with this option enabled that can ensure grsec_lock is enabled
51949+ after boot should use this option.
51950+ *Failure to set grsec_lock after boot makes all grsec features
51951+ this option covers useless*
51952+
51953+ Currently this option creates the following sysctl entries:
51954+ "Disable Privileged I/O": "disable_priv_io"
51955+
51956+config GRKERNSEC_SYSCTL_ON
51957+ bool "Turn on features by default"
51958+ default y if GRKERNSEC_CONFIG_AUTO
51959+ depends on GRKERNSEC_SYSCTL
51960+ help
51961+ If you say Y here, instead of having all features enabled in the
51962+ kernel configuration disabled at boot time, the features will be
51963+ enabled at boot time. It is recommended you say Y here unless
51964+ there is some reason you would want all sysctl-tunable features to
51965+ be disabled by default. As mentioned elsewhere, it is important
51966+ to enable the grsec_lock entry once you have finished modifying
51967+ the sysctl entries.
51968+
51969+endmenu
51970+menu "Logging Options"
51971+depends on GRKERNSEC
51972+
51973+config GRKERNSEC_FLOODTIME
51974+ int "Seconds in between log messages (minimum)"
51975+ default 10
51976+ help
51977+ This option allows you to enforce the number of seconds between
51978+ grsecurity log messages. The default should be suitable for most
51979+ people, however, if you choose to change it, choose a value small enough
51980+ to allow informative logs to be produced, but large enough to
51981+ prevent flooding.
51982+
51983+config GRKERNSEC_FLOODBURST
51984+ int "Number of messages in a burst (maximum)"
51985+ default 6
51986+ help
51987+ This option allows you to choose the maximum number of messages allowed
51988+ within the flood time interval you chose in a separate option. The
51989+ default should be suitable for most people, however if you find that
51990+ many of your logs are being interpreted as flooding, you may want to
51991+ raise this value.
51992+
51993+endmenu
51994diff --git a/grsecurity/Makefile b/grsecurity/Makefile
51995new file mode 100644
51996index 0000000..1b9afa9
51997--- /dev/null
51998+++ b/grsecurity/Makefile
51999@@ -0,0 +1,38 @@
52000+# grsecurity's ACL system was originally written in 2001 by Michael Dalton
52001+# during 2001-2009 it has been completely redesigned by Brad Spengler
52002+# into an RBAC system
52003+#
52004+# All code in this directory and various hooks inserted throughout the kernel
52005+# are copyright Brad Spengler - Open Source Security, Inc., and released
52006+# under the GPL v2 or higher
52007+
52008+KBUILD_CFLAGS += -Werror
52009+
52010+obj-y = grsec_chdir.o grsec_chroot.o grsec_exec.o grsec_fifo.o grsec_fork.o \
52011+ grsec_mount.o grsec_sig.o grsec_sysctl.o \
52012+ grsec_time.o grsec_tpe.o grsec_link.o grsec_pax.o grsec_ptrace.o
52013+
52014+obj-$(CONFIG_GRKERNSEC) += grsec_init.o grsum.o gracl.o gracl_segv.o \
52015+ gracl_cap.o gracl_alloc.o gracl_shm.o grsec_mem.o gracl_fs.o \
52016+ gracl_learn.o grsec_log.o
52017+obj-$(CONFIG_GRKERNSEC_RESLOG) += gracl_res.o
52018+
52019+ifdef CONFIG_NET
52020+obj-y += grsec_sock.o
52021+obj-$(CONFIG_GRKERNSEC) += gracl_ip.o
52022+endif
52023+
52024+ifndef CONFIG_GRKERNSEC
52025+obj-y += grsec_disabled.o
52026+endif
52027+
52028+ifdef CONFIG_GRKERNSEC_HIDESYM
52029+extra-y := grsec_hidesym.o
52030+$(obj)/grsec_hidesym.o:
52031+ @-chmod -f 500 /boot
52032+ @-chmod -f 500 /lib/modules
52033+ @-chmod -f 500 /lib64/modules
52034+ @-chmod -f 500 /lib32/modules
52035+ @-chmod -f 700 .
52036+ @echo ' grsec: protected kernel image paths'
52037+endif
52038diff --git a/grsecurity/gracl.c b/grsecurity/gracl.c
52039new file mode 100644
52040index 0000000..4428c82
52041--- /dev/null
52042+++ b/grsecurity/gracl.c
52043@@ -0,0 +1,4056 @@
52044+#include <linux/kernel.h>
52045+#include <linux/module.h>
52046+#include <linux/sched.h>
52047+#include <linux/mm.h>
52048+#include <linux/file.h>
52049+#include <linux/fs.h>
52050+#include <linux/namei.h>
52051+#include <linux/mount.h>
52052+#include <linux/tty.h>
52053+#include <linux/proc_fs.h>
52054+#include <linux/lglock.h>
52055+#include <linux/slab.h>
52056+#include <linux/vmalloc.h>
52057+#include <linux/types.h>
52058+#include <linux/sysctl.h>
52059+#include <linux/netdevice.h>
52060+#include <linux/ptrace.h>
52061+#include <linux/gracl.h>
52062+#include <linux/gralloc.h>
52063+#include <linux/security.h>
52064+#include <linux/grinternal.h>
52065+#include <linux/pid_namespace.h>
52066+#include <linux/stop_machine.h>
52067+#include <linux/fdtable.h>
52068+#include <linux/percpu.h>
52069+#include <linux/lglock.h>
52070+#include "../fs/mount.h"
52071+
52072+#include <asm/uaccess.h>
52073+#include <asm/errno.h>
52074+#include <asm/mman.h>
52075+
52076+extern struct lglock vfsmount_lock;
52077+
52078+static struct acl_role_db acl_role_set;
52079+static struct name_db name_set;
52080+static struct inodev_db inodev_set;
52081+
52082+/* for keeping track of userspace pointers used for subjects, so we
52083+ can share references in the kernel as well
52084+*/
52085+
52086+static struct path real_root;
52087+
52088+static struct acl_subj_map_db subj_map_set;
52089+
52090+static struct acl_role_label *default_role;
52091+
52092+static struct acl_role_label *role_list;
52093+
52094+static u16 acl_sp_role_value;
52095+
52096+extern char *gr_shared_page[4];
52097+static DEFINE_MUTEX(gr_dev_mutex);
52098+DEFINE_RWLOCK(gr_inode_lock);
52099+
52100+struct gr_arg *gr_usermode;
52101+
52102+static unsigned int gr_status __read_only = GR_STATUS_INIT;
52103+
52104+extern int chkpw(struct gr_arg *entry, unsigned char *salt, unsigned char *sum);
52105+extern void gr_clear_learn_entries(void);
52106+
52107+#ifdef CONFIG_GRKERNSEC_RESLOG
52108+extern void gr_log_resource(const struct task_struct *task,
52109+ const int res, const unsigned long wanted, const int gt);
52110+#endif
52111+
52112+unsigned char *gr_system_salt;
52113+unsigned char *gr_system_sum;
52114+
52115+static struct sprole_pw **acl_special_roles = NULL;
52116+static __u16 num_sprole_pws = 0;
52117+
52118+static struct acl_role_label *kernel_role = NULL;
52119+
52120+static unsigned int gr_auth_attempts = 0;
52121+static unsigned long gr_auth_expires = 0UL;
52122+
52123+#ifdef CONFIG_NET
52124+extern struct vfsmount *sock_mnt;
52125+#endif
52126+
52127+extern struct vfsmount *pipe_mnt;
52128+extern struct vfsmount *shm_mnt;
52129+#ifdef CONFIG_HUGETLBFS
52130+extern struct vfsmount *hugetlbfs_vfsmount;
52131+#endif
52132+
52133+static struct acl_object_label *fakefs_obj_rw;
52134+static struct acl_object_label *fakefs_obj_rwx;
52135+
52136+extern int gr_init_uidset(void);
52137+extern void gr_free_uidset(void);
52138+extern void gr_remove_uid(uid_t uid);
52139+extern int gr_find_uid(uid_t uid);
52140+
52141+__inline__ int
52142+gr_acl_is_enabled(void)
52143+{
52144+ return (gr_status & GR_READY);
52145+}
52146+
52147+#ifdef CONFIG_BTRFS_FS
52148+extern dev_t get_btrfs_dev_from_inode(struct inode *inode);
52149+extern int btrfs_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat);
52150+#endif
52151+
52152+static inline dev_t __get_dev(const struct dentry *dentry)
52153+{
52154+#ifdef CONFIG_BTRFS_FS
52155+ if (dentry->d_inode->i_op && dentry->d_inode->i_op->getattr == &btrfs_getattr)
52156+ return get_btrfs_dev_from_inode(dentry->d_inode);
52157+ else
52158+#endif
52159+ return dentry->d_inode->i_sb->s_dev;
52160+}
52161+
52162+dev_t gr_get_dev_from_dentry(struct dentry *dentry)
52163+{
52164+ return __get_dev(dentry);
52165+}
52166+
52167+static char gr_task_roletype_to_char(struct task_struct *task)
52168+{
52169+ switch (task->role->roletype &
52170+ (GR_ROLE_DEFAULT | GR_ROLE_USER | GR_ROLE_GROUP |
52171+ GR_ROLE_SPECIAL)) {
52172+ case GR_ROLE_DEFAULT:
52173+ return 'D';
52174+ case GR_ROLE_USER:
52175+ return 'U';
52176+ case GR_ROLE_GROUP:
52177+ return 'G';
52178+ case GR_ROLE_SPECIAL:
52179+ return 'S';
52180+ }
52181+
52182+ return 'X';
52183+}
52184+
52185+char gr_roletype_to_char(void)
52186+{
52187+ return gr_task_roletype_to_char(current);
52188+}
52189+
52190+__inline__ int
52191+gr_acl_tpe_check(void)
52192+{
52193+ if (unlikely(!(gr_status & GR_READY)))
52194+ return 0;
52195+ if (current->role->roletype & GR_ROLE_TPE)
52196+ return 1;
52197+ else
52198+ return 0;
52199+}
52200+
52201+int
52202+gr_handle_rawio(const struct inode *inode)
52203+{
52204+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
52205+ if (inode && S_ISBLK(inode->i_mode) &&
52206+ grsec_enable_chroot_caps && proc_is_chrooted(current) &&
52207+ !capable(CAP_SYS_RAWIO))
52208+ return 1;
52209+#endif
52210+ return 0;
52211+}
52212+
52213+static int
52214+gr_streq(const char *a, const char *b, const unsigned int lena, const unsigned int lenb)
52215+{
52216+ if (likely(lena != lenb))
52217+ return 0;
52218+
52219+ return !memcmp(a, b, lena);
52220+}
52221+
52222+static int prepend(char **buffer, int *buflen, const char *str, int namelen)
52223+{
52224+ *buflen -= namelen;
52225+ if (*buflen < 0)
52226+ return -ENAMETOOLONG;
52227+ *buffer -= namelen;
52228+ memcpy(*buffer, str, namelen);
52229+ return 0;
52230+}
52231+
52232+static int prepend_name(char **buffer, int *buflen, struct qstr *name)
52233+{
52234+ return prepend(buffer, buflen, name->name, name->len);
52235+}
52236+
52237+static int prepend_path(const struct path *path, struct path *root,
52238+ char **buffer, int *buflen)
52239+{
52240+ struct dentry *dentry = path->dentry;
52241+ struct vfsmount *vfsmnt = path->mnt;
52242+ struct mount *mnt = real_mount(vfsmnt);
52243+ bool slash = false;
52244+ int error = 0;
52245+
52246+ while (dentry != root->dentry || vfsmnt != root->mnt) {
52247+ struct dentry * parent;
52248+
52249+ if (dentry == vfsmnt->mnt_root || IS_ROOT(dentry)) {
52250+ /* Global root? */
52251+ if (!mnt_has_parent(mnt)) {
52252+ goto out;
52253+ }
52254+ dentry = mnt->mnt_mountpoint;
52255+ mnt = mnt->mnt_parent;
52256+ vfsmnt = &mnt->mnt;
52257+ continue;
52258+ }
52259+ parent = dentry->d_parent;
52260+ prefetch(parent);
52261+ spin_lock(&dentry->d_lock);
52262+ error = prepend_name(buffer, buflen, &dentry->d_name);
52263+ spin_unlock(&dentry->d_lock);
52264+ if (!error)
52265+ error = prepend(buffer, buflen, "/", 1);
52266+ if (error)
52267+ break;
52268+
52269+ slash = true;
52270+ dentry = parent;
52271+ }
52272+
52273+out:
52274+ if (!error && !slash)
52275+ error = prepend(buffer, buflen, "/", 1);
52276+
52277+ return error;
52278+}
52279+
52280+/* this must be called with vfsmount_lock and rename_lock held */
52281+
52282+static char *__our_d_path(const struct path *path, struct path *root,
52283+ char *buf, int buflen)
52284+{
52285+ char *res = buf + buflen;
52286+ int error;
52287+
52288+ prepend(&res, &buflen, "\0", 1);
52289+ error = prepend_path(path, root, &res, &buflen);
52290+ if (error)
52291+ return ERR_PTR(error);
52292+
52293+ return res;
52294+}
52295+
52296+static char *
52297+gen_full_path(struct path *path, struct path *root, char *buf, int buflen)
52298+{
52299+ char *retval;
52300+
52301+ retval = __our_d_path(path, root, buf, buflen);
52302+ if (unlikely(IS_ERR(retval)))
52303+ retval = strcpy(buf, "<path too long>");
52304+ else if (unlikely(retval[1] == '/' && retval[2] == '\0'))
52305+ retval[1] = '\0';
52306+
52307+ return retval;
52308+}
52309+
52310+static char *
52311+__d_real_path(const struct dentry *dentry, const struct vfsmount *vfsmnt,
52312+ char *buf, int buflen)
52313+{
52314+ struct path path;
52315+ char *res;
52316+
52317+ path.dentry = (struct dentry *)dentry;
52318+ path.mnt = (struct vfsmount *)vfsmnt;
52319+
52320+ /* we can use real_root.dentry, real_root.mnt, because this is only called
52321+ by the RBAC system */
52322+ res = gen_full_path(&path, &real_root, buf, buflen);
52323+
52324+ return res;
52325+}
52326+
52327+static char *
52328+d_real_path(const struct dentry *dentry, const struct vfsmount *vfsmnt,
52329+ char *buf, int buflen)
52330+{
52331+ char *res;
52332+ struct path path;
52333+ struct path root;
52334+ struct task_struct *reaper = init_pid_ns.child_reaper;
52335+
52336+ path.dentry = (struct dentry *)dentry;
52337+ path.mnt = (struct vfsmount *)vfsmnt;
52338+
52339+ /* we can't use real_root.dentry, real_root.mnt, because they belong only to the RBAC system */
52340+ get_fs_root(reaper->fs, &root);
52341+
52342+ write_seqlock(&rename_lock);
52343+ br_read_lock(&vfsmount_lock);
52344+ res = gen_full_path(&path, &root, buf, buflen);
52345+ br_read_unlock(&vfsmount_lock);
52346+ write_sequnlock(&rename_lock);
52347+
52348+ path_put(&root);
52349+ return res;
52350+}
52351+
52352+static char *
52353+gr_to_filename_rbac(const struct dentry *dentry, const struct vfsmount *mnt)
52354+{
52355+ char *ret;
52356+ write_seqlock(&rename_lock);
52357+ br_read_lock(&vfsmount_lock);
52358+ ret = __d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0],smp_processor_id()),
52359+ PAGE_SIZE);
52360+ br_read_unlock(&vfsmount_lock);
52361+ write_sequnlock(&rename_lock);
52362+ return ret;
52363+}
52364+
52365+static char *
52366+gr_to_proc_filename_rbac(const struct dentry *dentry, const struct vfsmount *mnt)
52367+{
52368+ char *ret;
52369+ char *buf;
52370+ int buflen;
52371+
52372+ write_seqlock(&rename_lock);
52373+ br_read_lock(&vfsmount_lock);
52374+ buf = per_cpu_ptr(gr_shared_page[0], smp_processor_id());
52375+ ret = __d_real_path(dentry, mnt, buf, PAGE_SIZE - 6);
52376+ buflen = (int)(ret - buf);
52377+ if (buflen >= 5)
52378+ prepend(&ret, &buflen, "/proc", 5);
52379+ else
52380+ ret = strcpy(buf, "<path too long>");
52381+ br_read_unlock(&vfsmount_lock);
52382+ write_sequnlock(&rename_lock);
52383+ return ret;
52384+}
52385+
52386+char *
52387+gr_to_filename_nolock(const struct dentry *dentry, const struct vfsmount *mnt)
52388+{
52389+ return __d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0],smp_processor_id()),
52390+ PAGE_SIZE);
52391+}
52392+
52393+char *
52394+gr_to_filename(const struct dentry *dentry, const struct vfsmount *mnt)
52395+{
52396+ return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0], smp_processor_id()),
52397+ PAGE_SIZE);
52398+}
52399+
52400+char *
52401+gr_to_filename1(const struct dentry *dentry, const struct vfsmount *mnt)
52402+{
52403+ return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[1], smp_processor_id()),
52404+ PAGE_SIZE);
52405+}
52406+
52407+char *
52408+gr_to_filename2(const struct dentry *dentry, const struct vfsmount *mnt)
52409+{
52410+ return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[2], smp_processor_id()),
52411+ PAGE_SIZE);
52412+}
52413+
52414+char *
52415+gr_to_filename3(const struct dentry *dentry, const struct vfsmount *mnt)
52416+{
52417+ return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[3], smp_processor_id()),
52418+ PAGE_SIZE);
52419+}
52420+
52421+__inline__ __u32
52422+to_gr_audit(const __u32 reqmode)
52423+{
52424+ /* masks off auditable permission flags, then shifts them to create
52425+ auditing flags, and adds the special case of append auditing if
52426+ we're requesting write */
52427+ return (((reqmode & ~GR_AUDITS) << 10) | ((reqmode & GR_WRITE) ? GR_AUDIT_APPEND : 0));
52428+}
52429+
52430+struct acl_subject_label *
52431+lookup_subject_map(const struct acl_subject_label *userp)
52432+{
52433+ unsigned int index = shash(userp, subj_map_set.s_size);
52434+ struct subject_map *match;
52435+
52436+ match = subj_map_set.s_hash[index];
52437+
52438+ while (match && match->user != userp)
52439+ match = match->next;
52440+
52441+ if (match != NULL)
52442+ return match->kernel;
52443+ else
52444+ return NULL;
52445+}
52446+
52447+static void
52448+insert_subj_map_entry(struct subject_map *subjmap)
52449+{
52450+ unsigned int index = shash(subjmap->user, subj_map_set.s_size);
52451+ struct subject_map **curr;
52452+
52453+ subjmap->prev = NULL;
52454+
52455+ curr = &subj_map_set.s_hash[index];
52456+ if (*curr != NULL)
52457+ (*curr)->prev = subjmap;
52458+
52459+ subjmap->next = *curr;
52460+ *curr = subjmap;
52461+
52462+ return;
52463+}
52464+
52465+static struct acl_role_label *
52466+lookup_acl_role_label(const struct task_struct *task, const uid_t uid,
52467+ const gid_t gid)
52468+{
52469+ unsigned int index = rhash(uid, GR_ROLE_USER, acl_role_set.r_size);
52470+ struct acl_role_label *match;
52471+ struct role_allowed_ip *ipp;
52472+ unsigned int x;
52473+ u32 curr_ip = task->signal->curr_ip;
52474+
52475+ task->signal->saved_ip = curr_ip;
52476+
52477+ match = acl_role_set.r_hash[index];
52478+
52479+ while (match) {
52480+ if ((match->roletype & (GR_ROLE_DOMAIN | GR_ROLE_USER)) == (GR_ROLE_DOMAIN | GR_ROLE_USER)) {
52481+ for (x = 0; x < match->domain_child_num; x++) {
52482+ if (match->domain_children[x] == uid)
52483+ goto found;
52484+ }
52485+ } else if (match->uidgid == uid && match->roletype & GR_ROLE_USER)
52486+ break;
52487+ match = match->next;
52488+ }
52489+found:
52490+ if (match == NULL) {
52491+ try_group:
52492+ index = rhash(gid, GR_ROLE_GROUP, acl_role_set.r_size);
52493+ match = acl_role_set.r_hash[index];
52494+
52495+ while (match) {
52496+ if ((match->roletype & (GR_ROLE_DOMAIN | GR_ROLE_GROUP)) == (GR_ROLE_DOMAIN | GR_ROLE_GROUP)) {
52497+ for (x = 0; x < match->domain_child_num; x++) {
52498+ if (match->domain_children[x] == gid)
52499+ goto found2;
52500+ }
52501+ } else if (match->uidgid == gid && match->roletype & GR_ROLE_GROUP)
52502+ break;
52503+ match = match->next;
52504+ }
52505+found2:
52506+ if (match == NULL)
52507+ match = default_role;
52508+ if (match->allowed_ips == NULL)
52509+ return match;
52510+ else {
52511+ for (ipp = match->allowed_ips; ipp; ipp = ipp->next) {
52512+ if (likely
52513+ ((ntohl(curr_ip) & ipp->netmask) ==
52514+ (ntohl(ipp->addr) & ipp->netmask)))
52515+ return match;
52516+ }
52517+ match = default_role;
52518+ }
52519+ } else if (match->allowed_ips == NULL) {
52520+ return match;
52521+ } else {
52522+ for (ipp = match->allowed_ips; ipp; ipp = ipp->next) {
52523+ if (likely
52524+ ((ntohl(curr_ip) & ipp->netmask) ==
52525+ (ntohl(ipp->addr) & ipp->netmask)))
52526+ return match;
52527+ }
52528+ goto try_group;
52529+ }
52530+
52531+ return match;
52532+}
52533+
52534+struct acl_subject_label *
52535+lookup_acl_subj_label(const ino_t ino, const dev_t dev,
52536+ const struct acl_role_label *role)
52537+{
52538+ unsigned int index = fhash(ino, dev, role->subj_hash_size);
52539+ struct acl_subject_label *match;
52540+
52541+ match = role->subj_hash[index];
52542+
52543+ while (match && (match->inode != ino || match->device != dev ||
52544+ (match->mode & GR_DELETED))) {
52545+ match = match->next;
52546+ }
52547+
52548+ if (match && !(match->mode & GR_DELETED))
52549+ return match;
52550+ else
52551+ return NULL;
52552+}
52553+
52554+struct acl_subject_label *
52555+lookup_acl_subj_label_deleted(const ino_t ino, const dev_t dev,
52556+ const struct acl_role_label *role)
52557+{
52558+ unsigned int index = fhash(ino, dev, role->subj_hash_size);
52559+ struct acl_subject_label *match;
52560+
52561+ match = role->subj_hash[index];
52562+
52563+ while (match && (match->inode != ino || match->device != dev ||
52564+ !(match->mode & GR_DELETED))) {
52565+ match = match->next;
52566+ }
52567+
52568+ if (match && (match->mode & GR_DELETED))
52569+ return match;
52570+ else
52571+ return NULL;
52572+}
52573+
52574+static struct acl_object_label *
52575+lookup_acl_obj_label(const ino_t ino, const dev_t dev,
52576+ const struct acl_subject_label *subj)
52577+{
52578+ unsigned int index = fhash(ino, dev, subj->obj_hash_size);
52579+ struct acl_object_label *match;
52580+
52581+ match = subj->obj_hash[index];
52582+
52583+ while (match && (match->inode != ino || match->device != dev ||
52584+ (match->mode & GR_DELETED))) {
52585+ match = match->next;
52586+ }
52587+
52588+ if (match && !(match->mode & GR_DELETED))
52589+ return match;
52590+ else
52591+ return NULL;
52592+}
52593+
52594+static struct acl_object_label *
52595+lookup_acl_obj_label_create(const ino_t ino, const dev_t dev,
52596+ const struct acl_subject_label *subj)
52597+{
52598+ unsigned int index = fhash(ino, dev, subj->obj_hash_size);
52599+ struct acl_object_label *match;
52600+
52601+ match = subj->obj_hash[index];
52602+
52603+ while (match && (match->inode != ino || match->device != dev ||
52604+ !(match->mode & GR_DELETED))) {
52605+ match = match->next;
52606+ }
52607+
52608+ if (match && (match->mode & GR_DELETED))
52609+ return match;
52610+
52611+ match = subj->obj_hash[index];
52612+
52613+ while (match && (match->inode != ino || match->device != dev ||
52614+ (match->mode & GR_DELETED))) {
52615+ match = match->next;
52616+ }
52617+
52618+ if (match && !(match->mode & GR_DELETED))
52619+ return match;
52620+ else
52621+ return NULL;
52622+}
52623+
52624+static struct name_entry *
52625+lookup_name_entry(const char *name)
52626+{
52627+ unsigned int len = strlen(name);
52628+ unsigned int key = full_name_hash(name, len);
52629+ unsigned int index = key % name_set.n_size;
52630+ struct name_entry *match;
52631+
52632+ match = name_set.n_hash[index];
52633+
52634+ while (match && (match->key != key || !gr_streq(match->name, name, match->len, len)))
52635+ match = match->next;
52636+
52637+ return match;
52638+}
52639+
52640+static struct name_entry *
52641+lookup_name_entry_create(const char *name)
52642+{
52643+ unsigned int len = strlen(name);
52644+ unsigned int key = full_name_hash(name, len);
52645+ unsigned int index = key % name_set.n_size;
52646+ struct name_entry *match;
52647+
52648+ match = name_set.n_hash[index];
52649+
52650+ while (match && (match->key != key || !gr_streq(match->name, name, match->len, len) ||
52651+ !match->deleted))
52652+ match = match->next;
52653+
52654+ if (match && match->deleted)
52655+ return match;
52656+
52657+ match = name_set.n_hash[index];
52658+
52659+ while (match && (match->key != key || !gr_streq(match->name, name, match->len, len) ||
52660+ match->deleted))
52661+ match = match->next;
52662+
52663+ if (match && !match->deleted)
52664+ return match;
52665+ else
52666+ return NULL;
52667+}
52668+
52669+static struct inodev_entry *
52670+lookup_inodev_entry(const ino_t ino, const dev_t dev)
52671+{
52672+ unsigned int index = fhash(ino, dev, inodev_set.i_size);
52673+ struct inodev_entry *match;
52674+
52675+ match = inodev_set.i_hash[index];
52676+
52677+ while (match && (match->nentry->inode != ino || match->nentry->device != dev))
52678+ match = match->next;
52679+
52680+ return match;
52681+}
52682+
52683+static void
52684+insert_inodev_entry(struct inodev_entry *entry)
52685+{
52686+ unsigned int index = fhash(entry->nentry->inode, entry->nentry->device,
52687+ inodev_set.i_size);
52688+ struct inodev_entry **curr;
52689+
52690+ entry->prev = NULL;
52691+
52692+ curr = &inodev_set.i_hash[index];
52693+ if (*curr != NULL)
52694+ (*curr)->prev = entry;
52695+
52696+ entry->next = *curr;
52697+ *curr = entry;
52698+
52699+ return;
52700+}
52701+
52702+static void
52703+__insert_acl_role_label(struct acl_role_label *role, uid_t uidgid)
52704+{
52705+ unsigned int index =
52706+ rhash(uidgid, role->roletype & (GR_ROLE_USER | GR_ROLE_GROUP), acl_role_set.r_size);
52707+ struct acl_role_label **curr;
52708+ struct acl_role_label *tmp, *tmp2;
52709+
52710+ curr = &acl_role_set.r_hash[index];
52711+
52712+ /* simple case, slot is empty, just set it to our role */
52713+ if (*curr == NULL) {
52714+ *curr = role;
52715+ } else {
52716+ /* example:
52717+ 1 -> 2 -> 3 (adding 2 -> 3 to here)
52718+ 2 -> 3
52719+ */
52720+ /* first check to see if we can already be reached via this slot */
52721+ tmp = *curr;
52722+ while (tmp && tmp != role)
52723+ tmp = tmp->next;
52724+ if (tmp == role) {
52725+ /* we don't need to add ourselves to this slot's chain */
52726+ return;
52727+ }
52728+ /* we need to add ourselves to this chain, two cases */
52729+ if (role->next == NULL) {
52730+ /* simple case, append the current chain to our role */
52731+ role->next = *curr;
52732+ *curr = role;
52733+ } else {
52734+ /* 1 -> 2 -> 3 -> 4
52735+ 2 -> 3 -> 4
52736+ 3 -> 4 (adding 1 -> 2 -> 3 -> 4 to here)
52737+ */
52738+ /* trickier case: walk our role's chain until we find
52739+ the role for the start of the current slot's chain */
52740+ tmp = role;
52741+ tmp2 = *curr;
52742+ while (tmp->next && tmp->next != tmp2)
52743+ tmp = tmp->next;
52744+ if (tmp->next == tmp2) {
52745+ /* from example above, we found 3, so just
52746+ replace this slot's chain with ours */
52747+ *curr = role;
52748+ } else {
52749+ /* we didn't find a subset of our role's chain
52750+ in the current slot's chain, so append their
52751+ chain to ours, and set us as the first role in
52752+ the slot's chain
52753+
52754+ we could fold this case with the case above,
52755+ but making it explicit for clarity
52756+ */
52757+ tmp->next = tmp2;
52758+ *curr = role;
52759+ }
52760+ }
52761+ }
52762+
52763+ return;
52764+}
52765+
52766+static void
52767+insert_acl_role_label(struct acl_role_label *role)
52768+{
52769+ int i;
52770+
52771+ if (role_list == NULL) {
52772+ role_list = role;
52773+ role->prev = NULL;
52774+ } else {
52775+ role->prev = role_list;
52776+ role_list = role;
52777+ }
52778+
52779+ /* used for hash chains */
52780+ role->next = NULL;
52781+
52782+ if (role->roletype & GR_ROLE_DOMAIN) {
52783+ for (i = 0; i < role->domain_child_num; i++)
52784+ __insert_acl_role_label(role, role->domain_children[i]);
52785+ } else
52786+ __insert_acl_role_label(role, role->uidgid);
52787+}
52788+
52789+static int
52790+insert_name_entry(char *name, const ino_t inode, const dev_t device, __u8 deleted)
52791+{
52792+ struct name_entry **curr, *nentry;
52793+ struct inodev_entry *ientry;
52794+ unsigned int len = strlen(name);
52795+ unsigned int key = full_name_hash(name, len);
52796+ unsigned int index = key % name_set.n_size;
52797+
52798+ curr = &name_set.n_hash[index];
52799+
52800+ while (*curr && ((*curr)->key != key || !gr_streq((*curr)->name, name, (*curr)->len, len)))
52801+ curr = &((*curr)->next);
52802+
52803+ if (*curr != NULL)
52804+ return 1;
52805+
52806+ nentry = acl_alloc(sizeof (struct name_entry));
52807+ if (nentry == NULL)
52808+ return 0;
52809+ ientry = acl_alloc(sizeof (struct inodev_entry));
52810+ if (ientry == NULL)
52811+ return 0;
52812+ ientry->nentry = nentry;
52813+
52814+ nentry->key = key;
52815+ nentry->name = name;
52816+ nentry->inode = inode;
52817+ nentry->device = device;
52818+ nentry->len = len;
52819+ nentry->deleted = deleted;
52820+
52821+ nentry->prev = NULL;
52822+ curr = &name_set.n_hash[index];
52823+ if (*curr != NULL)
52824+ (*curr)->prev = nentry;
52825+ nentry->next = *curr;
52826+ *curr = nentry;
52827+
52828+ /* insert us into the table searchable by inode/dev */
52829+ insert_inodev_entry(ientry);
52830+
52831+ return 1;
52832+}
52833+
52834+static void
52835+insert_acl_obj_label(struct acl_object_label *obj,
52836+ struct acl_subject_label *subj)
52837+{
52838+ unsigned int index =
52839+ fhash(obj->inode, obj->device, subj->obj_hash_size);
52840+ struct acl_object_label **curr;
52841+
52842+
52843+ obj->prev = NULL;
52844+
52845+ curr = &subj->obj_hash[index];
52846+ if (*curr != NULL)
52847+ (*curr)->prev = obj;
52848+
52849+ obj->next = *curr;
52850+ *curr = obj;
52851+
52852+ return;
52853+}
52854+
52855+static void
52856+insert_acl_subj_label(struct acl_subject_label *obj,
52857+ struct acl_role_label *role)
52858+{
52859+ unsigned int index = fhash(obj->inode, obj->device, role->subj_hash_size);
52860+ struct acl_subject_label **curr;
52861+
52862+ obj->prev = NULL;
52863+
52864+ curr = &role->subj_hash[index];
52865+ if (*curr != NULL)
52866+ (*curr)->prev = obj;
52867+
52868+ obj->next = *curr;
52869+ *curr = obj;
52870+
52871+ return;
52872+}
52873+
52874+/* allocating chained hash tables, so optimal size is where lambda ~ 1 */
52875+
52876+static void *
52877+create_table(__u32 * len, int elementsize)
52878+{
52879+ unsigned int table_sizes[] = {
52880+ 7, 13, 31, 61, 127, 251, 509, 1021, 2039, 4093, 8191, 16381,
52881+ 32749, 65521, 131071, 262139, 524287, 1048573, 2097143,
52882+ 4194301, 8388593, 16777213, 33554393, 67108859
52883+ };
52884+ void *newtable = NULL;
52885+ unsigned int pwr = 0;
52886+
52887+ while ((pwr < ((sizeof (table_sizes) / sizeof (table_sizes[0])) - 1)) &&
52888+ table_sizes[pwr] <= *len)
52889+ pwr++;
52890+
52891+ if (table_sizes[pwr] <= *len || (table_sizes[pwr] > ULONG_MAX / elementsize))
52892+ return newtable;
52893+
52894+ if ((table_sizes[pwr] * elementsize) <= PAGE_SIZE)
52895+ newtable =
52896+ kmalloc(table_sizes[pwr] * elementsize, GFP_KERNEL);
52897+ else
52898+ newtable = vmalloc(table_sizes[pwr] * elementsize);
52899+
52900+ *len = table_sizes[pwr];
52901+
52902+ return newtable;
52903+}
52904+
52905+static int
52906+init_variables(const struct gr_arg *arg)
52907+{
52908+ struct task_struct *reaper = init_pid_ns.child_reaper;
52909+ unsigned int stacksize;
52910+
52911+ subj_map_set.s_size = arg->role_db.num_subjects;
52912+ acl_role_set.r_size = arg->role_db.num_roles + arg->role_db.num_domain_children;
52913+ name_set.n_size = arg->role_db.num_objects;
52914+ inodev_set.i_size = arg->role_db.num_objects;
52915+
52916+ if (!subj_map_set.s_size || !acl_role_set.r_size ||
52917+ !name_set.n_size || !inodev_set.i_size)
52918+ return 1;
52919+
52920+ if (!gr_init_uidset())
52921+ return 1;
52922+
52923+ /* set up the stack that holds allocation info */
52924+
52925+ stacksize = arg->role_db.num_pointers + 5;
52926+
52927+ if (!acl_alloc_stack_init(stacksize))
52928+ return 1;
52929+
52930+ /* grab reference for the real root dentry and vfsmount */
52931+ get_fs_root(reaper->fs, &real_root);
52932+
52933+#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
52934+ printk(KERN_ALERT "Obtained real root device=%d, inode=%lu\n", __get_dev(real_root.dentry), real_root.dentry->d_inode->i_ino);
52935+#endif
52936+
52937+ fakefs_obj_rw = acl_alloc(sizeof(struct acl_object_label));
52938+ if (fakefs_obj_rw == NULL)
52939+ return 1;
52940+ fakefs_obj_rw->mode = GR_FIND | GR_READ | GR_WRITE;
52941+
52942+ fakefs_obj_rwx = acl_alloc(sizeof(struct acl_object_label));
52943+ if (fakefs_obj_rwx == NULL)
52944+ return 1;
52945+ fakefs_obj_rwx->mode = GR_FIND | GR_READ | GR_WRITE | GR_EXEC;
52946+
52947+ subj_map_set.s_hash =
52948+ (struct subject_map **) create_table(&subj_map_set.s_size, sizeof(void *));
52949+ acl_role_set.r_hash =
52950+ (struct acl_role_label **) create_table(&acl_role_set.r_size, sizeof(void *));
52951+ name_set.n_hash = (struct name_entry **) create_table(&name_set.n_size, sizeof(void *));
52952+ inodev_set.i_hash =
52953+ (struct inodev_entry **) create_table(&inodev_set.i_size, sizeof(void *));
52954+
52955+ if (!subj_map_set.s_hash || !acl_role_set.r_hash ||
52956+ !name_set.n_hash || !inodev_set.i_hash)
52957+ return 1;
52958+
52959+ memset(subj_map_set.s_hash, 0,
52960+ sizeof(struct subject_map *) * subj_map_set.s_size);
52961+ memset(acl_role_set.r_hash, 0,
52962+ sizeof (struct acl_role_label *) * acl_role_set.r_size);
52963+ memset(name_set.n_hash, 0,
52964+ sizeof (struct name_entry *) * name_set.n_size);
52965+ memset(inodev_set.i_hash, 0,
52966+ sizeof (struct inodev_entry *) * inodev_set.i_size);
52967+
52968+ return 0;
52969+}
52970+
52971+/* free information not needed after startup
52972+ currently contains user->kernel pointer mappings for subjects
52973+*/
52974+
52975+static void
52976+free_init_variables(void)
52977+{
52978+ __u32 i;
52979+
52980+ if (subj_map_set.s_hash) {
52981+ for (i = 0; i < subj_map_set.s_size; i++) {
52982+ if (subj_map_set.s_hash[i]) {
52983+ kfree(subj_map_set.s_hash[i]);
52984+ subj_map_set.s_hash[i] = NULL;
52985+ }
52986+ }
52987+
52988+ if ((subj_map_set.s_size * sizeof (struct subject_map *)) <=
52989+ PAGE_SIZE)
52990+ kfree(subj_map_set.s_hash);
52991+ else
52992+ vfree(subj_map_set.s_hash);
52993+ }
52994+
52995+ return;
52996+}
52997+
52998+static void
52999+free_variables(void)
53000+{
53001+ struct acl_subject_label *s;
53002+ struct acl_role_label *r;
53003+ struct task_struct *task, *task2;
53004+ unsigned int x;
53005+
53006+ gr_clear_learn_entries();
53007+
53008+ read_lock(&tasklist_lock);
53009+ do_each_thread(task2, task) {
53010+ task->acl_sp_role = 0;
53011+ task->acl_role_id = 0;
53012+ task->acl = NULL;
53013+ task->role = NULL;
53014+ } while_each_thread(task2, task);
53015+ read_unlock(&tasklist_lock);
53016+
53017+ /* release the reference to the real root dentry and vfsmount */
53018+ path_put(&real_root);
53019+ memset(&real_root, 0, sizeof(real_root));
53020+
53021+ /* free all object hash tables */
53022+
53023+ FOR_EACH_ROLE_START(r)
53024+ if (r->subj_hash == NULL)
53025+ goto next_role;
53026+ FOR_EACH_SUBJECT_START(r, s, x)
53027+ if (s->obj_hash == NULL)
53028+ break;
53029+ if ((s->obj_hash_size * sizeof (struct acl_object_label *)) <= PAGE_SIZE)
53030+ kfree(s->obj_hash);
53031+ else
53032+ vfree(s->obj_hash);
53033+ FOR_EACH_SUBJECT_END(s, x)
53034+ FOR_EACH_NESTED_SUBJECT_START(r, s)
53035+ if (s->obj_hash == NULL)
53036+ break;
53037+ if ((s->obj_hash_size * sizeof (struct acl_object_label *)) <= PAGE_SIZE)
53038+ kfree(s->obj_hash);
53039+ else
53040+ vfree(s->obj_hash);
53041+ FOR_EACH_NESTED_SUBJECT_END(s)
53042+ if ((r->subj_hash_size * sizeof (struct acl_subject_label *)) <= PAGE_SIZE)
53043+ kfree(r->subj_hash);
53044+ else
53045+ vfree(r->subj_hash);
53046+ r->subj_hash = NULL;
53047+next_role:
53048+ FOR_EACH_ROLE_END(r)
53049+
53050+ acl_free_all();
53051+
53052+ if (acl_role_set.r_hash) {
53053+ if ((acl_role_set.r_size * sizeof (struct acl_role_label *)) <=
53054+ PAGE_SIZE)
53055+ kfree(acl_role_set.r_hash);
53056+ else
53057+ vfree(acl_role_set.r_hash);
53058+ }
53059+ if (name_set.n_hash) {
53060+ if ((name_set.n_size * sizeof (struct name_entry *)) <=
53061+ PAGE_SIZE)
53062+ kfree(name_set.n_hash);
53063+ else
53064+ vfree(name_set.n_hash);
53065+ }
53066+
53067+ if (inodev_set.i_hash) {
53068+ if ((inodev_set.i_size * sizeof (struct inodev_entry *)) <=
53069+ PAGE_SIZE)
53070+ kfree(inodev_set.i_hash);
53071+ else
53072+ vfree(inodev_set.i_hash);
53073+ }
53074+
53075+ gr_free_uidset();
53076+
53077+ memset(&name_set, 0, sizeof (struct name_db));
53078+ memset(&inodev_set, 0, sizeof (struct inodev_db));
53079+ memset(&acl_role_set, 0, sizeof (struct acl_role_db));
53080+ memset(&subj_map_set, 0, sizeof (struct acl_subj_map_db));
53081+
53082+ default_role = NULL;
53083+ kernel_role = NULL;
53084+ role_list = NULL;
53085+
53086+ return;
53087+}
53088+
53089+static __u32
53090+count_user_objs(struct acl_object_label *userp)
53091+{
53092+ struct acl_object_label o_tmp;
53093+ __u32 num = 0;
53094+
53095+ while (userp) {
53096+ if (copy_from_user(&o_tmp, userp,
53097+ sizeof (struct acl_object_label)))
53098+ break;
53099+
53100+ userp = o_tmp.prev;
53101+ num++;
53102+ }
53103+
53104+ return num;
53105+}
53106+
53107+static struct acl_subject_label *
53108+do_copy_user_subj(struct acl_subject_label *userp, struct acl_role_label *role, int *already_copied);
53109+
53110+static int
53111+copy_user_glob(struct acl_object_label *obj)
53112+{
53113+ struct acl_object_label *g_tmp, **guser;
53114+ unsigned int len;
53115+ char *tmp;
53116+
53117+ if (obj->globbed == NULL)
53118+ return 0;
53119+
53120+ guser = &obj->globbed;
53121+ while (*guser) {
53122+ g_tmp = (struct acl_object_label *)
53123+ acl_alloc(sizeof (struct acl_object_label));
53124+ if (g_tmp == NULL)
53125+ return -ENOMEM;
53126+
53127+ if (copy_from_user(g_tmp, *guser,
53128+ sizeof (struct acl_object_label)))
53129+ return -EFAULT;
53130+
53131+ len = strnlen_user(g_tmp->filename, PATH_MAX);
53132+
53133+ if (!len || len >= PATH_MAX)
53134+ return -EINVAL;
53135+
53136+ if ((tmp = (char *) acl_alloc(len)) == NULL)
53137+ return -ENOMEM;
53138+
53139+ if (copy_from_user(tmp, g_tmp->filename, len))
53140+ return -EFAULT;
53141+ tmp[len-1] = '\0';
53142+ g_tmp->filename = tmp;
53143+
53144+ *guser = g_tmp;
53145+ guser = &(g_tmp->next);
53146+ }
53147+
53148+ return 0;
53149+}
53150+
53151+static int
53152+copy_user_objs(struct acl_object_label *userp, struct acl_subject_label *subj,
53153+ struct acl_role_label *role)
53154+{
53155+ struct acl_object_label *o_tmp;
53156+ unsigned int len;
53157+ int ret;
53158+ char *tmp;
53159+
53160+ while (userp) {
53161+ if ((o_tmp = (struct acl_object_label *)
53162+ acl_alloc(sizeof (struct acl_object_label))) == NULL)
53163+ return -ENOMEM;
53164+
53165+ if (copy_from_user(o_tmp, userp,
53166+ sizeof (struct acl_object_label)))
53167+ return -EFAULT;
53168+
53169+ userp = o_tmp->prev;
53170+
53171+ len = strnlen_user(o_tmp->filename, PATH_MAX);
53172+
53173+ if (!len || len >= PATH_MAX)
53174+ return -EINVAL;
53175+
53176+ if ((tmp = (char *) acl_alloc(len)) == NULL)
53177+ return -ENOMEM;
53178+
53179+ if (copy_from_user(tmp, o_tmp->filename, len))
53180+ return -EFAULT;
53181+ tmp[len-1] = '\0';
53182+ o_tmp->filename = tmp;
53183+
53184+ insert_acl_obj_label(o_tmp, subj);
53185+ if (!insert_name_entry(o_tmp->filename, o_tmp->inode,
53186+ o_tmp->device, (o_tmp->mode & GR_DELETED) ? 1 : 0))
53187+ return -ENOMEM;
53188+
53189+ ret = copy_user_glob(o_tmp);
53190+ if (ret)
53191+ return ret;
53192+
53193+ if (o_tmp->nested) {
53194+ int already_copied;
53195+
53196+ o_tmp->nested = do_copy_user_subj(o_tmp->nested, role, &already_copied);
53197+ if (IS_ERR(o_tmp->nested))
53198+ return PTR_ERR(o_tmp->nested);
53199+
53200+ /* insert into nested subject list if we haven't copied this one yet
53201+ to prevent duplicate entries */
53202+ if (!already_copied) {
53203+ o_tmp->nested->next = role->hash->first;
53204+ role->hash->first = o_tmp->nested;
53205+ }
53206+ }
53207+ }
53208+
53209+ return 0;
53210+}
53211+
53212+static __u32
53213+count_user_subjs(struct acl_subject_label *userp)
53214+{
53215+ struct acl_subject_label s_tmp;
53216+ __u32 num = 0;
53217+
53218+ while (userp) {
53219+ if (copy_from_user(&s_tmp, userp,
53220+ sizeof (struct acl_subject_label)))
53221+ break;
53222+
53223+ userp = s_tmp.prev;
53224+ /* do not count nested subjects against this count, since
53225+ they are not included in the hash table, but are
53226+ attached to objects. We have already counted
53227+ the subjects in userspace for the allocation
53228+ stack
53229+ */
53230+ if (!(s_tmp.mode & GR_NESTED))
53231+ num++;
53232+ }
53233+
53234+ return num;
53235+}
53236+
53237+static int
53238+copy_user_allowedips(struct acl_role_label *rolep)
53239+{
53240+ struct role_allowed_ip *ruserip, *rtmp = NULL, *rlast;
53241+
53242+ ruserip = rolep->allowed_ips;
53243+
53244+ while (ruserip) {
53245+ rlast = rtmp;
53246+
53247+ if ((rtmp = (struct role_allowed_ip *)
53248+ acl_alloc(sizeof (struct role_allowed_ip))) == NULL)
53249+ return -ENOMEM;
53250+
53251+ if (copy_from_user(rtmp, ruserip,
53252+ sizeof (struct role_allowed_ip)))
53253+ return -EFAULT;
53254+
53255+ ruserip = rtmp->prev;
53256+
53257+ if (!rlast) {
53258+ rtmp->prev = NULL;
53259+ rolep->allowed_ips = rtmp;
53260+ } else {
53261+ rlast->next = rtmp;
53262+ rtmp->prev = rlast;
53263+ }
53264+
53265+ if (!ruserip)
53266+ rtmp->next = NULL;
53267+ }
53268+
53269+ return 0;
53270+}
53271+
53272+static int
53273+copy_user_transitions(struct acl_role_label *rolep)
53274+{
53275+ struct role_transition *rusertp, *rtmp = NULL, *rlast;
53276+
53277+ unsigned int len;
53278+ char *tmp;
53279+
53280+ rusertp = rolep->transitions;
53281+
53282+ while (rusertp) {
53283+ rlast = rtmp;
53284+
53285+ if ((rtmp = (struct role_transition *)
53286+ acl_alloc(sizeof (struct role_transition))) == NULL)
53287+ return -ENOMEM;
53288+
53289+ if (copy_from_user(rtmp, rusertp,
53290+ sizeof (struct role_transition)))
53291+ return -EFAULT;
53292+
53293+ rusertp = rtmp->prev;
53294+
53295+ len = strnlen_user(rtmp->rolename, GR_SPROLE_LEN);
53296+
53297+ if (!len || len >= GR_SPROLE_LEN)
53298+ return -EINVAL;
53299+
53300+ if ((tmp = (char *) acl_alloc(len)) == NULL)
53301+ return -ENOMEM;
53302+
53303+ if (copy_from_user(tmp, rtmp->rolename, len))
53304+ return -EFAULT;
53305+ tmp[len-1] = '\0';
53306+ rtmp->rolename = tmp;
53307+
53308+ if (!rlast) {
53309+ rtmp->prev = NULL;
53310+ rolep->transitions = rtmp;
53311+ } else {
53312+ rlast->next = rtmp;
53313+ rtmp->prev = rlast;
53314+ }
53315+
53316+ if (!rusertp)
53317+ rtmp->next = NULL;
53318+ }
53319+
53320+ return 0;
53321+}
53322+
53323+static struct acl_subject_label *
53324+do_copy_user_subj(struct acl_subject_label *userp, struct acl_role_label *role, int *already_copied)
53325+{
53326+ struct acl_subject_label *s_tmp = NULL, *s_tmp2;
53327+ unsigned int len;
53328+ char *tmp;
53329+ __u32 num_objs;
53330+ struct acl_ip_label **i_tmp, *i_utmp2;
53331+ struct gr_hash_struct ghash;
53332+ struct subject_map *subjmap;
53333+ unsigned int i_num;
53334+ int err;
53335+
53336+ if (already_copied != NULL)
53337+ *already_copied = 0;
53338+
53339+ s_tmp = lookup_subject_map(userp);
53340+
53341+ /* we've already copied this subject into the kernel, just return
53342+ the reference to it, and don't copy it over again
53343+ */
53344+ if (s_tmp) {
53345+ if (already_copied != NULL)
53346+ *already_copied = 1;
53347+ return(s_tmp);
53348+ }
53349+
53350+ if ((s_tmp = (struct acl_subject_label *)
53351+ acl_alloc(sizeof (struct acl_subject_label))) == NULL)
53352+ return ERR_PTR(-ENOMEM);
53353+
53354+ subjmap = (struct subject_map *)kmalloc(sizeof (struct subject_map), GFP_KERNEL);
53355+ if (subjmap == NULL)
53356+ return ERR_PTR(-ENOMEM);
53357+
53358+ subjmap->user = userp;
53359+ subjmap->kernel = s_tmp;
53360+ insert_subj_map_entry(subjmap);
53361+
53362+ if (copy_from_user(s_tmp, userp,
53363+ sizeof (struct acl_subject_label)))
53364+ return ERR_PTR(-EFAULT);
53365+
53366+ len = strnlen_user(s_tmp->filename, PATH_MAX);
53367+
53368+ if (!len || len >= PATH_MAX)
53369+ return ERR_PTR(-EINVAL);
53370+
53371+ if ((tmp = (char *) acl_alloc(len)) == NULL)
53372+ return ERR_PTR(-ENOMEM);
53373+
53374+ if (copy_from_user(tmp, s_tmp->filename, len))
53375+ return ERR_PTR(-EFAULT);
53376+ tmp[len-1] = '\0';
53377+ s_tmp->filename = tmp;
53378+
53379+ if (!strcmp(s_tmp->filename, "/"))
53380+ role->root_label = s_tmp;
53381+
53382+ if (copy_from_user(&ghash, s_tmp->hash, sizeof(struct gr_hash_struct)))
53383+ return ERR_PTR(-EFAULT);
53384+
53385+ /* copy user and group transition tables */
53386+
53387+ if (s_tmp->user_trans_num) {
53388+ uid_t *uidlist;
53389+
53390+ uidlist = (uid_t *)acl_alloc_num(s_tmp->user_trans_num, sizeof(uid_t));
53391+ if (uidlist == NULL)
53392+ return ERR_PTR(-ENOMEM);
53393+ if (copy_from_user(uidlist, s_tmp->user_transitions, s_tmp->user_trans_num * sizeof(uid_t)))
53394+ return ERR_PTR(-EFAULT);
53395+
53396+ s_tmp->user_transitions = uidlist;
53397+ }
53398+
53399+ if (s_tmp->group_trans_num) {
53400+ gid_t *gidlist;
53401+
53402+ gidlist = (gid_t *)acl_alloc_num(s_tmp->group_trans_num, sizeof(gid_t));
53403+ if (gidlist == NULL)
53404+ return ERR_PTR(-ENOMEM);
53405+ if (copy_from_user(gidlist, s_tmp->group_transitions, s_tmp->group_trans_num * sizeof(gid_t)))
53406+ return ERR_PTR(-EFAULT);
53407+
53408+ s_tmp->group_transitions = gidlist;
53409+ }
53410+
53411+ /* set up object hash table */
53412+ num_objs = count_user_objs(ghash.first);
53413+
53414+ s_tmp->obj_hash_size = num_objs;
53415+ s_tmp->obj_hash =
53416+ (struct acl_object_label **)
53417+ create_table(&(s_tmp->obj_hash_size), sizeof(void *));
53418+
53419+ if (!s_tmp->obj_hash)
53420+ return ERR_PTR(-ENOMEM);
53421+
53422+ memset(s_tmp->obj_hash, 0,
53423+ s_tmp->obj_hash_size *
53424+ sizeof (struct acl_object_label *));
53425+
53426+ /* add in objects */
53427+ err = copy_user_objs(ghash.first, s_tmp, role);
53428+
53429+ if (err)
53430+ return ERR_PTR(err);
53431+
53432+ /* set pointer for parent subject */
53433+ if (s_tmp->parent_subject) {
53434+ s_tmp2 = do_copy_user_subj(s_tmp->parent_subject, role, NULL);
53435+
53436+ if (IS_ERR(s_tmp2))
53437+ return s_tmp2;
53438+
53439+ s_tmp->parent_subject = s_tmp2;
53440+ }
53441+
53442+ /* add in ip acls */
53443+
53444+ if (!s_tmp->ip_num) {
53445+ s_tmp->ips = NULL;
53446+ goto insert;
53447+ }
53448+
53449+ i_tmp =
53450+ (struct acl_ip_label **) acl_alloc_num(s_tmp->ip_num,
53451+ sizeof (struct acl_ip_label *));
53452+
53453+ if (!i_tmp)
53454+ return ERR_PTR(-ENOMEM);
53455+
53456+ for (i_num = 0; i_num < s_tmp->ip_num; i_num++) {
53457+ *(i_tmp + i_num) =
53458+ (struct acl_ip_label *)
53459+ acl_alloc(sizeof (struct acl_ip_label));
53460+ if (!*(i_tmp + i_num))
53461+ return ERR_PTR(-ENOMEM);
53462+
53463+ if (copy_from_user
53464+ (&i_utmp2, s_tmp->ips + i_num,
53465+ sizeof (struct acl_ip_label *)))
53466+ return ERR_PTR(-EFAULT);
53467+
53468+ if (copy_from_user
53469+ (*(i_tmp + i_num), i_utmp2,
53470+ sizeof (struct acl_ip_label)))
53471+ return ERR_PTR(-EFAULT);
53472+
53473+ if ((*(i_tmp + i_num))->iface == NULL)
53474+ continue;
53475+
53476+ len = strnlen_user((*(i_tmp + i_num))->iface, IFNAMSIZ);
53477+ if (!len || len >= IFNAMSIZ)
53478+ return ERR_PTR(-EINVAL);
53479+ tmp = acl_alloc(len);
53480+ if (tmp == NULL)
53481+ return ERR_PTR(-ENOMEM);
53482+ if (copy_from_user(tmp, (*(i_tmp + i_num))->iface, len))
53483+ return ERR_PTR(-EFAULT);
53484+ (*(i_tmp + i_num))->iface = tmp;
53485+ }
53486+
53487+ s_tmp->ips = i_tmp;
53488+
53489+insert:
53490+ if (!insert_name_entry(s_tmp->filename, s_tmp->inode,
53491+ s_tmp->device, (s_tmp->mode & GR_DELETED) ? 1 : 0))
53492+ return ERR_PTR(-ENOMEM);
53493+
53494+ return s_tmp;
53495+}
53496+
53497+static int
53498+copy_user_subjs(struct acl_subject_label *userp, struct acl_role_label *role)
53499+{
53500+ struct acl_subject_label s_pre;
53501+ struct acl_subject_label * ret;
53502+ int err;
53503+
53504+ while (userp) {
53505+ if (copy_from_user(&s_pre, userp,
53506+ sizeof (struct acl_subject_label)))
53507+ return -EFAULT;
53508+
53509+ /* do not add nested subjects here, add
53510+ while parsing objects
53511+ */
53512+
53513+ if (s_pre.mode & GR_NESTED) {
53514+ userp = s_pre.prev;
53515+ continue;
53516+ }
53517+
53518+ ret = do_copy_user_subj(userp, role, NULL);
53519+
53520+ err = PTR_ERR(ret);
53521+ if (IS_ERR(ret))
53522+ return err;
53523+
53524+ insert_acl_subj_label(ret, role);
53525+
53526+ userp = s_pre.prev;
53527+ }
53528+
53529+ return 0;
53530+}
53531+
53532+static int
53533+copy_user_acl(struct gr_arg *arg)
53534+{
53535+ struct acl_role_label *r_tmp = NULL, **r_utmp, *r_utmp2;
53536+ struct acl_subject_label *subj_list;
53537+ struct sprole_pw *sptmp;
53538+ struct gr_hash_struct *ghash;
53539+ uid_t *domainlist;
53540+ unsigned int r_num;
53541+ unsigned int len;
53542+ char *tmp;
53543+ int err = 0;
53544+ __u16 i;
53545+ __u32 num_subjs;
53546+
53547+ /* we need a default and kernel role */
53548+ if (arg->role_db.num_roles < 2)
53549+ return -EINVAL;
53550+
53551+ /* copy special role authentication info from userspace */
53552+
53553+ num_sprole_pws = arg->num_sprole_pws;
53554+ acl_special_roles = (struct sprole_pw **) acl_alloc_num(num_sprole_pws, sizeof(struct sprole_pw *));
53555+
53556+ if (!acl_special_roles && num_sprole_pws)
53557+ return -ENOMEM;
53558+
53559+ for (i = 0; i < num_sprole_pws; i++) {
53560+ sptmp = (struct sprole_pw *) acl_alloc(sizeof(struct sprole_pw));
53561+ if (!sptmp)
53562+ return -ENOMEM;
53563+ if (copy_from_user(sptmp, arg->sprole_pws + i,
53564+ sizeof (struct sprole_pw)))
53565+ return -EFAULT;
53566+
53567+ len = strnlen_user(sptmp->rolename, GR_SPROLE_LEN);
53568+
53569+ if (!len || len >= GR_SPROLE_LEN)
53570+ return -EINVAL;
53571+
53572+ if ((tmp = (char *) acl_alloc(len)) == NULL)
53573+ return -ENOMEM;
53574+
53575+ if (copy_from_user(tmp, sptmp->rolename, len))
53576+ return -EFAULT;
53577+
53578+ tmp[len-1] = '\0';
53579+#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
53580+ printk(KERN_ALERT "Copying special role %s\n", tmp);
53581+#endif
53582+ sptmp->rolename = tmp;
53583+ acl_special_roles[i] = sptmp;
53584+ }
53585+
53586+ r_utmp = (struct acl_role_label **) arg->role_db.r_table;
53587+
53588+ for (r_num = 0; r_num < arg->role_db.num_roles; r_num++) {
53589+ r_tmp = acl_alloc(sizeof (struct acl_role_label));
53590+
53591+ if (!r_tmp)
53592+ return -ENOMEM;
53593+
53594+ if (copy_from_user(&r_utmp2, r_utmp + r_num,
53595+ sizeof (struct acl_role_label *)))
53596+ return -EFAULT;
53597+
53598+ if (copy_from_user(r_tmp, r_utmp2,
53599+ sizeof (struct acl_role_label)))
53600+ return -EFAULT;
53601+
53602+ len = strnlen_user(r_tmp->rolename, GR_SPROLE_LEN);
53603+
53604+ if (!len || len >= PATH_MAX)
53605+ return -EINVAL;
53606+
53607+ if ((tmp = (char *) acl_alloc(len)) == NULL)
53608+ return -ENOMEM;
53609+
53610+ if (copy_from_user(tmp, r_tmp->rolename, len))
53611+ return -EFAULT;
53612+
53613+ tmp[len-1] = '\0';
53614+ r_tmp->rolename = tmp;
53615+
53616+ if (!strcmp(r_tmp->rolename, "default")
53617+ && (r_tmp->roletype & GR_ROLE_DEFAULT)) {
53618+ default_role = r_tmp;
53619+ } else if (!strcmp(r_tmp->rolename, ":::kernel:::")) {
53620+ kernel_role = r_tmp;
53621+ }
53622+
53623+ if ((ghash = (struct gr_hash_struct *) acl_alloc(sizeof(struct gr_hash_struct))) == NULL)
53624+ return -ENOMEM;
53625+
53626+ if (copy_from_user(ghash, r_tmp->hash, sizeof(struct gr_hash_struct)))
53627+ return -EFAULT;
53628+
53629+ r_tmp->hash = ghash;
53630+
53631+ num_subjs = count_user_subjs(r_tmp->hash->first);
53632+
53633+ r_tmp->subj_hash_size = num_subjs;
53634+ r_tmp->subj_hash =
53635+ (struct acl_subject_label **)
53636+ create_table(&(r_tmp->subj_hash_size), sizeof(void *));
53637+
53638+ if (!r_tmp->subj_hash)
53639+ return -ENOMEM;
53640+
53641+ err = copy_user_allowedips(r_tmp);
53642+ if (err)
53643+ return err;
53644+
53645+ /* copy domain info */
53646+ if (r_tmp->domain_children != NULL) {
53647+ domainlist = acl_alloc_num(r_tmp->domain_child_num, sizeof(uid_t));
53648+ if (domainlist == NULL)
53649+ return -ENOMEM;
53650+
53651+ if (copy_from_user(domainlist, r_tmp->domain_children, r_tmp->domain_child_num * sizeof(uid_t)))
53652+ return -EFAULT;
53653+
53654+ r_tmp->domain_children = domainlist;
53655+ }
53656+
53657+ err = copy_user_transitions(r_tmp);
53658+ if (err)
53659+ return err;
53660+
53661+ memset(r_tmp->subj_hash, 0,
53662+ r_tmp->subj_hash_size *
53663+ sizeof (struct acl_subject_label *));
53664+
53665+ /* acquire the list of subjects, then NULL out
53666+ the list prior to parsing the subjects for this role,
53667+ as during this parsing the list is replaced with a list
53668+ of *nested* subjects for the role
53669+ */
53670+ subj_list = r_tmp->hash->first;
53671+
53672+ /* set nested subject list to null */
53673+ r_tmp->hash->first = NULL;
53674+
53675+ err = copy_user_subjs(subj_list, r_tmp);
53676+
53677+ if (err)
53678+ return err;
53679+
53680+ insert_acl_role_label(r_tmp);
53681+ }
53682+
53683+ if (default_role == NULL || kernel_role == NULL)
53684+ return -EINVAL;
53685+
53686+ return err;
53687+}
53688+
53689+static int
53690+gracl_init(struct gr_arg *args)
53691+{
53692+ int error = 0;
53693+
53694+ memcpy(gr_system_salt, args->salt, GR_SALT_LEN);
53695+ memcpy(gr_system_sum, args->sum, GR_SHA_LEN);
53696+
53697+ if (init_variables(args)) {
53698+ gr_log_str(GR_DONT_AUDIT_GOOD, GR_INITF_ACL_MSG, GR_VERSION);
53699+ error = -ENOMEM;
53700+ free_variables();
53701+ goto out;
53702+ }
53703+
53704+ error = copy_user_acl(args);
53705+ free_init_variables();
53706+ if (error) {
53707+ free_variables();
53708+ goto out;
53709+ }
53710+
53711+ if ((error = gr_set_acls(0))) {
53712+ free_variables();
53713+ goto out;
53714+ }
53715+
53716+ pax_open_kernel();
53717+ gr_status |= GR_READY;
53718+ pax_close_kernel();
53719+
53720+ out:
53721+ return error;
53722+}
53723+
53724+/* derived from glibc fnmatch() 0: match, 1: no match*/
53725+
53726+static int
53727+glob_match(const char *p, const char *n)
53728+{
53729+ char c;
53730+
53731+ while ((c = *p++) != '\0') {
53732+ switch (c) {
53733+ case '?':
53734+ if (*n == '\0')
53735+ return 1;
53736+ else if (*n == '/')
53737+ return 1;
53738+ break;
53739+ case '\\':
53740+ if (*n != c)
53741+ return 1;
53742+ break;
53743+ case '*':
53744+ for (c = *p++; c == '?' || c == '*'; c = *p++) {
53745+ if (*n == '/')
53746+ return 1;
53747+ else if (c == '?') {
53748+ if (*n == '\0')
53749+ return 1;
53750+ else
53751+ ++n;
53752+ }
53753+ }
53754+ if (c == '\0') {
53755+ return 0;
53756+ } else {
53757+ const char *endp;
53758+
53759+ if ((endp = strchr(n, '/')) == NULL)
53760+ endp = n + strlen(n);
53761+
53762+ if (c == '[') {
53763+ for (--p; n < endp; ++n)
53764+ if (!glob_match(p, n))
53765+ return 0;
53766+ } else if (c == '/') {
53767+ while (*n != '\0' && *n != '/')
53768+ ++n;
53769+ if (*n == '/' && !glob_match(p, n + 1))
53770+ return 0;
53771+ } else {
53772+ for (--p; n < endp; ++n)
53773+ if (*n == c && !glob_match(p, n))
53774+ return 0;
53775+ }
53776+
53777+ return 1;
53778+ }
53779+ case '[':
53780+ {
53781+ int not;
53782+ char cold;
53783+
53784+ if (*n == '\0' || *n == '/')
53785+ return 1;
53786+
53787+ not = (*p == '!' || *p == '^');
53788+ if (not)
53789+ ++p;
53790+
53791+ c = *p++;
53792+ for (;;) {
53793+ unsigned char fn = (unsigned char)*n;
53794+
53795+ if (c == '\0')
53796+ return 1;
53797+ else {
53798+ if (c == fn)
53799+ goto matched;
53800+ cold = c;
53801+ c = *p++;
53802+
53803+ if (c == '-' && *p != ']') {
53804+ unsigned char cend = *p++;
53805+
53806+ if (cend == '\0')
53807+ return 1;
53808+
53809+ if (cold <= fn && fn <= cend)
53810+ goto matched;
53811+
53812+ c = *p++;
53813+ }
53814+ }
53815+
53816+ if (c == ']')
53817+ break;
53818+ }
53819+ if (!not)
53820+ return 1;
53821+ break;
53822+ matched:
53823+ while (c != ']') {
53824+ if (c == '\0')
53825+ return 1;
53826+
53827+ c = *p++;
53828+ }
53829+ if (not)
53830+ return 1;
53831+ }
53832+ break;
53833+ default:
53834+ if (c != *n)
53835+ return 1;
53836+ }
53837+
53838+ ++n;
53839+ }
53840+
53841+ if (*n == '\0')
53842+ return 0;
53843+
53844+ if (*n == '/')
53845+ return 0;
53846+
53847+ return 1;
53848+}
53849+
53850+static struct acl_object_label *
53851+chk_glob_label(struct acl_object_label *globbed,
53852+ const struct dentry *dentry, const struct vfsmount *mnt, char **path)
53853+{
53854+ struct acl_object_label *tmp;
53855+
53856+ if (*path == NULL)
53857+ *path = gr_to_filename_nolock(dentry, mnt);
53858+
53859+ tmp = globbed;
53860+
53861+ while (tmp) {
53862+ if (!glob_match(tmp->filename, *path))
53863+ return tmp;
53864+ tmp = tmp->next;
53865+ }
53866+
53867+ return NULL;
53868+}
53869+
53870+static struct acl_object_label *
53871+__full_lookup(const struct dentry *orig_dentry, const struct vfsmount *orig_mnt,
53872+ const ino_t curr_ino, const dev_t curr_dev,
53873+ const struct acl_subject_label *subj, char **path, const int checkglob)
53874+{
53875+ struct acl_subject_label *tmpsubj;
53876+ struct acl_object_label *retval;
53877+ struct acl_object_label *retval2;
53878+
53879+ tmpsubj = (struct acl_subject_label *) subj;
53880+ read_lock(&gr_inode_lock);
53881+ do {
53882+ retval = lookup_acl_obj_label(curr_ino, curr_dev, tmpsubj);
53883+ if (retval) {
53884+ if (checkglob && retval->globbed) {
53885+ retval2 = chk_glob_label(retval->globbed, orig_dentry, orig_mnt, path);
53886+ if (retval2)
53887+ retval = retval2;
53888+ }
53889+ break;
53890+ }
53891+ } while ((tmpsubj = tmpsubj->parent_subject));
53892+ read_unlock(&gr_inode_lock);
53893+
53894+ return retval;
53895+}
53896+
53897+static __inline__ struct acl_object_label *
53898+full_lookup(const struct dentry *orig_dentry, const struct vfsmount *orig_mnt,
53899+ struct dentry *curr_dentry,
53900+ const struct acl_subject_label *subj, char **path, const int checkglob)
53901+{
53902+ int newglob = checkglob;
53903+ ino_t inode;
53904+ dev_t device;
53905+
53906+ /* if we aren't checking a subdirectory of the original path yet, don't do glob checking
53907+ as we don't want a / * rule to match instead of the / object
53908+ don't do this for create lookups that call this function though, since they're looking up
53909+ on the parent and thus need globbing checks on all paths
53910+ */
53911+ if (orig_dentry == curr_dentry && newglob != GR_CREATE_GLOB)
53912+ newglob = GR_NO_GLOB;
53913+
53914+ spin_lock(&curr_dentry->d_lock);
53915+ inode = curr_dentry->d_inode->i_ino;
53916+ device = __get_dev(curr_dentry);
53917+ spin_unlock(&curr_dentry->d_lock);
53918+
53919+ return __full_lookup(orig_dentry, orig_mnt, inode, device, subj, path, newglob);
53920+}
53921+
53922+static struct acl_object_label *
53923+__chk_obj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
53924+ const struct acl_subject_label *subj, char *path, const int checkglob)
53925+{
53926+ struct dentry *dentry = (struct dentry *) l_dentry;
53927+ struct vfsmount *mnt = (struct vfsmount *) l_mnt;
53928+ struct mount *real_mnt = real_mount(mnt);
53929+ struct acl_object_label *retval;
53930+ struct dentry *parent;
53931+
53932+ write_seqlock(&rename_lock);
53933+ br_read_lock(&vfsmount_lock);
53934+
53935+ if (unlikely((mnt == shm_mnt && dentry->d_inode->i_nlink == 0) || mnt == pipe_mnt ||
53936+#ifdef CONFIG_NET
53937+ mnt == sock_mnt ||
53938+#endif
53939+#ifdef CONFIG_HUGETLBFS
53940+ (mnt == hugetlbfs_vfsmount && dentry->d_inode->i_nlink == 0) ||
53941+#endif
53942+ /* ignore Eric Biederman */
53943+ IS_PRIVATE(l_dentry->d_inode))) {
53944+ retval = (subj->mode & GR_SHMEXEC) ? fakefs_obj_rwx : fakefs_obj_rw;
53945+ goto out;
53946+ }
53947+
53948+ for (;;) {
53949+ if (dentry == real_root.dentry && mnt == real_root.mnt)
53950+ break;
53951+
53952+ if (dentry == mnt->mnt_root || IS_ROOT(dentry)) {
53953+ if (!mnt_has_parent(real_mnt))
53954+ break;
53955+
53956+ retval = full_lookup(l_dentry, l_mnt, dentry, subj, &path, checkglob);
53957+ if (retval != NULL)
53958+ goto out;
53959+
53960+ dentry = real_mnt->mnt_mountpoint;
53961+ real_mnt = real_mnt->mnt_parent;
53962+ mnt = &real_mnt->mnt;
53963+ continue;
53964+ }
53965+
53966+ parent = dentry->d_parent;
53967+ retval = full_lookup(l_dentry, l_mnt, dentry, subj, &path, checkglob);
53968+ if (retval != NULL)
53969+ goto out;
53970+
53971+ dentry = parent;
53972+ }
53973+
53974+ retval = full_lookup(l_dentry, l_mnt, dentry, subj, &path, checkglob);
53975+
53976+ /* real_root is pinned so we don't have to hold a reference */
53977+ if (retval == NULL)
53978+ retval = full_lookup(l_dentry, l_mnt, real_root.dentry, subj, &path, checkglob);
53979+out:
53980+ br_read_unlock(&vfsmount_lock);
53981+ write_sequnlock(&rename_lock);
53982+
53983+ BUG_ON(retval == NULL);
53984+
53985+ return retval;
53986+}
53987+
53988+static __inline__ struct acl_object_label *
53989+chk_obj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
53990+ const struct acl_subject_label *subj)
53991+{
53992+ char *path = NULL;
53993+ return __chk_obj_label(l_dentry, l_mnt, subj, path, GR_REG_GLOB);
53994+}
53995+
53996+static __inline__ struct acl_object_label *
53997+chk_obj_label_noglob(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
53998+ const struct acl_subject_label *subj)
53999+{
54000+ char *path = NULL;
54001+ return __chk_obj_label(l_dentry, l_mnt, subj, path, GR_NO_GLOB);
54002+}
54003+
54004+static __inline__ struct acl_object_label *
54005+chk_obj_create_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
54006+ const struct acl_subject_label *subj, char *path)
54007+{
54008+ return __chk_obj_label(l_dentry, l_mnt, subj, path, GR_CREATE_GLOB);
54009+}
54010+
54011+static struct acl_subject_label *
54012+chk_subj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
54013+ const struct acl_role_label *role)
54014+{
54015+ struct dentry *dentry = (struct dentry *) l_dentry;
54016+ struct vfsmount *mnt = (struct vfsmount *) l_mnt;
54017+ struct mount *real_mnt = real_mount(mnt);
54018+ struct acl_subject_label *retval;
54019+ struct dentry *parent;
54020+
54021+ write_seqlock(&rename_lock);
54022+ br_read_lock(&vfsmount_lock);
54023+
54024+ for (;;) {
54025+ if (dentry == real_root.dentry && mnt == real_root.mnt)
54026+ break;
54027+ if (dentry == mnt->mnt_root || IS_ROOT(dentry)) {
54028+ if (!mnt_has_parent(real_mnt))
54029+ break;
54030+
54031+ spin_lock(&dentry->d_lock);
54032+ read_lock(&gr_inode_lock);
54033+ retval =
54034+ lookup_acl_subj_label(dentry->d_inode->i_ino,
54035+ __get_dev(dentry), role);
54036+ read_unlock(&gr_inode_lock);
54037+ spin_unlock(&dentry->d_lock);
54038+ if (retval != NULL)
54039+ goto out;
54040+
54041+ dentry = real_mnt->mnt_mountpoint;
54042+ real_mnt = real_mnt->mnt_parent;
54043+ mnt = &real_mnt->mnt;
54044+ continue;
54045+ }
54046+
54047+ spin_lock(&dentry->d_lock);
54048+ read_lock(&gr_inode_lock);
54049+ retval = lookup_acl_subj_label(dentry->d_inode->i_ino,
54050+ __get_dev(dentry), role);
54051+ read_unlock(&gr_inode_lock);
54052+ parent = dentry->d_parent;
54053+ spin_unlock(&dentry->d_lock);
54054+
54055+ if (retval != NULL)
54056+ goto out;
54057+
54058+ dentry = parent;
54059+ }
54060+
54061+ spin_lock(&dentry->d_lock);
54062+ read_lock(&gr_inode_lock);
54063+ retval = lookup_acl_subj_label(dentry->d_inode->i_ino,
54064+ __get_dev(dentry), role);
54065+ read_unlock(&gr_inode_lock);
54066+ spin_unlock(&dentry->d_lock);
54067+
54068+ if (unlikely(retval == NULL)) {
54069+ /* real_root is pinned, we don't need to hold a reference */
54070+ read_lock(&gr_inode_lock);
54071+ retval = lookup_acl_subj_label(real_root.dentry->d_inode->i_ino,
54072+ __get_dev(real_root.dentry), role);
54073+ read_unlock(&gr_inode_lock);
54074+ }
54075+out:
54076+ br_read_unlock(&vfsmount_lock);
54077+ write_sequnlock(&rename_lock);
54078+
54079+ BUG_ON(retval == NULL);
54080+
54081+ return retval;
54082+}
54083+
54084+static void
54085+gr_log_learn(const struct dentry *dentry, const struct vfsmount *mnt, const __u32 mode)
54086+{
54087+ struct task_struct *task = current;
54088+ const struct cred *cred = current_cred();
54089+
54090+ security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename, task->role->roletype,
54091+ cred->uid, cred->gid, task->exec_file ? gr_to_filename1(task->exec_file->f_path.dentry,
54092+ task->exec_file->f_path.mnt) : task->acl->filename, task->acl->filename,
54093+ 1UL, 1UL, gr_to_filename(dentry, mnt), (unsigned long) mode, &task->signal->saved_ip);
54094+
54095+ return;
54096+}
54097+
54098+static void
54099+gr_log_learn_id_change(const char type, const unsigned int real,
54100+ const unsigned int effective, const unsigned int fs)
54101+{
54102+ struct task_struct *task = current;
54103+ const struct cred *cred = current_cred();
54104+
54105+ security_learn(GR_ID_LEARN_MSG, task->role->rolename, task->role->roletype,
54106+ cred->uid, cred->gid, task->exec_file ? gr_to_filename1(task->exec_file->f_path.dentry,
54107+ task->exec_file->f_path.mnt) : task->acl->filename, task->acl->filename,
54108+ type, real, effective, fs, &task->signal->saved_ip);
54109+
54110+ return;
54111+}
54112+
54113+__u32
54114+gr_search_file(const struct dentry * dentry, const __u32 mode,
54115+ const struct vfsmount * mnt)
54116+{
54117+ __u32 retval = mode;
54118+ struct acl_subject_label *curracl;
54119+ struct acl_object_label *currobj;
54120+
54121+ if (unlikely(!(gr_status & GR_READY)))
54122+ return (mode & ~GR_AUDITS);
54123+
54124+ curracl = current->acl;
54125+
54126+ currobj = chk_obj_label(dentry, mnt, curracl);
54127+ retval = currobj->mode & mode;
54128+
54129+ /* if we're opening a specified transfer file for writing
54130+ (e.g. /dev/initctl), then transfer our role to init
54131+ */
54132+ if (unlikely(currobj->mode & GR_INIT_TRANSFER && retval & GR_WRITE &&
54133+ current->role->roletype & GR_ROLE_PERSIST)) {
54134+ struct task_struct *task = init_pid_ns.child_reaper;
54135+
54136+ if (task->role != current->role) {
54137+ task->acl_sp_role = 0;
54138+ task->acl_role_id = current->acl_role_id;
54139+ task->role = current->role;
54140+ rcu_read_lock();
54141+ read_lock(&grsec_exec_file_lock);
54142+ gr_apply_subject_to_task(task);
54143+ read_unlock(&grsec_exec_file_lock);
54144+ rcu_read_unlock();
54145+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_INIT_TRANSFER_MSG);
54146+ }
54147+ }
54148+
54149+ if (unlikely
54150+ ((curracl->mode & (GR_LEARN | GR_INHERITLEARN)) && !(mode & GR_NOPTRACE)
54151+ && (retval != (mode & ~(GR_AUDITS | GR_SUPPRESS))))) {
54152+ __u32 new_mode = mode;
54153+
54154+ new_mode &= ~(GR_AUDITS | GR_SUPPRESS);
54155+
54156+ retval = new_mode;
54157+
54158+ if (new_mode & GR_EXEC && curracl->mode & GR_INHERITLEARN)
54159+ new_mode |= GR_INHERIT;
54160+
54161+ if (!(mode & GR_NOLEARN))
54162+ gr_log_learn(dentry, mnt, new_mode);
54163+ }
54164+
54165+ return retval;
54166+}
54167+
54168+struct acl_object_label *gr_get_create_object(const struct dentry *new_dentry,
54169+ const struct dentry *parent,
54170+ const struct vfsmount *mnt)
54171+{
54172+ struct name_entry *match;
54173+ struct acl_object_label *matchpo;
54174+ struct acl_subject_label *curracl;
54175+ char *path;
54176+
54177+ if (unlikely(!(gr_status & GR_READY)))
54178+ return NULL;
54179+
54180+ preempt_disable();
54181+ path = gr_to_filename_rbac(new_dentry, mnt);
54182+ match = lookup_name_entry_create(path);
54183+
54184+ curracl = current->acl;
54185+
54186+ if (match) {
54187+ read_lock(&gr_inode_lock);
54188+ matchpo = lookup_acl_obj_label_create(match->inode, match->device, curracl);
54189+ read_unlock(&gr_inode_lock);
54190+
54191+ if (matchpo) {
54192+ preempt_enable();
54193+ return matchpo;
54194+ }
54195+ }
54196+
54197+ // lookup parent
54198+
54199+ matchpo = chk_obj_create_label(parent, mnt, curracl, path);
54200+
54201+ preempt_enable();
54202+ return matchpo;
54203+}
54204+
54205+__u32
54206+gr_check_create(const struct dentry * new_dentry, const struct dentry * parent,
54207+ const struct vfsmount * mnt, const __u32 mode)
54208+{
54209+ struct acl_object_label *matchpo;
54210+ __u32 retval;
54211+
54212+ if (unlikely(!(gr_status & GR_READY)))
54213+ return (mode & ~GR_AUDITS);
54214+
54215+ matchpo = gr_get_create_object(new_dentry, parent, mnt);
54216+
54217+ retval = matchpo->mode & mode;
54218+
54219+ if ((retval != (mode & ~(GR_AUDITS | GR_SUPPRESS)))
54220+ && (current->acl->mode & (GR_LEARN | GR_INHERITLEARN))) {
54221+ __u32 new_mode = mode;
54222+
54223+ new_mode &= ~(GR_AUDITS | GR_SUPPRESS);
54224+
54225+ gr_log_learn(new_dentry, mnt, new_mode);
54226+ return new_mode;
54227+ }
54228+
54229+ return retval;
54230+}
54231+
54232+__u32
54233+gr_check_link(const struct dentry * new_dentry,
54234+ const struct dentry * parent_dentry,
54235+ const struct vfsmount * parent_mnt,
54236+ const struct dentry * old_dentry, const struct vfsmount * old_mnt)
54237+{
54238+ struct acl_object_label *obj;
54239+ __u32 oldmode, newmode;
54240+ __u32 needmode;
54241+ __u32 checkmodes = GR_FIND | GR_APPEND | GR_WRITE | GR_EXEC | GR_SETID | GR_READ |
54242+ GR_DELETE | GR_INHERIT;
54243+
54244+ if (unlikely(!(gr_status & GR_READY)))
54245+ return (GR_CREATE | GR_LINK);
54246+
54247+ obj = chk_obj_label(old_dentry, old_mnt, current->acl);
54248+ oldmode = obj->mode;
54249+
54250+ obj = gr_get_create_object(new_dentry, parent_dentry, parent_mnt);
54251+ newmode = obj->mode;
54252+
54253+ needmode = newmode & checkmodes;
54254+
54255+ // old name for hardlink must have at least the permissions of the new name
54256+ if ((oldmode & needmode) != needmode)
54257+ goto bad;
54258+
54259+ // if old name had restrictions/auditing, make sure the new name does as well
54260+ needmode = oldmode & (GR_NOPTRACE | GR_PTRACERD | GR_INHERIT | GR_AUDITS);
54261+
54262+ // don't allow hardlinking of suid/sgid/fcapped files without permission
54263+ if (is_privileged_binary(old_dentry))
54264+ needmode |= GR_SETID;
54265+
54266+ if ((newmode & needmode) != needmode)
54267+ goto bad;
54268+
54269+ // enforce minimum permissions
54270+ if ((newmode & (GR_CREATE | GR_LINK)) == (GR_CREATE | GR_LINK))
54271+ return newmode;
54272+bad:
54273+ needmode = oldmode;
54274+ if (is_privileged_binary(old_dentry))
54275+ needmode |= GR_SETID;
54276+
54277+ if (current->acl->mode & (GR_LEARN | GR_INHERITLEARN)) {
54278+ gr_log_learn(old_dentry, old_mnt, needmode | GR_CREATE | GR_LINK);
54279+ return (GR_CREATE | GR_LINK);
54280+ } else if (newmode & GR_SUPPRESS)
54281+ return GR_SUPPRESS;
54282+ else
54283+ return 0;
54284+}
54285+
54286+int
54287+gr_check_hidden_task(const struct task_struct *task)
54288+{
54289+ if (unlikely(!(gr_status & GR_READY)))
54290+ return 0;
54291+
54292+ if (!(task->acl->mode & GR_PROCFIND) && !(current->acl->mode & GR_VIEW))
54293+ return 1;
54294+
54295+ return 0;
54296+}
54297+
54298+int
54299+gr_check_protected_task(const struct task_struct *task)
54300+{
54301+ if (unlikely(!(gr_status & GR_READY) || !task))
54302+ return 0;
54303+
54304+ if ((task->acl->mode & GR_PROTECTED) && !(current->acl->mode & GR_KILL) &&
54305+ task->acl != current->acl)
54306+ return 1;
54307+
54308+ return 0;
54309+}
54310+
54311+int
54312+gr_check_protected_task_fowner(struct pid *pid, enum pid_type type)
54313+{
54314+ struct task_struct *p;
54315+ int ret = 0;
54316+
54317+ if (unlikely(!(gr_status & GR_READY) || !pid))
54318+ return ret;
54319+
54320+ read_lock(&tasklist_lock);
54321+ do_each_pid_task(pid, type, p) {
54322+ if ((p->acl->mode & GR_PROTECTED) && !(current->acl->mode & GR_KILL) &&
54323+ p->acl != current->acl) {
54324+ ret = 1;
54325+ goto out;
54326+ }
54327+ } while_each_pid_task(pid, type, p);
54328+out:
54329+ read_unlock(&tasklist_lock);
54330+
54331+ return ret;
54332+}
54333+
54334+void
54335+gr_copy_label(struct task_struct *tsk)
54336+{
54337+ tsk->signal->used_accept = 0;
54338+ tsk->acl_sp_role = 0;
54339+ tsk->acl_role_id = current->acl_role_id;
54340+ tsk->acl = current->acl;
54341+ tsk->role = current->role;
54342+ tsk->signal->curr_ip = current->signal->curr_ip;
54343+ tsk->signal->saved_ip = current->signal->saved_ip;
54344+ if (current->exec_file)
54345+ get_file(current->exec_file);
54346+ tsk->exec_file = current->exec_file;
54347+ tsk->is_writable = current->is_writable;
54348+ if (unlikely(current->signal->used_accept)) {
54349+ current->signal->curr_ip = 0;
54350+ current->signal->saved_ip = 0;
54351+ }
54352+
54353+ return;
54354+}
54355+
54356+static void
54357+gr_set_proc_res(struct task_struct *task)
54358+{
54359+ struct acl_subject_label *proc;
54360+ unsigned short i;
54361+
54362+ proc = task->acl;
54363+
54364+ if (proc->mode & (GR_LEARN | GR_INHERITLEARN))
54365+ return;
54366+
54367+ for (i = 0; i < RLIM_NLIMITS; i++) {
54368+ if (!(proc->resmask & (1 << i)))
54369+ continue;
54370+
54371+ task->signal->rlim[i].rlim_cur = proc->res[i].rlim_cur;
54372+ task->signal->rlim[i].rlim_max = proc->res[i].rlim_max;
54373+ }
54374+
54375+ return;
54376+}
54377+
54378+extern int __gr_process_user_ban(struct user_struct *user);
54379+
54380+int
54381+gr_check_user_change(int real, int effective, int fs)
54382+{
54383+ unsigned int i;
54384+ __u16 num;
54385+ uid_t *uidlist;
54386+ int curuid;
54387+ int realok = 0;
54388+ int effectiveok = 0;
54389+ int fsok = 0;
54390+
54391+#if defined(CONFIG_GRKERNSEC_KERN_LOCKOUT) || defined(CONFIG_GRKERNSEC_BRUTE)
54392+ struct user_struct *user;
54393+
54394+ if (real == -1)
54395+ goto skipit;
54396+
54397+ user = find_user(real);
54398+ if (user == NULL)
54399+ goto skipit;
54400+
54401+ if (__gr_process_user_ban(user)) {
54402+ /* for find_user */
54403+ free_uid(user);
54404+ return 1;
54405+ }
54406+
54407+ /* for find_user */
54408+ free_uid(user);
54409+
54410+skipit:
54411+#endif
54412+
54413+ if (unlikely(!(gr_status & GR_READY)))
54414+ return 0;
54415+
54416+ if (current->acl->mode & (GR_LEARN | GR_INHERITLEARN))
54417+ gr_log_learn_id_change('u', real, effective, fs);
54418+
54419+ num = current->acl->user_trans_num;
54420+ uidlist = current->acl->user_transitions;
54421+
54422+ if (uidlist == NULL)
54423+ return 0;
54424+
54425+ if (real == -1)
54426+ realok = 1;
54427+ if (effective == -1)
54428+ effectiveok = 1;
54429+ if (fs == -1)
54430+ fsok = 1;
54431+
54432+ if (current->acl->user_trans_type & GR_ID_ALLOW) {
54433+ for (i = 0; i < num; i++) {
54434+ curuid = (int)uidlist[i];
54435+ if (real == curuid)
54436+ realok = 1;
54437+ if (effective == curuid)
54438+ effectiveok = 1;
54439+ if (fs == curuid)
54440+ fsok = 1;
54441+ }
54442+ } else if (current->acl->user_trans_type & GR_ID_DENY) {
54443+ for (i = 0; i < num; i++) {
54444+ curuid = (int)uidlist[i];
54445+ if (real == curuid)
54446+ break;
54447+ if (effective == curuid)
54448+ break;
54449+ if (fs == curuid)
54450+ break;
54451+ }
54452+ /* not in deny list */
54453+ if (i == num) {
54454+ realok = 1;
54455+ effectiveok = 1;
54456+ fsok = 1;
54457+ }
54458+ }
54459+
54460+ if (realok && effectiveok && fsok)
54461+ return 0;
54462+ else {
54463+ gr_log_int(GR_DONT_AUDIT, GR_USRCHANGE_ACL_MSG, realok ? (effectiveok ? (fsok ? 0 : fs) : effective) : real);
54464+ return 1;
54465+ }
54466+}
54467+
54468+int
54469+gr_check_group_change(int real, int effective, int fs)
54470+{
54471+ unsigned int i;
54472+ __u16 num;
54473+ gid_t *gidlist;
54474+ int curgid;
54475+ int realok = 0;
54476+ int effectiveok = 0;
54477+ int fsok = 0;
54478+
54479+ if (unlikely(!(gr_status & GR_READY)))
54480+ return 0;
54481+
54482+ if (current->acl->mode & (GR_LEARN | GR_INHERITLEARN))
54483+ gr_log_learn_id_change('g', real, effective, fs);
54484+
54485+ num = current->acl->group_trans_num;
54486+ gidlist = current->acl->group_transitions;
54487+
54488+ if (gidlist == NULL)
54489+ return 0;
54490+
54491+ if (real == -1)
54492+ realok = 1;
54493+ if (effective == -1)
54494+ effectiveok = 1;
54495+ if (fs == -1)
54496+ fsok = 1;
54497+
54498+ if (current->acl->group_trans_type & GR_ID_ALLOW) {
54499+ for (i = 0; i < num; i++) {
54500+ curgid = (int)gidlist[i];
54501+ if (real == curgid)
54502+ realok = 1;
54503+ if (effective == curgid)
54504+ effectiveok = 1;
54505+ if (fs == curgid)
54506+ fsok = 1;
54507+ }
54508+ } else if (current->acl->group_trans_type & GR_ID_DENY) {
54509+ for (i = 0; i < num; i++) {
54510+ curgid = (int)gidlist[i];
54511+ if (real == curgid)
54512+ break;
54513+ if (effective == curgid)
54514+ break;
54515+ if (fs == curgid)
54516+ break;
54517+ }
54518+ /* not in deny list */
54519+ if (i == num) {
54520+ realok = 1;
54521+ effectiveok = 1;
54522+ fsok = 1;
54523+ }
54524+ }
54525+
54526+ if (realok && effectiveok && fsok)
54527+ return 0;
54528+ else {
54529+ gr_log_int(GR_DONT_AUDIT, GR_GRPCHANGE_ACL_MSG, realok ? (effectiveok ? (fsok ? 0 : fs) : effective) : real);
54530+ return 1;
54531+ }
54532+}
54533+
54534+extern int gr_acl_is_capable(const int cap);
54535+
54536+void
54537+gr_set_role_label(struct task_struct *task, const uid_t uid, const uid_t gid)
54538+{
54539+ struct acl_role_label *role = task->role;
54540+ struct acl_subject_label *subj = NULL;
54541+ struct acl_object_label *obj;
54542+ struct file *filp;
54543+
54544+ if (unlikely(!(gr_status & GR_READY)))
54545+ return;
54546+
54547+ filp = task->exec_file;
54548+
54549+ /* kernel process, we'll give them the kernel role */
54550+ if (unlikely(!filp)) {
54551+ task->role = kernel_role;
54552+ task->acl = kernel_role->root_label;
54553+ return;
54554+ } else if (!task->role || !(task->role->roletype & GR_ROLE_SPECIAL))
54555+ role = lookup_acl_role_label(task, uid, gid);
54556+
54557+ /* don't change the role if we're not a privileged process */
54558+ if (role && task->role != role &&
54559+ (((role->roletype & GR_ROLE_USER) && !gr_acl_is_capable(CAP_SETUID)) ||
54560+ ((role->roletype & GR_ROLE_GROUP) && !gr_acl_is_capable(CAP_SETGID))))
54561+ return;
54562+
54563+ /* perform subject lookup in possibly new role
54564+ we can use this result below in the case where role == task->role
54565+ */
54566+ subj = chk_subj_label(filp->f_path.dentry, filp->f_path.mnt, role);
54567+
54568+ /* if we changed uid/gid, but result in the same role
54569+ and are using inheritance, don't lose the inherited subject
54570+ if current subject is other than what normal lookup
54571+ would result in, we arrived via inheritance, don't
54572+ lose subject
54573+ */
54574+ if (role != task->role || (!(task->acl->mode & GR_INHERITLEARN) &&
54575+ (subj == task->acl)))
54576+ task->acl = subj;
54577+
54578+ task->role = role;
54579+
54580+ task->is_writable = 0;
54581+
54582+ /* ignore additional mmap checks for processes that are writable
54583+ by the default ACL */
54584+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, default_role->root_label);
54585+ if (unlikely(obj->mode & GR_WRITE))
54586+ task->is_writable = 1;
54587+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, task->role->root_label);
54588+ if (unlikely(obj->mode & GR_WRITE))
54589+ task->is_writable = 1;
54590+
54591+#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
54592+ printk(KERN_ALERT "Set role label for (%s:%d): role:%s, subject:%s\n", task->comm, task->pid, task->role->rolename, task->acl->filename);
54593+#endif
54594+
54595+ gr_set_proc_res(task);
54596+
54597+ return;
54598+}
54599+
54600+int
54601+gr_set_proc_label(const struct dentry *dentry, const struct vfsmount *mnt,
54602+ const int unsafe_flags)
54603+{
54604+ struct task_struct *task = current;
54605+ struct acl_subject_label *newacl;
54606+ struct acl_object_label *obj;
54607+ __u32 retmode;
54608+
54609+ if (unlikely(!(gr_status & GR_READY)))
54610+ return 0;
54611+
54612+ newacl = chk_subj_label(dentry, mnt, task->role);
54613+
54614+ /* special handling for if we did an strace -f -p <pid> from an admin role, where pid then
54615+ did an exec
54616+ */
54617+ rcu_read_lock();
54618+ read_lock(&tasklist_lock);
54619+ if (task->ptrace && task->parent && ((task->parent->role->roletype & GR_ROLE_GOD) ||
54620+ (task->parent->acl->mode & GR_POVERRIDE))) {
54621+ read_unlock(&tasklist_lock);
54622+ rcu_read_unlock();
54623+ goto skip_check;
54624+ }
54625+ read_unlock(&tasklist_lock);
54626+ rcu_read_unlock();
54627+
54628+ if (unsafe_flags && !(task->acl->mode & GR_POVERRIDE) && (task->acl != newacl) &&
54629+ !(task->role->roletype & GR_ROLE_GOD) &&
54630+ !gr_search_file(dentry, GR_PTRACERD, mnt) &&
54631+ !(task->acl->mode & (GR_LEARN | GR_INHERITLEARN))) {
54632+ if (unsafe_flags & LSM_UNSAFE_SHARE)
54633+ gr_log_fs_generic(GR_DONT_AUDIT, GR_UNSAFESHARE_EXEC_ACL_MSG, dentry, mnt);
54634+ else
54635+ gr_log_fs_generic(GR_DONT_AUDIT, GR_PTRACE_EXEC_ACL_MSG, dentry, mnt);
54636+ return -EACCES;
54637+ }
54638+
54639+skip_check:
54640+
54641+ obj = chk_obj_label(dentry, mnt, task->acl);
54642+ retmode = obj->mode & (GR_INHERIT | GR_AUDIT_INHERIT);
54643+
54644+ if (!(task->acl->mode & GR_INHERITLEARN) &&
54645+ ((newacl->mode & GR_LEARN) || !(retmode & GR_INHERIT))) {
54646+ if (obj->nested)
54647+ task->acl = obj->nested;
54648+ else
54649+ task->acl = newacl;
54650+ } else if (retmode & GR_INHERIT && retmode & GR_AUDIT_INHERIT)
54651+ gr_log_str_fs(GR_DO_AUDIT, GR_INHERIT_ACL_MSG, task->acl->filename, dentry, mnt);
54652+
54653+ task->is_writable = 0;
54654+
54655+ /* ignore additional mmap checks for processes that are writable
54656+ by the default ACL */
54657+ obj = chk_obj_label(dentry, mnt, default_role->root_label);
54658+ if (unlikely(obj->mode & GR_WRITE))
54659+ task->is_writable = 1;
54660+ obj = chk_obj_label(dentry, mnt, task->role->root_label);
54661+ if (unlikely(obj->mode & GR_WRITE))
54662+ task->is_writable = 1;
54663+
54664+ gr_set_proc_res(task);
54665+
54666+#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
54667+ printk(KERN_ALERT "Set subject label for (%s:%d): role:%s, subject:%s\n", task->comm, task->pid, task->role->rolename, task->acl->filename);
54668+#endif
54669+ return 0;
54670+}
54671+
54672+/* always called with valid inodev ptr */
54673+static void
54674+do_handle_delete(struct inodev_entry *inodev, const ino_t ino, const dev_t dev)
54675+{
54676+ struct acl_object_label *matchpo;
54677+ struct acl_subject_label *matchps;
54678+ struct acl_subject_label *subj;
54679+ struct acl_role_label *role;
54680+ unsigned int x;
54681+
54682+ FOR_EACH_ROLE_START(role)
54683+ FOR_EACH_SUBJECT_START(role, subj, x)
54684+ if ((matchpo = lookup_acl_obj_label(ino, dev, subj)) != NULL)
54685+ matchpo->mode |= GR_DELETED;
54686+ FOR_EACH_SUBJECT_END(subj,x)
54687+ FOR_EACH_NESTED_SUBJECT_START(role, subj)
54688+ /* nested subjects aren't in the role's subj_hash table */
54689+ if ((matchpo = lookup_acl_obj_label(ino, dev, subj)) != NULL)
54690+ matchpo->mode |= GR_DELETED;
54691+ FOR_EACH_NESTED_SUBJECT_END(subj)
54692+ if ((matchps = lookup_acl_subj_label(ino, dev, role)) != NULL)
54693+ matchps->mode |= GR_DELETED;
54694+ FOR_EACH_ROLE_END(role)
54695+
54696+ inodev->nentry->deleted = 1;
54697+
54698+ return;
54699+}
54700+
54701+void
54702+gr_handle_delete(const ino_t ino, const dev_t dev)
54703+{
54704+ struct inodev_entry *inodev;
54705+
54706+ if (unlikely(!(gr_status & GR_READY)))
54707+ return;
54708+
54709+ write_lock(&gr_inode_lock);
54710+ inodev = lookup_inodev_entry(ino, dev);
54711+ if (inodev != NULL)
54712+ do_handle_delete(inodev, ino, dev);
54713+ write_unlock(&gr_inode_lock);
54714+
54715+ return;
54716+}
54717+
54718+static void
54719+update_acl_obj_label(const ino_t oldinode, const dev_t olddevice,
54720+ const ino_t newinode, const dev_t newdevice,
54721+ struct acl_subject_label *subj)
54722+{
54723+ unsigned int index = fhash(oldinode, olddevice, subj->obj_hash_size);
54724+ struct acl_object_label *match;
54725+
54726+ match = subj->obj_hash[index];
54727+
54728+ while (match && (match->inode != oldinode ||
54729+ match->device != olddevice ||
54730+ !(match->mode & GR_DELETED)))
54731+ match = match->next;
54732+
54733+ if (match && (match->inode == oldinode)
54734+ && (match->device == olddevice)
54735+ && (match->mode & GR_DELETED)) {
54736+ if (match->prev == NULL) {
54737+ subj->obj_hash[index] = match->next;
54738+ if (match->next != NULL)
54739+ match->next->prev = NULL;
54740+ } else {
54741+ match->prev->next = match->next;
54742+ if (match->next != NULL)
54743+ match->next->prev = match->prev;
54744+ }
54745+ match->prev = NULL;
54746+ match->next = NULL;
54747+ match->inode = newinode;
54748+ match->device = newdevice;
54749+ match->mode &= ~GR_DELETED;
54750+
54751+ insert_acl_obj_label(match, subj);
54752+ }
54753+
54754+ return;
54755+}
54756+
54757+static void
54758+update_acl_subj_label(const ino_t oldinode, const dev_t olddevice,
54759+ const ino_t newinode, const dev_t newdevice,
54760+ struct acl_role_label *role)
54761+{
54762+ unsigned int index = fhash(oldinode, olddevice, role->subj_hash_size);
54763+ struct acl_subject_label *match;
54764+
54765+ match = role->subj_hash[index];
54766+
54767+ while (match && (match->inode != oldinode ||
54768+ match->device != olddevice ||
54769+ !(match->mode & GR_DELETED)))
54770+ match = match->next;
54771+
54772+ if (match && (match->inode == oldinode)
54773+ && (match->device == olddevice)
54774+ && (match->mode & GR_DELETED)) {
54775+ if (match->prev == NULL) {
54776+ role->subj_hash[index] = match->next;
54777+ if (match->next != NULL)
54778+ match->next->prev = NULL;
54779+ } else {
54780+ match->prev->next = match->next;
54781+ if (match->next != NULL)
54782+ match->next->prev = match->prev;
54783+ }
54784+ match->prev = NULL;
54785+ match->next = NULL;
54786+ match->inode = newinode;
54787+ match->device = newdevice;
54788+ match->mode &= ~GR_DELETED;
54789+
54790+ insert_acl_subj_label(match, role);
54791+ }
54792+
54793+ return;
54794+}
54795+
54796+static void
54797+update_inodev_entry(const ino_t oldinode, const dev_t olddevice,
54798+ const ino_t newinode, const dev_t newdevice)
54799+{
54800+ unsigned int index = fhash(oldinode, olddevice, inodev_set.i_size);
54801+ struct inodev_entry *match;
54802+
54803+ match = inodev_set.i_hash[index];
54804+
54805+ while (match && (match->nentry->inode != oldinode ||
54806+ match->nentry->device != olddevice || !match->nentry->deleted))
54807+ match = match->next;
54808+
54809+ if (match && (match->nentry->inode == oldinode)
54810+ && (match->nentry->device == olddevice) &&
54811+ match->nentry->deleted) {
54812+ if (match->prev == NULL) {
54813+ inodev_set.i_hash[index] = match->next;
54814+ if (match->next != NULL)
54815+ match->next->prev = NULL;
54816+ } else {
54817+ match->prev->next = match->next;
54818+ if (match->next != NULL)
54819+ match->next->prev = match->prev;
54820+ }
54821+ match->prev = NULL;
54822+ match->next = NULL;
54823+ match->nentry->inode = newinode;
54824+ match->nentry->device = newdevice;
54825+ match->nentry->deleted = 0;
54826+
54827+ insert_inodev_entry(match);
54828+ }
54829+
54830+ return;
54831+}
54832+
54833+static void
54834+__do_handle_create(const struct name_entry *matchn, ino_t ino, dev_t dev)
54835+{
54836+ struct acl_subject_label *subj;
54837+ struct acl_role_label *role;
54838+ unsigned int x;
54839+
54840+ FOR_EACH_ROLE_START(role)
54841+ update_acl_subj_label(matchn->inode, matchn->device, ino, dev, role);
54842+
54843+ FOR_EACH_NESTED_SUBJECT_START(role, subj)
54844+ if ((subj->inode == ino) && (subj->device == dev)) {
54845+ subj->inode = ino;
54846+ subj->device = dev;
54847+ }
54848+ /* nested subjects aren't in the role's subj_hash table */
54849+ update_acl_obj_label(matchn->inode, matchn->device,
54850+ ino, dev, subj);
54851+ FOR_EACH_NESTED_SUBJECT_END(subj)
54852+ FOR_EACH_SUBJECT_START(role, subj, x)
54853+ update_acl_obj_label(matchn->inode, matchn->device,
54854+ ino, dev, subj);
54855+ FOR_EACH_SUBJECT_END(subj,x)
54856+ FOR_EACH_ROLE_END(role)
54857+
54858+ update_inodev_entry(matchn->inode, matchn->device, ino, dev);
54859+
54860+ return;
54861+}
54862+
54863+static void
54864+do_handle_create(const struct name_entry *matchn, const struct dentry *dentry,
54865+ const struct vfsmount *mnt)
54866+{
54867+ ino_t ino = dentry->d_inode->i_ino;
54868+ dev_t dev = __get_dev(dentry);
54869+
54870+ __do_handle_create(matchn, ino, dev);
54871+
54872+ return;
54873+}
54874+
54875+void
54876+gr_handle_create(const struct dentry *dentry, const struct vfsmount *mnt)
54877+{
54878+ struct name_entry *matchn;
54879+
54880+ if (unlikely(!(gr_status & GR_READY)))
54881+ return;
54882+
54883+ preempt_disable();
54884+ matchn = lookup_name_entry(gr_to_filename_rbac(dentry, mnt));
54885+
54886+ if (unlikely((unsigned long)matchn)) {
54887+ write_lock(&gr_inode_lock);
54888+ do_handle_create(matchn, dentry, mnt);
54889+ write_unlock(&gr_inode_lock);
54890+ }
54891+ preempt_enable();
54892+
54893+ return;
54894+}
54895+
54896+void
54897+gr_handle_proc_create(const struct dentry *dentry, const struct inode *inode)
54898+{
54899+ struct name_entry *matchn;
54900+
54901+ if (unlikely(!(gr_status & GR_READY)))
54902+ return;
54903+
54904+ preempt_disable();
54905+ matchn = lookup_name_entry(gr_to_proc_filename_rbac(dentry, init_pid_ns.proc_mnt));
54906+
54907+ if (unlikely((unsigned long)matchn)) {
54908+ write_lock(&gr_inode_lock);
54909+ __do_handle_create(matchn, inode->i_ino, inode->i_sb->s_dev);
54910+ write_unlock(&gr_inode_lock);
54911+ }
54912+ preempt_enable();
54913+
54914+ return;
54915+}
54916+
54917+void
54918+gr_handle_rename(struct inode *old_dir, struct inode *new_dir,
54919+ struct dentry *old_dentry,
54920+ struct dentry *new_dentry,
54921+ struct vfsmount *mnt, const __u8 replace)
54922+{
54923+ struct name_entry *matchn;
54924+ struct inodev_entry *inodev;
54925+ struct inode *inode = new_dentry->d_inode;
54926+ ino_t old_ino = old_dentry->d_inode->i_ino;
54927+ dev_t old_dev = __get_dev(old_dentry);
54928+
54929+ /* vfs_rename swaps the name and parent link for old_dentry and
54930+ new_dentry
54931+ at this point, old_dentry has the new name, parent link, and inode
54932+ for the renamed file
54933+ if a file is being replaced by a rename, new_dentry has the inode
54934+ and name for the replaced file
54935+ */
54936+
54937+ if (unlikely(!(gr_status & GR_READY)))
54938+ return;
54939+
54940+ preempt_disable();
54941+ matchn = lookup_name_entry(gr_to_filename_rbac(old_dentry, mnt));
54942+
54943+ /* we wouldn't have to check d_inode if it weren't for
54944+ NFS silly-renaming
54945+ */
54946+
54947+ write_lock(&gr_inode_lock);
54948+ if (unlikely(replace && inode)) {
54949+ ino_t new_ino = inode->i_ino;
54950+ dev_t new_dev = __get_dev(new_dentry);
54951+
54952+ inodev = lookup_inodev_entry(new_ino, new_dev);
54953+ if (inodev != NULL && ((inode->i_nlink <= 1) || S_ISDIR(inode->i_mode)))
54954+ do_handle_delete(inodev, new_ino, new_dev);
54955+ }
54956+
54957+ inodev = lookup_inodev_entry(old_ino, old_dev);
54958+ if (inodev != NULL && ((old_dentry->d_inode->i_nlink <= 1) || S_ISDIR(old_dentry->d_inode->i_mode)))
54959+ do_handle_delete(inodev, old_ino, old_dev);
54960+
54961+ if (unlikely((unsigned long)matchn))
54962+ do_handle_create(matchn, old_dentry, mnt);
54963+
54964+ write_unlock(&gr_inode_lock);
54965+ preempt_enable();
54966+
54967+ return;
54968+}
54969+
54970+static int
54971+lookup_special_role_auth(__u16 mode, const char *rolename, unsigned char **salt,
54972+ unsigned char **sum)
54973+{
54974+ struct acl_role_label *r;
54975+ struct role_allowed_ip *ipp;
54976+ struct role_transition *trans;
54977+ unsigned int i;
54978+ int found = 0;
54979+ u32 curr_ip = current->signal->curr_ip;
54980+
54981+ current->signal->saved_ip = curr_ip;
54982+
54983+ /* check transition table */
54984+
54985+ for (trans = current->role->transitions; trans; trans = trans->next) {
54986+ if (!strcmp(rolename, trans->rolename)) {
54987+ found = 1;
54988+ break;
54989+ }
54990+ }
54991+
54992+ if (!found)
54993+ return 0;
54994+
54995+ /* handle special roles that do not require authentication
54996+ and check ip */
54997+
54998+ FOR_EACH_ROLE_START(r)
54999+ if (!strcmp(rolename, r->rolename) &&
55000+ (r->roletype & GR_ROLE_SPECIAL)) {
55001+ found = 0;
55002+ if (r->allowed_ips != NULL) {
55003+ for (ipp = r->allowed_ips; ipp; ipp = ipp->next) {
55004+ if ((ntohl(curr_ip) & ipp->netmask) ==
55005+ (ntohl(ipp->addr) & ipp->netmask))
55006+ found = 1;
55007+ }
55008+ } else
55009+ found = 2;
55010+ if (!found)
55011+ return 0;
55012+
55013+ if (((mode == GR_SPROLE) && (r->roletype & GR_ROLE_NOPW)) ||
55014+ ((mode == GR_SPROLEPAM) && (r->roletype & GR_ROLE_PAM))) {
55015+ *salt = NULL;
55016+ *sum = NULL;
55017+ return 1;
55018+ }
55019+ }
55020+ FOR_EACH_ROLE_END(r)
55021+
55022+ for (i = 0; i < num_sprole_pws; i++) {
55023+ if (!strcmp(rolename, acl_special_roles[i]->rolename)) {
55024+ *salt = acl_special_roles[i]->salt;
55025+ *sum = acl_special_roles[i]->sum;
55026+ return 1;
55027+ }
55028+ }
55029+
55030+ return 0;
55031+}
55032+
55033+static void
55034+assign_special_role(char *rolename)
55035+{
55036+ struct acl_object_label *obj;
55037+ struct acl_role_label *r;
55038+ struct acl_role_label *assigned = NULL;
55039+ struct task_struct *tsk;
55040+ struct file *filp;
55041+
55042+ FOR_EACH_ROLE_START(r)
55043+ if (!strcmp(rolename, r->rolename) &&
55044+ (r->roletype & GR_ROLE_SPECIAL)) {
55045+ assigned = r;
55046+ break;
55047+ }
55048+ FOR_EACH_ROLE_END(r)
55049+
55050+ if (!assigned)
55051+ return;
55052+
55053+ read_lock(&tasklist_lock);
55054+ read_lock(&grsec_exec_file_lock);
55055+
55056+ tsk = current->real_parent;
55057+ if (tsk == NULL)
55058+ goto out_unlock;
55059+
55060+ filp = tsk->exec_file;
55061+ if (filp == NULL)
55062+ goto out_unlock;
55063+
55064+ tsk->is_writable = 0;
55065+
55066+ tsk->acl_sp_role = 1;
55067+ tsk->acl_role_id = ++acl_sp_role_value;
55068+ tsk->role = assigned;
55069+ tsk->acl = chk_subj_label(filp->f_path.dentry, filp->f_path.mnt, tsk->role);
55070+
55071+ /* ignore additional mmap checks for processes that are writable
55072+ by the default ACL */
55073+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, default_role->root_label);
55074+ if (unlikely(obj->mode & GR_WRITE))
55075+ tsk->is_writable = 1;
55076+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, tsk->role->root_label);
55077+ if (unlikely(obj->mode & GR_WRITE))
55078+ tsk->is_writable = 1;
55079+
55080+#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
55081+ printk(KERN_ALERT "Assigning special role:%s subject:%s to process (%s:%d)\n", tsk->role->rolename, tsk->acl->filename, tsk->comm, tsk->pid);
55082+#endif
55083+
55084+out_unlock:
55085+ read_unlock(&grsec_exec_file_lock);
55086+ read_unlock(&tasklist_lock);
55087+ return;
55088+}
55089+
55090+int gr_check_secure_terminal(struct task_struct *task)
55091+{
55092+ struct task_struct *p, *p2, *p3;
55093+ struct files_struct *files;
55094+ struct fdtable *fdt;
55095+ struct file *our_file = NULL, *file;
55096+ int i;
55097+
55098+ if (task->signal->tty == NULL)
55099+ return 1;
55100+
55101+ files = get_files_struct(task);
55102+ if (files != NULL) {
55103+ rcu_read_lock();
55104+ fdt = files_fdtable(files);
55105+ for (i=0; i < fdt->max_fds; i++) {
55106+ file = fcheck_files(files, i);
55107+ if (file && (our_file == NULL) && (file->private_data == task->signal->tty)) {
55108+ get_file(file);
55109+ our_file = file;
55110+ }
55111+ }
55112+ rcu_read_unlock();
55113+ put_files_struct(files);
55114+ }
55115+
55116+ if (our_file == NULL)
55117+ return 1;
55118+
55119+ read_lock(&tasklist_lock);
55120+ do_each_thread(p2, p) {
55121+ files = get_files_struct(p);
55122+ if (files == NULL ||
55123+ (p->signal && p->signal->tty == task->signal->tty)) {
55124+ if (files != NULL)
55125+ put_files_struct(files);
55126+ continue;
55127+ }
55128+ rcu_read_lock();
55129+ fdt = files_fdtable(files);
55130+ for (i=0; i < fdt->max_fds; i++) {
55131+ file = fcheck_files(files, i);
55132+ if (file && S_ISCHR(file->f_path.dentry->d_inode->i_mode) &&
55133+ file->f_path.dentry->d_inode->i_rdev == our_file->f_path.dentry->d_inode->i_rdev) {
55134+ p3 = task;
55135+ while (p3->pid > 0) {
55136+ if (p3 == p)
55137+ break;
55138+ p3 = p3->real_parent;
55139+ }
55140+ if (p3 == p)
55141+ break;
55142+ gr_log_ttysniff(GR_DONT_AUDIT_GOOD, GR_TTYSNIFF_ACL_MSG, p);
55143+ gr_handle_alertkill(p);
55144+ rcu_read_unlock();
55145+ put_files_struct(files);
55146+ read_unlock(&tasklist_lock);
55147+ fput(our_file);
55148+ return 0;
55149+ }
55150+ }
55151+ rcu_read_unlock();
55152+ put_files_struct(files);
55153+ } while_each_thread(p2, p);
55154+ read_unlock(&tasklist_lock);
55155+
55156+ fput(our_file);
55157+ return 1;
55158+}
55159+
55160+static int gr_rbac_disable(void *unused)
55161+{
55162+ pax_open_kernel();
55163+ gr_status &= ~GR_READY;
55164+ pax_close_kernel();
55165+
55166+ return 0;
55167+}
55168+
55169+ssize_t
55170+write_grsec_handler(struct file *file, const char * buf, size_t count, loff_t *ppos)
55171+{
55172+ struct gr_arg_wrapper uwrap;
55173+ unsigned char *sprole_salt = NULL;
55174+ unsigned char *sprole_sum = NULL;
55175+ int error = sizeof (struct gr_arg_wrapper);
55176+ int error2 = 0;
55177+
55178+ mutex_lock(&gr_dev_mutex);
55179+
55180+ if ((gr_status & GR_READY) && !(current->acl->mode & GR_KERNELAUTH)) {
55181+ error = -EPERM;
55182+ goto out;
55183+ }
55184+
55185+ if (count != sizeof (struct gr_arg_wrapper)) {
55186+ gr_log_int_int(GR_DONT_AUDIT_GOOD, GR_DEV_ACL_MSG, (int)count, (int)sizeof(struct gr_arg_wrapper));
55187+ error = -EINVAL;
55188+ goto out;
55189+ }
55190+
55191+
55192+ if (gr_auth_expires && time_after_eq(get_seconds(), gr_auth_expires)) {
55193+ gr_auth_expires = 0;
55194+ gr_auth_attempts = 0;
55195+ }
55196+
55197+ if (copy_from_user(&uwrap, buf, sizeof (struct gr_arg_wrapper))) {
55198+ error = -EFAULT;
55199+ goto out;
55200+ }
55201+
55202+ if ((uwrap.version != GRSECURITY_VERSION) || (uwrap.size != sizeof(struct gr_arg))) {
55203+ error = -EINVAL;
55204+ goto out;
55205+ }
55206+
55207+ if (copy_from_user(gr_usermode, uwrap.arg, sizeof (struct gr_arg))) {
55208+ error = -EFAULT;
55209+ goto out;
55210+ }
55211+
55212+ if (gr_usermode->mode != GR_SPROLE && gr_usermode->mode != GR_SPROLEPAM &&
55213+ gr_auth_attempts >= CONFIG_GRKERNSEC_ACL_MAXTRIES &&
55214+ time_after(gr_auth_expires, get_seconds())) {
55215+ error = -EBUSY;
55216+ goto out;
55217+ }
55218+
55219+ /* if non-root trying to do anything other than use a special role,
55220+ do not attempt authentication, do not count towards authentication
55221+ locking
55222+ */
55223+
55224+ if (gr_usermode->mode != GR_SPROLE && gr_usermode->mode != GR_STATUS &&
55225+ gr_usermode->mode != GR_UNSPROLE && gr_usermode->mode != GR_SPROLEPAM &&
55226+ !uid_eq(current_uid(), GLOBAL_ROOT_UID)) {
55227+ error = -EPERM;
55228+ goto out;
55229+ }
55230+
55231+ /* ensure pw and special role name are null terminated */
55232+
55233+ gr_usermode->pw[GR_PW_LEN - 1] = '\0';
55234+ gr_usermode->sp_role[GR_SPROLE_LEN - 1] = '\0';
55235+
55236+ /* Okay.
55237+ * We have our enough of the argument structure..(we have yet
55238+ * to copy_from_user the tables themselves) . Copy the tables
55239+ * only if we need them, i.e. for loading operations. */
55240+
55241+ switch (gr_usermode->mode) {
55242+ case GR_STATUS:
55243+ if (gr_status & GR_READY) {
55244+ error = 1;
55245+ if (!gr_check_secure_terminal(current))
55246+ error = 3;
55247+ } else
55248+ error = 2;
55249+ goto out;
55250+ case GR_SHUTDOWN:
55251+ if ((gr_status & GR_READY)
55252+ && !(chkpw(gr_usermode, gr_system_salt, gr_system_sum))) {
55253+ stop_machine(gr_rbac_disable, NULL, NULL);
55254+ free_variables();
55255+ memset(gr_usermode, 0, sizeof (struct gr_arg));
55256+ memset(gr_system_salt, 0, GR_SALT_LEN);
55257+ memset(gr_system_sum, 0, GR_SHA_LEN);
55258+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SHUTS_ACL_MSG);
55259+ } else if (gr_status & GR_READY) {
55260+ gr_log_noargs(GR_DONT_AUDIT, GR_SHUTF_ACL_MSG);
55261+ error = -EPERM;
55262+ } else {
55263+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SHUTI_ACL_MSG);
55264+ error = -EAGAIN;
55265+ }
55266+ break;
55267+ case GR_ENABLE:
55268+ if (!(gr_status & GR_READY) && !(error2 = gracl_init(gr_usermode)))
55269+ gr_log_str(GR_DONT_AUDIT_GOOD, GR_ENABLE_ACL_MSG, GR_VERSION);
55270+ else {
55271+ if (gr_status & GR_READY)
55272+ error = -EAGAIN;
55273+ else
55274+ error = error2;
55275+ gr_log_str(GR_DONT_AUDIT, GR_ENABLEF_ACL_MSG, GR_VERSION);
55276+ }
55277+ break;
55278+ case GR_RELOAD:
55279+ if (!(gr_status & GR_READY)) {
55280+ gr_log_str(GR_DONT_AUDIT_GOOD, GR_RELOADI_ACL_MSG, GR_VERSION);
55281+ error = -EAGAIN;
55282+ } else if (!(chkpw(gr_usermode, gr_system_salt, gr_system_sum))) {
55283+ stop_machine(gr_rbac_disable, NULL, NULL);
55284+ free_variables();
55285+ error2 = gracl_init(gr_usermode);
55286+ if (!error2)
55287+ gr_log_str(GR_DONT_AUDIT_GOOD, GR_RELOAD_ACL_MSG, GR_VERSION);
55288+ else {
55289+ gr_log_str(GR_DONT_AUDIT, GR_RELOADF_ACL_MSG, GR_VERSION);
55290+ error = error2;
55291+ }
55292+ } else {
55293+ gr_log_str(GR_DONT_AUDIT, GR_RELOADF_ACL_MSG, GR_VERSION);
55294+ error = -EPERM;
55295+ }
55296+ break;
55297+ case GR_SEGVMOD:
55298+ if (unlikely(!(gr_status & GR_READY))) {
55299+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SEGVMODI_ACL_MSG);
55300+ error = -EAGAIN;
55301+ break;
55302+ }
55303+
55304+ if (!(chkpw(gr_usermode, gr_system_salt, gr_system_sum))) {
55305+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SEGVMODS_ACL_MSG);
55306+ if (gr_usermode->segv_device && gr_usermode->segv_inode) {
55307+ struct acl_subject_label *segvacl;
55308+ segvacl =
55309+ lookup_acl_subj_label(gr_usermode->segv_inode,
55310+ gr_usermode->segv_device,
55311+ current->role);
55312+ if (segvacl) {
55313+ segvacl->crashes = 0;
55314+ segvacl->expires = 0;
55315+ }
55316+ } else if (gr_find_uid(gr_usermode->segv_uid) >= 0) {
55317+ gr_remove_uid(gr_usermode->segv_uid);
55318+ }
55319+ } else {
55320+ gr_log_noargs(GR_DONT_AUDIT, GR_SEGVMODF_ACL_MSG);
55321+ error = -EPERM;
55322+ }
55323+ break;
55324+ case GR_SPROLE:
55325+ case GR_SPROLEPAM:
55326+ if (unlikely(!(gr_status & GR_READY))) {
55327+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SPROLEI_ACL_MSG);
55328+ error = -EAGAIN;
55329+ break;
55330+ }
55331+
55332+ if (current->role->expires && time_after_eq(get_seconds(), current->role->expires)) {
55333+ current->role->expires = 0;
55334+ current->role->auth_attempts = 0;
55335+ }
55336+
55337+ if (current->role->auth_attempts >= CONFIG_GRKERNSEC_ACL_MAXTRIES &&
55338+ time_after(current->role->expires, get_seconds())) {
55339+ error = -EBUSY;
55340+ goto out;
55341+ }
55342+
55343+ if (lookup_special_role_auth
55344+ (gr_usermode->mode, gr_usermode->sp_role, &sprole_salt, &sprole_sum)
55345+ && ((!sprole_salt && !sprole_sum)
55346+ || !(chkpw(gr_usermode, sprole_salt, sprole_sum)))) {
55347+ char *p = "";
55348+ assign_special_role(gr_usermode->sp_role);
55349+ read_lock(&tasklist_lock);
55350+ if (current->real_parent)
55351+ p = current->real_parent->role->rolename;
55352+ read_unlock(&tasklist_lock);
55353+ gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_SPROLES_ACL_MSG,
55354+ p, acl_sp_role_value);
55355+ } else {
55356+ gr_log_str(GR_DONT_AUDIT, GR_SPROLEF_ACL_MSG, gr_usermode->sp_role);
55357+ error = -EPERM;
55358+ if(!(current->role->auth_attempts++))
55359+ current->role->expires = get_seconds() + CONFIG_GRKERNSEC_ACL_TIMEOUT;
55360+
55361+ goto out;
55362+ }
55363+ break;
55364+ case GR_UNSPROLE:
55365+ if (unlikely(!(gr_status & GR_READY))) {
55366+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_UNSPROLEI_ACL_MSG);
55367+ error = -EAGAIN;
55368+ break;
55369+ }
55370+
55371+ if (current->role->roletype & GR_ROLE_SPECIAL) {
55372+ char *p = "";
55373+ int i = 0;
55374+
55375+ read_lock(&tasklist_lock);
55376+ if (current->real_parent) {
55377+ p = current->real_parent->role->rolename;
55378+ i = current->real_parent->acl_role_id;
55379+ }
55380+ read_unlock(&tasklist_lock);
55381+
55382+ gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_UNSPROLES_ACL_MSG, p, i);
55383+ gr_set_acls(1);
55384+ } else {
55385+ error = -EPERM;
55386+ goto out;
55387+ }
55388+ break;
55389+ default:
55390+ gr_log_int(GR_DONT_AUDIT, GR_INVMODE_ACL_MSG, gr_usermode->mode);
55391+ error = -EINVAL;
55392+ break;
55393+ }
55394+
55395+ if (error != -EPERM)
55396+ goto out;
55397+
55398+ if(!(gr_auth_attempts++))
55399+ gr_auth_expires = get_seconds() + CONFIG_GRKERNSEC_ACL_TIMEOUT;
55400+
55401+ out:
55402+ mutex_unlock(&gr_dev_mutex);
55403+ return error;
55404+}
55405+
55406+/* must be called with
55407+ rcu_read_lock();
55408+ read_lock(&tasklist_lock);
55409+ read_lock(&grsec_exec_file_lock);
55410+*/
55411+int gr_apply_subject_to_task(struct task_struct *task)
55412+{
55413+ struct acl_object_label *obj;
55414+ char *tmpname;
55415+ struct acl_subject_label *tmpsubj;
55416+ struct file *filp;
55417+ struct name_entry *nmatch;
55418+
55419+ filp = task->exec_file;
55420+ if (filp == NULL)
55421+ return 0;
55422+
55423+ /* the following is to apply the correct subject
55424+ on binaries running when the RBAC system
55425+ is enabled, when the binaries have been
55426+ replaced or deleted since their execution
55427+ -----
55428+ when the RBAC system starts, the inode/dev
55429+ from exec_file will be one the RBAC system
55430+ is unaware of. It only knows the inode/dev
55431+ of the present file on disk, or the absence
55432+ of it.
55433+ */
55434+ preempt_disable();
55435+ tmpname = gr_to_filename_rbac(filp->f_path.dentry, filp->f_path.mnt);
55436+
55437+ nmatch = lookup_name_entry(tmpname);
55438+ preempt_enable();
55439+ tmpsubj = NULL;
55440+ if (nmatch) {
55441+ if (nmatch->deleted)
55442+ tmpsubj = lookup_acl_subj_label_deleted(nmatch->inode, nmatch->device, task->role);
55443+ else
55444+ tmpsubj = lookup_acl_subj_label(nmatch->inode, nmatch->device, task->role);
55445+ if (tmpsubj != NULL)
55446+ task->acl = tmpsubj;
55447+ }
55448+ if (tmpsubj == NULL)
55449+ task->acl = chk_subj_label(filp->f_path.dentry, filp->f_path.mnt,
55450+ task->role);
55451+ if (task->acl) {
55452+ task->is_writable = 0;
55453+ /* ignore additional mmap checks for processes that are writable
55454+ by the default ACL */
55455+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, default_role->root_label);
55456+ if (unlikely(obj->mode & GR_WRITE))
55457+ task->is_writable = 1;
55458+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, task->role->root_label);
55459+ if (unlikely(obj->mode & GR_WRITE))
55460+ task->is_writable = 1;
55461+
55462+ gr_set_proc_res(task);
55463+
55464+#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
55465+ printk(KERN_ALERT "gr_set_acls for (%s:%d): role:%s, subject:%s\n", task->comm, task->pid, task->role->rolename, task->acl->filename);
55466+#endif
55467+ } else {
55468+ return 1;
55469+ }
55470+
55471+ return 0;
55472+}
55473+
55474+int
55475+gr_set_acls(const int type)
55476+{
55477+ struct task_struct *task, *task2;
55478+ struct acl_role_label *role = current->role;
55479+ __u16 acl_role_id = current->acl_role_id;
55480+ const struct cred *cred;
55481+ int ret;
55482+
55483+ rcu_read_lock();
55484+ read_lock(&tasklist_lock);
55485+ read_lock(&grsec_exec_file_lock);
55486+ do_each_thread(task2, task) {
55487+ /* check to see if we're called from the exit handler,
55488+ if so, only replace ACLs that have inherited the admin
55489+ ACL */
55490+
55491+ if (type && (task->role != role ||
55492+ task->acl_role_id != acl_role_id))
55493+ continue;
55494+
55495+ task->acl_role_id = 0;
55496+ task->acl_sp_role = 0;
55497+
55498+ if (task->exec_file) {
55499+ cred = __task_cred(task);
55500+ task->role = lookup_acl_role_label(task, cred->uid, cred->gid);
55501+ ret = gr_apply_subject_to_task(task);
55502+ if (ret) {
55503+ read_unlock(&grsec_exec_file_lock);
55504+ read_unlock(&tasklist_lock);
55505+ rcu_read_unlock();
55506+ gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_DEFACL_MSG, task->comm, task->pid);
55507+ return ret;
55508+ }
55509+ } else {
55510+ // it's a kernel process
55511+ task->role = kernel_role;
55512+ task->acl = kernel_role->root_label;
55513+#ifdef CONFIG_GRKERNSEC_ACL_HIDEKERN
55514+ task->acl->mode &= ~GR_PROCFIND;
55515+#endif
55516+ }
55517+ } while_each_thread(task2, task);
55518+ read_unlock(&grsec_exec_file_lock);
55519+ read_unlock(&tasklist_lock);
55520+ rcu_read_unlock();
55521+
55522+ return 0;
55523+}
55524+
55525+void
55526+gr_learn_resource(const struct task_struct *task,
55527+ const int res, const unsigned long wanted, const int gt)
55528+{
55529+ struct acl_subject_label *acl;
55530+ const struct cred *cred;
55531+
55532+ if (unlikely((gr_status & GR_READY) &&
55533+ task->acl && (task->acl->mode & (GR_LEARN | GR_INHERITLEARN))))
55534+ goto skip_reslog;
55535+
55536+#ifdef CONFIG_GRKERNSEC_RESLOG
55537+ gr_log_resource(task, res, wanted, gt);
55538+#endif
55539+ skip_reslog:
55540+
55541+ if (unlikely(!(gr_status & GR_READY) || !wanted || res >= GR_NLIMITS))
55542+ return;
55543+
55544+ acl = task->acl;
55545+
55546+ if (likely(!acl || !(acl->mode & (GR_LEARN | GR_INHERITLEARN)) ||
55547+ !(acl->resmask & (1 << (unsigned short) res))))
55548+ return;
55549+
55550+ if (wanted >= acl->res[res].rlim_cur) {
55551+ unsigned long res_add;
55552+
55553+ res_add = wanted;
55554+ switch (res) {
55555+ case RLIMIT_CPU:
55556+ res_add += GR_RLIM_CPU_BUMP;
55557+ break;
55558+ case RLIMIT_FSIZE:
55559+ res_add += GR_RLIM_FSIZE_BUMP;
55560+ break;
55561+ case RLIMIT_DATA:
55562+ res_add += GR_RLIM_DATA_BUMP;
55563+ break;
55564+ case RLIMIT_STACK:
55565+ res_add += GR_RLIM_STACK_BUMP;
55566+ break;
55567+ case RLIMIT_CORE:
55568+ res_add += GR_RLIM_CORE_BUMP;
55569+ break;
55570+ case RLIMIT_RSS:
55571+ res_add += GR_RLIM_RSS_BUMP;
55572+ break;
55573+ case RLIMIT_NPROC:
55574+ res_add += GR_RLIM_NPROC_BUMP;
55575+ break;
55576+ case RLIMIT_NOFILE:
55577+ res_add += GR_RLIM_NOFILE_BUMP;
55578+ break;
55579+ case RLIMIT_MEMLOCK:
55580+ res_add += GR_RLIM_MEMLOCK_BUMP;
55581+ break;
55582+ case RLIMIT_AS:
55583+ res_add += GR_RLIM_AS_BUMP;
55584+ break;
55585+ case RLIMIT_LOCKS:
55586+ res_add += GR_RLIM_LOCKS_BUMP;
55587+ break;
55588+ case RLIMIT_SIGPENDING:
55589+ res_add += GR_RLIM_SIGPENDING_BUMP;
55590+ break;
55591+ case RLIMIT_MSGQUEUE:
55592+ res_add += GR_RLIM_MSGQUEUE_BUMP;
55593+ break;
55594+ case RLIMIT_NICE:
55595+ res_add += GR_RLIM_NICE_BUMP;
55596+ break;
55597+ case RLIMIT_RTPRIO:
55598+ res_add += GR_RLIM_RTPRIO_BUMP;
55599+ break;
55600+ case RLIMIT_RTTIME:
55601+ res_add += GR_RLIM_RTTIME_BUMP;
55602+ break;
55603+ }
55604+
55605+ acl->res[res].rlim_cur = res_add;
55606+
55607+ if (wanted > acl->res[res].rlim_max)
55608+ acl->res[res].rlim_max = res_add;
55609+
55610+ /* only log the subject filename, since resource logging is supported for
55611+ single-subject learning only */
55612+ rcu_read_lock();
55613+ cred = __task_cred(task);
55614+ security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename,
55615+ task->role->roletype, cred->uid, cred->gid, acl->filename,
55616+ acl->filename, acl->res[res].rlim_cur, acl->res[res].rlim_max,
55617+ "", (unsigned long) res, &task->signal->saved_ip);
55618+ rcu_read_unlock();
55619+ }
55620+
55621+ return;
55622+}
55623+
55624+#if defined(CONFIG_PAX_HAVE_ACL_FLAGS) && (defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR))
55625+void
55626+pax_set_initial_flags(struct linux_binprm *bprm)
55627+{
55628+ struct task_struct *task = current;
55629+ struct acl_subject_label *proc;
55630+ unsigned long flags;
55631+
55632+ if (unlikely(!(gr_status & GR_READY)))
55633+ return;
55634+
55635+ flags = pax_get_flags(task);
55636+
55637+ proc = task->acl;
55638+
55639+ if (proc->pax_flags & GR_PAX_DISABLE_PAGEEXEC)
55640+ flags &= ~MF_PAX_PAGEEXEC;
55641+ if (proc->pax_flags & GR_PAX_DISABLE_SEGMEXEC)
55642+ flags &= ~MF_PAX_SEGMEXEC;
55643+ if (proc->pax_flags & GR_PAX_DISABLE_RANDMMAP)
55644+ flags &= ~MF_PAX_RANDMMAP;
55645+ if (proc->pax_flags & GR_PAX_DISABLE_EMUTRAMP)
55646+ flags &= ~MF_PAX_EMUTRAMP;
55647+ if (proc->pax_flags & GR_PAX_DISABLE_MPROTECT)
55648+ flags &= ~MF_PAX_MPROTECT;
55649+
55650+ if (proc->pax_flags & GR_PAX_ENABLE_PAGEEXEC)
55651+ flags |= MF_PAX_PAGEEXEC;
55652+ if (proc->pax_flags & GR_PAX_ENABLE_SEGMEXEC)
55653+ flags |= MF_PAX_SEGMEXEC;
55654+ if (proc->pax_flags & GR_PAX_ENABLE_RANDMMAP)
55655+ flags |= MF_PAX_RANDMMAP;
55656+ if (proc->pax_flags & GR_PAX_ENABLE_EMUTRAMP)
55657+ flags |= MF_PAX_EMUTRAMP;
55658+ if (proc->pax_flags & GR_PAX_ENABLE_MPROTECT)
55659+ flags |= MF_PAX_MPROTECT;
55660+
55661+ pax_set_flags(task, flags);
55662+
55663+ return;
55664+}
55665+#endif
55666+
55667+int
55668+gr_handle_proc_ptrace(struct task_struct *task)
55669+{
55670+ struct file *filp;
55671+ struct task_struct *tmp = task;
55672+ struct task_struct *curtemp = current;
55673+ __u32 retmode;
55674+
55675+#ifndef CONFIG_GRKERNSEC_HARDEN_PTRACE
55676+ if (unlikely(!(gr_status & GR_READY)))
55677+ return 0;
55678+#endif
55679+
55680+ read_lock(&tasklist_lock);
55681+ read_lock(&grsec_exec_file_lock);
55682+ filp = task->exec_file;
55683+
55684+ while (tmp->pid > 0) {
55685+ if (tmp == curtemp)
55686+ break;
55687+ tmp = tmp->real_parent;
55688+ }
55689+
55690+ if (!filp || (tmp->pid == 0 && ((grsec_enable_harden_ptrace && !uid_eq(current_uid(), GLOBAL_ROOT_UID) && !(gr_status & GR_READY)) ||
55691+ ((gr_status & GR_READY) && !(current->acl->mode & GR_RELAXPTRACE))))) {
55692+ read_unlock(&grsec_exec_file_lock);
55693+ read_unlock(&tasklist_lock);
55694+ return 1;
55695+ }
55696+
55697+#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
55698+ if (!(gr_status & GR_READY)) {
55699+ read_unlock(&grsec_exec_file_lock);
55700+ read_unlock(&tasklist_lock);
55701+ return 0;
55702+ }
55703+#endif
55704+
55705+ retmode = gr_search_file(filp->f_path.dentry, GR_NOPTRACE, filp->f_path.mnt);
55706+ read_unlock(&grsec_exec_file_lock);
55707+ read_unlock(&tasklist_lock);
55708+
55709+ if (retmode & GR_NOPTRACE)
55710+ return 1;
55711+
55712+ if (!(current->acl->mode & GR_POVERRIDE) && !(current->role->roletype & GR_ROLE_GOD)
55713+ && (current->acl != task->acl || (current->acl != current->role->root_label
55714+ && current->pid != task->pid)))
55715+ return 1;
55716+
55717+ return 0;
55718+}
55719+
55720+void task_grsec_rbac(struct seq_file *m, struct task_struct *p)
55721+{
55722+ if (unlikely(!(gr_status & GR_READY)))
55723+ return;
55724+
55725+ if (!(current->role->roletype & GR_ROLE_GOD))
55726+ return;
55727+
55728+ seq_printf(m, "RBAC:\t%.64s:%c:%.950s\n",
55729+ p->role->rolename, gr_task_roletype_to_char(p),
55730+ p->acl->filename);
55731+}
55732+
55733+int
55734+gr_handle_ptrace(struct task_struct *task, const long request)
55735+{
55736+ struct task_struct *tmp = task;
55737+ struct task_struct *curtemp = current;
55738+ __u32 retmode;
55739+
55740+#ifndef CONFIG_GRKERNSEC_HARDEN_PTRACE
55741+ if (unlikely(!(gr_status & GR_READY)))
55742+ return 0;
55743+#endif
55744+ if (request == PTRACE_ATTACH || request == PTRACE_SEIZE) {
55745+ read_lock(&tasklist_lock);
55746+ while (tmp->pid > 0) {
55747+ if (tmp == curtemp)
55748+ break;
55749+ tmp = tmp->real_parent;
55750+ }
55751+
55752+ if (tmp->pid == 0 && ((grsec_enable_harden_ptrace && !uid_eq(current_uid(), GLOBAL_ROOT_UID) && !(gr_status & GR_READY)) ||
55753+ ((gr_status & GR_READY) && !(current->acl->mode & GR_RELAXPTRACE)))) {
55754+ read_unlock(&tasklist_lock);
55755+ gr_log_ptrace(GR_DONT_AUDIT, GR_PTRACE_ACL_MSG, task);
55756+ return 1;
55757+ }
55758+ read_unlock(&tasklist_lock);
55759+ }
55760+
55761+#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
55762+ if (!(gr_status & GR_READY))
55763+ return 0;
55764+#endif
55765+
55766+ read_lock(&grsec_exec_file_lock);
55767+ if (unlikely(!task->exec_file)) {
55768+ read_unlock(&grsec_exec_file_lock);
55769+ return 0;
55770+ }
55771+
55772+ retmode = gr_search_file(task->exec_file->f_path.dentry, GR_PTRACERD | GR_NOPTRACE, task->exec_file->f_path.mnt);
55773+ read_unlock(&grsec_exec_file_lock);
55774+
55775+ if (retmode & GR_NOPTRACE) {
55776+ gr_log_ptrace(GR_DONT_AUDIT, GR_PTRACE_ACL_MSG, task);
55777+ return 1;
55778+ }
55779+
55780+ if (retmode & GR_PTRACERD) {
55781+ switch (request) {
55782+ case PTRACE_SEIZE:
55783+ case PTRACE_POKETEXT:
55784+ case PTRACE_POKEDATA:
55785+ case PTRACE_POKEUSR:
55786+#if !defined(CONFIG_PPC32) && !defined(CONFIG_PPC64) && !defined(CONFIG_PARISC) && !defined(CONFIG_ALPHA) && !defined(CONFIG_IA64)
55787+ case PTRACE_SETREGS:
55788+ case PTRACE_SETFPREGS:
55789+#endif
55790+#ifdef CONFIG_X86
55791+ case PTRACE_SETFPXREGS:
55792+#endif
55793+#ifdef CONFIG_ALTIVEC
55794+ case PTRACE_SETVRREGS:
55795+#endif
55796+ return 1;
55797+ default:
55798+ return 0;
55799+ }
55800+ } else if (!(current->acl->mode & GR_POVERRIDE) &&
55801+ !(current->role->roletype & GR_ROLE_GOD) &&
55802+ (current->acl != task->acl)) {
55803+ gr_log_ptrace(GR_DONT_AUDIT, GR_PTRACE_ACL_MSG, task);
55804+ return 1;
55805+ }
55806+
55807+ return 0;
55808+}
55809+
55810+static int is_writable_mmap(const struct file *filp)
55811+{
55812+ struct task_struct *task = current;
55813+ struct acl_object_label *obj, *obj2;
55814+
55815+ if (gr_status & GR_READY && !(task->acl->mode & GR_OVERRIDE) &&
55816+ !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))) {
55817+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, default_role->root_label);
55818+ obj2 = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt,
55819+ task->role->root_label);
55820+ if (unlikely((obj->mode & GR_WRITE) || (obj2->mode & GR_WRITE))) {
55821+ gr_log_fs_generic(GR_DONT_AUDIT, GR_WRITLIB_ACL_MSG, filp->f_path.dentry, filp->f_path.mnt);
55822+ return 1;
55823+ }
55824+ }
55825+ return 0;
55826+}
55827+
55828+int
55829+gr_acl_handle_mmap(const struct file *file, const unsigned long prot)
55830+{
55831+ __u32 mode;
55832+
55833+ if (unlikely(!file || !(prot & PROT_EXEC)))
55834+ return 1;
55835+
55836+ if (is_writable_mmap(file))
55837+ return 0;
55838+
55839+ mode =
55840+ gr_search_file(file->f_path.dentry,
55841+ GR_EXEC | GR_AUDIT_EXEC | GR_SUPPRESS,
55842+ file->f_path.mnt);
55843+
55844+ if (!gr_tpe_allow(file))
55845+ return 0;
55846+
55847+ if (unlikely(!(mode & GR_EXEC) && !(mode & GR_SUPPRESS))) {
55848+ gr_log_fs_rbac_generic(GR_DONT_AUDIT, GR_MMAP_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
55849+ return 0;
55850+ } else if (unlikely(!(mode & GR_EXEC))) {
55851+ return 0;
55852+ } else if (unlikely(mode & GR_EXEC && mode & GR_AUDIT_EXEC)) {
55853+ gr_log_fs_rbac_generic(GR_DO_AUDIT, GR_MMAP_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
55854+ return 1;
55855+ }
55856+
55857+ return 1;
55858+}
55859+
55860+int
55861+gr_acl_handle_mprotect(const struct file *file, const unsigned long prot)
55862+{
55863+ __u32 mode;
55864+
55865+ if (unlikely(!file || !(prot & PROT_EXEC)))
55866+ return 1;
55867+
55868+ if (is_writable_mmap(file))
55869+ return 0;
55870+
55871+ mode =
55872+ gr_search_file(file->f_path.dentry,
55873+ GR_EXEC | GR_AUDIT_EXEC | GR_SUPPRESS,
55874+ file->f_path.mnt);
55875+
55876+ if (!gr_tpe_allow(file))
55877+ return 0;
55878+
55879+ if (unlikely(!(mode & GR_EXEC) && !(mode & GR_SUPPRESS))) {
55880+ gr_log_fs_rbac_generic(GR_DONT_AUDIT, GR_MPROTECT_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
55881+ return 0;
55882+ } else if (unlikely(!(mode & GR_EXEC))) {
55883+ return 0;
55884+ } else if (unlikely(mode & GR_EXEC && mode & GR_AUDIT_EXEC)) {
55885+ gr_log_fs_rbac_generic(GR_DO_AUDIT, GR_MPROTECT_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
55886+ return 1;
55887+ }
55888+
55889+ return 1;
55890+}
55891+
55892+void
55893+gr_acl_handle_psacct(struct task_struct *task, const long code)
55894+{
55895+ unsigned long runtime;
55896+ unsigned long cputime;
55897+ unsigned int wday, cday;
55898+ __u8 whr, chr;
55899+ __u8 wmin, cmin;
55900+ __u8 wsec, csec;
55901+ struct timespec timeval;
55902+
55903+ if (unlikely(!(gr_status & GR_READY) || !task->acl ||
55904+ !(task->acl->mode & GR_PROCACCT)))
55905+ return;
55906+
55907+ do_posix_clock_monotonic_gettime(&timeval);
55908+ runtime = timeval.tv_sec - task->start_time.tv_sec;
55909+ wday = runtime / (3600 * 24);
55910+ runtime -= wday * (3600 * 24);
55911+ whr = runtime / 3600;
55912+ runtime -= whr * 3600;
55913+ wmin = runtime / 60;
55914+ runtime -= wmin * 60;
55915+ wsec = runtime;
55916+
55917+ cputime = (task->utime + task->stime) / HZ;
55918+ cday = cputime / (3600 * 24);
55919+ cputime -= cday * (3600 * 24);
55920+ chr = cputime / 3600;
55921+ cputime -= chr * 3600;
55922+ cmin = cputime / 60;
55923+ cputime -= cmin * 60;
55924+ csec = cputime;
55925+
55926+ gr_log_procacct(GR_DO_AUDIT, GR_ACL_PROCACCT_MSG, task, wday, whr, wmin, wsec, cday, chr, cmin, csec, code);
55927+
55928+ return;
55929+}
55930+
55931+void gr_set_kernel_label(struct task_struct *task)
55932+{
55933+ if (gr_status & GR_READY) {
55934+ task->role = kernel_role;
55935+ task->acl = kernel_role->root_label;
55936+ }
55937+ return;
55938+}
55939+
55940+#ifdef CONFIG_TASKSTATS
55941+int gr_is_taskstats_denied(int pid)
55942+{
55943+ struct task_struct *task;
55944+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
55945+ const struct cred *cred;
55946+#endif
55947+ int ret = 0;
55948+
55949+ /* restrict taskstats viewing to un-chrooted root users
55950+ who have the 'view' subject flag if the RBAC system is enabled
55951+ */
55952+
55953+ rcu_read_lock();
55954+ read_lock(&tasklist_lock);
55955+ task = find_task_by_vpid(pid);
55956+ if (task) {
55957+#ifdef CONFIG_GRKERNSEC_CHROOT
55958+ if (proc_is_chrooted(task))
55959+ ret = -EACCES;
55960+#endif
55961+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
55962+ cred = __task_cred(task);
55963+#ifdef CONFIG_GRKERNSEC_PROC_USER
55964+ if (!uid_eq(cred->uid, GLOBAL_ROOT_UID))
55965+ ret = -EACCES;
55966+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
55967+ if (!uid_eq(cred->uid, GLOBAL_ROOT_UID) && !groups_search(cred->group_info, grsec_proc_gid))
55968+ ret = -EACCES;
55969+#endif
55970+#endif
55971+ if (gr_status & GR_READY) {
55972+ if (!(task->acl->mode & GR_VIEW))
55973+ ret = -EACCES;
55974+ }
55975+ } else
55976+ ret = -ENOENT;
55977+
55978+ read_unlock(&tasklist_lock);
55979+ rcu_read_unlock();
55980+
55981+ return ret;
55982+}
55983+#endif
55984+
55985+/* AUXV entries are filled via a descendant of search_binary_handler
55986+ after we've already applied the subject for the target
55987+*/
55988+int gr_acl_enable_at_secure(void)
55989+{
55990+ if (unlikely(!(gr_status & GR_READY)))
55991+ return 0;
55992+
55993+ if (current->acl->mode & GR_ATSECURE)
55994+ return 1;
55995+
55996+ return 0;
55997+}
55998+
55999+int gr_acl_handle_filldir(const struct file *file, const char *name, const unsigned int namelen, const ino_t ino)
56000+{
56001+ struct task_struct *task = current;
56002+ struct dentry *dentry = file->f_path.dentry;
56003+ struct vfsmount *mnt = file->f_path.mnt;
56004+ struct acl_object_label *obj, *tmp;
56005+ struct acl_subject_label *subj;
56006+ unsigned int bufsize;
56007+ int is_not_root;
56008+ char *path;
56009+ dev_t dev = __get_dev(dentry);
56010+
56011+ if (unlikely(!(gr_status & GR_READY)))
56012+ return 1;
56013+
56014+ if (task->acl->mode & (GR_LEARN | GR_INHERITLEARN))
56015+ return 1;
56016+
56017+ /* ignore Eric Biederman */
56018+ if (IS_PRIVATE(dentry->d_inode))
56019+ return 1;
56020+
56021+ subj = task->acl;
56022+ read_lock(&gr_inode_lock);
56023+ do {
56024+ obj = lookup_acl_obj_label(ino, dev, subj);
56025+ if (obj != NULL) {
56026+ read_unlock(&gr_inode_lock);
56027+ return (obj->mode & GR_FIND) ? 1 : 0;
56028+ }
56029+ } while ((subj = subj->parent_subject));
56030+ read_unlock(&gr_inode_lock);
56031+
56032+ /* this is purely an optimization since we're looking for an object
56033+ for the directory we're doing a readdir on
56034+ if it's possible for any globbed object to match the entry we're
56035+ filling into the directory, then the object we find here will be
56036+ an anchor point with attached globbed objects
56037+ */
56038+ obj = chk_obj_label_noglob(dentry, mnt, task->acl);
56039+ if (obj->globbed == NULL)
56040+ return (obj->mode & GR_FIND) ? 1 : 0;
56041+
56042+ is_not_root = ((obj->filename[0] == '/') &&
56043+ (obj->filename[1] == '\0')) ? 0 : 1;
56044+ bufsize = PAGE_SIZE - namelen - is_not_root;
56045+
56046+ /* check bufsize > PAGE_SIZE || bufsize == 0 */
56047+ if (unlikely((bufsize - 1) > (PAGE_SIZE - 1)))
56048+ return 1;
56049+
56050+ preempt_disable();
56051+ path = d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0], smp_processor_id()),
56052+ bufsize);
56053+
56054+ bufsize = strlen(path);
56055+
56056+ /* if base is "/", don't append an additional slash */
56057+ if (is_not_root)
56058+ *(path + bufsize) = '/';
56059+ memcpy(path + bufsize + is_not_root, name, namelen);
56060+ *(path + bufsize + namelen + is_not_root) = '\0';
56061+
56062+ tmp = obj->globbed;
56063+ while (tmp) {
56064+ if (!glob_match(tmp->filename, path)) {
56065+ preempt_enable();
56066+ return (tmp->mode & GR_FIND) ? 1 : 0;
56067+ }
56068+ tmp = tmp->next;
56069+ }
56070+ preempt_enable();
56071+ return (obj->mode & GR_FIND) ? 1 : 0;
56072+}
56073+
56074+void gr_put_exec_file(struct task_struct *task)
56075+{
56076+ struct file *filp;
56077+
56078+ write_lock(&grsec_exec_file_lock);
56079+ filp = task->exec_file;
56080+ task->exec_file = NULL;
56081+ write_unlock(&grsec_exec_file_lock);
56082+
56083+ if (filp)
56084+ fput(filp);
56085+
56086+ return;
56087+}
56088+
56089+
56090+#ifdef CONFIG_NETFILTER_XT_MATCH_GRADM_MODULE
56091+EXPORT_SYMBOL(gr_acl_is_enabled);
56092+#endif
56093+EXPORT_SYMBOL(gr_learn_resource);
56094+EXPORT_SYMBOL(gr_set_kernel_label);
56095+#ifdef CONFIG_SECURITY
56096+EXPORT_SYMBOL(gr_check_user_change);
56097+EXPORT_SYMBOL(gr_check_group_change);
56098+#endif
56099+
56100diff --git a/grsecurity/gracl_alloc.c b/grsecurity/gracl_alloc.c
56101new file mode 100644
56102index 0000000..34fefda
56103--- /dev/null
56104+++ b/grsecurity/gracl_alloc.c
56105@@ -0,0 +1,105 @@
56106+#include <linux/kernel.h>
56107+#include <linux/mm.h>
56108+#include <linux/slab.h>
56109+#include <linux/vmalloc.h>
56110+#include <linux/gracl.h>
56111+#include <linux/grsecurity.h>
56112+
56113+static unsigned long alloc_stack_next = 1;
56114+static unsigned long alloc_stack_size = 1;
56115+static void **alloc_stack;
56116+
56117+static __inline__ int
56118+alloc_pop(void)
56119+{
56120+ if (alloc_stack_next == 1)
56121+ return 0;
56122+
56123+ kfree(alloc_stack[alloc_stack_next - 2]);
56124+
56125+ alloc_stack_next--;
56126+
56127+ return 1;
56128+}
56129+
56130+static __inline__ int
56131+alloc_push(void *buf)
56132+{
56133+ if (alloc_stack_next >= alloc_stack_size)
56134+ return 1;
56135+
56136+ alloc_stack[alloc_stack_next - 1] = buf;
56137+
56138+ alloc_stack_next++;
56139+
56140+ return 0;
56141+}
56142+
56143+void *
56144+acl_alloc(unsigned long len)
56145+{
56146+ void *ret = NULL;
56147+
56148+ if (!len || len > PAGE_SIZE)
56149+ goto out;
56150+
56151+ ret = kmalloc(len, GFP_KERNEL);
56152+
56153+ if (ret) {
56154+ if (alloc_push(ret)) {
56155+ kfree(ret);
56156+ ret = NULL;
56157+ }
56158+ }
56159+
56160+out:
56161+ return ret;
56162+}
56163+
56164+void *
56165+acl_alloc_num(unsigned long num, unsigned long len)
56166+{
56167+ if (!len || (num > (PAGE_SIZE / len)))
56168+ return NULL;
56169+
56170+ return acl_alloc(num * len);
56171+}
56172+
56173+void
56174+acl_free_all(void)
56175+{
56176+ if (gr_acl_is_enabled() || !alloc_stack)
56177+ return;
56178+
56179+ while (alloc_pop()) ;
56180+
56181+ if (alloc_stack) {
56182+ if ((alloc_stack_size * sizeof (void *)) <= PAGE_SIZE)
56183+ kfree(alloc_stack);
56184+ else
56185+ vfree(alloc_stack);
56186+ }
56187+
56188+ alloc_stack = NULL;
56189+ alloc_stack_size = 1;
56190+ alloc_stack_next = 1;
56191+
56192+ return;
56193+}
56194+
56195+int
56196+acl_alloc_stack_init(unsigned long size)
56197+{
56198+ if ((size * sizeof (void *)) <= PAGE_SIZE)
56199+ alloc_stack =
56200+ (void **) kmalloc(size * sizeof (void *), GFP_KERNEL);
56201+ else
56202+ alloc_stack = (void **) vmalloc(size * sizeof (void *));
56203+
56204+ alloc_stack_size = size;
56205+
56206+ if (!alloc_stack)
56207+ return 0;
56208+ else
56209+ return 1;
56210+}
56211diff --git a/grsecurity/gracl_cap.c b/grsecurity/gracl_cap.c
56212new file mode 100644
56213index 0000000..6d21049
56214--- /dev/null
56215+++ b/grsecurity/gracl_cap.c
56216@@ -0,0 +1,110 @@
56217+#include <linux/kernel.h>
56218+#include <linux/module.h>
56219+#include <linux/sched.h>
56220+#include <linux/gracl.h>
56221+#include <linux/grsecurity.h>
56222+#include <linux/grinternal.h>
56223+
56224+extern const char *captab_log[];
56225+extern int captab_log_entries;
56226+
56227+int gr_task_acl_is_capable(const struct task_struct *task, const struct cred *cred, const int cap)
56228+{
56229+ struct acl_subject_label *curracl;
56230+ kernel_cap_t cap_drop = __cap_empty_set, cap_mask = __cap_empty_set;
56231+ kernel_cap_t cap_audit = __cap_empty_set;
56232+
56233+ if (!gr_acl_is_enabled())
56234+ return 1;
56235+
56236+ curracl = task->acl;
56237+
56238+ cap_drop = curracl->cap_lower;
56239+ cap_mask = curracl->cap_mask;
56240+ cap_audit = curracl->cap_invert_audit;
56241+
56242+ while ((curracl = curracl->parent_subject)) {
56243+ /* if the cap isn't specified in the current computed mask but is specified in the
56244+ current level subject, and is lowered in the current level subject, then add
56245+ it to the set of dropped capabilities
56246+ otherwise, add the current level subject's mask to the current computed mask
56247+ */
56248+ if (!cap_raised(cap_mask, cap) && cap_raised(curracl->cap_mask, cap)) {
56249+ cap_raise(cap_mask, cap);
56250+ if (cap_raised(curracl->cap_lower, cap))
56251+ cap_raise(cap_drop, cap);
56252+ if (cap_raised(curracl->cap_invert_audit, cap))
56253+ cap_raise(cap_audit, cap);
56254+ }
56255+ }
56256+
56257+ if (!cap_raised(cap_drop, cap)) {
56258+ if (cap_raised(cap_audit, cap))
56259+ gr_log_cap(GR_DO_AUDIT, GR_CAP_ACL_MSG2, task, captab_log[cap]);
56260+ return 1;
56261+ }
56262+
56263+ curracl = task->acl;
56264+
56265+ if ((curracl->mode & (GR_LEARN | GR_INHERITLEARN))
56266+ && cap_raised(cred->cap_effective, cap)) {
56267+ security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename,
56268+ task->role->roletype, cred->uid,
56269+ cred->gid, task->exec_file ?
56270+ gr_to_filename(task->exec_file->f_path.dentry,
56271+ task->exec_file->f_path.mnt) : curracl->filename,
56272+ curracl->filename, 0UL,
56273+ 0UL, "", (unsigned long) cap, &task->signal->saved_ip);
56274+ return 1;
56275+ }
56276+
56277+ if ((cap >= 0) && (cap < captab_log_entries) && cap_raised(cred->cap_effective, cap) && !cap_raised(cap_audit, cap))
56278+ gr_log_cap(GR_DONT_AUDIT, GR_CAP_ACL_MSG, task, captab_log[cap]);
56279+
56280+ return 0;
56281+}
56282+
56283+int
56284+gr_acl_is_capable(const int cap)
56285+{
56286+ return gr_task_acl_is_capable(current, current_cred(), cap);
56287+}
56288+
56289+int gr_task_acl_is_capable_nolog(const struct task_struct *task, const int cap)
56290+{
56291+ struct acl_subject_label *curracl;
56292+ kernel_cap_t cap_drop = __cap_empty_set, cap_mask = __cap_empty_set;
56293+
56294+ if (!gr_acl_is_enabled())
56295+ return 1;
56296+
56297+ curracl = task->acl;
56298+
56299+ cap_drop = curracl->cap_lower;
56300+ cap_mask = curracl->cap_mask;
56301+
56302+ while ((curracl = curracl->parent_subject)) {
56303+ /* if the cap isn't specified in the current computed mask but is specified in the
56304+ current level subject, and is lowered in the current level subject, then add
56305+ it to the set of dropped capabilities
56306+ otherwise, add the current level subject's mask to the current computed mask
56307+ */
56308+ if (!cap_raised(cap_mask, cap) && cap_raised(curracl->cap_mask, cap)) {
56309+ cap_raise(cap_mask, cap);
56310+ if (cap_raised(curracl->cap_lower, cap))
56311+ cap_raise(cap_drop, cap);
56312+ }
56313+ }
56314+
56315+ if (!cap_raised(cap_drop, cap))
56316+ return 1;
56317+
56318+ return 0;
56319+}
56320+
56321+int
56322+gr_acl_is_capable_nolog(const int cap)
56323+{
56324+ return gr_task_acl_is_capable_nolog(current, cap);
56325+}
56326+
56327diff --git a/grsecurity/gracl_fs.c b/grsecurity/gracl_fs.c
56328new file mode 100644
56329index 0000000..d28e241
56330--- /dev/null
56331+++ b/grsecurity/gracl_fs.c
56332@@ -0,0 +1,437 @@
56333+#include <linux/kernel.h>
56334+#include <linux/sched.h>
56335+#include <linux/types.h>
56336+#include <linux/fs.h>
56337+#include <linux/file.h>
56338+#include <linux/stat.h>
56339+#include <linux/grsecurity.h>
56340+#include <linux/grinternal.h>
56341+#include <linux/gracl.h>
56342+
56343+umode_t
56344+gr_acl_umask(void)
56345+{
56346+ if (unlikely(!gr_acl_is_enabled()))
56347+ return 0;
56348+
56349+ return current->role->umask;
56350+}
56351+
56352+__u32
56353+gr_acl_handle_hidden_file(const struct dentry * dentry,
56354+ const struct vfsmount * mnt)
56355+{
56356+ __u32 mode;
56357+
56358+ if (unlikely(!dentry->d_inode))
56359+ return GR_FIND;
56360+
56361+ mode =
56362+ gr_search_file(dentry, GR_FIND | GR_AUDIT_FIND | GR_SUPPRESS, mnt);
56363+
56364+ if (unlikely(mode & GR_FIND && mode & GR_AUDIT_FIND)) {
56365+ gr_log_fs_rbac_generic(GR_DO_AUDIT, GR_HIDDEN_ACL_MSG, dentry, mnt);
56366+ return mode;
56367+ } else if (unlikely(!(mode & GR_FIND) && !(mode & GR_SUPPRESS))) {
56368+ gr_log_fs_rbac_generic(GR_DONT_AUDIT, GR_HIDDEN_ACL_MSG, dentry, mnt);
56369+ return 0;
56370+ } else if (unlikely(!(mode & GR_FIND)))
56371+ return 0;
56372+
56373+ return GR_FIND;
56374+}
56375+
56376+__u32
56377+gr_acl_handle_open(const struct dentry * dentry, const struct vfsmount * mnt,
56378+ int acc_mode)
56379+{
56380+ __u32 reqmode = GR_FIND;
56381+ __u32 mode;
56382+
56383+ if (unlikely(!dentry->d_inode))
56384+ return reqmode;
56385+
56386+ if (acc_mode & MAY_APPEND)
56387+ reqmode |= GR_APPEND;
56388+ else if (acc_mode & MAY_WRITE)
56389+ reqmode |= GR_WRITE;
56390+ if ((acc_mode & MAY_READ) && !S_ISDIR(dentry->d_inode->i_mode))
56391+ reqmode |= GR_READ;
56392+
56393+ mode =
56394+ gr_search_file(dentry, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS,
56395+ mnt);
56396+
56397+ if (unlikely(((mode & reqmode) == reqmode) && mode & GR_AUDITS)) {
56398+ gr_log_fs_rbac_mode2(GR_DO_AUDIT, GR_OPEN_ACL_MSG, dentry, mnt,
56399+ reqmode & GR_READ ? " reading" : "",
56400+ reqmode & GR_WRITE ? " writing" : reqmode &
56401+ GR_APPEND ? " appending" : "");
56402+ return reqmode;
56403+ } else
56404+ if (unlikely((mode & reqmode) != reqmode && !(mode & GR_SUPPRESS)))
56405+ {
56406+ gr_log_fs_rbac_mode2(GR_DONT_AUDIT, GR_OPEN_ACL_MSG, dentry, mnt,
56407+ reqmode & GR_READ ? " reading" : "",
56408+ reqmode & GR_WRITE ? " writing" : reqmode &
56409+ GR_APPEND ? " appending" : "");
56410+ return 0;
56411+ } else if (unlikely((mode & reqmode) != reqmode))
56412+ return 0;
56413+
56414+ return reqmode;
56415+}
56416+
56417+__u32
56418+gr_acl_handle_creat(const struct dentry * dentry,
56419+ const struct dentry * p_dentry,
56420+ const struct vfsmount * p_mnt, int open_flags, int acc_mode,
56421+ const int imode)
56422+{
56423+ __u32 reqmode = GR_WRITE | GR_CREATE;
56424+ __u32 mode;
56425+
56426+ if (acc_mode & MAY_APPEND)
56427+ reqmode |= GR_APPEND;
56428+ // if a directory was required or the directory already exists, then
56429+ // don't count this open as a read
56430+ if ((acc_mode & MAY_READ) &&
56431+ !((open_flags & O_DIRECTORY) || (dentry->d_inode && S_ISDIR(dentry->d_inode->i_mode))))
56432+ reqmode |= GR_READ;
56433+ if ((open_flags & O_CREAT) &&
56434+ ((imode & S_ISUID) || ((imode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))))
56435+ reqmode |= GR_SETID;
56436+
56437+ mode =
56438+ gr_check_create(dentry, p_dentry, p_mnt,
56439+ reqmode | to_gr_audit(reqmode) | GR_SUPPRESS);
56440+
56441+ if (unlikely(((mode & reqmode) == reqmode) && mode & GR_AUDITS)) {
56442+ gr_log_fs_rbac_mode2(GR_DO_AUDIT, GR_CREATE_ACL_MSG, dentry, p_mnt,
56443+ reqmode & GR_READ ? " reading" : "",
56444+ reqmode & GR_WRITE ? " writing" : reqmode &
56445+ GR_APPEND ? " appending" : "");
56446+ return reqmode;
56447+ } else
56448+ if (unlikely((mode & reqmode) != reqmode && !(mode & GR_SUPPRESS)))
56449+ {
56450+ gr_log_fs_rbac_mode2(GR_DONT_AUDIT, GR_CREATE_ACL_MSG, dentry, p_mnt,
56451+ reqmode & GR_READ ? " reading" : "",
56452+ reqmode & GR_WRITE ? " writing" : reqmode &
56453+ GR_APPEND ? " appending" : "");
56454+ return 0;
56455+ } else if (unlikely((mode & reqmode) != reqmode))
56456+ return 0;
56457+
56458+ return reqmode;
56459+}
56460+
56461+__u32
56462+gr_acl_handle_access(const struct dentry * dentry, const struct vfsmount * mnt,
56463+ const int fmode)
56464+{
56465+ __u32 mode, reqmode = GR_FIND;
56466+
56467+ if ((fmode & S_IXOTH) && !S_ISDIR(dentry->d_inode->i_mode))
56468+ reqmode |= GR_EXEC;
56469+ if (fmode & S_IWOTH)
56470+ reqmode |= GR_WRITE;
56471+ if (fmode & S_IROTH)
56472+ reqmode |= GR_READ;
56473+
56474+ mode =
56475+ gr_search_file(dentry, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS,
56476+ mnt);
56477+
56478+ if (unlikely(((mode & reqmode) == reqmode) && mode & GR_AUDITS)) {
56479+ gr_log_fs_rbac_mode3(GR_DO_AUDIT, GR_ACCESS_ACL_MSG, dentry, mnt,
56480+ reqmode & GR_READ ? " reading" : "",
56481+ reqmode & GR_WRITE ? " writing" : "",
56482+ reqmode & GR_EXEC ? " executing" : "");
56483+ return reqmode;
56484+ } else
56485+ if (unlikely((mode & reqmode) != reqmode && !(mode & GR_SUPPRESS)))
56486+ {
56487+ gr_log_fs_rbac_mode3(GR_DONT_AUDIT, GR_ACCESS_ACL_MSG, dentry, mnt,
56488+ reqmode & GR_READ ? " reading" : "",
56489+ reqmode & GR_WRITE ? " writing" : "",
56490+ reqmode & GR_EXEC ? " executing" : "");
56491+ return 0;
56492+ } else if (unlikely((mode & reqmode) != reqmode))
56493+ return 0;
56494+
56495+ return reqmode;
56496+}
56497+
56498+static __u32 generic_fs_handler(const struct dentry *dentry, const struct vfsmount *mnt, __u32 reqmode, const char *fmt)
56499+{
56500+ __u32 mode;
56501+
56502+ mode = gr_search_file(dentry, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS, mnt);
56503+
56504+ if (unlikely(((mode & (reqmode)) == (reqmode)) && mode & GR_AUDITS)) {
56505+ gr_log_fs_rbac_generic(GR_DO_AUDIT, fmt, dentry, mnt);
56506+ return mode;
56507+ } else if (unlikely((mode & (reqmode)) != (reqmode) && !(mode & GR_SUPPRESS))) {
56508+ gr_log_fs_rbac_generic(GR_DONT_AUDIT, fmt, dentry, mnt);
56509+ return 0;
56510+ } else if (unlikely((mode & (reqmode)) != (reqmode)))
56511+ return 0;
56512+
56513+ return (reqmode);
56514+}
56515+
56516+__u32
56517+gr_acl_handle_rmdir(const struct dentry * dentry, const struct vfsmount * mnt)
56518+{
56519+ return generic_fs_handler(dentry, mnt, GR_WRITE | GR_DELETE , GR_RMDIR_ACL_MSG);
56520+}
56521+
56522+__u32
56523+gr_acl_handle_unlink(const struct dentry *dentry, const struct vfsmount *mnt)
56524+{
56525+ return generic_fs_handler(dentry, mnt, GR_WRITE | GR_DELETE , GR_UNLINK_ACL_MSG);
56526+}
56527+
56528+__u32
56529+gr_acl_handle_truncate(const struct dentry *dentry, const struct vfsmount *mnt)
56530+{
56531+ return generic_fs_handler(dentry, mnt, GR_WRITE, GR_TRUNCATE_ACL_MSG);
56532+}
56533+
56534+__u32
56535+gr_acl_handle_utime(const struct dentry *dentry, const struct vfsmount *mnt)
56536+{
56537+ return generic_fs_handler(dentry, mnt, GR_WRITE, GR_ATIME_ACL_MSG);
56538+}
56539+
56540+__u32
56541+gr_acl_handle_chmod(const struct dentry *dentry, const struct vfsmount *mnt,
56542+ umode_t *modeptr)
56543+{
56544+ umode_t mode;
56545+
56546+ *modeptr &= ~gr_acl_umask();
56547+ mode = *modeptr;
56548+
56549+ if (unlikely(dentry->d_inode && S_ISSOCK(dentry->d_inode->i_mode)))
56550+ return 1;
56551+
56552+ if (unlikely(dentry->d_inode && !S_ISDIR(dentry->d_inode->i_mode) &&
56553+ ((mode & S_ISUID) || ((mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))))) {
56554+ return generic_fs_handler(dentry, mnt, GR_WRITE | GR_SETID,
56555+ GR_CHMOD_ACL_MSG);
56556+ } else {
56557+ return generic_fs_handler(dentry, mnt, GR_WRITE, GR_CHMOD_ACL_MSG);
56558+ }
56559+}
56560+
56561+__u32
56562+gr_acl_handle_chown(const struct dentry *dentry, const struct vfsmount *mnt)
56563+{
56564+ return generic_fs_handler(dentry, mnt, GR_WRITE, GR_CHOWN_ACL_MSG);
56565+}
56566+
56567+__u32
56568+gr_acl_handle_setxattr(const struct dentry *dentry, const struct vfsmount *mnt)
56569+{
56570+ return generic_fs_handler(dentry, mnt, GR_WRITE, GR_SETXATTR_ACL_MSG);
56571+}
56572+
56573+__u32
56574+gr_acl_handle_execve(const struct dentry *dentry, const struct vfsmount *mnt)
56575+{
56576+ return generic_fs_handler(dentry, mnt, GR_EXEC, GR_EXEC_ACL_MSG);
56577+}
56578+
56579+__u32
56580+gr_acl_handle_unix(const struct dentry *dentry, const struct vfsmount *mnt)
56581+{
56582+ return generic_fs_handler(dentry, mnt, GR_READ | GR_WRITE,
56583+ GR_UNIXCONNECT_ACL_MSG);
56584+}
56585+
56586+/* hardlinks require at minimum create and link permission,
56587+ any additional privilege required is based on the
56588+ privilege of the file being linked to
56589+*/
56590+__u32
56591+gr_acl_handle_link(const struct dentry * new_dentry,
56592+ const struct dentry * parent_dentry,
56593+ const struct vfsmount * parent_mnt,
56594+ const struct dentry * old_dentry,
56595+ const struct vfsmount * old_mnt, const char *to)
56596+{
56597+ __u32 mode;
56598+ __u32 needmode = GR_CREATE | GR_LINK;
56599+ __u32 needaudit = GR_AUDIT_CREATE | GR_AUDIT_LINK;
56600+
56601+ mode =
56602+ gr_check_link(new_dentry, parent_dentry, parent_mnt, old_dentry,
56603+ old_mnt);
56604+
56605+ if (unlikely(((mode & needmode) == needmode) && (mode & needaudit))) {
56606+ gr_log_fs_rbac_str(GR_DO_AUDIT, GR_LINK_ACL_MSG, old_dentry, old_mnt, to);
56607+ return mode;
56608+ } else if (unlikely(((mode & needmode) != needmode) && !(mode & GR_SUPPRESS))) {
56609+ gr_log_fs_rbac_str(GR_DONT_AUDIT, GR_LINK_ACL_MSG, old_dentry, old_mnt, to);
56610+ return 0;
56611+ } else if (unlikely((mode & needmode) != needmode))
56612+ return 0;
56613+
56614+ return 1;
56615+}
56616+
56617+__u32
56618+gr_acl_handle_symlink(const struct dentry * new_dentry,
56619+ const struct dentry * parent_dentry,
56620+ const struct vfsmount * parent_mnt, const char *from)
56621+{
56622+ __u32 needmode = GR_WRITE | GR_CREATE;
56623+ __u32 mode;
56624+
56625+ mode =
56626+ gr_check_create(new_dentry, parent_dentry, parent_mnt,
56627+ GR_CREATE | GR_AUDIT_CREATE |
56628+ GR_WRITE | GR_AUDIT_WRITE | GR_SUPPRESS);
56629+
56630+ if (unlikely(mode & GR_WRITE && mode & GR_AUDITS)) {
56631+ gr_log_fs_str_rbac(GR_DO_AUDIT, GR_SYMLINK_ACL_MSG, from, new_dentry, parent_mnt);
56632+ return mode;
56633+ } else if (unlikely(((mode & needmode) != needmode) && !(mode & GR_SUPPRESS))) {
56634+ gr_log_fs_str_rbac(GR_DONT_AUDIT, GR_SYMLINK_ACL_MSG, from, new_dentry, parent_mnt);
56635+ return 0;
56636+ } else if (unlikely((mode & needmode) != needmode))
56637+ return 0;
56638+
56639+ return (GR_WRITE | GR_CREATE);
56640+}
56641+
56642+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)
56643+{
56644+ __u32 mode;
56645+
56646+ mode = gr_check_create(new_dentry, parent_dentry, parent_mnt, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS);
56647+
56648+ if (unlikely(((mode & (reqmode)) == (reqmode)) && mode & GR_AUDITS)) {
56649+ gr_log_fs_rbac_generic(GR_DO_AUDIT, fmt, new_dentry, parent_mnt);
56650+ return mode;
56651+ } else if (unlikely((mode & (reqmode)) != (reqmode) && !(mode & GR_SUPPRESS))) {
56652+ gr_log_fs_rbac_generic(GR_DONT_AUDIT, fmt, new_dentry, parent_mnt);
56653+ return 0;
56654+ } else if (unlikely((mode & (reqmode)) != (reqmode)))
56655+ return 0;
56656+
56657+ return (reqmode);
56658+}
56659+
56660+__u32
56661+gr_acl_handle_mknod(const struct dentry * new_dentry,
56662+ const struct dentry * parent_dentry,
56663+ const struct vfsmount * parent_mnt,
56664+ const int mode)
56665+{
56666+ __u32 reqmode = GR_WRITE | GR_CREATE;
56667+ if (unlikely((mode & S_ISUID) || ((mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))))
56668+ reqmode |= GR_SETID;
56669+
56670+ return generic_fs_create_handler(new_dentry, parent_dentry, parent_mnt,
56671+ reqmode, GR_MKNOD_ACL_MSG);
56672+}
56673+
56674+__u32
56675+gr_acl_handle_mkdir(const struct dentry *new_dentry,
56676+ const struct dentry *parent_dentry,
56677+ const struct vfsmount *parent_mnt)
56678+{
56679+ return generic_fs_create_handler(new_dentry, parent_dentry, parent_mnt,
56680+ GR_WRITE | GR_CREATE, GR_MKDIR_ACL_MSG);
56681+}
56682+
56683+#define RENAME_CHECK_SUCCESS(old, new) \
56684+ (((old & (GR_WRITE | GR_READ)) == (GR_WRITE | GR_READ)) && \
56685+ ((new & (GR_WRITE | GR_READ)) == (GR_WRITE | GR_READ)))
56686+
56687+int
56688+gr_acl_handle_rename(struct dentry *new_dentry,
56689+ struct dentry *parent_dentry,
56690+ const struct vfsmount *parent_mnt,
56691+ struct dentry *old_dentry,
56692+ struct inode *old_parent_inode,
56693+ struct vfsmount *old_mnt, const char *newname)
56694+{
56695+ __u32 comp1, comp2;
56696+ int error = 0;
56697+
56698+ if (unlikely(!gr_acl_is_enabled()))
56699+ return 0;
56700+
56701+ if (!new_dentry->d_inode) {
56702+ comp1 = gr_check_create(new_dentry, parent_dentry, parent_mnt,
56703+ GR_READ | GR_WRITE | GR_CREATE | GR_AUDIT_READ |
56704+ GR_AUDIT_WRITE | GR_AUDIT_CREATE | GR_SUPPRESS);
56705+ comp2 = gr_search_file(old_dentry, GR_READ | GR_WRITE |
56706+ GR_DELETE | GR_AUDIT_DELETE |
56707+ GR_AUDIT_READ | GR_AUDIT_WRITE |
56708+ GR_SUPPRESS, old_mnt);
56709+ } else {
56710+ comp1 = gr_search_file(new_dentry, GR_READ | GR_WRITE |
56711+ GR_CREATE | GR_DELETE |
56712+ GR_AUDIT_CREATE | GR_AUDIT_DELETE |
56713+ GR_AUDIT_READ | GR_AUDIT_WRITE |
56714+ GR_SUPPRESS, parent_mnt);
56715+ comp2 =
56716+ gr_search_file(old_dentry,
56717+ GR_READ | GR_WRITE | GR_AUDIT_READ |
56718+ GR_DELETE | GR_AUDIT_DELETE |
56719+ GR_AUDIT_WRITE | GR_SUPPRESS, old_mnt);
56720+ }
56721+
56722+ if (RENAME_CHECK_SUCCESS(comp1, comp2) &&
56723+ ((comp1 & GR_AUDITS) || (comp2 & GR_AUDITS)))
56724+ gr_log_fs_rbac_str(GR_DO_AUDIT, GR_RENAME_ACL_MSG, old_dentry, old_mnt, newname);
56725+ else if (!RENAME_CHECK_SUCCESS(comp1, comp2) && !(comp1 & GR_SUPPRESS)
56726+ && !(comp2 & GR_SUPPRESS)) {
56727+ gr_log_fs_rbac_str(GR_DONT_AUDIT, GR_RENAME_ACL_MSG, old_dentry, old_mnt, newname);
56728+ error = -EACCES;
56729+ } else if (unlikely(!RENAME_CHECK_SUCCESS(comp1, comp2)))
56730+ error = -EACCES;
56731+
56732+ return error;
56733+}
56734+
56735+void
56736+gr_acl_handle_exit(void)
56737+{
56738+ u16 id;
56739+ char *rolename;
56740+ struct file *exec_file;
56741+
56742+ if (unlikely(current->acl_sp_role && gr_acl_is_enabled() &&
56743+ !(current->role->roletype & GR_ROLE_PERSIST))) {
56744+ id = current->acl_role_id;
56745+ rolename = current->role->rolename;
56746+ gr_set_acls(1);
56747+ gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_SPROLEL_ACL_MSG, rolename, id);
56748+ }
56749+
56750+ write_lock(&grsec_exec_file_lock);
56751+ exec_file = current->exec_file;
56752+ current->exec_file = NULL;
56753+ write_unlock(&grsec_exec_file_lock);
56754+
56755+ if (exec_file)
56756+ fput(exec_file);
56757+}
56758+
56759+int
56760+gr_acl_handle_procpidmem(const struct task_struct *task)
56761+{
56762+ if (unlikely(!gr_acl_is_enabled()))
56763+ return 0;
56764+
56765+ if (task != current && task->acl->mode & GR_PROTPROCFD)
56766+ return -EACCES;
56767+
56768+ return 0;
56769+}
56770diff --git a/grsecurity/gracl_ip.c b/grsecurity/gracl_ip.c
56771new file mode 100644
56772index 0000000..58800a7
56773--- /dev/null
56774+++ b/grsecurity/gracl_ip.c
56775@@ -0,0 +1,384 @@
56776+#include <linux/kernel.h>
56777+#include <asm/uaccess.h>
56778+#include <asm/errno.h>
56779+#include <net/sock.h>
56780+#include <linux/file.h>
56781+#include <linux/fs.h>
56782+#include <linux/net.h>
56783+#include <linux/in.h>
56784+#include <linux/skbuff.h>
56785+#include <linux/ip.h>
56786+#include <linux/udp.h>
56787+#include <linux/types.h>
56788+#include <linux/sched.h>
56789+#include <linux/netdevice.h>
56790+#include <linux/inetdevice.h>
56791+#include <linux/gracl.h>
56792+#include <linux/grsecurity.h>
56793+#include <linux/grinternal.h>
56794+
56795+#define GR_BIND 0x01
56796+#define GR_CONNECT 0x02
56797+#define GR_INVERT 0x04
56798+#define GR_BINDOVERRIDE 0x08
56799+#define GR_CONNECTOVERRIDE 0x10
56800+#define GR_SOCK_FAMILY 0x20
56801+
56802+static const char * gr_protocols[IPPROTO_MAX] = {
56803+ "ip", "icmp", "igmp", "ggp", "ipencap", "st", "tcp", "cbt",
56804+ "egp", "igp", "bbn-rcc", "nvp", "pup", "argus", "emcon", "xnet",
56805+ "chaos", "udp", "mux", "dcn", "hmp", "prm", "xns-idp", "trunk-1",
56806+ "trunk-2", "leaf-1", "leaf-2", "rdp", "irtp", "iso-tp4", "netblt", "mfe-nsp",
56807+ "merit-inp", "sep", "3pc", "idpr", "xtp", "ddp", "idpr-cmtp", "tp++",
56808+ "il", "ipv6", "sdrp", "ipv6-route", "ipv6-frag", "idrp", "rsvp", "gre",
56809+ "mhrp", "bna", "ipv6-crypt", "ipv6-auth", "i-nlsp", "swipe", "narp", "mobile",
56810+ "tlsp", "skip", "ipv6-icmp", "ipv6-nonxt", "ipv6-opts", "unknown:61", "cftp", "unknown:63",
56811+ "sat-expak", "kryptolan", "rvd", "ippc", "unknown:68", "sat-mon", "visa", "ipcv",
56812+ "cpnx", "cphb", "wsn", "pvp", "br-sat-mon", "sun-nd", "wb-mon", "wb-expak",
56813+ "iso-ip", "vmtp", "secure-vmtp", "vines", "ttp", "nfsnet-igp", "dgp", "tcf",
56814+ "eigrp", "ospf", "sprite-rpc", "larp", "mtp", "ax.25", "ipip", "micp",
56815+ "scc-sp", "etherip", "encap", "unknown:99", "gmtp", "ifmp", "pnni", "pim",
56816+ "aris", "scps", "qnx", "a/n", "ipcomp", "snp", "compaq-peer", "ipx-in-ip",
56817+ "vrrp", "pgm", "unknown:114", "l2tp", "ddx", "iatp", "stp", "srp",
56818+ "uti", "smp", "sm", "ptp", "isis", "fire", "crtp", "crdup",
56819+ "sscopmce", "iplt", "sps", "pipe", "sctp", "fc", "unkown:134", "unknown:135",
56820+ "unknown:136", "unknown:137", "unknown:138", "unknown:139", "unknown:140", "unknown:141", "unknown:142", "unknown:143",
56821+ "unknown:144", "unknown:145", "unknown:146", "unknown:147", "unknown:148", "unknown:149", "unknown:150", "unknown:151",
56822+ "unknown:152", "unknown:153", "unknown:154", "unknown:155", "unknown:156", "unknown:157", "unknown:158", "unknown:159",
56823+ "unknown:160", "unknown:161", "unknown:162", "unknown:163", "unknown:164", "unknown:165", "unknown:166", "unknown:167",
56824+ "unknown:168", "unknown:169", "unknown:170", "unknown:171", "unknown:172", "unknown:173", "unknown:174", "unknown:175",
56825+ "unknown:176", "unknown:177", "unknown:178", "unknown:179", "unknown:180", "unknown:181", "unknown:182", "unknown:183",
56826+ "unknown:184", "unknown:185", "unknown:186", "unknown:187", "unknown:188", "unknown:189", "unknown:190", "unknown:191",
56827+ "unknown:192", "unknown:193", "unknown:194", "unknown:195", "unknown:196", "unknown:197", "unknown:198", "unknown:199",
56828+ "unknown:200", "unknown:201", "unknown:202", "unknown:203", "unknown:204", "unknown:205", "unknown:206", "unknown:207",
56829+ "unknown:208", "unknown:209", "unknown:210", "unknown:211", "unknown:212", "unknown:213", "unknown:214", "unknown:215",
56830+ "unknown:216", "unknown:217", "unknown:218", "unknown:219", "unknown:220", "unknown:221", "unknown:222", "unknown:223",
56831+ "unknown:224", "unknown:225", "unknown:226", "unknown:227", "unknown:228", "unknown:229", "unknown:230", "unknown:231",
56832+ "unknown:232", "unknown:233", "unknown:234", "unknown:235", "unknown:236", "unknown:237", "unknown:238", "unknown:239",
56833+ "unknown:240", "unknown:241", "unknown:242", "unknown:243", "unknown:244", "unknown:245", "unknown:246", "unknown:247",
56834+ "unknown:248", "unknown:249", "unknown:250", "unknown:251", "unknown:252", "unknown:253", "unknown:254", "unknown:255",
56835+ };
56836+
56837+static const char * gr_socktypes[SOCK_MAX] = {
56838+ "unknown:0", "stream", "dgram", "raw", "rdm", "seqpacket", "unknown:6",
56839+ "unknown:7", "unknown:8", "unknown:9", "packet"
56840+ };
56841+
56842+static const char * gr_sockfamilies[AF_MAX+1] = {
56843+ "unspec", "unix", "inet", "ax25", "ipx", "appletalk", "netrom", "bridge", "atmpvc", "x25",
56844+ "inet6", "rose", "decnet", "netbeui", "security", "key", "netlink", "packet", "ash",
56845+ "econet", "atmsvc", "rds", "sna", "irda", "ppox", "wanpipe", "llc", "fam_27", "fam_28",
56846+ "tipc", "bluetooth", "iucv", "rxrpc", "isdn", "phonet", "ieee802154", "ciaf"
56847+ };
56848+
56849+const char *
56850+gr_proto_to_name(unsigned char proto)
56851+{
56852+ return gr_protocols[proto];
56853+}
56854+
56855+const char *
56856+gr_socktype_to_name(unsigned char type)
56857+{
56858+ return gr_socktypes[type];
56859+}
56860+
56861+const char *
56862+gr_sockfamily_to_name(unsigned char family)
56863+{
56864+ return gr_sockfamilies[family];
56865+}
56866+
56867+int
56868+gr_search_socket(const int domain, const int type, const int protocol)
56869+{
56870+ struct acl_subject_label *curr;
56871+ const struct cred *cred = current_cred();
56872+
56873+ if (unlikely(!gr_acl_is_enabled()))
56874+ goto exit;
56875+
56876+ if ((domain < 0) || (type < 0) || (protocol < 0) ||
56877+ (domain >= AF_MAX) || (type >= SOCK_MAX) || (protocol >= IPPROTO_MAX))
56878+ goto exit; // let the kernel handle it
56879+
56880+ curr = current->acl;
56881+
56882+ if (curr->sock_families[domain / 32] & (1 << (domain % 32))) {
56883+ /* the family is allowed, if this is PF_INET allow it only if
56884+ the extra sock type/protocol checks pass */
56885+ if (domain == PF_INET)
56886+ goto inet_check;
56887+ goto exit;
56888+ } else {
56889+ if (curr->mode & (GR_LEARN | GR_INHERITLEARN)) {
56890+ __u32 fakeip = 0;
56891+ security_learn(GR_IP_LEARN_MSG, current->role->rolename,
56892+ current->role->roletype, cred->uid,
56893+ cred->gid, current->exec_file ?
56894+ gr_to_filename(current->exec_file->f_path.dentry,
56895+ current->exec_file->f_path.mnt) :
56896+ curr->filename, curr->filename,
56897+ &fakeip, domain, 0, 0, GR_SOCK_FAMILY,
56898+ &current->signal->saved_ip);
56899+ goto exit;
56900+ }
56901+ goto exit_fail;
56902+ }
56903+
56904+inet_check:
56905+ /* the rest of this checking is for IPv4 only */
56906+ if (!curr->ips)
56907+ goto exit;
56908+
56909+ if ((curr->ip_type & (1 << type)) &&
56910+ (curr->ip_proto[protocol / 32] & (1 << (protocol % 32))))
56911+ goto exit;
56912+
56913+ if (curr->mode & (GR_LEARN | GR_INHERITLEARN)) {
56914+ /* we don't place acls on raw sockets , and sometimes
56915+ dgram/ip sockets are opened for ioctl and not
56916+ bind/connect, so we'll fake a bind learn log */
56917+ if (type == SOCK_RAW || type == SOCK_PACKET) {
56918+ __u32 fakeip = 0;
56919+ security_learn(GR_IP_LEARN_MSG, current->role->rolename,
56920+ current->role->roletype, cred->uid,
56921+ cred->gid, current->exec_file ?
56922+ gr_to_filename(current->exec_file->f_path.dentry,
56923+ current->exec_file->f_path.mnt) :
56924+ curr->filename, curr->filename,
56925+ &fakeip, 0, type,
56926+ protocol, GR_CONNECT, &current->signal->saved_ip);
56927+ } else if ((type == SOCK_DGRAM) && (protocol == IPPROTO_IP)) {
56928+ __u32 fakeip = 0;
56929+ security_learn(GR_IP_LEARN_MSG, current->role->rolename,
56930+ current->role->roletype, cred->uid,
56931+ cred->gid, current->exec_file ?
56932+ gr_to_filename(current->exec_file->f_path.dentry,
56933+ current->exec_file->f_path.mnt) :
56934+ curr->filename, curr->filename,
56935+ &fakeip, 0, type,
56936+ protocol, GR_BIND, &current->signal->saved_ip);
56937+ }
56938+ /* we'll log when they use connect or bind */
56939+ goto exit;
56940+ }
56941+
56942+exit_fail:
56943+ if (domain == PF_INET)
56944+ gr_log_str3(GR_DONT_AUDIT, GR_SOCK_MSG, gr_sockfamily_to_name(domain),
56945+ gr_socktype_to_name(type), gr_proto_to_name(protocol));
56946+ else
56947+ gr_log_str2_int(GR_DONT_AUDIT, GR_SOCK_NOINET_MSG, gr_sockfamily_to_name(domain),
56948+ gr_socktype_to_name(type), protocol);
56949+
56950+ return 0;
56951+exit:
56952+ return 1;
56953+}
56954+
56955+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)
56956+{
56957+ if ((ip->mode & mode) &&
56958+ (ip_port >= ip->low) &&
56959+ (ip_port <= ip->high) &&
56960+ ((ntohl(ip_addr) & our_netmask) ==
56961+ (ntohl(our_addr) & our_netmask))
56962+ && (ip->proto[protocol / 32] & (1 << (protocol % 32)))
56963+ && (ip->type & (1 << type))) {
56964+ if (ip->mode & GR_INVERT)
56965+ return 2; // specifically denied
56966+ else
56967+ return 1; // allowed
56968+ }
56969+
56970+ return 0; // not specifically allowed, may continue parsing
56971+}
56972+
56973+static int
56974+gr_search_connectbind(const int full_mode, struct sock *sk,
56975+ struct sockaddr_in *addr, const int type)
56976+{
56977+ char iface[IFNAMSIZ] = {0};
56978+ struct acl_subject_label *curr;
56979+ struct acl_ip_label *ip;
56980+ struct inet_sock *isk;
56981+ struct net_device *dev;
56982+ struct in_device *idev;
56983+ unsigned long i;
56984+ int ret;
56985+ int mode = full_mode & (GR_BIND | GR_CONNECT);
56986+ __u32 ip_addr = 0;
56987+ __u32 our_addr;
56988+ __u32 our_netmask;
56989+ char *p;
56990+ __u16 ip_port = 0;
56991+ const struct cred *cred = current_cred();
56992+
56993+ if (unlikely(!gr_acl_is_enabled() || sk->sk_family != PF_INET))
56994+ return 0;
56995+
56996+ curr = current->acl;
56997+ isk = inet_sk(sk);
56998+
56999+ /* INADDR_ANY overriding for binds, inaddr_any_override is already in network order */
57000+ if ((full_mode & GR_BINDOVERRIDE) && addr->sin_addr.s_addr == htonl(INADDR_ANY) && curr->inaddr_any_override != 0)
57001+ addr->sin_addr.s_addr = curr->inaddr_any_override;
57002+ if ((full_mode & GR_CONNECT) && isk->inet_saddr == htonl(INADDR_ANY) && curr->inaddr_any_override != 0) {
57003+ struct sockaddr_in saddr;
57004+ int err;
57005+
57006+ saddr.sin_family = AF_INET;
57007+ saddr.sin_addr.s_addr = curr->inaddr_any_override;
57008+ saddr.sin_port = isk->inet_sport;
57009+
57010+ err = security_socket_bind(sk->sk_socket, (struct sockaddr *)&saddr, sizeof(struct sockaddr_in));
57011+ if (err)
57012+ return err;
57013+
57014+ err = sk->sk_socket->ops->bind(sk->sk_socket, (struct sockaddr *)&saddr, sizeof(struct sockaddr_in));
57015+ if (err)
57016+ return err;
57017+ }
57018+
57019+ if (!curr->ips)
57020+ return 0;
57021+
57022+ ip_addr = addr->sin_addr.s_addr;
57023+ ip_port = ntohs(addr->sin_port);
57024+
57025+ if (curr->mode & (GR_LEARN | GR_INHERITLEARN)) {
57026+ security_learn(GR_IP_LEARN_MSG, current->role->rolename,
57027+ current->role->roletype, cred->uid,
57028+ cred->gid, current->exec_file ?
57029+ gr_to_filename(current->exec_file->f_path.dentry,
57030+ current->exec_file->f_path.mnt) :
57031+ curr->filename, curr->filename,
57032+ &ip_addr, ip_port, type,
57033+ sk->sk_protocol, mode, &current->signal->saved_ip);
57034+ return 0;
57035+ }
57036+
57037+ for (i = 0; i < curr->ip_num; i++) {
57038+ ip = *(curr->ips + i);
57039+ if (ip->iface != NULL) {
57040+ strncpy(iface, ip->iface, IFNAMSIZ - 1);
57041+ p = strchr(iface, ':');
57042+ if (p != NULL)
57043+ *p = '\0';
57044+ dev = dev_get_by_name(sock_net(sk), iface);
57045+ if (dev == NULL)
57046+ continue;
57047+ idev = in_dev_get(dev);
57048+ if (idev == NULL) {
57049+ dev_put(dev);
57050+ continue;
57051+ }
57052+ rcu_read_lock();
57053+ for_ifa(idev) {
57054+ if (!strcmp(ip->iface, ifa->ifa_label)) {
57055+ our_addr = ifa->ifa_address;
57056+ our_netmask = 0xffffffff;
57057+ ret = check_ip_policy(ip, ip_addr, ip_port, sk->sk_protocol, mode, type, our_addr, our_netmask);
57058+ if (ret == 1) {
57059+ rcu_read_unlock();
57060+ in_dev_put(idev);
57061+ dev_put(dev);
57062+ return 0;
57063+ } else if (ret == 2) {
57064+ rcu_read_unlock();
57065+ in_dev_put(idev);
57066+ dev_put(dev);
57067+ goto denied;
57068+ }
57069+ }
57070+ } endfor_ifa(idev);
57071+ rcu_read_unlock();
57072+ in_dev_put(idev);
57073+ dev_put(dev);
57074+ } else {
57075+ our_addr = ip->addr;
57076+ our_netmask = ip->netmask;
57077+ ret = check_ip_policy(ip, ip_addr, ip_port, sk->sk_protocol, mode, type, our_addr, our_netmask);
57078+ if (ret == 1)
57079+ return 0;
57080+ else if (ret == 2)
57081+ goto denied;
57082+ }
57083+ }
57084+
57085+denied:
57086+ if (mode == GR_BIND)
57087+ 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));
57088+ else if (mode == GR_CONNECT)
57089+ 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));
57090+
57091+ return -EACCES;
57092+}
57093+
57094+int
57095+gr_search_connect(struct socket *sock, struct sockaddr_in *addr)
57096+{
57097+ /* always allow disconnection of dgram sockets with connect */
57098+ if (addr->sin_family == AF_UNSPEC)
57099+ return 0;
57100+ return gr_search_connectbind(GR_CONNECT | GR_CONNECTOVERRIDE, sock->sk, addr, sock->type);
57101+}
57102+
57103+int
57104+gr_search_bind(struct socket *sock, struct sockaddr_in *addr)
57105+{
57106+ return gr_search_connectbind(GR_BIND | GR_BINDOVERRIDE, sock->sk, addr, sock->type);
57107+}
57108+
57109+int gr_search_listen(struct socket *sock)
57110+{
57111+ struct sock *sk = sock->sk;
57112+ struct sockaddr_in addr;
57113+
57114+ addr.sin_addr.s_addr = inet_sk(sk)->inet_saddr;
57115+ addr.sin_port = inet_sk(sk)->inet_sport;
57116+
57117+ return gr_search_connectbind(GR_BIND | GR_CONNECTOVERRIDE, sock->sk, &addr, sock->type);
57118+}
57119+
57120+int gr_search_accept(struct socket *sock)
57121+{
57122+ struct sock *sk = sock->sk;
57123+ struct sockaddr_in addr;
57124+
57125+ addr.sin_addr.s_addr = inet_sk(sk)->inet_saddr;
57126+ addr.sin_port = inet_sk(sk)->inet_sport;
57127+
57128+ return gr_search_connectbind(GR_BIND | GR_CONNECTOVERRIDE, sock->sk, &addr, sock->type);
57129+}
57130+
57131+int
57132+gr_search_udp_sendmsg(struct sock *sk, struct sockaddr_in *addr)
57133+{
57134+ if (addr)
57135+ return gr_search_connectbind(GR_CONNECT, sk, addr, SOCK_DGRAM);
57136+ else {
57137+ struct sockaddr_in sin;
57138+ const struct inet_sock *inet = inet_sk(sk);
57139+
57140+ sin.sin_addr.s_addr = inet->inet_daddr;
57141+ sin.sin_port = inet->inet_dport;
57142+
57143+ return gr_search_connectbind(GR_CONNECT | GR_CONNECTOVERRIDE, sk, &sin, SOCK_DGRAM);
57144+ }
57145+}
57146+
57147+int
57148+gr_search_udp_recvmsg(struct sock *sk, const struct sk_buff *skb)
57149+{
57150+ struct sockaddr_in sin;
57151+
57152+ if (unlikely(skb->len < sizeof (struct udphdr)))
57153+ return 0; // skip this packet
57154+
57155+ sin.sin_addr.s_addr = ip_hdr(skb)->saddr;
57156+ sin.sin_port = udp_hdr(skb)->source;
57157+
57158+ return gr_search_connectbind(GR_CONNECT | GR_CONNECTOVERRIDE, sk, &sin, SOCK_DGRAM);
57159+}
57160diff --git a/grsecurity/gracl_learn.c b/grsecurity/gracl_learn.c
57161new file mode 100644
57162index 0000000..25f54ef
57163--- /dev/null
57164+++ b/grsecurity/gracl_learn.c
57165@@ -0,0 +1,207 @@
57166+#include <linux/kernel.h>
57167+#include <linux/mm.h>
57168+#include <linux/sched.h>
57169+#include <linux/poll.h>
57170+#include <linux/string.h>
57171+#include <linux/file.h>
57172+#include <linux/types.h>
57173+#include <linux/vmalloc.h>
57174+#include <linux/grinternal.h>
57175+
57176+extern ssize_t write_grsec_handler(struct file * file, const char __user * buf,
57177+ size_t count, loff_t *ppos);
57178+extern int gr_acl_is_enabled(void);
57179+
57180+static DECLARE_WAIT_QUEUE_HEAD(learn_wait);
57181+static int gr_learn_attached;
57182+
57183+/* use a 512k buffer */
57184+#define LEARN_BUFFER_SIZE (512 * 1024)
57185+
57186+static DEFINE_SPINLOCK(gr_learn_lock);
57187+static DEFINE_MUTEX(gr_learn_user_mutex);
57188+
57189+/* we need to maintain two buffers, so that the kernel context of grlearn
57190+ uses a semaphore around the userspace copying, and the other kernel contexts
57191+ use a spinlock when copying into the buffer, since they cannot sleep
57192+*/
57193+static char *learn_buffer;
57194+static char *learn_buffer_user;
57195+static int learn_buffer_len;
57196+static int learn_buffer_user_len;
57197+
57198+static ssize_t
57199+read_learn(struct file *file, char __user * buf, size_t count, loff_t * ppos)
57200+{
57201+ DECLARE_WAITQUEUE(wait, current);
57202+ ssize_t retval = 0;
57203+
57204+ add_wait_queue(&learn_wait, &wait);
57205+ set_current_state(TASK_INTERRUPTIBLE);
57206+ do {
57207+ mutex_lock(&gr_learn_user_mutex);
57208+ spin_lock(&gr_learn_lock);
57209+ if (learn_buffer_len)
57210+ break;
57211+ spin_unlock(&gr_learn_lock);
57212+ mutex_unlock(&gr_learn_user_mutex);
57213+ if (file->f_flags & O_NONBLOCK) {
57214+ retval = -EAGAIN;
57215+ goto out;
57216+ }
57217+ if (signal_pending(current)) {
57218+ retval = -ERESTARTSYS;
57219+ goto out;
57220+ }
57221+
57222+ schedule();
57223+ } while (1);
57224+
57225+ memcpy(learn_buffer_user, learn_buffer, learn_buffer_len);
57226+ learn_buffer_user_len = learn_buffer_len;
57227+ retval = learn_buffer_len;
57228+ learn_buffer_len = 0;
57229+
57230+ spin_unlock(&gr_learn_lock);
57231+
57232+ if (copy_to_user(buf, learn_buffer_user, learn_buffer_user_len))
57233+ retval = -EFAULT;
57234+
57235+ mutex_unlock(&gr_learn_user_mutex);
57236+out:
57237+ set_current_state(TASK_RUNNING);
57238+ remove_wait_queue(&learn_wait, &wait);
57239+ return retval;
57240+}
57241+
57242+static unsigned int
57243+poll_learn(struct file * file, poll_table * wait)
57244+{
57245+ poll_wait(file, &learn_wait, wait);
57246+
57247+ if (learn_buffer_len)
57248+ return (POLLIN | POLLRDNORM);
57249+
57250+ return 0;
57251+}
57252+
57253+void
57254+gr_clear_learn_entries(void)
57255+{
57256+ char *tmp;
57257+
57258+ mutex_lock(&gr_learn_user_mutex);
57259+ spin_lock(&gr_learn_lock);
57260+ tmp = learn_buffer;
57261+ learn_buffer = NULL;
57262+ spin_unlock(&gr_learn_lock);
57263+ if (tmp)
57264+ vfree(tmp);
57265+ if (learn_buffer_user != NULL) {
57266+ vfree(learn_buffer_user);
57267+ learn_buffer_user = NULL;
57268+ }
57269+ learn_buffer_len = 0;
57270+ mutex_unlock(&gr_learn_user_mutex);
57271+
57272+ return;
57273+}
57274+
57275+void
57276+gr_add_learn_entry(const char *fmt, ...)
57277+{
57278+ va_list args;
57279+ unsigned int len;
57280+
57281+ if (!gr_learn_attached)
57282+ return;
57283+
57284+ spin_lock(&gr_learn_lock);
57285+
57286+ /* leave a gap at the end so we know when it's "full" but don't have to
57287+ compute the exact length of the string we're trying to append
57288+ */
57289+ if (learn_buffer_len > LEARN_BUFFER_SIZE - 16384) {
57290+ spin_unlock(&gr_learn_lock);
57291+ wake_up_interruptible(&learn_wait);
57292+ return;
57293+ }
57294+ if (learn_buffer == NULL) {
57295+ spin_unlock(&gr_learn_lock);
57296+ return;
57297+ }
57298+
57299+ va_start(args, fmt);
57300+ len = vsnprintf(learn_buffer + learn_buffer_len, LEARN_BUFFER_SIZE - learn_buffer_len, fmt, args);
57301+ va_end(args);
57302+
57303+ learn_buffer_len += len + 1;
57304+
57305+ spin_unlock(&gr_learn_lock);
57306+ wake_up_interruptible(&learn_wait);
57307+
57308+ return;
57309+}
57310+
57311+static int
57312+open_learn(struct inode *inode, struct file *file)
57313+{
57314+ if (file->f_mode & FMODE_READ && gr_learn_attached)
57315+ return -EBUSY;
57316+ if (file->f_mode & FMODE_READ) {
57317+ int retval = 0;
57318+ mutex_lock(&gr_learn_user_mutex);
57319+ if (learn_buffer == NULL)
57320+ learn_buffer = vmalloc(LEARN_BUFFER_SIZE);
57321+ if (learn_buffer_user == NULL)
57322+ learn_buffer_user = vmalloc(LEARN_BUFFER_SIZE);
57323+ if (learn_buffer == NULL) {
57324+ retval = -ENOMEM;
57325+ goto out_error;
57326+ }
57327+ if (learn_buffer_user == NULL) {
57328+ retval = -ENOMEM;
57329+ goto out_error;
57330+ }
57331+ learn_buffer_len = 0;
57332+ learn_buffer_user_len = 0;
57333+ gr_learn_attached = 1;
57334+out_error:
57335+ mutex_unlock(&gr_learn_user_mutex);
57336+ return retval;
57337+ }
57338+ return 0;
57339+}
57340+
57341+static int
57342+close_learn(struct inode *inode, struct file *file)
57343+{
57344+ if (file->f_mode & FMODE_READ) {
57345+ char *tmp = NULL;
57346+ mutex_lock(&gr_learn_user_mutex);
57347+ spin_lock(&gr_learn_lock);
57348+ tmp = learn_buffer;
57349+ learn_buffer = NULL;
57350+ spin_unlock(&gr_learn_lock);
57351+ if (tmp)
57352+ vfree(tmp);
57353+ if (learn_buffer_user != NULL) {
57354+ vfree(learn_buffer_user);
57355+ learn_buffer_user = NULL;
57356+ }
57357+ learn_buffer_len = 0;
57358+ learn_buffer_user_len = 0;
57359+ gr_learn_attached = 0;
57360+ mutex_unlock(&gr_learn_user_mutex);
57361+ }
57362+
57363+ return 0;
57364+}
57365+
57366+const struct file_operations grsec_fops = {
57367+ .read = read_learn,
57368+ .write = write_grsec_handler,
57369+ .open = open_learn,
57370+ .release = close_learn,
57371+ .poll = poll_learn,
57372+};
57373diff --git a/grsecurity/gracl_res.c b/grsecurity/gracl_res.c
57374new file mode 100644
57375index 0000000..39645c9
57376--- /dev/null
57377+++ b/grsecurity/gracl_res.c
57378@@ -0,0 +1,68 @@
57379+#include <linux/kernel.h>
57380+#include <linux/sched.h>
57381+#include <linux/gracl.h>
57382+#include <linux/grinternal.h>
57383+
57384+static const char *restab_log[] = {
57385+ [RLIMIT_CPU] = "RLIMIT_CPU",
57386+ [RLIMIT_FSIZE] = "RLIMIT_FSIZE",
57387+ [RLIMIT_DATA] = "RLIMIT_DATA",
57388+ [RLIMIT_STACK] = "RLIMIT_STACK",
57389+ [RLIMIT_CORE] = "RLIMIT_CORE",
57390+ [RLIMIT_RSS] = "RLIMIT_RSS",
57391+ [RLIMIT_NPROC] = "RLIMIT_NPROC",
57392+ [RLIMIT_NOFILE] = "RLIMIT_NOFILE",
57393+ [RLIMIT_MEMLOCK] = "RLIMIT_MEMLOCK",
57394+ [RLIMIT_AS] = "RLIMIT_AS",
57395+ [RLIMIT_LOCKS] = "RLIMIT_LOCKS",
57396+ [RLIMIT_SIGPENDING] = "RLIMIT_SIGPENDING",
57397+ [RLIMIT_MSGQUEUE] = "RLIMIT_MSGQUEUE",
57398+ [RLIMIT_NICE] = "RLIMIT_NICE",
57399+ [RLIMIT_RTPRIO] = "RLIMIT_RTPRIO",
57400+ [RLIMIT_RTTIME] = "RLIMIT_RTTIME",
57401+ [GR_CRASH_RES] = "RLIMIT_CRASH"
57402+};
57403+
57404+void
57405+gr_log_resource(const struct task_struct *task,
57406+ const int res, const unsigned long wanted, const int gt)
57407+{
57408+ const struct cred *cred;
57409+ unsigned long rlim;
57410+
57411+ if (!gr_acl_is_enabled() && !grsec_resource_logging)
57412+ return;
57413+
57414+ // not yet supported resource
57415+ if (unlikely(!restab_log[res]))
57416+ return;
57417+
57418+ if (res == RLIMIT_CPU || res == RLIMIT_RTTIME)
57419+ rlim = task_rlimit_max(task, res);
57420+ else
57421+ rlim = task_rlimit(task, res);
57422+
57423+ if (likely((rlim == RLIM_INFINITY) || (gt && wanted <= rlim) || (!gt && wanted < rlim)))
57424+ return;
57425+
57426+ rcu_read_lock();
57427+ cred = __task_cred(task);
57428+
57429+ if (res == RLIMIT_NPROC &&
57430+ (cap_raised(cred->cap_effective, CAP_SYS_ADMIN) ||
57431+ cap_raised(cred->cap_effective, CAP_SYS_RESOURCE)))
57432+ goto out_rcu_unlock;
57433+ else if (res == RLIMIT_MEMLOCK &&
57434+ cap_raised(cred->cap_effective, CAP_IPC_LOCK))
57435+ goto out_rcu_unlock;
57436+ else if (res == RLIMIT_NICE && cap_raised(cred->cap_effective, CAP_SYS_NICE))
57437+ goto out_rcu_unlock;
57438+ rcu_read_unlock();
57439+
57440+ gr_log_res_ulong2_str(GR_DONT_AUDIT, GR_RESOURCE_MSG, task, wanted, restab_log[res], rlim);
57441+
57442+ return;
57443+out_rcu_unlock:
57444+ rcu_read_unlock();
57445+ return;
57446+}
57447diff --git a/grsecurity/gracl_segv.c b/grsecurity/gracl_segv.c
57448new file mode 100644
57449index 0000000..25197e9
57450--- /dev/null
57451+++ b/grsecurity/gracl_segv.c
57452@@ -0,0 +1,299 @@
57453+#include <linux/kernel.h>
57454+#include <linux/mm.h>
57455+#include <asm/uaccess.h>
57456+#include <asm/errno.h>
57457+#include <asm/mman.h>
57458+#include <net/sock.h>
57459+#include <linux/file.h>
57460+#include <linux/fs.h>
57461+#include <linux/net.h>
57462+#include <linux/in.h>
57463+#include <linux/slab.h>
57464+#include <linux/types.h>
57465+#include <linux/sched.h>
57466+#include <linux/timer.h>
57467+#include <linux/gracl.h>
57468+#include <linux/grsecurity.h>
57469+#include <linux/grinternal.h>
57470+
57471+static struct crash_uid *uid_set;
57472+static unsigned short uid_used;
57473+static DEFINE_SPINLOCK(gr_uid_lock);
57474+extern rwlock_t gr_inode_lock;
57475+extern struct acl_subject_label *
57476+ lookup_acl_subj_label(const ino_t inode, const dev_t dev,
57477+ struct acl_role_label *role);
57478+
57479+#ifdef CONFIG_BTRFS_FS
57480+extern dev_t get_btrfs_dev_from_inode(struct inode *inode);
57481+extern int btrfs_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat);
57482+#endif
57483+
57484+static inline dev_t __get_dev(const struct dentry *dentry)
57485+{
57486+#ifdef CONFIG_BTRFS_FS
57487+ if (dentry->d_inode->i_op && dentry->d_inode->i_op->getattr == &btrfs_getattr)
57488+ return get_btrfs_dev_from_inode(dentry->d_inode);
57489+ else
57490+#endif
57491+ return dentry->d_inode->i_sb->s_dev;
57492+}
57493+
57494+int
57495+gr_init_uidset(void)
57496+{
57497+ uid_set =
57498+ kmalloc(GR_UIDTABLE_MAX * sizeof (struct crash_uid), GFP_KERNEL);
57499+ uid_used = 0;
57500+
57501+ return uid_set ? 1 : 0;
57502+}
57503+
57504+void
57505+gr_free_uidset(void)
57506+{
57507+ if (uid_set)
57508+ kfree(uid_set);
57509+
57510+ return;
57511+}
57512+
57513+int
57514+gr_find_uid(const uid_t uid)
57515+{
57516+ struct crash_uid *tmp = uid_set;
57517+ uid_t buid;
57518+ int low = 0, high = uid_used - 1, mid;
57519+
57520+ while (high >= low) {
57521+ mid = (low + high) >> 1;
57522+ buid = tmp[mid].uid;
57523+ if (buid == uid)
57524+ return mid;
57525+ if (buid > uid)
57526+ high = mid - 1;
57527+ if (buid < uid)
57528+ low = mid + 1;
57529+ }
57530+
57531+ return -1;
57532+}
57533+
57534+static __inline__ void
57535+gr_insertsort(void)
57536+{
57537+ unsigned short i, j;
57538+ struct crash_uid index;
57539+
57540+ for (i = 1; i < uid_used; i++) {
57541+ index = uid_set[i];
57542+ j = i;
57543+ while ((j > 0) && uid_set[j - 1].uid > index.uid) {
57544+ uid_set[j] = uid_set[j - 1];
57545+ j--;
57546+ }
57547+ uid_set[j] = index;
57548+ }
57549+
57550+ return;
57551+}
57552+
57553+static __inline__ void
57554+gr_insert_uid(const uid_t uid, const unsigned long expires)
57555+{
57556+ int loc;
57557+
57558+ if (uid_used == GR_UIDTABLE_MAX)
57559+ return;
57560+
57561+ loc = gr_find_uid(uid);
57562+
57563+ if (loc >= 0) {
57564+ uid_set[loc].expires = expires;
57565+ return;
57566+ }
57567+
57568+ uid_set[uid_used].uid = uid;
57569+ uid_set[uid_used].expires = expires;
57570+ uid_used++;
57571+
57572+ gr_insertsort();
57573+
57574+ return;
57575+}
57576+
57577+void
57578+gr_remove_uid(const unsigned short loc)
57579+{
57580+ unsigned short i;
57581+
57582+ for (i = loc + 1; i < uid_used; i++)
57583+ uid_set[i - 1] = uid_set[i];
57584+
57585+ uid_used--;
57586+
57587+ return;
57588+}
57589+
57590+int
57591+gr_check_crash_uid(const uid_t uid)
57592+{
57593+ int loc;
57594+ int ret = 0;
57595+
57596+ if (unlikely(!gr_acl_is_enabled()))
57597+ return 0;
57598+
57599+ spin_lock(&gr_uid_lock);
57600+ loc = gr_find_uid(uid);
57601+
57602+ if (loc < 0)
57603+ goto out_unlock;
57604+
57605+ if (time_before_eq(uid_set[loc].expires, get_seconds()))
57606+ gr_remove_uid(loc);
57607+ else
57608+ ret = 1;
57609+
57610+out_unlock:
57611+ spin_unlock(&gr_uid_lock);
57612+ return ret;
57613+}
57614+
57615+static __inline__ int
57616+proc_is_setxid(const struct cred *cred)
57617+{
57618+ if (!uid_eq(cred->uid, cred->euid) || !uid_eq(cred->uid, cred->suid) ||
57619+ !uid_eq(cred->uid, cred->fsuid))
57620+ return 1;
57621+ if (!uid_eq(cred->gid, cred->egid) || !uid_eq(cred->gid, cred->sgid) ||
57622+ !uid_eq(cred->gid, cred->fsgid))
57623+ return 1;
57624+
57625+ return 0;
57626+}
57627+
57628+extern int gr_fake_force_sig(int sig, struct task_struct *t);
57629+
57630+void
57631+gr_handle_crash(struct task_struct *task, const int sig)
57632+{
57633+ struct acl_subject_label *curr;
57634+ struct task_struct *tsk, *tsk2;
57635+ const struct cred *cred;
57636+ const struct cred *cred2;
57637+
57638+ if (sig != SIGSEGV && sig != SIGKILL && sig != SIGBUS && sig != SIGILL)
57639+ return;
57640+
57641+ if (unlikely(!gr_acl_is_enabled()))
57642+ return;
57643+
57644+ curr = task->acl;
57645+
57646+ if (!(curr->resmask & (1 << GR_CRASH_RES)))
57647+ return;
57648+
57649+ if (time_before_eq(curr->expires, get_seconds())) {
57650+ curr->expires = 0;
57651+ curr->crashes = 0;
57652+ }
57653+
57654+ curr->crashes++;
57655+
57656+ if (!curr->expires)
57657+ curr->expires = get_seconds() + curr->res[GR_CRASH_RES].rlim_max;
57658+
57659+ if ((curr->crashes >= curr->res[GR_CRASH_RES].rlim_cur) &&
57660+ time_after(curr->expires, get_seconds())) {
57661+ rcu_read_lock();
57662+ cred = __task_cred(task);
57663+ if (!uid_eq(cred->uid, GLOBAL_ROOT_UID) && proc_is_setxid(cred)) {
57664+ gr_log_crash1(GR_DONT_AUDIT, GR_SEGVSTART_ACL_MSG, task, curr->res[GR_CRASH_RES].rlim_max);
57665+ spin_lock(&gr_uid_lock);
57666+ gr_insert_uid(cred->uid, curr->expires);
57667+ spin_unlock(&gr_uid_lock);
57668+ curr->expires = 0;
57669+ curr->crashes = 0;
57670+ read_lock(&tasklist_lock);
57671+ do_each_thread(tsk2, tsk) {
57672+ cred2 = __task_cred(tsk);
57673+ if (tsk != task && uid_eq(cred2->uid, cred->uid))
57674+ gr_fake_force_sig(SIGKILL, tsk);
57675+ } while_each_thread(tsk2, tsk);
57676+ read_unlock(&tasklist_lock);
57677+ } else {
57678+ gr_log_crash2(GR_DONT_AUDIT, GR_SEGVNOSUID_ACL_MSG, task, curr->res[GR_CRASH_RES].rlim_max);
57679+ read_lock(&tasklist_lock);
57680+ read_lock(&grsec_exec_file_lock);
57681+ do_each_thread(tsk2, tsk) {
57682+ if (likely(tsk != task)) {
57683+ // if this thread has the same subject as the one that triggered
57684+ // RES_CRASH and it's the same binary, kill it
57685+ if (tsk->acl == task->acl && tsk->exec_file == task->exec_file)
57686+ gr_fake_force_sig(SIGKILL, tsk);
57687+ }
57688+ } while_each_thread(tsk2, tsk);
57689+ read_unlock(&grsec_exec_file_lock);
57690+ read_unlock(&tasklist_lock);
57691+ }
57692+ rcu_read_unlock();
57693+ }
57694+
57695+ return;
57696+}
57697+
57698+int
57699+gr_check_crash_exec(const struct file *filp)
57700+{
57701+ struct acl_subject_label *curr;
57702+
57703+ if (unlikely(!gr_acl_is_enabled()))
57704+ return 0;
57705+
57706+ read_lock(&gr_inode_lock);
57707+ curr = lookup_acl_subj_label(filp->f_path.dentry->d_inode->i_ino,
57708+ __get_dev(filp->f_path.dentry),
57709+ current->role);
57710+ read_unlock(&gr_inode_lock);
57711+
57712+ if (!curr || !(curr->resmask & (1 << GR_CRASH_RES)) ||
57713+ (!curr->crashes && !curr->expires))
57714+ return 0;
57715+
57716+ if ((curr->crashes >= curr->res[GR_CRASH_RES].rlim_cur) &&
57717+ time_after(curr->expires, get_seconds()))
57718+ return 1;
57719+ else if (time_before_eq(curr->expires, get_seconds())) {
57720+ curr->crashes = 0;
57721+ curr->expires = 0;
57722+ }
57723+
57724+ return 0;
57725+}
57726+
57727+void
57728+gr_handle_alertkill(struct task_struct *task)
57729+{
57730+ struct acl_subject_label *curracl;
57731+ __u32 curr_ip;
57732+ struct task_struct *p, *p2;
57733+
57734+ if (unlikely(!gr_acl_is_enabled()))
57735+ return;
57736+
57737+ curracl = task->acl;
57738+ curr_ip = task->signal->curr_ip;
57739+
57740+ if ((curracl->mode & GR_KILLIPPROC) && curr_ip) {
57741+ read_lock(&tasklist_lock);
57742+ do_each_thread(p2, p) {
57743+ if (p->signal->curr_ip == curr_ip)
57744+ gr_fake_force_sig(SIGKILL, p);
57745+ } while_each_thread(p2, p);
57746+ read_unlock(&tasklist_lock);
57747+ } else if (curracl->mode & GR_KILLPROC)
57748+ gr_fake_force_sig(SIGKILL, task);
57749+
57750+ return;
57751+}
57752diff --git a/grsecurity/gracl_shm.c b/grsecurity/gracl_shm.c
57753new file mode 100644
57754index 0000000..9d83a69
57755--- /dev/null
57756+++ b/grsecurity/gracl_shm.c
57757@@ -0,0 +1,40 @@
57758+#include <linux/kernel.h>
57759+#include <linux/mm.h>
57760+#include <linux/sched.h>
57761+#include <linux/file.h>
57762+#include <linux/ipc.h>
57763+#include <linux/gracl.h>
57764+#include <linux/grsecurity.h>
57765+#include <linux/grinternal.h>
57766+
57767+int
57768+gr_handle_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
57769+ const time_t shm_createtime, const uid_t cuid, const int shmid)
57770+{
57771+ struct task_struct *task;
57772+
57773+ if (!gr_acl_is_enabled())
57774+ return 1;
57775+
57776+ rcu_read_lock();
57777+ read_lock(&tasklist_lock);
57778+
57779+ task = find_task_by_vpid(shm_cprid);
57780+
57781+ if (unlikely(!task))
57782+ task = find_task_by_vpid(shm_lapid);
57783+
57784+ if (unlikely(task && (time_before_eq((unsigned long)task->start_time.tv_sec, (unsigned long)shm_createtime) ||
57785+ (task->pid == shm_lapid)) &&
57786+ (task->acl->mode & GR_PROTSHM) &&
57787+ (task->acl != current->acl))) {
57788+ read_unlock(&tasklist_lock);
57789+ rcu_read_unlock();
57790+ gr_log_int3(GR_DONT_AUDIT, GR_SHMAT_ACL_MSG, cuid, shm_cprid, shmid);
57791+ return 0;
57792+ }
57793+ read_unlock(&tasklist_lock);
57794+ rcu_read_unlock();
57795+
57796+ return 1;
57797+}
57798diff --git a/grsecurity/grsec_chdir.c b/grsecurity/grsec_chdir.c
57799new file mode 100644
57800index 0000000..bc0be01
57801--- /dev/null
57802+++ b/grsecurity/grsec_chdir.c
57803@@ -0,0 +1,19 @@
57804+#include <linux/kernel.h>
57805+#include <linux/sched.h>
57806+#include <linux/fs.h>
57807+#include <linux/file.h>
57808+#include <linux/grsecurity.h>
57809+#include <linux/grinternal.h>
57810+
57811+void
57812+gr_log_chdir(const struct dentry *dentry, const struct vfsmount *mnt)
57813+{
57814+#ifdef CONFIG_GRKERNSEC_AUDIT_CHDIR
57815+ if ((grsec_enable_chdir && grsec_enable_group &&
57816+ in_group_p(grsec_audit_gid)) || (grsec_enable_chdir &&
57817+ !grsec_enable_group)) {
57818+ gr_log_fs_generic(GR_DO_AUDIT, GR_CHDIR_AUDIT_MSG, dentry, mnt);
57819+ }
57820+#endif
57821+ return;
57822+}
57823diff --git a/grsecurity/grsec_chroot.c b/grsecurity/grsec_chroot.c
57824new file mode 100644
57825index 0000000..9807ee2
57826--- /dev/null
57827+++ b/grsecurity/grsec_chroot.c
57828@@ -0,0 +1,368 @@
57829+#include <linux/kernel.h>
57830+#include <linux/module.h>
57831+#include <linux/sched.h>
57832+#include <linux/file.h>
57833+#include <linux/fs.h>
57834+#include <linux/mount.h>
57835+#include <linux/types.h>
57836+#include "../fs/mount.h"
57837+#include <linux/grsecurity.h>
57838+#include <linux/grinternal.h>
57839+
57840+void gr_set_chroot_entries(struct task_struct *task, struct path *path)
57841+{
57842+#ifdef CONFIG_GRKERNSEC
57843+ if (task->pid > 1 && path->dentry != init_task.fs->root.dentry &&
57844+ path->dentry != task->nsproxy->mnt_ns->root->mnt.mnt_root)
57845+ task->gr_is_chrooted = 1;
57846+ else
57847+ task->gr_is_chrooted = 0;
57848+
57849+ task->gr_chroot_dentry = path->dentry;
57850+#endif
57851+ return;
57852+}
57853+
57854+void gr_clear_chroot_entries(struct task_struct *task)
57855+{
57856+#ifdef CONFIG_GRKERNSEC
57857+ task->gr_is_chrooted = 0;
57858+ task->gr_chroot_dentry = NULL;
57859+#endif
57860+ return;
57861+}
57862+
57863+int
57864+gr_handle_chroot_unix(const pid_t pid)
57865+{
57866+#ifdef CONFIG_GRKERNSEC_CHROOT_UNIX
57867+ struct task_struct *p;
57868+
57869+ if (unlikely(!grsec_enable_chroot_unix))
57870+ return 1;
57871+
57872+ if (likely(!proc_is_chrooted(current)))
57873+ return 1;
57874+
57875+ rcu_read_lock();
57876+ read_lock(&tasklist_lock);
57877+ p = find_task_by_vpid_unrestricted(pid);
57878+ if (unlikely(p && !have_same_root(current, p))) {
57879+ read_unlock(&tasklist_lock);
57880+ rcu_read_unlock();
57881+ gr_log_noargs(GR_DONT_AUDIT, GR_UNIX_CHROOT_MSG);
57882+ return 0;
57883+ }
57884+ read_unlock(&tasklist_lock);
57885+ rcu_read_unlock();
57886+#endif
57887+ return 1;
57888+}
57889+
57890+int
57891+gr_handle_chroot_nice(void)
57892+{
57893+#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
57894+ if (grsec_enable_chroot_nice && proc_is_chrooted(current)) {
57895+ gr_log_noargs(GR_DONT_AUDIT, GR_NICE_CHROOT_MSG);
57896+ return -EPERM;
57897+ }
57898+#endif
57899+ return 0;
57900+}
57901+
57902+int
57903+gr_handle_chroot_setpriority(struct task_struct *p, const int niceval)
57904+{
57905+#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
57906+ if (grsec_enable_chroot_nice && (niceval < task_nice(p))
57907+ && proc_is_chrooted(current)) {
57908+ gr_log_str_int(GR_DONT_AUDIT, GR_PRIORITY_CHROOT_MSG, p->comm, p->pid);
57909+ return -EACCES;
57910+ }
57911+#endif
57912+ return 0;
57913+}
57914+
57915+int
57916+gr_handle_chroot_rawio(const struct inode *inode)
57917+{
57918+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
57919+ if (grsec_enable_chroot_caps && proc_is_chrooted(current) &&
57920+ inode && S_ISBLK(inode->i_mode) && !capable(CAP_SYS_RAWIO))
57921+ return 1;
57922+#endif
57923+ return 0;
57924+}
57925+
57926+int
57927+gr_handle_chroot_fowner(struct pid *pid, enum pid_type type)
57928+{
57929+#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
57930+ struct task_struct *p;
57931+ int ret = 0;
57932+ if (!grsec_enable_chroot_findtask || !proc_is_chrooted(current) || !pid)
57933+ return ret;
57934+
57935+ read_lock(&tasklist_lock);
57936+ do_each_pid_task(pid, type, p) {
57937+ if (!have_same_root(current, p)) {
57938+ ret = 1;
57939+ goto out;
57940+ }
57941+ } while_each_pid_task(pid, type, p);
57942+out:
57943+ read_unlock(&tasklist_lock);
57944+ return ret;
57945+#endif
57946+ return 0;
57947+}
57948+
57949+int
57950+gr_pid_is_chrooted(struct task_struct *p)
57951+{
57952+#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
57953+ if (!grsec_enable_chroot_findtask || !proc_is_chrooted(current) || p == NULL)
57954+ return 0;
57955+
57956+ if ((p->exit_state & (EXIT_ZOMBIE | EXIT_DEAD)) ||
57957+ !have_same_root(current, p)) {
57958+ return 1;
57959+ }
57960+#endif
57961+ return 0;
57962+}
57963+
57964+EXPORT_SYMBOL(gr_pid_is_chrooted);
57965+
57966+#if defined(CONFIG_GRKERNSEC_CHROOT_DOUBLE) || defined(CONFIG_GRKERNSEC_CHROOT_FCHDIR)
57967+int gr_is_outside_chroot(const struct dentry *u_dentry, const struct vfsmount *u_mnt)
57968+{
57969+ struct path path, currentroot;
57970+ int ret = 0;
57971+
57972+ path.dentry = (struct dentry *)u_dentry;
57973+ path.mnt = (struct vfsmount *)u_mnt;
57974+ get_fs_root(current->fs, &currentroot);
57975+ if (path_is_under(&path, &currentroot))
57976+ ret = 1;
57977+ path_put(&currentroot);
57978+
57979+ return ret;
57980+}
57981+#endif
57982+
57983+int
57984+gr_chroot_fchdir(struct dentry *u_dentry, struct vfsmount *u_mnt)
57985+{
57986+#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
57987+ if (!grsec_enable_chroot_fchdir)
57988+ return 1;
57989+
57990+ if (!proc_is_chrooted(current))
57991+ return 1;
57992+ else if (!gr_is_outside_chroot(u_dentry, u_mnt)) {
57993+ gr_log_fs_generic(GR_DONT_AUDIT, GR_CHROOT_FCHDIR_MSG, u_dentry, u_mnt);
57994+ return 0;
57995+ }
57996+#endif
57997+ return 1;
57998+}
57999+
58000+int
58001+gr_chroot_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
58002+ const time_t shm_createtime)
58003+{
58004+#ifdef CONFIG_GRKERNSEC_CHROOT_SHMAT
58005+ struct task_struct *p;
58006+ time_t starttime;
58007+
58008+ if (unlikely(!grsec_enable_chroot_shmat))
58009+ return 1;
58010+
58011+ if (likely(!proc_is_chrooted(current)))
58012+ return 1;
58013+
58014+ rcu_read_lock();
58015+ read_lock(&tasklist_lock);
58016+
58017+ if ((p = find_task_by_vpid_unrestricted(shm_cprid))) {
58018+ starttime = p->start_time.tv_sec;
58019+ if (time_before_eq((unsigned long)starttime, (unsigned long)shm_createtime)) {
58020+ if (have_same_root(current, p)) {
58021+ goto allow;
58022+ } else {
58023+ read_unlock(&tasklist_lock);
58024+ rcu_read_unlock();
58025+ gr_log_noargs(GR_DONT_AUDIT, GR_SHMAT_CHROOT_MSG);
58026+ return 0;
58027+ }
58028+ }
58029+ /* creator exited, pid reuse, fall through to next check */
58030+ }
58031+ if ((p = find_task_by_vpid_unrestricted(shm_lapid))) {
58032+ if (unlikely(!have_same_root(current, p))) {
58033+ read_unlock(&tasklist_lock);
58034+ rcu_read_unlock();
58035+ gr_log_noargs(GR_DONT_AUDIT, GR_SHMAT_CHROOT_MSG);
58036+ return 0;
58037+ }
58038+ }
58039+
58040+allow:
58041+ read_unlock(&tasklist_lock);
58042+ rcu_read_unlock();
58043+#endif
58044+ return 1;
58045+}
58046+
58047+void
58048+gr_log_chroot_exec(const struct dentry *dentry, const struct vfsmount *mnt)
58049+{
58050+#ifdef CONFIG_GRKERNSEC_CHROOT_EXECLOG
58051+ if (grsec_enable_chroot_execlog && proc_is_chrooted(current))
58052+ gr_log_fs_generic(GR_DO_AUDIT, GR_EXEC_CHROOT_MSG, dentry, mnt);
58053+#endif
58054+ return;
58055+}
58056+
58057+int
58058+gr_handle_chroot_mknod(const struct dentry *dentry,
58059+ const struct vfsmount *mnt, const int mode)
58060+{
58061+#ifdef CONFIG_GRKERNSEC_CHROOT_MKNOD
58062+ if (grsec_enable_chroot_mknod && !S_ISFIFO(mode) && !S_ISREG(mode) &&
58063+ proc_is_chrooted(current)) {
58064+ gr_log_fs_generic(GR_DONT_AUDIT, GR_MKNOD_CHROOT_MSG, dentry, mnt);
58065+ return -EPERM;
58066+ }
58067+#endif
58068+ return 0;
58069+}
58070+
58071+int
58072+gr_handle_chroot_mount(const struct dentry *dentry,
58073+ const struct vfsmount *mnt, const char *dev_name)
58074+{
58075+#ifdef CONFIG_GRKERNSEC_CHROOT_MOUNT
58076+ if (grsec_enable_chroot_mount && proc_is_chrooted(current)) {
58077+ gr_log_str_fs(GR_DONT_AUDIT, GR_MOUNT_CHROOT_MSG, dev_name ? dev_name : "none", dentry, mnt);
58078+ return -EPERM;
58079+ }
58080+#endif
58081+ return 0;
58082+}
58083+
58084+int
58085+gr_handle_chroot_pivot(void)
58086+{
58087+#ifdef CONFIG_GRKERNSEC_CHROOT_PIVOT
58088+ if (grsec_enable_chroot_pivot && proc_is_chrooted(current)) {
58089+ gr_log_noargs(GR_DONT_AUDIT, GR_PIVOT_CHROOT_MSG);
58090+ return -EPERM;
58091+ }
58092+#endif
58093+ return 0;
58094+}
58095+
58096+int
58097+gr_handle_chroot_chroot(const struct dentry *dentry, const struct vfsmount *mnt)
58098+{
58099+#ifdef CONFIG_GRKERNSEC_CHROOT_DOUBLE
58100+ if (grsec_enable_chroot_double && proc_is_chrooted(current) &&
58101+ !gr_is_outside_chroot(dentry, mnt)) {
58102+ gr_log_fs_generic(GR_DONT_AUDIT, GR_CHROOT_CHROOT_MSG, dentry, mnt);
58103+ return -EPERM;
58104+ }
58105+#endif
58106+ return 0;
58107+}
58108+
58109+extern const char *captab_log[];
58110+extern int captab_log_entries;
58111+
58112+int
58113+gr_task_chroot_is_capable(const struct task_struct *task, const struct cred *cred, const int cap)
58114+{
58115+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
58116+ if (grsec_enable_chroot_caps && proc_is_chrooted(task)) {
58117+ kernel_cap_t chroot_caps = GR_CHROOT_CAPS;
58118+ if (cap_raised(chroot_caps, cap)) {
58119+ if (cap_raised(cred->cap_effective, cap) && cap < captab_log_entries) {
58120+ gr_log_cap(GR_DONT_AUDIT, GR_CAP_CHROOT_MSG, task, captab_log[cap]);
58121+ }
58122+ return 0;
58123+ }
58124+ }
58125+#endif
58126+ return 1;
58127+}
58128+
58129+int
58130+gr_chroot_is_capable(const int cap)
58131+{
58132+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
58133+ return gr_task_chroot_is_capable(current, current_cred(), cap);
58134+#endif
58135+ return 1;
58136+}
58137+
58138+int
58139+gr_task_chroot_is_capable_nolog(const struct task_struct *task, const int cap)
58140+{
58141+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
58142+ if (grsec_enable_chroot_caps && proc_is_chrooted(task)) {
58143+ kernel_cap_t chroot_caps = GR_CHROOT_CAPS;
58144+ if (cap_raised(chroot_caps, cap)) {
58145+ return 0;
58146+ }
58147+ }
58148+#endif
58149+ return 1;
58150+}
58151+
58152+int
58153+gr_chroot_is_capable_nolog(const int cap)
58154+{
58155+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
58156+ return gr_task_chroot_is_capable_nolog(current, cap);
58157+#endif
58158+ return 1;
58159+}
58160+
58161+int
58162+gr_handle_chroot_sysctl(const int op)
58163+{
58164+#ifdef CONFIG_GRKERNSEC_CHROOT_SYSCTL
58165+ if (grsec_enable_chroot_sysctl && (op & MAY_WRITE) &&
58166+ proc_is_chrooted(current))
58167+ return -EACCES;
58168+#endif
58169+ return 0;
58170+}
58171+
58172+void
58173+gr_handle_chroot_chdir(struct path *path)
58174+{
58175+#ifdef CONFIG_GRKERNSEC_CHROOT_CHDIR
58176+ if (grsec_enable_chroot_chdir)
58177+ set_fs_pwd(current->fs, path);
58178+#endif
58179+ return;
58180+}
58181+
58182+int
58183+gr_handle_chroot_chmod(const struct dentry *dentry,
58184+ const struct vfsmount *mnt, const int mode)
58185+{
58186+#ifdef CONFIG_GRKERNSEC_CHROOT_CHMOD
58187+ /* allow chmod +s on directories, but not files */
58188+ if (grsec_enable_chroot_chmod && !S_ISDIR(dentry->d_inode->i_mode) &&
58189+ ((mode & S_ISUID) || ((mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))) &&
58190+ proc_is_chrooted(current)) {
58191+ gr_log_fs_generic(GR_DONT_AUDIT, GR_CHMOD_CHROOT_MSG, dentry, mnt);
58192+ return -EPERM;
58193+ }
58194+#endif
58195+ return 0;
58196+}
58197diff --git a/grsecurity/grsec_disabled.c b/grsecurity/grsec_disabled.c
58198new file mode 100644
58199index 0000000..b79fe50
58200--- /dev/null
58201+++ b/grsecurity/grsec_disabled.c
58202@@ -0,0 +1,442 @@
58203+#include <linux/kernel.h>
58204+#include <linux/module.h>
58205+#include <linux/sched.h>
58206+#include <linux/file.h>
58207+#include <linux/fs.h>
58208+#include <linux/kdev_t.h>
58209+#include <linux/net.h>
58210+#include <linux/in.h>
58211+#include <linux/ip.h>
58212+#include <linux/skbuff.h>
58213+#include <linux/sysctl.h>
58214+
58215+#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
58216+void
58217+pax_set_initial_flags(struct linux_binprm *bprm)
58218+{
58219+ return;
58220+}
58221+#endif
58222+
58223+#ifdef CONFIG_SYSCTL
58224+__u32
58225+gr_handle_sysctl(const struct ctl_table * table, const int op)
58226+{
58227+ return 0;
58228+}
58229+#endif
58230+
58231+#ifdef CONFIG_TASKSTATS
58232+int gr_is_taskstats_denied(int pid)
58233+{
58234+ return 0;
58235+}
58236+#endif
58237+
58238+int
58239+gr_acl_is_enabled(void)
58240+{
58241+ return 0;
58242+}
58243+
58244+void
58245+gr_handle_proc_create(const struct dentry *dentry, const struct inode *inode)
58246+{
58247+ return;
58248+}
58249+
58250+int
58251+gr_handle_rawio(const struct inode *inode)
58252+{
58253+ return 0;
58254+}
58255+
58256+void
58257+gr_acl_handle_psacct(struct task_struct *task, const long code)
58258+{
58259+ return;
58260+}
58261+
58262+int
58263+gr_handle_ptrace(struct task_struct *task, const long request)
58264+{
58265+ return 0;
58266+}
58267+
58268+int
58269+gr_handle_proc_ptrace(struct task_struct *task)
58270+{
58271+ return 0;
58272+}
58273+
58274+void
58275+gr_learn_resource(const struct task_struct *task,
58276+ const int res, const unsigned long wanted, const int gt)
58277+{
58278+ return;
58279+}
58280+
58281+int
58282+gr_set_acls(const int type)
58283+{
58284+ return 0;
58285+}
58286+
58287+int
58288+gr_check_hidden_task(const struct task_struct *tsk)
58289+{
58290+ return 0;
58291+}
58292+
58293+int
58294+gr_check_protected_task(const struct task_struct *task)
58295+{
58296+ return 0;
58297+}
58298+
58299+int
58300+gr_check_protected_task_fowner(struct pid *pid, enum pid_type type)
58301+{
58302+ return 0;
58303+}
58304+
58305+void
58306+gr_copy_label(struct task_struct *tsk)
58307+{
58308+ return;
58309+}
58310+
58311+void
58312+gr_set_pax_flags(struct task_struct *task)
58313+{
58314+ return;
58315+}
58316+
58317+int
58318+gr_set_proc_label(const struct dentry *dentry, const struct vfsmount *mnt,
58319+ const int unsafe_share)
58320+{
58321+ return 0;
58322+}
58323+
58324+void
58325+gr_handle_delete(const ino_t ino, const dev_t dev)
58326+{
58327+ return;
58328+}
58329+
58330+void
58331+gr_handle_create(const struct dentry *dentry, const struct vfsmount *mnt)
58332+{
58333+ return;
58334+}
58335+
58336+void
58337+gr_handle_crash(struct task_struct *task, const int sig)
58338+{
58339+ return;
58340+}
58341+
58342+int
58343+gr_check_crash_exec(const struct file *filp)
58344+{
58345+ return 0;
58346+}
58347+
58348+int
58349+gr_check_crash_uid(const uid_t uid)
58350+{
58351+ return 0;
58352+}
58353+
58354+void
58355+gr_handle_rename(struct inode *old_dir, struct inode *new_dir,
58356+ struct dentry *old_dentry,
58357+ struct dentry *new_dentry,
58358+ struct vfsmount *mnt, const __u8 replace)
58359+{
58360+ return;
58361+}
58362+
58363+int
58364+gr_search_socket(const int family, const int type, const int protocol)
58365+{
58366+ return 1;
58367+}
58368+
58369+int
58370+gr_search_connectbind(const int mode, const struct socket *sock,
58371+ const struct sockaddr_in *addr)
58372+{
58373+ return 0;
58374+}
58375+
58376+void
58377+gr_handle_alertkill(struct task_struct *task)
58378+{
58379+ return;
58380+}
58381+
58382+__u32
58383+gr_acl_handle_execve(const struct dentry * dentry, const struct vfsmount * mnt)
58384+{
58385+ return 1;
58386+}
58387+
58388+__u32
58389+gr_acl_handle_hidden_file(const struct dentry * dentry,
58390+ const struct vfsmount * mnt)
58391+{
58392+ return 1;
58393+}
58394+
58395+__u32
58396+gr_acl_handle_open(const struct dentry * dentry, const struct vfsmount * mnt,
58397+ int acc_mode)
58398+{
58399+ return 1;
58400+}
58401+
58402+__u32
58403+gr_acl_handle_rmdir(const struct dentry * dentry, const struct vfsmount * mnt)
58404+{
58405+ return 1;
58406+}
58407+
58408+__u32
58409+gr_acl_handle_unlink(const struct dentry * dentry, const struct vfsmount * mnt)
58410+{
58411+ return 1;
58412+}
58413+
58414+int
58415+gr_acl_handle_mmap(const struct file *file, const unsigned long prot,
58416+ unsigned int *vm_flags)
58417+{
58418+ return 1;
58419+}
58420+
58421+__u32
58422+gr_acl_handle_truncate(const struct dentry * dentry,
58423+ const struct vfsmount * mnt)
58424+{
58425+ return 1;
58426+}
58427+
58428+__u32
58429+gr_acl_handle_utime(const struct dentry * dentry, const struct vfsmount * mnt)
58430+{
58431+ return 1;
58432+}
58433+
58434+__u32
58435+gr_acl_handle_access(const struct dentry * dentry,
58436+ const struct vfsmount * mnt, const int fmode)
58437+{
58438+ return 1;
58439+}
58440+
58441+__u32
58442+gr_acl_handle_chmod(const struct dentry * dentry, const struct vfsmount * mnt,
58443+ umode_t *mode)
58444+{
58445+ return 1;
58446+}
58447+
58448+__u32
58449+gr_acl_handle_chown(const struct dentry * dentry, const struct vfsmount * mnt)
58450+{
58451+ return 1;
58452+}
58453+
58454+__u32
58455+gr_acl_handle_setxattr(const struct dentry * dentry, const struct vfsmount * mnt)
58456+{
58457+ return 1;
58458+}
58459+
58460+void
58461+grsecurity_init(void)
58462+{
58463+ return;
58464+}
58465+
58466+umode_t gr_acl_umask(void)
58467+{
58468+ return 0;
58469+}
58470+
58471+__u32
58472+gr_acl_handle_mknod(const struct dentry * new_dentry,
58473+ const struct dentry * parent_dentry,
58474+ const struct vfsmount * parent_mnt,
58475+ const int mode)
58476+{
58477+ return 1;
58478+}
58479+
58480+__u32
58481+gr_acl_handle_mkdir(const struct dentry * new_dentry,
58482+ const struct dentry * parent_dentry,
58483+ const struct vfsmount * parent_mnt)
58484+{
58485+ return 1;
58486+}
58487+
58488+__u32
58489+gr_acl_handle_symlink(const struct dentry * new_dentry,
58490+ const struct dentry * parent_dentry,
58491+ const struct vfsmount * parent_mnt, const char *from)
58492+{
58493+ return 1;
58494+}
58495+
58496+__u32
58497+gr_acl_handle_link(const struct dentry * new_dentry,
58498+ const struct dentry * parent_dentry,
58499+ const struct vfsmount * parent_mnt,
58500+ const struct dentry * old_dentry,
58501+ const struct vfsmount * old_mnt, const char *to)
58502+{
58503+ return 1;
58504+}
58505+
58506+int
58507+gr_acl_handle_rename(const struct dentry *new_dentry,
58508+ const struct dentry *parent_dentry,
58509+ const struct vfsmount *parent_mnt,
58510+ const struct dentry *old_dentry,
58511+ const struct inode *old_parent_inode,
58512+ const struct vfsmount *old_mnt, const char *newname)
58513+{
58514+ return 0;
58515+}
58516+
58517+int
58518+gr_acl_handle_filldir(const struct file *file, const char *name,
58519+ const int namelen, const ino_t ino)
58520+{
58521+ return 1;
58522+}
58523+
58524+int
58525+gr_handle_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
58526+ const time_t shm_createtime, const uid_t cuid, const int shmid)
58527+{
58528+ return 1;
58529+}
58530+
58531+int
58532+gr_search_bind(const struct socket *sock, const struct sockaddr_in *addr)
58533+{
58534+ return 0;
58535+}
58536+
58537+int
58538+gr_search_accept(const struct socket *sock)
58539+{
58540+ return 0;
58541+}
58542+
58543+int
58544+gr_search_listen(const struct socket *sock)
58545+{
58546+ return 0;
58547+}
58548+
58549+int
58550+gr_search_connect(const struct socket *sock, const struct sockaddr_in *addr)
58551+{
58552+ return 0;
58553+}
58554+
58555+__u32
58556+gr_acl_handle_unix(const struct dentry * dentry, const struct vfsmount * mnt)
58557+{
58558+ return 1;
58559+}
58560+
58561+__u32
58562+gr_acl_handle_creat(const struct dentry * dentry,
58563+ const struct dentry * p_dentry,
58564+ const struct vfsmount * p_mnt, int open_flags, int acc_mode,
58565+ const int imode)
58566+{
58567+ return 1;
58568+}
58569+
58570+void
58571+gr_acl_handle_exit(void)
58572+{
58573+ return;
58574+}
58575+
58576+int
58577+gr_acl_handle_mprotect(const struct file *file, const unsigned long prot)
58578+{
58579+ return 1;
58580+}
58581+
58582+void
58583+gr_set_role_label(const uid_t uid, const gid_t gid)
58584+{
58585+ return;
58586+}
58587+
58588+int
58589+gr_acl_handle_procpidmem(const struct task_struct *task)
58590+{
58591+ return 0;
58592+}
58593+
58594+int
58595+gr_search_udp_recvmsg(const struct sock *sk, const struct sk_buff *skb)
58596+{
58597+ return 0;
58598+}
58599+
58600+int
58601+gr_search_udp_sendmsg(const struct sock *sk, const struct sockaddr_in *addr)
58602+{
58603+ return 0;
58604+}
58605+
58606+void
58607+gr_set_kernel_label(struct task_struct *task)
58608+{
58609+ return;
58610+}
58611+
58612+int
58613+gr_check_user_change(int real, int effective, int fs)
58614+{
58615+ return 0;
58616+}
58617+
58618+int
58619+gr_check_group_change(int real, int effective, int fs)
58620+{
58621+ return 0;
58622+}
58623+
58624+int gr_acl_enable_at_secure(void)
58625+{
58626+ return 0;
58627+}
58628+
58629+dev_t gr_get_dev_from_dentry(struct dentry *dentry)
58630+{
58631+ return dentry->d_inode->i_sb->s_dev;
58632+}
58633+
58634+void gr_put_exec_file(struct task_struct *task)
58635+{
58636+ return;
58637+}
58638+
58639+EXPORT_SYMBOL(gr_learn_resource);
58640+EXPORT_SYMBOL(gr_set_kernel_label);
58641+#ifdef CONFIG_SECURITY
58642+EXPORT_SYMBOL(gr_check_user_change);
58643+EXPORT_SYMBOL(gr_check_group_change);
58644+#endif
58645diff --git a/grsecurity/grsec_exec.c b/grsecurity/grsec_exec.c
58646new file mode 100644
58647index 0000000..abfa971
58648--- /dev/null
58649+++ b/grsecurity/grsec_exec.c
58650@@ -0,0 +1,174 @@
58651+#include <linux/kernel.h>
58652+#include <linux/sched.h>
58653+#include <linux/file.h>
58654+#include <linux/binfmts.h>
58655+#include <linux/fs.h>
58656+#include <linux/types.h>
58657+#include <linux/grdefs.h>
58658+#include <linux/grsecurity.h>
58659+#include <linux/grinternal.h>
58660+#include <linux/capability.h>
58661+#include <linux/module.h>
58662+
58663+#include <asm/uaccess.h>
58664+
58665+#ifdef CONFIG_GRKERNSEC_EXECLOG
58666+static char gr_exec_arg_buf[132];
58667+static DEFINE_MUTEX(gr_exec_arg_mutex);
58668+#endif
58669+
58670+extern const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr);
58671+
58672+void
58673+gr_handle_exec_args(struct linux_binprm *bprm, struct user_arg_ptr argv)
58674+{
58675+#ifdef CONFIG_GRKERNSEC_EXECLOG
58676+ char *grarg = gr_exec_arg_buf;
58677+ unsigned int i, x, execlen = 0;
58678+ char c;
58679+
58680+ if (!((grsec_enable_execlog && grsec_enable_group &&
58681+ in_group_p(grsec_audit_gid))
58682+ || (grsec_enable_execlog && !grsec_enable_group)))
58683+ return;
58684+
58685+ mutex_lock(&gr_exec_arg_mutex);
58686+ memset(grarg, 0, sizeof(gr_exec_arg_buf));
58687+
58688+ for (i = 0; i < bprm->argc && execlen < 128; i++) {
58689+ const char __user *p;
58690+ unsigned int len;
58691+
58692+ p = get_user_arg_ptr(argv, i);
58693+ if (IS_ERR(p))
58694+ goto log;
58695+
58696+ len = strnlen_user(p, 128 - execlen);
58697+ if (len > 128 - execlen)
58698+ len = 128 - execlen;
58699+ else if (len > 0)
58700+ len--;
58701+ if (copy_from_user(grarg + execlen, p, len))
58702+ goto log;
58703+
58704+ /* rewrite unprintable characters */
58705+ for (x = 0; x < len; x++) {
58706+ c = *(grarg + execlen + x);
58707+ if (c < 32 || c > 126)
58708+ *(grarg + execlen + x) = ' ';
58709+ }
58710+
58711+ execlen += len;
58712+ *(grarg + execlen) = ' ';
58713+ *(grarg + execlen + 1) = '\0';
58714+ execlen++;
58715+ }
58716+
58717+ log:
58718+ gr_log_fs_str(GR_DO_AUDIT, GR_EXEC_AUDIT_MSG, bprm->file->f_path.dentry,
58719+ bprm->file->f_path.mnt, grarg);
58720+ mutex_unlock(&gr_exec_arg_mutex);
58721+#endif
58722+ return;
58723+}
58724+
58725+#ifdef CONFIG_GRKERNSEC
58726+extern int gr_acl_is_capable(const int cap);
58727+extern int gr_acl_is_capable_nolog(const int cap);
58728+extern int gr_task_acl_is_capable(const struct task_struct *task, const struct cred *cred, const int cap);
58729+extern int gr_task_acl_is_capable_nolog(const struct task_struct *task, const int cap);
58730+extern int gr_chroot_is_capable(const int cap);
58731+extern int gr_chroot_is_capable_nolog(const int cap);
58732+extern int gr_task_chroot_is_capable(const struct task_struct *task, const struct cred *cred, const int cap);
58733+extern int gr_task_chroot_is_capable_nolog(const struct task_struct *task, const int cap);
58734+#endif
58735+
58736+const char *captab_log[] = {
58737+ "CAP_CHOWN",
58738+ "CAP_DAC_OVERRIDE",
58739+ "CAP_DAC_READ_SEARCH",
58740+ "CAP_FOWNER",
58741+ "CAP_FSETID",
58742+ "CAP_KILL",
58743+ "CAP_SETGID",
58744+ "CAP_SETUID",
58745+ "CAP_SETPCAP",
58746+ "CAP_LINUX_IMMUTABLE",
58747+ "CAP_NET_BIND_SERVICE",
58748+ "CAP_NET_BROADCAST",
58749+ "CAP_NET_ADMIN",
58750+ "CAP_NET_RAW",
58751+ "CAP_IPC_LOCK",
58752+ "CAP_IPC_OWNER",
58753+ "CAP_SYS_MODULE",
58754+ "CAP_SYS_RAWIO",
58755+ "CAP_SYS_CHROOT",
58756+ "CAP_SYS_PTRACE",
58757+ "CAP_SYS_PACCT",
58758+ "CAP_SYS_ADMIN",
58759+ "CAP_SYS_BOOT",
58760+ "CAP_SYS_NICE",
58761+ "CAP_SYS_RESOURCE",
58762+ "CAP_SYS_TIME",
58763+ "CAP_SYS_TTY_CONFIG",
58764+ "CAP_MKNOD",
58765+ "CAP_LEASE",
58766+ "CAP_AUDIT_WRITE",
58767+ "CAP_AUDIT_CONTROL",
58768+ "CAP_SETFCAP",
58769+ "CAP_MAC_OVERRIDE",
58770+ "CAP_MAC_ADMIN",
58771+ "CAP_SYSLOG",
58772+ "CAP_WAKE_ALARM"
58773+};
58774+
58775+int captab_log_entries = sizeof(captab_log)/sizeof(captab_log[0]);
58776+
58777+int gr_is_capable(const int cap)
58778+{
58779+#ifdef CONFIG_GRKERNSEC
58780+ if (gr_acl_is_capable(cap) && gr_chroot_is_capable(cap))
58781+ return 1;
58782+ return 0;
58783+#else
58784+ return 1;
58785+#endif
58786+}
58787+
58788+int gr_task_is_capable(const struct task_struct *task, const struct cred *cred, const int cap)
58789+{
58790+#ifdef CONFIG_GRKERNSEC
58791+ if (gr_task_acl_is_capable(task, cred, cap) && gr_task_chroot_is_capable(task, cred, cap))
58792+ return 1;
58793+ return 0;
58794+#else
58795+ return 1;
58796+#endif
58797+}
58798+
58799+int gr_is_capable_nolog(const int cap)
58800+{
58801+#ifdef CONFIG_GRKERNSEC
58802+ if (gr_acl_is_capable_nolog(cap) && gr_chroot_is_capable_nolog(cap))
58803+ return 1;
58804+ return 0;
58805+#else
58806+ return 1;
58807+#endif
58808+}
58809+
58810+int gr_task_is_capable_nolog(const struct task_struct *task, const int cap)
58811+{
58812+#ifdef CONFIG_GRKERNSEC
58813+ if (gr_task_acl_is_capable_nolog(task, cap) && gr_task_chroot_is_capable_nolog(task, cap))
58814+ return 1;
58815+ return 0;
58816+#else
58817+ return 1;
58818+#endif
58819+}
58820+
58821+EXPORT_SYMBOL(gr_is_capable);
58822+EXPORT_SYMBOL(gr_is_capable_nolog);
58823+EXPORT_SYMBOL(gr_task_is_capable);
58824+EXPORT_SYMBOL(gr_task_is_capable_nolog);
58825diff --git a/grsecurity/grsec_fifo.c b/grsecurity/grsec_fifo.c
58826new file mode 100644
58827index 0000000..d3ee748
58828--- /dev/null
58829+++ b/grsecurity/grsec_fifo.c
58830@@ -0,0 +1,24 @@
58831+#include <linux/kernel.h>
58832+#include <linux/sched.h>
58833+#include <linux/fs.h>
58834+#include <linux/file.h>
58835+#include <linux/grinternal.h>
58836+
58837+int
58838+gr_handle_fifo(const struct dentry *dentry, const struct vfsmount *mnt,
58839+ const struct dentry *dir, const int flag, const int acc_mode)
58840+{
58841+#ifdef CONFIG_GRKERNSEC_FIFO
58842+ const struct cred *cred = current_cred();
58843+
58844+ if (grsec_enable_fifo && S_ISFIFO(dentry->d_inode->i_mode) &&
58845+ !(flag & O_EXCL) && (dir->d_inode->i_mode & S_ISVTX) &&
58846+ (dentry->d_inode->i_uid != dir->d_inode->i_uid) &&
58847+ (cred->fsuid != dentry->d_inode->i_uid)) {
58848+ if (!inode_permission(dentry->d_inode, acc_mode))
58849+ gr_log_fs_int2(GR_DONT_AUDIT, GR_FIFO_MSG, dentry, mnt, dentry->d_inode->i_uid, dentry->d_inode->i_gid);
58850+ return -EACCES;
58851+ }
58852+#endif
58853+ return 0;
58854+}
58855diff --git a/grsecurity/grsec_fork.c b/grsecurity/grsec_fork.c
58856new file mode 100644
58857index 0000000..8ca18bf
58858--- /dev/null
58859+++ b/grsecurity/grsec_fork.c
58860@@ -0,0 +1,23 @@
58861+#include <linux/kernel.h>
58862+#include <linux/sched.h>
58863+#include <linux/grsecurity.h>
58864+#include <linux/grinternal.h>
58865+#include <linux/errno.h>
58866+
58867+void
58868+gr_log_forkfail(const int retval)
58869+{
58870+#ifdef CONFIG_GRKERNSEC_FORKFAIL
58871+ if (grsec_enable_forkfail && (retval == -EAGAIN || retval == -ENOMEM)) {
58872+ switch (retval) {
58873+ case -EAGAIN:
58874+ gr_log_str(GR_DONT_AUDIT, GR_FAILFORK_MSG, "EAGAIN");
58875+ break;
58876+ case -ENOMEM:
58877+ gr_log_str(GR_DONT_AUDIT, GR_FAILFORK_MSG, "ENOMEM");
58878+ break;
58879+ }
58880+ }
58881+#endif
58882+ return;
58883+}
58884diff --git a/grsecurity/grsec_init.c b/grsecurity/grsec_init.c
58885new file mode 100644
58886index 0000000..05a6015
58887--- /dev/null
58888+++ b/grsecurity/grsec_init.c
58889@@ -0,0 +1,283 @@
58890+#include <linux/kernel.h>
58891+#include <linux/sched.h>
58892+#include <linux/mm.h>
58893+#include <linux/gracl.h>
58894+#include <linux/slab.h>
58895+#include <linux/vmalloc.h>
58896+#include <linux/percpu.h>
58897+#include <linux/module.h>
58898+
58899+int grsec_enable_ptrace_readexec;
58900+int grsec_enable_setxid;
58901+int grsec_enable_symlinkown;
58902+int grsec_symlinkown_gid;
58903+int grsec_enable_brute;
58904+int grsec_enable_link;
58905+int grsec_enable_dmesg;
58906+int grsec_enable_harden_ptrace;
58907+int grsec_enable_fifo;
58908+int grsec_enable_execlog;
58909+int grsec_enable_signal;
58910+int grsec_enable_forkfail;
58911+int grsec_enable_audit_ptrace;
58912+int grsec_enable_time;
58913+int grsec_enable_audit_textrel;
58914+int grsec_enable_group;
58915+int grsec_audit_gid;
58916+int grsec_enable_chdir;
58917+int grsec_enable_mount;
58918+int grsec_enable_rofs;
58919+int grsec_enable_chroot_findtask;
58920+int grsec_enable_chroot_mount;
58921+int grsec_enable_chroot_shmat;
58922+int grsec_enable_chroot_fchdir;
58923+int grsec_enable_chroot_double;
58924+int grsec_enable_chroot_pivot;
58925+int grsec_enable_chroot_chdir;
58926+int grsec_enable_chroot_chmod;
58927+int grsec_enable_chroot_mknod;
58928+int grsec_enable_chroot_nice;
58929+int grsec_enable_chroot_execlog;
58930+int grsec_enable_chroot_caps;
58931+int grsec_enable_chroot_sysctl;
58932+int grsec_enable_chroot_unix;
58933+int grsec_enable_tpe;
58934+int grsec_tpe_gid;
58935+int grsec_enable_blackhole;
58936+#ifdef CONFIG_IPV6_MODULE
58937+EXPORT_SYMBOL(grsec_enable_blackhole);
58938+#endif
58939+int grsec_lastack_retries;
58940+int grsec_enable_tpe_all;
58941+int grsec_enable_tpe_invert;
58942+int grsec_enable_socket_all;
58943+int grsec_socket_all_gid;
58944+int grsec_enable_socket_client;
58945+int grsec_socket_client_gid;
58946+int grsec_enable_socket_server;
58947+int grsec_socket_server_gid;
58948+int grsec_resource_logging;
58949+int grsec_disable_privio;
58950+int grsec_enable_log_rwxmaps;
58951+int grsec_lock;
58952+
58953+DEFINE_SPINLOCK(grsec_alert_lock);
58954+unsigned long grsec_alert_wtime = 0;
58955+unsigned long grsec_alert_fyet = 0;
58956+
58957+DEFINE_SPINLOCK(grsec_audit_lock);
58958+
58959+DEFINE_RWLOCK(grsec_exec_file_lock);
58960+
58961+char *gr_shared_page[4];
58962+
58963+char *gr_alert_log_fmt;
58964+char *gr_audit_log_fmt;
58965+char *gr_alert_log_buf;
58966+char *gr_audit_log_buf;
58967+
58968+extern struct gr_arg *gr_usermode;
58969+extern unsigned char *gr_system_salt;
58970+extern unsigned char *gr_system_sum;
58971+
58972+void __init
58973+grsecurity_init(void)
58974+{
58975+ int j;
58976+ /* create the per-cpu shared pages */
58977+
58978+#ifdef CONFIG_X86
58979+ memset((char *)(0x41a + PAGE_OFFSET), 0, 36);
58980+#endif
58981+
58982+ for (j = 0; j < 4; j++) {
58983+ gr_shared_page[j] = (char *)__alloc_percpu(PAGE_SIZE, __alignof__(unsigned long long));
58984+ if (gr_shared_page[j] == NULL) {
58985+ panic("Unable to allocate grsecurity shared page");
58986+ return;
58987+ }
58988+ }
58989+
58990+ /* allocate log buffers */
58991+ gr_alert_log_fmt = kmalloc(512, GFP_KERNEL);
58992+ if (!gr_alert_log_fmt) {
58993+ panic("Unable to allocate grsecurity alert log format buffer");
58994+ return;
58995+ }
58996+ gr_audit_log_fmt = kmalloc(512, GFP_KERNEL);
58997+ if (!gr_audit_log_fmt) {
58998+ panic("Unable to allocate grsecurity audit log format buffer");
58999+ return;
59000+ }
59001+ gr_alert_log_buf = (char *) get_zeroed_page(GFP_KERNEL);
59002+ if (!gr_alert_log_buf) {
59003+ panic("Unable to allocate grsecurity alert log buffer");
59004+ return;
59005+ }
59006+ gr_audit_log_buf = (char *) get_zeroed_page(GFP_KERNEL);
59007+ if (!gr_audit_log_buf) {
59008+ panic("Unable to allocate grsecurity audit log buffer");
59009+ return;
59010+ }
59011+
59012+ /* allocate memory for authentication structure */
59013+ gr_usermode = kmalloc(sizeof(struct gr_arg), GFP_KERNEL);
59014+ gr_system_salt = kmalloc(GR_SALT_LEN, GFP_KERNEL);
59015+ gr_system_sum = kmalloc(GR_SHA_LEN, GFP_KERNEL);
59016+
59017+ if (!gr_usermode || !gr_system_salt || !gr_system_sum) {
59018+ panic("Unable to allocate grsecurity authentication structure");
59019+ return;
59020+ }
59021+
59022+
59023+#ifdef CONFIG_GRKERNSEC_IO
59024+#if !defined(CONFIG_GRKERNSEC_SYSCTL_DISTRO)
59025+ grsec_disable_privio = 1;
59026+#elif defined(CONFIG_GRKERNSEC_SYSCTL_ON)
59027+ grsec_disable_privio = 1;
59028+#else
59029+ grsec_disable_privio = 0;
59030+#endif
59031+#endif
59032+
59033+#ifdef CONFIG_GRKERNSEC_TPE_INVERT
59034+ /* for backward compatibility, tpe_invert always defaults to on if
59035+ enabled in the kernel
59036+ */
59037+ grsec_enable_tpe_invert = 1;
59038+#endif
59039+
59040+#if !defined(CONFIG_GRKERNSEC_SYSCTL) || defined(CONFIG_GRKERNSEC_SYSCTL_ON)
59041+#ifndef CONFIG_GRKERNSEC_SYSCTL
59042+ grsec_lock = 1;
59043+#endif
59044+
59045+#ifdef CONFIG_GRKERNSEC_AUDIT_TEXTREL
59046+ grsec_enable_audit_textrel = 1;
59047+#endif
59048+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
59049+ grsec_enable_log_rwxmaps = 1;
59050+#endif
59051+#ifdef CONFIG_GRKERNSEC_AUDIT_GROUP
59052+ grsec_enable_group = 1;
59053+ grsec_audit_gid = CONFIG_GRKERNSEC_AUDIT_GID;
59054+#endif
59055+#ifdef CONFIG_GRKERNSEC_PTRACE_READEXEC
59056+ grsec_enable_ptrace_readexec = 1;
59057+#endif
59058+#ifdef CONFIG_GRKERNSEC_AUDIT_CHDIR
59059+ grsec_enable_chdir = 1;
59060+#endif
59061+#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
59062+ grsec_enable_harden_ptrace = 1;
59063+#endif
59064+#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
59065+ grsec_enable_mount = 1;
59066+#endif
59067+#ifdef CONFIG_GRKERNSEC_LINK
59068+ grsec_enable_link = 1;
59069+#endif
59070+#ifdef CONFIG_GRKERNSEC_BRUTE
59071+ grsec_enable_brute = 1;
59072+#endif
59073+#ifdef CONFIG_GRKERNSEC_DMESG
59074+ grsec_enable_dmesg = 1;
59075+#endif
59076+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
59077+ grsec_enable_blackhole = 1;
59078+ grsec_lastack_retries = 4;
59079+#endif
59080+#ifdef CONFIG_GRKERNSEC_FIFO
59081+ grsec_enable_fifo = 1;
59082+#endif
59083+#ifdef CONFIG_GRKERNSEC_EXECLOG
59084+ grsec_enable_execlog = 1;
59085+#endif
59086+#ifdef CONFIG_GRKERNSEC_SETXID
59087+ grsec_enable_setxid = 1;
59088+#endif
59089+#ifdef CONFIG_GRKERNSEC_SIGNAL
59090+ grsec_enable_signal = 1;
59091+#endif
59092+#ifdef CONFIG_GRKERNSEC_FORKFAIL
59093+ grsec_enable_forkfail = 1;
59094+#endif
59095+#ifdef CONFIG_GRKERNSEC_TIME
59096+ grsec_enable_time = 1;
59097+#endif
59098+#ifdef CONFIG_GRKERNSEC_RESLOG
59099+ grsec_resource_logging = 1;
59100+#endif
59101+#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
59102+ grsec_enable_chroot_findtask = 1;
59103+#endif
59104+#ifdef CONFIG_GRKERNSEC_CHROOT_UNIX
59105+ grsec_enable_chroot_unix = 1;
59106+#endif
59107+#ifdef CONFIG_GRKERNSEC_CHROOT_MOUNT
59108+ grsec_enable_chroot_mount = 1;
59109+#endif
59110+#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
59111+ grsec_enable_chroot_fchdir = 1;
59112+#endif
59113+#ifdef CONFIG_GRKERNSEC_CHROOT_SHMAT
59114+ grsec_enable_chroot_shmat = 1;
59115+#endif
59116+#ifdef CONFIG_GRKERNSEC_AUDIT_PTRACE
59117+ grsec_enable_audit_ptrace = 1;
59118+#endif
59119+#ifdef CONFIG_GRKERNSEC_CHROOT_DOUBLE
59120+ grsec_enable_chroot_double = 1;
59121+#endif
59122+#ifdef CONFIG_GRKERNSEC_CHROOT_PIVOT
59123+ grsec_enable_chroot_pivot = 1;
59124+#endif
59125+#ifdef CONFIG_GRKERNSEC_CHROOT_CHDIR
59126+ grsec_enable_chroot_chdir = 1;
59127+#endif
59128+#ifdef CONFIG_GRKERNSEC_CHROOT_CHMOD
59129+ grsec_enable_chroot_chmod = 1;
59130+#endif
59131+#ifdef CONFIG_GRKERNSEC_CHROOT_MKNOD
59132+ grsec_enable_chroot_mknod = 1;
59133+#endif
59134+#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
59135+ grsec_enable_chroot_nice = 1;
59136+#endif
59137+#ifdef CONFIG_GRKERNSEC_CHROOT_EXECLOG
59138+ grsec_enable_chroot_execlog = 1;
59139+#endif
59140+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
59141+ grsec_enable_chroot_caps = 1;
59142+#endif
59143+#ifdef CONFIG_GRKERNSEC_CHROOT_SYSCTL
59144+ grsec_enable_chroot_sysctl = 1;
59145+#endif
59146+#ifdef CONFIG_GRKERNSEC_SYMLINKOWN
59147+ grsec_enable_symlinkown = 1;
59148+ grsec_symlinkown_gid = CONFIG_GRKERNSEC_SYMLINKOWN_GID;
59149+#endif
59150+#ifdef CONFIG_GRKERNSEC_TPE
59151+ grsec_enable_tpe = 1;
59152+ grsec_tpe_gid = CONFIG_GRKERNSEC_TPE_GID;
59153+#ifdef CONFIG_GRKERNSEC_TPE_ALL
59154+ grsec_enable_tpe_all = 1;
59155+#endif
59156+#endif
59157+#ifdef CONFIG_GRKERNSEC_SOCKET_ALL
59158+ grsec_enable_socket_all = 1;
59159+ grsec_socket_all_gid = CONFIG_GRKERNSEC_SOCKET_ALL_GID;
59160+#endif
59161+#ifdef CONFIG_GRKERNSEC_SOCKET_CLIENT
59162+ grsec_enable_socket_client = 1;
59163+ grsec_socket_client_gid = CONFIG_GRKERNSEC_SOCKET_CLIENT_GID;
59164+#endif
59165+#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
59166+ grsec_enable_socket_server = 1;
59167+ grsec_socket_server_gid = CONFIG_GRKERNSEC_SOCKET_SERVER_GID;
59168+#endif
59169+#endif
59170+
59171+ return;
59172+}
59173diff --git a/grsecurity/grsec_link.c b/grsecurity/grsec_link.c
59174new file mode 100644
59175index 0000000..589481f
59176--- /dev/null
59177+++ b/grsecurity/grsec_link.c
59178@@ -0,0 +1,58 @@
59179+#include <linux/kernel.h>
59180+#include <linux/sched.h>
59181+#include <linux/fs.h>
59182+#include <linux/file.h>
59183+#include <linux/grinternal.h>
59184+
59185+int gr_handle_symlink_owner(const struct path *link, const struct inode *target)
59186+{
59187+#ifdef CONFIG_GRKERNSEC_SYMLINKOWN
59188+ const struct inode *link_inode = link->dentry->d_inode;
59189+
59190+ if (grsec_enable_symlinkown && in_group_p(grsec_symlinkown_gid) &&
59191+ /* ignore root-owned links, e.g. /proc/self */
59192+ !uid_eq(link_inode->i_uid, GLOBAL_ROOT_UID) && target &&
59193+ !uid_eq(link_inode->i_uid, target->i_uid)) {
59194+ gr_log_fs_int2(GR_DONT_AUDIT, GR_SYMLINKOWNER_MSG, link->dentry, link->mnt, link_inode->i_uid, target->i_uid);
59195+ return 1;
59196+ }
59197+#endif
59198+ return 0;
59199+}
59200+
59201+int
59202+gr_handle_follow_link(const struct inode *parent,
59203+ const struct inode *inode,
59204+ const struct dentry *dentry, const struct vfsmount *mnt)
59205+{
59206+#ifdef CONFIG_GRKERNSEC_LINK
59207+ const struct cred *cred = current_cred();
59208+
59209+ if (grsec_enable_link && S_ISLNK(inode->i_mode) &&
59210+ (parent->i_mode & S_ISVTX) && !uid_eq(parent->i_uid, inode->i_uid) &&
59211+ (parent->i_mode & S_IWOTH) && !uid_eq(cred->fsuid, inode->i_uid)) {
59212+ gr_log_fs_int2(GR_DONT_AUDIT, GR_SYMLINK_MSG, dentry, mnt, inode->i_uid, inode->i_gid);
59213+ return -EACCES;
59214+ }
59215+#endif
59216+ return 0;
59217+}
59218+
59219+int
59220+gr_handle_hardlink(const struct dentry *dentry,
59221+ const struct vfsmount *mnt,
59222+ struct inode *inode, const int mode, const char *to)
59223+{
59224+#ifdef CONFIG_GRKERNSEC_LINK
59225+ const struct cred *cred = current_cred();
59226+
59227+ if (grsec_enable_link && !uid_eq(cred->fsuid, inode->i_uid) &&
59228+ (!S_ISREG(mode) || is_privileged_binary(dentry) ||
59229+ (inode_permission(inode, MAY_READ | MAY_WRITE))) &&
59230+ !capable(CAP_FOWNER) && !uid_eq(cred->uid, GLOBAL_ROOT_UID)) {
59231+ gr_log_fs_int2_str(GR_DONT_AUDIT, GR_HARDLINK_MSG, dentry, mnt, inode->i_uid, inode->i_gid, to);
59232+ return -EPERM;
59233+ }
59234+#endif
59235+ return 0;
59236+}
59237diff --git a/grsecurity/grsec_log.c b/grsecurity/grsec_log.c
59238new file mode 100644
59239index 0000000..a45d2e9
59240--- /dev/null
59241+++ b/grsecurity/grsec_log.c
59242@@ -0,0 +1,322 @@
59243+#include <linux/kernel.h>
59244+#include <linux/sched.h>
59245+#include <linux/file.h>
59246+#include <linux/tty.h>
59247+#include <linux/fs.h>
59248+#include <linux/grinternal.h>
59249+
59250+#ifdef CONFIG_TREE_PREEMPT_RCU
59251+#define DISABLE_PREEMPT() preempt_disable()
59252+#define ENABLE_PREEMPT() preempt_enable()
59253+#else
59254+#define DISABLE_PREEMPT()
59255+#define ENABLE_PREEMPT()
59256+#endif
59257+
59258+#define BEGIN_LOCKS(x) \
59259+ DISABLE_PREEMPT(); \
59260+ rcu_read_lock(); \
59261+ read_lock(&tasklist_lock); \
59262+ read_lock(&grsec_exec_file_lock); \
59263+ if (x != GR_DO_AUDIT) \
59264+ spin_lock(&grsec_alert_lock); \
59265+ else \
59266+ spin_lock(&grsec_audit_lock)
59267+
59268+#define END_LOCKS(x) \
59269+ if (x != GR_DO_AUDIT) \
59270+ spin_unlock(&grsec_alert_lock); \
59271+ else \
59272+ spin_unlock(&grsec_audit_lock); \
59273+ read_unlock(&grsec_exec_file_lock); \
59274+ read_unlock(&tasklist_lock); \
59275+ rcu_read_unlock(); \
59276+ ENABLE_PREEMPT(); \
59277+ if (x == GR_DONT_AUDIT) \
59278+ gr_handle_alertkill(current)
59279+
59280+enum {
59281+ FLOODING,
59282+ NO_FLOODING
59283+};
59284+
59285+extern char *gr_alert_log_fmt;
59286+extern char *gr_audit_log_fmt;
59287+extern char *gr_alert_log_buf;
59288+extern char *gr_audit_log_buf;
59289+
59290+static int gr_log_start(int audit)
59291+{
59292+ char *loglevel = (audit == GR_DO_AUDIT) ? KERN_INFO : KERN_ALERT;
59293+ char *fmt = (audit == GR_DO_AUDIT) ? gr_audit_log_fmt : gr_alert_log_fmt;
59294+ char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
59295+#if (CONFIG_GRKERNSEC_FLOODTIME > 0 && CONFIG_GRKERNSEC_FLOODBURST > 0)
59296+ unsigned long curr_secs = get_seconds();
59297+
59298+ if (audit == GR_DO_AUDIT)
59299+ goto set_fmt;
59300+
59301+ if (!grsec_alert_wtime || time_after(curr_secs, grsec_alert_wtime + CONFIG_GRKERNSEC_FLOODTIME)) {
59302+ grsec_alert_wtime = curr_secs;
59303+ grsec_alert_fyet = 0;
59304+ } else if (time_before_eq(curr_secs, grsec_alert_wtime + CONFIG_GRKERNSEC_FLOODTIME)
59305+ && (grsec_alert_fyet < CONFIG_GRKERNSEC_FLOODBURST)) {
59306+ grsec_alert_fyet++;
59307+ } else if (grsec_alert_fyet == CONFIG_GRKERNSEC_FLOODBURST) {
59308+ grsec_alert_wtime = curr_secs;
59309+ grsec_alert_fyet++;
59310+ printk(KERN_ALERT "grsec: more alerts, logging disabled for %d seconds\n", CONFIG_GRKERNSEC_FLOODTIME);
59311+ return FLOODING;
59312+ }
59313+ else return FLOODING;
59314+
59315+set_fmt:
59316+#endif
59317+ memset(buf, 0, PAGE_SIZE);
59318+ if (current->signal->curr_ip && gr_acl_is_enabled()) {
59319+ sprintf(fmt, "%s%s", loglevel, "grsec: From %pI4: (%.64s:%c:%.950s) ");
59320+ snprintf(buf, PAGE_SIZE - 1, fmt, &current->signal->curr_ip, current->role->rolename, gr_roletype_to_char(), current->acl->filename);
59321+ } else if (current->signal->curr_ip) {
59322+ sprintf(fmt, "%s%s", loglevel, "grsec: From %pI4: ");
59323+ snprintf(buf, PAGE_SIZE - 1, fmt, &current->signal->curr_ip);
59324+ } else if (gr_acl_is_enabled()) {
59325+ sprintf(fmt, "%s%s", loglevel, "grsec: (%.64s:%c:%.950s) ");
59326+ snprintf(buf, PAGE_SIZE - 1, fmt, current->role->rolename, gr_roletype_to_char(), current->acl->filename);
59327+ } else {
59328+ sprintf(fmt, "%s%s", loglevel, "grsec: ");
59329+ strcpy(buf, fmt);
59330+ }
59331+
59332+ return NO_FLOODING;
59333+}
59334+
59335+static void gr_log_middle(int audit, const char *msg, va_list ap)
59336+ __attribute__ ((format (printf, 2, 0)));
59337+
59338+static void gr_log_middle(int audit, const char *msg, va_list ap)
59339+{
59340+ char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
59341+ unsigned int len = strlen(buf);
59342+
59343+ vsnprintf(buf + len, PAGE_SIZE - len - 1, msg, ap);
59344+
59345+ return;
59346+}
59347+
59348+static void gr_log_middle_varargs(int audit, const char *msg, ...)
59349+ __attribute__ ((format (printf, 2, 3)));
59350+
59351+static void gr_log_middle_varargs(int audit, const char *msg, ...)
59352+{
59353+ char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
59354+ unsigned int len = strlen(buf);
59355+ va_list ap;
59356+
59357+ va_start(ap, msg);
59358+ vsnprintf(buf + len, PAGE_SIZE - len - 1, msg, ap);
59359+ va_end(ap);
59360+
59361+ return;
59362+}
59363+
59364+static void gr_log_end(int audit, int append_default)
59365+{
59366+ char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
59367+
59368+ if (append_default) {
59369+ unsigned int len = strlen(buf);
59370+ snprintf(buf + len, PAGE_SIZE - len - 1, DEFAULTSECMSG, DEFAULTSECARGS(current, current_cred(), __task_cred(current->real_parent)));
59371+ }
59372+
59373+ printk("%s\n", buf);
59374+
59375+ return;
59376+}
59377+
59378+void gr_log_varargs(int audit, const char *msg, int argtypes, ...)
59379+{
59380+ int logtype;
59381+ char *result = (audit == GR_DO_AUDIT) ? "successful" : "denied";
59382+ char *str1 = NULL, *str2 = NULL, *str3 = NULL;
59383+ void *voidptr = NULL;
59384+ int num1 = 0, num2 = 0;
59385+ unsigned long ulong1 = 0, ulong2 = 0;
59386+ struct dentry *dentry = NULL;
59387+ struct vfsmount *mnt = NULL;
59388+ struct file *file = NULL;
59389+ struct task_struct *task = NULL;
59390+ const struct cred *cred, *pcred;
59391+ va_list ap;
59392+
59393+ BEGIN_LOCKS(audit);
59394+ logtype = gr_log_start(audit);
59395+ if (logtype == FLOODING) {
59396+ END_LOCKS(audit);
59397+ return;
59398+ }
59399+ va_start(ap, argtypes);
59400+ switch (argtypes) {
59401+ case GR_TTYSNIFF:
59402+ task = va_arg(ap, struct task_struct *);
59403+ 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);
59404+ break;
59405+ case GR_SYSCTL_HIDDEN:
59406+ str1 = va_arg(ap, char *);
59407+ gr_log_middle_varargs(audit, msg, result, str1);
59408+ break;
59409+ case GR_RBAC:
59410+ dentry = va_arg(ap, struct dentry *);
59411+ mnt = va_arg(ap, struct vfsmount *);
59412+ gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt));
59413+ break;
59414+ case GR_RBAC_STR:
59415+ dentry = va_arg(ap, struct dentry *);
59416+ mnt = va_arg(ap, struct vfsmount *);
59417+ str1 = va_arg(ap, char *);
59418+ gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt), str1);
59419+ break;
59420+ case GR_STR_RBAC:
59421+ str1 = va_arg(ap, char *);
59422+ dentry = va_arg(ap, struct dentry *);
59423+ mnt = va_arg(ap, struct vfsmount *);
59424+ gr_log_middle_varargs(audit, msg, result, str1, gr_to_filename(dentry, mnt));
59425+ break;
59426+ case GR_RBAC_MODE2:
59427+ dentry = va_arg(ap, struct dentry *);
59428+ mnt = va_arg(ap, struct vfsmount *);
59429+ str1 = va_arg(ap, char *);
59430+ str2 = va_arg(ap, char *);
59431+ gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt), str1, str2);
59432+ break;
59433+ case GR_RBAC_MODE3:
59434+ dentry = va_arg(ap, struct dentry *);
59435+ mnt = va_arg(ap, struct vfsmount *);
59436+ str1 = va_arg(ap, char *);
59437+ str2 = va_arg(ap, char *);
59438+ str3 = va_arg(ap, char *);
59439+ gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt), str1, str2, str3);
59440+ break;
59441+ case GR_FILENAME:
59442+ dentry = va_arg(ap, struct dentry *);
59443+ mnt = va_arg(ap, struct vfsmount *);
59444+ gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt));
59445+ break;
59446+ case GR_STR_FILENAME:
59447+ str1 = va_arg(ap, char *);
59448+ dentry = va_arg(ap, struct dentry *);
59449+ mnt = va_arg(ap, struct vfsmount *);
59450+ gr_log_middle_varargs(audit, msg, str1, gr_to_filename(dentry, mnt));
59451+ break;
59452+ case GR_FILENAME_STR:
59453+ dentry = va_arg(ap, struct dentry *);
59454+ mnt = va_arg(ap, struct vfsmount *);
59455+ str1 = va_arg(ap, char *);
59456+ gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt), str1);
59457+ break;
59458+ case GR_FILENAME_TWO_INT:
59459+ dentry = va_arg(ap, struct dentry *);
59460+ mnt = va_arg(ap, struct vfsmount *);
59461+ num1 = va_arg(ap, int);
59462+ num2 = va_arg(ap, int);
59463+ gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt), num1, num2);
59464+ break;
59465+ case GR_FILENAME_TWO_INT_STR:
59466+ dentry = va_arg(ap, struct dentry *);
59467+ mnt = va_arg(ap, struct vfsmount *);
59468+ num1 = va_arg(ap, int);
59469+ num2 = va_arg(ap, int);
59470+ str1 = va_arg(ap, char *);
59471+ gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt), num1, num2, str1);
59472+ break;
59473+ case GR_TEXTREL:
59474+ file = va_arg(ap, struct file *);
59475+ ulong1 = va_arg(ap, unsigned long);
59476+ ulong2 = va_arg(ap, unsigned long);
59477+ gr_log_middle_varargs(audit, msg, file ? gr_to_filename(file->f_path.dentry, file->f_path.mnt) : "<anonymous mapping>", ulong1, ulong2);
59478+ break;
59479+ case GR_PTRACE:
59480+ task = va_arg(ap, struct task_struct *);
59481+ 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);
59482+ break;
59483+ case GR_RESOURCE:
59484+ task = va_arg(ap, struct task_struct *);
59485+ cred = __task_cred(task);
59486+ pcred = __task_cred(task->real_parent);
59487+ ulong1 = va_arg(ap, unsigned long);
59488+ str1 = va_arg(ap, char *);
59489+ ulong2 = va_arg(ap, unsigned long);
59490+ 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);
59491+ break;
59492+ case GR_CAP:
59493+ task = va_arg(ap, struct task_struct *);
59494+ cred = __task_cred(task);
59495+ pcred = __task_cred(task->real_parent);
59496+ str1 = va_arg(ap, char *);
59497+ 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);
59498+ break;
59499+ case GR_SIG:
59500+ str1 = va_arg(ap, char *);
59501+ voidptr = va_arg(ap, void *);
59502+ gr_log_middle_varargs(audit, msg, str1, voidptr);
59503+ break;
59504+ case GR_SIG2:
59505+ task = va_arg(ap, struct task_struct *);
59506+ cred = __task_cred(task);
59507+ pcred = __task_cred(task->real_parent);
59508+ num1 = va_arg(ap, int);
59509+ 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);
59510+ break;
59511+ case GR_CRASH1:
59512+ task = va_arg(ap, struct task_struct *);
59513+ cred = __task_cred(task);
59514+ pcred = __task_cred(task->real_parent);
59515+ ulong1 = va_arg(ap, unsigned long);
59516+ 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);
59517+ break;
59518+ case GR_CRASH2:
59519+ task = va_arg(ap, struct task_struct *);
59520+ cred = __task_cred(task);
59521+ pcred = __task_cred(task->real_parent);
59522+ ulong1 = va_arg(ap, unsigned long);
59523+ 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);
59524+ break;
59525+ case GR_RWXMAP:
59526+ file = va_arg(ap, struct file *);
59527+ gr_log_middle_varargs(audit, msg, file ? gr_to_filename(file->f_path.dentry, file->f_path.mnt) : "<anonymous mapping>");
59528+ break;
59529+ case GR_PSACCT:
59530+ {
59531+ unsigned int wday, cday;
59532+ __u8 whr, chr;
59533+ __u8 wmin, cmin;
59534+ __u8 wsec, csec;
59535+ char cur_tty[64] = { 0 };
59536+ char parent_tty[64] = { 0 };
59537+
59538+ task = va_arg(ap, struct task_struct *);
59539+ wday = va_arg(ap, unsigned int);
59540+ cday = va_arg(ap, unsigned int);
59541+ whr = va_arg(ap, int);
59542+ chr = va_arg(ap, int);
59543+ wmin = va_arg(ap, int);
59544+ cmin = va_arg(ap, int);
59545+ wsec = va_arg(ap, int);
59546+ csec = va_arg(ap, int);
59547+ ulong1 = va_arg(ap, unsigned long);
59548+ cred = __task_cred(task);
59549+ pcred = __task_cred(task->real_parent);
59550+
59551+ 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);
59552+ }
59553+ break;
59554+ default:
59555+ gr_log_middle(audit, msg, ap);
59556+ }
59557+ va_end(ap);
59558+ // these don't need DEFAULTSECARGS printed on the end
59559+ if (argtypes == GR_CRASH1 || argtypes == GR_CRASH2)
59560+ gr_log_end(audit, 0);
59561+ else
59562+ gr_log_end(audit, 1);
59563+ END_LOCKS(audit);
59564+}
59565diff --git a/grsecurity/grsec_mem.c b/grsecurity/grsec_mem.c
59566new file mode 100644
59567index 0000000..f536303
59568--- /dev/null
59569+++ b/grsecurity/grsec_mem.c
59570@@ -0,0 +1,40 @@
59571+#include <linux/kernel.h>
59572+#include <linux/sched.h>
59573+#include <linux/mm.h>
59574+#include <linux/mman.h>
59575+#include <linux/grinternal.h>
59576+
59577+void
59578+gr_handle_ioperm(void)
59579+{
59580+ gr_log_noargs(GR_DONT_AUDIT, GR_IOPERM_MSG);
59581+ return;
59582+}
59583+
59584+void
59585+gr_handle_iopl(void)
59586+{
59587+ gr_log_noargs(GR_DONT_AUDIT, GR_IOPL_MSG);
59588+ return;
59589+}
59590+
59591+void
59592+gr_handle_mem_readwrite(u64 from, u64 to)
59593+{
59594+ gr_log_two_u64(GR_DONT_AUDIT, GR_MEM_READWRITE_MSG, from, to);
59595+ return;
59596+}
59597+
59598+void
59599+gr_handle_vm86(void)
59600+{
59601+ gr_log_noargs(GR_DONT_AUDIT, GR_VM86_MSG);
59602+ return;
59603+}
59604+
59605+void
59606+gr_log_badprocpid(const char *entry)
59607+{
59608+ gr_log_str(GR_DONT_AUDIT, GR_BADPROCPID_MSG, entry);
59609+ return;
59610+}
59611diff --git a/grsecurity/grsec_mount.c b/grsecurity/grsec_mount.c
59612new file mode 100644
59613index 0000000..2131422
59614--- /dev/null
59615+++ b/grsecurity/grsec_mount.c
59616@@ -0,0 +1,62 @@
59617+#include <linux/kernel.h>
59618+#include <linux/sched.h>
59619+#include <linux/mount.h>
59620+#include <linux/grsecurity.h>
59621+#include <linux/grinternal.h>
59622+
59623+void
59624+gr_log_remount(const char *devname, const int retval)
59625+{
59626+#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
59627+ if (grsec_enable_mount && (retval >= 0))
59628+ gr_log_str(GR_DO_AUDIT, GR_REMOUNT_AUDIT_MSG, devname ? devname : "none");
59629+#endif
59630+ return;
59631+}
59632+
59633+void
59634+gr_log_unmount(const char *devname, const int retval)
59635+{
59636+#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
59637+ if (grsec_enable_mount && (retval >= 0))
59638+ gr_log_str(GR_DO_AUDIT, GR_UNMOUNT_AUDIT_MSG, devname ? devname : "none");
59639+#endif
59640+ return;
59641+}
59642+
59643+void
59644+gr_log_mount(const char *from, const char *to, const int retval)
59645+{
59646+#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
59647+ if (grsec_enable_mount && (retval >= 0))
59648+ gr_log_str_str(GR_DO_AUDIT, GR_MOUNT_AUDIT_MSG, from ? from : "none", to);
59649+#endif
59650+ return;
59651+}
59652+
59653+int
59654+gr_handle_rofs_mount(struct dentry *dentry, struct vfsmount *mnt, int mnt_flags)
59655+{
59656+#ifdef CONFIG_GRKERNSEC_ROFS
59657+ if (grsec_enable_rofs && !(mnt_flags & MNT_READONLY)) {
59658+ gr_log_fs_generic(GR_DO_AUDIT, GR_ROFS_MOUNT_MSG, dentry, mnt);
59659+ return -EPERM;
59660+ } else
59661+ return 0;
59662+#endif
59663+ return 0;
59664+}
59665+
59666+int
59667+gr_handle_rofs_blockwrite(struct dentry *dentry, struct vfsmount *mnt, int acc_mode)
59668+{
59669+#ifdef CONFIG_GRKERNSEC_ROFS
59670+ if (grsec_enable_rofs && (acc_mode & MAY_WRITE) &&
59671+ dentry->d_inode && S_ISBLK(dentry->d_inode->i_mode)) {
59672+ gr_log_fs_generic(GR_DO_AUDIT, GR_ROFS_BLOCKWRITE_MSG, dentry, mnt);
59673+ return -EPERM;
59674+ } else
59675+ return 0;
59676+#endif
59677+ return 0;
59678+}
59679diff --git a/grsecurity/grsec_pax.c b/grsecurity/grsec_pax.c
59680new file mode 100644
59681index 0000000..a3b12a0
59682--- /dev/null
59683+++ b/grsecurity/grsec_pax.c
59684@@ -0,0 +1,36 @@
59685+#include <linux/kernel.h>
59686+#include <linux/sched.h>
59687+#include <linux/mm.h>
59688+#include <linux/file.h>
59689+#include <linux/grinternal.h>
59690+#include <linux/grsecurity.h>
59691+
59692+void
59693+gr_log_textrel(struct vm_area_struct * vma)
59694+{
59695+#ifdef CONFIG_GRKERNSEC_AUDIT_TEXTREL
59696+ if (grsec_enable_audit_textrel)
59697+ gr_log_textrel_ulong_ulong(GR_DO_AUDIT, GR_TEXTREL_AUDIT_MSG, vma->vm_file, vma->vm_start, vma->vm_pgoff);
59698+#endif
59699+ return;
59700+}
59701+
59702+void
59703+gr_log_rwxmmap(struct file *file)
59704+{
59705+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
59706+ if (grsec_enable_log_rwxmaps)
59707+ gr_log_rwxmap(GR_DONT_AUDIT, GR_RWXMMAP_MSG, file);
59708+#endif
59709+ return;
59710+}
59711+
59712+void
59713+gr_log_rwxmprotect(struct file *file)
59714+{
59715+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
59716+ if (grsec_enable_log_rwxmaps)
59717+ gr_log_rwxmap(GR_DONT_AUDIT, GR_RWXMPROTECT_MSG, file);
59718+#endif
59719+ return;
59720+}
59721diff --git a/grsecurity/grsec_ptrace.c b/grsecurity/grsec_ptrace.c
59722new file mode 100644
59723index 0000000..f7f29aa
59724--- /dev/null
59725+++ b/grsecurity/grsec_ptrace.c
59726@@ -0,0 +1,30 @@
59727+#include <linux/kernel.h>
59728+#include <linux/sched.h>
59729+#include <linux/grinternal.h>
59730+#include <linux/security.h>
59731+
59732+void
59733+gr_audit_ptrace(struct task_struct *task)
59734+{
59735+#ifdef CONFIG_GRKERNSEC_AUDIT_PTRACE
59736+ if (grsec_enable_audit_ptrace)
59737+ gr_log_ptrace(GR_DO_AUDIT, GR_PTRACE_AUDIT_MSG, task);
59738+#endif
59739+ return;
59740+}
59741+
59742+int
59743+gr_ptrace_readexec(struct file *file, int unsafe_flags)
59744+{
59745+#ifdef CONFIG_GRKERNSEC_PTRACE_READEXEC
59746+ const struct dentry *dentry = file->f_path.dentry;
59747+ const struct vfsmount *mnt = file->f_path.mnt;
59748+
59749+ if (grsec_enable_ptrace_readexec && (unsafe_flags & LSM_UNSAFE_PTRACE) &&
59750+ (inode_permission(dentry->d_inode, MAY_READ) || !gr_acl_handle_open(dentry, mnt, MAY_READ))) {
59751+ gr_log_fs_generic(GR_DONT_AUDIT, GR_PTRACE_READEXEC_MSG, dentry, mnt);
59752+ return -EACCES;
59753+ }
59754+#endif
59755+ return 0;
59756+}
59757diff --git a/grsecurity/grsec_sig.c b/grsecurity/grsec_sig.c
59758new file mode 100644
59759index 0000000..b4ac94c
59760--- /dev/null
59761+++ b/grsecurity/grsec_sig.c
59762@@ -0,0 +1,209 @@
59763+#include <linux/kernel.h>
59764+#include <linux/sched.h>
59765+#include <linux/delay.h>
59766+#include <linux/grsecurity.h>
59767+#include <linux/grinternal.h>
59768+#include <linux/hardirq.h>
59769+
59770+char *signames[] = {
59771+ [SIGSEGV] = "Segmentation fault",
59772+ [SIGILL] = "Illegal instruction",
59773+ [SIGABRT] = "Abort",
59774+ [SIGBUS] = "Invalid alignment/Bus error"
59775+};
59776+
59777+void
59778+gr_log_signal(const int sig, const void *addr, const struct task_struct *t)
59779+{
59780+#ifdef CONFIG_GRKERNSEC_SIGNAL
59781+ if (grsec_enable_signal && ((sig == SIGSEGV) || (sig == SIGILL) ||
59782+ (sig == SIGABRT) || (sig == SIGBUS))) {
59783+ if (t->pid == current->pid) {
59784+ gr_log_sig_addr(GR_DONT_AUDIT_GOOD, GR_UNISIGLOG_MSG, signames[sig], addr);
59785+ } else {
59786+ gr_log_sig_task(GR_DONT_AUDIT_GOOD, GR_DUALSIGLOG_MSG, t, sig);
59787+ }
59788+ }
59789+#endif
59790+ return;
59791+}
59792+
59793+int
59794+gr_handle_signal(const struct task_struct *p, const int sig)
59795+{
59796+#ifdef CONFIG_GRKERNSEC
59797+ /* ignore the 0 signal for protected task checks */
59798+ if (current->pid > 1 && sig && gr_check_protected_task(p)) {
59799+ gr_log_sig_task(GR_DONT_AUDIT, GR_SIG_ACL_MSG, p, sig);
59800+ return -EPERM;
59801+ } else if (gr_pid_is_chrooted((struct task_struct *)p)) {
59802+ return -EPERM;
59803+ }
59804+#endif
59805+ return 0;
59806+}
59807+
59808+#ifdef CONFIG_GRKERNSEC
59809+extern int specific_send_sig_info(int sig, struct siginfo *info, struct task_struct *t);
59810+
59811+int gr_fake_force_sig(int sig, struct task_struct *t)
59812+{
59813+ unsigned long int flags;
59814+ int ret, blocked, ignored;
59815+ struct k_sigaction *action;
59816+
59817+ spin_lock_irqsave(&t->sighand->siglock, flags);
59818+ action = &t->sighand->action[sig-1];
59819+ ignored = action->sa.sa_handler == SIG_IGN;
59820+ blocked = sigismember(&t->blocked, sig);
59821+ if (blocked || ignored) {
59822+ action->sa.sa_handler = SIG_DFL;
59823+ if (blocked) {
59824+ sigdelset(&t->blocked, sig);
59825+ recalc_sigpending_and_wake(t);
59826+ }
59827+ }
59828+ if (action->sa.sa_handler == SIG_DFL)
59829+ t->signal->flags &= ~SIGNAL_UNKILLABLE;
59830+ ret = specific_send_sig_info(sig, SEND_SIG_PRIV, t);
59831+
59832+ spin_unlock_irqrestore(&t->sighand->siglock, flags);
59833+
59834+ return ret;
59835+}
59836+#endif
59837+
59838+#ifdef CONFIG_GRKERNSEC_BRUTE
59839+#define GR_USER_BAN_TIME (15 * 60)
59840+
59841+static int __get_dumpable(unsigned long mm_flags)
59842+{
59843+ int ret;
59844+
59845+ ret = mm_flags & MMF_DUMPABLE_MASK;
59846+ return (ret >= 2) ? 2 : ret;
59847+}
59848+#endif
59849+
59850+void gr_handle_brute_attach(struct task_struct *p, unsigned long mm_flags)
59851+{
59852+#ifdef CONFIG_GRKERNSEC_BRUTE
59853+ kuid_t uid = GLOBAL_ROOT_UID;
59854+
59855+ if (!grsec_enable_brute)
59856+ return;
59857+
59858+ rcu_read_lock();
59859+ read_lock(&tasklist_lock);
59860+ read_lock(&grsec_exec_file_lock);
59861+ if (p->real_parent && p->real_parent->exec_file == p->exec_file)
59862+ p->real_parent->brute = 1;
59863+ else {
59864+ const struct cred *cred = __task_cred(p), *cred2;
59865+ struct task_struct *tsk, *tsk2;
59866+
59867+ if (!__get_dumpable(mm_flags) && !uid_eq(cred->uid, GLOBAL_ROOT_UID)) {
59868+ struct user_struct *user;
59869+
59870+ uid = cred->uid;
59871+
59872+ /* this is put upon execution past expiration */
59873+ user = find_user(uid);
59874+ if (user == NULL)
59875+ goto unlock;
59876+ user->banned = 1;
59877+ user->ban_expires = get_seconds() + GR_USER_BAN_TIME;
59878+ if (user->ban_expires == ~0UL)
59879+ user->ban_expires--;
59880+
59881+ do_each_thread(tsk2, tsk) {
59882+ cred2 = __task_cred(tsk);
59883+ if (tsk != p && uid_eq(cred2->uid, uid))
59884+ gr_fake_force_sig(SIGKILL, tsk);
59885+ } while_each_thread(tsk2, tsk);
59886+ }
59887+ }
59888+unlock:
59889+ read_unlock(&grsec_exec_file_lock);
59890+ read_unlock(&tasklist_lock);
59891+ rcu_read_unlock();
59892+
59893+ if (!uid_eq(uid, GLOBAL_ROOT_UID))
59894+ printk(KERN_ALERT "grsec: bruteforce prevention initiated against uid %u, banning for %d minutes\n",
59895+ from_kuid_munged(&init_user_ns, uid), GR_USER_BAN_TIME / 60);
59896+
59897+#endif
59898+ return;
59899+}
59900+
59901+void gr_handle_brute_check(void)
59902+{
59903+#ifdef CONFIG_GRKERNSEC_BRUTE
59904+ if (current->brute)
59905+ msleep(30 * 1000);
59906+#endif
59907+ return;
59908+}
59909+
59910+void gr_handle_kernel_exploit(void)
59911+{
59912+#ifdef CONFIG_GRKERNSEC_KERN_LOCKOUT
59913+ const struct cred *cred;
59914+ struct task_struct *tsk, *tsk2;
59915+ struct user_struct *user;
59916+ kuid_t uid;
59917+
59918+ if (in_irq() || in_serving_softirq() || in_nmi())
59919+ panic("grsec: halting the system due to suspicious kernel crash caused in interrupt context");
59920+
59921+ uid = current_uid();
59922+
59923+ if (uid_eq(uid, GLOBAL_ROOT_UID))
59924+ panic("grsec: halting the system due to suspicious kernel crash caused by root");
59925+ else {
59926+ /* kill all the processes of this user, hold a reference
59927+ to their creds struct, and prevent them from creating
59928+ another process until system reset
59929+ */
59930+ printk(KERN_ALERT "grsec: banning user with uid %u until system restart for suspicious kernel crash\n",
59931+ from_kuid_munged(&init_user_ns, uid));
59932+ /* we intentionally leak this ref */
59933+ user = get_uid(current->cred->user);
59934+ if (user) {
59935+ user->banned = 1;
59936+ user->ban_expires = ~0UL;
59937+ }
59938+
59939+ read_lock(&tasklist_lock);
59940+ do_each_thread(tsk2, tsk) {
59941+ cred = __task_cred(tsk);
59942+ if (uid_eq(cred->uid, uid))
59943+ gr_fake_force_sig(SIGKILL, tsk);
59944+ } while_each_thread(tsk2, tsk);
59945+ read_unlock(&tasklist_lock);
59946+ }
59947+#endif
59948+}
59949+
59950+int __gr_process_user_ban(struct user_struct *user)
59951+{
59952+#if defined(CONFIG_GRKERNSEC_KERN_LOCKOUT) || defined(CONFIG_GRKERNSEC_BRUTE)
59953+ if (unlikely(user->banned)) {
59954+ if (user->ban_expires != ~0UL && time_after_eq(get_seconds(), user->ban_expires)) {
59955+ user->banned = 0;
59956+ user->ban_expires = 0;
59957+ free_uid(user);
59958+ } else
59959+ return -EPERM;
59960+ }
59961+#endif
59962+ return 0;
59963+}
59964+
59965+int gr_process_user_ban(void)
59966+{
59967+#if defined(CONFIG_GRKERNSEC_KERN_LOCKOUT) || defined(CONFIG_GRKERNSEC_BRUTE)
59968+ return __gr_process_user_ban(current->cred->user);
59969+#endif
59970+ return 0;
59971+}
59972diff --git a/grsecurity/grsec_sock.c b/grsecurity/grsec_sock.c
59973new file mode 100644
59974index 0000000..4030d57
59975--- /dev/null
59976+++ b/grsecurity/grsec_sock.c
59977@@ -0,0 +1,244 @@
59978+#include <linux/kernel.h>
59979+#include <linux/module.h>
59980+#include <linux/sched.h>
59981+#include <linux/file.h>
59982+#include <linux/net.h>
59983+#include <linux/in.h>
59984+#include <linux/ip.h>
59985+#include <net/sock.h>
59986+#include <net/inet_sock.h>
59987+#include <linux/grsecurity.h>
59988+#include <linux/grinternal.h>
59989+#include <linux/gracl.h>
59990+
59991+extern int gr_search_udp_recvmsg(const struct sock *sk, const struct sk_buff *skb);
59992+extern int gr_search_udp_sendmsg(const struct sock *sk, const struct sockaddr_in *addr);
59993+
59994+EXPORT_SYMBOL(gr_search_udp_recvmsg);
59995+EXPORT_SYMBOL(gr_search_udp_sendmsg);
59996+
59997+#ifdef CONFIG_UNIX_MODULE
59998+EXPORT_SYMBOL(gr_acl_handle_unix);
59999+EXPORT_SYMBOL(gr_acl_handle_mknod);
60000+EXPORT_SYMBOL(gr_handle_chroot_unix);
60001+EXPORT_SYMBOL(gr_handle_create);
60002+#endif
60003+
60004+#ifdef CONFIG_GRKERNSEC
60005+#define gr_conn_table_size 32749
60006+struct conn_table_entry {
60007+ struct conn_table_entry *next;
60008+ struct signal_struct *sig;
60009+};
60010+
60011+struct conn_table_entry *gr_conn_table[gr_conn_table_size];
60012+DEFINE_SPINLOCK(gr_conn_table_lock);
60013+
60014+extern const char * gr_socktype_to_name(unsigned char type);
60015+extern const char * gr_proto_to_name(unsigned char proto);
60016+extern const char * gr_sockfamily_to_name(unsigned char family);
60017+
60018+static __inline__ int
60019+conn_hash(__u32 saddr, __u32 daddr, __u16 sport, __u16 dport, unsigned int size)
60020+{
60021+ return ((daddr + saddr + (sport << 8) + (dport << 16)) % size);
60022+}
60023+
60024+static __inline__ int
60025+conn_match(const struct signal_struct *sig, __u32 saddr, __u32 daddr,
60026+ __u16 sport, __u16 dport)
60027+{
60028+ if (unlikely(sig->gr_saddr == saddr && sig->gr_daddr == daddr &&
60029+ sig->gr_sport == sport && sig->gr_dport == dport))
60030+ return 1;
60031+ else
60032+ return 0;
60033+}
60034+
60035+static void gr_add_to_task_ip_table_nolock(struct signal_struct *sig, struct conn_table_entry *newent)
60036+{
60037+ struct conn_table_entry **match;
60038+ unsigned int index;
60039+
60040+ index = conn_hash(sig->gr_saddr, sig->gr_daddr,
60041+ sig->gr_sport, sig->gr_dport,
60042+ gr_conn_table_size);
60043+
60044+ newent->sig = sig;
60045+
60046+ match = &gr_conn_table[index];
60047+ newent->next = *match;
60048+ *match = newent;
60049+
60050+ return;
60051+}
60052+
60053+static void gr_del_task_from_ip_table_nolock(struct signal_struct *sig)
60054+{
60055+ struct conn_table_entry *match, *last = NULL;
60056+ unsigned int index;
60057+
60058+ index = conn_hash(sig->gr_saddr, sig->gr_daddr,
60059+ sig->gr_sport, sig->gr_dport,
60060+ gr_conn_table_size);
60061+
60062+ match = gr_conn_table[index];
60063+ while (match && !conn_match(match->sig,
60064+ sig->gr_saddr, sig->gr_daddr, sig->gr_sport,
60065+ sig->gr_dport)) {
60066+ last = match;
60067+ match = match->next;
60068+ }
60069+
60070+ if (match) {
60071+ if (last)
60072+ last->next = match->next;
60073+ else
60074+ gr_conn_table[index] = NULL;
60075+ kfree(match);
60076+ }
60077+
60078+ return;
60079+}
60080+
60081+static struct signal_struct * gr_lookup_task_ip_table(__u32 saddr, __u32 daddr,
60082+ __u16 sport, __u16 dport)
60083+{
60084+ struct conn_table_entry *match;
60085+ unsigned int index;
60086+
60087+ index = conn_hash(saddr, daddr, sport, dport, gr_conn_table_size);
60088+
60089+ match = gr_conn_table[index];
60090+ while (match && !conn_match(match->sig, saddr, daddr, sport, dport))
60091+ match = match->next;
60092+
60093+ if (match)
60094+ return match->sig;
60095+ else
60096+ return NULL;
60097+}
60098+
60099+#endif
60100+
60101+void gr_update_task_in_ip_table(struct task_struct *task, const struct inet_sock *inet)
60102+{
60103+#ifdef CONFIG_GRKERNSEC
60104+ struct signal_struct *sig = task->signal;
60105+ struct conn_table_entry *newent;
60106+
60107+ newent = kmalloc(sizeof(struct conn_table_entry), GFP_ATOMIC);
60108+ if (newent == NULL)
60109+ return;
60110+ /* no bh lock needed since we are called with bh disabled */
60111+ spin_lock(&gr_conn_table_lock);
60112+ gr_del_task_from_ip_table_nolock(sig);
60113+ sig->gr_saddr = inet->inet_rcv_saddr;
60114+ sig->gr_daddr = inet->inet_daddr;
60115+ sig->gr_sport = inet->inet_sport;
60116+ sig->gr_dport = inet->inet_dport;
60117+ gr_add_to_task_ip_table_nolock(sig, newent);
60118+ spin_unlock(&gr_conn_table_lock);
60119+#endif
60120+ return;
60121+}
60122+
60123+void gr_del_task_from_ip_table(struct task_struct *task)
60124+{
60125+#ifdef CONFIG_GRKERNSEC
60126+ spin_lock_bh(&gr_conn_table_lock);
60127+ gr_del_task_from_ip_table_nolock(task->signal);
60128+ spin_unlock_bh(&gr_conn_table_lock);
60129+#endif
60130+ return;
60131+}
60132+
60133+void
60134+gr_attach_curr_ip(const struct sock *sk)
60135+{
60136+#ifdef CONFIG_GRKERNSEC
60137+ struct signal_struct *p, *set;
60138+ const struct inet_sock *inet = inet_sk(sk);
60139+
60140+ if (unlikely(sk->sk_protocol != IPPROTO_TCP))
60141+ return;
60142+
60143+ set = current->signal;
60144+
60145+ spin_lock_bh(&gr_conn_table_lock);
60146+ p = gr_lookup_task_ip_table(inet->inet_daddr, inet->inet_rcv_saddr,
60147+ inet->inet_dport, inet->inet_sport);
60148+ if (unlikely(p != NULL)) {
60149+ set->curr_ip = p->curr_ip;
60150+ set->used_accept = 1;
60151+ gr_del_task_from_ip_table_nolock(p);
60152+ spin_unlock_bh(&gr_conn_table_lock);
60153+ return;
60154+ }
60155+ spin_unlock_bh(&gr_conn_table_lock);
60156+
60157+ set->curr_ip = inet->inet_daddr;
60158+ set->used_accept = 1;
60159+#endif
60160+ return;
60161+}
60162+
60163+int
60164+gr_handle_sock_all(const int family, const int type, const int protocol)
60165+{
60166+#ifdef CONFIG_GRKERNSEC_SOCKET_ALL
60167+ if (grsec_enable_socket_all && in_group_p(grsec_socket_all_gid) &&
60168+ (family != AF_UNIX)) {
60169+ if (family == AF_INET)
60170+ gr_log_str3(GR_DONT_AUDIT, GR_SOCK_MSG, gr_sockfamily_to_name(family), gr_socktype_to_name(type), gr_proto_to_name(protocol));
60171+ else
60172+ gr_log_str2_int(GR_DONT_AUDIT, GR_SOCK_NOINET_MSG, gr_sockfamily_to_name(family), gr_socktype_to_name(type), protocol);
60173+ return -EACCES;
60174+ }
60175+#endif
60176+ return 0;
60177+}
60178+
60179+int
60180+gr_handle_sock_server(const struct sockaddr *sck)
60181+{
60182+#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
60183+ if (grsec_enable_socket_server &&
60184+ in_group_p(grsec_socket_server_gid) &&
60185+ sck && (sck->sa_family != AF_UNIX) &&
60186+ (sck->sa_family != AF_LOCAL)) {
60187+ gr_log_noargs(GR_DONT_AUDIT, GR_BIND_MSG);
60188+ return -EACCES;
60189+ }
60190+#endif
60191+ return 0;
60192+}
60193+
60194+int
60195+gr_handle_sock_server_other(const struct sock *sck)
60196+{
60197+#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
60198+ if (grsec_enable_socket_server &&
60199+ in_group_p(grsec_socket_server_gid) &&
60200+ sck && (sck->sk_family != AF_UNIX) &&
60201+ (sck->sk_family != AF_LOCAL)) {
60202+ gr_log_noargs(GR_DONT_AUDIT, GR_BIND_MSG);
60203+ return -EACCES;
60204+ }
60205+#endif
60206+ return 0;
60207+}
60208+
60209+int
60210+gr_handle_sock_client(const struct sockaddr *sck)
60211+{
60212+#ifdef CONFIG_GRKERNSEC_SOCKET_CLIENT
60213+ if (grsec_enable_socket_client && in_group_p(grsec_socket_client_gid) &&
60214+ sck && (sck->sa_family != AF_UNIX) &&
60215+ (sck->sa_family != AF_LOCAL)) {
60216+ gr_log_noargs(GR_DONT_AUDIT, GR_CONNECT_MSG);
60217+ return -EACCES;
60218+ }
60219+#endif
60220+ return 0;
60221+}
60222diff --git a/grsecurity/grsec_sysctl.c b/grsecurity/grsec_sysctl.c
60223new file mode 100644
60224index 0000000..f55ef0f
60225--- /dev/null
60226+++ b/grsecurity/grsec_sysctl.c
60227@@ -0,0 +1,469 @@
60228+#include <linux/kernel.h>
60229+#include <linux/sched.h>
60230+#include <linux/sysctl.h>
60231+#include <linux/grsecurity.h>
60232+#include <linux/grinternal.h>
60233+
60234+int
60235+gr_handle_sysctl_mod(const char *dirname, const char *name, const int op)
60236+{
60237+#ifdef CONFIG_GRKERNSEC_SYSCTL
60238+ if (dirname == NULL || name == NULL)
60239+ return 0;
60240+ if (!strcmp(dirname, "grsecurity") && grsec_lock && (op & MAY_WRITE)) {
60241+ gr_log_str(GR_DONT_AUDIT, GR_SYSCTL_MSG, name);
60242+ return -EACCES;
60243+ }
60244+#endif
60245+ return 0;
60246+}
60247+
60248+#ifdef CONFIG_GRKERNSEC_ROFS
60249+static int __maybe_unused one = 1;
60250+#endif
60251+
60252+#if defined(CONFIG_GRKERNSEC_SYSCTL) || defined(CONFIG_GRKERNSEC_ROFS)
60253+struct ctl_table grsecurity_table[] = {
60254+#ifdef CONFIG_GRKERNSEC_SYSCTL
60255+#ifdef CONFIG_GRKERNSEC_SYSCTL_DISTRO
60256+#ifdef CONFIG_GRKERNSEC_IO
60257+ {
60258+ .procname = "disable_priv_io",
60259+ .data = &grsec_disable_privio,
60260+ .maxlen = sizeof(int),
60261+ .mode = 0600,
60262+ .proc_handler = &proc_dointvec,
60263+ },
60264+#endif
60265+#endif
60266+#ifdef CONFIG_GRKERNSEC_LINK
60267+ {
60268+ .procname = "linking_restrictions",
60269+ .data = &grsec_enable_link,
60270+ .maxlen = sizeof(int),
60271+ .mode = 0600,
60272+ .proc_handler = &proc_dointvec,
60273+ },
60274+#endif
60275+#ifdef CONFIG_GRKERNSEC_SYMLINKOWN
60276+ {
60277+ .procname = "enforce_symlinksifowner",
60278+ .data = &grsec_enable_symlinkown,
60279+ .maxlen = sizeof(int),
60280+ .mode = 0600,
60281+ .proc_handler = &proc_dointvec,
60282+ },
60283+ {
60284+ .procname = "symlinkown_gid",
60285+ .data = &grsec_symlinkown_gid,
60286+ .maxlen = sizeof(int),
60287+ .mode = 0600,
60288+ .proc_handler = &proc_dointvec,
60289+ },
60290+#endif
60291+#ifdef CONFIG_GRKERNSEC_BRUTE
60292+ {
60293+ .procname = "deter_bruteforce",
60294+ .data = &grsec_enable_brute,
60295+ .maxlen = sizeof(int),
60296+ .mode = 0600,
60297+ .proc_handler = &proc_dointvec,
60298+ },
60299+#endif
60300+#ifdef CONFIG_GRKERNSEC_FIFO
60301+ {
60302+ .procname = "fifo_restrictions",
60303+ .data = &grsec_enable_fifo,
60304+ .maxlen = sizeof(int),
60305+ .mode = 0600,
60306+ .proc_handler = &proc_dointvec,
60307+ },
60308+#endif
60309+#ifdef CONFIG_GRKERNSEC_PTRACE_READEXEC
60310+ {
60311+ .procname = "ptrace_readexec",
60312+ .data = &grsec_enable_ptrace_readexec,
60313+ .maxlen = sizeof(int),
60314+ .mode = 0600,
60315+ .proc_handler = &proc_dointvec,
60316+ },
60317+#endif
60318+#ifdef CONFIG_GRKERNSEC_SETXID
60319+ {
60320+ .procname = "consistent_setxid",
60321+ .data = &grsec_enable_setxid,
60322+ .maxlen = sizeof(int),
60323+ .mode = 0600,
60324+ .proc_handler = &proc_dointvec,
60325+ },
60326+#endif
60327+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
60328+ {
60329+ .procname = "ip_blackhole",
60330+ .data = &grsec_enable_blackhole,
60331+ .maxlen = sizeof(int),
60332+ .mode = 0600,
60333+ .proc_handler = &proc_dointvec,
60334+ },
60335+ {
60336+ .procname = "lastack_retries",
60337+ .data = &grsec_lastack_retries,
60338+ .maxlen = sizeof(int),
60339+ .mode = 0600,
60340+ .proc_handler = &proc_dointvec,
60341+ },
60342+#endif
60343+#ifdef CONFIG_GRKERNSEC_EXECLOG
60344+ {
60345+ .procname = "exec_logging",
60346+ .data = &grsec_enable_execlog,
60347+ .maxlen = sizeof(int),
60348+ .mode = 0600,
60349+ .proc_handler = &proc_dointvec,
60350+ },
60351+#endif
60352+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
60353+ {
60354+ .procname = "rwxmap_logging",
60355+ .data = &grsec_enable_log_rwxmaps,
60356+ .maxlen = sizeof(int),
60357+ .mode = 0600,
60358+ .proc_handler = &proc_dointvec,
60359+ },
60360+#endif
60361+#ifdef CONFIG_GRKERNSEC_SIGNAL
60362+ {
60363+ .procname = "signal_logging",
60364+ .data = &grsec_enable_signal,
60365+ .maxlen = sizeof(int),
60366+ .mode = 0600,
60367+ .proc_handler = &proc_dointvec,
60368+ },
60369+#endif
60370+#ifdef CONFIG_GRKERNSEC_FORKFAIL
60371+ {
60372+ .procname = "forkfail_logging",
60373+ .data = &grsec_enable_forkfail,
60374+ .maxlen = sizeof(int),
60375+ .mode = 0600,
60376+ .proc_handler = &proc_dointvec,
60377+ },
60378+#endif
60379+#ifdef CONFIG_GRKERNSEC_TIME
60380+ {
60381+ .procname = "timechange_logging",
60382+ .data = &grsec_enable_time,
60383+ .maxlen = sizeof(int),
60384+ .mode = 0600,
60385+ .proc_handler = &proc_dointvec,
60386+ },
60387+#endif
60388+#ifdef CONFIG_GRKERNSEC_CHROOT_SHMAT
60389+ {
60390+ .procname = "chroot_deny_shmat",
60391+ .data = &grsec_enable_chroot_shmat,
60392+ .maxlen = sizeof(int),
60393+ .mode = 0600,
60394+ .proc_handler = &proc_dointvec,
60395+ },
60396+#endif
60397+#ifdef CONFIG_GRKERNSEC_CHROOT_UNIX
60398+ {
60399+ .procname = "chroot_deny_unix",
60400+ .data = &grsec_enable_chroot_unix,
60401+ .maxlen = sizeof(int),
60402+ .mode = 0600,
60403+ .proc_handler = &proc_dointvec,
60404+ },
60405+#endif
60406+#ifdef CONFIG_GRKERNSEC_CHROOT_MOUNT
60407+ {
60408+ .procname = "chroot_deny_mount",
60409+ .data = &grsec_enable_chroot_mount,
60410+ .maxlen = sizeof(int),
60411+ .mode = 0600,
60412+ .proc_handler = &proc_dointvec,
60413+ },
60414+#endif
60415+#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
60416+ {
60417+ .procname = "chroot_deny_fchdir",
60418+ .data = &grsec_enable_chroot_fchdir,
60419+ .maxlen = sizeof(int),
60420+ .mode = 0600,
60421+ .proc_handler = &proc_dointvec,
60422+ },
60423+#endif
60424+#ifdef CONFIG_GRKERNSEC_CHROOT_DOUBLE
60425+ {
60426+ .procname = "chroot_deny_chroot",
60427+ .data = &grsec_enable_chroot_double,
60428+ .maxlen = sizeof(int),
60429+ .mode = 0600,
60430+ .proc_handler = &proc_dointvec,
60431+ },
60432+#endif
60433+#ifdef CONFIG_GRKERNSEC_CHROOT_PIVOT
60434+ {
60435+ .procname = "chroot_deny_pivot",
60436+ .data = &grsec_enable_chroot_pivot,
60437+ .maxlen = sizeof(int),
60438+ .mode = 0600,
60439+ .proc_handler = &proc_dointvec,
60440+ },
60441+#endif
60442+#ifdef CONFIG_GRKERNSEC_CHROOT_CHDIR
60443+ {
60444+ .procname = "chroot_enforce_chdir",
60445+ .data = &grsec_enable_chroot_chdir,
60446+ .maxlen = sizeof(int),
60447+ .mode = 0600,
60448+ .proc_handler = &proc_dointvec,
60449+ },
60450+#endif
60451+#ifdef CONFIG_GRKERNSEC_CHROOT_CHMOD
60452+ {
60453+ .procname = "chroot_deny_chmod",
60454+ .data = &grsec_enable_chroot_chmod,
60455+ .maxlen = sizeof(int),
60456+ .mode = 0600,
60457+ .proc_handler = &proc_dointvec,
60458+ },
60459+#endif
60460+#ifdef CONFIG_GRKERNSEC_CHROOT_MKNOD
60461+ {
60462+ .procname = "chroot_deny_mknod",
60463+ .data = &grsec_enable_chroot_mknod,
60464+ .maxlen = sizeof(int),
60465+ .mode = 0600,
60466+ .proc_handler = &proc_dointvec,
60467+ },
60468+#endif
60469+#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
60470+ {
60471+ .procname = "chroot_restrict_nice",
60472+ .data = &grsec_enable_chroot_nice,
60473+ .maxlen = sizeof(int),
60474+ .mode = 0600,
60475+ .proc_handler = &proc_dointvec,
60476+ },
60477+#endif
60478+#ifdef CONFIG_GRKERNSEC_CHROOT_EXECLOG
60479+ {
60480+ .procname = "chroot_execlog",
60481+ .data = &grsec_enable_chroot_execlog,
60482+ .maxlen = sizeof(int),
60483+ .mode = 0600,
60484+ .proc_handler = &proc_dointvec,
60485+ },
60486+#endif
60487+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
60488+ {
60489+ .procname = "chroot_caps",
60490+ .data = &grsec_enable_chroot_caps,
60491+ .maxlen = sizeof(int),
60492+ .mode = 0600,
60493+ .proc_handler = &proc_dointvec,
60494+ },
60495+#endif
60496+#ifdef CONFIG_GRKERNSEC_CHROOT_SYSCTL
60497+ {
60498+ .procname = "chroot_deny_sysctl",
60499+ .data = &grsec_enable_chroot_sysctl,
60500+ .maxlen = sizeof(int),
60501+ .mode = 0600,
60502+ .proc_handler = &proc_dointvec,
60503+ },
60504+#endif
60505+#ifdef CONFIG_GRKERNSEC_TPE
60506+ {
60507+ .procname = "tpe",
60508+ .data = &grsec_enable_tpe,
60509+ .maxlen = sizeof(int),
60510+ .mode = 0600,
60511+ .proc_handler = &proc_dointvec,
60512+ },
60513+ {
60514+ .procname = "tpe_gid",
60515+ .data = &grsec_tpe_gid,
60516+ .maxlen = sizeof(int),
60517+ .mode = 0600,
60518+ .proc_handler = &proc_dointvec,
60519+ },
60520+#endif
60521+#ifdef CONFIG_GRKERNSEC_TPE_INVERT
60522+ {
60523+ .procname = "tpe_invert",
60524+ .data = &grsec_enable_tpe_invert,
60525+ .maxlen = sizeof(int),
60526+ .mode = 0600,
60527+ .proc_handler = &proc_dointvec,
60528+ },
60529+#endif
60530+#ifdef CONFIG_GRKERNSEC_TPE_ALL
60531+ {
60532+ .procname = "tpe_restrict_all",
60533+ .data = &grsec_enable_tpe_all,
60534+ .maxlen = sizeof(int),
60535+ .mode = 0600,
60536+ .proc_handler = &proc_dointvec,
60537+ },
60538+#endif
60539+#ifdef CONFIG_GRKERNSEC_SOCKET_ALL
60540+ {
60541+ .procname = "socket_all",
60542+ .data = &grsec_enable_socket_all,
60543+ .maxlen = sizeof(int),
60544+ .mode = 0600,
60545+ .proc_handler = &proc_dointvec,
60546+ },
60547+ {
60548+ .procname = "socket_all_gid",
60549+ .data = &grsec_socket_all_gid,
60550+ .maxlen = sizeof(int),
60551+ .mode = 0600,
60552+ .proc_handler = &proc_dointvec,
60553+ },
60554+#endif
60555+#ifdef CONFIG_GRKERNSEC_SOCKET_CLIENT
60556+ {
60557+ .procname = "socket_client",
60558+ .data = &grsec_enable_socket_client,
60559+ .maxlen = sizeof(int),
60560+ .mode = 0600,
60561+ .proc_handler = &proc_dointvec,
60562+ },
60563+ {
60564+ .procname = "socket_client_gid",
60565+ .data = &grsec_socket_client_gid,
60566+ .maxlen = sizeof(int),
60567+ .mode = 0600,
60568+ .proc_handler = &proc_dointvec,
60569+ },
60570+#endif
60571+#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
60572+ {
60573+ .procname = "socket_server",
60574+ .data = &grsec_enable_socket_server,
60575+ .maxlen = sizeof(int),
60576+ .mode = 0600,
60577+ .proc_handler = &proc_dointvec,
60578+ },
60579+ {
60580+ .procname = "socket_server_gid",
60581+ .data = &grsec_socket_server_gid,
60582+ .maxlen = sizeof(int),
60583+ .mode = 0600,
60584+ .proc_handler = &proc_dointvec,
60585+ },
60586+#endif
60587+#ifdef CONFIG_GRKERNSEC_AUDIT_GROUP
60588+ {
60589+ .procname = "audit_group",
60590+ .data = &grsec_enable_group,
60591+ .maxlen = sizeof(int),
60592+ .mode = 0600,
60593+ .proc_handler = &proc_dointvec,
60594+ },
60595+ {
60596+ .procname = "audit_gid",
60597+ .data = &grsec_audit_gid,
60598+ .maxlen = sizeof(int),
60599+ .mode = 0600,
60600+ .proc_handler = &proc_dointvec,
60601+ },
60602+#endif
60603+#ifdef CONFIG_GRKERNSEC_AUDIT_CHDIR
60604+ {
60605+ .procname = "audit_chdir",
60606+ .data = &grsec_enable_chdir,
60607+ .maxlen = sizeof(int),
60608+ .mode = 0600,
60609+ .proc_handler = &proc_dointvec,
60610+ },
60611+#endif
60612+#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
60613+ {
60614+ .procname = "audit_mount",
60615+ .data = &grsec_enable_mount,
60616+ .maxlen = sizeof(int),
60617+ .mode = 0600,
60618+ .proc_handler = &proc_dointvec,
60619+ },
60620+#endif
60621+#ifdef CONFIG_GRKERNSEC_AUDIT_TEXTREL
60622+ {
60623+ .procname = "audit_textrel",
60624+ .data = &grsec_enable_audit_textrel,
60625+ .maxlen = sizeof(int),
60626+ .mode = 0600,
60627+ .proc_handler = &proc_dointvec,
60628+ },
60629+#endif
60630+#ifdef CONFIG_GRKERNSEC_DMESG
60631+ {
60632+ .procname = "dmesg",
60633+ .data = &grsec_enable_dmesg,
60634+ .maxlen = sizeof(int),
60635+ .mode = 0600,
60636+ .proc_handler = &proc_dointvec,
60637+ },
60638+#endif
60639+#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
60640+ {
60641+ .procname = "chroot_findtask",
60642+ .data = &grsec_enable_chroot_findtask,
60643+ .maxlen = sizeof(int),
60644+ .mode = 0600,
60645+ .proc_handler = &proc_dointvec,
60646+ },
60647+#endif
60648+#ifdef CONFIG_GRKERNSEC_RESLOG
60649+ {
60650+ .procname = "resource_logging",
60651+ .data = &grsec_resource_logging,
60652+ .maxlen = sizeof(int),
60653+ .mode = 0600,
60654+ .proc_handler = &proc_dointvec,
60655+ },
60656+#endif
60657+#ifdef CONFIG_GRKERNSEC_AUDIT_PTRACE
60658+ {
60659+ .procname = "audit_ptrace",
60660+ .data = &grsec_enable_audit_ptrace,
60661+ .maxlen = sizeof(int),
60662+ .mode = 0600,
60663+ .proc_handler = &proc_dointvec,
60664+ },
60665+#endif
60666+#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
60667+ {
60668+ .procname = "harden_ptrace",
60669+ .data = &grsec_enable_harden_ptrace,
60670+ .maxlen = sizeof(int),
60671+ .mode = 0600,
60672+ .proc_handler = &proc_dointvec,
60673+ },
60674+#endif
60675+ {
60676+ .procname = "grsec_lock",
60677+ .data = &grsec_lock,
60678+ .maxlen = sizeof(int),
60679+ .mode = 0600,
60680+ .proc_handler = &proc_dointvec,
60681+ },
60682+#endif
60683+#ifdef CONFIG_GRKERNSEC_ROFS
60684+ {
60685+ .procname = "romount_protect",
60686+ .data = &grsec_enable_rofs,
60687+ .maxlen = sizeof(int),
60688+ .mode = 0600,
60689+ .proc_handler = &proc_dointvec_minmax,
60690+ .extra1 = &one,
60691+ .extra2 = &one,
60692+ },
60693+#endif
60694+ { }
60695+};
60696+#endif
60697diff --git a/grsecurity/grsec_time.c b/grsecurity/grsec_time.c
60698new file mode 100644
60699index 0000000..0dc13c3
60700--- /dev/null
60701+++ b/grsecurity/grsec_time.c
60702@@ -0,0 +1,16 @@
60703+#include <linux/kernel.h>
60704+#include <linux/sched.h>
60705+#include <linux/grinternal.h>
60706+#include <linux/module.h>
60707+
60708+void
60709+gr_log_timechange(void)
60710+{
60711+#ifdef CONFIG_GRKERNSEC_TIME
60712+ if (grsec_enable_time)
60713+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_TIME_MSG);
60714+#endif
60715+ return;
60716+}
60717+
60718+EXPORT_SYMBOL(gr_log_timechange);
60719diff --git a/grsecurity/grsec_tpe.c b/grsecurity/grsec_tpe.c
60720new file mode 100644
60721index 0000000..07e0dc0
60722--- /dev/null
60723+++ b/grsecurity/grsec_tpe.c
60724@@ -0,0 +1,73 @@
60725+#include <linux/kernel.h>
60726+#include <linux/sched.h>
60727+#include <linux/file.h>
60728+#include <linux/fs.h>
60729+#include <linux/grinternal.h>
60730+
60731+extern int gr_acl_tpe_check(void);
60732+
60733+int
60734+gr_tpe_allow(const struct file *file)
60735+{
60736+#ifdef CONFIG_GRKERNSEC
60737+ struct inode *inode = file->f_path.dentry->d_parent->d_inode;
60738+ const struct cred *cred = current_cred();
60739+ char *msg = NULL;
60740+ char *msg2 = NULL;
60741+
60742+ // never restrict root
60743+ if (!cred->uid)
60744+ return 1;
60745+
60746+ if (grsec_enable_tpe) {
60747+#ifdef CONFIG_GRKERNSEC_TPE_INVERT
60748+ if (grsec_enable_tpe_invert && !in_group_p(grsec_tpe_gid))
60749+ msg = "not being in trusted group";
60750+ else if (!grsec_enable_tpe_invert && in_group_p(grsec_tpe_gid))
60751+ msg = "being in untrusted group";
60752+#else
60753+ if (in_group_p(grsec_tpe_gid))
60754+ msg = "being in untrusted group";
60755+#endif
60756+ }
60757+ if (!msg && gr_acl_tpe_check())
60758+ msg = "being in untrusted role";
60759+
60760+ // not in any affected group/role
60761+ if (!msg)
60762+ goto next_check;
60763+
60764+ if (inode->i_uid)
60765+ msg2 = "file in non-root-owned directory";
60766+ else if (inode->i_mode & S_IWOTH)
60767+ msg2 = "file in world-writable directory";
60768+ else if (inode->i_mode & S_IWGRP)
60769+ msg2 = "file in group-writable directory";
60770+
60771+ if (msg && msg2) {
60772+ char fullmsg[70] = {0};
60773+ snprintf(fullmsg, sizeof(fullmsg)-1, "%s and %s", msg, msg2);
60774+ gr_log_str_fs(GR_DONT_AUDIT, GR_EXEC_TPE_MSG, fullmsg, file->f_path.dentry, file->f_path.mnt);
60775+ return 0;
60776+ }
60777+ msg = NULL;
60778+next_check:
60779+#ifdef CONFIG_GRKERNSEC_TPE_ALL
60780+ if (!grsec_enable_tpe || !grsec_enable_tpe_all)
60781+ return 1;
60782+
60783+ if (inode->i_uid && (inode->i_uid != cred->uid))
60784+ msg = "directory not owned by user";
60785+ else if (inode->i_mode & S_IWOTH)
60786+ msg = "file in world-writable directory";
60787+ else if (inode->i_mode & S_IWGRP)
60788+ msg = "file in group-writable directory";
60789+
60790+ if (msg) {
60791+ gr_log_str_fs(GR_DONT_AUDIT, GR_EXEC_TPE_MSG, msg, file->f_path.dentry, file->f_path.mnt);
60792+ return 0;
60793+ }
60794+#endif
60795+#endif
60796+ return 1;
60797+}
60798diff --git a/grsecurity/grsum.c b/grsecurity/grsum.c
60799new file mode 100644
60800index 0000000..9f7b1ac
60801--- /dev/null
60802+++ b/grsecurity/grsum.c
60803@@ -0,0 +1,61 @@
60804+#include <linux/err.h>
60805+#include <linux/kernel.h>
60806+#include <linux/sched.h>
60807+#include <linux/mm.h>
60808+#include <linux/scatterlist.h>
60809+#include <linux/crypto.h>
60810+#include <linux/gracl.h>
60811+
60812+
60813+#if !defined(CONFIG_CRYPTO) || defined(CONFIG_CRYPTO_MODULE) || !defined(CONFIG_CRYPTO_SHA256) || defined(CONFIG_CRYPTO_SHA256_MODULE)
60814+#error "crypto and sha256 must be built into the kernel"
60815+#endif
60816+
60817+int
60818+chkpw(struct gr_arg *entry, unsigned char *salt, unsigned char *sum)
60819+{
60820+ char *p;
60821+ struct crypto_hash *tfm;
60822+ struct hash_desc desc;
60823+ struct scatterlist sg;
60824+ unsigned char temp_sum[GR_SHA_LEN];
60825+ volatile int retval = 0;
60826+ volatile int dummy = 0;
60827+ unsigned int i;
60828+
60829+ sg_init_table(&sg, 1);
60830+
60831+ tfm = crypto_alloc_hash("sha256", 0, CRYPTO_ALG_ASYNC);
60832+ if (IS_ERR(tfm)) {
60833+ /* should never happen, since sha256 should be built in */
60834+ return 1;
60835+ }
60836+
60837+ desc.tfm = tfm;
60838+ desc.flags = 0;
60839+
60840+ crypto_hash_init(&desc);
60841+
60842+ p = salt;
60843+ sg_set_buf(&sg, p, GR_SALT_LEN);
60844+ crypto_hash_update(&desc, &sg, sg.length);
60845+
60846+ p = entry->pw;
60847+ sg_set_buf(&sg, p, strlen(p));
60848+
60849+ crypto_hash_update(&desc, &sg, sg.length);
60850+
60851+ crypto_hash_final(&desc, temp_sum);
60852+
60853+ memset(entry->pw, 0, GR_PW_LEN);
60854+
60855+ for (i = 0; i < GR_SHA_LEN; i++)
60856+ if (sum[i] != temp_sum[i])
60857+ retval = 1;
60858+ else
60859+ dummy = 1; // waste a cycle
60860+
60861+ crypto_free_hash(tfm);
60862+
60863+ return retval;
60864+}
60865diff --git a/include/acpi/acpi_bus.h b/include/acpi/acpi_bus.h
60866index bde976e..a1cc32a 100644
60867--- a/include/acpi/acpi_bus.h
60868+++ b/include/acpi/acpi_bus.h
60869@@ -136,7 +136,7 @@ struct acpi_device_ops {
60870 acpi_op_bind bind;
60871 acpi_op_unbind unbind;
60872 acpi_op_notify notify;
60873-};
60874+} __no_const;
60875
60876 #define ACPI_DRIVER_ALL_NOTIFY_EVENTS 0x1 /* system AND device events */
60877
60878diff --git a/include/asm-generic/4level-fixup.h b/include/asm-generic/4level-fixup.h
60879index 77ff547..181834f 100644
60880--- a/include/asm-generic/4level-fixup.h
60881+++ b/include/asm-generic/4level-fixup.h
60882@@ -13,8 +13,10 @@
60883 #define pmd_alloc(mm, pud, address) \
60884 ((unlikely(pgd_none(*(pud))) && __pmd_alloc(mm, pud, address))? \
60885 NULL: pmd_offset(pud, address))
60886+#define pmd_alloc_kernel(mm, pud, address) pmd_alloc((mm), (pud), (address))
60887
60888 #define pud_alloc(mm, pgd, address) (pgd)
60889+#define pud_alloc_kernel(mm, pgd, address) pud_alloc((mm), (pgd), (address))
60890 #define pud_offset(pgd, start) (pgd)
60891 #define pud_none(pud) 0
60892 #define pud_bad(pud) 0
60893diff --git a/include/asm-generic/atomic-long.h b/include/asm-generic/atomic-long.h
60894index b7babf0..3ba8aee 100644
60895--- a/include/asm-generic/atomic-long.h
60896+++ b/include/asm-generic/atomic-long.h
60897@@ -22,6 +22,12 @@
60898
60899 typedef atomic64_t atomic_long_t;
60900
60901+#ifdef CONFIG_PAX_REFCOUNT
60902+typedef atomic64_unchecked_t atomic_long_unchecked_t;
60903+#else
60904+typedef atomic64_t atomic_long_unchecked_t;
60905+#endif
60906+
60907 #define ATOMIC_LONG_INIT(i) ATOMIC64_INIT(i)
60908
60909 static inline long atomic_long_read(atomic_long_t *l)
60910@@ -31,6 +37,15 @@ static inline long atomic_long_read(atomic_long_t *l)
60911 return (long)atomic64_read(v);
60912 }
60913
60914+#ifdef CONFIG_PAX_REFCOUNT
60915+static inline long atomic_long_read_unchecked(atomic_long_unchecked_t *l)
60916+{
60917+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
60918+
60919+ return (long)atomic64_read_unchecked(v);
60920+}
60921+#endif
60922+
60923 static inline void atomic_long_set(atomic_long_t *l, long i)
60924 {
60925 atomic64_t *v = (atomic64_t *)l;
60926@@ -38,6 +53,15 @@ static inline void atomic_long_set(atomic_long_t *l, long i)
60927 atomic64_set(v, i);
60928 }
60929
60930+#ifdef CONFIG_PAX_REFCOUNT
60931+static inline void atomic_long_set_unchecked(atomic_long_unchecked_t *l, long i)
60932+{
60933+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
60934+
60935+ atomic64_set_unchecked(v, i);
60936+}
60937+#endif
60938+
60939 static inline void atomic_long_inc(atomic_long_t *l)
60940 {
60941 atomic64_t *v = (atomic64_t *)l;
60942@@ -45,6 +69,15 @@ static inline void atomic_long_inc(atomic_long_t *l)
60943 atomic64_inc(v);
60944 }
60945
60946+#ifdef CONFIG_PAX_REFCOUNT
60947+static inline void atomic_long_inc_unchecked(atomic_long_unchecked_t *l)
60948+{
60949+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
60950+
60951+ atomic64_inc_unchecked(v);
60952+}
60953+#endif
60954+
60955 static inline void atomic_long_dec(atomic_long_t *l)
60956 {
60957 atomic64_t *v = (atomic64_t *)l;
60958@@ -52,6 +85,15 @@ static inline void atomic_long_dec(atomic_long_t *l)
60959 atomic64_dec(v);
60960 }
60961
60962+#ifdef CONFIG_PAX_REFCOUNT
60963+static inline void atomic_long_dec_unchecked(atomic_long_unchecked_t *l)
60964+{
60965+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
60966+
60967+ atomic64_dec_unchecked(v);
60968+}
60969+#endif
60970+
60971 static inline void atomic_long_add(long i, atomic_long_t *l)
60972 {
60973 atomic64_t *v = (atomic64_t *)l;
60974@@ -59,6 +101,15 @@ static inline void atomic_long_add(long i, atomic_long_t *l)
60975 atomic64_add(i, v);
60976 }
60977
60978+#ifdef CONFIG_PAX_REFCOUNT
60979+static inline void atomic_long_add_unchecked(long i, atomic_long_unchecked_t *l)
60980+{
60981+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
60982+
60983+ atomic64_add_unchecked(i, v);
60984+}
60985+#endif
60986+
60987 static inline void atomic_long_sub(long i, atomic_long_t *l)
60988 {
60989 atomic64_t *v = (atomic64_t *)l;
60990@@ -66,6 +117,15 @@ static inline void atomic_long_sub(long i, atomic_long_t *l)
60991 atomic64_sub(i, v);
60992 }
60993
60994+#ifdef CONFIG_PAX_REFCOUNT
60995+static inline void atomic_long_sub_unchecked(long i, atomic_long_unchecked_t *l)
60996+{
60997+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
60998+
60999+ atomic64_sub_unchecked(i, v);
61000+}
61001+#endif
61002+
61003 static inline int atomic_long_sub_and_test(long i, atomic_long_t *l)
61004 {
61005 atomic64_t *v = (atomic64_t *)l;
61006@@ -115,6 +175,15 @@ static inline long atomic_long_inc_return(atomic_long_t *l)
61007 return (long)atomic64_inc_return(v);
61008 }
61009
61010+#ifdef CONFIG_PAX_REFCOUNT
61011+static inline long atomic_long_inc_return_unchecked(atomic_long_unchecked_t *l)
61012+{
61013+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
61014+
61015+ return (long)atomic64_inc_return_unchecked(v);
61016+}
61017+#endif
61018+
61019 static inline long atomic_long_dec_return(atomic_long_t *l)
61020 {
61021 atomic64_t *v = (atomic64_t *)l;
61022@@ -140,6 +209,12 @@ static inline long atomic_long_add_unless(atomic_long_t *l, long a, long u)
61023
61024 typedef atomic_t atomic_long_t;
61025
61026+#ifdef CONFIG_PAX_REFCOUNT
61027+typedef atomic_unchecked_t atomic_long_unchecked_t;
61028+#else
61029+typedef atomic_t atomic_long_unchecked_t;
61030+#endif
61031+
61032 #define ATOMIC_LONG_INIT(i) ATOMIC_INIT(i)
61033 static inline long atomic_long_read(atomic_long_t *l)
61034 {
61035@@ -148,6 +223,15 @@ static inline long atomic_long_read(atomic_long_t *l)
61036 return (long)atomic_read(v);
61037 }
61038
61039+#ifdef CONFIG_PAX_REFCOUNT
61040+static inline long atomic_long_read_unchecked(atomic_long_unchecked_t *l)
61041+{
61042+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
61043+
61044+ return (long)atomic_read_unchecked(v);
61045+}
61046+#endif
61047+
61048 static inline void atomic_long_set(atomic_long_t *l, long i)
61049 {
61050 atomic_t *v = (atomic_t *)l;
61051@@ -155,6 +239,15 @@ static inline void atomic_long_set(atomic_long_t *l, long i)
61052 atomic_set(v, i);
61053 }
61054
61055+#ifdef CONFIG_PAX_REFCOUNT
61056+static inline void atomic_long_set_unchecked(atomic_long_unchecked_t *l, long i)
61057+{
61058+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
61059+
61060+ atomic_set_unchecked(v, i);
61061+}
61062+#endif
61063+
61064 static inline void atomic_long_inc(atomic_long_t *l)
61065 {
61066 atomic_t *v = (atomic_t *)l;
61067@@ -162,6 +255,15 @@ static inline void atomic_long_inc(atomic_long_t *l)
61068 atomic_inc(v);
61069 }
61070
61071+#ifdef CONFIG_PAX_REFCOUNT
61072+static inline void atomic_long_inc_unchecked(atomic_long_unchecked_t *l)
61073+{
61074+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
61075+
61076+ atomic_inc_unchecked(v);
61077+}
61078+#endif
61079+
61080 static inline void atomic_long_dec(atomic_long_t *l)
61081 {
61082 atomic_t *v = (atomic_t *)l;
61083@@ -169,6 +271,15 @@ static inline void atomic_long_dec(atomic_long_t *l)
61084 atomic_dec(v);
61085 }
61086
61087+#ifdef CONFIG_PAX_REFCOUNT
61088+static inline void atomic_long_dec_unchecked(atomic_long_unchecked_t *l)
61089+{
61090+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
61091+
61092+ atomic_dec_unchecked(v);
61093+}
61094+#endif
61095+
61096 static inline void atomic_long_add(long i, atomic_long_t *l)
61097 {
61098 atomic_t *v = (atomic_t *)l;
61099@@ -176,6 +287,15 @@ static inline void atomic_long_add(long i, atomic_long_t *l)
61100 atomic_add(i, v);
61101 }
61102
61103+#ifdef CONFIG_PAX_REFCOUNT
61104+static inline void atomic_long_add_unchecked(long i, atomic_long_unchecked_t *l)
61105+{
61106+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
61107+
61108+ atomic_add_unchecked(i, v);
61109+}
61110+#endif
61111+
61112 static inline void atomic_long_sub(long i, atomic_long_t *l)
61113 {
61114 atomic_t *v = (atomic_t *)l;
61115@@ -183,6 +303,15 @@ static inline void atomic_long_sub(long i, atomic_long_t *l)
61116 atomic_sub(i, v);
61117 }
61118
61119+#ifdef CONFIG_PAX_REFCOUNT
61120+static inline void atomic_long_sub_unchecked(long i, atomic_long_unchecked_t *l)
61121+{
61122+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
61123+
61124+ atomic_sub_unchecked(i, v);
61125+}
61126+#endif
61127+
61128 static inline int atomic_long_sub_and_test(long i, atomic_long_t *l)
61129 {
61130 atomic_t *v = (atomic_t *)l;
61131@@ -232,6 +361,15 @@ static inline long atomic_long_inc_return(atomic_long_t *l)
61132 return (long)atomic_inc_return(v);
61133 }
61134
61135+#ifdef CONFIG_PAX_REFCOUNT
61136+static inline long atomic_long_inc_return_unchecked(atomic_long_unchecked_t *l)
61137+{
61138+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
61139+
61140+ return (long)atomic_inc_return_unchecked(v);
61141+}
61142+#endif
61143+
61144 static inline long atomic_long_dec_return(atomic_long_t *l)
61145 {
61146 atomic_t *v = (atomic_t *)l;
61147@@ -255,4 +393,55 @@ static inline long atomic_long_add_unless(atomic_long_t *l, long a, long u)
61148
61149 #endif /* BITS_PER_LONG == 64 */
61150
61151+#ifdef CONFIG_PAX_REFCOUNT
61152+static inline void pax_refcount_needs_these_functions(void)
61153+{
61154+ atomic_read_unchecked((atomic_unchecked_t *)NULL);
61155+ atomic_set_unchecked((atomic_unchecked_t *)NULL, 0);
61156+ atomic_add_unchecked(0, (atomic_unchecked_t *)NULL);
61157+ atomic_sub_unchecked(0, (atomic_unchecked_t *)NULL);
61158+ atomic_inc_unchecked((atomic_unchecked_t *)NULL);
61159+ (void)atomic_inc_and_test_unchecked((atomic_unchecked_t *)NULL);
61160+ atomic_inc_return_unchecked((atomic_unchecked_t *)NULL);
61161+ atomic_add_return_unchecked(0, (atomic_unchecked_t *)NULL);
61162+ atomic_dec_unchecked((atomic_unchecked_t *)NULL);
61163+ atomic_cmpxchg_unchecked((atomic_unchecked_t *)NULL, 0, 0);
61164+ (void)atomic_xchg_unchecked((atomic_unchecked_t *)NULL, 0);
61165+#ifdef CONFIG_X86
61166+ atomic_clear_mask_unchecked(0, NULL);
61167+ atomic_set_mask_unchecked(0, NULL);
61168+#endif
61169+
61170+ atomic_long_read_unchecked((atomic_long_unchecked_t *)NULL);
61171+ atomic_long_set_unchecked((atomic_long_unchecked_t *)NULL, 0);
61172+ atomic_long_add_unchecked(0, (atomic_long_unchecked_t *)NULL);
61173+ atomic_long_sub_unchecked(0, (atomic_long_unchecked_t *)NULL);
61174+ atomic_long_inc_unchecked((atomic_long_unchecked_t *)NULL);
61175+ atomic_long_inc_return_unchecked((atomic_long_unchecked_t *)NULL);
61176+ atomic_long_dec_unchecked((atomic_long_unchecked_t *)NULL);
61177+}
61178+#else
61179+#define atomic_read_unchecked(v) atomic_read(v)
61180+#define atomic_set_unchecked(v, i) atomic_set((v), (i))
61181+#define atomic_add_unchecked(i, v) atomic_add((i), (v))
61182+#define atomic_sub_unchecked(i, v) atomic_sub((i), (v))
61183+#define atomic_inc_unchecked(v) atomic_inc(v)
61184+#define atomic_inc_and_test_unchecked(v) atomic_inc_and_test(v)
61185+#define atomic_inc_return_unchecked(v) atomic_inc_return(v)
61186+#define atomic_add_return_unchecked(i, v) atomic_add_return((i), (v))
61187+#define atomic_dec_unchecked(v) atomic_dec(v)
61188+#define atomic_cmpxchg_unchecked(v, o, n) atomic_cmpxchg((v), (o), (n))
61189+#define atomic_xchg_unchecked(v, i) atomic_xchg((v), (i))
61190+#define atomic_clear_mask_unchecked(mask, v) atomic_clear_mask((mask), (v))
61191+#define atomic_set_mask_unchecked(mask, v) atomic_set_mask((mask), (v))
61192+
61193+#define atomic_long_read_unchecked(v) atomic_long_read(v)
61194+#define atomic_long_set_unchecked(v, i) atomic_long_set((v), (i))
61195+#define atomic_long_add_unchecked(i, v) atomic_long_add((i), (v))
61196+#define atomic_long_sub_unchecked(i, v) atomic_long_sub((i), (v))
61197+#define atomic_long_inc_unchecked(v) atomic_long_inc(v)
61198+#define atomic_long_inc_return_unchecked(v) atomic_long_inc_return(v)
61199+#define atomic_long_dec_unchecked(v) atomic_long_dec(v)
61200+#endif
61201+
61202 #endif /* _ASM_GENERIC_ATOMIC_LONG_H */
61203diff --git a/include/asm-generic/atomic.h b/include/asm-generic/atomic.h
61204index 1ced641..c896ee8 100644
61205--- a/include/asm-generic/atomic.h
61206+++ b/include/asm-generic/atomic.h
61207@@ -159,7 +159,7 @@ static inline int __atomic_add_unless(atomic_t *v, int a, int u)
61208 * Atomically clears the bits set in @mask from @v
61209 */
61210 #ifndef atomic_clear_mask
61211-static inline void atomic_clear_mask(unsigned long mask, atomic_t *v)
61212+static inline void atomic_clear_mask(unsigned int mask, atomic_t *v)
61213 {
61214 unsigned long flags;
61215
61216diff --git a/include/asm-generic/atomic64.h b/include/asm-generic/atomic64.h
61217index b18ce4f..2ee2843 100644
61218--- a/include/asm-generic/atomic64.h
61219+++ b/include/asm-generic/atomic64.h
61220@@ -16,6 +16,8 @@ typedef struct {
61221 long long counter;
61222 } atomic64_t;
61223
61224+typedef atomic64_t atomic64_unchecked_t;
61225+
61226 #define ATOMIC64_INIT(i) { (i) }
61227
61228 extern long long atomic64_read(const atomic64_t *v);
61229@@ -39,4 +41,14 @@ extern int atomic64_add_unless(atomic64_t *v, long long a, long long u);
61230 #define atomic64_dec_and_test(v) (atomic64_dec_return((v)) == 0)
61231 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1LL, 0LL)
61232
61233+#define atomic64_read_unchecked(v) atomic64_read(v)
61234+#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
61235+#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
61236+#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
61237+#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
61238+#define atomic64_inc_unchecked(v) atomic64_inc(v)
61239+#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
61240+#define atomic64_dec_unchecked(v) atomic64_dec(v)
61241+#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
61242+
61243 #endif /* _ASM_GENERIC_ATOMIC64_H */
61244diff --git a/include/asm-generic/cache.h b/include/asm-generic/cache.h
61245index 1bfcfe5..e04c5c9 100644
61246--- a/include/asm-generic/cache.h
61247+++ b/include/asm-generic/cache.h
61248@@ -6,7 +6,7 @@
61249 * cache lines need to provide their own cache.h.
61250 */
61251
61252-#define L1_CACHE_SHIFT 5
61253-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
61254+#define L1_CACHE_SHIFT 5UL
61255+#define L1_CACHE_BYTES (1UL << L1_CACHE_SHIFT)
61256
61257 #endif /* __ASM_GENERIC_CACHE_H */
61258diff --git a/include/asm-generic/emergency-restart.h b/include/asm-generic/emergency-restart.h
61259index 0d68a1e..b74a761 100644
61260--- a/include/asm-generic/emergency-restart.h
61261+++ b/include/asm-generic/emergency-restart.h
61262@@ -1,7 +1,7 @@
61263 #ifndef _ASM_GENERIC_EMERGENCY_RESTART_H
61264 #define _ASM_GENERIC_EMERGENCY_RESTART_H
61265
61266-static inline void machine_emergency_restart(void)
61267+static inline __noreturn void machine_emergency_restart(void)
61268 {
61269 machine_restart(NULL);
61270 }
61271diff --git a/include/asm-generic/kmap_types.h b/include/asm-generic/kmap_types.h
61272index 90f99c7..00ce236 100644
61273--- a/include/asm-generic/kmap_types.h
61274+++ b/include/asm-generic/kmap_types.h
61275@@ -2,9 +2,9 @@
61276 #define _ASM_GENERIC_KMAP_TYPES_H
61277
61278 #ifdef __WITH_KM_FENCE
61279-# define KM_TYPE_NR 41
61280+# define KM_TYPE_NR 42
61281 #else
61282-# define KM_TYPE_NR 20
61283+# define KM_TYPE_NR 21
61284 #endif
61285
61286 #endif
61287diff --git a/include/asm-generic/local.h b/include/asm-generic/local.h
61288index 9ceb03b..2efbcbd 100644
61289--- a/include/asm-generic/local.h
61290+++ b/include/asm-generic/local.h
61291@@ -39,6 +39,7 @@ typedef struct
61292 #define local_add_return(i, l) atomic_long_add_return((i), (&(l)->a))
61293 #define local_sub_return(i, l) atomic_long_sub_return((i), (&(l)->a))
61294 #define local_inc_return(l) atomic_long_inc_return(&(l)->a)
61295+#define local_dec_return(l) atomic_long_dec_return(&(l)->a)
61296
61297 #define local_cmpxchg(l, o, n) atomic_long_cmpxchg((&(l)->a), (o), (n))
61298 #define local_xchg(l, n) atomic_long_xchg((&(l)->a), (n))
61299diff --git a/include/asm-generic/pgtable-nopmd.h b/include/asm-generic/pgtable-nopmd.h
61300index 725612b..9cc513a 100644
61301--- a/include/asm-generic/pgtable-nopmd.h
61302+++ b/include/asm-generic/pgtable-nopmd.h
61303@@ -1,14 +1,19 @@
61304 #ifndef _PGTABLE_NOPMD_H
61305 #define _PGTABLE_NOPMD_H
61306
61307-#ifndef __ASSEMBLY__
61308-
61309 #include <asm-generic/pgtable-nopud.h>
61310
61311-struct mm_struct;
61312-
61313 #define __PAGETABLE_PMD_FOLDED
61314
61315+#define PMD_SHIFT PUD_SHIFT
61316+#define PTRS_PER_PMD 1
61317+#define PMD_SIZE (_AC(1,UL) << PMD_SHIFT)
61318+#define PMD_MASK (~(PMD_SIZE-1))
61319+
61320+#ifndef __ASSEMBLY__
61321+
61322+struct mm_struct;
61323+
61324 /*
61325 * Having the pmd type consist of a pud gets the size right, and allows
61326 * us to conceptually access the pud entry that this pmd is folded into
61327@@ -16,11 +21,6 @@ struct mm_struct;
61328 */
61329 typedef struct { pud_t pud; } pmd_t;
61330
61331-#define PMD_SHIFT PUD_SHIFT
61332-#define PTRS_PER_PMD 1
61333-#define PMD_SIZE (1UL << PMD_SHIFT)
61334-#define PMD_MASK (~(PMD_SIZE-1))
61335-
61336 /*
61337 * The "pud_xxx()" functions here are trivial for a folded two-level
61338 * setup: the pmd is never bad, and a pmd always exists (as it's folded
61339diff --git a/include/asm-generic/pgtable-nopud.h b/include/asm-generic/pgtable-nopud.h
61340index 810431d..0ec4804f 100644
61341--- a/include/asm-generic/pgtable-nopud.h
61342+++ b/include/asm-generic/pgtable-nopud.h
61343@@ -1,10 +1,15 @@
61344 #ifndef _PGTABLE_NOPUD_H
61345 #define _PGTABLE_NOPUD_H
61346
61347-#ifndef __ASSEMBLY__
61348-
61349 #define __PAGETABLE_PUD_FOLDED
61350
61351+#define PUD_SHIFT PGDIR_SHIFT
61352+#define PTRS_PER_PUD 1
61353+#define PUD_SIZE (_AC(1,UL) << PUD_SHIFT)
61354+#define PUD_MASK (~(PUD_SIZE-1))
61355+
61356+#ifndef __ASSEMBLY__
61357+
61358 /*
61359 * Having the pud type consist of a pgd gets the size right, and allows
61360 * us to conceptually access the pgd entry that this pud is folded into
61361@@ -12,11 +17,6 @@
61362 */
61363 typedef struct { pgd_t pgd; } pud_t;
61364
61365-#define PUD_SHIFT PGDIR_SHIFT
61366-#define PTRS_PER_PUD 1
61367-#define PUD_SIZE (1UL << PUD_SHIFT)
61368-#define PUD_MASK (~(PUD_SIZE-1))
61369-
61370 /*
61371 * The "pgd_xxx()" functions here are trivial for a folded two-level
61372 * setup: the pud is never bad, and a pud always exists (as it's folded
61373@@ -29,6 +29,7 @@ static inline void pgd_clear(pgd_t *pgd) { }
61374 #define pud_ERROR(pud) (pgd_ERROR((pud).pgd))
61375
61376 #define pgd_populate(mm, pgd, pud) do { } while (0)
61377+#define pgd_populate_kernel(mm, pgd, pud) do { } while (0)
61378 /*
61379 * (puds are folded into pgds so this doesn't get actually called,
61380 * but the define is needed for a generic inline function.)
61381diff --git a/include/asm-generic/pgtable.h b/include/asm-generic/pgtable.h
61382index ff4947b..f48183f 100644
61383--- a/include/asm-generic/pgtable.h
61384+++ b/include/asm-generic/pgtable.h
61385@@ -530,6 +530,14 @@ static inline int pmd_trans_unstable(pmd_t *pmd)
61386 #endif
61387 }
61388
61389+#ifndef __HAVE_ARCH_PAX_OPEN_KERNEL
61390+static inline unsigned long pax_open_kernel(void) { return 0; }
61391+#endif
61392+
61393+#ifndef __HAVE_ARCH_PAX_CLOSE_KERNEL
61394+static inline unsigned long pax_close_kernel(void) { return 0; }
61395+#endif
61396+
61397 #endif /* CONFIG_MMU */
61398
61399 #endif /* !__ASSEMBLY__ */
61400diff --git a/include/asm-generic/vmlinux.lds.h b/include/asm-generic/vmlinux.lds.h
61401index 4e2e1cc..12c266b 100644
61402--- a/include/asm-generic/vmlinux.lds.h
61403+++ b/include/asm-generic/vmlinux.lds.h
61404@@ -218,6 +218,7 @@
61405 .rodata : AT(ADDR(.rodata) - LOAD_OFFSET) { \
61406 VMLINUX_SYMBOL(__start_rodata) = .; \
61407 *(.rodata) *(.rodata.*) \
61408+ *(.data..read_only) \
61409 *(__vermagic) /* Kernel version magic */ \
61410 . = ALIGN(8); \
61411 VMLINUX_SYMBOL(__start___tracepoints_ptrs) = .; \
61412@@ -716,17 +717,18 @@
61413 * section in the linker script will go there too. @phdr should have
61414 * a leading colon.
61415 *
61416- * Note that this macros defines __per_cpu_load as an absolute symbol.
61417+ * Note that this macros defines per_cpu_load as an absolute symbol.
61418 * If there is no need to put the percpu section at a predetermined
61419 * address, use PERCPU_SECTION.
61420 */
61421 #define PERCPU_VADDR(cacheline, vaddr, phdr) \
61422- VMLINUX_SYMBOL(__per_cpu_load) = .; \
61423- .data..percpu vaddr : AT(VMLINUX_SYMBOL(__per_cpu_load) \
61424+ per_cpu_load = .; \
61425+ .data..percpu vaddr : AT(VMLINUX_SYMBOL(per_cpu_load) \
61426 - LOAD_OFFSET) { \
61427+ VMLINUX_SYMBOL(__per_cpu_load) = . + per_cpu_load; \
61428 PERCPU_INPUT(cacheline) \
61429 } phdr \
61430- . = VMLINUX_SYMBOL(__per_cpu_load) + SIZEOF(.data..percpu);
61431+ . = VMLINUX_SYMBOL(per_cpu_load) + SIZEOF(.data..percpu);
61432
61433 /**
61434 * PERCPU_SECTION - define output section for percpu area, simple version
61435diff --git a/include/drm/drmP.h b/include/drm/drmP.h
61436index d6b67bb..a272c29 100644
61437--- a/include/drm/drmP.h
61438+++ b/include/drm/drmP.h
61439@@ -72,6 +72,7 @@
61440 #include <linux/workqueue.h>
61441 #include <linux/poll.h>
61442 #include <asm/pgalloc.h>
61443+#include <asm/local.h>
61444 #include "drm.h"
61445
61446 #include <linux/idr.h>
61447@@ -1067,7 +1068,7 @@ struct drm_device {
61448
61449 /** \name Usage Counters */
61450 /*@{ */
61451- int open_count; /**< Outstanding files open */
61452+ local_t open_count; /**< Outstanding files open */
61453 atomic_t ioctl_count; /**< Outstanding IOCTLs pending */
61454 atomic_t vma_count; /**< Outstanding vma areas open */
61455 int buf_use; /**< Buffers in use -- cannot alloc */
61456@@ -1078,7 +1079,7 @@ struct drm_device {
61457 /*@{ */
61458 unsigned long counters;
61459 enum drm_stat_type types[15];
61460- atomic_t counts[15];
61461+ atomic_unchecked_t counts[15];
61462 /*@} */
61463
61464 struct list_head filelist;
61465diff --git a/include/drm/drm_crtc_helper.h b/include/drm/drm_crtc_helper.h
61466index e01cc80..319855d 100644
61467--- a/include/drm/drm_crtc_helper.h
61468+++ b/include/drm/drm_crtc_helper.h
61469@@ -81,7 +81,7 @@ struct drm_crtc_helper_funcs {
61470
61471 /* disable crtc when not in use - more explicit than dpms off */
61472 void (*disable)(struct drm_crtc *crtc);
61473-};
61474+} __no_const;
61475
61476 /**
61477 * drm_encoder_helper_funcs - helper operations for encoders
61478@@ -109,7 +109,7 @@ struct drm_encoder_helper_funcs {
61479 struct drm_connector *connector);
61480 /* disable encoder when not in use - more explicit than dpms off */
61481 void (*disable)(struct drm_encoder *encoder);
61482-};
61483+} __no_const;
61484
61485 /**
61486 * drm_connector_helper_funcs - helper operations for connectors
61487diff --git a/include/drm/ttm/ttm_memory.h b/include/drm/ttm/ttm_memory.h
61488index d6d1da4..fdd1ac5 100644
61489--- a/include/drm/ttm/ttm_memory.h
61490+++ b/include/drm/ttm/ttm_memory.h
61491@@ -48,7 +48,7 @@
61492
61493 struct ttm_mem_shrink {
61494 int (*do_shrink) (struct ttm_mem_shrink *);
61495-};
61496+} __no_const;
61497
61498 /**
61499 * struct ttm_mem_global - Global memory accounting structure.
61500diff --git a/include/linux/a.out.h b/include/linux/a.out.h
61501index e86dfca..40cc55f 100644
61502--- a/include/linux/a.out.h
61503+++ b/include/linux/a.out.h
61504@@ -39,6 +39,14 @@ enum machine_type {
61505 M_MIPS2 = 152 /* MIPS R6000/R4000 binary */
61506 };
61507
61508+/* Constants for the N_FLAGS field */
61509+#define F_PAX_PAGEEXEC 1 /* Paging based non-executable pages */
61510+#define F_PAX_EMUTRAMP 2 /* Emulate trampolines */
61511+#define F_PAX_MPROTECT 4 /* Restrict mprotect() */
61512+#define F_PAX_RANDMMAP 8 /* Randomize mmap() base */
61513+/*#define F_PAX_RANDEXEC 16*/ /* Randomize ET_EXEC base */
61514+#define F_PAX_SEGMEXEC 32 /* Segmentation based non-executable pages */
61515+
61516 #if !defined (N_MAGIC)
61517 #define N_MAGIC(exec) ((exec).a_info & 0xffff)
61518 #endif
61519diff --git a/include/linux/atmdev.h b/include/linux/atmdev.h
61520index 06fd4bb..1caec0d 100644
61521--- a/include/linux/atmdev.h
61522+++ b/include/linux/atmdev.h
61523@@ -237,7 +237,7 @@ struct compat_atm_iobuf {
61524 #endif
61525
61526 struct k_atm_aal_stats {
61527-#define __HANDLE_ITEM(i) atomic_t i
61528+#define __HANDLE_ITEM(i) atomic_unchecked_t i
61529 __AAL_STAT_ITEMS
61530 #undef __HANDLE_ITEM
61531 };
61532diff --git a/include/linux/binfmts.h b/include/linux/binfmts.h
61533index 366422b..1fa7f84 100644
61534--- a/include/linux/binfmts.h
61535+++ b/include/linux/binfmts.h
61536@@ -89,6 +89,7 @@ struct linux_binfmt {
61537 int (*load_binary)(struct linux_binprm *, struct pt_regs * regs);
61538 int (*load_shlib)(struct file *);
61539 int (*core_dump)(struct coredump_params *cprm);
61540+ void (*handle_mprotect)(struct vm_area_struct *vma, unsigned long newflags);
61541 unsigned long min_coredump; /* minimal dump size */
61542 };
61543
61544diff --git a/include/linux/blkdev.h b/include/linux/blkdev.h
61545index 4a2ab7c..a2de7a8 100644
61546--- a/include/linux/blkdev.h
61547+++ b/include/linux/blkdev.h
61548@@ -1420,7 +1420,7 @@ struct block_device_operations {
61549 /* this callback is with swap_lock and sometimes page table lock held */
61550 void (*swap_slot_free_notify) (struct block_device *, unsigned long);
61551 struct module *owner;
61552-};
61553+} __do_const;
61554
61555 extern int __blkdev_driver_ioctl(struct block_device *, fmode_t, unsigned int,
61556 unsigned long);
61557diff --git a/include/linux/blktrace_api.h b/include/linux/blktrace_api.h
61558index 4d1a074..88f929a 100644
61559--- a/include/linux/blktrace_api.h
61560+++ b/include/linux/blktrace_api.h
61561@@ -162,7 +162,7 @@ struct blk_trace {
61562 struct dentry *dir;
61563 struct dentry *dropped_file;
61564 struct dentry *msg_file;
61565- atomic_t dropped;
61566+ atomic_unchecked_t dropped;
61567 };
61568
61569 extern int blk_trace_ioctl(struct block_device *, unsigned, char __user *);
61570diff --git a/include/linux/byteorder/little_endian.h b/include/linux/byteorder/little_endian.h
61571index 83195fb..0b0f77d 100644
61572--- a/include/linux/byteorder/little_endian.h
61573+++ b/include/linux/byteorder/little_endian.h
61574@@ -42,51 +42,51 @@
61575
61576 static inline __le64 __cpu_to_le64p(const __u64 *p)
61577 {
61578- return (__force __le64)*p;
61579+ return (__force const __le64)*p;
61580 }
61581 static inline __u64 __le64_to_cpup(const __le64 *p)
61582 {
61583- return (__force __u64)*p;
61584+ return (__force const __u64)*p;
61585 }
61586 static inline __le32 __cpu_to_le32p(const __u32 *p)
61587 {
61588- return (__force __le32)*p;
61589+ return (__force const __le32)*p;
61590 }
61591 static inline __u32 __le32_to_cpup(const __le32 *p)
61592 {
61593- return (__force __u32)*p;
61594+ return (__force const __u32)*p;
61595 }
61596 static inline __le16 __cpu_to_le16p(const __u16 *p)
61597 {
61598- return (__force __le16)*p;
61599+ return (__force const __le16)*p;
61600 }
61601 static inline __u16 __le16_to_cpup(const __le16 *p)
61602 {
61603- return (__force __u16)*p;
61604+ return (__force const __u16)*p;
61605 }
61606 static inline __be64 __cpu_to_be64p(const __u64 *p)
61607 {
61608- return (__force __be64)__swab64p(p);
61609+ return (__force const __be64)__swab64p(p);
61610 }
61611 static inline __u64 __be64_to_cpup(const __be64 *p)
61612 {
61613- return __swab64p((__u64 *)p);
61614+ return __swab64p((const __u64 *)p);
61615 }
61616 static inline __be32 __cpu_to_be32p(const __u32 *p)
61617 {
61618- return (__force __be32)__swab32p(p);
61619+ return (__force const __be32)__swab32p(p);
61620 }
61621 static inline __u32 __be32_to_cpup(const __be32 *p)
61622 {
61623- return __swab32p((__u32 *)p);
61624+ return __swab32p((const __u32 *)p);
61625 }
61626 static inline __be16 __cpu_to_be16p(const __u16 *p)
61627 {
61628- return (__force __be16)__swab16p(p);
61629+ return (__force const __be16)__swab16p(p);
61630 }
61631 static inline __u16 __be16_to_cpup(const __be16 *p)
61632 {
61633- return __swab16p((__u16 *)p);
61634+ return __swab16p((const __u16 *)p);
61635 }
61636 #define __cpu_to_le64s(x) do { (void)(x); } while (0)
61637 #define __le64_to_cpus(x) do { (void)(x); } while (0)
61638diff --git a/include/linux/cache.h b/include/linux/cache.h
61639index 4c57065..4307975 100644
61640--- a/include/linux/cache.h
61641+++ b/include/linux/cache.h
61642@@ -16,6 +16,10 @@
61643 #define __read_mostly
61644 #endif
61645
61646+#ifndef __read_only
61647+#define __read_only __read_mostly
61648+#endif
61649+
61650 #ifndef ____cacheline_aligned
61651 #define ____cacheline_aligned __attribute__((__aligned__(SMP_CACHE_BYTES)))
61652 #endif
61653diff --git a/include/linux/capability.h b/include/linux/capability.h
61654index d10b7ed..0288b79 100644
61655--- a/include/linux/capability.h
61656+++ b/include/linux/capability.h
61657@@ -553,10 +553,15 @@ extern bool capable(int cap);
61658 extern bool ns_capable(struct user_namespace *ns, int cap);
61659 extern bool nsown_capable(int cap);
61660 extern bool inode_capable(const struct inode *inode, int cap);
61661+extern bool capable_nolog(int cap);
61662+extern bool ns_capable_nolog(struct user_namespace *ns, int cap);
61663+extern bool inode_capable_nolog(const struct inode *inode, int cap);
61664
61665 /* audit system wants to get cap info from files as well */
61666 extern int get_vfs_caps_from_disk(const struct dentry *dentry, struct cpu_vfs_cap_data *cpu_caps);
61667
61668+extern int is_privileged_binary(const struct dentry *dentry);
61669+
61670 #endif /* __KERNEL__ */
61671
61672 #endif /* !_LINUX_CAPABILITY_H */
61673diff --git a/include/linux/cleancache.h b/include/linux/cleancache.h
61674index 42e55de..1cd0e66 100644
61675--- a/include/linux/cleancache.h
61676+++ b/include/linux/cleancache.h
61677@@ -31,7 +31,7 @@ struct cleancache_ops {
61678 void (*invalidate_page)(int, struct cleancache_filekey, pgoff_t);
61679 void (*invalidate_inode)(int, struct cleancache_filekey);
61680 void (*invalidate_fs)(int);
61681-};
61682+} __no_const;
61683
61684 extern struct cleancache_ops
61685 cleancache_register_ops(struct cleancache_ops *ops);
61686diff --git a/include/linux/clk-provider.h b/include/linux/clk-provider.h
61687index 77335fa..6cbe7dd 100644
61688--- a/include/linux/clk-provider.h
61689+++ b/include/linux/clk-provider.h
61690@@ -111,6 +111,7 @@ struct clk_ops {
61691 unsigned long);
61692 void (*init)(struct clk_hw *hw);
61693 };
61694+typedef struct clk_ops __no_const clk_ops_no_const;
61695
61696 /**
61697 * struct clk_init_data - holds init data that's common to all clocks and is
61698diff --git a/include/linux/compiler-gcc4.h b/include/linux/compiler-gcc4.h
61699index 934bc34..1b47129 100644
61700--- a/include/linux/compiler-gcc4.h
61701+++ b/include/linux/compiler-gcc4.h
61702@@ -32,6 +32,21 @@
61703 #define __linktime_error(message) __attribute__((__error__(message)))
61704
61705 #if __GNUC_MINOR__ >= 5
61706+
61707+#ifdef CONSTIFY_PLUGIN
61708+#define __no_const __attribute__((no_const))
61709+#define __do_const __attribute__((do_const))
61710+#endif
61711+
61712+#ifdef SIZE_OVERFLOW_PLUGIN
61713+#define __size_overflow(...) __attribute__((size_overflow(__VA_ARGS__)))
61714+#define __intentional_overflow(...) __attribute__((intentional_overflow(__VA_ARGS__)))
61715+#endif
61716+
61717+#ifdef LATENT_ENTROPY_PLUGIN
61718+#define __latent_entropy __attribute__((latent_entropy))
61719+#endif
61720+
61721 /*
61722 * Mark a position in code as unreachable. This can be used to
61723 * suppress control flow warnings after asm blocks that transfer
61724@@ -47,6 +62,11 @@
61725 #define __noclone __attribute__((__noclone__))
61726
61727 #endif
61728+
61729+#define __alloc_size(...) __attribute((alloc_size(__VA_ARGS__)))
61730+#define __bos(ptr, arg) __builtin_object_size((ptr), (arg))
61731+#define __bos0(ptr) __bos((ptr), 0)
61732+#define __bos1(ptr) __bos((ptr), 1)
61733 #endif
61734
61735 #if __GNUC_MINOR__ >= 6
61736diff --git a/include/linux/compiler.h b/include/linux/compiler.h
61737index f430e41..38be90f 100644
61738--- a/include/linux/compiler.h
61739+++ b/include/linux/compiler.h
61740@@ -5,31 +5,62 @@
61741
61742 #ifdef __CHECKER__
61743 # define __user __attribute__((noderef, address_space(1)))
61744+# define __force_user __force __user
61745 # define __kernel __attribute__((address_space(0)))
61746+# define __force_kernel __force __kernel
61747 # define __safe __attribute__((safe))
61748 # define __force __attribute__((force))
61749 # define __nocast __attribute__((nocast))
61750 # define __iomem __attribute__((noderef, address_space(2)))
61751+# define __force_iomem __force __iomem
61752 # define __acquires(x) __attribute__((context(x,0,1)))
61753 # define __releases(x) __attribute__((context(x,1,0)))
61754 # define __acquire(x) __context__(x,1)
61755 # define __release(x) __context__(x,-1)
61756 # define __cond_lock(x,c) ((c) ? ({ __acquire(x); 1; }) : 0)
61757 # define __percpu __attribute__((noderef, address_space(3)))
61758+# define __force_percpu __force __percpu
61759 #ifdef CONFIG_SPARSE_RCU_POINTER
61760 # define __rcu __attribute__((noderef, address_space(4)))
61761+# define __force_rcu __force __rcu
61762 #else
61763 # define __rcu
61764+# define __force_rcu
61765 #endif
61766 extern void __chk_user_ptr(const volatile void __user *);
61767 extern void __chk_io_ptr(const volatile void __iomem *);
61768+#elif defined(CHECKER_PLUGIN)
61769+//# define __user
61770+//# define __force_user
61771+//# define __kernel
61772+//# define __force_kernel
61773+# define __safe
61774+# define __force
61775+# define __nocast
61776+# define __iomem
61777+# define __force_iomem
61778+# define __chk_user_ptr(x) (void)0
61779+# define __chk_io_ptr(x) (void)0
61780+# define __builtin_warning(x, y...) (1)
61781+# define __acquires(x)
61782+# define __releases(x)
61783+# define __acquire(x) (void)0
61784+# define __release(x) (void)0
61785+# define __cond_lock(x,c) (c)
61786+# define __percpu
61787+# define __force_percpu
61788+# define __rcu
61789+# define __force_rcu
61790 #else
61791 # define __user
61792+# define __force_user
61793 # define __kernel
61794+# define __force_kernel
61795 # define __safe
61796 # define __force
61797 # define __nocast
61798 # define __iomem
61799+# define __force_iomem
61800 # define __chk_user_ptr(x) (void)0
61801 # define __chk_io_ptr(x) (void)0
61802 # define __builtin_warning(x, y...) (1)
61803@@ -39,7 +70,9 @@ extern void __chk_io_ptr(const volatile void __iomem *);
61804 # define __release(x) (void)0
61805 # define __cond_lock(x,c) (c)
61806 # define __percpu
61807+# define __force_percpu
61808 # define __rcu
61809+# define __force_rcu
61810 #endif
61811
61812 #ifdef __KERNEL__
61813@@ -264,6 +297,26 @@ void ftrace_likely_update(struct ftrace_branch_data *f, int val, int expect);
61814 # define __attribute_const__ /* unimplemented */
61815 #endif
61816
61817+#ifndef __no_const
61818+# define __no_const
61819+#endif
61820+
61821+#ifndef __do_const
61822+# define __do_const
61823+#endif
61824+
61825+#ifndef __size_overflow
61826+# define __size_overflow(...)
61827+#endif
61828+
61829+#ifndef __intentional_overflow
61830+# define __intentional_overflow(...)
61831+#endif
61832+
61833+#ifndef __latent_entropy
61834+# define __latent_entropy
61835+#endif
61836+
61837 /*
61838 * Tell gcc if a function is cold. The compiler will assume any path
61839 * directly leading to the call is unlikely.
61840@@ -273,6 +326,22 @@ void ftrace_likely_update(struct ftrace_branch_data *f, int val, int expect);
61841 #define __cold
61842 #endif
61843
61844+#ifndef __alloc_size
61845+#define __alloc_size(...)
61846+#endif
61847+
61848+#ifndef __bos
61849+#define __bos(ptr, arg)
61850+#endif
61851+
61852+#ifndef __bos0
61853+#define __bos0(ptr)
61854+#endif
61855+
61856+#ifndef __bos1
61857+#define __bos1(ptr)
61858+#endif
61859+
61860 /* Simple shorthand for a section definition */
61861 #ifndef __section
61862 # define __section(S) __attribute__ ((__section__(#S)))
61863@@ -312,6 +381,7 @@ void ftrace_likely_update(struct ftrace_branch_data *f, int val, int expect);
61864 * use is to mediate communication between process-level code and irq/NMI
61865 * handlers, all running on the same CPU.
61866 */
61867-#define ACCESS_ONCE(x) (*(volatile typeof(x) *)&(x))
61868+#define ACCESS_ONCE(x) (*(volatile const typeof(x) *)&(x))
61869+#define ACCESS_ONCE_RW(x) (*(volatile typeof(x) *)&(x))
61870
61871 #endif /* __LINUX_COMPILER_H */
61872diff --git a/include/linux/cred.h b/include/linux/cred.h
61873index ebbed2c..908cc2c 100644
61874--- a/include/linux/cred.h
61875+++ b/include/linux/cred.h
61876@@ -208,6 +208,9 @@ static inline void validate_creds_for_do_exit(struct task_struct *tsk)
61877 static inline void validate_process_creds(void)
61878 {
61879 }
61880+static inline void validate_task_creds(struct task_struct *task)
61881+{
61882+}
61883 #endif
61884
61885 /**
61886diff --git a/include/linux/crypto.h b/include/linux/crypto.h
61887index b92eadf..b4ecdc1 100644
61888--- a/include/linux/crypto.h
61889+++ b/include/linux/crypto.h
61890@@ -373,7 +373,7 @@ struct cipher_tfm {
61891 const u8 *key, unsigned int keylen);
61892 void (*cit_encrypt_one)(struct crypto_tfm *tfm, u8 *dst, const u8 *src);
61893 void (*cit_decrypt_one)(struct crypto_tfm *tfm, u8 *dst, const u8 *src);
61894-};
61895+} __no_const;
61896
61897 struct hash_tfm {
61898 int (*init)(struct hash_desc *desc);
61899@@ -394,13 +394,13 @@ struct compress_tfm {
61900 int (*cot_decompress)(struct crypto_tfm *tfm,
61901 const u8 *src, unsigned int slen,
61902 u8 *dst, unsigned int *dlen);
61903-};
61904+} __no_const;
61905
61906 struct rng_tfm {
61907 int (*rng_gen_random)(struct crypto_rng *tfm, u8 *rdata,
61908 unsigned int dlen);
61909 int (*rng_reset)(struct crypto_rng *tfm, u8 *seed, unsigned int slen);
61910-};
61911+} __no_const;
61912
61913 #define crt_ablkcipher crt_u.ablkcipher
61914 #define crt_aead crt_u.aead
61915diff --git a/include/linux/decompress/mm.h b/include/linux/decompress/mm.h
61916index 7925bf0..d5143d2 100644
61917--- a/include/linux/decompress/mm.h
61918+++ b/include/linux/decompress/mm.h
61919@@ -77,7 +77,7 @@ static void free(void *where)
61920 * warnings when not needed (indeed large_malloc / large_free are not
61921 * needed by inflate */
61922
61923-#define malloc(a) kmalloc(a, GFP_KERNEL)
61924+#define malloc(a) kmalloc((a), GFP_KERNEL)
61925 #define free(a) kfree(a)
61926
61927 #define large_malloc(a) vmalloc(a)
61928diff --git a/include/linux/dma-mapping.h b/include/linux/dma-mapping.h
61929index 94af418..b1ca7a2 100644
61930--- a/include/linux/dma-mapping.h
61931+++ b/include/linux/dma-mapping.h
61932@@ -54,7 +54,7 @@ struct dma_map_ops {
61933 u64 (*get_required_mask)(struct device *dev);
61934 #endif
61935 int is_phys;
61936-};
61937+} __do_const;
61938
61939 #define DMA_BIT_MASK(n) (((n) == 64) ? ~0ULL : ((1ULL<<(n))-1))
61940
61941diff --git a/include/linux/dmaengine.h b/include/linux/dmaengine.h
61942index 9c02a45..89fdd73 100644
61943--- a/include/linux/dmaengine.h
61944+++ b/include/linux/dmaengine.h
61945@@ -1017,9 +1017,9 @@ struct dma_pinned_list {
61946 struct dma_pinned_list *dma_pin_iovec_pages(struct iovec *iov, size_t len);
61947 void dma_unpin_iovec_pages(struct dma_pinned_list* pinned_list);
61948
61949-dma_cookie_t dma_memcpy_to_iovec(struct dma_chan *chan, struct iovec *iov,
61950+dma_cookie_t __intentional_overflow(0) dma_memcpy_to_iovec(struct dma_chan *chan, struct iovec *iov,
61951 struct dma_pinned_list *pinned_list, unsigned char *kdata, size_t len);
61952-dma_cookie_t dma_memcpy_pg_to_iovec(struct dma_chan *chan, struct iovec *iov,
61953+dma_cookie_t __intentional_overflow(0) dma_memcpy_pg_to_iovec(struct dma_chan *chan, struct iovec *iov,
61954 struct dma_pinned_list *pinned_list, struct page *page,
61955 unsigned int offset, size_t len);
61956
61957diff --git a/include/linux/efi.h b/include/linux/efi.h
61958index 5782114..e9b1ba1 100644
61959--- a/include/linux/efi.h
61960+++ b/include/linux/efi.h
61961@@ -640,7 +640,7 @@ struct efivar_operations {
61962 efi_get_variable_t *get_variable;
61963 efi_get_next_variable_t *get_next_variable;
61964 efi_set_variable_t *set_variable;
61965-};
61966+} __no_const;
61967
61968 struct efivars {
61969 /*
61970diff --git a/include/linux/elf.h b/include/linux/elf.h
61971index 999b4f5..57753b4 100644
61972--- a/include/linux/elf.h
61973+++ b/include/linux/elf.h
61974@@ -40,6 +40,17 @@ typedef __s64 Elf64_Sxword;
61975 #define PT_GNU_EH_FRAME 0x6474e550
61976
61977 #define PT_GNU_STACK (PT_LOOS + 0x474e551)
61978+#define PT_GNU_RELRO (PT_LOOS + 0x474e552)
61979+
61980+#define PT_PAX_FLAGS (PT_LOOS + 0x5041580)
61981+
61982+/* Constants for the e_flags field */
61983+#define EF_PAX_PAGEEXEC 1 /* Paging based non-executable pages */
61984+#define EF_PAX_EMUTRAMP 2 /* Emulate trampolines */
61985+#define EF_PAX_MPROTECT 4 /* Restrict mprotect() */
61986+#define EF_PAX_RANDMMAP 8 /* Randomize mmap() base */
61987+/*#define EF_PAX_RANDEXEC 16*/ /* Randomize ET_EXEC base */
61988+#define EF_PAX_SEGMEXEC 32 /* Segmentation based non-executable pages */
61989
61990 /*
61991 * Extended Numbering
61992@@ -97,6 +108,8 @@ typedef __s64 Elf64_Sxword;
61993 #define DT_DEBUG 21
61994 #define DT_TEXTREL 22
61995 #define DT_JMPREL 23
61996+#define DT_FLAGS 30
61997+ #define DF_TEXTREL 0x00000004
61998 #define DT_ENCODING 32
61999 #define OLD_DT_LOOS 0x60000000
62000 #define DT_LOOS 0x6000000d
62001@@ -243,6 +256,19 @@ typedef struct elf64_hdr {
62002 #define PF_W 0x2
62003 #define PF_X 0x1
62004
62005+#define PF_PAGEEXEC (1U << 4) /* Enable PAGEEXEC */
62006+#define PF_NOPAGEEXEC (1U << 5) /* Disable PAGEEXEC */
62007+#define PF_SEGMEXEC (1U << 6) /* Enable SEGMEXEC */
62008+#define PF_NOSEGMEXEC (1U << 7) /* Disable SEGMEXEC */
62009+#define PF_MPROTECT (1U << 8) /* Enable MPROTECT */
62010+#define PF_NOMPROTECT (1U << 9) /* Disable MPROTECT */
62011+/*#define PF_RANDEXEC (1U << 10)*/ /* Enable RANDEXEC */
62012+/*#define PF_NORANDEXEC (1U << 11)*/ /* Disable RANDEXEC */
62013+#define PF_EMUTRAMP (1U << 12) /* Enable EMUTRAMP */
62014+#define PF_NOEMUTRAMP (1U << 13) /* Disable EMUTRAMP */
62015+#define PF_RANDMMAP (1U << 14) /* Enable RANDMMAP */
62016+#define PF_NORANDMMAP (1U << 15) /* Disable RANDMMAP */
62017+
62018 typedef struct elf32_phdr{
62019 Elf32_Word p_type;
62020 Elf32_Off p_offset;
62021@@ -335,6 +361,8 @@ typedef struct elf64_shdr {
62022 #define EI_OSABI 7
62023 #define EI_PAD 8
62024
62025+#define EI_PAX 14
62026+
62027 #define ELFMAG0 0x7f /* EI_MAG */
62028 #define ELFMAG1 'E'
62029 #define ELFMAG2 'L'
62030@@ -421,6 +449,7 @@ extern Elf32_Dyn _DYNAMIC [];
62031 #define elf_note elf32_note
62032 #define elf_addr_t Elf32_Off
62033 #define Elf_Half Elf32_Half
62034+#define elf_dyn Elf32_Dyn
62035
62036 #else
62037
62038@@ -431,6 +460,7 @@ extern Elf64_Dyn _DYNAMIC [];
62039 #define elf_note elf64_note
62040 #define elf_addr_t Elf64_Off
62041 #define Elf_Half Elf64_Half
62042+#define elf_dyn Elf64_Dyn
62043
62044 #endif
62045
62046diff --git a/include/linux/filter.h b/include/linux/filter.h
62047index 82b0135..917914d 100644
62048--- a/include/linux/filter.h
62049+++ b/include/linux/filter.h
62050@@ -146,6 +146,7 @@ struct compat_sock_fprog {
62051
62052 struct sk_buff;
62053 struct sock;
62054+struct bpf_jit_work;
62055
62056 struct sk_filter
62057 {
62058@@ -153,6 +154,9 @@ struct sk_filter
62059 unsigned int len; /* Number of filter blocks */
62060 unsigned int (*bpf_func)(const struct sk_buff *skb,
62061 const struct sock_filter *filter);
62062+#ifdef CONFIG_BPF_JIT
62063+ struct bpf_jit_work *work;
62064+#endif
62065 struct rcu_head rcu;
62066 struct sock_filter insns[0];
62067 };
62068diff --git a/include/linux/firewire.h b/include/linux/firewire.h
62069index db04ec5..f6ed627 100644
62070--- a/include/linux/firewire.h
62071+++ b/include/linux/firewire.h
62072@@ -430,7 +430,7 @@ struct fw_iso_context {
62073 union {
62074 fw_iso_callback_t sc;
62075 fw_iso_mc_callback_t mc;
62076- } callback;
62077+ } __no_const callback;
62078 void *callback_data;
62079 };
62080
62081diff --git a/include/linux/frontswap.h b/include/linux/frontswap.h
62082index 0e4e2ee..4ff4312 100644
62083--- a/include/linux/frontswap.h
62084+++ b/include/linux/frontswap.h
62085@@ -11,7 +11,7 @@ struct frontswap_ops {
62086 int (*load)(unsigned, pgoff_t, struct page *);
62087 void (*invalidate_page)(unsigned, pgoff_t);
62088 void (*invalidate_area)(unsigned);
62089-};
62090+} __no_const;
62091
62092 extern bool frontswap_enabled;
62093 extern struct frontswap_ops
62094diff --git a/include/linux/fs.h b/include/linux/fs.h
62095index aa11047..7d046d0 100644
62096--- a/include/linux/fs.h
62097+++ b/include/linux/fs.h
62098@@ -1802,7 +1802,8 @@ struct file_operations {
62099 int (*setlease)(struct file *, long, struct file_lock **);
62100 long (*fallocate)(struct file *file, int mode, loff_t offset,
62101 loff_t len);
62102-};
62103+} __do_const;
62104+typedef struct file_operations __no_const file_operations_no_const;
62105
62106 struct inode_operations {
62107 struct dentry * (*lookup) (struct inode *,struct dentry *, unsigned int);
62108diff --git a/include/linux/fs_struct.h b/include/linux/fs_struct.h
62109index 003dc0f..3c4ea97 100644
62110--- a/include/linux/fs_struct.h
62111+++ b/include/linux/fs_struct.h
62112@@ -6,7 +6,7 @@
62113 #include <linux/seqlock.h>
62114
62115 struct fs_struct {
62116- int users;
62117+ atomic_t users;
62118 spinlock_t lock;
62119 seqcount_t seq;
62120 int umask;
62121diff --git a/include/linux/fscache-cache.h b/include/linux/fscache-cache.h
62122index ce31408..b1ad003 100644
62123--- a/include/linux/fscache-cache.h
62124+++ b/include/linux/fscache-cache.h
62125@@ -102,7 +102,7 @@ struct fscache_operation {
62126 fscache_operation_release_t release;
62127 };
62128
62129-extern atomic_t fscache_op_debug_id;
62130+extern atomic_unchecked_t fscache_op_debug_id;
62131 extern void fscache_op_work_func(struct work_struct *work);
62132
62133 extern void fscache_enqueue_operation(struct fscache_operation *);
62134@@ -122,7 +122,7 @@ static inline void fscache_operation_init(struct fscache_operation *op,
62135 {
62136 INIT_WORK(&op->work, fscache_op_work_func);
62137 atomic_set(&op->usage, 1);
62138- op->debug_id = atomic_inc_return(&fscache_op_debug_id);
62139+ op->debug_id = atomic_inc_return_unchecked(&fscache_op_debug_id);
62140 op->processor = processor;
62141 op->release = release;
62142 INIT_LIST_HEAD(&op->pend_link);
62143diff --git a/include/linux/fsnotify.h b/include/linux/fsnotify.h
62144index a6dfe69..569586df 100644
62145--- a/include/linux/fsnotify.h
62146+++ b/include/linux/fsnotify.h
62147@@ -315,7 +315,7 @@ static inline void fsnotify_change(struct dentry *dentry, unsigned int ia_valid)
62148 */
62149 static inline const unsigned char *fsnotify_oldname_init(const unsigned char *name)
62150 {
62151- return kstrdup(name, GFP_KERNEL);
62152+ return (const unsigned char *)kstrdup((const char *)name, GFP_KERNEL);
62153 }
62154
62155 /*
62156diff --git a/include/linux/fsnotify_backend.h b/include/linux/fsnotify_backend.h
62157index 63d966d..cdcb717 100644
62158--- a/include/linux/fsnotify_backend.h
62159+++ b/include/linux/fsnotify_backend.h
62160@@ -105,6 +105,7 @@ struct fsnotify_ops {
62161 void (*freeing_mark)(struct fsnotify_mark *mark, struct fsnotify_group *group);
62162 void (*free_event_priv)(struct fsnotify_event_private_data *priv);
62163 };
62164+typedef struct fsnotify_ops __no_const fsnotify_ops_no_const;
62165
62166 /*
62167 * A group is a "thing" that wants to receive notification about filesystem
62168diff --git a/include/linux/ftrace_event.h b/include/linux/ftrace_event.h
62169index 642928c..e6c83a7 100644
62170--- a/include/linux/ftrace_event.h
62171+++ b/include/linux/ftrace_event.h
62172@@ -97,7 +97,7 @@ struct trace_event_functions {
62173 trace_print_func raw;
62174 trace_print_func hex;
62175 trace_print_func binary;
62176-};
62177+} __no_const;
62178
62179 struct trace_event {
62180 struct hlist_node node;
62181@@ -266,7 +266,7 @@ extern int trace_define_field(struct ftrace_event_call *call, const char *type,
62182 extern int trace_add_event_call(struct ftrace_event_call *call);
62183 extern void trace_remove_event_call(struct ftrace_event_call *call);
62184
62185-#define is_signed_type(type) (((type)(-1)) < 0)
62186+#define is_signed_type(type) (((type)(-1)) < (type)1)
62187
62188 int trace_set_clr_event(const char *system, const char *event, int set);
62189
62190diff --git a/include/linux/genhd.h b/include/linux/genhd.h
62191index 4f440b3..342233a 100644
62192--- a/include/linux/genhd.h
62193+++ b/include/linux/genhd.h
62194@@ -190,7 +190,7 @@ struct gendisk {
62195 struct kobject *slave_dir;
62196
62197 struct timer_rand_state *random;
62198- atomic_t sync_io; /* RAID */
62199+ atomic_unchecked_t sync_io; /* RAID */
62200 struct disk_events *ev;
62201 #ifdef CONFIG_BLK_DEV_INTEGRITY
62202 struct blk_integrity *integrity;
62203diff --git a/include/linux/gfp.h b/include/linux/gfp.h
62204index 4883f39..26688a8 100644
62205--- a/include/linux/gfp.h
62206+++ b/include/linux/gfp.h
62207@@ -39,6 +39,12 @@ struct vm_area_struct;
62208 #define ___GFP_OTHER_NODE 0x800000u
62209 #define ___GFP_WRITE 0x1000000u
62210
62211+#ifdef CONFIG_PAX_USERCOPY_SLABS
62212+#define ___GFP_USERCOPY 0x2000000u
62213+#else
62214+#define ___GFP_USERCOPY 0
62215+#endif
62216+
62217 /*
62218 * GFP bitmasks..
62219 *
62220@@ -93,6 +99,7 @@ struct vm_area_struct;
62221 #define __GFP_NO_KSWAPD ((__force gfp_t)___GFP_NO_KSWAPD)
62222 #define __GFP_OTHER_NODE ((__force gfp_t)___GFP_OTHER_NODE) /* On behalf of other node */
62223 #define __GFP_WRITE ((__force gfp_t)___GFP_WRITE) /* Allocator intends to dirty page */
62224+#define __GFP_USERCOPY ((__force gfp_t)___GFP_USERCOPY)/* Allocator intends to copy page to/from userland */
62225
62226 /*
62227 * This may seem redundant, but it's a way of annotating false positives vs.
62228@@ -100,7 +107,7 @@ struct vm_area_struct;
62229 */
62230 #define __GFP_NOTRACK_FALSE_POSITIVE (__GFP_NOTRACK)
62231
62232-#define __GFP_BITS_SHIFT 25 /* Room for N __GFP_FOO bits */
62233+#define __GFP_BITS_SHIFT 26 /* Room for N __GFP_FOO bits */
62234 #define __GFP_BITS_MASK ((__force gfp_t)((1 << __GFP_BITS_SHIFT) - 1))
62235
62236 /* This equals 0, but use constants in case they ever change */
62237@@ -154,6 +161,8 @@ struct vm_area_struct;
62238 /* 4GB DMA on some platforms */
62239 #define GFP_DMA32 __GFP_DMA32
62240
62241+#define GFP_USERCOPY __GFP_USERCOPY
62242+
62243 /* Convert GFP flags to their corresponding migrate type */
62244 static inline int allocflags_to_migratetype(gfp_t gfp_flags)
62245 {
62246diff --git a/include/linux/gracl.h b/include/linux/gracl.h
62247new file mode 100644
62248index 0000000..c938b1f
62249--- /dev/null
62250+++ b/include/linux/gracl.h
62251@@ -0,0 +1,319 @@
62252+#ifndef GR_ACL_H
62253+#define GR_ACL_H
62254+
62255+#include <linux/grdefs.h>
62256+#include <linux/resource.h>
62257+#include <linux/capability.h>
62258+#include <linux/dcache.h>
62259+#include <asm/resource.h>
62260+
62261+/* Major status information */
62262+
62263+#define GR_VERSION "grsecurity 2.9.1"
62264+#define GRSECURITY_VERSION 0x2901
62265+
62266+enum {
62267+ GR_SHUTDOWN = 0,
62268+ GR_ENABLE = 1,
62269+ GR_SPROLE = 2,
62270+ GR_RELOAD = 3,
62271+ GR_SEGVMOD = 4,
62272+ GR_STATUS = 5,
62273+ GR_UNSPROLE = 6,
62274+ GR_PASSSET = 7,
62275+ GR_SPROLEPAM = 8,
62276+};
62277+
62278+/* Password setup definitions
62279+ * kernel/grhash.c */
62280+enum {
62281+ GR_PW_LEN = 128,
62282+ GR_SALT_LEN = 16,
62283+ GR_SHA_LEN = 32,
62284+};
62285+
62286+enum {
62287+ GR_SPROLE_LEN = 64,
62288+};
62289+
62290+enum {
62291+ GR_NO_GLOB = 0,
62292+ GR_REG_GLOB,
62293+ GR_CREATE_GLOB
62294+};
62295+
62296+#define GR_NLIMITS 32
62297+
62298+/* Begin Data Structures */
62299+
62300+struct sprole_pw {
62301+ unsigned char *rolename;
62302+ unsigned char salt[GR_SALT_LEN];
62303+ unsigned char sum[GR_SHA_LEN]; /* 256-bit SHA hash of the password */
62304+};
62305+
62306+struct name_entry {
62307+ __u32 key;
62308+ ino_t inode;
62309+ dev_t device;
62310+ char *name;
62311+ __u16 len;
62312+ __u8 deleted;
62313+ struct name_entry *prev;
62314+ struct name_entry *next;
62315+};
62316+
62317+struct inodev_entry {
62318+ struct name_entry *nentry;
62319+ struct inodev_entry *prev;
62320+ struct inodev_entry *next;
62321+};
62322+
62323+struct acl_role_db {
62324+ struct acl_role_label **r_hash;
62325+ __u32 r_size;
62326+};
62327+
62328+struct inodev_db {
62329+ struct inodev_entry **i_hash;
62330+ __u32 i_size;
62331+};
62332+
62333+struct name_db {
62334+ struct name_entry **n_hash;
62335+ __u32 n_size;
62336+};
62337+
62338+struct crash_uid {
62339+ uid_t uid;
62340+ unsigned long expires;
62341+};
62342+
62343+struct gr_hash_struct {
62344+ void **table;
62345+ void **nametable;
62346+ void *first;
62347+ __u32 table_size;
62348+ __u32 used_size;
62349+ int type;
62350+};
62351+
62352+/* Userspace Grsecurity ACL data structures */
62353+
62354+struct acl_subject_label {
62355+ char *filename;
62356+ ino_t inode;
62357+ dev_t device;
62358+ __u32 mode;
62359+ kernel_cap_t cap_mask;
62360+ kernel_cap_t cap_lower;
62361+ kernel_cap_t cap_invert_audit;
62362+
62363+ struct rlimit res[GR_NLIMITS];
62364+ __u32 resmask;
62365+
62366+ __u8 user_trans_type;
62367+ __u8 group_trans_type;
62368+ uid_t *user_transitions;
62369+ gid_t *group_transitions;
62370+ __u16 user_trans_num;
62371+ __u16 group_trans_num;
62372+
62373+ __u32 sock_families[2];
62374+ __u32 ip_proto[8];
62375+ __u32 ip_type;
62376+ struct acl_ip_label **ips;
62377+ __u32 ip_num;
62378+ __u32 inaddr_any_override;
62379+
62380+ __u32 crashes;
62381+ unsigned long expires;
62382+
62383+ struct acl_subject_label *parent_subject;
62384+ struct gr_hash_struct *hash;
62385+ struct acl_subject_label *prev;
62386+ struct acl_subject_label *next;
62387+
62388+ struct acl_object_label **obj_hash;
62389+ __u32 obj_hash_size;
62390+ __u16 pax_flags;
62391+};
62392+
62393+struct role_allowed_ip {
62394+ __u32 addr;
62395+ __u32 netmask;
62396+
62397+ struct role_allowed_ip *prev;
62398+ struct role_allowed_ip *next;
62399+};
62400+
62401+struct role_transition {
62402+ char *rolename;
62403+
62404+ struct role_transition *prev;
62405+ struct role_transition *next;
62406+};
62407+
62408+struct acl_role_label {
62409+ char *rolename;
62410+ uid_t uidgid;
62411+ __u16 roletype;
62412+
62413+ __u16 auth_attempts;
62414+ unsigned long expires;
62415+
62416+ struct acl_subject_label *root_label;
62417+ struct gr_hash_struct *hash;
62418+
62419+ struct acl_role_label *prev;
62420+ struct acl_role_label *next;
62421+
62422+ struct role_transition *transitions;
62423+ struct role_allowed_ip *allowed_ips;
62424+ uid_t *domain_children;
62425+ __u16 domain_child_num;
62426+
62427+ umode_t umask;
62428+
62429+ struct acl_subject_label **subj_hash;
62430+ __u32 subj_hash_size;
62431+};
62432+
62433+struct user_acl_role_db {
62434+ struct acl_role_label **r_table;
62435+ __u32 num_pointers; /* Number of allocations to track */
62436+ __u32 num_roles; /* Number of roles */
62437+ __u32 num_domain_children; /* Number of domain children */
62438+ __u32 num_subjects; /* Number of subjects */
62439+ __u32 num_objects; /* Number of objects */
62440+};
62441+
62442+struct acl_object_label {
62443+ char *filename;
62444+ ino_t inode;
62445+ dev_t device;
62446+ __u32 mode;
62447+
62448+ struct acl_subject_label *nested;
62449+ struct acl_object_label *globbed;
62450+
62451+ /* next two structures not used */
62452+
62453+ struct acl_object_label *prev;
62454+ struct acl_object_label *next;
62455+};
62456+
62457+struct acl_ip_label {
62458+ char *iface;
62459+ __u32 addr;
62460+ __u32 netmask;
62461+ __u16 low, high;
62462+ __u8 mode;
62463+ __u32 type;
62464+ __u32 proto[8];
62465+
62466+ /* next two structures not used */
62467+
62468+ struct acl_ip_label *prev;
62469+ struct acl_ip_label *next;
62470+};
62471+
62472+struct gr_arg {
62473+ struct user_acl_role_db role_db;
62474+ unsigned char pw[GR_PW_LEN];
62475+ unsigned char salt[GR_SALT_LEN];
62476+ unsigned char sum[GR_SHA_LEN];
62477+ unsigned char sp_role[GR_SPROLE_LEN];
62478+ struct sprole_pw *sprole_pws;
62479+ dev_t segv_device;
62480+ ino_t segv_inode;
62481+ uid_t segv_uid;
62482+ __u16 num_sprole_pws;
62483+ __u16 mode;
62484+};
62485+
62486+struct gr_arg_wrapper {
62487+ struct gr_arg *arg;
62488+ __u32 version;
62489+ __u32 size;
62490+};
62491+
62492+struct subject_map {
62493+ struct acl_subject_label *user;
62494+ struct acl_subject_label *kernel;
62495+ struct subject_map *prev;
62496+ struct subject_map *next;
62497+};
62498+
62499+struct acl_subj_map_db {
62500+ struct subject_map **s_hash;
62501+ __u32 s_size;
62502+};
62503+
62504+/* End Data Structures Section */
62505+
62506+/* Hash functions generated by empirical testing by Brad Spengler
62507+ Makes good use of the low bits of the inode. Generally 0-1 times
62508+ in loop for successful match. 0-3 for unsuccessful match.
62509+ Shift/add algorithm with modulus of table size and an XOR*/
62510+
62511+static __inline__ unsigned int
62512+rhash(const uid_t uid, const __u16 type, const unsigned int sz)
62513+{
62514+ return ((((uid + type) << (16 + type)) ^ uid) % sz);
62515+}
62516+
62517+ static __inline__ unsigned int
62518+shash(const struct acl_subject_label *userp, const unsigned int sz)
62519+{
62520+ return ((const unsigned long)userp % sz);
62521+}
62522+
62523+static __inline__ unsigned int
62524+fhash(const ino_t ino, const dev_t dev, const unsigned int sz)
62525+{
62526+ return (((ino + dev) ^ ((ino << 13) + (ino << 23) + (dev << 9))) % sz);
62527+}
62528+
62529+static __inline__ unsigned int
62530+nhash(const char *name, const __u16 len, const unsigned int sz)
62531+{
62532+ return full_name_hash((const unsigned char *)name, len) % sz;
62533+}
62534+
62535+#define FOR_EACH_ROLE_START(role) \
62536+ role = role_list; \
62537+ while (role) {
62538+
62539+#define FOR_EACH_ROLE_END(role) \
62540+ role = role->prev; \
62541+ }
62542+
62543+#define FOR_EACH_SUBJECT_START(role,subj,iter) \
62544+ subj = NULL; \
62545+ iter = 0; \
62546+ while (iter < role->subj_hash_size) { \
62547+ if (subj == NULL) \
62548+ subj = role->subj_hash[iter]; \
62549+ if (subj == NULL) { \
62550+ iter++; \
62551+ continue; \
62552+ }
62553+
62554+#define FOR_EACH_SUBJECT_END(subj,iter) \
62555+ subj = subj->next; \
62556+ if (subj == NULL) \
62557+ iter++; \
62558+ }
62559+
62560+
62561+#define FOR_EACH_NESTED_SUBJECT_START(role,subj) \
62562+ subj = role->hash->first; \
62563+ while (subj != NULL) {
62564+
62565+#define FOR_EACH_NESTED_SUBJECT_END(subj) \
62566+ subj = subj->next; \
62567+ }
62568+
62569+#endif
62570+
62571diff --git a/include/linux/gralloc.h b/include/linux/gralloc.h
62572new file mode 100644
62573index 0000000..323ecf2
62574--- /dev/null
62575+++ b/include/linux/gralloc.h
62576@@ -0,0 +1,9 @@
62577+#ifndef __GRALLOC_H
62578+#define __GRALLOC_H
62579+
62580+void acl_free_all(void);
62581+int acl_alloc_stack_init(unsigned long size);
62582+void *acl_alloc(unsigned long len);
62583+void *acl_alloc_num(unsigned long num, unsigned long len);
62584+
62585+#endif
62586diff --git a/include/linux/grdefs.h b/include/linux/grdefs.h
62587new file mode 100644
62588index 0000000..b30e9bc
62589--- /dev/null
62590+++ b/include/linux/grdefs.h
62591@@ -0,0 +1,140 @@
62592+#ifndef GRDEFS_H
62593+#define GRDEFS_H
62594+
62595+/* Begin grsecurity status declarations */
62596+
62597+enum {
62598+ GR_READY = 0x01,
62599+ GR_STATUS_INIT = 0x00 // disabled state
62600+};
62601+
62602+/* Begin ACL declarations */
62603+
62604+/* Role flags */
62605+
62606+enum {
62607+ GR_ROLE_USER = 0x0001,
62608+ GR_ROLE_GROUP = 0x0002,
62609+ GR_ROLE_DEFAULT = 0x0004,
62610+ GR_ROLE_SPECIAL = 0x0008,
62611+ GR_ROLE_AUTH = 0x0010,
62612+ GR_ROLE_NOPW = 0x0020,
62613+ GR_ROLE_GOD = 0x0040,
62614+ GR_ROLE_LEARN = 0x0080,
62615+ GR_ROLE_TPE = 0x0100,
62616+ GR_ROLE_DOMAIN = 0x0200,
62617+ GR_ROLE_PAM = 0x0400,
62618+ GR_ROLE_PERSIST = 0x0800
62619+};
62620+
62621+/* ACL Subject and Object mode flags */
62622+enum {
62623+ GR_DELETED = 0x80000000
62624+};
62625+
62626+/* ACL Object-only mode flags */
62627+enum {
62628+ GR_READ = 0x00000001,
62629+ GR_APPEND = 0x00000002,
62630+ GR_WRITE = 0x00000004,
62631+ GR_EXEC = 0x00000008,
62632+ GR_FIND = 0x00000010,
62633+ GR_INHERIT = 0x00000020,
62634+ GR_SETID = 0x00000040,
62635+ GR_CREATE = 0x00000080,
62636+ GR_DELETE = 0x00000100,
62637+ GR_LINK = 0x00000200,
62638+ GR_AUDIT_READ = 0x00000400,
62639+ GR_AUDIT_APPEND = 0x00000800,
62640+ GR_AUDIT_WRITE = 0x00001000,
62641+ GR_AUDIT_EXEC = 0x00002000,
62642+ GR_AUDIT_FIND = 0x00004000,
62643+ GR_AUDIT_INHERIT= 0x00008000,
62644+ GR_AUDIT_SETID = 0x00010000,
62645+ GR_AUDIT_CREATE = 0x00020000,
62646+ GR_AUDIT_DELETE = 0x00040000,
62647+ GR_AUDIT_LINK = 0x00080000,
62648+ GR_PTRACERD = 0x00100000,
62649+ GR_NOPTRACE = 0x00200000,
62650+ GR_SUPPRESS = 0x00400000,
62651+ GR_NOLEARN = 0x00800000,
62652+ GR_INIT_TRANSFER= 0x01000000
62653+};
62654+
62655+#define GR_AUDITS (GR_AUDIT_READ | GR_AUDIT_WRITE | GR_AUDIT_APPEND | GR_AUDIT_EXEC | \
62656+ GR_AUDIT_FIND | GR_AUDIT_INHERIT | GR_AUDIT_SETID | \
62657+ GR_AUDIT_CREATE | GR_AUDIT_DELETE | GR_AUDIT_LINK)
62658+
62659+/* ACL subject-only mode flags */
62660+enum {
62661+ GR_KILL = 0x00000001,
62662+ GR_VIEW = 0x00000002,
62663+ GR_PROTECTED = 0x00000004,
62664+ GR_LEARN = 0x00000008,
62665+ GR_OVERRIDE = 0x00000010,
62666+ /* just a placeholder, this mode is only used in userspace */
62667+ GR_DUMMY = 0x00000020,
62668+ GR_PROTSHM = 0x00000040,
62669+ GR_KILLPROC = 0x00000080,
62670+ GR_KILLIPPROC = 0x00000100,
62671+ /* just a placeholder, this mode is only used in userspace */
62672+ GR_NOTROJAN = 0x00000200,
62673+ GR_PROTPROCFD = 0x00000400,
62674+ GR_PROCACCT = 0x00000800,
62675+ GR_RELAXPTRACE = 0x00001000,
62676+ GR_NESTED = 0x00002000,
62677+ GR_INHERITLEARN = 0x00004000,
62678+ GR_PROCFIND = 0x00008000,
62679+ GR_POVERRIDE = 0x00010000,
62680+ GR_KERNELAUTH = 0x00020000,
62681+ GR_ATSECURE = 0x00040000,
62682+ GR_SHMEXEC = 0x00080000
62683+};
62684+
62685+enum {
62686+ GR_PAX_ENABLE_SEGMEXEC = 0x0001,
62687+ GR_PAX_ENABLE_PAGEEXEC = 0x0002,
62688+ GR_PAX_ENABLE_MPROTECT = 0x0004,
62689+ GR_PAX_ENABLE_RANDMMAP = 0x0008,
62690+ GR_PAX_ENABLE_EMUTRAMP = 0x0010,
62691+ GR_PAX_DISABLE_SEGMEXEC = 0x0100,
62692+ GR_PAX_DISABLE_PAGEEXEC = 0x0200,
62693+ GR_PAX_DISABLE_MPROTECT = 0x0400,
62694+ GR_PAX_DISABLE_RANDMMAP = 0x0800,
62695+ GR_PAX_DISABLE_EMUTRAMP = 0x1000,
62696+};
62697+
62698+enum {
62699+ GR_ID_USER = 0x01,
62700+ GR_ID_GROUP = 0x02,
62701+};
62702+
62703+enum {
62704+ GR_ID_ALLOW = 0x01,
62705+ GR_ID_DENY = 0x02,
62706+};
62707+
62708+#define GR_CRASH_RES 31
62709+#define GR_UIDTABLE_MAX 500
62710+
62711+/* begin resource learning section */
62712+enum {
62713+ GR_RLIM_CPU_BUMP = 60,
62714+ GR_RLIM_FSIZE_BUMP = 50000,
62715+ GR_RLIM_DATA_BUMP = 10000,
62716+ GR_RLIM_STACK_BUMP = 1000,
62717+ GR_RLIM_CORE_BUMP = 10000,
62718+ GR_RLIM_RSS_BUMP = 500000,
62719+ GR_RLIM_NPROC_BUMP = 1,
62720+ GR_RLIM_NOFILE_BUMP = 5,
62721+ GR_RLIM_MEMLOCK_BUMP = 50000,
62722+ GR_RLIM_AS_BUMP = 500000,
62723+ GR_RLIM_LOCKS_BUMP = 2,
62724+ GR_RLIM_SIGPENDING_BUMP = 5,
62725+ GR_RLIM_MSGQUEUE_BUMP = 10000,
62726+ GR_RLIM_NICE_BUMP = 1,
62727+ GR_RLIM_RTPRIO_BUMP = 1,
62728+ GR_RLIM_RTTIME_BUMP = 1000000
62729+};
62730+
62731+#endif
62732diff --git a/include/linux/grinternal.h b/include/linux/grinternal.h
62733new file mode 100644
62734index 0000000..c9292f7
62735--- /dev/null
62736+++ b/include/linux/grinternal.h
62737@@ -0,0 +1,223 @@
62738+#ifndef __GRINTERNAL_H
62739+#define __GRINTERNAL_H
62740+
62741+#ifdef CONFIG_GRKERNSEC
62742+
62743+#include <linux/fs.h>
62744+#include <linux/mnt_namespace.h>
62745+#include <linux/nsproxy.h>
62746+#include <linux/gracl.h>
62747+#include <linux/grdefs.h>
62748+#include <linux/grmsg.h>
62749+
62750+void gr_add_learn_entry(const char *fmt, ...)
62751+ __attribute__ ((format (printf, 1, 2)));
62752+__u32 gr_search_file(const struct dentry *dentry, const __u32 mode,
62753+ const struct vfsmount *mnt);
62754+__u32 gr_check_create(const struct dentry *new_dentry,
62755+ const struct dentry *parent,
62756+ const struct vfsmount *mnt, const __u32 mode);
62757+int gr_check_protected_task(const struct task_struct *task);
62758+__u32 to_gr_audit(const __u32 reqmode);
62759+int gr_set_acls(const int type);
62760+int gr_apply_subject_to_task(struct task_struct *task);
62761+int gr_acl_is_enabled(void);
62762+char gr_roletype_to_char(void);
62763+
62764+void gr_handle_alertkill(struct task_struct *task);
62765+char *gr_to_filename(const struct dentry *dentry,
62766+ const struct vfsmount *mnt);
62767+char *gr_to_filename1(const struct dentry *dentry,
62768+ const struct vfsmount *mnt);
62769+char *gr_to_filename2(const struct dentry *dentry,
62770+ const struct vfsmount *mnt);
62771+char *gr_to_filename3(const struct dentry *dentry,
62772+ const struct vfsmount *mnt);
62773+
62774+extern int grsec_enable_ptrace_readexec;
62775+extern int grsec_enable_harden_ptrace;
62776+extern int grsec_enable_link;
62777+extern int grsec_enable_fifo;
62778+extern int grsec_enable_execve;
62779+extern int grsec_enable_shm;
62780+extern int grsec_enable_execlog;
62781+extern int grsec_enable_signal;
62782+extern int grsec_enable_audit_ptrace;
62783+extern int grsec_enable_forkfail;
62784+extern int grsec_enable_time;
62785+extern int grsec_enable_rofs;
62786+extern int grsec_enable_chroot_shmat;
62787+extern int grsec_enable_chroot_mount;
62788+extern int grsec_enable_chroot_double;
62789+extern int grsec_enable_chroot_pivot;
62790+extern int grsec_enable_chroot_chdir;
62791+extern int grsec_enable_chroot_chmod;
62792+extern int grsec_enable_chroot_mknod;
62793+extern int grsec_enable_chroot_fchdir;
62794+extern int grsec_enable_chroot_nice;
62795+extern int grsec_enable_chroot_execlog;
62796+extern int grsec_enable_chroot_caps;
62797+extern int grsec_enable_chroot_sysctl;
62798+extern int grsec_enable_chroot_unix;
62799+extern int grsec_enable_symlinkown;
62800+extern int grsec_symlinkown_gid;
62801+extern int grsec_enable_tpe;
62802+extern int grsec_tpe_gid;
62803+extern int grsec_enable_tpe_all;
62804+extern int grsec_enable_tpe_invert;
62805+extern int grsec_enable_socket_all;
62806+extern int grsec_socket_all_gid;
62807+extern int grsec_enable_socket_client;
62808+extern int grsec_socket_client_gid;
62809+extern int grsec_enable_socket_server;
62810+extern int grsec_socket_server_gid;
62811+extern int grsec_audit_gid;
62812+extern int grsec_enable_group;
62813+extern int grsec_enable_audit_textrel;
62814+extern int grsec_enable_log_rwxmaps;
62815+extern int grsec_enable_mount;
62816+extern int grsec_enable_chdir;
62817+extern int grsec_resource_logging;
62818+extern int grsec_enable_blackhole;
62819+extern int grsec_lastack_retries;
62820+extern int grsec_enable_brute;
62821+extern int grsec_lock;
62822+
62823+extern spinlock_t grsec_alert_lock;
62824+extern unsigned long grsec_alert_wtime;
62825+extern unsigned long grsec_alert_fyet;
62826+
62827+extern spinlock_t grsec_audit_lock;
62828+
62829+extern rwlock_t grsec_exec_file_lock;
62830+
62831+#define gr_task_fullpath(tsk) ((tsk)->exec_file ? \
62832+ gr_to_filename2((tsk)->exec_file->f_path.dentry, \
62833+ (tsk)->exec_file->f_vfsmnt) : "/")
62834+
62835+#define gr_parent_task_fullpath(tsk) ((tsk)->real_parent->exec_file ? \
62836+ gr_to_filename3((tsk)->real_parent->exec_file->f_path.dentry, \
62837+ (tsk)->real_parent->exec_file->f_vfsmnt) : "/")
62838+
62839+#define gr_task_fullpath0(tsk) ((tsk)->exec_file ? \
62840+ gr_to_filename((tsk)->exec_file->f_path.dentry, \
62841+ (tsk)->exec_file->f_vfsmnt) : "/")
62842+
62843+#define gr_parent_task_fullpath0(tsk) ((tsk)->real_parent->exec_file ? \
62844+ gr_to_filename1((tsk)->real_parent->exec_file->f_path.dentry, \
62845+ (tsk)->real_parent->exec_file->f_vfsmnt) : "/")
62846+
62847+#define proc_is_chrooted(tsk_a) ((tsk_a)->gr_is_chrooted)
62848+
62849+#define have_same_root(tsk_a,tsk_b) ((tsk_a)->gr_chroot_dentry == (tsk_b)->gr_chroot_dentry)
62850+
62851+#define DEFAULTSECARGS(task, cred, pcred) gr_task_fullpath(task), (task)->comm, \
62852+ (task)->pid, (cred)->uid, \
62853+ (cred)->euid, (cred)->gid, (cred)->egid, \
62854+ gr_parent_task_fullpath(task), \
62855+ (task)->real_parent->comm, (task)->real_parent->pid, \
62856+ (pcred)->uid, (pcred)->euid, \
62857+ (pcred)->gid, (pcred)->egid
62858+
62859+#define GR_CHROOT_CAPS {{ \
62860+ CAP_TO_MASK(CAP_LINUX_IMMUTABLE) | CAP_TO_MASK(CAP_NET_ADMIN) | \
62861+ CAP_TO_MASK(CAP_SYS_MODULE) | CAP_TO_MASK(CAP_SYS_RAWIO) | \
62862+ CAP_TO_MASK(CAP_SYS_PACCT) | CAP_TO_MASK(CAP_SYS_ADMIN) | \
62863+ CAP_TO_MASK(CAP_SYS_BOOT) | CAP_TO_MASK(CAP_SYS_TIME) | \
62864+ CAP_TO_MASK(CAP_NET_RAW) | CAP_TO_MASK(CAP_SYS_TTY_CONFIG) | \
62865+ CAP_TO_MASK(CAP_IPC_OWNER) | CAP_TO_MASK(CAP_SETFCAP), \
62866+ CAP_TO_MASK(CAP_SYSLOG) | CAP_TO_MASK(CAP_MAC_ADMIN) }}
62867+
62868+#define security_learn(normal_msg,args...) \
62869+({ \
62870+ read_lock(&grsec_exec_file_lock); \
62871+ gr_add_learn_entry(normal_msg "\n", ## args); \
62872+ read_unlock(&grsec_exec_file_lock); \
62873+})
62874+
62875+enum {
62876+ GR_DO_AUDIT,
62877+ GR_DONT_AUDIT,
62878+ /* used for non-audit messages that we shouldn't kill the task on */
62879+ GR_DONT_AUDIT_GOOD
62880+};
62881+
62882+enum {
62883+ GR_TTYSNIFF,
62884+ GR_RBAC,
62885+ GR_RBAC_STR,
62886+ GR_STR_RBAC,
62887+ GR_RBAC_MODE2,
62888+ GR_RBAC_MODE3,
62889+ GR_FILENAME,
62890+ GR_SYSCTL_HIDDEN,
62891+ GR_NOARGS,
62892+ GR_ONE_INT,
62893+ GR_ONE_INT_TWO_STR,
62894+ GR_ONE_STR,
62895+ GR_STR_INT,
62896+ GR_TWO_STR_INT,
62897+ GR_TWO_INT,
62898+ GR_TWO_U64,
62899+ GR_THREE_INT,
62900+ GR_FIVE_INT_TWO_STR,
62901+ GR_TWO_STR,
62902+ GR_THREE_STR,
62903+ GR_FOUR_STR,
62904+ GR_STR_FILENAME,
62905+ GR_FILENAME_STR,
62906+ GR_FILENAME_TWO_INT,
62907+ GR_FILENAME_TWO_INT_STR,
62908+ GR_TEXTREL,
62909+ GR_PTRACE,
62910+ GR_RESOURCE,
62911+ GR_CAP,
62912+ GR_SIG,
62913+ GR_SIG2,
62914+ GR_CRASH1,
62915+ GR_CRASH2,
62916+ GR_PSACCT,
62917+ GR_RWXMAP
62918+};
62919+
62920+#define gr_log_hidden_sysctl(audit, msg, str) gr_log_varargs(audit, msg, GR_SYSCTL_HIDDEN, str)
62921+#define gr_log_ttysniff(audit, msg, task) gr_log_varargs(audit, msg, GR_TTYSNIFF, task)
62922+#define gr_log_fs_rbac_generic(audit, msg, dentry, mnt) gr_log_varargs(audit, msg, GR_RBAC, dentry, mnt)
62923+#define gr_log_fs_rbac_str(audit, msg, dentry, mnt, str) gr_log_varargs(audit, msg, GR_RBAC_STR, dentry, mnt, str)
62924+#define gr_log_fs_str_rbac(audit, msg, str, dentry, mnt) gr_log_varargs(audit, msg, GR_STR_RBAC, str, dentry, mnt)
62925+#define gr_log_fs_rbac_mode2(audit, msg, dentry, mnt, str1, str2) gr_log_varargs(audit, msg, GR_RBAC_MODE2, dentry, mnt, str1, str2)
62926+#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)
62927+#define gr_log_fs_generic(audit, msg, dentry, mnt) gr_log_varargs(audit, msg, GR_FILENAME, dentry, mnt)
62928+#define gr_log_noargs(audit, msg) gr_log_varargs(audit, msg, GR_NOARGS)
62929+#define gr_log_int(audit, msg, num) gr_log_varargs(audit, msg, GR_ONE_INT, num)
62930+#define gr_log_int_str2(audit, msg, num, str1, str2) gr_log_varargs(audit, msg, GR_ONE_INT_TWO_STR, num, str1, str2)
62931+#define gr_log_str(audit, msg, str) gr_log_varargs(audit, msg, GR_ONE_STR, str)
62932+#define gr_log_str_int(audit, msg, str, num) gr_log_varargs(audit, msg, GR_STR_INT, str, num)
62933+#define gr_log_int_int(audit, msg, num1, num2) gr_log_varargs(audit, msg, GR_TWO_INT, num1, num2)
62934+#define gr_log_two_u64(audit, msg, num1, num2) gr_log_varargs(audit, msg, GR_TWO_U64, num1, num2)
62935+#define gr_log_int3(audit, msg, num1, num2, num3) gr_log_varargs(audit, msg, GR_THREE_INT, num1, num2, num3)
62936+#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)
62937+#define gr_log_str_str(audit, msg, str1, str2) gr_log_varargs(audit, msg, GR_TWO_STR, str1, str2)
62938+#define gr_log_str2_int(audit, msg, str1, str2, num) gr_log_varargs(audit, msg, GR_TWO_STR_INT, str1, str2, num)
62939+#define gr_log_str3(audit, msg, str1, str2, str3) gr_log_varargs(audit, msg, GR_THREE_STR, str1, str2, str3)
62940+#define gr_log_str4(audit, msg, str1, str2, str3, str4) gr_log_varargs(audit, msg, GR_FOUR_STR, str1, str2, str3, str4)
62941+#define gr_log_str_fs(audit, msg, str, dentry, mnt) gr_log_varargs(audit, msg, GR_STR_FILENAME, str, dentry, mnt)
62942+#define gr_log_fs_str(audit, msg, dentry, mnt, str) gr_log_varargs(audit, msg, GR_FILENAME_STR, dentry, mnt, str)
62943+#define gr_log_fs_int2(audit, msg, dentry, mnt, num1, num2) gr_log_varargs(audit, msg, GR_FILENAME_TWO_INT, dentry, mnt, num1, num2)
62944+#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)
62945+#define gr_log_textrel_ulong_ulong(audit, msg, file, ulong1, ulong2) gr_log_varargs(audit, msg, GR_TEXTREL, file, ulong1, ulong2)
62946+#define gr_log_ptrace(audit, msg, task) gr_log_varargs(audit, msg, GR_PTRACE, task)
62947+#define gr_log_res_ulong2_str(audit, msg, task, ulong1, str, ulong2) gr_log_varargs(audit, msg, GR_RESOURCE, task, ulong1, str, ulong2)
62948+#define gr_log_cap(audit, msg, task, str) gr_log_varargs(audit, msg, GR_CAP, task, str)
62949+#define gr_log_sig_addr(audit, msg, str, addr) gr_log_varargs(audit, msg, GR_SIG, str, addr)
62950+#define gr_log_sig_task(audit, msg, task, num) gr_log_varargs(audit, msg, GR_SIG2, task, num)
62951+#define gr_log_crash1(audit, msg, task, ulong) gr_log_varargs(audit, msg, GR_CRASH1, task, ulong)
62952+#define gr_log_crash2(audit, msg, task, ulong1) gr_log_varargs(audit, msg, GR_CRASH2, task, ulong1)
62953+#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)
62954+#define gr_log_rwxmap(audit, msg, str) gr_log_varargs(audit, msg, GR_RWXMAP, str)
62955+
62956+void gr_log_varargs(int audit, const char *msg, int argtypes, ...);
62957+
62958+#endif
62959+
62960+#endif
62961diff --git a/include/linux/grmsg.h b/include/linux/grmsg.h
62962new file mode 100644
62963index 0000000..54f4e85
62964--- /dev/null
62965+++ b/include/linux/grmsg.h
62966@@ -0,0 +1,110 @@
62967+#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"
62968+#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"
62969+#define GR_PTRACE_ACL_MSG "denied ptrace of %.950s(%.16s:%d) by "
62970+#define GR_STOPMOD_MSG "denied modification of module state by "
62971+#define GR_ROFS_BLOCKWRITE_MSG "denied write to block device %.950s by "
62972+#define GR_ROFS_MOUNT_MSG "denied writable mount of %.950s by "
62973+#define GR_IOPERM_MSG "denied use of ioperm() by "
62974+#define GR_IOPL_MSG "denied use of iopl() by "
62975+#define GR_SHMAT_ACL_MSG "denied attach of shared memory of UID %u, PID %d, ID %u by "
62976+#define GR_UNIX_CHROOT_MSG "denied connect() to abstract AF_UNIX socket outside of chroot by "
62977+#define GR_SHMAT_CHROOT_MSG "denied attach of shared memory outside of chroot by "
62978+#define GR_MEM_READWRITE_MSG "denied access of range %Lx -> %Lx in /dev/mem by "
62979+#define GR_SYMLINK_MSG "not following symlink %.950s owned by %d.%d by "
62980+#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"
62981+#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"
62982+#define GR_HIDDEN_ACL_MSG "%s access to hidden file %.950s by "
62983+#define GR_OPEN_ACL_MSG "%s open of %.950s for%s%s by "
62984+#define GR_CREATE_ACL_MSG "%s create of %.950s for%s%s by "
62985+#define GR_FIFO_MSG "denied writing FIFO %.950s of %d.%d by "
62986+#define GR_MKNOD_CHROOT_MSG "denied mknod of %.950s from chroot by "
62987+#define GR_MKNOD_ACL_MSG "%s mknod of %.950s by "
62988+#define GR_UNIXCONNECT_ACL_MSG "%s connect() to the unix domain socket %.950s by "
62989+#define GR_TTYSNIFF_ACL_MSG "terminal being sniffed by IP:%pI4 %.480s[%.16s:%d], parent %.480s[%.16s:%d] against "
62990+#define GR_MKDIR_ACL_MSG "%s mkdir of %.950s by "
62991+#define GR_RMDIR_ACL_MSG "%s rmdir of %.950s by "
62992+#define GR_UNLINK_ACL_MSG "%s unlink of %.950s by "
62993+#define GR_SYMLINK_ACL_MSG "%s symlink from %.480s to %.480s by "
62994+#define GR_HARDLINK_MSG "denied hardlink of %.930s (owned by %d.%d) to %.30s for "
62995+#define GR_LINK_ACL_MSG "%s link of %.480s to %.480s by "
62996+#define GR_INHERIT_ACL_MSG "successful inherit of %.480s's ACL for %.480s by "
62997+#define GR_RENAME_ACL_MSG "%s rename of %.480s to %.480s by "
62998+#define GR_UNSAFESHARE_EXEC_ACL_MSG "denied exec with cloned fs of %.950s by "
62999+#define GR_PTRACE_EXEC_ACL_MSG "denied ptrace of %.950s by "
63000+#define GR_EXEC_ACL_MSG "%s execution of %.950s by "
63001+#define GR_EXEC_TPE_MSG "denied untrusted exec (due to %.70s) of %.950s by "
63002+#define GR_SEGVSTART_ACL_MSG "possible exploit bruteforcing on " DEFAULTSECMSG " banning uid %u from login for %lu seconds"
63003+#define GR_SEGVNOSUID_ACL_MSG "possible exploit bruteforcing on " DEFAULTSECMSG " banning execution for %lu seconds"
63004+#define GR_MOUNT_CHROOT_MSG "denied mount of %.256s as %.930s from chroot by "
63005+#define GR_PIVOT_CHROOT_MSG "denied pivot_root from chroot by "
63006+#define GR_TRUNCATE_ACL_MSG "%s truncate of %.950s by "
63007+#define GR_ATIME_ACL_MSG "%s access time change of %.950s by "
63008+#define GR_ACCESS_ACL_MSG "%s access of %.950s for%s%s%s by "
63009+#define GR_CHROOT_CHROOT_MSG "denied double chroot to %.950s by "
63010+#define GR_CHMOD_CHROOT_MSG "denied chmod +s of %.950s by "
63011+#define GR_CHMOD_ACL_MSG "%s chmod of %.950s by "
63012+#define GR_CHROOT_FCHDIR_MSG "denied fchdir outside of chroot to %.950s by "
63013+#define GR_CHOWN_ACL_MSG "%s chown of %.950s by "
63014+#define GR_SETXATTR_ACL_MSG "%s setting extended attributes of %.950s by "
63015+#define GR_WRITLIB_ACL_MSG "denied load of writable library %.950s by "
63016+#define GR_INITF_ACL_MSG "init_variables() failed %s by "
63017+#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"
63018+#define GR_DEV_ACL_MSG "/dev/grsec: %d bytes sent %d required, being fed garbage by "
63019+#define GR_SHUTS_ACL_MSG "shutdown auth success for "
63020+#define GR_SHUTF_ACL_MSG "shutdown auth failure for "
63021+#define GR_SHUTI_ACL_MSG "ignoring shutdown for disabled RBAC system for "
63022+#define GR_SEGVMODS_ACL_MSG "segvmod auth success for "
63023+#define GR_SEGVMODF_ACL_MSG "segvmod auth failure for "
63024+#define GR_SEGVMODI_ACL_MSG "ignoring segvmod for disabled RBAC system for "
63025+#define GR_ENABLE_ACL_MSG "%s RBAC system loaded by "
63026+#define GR_ENABLEF_ACL_MSG "unable to load %s for "
63027+#define GR_RELOADI_ACL_MSG "ignoring reload request for disabled RBAC system"
63028+#define GR_RELOAD_ACL_MSG "%s RBAC system reloaded by "
63029+#define GR_RELOADF_ACL_MSG "failed reload of %s for "
63030+#define GR_SPROLEI_ACL_MSG "ignoring change to special role for disabled RBAC system for "
63031+#define GR_SPROLES_ACL_MSG "successful change to special role %s (id %d) by "
63032+#define GR_SPROLEL_ACL_MSG "special role %s (id %d) exited by "
63033+#define GR_SPROLEF_ACL_MSG "special role %s failure for "
63034+#define GR_UNSPROLEI_ACL_MSG "ignoring unauth of special role for disabled RBAC system for "
63035+#define GR_UNSPROLES_ACL_MSG "successful unauth of special role %s (id %d) by "
63036+#define GR_INVMODE_ACL_MSG "invalid mode %d by "
63037+#define GR_PRIORITY_CHROOT_MSG "denied priority change of process (%.16s:%d) by "
63038+#define GR_FAILFORK_MSG "failed fork with errno %s by "
63039+#define GR_NICE_CHROOT_MSG "denied priority change by "
63040+#define GR_UNISIGLOG_MSG "%.32s occurred at %p in "
63041+#define GR_DUALSIGLOG_MSG "signal %d sent to " DEFAULTSECMSG " by "
63042+#define GR_SIG_ACL_MSG "denied send of signal %d to protected task " DEFAULTSECMSG " by "
63043+#define GR_SYSCTL_MSG "denied modification of grsecurity sysctl value : %.32s by "
63044+#define GR_SYSCTL_ACL_MSG "%s sysctl of %.950s for%s%s by "
63045+#define GR_TIME_MSG "time set by "
63046+#define GR_DEFACL_MSG "fatal: unable to find subject for (%.16s:%d), loaded by "
63047+#define GR_MMAP_ACL_MSG "%s executable mmap of %.950s by "
63048+#define GR_MPROTECT_ACL_MSG "%s executable mprotect of %.950s by "
63049+#define GR_SOCK_MSG "denied socket(%.16s,%.16s,%.16s) by "
63050+#define GR_SOCK_NOINET_MSG "denied socket(%.16s,%.16s,%d) by "
63051+#define GR_BIND_MSG "denied bind() by "
63052+#define GR_CONNECT_MSG "denied connect() by "
63053+#define GR_BIND_ACL_MSG "denied bind() to %pI4 port %u sock type %.16s protocol %.16s by "
63054+#define GR_CONNECT_ACL_MSG "denied connect() to %pI4 port %u sock type %.16s protocol %.16s by "
63055+#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"
63056+#define GR_EXEC_CHROOT_MSG "exec of %.980s within chroot by process "
63057+#define GR_CAP_ACL_MSG "use of %s denied for "
63058+#define GR_CAP_CHROOT_MSG "use of %s in chroot denied for "
63059+#define GR_CAP_ACL_MSG2 "use of %s permitted for "
63060+#define GR_USRCHANGE_ACL_MSG "change to uid %u denied for "
63061+#define GR_GRPCHANGE_ACL_MSG "change to gid %u denied for "
63062+#define GR_REMOUNT_AUDIT_MSG "remount of %.256s by "
63063+#define GR_UNMOUNT_AUDIT_MSG "unmount of %.256s by "
63064+#define GR_MOUNT_AUDIT_MSG "mount of %.256s to %.256s by "
63065+#define GR_CHDIR_AUDIT_MSG "chdir to %.980s by "
63066+#define GR_EXEC_AUDIT_MSG "exec of %.930s (%.128s) by "
63067+#define GR_RESOURCE_MSG "denied resource overstep by requesting %lu for %.16s against limit %lu for "
63068+#define GR_RWXMMAP_MSG "denied RWX mmap of %.950s by "
63069+#define GR_RWXMPROTECT_MSG "denied RWX mprotect of %.950s by "
63070+#define GR_TEXTREL_AUDIT_MSG "text relocation in %s, VMA:0x%08lx 0x%08lx by "
63071+#define GR_VM86_MSG "denied use of vm86 by "
63072+#define GR_PTRACE_AUDIT_MSG "process %.950s(%.16s:%d) attached to via ptrace by "
63073+#define GR_PTRACE_READEXEC_MSG "denied ptrace of unreadable binary %.950s by "
63074+#define GR_INIT_TRANSFER_MSG "persistent special role transferred privilege to init by "
63075+#define GR_BADPROCPID_MSG "denied read of sensitive /proc/pid/%s entry via fd passed across exec by "
63076+#define GR_SYMLINKOWNER_MSG "denied following symlink %.950s since symlink owner %u does not match target owner %u, by "
63077diff --git a/include/linux/grsecurity.h b/include/linux/grsecurity.h
63078new file mode 100644
63079index 0000000..187b3ed
63080--- /dev/null
63081+++ b/include/linux/grsecurity.h
63082@@ -0,0 +1,239 @@
63083+#ifndef GR_SECURITY_H
63084+#define GR_SECURITY_H
63085+#include <linux/fs.h>
63086+#include <linux/fs_struct.h>
63087+#include <linux/binfmts.h>
63088+#include <linux/gracl.h>
63089+
63090+/* notify of brain-dead configs */
63091+#if defined(CONFIG_GRKERNSEC_PROC_USER) && defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
63092+#error "CONFIG_GRKERNSEC_PROC_USER and CONFIG_GRKERNSEC_PROC_USERGROUP cannot both be enabled."
63093+#endif
63094+#if defined(CONFIG_PAX_NOEXEC) && !defined(CONFIG_PAX_PAGEEXEC) && !defined(CONFIG_PAX_SEGMEXEC) && !defined(CONFIG_PAX_KERNEXEC)
63095+#error "CONFIG_PAX_NOEXEC enabled, but PAGEEXEC, SEGMEXEC, and KERNEXEC are disabled."
63096+#endif
63097+#if defined(CONFIG_PAX_ASLR) && !defined(CONFIG_PAX_RANDKSTACK) && !defined(CONFIG_PAX_RANDUSTACK) && !defined(CONFIG_PAX_RANDMMAP)
63098+#error "CONFIG_PAX_ASLR enabled, but RANDKSTACK, RANDUSTACK, and RANDMMAP are disabled."
63099+#endif
63100+#if defined(CONFIG_PAX) && !defined(CONFIG_PAX_NOEXEC) && !defined(CONFIG_PAX_ASLR)
63101+#error "CONFIG_PAX enabled, but no PaX options are enabled."
63102+#endif
63103+
63104+#include <linux/compat.h>
63105+
63106+struct user_arg_ptr {
63107+#ifdef CONFIG_COMPAT
63108+ bool is_compat;
63109+#endif
63110+ union {
63111+ const char __user *const __user *native;
63112+#ifdef CONFIG_COMPAT
63113+ compat_uptr_t __user *compat;
63114+#endif
63115+ } ptr;
63116+};
63117+
63118+void gr_handle_brute_attach(struct task_struct *p, unsigned long mm_flags);
63119+void gr_handle_brute_check(void);
63120+void gr_handle_kernel_exploit(void);
63121+int gr_process_user_ban(void);
63122+
63123+char gr_roletype_to_char(void);
63124+
63125+int gr_acl_enable_at_secure(void);
63126+
63127+int gr_check_user_change(int real, int effective, int fs);
63128+int gr_check_group_change(int real, int effective, int fs);
63129+
63130+void gr_del_task_from_ip_table(struct task_struct *p);
63131+
63132+int gr_pid_is_chrooted(struct task_struct *p);
63133+int gr_handle_chroot_fowner(struct pid *pid, enum pid_type type);
63134+int gr_handle_chroot_nice(void);
63135+int gr_handle_chroot_sysctl(const int op);
63136+int gr_handle_chroot_setpriority(struct task_struct *p,
63137+ const int niceval);
63138+int gr_chroot_fchdir(struct dentry *u_dentry, struct vfsmount *u_mnt);
63139+int gr_handle_chroot_chroot(const struct dentry *dentry,
63140+ const struct vfsmount *mnt);
63141+void gr_handle_chroot_chdir(struct path *path);
63142+int gr_handle_chroot_chmod(const struct dentry *dentry,
63143+ const struct vfsmount *mnt, const int mode);
63144+int gr_handle_chroot_mknod(const struct dentry *dentry,
63145+ const struct vfsmount *mnt, const int mode);
63146+int gr_handle_chroot_mount(const struct dentry *dentry,
63147+ const struct vfsmount *mnt,
63148+ const char *dev_name);
63149+int gr_handle_chroot_pivot(void);
63150+int gr_handle_chroot_unix(const pid_t pid);
63151+
63152+int gr_handle_rawio(const struct inode *inode);
63153+
63154+void gr_handle_ioperm(void);
63155+void gr_handle_iopl(void);
63156+
63157+umode_t gr_acl_umask(void);
63158+
63159+int gr_tpe_allow(const struct file *file);
63160+
63161+void gr_set_chroot_entries(struct task_struct *task, struct path *path);
63162+void gr_clear_chroot_entries(struct task_struct *task);
63163+
63164+void gr_log_forkfail(const int retval);
63165+void gr_log_timechange(void);
63166+void gr_log_signal(const int sig, const void *addr, const struct task_struct *t);
63167+void gr_log_chdir(const struct dentry *dentry,
63168+ const struct vfsmount *mnt);
63169+void gr_log_chroot_exec(const struct dentry *dentry,
63170+ const struct vfsmount *mnt);
63171+void gr_handle_exec_args(struct linux_binprm *bprm, struct user_arg_ptr argv);
63172+void gr_log_remount(const char *devname, const int retval);
63173+void gr_log_unmount(const char *devname, const int retval);
63174+void gr_log_mount(const char *from, const char *to, const int retval);
63175+void gr_log_textrel(struct vm_area_struct *vma);
63176+void gr_log_rwxmmap(struct file *file);
63177+void gr_log_rwxmprotect(struct file *file);
63178+
63179+int gr_handle_follow_link(const struct inode *parent,
63180+ const struct inode *inode,
63181+ const struct dentry *dentry,
63182+ const struct vfsmount *mnt);
63183+int gr_handle_fifo(const struct dentry *dentry,
63184+ const struct vfsmount *mnt,
63185+ const struct dentry *dir, const int flag,
63186+ const int acc_mode);
63187+int gr_handle_hardlink(const struct dentry *dentry,
63188+ const struct vfsmount *mnt,
63189+ struct inode *inode,
63190+ const int mode, const char *to);
63191+
63192+int gr_is_capable(const int cap);
63193+int gr_is_capable_nolog(const int cap);
63194+int gr_task_is_capable(const struct task_struct *task, const struct cred *cred, const int cap);
63195+int gr_task_is_capable_nolog(const struct task_struct *task, const int cap);
63196+
63197+void gr_learn_resource(const struct task_struct *task, const int limit,
63198+ const unsigned long wanted, const int gt);
63199+void gr_copy_label(struct task_struct *tsk);
63200+void gr_handle_crash(struct task_struct *task, const int sig);
63201+int gr_handle_signal(const struct task_struct *p, const int sig);
63202+int gr_check_crash_uid(const uid_t uid);
63203+int gr_check_protected_task(const struct task_struct *task);
63204+int gr_check_protected_task_fowner(struct pid *pid, enum pid_type type);
63205+int gr_acl_handle_mmap(const struct file *file,
63206+ const unsigned long prot);
63207+int gr_acl_handle_mprotect(const struct file *file,
63208+ const unsigned long prot);
63209+int gr_check_hidden_task(const struct task_struct *tsk);
63210+__u32 gr_acl_handle_truncate(const struct dentry *dentry,
63211+ const struct vfsmount *mnt);
63212+__u32 gr_acl_handle_utime(const struct dentry *dentry,
63213+ const struct vfsmount *mnt);
63214+__u32 gr_acl_handle_access(const struct dentry *dentry,
63215+ const struct vfsmount *mnt, const int fmode);
63216+__u32 gr_acl_handle_chmod(const struct dentry *dentry,
63217+ const struct vfsmount *mnt, umode_t *mode);
63218+__u32 gr_acl_handle_chown(const struct dentry *dentry,
63219+ const struct vfsmount *mnt);
63220+__u32 gr_acl_handle_setxattr(const struct dentry *dentry,
63221+ const struct vfsmount *mnt);
63222+int gr_handle_ptrace(struct task_struct *task, const long request);
63223+int gr_handle_proc_ptrace(struct task_struct *task);
63224+__u32 gr_acl_handle_execve(const struct dentry *dentry,
63225+ const struct vfsmount *mnt);
63226+int gr_check_crash_exec(const struct file *filp);
63227+int gr_acl_is_enabled(void);
63228+void gr_set_kernel_label(struct task_struct *task);
63229+void gr_set_role_label(struct task_struct *task, const uid_t uid,
63230+ const gid_t gid);
63231+int gr_set_proc_label(const struct dentry *dentry,
63232+ const struct vfsmount *mnt,
63233+ const int unsafe_flags);
63234+__u32 gr_acl_handle_hidden_file(const struct dentry *dentry,
63235+ const struct vfsmount *mnt);
63236+__u32 gr_acl_handle_open(const struct dentry *dentry,
63237+ const struct vfsmount *mnt, int acc_mode);
63238+__u32 gr_acl_handle_creat(const struct dentry *dentry,
63239+ const struct dentry *p_dentry,
63240+ const struct vfsmount *p_mnt,
63241+ int open_flags, int acc_mode, const int imode);
63242+void gr_handle_create(const struct dentry *dentry,
63243+ const struct vfsmount *mnt);
63244+void gr_handle_proc_create(const struct dentry *dentry,
63245+ const struct inode *inode);
63246+__u32 gr_acl_handle_mknod(const struct dentry *new_dentry,
63247+ const struct dentry *parent_dentry,
63248+ const struct vfsmount *parent_mnt,
63249+ const int mode);
63250+__u32 gr_acl_handle_mkdir(const struct dentry *new_dentry,
63251+ const struct dentry *parent_dentry,
63252+ const struct vfsmount *parent_mnt);
63253+__u32 gr_acl_handle_rmdir(const struct dentry *dentry,
63254+ const struct vfsmount *mnt);
63255+void gr_handle_delete(const ino_t ino, const dev_t dev);
63256+__u32 gr_acl_handle_unlink(const struct dentry *dentry,
63257+ const struct vfsmount *mnt);
63258+__u32 gr_acl_handle_symlink(const struct dentry *new_dentry,
63259+ const struct dentry *parent_dentry,
63260+ const struct vfsmount *parent_mnt,
63261+ const char *from);
63262+__u32 gr_acl_handle_link(const struct dentry *new_dentry,
63263+ const struct dentry *parent_dentry,
63264+ const struct vfsmount *parent_mnt,
63265+ const struct dentry *old_dentry,
63266+ const struct vfsmount *old_mnt, const char *to);
63267+int gr_handle_symlink_owner(const struct path *link, const struct inode *target);
63268+int gr_acl_handle_rename(struct dentry *new_dentry,
63269+ struct dentry *parent_dentry,
63270+ const struct vfsmount *parent_mnt,
63271+ struct dentry *old_dentry,
63272+ struct inode *old_parent_inode,
63273+ struct vfsmount *old_mnt, const char *newname);
63274+void gr_handle_rename(struct inode *old_dir, struct inode *new_dir,
63275+ struct dentry *old_dentry,
63276+ struct dentry *new_dentry,
63277+ struct vfsmount *mnt, const __u8 replace);
63278+__u32 gr_check_link(const struct dentry *new_dentry,
63279+ const struct dentry *parent_dentry,
63280+ const struct vfsmount *parent_mnt,
63281+ const struct dentry *old_dentry,
63282+ const struct vfsmount *old_mnt);
63283+int gr_acl_handle_filldir(const struct file *file, const char *name,
63284+ const unsigned int namelen, const ino_t ino);
63285+
63286+__u32 gr_acl_handle_unix(const struct dentry *dentry,
63287+ const struct vfsmount *mnt);
63288+void gr_acl_handle_exit(void);
63289+void gr_acl_handle_psacct(struct task_struct *task, const long code);
63290+int gr_acl_handle_procpidmem(const struct task_struct *task);
63291+int gr_handle_rofs_mount(struct dentry *dentry, struct vfsmount *mnt, int mnt_flags);
63292+int gr_handle_rofs_blockwrite(struct dentry *dentry, struct vfsmount *mnt, int acc_mode);
63293+void gr_audit_ptrace(struct task_struct *task);
63294+dev_t gr_get_dev_from_dentry(struct dentry *dentry);
63295+void gr_put_exec_file(struct task_struct *task);
63296+
63297+int gr_ptrace_readexec(struct file *file, int unsafe_flags);
63298+
63299+#ifdef CONFIG_GRKERNSEC
63300+void task_grsec_rbac(struct seq_file *m, struct task_struct *p);
63301+void gr_handle_vm86(void);
63302+void gr_handle_mem_readwrite(u64 from, u64 to);
63303+
63304+void gr_log_badprocpid(const char *entry);
63305+
63306+extern int grsec_enable_dmesg;
63307+extern int grsec_disable_privio;
63308+
63309+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
63310+extern int grsec_proc_gid;
63311+#endif
63312+
63313+#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
63314+extern int grsec_enable_chroot_findtask;
63315+#endif
63316+#ifdef CONFIG_GRKERNSEC_SETXID
63317+extern int grsec_enable_setxid;
63318+#endif
63319+#endif
63320+
63321+#endif
63322diff --git a/include/linux/grsock.h b/include/linux/grsock.h
63323new file mode 100644
63324index 0000000..e7ffaaf
63325--- /dev/null
63326+++ b/include/linux/grsock.h
63327@@ -0,0 +1,19 @@
63328+#ifndef __GRSOCK_H
63329+#define __GRSOCK_H
63330+
63331+extern void gr_attach_curr_ip(const struct sock *sk);
63332+extern int gr_handle_sock_all(const int family, const int type,
63333+ const int protocol);
63334+extern int gr_handle_sock_server(const struct sockaddr *sck);
63335+extern int gr_handle_sock_server_other(const struct sock *sck);
63336+extern int gr_handle_sock_client(const struct sockaddr *sck);
63337+extern int gr_search_connect(struct socket * sock,
63338+ struct sockaddr_in * addr);
63339+extern int gr_search_bind(struct socket * sock,
63340+ struct sockaddr_in * addr);
63341+extern int gr_search_listen(struct socket * sock);
63342+extern int gr_search_accept(struct socket * sock);
63343+extern int gr_search_socket(const int domain, const int type,
63344+ const int protocol);
63345+
63346+#endif
63347diff --git a/include/linux/hid.h b/include/linux/hid.h
63348index 42970de..5db3c92 100644
63349--- a/include/linux/hid.h
63350+++ b/include/linux/hid.h
63351@@ -705,7 +705,7 @@ struct hid_ll_driver {
63352 unsigned int code, int value);
63353
63354 int (*parse)(struct hid_device *hdev);
63355-};
63356+} __no_const;
63357
63358 #define PM_HINT_FULLON 1<<5
63359 #define PM_HINT_NORMAL 1<<1
63360diff --git a/include/linux/highmem.h b/include/linux/highmem.h
63361index ef788b5..ac41b7b 100644
63362--- a/include/linux/highmem.h
63363+++ b/include/linux/highmem.h
63364@@ -189,6 +189,18 @@ static inline void clear_highpage(struct page *page)
63365 kunmap_atomic(kaddr);
63366 }
63367
63368+static inline void sanitize_highpage(struct page *page)
63369+{
63370+ void *kaddr;
63371+ unsigned long flags;
63372+
63373+ local_irq_save(flags);
63374+ kaddr = kmap_atomic(page);
63375+ clear_page(kaddr);
63376+ kunmap_atomic(kaddr);
63377+ local_irq_restore(flags);
63378+}
63379+
63380 static inline void zero_user_segments(struct page *page,
63381 unsigned start1, unsigned end1,
63382 unsigned start2, unsigned end2)
63383diff --git a/include/linux/i2c.h b/include/linux/i2c.h
63384index 5970266..1c48c3b 100644
63385--- a/include/linux/i2c.h
63386+++ b/include/linux/i2c.h
63387@@ -369,6 +369,7 @@ struct i2c_algorithm {
63388 /* To determine what the adapter supports */
63389 u32 (*functionality) (struct i2c_adapter *);
63390 };
63391+typedef struct i2c_algorithm __no_const i2c_algorithm_no_const;
63392
63393 /*
63394 * i2c_adapter is the structure used to identify a physical i2c bus along
63395diff --git a/include/linux/i2o.h b/include/linux/i2o.h
63396index d23c3c2..eb63c81 100644
63397--- a/include/linux/i2o.h
63398+++ b/include/linux/i2o.h
63399@@ -565,7 +565,7 @@ struct i2o_controller {
63400 struct i2o_device *exec; /* Executive */
63401 #if BITS_PER_LONG == 64
63402 spinlock_t context_list_lock; /* lock for context_list */
63403- atomic_t context_list_counter; /* needed for unique contexts */
63404+ atomic_unchecked_t context_list_counter; /* needed for unique contexts */
63405 struct list_head context_list; /* list of context id's
63406 and pointers */
63407 #endif
63408diff --git a/include/linux/if_team.h b/include/linux/if_team.h
63409index aa2e167..84024ce 100644
63410--- a/include/linux/if_team.h
63411+++ b/include/linux/if_team.h
63412@@ -109,6 +109,7 @@ struct team_mode_ops {
63413 void (*port_enabled)(struct team *team, struct team_port *port);
63414 void (*port_disabled)(struct team *team, struct team_port *port);
63415 };
63416+typedef struct team_mode_ops __no_const team_mode_ops_no_const;
63417
63418 enum team_option_type {
63419 TEAM_OPTION_TYPE_U32,
63420@@ -181,7 +182,7 @@ struct team {
63421 struct list_head option_inst_list; /* list of option instances */
63422
63423 const struct team_mode *mode;
63424- struct team_mode_ops ops;
63425+ team_mode_ops_no_const ops;
63426 long mode_priv[TEAM_MODE_PRIV_LONGS];
63427 };
63428
63429diff --git a/include/linux/init.h b/include/linux/init.h
63430index 5e664f6..ba694f0 100644
63431--- a/include/linux/init.h
63432+++ b/include/linux/init.h
63433@@ -39,9 +39,36 @@
63434 * Also note, that this data cannot be "const".
63435 */
63436
63437+#ifdef MODULE
63438+#define add_init_latent_entropy
63439+#define add_devinit_latent_entropy
63440+#define add_cpuinit_latent_entropy
63441+#define add_meminit_latent_entropy
63442+#else
63443+#define add_init_latent_entropy __latent_entropy
63444+
63445+#ifdef CONFIG_HOTPLUG
63446+#define add_devinit_latent_entropy
63447+#else
63448+#define add_devinit_latent_entropy __latent_entropy
63449+#endif
63450+
63451+#ifdef CONFIG_HOTPLUG_CPU
63452+#define add_cpuinit_latent_entropy
63453+#else
63454+#define add_cpuinit_latent_entropy __latent_entropy
63455+#endif
63456+
63457+#ifdef CONFIG_MEMORY_HOTPLUG
63458+#define add_meminit_latent_entropy
63459+#else
63460+#define add_meminit_latent_entropy __latent_entropy
63461+#endif
63462+#endif
63463+
63464 /* These are for everybody (although not all archs will actually
63465 discard it in modules) */
63466-#define __init __section(.init.text) __cold notrace
63467+#define __init __section(.init.text) __cold notrace add_init_latent_entropy
63468 #define __initdata __section(.init.data)
63469 #define __initconst __section(.init.rodata)
63470 #define __exitdata __section(.exit.data)
63471@@ -83,7 +110,7 @@
63472 #define __exit __section(.exit.text) __exitused __cold notrace
63473
63474 /* Used for HOTPLUG */
63475-#define __devinit __section(.devinit.text) __cold notrace
63476+#define __devinit __section(.devinit.text) __cold notrace add_devinit_latent_entropy
63477 #define __devinitdata __section(.devinit.data)
63478 #define __devinitconst __section(.devinit.rodata)
63479 #define __devexit __section(.devexit.text) __exitused __cold notrace
63480@@ -91,7 +118,7 @@
63481 #define __devexitconst __section(.devexit.rodata)
63482
63483 /* Used for HOTPLUG_CPU */
63484-#define __cpuinit __section(.cpuinit.text) __cold notrace
63485+#define __cpuinit __section(.cpuinit.text) __cold notrace add_cpuinit_latent_entropy
63486 #define __cpuinitdata __section(.cpuinit.data)
63487 #define __cpuinitconst __section(.cpuinit.rodata)
63488 #define __cpuexit __section(.cpuexit.text) __exitused __cold notrace
63489@@ -99,7 +126,7 @@
63490 #define __cpuexitconst __section(.cpuexit.rodata)
63491
63492 /* Used for MEMORY_HOTPLUG */
63493-#define __meminit __section(.meminit.text) __cold notrace
63494+#define __meminit __section(.meminit.text) __cold notrace add_meminit_latent_entropy
63495 #define __meminitdata __section(.meminit.data)
63496 #define __meminitconst __section(.meminit.rodata)
63497 #define __memexit __section(.memexit.text) __exitused __cold notrace
63498diff --git a/include/linux/init_task.h b/include/linux/init_task.h
63499index 89f1cb1..7986c0f 100644
63500--- a/include/linux/init_task.h
63501+++ b/include/linux/init_task.h
63502@@ -143,6 +143,12 @@ extern struct task_group root_task_group;
63503
63504 #define INIT_TASK_COMM "swapper"
63505
63506+#ifdef CONFIG_X86
63507+#define INIT_TASK_THREAD_INFO .tinfo = INIT_THREAD_INFO,
63508+#else
63509+#define INIT_TASK_THREAD_INFO
63510+#endif
63511+
63512 /*
63513 * INIT_TASK is used to set up the first task table, touch at
63514 * your own risk!. Base=0, limit=0x1fffff (=2MB)
63515@@ -182,6 +188,7 @@ extern struct task_group root_task_group;
63516 RCU_POINTER_INITIALIZER(cred, &init_cred), \
63517 .comm = INIT_TASK_COMM, \
63518 .thread = INIT_THREAD, \
63519+ INIT_TASK_THREAD_INFO \
63520 .fs = &init_fs, \
63521 .files = &init_files, \
63522 .signal = &init_signals, \
63523diff --git a/include/linux/intel-iommu.h b/include/linux/intel-iommu.h
63524index 78e2ada..745564d 100644
63525--- a/include/linux/intel-iommu.h
63526+++ b/include/linux/intel-iommu.h
63527@@ -296,7 +296,7 @@ struct iommu_flush {
63528 u8 fm, u64 type);
63529 void (*flush_iotlb)(struct intel_iommu *iommu, u16 did, u64 addr,
63530 unsigned int size_order, u64 type);
63531-};
63532+} __no_const;
63533
63534 enum {
63535 SR_DMAR_FECTL_REG,
63536diff --git a/include/linux/interrupt.h b/include/linux/interrupt.h
63537index c5f856a..d29c117 100644
63538--- a/include/linux/interrupt.h
63539+++ b/include/linux/interrupt.h
63540@@ -433,7 +433,7 @@ enum
63541 /* map softirq index to softirq name. update 'softirq_to_name' in
63542 * kernel/softirq.c when adding a new softirq.
63543 */
63544-extern char *softirq_to_name[NR_SOFTIRQS];
63545+extern const char * const softirq_to_name[NR_SOFTIRQS];
63546
63547 /* softirq mask and active fields moved to irq_cpustat_t in
63548 * asm/hardirq.h to get better cache usage. KAO
63549@@ -441,12 +441,12 @@ extern char *softirq_to_name[NR_SOFTIRQS];
63550
63551 struct softirq_action
63552 {
63553- void (*action)(struct softirq_action *);
63554+ void (*action)(void);
63555 };
63556
63557 asmlinkage void do_softirq(void);
63558 asmlinkage void __do_softirq(void);
63559-extern void open_softirq(int nr, void (*action)(struct softirq_action *));
63560+extern void open_softirq(int nr, void (*action)(void));
63561 extern void softirq_init(void);
63562 extern void __raise_softirq_irqoff(unsigned int nr);
63563
63564diff --git a/include/linux/kallsyms.h b/include/linux/kallsyms.h
63565index 6883e19..06992b1 100644
63566--- a/include/linux/kallsyms.h
63567+++ b/include/linux/kallsyms.h
63568@@ -15,7 +15,8 @@
63569
63570 struct module;
63571
63572-#ifdef CONFIG_KALLSYMS
63573+#if !defined(__INCLUDED_BY_HIDESYM) || !defined(CONFIG_KALLSYMS)
63574+#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
63575 /* Lookup the address for a symbol. Returns 0 if not found. */
63576 unsigned long kallsyms_lookup_name(const char *name);
63577
63578@@ -106,6 +107,17 @@ static inline int lookup_symbol_attrs(unsigned long addr, unsigned long *size, u
63579 /* Stupid that this does nothing, but I didn't create this mess. */
63580 #define __print_symbol(fmt, addr)
63581 #endif /*CONFIG_KALLSYMS*/
63582+#else /* when included by kallsyms.c, vsnprintf.c, or
63583+ arch/x86/kernel/dumpstack.c, with HIDESYM enabled */
63584+extern void __print_symbol(const char *fmt, unsigned long address);
63585+extern int sprint_backtrace(char *buffer, unsigned long address);
63586+extern int sprint_symbol(char *buffer, unsigned long address);
63587+extern int sprint_symbol_no_offset(char *buffer, unsigned long address);
63588+const char *kallsyms_lookup(unsigned long addr,
63589+ unsigned long *symbolsize,
63590+ unsigned long *offset,
63591+ char **modname, char *namebuf);
63592+#endif
63593
63594 /* This macro allows us to keep printk typechecking */
63595 static __printf(1, 2)
63596diff --git a/include/linux/kgdb.h b/include/linux/kgdb.h
63597index c4d2fc1..5df9c19 100644
63598--- a/include/linux/kgdb.h
63599+++ b/include/linux/kgdb.h
63600@@ -53,7 +53,7 @@ extern int kgdb_connected;
63601 extern int kgdb_io_module_registered;
63602
63603 extern atomic_t kgdb_setting_breakpoint;
63604-extern atomic_t kgdb_cpu_doing_single_step;
63605+extern atomic_unchecked_t kgdb_cpu_doing_single_step;
63606
63607 extern struct task_struct *kgdb_usethread;
63608 extern struct task_struct *kgdb_contthread;
63609@@ -252,7 +252,7 @@ struct kgdb_arch {
63610 void (*disable_hw_break)(struct pt_regs *regs);
63611 void (*remove_all_hw_break)(void);
63612 void (*correct_hw_break)(void);
63613-};
63614+} __do_const;
63615
63616 /**
63617 * struct kgdb_io - Describe the interface for an I/O driver to talk with KGDB.
63618@@ -277,7 +277,7 @@ struct kgdb_io {
63619 void (*pre_exception) (void);
63620 void (*post_exception) (void);
63621 int is_console;
63622-};
63623+} __do_const;
63624
63625 extern struct kgdb_arch arch_kgdb_ops;
63626
63627diff --git a/include/linux/kmod.h b/include/linux/kmod.h
63628index 5398d58..5883a34 100644
63629--- a/include/linux/kmod.h
63630+++ b/include/linux/kmod.h
63631@@ -34,6 +34,8 @@ extern char modprobe_path[]; /* for sysctl */
63632 * usually useless though. */
63633 extern __printf(2, 3)
63634 int __request_module(bool wait, const char *name, ...);
63635+extern __printf(3, 4)
63636+int ___request_module(bool wait, char *param_name, const char *name, ...);
63637 #define request_module(mod...) __request_module(true, mod)
63638 #define request_module_nowait(mod...) __request_module(false, mod)
63639 #define try_then_request_module(x, mod...) \
63640diff --git a/include/linux/kref.h b/include/linux/kref.h
63641index 65af688..0592677 100644
63642--- a/include/linux/kref.h
63643+++ b/include/linux/kref.h
63644@@ -64,7 +64,7 @@ static inline void kref_get(struct kref *kref)
63645 static inline int kref_sub(struct kref *kref, unsigned int count,
63646 void (*release)(struct kref *kref))
63647 {
63648- WARN_ON(release == NULL);
63649+ BUG_ON(release == NULL);
63650
63651 if (atomic_sub_and_test((int) count, &kref->refcount)) {
63652 release(kref);
63653diff --git a/include/linux/kvm_host.h b/include/linux/kvm_host.h
63654index b70b48b..0d7153b 100644
63655--- a/include/linux/kvm_host.h
63656+++ b/include/linux/kvm_host.h
63657@@ -351,7 +351,7 @@ void kvm_vcpu_uninit(struct kvm_vcpu *vcpu);
63658 void vcpu_load(struct kvm_vcpu *vcpu);
63659 void vcpu_put(struct kvm_vcpu *vcpu);
63660
63661-int kvm_init(void *opaque, unsigned vcpu_size, unsigned vcpu_align,
63662+int kvm_init(const void *opaque, unsigned vcpu_size, unsigned vcpu_align,
63663 struct module *module);
63664 void kvm_exit(void);
63665
63666@@ -517,7 +517,7 @@ int kvm_arch_vcpu_ioctl_set_guest_debug(struct kvm_vcpu *vcpu,
63667 struct kvm_guest_debug *dbg);
63668 int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu, struct kvm_run *kvm_run);
63669
63670-int kvm_arch_init(void *opaque);
63671+int kvm_arch_init(const void *opaque);
63672 void kvm_arch_exit(void);
63673
63674 int kvm_arch_vcpu_init(struct kvm_vcpu *vcpu);
63675diff --git a/include/linux/libata.h b/include/linux/libata.h
63676index 64f90e1..32b945b 100644
63677--- a/include/linux/libata.h
63678+++ b/include/linux/libata.h
63679@@ -909,7 +909,7 @@ struct ata_port_operations {
63680 * fields must be pointers.
63681 */
63682 const struct ata_port_operations *inherits;
63683-};
63684+} __do_const;
63685
63686 struct ata_port_info {
63687 unsigned long flags;
63688diff --git a/include/linux/memory.h b/include/linux/memory.h
63689index ff9a9f8..c715deb 100644
63690--- a/include/linux/memory.h
63691+++ b/include/linux/memory.h
63692@@ -143,7 +143,7 @@ struct memory_accessor {
63693 size_t count);
63694 ssize_t (*write)(struct memory_accessor *, const char *buf,
63695 off_t offset, size_t count);
63696-};
63697+} __no_const;
63698
63699 /*
63700 * Kernel text modification mutex, used for code patching. Users of this lock
63701diff --git a/include/linux/mfd/abx500.h b/include/linux/mfd/abx500.h
63702index 1318ca6..7521340 100644
63703--- a/include/linux/mfd/abx500.h
63704+++ b/include/linux/mfd/abx500.h
63705@@ -452,6 +452,7 @@ struct abx500_ops {
63706 int (*event_registers_startup_state_get) (struct device *, u8 *);
63707 int (*startup_irq_enabled) (struct device *, unsigned int);
63708 };
63709+typedef struct abx500_ops __no_const abx500_ops_no_const;
63710
63711 int abx500_register_ops(struct device *core_dev, struct abx500_ops *ops);
63712 void abx500_remove_ops(struct device *dev);
63713diff --git a/include/linux/mfd/abx500/ux500_chargalg.h b/include/linux/mfd/abx500/ux500_chargalg.h
63714index 9b07725..3d55001 100644
63715--- a/include/linux/mfd/abx500/ux500_chargalg.h
63716+++ b/include/linux/mfd/abx500/ux500_chargalg.h
63717@@ -19,7 +19,7 @@ struct ux500_charger_ops {
63718 int (*enable) (struct ux500_charger *, int, int, int);
63719 int (*kick_wd) (struct ux500_charger *);
63720 int (*update_curr) (struct ux500_charger *, int);
63721-};
63722+} __no_const;
63723
63724 /**
63725 * struct ux500_charger - power supply ux500 charger sub class
63726diff --git a/include/linux/mm.h b/include/linux/mm.h
63727index 311be90..5f1638c 100644
63728--- a/include/linux/mm.h
63729+++ b/include/linux/mm.h
63730@@ -116,7 +116,14 @@ extern unsigned int kobjsize(const void *objp);
63731
63732 #define VM_CAN_NONLINEAR 0x08000000 /* Has ->fault & does nonlinear pages */
63733 #define VM_MIXEDMAP 0x10000000 /* Can contain "struct page" and pure PFN pages */
63734+
63735+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
63736+#define VM_SAO 0x00000000 /* Strong Access Ordering (powerpc) */
63737+#define VM_PAGEEXEC 0x20000000 /* vma->vm_page_prot needs special handling */
63738+#else
63739 #define VM_SAO 0x20000000 /* Strong Access Ordering (powerpc) */
63740+#endif
63741+
63742 #define VM_PFN_AT_MMAP 0x40000000 /* PFNMAP vma that is fully mapped at mmap time */
63743 #define VM_MERGEABLE 0x80000000 /* KSM may merge identical pages */
63744
63745@@ -1038,34 +1045,6 @@ int set_page_dirty(struct page *page);
63746 int set_page_dirty_lock(struct page *page);
63747 int clear_page_dirty_for_io(struct page *page);
63748
63749-/* Is the vma a continuation of the stack vma above it? */
63750-static inline int vma_growsdown(struct vm_area_struct *vma, unsigned long addr)
63751-{
63752- return vma && (vma->vm_end == addr) && (vma->vm_flags & VM_GROWSDOWN);
63753-}
63754-
63755-static inline int stack_guard_page_start(struct vm_area_struct *vma,
63756- unsigned long addr)
63757-{
63758- return (vma->vm_flags & VM_GROWSDOWN) &&
63759- (vma->vm_start == addr) &&
63760- !vma_growsdown(vma->vm_prev, addr);
63761-}
63762-
63763-/* Is the vma a continuation of the stack vma below it? */
63764-static inline int vma_growsup(struct vm_area_struct *vma, unsigned long addr)
63765-{
63766- return vma && (vma->vm_start == addr) && (vma->vm_flags & VM_GROWSUP);
63767-}
63768-
63769-static inline int stack_guard_page_end(struct vm_area_struct *vma,
63770- unsigned long addr)
63771-{
63772- return (vma->vm_flags & VM_GROWSUP) &&
63773- (vma->vm_end == addr) &&
63774- !vma_growsup(vma->vm_next, addr);
63775-}
63776-
63777 extern pid_t
63778 vm_is_stack(struct task_struct *task, struct vm_area_struct *vma, int in_group);
63779
63780@@ -1164,6 +1143,15 @@ static inline void sync_mm_rss(struct mm_struct *mm)
63781 }
63782 #endif
63783
63784+#ifdef CONFIG_MMU
63785+pgprot_t vm_get_page_prot(vm_flags_t vm_flags);
63786+#else
63787+static inline pgprot_t vm_get_page_prot(vm_flags_t vm_flags)
63788+{
63789+ return __pgprot(0);
63790+}
63791+#endif
63792+
63793 int vma_wants_writenotify(struct vm_area_struct *vma);
63794
63795 extern pte_t *__get_locked_pte(struct mm_struct *mm, unsigned long addr,
63796@@ -1182,8 +1170,15 @@ static inline int __pud_alloc(struct mm_struct *mm, pgd_t *pgd,
63797 {
63798 return 0;
63799 }
63800+
63801+static inline int __pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd,
63802+ unsigned long address)
63803+{
63804+ return 0;
63805+}
63806 #else
63807 int __pud_alloc(struct mm_struct *mm, pgd_t *pgd, unsigned long address);
63808+int __pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd, unsigned long address);
63809 #endif
63810
63811 #ifdef __PAGETABLE_PMD_FOLDED
63812@@ -1192,8 +1187,15 @@ static inline int __pmd_alloc(struct mm_struct *mm, pud_t *pud,
63813 {
63814 return 0;
63815 }
63816+
63817+static inline int __pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud,
63818+ unsigned long address)
63819+{
63820+ return 0;
63821+}
63822 #else
63823 int __pmd_alloc(struct mm_struct *mm, pud_t *pud, unsigned long address);
63824+int __pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud, unsigned long address);
63825 #endif
63826
63827 int __pte_alloc(struct mm_struct *mm, struct vm_area_struct *vma,
63828@@ -1211,11 +1213,23 @@ static inline pud_t *pud_alloc(struct mm_struct *mm, pgd_t *pgd, unsigned long a
63829 NULL: pud_offset(pgd, address);
63830 }
63831
63832+static inline pud_t *pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd, unsigned long address)
63833+{
63834+ return (unlikely(pgd_none(*pgd)) && __pud_alloc_kernel(mm, pgd, address))?
63835+ NULL: pud_offset(pgd, address);
63836+}
63837+
63838 static inline pmd_t *pmd_alloc(struct mm_struct *mm, pud_t *pud, unsigned long address)
63839 {
63840 return (unlikely(pud_none(*pud)) && __pmd_alloc(mm, pud, address))?
63841 NULL: pmd_offset(pud, address);
63842 }
63843+
63844+static inline pmd_t *pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud, unsigned long address)
63845+{
63846+ return (unlikely(pud_none(*pud)) && __pmd_alloc_kernel(mm, pud, address))?
63847+ NULL: pmd_offset(pud, address);
63848+}
63849 #endif /* CONFIG_MMU && !__ARCH_HAS_4LEVEL_HACK */
63850
63851 #if USE_SPLIT_PTLOCKS
63852@@ -1426,6 +1440,7 @@ extern unsigned long do_mmap_pgoff(struct file *, unsigned long,
63853 unsigned long, unsigned long,
63854 unsigned long, unsigned long);
63855 extern int do_munmap(struct mm_struct *, unsigned long, size_t);
63856+extern int __do_munmap(struct mm_struct *, unsigned long, size_t);
63857
63858 /* These take the mm semaphore themselves */
63859 extern unsigned long vm_brk(unsigned long, unsigned long);
63860@@ -1489,6 +1504,10 @@ extern struct vm_area_struct * find_vma(struct mm_struct * mm, unsigned long add
63861 extern struct vm_area_struct * find_vma_prev(struct mm_struct * mm, unsigned long addr,
63862 struct vm_area_struct **pprev);
63863
63864+extern struct vm_area_struct *pax_find_mirror_vma(struct vm_area_struct *vma);
63865+extern __must_check long pax_mirror_vma(struct vm_area_struct *vma_m, struct vm_area_struct *vma);
63866+extern void pax_mirror_file_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m, spinlock_t *ptl);
63867+
63868 /* Look up the first VMA which intersects the interval start_addr..end_addr-1,
63869 NULL if none. Assume start_addr < end_addr. */
63870 static inline struct vm_area_struct * find_vma_intersection(struct mm_struct * mm, unsigned long start_addr, unsigned long end_addr)
63871@@ -1517,15 +1536,6 @@ static inline struct vm_area_struct *find_exact_vma(struct mm_struct *mm,
63872 return vma;
63873 }
63874
63875-#ifdef CONFIG_MMU
63876-pgprot_t vm_get_page_prot(unsigned long vm_flags);
63877-#else
63878-static inline pgprot_t vm_get_page_prot(unsigned long vm_flags)
63879-{
63880- return __pgprot(0);
63881-}
63882-#endif
63883-
63884 struct vm_area_struct *find_extend_vma(struct mm_struct *, unsigned long addr);
63885 int remap_pfn_range(struct vm_area_struct *, unsigned long addr,
63886 unsigned long pfn, unsigned long size, pgprot_t);
63887@@ -1631,7 +1641,7 @@ extern int unpoison_memory(unsigned long pfn);
63888 extern int sysctl_memory_failure_early_kill;
63889 extern int sysctl_memory_failure_recovery;
63890 extern void shake_page(struct page *p, int access);
63891-extern atomic_long_t mce_bad_pages;
63892+extern atomic_long_unchecked_t mce_bad_pages;
63893 extern int soft_offline_page(struct page *page, int flags);
63894
63895 extern void dump_page(struct page *page);
63896@@ -1662,5 +1672,11 @@ static inline unsigned int debug_guardpage_minorder(void) { return 0; }
63897 static inline bool page_is_guard(struct page *page) { return false; }
63898 #endif /* CONFIG_DEBUG_PAGEALLOC */
63899
63900+#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
63901+extern void track_exec_limit(struct mm_struct *mm, unsigned long start, unsigned long end, unsigned long prot);
63902+#else
63903+static inline void track_exec_limit(struct mm_struct *mm, unsigned long start, unsigned long end, unsigned long prot) {}
63904+#endif
63905+
63906 #endif /* __KERNEL__ */
63907 #endif /* _LINUX_MM_H */
63908diff --git a/include/linux/mm_types.h b/include/linux/mm_types.h
63909index bf78672..debc693 100644
63910--- a/include/linux/mm_types.h
63911+++ b/include/linux/mm_types.h
63912@@ -279,6 +279,8 @@ struct vm_area_struct {
63913 #ifdef CONFIG_NUMA
63914 struct mempolicy *vm_policy; /* NUMA policy for the VMA */
63915 #endif
63916+
63917+ struct vm_area_struct *vm_mirror;/* PaX: mirror vma or NULL */
63918 };
63919
63920 struct core_thread {
63921@@ -353,7 +355,7 @@ struct mm_struct {
63922 unsigned long def_flags;
63923 unsigned long nr_ptes; /* Page table pages */
63924 unsigned long start_code, end_code, start_data, end_data;
63925- unsigned long start_brk, brk, start_stack;
63926+ unsigned long brk_gap, start_brk, brk, start_stack;
63927 unsigned long arg_start, arg_end, env_start, env_end;
63928
63929 unsigned long saved_auxv[AT_VECTOR_SIZE]; /* for /proc/PID/auxv */
63930@@ -405,6 +407,24 @@ struct mm_struct {
63931 struct cpumask cpumask_allocation;
63932 #endif
63933 struct uprobes_state uprobes_state;
63934+
63935+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
63936+ unsigned long pax_flags;
63937+#endif
63938+
63939+#ifdef CONFIG_PAX_DLRESOLVE
63940+ unsigned long call_dl_resolve;
63941+#endif
63942+
63943+#if defined(CONFIG_PPC32) && defined(CONFIG_PAX_EMUSIGRT)
63944+ unsigned long call_syscall;
63945+#endif
63946+
63947+#ifdef CONFIG_PAX_ASLR
63948+ unsigned long delta_mmap; /* randomized offset */
63949+ unsigned long delta_stack; /* randomized offset */
63950+#endif
63951+
63952 };
63953
63954 static inline void mm_init_cpumask(struct mm_struct *mm)
63955diff --git a/include/linux/mmu_notifier.h b/include/linux/mmu_notifier.h
63956index 1d1b1e1..2a13c78 100644
63957--- a/include/linux/mmu_notifier.h
63958+++ b/include/linux/mmu_notifier.h
63959@@ -255,12 +255,12 @@ static inline void mmu_notifier_mm_destroy(struct mm_struct *mm)
63960 */
63961 #define ptep_clear_flush_notify(__vma, __address, __ptep) \
63962 ({ \
63963- pte_t __pte; \
63964+ pte_t ___pte; \
63965 struct vm_area_struct *___vma = __vma; \
63966 unsigned long ___address = __address; \
63967- __pte = ptep_clear_flush(___vma, ___address, __ptep); \
63968+ ___pte = ptep_clear_flush(___vma, ___address, __ptep); \
63969 mmu_notifier_invalidate_page(___vma->vm_mm, ___address); \
63970- __pte; \
63971+ ___pte; \
63972 })
63973
63974 #define pmdp_clear_flush_notify(__vma, __address, __pmdp) \
63975diff --git a/include/linux/mmzone.h b/include/linux/mmzone.h
63976index a16d929..860ae00 100644
63977--- a/include/linux/mmzone.h
63978+++ b/include/linux/mmzone.h
63979@@ -414,7 +414,7 @@ struct zone {
63980 unsigned long flags; /* zone flags, see below */
63981
63982 /* Zone statistics */
63983- atomic_long_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
63984+ atomic_long_unchecked_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
63985
63986 /*
63987 * The target ratio of ACTIVE_ANON to INACTIVE_ANON pages on
63988diff --git a/include/linux/mod_devicetable.h b/include/linux/mod_devicetable.h
63989index 6955045..ebdb7cd 100644
63990--- a/include/linux/mod_devicetable.h
63991+++ b/include/linux/mod_devicetable.h
63992@@ -12,7 +12,7 @@
63993 typedef unsigned long kernel_ulong_t;
63994 #endif
63995
63996-#define PCI_ANY_ID (~0)
63997+#define PCI_ANY_ID ((__u16)~0)
63998
63999 struct pci_device_id {
64000 __u32 vendor, device; /* Vendor and device ID or PCI_ANY_ID*/
64001@@ -139,7 +139,7 @@ struct usb_device_id {
64002 #define USB_DEVICE_ID_MATCH_INT_PROTOCOL 0x0200
64003 #define USB_DEVICE_ID_MATCH_INT_NUMBER 0x0400
64004
64005-#define HID_ANY_ID (~0)
64006+#define HID_ANY_ID (~0U)
64007 #define HID_BUS_ANY 0xffff
64008 #define HID_GROUP_ANY 0x0000
64009
64010diff --git a/include/linux/module.h b/include/linux/module.h
64011index fbcafe2..e5d9587 100644
64012--- a/include/linux/module.h
64013+++ b/include/linux/module.h
64014@@ -17,6 +17,7 @@
64015 #include <linux/moduleparam.h>
64016 #include <linux/tracepoint.h>
64017 #include <linux/export.h>
64018+#include <linux/fs.h>
64019
64020 #include <linux/percpu.h>
64021 #include <asm/module.h>
64022@@ -273,19 +274,16 @@ struct module
64023 int (*init)(void);
64024
64025 /* If this is non-NULL, vfree after init() returns */
64026- void *module_init;
64027+ void *module_init_rx, *module_init_rw;
64028
64029 /* Here is the actual code + data, vfree'd on unload. */
64030- void *module_core;
64031+ void *module_core_rx, *module_core_rw;
64032
64033 /* Here are the sizes of the init and core sections */
64034- unsigned int init_size, core_size;
64035+ unsigned int init_size_rw, core_size_rw;
64036
64037 /* The size of the executable code in each section. */
64038- unsigned int init_text_size, core_text_size;
64039-
64040- /* Size of RO sections of the module (text+rodata) */
64041- unsigned int init_ro_size, core_ro_size;
64042+ unsigned int init_size_rx, core_size_rx;
64043
64044 /* Arch-specific module values */
64045 struct mod_arch_specific arch;
64046@@ -341,6 +339,10 @@ struct module
64047 #ifdef CONFIG_EVENT_TRACING
64048 struct ftrace_event_call **trace_events;
64049 unsigned int num_trace_events;
64050+ struct file_operations trace_id;
64051+ struct file_operations trace_enable;
64052+ struct file_operations trace_format;
64053+ struct file_operations trace_filter;
64054 #endif
64055 #ifdef CONFIG_FTRACE_MCOUNT_RECORD
64056 unsigned int num_ftrace_callsites;
64057@@ -388,16 +390,46 @@ bool is_module_address(unsigned long addr);
64058 bool is_module_percpu_address(unsigned long addr);
64059 bool is_module_text_address(unsigned long addr);
64060
64061+static inline int within_module_range(unsigned long addr, void *start, unsigned long size)
64062+{
64063+
64064+#ifdef CONFIG_PAX_KERNEXEC
64065+ if (ktla_ktva(addr) >= (unsigned long)start &&
64066+ ktla_ktva(addr) < (unsigned long)start + size)
64067+ return 1;
64068+#endif
64069+
64070+ return ((void *)addr >= start && (void *)addr < start + size);
64071+}
64072+
64073+static inline int within_module_core_rx(unsigned long addr, struct module *mod)
64074+{
64075+ return within_module_range(addr, mod->module_core_rx, mod->core_size_rx);
64076+}
64077+
64078+static inline int within_module_core_rw(unsigned long addr, struct module *mod)
64079+{
64080+ return within_module_range(addr, mod->module_core_rw, mod->core_size_rw);
64081+}
64082+
64083+static inline int within_module_init_rx(unsigned long addr, struct module *mod)
64084+{
64085+ return within_module_range(addr, mod->module_init_rx, mod->init_size_rx);
64086+}
64087+
64088+static inline int within_module_init_rw(unsigned long addr, struct module *mod)
64089+{
64090+ return within_module_range(addr, mod->module_init_rw, mod->init_size_rw);
64091+}
64092+
64093 static inline int within_module_core(unsigned long addr, struct module *mod)
64094 {
64095- return (unsigned long)mod->module_core <= addr &&
64096- addr < (unsigned long)mod->module_core + mod->core_size;
64097+ return within_module_core_rx(addr, mod) || within_module_core_rw(addr, mod);
64098 }
64099
64100 static inline int within_module_init(unsigned long addr, struct module *mod)
64101 {
64102- return (unsigned long)mod->module_init <= addr &&
64103- addr < (unsigned long)mod->module_init + mod->init_size;
64104+ return within_module_init_rx(addr, mod) || within_module_init_rw(addr, mod);
64105 }
64106
64107 /* Search for module by name: must hold module_mutex. */
64108diff --git a/include/linux/moduleloader.h b/include/linux/moduleloader.h
64109index b2be02e..72d2f78 100644
64110--- a/include/linux/moduleloader.h
64111+++ b/include/linux/moduleloader.h
64112@@ -23,11 +23,23 @@ unsigned int arch_mod_section_prepend(struct module *mod, unsigned int section);
64113
64114 /* Allocator used for allocating struct module, core sections and init
64115 sections. Returns NULL on failure. */
64116-void *module_alloc(unsigned long size);
64117+void *module_alloc(unsigned long size) __size_overflow(1);
64118+
64119+#ifdef CONFIG_PAX_KERNEXEC
64120+void *module_alloc_exec(unsigned long size) __size_overflow(1);
64121+#else
64122+#define module_alloc_exec(x) module_alloc(x)
64123+#endif
64124
64125 /* Free memory returned from module_alloc. */
64126 void module_free(struct module *mod, void *module_region);
64127
64128+#ifdef CONFIG_PAX_KERNEXEC
64129+void module_free_exec(struct module *mod, void *module_region);
64130+#else
64131+#define module_free_exec(x, y) module_free((x), (y))
64132+#endif
64133+
64134 /* Apply the given relocation to the (simplified) ELF. Return -error
64135 or 0. */
64136 int apply_relocate(Elf_Shdr *sechdrs,
64137diff --git a/include/linux/moduleparam.h b/include/linux/moduleparam.h
64138index d6a5806..7c13347 100644
64139--- a/include/linux/moduleparam.h
64140+++ b/include/linux/moduleparam.h
64141@@ -286,7 +286,7 @@ static inline void __kernel_param_unlock(void)
64142 * @len is usually just sizeof(string).
64143 */
64144 #define module_param_string(name, string, len, perm) \
64145- static const struct kparam_string __param_string_##name \
64146+ static const struct kparam_string __param_string_##name __used \
64147 = { len, string }; \
64148 __module_param_call(MODULE_PARAM_PREFIX, name, \
64149 &param_ops_string, \
64150@@ -425,7 +425,7 @@ extern int param_set_bint(const char *val, const struct kernel_param *kp);
64151 */
64152 #define module_param_array_named(name, array, type, nump, perm) \
64153 param_check_##type(name, &(array)[0]); \
64154- static const struct kparam_array __param_arr_##name \
64155+ static const struct kparam_array __param_arr_##name __used \
64156 = { .max = ARRAY_SIZE(array), .num = nump, \
64157 .ops = &param_ops_##type, \
64158 .elemsize = sizeof(array[0]), .elem = array }; \
64159diff --git a/include/linux/namei.h b/include/linux/namei.h
64160index 4bf19d8..5268cea 100644
64161--- a/include/linux/namei.h
64162+++ b/include/linux/namei.h
64163@@ -18,7 +18,7 @@ struct nameidata {
64164 unsigned seq;
64165 int last_type;
64166 unsigned depth;
64167- char *saved_names[MAX_NESTED_LINKS + 1];
64168+ const char *saved_names[MAX_NESTED_LINKS + 1];
64169 };
64170
64171 /*
64172@@ -83,12 +83,12 @@ extern void unlock_rename(struct dentry *, struct dentry *);
64173
64174 extern void nd_jump_link(struct nameidata *nd, struct path *path);
64175
64176-static inline void nd_set_link(struct nameidata *nd, char *path)
64177+static inline void nd_set_link(struct nameidata *nd, const char *path)
64178 {
64179 nd->saved_names[nd->depth] = path;
64180 }
64181
64182-static inline char *nd_get_link(struct nameidata *nd)
64183+static inline const char *nd_get_link(const struct nameidata *nd)
64184 {
64185 return nd->saved_names[nd->depth];
64186 }
64187diff --git a/include/linux/netdevice.h b/include/linux/netdevice.h
64188index 59dc05f3..c905a34 100644
64189--- a/include/linux/netdevice.h
64190+++ b/include/linux/netdevice.h
64191@@ -1027,6 +1027,7 @@ struct net_device_ops {
64192 struct net_device *dev,
64193 int idx);
64194 };
64195+typedef struct net_device_ops __no_const net_device_ops_no_const;
64196
64197 /*
64198 * The DEVICE structure.
64199@@ -1087,7 +1088,7 @@ struct net_device {
64200 int iflink;
64201
64202 struct net_device_stats stats;
64203- atomic_long_t rx_dropped; /* dropped packets by core network
64204+ atomic_long_unchecked_t rx_dropped; /* dropped packets by core network
64205 * Do not use this in drivers.
64206 */
64207
64208diff --git a/include/linux/netfilter/xt_gradm.h b/include/linux/netfilter/xt_gradm.h
64209new file mode 100644
64210index 0000000..33f4af8
64211--- /dev/null
64212+++ b/include/linux/netfilter/xt_gradm.h
64213@@ -0,0 +1,9 @@
64214+#ifndef _LINUX_NETFILTER_XT_GRADM_H
64215+#define _LINUX_NETFILTER_XT_GRADM_H 1
64216+
64217+struct xt_gradm_mtinfo {
64218+ __u16 flags;
64219+ __u16 invflags;
64220+};
64221+
64222+#endif
64223diff --git a/include/linux/of_pdt.h b/include/linux/of_pdt.h
64224index c65a18a..0c05f3a 100644
64225--- a/include/linux/of_pdt.h
64226+++ b/include/linux/of_pdt.h
64227@@ -32,7 +32,7 @@ struct of_pdt_ops {
64228
64229 /* return 0 on success; fill in 'len' with number of bytes in path */
64230 int (*pkg2path)(phandle node, char *buf, const int buflen, int *len);
64231-};
64232+} __no_const;
64233
64234 extern void *prom_early_alloc(unsigned long size);
64235
64236diff --git a/include/linux/oprofile.h b/include/linux/oprofile.h
64237index a4c5624..79d6d88 100644
64238--- a/include/linux/oprofile.h
64239+++ b/include/linux/oprofile.h
64240@@ -139,9 +139,9 @@ int oprofilefs_create_ulong(struct super_block * sb, struct dentry * root,
64241 int oprofilefs_create_ro_ulong(struct super_block * sb, struct dentry * root,
64242 char const * name, ulong * val);
64243
64244-/** Create a file for read-only access to an atomic_t. */
64245+/** Create a file for read-only access to an atomic_unchecked_t. */
64246 int oprofilefs_create_ro_atomic(struct super_block * sb, struct dentry * root,
64247- char const * name, atomic_t * val);
64248+ char const * name, atomic_unchecked_t * val);
64249
64250 /** create a directory */
64251 struct dentry * oprofilefs_mkdir(struct super_block * sb, struct dentry * root,
64252diff --git a/include/linux/perf_event.h b/include/linux/perf_event.h
64253index bdb4161..f373d41 100644
64254--- a/include/linux/perf_event.h
64255+++ b/include/linux/perf_event.h
64256@@ -882,8 +882,8 @@ struct perf_event {
64257
64258 enum perf_event_active_state state;
64259 unsigned int attach_state;
64260- local64_t count;
64261- atomic64_t child_count;
64262+ local64_t count; /* PaX: fix it one day */
64263+ atomic64_unchecked_t child_count;
64264
64265 /*
64266 * These are the total time in nanoseconds that the event
64267@@ -934,8 +934,8 @@ struct perf_event {
64268 * These accumulate total time (in nanoseconds) that children
64269 * events have been enabled and running, respectively.
64270 */
64271- atomic64_t child_total_time_enabled;
64272- atomic64_t child_total_time_running;
64273+ atomic64_unchecked_t child_total_time_enabled;
64274+ atomic64_unchecked_t child_total_time_running;
64275
64276 /*
64277 * Protect attach/detach and child_list:
64278diff --git a/include/linux/personality.h b/include/linux/personality.h
64279index 8fc7dd1a..c19d89e 100644
64280--- a/include/linux/personality.h
64281+++ b/include/linux/personality.h
64282@@ -44,6 +44,7 @@ enum {
64283 #define PER_CLEAR_ON_SETID (READ_IMPLIES_EXEC | \
64284 ADDR_NO_RANDOMIZE | \
64285 ADDR_COMPAT_LAYOUT | \
64286+ ADDR_LIMIT_3GB | \
64287 MMAP_PAGE_ZERO)
64288
64289 /*
64290diff --git a/include/linux/pipe_fs_i.h b/include/linux/pipe_fs_i.h
64291index ad1a427..6419649 100644
64292--- a/include/linux/pipe_fs_i.h
64293+++ b/include/linux/pipe_fs_i.h
64294@@ -45,9 +45,9 @@ struct pipe_buffer {
64295 struct pipe_inode_info {
64296 wait_queue_head_t wait;
64297 unsigned int nrbufs, curbuf, buffers;
64298- unsigned int readers;
64299- unsigned int writers;
64300- unsigned int waiting_writers;
64301+ atomic_t readers;
64302+ atomic_t writers;
64303+ atomic_t waiting_writers;
64304 unsigned int r_counter;
64305 unsigned int w_counter;
64306 struct page *tmp_page;
64307diff --git a/include/linux/pm_runtime.h b/include/linux/pm_runtime.h
64308index f271860..6b3bec5 100644
64309--- a/include/linux/pm_runtime.h
64310+++ b/include/linux/pm_runtime.h
64311@@ -97,7 +97,7 @@ static inline bool pm_runtime_callbacks_present(struct device *dev)
64312
64313 static inline void pm_runtime_mark_last_busy(struct device *dev)
64314 {
64315- ACCESS_ONCE(dev->power.last_busy) = jiffies;
64316+ ACCESS_ONCE_RW(dev->power.last_busy) = jiffies;
64317 }
64318
64319 #else /* !CONFIG_PM_RUNTIME */
64320diff --git a/include/linux/poison.h b/include/linux/poison.h
64321index 2110a81..13a11bb 100644
64322--- a/include/linux/poison.h
64323+++ b/include/linux/poison.h
64324@@ -19,8 +19,8 @@
64325 * under normal circumstances, used to verify that nobody uses
64326 * non-initialized list entries.
64327 */
64328-#define LIST_POISON1 ((void *) 0x00100100 + POISON_POINTER_DELTA)
64329-#define LIST_POISON2 ((void *) 0x00200200 + POISON_POINTER_DELTA)
64330+#define LIST_POISON1 ((void *) (long)0xFFFFFF01)
64331+#define LIST_POISON2 ((void *) (long)0xFFFFFF02)
64332
64333 /********** include/linux/timer.h **********/
64334 /*
64335diff --git a/include/linux/preempt.h b/include/linux/preempt.h
64336index 5a710b9..0b0dab9 100644
64337--- a/include/linux/preempt.h
64338+++ b/include/linux/preempt.h
64339@@ -126,7 +126,7 @@ struct preempt_ops {
64340 void (*sched_in)(struct preempt_notifier *notifier, int cpu);
64341 void (*sched_out)(struct preempt_notifier *notifier,
64342 struct task_struct *next);
64343-};
64344+} __no_const;
64345
64346 /**
64347 * preempt_notifier - key for installing preemption notifiers
64348diff --git a/include/linux/printk.h b/include/linux/printk.h
64349index 9afc01e..92c32e8 100644
64350--- a/include/linux/printk.h
64351+++ b/include/linux/printk.h
64352@@ -101,6 +101,8 @@ void early_printk(const char *fmt, ...);
64353 extern int printk_needs_cpu(int cpu);
64354 extern void printk_tick(void);
64355
64356+extern int kptr_restrict;
64357+
64358 #ifdef CONFIG_PRINTK
64359 asmlinkage __printf(5, 0)
64360 int vprintk_emit(int facility, int level,
64361@@ -135,7 +137,6 @@ extern bool printk_timed_ratelimit(unsigned long *caller_jiffies,
64362
64363 extern int printk_delay_msec;
64364 extern int dmesg_restrict;
64365-extern int kptr_restrict;
64366
64367 void log_buf_kexec_setup(void);
64368 void __init setup_log_buf(int early);
64369diff --git a/include/linux/proc_fs.h b/include/linux/proc_fs.h
64370index 3fd2e87..d93a721 100644
64371--- a/include/linux/proc_fs.h
64372+++ b/include/linux/proc_fs.h
64373@@ -155,6 +155,18 @@ static inline struct proc_dir_entry *proc_create(const char *name, umode_t mode,
64374 return proc_create_data(name, mode, parent, proc_fops, NULL);
64375 }
64376
64377+static inline struct proc_dir_entry *proc_create_grsec(const char *name, umode_t mode,
64378+ struct proc_dir_entry *parent, const struct file_operations *proc_fops)
64379+{
64380+#ifdef CONFIG_GRKERNSEC_PROC_USER
64381+ return proc_create_data(name, S_IRUSR, parent, proc_fops, NULL);
64382+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
64383+ return proc_create_data(name, S_IRUSR | S_IRGRP, parent, proc_fops, NULL);
64384+#else
64385+ return proc_create_data(name, mode, parent, proc_fops, NULL);
64386+#endif
64387+}
64388+
64389 static inline struct proc_dir_entry *create_proc_read_entry(const char *name,
64390 umode_t mode, struct proc_dir_entry *base,
64391 read_proc_t *read_proc, void * data)
64392@@ -258,7 +270,7 @@ union proc_op {
64393 int (*proc_show)(struct seq_file *m,
64394 struct pid_namespace *ns, struct pid *pid,
64395 struct task_struct *task);
64396-};
64397+} __no_const;
64398
64399 struct ctl_table_header;
64400 struct ctl_table;
64401diff --git a/include/linux/random.h b/include/linux/random.h
64402index ac621ce..c1215f3 100644
64403--- a/include/linux/random.h
64404+++ b/include/linux/random.h
64405@@ -53,6 +53,10 @@ extern void add_input_randomness(unsigned int type, unsigned int code,
64406 unsigned int value);
64407 extern void add_interrupt_randomness(int irq, int irq_flags);
64408
64409+#ifdef CONFIG_PAX_LATENT_ENTROPY
64410+extern void transfer_latent_entropy(void);
64411+#endif
64412+
64413 extern void get_random_bytes(void *buf, int nbytes);
64414 extern void get_random_bytes_arch(void *buf, int nbytes);
64415 void generate_random_uuid(unsigned char uuid_out[16]);
64416@@ -69,12 +73,17 @@ void srandom32(u32 seed);
64417
64418 u32 prandom32(struct rnd_state *);
64419
64420+static inline unsigned long pax_get_random_long(void)
64421+{
64422+ return random32() + (sizeof(long) > 4 ? (unsigned long)random32() << 32 : 0);
64423+}
64424+
64425 /*
64426 * Handle minimum values for seeds
64427 */
64428 static inline u32 __seed(u32 x, u32 m)
64429 {
64430- return (x < m) ? x + m : x;
64431+ return (x <= m) ? x + m + 1 : x;
64432 }
64433
64434 /**
64435diff --git a/include/linux/reboot.h b/include/linux/reboot.h
64436index e0879a7..a12f962 100644
64437--- a/include/linux/reboot.h
64438+++ b/include/linux/reboot.h
64439@@ -52,9 +52,9 @@ extern int unregister_reboot_notifier(struct notifier_block *);
64440 * Architecture-specific implementations of sys_reboot commands.
64441 */
64442
64443-extern void machine_restart(char *cmd);
64444-extern void machine_halt(void);
64445-extern void machine_power_off(void);
64446+extern void machine_restart(char *cmd) __noreturn;
64447+extern void machine_halt(void) __noreturn;
64448+extern void machine_power_off(void) __noreturn;
64449
64450 extern void machine_shutdown(void);
64451 struct pt_regs;
64452@@ -65,9 +65,9 @@ extern void machine_crash_shutdown(struct pt_regs *);
64453 */
64454
64455 extern void kernel_restart_prepare(char *cmd);
64456-extern void kernel_restart(char *cmd);
64457-extern void kernel_halt(void);
64458-extern void kernel_power_off(void);
64459+extern void kernel_restart(char *cmd) __noreturn;
64460+extern void kernel_halt(void) __noreturn;
64461+extern void kernel_power_off(void) __noreturn;
64462
64463 extern int C_A_D; /* for sysctl */
64464 void ctrl_alt_del(void);
64465@@ -81,7 +81,7 @@ extern int orderly_poweroff(bool force);
64466 * Emergency restart, callable from an interrupt handler.
64467 */
64468
64469-extern void emergency_restart(void);
64470+extern void emergency_restart(void) __noreturn;
64471 #include <asm/emergency-restart.h>
64472
64473 #endif
64474diff --git a/include/linux/relay.h b/include/linux/relay.h
64475index 91cacc3..b55ff74 100644
64476--- a/include/linux/relay.h
64477+++ b/include/linux/relay.h
64478@@ -160,7 +160,7 @@ struct rchan_callbacks
64479 * The callback should return 0 if successful, negative if not.
64480 */
64481 int (*remove_buf_file)(struct dentry *dentry);
64482-};
64483+} __no_const;
64484
64485 /*
64486 * CONFIG_RELAY kernel API, kernel/relay.c
64487diff --git a/include/linux/rfkill.h b/include/linux/rfkill.h
64488index 6fdf027..ff72610 100644
64489--- a/include/linux/rfkill.h
64490+++ b/include/linux/rfkill.h
64491@@ -147,6 +147,7 @@ struct rfkill_ops {
64492 void (*query)(struct rfkill *rfkill, void *data);
64493 int (*set_block)(void *data, bool blocked);
64494 };
64495+typedef struct rfkill_ops __no_const rfkill_ops_no_const;
64496
64497 #if defined(CONFIG_RFKILL) || defined(CONFIG_RFKILL_MODULE)
64498 /**
64499diff --git a/include/linux/rio.h b/include/linux/rio.h
64500index a90ebad..fd87b5d 100644
64501--- a/include/linux/rio.h
64502+++ b/include/linux/rio.h
64503@@ -321,7 +321,7 @@ struct rio_ops {
64504 int mbox, void *buffer, size_t len);
64505 int (*add_inb_buffer)(struct rio_mport *mport, int mbox, void *buf);
64506 void *(*get_inb_message)(struct rio_mport *mport, int mbox);
64507-};
64508+} __no_const;
64509
64510 #define RIO_RESOURCE_MEM 0x00000100
64511 #define RIO_RESOURCE_DOORBELL 0x00000200
64512diff --git a/include/linux/rmap.h b/include/linux/rmap.h
64513index 3fce545..b4fed6e 100644
64514--- a/include/linux/rmap.h
64515+++ b/include/linux/rmap.h
64516@@ -119,9 +119,9 @@ static inline void anon_vma_unlock(struct anon_vma *anon_vma)
64517 void anon_vma_init(void); /* create anon_vma_cachep */
64518 int anon_vma_prepare(struct vm_area_struct *);
64519 void unlink_anon_vmas(struct vm_area_struct *);
64520-int anon_vma_clone(struct vm_area_struct *, struct vm_area_struct *);
64521+int anon_vma_clone(struct vm_area_struct *, const struct vm_area_struct *);
64522 void anon_vma_moveto_tail(struct vm_area_struct *);
64523-int anon_vma_fork(struct vm_area_struct *, struct vm_area_struct *);
64524+int anon_vma_fork(struct vm_area_struct *, const struct vm_area_struct *);
64525
64526 static inline void anon_vma_merge(struct vm_area_struct *vma,
64527 struct vm_area_struct *next)
64528diff --git a/include/linux/sched.h b/include/linux/sched.h
64529index 23bddac..5976055 100644
64530--- a/include/linux/sched.h
64531+++ b/include/linux/sched.h
64532@@ -101,6 +101,7 @@ struct bio_list;
64533 struct fs_struct;
64534 struct perf_event_context;
64535 struct blk_plug;
64536+struct linux_binprm;
64537
64538 /*
64539 * List of flags we want to share for kernel threads,
64540@@ -384,10 +385,13 @@ struct user_namespace;
64541 #define DEFAULT_MAX_MAP_COUNT (USHRT_MAX - MAPCOUNT_ELF_CORE_MARGIN)
64542
64543 extern int sysctl_max_map_count;
64544+extern unsigned long sysctl_heap_stack_gap;
64545
64546 #include <linux/aio.h>
64547
64548 #ifdef CONFIG_MMU
64549+extern bool check_heap_stack_gap(const struct vm_area_struct *vma, unsigned long addr, unsigned long len);
64550+extern unsigned long skip_heap_stack_gap(const struct vm_area_struct *vma, unsigned long len);
64551 extern void arch_pick_mmap_layout(struct mm_struct *mm);
64552 extern unsigned long
64553 arch_get_unmapped_area(struct file *, unsigned long, unsigned long,
64554@@ -651,6 +655,17 @@ struct signal_struct {
64555 #ifdef CONFIG_TASKSTATS
64556 struct taskstats *stats;
64557 #endif
64558+
64559+#ifdef CONFIG_GRKERNSEC
64560+ u32 curr_ip;
64561+ u32 saved_ip;
64562+ u32 gr_saddr;
64563+ u32 gr_daddr;
64564+ u16 gr_sport;
64565+ u16 gr_dport;
64566+ u8 used_accept:1;
64567+#endif
64568+
64569 #ifdef CONFIG_AUDIT
64570 unsigned audit_tty;
64571 struct tty_audit_buf *tty_audit_buf;
64572@@ -734,6 +749,11 @@ struct user_struct {
64573 struct key *session_keyring; /* UID's default session keyring */
64574 #endif
64575
64576+#if defined(CONFIG_GRKERNSEC_KERN_LOCKOUT) || defined(CONFIG_GRKERNSEC_BRUTE)
64577+ unsigned int banned;
64578+ unsigned long ban_expires;
64579+#endif
64580+
64581 /* Hash table maintenance information */
64582 struct hlist_node uidhash_node;
64583 kuid_t uid;
64584@@ -1356,8 +1376,8 @@ struct task_struct {
64585 struct list_head thread_group;
64586
64587 struct completion *vfork_done; /* for vfork() */
64588- int __user *set_child_tid; /* CLONE_CHILD_SETTID */
64589- int __user *clear_child_tid; /* CLONE_CHILD_CLEARTID */
64590+ pid_t __user *set_child_tid; /* CLONE_CHILD_SETTID */
64591+ pid_t __user *clear_child_tid; /* CLONE_CHILD_CLEARTID */
64592
64593 cputime_t utime, stime, utimescaled, stimescaled;
64594 cputime_t gtime;
64595@@ -1373,11 +1393,6 @@ struct task_struct {
64596 struct task_cputime cputime_expires;
64597 struct list_head cpu_timers[3];
64598
64599-/* process credentials */
64600- const struct cred __rcu *real_cred; /* objective and real subjective task
64601- * credentials (COW) */
64602- const struct cred __rcu *cred; /* effective (overridable) subjective task
64603- * credentials (COW) */
64604 char comm[TASK_COMM_LEN]; /* executable name excluding path
64605 - access with [gs]et_task_comm (which lock
64606 it with task_lock())
64607@@ -1394,6 +1409,10 @@ struct task_struct {
64608 #endif
64609 /* CPU-specific state of this task */
64610 struct thread_struct thread;
64611+/* thread_info moved to task_struct */
64612+#ifdef CONFIG_X86
64613+ struct thread_info tinfo;
64614+#endif
64615 /* filesystem information */
64616 struct fs_struct *fs;
64617 /* open file information */
64618@@ -1467,6 +1486,10 @@ struct task_struct {
64619 gfp_t lockdep_reclaim_gfp;
64620 #endif
64621
64622+/* process credentials */
64623+ const struct cred __rcu *real_cred; /* objective and real subjective task
64624+ * credentials (COW) */
64625+
64626 /* journalling filesystem info */
64627 void *journal_info;
64628
64629@@ -1505,6 +1528,10 @@ struct task_struct {
64630 /* cg_list protected by css_set_lock and tsk->alloc_lock */
64631 struct list_head cg_list;
64632 #endif
64633+
64634+ const struct cred __rcu *cred; /* effective (overridable) subjective task
64635+ * credentials (COW) */
64636+
64637 #ifdef CONFIG_FUTEX
64638 struct robust_list_head __user *robust_list;
64639 #ifdef CONFIG_COMPAT
64640@@ -1589,8 +1616,74 @@ struct task_struct {
64641 #ifdef CONFIG_UPROBES
64642 struct uprobe_task *utask;
64643 #endif
64644+
64645+#ifdef CONFIG_GRKERNSEC
64646+ /* grsecurity */
64647+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
64648+ u64 exec_id;
64649+#endif
64650+#ifdef CONFIG_GRKERNSEC_SETXID
64651+ const struct cred *delayed_cred;
64652+#endif
64653+ struct dentry *gr_chroot_dentry;
64654+ struct acl_subject_label *acl;
64655+ struct acl_role_label *role;
64656+ struct file *exec_file;
64657+ u16 acl_role_id;
64658+ /* is this the task that authenticated to the special role */
64659+ u8 acl_sp_role;
64660+ u8 is_writable;
64661+ u8 brute;
64662+ u8 gr_is_chrooted;
64663+#endif
64664+
64665 };
64666
64667+#define MF_PAX_PAGEEXEC 0x01000000 /* Paging based non-executable pages */
64668+#define MF_PAX_EMUTRAMP 0x02000000 /* Emulate trampolines */
64669+#define MF_PAX_MPROTECT 0x04000000 /* Restrict mprotect() */
64670+#define MF_PAX_RANDMMAP 0x08000000 /* Randomize mmap() base */
64671+/*#define MF_PAX_RANDEXEC 0x10000000*/ /* Randomize ET_EXEC base */
64672+#define MF_PAX_SEGMEXEC 0x20000000 /* Segmentation based non-executable pages */
64673+
64674+#ifdef CONFIG_PAX_SOFTMODE
64675+extern int pax_softmode;
64676+#endif
64677+
64678+extern int pax_check_flags(unsigned long *);
64679+
64680+/* if tsk != current then task_lock must be held on it */
64681+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
64682+static inline unsigned long pax_get_flags(struct task_struct *tsk)
64683+{
64684+ if (likely(tsk->mm))
64685+ return tsk->mm->pax_flags;
64686+ else
64687+ return 0UL;
64688+}
64689+
64690+/* if tsk != current then task_lock must be held on it */
64691+static inline long pax_set_flags(struct task_struct *tsk, unsigned long flags)
64692+{
64693+ if (likely(tsk->mm)) {
64694+ tsk->mm->pax_flags = flags;
64695+ return 0;
64696+ }
64697+ return -EINVAL;
64698+}
64699+#endif
64700+
64701+#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
64702+extern void pax_set_initial_flags(struct linux_binprm *bprm);
64703+#elif defined(CONFIG_PAX_HOOK_ACL_FLAGS)
64704+extern void (*pax_set_initial_flags_func)(struct linux_binprm *bprm);
64705+#endif
64706+
64707+extern void pax_report_fault(struct pt_regs *regs, void *pc, void *sp);
64708+extern void pax_report_insns(struct pt_regs *regs, void *pc, void *sp);
64709+extern void pax_report_refcount_overflow(struct pt_regs *regs);
64710+extern void check_object_size(const void *ptr, unsigned long n, bool to);
64711+
64712 /* Future-safe accessor for struct task_struct's cpus_allowed. */
64713 #define tsk_cpus_allowed(tsk) (&(tsk)->cpus_allowed)
64714
64715@@ -2125,7 +2218,9 @@ void yield(void);
64716 extern struct exec_domain default_exec_domain;
64717
64718 union thread_union {
64719+#ifndef CONFIG_X86
64720 struct thread_info thread_info;
64721+#endif
64722 unsigned long stack[THREAD_SIZE/sizeof(long)];
64723 };
64724
64725@@ -2158,6 +2253,7 @@ extern struct pid_namespace init_pid_ns;
64726 */
64727
64728 extern struct task_struct *find_task_by_vpid(pid_t nr);
64729+extern struct task_struct *find_task_by_vpid_unrestricted(pid_t nr);
64730 extern struct task_struct *find_task_by_pid_ns(pid_t nr,
64731 struct pid_namespace *ns);
64732
64733@@ -2314,7 +2410,7 @@ extern void __cleanup_sighand(struct sighand_struct *);
64734 extern void exit_itimers(struct signal_struct *);
64735 extern void flush_itimer_signals(void);
64736
64737-extern void do_group_exit(int);
64738+extern __noreturn void do_group_exit(int);
64739
64740 extern void daemonize(const char *, ...);
64741 extern int allow_signal(int);
64742@@ -2515,9 +2611,9 @@ static inline unsigned long *end_of_stack(struct task_struct *p)
64743
64744 #endif
64745
64746-static inline int object_is_on_stack(void *obj)
64747+static inline int object_starts_on_stack(void *obj)
64748 {
64749- void *stack = task_stack_page(current);
64750+ const void *stack = task_stack_page(current);
64751
64752 return (obj >= stack) && (obj < (stack + THREAD_SIZE));
64753 }
64754diff --git a/include/linux/screen_info.h b/include/linux/screen_info.h
64755index 899fbb4..1cb4138 100644
64756--- a/include/linux/screen_info.h
64757+++ b/include/linux/screen_info.h
64758@@ -43,7 +43,8 @@ struct screen_info {
64759 __u16 pages; /* 0x32 */
64760 __u16 vesa_attributes; /* 0x34 */
64761 __u32 capabilities; /* 0x36 */
64762- __u8 _reserved[6]; /* 0x3a */
64763+ __u16 vesapm_size; /* 0x3a */
64764+ __u8 _reserved[4]; /* 0x3c */
64765 } __attribute__((packed));
64766
64767 #define VIDEO_TYPE_MDA 0x10 /* Monochrome Text Display */
64768diff --git a/include/linux/security.h b/include/linux/security.h
64769index d143b8e..9f27b95 100644
64770--- a/include/linux/security.h
64771+++ b/include/linux/security.h
64772@@ -26,6 +26,7 @@
64773 #include <linux/capability.h>
64774 #include <linux/slab.h>
64775 #include <linux/err.h>
64776+#include <linux/grsecurity.h>
64777
64778 struct linux_binprm;
64779 struct cred;
64780diff --git a/include/linux/seq_file.h b/include/linux/seq_file.h
64781index 83c44ee..e8a9eba 100644
64782--- a/include/linux/seq_file.h
64783+++ b/include/linux/seq_file.h
64784@@ -25,6 +25,9 @@ struct seq_file {
64785 struct mutex lock;
64786 const struct seq_operations *op;
64787 int poll_event;
64788+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
64789+ u64 exec_id;
64790+#endif
64791 void *private;
64792 };
64793
64794@@ -34,6 +37,7 @@ struct seq_operations {
64795 void * (*next) (struct seq_file *m, void *v, loff_t *pos);
64796 int (*show) (struct seq_file *m, void *v);
64797 };
64798+typedef struct seq_operations __no_const seq_operations_no_const;
64799
64800 #define SEQ_SKIP 1
64801
64802diff --git a/include/linux/shm.h b/include/linux/shm.h
64803index edd0868..f98feee 100644
64804--- a/include/linux/shm.h
64805+++ b/include/linux/shm.h
64806@@ -98,6 +98,10 @@ struct shmid_kernel /* private to the kernel */
64807
64808 /* The task created the shm object. NULL if the task is dead. */
64809 struct task_struct *shm_creator;
64810+#ifdef CONFIG_GRKERNSEC
64811+ time_t shm_createtime;
64812+ pid_t shm_lapid;
64813+#endif
64814 };
64815
64816 /* shm_mode upper byte flags */
64817diff --git a/include/linux/skbuff.h b/include/linux/skbuff.h
64818index f3165d2..2cb3cb7 100644
64819--- a/include/linux/skbuff.h
64820+++ b/include/linux/skbuff.h
64821@@ -577,7 +577,7 @@ extern bool skb_try_coalesce(struct sk_buff *to, struct sk_buff *from,
64822 extern struct sk_buff *__alloc_skb(unsigned int size,
64823 gfp_t priority, int flags, int node);
64824 extern struct sk_buff *build_skb(void *data, unsigned int frag_size);
64825-static inline struct sk_buff *alloc_skb(unsigned int size,
64826+static inline struct sk_buff * __intentional_overflow(0) alloc_skb(unsigned int size,
64827 gfp_t priority)
64828 {
64829 return __alloc_skb(size, priority, 0, NUMA_NO_NODE);
64830@@ -687,7 +687,7 @@ static inline struct skb_shared_hwtstamps *skb_hwtstamps(struct sk_buff *skb)
64831 */
64832 static inline int skb_queue_empty(const struct sk_buff_head *list)
64833 {
64834- return list->next == (struct sk_buff *)list;
64835+ return list->next == (const struct sk_buff *)list;
64836 }
64837
64838 /**
64839@@ -700,7 +700,7 @@ static inline int skb_queue_empty(const struct sk_buff_head *list)
64840 static inline bool skb_queue_is_last(const struct sk_buff_head *list,
64841 const struct sk_buff *skb)
64842 {
64843- return skb->next == (struct sk_buff *)list;
64844+ return skb->next == (const struct sk_buff *)list;
64845 }
64846
64847 /**
64848@@ -713,7 +713,7 @@ static inline bool skb_queue_is_last(const struct sk_buff_head *list,
64849 static inline bool skb_queue_is_first(const struct sk_buff_head *list,
64850 const struct sk_buff *skb)
64851 {
64852- return skb->prev == (struct sk_buff *)list;
64853+ return skb->prev == (const struct sk_buff *)list;
64854 }
64855
64856 /**
64857@@ -1623,7 +1623,7 @@ static inline int pskb_network_may_pull(struct sk_buff *skb, unsigned int len)
64858 * NET_IP_ALIGN(2) + ethernet_header(14) + IP_header(20/40) + ports(8)
64859 */
64860 #ifndef NET_SKB_PAD
64861-#define NET_SKB_PAD max(32, L1_CACHE_BYTES)
64862+#define NET_SKB_PAD max(_AC(32,UL), L1_CACHE_BYTES)
64863 #endif
64864
64865 extern int ___pskb_trim(struct sk_buff *skb, unsigned int len);
64866@@ -2201,7 +2201,7 @@ extern struct sk_buff *skb_recv_datagram(struct sock *sk, unsigned flags,
64867 int noblock, int *err);
64868 extern unsigned int datagram_poll(struct file *file, struct socket *sock,
64869 struct poll_table_struct *wait);
64870-extern int skb_copy_datagram_iovec(const struct sk_buff *from,
64871+extern int __intentional_overflow(0) skb_copy_datagram_iovec(const struct sk_buff *from,
64872 int offset, struct iovec *to,
64873 int size);
64874 extern int skb_copy_and_csum_datagram_iovec(struct sk_buff *skb,
64875diff --git a/include/linux/slab.h b/include/linux/slab.h
64876index 0dd2dfa..2b8677c 100644
64877--- a/include/linux/slab.h
64878+++ b/include/linux/slab.h
64879@@ -11,12 +11,20 @@
64880
64881 #include <linux/gfp.h>
64882 #include <linux/types.h>
64883+#include <linux/err.h>
64884
64885 /*
64886 * Flags to pass to kmem_cache_create().
64887 * The ones marked DEBUG are only valid if CONFIG_SLAB_DEBUG is set.
64888 */
64889 #define SLAB_DEBUG_FREE 0x00000100UL /* DEBUG: Perform (expensive) checks on free */
64890+
64891+#ifdef CONFIG_PAX_USERCOPY_SLABS
64892+#define SLAB_USERCOPY 0x00000200UL /* PaX: Allow copying objs to/from userland */
64893+#else
64894+#define SLAB_USERCOPY 0x00000000UL
64895+#endif
64896+
64897 #define SLAB_RED_ZONE 0x00000400UL /* DEBUG: Red zone objs in a cache */
64898 #define SLAB_POISON 0x00000800UL /* DEBUG: Poison objects */
64899 #define SLAB_HWCACHE_ALIGN 0x00002000UL /* Align objs on cache lines */
64900@@ -87,10 +95,13 @@
64901 * ZERO_SIZE_PTR can be passed to kfree though in the same way that NULL can.
64902 * Both make kfree a no-op.
64903 */
64904-#define ZERO_SIZE_PTR ((void *)16)
64905+#define ZERO_SIZE_PTR \
64906+({ \
64907+ BUILD_BUG_ON(!(MAX_ERRNO & ~PAGE_MASK));\
64908+ (void *)(-MAX_ERRNO-1L); \
64909+})
64910
64911-#define ZERO_OR_NULL_PTR(x) ((unsigned long)(x) <= \
64912- (unsigned long)ZERO_SIZE_PTR)
64913+#define ZERO_OR_NULL_PTR(x) ((unsigned long)(x) - 1 >= (unsigned long)ZERO_SIZE_PTR - 1)
64914
64915 /*
64916 * Common fields provided in kmem_cache by all slab allocators
64917@@ -185,6 +196,8 @@ void * __must_check krealloc(const void *, size_t, gfp_t);
64918 void kfree(const void *);
64919 void kzfree(const void *);
64920 size_t ksize(const void *);
64921+const char *check_heap_object(const void *ptr, unsigned long n, bool to);
64922+bool is_usercopy_object(const void *ptr);
64923
64924 /*
64925 * Allocator specific definitions. These are mainly used to establish optimized
64926@@ -322,7 +335,7 @@ static inline void *kmem_cache_alloc_node(struct kmem_cache *cachep,
64927 */
64928 #if defined(CONFIG_DEBUG_SLAB) || defined(CONFIG_SLUB) || \
64929 (defined(CONFIG_SLAB) && defined(CONFIG_TRACING))
64930-extern void *__kmalloc_track_caller(size_t, gfp_t, unsigned long);
64931+extern void *__kmalloc_track_caller(size_t, gfp_t, unsigned long) __size_overflow(1);
64932 #define kmalloc_track_caller(size, flags) \
64933 __kmalloc_track_caller(size, flags, _RET_IP_)
64934 #else
64935@@ -341,7 +354,7 @@ extern void *__kmalloc_track_caller(size_t, gfp_t, unsigned long);
64936 */
64937 #if defined(CONFIG_DEBUG_SLAB) || defined(CONFIG_SLUB) || \
64938 (defined(CONFIG_SLAB) && defined(CONFIG_TRACING))
64939-extern void *__kmalloc_node_track_caller(size_t, gfp_t, int, unsigned long);
64940+extern void *__kmalloc_node_track_caller(size_t, gfp_t, int, unsigned long) __size_overflow(1);
64941 #define kmalloc_node_track_caller(size, flags, node) \
64942 __kmalloc_node_track_caller(size, flags, node, \
64943 _RET_IP_)
64944diff --git a/include/linux/slab_def.h b/include/linux/slab_def.h
64945index 0c634fa..8616300 100644
64946--- a/include/linux/slab_def.h
64947+++ b/include/linux/slab_def.h
64948@@ -69,10 +69,10 @@ struct kmem_cache {
64949 unsigned long node_allocs;
64950 unsigned long node_frees;
64951 unsigned long node_overflow;
64952- atomic_t allochit;
64953- atomic_t allocmiss;
64954- atomic_t freehit;
64955- atomic_t freemiss;
64956+ atomic_unchecked_t allochit;
64957+ atomic_unchecked_t allocmiss;
64958+ atomic_unchecked_t freehit;
64959+ atomic_unchecked_t freemiss;
64960
64961 /*
64962 * If debugging is enabled, then the allocator can add additional
64963@@ -105,11 +105,16 @@ struct cache_sizes {
64964 #ifdef CONFIG_ZONE_DMA
64965 struct kmem_cache *cs_dmacachep;
64966 #endif
64967+
64968+#ifdef CONFIG_PAX_USERCOPY_SLABS
64969+ struct kmem_cache *cs_usercopycachep;
64970+#endif
64971+
64972 };
64973 extern struct cache_sizes malloc_sizes[];
64974
64975 void *kmem_cache_alloc(struct kmem_cache *, gfp_t);
64976-void *__kmalloc(size_t size, gfp_t flags);
64977+void *__kmalloc(size_t size, gfp_t flags) __size_overflow(1);
64978
64979 #ifdef CONFIG_TRACING
64980 extern void *kmem_cache_alloc_trace(size_t size,
64981@@ -152,6 +157,13 @@ found:
64982 cachep = malloc_sizes[i].cs_dmacachep;
64983 else
64984 #endif
64985+
64986+#ifdef CONFIG_PAX_USERCOPY_SLABS
64987+ if (flags & GFP_USERCOPY)
64988+ cachep = malloc_sizes[i].cs_usercopycachep;
64989+ else
64990+#endif
64991+
64992 cachep = malloc_sizes[i].cs_cachep;
64993
64994 ret = kmem_cache_alloc_trace(size, cachep, flags);
64995@@ -162,7 +174,7 @@ found:
64996 }
64997
64998 #ifdef CONFIG_NUMA
64999-extern void *__kmalloc_node(size_t size, gfp_t flags, int node);
65000+extern void *__kmalloc_node(size_t size, gfp_t flags, int node) __size_overflow(1);
65001 extern void *kmem_cache_alloc_node(struct kmem_cache *, gfp_t flags, int node);
65002
65003 #ifdef CONFIG_TRACING
65004@@ -205,6 +217,13 @@ found:
65005 cachep = malloc_sizes[i].cs_dmacachep;
65006 else
65007 #endif
65008+
65009+#ifdef CONFIG_PAX_USERCOPY_SLABS
65010+ if (flags & GFP_USERCOPY)
65011+ cachep = malloc_sizes[i].cs_usercopycachep;
65012+ else
65013+#endif
65014+
65015 cachep = malloc_sizes[i].cs_cachep;
65016
65017 return kmem_cache_alloc_node_trace(size, cachep, flags, node);
65018diff --git a/include/linux/slob_def.h b/include/linux/slob_def.h
65019index 0ec00b3..22b4715 100644
65020--- a/include/linux/slob_def.h
65021+++ b/include/linux/slob_def.h
65022@@ -9,7 +9,7 @@ static __always_inline void *kmem_cache_alloc(struct kmem_cache *cachep,
65023 return kmem_cache_alloc_node(cachep, flags, -1);
65024 }
65025
65026-void *__kmalloc_node(size_t size, gfp_t flags, int node);
65027+void *__kmalloc_node(size_t size, gfp_t flags, int node) __size_overflow(1);
65028
65029 static __always_inline void *kmalloc_node(size_t size, gfp_t flags, int node)
65030 {
65031@@ -29,7 +29,7 @@ static __always_inline void *kmalloc(size_t size, gfp_t flags)
65032 return __kmalloc_node(size, flags, -1);
65033 }
65034
65035-static __always_inline void *__kmalloc(size_t size, gfp_t flags)
65036+static __always_inline __size_overflow(1) void *__kmalloc(size_t size, gfp_t flags)
65037 {
65038 return kmalloc(size, flags);
65039 }
65040diff --git a/include/linux/slub_def.h b/include/linux/slub_def.h
65041index df448ad..b99e7f6 100644
65042--- a/include/linux/slub_def.h
65043+++ b/include/linux/slub_def.h
65044@@ -91,7 +91,7 @@ struct kmem_cache {
65045 struct kmem_cache_order_objects max;
65046 struct kmem_cache_order_objects min;
65047 gfp_t allocflags; /* gfp flags to use on each alloc */
65048- int refcount; /* Refcount for slab cache destroy */
65049+ atomic_t refcount; /* Refcount for slab cache destroy */
65050 void (*ctor)(void *);
65051 int inuse; /* Offset to metadata */
65052 int align; /* Alignment */
65053@@ -152,7 +152,7 @@ extern struct kmem_cache *kmalloc_caches[SLUB_PAGE_SHIFT];
65054 * Sorry that the following has to be that ugly but some versions of GCC
65055 * have trouble with constant propagation and loops.
65056 */
65057-static __always_inline int kmalloc_index(size_t size)
65058+static __always_inline __size_overflow(1) int kmalloc_index(size_t size)
65059 {
65060 if (!size)
65061 return 0;
65062@@ -217,7 +217,7 @@ static __always_inline struct kmem_cache *kmalloc_slab(size_t size)
65063 }
65064
65065 void *kmem_cache_alloc(struct kmem_cache *, gfp_t);
65066-void *__kmalloc(size_t size, gfp_t flags);
65067+void *__kmalloc(size_t size, gfp_t flags) __alloc_size(1) __size_overflow(1);
65068
65069 static __always_inline void *
65070 kmalloc_order(size_t size, gfp_t flags, unsigned int order)
65071@@ -258,7 +258,7 @@ kmalloc_order_trace(size_t size, gfp_t flags, unsigned int order)
65072 }
65073 #endif
65074
65075-static __always_inline void *kmalloc_large(size_t size, gfp_t flags)
65076+static __always_inline __size_overflow(1) void *kmalloc_large(size_t size, gfp_t flags)
65077 {
65078 unsigned int order = get_order(size);
65079 return kmalloc_order_trace(size, flags, order);
65080@@ -283,7 +283,7 @@ static __always_inline void *kmalloc(size_t size, gfp_t flags)
65081 }
65082
65083 #ifdef CONFIG_NUMA
65084-void *__kmalloc_node(size_t size, gfp_t flags, int node);
65085+void *__kmalloc_node(size_t size, gfp_t flags, int node) __size_overflow(1);
65086 void *kmem_cache_alloc_node(struct kmem_cache *, gfp_t flags, int node);
65087
65088 #ifdef CONFIG_TRACING
65089diff --git a/include/linux/sonet.h b/include/linux/sonet.h
65090index de8832d..0147b46 100644
65091--- a/include/linux/sonet.h
65092+++ b/include/linux/sonet.h
65093@@ -61,7 +61,7 @@ struct sonet_stats {
65094 #include <linux/atomic.h>
65095
65096 struct k_sonet_stats {
65097-#define __HANDLE_ITEM(i) atomic_t i
65098+#define __HANDLE_ITEM(i) atomic_unchecked_t i
65099 __SONET_ITEMS
65100 #undef __HANDLE_ITEM
65101 };
65102diff --git a/include/linux/sunrpc/clnt.h b/include/linux/sunrpc/clnt.h
65103index 523547e..2cb7140 100644
65104--- a/include/linux/sunrpc/clnt.h
65105+++ b/include/linux/sunrpc/clnt.h
65106@@ -174,9 +174,9 @@ static inline unsigned short rpc_get_port(const struct sockaddr *sap)
65107 {
65108 switch (sap->sa_family) {
65109 case AF_INET:
65110- return ntohs(((struct sockaddr_in *)sap)->sin_port);
65111+ return ntohs(((const struct sockaddr_in *)sap)->sin_port);
65112 case AF_INET6:
65113- return ntohs(((struct sockaddr_in6 *)sap)->sin6_port);
65114+ return ntohs(((const struct sockaddr_in6 *)sap)->sin6_port);
65115 }
65116 return 0;
65117 }
65118@@ -209,7 +209,7 @@ static inline bool __rpc_cmp_addr4(const struct sockaddr *sap1,
65119 static inline bool __rpc_copy_addr4(struct sockaddr *dst,
65120 const struct sockaddr *src)
65121 {
65122- const struct sockaddr_in *ssin = (struct sockaddr_in *) src;
65123+ const struct sockaddr_in *ssin = (const struct sockaddr_in *) src;
65124 struct sockaddr_in *dsin = (struct sockaddr_in *) dst;
65125
65126 dsin->sin_family = ssin->sin_family;
65127@@ -312,7 +312,7 @@ static inline u32 rpc_get_scope_id(const struct sockaddr *sa)
65128 if (sa->sa_family != AF_INET6)
65129 return 0;
65130
65131- return ((struct sockaddr_in6 *) sa)->sin6_scope_id;
65132+ return ((const struct sockaddr_in6 *) sa)->sin6_scope_id;
65133 }
65134
65135 #endif /* __KERNEL__ */
65136diff --git a/include/linux/sunrpc/sched.h b/include/linux/sunrpc/sched.h
65137index dc0c3cc..8503fb6 100644
65138--- a/include/linux/sunrpc/sched.h
65139+++ b/include/linux/sunrpc/sched.h
65140@@ -106,6 +106,7 @@ struct rpc_call_ops {
65141 void (*rpc_count_stats)(struct rpc_task *, void *);
65142 void (*rpc_release)(void *);
65143 };
65144+typedef struct rpc_call_ops __no_const rpc_call_ops_no_const;
65145
65146 struct rpc_task_setup {
65147 struct rpc_task *task;
65148diff --git a/include/linux/sunrpc/svc_rdma.h b/include/linux/sunrpc/svc_rdma.h
65149index 0b8e3e6..33e0a01 100644
65150--- a/include/linux/sunrpc/svc_rdma.h
65151+++ b/include/linux/sunrpc/svc_rdma.h
65152@@ -53,15 +53,15 @@ extern unsigned int svcrdma_ord;
65153 extern unsigned int svcrdma_max_requests;
65154 extern unsigned int svcrdma_max_req_size;
65155
65156-extern atomic_t rdma_stat_recv;
65157-extern atomic_t rdma_stat_read;
65158-extern atomic_t rdma_stat_write;
65159-extern atomic_t rdma_stat_sq_starve;
65160-extern atomic_t rdma_stat_rq_starve;
65161-extern atomic_t rdma_stat_rq_poll;
65162-extern atomic_t rdma_stat_rq_prod;
65163-extern atomic_t rdma_stat_sq_poll;
65164-extern atomic_t rdma_stat_sq_prod;
65165+extern atomic_unchecked_t rdma_stat_recv;
65166+extern atomic_unchecked_t rdma_stat_read;
65167+extern atomic_unchecked_t rdma_stat_write;
65168+extern atomic_unchecked_t rdma_stat_sq_starve;
65169+extern atomic_unchecked_t rdma_stat_rq_starve;
65170+extern atomic_unchecked_t rdma_stat_rq_poll;
65171+extern atomic_unchecked_t rdma_stat_rq_prod;
65172+extern atomic_unchecked_t rdma_stat_sq_poll;
65173+extern atomic_unchecked_t rdma_stat_sq_prod;
65174
65175 #define RPCRDMA_VERSION 1
65176
65177diff --git a/include/linux/sysctl.h b/include/linux/sysctl.h
65178index c34b4c8..a65b67d 100644
65179--- a/include/linux/sysctl.h
65180+++ b/include/linux/sysctl.h
65181@@ -155,7 +155,11 @@ enum
65182 KERN_PANIC_ON_NMI=76, /* int: whether we will panic on an unrecovered */
65183 };
65184
65185-
65186+#ifdef CONFIG_PAX_SOFTMODE
65187+enum {
65188+ PAX_SOFTMODE=1 /* PaX: disable/enable soft mode */
65189+};
65190+#endif
65191
65192 /* CTL_VM names: */
65193 enum
65194@@ -948,6 +952,8 @@ typedef int proc_handler (struct ctl_table *ctl, int write,
65195
65196 extern int proc_dostring(struct ctl_table *, int,
65197 void __user *, size_t *, loff_t *);
65198+extern int proc_dostring_modpriv(struct ctl_table *, int,
65199+ void __user *, size_t *, loff_t *);
65200 extern int proc_dointvec(struct ctl_table *, int,
65201 void __user *, size_t *, loff_t *);
65202 extern int proc_dointvec_minmax(struct ctl_table *, int,
65203diff --git a/include/linux/tty.h b/include/linux/tty.h
65204index 9f47ab5..73da944 100644
65205--- a/include/linux/tty.h
65206+++ b/include/linux/tty.h
65207@@ -225,7 +225,7 @@ struct tty_port {
65208 const struct tty_port_operations *ops; /* Port operations */
65209 spinlock_t lock; /* Lock protecting tty field */
65210 int blocked_open; /* Waiting to open */
65211- int count; /* Usage count */
65212+ atomic_t count; /* Usage count */
65213 wait_queue_head_t open_wait; /* Open waiters */
65214 wait_queue_head_t close_wait; /* Close waiters */
65215 wait_queue_head_t delta_msr_wait; /* Modem status change */
65216@@ -525,7 +525,7 @@ extern int tty_port_open(struct tty_port *port,
65217 struct tty_struct *tty, struct file *filp);
65218 static inline int tty_port_users(struct tty_port *port)
65219 {
65220- return port->count + port->blocked_open;
65221+ return atomic_read(&port->count) + port->blocked_open;
65222 }
65223
65224 extern int tty_register_ldisc(int disc, struct tty_ldisc_ops *new_ldisc);
65225diff --git a/include/linux/tty_ldisc.h b/include/linux/tty_ldisc.h
65226index fb79dd8d..07d4773 100644
65227--- a/include/linux/tty_ldisc.h
65228+++ b/include/linux/tty_ldisc.h
65229@@ -149,7 +149,7 @@ struct tty_ldisc_ops {
65230
65231 struct module *owner;
65232
65233- int refcount;
65234+ atomic_t refcount;
65235 };
65236
65237 struct tty_ldisc {
65238diff --git a/include/linux/types.h b/include/linux/types.h
65239index bf0dd75..a1f23aaa 100644
65240--- a/include/linux/types.h
65241+++ b/include/linux/types.h
65242@@ -220,10 +220,26 @@ typedef struct {
65243 int counter;
65244 } atomic_t;
65245
65246+#ifdef CONFIG_PAX_REFCOUNT
65247+typedef struct {
65248+ int counter;
65249+} atomic_unchecked_t;
65250+#else
65251+typedef atomic_t atomic_unchecked_t;
65252+#endif
65253+
65254 #ifdef CONFIG_64BIT
65255 typedef struct {
65256 long counter;
65257 } atomic64_t;
65258+
65259+#ifdef CONFIG_PAX_REFCOUNT
65260+typedef struct {
65261+ long counter;
65262+} atomic64_unchecked_t;
65263+#else
65264+typedef atomic64_t atomic64_unchecked_t;
65265+#endif
65266 #endif
65267
65268 struct list_head {
65269diff --git a/include/linux/uaccess.h b/include/linux/uaccess.h
65270index 5ca0951..ab496a5 100644
65271--- a/include/linux/uaccess.h
65272+++ b/include/linux/uaccess.h
65273@@ -76,11 +76,11 @@ static inline unsigned long __copy_from_user_nocache(void *to,
65274 long ret; \
65275 mm_segment_t old_fs = get_fs(); \
65276 \
65277- set_fs(KERNEL_DS); \
65278 pagefault_disable(); \
65279- ret = __copy_from_user_inatomic(&(retval), (__force typeof(retval) __user *)(addr), sizeof(retval)); \
65280- pagefault_enable(); \
65281+ set_fs(KERNEL_DS); \
65282+ ret = __copy_from_user_inatomic(&(retval), (typeof(retval) __force_user *)(addr), sizeof(retval)); \
65283 set_fs(old_fs); \
65284+ pagefault_enable(); \
65285 ret; \
65286 })
65287
65288diff --git a/include/linux/unaligned/access_ok.h b/include/linux/unaligned/access_ok.h
65289index 99c1b4d..bb94261 100644
65290--- a/include/linux/unaligned/access_ok.h
65291+++ b/include/linux/unaligned/access_ok.h
65292@@ -6,32 +6,32 @@
65293
65294 static inline u16 get_unaligned_le16(const void *p)
65295 {
65296- return le16_to_cpup((__le16 *)p);
65297+ return le16_to_cpup((const __le16 *)p);
65298 }
65299
65300 static inline u32 get_unaligned_le32(const void *p)
65301 {
65302- return le32_to_cpup((__le32 *)p);
65303+ return le32_to_cpup((const __le32 *)p);
65304 }
65305
65306 static inline u64 get_unaligned_le64(const void *p)
65307 {
65308- return le64_to_cpup((__le64 *)p);
65309+ return le64_to_cpup((const __le64 *)p);
65310 }
65311
65312 static inline u16 get_unaligned_be16(const void *p)
65313 {
65314- return be16_to_cpup((__be16 *)p);
65315+ return be16_to_cpup((const __be16 *)p);
65316 }
65317
65318 static inline u32 get_unaligned_be32(const void *p)
65319 {
65320- return be32_to_cpup((__be32 *)p);
65321+ return be32_to_cpup((const __be32 *)p);
65322 }
65323
65324 static inline u64 get_unaligned_be64(const void *p)
65325 {
65326- return be64_to_cpup((__be64 *)p);
65327+ return be64_to_cpup((const __be64 *)p);
65328 }
65329
65330 static inline void put_unaligned_le16(u16 val, void *p)
65331diff --git a/include/linux/usb/renesas_usbhs.h b/include/linux/usb/renesas_usbhs.h
65332index c5d36c6..8478c90 100644
65333--- a/include/linux/usb/renesas_usbhs.h
65334+++ b/include/linux/usb/renesas_usbhs.h
65335@@ -39,7 +39,7 @@ enum {
65336 */
65337 struct renesas_usbhs_driver_callback {
65338 int (*notify_hotplug)(struct platform_device *pdev);
65339-};
65340+} __no_const;
65341
65342 /*
65343 * callback functions for platform
65344@@ -97,7 +97,7 @@ struct renesas_usbhs_platform_callback {
65345 * VBUS control is needed for Host
65346 */
65347 int (*set_vbus)(struct platform_device *pdev, int enable);
65348-};
65349+} __no_const;
65350
65351 /*
65352 * parameters for renesas usbhs
65353diff --git a/include/linux/vermagic.h b/include/linux/vermagic.h
65354index 6f8fbcf..8259001 100644
65355--- a/include/linux/vermagic.h
65356+++ b/include/linux/vermagic.h
65357@@ -25,9 +25,35 @@
65358 #define MODULE_ARCH_VERMAGIC ""
65359 #endif
65360
65361+#ifdef CONFIG_PAX_REFCOUNT
65362+#define MODULE_PAX_REFCOUNT "REFCOUNT "
65363+#else
65364+#define MODULE_PAX_REFCOUNT ""
65365+#endif
65366+
65367+#ifdef CONSTIFY_PLUGIN
65368+#define MODULE_CONSTIFY_PLUGIN "CONSTIFY_PLUGIN "
65369+#else
65370+#define MODULE_CONSTIFY_PLUGIN ""
65371+#endif
65372+
65373+#ifdef STACKLEAK_PLUGIN
65374+#define MODULE_STACKLEAK_PLUGIN "STACKLEAK_PLUGIN "
65375+#else
65376+#define MODULE_STACKLEAK_PLUGIN ""
65377+#endif
65378+
65379+#ifdef CONFIG_GRKERNSEC
65380+#define MODULE_GRSEC "GRSEC "
65381+#else
65382+#define MODULE_GRSEC ""
65383+#endif
65384+
65385 #define VERMAGIC_STRING \
65386 UTS_RELEASE " " \
65387 MODULE_VERMAGIC_SMP MODULE_VERMAGIC_PREEMPT \
65388 MODULE_VERMAGIC_MODULE_UNLOAD MODULE_VERMAGIC_MODVERSIONS \
65389- MODULE_ARCH_VERMAGIC
65390+ MODULE_ARCH_VERMAGIC \
65391+ MODULE_PAX_REFCOUNT MODULE_CONSTIFY_PLUGIN MODULE_STACKLEAK_PLUGIN \
65392+ MODULE_GRSEC
65393
65394diff --git a/include/linux/vmalloc.h b/include/linux/vmalloc.h
65395index 6071e91..ca6a489 100644
65396--- a/include/linux/vmalloc.h
65397+++ b/include/linux/vmalloc.h
65398@@ -14,6 +14,11 @@ struct vm_area_struct; /* vma defining user mapping in mm_types.h */
65399 #define VM_USERMAP 0x00000008 /* suitable for remap_vmalloc_range */
65400 #define VM_VPAGES 0x00000010 /* buffer for pages was vmalloc'ed */
65401 #define VM_UNLIST 0x00000020 /* vm_struct is not listed in vmlist */
65402+
65403+#if defined(CONFIG_MODULES) && defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
65404+#define VM_KERNEXEC 0x00000040 /* allocate from executable kernel memory range */
65405+#endif
65406+
65407 /* bits [20..32] reserved for arch specific ioremap internals */
65408
65409 /*
65410@@ -62,7 +67,7 @@ extern void *vmalloc_32_user(unsigned long size);
65411 extern void *__vmalloc(unsigned long size, gfp_t gfp_mask, pgprot_t prot);
65412 extern void *__vmalloc_node_range(unsigned long size, unsigned long align,
65413 unsigned long start, unsigned long end, gfp_t gfp_mask,
65414- pgprot_t prot, int node, const void *caller);
65415+ pgprot_t prot, int node, const void *caller) __size_overflow(1);
65416 extern void vfree(const void *addr);
65417
65418 extern void *vmap(struct page **pages, unsigned int count,
65419@@ -124,8 +129,8 @@ extern struct vm_struct *alloc_vm_area(size_t size, pte_t **ptes);
65420 extern void free_vm_area(struct vm_struct *area);
65421
65422 /* for /dev/kmem */
65423-extern long vread(char *buf, char *addr, unsigned long count);
65424-extern long vwrite(char *buf, char *addr, unsigned long count);
65425+extern long vread(char *buf, char *addr, unsigned long count) __size_overflow(3);
65426+extern long vwrite(char *buf, char *addr, unsigned long count) __size_overflow(3);
65427
65428 /*
65429 * Internals. Dont't use..
65430diff --git a/include/linux/vmstat.h b/include/linux/vmstat.h
65431index ad2cfd5..74c94ad 100644
65432--- a/include/linux/vmstat.h
65433+++ b/include/linux/vmstat.h
65434@@ -87,18 +87,18 @@ static inline void vm_events_fold_cpu(int cpu)
65435 /*
65436 * Zone based page accounting with per cpu differentials.
65437 */
65438-extern atomic_long_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
65439+extern atomic_long_unchecked_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
65440
65441 static inline void zone_page_state_add(long x, struct zone *zone,
65442 enum zone_stat_item item)
65443 {
65444- atomic_long_add(x, &zone->vm_stat[item]);
65445- atomic_long_add(x, &vm_stat[item]);
65446+ atomic_long_add_unchecked(x, &zone->vm_stat[item]);
65447+ atomic_long_add_unchecked(x, &vm_stat[item]);
65448 }
65449
65450 static inline unsigned long global_page_state(enum zone_stat_item item)
65451 {
65452- long x = atomic_long_read(&vm_stat[item]);
65453+ long x = atomic_long_read_unchecked(&vm_stat[item]);
65454 #ifdef CONFIG_SMP
65455 if (x < 0)
65456 x = 0;
65457@@ -109,7 +109,7 @@ static inline unsigned long global_page_state(enum zone_stat_item item)
65458 static inline unsigned long zone_page_state(struct zone *zone,
65459 enum zone_stat_item item)
65460 {
65461- long x = atomic_long_read(&zone->vm_stat[item]);
65462+ long x = atomic_long_read_unchecked(&zone->vm_stat[item]);
65463 #ifdef CONFIG_SMP
65464 if (x < 0)
65465 x = 0;
65466@@ -126,7 +126,7 @@ static inline unsigned long zone_page_state(struct zone *zone,
65467 static inline unsigned long zone_page_state_snapshot(struct zone *zone,
65468 enum zone_stat_item item)
65469 {
65470- long x = atomic_long_read(&zone->vm_stat[item]);
65471+ long x = atomic_long_read_unchecked(&zone->vm_stat[item]);
65472
65473 #ifdef CONFIG_SMP
65474 int cpu;
65475@@ -216,8 +216,8 @@ static inline void __mod_zone_page_state(struct zone *zone,
65476
65477 static inline void __inc_zone_state(struct zone *zone, enum zone_stat_item item)
65478 {
65479- atomic_long_inc(&zone->vm_stat[item]);
65480- atomic_long_inc(&vm_stat[item]);
65481+ atomic_long_inc_unchecked(&zone->vm_stat[item]);
65482+ atomic_long_inc_unchecked(&vm_stat[item]);
65483 }
65484
65485 static inline void __inc_zone_page_state(struct page *page,
65486@@ -228,8 +228,8 @@ static inline void __inc_zone_page_state(struct page *page,
65487
65488 static inline void __dec_zone_state(struct zone *zone, enum zone_stat_item item)
65489 {
65490- atomic_long_dec(&zone->vm_stat[item]);
65491- atomic_long_dec(&vm_stat[item]);
65492+ atomic_long_dec_unchecked(&zone->vm_stat[item]);
65493+ atomic_long_dec_unchecked(&vm_stat[item]);
65494 }
65495
65496 static inline void __dec_zone_page_state(struct page *page,
65497diff --git a/include/linux/xattr.h b/include/linux/xattr.h
65498index e5d1220..ef6e406 100644
65499--- a/include/linux/xattr.h
65500+++ b/include/linux/xattr.h
65501@@ -57,6 +57,11 @@
65502 #define XATTR_POSIX_ACL_DEFAULT "posix_acl_default"
65503 #define XATTR_NAME_POSIX_ACL_DEFAULT XATTR_SYSTEM_PREFIX XATTR_POSIX_ACL_DEFAULT
65504
65505+/* User namespace */
65506+#define XATTR_PAX_PREFIX XATTR_USER_PREFIX "pax."
65507+#define XATTR_PAX_FLAGS_SUFFIX "flags"
65508+#define XATTR_NAME_PAX_FLAGS XATTR_PAX_PREFIX XATTR_PAX_FLAGS_SUFFIX
65509+
65510 #ifdef __KERNEL__
65511
65512 #include <linux/types.h>
65513diff --git a/include/media/saa7146_vv.h b/include/media/saa7146_vv.h
65514index 944ecdf..a3994fc 100644
65515--- a/include/media/saa7146_vv.h
65516+++ b/include/media/saa7146_vv.h
65517@@ -161,8 +161,8 @@ struct saa7146_ext_vv
65518 int (*std_callback)(struct saa7146_dev*, struct saa7146_standard *);
65519
65520 /* the extension can override this */
65521- struct v4l2_ioctl_ops vid_ops;
65522- struct v4l2_ioctl_ops vbi_ops;
65523+ v4l2_ioctl_ops_no_const vid_ops;
65524+ v4l2_ioctl_ops_no_const vbi_ops;
65525 /* pointer to the saa7146 core ops */
65526 const struct v4l2_ioctl_ops *core_ops;
65527
65528diff --git a/include/media/v4l2-dev.h b/include/media/v4l2-dev.h
65529index 5c416cd..20021aa 100644
65530--- a/include/media/v4l2-dev.h
65531+++ b/include/media/v4l2-dev.h
65532@@ -73,7 +73,8 @@ struct v4l2_file_operations {
65533 int (*mmap) (struct file *, struct vm_area_struct *);
65534 int (*open) (struct file *);
65535 int (*release) (struct file *);
65536-};
65537+} __do_const;
65538+typedef struct v4l2_file_operations __no_const v4l2_file_operations_no_const;
65539
65540 /*
65541 * Newer version of video_device, handled by videodev2.c
65542diff --git a/include/media/v4l2-ioctl.h b/include/media/v4l2-ioctl.h
65543index e614c9c..20602b7 100644
65544--- a/include/media/v4l2-ioctl.h
65545+++ b/include/media/v4l2-ioctl.h
65546@@ -289,7 +289,7 @@ struct v4l2_ioctl_ops {
65547 long (*vidioc_default) (struct file *file, void *fh,
65548 bool valid_prio, int cmd, void *arg);
65549 };
65550-
65551+typedef struct v4l2_ioctl_ops __no_const v4l2_ioctl_ops_no_const;
65552
65553 /* v4l debugging and diagnostics */
65554
65555diff --git a/include/net/caif/caif_hsi.h b/include/net/caif/caif_hsi.h
65556index bcb9cc3..f4ec722e 100644
65557--- a/include/net/caif/caif_hsi.h
65558+++ b/include/net/caif/caif_hsi.h
65559@@ -98,7 +98,7 @@ struct cfhsi_cb_ops {
65560 void (*rx_done_cb) (struct cfhsi_cb_ops *drv);
65561 void (*wake_up_cb) (struct cfhsi_cb_ops *drv);
65562 void (*wake_down_cb) (struct cfhsi_cb_ops *drv);
65563-};
65564+} __no_const;
65565
65566 /* Structure implemented by HSI device. */
65567 struct cfhsi_ops {
65568diff --git a/include/net/caif/cfctrl.h b/include/net/caif/cfctrl.h
65569index 9e5425b..8136ffc 100644
65570--- a/include/net/caif/cfctrl.h
65571+++ b/include/net/caif/cfctrl.h
65572@@ -52,7 +52,7 @@ struct cfctrl_rsp {
65573 void (*radioset_rsp)(void);
65574 void (*reject_rsp)(struct cflayer *layer, u8 linkid,
65575 struct cflayer *client_layer);
65576-};
65577+} __no_const;
65578
65579 /* Link Setup Parameters for CAIF-Links. */
65580 struct cfctrl_link_param {
65581@@ -101,8 +101,8 @@ struct cfctrl_request_info {
65582 struct cfctrl {
65583 struct cfsrvl serv;
65584 struct cfctrl_rsp res;
65585- atomic_t req_seq_no;
65586- atomic_t rsp_seq_no;
65587+ atomic_unchecked_t req_seq_no;
65588+ atomic_unchecked_t rsp_seq_no;
65589 struct list_head list;
65590 /* Protects from simultaneous access to first_req list */
65591 spinlock_t info_list_lock;
65592diff --git a/include/net/flow.h b/include/net/flow.h
65593index 628e11b..4c475df 100644
65594--- a/include/net/flow.h
65595+++ b/include/net/flow.h
65596@@ -221,6 +221,6 @@ extern struct flow_cache_object *flow_cache_lookup(
65597
65598 extern void flow_cache_flush(void);
65599 extern void flow_cache_flush_deferred(void);
65600-extern atomic_t flow_cache_genid;
65601+extern atomic_unchecked_t flow_cache_genid;
65602
65603 #endif
65604diff --git a/include/net/inetpeer.h b/include/net/inetpeer.h
65605index 53f464d..ba76aaa 100644
65606--- a/include/net/inetpeer.h
65607+++ b/include/net/inetpeer.h
65608@@ -47,8 +47,8 @@ struct inet_peer {
65609 */
65610 union {
65611 struct {
65612- atomic_t rid; /* Frag reception counter */
65613- atomic_t ip_id_count; /* IP ID for the next packet */
65614+ atomic_unchecked_t rid; /* Frag reception counter */
65615+ atomic_unchecked_t ip_id_count; /* IP ID for the next packet */
65616 };
65617 struct rcu_head rcu;
65618 struct inet_peer *gc_next;
65619@@ -182,11 +182,11 @@ static inline int inet_getid(struct inet_peer *p, int more)
65620 more++;
65621 inet_peer_refcheck(p);
65622 do {
65623- old = atomic_read(&p->ip_id_count);
65624+ old = atomic_read_unchecked(&p->ip_id_count);
65625 new = old + more;
65626 if (!new)
65627 new = 1;
65628- } while (atomic_cmpxchg(&p->ip_id_count, old, new) != old);
65629+ } while (atomic_cmpxchg_unchecked(&p->ip_id_count, old, new) != old);
65630 return new;
65631 }
65632
65633diff --git a/include/net/ip_fib.h b/include/net/ip_fib.h
65634index 9497be1..5a4fafe 100644
65635--- a/include/net/ip_fib.h
65636+++ b/include/net/ip_fib.h
65637@@ -169,7 +169,7 @@ extern __be32 fib_info_update_nh_saddr(struct net *net, struct fib_nh *nh);
65638
65639 #define FIB_RES_SADDR(net, res) \
65640 ((FIB_RES_NH(res).nh_saddr_genid == \
65641- atomic_read(&(net)->ipv4.dev_addr_genid)) ? \
65642+ atomic_read_unchecked(&(net)->ipv4.dev_addr_genid)) ? \
65643 FIB_RES_NH(res).nh_saddr : \
65644 fib_info_update_nh_saddr((net), &FIB_RES_NH(res)))
65645 #define FIB_RES_GW(res) (FIB_RES_NH(res).nh_gw)
65646diff --git a/include/net/ip_vs.h b/include/net/ip_vs.h
65647index 95374d1..2300e36 100644
65648--- a/include/net/ip_vs.h
65649+++ b/include/net/ip_vs.h
65650@@ -510,7 +510,7 @@ struct ip_vs_conn {
65651 struct ip_vs_conn *control; /* Master control connection */
65652 atomic_t n_control; /* Number of controlled ones */
65653 struct ip_vs_dest *dest; /* real server */
65654- atomic_t in_pkts; /* incoming packet counter */
65655+ atomic_unchecked_t in_pkts; /* incoming packet counter */
65656
65657 /* packet transmitter for different forwarding methods. If it
65658 mangles the packet, it must return NF_DROP or better NF_STOLEN,
65659@@ -648,7 +648,7 @@ struct ip_vs_dest {
65660 __be16 port; /* port number of the server */
65661 union nf_inet_addr addr; /* IP address of the server */
65662 volatile unsigned int flags; /* dest status flags */
65663- atomic_t conn_flags; /* flags to copy to conn */
65664+ atomic_unchecked_t conn_flags; /* flags to copy to conn */
65665 atomic_t weight; /* server weight */
65666
65667 atomic_t refcnt; /* reference counter */
65668diff --git a/include/net/irda/ircomm_core.h b/include/net/irda/ircomm_core.h
65669index 69b610a..fe3962c 100644
65670--- a/include/net/irda/ircomm_core.h
65671+++ b/include/net/irda/ircomm_core.h
65672@@ -51,7 +51,7 @@ typedef struct {
65673 int (*connect_response)(struct ircomm_cb *, struct sk_buff *);
65674 int (*disconnect_request)(struct ircomm_cb *, struct sk_buff *,
65675 struct ircomm_info *);
65676-} call_t;
65677+} __no_const call_t;
65678
65679 struct ircomm_cb {
65680 irda_queue_t queue;
65681diff --git a/include/net/irda/ircomm_tty.h b/include/net/irda/ircomm_tty.h
65682index 59ba38bc..d515662 100644
65683--- a/include/net/irda/ircomm_tty.h
65684+++ b/include/net/irda/ircomm_tty.h
65685@@ -35,6 +35,7 @@
65686 #include <linux/termios.h>
65687 #include <linux/timer.h>
65688 #include <linux/tty.h> /* struct tty_struct */
65689+#include <asm/local.h>
65690
65691 #include <net/irda/irias_object.h>
65692 #include <net/irda/ircomm_core.h>
65693@@ -105,8 +106,8 @@ struct ircomm_tty_cb {
65694 unsigned short close_delay;
65695 unsigned short closing_wait; /* time to wait before closing */
65696
65697- int open_count;
65698- int blocked_open; /* # of blocked opens */
65699+ local_t open_count;
65700+ local_t blocked_open; /* # of blocked opens */
65701
65702 /* Protect concurent access to :
65703 * o self->open_count
65704diff --git a/include/net/iucv/af_iucv.h b/include/net/iucv/af_iucv.h
65705index cc7c197..9f2da2a 100644
65706--- a/include/net/iucv/af_iucv.h
65707+++ b/include/net/iucv/af_iucv.h
65708@@ -141,7 +141,7 @@ struct iucv_sock {
65709 struct iucv_sock_list {
65710 struct hlist_head head;
65711 rwlock_t lock;
65712- atomic_t autobind_name;
65713+ atomic_unchecked_t autobind_name;
65714 };
65715
65716 unsigned int iucv_sock_poll(struct file *file, struct socket *sock,
65717diff --git a/include/net/neighbour.h b/include/net/neighbour.h
65718index 344d898..2ae1302 100644
65719--- a/include/net/neighbour.h
65720+++ b/include/net/neighbour.h
65721@@ -123,7 +123,7 @@ struct neigh_ops {
65722 void (*error_report)(struct neighbour *, struct sk_buff *);
65723 int (*output)(struct neighbour *, struct sk_buff *);
65724 int (*connected_output)(struct neighbour *, struct sk_buff *);
65725-};
65726+} __do_const;
65727
65728 struct pneigh_entry {
65729 struct pneigh_entry *next;
65730diff --git a/include/net/net_namespace.h b/include/net/net_namespace.h
65731index fd87963..312a11f 100644
65732--- a/include/net/net_namespace.h
65733+++ b/include/net/net_namespace.h
65734@@ -102,7 +102,7 @@ struct net {
65735 #endif
65736 struct netns_ipvs *ipvs;
65737 struct sock *diag_nlsk;
65738- atomic_t rt_genid;
65739+ atomic_unchecked_t rt_genid;
65740 };
65741
65742
65743@@ -303,12 +303,12 @@ static inline void unregister_net_sysctl_table(struct ctl_table_header *header)
65744
65745 static inline int rt_genid(struct net *net)
65746 {
65747- return atomic_read(&net->rt_genid);
65748+ return atomic_read_unchecked(&net->rt_genid);
65749 }
65750
65751 static inline void rt_genid_bump(struct net *net)
65752 {
65753- atomic_inc(&net->rt_genid);
65754+ atomic_inc_unchecked(&net->rt_genid);
65755 }
65756
65757 #endif /* __NET_NET_NAMESPACE_H */
65758diff --git a/include/net/netdma.h b/include/net/netdma.h
65759index 8ba8ce2..99b7fff 100644
65760--- a/include/net/netdma.h
65761+++ b/include/net/netdma.h
65762@@ -24,7 +24,7 @@
65763 #include <linux/dmaengine.h>
65764 #include <linux/skbuff.h>
65765
65766-int dma_skb_copy_datagram_iovec(struct dma_chan* chan,
65767+int __intentional_overflow(3,5) dma_skb_copy_datagram_iovec(struct dma_chan* chan,
65768 struct sk_buff *skb, int offset, struct iovec *to,
65769 size_t len, struct dma_pinned_list *pinned_list);
65770
65771diff --git a/include/net/netlink.h b/include/net/netlink.h
65772index 785f37a..c81dc0c 100644
65773--- a/include/net/netlink.h
65774+++ b/include/net/netlink.h
65775@@ -520,7 +520,7 @@ static inline void *nlmsg_get_pos(struct sk_buff *skb)
65776 static inline void nlmsg_trim(struct sk_buff *skb, const void *mark)
65777 {
65778 if (mark)
65779- skb_trim(skb, (unsigned char *) mark - skb->data);
65780+ skb_trim(skb, (const unsigned char *) mark - skb->data);
65781 }
65782
65783 /**
65784diff --git a/include/net/netns/ipv4.h b/include/net/netns/ipv4.h
65785index eb24dbc..567d6ed 100644
65786--- a/include/net/netns/ipv4.h
65787+++ b/include/net/netns/ipv4.h
65788@@ -65,7 +65,7 @@ struct netns_ipv4 {
65789 unsigned int sysctl_ping_group_range[2];
65790 long sysctl_tcp_mem[3];
65791
65792- atomic_t dev_addr_genid;
65793+ atomic_unchecked_t dev_addr_genid;
65794
65795 #ifdef CONFIG_IP_MROUTE
65796 #ifndef CONFIG_IP_MROUTE_MULTIPLE_TABLES
65797diff --git a/include/net/sctp/sctp.h b/include/net/sctp/sctp.h
65798index ff49964..1411fee 100644
65799--- a/include/net/sctp/sctp.h
65800+++ b/include/net/sctp/sctp.h
65801@@ -320,9 +320,9 @@ do { \
65802
65803 #else /* SCTP_DEBUG */
65804
65805-#define SCTP_DEBUG_PRINTK(whatever...)
65806-#define SCTP_DEBUG_PRINTK_CONT(fmt, args...)
65807-#define SCTP_DEBUG_PRINTK_IPADDR(whatever...)
65808+#define SCTP_DEBUG_PRINTK(whatever...) do {} while (0)
65809+#define SCTP_DEBUG_PRINTK_CONT(fmt, args...) do {} while (0)
65810+#define SCTP_DEBUG_PRINTK_IPADDR(whatever...) do {} while (0)
65811 #define SCTP_ENABLE_DEBUG
65812 #define SCTP_DISABLE_DEBUG
65813 #define SCTP_ASSERT(expr, str, func)
65814diff --git a/include/net/sock.h b/include/net/sock.h
65815index adb7da2..1100002 100644
65816--- a/include/net/sock.h
65817+++ b/include/net/sock.h
65818@@ -305,7 +305,7 @@ struct sock {
65819 #ifdef CONFIG_RPS
65820 __u32 sk_rxhash;
65821 #endif
65822- atomic_t sk_drops;
65823+ atomic_unchecked_t sk_drops;
65824 int sk_rcvbuf;
65825
65826 struct sk_filter __rcu *sk_filter;
65827@@ -1764,7 +1764,7 @@ static inline void sk_nocaps_add(struct sock *sk, netdev_features_t flags)
65828 }
65829
65830 static inline int skb_do_copy_data_nocache(struct sock *sk, struct sk_buff *skb,
65831- char __user *from, char *to,
65832+ char __user *from, unsigned char *to,
65833 int copy, int offset)
65834 {
65835 if (skb->ip_summed == CHECKSUM_NONE) {
65836@@ -2023,7 +2023,7 @@ static inline void sk_stream_moderate_sndbuf(struct sock *sk)
65837 }
65838 }
65839
65840-struct sk_buff *sk_stream_alloc_skb(struct sock *sk, int size, gfp_t gfp);
65841+struct sk_buff * __intentional_overflow(0) sk_stream_alloc_skb(struct sock *sk, int size, gfp_t gfp);
65842
65843 static inline struct page *sk_stream_alloc_page(struct sock *sk)
65844 {
65845diff --git a/include/net/tcp.h b/include/net/tcp.h
65846index 1f000ff..e5a8dfb 100644
65847--- a/include/net/tcp.h
65848+++ b/include/net/tcp.h
65849@@ -508,7 +508,7 @@ extern void tcp_retransmit_timer(struct sock *sk);
65850 extern void tcp_xmit_retransmit_queue(struct sock *);
65851 extern void tcp_simple_retransmit(struct sock *);
65852 extern int tcp_trim_head(struct sock *, struct sk_buff *, u32);
65853-extern int tcp_fragment(struct sock *, struct sk_buff *, u32, unsigned int);
65854+extern int __intentional_overflow(3) tcp_fragment(struct sock *, struct sk_buff *, u32, unsigned int);
65855
65856 extern void tcp_send_probe0(struct sock *);
65857 extern void tcp_send_partial(struct sock *);
65858@@ -677,8 +677,8 @@ struct tcp_skb_cb {
65859 struct inet6_skb_parm h6;
65860 #endif
65861 } header; /* For incoming frames */
65862- __u32 seq; /* Starting sequence number */
65863- __u32 end_seq; /* SEQ + FIN + SYN + datalen */
65864+ __u32 seq __intentional_overflow(0); /* Starting sequence number */
65865+ __u32 end_seq __intentional_overflow(0); /* SEQ + FIN + SYN + datalen */
65866 __u32 when; /* used to compute rtt's */
65867 __u8 tcp_flags; /* TCP header flags. (tcp[13]) */
65868
65869@@ -692,7 +692,7 @@ struct tcp_skb_cb {
65870
65871 __u8 ip_dsfield; /* IPv4 tos or IPv6 dsfield */
65872 /* 1 byte hole */
65873- __u32 ack_seq; /* Sequence number ACK'd */
65874+ __u32 ack_seq __intentional_overflow(0); /* Sequence number ACK'd */
65875 };
65876
65877 #define TCP_SKB_CB(__skb) ((struct tcp_skb_cb *)&((__skb)->cb[0]))
65878@@ -1502,7 +1502,7 @@ struct tcp_seq_afinfo {
65879 char *name;
65880 sa_family_t family;
65881 const struct file_operations *seq_fops;
65882- struct seq_operations seq_ops;
65883+ seq_operations_no_const seq_ops;
65884 };
65885
65886 struct tcp_iter_state {
65887diff --git a/include/net/udp.h b/include/net/udp.h
65888index 065f379..b661b40 100644
65889--- a/include/net/udp.h
65890+++ b/include/net/udp.h
65891@@ -244,7 +244,7 @@ struct udp_seq_afinfo {
65892 sa_family_t family;
65893 struct udp_table *udp_table;
65894 const struct file_operations *seq_fops;
65895- struct seq_operations seq_ops;
65896+ seq_operations_no_const seq_ops;
65897 };
65898
65899 struct udp_iter_state {
65900diff --git a/include/net/xfrm.h b/include/net/xfrm.h
65901index 639dd13..15b206c 100644
65902--- a/include/net/xfrm.h
65903+++ b/include/net/xfrm.h
65904@@ -514,7 +514,7 @@ struct xfrm_policy {
65905 struct timer_list timer;
65906
65907 struct flow_cache_object flo;
65908- atomic_t genid;
65909+ atomic_unchecked_t genid;
65910 u32 priority;
65911 u32 index;
65912 struct xfrm_mark mark;
65913diff --git a/include/rdma/iw_cm.h b/include/rdma/iw_cm.h
65914index 1a046b1..ee0bef0 100644
65915--- a/include/rdma/iw_cm.h
65916+++ b/include/rdma/iw_cm.h
65917@@ -122,7 +122,7 @@ struct iw_cm_verbs {
65918 int backlog);
65919
65920 int (*destroy_listen)(struct iw_cm_id *cm_id);
65921-};
65922+} __no_const;
65923
65924 /**
65925 * iw_create_cm_id - Create an IW CM identifier.
65926diff --git a/include/scsi/libfc.h b/include/scsi/libfc.h
65927index 399162b..b337f1a 100644
65928--- a/include/scsi/libfc.h
65929+++ b/include/scsi/libfc.h
65930@@ -762,6 +762,7 @@ struct libfc_function_template {
65931 */
65932 void (*disc_stop_final) (struct fc_lport *);
65933 };
65934+typedef struct libfc_function_template __no_const libfc_function_template_no_const;
65935
65936 /**
65937 * struct fc_disc - Discovery context
65938@@ -866,7 +867,7 @@ struct fc_lport {
65939 struct fc_vport *vport;
65940
65941 /* Operational Information */
65942- struct libfc_function_template tt;
65943+ libfc_function_template_no_const tt;
65944 u8 link_up;
65945 u8 qfull;
65946 enum fc_lport_state state;
65947diff --git a/include/scsi/scsi_device.h b/include/scsi/scsi_device.h
65948index 9895f69..f1418f0 100644
65949--- a/include/scsi/scsi_device.h
65950+++ b/include/scsi/scsi_device.h
65951@@ -166,9 +166,9 @@ struct scsi_device {
65952 unsigned int max_device_blocked; /* what device_blocked counts down from */
65953 #define SCSI_DEFAULT_DEVICE_BLOCKED 3
65954
65955- atomic_t iorequest_cnt;
65956- atomic_t iodone_cnt;
65957- atomic_t ioerr_cnt;
65958+ atomic_unchecked_t iorequest_cnt;
65959+ atomic_unchecked_t iodone_cnt;
65960+ atomic_unchecked_t ioerr_cnt;
65961
65962 struct device sdev_gendev,
65963 sdev_dev;
65964diff --git a/include/scsi/scsi_transport_fc.h b/include/scsi/scsi_transport_fc.h
65965index b797e8f..8e2c3aa 100644
65966--- a/include/scsi/scsi_transport_fc.h
65967+++ b/include/scsi/scsi_transport_fc.h
65968@@ -751,7 +751,8 @@ struct fc_function_template {
65969 unsigned long show_host_system_hostname:1;
65970
65971 unsigned long disable_target_scan:1;
65972-};
65973+} __do_const;
65974+typedef struct fc_function_template __no_const fc_function_template_no_const;
65975
65976
65977 /**
65978diff --git a/include/sound/ak4xxx-adda.h b/include/sound/ak4xxx-adda.h
65979index 030b87c..98a6954 100644
65980--- a/include/sound/ak4xxx-adda.h
65981+++ b/include/sound/ak4xxx-adda.h
65982@@ -35,7 +35,7 @@ struct snd_ak4xxx_ops {
65983 void (*write)(struct snd_akm4xxx *ak, int chip, unsigned char reg,
65984 unsigned char val);
65985 void (*set_rate_val)(struct snd_akm4xxx *ak, unsigned int rate);
65986-};
65987+} __no_const;
65988
65989 #define AK4XXX_IMAGE_SIZE (AK4XXX_MAX_CHIPS * 16) /* 64 bytes */
65990
65991diff --git a/include/sound/hwdep.h b/include/sound/hwdep.h
65992index 8c05e47..2b5df97 100644
65993--- a/include/sound/hwdep.h
65994+++ b/include/sound/hwdep.h
65995@@ -49,7 +49,7 @@ struct snd_hwdep_ops {
65996 struct snd_hwdep_dsp_status *status);
65997 int (*dsp_load)(struct snd_hwdep *hw,
65998 struct snd_hwdep_dsp_image *image);
65999-};
66000+} __no_const;
66001
66002 struct snd_hwdep {
66003 struct snd_card *card;
66004diff --git a/include/sound/info.h b/include/sound/info.h
66005index 9ca1a49..aba1728 100644
66006--- a/include/sound/info.h
66007+++ b/include/sound/info.h
66008@@ -44,7 +44,7 @@ struct snd_info_entry_text {
66009 struct snd_info_buffer *buffer);
66010 void (*write)(struct snd_info_entry *entry,
66011 struct snd_info_buffer *buffer);
66012-};
66013+} __no_const;
66014
66015 struct snd_info_entry_ops {
66016 int (*open)(struct snd_info_entry *entry,
66017diff --git a/include/sound/pcm.h b/include/sound/pcm.h
66018index cdca2ab..10bbe05 100644
66019--- a/include/sound/pcm.h
66020+++ b/include/sound/pcm.h
66021@@ -81,6 +81,7 @@ struct snd_pcm_ops {
66022 int (*mmap)(struct snd_pcm_substream *substream, struct vm_area_struct *vma);
66023 int (*ack)(struct snd_pcm_substream *substream);
66024 };
66025+typedef struct snd_pcm_ops __no_const snd_pcm_ops_no_const;
66026
66027 /*
66028 *
66029diff --git a/include/sound/sb16_csp.h b/include/sound/sb16_csp.h
66030index af1b49e..a5d55a5 100644
66031--- a/include/sound/sb16_csp.h
66032+++ b/include/sound/sb16_csp.h
66033@@ -146,7 +146,7 @@ struct snd_sb_csp_ops {
66034 int (*csp_start) (struct snd_sb_csp * p, int sample_width, int channels);
66035 int (*csp_stop) (struct snd_sb_csp * p);
66036 int (*csp_qsound_transfer) (struct snd_sb_csp * p);
66037-};
66038+} __no_const;
66039
66040 /*
66041 * CSP private data
66042diff --git a/include/sound/soc.h b/include/sound/soc.h
66043index e063380..e8077d5 100644
66044--- a/include/sound/soc.h
66045+++ b/include/sound/soc.h
66046@@ -801,7 +801,7 @@ struct snd_soc_platform_driver {
66047 unsigned int (*read)(struct snd_soc_platform *, unsigned int);
66048 int (*write)(struct snd_soc_platform *, unsigned int, unsigned int);
66049 int (*bespoke_trigger)(struct snd_pcm_substream *, int);
66050-};
66051+} __do_const;
66052
66053 struct snd_soc_platform {
66054 const char *name;
66055@@ -1016,7 +1016,7 @@ struct snd_soc_pcm_runtime {
66056 struct snd_soc_dai_link *dai_link;
66057 struct mutex pcm_mutex;
66058 enum snd_soc_pcm_subclass pcm_subclass;
66059- struct snd_pcm_ops ops;
66060+ snd_pcm_ops_no_const ops;
66061
66062 unsigned int dev_registered:1;
66063
66064diff --git a/include/sound/tea575x-tuner.h b/include/sound/tea575x-tuner.h
66065index fe8590c..aaed363 100644
66066--- a/include/sound/tea575x-tuner.h
66067+++ b/include/sound/tea575x-tuner.h
66068@@ -48,7 +48,7 @@ struct snd_tea575x_ops {
66069
66070 struct snd_tea575x {
66071 struct v4l2_device *v4l2_dev;
66072- struct v4l2_file_operations fops;
66073+ v4l2_file_operations_no_const fops;
66074 struct video_device vd; /* video device */
66075 int radio_nr; /* radio_nr */
66076 bool tea5759; /* 5759 chip is present */
66077diff --git a/include/target/target_core_base.h b/include/target/target_core_base.h
66078index 5be8937..a8e46e9 100644
66079--- a/include/target/target_core_base.h
66080+++ b/include/target/target_core_base.h
66081@@ -434,7 +434,7 @@ struct t10_reservation_ops {
66082 int (*t10_seq_non_holder)(struct se_cmd *, unsigned char *, u32);
66083 int (*t10_pr_register)(struct se_cmd *);
66084 int (*t10_pr_clear)(struct se_cmd *);
66085-};
66086+} __no_const;
66087
66088 struct t10_reservation {
66089 /* Reservation effects all target ports */
66090@@ -758,7 +758,7 @@ struct se_device {
66091 spinlock_t stats_lock;
66092 /* Active commands on this virtual SE device */
66093 atomic_t simple_cmds;
66094- atomic_t dev_ordered_id;
66095+ atomic_unchecked_t dev_ordered_id;
66096 atomic_t dev_ordered_sync;
66097 atomic_t dev_qf_count;
66098 struct se_obj dev_obj;
66099diff --git a/include/trace/events/fs.h b/include/trace/events/fs.h
66100new file mode 100644
66101index 0000000..2efe49d
66102--- /dev/null
66103+++ b/include/trace/events/fs.h
66104@@ -0,0 +1,53 @@
66105+#undef TRACE_SYSTEM
66106+#define TRACE_SYSTEM fs
66107+
66108+#if !defined(_TRACE_FS_H) || defined(TRACE_HEADER_MULTI_READ)
66109+#define _TRACE_FS_H
66110+
66111+#include <linux/fs.h>
66112+#include <linux/tracepoint.h>
66113+
66114+TRACE_EVENT(do_sys_open,
66115+
66116+ TP_PROTO(char *filename, int flags, int mode),
66117+
66118+ TP_ARGS(filename, flags, mode),
66119+
66120+ TP_STRUCT__entry(
66121+ __string( filename, filename )
66122+ __field( int, flags )
66123+ __field( int, mode )
66124+ ),
66125+
66126+ TP_fast_assign(
66127+ __assign_str(filename, filename);
66128+ __entry->flags = flags;
66129+ __entry->mode = mode;
66130+ ),
66131+
66132+ TP_printk("\"%s\" %x %o",
66133+ __get_str(filename), __entry->flags, __entry->mode)
66134+);
66135+
66136+TRACE_EVENT(open_exec,
66137+
66138+ TP_PROTO(const char *filename),
66139+
66140+ TP_ARGS(filename),
66141+
66142+ TP_STRUCT__entry(
66143+ __string( filename, filename )
66144+ ),
66145+
66146+ TP_fast_assign(
66147+ __assign_str(filename, filename);
66148+ ),
66149+
66150+ TP_printk("\"%s\"",
66151+ __get_str(filename))
66152+);
66153+
66154+#endif /* _TRACE_FS_H */
66155+
66156+/* This part must be outside protection */
66157+#include <trace/define_trace.h>
66158diff --git a/include/trace/events/irq.h b/include/trace/events/irq.h
66159index 1c09820..7f5ec79 100644
66160--- a/include/trace/events/irq.h
66161+++ b/include/trace/events/irq.h
66162@@ -36,7 +36,7 @@ struct softirq_action;
66163 */
66164 TRACE_EVENT(irq_handler_entry,
66165
66166- TP_PROTO(int irq, struct irqaction *action),
66167+ TP_PROTO(int irq, const struct irqaction *action),
66168
66169 TP_ARGS(irq, action),
66170
66171@@ -66,7 +66,7 @@ TRACE_EVENT(irq_handler_entry,
66172 */
66173 TRACE_EVENT(irq_handler_exit,
66174
66175- TP_PROTO(int irq, struct irqaction *action, int ret),
66176+ TP_PROTO(int irq, const struct irqaction *action, int ret),
66177
66178 TP_ARGS(irq, action, ret),
66179
66180diff --git a/include/video/udlfb.h b/include/video/udlfb.h
66181index f9466fa..f4e2b81 100644
66182--- a/include/video/udlfb.h
66183+++ b/include/video/udlfb.h
66184@@ -53,10 +53,10 @@ struct dlfb_data {
66185 u32 pseudo_palette[256];
66186 int blank_mode; /*one of FB_BLANK_ */
66187 /* blit-only rendering path metrics, exposed through sysfs */
66188- atomic_t bytes_rendered; /* raw pixel-bytes driver asked to render */
66189- atomic_t bytes_identical; /* saved effort with backbuffer comparison */
66190- atomic_t bytes_sent; /* to usb, after compression including overhead */
66191- atomic_t cpu_kcycles_used; /* transpired during pixel processing */
66192+ atomic_unchecked_t bytes_rendered; /* raw pixel-bytes driver asked to render */
66193+ atomic_unchecked_t bytes_identical; /* saved effort with backbuffer comparison */
66194+ atomic_unchecked_t bytes_sent; /* to usb, after compression including overhead */
66195+ atomic_unchecked_t cpu_kcycles_used; /* transpired during pixel processing */
66196 };
66197
66198 #define NR_USB_REQUEST_I2C_SUB_IO 0x02
66199diff --git a/include/video/uvesafb.h b/include/video/uvesafb.h
66200index 0993a22..32ba2fe 100644
66201--- a/include/video/uvesafb.h
66202+++ b/include/video/uvesafb.h
66203@@ -177,6 +177,7 @@ struct uvesafb_par {
66204 u8 ypan; /* 0 - nothing, 1 - ypan, 2 - ywrap */
66205 u8 pmi_setpal; /* PMI for palette changes */
66206 u16 *pmi_base; /* protected mode interface location */
66207+ u8 *pmi_code; /* protected mode code location */
66208 void *pmi_start;
66209 void *pmi_pal;
66210 u8 *vbe_state_orig; /*
66211diff --git a/init/Kconfig b/init/Kconfig
66212index af6c7f8..5c188f8 100644
66213--- a/init/Kconfig
66214+++ b/init/Kconfig
66215@@ -850,6 +850,7 @@ endif # CGROUPS
66216
66217 config CHECKPOINT_RESTORE
66218 bool "Checkpoint/restore support" if EXPERT
66219+ depends on !GRKERNSEC
66220 default n
66221 help
66222 Enables additional kernel features in a sake of checkpoint/restore.
66223@@ -1029,6 +1030,7 @@ config UIDGID_CONVERTED
66224 # Security modules
66225 depends on SECURITY_TOMOYO = n
66226 depends on SECURITY_APPARMOR = n
66227+ depends on GRKERNSEC = n
66228
66229 config UIDGID_STRICT_TYPE_CHECKS
66230 bool "Require conversions between uid/gids and their internal representation"
66231@@ -1416,7 +1418,7 @@ config SLUB_DEBUG
66232
66233 config COMPAT_BRK
66234 bool "Disable heap randomization"
66235- default y
66236+ default n
66237 help
66238 Randomizing heap placement makes heap exploits harder, but it
66239 also breaks ancient binaries (including anything libc5 based).
66240@@ -1599,7 +1601,7 @@ config INIT_ALL_POSSIBLE
66241 config STOP_MACHINE
66242 bool
66243 default y
66244- depends on (SMP && MODULE_UNLOAD) || HOTPLUG_CPU
66245+ depends on (SMP && MODULE_UNLOAD) || HOTPLUG_CPU || GRKERNSEC
66246 help
66247 Need stop_machine() primitive.
66248
66249diff --git a/init/Makefile b/init/Makefile
66250index 7bc47ee..6da2dc7 100644
66251--- a/init/Makefile
66252+++ b/init/Makefile
66253@@ -2,6 +2,9 @@
66254 # Makefile for the linux kernel.
66255 #
66256
66257+ccflags-y := $(GCC_PLUGINS_CFLAGS)
66258+asflags-y := $(GCC_PLUGINS_AFLAGS)
66259+
66260 obj-y := main.o version.o mounts.o
66261 ifneq ($(CONFIG_BLK_DEV_INITRD),y)
66262 obj-y += noinitramfs.o
66263diff --git a/init/do_mounts.c b/init/do_mounts.c
66264index d3f0aee..c9322f5 100644
66265--- a/init/do_mounts.c
66266+++ b/init/do_mounts.c
66267@@ -336,11 +336,11 @@ static void __init get_fs_names(char *page)
66268 static int __init do_mount_root(char *name, char *fs, int flags, void *data)
66269 {
66270 struct super_block *s;
66271- int err = sys_mount(name, "/root", fs, flags, data);
66272+ int err = sys_mount((char __force_user *)name, (char __force_user *)"/root", (char __force_user *)fs, flags, (void __force_user *)data);
66273 if (err)
66274 return err;
66275
66276- sys_chdir("/root");
66277+ sys_chdir((const char __force_user *)"/root");
66278 s = current->fs->pwd.dentry->d_sb;
66279 ROOT_DEV = s->s_dev;
66280 printk(KERN_INFO
66281@@ -460,18 +460,18 @@ void __init change_floppy(char *fmt, ...)
66282 va_start(args, fmt);
66283 vsprintf(buf, fmt, args);
66284 va_end(args);
66285- fd = sys_open("/dev/root", O_RDWR | O_NDELAY, 0);
66286+ fd = sys_open((char __user *)"/dev/root", O_RDWR | O_NDELAY, 0);
66287 if (fd >= 0) {
66288 sys_ioctl(fd, FDEJECT, 0);
66289 sys_close(fd);
66290 }
66291 printk(KERN_NOTICE "VFS: Insert %s and press ENTER\n", buf);
66292- fd = sys_open("/dev/console", O_RDWR, 0);
66293+ fd = sys_open((__force const char __user *)"/dev/console", O_RDWR, 0);
66294 if (fd >= 0) {
66295 sys_ioctl(fd, TCGETS, (long)&termios);
66296 termios.c_lflag &= ~ICANON;
66297 sys_ioctl(fd, TCSETSF, (long)&termios);
66298- sys_read(fd, &c, 1);
66299+ sys_read(fd, (char __user *)&c, 1);
66300 termios.c_lflag |= ICANON;
66301 sys_ioctl(fd, TCSETSF, (long)&termios);
66302 sys_close(fd);
66303@@ -565,6 +565,6 @@ void __init prepare_namespace(void)
66304 mount_root();
66305 out:
66306 devtmpfs_mount("dev");
66307- sys_mount(".", "/", NULL, MS_MOVE, NULL);
66308- sys_chroot(".");
66309+ sys_mount((char __force_user *)".", (char __force_user *)"/", NULL, MS_MOVE, NULL);
66310+ sys_chroot((const char __force_user *)".");
66311 }
66312diff --git a/init/do_mounts.h b/init/do_mounts.h
66313index f5b978a..69dbfe8 100644
66314--- a/init/do_mounts.h
66315+++ b/init/do_mounts.h
66316@@ -15,15 +15,15 @@ extern int root_mountflags;
66317
66318 static inline int create_dev(char *name, dev_t dev)
66319 {
66320- sys_unlink(name);
66321- return sys_mknod(name, S_IFBLK|0600, new_encode_dev(dev));
66322+ sys_unlink((char __force_user *)name);
66323+ return sys_mknod((char __force_user *)name, S_IFBLK|0600, new_encode_dev(dev));
66324 }
66325
66326 #if BITS_PER_LONG == 32
66327 static inline u32 bstat(char *name)
66328 {
66329 struct stat64 stat;
66330- if (sys_stat64(name, &stat) != 0)
66331+ if (sys_stat64((char __force_user *)name, (struct stat64 __force_user *)&stat) != 0)
66332 return 0;
66333 if (!S_ISBLK(stat.st_mode))
66334 return 0;
66335@@ -35,7 +35,7 @@ static inline u32 bstat(char *name)
66336 static inline u32 bstat(char *name)
66337 {
66338 struct stat stat;
66339- if (sys_newstat(name, &stat) != 0)
66340+ if (sys_newstat((const char __force_user *)name, (struct stat __force_user *)&stat) != 0)
66341 return 0;
66342 if (!S_ISBLK(stat.st_mode))
66343 return 0;
66344diff --git a/init/do_mounts_initrd.c b/init/do_mounts_initrd.c
66345index 135959a2..28a3f43 100644
66346--- a/init/do_mounts_initrd.c
66347+++ b/init/do_mounts_initrd.c
66348@@ -53,13 +53,13 @@ static void __init handle_initrd(void)
66349 create_dev("/dev/root.old", Root_RAM0);
66350 /* mount initrd on rootfs' /root */
66351 mount_block_root("/dev/root.old", root_mountflags & ~MS_RDONLY);
66352- sys_mkdir("/old", 0700);
66353- root_fd = sys_open("/", 0, 0);
66354- old_fd = sys_open("/old", 0, 0);
66355+ sys_mkdir((const char __force_user *)"/old", 0700);
66356+ root_fd = sys_open((const char __force_user *)"/", 0, 0);
66357+ old_fd = sys_open((const char __force_user *)"/old", 0, 0);
66358 /* move initrd over / and chdir/chroot in initrd root */
66359- sys_chdir("/root");
66360- sys_mount(".", "/", NULL, MS_MOVE, NULL);
66361- sys_chroot(".");
66362+ sys_chdir((const char __force_user *)"/root");
66363+ sys_mount((char __force_user *)".", (char __force_user *)"/", NULL, MS_MOVE, NULL);
66364+ sys_chroot((const char __force_user *)".");
66365
66366 /*
66367 * In case that a resume from disk is carried out by linuxrc or one of
66368@@ -76,15 +76,15 @@ static void __init handle_initrd(void)
66369
66370 /* move initrd to rootfs' /old */
66371 sys_fchdir(old_fd);
66372- sys_mount("/", ".", NULL, MS_MOVE, NULL);
66373+ sys_mount((char __force_user *)"/", (char __force_user *)".", NULL, MS_MOVE, NULL);
66374 /* switch root and cwd back to / of rootfs */
66375 sys_fchdir(root_fd);
66376- sys_chroot(".");
66377+ sys_chroot((const char __force_user *)".");
66378 sys_close(old_fd);
66379 sys_close(root_fd);
66380
66381 if (new_decode_dev(real_root_dev) == Root_RAM0) {
66382- sys_chdir("/old");
66383+ sys_chdir((const char __force_user *)"/old");
66384 return;
66385 }
66386
66387@@ -92,17 +92,17 @@ static void __init handle_initrd(void)
66388 mount_root();
66389
66390 printk(KERN_NOTICE "Trying to move old root to /initrd ... ");
66391- error = sys_mount("/old", "/root/initrd", NULL, MS_MOVE, NULL);
66392+ error = sys_mount((char __force_user *)"/old", (char __force_user *)"/root/initrd", NULL, MS_MOVE, NULL);
66393 if (!error)
66394 printk("okay\n");
66395 else {
66396- int fd = sys_open("/dev/root.old", O_RDWR, 0);
66397+ int fd = sys_open((const char __force_user *)"/dev/root.old", O_RDWR, 0);
66398 if (error == -ENOENT)
66399 printk("/initrd does not exist. Ignored.\n");
66400 else
66401 printk("failed\n");
66402 printk(KERN_NOTICE "Unmounting old root\n");
66403- sys_umount("/old", MNT_DETACH);
66404+ sys_umount((char __force_user *)"/old", MNT_DETACH);
66405 printk(KERN_NOTICE "Trying to free ramdisk memory ... ");
66406 if (fd < 0) {
66407 error = fd;
66408@@ -125,11 +125,11 @@ int __init initrd_load(void)
66409 * mounted in the normal path.
66410 */
66411 if (rd_load_image("/initrd.image") && ROOT_DEV != Root_RAM0) {
66412- sys_unlink("/initrd.image");
66413+ sys_unlink((const char __force_user *)"/initrd.image");
66414 handle_initrd();
66415 return 1;
66416 }
66417 }
66418- sys_unlink("/initrd.image");
66419+ sys_unlink((const char __force_user *)"/initrd.image");
66420 return 0;
66421 }
66422diff --git a/init/do_mounts_md.c b/init/do_mounts_md.c
66423index 8cb6db5..d729f50 100644
66424--- a/init/do_mounts_md.c
66425+++ b/init/do_mounts_md.c
66426@@ -180,7 +180,7 @@ static void __init md_setup_drive(void)
66427 partitioned ? "_d" : "", minor,
66428 md_setup_args[ent].device_names);
66429
66430- fd = sys_open(name, 0, 0);
66431+ fd = sys_open((char __force_user *)name, 0, 0);
66432 if (fd < 0) {
66433 printk(KERN_ERR "md: open failed - cannot start "
66434 "array %s\n", name);
66435@@ -243,7 +243,7 @@ static void __init md_setup_drive(void)
66436 * array without it
66437 */
66438 sys_close(fd);
66439- fd = sys_open(name, 0, 0);
66440+ fd = sys_open((char __force_user *)name, 0, 0);
66441 sys_ioctl(fd, BLKRRPART, 0);
66442 }
66443 sys_close(fd);
66444@@ -293,7 +293,7 @@ static void __init autodetect_raid(void)
66445
66446 wait_for_device_probe();
66447
66448- fd = sys_open("/dev/md0", 0, 0);
66449+ fd = sys_open((const char __force_user *) "/dev/md0", 0, 0);
66450 if (fd >= 0) {
66451 sys_ioctl(fd, RAID_AUTORUN, raid_autopart);
66452 sys_close(fd);
66453diff --git a/init/init_task.c b/init/init_task.c
66454index 8b2f399..f0797c9 100644
66455--- a/init/init_task.c
66456+++ b/init/init_task.c
66457@@ -20,5 +20,9 @@ EXPORT_SYMBOL(init_task);
66458 * Initial thread structure. Alignment of this is handled by a special
66459 * linker map entry.
66460 */
66461+#ifdef CONFIG_X86
66462+union thread_union init_thread_union __init_task_data;
66463+#else
66464 union thread_union init_thread_union __init_task_data =
66465 { INIT_THREAD_INFO(init_task) };
66466+#endif
66467diff --git a/init/initramfs.c b/init/initramfs.c
66468index 84c6bf1..8899338 100644
66469--- a/init/initramfs.c
66470+++ b/init/initramfs.c
66471@@ -84,7 +84,7 @@ static void __init free_hash(void)
66472 }
66473 }
66474
66475-static long __init do_utime(char *filename, time_t mtime)
66476+static long __init do_utime(char __force_user *filename, time_t mtime)
66477 {
66478 struct timespec t[2];
66479
66480@@ -119,7 +119,7 @@ static void __init dir_utime(void)
66481 struct dir_entry *de, *tmp;
66482 list_for_each_entry_safe(de, tmp, &dir_list, list) {
66483 list_del(&de->list);
66484- do_utime(de->name, de->mtime);
66485+ do_utime((char __force_user *)de->name, de->mtime);
66486 kfree(de->name);
66487 kfree(de);
66488 }
66489@@ -281,7 +281,7 @@ static int __init maybe_link(void)
66490 if (nlink >= 2) {
66491 char *old = find_link(major, minor, ino, mode, collected);
66492 if (old)
66493- return (sys_link(old, collected) < 0) ? -1 : 1;
66494+ return (sys_link((char __force_user *)old, (char __force_user *)collected) < 0) ? -1 : 1;
66495 }
66496 return 0;
66497 }
66498@@ -290,11 +290,11 @@ static void __init clean_path(char *path, umode_t mode)
66499 {
66500 struct stat st;
66501
66502- if (!sys_newlstat(path, &st) && (st.st_mode^mode) & S_IFMT) {
66503+ if (!sys_newlstat((char __force_user *)path, (struct stat __force_user *)&st) && (st.st_mode^mode) & S_IFMT) {
66504 if (S_ISDIR(st.st_mode))
66505- sys_rmdir(path);
66506+ sys_rmdir((char __force_user *)path);
66507 else
66508- sys_unlink(path);
66509+ sys_unlink((char __force_user *)path);
66510 }
66511 }
66512
66513@@ -315,7 +315,7 @@ static int __init do_name(void)
66514 int openflags = O_WRONLY|O_CREAT;
66515 if (ml != 1)
66516 openflags |= O_TRUNC;
66517- wfd = sys_open(collected, openflags, mode);
66518+ wfd = sys_open((char __force_user *)collected, openflags, mode);
66519
66520 if (wfd >= 0) {
66521 sys_fchown(wfd, uid, gid);
66522@@ -327,17 +327,17 @@ static int __init do_name(void)
66523 }
66524 }
66525 } else if (S_ISDIR(mode)) {
66526- sys_mkdir(collected, mode);
66527- sys_chown(collected, uid, gid);
66528- sys_chmod(collected, mode);
66529+ sys_mkdir((char __force_user *)collected, mode);
66530+ sys_chown((char __force_user *)collected, uid, gid);
66531+ sys_chmod((char __force_user *)collected, mode);
66532 dir_add(collected, mtime);
66533 } else if (S_ISBLK(mode) || S_ISCHR(mode) ||
66534 S_ISFIFO(mode) || S_ISSOCK(mode)) {
66535 if (maybe_link() == 0) {
66536- sys_mknod(collected, mode, rdev);
66537- sys_chown(collected, uid, gid);
66538- sys_chmod(collected, mode);
66539- do_utime(collected, mtime);
66540+ sys_mknod((char __force_user *)collected, mode, rdev);
66541+ sys_chown((char __force_user *)collected, uid, gid);
66542+ sys_chmod((char __force_user *)collected, mode);
66543+ do_utime((char __force_user *)collected, mtime);
66544 }
66545 }
66546 return 0;
66547@@ -346,15 +346,15 @@ static int __init do_name(void)
66548 static int __init do_copy(void)
66549 {
66550 if (count >= body_len) {
66551- sys_write(wfd, victim, body_len);
66552+ sys_write(wfd, (char __force_user *)victim, body_len);
66553 sys_close(wfd);
66554- do_utime(vcollected, mtime);
66555+ do_utime((char __force_user *)vcollected, mtime);
66556 kfree(vcollected);
66557 eat(body_len);
66558 state = SkipIt;
66559 return 0;
66560 } else {
66561- sys_write(wfd, victim, count);
66562+ sys_write(wfd, (char __force_user *)victim, count);
66563 body_len -= count;
66564 eat(count);
66565 return 1;
66566@@ -365,9 +365,9 @@ static int __init do_symlink(void)
66567 {
66568 collected[N_ALIGN(name_len) + body_len] = '\0';
66569 clean_path(collected, 0);
66570- sys_symlink(collected + N_ALIGN(name_len), collected);
66571- sys_lchown(collected, uid, gid);
66572- do_utime(collected, mtime);
66573+ sys_symlink((char __force_user *)collected + N_ALIGN(name_len), (char __force_user *)collected);
66574+ sys_lchown((char __force_user *)collected, uid, gid);
66575+ do_utime((char __force_user *)collected, mtime);
66576 state = SkipIt;
66577 next_state = Reset;
66578 return 0;
66579diff --git a/init/main.c b/init/main.c
66580index d61ec54..bd3144f 100644
66581--- a/init/main.c
66582+++ b/init/main.c
66583@@ -96,6 +96,8 @@ static inline void mark_rodata_ro(void) { }
66584 extern void tc_init(void);
66585 #endif
66586
66587+extern void grsecurity_init(void);
66588+
66589 /*
66590 * Debug helper: via this flag we know that we are in 'early bootup code'
66591 * where only the boot processor is running with IRQ disabled. This means
66592@@ -149,6 +151,61 @@ static int __init set_reset_devices(char *str)
66593
66594 __setup("reset_devices", set_reset_devices);
66595
66596+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
66597+int grsec_proc_gid = CONFIG_GRKERNSEC_PROC_GID;
66598+static int __init setup_grsec_proc_gid(char *str)
66599+{
66600+ grsec_proc_gid = (int)simple_strtol(str, NULL, 0);
66601+ return 1;
66602+}
66603+__setup("grsec_proc_gid=", setup_grsec_proc_gid);
66604+#endif
66605+
66606+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
66607+extern char pax_enter_kernel_user[];
66608+extern char pax_exit_kernel_user[];
66609+extern pgdval_t clone_pgd_mask;
66610+#endif
66611+
66612+#if defined(CONFIG_X86) && defined(CONFIG_PAX_MEMORY_UDEREF)
66613+static int __init setup_pax_nouderef(char *str)
66614+{
66615+#ifdef CONFIG_X86_32
66616+ unsigned int cpu;
66617+ struct desc_struct *gdt;
66618+
66619+ for (cpu = 0; cpu < nr_cpu_ids; cpu++) {
66620+ gdt = get_cpu_gdt_table(cpu);
66621+ gdt[GDT_ENTRY_KERNEL_DS].type = 3;
66622+ gdt[GDT_ENTRY_KERNEL_DS].limit = 0xf;
66623+ gdt[GDT_ENTRY_DEFAULT_USER_CS].limit = 0xf;
66624+ gdt[GDT_ENTRY_DEFAULT_USER_DS].limit = 0xf;
66625+ }
66626+ loadsegment(ds, __KERNEL_DS);
66627+ loadsegment(es, __KERNEL_DS);
66628+ loadsegment(ss, __KERNEL_DS);
66629+#else
66630+ memcpy(pax_enter_kernel_user, (unsigned char []){0xc3}, 1);
66631+ memcpy(pax_exit_kernel_user, (unsigned char []){0xc3}, 1);
66632+ clone_pgd_mask = ~(pgdval_t)0UL;
66633+#endif
66634+
66635+ return 0;
66636+}
66637+early_param("pax_nouderef", setup_pax_nouderef);
66638+#endif
66639+
66640+#ifdef CONFIG_PAX_SOFTMODE
66641+int pax_softmode;
66642+
66643+static int __init setup_pax_softmode(char *str)
66644+{
66645+ get_option(&str, &pax_softmode);
66646+ return 1;
66647+}
66648+__setup("pax_softmode=", setup_pax_softmode);
66649+#endif
66650+
66651 static const char * argv_init[MAX_INIT_ARGS+2] = { "init", NULL, };
66652 const char * envp_init[MAX_INIT_ENVS+2] = { "HOME=/", "TERM=linux", NULL, };
66653 static const char *panic_later, *panic_param;
66654@@ -678,6 +735,7 @@ int __init_or_module do_one_initcall(initcall_t fn)
66655 {
66656 int count = preempt_count();
66657 int ret;
66658+ const char *msg1 = "", *msg2 = "";
66659
66660 if (initcall_debug)
66661 ret = do_one_initcall_debug(fn);
66662@@ -690,15 +748,15 @@ int __init_or_module do_one_initcall(initcall_t fn)
66663 sprintf(msgbuf, "error code %d ", ret);
66664
66665 if (preempt_count() != count) {
66666- strlcat(msgbuf, "preemption imbalance ", sizeof(msgbuf));
66667+ msg1 = " preemption imbalance";
66668 preempt_count() = count;
66669 }
66670 if (irqs_disabled()) {
66671- strlcat(msgbuf, "disabled interrupts ", sizeof(msgbuf));
66672+ msg2 = " disabled interrupts";
66673 local_irq_enable();
66674 }
66675- if (msgbuf[0]) {
66676- printk("initcall %pF returned with %s\n", fn, msgbuf);
66677+ if (msgbuf[0] || *msg1 || *msg2) {
66678+ printk("initcall %pF returned with %s%s%s\n", fn, msgbuf, msg1, msg2);
66679 }
66680
66681 return ret;
66682@@ -752,8 +810,14 @@ static void __init do_initcall_level(int level)
66683 level, level,
66684 &repair_env_string);
66685
66686- for (fn = initcall_levels[level]; fn < initcall_levels[level+1]; fn++)
66687+ for (fn = initcall_levels[level]; fn < initcall_levels[level+1]; fn++) {
66688 do_one_initcall(*fn);
66689+
66690+#ifdef CONFIG_PAX_LATENT_ENTROPY
66691+ transfer_latent_entropy();
66692+#endif
66693+
66694+ }
66695 }
66696
66697 static void __init do_initcalls(void)
66698@@ -787,8 +851,14 @@ static void __init do_pre_smp_initcalls(void)
66699 {
66700 initcall_t *fn;
66701
66702- for (fn = __initcall_start; fn < __initcall0_start; fn++)
66703+ for (fn = __initcall_start; fn < __initcall0_start; fn++) {
66704 do_one_initcall(*fn);
66705+
66706+#ifdef CONFIG_PAX_LATENT_ENTROPY
66707+ transfer_latent_entropy();
66708+#endif
66709+
66710+ }
66711 }
66712
66713 static void run_init_process(const char *init_filename)
66714@@ -870,7 +940,7 @@ static int __init kernel_init(void * unused)
66715 do_basic_setup();
66716
66717 /* Open the /dev/console on the rootfs, this should never fail */
66718- if (sys_open((const char __user *) "/dev/console", O_RDWR, 0) < 0)
66719+ if (sys_open((const char __force_user *) "/dev/console", O_RDWR, 0) < 0)
66720 printk(KERN_WARNING "Warning: unable to open an initial console.\n");
66721
66722 (void) sys_dup(0);
66723@@ -883,11 +953,13 @@ static int __init kernel_init(void * unused)
66724 if (!ramdisk_execute_command)
66725 ramdisk_execute_command = "/init";
66726
66727- if (sys_access((const char __user *) ramdisk_execute_command, 0) != 0) {
66728+ if (sys_access((const char __force_user *) ramdisk_execute_command, 0) != 0) {
66729 ramdisk_execute_command = NULL;
66730 prepare_namespace();
66731 }
66732
66733+ grsecurity_init();
66734+
66735 /*
66736 * Ok, we have completed the initial bootup, and
66737 * we're essentially up and running. Get rid of the
66738diff --git a/ipc/mqueue.c b/ipc/mqueue.c
66739index 9a08acc..e65ebe7 100644
66740--- a/ipc/mqueue.c
66741+++ b/ipc/mqueue.c
66742@@ -279,6 +279,7 @@ static struct inode *mqueue_get_inode(struct super_block *sb,
66743 mq_bytes = mq_treesize + (info->attr.mq_maxmsg *
66744 info->attr.mq_msgsize);
66745
66746+ gr_learn_resource(current, RLIMIT_MSGQUEUE, u->mq_bytes + mq_bytes, 1);
66747 spin_lock(&mq_lock);
66748 if (u->mq_bytes + mq_bytes < u->mq_bytes ||
66749 u->mq_bytes + mq_bytes > rlimit(RLIMIT_MSGQUEUE)) {
66750diff --git a/ipc/msg.c b/ipc/msg.c
66751index 7385de2..a8180e08 100644
66752--- a/ipc/msg.c
66753+++ b/ipc/msg.c
66754@@ -309,18 +309,19 @@ static inline int msg_security(struct kern_ipc_perm *ipcp, int msgflg)
66755 return security_msg_queue_associate(msq, msgflg);
66756 }
66757
66758+static struct ipc_ops msg_ops = {
66759+ .getnew = newque,
66760+ .associate = msg_security,
66761+ .more_checks = NULL
66762+};
66763+
66764 SYSCALL_DEFINE2(msgget, key_t, key, int, msgflg)
66765 {
66766 struct ipc_namespace *ns;
66767- struct ipc_ops msg_ops;
66768 struct ipc_params msg_params;
66769
66770 ns = current->nsproxy->ipc_ns;
66771
66772- msg_ops.getnew = newque;
66773- msg_ops.associate = msg_security;
66774- msg_ops.more_checks = NULL;
66775-
66776 msg_params.key = key;
66777 msg_params.flg = msgflg;
66778
66779diff --git a/ipc/sem.c b/ipc/sem.c
66780index 5215a81..cfc0cac 100644
66781--- a/ipc/sem.c
66782+++ b/ipc/sem.c
66783@@ -364,10 +364,15 @@ static inline int sem_more_checks(struct kern_ipc_perm *ipcp,
66784 return 0;
66785 }
66786
66787+static struct ipc_ops sem_ops = {
66788+ .getnew = newary,
66789+ .associate = sem_security,
66790+ .more_checks = sem_more_checks
66791+};
66792+
66793 SYSCALL_DEFINE3(semget, key_t, key, int, nsems, int, semflg)
66794 {
66795 struct ipc_namespace *ns;
66796- struct ipc_ops sem_ops;
66797 struct ipc_params sem_params;
66798
66799 ns = current->nsproxy->ipc_ns;
66800@@ -375,10 +380,6 @@ SYSCALL_DEFINE3(semget, key_t, key, int, nsems, int, semflg)
66801 if (nsems < 0 || nsems > ns->sc_semmsl)
66802 return -EINVAL;
66803
66804- sem_ops.getnew = newary;
66805- sem_ops.associate = sem_security;
66806- sem_ops.more_checks = sem_more_checks;
66807-
66808 sem_params.key = key;
66809 sem_params.flg = semflg;
66810 sem_params.u.nsems = nsems;
66811diff --git a/ipc/shm.c b/ipc/shm.c
66812index 00faa05..7040960 100644
66813--- a/ipc/shm.c
66814+++ b/ipc/shm.c
66815@@ -69,6 +69,14 @@ static void shm_destroy (struct ipc_namespace *ns, struct shmid_kernel *shp);
66816 static int sysvipc_shm_proc_show(struct seq_file *s, void *it);
66817 #endif
66818
66819+#ifdef CONFIG_GRKERNSEC
66820+extern int gr_handle_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
66821+ const time_t shm_createtime, const uid_t cuid,
66822+ const int shmid);
66823+extern int gr_chroot_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
66824+ const time_t shm_createtime);
66825+#endif
66826+
66827 void shm_init_ns(struct ipc_namespace *ns)
66828 {
66829 ns->shm_ctlmax = SHMMAX;
66830@@ -520,6 +528,14 @@ static int newseg(struct ipc_namespace *ns, struct ipc_params *params)
66831 shp->shm_lprid = 0;
66832 shp->shm_atim = shp->shm_dtim = 0;
66833 shp->shm_ctim = get_seconds();
66834+#ifdef CONFIG_GRKERNSEC
66835+ {
66836+ struct timespec timeval;
66837+ do_posix_clock_monotonic_gettime(&timeval);
66838+
66839+ shp->shm_createtime = timeval.tv_sec;
66840+ }
66841+#endif
66842 shp->shm_segsz = size;
66843 shp->shm_nattch = 0;
66844 shp->shm_file = file;
66845@@ -571,18 +587,19 @@ static inline int shm_more_checks(struct kern_ipc_perm *ipcp,
66846 return 0;
66847 }
66848
66849+static struct ipc_ops shm_ops = {
66850+ .getnew = newseg,
66851+ .associate = shm_security,
66852+ .more_checks = shm_more_checks
66853+};
66854+
66855 SYSCALL_DEFINE3(shmget, key_t, key, size_t, size, int, shmflg)
66856 {
66857 struct ipc_namespace *ns;
66858- struct ipc_ops shm_ops;
66859 struct ipc_params shm_params;
66860
66861 ns = current->nsproxy->ipc_ns;
66862
66863- shm_ops.getnew = newseg;
66864- shm_ops.associate = shm_security;
66865- shm_ops.more_checks = shm_more_checks;
66866-
66867 shm_params.key = key;
66868 shm_params.flg = shmflg;
66869 shm_params.u.size = size;
66870@@ -1001,6 +1018,12 @@ long do_shmat(int shmid, char __user *shmaddr, int shmflg, ulong *raddr,
66871 f_mode = FMODE_READ | FMODE_WRITE;
66872 }
66873 if (shmflg & SHM_EXEC) {
66874+
66875+#ifdef CONFIG_PAX_MPROTECT
66876+ if (current->mm->pax_flags & MF_PAX_MPROTECT)
66877+ goto out;
66878+#endif
66879+
66880 prot |= PROT_EXEC;
66881 acc_mode |= S_IXUGO;
66882 }
66883@@ -1024,9 +1047,21 @@ long do_shmat(int shmid, char __user *shmaddr, int shmflg, ulong *raddr,
66884 if (err)
66885 goto out_unlock;
66886
66887+#ifdef CONFIG_GRKERNSEC
66888+ if (!gr_handle_shmat(shp->shm_cprid, shp->shm_lapid, shp->shm_createtime,
66889+ shp->shm_perm.cuid, shmid) ||
66890+ !gr_chroot_shmat(shp->shm_cprid, shp->shm_lapid, shp->shm_createtime)) {
66891+ err = -EACCES;
66892+ goto out_unlock;
66893+ }
66894+#endif
66895+
66896 path = shp->shm_file->f_path;
66897 path_get(&path);
66898 shp->shm_nattch++;
66899+#ifdef CONFIG_GRKERNSEC
66900+ shp->shm_lapid = current->pid;
66901+#endif
66902 size = i_size_read(path.dentry->d_inode);
66903 shm_unlock(shp);
66904
66905diff --git a/kernel/acct.c b/kernel/acct.c
66906index 02e6167..54824f7 100644
66907--- a/kernel/acct.c
66908+++ b/kernel/acct.c
66909@@ -550,7 +550,7 @@ static void do_acct_process(struct bsd_acct_struct *acct,
66910 */
66911 flim = current->signal->rlim[RLIMIT_FSIZE].rlim_cur;
66912 current->signal->rlim[RLIMIT_FSIZE].rlim_cur = RLIM_INFINITY;
66913- file->f_op->write(file, (char *)&ac,
66914+ file->f_op->write(file, (char __force_user *)&ac,
66915 sizeof(acct_t), &file->f_pos);
66916 current->signal->rlim[RLIMIT_FSIZE].rlim_cur = flim;
66917 set_fs(fs);
66918diff --git a/kernel/audit.c b/kernel/audit.c
66919index a8c84be..8bd034c 100644
66920--- a/kernel/audit.c
66921+++ b/kernel/audit.c
66922@@ -115,7 +115,7 @@ u32 audit_sig_sid = 0;
66923 3) suppressed due to audit_rate_limit
66924 4) suppressed due to audit_backlog_limit
66925 */
66926-static atomic_t audit_lost = ATOMIC_INIT(0);
66927+static atomic_unchecked_t audit_lost = ATOMIC_INIT(0);
66928
66929 /* The netlink socket. */
66930 static struct sock *audit_sock;
66931@@ -237,7 +237,7 @@ void audit_log_lost(const char *message)
66932 unsigned long now;
66933 int print;
66934
66935- atomic_inc(&audit_lost);
66936+ atomic_inc_unchecked(&audit_lost);
66937
66938 print = (audit_failure == AUDIT_FAIL_PANIC || !audit_rate_limit);
66939
66940@@ -256,7 +256,7 @@ void audit_log_lost(const char *message)
66941 printk(KERN_WARNING
66942 "audit: audit_lost=%d audit_rate_limit=%d "
66943 "audit_backlog_limit=%d\n",
66944- atomic_read(&audit_lost),
66945+ atomic_read_unchecked(&audit_lost),
66946 audit_rate_limit,
66947 audit_backlog_limit);
66948 audit_panic(message);
66949@@ -690,7 +690,7 @@ static int audit_receive_msg(struct sk_buff *skb, struct nlmsghdr *nlh)
66950 status_set.pid = audit_pid;
66951 status_set.rate_limit = audit_rate_limit;
66952 status_set.backlog_limit = audit_backlog_limit;
66953- status_set.lost = atomic_read(&audit_lost);
66954+ status_set.lost = atomic_read_unchecked(&audit_lost);
66955 status_set.backlog = skb_queue_len(&audit_skb_queue);
66956 audit_send_reply(NETLINK_CB(skb).pid, seq, AUDIT_GET, 0, 0,
66957 &status_set, sizeof(status_set));
66958diff --git a/kernel/auditsc.c b/kernel/auditsc.c
66959index 4b96415..d8c16ee 100644
66960--- a/kernel/auditsc.c
66961+++ b/kernel/auditsc.c
66962@@ -2289,7 +2289,7 @@ int auditsc_get_stamp(struct audit_context *ctx,
66963 }
66964
66965 /* global counter which is incremented every time something logs in */
66966-static atomic_t session_id = ATOMIC_INIT(0);
66967+static atomic_unchecked_t session_id = ATOMIC_INIT(0);
66968
66969 /**
66970 * audit_set_loginuid - set current task's audit_context loginuid
66971@@ -2313,7 +2313,7 @@ int audit_set_loginuid(uid_t loginuid)
66972 return -EPERM;
66973 #endif /* CONFIG_AUDIT_LOGINUID_IMMUTABLE */
66974
66975- sessionid = atomic_inc_return(&session_id);
66976+ sessionid = atomic_inc_return_unchecked(&session_id);
66977 if (context && context->in_syscall) {
66978 struct audit_buffer *ab;
66979
66980diff --git a/kernel/capability.c b/kernel/capability.c
66981index 493d972..ea17248 100644
66982--- a/kernel/capability.c
66983+++ b/kernel/capability.c
66984@@ -202,6 +202,9 @@ SYSCALL_DEFINE2(capget, cap_user_header_t, header, cap_user_data_t, dataptr)
66985 * before modification is attempted and the application
66986 * fails.
66987 */
66988+ if (tocopy > ARRAY_SIZE(kdata))
66989+ return -EFAULT;
66990+
66991 if (copy_to_user(dataptr, kdata, tocopy
66992 * sizeof(struct __user_cap_data_struct))) {
66993 return -EFAULT;
66994@@ -303,10 +306,11 @@ bool has_ns_capability(struct task_struct *t,
66995 int ret;
66996
66997 rcu_read_lock();
66998- ret = security_capable(__task_cred(t), ns, cap);
66999+ ret = security_capable(__task_cred(t), ns, cap) == 0 &&
67000+ gr_task_is_capable(t, __task_cred(t), cap);
67001 rcu_read_unlock();
67002
67003- return (ret == 0);
67004+ return ret;
67005 }
67006
67007 /**
67008@@ -343,10 +347,10 @@ bool has_ns_capability_noaudit(struct task_struct *t,
67009 int ret;
67010
67011 rcu_read_lock();
67012- ret = security_capable_noaudit(__task_cred(t), ns, cap);
67013+ ret = security_capable_noaudit(__task_cred(t), ns, cap) == 0 && gr_task_is_capable_nolog(t, cap);
67014 rcu_read_unlock();
67015
67016- return (ret == 0);
67017+ return ret;
67018 }
67019
67020 /**
67021@@ -384,7 +388,7 @@ bool ns_capable(struct user_namespace *ns, int cap)
67022 BUG();
67023 }
67024
67025- if (security_capable(current_cred(), ns, cap) == 0) {
67026+ if (security_capable(current_cred(), ns, cap) == 0 && gr_is_capable(cap)) {
67027 current->flags |= PF_SUPERPRIV;
67028 return true;
67029 }
67030@@ -392,6 +396,21 @@ bool ns_capable(struct user_namespace *ns, int cap)
67031 }
67032 EXPORT_SYMBOL(ns_capable);
67033
67034+bool ns_capable_nolog(struct user_namespace *ns, int cap)
67035+{
67036+ if (unlikely(!cap_valid(cap))) {
67037+ printk(KERN_CRIT "capable() called with invalid cap=%u\n", cap);
67038+ BUG();
67039+ }
67040+
67041+ if (security_capable(current_cred(), ns, cap) == 0 && gr_is_capable_nolog(cap)) {
67042+ current->flags |= PF_SUPERPRIV;
67043+ return true;
67044+ }
67045+ return false;
67046+}
67047+EXPORT_SYMBOL(ns_capable_nolog);
67048+
67049 /**
67050 * capable - Determine if the current task has a superior capability in effect
67051 * @cap: The capability to be tested for
67052@@ -408,6 +427,12 @@ bool capable(int cap)
67053 }
67054 EXPORT_SYMBOL(capable);
67055
67056+bool capable_nolog(int cap)
67057+{
67058+ return ns_capable_nolog(&init_user_ns, cap);
67059+}
67060+EXPORT_SYMBOL(capable_nolog);
67061+
67062 /**
67063 * nsown_capable - Check superior capability to one's own user_ns
67064 * @cap: The capability in question
67065@@ -440,3 +465,10 @@ bool inode_capable(const struct inode *inode, int cap)
67066
67067 return ns_capable(ns, cap) && kuid_has_mapping(ns, inode->i_uid);
67068 }
67069+
67070+bool inode_capable_nolog(const struct inode *inode, int cap)
67071+{
67072+ struct user_namespace *ns = current_user_ns();
67073+
67074+ return ns_capable_nolog(ns, cap) && kuid_has_mapping(ns, inode->i_uid);
67075+}
67076diff --git a/kernel/cgroup.c b/kernel/cgroup.c
67077index ff2bce5..a41e8f9 100644
67078--- a/kernel/cgroup.c
67079+++ b/kernel/cgroup.c
67080@@ -5390,7 +5390,7 @@ static int cgroup_css_links_read(struct cgroup *cont,
67081 struct css_set *cg = link->cg;
67082 struct task_struct *task;
67083 int count = 0;
67084- seq_printf(seq, "css_set %p\n", cg);
67085+ seq_printf(seq, "css_set %pK\n", cg);
67086 list_for_each_entry(task, &cg->tasks, cg_list) {
67087 if (count++ > MAX_TASKS_SHOWN_PER_CSS) {
67088 seq_puts(seq, " ...\n");
67089diff --git a/kernel/compat.c b/kernel/compat.c
67090index c28a306..b4d0cf3 100644
67091--- a/kernel/compat.c
67092+++ b/kernel/compat.c
67093@@ -13,6 +13,7 @@
67094
67095 #include <linux/linkage.h>
67096 #include <linux/compat.h>
67097+#include <linux/module.h>
67098 #include <linux/errno.h>
67099 #include <linux/time.h>
67100 #include <linux/signal.h>
67101@@ -220,7 +221,7 @@ static long compat_nanosleep_restart(struct restart_block *restart)
67102 mm_segment_t oldfs;
67103 long ret;
67104
67105- restart->nanosleep.rmtp = (struct timespec __user *) &rmt;
67106+ restart->nanosleep.rmtp = (struct timespec __force_user *) &rmt;
67107 oldfs = get_fs();
67108 set_fs(KERNEL_DS);
67109 ret = hrtimer_nanosleep_restart(restart);
67110@@ -252,7 +253,7 @@ asmlinkage long compat_sys_nanosleep(struct compat_timespec __user *rqtp,
67111 oldfs = get_fs();
67112 set_fs(KERNEL_DS);
67113 ret = hrtimer_nanosleep(&tu,
67114- rmtp ? (struct timespec __user *)&rmt : NULL,
67115+ rmtp ? (struct timespec __force_user *)&rmt : NULL,
67116 HRTIMER_MODE_REL, CLOCK_MONOTONIC);
67117 set_fs(oldfs);
67118
67119@@ -361,7 +362,7 @@ asmlinkage long compat_sys_sigpending(compat_old_sigset_t __user *set)
67120 mm_segment_t old_fs = get_fs();
67121
67122 set_fs(KERNEL_DS);
67123- ret = sys_sigpending((old_sigset_t __user *) &s);
67124+ ret = sys_sigpending((old_sigset_t __force_user *) &s);
67125 set_fs(old_fs);
67126 if (ret == 0)
67127 ret = put_user(s, set);
67128@@ -451,7 +452,7 @@ asmlinkage long compat_sys_old_getrlimit(unsigned int resource,
67129 mm_segment_t old_fs = get_fs();
67130
67131 set_fs(KERNEL_DS);
67132- ret = sys_old_getrlimit(resource, &r);
67133+ ret = sys_old_getrlimit(resource, (struct rlimit __force_user *)&r);
67134 set_fs(old_fs);
67135
67136 if (!ret) {
67137@@ -523,7 +524,7 @@ asmlinkage long compat_sys_getrusage(int who, struct compat_rusage __user *ru)
67138 mm_segment_t old_fs = get_fs();
67139
67140 set_fs(KERNEL_DS);
67141- ret = sys_getrusage(who, (struct rusage __user *) &r);
67142+ ret = sys_getrusage(who, (struct rusage __force_user *) &r);
67143 set_fs(old_fs);
67144
67145 if (ret)
67146@@ -550,8 +551,8 @@ compat_sys_wait4(compat_pid_t pid, compat_uint_t __user *stat_addr, int options,
67147 set_fs (KERNEL_DS);
67148 ret = sys_wait4(pid,
67149 (stat_addr ?
67150- (unsigned int __user *) &status : NULL),
67151- options, (struct rusage __user *) &r);
67152+ (unsigned int __force_user *) &status : NULL),
67153+ options, (struct rusage __force_user *) &r);
67154 set_fs (old_fs);
67155
67156 if (ret > 0) {
67157@@ -576,8 +577,8 @@ asmlinkage long compat_sys_waitid(int which, compat_pid_t pid,
67158 memset(&info, 0, sizeof(info));
67159
67160 set_fs(KERNEL_DS);
67161- ret = sys_waitid(which, pid, (siginfo_t __user *)&info, options,
67162- uru ? (struct rusage __user *)&ru : NULL);
67163+ ret = sys_waitid(which, pid, (siginfo_t __force_user *)&info, options,
67164+ uru ? (struct rusage __force_user *)&ru : NULL);
67165 set_fs(old_fs);
67166
67167 if ((ret < 0) || (info.si_signo == 0))
67168@@ -707,8 +708,8 @@ long compat_sys_timer_settime(timer_t timer_id, int flags,
67169 oldfs = get_fs();
67170 set_fs(KERNEL_DS);
67171 err = sys_timer_settime(timer_id, flags,
67172- (struct itimerspec __user *) &newts,
67173- (struct itimerspec __user *) &oldts);
67174+ (struct itimerspec __force_user *) &newts,
67175+ (struct itimerspec __force_user *) &oldts);
67176 set_fs(oldfs);
67177 if (!err && old && put_compat_itimerspec(old, &oldts))
67178 return -EFAULT;
67179@@ -725,7 +726,7 @@ long compat_sys_timer_gettime(timer_t timer_id,
67180 oldfs = get_fs();
67181 set_fs(KERNEL_DS);
67182 err = sys_timer_gettime(timer_id,
67183- (struct itimerspec __user *) &ts);
67184+ (struct itimerspec __force_user *) &ts);
67185 set_fs(oldfs);
67186 if (!err && put_compat_itimerspec(setting, &ts))
67187 return -EFAULT;
67188@@ -744,7 +745,7 @@ long compat_sys_clock_settime(clockid_t which_clock,
67189 oldfs = get_fs();
67190 set_fs(KERNEL_DS);
67191 err = sys_clock_settime(which_clock,
67192- (struct timespec __user *) &ts);
67193+ (struct timespec __force_user *) &ts);
67194 set_fs(oldfs);
67195 return err;
67196 }
67197@@ -759,7 +760,7 @@ long compat_sys_clock_gettime(clockid_t which_clock,
67198 oldfs = get_fs();
67199 set_fs(KERNEL_DS);
67200 err = sys_clock_gettime(which_clock,
67201- (struct timespec __user *) &ts);
67202+ (struct timespec __force_user *) &ts);
67203 set_fs(oldfs);
67204 if (!err && put_compat_timespec(&ts, tp))
67205 return -EFAULT;
67206@@ -779,7 +780,7 @@ long compat_sys_clock_adjtime(clockid_t which_clock,
67207
67208 oldfs = get_fs();
67209 set_fs(KERNEL_DS);
67210- ret = sys_clock_adjtime(which_clock, (struct timex __user *) &txc);
67211+ ret = sys_clock_adjtime(which_clock, (struct timex __force_user *) &txc);
67212 set_fs(oldfs);
67213
67214 err = compat_put_timex(utp, &txc);
67215@@ -799,7 +800,7 @@ long compat_sys_clock_getres(clockid_t which_clock,
67216 oldfs = get_fs();
67217 set_fs(KERNEL_DS);
67218 err = sys_clock_getres(which_clock,
67219- (struct timespec __user *) &ts);
67220+ (struct timespec __force_user *) &ts);
67221 set_fs(oldfs);
67222 if (!err && tp && put_compat_timespec(&ts, tp))
67223 return -EFAULT;
67224@@ -811,9 +812,9 @@ static long compat_clock_nanosleep_restart(struct restart_block *restart)
67225 long err;
67226 mm_segment_t oldfs;
67227 struct timespec tu;
67228- struct compat_timespec *rmtp = restart->nanosleep.compat_rmtp;
67229+ struct compat_timespec __user *rmtp = restart->nanosleep.compat_rmtp;
67230
67231- restart->nanosleep.rmtp = (struct timespec __user *) &tu;
67232+ restart->nanosleep.rmtp = (struct timespec __force_user *) &tu;
67233 oldfs = get_fs();
67234 set_fs(KERNEL_DS);
67235 err = clock_nanosleep_restart(restart);
67236@@ -845,8 +846,8 @@ long compat_sys_clock_nanosleep(clockid_t which_clock, int flags,
67237 oldfs = get_fs();
67238 set_fs(KERNEL_DS);
67239 err = sys_clock_nanosleep(which_clock, flags,
67240- (struct timespec __user *) &in,
67241- (struct timespec __user *) &out);
67242+ (struct timespec __force_user *) &in,
67243+ (struct timespec __force_user *) &out);
67244 set_fs(oldfs);
67245
67246 if ((err == -ERESTART_RESTARTBLOCK) && rmtp &&
67247diff --git a/kernel/configs.c b/kernel/configs.c
67248index 42e8fa0..9e7406b 100644
67249--- a/kernel/configs.c
67250+++ b/kernel/configs.c
67251@@ -74,8 +74,19 @@ static int __init ikconfig_init(void)
67252 struct proc_dir_entry *entry;
67253
67254 /* create the current config file */
67255+#if defined(CONFIG_GRKERNSEC_PROC_ADD) || defined(CONFIG_GRKERNSEC_HIDESYM)
67256+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_HIDESYM)
67257+ entry = proc_create("config.gz", S_IFREG | S_IRUSR, NULL,
67258+ &ikconfig_file_ops);
67259+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
67260+ entry = proc_create("config.gz", S_IFREG | S_IRUSR | S_IRGRP, NULL,
67261+ &ikconfig_file_ops);
67262+#endif
67263+#else
67264 entry = proc_create("config.gz", S_IFREG | S_IRUGO, NULL,
67265 &ikconfig_file_ops);
67266+#endif
67267+
67268 if (!entry)
67269 return -ENOMEM;
67270
67271diff --git a/kernel/cred.c b/kernel/cred.c
67272index de728ac..e3c267c 100644
67273--- a/kernel/cred.c
67274+++ b/kernel/cred.c
67275@@ -207,6 +207,16 @@ void exit_creds(struct task_struct *tsk)
67276 validate_creds(cred);
67277 alter_cred_subscribers(cred, -1);
67278 put_cred(cred);
67279+
67280+#ifdef CONFIG_GRKERNSEC_SETXID
67281+ cred = (struct cred *) tsk->delayed_cred;
67282+ if (cred != NULL) {
67283+ tsk->delayed_cred = NULL;
67284+ validate_creds(cred);
67285+ alter_cred_subscribers(cred, -1);
67286+ put_cred(cred);
67287+ }
67288+#endif
67289 }
67290
67291 /**
67292@@ -469,7 +479,7 @@ error_put:
67293 * Always returns 0 thus allowing this function to be tail-called at the end
67294 * of, say, sys_setgid().
67295 */
67296-int commit_creds(struct cred *new)
67297+static int __commit_creds(struct cred *new)
67298 {
67299 struct task_struct *task = current;
67300 const struct cred *old = task->real_cred;
67301@@ -488,6 +498,8 @@ int commit_creds(struct cred *new)
67302
67303 get_cred(new); /* we will require a ref for the subj creds too */
67304
67305+ gr_set_role_label(task, new->uid, new->gid);
67306+
67307 /* dumpability changes */
67308 if (!uid_eq(old->euid, new->euid) ||
67309 !gid_eq(old->egid, new->egid) ||
67310@@ -537,6 +549,101 @@ int commit_creds(struct cred *new)
67311 put_cred(old);
67312 return 0;
67313 }
67314+#ifdef CONFIG_GRKERNSEC_SETXID
67315+extern int set_user(struct cred *new);
67316+
67317+void gr_delayed_cred_worker(void)
67318+{
67319+ const struct cred *new = current->delayed_cred;
67320+ struct cred *ncred;
67321+
67322+ current->delayed_cred = NULL;
67323+
67324+ if (current_uid() && new != NULL) {
67325+ // from doing get_cred on it when queueing this
67326+ put_cred(new);
67327+ return;
67328+ } else if (new == NULL)
67329+ return;
67330+
67331+ ncred = prepare_creds();
67332+ if (!ncred)
67333+ goto die;
67334+ // uids
67335+ ncred->uid = new->uid;
67336+ ncred->euid = new->euid;
67337+ ncred->suid = new->suid;
67338+ ncred->fsuid = new->fsuid;
67339+ // gids
67340+ ncred->gid = new->gid;
67341+ ncred->egid = new->egid;
67342+ ncred->sgid = new->sgid;
67343+ ncred->fsgid = new->fsgid;
67344+ // groups
67345+ if (set_groups(ncred, new->group_info) < 0) {
67346+ abort_creds(ncred);
67347+ goto die;
67348+ }
67349+ // caps
67350+ ncred->securebits = new->securebits;
67351+ ncred->cap_inheritable = new->cap_inheritable;
67352+ ncred->cap_permitted = new->cap_permitted;
67353+ ncred->cap_effective = new->cap_effective;
67354+ ncred->cap_bset = new->cap_bset;
67355+
67356+ if (set_user(ncred)) {
67357+ abort_creds(ncred);
67358+ goto die;
67359+ }
67360+
67361+ // from doing get_cred on it when queueing this
67362+ put_cred(new);
67363+
67364+ __commit_creds(ncred);
67365+ return;
67366+die:
67367+ // from doing get_cred on it when queueing this
67368+ put_cred(new);
67369+ do_group_exit(SIGKILL);
67370+}
67371+#endif
67372+
67373+int commit_creds(struct cred *new)
67374+{
67375+#ifdef CONFIG_GRKERNSEC_SETXID
67376+ int ret;
67377+ int schedule_it = 0;
67378+ struct task_struct *t;
67379+
67380+ /* we won't get called with tasklist_lock held for writing
67381+ and interrupts disabled as the cred struct in that case is
67382+ init_cred
67383+ */
67384+ if (grsec_enable_setxid && !current_is_single_threaded() &&
67385+ !current_uid() && new->uid) {
67386+ schedule_it = 1;
67387+ }
67388+ ret = __commit_creds(new);
67389+ if (schedule_it) {
67390+ rcu_read_lock();
67391+ read_lock(&tasklist_lock);
67392+ for (t = next_thread(current); t != current;
67393+ t = next_thread(t)) {
67394+ if (t->delayed_cred == NULL) {
67395+ t->delayed_cred = get_cred(new);
67396+ set_tsk_thread_flag(t, TIF_GRSEC_SETXID);
67397+ set_tsk_need_resched(t);
67398+ }
67399+ }
67400+ read_unlock(&tasklist_lock);
67401+ rcu_read_unlock();
67402+ }
67403+ return ret;
67404+#else
67405+ return __commit_creds(new);
67406+#endif
67407+}
67408+
67409 EXPORT_SYMBOL(commit_creds);
67410
67411 /**
67412diff --git a/kernel/debug/debug_core.c b/kernel/debug/debug_core.c
67413index 0557f24..1a00d9a 100644
67414--- a/kernel/debug/debug_core.c
67415+++ b/kernel/debug/debug_core.c
67416@@ -122,7 +122,7 @@ static DEFINE_RAW_SPINLOCK(dbg_slave_lock);
67417 */
67418 static atomic_t masters_in_kgdb;
67419 static atomic_t slaves_in_kgdb;
67420-static atomic_t kgdb_break_tasklet_var;
67421+static atomic_unchecked_t kgdb_break_tasklet_var;
67422 atomic_t kgdb_setting_breakpoint;
67423
67424 struct task_struct *kgdb_usethread;
67425@@ -132,7 +132,7 @@ int kgdb_single_step;
67426 static pid_t kgdb_sstep_pid;
67427
67428 /* to keep track of the CPU which is doing the single stepping*/
67429-atomic_t kgdb_cpu_doing_single_step = ATOMIC_INIT(-1);
67430+atomic_unchecked_t kgdb_cpu_doing_single_step = ATOMIC_INIT(-1);
67431
67432 /*
67433 * If you are debugging a problem where roundup (the collection of
67434@@ -540,7 +540,7 @@ return_normal:
67435 * kernel will only try for the value of sstep_tries before
67436 * giving up and continuing on.
67437 */
67438- if (atomic_read(&kgdb_cpu_doing_single_step) != -1 &&
67439+ if (atomic_read_unchecked(&kgdb_cpu_doing_single_step) != -1 &&
67440 (kgdb_info[cpu].task &&
67441 kgdb_info[cpu].task->pid != kgdb_sstep_pid) && --sstep_tries) {
67442 atomic_set(&kgdb_active, -1);
67443@@ -634,8 +634,8 @@ cpu_master_loop:
67444 }
67445
67446 kgdb_restore:
67447- if (atomic_read(&kgdb_cpu_doing_single_step) != -1) {
67448- int sstep_cpu = atomic_read(&kgdb_cpu_doing_single_step);
67449+ if (atomic_read_unchecked(&kgdb_cpu_doing_single_step) != -1) {
67450+ int sstep_cpu = atomic_read_unchecked(&kgdb_cpu_doing_single_step);
67451 if (kgdb_info[sstep_cpu].task)
67452 kgdb_sstep_pid = kgdb_info[sstep_cpu].task->pid;
67453 else
67454@@ -861,18 +861,18 @@ static void kgdb_unregister_callbacks(void)
67455 static void kgdb_tasklet_bpt(unsigned long ing)
67456 {
67457 kgdb_breakpoint();
67458- atomic_set(&kgdb_break_tasklet_var, 0);
67459+ atomic_set_unchecked(&kgdb_break_tasklet_var, 0);
67460 }
67461
67462 static DECLARE_TASKLET(kgdb_tasklet_breakpoint, kgdb_tasklet_bpt, 0);
67463
67464 void kgdb_schedule_breakpoint(void)
67465 {
67466- if (atomic_read(&kgdb_break_tasklet_var) ||
67467+ if (atomic_read_unchecked(&kgdb_break_tasklet_var) ||
67468 atomic_read(&kgdb_active) != -1 ||
67469 atomic_read(&kgdb_setting_breakpoint))
67470 return;
67471- atomic_inc(&kgdb_break_tasklet_var);
67472+ atomic_inc_unchecked(&kgdb_break_tasklet_var);
67473 tasklet_schedule(&kgdb_tasklet_breakpoint);
67474 }
67475 EXPORT_SYMBOL_GPL(kgdb_schedule_breakpoint);
67476diff --git a/kernel/debug/kdb/kdb_main.c b/kernel/debug/kdb/kdb_main.c
67477index 31df170..bc98840 100644
67478--- a/kernel/debug/kdb/kdb_main.c
67479+++ b/kernel/debug/kdb/kdb_main.c
67480@@ -1971,7 +1971,7 @@ static int kdb_lsmod(int argc, const char **argv)
67481 list_for_each_entry(mod, kdb_modules, list) {
67482
67483 kdb_printf("%-20s%8u 0x%p ", mod->name,
67484- mod->core_size, (void *)mod);
67485+ mod->core_size_rx + mod->core_size_rw, (void *)mod);
67486 #ifdef CONFIG_MODULE_UNLOAD
67487 kdb_printf("%4ld ", module_refcount(mod));
67488 #endif
67489@@ -1981,7 +1981,7 @@ static int kdb_lsmod(int argc, const char **argv)
67490 kdb_printf(" (Loading)");
67491 else
67492 kdb_printf(" (Live)");
67493- kdb_printf(" 0x%p", mod->module_core);
67494+ kdb_printf(" 0x%p 0x%p", mod->module_core_rx, mod->module_core_rw);
67495
67496 #ifdef CONFIG_MODULE_UNLOAD
67497 {
67498diff --git a/kernel/events/core.c b/kernel/events/core.c
67499index 7fee567..8affa2c 100644
67500--- a/kernel/events/core.c
67501+++ b/kernel/events/core.c
67502@@ -181,7 +181,7 @@ int perf_proc_update_handler(struct ctl_table *table, int write,
67503 return 0;
67504 }
67505
67506-static atomic64_t perf_event_id;
67507+static atomic64_unchecked_t perf_event_id;
67508
67509 static void cpu_ctx_sched_out(struct perf_cpu_context *cpuctx,
67510 enum event_type_t event_type);
67511@@ -2665,7 +2665,7 @@ static void __perf_event_read(void *info)
67512
67513 static inline u64 perf_event_count(struct perf_event *event)
67514 {
67515- return local64_read(&event->count) + atomic64_read(&event->child_count);
67516+ return local64_read(&event->count) + atomic64_read_unchecked(&event->child_count);
67517 }
67518
67519 static u64 perf_event_read(struct perf_event *event)
67520@@ -2995,9 +2995,9 @@ u64 perf_event_read_value(struct perf_event *event, u64 *enabled, u64 *running)
67521 mutex_lock(&event->child_mutex);
67522 total += perf_event_read(event);
67523 *enabled += event->total_time_enabled +
67524- atomic64_read(&event->child_total_time_enabled);
67525+ atomic64_read_unchecked(&event->child_total_time_enabled);
67526 *running += event->total_time_running +
67527- atomic64_read(&event->child_total_time_running);
67528+ atomic64_read_unchecked(&event->child_total_time_running);
67529
67530 list_for_each_entry(child, &event->child_list, child_list) {
67531 total += perf_event_read(child);
67532@@ -3406,10 +3406,10 @@ void perf_event_update_userpage(struct perf_event *event)
67533 userpg->offset -= local64_read(&event->hw.prev_count);
67534
67535 userpg->time_enabled = enabled +
67536- atomic64_read(&event->child_total_time_enabled);
67537+ atomic64_read_unchecked(&event->child_total_time_enabled);
67538
67539 userpg->time_running = running +
67540- atomic64_read(&event->child_total_time_running);
67541+ atomic64_read_unchecked(&event->child_total_time_running);
67542
67543 arch_perf_update_userpage(userpg, now);
67544
67545@@ -3842,11 +3842,11 @@ static void perf_output_read_one(struct perf_output_handle *handle,
67546 values[n++] = perf_event_count(event);
67547 if (read_format & PERF_FORMAT_TOTAL_TIME_ENABLED) {
67548 values[n++] = enabled +
67549- atomic64_read(&event->child_total_time_enabled);
67550+ atomic64_read_unchecked(&event->child_total_time_enabled);
67551 }
67552 if (read_format & PERF_FORMAT_TOTAL_TIME_RUNNING) {
67553 values[n++] = running +
67554- atomic64_read(&event->child_total_time_running);
67555+ atomic64_read_unchecked(&event->child_total_time_running);
67556 }
67557 if (read_format & PERF_FORMAT_ID)
67558 values[n++] = primary_event_id(event);
67559@@ -4524,12 +4524,12 @@ static void perf_event_mmap_event(struct perf_mmap_event *mmap_event)
67560 * need to add enough zero bytes after the string to handle
67561 * the 64bit alignment we do later.
67562 */
67563- buf = kzalloc(PATH_MAX + sizeof(u64), GFP_KERNEL);
67564+ buf = kzalloc(PATH_MAX, GFP_KERNEL);
67565 if (!buf) {
67566 name = strncpy(tmp, "//enomem", sizeof(tmp));
67567 goto got_name;
67568 }
67569- name = d_path(&file->f_path, buf, PATH_MAX);
67570+ name = d_path(&file->f_path, buf, PATH_MAX - sizeof(u64));
67571 if (IS_ERR(name)) {
67572 name = strncpy(tmp, "//toolong", sizeof(tmp));
67573 goto got_name;
67574@@ -5968,7 +5968,7 @@ perf_event_alloc(struct perf_event_attr *attr, int cpu,
67575 event->parent = parent_event;
67576
67577 event->ns = get_pid_ns(current->nsproxy->pid_ns);
67578- event->id = atomic64_inc_return(&perf_event_id);
67579+ event->id = atomic64_inc_return_unchecked(&perf_event_id);
67580
67581 event->state = PERF_EVENT_STATE_INACTIVE;
67582
67583@@ -6567,10 +6567,10 @@ static void sync_child_event(struct perf_event *child_event,
67584 /*
67585 * Add back the child's count to the parent's count:
67586 */
67587- atomic64_add(child_val, &parent_event->child_count);
67588- atomic64_add(child_event->total_time_enabled,
67589+ atomic64_add_unchecked(child_val, &parent_event->child_count);
67590+ atomic64_add_unchecked(child_event->total_time_enabled,
67591 &parent_event->child_total_time_enabled);
67592- atomic64_add(child_event->total_time_running,
67593+ atomic64_add_unchecked(child_event->total_time_running,
67594 &parent_event->child_total_time_running);
67595
67596 /*
67597diff --git a/kernel/exit.c b/kernel/exit.c
67598index f65345f9..1423231 100644
67599--- a/kernel/exit.c
67600+++ b/kernel/exit.c
67601@@ -182,6 +182,10 @@ void release_task(struct task_struct * p)
67602 struct task_struct *leader;
67603 int zap_leader;
67604 repeat:
67605+#ifdef CONFIG_NET
67606+ gr_del_task_from_ip_table(p);
67607+#endif
67608+
67609 /* don't need to get the RCU readlock here - the process is dead and
67610 * can't be modifying its own credentials. But shut RCU-lockdep up */
67611 rcu_read_lock();
67612@@ -394,7 +398,7 @@ int allow_signal(int sig)
67613 * know it'll be handled, so that they don't get converted to
67614 * SIGKILL or just silently dropped.
67615 */
67616- current->sighand->action[(sig)-1].sa.sa_handler = (void __user *)2;
67617+ current->sighand->action[(sig)-1].sa.sa_handler = (__force void __user *)2;
67618 recalc_sigpending();
67619 spin_unlock_irq(&current->sighand->siglock);
67620 return 0;
67621@@ -430,6 +434,8 @@ void daemonize(const char *name, ...)
67622 vsnprintf(current->comm, sizeof(current->comm), name, args);
67623 va_end(args);
67624
67625+ gr_set_kernel_label(current);
67626+
67627 /*
67628 * If we were started as result of loading a module, close all of the
67629 * user space pages. We don't need them, and if we didn't close them
67630@@ -907,6 +913,8 @@ void do_exit(long code)
67631 struct task_struct *tsk = current;
67632 int group_dead;
67633
67634+ set_fs(USER_DS);
67635+
67636 profile_task_exit(tsk);
67637
67638 WARN_ON(blk_needs_flush_plug(tsk));
67639@@ -923,7 +931,6 @@ void do_exit(long code)
67640 * mm_release()->clear_child_tid() from writing to a user-controlled
67641 * kernel address.
67642 */
67643- set_fs(USER_DS);
67644
67645 ptrace_event(PTRACE_EVENT_EXIT, code);
67646
67647@@ -982,6 +989,9 @@ void do_exit(long code)
67648 tsk->exit_code = code;
67649 taskstats_exit(tsk, group_dead);
67650
67651+ gr_acl_handle_psacct(tsk, code);
67652+ gr_acl_handle_exit();
67653+
67654 exit_mm(tsk);
67655
67656 if (group_dead)
67657@@ -1099,7 +1109,7 @@ SYSCALL_DEFINE1(exit, int, error_code)
67658 * Take down every thread in the group. This is called by fatal signals
67659 * as well as by sys_exit_group (below).
67660 */
67661-void
67662+__noreturn void
67663 do_group_exit(int exit_code)
67664 {
67665 struct signal_struct *sig = current->signal;
67666diff --git a/kernel/fork.c b/kernel/fork.c
67667index 2c8857e..288c9c7 100644
67668--- a/kernel/fork.c
67669+++ b/kernel/fork.c
67670@@ -318,7 +318,7 @@ static struct task_struct *dup_task_struct(struct task_struct *orig)
67671 *stackend = STACK_END_MAGIC; /* for overflow detection */
67672
67673 #ifdef CONFIG_CC_STACKPROTECTOR
67674- tsk->stack_canary = get_random_int();
67675+ tsk->stack_canary = pax_get_random_long();
67676 #endif
67677
67678 /*
67679@@ -343,13 +343,78 @@ free_tsk:
67680 }
67681
67682 #ifdef CONFIG_MMU
67683+static struct vm_area_struct *dup_vma(struct mm_struct *mm, struct mm_struct *oldmm, struct vm_area_struct *mpnt)
67684+{
67685+ struct vm_area_struct *tmp;
67686+ unsigned long charge;
67687+ struct mempolicy *pol;
67688+ struct file *file;
67689+
67690+ charge = 0;
67691+ if (mpnt->vm_flags & VM_ACCOUNT) {
67692+ unsigned long len = vma_pages(mpnt);
67693+
67694+ if (security_vm_enough_memory_mm(oldmm, len)) /* sic */
67695+ goto fail_nomem;
67696+ charge = len;
67697+ }
67698+ tmp = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
67699+ if (!tmp)
67700+ goto fail_nomem;
67701+ *tmp = *mpnt;
67702+ tmp->vm_mm = mm;
67703+ INIT_LIST_HEAD(&tmp->anon_vma_chain);
67704+ pol = mpol_dup(vma_policy(mpnt));
67705+ if (IS_ERR(pol))
67706+ goto fail_nomem_policy;
67707+ vma_set_policy(tmp, pol);
67708+ if (anon_vma_fork(tmp, mpnt))
67709+ goto fail_nomem_anon_vma_fork;
67710+ tmp->vm_flags &= ~VM_LOCKED;
67711+ tmp->vm_next = tmp->vm_prev = NULL;
67712+ tmp->vm_mirror = NULL;
67713+ file = tmp->vm_file;
67714+ if (file) {
67715+ struct inode *inode = file->f_path.dentry->d_inode;
67716+ struct address_space *mapping = file->f_mapping;
67717+
67718+ get_file(file);
67719+ if (tmp->vm_flags & VM_DENYWRITE)
67720+ atomic_dec(&inode->i_writecount);
67721+ mutex_lock(&mapping->i_mmap_mutex);
67722+ if (tmp->vm_flags & VM_SHARED)
67723+ mapping->i_mmap_writable++;
67724+ flush_dcache_mmap_lock(mapping);
67725+ /* insert tmp into the share list, just after mpnt */
67726+ vma_prio_tree_add(tmp, mpnt);
67727+ flush_dcache_mmap_unlock(mapping);
67728+ mutex_unlock(&mapping->i_mmap_mutex);
67729+ }
67730+
67731+ /*
67732+ * Clear hugetlb-related page reserves for children. This only
67733+ * affects MAP_PRIVATE mappings. Faults generated by the child
67734+ * are not guaranteed to succeed, even if read-only
67735+ */
67736+ if (is_vm_hugetlb_page(tmp))
67737+ reset_vma_resv_huge_pages(tmp);
67738+
67739+ return tmp;
67740+
67741+fail_nomem_anon_vma_fork:
67742+ mpol_put(pol);
67743+fail_nomem_policy:
67744+ kmem_cache_free(vm_area_cachep, tmp);
67745+fail_nomem:
67746+ vm_unacct_memory(charge);
67747+ return NULL;
67748+}
67749+
67750 static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
67751 {
67752 struct vm_area_struct *mpnt, *tmp, *prev, **pprev;
67753 struct rb_node **rb_link, *rb_parent;
67754 int retval;
67755- unsigned long charge;
67756- struct mempolicy *pol;
67757
67758 down_write(&oldmm->mmap_sem);
67759 flush_cache_dup_mm(oldmm);
67760@@ -361,8 +426,8 @@ static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
67761 mm->locked_vm = 0;
67762 mm->mmap = NULL;
67763 mm->mmap_cache = NULL;
67764- mm->free_area_cache = oldmm->mmap_base;
67765- mm->cached_hole_size = ~0UL;
67766+ mm->free_area_cache = oldmm->free_area_cache;
67767+ mm->cached_hole_size = oldmm->cached_hole_size;
67768 mm->map_count = 0;
67769 cpumask_clear(mm_cpumask(mm));
67770 mm->mm_rb = RB_ROOT;
67771@@ -378,52 +443,15 @@ static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
67772
67773 prev = NULL;
67774 for (mpnt = oldmm->mmap; mpnt; mpnt = mpnt->vm_next) {
67775- struct file *file;
67776-
67777 if (mpnt->vm_flags & VM_DONTCOPY) {
67778 vm_stat_account(mm, mpnt->vm_flags, mpnt->vm_file,
67779 -vma_pages(mpnt));
67780 continue;
67781 }
67782- charge = 0;
67783- if (mpnt->vm_flags & VM_ACCOUNT) {
67784- unsigned long len = vma_pages(mpnt);
67785-
67786- if (security_vm_enough_memory_mm(oldmm, len)) /* sic */
67787- goto fail_nomem;
67788- charge = len;
67789- }
67790- tmp = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
67791- if (!tmp)
67792- goto fail_nomem;
67793- *tmp = *mpnt;
67794- INIT_LIST_HEAD(&tmp->anon_vma_chain);
67795- pol = mpol_dup(vma_policy(mpnt));
67796- retval = PTR_ERR(pol);
67797- if (IS_ERR(pol))
67798- goto fail_nomem_policy;
67799- vma_set_policy(tmp, pol);
67800- tmp->vm_mm = mm;
67801- if (anon_vma_fork(tmp, mpnt))
67802- goto fail_nomem_anon_vma_fork;
67803- tmp->vm_flags &= ~VM_LOCKED;
67804- tmp->vm_next = tmp->vm_prev = NULL;
67805- file = tmp->vm_file;
67806- if (file) {
67807- struct inode *inode = file->f_path.dentry->d_inode;
67808- struct address_space *mapping = file->f_mapping;
67809-
67810- get_file(file);
67811- if (tmp->vm_flags & VM_DENYWRITE)
67812- atomic_dec(&inode->i_writecount);
67813- mutex_lock(&mapping->i_mmap_mutex);
67814- if (tmp->vm_flags & VM_SHARED)
67815- mapping->i_mmap_writable++;
67816- flush_dcache_mmap_lock(mapping);
67817- /* insert tmp into the share list, just after mpnt */
67818- vma_prio_tree_add(tmp, mpnt);
67819- flush_dcache_mmap_unlock(mapping);
67820- mutex_unlock(&mapping->i_mmap_mutex);
67821+ tmp = dup_vma(mm, oldmm, mpnt);
67822+ if (!tmp) {
67823+ retval = -ENOMEM;
67824+ goto out;
67825 }
67826
67827 /*
67828@@ -455,9 +483,34 @@ static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
67829 if (retval)
67830 goto out;
67831
67832- if (file)
67833+ if (tmp->vm_file)
67834 uprobe_mmap(tmp);
67835 }
67836+
67837+#ifdef CONFIG_PAX_SEGMEXEC
67838+ if (oldmm->pax_flags & MF_PAX_SEGMEXEC) {
67839+ struct vm_area_struct *mpnt_m;
67840+
67841+ for (mpnt = oldmm->mmap, mpnt_m = mm->mmap; mpnt; mpnt = mpnt->vm_next, mpnt_m = mpnt_m->vm_next) {
67842+ BUG_ON(!mpnt_m || mpnt_m->vm_mirror || mpnt->vm_mm != oldmm || mpnt_m->vm_mm != mm);
67843+
67844+ if (!mpnt->vm_mirror)
67845+ continue;
67846+
67847+ if (mpnt->vm_end <= SEGMEXEC_TASK_SIZE) {
67848+ BUG_ON(mpnt->vm_mirror->vm_mirror != mpnt);
67849+ mpnt->vm_mirror = mpnt_m;
67850+ } else {
67851+ BUG_ON(mpnt->vm_mirror->vm_mirror == mpnt || mpnt->vm_mirror->vm_mirror->vm_mm != mm);
67852+ mpnt_m->vm_mirror = mpnt->vm_mirror->vm_mirror;
67853+ mpnt_m->vm_mirror->vm_mirror = mpnt_m;
67854+ mpnt->vm_mirror->vm_mirror = mpnt;
67855+ }
67856+ }
67857+ BUG_ON(mpnt_m);
67858+ }
67859+#endif
67860+
67861 /* a new mm has just been created */
67862 arch_dup_mmap(oldmm, mm);
67863 retval = 0;
67864@@ -466,14 +519,6 @@ out:
67865 flush_tlb_mm(oldmm);
67866 up_write(&oldmm->mmap_sem);
67867 return retval;
67868-fail_nomem_anon_vma_fork:
67869- mpol_put(pol);
67870-fail_nomem_policy:
67871- kmem_cache_free(vm_area_cachep, tmp);
67872-fail_nomem:
67873- retval = -ENOMEM;
67874- vm_unacct_memory(charge);
67875- goto out;
67876 }
67877
67878 static inline int mm_alloc_pgd(struct mm_struct *mm)
67879@@ -710,8 +755,8 @@ struct mm_struct *mm_access(struct task_struct *task, unsigned int mode)
67880 return ERR_PTR(err);
67881
67882 mm = get_task_mm(task);
67883- if (mm && mm != current->mm &&
67884- !ptrace_may_access(task, mode)) {
67885+ if (mm && ((mm != current->mm && !ptrace_may_access(task, mode)) ||
67886+ (mode == PTRACE_MODE_ATTACH && (gr_handle_proc_ptrace(task) || gr_acl_handle_procpidmem(task))))) {
67887 mmput(mm);
67888 mm = ERR_PTR(-EACCES);
67889 }
67890@@ -932,13 +977,20 @@ static int copy_fs(unsigned long clone_flags, struct task_struct *tsk)
67891 spin_unlock(&fs->lock);
67892 return -EAGAIN;
67893 }
67894- fs->users++;
67895+ atomic_inc(&fs->users);
67896 spin_unlock(&fs->lock);
67897 return 0;
67898 }
67899 tsk->fs = copy_fs_struct(fs);
67900 if (!tsk->fs)
67901 return -ENOMEM;
67902+ /* Carry through gr_chroot_dentry and is_chrooted instead
67903+ of recomputing it here. Already copied when the task struct
67904+ is duplicated. This allows pivot_root to not be treated as
67905+ a chroot
67906+ */
67907+ //gr_set_chroot_entries(tsk, &tsk->fs->root);
67908+
67909 return 0;
67910 }
67911
67912@@ -1205,6 +1257,9 @@ static struct task_struct *copy_process(unsigned long clone_flags,
67913 DEBUG_LOCKS_WARN_ON(!p->softirqs_enabled);
67914 #endif
67915 retval = -EAGAIN;
67916+
67917+ gr_learn_resource(p, RLIMIT_NPROC, atomic_read(&p->real_cred->user->processes), 0);
67918+
67919 if (atomic_read(&p->real_cred->user->processes) >=
67920 task_rlimit(p, RLIMIT_NPROC)) {
67921 if (!capable(CAP_SYS_ADMIN) && !capable(CAP_SYS_RESOURCE) &&
67922@@ -1427,6 +1482,9 @@ static struct task_struct *copy_process(unsigned long clone_flags,
67923 /* Need tasklist lock for parent etc handling! */
67924 write_lock_irq(&tasklist_lock);
67925
67926+ /* synchronizes with gr_set_acls() */
67927+ gr_copy_label(p);
67928+
67929 /* CLONE_PARENT re-uses the old parent */
67930 if (clone_flags & (CLONE_PARENT|CLONE_THREAD)) {
67931 p->real_parent = current->real_parent;
67932@@ -1537,6 +1595,8 @@ bad_fork_cleanup_count:
67933 bad_fork_free:
67934 free_task(p);
67935 fork_out:
67936+ gr_log_forkfail(retval);
67937+
67938 return ERR_PTR(retval);
67939 }
67940
67941@@ -1637,6 +1697,8 @@ long do_fork(unsigned long clone_flags,
67942 if (clone_flags & CLONE_PARENT_SETTID)
67943 put_user(nr, parent_tidptr);
67944
67945+ gr_handle_brute_check();
67946+
67947 if (clone_flags & CLONE_VFORK) {
67948 p->vfork_done = &vfork;
67949 init_completion(&vfork);
67950@@ -1735,7 +1797,7 @@ static int unshare_fs(unsigned long unshare_flags, struct fs_struct **new_fsp)
67951 return 0;
67952
67953 /* don't need lock here; in the worst case we'll do useless copy */
67954- if (fs->users == 1)
67955+ if (atomic_read(&fs->users) == 1)
67956 return 0;
67957
67958 *new_fsp = copy_fs_struct(fs);
67959@@ -1824,7 +1886,8 @@ SYSCALL_DEFINE1(unshare, unsigned long, unshare_flags)
67960 fs = current->fs;
67961 spin_lock(&fs->lock);
67962 current->fs = new_fs;
67963- if (--fs->users)
67964+ gr_set_chroot_entries(current, &current->fs->root);
67965+ if (atomic_dec_return(&fs->users))
67966 new_fs = NULL;
67967 else
67968 new_fs = fs;
67969diff --git a/kernel/futex.c b/kernel/futex.c
67970index 20ef219..b8c65ea 100644
67971--- a/kernel/futex.c
67972+++ b/kernel/futex.c
67973@@ -54,6 +54,7 @@
67974 #include <linux/mount.h>
67975 #include <linux/pagemap.h>
67976 #include <linux/syscalls.h>
67977+#include <linux/ptrace.h>
67978 #include <linux/signal.h>
67979 #include <linux/export.h>
67980 #include <linux/magic.h>
67981@@ -239,6 +240,11 @@ get_futex_key(u32 __user *uaddr, int fshared, union futex_key *key, int rw)
67982 struct page *page, *page_head;
67983 int err, ro = 0;
67984
67985+#ifdef CONFIG_PAX_SEGMEXEC
67986+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && address >= SEGMEXEC_TASK_SIZE)
67987+ return -EFAULT;
67988+#endif
67989+
67990 /*
67991 * The futex address must be "naturally" aligned.
67992 */
67993@@ -843,6 +849,9 @@ static void wake_futex(struct futex_q *q)
67994 {
67995 struct task_struct *p = q->task;
67996
67997+ if (WARN(q->pi_state || q->rt_waiter, "refusing to wake PI futex\n"))
67998+ return;
67999+
68000 /*
68001 * We set q->lock_ptr = NULL _before_ we wake up the task. If
68002 * a non-futex wake up happens on another CPU then the task
68003@@ -1078,6 +1087,10 @@ retry_private:
68004
68005 plist_for_each_entry_safe(this, next, head, list) {
68006 if (match_futex (&this->key, &key1)) {
68007+ if (this->pi_state || this->rt_waiter) {
68008+ ret = -EINVAL;
68009+ goto out_unlock;
68010+ }
68011 wake_futex(this);
68012 if (++ret >= nr_wake)
68013 break;
68014@@ -1090,6 +1103,10 @@ retry_private:
68015 op_ret = 0;
68016 plist_for_each_entry_safe(this, next, head, list) {
68017 if (match_futex (&this->key, &key2)) {
68018+ if (this->pi_state || this->rt_waiter) {
68019+ ret = -EINVAL;
68020+ goto out_unlock;
68021+ }
68022 wake_futex(this);
68023 if (++op_ret >= nr_wake2)
68024 break;
68025@@ -1098,6 +1115,7 @@ retry_private:
68026 ret += op_ret;
68027 }
68028
68029+out_unlock:
68030 double_unlock_hb(hb1, hb2);
68031 out_put_keys:
68032 put_futex_key(&key2);
68033@@ -1387,9 +1405,13 @@ retry_private:
68034 /*
68035 * FUTEX_WAIT_REQEUE_PI and FUTEX_CMP_REQUEUE_PI should always
68036 * be paired with each other and no other futex ops.
68037+ *
68038+ * We should never be requeueing a futex_q with a pi_state,
68039+ * which is awaiting a futex_unlock_pi().
68040 */
68041 if ((requeue_pi && !this->rt_waiter) ||
68042- (!requeue_pi && this->rt_waiter)) {
68043+ (!requeue_pi && this->rt_waiter) ||
68044+ this->pi_state) {
68045 ret = -EINVAL;
68046 break;
68047 }
68048@@ -2717,6 +2739,7 @@ static int __init futex_init(void)
68049 {
68050 u32 curval;
68051 int i;
68052+ mm_segment_t oldfs;
68053
68054 /*
68055 * This will fail and we want it. Some arch implementations do
68056@@ -2728,8 +2751,11 @@ static int __init futex_init(void)
68057 * implementation, the non-functional ones will return
68058 * -ENOSYS.
68059 */
68060+ oldfs = get_fs();
68061+ set_fs(USER_DS);
68062 if (cmpxchg_futex_value_locked(&curval, NULL, 0, 0) == -EFAULT)
68063 futex_cmpxchg_enabled = 1;
68064+ set_fs(oldfs);
68065
68066 for (i = 0; i < ARRAY_SIZE(futex_queues); i++) {
68067 plist_head_init(&futex_queues[i].chain);
68068diff --git a/kernel/gcov/base.c b/kernel/gcov/base.c
68069index 9b22d03..6295b62 100644
68070--- a/kernel/gcov/base.c
68071+++ b/kernel/gcov/base.c
68072@@ -102,11 +102,6 @@ void gcov_enable_events(void)
68073 }
68074
68075 #ifdef CONFIG_MODULES
68076-static inline int within(void *addr, void *start, unsigned long size)
68077-{
68078- return ((addr >= start) && (addr < start + size));
68079-}
68080-
68081 /* Update list and generate events when modules are unloaded. */
68082 static int gcov_module_notifier(struct notifier_block *nb, unsigned long event,
68083 void *data)
68084@@ -121,7 +116,7 @@ static int gcov_module_notifier(struct notifier_block *nb, unsigned long event,
68085 prev = NULL;
68086 /* Remove entries located in module from linked list. */
68087 for (info = gcov_info_head; info; info = info->next) {
68088- if (within(info, mod->module_core, mod->core_size)) {
68089+ if (within_module_core_rw((unsigned long)info, mod)) {
68090 if (prev)
68091 prev->next = info->next;
68092 else
68093diff --git a/kernel/hrtimer.c b/kernel/hrtimer.c
68094index 6db7a5e..25b6648 100644
68095--- a/kernel/hrtimer.c
68096+++ b/kernel/hrtimer.c
68097@@ -1407,7 +1407,7 @@ void hrtimer_peek_ahead_timers(void)
68098 local_irq_restore(flags);
68099 }
68100
68101-static void run_hrtimer_softirq(struct softirq_action *h)
68102+static void run_hrtimer_softirq(void)
68103 {
68104 struct hrtimer_cpu_base *cpu_base = &__get_cpu_var(hrtimer_bases);
68105
68106diff --git a/kernel/jump_label.c b/kernel/jump_label.c
68107index 4304919..408c4c0 100644
68108--- a/kernel/jump_label.c
68109+++ b/kernel/jump_label.c
68110@@ -13,6 +13,7 @@
68111 #include <linux/sort.h>
68112 #include <linux/err.h>
68113 #include <linux/static_key.h>
68114+#include <linux/mm.h>
68115
68116 #ifdef HAVE_JUMP_LABEL
68117
68118@@ -50,7 +51,9 @@ jump_label_sort_entries(struct jump_entry *start, struct jump_entry *stop)
68119
68120 size = (((unsigned long)stop - (unsigned long)start)
68121 / sizeof(struct jump_entry));
68122+ pax_open_kernel();
68123 sort(start, size, sizeof(struct jump_entry), jump_label_cmp, NULL);
68124+ pax_close_kernel();
68125 }
68126
68127 static void jump_label_update(struct static_key *key, int enable);
68128@@ -356,10 +359,12 @@ static void jump_label_invalidate_module_init(struct module *mod)
68129 struct jump_entry *iter_stop = iter_start + mod->num_jump_entries;
68130 struct jump_entry *iter;
68131
68132+ pax_open_kernel();
68133 for (iter = iter_start; iter < iter_stop; iter++) {
68134 if (within_module_init(iter->code, mod))
68135 iter->code = 0;
68136 }
68137+ pax_close_kernel();
68138 }
68139
68140 static int
68141diff --git a/kernel/kallsyms.c b/kernel/kallsyms.c
68142index 2169fee..45c017a 100644
68143--- a/kernel/kallsyms.c
68144+++ b/kernel/kallsyms.c
68145@@ -11,6 +11,9 @@
68146 * Changed the compression method from stem compression to "table lookup"
68147 * compression (see scripts/kallsyms.c for a more complete description)
68148 */
68149+#ifdef CONFIG_GRKERNSEC_HIDESYM
68150+#define __INCLUDED_BY_HIDESYM 1
68151+#endif
68152 #include <linux/kallsyms.h>
68153 #include <linux/module.h>
68154 #include <linux/init.h>
68155@@ -53,12 +56,33 @@ extern const unsigned long kallsyms_markers[] __attribute__((weak));
68156
68157 static inline int is_kernel_inittext(unsigned long addr)
68158 {
68159+ if (system_state != SYSTEM_BOOTING)
68160+ return 0;
68161+
68162 if (addr >= (unsigned long)_sinittext
68163 && addr <= (unsigned long)_einittext)
68164 return 1;
68165 return 0;
68166 }
68167
68168+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
68169+#ifdef CONFIG_MODULES
68170+static inline int is_module_text(unsigned long addr)
68171+{
68172+ if ((unsigned long)MODULES_EXEC_VADDR <= addr && addr <= (unsigned long)MODULES_EXEC_END)
68173+ return 1;
68174+
68175+ addr = ktla_ktva(addr);
68176+ return (unsigned long)MODULES_EXEC_VADDR <= addr && addr <= (unsigned long)MODULES_EXEC_END;
68177+}
68178+#else
68179+static inline int is_module_text(unsigned long addr)
68180+{
68181+ return 0;
68182+}
68183+#endif
68184+#endif
68185+
68186 static inline int is_kernel_text(unsigned long addr)
68187 {
68188 if ((addr >= (unsigned long)_stext && addr <= (unsigned long)_etext) ||
68189@@ -69,13 +93,28 @@ static inline int is_kernel_text(unsigned long addr)
68190
68191 static inline int is_kernel(unsigned long addr)
68192 {
68193+
68194+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
68195+ if (is_kernel_text(addr) || is_kernel_inittext(addr))
68196+ return 1;
68197+
68198+ if (ktla_ktva((unsigned long)_text) <= addr && addr < (unsigned long)_end)
68199+#else
68200 if (addr >= (unsigned long)_stext && addr <= (unsigned long)_end)
68201+#endif
68202+
68203 return 1;
68204 return in_gate_area_no_mm(addr);
68205 }
68206
68207 static int is_ksym_addr(unsigned long addr)
68208 {
68209+
68210+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
68211+ if (is_module_text(addr))
68212+ return 0;
68213+#endif
68214+
68215 if (all_var)
68216 return is_kernel(addr);
68217
68218@@ -470,7 +509,6 @@ static unsigned long get_ksymbol_core(struct kallsym_iter *iter)
68219
68220 static void reset_iter(struct kallsym_iter *iter, loff_t new_pos)
68221 {
68222- iter->name[0] = '\0';
68223 iter->nameoff = get_symbol_offset(new_pos);
68224 iter->pos = new_pos;
68225 }
68226@@ -518,6 +556,11 @@ static int s_show(struct seq_file *m, void *p)
68227 {
68228 struct kallsym_iter *iter = m->private;
68229
68230+#ifdef CONFIG_GRKERNSEC_HIDESYM
68231+ if (current_uid())
68232+ return 0;
68233+#endif
68234+
68235 /* Some debugging symbols have no name. Ignore them. */
68236 if (!iter->name[0])
68237 return 0;
68238@@ -531,6 +574,7 @@ static int s_show(struct seq_file *m, void *p)
68239 */
68240 type = iter->exported ? toupper(iter->type) :
68241 tolower(iter->type);
68242+
68243 seq_printf(m, "%pK %c %s\t[%s]\n", (void *)iter->value,
68244 type, iter->name, iter->module_name);
68245 } else
68246@@ -556,7 +600,7 @@ static int kallsyms_open(struct inode *inode, struct file *file)
68247 struct kallsym_iter *iter;
68248 int ret;
68249
68250- iter = kmalloc(sizeof(*iter), GFP_KERNEL);
68251+ iter = kzalloc(sizeof(*iter), GFP_KERNEL);
68252 if (!iter)
68253 return -ENOMEM;
68254 reset_iter(iter, 0);
68255diff --git a/kernel/kcmp.c b/kernel/kcmp.c
68256index 30b7b22..c726387 100644
68257--- a/kernel/kcmp.c
68258+++ b/kernel/kcmp.c
68259@@ -98,6 +98,10 @@ SYSCALL_DEFINE5(kcmp, pid_t, pid1, pid_t, pid2, int, type,
68260 struct task_struct *task1, *task2;
68261 int ret;
68262
68263+#ifdef CONFIG_GRKERNSEC
68264+ return -ENOSYS;
68265+#endif
68266+
68267 rcu_read_lock();
68268
68269 /*
68270diff --git a/kernel/kexec.c b/kernel/kexec.c
68271index 0668d58..591b6fc 100644
68272--- a/kernel/kexec.c
68273+++ b/kernel/kexec.c
68274@@ -1046,7 +1046,8 @@ asmlinkage long compat_sys_kexec_load(unsigned long entry,
68275 unsigned long flags)
68276 {
68277 struct compat_kexec_segment in;
68278- struct kexec_segment out, __user *ksegments;
68279+ struct kexec_segment out;
68280+ struct kexec_segment __user *ksegments;
68281 unsigned long i, result;
68282
68283 /* Don't allow clients that don't understand the native
68284diff --git a/kernel/kmod.c b/kernel/kmod.c
68285index 6f99aea..eb6e3a0 100644
68286--- a/kernel/kmod.c
68287+++ b/kernel/kmod.c
68288@@ -73,7 +73,7 @@ static void free_modprobe_argv(struct subprocess_info *info)
68289 kfree(info->argv);
68290 }
68291
68292-static int call_modprobe(char *module_name, int wait)
68293+static int call_modprobe(char *module_name, char *module_param, int wait)
68294 {
68295 static char *envp[] = {
68296 "HOME=/",
68297@@ -82,7 +82,7 @@ static int call_modprobe(char *module_name, int wait)
68298 NULL
68299 };
68300
68301- char **argv = kmalloc(sizeof(char *[5]), GFP_KERNEL);
68302+ char **argv = kmalloc(sizeof(char *[6]), GFP_KERNEL);
68303 if (!argv)
68304 goto out;
68305
68306@@ -94,7 +94,8 @@ static int call_modprobe(char *module_name, int wait)
68307 argv[1] = "-q";
68308 argv[2] = "--";
68309 argv[3] = module_name; /* check free_modprobe_argv() */
68310- argv[4] = NULL;
68311+ argv[4] = module_param;
68312+ argv[5] = NULL;
68313
68314 return call_usermodehelper_fns(modprobe_path, argv, envp,
68315 wait | UMH_KILLABLE, NULL, free_modprobe_argv, NULL);
68316@@ -119,9 +120,8 @@ out:
68317 * If module auto-loading support is disabled then this function
68318 * becomes a no-operation.
68319 */
68320-int __request_module(bool wait, const char *fmt, ...)
68321+static int ____request_module(bool wait, char *module_param, const char *fmt, va_list ap)
68322 {
68323- va_list args;
68324 char module_name[MODULE_NAME_LEN];
68325 unsigned int max_modprobes;
68326 int ret;
68327@@ -129,9 +129,7 @@ int __request_module(bool wait, const char *fmt, ...)
68328 #define MAX_KMOD_CONCURRENT 50 /* Completely arbitrary value - KAO */
68329 static int kmod_loop_msg;
68330
68331- va_start(args, fmt);
68332- ret = vsnprintf(module_name, MODULE_NAME_LEN, fmt, args);
68333- va_end(args);
68334+ ret = vsnprintf(module_name, MODULE_NAME_LEN, fmt, ap);
68335 if (ret >= MODULE_NAME_LEN)
68336 return -ENAMETOOLONG;
68337
68338@@ -139,6 +137,20 @@ int __request_module(bool wait, const char *fmt, ...)
68339 if (ret)
68340 return ret;
68341
68342+#ifdef CONFIG_GRKERNSEC_MODHARDEN
68343+ if (!current_uid()) {
68344+ /* hack to workaround consolekit/udisks stupidity */
68345+ read_lock(&tasklist_lock);
68346+ if (!strcmp(current->comm, "mount") &&
68347+ current->real_parent && !strncmp(current->real_parent->comm, "udisk", 5)) {
68348+ read_unlock(&tasklist_lock);
68349+ printk(KERN_ALERT "grsec: denied attempt to auto-load fs module %.64s by udisks\n", module_name);
68350+ return -EPERM;
68351+ }
68352+ read_unlock(&tasklist_lock);
68353+ }
68354+#endif
68355+
68356 /* If modprobe needs a service that is in a module, we get a recursive
68357 * loop. Limit the number of running kmod threads to max_threads/2 or
68358 * MAX_KMOD_CONCURRENT, whichever is the smaller. A cleaner method
68359@@ -167,11 +179,52 @@ int __request_module(bool wait, const char *fmt, ...)
68360
68361 trace_module_request(module_name, wait, _RET_IP_);
68362
68363- ret = call_modprobe(module_name, wait ? UMH_WAIT_PROC : UMH_WAIT_EXEC);
68364+ ret = call_modprobe(module_name, module_param, wait ? UMH_WAIT_PROC : UMH_WAIT_EXEC);
68365
68366 atomic_dec(&kmod_concurrent);
68367 return ret;
68368 }
68369+
68370+int ___request_module(bool wait, char *module_param, const char *fmt, ...)
68371+{
68372+ va_list args;
68373+ int ret;
68374+
68375+ va_start(args, fmt);
68376+ ret = ____request_module(wait, module_param, fmt, args);
68377+ va_end(args);
68378+
68379+ return ret;
68380+}
68381+
68382+int __request_module(bool wait, const char *fmt, ...)
68383+{
68384+ va_list args;
68385+ int ret;
68386+
68387+#ifdef CONFIG_GRKERNSEC_MODHARDEN
68388+ if (current_uid()) {
68389+ char module_param[MODULE_NAME_LEN];
68390+
68391+ memset(module_param, 0, sizeof(module_param));
68392+
68393+ snprintf(module_param, sizeof(module_param) - 1, "grsec_modharden_normal%u_", current_uid());
68394+
68395+ va_start(args, fmt);
68396+ ret = ____request_module(wait, module_param, fmt, args);
68397+ va_end(args);
68398+
68399+ return ret;
68400+ }
68401+#endif
68402+
68403+ va_start(args, fmt);
68404+ ret = ____request_module(wait, NULL, fmt, args);
68405+ va_end(args);
68406+
68407+ return ret;
68408+}
68409+
68410 EXPORT_SYMBOL(__request_module);
68411 #endif /* CONFIG_MODULES */
68412
68413@@ -280,7 +333,7 @@ static int wait_for_helper(void *data)
68414 *
68415 * Thus the __user pointer cast is valid here.
68416 */
68417- sys_wait4(pid, (int __user *)&ret, 0, NULL);
68418+ sys_wait4(pid, (int __force_user *)&ret, 0, NULL);
68419
68420 /*
68421 * If ret is 0, either ____call_usermodehelper failed and the
68422diff --git a/kernel/kprobes.c b/kernel/kprobes.c
68423index c62b854..6fc810d 100644
68424--- a/kernel/kprobes.c
68425+++ b/kernel/kprobes.c
68426@@ -185,7 +185,7 @@ static kprobe_opcode_t __kprobes *__get_insn_slot(struct kprobe_insn_cache *c)
68427 * kernel image and loaded module images reside. This is required
68428 * so x86_64 can correctly handle the %rip-relative fixups.
68429 */
68430- kip->insns = module_alloc(PAGE_SIZE);
68431+ kip->insns = module_alloc_exec(PAGE_SIZE);
68432 if (!kip->insns) {
68433 kfree(kip);
68434 return NULL;
68435@@ -225,7 +225,7 @@ static int __kprobes collect_one_slot(struct kprobe_insn_page *kip, int idx)
68436 */
68437 if (!list_is_singular(&kip->list)) {
68438 list_del(&kip->list);
68439- module_free(NULL, kip->insns);
68440+ module_free_exec(NULL, kip->insns);
68441 kfree(kip);
68442 }
68443 return 1;
68444@@ -1955,7 +1955,7 @@ static int __init init_kprobes(void)
68445 {
68446 int i, err = 0;
68447 unsigned long offset = 0, size = 0;
68448- char *modname, namebuf[128];
68449+ char *modname, namebuf[KSYM_NAME_LEN];
68450 const char *symbol_name;
68451 void *addr;
68452 struct kprobe_blackpoint *kb;
68453@@ -2040,11 +2040,11 @@ static void __kprobes report_probe(struct seq_file *pi, struct kprobe *p,
68454 kprobe_type = "k";
68455
68456 if (sym)
68457- seq_printf(pi, "%p %s %s+0x%x %s ",
68458+ seq_printf(pi, "%pK %s %s+0x%x %s ",
68459 p->addr, kprobe_type, sym, offset,
68460 (modname ? modname : " "));
68461 else
68462- seq_printf(pi, "%p %s %p ",
68463+ seq_printf(pi, "%pK %s %pK ",
68464 p->addr, kprobe_type, p->addr);
68465
68466 if (!pp)
68467@@ -2081,7 +2081,7 @@ static int __kprobes show_kprobe_addr(struct seq_file *pi, void *v)
68468 const char *sym = NULL;
68469 unsigned int i = *(loff_t *) v;
68470 unsigned long offset = 0;
68471- char *modname, namebuf[128];
68472+ char *modname, namebuf[KSYM_NAME_LEN];
68473
68474 head = &kprobe_table[i];
68475 preempt_disable();
68476diff --git a/kernel/ksysfs.c b/kernel/ksysfs.c
68477index 4e316e1..5501eef 100644
68478--- a/kernel/ksysfs.c
68479+++ b/kernel/ksysfs.c
68480@@ -47,6 +47,8 @@ static ssize_t uevent_helper_store(struct kobject *kobj,
68481 {
68482 if (count+1 > UEVENT_HELPER_PATH_LEN)
68483 return -ENOENT;
68484+ if (!capable(CAP_SYS_ADMIN))
68485+ return -EPERM;
68486 memcpy(uevent_helper, buf, count);
68487 uevent_helper[count] = '\0';
68488 if (count && uevent_helper[count-1] == '\n')
68489diff --git a/kernel/lockdep.c b/kernel/lockdep.c
68490index ea9ee45..67ebc8f 100644
68491--- a/kernel/lockdep.c
68492+++ b/kernel/lockdep.c
68493@@ -590,6 +590,10 @@ static int static_obj(void *obj)
68494 end = (unsigned long) &_end,
68495 addr = (unsigned long) obj;
68496
68497+#ifdef CONFIG_PAX_KERNEXEC
68498+ start = ktla_ktva(start);
68499+#endif
68500+
68501 /*
68502 * static variable?
68503 */
68504@@ -730,6 +734,7 @@ register_lock_class(struct lockdep_map *lock, unsigned int subclass, int force)
68505 if (!static_obj(lock->key)) {
68506 debug_locks_off();
68507 printk("INFO: trying to register non-static key.\n");
68508+ printk("lock:%pS key:%pS.\n", lock, lock->key);
68509 printk("the code is fine but needs lockdep annotation.\n");
68510 printk("turning off the locking correctness validator.\n");
68511 dump_stack();
68512@@ -3042,7 +3047,7 @@ static int __lock_acquire(struct lockdep_map *lock, unsigned int subclass,
68513 if (!class)
68514 return 0;
68515 }
68516- atomic_inc((atomic_t *)&class->ops);
68517+ atomic_inc_unchecked((atomic_unchecked_t *)&class->ops);
68518 if (very_verbose(class)) {
68519 printk("\nacquire class [%p] %s", class->key, class->name);
68520 if (class->name_version > 1)
68521diff --git a/kernel/lockdep_proc.c b/kernel/lockdep_proc.c
68522index 91c32a0..7b88d63 100644
68523--- a/kernel/lockdep_proc.c
68524+++ b/kernel/lockdep_proc.c
68525@@ -39,7 +39,7 @@ static void l_stop(struct seq_file *m, void *v)
68526
68527 static void print_name(struct seq_file *m, struct lock_class *class)
68528 {
68529- char str[128];
68530+ char str[KSYM_NAME_LEN];
68531 const char *name = class->name;
68532
68533 if (!name) {
68534@@ -65,7 +65,7 @@ static int l_show(struct seq_file *m, void *v)
68535 return 0;
68536 }
68537
68538- seq_printf(m, "%p", class->key);
68539+ seq_printf(m, "%pK", class->key);
68540 #ifdef CONFIG_DEBUG_LOCKDEP
68541 seq_printf(m, " OPS:%8ld", class->ops);
68542 #endif
68543@@ -83,7 +83,7 @@ static int l_show(struct seq_file *m, void *v)
68544
68545 list_for_each_entry(entry, &class->locks_after, entry) {
68546 if (entry->distance == 1) {
68547- seq_printf(m, " -> [%p] ", entry->class->key);
68548+ seq_printf(m, " -> [%pK] ", entry->class->key);
68549 print_name(m, entry->class);
68550 seq_puts(m, "\n");
68551 }
68552@@ -152,7 +152,7 @@ static int lc_show(struct seq_file *m, void *v)
68553 if (!class->key)
68554 continue;
68555
68556- seq_printf(m, "[%p] ", class->key);
68557+ seq_printf(m, "[%pK] ", class->key);
68558 print_name(m, class);
68559 seq_puts(m, "\n");
68560 }
68561@@ -495,7 +495,7 @@ static void seq_stats(struct seq_file *m, struct lock_stat_data *data)
68562 if (!i)
68563 seq_line(m, '-', 40-namelen, namelen);
68564
68565- snprintf(ip, sizeof(ip), "[<%p>]",
68566+ snprintf(ip, sizeof(ip), "[<%pK>]",
68567 (void *)class->contention_point[i]);
68568 seq_printf(m, "%40s %14lu %29s %pS\n",
68569 name, stats->contention_point[i],
68570@@ -510,7 +510,7 @@ static void seq_stats(struct seq_file *m, struct lock_stat_data *data)
68571 if (!i)
68572 seq_line(m, '-', 40-namelen, namelen);
68573
68574- snprintf(ip, sizeof(ip), "[<%p>]",
68575+ snprintf(ip, sizeof(ip), "[<%pK>]",
68576 (void *)class->contending_point[i]);
68577 seq_printf(m, "%40s %14lu %29s %pS\n",
68578 name, stats->contending_point[i],
68579diff --git a/kernel/module.c b/kernel/module.c
68580index 2a15c59..731c128 100644
68581--- a/kernel/module.c
68582+++ b/kernel/module.c
68583@@ -58,6 +58,7 @@
68584 #include <linux/jump_label.h>
68585 #include <linux/pfn.h>
68586 #include <linux/bsearch.h>
68587+#include <linux/grsecurity.h>
68588
68589 #define CREATE_TRACE_POINTS
68590 #include <trace/events/module.h>
68591@@ -114,7 +115,8 @@ static BLOCKING_NOTIFIER_HEAD(module_notify_list);
68592
68593 /* Bounds of module allocation, for speeding __module_address.
68594 * Protected by module_mutex. */
68595-static unsigned long module_addr_min = -1UL, module_addr_max = 0;
68596+static unsigned long module_addr_min_rw = -1UL, module_addr_max_rw = 0;
68597+static unsigned long module_addr_min_rx = -1UL, module_addr_max_rx = 0;
68598
68599 int register_module_notifier(struct notifier_block * nb)
68600 {
68601@@ -278,7 +280,7 @@ bool each_symbol_section(bool (*fn)(const struct symsearch *arr,
68602 return true;
68603
68604 list_for_each_entry_rcu(mod, &modules, list) {
68605- struct symsearch arr[] = {
68606+ struct symsearch modarr[] = {
68607 { mod->syms, mod->syms + mod->num_syms, mod->crcs,
68608 NOT_GPL_ONLY, false },
68609 { mod->gpl_syms, mod->gpl_syms + mod->num_gpl_syms,
68610@@ -300,7 +302,7 @@ bool each_symbol_section(bool (*fn)(const struct symsearch *arr,
68611 #endif
68612 };
68613
68614- if (each_symbol_in_section(arr, ARRAY_SIZE(arr), mod, fn, data))
68615+ if (each_symbol_in_section(modarr, ARRAY_SIZE(modarr), mod, fn, data))
68616 return true;
68617 }
68618 return false;
68619@@ -432,7 +434,7 @@ static inline void __percpu *mod_percpu(struct module *mod)
68620 static int percpu_modalloc(struct module *mod,
68621 unsigned long size, unsigned long align)
68622 {
68623- if (align > PAGE_SIZE) {
68624+ if (align-1 >= PAGE_SIZE) {
68625 printk(KERN_WARNING "%s: per-cpu alignment %li > %li\n",
68626 mod->name, align, PAGE_SIZE);
68627 align = PAGE_SIZE;
68628@@ -1032,7 +1034,7 @@ struct module_attribute module_uevent =
68629 static ssize_t show_coresize(struct module_attribute *mattr,
68630 struct module_kobject *mk, char *buffer)
68631 {
68632- return sprintf(buffer, "%u\n", mk->mod->core_size);
68633+ return sprintf(buffer, "%u\n", mk->mod->core_size_rx + mk->mod->core_size_rw);
68634 }
68635
68636 static struct module_attribute modinfo_coresize =
68637@@ -1041,7 +1043,7 @@ static struct module_attribute modinfo_coresize =
68638 static ssize_t show_initsize(struct module_attribute *mattr,
68639 struct module_kobject *mk, char *buffer)
68640 {
68641- return sprintf(buffer, "%u\n", mk->mod->init_size);
68642+ return sprintf(buffer, "%u\n", mk->mod->init_size_rx + mk->mod->init_size_rw);
68643 }
68644
68645 static struct module_attribute modinfo_initsize =
68646@@ -1255,7 +1257,7 @@ resolve_symbol_wait(struct module *mod,
68647 */
68648 #ifdef CONFIG_SYSFS
68649
68650-#ifdef CONFIG_KALLSYMS
68651+#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
68652 static inline bool sect_empty(const Elf_Shdr *sect)
68653 {
68654 return !(sect->sh_flags & SHF_ALLOC) || sect->sh_size == 0;
68655@@ -1721,21 +1723,21 @@ static void set_section_ro_nx(void *base,
68656
68657 static void unset_module_core_ro_nx(struct module *mod)
68658 {
68659- set_page_attributes(mod->module_core + mod->core_text_size,
68660- mod->module_core + mod->core_size,
68661+ set_page_attributes(mod->module_core_rw,
68662+ mod->module_core_rw + mod->core_size_rw,
68663 set_memory_x);
68664- set_page_attributes(mod->module_core,
68665- mod->module_core + mod->core_ro_size,
68666+ set_page_attributes(mod->module_core_rx,
68667+ mod->module_core_rx + mod->core_size_rx,
68668 set_memory_rw);
68669 }
68670
68671 static void unset_module_init_ro_nx(struct module *mod)
68672 {
68673- set_page_attributes(mod->module_init + mod->init_text_size,
68674- mod->module_init + mod->init_size,
68675+ set_page_attributes(mod->module_init_rw,
68676+ mod->module_init_rw + mod->init_size_rw,
68677 set_memory_x);
68678- set_page_attributes(mod->module_init,
68679- mod->module_init + mod->init_ro_size,
68680+ set_page_attributes(mod->module_init_rx,
68681+ mod->module_init_rx + mod->init_size_rx,
68682 set_memory_rw);
68683 }
68684
68685@@ -1746,14 +1748,14 @@ void set_all_modules_text_rw(void)
68686
68687 mutex_lock(&module_mutex);
68688 list_for_each_entry_rcu(mod, &modules, list) {
68689- if ((mod->module_core) && (mod->core_text_size)) {
68690- set_page_attributes(mod->module_core,
68691- mod->module_core + mod->core_text_size,
68692+ if ((mod->module_core_rx) && (mod->core_size_rx)) {
68693+ set_page_attributes(mod->module_core_rx,
68694+ mod->module_core_rx + mod->core_size_rx,
68695 set_memory_rw);
68696 }
68697- if ((mod->module_init) && (mod->init_text_size)) {
68698- set_page_attributes(mod->module_init,
68699- mod->module_init + mod->init_text_size,
68700+ if ((mod->module_init_rx) && (mod->init_size_rx)) {
68701+ set_page_attributes(mod->module_init_rx,
68702+ mod->module_init_rx + mod->init_size_rx,
68703 set_memory_rw);
68704 }
68705 }
68706@@ -1767,14 +1769,14 @@ void set_all_modules_text_ro(void)
68707
68708 mutex_lock(&module_mutex);
68709 list_for_each_entry_rcu(mod, &modules, list) {
68710- if ((mod->module_core) && (mod->core_text_size)) {
68711- set_page_attributes(mod->module_core,
68712- mod->module_core + mod->core_text_size,
68713+ if ((mod->module_core_rx) && (mod->core_size_rx)) {
68714+ set_page_attributes(mod->module_core_rx,
68715+ mod->module_core_rx + mod->core_size_rx,
68716 set_memory_ro);
68717 }
68718- if ((mod->module_init) && (mod->init_text_size)) {
68719- set_page_attributes(mod->module_init,
68720- mod->module_init + mod->init_text_size,
68721+ if ((mod->module_init_rx) && (mod->init_size_rx)) {
68722+ set_page_attributes(mod->module_init_rx,
68723+ mod->module_init_rx + mod->init_size_rx,
68724 set_memory_ro);
68725 }
68726 }
68727@@ -1820,16 +1822,19 @@ static void free_module(struct module *mod)
68728
68729 /* This may be NULL, but that's OK */
68730 unset_module_init_ro_nx(mod);
68731- module_free(mod, mod->module_init);
68732+ module_free(mod, mod->module_init_rw);
68733+ module_free_exec(mod, mod->module_init_rx);
68734 kfree(mod->args);
68735 percpu_modfree(mod);
68736
68737 /* Free lock-classes: */
68738- lockdep_free_key_range(mod->module_core, mod->core_size);
68739+ lockdep_free_key_range(mod->module_core_rx, mod->core_size_rx);
68740+ lockdep_free_key_range(mod->module_core_rw, mod->core_size_rw);
68741
68742 /* Finally, free the core (containing the module structure) */
68743 unset_module_core_ro_nx(mod);
68744- module_free(mod, mod->module_core);
68745+ module_free_exec(mod, mod->module_core_rx);
68746+ module_free(mod, mod->module_core_rw);
68747
68748 #ifdef CONFIG_MPU
68749 update_protections(current->mm);
68750@@ -1899,9 +1904,31 @@ static int simplify_symbols(struct module *mod, const struct load_info *info)
68751 int ret = 0;
68752 const struct kernel_symbol *ksym;
68753
68754+#ifdef CONFIG_GRKERNSEC_MODHARDEN
68755+ int is_fs_load = 0;
68756+ int register_filesystem_found = 0;
68757+ char *p;
68758+
68759+ p = strstr(mod->args, "grsec_modharden_fs");
68760+ if (p) {
68761+ char *endptr = p + sizeof("grsec_modharden_fs") - 1;
68762+ /* copy \0 as well */
68763+ memmove(p, endptr, strlen(mod->args) - (unsigned int)(endptr - mod->args) + 1);
68764+ is_fs_load = 1;
68765+ }
68766+#endif
68767+
68768 for (i = 1; i < symsec->sh_size / sizeof(Elf_Sym); i++) {
68769 const char *name = info->strtab + sym[i].st_name;
68770
68771+#ifdef CONFIG_GRKERNSEC_MODHARDEN
68772+ /* it's a real shame this will never get ripped and copied
68773+ upstream! ;(
68774+ */
68775+ if (is_fs_load && !strcmp(name, "register_filesystem"))
68776+ register_filesystem_found = 1;
68777+#endif
68778+
68779 switch (sym[i].st_shndx) {
68780 case SHN_COMMON:
68781 /* We compiled with -fno-common. These are not
68782@@ -1922,7 +1949,9 @@ static int simplify_symbols(struct module *mod, const struct load_info *info)
68783 ksym = resolve_symbol_wait(mod, info, name);
68784 /* Ok if resolved. */
68785 if (ksym && !IS_ERR(ksym)) {
68786+ pax_open_kernel();
68787 sym[i].st_value = ksym->value;
68788+ pax_close_kernel();
68789 break;
68790 }
68791
68792@@ -1941,11 +1970,20 @@ static int simplify_symbols(struct module *mod, const struct load_info *info)
68793 secbase = (unsigned long)mod_percpu(mod);
68794 else
68795 secbase = info->sechdrs[sym[i].st_shndx].sh_addr;
68796+ pax_open_kernel();
68797 sym[i].st_value += secbase;
68798+ pax_close_kernel();
68799 break;
68800 }
68801 }
68802
68803+#ifdef CONFIG_GRKERNSEC_MODHARDEN
68804+ if (is_fs_load && !register_filesystem_found) {
68805+ printk(KERN_ALERT "grsec: Denied attempt to load non-fs module %.64s through mount\n", mod->name);
68806+ ret = -EPERM;
68807+ }
68808+#endif
68809+
68810 return ret;
68811 }
68812
68813@@ -2049,22 +2087,12 @@ static void layout_sections(struct module *mod, struct load_info *info)
68814 || s->sh_entsize != ~0UL
68815 || strstarts(sname, ".init"))
68816 continue;
68817- s->sh_entsize = get_offset(mod, &mod->core_size, s, i);
68818+ if ((s->sh_flags & SHF_WRITE) || !(s->sh_flags & SHF_ALLOC))
68819+ s->sh_entsize = get_offset(mod, &mod->core_size_rw, s, i);
68820+ else
68821+ s->sh_entsize = get_offset(mod, &mod->core_size_rx, s, i);
68822 pr_debug("\t%s\n", sname);
68823 }
68824- switch (m) {
68825- case 0: /* executable */
68826- mod->core_size = debug_align(mod->core_size);
68827- mod->core_text_size = mod->core_size;
68828- break;
68829- case 1: /* RO: text and ro-data */
68830- mod->core_size = debug_align(mod->core_size);
68831- mod->core_ro_size = mod->core_size;
68832- break;
68833- case 3: /* whole core */
68834- mod->core_size = debug_align(mod->core_size);
68835- break;
68836- }
68837 }
68838
68839 pr_debug("Init section allocation order:\n");
68840@@ -2078,23 +2106,13 @@ static void layout_sections(struct module *mod, struct load_info *info)
68841 || s->sh_entsize != ~0UL
68842 || !strstarts(sname, ".init"))
68843 continue;
68844- s->sh_entsize = (get_offset(mod, &mod->init_size, s, i)
68845- | INIT_OFFSET_MASK);
68846+ if ((s->sh_flags & SHF_WRITE) || !(s->sh_flags & SHF_ALLOC))
68847+ s->sh_entsize = get_offset(mod, &mod->init_size_rw, s, i);
68848+ else
68849+ s->sh_entsize = get_offset(mod, &mod->init_size_rx, s, i);
68850+ s->sh_entsize |= INIT_OFFSET_MASK;
68851 pr_debug("\t%s\n", sname);
68852 }
68853- switch (m) {
68854- case 0: /* executable */
68855- mod->init_size = debug_align(mod->init_size);
68856- mod->init_text_size = mod->init_size;
68857- break;
68858- case 1: /* RO: text and ro-data */
68859- mod->init_size = debug_align(mod->init_size);
68860- mod->init_ro_size = mod->init_size;
68861- break;
68862- case 3: /* whole init */
68863- mod->init_size = debug_align(mod->init_size);
68864- break;
68865- }
68866 }
68867 }
68868
68869@@ -2266,7 +2284,7 @@ static void layout_symtab(struct module *mod, struct load_info *info)
68870
68871 /* Put symbol section at end of init part of module. */
68872 symsect->sh_flags |= SHF_ALLOC;
68873- symsect->sh_entsize = get_offset(mod, &mod->init_size, symsect,
68874+ symsect->sh_entsize = get_offset(mod, &mod->init_size_rx, symsect,
68875 info->index.sym) | INIT_OFFSET_MASK;
68876 pr_debug("\t%s\n", info->secstrings + symsect->sh_name);
68877
68878@@ -2286,13 +2304,13 @@ static void layout_symtab(struct module *mod, struct load_info *info)
68879 }
68880
68881 /* Append room for core symbols at end of core part. */
68882- info->symoffs = ALIGN(mod->core_size, symsect->sh_addralign ?: 1);
68883- info->stroffs = mod->core_size = info->symoffs + ndst * sizeof(Elf_Sym);
68884- mod->core_size += strtab_size;
68885+ info->symoffs = ALIGN(mod->core_size_rx, symsect->sh_addralign ?: 1);
68886+ info->stroffs = mod->core_size_rx = info->symoffs + ndst * sizeof(Elf_Sym);
68887+ mod->core_size_rx += strtab_size;
68888
68889 /* Put string table section at end of init part of module. */
68890 strsect->sh_flags |= SHF_ALLOC;
68891- strsect->sh_entsize = get_offset(mod, &mod->init_size, strsect,
68892+ strsect->sh_entsize = get_offset(mod, &mod->init_size_rx, strsect,
68893 info->index.str) | INIT_OFFSET_MASK;
68894 pr_debug("\t%s\n", info->secstrings + strsect->sh_name);
68895 }
68896@@ -2310,12 +2328,14 @@ static void add_kallsyms(struct module *mod, const struct load_info *info)
68897 /* Make sure we get permanent strtab: don't use info->strtab. */
68898 mod->strtab = (void *)info->sechdrs[info->index.str].sh_addr;
68899
68900+ pax_open_kernel();
68901+
68902 /* Set types up while we still have access to sections. */
68903 for (i = 0; i < mod->num_symtab; i++)
68904 mod->symtab[i].st_info = elf_type(&mod->symtab[i], info);
68905
68906- mod->core_symtab = dst = mod->module_core + info->symoffs;
68907- mod->core_strtab = s = mod->module_core + info->stroffs;
68908+ mod->core_symtab = dst = mod->module_core_rx + info->symoffs;
68909+ mod->core_strtab = s = mod->module_core_rx + info->stroffs;
68910 src = mod->symtab;
68911 *s++ = 0;
68912 for (ndst = i = 0; i < mod->num_symtab; i++) {
68913@@ -2328,6 +2348,8 @@ static void add_kallsyms(struct module *mod, const struct load_info *info)
68914 }
68915 }
68916 mod->core_num_syms = ndst;
68917+
68918+ pax_close_kernel();
68919 }
68920 #else
68921 static inline void layout_symtab(struct module *mod, struct load_info *info)
68922@@ -2361,17 +2383,33 @@ void * __weak module_alloc(unsigned long size)
68923 return size == 0 ? NULL : vmalloc_exec(size);
68924 }
68925
68926-static void *module_alloc_update_bounds(unsigned long size)
68927+static void *module_alloc_update_bounds_rw(unsigned long size)
68928 {
68929 void *ret = module_alloc(size);
68930
68931 if (ret) {
68932 mutex_lock(&module_mutex);
68933 /* Update module bounds. */
68934- if ((unsigned long)ret < module_addr_min)
68935- module_addr_min = (unsigned long)ret;
68936- if ((unsigned long)ret + size > module_addr_max)
68937- module_addr_max = (unsigned long)ret + size;
68938+ if ((unsigned long)ret < module_addr_min_rw)
68939+ module_addr_min_rw = (unsigned long)ret;
68940+ if ((unsigned long)ret + size > module_addr_max_rw)
68941+ module_addr_max_rw = (unsigned long)ret + size;
68942+ mutex_unlock(&module_mutex);
68943+ }
68944+ return ret;
68945+}
68946+
68947+static void *module_alloc_update_bounds_rx(unsigned long size)
68948+{
68949+ void *ret = module_alloc_exec(size);
68950+
68951+ if (ret) {
68952+ mutex_lock(&module_mutex);
68953+ /* Update module bounds. */
68954+ if ((unsigned long)ret < module_addr_min_rx)
68955+ module_addr_min_rx = (unsigned long)ret;
68956+ if ((unsigned long)ret + size > module_addr_max_rx)
68957+ module_addr_max_rx = (unsigned long)ret + size;
68958 mutex_unlock(&module_mutex);
68959 }
68960 return ret;
68961@@ -2549,8 +2587,14 @@ static struct module *setup_load_info(struct load_info *info)
68962 static int check_modinfo(struct module *mod, struct load_info *info)
68963 {
68964 const char *modmagic = get_modinfo(info, "vermagic");
68965+ const char *license = get_modinfo(info, "license");
68966 int err;
68967
68968+#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR
68969+ if (!license || !license_is_gpl_compatible(license))
68970+ return -ENOEXEC;
68971+#endif
68972+
68973 /* This is allowed: modprobe --force will invalidate it. */
68974 if (!modmagic) {
68975 err = try_to_force_load(mod, "bad vermagic");
68976@@ -2573,7 +2617,7 @@ static int check_modinfo(struct module *mod, struct load_info *info)
68977 }
68978
68979 /* Set up license info based on the info section */
68980- set_license(mod, get_modinfo(info, "license"));
68981+ set_license(mod, license);
68982
68983 return 0;
68984 }
68985@@ -2667,7 +2711,7 @@ static int move_module(struct module *mod, struct load_info *info)
68986 void *ptr;
68987
68988 /* Do the allocs. */
68989- ptr = module_alloc_update_bounds(mod->core_size);
68990+ ptr = module_alloc_update_bounds_rw(mod->core_size_rw);
68991 /*
68992 * The pointer to this block is stored in the module structure
68993 * which is inside the block. Just mark it as not being a
68994@@ -2677,23 +2721,50 @@ static int move_module(struct module *mod, struct load_info *info)
68995 if (!ptr)
68996 return -ENOMEM;
68997
68998- memset(ptr, 0, mod->core_size);
68999- mod->module_core = ptr;
69000+ memset(ptr, 0, mod->core_size_rw);
69001+ mod->module_core_rw = ptr;
69002
69003- ptr = module_alloc_update_bounds(mod->init_size);
69004+ ptr = module_alloc_update_bounds_rw(mod->init_size_rw);
69005 /*
69006 * The pointer to this block is stored in the module structure
69007 * which is inside the block. This block doesn't need to be
69008 * scanned as it contains data and code that will be freed
69009 * after the module is initialized.
69010 */
69011- kmemleak_ignore(ptr);
69012- if (!ptr && mod->init_size) {
69013- module_free(mod, mod->module_core);
69014+ kmemleak_not_leak(ptr);
69015+ if (!ptr && mod->init_size_rw) {
69016+ module_free(mod, mod->module_core_rw);
69017 return -ENOMEM;
69018 }
69019- memset(ptr, 0, mod->init_size);
69020- mod->module_init = ptr;
69021+ memset(ptr, 0, mod->init_size_rw);
69022+ mod->module_init_rw = ptr;
69023+
69024+ ptr = module_alloc_update_bounds_rx(mod->core_size_rx);
69025+ kmemleak_not_leak(ptr);
69026+ if (!ptr) {
69027+ module_free(mod, mod->module_init_rw);
69028+ module_free(mod, mod->module_core_rw);
69029+ return -ENOMEM;
69030+ }
69031+
69032+ pax_open_kernel();
69033+ memset(ptr, 0, mod->core_size_rx);
69034+ pax_close_kernel();
69035+ mod->module_core_rx = ptr;
69036+
69037+ ptr = module_alloc_update_bounds_rx(mod->init_size_rx);
69038+ kmemleak_not_leak(ptr);
69039+ if (!ptr && mod->init_size_rx) {
69040+ module_free_exec(mod, mod->module_core_rx);
69041+ module_free(mod, mod->module_init_rw);
69042+ module_free(mod, mod->module_core_rw);
69043+ return -ENOMEM;
69044+ }
69045+
69046+ pax_open_kernel();
69047+ memset(ptr, 0, mod->init_size_rx);
69048+ pax_close_kernel();
69049+ mod->module_init_rx = ptr;
69050
69051 /* Transfer each section which specifies SHF_ALLOC */
69052 pr_debug("final section addresses:\n");
69053@@ -2704,16 +2775,45 @@ static int move_module(struct module *mod, struct load_info *info)
69054 if (!(shdr->sh_flags & SHF_ALLOC))
69055 continue;
69056
69057- if (shdr->sh_entsize & INIT_OFFSET_MASK)
69058- dest = mod->module_init
69059- + (shdr->sh_entsize & ~INIT_OFFSET_MASK);
69060- else
69061- dest = mod->module_core + shdr->sh_entsize;
69062+ if (shdr->sh_entsize & INIT_OFFSET_MASK) {
69063+ if ((shdr->sh_flags & SHF_WRITE) || !(shdr->sh_flags & SHF_ALLOC))
69064+ dest = mod->module_init_rw
69065+ + (shdr->sh_entsize & ~INIT_OFFSET_MASK);
69066+ else
69067+ dest = mod->module_init_rx
69068+ + (shdr->sh_entsize & ~INIT_OFFSET_MASK);
69069+ } else {
69070+ if ((shdr->sh_flags & SHF_WRITE) || !(shdr->sh_flags & SHF_ALLOC))
69071+ dest = mod->module_core_rw + shdr->sh_entsize;
69072+ else
69073+ dest = mod->module_core_rx + shdr->sh_entsize;
69074+ }
69075+
69076+ if (shdr->sh_type != SHT_NOBITS) {
69077+
69078+#ifdef CONFIG_PAX_KERNEXEC
69079+#ifdef CONFIG_X86_64
69080+ if ((shdr->sh_flags & SHF_WRITE) && (shdr->sh_flags & SHF_EXECINSTR))
69081+ set_memory_x((unsigned long)dest, (shdr->sh_size + PAGE_SIZE) >> PAGE_SHIFT);
69082+#endif
69083+ if (!(shdr->sh_flags & SHF_WRITE) && (shdr->sh_flags & SHF_ALLOC)) {
69084+ pax_open_kernel();
69085+ memcpy(dest, (void *)shdr->sh_addr, shdr->sh_size);
69086+ pax_close_kernel();
69087+ } else
69088+#endif
69089
69090- if (shdr->sh_type != SHT_NOBITS)
69091 memcpy(dest, (void *)shdr->sh_addr, shdr->sh_size);
69092+ }
69093 /* Update sh_addr to point to copy in image. */
69094- shdr->sh_addr = (unsigned long)dest;
69095+
69096+#ifdef CONFIG_PAX_KERNEXEC
69097+ if (shdr->sh_flags & SHF_EXECINSTR)
69098+ shdr->sh_addr = ktva_ktla((unsigned long)dest);
69099+ else
69100+#endif
69101+
69102+ shdr->sh_addr = (unsigned long)dest;
69103 pr_debug("\t0x%lx %s\n",
69104 (long)shdr->sh_addr, info->secstrings + shdr->sh_name);
69105 }
69106@@ -2768,12 +2868,12 @@ static void flush_module_icache(const struct module *mod)
69107 * Do it before processing of module parameters, so the module
69108 * can provide parameter accessor functions of its own.
69109 */
69110- if (mod->module_init)
69111- flush_icache_range((unsigned long)mod->module_init,
69112- (unsigned long)mod->module_init
69113- + mod->init_size);
69114- flush_icache_range((unsigned long)mod->module_core,
69115- (unsigned long)mod->module_core + mod->core_size);
69116+ if (mod->module_init_rx)
69117+ flush_icache_range((unsigned long)mod->module_init_rx,
69118+ (unsigned long)mod->module_init_rx
69119+ + mod->init_size_rx);
69120+ flush_icache_range((unsigned long)mod->module_core_rx,
69121+ (unsigned long)mod->module_core_rx + mod->core_size_rx);
69122
69123 set_fs(old_fs);
69124 }
69125@@ -2843,8 +2943,10 @@ out:
69126 static void module_deallocate(struct module *mod, struct load_info *info)
69127 {
69128 percpu_modfree(mod);
69129- module_free(mod, mod->module_init);
69130- module_free(mod, mod->module_core);
69131+ module_free_exec(mod, mod->module_init_rx);
69132+ module_free_exec(mod, mod->module_core_rx);
69133+ module_free(mod, mod->module_init_rw);
69134+ module_free(mod, mod->module_core_rw);
69135 }
69136
69137 int __weak module_finalize(const Elf_Ehdr *hdr,
69138@@ -2857,7 +2959,9 @@ int __weak module_finalize(const Elf_Ehdr *hdr,
69139 static int post_relocation(struct module *mod, const struct load_info *info)
69140 {
69141 /* Sort exception table now relocations are done. */
69142+ pax_open_kernel();
69143 sort_extable(mod->extable, mod->extable + mod->num_exentries);
69144+ pax_close_kernel();
69145
69146 /* Copy relocated percpu area over. */
69147 percpu_modcopy(mod, (void *)info->sechdrs[info->index.pcpu].sh_addr,
69148@@ -2908,9 +3012,38 @@ static struct module *load_module(void __user *umod,
69149 if (err)
69150 goto free_unload;
69151
69152+ /* Now copy in args */
69153+ mod->args = strndup_user(uargs, ~0UL >> 1);
69154+ if (IS_ERR(mod->args)) {
69155+ err = PTR_ERR(mod->args);
69156+ goto free_unload;
69157+ }
69158+
69159 /* Set up MODINFO_ATTR fields */
69160 setup_modinfo(mod, &info);
69161
69162+#ifdef CONFIG_GRKERNSEC_MODHARDEN
69163+ {
69164+ char *p, *p2;
69165+
69166+ if (strstr(mod->args, "grsec_modharden_netdev")) {
69167+ 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);
69168+ err = -EPERM;
69169+ goto free_modinfo;
69170+ } else if ((p = strstr(mod->args, "grsec_modharden_normal"))) {
69171+ p += sizeof("grsec_modharden_normal") - 1;
69172+ p2 = strstr(p, "_");
69173+ if (p2) {
69174+ *p2 = '\0';
69175+ printk(KERN_ALERT "grsec: denied kernel module auto-load of %.64s by uid %.9s\n", mod->name, p);
69176+ *p2 = '_';
69177+ }
69178+ err = -EPERM;
69179+ goto free_modinfo;
69180+ }
69181+ }
69182+#endif
69183+
69184 /* Fix up syms, so that st_value is a pointer to location. */
69185 err = simplify_symbols(mod, &info);
69186 if (err < 0)
69187@@ -2926,13 +3059,6 @@ static struct module *load_module(void __user *umod,
69188
69189 flush_module_icache(mod);
69190
69191- /* Now copy in args */
69192- mod->args = strndup_user(uargs, ~0UL >> 1);
69193- if (IS_ERR(mod->args)) {
69194- err = PTR_ERR(mod->args);
69195- goto free_arch_cleanup;
69196- }
69197-
69198 /* Mark state as coming so strong_try_module_get() ignores us. */
69199 mod->state = MODULE_STATE_COMING;
69200
69201@@ -2990,11 +3116,10 @@ static struct module *load_module(void __user *umod,
69202 unlock:
69203 mutex_unlock(&module_mutex);
69204 synchronize_sched();
69205- kfree(mod->args);
69206- free_arch_cleanup:
69207 module_arch_cleanup(mod);
69208 free_modinfo:
69209 free_modinfo(mod);
69210+ kfree(mod->args);
69211 free_unload:
69212 module_unload_free(mod);
69213 free_module:
69214@@ -3035,16 +3160,16 @@ SYSCALL_DEFINE3(init_module, void __user *, umod,
69215 MODULE_STATE_COMING, mod);
69216
69217 /* Set RO and NX regions for core */
69218- set_section_ro_nx(mod->module_core,
69219- mod->core_text_size,
69220- mod->core_ro_size,
69221- mod->core_size);
69222+ set_section_ro_nx(mod->module_core_rx,
69223+ mod->core_size_rx,
69224+ mod->core_size_rx,
69225+ mod->core_size_rx);
69226
69227 /* Set RO and NX regions for init */
69228- set_section_ro_nx(mod->module_init,
69229- mod->init_text_size,
69230- mod->init_ro_size,
69231- mod->init_size);
69232+ set_section_ro_nx(mod->module_init_rx,
69233+ mod->init_size_rx,
69234+ mod->init_size_rx,
69235+ mod->init_size_rx);
69236
69237 do_mod_ctors(mod);
69238 /* Start the module */
69239@@ -3090,11 +3215,12 @@ SYSCALL_DEFINE3(init_module, void __user *, umod,
69240 mod->strtab = mod->core_strtab;
69241 #endif
69242 unset_module_init_ro_nx(mod);
69243- module_free(mod, mod->module_init);
69244- mod->module_init = NULL;
69245- mod->init_size = 0;
69246- mod->init_ro_size = 0;
69247- mod->init_text_size = 0;
69248+ module_free(mod, mod->module_init_rw);
69249+ module_free_exec(mod, mod->module_init_rx);
69250+ mod->module_init_rw = NULL;
69251+ mod->module_init_rx = NULL;
69252+ mod->init_size_rw = 0;
69253+ mod->init_size_rx = 0;
69254 mutex_unlock(&module_mutex);
69255
69256 return 0;
69257@@ -3125,10 +3251,16 @@ static const char *get_ksymbol(struct module *mod,
69258 unsigned long nextval;
69259
69260 /* At worse, next value is at end of module */
69261- if (within_module_init(addr, mod))
69262- nextval = (unsigned long)mod->module_init+mod->init_text_size;
69263+ if (within_module_init_rx(addr, mod))
69264+ nextval = (unsigned long)mod->module_init_rx+mod->init_size_rx;
69265+ else if (within_module_init_rw(addr, mod))
69266+ nextval = (unsigned long)mod->module_init_rw+mod->init_size_rw;
69267+ else if (within_module_core_rx(addr, mod))
69268+ nextval = (unsigned long)mod->module_core_rx+mod->core_size_rx;
69269+ else if (within_module_core_rw(addr, mod))
69270+ nextval = (unsigned long)mod->module_core_rw+mod->core_size_rw;
69271 else
69272- nextval = (unsigned long)mod->module_core+mod->core_text_size;
69273+ return NULL;
69274
69275 /* Scan for closest preceding symbol, and next symbol. (ELF
69276 starts real symbols at 1). */
69277@@ -3363,7 +3495,7 @@ static int m_show(struct seq_file *m, void *p)
69278 char buf[8];
69279
69280 seq_printf(m, "%s %u",
69281- mod->name, mod->init_size + mod->core_size);
69282+ mod->name, mod->init_size_rx + mod->init_size_rw + mod->core_size_rx + mod->core_size_rw);
69283 print_unload_info(m, mod);
69284
69285 /* Informative for users. */
69286@@ -3372,7 +3504,7 @@ static int m_show(struct seq_file *m, void *p)
69287 mod->state == MODULE_STATE_COMING ? "Loading":
69288 "Live");
69289 /* Used by oprofile and other similar tools. */
69290- seq_printf(m, " 0x%pK", mod->module_core);
69291+ seq_printf(m, " 0x%pK 0x%pK", mod->module_core_rx, mod->module_core_rw);
69292
69293 /* Taints info */
69294 if (mod->taints)
69295@@ -3408,7 +3540,17 @@ static const struct file_operations proc_modules_operations = {
69296
69297 static int __init proc_modules_init(void)
69298 {
69299+#ifndef CONFIG_GRKERNSEC_HIDESYM
69300+#ifdef CONFIG_GRKERNSEC_PROC_USER
69301+ proc_create("modules", S_IRUSR, NULL, &proc_modules_operations);
69302+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
69303+ proc_create("modules", S_IRUSR | S_IRGRP, NULL, &proc_modules_operations);
69304+#else
69305 proc_create("modules", 0, NULL, &proc_modules_operations);
69306+#endif
69307+#else
69308+ proc_create("modules", S_IRUSR, NULL, &proc_modules_operations);
69309+#endif
69310 return 0;
69311 }
69312 module_init(proc_modules_init);
69313@@ -3467,12 +3609,12 @@ struct module *__module_address(unsigned long addr)
69314 {
69315 struct module *mod;
69316
69317- if (addr < module_addr_min || addr > module_addr_max)
69318+ if ((addr < module_addr_min_rx || addr > module_addr_max_rx) &&
69319+ (addr < module_addr_min_rw || addr > module_addr_max_rw))
69320 return NULL;
69321
69322 list_for_each_entry_rcu(mod, &modules, list)
69323- if (within_module_core(addr, mod)
69324- || within_module_init(addr, mod))
69325+ if (within_module_init(addr, mod) || within_module_core(addr, mod))
69326 return mod;
69327 return NULL;
69328 }
69329@@ -3506,11 +3648,20 @@ bool is_module_text_address(unsigned long addr)
69330 */
69331 struct module *__module_text_address(unsigned long addr)
69332 {
69333- struct module *mod = __module_address(addr);
69334+ struct module *mod;
69335+
69336+#ifdef CONFIG_X86_32
69337+ addr = ktla_ktva(addr);
69338+#endif
69339+
69340+ if (addr < module_addr_min_rx || addr > module_addr_max_rx)
69341+ return NULL;
69342+
69343+ mod = __module_address(addr);
69344+
69345 if (mod) {
69346 /* Make sure it's within the text section. */
69347- if (!within(addr, mod->module_init, mod->init_text_size)
69348- && !within(addr, mod->module_core, mod->core_text_size))
69349+ if (!within_module_init_rx(addr, mod) && !within_module_core_rx(addr, mod))
69350 mod = NULL;
69351 }
69352 return mod;
69353diff --git a/kernel/mutex-debug.c b/kernel/mutex-debug.c
69354index 7e3443f..b2a1e6b 100644
69355--- a/kernel/mutex-debug.c
69356+++ b/kernel/mutex-debug.c
69357@@ -49,21 +49,21 @@ void debug_mutex_free_waiter(struct mutex_waiter *waiter)
69358 }
69359
69360 void debug_mutex_add_waiter(struct mutex *lock, struct mutex_waiter *waiter,
69361- struct thread_info *ti)
69362+ struct task_struct *task)
69363 {
69364 SMP_DEBUG_LOCKS_WARN_ON(!spin_is_locked(&lock->wait_lock));
69365
69366 /* Mark the current thread as blocked on the lock: */
69367- ti->task->blocked_on = waiter;
69368+ task->blocked_on = waiter;
69369 }
69370
69371 void mutex_remove_waiter(struct mutex *lock, struct mutex_waiter *waiter,
69372- struct thread_info *ti)
69373+ struct task_struct *task)
69374 {
69375 DEBUG_LOCKS_WARN_ON(list_empty(&waiter->list));
69376- DEBUG_LOCKS_WARN_ON(waiter->task != ti->task);
69377- DEBUG_LOCKS_WARN_ON(ti->task->blocked_on != waiter);
69378- ti->task->blocked_on = NULL;
69379+ DEBUG_LOCKS_WARN_ON(waiter->task != task);
69380+ DEBUG_LOCKS_WARN_ON(task->blocked_on != waiter);
69381+ task->blocked_on = NULL;
69382
69383 list_del_init(&waiter->list);
69384 waiter->task = NULL;
69385diff --git a/kernel/mutex-debug.h b/kernel/mutex-debug.h
69386index 0799fd3..d06ae3b 100644
69387--- a/kernel/mutex-debug.h
69388+++ b/kernel/mutex-debug.h
69389@@ -20,9 +20,9 @@ extern void debug_mutex_wake_waiter(struct mutex *lock,
69390 extern void debug_mutex_free_waiter(struct mutex_waiter *waiter);
69391 extern void debug_mutex_add_waiter(struct mutex *lock,
69392 struct mutex_waiter *waiter,
69393- struct thread_info *ti);
69394+ struct task_struct *task);
69395 extern void mutex_remove_waiter(struct mutex *lock, struct mutex_waiter *waiter,
69396- struct thread_info *ti);
69397+ struct task_struct *task);
69398 extern void debug_mutex_unlock(struct mutex *lock);
69399 extern void debug_mutex_init(struct mutex *lock, const char *name,
69400 struct lock_class_key *key);
69401diff --git a/kernel/mutex.c b/kernel/mutex.c
69402index a307cc9..27fd2e9 100644
69403--- a/kernel/mutex.c
69404+++ b/kernel/mutex.c
69405@@ -198,7 +198,7 @@ __mutex_lock_common(struct mutex *lock, long state, unsigned int subclass,
69406 spin_lock_mutex(&lock->wait_lock, flags);
69407
69408 debug_mutex_lock_common(lock, &waiter);
69409- debug_mutex_add_waiter(lock, &waiter, task_thread_info(task));
69410+ debug_mutex_add_waiter(lock, &waiter, task);
69411
69412 /* add waiting tasks to the end of the waitqueue (FIFO): */
69413 list_add_tail(&waiter.list, &lock->wait_list);
69414@@ -227,8 +227,7 @@ __mutex_lock_common(struct mutex *lock, long state, unsigned int subclass,
69415 * TASK_UNINTERRUPTIBLE case.)
69416 */
69417 if (unlikely(signal_pending_state(state, task))) {
69418- mutex_remove_waiter(lock, &waiter,
69419- task_thread_info(task));
69420+ mutex_remove_waiter(lock, &waiter, task);
69421 mutex_release(&lock->dep_map, 1, ip);
69422 spin_unlock_mutex(&lock->wait_lock, flags);
69423
69424@@ -247,7 +246,7 @@ __mutex_lock_common(struct mutex *lock, long state, unsigned int subclass,
69425 done:
69426 lock_acquired(&lock->dep_map, ip);
69427 /* got the lock - rejoice! */
69428- mutex_remove_waiter(lock, &waiter, current_thread_info());
69429+ mutex_remove_waiter(lock, &waiter, task);
69430 mutex_set_owner(lock);
69431
69432 /* set it to 0 if there are no waiters left: */
69433diff --git a/kernel/panic.c b/kernel/panic.c
69434index e1b2822..5edc1d9 100644
69435--- a/kernel/panic.c
69436+++ b/kernel/panic.c
69437@@ -410,7 +410,7 @@ static void warn_slowpath_common(const char *file, int line, void *caller,
69438 const char *board;
69439
69440 printk(KERN_WARNING "------------[ cut here ]------------\n");
69441- printk(KERN_WARNING "WARNING: at %s:%d %pS()\n", file, line, caller);
69442+ printk(KERN_WARNING "WARNING: at %s:%d %pA()\n", file, line, caller);
69443 board = dmi_get_system_info(DMI_PRODUCT_NAME);
69444 if (board)
69445 printk(KERN_WARNING "Hardware name: %s\n", board);
69446@@ -465,7 +465,8 @@ EXPORT_SYMBOL(warn_slowpath_null);
69447 */
69448 void __stack_chk_fail(void)
69449 {
69450- panic("stack-protector: Kernel stack is corrupted in: %p\n",
69451+ dump_stack();
69452+ panic("stack-protector: Kernel stack is corrupted in: %pA\n",
69453 __builtin_return_address(0));
69454 }
69455 EXPORT_SYMBOL(__stack_chk_fail);
69456diff --git a/kernel/pid.c b/kernel/pid.c
69457index e86b291a..e8b0fb5 100644
69458--- a/kernel/pid.c
69459+++ b/kernel/pid.c
69460@@ -33,6 +33,7 @@
69461 #include <linux/rculist.h>
69462 #include <linux/bootmem.h>
69463 #include <linux/hash.h>
69464+#include <linux/security.h>
69465 #include <linux/pid_namespace.h>
69466 #include <linux/init_task.h>
69467 #include <linux/syscalls.h>
69468@@ -45,7 +46,7 @@ struct pid init_struct_pid = INIT_STRUCT_PID;
69469
69470 int pid_max = PID_MAX_DEFAULT;
69471
69472-#define RESERVED_PIDS 300
69473+#define RESERVED_PIDS 500
69474
69475 int pid_max_min = RESERVED_PIDS + 1;
69476 int pid_max_max = PID_MAX_LIMIT;
69477@@ -420,10 +421,18 @@ EXPORT_SYMBOL(pid_task);
69478 */
69479 struct task_struct *find_task_by_pid_ns(pid_t nr, struct pid_namespace *ns)
69480 {
69481+ struct task_struct *task;
69482+
69483 rcu_lockdep_assert(rcu_read_lock_held(),
69484 "find_task_by_pid_ns() needs rcu_read_lock()"
69485 " protection");
69486- return pid_task(find_pid_ns(nr, ns), PIDTYPE_PID);
69487+
69488+ task = pid_task(find_pid_ns(nr, ns), PIDTYPE_PID);
69489+
69490+ if (gr_pid_is_chrooted(task))
69491+ return NULL;
69492+
69493+ return task;
69494 }
69495
69496 struct task_struct *find_task_by_vpid(pid_t vnr)
69497@@ -431,6 +440,14 @@ struct task_struct *find_task_by_vpid(pid_t vnr)
69498 return find_task_by_pid_ns(vnr, current->nsproxy->pid_ns);
69499 }
69500
69501+struct task_struct *find_task_by_vpid_unrestricted(pid_t vnr)
69502+{
69503+ rcu_lockdep_assert(rcu_read_lock_held(),
69504+ "find_task_by_pid_ns() needs rcu_read_lock()"
69505+ " protection");
69506+ return pid_task(find_pid_ns(vnr, current->nsproxy->pid_ns), PIDTYPE_PID);
69507+}
69508+
69509 struct pid *get_task_pid(struct task_struct *task, enum pid_type type)
69510 {
69511 struct pid *pid;
69512diff --git a/kernel/posix-cpu-timers.c b/kernel/posix-cpu-timers.c
69513index 125cb67..a4d1c30 100644
69514--- a/kernel/posix-cpu-timers.c
69515+++ b/kernel/posix-cpu-timers.c
69516@@ -6,6 +6,7 @@
69517 #include <linux/posix-timers.h>
69518 #include <linux/errno.h>
69519 #include <linux/math64.h>
69520+#include <linux/security.h>
69521 #include <asm/uaccess.h>
69522 #include <linux/kernel_stat.h>
69523 #include <trace/events/timer.h>
69524@@ -1578,14 +1579,14 @@ struct k_clock clock_posix_cpu = {
69525
69526 static __init int init_posix_cpu_timers(void)
69527 {
69528- struct k_clock process = {
69529+ static struct k_clock process = {
69530 .clock_getres = process_cpu_clock_getres,
69531 .clock_get = process_cpu_clock_get,
69532 .timer_create = process_cpu_timer_create,
69533 .nsleep = process_cpu_nsleep,
69534 .nsleep_restart = process_cpu_nsleep_restart,
69535 };
69536- struct k_clock thread = {
69537+ static struct k_clock thread = {
69538 .clock_getres = thread_cpu_clock_getres,
69539 .clock_get = thread_cpu_clock_get,
69540 .timer_create = thread_cpu_timer_create,
69541diff --git a/kernel/posix-timers.c b/kernel/posix-timers.c
69542index 69185ae..cc2847a 100644
69543--- a/kernel/posix-timers.c
69544+++ b/kernel/posix-timers.c
69545@@ -43,6 +43,7 @@
69546 #include <linux/idr.h>
69547 #include <linux/posix-clock.h>
69548 #include <linux/posix-timers.h>
69549+#include <linux/grsecurity.h>
69550 #include <linux/syscalls.h>
69551 #include <linux/wait.h>
69552 #include <linux/workqueue.h>
69553@@ -129,7 +130,7 @@ static DEFINE_SPINLOCK(idr_lock);
69554 * which we beg off on and pass to do_sys_settimeofday().
69555 */
69556
69557-static struct k_clock posix_clocks[MAX_CLOCKS];
69558+static struct k_clock *posix_clocks[MAX_CLOCKS];
69559
69560 /*
69561 * These ones are defined below.
69562@@ -227,7 +228,7 @@ static int posix_get_boottime(const clockid_t which_clock, struct timespec *tp)
69563 */
69564 static __init int init_posix_timers(void)
69565 {
69566- struct k_clock clock_realtime = {
69567+ static struct k_clock clock_realtime = {
69568 .clock_getres = hrtimer_get_res,
69569 .clock_get = posix_clock_realtime_get,
69570 .clock_set = posix_clock_realtime_set,
69571@@ -239,7 +240,7 @@ static __init int init_posix_timers(void)
69572 .timer_get = common_timer_get,
69573 .timer_del = common_timer_del,
69574 };
69575- struct k_clock clock_monotonic = {
69576+ static struct k_clock clock_monotonic = {
69577 .clock_getres = hrtimer_get_res,
69578 .clock_get = posix_ktime_get_ts,
69579 .nsleep = common_nsleep,
69580@@ -249,19 +250,19 @@ static __init int init_posix_timers(void)
69581 .timer_get = common_timer_get,
69582 .timer_del = common_timer_del,
69583 };
69584- struct k_clock clock_monotonic_raw = {
69585+ static struct k_clock clock_monotonic_raw = {
69586 .clock_getres = hrtimer_get_res,
69587 .clock_get = posix_get_monotonic_raw,
69588 };
69589- struct k_clock clock_realtime_coarse = {
69590+ static struct k_clock clock_realtime_coarse = {
69591 .clock_getres = posix_get_coarse_res,
69592 .clock_get = posix_get_realtime_coarse,
69593 };
69594- struct k_clock clock_monotonic_coarse = {
69595+ static struct k_clock clock_monotonic_coarse = {
69596 .clock_getres = posix_get_coarse_res,
69597 .clock_get = posix_get_monotonic_coarse,
69598 };
69599- struct k_clock clock_boottime = {
69600+ static struct k_clock clock_boottime = {
69601 .clock_getres = hrtimer_get_res,
69602 .clock_get = posix_get_boottime,
69603 .nsleep = common_nsleep,
69604@@ -473,7 +474,7 @@ void posix_timers_register_clock(const clockid_t clock_id,
69605 return;
69606 }
69607
69608- posix_clocks[clock_id] = *new_clock;
69609+ posix_clocks[clock_id] = new_clock;
69610 }
69611 EXPORT_SYMBOL_GPL(posix_timers_register_clock);
69612
69613@@ -519,9 +520,9 @@ static struct k_clock *clockid_to_kclock(const clockid_t id)
69614 return (id & CLOCKFD_MASK) == CLOCKFD ?
69615 &clock_posix_dynamic : &clock_posix_cpu;
69616
69617- if (id >= MAX_CLOCKS || !posix_clocks[id].clock_getres)
69618+ if (id >= MAX_CLOCKS || !posix_clocks[id] || !posix_clocks[id]->clock_getres)
69619 return NULL;
69620- return &posix_clocks[id];
69621+ return posix_clocks[id];
69622 }
69623
69624 static int common_timer_create(struct k_itimer *new_timer)
69625@@ -959,6 +960,13 @@ SYSCALL_DEFINE2(clock_settime, const clockid_t, which_clock,
69626 if (copy_from_user(&new_tp, tp, sizeof (*tp)))
69627 return -EFAULT;
69628
69629+ /* only the CLOCK_REALTIME clock can be set, all other clocks
69630+ have their clock_set fptr set to a nosettime dummy function
69631+ CLOCK_REALTIME has a NULL clock_set fptr which causes it to
69632+ call common_clock_set, which calls do_sys_settimeofday, which
69633+ we hook
69634+ */
69635+
69636 return kc->clock_set(which_clock, &new_tp);
69637 }
69638
69639diff --git a/kernel/power/poweroff.c b/kernel/power/poweroff.c
69640index d523593..68197a4 100644
69641--- a/kernel/power/poweroff.c
69642+++ b/kernel/power/poweroff.c
69643@@ -37,7 +37,7 @@ static struct sysrq_key_op sysrq_poweroff_op = {
69644 .enable_mask = SYSRQ_ENABLE_BOOT,
69645 };
69646
69647-static int pm_sysrq_init(void)
69648+static int __init pm_sysrq_init(void)
69649 {
69650 register_sysrq_key('o', &sysrq_poweroff_op);
69651 return 0;
69652diff --git a/kernel/power/process.c b/kernel/power/process.c
69653index 19db29f..33b52b6 100644
69654--- a/kernel/power/process.c
69655+++ b/kernel/power/process.c
69656@@ -33,6 +33,7 @@ static int try_to_freeze_tasks(bool user_only)
69657 u64 elapsed_csecs64;
69658 unsigned int elapsed_csecs;
69659 bool wakeup = false;
69660+ bool timedout = false;
69661
69662 do_gettimeofday(&start);
69663
69664@@ -43,6 +44,8 @@ static int try_to_freeze_tasks(bool user_only)
69665
69666 while (true) {
69667 todo = 0;
69668+ if (time_after(jiffies, end_time))
69669+ timedout = true;
69670 read_lock(&tasklist_lock);
69671 do_each_thread(g, p) {
69672 if (p == current || !freeze_task(p))
69673@@ -58,9 +61,13 @@ static int try_to_freeze_tasks(bool user_only)
69674 * guaranteed that TASK_STOPPED/TRACED -> TASK_RUNNING
69675 * transition can't race with task state testing here.
69676 */
69677- if (!task_is_stopped_or_traced(p) &&
69678- !freezer_should_skip(p))
69679+ if (!task_is_stopped_or_traced(p) && !freezer_should_skip(p)) {
69680 todo++;
69681+ if (timedout) {
69682+ printk(KERN_ERR "Task refusing to freeze:\n");
69683+ sched_show_task(p);
69684+ }
69685+ }
69686 } while_each_thread(g, p);
69687 read_unlock(&tasklist_lock);
69688
69689@@ -69,7 +76,7 @@ static int try_to_freeze_tasks(bool user_only)
69690 todo += wq_busy;
69691 }
69692
69693- if (!todo || time_after(jiffies, end_time))
69694+ if (!todo || timedout)
69695 break;
69696
69697 if (pm_wakeup_pending()) {
69698diff --git a/kernel/printk.c b/kernel/printk.c
69699index 66a2ea3..10f3a01 100644
69700--- a/kernel/printk.c
69701+++ b/kernel/printk.c
69702@@ -817,6 +817,11 @@ static int check_syslog_permissions(int type, bool from_file)
69703 if (from_file && type != SYSLOG_ACTION_OPEN)
69704 return 0;
69705
69706+#ifdef CONFIG_GRKERNSEC_DMESG
69707+ if (grsec_enable_dmesg && !capable(CAP_SYSLOG) && !capable_nolog(CAP_SYS_ADMIN))
69708+ return -EPERM;
69709+#endif
69710+
69711 if (syslog_action_restricted(type)) {
69712 if (capable(CAP_SYSLOG))
69713 return 0;
69714diff --git a/kernel/profile.c b/kernel/profile.c
69715index 76b8e77..a2930e8 100644
69716--- a/kernel/profile.c
69717+++ b/kernel/profile.c
69718@@ -39,7 +39,7 @@ struct profile_hit {
69719 /* Oprofile timer tick hook */
69720 static int (*timer_hook)(struct pt_regs *) __read_mostly;
69721
69722-static atomic_t *prof_buffer;
69723+static atomic_unchecked_t *prof_buffer;
69724 static unsigned long prof_len, prof_shift;
69725
69726 int prof_on __read_mostly;
69727@@ -281,7 +281,7 @@ static void profile_flip_buffers(void)
69728 hits[i].pc = 0;
69729 continue;
69730 }
69731- atomic_add(hits[i].hits, &prof_buffer[hits[i].pc]);
69732+ atomic_add_unchecked(hits[i].hits, &prof_buffer[hits[i].pc]);
69733 hits[i].hits = hits[i].pc = 0;
69734 }
69735 }
69736@@ -342,9 +342,9 @@ static void do_profile_hits(int type, void *__pc, unsigned int nr_hits)
69737 * Add the current hit(s) and flush the write-queue out
69738 * to the global buffer:
69739 */
69740- atomic_add(nr_hits, &prof_buffer[pc]);
69741+ atomic_add_unchecked(nr_hits, &prof_buffer[pc]);
69742 for (i = 0; i < NR_PROFILE_HIT; ++i) {
69743- atomic_add(hits[i].hits, &prof_buffer[hits[i].pc]);
69744+ atomic_add_unchecked(hits[i].hits, &prof_buffer[hits[i].pc]);
69745 hits[i].pc = hits[i].hits = 0;
69746 }
69747 out:
69748@@ -419,7 +419,7 @@ static void do_profile_hits(int type, void *__pc, unsigned int nr_hits)
69749 {
69750 unsigned long pc;
69751 pc = ((unsigned long)__pc - (unsigned long)_stext) >> prof_shift;
69752- atomic_add(nr_hits, &prof_buffer[min(pc, prof_len - 1)]);
69753+ atomic_add_unchecked(nr_hits, &prof_buffer[min(pc, prof_len - 1)]);
69754 }
69755 #endif /* !CONFIG_SMP */
69756
69757@@ -517,7 +517,7 @@ read_profile(struct file *file, char __user *buf, size_t count, loff_t *ppos)
69758 return -EFAULT;
69759 buf++; p++; count--; read++;
69760 }
69761- pnt = (char *)prof_buffer + p - sizeof(atomic_t);
69762+ pnt = (char *)prof_buffer + p - sizeof(atomic_unchecked_t);
69763 if (copy_to_user(buf, (void *)pnt, count))
69764 return -EFAULT;
69765 read += count;
69766@@ -548,7 +548,7 @@ static ssize_t write_profile(struct file *file, const char __user *buf,
69767 }
69768 #endif
69769 profile_discard_flip_buffers();
69770- memset(prof_buffer, 0, prof_len * sizeof(atomic_t));
69771+ memset(prof_buffer, 0, prof_len * sizeof(atomic_unchecked_t));
69772 return count;
69773 }
69774
69775diff --git a/kernel/ptrace.c b/kernel/ptrace.c
69776index a232bb5..2a65ef9 100644
69777--- a/kernel/ptrace.c
69778+++ b/kernel/ptrace.c
69779@@ -279,7 +279,7 @@ static int ptrace_attach(struct task_struct *task, long request,
69780
69781 if (seize)
69782 flags |= PT_SEIZED;
69783- if (ns_capable(task_user_ns(task), CAP_SYS_PTRACE))
69784+ if (ns_capable_nolog(task_user_ns(task), CAP_SYS_PTRACE))
69785 flags |= PT_PTRACE_CAP;
69786 task->ptrace = flags;
69787
69788@@ -486,7 +486,7 @@ int ptrace_readdata(struct task_struct *tsk, unsigned long src, char __user *dst
69789 break;
69790 return -EIO;
69791 }
69792- if (copy_to_user(dst, buf, retval))
69793+ if (retval > sizeof(buf) || copy_to_user(dst, buf, retval))
69794 return -EFAULT;
69795 copied += retval;
69796 src += retval;
69797@@ -671,7 +671,7 @@ int ptrace_request(struct task_struct *child, long request,
69798 bool seized = child->ptrace & PT_SEIZED;
69799 int ret = -EIO;
69800 siginfo_t siginfo, *si;
69801- void __user *datavp = (void __user *) data;
69802+ void __user *datavp = (__force void __user *) data;
69803 unsigned long __user *datalp = datavp;
69804 unsigned long flags;
69805
69806@@ -873,14 +873,21 @@ SYSCALL_DEFINE4(ptrace, long, request, long, pid, unsigned long, addr,
69807 goto out;
69808 }
69809
69810+ if (gr_handle_ptrace(child, request)) {
69811+ ret = -EPERM;
69812+ goto out_put_task_struct;
69813+ }
69814+
69815 if (request == PTRACE_ATTACH || request == PTRACE_SEIZE) {
69816 ret = ptrace_attach(child, request, addr, data);
69817 /*
69818 * Some architectures need to do book-keeping after
69819 * a ptrace attach.
69820 */
69821- if (!ret)
69822+ if (!ret) {
69823 arch_ptrace_attach(child);
69824+ gr_audit_ptrace(child);
69825+ }
69826 goto out_put_task_struct;
69827 }
69828
69829@@ -906,7 +913,7 @@ int generic_ptrace_peekdata(struct task_struct *tsk, unsigned long addr,
69830 copied = access_process_vm(tsk, addr, &tmp, sizeof(tmp), 0);
69831 if (copied != sizeof(tmp))
69832 return -EIO;
69833- return put_user(tmp, (unsigned long __user *)data);
69834+ return put_user(tmp, (__force unsigned long __user *)data);
69835 }
69836
69837 int generic_ptrace_pokedata(struct task_struct *tsk, unsigned long addr,
69838@@ -1016,14 +1023,21 @@ asmlinkage long compat_sys_ptrace(compat_long_t request, compat_long_t pid,
69839 goto out;
69840 }
69841
69842+ if (gr_handle_ptrace(child, request)) {
69843+ ret = -EPERM;
69844+ goto out_put_task_struct;
69845+ }
69846+
69847 if (request == PTRACE_ATTACH || request == PTRACE_SEIZE) {
69848 ret = ptrace_attach(child, request, addr, data);
69849 /*
69850 * Some architectures need to do book-keeping after
69851 * a ptrace attach.
69852 */
69853- if (!ret)
69854+ if (!ret) {
69855 arch_ptrace_attach(child);
69856+ gr_audit_ptrace(child);
69857+ }
69858 goto out_put_task_struct;
69859 }
69860
69861diff --git a/kernel/rcutiny.c b/kernel/rcutiny.c
69862index 547b1fe..65e874e 100644
69863--- a/kernel/rcutiny.c
69864+++ b/kernel/rcutiny.c
69865@@ -46,7 +46,7 @@
69866 struct rcu_ctrlblk;
69867 static void invoke_rcu_callbacks(void);
69868 static void __rcu_process_callbacks(struct rcu_ctrlblk *rcp);
69869-static void rcu_process_callbacks(struct softirq_action *unused);
69870+static void rcu_process_callbacks(void);
69871 static void __call_rcu(struct rcu_head *head,
69872 void (*func)(struct rcu_head *rcu),
69873 struct rcu_ctrlblk *rcp);
69874@@ -307,7 +307,7 @@ static void __rcu_process_callbacks(struct rcu_ctrlblk *rcp)
69875 rcu_is_callbacks_kthread()));
69876 }
69877
69878-static void rcu_process_callbacks(struct softirq_action *unused)
69879+static void rcu_process_callbacks(void)
69880 {
69881 __rcu_process_callbacks(&rcu_sched_ctrlblk);
69882 __rcu_process_callbacks(&rcu_bh_ctrlblk);
69883diff --git a/kernel/rcutiny_plugin.h b/kernel/rcutiny_plugin.h
69884index 918fd1e..85089bb 100644
69885--- a/kernel/rcutiny_plugin.h
69886+++ b/kernel/rcutiny_plugin.h
69887@@ -893,7 +893,7 @@ static int rcu_kthread(void *arg)
69888 have_rcu_kthread_work = morework;
69889 local_irq_restore(flags);
69890 if (work)
69891- rcu_process_callbacks(NULL);
69892+ rcu_process_callbacks();
69893 schedule_timeout_interruptible(1); /* Leave CPU for others. */
69894 }
69895
69896diff --git a/kernel/rcutorture.c b/kernel/rcutorture.c
69897index 25b1503..1988a74 100644
69898--- a/kernel/rcutorture.c
69899+++ b/kernel/rcutorture.c
69900@@ -162,12 +162,12 @@ static DEFINE_PER_CPU(long [RCU_TORTURE_PIPE_LEN + 1], rcu_torture_count) =
69901 { 0 };
69902 static DEFINE_PER_CPU(long [RCU_TORTURE_PIPE_LEN + 1], rcu_torture_batch) =
69903 { 0 };
69904-static atomic_t rcu_torture_wcount[RCU_TORTURE_PIPE_LEN + 1];
69905-static atomic_t n_rcu_torture_alloc;
69906-static atomic_t n_rcu_torture_alloc_fail;
69907-static atomic_t n_rcu_torture_free;
69908-static atomic_t n_rcu_torture_mberror;
69909-static atomic_t n_rcu_torture_error;
69910+static atomic_unchecked_t rcu_torture_wcount[RCU_TORTURE_PIPE_LEN + 1];
69911+static atomic_unchecked_t n_rcu_torture_alloc;
69912+static atomic_unchecked_t n_rcu_torture_alloc_fail;
69913+static atomic_unchecked_t n_rcu_torture_free;
69914+static atomic_unchecked_t n_rcu_torture_mberror;
69915+static atomic_unchecked_t n_rcu_torture_error;
69916 static long n_rcu_torture_barrier_error;
69917 static long n_rcu_torture_boost_ktrerror;
69918 static long n_rcu_torture_boost_rterror;
69919@@ -265,11 +265,11 @@ rcu_torture_alloc(void)
69920
69921 spin_lock_bh(&rcu_torture_lock);
69922 if (list_empty(&rcu_torture_freelist)) {
69923- atomic_inc(&n_rcu_torture_alloc_fail);
69924+ atomic_inc_unchecked(&n_rcu_torture_alloc_fail);
69925 spin_unlock_bh(&rcu_torture_lock);
69926 return NULL;
69927 }
69928- atomic_inc(&n_rcu_torture_alloc);
69929+ atomic_inc_unchecked(&n_rcu_torture_alloc);
69930 p = rcu_torture_freelist.next;
69931 list_del_init(p);
69932 spin_unlock_bh(&rcu_torture_lock);
69933@@ -282,7 +282,7 @@ rcu_torture_alloc(void)
69934 static void
69935 rcu_torture_free(struct rcu_torture *p)
69936 {
69937- atomic_inc(&n_rcu_torture_free);
69938+ atomic_inc_unchecked(&n_rcu_torture_free);
69939 spin_lock_bh(&rcu_torture_lock);
69940 list_add_tail(&p->rtort_free, &rcu_torture_freelist);
69941 spin_unlock_bh(&rcu_torture_lock);
69942@@ -403,7 +403,7 @@ rcu_torture_cb(struct rcu_head *p)
69943 i = rp->rtort_pipe_count;
69944 if (i > RCU_TORTURE_PIPE_LEN)
69945 i = RCU_TORTURE_PIPE_LEN;
69946- atomic_inc(&rcu_torture_wcount[i]);
69947+ atomic_inc_unchecked(&rcu_torture_wcount[i]);
69948 if (++rp->rtort_pipe_count >= RCU_TORTURE_PIPE_LEN) {
69949 rp->rtort_mbtest = 0;
69950 rcu_torture_free(rp);
69951@@ -452,7 +452,7 @@ static void rcu_sync_torture_deferred_free(struct rcu_torture *p)
69952 i = rp->rtort_pipe_count;
69953 if (i > RCU_TORTURE_PIPE_LEN)
69954 i = RCU_TORTURE_PIPE_LEN;
69955- atomic_inc(&rcu_torture_wcount[i]);
69956+ atomic_inc_unchecked(&rcu_torture_wcount[i]);
69957 if (++rp->rtort_pipe_count >= RCU_TORTURE_PIPE_LEN) {
69958 rp->rtort_mbtest = 0;
69959 list_del(&rp->rtort_free);
69960@@ -995,7 +995,7 @@ rcu_torture_writer(void *arg)
69961 i = old_rp->rtort_pipe_count;
69962 if (i > RCU_TORTURE_PIPE_LEN)
69963 i = RCU_TORTURE_PIPE_LEN;
69964- atomic_inc(&rcu_torture_wcount[i]);
69965+ atomic_inc_unchecked(&rcu_torture_wcount[i]);
69966 old_rp->rtort_pipe_count++;
69967 cur_ops->deferred_free(old_rp);
69968 }
69969@@ -1080,7 +1080,7 @@ static void rcu_torture_timer(unsigned long unused)
69970 }
69971 do_trace_rcu_torture_read(cur_ops->name, &p->rtort_rcu);
69972 if (p->rtort_mbtest == 0)
69973- atomic_inc(&n_rcu_torture_mberror);
69974+ atomic_inc_unchecked(&n_rcu_torture_mberror);
69975 spin_lock(&rand_lock);
69976 cur_ops->read_delay(&rand);
69977 n_rcu_torture_timers++;
69978@@ -1144,7 +1144,7 @@ rcu_torture_reader(void *arg)
69979 }
69980 do_trace_rcu_torture_read(cur_ops->name, &p->rtort_rcu);
69981 if (p->rtort_mbtest == 0)
69982- atomic_inc(&n_rcu_torture_mberror);
69983+ atomic_inc_unchecked(&n_rcu_torture_mberror);
69984 cur_ops->read_delay(&rand);
69985 preempt_disable();
69986 pipe_count = p->rtort_pipe_count;
69987@@ -1203,11 +1203,11 @@ rcu_torture_printk(char *page)
69988 rcu_torture_current,
69989 rcu_torture_current_version,
69990 list_empty(&rcu_torture_freelist),
69991- atomic_read(&n_rcu_torture_alloc),
69992- atomic_read(&n_rcu_torture_alloc_fail),
69993- atomic_read(&n_rcu_torture_free));
69994+ atomic_read_unchecked(&n_rcu_torture_alloc),
69995+ atomic_read_unchecked(&n_rcu_torture_alloc_fail),
69996+ atomic_read_unchecked(&n_rcu_torture_free));
69997 cnt += sprintf(&page[cnt], "rtmbe: %d rtbke: %ld rtbre: %ld ",
69998- atomic_read(&n_rcu_torture_mberror),
69999+ atomic_read_unchecked(&n_rcu_torture_mberror),
70000 n_rcu_torture_boost_ktrerror,
70001 n_rcu_torture_boost_rterror);
70002 cnt += sprintf(&page[cnt], "rtbf: %ld rtb: %ld nt: %ld ",
70003@@ -1224,14 +1224,14 @@ rcu_torture_printk(char *page)
70004 n_barrier_attempts,
70005 n_rcu_torture_barrier_error);
70006 cnt += sprintf(&page[cnt], "\n%s%s ", torture_type, TORTURE_FLAG);
70007- if (atomic_read(&n_rcu_torture_mberror) != 0 ||
70008+ if (atomic_read_unchecked(&n_rcu_torture_mberror) != 0 ||
70009 n_rcu_torture_barrier_error != 0 ||
70010 n_rcu_torture_boost_ktrerror != 0 ||
70011 n_rcu_torture_boost_rterror != 0 ||
70012 n_rcu_torture_boost_failure != 0 ||
70013 i > 1) {
70014 cnt += sprintf(&page[cnt], "!!! ");
70015- atomic_inc(&n_rcu_torture_error);
70016+ atomic_inc_unchecked(&n_rcu_torture_error);
70017 WARN_ON_ONCE(1);
70018 }
70019 cnt += sprintf(&page[cnt], "Reader Pipe: ");
70020@@ -1245,7 +1245,7 @@ rcu_torture_printk(char *page)
70021 cnt += sprintf(&page[cnt], "Free-Block Circulation: ");
70022 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++) {
70023 cnt += sprintf(&page[cnt], " %d",
70024- atomic_read(&rcu_torture_wcount[i]));
70025+ atomic_read_unchecked(&rcu_torture_wcount[i]));
70026 }
70027 cnt += sprintf(&page[cnt], "\n");
70028 if (cur_ops->stats)
70029@@ -1905,7 +1905,7 @@ rcu_torture_cleanup(void)
70030
70031 if (cur_ops->cleanup)
70032 cur_ops->cleanup();
70033- if (atomic_read(&n_rcu_torture_error) || n_rcu_torture_barrier_error)
70034+ if (atomic_read_unchecked(&n_rcu_torture_error) || n_rcu_torture_barrier_error)
70035 rcu_torture_print_module_parms(cur_ops, "End of test: FAILURE");
70036 else if (n_online_successes != n_online_attempts ||
70037 n_offline_successes != n_offline_attempts)
70038@@ -1974,18 +1974,18 @@ rcu_torture_init(void)
70039
70040 rcu_torture_current = NULL;
70041 rcu_torture_current_version = 0;
70042- atomic_set(&n_rcu_torture_alloc, 0);
70043- atomic_set(&n_rcu_torture_alloc_fail, 0);
70044- atomic_set(&n_rcu_torture_free, 0);
70045- atomic_set(&n_rcu_torture_mberror, 0);
70046- atomic_set(&n_rcu_torture_error, 0);
70047+ atomic_set_unchecked(&n_rcu_torture_alloc, 0);
70048+ atomic_set_unchecked(&n_rcu_torture_alloc_fail, 0);
70049+ atomic_set_unchecked(&n_rcu_torture_free, 0);
70050+ atomic_set_unchecked(&n_rcu_torture_mberror, 0);
70051+ atomic_set_unchecked(&n_rcu_torture_error, 0);
70052 n_rcu_torture_barrier_error = 0;
70053 n_rcu_torture_boost_ktrerror = 0;
70054 n_rcu_torture_boost_rterror = 0;
70055 n_rcu_torture_boost_failure = 0;
70056 n_rcu_torture_boosts = 0;
70057 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++)
70058- atomic_set(&rcu_torture_wcount[i], 0);
70059+ atomic_set_unchecked(&rcu_torture_wcount[i], 0);
70060 for_each_possible_cpu(cpu) {
70061 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++) {
70062 per_cpu(rcu_torture_count, cpu)[i] = 0;
70063diff --git a/kernel/rcutree.c b/kernel/rcutree.c
70064index f7bcd9e..8973e14 100644
70065--- a/kernel/rcutree.c
70066+++ b/kernel/rcutree.c
70067@@ -369,9 +369,9 @@ static void rcu_idle_enter_common(struct rcu_dynticks *rdtp, long long oldval)
70068 rcu_prepare_for_idle(smp_processor_id());
70069 /* CPUs seeing atomic_inc() must see prior RCU read-side crit sects */
70070 smp_mb__before_atomic_inc(); /* See above. */
70071- atomic_inc(&rdtp->dynticks);
70072+ atomic_inc_unchecked(&rdtp->dynticks);
70073 smp_mb__after_atomic_inc(); /* Force ordering with next sojourn. */
70074- WARN_ON_ONCE(atomic_read(&rdtp->dynticks) & 0x1);
70075+ WARN_ON_ONCE(atomic_read_unchecked(&rdtp->dynticks) & 0x1);
70076
70077 /*
70078 * The idle task is not permitted to enter the idle loop while
70079@@ -460,10 +460,10 @@ void rcu_irq_exit(void)
70080 static void rcu_idle_exit_common(struct rcu_dynticks *rdtp, long long oldval)
70081 {
70082 smp_mb__before_atomic_inc(); /* Force ordering w/previous sojourn. */
70083- atomic_inc(&rdtp->dynticks);
70084+ atomic_inc_unchecked(&rdtp->dynticks);
70085 /* CPUs seeing atomic_inc() must see later RCU read-side crit sects */
70086 smp_mb__after_atomic_inc(); /* See above. */
70087- WARN_ON_ONCE(!(atomic_read(&rdtp->dynticks) & 0x1));
70088+ WARN_ON_ONCE(!(atomic_read_unchecked(&rdtp->dynticks) & 0x1));
70089 rcu_cleanup_after_idle(smp_processor_id());
70090 trace_rcu_dyntick("End", oldval, rdtp->dynticks_nesting);
70091 if (!is_idle_task(current)) {
70092@@ -557,14 +557,14 @@ void rcu_nmi_enter(void)
70093 struct rcu_dynticks *rdtp = &__get_cpu_var(rcu_dynticks);
70094
70095 if (rdtp->dynticks_nmi_nesting == 0 &&
70096- (atomic_read(&rdtp->dynticks) & 0x1))
70097+ (atomic_read_unchecked(&rdtp->dynticks) & 0x1))
70098 return;
70099 rdtp->dynticks_nmi_nesting++;
70100 smp_mb__before_atomic_inc(); /* Force delay from prior write. */
70101- atomic_inc(&rdtp->dynticks);
70102+ atomic_inc_unchecked(&rdtp->dynticks);
70103 /* CPUs seeing atomic_inc() must see later RCU read-side crit sects */
70104 smp_mb__after_atomic_inc(); /* See above. */
70105- WARN_ON_ONCE(!(atomic_read(&rdtp->dynticks) & 0x1));
70106+ WARN_ON_ONCE(!(atomic_read_unchecked(&rdtp->dynticks) & 0x1));
70107 }
70108
70109 /**
70110@@ -583,9 +583,9 @@ void rcu_nmi_exit(void)
70111 return;
70112 /* CPUs seeing atomic_inc() must see prior RCU read-side crit sects */
70113 smp_mb__before_atomic_inc(); /* See above. */
70114- atomic_inc(&rdtp->dynticks);
70115+ atomic_inc_unchecked(&rdtp->dynticks);
70116 smp_mb__after_atomic_inc(); /* Force delay to next write. */
70117- WARN_ON_ONCE(atomic_read(&rdtp->dynticks) & 0x1);
70118+ WARN_ON_ONCE(atomic_read_unchecked(&rdtp->dynticks) & 0x1);
70119 }
70120
70121 /**
70122@@ -599,7 +599,7 @@ int rcu_is_cpu_idle(void)
70123 int ret;
70124
70125 preempt_disable();
70126- ret = (atomic_read(&__get_cpu_var(rcu_dynticks).dynticks) & 0x1) == 0;
70127+ ret = (atomic_read_unchecked(&__get_cpu_var(rcu_dynticks).dynticks) & 0x1) == 0;
70128 preempt_enable();
70129 return ret;
70130 }
70131@@ -667,7 +667,7 @@ int rcu_is_cpu_rrupt_from_idle(void)
70132 */
70133 static int dyntick_save_progress_counter(struct rcu_data *rdp)
70134 {
70135- rdp->dynticks_snap = atomic_add_return(0, &rdp->dynticks->dynticks);
70136+ rdp->dynticks_snap = atomic_add_return_unchecked(0, &rdp->dynticks->dynticks);
70137 return (rdp->dynticks_snap & 0x1) == 0;
70138 }
70139
70140@@ -682,7 +682,7 @@ static int rcu_implicit_dynticks_qs(struct rcu_data *rdp)
70141 unsigned int curr;
70142 unsigned int snap;
70143
70144- curr = (unsigned int)atomic_add_return(0, &rdp->dynticks->dynticks);
70145+ curr = (unsigned int)atomic_add_return_unchecked(0, &rdp->dynticks->dynticks);
70146 snap = (unsigned int)rdp->dynticks_snap;
70147
70148 /*
70149@@ -712,10 +712,10 @@ static int jiffies_till_stall_check(void)
70150 * for CONFIG_RCU_CPU_STALL_TIMEOUT.
70151 */
70152 if (till_stall_check < 3) {
70153- ACCESS_ONCE(rcu_cpu_stall_timeout) = 3;
70154+ ACCESS_ONCE_RW(rcu_cpu_stall_timeout) = 3;
70155 till_stall_check = 3;
70156 } else if (till_stall_check > 300) {
70157- ACCESS_ONCE(rcu_cpu_stall_timeout) = 300;
70158+ ACCESS_ONCE_RW(rcu_cpu_stall_timeout) = 300;
70159 till_stall_check = 300;
70160 }
70161 return till_stall_check * HZ + RCU_STALL_DELAY_DELTA;
70162@@ -1351,7 +1351,7 @@ rcu_send_cbs_to_orphanage(int cpu, struct rcu_state *rsp,
70163 rsp->qlen += rdp->qlen;
70164 rdp->n_cbs_orphaned += rdp->qlen;
70165 rdp->qlen_lazy = 0;
70166- ACCESS_ONCE(rdp->qlen) = 0;
70167+ ACCESS_ONCE_RW(rdp->qlen) = 0;
70168 }
70169
70170 /*
70171@@ -1604,7 +1604,7 @@ static void rcu_do_batch(struct rcu_state *rsp, struct rcu_data *rdp)
70172 }
70173 smp_mb(); /* List handling before counting for rcu_barrier(). */
70174 rdp->qlen_lazy -= count_lazy;
70175- ACCESS_ONCE(rdp->qlen) -= count;
70176+ ACCESS_ONCE_RW(rdp->qlen) -= count;
70177 rdp->n_cbs_invoked += count;
70178
70179 /* Reinstate batch limit if we have worked down the excess. */
70180@@ -1836,7 +1836,7 @@ __rcu_process_callbacks(struct rcu_state *rsp)
70181 /*
70182 * Do RCU core processing for the current CPU.
70183 */
70184-static void rcu_process_callbacks(struct softirq_action *unused)
70185+static void rcu_process_callbacks(void)
70186 {
70187 struct rcu_state *rsp;
70188
70189@@ -1943,7 +1943,7 @@ __call_rcu(struct rcu_head *head, void (*func)(struct rcu_head *rcu),
70190 rdp = this_cpu_ptr(rsp->rda);
70191
70192 /* Add the callback to our list. */
70193- ACCESS_ONCE(rdp->qlen)++;
70194+ ACCESS_ONCE_RW(rdp->qlen)++;
70195 if (lazy)
70196 rdp->qlen_lazy++;
70197 else
70198@@ -2057,8 +2057,8 @@ void synchronize_rcu_bh(void)
70199 }
70200 EXPORT_SYMBOL_GPL(synchronize_rcu_bh);
70201
70202-static atomic_t sync_sched_expedited_started = ATOMIC_INIT(0);
70203-static atomic_t sync_sched_expedited_done = ATOMIC_INIT(0);
70204+static atomic_unchecked_t sync_sched_expedited_started = ATOMIC_INIT(0);
70205+static atomic_unchecked_t sync_sched_expedited_done = ATOMIC_INIT(0);
70206
70207 static int synchronize_sched_expedited_cpu_stop(void *data)
70208 {
70209@@ -2119,7 +2119,7 @@ void synchronize_sched_expedited(void)
70210 int firstsnap, s, snap, trycount = 0;
70211
70212 /* Note that atomic_inc_return() implies full memory barrier. */
70213- firstsnap = snap = atomic_inc_return(&sync_sched_expedited_started);
70214+ firstsnap = snap = atomic_inc_return_unchecked(&sync_sched_expedited_started);
70215 get_online_cpus();
70216 WARN_ON_ONCE(cpu_is_offline(raw_smp_processor_id()));
70217
70218@@ -2141,7 +2141,7 @@ void synchronize_sched_expedited(void)
70219 }
70220
70221 /* Check to see if someone else did our work for us. */
70222- s = atomic_read(&sync_sched_expedited_done);
70223+ s = atomic_read_unchecked(&sync_sched_expedited_done);
70224 if (UINT_CMP_GE((unsigned)s, (unsigned)firstsnap)) {
70225 smp_mb(); /* ensure test happens before caller kfree */
70226 return;
70227@@ -2156,7 +2156,7 @@ void synchronize_sched_expedited(void)
70228 * grace period works for us.
70229 */
70230 get_online_cpus();
70231- snap = atomic_read(&sync_sched_expedited_started);
70232+ snap = atomic_read_unchecked(&sync_sched_expedited_started);
70233 smp_mb(); /* ensure read is before try_stop_cpus(). */
70234 }
70235
70236@@ -2167,12 +2167,12 @@ void synchronize_sched_expedited(void)
70237 * than we did beat us to the punch.
70238 */
70239 do {
70240- s = atomic_read(&sync_sched_expedited_done);
70241+ s = atomic_read_unchecked(&sync_sched_expedited_done);
70242 if (UINT_CMP_GE((unsigned)s, (unsigned)snap)) {
70243 smp_mb(); /* ensure test happens before caller kfree */
70244 break;
70245 }
70246- } while (atomic_cmpxchg(&sync_sched_expedited_done, s, snap) != s);
70247+ } while (atomic_cmpxchg_unchecked(&sync_sched_expedited_done, s, snap) != s);
70248
70249 put_online_cpus();
70250 }
70251@@ -2366,7 +2366,7 @@ static void _rcu_barrier(struct rcu_state *rsp)
70252 * ACCESS_ONCE() to prevent the compiler from speculating
70253 * the increment to precede the early-exit check.
70254 */
70255- ACCESS_ONCE(rsp->n_barrier_done)++;
70256+ ACCESS_ONCE_RW(rsp->n_barrier_done)++;
70257 WARN_ON_ONCE((rsp->n_barrier_done & 0x1) != 1);
70258 _rcu_barrier_trace(rsp, "Inc1", -1, rsp->n_barrier_done);
70259 smp_mb(); /* Order ->n_barrier_done increment with below mechanism. */
70260@@ -2448,7 +2448,7 @@ static void _rcu_barrier(struct rcu_state *rsp)
70261
70262 /* Increment ->n_barrier_done to prevent duplicate work. */
70263 smp_mb(); /* Keep increment after above mechanism. */
70264- ACCESS_ONCE(rsp->n_barrier_done)++;
70265+ ACCESS_ONCE_RW(rsp->n_barrier_done)++;
70266 WARN_ON_ONCE((rsp->n_barrier_done & 0x1) != 0);
70267 _rcu_barrier_trace(rsp, "Inc2", -1, rsp->n_barrier_done);
70268 smp_mb(); /* Keep increment before caller's subsequent code. */
70269@@ -2495,10 +2495,10 @@ rcu_boot_init_percpu_data(int cpu, struct rcu_state *rsp)
70270 rdp->grpmask = 1UL << (cpu - rdp->mynode->grplo);
70271 init_callback_list(rdp);
70272 rdp->qlen_lazy = 0;
70273- ACCESS_ONCE(rdp->qlen) = 0;
70274+ ACCESS_ONCE_RW(rdp->qlen) = 0;
70275 rdp->dynticks = &per_cpu(rcu_dynticks, cpu);
70276 WARN_ON_ONCE(rdp->dynticks->dynticks_nesting != DYNTICK_TASK_EXIT_IDLE);
70277- WARN_ON_ONCE(atomic_read(&rdp->dynticks->dynticks) != 1);
70278+ WARN_ON_ONCE(atomic_read_unchecked(&rdp->dynticks->dynticks) != 1);
70279 rdp->cpu = cpu;
70280 rdp->rsp = rsp;
70281 raw_spin_unlock_irqrestore(&rnp->lock, flags);
70282@@ -2526,8 +2526,8 @@ rcu_init_percpu_data(int cpu, struct rcu_state *rsp, int preemptible)
70283 rdp->n_force_qs_snap = rsp->n_force_qs;
70284 rdp->blimit = blimit;
70285 rdp->dynticks->dynticks_nesting = DYNTICK_TASK_EXIT_IDLE;
70286- atomic_set(&rdp->dynticks->dynticks,
70287- (atomic_read(&rdp->dynticks->dynticks) & ~0x1) + 1);
70288+ atomic_set_unchecked(&rdp->dynticks->dynticks,
70289+ (atomic_read_unchecked(&rdp->dynticks->dynticks) & ~0x1) + 1);
70290 rcu_prepare_for_idle_init(cpu);
70291 raw_spin_unlock(&rnp->lock); /* irqs remain disabled. */
70292
70293diff --git a/kernel/rcutree.h b/kernel/rcutree.h
70294index 4d29169..d104a3c 100644
70295--- a/kernel/rcutree.h
70296+++ b/kernel/rcutree.h
70297@@ -86,7 +86,7 @@ struct rcu_dynticks {
70298 long long dynticks_nesting; /* Track irq/process nesting level. */
70299 /* Process level is worth LLONG_MAX/2. */
70300 int dynticks_nmi_nesting; /* Track NMI nesting level. */
70301- atomic_t dynticks; /* Even value for idle, else odd. */
70302+ atomic_unchecked_t dynticks;/* Even value for idle, else odd. */
70303 #ifdef CONFIG_RCU_FAST_NO_HZ
70304 int dyntick_drain; /* Prepare-for-idle state variable. */
70305 unsigned long dyntick_holdoff;
70306diff --git a/kernel/rcutree_plugin.h b/kernel/rcutree_plugin.h
70307index 7f3244c..417d606 100644
70308--- a/kernel/rcutree_plugin.h
70309+++ b/kernel/rcutree_plugin.h
70310@@ -843,7 +843,7 @@ void synchronize_rcu_expedited(void)
70311
70312 /* Clean up and exit. */
70313 smp_mb(); /* ensure expedited GP seen before counter increment. */
70314- ACCESS_ONCE(sync_rcu_preempt_exp_count)++;
70315+ ACCESS_ONCE_RW(sync_rcu_preempt_exp_count)++;
70316 unlock_mb_ret:
70317 mutex_unlock(&sync_rcu_preempt_exp_mutex);
70318 mb_ret:
70319diff --git a/kernel/rcutree_trace.c b/kernel/rcutree_trace.c
70320index abffb48..cbfa6d3 100644
70321--- a/kernel/rcutree_trace.c
70322+++ b/kernel/rcutree_trace.c
70323@@ -93,7 +93,7 @@ static void print_one_rcu_data(struct seq_file *m, struct rcu_data *rdp)
70324 rdp->passed_quiesce, rdp->passed_quiesce_gpnum,
70325 rdp->qs_pending);
70326 seq_printf(m, " dt=%d/%llx/%d df=%lu",
70327- atomic_read(&rdp->dynticks->dynticks),
70328+ atomic_read_unchecked(&rdp->dynticks->dynticks),
70329 rdp->dynticks->dynticks_nesting,
70330 rdp->dynticks->dynticks_nmi_nesting,
70331 rdp->dynticks_fqs);
70332@@ -157,7 +157,7 @@ static void print_one_rcu_data_csv(struct seq_file *m, struct rcu_data *rdp)
70333 rdp->passed_quiesce, rdp->passed_quiesce_gpnum,
70334 rdp->qs_pending);
70335 seq_printf(m, ",%d,%llx,%d,%lu",
70336- atomic_read(&rdp->dynticks->dynticks),
70337+ atomic_read_unchecked(&rdp->dynticks->dynticks),
70338 rdp->dynticks->dynticks_nesting,
70339 rdp->dynticks->dynticks_nmi_nesting,
70340 rdp->dynticks_fqs);
70341diff --git a/kernel/resource.c b/kernel/resource.c
70342index 34d4588..10baa6a 100644
70343--- a/kernel/resource.c
70344+++ b/kernel/resource.c
70345@@ -143,8 +143,18 @@ static const struct file_operations proc_iomem_operations = {
70346
70347 static int __init ioresources_init(void)
70348 {
70349+#ifdef CONFIG_GRKERNSEC_PROC_ADD
70350+#ifdef CONFIG_GRKERNSEC_PROC_USER
70351+ proc_create("ioports", S_IRUSR, NULL, &proc_ioports_operations);
70352+ proc_create("iomem", S_IRUSR, NULL, &proc_iomem_operations);
70353+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
70354+ proc_create("ioports", S_IRUSR | S_IRGRP, NULL, &proc_ioports_operations);
70355+ proc_create("iomem", S_IRUSR | S_IRGRP, NULL, &proc_iomem_operations);
70356+#endif
70357+#else
70358 proc_create("ioports", 0, NULL, &proc_ioports_operations);
70359 proc_create("iomem", 0, NULL, &proc_iomem_operations);
70360+#endif
70361 return 0;
70362 }
70363 __initcall(ioresources_init);
70364diff --git a/kernel/rtmutex-tester.c b/kernel/rtmutex-tester.c
70365index 98ec494..4241d6d 100644
70366--- a/kernel/rtmutex-tester.c
70367+++ b/kernel/rtmutex-tester.c
70368@@ -20,7 +20,7 @@
70369 #define MAX_RT_TEST_MUTEXES 8
70370
70371 static spinlock_t rttest_lock;
70372-static atomic_t rttest_event;
70373+static atomic_unchecked_t rttest_event;
70374
70375 struct test_thread_data {
70376 int opcode;
70377@@ -61,7 +61,7 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
70378
70379 case RTTEST_LOCKCONT:
70380 td->mutexes[td->opdata] = 1;
70381- td->event = atomic_add_return(1, &rttest_event);
70382+ td->event = atomic_add_return_unchecked(1, &rttest_event);
70383 return 0;
70384
70385 case RTTEST_RESET:
70386@@ -74,7 +74,7 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
70387 return 0;
70388
70389 case RTTEST_RESETEVENT:
70390- atomic_set(&rttest_event, 0);
70391+ atomic_set_unchecked(&rttest_event, 0);
70392 return 0;
70393
70394 default:
70395@@ -91,9 +91,9 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
70396 return ret;
70397
70398 td->mutexes[id] = 1;
70399- td->event = atomic_add_return(1, &rttest_event);
70400+ td->event = atomic_add_return_unchecked(1, &rttest_event);
70401 rt_mutex_lock(&mutexes[id]);
70402- td->event = atomic_add_return(1, &rttest_event);
70403+ td->event = atomic_add_return_unchecked(1, &rttest_event);
70404 td->mutexes[id] = 4;
70405 return 0;
70406
70407@@ -104,9 +104,9 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
70408 return ret;
70409
70410 td->mutexes[id] = 1;
70411- td->event = atomic_add_return(1, &rttest_event);
70412+ td->event = atomic_add_return_unchecked(1, &rttest_event);
70413 ret = rt_mutex_lock_interruptible(&mutexes[id], 0);
70414- td->event = atomic_add_return(1, &rttest_event);
70415+ td->event = atomic_add_return_unchecked(1, &rttest_event);
70416 td->mutexes[id] = ret ? 0 : 4;
70417 return ret ? -EINTR : 0;
70418
70419@@ -115,9 +115,9 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
70420 if (id < 0 || id >= MAX_RT_TEST_MUTEXES || td->mutexes[id] != 4)
70421 return ret;
70422
70423- td->event = atomic_add_return(1, &rttest_event);
70424+ td->event = atomic_add_return_unchecked(1, &rttest_event);
70425 rt_mutex_unlock(&mutexes[id]);
70426- td->event = atomic_add_return(1, &rttest_event);
70427+ td->event = atomic_add_return_unchecked(1, &rttest_event);
70428 td->mutexes[id] = 0;
70429 return 0;
70430
70431@@ -164,7 +164,7 @@ void schedule_rt_mutex_test(struct rt_mutex *mutex)
70432 break;
70433
70434 td->mutexes[dat] = 2;
70435- td->event = atomic_add_return(1, &rttest_event);
70436+ td->event = atomic_add_return_unchecked(1, &rttest_event);
70437 break;
70438
70439 default:
70440@@ -184,7 +184,7 @@ void schedule_rt_mutex_test(struct rt_mutex *mutex)
70441 return;
70442
70443 td->mutexes[dat] = 3;
70444- td->event = atomic_add_return(1, &rttest_event);
70445+ td->event = atomic_add_return_unchecked(1, &rttest_event);
70446 break;
70447
70448 case RTTEST_LOCKNOWAIT:
70449@@ -196,7 +196,7 @@ void schedule_rt_mutex_test(struct rt_mutex *mutex)
70450 return;
70451
70452 td->mutexes[dat] = 1;
70453- td->event = atomic_add_return(1, &rttest_event);
70454+ td->event = atomic_add_return_unchecked(1, &rttest_event);
70455 return;
70456
70457 default:
70458diff --git a/kernel/sched/auto_group.c b/kernel/sched/auto_group.c
70459index 0984a21..939f183 100644
70460--- a/kernel/sched/auto_group.c
70461+++ b/kernel/sched/auto_group.c
70462@@ -11,7 +11,7 @@
70463
70464 unsigned int __read_mostly sysctl_sched_autogroup_enabled = 1;
70465 static struct autogroup autogroup_default;
70466-static atomic_t autogroup_seq_nr;
70467+static atomic_unchecked_t autogroup_seq_nr;
70468
70469 void __init autogroup_init(struct task_struct *init_task)
70470 {
70471@@ -78,7 +78,7 @@ static inline struct autogroup *autogroup_create(void)
70472
70473 kref_init(&ag->kref);
70474 init_rwsem(&ag->lock);
70475- ag->id = atomic_inc_return(&autogroup_seq_nr);
70476+ ag->id = atomic_inc_return_unchecked(&autogroup_seq_nr);
70477 ag->tg = tg;
70478 #ifdef CONFIG_RT_GROUP_SCHED
70479 /*
70480diff --git a/kernel/sched/core.c b/kernel/sched/core.c
70481index 1a48cdb..d3949ff 100644
70482--- a/kernel/sched/core.c
70483+++ b/kernel/sched/core.c
70484@@ -4103,6 +4103,8 @@ int can_nice(const struct task_struct *p, const int nice)
70485 /* convert nice value [19,-20] to rlimit style value [1,40] */
70486 int nice_rlim = 20 - nice;
70487
70488+ gr_learn_resource(p, RLIMIT_NICE, nice_rlim, 1);
70489+
70490 return (nice_rlim <= task_rlimit(p, RLIMIT_NICE) ||
70491 capable(CAP_SYS_NICE));
70492 }
70493@@ -4136,7 +4138,8 @@ SYSCALL_DEFINE1(nice, int, increment)
70494 if (nice > 19)
70495 nice = 19;
70496
70497- if (increment < 0 && !can_nice(current, nice))
70498+ if (increment < 0 && (!can_nice(current, nice) ||
70499+ gr_handle_chroot_nice()))
70500 return -EPERM;
70501
70502 retval = security_task_setnice(current, nice);
70503@@ -4290,6 +4293,7 @@ recheck:
70504 unsigned long rlim_rtprio =
70505 task_rlimit(p, RLIMIT_RTPRIO);
70506
70507+ gr_learn_resource(p, RLIMIT_RTPRIO, param->sched_priority, 1);
70508 /* can't set/change the rt policy */
70509 if (policy != p->policy && !rlim_rtprio)
70510 return -EPERM;
70511diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c
70512index 96e2b18..bb31eec 100644
70513--- a/kernel/sched/fair.c
70514+++ b/kernel/sched/fair.c
70515@@ -4923,7 +4923,7 @@ static void nohz_idle_balance(int this_cpu, enum cpu_idle_type idle) { }
70516 * run_rebalance_domains is triggered when needed from the scheduler tick.
70517 * Also triggered for nohz idle balancing (with nohz_balancing_kick set).
70518 */
70519-static void run_rebalance_domains(struct softirq_action *h)
70520+static void run_rebalance_domains(void)
70521 {
70522 int this_cpu = smp_processor_id();
70523 struct rq *this_rq = cpu_rq(this_cpu);
70524diff --git a/kernel/signal.c b/kernel/signal.c
70525index be4f856..453401c 100644
70526--- a/kernel/signal.c
70527+++ b/kernel/signal.c
70528@@ -48,12 +48,12 @@ static struct kmem_cache *sigqueue_cachep;
70529
70530 int print_fatal_signals __read_mostly;
70531
70532-static void __user *sig_handler(struct task_struct *t, int sig)
70533+static __sighandler_t sig_handler(struct task_struct *t, int sig)
70534 {
70535 return t->sighand->action[sig - 1].sa.sa_handler;
70536 }
70537
70538-static int sig_handler_ignored(void __user *handler, int sig)
70539+static int sig_handler_ignored(__sighandler_t handler, int sig)
70540 {
70541 /* Is it explicitly or implicitly ignored? */
70542 return handler == SIG_IGN ||
70543@@ -62,7 +62,7 @@ static int sig_handler_ignored(void __user *handler, int sig)
70544
70545 static int sig_task_ignored(struct task_struct *t, int sig, bool force)
70546 {
70547- void __user *handler;
70548+ __sighandler_t handler;
70549
70550 handler = sig_handler(t, sig);
70551
70552@@ -366,6 +366,9 @@ __sigqueue_alloc(int sig, struct task_struct *t, gfp_t flags, int override_rlimi
70553 atomic_inc(&user->sigpending);
70554 rcu_read_unlock();
70555
70556+ if (!override_rlimit)
70557+ gr_learn_resource(t, RLIMIT_SIGPENDING, atomic_read(&user->sigpending), 1);
70558+
70559 if (override_rlimit ||
70560 atomic_read(&user->sigpending) <=
70561 task_rlimit(t, RLIMIT_SIGPENDING)) {
70562@@ -490,7 +493,7 @@ flush_signal_handlers(struct task_struct *t, int force_default)
70563
70564 int unhandled_signal(struct task_struct *tsk, int sig)
70565 {
70566- void __user *handler = tsk->sighand->action[sig-1].sa.sa_handler;
70567+ __sighandler_t handler = tsk->sighand->action[sig-1].sa.sa_handler;
70568 if (is_global_init(tsk))
70569 return 1;
70570 if (handler != SIG_IGN && handler != SIG_DFL)
70571@@ -816,6 +819,13 @@ static int check_kill_permission(int sig, struct siginfo *info,
70572 }
70573 }
70574
70575+ /* allow glibc communication via tgkill to other threads in our
70576+ thread group */
70577+ if ((info == SEND_SIG_NOINFO || info->si_code != SI_TKILL ||
70578+ sig != (SIGRTMIN+1) || task_tgid_vnr(t) != info->si_pid)
70579+ && gr_handle_signal(t, sig))
70580+ return -EPERM;
70581+
70582 return security_task_kill(t, info, sig, 0);
70583 }
70584
70585@@ -1197,7 +1207,7 @@ __group_send_sig_info(int sig, struct siginfo *info, struct task_struct *p)
70586 return send_signal(sig, info, p, 1);
70587 }
70588
70589-static int
70590+int
70591 specific_send_sig_info(int sig, struct siginfo *info, struct task_struct *t)
70592 {
70593 return send_signal(sig, info, t, 0);
70594@@ -1234,6 +1244,7 @@ force_sig_info(int sig, struct siginfo *info, struct task_struct *t)
70595 unsigned long int flags;
70596 int ret, blocked, ignored;
70597 struct k_sigaction *action;
70598+ int is_unhandled = 0;
70599
70600 spin_lock_irqsave(&t->sighand->siglock, flags);
70601 action = &t->sighand->action[sig-1];
70602@@ -1248,9 +1259,18 @@ force_sig_info(int sig, struct siginfo *info, struct task_struct *t)
70603 }
70604 if (action->sa.sa_handler == SIG_DFL)
70605 t->signal->flags &= ~SIGNAL_UNKILLABLE;
70606+ if (action->sa.sa_handler == SIG_IGN || action->sa.sa_handler == SIG_DFL)
70607+ is_unhandled = 1;
70608 ret = specific_send_sig_info(sig, info, t);
70609 spin_unlock_irqrestore(&t->sighand->siglock, flags);
70610
70611+ /* only deal with unhandled signals, java etc trigger SIGSEGV during
70612+ normal operation */
70613+ if (is_unhandled) {
70614+ gr_log_signal(sig, !is_si_special(info) ? info->si_addr : NULL, t);
70615+ gr_handle_crash(t, sig);
70616+ }
70617+
70618 return ret;
70619 }
70620
70621@@ -1317,8 +1337,11 @@ int group_send_sig_info(int sig, struct siginfo *info, struct task_struct *p)
70622 ret = check_kill_permission(sig, info, p);
70623 rcu_read_unlock();
70624
70625- if (!ret && sig)
70626+ if (!ret && sig) {
70627 ret = do_send_sig_info(sig, info, p, true);
70628+ if (!ret)
70629+ gr_log_signal(sig, !is_si_special(info) ? info->si_addr : NULL, p);
70630+ }
70631
70632 return ret;
70633 }
70634@@ -2873,7 +2896,15 @@ do_send_specific(pid_t tgid, pid_t pid, int sig, struct siginfo *info)
70635 int error = -ESRCH;
70636
70637 rcu_read_lock();
70638- p = find_task_by_vpid(pid);
70639+#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
70640+ /* allow glibc communication via tgkill to other threads in our
70641+ thread group */
70642+ if (grsec_enable_chroot_findtask && info->si_code == SI_TKILL &&
70643+ sig == (SIGRTMIN+1) && tgid == info->si_pid)
70644+ p = find_task_by_vpid_unrestricted(pid);
70645+ else
70646+#endif
70647+ p = find_task_by_vpid(pid);
70648 if (p && (tgid <= 0 || task_tgid_vnr(p) == tgid)) {
70649 error = check_kill_permission(sig, info, p);
70650 /*
70651diff --git a/kernel/softirq.c b/kernel/softirq.c
70652index b73e681..645ab62 100644
70653--- a/kernel/softirq.c
70654+++ b/kernel/softirq.c
70655@@ -56,7 +56,7 @@ static struct softirq_action softirq_vec[NR_SOFTIRQS] __cacheline_aligned_in_smp
70656
70657 DEFINE_PER_CPU(struct task_struct *, ksoftirqd);
70658
70659-char *softirq_to_name[NR_SOFTIRQS] = {
70660+const char * const softirq_to_name[NR_SOFTIRQS] = {
70661 "HI", "TIMER", "NET_TX", "NET_RX", "BLOCK", "BLOCK_IOPOLL",
70662 "TASKLET", "SCHED", "HRTIMER", "RCU"
70663 };
70664@@ -243,7 +243,7 @@ restart:
70665 kstat_incr_softirqs_this_cpu(vec_nr);
70666
70667 trace_softirq_entry(vec_nr);
70668- h->action(h);
70669+ h->action();
70670 trace_softirq_exit(vec_nr);
70671 if (unlikely(prev_count != preempt_count())) {
70672 printk(KERN_ERR "huh, entered softirq %u %s %p"
70673@@ -390,9 +390,11 @@ void __raise_softirq_irqoff(unsigned int nr)
70674 or_softirq_pending(1UL << nr);
70675 }
70676
70677-void open_softirq(int nr, void (*action)(struct softirq_action *))
70678+void open_softirq(int nr, void (*action)(void))
70679 {
70680- softirq_vec[nr].action = action;
70681+ pax_open_kernel();
70682+ *(void **)&softirq_vec[nr].action = action;
70683+ pax_close_kernel();
70684 }
70685
70686 /*
70687@@ -446,7 +448,7 @@ void __tasklet_hi_schedule_first(struct tasklet_struct *t)
70688
70689 EXPORT_SYMBOL(__tasklet_hi_schedule_first);
70690
70691-static void tasklet_action(struct softirq_action *a)
70692+static void tasklet_action(void)
70693 {
70694 struct tasklet_struct *list;
70695
70696@@ -481,7 +483,7 @@ static void tasklet_action(struct softirq_action *a)
70697 }
70698 }
70699
70700-static void tasklet_hi_action(struct softirq_action *a)
70701+static void tasklet_hi_action(void)
70702 {
70703 struct tasklet_struct *list;
70704
70705diff --git a/kernel/srcu.c b/kernel/srcu.c
70706index 2095be3..9a5b89d 100644
70707--- a/kernel/srcu.c
70708+++ b/kernel/srcu.c
70709@@ -302,9 +302,9 @@ int __srcu_read_lock(struct srcu_struct *sp)
70710 preempt_disable();
70711 idx = rcu_dereference_index_check(sp->completed,
70712 rcu_read_lock_sched_held()) & 0x1;
70713- ACCESS_ONCE(this_cpu_ptr(sp->per_cpu_ref)->c[idx]) += 1;
70714+ ACCESS_ONCE_RW(this_cpu_ptr(sp->per_cpu_ref)->c[idx]) += 1;
70715 smp_mb(); /* B */ /* Avoid leaking the critical section. */
70716- ACCESS_ONCE(this_cpu_ptr(sp->per_cpu_ref)->seq[idx]) += 1;
70717+ ACCESS_ONCE_RW(this_cpu_ptr(sp->per_cpu_ref)->seq[idx]) += 1;
70718 preempt_enable();
70719 return idx;
70720 }
70721@@ -320,7 +320,7 @@ void __srcu_read_unlock(struct srcu_struct *sp, int idx)
70722 {
70723 preempt_disable();
70724 smp_mb(); /* C */ /* Avoid leaking the critical section. */
70725- ACCESS_ONCE(this_cpu_ptr(sp->per_cpu_ref)->c[idx]) -= 1;
70726+ ACCESS_ONCE_RW(this_cpu_ptr(sp->per_cpu_ref)->c[idx]) -= 1;
70727 preempt_enable();
70728 }
70729 EXPORT_SYMBOL_GPL(__srcu_read_unlock);
70730diff --git a/kernel/sys.c b/kernel/sys.c
70731index 909148a..cd51acf 100644
70732--- a/kernel/sys.c
70733+++ b/kernel/sys.c
70734@@ -157,6 +157,12 @@ static int set_one_prio(struct task_struct *p, int niceval, int error)
70735 error = -EACCES;
70736 goto out;
70737 }
70738+
70739+ if (gr_handle_chroot_setpriority(p, niceval)) {
70740+ error = -EACCES;
70741+ goto out;
70742+ }
70743+
70744 no_nice = security_task_setnice(p, niceval);
70745 if (no_nice) {
70746 error = no_nice;
70747@@ -595,6 +601,9 @@ SYSCALL_DEFINE2(setregid, gid_t, rgid, gid_t, egid)
70748 goto error;
70749 }
70750
70751+ if (gr_check_group_change(new->gid, new->egid, -1))
70752+ goto error;
70753+
70754 if (rgid != (gid_t) -1 ||
70755 (egid != (gid_t) -1 && !gid_eq(kegid, old->gid)))
70756 new->sgid = new->egid;
70757@@ -630,6 +639,10 @@ SYSCALL_DEFINE1(setgid, gid_t, gid)
70758 old = current_cred();
70759
70760 retval = -EPERM;
70761+
70762+ if (gr_check_group_change(kgid, kgid, kgid))
70763+ goto error;
70764+
70765 if (nsown_capable(CAP_SETGID))
70766 new->gid = new->egid = new->sgid = new->fsgid = kgid;
70767 else if (gid_eq(kgid, old->gid) || gid_eq(kgid, old->sgid))
70768@@ -647,7 +660,7 @@ error:
70769 /*
70770 * change the user struct in a credentials set to match the new UID
70771 */
70772-static int set_user(struct cred *new)
70773+int set_user(struct cred *new)
70774 {
70775 struct user_struct *new_user;
70776
70777@@ -727,6 +740,9 @@ SYSCALL_DEFINE2(setreuid, uid_t, ruid, uid_t, euid)
70778 goto error;
70779 }
70780
70781+ if (gr_check_user_change(new->uid, new->euid, -1))
70782+ goto error;
70783+
70784 if (!uid_eq(new->uid, old->uid)) {
70785 retval = set_user(new);
70786 if (retval < 0)
70787@@ -777,6 +793,12 @@ SYSCALL_DEFINE1(setuid, uid_t, uid)
70788 old = current_cred();
70789
70790 retval = -EPERM;
70791+
70792+ if (gr_check_crash_uid(kuid))
70793+ goto error;
70794+ if (gr_check_user_change(kuid, kuid, kuid))
70795+ goto error;
70796+
70797 if (nsown_capable(CAP_SETUID)) {
70798 new->suid = new->uid = kuid;
70799 if (!uid_eq(kuid, old->uid)) {
70800@@ -846,6 +868,9 @@ SYSCALL_DEFINE3(setresuid, uid_t, ruid, uid_t, euid, uid_t, suid)
70801 goto error;
70802 }
70803
70804+ if (gr_check_user_change(kruid, keuid, -1))
70805+ goto error;
70806+
70807 if (ruid != (uid_t) -1) {
70808 new->uid = kruid;
70809 if (!uid_eq(kruid, old->uid)) {
70810@@ -928,6 +953,9 @@ SYSCALL_DEFINE3(setresgid, gid_t, rgid, gid_t, egid, gid_t, sgid)
70811 goto error;
70812 }
70813
70814+ if (gr_check_group_change(krgid, kegid, -1))
70815+ goto error;
70816+
70817 if (rgid != (gid_t) -1)
70818 new->gid = krgid;
70819 if (egid != (gid_t) -1)
70820@@ -981,6 +1009,9 @@ SYSCALL_DEFINE1(setfsuid, uid_t, uid)
70821 if (!uid_valid(kuid))
70822 return old_fsuid;
70823
70824+ if (gr_check_user_change(-1, -1, kuid))
70825+ goto error;
70826+
70827 new = prepare_creds();
70828 if (!new)
70829 return old_fsuid;
70830@@ -995,6 +1026,7 @@ SYSCALL_DEFINE1(setfsuid, uid_t, uid)
70831 }
70832 }
70833
70834+error:
70835 abort_creds(new);
70836 return old_fsuid;
70837
70838@@ -1027,12 +1059,16 @@ SYSCALL_DEFINE1(setfsgid, gid_t, gid)
70839 if (gid_eq(kgid, old->gid) || gid_eq(kgid, old->egid) ||
70840 gid_eq(kgid, old->sgid) || gid_eq(kgid, old->fsgid) ||
70841 nsown_capable(CAP_SETGID)) {
70842+ if (gr_check_group_change(-1, -1, kgid))
70843+ goto error;
70844+
70845 if (!gid_eq(kgid, old->fsgid)) {
70846 new->fsgid = kgid;
70847 goto change_okay;
70848 }
70849 }
70850
70851+error:
70852 abort_creds(new);
70853 return old_fsgid;
70854
70855@@ -1340,19 +1376,19 @@ SYSCALL_DEFINE1(olduname, struct oldold_utsname __user *, name)
70856 return -EFAULT;
70857
70858 down_read(&uts_sem);
70859- error = __copy_to_user(&name->sysname, &utsname()->sysname,
70860+ error = __copy_to_user(name->sysname, &utsname()->sysname,
70861 __OLD_UTS_LEN);
70862 error |= __put_user(0, name->sysname + __OLD_UTS_LEN);
70863- error |= __copy_to_user(&name->nodename, &utsname()->nodename,
70864+ error |= __copy_to_user(name->nodename, &utsname()->nodename,
70865 __OLD_UTS_LEN);
70866 error |= __put_user(0, name->nodename + __OLD_UTS_LEN);
70867- error |= __copy_to_user(&name->release, &utsname()->release,
70868+ error |= __copy_to_user(name->release, &utsname()->release,
70869 __OLD_UTS_LEN);
70870 error |= __put_user(0, name->release + __OLD_UTS_LEN);
70871- error |= __copy_to_user(&name->version, &utsname()->version,
70872+ error |= __copy_to_user(name->version, &utsname()->version,
70873 __OLD_UTS_LEN);
70874 error |= __put_user(0, name->version + __OLD_UTS_LEN);
70875- error |= __copy_to_user(&name->machine, &utsname()->machine,
70876+ error |= __copy_to_user(name->machine, &utsname()->machine,
70877 __OLD_UTS_LEN);
70878 error |= __put_user(0, name->machine + __OLD_UTS_LEN);
70879 up_read(&uts_sem);
70880@@ -2026,7 +2062,7 @@ SYSCALL_DEFINE5(prctl, int, option, unsigned long, arg2, unsigned long, arg3,
70881 error = get_dumpable(me->mm);
70882 break;
70883 case PR_SET_DUMPABLE:
70884- if (arg2 < 0 || arg2 > 1) {
70885+ if (arg2 > 1) {
70886 error = -EINVAL;
70887 break;
70888 }
70889diff --git a/kernel/sysctl.c b/kernel/sysctl.c
70890index 87174ef..68cbb82 100644
70891--- a/kernel/sysctl.c
70892+++ b/kernel/sysctl.c
70893@@ -92,7 +92,6 @@
70894
70895
70896 #if defined(CONFIG_SYSCTL)
70897-
70898 /* External variables not in a header file. */
70899 extern int sysctl_overcommit_memory;
70900 extern int sysctl_overcommit_ratio;
70901@@ -170,10 +169,8 @@ static int proc_taint(struct ctl_table *table, int write,
70902 void __user *buffer, size_t *lenp, loff_t *ppos);
70903 #endif
70904
70905-#ifdef CONFIG_PRINTK
70906 static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
70907 void __user *buffer, size_t *lenp, loff_t *ppos);
70908-#endif
70909
70910 static int proc_dointvec_minmax_coredump(struct ctl_table *table, int write,
70911 void __user *buffer, size_t *lenp, loff_t *ppos);
70912@@ -202,6 +199,8 @@ static int sysrq_sysctl_handler(ctl_table *table, int write,
70913
70914 #endif
70915
70916+extern struct ctl_table grsecurity_table[];
70917+
70918 static struct ctl_table kern_table[];
70919 static struct ctl_table vm_table[];
70920 static struct ctl_table fs_table[];
70921@@ -216,6 +215,20 @@ extern struct ctl_table epoll_table[];
70922 int sysctl_legacy_va_layout;
70923 #endif
70924
70925+#ifdef CONFIG_PAX_SOFTMODE
70926+static ctl_table pax_table[] = {
70927+ {
70928+ .procname = "softmode",
70929+ .data = &pax_softmode,
70930+ .maxlen = sizeof(unsigned int),
70931+ .mode = 0600,
70932+ .proc_handler = &proc_dointvec,
70933+ },
70934+
70935+ { }
70936+};
70937+#endif
70938+
70939 /* The default sysctl tables: */
70940
70941 static struct ctl_table sysctl_base_table[] = {
70942@@ -262,6 +275,22 @@ static int max_extfrag_threshold = 1000;
70943 #endif
70944
70945 static struct ctl_table kern_table[] = {
70946+#if defined(CONFIG_GRKERNSEC_SYSCTL) || defined(CONFIG_GRKERNSEC_ROFS)
70947+ {
70948+ .procname = "grsecurity",
70949+ .mode = 0500,
70950+ .child = grsecurity_table,
70951+ },
70952+#endif
70953+
70954+#ifdef CONFIG_PAX_SOFTMODE
70955+ {
70956+ .procname = "pax",
70957+ .mode = 0500,
70958+ .child = pax_table,
70959+ },
70960+#endif
70961+
70962 {
70963 .procname = "sched_child_runs_first",
70964 .data = &sysctl_sched_child_runs_first,
70965@@ -546,7 +575,7 @@ static struct ctl_table kern_table[] = {
70966 .data = &modprobe_path,
70967 .maxlen = KMOD_PATH_LEN,
70968 .mode = 0644,
70969- .proc_handler = proc_dostring,
70970+ .proc_handler = proc_dostring_modpriv,
70971 },
70972 {
70973 .procname = "modules_disabled",
70974@@ -713,16 +742,20 @@ static struct ctl_table kern_table[] = {
70975 .extra1 = &zero,
70976 .extra2 = &one,
70977 },
70978+#endif
70979 {
70980 .procname = "kptr_restrict",
70981 .data = &kptr_restrict,
70982 .maxlen = sizeof(int),
70983 .mode = 0644,
70984 .proc_handler = proc_dointvec_minmax_sysadmin,
70985+#ifdef CONFIG_GRKERNSEC_HIDESYM
70986+ .extra1 = &two,
70987+#else
70988 .extra1 = &zero,
70989+#endif
70990 .extra2 = &two,
70991 },
70992-#endif
70993 {
70994 .procname = "ngroups_max",
70995 .data = &ngroups_max,
70996@@ -1219,6 +1252,13 @@ static struct ctl_table vm_table[] = {
70997 .proc_handler = proc_dointvec_minmax,
70998 .extra1 = &zero,
70999 },
71000+ {
71001+ .procname = "heap_stack_gap",
71002+ .data = &sysctl_heap_stack_gap,
71003+ .maxlen = sizeof(sysctl_heap_stack_gap),
71004+ .mode = 0644,
71005+ .proc_handler = proc_doulongvec_minmax,
71006+ },
71007 #else
71008 {
71009 .procname = "nr_trim_pages",
71010@@ -1670,6 +1710,16 @@ int proc_dostring(struct ctl_table *table, int write,
71011 buffer, lenp, ppos);
71012 }
71013
71014+int proc_dostring_modpriv(struct ctl_table *table, int write,
71015+ void __user *buffer, size_t *lenp, loff_t *ppos)
71016+{
71017+ if (write && !capable(CAP_SYS_MODULE))
71018+ return -EPERM;
71019+
71020+ return _proc_do_string(table->data, table->maxlen, write,
71021+ buffer, lenp, ppos);
71022+}
71023+
71024 static size_t proc_skip_spaces(char **buf)
71025 {
71026 size_t ret;
71027@@ -1775,6 +1825,8 @@ static int proc_put_long(void __user **buf, size_t *size, unsigned long val,
71028 len = strlen(tmp);
71029 if (len > *size)
71030 len = *size;
71031+ if (len > sizeof(tmp))
71032+ len = sizeof(tmp);
71033 if (copy_to_user(*buf, tmp, len))
71034 return -EFAULT;
71035 *size -= len;
71036@@ -1967,7 +2019,6 @@ static int proc_taint(struct ctl_table *table, int write,
71037 return err;
71038 }
71039
71040-#ifdef CONFIG_PRINTK
71041 static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
71042 void __user *buffer, size_t *lenp, loff_t *ppos)
71043 {
71044@@ -1976,7 +2027,6 @@ static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
71045
71046 return proc_dointvec_minmax(table, write, buffer, lenp, ppos);
71047 }
71048-#endif
71049
71050 struct do_proc_dointvec_minmax_conv_param {
71051 int *min;
71052@@ -2119,8 +2169,11 @@ static int __do_proc_doulongvec_minmax(void *data, struct ctl_table *table, int
71053 *i = val;
71054 } else {
71055 val = convdiv * (*i) / convmul;
71056- if (!first)
71057+ if (!first) {
71058 err = proc_put_char(&buffer, &left, '\t');
71059+ if (err)
71060+ break;
71061+ }
71062 err = proc_put_long(&buffer, &left, val, false);
71063 if (err)
71064 break;
71065@@ -2512,6 +2565,12 @@ int proc_dostring(struct ctl_table *table, int write,
71066 return -ENOSYS;
71067 }
71068
71069+int proc_dostring_modpriv(struct ctl_table *table, int write,
71070+ void __user *buffer, size_t *lenp, loff_t *ppos)
71071+{
71072+ return -ENOSYS;
71073+}
71074+
71075 int proc_dointvec(struct ctl_table *table, int write,
71076 void __user *buffer, size_t *lenp, loff_t *ppos)
71077 {
71078@@ -2568,5 +2627,6 @@ EXPORT_SYMBOL(proc_dointvec_minmax);
71079 EXPORT_SYMBOL(proc_dointvec_userhz_jiffies);
71080 EXPORT_SYMBOL(proc_dointvec_ms_jiffies);
71081 EXPORT_SYMBOL(proc_dostring);
71082+EXPORT_SYMBOL(proc_dostring_modpriv);
71083 EXPORT_SYMBOL(proc_doulongvec_minmax);
71084 EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax);
71085diff --git a/kernel/sysctl_binary.c b/kernel/sysctl_binary.c
71086index 65bdcf1..21eb831 100644
71087--- a/kernel/sysctl_binary.c
71088+++ b/kernel/sysctl_binary.c
71089@@ -989,7 +989,7 @@ static ssize_t bin_intvec(struct file *file,
71090 int i;
71091
71092 set_fs(KERNEL_DS);
71093- result = vfs_read(file, buffer, BUFSZ - 1, &pos);
71094+ result = vfs_read(file, (char __force_user *)buffer, BUFSZ - 1, &pos);
71095 set_fs(old_fs);
71096 if (result < 0)
71097 goto out_kfree;
71098@@ -1034,7 +1034,7 @@ static ssize_t bin_intvec(struct file *file,
71099 }
71100
71101 set_fs(KERNEL_DS);
71102- result = vfs_write(file, buffer, str - buffer, &pos);
71103+ result = vfs_write(file, (const char __force_user *)buffer, str - buffer, &pos);
71104 set_fs(old_fs);
71105 if (result < 0)
71106 goto out_kfree;
71107@@ -1067,7 +1067,7 @@ static ssize_t bin_ulongvec(struct file *file,
71108 int i;
71109
71110 set_fs(KERNEL_DS);
71111- result = vfs_read(file, buffer, BUFSZ - 1, &pos);
71112+ result = vfs_read(file, (char __force_user *)buffer, BUFSZ - 1, &pos);
71113 set_fs(old_fs);
71114 if (result < 0)
71115 goto out_kfree;
71116@@ -1112,7 +1112,7 @@ static ssize_t bin_ulongvec(struct file *file,
71117 }
71118
71119 set_fs(KERNEL_DS);
71120- result = vfs_write(file, buffer, str - buffer, &pos);
71121+ result = vfs_write(file, (const char __force_user *)buffer, str - buffer, &pos);
71122 set_fs(old_fs);
71123 if (result < 0)
71124 goto out_kfree;
71125@@ -1138,7 +1138,7 @@ static ssize_t bin_uuid(struct file *file,
71126 int i;
71127
71128 set_fs(KERNEL_DS);
71129- result = vfs_read(file, buf, sizeof(buf) - 1, &pos);
71130+ result = vfs_read(file, (char __force_user *)buf, sizeof(buf) - 1, &pos);
71131 set_fs(old_fs);
71132 if (result < 0)
71133 goto out;
71134@@ -1185,7 +1185,7 @@ static ssize_t bin_dn_node_address(struct file *file,
71135 __le16 dnaddr;
71136
71137 set_fs(KERNEL_DS);
71138- result = vfs_read(file, buf, sizeof(buf) - 1, &pos);
71139+ result = vfs_read(file, (char __force_user *)buf, sizeof(buf) - 1, &pos);
71140 set_fs(old_fs);
71141 if (result < 0)
71142 goto out;
71143@@ -1233,7 +1233,7 @@ static ssize_t bin_dn_node_address(struct file *file,
71144 le16_to_cpu(dnaddr) & 0x3ff);
71145
71146 set_fs(KERNEL_DS);
71147- result = vfs_write(file, buf, len, &pos);
71148+ result = vfs_write(file, (const char __force_user *)buf, len, &pos);
71149 set_fs(old_fs);
71150 if (result < 0)
71151 goto out;
71152diff --git a/kernel/taskstats.c b/kernel/taskstats.c
71153index d0a3279..db0ad99 100644
71154--- a/kernel/taskstats.c
71155+++ b/kernel/taskstats.c
71156@@ -27,9 +27,12 @@
71157 #include <linux/cgroup.h>
71158 #include <linux/fs.h>
71159 #include <linux/file.h>
71160+#include <linux/grsecurity.h>
71161 #include <net/genetlink.h>
71162 #include <linux/atomic.h>
71163
71164+extern int gr_is_taskstats_denied(int pid);
71165+
71166 /*
71167 * Maximum length of a cpumask that can be specified in
71168 * the TASKSTATS_CMD_ATTR_REGISTER/DEREGISTER_CPUMASK attribute
71169@@ -561,6 +564,9 @@ err:
71170
71171 static int taskstats_user_cmd(struct sk_buff *skb, struct genl_info *info)
71172 {
71173+ if (gr_is_taskstats_denied(current->pid))
71174+ return -EACCES;
71175+
71176 if (info->attrs[TASKSTATS_CMD_ATTR_REGISTER_CPUMASK])
71177 return cmd_attr_register_cpumask(info);
71178 else if (info->attrs[TASKSTATS_CMD_ATTR_DEREGISTER_CPUMASK])
71179diff --git a/kernel/time.c b/kernel/time.c
71180index ba744cf..267b7c5 100644
71181--- a/kernel/time.c
71182+++ b/kernel/time.c
71183@@ -163,6 +163,11 @@ int do_sys_settimeofday(const struct timespec *tv, const struct timezone *tz)
71184 return error;
71185
71186 if (tz) {
71187+ /* we log in do_settimeofday called below, so don't log twice
71188+ */
71189+ if (!tv)
71190+ gr_log_timechange();
71191+
71192 sys_tz = *tz;
71193 update_vsyscall_tz();
71194 if (firsttime) {
71195diff --git a/kernel/time/alarmtimer.c b/kernel/time/alarmtimer.c
71196index aa27d39..34d221c 100644
71197--- a/kernel/time/alarmtimer.c
71198+++ b/kernel/time/alarmtimer.c
71199@@ -779,7 +779,7 @@ static int __init alarmtimer_init(void)
71200 struct platform_device *pdev;
71201 int error = 0;
71202 int i;
71203- struct k_clock alarm_clock = {
71204+ static struct k_clock alarm_clock = {
71205 .clock_getres = alarm_clock_getres,
71206 .clock_get = alarm_clock_get,
71207 .timer_create = alarm_timer_create,
71208diff --git a/kernel/time/tick-broadcast.c b/kernel/time/tick-broadcast.c
71209index f113755..ec24223 100644
71210--- a/kernel/time/tick-broadcast.c
71211+++ b/kernel/time/tick-broadcast.c
71212@@ -115,7 +115,7 @@ int tick_device_uses_broadcast(struct clock_event_device *dev, int cpu)
71213 * then clear the broadcast bit.
71214 */
71215 if (!(dev->features & CLOCK_EVT_FEAT_C3STOP)) {
71216- int cpu = smp_processor_id();
71217+ cpu = smp_processor_id();
71218
71219 cpumask_clear_cpu(cpu, tick_get_broadcast_mask());
71220 tick_broadcast_clear_oneshot(cpu);
71221diff --git a/kernel/time/timekeeping.c b/kernel/time/timekeeping.c
71222index f791637..00051de 100644
71223--- a/kernel/time/timekeeping.c
71224+++ b/kernel/time/timekeeping.c
71225@@ -14,6 +14,7 @@
71226 #include <linux/init.h>
71227 #include <linux/mm.h>
71228 #include <linux/sched.h>
71229+#include <linux/grsecurity.h>
71230 #include <linux/syscore_ops.h>
71231 #include <linux/clocksource.h>
71232 #include <linux/jiffies.h>
71233@@ -434,6 +435,8 @@ int do_settimeofday(const struct timespec *tv)
71234 if (!timespec_valid_strict(tv))
71235 return -EINVAL;
71236
71237+ gr_log_timechange();
71238+
71239 write_seqlock_irqsave(&tk->lock, flags);
71240
71241 timekeeping_forward_now(tk);
71242diff --git a/kernel/time/timer_list.c b/kernel/time/timer_list.c
71243index af5a7e9..715611a 100644
71244--- a/kernel/time/timer_list.c
71245+++ b/kernel/time/timer_list.c
71246@@ -38,12 +38,16 @@ DECLARE_PER_CPU(struct hrtimer_cpu_base, hrtimer_bases);
71247
71248 static void print_name_offset(struct seq_file *m, void *sym)
71249 {
71250+#ifdef CONFIG_GRKERNSEC_HIDESYM
71251+ SEQ_printf(m, "<%p>", NULL);
71252+#else
71253 char symname[KSYM_NAME_LEN];
71254
71255 if (lookup_symbol_name((unsigned long)sym, symname) < 0)
71256 SEQ_printf(m, "<%pK>", sym);
71257 else
71258 SEQ_printf(m, "%s", symname);
71259+#endif
71260 }
71261
71262 static void
71263@@ -112,7 +116,11 @@ next_one:
71264 static void
71265 print_base(struct seq_file *m, struct hrtimer_clock_base *base, u64 now)
71266 {
71267+#ifdef CONFIG_GRKERNSEC_HIDESYM
71268+ SEQ_printf(m, " .base: %p\n", NULL);
71269+#else
71270 SEQ_printf(m, " .base: %pK\n", base);
71271+#endif
71272 SEQ_printf(m, " .index: %d\n",
71273 base->index);
71274 SEQ_printf(m, " .resolution: %Lu nsecs\n",
71275@@ -293,7 +301,11 @@ static int __init init_timer_list_procfs(void)
71276 {
71277 struct proc_dir_entry *pe;
71278
71279+#ifdef CONFIG_GRKERNSEC_PROC_ADD
71280+ pe = proc_create("timer_list", 0400, NULL, &timer_list_fops);
71281+#else
71282 pe = proc_create("timer_list", 0444, NULL, &timer_list_fops);
71283+#endif
71284 if (!pe)
71285 return -ENOMEM;
71286 return 0;
71287diff --git a/kernel/time/timer_stats.c b/kernel/time/timer_stats.c
71288index 0b537f2..40d6c20 100644
71289--- a/kernel/time/timer_stats.c
71290+++ b/kernel/time/timer_stats.c
71291@@ -116,7 +116,7 @@ static ktime_t time_start, time_stop;
71292 static unsigned long nr_entries;
71293 static struct entry entries[MAX_ENTRIES];
71294
71295-static atomic_t overflow_count;
71296+static atomic_unchecked_t overflow_count;
71297
71298 /*
71299 * The entries are in a hash-table, for fast lookup:
71300@@ -140,7 +140,7 @@ static void reset_entries(void)
71301 nr_entries = 0;
71302 memset(entries, 0, sizeof(entries));
71303 memset(tstat_hash_table, 0, sizeof(tstat_hash_table));
71304- atomic_set(&overflow_count, 0);
71305+ atomic_set_unchecked(&overflow_count, 0);
71306 }
71307
71308 static struct entry *alloc_entry(void)
71309@@ -261,7 +261,7 @@ void timer_stats_update_stats(void *timer, pid_t pid, void *startf,
71310 if (likely(entry))
71311 entry->count++;
71312 else
71313- atomic_inc(&overflow_count);
71314+ atomic_inc_unchecked(&overflow_count);
71315
71316 out_unlock:
71317 raw_spin_unlock_irqrestore(lock, flags);
71318@@ -269,12 +269,16 @@ void timer_stats_update_stats(void *timer, pid_t pid, void *startf,
71319
71320 static void print_name_offset(struct seq_file *m, unsigned long addr)
71321 {
71322+#ifdef CONFIG_GRKERNSEC_HIDESYM
71323+ seq_printf(m, "<%p>", NULL);
71324+#else
71325 char symname[KSYM_NAME_LEN];
71326
71327 if (lookup_symbol_name(addr, symname) < 0)
71328- seq_printf(m, "<%p>", (void *)addr);
71329+ seq_printf(m, "<%pK>", (void *)addr);
71330 else
71331 seq_printf(m, "%s", symname);
71332+#endif
71333 }
71334
71335 static int tstats_show(struct seq_file *m, void *v)
71336@@ -300,9 +304,9 @@ static int tstats_show(struct seq_file *m, void *v)
71337
71338 seq_puts(m, "Timer Stats Version: v0.2\n");
71339 seq_printf(m, "Sample period: %ld.%03ld s\n", period.tv_sec, ms);
71340- if (atomic_read(&overflow_count))
71341+ if (atomic_read_unchecked(&overflow_count))
71342 seq_printf(m, "Overflow: %d entries\n",
71343- atomic_read(&overflow_count));
71344+ atomic_read_unchecked(&overflow_count));
71345
71346 for (i = 0; i < nr_entries; i++) {
71347 entry = entries + i;
71348@@ -417,7 +421,11 @@ static int __init init_tstats_procfs(void)
71349 {
71350 struct proc_dir_entry *pe;
71351
71352+#ifdef CONFIG_GRKERNSEC_PROC_ADD
71353+ pe = proc_create("timer_stats", 0600, NULL, &tstats_fops);
71354+#else
71355 pe = proc_create("timer_stats", 0644, NULL, &tstats_fops);
71356+#endif
71357 if (!pe)
71358 return -ENOMEM;
71359 return 0;
71360diff --git a/kernel/timer.c b/kernel/timer.c
71361index 46ef2b1..ad081f144 100644
71362--- a/kernel/timer.c
71363+++ b/kernel/timer.c
71364@@ -1377,7 +1377,7 @@ void update_process_times(int user_tick)
71365 /*
71366 * This function runs timers and the timer-tq in bottom half context.
71367 */
71368-static void run_timer_softirq(struct softirq_action *h)
71369+static void run_timer_softirq(void)
71370 {
71371 struct tvec_base *base = __this_cpu_read(tvec_bases);
71372
71373diff --git a/kernel/trace/blktrace.c b/kernel/trace/blktrace.c
71374index c0bd030..62a1927 100644
71375--- a/kernel/trace/blktrace.c
71376+++ b/kernel/trace/blktrace.c
71377@@ -317,7 +317,7 @@ static ssize_t blk_dropped_read(struct file *filp, char __user *buffer,
71378 struct blk_trace *bt = filp->private_data;
71379 char buf[16];
71380
71381- snprintf(buf, sizeof(buf), "%u\n", atomic_read(&bt->dropped));
71382+ snprintf(buf, sizeof(buf), "%u\n", atomic_read_unchecked(&bt->dropped));
71383
71384 return simple_read_from_buffer(buffer, count, ppos, buf, strlen(buf));
71385 }
71386@@ -375,7 +375,7 @@ static int blk_subbuf_start_callback(struct rchan_buf *buf, void *subbuf,
71387 return 1;
71388
71389 bt = buf->chan->private_data;
71390- atomic_inc(&bt->dropped);
71391+ atomic_inc_unchecked(&bt->dropped);
71392 return 0;
71393 }
71394
71395@@ -476,7 +476,7 @@ int do_blk_trace_setup(struct request_queue *q, char *name, dev_t dev,
71396
71397 bt->dir = dir;
71398 bt->dev = dev;
71399- atomic_set(&bt->dropped, 0);
71400+ atomic_set_unchecked(&bt->dropped, 0);
71401
71402 ret = -EIO;
71403 bt->dropped_file = debugfs_create_file("dropped", 0444, dir, bt,
71404diff --git a/kernel/trace/ftrace.c b/kernel/trace/ftrace.c
71405index b4f20fb..483c5fa 100644
71406--- a/kernel/trace/ftrace.c
71407+++ b/kernel/trace/ftrace.c
71408@@ -1785,12 +1785,17 @@ ftrace_code_disable(struct module *mod, struct dyn_ftrace *rec)
71409 if (unlikely(ftrace_disabled))
71410 return 0;
71411
71412+ ret = ftrace_arch_code_modify_prepare();
71413+ FTRACE_WARN_ON(ret);
71414+ if (ret)
71415+ return 0;
71416+
71417 ret = ftrace_make_nop(mod, rec, MCOUNT_ADDR);
71418+ FTRACE_WARN_ON(ftrace_arch_code_modify_post_process());
71419 if (ret) {
71420 ftrace_bug(ret, ip);
71421- return 0;
71422 }
71423- return 1;
71424+ return ret ? 0 : 1;
71425 }
71426
71427 /*
71428@@ -2885,7 +2890,7 @@ static void ftrace_free_entry_rcu(struct rcu_head *rhp)
71429
71430 int
71431 register_ftrace_function_probe(char *glob, struct ftrace_probe_ops *ops,
71432- void *data)
71433+ void *data)
71434 {
71435 struct ftrace_func_probe *entry;
71436 struct ftrace_page *pg;
71437@@ -3697,8 +3702,10 @@ static int ftrace_process_locs(struct module *mod,
71438 if (!count)
71439 return 0;
71440
71441+ pax_open_kernel();
71442 sort(start, count, sizeof(*start),
71443 ftrace_cmp_ips, ftrace_swap_ips);
71444+ pax_close_kernel();
71445
71446 start_pg = ftrace_allocate_pages(count);
71447 if (!start_pg)
71448diff --git a/kernel/trace/trace.c b/kernel/trace/trace.c
71449index 5c38c81..88012af 100644
71450--- a/kernel/trace/trace.c
71451+++ b/kernel/trace/trace.c
71452@@ -4437,10 +4437,9 @@ static const struct file_operations tracing_dyn_info_fops = {
71453 };
71454 #endif
71455
71456-static struct dentry *d_tracer;
71457-
71458 struct dentry *tracing_init_dentry(void)
71459 {
71460+ static struct dentry *d_tracer;
71461 static int once;
71462
71463 if (d_tracer)
71464@@ -4460,10 +4459,9 @@ struct dentry *tracing_init_dentry(void)
71465 return d_tracer;
71466 }
71467
71468-static struct dentry *d_percpu;
71469-
71470 struct dentry *tracing_dentry_percpu(void)
71471 {
71472+ static struct dentry *d_percpu;
71473 static int once;
71474 struct dentry *d_tracer;
71475
71476diff --git a/kernel/trace/trace_events.c b/kernel/trace/trace_events.c
71477index 29111da..d190fe2 100644
71478--- a/kernel/trace/trace_events.c
71479+++ b/kernel/trace/trace_events.c
71480@@ -1308,10 +1308,6 @@ static LIST_HEAD(ftrace_module_file_list);
71481 struct ftrace_module_file_ops {
71482 struct list_head list;
71483 struct module *mod;
71484- struct file_operations id;
71485- struct file_operations enable;
71486- struct file_operations format;
71487- struct file_operations filter;
71488 };
71489
71490 static struct ftrace_module_file_ops *
71491@@ -1332,17 +1328,12 @@ trace_create_file_ops(struct module *mod)
71492
71493 file_ops->mod = mod;
71494
71495- file_ops->id = ftrace_event_id_fops;
71496- file_ops->id.owner = mod;
71497-
71498- file_ops->enable = ftrace_enable_fops;
71499- file_ops->enable.owner = mod;
71500-
71501- file_ops->filter = ftrace_event_filter_fops;
71502- file_ops->filter.owner = mod;
71503-
71504- file_ops->format = ftrace_event_format_fops;
71505- file_ops->format.owner = mod;
71506+ pax_open_kernel();
71507+ *(void **)&mod->trace_id.owner = mod;
71508+ *(void **)&mod->trace_enable.owner = mod;
71509+ *(void **)&mod->trace_filter.owner = mod;
71510+ *(void **)&mod->trace_format.owner = mod;
71511+ pax_close_kernel();
71512
71513 list_add(&file_ops->list, &ftrace_module_file_list);
71514
71515@@ -1366,8 +1357,8 @@ static void trace_module_add_events(struct module *mod)
71516
71517 for_each_event(call, start, end) {
71518 __trace_add_event_call(*call, mod,
71519- &file_ops->id, &file_ops->enable,
71520- &file_ops->filter, &file_ops->format);
71521+ &mod->trace_id, &mod->trace_enable,
71522+ &mod->trace_filter, &mod->trace_format);
71523 }
71524 }
71525
71526diff --git a/kernel/trace/trace_mmiotrace.c b/kernel/trace/trace_mmiotrace.c
71527index fd3c8aa..5f324a6 100644
71528--- a/kernel/trace/trace_mmiotrace.c
71529+++ b/kernel/trace/trace_mmiotrace.c
71530@@ -24,7 +24,7 @@ struct header_iter {
71531 static struct trace_array *mmio_trace_array;
71532 static bool overrun_detected;
71533 static unsigned long prev_overruns;
71534-static atomic_t dropped_count;
71535+static atomic_unchecked_t dropped_count;
71536
71537 static void mmio_reset_data(struct trace_array *tr)
71538 {
71539@@ -127,7 +127,7 @@ static void mmio_close(struct trace_iterator *iter)
71540
71541 static unsigned long count_overruns(struct trace_iterator *iter)
71542 {
71543- unsigned long cnt = atomic_xchg(&dropped_count, 0);
71544+ unsigned long cnt = atomic_xchg_unchecked(&dropped_count, 0);
71545 unsigned long over = ring_buffer_overruns(iter->tr->buffer);
71546
71547 if (over > prev_overruns)
71548@@ -317,7 +317,7 @@ static void __trace_mmiotrace_rw(struct trace_array *tr,
71549 event = trace_buffer_lock_reserve(buffer, TRACE_MMIO_RW,
71550 sizeof(*entry), 0, pc);
71551 if (!event) {
71552- atomic_inc(&dropped_count);
71553+ atomic_inc_unchecked(&dropped_count);
71554 return;
71555 }
71556 entry = ring_buffer_event_data(event);
71557@@ -347,7 +347,7 @@ static void __trace_mmiotrace_map(struct trace_array *tr,
71558 event = trace_buffer_lock_reserve(buffer, TRACE_MMIO_MAP,
71559 sizeof(*entry), 0, pc);
71560 if (!event) {
71561- atomic_inc(&dropped_count);
71562+ atomic_inc_unchecked(&dropped_count);
71563 return;
71564 }
71565 entry = ring_buffer_event_data(event);
71566diff --git a/kernel/trace/trace_output.c b/kernel/trace/trace_output.c
71567index 123b189..97b81f5 100644
71568--- a/kernel/trace/trace_output.c
71569+++ b/kernel/trace/trace_output.c
71570@@ -278,7 +278,7 @@ int trace_seq_path(struct trace_seq *s, const struct path *path)
71571
71572 p = d_path(path, s->buffer + s->len, PAGE_SIZE - s->len);
71573 if (!IS_ERR(p)) {
71574- p = mangle_path(s->buffer + s->len, p, "\n");
71575+ p = mangle_path(s->buffer + s->len, p, "\n\\");
71576 if (p) {
71577 s->len = p - s->buffer;
71578 return 1;
71579diff --git a/kernel/trace/trace_stack.c b/kernel/trace/trace_stack.c
71580index d4545f4..a9010a1 100644
71581--- a/kernel/trace/trace_stack.c
71582+++ b/kernel/trace/trace_stack.c
71583@@ -53,7 +53,7 @@ static inline void check_stack(void)
71584 return;
71585
71586 /* we do not handle interrupt stacks yet */
71587- if (!object_is_on_stack(&this_size))
71588+ if (!object_starts_on_stack(&this_size))
71589 return;
71590
71591 local_irq_save(flags);
71592diff --git a/kernel/workqueue.c b/kernel/workqueue.c
71593index 872bd6d..31601a2 100644
71594--- a/kernel/workqueue.c
71595+++ b/kernel/workqueue.c
71596@@ -1422,7 +1422,7 @@ retry:
71597 /* morph UNBOUND to REBIND atomically */
71598 worker_flags &= ~WORKER_UNBOUND;
71599 worker_flags |= WORKER_REBIND;
71600- ACCESS_ONCE(worker->flags) = worker_flags;
71601+ ACCESS_ONCE_RW(worker->flags) = worker_flags;
71602
71603 idle_rebind.cnt++;
71604 worker->idle_rebind = &idle_rebind;
71605@@ -1448,7 +1448,7 @@ retry:
71606 /* morph UNBOUND to REBIND atomically */
71607 worker_flags &= ~WORKER_UNBOUND;
71608 worker_flags |= WORKER_REBIND;
71609- ACCESS_ONCE(worker->flags) = worker_flags;
71610+ ACCESS_ONCE_RW(worker->flags) = worker_flags;
71611
71612 if (test_and_set_bit(WORK_STRUCT_PENDING_BIT,
71613 work_data_bits(rebind_work)))
71614diff --git a/lib/Kconfig.debug b/lib/Kconfig.debug
71615index 2403a63..5c4be4c 100644
71616--- a/lib/Kconfig.debug
71617+++ b/lib/Kconfig.debug
71618@@ -1252,6 +1252,7 @@ config LATENCYTOP
71619 depends on DEBUG_KERNEL
71620 depends on STACKTRACE_SUPPORT
71621 depends on PROC_FS
71622+ depends on !GRKERNSEC_HIDESYM
71623 select FRAME_POINTER if !MIPS && !PPC && !S390 && !MICROBLAZE && !ARM_UNWIND
71624 select KALLSYMS
71625 select KALLSYMS_ALL
71626@@ -1267,7 +1268,7 @@ source kernel/trace/Kconfig
71627
71628 config PROVIDE_OHCI1394_DMA_INIT
71629 bool "Remote debugging over FireWire early on boot"
71630- depends on PCI && X86
71631+ depends on PCI && X86 && !GRKERNSEC
71632 help
71633 If you want to debug problems which hang or crash the kernel early
71634 on boot and the crashing machine has a FireWire port, you can use
71635@@ -1296,7 +1297,7 @@ config PROVIDE_OHCI1394_DMA_INIT
71636
71637 config FIREWIRE_OHCI_REMOTE_DMA
71638 bool "Remote debugging over FireWire with firewire-ohci"
71639- depends on FIREWIRE_OHCI
71640+ depends on FIREWIRE_OHCI && !GRKERNSEC
71641 help
71642 This option lets you use the FireWire bus for remote debugging
71643 with help of the firewire-ohci driver. It enables unfiltered
71644diff --git a/lib/bitmap.c b/lib/bitmap.c
71645index 06fdfa1..97c5c7d 100644
71646--- a/lib/bitmap.c
71647+++ b/lib/bitmap.c
71648@@ -422,7 +422,7 @@ int __bitmap_parse(const char *buf, unsigned int buflen,
71649 {
71650 int c, old_c, totaldigits, ndigits, nchunks, nbits;
71651 u32 chunk;
71652- const char __user __force *ubuf = (const char __user __force *)buf;
71653+ const char __user *ubuf = (const char __force_user *)buf;
71654
71655 bitmap_zero(maskp, nmaskbits);
71656
71657@@ -507,7 +507,7 @@ int bitmap_parse_user(const char __user *ubuf,
71658 {
71659 if (!access_ok(VERIFY_READ, ubuf, ulen))
71660 return -EFAULT;
71661- return __bitmap_parse((const char __force *)ubuf,
71662+ return __bitmap_parse((const char __force_kernel *)ubuf,
71663 ulen, 1, maskp, nmaskbits);
71664
71665 }
71666@@ -598,7 +598,7 @@ static int __bitmap_parselist(const char *buf, unsigned int buflen,
71667 {
71668 unsigned a, b;
71669 int c, old_c, totaldigits;
71670- const char __user __force *ubuf = (const char __user __force *)buf;
71671+ const char __user *ubuf = (const char __force_user *)buf;
71672 int exp_digit, in_range;
71673
71674 totaldigits = c = 0;
71675@@ -698,7 +698,7 @@ int bitmap_parselist_user(const char __user *ubuf,
71676 {
71677 if (!access_ok(VERIFY_READ, ubuf, ulen))
71678 return -EFAULT;
71679- return __bitmap_parselist((const char __force *)ubuf,
71680+ return __bitmap_parselist((const char __force_kernel *)ubuf,
71681 ulen, 1, maskp, nmaskbits);
71682 }
71683 EXPORT_SYMBOL(bitmap_parselist_user);
71684diff --git a/lib/bug.c b/lib/bug.c
71685index a28c141..2bd3d95 100644
71686--- a/lib/bug.c
71687+++ b/lib/bug.c
71688@@ -133,6 +133,8 @@ enum bug_trap_type report_bug(unsigned long bugaddr, struct pt_regs *regs)
71689 return BUG_TRAP_TYPE_NONE;
71690
71691 bug = find_bug(bugaddr);
71692+ if (!bug)
71693+ return BUG_TRAP_TYPE_NONE;
71694
71695 file = NULL;
71696 line = 0;
71697diff --git a/lib/debugobjects.c b/lib/debugobjects.c
71698index d11808c..dc2d6f8 100644
71699--- a/lib/debugobjects.c
71700+++ b/lib/debugobjects.c
71701@@ -287,7 +287,7 @@ static void debug_object_is_on_stack(void *addr, int onstack)
71702 if (limit > 4)
71703 return;
71704
71705- is_on_stack = object_is_on_stack(addr);
71706+ is_on_stack = object_starts_on_stack(addr);
71707 if (is_on_stack == onstack)
71708 return;
71709
71710diff --git a/lib/devres.c b/lib/devres.c
71711index 80b9c76..9e32279 100644
71712--- a/lib/devres.c
71713+++ b/lib/devres.c
71714@@ -80,7 +80,7 @@ EXPORT_SYMBOL(devm_ioremap_nocache);
71715 void devm_iounmap(struct device *dev, void __iomem *addr)
71716 {
71717 WARN_ON(devres_destroy(dev, devm_ioremap_release, devm_ioremap_match,
71718- (void *)addr));
71719+ (void __force *)addr));
71720 iounmap(addr);
71721 }
71722 EXPORT_SYMBOL(devm_iounmap);
71723@@ -192,7 +192,7 @@ void devm_ioport_unmap(struct device *dev, void __iomem *addr)
71724 {
71725 ioport_unmap(addr);
71726 WARN_ON(devres_destroy(dev, devm_ioport_map_release,
71727- devm_ioport_map_match, (void *)addr));
71728+ devm_ioport_map_match, (void __force *)addr));
71729 }
71730 EXPORT_SYMBOL(devm_ioport_unmap);
71731
71732diff --git a/lib/dma-debug.c b/lib/dma-debug.c
71733index 66ce414..6f0a0dd 100644
71734--- a/lib/dma-debug.c
71735+++ b/lib/dma-debug.c
71736@@ -924,7 +924,7 @@ out:
71737
71738 static void check_for_stack(struct device *dev, void *addr)
71739 {
71740- if (object_is_on_stack(addr))
71741+ if (object_starts_on_stack(addr))
71742 err_printk(dev, NULL, "DMA-API: device driver maps memory from"
71743 "stack [addr=%p]\n", addr);
71744 }
71745diff --git a/lib/inflate.c b/lib/inflate.c
71746index 013a761..c28f3fc 100644
71747--- a/lib/inflate.c
71748+++ b/lib/inflate.c
71749@@ -269,7 +269,7 @@ static void free(void *where)
71750 malloc_ptr = free_mem_ptr;
71751 }
71752 #else
71753-#define malloc(a) kmalloc(a, GFP_KERNEL)
71754+#define malloc(a) kmalloc((a), GFP_KERNEL)
71755 #define free(a) kfree(a)
71756 #endif
71757
71758diff --git a/lib/ioremap.c b/lib/ioremap.c
71759index 0c9216c..863bd89 100644
71760--- a/lib/ioremap.c
71761+++ b/lib/ioremap.c
71762@@ -38,7 +38,7 @@ static inline int ioremap_pmd_range(pud_t *pud, unsigned long addr,
71763 unsigned long next;
71764
71765 phys_addr -= addr;
71766- pmd = pmd_alloc(&init_mm, pud, addr);
71767+ pmd = pmd_alloc_kernel(&init_mm, pud, addr);
71768 if (!pmd)
71769 return -ENOMEM;
71770 do {
71771@@ -56,7 +56,7 @@ static inline int ioremap_pud_range(pgd_t *pgd, unsigned long addr,
71772 unsigned long next;
71773
71774 phys_addr -= addr;
71775- pud = pud_alloc(&init_mm, pgd, addr);
71776+ pud = pud_alloc_kernel(&init_mm, pgd, addr);
71777 if (!pud)
71778 return -ENOMEM;
71779 do {
71780diff --git a/lib/is_single_threaded.c b/lib/is_single_threaded.c
71781index bd2bea9..6b3c95e 100644
71782--- a/lib/is_single_threaded.c
71783+++ b/lib/is_single_threaded.c
71784@@ -22,6 +22,9 @@ bool current_is_single_threaded(void)
71785 struct task_struct *p, *t;
71786 bool ret;
71787
71788+ if (!mm)
71789+ return true;
71790+
71791 if (atomic_read(&task->signal->live) != 1)
71792 return false;
71793
71794diff --git a/lib/list_debug.c b/lib/list_debug.c
71795index c24c2f7..bef49ee 100644
71796--- a/lib/list_debug.c
71797+++ b/lib/list_debug.c
71798@@ -23,17 +23,19 @@ void __list_add(struct list_head *new,
71799 struct list_head *prev,
71800 struct list_head *next)
71801 {
71802- WARN(next->prev != prev,
71803+ if (WARN(next->prev != prev,
71804 "list_add corruption. next->prev should be "
71805 "prev (%p), but was %p. (next=%p).\n",
71806- prev, next->prev, next);
71807- WARN(prev->next != next,
71808+ prev, next->prev, next) ||
71809+ WARN(prev->next != next,
71810 "list_add corruption. prev->next should be "
71811 "next (%p), but was %p. (prev=%p).\n",
71812- next, prev->next, prev);
71813- WARN(new == prev || new == next,
71814+ next, prev->next, prev) ||
71815+ WARN(new == prev || new == next,
71816 "list_add double add: new=%p, prev=%p, next=%p.\n",
71817- new, prev, next);
71818+ new, prev, next))
71819+ return;
71820+
71821 next->prev = new;
71822 new->next = next;
71823 new->prev = prev;
71824@@ -86,12 +88,14 @@ EXPORT_SYMBOL(list_del);
71825 void __list_add_rcu(struct list_head *new,
71826 struct list_head *prev, struct list_head *next)
71827 {
71828- WARN(next->prev != prev,
71829+ if (WARN(next->prev != prev,
71830 "list_add_rcu corruption. next->prev should be prev (%p), but was %p. (next=%p).\n",
71831- prev, next->prev, next);
71832- WARN(prev->next != next,
71833+ prev, next->prev, next) ||
71834+ WARN(prev->next != next,
71835 "list_add_rcu corruption. prev->next should be next (%p), but was %p. (prev=%p).\n",
71836- next, prev->next, prev);
71837+ next, prev->next, prev))
71838+ return;
71839+
71840 new->next = next;
71841 new->prev = prev;
71842 rcu_assign_pointer(list_next_rcu(prev), new);
71843diff --git a/lib/radix-tree.c b/lib/radix-tree.c
71844index e796429..6e38f9f 100644
71845--- a/lib/radix-tree.c
71846+++ b/lib/radix-tree.c
71847@@ -92,7 +92,7 @@ struct radix_tree_preload {
71848 int nr;
71849 struct radix_tree_node *nodes[RADIX_TREE_PRELOAD_SIZE];
71850 };
71851-static DEFINE_PER_CPU(struct radix_tree_preload, radix_tree_preloads) = { 0, };
71852+static DEFINE_PER_CPU(struct radix_tree_preload, radix_tree_preloads);
71853
71854 static inline void *ptr_to_indirect(void *ptr)
71855 {
71856diff --git a/lib/strncpy_from_user.c b/lib/strncpy_from_user.c
71857index bb2b201..46abaf9 100644
71858--- a/lib/strncpy_from_user.c
71859+++ b/lib/strncpy_from_user.c
71860@@ -21,7 +21,7 @@
71861 */
71862 static inline long do_strncpy_from_user(char *dst, const char __user *src, long count, unsigned long max)
71863 {
71864- const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
71865+ static const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
71866 long res = 0;
71867
71868 /*
71869diff --git a/lib/strnlen_user.c b/lib/strnlen_user.c
71870index a28df52..3d55877 100644
71871--- a/lib/strnlen_user.c
71872+++ b/lib/strnlen_user.c
71873@@ -26,7 +26,7 @@
71874 */
71875 static inline long do_strnlen_user(const char __user *src, unsigned long count, unsigned long max)
71876 {
71877- const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
71878+ static const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
71879 long align, res = 0;
71880 unsigned long c;
71881
71882diff --git a/lib/vsprintf.c b/lib/vsprintf.c
71883index 0e33754..50a0e63 100644
71884--- a/lib/vsprintf.c
71885+++ b/lib/vsprintf.c
71886@@ -16,6 +16,9 @@
71887 * - scnprintf and vscnprintf
71888 */
71889
71890+#ifdef CONFIG_GRKERNSEC_HIDESYM
71891+#define __INCLUDED_BY_HIDESYM 1
71892+#endif
71893 #include <stdarg.h>
71894 #include <linux/module.h> /* for KSYM_SYMBOL_LEN */
71895 #include <linux/types.h>
71896@@ -536,7 +539,7 @@ char *symbol_string(char *buf, char *end, void *ptr,
71897 char sym[KSYM_SYMBOL_LEN];
71898 if (ext == 'B')
71899 sprint_backtrace(sym, value);
71900- else if (ext != 'f' && ext != 's')
71901+ else if (ext != 'f' && ext != 's' && ext != 'a')
71902 sprint_symbol(sym, value);
71903 else
71904 sprint_symbol_no_offset(sym, value);
71905@@ -969,7 +972,11 @@ char *netdev_feature_string(char *buf, char *end, const u8 *addr,
71906 return number(buf, end, *(const netdev_features_t *)addr, spec);
71907 }
71908
71909+#ifdef CONFIG_GRKERNSEC_HIDESYM
71910+int kptr_restrict __read_mostly = 2;
71911+#else
71912 int kptr_restrict __read_mostly;
71913+#endif
71914
71915 /*
71916 * Show a '%p' thing. A kernel extension is that the '%p' is followed
71917@@ -983,6 +990,8 @@ int kptr_restrict __read_mostly;
71918 * - 'S' For symbolic direct pointers with offset
71919 * - 's' For symbolic direct pointers without offset
71920 * - 'B' For backtraced symbolic direct pointers with offset
71921+ * - 'A' For symbolic direct pointers with offset approved for use with GRKERNSEC_HIDESYM
71922+ * - 'a' For symbolic direct pointers without offset approved for use with GRKERNSEC_HIDESYM
71923 * - 'R' For decoded struct resource, e.g., [mem 0x0-0x1f 64bit pref]
71924 * - 'r' For raw struct resource, e.g., [mem 0x0-0x1f flags 0x201]
71925 * - 'M' For a 6-byte MAC address, it prints the address in the
71926@@ -1038,12 +1047,12 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
71927
71928 if (!ptr && *fmt != 'K') {
71929 /*
71930- * Print (null) with the same width as a pointer so it makes
71931+ * Print (nil) with the same width as a pointer so it makes
71932 * tabular output look nice.
71933 */
71934 if (spec.field_width == -1)
71935 spec.field_width = default_width;
71936- return string(buf, end, "(null)", spec);
71937+ return string(buf, end, "(nil)", spec);
71938 }
71939
71940 switch (*fmt) {
71941@@ -1053,6 +1062,13 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
71942 /* Fallthrough */
71943 case 'S':
71944 case 's':
71945+#ifdef CONFIG_GRKERNSEC_HIDESYM
71946+ break;
71947+#else
71948+ return symbol_string(buf, end, ptr, spec, *fmt);
71949+#endif
71950+ case 'A':
71951+ case 'a':
71952 case 'B':
71953 return symbol_string(buf, end, ptr, spec, *fmt);
71954 case 'R':
71955@@ -1093,6 +1109,8 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
71956 va_end(va);
71957 return buf;
71958 }
71959+ case 'P':
71960+ break;
71961 case 'K':
71962 /*
71963 * %pK cannot be used in IRQ context because its test
71964@@ -1116,6 +1134,21 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
71965 }
71966 break;
71967 }
71968+
71969+#ifdef CONFIG_GRKERNSEC_HIDESYM
71970+ /* 'P' = approved pointers to copy to userland,
71971+ as in the /proc/kallsyms case, as we make it display nothing
71972+ for non-root users, and the real contents for root users
71973+ Also ignore 'K' pointers, since we force their NULLing for non-root users
71974+ above
71975+ */
71976+ if (ptr > TASK_SIZE && *fmt != 'P' && *fmt != 'K' && is_usercopy_object(buf)) {
71977+ printk(KERN_ALERT "grsec: kernel infoleak detected! Please report this log to spender@grsecurity.net.\n");
71978+ dump_stack();
71979+ ptr = NULL;
71980+ }
71981+#endif
71982+
71983 spec.flags |= SMALL;
71984 if (spec.field_width == -1) {
71985 spec.field_width = default_width;
71986@@ -1831,11 +1864,11 @@ int bstr_printf(char *buf, size_t size, const char *fmt, const u32 *bin_buf)
71987 typeof(type) value; \
71988 if (sizeof(type) == 8) { \
71989 args = PTR_ALIGN(args, sizeof(u32)); \
71990- *(u32 *)&value = *(u32 *)args; \
71991- *((u32 *)&value + 1) = *(u32 *)(args + 4); \
71992+ *(u32 *)&value = *(const u32 *)args; \
71993+ *((u32 *)&value + 1) = *(const u32 *)(args + 4); \
71994 } else { \
71995 args = PTR_ALIGN(args, sizeof(type)); \
71996- value = *(typeof(type) *)args; \
71997+ value = *(const typeof(type) *)args; \
71998 } \
71999 args += sizeof(type); \
72000 value; \
72001@@ -1898,7 +1931,7 @@ int bstr_printf(char *buf, size_t size, const char *fmt, const u32 *bin_buf)
72002 case FORMAT_TYPE_STR: {
72003 const char *str_arg = args;
72004 args += strlen(str_arg) + 1;
72005- str = string(str, end, (char *)str_arg, spec);
72006+ str = string(str, end, str_arg, spec);
72007 break;
72008 }
72009
72010diff --git a/localversion-grsec b/localversion-grsec
72011new file mode 100644
72012index 0000000..7cd6065
72013--- /dev/null
72014+++ b/localversion-grsec
72015@@ -0,0 +1 @@
72016+-grsec
72017diff --git a/mm/Kconfig b/mm/Kconfig
72018index d5c8019..f513038 100644
72019--- a/mm/Kconfig
72020+++ b/mm/Kconfig
72021@@ -251,10 +251,10 @@ config KSM
72022 root has set /sys/kernel/mm/ksm/run to 1 (if CONFIG_SYSFS is set).
72023
72024 config DEFAULT_MMAP_MIN_ADDR
72025- int "Low address space to protect from user allocation"
72026+ int "Low address space to protect from user allocation"
72027 depends on MMU
72028- default 4096
72029- help
72030+ default 65536
72031+ help
72032 This is the portion of low virtual memory which should be protected
72033 from userspace allocation. Keeping a user from writing to low pages
72034 can help reduce the impact of kernel NULL pointer bugs.
72035@@ -285,7 +285,7 @@ config MEMORY_FAILURE
72036
72037 config HWPOISON_INJECT
72038 tristate "HWPoison pages injector"
72039- depends on MEMORY_FAILURE && DEBUG_KERNEL && PROC_FS
72040+ depends on MEMORY_FAILURE && DEBUG_KERNEL && PROC_FS && !GRKERNSEC
72041 select PROC_PAGE_MONITOR
72042
72043 config NOMMU_INITIAL_TRIM_EXCESS
72044diff --git a/mm/filemap.c b/mm/filemap.c
72045index 3843445..4fe6833 100644
72046--- a/mm/filemap.c
72047+++ b/mm/filemap.c
72048@@ -1746,7 +1746,7 @@ int generic_file_mmap(struct file * file, struct vm_area_struct * vma)
72049 struct address_space *mapping = file->f_mapping;
72050
72051 if (!mapping->a_ops->readpage)
72052- return -ENOEXEC;
72053+ return -ENODEV;
72054 file_accessed(file);
72055 vma->vm_ops = &generic_file_vm_ops;
72056 vma->vm_flags |= VM_CAN_NONLINEAR;
72057@@ -2087,6 +2087,7 @@ inline int generic_write_checks(struct file *file, loff_t *pos, size_t *count, i
72058 *pos = i_size_read(inode);
72059
72060 if (limit != RLIM_INFINITY) {
72061+ gr_learn_resource(current, RLIMIT_FSIZE,*pos, 0);
72062 if (*pos >= limit) {
72063 send_sig(SIGXFSZ, current, 0);
72064 return -EFBIG;
72065diff --git a/mm/fremap.c b/mm/fremap.c
72066index 9ed4fd4..c42648d 100644
72067--- a/mm/fremap.c
72068+++ b/mm/fremap.c
72069@@ -155,6 +155,11 @@ SYSCALL_DEFINE5(remap_file_pages, unsigned long, start, unsigned long, size,
72070 retry:
72071 vma = find_vma(mm, start);
72072
72073+#ifdef CONFIG_PAX_SEGMEXEC
72074+ if (vma && (mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_flags & VM_MAYEXEC))
72075+ goto out;
72076+#endif
72077+
72078 /*
72079 * Make sure the vma is shared, that it supports prefaulting,
72080 * and that the remapped range is valid and fully within
72081diff --git a/mm/highmem.c b/mm/highmem.c
72082index d517cd1..9568fec 100644
72083--- a/mm/highmem.c
72084+++ b/mm/highmem.c
72085@@ -98,7 +98,7 @@ struct page *kmap_to_page(void *vaddr)
72086 {
72087 unsigned long addr = (unsigned long)vaddr;
72088
72089- if (addr >= PKMAP_ADDR(0) && addr <= PKMAP_ADDR(LAST_PKMAP)) {
72090+ if (addr >= PKMAP_ADDR(0) && addr < PKMAP_ADDR(LAST_PKMAP)) {
72091 int i = (addr - PKMAP_ADDR(0)) >> PAGE_SHIFT;
72092 return pte_page(pkmap_page_table[i]);
72093 }
72094@@ -137,9 +137,10 @@ static void flush_all_zero_pkmaps(void)
72095 * So no dangers, even with speculative execution.
72096 */
72097 page = pte_page(pkmap_page_table[i]);
72098+ pax_open_kernel();
72099 pte_clear(&init_mm, (unsigned long)page_address(page),
72100 &pkmap_page_table[i]);
72101-
72102+ pax_close_kernel();
72103 set_page_address(page, NULL);
72104 need_flush = 1;
72105 }
72106@@ -198,9 +199,11 @@ start:
72107 }
72108 }
72109 vaddr = PKMAP_ADDR(last_pkmap_nr);
72110+
72111+ pax_open_kernel();
72112 set_pte_at(&init_mm, vaddr,
72113 &(pkmap_page_table[last_pkmap_nr]), mk_pte(page, kmap_prot));
72114-
72115+ pax_close_kernel();
72116 pkmap_count[last_pkmap_nr] = 1;
72117 set_page_address(page, (void *)vaddr);
72118
72119diff --git a/mm/huge_memory.c b/mm/huge_memory.c
72120index 141dbb6..ebff057 100644
72121--- a/mm/huge_memory.c
72122+++ b/mm/huge_memory.c
72123@@ -735,7 +735,7 @@ out:
72124 * run pte_offset_map on the pmd, if an huge pmd could
72125 * materialize from under us from a different thread.
72126 */
72127- if (unlikely(__pte_alloc(mm, vma, pmd, address)))
72128+ if (unlikely(pmd_none(*pmd) && __pte_alloc(mm, vma, pmd, address)))
72129 return VM_FAULT_OOM;
72130 /* if an huge pmd materialized from under us just retry later */
72131 if (unlikely(pmd_trans_huge(*pmd)))
72132diff --git a/mm/hugetlb.c b/mm/hugetlb.c
72133index 3adceaf..dccfea3 100644
72134--- a/mm/hugetlb.c
72135+++ b/mm/hugetlb.c
72136@@ -2512,6 +2512,27 @@ static int unmap_ref_private(struct mm_struct *mm, struct vm_area_struct *vma,
72137 return 1;
72138 }
72139
72140+#ifdef CONFIG_PAX_SEGMEXEC
72141+static void pax_mirror_huge_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m)
72142+{
72143+ struct mm_struct *mm = vma->vm_mm;
72144+ struct vm_area_struct *vma_m;
72145+ unsigned long address_m;
72146+ pte_t *ptep_m;
72147+
72148+ vma_m = pax_find_mirror_vma(vma);
72149+ if (!vma_m)
72150+ return;
72151+
72152+ BUG_ON(address >= SEGMEXEC_TASK_SIZE);
72153+ address_m = address + SEGMEXEC_TASK_SIZE;
72154+ ptep_m = huge_pte_offset(mm, address_m & HPAGE_MASK);
72155+ get_page(page_m);
72156+ hugepage_add_anon_rmap(page_m, vma_m, address_m);
72157+ set_huge_pte_at(mm, address_m, ptep_m, make_huge_pte(vma_m, page_m, 0));
72158+}
72159+#endif
72160+
72161 /*
72162 * Hugetlb_cow() should be called with page lock of the original hugepage held.
72163 * Called with hugetlb_instantiation_mutex held and pte_page locked so we
72164@@ -2628,6 +2649,11 @@ retry_avoidcopy:
72165 make_huge_pte(vma, new_page, 1));
72166 page_remove_rmap(old_page);
72167 hugepage_add_new_anon_rmap(new_page, vma, address);
72168+
72169+#ifdef CONFIG_PAX_SEGMEXEC
72170+ pax_mirror_huge_pte(vma, address, new_page);
72171+#endif
72172+
72173 /* Make the old page be freed below */
72174 new_page = old_page;
72175 mmu_notifier_invalidate_range_end(mm,
72176@@ -2786,6 +2812,10 @@ retry:
72177 && (vma->vm_flags & VM_SHARED)));
72178 set_huge_pte_at(mm, address, ptep, new_pte);
72179
72180+#ifdef CONFIG_PAX_SEGMEXEC
72181+ pax_mirror_huge_pte(vma, address, page);
72182+#endif
72183+
72184 if ((flags & FAULT_FLAG_WRITE) && !(vma->vm_flags & VM_SHARED)) {
72185 /* Optimization, do the COW without a second fault */
72186 ret = hugetlb_cow(mm, vma, address, ptep, new_pte, page);
72187@@ -2815,6 +2845,10 @@ int hugetlb_fault(struct mm_struct *mm, struct vm_area_struct *vma,
72188 static DEFINE_MUTEX(hugetlb_instantiation_mutex);
72189 struct hstate *h = hstate_vma(vma);
72190
72191+#ifdef CONFIG_PAX_SEGMEXEC
72192+ struct vm_area_struct *vma_m;
72193+#endif
72194+
72195 address &= huge_page_mask(h);
72196
72197 ptep = huge_pte_offset(mm, address);
72198@@ -2828,6 +2862,26 @@ int hugetlb_fault(struct mm_struct *mm, struct vm_area_struct *vma,
72199 VM_FAULT_SET_HINDEX(hstate_index(h));
72200 }
72201
72202+#ifdef CONFIG_PAX_SEGMEXEC
72203+ vma_m = pax_find_mirror_vma(vma);
72204+ if (vma_m) {
72205+ unsigned long address_m;
72206+
72207+ if (vma->vm_start > vma_m->vm_start) {
72208+ address_m = address;
72209+ address -= SEGMEXEC_TASK_SIZE;
72210+ vma = vma_m;
72211+ h = hstate_vma(vma);
72212+ } else
72213+ address_m = address + SEGMEXEC_TASK_SIZE;
72214+
72215+ if (!huge_pte_alloc(mm, address_m, huge_page_size(h)))
72216+ return VM_FAULT_OOM;
72217+ address_m &= HPAGE_MASK;
72218+ unmap_hugepage_range(vma, address_m, address_m + HPAGE_SIZE, NULL);
72219+ }
72220+#endif
72221+
72222 ptep = huge_pte_alloc(mm, address, huge_page_size(h));
72223 if (!ptep)
72224 return VM_FAULT_OOM;
72225diff --git a/mm/internal.h b/mm/internal.h
72226index b8c91b3..93e95a3 100644
72227--- a/mm/internal.h
72228+++ b/mm/internal.h
72229@@ -95,6 +95,7 @@ extern void putback_lru_page(struct page *page);
72230 * in mm/page_alloc.c
72231 */
72232 extern void __free_pages_bootmem(struct page *page, unsigned int order);
72233+extern void free_compound_page(struct page *page);
72234 extern void prep_compound_page(struct page *page, unsigned long order);
72235 #ifdef CONFIG_MEMORY_FAILURE
72236 extern bool is_free_buddy_page(struct page *page);
72237diff --git a/mm/kmemleak.c b/mm/kmemleak.c
72238index 45eb621..6ccd8ea 100644
72239--- a/mm/kmemleak.c
72240+++ b/mm/kmemleak.c
72241@@ -363,7 +363,7 @@ static void print_unreferenced(struct seq_file *seq,
72242
72243 for (i = 0; i < object->trace_len; i++) {
72244 void *ptr = (void *)object->trace[i];
72245- seq_printf(seq, " [<%p>] %pS\n", ptr, ptr);
72246+ seq_printf(seq, " [<%p>] %pA\n", ptr, ptr);
72247 }
72248 }
72249
72250diff --git a/mm/maccess.c b/mm/maccess.c
72251index d53adf9..03a24bf 100644
72252--- a/mm/maccess.c
72253+++ b/mm/maccess.c
72254@@ -26,7 +26,7 @@ long __probe_kernel_read(void *dst, const void *src, size_t size)
72255 set_fs(KERNEL_DS);
72256 pagefault_disable();
72257 ret = __copy_from_user_inatomic(dst,
72258- (__force const void __user *)src, size);
72259+ (const void __force_user *)src, size);
72260 pagefault_enable();
72261 set_fs(old_fs);
72262
72263@@ -53,7 +53,7 @@ long __probe_kernel_write(void *dst, const void *src, size_t size)
72264
72265 set_fs(KERNEL_DS);
72266 pagefault_disable();
72267- ret = __copy_to_user_inatomic((__force void __user *)dst, src, size);
72268+ ret = __copy_to_user_inatomic((void __force_user *)dst, src, size);
72269 pagefault_enable();
72270 set_fs(old_fs);
72271
72272diff --git a/mm/madvise.c b/mm/madvise.c
72273index 14d260f..b2a80fd 100644
72274--- a/mm/madvise.c
72275+++ b/mm/madvise.c
72276@@ -48,6 +48,10 @@ static long madvise_behavior(struct vm_area_struct * vma,
72277 pgoff_t pgoff;
72278 unsigned long new_flags = vma->vm_flags;
72279
72280+#ifdef CONFIG_PAX_SEGMEXEC
72281+ struct vm_area_struct *vma_m;
72282+#endif
72283+
72284 switch (behavior) {
72285 case MADV_NORMAL:
72286 new_flags = new_flags & ~VM_RAND_READ & ~VM_SEQ_READ;
72287@@ -119,6 +123,13 @@ success:
72288 /*
72289 * vm_flags is protected by the mmap_sem held in write mode.
72290 */
72291+
72292+#ifdef CONFIG_PAX_SEGMEXEC
72293+ vma_m = pax_find_mirror_vma(vma);
72294+ if (vma_m)
72295+ vma_m->vm_flags = new_flags & ~(VM_WRITE | VM_MAYWRITE | VM_ACCOUNT);
72296+#endif
72297+
72298 vma->vm_flags = new_flags;
72299
72300 out:
72301@@ -177,6 +188,11 @@ static long madvise_dontneed(struct vm_area_struct * vma,
72302 struct vm_area_struct ** prev,
72303 unsigned long start, unsigned long end)
72304 {
72305+
72306+#ifdef CONFIG_PAX_SEGMEXEC
72307+ struct vm_area_struct *vma_m;
72308+#endif
72309+
72310 *prev = vma;
72311 if (vma->vm_flags & (VM_LOCKED|VM_HUGETLB|VM_PFNMAP))
72312 return -EINVAL;
72313@@ -189,6 +205,21 @@ static long madvise_dontneed(struct vm_area_struct * vma,
72314 zap_page_range(vma, start, end - start, &details);
72315 } else
72316 zap_page_range(vma, start, end - start, NULL);
72317+
72318+#ifdef CONFIG_PAX_SEGMEXEC
72319+ vma_m = pax_find_mirror_vma(vma);
72320+ if (vma_m) {
72321+ if (unlikely(vma->vm_flags & VM_NONLINEAR)) {
72322+ struct zap_details details = {
72323+ .nonlinear_vma = vma_m,
72324+ .last_index = ULONG_MAX,
72325+ };
72326+ zap_page_range(vma, start + SEGMEXEC_TASK_SIZE, end - start, &details);
72327+ } else
72328+ zap_page_range(vma, start + SEGMEXEC_TASK_SIZE, end - start, NULL);
72329+ }
72330+#endif
72331+
72332 return 0;
72333 }
72334
72335@@ -393,6 +424,16 @@ SYSCALL_DEFINE3(madvise, unsigned long, start, size_t, len_in, int, behavior)
72336 if (end < start)
72337 goto out;
72338
72339+#ifdef CONFIG_PAX_SEGMEXEC
72340+ if (current->mm->pax_flags & MF_PAX_SEGMEXEC) {
72341+ if (end > SEGMEXEC_TASK_SIZE)
72342+ goto out;
72343+ } else
72344+#endif
72345+
72346+ if (end > TASK_SIZE)
72347+ goto out;
72348+
72349 error = 0;
72350 if (end == start)
72351 goto out;
72352diff --git a/mm/memory-failure.c b/mm/memory-failure.c
72353index a6e2141..eaf5aad 100644
72354--- a/mm/memory-failure.c
72355+++ b/mm/memory-failure.c
72356@@ -61,7 +61,7 @@ int sysctl_memory_failure_early_kill __read_mostly = 0;
72357
72358 int sysctl_memory_failure_recovery __read_mostly = 1;
72359
72360-atomic_long_t mce_bad_pages __read_mostly = ATOMIC_LONG_INIT(0);
72361+atomic_long_unchecked_t mce_bad_pages __read_mostly = ATOMIC_LONG_INIT(0);
72362
72363 #if defined(CONFIG_HWPOISON_INJECT) || defined(CONFIG_HWPOISON_INJECT_MODULE)
72364
72365@@ -202,7 +202,7 @@ static int kill_proc(struct task_struct *t, unsigned long addr, int trapno,
72366 pfn, t->comm, t->pid);
72367 si.si_signo = SIGBUS;
72368 si.si_errno = 0;
72369- si.si_addr = (void *)addr;
72370+ si.si_addr = (void __user *)addr;
72371 #ifdef __ARCH_SI_TRAPNO
72372 si.si_trapno = trapno;
72373 #endif
72374@@ -1038,7 +1038,7 @@ int memory_failure(unsigned long pfn, int trapno, int flags)
72375 }
72376
72377 nr_pages = 1 << compound_trans_order(hpage);
72378- atomic_long_add(nr_pages, &mce_bad_pages);
72379+ atomic_long_add_unchecked(nr_pages, &mce_bad_pages);
72380
72381 /*
72382 * We need/can do nothing about count=0 pages.
72383@@ -1068,7 +1068,7 @@ int memory_failure(unsigned long pfn, int trapno, int flags)
72384 if (!PageHWPoison(hpage)
72385 || (hwpoison_filter(p) && TestClearPageHWPoison(p))
72386 || (p != hpage && TestSetPageHWPoison(hpage))) {
72387- atomic_long_sub(nr_pages, &mce_bad_pages);
72388+ atomic_long_sub_unchecked(nr_pages, &mce_bad_pages);
72389 return 0;
72390 }
72391 set_page_hwpoison_huge_page(hpage);
72392@@ -1126,7 +1126,7 @@ int memory_failure(unsigned long pfn, int trapno, int flags)
72393 }
72394 if (hwpoison_filter(p)) {
72395 if (TestClearPageHWPoison(p))
72396- atomic_long_sub(nr_pages, &mce_bad_pages);
72397+ atomic_long_sub_unchecked(nr_pages, &mce_bad_pages);
72398 unlock_page(hpage);
72399 put_page(hpage);
72400 return 0;
72401@@ -1321,7 +1321,7 @@ int unpoison_memory(unsigned long pfn)
72402 return 0;
72403 }
72404 if (TestClearPageHWPoison(p))
72405- atomic_long_sub(nr_pages, &mce_bad_pages);
72406+ atomic_long_sub_unchecked(nr_pages, &mce_bad_pages);
72407 pr_info("MCE: Software-unpoisoned free page %#lx\n", pfn);
72408 return 0;
72409 }
72410@@ -1335,7 +1335,7 @@ int unpoison_memory(unsigned long pfn)
72411 */
72412 if (TestClearPageHWPoison(page)) {
72413 pr_info("MCE: Software-unpoisoned page %#lx\n", pfn);
72414- atomic_long_sub(nr_pages, &mce_bad_pages);
72415+ atomic_long_sub_unchecked(nr_pages, &mce_bad_pages);
72416 freeit = 1;
72417 if (PageHuge(page))
72418 clear_page_hwpoison_huge_page(page);
72419@@ -1440,7 +1440,7 @@ static int soft_offline_huge_page(struct page *page, int flags)
72420 }
72421 done:
72422 if (!PageHWPoison(hpage))
72423- atomic_long_add(1 << compound_trans_order(hpage),
72424+ atomic_long_add_unchecked(1 << compound_trans_order(hpage),
72425 &mce_bad_pages);
72426 set_page_hwpoison_huge_page(hpage);
72427 dequeue_hwpoisoned_huge_page(hpage);
72428@@ -1572,7 +1572,7 @@ int soft_offline_page(struct page *page, int flags)
72429 return ret;
72430
72431 done:
72432- atomic_long_add(1, &mce_bad_pages);
72433+ atomic_long_add_unchecked(1, &mce_bad_pages);
72434 SetPageHWPoison(page);
72435 /* keep elevated page count for bad page */
72436 return ret;
72437diff --git a/mm/memory.c b/mm/memory.c
72438index 5736170..8e04800 100644
72439--- a/mm/memory.c
72440+++ b/mm/memory.c
72441@@ -426,6 +426,7 @@ static inline void free_pmd_range(struct mmu_gather *tlb, pud_t *pud,
72442 free_pte_range(tlb, pmd, addr);
72443 } while (pmd++, addr = next, addr != end);
72444
72445+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_PER_CPU_PGD)
72446 start &= PUD_MASK;
72447 if (start < floor)
72448 return;
72449@@ -440,6 +441,8 @@ static inline void free_pmd_range(struct mmu_gather *tlb, pud_t *pud,
72450 pmd = pmd_offset(pud, start);
72451 pud_clear(pud);
72452 pmd_free_tlb(tlb, pmd, start);
72453+#endif
72454+
72455 }
72456
72457 static inline void free_pud_range(struct mmu_gather *tlb, pgd_t *pgd,
72458@@ -459,6 +462,7 @@ static inline void free_pud_range(struct mmu_gather *tlb, pgd_t *pgd,
72459 free_pmd_range(tlb, pud, addr, next, floor, ceiling);
72460 } while (pud++, addr = next, addr != end);
72461
72462+#if !defined(CONFIG_X86_64) || !defined(CONFIG_PAX_PER_CPU_PGD)
72463 start &= PGDIR_MASK;
72464 if (start < floor)
72465 return;
72466@@ -473,6 +477,8 @@ static inline void free_pud_range(struct mmu_gather *tlb, pgd_t *pgd,
72467 pud = pud_offset(pgd, start);
72468 pgd_clear(pgd);
72469 pud_free_tlb(tlb, pud, start);
72470+#endif
72471+
72472 }
72473
72474 /*
72475@@ -1614,12 +1620,6 @@ no_page_table:
72476 return page;
72477 }
72478
72479-static inline int stack_guard_page(struct vm_area_struct *vma, unsigned long addr)
72480-{
72481- return stack_guard_page_start(vma, addr) ||
72482- stack_guard_page_end(vma, addr+PAGE_SIZE);
72483-}
72484-
72485 /**
72486 * __get_user_pages() - pin user pages in memory
72487 * @tsk: task_struct of target task
72488@@ -1692,10 +1692,10 @@ int __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
72489 (VM_MAYREAD | VM_MAYWRITE) : (VM_READ | VM_WRITE);
72490 i = 0;
72491
72492- do {
72493+ while (nr_pages) {
72494 struct vm_area_struct *vma;
72495
72496- vma = find_extend_vma(mm, start);
72497+ vma = find_vma(mm, start);
72498 if (!vma && in_gate_area(mm, start)) {
72499 unsigned long pg = start & PAGE_MASK;
72500 pgd_t *pgd;
72501@@ -1743,7 +1743,7 @@ int __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
72502 goto next_page;
72503 }
72504
72505- if (!vma ||
72506+ if (!vma || start < vma->vm_start ||
72507 (vma->vm_flags & (VM_IO | VM_PFNMAP)) ||
72508 !(vm_flags & vma->vm_flags))
72509 return i ? : -EFAULT;
72510@@ -1770,11 +1770,6 @@ int __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
72511 int ret;
72512 unsigned int fault_flags = 0;
72513
72514- /* For mlock, just skip the stack guard page. */
72515- if (foll_flags & FOLL_MLOCK) {
72516- if (stack_guard_page(vma, start))
72517- goto next_page;
72518- }
72519 if (foll_flags & FOLL_WRITE)
72520 fault_flags |= FAULT_FLAG_WRITE;
72521 if (nonblocking)
72522@@ -1848,7 +1843,7 @@ next_page:
72523 start += PAGE_SIZE;
72524 nr_pages--;
72525 } while (nr_pages && start < vma->vm_end);
72526- } while (nr_pages);
72527+ }
72528 return i;
72529 }
72530 EXPORT_SYMBOL(__get_user_pages);
72531@@ -2055,6 +2050,10 @@ static int insert_page(struct vm_area_struct *vma, unsigned long addr,
72532 page_add_file_rmap(page);
72533 set_pte_at(mm, addr, pte, mk_pte(page, prot));
72534
72535+#ifdef CONFIG_PAX_SEGMEXEC
72536+ pax_mirror_file_pte(vma, addr, page, ptl);
72537+#endif
72538+
72539 retval = 0;
72540 pte_unmap_unlock(pte, ptl);
72541 return retval;
72542@@ -2089,10 +2088,22 @@ out:
72543 int vm_insert_page(struct vm_area_struct *vma, unsigned long addr,
72544 struct page *page)
72545 {
72546+
72547+#ifdef CONFIG_PAX_SEGMEXEC
72548+ struct vm_area_struct *vma_m;
72549+#endif
72550+
72551 if (addr < vma->vm_start || addr >= vma->vm_end)
72552 return -EFAULT;
72553 if (!page_count(page))
72554 return -EINVAL;
72555+
72556+#ifdef CONFIG_PAX_SEGMEXEC
72557+ vma_m = pax_find_mirror_vma(vma);
72558+ if (vma_m)
72559+ vma_m->vm_flags |= VM_INSERTPAGE;
72560+#endif
72561+
72562 vma->vm_flags |= VM_INSERTPAGE;
72563 return insert_page(vma, addr, page, vma->vm_page_prot);
72564 }
72565@@ -2178,6 +2189,7 @@ int vm_insert_mixed(struct vm_area_struct *vma, unsigned long addr,
72566 unsigned long pfn)
72567 {
72568 BUG_ON(!(vma->vm_flags & VM_MIXEDMAP));
72569+ BUG_ON(vma->vm_mirror);
72570
72571 if (addr < vma->vm_start || addr >= vma->vm_end)
72572 return -EFAULT;
72573@@ -2385,7 +2397,9 @@ static int apply_to_pmd_range(struct mm_struct *mm, pud_t *pud,
72574
72575 BUG_ON(pud_huge(*pud));
72576
72577- pmd = pmd_alloc(mm, pud, addr);
72578+ pmd = (mm == &init_mm) ?
72579+ pmd_alloc_kernel(mm, pud, addr) :
72580+ pmd_alloc(mm, pud, addr);
72581 if (!pmd)
72582 return -ENOMEM;
72583 do {
72584@@ -2405,7 +2419,9 @@ static int apply_to_pud_range(struct mm_struct *mm, pgd_t *pgd,
72585 unsigned long next;
72586 int err;
72587
72588- pud = pud_alloc(mm, pgd, addr);
72589+ pud = (mm == &init_mm) ?
72590+ pud_alloc_kernel(mm, pgd, addr) :
72591+ pud_alloc(mm, pgd, addr);
72592 if (!pud)
72593 return -ENOMEM;
72594 do {
72595@@ -2493,6 +2509,186 @@ static inline void cow_user_page(struct page *dst, struct page *src, unsigned lo
72596 copy_user_highpage(dst, src, va, vma);
72597 }
72598
72599+#ifdef CONFIG_PAX_SEGMEXEC
72600+static void pax_unmap_mirror_pte(struct vm_area_struct *vma, unsigned long address, pmd_t *pmd)
72601+{
72602+ struct mm_struct *mm = vma->vm_mm;
72603+ spinlock_t *ptl;
72604+ pte_t *pte, entry;
72605+
72606+ pte = pte_offset_map_lock(mm, pmd, address, &ptl);
72607+ entry = *pte;
72608+ if (!pte_present(entry)) {
72609+ if (!pte_none(entry)) {
72610+ BUG_ON(pte_file(entry));
72611+ free_swap_and_cache(pte_to_swp_entry(entry));
72612+ pte_clear_not_present_full(mm, address, pte, 0);
72613+ }
72614+ } else {
72615+ struct page *page;
72616+
72617+ flush_cache_page(vma, address, pte_pfn(entry));
72618+ entry = ptep_clear_flush(vma, address, pte);
72619+ BUG_ON(pte_dirty(entry));
72620+ page = vm_normal_page(vma, address, entry);
72621+ if (page) {
72622+ update_hiwater_rss(mm);
72623+ if (PageAnon(page))
72624+ dec_mm_counter_fast(mm, MM_ANONPAGES);
72625+ else
72626+ dec_mm_counter_fast(mm, MM_FILEPAGES);
72627+ page_remove_rmap(page);
72628+ page_cache_release(page);
72629+ }
72630+ }
72631+ pte_unmap_unlock(pte, ptl);
72632+}
72633+
72634+/* PaX: if vma is mirrored, synchronize the mirror's PTE
72635+ *
72636+ * the ptl of the lower mapped page is held on entry and is not released on exit
72637+ * or inside to ensure atomic changes to the PTE states (swapout, mremap, munmap, etc)
72638+ */
72639+static void pax_mirror_anon_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m, spinlock_t *ptl)
72640+{
72641+ struct mm_struct *mm = vma->vm_mm;
72642+ unsigned long address_m;
72643+ spinlock_t *ptl_m;
72644+ struct vm_area_struct *vma_m;
72645+ pmd_t *pmd_m;
72646+ pte_t *pte_m, entry_m;
72647+
72648+ BUG_ON(!page_m || !PageAnon(page_m));
72649+
72650+ vma_m = pax_find_mirror_vma(vma);
72651+ if (!vma_m)
72652+ return;
72653+
72654+ BUG_ON(!PageLocked(page_m));
72655+ BUG_ON(address >= SEGMEXEC_TASK_SIZE);
72656+ address_m = address + SEGMEXEC_TASK_SIZE;
72657+ pmd_m = pmd_offset(pud_offset(pgd_offset(mm, address_m), address_m), address_m);
72658+ pte_m = pte_offset_map(pmd_m, address_m);
72659+ ptl_m = pte_lockptr(mm, pmd_m);
72660+ if (ptl != ptl_m) {
72661+ spin_lock_nested(ptl_m, SINGLE_DEPTH_NESTING);
72662+ if (!pte_none(*pte_m))
72663+ goto out;
72664+ }
72665+
72666+ entry_m = pfn_pte(page_to_pfn(page_m), vma_m->vm_page_prot);
72667+ page_cache_get(page_m);
72668+ page_add_anon_rmap(page_m, vma_m, address_m);
72669+ inc_mm_counter_fast(mm, MM_ANONPAGES);
72670+ set_pte_at(mm, address_m, pte_m, entry_m);
72671+ update_mmu_cache(vma_m, address_m, entry_m);
72672+out:
72673+ if (ptl != ptl_m)
72674+ spin_unlock(ptl_m);
72675+ pte_unmap(pte_m);
72676+ unlock_page(page_m);
72677+}
72678+
72679+void pax_mirror_file_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m, spinlock_t *ptl)
72680+{
72681+ struct mm_struct *mm = vma->vm_mm;
72682+ unsigned long address_m;
72683+ spinlock_t *ptl_m;
72684+ struct vm_area_struct *vma_m;
72685+ pmd_t *pmd_m;
72686+ pte_t *pte_m, entry_m;
72687+
72688+ BUG_ON(!page_m || PageAnon(page_m));
72689+
72690+ vma_m = pax_find_mirror_vma(vma);
72691+ if (!vma_m)
72692+ return;
72693+
72694+ BUG_ON(address >= SEGMEXEC_TASK_SIZE);
72695+ address_m = address + SEGMEXEC_TASK_SIZE;
72696+ pmd_m = pmd_offset(pud_offset(pgd_offset(mm, address_m), address_m), address_m);
72697+ pte_m = pte_offset_map(pmd_m, address_m);
72698+ ptl_m = pte_lockptr(mm, pmd_m);
72699+ if (ptl != ptl_m) {
72700+ spin_lock_nested(ptl_m, SINGLE_DEPTH_NESTING);
72701+ if (!pte_none(*pte_m))
72702+ goto out;
72703+ }
72704+
72705+ entry_m = pfn_pte(page_to_pfn(page_m), vma_m->vm_page_prot);
72706+ page_cache_get(page_m);
72707+ page_add_file_rmap(page_m);
72708+ inc_mm_counter_fast(mm, MM_FILEPAGES);
72709+ set_pte_at(mm, address_m, pte_m, entry_m);
72710+ update_mmu_cache(vma_m, address_m, entry_m);
72711+out:
72712+ if (ptl != ptl_m)
72713+ spin_unlock(ptl_m);
72714+ pte_unmap(pte_m);
72715+}
72716+
72717+static void pax_mirror_pfn_pte(struct vm_area_struct *vma, unsigned long address, unsigned long pfn_m, spinlock_t *ptl)
72718+{
72719+ struct mm_struct *mm = vma->vm_mm;
72720+ unsigned long address_m;
72721+ spinlock_t *ptl_m;
72722+ struct vm_area_struct *vma_m;
72723+ pmd_t *pmd_m;
72724+ pte_t *pte_m, entry_m;
72725+
72726+ vma_m = pax_find_mirror_vma(vma);
72727+ if (!vma_m)
72728+ return;
72729+
72730+ BUG_ON(address >= SEGMEXEC_TASK_SIZE);
72731+ address_m = address + SEGMEXEC_TASK_SIZE;
72732+ pmd_m = pmd_offset(pud_offset(pgd_offset(mm, address_m), address_m), address_m);
72733+ pte_m = pte_offset_map(pmd_m, address_m);
72734+ ptl_m = pte_lockptr(mm, pmd_m);
72735+ if (ptl != ptl_m) {
72736+ spin_lock_nested(ptl_m, SINGLE_DEPTH_NESTING);
72737+ if (!pte_none(*pte_m))
72738+ goto out;
72739+ }
72740+
72741+ entry_m = pfn_pte(pfn_m, vma_m->vm_page_prot);
72742+ set_pte_at(mm, address_m, pte_m, entry_m);
72743+out:
72744+ if (ptl != ptl_m)
72745+ spin_unlock(ptl_m);
72746+ pte_unmap(pte_m);
72747+}
72748+
72749+static void pax_mirror_pte(struct vm_area_struct *vma, unsigned long address, pte_t *pte, pmd_t *pmd, spinlock_t *ptl)
72750+{
72751+ struct page *page_m;
72752+ pte_t entry;
72753+
72754+ if (!(vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC))
72755+ goto out;
72756+
72757+ entry = *pte;
72758+ page_m = vm_normal_page(vma, address, entry);
72759+ if (!page_m)
72760+ pax_mirror_pfn_pte(vma, address, pte_pfn(entry), ptl);
72761+ else if (PageAnon(page_m)) {
72762+ if (pax_find_mirror_vma(vma)) {
72763+ pte_unmap_unlock(pte, ptl);
72764+ lock_page(page_m);
72765+ pte = pte_offset_map_lock(vma->vm_mm, pmd, address, &ptl);
72766+ if (pte_same(entry, *pte))
72767+ pax_mirror_anon_pte(vma, address, page_m, ptl);
72768+ else
72769+ unlock_page(page_m);
72770+ }
72771+ } else
72772+ pax_mirror_file_pte(vma, address, page_m, ptl);
72773+
72774+out:
72775+ pte_unmap_unlock(pte, ptl);
72776+}
72777+#endif
72778+
72779 /*
72780 * This routine handles present pages, when users try to write
72781 * to a shared page. It is done by copying the page to a new address
72782@@ -2703,6 +2899,12 @@ gotten:
72783 */
72784 page_table = pte_offset_map_lock(mm, pmd, address, &ptl);
72785 if (likely(pte_same(*page_table, orig_pte))) {
72786+
72787+#ifdef CONFIG_PAX_SEGMEXEC
72788+ if (pax_find_mirror_vma(vma))
72789+ BUG_ON(!trylock_page(new_page));
72790+#endif
72791+
72792 if (old_page) {
72793 if (!PageAnon(old_page)) {
72794 dec_mm_counter_fast(mm, MM_FILEPAGES);
72795@@ -2754,6 +2956,10 @@ gotten:
72796 page_remove_rmap(old_page);
72797 }
72798
72799+#ifdef CONFIG_PAX_SEGMEXEC
72800+ pax_mirror_anon_pte(vma, address, new_page, ptl);
72801+#endif
72802+
72803 /* Free the old page.. */
72804 new_page = old_page;
72805 ret |= VM_FAULT_WRITE;
72806@@ -3033,6 +3239,11 @@ static int do_swap_page(struct mm_struct *mm, struct vm_area_struct *vma,
72807 swap_free(entry);
72808 if (vm_swap_full() || (vma->vm_flags & VM_LOCKED) || PageMlocked(page))
72809 try_to_free_swap(page);
72810+
72811+#ifdef CONFIG_PAX_SEGMEXEC
72812+ if ((flags & FAULT_FLAG_WRITE) || !pax_find_mirror_vma(vma))
72813+#endif
72814+
72815 unlock_page(page);
72816 if (swapcache) {
72817 /*
72818@@ -3056,6 +3267,11 @@ static int do_swap_page(struct mm_struct *mm, struct vm_area_struct *vma,
72819
72820 /* No need to invalidate - it was non-present before */
72821 update_mmu_cache(vma, address, page_table);
72822+
72823+#ifdef CONFIG_PAX_SEGMEXEC
72824+ pax_mirror_anon_pte(vma, address, page, ptl);
72825+#endif
72826+
72827 unlock:
72828 pte_unmap_unlock(page_table, ptl);
72829 out:
72830@@ -3075,40 +3291,6 @@ out_release:
72831 }
72832
72833 /*
72834- * This is like a special single-page "expand_{down|up}wards()",
72835- * except we must first make sure that 'address{-|+}PAGE_SIZE'
72836- * doesn't hit another vma.
72837- */
72838-static inline int check_stack_guard_page(struct vm_area_struct *vma, unsigned long address)
72839-{
72840- address &= PAGE_MASK;
72841- if ((vma->vm_flags & VM_GROWSDOWN) && address == vma->vm_start) {
72842- struct vm_area_struct *prev = vma->vm_prev;
72843-
72844- /*
72845- * Is there a mapping abutting this one below?
72846- *
72847- * That's only ok if it's the same stack mapping
72848- * that has gotten split..
72849- */
72850- if (prev && prev->vm_end == address)
72851- return prev->vm_flags & VM_GROWSDOWN ? 0 : -ENOMEM;
72852-
72853- expand_downwards(vma, address - PAGE_SIZE);
72854- }
72855- if ((vma->vm_flags & VM_GROWSUP) && address + PAGE_SIZE == vma->vm_end) {
72856- struct vm_area_struct *next = vma->vm_next;
72857-
72858- /* As VM_GROWSDOWN but s/below/above/ */
72859- if (next && next->vm_start == address + PAGE_SIZE)
72860- return next->vm_flags & VM_GROWSUP ? 0 : -ENOMEM;
72861-
72862- expand_upwards(vma, address + PAGE_SIZE);
72863- }
72864- return 0;
72865-}
72866-
72867-/*
72868 * We enter with non-exclusive mmap_sem (to exclude vma changes,
72869 * but allow concurrent faults), and pte mapped but not yet locked.
72870 * We return with mmap_sem still held, but pte unmapped and unlocked.
72871@@ -3117,27 +3299,23 @@ static int do_anonymous_page(struct mm_struct *mm, struct vm_area_struct *vma,
72872 unsigned long address, pte_t *page_table, pmd_t *pmd,
72873 unsigned int flags)
72874 {
72875- struct page *page;
72876+ struct page *page = NULL;
72877 spinlock_t *ptl;
72878 pte_t entry;
72879
72880- pte_unmap(page_table);
72881-
72882- /* Check if we need to add a guard page to the stack */
72883- if (check_stack_guard_page(vma, address) < 0)
72884- return VM_FAULT_SIGBUS;
72885-
72886- /* Use the zero-page for reads */
72887 if (!(flags & FAULT_FLAG_WRITE)) {
72888 entry = pte_mkspecial(pfn_pte(my_zero_pfn(address),
72889 vma->vm_page_prot));
72890- page_table = pte_offset_map_lock(mm, pmd, address, &ptl);
72891+ ptl = pte_lockptr(mm, pmd);
72892+ spin_lock(ptl);
72893 if (!pte_none(*page_table))
72894 goto unlock;
72895 goto setpte;
72896 }
72897
72898 /* Allocate our own private page. */
72899+ pte_unmap(page_table);
72900+
72901 if (unlikely(anon_vma_prepare(vma)))
72902 goto oom;
72903 page = alloc_zeroed_user_highpage_movable(vma, address);
72904@@ -3156,6 +3334,11 @@ static int do_anonymous_page(struct mm_struct *mm, struct vm_area_struct *vma,
72905 if (!pte_none(*page_table))
72906 goto release;
72907
72908+#ifdef CONFIG_PAX_SEGMEXEC
72909+ if (pax_find_mirror_vma(vma))
72910+ BUG_ON(!trylock_page(page));
72911+#endif
72912+
72913 inc_mm_counter_fast(mm, MM_ANONPAGES);
72914 page_add_new_anon_rmap(page, vma, address);
72915 setpte:
72916@@ -3163,6 +3346,12 @@ setpte:
72917
72918 /* No need to invalidate - it was non-present before */
72919 update_mmu_cache(vma, address, page_table);
72920+
72921+#ifdef CONFIG_PAX_SEGMEXEC
72922+ if (page)
72923+ pax_mirror_anon_pte(vma, address, page, ptl);
72924+#endif
72925+
72926 unlock:
72927 pte_unmap_unlock(page_table, ptl);
72928 return 0;
72929@@ -3306,6 +3495,12 @@ static int __do_fault(struct mm_struct *mm, struct vm_area_struct *vma,
72930 */
72931 /* Only go through if we didn't race with anybody else... */
72932 if (likely(pte_same(*page_table, orig_pte))) {
72933+
72934+#ifdef CONFIG_PAX_SEGMEXEC
72935+ if (anon && pax_find_mirror_vma(vma))
72936+ BUG_ON(!trylock_page(page));
72937+#endif
72938+
72939 flush_icache_page(vma, page);
72940 entry = mk_pte(page, vma->vm_page_prot);
72941 if (flags & FAULT_FLAG_WRITE)
72942@@ -3325,6 +3520,14 @@ static int __do_fault(struct mm_struct *mm, struct vm_area_struct *vma,
72943
72944 /* no need to invalidate: a not-present page won't be cached */
72945 update_mmu_cache(vma, address, page_table);
72946+
72947+#ifdef CONFIG_PAX_SEGMEXEC
72948+ if (anon)
72949+ pax_mirror_anon_pte(vma, address, page, ptl);
72950+ else
72951+ pax_mirror_file_pte(vma, address, page, ptl);
72952+#endif
72953+
72954 } else {
72955 if (cow_page)
72956 mem_cgroup_uncharge_page(cow_page);
72957@@ -3479,6 +3682,12 @@ int handle_pte_fault(struct mm_struct *mm,
72958 if (flags & FAULT_FLAG_WRITE)
72959 flush_tlb_fix_spurious_fault(vma, address);
72960 }
72961+
72962+#ifdef CONFIG_PAX_SEGMEXEC
72963+ pax_mirror_pte(vma, address, pte, pmd, ptl);
72964+ return 0;
72965+#endif
72966+
72967 unlock:
72968 pte_unmap_unlock(pte, ptl);
72969 return 0;
72970@@ -3495,6 +3704,10 @@ int handle_mm_fault(struct mm_struct *mm, struct vm_area_struct *vma,
72971 pmd_t *pmd;
72972 pte_t *pte;
72973
72974+#ifdef CONFIG_PAX_SEGMEXEC
72975+ struct vm_area_struct *vma_m;
72976+#endif
72977+
72978 __set_current_state(TASK_RUNNING);
72979
72980 count_vm_event(PGFAULT);
72981@@ -3506,6 +3719,34 @@ int handle_mm_fault(struct mm_struct *mm, struct vm_area_struct *vma,
72982 if (unlikely(is_vm_hugetlb_page(vma)))
72983 return hugetlb_fault(mm, vma, address, flags);
72984
72985+#ifdef CONFIG_PAX_SEGMEXEC
72986+ vma_m = pax_find_mirror_vma(vma);
72987+ if (vma_m) {
72988+ unsigned long address_m;
72989+ pgd_t *pgd_m;
72990+ pud_t *pud_m;
72991+ pmd_t *pmd_m;
72992+
72993+ if (vma->vm_start > vma_m->vm_start) {
72994+ address_m = address;
72995+ address -= SEGMEXEC_TASK_SIZE;
72996+ vma = vma_m;
72997+ } else
72998+ address_m = address + SEGMEXEC_TASK_SIZE;
72999+
73000+ pgd_m = pgd_offset(mm, address_m);
73001+ pud_m = pud_alloc(mm, pgd_m, address_m);
73002+ if (!pud_m)
73003+ return VM_FAULT_OOM;
73004+ pmd_m = pmd_alloc(mm, pud_m, address_m);
73005+ if (!pmd_m)
73006+ return VM_FAULT_OOM;
73007+ if (!pmd_present(*pmd_m) && __pte_alloc(mm, vma_m, pmd_m, address_m))
73008+ return VM_FAULT_OOM;
73009+ pax_unmap_mirror_pte(vma_m, address_m, pmd_m);
73010+ }
73011+#endif
73012+
73013 retry:
73014 pgd = pgd_offset(mm, address);
73015 pud = pud_alloc(mm, pgd, address);
73016@@ -3547,7 +3788,7 @@ retry:
73017 * run pte_offset_map on the pmd, if an huge pmd could
73018 * materialize from under us from a different thread.
73019 */
73020- if (unlikely(pmd_none(*pmd)) && __pte_alloc(mm, vma, pmd, address))
73021+ if (unlikely(pmd_none(*pmd) && __pte_alloc(mm, vma, pmd, address)))
73022 return VM_FAULT_OOM;
73023 /* if an huge pmd materialized from under us just retry later */
73024 if (unlikely(pmd_trans_huge(*pmd)))
73025@@ -3584,6 +3825,23 @@ int __pud_alloc(struct mm_struct *mm, pgd_t *pgd, unsigned long address)
73026 spin_unlock(&mm->page_table_lock);
73027 return 0;
73028 }
73029+
73030+int __pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd, unsigned long address)
73031+{
73032+ pud_t *new = pud_alloc_one(mm, address);
73033+ if (!new)
73034+ return -ENOMEM;
73035+
73036+ smp_wmb(); /* See comment in __pte_alloc */
73037+
73038+ spin_lock(&mm->page_table_lock);
73039+ if (pgd_present(*pgd)) /* Another has populated it */
73040+ pud_free(mm, new);
73041+ else
73042+ pgd_populate_kernel(mm, pgd, new);
73043+ spin_unlock(&mm->page_table_lock);
73044+ return 0;
73045+}
73046 #endif /* __PAGETABLE_PUD_FOLDED */
73047
73048 #ifndef __PAGETABLE_PMD_FOLDED
73049@@ -3614,6 +3872,30 @@ int __pmd_alloc(struct mm_struct *mm, pud_t *pud, unsigned long address)
73050 spin_unlock(&mm->page_table_lock);
73051 return 0;
73052 }
73053+
73054+int __pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud, unsigned long address)
73055+{
73056+ pmd_t *new = pmd_alloc_one(mm, address);
73057+ if (!new)
73058+ return -ENOMEM;
73059+
73060+ smp_wmb(); /* See comment in __pte_alloc */
73061+
73062+ spin_lock(&mm->page_table_lock);
73063+#ifndef __ARCH_HAS_4LEVEL_HACK
73064+ if (pud_present(*pud)) /* Another has populated it */
73065+ pmd_free(mm, new);
73066+ else
73067+ pud_populate_kernel(mm, pud, new);
73068+#else
73069+ if (pgd_present(*pud)) /* Another has populated it */
73070+ pmd_free(mm, new);
73071+ else
73072+ pgd_populate_kernel(mm, pud, new);
73073+#endif /* __ARCH_HAS_4LEVEL_HACK */
73074+ spin_unlock(&mm->page_table_lock);
73075+ return 0;
73076+}
73077 #endif /* __PAGETABLE_PMD_FOLDED */
73078
73079 int make_pages_present(unsigned long addr, unsigned long end)
73080@@ -3651,7 +3933,7 @@ static int __init gate_vma_init(void)
73081 gate_vma.vm_start = FIXADDR_USER_START;
73082 gate_vma.vm_end = FIXADDR_USER_END;
73083 gate_vma.vm_flags = VM_READ | VM_MAYREAD | VM_EXEC | VM_MAYEXEC;
73084- gate_vma.vm_page_prot = __P101;
73085+ gate_vma.vm_page_prot = vm_get_page_prot(gate_vma.vm_flags);
73086
73087 return 0;
73088 }
73089diff --git a/mm/mempolicy.c b/mm/mempolicy.c
73090index 3d64b36..c6ab69c 100644
73091--- a/mm/mempolicy.c
73092+++ b/mm/mempolicy.c
73093@@ -655,6 +655,10 @@ static int mbind_range(struct mm_struct *mm, unsigned long start,
73094 unsigned long vmstart;
73095 unsigned long vmend;
73096
73097+#ifdef CONFIG_PAX_SEGMEXEC
73098+ struct vm_area_struct *vma_m;
73099+#endif
73100+
73101 vma = find_vma(mm, start);
73102 if (!vma || vma->vm_start > start)
73103 return -EFAULT;
73104@@ -691,9 +695,20 @@ static int mbind_range(struct mm_struct *mm, unsigned long start,
73105 if (err)
73106 goto out;
73107 }
73108+
73109 err = vma_replace_policy(vma, new_pol);
73110 if (err)
73111 goto out;
73112+
73113+#ifdef CONFIG_PAX_SEGMEXEC
73114+ vma_m = pax_find_mirror_vma(vma);
73115+ if (vma_m) {
73116+ err = vma_replace_policy(vma_m, new_pol);
73117+ if (err)
73118+ goto out;
73119+ }
73120+#endif
73121+
73122 }
73123
73124 out:
73125@@ -1147,6 +1162,17 @@ static long do_mbind(unsigned long start, unsigned long len,
73126
73127 if (end < start)
73128 return -EINVAL;
73129+
73130+#ifdef CONFIG_PAX_SEGMEXEC
73131+ if (mm->pax_flags & MF_PAX_SEGMEXEC) {
73132+ if (end > SEGMEXEC_TASK_SIZE)
73133+ return -EINVAL;
73134+ } else
73135+#endif
73136+
73137+ if (end > TASK_SIZE)
73138+ return -EINVAL;
73139+
73140 if (end == start)
73141 return 0;
73142
73143@@ -1370,8 +1396,7 @@ SYSCALL_DEFINE4(migrate_pages, pid_t, pid, unsigned long, maxnode,
73144 */
73145 tcred = __task_cred(task);
73146 if (!uid_eq(cred->euid, tcred->suid) && !uid_eq(cred->euid, tcred->uid) &&
73147- !uid_eq(cred->uid, tcred->suid) && !uid_eq(cred->uid, tcred->uid) &&
73148- !capable(CAP_SYS_NICE)) {
73149+ !uid_eq(cred->uid, tcred->suid) && !capable(CAP_SYS_NICE)) {
73150 rcu_read_unlock();
73151 err = -EPERM;
73152 goto out_put;
73153@@ -1402,6 +1427,15 @@ SYSCALL_DEFINE4(migrate_pages, pid_t, pid, unsigned long, maxnode,
73154 goto out;
73155 }
73156
73157+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
73158+ if (mm != current->mm &&
73159+ (mm->pax_flags & MF_PAX_RANDMMAP || mm->pax_flags & MF_PAX_SEGMEXEC)) {
73160+ mmput(mm);
73161+ err = -EPERM;
73162+ goto out;
73163+ }
73164+#endif
73165+
73166 err = do_migrate_pages(mm, old, new,
73167 capable(CAP_SYS_NICE) ? MPOL_MF_MOVE_ALL : MPOL_MF_MOVE);
73168
73169diff --git a/mm/migrate.c b/mm/migrate.c
73170index 77ed2d7..317d528 100644
73171--- a/mm/migrate.c
73172+++ b/mm/migrate.c
73173@@ -1350,8 +1350,7 @@ SYSCALL_DEFINE6(move_pages, pid_t, pid, unsigned long, nr_pages,
73174 */
73175 tcred = __task_cred(task);
73176 if (!uid_eq(cred->euid, tcred->suid) && !uid_eq(cred->euid, tcred->uid) &&
73177- !uid_eq(cred->uid, tcred->suid) && !uid_eq(cred->uid, tcred->uid) &&
73178- !capable(CAP_SYS_NICE)) {
73179+ !uid_eq(cred->uid, tcred->suid) && !capable(CAP_SYS_NICE)) {
73180 rcu_read_unlock();
73181 err = -EPERM;
73182 goto out;
73183diff --git a/mm/mlock.c b/mm/mlock.c
73184index ef726e8..cd7f1ec 100644
73185--- a/mm/mlock.c
73186+++ b/mm/mlock.c
73187@@ -13,6 +13,7 @@
73188 #include <linux/pagemap.h>
73189 #include <linux/mempolicy.h>
73190 #include <linux/syscalls.h>
73191+#include <linux/security.h>
73192 #include <linux/sched.h>
73193 #include <linux/export.h>
73194 #include <linux/rmap.h>
73195@@ -376,7 +377,7 @@ static int do_mlock(unsigned long start, size_t len, int on)
73196 {
73197 unsigned long nstart, end, tmp;
73198 struct vm_area_struct * vma, * prev;
73199- int error;
73200+ int error = 0;
73201
73202 VM_BUG_ON(start & ~PAGE_MASK);
73203 VM_BUG_ON(len != PAGE_ALIGN(len));
73204@@ -385,6 +386,9 @@ static int do_mlock(unsigned long start, size_t len, int on)
73205 return -EINVAL;
73206 if (end == start)
73207 return 0;
73208+ if (end > TASK_SIZE)
73209+ return -EINVAL;
73210+
73211 vma = find_vma(current->mm, start);
73212 if (!vma || vma->vm_start > start)
73213 return -ENOMEM;
73214@@ -396,6 +400,11 @@ static int do_mlock(unsigned long start, size_t len, int on)
73215 for (nstart = start ; ; ) {
73216 vm_flags_t newflags;
73217
73218+#ifdef CONFIG_PAX_SEGMEXEC
73219+ if ((current->mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_start >= SEGMEXEC_TASK_SIZE))
73220+ break;
73221+#endif
73222+
73223 /* Here we know that vma->vm_start <= nstart < vma->vm_end. */
73224
73225 newflags = vma->vm_flags | VM_LOCKED;
73226@@ -501,6 +510,7 @@ SYSCALL_DEFINE2(mlock, unsigned long, start, size_t, len)
73227 lock_limit >>= PAGE_SHIFT;
73228
73229 /* check against resource limits */
73230+ gr_learn_resource(current, RLIMIT_MEMLOCK, (current->mm->locked_vm << PAGE_SHIFT) + len, 1);
73231 if ((locked <= lock_limit) || capable(CAP_IPC_LOCK))
73232 error = do_mlock(start, len, 1);
73233 up_write(&current->mm->mmap_sem);
73234@@ -524,17 +534,23 @@ SYSCALL_DEFINE2(munlock, unsigned long, start, size_t, len)
73235 static int do_mlockall(int flags)
73236 {
73237 struct vm_area_struct * vma, * prev = NULL;
73238- unsigned int def_flags = 0;
73239
73240 if (flags & MCL_FUTURE)
73241- def_flags = VM_LOCKED;
73242- current->mm->def_flags = def_flags;
73243+ current->mm->def_flags |= VM_LOCKED;
73244+ else
73245+ current->mm->def_flags &= ~VM_LOCKED;
73246 if (flags == MCL_FUTURE)
73247 goto out;
73248
73249 for (vma = current->mm->mmap; vma ; vma = prev->vm_next) {
73250 vm_flags_t newflags;
73251
73252+#ifdef CONFIG_PAX_SEGMEXEC
73253+ if ((current->mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_start >= SEGMEXEC_TASK_SIZE))
73254+ break;
73255+#endif
73256+
73257+ BUG_ON(vma->vm_end > TASK_SIZE);
73258 newflags = vma->vm_flags | VM_LOCKED;
73259 if (!(flags & MCL_CURRENT))
73260 newflags &= ~VM_LOCKED;
73261@@ -567,6 +583,7 @@ SYSCALL_DEFINE1(mlockall, int, flags)
73262 lock_limit >>= PAGE_SHIFT;
73263
73264 ret = -ENOMEM;
73265+ gr_learn_resource(current, RLIMIT_MEMLOCK, current->mm->total_vm << PAGE_SHIFT, 1);
73266 if (!(flags & MCL_CURRENT) || (current->mm->total_vm <= lock_limit) ||
73267 capable(CAP_IPC_LOCK))
73268 ret = do_mlockall(flags);
73269diff --git a/mm/mmap.c b/mm/mmap.c
73270index ae18a48..86cf99e 100644
73271--- a/mm/mmap.c
73272+++ b/mm/mmap.c
73273@@ -47,6 +47,16 @@
73274 #define arch_rebalance_pgtables(addr, len) (addr)
73275 #endif
73276
73277+static inline void verify_mm_writelocked(struct mm_struct *mm)
73278+{
73279+#if defined(CONFIG_DEBUG_VM) || defined(CONFIG_PAX)
73280+ if (unlikely(down_read_trylock(&mm->mmap_sem))) {
73281+ up_read(&mm->mmap_sem);
73282+ BUG();
73283+ }
73284+#endif
73285+}
73286+
73287 static void unmap_region(struct mm_struct *mm,
73288 struct vm_area_struct *vma, struct vm_area_struct *prev,
73289 unsigned long start, unsigned long end);
73290@@ -72,22 +82,32 @@ static void unmap_region(struct mm_struct *mm,
73291 * x: (no) no x: (no) yes x: (no) yes x: (yes) yes
73292 *
73293 */
73294-pgprot_t protection_map[16] = {
73295+pgprot_t protection_map[16] __read_only = {
73296 __P000, __P001, __P010, __P011, __P100, __P101, __P110, __P111,
73297 __S000, __S001, __S010, __S011, __S100, __S101, __S110, __S111
73298 };
73299
73300-pgprot_t vm_get_page_prot(unsigned long vm_flags)
73301+pgprot_t vm_get_page_prot(vm_flags_t vm_flags)
73302 {
73303- return __pgprot(pgprot_val(protection_map[vm_flags &
73304+ pgprot_t prot = __pgprot(pgprot_val(protection_map[vm_flags &
73305 (VM_READ|VM_WRITE|VM_EXEC|VM_SHARED)]) |
73306 pgprot_val(arch_vm_get_page_prot(vm_flags)));
73307+
73308+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
73309+ if (!(__supported_pte_mask & _PAGE_NX) &&
73310+ (vm_flags & (VM_PAGEEXEC | VM_EXEC)) == VM_PAGEEXEC &&
73311+ (vm_flags & (VM_READ | VM_WRITE)))
73312+ prot = __pgprot(pte_val(pte_exprotect(__pte(pgprot_val(prot)))));
73313+#endif
73314+
73315+ return prot;
73316 }
73317 EXPORT_SYMBOL(vm_get_page_prot);
73318
73319 int sysctl_overcommit_memory __read_mostly = OVERCOMMIT_GUESS; /* heuristic overcommit */
73320 int sysctl_overcommit_ratio __read_mostly = 50; /* default is 50% */
73321 int sysctl_max_map_count __read_mostly = DEFAULT_MAX_MAP_COUNT;
73322+unsigned long sysctl_heap_stack_gap __read_mostly = 64*1024;
73323 /*
73324 * Make sure vm_committed_as in one cacheline and not cacheline shared with
73325 * other variables. It can be updated by several CPUs frequently.
73326@@ -229,6 +249,7 @@ static struct vm_area_struct *remove_vma(struct vm_area_struct *vma)
73327 struct vm_area_struct *next = vma->vm_next;
73328
73329 might_sleep();
73330+ BUG_ON(vma->vm_mirror);
73331 if (vma->vm_ops && vma->vm_ops->close)
73332 vma->vm_ops->close(vma);
73333 if (vma->vm_file) {
73334@@ -275,6 +296,7 @@ SYSCALL_DEFINE1(brk, unsigned long, brk)
73335 * not page aligned -Ram Gupta
73336 */
73337 rlim = rlimit(RLIMIT_DATA);
73338+ gr_learn_resource(current, RLIMIT_DATA, (brk - mm->start_brk) + (mm->end_data - mm->start_data), 1);
73339 if (rlim < RLIM_INFINITY && (brk - mm->start_brk) +
73340 (mm->end_data - mm->start_data) > rlim)
73341 goto out;
73342@@ -708,6 +730,12 @@ static int
73343 can_vma_merge_before(struct vm_area_struct *vma, unsigned long vm_flags,
73344 struct anon_vma *anon_vma, struct file *file, pgoff_t vm_pgoff)
73345 {
73346+
73347+#ifdef CONFIG_PAX_SEGMEXEC
73348+ if ((vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) && vma->vm_start == SEGMEXEC_TASK_SIZE)
73349+ return 0;
73350+#endif
73351+
73352 if (is_mergeable_vma(vma, file, vm_flags) &&
73353 is_mergeable_anon_vma(anon_vma, vma->anon_vma, vma)) {
73354 if (vma->vm_pgoff == vm_pgoff)
73355@@ -727,6 +755,12 @@ static int
73356 can_vma_merge_after(struct vm_area_struct *vma, unsigned long vm_flags,
73357 struct anon_vma *anon_vma, struct file *file, pgoff_t vm_pgoff)
73358 {
73359+
73360+#ifdef CONFIG_PAX_SEGMEXEC
73361+ if ((vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) && vma->vm_end == SEGMEXEC_TASK_SIZE)
73362+ return 0;
73363+#endif
73364+
73365 if (is_mergeable_vma(vma, file, vm_flags) &&
73366 is_mergeable_anon_vma(anon_vma, vma->anon_vma, vma)) {
73367 pgoff_t vm_pglen;
73368@@ -769,13 +803,20 @@ can_vma_merge_after(struct vm_area_struct *vma, unsigned long vm_flags,
73369 struct vm_area_struct *vma_merge(struct mm_struct *mm,
73370 struct vm_area_struct *prev, unsigned long addr,
73371 unsigned long end, unsigned long vm_flags,
73372- struct anon_vma *anon_vma, struct file *file,
73373+ struct anon_vma *anon_vma, struct file *file,
73374 pgoff_t pgoff, struct mempolicy *policy)
73375 {
73376 pgoff_t pglen = (end - addr) >> PAGE_SHIFT;
73377 struct vm_area_struct *area, *next;
73378 int err;
73379
73380+#ifdef CONFIG_PAX_SEGMEXEC
73381+ unsigned long addr_m = addr + SEGMEXEC_TASK_SIZE, end_m = end + SEGMEXEC_TASK_SIZE;
73382+ struct vm_area_struct *area_m = NULL, *next_m = NULL, *prev_m = NULL;
73383+
73384+ BUG_ON((mm->pax_flags & MF_PAX_SEGMEXEC) && SEGMEXEC_TASK_SIZE < end);
73385+#endif
73386+
73387 /*
73388 * We later require that vma->vm_flags == vm_flags,
73389 * so this tests vma->vm_flags & VM_SPECIAL, too.
73390@@ -791,6 +832,15 @@ struct vm_area_struct *vma_merge(struct mm_struct *mm,
73391 if (next && next->vm_end == end) /* cases 6, 7, 8 */
73392 next = next->vm_next;
73393
73394+#ifdef CONFIG_PAX_SEGMEXEC
73395+ if (prev)
73396+ prev_m = pax_find_mirror_vma(prev);
73397+ if (area)
73398+ area_m = pax_find_mirror_vma(area);
73399+ if (next)
73400+ next_m = pax_find_mirror_vma(next);
73401+#endif
73402+
73403 /*
73404 * Can it merge with the predecessor?
73405 */
73406@@ -810,9 +860,24 @@ struct vm_area_struct *vma_merge(struct mm_struct *mm,
73407 /* cases 1, 6 */
73408 err = vma_adjust(prev, prev->vm_start,
73409 next->vm_end, prev->vm_pgoff, NULL);
73410- } else /* cases 2, 5, 7 */
73411+
73412+#ifdef CONFIG_PAX_SEGMEXEC
73413+ if (!err && prev_m)
73414+ err = vma_adjust(prev_m, prev_m->vm_start,
73415+ next_m->vm_end, prev_m->vm_pgoff, NULL);
73416+#endif
73417+
73418+ } else { /* cases 2, 5, 7 */
73419 err = vma_adjust(prev, prev->vm_start,
73420 end, prev->vm_pgoff, NULL);
73421+
73422+#ifdef CONFIG_PAX_SEGMEXEC
73423+ if (!err && prev_m)
73424+ err = vma_adjust(prev_m, prev_m->vm_start,
73425+ end_m, prev_m->vm_pgoff, NULL);
73426+#endif
73427+
73428+ }
73429 if (err)
73430 return NULL;
73431 khugepaged_enter_vma_merge(prev);
73432@@ -826,12 +891,27 @@ struct vm_area_struct *vma_merge(struct mm_struct *mm,
73433 mpol_equal(policy, vma_policy(next)) &&
73434 can_vma_merge_before(next, vm_flags,
73435 anon_vma, file, pgoff+pglen)) {
73436- if (prev && addr < prev->vm_end) /* case 4 */
73437+ if (prev && addr < prev->vm_end) { /* case 4 */
73438 err = vma_adjust(prev, prev->vm_start,
73439 addr, prev->vm_pgoff, NULL);
73440- else /* cases 3, 8 */
73441+
73442+#ifdef CONFIG_PAX_SEGMEXEC
73443+ if (!err && prev_m)
73444+ err = vma_adjust(prev_m, prev_m->vm_start,
73445+ addr_m, prev_m->vm_pgoff, NULL);
73446+#endif
73447+
73448+ } else { /* cases 3, 8 */
73449 err = vma_adjust(area, addr, next->vm_end,
73450 next->vm_pgoff - pglen, NULL);
73451+
73452+#ifdef CONFIG_PAX_SEGMEXEC
73453+ if (!err && area_m)
73454+ err = vma_adjust(area_m, addr_m, next_m->vm_end,
73455+ next_m->vm_pgoff - pglen, NULL);
73456+#endif
73457+
73458+ }
73459 if (err)
73460 return NULL;
73461 khugepaged_enter_vma_merge(area);
73462@@ -940,16 +1020,13 @@ none:
73463 void vm_stat_account(struct mm_struct *mm, unsigned long flags,
73464 struct file *file, long pages)
73465 {
73466- const unsigned long stack_flags
73467- = VM_STACK_FLAGS & (VM_GROWSUP|VM_GROWSDOWN);
73468-
73469 mm->total_vm += pages;
73470
73471 if (file) {
73472 mm->shared_vm += pages;
73473 if ((flags & (VM_EXEC|VM_WRITE)) == VM_EXEC)
73474 mm->exec_vm += pages;
73475- } else if (flags & stack_flags)
73476+ } else if (flags & (VM_GROWSUP|VM_GROWSDOWN))
73477 mm->stack_vm += pages;
73478 if (flags & (VM_RESERVED|VM_IO))
73479 mm->reserved_vm += pages;
73480@@ -987,7 +1064,7 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
73481 * (the exception is when the underlying filesystem is noexec
73482 * mounted, in which case we dont add PROT_EXEC.)
73483 */
73484- if ((prot & PROT_READ) && (current->personality & READ_IMPLIES_EXEC))
73485+ if ((prot & (PROT_READ | PROT_WRITE)) && (current->personality & READ_IMPLIES_EXEC))
73486 if (!(file && (file->f_path.mnt->mnt_flags & MNT_NOEXEC)))
73487 prot |= PROT_EXEC;
73488
73489@@ -1013,7 +1090,7 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
73490 /* Obtain the address to map to. we verify (or select) it and ensure
73491 * that it represents a valid section of the address space.
73492 */
73493- addr = get_unmapped_area(file, addr, len, pgoff, flags);
73494+ addr = get_unmapped_area(file, addr, len, pgoff, flags | ((prot & PROT_EXEC) ? MAP_EXECUTABLE : 0));
73495 if (addr & ~PAGE_MASK)
73496 return addr;
73497
73498@@ -1024,6 +1101,36 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
73499 vm_flags = calc_vm_prot_bits(prot) | calc_vm_flag_bits(flags) |
73500 mm->def_flags | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC;
73501
73502+#ifdef CONFIG_PAX_MPROTECT
73503+ if (mm->pax_flags & MF_PAX_MPROTECT) {
73504+#ifndef CONFIG_PAX_MPROTECT_COMPAT
73505+ if ((vm_flags & (VM_WRITE | VM_EXEC)) == (VM_WRITE | VM_EXEC)) {
73506+ gr_log_rwxmmap(file);
73507+
73508+#ifdef CONFIG_PAX_EMUPLT
73509+ vm_flags &= ~VM_EXEC;
73510+#else
73511+ return -EPERM;
73512+#endif
73513+
73514+ }
73515+
73516+ if (!(vm_flags & VM_EXEC))
73517+ vm_flags &= ~VM_MAYEXEC;
73518+#else
73519+ if ((vm_flags & (VM_WRITE | VM_EXEC)) != VM_EXEC)
73520+ vm_flags &= ~(VM_EXEC | VM_MAYEXEC);
73521+#endif
73522+ else
73523+ vm_flags &= ~VM_MAYWRITE;
73524+ }
73525+#endif
73526+
73527+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
73528+ if ((mm->pax_flags & MF_PAX_PAGEEXEC) && file)
73529+ vm_flags &= ~VM_PAGEEXEC;
73530+#endif
73531+
73532 if (flags & MAP_LOCKED)
73533 if (!can_do_mlock())
73534 return -EPERM;
73535@@ -1035,6 +1142,7 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
73536 locked += mm->locked_vm;
73537 lock_limit = rlimit(RLIMIT_MEMLOCK);
73538 lock_limit >>= PAGE_SHIFT;
73539+ gr_learn_resource(current, RLIMIT_MEMLOCK, locked << PAGE_SHIFT, 1);
73540 if (locked > lock_limit && !capable(CAP_IPC_LOCK))
73541 return -EAGAIN;
73542 }
73543@@ -1101,6 +1209,9 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
73544 }
73545 }
73546
73547+ if (!gr_acl_handle_mmap(file, prot))
73548+ return -EACCES;
73549+
73550 return mmap_region(file, addr, len, flags, vm_flags, pgoff);
73551 }
73552
73553@@ -1177,7 +1288,7 @@ int vma_wants_writenotify(struct vm_area_struct *vma)
73554 vm_flags_t vm_flags = vma->vm_flags;
73555
73556 /* If it was private or non-writable, the write bit is already clear */
73557- if ((vm_flags & (VM_WRITE|VM_SHARED)) != ((VM_WRITE|VM_SHARED)))
73558+ if ((vm_flags & (VM_WRITE|VM_SHARED)) != (VM_WRITE|VM_SHARED))
73559 return 0;
73560
73561 /* The backer wishes to know when pages are first written to? */
73562@@ -1226,14 +1337,24 @@ unsigned long mmap_region(struct file *file, unsigned long addr,
73563 unsigned long charged = 0;
73564 struct inode *inode = file ? file->f_path.dentry->d_inode : NULL;
73565
73566+#ifdef CONFIG_PAX_SEGMEXEC
73567+ struct vm_area_struct *vma_m = NULL;
73568+#endif
73569+
73570+ /*
73571+ * mm->mmap_sem is required to protect against another thread
73572+ * changing the mappings in case we sleep.
73573+ */
73574+ verify_mm_writelocked(mm);
73575+
73576 /* Clear old maps */
73577 error = -ENOMEM;
73578-munmap_back:
73579 vma = find_vma_prepare(mm, addr, &prev, &rb_link, &rb_parent);
73580 if (vma && vma->vm_start < addr + len) {
73581 if (do_munmap(mm, addr, len))
73582 return -ENOMEM;
73583- goto munmap_back;
73584+ vma = find_vma_prepare(mm, addr, &prev, &rb_link, &rb_parent);
73585+ BUG_ON(vma && vma->vm_start < addr + len);
73586 }
73587
73588 /* Check against address space limit. */
73589@@ -1282,6 +1403,16 @@ munmap_back:
73590 goto unacct_error;
73591 }
73592
73593+#ifdef CONFIG_PAX_SEGMEXEC
73594+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (vm_flags & VM_EXEC)) {
73595+ vma_m = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
73596+ if (!vma_m) {
73597+ error = -ENOMEM;
73598+ goto free_vma;
73599+ }
73600+ }
73601+#endif
73602+
73603 vma->vm_mm = mm;
73604 vma->vm_start = addr;
73605 vma->vm_end = addr + len;
73606@@ -1306,6 +1437,19 @@ munmap_back:
73607 error = file->f_op->mmap(file, vma);
73608 if (error)
73609 goto unmap_and_free_vma;
73610+
73611+#ifdef CONFIG_PAX_SEGMEXEC
73612+ if (vma_m && (vm_flags & VM_EXECUTABLE))
73613+ added_exe_file_vma(mm);
73614+#endif
73615+
73616+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
73617+ if ((mm->pax_flags & MF_PAX_PAGEEXEC) && !(vma->vm_flags & VM_SPECIAL)) {
73618+ vma->vm_flags |= VM_PAGEEXEC;
73619+ vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
73620+ }
73621+#endif
73622+
73623 if (vm_flags & VM_EXECUTABLE)
73624 added_exe_file_vma(mm);
73625
73626@@ -1343,6 +1487,11 @@ munmap_back:
73627 vma_link(mm, vma, prev, rb_link, rb_parent);
73628 file = vma->vm_file;
73629
73630+#ifdef CONFIG_PAX_SEGMEXEC
73631+ if (vma_m)
73632+ BUG_ON(pax_mirror_vma(vma_m, vma));
73633+#endif
73634+
73635 /* Once vma denies write, undo our temporary denial count */
73636 if (correct_wcount)
73637 atomic_inc(&inode->i_writecount);
73638@@ -1350,6 +1499,7 @@ out:
73639 perf_event_mmap(vma);
73640
73641 vm_stat_account(mm, vm_flags, file, len >> PAGE_SHIFT);
73642+ track_exec_limit(mm, addr, addr + len, vm_flags);
73643 if (vm_flags & VM_LOCKED) {
73644 if (!mlock_vma_pages_range(vma, addr, addr + len))
73645 mm->locked_vm += (len >> PAGE_SHIFT);
73646@@ -1371,6 +1521,12 @@ unmap_and_free_vma:
73647 unmap_region(mm, vma, prev, vma->vm_start, vma->vm_end);
73648 charged = 0;
73649 free_vma:
73650+
73651+#ifdef CONFIG_PAX_SEGMEXEC
73652+ if (vma_m)
73653+ kmem_cache_free(vm_area_cachep, vma_m);
73654+#endif
73655+
73656 kmem_cache_free(vm_area_cachep, vma);
73657 unacct_error:
73658 if (charged)
73659@@ -1378,6 +1534,44 @@ unacct_error:
73660 return error;
73661 }
73662
73663+bool check_heap_stack_gap(const struct vm_area_struct *vma, unsigned long addr, unsigned long len)
73664+{
73665+ if (!vma) {
73666+#ifdef CONFIG_STACK_GROWSUP
73667+ if (addr > sysctl_heap_stack_gap)
73668+ vma = find_vma(current->mm, addr - sysctl_heap_stack_gap);
73669+ else
73670+ vma = find_vma(current->mm, 0);
73671+ if (vma && (vma->vm_flags & VM_GROWSUP))
73672+ return false;
73673+#endif
73674+ return true;
73675+ }
73676+
73677+ if (addr + len > vma->vm_start)
73678+ return false;
73679+
73680+ if (vma->vm_flags & VM_GROWSDOWN)
73681+ return sysctl_heap_stack_gap <= vma->vm_start - addr - len;
73682+#ifdef CONFIG_STACK_GROWSUP
73683+ else if (vma->vm_prev && (vma->vm_prev->vm_flags & VM_GROWSUP))
73684+ return addr - vma->vm_prev->vm_end <= sysctl_heap_stack_gap;
73685+#endif
73686+
73687+ return true;
73688+}
73689+
73690+unsigned long skip_heap_stack_gap(const struct vm_area_struct *vma, unsigned long len)
73691+{
73692+ if (vma->vm_start < len)
73693+ return -ENOMEM;
73694+ if (!(vma->vm_flags & VM_GROWSDOWN))
73695+ return vma->vm_start - len;
73696+ if (sysctl_heap_stack_gap <= vma->vm_start - len)
73697+ return vma->vm_start - len - sysctl_heap_stack_gap;
73698+ return -ENOMEM;
73699+}
73700+
73701 /* Get an address range which is currently unmapped.
73702 * For shmat() with addr=0.
73703 *
73704@@ -1404,18 +1598,23 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
73705 if (flags & MAP_FIXED)
73706 return addr;
73707
73708+#ifdef CONFIG_PAX_RANDMMAP
73709+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
73710+#endif
73711+
73712 if (addr) {
73713 addr = PAGE_ALIGN(addr);
73714- vma = find_vma(mm, addr);
73715- if (TASK_SIZE - len >= addr &&
73716- (!vma || addr + len <= vma->vm_start))
73717- return addr;
73718+ if (TASK_SIZE - len >= addr) {
73719+ vma = find_vma(mm, addr);
73720+ if (check_heap_stack_gap(vma, addr, len))
73721+ return addr;
73722+ }
73723 }
73724 if (len > mm->cached_hole_size) {
73725- start_addr = addr = mm->free_area_cache;
73726+ start_addr = addr = mm->free_area_cache;
73727 } else {
73728- start_addr = addr = TASK_UNMAPPED_BASE;
73729- mm->cached_hole_size = 0;
73730+ start_addr = addr = mm->mmap_base;
73731+ mm->cached_hole_size = 0;
73732 }
73733
73734 full_search:
73735@@ -1426,34 +1625,40 @@ full_search:
73736 * Start a new search - just in case we missed
73737 * some holes.
73738 */
73739- if (start_addr != TASK_UNMAPPED_BASE) {
73740- addr = TASK_UNMAPPED_BASE;
73741- start_addr = addr;
73742+ if (start_addr != mm->mmap_base) {
73743+ start_addr = addr = mm->mmap_base;
73744 mm->cached_hole_size = 0;
73745 goto full_search;
73746 }
73747 return -ENOMEM;
73748 }
73749- if (!vma || addr + len <= vma->vm_start) {
73750- /*
73751- * Remember the place where we stopped the search:
73752- */
73753- mm->free_area_cache = addr + len;
73754- return addr;
73755- }
73756+ if (check_heap_stack_gap(vma, addr, len))
73757+ break;
73758 if (addr + mm->cached_hole_size < vma->vm_start)
73759 mm->cached_hole_size = vma->vm_start - addr;
73760 addr = vma->vm_end;
73761 }
73762+
73763+ /*
73764+ * Remember the place where we stopped the search:
73765+ */
73766+ mm->free_area_cache = addr + len;
73767+ return addr;
73768 }
73769 #endif
73770
73771 void arch_unmap_area(struct mm_struct *mm, unsigned long addr)
73772 {
73773+
73774+#ifdef CONFIG_PAX_SEGMEXEC
73775+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && SEGMEXEC_TASK_SIZE <= addr)
73776+ return;
73777+#endif
73778+
73779 /*
73780 * Is this a new hole at the lowest possible address?
73781 */
73782- if (addr >= TASK_UNMAPPED_BASE && addr < mm->free_area_cache)
73783+ if (addr >= mm->mmap_base && addr < mm->free_area_cache)
73784 mm->free_area_cache = addr;
73785 }
73786
73787@@ -1469,7 +1674,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
73788 {
73789 struct vm_area_struct *vma;
73790 struct mm_struct *mm = current->mm;
73791- unsigned long addr = addr0, start_addr;
73792+ unsigned long base = mm->mmap_base, addr = addr0, start_addr;
73793
73794 /* requested length too big for entire address space */
73795 if (len > TASK_SIZE)
73796@@ -1478,13 +1683,18 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
73797 if (flags & MAP_FIXED)
73798 return addr;
73799
73800+#ifdef CONFIG_PAX_RANDMMAP
73801+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
73802+#endif
73803+
73804 /* requesting a specific address */
73805 if (addr) {
73806 addr = PAGE_ALIGN(addr);
73807- vma = find_vma(mm, addr);
73808- if (TASK_SIZE - len >= addr &&
73809- (!vma || addr + len <= vma->vm_start))
73810- return addr;
73811+ if (TASK_SIZE - len >= addr) {
73812+ vma = find_vma(mm, addr);
73813+ if (check_heap_stack_gap(vma, addr, len))
73814+ return addr;
73815+ }
73816 }
73817
73818 /* check if free_area_cache is useful for us */
73819@@ -1508,7 +1718,7 @@ try_again:
73820 * return with success:
73821 */
73822 vma = find_vma(mm, addr);
73823- if (!vma || addr+len <= vma->vm_start)
73824+ if (check_heap_stack_gap(vma, addr, len))
73825 /* remember the address as a hint for next time */
73826 return (mm->free_area_cache = addr);
73827
73828@@ -1517,8 +1727,8 @@ try_again:
73829 mm->cached_hole_size = vma->vm_start - addr;
73830
73831 /* try just below the current vma->vm_start */
73832- addr = vma->vm_start-len;
73833- } while (len < vma->vm_start);
73834+ addr = skip_heap_stack_gap(vma, len);
73835+ } while (!IS_ERR_VALUE(addr));
73836
73837 fail:
73838 /*
73839@@ -1541,13 +1751,21 @@ fail:
73840 * can happen with large stack limits and large mmap()
73841 * allocations.
73842 */
73843+ mm->mmap_base = TASK_UNMAPPED_BASE;
73844+
73845+#ifdef CONFIG_PAX_RANDMMAP
73846+ if (mm->pax_flags & MF_PAX_RANDMMAP)
73847+ mm->mmap_base += mm->delta_mmap;
73848+#endif
73849+
73850+ mm->free_area_cache = mm->mmap_base;
73851 mm->cached_hole_size = ~0UL;
73852- mm->free_area_cache = TASK_UNMAPPED_BASE;
73853 addr = arch_get_unmapped_area(filp, addr0, len, pgoff, flags);
73854 /*
73855 * Restore the topdown base:
73856 */
73857- mm->free_area_cache = mm->mmap_base;
73858+ mm->mmap_base = base;
73859+ mm->free_area_cache = base;
73860 mm->cached_hole_size = ~0UL;
73861
73862 return addr;
73863@@ -1556,6 +1774,12 @@ fail:
73864
73865 void arch_unmap_area_topdown(struct mm_struct *mm, unsigned long addr)
73866 {
73867+
73868+#ifdef CONFIG_PAX_SEGMEXEC
73869+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && SEGMEXEC_TASK_SIZE <= addr)
73870+ return;
73871+#endif
73872+
73873 /*
73874 * Is this a new hole at the highest possible address?
73875 */
73876@@ -1563,8 +1787,10 @@ void arch_unmap_area_topdown(struct mm_struct *mm, unsigned long addr)
73877 mm->free_area_cache = addr;
73878
73879 /* dont allow allocations above current base */
73880- if (mm->free_area_cache > mm->mmap_base)
73881+ if (mm->free_area_cache > mm->mmap_base) {
73882 mm->free_area_cache = mm->mmap_base;
73883+ mm->cached_hole_size = ~0UL;
73884+ }
73885 }
73886
73887 unsigned long
73888@@ -1663,6 +1889,28 @@ find_vma_prev(struct mm_struct *mm, unsigned long addr,
73889 return vma;
73890 }
73891
73892+#ifdef CONFIG_PAX_SEGMEXEC
73893+struct vm_area_struct *pax_find_mirror_vma(struct vm_area_struct *vma)
73894+{
73895+ struct vm_area_struct *vma_m;
73896+
73897+ BUG_ON(!vma || vma->vm_start >= vma->vm_end);
73898+ if (!(vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) || !(vma->vm_flags & VM_EXEC)) {
73899+ BUG_ON(vma->vm_mirror);
73900+ return NULL;
73901+ }
73902+ BUG_ON(vma->vm_start < SEGMEXEC_TASK_SIZE && SEGMEXEC_TASK_SIZE < vma->vm_end);
73903+ vma_m = vma->vm_mirror;
73904+ BUG_ON(!vma_m || vma_m->vm_mirror != vma);
73905+ BUG_ON(vma->vm_file != vma_m->vm_file);
73906+ BUG_ON(vma->vm_end - vma->vm_start != vma_m->vm_end - vma_m->vm_start);
73907+ BUG_ON(vma->vm_pgoff != vma_m->vm_pgoff);
73908+ BUG_ON(vma->anon_vma != vma_m->anon_vma && vma->anon_vma->root != vma_m->anon_vma->root);
73909+ BUG_ON((vma->vm_flags ^ vma_m->vm_flags) & ~(VM_WRITE | VM_MAYWRITE | VM_ACCOUNT | VM_LOCKED | VM_RESERVED));
73910+ return vma_m;
73911+}
73912+#endif
73913+
73914 /*
73915 * Verify that the stack growth is acceptable and
73916 * update accounting. This is shared with both the
73917@@ -1679,6 +1927,7 @@ static int acct_stack_growth(struct vm_area_struct *vma, unsigned long size, uns
73918 return -ENOMEM;
73919
73920 /* Stack limit test */
73921+ gr_learn_resource(current, RLIMIT_STACK, size, 1);
73922 if (size > ACCESS_ONCE(rlim[RLIMIT_STACK].rlim_cur))
73923 return -ENOMEM;
73924
73925@@ -1689,6 +1938,7 @@ static int acct_stack_growth(struct vm_area_struct *vma, unsigned long size, uns
73926 locked = mm->locked_vm + grow;
73927 limit = ACCESS_ONCE(rlim[RLIMIT_MEMLOCK].rlim_cur);
73928 limit >>= PAGE_SHIFT;
73929+ gr_learn_resource(current, RLIMIT_MEMLOCK, locked << PAGE_SHIFT, 1);
73930 if (locked > limit && !capable(CAP_IPC_LOCK))
73931 return -ENOMEM;
73932 }
73933@@ -1718,37 +1968,48 @@ static int acct_stack_growth(struct vm_area_struct *vma, unsigned long size, uns
73934 * PA-RISC uses this for its stack; IA64 for its Register Backing Store.
73935 * vma is the last one with address > vma->vm_end. Have to extend vma.
73936 */
73937+#ifndef CONFIG_IA64
73938+static
73939+#endif
73940 int expand_upwards(struct vm_area_struct *vma, unsigned long address)
73941 {
73942 int error;
73943+ bool locknext;
73944
73945 if (!(vma->vm_flags & VM_GROWSUP))
73946 return -EFAULT;
73947
73948+ /* Also guard against wrapping around to address 0. */
73949+ if (address < PAGE_ALIGN(address+1))
73950+ address = PAGE_ALIGN(address+1);
73951+ else
73952+ return -ENOMEM;
73953+
73954 /*
73955 * We must make sure the anon_vma is allocated
73956 * so that the anon_vma locking is not a noop.
73957 */
73958 if (unlikely(anon_vma_prepare(vma)))
73959 return -ENOMEM;
73960+ locknext = vma->vm_next && (vma->vm_next->vm_flags & VM_GROWSDOWN);
73961+ if (locknext && anon_vma_prepare(vma->vm_next))
73962+ return -ENOMEM;
73963 vma_lock_anon_vma(vma);
73964+ if (locknext)
73965+ vma_lock_anon_vma(vma->vm_next);
73966
73967 /*
73968 * vma->vm_start/vm_end cannot change under us because the caller
73969 * is required to hold the mmap_sem in read mode. We need the
73970- * anon_vma lock to serialize against concurrent expand_stacks.
73971- * Also guard against wrapping around to address 0.
73972+ * anon_vma locks to serialize against concurrent expand_stacks
73973+ * and expand_upwards.
73974 */
73975- if (address < PAGE_ALIGN(address+4))
73976- address = PAGE_ALIGN(address+4);
73977- else {
73978- vma_unlock_anon_vma(vma);
73979- return -ENOMEM;
73980- }
73981 error = 0;
73982
73983 /* Somebody else might have raced and expanded it already */
73984- if (address > vma->vm_end) {
73985+ 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)
73986+ error = -ENOMEM;
73987+ else if (address > vma->vm_end && (!locknext || vma->vm_next->vm_start >= address)) {
73988 unsigned long size, grow;
73989
73990 size = address - vma->vm_start;
73991@@ -1763,6 +2024,8 @@ int expand_upwards(struct vm_area_struct *vma, unsigned long address)
73992 }
73993 }
73994 }
73995+ if (locknext)
73996+ vma_unlock_anon_vma(vma->vm_next);
73997 vma_unlock_anon_vma(vma);
73998 khugepaged_enter_vma_merge(vma);
73999 return error;
74000@@ -1776,6 +2039,8 @@ int expand_downwards(struct vm_area_struct *vma,
74001 unsigned long address)
74002 {
74003 int error;
74004+ bool lockprev = false;
74005+ struct vm_area_struct *prev;
74006
74007 /*
74008 * We must make sure the anon_vma is allocated
74009@@ -1789,6 +2054,15 @@ int expand_downwards(struct vm_area_struct *vma,
74010 if (error)
74011 return error;
74012
74013+ prev = vma->vm_prev;
74014+#if defined(CONFIG_STACK_GROWSUP) || defined(CONFIG_IA64)
74015+ lockprev = prev && (prev->vm_flags & VM_GROWSUP);
74016+#endif
74017+ if (lockprev && anon_vma_prepare(prev))
74018+ return -ENOMEM;
74019+ if (lockprev)
74020+ vma_lock_anon_vma(prev);
74021+
74022 vma_lock_anon_vma(vma);
74023
74024 /*
74025@@ -1798,9 +2072,17 @@ int expand_downwards(struct vm_area_struct *vma,
74026 */
74027
74028 /* Somebody else might have raced and expanded it already */
74029- if (address < vma->vm_start) {
74030+ if (prev && (prev->vm_flags & (VM_READ | VM_WRITE | VM_EXEC)) && address - prev->vm_end < sysctl_heap_stack_gap)
74031+ error = -ENOMEM;
74032+ else if (address < vma->vm_start && (!lockprev || prev->vm_end <= address)) {
74033 unsigned long size, grow;
74034
74035+#ifdef CONFIG_PAX_SEGMEXEC
74036+ struct vm_area_struct *vma_m;
74037+
74038+ vma_m = pax_find_mirror_vma(vma);
74039+#endif
74040+
74041 size = vma->vm_end - address;
74042 grow = (vma->vm_start - address) >> PAGE_SHIFT;
74043
74044@@ -1810,11 +2092,22 @@ int expand_downwards(struct vm_area_struct *vma,
74045 if (!error) {
74046 vma->vm_start = address;
74047 vma->vm_pgoff -= grow;
74048+ track_exec_limit(vma->vm_mm, vma->vm_start, vma->vm_end, vma->vm_flags);
74049+
74050+#ifdef CONFIG_PAX_SEGMEXEC
74051+ if (vma_m) {
74052+ vma_m->vm_start -= grow << PAGE_SHIFT;
74053+ vma_m->vm_pgoff -= grow;
74054+ }
74055+#endif
74056+
74057 perf_event_mmap(vma);
74058 }
74059 }
74060 }
74061 vma_unlock_anon_vma(vma);
74062+ if (lockprev)
74063+ vma_unlock_anon_vma(prev);
74064 khugepaged_enter_vma_merge(vma);
74065 return error;
74066 }
74067@@ -1886,6 +2179,13 @@ static void remove_vma_list(struct mm_struct *mm, struct vm_area_struct *vma)
74068 do {
74069 long nrpages = vma_pages(vma);
74070
74071+#ifdef CONFIG_PAX_SEGMEXEC
74072+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_start >= SEGMEXEC_TASK_SIZE)) {
74073+ vma = remove_vma(vma);
74074+ continue;
74075+ }
74076+#endif
74077+
74078 if (vma->vm_flags & VM_ACCOUNT)
74079 nr_accounted += nrpages;
74080 vm_stat_account(mm, vma->vm_flags, vma->vm_file, -nrpages);
74081@@ -1931,6 +2231,16 @@ detach_vmas_to_be_unmapped(struct mm_struct *mm, struct vm_area_struct *vma,
74082 insertion_point = (prev ? &prev->vm_next : &mm->mmap);
74083 vma->vm_prev = NULL;
74084 do {
74085+
74086+#ifdef CONFIG_PAX_SEGMEXEC
74087+ if (vma->vm_mirror) {
74088+ BUG_ON(!vma->vm_mirror->vm_mirror || vma->vm_mirror->vm_mirror != vma);
74089+ vma->vm_mirror->vm_mirror = NULL;
74090+ vma->vm_mirror->vm_flags &= ~VM_EXEC;
74091+ vma->vm_mirror = NULL;
74092+ }
74093+#endif
74094+
74095 rb_erase(&vma->vm_rb, &mm->mm_rb);
74096 mm->map_count--;
74097 tail_vma = vma;
74098@@ -1959,14 +2269,33 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
74099 struct vm_area_struct *new;
74100 int err = -ENOMEM;
74101
74102+#ifdef CONFIG_PAX_SEGMEXEC
74103+ struct vm_area_struct *vma_m, *new_m = NULL;
74104+ unsigned long addr_m = addr + SEGMEXEC_TASK_SIZE;
74105+#endif
74106+
74107 if (is_vm_hugetlb_page(vma) && (addr &
74108 ~(huge_page_mask(hstate_vma(vma)))))
74109 return -EINVAL;
74110
74111+#ifdef CONFIG_PAX_SEGMEXEC
74112+ vma_m = pax_find_mirror_vma(vma);
74113+#endif
74114+
74115 new = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
74116 if (!new)
74117 goto out_err;
74118
74119+#ifdef CONFIG_PAX_SEGMEXEC
74120+ if (vma_m) {
74121+ new_m = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
74122+ if (!new_m) {
74123+ kmem_cache_free(vm_area_cachep, new);
74124+ goto out_err;
74125+ }
74126+ }
74127+#endif
74128+
74129 /* most fields are the same, copy all, and then fixup */
74130 *new = *vma;
74131
74132@@ -1979,6 +2308,22 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
74133 new->vm_pgoff += ((addr - vma->vm_start) >> PAGE_SHIFT);
74134 }
74135
74136+#ifdef CONFIG_PAX_SEGMEXEC
74137+ if (vma_m) {
74138+ *new_m = *vma_m;
74139+ INIT_LIST_HEAD(&new_m->anon_vma_chain);
74140+ new_m->vm_mirror = new;
74141+ new->vm_mirror = new_m;
74142+
74143+ if (new_below)
74144+ new_m->vm_end = addr_m;
74145+ else {
74146+ new_m->vm_start = addr_m;
74147+ new_m->vm_pgoff += ((addr_m - vma_m->vm_start) >> PAGE_SHIFT);
74148+ }
74149+ }
74150+#endif
74151+
74152 pol = mpol_dup(vma_policy(vma));
74153 if (IS_ERR(pol)) {
74154 err = PTR_ERR(pol);
74155@@ -2004,6 +2349,42 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
74156 else
74157 err = vma_adjust(vma, vma->vm_start, addr, vma->vm_pgoff, new);
74158
74159+#ifdef CONFIG_PAX_SEGMEXEC
74160+ if (!err && vma_m) {
74161+ if (anon_vma_clone(new_m, vma_m))
74162+ goto out_free_mpol;
74163+
74164+ mpol_get(pol);
74165+ vma_set_policy(new_m, pol);
74166+
74167+ if (new_m->vm_file) {
74168+ get_file(new_m->vm_file);
74169+ if (vma_m->vm_flags & VM_EXECUTABLE)
74170+ added_exe_file_vma(mm);
74171+ }
74172+
74173+ if (new_m->vm_ops && new_m->vm_ops->open)
74174+ new_m->vm_ops->open(new_m);
74175+
74176+ if (new_below)
74177+ err = vma_adjust(vma_m, addr_m, vma_m->vm_end, vma_m->vm_pgoff +
74178+ ((addr_m - new_m->vm_start) >> PAGE_SHIFT), new_m);
74179+ else
74180+ err = vma_adjust(vma_m, vma_m->vm_start, addr_m, vma_m->vm_pgoff, new_m);
74181+
74182+ if (err) {
74183+ if (new_m->vm_ops && new_m->vm_ops->close)
74184+ new_m->vm_ops->close(new_m);
74185+ if (new_m->vm_file) {
74186+ if (vma_m->vm_flags & VM_EXECUTABLE)
74187+ removed_exe_file_vma(mm);
74188+ fput(new_m->vm_file);
74189+ }
74190+ mpol_put(pol);
74191+ }
74192+ }
74193+#endif
74194+
74195 /* Success. */
74196 if (!err)
74197 return 0;
74198@@ -2016,10 +2397,18 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
74199 removed_exe_file_vma(mm);
74200 fput(new->vm_file);
74201 }
74202- unlink_anon_vmas(new);
74203 out_free_mpol:
74204 mpol_put(pol);
74205 out_free_vma:
74206+
74207+#ifdef CONFIG_PAX_SEGMEXEC
74208+ if (new_m) {
74209+ unlink_anon_vmas(new_m);
74210+ kmem_cache_free(vm_area_cachep, new_m);
74211+ }
74212+#endif
74213+
74214+ unlink_anon_vmas(new);
74215 kmem_cache_free(vm_area_cachep, new);
74216 out_err:
74217 return err;
74218@@ -2032,6 +2421,15 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
74219 int split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
74220 unsigned long addr, int new_below)
74221 {
74222+
74223+#ifdef CONFIG_PAX_SEGMEXEC
74224+ if (mm->pax_flags & MF_PAX_SEGMEXEC) {
74225+ BUG_ON(vma->vm_end > SEGMEXEC_TASK_SIZE);
74226+ if (mm->map_count >= sysctl_max_map_count-1)
74227+ return -ENOMEM;
74228+ } else
74229+#endif
74230+
74231 if (mm->map_count >= sysctl_max_map_count)
74232 return -ENOMEM;
74233
74234@@ -2043,11 +2441,30 @@ int split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
74235 * work. This now handles partial unmappings.
74236 * Jeremy Fitzhardinge <jeremy@goop.org>
74237 */
74238+#ifdef CONFIG_PAX_SEGMEXEC
74239 int do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
74240 {
74241+ int ret = __do_munmap(mm, start, len);
74242+ if (ret || !(mm->pax_flags & MF_PAX_SEGMEXEC))
74243+ return ret;
74244+
74245+ return __do_munmap(mm, start + SEGMEXEC_TASK_SIZE, len);
74246+}
74247+
74248+int __do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
74249+#else
74250+int do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
74251+#endif
74252+{
74253 unsigned long end;
74254 struct vm_area_struct *vma, *prev, *last;
74255
74256+ /*
74257+ * mm->mmap_sem is required to protect against another thread
74258+ * changing the mappings in case we sleep.
74259+ */
74260+ verify_mm_writelocked(mm);
74261+
74262 if ((start & ~PAGE_MASK) || start > TASK_SIZE || len > TASK_SIZE-start)
74263 return -EINVAL;
74264
74265@@ -2122,6 +2539,8 @@ int do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
74266 /* Fix up all other VM information */
74267 remove_vma_list(mm, vma);
74268
74269+ track_exec_limit(mm, start, end, 0UL);
74270+
74271 return 0;
74272 }
74273
74274@@ -2130,6 +2549,13 @@ int vm_munmap(unsigned long start, size_t len)
74275 int ret;
74276 struct mm_struct *mm = current->mm;
74277
74278+
74279+#ifdef CONFIG_PAX_SEGMEXEC
74280+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) &&
74281+ (len > SEGMEXEC_TASK_SIZE || start > SEGMEXEC_TASK_SIZE-len))
74282+ return -EINVAL;
74283+#endif
74284+
74285 down_write(&mm->mmap_sem);
74286 ret = do_munmap(mm, start, len);
74287 up_write(&mm->mmap_sem);
74288@@ -2143,16 +2569,6 @@ SYSCALL_DEFINE2(munmap, unsigned long, addr, size_t, len)
74289 return vm_munmap(addr, len);
74290 }
74291
74292-static inline void verify_mm_writelocked(struct mm_struct *mm)
74293-{
74294-#ifdef CONFIG_DEBUG_VM
74295- if (unlikely(down_read_trylock(&mm->mmap_sem))) {
74296- WARN_ON(1);
74297- up_read(&mm->mmap_sem);
74298- }
74299-#endif
74300-}
74301-
74302 /*
74303 * this is really a simplified "do_mmap". it only handles
74304 * anonymous maps. eventually we may be able to do some
74305@@ -2166,6 +2582,7 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
74306 struct rb_node ** rb_link, * rb_parent;
74307 pgoff_t pgoff = addr >> PAGE_SHIFT;
74308 int error;
74309+ unsigned long charged;
74310
74311 len = PAGE_ALIGN(len);
74312 if (!len)
74313@@ -2173,16 +2590,30 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
74314
74315 flags = VM_DATA_DEFAULT_FLAGS | VM_ACCOUNT | mm->def_flags;
74316
74317+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
74318+ if (mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
74319+ flags &= ~VM_EXEC;
74320+
74321+#ifdef CONFIG_PAX_MPROTECT
74322+ if (mm->pax_flags & MF_PAX_MPROTECT)
74323+ flags &= ~VM_MAYEXEC;
74324+#endif
74325+
74326+ }
74327+#endif
74328+
74329 error = get_unmapped_area(NULL, addr, len, 0, MAP_FIXED);
74330 if (error & ~PAGE_MASK)
74331 return error;
74332
74333+ charged = len >> PAGE_SHIFT;
74334+
74335 /*
74336 * mlock MCL_FUTURE?
74337 */
74338 if (mm->def_flags & VM_LOCKED) {
74339 unsigned long locked, lock_limit;
74340- locked = len >> PAGE_SHIFT;
74341+ locked = charged;
74342 locked += mm->locked_vm;
74343 lock_limit = rlimit(RLIMIT_MEMLOCK);
74344 lock_limit >>= PAGE_SHIFT;
74345@@ -2199,22 +2630,22 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
74346 /*
74347 * Clear old maps. this also does some error checking for us
74348 */
74349- munmap_back:
74350 vma = find_vma_prepare(mm, addr, &prev, &rb_link, &rb_parent);
74351 if (vma && vma->vm_start < addr + len) {
74352 if (do_munmap(mm, addr, len))
74353 return -ENOMEM;
74354- goto munmap_back;
74355- }
74356+ vma = find_vma_prepare(mm, addr, &prev, &rb_link, &rb_parent);
74357+ BUG_ON(vma && vma->vm_start < addr + len);
74358+ }
74359
74360 /* Check against address space limits *after* clearing old maps... */
74361- if (!may_expand_vm(mm, len >> PAGE_SHIFT))
74362+ if (!may_expand_vm(mm, charged))
74363 return -ENOMEM;
74364
74365 if (mm->map_count > sysctl_max_map_count)
74366 return -ENOMEM;
74367
74368- if (security_vm_enough_memory_mm(mm, len >> PAGE_SHIFT))
74369+ if (security_vm_enough_memory_mm(mm, charged))
74370 return -ENOMEM;
74371
74372 /* Can we just expand an old private anonymous mapping? */
74373@@ -2228,7 +2659,7 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
74374 */
74375 vma = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
74376 if (!vma) {
74377- vm_unacct_memory(len >> PAGE_SHIFT);
74378+ vm_unacct_memory(charged);
74379 return -ENOMEM;
74380 }
74381
74382@@ -2242,11 +2673,12 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
74383 vma_link(mm, vma, prev, rb_link, rb_parent);
74384 out:
74385 perf_event_mmap(vma);
74386- mm->total_vm += len >> PAGE_SHIFT;
74387+ mm->total_vm += charged;
74388 if (flags & VM_LOCKED) {
74389 if (!mlock_vma_pages_range(vma, addr, addr + len))
74390- mm->locked_vm += (len >> PAGE_SHIFT);
74391+ mm->locked_vm += charged;
74392 }
74393+ track_exec_limit(mm, addr, addr + len, flags);
74394 return addr;
74395 }
74396
74397@@ -2304,6 +2736,7 @@ void exit_mmap(struct mm_struct *mm)
74398 while (vma) {
74399 if (vma->vm_flags & VM_ACCOUNT)
74400 nr_accounted += vma_pages(vma);
74401+ vma->vm_mirror = NULL;
74402 vma = remove_vma(vma);
74403 }
74404 vm_unacct_memory(nr_accounted);
74405@@ -2320,6 +2753,13 @@ int insert_vm_struct(struct mm_struct * mm, struct vm_area_struct * vma)
74406 struct vm_area_struct * __vma, * prev;
74407 struct rb_node ** rb_link, * rb_parent;
74408
74409+#ifdef CONFIG_PAX_SEGMEXEC
74410+ struct vm_area_struct *vma_m = NULL;
74411+#endif
74412+
74413+ if (security_mmap_addr(vma->vm_start))
74414+ return -EPERM;
74415+
74416 /*
74417 * The vm_pgoff of a purely anonymous vma should be irrelevant
74418 * until its first write fault, when page's anon_vma and index
74419@@ -2343,7 +2783,21 @@ int insert_vm_struct(struct mm_struct * mm, struct vm_area_struct * vma)
74420 security_vm_enough_memory_mm(mm, vma_pages(vma)))
74421 return -ENOMEM;
74422
74423+#ifdef CONFIG_PAX_SEGMEXEC
74424+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_flags & VM_EXEC)) {
74425+ vma_m = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
74426+ if (!vma_m)
74427+ return -ENOMEM;
74428+ }
74429+#endif
74430+
74431 vma_link(mm, vma, prev, rb_link, rb_parent);
74432+
74433+#ifdef CONFIG_PAX_SEGMEXEC
74434+ if (vma_m)
74435+ BUG_ON(pax_mirror_vma(vma_m, vma));
74436+#endif
74437+
74438 return 0;
74439 }
74440
74441@@ -2362,6 +2816,8 @@ struct vm_area_struct *copy_vma(struct vm_area_struct **vmap,
74442 struct mempolicy *pol;
74443 bool faulted_in_anon_vma = true;
74444
74445+ BUG_ON(vma->vm_mirror);
74446+
74447 /*
74448 * If anonymous vma has not yet been faulted, update new pgoff
74449 * to match new location, to increase its chance of merging.
74450@@ -2430,6 +2886,39 @@ struct vm_area_struct *copy_vma(struct vm_area_struct **vmap,
74451 return NULL;
74452 }
74453
74454+#ifdef CONFIG_PAX_SEGMEXEC
74455+long pax_mirror_vma(struct vm_area_struct *vma_m, struct vm_area_struct *vma)
74456+{
74457+ struct vm_area_struct *prev_m;
74458+ struct rb_node **rb_link_m, *rb_parent_m;
74459+ struct mempolicy *pol_m;
74460+
74461+ BUG_ON(!(vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) || !(vma->vm_flags & VM_EXEC));
74462+ BUG_ON(vma->vm_mirror || vma_m->vm_mirror);
74463+ BUG_ON(!mpol_equal(vma_policy(vma), vma_policy(vma_m)));
74464+ *vma_m = *vma;
74465+ INIT_LIST_HEAD(&vma_m->anon_vma_chain);
74466+ if (anon_vma_clone(vma_m, vma))
74467+ return -ENOMEM;
74468+ pol_m = vma_policy(vma_m);
74469+ mpol_get(pol_m);
74470+ vma_set_policy(vma_m, pol_m);
74471+ vma_m->vm_start += SEGMEXEC_TASK_SIZE;
74472+ vma_m->vm_end += SEGMEXEC_TASK_SIZE;
74473+ vma_m->vm_flags &= ~(VM_WRITE | VM_MAYWRITE | VM_ACCOUNT | VM_LOCKED);
74474+ vma_m->vm_page_prot = vm_get_page_prot(vma_m->vm_flags);
74475+ if (vma_m->vm_file)
74476+ get_file(vma_m->vm_file);
74477+ if (vma_m->vm_ops && vma_m->vm_ops->open)
74478+ vma_m->vm_ops->open(vma_m);
74479+ find_vma_prepare(vma->vm_mm, vma_m->vm_start, &prev_m, &rb_link_m, &rb_parent_m);
74480+ vma_link(vma->vm_mm, vma_m, prev_m, rb_link_m, rb_parent_m);
74481+ vma_m->vm_mirror = vma;
74482+ vma->vm_mirror = vma_m;
74483+ return 0;
74484+}
74485+#endif
74486+
74487 /*
74488 * Return true if the calling process may expand its vm space by the passed
74489 * number of pages
74490@@ -2441,6 +2930,12 @@ int may_expand_vm(struct mm_struct *mm, unsigned long npages)
74491
74492 lim = rlimit(RLIMIT_AS) >> PAGE_SHIFT;
74493
74494+#ifdef CONFIG_PAX_RANDMMAP
74495+ if (mm->pax_flags & MF_PAX_RANDMMAP)
74496+ cur -= mm->brk_gap;
74497+#endif
74498+
74499+ gr_learn_resource(current, RLIMIT_AS, (cur + npages) << PAGE_SHIFT, 1);
74500 if (cur + npages > lim)
74501 return 0;
74502 return 1;
74503@@ -2511,6 +3006,22 @@ int install_special_mapping(struct mm_struct *mm,
74504 vma->vm_start = addr;
74505 vma->vm_end = addr + len;
74506
74507+#ifdef CONFIG_PAX_MPROTECT
74508+ if (mm->pax_flags & MF_PAX_MPROTECT) {
74509+#ifndef CONFIG_PAX_MPROTECT_COMPAT
74510+ if ((vm_flags & (VM_WRITE | VM_EXEC)) == (VM_WRITE | VM_EXEC))
74511+ return -EPERM;
74512+ if (!(vm_flags & VM_EXEC))
74513+ vm_flags &= ~VM_MAYEXEC;
74514+#else
74515+ if ((vm_flags & (VM_WRITE | VM_EXEC)) != VM_EXEC)
74516+ vm_flags &= ~(VM_EXEC | VM_MAYEXEC);
74517+#endif
74518+ else
74519+ vm_flags &= ~VM_MAYWRITE;
74520+ }
74521+#endif
74522+
74523 vma->vm_flags = vm_flags | mm->def_flags | VM_DONTEXPAND;
74524 vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
74525
74526diff --git a/mm/mprotect.c b/mm/mprotect.c
74527index a409926..8b32e6d 100644
74528--- a/mm/mprotect.c
74529+++ b/mm/mprotect.c
74530@@ -23,10 +23,17 @@
74531 #include <linux/mmu_notifier.h>
74532 #include <linux/migrate.h>
74533 #include <linux/perf_event.h>
74534+
74535+#ifdef CONFIG_PAX_MPROTECT
74536+#include <linux/elf.h>
74537+#include <linux/binfmts.h>
74538+#endif
74539+
74540 #include <asm/uaccess.h>
74541 #include <asm/pgtable.h>
74542 #include <asm/cacheflush.h>
74543 #include <asm/tlbflush.h>
74544+#include <asm/mmu_context.h>
74545
74546 #ifndef pgprot_modify
74547 static inline pgprot_t pgprot_modify(pgprot_t oldprot, pgprot_t newprot)
74548@@ -141,6 +148,48 @@ static void change_protection(struct vm_area_struct *vma,
74549 flush_tlb_range(vma, start, end);
74550 }
74551
74552+#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
74553+/* called while holding the mmap semaphor for writing except stack expansion */
74554+void track_exec_limit(struct mm_struct *mm, unsigned long start, unsigned long end, unsigned long prot)
74555+{
74556+ unsigned long oldlimit, newlimit = 0UL;
74557+
74558+ if (!(mm->pax_flags & MF_PAX_PAGEEXEC) || (__supported_pte_mask & _PAGE_NX))
74559+ return;
74560+
74561+ spin_lock(&mm->page_table_lock);
74562+ oldlimit = mm->context.user_cs_limit;
74563+ if ((prot & VM_EXEC) && oldlimit < end)
74564+ /* USER_CS limit moved up */
74565+ newlimit = end;
74566+ else if (!(prot & VM_EXEC) && start < oldlimit && oldlimit <= end)
74567+ /* USER_CS limit moved down */
74568+ newlimit = start;
74569+
74570+ if (newlimit) {
74571+ mm->context.user_cs_limit = newlimit;
74572+
74573+#ifdef CONFIG_SMP
74574+ wmb();
74575+ cpus_clear(mm->context.cpu_user_cs_mask);
74576+ cpu_set(smp_processor_id(), mm->context.cpu_user_cs_mask);
74577+#endif
74578+
74579+ set_user_cs(mm->context.user_cs_base, mm->context.user_cs_limit, smp_processor_id());
74580+ }
74581+ spin_unlock(&mm->page_table_lock);
74582+ if (newlimit == end) {
74583+ struct vm_area_struct *vma = find_vma(mm, oldlimit);
74584+
74585+ for (; vma && vma->vm_start < end; vma = vma->vm_next)
74586+ if (is_vm_hugetlb_page(vma))
74587+ hugetlb_change_protection(vma, vma->vm_start, vma->vm_end, vma->vm_page_prot);
74588+ else
74589+ change_protection(vma, vma->vm_start, vma->vm_end, vma->vm_page_prot, vma_wants_writenotify(vma));
74590+ }
74591+}
74592+#endif
74593+
74594 int
74595 mprotect_fixup(struct vm_area_struct *vma, struct vm_area_struct **pprev,
74596 unsigned long start, unsigned long end, unsigned long newflags)
74597@@ -153,11 +202,29 @@ mprotect_fixup(struct vm_area_struct *vma, struct vm_area_struct **pprev,
74598 int error;
74599 int dirty_accountable = 0;
74600
74601+#ifdef CONFIG_PAX_SEGMEXEC
74602+ struct vm_area_struct *vma_m = NULL;
74603+ unsigned long start_m, end_m;
74604+
74605+ start_m = start + SEGMEXEC_TASK_SIZE;
74606+ end_m = end + SEGMEXEC_TASK_SIZE;
74607+#endif
74608+
74609 if (newflags == oldflags) {
74610 *pprev = vma;
74611 return 0;
74612 }
74613
74614+ if (newflags & (VM_READ | VM_WRITE | VM_EXEC)) {
74615+ struct vm_area_struct *prev = vma->vm_prev, *next = vma->vm_next;
74616+
74617+ if (next && (next->vm_flags & VM_GROWSDOWN) && sysctl_heap_stack_gap > next->vm_start - end)
74618+ return -ENOMEM;
74619+
74620+ if (prev && (prev->vm_flags & VM_GROWSUP) && sysctl_heap_stack_gap > start - prev->vm_end)
74621+ return -ENOMEM;
74622+ }
74623+
74624 /*
74625 * If we make a private mapping writable we increase our commit;
74626 * but (without finer accounting) cannot reduce our commit if we
74627@@ -174,6 +241,42 @@ mprotect_fixup(struct vm_area_struct *vma, struct vm_area_struct **pprev,
74628 }
74629 }
74630
74631+#ifdef CONFIG_PAX_SEGMEXEC
74632+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && ((oldflags ^ newflags) & VM_EXEC)) {
74633+ if (start != vma->vm_start) {
74634+ error = split_vma(mm, vma, start, 1);
74635+ if (error)
74636+ goto fail;
74637+ BUG_ON(!*pprev || (*pprev)->vm_next == vma);
74638+ *pprev = (*pprev)->vm_next;
74639+ }
74640+
74641+ if (end != vma->vm_end) {
74642+ error = split_vma(mm, vma, end, 0);
74643+ if (error)
74644+ goto fail;
74645+ }
74646+
74647+ if (pax_find_mirror_vma(vma)) {
74648+ error = __do_munmap(mm, start_m, end_m - start_m);
74649+ if (error)
74650+ goto fail;
74651+ } else {
74652+ vma_m = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
74653+ if (!vma_m) {
74654+ error = -ENOMEM;
74655+ goto fail;
74656+ }
74657+ vma->vm_flags = newflags;
74658+ error = pax_mirror_vma(vma_m, vma);
74659+ if (error) {
74660+ vma->vm_flags = oldflags;
74661+ goto fail;
74662+ }
74663+ }
74664+ }
74665+#endif
74666+
74667 /*
74668 * First try to merge with previous and/or next vma.
74669 */
74670@@ -204,9 +307,21 @@ success:
74671 * vm_flags and vm_page_prot are protected by the mmap_sem
74672 * held in write mode.
74673 */
74674+
74675+#ifdef CONFIG_PAX_SEGMEXEC
74676+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (newflags & VM_EXEC) && ((vma->vm_flags ^ newflags) & VM_READ))
74677+ pax_find_mirror_vma(vma)->vm_flags ^= VM_READ;
74678+#endif
74679+
74680 vma->vm_flags = newflags;
74681+
74682+#ifdef CONFIG_PAX_MPROTECT
74683+ if (mm->binfmt && mm->binfmt->handle_mprotect)
74684+ mm->binfmt->handle_mprotect(vma, newflags);
74685+#endif
74686+
74687 vma->vm_page_prot = pgprot_modify(vma->vm_page_prot,
74688- vm_get_page_prot(newflags));
74689+ vm_get_page_prot(vma->vm_flags));
74690
74691 if (vma_wants_writenotify(vma)) {
74692 vma->vm_page_prot = vm_get_page_prot(newflags & ~VM_SHARED);
74693@@ -248,6 +363,17 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
74694 end = start + len;
74695 if (end <= start)
74696 return -ENOMEM;
74697+
74698+#ifdef CONFIG_PAX_SEGMEXEC
74699+ if (current->mm->pax_flags & MF_PAX_SEGMEXEC) {
74700+ if (end > SEGMEXEC_TASK_SIZE)
74701+ return -EINVAL;
74702+ } else
74703+#endif
74704+
74705+ if (end > TASK_SIZE)
74706+ return -EINVAL;
74707+
74708 if (!arch_validate_prot(prot))
74709 return -EINVAL;
74710
74711@@ -255,7 +381,7 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
74712 /*
74713 * Does the application expect PROT_READ to imply PROT_EXEC:
74714 */
74715- if ((prot & PROT_READ) && (current->personality & READ_IMPLIES_EXEC))
74716+ if ((prot & (PROT_READ | PROT_WRITE)) && (current->personality & READ_IMPLIES_EXEC))
74717 prot |= PROT_EXEC;
74718
74719 vm_flags = calc_vm_prot_bits(prot);
74720@@ -288,6 +414,11 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
74721 if (start > vma->vm_start)
74722 prev = vma;
74723
74724+#ifdef CONFIG_PAX_MPROTECT
74725+ if (current->mm->binfmt && current->mm->binfmt->handle_mprotect)
74726+ current->mm->binfmt->handle_mprotect(vma, vm_flags);
74727+#endif
74728+
74729 for (nstart = start ; ; ) {
74730 unsigned long newflags;
74731
74732@@ -297,6 +428,14 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
74733
74734 /* newflags >> 4 shift VM_MAY% in place of VM_% */
74735 if ((newflags & ~(newflags >> 4)) & (VM_READ | VM_WRITE | VM_EXEC)) {
74736+ if (prot & (PROT_WRITE | PROT_EXEC))
74737+ gr_log_rwxmprotect(vma->vm_file);
74738+
74739+ error = -EACCES;
74740+ goto out;
74741+ }
74742+
74743+ if (!gr_acl_handle_mprotect(vma->vm_file, prot)) {
74744 error = -EACCES;
74745 goto out;
74746 }
74747@@ -311,6 +450,9 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
74748 error = mprotect_fixup(vma, &prev, nstart, tmp, newflags);
74749 if (error)
74750 goto out;
74751+
74752+ track_exec_limit(current->mm, nstart, tmp, vm_flags);
74753+
74754 nstart = tmp;
74755
74756 if (nstart < prev->vm_end)
74757diff --git a/mm/mremap.c b/mm/mremap.c
74758index cc06d0e..40b5d18 100644
74759--- a/mm/mremap.c
74760+++ b/mm/mremap.c
74761@@ -106,6 +106,12 @@ static void move_ptes(struct vm_area_struct *vma, pmd_t *old_pmd,
74762 continue;
74763 pte = ptep_get_and_clear(mm, old_addr, old_pte);
74764 pte = move_pte(pte, new_vma->vm_page_prot, old_addr, new_addr);
74765+
74766+#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
74767+ if (!(__supported_pte_mask & _PAGE_NX) && (new_vma->vm_flags & (VM_PAGEEXEC | VM_EXEC)) == VM_PAGEEXEC)
74768+ pte = pte_exprotect(pte);
74769+#endif
74770+
74771 set_pte_at(mm, new_addr, new_pte, pte);
74772 }
74773
74774@@ -298,6 +304,11 @@ static struct vm_area_struct *vma_to_resize(unsigned long addr,
74775 if (is_vm_hugetlb_page(vma))
74776 goto Einval;
74777
74778+#ifdef CONFIG_PAX_SEGMEXEC
74779+ if (pax_find_mirror_vma(vma))
74780+ goto Einval;
74781+#endif
74782+
74783 /* We can't remap across vm area boundaries */
74784 if (old_len > vma->vm_end - addr)
74785 goto Efault;
74786@@ -354,20 +365,25 @@ static unsigned long mremap_to(unsigned long addr,
74787 unsigned long ret = -EINVAL;
74788 unsigned long charged = 0;
74789 unsigned long map_flags;
74790+ unsigned long pax_task_size = TASK_SIZE;
74791
74792 if (new_addr & ~PAGE_MASK)
74793 goto out;
74794
74795- if (new_len > TASK_SIZE || new_addr > TASK_SIZE - new_len)
74796+#ifdef CONFIG_PAX_SEGMEXEC
74797+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
74798+ pax_task_size = SEGMEXEC_TASK_SIZE;
74799+#endif
74800+
74801+ pax_task_size -= PAGE_SIZE;
74802+
74803+ if (new_len > TASK_SIZE || new_addr > pax_task_size - new_len)
74804 goto out;
74805
74806 /* Check if the location we're moving into overlaps the
74807 * old location at all, and fail if it does.
74808 */
74809- if ((new_addr <= addr) && (new_addr+new_len) > addr)
74810- goto out;
74811-
74812- if ((addr <= new_addr) && (addr+old_len) > new_addr)
74813+ if (addr + old_len > new_addr && new_addr + new_len > addr)
74814 goto out;
74815
74816 ret = do_munmap(mm, new_addr, new_len);
74817@@ -435,6 +451,7 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
74818 struct vm_area_struct *vma;
74819 unsigned long ret = -EINVAL;
74820 unsigned long charged = 0;
74821+ unsigned long pax_task_size = TASK_SIZE;
74822
74823 down_write(&current->mm->mmap_sem);
74824
74825@@ -455,6 +472,17 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
74826 if (!new_len)
74827 goto out;
74828
74829+#ifdef CONFIG_PAX_SEGMEXEC
74830+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
74831+ pax_task_size = SEGMEXEC_TASK_SIZE;
74832+#endif
74833+
74834+ pax_task_size -= PAGE_SIZE;
74835+
74836+ if (new_len > pax_task_size || addr > pax_task_size-new_len ||
74837+ old_len > pax_task_size || addr > pax_task_size-old_len)
74838+ goto out;
74839+
74840 if (flags & MREMAP_FIXED) {
74841 if (flags & MREMAP_MAYMOVE)
74842 ret = mremap_to(addr, old_len, new_addr, new_len);
74843@@ -503,6 +531,7 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
74844 addr + new_len);
74845 }
74846 ret = addr;
74847+ track_exec_limit(vma->vm_mm, vma->vm_start, addr + new_len, vma->vm_flags);
74848 goto out;
74849 }
74850 }
74851@@ -526,7 +555,12 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
74852 goto out;
74853 }
74854
74855+ map_flags = vma->vm_flags;
74856 ret = move_vma(vma, addr, old_len, new_len, new_addr);
74857+ if (!(ret & ~PAGE_MASK)) {
74858+ track_exec_limit(current->mm, addr, addr + old_len, 0UL);
74859+ track_exec_limit(current->mm, new_addr, new_addr + new_len, map_flags);
74860+ }
74861 }
74862 out:
74863 if (ret & ~PAGE_MASK)
74864diff --git a/mm/nommu.c b/mm/nommu.c
74865index d4b0c10..ed421b5 100644
74866--- a/mm/nommu.c
74867+++ b/mm/nommu.c
74868@@ -62,7 +62,6 @@ int sysctl_overcommit_memory = OVERCOMMIT_GUESS; /* heuristic overcommit */
74869 int sysctl_overcommit_ratio = 50; /* default is 50% */
74870 int sysctl_max_map_count = DEFAULT_MAX_MAP_COUNT;
74871 int sysctl_nr_trim_pages = CONFIG_NOMMU_INITIAL_TRIM_EXCESS;
74872-int heap_stack_gap = 0;
74873
74874 atomic_long_t mmap_pages_allocated;
74875
74876@@ -827,15 +826,6 @@ struct vm_area_struct *find_vma(struct mm_struct *mm, unsigned long addr)
74877 EXPORT_SYMBOL(find_vma);
74878
74879 /*
74880- * find a VMA
74881- * - we don't extend stack VMAs under NOMMU conditions
74882- */
74883-struct vm_area_struct *find_extend_vma(struct mm_struct *mm, unsigned long addr)
74884-{
74885- return find_vma(mm, addr);
74886-}
74887-
74888-/*
74889 * expand a stack to a given address
74890 * - not supported under NOMMU conditions
74891 */
74892@@ -1551,6 +1541,7 @@ int split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
74893
74894 /* most fields are the same, copy all, and then fixup */
74895 *new = *vma;
74896+ INIT_LIST_HEAD(&new->anon_vma_chain);
74897 *region = *vma->vm_region;
74898 new->vm_region = region;
74899
74900diff --git a/mm/page_alloc.c b/mm/page_alloc.c
74901index d2d8f54..be2a87c 100644
74902--- a/mm/page_alloc.c
74903+++ b/mm/page_alloc.c
74904@@ -340,7 +340,7 @@ out:
74905 * This usage means that zero-order pages may not be compound.
74906 */
74907
74908-static void free_compound_page(struct page *page)
74909+void free_compound_page(struct page *page)
74910 {
74911 __free_pages_ok(page, compound_order(page));
74912 }
74913@@ -697,6 +697,10 @@ static bool free_pages_prepare(struct page *page, unsigned int order)
74914 int i;
74915 int bad = 0;
74916
74917+#ifdef CONFIG_PAX_MEMORY_SANITIZE
74918+ unsigned long index = 1UL << order;
74919+#endif
74920+
74921 trace_mm_page_free(page, order);
74922 kmemcheck_free_shadow(page, order);
74923
74924@@ -712,6 +716,12 @@ static bool free_pages_prepare(struct page *page, unsigned int order)
74925 debug_check_no_obj_freed(page_address(page),
74926 PAGE_SIZE << order);
74927 }
74928+
74929+#ifdef CONFIG_PAX_MEMORY_SANITIZE
74930+ for (; index; --index)
74931+ sanitize_highpage(page + index - 1);
74932+#endif
74933+
74934 arch_free_page(page, order);
74935 kernel_map_pages(page, 1 << order, 0);
74936
74937@@ -853,8 +863,10 @@ static int prep_new_page(struct page *page, int order, gfp_t gfp_flags)
74938 arch_alloc_page(page, order);
74939 kernel_map_pages(page, 1 << order, 1);
74940
74941+#ifndef CONFIG_PAX_MEMORY_SANITIZE
74942 if (gfp_flags & __GFP_ZERO)
74943 prep_zero_page(page, order, gfp_flags);
74944+#endif
74945
74946 if (order && (gfp_flags & __GFP_COMP))
74947 prep_compound_page(page, order);
74948@@ -3648,7 +3660,13 @@ static int pageblock_is_reserved(unsigned long start_pfn, unsigned long end_pfn)
74949 unsigned long pfn;
74950
74951 for (pfn = start_pfn; pfn < end_pfn; pfn++) {
74952+#ifdef CONFIG_X86_32
74953+ /* boot failures in VMware 8 on 32bit vanilla since
74954+ this change */
74955+ if (!pfn_valid(pfn) || PageReserved(pfn_to_page(pfn)))
74956+#else
74957 if (!pfn_valid_within(pfn) || PageReserved(pfn_to_page(pfn)))
74958+#endif
74959 return 1;
74960 }
74961 return 0;
74962diff --git a/mm/percpu.c b/mm/percpu.c
74963index bb4be74..a43ea85 100644
74964--- a/mm/percpu.c
74965+++ b/mm/percpu.c
74966@@ -122,7 +122,7 @@ static unsigned int pcpu_low_unit_cpu __read_mostly;
74967 static unsigned int pcpu_high_unit_cpu __read_mostly;
74968
74969 /* the address of the first chunk which starts with the kernel static area */
74970-void *pcpu_base_addr __read_mostly;
74971+void *pcpu_base_addr __read_only;
74972 EXPORT_SYMBOL_GPL(pcpu_base_addr);
74973
74974 static const int *pcpu_unit_map __read_mostly; /* cpu -> unit */
74975diff --git a/mm/process_vm_access.c b/mm/process_vm_access.c
74976index 926b466..b23df53 100644
74977--- a/mm/process_vm_access.c
74978+++ b/mm/process_vm_access.c
74979@@ -13,6 +13,7 @@
74980 #include <linux/uio.h>
74981 #include <linux/sched.h>
74982 #include <linux/highmem.h>
74983+#include <linux/security.h>
74984 #include <linux/ptrace.h>
74985 #include <linux/slab.h>
74986 #include <linux/syscalls.h>
74987@@ -258,19 +259,19 @@ static ssize_t process_vm_rw_core(pid_t pid, const struct iovec *lvec,
74988 size_t iov_l_curr_offset = 0;
74989 ssize_t iov_len;
74990
74991+ return -ENOSYS; // PaX: until properly audited
74992+
74993 /*
74994 * Work out how many pages of struct pages we're going to need
74995 * when eventually calling get_user_pages
74996 */
74997 for (i = 0; i < riovcnt; i++) {
74998 iov_len = rvec[i].iov_len;
74999- if (iov_len > 0) {
75000- nr_pages_iov = ((unsigned long)rvec[i].iov_base
75001- + iov_len)
75002- / PAGE_SIZE - (unsigned long)rvec[i].iov_base
75003- / PAGE_SIZE + 1;
75004- nr_pages = max(nr_pages, nr_pages_iov);
75005- }
75006+ if (iov_len <= 0)
75007+ continue;
75008+ nr_pages_iov = ((unsigned long)rvec[i].iov_base + iov_len) / PAGE_SIZE -
75009+ (unsigned long)rvec[i].iov_base / PAGE_SIZE + 1;
75010+ nr_pages = max(nr_pages, nr_pages_iov);
75011 }
75012
75013 if (nr_pages == 0)
75014@@ -298,6 +299,11 @@ static ssize_t process_vm_rw_core(pid_t pid, const struct iovec *lvec,
75015 goto free_proc_pages;
75016 }
75017
75018+ if (gr_handle_ptrace(task, vm_write ? PTRACE_POKETEXT : PTRACE_ATTACH)) {
75019+ rc = -EPERM;
75020+ goto put_task_struct;
75021+ }
75022+
75023 mm = mm_access(task, PTRACE_MODE_ATTACH);
75024 if (!mm || IS_ERR(mm)) {
75025 rc = IS_ERR(mm) ? PTR_ERR(mm) : -ESRCH;
75026diff --git a/mm/rmap.c b/mm/rmap.c
75027index aa95e59..b681a63 100644
75028--- a/mm/rmap.c
75029+++ b/mm/rmap.c
75030@@ -168,6 +168,10 @@ int anon_vma_prepare(struct vm_area_struct *vma)
75031 struct anon_vma *anon_vma = vma->anon_vma;
75032 struct anon_vma_chain *avc;
75033
75034+#ifdef CONFIG_PAX_SEGMEXEC
75035+ struct anon_vma_chain *avc_m = NULL;
75036+#endif
75037+
75038 might_sleep();
75039 if (unlikely(!anon_vma)) {
75040 struct mm_struct *mm = vma->vm_mm;
75041@@ -177,6 +181,12 @@ int anon_vma_prepare(struct vm_area_struct *vma)
75042 if (!avc)
75043 goto out_enomem;
75044
75045+#ifdef CONFIG_PAX_SEGMEXEC
75046+ avc_m = anon_vma_chain_alloc(GFP_KERNEL);
75047+ if (!avc_m)
75048+ goto out_enomem_free_avc;
75049+#endif
75050+
75051 anon_vma = find_mergeable_anon_vma(vma);
75052 allocated = NULL;
75053 if (!anon_vma) {
75054@@ -190,6 +200,18 @@ int anon_vma_prepare(struct vm_area_struct *vma)
75055 /* page_table_lock to protect against threads */
75056 spin_lock(&mm->page_table_lock);
75057 if (likely(!vma->anon_vma)) {
75058+
75059+#ifdef CONFIG_PAX_SEGMEXEC
75060+ struct vm_area_struct *vma_m = pax_find_mirror_vma(vma);
75061+
75062+ if (vma_m) {
75063+ BUG_ON(vma_m->anon_vma);
75064+ vma_m->anon_vma = anon_vma;
75065+ anon_vma_chain_link(vma_m, avc_m, anon_vma);
75066+ avc_m = NULL;
75067+ }
75068+#endif
75069+
75070 vma->anon_vma = anon_vma;
75071 anon_vma_chain_link(vma, avc, anon_vma);
75072 allocated = NULL;
75073@@ -200,12 +222,24 @@ int anon_vma_prepare(struct vm_area_struct *vma)
75074
75075 if (unlikely(allocated))
75076 put_anon_vma(allocated);
75077+
75078+#ifdef CONFIG_PAX_SEGMEXEC
75079+ if (unlikely(avc_m))
75080+ anon_vma_chain_free(avc_m);
75081+#endif
75082+
75083 if (unlikely(avc))
75084 anon_vma_chain_free(avc);
75085 }
75086 return 0;
75087
75088 out_enomem_free_avc:
75089+
75090+#ifdef CONFIG_PAX_SEGMEXEC
75091+ if (avc_m)
75092+ anon_vma_chain_free(avc_m);
75093+#endif
75094+
75095 anon_vma_chain_free(avc);
75096 out_enomem:
75097 return -ENOMEM;
75098@@ -241,7 +275,7 @@ static inline void unlock_anon_vma_root(struct anon_vma *root)
75099 * Attach the anon_vmas from src to dst.
75100 * Returns 0 on success, -ENOMEM on failure.
75101 */
75102-int anon_vma_clone(struct vm_area_struct *dst, struct vm_area_struct *src)
75103+int anon_vma_clone(struct vm_area_struct *dst, const struct vm_area_struct *src)
75104 {
75105 struct anon_vma_chain *avc, *pavc;
75106 struct anon_vma *root = NULL;
75107@@ -319,7 +353,7 @@ void anon_vma_moveto_tail(struct vm_area_struct *dst)
75108 * the corresponding VMA in the parent process is attached to.
75109 * Returns 0 on success, non-zero on failure.
75110 */
75111-int anon_vma_fork(struct vm_area_struct *vma, struct vm_area_struct *pvma)
75112+int anon_vma_fork(struct vm_area_struct *vma, const struct vm_area_struct *pvma)
75113 {
75114 struct anon_vma_chain *avc;
75115 struct anon_vma *anon_vma;
75116diff --git a/mm/shmem.c b/mm/shmem.c
75117index 31e1506..dbf3647 100644
75118--- a/mm/shmem.c
75119+++ b/mm/shmem.c
75120@@ -31,7 +31,7 @@
75121 #include <linux/export.h>
75122 #include <linux/swap.h>
75123
75124-static struct vfsmount *shm_mnt;
75125+struct vfsmount *shm_mnt;
75126
75127 #ifdef CONFIG_SHMEM
75128 /*
75129@@ -75,7 +75,7 @@ static struct vfsmount *shm_mnt;
75130 #define BOGO_DIRENT_SIZE 20
75131
75132 /* Symlink up to this size is kmalloc'ed instead of using a swappable page */
75133-#define SHORT_SYMLINK_LEN 128
75134+#define SHORT_SYMLINK_LEN 64
75135
75136 struct shmem_xattr {
75137 struct list_head list; /* anchored by shmem_inode_info->xattr_list */
75138@@ -2219,6 +2219,11 @@ static const struct xattr_handler *shmem_xattr_handlers[] = {
75139 static int shmem_xattr_validate(const char *name)
75140 {
75141 struct { const char *prefix; size_t len; } arr[] = {
75142+
75143+#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
75144+ { XATTR_USER_PREFIX, XATTR_USER_PREFIX_LEN},
75145+#endif
75146+
75147 { XATTR_SECURITY_PREFIX, XATTR_SECURITY_PREFIX_LEN },
75148 { XATTR_TRUSTED_PREFIX, XATTR_TRUSTED_PREFIX_LEN }
75149 };
75150@@ -2272,6 +2277,15 @@ static int shmem_setxattr(struct dentry *dentry, const char *name,
75151 if (err)
75152 return err;
75153
75154+#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
75155+ if (!strncmp(name, XATTR_USER_PREFIX, XATTR_USER_PREFIX_LEN)) {
75156+ if (strcmp(name, XATTR_NAME_PAX_FLAGS))
75157+ return -EOPNOTSUPP;
75158+ if (size > 8)
75159+ return -EINVAL;
75160+ }
75161+#endif
75162+
75163 if (size == 0)
75164 value = ""; /* empty EA, do not remove */
75165
75166@@ -2606,8 +2620,7 @@ int shmem_fill_super(struct super_block *sb, void *data, int silent)
75167 int err = -ENOMEM;
75168
75169 /* Round up to L1_CACHE_BYTES to resist false sharing */
75170- sbinfo = kzalloc(max((int)sizeof(struct shmem_sb_info),
75171- L1_CACHE_BYTES), GFP_KERNEL);
75172+ sbinfo = kzalloc(max(sizeof(struct shmem_sb_info), L1_CACHE_BYTES), GFP_KERNEL);
75173 if (!sbinfo)
75174 return -ENOMEM;
75175
75176diff --git a/mm/slab.c b/mm/slab.c
75177index d066037..5bb78d9 100644
75178--- a/mm/slab.c
75179+++ b/mm/slab.c
75180@@ -164,7 +164,7 @@ static bool pfmemalloc_active __read_mostly;
75181
75182 /* Legal flag mask for kmem_cache_create(). */
75183 #if DEBUG
75184-# define CREATE_MASK (SLAB_RED_ZONE | \
75185+# define CREATE_MASK (SLAB_USERCOPY | SLAB_RED_ZONE | \
75186 SLAB_POISON | SLAB_HWCACHE_ALIGN | \
75187 SLAB_CACHE_DMA | \
75188 SLAB_STORE_USER | \
75189@@ -172,7 +172,7 @@ static bool pfmemalloc_active __read_mostly;
75190 SLAB_DESTROY_BY_RCU | SLAB_MEM_SPREAD | \
75191 SLAB_DEBUG_OBJECTS | SLAB_NOLEAKTRACE | SLAB_NOTRACK)
75192 #else
75193-# define CREATE_MASK (SLAB_HWCACHE_ALIGN | \
75194+# define CREATE_MASK (SLAB_USERCOPY | SLAB_HWCACHE_ALIGN | \
75195 SLAB_CACHE_DMA | \
75196 SLAB_RECLAIM_ACCOUNT | SLAB_PANIC | \
75197 SLAB_DESTROY_BY_RCU | SLAB_MEM_SPREAD | \
75198@@ -322,7 +322,7 @@ struct kmem_list3 {
75199 * Need this for bootstrapping a per node allocator.
75200 */
75201 #define NUM_INIT_LISTS (3 * MAX_NUMNODES)
75202-static struct kmem_list3 __initdata initkmem_list3[NUM_INIT_LISTS];
75203+static struct kmem_list3 initkmem_list3[NUM_INIT_LISTS];
75204 #define CACHE_CACHE 0
75205 #define SIZE_AC MAX_NUMNODES
75206 #define SIZE_L3 (2 * MAX_NUMNODES)
75207@@ -423,10 +423,10 @@ static void kmem_list3_init(struct kmem_list3 *parent)
75208 if ((x)->max_freeable < i) \
75209 (x)->max_freeable = i; \
75210 } while (0)
75211-#define STATS_INC_ALLOCHIT(x) atomic_inc(&(x)->allochit)
75212-#define STATS_INC_ALLOCMISS(x) atomic_inc(&(x)->allocmiss)
75213-#define STATS_INC_FREEHIT(x) atomic_inc(&(x)->freehit)
75214-#define STATS_INC_FREEMISS(x) atomic_inc(&(x)->freemiss)
75215+#define STATS_INC_ALLOCHIT(x) atomic_inc_unchecked(&(x)->allochit)
75216+#define STATS_INC_ALLOCMISS(x) atomic_inc_unchecked(&(x)->allocmiss)
75217+#define STATS_INC_FREEHIT(x) atomic_inc_unchecked(&(x)->freehit)
75218+#define STATS_INC_FREEMISS(x) atomic_inc_unchecked(&(x)->freemiss)
75219 #else
75220 #define STATS_INC_ACTIVE(x) do { } while (0)
75221 #define STATS_DEC_ACTIVE(x) do { } while (0)
75222@@ -549,7 +549,7 @@ static inline void *index_to_obj(struct kmem_cache *cache, struct slab *slab,
75223 * reciprocal_divide(offset, cache->reciprocal_buffer_size)
75224 */
75225 static inline unsigned int obj_to_index(const struct kmem_cache *cache,
75226- const struct slab *slab, void *obj)
75227+ const struct slab *slab, const void *obj)
75228 {
75229 u32 offset = (obj - slab->s_mem);
75230 return reciprocal_divide(offset, cache->reciprocal_buffer_size);
75231@@ -570,12 +570,13 @@ EXPORT_SYMBOL(malloc_sizes);
75232 struct cache_names {
75233 char *name;
75234 char *name_dma;
75235+ char *name_usercopy;
75236 };
75237
75238 static struct cache_names __initdata cache_names[] = {
75239-#define CACHE(x) { .name = "size-" #x, .name_dma = "size-" #x "(DMA)" },
75240+#define CACHE(x) { .name = "size-" #x, .name_dma = "size-" #x "(DMA)", .name_usercopy = "size-" #x "(USERCOPY)" },
75241 #include <linux/kmalloc_sizes.h>
75242- {NULL,}
75243+ {NULL}
75244 #undef CACHE
75245 };
75246
75247@@ -736,6 +737,12 @@ static inline struct kmem_cache *__find_general_cachep(size_t size,
75248 if (unlikely(gfpflags & GFP_DMA))
75249 return csizep->cs_dmacachep;
75250 #endif
75251+
75252+#ifdef CONFIG_PAX_USERCOPY_SLABS
75253+ if (unlikely(gfpflags & GFP_USERCOPY))
75254+ return csizep->cs_usercopycachep;
75255+#endif
75256+
75257 return csizep->cs_cachep;
75258 }
75259
75260@@ -1684,7 +1691,7 @@ void __init kmem_cache_init(void)
75261 sizes[INDEX_AC].cs_cachep = __kmem_cache_create(names[INDEX_AC].name,
75262 sizes[INDEX_AC].cs_size,
75263 ARCH_KMALLOC_MINALIGN,
75264- ARCH_KMALLOC_FLAGS|SLAB_PANIC,
75265+ ARCH_KMALLOC_FLAGS|SLAB_PANIC|SLAB_USERCOPY,
75266 NULL);
75267
75268 if (INDEX_AC != INDEX_L3) {
75269@@ -1692,7 +1699,7 @@ void __init kmem_cache_init(void)
75270 __kmem_cache_create(names[INDEX_L3].name,
75271 sizes[INDEX_L3].cs_size,
75272 ARCH_KMALLOC_MINALIGN,
75273- ARCH_KMALLOC_FLAGS|SLAB_PANIC,
75274+ ARCH_KMALLOC_FLAGS|SLAB_PANIC|SLAB_USERCOPY,
75275 NULL);
75276 }
75277
75278@@ -1710,7 +1717,7 @@ void __init kmem_cache_init(void)
75279 sizes->cs_cachep = __kmem_cache_create(names->name,
75280 sizes->cs_size,
75281 ARCH_KMALLOC_MINALIGN,
75282- ARCH_KMALLOC_FLAGS|SLAB_PANIC,
75283+ ARCH_KMALLOC_FLAGS|SLAB_PANIC|SLAB_USERCOPY,
75284 NULL);
75285 }
75286 #ifdef CONFIG_ZONE_DMA
75287@@ -1722,6 +1729,16 @@ void __init kmem_cache_init(void)
75288 SLAB_PANIC,
75289 NULL);
75290 #endif
75291+
75292+#ifdef CONFIG_PAX_USERCOPY_SLABS
75293+ sizes->cs_usercopycachep = kmem_cache_create(
75294+ names->name_usercopy,
75295+ sizes->cs_size,
75296+ ARCH_KMALLOC_MINALIGN,
75297+ ARCH_KMALLOC_FLAGS|SLAB_PANIC|SLAB_USERCOPY,
75298+ NULL);
75299+#endif
75300+
75301 sizes++;
75302 names++;
75303 }
75304@@ -4467,10 +4484,10 @@ static int s_show(struct seq_file *m, void *p)
75305 }
75306 /* cpu stats */
75307 {
75308- unsigned long allochit = atomic_read(&cachep->allochit);
75309- unsigned long allocmiss = atomic_read(&cachep->allocmiss);
75310- unsigned long freehit = atomic_read(&cachep->freehit);
75311- unsigned long freemiss = atomic_read(&cachep->freemiss);
75312+ unsigned long allochit = atomic_read_unchecked(&cachep->allochit);
75313+ unsigned long allocmiss = atomic_read_unchecked(&cachep->allocmiss);
75314+ unsigned long freehit = atomic_read_unchecked(&cachep->freehit);
75315+ unsigned long freemiss = atomic_read_unchecked(&cachep->freemiss);
75316
75317 seq_printf(m, " : cpustat %6lu %6lu %6lu %6lu",
75318 allochit, allocmiss, freehit, freemiss);
75319@@ -4729,13 +4746,71 @@ static int __init slab_proc_init(void)
75320 {
75321 proc_create("slabinfo",S_IWUSR|S_IRUSR,NULL,&proc_slabinfo_operations);
75322 #ifdef CONFIG_DEBUG_SLAB_LEAK
75323- proc_create("slab_allocators", 0, NULL, &proc_slabstats_operations);
75324+ proc_create("slab_allocators", S_IRUSR, NULL, &proc_slabstats_operations);
75325 #endif
75326 return 0;
75327 }
75328 module_init(slab_proc_init);
75329 #endif
75330
75331+bool is_usercopy_object(const void *ptr)
75332+{
75333+ struct page *page;
75334+ struct kmem_cache *cachep;
75335+
75336+ if (ZERO_OR_NULL_PTR(ptr))
75337+ return false;
75338+
75339+ if (!slab_is_available())
75340+ return false;
75341+
75342+ if (!virt_addr_valid(ptr))
75343+ return false;
75344+
75345+ page = virt_to_head_page(ptr);
75346+
75347+ if (!PageSlab(page))
75348+ return false;
75349+
75350+ cachep = page_get_cache(page);
75351+ return cachep->flags & SLAB_USERCOPY;
75352+}
75353+
75354+#ifdef CONFIG_PAX_USERCOPY
75355+const char *check_heap_object(const void *ptr, unsigned long n, bool to)
75356+{
75357+ struct page *page;
75358+ struct kmem_cache *cachep;
75359+ struct slab *slabp;
75360+ unsigned int objnr;
75361+ unsigned long offset;
75362+
75363+ if (ZERO_OR_NULL_PTR(ptr))
75364+ return "<null>";
75365+
75366+ if (!virt_addr_valid(ptr))
75367+ return NULL;
75368+
75369+ page = virt_to_head_page(ptr);
75370+
75371+ if (!PageSlab(page))
75372+ return NULL;
75373+
75374+ cachep = page_get_cache(page);
75375+ if (!(cachep->flags & SLAB_USERCOPY))
75376+ return cachep->name;
75377+
75378+ slabp = page->slab_page;
75379+ objnr = obj_to_index(cachep, slabp, ptr);
75380+ BUG_ON(objnr >= cachep->num);
75381+ offset = ptr - index_to_obj(cachep, slabp, objnr) - obj_offset(cachep);
75382+ if (offset <= cachep->object_size && n <= cachep->object_size - offset)
75383+ return NULL;
75384+
75385+ return cachep->name;
75386+}
75387+#endif
75388+
75389 /**
75390 * ksize - get the actual amount of memory allocated for a given object
75391 * @objp: Pointer to the object
75392diff --git a/mm/slob.c b/mm/slob.c
75393index 45d4ca7..88943c1 100644
75394--- a/mm/slob.c
75395+++ b/mm/slob.c
75396@@ -159,7 +159,7 @@ static void set_slob(slob_t *s, slobidx_t size, slob_t *next)
75397 /*
75398 * Return the size of a slob block.
75399 */
75400-static slobidx_t slob_units(slob_t *s)
75401+static slobidx_t slob_units(const slob_t *s)
75402 {
75403 if (s->units > 0)
75404 return s->units;
75405@@ -169,7 +169,7 @@ static slobidx_t slob_units(slob_t *s)
75406 /*
75407 * Return the next free slob block pointer after this one.
75408 */
75409-static slob_t *slob_next(slob_t *s)
75410+static slob_t *slob_next(const slob_t *s)
75411 {
75412 slob_t *base = (slob_t *)((unsigned long)s & PAGE_MASK);
75413 slobidx_t next;
75414@@ -184,14 +184,14 @@ static slob_t *slob_next(slob_t *s)
75415 /*
75416 * Returns true if s is the last free block in its page.
75417 */
75418-static int slob_last(slob_t *s)
75419+static int slob_last(const slob_t *s)
75420 {
75421 return !((unsigned long)slob_next(s) & ~PAGE_MASK);
75422 }
75423
75424-static void *slob_new_pages(gfp_t gfp, int order, int node)
75425+static struct page *slob_new_pages(gfp_t gfp, unsigned int order, int node)
75426 {
75427- void *page;
75428+ struct page *page;
75429
75430 #ifdef CONFIG_NUMA
75431 if (node != -1)
75432@@ -203,14 +203,18 @@ static void *slob_new_pages(gfp_t gfp, int order, int node)
75433 if (!page)
75434 return NULL;
75435
75436- return page_address(page);
75437+ __SetPageSlab(page);
75438+ return page;
75439 }
75440
75441-static void slob_free_pages(void *b, int order)
75442+static void slob_free_pages(struct page *sp, int order)
75443 {
75444 if (current->reclaim_state)
75445 current->reclaim_state->reclaimed_slab += 1 << order;
75446- free_pages((unsigned long)b, order);
75447+ __ClearPageSlab(sp);
75448+ reset_page_mapcount(sp);
75449+ sp->private = 0;
75450+ __free_pages(sp, order);
75451 }
75452
75453 /*
75454@@ -315,15 +319,15 @@ static void *slob_alloc(size_t size, gfp_t gfp, int align, int node)
75455
75456 /* Not enough space: must allocate a new page */
75457 if (!b) {
75458- b = slob_new_pages(gfp & ~__GFP_ZERO, 0, node);
75459- if (!b)
75460+ sp = slob_new_pages(gfp & ~__GFP_ZERO, 0, node);
75461+ if (!sp)
75462 return NULL;
75463- sp = virt_to_page(b);
75464- __SetPageSlab(sp);
75465+ b = page_address(sp);
75466
75467 spin_lock_irqsave(&slob_lock, flags);
75468 sp->units = SLOB_UNITS(PAGE_SIZE);
75469 sp->freelist = b;
75470+ sp->private = 0;
75471 INIT_LIST_HEAD(&sp->list);
75472 set_slob(b, SLOB_UNITS(PAGE_SIZE), b + SLOB_UNITS(PAGE_SIZE));
75473 set_slob_page_free(sp, slob_list);
75474@@ -361,9 +365,7 @@ static void slob_free(void *block, int size)
75475 if (slob_page_free(sp))
75476 clear_slob_page_free(sp);
75477 spin_unlock_irqrestore(&slob_lock, flags);
75478- __ClearPageSlab(sp);
75479- reset_page_mapcount(sp);
75480- slob_free_pages(b, 0);
75481+ slob_free_pages(sp, 0);
75482 return;
75483 }
75484
75485@@ -425,11 +427,10 @@ out:
75486 * End of slob allocator proper. Begin kmem_cache_alloc and kmalloc frontend.
75487 */
75488
75489-void *__kmalloc_node(size_t size, gfp_t gfp, int node)
75490+static void *__kmalloc_node_align(size_t size, gfp_t gfp, int node, int align)
75491 {
75492- unsigned int *m;
75493- int align = max(ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
75494- void *ret;
75495+ slob_t *m;
75496+ void *ret = NULL;
75497
75498 gfp &= gfp_allowed_mask;
75499
75500@@ -443,20 +444,23 @@ void *__kmalloc_node(size_t size, gfp_t gfp, int node)
75501
75502 if (!m)
75503 return NULL;
75504- *m = size;
75505+ BUILD_BUG_ON(ARCH_KMALLOC_MINALIGN < 2 * SLOB_UNIT);
75506+ BUILD_BUG_ON(ARCH_SLAB_MINALIGN < 2 * SLOB_UNIT);
75507+ m[0].units = size;
75508+ m[1].units = align;
75509 ret = (void *)m + align;
75510
75511 trace_kmalloc_node(_RET_IP_, ret,
75512 size, size + align, gfp, node);
75513 } else {
75514 unsigned int order = get_order(size);
75515+ struct page *page;
75516
75517 if (likely(order))
75518 gfp |= __GFP_COMP;
75519- ret = slob_new_pages(gfp, order, node);
75520- if (ret) {
75521- struct page *page;
75522- page = virt_to_page(ret);
75523+ page = slob_new_pages(gfp, order, node);
75524+ if (page) {
75525+ ret = page_address(page);
75526 page->private = size;
75527 }
75528
75529@@ -464,7 +468,16 @@ void *__kmalloc_node(size_t size, gfp_t gfp, int node)
75530 size, PAGE_SIZE << order, gfp, node);
75531 }
75532
75533- kmemleak_alloc(ret, size, 1, gfp);
75534+ return ret;
75535+}
75536+
75537+void *__kmalloc_node(size_t size, gfp_t gfp, int node)
75538+{
75539+ int align = max(ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
75540+ void *ret = __kmalloc_node_align(size, gfp, node, align);
75541+
75542+ if (!ZERO_OR_NULL_PTR(ret))
75543+ kmemleak_alloc(ret, size, 1, gfp);
75544 return ret;
75545 }
75546 EXPORT_SYMBOL(__kmalloc_node);
75547@@ -480,15 +493,91 @@ void kfree(const void *block)
75548 kmemleak_free(block);
75549
75550 sp = virt_to_page(block);
75551- if (PageSlab(sp)) {
75552+ VM_BUG_ON(!PageSlab(sp));
75553+ if (!sp->private) {
75554 int align = max(ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
75555- unsigned int *m = (unsigned int *)(block - align);
75556- slob_free(m, *m + align);
75557- } else
75558+ slob_t *m = (slob_t *)(block - align);
75559+ slob_free(m, m[0].units + align);
75560+ } else {
75561+ __ClearPageSlab(sp);
75562+ reset_page_mapcount(sp);
75563+ sp->private = 0;
75564 put_page(sp);
75565+ }
75566 }
75567 EXPORT_SYMBOL(kfree);
75568
75569+bool is_usercopy_object(const void *ptr)
75570+{
75571+ if (!slab_is_available())
75572+ return false;
75573+
75574+ // PAX: TODO
75575+
75576+ return false;
75577+}
75578+
75579+#ifdef CONFIG_PAX_USERCOPY
75580+const char *check_heap_object(const void *ptr, unsigned long n, bool to)
75581+{
75582+ struct page *page;
75583+ const slob_t *free;
75584+ const void *base;
75585+ unsigned long flags;
75586+
75587+ if (ZERO_OR_NULL_PTR(ptr))
75588+ return "<null>";
75589+
75590+ if (!virt_addr_valid(ptr))
75591+ return NULL;
75592+
75593+ page = virt_to_head_page(ptr);
75594+ if (!PageSlab(page))
75595+ return NULL;
75596+
75597+ if (page->private) {
75598+ base = page;
75599+ if (base <= ptr && n <= page->private - (ptr - base))
75600+ return NULL;
75601+ return "<slob>";
75602+ }
75603+
75604+ /* some tricky double walking to find the chunk */
75605+ spin_lock_irqsave(&slob_lock, flags);
75606+ base = (void *)((unsigned long)ptr & PAGE_MASK);
75607+ free = page->freelist;
75608+
75609+ while (!slob_last(free) && (void *)free <= ptr) {
75610+ base = free + slob_units(free);
75611+ free = slob_next(free);
75612+ }
75613+
75614+ while (base < (void *)free) {
75615+ slobidx_t m = ((slob_t *)base)[0].units, align = ((slob_t *)base)[1].units;
75616+ int size = SLOB_UNIT * SLOB_UNITS(m + align);
75617+ int offset;
75618+
75619+ if (ptr < base + align)
75620+ break;
75621+
75622+ offset = ptr - base - align;
75623+ if (offset >= m) {
75624+ base += size;
75625+ continue;
75626+ }
75627+
75628+ if (n > m - offset)
75629+ break;
75630+
75631+ spin_unlock_irqrestore(&slob_lock, flags);
75632+ return NULL;
75633+ }
75634+
75635+ spin_unlock_irqrestore(&slob_lock, flags);
75636+ return "<slob>";
75637+}
75638+#endif
75639+
75640 /* can't use ksize for kmem_cache_alloc memory, only kmalloc */
75641 size_t ksize(const void *block)
75642 {
75643@@ -499,10 +588,11 @@ size_t ksize(const void *block)
75644 return 0;
75645
75646 sp = virt_to_page(block);
75647- if (PageSlab(sp)) {
75648+ VM_BUG_ON(!PageSlab(sp));
75649+ if (!sp->private) {
75650 int align = max(ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
75651- unsigned int *m = (unsigned int *)(block - align);
75652- return SLOB_UNITS(*m) * SLOB_UNIT;
75653+ slob_t *m = (slob_t *)(block - align);
75654+ return SLOB_UNITS(m[0].units) * SLOB_UNIT;
75655 } else
75656 return sp->private;
75657 }
75658@@ -513,8 +603,13 @@ struct kmem_cache *__kmem_cache_create(const char *name, size_t size,
75659 {
75660 struct kmem_cache *c;
75661
75662+#ifdef CONFIG_PAX_USERCOPY_SLABS
75663+ c = __kmalloc_node_align(sizeof(struct kmem_cache),
75664+ GFP_KERNEL, -1, ARCH_KMALLOC_MINALIGN);
75665+#else
75666 c = slob_alloc(sizeof(struct kmem_cache),
75667 GFP_KERNEL, ARCH_KMALLOC_MINALIGN, -1);
75668+#endif
75669
75670 if (c) {
75671 c->name = name;
75672@@ -549,23 +644,33 @@ EXPORT_SYMBOL(kmem_cache_destroy);
75673
75674 void *kmem_cache_alloc_node(struct kmem_cache *c, gfp_t flags, int node)
75675 {
75676- void *b;
75677+ void *b = NULL;
75678
75679 flags &= gfp_allowed_mask;
75680
75681 lockdep_trace_alloc(flags);
75682
75683+#ifdef CONFIG_PAX_USERCOPY_SLABS
75684+ b = __kmalloc_node_align(c->size, flags, node, c->align);
75685+#else
75686 if (c->size < PAGE_SIZE) {
75687 b = slob_alloc(c->size, flags, c->align, node);
75688 trace_kmem_cache_alloc_node(_RET_IP_, b, c->size,
75689 SLOB_UNITS(c->size) * SLOB_UNIT,
75690 flags, node);
75691 } else {
75692- b = slob_new_pages(flags, get_order(c->size), node);
75693+ struct page *sp;
75694+
75695+ sp = slob_new_pages(flags, get_order(c->size), node);
75696+ if (sp) {
75697+ b = page_address(sp);
75698+ sp->private = c->size;
75699+ }
75700 trace_kmem_cache_alloc_node(_RET_IP_, b, c->size,
75701 PAGE_SIZE << get_order(c->size),
75702 flags, node);
75703 }
75704+#endif
75705
75706 if (c->ctor)
75707 c->ctor(b);
75708@@ -577,10 +682,14 @@ EXPORT_SYMBOL(kmem_cache_alloc_node);
75709
75710 static void __kmem_cache_free(void *b, int size)
75711 {
75712- if (size < PAGE_SIZE)
75713+ struct page *sp;
75714+
75715+ sp = virt_to_page(b);
75716+ BUG_ON(!PageSlab(sp));
75717+ if (!sp->private)
75718 slob_free(b, size);
75719 else
75720- slob_free_pages(b, get_order(size));
75721+ slob_free_pages(sp, get_order(size));
75722 }
75723
75724 static void kmem_rcu_free(struct rcu_head *head)
75725@@ -593,17 +702,31 @@ static void kmem_rcu_free(struct rcu_head *head)
75726
75727 void kmem_cache_free(struct kmem_cache *c, void *b)
75728 {
75729+ int size = c->size;
75730+
75731+#ifdef CONFIG_PAX_USERCOPY_SLABS
75732+ if (size + c->align < PAGE_SIZE) {
75733+ size += c->align;
75734+ b -= c->align;
75735+ }
75736+#endif
75737+
75738 kmemleak_free_recursive(b, c->flags);
75739 if (unlikely(c->flags & SLAB_DESTROY_BY_RCU)) {
75740 struct slob_rcu *slob_rcu;
75741- slob_rcu = b + (c->size - sizeof(struct slob_rcu));
75742- slob_rcu->size = c->size;
75743+ slob_rcu = b + (size - sizeof(struct slob_rcu));
75744+ slob_rcu->size = size;
75745 call_rcu(&slob_rcu->head, kmem_rcu_free);
75746 } else {
75747- __kmem_cache_free(b, c->size);
75748+ __kmem_cache_free(b, size);
75749 }
75750
75751+#ifdef CONFIG_PAX_USERCOPY_SLABS
75752+ trace_kfree(_RET_IP_, b);
75753+#else
75754 trace_kmem_cache_free(_RET_IP_, b);
75755+#endif
75756+
75757 }
75758 EXPORT_SYMBOL(kmem_cache_free);
75759
75760diff --git a/mm/slub.c b/mm/slub.c
75761index 2fdd96f..1e2f893 100644
75762--- a/mm/slub.c
75763+++ b/mm/slub.c
75764@@ -201,7 +201,7 @@ struct track {
75765
75766 enum track_item { TRACK_ALLOC, TRACK_FREE };
75767
75768-#ifdef CONFIG_SYSFS
75769+#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
75770 static int sysfs_slab_add(struct kmem_cache *);
75771 static int sysfs_slab_alias(struct kmem_cache *, const char *);
75772 static void sysfs_slab_remove(struct kmem_cache *);
75773@@ -525,7 +525,7 @@ static void print_track(const char *s, struct track *t)
75774 if (!t->addr)
75775 return;
75776
75777- printk(KERN_ERR "INFO: %s in %pS age=%lu cpu=%u pid=%d\n",
75778+ printk(KERN_ERR "INFO: %s in %pA age=%lu cpu=%u pid=%d\n",
75779 s, (void *)t->addr, jiffies - t->when, t->cpu, t->pid);
75780 #ifdef CONFIG_STACKTRACE
75781 {
75782@@ -2612,6 +2612,8 @@ void kmem_cache_free(struct kmem_cache *s, void *x)
75783
75784 page = virt_to_head_page(x);
75785
75786+ BUG_ON(!PageSlab(page));
75787+
75788 slab_free(s, page, x, _RET_IP_);
75789
75790 trace_kmem_cache_free(_RET_IP_, x);
75791@@ -2645,7 +2647,7 @@ static int slub_min_objects;
75792 * Merge control. If this is set then no merging of slab caches will occur.
75793 * (Could be removed. This was introduced to pacify the merge skeptics.)
75794 */
75795-static int slub_nomerge;
75796+static int slub_nomerge = 1;
75797
75798 /*
75799 * Calculate the order of allocation given an slab object size.
75800@@ -3098,7 +3100,7 @@ static int kmem_cache_open(struct kmem_cache *s,
75801 else
75802 s->cpu_partial = 30;
75803
75804- s->refcount = 1;
75805+ atomic_set(&s->refcount, 1);
75806 #ifdef CONFIG_NUMA
75807 s->remote_node_defrag_ratio = 1000;
75808 #endif
75809@@ -3202,8 +3204,7 @@ static inline int kmem_cache_close(struct kmem_cache *s)
75810 void kmem_cache_destroy(struct kmem_cache *s)
75811 {
75812 mutex_lock(&slab_mutex);
75813- s->refcount--;
75814- if (!s->refcount) {
75815+ if (atomic_dec_and_test(&s->refcount)) {
75816 list_del(&s->list);
75817 mutex_unlock(&slab_mutex);
75818 if (kmem_cache_close(s)) {
75819@@ -3232,6 +3233,10 @@ static struct kmem_cache *kmem_cache;
75820 static struct kmem_cache *kmalloc_dma_caches[SLUB_PAGE_SHIFT];
75821 #endif
75822
75823+#ifdef CONFIG_PAX_USERCOPY_SLABS
75824+static struct kmem_cache *kmalloc_usercopy_caches[SLUB_PAGE_SHIFT];
75825+#endif
75826+
75827 static int __init setup_slub_min_order(char *str)
75828 {
75829 get_option(&str, &slub_min_order);
75830@@ -3346,6 +3351,13 @@ static struct kmem_cache *get_slab(size_t size, gfp_t flags)
75831 return kmalloc_dma_caches[index];
75832
75833 #endif
75834+
75835+#ifdef CONFIG_PAX_USERCOPY_SLABS
75836+ if (flags & SLAB_USERCOPY)
75837+ return kmalloc_usercopy_caches[index];
75838+
75839+#endif
75840+
75841 return kmalloc_caches[index];
75842 }
75843
75844@@ -3414,6 +3426,59 @@ void *__kmalloc_node(size_t size, gfp_t flags, int node)
75845 EXPORT_SYMBOL(__kmalloc_node);
75846 #endif
75847
75848+bool is_usercopy_object(const void *ptr)
75849+{
75850+ struct page *page;
75851+ struct kmem_cache *s;
75852+
75853+ if (ZERO_OR_NULL_PTR(ptr))
75854+ return false;
75855+
75856+ if (!slab_is_available())
75857+ return false;
75858+
75859+ if (!virt_addr_valid(ptr))
75860+ return false;
75861+
75862+ page = virt_to_head_page(ptr);
75863+
75864+ if (!PageSlab(page))
75865+ return false;
75866+
75867+ s = page->slab;
75868+ return s->flags & SLAB_USERCOPY;
75869+}
75870+
75871+#ifdef CONFIG_PAX_USERCOPY
75872+const char *check_heap_object(const void *ptr, unsigned long n, bool to)
75873+{
75874+ struct page *page;
75875+ struct kmem_cache *s;
75876+ unsigned long offset;
75877+
75878+ if (ZERO_OR_NULL_PTR(ptr))
75879+ return "<null>";
75880+
75881+ if (!virt_addr_valid(ptr))
75882+ return NULL;
75883+
75884+ page = virt_to_head_page(ptr);
75885+
75886+ if (!PageSlab(page))
75887+ return NULL;
75888+
75889+ s = page->slab;
75890+ if (!(s->flags & SLAB_USERCOPY))
75891+ return s->name;
75892+
75893+ offset = (ptr - page_address(page)) % s->size;
75894+ if (offset <= s->object_size && n <= s->object_size - offset)
75895+ return NULL;
75896+
75897+ return s->name;
75898+}
75899+#endif
75900+
75901 size_t ksize(const void *object)
75902 {
75903 struct page *page;
75904@@ -3688,7 +3753,7 @@ static void __init kmem_cache_bootstrap_fixup(struct kmem_cache *s)
75905 int node;
75906
75907 list_add(&s->list, &slab_caches);
75908- s->refcount = -1;
75909+ atomic_set(&s->refcount, -1);
75910
75911 for_each_node_state(node, N_NORMAL_MEMORY) {
75912 struct kmem_cache_node *n = get_node(s, node);
75913@@ -3808,17 +3873,17 @@ void __init kmem_cache_init(void)
75914
75915 /* Caches that are not of the two-to-the-power-of size */
75916 if (KMALLOC_MIN_SIZE <= 32) {
75917- kmalloc_caches[1] = create_kmalloc_cache("kmalloc-96", 96, 0);
75918+ kmalloc_caches[1] = create_kmalloc_cache("kmalloc-96", 96, SLAB_USERCOPY);
75919 caches++;
75920 }
75921
75922 if (KMALLOC_MIN_SIZE <= 64) {
75923- kmalloc_caches[2] = create_kmalloc_cache("kmalloc-192", 192, 0);
75924+ kmalloc_caches[2] = create_kmalloc_cache("kmalloc-192", 192, SLAB_USERCOPY);
75925 caches++;
75926 }
75927
75928 for (i = KMALLOC_SHIFT_LOW; i < SLUB_PAGE_SHIFT; i++) {
75929- kmalloc_caches[i] = create_kmalloc_cache("kmalloc", 1 << i, 0);
75930+ kmalloc_caches[i] = create_kmalloc_cache("kmalloc", 1 << i, SLAB_USERCOPY);
75931 caches++;
75932 }
75933
75934@@ -3860,6 +3925,22 @@ void __init kmem_cache_init(void)
75935 }
75936 }
75937 #endif
75938+
75939+#ifdef CONFIG_PAX_USERCOPY_SLABS
75940+ for (i = 0; i < SLUB_PAGE_SHIFT; i++) {
75941+ struct kmem_cache *s = kmalloc_caches[i];
75942+
75943+ if (s && s->size) {
75944+ char *name = kasprintf(GFP_NOWAIT,
75945+ "usercopy-kmalloc-%d", s->object_size);
75946+
75947+ BUG_ON(!name);
75948+ kmalloc_usercopy_caches[i] = create_kmalloc_cache(name,
75949+ s->object_size, SLAB_USERCOPY);
75950+ }
75951+ }
75952+#endif
75953+
75954 printk(KERN_INFO
75955 "SLUB: Genslabs=%d, HWalign=%d, Order=%d-%d, MinObjects=%d,"
75956 " CPUs=%d, Nodes=%d\n",
75957@@ -3886,7 +3967,7 @@ static int slab_unmergeable(struct kmem_cache *s)
75958 /*
75959 * We may have set a slab to be unmergeable during bootstrap.
75960 */
75961- if (s->refcount < 0)
75962+ if (atomic_read(&s->refcount) < 0)
75963 return 1;
75964
75965 return 0;
75966@@ -3941,7 +4022,7 @@ struct kmem_cache *__kmem_cache_create(const char *name, size_t size,
75967
75968 s = find_mergeable(size, align, flags, name, ctor);
75969 if (s) {
75970- s->refcount++;
75971+ atomic_inc(&s->refcount);
75972 /*
75973 * Adjust the object sizes so that we clear
75974 * the complete object on kzalloc.
75975@@ -3950,7 +4031,7 @@ struct kmem_cache *__kmem_cache_create(const char *name, size_t size,
75976 s->inuse = max_t(int, s->inuse, ALIGN(size, sizeof(void *)));
75977
75978 if (sysfs_slab_alias(s, name)) {
75979- s->refcount--;
75980+ atomic_dec(&s->refcount);
75981 return NULL;
75982 }
75983 return s;
75984@@ -4072,7 +4153,7 @@ void *__kmalloc_node_track_caller(size_t size, gfp_t gfpflags,
75985 }
75986 #endif
75987
75988-#ifdef CONFIG_SYSFS
75989+#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
75990 static int count_inuse(struct page *page)
75991 {
75992 return page->inuse;
75993@@ -4459,12 +4540,12 @@ static void resiliency_test(void)
75994 validate_slab_cache(kmalloc_caches[9]);
75995 }
75996 #else
75997-#ifdef CONFIG_SYSFS
75998+#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
75999 static void resiliency_test(void) {};
76000 #endif
76001 #endif
76002
76003-#ifdef CONFIG_SYSFS
76004+#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
76005 enum slab_stat_type {
76006 SL_ALL, /* All slabs */
76007 SL_PARTIAL, /* Only partially allocated slabs */
76008@@ -4708,7 +4789,7 @@ SLAB_ATTR_RO(ctor);
76009
76010 static ssize_t aliases_show(struct kmem_cache *s, char *buf)
76011 {
76012- return sprintf(buf, "%d\n", s->refcount - 1);
76013+ return sprintf(buf, "%d\n", atomic_read(&s->refcount) - 1);
76014 }
76015 SLAB_ATTR_RO(aliases);
76016
76017@@ -5279,6 +5360,7 @@ static char *create_unique_id(struct kmem_cache *s)
76018 return name;
76019 }
76020
76021+#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
76022 static int sysfs_slab_add(struct kmem_cache *s)
76023 {
76024 int err;
76025@@ -5341,6 +5423,7 @@ static void sysfs_slab_remove(struct kmem_cache *s)
76026 kobject_del(&s->kobj);
76027 kobject_put(&s->kobj);
76028 }
76029+#endif
76030
76031 /*
76032 * Need to buffer aliases during bootup until sysfs becomes
76033@@ -5354,6 +5437,7 @@ struct saved_alias {
76034
76035 static struct saved_alias *alias_list;
76036
76037+#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
76038 static int sysfs_slab_alias(struct kmem_cache *s, const char *name)
76039 {
76040 struct saved_alias *al;
76041@@ -5376,6 +5460,7 @@ static int sysfs_slab_alias(struct kmem_cache *s, const char *name)
76042 alias_list = al;
76043 return 0;
76044 }
76045+#endif
76046
76047 static int __init slab_sysfs_init(void)
76048 {
76049diff --git a/mm/sparse-vmemmap.c b/mm/sparse-vmemmap.c
76050index 1b7e22a..3fcd4f3 100644
76051--- a/mm/sparse-vmemmap.c
76052+++ b/mm/sparse-vmemmap.c
76053@@ -128,7 +128,7 @@ pud_t * __meminit vmemmap_pud_populate(pgd_t *pgd, unsigned long addr, int node)
76054 void *p = vmemmap_alloc_block(PAGE_SIZE, node);
76055 if (!p)
76056 return NULL;
76057- pud_populate(&init_mm, pud, p);
76058+ pud_populate_kernel(&init_mm, pud, p);
76059 }
76060 return pud;
76061 }
76062@@ -140,7 +140,7 @@ pgd_t * __meminit vmemmap_pgd_populate(unsigned long addr, int node)
76063 void *p = vmemmap_alloc_block(PAGE_SIZE, node);
76064 if (!p)
76065 return NULL;
76066- pgd_populate(&init_mm, pgd, p);
76067+ pgd_populate_kernel(&init_mm, pgd, p);
76068 }
76069 return pgd;
76070 }
76071diff --git a/mm/swap.c b/mm/swap.c
76072index 7782588..228c784 100644
76073--- a/mm/swap.c
76074+++ b/mm/swap.c
76075@@ -30,6 +30,7 @@
76076 #include <linux/backing-dev.h>
76077 #include <linux/memcontrol.h>
76078 #include <linux/gfp.h>
76079+#include <linux/hugetlb.h>
76080
76081 #include "internal.h"
76082
76083@@ -72,6 +73,8 @@ static void __put_compound_page(struct page *page)
76084
76085 __page_cache_release(page);
76086 dtor = get_compound_page_dtor(page);
76087+ if (!PageHuge(page))
76088+ BUG_ON(dtor != free_compound_page);
76089 (*dtor)(page);
76090 }
76091
76092diff --git a/mm/swapfile.c b/mm/swapfile.c
76093index 14e254c..a6af32c 100644
76094--- a/mm/swapfile.c
76095+++ b/mm/swapfile.c
76096@@ -64,7 +64,7 @@ static DEFINE_MUTEX(swapon_mutex);
76097
76098 static DECLARE_WAIT_QUEUE_HEAD(proc_poll_wait);
76099 /* Activity counter to indicate that a swapon or swapoff has occurred */
76100-static atomic_t proc_poll_event = ATOMIC_INIT(0);
76101+static atomic_unchecked_t proc_poll_event = ATOMIC_INIT(0);
76102
76103 static inline unsigned char swap_count(unsigned char ent)
76104 {
76105@@ -1603,7 +1603,7 @@ SYSCALL_DEFINE1(swapoff, const char __user *, specialfile)
76106 }
76107 filp_close(swap_file, NULL);
76108 err = 0;
76109- atomic_inc(&proc_poll_event);
76110+ atomic_inc_unchecked(&proc_poll_event);
76111 wake_up_interruptible(&proc_poll_wait);
76112
76113 out_dput:
76114@@ -1619,8 +1619,8 @@ static unsigned swaps_poll(struct file *file, poll_table *wait)
76115
76116 poll_wait(file, &proc_poll_wait, wait);
76117
76118- if (seq->poll_event != atomic_read(&proc_poll_event)) {
76119- seq->poll_event = atomic_read(&proc_poll_event);
76120+ if (seq->poll_event != atomic_read_unchecked(&proc_poll_event)) {
76121+ seq->poll_event = atomic_read_unchecked(&proc_poll_event);
76122 return POLLIN | POLLRDNORM | POLLERR | POLLPRI;
76123 }
76124
76125@@ -1718,7 +1718,7 @@ static int swaps_open(struct inode *inode, struct file *file)
76126 return ret;
76127
76128 seq = file->private_data;
76129- seq->poll_event = atomic_read(&proc_poll_event);
76130+ seq->poll_event = atomic_read_unchecked(&proc_poll_event);
76131 return 0;
76132 }
76133
76134@@ -2060,7 +2060,7 @@ SYSCALL_DEFINE2(swapon, const char __user *, specialfile, int, swap_flags)
76135 (frontswap_map) ? "FS" : "");
76136
76137 mutex_unlock(&swapon_mutex);
76138- atomic_inc(&proc_poll_event);
76139+ atomic_inc_unchecked(&proc_poll_event);
76140 wake_up_interruptible(&proc_poll_wait);
76141
76142 if (S_ISREG(inode->i_mode))
76143diff --git a/mm/util.c b/mm/util.c
76144index 8c7265a..c96d884 100644
76145--- a/mm/util.c
76146+++ b/mm/util.c
76147@@ -285,6 +285,12 @@ done:
76148 void arch_pick_mmap_layout(struct mm_struct *mm)
76149 {
76150 mm->mmap_base = TASK_UNMAPPED_BASE;
76151+
76152+#ifdef CONFIG_PAX_RANDMMAP
76153+ if (mm->pax_flags & MF_PAX_RANDMMAP)
76154+ mm->mmap_base += mm->delta_mmap;
76155+#endif
76156+
76157 mm->get_unmapped_area = arch_get_unmapped_area;
76158 mm->unmap_area = arch_unmap_area;
76159 }
76160diff --git a/mm/vmalloc.c b/mm/vmalloc.c
76161index 2bb90b1..3795e47 100644
76162--- a/mm/vmalloc.c
76163+++ b/mm/vmalloc.c
76164@@ -39,8 +39,19 @@ static void vunmap_pte_range(pmd_t *pmd, unsigned long addr, unsigned long end)
76165
76166 pte = pte_offset_kernel(pmd, addr);
76167 do {
76168- pte_t ptent = ptep_get_and_clear(&init_mm, addr, pte);
76169- WARN_ON(!pte_none(ptent) && !pte_present(ptent));
76170+
76171+#if defined(CONFIG_MODULES) && defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
76172+ if ((unsigned long)MODULES_EXEC_VADDR <= addr && addr < (unsigned long)MODULES_EXEC_END) {
76173+ BUG_ON(!pte_exec(*pte));
76174+ set_pte_at(&init_mm, addr, pte, pfn_pte(__pa(addr) >> PAGE_SHIFT, PAGE_KERNEL_EXEC));
76175+ continue;
76176+ }
76177+#endif
76178+
76179+ {
76180+ pte_t ptent = ptep_get_and_clear(&init_mm, addr, pte);
76181+ WARN_ON(!pte_none(ptent) && !pte_present(ptent));
76182+ }
76183 } while (pte++, addr += PAGE_SIZE, addr != end);
76184 }
76185
76186@@ -100,16 +111,29 @@ static int vmap_pte_range(pmd_t *pmd, unsigned long addr,
76187 pte = pte_alloc_kernel(pmd, addr);
76188 if (!pte)
76189 return -ENOMEM;
76190+
76191+ pax_open_kernel();
76192 do {
76193 struct page *page = pages[*nr];
76194
76195- if (WARN_ON(!pte_none(*pte)))
76196+#if defined(CONFIG_MODULES) && defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
76197+ if (pgprot_val(prot) & _PAGE_NX)
76198+#endif
76199+
76200+ if (!pte_none(*pte)) {
76201+ pax_close_kernel();
76202+ WARN_ON(1);
76203 return -EBUSY;
76204- if (WARN_ON(!page))
76205+ }
76206+ if (!page) {
76207+ pax_close_kernel();
76208+ WARN_ON(1);
76209 return -ENOMEM;
76210+ }
76211 set_pte_at(&init_mm, addr, pte, mk_pte(page, prot));
76212 (*nr)++;
76213 } while (pte++, addr += PAGE_SIZE, addr != end);
76214+ pax_close_kernel();
76215 return 0;
76216 }
76217
76218@@ -119,7 +143,7 @@ static int vmap_pmd_range(pud_t *pud, unsigned long addr,
76219 pmd_t *pmd;
76220 unsigned long next;
76221
76222- pmd = pmd_alloc(&init_mm, pud, addr);
76223+ pmd = pmd_alloc_kernel(&init_mm, pud, addr);
76224 if (!pmd)
76225 return -ENOMEM;
76226 do {
76227@@ -136,7 +160,7 @@ static int vmap_pud_range(pgd_t *pgd, unsigned long addr,
76228 pud_t *pud;
76229 unsigned long next;
76230
76231- pud = pud_alloc(&init_mm, pgd, addr);
76232+ pud = pud_alloc_kernel(&init_mm, pgd, addr);
76233 if (!pud)
76234 return -ENOMEM;
76235 do {
76236@@ -191,11 +215,20 @@ int is_vmalloc_or_module_addr(const void *x)
76237 * and fall back on vmalloc() if that fails. Others
76238 * just put it in the vmalloc space.
76239 */
76240-#if defined(CONFIG_MODULES) && defined(MODULES_VADDR)
76241+#ifdef CONFIG_MODULES
76242+#ifdef MODULES_VADDR
76243 unsigned long addr = (unsigned long)x;
76244 if (addr >= MODULES_VADDR && addr < MODULES_END)
76245 return 1;
76246 #endif
76247+
76248+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
76249+ if (x >= (const void *)MODULES_EXEC_VADDR && x < (const void *)MODULES_EXEC_END)
76250+ return 1;
76251+#endif
76252+
76253+#endif
76254+
76255 return is_vmalloc_addr(x);
76256 }
76257
76258@@ -216,8 +249,14 @@ struct page *vmalloc_to_page(const void *vmalloc_addr)
76259
76260 if (!pgd_none(*pgd)) {
76261 pud_t *pud = pud_offset(pgd, addr);
76262+#ifdef CONFIG_X86
76263+ if (!pud_large(*pud))
76264+#endif
76265 if (!pud_none(*pud)) {
76266 pmd_t *pmd = pmd_offset(pud, addr);
76267+#ifdef CONFIG_X86
76268+ if (!pmd_large(*pmd))
76269+#endif
76270 if (!pmd_none(*pmd)) {
76271 pte_t *ptep, pte;
76272
76273@@ -329,7 +368,7 @@ static void purge_vmap_area_lazy(void);
76274 * Allocate a region of KVA of the specified size and alignment, within the
76275 * vstart and vend.
76276 */
76277-static struct vmap_area *alloc_vmap_area(unsigned long size,
76278+static __size_overflow(1) struct vmap_area *alloc_vmap_area(unsigned long size,
76279 unsigned long align,
76280 unsigned long vstart, unsigned long vend,
76281 int node, gfp_t gfp_mask)
76282@@ -1328,6 +1367,16 @@ static struct vm_struct *__get_vm_area_node(unsigned long size,
76283 struct vm_struct *area;
76284
76285 BUG_ON(in_interrupt());
76286+
76287+#if defined(CONFIG_MODULES) && defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
76288+ if (flags & VM_KERNEXEC) {
76289+ if (start != VMALLOC_START || end != VMALLOC_END)
76290+ return NULL;
76291+ start = (unsigned long)MODULES_EXEC_VADDR;
76292+ end = (unsigned long)MODULES_EXEC_END;
76293+ }
76294+#endif
76295+
76296 if (flags & VM_IOREMAP) {
76297 int bit = fls(size);
76298
76299@@ -1568,6 +1617,11 @@ void *vmap(struct page **pages, unsigned int count,
76300 if (count > totalram_pages)
76301 return NULL;
76302
76303+#if defined(CONFIG_MODULES) && defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
76304+ if (!(pgprot_val(prot) & _PAGE_NX))
76305+ flags |= VM_KERNEXEC;
76306+#endif
76307+
76308 area = get_vm_area_caller((count << PAGE_SHIFT), flags,
76309 __builtin_return_address(0));
76310 if (!area)
76311@@ -1669,6 +1723,13 @@ void *__vmalloc_node_range(unsigned long size, unsigned long align,
76312 if (!size || (size >> PAGE_SHIFT) > totalram_pages)
76313 goto fail;
76314
76315+#if defined(CONFIG_MODULES) && defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
76316+ if (!(pgprot_val(prot) & _PAGE_NX))
76317+ area = __get_vm_area_node(size, align, VM_ALLOC | VM_UNLIST | VM_KERNEXEC,
76318+ VMALLOC_START, VMALLOC_END, node, gfp_mask, caller);
76319+ else
76320+#endif
76321+
76322 area = __get_vm_area_node(size, align, VM_ALLOC | VM_UNLIST,
76323 start, end, node, gfp_mask, caller);
76324 if (!area)
76325@@ -1842,10 +1903,9 @@ EXPORT_SYMBOL(vzalloc_node);
76326 * For tight control over page level allocator and protection flags
76327 * use __vmalloc() instead.
76328 */
76329-
76330 void *vmalloc_exec(unsigned long size)
76331 {
76332- return __vmalloc_node(size, 1, GFP_KERNEL | __GFP_HIGHMEM, PAGE_KERNEL_EXEC,
76333+ return __vmalloc_node(size, 1, GFP_KERNEL | __GFP_HIGHMEM | __GFP_ZERO, PAGE_KERNEL_EXEC,
76334 -1, __builtin_return_address(0));
76335 }
76336
76337@@ -2136,6 +2196,8 @@ int remap_vmalloc_range(struct vm_area_struct *vma, void *addr,
76338 unsigned long uaddr = vma->vm_start;
76339 unsigned long usize = vma->vm_end - vma->vm_start;
76340
76341+ BUG_ON(vma->vm_mirror);
76342+
76343 if ((PAGE_SIZE-1) & (unsigned long)addr)
76344 return -EINVAL;
76345
76346@@ -2572,7 +2634,7 @@ static int s_show(struct seq_file *m, void *p)
76347 {
76348 struct vm_struct *v = p;
76349
76350- seq_printf(m, "0x%p-0x%p %7ld",
76351+ seq_printf(m, "0x%pK-0x%pK %7ld",
76352 v->addr, v->addr + v->size, v->size);
76353
76354 if (v->caller)
76355diff --git a/mm/vmstat.c b/mm/vmstat.c
76356index df7a674..8b4a4f3 100644
76357--- a/mm/vmstat.c
76358+++ b/mm/vmstat.c
76359@@ -78,7 +78,7 @@ void vm_events_fold_cpu(int cpu)
76360 *
76361 * vm_stat contains the global counters
76362 */
76363-atomic_long_t vm_stat[NR_VM_ZONE_STAT_ITEMS] __cacheline_aligned_in_smp;
76364+atomic_long_unchecked_t vm_stat[NR_VM_ZONE_STAT_ITEMS] __cacheline_aligned_in_smp;
76365 EXPORT_SYMBOL(vm_stat);
76366
76367 #ifdef CONFIG_SMP
76368@@ -454,7 +454,7 @@ void refresh_cpu_vm_stats(int cpu)
76369 v = p->vm_stat_diff[i];
76370 p->vm_stat_diff[i] = 0;
76371 local_irq_restore(flags);
76372- atomic_long_add(v, &zone->vm_stat[i]);
76373+ atomic_long_add_unchecked(v, &zone->vm_stat[i]);
76374 global_diff[i] += v;
76375 #ifdef CONFIG_NUMA
76376 /* 3 seconds idle till flush */
76377@@ -492,7 +492,7 @@ void refresh_cpu_vm_stats(int cpu)
76378
76379 for (i = 0; i < NR_VM_ZONE_STAT_ITEMS; i++)
76380 if (global_diff[i])
76381- atomic_long_add(global_diff[i], &vm_stat[i]);
76382+ atomic_long_add_unchecked(global_diff[i], &vm_stat[i]);
76383 }
76384
76385 #endif
76386@@ -1212,10 +1212,20 @@ static int __init setup_vmstat(void)
76387 start_cpu_timer(cpu);
76388 #endif
76389 #ifdef CONFIG_PROC_FS
76390- proc_create("buddyinfo", S_IRUGO, NULL, &fragmentation_file_operations);
76391- proc_create("pagetypeinfo", S_IRUGO, NULL, &pagetypeinfo_file_ops);
76392- proc_create("vmstat", S_IRUGO, NULL, &proc_vmstat_file_operations);
76393- proc_create("zoneinfo", S_IRUGO, NULL, &proc_zoneinfo_file_operations);
76394+ {
76395+ mode_t gr_mode = S_IRUGO;
76396+#ifdef CONFIG_GRKERNSEC_PROC_ADD
76397+ gr_mode = S_IRUSR;
76398+#endif
76399+ proc_create("buddyinfo", gr_mode, NULL, &fragmentation_file_operations);
76400+ proc_create("pagetypeinfo", gr_mode, NULL, &pagetypeinfo_file_ops);
76401+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
76402+ proc_create("vmstat", gr_mode | S_IRGRP, NULL, &proc_vmstat_file_operations);
76403+#else
76404+ proc_create("vmstat", gr_mode, NULL, &proc_vmstat_file_operations);
76405+#endif
76406+ proc_create("zoneinfo", gr_mode, NULL, &proc_zoneinfo_file_operations);
76407+ }
76408 #endif
76409 return 0;
76410 }
76411diff --git a/net/8021q/vlan.c b/net/8021q/vlan.c
76412index 9096bcb..43ed7bb 100644
76413--- a/net/8021q/vlan.c
76414+++ b/net/8021q/vlan.c
76415@@ -557,8 +557,7 @@ static int vlan_ioctl_handler(struct net *net, void __user *arg)
76416 err = -EPERM;
76417 if (!capable(CAP_NET_ADMIN))
76418 break;
76419- if ((args.u.name_type >= 0) &&
76420- (args.u.name_type < VLAN_NAME_TYPE_HIGHEST)) {
76421+ if (args.u.name_type < VLAN_NAME_TYPE_HIGHEST) {
76422 struct vlan_net *vn;
76423
76424 vn = net_generic(net, vlan_net_id);
76425diff --git a/net/9p/trans_fd.c b/net/9p/trans_fd.c
76426index 6449bae..8c1f454 100644
76427--- a/net/9p/trans_fd.c
76428+++ b/net/9p/trans_fd.c
76429@@ -425,7 +425,7 @@ static int p9_fd_write(struct p9_client *client, void *v, int len)
76430 oldfs = get_fs();
76431 set_fs(get_ds());
76432 /* The cast to a user pointer is valid due to the set_fs() */
76433- ret = vfs_write(ts->wr, (__force void __user *)v, len, &ts->wr->f_pos);
76434+ ret = vfs_write(ts->wr, (void __force_user *)v, len, &ts->wr->f_pos);
76435 set_fs(oldfs);
76436
76437 if (ret <= 0 && ret != -ERESTARTSYS && ret != -EAGAIN)
76438diff --git a/net/atm/atm_misc.c b/net/atm/atm_misc.c
76439index 876fbe8..8bbea9f 100644
76440--- a/net/atm/atm_misc.c
76441+++ b/net/atm/atm_misc.c
76442@@ -17,7 +17,7 @@ int atm_charge(struct atm_vcc *vcc, int truesize)
76443 if (atomic_read(&sk_atm(vcc)->sk_rmem_alloc) <= sk_atm(vcc)->sk_rcvbuf)
76444 return 1;
76445 atm_return(vcc, truesize);
76446- atomic_inc(&vcc->stats->rx_drop);
76447+ atomic_inc_unchecked(&vcc->stats->rx_drop);
76448 return 0;
76449 }
76450 EXPORT_SYMBOL(atm_charge);
76451@@ -39,7 +39,7 @@ struct sk_buff *atm_alloc_charge(struct atm_vcc *vcc, int pdu_size,
76452 }
76453 }
76454 atm_return(vcc, guess);
76455- atomic_inc(&vcc->stats->rx_drop);
76456+ atomic_inc_unchecked(&vcc->stats->rx_drop);
76457 return NULL;
76458 }
76459 EXPORT_SYMBOL(atm_alloc_charge);
76460@@ -86,7 +86,7 @@ EXPORT_SYMBOL(atm_pcr_goal);
76461
76462 void sonet_copy_stats(struct k_sonet_stats *from, struct sonet_stats *to)
76463 {
76464-#define __HANDLE_ITEM(i) to->i = atomic_read(&from->i)
76465+#define __HANDLE_ITEM(i) to->i = atomic_read_unchecked(&from->i)
76466 __SONET_ITEMS
76467 #undef __HANDLE_ITEM
76468 }
76469@@ -94,7 +94,7 @@ EXPORT_SYMBOL(sonet_copy_stats);
76470
76471 void sonet_subtract_stats(struct k_sonet_stats *from, struct sonet_stats *to)
76472 {
76473-#define __HANDLE_ITEM(i) atomic_sub(to->i, &from->i)
76474+#define __HANDLE_ITEM(i) atomic_sub_unchecked(to->i,&from->i)
76475 __SONET_ITEMS
76476 #undef __HANDLE_ITEM
76477 }
76478diff --git a/net/atm/lec.h b/net/atm/lec.h
76479index a86aff9..3a0d6f6 100644
76480--- a/net/atm/lec.h
76481+++ b/net/atm/lec.h
76482@@ -48,7 +48,7 @@ struct lane2_ops {
76483 const u8 *tlvs, u32 sizeoftlvs);
76484 void (*associate_indicator) (struct net_device *dev, const u8 *mac_addr,
76485 const u8 *tlvs, u32 sizeoftlvs);
76486-};
76487+} __no_const;
76488
76489 /*
76490 * ATM LAN Emulation supports both LLC & Dix Ethernet EtherType
76491diff --git a/net/atm/mpc.h b/net/atm/mpc.h
76492index 0919a88..a23d54e 100644
76493--- a/net/atm/mpc.h
76494+++ b/net/atm/mpc.h
76495@@ -33,7 +33,7 @@ struct mpoa_client {
76496 struct mpc_parameters parameters; /* parameters for this client */
76497
76498 const struct net_device_ops *old_ops;
76499- struct net_device_ops new_ops;
76500+ net_device_ops_no_const new_ops;
76501 };
76502
76503
76504diff --git a/net/atm/proc.c b/net/atm/proc.c
76505index 0d020de..011c7bb 100644
76506--- a/net/atm/proc.c
76507+++ b/net/atm/proc.c
76508@@ -45,9 +45,9 @@ static void add_stats(struct seq_file *seq, const char *aal,
76509 const struct k_atm_aal_stats *stats)
76510 {
76511 seq_printf(seq, "%s ( %d %d %d %d %d )", aal,
76512- atomic_read(&stats->tx), atomic_read(&stats->tx_err),
76513- atomic_read(&stats->rx), atomic_read(&stats->rx_err),
76514- atomic_read(&stats->rx_drop));
76515+ atomic_read_unchecked(&stats->tx),atomic_read_unchecked(&stats->tx_err),
76516+ atomic_read_unchecked(&stats->rx),atomic_read_unchecked(&stats->rx_err),
76517+ atomic_read_unchecked(&stats->rx_drop));
76518 }
76519
76520 static void atm_dev_info(struct seq_file *seq, const struct atm_dev *dev)
76521diff --git a/net/atm/resources.c b/net/atm/resources.c
76522index 23f45ce..c748f1a 100644
76523--- a/net/atm/resources.c
76524+++ b/net/atm/resources.c
76525@@ -160,7 +160,7 @@ EXPORT_SYMBOL(atm_dev_deregister);
76526 static void copy_aal_stats(struct k_atm_aal_stats *from,
76527 struct atm_aal_stats *to)
76528 {
76529-#define __HANDLE_ITEM(i) to->i = atomic_read(&from->i)
76530+#define __HANDLE_ITEM(i) to->i = atomic_read_unchecked(&from->i)
76531 __AAL_STAT_ITEMS
76532 #undef __HANDLE_ITEM
76533 }
76534@@ -168,7 +168,7 @@ static void copy_aal_stats(struct k_atm_aal_stats *from,
76535 static void subtract_aal_stats(struct k_atm_aal_stats *from,
76536 struct atm_aal_stats *to)
76537 {
76538-#define __HANDLE_ITEM(i) atomic_sub(to->i, &from->i)
76539+#define __HANDLE_ITEM(i) atomic_sub_unchecked(to->i, &from->i)
76540 __AAL_STAT_ITEMS
76541 #undef __HANDLE_ITEM
76542 }
76543diff --git a/net/batman-adv/bat_iv_ogm.c b/net/batman-adv/bat_iv_ogm.c
76544index 469daab..262851c 100644
76545--- a/net/batman-adv/bat_iv_ogm.c
76546+++ b/net/batman-adv/bat_iv_ogm.c
76547@@ -62,7 +62,7 @@ static int batadv_iv_ogm_iface_enable(struct batadv_hard_iface *hard_iface)
76548
76549 /* randomize initial seqno to avoid collision */
76550 get_random_bytes(&random_seqno, sizeof(random_seqno));
76551- atomic_set(&hard_iface->seqno, random_seqno);
76552+ atomic_set_unchecked(&hard_iface->seqno, random_seqno);
76553
76554 hard_iface->packet_len = BATADV_OGM_HLEN;
76555 hard_iface->packet_buff = kmalloc(hard_iface->packet_len, GFP_ATOMIC);
76556@@ -600,8 +600,8 @@ static void batadv_iv_ogm_schedule(struct batadv_hard_iface *hard_iface)
76557
76558 /* change sequence number to network order */
76559 batadv_ogm_packet->seqno =
76560- htonl((uint32_t)atomic_read(&hard_iface->seqno));
76561- atomic_inc(&hard_iface->seqno);
76562+ htonl((uint32_t)atomic_read_unchecked(&hard_iface->seqno));
76563+ atomic_inc_unchecked(&hard_iface->seqno);
76564
76565 batadv_ogm_packet->ttvn = atomic_read(&bat_priv->ttvn);
76566 batadv_ogm_packet->tt_crc = htons(bat_priv->tt_crc);
76567@@ -1001,7 +1001,7 @@ static void batadv_iv_ogm_process(const struct ethhdr *ethhdr,
76568 return;
76569
76570 /* could be changed by schedule_own_packet() */
76571- if_incoming_seqno = atomic_read(&if_incoming->seqno);
76572+ if_incoming_seqno = atomic_read_unchecked(&if_incoming->seqno);
76573
76574 if (batadv_ogm_packet->flags & BATADV_DIRECTLINK)
76575 has_directlink_flag = 1;
76576diff --git a/net/batman-adv/hard-interface.c b/net/batman-adv/hard-interface.c
76577index 282bf6e..4b2603d 100644
76578--- a/net/batman-adv/hard-interface.c
76579+++ b/net/batman-adv/hard-interface.c
76580@@ -320,7 +320,7 @@ int batadv_hardif_enable_interface(struct batadv_hard_iface *hard_iface,
76581 hard_iface->batman_adv_ptype.dev = hard_iface->net_dev;
76582 dev_add_pack(&hard_iface->batman_adv_ptype);
76583
76584- atomic_set(&hard_iface->frag_seqno, 1);
76585+ atomic_set_unchecked(&hard_iface->frag_seqno, 1);
76586 batadv_info(hard_iface->soft_iface, "Adding interface: %s\n",
76587 hard_iface->net_dev->name);
76588
76589@@ -443,7 +443,7 @@ batadv_hardif_add_interface(struct net_device *net_dev)
76590 /* This can't be called via a bat_priv callback because
76591 * we have no bat_priv yet.
76592 */
76593- atomic_set(&hard_iface->seqno, 1);
76594+ atomic_set_unchecked(&hard_iface->seqno, 1);
76595 hard_iface->packet_buff = NULL;
76596
76597 return hard_iface;
76598diff --git a/net/batman-adv/soft-interface.c b/net/batman-adv/soft-interface.c
76599index 21c5357..768be1a 100644
76600--- a/net/batman-adv/soft-interface.c
76601+++ b/net/batman-adv/soft-interface.c
76602@@ -227,7 +227,7 @@ static int batadv_interface_tx(struct sk_buff *skb,
76603
76604 /* set broadcast sequence number */
76605 bcast_packet->seqno =
76606- htonl(atomic_inc_return(&bat_priv->bcast_seqno));
76607+ htonl(atomic_inc_return_unchecked(&bat_priv->bcast_seqno));
76608
76609 batadv_add_bcast_packet_to_list(bat_priv, skb, 1);
76610
76611@@ -407,7 +407,7 @@ struct net_device *batadv_softif_create(const char *name)
76612 atomic_set(&bat_priv->batman_queue_left, BATADV_BATMAN_QUEUE_LEN);
76613
76614 atomic_set(&bat_priv->mesh_state, BATADV_MESH_INACTIVE);
76615- atomic_set(&bat_priv->bcast_seqno, 1);
76616+ atomic_set_unchecked(&bat_priv->bcast_seqno, 1);
76617 atomic_set(&bat_priv->ttvn, 0);
76618 atomic_set(&bat_priv->tt_local_changes, 0);
76619 atomic_set(&bat_priv->tt_ogm_append_cnt, 0);
76620diff --git a/net/batman-adv/types.h b/net/batman-adv/types.h
76621index 12635fd..d99d837 100644
76622--- a/net/batman-adv/types.h
76623+++ b/net/batman-adv/types.h
76624@@ -33,8 +33,8 @@ struct batadv_hard_iface {
76625 int16_t if_num;
76626 char if_status;
76627 struct net_device *net_dev;
76628- atomic_t seqno;
76629- atomic_t frag_seqno;
76630+ atomic_unchecked_t seqno;
76631+ atomic_unchecked_t frag_seqno;
76632 unsigned char *packet_buff;
76633 int packet_len;
76634 struct kobject *hardif_obj;
76635@@ -176,7 +176,7 @@ struct batadv_priv {
76636 atomic_t orig_interval; /* uint */
76637 atomic_t hop_penalty; /* uint */
76638 atomic_t log_level; /* uint */
76639- atomic_t bcast_seqno;
76640+ atomic_unchecked_t bcast_seqno;
76641 atomic_t bcast_queue_left;
76642 atomic_t batman_queue_left;
76643 atomic_t ttvn; /* translation table version number */
76644diff --git a/net/batman-adv/unicast.c b/net/batman-adv/unicast.c
76645index 0016464..0ef3e53 100644
76646--- a/net/batman-adv/unicast.c
76647+++ b/net/batman-adv/unicast.c
76648@@ -269,7 +269,7 @@ int batadv_frag_send_skb(struct sk_buff *skb, struct batadv_priv *bat_priv,
76649 frag1->flags = BATADV_UNI_FRAG_HEAD | large_tail;
76650 frag2->flags = large_tail;
76651
76652- seqno = atomic_add_return(2, &hard_iface->frag_seqno);
76653+ seqno = atomic_add_return_unchecked(2, &hard_iface->frag_seqno);
76654 frag1->seqno = htons(seqno - 1);
76655 frag2->seqno = htons(seqno);
76656
76657diff --git a/net/bluetooth/hci_sock.c b/net/bluetooth/hci_sock.c
76658index d5ace1e..231c4bf 100644
76659--- a/net/bluetooth/hci_sock.c
76660+++ b/net/bluetooth/hci_sock.c
76661@@ -934,7 +934,7 @@ static int hci_sock_setsockopt(struct socket *sock, int level, int optname,
76662 uf.event_mask[1] = *((u32 *) f->event_mask + 1);
76663 }
76664
76665- len = min_t(unsigned int, len, sizeof(uf));
76666+ len = min((size_t)len, sizeof(uf));
76667 if (copy_from_user(&uf, optval, len)) {
76668 err = -EFAULT;
76669 break;
76670diff --git a/net/bluetooth/l2cap_core.c b/net/bluetooth/l2cap_core.c
76671index 38c00f1..e9d566e 100644
76672--- a/net/bluetooth/l2cap_core.c
76673+++ b/net/bluetooth/l2cap_core.c
76674@@ -3165,8 +3165,10 @@ static int l2cap_parse_conf_rsp(struct l2cap_chan *chan, void *rsp, int len, voi
76675 break;
76676
76677 case L2CAP_CONF_RFC:
76678- if (olen == sizeof(rfc))
76679- memcpy(&rfc, (void *)val, olen);
76680+ if (olen != sizeof(rfc))
76681+ break;
76682+
76683+ memcpy(&rfc, (void *)val, olen);
76684
76685 if (test_bit(CONF_STATE2_DEVICE, &chan->conf_state) &&
76686 rfc.mode != chan->mode)
76687diff --git a/net/bluetooth/l2cap_sock.c b/net/bluetooth/l2cap_sock.c
76688index 34bbe1c..451c19b 100644
76689--- a/net/bluetooth/l2cap_sock.c
76690+++ b/net/bluetooth/l2cap_sock.c
76691@@ -467,7 +467,8 @@ static int l2cap_sock_setsockopt_old(struct socket *sock, int optname, char __us
76692 struct sock *sk = sock->sk;
76693 struct l2cap_chan *chan = l2cap_pi(sk)->chan;
76694 struct l2cap_options opts;
76695- int len, err = 0;
76696+ int err = 0;
76697+ size_t len = optlen;
76698 u32 opt;
76699
76700 BT_DBG("sk %p", sk);
76701@@ -489,7 +490,7 @@ static int l2cap_sock_setsockopt_old(struct socket *sock, int optname, char __us
76702 opts.max_tx = chan->max_tx;
76703 opts.txwin_size = chan->tx_win;
76704
76705- len = min_t(unsigned int, sizeof(opts), optlen);
76706+ len = min(sizeof(opts), len);
76707 if (copy_from_user((char *) &opts, optval, len)) {
76708 err = -EFAULT;
76709 break;
76710@@ -567,7 +568,8 @@ static int l2cap_sock_setsockopt(struct socket *sock, int level, int optname, ch
76711 struct bt_security sec;
76712 struct bt_power pwr;
76713 struct l2cap_conn *conn;
76714- int len, err = 0;
76715+ int err = 0;
76716+ size_t len = optlen;
76717 u32 opt;
76718
76719 BT_DBG("sk %p", sk);
76720@@ -590,7 +592,7 @@ static int l2cap_sock_setsockopt(struct socket *sock, int level, int optname, ch
76721
76722 sec.level = BT_SECURITY_LOW;
76723
76724- len = min_t(unsigned int, sizeof(sec), optlen);
76725+ len = min(sizeof(sec), len);
76726 if (copy_from_user((char *) &sec, optval, len)) {
76727 err = -EFAULT;
76728 break;
76729@@ -687,7 +689,7 @@ static int l2cap_sock_setsockopt(struct socket *sock, int level, int optname, ch
76730
76731 pwr.force_active = BT_POWER_FORCE_ACTIVE_ON;
76732
76733- len = min_t(unsigned int, sizeof(pwr), optlen);
76734+ len = min(sizeof(pwr), len);
76735 if (copy_from_user((char *) &pwr, optval, len)) {
76736 err = -EFAULT;
76737 break;
76738diff --git a/net/bluetooth/rfcomm/sock.c b/net/bluetooth/rfcomm/sock.c
76739index 1a17850..65a3129 100644
76740--- a/net/bluetooth/rfcomm/sock.c
76741+++ b/net/bluetooth/rfcomm/sock.c
76742@@ -667,7 +667,7 @@ static int rfcomm_sock_setsockopt(struct socket *sock, int level, int optname, c
76743 struct sock *sk = sock->sk;
76744 struct bt_security sec;
76745 int err = 0;
76746- size_t len;
76747+ size_t len = optlen;
76748 u32 opt;
76749
76750 BT_DBG("sk %p", sk);
76751@@ -689,7 +689,7 @@ static int rfcomm_sock_setsockopt(struct socket *sock, int level, int optname, c
76752
76753 sec.level = BT_SECURITY_LOW;
76754
76755- len = min_t(unsigned int, sizeof(sec), optlen);
76756+ len = min(sizeof(sec), len);
76757 if (copy_from_user((char *) &sec, optval, len)) {
76758 err = -EFAULT;
76759 break;
76760diff --git a/net/bluetooth/rfcomm/tty.c b/net/bluetooth/rfcomm/tty.c
76761index 56f1823..da44330 100644
76762--- a/net/bluetooth/rfcomm/tty.c
76763+++ b/net/bluetooth/rfcomm/tty.c
76764@@ -309,7 +309,7 @@ static void rfcomm_dev_del(struct rfcomm_dev *dev)
76765 BUG_ON(test_and_set_bit(RFCOMM_TTY_RELEASED, &dev->flags));
76766
76767 spin_lock_irqsave(&dev->port.lock, flags);
76768- if (dev->port.count > 0) {
76769+ if (atomic_read(&dev->port.count) > 0) {
76770 spin_unlock_irqrestore(&dev->port.lock, flags);
76771 return;
76772 }
76773@@ -664,10 +664,10 @@ static int rfcomm_tty_open(struct tty_struct *tty, struct file *filp)
76774 return -ENODEV;
76775
76776 BT_DBG("dev %p dst %s channel %d opened %d", dev, batostr(&dev->dst),
76777- dev->channel, dev->port.count);
76778+ dev->channel, atomic_read(&dev->port.count));
76779
76780 spin_lock_irqsave(&dev->port.lock, flags);
76781- if (++dev->port.count > 1) {
76782+ if (atomic_inc_return(&dev->port.count) > 1) {
76783 spin_unlock_irqrestore(&dev->port.lock, flags);
76784 return 0;
76785 }
76786@@ -732,10 +732,10 @@ static void rfcomm_tty_close(struct tty_struct *tty, struct file *filp)
76787 return;
76788
76789 BT_DBG("tty %p dev %p dlc %p opened %d", tty, dev, dev->dlc,
76790- dev->port.count);
76791+ atomic_read(&dev->port.count));
76792
76793 spin_lock_irqsave(&dev->port.lock, flags);
76794- if (!--dev->port.count) {
76795+ if (!atomic_dec_return(&dev->port.count)) {
76796 spin_unlock_irqrestore(&dev->port.lock, flags);
76797 if (dev->tty_dev->parent)
76798 device_move(dev->tty_dev, NULL, DPM_ORDER_DEV_LAST);
76799diff --git a/net/bridge/netfilter/ebtables.c b/net/bridge/netfilter/ebtables.c
76800index 5fe2ff3..121d696 100644
76801--- a/net/bridge/netfilter/ebtables.c
76802+++ b/net/bridge/netfilter/ebtables.c
76803@@ -1523,7 +1523,7 @@ static int do_ebt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
76804 tmp.valid_hooks = t->table->valid_hooks;
76805 }
76806 mutex_unlock(&ebt_mutex);
76807- if (copy_to_user(user, &tmp, *len) != 0){
76808+ if (*len > sizeof(tmp) || copy_to_user(user, &tmp, *len) != 0){
76809 BUGPRINT("c2u Didn't work\n");
76810 ret = -EFAULT;
76811 break;
76812@@ -2327,7 +2327,7 @@ static int compat_do_ebt_get_ctl(struct sock *sk, int cmd,
76813 goto out;
76814 tmp.valid_hooks = t->valid_hooks;
76815
76816- if (copy_to_user(user, &tmp, *len) != 0) {
76817+ if (*len > sizeof(tmp) || copy_to_user(user, &tmp, *len) != 0) {
76818 ret = -EFAULT;
76819 break;
76820 }
76821@@ -2338,7 +2338,7 @@ static int compat_do_ebt_get_ctl(struct sock *sk, int cmd,
76822 tmp.entries_size = t->table->entries_size;
76823 tmp.valid_hooks = t->table->valid_hooks;
76824
76825- if (copy_to_user(user, &tmp, *len) != 0) {
76826+ if (*len > sizeof(tmp) || copy_to_user(user, &tmp, *len) != 0) {
76827 ret = -EFAULT;
76828 break;
76829 }
76830diff --git a/net/caif/cfctrl.c b/net/caif/cfctrl.c
76831index 44f270f..1f5602d 100644
76832--- a/net/caif/cfctrl.c
76833+++ b/net/caif/cfctrl.c
76834@@ -10,6 +10,7 @@
76835 #include <linux/spinlock.h>
76836 #include <linux/slab.h>
76837 #include <linux/pkt_sched.h>
76838+#include <linux/sched.h>
76839 #include <net/caif/caif_layer.h>
76840 #include <net/caif/cfpkt.h>
76841 #include <net/caif/cfctrl.h>
76842@@ -43,8 +44,8 @@ struct cflayer *cfctrl_create(void)
76843 memset(&dev_info, 0, sizeof(dev_info));
76844 dev_info.id = 0xff;
76845 cfsrvl_init(&this->serv, 0, &dev_info, false);
76846- atomic_set(&this->req_seq_no, 1);
76847- atomic_set(&this->rsp_seq_no, 1);
76848+ atomic_set_unchecked(&this->req_seq_no, 1);
76849+ atomic_set_unchecked(&this->rsp_seq_no, 1);
76850 this->serv.layer.receive = cfctrl_recv;
76851 sprintf(this->serv.layer.name, "ctrl");
76852 this->serv.layer.ctrlcmd = cfctrl_ctrlcmd;
76853@@ -130,8 +131,8 @@ static void cfctrl_insert_req(struct cfctrl *ctrl,
76854 struct cfctrl_request_info *req)
76855 {
76856 spin_lock_bh(&ctrl->info_list_lock);
76857- atomic_inc(&ctrl->req_seq_no);
76858- req->sequence_no = atomic_read(&ctrl->req_seq_no);
76859+ atomic_inc_unchecked(&ctrl->req_seq_no);
76860+ req->sequence_no = atomic_read_unchecked(&ctrl->req_seq_no);
76861 list_add_tail(&req->list, &ctrl->list);
76862 spin_unlock_bh(&ctrl->info_list_lock);
76863 }
76864@@ -149,7 +150,7 @@ static struct cfctrl_request_info *cfctrl_remove_req(struct cfctrl *ctrl,
76865 if (p != first)
76866 pr_warn("Requests are not received in order\n");
76867
76868- atomic_set(&ctrl->rsp_seq_no,
76869+ atomic_set_unchecked(&ctrl->rsp_seq_no,
76870 p->sequence_no);
76871 list_del(&p->list);
76872 goto out;
76873diff --git a/net/can/bcm.c b/net/can/bcm.c
76874index 151b773..3910c1f 100644
76875--- a/net/can/bcm.c
76876+++ b/net/can/bcm.c
76877@@ -1084,6 +1084,9 @@ static int bcm_rx_setup(struct bcm_msg_head *msg_head, struct msghdr *msg,
76878 op->sk = sk;
76879 op->ifindex = ifindex;
76880
76881+ /* ifindex for timeout events w/o previous frame reception */
76882+ op->rx_ifindex = ifindex;
76883+
76884 /* initialize uninitialized (kzalloc) structure */
76885 hrtimer_init(&op->timer, CLOCK_MONOTONIC, HRTIMER_MODE_REL);
76886 op->timer.function = bcm_rx_timeout_handler;
76887diff --git a/net/can/gw.c b/net/can/gw.c
76888index b54d5e6..91c3b25 100644
76889--- a/net/can/gw.c
76890+++ b/net/can/gw.c
76891@@ -96,7 +96,7 @@ struct cf_mod {
76892 struct {
76893 void (*xor)(struct can_frame *cf, struct cgw_csum_xor *xor);
76894 void (*crc8)(struct can_frame *cf, struct cgw_csum_crc8 *crc8);
76895- } csumfunc;
76896+ } __no_const csumfunc;
76897 };
76898
76899
76900diff --git a/net/compat.c b/net/compat.c
76901index 74ed1d7..3695bd9 100644
76902--- a/net/compat.c
76903+++ b/net/compat.c
76904@@ -71,9 +71,9 @@ int get_compat_msghdr(struct msghdr *kmsg, struct compat_msghdr __user *umsg)
76905 __get_user(kmsg->msg_controllen, &umsg->msg_controllen) ||
76906 __get_user(kmsg->msg_flags, &umsg->msg_flags))
76907 return -EFAULT;
76908- kmsg->msg_name = compat_ptr(tmp1);
76909- kmsg->msg_iov = compat_ptr(tmp2);
76910- kmsg->msg_control = compat_ptr(tmp3);
76911+ kmsg->msg_name = (void __force_kernel *)compat_ptr(tmp1);
76912+ kmsg->msg_iov = (void __force_kernel *)compat_ptr(tmp2);
76913+ kmsg->msg_control = (void __force_kernel *)compat_ptr(tmp3);
76914 return 0;
76915 }
76916
76917@@ -85,7 +85,7 @@ int verify_compat_iovec(struct msghdr *kern_msg, struct iovec *kern_iov,
76918
76919 if (kern_msg->msg_namelen) {
76920 if (mode == VERIFY_READ) {
76921- int err = move_addr_to_kernel(kern_msg->msg_name,
76922+ int err = move_addr_to_kernel((void __force_user *)kern_msg->msg_name,
76923 kern_msg->msg_namelen,
76924 kern_address);
76925 if (err < 0)
76926@@ -96,7 +96,7 @@ int verify_compat_iovec(struct msghdr *kern_msg, struct iovec *kern_iov,
76927 kern_msg->msg_name = NULL;
76928
76929 tot_len = iov_from_user_compat_to_kern(kern_iov,
76930- (struct compat_iovec __user *)kern_msg->msg_iov,
76931+ (struct compat_iovec __force_user *)kern_msg->msg_iov,
76932 kern_msg->msg_iovlen);
76933 if (tot_len >= 0)
76934 kern_msg->msg_iov = kern_iov;
76935@@ -116,20 +116,20 @@ int verify_compat_iovec(struct msghdr *kern_msg, struct iovec *kern_iov,
76936
76937 #define CMSG_COMPAT_FIRSTHDR(msg) \
76938 (((msg)->msg_controllen) >= sizeof(struct compat_cmsghdr) ? \
76939- (struct compat_cmsghdr __user *)((msg)->msg_control) : \
76940+ (struct compat_cmsghdr __force_user *)((msg)->msg_control) : \
76941 (struct compat_cmsghdr __user *)NULL)
76942
76943 #define CMSG_COMPAT_OK(ucmlen, ucmsg, mhdr) \
76944 ((ucmlen) >= sizeof(struct compat_cmsghdr) && \
76945 (ucmlen) <= (unsigned long) \
76946 ((mhdr)->msg_controllen - \
76947- ((char *)(ucmsg) - (char *)(mhdr)->msg_control)))
76948+ ((char __force_kernel *)(ucmsg) - (char *)(mhdr)->msg_control)))
76949
76950 static inline struct compat_cmsghdr __user *cmsg_compat_nxthdr(struct msghdr *msg,
76951 struct compat_cmsghdr __user *cmsg, int cmsg_len)
76952 {
76953 char __user *ptr = (char __user *)cmsg + CMSG_COMPAT_ALIGN(cmsg_len);
76954- if ((unsigned long)(ptr + 1 - (char __user *)msg->msg_control) >
76955+ if ((unsigned long)(ptr + 1 - (char __force_user *)msg->msg_control) >
76956 msg->msg_controllen)
76957 return NULL;
76958 return (struct compat_cmsghdr __user *)ptr;
76959@@ -219,7 +219,7 @@ Efault:
76960
76961 int put_cmsg_compat(struct msghdr *kmsg, int level, int type, int len, void *data)
76962 {
76963- struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __user *) kmsg->msg_control;
76964+ struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __force_user *) kmsg->msg_control;
76965 struct compat_cmsghdr cmhdr;
76966 struct compat_timeval ctv;
76967 struct compat_timespec cts[3];
76968@@ -275,7 +275,7 @@ int put_cmsg_compat(struct msghdr *kmsg, int level, int type, int len, void *dat
76969
76970 void scm_detach_fds_compat(struct msghdr *kmsg, struct scm_cookie *scm)
76971 {
76972- struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __user *) kmsg->msg_control;
76973+ struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __force_user *) kmsg->msg_control;
76974 int fdmax = (kmsg->msg_controllen - sizeof(struct compat_cmsghdr)) / sizeof(int);
76975 int fdnum = scm->fp->count;
76976 struct file **fp = scm->fp->fp;
76977@@ -364,7 +364,7 @@ static int do_set_sock_timeout(struct socket *sock, int level,
76978 return -EFAULT;
76979 old_fs = get_fs();
76980 set_fs(KERNEL_DS);
76981- err = sock_setsockopt(sock, level, optname, (char *)&ktime, sizeof(ktime));
76982+ err = sock_setsockopt(sock, level, optname, (char __force_user *)&ktime, sizeof(ktime));
76983 set_fs(old_fs);
76984
76985 return err;
76986@@ -425,7 +425,7 @@ static int do_get_sock_timeout(struct socket *sock, int level, int optname,
76987 len = sizeof(ktime);
76988 old_fs = get_fs();
76989 set_fs(KERNEL_DS);
76990- err = sock_getsockopt(sock, level, optname, (char *) &ktime, &len);
76991+ err = sock_getsockopt(sock, level, optname, (char __force_user *) &ktime, (int __force_user *)&len);
76992 set_fs(old_fs);
76993
76994 if (!err) {
76995@@ -568,7 +568,7 @@ int compat_mc_setsockopt(struct sock *sock, int level, int optname,
76996 case MCAST_JOIN_GROUP:
76997 case MCAST_LEAVE_GROUP:
76998 {
76999- struct compat_group_req __user *gr32 = (void *)optval;
77000+ struct compat_group_req __user *gr32 = (void __user *)optval;
77001 struct group_req __user *kgr =
77002 compat_alloc_user_space(sizeof(struct group_req));
77003 u32 interface;
77004@@ -589,7 +589,7 @@ int compat_mc_setsockopt(struct sock *sock, int level, int optname,
77005 case MCAST_BLOCK_SOURCE:
77006 case MCAST_UNBLOCK_SOURCE:
77007 {
77008- struct compat_group_source_req __user *gsr32 = (void *)optval;
77009+ struct compat_group_source_req __user *gsr32 = (void __user *)optval;
77010 struct group_source_req __user *kgsr = compat_alloc_user_space(
77011 sizeof(struct group_source_req));
77012 u32 interface;
77013@@ -610,7 +610,7 @@ int compat_mc_setsockopt(struct sock *sock, int level, int optname,
77014 }
77015 case MCAST_MSFILTER:
77016 {
77017- struct compat_group_filter __user *gf32 = (void *)optval;
77018+ struct compat_group_filter __user *gf32 = (void __user *)optval;
77019 struct group_filter __user *kgf;
77020 u32 interface, fmode, numsrc;
77021
77022@@ -648,7 +648,7 @@ int compat_mc_getsockopt(struct sock *sock, int level, int optname,
77023 char __user *optval, int __user *optlen,
77024 int (*getsockopt)(struct sock *, int, int, char __user *, int __user *))
77025 {
77026- struct compat_group_filter __user *gf32 = (void *)optval;
77027+ struct compat_group_filter __user *gf32 = (void __user *)optval;
77028 struct group_filter __user *kgf;
77029 int __user *koptlen;
77030 u32 interface, fmode, numsrc;
77031@@ -797,7 +797,7 @@ asmlinkage long compat_sys_socketcall(int call, u32 __user *args)
77032
77033 if (call < SYS_SOCKET || call > SYS_SENDMMSG)
77034 return -EINVAL;
77035- if (copy_from_user(a, args, nas[call]))
77036+ if (nas[call] > sizeof a || copy_from_user(a, args, nas[call]))
77037 return -EFAULT;
77038 a0 = a[0];
77039 a1 = a[1];
77040diff --git a/net/core/datagram.c b/net/core/datagram.c
77041index 0337e2b..47914a0 100644
77042--- a/net/core/datagram.c
77043+++ b/net/core/datagram.c
77044@@ -289,7 +289,7 @@ int skb_kill_datagram(struct sock *sk, struct sk_buff *skb, unsigned int flags)
77045 }
77046
77047 kfree_skb(skb);
77048- atomic_inc(&sk->sk_drops);
77049+ atomic_inc_unchecked(&sk->sk_drops);
77050 sk_mem_reclaim_partial(sk);
77051
77052 return err;
77053diff --git a/net/core/dev.c b/net/core/dev.c
77054index 1dce5b5..363a522 100644
77055--- a/net/core/dev.c
77056+++ b/net/core/dev.c
77057@@ -1138,9 +1138,13 @@ void dev_load(struct net *net, const char *name)
77058 if (no_module && capable(CAP_NET_ADMIN))
77059 no_module = request_module("netdev-%s", name);
77060 if (no_module && capable(CAP_SYS_MODULE)) {
77061+#ifdef CONFIG_GRKERNSEC_MODHARDEN
77062+ ___request_module(true, "grsec_modharden_netdev", "%s", name);
77063+#else
77064 if (!request_module("%s", name))
77065 pr_warn("Loading kernel module for a network device with CAP_SYS_MODULE (deprecated). Use CAP_NET_ADMIN and alias netdev-%s instead.\n",
77066 name);
77067+#endif
77068 }
77069 }
77070 EXPORT_SYMBOL(dev_load);
77071@@ -1605,7 +1609,7 @@ int dev_forward_skb(struct net_device *dev, struct sk_buff *skb)
77072 {
77073 if (skb_shinfo(skb)->tx_flags & SKBTX_DEV_ZEROCOPY) {
77074 if (skb_copy_ubufs(skb, GFP_ATOMIC)) {
77075- atomic_long_inc(&dev->rx_dropped);
77076+ atomic_long_inc_unchecked(&dev->rx_dropped);
77077 kfree_skb(skb);
77078 return NET_RX_DROP;
77079 }
77080@@ -1615,7 +1619,7 @@ int dev_forward_skb(struct net_device *dev, struct sk_buff *skb)
77081 nf_reset(skb);
77082
77083 if (unlikely(!is_skb_forwardable(dev, skb))) {
77084- atomic_long_inc(&dev->rx_dropped);
77085+ atomic_long_inc_unchecked(&dev->rx_dropped);
77086 kfree_skb(skb);
77087 return NET_RX_DROP;
77088 }
77089@@ -2071,7 +2075,7 @@ static int illegal_highdma(struct net_device *dev, struct sk_buff *skb)
77090
77091 struct dev_gso_cb {
77092 void (*destructor)(struct sk_buff *skb);
77093-};
77094+} __no_const;
77095
77096 #define DEV_GSO_CB(skb) ((struct dev_gso_cb *)(skb)->cb)
77097
77098@@ -2930,7 +2934,7 @@ enqueue:
77099
77100 local_irq_restore(flags);
77101
77102- atomic_long_inc(&skb->dev->rx_dropped);
77103+ atomic_long_inc_unchecked(&skb->dev->rx_dropped);
77104 kfree_skb(skb);
77105 return NET_RX_DROP;
77106 }
77107@@ -3002,7 +3006,7 @@ int netif_rx_ni(struct sk_buff *skb)
77108 }
77109 EXPORT_SYMBOL(netif_rx_ni);
77110
77111-static void net_tx_action(struct softirq_action *h)
77112+static void net_tx_action(void)
77113 {
77114 struct softnet_data *sd = &__get_cpu_var(softnet_data);
77115
77116@@ -3333,7 +3337,7 @@ ncls:
77117 ret = pt_prev->func(skb, skb->dev, pt_prev, orig_dev);
77118 } else {
77119 drop:
77120- atomic_long_inc(&skb->dev->rx_dropped);
77121+ atomic_long_inc_unchecked(&skb->dev->rx_dropped);
77122 kfree_skb(skb);
77123 /* Jamal, now you will not able to escape explaining
77124 * me how you were going to use this. :-)
77125@@ -3900,7 +3904,7 @@ void netif_napi_del(struct napi_struct *napi)
77126 }
77127 EXPORT_SYMBOL(netif_napi_del);
77128
77129-static void net_rx_action(struct softirq_action *h)
77130+static void net_rx_action(void)
77131 {
77132 struct softnet_data *sd = &__get_cpu_var(softnet_data);
77133 unsigned long time_limit = jiffies + 2;
77134@@ -4370,8 +4374,13 @@ static int ptype_seq_show(struct seq_file *seq, void *v)
77135 else
77136 seq_printf(seq, "%04x", ntohs(pt->type));
77137
77138+#ifdef CONFIG_GRKERNSEC_HIDESYM
77139+ seq_printf(seq, " %-8s %p\n",
77140+ pt->dev ? pt->dev->name : "", NULL);
77141+#else
77142 seq_printf(seq, " %-8s %pF\n",
77143 pt->dev ? pt->dev->name : "", pt->func);
77144+#endif
77145 }
77146
77147 return 0;
77148@@ -5924,7 +5933,7 @@ struct rtnl_link_stats64 *dev_get_stats(struct net_device *dev,
77149 } else {
77150 netdev_stats_to_stats64(storage, &dev->stats);
77151 }
77152- storage->rx_dropped += atomic_long_read(&dev->rx_dropped);
77153+ storage->rx_dropped += atomic_long_read_unchecked(&dev->rx_dropped);
77154 return storage;
77155 }
77156 EXPORT_SYMBOL(dev_get_stats);
77157diff --git a/net/core/flow.c b/net/core/flow.c
77158index e318c7e..168b1d0 100644
77159--- a/net/core/flow.c
77160+++ b/net/core/flow.c
77161@@ -61,7 +61,7 @@ struct flow_cache {
77162 struct timer_list rnd_timer;
77163 };
77164
77165-atomic_t flow_cache_genid = ATOMIC_INIT(0);
77166+atomic_unchecked_t flow_cache_genid = ATOMIC_INIT(0);
77167 EXPORT_SYMBOL(flow_cache_genid);
77168 static struct flow_cache flow_cache_global;
77169 static struct kmem_cache *flow_cachep __read_mostly;
77170@@ -86,7 +86,7 @@ static void flow_cache_new_hashrnd(unsigned long arg)
77171
77172 static int flow_entry_valid(struct flow_cache_entry *fle)
77173 {
77174- if (atomic_read(&flow_cache_genid) != fle->genid)
77175+ if (atomic_read_unchecked(&flow_cache_genid) != fle->genid)
77176 return 0;
77177 if (fle->object && !fle->object->ops->check(fle->object))
77178 return 0;
77179@@ -259,7 +259,7 @@ flow_cache_lookup(struct net *net, const struct flowi *key, u16 family, u8 dir,
77180 hlist_add_head(&fle->u.hlist, &fcp->hash_table[hash]);
77181 fcp->hash_count++;
77182 }
77183- } else if (likely(fle->genid == atomic_read(&flow_cache_genid))) {
77184+ } else if (likely(fle->genid == atomic_read_unchecked(&flow_cache_genid))) {
77185 flo = fle->object;
77186 if (!flo)
77187 goto ret_object;
77188@@ -280,7 +280,7 @@ nocache:
77189 }
77190 flo = resolver(net, key, family, dir, flo, ctx);
77191 if (fle) {
77192- fle->genid = atomic_read(&flow_cache_genid);
77193+ fle->genid = atomic_read_unchecked(&flow_cache_genid);
77194 if (!IS_ERR(flo))
77195 fle->object = flo;
77196 else
77197diff --git a/net/core/iovec.c b/net/core/iovec.c
77198index 7e7aeb0..2a998cb 100644
77199--- a/net/core/iovec.c
77200+++ b/net/core/iovec.c
77201@@ -42,7 +42,7 @@ int verify_iovec(struct msghdr *m, struct iovec *iov, struct sockaddr_storage *a
77202 if (m->msg_namelen) {
77203 if (mode == VERIFY_READ) {
77204 void __user *namep;
77205- namep = (void __user __force *) m->msg_name;
77206+ namep = (void __force_user *) m->msg_name;
77207 err = move_addr_to_kernel(namep, m->msg_namelen,
77208 address);
77209 if (err < 0)
77210@@ -54,7 +54,7 @@ int verify_iovec(struct msghdr *m, struct iovec *iov, struct sockaddr_storage *a
77211 }
77212
77213 size = m->msg_iovlen * sizeof(struct iovec);
77214- if (copy_from_user(iov, (void __user __force *) m->msg_iov, size))
77215+ if (copy_from_user(iov, (void __force_user *) m->msg_iov, size))
77216 return -EFAULT;
77217
77218 m->msg_iov = iov;
77219diff --git a/net/core/rtnetlink.c b/net/core/rtnetlink.c
77220index 2c5a0a0..a45f90c 100644
77221--- a/net/core/rtnetlink.c
77222+++ b/net/core/rtnetlink.c
77223@@ -58,7 +58,7 @@ struct rtnl_link {
77224 rtnl_doit_func doit;
77225 rtnl_dumpit_func dumpit;
77226 rtnl_calcit_func calcit;
77227-};
77228+} __no_const;
77229
77230 static DEFINE_MUTEX(rtnl_mutex);
77231
77232diff --git a/net/core/scm.c b/net/core/scm.c
77233index 040cebe..5b1e312 100644
77234--- a/net/core/scm.c
77235+++ b/net/core/scm.c
77236@@ -203,7 +203,7 @@ EXPORT_SYMBOL(__scm_send);
77237 int put_cmsg(struct msghdr * msg, int level, int type, int len, void *data)
77238 {
77239 struct cmsghdr __user *cm
77240- = (__force struct cmsghdr __user *)msg->msg_control;
77241+ = (struct cmsghdr __force_user *)msg->msg_control;
77242 struct cmsghdr cmhdr;
77243 int cmlen = CMSG_LEN(len);
77244 int err;
77245@@ -226,7 +226,7 @@ int put_cmsg(struct msghdr * msg, int level, int type, int len, void *data)
77246 err = -EFAULT;
77247 if (copy_to_user(cm, &cmhdr, sizeof cmhdr))
77248 goto out;
77249- if (copy_to_user(CMSG_DATA(cm), data, cmlen - sizeof(struct cmsghdr)))
77250+ if (copy_to_user((void __force_user *)CMSG_DATA((void __force_kernel *)cm), data, cmlen - sizeof(struct cmsghdr)))
77251 goto out;
77252 cmlen = CMSG_SPACE(len);
77253 if (msg->msg_controllen < cmlen)
77254@@ -242,7 +242,7 @@ EXPORT_SYMBOL(put_cmsg);
77255 void scm_detach_fds(struct msghdr *msg, struct scm_cookie *scm)
77256 {
77257 struct cmsghdr __user *cm
77258- = (__force struct cmsghdr __user*)msg->msg_control;
77259+ = (struct cmsghdr __force_user *)msg->msg_control;
77260
77261 int fdmax = 0;
77262 int fdnum = scm->fp->count;
77263@@ -262,7 +262,7 @@ void scm_detach_fds(struct msghdr *msg, struct scm_cookie *scm)
77264 if (fdnum < fdmax)
77265 fdmax = fdnum;
77266
77267- for (i=0, cmfptr=(__force int __user *)CMSG_DATA(cm); i<fdmax;
77268+ for (i=0, cmfptr=(int __force_user *)CMSG_DATA((void __force_kernel *)cm); i<fdmax;
77269 i++, cmfptr++)
77270 {
77271 struct socket *sock;
77272diff --git a/net/core/sock.c b/net/core/sock.c
77273index a6000fb..d4aee72 100644
77274--- a/net/core/sock.c
77275+++ b/net/core/sock.c
77276@@ -399,7 +399,7 @@ int sock_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
77277 struct sk_buff_head *list = &sk->sk_receive_queue;
77278
77279 if (atomic_read(&sk->sk_rmem_alloc) >= sk->sk_rcvbuf) {
77280- atomic_inc(&sk->sk_drops);
77281+ atomic_inc_unchecked(&sk->sk_drops);
77282 trace_sock_rcvqueue_full(sk, skb);
77283 return -ENOMEM;
77284 }
77285@@ -409,7 +409,7 @@ int sock_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
77286 return err;
77287
77288 if (!sk_rmem_schedule(sk, skb, skb->truesize)) {
77289- atomic_inc(&sk->sk_drops);
77290+ atomic_inc_unchecked(&sk->sk_drops);
77291 return -ENOBUFS;
77292 }
77293
77294@@ -429,7 +429,7 @@ int sock_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
77295 skb_dst_force(skb);
77296
77297 spin_lock_irqsave(&list->lock, flags);
77298- skb->dropcount = atomic_read(&sk->sk_drops);
77299+ skb->dropcount = atomic_read_unchecked(&sk->sk_drops);
77300 __skb_queue_tail(list, skb);
77301 spin_unlock_irqrestore(&list->lock, flags);
77302
77303@@ -449,7 +449,7 @@ int sk_receive_skb(struct sock *sk, struct sk_buff *skb, const int nested)
77304 skb->dev = NULL;
77305
77306 if (sk_rcvqueues_full(sk, skb, sk->sk_rcvbuf)) {
77307- atomic_inc(&sk->sk_drops);
77308+ atomic_inc_unchecked(&sk->sk_drops);
77309 goto discard_and_relse;
77310 }
77311 if (nested)
77312@@ -467,7 +467,7 @@ int sk_receive_skb(struct sock *sk, struct sk_buff *skb, const int nested)
77313 mutex_release(&sk->sk_lock.dep_map, 1, _RET_IP_);
77314 } else if (sk_add_backlog(sk, skb, sk->sk_rcvbuf)) {
77315 bh_unlock_sock(sk);
77316- atomic_inc(&sk->sk_drops);
77317+ atomic_inc_unchecked(&sk->sk_drops);
77318 goto discard_and_relse;
77319 }
77320
77321@@ -886,12 +886,12 @@ int sock_getsockopt(struct socket *sock, int level, int optname,
77322 struct timeval tm;
77323 } v;
77324
77325- int lv = sizeof(int);
77326- int len;
77327+ unsigned int lv = sizeof(int);
77328+ unsigned int len;
77329
77330 if (get_user(len, optlen))
77331 return -EFAULT;
77332- if (len < 0)
77333+ if (len > INT_MAX)
77334 return -EINVAL;
77335
77336 memset(&v, 0, sizeof(v));
77337@@ -1039,11 +1039,11 @@ int sock_getsockopt(struct socket *sock, int level, int optname,
77338
77339 case SO_PEERNAME:
77340 {
77341- char address[128];
77342+ char address[_K_SS_MAXSIZE];
77343
77344 if (sock->ops->getname(sock, (struct sockaddr *)address, &lv, 2))
77345 return -ENOTCONN;
77346- if (lv < len)
77347+ if (lv < len || sizeof address < len)
77348 return -EINVAL;
77349 if (copy_to_user(optval, address, len))
77350 return -EFAULT;
77351@@ -1091,7 +1091,7 @@ int sock_getsockopt(struct socket *sock, int level, int optname,
77352
77353 if (len > lv)
77354 len = lv;
77355- if (copy_to_user(optval, &v, len))
77356+ if (len > sizeof(v) || copy_to_user(optval, &v, len))
77357 return -EFAULT;
77358 lenout:
77359 if (put_user(len, optlen))
77360@@ -2193,7 +2193,7 @@ void sock_init_data(struct socket *sock, struct sock *sk)
77361 */
77362 smp_wmb();
77363 atomic_set(&sk->sk_refcnt, 1);
77364- atomic_set(&sk->sk_drops, 0);
77365+ atomic_set_unchecked(&sk->sk_drops, 0);
77366 }
77367 EXPORT_SYMBOL(sock_init_data);
77368
77369diff --git a/net/core/sock_diag.c b/net/core/sock_diag.c
77370index 9d8755e..26de8bc 100644
77371--- a/net/core/sock_diag.c
77372+++ b/net/core/sock_diag.c
77373@@ -15,20 +15,27 @@ static DEFINE_MUTEX(sock_diag_table_mutex);
77374
77375 int sock_diag_check_cookie(void *sk, __u32 *cookie)
77376 {
77377+#ifndef CONFIG_GRKERNSEC_HIDESYM
77378 if ((cookie[0] != INET_DIAG_NOCOOKIE ||
77379 cookie[1] != INET_DIAG_NOCOOKIE) &&
77380 ((u32)(unsigned long)sk != cookie[0] ||
77381 (u32)((((unsigned long)sk) >> 31) >> 1) != cookie[1]))
77382 return -ESTALE;
77383 else
77384+#endif
77385 return 0;
77386 }
77387 EXPORT_SYMBOL_GPL(sock_diag_check_cookie);
77388
77389 void sock_diag_save_cookie(void *sk, __u32 *cookie)
77390 {
77391+#ifdef CONFIG_GRKERNSEC_HIDESYM
77392+ cookie[0] = 0;
77393+ cookie[1] = 0;
77394+#else
77395 cookie[0] = (u32)(unsigned long)sk;
77396 cookie[1] = (u32)(((unsigned long)sk >> 31) >> 1);
77397+#endif
77398 }
77399 EXPORT_SYMBOL_GPL(sock_diag_save_cookie);
77400
77401diff --git a/net/decnet/sysctl_net_decnet.c b/net/decnet/sysctl_net_decnet.c
77402index a55eecc..dd8428c 100644
77403--- a/net/decnet/sysctl_net_decnet.c
77404+++ b/net/decnet/sysctl_net_decnet.c
77405@@ -174,7 +174,7 @@ static int dn_node_address_handler(ctl_table *table, int write,
77406
77407 if (len > *lenp) len = *lenp;
77408
77409- if (copy_to_user(buffer, addr, len))
77410+ if (len > sizeof addr || copy_to_user(buffer, addr, len))
77411 return -EFAULT;
77412
77413 *lenp = len;
77414@@ -237,7 +237,7 @@ static int dn_def_dev_handler(ctl_table *table, int write,
77415
77416 if (len > *lenp) len = *lenp;
77417
77418- if (copy_to_user(buffer, devname, len))
77419+ if (len > sizeof devname || copy_to_user(buffer, devname, len))
77420 return -EFAULT;
77421
77422 *lenp = len;
77423diff --git a/net/ipv4/fib_frontend.c b/net/ipv4/fib_frontend.c
77424index f444ac7..b7bdda9 100644
77425--- a/net/ipv4/fib_frontend.c
77426+++ b/net/ipv4/fib_frontend.c
77427@@ -1020,12 +1020,12 @@ static int fib_inetaddr_event(struct notifier_block *this, unsigned long event,
77428 #ifdef CONFIG_IP_ROUTE_MULTIPATH
77429 fib_sync_up(dev);
77430 #endif
77431- atomic_inc(&net->ipv4.dev_addr_genid);
77432+ atomic_inc_unchecked(&net->ipv4.dev_addr_genid);
77433 rt_cache_flush(dev_net(dev));
77434 break;
77435 case NETDEV_DOWN:
77436 fib_del_ifaddr(ifa, NULL);
77437- atomic_inc(&net->ipv4.dev_addr_genid);
77438+ atomic_inc_unchecked(&net->ipv4.dev_addr_genid);
77439 if (ifa->ifa_dev->ifa_list == NULL) {
77440 /* Last address was deleted from this interface.
77441 * Disable IP.
77442@@ -1062,7 +1062,7 @@ static int fib_netdev_event(struct notifier_block *this, unsigned long event, vo
77443 #ifdef CONFIG_IP_ROUTE_MULTIPATH
77444 fib_sync_up(dev);
77445 #endif
77446- atomic_inc(&net->ipv4.dev_addr_genid);
77447+ atomic_inc_unchecked(&net->ipv4.dev_addr_genid);
77448 rt_cache_flush(dev_net(dev));
77449 break;
77450 case NETDEV_DOWN:
77451diff --git a/net/ipv4/fib_semantics.c b/net/ipv4/fib_semantics.c
77452index 9633661..4e0bc08 100644
77453--- a/net/ipv4/fib_semantics.c
77454+++ b/net/ipv4/fib_semantics.c
77455@@ -767,7 +767,7 @@ __be32 fib_info_update_nh_saddr(struct net *net, struct fib_nh *nh)
77456 nh->nh_saddr = inet_select_addr(nh->nh_dev,
77457 nh->nh_gw,
77458 nh->nh_parent->fib_scope);
77459- nh->nh_saddr_genid = atomic_read(&net->ipv4.dev_addr_genid);
77460+ nh->nh_saddr_genid = atomic_read_unchecked(&net->ipv4.dev_addr_genid);
77461
77462 return nh->nh_saddr;
77463 }
77464diff --git a/net/ipv4/icmp.c b/net/ipv4/icmp.c
77465index f2eccd5..17ff9fd 100644
77466--- a/net/ipv4/icmp.c
77467+++ b/net/ipv4/icmp.c
77468@@ -257,7 +257,8 @@ static inline bool icmpv4_xrlim_allow(struct net *net, struct rtable *rt,
77469 struct inet_peer *peer = inet_getpeer_v4(net->ipv4.peers, fl4->daddr, 1);
77470 rc = inet_peer_xrlim_allow(peer,
77471 net->ipv4.sysctl_icmp_ratelimit);
77472- inet_putpeer(peer);
77473+ if (peer)
77474+ inet_putpeer(peer);
77475 }
77476 out:
77477 return rc;
77478diff --git a/net/ipv4/inet_hashtables.c b/net/ipv4/inet_hashtables.c
77479index 7880af9..70f92a3 100644
77480--- a/net/ipv4/inet_hashtables.c
77481+++ b/net/ipv4/inet_hashtables.c
77482@@ -18,12 +18,15 @@
77483 #include <linux/sched.h>
77484 #include <linux/slab.h>
77485 #include <linux/wait.h>
77486+#include <linux/security.h>
77487
77488 #include <net/inet_connection_sock.h>
77489 #include <net/inet_hashtables.h>
77490 #include <net/secure_seq.h>
77491 #include <net/ip.h>
77492
77493+extern void gr_update_task_in_ip_table(struct task_struct *task, const struct inet_sock *inet);
77494+
77495 /*
77496 * Allocate and initialize a new local port bind bucket.
77497 * The bindhash mutex for snum's hash chain must be held here.
77498@@ -530,6 +533,8 @@ ok:
77499 twrefcnt += inet_twsk_bind_unhash(tw, hinfo);
77500 spin_unlock(&head->lock);
77501
77502+ gr_update_task_in_ip_table(current, inet_sk(sk));
77503+
77504 if (tw) {
77505 inet_twsk_deschedule(tw, death_row);
77506 while (twrefcnt) {
77507diff --git a/net/ipv4/inetpeer.c b/net/ipv4/inetpeer.c
77508index c7527f6..d8bba61 100644
77509--- a/net/ipv4/inetpeer.c
77510+++ b/net/ipv4/inetpeer.c
77511@@ -503,8 +503,8 @@ relookup:
77512 if (p) {
77513 p->daddr = *daddr;
77514 atomic_set(&p->refcnt, 1);
77515- atomic_set(&p->rid, 0);
77516- atomic_set(&p->ip_id_count,
77517+ atomic_set_unchecked(&p->rid, 0);
77518+ atomic_set_unchecked(&p->ip_id_count,
77519 (daddr->family == AF_INET) ?
77520 secure_ip_id(daddr->addr.a4) :
77521 secure_ipv6_id(daddr->addr.a6));
77522diff --git a/net/ipv4/ip_fragment.c b/net/ipv4/ip_fragment.c
77523index 8d07c97..d0812ef 100644
77524--- a/net/ipv4/ip_fragment.c
77525+++ b/net/ipv4/ip_fragment.c
77526@@ -322,7 +322,7 @@ static inline int ip_frag_too_far(struct ipq *qp)
77527 return 0;
77528
77529 start = qp->rid;
77530- end = atomic_inc_return(&peer->rid);
77531+ end = atomic_inc_return_unchecked(&peer->rid);
77532 qp->rid = end;
77533
77534 rc = qp->q.fragments && (end - start) > max;
77535diff --git a/net/ipv4/ip_sockglue.c b/net/ipv4/ip_sockglue.c
77536index 14bbfcf..644f472 100644
77537--- a/net/ipv4/ip_sockglue.c
77538+++ b/net/ipv4/ip_sockglue.c
77539@@ -1151,7 +1151,8 @@ static int do_ip_getsockopt(struct sock *sk, int level, int optname,
77540 len = min_t(unsigned int, len, opt->optlen);
77541 if (put_user(len, optlen))
77542 return -EFAULT;
77543- if (copy_to_user(optval, opt->__data, len))
77544+ if ((len > (sizeof(optbuf) - sizeof(struct ip_options))) ||
77545+ copy_to_user(optval, opt->__data, len))
77546 return -EFAULT;
77547 return 0;
77548 }
77549@@ -1282,7 +1283,7 @@ static int do_ip_getsockopt(struct sock *sk, int level, int optname,
77550 if (sk->sk_type != SOCK_STREAM)
77551 return -ENOPROTOOPT;
77552
77553- msg.msg_control = optval;
77554+ msg.msg_control = (void __force_kernel *)optval;
77555 msg.msg_controllen = len;
77556 msg.msg_flags = flags;
77557
77558diff --git a/net/ipv4/ipconfig.c b/net/ipv4/ipconfig.c
77559index 67e8a6b..386764d 100644
77560--- a/net/ipv4/ipconfig.c
77561+++ b/net/ipv4/ipconfig.c
77562@@ -321,7 +321,7 @@ static int __init ic_devinet_ioctl(unsigned int cmd, struct ifreq *arg)
77563
77564 mm_segment_t oldfs = get_fs();
77565 set_fs(get_ds());
77566- res = devinet_ioctl(&init_net, cmd, (struct ifreq __user *) arg);
77567+ res = devinet_ioctl(&init_net, cmd, (struct ifreq __force_user *) arg);
77568 set_fs(oldfs);
77569 return res;
77570 }
77571@@ -332,7 +332,7 @@ static int __init ic_dev_ioctl(unsigned int cmd, struct ifreq *arg)
77572
77573 mm_segment_t oldfs = get_fs();
77574 set_fs(get_ds());
77575- res = dev_ioctl(&init_net, cmd, (struct ifreq __user *) arg);
77576+ res = dev_ioctl(&init_net, cmd, (struct ifreq __force_user *) arg);
77577 set_fs(oldfs);
77578 return res;
77579 }
77580@@ -343,7 +343,7 @@ static int __init ic_route_ioctl(unsigned int cmd, struct rtentry *arg)
77581
77582 mm_segment_t oldfs = get_fs();
77583 set_fs(get_ds());
77584- res = ip_rt_ioctl(&init_net, cmd, (void __user *) arg);
77585+ res = ip_rt_ioctl(&init_net, cmd, (void __force_user *) arg);
77586 set_fs(oldfs);
77587 return res;
77588 }
77589diff --git a/net/ipv4/ipmr.c b/net/ipv4/ipmr.c
77590index ebdf06f..f797f59 100644
77591--- a/net/ipv4/ipmr.c
77592+++ b/net/ipv4/ipmr.c
77593@@ -1318,6 +1318,10 @@ int ip_mroute_setsockopt(struct sock *sk, int optname, char __user *optval, unsi
77594 if (get_user(v, (u32 __user *)optval))
77595 return -EFAULT;
77596
77597+ /* "pimreg%u" should not exceed 16 bytes (IFNAMSIZ) */
77598+ if (v != RT_TABLE_DEFAULT && v >= 1000000000)
77599+ return -EINVAL;
77600+
77601 rtnl_lock();
77602 ret = 0;
77603 if (sk == rtnl_dereference(mrt->mroute_sk)) {
77604diff --git a/net/ipv4/netfilter/arp_tables.c b/net/ipv4/netfilter/arp_tables.c
77605index 97e61ea..cac1bbb 100644
77606--- a/net/ipv4/netfilter/arp_tables.c
77607+++ b/net/ipv4/netfilter/arp_tables.c
77608@@ -879,14 +879,14 @@ static int compat_table_info(const struct xt_table_info *info,
77609 #endif
77610
77611 static int get_info(struct net *net, void __user *user,
77612- const int *len, int compat)
77613+ int len, int compat)
77614 {
77615 char name[XT_TABLE_MAXNAMELEN];
77616 struct xt_table *t;
77617 int ret;
77618
77619- if (*len != sizeof(struct arpt_getinfo)) {
77620- duprintf("length %u != %Zu\n", *len,
77621+ if (len != sizeof(struct arpt_getinfo)) {
77622+ duprintf("length %u != %Zu\n", len,
77623 sizeof(struct arpt_getinfo));
77624 return -EINVAL;
77625 }
77626@@ -923,7 +923,7 @@ static int get_info(struct net *net, void __user *user,
77627 info.size = private->size;
77628 strcpy(info.name, name);
77629
77630- if (copy_to_user(user, &info, *len) != 0)
77631+ if (copy_to_user(user, &info, len) != 0)
77632 ret = -EFAULT;
77633 else
77634 ret = 0;
77635@@ -1682,7 +1682,7 @@ static int compat_do_arpt_get_ctl(struct sock *sk, int cmd, void __user *user,
77636
77637 switch (cmd) {
77638 case ARPT_SO_GET_INFO:
77639- ret = get_info(sock_net(sk), user, len, 1);
77640+ ret = get_info(sock_net(sk), user, *len, 1);
77641 break;
77642 case ARPT_SO_GET_ENTRIES:
77643 ret = compat_get_entries(sock_net(sk), user, len);
77644@@ -1727,7 +1727,7 @@ static int do_arpt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len
77645
77646 switch (cmd) {
77647 case ARPT_SO_GET_INFO:
77648- ret = get_info(sock_net(sk), user, len, 0);
77649+ ret = get_info(sock_net(sk), user, *len, 0);
77650 break;
77651
77652 case ARPT_SO_GET_ENTRIES:
77653diff --git a/net/ipv4/netfilter/ip_tables.c b/net/ipv4/netfilter/ip_tables.c
77654index 170b1fd..6105b91 100644
77655--- a/net/ipv4/netfilter/ip_tables.c
77656+++ b/net/ipv4/netfilter/ip_tables.c
77657@@ -1068,14 +1068,14 @@ static int compat_table_info(const struct xt_table_info *info,
77658 #endif
77659
77660 static int get_info(struct net *net, void __user *user,
77661- const int *len, int compat)
77662+ int len, int compat)
77663 {
77664 char name[XT_TABLE_MAXNAMELEN];
77665 struct xt_table *t;
77666 int ret;
77667
77668- if (*len != sizeof(struct ipt_getinfo)) {
77669- duprintf("length %u != %zu\n", *len,
77670+ if (len != sizeof(struct ipt_getinfo)) {
77671+ duprintf("length %u != %zu\n", len,
77672 sizeof(struct ipt_getinfo));
77673 return -EINVAL;
77674 }
77675@@ -1112,7 +1112,7 @@ static int get_info(struct net *net, void __user *user,
77676 info.size = private->size;
77677 strcpy(info.name, name);
77678
77679- if (copy_to_user(user, &info, *len) != 0)
77680+ if (copy_to_user(user, &info, len) != 0)
77681 ret = -EFAULT;
77682 else
77683 ret = 0;
77684@@ -1966,7 +1966,7 @@ compat_do_ipt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
77685
77686 switch (cmd) {
77687 case IPT_SO_GET_INFO:
77688- ret = get_info(sock_net(sk), user, len, 1);
77689+ ret = get_info(sock_net(sk), user, *len, 1);
77690 break;
77691 case IPT_SO_GET_ENTRIES:
77692 ret = compat_get_entries(sock_net(sk), user, len);
77693@@ -2013,7 +2013,7 @@ do_ipt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
77694
77695 switch (cmd) {
77696 case IPT_SO_GET_INFO:
77697- ret = get_info(sock_net(sk), user, len, 0);
77698+ ret = get_info(sock_net(sk), user, *len, 0);
77699 break;
77700
77701 case IPT_SO_GET_ENTRIES:
77702diff --git a/net/ipv4/ping.c b/net/ipv4/ping.c
77703index 6232d47..6b88607 100644
77704--- a/net/ipv4/ping.c
77705+++ b/net/ipv4/ping.c
77706@@ -847,7 +847,7 @@ static void ping_format_sock(struct sock *sp, struct seq_file *f,
77707 sk_rmem_alloc_get(sp),
77708 0, 0L, 0, sock_i_uid(sp), 0, sock_i_ino(sp),
77709 atomic_read(&sp->sk_refcnt), sp,
77710- atomic_read(&sp->sk_drops), len);
77711+ atomic_read_unchecked(&sp->sk_drops), len);
77712 }
77713
77714 static int ping_seq_show(struct seq_file *seq, void *v)
77715diff --git a/net/ipv4/raw.c b/net/ipv4/raw.c
77716index d23c657..cb69cc2 100644
77717--- a/net/ipv4/raw.c
77718+++ b/net/ipv4/raw.c
77719@@ -311,7 +311,7 @@ static int raw_rcv_skb(struct sock *sk, struct sk_buff *skb)
77720 int raw_rcv(struct sock *sk, struct sk_buff *skb)
77721 {
77722 if (!xfrm4_policy_check(sk, XFRM_POLICY_IN, skb)) {
77723- atomic_inc(&sk->sk_drops);
77724+ atomic_inc_unchecked(&sk->sk_drops);
77725 kfree_skb(skb);
77726 return NET_RX_DROP;
77727 }
77728@@ -747,16 +747,20 @@ static int raw_init(struct sock *sk)
77729
77730 static int raw_seticmpfilter(struct sock *sk, char __user *optval, int optlen)
77731 {
77732+ struct icmp_filter filter;
77733+
77734 if (optlen > sizeof(struct icmp_filter))
77735 optlen = sizeof(struct icmp_filter);
77736- if (copy_from_user(&raw_sk(sk)->filter, optval, optlen))
77737+ if (copy_from_user(&filter, optval, optlen))
77738 return -EFAULT;
77739+ raw_sk(sk)->filter = filter;
77740 return 0;
77741 }
77742
77743 static int raw_geticmpfilter(struct sock *sk, char __user *optval, int __user *optlen)
77744 {
77745 int len, ret = -EFAULT;
77746+ struct icmp_filter filter;
77747
77748 if (get_user(len, optlen))
77749 goto out;
77750@@ -766,8 +770,8 @@ static int raw_geticmpfilter(struct sock *sk, char __user *optval, int __user *o
77751 if (len > sizeof(struct icmp_filter))
77752 len = sizeof(struct icmp_filter);
77753 ret = -EFAULT;
77754- if (put_user(len, optlen) ||
77755- copy_to_user(optval, &raw_sk(sk)->filter, len))
77756+ filter = raw_sk(sk)->filter;
77757+ if (put_user(len, optlen) || len > sizeof filter || copy_to_user(optval, &filter, len))
77758 goto out;
77759 ret = 0;
77760 out: return ret;
77761@@ -995,7 +999,13 @@ static void raw_sock_seq_show(struct seq_file *seq, struct sock *sp, int i)
77762 sk_wmem_alloc_get(sp),
77763 sk_rmem_alloc_get(sp),
77764 0, 0L, 0, sock_i_uid(sp), 0, sock_i_ino(sp),
77765- atomic_read(&sp->sk_refcnt), sp, atomic_read(&sp->sk_drops));
77766+ atomic_read(&sp->sk_refcnt),
77767+#ifdef CONFIG_GRKERNSEC_HIDESYM
77768+ NULL,
77769+#else
77770+ sp,
77771+#endif
77772+ atomic_read_unchecked(&sp->sk_drops));
77773 }
77774
77775 static int raw_seq_show(struct seq_file *seq, void *v)
77776diff --git a/net/ipv4/route.c b/net/ipv4/route.c
77777index c017cb1..9eb15b7d 100644
77778--- a/net/ipv4/route.c
77779+++ b/net/ipv4/route.c
77780@@ -2526,7 +2526,7 @@ static __net_initdata struct pernet_operations sysctl_route_ops = {
77781
77782 static __net_init int rt_genid_init(struct net *net)
77783 {
77784- atomic_set(&net->rt_genid, 0);
77785+ atomic_set_unchecked(&net->rt_genid, 0);
77786 get_random_bytes(&net->ipv4.dev_addr_genid,
77787 sizeof(net->ipv4.dev_addr_genid));
77788 return 0;
77789diff --git a/net/ipv4/tcp_input.c b/net/ipv4/tcp_input.c
77790index c92c4da..f19e3ec 100644
77791--- a/net/ipv4/tcp_input.c
77792+++ b/net/ipv4/tcp_input.c
77793@@ -4731,7 +4731,7 @@ static struct sk_buff *tcp_collapse_one(struct sock *sk, struct sk_buff *skb,
77794 * simplifies code)
77795 */
77796 static void
77797-tcp_collapse(struct sock *sk, struct sk_buff_head *list,
77798+__intentional_overflow(5,6) tcp_collapse(struct sock *sk, struct sk_buff_head *list,
77799 struct sk_buff *head, struct sk_buff *tail,
77800 u32 start, u32 end)
77801 {
77802diff --git a/net/ipv4/tcp_ipv4.c b/net/ipv4/tcp_ipv4.c
77803index db7bfad..bfea796 100644
77804--- a/net/ipv4/tcp_ipv4.c
77805+++ b/net/ipv4/tcp_ipv4.c
77806@@ -90,6 +90,10 @@ int sysctl_tcp_low_latency __read_mostly;
77807 EXPORT_SYMBOL(sysctl_tcp_low_latency);
77808
77809
77810+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
77811+extern int grsec_enable_blackhole;
77812+#endif
77813+
77814 #ifdef CONFIG_TCP_MD5SIG
77815 static int tcp_v4_md5_hash_hdr(char *md5_hash, const struct tcp_md5sig_key *key,
77816 __be32 daddr, __be32 saddr, const struct tcphdr *th);
77817@@ -1664,6 +1668,9 @@ int tcp_v4_do_rcv(struct sock *sk, struct sk_buff *skb)
77818 return 0;
77819
77820 reset:
77821+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
77822+ if (!grsec_enable_blackhole)
77823+#endif
77824 tcp_v4_send_reset(rsk, skb);
77825 discard:
77826 kfree_skb(skb);
77827@@ -1764,12 +1771,19 @@ int tcp_v4_rcv(struct sk_buff *skb)
77828 TCP_SKB_CB(skb)->sacked = 0;
77829
77830 sk = __inet_lookup_skb(&tcp_hashinfo, skb, th->source, th->dest);
77831- if (!sk)
77832+ if (!sk) {
77833+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
77834+ ret = 1;
77835+#endif
77836 goto no_tcp_socket;
77837-
77838+ }
77839 process:
77840- if (sk->sk_state == TCP_TIME_WAIT)
77841+ if (sk->sk_state == TCP_TIME_WAIT) {
77842+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
77843+ ret = 2;
77844+#endif
77845 goto do_time_wait;
77846+ }
77847
77848 if (unlikely(iph->ttl < inet_sk(sk)->min_ttl)) {
77849 NET_INC_STATS_BH(net, LINUX_MIB_TCPMINTTLDROP);
77850@@ -1820,6 +1834,10 @@ no_tcp_socket:
77851 bad_packet:
77852 TCP_INC_STATS_BH(net, TCP_MIB_INERRS);
77853 } else {
77854+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
77855+ if (!grsec_enable_blackhole || (ret == 1 &&
77856+ (skb->dev->flags & IFF_LOOPBACK)))
77857+#endif
77858 tcp_v4_send_reset(NULL, skb);
77859 }
77860
77861@@ -2415,7 +2433,11 @@ static void get_openreq4(const struct sock *sk, const struct request_sock *req,
77862 0, /* non standard timer */
77863 0, /* open_requests have no inode */
77864 atomic_read(&sk->sk_refcnt),
77865+#ifdef CONFIG_GRKERNSEC_HIDESYM
77866+ NULL,
77867+#else
77868 req,
77869+#endif
77870 len);
77871 }
77872
77873@@ -2465,7 +2487,12 @@ static void get_tcp4_sock(struct sock *sk, struct seq_file *f, int i, int *len)
77874 sock_i_uid(sk),
77875 icsk->icsk_probes_out,
77876 sock_i_ino(sk),
77877- atomic_read(&sk->sk_refcnt), sk,
77878+ atomic_read(&sk->sk_refcnt),
77879+#ifdef CONFIG_GRKERNSEC_HIDESYM
77880+ NULL,
77881+#else
77882+ sk,
77883+#endif
77884 jiffies_to_clock_t(icsk->icsk_rto),
77885 jiffies_to_clock_t(icsk->icsk_ack.ato),
77886 (icsk->icsk_ack.quick << 1) | icsk->icsk_ack.pingpong,
77887@@ -2493,7 +2520,13 @@ static void get_timewait4_sock(const struct inet_timewait_sock *tw,
77888 " %02X %08X:%08X %02X:%08lX %08X %5d %8d %d %d %pK%n",
77889 i, src, srcp, dest, destp, tw->tw_substate, 0, 0,
77890 3, jiffies_to_clock_t(ttd), 0, 0, 0, 0,
77891- atomic_read(&tw->tw_refcnt), tw, len);
77892+ atomic_read(&tw->tw_refcnt),
77893+#ifdef CONFIG_GRKERNSEC_HIDESYM
77894+ NULL,
77895+#else
77896+ tw,
77897+#endif
77898+ len);
77899 }
77900
77901 #define TMPSZ 150
77902diff --git a/net/ipv4/tcp_minisocks.c b/net/ipv4/tcp_minisocks.c
77903index 6ff7f10..38de56e 100644
77904--- a/net/ipv4/tcp_minisocks.c
77905+++ b/net/ipv4/tcp_minisocks.c
77906@@ -27,6 +27,10 @@
77907 #include <net/inet_common.h>
77908 #include <net/xfrm.h>
77909
77910+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
77911+extern int grsec_enable_blackhole;
77912+#endif
77913+
77914 int sysctl_tcp_syncookies __read_mostly = 1;
77915 EXPORT_SYMBOL(sysctl_tcp_syncookies);
77916
77917@@ -707,6 +711,10 @@ listen_overflow:
77918
77919 embryonic_reset:
77920 NET_INC_STATS_BH(sock_net(sk), LINUX_MIB_EMBRYONICRSTS);
77921+
77922+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
77923+ if (!grsec_enable_blackhole)
77924+#endif
77925 if (!(flg & TCP_FLAG_RST))
77926 req->rsk_ops->send_reset(sk, skb);
77927
77928diff --git a/net/ipv4/tcp_probe.c b/net/ipv4/tcp_probe.c
77929index 4526fe6..1a34e43 100644
77930--- a/net/ipv4/tcp_probe.c
77931+++ b/net/ipv4/tcp_probe.c
77932@@ -204,7 +204,7 @@ static ssize_t tcpprobe_read(struct file *file, char __user *buf,
77933 if (cnt + width >= len)
77934 break;
77935
77936- if (copy_to_user(buf + cnt, tbuf, width))
77937+ if (width > sizeof tbuf || copy_to_user(buf + cnt, tbuf, width))
77938 return -EFAULT;
77939 cnt += width;
77940 }
77941diff --git a/net/ipv4/tcp_timer.c b/net/ipv4/tcp_timer.c
77942index b774a03..3873efe 100644
77943--- a/net/ipv4/tcp_timer.c
77944+++ b/net/ipv4/tcp_timer.c
77945@@ -22,6 +22,10 @@
77946 #include <linux/gfp.h>
77947 #include <net/tcp.h>
77948
77949+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
77950+extern int grsec_lastack_retries;
77951+#endif
77952+
77953 int sysctl_tcp_syn_retries __read_mostly = TCP_SYN_RETRIES;
77954 int sysctl_tcp_synack_retries __read_mostly = TCP_SYNACK_RETRIES;
77955 int sysctl_tcp_keepalive_time __read_mostly = TCP_KEEPALIVE_TIME;
77956@@ -185,6 +189,13 @@ static int tcp_write_timeout(struct sock *sk)
77957 }
77958 }
77959
77960+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
77961+ if ((sk->sk_state == TCP_LAST_ACK) &&
77962+ (grsec_lastack_retries > 0) &&
77963+ (grsec_lastack_retries < retry_until))
77964+ retry_until = grsec_lastack_retries;
77965+#endif
77966+
77967 if (retransmits_timed_out(sk, retry_until,
77968 syn_set ? 0 : icsk->icsk_user_timeout, syn_set)) {
77969 /* Has it gone just too far? */
77970diff --git a/net/ipv4/udp.c b/net/ipv4/udp.c
77971index 2814f66..fa2b223 100644
77972--- a/net/ipv4/udp.c
77973+++ b/net/ipv4/udp.c
77974@@ -87,6 +87,7 @@
77975 #include <linux/types.h>
77976 #include <linux/fcntl.h>
77977 #include <linux/module.h>
77978+#include <linux/security.h>
77979 #include <linux/socket.h>
77980 #include <linux/sockios.h>
77981 #include <linux/igmp.h>
77982@@ -111,6 +112,10 @@
77983 #include <trace/events/skb.h>
77984 #include "udp_impl.h"
77985
77986+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
77987+extern int grsec_enable_blackhole;
77988+#endif
77989+
77990 struct udp_table udp_table __read_mostly;
77991 EXPORT_SYMBOL(udp_table);
77992
77993@@ -569,6 +574,9 @@ found:
77994 return s;
77995 }
77996
77997+extern int gr_search_udp_recvmsg(struct sock *sk, const struct sk_buff *skb);
77998+extern int gr_search_udp_sendmsg(struct sock *sk, struct sockaddr_in *addr);
77999+
78000 /*
78001 * This routine is called by the ICMP module when it gets some
78002 * sort of error condition. If err < 0 then the socket should
78003@@ -864,9 +872,18 @@ int udp_sendmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg,
78004 dport = usin->sin_port;
78005 if (dport == 0)
78006 return -EINVAL;
78007+
78008+ err = gr_search_udp_sendmsg(sk, usin);
78009+ if (err)
78010+ return err;
78011 } else {
78012 if (sk->sk_state != TCP_ESTABLISHED)
78013 return -EDESTADDRREQ;
78014+
78015+ err = gr_search_udp_sendmsg(sk, NULL);
78016+ if (err)
78017+ return err;
78018+
78019 daddr = inet->inet_daddr;
78020 dport = inet->inet_dport;
78021 /* Open fast path for connected socket.
78022@@ -1108,7 +1125,7 @@ static unsigned int first_packet_length(struct sock *sk)
78023 udp_lib_checksum_complete(skb)) {
78024 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS,
78025 IS_UDPLITE(sk));
78026- atomic_inc(&sk->sk_drops);
78027+ atomic_inc_unchecked(&sk->sk_drops);
78028 __skb_unlink(skb, rcvq);
78029 __skb_queue_tail(&list_kill, skb);
78030 }
78031@@ -1194,6 +1211,10 @@ try_again:
78032 if (!skb)
78033 goto out;
78034
78035+ err = gr_search_udp_recvmsg(sk, skb);
78036+ if (err)
78037+ goto out_free;
78038+
78039 ulen = skb->len - sizeof(struct udphdr);
78040 copied = len;
78041 if (copied > ulen)
78042@@ -1227,7 +1248,7 @@ try_again:
78043 if (unlikely(err)) {
78044 trace_kfree_skb(skb, udp_recvmsg);
78045 if (!peeked) {
78046- atomic_inc(&sk->sk_drops);
78047+ atomic_inc_unchecked(&sk->sk_drops);
78048 UDP_INC_STATS_USER(sock_net(sk),
78049 UDP_MIB_INERRORS, is_udplite);
78050 }
78051@@ -1510,7 +1531,7 @@ int udp_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
78052
78053 drop:
78054 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS, is_udplite);
78055- atomic_inc(&sk->sk_drops);
78056+ atomic_inc_unchecked(&sk->sk_drops);
78057 kfree_skb(skb);
78058 return -1;
78059 }
78060@@ -1529,7 +1550,7 @@ static void flush_stack(struct sock **stack, unsigned int count,
78061 skb1 = (i == final) ? skb : skb_clone(skb, GFP_ATOMIC);
78062
78063 if (!skb1) {
78064- atomic_inc(&sk->sk_drops);
78065+ atomic_inc_unchecked(&sk->sk_drops);
78066 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_RCVBUFERRORS,
78067 IS_UDPLITE(sk));
78068 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS,
78069@@ -1698,6 +1719,9 @@ int __udp4_lib_rcv(struct sk_buff *skb, struct udp_table *udptable,
78070 goto csum_error;
78071
78072 UDP_INC_STATS_BH(net, UDP_MIB_NOPORTS, proto == IPPROTO_UDPLITE);
78073+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
78074+ if (!grsec_enable_blackhole || (skb->dev->flags & IFF_LOOPBACK))
78075+#endif
78076 icmp_send(skb, ICMP_DEST_UNREACH, ICMP_PORT_UNREACH, 0);
78077
78078 /*
78079@@ -2116,8 +2140,13 @@ static void udp4_format_sock(struct sock *sp, struct seq_file *f,
78080 sk_wmem_alloc_get(sp),
78081 sk_rmem_alloc_get(sp),
78082 0, 0L, 0, sock_i_uid(sp), 0, sock_i_ino(sp),
78083- atomic_read(&sp->sk_refcnt), sp,
78084- atomic_read(&sp->sk_drops), len);
78085+ atomic_read(&sp->sk_refcnt),
78086+#ifdef CONFIG_GRKERNSEC_HIDESYM
78087+ NULL,
78088+#else
78089+ sp,
78090+#endif
78091+ atomic_read_unchecked(&sp->sk_drops), len);
78092 }
78093
78094 int udp4_seq_show(struct seq_file *seq, void *v)
78095diff --git a/net/ipv6/addrconf.c b/net/ipv6/addrconf.c
78096index b10374d..0baa1f9 100644
78097--- a/net/ipv6/addrconf.c
78098+++ b/net/ipv6/addrconf.c
78099@@ -2144,7 +2144,7 @@ int addrconf_set_dstaddr(struct net *net, void __user *arg)
78100 p.iph.ihl = 5;
78101 p.iph.protocol = IPPROTO_IPV6;
78102 p.iph.ttl = 64;
78103- ifr.ifr_ifru.ifru_data = (__force void __user *)&p;
78104+ ifr.ifr_ifru.ifru_data = (void __force_user *)&p;
78105
78106 if (ops->ndo_do_ioctl) {
78107 mm_segment_t oldfs = get_fs();
78108diff --git a/net/ipv6/ipv6_sockglue.c b/net/ipv6/ipv6_sockglue.c
78109index e02faed..9780f28 100644
78110--- a/net/ipv6/ipv6_sockglue.c
78111+++ b/net/ipv6/ipv6_sockglue.c
78112@@ -990,7 +990,7 @@ static int do_ipv6_getsockopt(struct sock *sk, int level, int optname,
78113 if (sk->sk_type != SOCK_STREAM)
78114 return -ENOPROTOOPT;
78115
78116- msg.msg_control = optval;
78117+ msg.msg_control = (void __force_kernel *)optval;
78118 msg.msg_controllen = len;
78119 msg.msg_flags = flags;
78120
78121diff --git a/net/ipv6/netfilter/ip6_tables.c b/net/ipv6/netfilter/ip6_tables.c
78122index d7cb045..8c0ded6 100644
78123--- a/net/ipv6/netfilter/ip6_tables.c
78124+++ b/net/ipv6/netfilter/ip6_tables.c
78125@@ -1078,14 +1078,14 @@ static int compat_table_info(const struct xt_table_info *info,
78126 #endif
78127
78128 static int get_info(struct net *net, void __user *user,
78129- const int *len, int compat)
78130+ int len, int compat)
78131 {
78132 char name[XT_TABLE_MAXNAMELEN];
78133 struct xt_table *t;
78134 int ret;
78135
78136- if (*len != sizeof(struct ip6t_getinfo)) {
78137- duprintf("length %u != %zu\n", *len,
78138+ if (len != sizeof(struct ip6t_getinfo)) {
78139+ duprintf("length %u != %zu\n", len,
78140 sizeof(struct ip6t_getinfo));
78141 return -EINVAL;
78142 }
78143@@ -1122,7 +1122,7 @@ static int get_info(struct net *net, void __user *user,
78144 info.size = private->size;
78145 strcpy(info.name, name);
78146
78147- if (copy_to_user(user, &info, *len) != 0)
78148+ if (copy_to_user(user, &info, len) != 0)
78149 ret = -EFAULT;
78150 else
78151 ret = 0;
78152@@ -1976,7 +1976,7 @@ compat_do_ip6t_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
78153
78154 switch (cmd) {
78155 case IP6T_SO_GET_INFO:
78156- ret = get_info(sock_net(sk), user, len, 1);
78157+ ret = get_info(sock_net(sk), user, *len, 1);
78158 break;
78159 case IP6T_SO_GET_ENTRIES:
78160 ret = compat_get_entries(sock_net(sk), user, len);
78161@@ -2023,7 +2023,7 @@ do_ip6t_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
78162
78163 switch (cmd) {
78164 case IP6T_SO_GET_INFO:
78165- ret = get_info(sock_net(sk), user, len, 0);
78166+ ret = get_info(sock_net(sk), user, *len, 0);
78167 break;
78168
78169 case IP6T_SO_GET_ENTRIES:
78170diff --git a/net/ipv6/raw.c b/net/ipv6/raw.c
78171index 4a5f78b..3f22ebe 100644
78172--- a/net/ipv6/raw.c
78173+++ b/net/ipv6/raw.c
78174@@ -379,7 +379,7 @@ static inline int rawv6_rcv_skb(struct sock *sk, struct sk_buff *skb)
78175 {
78176 if ((raw6_sk(sk)->checksum || rcu_access_pointer(sk->sk_filter)) &&
78177 skb_checksum_complete(skb)) {
78178- atomic_inc(&sk->sk_drops);
78179+ atomic_inc_unchecked(&sk->sk_drops);
78180 kfree_skb(skb);
78181 return NET_RX_DROP;
78182 }
78183@@ -407,7 +407,7 @@ int rawv6_rcv(struct sock *sk, struct sk_buff *skb)
78184 struct raw6_sock *rp = raw6_sk(sk);
78185
78186 if (!xfrm6_policy_check(sk, XFRM_POLICY_IN, skb)) {
78187- atomic_inc(&sk->sk_drops);
78188+ atomic_inc_unchecked(&sk->sk_drops);
78189 kfree_skb(skb);
78190 return NET_RX_DROP;
78191 }
78192@@ -431,7 +431,7 @@ int rawv6_rcv(struct sock *sk, struct sk_buff *skb)
78193
78194 if (inet->hdrincl) {
78195 if (skb_checksum_complete(skb)) {
78196- atomic_inc(&sk->sk_drops);
78197+ atomic_inc_unchecked(&sk->sk_drops);
78198 kfree_skb(skb);
78199 return NET_RX_DROP;
78200 }
78201@@ -604,7 +604,7 @@ out:
78202 return err;
78203 }
78204
78205-static int rawv6_send_hdrinc(struct sock *sk, void *from, int length,
78206+static int rawv6_send_hdrinc(struct sock *sk, void *from, unsigned int length,
78207 struct flowi6 *fl6, struct dst_entry **dstp,
78208 unsigned int flags)
78209 {
78210@@ -916,12 +916,15 @@ do_confirm:
78211 static int rawv6_seticmpfilter(struct sock *sk, int level, int optname,
78212 char __user *optval, int optlen)
78213 {
78214+ struct icmp6_filter filter;
78215+
78216 switch (optname) {
78217 case ICMPV6_FILTER:
78218 if (optlen > sizeof(struct icmp6_filter))
78219 optlen = sizeof(struct icmp6_filter);
78220- if (copy_from_user(&raw6_sk(sk)->filter, optval, optlen))
78221+ if (copy_from_user(&filter, optval, optlen))
78222 return -EFAULT;
78223+ raw6_sk(sk)->filter = filter;
78224 return 0;
78225 default:
78226 return -ENOPROTOOPT;
78227@@ -934,6 +937,7 @@ static int rawv6_geticmpfilter(struct sock *sk, int level, int optname,
78228 char __user *optval, int __user *optlen)
78229 {
78230 int len;
78231+ struct icmp6_filter filter;
78232
78233 switch (optname) {
78234 case ICMPV6_FILTER:
78235@@ -945,7 +949,8 @@ static int rawv6_geticmpfilter(struct sock *sk, int level, int optname,
78236 len = sizeof(struct icmp6_filter);
78237 if (put_user(len, optlen))
78238 return -EFAULT;
78239- if (copy_to_user(optval, &raw6_sk(sk)->filter, len))
78240+ filter = raw6_sk(sk)->filter;
78241+ if (len > sizeof filter || copy_to_user(optval, &filter, len))
78242 return -EFAULT;
78243 return 0;
78244 default:
78245@@ -1252,7 +1257,13 @@ static void raw6_sock_seq_show(struct seq_file *seq, struct sock *sp, int i)
78246 0, 0L, 0,
78247 sock_i_uid(sp), 0,
78248 sock_i_ino(sp),
78249- atomic_read(&sp->sk_refcnt), sp, atomic_read(&sp->sk_drops));
78250+ atomic_read(&sp->sk_refcnt),
78251+#ifdef CONFIG_GRKERNSEC_HIDESYM
78252+ NULL,
78253+#else
78254+ sp,
78255+#endif
78256+ atomic_read_unchecked(&sp->sk_drops));
78257 }
78258
78259 static int raw6_seq_show(struct seq_file *seq, void *v)
78260diff --git a/net/ipv6/tcp_ipv6.c b/net/ipv6/tcp_ipv6.c
78261index 7e32d42..5d975ba 100644
78262--- a/net/ipv6/tcp_ipv6.c
78263+++ b/net/ipv6/tcp_ipv6.c
78264@@ -106,6 +106,10 @@ static void inet6_sk_rx_dst_set(struct sock *sk, const struct sk_buff *skb)
78265 inet6_sk(sk)->rx_dst_cookie = rt->rt6i_node->fn_sernum;
78266 }
78267
78268+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
78269+extern int grsec_enable_blackhole;
78270+#endif
78271+
78272 static void tcp_v6_hash(struct sock *sk)
78273 {
78274 if (sk->sk_state != TCP_CLOSE) {
78275@@ -1511,6 +1515,9 @@ static int tcp_v6_do_rcv(struct sock *sk, struct sk_buff *skb)
78276 return 0;
78277
78278 reset:
78279+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
78280+ if (!grsec_enable_blackhole)
78281+#endif
78282 tcp_v6_send_reset(sk, skb);
78283 discard:
78284 if (opt_skb)
78285@@ -1592,12 +1599,20 @@ static int tcp_v6_rcv(struct sk_buff *skb)
78286 TCP_SKB_CB(skb)->sacked = 0;
78287
78288 sk = __inet6_lookup_skb(&tcp_hashinfo, skb, th->source, th->dest);
78289- if (!sk)
78290+ if (!sk) {
78291+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
78292+ ret = 1;
78293+#endif
78294 goto no_tcp_socket;
78295+ }
78296
78297 process:
78298- if (sk->sk_state == TCP_TIME_WAIT)
78299+ if (sk->sk_state == TCP_TIME_WAIT) {
78300+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
78301+ ret = 2;
78302+#endif
78303 goto do_time_wait;
78304+ }
78305
78306 if (hdr->hop_limit < inet6_sk(sk)->min_hopcount) {
78307 NET_INC_STATS_BH(net, LINUX_MIB_TCPMINTTLDROP);
78308@@ -1646,6 +1661,10 @@ no_tcp_socket:
78309 bad_packet:
78310 TCP_INC_STATS_BH(net, TCP_MIB_INERRS);
78311 } else {
78312+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
78313+ if (!grsec_enable_blackhole || (ret == 1 &&
78314+ (skb->dev->flags & IFF_LOOPBACK)))
78315+#endif
78316 tcp_v6_send_reset(NULL, skb);
78317 }
78318
78319@@ -1857,7 +1876,13 @@ static void get_openreq6(struct seq_file *seq,
78320 uid,
78321 0, /* non standard timer */
78322 0, /* open_requests have no inode */
78323- 0, req);
78324+ 0,
78325+#ifdef CONFIG_GRKERNSEC_HIDESYM
78326+ NULL
78327+#else
78328+ req
78329+#endif
78330+ );
78331 }
78332
78333 static void get_tcp6_sock(struct seq_file *seq, struct sock *sp, int i)
78334@@ -1907,7 +1932,12 @@ static void get_tcp6_sock(struct seq_file *seq, struct sock *sp, int i)
78335 sock_i_uid(sp),
78336 icsk->icsk_probes_out,
78337 sock_i_ino(sp),
78338- atomic_read(&sp->sk_refcnt), sp,
78339+ atomic_read(&sp->sk_refcnt),
78340+#ifdef CONFIG_GRKERNSEC_HIDESYM
78341+ NULL,
78342+#else
78343+ sp,
78344+#endif
78345 jiffies_to_clock_t(icsk->icsk_rto),
78346 jiffies_to_clock_t(icsk->icsk_ack.ato),
78347 (icsk->icsk_ack.quick << 1 ) | icsk->icsk_ack.pingpong,
78348@@ -1942,7 +1972,13 @@ static void get_timewait6_sock(struct seq_file *seq,
78349 dest->s6_addr32[2], dest->s6_addr32[3], destp,
78350 tw->tw_substate, 0, 0,
78351 3, jiffies_to_clock_t(ttd), 0, 0, 0, 0,
78352- atomic_read(&tw->tw_refcnt), tw);
78353+ atomic_read(&tw->tw_refcnt),
78354+#ifdef CONFIG_GRKERNSEC_HIDESYM
78355+ NULL
78356+#else
78357+ tw
78358+#endif
78359+ );
78360 }
78361
78362 static int tcp6_seq_show(struct seq_file *seq, void *v)
78363diff --git a/net/ipv6/udp.c b/net/ipv6/udp.c
78364index 07e2bfe..328dae8 100644
78365--- a/net/ipv6/udp.c
78366+++ b/net/ipv6/udp.c
78367@@ -51,6 +51,10 @@
78368 #include <trace/events/skb.h>
78369 #include "udp_impl.h"
78370
78371+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
78372+extern int grsec_enable_blackhole;
78373+#endif
78374+
78375 int ipv6_rcv_saddr_equal(const struct sock *sk, const struct sock *sk2)
78376 {
78377 const struct in6_addr *sk_rcv_saddr6 = &inet6_sk(sk)->rcv_saddr;
78378@@ -395,7 +399,7 @@ try_again:
78379 if (unlikely(err)) {
78380 trace_kfree_skb(skb, udpv6_recvmsg);
78381 if (!peeked) {
78382- atomic_inc(&sk->sk_drops);
78383+ atomic_inc_unchecked(&sk->sk_drops);
78384 if (is_udp4)
78385 UDP_INC_STATS_USER(sock_net(sk),
78386 UDP_MIB_INERRORS,
78387@@ -633,7 +637,7 @@ int udpv6_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
78388 return rc;
78389 drop:
78390 UDP6_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS, is_udplite);
78391- atomic_inc(&sk->sk_drops);
78392+ atomic_inc_unchecked(&sk->sk_drops);
78393 kfree_skb(skb);
78394 return -1;
78395 }
78396@@ -691,7 +695,7 @@ static void flush_stack(struct sock **stack, unsigned int count,
78397 if (likely(skb1 == NULL))
78398 skb1 = (i == final) ? skb : skb_clone(skb, GFP_ATOMIC);
78399 if (!skb1) {
78400- atomic_inc(&sk->sk_drops);
78401+ atomic_inc_unchecked(&sk->sk_drops);
78402 UDP6_INC_STATS_BH(sock_net(sk), UDP_MIB_RCVBUFERRORS,
78403 IS_UDPLITE(sk));
78404 UDP6_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS,
78405@@ -862,6 +866,9 @@ int __udp6_lib_rcv(struct sk_buff *skb, struct udp_table *udptable,
78406 goto discard;
78407
78408 UDP6_INC_STATS_BH(net, UDP_MIB_NOPORTS, proto == IPPROTO_UDPLITE);
78409+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
78410+ if (!grsec_enable_blackhole || (skb->dev->flags & IFF_LOOPBACK))
78411+#endif
78412 icmpv6_send(skb, ICMPV6_DEST_UNREACH, ICMPV6_PORT_UNREACH, 0);
78413
78414 kfree_skb(skb);
78415@@ -1471,8 +1478,13 @@ static void udp6_sock_seq_show(struct seq_file *seq, struct sock *sp, int bucket
78416 0, 0L, 0,
78417 sock_i_uid(sp), 0,
78418 sock_i_ino(sp),
78419- atomic_read(&sp->sk_refcnt), sp,
78420- atomic_read(&sp->sk_drops));
78421+ atomic_read(&sp->sk_refcnt),
78422+#ifdef CONFIG_GRKERNSEC_HIDESYM
78423+ NULL,
78424+#else
78425+ sp,
78426+#endif
78427+ atomic_read_unchecked(&sp->sk_drops));
78428 }
78429
78430 int udp6_seq_show(struct seq_file *seq, void *v)
78431diff --git a/net/irda/ircomm/ircomm_tty.c b/net/irda/ircomm/ircomm_tty.c
78432index 6b9d5a0..4dffaf1 100644
78433--- a/net/irda/ircomm/ircomm_tty.c
78434+++ b/net/irda/ircomm/ircomm_tty.c
78435@@ -281,16 +281,16 @@ static int ircomm_tty_block_til_ready(struct ircomm_tty_cb *self,
78436 add_wait_queue(&self->open_wait, &wait);
78437
78438 IRDA_DEBUG(2, "%s(%d):block_til_ready before block on %s open_count=%d\n",
78439- __FILE__,__LINE__, tty->driver->name, self->open_count );
78440+ __FILE__,__LINE__, tty->driver->name, local_read(&self->open_count) );
78441
78442 /* As far as I can see, we protect open_count - Jean II */
78443 spin_lock_irqsave(&self->spinlock, flags);
78444 if (!tty_hung_up_p(filp)) {
78445 extra_count = 1;
78446- self->open_count--;
78447+ local_dec(&self->open_count);
78448 }
78449 spin_unlock_irqrestore(&self->spinlock, flags);
78450- self->blocked_open++;
78451+ local_inc(&self->blocked_open);
78452
78453 while (1) {
78454 if (tty->termios->c_cflag & CBAUD) {
78455@@ -330,7 +330,7 @@ static int ircomm_tty_block_til_ready(struct ircomm_tty_cb *self,
78456 }
78457
78458 IRDA_DEBUG(1, "%s(%d):block_til_ready blocking on %s open_count=%d\n",
78459- __FILE__,__LINE__, tty->driver->name, self->open_count );
78460+ __FILE__,__LINE__, tty->driver->name, local_read(&self->open_count) );
78461
78462 schedule();
78463 }
78464@@ -341,13 +341,13 @@ static int ircomm_tty_block_til_ready(struct ircomm_tty_cb *self,
78465 if (extra_count) {
78466 /* ++ is not atomic, so this should be protected - Jean II */
78467 spin_lock_irqsave(&self->spinlock, flags);
78468- self->open_count++;
78469+ local_inc(&self->open_count);
78470 spin_unlock_irqrestore(&self->spinlock, flags);
78471 }
78472- self->blocked_open--;
78473+ local_dec(&self->blocked_open);
78474
78475 IRDA_DEBUG(1, "%s(%d):block_til_ready after blocking on %s open_count=%d\n",
78476- __FILE__,__LINE__, tty->driver->name, self->open_count);
78477+ __FILE__,__LINE__, tty->driver->name, local_read(&self->open_count));
78478
78479 if (!retval)
78480 self->flags |= ASYNC_NORMAL_ACTIVE;
78481@@ -412,14 +412,14 @@ static int ircomm_tty_open(struct tty_struct *tty, struct file *filp)
78482 }
78483 /* ++ is not atomic, so this should be protected - Jean II */
78484 spin_lock_irqsave(&self->spinlock, flags);
78485- self->open_count++;
78486+ local_inc(&self->open_count);
78487
78488 tty->driver_data = self;
78489 self->tty = tty;
78490 spin_unlock_irqrestore(&self->spinlock, flags);
78491
78492 IRDA_DEBUG(1, "%s(), %s%d, count = %d\n", __func__ , tty->driver->name,
78493- self->line, self->open_count);
78494+ self->line, local_read(&self->open_count));
78495
78496 /* Not really used by us, but lets do it anyway */
78497 self->tty->low_latency = (self->flags & ASYNC_LOW_LATENCY) ? 1 : 0;
78498@@ -505,7 +505,7 @@ static void ircomm_tty_close(struct tty_struct *tty, struct file *filp)
78499 return;
78500 }
78501
78502- if ((tty->count == 1) && (self->open_count != 1)) {
78503+ if ((tty->count == 1) && (local_read(&self->open_count) != 1)) {
78504 /*
78505 * Uh, oh. tty->count is 1, which means that the tty
78506 * structure will be freed. state->count should always
78507@@ -515,16 +515,16 @@ static void ircomm_tty_close(struct tty_struct *tty, struct file *filp)
78508 */
78509 IRDA_DEBUG(0, "%s(), bad serial port count; "
78510 "tty->count is 1, state->count is %d\n", __func__ ,
78511- self->open_count);
78512- self->open_count = 1;
78513+ local_read(&self->open_count));
78514+ local_set(&self->open_count, 1);
78515 }
78516
78517- if (--self->open_count < 0) {
78518+ if (local_dec_return(&self->open_count) < 0) {
78519 IRDA_ERROR("%s(), bad serial port count for ttys%d: %d\n",
78520- __func__, self->line, self->open_count);
78521- self->open_count = 0;
78522+ __func__, self->line, local_read(&self->open_count));
78523+ local_set(&self->open_count, 0);
78524 }
78525- if (self->open_count) {
78526+ if (local_read(&self->open_count)) {
78527 spin_unlock_irqrestore(&self->spinlock, flags);
78528
78529 IRDA_DEBUG(0, "%s(), open count > 0\n", __func__ );
78530@@ -556,7 +556,7 @@ static void ircomm_tty_close(struct tty_struct *tty, struct file *filp)
78531 tty->closing = 0;
78532 self->tty = NULL;
78533
78534- if (self->blocked_open) {
78535+ if (local_read(&self->blocked_open)) {
78536 if (self->close_delay)
78537 schedule_timeout_interruptible(self->close_delay);
78538 wake_up_interruptible(&self->open_wait);
78539@@ -1008,7 +1008,7 @@ static void ircomm_tty_hangup(struct tty_struct *tty)
78540 spin_lock_irqsave(&self->spinlock, flags);
78541 self->flags &= ~ASYNC_NORMAL_ACTIVE;
78542 self->tty = NULL;
78543- self->open_count = 0;
78544+ local_set(&self->open_count, 0);
78545 spin_unlock_irqrestore(&self->spinlock, flags);
78546
78547 wake_up_interruptible(&self->open_wait);
78548@@ -1355,7 +1355,7 @@ static void ircomm_tty_line_info(struct ircomm_tty_cb *self, struct seq_file *m)
78549 seq_putc(m, '\n');
78550
78551 seq_printf(m, "Role: %s\n", self->client ? "client" : "server");
78552- seq_printf(m, "Open count: %d\n", self->open_count);
78553+ seq_printf(m, "Open count: %d\n", local_read(&self->open_count));
78554 seq_printf(m, "Max data size: %d\n", self->max_data_size);
78555 seq_printf(m, "Max header size: %d\n", self->max_header_size);
78556
78557diff --git a/net/irda/irttp.c b/net/irda/irttp.c
78558index 5c93f29..71498f0 100644
78559--- a/net/irda/irttp.c
78560+++ b/net/irda/irttp.c
78561@@ -441,6 +441,7 @@ struct tsap_cb *irttp_open_tsap(__u8 stsap_sel, int credit, notify_t *notify)
78562 lsap = irlmp_open_lsap(stsap_sel, &ttp_notify, 0);
78563 if (lsap == NULL) {
78564 IRDA_WARNING("%s: unable to allocate LSAP!!\n", __func__);
78565+ __irttp_close_tsap(self);
78566 return NULL;
78567 }
78568
78569diff --git a/net/iucv/af_iucv.c b/net/iucv/af_iucv.c
78570index cd6f7a9..e63fe89 100644
78571--- a/net/iucv/af_iucv.c
78572+++ b/net/iucv/af_iucv.c
78573@@ -782,10 +782,10 @@ static int iucv_sock_autobind(struct sock *sk)
78574
78575 write_lock_bh(&iucv_sk_list.lock);
78576
78577- sprintf(name, "%08x", atomic_inc_return(&iucv_sk_list.autobind_name));
78578+ sprintf(name, "%08x", atomic_inc_return_unchecked(&iucv_sk_list.autobind_name));
78579 while (__iucv_get_sock_by_name(name)) {
78580 sprintf(name, "%08x",
78581- atomic_inc_return(&iucv_sk_list.autobind_name));
78582+ atomic_inc_return_unchecked(&iucv_sk_list.autobind_name));
78583 }
78584
78585 write_unlock_bh(&iucv_sk_list.lock);
78586diff --git a/net/key/af_key.c b/net/key/af_key.c
78587index 34e4185..8823368 100644
78588--- a/net/key/af_key.c
78589+++ b/net/key/af_key.c
78590@@ -3016,10 +3016,10 @@ static int pfkey_send_policy_notify(struct xfrm_policy *xp, int dir, const struc
78591 static u32 get_acqseq(void)
78592 {
78593 u32 res;
78594- static atomic_t acqseq;
78595+ static atomic_unchecked_t acqseq;
78596
78597 do {
78598- res = atomic_inc_return(&acqseq);
78599+ res = atomic_inc_return_unchecked(&acqseq);
78600 } while (!res);
78601 return res;
78602 }
78603diff --git a/net/mac80211/ieee80211_i.h b/net/mac80211/ieee80211_i.h
78604index 642a2a3..9dcc3dd 100644
78605--- a/net/mac80211/ieee80211_i.h
78606+++ b/net/mac80211/ieee80211_i.h
78607@@ -28,6 +28,7 @@
78608 #include <net/ieee80211_radiotap.h>
78609 #include <net/cfg80211.h>
78610 #include <net/mac80211.h>
78611+#include <asm/local.h>
78612 #include "key.h"
78613 #include "sta_info.h"
78614 #include "debug.h"
78615@@ -840,7 +841,7 @@ struct ieee80211_local {
78616 /* also used to protect ampdu_ac_queue and amdpu_ac_stop_refcnt */
78617 spinlock_t queue_stop_reason_lock;
78618
78619- int open_count;
78620+ local_t open_count;
78621 int monitors, cooked_mntrs;
78622 /* number of interfaces with corresponding FIF_ flags */
78623 int fif_fcsfail, fif_plcpfail, fif_control, fif_other_bss, fif_pspoll,
78624diff --git a/net/mac80211/iface.c b/net/mac80211/iface.c
78625index c93d395..a305570 100644
78626--- a/net/mac80211/iface.c
78627+++ b/net/mac80211/iface.c
78628@@ -454,7 +454,7 @@ static int ieee80211_do_open(struct net_device *dev, bool coming_up)
78629 break;
78630 }
78631
78632- if (local->open_count == 0) {
78633+ if (local_read(&local->open_count) == 0) {
78634 res = drv_start(local);
78635 if (res)
78636 goto err_del_bss;
78637@@ -497,7 +497,7 @@ static int ieee80211_do_open(struct net_device *dev, bool coming_up)
78638 break;
78639 }
78640
78641- if (local->monitors == 0 && local->open_count == 0) {
78642+ if (local->monitors == 0 && local_read(&local->open_count) == 0) {
78643 res = ieee80211_add_virtual_monitor(local);
78644 if (res)
78645 goto err_stop;
78646@@ -594,7 +594,7 @@ static int ieee80211_do_open(struct net_device *dev, bool coming_up)
78647 mutex_unlock(&local->mtx);
78648
78649 if (coming_up)
78650- local->open_count++;
78651+ local_inc(&local->open_count);
78652
78653 if (hw_reconf_flags)
78654 ieee80211_hw_config(local, hw_reconf_flags);
78655@@ -607,7 +607,7 @@ static int ieee80211_do_open(struct net_device *dev, bool coming_up)
78656 err_del_interface:
78657 drv_remove_interface(local, sdata);
78658 err_stop:
78659- if (!local->open_count)
78660+ if (!local_read(&local->open_count))
78661 drv_stop(local);
78662 err_del_bss:
78663 sdata->bss = NULL;
78664@@ -736,7 +736,7 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
78665 }
78666
78667 if (going_down)
78668- local->open_count--;
78669+ local_dec(&local->open_count);
78670
78671 switch (sdata->vif.type) {
78672 case NL80211_IFTYPE_AP_VLAN:
78673@@ -796,7 +796,7 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
78674
78675 ieee80211_recalc_ps(local, -1);
78676
78677- if (local->open_count == 0) {
78678+ if (local_read(&local->open_count) == 0) {
78679 if (local->ops->napi_poll)
78680 napi_disable(&local->napi);
78681 ieee80211_clear_tx_pending(local);
78682@@ -828,7 +828,7 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
78683 }
78684 spin_unlock_irqrestore(&local->queue_stop_reason_lock, flags);
78685
78686- if (local->monitors == local->open_count && local->monitors > 0)
78687+ if (local->monitors == local_read(&local->open_count) && local->monitors > 0)
78688 ieee80211_add_virtual_monitor(local);
78689 }
78690
78691diff --git a/net/mac80211/main.c b/net/mac80211/main.c
78692index c26e231..8916637 100644
78693--- a/net/mac80211/main.c
78694+++ b/net/mac80211/main.c
78695@@ -166,7 +166,7 @@ int ieee80211_hw_config(struct ieee80211_local *local, u32 changed)
78696 local->hw.conf.power_level = power;
78697 }
78698
78699- if (changed && local->open_count) {
78700+ if (changed && local_read(&local->open_count)) {
78701 ret = drv_config(local, changed);
78702 /*
78703 * Goal:
78704diff --git a/net/mac80211/pm.c b/net/mac80211/pm.c
78705index 5c572e7..ecf75ce 100644
78706--- a/net/mac80211/pm.c
78707+++ b/net/mac80211/pm.c
78708@@ -34,7 +34,7 @@ int __ieee80211_suspend(struct ieee80211_hw *hw, struct cfg80211_wowlan *wowlan)
78709 struct ieee80211_sub_if_data *sdata;
78710 struct sta_info *sta;
78711
78712- if (!local->open_count)
78713+ if (!local_read(&local->open_count))
78714 goto suspend;
78715
78716 ieee80211_scan_cancel(local);
78717@@ -72,7 +72,7 @@ int __ieee80211_suspend(struct ieee80211_hw *hw, struct cfg80211_wowlan *wowlan)
78718 cancel_work_sync(&local->dynamic_ps_enable_work);
78719 del_timer_sync(&local->dynamic_ps_timer);
78720
78721- local->wowlan = wowlan && local->open_count;
78722+ local->wowlan = wowlan && local_read(&local->open_count);
78723 if (local->wowlan) {
78724 int err = drv_suspend(local, wowlan);
78725 if (err < 0) {
78726@@ -143,7 +143,7 @@ int __ieee80211_suspend(struct ieee80211_hw *hw, struct cfg80211_wowlan *wowlan)
78727 drv_remove_interface(local, sdata);
78728
78729 /* stop hardware - this must stop RX */
78730- if (local->open_count)
78731+ if (local_read(&local->open_count))
78732 ieee80211_stop_device(local);
78733
78734 suspend:
78735diff --git a/net/mac80211/rate.c b/net/mac80211/rate.c
78736index 3313c11..bec9f17 100644
78737--- a/net/mac80211/rate.c
78738+++ b/net/mac80211/rate.c
78739@@ -494,7 +494,7 @@ int ieee80211_init_rate_ctrl_alg(struct ieee80211_local *local,
78740
78741 ASSERT_RTNL();
78742
78743- if (local->open_count)
78744+ if (local_read(&local->open_count))
78745 return -EBUSY;
78746
78747 if (local->hw.flags & IEEE80211_HW_HAS_RATE_CONTROL) {
78748diff --git a/net/mac80211/rc80211_pid_debugfs.c b/net/mac80211/rc80211_pid_debugfs.c
78749index c97a065..ff61928 100644
78750--- a/net/mac80211/rc80211_pid_debugfs.c
78751+++ b/net/mac80211/rc80211_pid_debugfs.c
78752@@ -193,7 +193,7 @@ static ssize_t rate_control_pid_events_read(struct file *file, char __user *buf,
78753
78754 spin_unlock_irqrestore(&events->lock, status);
78755
78756- if (copy_to_user(buf, pb, p))
78757+ if (p > sizeof(pb) || copy_to_user(buf, pb, p))
78758 return -EFAULT;
78759
78760 return p;
78761diff --git a/net/mac80211/util.c b/net/mac80211/util.c
78762index 7883449..17c6a9a 100644
78763--- a/net/mac80211/util.c
78764+++ b/net/mac80211/util.c
78765@@ -1279,7 +1279,7 @@ int ieee80211_reconfig(struct ieee80211_local *local)
78766 }
78767 #endif
78768 /* everything else happens only if HW was up & running */
78769- if (!local->open_count)
78770+ if (!local_read(&local->open_count))
78771 goto wake_up;
78772
78773 /*
78774diff --git a/net/netfilter/Kconfig b/net/netfilter/Kconfig
78775index c19b214..471fad1 100644
78776--- a/net/netfilter/Kconfig
78777+++ b/net/netfilter/Kconfig
78778@@ -872,6 +872,16 @@ config NETFILTER_XT_MATCH_ESP
78779
78780 To compile it as a module, choose M here. If unsure, say N.
78781
78782+config NETFILTER_XT_MATCH_GRADM
78783+ tristate '"gradm" match support'
78784+ depends on NETFILTER_XTABLES && NETFILTER_ADVANCED
78785+ depends on GRKERNSEC && !GRKERNSEC_NO_RBAC
78786+ ---help---
78787+ The gradm match allows to match on grsecurity RBAC being enabled.
78788+ It is useful when iptables rules are applied early on bootup to
78789+ prevent connections to the machine (except from a trusted host)
78790+ while the RBAC system is disabled.
78791+
78792 config NETFILTER_XT_MATCH_HASHLIMIT
78793 tristate '"hashlimit" match support'
78794 depends on (IP6_NF_IPTABLES || IP6_NF_IPTABLES=n)
78795diff --git a/net/netfilter/Makefile b/net/netfilter/Makefile
78796index 1c5160f..145ae21 100644
78797--- a/net/netfilter/Makefile
78798+++ b/net/netfilter/Makefile
78799@@ -90,6 +90,7 @@ obj-$(CONFIG_NETFILTER_XT_MATCH_DEVGROUP) += xt_devgroup.o
78800 obj-$(CONFIG_NETFILTER_XT_MATCH_DSCP) += xt_dscp.o
78801 obj-$(CONFIG_NETFILTER_XT_MATCH_ECN) += xt_ecn.o
78802 obj-$(CONFIG_NETFILTER_XT_MATCH_ESP) += xt_esp.o
78803+obj-$(CONFIG_NETFILTER_XT_MATCH_GRADM) += xt_gradm.o
78804 obj-$(CONFIG_NETFILTER_XT_MATCH_HASHLIMIT) += xt_hashlimit.o
78805 obj-$(CONFIG_NETFILTER_XT_MATCH_HELPER) += xt_helper.o
78806 obj-$(CONFIG_NETFILTER_XT_MATCH_HL) += xt_hl.o
78807diff --git a/net/netfilter/ipset/ip_set_hash_netiface.c b/net/netfilter/ipset/ip_set_hash_netiface.c
78808index d5d3607..1b6fa7b 100644
78809--- a/net/netfilter/ipset/ip_set_hash_netiface.c
78810+++ b/net/netfilter/ipset/ip_set_hash_netiface.c
78811@@ -791,7 +791,7 @@ static struct ip_set_type hash_netiface_type __read_mostly = {
78812 [IPSET_ATTR_IP] = { .type = NLA_NESTED },
78813 [IPSET_ATTR_IP_TO] = { .type = NLA_NESTED },
78814 [IPSET_ATTR_IFACE] = { .type = NLA_NUL_STRING,
78815- .len = IPSET_MAXNAMELEN - 1 },
78816+ .len = IFNAMSIZ - 1 },
78817 [IPSET_ATTR_CADT_FLAGS] = { .type = NLA_U32 },
78818 [IPSET_ATTR_CIDR] = { .type = NLA_U8 },
78819 [IPSET_ATTR_TIMEOUT] = { .type = NLA_U32 },
78820diff --git a/net/netfilter/ipvs/ip_vs_conn.c b/net/netfilter/ipvs/ip_vs_conn.c
78821index 1548df9..98ad9b4 100644
78822--- a/net/netfilter/ipvs/ip_vs_conn.c
78823+++ b/net/netfilter/ipvs/ip_vs_conn.c
78824@@ -557,7 +557,7 @@ ip_vs_bind_dest(struct ip_vs_conn *cp, struct ip_vs_dest *dest)
78825 /* Increase the refcnt counter of the dest */
78826 atomic_inc(&dest->refcnt);
78827
78828- conn_flags = atomic_read(&dest->conn_flags);
78829+ conn_flags = atomic_read_unchecked(&dest->conn_flags);
78830 if (cp->protocol != IPPROTO_UDP)
78831 conn_flags &= ~IP_VS_CONN_F_ONE_PACKET;
78832 flags = cp->flags;
78833@@ -902,7 +902,7 @@ ip_vs_conn_new(const struct ip_vs_conn_param *p,
78834 atomic_set(&cp->refcnt, 1);
78835
78836 atomic_set(&cp->n_control, 0);
78837- atomic_set(&cp->in_pkts, 0);
78838+ atomic_set_unchecked(&cp->in_pkts, 0);
78839
78840 atomic_inc(&ipvs->conn_count);
78841 if (flags & IP_VS_CONN_F_NO_CPORT)
78842@@ -1183,7 +1183,7 @@ static inline int todrop_entry(struct ip_vs_conn *cp)
78843
78844 /* Don't drop the entry if its number of incoming packets is not
78845 located in [0, 8] */
78846- i = atomic_read(&cp->in_pkts);
78847+ i = atomic_read_unchecked(&cp->in_pkts);
78848 if (i > 8 || i < 0) return 0;
78849
78850 if (!todrop_rate[i]) return 0;
78851diff --git a/net/netfilter/ipvs/ip_vs_core.c b/net/netfilter/ipvs/ip_vs_core.c
78852index b54ecce..fc5f6cf 100644
78853--- a/net/netfilter/ipvs/ip_vs_core.c
78854+++ b/net/netfilter/ipvs/ip_vs_core.c
78855@@ -562,7 +562,7 @@ int ip_vs_leave(struct ip_vs_service *svc, struct sk_buff *skb,
78856 ret = cp->packet_xmit(skb, cp, pd->pp);
78857 /* do not touch skb anymore */
78858
78859- atomic_inc(&cp->in_pkts);
78860+ atomic_inc_unchecked(&cp->in_pkts);
78861 ip_vs_conn_put(cp);
78862 return ret;
78863 }
78864@@ -1611,7 +1611,7 @@ ip_vs_in(unsigned int hooknum, struct sk_buff *skb, int af)
78865 if (cp->flags & IP_VS_CONN_F_ONE_PACKET)
78866 pkts = sysctl_sync_threshold(ipvs);
78867 else
78868- pkts = atomic_add_return(1, &cp->in_pkts);
78869+ pkts = atomic_add_return_unchecked(1, &cp->in_pkts);
78870
78871 if (ipvs->sync_state & IP_VS_STATE_MASTER)
78872 ip_vs_sync_conn(net, cp, pkts);
78873diff --git a/net/netfilter/ipvs/ip_vs_ctl.c b/net/netfilter/ipvs/ip_vs_ctl.c
78874index f51013c..c99ee52 100644
78875--- a/net/netfilter/ipvs/ip_vs_ctl.c
78876+++ b/net/netfilter/ipvs/ip_vs_ctl.c
78877@@ -788,7 +788,7 @@ __ip_vs_update_dest(struct ip_vs_service *svc, struct ip_vs_dest *dest,
78878 ip_vs_rs_hash(ipvs, dest);
78879 write_unlock_bh(&ipvs->rs_lock);
78880 }
78881- atomic_set(&dest->conn_flags, conn_flags);
78882+ atomic_set_unchecked(&dest->conn_flags, conn_flags);
78883
78884 /* bind the service */
78885 if (!dest->svc) {
78886@@ -2076,7 +2076,7 @@ static int ip_vs_info_seq_show(struct seq_file *seq, void *v)
78887 " %-7s %-6d %-10d %-10d\n",
78888 &dest->addr.in6,
78889 ntohs(dest->port),
78890- ip_vs_fwd_name(atomic_read(&dest->conn_flags)),
78891+ ip_vs_fwd_name(atomic_read_unchecked(&dest->conn_flags)),
78892 atomic_read(&dest->weight),
78893 atomic_read(&dest->activeconns),
78894 atomic_read(&dest->inactconns));
78895@@ -2087,7 +2087,7 @@ static int ip_vs_info_seq_show(struct seq_file *seq, void *v)
78896 "%-7s %-6d %-10d %-10d\n",
78897 ntohl(dest->addr.ip),
78898 ntohs(dest->port),
78899- ip_vs_fwd_name(atomic_read(&dest->conn_flags)),
78900+ ip_vs_fwd_name(atomic_read_unchecked(&dest->conn_flags)),
78901 atomic_read(&dest->weight),
78902 atomic_read(&dest->activeconns),
78903 atomic_read(&dest->inactconns));
78904@@ -2557,7 +2557,7 @@ __ip_vs_get_dest_entries(struct net *net, const struct ip_vs_get_dests *get,
78905
78906 entry.addr = dest->addr.ip;
78907 entry.port = dest->port;
78908- entry.conn_flags = atomic_read(&dest->conn_flags);
78909+ entry.conn_flags = atomic_read_unchecked(&dest->conn_flags);
78910 entry.weight = atomic_read(&dest->weight);
78911 entry.u_threshold = dest->u_threshold;
78912 entry.l_threshold = dest->l_threshold;
78913@@ -3092,7 +3092,7 @@ static int ip_vs_genl_fill_dest(struct sk_buff *skb, struct ip_vs_dest *dest)
78914 if (nla_put(skb, IPVS_DEST_ATTR_ADDR, sizeof(dest->addr), &dest->addr) ||
78915 nla_put_u16(skb, IPVS_DEST_ATTR_PORT, dest->port) ||
78916 nla_put_u32(skb, IPVS_DEST_ATTR_FWD_METHOD,
78917- (atomic_read(&dest->conn_flags) &
78918+ (atomic_read_unchecked(&dest->conn_flags) &
78919 IP_VS_CONN_F_FWD_MASK)) ||
78920 nla_put_u32(skb, IPVS_DEST_ATTR_WEIGHT,
78921 atomic_read(&dest->weight)) ||
78922diff --git a/net/netfilter/ipvs/ip_vs_sync.c b/net/netfilter/ipvs/ip_vs_sync.c
78923index effa10c..9058928 100644
78924--- a/net/netfilter/ipvs/ip_vs_sync.c
78925+++ b/net/netfilter/ipvs/ip_vs_sync.c
78926@@ -596,7 +596,7 @@ static void ip_vs_sync_conn_v0(struct net *net, struct ip_vs_conn *cp,
78927 cp = cp->control;
78928 if (cp) {
78929 if (cp->flags & IP_VS_CONN_F_TEMPLATE)
78930- pkts = atomic_add_return(1, &cp->in_pkts);
78931+ pkts = atomic_add_return_unchecked(1, &cp->in_pkts);
78932 else
78933 pkts = sysctl_sync_threshold(ipvs);
78934 ip_vs_sync_conn(net, cp->control, pkts);
78935@@ -758,7 +758,7 @@ control:
78936 if (!cp)
78937 return;
78938 if (cp->flags & IP_VS_CONN_F_TEMPLATE)
78939- pkts = atomic_add_return(1, &cp->in_pkts);
78940+ pkts = atomic_add_return_unchecked(1, &cp->in_pkts);
78941 else
78942 pkts = sysctl_sync_threshold(ipvs);
78943 goto sloop;
78944@@ -885,7 +885,7 @@ static void ip_vs_proc_conn(struct net *net, struct ip_vs_conn_param *param,
78945
78946 if (opt)
78947 memcpy(&cp->in_seq, opt, sizeof(*opt));
78948- atomic_set(&cp->in_pkts, sysctl_sync_threshold(ipvs));
78949+ atomic_set_unchecked(&cp->in_pkts, sysctl_sync_threshold(ipvs));
78950 cp->state = state;
78951 cp->old_state = cp->state;
78952 /*
78953diff --git a/net/netfilter/ipvs/ip_vs_xmit.c b/net/netfilter/ipvs/ip_vs_xmit.c
78954index c3c6291..3376d73 100644
78955--- a/net/netfilter/ipvs/ip_vs_xmit.c
78956+++ b/net/netfilter/ipvs/ip_vs_xmit.c
78957@@ -1157,7 +1157,7 @@ ip_vs_icmp_xmit(struct sk_buff *skb, struct ip_vs_conn *cp,
78958 else
78959 rc = NF_ACCEPT;
78960 /* do not touch skb anymore */
78961- atomic_inc(&cp->in_pkts);
78962+ atomic_inc_unchecked(&cp->in_pkts);
78963 goto out;
78964 }
78965
78966@@ -1278,7 +1278,7 @@ ip_vs_icmp_xmit_v6(struct sk_buff *skb, struct ip_vs_conn *cp,
78967 else
78968 rc = NF_ACCEPT;
78969 /* do not touch skb anymore */
78970- atomic_inc(&cp->in_pkts);
78971+ atomic_inc_unchecked(&cp->in_pkts);
78972 goto out;
78973 }
78974
78975diff --git a/net/netfilter/nf_conntrack_core.c b/net/netfilter/nf_conntrack_core.c
78976index 2ceec64..a5b8a61 100644
78977--- a/net/netfilter/nf_conntrack_core.c
78978+++ b/net/netfilter/nf_conntrack_core.c
78979@@ -1529,6 +1529,10 @@ err_extend:
78980 #define UNCONFIRMED_NULLS_VAL ((1<<30)+0)
78981 #define DYING_NULLS_VAL ((1<<30)+1)
78982
78983+#ifdef CONFIG_GRKERNSEC_HIDESYM
78984+static atomic_unchecked_t conntrack_cache_id = ATOMIC_INIT(0);
78985+#endif
78986+
78987 static int nf_conntrack_init_net(struct net *net)
78988 {
78989 int ret;
78990@@ -1542,7 +1546,11 @@ static int nf_conntrack_init_net(struct net *net)
78991 goto err_stat;
78992 }
78993
78994+#ifdef CONFIG_GRKERNSEC_HIDESYM
78995+ net->ct.slabname = kasprintf(GFP_KERNEL, "nf_conntrack_%08lx", atomic_inc_return_unchecked(&conntrack_cache_id));
78996+#else
78997 net->ct.slabname = kasprintf(GFP_KERNEL, "nf_conntrack_%p", net);
78998+#endif
78999 if (!net->ct.slabname) {
79000 ret = -ENOMEM;
79001 goto err_slabname;
79002diff --git a/net/netfilter/nfnetlink_log.c b/net/netfilter/nfnetlink_log.c
79003index 5cfb5be..217c6d8 100644
79004--- a/net/netfilter/nfnetlink_log.c
79005+++ b/net/netfilter/nfnetlink_log.c
79006@@ -70,7 +70,7 @@ struct nfulnl_instance {
79007 };
79008
79009 static DEFINE_SPINLOCK(instances_lock);
79010-static atomic_t global_seq;
79011+static atomic_unchecked_t global_seq;
79012
79013 #define INSTANCE_BUCKETS 16
79014 static struct hlist_head instance_table[INSTANCE_BUCKETS];
79015@@ -523,7 +523,7 @@ __build_packet_message(struct nfulnl_instance *inst,
79016 /* global sequence number */
79017 if ((inst->flags & NFULNL_CFG_F_SEQ_GLOBAL) &&
79018 nla_put_be32(inst->skb, NFULA_SEQ_GLOBAL,
79019- htonl(atomic_inc_return(&global_seq))))
79020+ htonl(atomic_inc_return_unchecked(&global_seq))))
79021 goto nla_put_failure;
79022
79023 if (data_len) {
79024diff --git a/net/netfilter/xt_gradm.c b/net/netfilter/xt_gradm.c
79025new file mode 100644
79026index 0000000..c566332
79027--- /dev/null
79028+++ b/net/netfilter/xt_gradm.c
79029@@ -0,0 +1,51 @@
79030+/*
79031+ * gradm match for netfilter
79032