]> git.ipfire.org Git - thirdparty/grsecurity-scrape.git/blame - test/grsecurity-2.9.1-3.6.7-201211221000.patch
Auto commit, 1 new patch{es}.
[thirdparty/grsecurity-scrape.git] / test / grsecurity-2.9.1-3.6.7-201211221000.patch
CommitLineData
ec3b351d
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 07f2308..7271d99 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/sys_parisc.c b/arch/parisc/kernel/sys_parisc.c
3474index 7426e40..30c8dbe 100644
3475--- a/arch/parisc/kernel/sys_parisc.c
3476+++ b/arch/parisc/kernel/sys_parisc.c
3477@@ -43,7 +43,7 @@ static unsigned long get_unshared_area(unsigned long addr, unsigned long len)
3478 /* At this point: (!vma || addr < vma->vm_end). */
3479 if (TASK_SIZE - len < addr)
3480 return -ENOMEM;
3481- if (!vma || addr + len <= vma->vm_start)
3482+ if (check_heap_stack_gap(vma, addr, len))
3483 return addr;
3484 addr = vma->vm_end;
3485 }
3486@@ -79,7 +79,7 @@ static unsigned long get_shared_area(struct address_space *mapping,
3487 /* At this point: (!vma || addr < vma->vm_end). */
3488 if (TASK_SIZE - len < addr)
3489 return -ENOMEM;
3490- if (!vma || addr + len <= vma->vm_start)
3491+ if (check_heap_stack_gap(vma, addr, len))
3492 return addr;
3493 addr = DCACHE_ALIGN(vma->vm_end - offset) + offset;
3494 if (addr < vma->vm_end) /* handle wraparound */
3495@@ -98,7 +98,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr,
3496 if (flags & MAP_FIXED)
3497 return addr;
3498 if (!addr)
3499- addr = TASK_UNMAPPED_BASE;
3500+ addr = current->mm->mmap_base;
3501
3502 if (filp) {
3503 addr = get_shared_area(filp->f_mapping, addr, len, pgoff);
3504diff --git a/arch/parisc/kernel/traps.c b/arch/parisc/kernel/traps.c
3505index 45ba99f..8e22c33 100644
3506--- a/arch/parisc/kernel/traps.c
3507+++ b/arch/parisc/kernel/traps.c
3508@@ -732,9 +732,7 @@ void notrace handle_interruption(int code, struct pt_regs *regs)
3509
3510 down_read(&current->mm->mmap_sem);
3511 vma = find_vma(current->mm,regs->iaoq[0]);
3512- if (vma && (regs->iaoq[0] >= vma->vm_start)
3513- && (vma->vm_flags & VM_EXEC)) {
3514-
3515+ if (vma && (regs->iaoq[0] >= vma->vm_start)) {
3516 fault_address = regs->iaoq[0];
3517 fault_space = regs->iasq[0];
3518
3519diff --git a/arch/parisc/mm/fault.c b/arch/parisc/mm/fault.c
3520index 18162ce..94de376 100644
3521--- a/arch/parisc/mm/fault.c
3522+++ b/arch/parisc/mm/fault.c
3523@@ -15,6 +15,7 @@
3524 #include <linux/sched.h>
3525 #include <linux/interrupt.h>
3526 #include <linux/module.h>
3527+#include <linux/unistd.h>
3528
3529 #include <asm/uaccess.h>
3530 #include <asm/traps.h>
3531@@ -52,7 +53,7 @@ DEFINE_PER_CPU(struct exception_data, exception_data);
3532 static unsigned long
3533 parisc_acctyp(unsigned long code, unsigned int inst)
3534 {
3535- if (code == 6 || code == 16)
3536+ if (code == 6 || code == 7 || code == 16)
3537 return VM_EXEC;
3538
3539 switch (inst & 0xf0000000) {
3540@@ -138,6 +139,116 @@ parisc_acctyp(unsigned long code, unsigned int inst)
3541 }
3542 #endif
3543
3544+#ifdef CONFIG_PAX_PAGEEXEC
3545+/*
3546+ * PaX: decide what to do with offenders (instruction_pointer(regs) = fault address)
3547+ *
3548+ * returns 1 when task should be killed
3549+ * 2 when rt_sigreturn trampoline was detected
3550+ * 3 when unpatched PLT trampoline was detected
3551+ */
3552+static int pax_handle_fetch_fault(struct pt_regs *regs)
3553+{
3554+
3555+#ifdef CONFIG_PAX_EMUPLT
3556+ int err;
3557+
3558+ do { /* PaX: unpatched PLT emulation */
3559+ unsigned int bl, depwi;
3560+
3561+ err = get_user(bl, (unsigned int *)instruction_pointer(regs));
3562+ err |= get_user(depwi, (unsigned int *)(instruction_pointer(regs)+4));
3563+
3564+ if (err)
3565+ break;
3566+
3567+ if (bl == 0xEA9F1FDDU && depwi == 0xD6801C1EU) {
3568+ unsigned int ldw, bv, ldw2, addr = instruction_pointer(regs)-12;
3569+
3570+ err = get_user(ldw, (unsigned int *)addr);
3571+ err |= get_user(bv, (unsigned int *)(addr+4));
3572+ err |= get_user(ldw2, (unsigned int *)(addr+8));
3573+
3574+ if (err)
3575+ break;
3576+
3577+ if (ldw == 0x0E801096U &&
3578+ bv == 0xEAC0C000U &&
3579+ ldw2 == 0x0E881095U)
3580+ {
3581+ unsigned int resolver, map;
3582+
3583+ err = get_user(resolver, (unsigned int *)(instruction_pointer(regs)+8));
3584+ err |= get_user(map, (unsigned int *)(instruction_pointer(regs)+12));
3585+ if (err)
3586+ break;
3587+
3588+ regs->gr[20] = instruction_pointer(regs)+8;
3589+ regs->gr[21] = map;
3590+ regs->gr[22] = resolver;
3591+ regs->iaoq[0] = resolver | 3UL;
3592+ regs->iaoq[1] = regs->iaoq[0] + 4;
3593+ return 3;
3594+ }
3595+ }
3596+ } while (0);
3597+#endif
3598+
3599+#ifdef CONFIG_PAX_EMUTRAMP
3600+
3601+#ifndef CONFIG_PAX_EMUSIGRT
3602+ if (!(current->mm->pax_flags & MF_PAX_EMUTRAMP))
3603+ return 1;
3604+#endif
3605+
3606+ do { /* PaX: rt_sigreturn emulation */
3607+ unsigned int ldi1, ldi2, bel, nop;
3608+
3609+ err = get_user(ldi1, (unsigned int *)instruction_pointer(regs));
3610+ err |= get_user(ldi2, (unsigned int *)(instruction_pointer(regs)+4));
3611+ err |= get_user(bel, (unsigned int *)(instruction_pointer(regs)+8));
3612+ err |= get_user(nop, (unsigned int *)(instruction_pointer(regs)+12));
3613+
3614+ if (err)
3615+ break;
3616+
3617+ if ((ldi1 == 0x34190000U || ldi1 == 0x34190002U) &&
3618+ ldi2 == 0x3414015AU &&
3619+ bel == 0xE4008200U &&
3620+ nop == 0x08000240U)
3621+ {
3622+ regs->gr[25] = (ldi1 & 2) >> 1;
3623+ regs->gr[20] = __NR_rt_sigreturn;
3624+ regs->gr[31] = regs->iaoq[1] + 16;
3625+ regs->sr[0] = regs->iasq[1];
3626+ regs->iaoq[0] = 0x100UL;
3627+ regs->iaoq[1] = regs->iaoq[0] + 4;
3628+ regs->iasq[0] = regs->sr[2];
3629+ regs->iasq[1] = regs->sr[2];
3630+ return 2;
3631+ }
3632+ } while (0);
3633+#endif
3634+
3635+ return 1;
3636+}
3637+
3638+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
3639+{
3640+ unsigned long i;
3641+
3642+ printk(KERN_ERR "PAX: bytes at PC: ");
3643+ for (i = 0; i < 5; i++) {
3644+ unsigned int c;
3645+ if (get_user(c, (unsigned int *)pc+i))
3646+ printk(KERN_CONT "???????? ");
3647+ else
3648+ printk(KERN_CONT "%08x ", c);
3649+ }
3650+ printk("\n");
3651+}
3652+#endif
3653+
3654 int fixup_exception(struct pt_regs *regs)
3655 {
3656 const struct exception_table_entry *fix;
3657@@ -192,8 +303,33 @@ good_area:
3658
3659 acc_type = parisc_acctyp(code,regs->iir);
3660
3661- if ((vma->vm_flags & acc_type) != acc_type)
3662+ if ((vma->vm_flags & acc_type) != acc_type) {
3663+
3664+#ifdef CONFIG_PAX_PAGEEXEC
3665+ if ((mm->pax_flags & MF_PAX_PAGEEXEC) && (acc_type & VM_EXEC) &&
3666+ (address & ~3UL) == instruction_pointer(regs))
3667+ {
3668+ up_read(&mm->mmap_sem);
3669+ switch (pax_handle_fetch_fault(regs)) {
3670+
3671+#ifdef CONFIG_PAX_EMUPLT
3672+ case 3:
3673+ return;
3674+#endif
3675+
3676+#ifdef CONFIG_PAX_EMUTRAMP
3677+ case 2:
3678+ return;
3679+#endif
3680+
3681+ }
3682+ pax_report_fault(regs, (void *)instruction_pointer(regs), (void *)regs->gr[30]);
3683+ do_group_exit(SIGKILL);
3684+ }
3685+#endif
3686+
3687 goto bad_area;
3688+ }
3689
3690 /*
3691 * If for any reason at all we couldn't handle the fault, make
3692diff --git a/arch/powerpc/include/asm/atomic.h b/arch/powerpc/include/asm/atomic.h
3693index da29032..f76c24c 100644
3694--- a/arch/powerpc/include/asm/atomic.h
3695+++ b/arch/powerpc/include/asm/atomic.h
3696@@ -522,6 +522,16 @@ static __inline__ long atomic64_inc_not_zero(atomic64_t *v)
3697 return t1;
3698 }
3699
3700+#define atomic64_read_unchecked(v) atomic64_read(v)
3701+#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
3702+#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
3703+#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
3704+#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
3705+#define atomic64_inc_unchecked(v) atomic64_inc(v)
3706+#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
3707+#define atomic64_dec_unchecked(v) atomic64_dec(v)
3708+#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
3709+
3710 #endif /* __powerpc64__ */
3711
3712 #endif /* __KERNEL__ */
3713diff --git a/arch/powerpc/include/asm/cache.h b/arch/powerpc/include/asm/cache.h
3714index 9e495c9..b6878e5 100644
3715--- a/arch/powerpc/include/asm/cache.h
3716+++ b/arch/powerpc/include/asm/cache.h
3717@@ -3,6 +3,7 @@
3718
3719 #ifdef __KERNEL__
3720
3721+#include <linux/const.h>
3722
3723 /* bytes per L1 cache line */
3724 #if defined(CONFIG_8xx) || defined(CONFIG_403GCX)
3725@@ -22,7 +23,7 @@
3726 #define L1_CACHE_SHIFT 7
3727 #endif
3728
3729-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
3730+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
3731
3732 #define SMP_CACHE_BYTES L1_CACHE_BYTES
3733
3734diff --git a/arch/powerpc/include/asm/elf.h b/arch/powerpc/include/asm/elf.h
3735index 3bf9cca..e7457d0 100644
3736--- a/arch/powerpc/include/asm/elf.h
3737+++ b/arch/powerpc/include/asm/elf.h
3738@@ -178,8 +178,19 @@ typedef elf_fpreg_t elf_vsrreghalf_t32[ELF_NVSRHALFREG];
3739 the loader. We need to make sure that it is out of the way of the program
3740 that it will "exec", and that there is sufficient room for the brk. */
3741
3742-extern unsigned long randomize_et_dyn(unsigned long base);
3743-#define ELF_ET_DYN_BASE (randomize_et_dyn(0x20000000))
3744+#define ELF_ET_DYN_BASE (0x20000000)
3745+
3746+#ifdef CONFIG_PAX_ASLR
3747+#define PAX_ELF_ET_DYN_BASE (0x10000000UL)
3748+
3749+#ifdef __powerpc64__
3750+#define PAX_DELTA_MMAP_LEN (is_32bit_task() ? 16 : 28)
3751+#define PAX_DELTA_STACK_LEN (is_32bit_task() ? 16 : 28)
3752+#else
3753+#define PAX_DELTA_MMAP_LEN 15
3754+#define PAX_DELTA_STACK_LEN 15
3755+#endif
3756+#endif
3757
3758 /*
3759 * Our registers are always unsigned longs, whether we're a 32 bit
3760@@ -274,9 +285,6 @@ extern int arch_setup_additional_pages(struct linux_binprm *bprm,
3761 (0x7ff >> (PAGE_SHIFT - 12)) : \
3762 (0x3ffff >> (PAGE_SHIFT - 12)))
3763
3764-extern unsigned long arch_randomize_brk(struct mm_struct *mm);
3765-#define arch_randomize_brk arch_randomize_brk
3766-
3767 #endif /* __KERNEL__ */
3768
3769 /*
3770diff --git a/arch/powerpc/include/asm/exec.h b/arch/powerpc/include/asm/exec.h
3771index 8196e9c..d83a9f3 100644
3772--- a/arch/powerpc/include/asm/exec.h
3773+++ b/arch/powerpc/include/asm/exec.h
3774@@ -4,6 +4,6 @@
3775 #ifndef _ASM_POWERPC_EXEC_H
3776 #define _ASM_POWERPC_EXEC_H
3777
3778-extern unsigned long arch_align_stack(unsigned long sp);
3779+#define arch_align_stack(x) ((x) & ~0xfUL)
3780
3781 #endif /* _ASM_POWERPC_EXEC_H */
3782diff --git a/arch/powerpc/include/asm/kmap_types.h b/arch/powerpc/include/asm/kmap_types.h
3783index 5acabbd..7ea14fa 100644
3784--- a/arch/powerpc/include/asm/kmap_types.h
3785+++ b/arch/powerpc/include/asm/kmap_types.h
3786@@ -10,7 +10,7 @@
3787 * 2 of the License, or (at your option) any later version.
3788 */
3789
3790-#define KM_TYPE_NR 16
3791+#define KM_TYPE_NR 17
3792
3793 #endif /* __KERNEL__ */
3794 #endif /* _ASM_POWERPC_KMAP_TYPES_H */
3795diff --git a/arch/powerpc/include/asm/mman.h b/arch/powerpc/include/asm/mman.h
3796index d4a7f64..451de1c 100644
3797--- a/arch/powerpc/include/asm/mman.h
3798+++ b/arch/powerpc/include/asm/mman.h
3799@@ -44,7 +44,7 @@ static inline unsigned long arch_calc_vm_prot_bits(unsigned long prot)
3800 }
3801 #define arch_calc_vm_prot_bits(prot) arch_calc_vm_prot_bits(prot)
3802
3803-static inline pgprot_t arch_vm_get_page_prot(unsigned long vm_flags)
3804+static inline pgprot_t arch_vm_get_page_prot(vm_flags_t vm_flags)
3805 {
3806 return (vm_flags & VM_SAO) ? __pgprot(_PAGE_SAO) : __pgprot(0);
3807 }
3808diff --git a/arch/powerpc/include/asm/page.h b/arch/powerpc/include/asm/page.h
3809index f072e97..b436dee 100644
3810--- a/arch/powerpc/include/asm/page.h
3811+++ b/arch/powerpc/include/asm/page.h
3812@@ -220,8 +220,9 @@ extern long long virt_phys_offset;
3813 * and needs to be executable. This means the whole heap ends
3814 * up being executable.
3815 */
3816-#define VM_DATA_DEFAULT_FLAGS32 (VM_READ | VM_WRITE | VM_EXEC | \
3817- VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
3818+#define VM_DATA_DEFAULT_FLAGS32 \
3819+ (((current->personality & READ_IMPLIES_EXEC) ? VM_EXEC : 0) | \
3820+ VM_READ | VM_WRITE | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
3821
3822 #define VM_DATA_DEFAULT_FLAGS64 (VM_READ | VM_WRITE | \
3823 VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
3824@@ -249,6 +250,9 @@ extern long long virt_phys_offset;
3825 #define is_kernel_addr(x) ((x) >= PAGE_OFFSET)
3826 #endif
3827
3828+#define ktla_ktva(addr) (addr)
3829+#define ktva_ktla(addr) (addr)
3830+
3831 /*
3832 * Use the top bit of the higher-level page table entries to indicate whether
3833 * the entries we point to contain hugepages. This works because we know that
3834diff --git a/arch/powerpc/include/asm/page_64.h b/arch/powerpc/include/asm/page_64.h
3835index fed85e6..da5c71b 100644
3836--- a/arch/powerpc/include/asm/page_64.h
3837+++ b/arch/powerpc/include/asm/page_64.h
3838@@ -146,15 +146,18 @@ do { \
3839 * stack by default, so in the absence of a PT_GNU_STACK program header
3840 * we turn execute permission off.
3841 */
3842-#define VM_STACK_DEFAULT_FLAGS32 (VM_READ | VM_WRITE | VM_EXEC | \
3843- VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
3844+#define VM_STACK_DEFAULT_FLAGS32 \
3845+ (((current->personality & READ_IMPLIES_EXEC) ? VM_EXEC : 0) | \
3846+ VM_READ | VM_WRITE | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
3847
3848 #define VM_STACK_DEFAULT_FLAGS64 (VM_READ | VM_WRITE | \
3849 VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
3850
3851+#ifndef CONFIG_PAX_PAGEEXEC
3852 #define VM_STACK_DEFAULT_FLAGS \
3853 (is_32bit_task() ? \
3854 VM_STACK_DEFAULT_FLAGS32 : VM_STACK_DEFAULT_FLAGS64)
3855+#endif
3856
3857 #include <asm-generic/getorder.h>
3858
3859diff --git a/arch/powerpc/include/asm/pgalloc-64.h b/arch/powerpc/include/asm/pgalloc-64.h
3860index 292725c..f87ae14 100644
3861--- a/arch/powerpc/include/asm/pgalloc-64.h
3862+++ b/arch/powerpc/include/asm/pgalloc-64.h
3863@@ -50,6 +50,7 @@ static inline void pgd_free(struct mm_struct *mm, pgd_t *pgd)
3864 #ifndef CONFIG_PPC_64K_PAGES
3865
3866 #define pgd_populate(MM, PGD, PUD) pgd_set(PGD, PUD)
3867+#define pgd_populate_kernel(MM, PGD, PUD) pgd_populate((MM), (PGD), (PUD))
3868
3869 static inline pud_t *pud_alloc_one(struct mm_struct *mm, unsigned long addr)
3870 {
3871@@ -67,6 +68,11 @@ static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
3872 pud_set(pud, (unsigned long)pmd);
3873 }
3874
3875+static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
3876+{
3877+ pud_populate(mm, pud, pmd);
3878+}
3879+
3880 #define pmd_populate(mm, pmd, pte_page) \
3881 pmd_populate_kernel(mm, pmd, page_address(pte_page))
3882 #define pmd_populate_kernel(mm, pmd, pte) pmd_set(pmd, (unsigned long)(pte))
3883@@ -76,6 +82,7 @@ static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
3884 #else /* CONFIG_PPC_64K_PAGES */
3885
3886 #define pud_populate(mm, pud, pmd) pud_set(pud, (unsigned long)pmd)
3887+#define pud_populate_kernel(mm, pud, pmd) pud_populate((mm), (pud), (pmd))
3888
3889 static inline void pmd_populate_kernel(struct mm_struct *mm, pmd_t *pmd,
3890 pte_t *pte)
3891diff --git a/arch/powerpc/include/asm/pgtable.h b/arch/powerpc/include/asm/pgtable.h
3892index 2e0e411..7899c68 100644
3893--- a/arch/powerpc/include/asm/pgtable.h
3894+++ b/arch/powerpc/include/asm/pgtable.h
3895@@ -2,6 +2,7 @@
3896 #define _ASM_POWERPC_PGTABLE_H
3897 #ifdef __KERNEL__
3898
3899+#include <linux/const.h>
3900 #ifndef __ASSEMBLY__
3901 #include <asm/processor.h> /* For TASK_SIZE */
3902 #include <asm/mmu.h>
3903diff --git a/arch/powerpc/include/asm/pte-hash32.h b/arch/powerpc/include/asm/pte-hash32.h
3904index 4aad413..85d86bf 100644
3905--- a/arch/powerpc/include/asm/pte-hash32.h
3906+++ b/arch/powerpc/include/asm/pte-hash32.h
3907@@ -21,6 +21,7 @@
3908 #define _PAGE_FILE 0x004 /* when !present: nonlinear file mapping */
3909 #define _PAGE_USER 0x004 /* usermode access allowed */
3910 #define _PAGE_GUARDED 0x008 /* G: prohibit speculative access */
3911+#define _PAGE_EXEC _PAGE_GUARDED
3912 #define _PAGE_COHERENT 0x010 /* M: enforce memory coherence (SMP systems) */
3913 #define _PAGE_NO_CACHE 0x020 /* I: cache inhibit */
3914 #define _PAGE_WRITETHRU 0x040 /* W: cache write-through */
3915diff --git a/arch/powerpc/include/asm/reg.h b/arch/powerpc/include/asm/reg.h
3916index 6386086..6982225 100644
3917--- a/arch/powerpc/include/asm/reg.h
3918+++ b/arch/powerpc/include/asm/reg.h
3919@@ -212,6 +212,7 @@
3920 #define SPRN_DBCR 0x136 /* e300 Data Breakpoint Control Reg */
3921 #define SPRN_DSISR 0x012 /* Data Storage Interrupt Status Register */
3922 #define DSISR_NOHPTE 0x40000000 /* no translation found */
3923+#define DSISR_GUARDED 0x10000000 /* fetch from guarded storage */
3924 #define DSISR_PROTFAULT 0x08000000 /* protection fault */
3925 #define DSISR_ISSTORE 0x02000000 /* access was a store */
3926 #define DSISR_DABRMATCH 0x00400000 /* hit data breakpoint */
3927diff --git a/arch/powerpc/include/asm/thread_info.h b/arch/powerpc/include/asm/thread_info.h
3928index faf9352..ab2ccec 100644
3929--- a/arch/powerpc/include/asm/thread_info.h
3930+++ b/arch/powerpc/include/asm/thread_info.h
3931@@ -97,12 +97,14 @@ static inline struct thread_info *current_thread_info(void)
3932 #define TIF_PERFMON_CTXSW 6 /* perfmon needs ctxsw calls */
3933 #define TIF_SYSCALL_AUDIT 7 /* syscall auditing active */
3934 #define TIF_SINGLESTEP 8 /* singlestepping active */
3935-#define TIF_MEMDIE 9 /* is terminating due to OOM killer */
3936 #define TIF_SECCOMP 10 /* secure computing */
3937 #define TIF_RESTOREALL 11 /* Restore all regs (implies NOERROR) */
3938 #define TIF_NOERROR 12 /* Force successful syscall return */
3939 #define TIF_NOTIFY_RESUME 13 /* callback before returning to user */
3940 #define TIF_SYSCALL_TRACEPOINT 15 /* syscall tracepoint instrumentation */
3941+#define TIF_MEMDIE 16 /* is terminating due to OOM killer */
3942+/* mask must be expressable within 16 bits to satisfy 'andi' instruction reqs */
3943+#define TIF_GRSEC_SETXID 9 /* update credentials on syscall entry/exit */
3944
3945 /* as above, but as bit values */
3946 #define _TIF_SYSCALL_TRACE (1<<TIF_SYSCALL_TRACE)
3947@@ -119,8 +121,10 @@ static inline struct thread_info *current_thread_info(void)
3948 #define _TIF_NOERROR (1<<TIF_NOERROR)
3949 #define _TIF_NOTIFY_RESUME (1<<TIF_NOTIFY_RESUME)
3950 #define _TIF_SYSCALL_TRACEPOINT (1<<TIF_SYSCALL_TRACEPOINT)
3951+#define _TIF_GRSEC_SETXID (1<<TIF_GRSEC_SETXID)
3952 #define _TIF_SYSCALL_T_OR_A (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | \
3953- _TIF_SECCOMP | _TIF_SYSCALL_TRACEPOINT)
3954+ _TIF_SECCOMP | _TIF_SYSCALL_TRACEPOINT | \
3955+ _TIF_GRSEC_SETXID)
3956
3957 #define _TIF_USER_WORK_MASK (_TIF_SIGPENDING | _TIF_NEED_RESCHED | \
3958 _TIF_NOTIFY_RESUME)
3959diff --git a/arch/powerpc/include/asm/uaccess.h b/arch/powerpc/include/asm/uaccess.h
3960index 17bb40c..353c98b 100644
3961--- a/arch/powerpc/include/asm/uaccess.h
3962+++ b/arch/powerpc/include/asm/uaccess.h
3963@@ -13,6 +13,8 @@
3964 #define VERIFY_READ 0
3965 #define VERIFY_WRITE 1
3966
3967+extern void check_object_size(const void *ptr, unsigned long n, bool to);
3968+
3969 /*
3970 * The fs value determines whether argument validity checking should be
3971 * performed or not. If get_fs() == USER_DS, checking is performed, with
3972@@ -329,52 +331,6 @@ do { \
3973 extern unsigned long __copy_tofrom_user(void __user *to,
3974 const void __user *from, unsigned long size);
3975
3976-#ifndef __powerpc64__
3977-
3978-static inline unsigned long copy_from_user(void *to,
3979- const void __user *from, unsigned long n)
3980-{
3981- unsigned long over;
3982-
3983- if (access_ok(VERIFY_READ, from, n))
3984- return __copy_tofrom_user((__force void __user *)to, from, n);
3985- if ((unsigned long)from < TASK_SIZE) {
3986- over = (unsigned long)from + n - TASK_SIZE;
3987- return __copy_tofrom_user((__force void __user *)to, from,
3988- n - over) + over;
3989- }
3990- return n;
3991-}
3992-
3993-static inline unsigned long copy_to_user(void __user *to,
3994- const void *from, unsigned long n)
3995-{
3996- unsigned long over;
3997-
3998- if (access_ok(VERIFY_WRITE, to, n))
3999- return __copy_tofrom_user(to, (__force void __user *)from, n);
4000- if ((unsigned long)to < TASK_SIZE) {
4001- over = (unsigned long)to + n - TASK_SIZE;
4002- return __copy_tofrom_user(to, (__force void __user *)from,
4003- n - over) + over;
4004- }
4005- return n;
4006-}
4007-
4008-#else /* __powerpc64__ */
4009-
4010-#define __copy_in_user(to, from, size) \
4011- __copy_tofrom_user((to), (from), (size))
4012-
4013-extern unsigned long copy_from_user(void *to, const void __user *from,
4014- unsigned long n);
4015-extern unsigned long copy_to_user(void __user *to, const void *from,
4016- unsigned long n);
4017-extern unsigned long copy_in_user(void __user *to, const void __user *from,
4018- unsigned long n);
4019-
4020-#endif /* __powerpc64__ */
4021-
4022 static inline unsigned long __copy_from_user_inatomic(void *to,
4023 const void __user *from, unsigned long n)
4024 {
4025@@ -398,6 +354,10 @@ static inline unsigned long __copy_from_user_inatomic(void *to,
4026 if (ret == 0)
4027 return 0;
4028 }
4029+
4030+ if (!__builtin_constant_p(n))
4031+ check_object_size(to, n, false);
4032+
4033 return __copy_tofrom_user((__force void __user *)to, from, n);
4034 }
4035
4036@@ -424,6 +384,10 @@ static inline unsigned long __copy_to_user_inatomic(void __user *to,
4037 if (ret == 0)
4038 return 0;
4039 }
4040+
4041+ if (!__builtin_constant_p(n))
4042+ check_object_size(from, n, true);
4043+
4044 return __copy_tofrom_user(to, (__force const void __user *)from, n);
4045 }
4046
4047@@ -441,6 +405,92 @@ static inline unsigned long __copy_to_user(void __user *to,
4048 return __copy_to_user_inatomic(to, from, size);
4049 }
4050
4051+#ifndef __powerpc64__
4052+
4053+static inline unsigned long __must_check copy_from_user(void *to,
4054+ const void __user *from, unsigned long n)
4055+{
4056+ unsigned long over;
4057+
4058+ if ((long)n < 0)
4059+ return n;
4060+
4061+ if (access_ok(VERIFY_READ, from, n)) {
4062+ if (!__builtin_constant_p(n))
4063+ check_object_size(to, n, false);
4064+ return __copy_tofrom_user((__force void __user *)to, from, n);
4065+ }
4066+ if ((unsigned long)from < TASK_SIZE) {
4067+ over = (unsigned long)from + n - TASK_SIZE;
4068+ if (!__builtin_constant_p(n - over))
4069+ check_object_size(to, n - over, false);
4070+ return __copy_tofrom_user((__force void __user *)to, from,
4071+ n - over) + over;
4072+ }
4073+ return n;
4074+}
4075+
4076+static inline unsigned long __must_check copy_to_user(void __user *to,
4077+ const void *from, unsigned long n)
4078+{
4079+ unsigned long over;
4080+
4081+ if ((long)n < 0)
4082+ return n;
4083+
4084+ if (access_ok(VERIFY_WRITE, to, n)) {
4085+ if (!__builtin_constant_p(n))
4086+ check_object_size(from, n, true);
4087+ return __copy_tofrom_user(to, (__force void __user *)from, n);
4088+ }
4089+ if ((unsigned long)to < TASK_SIZE) {
4090+ over = (unsigned long)to + n - TASK_SIZE;
4091+ if (!__builtin_constant_p(n))
4092+ check_object_size(from, n - over, true);
4093+ return __copy_tofrom_user(to, (__force void __user *)from,
4094+ n - over) + over;
4095+ }
4096+ return n;
4097+}
4098+
4099+#else /* __powerpc64__ */
4100+
4101+#define __copy_in_user(to, from, size) \
4102+ __copy_tofrom_user((to), (from), (size))
4103+
4104+static inline unsigned long __must_check copy_from_user(void *to, const void __user *from, unsigned long n)
4105+{
4106+ if ((long)n < 0 || n > INT_MAX)
4107+ return n;
4108+
4109+ if (!__builtin_constant_p(n))
4110+ check_object_size(to, n, false);
4111+
4112+ if (likely(access_ok(VERIFY_READ, from, n)))
4113+ n = __copy_from_user(to, from, n);
4114+ else
4115+ memset(to, 0, n);
4116+ return n;
4117+}
4118+
4119+static inline unsigned long __must_check copy_to_user(void __user *to, const void *from, unsigned long n)
4120+{
4121+ if ((long)n < 0 || n > INT_MAX)
4122+ return n;
4123+
4124+ if (likely(access_ok(VERIFY_WRITE, to, n))) {
4125+ if (!__builtin_constant_p(n))
4126+ check_object_size(from, n, true);
4127+ n = __copy_to_user(to, from, n);
4128+ }
4129+ return n;
4130+}
4131+
4132+extern unsigned long copy_in_user(void __user *to, const void __user *from,
4133+ unsigned long n);
4134+
4135+#endif /* __powerpc64__ */
4136+
4137 extern unsigned long __clear_user(void __user *addr, unsigned long size);
4138
4139 static inline unsigned long clear_user(void __user *addr, unsigned long size)
4140diff --git a/arch/powerpc/kernel/exceptions-64e.S b/arch/powerpc/kernel/exceptions-64e.S
4141index 98be7f0..8ef62de 100644
4142--- a/arch/powerpc/kernel/exceptions-64e.S
4143+++ b/arch/powerpc/kernel/exceptions-64e.S
4144@@ -661,6 +661,7 @@ storage_fault_common:
4145 std r14,_DAR(r1)
4146 std r15,_DSISR(r1)
4147 addi r3,r1,STACK_FRAME_OVERHEAD
4148+ bl .save_nvgprs
4149 mr r4,r14
4150 mr r5,r15
4151 ld r14,PACA_EXGEN+EX_R14(r13)
4152@@ -669,8 +670,7 @@ storage_fault_common:
4153 cmpdi r3,0
4154 bne- 1f
4155 b .ret_from_except_lite
4156-1: bl .save_nvgprs
4157- mr r5,r3
4158+1: mr r5,r3
4159 addi r3,r1,STACK_FRAME_OVERHEAD
4160 ld r4,_DAR(r1)
4161 bl .bad_page_fault
4162diff --git a/arch/powerpc/kernel/exceptions-64s.S b/arch/powerpc/kernel/exceptions-64s.S
4163index 39aa97d..dc916ee 100644
4164--- a/arch/powerpc/kernel/exceptions-64s.S
4165+++ b/arch/powerpc/kernel/exceptions-64s.S
4166@@ -890,10 +890,10 @@ handle_page_fault:
4167 11: ld r4,_DAR(r1)
4168 ld r5,_DSISR(r1)
4169 addi r3,r1,STACK_FRAME_OVERHEAD
4170+ bl .save_nvgprs
4171 bl .do_page_fault
4172 cmpdi r3,0
4173 beq+ 12f
4174- bl .save_nvgprs
4175 mr r5,r3
4176 addi r3,r1,STACK_FRAME_OVERHEAD
4177 lwz r4,_DAR(r1)
4178diff --git a/arch/powerpc/kernel/module_32.c b/arch/powerpc/kernel/module_32.c
4179index 2e3200c..72095ce 100644
4180--- a/arch/powerpc/kernel/module_32.c
4181+++ b/arch/powerpc/kernel/module_32.c
4182@@ -162,7 +162,7 @@ int module_frob_arch_sections(Elf32_Ehdr *hdr,
4183 me->arch.core_plt_section = i;
4184 }
4185 if (!me->arch.core_plt_section || !me->arch.init_plt_section) {
4186- printk("Module doesn't contain .plt or .init.plt sections.\n");
4187+ printk("Module %s doesn't contain .plt or .init.plt sections.\n", me->name);
4188 return -ENOEXEC;
4189 }
4190
4191@@ -192,11 +192,16 @@ static uint32_t do_plt_call(void *location,
4192
4193 DEBUGP("Doing plt for call to 0x%x at 0x%x\n", val, (unsigned int)location);
4194 /* Init, or core PLT? */
4195- if (location >= mod->module_core
4196- && location < mod->module_core + mod->core_size)
4197+ if ((location >= mod->module_core_rx && location < mod->module_core_rx + mod->core_size_rx) ||
4198+ (location >= mod->module_core_rw && location < mod->module_core_rw + mod->core_size_rw))
4199 entry = (void *)sechdrs[mod->arch.core_plt_section].sh_addr;
4200- else
4201+ else if ((location >= mod->module_init_rx && location < mod->module_init_rx + mod->init_size_rx) ||
4202+ (location >= mod->module_init_rw && location < mod->module_init_rw + mod->init_size_rw))
4203 entry = (void *)sechdrs[mod->arch.init_plt_section].sh_addr;
4204+ else {
4205+ printk(KERN_ERR "%s: invalid R_PPC_REL24 entry found\n", mod->name);
4206+ return ~0UL;
4207+ }
4208
4209 /* Find this entry, or if that fails, the next avail. entry */
4210 while (entry->jump[0]) {
4211diff --git a/arch/powerpc/kernel/process.c b/arch/powerpc/kernel/process.c
4212index 1a1f2dd..f4d1bb4 100644
4213--- a/arch/powerpc/kernel/process.c
4214+++ b/arch/powerpc/kernel/process.c
4215@@ -681,8 +681,8 @@ void show_regs(struct pt_regs * regs)
4216 * Lookup NIP late so we have the best change of getting the
4217 * above info out without failing
4218 */
4219- printk("NIP ["REG"] %pS\n", regs->nip, (void *)regs->nip);
4220- printk("LR ["REG"] %pS\n", regs->link, (void *)regs->link);
4221+ printk("NIP ["REG"] %pA\n", regs->nip, (void *)regs->nip);
4222+ printk("LR ["REG"] %pA\n", regs->link, (void *)regs->link);
4223 #endif
4224 show_stack(current, (unsigned long *) regs->gpr[1]);
4225 if (!user_mode(regs))
4226@@ -1181,10 +1181,10 @@ void show_stack(struct task_struct *tsk, unsigned long *stack)
4227 newsp = stack[0];
4228 ip = stack[STACK_FRAME_LR_SAVE];
4229 if (!firstframe || ip != lr) {
4230- printk("["REG"] ["REG"] %pS", sp, ip, (void *)ip);
4231+ printk("["REG"] ["REG"] %pA", sp, ip, (void *)ip);
4232 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
4233 if ((ip == rth || ip == mrth) && curr_frame >= 0) {
4234- printk(" (%pS)",
4235+ printk(" (%pA)",
4236 (void *)current->ret_stack[curr_frame].ret);
4237 curr_frame--;
4238 }
4239@@ -1204,7 +1204,7 @@ void show_stack(struct task_struct *tsk, unsigned long *stack)
4240 struct pt_regs *regs = (struct pt_regs *)
4241 (sp + STACK_FRAME_OVERHEAD);
4242 lr = regs->link;
4243- printk("--- Exception: %lx at %pS\n LR = %pS\n",
4244+ printk("--- Exception: %lx at %pA\n LR = %pA\n",
4245 regs->trap, (void *)regs->nip, (void *)lr);
4246 firstframe = 1;
4247 }
4248@@ -1246,58 +1246,3 @@ void __ppc64_runlatch_off(void)
4249 mtspr(SPRN_CTRLT, ctrl);
4250 }
4251 #endif /* CONFIG_PPC64 */
4252-
4253-unsigned long arch_align_stack(unsigned long sp)
4254-{
4255- if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
4256- sp -= get_random_int() & ~PAGE_MASK;
4257- return sp & ~0xf;
4258-}
4259-
4260-static inline unsigned long brk_rnd(void)
4261-{
4262- unsigned long rnd = 0;
4263-
4264- /* 8MB for 32bit, 1GB for 64bit */
4265- if (is_32bit_task())
4266- rnd = (long)(get_random_int() % (1<<(23-PAGE_SHIFT)));
4267- else
4268- rnd = (long)(get_random_int() % (1<<(30-PAGE_SHIFT)));
4269-
4270- return rnd << PAGE_SHIFT;
4271-}
4272-
4273-unsigned long arch_randomize_brk(struct mm_struct *mm)
4274-{
4275- unsigned long base = mm->brk;
4276- unsigned long ret;
4277-
4278-#ifdef CONFIG_PPC_STD_MMU_64
4279- /*
4280- * If we are using 1TB segments and we are allowed to randomise
4281- * the heap, we can put it above 1TB so it is backed by a 1TB
4282- * segment. Otherwise the heap will be in the bottom 1TB
4283- * which always uses 256MB segments and this may result in a
4284- * performance penalty.
4285- */
4286- if (!is_32bit_task() && (mmu_highuser_ssize == MMU_SEGSIZE_1T))
4287- base = max_t(unsigned long, mm->brk, 1UL << SID_SHIFT_1T);
4288-#endif
4289-
4290- ret = PAGE_ALIGN(base + brk_rnd());
4291-
4292- if (ret < mm->brk)
4293- return mm->brk;
4294-
4295- return ret;
4296-}
4297-
4298-unsigned long randomize_et_dyn(unsigned long base)
4299-{
4300- unsigned long ret = PAGE_ALIGN(base + brk_rnd());
4301-
4302- if (ret < base)
4303- return base;
4304-
4305- return ret;
4306-}
4307diff --git a/arch/powerpc/kernel/ptrace.c b/arch/powerpc/kernel/ptrace.c
4308index c10fc28..c4ef063 100644
4309--- a/arch/powerpc/kernel/ptrace.c
4310+++ b/arch/powerpc/kernel/ptrace.c
4311@@ -1660,6 +1660,10 @@ long arch_ptrace(struct task_struct *child, long request,
4312 return ret;
4313 }
4314
4315+#ifdef CONFIG_GRKERNSEC_SETXID
4316+extern void gr_delayed_cred_worker(void);
4317+#endif
4318+
4319 /*
4320 * We must return the syscall number to actually look up in the table.
4321 * This can be -1L to skip running any syscall at all.
4322@@ -1670,6 +1674,11 @@ long do_syscall_trace_enter(struct pt_regs *regs)
4323
4324 secure_computing_strict(regs->gpr[0]);
4325
4326+#ifdef CONFIG_GRKERNSEC_SETXID
4327+ if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
4328+ gr_delayed_cred_worker();
4329+#endif
4330+
4331 if (test_thread_flag(TIF_SYSCALL_TRACE) &&
4332 tracehook_report_syscall_entry(regs))
4333 /*
4334@@ -1704,6 +1713,11 @@ void do_syscall_trace_leave(struct pt_regs *regs)
4335 {
4336 int step;
4337
4338+#ifdef CONFIG_GRKERNSEC_SETXID
4339+ if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
4340+ gr_delayed_cred_worker();
4341+#endif
4342+
4343 audit_syscall_exit(regs);
4344
4345 if (unlikely(test_thread_flag(TIF_SYSCALL_TRACEPOINT)))
4346diff --git a/arch/powerpc/kernel/signal_32.c b/arch/powerpc/kernel/signal_32.c
4347index 8b4c049..dcd6ef3 100644
4348--- a/arch/powerpc/kernel/signal_32.c
4349+++ b/arch/powerpc/kernel/signal_32.c
4350@@ -852,7 +852,7 @@ int handle_rt_signal32(unsigned long sig, struct k_sigaction *ka,
4351 /* Save user registers on the stack */
4352 frame = &rt_sf->uc.uc_mcontext;
4353 addr = frame;
4354- if (vdso32_rt_sigtramp && current->mm->context.vdso_base) {
4355+ if (vdso32_rt_sigtramp && current->mm->context.vdso_base != ~0UL) {
4356 if (save_user_regs(regs, frame, 0, 1))
4357 goto badframe;
4358 regs->link = current->mm->context.vdso_base + vdso32_rt_sigtramp;
4359diff --git a/arch/powerpc/kernel/signal_64.c b/arch/powerpc/kernel/signal_64.c
4360index d183f87..1867f1a 100644
4361--- a/arch/powerpc/kernel/signal_64.c
4362+++ b/arch/powerpc/kernel/signal_64.c
4363@@ -430,7 +430,7 @@ int handle_rt_signal64(int signr, struct k_sigaction *ka, siginfo_t *info,
4364 current->thread.fpscr.val = 0;
4365
4366 /* Set up to return from userspace. */
4367- if (vdso64_rt_sigtramp && current->mm->context.vdso_base) {
4368+ if (vdso64_rt_sigtramp && current->mm->context.vdso_base != ~0UL) {
4369 regs->link = current->mm->context.vdso_base + vdso64_rt_sigtramp;
4370 } else {
4371 err |= setup_trampoline(__NR_rt_sigreturn, &frame->tramp[0]);
4372diff --git a/arch/powerpc/kernel/traps.c b/arch/powerpc/kernel/traps.c
4373index ae0843f..f16372c 100644
4374--- a/arch/powerpc/kernel/traps.c
4375+++ b/arch/powerpc/kernel/traps.c
4376@@ -133,6 +133,8 @@ static unsigned __kprobes long oops_begin(struct pt_regs *regs)
4377 return flags;
4378 }
4379
4380+extern void gr_handle_kernel_exploit(void);
4381+
4382 static void __kprobes oops_end(unsigned long flags, struct pt_regs *regs,
4383 int signr)
4384 {
4385@@ -182,6 +184,9 @@ static void __kprobes oops_end(unsigned long flags, struct pt_regs *regs,
4386 panic("Fatal exception in interrupt");
4387 if (panic_on_oops)
4388 panic("Fatal exception");
4389+
4390+ gr_handle_kernel_exploit();
4391+
4392 do_exit(signr);
4393 }
4394
4395diff --git a/arch/powerpc/kernel/vdso.c b/arch/powerpc/kernel/vdso.c
4396index b67db22..38825d2 100644
4397--- a/arch/powerpc/kernel/vdso.c
4398+++ b/arch/powerpc/kernel/vdso.c
4399@@ -34,6 +34,7 @@
4400 #include <asm/firmware.h>
4401 #include <asm/vdso.h>
4402 #include <asm/vdso_datapage.h>
4403+#include <asm/mman.h>
4404
4405 #include "setup.h"
4406
4407@@ -218,7 +219,7 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
4408 vdso_base = VDSO32_MBASE;
4409 #endif
4410
4411- current->mm->context.vdso_base = 0;
4412+ current->mm->context.vdso_base = ~0UL;
4413
4414 /* vDSO has a problem and was disabled, just don't "enable" it for the
4415 * process
4416@@ -238,7 +239,7 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
4417 vdso_base = get_unmapped_area(NULL, vdso_base,
4418 (vdso_pages << PAGE_SHIFT) +
4419 ((VDSO_ALIGNMENT - 1) & PAGE_MASK),
4420- 0, 0);
4421+ 0, MAP_PRIVATE | MAP_EXECUTABLE);
4422 if (IS_ERR_VALUE(vdso_base)) {
4423 rc = vdso_base;
4424 goto fail_mmapsem;
4425diff --git a/arch/powerpc/lib/usercopy_64.c b/arch/powerpc/lib/usercopy_64.c
4426index 5eea6f3..5d10396 100644
4427--- a/arch/powerpc/lib/usercopy_64.c
4428+++ b/arch/powerpc/lib/usercopy_64.c
4429@@ -9,22 +9,6 @@
4430 #include <linux/module.h>
4431 #include <asm/uaccess.h>
4432
4433-unsigned long copy_from_user(void *to, const void __user *from, unsigned long n)
4434-{
4435- if (likely(access_ok(VERIFY_READ, from, n)))
4436- n = __copy_from_user(to, from, n);
4437- else
4438- memset(to, 0, n);
4439- return n;
4440-}
4441-
4442-unsigned long copy_to_user(void __user *to, const void *from, unsigned long n)
4443-{
4444- if (likely(access_ok(VERIFY_WRITE, to, n)))
4445- n = __copy_to_user(to, from, n);
4446- return n;
4447-}
4448-
4449 unsigned long copy_in_user(void __user *to, const void __user *from,
4450 unsigned long n)
4451 {
4452@@ -35,7 +19,5 @@ unsigned long copy_in_user(void __user *to, const void __user *from,
4453 return n;
4454 }
4455
4456-EXPORT_SYMBOL(copy_from_user);
4457-EXPORT_SYMBOL(copy_to_user);
4458 EXPORT_SYMBOL(copy_in_user);
4459
4460diff --git a/arch/powerpc/mm/fault.c b/arch/powerpc/mm/fault.c
4461index 08ffcf5..a0ab912 100644
4462--- a/arch/powerpc/mm/fault.c
4463+++ b/arch/powerpc/mm/fault.c
4464@@ -32,6 +32,10 @@
4465 #include <linux/perf_event.h>
4466 #include <linux/magic.h>
4467 #include <linux/ratelimit.h>
4468+#include <linux/slab.h>
4469+#include <linux/pagemap.h>
4470+#include <linux/compiler.h>
4471+#include <linux/unistd.h>
4472
4473 #include <asm/firmware.h>
4474 #include <asm/page.h>
4475@@ -68,6 +72,33 @@ static inline int notify_page_fault(struct pt_regs *regs)
4476 }
4477 #endif
4478
4479+#ifdef CONFIG_PAX_PAGEEXEC
4480+/*
4481+ * PaX: decide what to do with offenders (regs->nip = fault address)
4482+ *
4483+ * returns 1 when task should be killed
4484+ */
4485+static int pax_handle_fetch_fault(struct pt_regs *regs)
4486+{
4487+ return 1;
4488+}
4489+
4490+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
4491+{
4492+ unsigned long i;
4493+
4494+ printk(KERN_ERR "PAX: bytes at PC: ");
4495+ for (i = 0; i < 5; i++) {
4496+ unsigned int c;
4497+ if (get_user(c, (unsigned int __user *)pc+i))
4498+ printk(KERN_CONT "???????? ");
4499+ else
4500+ printk(KERN_CONT "%08x ", c);
4501+ }
4502+ printk("\n");
4503+}
4504+#endif
4505+
4506 /*
4507 * Check whether the instruction at regs->nip is a store using
4508 * an update addressing form which will update r1.
4509@@ -215,7 +246,7 @@ int __kprobes do_page_fault(struct pt_regs *regs, unsigned long address,
4510 * indicate errors in DSISR but can validly be set in SRR1.
4511 */
4512 if (trap == 0x400)
4513- error_code &= 0x48200000;
4514+ error_code &= 0x58200000;
4515 else
4516 is_write = error_code & DSISR_ISSTORE;
4517 #else
4518@@ -366,7 +397,7 @@ good_area:
4519 * "undefined". Of those that can be set, this is the only
4520 * one which seems bad.
4521 */
4522- if (error_code & 0x10000000)
4523+ if (error_code & DSISR_GUARDED)
4524 /* Guarded storage error. */
4525 goto bad_area;
4526 #endif /* CONFIG_8xx */
4527@@ -381,7 +412,7 @@ good_area:
4528 * processors use the same I/D cache coherency mechanism
4529 * as embedded.
4530 */
4531- if (error_code & DSISR_PROTFAULT)
4532+ if (error_code & (DSISR_PROTFAULT | DSISR_GUARDED))
4533 goto bad_area;
4534 #endif /* CONFIG_PPC_STD_MMU */
4535
4536@@ -463,6 +494,23 @@ bad_area:
4537 bad_area_nosemaphore:
4538 /* User mode accesses cause a SIGSEGV */
4539 if (user_mode(regs)) {
4540+
4541+#ifdef CONFIG_PAX_PAGEEXEC
4542+ if (mm->pax_flags & MF_PAX_PAGEEXEC) {
4543+#ifdef CONFIG_PPC_STD_MMU
4544+ if (is_exec && (error_code & (DSISR_PROTFAULT | DSISR_GUARDED))) {
4545+#else
4546+ if (is_exec && regs->nip == address) {
4547+#endif
4548+ switch (pax_handle_fetch_fault(regs)) {
4549+ }
4550+
4551+ pax_report_fault(regs, (void *)regs->nip, (void *)regs->gpr[PT_R1]);
4552+ do_group_exit(SIGKILL);
4553+ }
4554+ }
4555+#endif
4556+
4557 _exception(SIGSEGV, regs, code, address);
4558 return 0;
4559 }
4560diff --git a/arch/powerpc/mm/mmap_64.c b/arch/powerpc/mm/mmap_64.c
4561index 67a42ed..1c7210c 100644
4562--- a/arch/powerpc/mm/mmap_64.c
4563+++ b/arch/powerpc/mm/mmap_64.c
4564@@ -91,10 +91,22 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
4565 */
4566 if (mmap_is_legacy()) {
4567 mm->mmap_base = TASK_UNMAPPED_BASE;
4568+
4569+#ifdef CONFIG_PAX_RANDMMAP
4570+ if (mm->pax_flags & MF_PAX_RANDMMAP)
4571+ mm->mmap_base += mm->delta_mmap;
4572+#endif
4573+
4574 mm->get_unmapped_area = arch_get_unmapped_area;
4575 mm->unmap_area = arch_unmap_area;
4576 } else {
4577 mm->mmap_base = mmap_base();
4578+
4579+#ifdef CONFIG_PAX_RANDMMAP
4580+ if (mm->pax_flags & MF_PAX_RANDMMAP)
4581+ mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
4582+#endif
4583+
4584 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
4585 mm->unmap_area = arch_unmap_area_topdown;
4586 }
4587diff --git a/arch/powerpc/mm/slice.c b/arch/powerpc/mm/slice.c
4588index 73709f7..6b90313 100644
4589--- a/arch/powerpc/mm/slice.c
4590+++ b/arch/powerpc/mm/slice.c
4591@@ -98,7 +98,7 @@ static int slice_area_is_free(struct mm_struct *mm, unsigned long addr,
4592 if ((mm->task_size - len) < addr)
4593 return 0;
4594 vma = find_vma(mm, addr);
4595- return (!vma || (addr + len) <= vma->vm_start);
4596+ return check_heap_stack_gap(vma, addr, len);
4597 }
4598
4599 static int slice_low_has_vma(struct mm_struct *mm, unsigned long slice)
4600@@ -256,7 +256,7 @@ full_search:
4601 addr = _ALIGN_UP(addr + 1, 1ul << SLICE_HIGH_SHIFT);
4602 continue;
4603 }
4604- if (!vma || addr + len <= vma->vm_start) {
4605+ if (check_heap_stack_gap(vma, addr, len)) {
4606 /*
4607 * Remember the place where we stopped the search:
4608 */
4609@@ -313,10 +313,14 @@ static unsigned long slice_find_area_topdown(struct mm_struct *mm,
4610 }
4611 }
4612
4613- addr = mm->mmap_base;
4614- while (addr > len) {
4615+ if (mm->mmap_base < len)
4616+ addr = -ENOMEM;
4617+ else
4618+ addr = mm->mmap_base - len;
4619+
4620+ while (!IS_ERR_VALUE(addr)) {
4621 /* Go down by chunk size */
4622- addr = _ALIGN_DOWN(addr - len, 1ul << pshift);
4623+ addr = _ALIGN_DOWN(addr, 1ul << pshift);
4624
4625 /* Check for hit with different page size */
4626 mask = slice_range_to_mask(addr, len);
4627@@ -336,7 +340,7 @@ static unsigned long slice_find_area_topdown(struct mm_struct *mm,
4628 * return with success:
4629 */
4630 vma = find_vma(mm, addr);
4631- if (!vma || (addr + len) <= vma->vm_start) {
4632+ if (check_heap_stack_gap(vma, addr, len)) {
4633 /* remember the address as a hint for next time */
4634 if (use_cache)
4635 mm->free_area_cache = addr;
4636@@ -348,7 +352,7 @@ static unsigned long slice_find_area_topdown(struct mm_struct *mm,
4637 mm->cached_hole_size = vma->vm_start - addr;
4638
4639 /* try just below the current vma->vm_start */
4640- addr = vma->vm_start;
4641+ addr = skip_heap_stack_gap(vma, len);
4642 }
4643
4644 /*
4645@@ -426,6 +430,11 @@ unsigned long slice_get_unmapped_area(unsigned long addr, unsigned long len,
4646 if (fixed && addr > (mm->task_size - len))
4647 return -EINVAL;
4648
4649+#ifdef CONFIG_PAX_RANDMMAP
4650+ if (!fixed && (mm->pax_flags & MF_PAX_RANDMMAP))
4651+ addr = 0;
4652+#endif
4653+
4654 /* If hint, make sure it matches our alignment restrictions */
4655 if (!fixed && addr) {
4656 addr = _ALIGN_UP(addr, 1ul << pshift);
4657diff --git a/arch/s390/include/asm/atomic.h b/arch/s390/include/asm/atomic.h
4658index c797832..ce575c8 100644
4659--- a/arch/s390/include/asm/atomic.h
4660+++ b/arch/s390/include/asm/atomic.h
4661@@ -326,6 +326,16 @@ static inline long long atomic64_dec_if_positive(atomic64_t *v)
4662 #define atomic64_dec_and_test(_v) (atomic64_sub_return(1, _v) == 0)
4663 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
4664
4665+#define atomic64_read_unchecked(v) atomic64_read(v)
4666+#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
4667+#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
4668+#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
4669+#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
4670+#define atomic64_inc_unchecked(v) atomic64_inc(v)
4671+#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
4672+#define atomic64_dec_unchecked(v) atomic64_dec(v)
4673+#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
4674+
4675 #define smp_mb__before_atomic_dec() smp_mb()
4676 #define smp_mb__after_atomic_dec() smp_mb()
4677 #define smp_mb__before_atomic_inc() smp_mb()
4678diff --git a/arch/s390/include/asm/cache.h b/arch/s390/include/asm/cache.h
4679index 4d7ccac..d03d0ad 100644
4680--- a/arch/s390/include/asm/cache.h
4681+++ b/arch/s390/include/asm/cache.h
4682@@ -9,8 +9,10 @@
4683 #ifndef __ARCH_S390_CACHE_H
4684 #define __ARCH_S390_CACHE_H
4685
4686-#define L1_CACHE_BYTES 256
4687+#include <linux/const.h>
4688+
4689 #define L1_CACHE_SHIFT 8
4690+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
4691 #define NET_SKB_PAD 32
4692
4693 #define __read_mostly __attribute__((__section__(".data..read_mostly")))
4694diff --git a/arch/s390/include/asm/elf.h b/arch/s390/include/asm/elf.h
4695index 9b94a16..63d4034 100644
4696--- a/arch/s390/include/asm/elf.h
4697+++ b/arch/s390/include/asm/elf.h
4698@@ -159,8 +159,14 @@ extern unsigned int vdso_enabled;
4699 the loader. We need to make sure that it is out of the way of the program
4700 that it will "exec", and that there is sufficient room for the brk. */
4701
4702-extern unsigned long randomize_et_dyn(unsigned long base);
4703-#define ELF_ET_DYN_BASE (randomize_et_dyn(STACK_TOP / 3 * 2))
4704+#define ELF_ET_DYN_BASE (STACK_TOP / 3 * 2)
4705+
4706+#ifdef CONFIG_PAX_ASLR
4707+#define PAX_ELF_ET_DYN_BASE (test_thread_flag(TIF_31BIT) ? 0x10000UL : 0x80000000UL)
4708+
4709+#define PAX_DELTA_MMAP_LEN (test_thread_flag(TIF_31BIT) ? 15 : 26)
4710+#define PAX_DELTA_STACK_LEN (test_thread_flag(TIF_31BIT) ? 15 : 26)
4711+#endif
4712
4713 /* This yields a mask that user programs can use to figure out what
4714 instruction set this CPU supports. */
4715@@ -209,7 +215,4 @@ struct linux_binprm;
4716 #define ARCH_HAS_SETUP_ADDITIONAL_PAGES 1
4717 int arch_setup_additional_pages(struct linux_binprm *, int);
4718
4719-extern unsigned long arch_randomize_brk(struct mm_struct *mm);
4720-#define arch_randomize_brk arch_randomize_brk
4721-
4722 #endif
4723diff --git a/arch/s390/include/asm/exec.h b/arch/s390/include/asm/exec.h
4724index c4a93d6..4d2a9b4 100644
4725--- a/arch/s390/include/asm/exec.h
4726+++ b/arch/s390/include/asm/exec.h
4727@@ -7,6 +7,6 @@
4728 #ifndef __ASM_EXEC_H
4729 #define __ASM_EXEC_H
4730
4731-extern unsigned long arch_align_stack(unsigned long sp);
4732+#define arch_align_stack(x) ((x) & ~0xfUL)
4733
4734 #endif /* __ASM_EXEC_H */
4735diff --git a/arch/s390/include/asm/uaccess.h b/arch/s390/include/asm/uaccess.h
4736index a8ab18b..75ddbf0 100644
4737--- a/arch/s390/include/asm/uaccess.h
4738+++ b/arch/s390/include/asm/uaccess.h
4739@@ -239,6 +239,10 @@ static inline unsigned long __must_check
4740 copy_to_user(void __user *to, const void *from, unsigned long n)
4741 {
4742 might_fault();
4743+
4744+ if ((long)n < 0)
4745+ return n;
4746+
4747 if (access_ok(VERIFY_WRITE, to, n))
4748 n = __copy_to_user(to, from, n);
4749 return n;
4750@@ -264,6 +268,9 @@ copy_to_user(void __user *to, const void *from, unsigned long n)
4751 static inline unsigned long __must_check
4752 __copy_from_user(void *to, const void __user *from, unsigned long n)
4753 {
4754+ if ((long)n < 0)
4755+ return n;
4756+
4757 if (__builtin_constant_p(n) && (n <= 256))
4758 return uaccess.copy_from_user_small(n, from, to);
4759 else
4760@@ -295,10 +302,14 @@ __compiletime_warning("copy_from_user() buffer size is not provably correct")
4761 static inline unsigned long __must_check
4762 copy_from_user(void *to, const void __user *from, unsigned long n)
4763 {
4764- unsigned int sz = __compiletime_object_size(to);
4765+ size_t sz = __compiletime_object_size(to);
4766
4767 might_fault();
4768- if (unlikely(sz != -1 && sz < n)) {
4769+
4770+ if ((long)n < 0)
4771+ return n;
4772+
4773+ if (unlikely(sz != (size_t)-1 && sz < n)) {
4774 copy_from_user_overflow();
4775 return n;
4776 }
4777diff --git a/arch/s390/kernel/module.c b/arch/s390/kernel/module.c
4778index 46412b1..e32874f 100644
4779--- a/arch/s390/kernel/module.c
4780+++ b/arch/s390/kernel/module.c
4781@@ -160,11 +160,11 @@ module_frob_arch_sections(Elf_Ehdr *hdr, Elf_Shdr *sechdrs,
4782
4783 /* Increase core size by size of got & plt and set start
4784 offsets for got and plt. */
4785- me->core_size = ALIGN(me->core_size, 4);
4786- me->arch.got_offset = me->core_size;
4787- me->core_size += me->arch.got_size;
4788- me->arch.plt_offset = me->core_size;
4789- me->core_size += me->arch.plt_size;
4790+ me->core_size_rw = ALIGN(me->core_size_rw, 4);
4791+ me->arch.got_offset = me->core_size_rw;
4792+ me->core_size_rw += me->arch.got_size;
4793+ me->arch.plt_offset = me->core_size_rx;
4794+ me->core_size_rx += me->arch.plt_size;
4795 return 0;
4796 }
4797
4798@@ -241,7 +241,7 @@ apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
4799 if (info->got_initialized == 0) {
4800 Elf_Addr *gotent;
4801
4802- gotent = me->module_core + me->arch.got_offset +
4803+ gotent = me->module_core_rw + me->arch.got_offset +
4804 info->got_offset;
4805 *gotent = val;
4806 info->got_initialized = 1;
4807@@ -265,7 +265,7 @@ apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
4808 else if (r_type == R_390_GOTENT ||
4809 r_type == R_390_GOTPLTENT)
4810 *(unsigned int *) loc =
4811- (val + (Elf_Addr) me->module_core - loc) >> 1;
4812+ (val + (Elf_Addr) me->module_core_rw - loc) >> 1;
4813 else if (r_type == R_390_GOT64 ||
4814 r_type == R_390_GOTPLT64)
4815 *(unsigned long *) loc = val;
4816@@ -279,7 +279,7 @@ apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
4817 case R_390_PLTOFF64: /* 16 bit offset from GOT to PLT. */
4818 if (info->plt_initialized == 0) {
4819 unsigned int *ip;
4820- ip = me->module_core + me->arch.plt_offset +
4821+ ip = me->module_core_rx + me->arch.plt_offset +
4822 info->plt_offset;
4823 #ifndef CONFIG_64BIT
4824 ip[0] = 0x0d105810; /* basr 1,0; l 1,6(1); br 1 */
4825@@ -304,7 +304,7 @@ apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
4826 val - loc + 0xffffUL < 0x1ffffeUL) ||
4827 (r_type == R_390_PLT32DBL &&
4828 val - loc + 0xffffffffULL < 0x1fffffffeULL)))
4829- val = (Elf_Addr) me->module_core +
4830+ val = (Elf_Addr) me->module_core_rx +
4831 me->arch.plt_offset +
4832 info->plt_offset;
4833 val += rela->r_addend - loc;
4834@@ -326,7 +326,7 @@ apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
4835 case R_390_GOTOFF32: /* 32 bit offset to GOT. */
4836 case R_390_GOTOFF64: /* 64 bit offset to GOT. */
4837 val = val + rela->r_addend -
4838- ((Elf_Addr) me->module_core + me->arch.got_offset);
4839+ ((Elf_Addr) me->module_core_rw + me->arch.got_offset);
4840 if (r_type == R_390_GOTOFF16)
4841 *(unsigned short *) loc = val;
4842 else if (r_type == R_390_GOTOFF32)
4843@@ -336,7 +336,7 @@ apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
4844 break;
4845 case R_390_GOTPC: /* 32 bit PC relative offset to GOT. */
4846 case R_390_GOTPCDBL: /* 32 bit PC rel. off. to GOT shifted by 1. */
4847- val = (Elf_Addr) me->module_core + me->arch.got_offset +
4848+ val = (Elf_Addr) me->module_core_rw + me->arch.got_offset +
4849 rela->r_addend - loc;
4850 if (r_type == R_390_GOTPC)
4851 *(unsigned int *) loc = val;
4852diff --git a/arch/s390/kernel/process.c b/arch/s390/kernel/process.c
4853index 7331753..dd71de4 100644
4854--- a/arch/s390/kernel/process.c
4855+++ b/arch/s390/kernel/process.c
4856@@ -316,39 +316,3 @@ unsigned long get_wchan(struct task_struct *p)
4857 }
4858 return 0;
4859 }
4860-
4861-unsigned long arch_align_stack(unsigned long sp)
4862-{
4863- if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
4864- sp -= get_random_int() & ~PAGE_MASK;
4865- return sp & ~0xf;
4866-}
4867-
4868-static inline unsigned long brk_rnd(void)
4869-{
4870- /* 8MB for 32bit, 1GB for 64bit */
4871- if (is_32bit_task())
4872- return (get_random_int() & 0x7ffUL) << PAGE_SHIFT;
4873- else
4874- return (get_random_int() & 0x3ffffUL) << PAGE_SHIFT;
4875-}
4876-
4877-unsigned long arch_randomize_brk(struct mm_struct *mm)
4878-{
4879- unsigned long ret = PAGE_ALIGN(mm->brk + brk_rnd());
4880-
4881- if (ret < mm->brk)
4882- return mm->brk;
4883- return ret;
4884-}
4885-
4886-unsigned long randomize_et_dyn(unsigned long base)
4887-{
4888- unsigned long ret = PAGE_ALIGN(base + brk_rnd());
4889-
4890- if (!(current->flags & PF_RANDOMIZE))
4891- return base;
4892- if (ret < base)
4893- return base;
4894- return ret;
4895-}
4896diff --git a/arch/s390/mm/mmap.c b/arch/s390/mm/mmap.c
4897index c59a5ef..3fae59c 100644
4898--- a/arch/s390/mm/mmap.c
4899+++ b/arch/s390/mm/mmap.c
4900@@ -90,10 +90,22 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
4901 */
4902 if (mmap_is_legacy()) {
4903 mm->mmap_base = TASK_UNMAPPED_BASE;
4904+
4905+#ifdef CONFIG_PAX_RANDMMAP
4906+ if (mm->pax_flags & MF_PAX_RANDMMAP)
4907+ mm->mmap_base += mm->delta_mmap;
4908+#endif
4909+
4910 mm->get_unmapped_area = arch_get_unmapped_area;
4911 mm->unmap_area = arch_unmap_area;
4912 } else {
4913 mm->mmap_base = mmap_base();
4914+
4915+#ifdef CONFIG_PAX_RANDMMAP
4916+ if (mm->pax_flags & MF_PAX_RANDMMAP)
4917+ mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
4918+#endif
4919+
4920 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
4921 mm->unmap_area = arch_unmap_area_topdown;
4922 }
4923@@ -172,10 +184,22 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
4924 */
4925 if (mmap_is_legacy()) {
4926 mm->mmap_base = TASK_UNMAPPED_BASE;
4927+
4928+#ifdef CONFIG_PAX_RANDMMAP
4929+ if (mm->pax_flags & MF_PAX_RANDMMAP)
4930+ mm->mmap_base += mm->delta_mmap;
4931+#endif
4932+
4933 mm->get_unmapped_area = s390_get_unmapped_area;
4934 mm->unmap_area = arch_unmap_area;
4935 } else {
4936 mm->mmap_base = mmap_base();
4937+
4938+#ifdef CONFIG_PAX_RANDMMAP
4939+ if (mm->pax_flags & MF_PAX_RANDMMAP)
4940+ mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
4941+#endif
4942+
4943 mm->get_unmapped_area = s390_get_unmapped_area_topdown;
4944 mm->unmap_area = arch_unmap_area_topdown;
4945 }
4946diff --git a/arch/score/include/asm/cache.h b/arch/score/include/asm/cache.h
4947index ae3d59f..f65f075 100644
4948--- a/arch/score/include/asm/cache.h
4949+++ b/arch/score/include/asm/cache.h
4950@@ -1,7 +1,9 @@
4951 #ifndef _ASM_SCORE_CACHE_H
4952 #define _ASM_SCORE_CACHE_H
4953
4954+#include <linux/const.h>
4955+
4956 #define L1_CACHE_SHIFT 4
4957-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
4958+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
4959
4960 #endif /* _ASM_SCORE_CACHE_H */
4961diff --git a/arch/score/include/asm/exec.h b/arch/score/include/asm/exec.h
4962index f9f3cd5..58ff438 100644
4963--- a/arch/score/include/asm/exec.h
4964+++ b/arch/score/include/asm/exec.h
4965@@ -1,6 +1,6 @@
4966 #ifndef _ASM_SCORE_EXEC_H
4967 #define _ASM_SCORE_EXEC_H
4968
4969-extern unsigned long arch_align_stack(unsigned long sp);
4970+#define arch_align_stack(x) (x)
4971
4972 #endif /* _ASM_SCORE_EXEC_H */
4973diff --git a/arch/score/kernel/process.c b/arch/score/kernel/process.c
4974index 637970c..0b6556b 100644
4975--- a/arch/score/kernel/process.c
4976+++ b/arch/score/kernel/process.c
4977@@ -161,8 +161,3 @@ unsigned long get_wchan(struct task_struct *task)
4978
4979 return task_pt_regs(task)->cp0_epc;
4980 }
4981-
4982-unsigned long arch_align_stack(unsigned long sp)
4983-{
4984- return sp;
4985-}
4986diff --git a/arch/sh/include/asm/cache.h b/arch/sh/include/asm/cache.h
4987index ef9e555..331bd29 100644
4988--- a/arch/sh/include/asm/cache.h
4989+++ b/arch/sh/include/asm/cache.h
4990@@ -9,10 +9,11 @@
4991 #define __ASM_SH_CACHE_H
4992 #ifdef __KERNEL__
4993
4994+#include <linux/const.h>
4995 #include <linux/init.h>
4996 #include <cpu/cache.h>
4997
4998-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
4999+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
5000
5001 #define __read_mostly __attribute__((__section__(".data..read_mostly")))
5002
5003diff --git a/arch/sh/mm/mmap.c b/arch/sh/mm/mmap.c
5004index afeb710..d1d1289 100644
5005--- a/arch/sh/mm/mmap.c
5006+++ b/arch/sh/mm/mmap.c
5007@@ -74,8 +74,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr,
5008 addr = PAGE_ALIGN(addr);
5009
5010 vma = find_vma(mm, addr);
5011- if (TASK_SIZE - len >= addr &&
5012- (!vma || addr + len <= vma->vm_start))
5013+ if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len))
5014 return addr;
5015 }
5016
5017@@ -106,7 +105,7 @@ full_search:
5018 }
5019 return -ENOMEM;
5020 }
5021- if (likely(!vma || addr + len <= vma->vm_start)) {
5022+ if (likely(check_heap_stack_gap(vma, addr, len))) {
5023 /*
5024 * Remember the place where we stopped the search:
5025 */
5026@@ -157,8 +156,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
5027 addr = PAGE_ALIGN(addr);
5028
5029 vma = find_vma(mm, addr);
5030- if (TASK_SIZE - len >= addr &&
5031- (!vma || addr + len <= vma->vm_start))
5032+ if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len))
5033 return addr;
5034 }
5035
5036@@ -179,7 +177,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
5037 /* make sure it can fit in the remaining address space */
5038 if (likely(addr > len)) {
5039 vma = find_vma(mm, addr-len);
5040- if (!vma || addr <= vma->vm_start) {
5041+ if (check_heap_stack_gap(vma, addr - len, len)) {
5042 /* remember the address as a hint for next time */
5043 return (mm->free_area_cache = addr-len);
5044 }
5045@@ -188,18 +186,18 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
5046 if (unlikely(mm->mmap_base < len))
5047 goto bottomup;
5048
5049- addr = mm->mmap_base-len;
5050- if (do_colour_align)
5051- addr = COLOUR_ALIGN_DOWN(addr, pgoff);
5052+ addr = mm->mmap_base - len;
5053
5054 do {
5055+ if (do_colour_align)
5056+ addr = COLOUR_ALIGN_DOWN(addr, pgoff);
5057 /*
5058 * Lookup failure means no vma is above this address,
5059 * else if new region fits below vma->vm_start,
5060 * return with success:
5061 */
5062 vma = find_vma(mm, addr);
5063- if (likely(!vma || addr+len <= vma->vm_start)) {
5064+ if (likely(check_heap_stack_gap(vma, addr, len))) {
5065 /* remember the address as a hint for next time */
5066 return (mm->free_area_cache = addr);
5067 }
5068@@ -209,10 +207,8 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
5069 mm->cached_hole_size = vma->vm_start - addr;
5070
5071 /* try just below the current vma->vm_start */
5072- addr = vma->vm_start-len;
5073- if (do_colour_align)
5074- addr = COLOUR_ALIGN_DOWN(addr, pgoff);
5075- } while (likely(len < vma->vm_start));
5076+ addr = skip_heap_stack_gap(vma, len);
5077+ } while (!IS_ERR_VALUE(addr));
5078
5079 bottomup:
5080 /*
5081diff --git a/arch/sparc/include/asm/atomic_64.h b/arch/sparc/include/asm/atomic_64.h
5082index ce35a1c..2e7b8f9 100644
5083--- a/arch/sparc/include/asm/atomic_64.h
5084+++ b/arch/sparc/include/asm/atomic_64.h
5085@@ -14,18 +14,40 @@
5086 #define ATOMIC64_INIT(i) { (i) }
5087
5088 #define atomic_read(v) (*(volatile int *)&(v)->counter)
5089+static inline int atomic_read_unchecked(const atomic_unchecked_t *v)
5090+{
5091+ return v->counter;
5092+}
5093 #define atomic64_read(v) (*(volatile long *)&(v)->counter)
5094+static inline long atomic64_read_unchecked(const atomic64_unchecked_t *v)
5095+{
5096+ return v->counter;
5097+}
5098
5099 #define atomic_set(v, i) (((v)->counter) = i)
5100+static inline void atomic_set_unchecked(atomic_unchecked_t *v, int i)
5101+{
5102+ v->counter = i;
5103+}
5104 #define atomic64_set(v, i) (((v)->counter) = i)
5105+static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, long i)
5106+{
5107+ v->counter = i;
5108+}
5109
5110 extern void atomic_add(int, atomic_t *);
5111+extern void atomic_add_unchecked(int, atomic_unchecked_t *);
5112 extern void atomic64_add(long, atomic64_t *);
5113+extern void atomic64_add_unchecked(long, atomic64_unchecked_t *);
5114 extern void atomic_sub(int, atomic_t *);
5115+extern void atomic_sub_unchecked(int, atomic_unchecked_t *);
5116 extern void atomic64_sub(long, atomic64_t *);
5117+extern void atomic64_sub_unchecked(long, atomic64_unchecked_t *);
5118
5119 extern int atomic_add_ret(int, atomic_t *);
5120+extern int atomic_add_ret_unchecked(int, atomic_unchecked_t *);
5121 extern long atomic64_add_ret(long, atomic64_t *);
5122+extern long atomic64_add_ret_unchecked(long, atomic64_unchecked_t *);
5123 extern int atomic_sub_ret(int, atomic_t *);
5124 extern long atomic64_sub_ret(long, atomic64_t *);
5125
5126@@ -33,13 +55,29 @@ extern long atomic64_sub_ret(long, atomic64_t *);
5127 #define atomic64_dec_return(v) atomic64_sub_ret(1, v)
5128
5129 #define atomic_inc_return(v) atomic_add_ret(1, v)
5130+static inline int atomic_inc_return_unchecked(atomic_unchecked_t *v)
5131+{
5132+ return atomic_add_ret_unchecked(1, v);
5133+}
5134 #define atomic64_inc_return(v) atomic64_add_ret(1, v)
5135+static inline long atomic64_inc_return_unchecked(atomic64_unchecked_t *v)
5136+{
5137+ return atomic64_add_ret_unchecked(1, v);
5138+}
5139
5140 #define atomic_sub_return(i, v) atomic_sub_ret(i, v)
5141 #define atomic64_sub_return(i, v) atomic64_sub_ret(i, v)
5142
5143 #define atomic_add_return(i, v) atomic_add_ret(i, v)
5144+static inline int atomic_add_return_unchecked(int i, atomic_unchecked_t *v)
5145+{
5146+ return atomic_add_ret_unchecked(i, v);
5147+}
5148 #define atomic64_add_return(i, v) atomic64_add_ret(i, v)
5149+static inline long atomic64_add_return_unchecked(long i, atomic64_unchecked_t *v)
5150+{
5151+ return atomic64_add_ret_unchecked(i, v);
5152+}
5153
5154 /*
5155 * atomic_inc_and_test - increment and test
5156@@ -50,6 +88,10 @@ extern long atomic64_sub_ret(long, atomic64_t *);
5157 * other cases.
5158 */
5159 #define atomic_inc_and_test(v) (atomic_inc_return(v) == 0)
5160+static inline int atomic_inc_and_test_unchecked(atomic_unchecked_t *v)
5161+{
5162+ return atomic_inc_return_unchecked(v) == 0;
5163+}
5164 #define atomic64_inc_and_test(v) (atomic64_inc_return(v) == 0)
5165
5166 #define atomic_sub_and_test(i, v) (atomic_sub_ret(i, v) == 0)
5167@@ -59,25 +101,60 @@ extern long atomic64_sub_ret(long, atomic64_t *);
5168 #define atomic64_dec_and_test(v) (atomic64_sub_ret(1, v) == 0)
5169
5170 #define atomic_inc(v) atomic_add(1, v)
5171+static inline void atomic_inc_unchecked(atomic_unchecked_t *v)
5172+{
5173+ atomic_add_unchecked(1, v);
5174+}
5175 #define atomic64_inc(v) atomic64_add(1, v)
5176+static inline void atomic64_inc_unchecked(atomic64_unchecked_t *v)
5177+{
5178+ atomic64_add_unchecked(1, v);
5179+}
5180
5181 #define atomic_dec(v) atomic_sub(1, v)
5182+static inline void atomic_dec_unchecked(atomic_unchecked_t *v)
5183+{
5184+ atomic_sub_unchecked(1, v);
5185+}
5186 #define atomic64_dec(v) atomic64_sub(1, v)
5187+static inline void atomic64_dec_unchecked(atomic64_unchecked_t *v)
5188+{
5189+ atomic64_sub_unchecked(1, v);
5190+}
5191
5192 #define atomic_add_negative(i, v) (atomic_add_ret(i, v) < 0)
5193 #define atomic64_add_negative(i, v) (atomic64_add_ret(i, v) < 0)
5194
5195 #define atomic_cmpxchg(v, o, n) (cmpxchg(&((v)->counter), (o), (n)))
5196+static inline int atomic_cmpxchg_unchecked(atomic_unchecked_t *v, int old, int new)
5197+{
5198+ return cmpxchg(&v->counter, old, new);
5199+}
5200 #define atomic_xchg(v, new) (xchg(&((v)->counter), new))
5201+static inline int atomic_xchg_unchecked(atomic_unchecked_t *v, int new)
5202+{
5203+ return xchg(&v->counter, new);
5204+}
5205
5206 static inline int __atomic_add_unless(atomic_t *v, int a, int u)
5207 {
5208- int c, old;
5209+ int c, old, new;
5210 c = atomic_read(v);
5211 for (;;) {
5212- if (unlikely(c == (u)))
5213+ if (unlikely(c == u))
5214 break;
5215- old = atomic_cmpxchg((v), c, c + (a));
5216+
5217+ asm volatile("addcc %2, %0, %0\n"
5218+
5219+#ifdef CONFIG_PAX_REFCOUNT
5220+ "tvs %%icc, 6\n"
5221+#endif
5222+
5223+ : "=r" (new)
5224+ : "0" (c), "ir" (a)
5225+ : "cc");
5226+
5227+ old = atomic_cmpxchg(v, c, new);
5228 if (likely(old == c))
5229 break;
5230 c = old;
5231@@ -88,20 +165,35 @@ static inline int __atomic_add_unless(atomic_t *v, int a, int u)
5232 #define atomic64_cmpxchg(v, o, n) \
5233 ((__typeof__((v)->counter))cmpxchg(&((v)->counter), (o), (n)))
5234 #define atomic64_xchg(v, new) (xchg(&((v)->counter), new))
5235+static inline long atomic64_xchg_unchecked(atomic64_unchecked_t *v, long new)
5236+{
5237+ return xchg(&v->counter, new);
5238+}
5239
5240 static inline long atomic64_add_unless(atomic64_t *v, long a, long u)
5241 {
5242- long c, old;
5243+ long c, old, new;
5244 c = atomic64_read(v);
5245 for (;;) {
5246- if (unlikely(c == (u)))
5247+ if (unlikely(c == u))
5248 break;
5249- old = atomic64_cmpxchg((v), c, c + (a));
5250+
5251+ asm volatile("addcc %2, %0, %0\n"
5252+
5253+#ifdef CONFIG_PAX_REFCOUNT
5254+ "tvs %%xcc, 6\n"
5255+#endif
5256+
5257+ : "=r" (new)
5258+ : "0" (c), "ir" (a)
5259+ : "cc");
5260+
5261+ old = atomic64_cmpxchg(v, c, new);
5262 if (likely(old == c))
5263 break;
5264 c = old;
5265 }
5266- return c != (u);
5267+ return c != u;
5268 }
5269
5270 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
5271diff --git a/arch/sparc/include/asm/cache.h b/arch/sparc/include/asm/cache.h
5272index 5bb6991..5c2132e 100644
5273--- a/arch/sparc/include/asm/cache.h
5274+++ b/arch/sparc/include/asm/cache.h
5275@@ -7,10 +7,12 @@
5276 #ifndef _SPARC_CACHE_H
5277 #define _SPARC_CACHE_H
5278
5279+#include <linux/const.h>
5280+
5281 #define ARCH_SLAB_MINALIGN __alignof__(unsigned long long)
5282
5283 #define L1_CACHE_SHIFT 5
5284-#define L1_CACHE_BYTES 32
5285+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
5286
5287 #ifdef CONFIG_SPARC32
5288 #define SMP_CACHE_BYTES_SHIFT 5
5289diff --git a/arch/sparc/include/asm/elf_32.h b/arch/sparc/include/asm/elf_32.h
5290index 2d4d755..81b6662 100644
5291--- a/arch/sparc/include/asm/elf_32.h
5292+++ b/arch/sparc/include/asm/elf_32.h
5293@@ -114,6 +114,13 @@ typedef struct {
5294
5295 #define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE)
5296
5297+#ifdef CONFIG_PAX_ASLR
5298+#define PAX_ELF_ET_DYN_BASE 0x10000UL
5299+
5300+#define PAX_DELTA_MMAP_LEN 16
5301+#define PAX_DELTA_STACK_LEN 16
5302+#endif
5303+
5304 /* This yields a mask that user programs can use to figure out what
5305 instruction set this cpu supports. This can NOT be done in userspace
5306 on Sparc. */
5307diff --git a/arch/sparc/include/asm/elf_64.h b/arch/sparc/include/asm/elf_64.h
5308index 7df8b7f..4946269 100644
5309--- a/arch/sparc/include/asm/elf_64.h
5310+++ b/arch/sparc/include/asm/elf_64.h
5311@@ -180,6 +180,13 @@ typedef struct {
5312 #define ELF_ET_DYN_BASE 0x0000010000000000UL
5313 #define COMPAT_ELF_ET_DYN_BASE 0x0000000070000000UL
5314
5315+#ifdef CONFIG_PAX_ASLR
5316+#define PAX_ELF_ET_DYN_BASE (test_thread_flag(TIF_32BIT) ? 0x10000UL : 0x100000UL)
5317+
5318+#define PAX_DELTA_MMAP_LEN (test_thread_flag(TIF_32BIT) ? 14 : 28)
5319+#define PAX_DELTA_STACK_LEN (test_thread_flag(TIF_32BIT) ? 15 : 29)
5320+#endif
5321+
5322 extern unsigned long sparc64_elf_hwcap;
5323 #define ELF_HWCAP sparc64_elf_hwcap
5324
5325diff --git a/arch/sparc/include/asm/pgalloc_32.h b/arch/sparc/include/asm/pgalloc_32.h
5326index 9b1c36d..209298b 100644
5327--- a/arch/sparc/include/asm/pgalloc_32.h
5328+++ b/arch/sparc/include/asm/pgalloc_32.h
5329@@ -33,6 +33,7 @@ static inline void pgd_set(pgd_t * pgdp, pmd_t * pmdp)
5330 }
5331
5332 #define pgd_populate(MM, PGD, PMD) pgd_set(PGD, PMD)
5333+#define pgd_populate_kernel(MM, PGD, PMD) pgd_populate((MM), (PGD), (PMD))
5334
5335 static inline pmd_t *pmd_alloc_one(struct mm_struct *mm,
5336 unsigned long address)
5337diff --git a/arch/sparc/include/asm/pgalloc_64.h b/arch/sparc/include/asm/pgalloc_64.h
5338index 40b2d7a..22a665b 100644
5339--- a/arch/sparc/include/asm/pgalloc_64.h
5340+++ b/arch/sparc/include/asm/pgalloc_64.h
5341@@ -26,6 +26,7 @@ static inline void pgd_free(struct mm_struct *mm, pgd_t *pgd)
5342 }
5343
5344 #define pud_populate(MM, PUD, PMD) pud_set(PUD, PMD)
5345+#define pud_populate_kernel(MM, PUD, PMD) pud_populate((MM), (PUD), (PMD))
5346
5347 static inline pmd_t *pmd_alloc_one(struct mm_struct *mm, unsigned long addr)
5348 {
5349diff --git a/arch/sparc/include/asm/pgtable_32.h b/arch/sparc/include/asm/pgtable_32.h
5350index 6fc1348..390c50a 100644
5351--- a/arch/sparc/include/asm/pgtable_32.h
5352+++ b/arch/sparc/include/asm/pgtable_32.h
5353@@ -50,6 +50,9 @@ extern unsigned long calc_highpages(void);
5354 #define PAGE_SHARED SRMMU_PAGE_SHARED
5355 #define PAGE_COPY SRMMU_PAGE_COPY
5356 #define PAGE_READONLY SRMMU_PAGE_RDONLY
5357+#define PAGE_SHARED_NOEXEC SRMMU_PAGE_SHARED_NOEXEC
5358+#define PAGE_COPY_NOEXEC SRMMU_PAGE_COPY_NOEXEC
5359+#define PAGE_READONLY_NOEXEC SRMMU_PAGE_RDONLY_NOEXEC
5360 #define PAGE_KERNEL SRMMU_PAGE_KERNEL
5361
5362 /* Top-level page directory - dummy used by init-mm.
5363@@ -62,18 +65,18 @@ extern unsigned long ptr_in_current_pgd;
5364
5365 /* xwr */
5366 #define __P000 PAGE_NONE
5367-#define __P001 PAGE_READONLY
5368-#define __P010 PAGE_COPY
5369-#define __P011 PAGE_COPY
5370+#define __P001 PAGE_READONLY_NOEXEC
5371+#define __P010 PAGE_COPY_NOEXEC
5372+#define __P011 PAGE_COPY_NOEXEC
5373 #define __P100 PAGE_READONLY
5374 #define __P101 PAGE_READONLY
5375 #define __P110 PAGE_COPY
5376 #define __P111 PAGE_COPY
5377
5378 #define __S000 PAGE_NONE
5379-#define __S001 PAGE_READONLY
5380-#define __S010 PAGE_SHARED
5381-#define __S011 PAGE_SHARED
5382+#define __S001 PAGE_READONLY_NOEXEC
5383+#define __S010 PAGE_SHARED_NOEXEC
5384+#define __S011 PAGE_SHARED_NOEXEC
5385 #define __S100 PAGE_READONLY
5386 #define __S101 PAGE_READONLY
5387 #define __S110 PAGE_SHARED
5388diff --git a/arch/sparc/include/asm/pgtsrmmu.h b/arch/sparc/include/asm/pgtsrmmu.h
5389index 79da178..c2eede8 100644
5390--- a/arch/sparc/include/asm/pgtsrmmu.h
5391+++ b/arch/sparc/include/asm/pgtsrmmu.h
5392@@ -115,6 +115,11 @@
5393 SRMMU_EXEC | SRMMU_REF)
5394 #define SRMMU_PAGE_RDONLY __pgprot(SRMMU_VALID | SRMMU_CACHE | \
5395 SRMMU_EXEC | SRMMU_REF)
5396+
5397+#define SRMMU_PAGE_SHARED_NOEXEC __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_WRITE | SRMMU_REF)
5398+#define SRMMU_PAGE_COPY_NOEXEC __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_REF)
5399+#define SRMMU_PAGE_RDONLY_NOEXEC __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_REF)
5400+
5401 #define SRMMU_PAGE_KERNEL __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_PRIV | \
5402 SRMMU_DIRTY | SRMMU_REF)
5403
5404diff --git a/arch/sparc/include/asm/spinlock_64.h b/arch/sparc/include/asm/spinlock_64.h
5405index 9689176..63c18ea 100644
5406--- a/arch/sparc/include/asm/spinlock_64.h
5407+++ b/arch/sparc/include/asm/spinlock_64.h
5408@@ -92,14 +92,19 @@ static inline void arch_spin_lock_flags(arch_spinlock_t *lock, unsigned long fla
5409
5410 /* Multi-reader locks, these are much saner than the 32-bit Sparc ones... */
5411
5412-static void inline arch_read_lock(arch_rwlock_t *lock)
5413+static inline void arch_read_lock(arch_rwlock_t *lock)
5414 {
5415 unsigned long tmp1, tmp2;
5416
5417 __asm__ __volatile__ (
5418 "1: ldsw [%2], %0\n"
5419 " brlz,pn %0, 2f\n"
5420-"4: add %0, 1, %1\n"
5421+"4: addcc %0, 1, %1\n"
5422+
5423+#ifdef CONFIG_PAX_REFCOUNT
5424+" tvs %%icc, 6\n"
5425+#endif
5426+
5427 " cas [%2], %0, %1\n"
5428 " cmp %0, %1\n"
5429 " bne,pn %%icc, 1b\n"
5430@@ -112,10 +117,10 @@ static void inline arch_read_lock(arch_rwlock_t *lock)
5431 " .previous"
5432 : "=&r" (tmp1), "=&r" (tmp2)
5433 : "r" (lock)
5434- : "memory");
5435+ : "memory", "cc");
5436 }
5437
5438-static int inline arch_read_trylock(arch_rwlock_t *lock)
5439+static inline int arch_read_trylock(arch_rwlock_t *lock)
5440 {
5441 int tmp1, tmp2;
5442
5443@@ -123,7 +128,12 @@ static int inline arch_read_trylock(arch_rwlock_t *lock)
5444 "1: ldsw [%2], %0\n"
5445 " brlz,a,pn %0, 2f\n"
5446 " mov 0, %0\n"
5447-" add %0, 1, %1\n"
5448+" addcc %0, 1, %1\n"
5449+
5450+#ifdef CONFIG_PAX_REFCOUNT
5451+" tvs %%icc, 6\n"
5452+#endif
5453+
5454 " cas [%2], %0, %1\n"
5455 " cmp %0, %1\n"
5456 " bne,pn %%icc, 1b\n"
5457@@ -136,13 +146,18 @@ static int inline arch_read_trylock(arch_rwlock_t *lock)
5458 return tmp1;
5459 }
5460
5461-static void inline arch_read_unlock(arch_rwlock_t *lock)
5462+static inline void arch_read_unlock(arch_rwlock_t *lock)
5463 {
5464 unsigned long tmp1, tmp2;
5465
5466 __asm__ __volatile__(
5467 "1: lduw [%2], %0\n"
5468-" sub %0, 1, %1\n"
5469+" subcc %0, 1, %1\n"
5470+
5471+#ifdef CONFIG_PAX_REFCOUNT
5472+" tvs %%icc, 6\n"
5473+#endif
5474+
5475 " cas [%2], %0, %1\n"
5476 " cmp %0, %1\n"
5477 " bne,pn %%xcc, 1b\n"
5478@@ -152,7 +167,7 @@ static void inline arch_read_unlock(arch_rwlock_t *lock)
5479 : "memory");
5480 }
5481
5482-static void inline arch_write_lock(arch_rwlock_t *lock)
5483+static inline void arch_write_lock(arch_rwlock_t *lock)
5484 {
5485 unsigned long mask, tmp1, tmp2;
5486
5487@@ -177,7 +192,7 @@ static void inline arch_write_lock(arch_rwlock_t *lock)
5488 : "memory");
5489 }
5490
5491-static void inline arch_write_unlock(arch_rwlock_t *lock)
5492+static inline void arch_write_unlock(arch_rwlock_t *lock)
5493 {
5494 __asm__ __volatile__(
5495 " stw %%g0, [%0]"
5496@@ -186,7 +201,7 @@ static void inline arch_write_unlock(arch_rwlock_t *lock)
5497 : "memory");
5498 }
5499
5500-static int inline arch_write_trylock(arch_rwlock_t *lock)
5501+static inline int arch_write_trylock(arch_rwlock_t *lock)
5502 {
5503 unsigned long mask, tmp1, tmp2, result;
5504
5505diff --git a/arch/sparc/include/asm/thread_info_32.h b/arch/sparc/include/asm/thread_info_32.h
5506index e6cd224..3a71793 100644
5507--- a/arch/sparc/include/asm/thread_info_32.h
5508+++ b/arch/sparc/include/asm/thread_info_32.h
5509@@ -49,6 +49,8 @@ struct thread_info {
5510 unsigned long w_saved;
5511
5512 struct restart_block restart_block;
5513+
5514+ unsigned long lowest_stack;
5515 };
5516
5517 /*
5518diff --git a/arch/sparc/include/asm/thread_info_64.h b/arch/sparc/include/asm/thread_info_64.h
5519index cfa8c38..13f30d3 100644
5520--- a/arch/sparc/include/asm/thread_info_64.h
5521+++ b/arch/sparc/include/asm/thread_info_64.h
5522@@ -63,6 +63,8 @@ struct thread_info {
5523 struct pt_regs *kern_una_regs;
5524 unsigned int kern_una_insn;
5525
5526+ unsigned long lowest_stack;
5527+
5528 unsigned long fpregs[0] __attribute__ ((aligned(64)));
5529 };
5530
5531@@ -193,10 +195,11 @@ register struct thread_info *current_thread_info_reg asm("g6");
5532 #define TIF_UNALIGNED 5 /* allowed to do unaligned accesses */
5533 /* flag bit 6 is available */
5534 #define TIF_32BIT 7 /* 32-bit binary */
5535-/* flag bit 8 is available */
5536+#define TIF_GRSEC_SETXID 8 /* update credentials on syscall entry/exit */
5537 #define TIF_SECCOMP 9 /* secure computing */
5538 #define TIF_SYSCALL_AUDIT 10 /* syscall auditing active */
5539 #define TIF_SYSCALL_TRACEPOINT 11 /* syscall tracepoint instrumentation */
5540+
5541 /* NOTE: Thread flags >= 12 should be ones we have no interest
5542 * in using in assembly, else we can't use the mask as
5543 * an immediate value in instructions such as andcc.
5544@@ -215,12 +218,18 @@ register struct thread_info *current_thread_info_reg asm("g6");
5545 #define _TIF_SYSCALL_AUDIT (1<<TIF_SYSCALL_AUDIT)
5546 #define _TIF_SYSCALL_TRACEPOINT (1<<TIF_SYSCALL_TRACEPOINT)
5547 #define _TIF_POLLING_NRFLAG (1<<TIF_POLLING_NRFLAG)
5548+#define _TIF_GRSEC_SETXID (1<<TIF_GRSEC_SETXID)
5549
5550 #define _TIF_USER_WORK_MASK ((0xff << TI_FLAG_WSAVED_SHIFT) | \
5551 _TIF_DO_NOTIFY_RESUME_MASK | \
5552 _TIF_NEED_RESCHED)
5553 #define _TIF_DO_NOTIFY_RESUME_MASK (_TIF_NOTIFY_RESUME | _TIF_SIGPENDING)
5554
5555+#define _TIF_WORK_SYSCALL \
5556+ (_TIF_SYSCALL_TRACE | _TIF_SECCOMP | _TIF_SYSCALL_AUDIT | \
5557+ _TIF_SYSCALL_TRACEPOINT | _TIF_GRSEC_SETXID)
5558+
5559+
5560 /*
5561 * Thread-synchronous status.
5562 *
5563diff --git a/arch/sparc/include/asm/uaccess.h b/arch/sparc/include/asm/uaccess.h
5564index 0167d26..9acd8ed 100644
5565--- a/arch/sparc/include/asm/uaccess.h
5566+++ b/arch/sparc/include/asm/uaccess.h
5567@@ -1,5 +1,13 @@
5568 #ifndef ___ASM_SPARC_UACCESS_H
5569 #define ___ASM_SPARC_UACCESS_H
5570+
5571+#ifdef __KERNEL__
5572+#ifndef __ASSEMBLY__
5573+#include <linux/types.h>
5574+extern void check_object_size(const void *ptr, unsigned long n, bool to);
5575+#endif
5576+#endif
5577+
5578 #if defined(__sparc__) && defined(__arch64__)
5579 #include <asm/uaccess_64.h>
5580 #else
5581diff --git a/arch/sparc/include/asm/uaccess_32.h b/arch/sparc/include/asm/uaccess_32.h
5582index 53a28dd..50c38c3 100644
5583--- a/arch/sparc/include/asm/uaccess_32.h
5584+++ b/arch/sparc/include/asm/uaccess_32.h
5585@@ -250,27 +250,46 @@ extern unsigned long __copy_user(void __user *to, const void __user *from, unsig
5586
5587 static inline unsigned long copy_to_user(void __user *to, const void *from, unsigned long n)
5588 {
5589- if (n && __access_ok((unsigned long) to, n))
5590+ if ((long)n < 0)
5591+ return n;
5592+
5593+ if (n && __access_ok((unsigned long) to, n)) {
5594+ if (!__builtin_constant_p(n))
5595+ check_object_size(from, n, true);
5596 return __copy_user(to, (__force void __user *) from, n);
5597- else
5598+ } else
5599 return n;
5600 }
5601
5602 static inline unsigned long __copy_to_user(void __user *to, const void *from, unsigned long n)
5603 {
5604+ if ((long)n < 0)
5605+ return n;
5606+
5607+ if (!__builtin_constant_p(n))
5608+ check_object_size(from, n, true);
5609+
5610 return __copy_user(to, (__force void __user *) from, n);
5611 }
5612
5613 static inline unsigned long copy_from_user(void *to, const void __user *from, unsigned long n)
5614 {
5615- if (n && __access_ok((unsigned long) from, n))
5616+ if ((long)n < 0)
5617+ return n;
5618+
5619+ if (n && __access_ok((unsigned long) from, n)) {
5620+ if (!__builtin_constant_p(n))
5621+ check_object_size(to, n, false);
5622 return __copy_user((__force void __user *) to, from, n);
5623- else
5624+ } else
5625 return n;
5626 }
5627
5628 static inline unsigned long __copy_from_user(void *to, const void __user *from, unsigned long n)
5629 {
5630+ if ((long)n < 0)
5631+ return n;
5632+
5633 return __copy_user((__force void __user *) to, from, n);
5634 }
5635
5636diff --git a/arch/sparc/include/asm/uaccess_64.h b/arch/sparc/include/asm/uaccess_64.h
5637index 7c831d8..d440ca7 100644
5638--- a/arch/sparc/include/asm/uaccess_64.h
5639+++ b/arch/sparc/include/asm/uaccess_64.h
5640@@ -10,6 +10,7 @@
5641 #include <linux/compiler.h>
5642 #include <linux/string.h>
5643 #include <linux/thread_info.h>
5644+#include <linux/kernel.h>
5645 #include <asm/asi.h>
5646 #include <asm/spitfire.h>
5647 #include <asm-generic/uaccess-unaligned.h>
5648@@ -214,8 +215,15 @@ extern unsigned long copy_from_user_fixup(void *to, const void __user *from,
5649 static inline unsigned long __must_check
5650 copy_from_user(void *to, const void __user *from, unsigned long size)
5651 {
5652- unsigned long ret = ___copy_from_user(to, from, size);
5653+ unsigned long ret;
5654
5655+ if ((long)size < 0 || size > INT_MAX)
5656+ return size;
5657+
5658+ if (!__builtin_constant_p(size))
5659+ check_object_size(to, size, false);
5660+
5661+ ret = ___copy_from_user(to, from, size);
5662 if (unlikely(ret))
5663 ret = copy_from_user_fixup(to, from, size);
5664
5665@@ -231,8 +239,15 @@ extern unsigned long copy_to_user_fixup(void __user *to, const void *from,
5666 static inline unsigned long __must_check
5667 copy_to_user(void __user *to, const void *from, unsigned long size)
5668 {
5669- unsigned long ret = ___copy_to_user(to, from, size);
5670+ unsigned long ret;
5671
5672+ if ((long)size < 0 || size > INT_MAX)
5673+ return size;
5674+
5675+ if (!__builtin_constant_p(size))
5676+ check_object_size(from, size, true);
5677+
5678+ ret = ___copy_to_user(to, from, size);
5679 if (unlikely(ret))
5680 ret = copy_to_user_fixup(to, from, size);
5681 return ret;
5682diff --git a/arch/sparc/kernel/Makefile b/arch/sparc/kernel/Makefile
5683index 6cf591b..b49e65a 100644
5684--- a/arch/sparc/kernel/Makefile
5685+++ b/arch/sparc/kernel/Makefile
5686@@ -3,7 +3,7 @@
5687 #
5688
5689 asflags-y := -ansi
5690-ccflags-y := -Werror
5691+#ccflags-y := -Werror
5692
5693 extra-y := head_$(BITS).o
5694
5695diff --git a/arch/sparc/kernel/leon_kernel.c b/arch/sparc/kernel/leon_kernel.c
5696index f8b6eee..87f60ee 100644
5697--- a/arch/sparc/kernel/leon_kernel.c
5698+++ b/arch/sparc/kernel/leon_kernel.c
5699@@ -56,11 +56,13 @@ static inline unsigned int leon_eirq_get(int cpu)
5700 static void leon_handle_ext_irq(unsigned int irq, struct irq_desc *desc)
5701 {
5702 unsigned int eirq;
5703+ struct irq_bucket *p;
5704 int cpu = sparc_leon3_cpuid();
5705
5706 eirq = leon_eirq_get(cpu);
5707- if ((eirq & 0x10) && irq_map[eirq]->irq) /* bit4 tells if IRQ happened */
5708- generic_handle_irq(irq_map[eirq]->irq);
5709+ p = irq_map[eirq];
5710+ if ((eirq & 0x10) && p && p->irq) /* bit4 tells if IRQ happened */
5711+ generic_handle_irq(p->irq);
5712 }
5713
5714 /* The extended IRQ controller has been found, this function registers it */
5715diff --git a/arch/sparc/kernel/process_32.c b/arch/sparc/kernel/process_32.c
5716index 14006d8..8146238 100644
5717--- a/arch/sparc/kernel/process_32.c
5718+++ b/arch/sparc/kernel/process_32.c
5719@@ -126,14 +126,14 @@ void show_regs(struct pt_regs *r)
5720
5721 printk("PSR: %08lx PC: %08lx NPC: %08lx Y: %08lx %s\n",
5722 r->psr, r->pc, r->npc, r->y, print_tainted());
5723- printk("PC: <%pS>\n", (void *) r->pc);
5724+ printk("PC: <%pA>\n", (void *) r->pc);
5725 printk("%%G: %08lx %08lx %08lx %08lx %08lx %08lx %08lx %08lx\n",
5726 r->u_regs[0], r->u_regs[1], r->u_regs[2], r->u_regs[3],
5727 r->u_regs[4], r->u_regs[5], r->u_regs[6], r->u_regs[7]);
5728 printk("%%O: %08lx %08lx %08lx %08lx %08lx %08lx %08lx %08lx\n",
5729 r->u_regs[8], r->u_regs[9], r->u_regs[10], r->u_regs[11],
5730 r->u_regs[12], r->u_regs[13], r->u_regs[14], r->u_regs[15]);
5731- printk("RPC: <%pS>\n", (void *) r->u_regs[15]);
5732+ printk("RPC: <%pA>\n", (void *) r->u_regs[15]);
5733
5734 printk("%%L: %08lx %08lx %08lx %08lx %08lx %08lx %08lx %08lx\n",
5735 rw->locals[0], rw->locals[1], rw->locals[2], rw->locals[3],
5736@@ -168,7 +168,7 @@ void show_stack(struct task_struct *tsk, unsigned long *_ksp)
5737 rw = (struct reg_window32 *) fp;
5738 pc = rw->ins[7];
5739 printk("[%08lx : ", pc);
5740- printk("%pS ] ", (void *) pc);
5741+ printk("%pA ] ", (void *) pc);
5742 fp = rw->ins[6];
5743 } while (++count < 16);
5744 printk("\n");
5745diff --git a/arch/sparc/kernel/process_64.c b/arch/sparc/kernel/process_64.c
5746index aff0c72..9067b39 100644
5747--- a/arch/sparc/kernel/process_64.c
5748+++ b/arch/sparc/kernel/process_64.c
5749@@ -179,14 +179,14 @@ static void show_regwindow(struct pt_regs *regs)
5750 printk("i4: %016lx i5: %016lx i6: %016lx i7: %016lx\n",
5751 rwk->ins[4], rwk->ins[5], rwk->ins[6], rwk->ins[7]);
5752 if (regs->tstate & TSTATE_PRIV)
5753- printk("I7: <%pS>\n", (void *) rwk->ins[7]);
5754+ printk("I7: <%pA>\n", (void *) rwk->ins[7]);
5755 }
5756
5757 void show_regs(struct pt_regs *regs)
5758 {
5759 printk("TSTATE: %016lx TPC: %016lx TNPC: %016lx Y: %08x %s\n", regs->tstate,
5760 regs->tpc, regs->tnpc, regs->y, print_tainted());
5761- printk("TPC: <%pS>\n", (void *) regs->tpc);
5762+ printk("TPC: <%pA>\n", (void *) regs->tpc);
5763 printk("g0: %016lx g1: %016lx g2: %016lx g3: %016lx\n",
5764 regs->u_regs[0], regs->u_regs[1], regs->u_regs[2],
5765 regs->u_regs[3]);
5766@@ -199,7 +199,7 @@ void show_regs(struct pt_regs *regs)
5767 printk("o4: %016lx o5: %016lx sp: %016lx ret_pc: %016lx\n",
5768 regs->u_regs[12], regs->u_regs[13], regs->u_regs[14],
5769 regs->u_regs[15]);
5770- printk("RPC: <%pS>\n", (void *) regs->u_regs[15]);
5771+ printk("RPC: <%pA>\n", (void *) regs->u_regs[15]);
5772 show_regwindow(regs);
5773 show_stack(current, (unsigned long *) regs->u_regs[UREG_FP]);
5774 }
5775@@ -284,7 +284,7 @@ void arch_trigger_all_cpu_backtrace(void)
5776 ((tp && tp->task) ? tp->task->pid : -1));
5777
5778 if (gp->tstate & TSTATE_PRIV) {
5779- printk(" TPC[%pS] O7[%pS] I7[%pS] RPC[%pS]\n",
5780+ printk(" TPC[%pA] O7[%pA] I7[%pA] RPC[%pA]\n",
5781 (void *) gp->tpc,
5782 (void *) gp->o7,
5783 (void *) gp->i7,
5784diff --git a/arch/sparc/kernel/ptrace_64.c b/arch/sparc/kernel/ptrace_64.c
5785index 484daba..0674139 100644
5786--- a/arch/sparc/kernel/ptrace_64.c
5787+++ b/arch/sparc/kernel/ptrace_64.c
5788@@ -1057,6 +1057,10 @@ long arch_ptrace(struct task_struct *child, long request,
5789 return ret;
5790 }
5791
5792+#ifdef CONFIG_GRKERNSEC_SETXID
5793+extern void gr_delayed_cred_worker(void);
5794+#endif
5795+
5796 asmlinkage int syscall_trace_enter(struct pt_regs *regs)
5797 {
5798 int ret = 0;
5799@@ -1064,6 +1068,11 @@ asmlinkage int syscall_trace_enter(struct pt_regs *regs)
5800 /* do the secure computing check first */
5801 secure_computing_strict(regs->u_regs[UREG_G1]);
5802
5803+#ifdef CONFIG_GRKERNSEC_SETXID
5804+ if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
5805+ gr_delayed_cred_worker();
5806+#endif
5807+
5808 if (test_thread_flag(TIF_SYSCALL_TRACE))
5809 ret = tracehook_report_syscall_entry(regs);
5810
5811@@ -1084,6 +1093,11 @@ asmlinkage int syscall_trace_enter(struct pt_regs *regs)
5812
5813 asmlinkage void syscall_trace_leave(struct pt_regs *regs)
5814 {
5815+#ifdef CONFIG_GRKERNSEC_SETXID
5816+ if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
5817+ gr_delayed_cred_worker();
5818+#endif
5819+
5820 audit_syscall_exit(regs);
5821
5822 if (unlikely(test_thread_flag(TIF_SYSCALL_TRACEPOINT)))
5823diff --git a/arch/sparc/kernel/sys_sparc_32.c b/arch/sparc/kernel/sys_sparc_32.c
5824index 0c9b31b..7cb7aee 100644
5825--- a/arch/sparc/kernel/sys_sparc_32.c
5826+++ b/arch/sparc/kernel/sys_sparc_32.c
5827@@ -54,7 +54,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
5828 if (len > TASK_SIZE - PAGE_SIZE)
5829 return -ENOMEM;
5830 if (!addr)
5831- addr = TASK_UNMAPPED_BASE;
5832+ addr = current->mm->mmap_base;
5833
5834 if (flags & MAP_SHARED)
5835 addr = COLOUR_ALIGN(addr);
5836@@ -65,7 +65,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
5837 /* At this point: (!vmm || addr < vmm->vm_end). */
5838 if (TASK_SIZE - PAGE_SIZE - len < addr)
5839 return -ENOMEM;
5840- if (!vmm || addr + len <= vmm->vm_start)
5841+ if (check_heap_stack_gap(vmm, addr, len))
5842 return addr;
5843 addr = vmm->vm_end;
5844 if (flags & MAP_SHARED)
5845diff --git a/arch/sparc/kernel/sys_sparc_64.c b/arch/sparc/kernel/sys_sparc_64.c
5846index 11c6c96..3ec33e8 100644
5847--- a/arch/sparc/kernel/sys_sparc_64.c
5848+++ b/arch/sparc/kernel/sys_sparc_64.c
5849@@ -107,7 +107,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
5850 /* We do not accept a shared mapping if it would violate
5851 * cache aliasing constraints.
5852 */
5853- if ((flags & MAP_SHARED) &&
5854+ if ((filp || (flags & MAP_SHARED)) &&
5855 ((addr - (pgoff << PAGE_SHIFT)) & (SHMLBA - 1)))
5856 return -EINVAL;
5857 return addr;
5858@@ -122,6 +122,10 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
5859 if (filp || (flags & MAP_SHARED))
5860 do_color_align = 1;
5861
5862+#ifdef CONFIG_PAX_RANDMMAP
5863+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
5864+#endif
5865+
5866 if (addr) {
5867 if (do_color_align)
5868 addr = COLOUR_ALIGN(addr, pgoff);
5869@@ -129,15 +133,14 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
5870 addr = PAGE_ALIGN(addr);
5871
5872 vma = find_vma(mm, addr);
5873- if (task_size - len >= addr &&
5874- (!vma || addr + len <= vma->vm_start))
5875+ if (task_size - len >= addr && check_heap_stack_gap(vma, addr, len))
5876 return addr;
5877 }
5878
5879 if (len > mm->cached_hole_size) {
5880- start_addr = addr = mm->free_area_cache;
5881+ start_addr = addr = mm->free_area_cache;
5882 } else {
5883- start_addr = addr = TASK_UNMAPPED_BASE;
5884+ start_addr = addr = mm->mmap_base;
5885 mm->cached_hole_size = 0;
5886 }
5887
5888@@ -157,14 +160,14 @@ full_search:
5889 vma = find_vma(mm, VA_EXCLUDE_END);
5890 }
5891 if (unlikely(task_size < addr)) {
5892- if (start_addr != TASK_UNMAPPED_BASE) {
5893- start_addr = addr = TASK_UNMAPPED_BASE;
5894+ if (start_addr != mm->mmap_base) {
5895+ start_addr = addr = mm->mmap_base;
5896 mm->cached_hole_size = 0;
5897 goto full_search;
5898 }
5899 return -ENOMEM;
5900 }
5901- if (likely(!vma || addr + len <= vma->vm_start)) {
5902+ if (likely(check_heap_stack_gap(vma, addr, len))) {
5903 /*
5904 * Remember the place where we stopped the search:
5905 */
5906@@ -198,7 +201,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
5907 /* We do not accept a shared mapping if it would violate
5908 * cache aliasing constraints.
5909 */
5910- if ((flags & MAP_SHARED) &&
5911+ if ((filp || (flags & MAP_SHARED)) &&
5912 ((addr - (pgoff << PAGE_SHIFT)) & (SHMLBA - 1)))
5913 return -EINVAL;
5914 return addr;
5915@@ -219,8 +222,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
5916 addr = PAGE_ALIGN(addr);
5917
5918 vma = find_vma(mm, addr);
5919- if (task_size - len >= addr &&
5920- (!vma || addr + len <= vma->vm_start))
5921+ if (task_size - len >= addr && check_heap_stack_gap(vma, addr, len))
5922 return addr;
5923 }
5924
5925@@ -241,7 +243,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
5926 /* make sure it can fit in the remaining address space */
5927 if (likely(addr > len)) {
5928 vma = find_vma(mm, addr-len);
5929- if (!vma || addr <= vma->vm_start) {
5930+ if (check_heap_stack_gap(vma, addr - len, len)) {
5931 /* remember the address as a hint for next time */
5932 return (mm->free_area_cache = addr-len);
5933 }
5934@@ -250,18 +252,18 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
5935 if (unlikely(mm->mmap_base < len))
5936 goto bottomup;
5937
5938- addr = mm->mmap_base-len;
5939- if (do_color_align)
5940- addr = COLOUR_ALIGN_DOWN(addr, pgoff);
5941+ addr = mm->mmap_base - len;
5942
5943 do {
5944+ if (do_color_align)
5945+ addr = COLOUR_ALIGN_DOWN(addr, pgoff);
5946 /*
5947 * Lookup failure means no vma is above this address,
5948 * else if new region fits below vma->vm_start,
5949 * return with success:
5950 */
5951 vma = find_vma(mm, addr);
5952- if (likely(!vma || addr+len <= vma->vm_start)) {
5953+ if (likely(check_heap_stack_gap(vma, addr, len))) {
5954 /* remember the address as a hint for next time */
5955 return (mm->free_area_cache = addr);
5956 }
5957@@ -271,10 +273,8 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
5958 mm->cached_hole_size = vma->vm_start - addr;
5959
5960 /* try just below the current vma->vm_start */
5961- addr = vma->vm_start-len;
5962- if (do_color_align)
5963- addr = COLOUR_ALIGN_DOWN(addr, pgoff);
5964- } while (likely(len < vma->vm_start));
5965+ addr = skip_heap_stack_gap(vma, len);
5966+ } while (!IS_ERR_VALUE(addr));
5967
5968 bottomup:
5969 /*
5970@@ -373,6 +373,12 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
5971 gap == RLIM_INFINITY ||
5972 sysctl_legacy_va_layout) {
5973 mm->mmap_base = TASK_UNMAPPED_BASE + random_factor;
5974+
5975+#ifdef CONFIG_PAX_RANDMMAP
5976+ if (mm->pax_flags & MF_PAX_RANDMMAP)
5977+ mm->mmap_base += mm->delta_mmap;
5978+#endif
5979+
5980 mm->get_unmapped_area = arch_get_unmapped_area;
5981 mm->unmap_area = arch_unmap_area;
5982 } else {
5983@@ -385,6 +391,12 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
5984 gap = (task_size / 6 * 5);
5985
5986 mm->mmap_base = PAGE_ALIGN(task_size - gap - random_factor);
5987+
5988+#ifdef CONFIG_PAX_RANDMMAP
5989+ if (mm->pax_flags & MF_PAX_RANDMMAP)
5990+ mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
5991+#endif
5992+
5993 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
5994 mm->unmap_area = arch_unmap_area_topdown;
5995 }
5996diff --git a/arch/sparc/kernel/syscalls.S b/arch/sparc/kernel/syscalls.S
5997index 7f5f65d..3308382 100644
5998--- a/arch/sparc/kernel/syscalls.S
5999+++ b/arch/sparc/kernel/syscalls.S
6000@@ -62,7 +62,7 @@ sys32_rt_sigreturn:
6001 #endif
6002 .align 32
6003 1: ldx [%g6 + TI_FLAGS], %l5
6004- andcc %l5, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT|_TIF_SYSCALL_TRACEPOINT), %g0
6005+ andcc %l5, _TIF_WORK_SYSCALL, %g0
6006 be,pt %icc, rtrap
6007 nop
6008 call syscall_trace_leave
6009@@ -179,7 +179,7 @@ linux_sparc_syscall32:
6010
6011 srl %i5, 0, %o5 ! IEU1
6012 srl %i2, 0, %o2 ! IEU0 Group
6013- andcc %l0, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT|_TIF_SYSCALL_TRACEPOINT), %g0
6014+ andcc %l0, _TIF_WORK_SYSCALL, %g0
6015 bne,pn %icc, linux_syscall_trace32 ! CTI
6016 mov %i0, %l5 ! IEU1
6017 call %l7 ! CTI Group brk forced
6018@@ -202,7 +202,7 @@ linux_sparc_syscall:
6019
6020 mov %i3, %o3 ! IEU1
6021 mov %i4, %o4 ! IEU0 Group
6022- andcc %l0, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT|_TIF_SYSCALL_TRACEPOINT), %g0
6023+ andcc %l0, _TIF_WORK_SYSCALL, %g0
6024 bne,pn %icc, linux_syscall_trace ! CTI Group
6025 mov %i0, %l5 ! IEU0
6026 2: call %l7 ! CTI Group brk forced
6027@@ -218,7 +218,7 @@ ret_sys_call:
6028
6029 cmp %o0, -ERESTART_RESTARTBLOCK
6030 bgeu,pn %xcc, 1f
6031- andcc %l0, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT|_TIF_SYSCALL_TRACEPOINT), %g0
6032+ andcc %l0, _TIF_WORK_SYSCALL, %g0
6033 ldx [%sp + PTREGS_OFF + PT_V9_TNPC], %l1 ! pc = npc
6034
6035 2:
6036diff --git a/arch/sparc/kernel/traps_32.c b/arch/sparc/kernel/traps_32.c
6037index a5785ea..405c5f7 100644
6038--- a/arch/sparc/kernel/traps_32.c
6039+++ b/arch/sparc/kernel/traps_32.c
6040@@ -44,6 +44,8 @@ static void instruction_dump(unsigned long *pc)
6041 #define __SAVE __asm__ __volatile__("save %sp, -0x40, %sp\n\t")
6042 #define __RESTORE __asm__ __volatile__("restore %g0, %g0, %g0\n\t")
6043
6044+extern void gr_handle_kernel_exploit(void);
6045+
6046 void die_if_kernel(char *str, struct pt_regs *regs)
6047 {
6048 static int die_counter;
6049@@ -76,15 +78,17 @@ void die_if_kernel(char *str, struct pt_regs *regs)
6050 count++ < 30 &&
6051 (((unsigned long) rw) >= PAGE_OFFSET) &&
6052 !(((unsigned long) rw) & 0x7)) {
6053- printk("Caller[%08lx]: %pS\n", rw->ins[7],
6054+ printk("Caller[%08lx]: %pA\n", rw->ins[7],
6055 (void *) rw->ins[7]);
6056 rw = (struct reg_window32 *)rw->ins[6];
6057 }
6058 }
6059 printk("Instruction DUMP:");
6060 instruction_dump ((unsigned long *) regs->pc);
6061- if(regs->psr & PSR_PS)
6062+ if(regs->psr & PSR_PS) {
6063+ gr_handle_kernel_exploit();
6064 do_exit(SIGKILL);
6065+ }
6066 do_exit(SIGSEGV);
6067 }
6068
6069diff --git a/arch/sparc/kernel/traps_64.c b/arch/sparc/kernel/traps_64.c
6070index 3b05e66..6ea2917 100644
6071--- a/arch/sparc/kernel/traps_64.c
6072+++ b/arch/sparc/kernel/traps_64.c
6073@@ -75,7 +75,7 @@ static void dump_tl1_traplog(struct tl1_traplog *p)
6074 i + 1,
6075 p->trapstack[i].tstate, p->trapstack[i].tpc,
6076 p->trapstack[i].tnpc, p->trapstack[i].tt);
6077- printk("TRAPLOG: TPC<%pS>\n", (void *) p->trapstack[i].tpc);
6078+ printk("TRAPLOG: TPC<%pA>\n", (void *) p->trapstack[i].tpc);
6079 }
6080 }
6081
6082@@ -95,6 +95,12 @@ void bad_trap(struct pt_regs *regs, long lvl)
6083
6084 lvl -= 0x100;
6085 if (regs->tstate & TSTATE_PRIV) {
6086+
6087+#ifdef CONFIG_PAX_REFCOUNT
6088+ if (lvl == 6)
6089+ pax_report_refcount_overflow(regs);
6090+#endif
6091+
6092 sprintf(buffer, "Kernel bad sw trap %lx", lvl);
6093 die_if_kernel(buffer, regs);
6094 }
6095@@ -113,11 +119,16 @@ void bad_trap(struct pt_regs *regs, long lvl)
6096 void bad_trap_tl1(struct pt_regs *regs, long lvl)
6097 {
6098 char buffer[32];
6099-
6100+
6101 if (notify_die(DIE_TRAP_TL1, "bad trap tl1", regs,
6102 0, lvl, SIGTRAP) == NOTIFY_STOP)
6103 return;
6104
6105+#ifdef CONFIG_PAX_REFCOUNT
6106+ if (lvl == 6)
6107+ pax_report_refcount_overflow(regs);
6108+#endif
6109+
6110 dump_tl1_traplog((struct tl1_traplog *)(regs + 1));
6111
6112 sprintf (buffer, "Bad trap %lx at tl>0", lvl);
6113@@ -1141,7 +1152,7 @@ static void cheetah_log_errors(struct pt_regs *regs, struct cheetah_err_info *in
6114 regs->tpc, regs->tnpc, regs->u_regs[UREG_I7], regs->tstate);
6115 printk("%s" "ERROR(%d): ",
6116 (recoverable ? KERN_WARNING : KERN_CRIT), smp_processor_id());
6117- printk("TPC<%pS>\n", (void *) regs->tpc);
6118+ printk("TPC<%pA>\n", (void *) regs->tpc);
6119 printk("%s" "ERROR(%d): M_SYND(%lx), E_SYND(%lx)%s%s\n",
6120 (recoverable ? KERN_WARNING : KERN_CRIT), smp_processor_id(),
6121 (afsr & CHAFSR_M_SYNDROME) >> CHAFSR_M_SYNDROME_SHIFT,
6122@@ -1748,7 +1759,7 @@ void cheetah_plus_parity_error(int type, struct pt_regs *regs)
6123 smp_processor_id(),
6124 (type & 0x1) ? 'I' : 'D',
6125 regs->tpc);
6126- printk(KERN_EMERG "TPC<%pS>\n", (void *) regs->tpc);
6127+ printk(KERN_EMERG "TPC<%pA>\n", (void *) regs->tpc);
6128 panic("Irrecoverable Cheetah+ parity error.");
6129 }
6130
6131@@ -1756,7 +1767,7 @@ void cheetah_plus_parity_error(int type, struct pt_regs *regs)
6132 smp_processor_id(),
6133 (type & 0x1) ? 'I' : 'D',
6134 regs->tpc);
6135- printk(KERN_WARNING "TPC<%pS>\n", (void *) regs->tpc);
6136+ printk(KERN_WARNING "TPC<%pA>\n", (void *) regs->tpc);
6137 }
6138
6139 struct sun4v_error_entry {
6140@@ -1963,9 +1974,9 @@ void sun4v_itlb_error_report(struct pt_regs *regs, int tl)
6141
6142 printk(KERN_EMERG "SUN4V-ITLB: Error at TPC[%lx], tl %d\n",
6143 regs->tpc, tl);
6144- printk(KERN_EMERG "SUN4V-ITLB: TPC<%pS>\n", (void *) regs->tpc);
6145+ printk(KERN_EMERG "SUN4V-ITLB: TPC<%pA>\n", (void *) regs->tpc);
6146 printk(KERN_EMERG "SUN4V-ITLB: O7[%lx]\n", regs->u_regs[UREG_I7]);
6147- printk(KERN_EMERG "SUN4V-ITLB: O7<%pS>\n",
6148+ printk(KERN_EMERG "SUN4V-ITLB: O7<%pA>\n",
6149 (void *) regs->u_regs[UREG_I7]);
6150 printk(KERN_EMERG "SUN4V-ITLB: vaddr[%lx] ctx[%lx] "
6151 "pte[%lx] error[%lx]\n",
6152@@ -1987,9 +1998,9 @@ void sun4v_dtlb_error_report(struct pt_regs *regs, int tl)
6153
6154 printk(KERN_EMERG "SUN4V-DTLB: Error at TPC[%lx], tl %d\n",
6155 regs->tpc, tl);
6156- printk(KERN_EMERG "SUN4V-DTLB: TPC<%pS>\n", (void *) regs->tpc);
6157+ printk(KERN_EMERG "SUN4V-DTLB: TPC<%pA>\n", (void *) regs->tpc);
6158 printk(KERN_EMERG "SUN4V-DTLB: O7[%lx]\n", regs->u_regs[UREG_I7]);
6159- printk(KERN_EMERG "SUN4V-DTLB: O7<%pS>\n",
6160+ printk(KERN_EMERG "SUN4V-DTLB: O7<%pA>\n",
6161 (void *) regs->u_regs[UREG_I7]);
6162 printk(KERN_EMERG "SUN4V-DTLB: vaddr[%lx] ctx[%lx] "
6163 "pte[%lx] error[%lx]\n",
6164@@ -2195,13 +2206,13 @@ void show_stack(struct task_struct *tsk, unsigned long *_ksp)
6165 fp = (unsigned long)sf->fp + STACK_BIAS;
6166 }
6167
6168- printk(" [%016lx] %pS\n", pc, (void *) pc);
6169+ printk(" [%016lx] %pA\n", pc, (void *) pc);
6170 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
6171 if ((pc + 8UL) == (unsigned long) &return_to_handler) {
6172 int index = tsk->curr_ret_stack;
6173 if (tsk->ret_stack && index >= graph) {
6174 pc = tsk->ret_stack[index - graph].ret;
6175- printk(" [%016lx] %pS\n", pc, (void *) pc);
6176+ printk(" [%016lx] %pA\n", pc, (void *) pc);
6177 graph++;
6178 }
6179 }
6180@@ -2226,6 +2237,8 @@ static inline struct reg_window *kernel_stack_up(struct reg_window *rw)
6181 return (struct reg_window *) (fp + STACK_BIAS);
6182 }
6183
6184+extern void gr_handle_kernel_exploit(void);
6185+
6186 void die_if_kernel(char *str, struct pt_regs *regs)
6187 {
6188 static int die_counter;
6189@@ -2254,7 +2267,7 @@ void die_if_kernel(char *str, struct pt_regs *regs)
6190 while (rw &&
6191 count++ < 30 &&
6192 kstack_valid(tp, (unsigned long) rw)) {
6193- printk("Caller[%016lx]: %pS\n", rw->ins[7],
6194+ printk("Caller[%016lx]: %pA\n", rw->ins[7],
6195 (void *) rw->ins[7]);
6196
6197 rw = kernel_stack_up(rw);
6198@@ -2267,8 +2280,10 @@ void die_if_kernel(char *str, struct pt_regs *regs)
6199 }
6200 user_instruction_dump ((unsigned int __user *) regs->tpc);
6201 }
6202- if (regs->tstate & TSTATE_PRIV)
6203+ if (regs->tstate & TSTATE_PRIV) {
6204+ gr_handle_kernel_exploit();
6205 do_exit(SIGKILL);
6206+ }
6207 do_exit(SIGSEGV);
6208 }
6209 EXPORT_SYMBOL(die_if_kernel);
6210diff --git a/arch/sparc/kernel/unaligned_64.c b/arch/sparc/kernel/unaligned_64.c
6211index f81d038..e7a4680 100644
6212--- a/arch/sparc/kernel/unaligned_64.c
6213+++ b/arch/sparc/kernel/unaligned_64.c
6214@@ -278,7 +278,7 @@ static void log_unaligned(struct pt_regs *regs)
6215 static DEFINE_RATELIMIT_STATE(ratelimit, 5 * HZ, 5);
6216
6217 if (__ratelimit(&ratelimit)) {
6218- printk("Kernel unaligned access at TPC[%lx] %pS\n",
6219+ printk("Kernel unaligned access at TPC[%lx] %pA\n",
6220 regs->tpc, (void *) regs->tpc);
6221 }
6222 }
6223diff --git a/arch/sparc/lib/Makefile b/arch/sparc/lib/Makefile
6224index dff4096..bd9a388 100644
6225--- a/arch/sparc/lib/Makefile
6226+++ b/arch/sparc/lib/Makefile
6227@@ -2,7 +2,7 @@
6228 #
6229
6230 asflags-y := -ansi -DST_DIV0=0x02
6231-ccflags-y := -Werror
6232+#ccflags-y := -Werror
6233
6234 lib-$(CONFIG_SPARC32) += ashrdi3.o
6235 lib-$(CONFIG_SPARC32) += memcpy.o memset.o
6236diff --git a/arch/sparc/lib/atomic_64.S b/arch/sparc/lib/atomic_64.S
6237index 4d502da..527c48d 100644
6238--- a/arch/sparc/lib/atomic_64.S
6239+++ b/arch/sparc/lib/atomic_64.S
6240@@ -17,7 +17,12 @@
6241 ENTRY(atomic_add) /* %o0 = increment, %o1 = atomic_ptr */
6242 BACKOFF_SETUP(%o2)
6243 1: lduw [%o1], %g1
6244- add %g1, %o0, %g7
6245+ addcc %g1, %o0, %g7
6246+
6247+#ifdef CONFIG_PAX_REFCOUNT
6248+ tvs %icc, 6
6249+#endif
6250+
6251 cas [%o1], %g1, %g7
6252 cmp %g1, %g7
6253 bne,pn %icc, BACKOFF_LABEL(2f, 1b)
6254@@ -27,10 +32,28 @@ ENTRY(atomic_add) /* %o0 = increment, %o1 = atomic_ptr */
6255 2: BACKOFF_SPIN(%o2, %o3, 1b)
6256 ENDPROC(atomic_add)
6257
6258+ENTRY(atomic_add_unchecked) /* %o0 = increment, %o1 = atomic_ptr */
6259+ BACKOFF_SETUP(%o2)
6260+1: lduw [%o1], %g1
6261+ add %g1, %o0, %g7
6262+ cas [%o1], %g1, %g7
6263+ cmp %g1, %g7
6264+ bne,pn %icc, 2f
6265+ nop
6266+ retl
6267+ nop
6268+2: BACKOFF_SPIN(%o2, %o3, 1b)
6269+ENDPROC(atomic_add_unchecked)
6270+
6271 ENTRY(atomic_sub) /* %o0 = decrement, %o1 = atomic_ptr */
6272 BACKOFF_SETUP(%o2)
6273 1: lduw [%o1], %g1
6274- sub %g1, %o0, %g7
6275+ subcc %g1, %o0, %g7
6276+
6277+#ifdef CONFIG_PAX_REFCOUNT
6278+ tvs %icc, 6
6279+#endif
6280+
6281 cas [%o1], %g1, %g7
6282 cmp %g1, %g7
6283 bne,pn %icc, BACKOFF_LABEL(2f, 1b)
6284@@ -40,10 +63,28 @@ ENTRY(atomic_sub) /* %o0 = decrement, %o1 = atomic_ptr */
6285 2: BACKOFF_SPIN(%o2, %o3, 1b)
6286 ENDPROC(atomic_sub)
6287
6288+ENTRY(atomic_sub_unchecked) /* %o0 = decrement, %o1 = atomic_ptr */
6289+ BACKOFF_SETUP(%o2)
6290+1: lduw [%o1], %g1
6291+ sub %g1, %o0, %g7
6292+ cas [%o1], %g1, %g7
6293+ cmp %g1, %g7
6294+ bne,pn %icc, 2f
6295+ nop
6296+ retl
6297+ nop
6298+2: BACKOFF_SPIN(%o2, %o3, 1b)
6299+ENDPROC(atomic_sub_unchecked)
6300+
6301 ENTRY(atomic_add_ret) /* %o0 = increment, %o1 = atomic_ptr */
6302 BACKOFF_SETUP(%o2)
6303 1: lduw [%o1], %g1
6304- add %g1, %o0, %g7
6305+ addcc %g1, %o0, %g7
6306+
6307+#ifdef CONFIG_PAX_REFCOUNT
6308+ tvs %icc, 6
6309+#endif
6310+
6311 cas [%o1], %g1, %g7
6312 cmp %g1, %g7
6313 bne,pn %icc, BACKOFF_LABEL(2f, 1b)
6314@@ -53,10 +94,29 @@ ENTRY(atomic_add_ret) /* %o0 = increment, %o1 = atomic_ptr */
6315 2: BACKOFF_SPIN(%o2, %o3, 1b)
6316 ENDPROC(atomic_add_ret)
6317
6318+ENTRY(atomic_add_ret_unchecked) /* %o0 = increment, %o1 = atomic_ptr */
6319+ BACKOFF_SETUP(%o2)
6320+1: lduw [%o1], %g1
6321+ addcc %g1, %o0, %g7
6322+ cas [%o1], %g1, %g7
6323+ cmp %g1, %g7
6324+ bne,pn %icc, 2f
6325+ add %g7, %o0, %g7
6326+ sra %g7, 0, %o0
6327+ retl
6328+ nop
6329+2: BACKOFF_SPIN(%o2, %o3, 1b)
6330+ENDPROC(atomic_add_ret_unchecked)
6331+
6332 ENTRY(atomic_sub_ret) /* %o0 = decrement, %o1 = atomic_ptr */
6333 BACKOFF_SETUP(%o2)
6334 1: lduw [%o1], %g1
6335- sub %g1, %o0, %g7
6336+ subcc %g1, %o0, %g7
6337+
6338+#ifdef CONFIG_PAX_REFCOUNT
6339+ tvs %icc, 6
6340+#endif
6341+
6342 cas [%o1], %g1, %g7
6343 cmp %g1, %g7
6344 bne,pn %icc, BACKOFF_LABEL(2f, 1b)
6345@@ -69,7 +129,12 @@ ENDPROC(atomic_sub_ret)
6346 ENTRY(atomic64_add) /* %o0 = increment, %o1 = atomic_ptr */
6347 BACKOFF_SETUP(%o2)
6348 1: ldx [%o1], %g1
6349- add %g1, %o0, %g7
6350+ addcc %g1, %o0, %g7
6351+
6352+#ifdef CONFIG_PAX_REFCOUNT
6353+ tvs %xcc, 6
6354+#endif
6355+
6356 casx [%o1], %g1, %g7
6357 cmp %g1, %g7
6358 bne,pn %xcc, BACKOFF_LABEL(2f, 1b)
6359@@ -79,10 +144,28 @@ ENTRY(atomic64_add) /* %o0 = increment, %o1 = atomic_ptr */
6360 2: BACKOFF_SPIN(%o2, %o3, 1b)
6361 ENDPROC(atomic64_add)
6362
6363+ENTRY(atomic64_add_unchecked) /* %o0 = increment, %o1 = atomic_ptr */
6364+ BACKOFF_SETUP(%o2)
6365+1: ldx [%o1], %g1
6366+ addcc %g1, %o0, %g7
6367+ casx [%o1], %g1, %g7
6368+ cmp %g1, %g7
6369+ bne,pn %xcc, 2f
6370+ nop
6371+ retl
6372+ nop
6373+2: BACKOFF_SPIN(%o2, %o3, 1b)
6374+ENDPROC(atomic64_add_unchecked)
6375+
6376 ENTRY(atomic64_sub) /* %o0 = decrement, %o1 = atomic_ptr */
6377 BACKOFF_SETUP(%o2)
6378 1: ldx [%o1], %g1
6379- sub %g1, %o0, %g7
6380+ subcc %g1, %o0, %g7
6381+
6382+#ifdef CONFIG_PAX_REFCOUNT
6383+ tvs %xcc, 6
6384+#endif
6385+
6386 casx [%o1], %g1, %g7
6387 cmp %g1, %g7
6388 bne,pn %xcc, BACKOFF_LABEL(2f, 1b)
6389@@ -92,10 +175,28 @@ ENTRY(atomic64_sub) /* %o0 = decrement, %o1 = atomic_ptr */
6390 2: BACKOFF_SPIN(%o2, %o3, 1b)
6391 ENDPROC(atomic64_sub)
6392
6393+ENTRY(atomic64_sub_unchecked) /* %o0 = decrement, %o1 = atomic_ptr */
6394+ BACKOFF_SETUP(%o2)
6395+1: ldx [%o1], %g1
6396+ subcc %g1, %o0, %g7
6397+ casx [%o1], %g1, %g7
6398+ cmp %g1, %g7
6399+ bne,pn %xcc, 2f
6400+ nop
6401+ retl
6402+ nop
6403+2: BACKOFF_SPIN(%o2, %o3, 1b)
6404+ENDPROC(atomic64_sub_unchecked)
6405+
6406 ENTRY(atomic64_add_ret) /* %o0 = increment, %o1 = atomic_ptr */
6407 BACKOFF_SETUP(%o2)
6408 1: ldx [%o1], %g1
6409- add %g1, %o0, %g7
6410+ addcc %g1, %o0, %g7
6411+
6412+#ifdef CONFIG_PAX_REFCOUNT
6413+ tvs %xcc, 6
6414+#endif
6415+
6416 casx [%o1], %g1, %g7
6417 cmp %g1, %g7
6418 bne,pn %xcc, BACKOFF_LABEL(2f, 1b)
6419@@ -105,10 +206,29 @@ ENTRY(atomic64_add_ret) /* %o0 = increment, %o1 = atomic_ptr */
6420 2: BACKOFF_SPIN(%o2, %o3, 1b)
6421 ENDPROC(atomic64_add_ret)
6422
6423+ENTRY(atomic64_add_ret_unchecked) /* %o0 = increment, %o1 = atomic_ptr */
6424+ BACKOFF_SETUP(%o2)
6425+1: ldx [%o1], %g1
6426+ addcc %g1, %o0, %g7
6427+ casx [%o1], %g1, %g7
6428+ cmp %g1, %g7
6429+ bne,pn %xcc, 2f
6430+ add %g7, %o0, %g7
6431+ mov %g7, %o0
6432+ retl
6433+ nop
6434+2: BACKOFF_SPIN(%o2, %o3, 1b)
6435+ENDPROC(atomic64_add_ret_unchecked)
6436+
6437 ENTRY(atomic64_sub_ret) /* %o0 = decrement, %o1 = atomic_ptr */
6438 BACKOFF_SETUP(%o2)
6439 1: ldx [%o1], %g1
6440- sub %g1, %o0, %g7
6441+ subcc %g1, %o0, %g7
6442+
6443+#ifdef CONFIG_PAX_REFCOUNT
6444+ tvs %xcc, 6
6445+#endif
6446+
6447 casx [%o1], %g1, %g7
6448 cmp %g1, %g7
6449 bne,pn %xcc, BACKOFF_LABEL(2f, 1b)
6450diff --git a/arch/sparc/lib/ksyms.c b/arch/sparc/lib/ksyms.c
6451index 3b31218..345c609 100644
6452--- a/arch/sparc/lib/ksyms.c
6453+++ b/arch/sparc/lib/ksyms.c
6454@@ -109,12 +109,18 @@ EXPORT_SYMBOL(__downgrade_write);
6455
6456 /* Atomic counter implementation. */
6457 EXPORT_SYMBOL(atomic_add);
6458+EXPORT_SYMBOL(atomic_add_unchecked);
6459 EXPORT_SYMBOL(atomic_add_ret);
6460+EXPORT_SYMBOL(atomic_add_ret_unchecked);
6461 EXPORT_SYMBOL(atomic_sub);
6462+EXPORT_SYMBOL(atomic_sub_unchecked);
6463 EXPORT_SYMBOL(atomic_sub_ret);
6464 EXPORT_SYMBOL(atomic64_add);
6465+EXPORT_SYMBOL(atomic64_add_unchecked);
6466 EXPORT_SYMBOL(atomic64_add_ret);
6467+EXPORT_SYMBOL(atomic64_add_ret_unchecked);
6468 EXPORT_SYMBOL(atomic64_sub);
6469+EXPORT_SYMBOL(atomic64_sub_unchecked);
6470 EXPORT_SYMBOL(atomic64_sub_ret);
6471
6472 /* Atomic bit operations. */
6473diff --git a/arch/sparc/mm/Makefile b/arch/sparc/mm/Makefile
6474index 30c3ecc..736f015 100644
6475--- a/arch/sparc/mm/Makefile
6476+++ b/arch/sparc/mm/Makefile
6477@@ -2,7 +2,7 @@
6478 #
6479
6480 asflags-y := -ansi
6481-ccflags-y := -Werror
6482+#ccflags-y := -Werror
6483
6484 obj-$(CONFIG_SPARC64) += ultra.o tlb.o tsb.o gup.o
6485 obj-y += fault_$(BITS).o
6486diff --git a/arch/sparc/mm/fault_32.c b/arch/sparc/mm/fault_32.c
6487index 77ac917..baf45db 100644
6488--- a/arch/sparc/mm/fault_32.c
6489+++ b/arch/sparc/mm/fault_32.c
6490@@ -21,6 +21,9 @@
6491 #include <linux/perf_event.h>
6492 #include <linux/interrupt.h>
6493 #include <linux/kdebug.h>
6494+#include <linux/slab.h>
6495+#include <linux/pagemap.h>
6496+#include <linux/compiler.h>
6497
6498 #include <asm/page.h>
6499 #include <asm/pgtable.h>
6500@@ -159,6 +162,277 @@ static unsigned long compute_si_addr(struct pt_regs *regs, int text_fault)
6501 return safe_compute_effective_address(regs, insn);
6502 }
6503
6504+#ifdef CONFIG_PAX_PAGEEXEC
6505+#ifdef CONFIG_PAX_DLRESOLVE
6506+static void pax_emuplt_close(struct vm_area_struct *vma)
6507+{
6508+ vma->vm_mm->call_dl_resolve = 0UL;
6509+}
6510+
6511+static int pax_emuplt_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
6512+{
6513+ unsigned int *kaddr;
6514+
6515+ vmf->page = alloc_page(GFP_HIGHUSER);
6516+ if (!vmf->page)
6517+ return VM_FAULT_OOM;
6518+
6519+ kaddr = kmap(vmf->page);
6520+ memset(kaddr, 0, PAGE_SIZE);
6521+ kaddr[0] = 0x9DE3BFA8U; /* save */
6522+ flush_dcache_page(vmf->page);
6523+ kunmap(vmf->page);
6524+ return VM_FAULT_MAJOR;
6525+}
6526+
6527+static const struct vm_operations_struct pax_vm_ops = {
6528+ .close = pax_emuplt_close,
6529+ .fault = pax_emuplt_fault
6530+};
6531+
6532+static int pax_insert_vma(struct vm_area_struct *vma, unsigned long addr)
6533+{
6534+ int ret;
6535+
6536+ INIT_LIST_HEAD(&vma->anon_vma_chain);
6537+ vma->vm_mm = current->mm;
6538+ vma->vm_start = addr;
6539+ vma->vm_end = addr + PAGE_SIZE;
6540+ vma->vm_flags = VM_READ | VM_EXEC | VM_MAYREAD | VM_MAYEXEC;
6541+ vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
6542+ vma->vm_ops = &pax_vm_ops;
6543+
6544+ ret = insert_vm_struct(current->mm, vma);
6545+ if (ret)
6546+ return ret;
6547+
6548+ ++current->mm->total_vm;
6549+ return 0;
6550+}
6551+#endif
6552+
6553+/*
6554+ * PaX: decide what to do with offenders (regs->pc = fault address)
6555+ *
6556+ * returns 1 when task should be killed
6557+ * 2 when patched PLT trampoline was detected
6558+ * 3 when unpatched PLT trampoline was detected
6559+ */
6560+static int pax_handle_fetch_fault(struct pt_regs *regs)
6561+{
6562+
6563+#ifdef CONFIG_PAX_EMUPLT
6564+ int err;
6565+
6566+ do { /* PaX: patched PLT emulation #1 */
6567+ unsigned int sethi1, sethi2, jmpl;
6568+
6569+ err = get_user(sethi1, (unsigned int *)regs->pc);
6570+ err |= get_user(sethi2, (unsigned int *)(regs->pc+4));
6571+ err |= get_user(jmpl, (unsigned int *)(regs->pc+8));
6572+
6573+ if (err)
6574+ break;
6575+
6576+ if ((sethi1 & 0xFFC00000U) == 0x03000000U &&
6577+ (sethi2 & 0xFFC00000U) == 0x03000000U &&
6578+ (jmpl & 0xFFFFE000U) == 0x81C06000U)
6579+ {
6580+ unsigned int addr;
6581+
6582+ regs->u_regs[UREG_G1] = (sethi2 & 0x003FFFFFU) << 10;
6583+ addr = regs->u_regs[UREG_G1];
6584+ addr += (((jmpl | 0xFFFFE000U) ^ 0x00001000U) + 0x00001000U);
6585+ regs->pc = addr;
6586+ regs->npc = addr+4;
6587+ return 2;
6588+ }
6589+ } while (0);
6590+
6591+ do { /* PaX: patched PLT emulation #2 */
6592+ unsigned int ba;
6593+
6594+ err = get_user(ba, (unsigned int *)regs->pc);
6595+
6596+ if (err)
6597+ break;
6598+
6599+ if ((ba & 0xFFC00000U) == 0x30800000U || (ba & 0xFFF80000U) == 0x30480000U) {
6600+ unsigned int addr;
6601+
6602+ if ((ba & 0xFFC00000U) == 0x30800000U)
6603+ addr = regs->pc + ((((ba | 0xFFC00000U) ^ 0x00200000U) + 0x00200000U) << 2);
6604+ else
6605+ addr = regs->pc + ((((ba | 0xFFF80000U) ^ 0x00040000U) + 0x00040000U) << 2);
6606+ regs->pc = addr;
6607+ regs->npc = addr+4;
6608+ return 2;
6609+ }
6610+ } while (0);
6611+
6612+ do { /* PaX: patched PLT emulation #3 */
6613+ unsigned int sethi, bajmpl, nop;
6614+
6615+ err = get_user(sethi, (unsigned int *)regs->pc);
6616+ err |= get_user(bajmpl, (unsigned int *)(regs->pc+4));
6617+ err |= get_user(nop, (unsigned int *)(regs->pc+8));
6618+
6619+ if (err)
6620+ break;
6621+
6622+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
6623+ ((bajmpl & 0xFFFFE000U) == 0x81C06000U || (bajmpl & 0xFFF80000U) == 0x30480000U) &&
6624+ nop == 0x01000000U)
6625+ {
6626+ unsigned int addr;
6627+
6628+ addr = (sethi & 0x003FFFFFU) << 10;
6629+ regs->u_regs[UREG_G1] = addr;
6630+ if ((bajmpl & 0xFFFFE000U) == 0x81C06000U)
6631+ addr += (((bajmpl | 0xFFFFE000U) ^ 0x00001000U) + 0x00001000U);
6632+ else
6633+ addr = regs->pc + ((((bajmpl | 0xFFF80000U) ^ 0x00040000U) + 0x00040000U) << 2);
6634+ regs->pc = addr;
6635+ regs->npc = addr+4;
6636+ return 2;
6637+ }
6638+ } while (0);
6639+
6640+ do { /* PaX: unpatched PLT emulation step 1 */
6641+ unsigned int sethi, ba, nop;
6642+
6643+ err = get_user(sethi, (unsigned int *)regs->pc);
6644+ err |= get_user(ba, (unsigned int *)(regs->pc+4));
6645+ err |= get_user(nop, (unsigned int *)(regs->pc+8));
6646+
6647+ if (err)
6648+ break;
6649+
6650+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
6651+ ((ba & 0xFFC00000U) == 0x30800000U || (ba & 0xFFF80000U) == 0x30680000U) &&
6652+ nop == 0x01000000U)
6653+ {
6654+ unsigned int addr, save, call;
6655+
6656+ if ((ba & 0xFFC00000U) == 0x30800000U)
6657+ addr = regs->pc + 4 + ((((ba | 0xFFC00000U) ^ 0x00200000U) + 0x00200000U) << 2);
6658+ else
6659+ addr = regs->pc + 4 + ((((ba | 0xFFF80000U) ^ 0x00040000U) + 0x00040000U) << 2);
6660+
6661+ err = get_user(save, (unsigned int *)addr);
6662+ err |= get_user(call, (unsigned int *)(addr+4));
6663+ err |= get_user(nop, (unsigned int *)(addr+8));
6664+ if (err)
6665+ break;
6666+
6667+#ifdef CONFIG_PAX_DLRESOLVE
6668+ if (save == 0x9DE3BFA8U &&
6669+ (call & 0xC0000000U) == 0x40000000U &&
6670+ nop == 0x01000000U)
6671+ {
6672+ struct vm_area_struct *vma;
6673+ unsigned long call_dl_resolve;
6674+
6675+ down_read(&current->mm->mmap_sem);
6676+ call_dl_resolve = current->mm->call_dl_resolve;
6677+ up_read(&current->mm->mmap_sem);
6678+ if (likely(call_dl_resolve))
6679+ goto emulate;
6680+
6681+ vma = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
6682+
6683+ down_write(&current->mm->mmap_sem);
6684+ if (current->mm->call_dl_resolve) {
6685+ call_dl_resolve = current->mm->call_dl_resolve;
6686+ up_write(&current->mm->mmap_sem);
6687+ if (vma)
6688+ kmem_cache_free(vm_area_cachep, vma);
6689+ goto emulate;
6690+ }
6691+
6692+ call_dl_resolve = get_unmapped_area(NULL, 0UL, PAGE_SIZE, 0UL, MAP_PRIVATE);
6693+ if (!vma || (call_dl_resolve & ~PAGE_MASK)) {
6694+ up_write(&current->mm->mmap_sem);
6695+ if (vma)
6696+ kmem_cache_free(vm_area_cachep, vma);
6697+ return 1;
6698+ }
6699+
6700+ if (pax_insert_vma(vma, call_dl_resolve)) {
6701+ up_write(&current->mm->mmap_sem);
6702+ kmem_cache_free(vm_area_cachep, vma);
6703+ return 1;
6704+ }
6705+
6706+ current->mm->call_dl_resolve = call_dl_resolve;
6707+ up_write(&current->mm->mmap_sem);
6708+
6709+emulate:
6710+ regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
6711+ regs->pc = call_dl_resolve;
6712+ regs->npc = addr+4;
6713+ return 3;
6714+ }
6715+#endif
6716+
6717+ /* PaX: glibc 2.4+ generates sethi/jmpl instead of save/call */
6718+ if ((save & 0xFFC00000U) == 0x05000000U &&
6719+ (call & 0xFFFFE000U) == 0x85C0A000U &&
6720+ nop == 0x01000000U)
6721+ {
6722+ regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
6723+ regs->u_regs[UREG_G2] = addr + 4;
6724+ addr = (save & 0x003FFFFFU) << 10;
6725+ addr += (((call | 0xFFFFE000U) ^ 0x00001000U) + 0x00001000U);
6726+ regs->pc = addr;
6727+ regs->npc = addr+4;
6728+ return 3;
6729+ }
6730+ }
6731+ } while (0);
6732+
6733+ do { /* PaX: unpatched PLT emulation step 2 */
6734+ unsigned int save, call, nop;
6735+
6736+ err = get_user(save, (unsigned int *)(regs->pc-4));
6737+ err |= get_user(call, (unsigned int *)regs->pc);
6738+ err |= get_user(nop, (unsigned int *)(regs->pc+4));
6739+ if (err)
6740+ break;
6741+
6742+ if (save == 0x9DE3BFA8U &&
6743+ (call & 0xC0000000U) == 0x40000000U &&
6744+ nop == 0x01000000U)
6745+ {
6746+ unsigned int dl_resolve = regs->pc + ((((call | 0xC0000000U) ^ 0x20000000U) + 0x20000000U) << 2);
6747+
6748+ regs->u_regs[UREG_RETPC] = regs->pc;
6749+ regs->pc = dl_resolve;
6750+ regs->npc = dl_resolve+4;
6751+ return 3;
6752+ }
6753+ } while (0);
6754+#endif
6755+
6756+ return 1;
6757+}
6758+
6759+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
6760+{
6761+ unsigned long i;
6762+
6763+ printk(KERN_ERR "PAX: bytes at PC: ");
6764+ for (i = 0; i < 8; i++) {
6765+ unsigned int c;
6766+ if (get_user(c, (unsigned int *)pc+i))
6767+ printk(KERN_CONT "???????? ");
6768+ else
6769+ printk(KERN_CONT "%08x ", c);
6770+ }
6771+ printk("\n");
6772+}
6773+#endif
6774+
6775 static noinline void do_fault_siginfo(int code, int sig, struct pt_regs *regs,
6776 int text_fault)
6777 {
6778@@ -230,6 +504,24 @@ good_area:
6779 if (!(vma->vm_flags & VM_WRITE))
6780 goto bad_area;
6781 } else {
6782+
6783+#ifdef CONFIG_PAX_PAGEEXEC
6784+ if ((mm->pax_flags & MF_PAX_PAGEEXEC) && text_fault && !(vma->vm_flags & VM_EXEC)) {
6785+ up_read(&mm->mmap_sem);
6786+ switch (pax_handle_fetch_fault(regs)) {
6787+
6788+#ifdef CONFIG_PAX_EMUPLT
6789+ case 2:
6790+ case 3:
6791+ return;
6792+#endif
6793+
6794+ }
6795+ pax_report_fault(regs, (void *)regs->pc, (void *)regs->u_regs[UREG_FP]);
6796+ do_group_exit(SIGKILL);
6797+ }
6798+#endif
6799+
6800 /* Allow reads even for write-only mappings */
6801 if (!(vma->vm_flags & (VM_READ | VM_EXEC)))
6802 goto bad_area;
6803diff --git a/arch/sparc/mm/fault_64.c b/arch/sparc/mm/fault_64.c
6804index 1fe0429..8dd5dd5 100644
6805--- a/arch/sparc/mm/fault_64.c
6806+++ b/arch/sparc/mm/fault_64.c
6807@@ -21,6 +21,9 @@
6808 #include <linux/kprobes.h>
6809 #include <linux/kdebug.h>
6810 #include <linux/percpu.h>
6811+#include <linux/slab.h>
6812+#include <linux/pagemap.h>
6813+#include <linux/compiler.h>
6814
6815 #include <asm/page.h>
6816 #include <asm/pgtable.h>
6817@@ -74,7 +77,7 @@ static void __kprobes bad_kernel_pc(struct pt_regs *regs, unsigned long vaddr)
6818 printk(KERN_CRIT "OOPS: Bogus kernel PC [%016lx] in fault handler\n",
6819 regs->tpc);
6820 printk(KERN_CRIT "OOPS: RPC [%016lx]\n", regs->u_regs[15]);
6821- printk("OOPS: RPC <%pS>\n", (void *) regs->u_regs[15]);
6822+ printk("OOPS: RPC <%pA>\n", (void *) regs->u_regs[15]);
6823 printk(KERN_CRIT "OOPS: Fault was to vaddr[%lx]\n", vaddr);
6824 dump_stack();
6825 unhandled_fault(regs->tpc, current, regs);
6826@@ -272,6 +275,466 @@ static void noinline __kprobes bogus_32bit_fault_address(struct pt_regs *regs,
6827 show_regs(regs);
6828 }
6829
6830+#ifdef CONFIG_PAX_PAGEEXEC
6831+#ifdef CONFIG_PAX_DLRESOLVE
6832+static void pax_emuplt_close(struct vm_area_struct *vma)
6833+{
6834+ vma->vm_mm->call_dl_resolve = 0UL;
6835+}
6836+
6837+static int pax_emuplt_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
6838+{
6839+ unsigned int *kaddr;
6840+
6841+ vmf->page = alloc_page(GFP_HIGHUSER);
6842+ if (!vmf->page)
6843+ return VM_FAULT_OOM;
6844+
6845+ kaddr = kmap(vmf->page);
6846+ memset(kaddr, 0, PAGE_SIZE);
6847+ kaddr[0] = 0x9DE3BFA8U; /* save */
6848+ flush_dcache_page(vmf->page);
6849+ kunmap(vmf->page);
6850+ return VM_FAULT_MAJOR;
6851+}
6852+
6853+static const struct vm_operations_struct pax_vm_ops = {
6854+ .close = pax_emuplt_close,
6855+ .fault = pax_emuplt_fault
6856+};
6857+
6858+static int pax_insert_vma(struct vm_area_struct *vma, unsigned long addr)
6859+{
6860+ int ret;
6861+
6862+ INIT_LIST_HEAD(&vma->anon_vma_chain);
6863+ vma->vm_mm = current->mm;
6864+ vma->vm_start = addr;
6865+ vma->vm_end = addr + PAGE_SIZE;
6866+ vma->vm_flags = VM_READ | VM_EXEC | VM_MAYREAD | VM_MAYEXEC;
6867+ vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
6868+ vma->vm_ops = &pax_vm_ops;
6869+
6870+ ret = insert_vm_struct(current->mm, vma);
6871+ if (ret)
6872+ return ret;
6873+
6874+ ++current->mm->total_vm;
6875+ return 0;
6876+}
6877+#endif
6878+
6879+/*
6880+ * PaX: decide what to do with offenders (regs->tpc = fault address)
6881+ *
6882+ * returns 1 when task should be killed
6883+ * 2 when patched PLT trampoline was detected
6884+ * 3 when unpatched PLT trampoline was detected
6885+ */
6886+static int pax_handle_fetch_fault(struct pt_regs *regs)
6887+{
6888+
6889+#ifdef CONFIG_PAX_EMUPLT
6890+ int err;
6891+
6892+ do { /* PaX: patched PLT emulation #1 */
6893+ unsigned int sethi1, sethi2, jmpl;
6894+
6895+ err = get_user(sethi1, (unsigned int *)regs->tpc);
6896+ err |= get_user(sethi2, (unsigned int *)(regs->tpc+4));
6897+ err |= get_user(jmpl, (unsigned int *)(regs->tpc+8));
6898+
6899+ if (err)
6900+ break;
6901+
6902+ if ((sethi1 & 0xFFC00000U) == 0x03000000U &&
6903+ (sethi2 & 0xFFC00000U) == 0x03000000U &&
6904+ (jmpl & 0xFFFFE000U) == 0x81C06000U)
6905+ {
6906+ unsigned long addr;
6907+
6908+ regs->u_regs[UREG_G1] = (sethi2 & 0x003FFFFFU) << 10;
6909+ addr = regs->u_regs[UREG_G1];
6910+ addr += (((jmpl | 0xFFFFFFFFFFFFE000UL) ^ 0x00001000UL) + 0x00001000UL);
6911+
6912+ if (test_thread_flag(TIF_32BIT))
6913+ addr &= 0xFFFFFFFFUL;
6914+
6915+ regs->tpc = addr;
6916+ regs->tnpc = addr+4;
6917+ return 2;
6918+ }
6919+ } while (0);
6920+
6921+ do { /* PaX: patched PLT emulation #2 */
6922+ unsigned int ba;
6923+
6924+ err = get_user(ba, (unsigned int *)regs->tpc);
6925+
6926+ if (err)
6927+ break;
6928+
6929+ if ((ba & 0xFFC00000U) == 0x30800000U || (ba & 0xFFF80000U) == 0x30480000U) {
6930+ unsigned long addr;
6931+
6932+ if ((ba & 0xFFC00000U) == 0x30800000U)
6933+ addr = regs->tpc + ((((ba | 0xFFFFFFFFFFC00000UL) ^ 0x00200000UL) + 0x00200000UL) << 2);
6934+ else
6935+ addr = regs->tpc + ((((ba | 0xFFFFFFFFFFF80000UL) ^ 0x00040000UL) + 0x00040000UL) << 2);
6936+
6937+ if (test_thread_flag(TIF_32BIT))
6938+ addr &= 0xFFFFFFFFUL;
6939+
6940+ regs->tpc = addr;
6941+ regs->tnpc = addr+4;
6942+ return 2;
6943+ }
6944+ } while (0);
6945+
6946+ do { /* PaX: patched PLT emulation #3 */
6947+ unsigned int sethi, bajmpl, nop;
6948+
6949+ err = get_user(sethi, (unsigned int *)regs->tpc);
6950+ err |= get_user(bajmpl, (unsigned int *)(regs->tpc+4));
6951+ err |= get_user(nop, (unsigned int *)(regs->tpc+8));
6952+
6953+ if (err)
6954+ break;
6955+
6956+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
6957+ ((bajmpl & 0xFFFFE000U) == 0x81C06000U || (bajmpl & 0xFFF80000U) == 0x30480000U) &&
6958+ nop == 0x01000000U)
6959+ {
6960+ unsigned long addr;
6961+
6962+ addr = (sethi & 0x003FFFFFU) << 10;
6963+ regs->u_regs[UREG_G1] = addr;
6964+ if ((bajmpl & 0xFFFFE000U) == 0x81C06000U)
6965+ addr += (((bajmpl | 0xFFFFFFFFFFFFE000UL) ^ 0x00001000UL) + 0x00001000UL);
6966+ else
6967+ addr = regs->tpc + ((((bajmpl | 0xFFFFFFFFFFF80000UL) ^ 0x00040000UL) + 0x00040000UL) << 2);
6968+
6969+ if (test_thread_flag(TIF_32BIT))
6970+ addr &= 0xFFFFFFFFUL;
6971+
6972+ regs->tpc = addr;
6973+ regs->tnpc = addr+4;
6974+ return 2;
6975+ }
6976+ } while (0);
6977+
6978+ do { /* PaX: patched PLT emulation #4 */
6979+ unsigned int sethi, mov1, call, mov2;
6980+
6981+ err = get_user(sethi, (unsigned int *)regs->tpc);
6982+ err |= get_user(mov1, (unsigned int *)(regs->tpc+4));
6983+ err |= get_user(call, (unsigned int *)(regs->tpc+8));
6984+ err |= get_user(mov2, (unsigned int *)(regs->tpc+12));
6985+
6986+ if (err)
6987+ break;
6988+
6989+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
6990+ mov1 == 0x8210000FU &&
6991+ (call & 0xC0000000U) == 0x40000000U &&
6992+ mov2 == 0x9E100001U)
6993+ {
6994+ unsigned long addr;
6995+
6996+ regs->u_regs[UREG_G1] = regs->u_regs[UREG_RETPC];
6997+ addr = regs->tpc + 4 + ((((call | 0xFFFFFFFFC0000000UL) ^ 0x20000000UL) + 0x20000000UL) << 2);
6998+
6999+ if (test_thread_flag(TIF_32BIT))
7000+ addr &= 0xFFFFFFFFUL;
7001+
7002+ regs->tpc = addr;
7003+ regs->tnpc = addr+4;
7004+ return 2;
7005+ }
7006+ } while (0);
7007+
7008+ do { /* PaX: patched PLT emulation #5 */
7009+ unsigned int sethi, sethi1, sethi2, or1, or2, sllx, jmpl, nop;
7010+
7011+ err = get_user(sethi, (unsigned int *)regs->tpc);
7012+ err |= get_user(sethi1, (unsigned int *)(regs->tpc+4));
7013+ err |= get_user(sethi2, (unsigned int *)(regs->tpc+8));
7014+ err |= get_user(or1, (unsigned int *)(regs->tpc+12));
7015+ err |= get_user(or2, (unsigned int *)(regs->tpc+16));
7016+ err |= get_user(sllx, (unsigned int *)(regs->tpc+20));
7017+ err |= get_user(jmpl, (unsigned int *)(regs->tpc+24));
7018+ err |= get_user(nop, (unsigned int *)(regs->tpc+28));
7019+
7020+ if (err)
7021+ break;
7022+
7023+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
7024+ (sethi1 & 0xFFC00000U) == 0x03000000U &&
7025+ (sethi2 & 0xFFC00000U) == 0x0B000000U &&
7026+ (or1 & 0xFFFFE000U) == 0x82106000U &&
7027+ (or2 & 0xFFFFE000U) == 0x8A116000U &&
7028+ sllx == 0x83287020U &&
7029+ jmpl == 0x81C04005U &&
7030+ nop == 0x01000000U)
7031+ {
7032+ unsigned long addr;
7033+
7034+ regs->u_regs[UREG_G1] = ((sethi1 & 0x003FFFFFU) << 10) | (or1 & 0x000003FFU);
7035+ regs->u_regs[UREG_G1] <<= 32;
7036+ regs->u_regs[UREG_G5] = ((sethi2 & 0x003FFFFFU) << 10) | (or2 & 0x000003FFU);
7037+ addr = regs->u_regs[UREG_G1] + regs->u_regs[UREG_G5];
7038+ regs->tpc = addr;
7039+ regs->tnpc = addr+4;
7040+ return 2;
7041+ }
7042+ } while (0);
7043+
7044+ do { /* PaX: patched PLT emulation #6 */
7045+ unsigned int sethi, sethi1, sethi2, sllx, or, jmpl, nop;
7046+
7047+ err = get_user(sethi, (unsigned int *)regs->tpc);
7048+ err |= get_user(sethi1, (unsigned int *)(regs->tpc+4));
7049+ err |= get_user(sethi2, (unsigned int *)(regs->tpc+8));
7050+ err |= get_user(sllx, (unsigned int *)(regs->tpc+12));
7051+ err |= get_user(or, (unsigned int *)(regs->tpc+16));
7052+ err |= get_user(jmpl, (unsigned int *)(regs->tpc+20));
7053+ err |= get_user(nop, (unsigned int *)(regs->tpc+24));
7054+
7055+ if (err)
7056+ break;
7057+
7058+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
7059+ (sethi1 & 0xFFC00000U) == 0x03000000U &&
7060+ (sethi2 & 0xFFC00000U) == 0x0B000000U &&
7061+ sllx == 0x83287020U &&
7062+ (or & 0xFFFFE000U) == 0x8A116000U &&
7063+ jmpl == 0x81C04005U &&
7064+ nop == 0x01000000U)
7065+ {
7066+ unsigned long addr;
7067+
7068+ regs->u_regs[UREG_G1] = (sethi1 & 0x003FFFFFU) << 10;
7069+ regs->u_regs[UREG_G1] <<= 32;
7070+ regs->u_regs[UREG_G5] = ((sethi2 & 0x003FFFFFU) << 10) | (or & 0x3FFU);
7071+ addr = regs->u_regs[UREG_G1] + regs->u_regs[UREG_G5];
7072+ regs->tpc = addr;
7073+ regs->tnpc = addr+4;
7074+ return 2;
7075+ }
7076+ } while (0);
7077+
7078+ do { /* PaX: unpatched PLT emulation step 1 */
7079+ unsigned int sethi, ba, nop;
7080+
7081+ err = get_user(sethi, (unsigned int *)regs->tpc);
7082+ err |= get_user(ba, (unsigned int *)(regs->tpc+4));
7083+ err |= get_user(nop, (unsigned int *)(regs->tpc+8));
7084+
7085+ if (err)
7086+ break;
7087+
7088+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
7089+ ((ba & 0xFFC00000U) == 0x30800000U || (ba & 0xFFF80000U) == 0x30680000U) &&
7090+ nop == 0x01000000U)
7091+ {
7092+ unsigned long addr;
7093+ unsigned int save, call;
7094+ unsigned int sethi1, sethi2, or1, or2, sllx, add, jmpl;
7095+
7096+ if ((ba & 0xFFC00000U) == 0x30800000U)
7097+ addr = regs->tpc + 4 + ((((ba | 0xFFFFFFFFFFC00000UL) ^ 0x00200000UL) + 0x00200000UL) << 2);
7098+ else
7099+ addr = regs->tpc + 4 + ((((ba | 0xFFFFFFFFFFF80000UL) ^ 0x00040000UL) + 0x00040000UL) << 2);
7100+
7101+ if (test_thread_flag(TIF_32BIT))
7102+ addr &= 0xFFFFFFFFUL;
7103+
7104+ err = get_user(save, (unsigned int *)addr);
7105+ err |= get_user(call, (unsigned int *)(addr+4));
7106+ err |= get_user(nop, (unsigned int *)(addr+8));
7107+ if (err)
7108+ break;
7109+
7110+#ifdef CONFIG_PAX_DLRESOLVE
7111+ if (save == 0x9DE3BFA8U &&
7112+ (call & 0xC0000000U) == 0x40000000U &&
7113+ nop == 0x01000000U)
7114+ {
7115+ struct vm_area_struct *vma;
7116+ unsigned long call_dl_resolve;
7117+
7118+ down_read(&current->mm->mmap_sem);
7119+ call_dl_resolve = current->mm->call_dl_resolve;
7120+ up_read(&current->mm->mmap_sem);
7121+ if (likely(call_dl_resolve))
7122+ goto emulate;
7123+
7124+ vma = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
7125+
7126+ down_write(&current->mm->mmap_sem);
7127+ if (current->mm->call_dl_resolve) {
7128+ call_dl_resolve = current->mm->call_dl_resolve;
7129+ up_write(&current->mm->mmap_sem);
7130+ if (vma)
7131+ kmem_cache_free(vm_area_cachep, vma);
7132+ goto emulate;
7133+ }
7134+
7135+ call_dl_resolve = get_unmapped_area(NULL, 0UL, PAGE_SIZE, 0UL, MAP_PRIVATE);
7136+ if (!vma || (call_dl_resolve & ~PAGE_MASK)) {
7137+ up_write(&current->mm->mmap_sem);
7138+ if (vma)
7139+ kmem_cache_free(vm_area_cachep, vma);
7140+ return 1;
7141+ }
7142+
7143+ if (pax_insert_vma(vma, call_dl_resolve)) {
7144+ up_write(&current->mm->mmap_sem);
7145+ kmem_cache_free(vm_area_cachep, vma);
7146+ return 1;
7147+ }
7148+
7149+ current->mm->call_dl_resolve = call_dl_resolve;
7150+ up_write(&current->mm->mmap_sem);
7151+
7152+emulate:
7153+ regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
7154+ regs->tpc = call_dl_resolve;
7155+ regs->tnpc = addr+4;
7156+ return 3;
7157+ }
7158+#endif
7159+
7160+ /* PaX: glibc 2.4+ generates sethi/jmpl instead of save/call */
7161+ if ((save & 0xFFC00000U) == 0x05000000U &&
7162+ (call & 0xFFFFE000U) == 0x85C0A000U &&
7163+ nop == 0x01000000U)
7164+ {
7165+ regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
7166+ regs->u_regs[UREG_G2] = addr + 4;
7167+ addr = (save & 0x003FFFFFU) << 10;
7168+ addr += (((call | 0xFFFFFFFFFFFFE000UL) ^ 0x00001000UL) + 0x00001000UL);
7169+
7170+ if (test_thread_flag(TIF_32BIT))
7171+ addr &= 0xFFFFFFFFUL;
7172+
7173+ regs->tpc = addr;
7174+ regs->tnpc = addr+4;
7175+ return 3;
7176+ }
7177+
7178+ /* PaX: 64-bit PLT stub */
7179+ err = get_user(sethi1, (unsigned int *)addr);
7180+ err |= get_user(sethi2, (unsigned int *)(addr+4));
7181+ err |= get_user(or1, (unsigned int *)(addr+8));
7182+ err |= get_user(or2, (unsigned int *)(addr+12));
7183+ err |= get_user(sllx, (unsigned int *)(addr+16));
7184+ err |= get_user(add, (unsigned int *)(addr+20));
7185+ err |= get_user(jmpl, (unsigned int *)(addr+24));
7186+ err |= get_user(nop, (unsigned int *)(addr+28));
7187+ if (err)
7188+ break;
7189+
7190+ if ((sethi1 & 0xFFC00000U) == 0x09000000U &&
7191+ (sethi2 & 0xFFC00000U) == 0x0B000000U &&
7192+ (or1 & 0xFFFFE000U) == 0x88112000U &&
7193+ (or2 & 0xFFFFE000U) == 0x8A116000U &&
7194+ sllx == 0x89293020U &&
7195+ add == 0x8A010005U &&
7196+ jmpl == 0x89C14000U &&
7197+ nop == 0x01000000U)
7198+ {
7199+ regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
7200+ regs->u_regs[UREG_G4] = ((sethi1 & 0x003FFFFFU) << 10) | (or1 & 0x000003FFU);
7201+ regs->u_regs[UREG_G4] <<= 32;
7202+ regs->u_regs[UREG_G5] = ((sethi2 & 0x003FFFFFU) << 10) | (or2 & 0x000003FFU);
7203+ regs->u_regs[UREG_G5] += regs->u_regs[UREG_G4];
7204+ regs->u_regs[UREG_G4] = addr + 24;
7205+ addr = regs->u_regs[UREG_G5];
7206+ regs->tpc = addr;
7207+ regs->tnpc = addr+4;
7208+ return 3;
7209+ }
7210+ }
7211+ } while (0);
7212+
7213+#ifdef CONFIG_PAX_DLRESOLVE
7214+ do { /* PaX: unpatched PLT emulation step 2 */
7215+ unsigned int save, call, nop;
7216+
7217+ err = get_user(save, (unsigned int *)(regs->tpc-4));
7218+ err |= get_user(call, (unsigned int *)regs->tpc);
7219+ err |= get_user(nop, (unsigned int *)(regs->tpc+4));
7220+ if (err)
7221+ break;
7222+
7223+ if (save == 0x9DE3BFA8U &&
7224+ (call & 0xC0000000U) == 0x40000000U &&
7225+ nop == 0x01000000U)
7226+ {
7227+ unsigned long dl_resolve = regs->tpc + ((((call | 0xFFFFFFFFC0000000UL) ^ 0x20000000UL) + 0x20000000UL) << 2);
7228+
7229+ if (test_thread_flag(TIF_32BIT))
7230+ dl_resolve &= 0xFFFFFFFFUL;
7231+
7232+ regs->u_regs[UREG_RETPC] = regs->tpc;
7233+ regs->tpc = dl_resolve;
7234+ regs->tnpc = dl_resolve+4;
7235+ return 3;
7236+ }
7237+ } while (0);
7238+#endif
7239+
7240+ do { /* PaX: patched PLT emulation #7, must be AFTER the unpatched PLT emulation */
7241+ unsigned int sethi, ba, nop;
7242+
7243+ err = get_user(sethi, (unsigned int *)regs->tpc);
7244+ err |= get_user(ba, (unsigned int *)(regs->tpc+4));
7245+ err |= get_user(nop, (unsigned int *)(regs->tpc+8));
7246+
7247+ if (err)
7248+ break;
7249+
7250+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
7251+ (ba & 0xFFF00000U) == 0x30600000U &&
7252+ nop == 0x01000000U)
7253+ {
7254+ unsigned long addr;
7255+
7256+ addr = (sethi & 0x003FFFFFU) << 10;
7257+ regs->u_regs[UREG_G1] = addr;
7258+ addr = regs->tpc + ((((ba | 0xFFFFFFFFFFF80000UL) ^ 0x00040000UL) + 0x00040000UL) << 2);
7259+
7260+ if (test_thread_flag(TIF_32BIT))
7261+ addr &= 0xFFFFFFFFUL;
7262+
7263+ regs->tpc = addr;
7264+ regs->tnpc = addr+4;
7265+ return 2;
7266+ }
7267+ } while (0);
7268+
7269+#endif
7270+
7271+ return 1;
7272+}
7273+
7274+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
7275+{
7276+ unsigned long i;
7277+
7278+ printk(KERN_ERR "PAX: bytes at PC: ");
7279+ for (i = 0; i < 8; i++) {
7280+ unsigned int c;
7281+ if (get_user(c, (unsigned int *)pc+i))
7282+ printk(KERN_CONT "???????? ");
7283+ else
7284+ printk(KERN_CONT "%08x ", c);
7285+ }
7286+ printk("\n");
7287+}
7288+#endif
7289+
7290 asmlinkage void __kprobes do_sparc64_fault(struct pt_regs *regs)
7291 {
7292 struct mm_struct *mm = current->mm;
7293@@ -343,6 +806,29 @@ retry:
7294 if (!vma)
7295 goto bad_area;
7296
7297+#ifdef CONFIG_PAX_PAGEEXEC
7298+ /* PaX: detect ITLB misses on non-exec pages */
7299+ if ((mm->pax_flags & MF_PAX_PAGEEXEC) && vma->vm_start <= address &&
7300+ !(vma->vm_flags & VM_EXEC) && (fault_code & FAULT_CODE_ITLB))
7301+ {
7302+ if (address != regs->tpc)
7303+ goto good_area;
7304+
7305+ up_read(&mm->mmap_sem);
7306+ switch (pax_handle_fetch_fault(regs)) {
7307+
7308+#ifdef CONFIG_PAX_EMUPLT
7309+ case 2:
7310+ case 3:
7311+ return;
7312+#endif
7313+
7314+ }
7315+ pax_report_fault(regs, (void *)regs->tpc, (void *)(regs->u_regs[UREG_FP] + STACK_BIAS));
7316+ do_group_exit(SIGKILL);
7317+ }
7318+#endif
7319+
7320 /* Pure DTLB misses do not tell us whether the fault causing
7321 * load/store/atomic was a write or not, it only says that there
7322 * was no match. So in such a case we (carefully) read the
7323diff --git a/arch/sparc/mm/hugetlbpage.c b/arch/sparc/mm/hugetlbpage.c
7324index 07e1453..0a7d9e9 100644
7325--- a/arch/sparc/mm/hugetlbpage.c
7326+++ b/arch/sparc/mm/hugetlbpage.c
7327@@ -67,7 +67,7 @@ full_search:
7328 }
7329 return -ENOMEM;
7330 }
7331- if (likely(!vma || addr + len <= vma->vm_start)) {
7332+ if (likely(check_heap_stack_gap(vma, addr, len))) {
7333 /*
7334 * Remember the place where we stopped the search:
7335 */
7336@@ -106,7 +106,7 @@ hugetlb_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
7337 /* make sure it can fit in the remaining address space */
7338 if (likely(addr > len)) {
7339 vma = find_vma(mm, addr-len);
7340- if (!vma || addr <= vma->vm_start) {
7341+ if (check_heap_stack_gap(vma, addr - len, len)) {
7342 /* remember the address as a hint for next time */
7343 return (mm->free_area_cache = addr-len);
7344 }
7345@@ -115,16 +115,17 @@ hugetlb_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
7346 if (unlikely(mm->mmap_base < len))
7347 goto bottomup;
7348
7349- addr = (mm->mmap_base-len) & HPAGE_MASK;
7350+ addr = mm->mmap_base - len;
7351
7352 do {
7353+ addr &= HPAGE_MASK;
7354 /*
7355 * Lookup failure means no vma is above this address,
7356 * else if new region fits below vma->vm_start,
7357 * return with success:
7358 */
7359 vma = find_vma(mm, addr);
7360- if (likely(!vma || addr+len <= vma->vm_start)) {
7361+ if (likely(check_heap_stack_gap(vma, addr, len))) {
7362 /* remember the address as a hint for next time */
7363 return (mm->free_area_cache = addr);
7364 }
7365@@ -134,8 +135,8 @@ hugetlb_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
7366 mm->cached_hole_size = vma->vm_start - addr;
7367
7368 /* try just below the current vma->vm_start */
7369- addr = (vma->vm_start-len) & HPAGE_MASK;
7370- } while (likely(len < vma->vm_start));
7371+ addr = skip_heap_stack_gap(vma, len);
7372+ } while (!IS_ERR_VALUE(addr));
7373
7374 bottomup:
7375 /*
7376@@ -181,8 +182,7 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
7377 if (addr) {
7378 addr = ALIGN(addr, HPAGE_SIZE);
7379 vma = find_vma(mm, addr);
7380- if (task_size - len >= addr &&
7381- (!vma || addr + len <= vma->vm_start))
7382+ if (task_size - len >= addr && check_heap_stack_gap(vma, addr, len))
7383 return addr;
7384 }
7385 if (mm->get_unmapped_area == arch_get_unmapped_area)
7386diff --git a/arch/tile/include/asm/atomic_64.h b/arch/tile/include/asm/atomic_64.h
7387index f4500c6..889656c 100644
7388--- a/arch/tile/include/asm/atomic_64.h
7389+++ b/arch/tile/include/asm/atomic_64.h
7390@@ -143,6 +143,16 @@ static inline long atomic64_add_unless(atomic64_t *v, long a, long u)
7391
7392 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
7393
7394+#define atomic64_read_unchecked(v) atomic64_read(v)
7395+#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
7396+#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
7397+#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
7398+#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
7399+#define atomic64_inc_unchecked(v) atomic64_inc(v)
7400+#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
7401+#define atomic64_dec_unchecked(v) atomic64_dec(v)
7402+#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
7403+
7404 /* Atomic dec and inc don't implement barrier, so provide them if needed. */
7405 #define smp_mb__before_atomic_dec() smp_mb()
7406 #define smp_mb__after_atomic_dec() smp_mb()
7407diff --git a/arch/tile/include/asm/cache.h b/arch/tile/include/asm/cache.h
7408index a9a5299..0fce79e 100644
7409--- a/arch/tile/include/asm/cache.h
7410+++ b/arch/tile/include/asm/cache.h
7411@@ -15,11 +15,12 @@
7412 #ifndef _ASM_TILE_CACHE_H
7413 #define _ASM_TILE_CACHE_H
7414
7415+#include <linux/const.h>
7416 #include <arch/chip.h>
7417
7418 /* bytes per L1 data cache line */
7419 #define L1_CACHE_SHIFT CHIP_L1D_LOG_LINE_SIZE()
7420-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
7421+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
7422
7423 /* bytes per L2 cache line */
7424 #define L2_CACHE_SHIFT CHIP_L2_LOG_LINE_SIZE()
7425diff --git a/arch/tile/include/asm/uaccess.h b/arch/tile/include/asm/uaccess.h
7426index 9ab078a..d6635c2 100644
7427--- a/arch/tile/include/asm/uaccess.h
7428+++ b/arch/tile/include/asm/uaccess.h
7429@@ -403,9 +403,9 @@ static inline unsigned long __must_check copy_from_user(void *to,
7430 const void __user *from,
7431 unsigned long n)
7432 {
7433- int sz = __compiletime_object_size(to);
7434+ size_t sz = __compiletime_object_size(to);
7435
7436- if (likely(sz == -1 || sz >= n))
7437+ if (likely(sz == (size_t)-1 || sz >= n))
7438 n = _copy_from_user(to, from, n);
7439 else
7440 copy_from_user_overflow();
7441diff --git a/arch/um/Makefile b/arch/um/Makefile
7442index 0970910..9f65c40 100644
7443--- a/arch/um/Makefile
7444+++ b/arch/um/Makefile
7445@@ -62,6 +62,10 @@ USER_CFLAGS = $(patsubst $(KERNEL_DEFINES),,$(patsubst -D__KERNEL__,,\
7446 $(patsubst -I%,,$(KBUILD_CFLAGS)))) $(ARCH_INCLUDE) $(MODE_INCLUDE) \
7447 $(filter -I%,$(CFLAGS)) -D_FILE_OFFSET_BITS=64 -idirafter include
7448
7449+ifdef CONSTIFY_PLUGIN
7450+USER_CFLAGS += -fplugin-arg-constify_plugin-no-constify
7451+endif
7452+
7453 #This will adjust *FLAGS accordingly to the platform.
7454 include $(srctree)/$(ARCH_DIR)/Makefile-os-$(OS)
7455
7456diff --git a/arch/um/include/asm/cache.h b/arch/um/include/asm/cache.h
7457index 19e1bdd..3665b77 100644
7458--- a/arch/um/include/asm/cache.h
7459+++ b/arch/um/include/asm/cache.h
7460@@ -1,6 +1,7 @@
7461 #ifndef __UM_CACHE_H
7462 #define __UM_CACHE_H
7463
7464+#include <linux/const.h>
7465
7466 #if defined(CONFIG_UML_X86) && !defined(CONFIG_64BIT)
7467 # define L1_CACHE_SHIFT (CONFIG_X86_L1_CACHE_SHIFT)
7468@@ -12,6 +13,6 @@
7469 # define L1_CACHE_SHIFT 5
7470 #endif
7471
7472-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
7473+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
7474
7475 #endif
7476diff --git a/arch/um/include/asm/kmap_types.h b/arch/um/include/asm/kmap_types.h
7477index 2e0a6b1..a64d0f5 100644
7478--- a/arch/um/include/asm/kmap_types.h
7479+++ b/arch/um/include/asm/kmap_types.h
7480@@ -8,6 +8,6 @@
7481
7482 /* No more #include "asm/arch/kmap_types.h" ! */
7483
7484-#define KM_TYPE_NR 14
7485+#define KM_TYPE_NR 15
7486
7487 #endif
7488diff --git a/arch/um/include/asm/page.h b/arch/um/include/asm/page.h
7489index 7cfc3ce..cbd1a58 100644
7490--- a/arch/um/include/asm/page.h
7491+++ b/arch/um/include/asm/page.h
7492@@ -14,6 +14,9 @@
7493 #define PAGE_SIZE (_AC(1, UL) << PAGE_SHIFT)
7494 #define PAGE_MASK (~(PAGE_SIZE-1))
7495
7496+#define ktla_ktva(addr) (addr)
7497+#define ktva_ktla(addr) (addr)
7498+
7499 #ifndef __ASSEMBLY__
7500
7501 struct page;
7502diff --git a/arch/um/include/asm/pgtable-3level.h b/arch/um/include/asm/pgtable-3level.h
7503index 0032f92..cd151e0 100644
7504--- a/arch/um/include/asm/pgtable-3level.h
7505+++ b/arch/um/include/asm/pgtable-3level.h
7506@@ -58,6 +58,7 @@
7507 #define pud_present(x) (pud_val(x) & _PAGE_PRESENT)
7508 #define pud_populate(mm, pud, pmd) \
7509 set_pud(pud, __pud(_PAGE_TABLE + __pa(pmd)))
7510+#define pud_populate_kernel(mm, pud, pmd) pud_populate((mm), (pud), (pmd))
7511
7512 #ifdef CONFIG_64BIT
7513 #define set_pud(pudptr, pudval) set_64bit((u64 *) (pudptr), pud_val(pudval))
7514diff --git a/arch/um/kernel/process.c b/arch/um/kernel/process.c
7515index c5f5afa..6abce4b 100644
7516--- a/arch/um/kernel/process.c
7517+++ b/arch/um/kernel/process.c
7518@@ -402,22 +402,6 @@ int singlestepping(void * t)
7519 return 2;
7520 }
7521
7522-/*
7523- * Only x86 and x86_64 have an arch_align_stack().
7524- * All other arches have "#define arch_align_stack(x) (x)"
7525- * in their asm/system.h
7526- * As this is included in UML from asm-um/system-generic.h,
7527- * we can use it to behave as the subarch does.
7528- */
7529-#ifndef arch_align_stack
7530-unsigned long arch_align_stack(unsigned long sp)
7531-{
7532- if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
7533- sp -= get_random_int() % 8192;
7534- return sp & ~0xf;
7535-}
7536-#endif
7537-
7538 unsigned long get_wchan(struct task_struct *p)
7539 {
7540 unsigned long stack_page, sp, ip;
7541diff --git a/arch/unicore32/include/asm/cache.h b/arch/unicore32/include/asm/cache.h
7542index ad8f795..2c7eec6 100644
7543--- a/arch/unicore32/include/asm/cache.h
7544+++ b/arch/unicore32/include/asm/cache.h
7545@@ -12,8 +12,10 @@
7546 #ifndef __UNICORE_CACHE_H__
7547 #define __UNICORE_CACHE_H__
7548
7549-#define L1_CACHE_SHIFT (5)
7550-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
7551+#include <linux/const.h>
7552+
7553+#define L1_CACHE_SHIFT 5
7554+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
7555
7556 /*
7557 * Memory returned by kmalloc() may be used for DMA, so we must make
7558diff --git a/arch/x86/Kconfig b/arch/x86/Kconfig
7559index 50a1d1f..c26369f 100644
7560--- a/arch/x86/Kconfig
7561+++ b/arch/x86/Kconfig
7562@@ -220,7 +220,7 @@ config X86_HT
7563
7564 config X86_32_LAZY_GS
7565 def_bool y
7566- depends on X86_32 && !CC_STACKPROTECTOR
7567+ depends on X86_32 && !CC_STACKPROTECTOR && !PAX_MEMORY_UDEREF
7568
7569 config ARCH_HWEIGHT_CFLAGS
7570 string
7571@@ -1049,7 +1049,7 @@ choice
7572
7573 config NOHIGHMEM
7574 bool "off"
7575- depends on !X86_NUMAQ
7576+ depends on !X86_NUMAQ && !(PAX_PAGEEXEC && PAX_ENABLE_PAE)
7577 ---help---
7578 Linux can use up to 64 Gigabytes of physical memory on x86 systems.
7579 However, the address space of 32-bit x86 processors is only 4
7580@@ -1086,7 +1086,7 @@ config NOHIGHMEM
7581
7582 config HIGHMEM4G
7583 bool "4GB"
7584- depends on !X86_NUMAQ
7585+ depends on !X86_NUMAQ && !(PAX_PAGEEXEC && PAX_ENABLE_PAE)
7586 ---help---
7587 Select this if you have a 32-bit processor and between 1 and 4
7588 gigabytes of physical RAM.
7589@@ -1140,7 +1140,7 @@ config PAGE_OFFSET
7590 hex
7591 default 0xB0000000 if VMSPLIT_3G_OPT
7592 default 0x80000000 if VMSPLIT_2G
7593- default 0x78000000 if VMSPLIT_2G_OPT
7594+ default 0x70000000 if VMSPLIT_2G_OPT
7595 default 0x40000000 if VMSPLIT_1G
7596 default 0xC0000000
7597 depends on X86_32
7598@@ -1528,6 +1528,7 @@ config SECCOMP
7599
7600 config CC_STACKPROTECTOR
7601 bool "Enable -fstack-protector buffer overflow detection"
7602+ depends on X86_64 || !PAX_MEMORY_UDEREF
7603 ---help---
7604 This option turns on the -fstack-protector GCC feature. This
7605 feature puts, at the beginning of functions, a canary value on
7606@@ -1585,6 +1586,7 @@ config KEXEC_JUMP
7607 config PHYSICAL_START
7608 hex "Physical address where the kernel is loaded" if (EXPERT || CRASH_DUMP)
7609 default "0x1000000"
7610+ range 0x400000 0x40000000
7611 ---help---
7612 This gives the physical address where the kernel is loaded.
7613
7614@@ -1648,6 +1650,7 @@ config X86_NEED_RELOCS
7615 config PHYSICAL_ALIGN
7616 hex "Alignment value to which kernel should be aligned" if X86_32
7617 default "0x1000000"
7618+ range 0x400000 0x1000000 if PAX_KERNEXEC
7619 range 0x2000 0x1000000
7620 ---help---
7621 This value puts the alignment restrictions on physical address
7622@@ -1679,9 +1682,10 @@ config HOTPLUG_CPU
7623 Say N if you want to disable CPU hotplug.
7624
7625 config COMPAT_VDSO
7626- def_bool y
7627+ def_bool n
7628 prompt "Compat VDSO support"
7629 depends on X86_32 || IA32_EMULATION
7630+ depends on !PAX_NOEXEC && !PAX_MEMORY_UDEREF
7631 ---help---
7632 Map the 32-bit VDSO to the predictable old-style address too.
7633
7634diff --git a/arch/x86/Kconfig.cpu b/arch/x86/Kconfig.cpu
7635index 706e12e..62e4feb 100644
7636--- a/arch/x86/Kconfig.cpu
7637+++ b/arch/x86/Kconfig.cpu
7638@@ -334,7 +334,7 @@ config X86_PPRO_FENCE
7639
7640 config X86_F00F_BUG
7641 def_bool y
7642- depends on M586MMX || M586TSC || M586 || M486 || M386
7643+ depends on (M586MMX || M586TSC || M586 || M486 || M386) && !PAX_KERNEXEC
7644
7645 config X86_INVD_BUG
7646 def_bool y
7647@@ -358,7 +358,7 @@ config X86_POPAD_OK
7648
7649 config X86_ALIGNMENT_16
7650 def_bool y
7651- depends on MWINCHIP3D || MWINCHIPC6 || MCYRIXIII || MELAN || MK6 || M586MMX || M586TSC || M586 || M486 || MVIAC3_2 || MGEODEGX1
7652+ depends on MWINCHIP3D || MWINCHIPC6 || MCYRIXIII || X86_ELAN || MK8 || MK7 || MK6 || MCORE2 || MPENTIUM4 || MPENTIUMIII || MPENTIUMII || M686 || M586MMX || M586TSC || M586 || M486 || MVIAC3_2 || MGEODEGX1
7653
7654 config X86_INTEL_USERCOPY
7655 def_bool y
7656@@ -404,7 +404,7 @@ config X86_CMPXCHG64
7657 # generates cmov.
7658 config X86_CMOV
7659 def_bool y
7660- depends on (MK8 || MK7 || MCORE2 || MPENTIUM4 || MPENTIUMM || MPENTIUMIII || MPENTIUMII || M686 || MVIAC3_2 || MVIAC7 || MCRUSOE || MEFFICEON || X86_64 || MATOM || MGEODE_LX)
7661+ depends on (MK8 || MK7 || MCORE2 || MPSC || MPENTIUM4 || MPENTIUMM || MPENTIUMIII || MPENTIUMII || M686 || MVIAC3_2 || MVIAC7 || MCRUSOE || MEFFICEON || X86_64 || MATOM || MGEODE_LX)
7662
7663 config X86_MINIMUM_CPU_FAMILY
7664 int
7665diff --git a/arch/x86/Kconfig.debug b/arch/x86/Kconfig.debug
7666index b322f12..652d0d9 100644
7667--- a/arch/x86/Kconfig.debug
7668+++ b/arch/x86/Kconfig.debug
7669@@ -84,7 +84,7 @@ config X86_PTDUMP
7670 config DEBUG_RODATA
7671 bool "Write protect kernel read-only data structures"
7672 default y
7673- depends on DEBUG_KERNEL
7674+ depends on DEBUG_KERNEL && BROKEN
7675 ---help---
7676 Mark the kernel read-only data as write-protected in the pagetables,
7677 in order to catch accidental (and incorrect) writes to such const
7678@@ -102,7 +102,7 @@ config DEBUG_RODATA_TEST
7679
7680 config DEBUG_SET_MODULE_RONX
7681 bool "Set loadable kernel module data as NX and text as RO"
7682- depends on MODULES
7683+ depends on MODULES && BROKEN
7684 ---help---
7685 This option helps catch unintended modifications to loadable
7686 kernel module's text and read-only data. It also prevents execution
7687@@ -294,7 +294,7 @@ config OPTIMIZE_INLINING
7688
7689 config DEBUG_STRICT_USER_COPY_CHECKS
7690 bool "Strict copy size checks"
7691- depends on DEBUG_KERNEL && !TRACE_BRANCH_PROFILING
7692+ depends on DEBUG_KERNEL && !TRACE_BRANCH_PROFILING && !PAX_SIZE_OVERFLOW
7693 ---help---
7694 Enabling this option turns a certain set of sanity checks for user
7695 copy operations into compile time failures.
7696diff --git a/arch/x86/Makefile b/arch/x86/Makefile
7697index 05afcca..b6ecb51 100644
7698--- a/arch/x86/Makefile
7699+++ b/arch/x86/Makefile
7700@@ -50,6 +50,7 @@ else
7701 UTS_MACHINE := x86_64
7702 CHECKFLAGS += -D__x86_64__ -m64
7703
7704+ biarch := $(call cc-option,-m64)
7705 KBUILD_AFLAGS += -m64
7706 KBUILD_CFLAGS += -m64
7707
7708@@ -229,3 +230,12 @@ define archhelp
7709 echo ' FDARGS="..." arguments for the booted kernel'
7710 echo ' FDINITRD=file initrd for the booted kernel'
7711 endef
7712+
7713+define OLD_LD
7714+
7715+*** ${VERSION}.${PATCHLEVEL} PaX kernels no longer build correctly with old versions of binutils.
7716+*** Please upgrade your binutils to 2.18 or newer
7717+endef
7718+
7719+archprepare:
7720+ $(if $(LDFLAGS_BUILD_ID),,$(error $(OLD_LD)))
7721diff --git a/arch/x86/boot/Makefile b/arch/x86/boot/Makefile
7722index f7535be..37db2d1 100644
7723--- a/arch/x86/boot/Makefile
7724+++ b/arch/x86/boot/Makefile
7725@@ -64,6 +64,9 @@ KBUILD_CFLAGS := $(LINUXINCLUDE) -g -Os -D_SETUP -D__KERNEL__ \
7726 $(call cc-option, -fno-stack-protector) \
7727 $(call cc-option, -mpreferred-stack-boundary=2)
7728 KBUILD_CFLAGS += $(call cc-option, -m32)
7729+ifdef CONSTIFY_PLUGIN
7730+KBUILD_CFLAGS += -fplugin-arg-constify_plugin-no-constify
7731+endif
7732 KBUILD_AFLAGS := $(KBUILD_CFLAGS) -D__ASSEMBLY__
7733 GCOV_PROFILE := n
7734
7735diff --git a/arch/x86/boot/bitops.h b/arch/x86/boot/bitops.h
7736index 878e4b9..20537ab 100644
7737--- a/arch/x86/boot/bitops.h
7738+++ b/arch/x86/boot/bitops.h
7739@@ -26,7 +26,7 @@ static inline int variable_test_bit(int nr, const void *addr)
7740 u8 v;
7741 const u32 *p = (const u32 *)addr;
7742
7743- asm("btl %2,%1; setc %0" : "=qm" (v) : "m" (*p), "Ir" (nr));
7744+ asm volatile("btl %2,%1; setc %0" : "=qm" (v) : "m" (*p), "Ir" (nr));
7745 return v;
7746 }
7747
7748@@ -37,7 +37,7 @@ static inline int variable_test_bit(int nr, const void *addr)
7749
7750 static inline void set_bit(int nr, void *addr)
7751 {
7752- asm("btsl %1,%0" : "+m" (*(u32 *)addr) : "Ir" (nr));
7753+ asm volatile("btsl %1,%0" : "+m" (*(u32 *)addr) : "Ir" (nr));
7754 }
7755
7756 #endif /* BOOT_BITOPS_H */
7757diff --git a/arch/x86/boot/boot.h b/arch/x86/boot/boot.h
7758index 18997e5..83d9c67 100644
7759--- a/arch/x86/boot/boot.h
7760+++ b/arch/x86/boot/boot.h
7761@@ -85,7 +85,7 @@ static inline void io_delay(void)
7762 static inline u16 ds(void)
7763 {
7764 u16 seg;
7765- asm("movw %%ds,%0" : "=rm" (seg));
7766+ asm volatile("movw %%ds,%0" : "=rm" (seg));
7767 return seg;
7768 }
7769
7770@@ -181,7 +181,7 @@ static inline void wrgs32(u32 v, addr_t addr)
7771 static inline int memcmp(const void *s1, const void *s2, size_t len)
7772 {
7773 u8 diff;
7774- asm("repe; cmpsb; setnz %0"
7775+ asm volatile("repe; cmpsb; setnz %0"
7776 : "=qm" (diff), "+D" (s1), "+S" (s2), "+c" (len));
7777 return diff;
7778 }
7779diff --git a/arch/x86/boot/compressed/Makefile b/arch/x86/boot/compressed/Makefile
7780index 8a84501..b2d165f 100644
7781--- a/arch/x86/boot/compressed/Makefile
7782+++ b/arch/x86/boot/compressed/Makefile
7783@@ -14,6 +14,9 @@ cflags-$(CONFIG_X86_64) := -mcmodel=small
7784 KBUILD_CFLAGS += $(cflags-y)
7785 KBUILD_CFLAGS += $(call cc-option,-ffreestanding)
7786 KBUILD_CFLAGS += $(call cc-option,-fno-stack-protector)
7787+ifdef CONSTIFY_PLUGIN
7788+KBUILD_CFLAGS += -fplugin-arg-constify_plugin-no-constify
7789+endif
7790
7791 KBUILD_AFLAGS := $(KBUILD_CFLAGS) -D__ASSEMBLY__
7792 GCOV_PROFILE := n
7793diff --git a/arch/x86/boot/compressed/eboot.c b/arch/x86/boot/compressed/eboot.c
7794index b3e0227..f2c02d5 100644
7795--- a/arch/x86/boot/compressed/eboot.c
7796+++ b/arch/x86/boot/compressed/eboot.c
7797@@ -142,7 +142,6 @@ again:
7798 *addr = max_addr;
7799 }
7800
7801-free_pool:
7802 efi_call_phys1(sys_table->boottime->free_pool, map);
7803
7804 fail:
7805@@ -206,7 +205,6 @@ static efi_status_t low_alloc(unsigned long size, unsigned long align,
7806 if (i == map_size / desc_size)
7807 status = EFI_NOT_FOUND;
7808
7809-free_pool:
7810 efi_call_phys1(sys_table->boottime->free_pool, map);
7811 fail:
7812 return status;
7813diff --git a/arch/x86/boot/compressed/head_32.S b/arch/x86/boot/compressed/head_32.S
7814index aa4aaf1..6656f2f 100644
7815--- a/arch/x86/boot/compressed/head_32.S
7816+++ b/arch/x86/boot/compressed/head_32.S
7817@@ -116,7 +116,7 @@ preferred_addr:
7818 notl %eax
7819 andl %eax, %ebx
7820 #else
7821- movl $LOAD_PHYSICAL_ADDR, %ebx
7822+ movl $____LOAD_PHYSICAL_ADDR, %ebx
7823 #endif
7824
7825 /* Target address to relocate to for decompression */
7826@@ -202,7 +202,7 @@ relocated:
7827 * and where it was actually loaded.
7828 */
7829 movl %ebp, %ebx
7830- subl $LOAD_PHYSICAL_ADDR, %ebx
7831+ subl $____LOAD_PHYSICAL_ADDR, %ebx
7832 jz 2f /* Nothing to be done if loaded at compiled addr. */
7833 /*
7834 * Process relocations.
7835@@ -210,8 +210,7 @@ relocated:
7836
7837 1: subl $4, %edi
7838 movl (%edi), %ecx
7839- testl %ecx, %ecx
7840- jz 2f
7841+ jecxz 2f
7842 addl %ebx, -__PAGE_OFFSET(%ebx, %ecx)
7843 jmp 1b
7844 2:
7845diff --git a/arch/x86/boot/compressed/head_64.S b/arch/x86/boot/compressed/head_64.S
7846index 2c4b171..e1fa5b1 100644
7847--- a/arch/x86/boot/compressed/head_64.S
7848+++ b/arch/x86/boot/compressed/head_64.S
7849@@ -91,7 +91,7 @@ ENTRY(startup_32)
7850 notl %eax
7851 andl %eax, %ebx
7852 #else
7853- movl $LOAD_PHYSICAL_ADDR, %ebx
7854+ movl $____LOAD_PHYSICAL_ADDR, %ebx
7855 #endif
7856
7857 /* Target address to relocate to for decompression */
7858@@ -273,7 +273,7 @@ preferred_addr:
7859 notq %rax
7860 andq %rax, %rbp
7861 #else
7862- movq $LOAD_PHYSICAL_ADDR, %rbp
7863+ movq $____LOAD_PHYSICAL_ADDR, %rbp
7864 #endif
7865
7866 /* Target address to relocate to for decompression */
7867diff --git a/arch/x86/boot/compressed/misc.c b/arch/x86/boot/compressed/misc.c
7868index 88f7ff6..ed695dd 100644
7869--- a/arch/x86/boot/compressed/misc.c
7870+++ b/arch/x86/boot/compressed/misc.c
7871@@ -303,7 +303,7 @@ static void parse_elf(void *output)
7872 case PT_LOAD:
7873 #ifdef CONFIG_RELOCATABLE
7874 dest = output;
7875- dest += (phdr->p_paddr - LOAD_PHYSICAL_ADDR);
7876+ dest += (phdr->p_paddr - ____LOAD_PHYSICAL_ADDR);
7877 #else
7878 dest = (void *)(phdr->p_paddr);
7879 #endif
7880@@ -352,7 +352,7 @@ asmlinkage void decompress_kernel(void *rmode, memptr heap,
7881 error("Destination address too large");
7882 #endif
7883 #ifndef CONFIG_RELOCATABLE
7884- if ((unsigned long)output != LOAD_PHYSICAL_ADDR)
7885+ if ((unsigned long)output != ____LOAD_PHYSICAL_ADDR)
7886 error("Wrong destination address");
7887 #endif
7888
7889diff --git a/arch/x86/boot/cpucheck.c b/arch/x86/boot/cpucheck.c
7890index 4d3ff03..e4972ff 100644
7891--- a/arch/x86/boot/cpucheck.c
7892+++ b/arch/x86/boot/cpucheck.c
7893@@ -74,7 +74,7 @@ static int has_fpu(void)
7894 u16 fcw = -1, fsw = -1;
7895 u32 cr0;
7896
7897- asm("movl %%cr0,%0" : "=r" (cr0));
7898+ asm volatile("movl %%cr0,%0" : "=r" (cr0));
7899 if (cr0 & (X86_CR0_EM|X86_CR0_TS)) {
7900 cr0 &= ~(X86_CR0_EM|X86_CR0_TS);
7901 asm volatile("movl %0,%%cr0" : : "r" (cr0));
7902@@ -90,7 +90,7 @@ static int has_eflag(u32 mask)
7903 {
7904 u32 f0, f1;
7905
7906- asm("pushfl ; "
7907+ asm volatile("pushfl ; "
7908 "pushfl ; "
7909 "popl %0 ; "
7910 "movl %0,%1 ; "
7911@@ -115,7 +115,7 @@ static void get_flags(void)
7912 set_bit(X86_FEATURE_FPU, cpu.flags);
7913
7914 if (has_eflag(X86_EFLAGS_ID)) {
7915- asm("cpuid"
7916+ asm volatile("cpuid"
7917 : "=a" (max_intel_level),
7918 "=b" (cpu_vendor[0]),
7919 "=d" (cpu_vendor[1]),
7920@@ -124,7 +124,7 @@ static void get_flags(void)
7921
7922 if (max_intel_level >= 0x00000001 &&
7923 max_intel_level <= 0x0000ffff) {
7924- asm("cpuid"
7925+ asm volatile("cpuid"
7926 : "=a" (tfms),
7927 "=c" (cpu.flags[4]),
7928 "=d" (cpu.flags[0])
7929@@ -136,7 +136,7 @@ static void get_flags(void)
7930 cpu.model += ((tfms >> 16) & 0xf) << 4;
7931 }
7932
7933- asm("cpuid"
7934+ asm volatile("cpuid"
7935 : "=a" (max_amd_level)
7936 : "a" (0x80000000)
7937 : "ebx", "ecx", "edx");
7938@@ -144,7 +144,7 @@ static void get_flags(void)
7939 if (max_amd_level >= 0x80000001 &&
7940 max_amd_level <= 0x8000ffff) {
7941 u32 eax = 0x80000001;
7942- asm("cpuid"
7943+ asm volatile("cpuid"
7944 : "+a" (eax),
7945 "=c" (cpu.flags[6]),
7946 "=d" (cpu.flags[1])
7947@@ -203,9 +203,9 @@ int check_cpu(int *cpu_level_ptr, int *req_level_ptr, u32 **err_flags_ptr)
7948 u32 ecx = MSR_K7_HWCR;
7949 u32 eax, edx;
7950
7951- asm("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
7952+ asm volatile("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
7953 eax &= ~(1 << 15);
7954- asm("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
7955+ asm volatile("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
7956
7957 get_flags(); /* Make sure it really did something */
7958 err = check_flags();
7959@@ -218,9 +218,9 @@ int check_cpu(int *cpu_level_ptr, int *req_level_ptr, u32 **err_flags_ptr)
7960 u32 ecx = MSR_VIA_FCR;
7961 u32 eax, edx;
7962
7963- asm("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
7964+ asm volatile("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
7965 eax |= (1<<1)|(1<<7);
7966- asm("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
7967+ asm volatile("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
7968
7969 set_bit(X86_FEATURE_CX8, cpu.flags);
7970 err = check_flags();
7971@@ -231,12 +231,12 @@ int check_cpu(int *cpu_level_ptr, int *req_level_ptr, u32 **err_flags_ptr)
7972 u32 eax, edx;
7973 u32 level = 1;
7974
7975- asm("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
7976- asm("wrmsr" : : "a" (~0), "d" (edx), "c" (ecx));
7977- asm("cpuid"
7978+ asm volatile("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
7979+ asm volatile("wrmsr" : : "a" (~0), "d" (edx), "c" (ecx));
7980+ asm volatile("cpuid"
7981 : "+a" (level), "=d" (cpu.flags[0])
7982 : : "ecx", "ebx");
7983- asm("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
7984+ asm volatile("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
7985
7986 err = check_flags();
7987 }
7988diff --git a/arch/x86/boot/header.S b/arch/x86/boot/header.S
7989index b4e15dd..8ac59ce 100644
7990--- a/arch/x86/boot/header.S
7991+++ b/arch/x86/boot/header.S
7992@@ -391,10 +391,14 @@ setup_data: .quad 0 # 64-bit physical pointer to
7993 # single linked list of
7994 # struct setup_data
7995
7996-pref_address: .quad LOAD_PHYSICAL_ADDR # preferred load addr
7997+pref_address: .quad ____LOAD_PHYSICAL_ADDR # preferred load addr
7998
7999 #define ZO_INIT_SIZE (ZO__end - ZO_startup_32 + ZO_z_extract_offset)
8000+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
8001+#define VO_INIT_SIZE (VO__end - VO__text - __PAGE_OFFSET - ____LOAD_PHYSICAL_ADDR)
8002+#else
8003 #define VO_INIT_SIZE (VO__end - VO__text)
8004+#endif
8005 #if ZO_INIT_SIZE > VO_INIT_SIZE
8006 #define INIT_SIZE ZO_INIT_SIZE
8007 #else
8008diff --git a/arch/x86/boot/memory.c b/arch/x86/boot/memory.c
8009index db75d07..8e6d0af 100644
8010--- a/arch/x86/boot/memory.c
8011+++ b/arch/x86/boot/memory.c
8012@@ -19,7 +19,7 @@
8013
8014 static int detect_memory_e820(void)
8015 {
8016- int count = 0;
8017+ unsigned int count = 0;
8018 struct biosregs ireg, oreg;
8019 struct e820entry *desc = boot_params.e820_map;
8020 static struct e820entry buf; /* static so it is zeroed */
8021diff --git a/arch/x86/boot/video-vesa.c b/arch/x86/boot/video-vesa.c
8022index 11e8c6e..fdbb1ed 100644
8023--- a/arch/x86/boot/video-vesa.c
8024+++ b/arch/x86/boot/video-vesa.c
8025@@ -200,6 +200,7 @@ static void vesa_store_pm_info(void)
8026
8027 boot_params.screen_info.vesapm_seg = oreg.es;
8028 boot_params.screen_info.vesapm_off = oreg.di;
8029+ boot_params.screen_info.vesapm_size = oreg.cx;
8030 }
8031
8032 /*
8033diff --git a/arch/x86/boot/video.c b/arch/x86/boot/video.c
8034index 43eda28..5ab5fdb 100644
8035--- a/arch/x86/boot/video.c
8036+++ b/arch/x86/boot/video.c
8037@@ -96,7 +96,7 @@ static void store_mode_params(void)
8038 static unsigned int get_entry(void)
8039 {
8040 char entry_buf[4];
8041- int i, len = 0;
8042+ unsigned int i, len = 0;
8043 int key;
8044 unsigned int v;
8045
8046diff --git a/arch/x86/crypto/aes-x86_64-asm_64.S b/arch/x86/crypto/aes-x86_64-asm_64.S
8047index 5b577d5..3c1fed4 100644
8048--- a/arch/x86/crypto/aes-x86_64-asm_64.S
8049+++ b/arch/x86/crypto/aes-x86_64-asm_64.S
8050@@ -8,6 +8,8 @@
8051 * including this sentence is retained in full.
8052 */
8053
8054+#include <asm/alternative-asm.h>
8055+
8056 .extern crypto_ft_tab
8057 .extern crypto_it_tab
8058 .extern crypto_fl_tab
8059@@ -71,6 +73,8 @@ FUNC: movq r1,r2; \
8060 je B192; \
8061 leaq 32(r9),r9;
8062
8063+#define ret pax_force_retaddr 0, 1; ret
8064+
8065 #define epilogue(r1,r2,r3,r4,r5,r6,r7,r8,r9) \
8066 movq r1,r2; \
8067 movq r3,r4; \
8068diff --git a/arch/x86/crypto/aesni-intel_asm.S b/arch/x86/crypto/aesni-intel_asm.S
8069index 3470624..201259d 100644
8070--- a/arch/x86/crypto/aesni-intel_asm.S
8071+++ b/arch/x86/crypto/aesni-intel_asm.S
8072@@ -31,6 +31,7 @@
8073
8074 #include <linux/linkage.h>
8075 #include <asm/inst.h>
8076+#include <asm/alternative-asm.h>
8077
8078 #ifdef __x86_64__
8079 .data
8080@@ -1436,7 +1437,9 @@ _return_T_done_decrypt:
8081 pop %r14
8082 pop %r13
8083 pop %r12
8084+ pax_force_retaddr 0, 1
8085 ret
8086+ENDPROC(aesni_gcm_dec)
8087
8088
8089 /*****************************************************************************
8090@@ -1699,7 +1702,9 @@ _return_T_done_encrypt:
8091 pop %r14
8092 pop %r13
8093 pop %r12
8094+ pax_force_retaddr 0, 1
8095 ret
8096+ENDPROC(aesni_gcm_enc)
8097
8098 #endif
8099
8100@@ -1714,6 +1719,7 @@ _key_expansion_256a:
8101 pxor %xmm1, %xmm0
8102 movaps %xmm0, (TKEYP)
8103 add $0x10, TKEYP
8104+ pax_force_retaddr_bts
8105 ret
8106
8107 .align 4
8108@@ -1738,6 +1744,7 @@ _key_expansion_192a:
8109 shufps $0b01001110, %xmm2, %xmm1
8110 movaps %xmm1, 0x10(TKEYP)
8111 add $0x20, TKEYP
8112+ pax_force_retaddr_bts
8113 ret
8114
8115 .align 4
8116@@ -1757,6 +1764,7 @@ _key_expansion_192b:
8117
8118 movaps %xmm0, (TKEYP)
8119 add $0x10, TKEYP
8120+ pax_force_retaddr_bts
8121 ret
8122
8123 .align 4
8124@@ -1769,6 +1777,7 @@ _key_expansion_256b:
8125 pxor %xmm1, %xmm2
8126 movaps %xmm2, (TKEYP)
8127 add $0x10, TKEYP
8128+ pax_force_retaddr_bts
8129 ret
8130
8131 /*
8132@@ -1881,7 +1890,9 @@ ENTRY(aesni_set_key)
8133 #ifndef __x86_64__
8134 popl KEYP
8135 #endif
8136+ pax_force_retaddr 0, 1
8137 ret
8138+ENDPROC(aesni_set_key)
8139
8140 /*
8141 * void aesni_enc(struct crypto_aes_ctx *ctx, u8 *dst, const u8 *src)
8142@@ -1902,7 +1913,9 @@ ENTRY(aesni_enc)
8143 popl KLEN
8144 popl KEYP
8145 #endif
8146+ pax_force_retaddr 0, 1
8147 ret
8148+ENDPROC(aesni_enc)
8149
8150 /*
8151 * _aesni_enc1: internal ABI
8152@@ -1959,6 +1972,7 @@ _aesni_enc1:
8153 AESENC KEY STATE
8154 movaps 0x70(TKEYP), KEY
8155 AESENCLAST KEY STATE
8156+ pax_force_retaddr_bts
8157 ret
8158
8159 /*
8160@@ -2067,6 +2081,7 @@ _aesni_enc4:
8161 AESENCLAST KEY STATE2
8162 AESENCLAST KEY STATE3
8163 AESENCLAST KEY STATE4
8164+ pax_force_retaddr_bts
8165 ret
8166
8167 /*
8168@@ -2089,7 +2104,9 @@ ENTRY(aesni_dec)
8169 popl KLEN
8170 popl KEYP
8171 #endif
8172+ pax_force_retaddr 0, 1
8173 ret
8174+ENDPROC(aesni_dec)
8175
8176 /*
8177 * _aesni_dec1: internal ABI
8178@@ -2146,6 +2163,7 @@ _aesni_dec1:
8179 AESDEC KEY STATE
8180 movaps 0x70(TKEYP), KEY
8181 AESDECLAST KEY STATE
8182+ pax_force_retaddr_bts
8183 ret
8184
8185 /*
8186@@ -2254,6 +2272,7 @@ _aesni_dec4:
8187 AESDECLAST KEY STATE2
8188 AESDECLAST KEY STATE3
8189 AESDECLAST KEY STATE4
8190+ pax_force_retaddr_bts
8191 ret
8192
8193 /*
8194@@ -2311,7 +2330,9 @@ ENTRY(aesni_ecb_enc)
8195 popl KEYP
8196 popl LEN
8197 #endif
8198+ pax_force_retaddr 0, 1
8199 ret
8200+ENDPROC(aesni_ecb_enc)
8201
8202 /*
8203 * void aesni_ecb_dec(struct crypto_aes_ctx *ctx, const u8 *dst, u8 *src,
8204@@ -2369,7 +2390,9 @@ ENTRY(aesni_ecb_dec)
8205 popl KEYP
8206 popl LEN
8207 #endif
8208+ pax_force_retaddr 0, 1
8209 ret
8210+ENDPROC(aesni_ecb_dec)
8211
8212 /*
8213 * void aesni_cbc_enc(struct crypto_aes_ctx *ctx, const u8 *dst, u8 *src,
8214@@ -2410,7 +2433,9 @@ ENTRY(aesni_cbc_enc)
8215 popl LEN
8216 popl IVP
8217 #endif
8218+ pax_force_retaddr 0, 1
8219 ret
8220+ENDPROC(aesni_cbc_enc)
8221
8222 /*
8223 * void aesni_cbc_dec(struct crypto_aes_ctx *ctx, const u8 *dst, u8 *src,
8224@@ -2500,7 +2525,9 @@ ENTRY(aesni_cbc_dec)
8225 popl LEN
8226 popl IVP
8227 #endif
8228+ pax_force_retaddr 0, 1
8229 ret
8230+ENDPROC(aesni_cbc_dec)
8231
8232 #ifdef __x86_64__
8233 .align 16
8234@@ -2526,6 +2553,7 @@ _aesni_inc_init:
8235 mov $1, TCTR_LOW
8236 MOVQ_R64_XMM TCTR_LOW INC
8237 MOVQ_R64_XMM CTR TCTR_LOW
8238+ pax_force_retaddr_bts
8239 ret
8240
8241 /*
8242@@ -2554,6 +2582,7 @@ _aesni_inc:
8243 .Linc_low:
8244 movaps CTR, IV
8245 PSHUFB_XMM BSWAP_MASK IV
8246+ pax_force_retaddr_bts
8247 ret
8248
8249 /*
8250@@ -2614,5 +2643,7 @@ ENTRY(aesni_ctr_enc)
8251 .Lctr_enc_ret:
8252 movups IV, (IVP)
8253 .Lctr_enc_just_ret:
8254+ pax_force_retaddr 0, 1
8255 ret
8256+ENDPROC(aesni_ctr_enc)
8257 #endif
8258diff --git a/arch/x86/crypto/blowfish-x86_64-asm_64.S b/arch/x86/crypto/blowfish-x86_64-asm_64.S
8259index 391d245..67f35c2 100644
8260--- a/arch/x86/crypto/blowfish-x86_64-asm_64.S
8261+++ b/arch/x86/crypto/blowfish-x86_64-asm_64.S
8262@@ -20,6 +20,8 @@
8263 *
8264 */
8265
8266+#include <asm/alternative-asm.h>
8267+
8268 .file "blowfish-x86_64-asm.S"
8269 .text
8270
8271@@ -151,9 +153,11 @@ __blowfish_enc_blk:
8272 jnz __enc_xor;
8273
8274 write_block();
8275+ pax_force_retaddr 0, 1
8276 ret;
8277 __enc_xor:
8278 xor_block();
8279+ pax_force_retaddr 0, 1
8280 ret;
8281
8282 .align 8
8283@@ -188,6 +192,7 @@ blowfish_dec_blk:
8284
8285 movq %r11, %rbp;
8286
8287+ pax_force_retaddr 0, 1
8288 ret;
8289
8290 /**********************************************************************
8291@@ -342,6 +347,7 @@ __blowfish_enc_blk_4way:
8292
8293 popq %rbx;
8294 popq %rbp;
8295+ pax_force_retaddr 0, 1
8296 ret;
8297
8298 __enc_xor4:
8299@@ -349,6 +355,7 @@ __enc_xor4:
8300
8301 popq %rbx;
8302 popq %rbp;
8303+ pax_force_retaddr 0, 1
8304 ret;
8305
8306 .align 8
8307@@ -386,5 +393,6 @@ blowfish_dec_blk_4way:
8308 popq %rbx;
8309 popq %rbp;
8310
8311+ pax_force_retaddr 0, 1
8312 ret;
8313
8314diff --git a/arch/x86/crypto/camellia-x86_64-asm_64.S b/arch/x86/crypto/camellia-x86_64-asm_64.S
8315index 0b33743..7a56206 100644
8316--- a/arch/x86/crypto/camellia-x86_64-asm_64.S
8317+++ b/arch/x86/crypto/camellia-x86_64-asm_64.S
8318@@ -20,6 +20,8 @@
8319 *
8320 */
8321
8322+#include <asm/alternative-asm.h>
8323+
8324 .file "camellia-x86_64-asm_64.S"
8325 .text
8326
8327@@ -229,12 +231,14 @@ __enc_done:
8328 enc_outunpack(mov, RT1);
8329
8330 movq RRBP, %rbp;
8331+ pax_force_retaddr 0, 1
8332 ret;
8333
8334 __enc_xor:
8335 enc_outunpack(xor, RT1);
8336
8337 movq RRBP, %rbp;
8338+ pax_force_retaddr 0, 1
8339 ret;
8340
8341 .global camellia_dec_blk;
8342@@ -275,6 +279,7 @@ __dec_rounds16:
8343 dec_outunpack();
8344
8345 movq RRBP, %rbp;
8346+ pax_force_retaddr 0, 1
8347 ret;
8348
8349 /**********************************************************************
8350@@ -468,6 +473,7 @@ __enc2_done:
8351
8352 movq RRBP, %rbp;
8353 popq %rbx;
8354+ pax_force_retaddr 0, 1
8355 ret;
8356
8357 __enc2_xor:
8358@@ -475,6 +481,7 @@ __enc2_xor:
8359
8360 movq RRBP, %rbp;
8361 popq %rbx;
8362+ pax_force_retaddr 0, 1
8363 ret;
8364
8365 .global camellia_dec_blk_2way;
8366@@ -517,4 +524,5 @@ __dec2_rounds16:
8367
8368 movq RRBP, %rbp;
8369 movq RXOR, %rbx;
8370+ pax_force_retaddr 0, 1
8371 ret;
8372diff --git a/arch/x86/crypto/salsa20-x86_64-asm_64.S b/arch/x86/crypto/salsa20-x86_64-asm_64.S
8373index 6214a9b..1f4fc9a 100644
8374--- a/arch/x86/crypto/salsa20-x86_64-asm_64.S
8375+++ b/arch/x86/crypto/salsa20-x86_64-asm_64.S
8376@@ -1,3 +1,5 @@
8377+#include <asm/alternative-asm.h>
8378+
8379 # enter ECRYPT_encrypt_bytes
8380 .text
8381 .p2align 5
8382@@ -790,6 +792,7 @@ ECRYPT_encrypt_bytes:
8383 add %r11,%rsp
8384 mov %rdi,%rax
8385 mov %rsi,%rdx
8386+ pax_force_retaddr 0, 1
8387 ret
8388 # bytesatleast65:
8389 ._bytesatleast65:
8390@@ -891,6 +894,7 @@ ECRYPT_keysetup:
8391 add %r11,%rsp
8392 mov %rdi,%rax
8393 mov %rsi,%rdx
8394+ pax_force_retaddr
8395 ret
8396 # enter ECRYPT_ivsetup
8397 .text
8398@@ -917,4 +921,5 @@ ECRYPT_ivsetup:
8399 add %r11,%rsp
8400 mov %rdi,%rax
8401 mov %rsi,%rdx
8402+ pax_force_retaddr
8403 ret
8404diff --git a/arch/x86/crypto/serpent-avx-x86_64-asm_64.S b/arch/x86/crypto/serpent-avx-x86_64-asm_64.S
8405index 504106b..4e50951 100644
8406--- a/arch/x86/crypto/serpent-avx-x86_64-asm_64.S
8407+++ b/arch/x86/crypto/serpent-avx-x86_64-asm_64.S
8408@@ -24,6 +24,8 @@
8409 *
8410 */
8411
8412+#include <asm/alternative-asm.h>
8413+
8414 .file "serpent-avx-x86_64-asm_64.S"
8415 .text
8416
8417@@ -638,12 +640,14 @@ __serpent_enc_blk_8way_avx:
8418 write_blocks(%rsi, RA1, RB1, RC1, RD1, RK0, RK1, RK2);
8419 write_blocks(%rax, RA2, RB2, RC2, RD2, RK0, RK1, RK2);
8420
8421+ pax_force_retaddr
8422 ret;
8423
8424 __enc_xor8:
8425 xor_blocks(%rsi, RA1, RB1, RC1, RD1, RK0, RK1, RK2);
8426 xor_blocks(%rax, RA2, RB2, RC2, RD2, RK0, RK1, RK2);
8427
8428+ pax_force_retaddr
8429 ret;
8430
8431 .align 8
8432@@ -701,4 +705,5 @@ serpent_dec_blk_8way_avx:
8433 write_blocks(%rsi, RC1, RD1, RB1, RE1, RK0, RK1, RK2);
8434 write_blocks(%rax, RC2, RD2, RB2, RE2, RK0, RK1, RK2);
8435
8436+ pax_force_retaddr
8437 ret;
8438diff --git a/arch/x86/crypto/serpent-sse2-x86_64-asm_64.S b/arch/x86/crypto/serpent-sse2-x86_64-asm_64.S
8439index 3ee1ff0..cbc568b 100644
8440--- a/arch/x86/crypto/serpent-sse2-x86_64-asm_64.S
8441+++ b/arch/x86/crypto/serpent-sse2-x86_64-asm_64.S
8442@@ -24,6 +24,8 @@
8443 *
8444 */
8445
8446+#include <asm/alternative-asm.h>
8447+
8448 .file "serpent-sse2-x86_64-asm_64.S"
8449 .text
8450
8451@@ -692,12 +694,14 @@ __serpent_enc_blk_8way:
8452 write_blocks(%rsi, RA1, RB1, RC1, RD1, RK0, RK1, RK2);
8453 write_blocks(%rax, RA2, RB2, RC2, RD2, RK0, RK1, RK2);
8454
8455+ pax_force_retaddr
8456 ret;
8457
8458 __enc_xor8:
8459 xor_blocks(%rsi, RA1, RB1, RC1, RD1, RK0, RK1, RK2);
8460 xor_blocks(%rax, RA2, RB2, RC2, RD2, RK0, RK1, RK2);
8461
8462+ pax_force_retaddr
8463 ret;
8464
8465 .align 8
8466@@ -755,4 +759,5 @@ serpent_dec_blk_8way:
8467 write_blocks(%rsi, RC1, RD1, RB1, RE1, RK0, RK1, RK2);
8468 write_blocks(%rax, RC2, RD2, RB2, RE2, RK0, RK1, RK2);
8469
8470+ pax_force_retaddr
8471 ret;
8472diff --git a/arch/x86/crypto/sha1_ssse3_asm.S b/arch/x86/crypto/sha1_ssse3_asm.S
8473index 49d6987..df66bd4 100644
8474--- a/arch/x86/crypto/sha1_ssse3_asm.S
8475+++ b/arch/x86/crypto/sha1_ssse3_asm.S
8476@@ -28,6 +28,8 @@
8477 * (at your option) any later version.
8478 */
8479
8480+#include <asm/alternative-asm.h>
8481+
8482 #define CTX %rdi // arg1
8483 #define BUF %rsi // arg2
8484 #define CNT %rdx // arg3
8485@@ -104,6 +106,7 @@
8486 pop %r12
8487 pop %rbp
8488 pop %rbx
8489+ pax_force_retaddr 0, 1
8490 ret
8491
8492 .size \name, .-\name
8493diff --git a/arch/x86/crypto/twofish-avx-x86_64-asm_64.S b/arch/x86/crypto/twofish-avx-x86_64-asm_64.S
8494index 35f4557..16b379f 100644
8495--- a/arch/x86/crypto/twofish-avx-x86_64-asm_64.S
8496+++ b/arch/x86/crypto/twofish-avx-x86_64-asm_64.S
8497@@ -21,6 +21,8 @@
8498 *
8499 */
8500
8501+#include <asm/alternative-asm.h>
8502+
8503 .file "twofish-avx-x86_64-asm_64.S"
8504 .text
8505
8506@@ -250,12 +252,14 @@ __twofish_enc_blk_8way:
8507 outunpack_blocks(%rsi, RC1, RD1, RA1, RB1, RK1, RX, RY, RK2);
8508 outunpack_blocks(%rax, RC2, RD2, RA2, RB2, RK1, RX, RY, RK2);
8509
8510+ pax_force_retaddr
8511 ret;
8512
8513 __enc_xor8:
8514 outunpack_xor_blocks(%rsi, RC1, RD1, RA1, RB1, RK1, RX, RY, RK2);
8515 outunpack_xor_blocks(%rax, RC2, RD2, RA2, RB2, RK1, RX, RY, RK2);
8516
8517+ pax_force_retaddr
8518 ret;
8519
8520 .align 8
8521@@ -297,4 +301,5 @@ twofish_dec_blk_8way:
8522 outunpack_blocks(%rsi, RA1, RB1, RC1, RD1, RK1, RX, RY, RK2);
8523 outunpack_blocks(%rax, RA2, RB2, RC2, RD2, RK1, RX, RY, RK2);
8524
8525+ pax_force_retaddr
8526 ret;
8527diff --git a/arch/x86/crypto/twofish-x86_64-asm_64-3way.S b/arch/x86/crypto/twofish-x86_64-asm_64-3way.S
8528index 5b012a2..36d5364 100644
8529--- a/arch/x86/crypto/twofish-x86_64-asm_64-3way.S
8530+++ b/arch/x86/crypto/twofish-x86_64-asm_64-3way.S
8531@@ -20,6 +20,8 @@
8532 *
8533 */
8534
8535+#include <asm/alternative-asm.h>
8536+
8537 .file "twofish-x86_64-asm-3way.S"
8538 .text
8539
8540@@ -260,6 +262,7 @@ __twofish_enc_blk_3way:
8541 popq %r13;
8542 popq %r14;
8543 popq %r15;
8544+ pax_force_retaddr 0, 1
8545 ret;
8546
8547 __enc_xor3:
8548@@ -271,6 +274,7 @@ __enc_xor3:
8549 popq %r13;
8550 popq %r14;
8551 popq %r15;
8552+ pax_force_retaddr 0, 1
8553 ret;
8554
8555 .global twofish_dec_blk_3way
8556@@ -312,5 +316,6 @@ twofish_dec_blk_3way:
8557 popq %r13;
8558 popq %r14;
8559 popq %r15;
8560+ pax_force_retaddr 0, 1
8561 ret;
8562
8563diff --git a/arch/x86/crypto/twofish-x86_64-asm_64.S b/arch/x86/crypto/twofish-x86_64-asm_64.S
8564index 7bcf3fc..f53832f 100644
8565--- a/arch/x86/crypto/twofish-x86_64-asm_64.S
8566+++ b/arch/x86/crypto/twofish-x86_64-asm_64.S
8567@@ -21,6 +21,7 @@
8568 .text
8569
8570 #include <asm/asm-offsets.h>
8571+#include <asm/alternative-asm.h>
8572
8573 #define a_offset 0
8574 #define b_offset 4
8575@@ -268,6 +269,7 @@ twofish_enc_blk:
8576
8577 popq R1
8578 movq $1,%rax
8579+ pax_force_retaddr 0, 1
8580 ret
8581
8582 twofish_dec_blk:
8583@@ -319,4 +321,5 @@ twofish_dec_blk:
8584
8585 popq R1
8586 movq $1,%rax
8587+ pax_force_retaddr 0, 1
8588 ret
8589diff --git a/arch/x86/ia32/ia32_aout.c b/arch/x86/ia32/ia32_aout.c
8590index 07b3a68..bd2a388 100644
8591--- a/arch/x86/ia32/ia32_aout.c
8592+++ b/arch/x86/ia32/ia32_aout.c
8593@@ -159,6 +159,8 @@ static int aout_core_dump(long signr, struct pt_regs *regs, struct file *file,
8594 unsigned long dump_start, dump_size;
8595 struct user32 dump;
8596
8597+ memset(&dump, 0, sizeof(dump));
8598+
8599 fs = get_fs();
8600 set_fs(KERNEL_DS);
8601 has_dumped = 1;
8602diff --git a/arch/x86/ia32/ia32_signal.c b/arch/x86/ia32/ia32_signal.c
8603index 673ac9b..7a8c5df 100644
8604--- a/arch/x86/ia32/ia32_signal.c
8605+++ b/arch/x86/ia32/ia32_signal.c
8606@@ -162,7 +162,7 @@ asmlinkage long sys32_sigaltstack(const stack_ia32_t __user *uss_ptr,
8607 }
8608 seg = get_fs();
8609 set_fs(KERNEL_DS);
8610- ret = do_sigaltstack(uss_ptr ? &uss : NULL, &uoss, regs->sp);
8611+ ret = do_sigaltstack(uss_ptr ? (const stack_t __force_user *)&uss : NULL, (stack_t __force_user *)&uoss, regs->sp);
8612 set_fs(seg);
8613 if (ret >= 0 && uoss_ptr) {
8614 if (!access_ok(VERIFY_WRITE, uoss_ptr, sizeof(stack_ia32_t)))
8615@@ -361,7 +361,7 @@ static int ia32_setup_sigcontext(struct sigcontext_ia32 __user *sc,
8616 */
8617 static void __user *get_sigframe(struct k_sigaction *ka, struct pt_regs *regs,
8618 size_t frame_size,
8619- void **fpstate)
8620+ void __user **fpstate)
8621 {
8622 unsigned long sp;
8623
8624@@ -382,7 +382,7 @@ static void __user *get_sigframe(struct k_sigaction *ka, struct pt_regs *regs,
8625
8626 if (used_math()) {
8627 sp = sp - sig_xstate_ia32_size;
8628- *fpstate = (struct _fpstate_ia32 *) sp;
8629+ *fpstate = (struct _fpstate_ia32 __user *) sp;
8630 if (save_i387_xstate_ia32(*fpstate) < 0)
8631 return (void __user *) -1L;
8632 }
8633@@ -390,7 +390,7 @@ static void __user *get_sigframe(struct k_sigaction *ka, struct pt_regs *regs,
8634 sp -= frame_size;
8635 /* Align the stack pointer according to the i386 ABI,
8636 * i.e. so that on function entry ((sp + 4) & 15) == 0. */
8637- sp = ((sp + 4) & -16ul) - 4;
8638+ sp = ((sp - 12) & -16ul) - 4;
8639 return (void __user *) sp;
8640 }
8641
8642@@ -448,7 +448,7 @@ int ia32_setup_frame(int sig, struct k_sigaction *ka,
8643 * These are actually not used anymore, but left because some
8644 * gdb versions depend on them as a marker.
8645 */
8646- put_user_ex(*((u64 *)&code), (u64 *)frame->retcode);
8647+ put_user_ex(*((const u64 *)&code), (u64 __user *)frame->retcode);
8648 } put_user_catch(err);
8649
8650 if (err)
8651@@ -490,7 +490,7 @@ int ia32_setup_rt_frame(int sig, struct k_sigaction *ka, siginfo_t *info,
8652 0xb8,
8653 __NR_ia32_rt_sigreturn,
8654 0x80cd,
8655- 0,
8656+ 0
8657 };
8658
8659 frame = get_sigframe(ka, regs, sizeof(*frame), &fpstate);
8660@@ -520,16 +520,18 @@ int ia32_setup_rt_frame(int sig, struct k_sigaction *ka, siginfo_t *info,
8661
8662 if (ka->sa.sa_flags & SA_RESTORER)
8663 restorer = ka->sa.sa_restorer;
8664+ else if (current->mm->context.vdso)
8665+ /* Return stub is in 32bit vsyscall page */
8666+ restorer = VDSO32_SYMBOL(current->mm->context.vdso, rt_sigreturn);
8667 else
8668- restorer = VDSO32_SYMBOL(current->mm->context.vdso,
8669- rt_sigreturn);
8670+ restorer = &frame->retcode;
8671 put_user_ex(ptr_to_compat(restorer), &frame->pretcode);
8672
8673 /*
8674 * Not actually used anymore, but left because some gdb
8675 * versions need it.
8676 */
8677- put_user_ex(*((u64 *)&code), (u64 *)frame->retcode);
8678+ put_user_ex(*((const u64 *)&code), (u64 __user *)frame->retcode);
8679 } put_user_catch(err);
8680
8681 if (err)
8682diff --git a/arch/x86/ia32/ia32entry.S b/arch/x86/ia32/ia32entry.S
8683index 20e5f7b..f33c779 100644
8684--- a/arch/x86/ia32/ia32entry.S
8685+++ b/arch/x86/ia32/ia32entry.S
8686@@ -14,8 +14,10 @@
8687 #include <asm/segment.h>
8688 #include <asm/irqflags.h>
8689 #include <asm/asm.h>
8690+#include <asm/pgtable.h>
8691 #include <linux/linkage.h>
8692 #include <linux/err.h>
8693+#include <asm/alternative-asm.h>
8694
8695 /* Avoid __ASSEMBLER__'ifying <linux/audit.h> just for this. */
8696 #include <linux/elf-em.h>
8697@@ -95,6 +97,32 @@ ENTRY(native_irq_enable_sysexit)
8698 ENDPROC(native_irq_enable_sysexit)
8699 #endif
8700
8701+ .macro pax_enter_kernel_user
8702+ pax_set_fptr_mask
8703+#ifdef CONFIG_PAX_MEMORY_UDEREF
8704+ call pax_enter_kernel_user
8705+#endif
8706+ .endm
8707+
8708+ .macro pax_exit_kernel_user
8709+#ifdef CONFIG_PAX_MEMORY_UDEREF
8710+ call pax_exit_kernel_user
8711+#endif
8712+#ifdef CONFIG_PAX_RANDKSTACK
8713+ pushq %rax
8714+ pushq %r11
8715+ call pax_randomize_kstack
8716+ popq %r11
8717+ popq %rax
8718+#endif
8719+ .endm
8720+
8721+.macro pax_erase_kstack
8722+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
8723+ call pax_erase_kstack
8724+#endif
8725+.endm
8726+
8727 /*
8728 * 32bit SYSENTER instruction entry.
8729 *
8730@@ -121,12 +149,6 @@ ENTRY(ia32_sysenter_target)
8731 CFI_REGISTER rsp,rbp
8732 SWAPGS_UNSAFE_STACK
8733 movq PER_CPU_VAR(kernel_stack), %rsp
8734- addq $(KERNEL_STACK_OFFSET),%rsp
8735- /*
8736- * No need to follow this irqs on/off section: the syscall
8737- * disabled irqs, here we enable it straight after entry:
8738- */
8739- ENABLE_INTERRUPTS(CLBR_NONE)
8740 movl %ebp,%ebp /* zero extension */
8741 pushq_cfi $__USER32_DS
8742 /*CFI_REL_OFFSET ss,0*/
8743@@ -134,22 +156,42 @@ ENTRY(ia32_sysenter_target)
8744 CFI_REL_OFFSET rsp,0
8745 pushfq_cfi
8746 /*CFI_REL_OFFSET rflags,0*/
8747- movl TI_sysenter_return+THREAD_INFO(%rsp,3*8-KERNEL_STACK_OFFSET),%r10d
8748- CFI_REGISTER rip,r10
8749+ orl $X86_EFLAGS_IF,(%rsp)
8750+ GET_THREAD_INFO(%r11)
8751+ movl TI_sysenter_return(%r11), %r11d
8752+ CFI_REGISTER rip,r11
8753 pushq_cfi $__USER32_CS
8754 /*CFI_REL_OFFSET cs,0*/
8755 movl %eax, %eax
8756- pushq_cfi %r10
8757+ pushq_cfi %r11
8758 CFI_REL_OFFSET rip,0
8759 pushq_cfi %rax
8760 cld
8761 SAVE_ARGS 0,1,0
8762+ pax_enter_kernel_user
8763+
8764+#ifdef CONFIG_PAX_RANDKSTACK
8765+ pax_erase_kstack
8766+#endif
8767+
8768+ /*
8769+ * No need to follow this irqs on/off section: the syscall
8770+ * disabled irqs, here we enable it straight after entry:
8771+ */
8772+ ENABLE_INTERRUPTS(CLBR_NONE)
8773 /* no need to do an access_ok check here because rbp has been
8774 32bit zero extended */
8775+
8776+#ifdef CONFIG_PAX_MEMORY_UDEREF
8777+ mov $PAX_USER_SHADOW_BASE,%r11
8778+ add %r11,%rbp
8779+#endif
8780+
8781 1: movl (%rbp),%ebp
8782 _ASM_EXTABLE(1b,ia32_badarg)
8783- orl $TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
8784- testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
8785+ GET_THREAD_INFO(%r11)
8786+ orl $TS_COMPAT,TI_status(%r11)
8787+ testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%r11)
8788 CFI_REMEMBER_STATE
8789 jnz sysenter_tracesys
8790 cmpq $(IA32_NR_syscalls-1),%rax
8791@@ -159,12 +201,15 @@ sysenter_do_call:
8792 sysenter_dispatch:
8793 call *ia32_sys_call_table(,%rax,8)
8794 movq %rax,RAX-ARGOFFSET(%rsp)
8795+ GET_THREAD_INFO(%r11)
8796 DISABLE_INTERRUPTS(CLBR_NONE)
8797 TRACE_IRQS_OFF
8798- testl $_TIF_ALLWORK_MASK,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
8799+ testl $_TIF_ALLWORK_MASK,TI_flags(%r11)
8800 jnz sysexit_audit
8801 sysexit_from_sys_call:
8802- andl $~TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
8803+ pax_exit_kernel_user
8804+ pax_erase_kstack
8805+ andl $~TS_COMPAT,TI_status(%r11)
8806 /* clear IF, that popfq doesn't enable interrupts early */
8807 andl $~0x200,EFLAGS-R11(%rsp)
8808 movl RIP-R11(%rsp),%edx /* User %eip */
8809@@ -190,6 +235,9 @@ sysexit_from_sys_call:
8810 movl %eax,%esi /* 2nd arg: syscall number */
8811 movl $AUDIT_ARCH_I386,%edi /* 1st arg: audit arch */
8812 call __audit_syscall_entry
8813+
8814+ pax_erase_kstack
8815+
8816 movl RAX-ARGOFFSET(%rsp),%eax /* reload syscall number */
8817 cmpq $(IA32_NR_syscalls-1),%rax
8818 ja ia32_badsys
8819@@ -201,7 +249,7 @@ sysexit_from_sys_call:
8820 .endm
8821
8822 .macro auditsys_exit exit
8823- testl $(_TIF_ALLWORK_MASK & ~_TIF_SYSCALL_AUDIT),TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
8824+ testl $(_TIF_ALLWORK_MASK & ~_TIF_SYSCALL_AUDIT),TI_flags(%r11)
8825 jnz ia32_ret_from_sys_call
8826 TRACE_IRQS_ON
8827 sti
8828@@ -212,11 +260,12 @@ sysexit_from_sys_call:
8829 1: setbe %al /* 1 if error, 0 if not */
8830 movzbl %al,%edi /* zero-extend that into %edi */
8831 call __audit_syscall_exit
8832+ GET_THREAD_INFO(%r11)
8833 movq RAX-ARGOFFSET(%rsp),%rax /* reload syscall return value */
8834 movl $(_TIF_ALLWORK_MASK & ~_TIF_SYSCALL_AUDIT),%edi
8835 cli
8836 TRACE_IRQS_OFF
8837- testl %edi,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
8838+ testl %edi,TI_flags(%r11)
8839 jz \exit
8840 CLEAR_RREGS -ARGOFFSET
8841 jmp int_with_check
8842@@ -234,7 +283,7 @@ sysexit_audit:
8843
8844 sysenter_tracesys:
8845 #ifdef CONFIG_AUDITSYSCALL
8846- testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
8847+ testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags(%r11)
8848 jz sysenter_auditsys
8849 #endif
8850 SAVE_REST
8851@@ -246,6 +295,9 @@ sysenter_tracesys:
8852 RESTORE_REST
8853 cmpq $(IA32_NR_syscalls-1),%rax
8854 ja int_ret_from_sys_call /* sysenter_tracesys has set RAX(%rsp) */
8855+
8856+ pax_erase_kstack
8857+
8858 jmp sysenter_do_call
8859 CFI_ENDPROC
8860 ENDPROC(ia32_sysenter_target)
8861@@ -273,19 +325,25 @@ ENDPROC(ia32_sysenter_target)
8862 ENTRY(ia32_cstar_target)
8863 CFI_STARTPROC32 simple
8864 CFI_SIGNAL_FRAME
8865- CFI_DEF_CFA rsp,KERNEL_STACK_OFFSET
8866+ CFI_DEF_CFA rsp,0
8867 CFI_REGISTER rip,rcx
8868 /*CFI_REGISTER rflags,r11*/
8869 SWAPGS_UNSAFE_STACK
8870 movl %esp,%r8d
8871 CFI_REGISTER rsp,r8
8872 movq PER_CPU_VAR(kernel_stack),%rsp
8873+ SAVE_ARGS 8*6,0,0
8874+ pax_enter_kernel_user
8875+
8876+#ifdef CONFIG_PAX_RANDKSTACK
8877+ pax_erase_kstack
8878+#endif
8879+
8880 /*
8881 * No need to follow this irqs on/off section: the syscall
8882 * disabled irqs and here we enable it straight after entry:
8883 */
8884 ENABLE_INTERRUPTS(CLBR_NONE)
8885- SAVE_ARGS 8,0,0
8886 movl %eax,%eax /* zero extension */
8887 movq %rax,ORIG_RAX-ARGOFFSET(%rsp)
8888 movq %rcx,RIP-ARGOFFSET(%rsp)
8889@@ -301,10 +359,17 @@ ENTRY(ia32_cstar_target)
8890 /* no need to do an access_ok check here because r8 has been
8891 32bit zero extended */
8892 /* hardware stack frame is complete now */
8893+
8894+#ifdef CONFIG_PAX_MEMORY_UDEREF
8895+ mov $PAX_USER_SHADOW_BASE,%r11
8896+ add %r11,%r8
8897+#endif
8898+
8899 1: movl (%r8),%r9d
8900 _ASM_EXTABLE(1b,ia32_badarg)
8901- orl $TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
8902- testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
8903+ GET_THREAD_INFO(%r11)
8904+ orl $TS_COMPAT,TI_status(%r11)
8905+ testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%r11)
8906 CFI_REMEMBER_STATE
8907 jnz cstar_tracesys
8908 cmpq $IA32_NR_syscalls-1,%rax
8909@@ -314,12 +379,15 @@ cstar_do_call:
8910 cstar_dispatch:
8911 call *ia32_sys_call_table(,%rax,8)
8912 movq %rax,RAX-ARGOFFSET(%rsp)
8913+ GET_THREAD_INFO(%r11)
8914 DISABLE_INTERRUPTS(CLBR_NONE)
8915 TRACE_IRQS_OFF
8916- testl $_TIF_ALLWORK_MASK,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
8917+ testl $_TIF_ALLWORK_MASK,TI_flags(%r11)
8918 jnz sysretl_audit
8919 sysretl_from_sys_call:
8920- andl $~TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
8921+ pax_exit_kernel_user
8922+ pax_erase_kstack
8923+ andl $~TS_COMPAT,TI_status(%r11)
8924 RESTORE_ARGS 0,-ARG_SKIP,0,0,0
8925 movl RIP-ARGOFFSET(%rsp),%ecx
8926 CFI_REGISTER rip,rcx
8927@@ -347,7 +415,7 @@ sysretl_audit:
8928
8929 cstar_tracesys:
8930 #ifdef CONFIG_AUDITSYSCALL
8931- testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
8932+ testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags(%r11)
8933 jz cstar_auditsys
8934 #endif
8935 xchgl %r9d,%ebp
8936@@ -361,6 +429,9 @@ cstar_tracesys:
8937 xchgl %ebp,%r9d
8938 cmpq $(IA32_NR_syscalls-1),%rax
8939 ja int_ret_from_sys_call /* cstar_tracesys has set RAX(%rsp) */
8940+
8941+ pax_erase_kstack
8942+
8943 jmp cstar_do_call
8944 END(ia32_cstar_target)
8945
8946@@ -401,19 +472,26 @@ ENTRY(ia32_syscall)
8947 CFI_REL_OFFSET rip,RIP-RIP
8948 PARAVIRT_ADJUST_EXCEPTION_FRAME
8949 SWAPGS
8950- /*
8951- * No need to follow this irqs on/off section: the syscall
8952- * disabled irqs and here we enable it straight after entry:
8953- */
8954- ENABLE_INTERRUPTS(CLBR_NONE)
8955 movl %eax,%eax
8956 pushq_cfi %rax
8957 cld
8958 /* note the registers are not zero extended to the sf.
8959 this could be a problem. */
8960 SAVE_ARGS 0,1,0
8961- orl $TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
8962- testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
8963+ pax_enter_kernel_user
8964+
8965+#ifdef CONFIG_PAX_RANDKSTACK
8966+ pax_erase_kstack
8967+#endif
8968+
8969+ /*
8970+ * No need to follow this irqs on/off section: the syscall
8971+ * disabled irqs and here we enable it straight after entry:
8972+ */
8973+ ENABLE_INTERRUPTS(CLBR_NONE)
8974+ GET_THREAD_INFO(%r11)
8975+ orl $TS_COMPAT,TI_status(%r11)
8976+ testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%r11)
8977 jnz ia32_tracesys
8978 cmpq $(IA32_NR_syscalls-1),%rax
8979 ja ia32_badsys
8980@@ -436,6 +514,9 @@ ia32_tracesys:
8981 RESTORE_REST
8982 cmpq $(IA32_NR_syscalls-1),%rax
8983 ja int_ret_from_sys_call /* ia32_tracesys has set RAX(%rsp) */
8984+
8985+ pax_erase_kstack
8986+
8987 jmp ia32_do_call
8988 END(ia32_syscall)
8989
8990diff --git a/arch/x86/ia32/sys_ia32.c b/arch/x86/ia32/sys_ia32.c
8991index 4540bec..714d913 100644
8992--- a/arch/x86/ia32/sys_ia32.c
8993+++ b/arch/x86/ia32/sys_ia32.c
8994@@ -69,8 +69,8 @@ asmlinkage long sys32_ftruncate64(unsigned int fd, unsigned long offset_low,
8995 */
8996 static int cp_stat64(struct stat64 __user *ubuf, struct kstat *stat)
8997 {
8998- typeof(ubuf->st_uid) uid = 0;
8999- typeof(ubuf->st_gid) gid = 0;
9000+ typeof(((struct stat64 *)0)->st_uid) uid = 0;
9001+ typeof(((struct stat64 *)0)->st_gid) gid = 0;
9002 SET_UID(uid, from_kuid_munged(current_user_ns(), stat->uid));
9003 SET_GID(gid, from_kgid_munged(current_user_ns(), stat->gid));
9004 if (!access_ok(VERIFY_WRITE, ubuf, sizeof(struct stat64)) ||
9005@@ -287,7 +287,7 @@ asmlinkage long sys32_sigaction(int sig, struct old_sigaction32 __user *act,
9006 return ret;
9007 }
9008
9009-asmlinkage long sys32_waitpid(compat_pid_t pid, unsigned int *stat_addr,
9010+asmlinkage long sys32_waitpid(compat_pid_t pid, unsigned int __user *stat_addr,
9011 int options)
9012 {
9013 return compat_sys_wait4(pid, stat_addr, options, NULL);
9014@@ -303,7 +303,7 @@ asmlinkage long sys32_sched_rr_get_interval(compat_pid_t pid,
9015 mm_segment_t old_fs = get_fs();
9016
9017 set_fs(KERNEL_DS);
9018- ret = sys_sched_rr_get_interval(pid, (struct timespec __user *)&t);
9019+ ret = sys_sched_rr_get_interval(pid, (struct timespec __force_user *)&t);
9020 set_fs(old_fs);
9021 if (put_compat_timespec(&t, interval))
9022 return -EFAULT;
9023@@ -319,7 +319,7 @@ asmlinkage long sys32_rt_sigpending(compat_sigset_t __user *set,
9024 mm_segment_t old_fs = get_fs();
9025
9026 set_fs(KERNEL_DS);
9027- ret = sys_rt_sigpending((sigset_t __user *)&s, sigsetsize);
9028+ ret = sys_rt_sigpending((sigset_t __force_user *)&s, sigsetsize);
9029 set_fs(old_fs);
9030 if (!ret) {
9031 switch (_NSIG_WORDS) {
9032@@ -344,7 +344,7 @@ asmlinkage long sys32_rt_sigqueueinfo(int pid, int sig,
9033 if (copy_siginfo_from_user32(&info, uinfo))
9034 return -EFAULT;
9035 set_fs(KERNEL_DS);
9036- ret = sys_rt_sigqueueinfo(pid, sig, (siginfo_t __user *)&info);
9037+ ret = sys_rt_sigqueueinfo(pid, sig, (siginfo_t __force_user *)&info);
9038 set_fs(old_fs);
9039 return ret;
9040 }
9041@@ -376,7 +376,7 @@ asmlinkage long sys32_sendfile(int out_fd, int in_fd,
9042 return -EFAULT;
9043
9044 set_fs(KERNEL_DS);
9045- ret = sys_sendfile(out_fd, in_fd, offset ? (off_t __user *)&of : NULL,
9046+ ret = sys_sendfile(out_fd, in_fd, offset ? (off_t __force_user *)&of : NULL,
9047 count);
9048 set_fs(old_fs);
9049
9050diff --git a/arch/x86/include/asm/alternative-asm.h b/arch/x86/include/asm/alternative-asm.h
9051index 952bd01..7692c6f 100644
9052--- a/arch/x86/include/asm/alternative-asm.h
9053+++ b/arch/x86/include/asm/alternative-asm.h
9054@@ -15,6 +15,45 @@
9055 .endm
9056 #endif
9057
9058+#ifdef KERNEXEC_PLUGIN
9059+ .macro pax_force_retaddr_bts rip=0
9060+ btsq $63,\rip(%rsp)
9061+ .endm
9062+#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_BTS
9063+ .macro pax_force_retaddr rip=0, reload=0
9064+ btsq $63,\rip(%rsp)
9065+ .endm
9066+ .macro pax_force_fptr ptr
9067+ btsq $63,\ptr
9068+ .endm
9069+ .macro pax_set_fptr_mask
9070+ .endm
9071+#endif
9072+#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR
9073+ .macro pax_force_retaddr rip=0, reload=0
9074+ .if \reload
9075+ pax_set_fptr_mask
9076+ .endif
9077+ orq %r10,\rip(%rsp)
9078+ .endm
9079+ .macro pax_force_fptr ptr
9080+ orq %r10,\ptr
9081+ .endm
9082+ .macro pax_set_fptr_mask
9083+ movabs $0x8000000000000000,%r10
9084+ .endm
9085+#endif
9086+#else
9087+ .macro pax_force_retaddr rip=0, reload=0
9088+ .endm
9089+ .macro pax_force_fptr ptr
9090+ .endm
9091+ .macro pax_force_retaddr_bts rip=0
9092+ .endm
9093+ .macro pax_set_fptr_mask
9094+ .endm
9095+#endif
9096+
9097 .macro altinstruction_entry orig alt feature orig_len alt_len
9098 .long \orig - .
9099 .long \alt - .
9100diff --git a/arch/x86/include/asm/alternative.h b/arch/x86/include/asm/alternative.h
9101index 7078068..f58bcda 100644
9102--- a/arch/x86/include/asm/alternative.h
9103+++ b/arch/x86/include/asm/alternative.h
9104@@ -105,7 +105,7 @@ static inline int alternatives_text_reserved(void *start, void *end)
9105 ".section .discard,\"aw\",@progbits\n" \
9106 DISCARD_ENTRY(1) \
9107 ".previous\n" \
9108- ".section .altinstr_replacement, \"ax\"\n" \
9109+ ".section .altinstr_replacement, \"a\"\n" \
9110 ALTINSTR_REPLACEMENT(newinstr, feature, 1) \
9111 ".previous"
9112
9113@@ -119,7 +119,7 @@ static inline int alternatives_text_reserved(void *start, void *end)
9114 DISCARD_ENTRY(1) \
9115 DISCARD_ENTRY(2) \
9116 ".previous\n" \
9117- ".section .altinstr_replacement, \"ax\"\n" \
9118+ ".section .altinstr_replacement, \"a\"\n" \
9119 ALTINSTR_REPLACEMENT(newinstr1, feature1, 1) \
9120 ALTINSTR_REPLACEMENT(newinstr2, feature2, 2) \
9121 ".previous"
9122diff --git a/arch/x86/include/asm/apic.h b/arch/x86/include/asm/apic.h
9123index f342612..b3fe911 100644
9124--- a/arch/x86/include/asm/apic.h
9125+++ b/arch/x86/include/asm/apic.h
9126@@ -44,7 +44,7 @@ static inline void generic_apic_probe(void)
9127
9128 #ifdef CONFIG_X86_LOCAL_APIC
9129
9130-extern unsigned int apic_verbosity;
9131+extern int apic_verbosity;
9132 extern int local_apic_timer_c2_ok;
9133
9134 extern int disable_apic;
9135@@ -391,7 +391,7 @@ struct apic {
9136 */
9137 int (*x86_32_numa_cpu_node)(int cpu);
9138 #endif
9139-};
9140+} __do_const;
9141
9142 /*
9143 * Pointer to the local APIC driver in use on this system (there's
9144diff --git a/arch/x86/include/asm/apm.h b/arch/x86/include/asm/apm.h
9145index 20370c6..a2eb9b0 100644
9146--- a/arch/x86/include/asm/apm.h
9147+++ b/arch/x86/include/asm/apm.h
9148@@ -34,7 +34,7 @@ static inline void apm_bios_call_asm(u32 func, u32 ebx_in, u32 ecx_in,
9149 __asm__ __volatile__(APM_DO_ZERO_SEGS
9150 "pushl %%edi\n\t"
9151 "pushl %%ebp\n\t"
9152- "lcall *%%cs:apm_bios_entry\n\t"
9153+ "lcall *%%ss:apm_bios_entry\n\t"
9154 "setc %%al\n\t"
9155 "popl %%ebp\n\t"
9156 "popl %%edi\n\t"
9157@@ -58,7 +58,7 @@ static inline u8 apm_bios_call_simple_asm(u32 func, u32 ebx_in,
9158 __asm__ __volatile__(APM_DO_ZERO_SEGS
9159 "pushl %%edi\n\t"
9160 "pushl %%ebp\n\t"
9161- "lcall *%%cs:apm_bios_entry\n\t"
9162+ "lcall *%%ss:apm_bios_entry\n\t"
9163 "setc %%bl\n\t"
9164 "popl %%ebp\n\t"
9165 "popl %%edi\n\t"
9166diff --git a/arch/x86/include/asm/atomic.h b/arch/x86/include/asm/atomic.h
9167index 58cb6d4..a4b806c 100644
9168--- a/arch/x86/include/asm/atomic.h
9169+++ b/arch/x86/include/asm/atomic.h
9170@@ -22,7 +22,18 @@
9171 */
9172 static inline int atomic_read(const atomic_t *v)
9173 {
9174- return (*(volatile int *)&(v)->counter);
9175+ return (*(volatile const int *)&(v)->counter);
9176+}
9177+
9178+/**
9179+ * atomic_read_unchecked - read atomic variable
9180+ * @v: pointer of type atomic_unchecked_t
9181+ *
9182+ * Atomically reads the value of @v.
9183+ */
9184+static inline int atomic_read_unchecked(const atomic_unchecked_t *v)
9185+{
9186+ return (*(volatile const int *)&(v)->counter);
9187 }
9188
9189 /**
9190@@ -38,6 +49,18 @@ static inline void atomic_set(atomic_t *v, int i)
9191 }
9192
9193 /**
9194+ * atomic_set_unchecked - set atomic variable
9195+ * @v: pointer of type atomic_unchecked_t
9196+ * @i: required value
9197+ *
9198+ * Atomically sets the value of @v to @i.
9199+ */
9200+static inline void atomic_set_unchecked(atomic_unchecked_t *v, int i)
9201+{
9202+ v->counter = i;
9203+}
9204+
9205+/**
9206 * atomic_add - add integer to atomic variable
9207 * @i: integer value to add
9208 * @v: pointer of type atomic_t
9209@@ -46,7 +69,29 @@ static inline void atomic_set(atomic_t *v, int i)
9210 */
9211 static inline void atomic_add(int i, atomic_t *v)
9212 {
9213- asm volatile(LOCK_PREFIX "addl %1,%0"
9214+ asm volatile(LOCK_PREFIX "addl %1,%0\n"
9215+
9216+#ifdef CONFIG_PAX_REFCOUNT
9217+ "jno 0f\n"
9218+ LOCK_PREFIX "subl %1,%0\n"
9219+ "int $4\n0:\n"
9220+ _ASM_EXTABLE(0b, 0b)
9221+#endif
9222+
9223+ : "+m" (v->counter)
9224+ : "ir" (i));
9225+}
9226+
9227+/**
9228+ * atomic_add_unchecked - add integer to atomic variable
9229+ * @i: integer value to add
9230+ * @v: pointer of type atomic_unchecked_t
9231+ *
9232+ * Atomically adds @i to @v.
9233+ */
9234+static inline void atomic_add_unchecked(int i, atomic_unchecked_t *v)
9235+{
9236+ asm volatile(LOCK_PREFIX "addl %1,%0\n"
9237 : "+m" (v->counter)
9238 : "ir" (i));
9239 }
9240@@ -60,7 +105,29 @@ static inline void atomic_add(int i, atomic_t *v)
9241 */
9242 static inline void atomic_sub(int i, atomic_t *v)
9243 {
9244- asm volatile(LOCK_PREFIX "subl %1,%0"
9245+ asm volatile(LOCK_PREFIX "subl %1,%0\n"
9246+
9247+#ifdef CONFIG_PAX_REFCOUNT
9248+ "jno 0f\n"
9249+ LOCK_PREFIX "addl %1,%0\n"
9250+ "int $4\n0:\n"
9251+ _ASM_EXTABLE(0b, 0b)
9252+#endif
9253+
9254+ : "+m" (v->counter)
9255+ : "ir" (i));
9256+}
9257+
9258+/**
9259+ * atomic_sub_unchecked - subtract integer from atomic variable
9260+ * @i: integer value to subtract
9261+ * @v: pointer of type atomic_unchecked_t
9262+ *
9263+ * Atomically subtracts @i from @v.
9264+ */
9265+static inline void atomic_sub_unchecked(int i, atomic_unchecked_t *v)
9266+{
9267+ asm volatile(LOCK_PREFIX "subl %1,%0\n"
9268 : "+m" (v->counter)
9269 : "ir" (i));
9270 }
9271@@ -78,7 +145,16 @@ static inline int atomic_sub_and_test(int i, atomic_t *v)
9272 {
9273 unsigned char c;
9274
9275- asm volatile(LOCK_PREFIX "subl %2,%0; sete %1"
9276+ asm volatile(LOCK_PREFIX "subl %2,%0\n"
9277+
9278+#ifdef CONFIG_PAX_REFCOUNT
9279+ "jno 0f\n"
9280+ LOCK_PREFIX "addl %2,%0\n"
9281+ "int $4\n0:\n"
9282+ _ASM_EXTABLE(0b, 0b)
9283+#endif
9284+
9285+ "sete %1\n"
9286 : "+m" (v->counter), "=qm" (c)
9287 : "ir" (i) : "memory");
9288 return c;
9289@@ -92,7 +168,27 @@ static inline int atomic_sub_and_test(int i, atomic_t *v)
9290 */
9291 static inline void atomic_inc(atomic_t *v)
9292 {
9293- asm volatile(LOCK_PREFIX "incl %0"
9294+ asm volatile(LOCK_PREFIX "incl %0\n"
9295+
9296+#ifdef CONFIG_PAX_REFCOUNT
9297+ "jno 0f\n"
9298+ LOCK_PREFIX "decl %0\n"
9299+ "int $4\n0:\n"
9300+ _ASM_EXTABLE(0b, 0b)
9301+#endif
9302+
9303+ : "+m" (v->counter));
9304+}
9305+
9306+/**
9307+ * atomic_inc_unchecked - increment atomic variable
9308+ * @v: pointer of type atomic_unchecked_t
9309+ *
9310+ * Atomically increments @v by 1.
9311+ */
9312+static inline void atomic_inc_unchecked(atomic_unchecked_t *v)
9313+{
9314+ asm volatile(LOCK_PREFIX "incl %0\n"
9315 : "+m" (v->counter));
9316 }
9317
9318@@ -104,7 +200,27 @@ static inline void atomic_inc(atomic_t *v)
9319 */
9320 static inline void atomic_dec(atomic_t *v)
9321 {
9322- asm volatile(LOCK_PREFIX "decl %0"
9323+ asm volatile(LOCK_PREFIX "decl %0\n"
9324+
9325+#ifdef CONFIG_PAX_REFCOUNT
9326+ "jno 0f\n"
9327+ LOCK_PREFIX "incl %0\n"
9328+ "int $4\n0:\n"
9329+ _ASM_EXTABLE(0b, 0b)
9330+#endif
9331+
9332+ : "+m" (v->counter));
9333+}
9334+
9335+/**
9336+ * atomic_dec_unchecked - decrement atomic variable
9337+ * @v: pointer of type atomic_unchecked_t
9338+ *
9339+ * Atomically decrements @v by 1.
9340+ */
9341+static inline void atomic_dec_unchecked(atomic_unchecked_t *v)
9342+{
9343+ asm volatile(LOCK_PREFIX "decl %0\n"
9344 : "+m" (v->counter));
9345 }
9346
9347@@ -120,7 +236,16 @@ static inline int atomic_dec_and_test(atomic_t *v)
9348 {
9349 unsigned char c;
9350
9351- asm volatile(LOCK_PREFIX "decl %0; sete %1"
9352+ asm volatile(LOCK_PREFIX "decl %0\n"
9353+
9354+#ifdef CONFIG_PAX_REFCOUNT
9355+ "jno 0f\n"
9356+ LOCK_PREFIX "incl %0\n"
9357+ "int $4\n0:\n"
9358+ _ASM_EXTABLE(0b, 0b)
9359+#endif
9360+
9361+ "sete %1\n"
9362 : "+m" (v->counter), "=qm" (c)
9363 : : "memory");
9364 return c != 0;
9365@@ -138,7 +263,35 @@ static inline int atomic_inc_and_test(atomic_t *v)
9366 {
9367 unsigned char c;
9368
9369- asm volatile(LOCK_PREFIX "incl %0; sete %1"
9370+ asm volatile(LOCK_PREFIX "incl %0\n"
9371+
9372+#ifdef CONFIG_PAX_REFCOUNT
9373+ "jno 0f\n"
9374+ LOCK_PREFIX "decl %0\n"
9375+ "int $4\n0:\n"
9376+ _ASM_EXTABLE(0b, 0b)
9377+#endif
9378+
9379+ "sete %1\n"
9380+ : "+m" (v->counter), "=qm" (c)
9381+ : : "memory");
9382+ return c != 0;
9383+}
9384+
9385+/**
9386+ * atomic_inc_and_test_unchecked - increment and test
9387+ * @v: pointer of type atomic_unchecked_t
9388+ *
9389+ * Atomically increments @v by 1
9390+ * and returns true if the result is zero, or false for all
9391+ * other cases.
9392+ */
9393+static inline int atomic_inc_and_test_unchecked(atomic_unchecked_t *v)
9394+{
9395+ unsigned char c;
9396+
9397+ asm volatile(LOCK_PREFIX "incl %0\n"
9398+ "sete %1\n"
9399 : "+m" (v->counter), "=qm" (c)
9400 : : "memory");
9401 return c != 0;
9402@@ -157,7 +310,16 @@ static inline int atomic_add_negative(int i, atomic_t *v)
9403 {
9404 unsigned char c;
9405
9406- asm volatile(LOCK_PREFIX "addl %2,%0; sets %1"
9407+ asm volatile(LOCK_PREFIX "addl %2,%0\n"
9408+
9409+#ifdef CONFIG_PAX_REFCOUNT
9410+ "jno 0f\n"
9411+ LOCK_PREFIX "subl %2,%0\n"
9412+ "int $4\n0:\n"
9413+ _ASM_EXTABLE(0b, 0b)
9414+#endif
9415+
9416+ "sets %1\n"
9417 : "+m" (v->counter), "=qm" (c)
9418 : "ir" (i) : "memory");
9419 return c;
9420@@ -179,7 +341,7 @@ static inline int atomic_add_return(int i, atomic_t *v)
9421 goto no_xadd;
9422 #endif
9423 /* Modern 486+ processor */
9424- return i + xadd(&v->counter, i);
9425+ return i + xadd_check_overflow(&v->counter, i);
9426
9427 #ifdef CONFIG_M386
9428 no_xadd: /* Legacy 386 processor */
9429@@ -192,6 +354,34 @@ no_xadd: /* Legacy 386 processor */
9430 }
9431
9432 /**
9433+ * atomic_add_return_unchecked - add integer and return
9434+ * @i: integer value to add
9435+ * @v: pointer of type atomic_unchecked_t
9436+ *
9437+ * Atomically adds @i to @v and returns @i + @v
9438+ */
9439+static inline int atomic_add_return_unchecked(int i, atomic_unchecked_t *v)
9440+{
9441+#ifdef CONFIG_M386
9442+ int __i;
9443+ unsigned long flags;
9444+ if (unlikely(boot_cpu_data.x86 <= 3))
9445+ goto no_xadd;
9446+#endif
9447+ /* Modern 486+ processor */
9448+ return i + xadd(&v->counter, i);
9449+
9450+#ifdef CONFIG_M386
9451+no_xadd: /* Legacy 386 processor */
9452+ raw_local_irq_save(flags);
9453+ __i = atomic_read_unchecked(v);
9454+ atomic_set_unchecked(v, i + __i);
9455+ raw_local_irq_restore(flags);
9456+ return i + __i;
9457+#endif
9458+}
9459+
9460+/**
9461 * atomic_sub_return - subtract integer and return
9462 * @v: pointer of type atomic_t
9463 * @i: integer value to subtract
9464@@ -204,6 +394,10 @@ static inline int atomic_sub_return(int i, atomic_t *v)
9465 }
9466
9467 #define atomic_inc_return(v) (atomic_add_return(1, v))
9468+static inline int atomic_inc_return_unchecked(atomic_unchecked_t *v)
9469+{
9470+ return atomic_add_return_unchecked(1, v);
9471+}
9472 #define atomic_dec_return(v) (atomic_sub_return(1, v))
9473
9474 static inline int atomic_cmpxchg(atomic_t *v, int old, int new)
9475@@ -211,11 +405,21 @@ static inline int atomic_cmpxchg(atomic_t *v, int old, int new)
9476 return cmpxchg(&v->counter, old, new);
9477 }
9478
9479+static inline int atomic_cmpxchg_unchecked(atomic_unchecked_t *v, int old, int new)
9480+{
9481+ return cmpxchg(&v->counter, old, new);
9482+}
9483+
9484 static inline int atomic_xchg(atomic_t *v, int new)
9485 {
9486 return xchg(&v->counter, new);
9487 }
9488
9489+static inline int atomic_xchg_unchecked(atomic_unchecked_t *v, int new)
9490+{
9491+ return xchg(&v->counter, new);
9492+}
9493+
9494 /**
9495 * __atomic_add_unless - add unless the number is already a given value
9496 * @v: pointer of type atomic_t
9497@@ -227,12 +431,25 @@ static inline int atomic_xchg(atomic_t *v, int new)
9498 */
9499 static inline int __atomic_add_unless(atomic_t *v, int a, int u)
9500 {
9501- int c, old;
9502+ int c, old, new;
9503 c = atomic_read(v);
9504 for (;;) {
9505- if (unlikely(c == (u)))
9506+ if (unlikely(c == u))
9507 break;
9508- old = atomic_cmpxchg((v), c, c + (a));
9509+
9510+ asm volatile("addl %2,%0\n"
9511+
9512+#ifdef CONFIG_PAX_REFCOUNT
9513+ "jno 0f\n"
9514+ "subl %2,%0\n"
9515+ "int $4\n0:\n"
9516+ _ASM_EXTABLE(0b, 0b)
9517+#endif
9518+
9519+ : "=r" (new)
9520+ : "0" (c), "ir" (a));
9521+
9522+ old = atomic_cmpxchg(v, c, new);
9523 if (likely(old == c))
9524 break;
9525 c = old;
9526@@ -240,6 +457,48 @@ static inline int __atomic_add_unless(atomic_t *v, int a, int u)
9527 return c;
9528 }
9529
9530+/**
9531+ * atomic_inc_not_zero_hint - increment if not null
9532+ * @v: pointer of type atomic_t
9533+ * @hint: probable value of the atomic before the increment
9534+ *
9535+ * This version of atomic_inc_not_zero() gives a hint of probable
9536+ * value of the atomic. This helps processor to not read the memory
9537+ * before doing the atomic read/modify/write cycle, lowering
9538+ * number of bus transactions on some arches.
9539+ *
9540+ * Returns: 0 if increment was not done, 1 otherwise.
9541+ */
9542+#define atomic_inc_not_zero_hint atomic_inc_not_zero_hint
9543+static inline int atomic_inc_not_zero_hint(atomic_t *v, int hint)
9544+{
9545+ int val, c = hint, new;
9546+
9547+ /* sanity test, should be removed by compiler if hint is a constant */
9548+ if (!hint)
9549+ return __atomic_add_unless(v, 1, 0);
9550+
9551+ do {
9552+ asm volatile("incl %0\n"
9553+
9554+#ifdef CONFIG_PAX_REFCOUNT
9555+ "jno 0f\n"
9556+ "decl %0\n"
9557+ "int $4\n0:\n"
9558+ _ASM_EXTABLE(0b, 0b)
9559+#endif
9560+
9561+ : "=r" (new)
9562+ : "0" (c));
9563+
9564+ val = atomic_cmpxchg(v, c, new);
9565+ if (val == c)
9566+ return 1;
9567+ c = val;
9568+ } while (c);
9569+
9570+ return 0;
9571+}
9572
9573 /*
9574 * atomic_dec_if_positive - decrement by 1 if old value positive
9575@@ -293,14 +552,37 @@ static inline void atomic_or_long(unsigned long *v1, unsigned long v2)
9576 #endif
9577
9578 /* These are x86-specific, used by some header files */
9579-#define atomic_clear_mask(mask, addr) \
9580- asm volatile(LOCK_PREFIX "andl %0,%1" \
9581- : : "r" (~(mask)), "m" (*(addr)) : "memory")
9582+static inline void atomic_clear_mask(unsigned int mask, atomic_t *v)
9583+{
9584+ asm volatile(LOCK_PREFIX "andl %1,%0"
9585+ : "+m" (v->counter)
9586+ : "r" (~(mask))
9587+ : "memory");
9588+}
9589
9590-#define atomic_set_mask(mask, addr) \
9591- asm volatile(LOCK_PREFIX "orl %0,%1" \
9592- : : "r" ((unsigned)(mask)), "m" (*(addr)) \
9593- : "memory")
9594+static inline void atomic_clear_mask_unchecked(unsigned int mask, atomic_unchecked_t *v)
9595+{
9596+ asm volatile(LOCK_PREFIX "andl %1,%0"
9597+ : "+m" (v->counter)
9598+ : "r" (~(mask))
9599+ : "memory");
9600+}
9601+
9602+static inline void atomic_set_mask(unsigned int mask, atomic_t *v)
9603+{
9604+ asm volatile(LOCK_PREFIX "orl %1,%0"
9605+ : "+m" (v->counter)
9606+ : "r" (mask)
9607+ : "memory");
9608+}
9609+
9610+static inline void atomic_set_mask_unchecked(unsigned int mask, atomic_unchecked_t *v)
9611+{
9612+ asm volatile(LOCK_PREFIX "orl %1,%0"
9613+ : "+m" (v->counter)
9614+ : "r" (mask)
9615+ : "memory");
9616+}
9617
9618 /* Atomic operations are already serializing on x86 */
9619 #define smp_mb__before_atomic_dec() barrier()
9620diff --git a/arch/x86/include/asm/atomic64_32.h b/arch/x86/include/asm/atomic64_32.h
9621index b154de7..aadebd8 100644
9622--- a/arch/x86/include/asm/atomic64_32.h
9623+++ b/arch/x86/include/asm/atomic64_32.h
9624@@ -12,6 +12,14 @@ typedef struct {
9625 u64 __aligned(8) counter;
9626 } atomic64_t;
9627
9628+#ifdef CONFIG_PAX_REFCOUNT
9629+typedef struct {
9630+ u64 __aligned(8) counter;
9631+} atomic64_unchecked_t;
9632+#else
9633+typedef atomic64_t atomic64_unchecked_t;
9634+#endif
9635+
9636 #define ATOMIC64_INIT(val) { (val) }
9637
9638 #define __ATOMIC64_DECL(sym) void atomic64_##sym(atomic64_t *, ...)
9639@@ -37,21 +45,31 @@ typedef struct {
9640 ATOMIC64_DECL_ONE(sym##_386)
9641
9642 ATOMIC64_DECL_ONE(add_386);
9643+ATOMIC64_DECL_ONE(add_unchecked_386);
9644 ATOMIC64_DECL_ONE(sub_386);
9645+ATOMIC64_DECL_ONE(sub_unchecked_386);
9646 ATOMIC64_DECL_ONE(inc_386);
9647+ATOMIC64_DECL_ONE(inc_unchecked_386);
9648 ATOMIC64_DECL_ONE(dec_386);
9649+ATOMIC64_DECL_ONE(dec_unchecked_386);
9650 #endif
9651
9652 #define alternative_atomic64(f, out, in...) \
9653 __alternative_atomic64(f, f, ASM_OUTPUT2(out), ## in)
9654
9655 ATOMIC64_DECL(read);
9656+ATOMIC64_DECL(read_unchecked);
9657 ATOMIC64_DECL(set);
9658+ATOMIC64_DECL(set_unchecked);
9659 ATOMIC64_DECL(xchg);
9660 ATOMIC64_DECL(add_return);
9661+ATOMIC64_DECL(add_return_unchecked);
9662 ATOMIC64_DECL(sub_return);
9663+ATOMIC64_DECL(sub_return_unchecked);
9664 ATOMIC64_DECL(inc_return);
9665+ATOMIC64_DECL(inc_return_unchecked);
9666 ATOMIC64_DECL(dec_return);
9667+ATOMIC64_DECL(dec_return_unchecked);
9668 ATOMIC64_DECL(dec_if_positive);
9669 ATOMIC64_DECL(inc_not_zero);
9670 ATOMIC64_DECL(add_unless);
9671@@ -77,6 +95,21 @@ static inline long long atomic64_cmpxchg(atomic64_t *v, long long o, long long n
9672 }
9673
9674 /**
9675+ * atomic64_cmpxchg_unchecked - cmpxchg atomic64 variable
9676+ * @p: pointer to type atomic64_unchecked_t
9677+ * @o: expected value
9678+ * @n: new value
9679+ *
9680+ * Atomically sets @v to @n if it was equal to @o and returns
9681+ * the old value.
9682+ */
9683+
9684+static inline long long atomic64_cmpxchg_unchecked(atomic64_unchecked_t *v, long long o, long long n)
9685+{
9686+ return cmpxchg64(&v->counter, o, n);
9687+}
9688+
9689+/**
9690 * atomic64_xchg - xchg atomic64 variable
9691 * @v: pointer to type atomic64_t
9692 * @n: value to assign
9693@@ -112,6 +145,22 @@ static inline void atomic64_set(atomic64_t *v, long long i)
9694 }
9695
9696 /**
9697+ * atomic64_set_unchecked - set atomic64 variable
9698+ * @v: pointer to type atomic64_unchecked_t
9699+ * @n: value to assign
9700+ *
9701+ * Atomically sets the value of @v to @n.
9702+ */
9703+static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, long long i)
9704+{
9705+ unsigned high = (unsigned)(i >> 32);
9706+ unsigned low = (unsigned)i;
9707+ alternative_atomic64(set, /* no output */,
9708+ "S" (v), "b" (low), "c" (high)
9709+ : "eax", "edx", "memory");
9710+}
9711+
9712+/**
9713 * atomic64_read - read atomic64 variable
9714 * @v: pointer to type atomic64_t
9715 *
9716@@ -125,6 +174,19 @@ static inline long long atomic64_read(const atomic64_t *v)
9717 }
9718
9719 /**
9720+ * atomic64_read_unchecked - read atomic64 variable
9721+ * @v: pointer to type atomic64_unchecked_t
9722+ *
9723+ * Atomically reads the value of @v and returns it.
9724+ */
9725+static inline long long atomic64_read_unchecked(atomic64_unchecked_t *v)
9726+{
9727+ long long r;
9728+ alternative_atomic64(read, "=&A" (r), "c" (v) : "memory");
9729+ return r;
9730+ }
9731+
9732+/**
9733 * atomic64_add_return - add and return
9734 * @i: integer value to add
9735 * @v: pointer to type atomic64_t
9736@@ -139,6 +201,21 @@ static inline long long atomic64_add_return(long long i, atomic64_t *v)
9737 return i;
9738 }
9739
9740+/**
9741+ * atomic64_add_return_unchecked - add and return
9742+ * @i: integer value to add
9743+ * @v: pointer to type atomic64_unchecked_t
9744+ *
9745+ * Atomically adds @i to @v and returns @i + *@v
9746+ */
9747+static inline long long atomic64_add_return_unchecked(long long i, atomic64_unchecked_t *v)
9748+{
9749+ alternative_atomic64(add_return_unchecked,
9750+ ASM_OUTPUT2("+A" (i), "+c" (v)),
9751+ ASM_NO_INPUT_CLOBBER("memory"));
9752+ return i;
9753+}
9754+
9755 /*
9756 * Other variants with different arithmetic operators:
9757 */
9758@@ -158,6 +235,14 @@ static inline long long atomic64_inc_return(atomic64_t *v)
9759 return a;
9760 }
9761
9762+static inline long long atomic64_inc_return_unchecked(atomic64_unchecked_t *v)
9763+{
9764+ long long a;
9765+ alternative_atomic64(inc_return_unchecked, "=&A" (a),
9766+ "S" (v) : "memory", "ecx");
9767+ return a;
9768+}
9769+
9770 static inline long long atomic64_dec_return(atomic64_t *v)
9771 {
9772 long long a;
9773@@ -182,6 +267,21 @@ static inline long long atomic64_add(long long i, atomic64_t *v)
9774 }
9775
9776 /**
9777+ * atomic64_add_unchecked - add integer to atomic64 variable
9778+ * @i: integer value to add
9779+ * @v: pointer to type atomic64_unchecked_t
9780+ *
9781+ * Atomically adds @i to @v.
9782+ */
9783+static inline long long atomic64_add_unchecked(long long i, atomic64_unchecked_t *v)
9784+{
9785+ __alternative_atomic64(add_unchecked, add_return_unchecked,
9786+ ASM_OUTPUT2("+A" (i), "+c" (v)),
9787+ ASM_NO_INPUT_CLOBBER("memory"));
9788+ return i;
9789+}
9790+
9791+/**
9792 * atomic64_sub - subtract the atomic64 variable
9793 * @i: integer value to subtract
9794 * @v: pointer to type atomic64_t
9795diff --git a/arch/x86/include/asm/atomic64_64.h b/arch/x86/include/asm/atomic64_64.h
9796index 0e1cbfc..5623683 100644
9797--- a/arch/x86/include/asm/atomic64_64.h
9798+++ b/arch/x86/include/asm/atomic64_64.h
9799@@ -18,7 +18,19 @@
9800 */
9801 static inline long atomic64_read(const atomic64_t *v)
9802 {
9803- return (*(volatile long *)&(v)->counter);
9804+ return (*(volatile const long *)&(v)->counter);
9805+}
9806+
9807+/**
9808+ * atomic64_read_unchecked - read atomic64 variable
9809+ * @v: pointer of type atomic64_unchecked_t
9810+ *
9811+ * Atomically reads the value of @v.
9812+ * Doesn't imply a read memory barrier.
9813+ */
9814+static inline long atomic64_read_unchecked(const atomic64_unchecked_t *v)
9815+{
9816+ return (*(volatile const long *)&(v)->counter);
9817 }
9818
9819 /**
9820@@ -34,6 +46,18 @@ static inline void atomic64_set(atomic64_t *v, long i)
9821 }
9822
9823 /**
9824+ * atomic64_set_unchecked - set atomic64 variable
9825+ * @v: pointer to type atomic64_unchecked_t
9826+ * @i: required value
9827+ *
9828+ * Atomically sets the value of @v to @i.
9829+ */
9830+static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, long i)
9831+{
9832+ v->counter = i;
9833+}
9834+
9835+/**
9836 * atomic64_add - add integer to atomic64 variable
9837 * @i: integer value to add
9838 * @v: pointer to type atomic64_t
9839@@ -42,6 +66,28 @@ static inline void atomic64_set(atomic64_t *v, long i)
9840 */
9841 static inline void atomic64_add(long i, atomic64_t *v)
9842 {
9843+ asm volatile(LOCK_PREFIX "addq %1,%0\n"
9844+
9845+#ifdef CONFIG_PAX_REFCOUNT
9846+ "jno 0f\n"
9847+ LOCK_PREFIX "subq %1,%0\n"
9848+ "int $4\n0:\n"
9849+ _ASM_EXTABLE(0b, 0b)
9850+#endif
9851+
9852+ : "=m" (v->counter)
9853+ : "er" (i), "m" (v->counter));
9854+}
9855+
9856+/**
9857+ * atomic64_add_unchecked - add integer to atomic64 variable
9858+ * @i: integer value to add
9859+ * @v: pointer to type atomic64_unchecked_t
9860+ *
9861+ * Atomically adds @i to @v.
9862+ */
9863+static inline void atomic64_add_unchecked(long i, atomic64_unchecked_t *v)
9864+{
9865 asm volatile(LOCK_PREFIX "addq %1,%0"
9866 : "=m" (v->counter)
9867 : "er" (i), "m" (v->counter));
9868@@ -56,7 +102,29 @@ static inline void atomic64_add(long i, atomic64_t *v)
9869 */
9870 static inline void atomic64_sub(long i, atomic64_t *v)
9871 {
9872- asm volatile(LOCK_PREFIX "subq %1,%0"
9873+ asm volatile(LOCK_PREFIX "subq %1,%0\n"
9874+
9875+#ifdef CONFIG_PAX_REFCOUNT
9876+ "jno 0f\n"
9877+ LOCK_PREFIX "addq %1,%0\n"
9878+ "int $4\n0:\n"
9879+ _ASM_EXTABLE(0b, 0b)
9880+#endif
9881+
9882+ : "=m" (v->counter)
9883+ : "er" (i), "m" (v->counter));
9884+}
9885+
9886+/**
9887+ * atomic64_sub_unchecked - subtract the atomic64 variable
9888+ * @i: integer value to subtract
9889+ * @v: pointer to type atomic64_unchecked_t
9890+ *
9891+ * Atomically subtracts @i from @v.
9892+ */
9893+static inline void atomic64_sub_unchecked(long i, atomic64_unchecked_t *v)
9894+{
9895+ asm volatile(LOCK_PREFIX "subq %1,%0\n"
9896 : "=m" (v->counter)
9897 : "er" (i), "m" (v->counter));
9898 }
9899@@ -74,7 +142,16 @@ static inline int atomic64_sub_and_test(long i, atomic64_t *v)
9900 {
9901 unsigned char c;
9902
9903- asm volatile(LOCK_PREFIX "subq %2,%0; sete %1"
9904+ asm volatile(LOCK_PREFIX "subq %2,%0\n"
9905+
9906+#ifdef CONFIG_PAX_REFCOUNT
9907+ "jno 0f\n"
9908+ LOCK_PREFIX "addq %2,%0\n"
9909+ "int $4\n0:\n"
9910+ _ASM_EXTABLE(0b, 0b)
9911+#endif
9912+
9913+ "sete %1\n"
9914 : "=m" (v->counter), "=qm" (c)
9915 : "er" (i), "m" (v->counter) : "memory");
9916 return c;
9917@@ -88,6 +165,27 @@ static inline int atomic64_sub_and_test(long i, atomic64_t *v)
9918 */
9919 static inline void atomic64_inc(atomic64_t *v)
9920 {
9921+ asm volatile(LOCK_PREFIX "incq %0\n"
9922+
9923+#ifdef CONFIG_PAX_REFCOUNT
9924+ "jno 0f\n"
9925+ LOCK_PREFIX "decq %0\n"
9926+ "int $4\n0:\n"
9927+ _ASM_EXTABLE(0b, 0b)
9928+#endif
9929+
9930+ : "=m" (v->counter)
9931+ : "m" (v->counter));
9932+}
9933+
9934+/**
9935+ * atomic64_inc_unchecked - increment atomic64 variable
9936+ * @v: pointer to type atomic64_unchecked_t
9937+ *
9938+ * Atomically increments @v by 1.
9939+ */
9940+static inline void atomic64_inc_unchecked(atomic64_unchecked_t *v)
9941+{
9942 asm volatile(LOCK_PREFIX "incq %0"
9943 : "=m" (v->counter)
9944 : "m" (v->counter));
9945@@ -101,7 +199,28 @@ static inline void atomic64_inc(atomic64_t *v)
9946 */
9947 static inline void atomic64_dec(atomic64_t *v)
9948 {
9949- asm volatile(LOCK_PREFIX "decq %0"
9950+ asm volatile(LOCK_PREFIX "decq %0\n"
9951+
9952+#ifdef CONFIG_PAX_REFCOUNT
9953+ "jno 0f\n"
9954+ LOCK_PREFIX "incq %0\n"
9955+ "int $4\n0:\n"
9956+ _ASM_EXTABLE(0b, 0b)
9957+#endif
9958+
9959+ : "=m" (v->counter)
9960+ : "m" (v->counter));
9961+}
9962+
9963+/**
9964+ * atomic64_dec_unchecked - decrement atomic64 variable
9965+ * @v: pointer to type atomic64_t
9966+ *
9967+ * Atomically decrements @v by 1.
9968+ */
9969+static inline void atomic64_dec_unchecked(atomic64_unchecked_t *v)
9970+{
9971+ asm volatile(LOCK_PREFIX "decq %0\n"
9972 : "=m" (v->counter)
9973 : "m" (v->counter));
9974 }
9975@@ -118,7 +237,16 @@ static inline int atomic64_dec_and_test(atomic64_t *v)
9976 {
9977 unsigned char c;
9978
9979- asm volatile(LOCK_PREFIX "decq %0; sete %1"
9980+ asm volatile(LOCK_PREFIX "decq %0\n"
9981+
9982+#ifdef CONFIG_PAX_REFCOUNT
9983+ "jno 0f\n"
9984+ LOCK_PREFIX "incq %0\n"
9985+ "int $4\n0:\n"
9986+ _ASM_EXTABLE(0b, 0b)
9987+#endif
9988+
9989+ "sete %1\n"
9990 : "=m" (v->counter), "=qm" (c)
9991 : "m" (v->counter) : "memory");
9992 return c != 0;
9993@@ -136,7 +264,16 @@ static inline int atomic64_inc_and_test(atomic64_t *v)
9994 {
9995 unsigned char c;
9996
9997- asm volatile(LOCK_PREFIX "incq %0; sete %1"
9998+ asm volatile(LOCK_PREFIX "incq %0\n"
9999+
10000+#ifdef CONFIG_PAX_REFCOUNT
10001+ "jno 0f\n"
10002+ LOCK_PREFIX "decq %0\n"
10003+ "int $4\n0:\n"
10004+ _ASM_EXTABLE(0b, 0b)
10005+#endif
10006+
10007+ "sete %1\n"
10008 : "=m" (v->counter), "=qm" (c)
10009 : "m" (v->counter) : "memory");
10010 return c != 0;
10011@@ -155,7 +292,16 @@ static inline int atomic64_add_negative(long i, atomic64_t *v)
10012 {
10013 unsigned char c;
10014
10015- asm volatile(LOCK_PREFIX "addq %2,%0; sets %1"
10016+ asm volatile(LOCK_PREFIX "addq %2,%0\n"
10017+
10018+#ifdef CONFIG_PAX_REFCOUNT
10019+ "jno 0f\n"
10020+ LOCK_PREFIX "subq %2,%0\n"
10021+ "int $4\n0:\n"
10022+ _ASM_EXTABLE(0b, 0b)
10023+#endif
10024+
10025+ "sets %1\n"
10026 : "=m" (v->counter), "=qm" (c)
10027 : "er" (i), "m" (v->counter) : "memory");
10028 return c;
10029@@ -170,6 +316,18 @@ static inline int atomic64_add_negative(long i, atomic64_t *v)
10030 */
10031 static inline long atomic64_add_return(long i, atomic64_t *v)
10032 {
10033+ return i + xadd_check_overflow(&v->counter, i);
10034+}
10035+
10036+/**
10037+ * atomic64_add_return_unchecked - add and return
10038+ * @i: integer value to add
10039+ * @v: pointer to type atomic64_unchecked_t
10040+ *
10041+ * Atomically adds @i to @v and returns @i + @v
10042+ */
10043+static inline long atomic64_add_return_unchecked(long i, atomic64_unchecked_t *v)
10044+{
10045 return i + xadd(&v->counter, i);
10046 }
10047
10048@@ -179,6 +337,10 @@ static inline long atomic64_sub_return(long i, atomic64_t *v)
10049 }
10050
10051 #define atomic64_inc_return(v) (atomic64_add_return(1, (v)))
10052+static inline long atomic64_inc_return_unchecked(atomic64_unchecked_t *v)
10053+{
10054+ return atomic64_add_return_unchecked(1, v);
10055+}
10056 #define atomic64_dec_return(v) (atomic64_sub_return(1, (v)))
10057
10058 static inline long atomic64_cmpxchg(atomic64_t *v, long old, long new)
10059@@ -186,6 +348,11 @@ static inline long atomic64_cmpxchg(atomic64_t *v, long old, long new)
10060 return cmpxchg(&v->counter, old, new);
10061 }
10062
10063+static inline long atomic64_cmpxchg_unchecked(atomic64_unchecked_t *v, long old, long new)
10064+{
10065+ return cmpxchg(&v->counter, old, new);
10066+}
10067+
10068 static inline long atomic64_xchg(atomic64_t *v, long new)
10069 {
10070 return xchg(&v->counter, new);
10071@@ -202,17 +369,30 @@ static inline long atomic64_xchg(atomic64_t *v, long new)
10072 */
10073 static inline int atomic64_add_unless(atomic64_t *v, long a, long u)
10074 {
10075- long c, old;
10076+ long c, old, new;
10077 c = atomic64_read(v);
10078 for (;;) {
10079- if (unlikely(c == (u)))
10080+ if (unlikely(c == u))
10081 break;
10082- old = atomic64_cmpxchg((v), c, c + (a));
10083+
10084+ asm volatile("add %2,%0\n"
10085+
10086+#ifdef CONFIG_PAX_REFCOUNT
10087+ "jno 0f\n"
10088+ "sub %2,%0\n"
10089+ "int $4\n0:\n"
10090+ _ASM_EXTABLE(0b, 0b)
10091+#endif
10092+
10093+ : "=r" (new)
10094+ : "0" (c), "ir" (a));
10095+
10096+ old = atomic64_cmpxchg(v, c, new);
10097 if (likely(old == c))
10098 break;
10099 c = old;
10100 }
10101- return c != (u);
10102+ return c != u;
10103 }
10104
10105 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
10106diff --git a/arch/x86/include/asm/bitops.h b/arch/x86/include/asm/bitops.h
10107index 72f5009..2f8b9a9 100644
10108--- a/arch/x86/include/asm/bitops.h
10109+++ b/arch/x86/include/asm/bitops.h
10110@@ -40,7 +40,7 @@
10111 * a mask operation on a byte.
10112 */
10113 #define IS_IMMEDIATE(nr) (__builtin_constant_p(nr))
10114-#define CONST_MASK_ADDR(nr, addr) BITOP_ADDR((void *)(addr) + ((nr)>>3))
10115+#define CONST_MASK_ADDR(nr, addr) BITOP_ADDR((volatile void *)(addr) + ((nr)>>3))
10116 #define CONST_MASK(nr) (1 << ((nr) & 7))
10117
10118 /**
10119diff --git a/arch/x86/include/asm/boot.h b/arch/x86/include/asm/boot.h
10120index b13fe63..0dab13a 100644
10121--- a/arch/x86/include/asm/boot.h
10122+++ b/arch/x86/include/asm/boot.h
10123@@ -11,10 +11,15 @@
10124 #include <asm/pgtable_types.h>
10125
10126 /* Physical address where kernel should be loaded. */
10127-#define LOAD_PHYSICAL_ADDR ((CONFIG_PHYSICAL_START \
10128+#define ____LOAD_PHYSICAL_ADDR ((CONFIG_PHYSICAL_START \
10129 + (CONFIG_PHYSICAL_ALIGN - 1)) \
10130 & ~(CONFIG_PHYSICAL_ALIGN - 1))
10131
10132+#ifndef __ASSEMBLY__
10133+extern unsigned char __LOAD_PHYSICAL_ADDR[];
10134+#define LOAD_PHYSICAL_ADDR ((unsigned long)__LOAD_PHYSICAL_ADDR)
10135+#endif
10136+
10137 /* Minimum kernel alignment, as a power of two */
10138 #ifdef CONFIG_X86_64
10139 #define MIN_KERNEL_ALIGN_LG2 PMD_SHIFT
10140diff --git a/arch/x86/include/asm/cache.h b/arch/x86/include/asm/cache.h
10141index 48f99f1..d78ebf9 100644
10142--- a/arch/x86/include/asm/cache.h
10143+++ b/arch/x86/include/asm/cache.h
10144@@ -5,12 +5,13 @@
10145
10146 /* L1 cache line size */
10147 #define L1_CACHE_SHIFT (CONFIG_X86_L1_CACHE_SHIFT)
10148-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
10149+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
10150
10151 #define __read_mostly __attribute__((__section__(".data..read_mostly")))
10152+#define __read_only __attribute__((__section__(".data..read_only")))
10153
10154 #define INTERNODE_CACHE_SHIFT CONFIG_X86_INTERNODE_CACHE_SHIFT
10155-#define INTERNODE_CACHE_BYTES (1 << INTERNODE_CACHE_SHIFT)
10156+#define INTERNODE_CACHE_BYTES (_AC(1,UL) << INTERNODE_CACHE_SHIFT)
10157
10158 #ifdef CONFIG_X86_VSMP
10159 #ifdef CONFIG_SMP
10160diff --git a/arch/x86/include/asm/cacheflush.h b/arch/x86/include/asm/cacheflush.h
10161index 9863ee3..4a1f8e1 100644
10162--- a/arch/x86/include/asm/cacheflush.h
10163+++ b/arch/x86/include/asm/cacheflush.h
10164@@ -27,7 +27,7 @@ static inline unsigned long get_page_memtype(struct page *pg)
10165 unsigned long pg_flags = pg->flags & _PGMT_MASK;
10166
10167 if (pg_flags == _PGMT_DEFAULT)
10168- return -1;
10169+ return ~0UL;
10170 else if (pg_flags == _PGMT_WC)
10171 return _PAGE_CACHE_WC;
10172 else if (pg_flags == _PGMT_UC_MINUS)
10173diff --git a/arch/x86/include/asm/checksum_32.h b/arch/x86/include/asm/checksum_32.h
10174index 46fc474..b02b0f9 100644
10175--- a/arch/x86/include/asm/checksum_32.h
10176+++ b/arch/x86/include/asm/checksum_32.h
10177@@ -31,6 +31,14 @@ asmlinkage __wsum csum_partial_copy_generic(const void *src, void *dst,
10178 int len, __wsum sum,
10179 int *src_err_ptr, int *dst_err_ptr);
10180
10181+asmlinkage __wsum csum_partial_copy_generic_to_user(const void *src, void *dst,
10182+ int len, __wsum sum,
10183+ int *src_err_ptr, int *dst_err_ptr);
10184+
10185+asmlinkage __wsum csum_partial_copy_generic_from_user(const void *src, void *dst,
10186+ int len, __wsum sum,
10187+ int *src_err_ptr, int *dst_err_ptr);
10188+
10189 /*
10190 * Note: when you get a NULL pointer exception here this means someone
10191 * passed in an incorrect kernel address to one of these functions.
10192@@ -50,7 +58,7 @@ static inline __wsum csum_partial_copy_from_user(const void __user *src,
10193 int *err_ptr)
10194 {
10195 might_sleep();
10196- return csum_partial_copy_generic((__force void *)src, dst,
10197+ return csum_partial_copy_generic_from_user((__force void *)src, dst,
10198 len, sum, err_ptr, NULL);
10199 }
10200
10201@@ -178,7 +186,7 @@ static inline __wsum csum_and_copy_to_user(const void *src,
10202 {
10203 might_sleep();
10204 if (access_ok(VERIFY_WRITE, dst, len))
10205- return csum_partial_copy_generic(src, (__force void *)dst,
10206+ return csum_partial_copy_generic_to_user(src, (__force void *)dst,
10207 len, sum, NULL, err_ptr);
10208
10209 if (len)
10210diff --git a/arch/x86/include/asm/cmpxchg.h b/arch/x86/include/asm/cmpxchg.h
10211index 99480e5..d81165b 100644
10212--- a/arch/x86/include/asm/cmpxchg.h
10213+++ b/arch/x86/include/asm/cmpxchg.h
10214@@ -14,8 +14,12 @@ extern void __cmpxchg_wrong_size(void)
10215 __compiletime_error("Bad argument size for cmpxchg");
10216 extern void __xadd_wrong_size(void)
10217 __compiletime_error("Bad argument size for xadd");
10218+extern void __xadd_check_overflow_wrong_size(void)
10219+ __compiletime_error("Bad argument size for xadd_check_overflow");
10220 extern void __add_wrong_size(void)
10221 __compiletime_error("Bad argument size for add");
10222+extern void __add_check_overflow_wrong_size(void)
10223+ __compiletime_error("Bad argument size for add_check_overflow");
10224
10225 /*
10226 * Constants for operation sizes. On 32-bit, the 64-bit size it set to
10227@@ -67,6 +71,34 @@ extern void __add_wrong_size(void)
10228 __ret; \
10229 })
10230
10231+#define __xchg_op_check_overflow(ptr, arg, op, lock) \
10232+ ({ \
10233+ __typeof__ (*(ptr)) __ret = (arg); \
10234+ switch (sizeof(*(ptr))) { \
10235+ case __X86_CASE_L: \
10236+ asm volatile (lock #op "l %0, %1\n" \
10237+ "jno 0f\n" \
10238+ "mov %0,%1\n" \
10239+ "int $4\n0:\n" \
10240+ _ASM_EXTABLE(0b, 0b) \
10241+ : "+r" (__ret), "+m" (*(ptr)) \
10242+ : : "memory", "cc"); \
10243+ break; \
10244+ case __X86_CASE_Q: \
10245+ asm volatile (lock #op "q %q0, %1\n" \
10246+ "jno 0f\n" \
10247+ "mov %0,%1\n" \
10248+ "int $4\n0:\n" \
10249+ _ASM_EXTABLE(0b, 0b) \
10250+ : "+r" (__ret), "+m" (*(ptr)) \
10251+ : : "memory", "cc"); \
10252+ break; \
10253+ default: \
10254+ __ ## op ## _check_overflow_wrong_size(); \
10255+ } \
10256+ __ret; \
10257+ })
10258+
10259 /*
10260 * Note: no "lock" prefix even on SMP: xchg always implies lock anyway.
10261 * Since this is generally used to protect other memory information, we
10262@@ -167,6 +199,9 @@ extern void __add_wrong_size(void)
10263 #define xadd_sync(ptr, inc) __xadd((ptr), (inc), "lock; ")
10264 #define xadd_local(ptr, inc) __xadd((ptr), (inc), "")
10265
10266+#define __xadd_check_overflow(ptr, inc, lock) __xchg_op_check_overflow((ptr), (inc), xadd, lock)
10267+#define xadd_check_overflow(ptr, inc) __xadd_check_overflow((ptr), (inc), LOCK_PREFIX)
10268+
10269 #define __add(ptr, inc, lock) \
10270 ({ \
10271 __typeof__ (*(ptr)) __ret = (inc); \
10272diff --git a/arch/x86/include/asm/cpufeature.h b/arch/x86/include/asm/cpufeature.h
10273index 6b7ee5f..9d664b3 100644
10274--- a/arch/x86/include/asm/cpufeature.h
10275+++ b/arch/x86/include/asm/cpufeature.h
10276@@ -202,13 +202,14 @@
10277 #define X86_FEATURE_BMI1 (9*32+ 3) /* 1st group bit manipulation extensions */
10278 #define X86_FEATURE_HLE (9*32+ 4) /* Hardware Lock Elision */
10279 #define X86_FEATURE_AVX2 (9*32+ 5) /* AVX2 instructions */
10280-#define X86_FEATURE_SMEP (9*32+ 7) /* Supervisor Mode Execution Protection */
10281+#define X86_FEATURE_SMEP (9*32+ 7) /* Supervisor Mode Execution Prevention */
10282 #define X86_FEATURE_BMI2 (9*32+ 8) /* 2nd group bit manipulation extensions */
10283 #define X86_FEATURE_ERMS (9*32+ 9) /* Enhanced REP MOVSB/STOSB */
10284 #define X86_FEATURE_INVPCID (9*32+10) /* Invalidate Processor Context ID */
10285 #define X86_FEATURE_RTM (9*32+11) /* Restricted Transactional Memory */
10286 #define X86_FEATURE_RDSEED (9*32+18) /* The RDSEED instruction */
10287 #define X86_FEATURE_ADX (9*32+19) /* The ADCX and ADOX instructions */
10288+#define X86_FEATURE_SMAP (9*32+20) /* Supervisor Mode Access Prevention */
10289
10290 #if defined(__KERNEL__) && !defined(__ASSEMBLY__)
10291
10292@@ -373,7 +374,7 @@ static __always_inline __pure bool __static_cpu_has(u16 bit)
10293 ".section .discard,\"aw\",@progbits\n"
10294 " .byte 0xff + (4f-3f) - (2b-1b)\n" /* size check */
10295 ".previous\n"
10296- ".section .altinstr_replacement,\"ax\"\n"
10297+ ".section .altinstr_replacement,\"a\"\n"
10298 "3: movb $1,%0\n"
10299 "4:\n"
10300 ".previous\n"
10301diff --git a/arch/x86/include/asm/desc.h b/arch/x86/include/asm/desc.h
10302index 8bf1c06..f723dfd 100644
10303--- a/arch/x86/include/asm/desc.h
10304+++ b/arch/x86/include/asm/desc.h
10305@@ -4,6 +4,7 @@
10306 #include <asm/desc_defs.h>
10307 #include <asm/ldt.h>
10308 #include <asm/mmu.h>
10309+#include <asm/pgtable.h>
10310
10311 #include <linux/smp.h>
10312 #include <linux/percpu.h>
10313@@ -17,6 +18,7 @@ static inline void fill_ldt(struct desc_struct *desc, const struct user_desc *in
10314
10315 desc->type = (info->read_exec_only ^ 1) << 1;
10316 desc->type |= info->contents << 2;
10317+ desc->type |= info->seg_not_present ^ 1;
10318
10319 desc->s = 1;
10320 desc->dpl = 0x3;
10321@@ -35,19 +37,14 @@ static inline void fill_ldt(struct desc_struct *desc, const struct user_desc *in
10322 }
10323
10324 extern struct desc_ptr idt_descr;
10325-extern gate_desc idt_table[];
10326 extern struct desc_ptr nmi_idt_descr;
10327-extern gate_desc nmi_idt_table[];
10328-
10329-struct gdt_page {
10330- struct desc_struct gdt[GDT_ENTRIES];
10331-} __attribute__((aligned(PAGE_SIZE)));
10332-
10333-DECLARE_PER_CPU_PAGE_ALIGNED(struct gdt_page, gdt_page);
10334+extern gate_desc idt_table[256];
10335+extern gate_desc nmi_idt_table[256];
10336
10337+extern struct desc_struct cpu_gdt_table[NR_CPUS][PAGE_SIZE / sizeof(struct desc_struct)];
10338 static inline struct desc_struct *get_cpu_gdt_table(unsigned int cpu)
10339 {
10340- return per_cpu(gdt_page, cpu).gdt;
10341+ return cpu_gdt_table[cpu];
10342 }
10343
10344 #ifdef CONFIG_X86_64
10345@@ -72,8 +69,14 @@ static inline void pack_gate(gate_desc *gate, unsigned char type,
10346 unsigned long base, unsigned dpl, unsigned flags,
10347 unsigned short seg)
10348 {
10349- gate->a = (seg << 16) | (base & 0xffff);
10350- gate->b = (base & 0xffff0000) | (((0x80 | type | (dpl << 5)) & 0xff) << 8);
10351+ gate->gate.offset_low = base;
10352+ gate->gate.seg = seg;
10353+ gate->gate.reserved = 0;
10354+ gate->gate.type = type;
10355+ gate->gate.s = 0;
10356+ gate->gate.dpl = dpl;
10357+ gate->gate.p = 1;
10358+ gate->gate.offset_high = base >> 16;
10359 }
10360
10361 #endif
10362@@ -118,12 +121,16 @@ static inline void paravirt_free_ldt(struct desc_struct *ldt, unsigned entries)
10363
10364 static inline void native_write_idt_entry(gate_desc *idt, int entry, const gate_desc *gate)
10365 {
10366+ pax_open_kernel();
10367 memcpy(&idt[entry], gate, sizeof(*gate));
10368+ pax_close_kernel();
10369 }
10370
10371 static inline void native_write_ldt_entry(struct desc_struct *ldt, int entry, const void *desc)
10372 {
10373+ pax_open_kernel();
10374 memcpy(&ldt[entry], desc, 8);
10375+ pax_close_kernel();
10376 }
10377
10378 static inline void
10379@@ -137,7 +144,9 @@ native_write_gdt_entry(struct desc_struct *gdt, int entry, const void *desc, int
10380 default: size = sizeof(*gdt); break;
10381 }
10382
10383+ pax_open_kernel();
10384 memcpy(&gdt[entry], desc, size);
10385+ pax_close_kernel();
10386 }
10387
10388 static inline void pack_descriptor(struct desc_struct *desc, unsigned long base,
10389@@ -210,7 +219,9 @@ static inline void native_set_ldt(const void *addr, unsigned int entries)
10390
10391 static inline void native_load_tr_desc(void)
10392 {
10393+ pax_open_kernel();
10394 asm volatile("ltr %w0"::"q" (GDT_ENTRY_TSS*8));
10395+ pax_close_kernel();
10396 }
10397
10398 static inline void native_load_gdt(const struct desc_ptr *dtr)
10399@@ -247,8 +258,10 @@ static inline void native_load_tls(struct thread_struct *t, unsigned int cpu)
10400 struct desc_struct *gdt = get_cpu_gdt_table(cpu);
10401 unsigned int i;
10402
10403+ pax_open_kernel();
10404 for (i = 0; i < GDT_ENTRY_TLS_ENTRIES; i++)
10405 gdt[GDT_ENTRY_TLS_MIN + i] = t->tls_array[i];
10406+ pax_close_kernel();
10407 }
10408
10409 #define _LDT_empty(info) \
10410@@ -311,7 +324,7 @@ static inline void set_desc_limit(struct desc_struct *desc, unsigned long limit)
10411 }
10412
10413 #ifdef CONFIG_X86_64
10414-static inline void set_nmi_gate(int gate, void *addr)
10415+static inline void set_nmi_gate(int gate, const void *addr)
10416 {
10417 gate_desc s;
10418
10419@@ -320,7 +333,7 @@ static inline void set_nmi_gate(int gate, void *addr)
10420 }
10421 #endif
10422
10423-static inline void _set_gate(int gate, unsigned type, void *addr,
10424+static inline void _set_gate(int gate, unsigned type, const void *addr,
10425 unsigned dpl, unsigned ist, unsigned seg)
10426 {
10427 gate_desc s;
10428@@ -339,7 +352,7 @@ static inline void _set_gate(int gate, unsigned type, void *addr,
10429 * Pentium F0 0F bugfix can have resulted in the mapped
10430 * IDT being write-protected.
10431 */
10432-static inline void set_intr_gate(unsigned int n, void *addr)
10433+static inline void set_intr_gate(unsigned int n, const void *addr)
10434 {
10435 BUG_ON((unsigned)n > 0xFF);
10436 _set_gate(n, GATE_INTERRUPT, addr, 0, 0, __KERNEL_CS);
10437@@ -369,19 +382,19 @@ static inline void alloc_intr_gate(unsigned int n, void *addr)
10438 /*
10439 * This routine sets up an interrupt gate at directory privilege level 3.
10440 */
10441-static inline void set_system_intr_gate(unsigned int n, void *addr)
10442+static inline void set_system_intr_gate(unsigned int n, const void *addr)
10443 {
10444 BUG_ON((unsigned)n > 0xFF);
10445 _set_gate(n, GATE_INTERRUPT, addr, 0x3, 0, __KERNEL_CS);
10446 }
10447
10448-static inline void set_system_trap_gate(unsigned int n, void *addr)
10449+static inline void set_system_trap_gate(unsigned int n, const void *addr)
10450 {
10451 BUG_ON((unsigned)n > 0xFF);
10452 _set_gate(n, GATE_TRAP, addr, 0x3, 0, __KERNEL_CS);
10453 }
10454
10455-static inline void set_trap_gate(unsigned int n, void *addr)
10456+static inline void set_trap_gate(unsigned int n, const void *addr)
10457 {
10458 BUG_ON((unsigned)n > 0xFF);
10459 _set_gate(n, GATE_TRAP, addr, 0, 0, __KERNEL_CS);
10460@@ -390,19 +403,31 @@ static inline void set_trap_gate(unsigned int n, void *addr)
10461 static inline void set_task_gate(unsigned int n, unsigned int gdt_entry)
10462 {
10463 BUG_ON((unsigned)n > 0xFF);
10464- _set_gate(n, GATE_TASK, (void *)0, 0, 0, (gdt_entry<<3));
10465+ _set_gate(n, GATE_TASK, (const void *)0, 0, 0, (gdt_entry<<3));
10466 }
10467
10468-static inline void set_intr_gate_ist(int n, void *addr, unsigned ist)
10469+static inline void set_intr_gate_ist(int n, const void *addr, unsigned ist)
10470 {
10471 BUG_ON((unsigned)n > 0xFF);
10472 _set_gate(n, GATE_INTERRUPT, addr, 0, ist, __KERNEL_CS);
10473 }
10474
10475-static inline void set_system_intr_gate_ist(int n, void *addr, unsigned ist)
10476+static inline void set_system_intr_gate_ist(int n, const void *addr, unsigned ist)
10477 {
10478 BUG_ON((unsigned)n > 0xFF);
10479 _set_gate(n, GATE_INTERRUPT, addr, 0x3, ist, __KERNEL_CS);
10480 }
10481
10482+#ifdef CONFIG_X86_32
10483+static inline void set_user_cs(unsigned long base, unsigned long limit, int cpu)
10484+{
10485+ struct desc_struct d;
10486+
10487+ if (likely(limit))
10488+ limit = (limit - 1UL) >> PAGE_SHIFT;
10489+ pack_descriptor(&d, base, limit, 0xFB, 0xC);
10490+ write_gdt_entry(get_cpu_gdt_table(cpu), GDT_ENTRY_DEFAULT_USER_CS, &d, DESCTYPE_S);
10491+}
10492+#endif
10493+
10494 #endif /* _ASM_X86_DESC_H */
10495diff --git a/arch/x86/include/asm/desc_defs.h b/arch/x86/include/asm/desc_defs.h
10496index 278441f..b95a174 100644
10497--- a/arch/x86/include/asm/desc_defs.h
10498+++ b/arch/x86/include/asm/desc_defs.h
10499@@ -31,6 +31,12 @@ struct desc_struct {
10500 unsigned base1: 8, type: 4, s: 1, dpl: 2, p: 1;
10501 unsigned limit: 4, avl: 1, l: 1, d: 1, g: 1, base2: 8;
10502 };
10503+ struct {
10504+ u16 offset_low;
10505+ u16 seg;
10506+ unsigned reserved: 8, type: 4, s: 1, dpl: 2, p: 1;
10507+ unsigned offset_high: 16;
10508+ } gate;
10509 };
10510 } __attribute__((packed));
10511
10512diff --git a/arch/x86/include/asm/e820.h b/arch/x86/include/asm/e820.h
10513index 3778256..c5d4fce 100644
10514--- a/arch/x86/include/asm/e820.h
10515+++ b/arch/x86/include/asm/e820.h
10516@@ -69,7 +69,7 @@ struct e820map {
10517 #define ISA_START_ADDRESS 0xa0000
10518 #define ISA_END_ADDRESS 0x100000
10519
10520-#define BIOS_BEGIN 0x000a0000
10521+#define BIOS_BEGIN 0x000c0000
10522 #define BIOS_END 0x00100000
10523
10524 #define BIOS_ROM_BASE 0xffe00000
10525diff --git a/arch/x86/include/asm/elf.h b/arch/x86/include/asm/elf.h
10526index 5939f44..f8845f6 100644
10527--- a/arch/x86/include/asm/elf.h
10528+++ b/arch/x86/include/asm/elf.h
10529@@ -243,7 +243,25 @@ extern int force_personality32;
10530 the loader. We need to make sure that it is out of the way of the program
10531 that it will "exec", and that there is sufficient room for the brk. */
10532
10533+#ifdef CONFIG_PAX_SEGMEXEC
10534+#define ELF_ET_DYN_BASE ((current->mm->pax_flags & MF_PAX_SEGMEXEC) ? SEGMEXEC_TASK_SIZE/3*2 : TASK_SIZE/3*2)
10535+#else
10536 #define ELF_ET_DYN_BASE (TASK_SIZE / 3 * 2)
10537+#endif
10538+
10539+#ifdef CONFIG_PAX_ASLR
10540+#ifdef CONFIG_X86_32
10541+#define PAX_ELF_ET_DYN_BASE 0x10000000UL
10542+
10543+#define PAX_DELTA_MMAP_LEN (current->mm->pax_flags & MF_PAX_SEGMEXEC ? 15 : 16)
10544+#define PAX_DELTA_STACK_LEN (current->mm->pax_flags & MF_PAX_SEGMEXEC ? 15 : 16)
10545+#else
10546+#define PAX_ELF_ET_DYN_BASE 0x400000UL
10547+
10548+#define PAX_DELTA_MMAP_LEN ((test_thread_flag(TIF_ADDR32)) ? 16 : TASK_SIZE_MAX_SHIFT - PAGE_SHIFT - 3)
10549+#define PAX_DELTA_STACK_LEN ((test_thread_flag(TIF_ADDR32)) ? 16 : TASK_SIZE_MAX_SHIFT - PAGE_SHIFT - 3)
10550+#endif
10551+#endif
10552
10553 /* This yields a mask that user programs can use to figure out what
10554 instruction set this CPU supports. This could be done in user space,
10555@@ -296,16 +314,12 @@ do { \
10556
10557 #define ARCH_DLINFO \
10558 do { \
10559- if (vdso_enabled) \
10560- NEW_AUX_ENT(AT_SYSINFO_EHDR, \
10561- (unsigned long)current->mm->context.vdso); \
10562+ NEW_AUX_ENT(AT_SYSINFO_EHDR, current->mm->context.vdso); \
10563 } while (0)
10564
10565 #define ARCH_DLINFO_X32 \
10566 do { \
10567- if (vdso_enabled) \
10568- NEW_AUX_ENT(AT_SYSINFO_EHDR, \
10569- (unsigned long)current->mm->context.vdso); \
10570+ NEW_AUX_ENT(AT_SYSINFO_EHDR, current->mm->context.vdso); \
10571 } while (0)
10572
10573 #define AT_SYSINFO 32
10574@@ -320,7 +334,7 @@ else \
10575
10576 #endif /* !CONFIG_X86_32 */
10577
10578-#define VDSO_CURRENT_BASE ((unsigned long)current->mm->context.vdso)
10579+#define VDSO_CURRENT_BASE (current->mm->context.vdso)
10580
10581 #define VDSO_ENTRY \
10582 ((unsigned long)VDSO32_SYMBOL(VDSO_CURRENT_BASE, vsyscall))
10583@@ -336,9 +350,6 @@ extern int x32_setup_additional_pages(struct linux_binprm *bprm,
10584 extern int syscall32_setup_pages(struct linux_binprm *, int exstack);
10585 #define compat_arch_setup_additional_pages syscall32_setup_pages
10586
10587-extern unsigned long arch_randomize_brk(struct mm_struct *mm);
10588-#define arch_randomize_brk arch_randomize_brk
10589-
10590 /*
10591 * True on X86_32 or when emulating IA32 on X86_64
10592 */
10593diff --git a/arch/x86/include/asm/emergency-restart.h b/arch/x86/include/asm/emergency-restart.h
10594index 75ce3f4..882e801 100644
10595--- a/arch/x86/include/asm/emergency-restart.h
10596+++ b/arch/x86/include/asm/emergency-restart.h
10597@@ -13,6 +13,6 @@ enum reboot_type {
10598
10599 extern enum reboot_type reboot_type;
10600
10601-extern void machine_emergency_restart(void);
10602+extern void machine_emergency_restart(void) __noreturn;
10603
10604 #endif /* _ASM_X86_EMERGENCY_RESTART_H */
10605diff --git a/arch/x86/include/asm/fpu-internal.h b/arch/x86/include/asm/fpu-internal.h
10606index 75f4c6d..ee3eb8f 100644
10607--- a/arch/x86/include/asm/fpu-internal.h
10608+++ b/arch/x86/include/asm/fpu-internal.h
10609@@ -86,6 +86,11 @@ static inline int fxrstor_checking(struct i387_fxsave_struct *fx)
10610 {
10611 int err;
10612
10613+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
10614+ if ((unsigned long)fx < PAX_USER_SHADOW_BASE)
10615+ fx = (struct i387_fxsave_struct __user *)((void *)fx + PAX_USER_SHADOW_BASE);
10616+#endif
10617+
10618 /* See comment in fxsave() below. */
10619 #ifdef CONFIG_AS_FXSAVEQ
10620 asm volatile("1: fxrstorq %[fx]\n\t"
10621@@ -115,6 +120,11 @@ static inline int fxsave_user(struct i387_fxsave_struct __user *fx)
10622 {
10623 int err;
10624
10625+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
10626+ if ((unsigned long)fx < PAX_USER_SHADOW_BASE)
10627+ fx = (struct i387_fxsave_struct __user *)((void __user *)fx + PAX_USER_SHADOW_BASE);
10628+#endif
10629+
10630 /*
10631 * Clear the bytes not touched by the fxsave and reserved
10632 * for the SW usage.
10633@@ -271,7 +281,7 @@ static inline int restore_fpu_checking(struct task_struct *tsk)
10634 "emms\n\t" /* clear stack tags */
10635 "fildl %P[addr]", /* set F?P to defined value */
10636 X86_FEATURE_FXSAVE_LEAK,
10637- [addr] "m" (tsk->thread.fpu.has_fpu));
10638+ [addr] "m" (init_tss[smp_processor_id()].x86_tss.sp0));
10639
10640 return fpu_restore_checking(&tsk->thread.fpu);
10641 }
10642diff --git a/arch/x86/include/asm/futex.h b/arch/x86/include/asm/futex.h
10643index 71ecbcb..bac10b7 100644
10644--- a/arch/x86/include/asm/futex.h
10645+++ b/arch/x86/include/asm/futex.h
10646@@ -11,16 +11,18 @@
10647 #include <asm/processor.h>
10648
10649 #define __futex_atomic_op1(insn, ret, oldval, uaddr, oparg) \
10650+ typecheck(u32 __user *, uaddr); \
10651 asm volatile("1:\t" insn "\n" \
10652 "2:\t.section .fixup,\"ax\"\n" \
10653 "3:\tmov\t%3, %1\n" \
10654 "\tjmp\t2b\n" \
10655 "\t.previous\n" \
10656 _ASM_EXTABLE(1b, 3b) \
10657- : "=r" (oldval), "=r" (ret), "+m" (*uaddr) \
10658+ : "=r" (oldval), "=r" (ret), "+m" (*(u32 __user *)____m(uaddr))\
10659 : "i" (-EFAULT), "0" (oparg), "1" (0))
10660
10661 #define __futex_atomic_op2(insn, ret, oldval, uaddr, oparg) \
10662+ typecheck(u32 __user *, uaddr); \
10663 asm volatile("1:\tmovl %2, %0\n" \
10664 "\tmovl\t%0, %3\n" \
10665 "\t" insn "\n" \
10666@@ -33,7 +35,7 @@
10667 _ASM_EXTABLE(1b, 4b) \
10668 _ASM_EXTABLE(2b, 4b) \
10669 : "=&a" (oldval), "=&r" (ret), \
10670- "+m" (*uaddr), "=&r" (tem) \
10671+ "+m" (*(u32 __user *)____m(uaddr)), "=&r" (tem) \
10672 : "r" (oparg), "i" (-EFAULT), "1" (0))
10673
10674 static inline int futex_atomic_op_inuser(int encoded_op, u32 __user *uaddr)
10675@@ -60,10 +62,10 @@ static inline int futex_atomic_op_inuser(int encoded_op, u32 __user *uaddr)
10676
10677 switch (op) {
10678 case FUTEX_OP_SET:
10679- __futex_atomic_op1("xchgl %0, %2", ret, oldval, uaddr, oparg);
10680+ __futex_atomic_op1(__copyuser_seg"xchgl %0, %2", ret, oldval, uaddr, oparg);
10681 break;
10682 case FUTEX_OP_ADD:
10683- __futex_atomic_op1(LOCK_PREFIX "xaddl %0, %2", ret, oldval,
10684+ __futex_atomic_op1(LOCK_PREFIX __copyuser_seg"xaddl %0, %2", ret, oldval,
10685 uaddr, oparg);
10686 break;
10687 case FUTEX_OP_OR:
10688@@ -122,13 +124,13 @@ static inline int futex_atomic_cmpxchg_inatomic(u32 *uval, u32 __user *uaddr,
10689 if (!access_ok(VERIFY_WRITE, uaddr, sizeof(u32)))
10690 return -EFAULT;
10691
10692- asm volatile("1:\t" LOCK_PREFIX "cmpxchgl %4, %2\n"
10693+ asm volatile("1:\t" LOCK_PREFIX __copyuser_seg"cmpxchgl %4, %2\n"
10694 "2:\t.section .fixup, \"ax\"\n"
10695 "3:\tmov %3, %0\n"
10696 "\tjmp 2b\n"
10697 "\t.previous\n"
10698 _ASM_EXTABLE(1b, 3b)
10699- : "+r" (ret), "=a" (oldval), "+m" (*uaddr)
10700+ : "+r" (ret), "=a" (oldval), "+m" (*(u32 __user *)____m(uaddr))
10701 : "i" (-EFAULT), "r" (newval), "1" (oldval)
10702 : "memory"
10703 );
10704diff --git a/arch/x86/include/asm/hw_irq.h b/arch/x86/include/asm/hw_irq.h
10705index eb92a6e..b98b2f4 100644
10706--- a/arch/x86/include/asm/hw_irq.h
10707+++ b/arch/x86/include/asm/hw_irq.h
10708@@ -136,8 +136,8 @@ extern void setup_ioapic_dest(void);
10709 extern void enable_IO_APIC(void);
10710
10711 /* Statistics */
10712-extern atomic_t irq_err_count;
10713-extern atomic_t irq_mis_count;
10714+extern atomic_unchecked_t irq_err_count;
10715+extern atomic_unchecked_t irq_mis_count;
10716
10717 /* EISA */
10718 extern void eisa_set_level_irq(unsigned int irq);
10719diff --git a/arch/x86/include/asm/io.h b/arch/x86/include/asm/io.h
10720index d8e8eef..99f81ae 100644
10721--- a/arch/x86/include/asm/io.h
10722+++ b/arch/x86/include/asm/io.h
10723@@ -194,6 +194,17 @@ extern void set_iounmap_nonlazy(void);
10724
10725 #include <linux/vmalloc.h>
10726
10727+#define ARCH_HAS_VALID_PHYS_ADDR_RANGE
10728+static inline int valid_phys_addr_range(unsigned long addr, size_t count)
10729+{
10730+ return ((addr + count + PAGE_SIZE - 1) >> PAGE_SHIFT) < (1ULL << (boot_cpu_data.x86_phys_bits - PAGE_SHIFT)) ? 1 : 0;
10731+}
10732+
10733+static inline int valid_mmap_phys_addr_range(unsigned long pfn, size_t count)
10734+{
10735+ return (pfn + (count >> PAGE_SHIFT)) < (1ULL << (boot_cpu_data.x86_phys_bits - PAGE_SHIFT)) ? 1 : 0;
10736+}
10737+
10738 /*
10739 * Convert a virtual cached pointer to an uncached pointer
10740 */
10741diff --git a/arch/x86/include/asm/irqflags.h b/arch/x86/include/asm/irqflags.h
10742index bba3cf8..06bc8da 100644
10743--- a/arch/x86/include/asm/irqflags.h
10744+++ b/arch/x86/include/asm/irqflags.h
10745@@ -141,6 +141,11 @@ static inline notrace unsigned long arch_local_irq_save(void)
10746 sti; \
10747 sysexit
10748
10749+#define GET_CR0_INTO_RDI mov %cr0, %rdi
10750+#define SET_RDI_INTO_CR0 mov %rdi, %cr0
10751+#define GET_CR3_INTO_RDI mov %cr3, %rdi
10752+#define SET_RDI_INTO_CR3 mov %rdi, %cr3
10753+
10754 #else
10755 #define INTERRUPT_RETURN iret
10756 #define ENABLE_INTERRUPTS_SYSEXIT sti; sysexit
10757diff --git a/arch/x86/include/asm/kprobes.h b/arch/x86/include/asm/kprobes.h
10758index 5478825..839e88c 100644
10759--- a/arch/x86/include/asm/kprobes.h
10760+++ b/arch/x86/include/asm/kprobes.h
10761@@ -37,13 +37,8 @@ typedef u8 kprobe_opcode_t;
10762 #define RELATIVEJUMP_SIZE 5
10763 #define RELATIVECALL_OPCODE 0xe8
10764 #define RELATIVE_ADDR_SIZE 4
10765-#define MAX_STACK_SIZE 64
10766-#define MIN_STACK_SIZE(ADDR) \
10767- (((MAX_STACK_SIZE) < (((unsigned long)current_thread_info()) + \
10768- THREAD_SIZE - (unsigned long)(ADDR))) \
10769- ? (MAX_STACK_SIZE) \
10770- : (((unsigned long)current_thread_info()) + \
10771- THREAD_SIZE - (unsigned long)(ADDR)))
10772+#define MAX_STACK_SIZE 64UL
10773+#define MIN_STACK_SIZE(ADDR) min(MAX_STACK_SIZE, current->thread.sp0 - (unsigned long)(ADDR))
10774
10775 #define flush_insn_slot(p) do { } while (0)
10776
10777diff --git a/arch/x86/include/asm/kvm_host.h b/arch/x86/include/asm/kvm_host.h
10778index 09155d6..d2e6df9 100644
10779--- a/arch/x86/include/asm/kvm_host.h
10780+++ b/arch/x86/include/asm/kvm_host.h
10781@@ -694,7 +694,7 @@ struct kvm_x86_ops {
10782 int (*check_intercept)(struct kvm_vcpu *vcpu,
10783 struct x86_instruction_info *info,
10784 enum x86_intercept_stage stage);
10785-};
10786+} __do_const;
10787
10788 struct kvm_arch_async_pf {
10789 u32 token;
10790diff --git a/arch/x86/include/asm/local.h b/arch/x86/include/asm/local.h
10791index c8bed0d..e5721fa 100644
10792--- a/arch/x86/include/asm/local.h
10793+++ b/arch/x86/include/asm/local.h
10794@@ -17,26 +17,58 @@ typedef struct {
10795
10796 static inline void local_inc(local_t *l)
10797 {
10798- asm volatile(_ASM_INC "%0"
10799+ asm volatile(_ASM_INC "%0\n"
10800+
10801+#ifdef CONFIG_PAX_REFCOUNT
10802+ "jno 0f\n"
10803+ _ASM_DEC "%0\n"
10804+ "int $4\n0:\n"
10805+ _ASM_EXTABLE(0b, 0b)
10806+#endif
10807+
10808 : "+m" (l->a.counter));
10809 }
10810
10811 static inline void local_dec(local_t *l)
10812 {
10813- asm volatile(_ASM_DEC "%0"
10814+ asm volatile(_ASM_DEC "%0\n"
10815+
10816+#ifdef CONFIG_PAX_REFCOUNT
10817+ "jno 0f\n"
10818+ _ASM_INC "%0\n"
10819+ "int $4\n0:\n"
10820+ _ASM_EXTABLE(0b, 0b)
10821+#endif
10822+
10823 : "+m" (l->a.counter));
10824 }
10825
10826 static inline void local_add(long i, local_t *l)
10827 {
10828- asm volatile(_ASM_ADD "%1,%0"
10829+ asm volatile(_ASM_ADD "%1,%0\n"
10830+
10831+#ifdef CONFIG_PAX_REFCOUNT
10832+ "jno 0f\n"
10833+ _ASM_SUB "%1,%0\n"
10834+ "int $4\n0:\n"
10835+ _ASM_EXTABLE(0b, 0b)
10836+#endif
10837+
10838 : "+m" (l->a.counter)
10839 : "ir" (i));
10840 }
10841
10842 static inline void local_sub(long i, local_t *l)
10843 {
10844- asm volatile(_ASM_SUB "%1,%0"
10845+ asm volatile(_ASM_SUB "%1,%0\n"
10846+
10847+#ifdef CONFIG_PAX_REFCOUNT
10848+ "jno 0f\n"
10849+ _ASM_ADD "%1,%0\n"
10850+ "int $4\n0:\n"
10851+ _ASM_EXTABLE(0b, 0b)
10852+#endif
10853+
10854 : "+m" (l->a.counter)
10855 : "ir" (i));
10856 }
10857@@ -54,7 +86,16 @@ static inline int local_sub_and_test(long i, local_t *l)
10858 {
10859 unsigned char c;
10860
10861- asm volatile(_ASM_SUB "%2,%0; sete %1"
10862+ asm volatile(_ASM_SUB "%2,%0\n"
10863+
10864+#ifdef CONFIG_PAX_REFCOUNT
10865+ "jno 0f\n"
10866+ _ASM_ADD "%2,%0\n"
10867+ "int $4\n0:\n"
10868+ _ASM_EXTABLE(0b, 0b)
10869+#endif
10870+
10871+ "sete %1\n"
10872 : "+m" (l->a.counter), "=qm" (c)
10873 : "ir" (i) : "memory");
10874 return c;
10875@@ -72,7 +113,16 @@ static inline int local_dec_and_test(local_t *l)
10876 {
10877 unsigned char c;
10878
10879- asm volatile(_ASM_DEC "%0; sete %1"
10880+ asm volatile(_ASM_DEC "%0\n"
10881+
10882+#ifdef CONFIG_PAX_REFCOUNT
10883+ "jno 0f\n"
10884+ _ASM_INC "%0\n"
10885+ "int $4\n0:\n"
10886+ _ASM_EXTABLE(0b, 0b)
10887+#endif
10888+
10889+ "sete %1\n"
10890 : "+m" (l->a.counter), "=qm" (c)
10891 : : "memory");
10892 return c != 0;
10893@@ -90,7 +140,16 @@ static inline int local_inc_and_test(local_t *l)
10894 {
10895 unsigned char c;
10896
10897- asm volatile(_ASM_INC "%0; sete %1"
10898+ asm volatile(_ASM_INC "%0\n"
10899+
10900+#ifdef CONFIG_PAX_REFCOUNT
10901+ "jno 0f\n"
10902+ _ASM_DEC "%0\n"
10903+ "int $4\n0:\n"
10904+ _ASM_EXTABLE(0b, 0b)
10905+#endif
10906+
10907+ "sete %1\n"
10908 : "+m" (l->a.counter), "=qm" (c)
10909 : : "memory");
10910 return c != 0;
10911@@ -109,7 +168,16 @@ static inline int local_add_negative(long i, local_t *l)
10912 {
10913 unsigned char c;
10914
10915- asm volatile(_ASM_ADD "%2,%0; sets %1"
10916+ asm volatile(_ASM_ADD "%2,%0\n"
10917+
10918+#ifdef CONFIG_PAX_REFCOUNT
10919+ "jno 0f\n"
10920+ _ASM_SUB "%2,%0\n"
10921+ "int $4\n0:\n"
10922+ _ASM_EXTABLE(0b, 0b)
10923+#endif
10924+
10925+ "sets %1\n"
10926 : "+m" (l->a.counter), "=qm" (c)
10927 : "ir" (i) : "memory");
10928 return c;
10929@@ -132,7 +200,15 @@ static inline long local_add_return(long i, local_t *l)
10930 #endif
10931 /* Modern 486+ processor */
10932 __i = i;
10933- asm volatile(_ASM_XADD "%0, %1;"
10934+ asm volatile(_ASM_XADD "%0, %1\n"
10935+
10936+#ifdef CONFIG_PAX_REFCOUNT
10937+ "jno 0f\n"
10938+ _ASM_MOV "%0,%1\n"
10939+ "int $4\n0:\n"
10940+ _ASM_EXTABLE(0b, 0b)
10941+#endif
10942+
10943 : "+r" (i), "+m" (l->a.counter)
10944 : : "memory");
10945 return i + __i;
10946diff --git a/arch/x86/include/asm/mman.h b/arch/x86/include/asm/mman.h
10947index 593e51d..fa69c9a 100644
10948--- a/arch/x86/include/asm/mman.h
10949+++ b/arch/x86/include/asm/mman.h
10950@@ -5,4 +5,14 @@
10951
10952 #include <asm-generic/mman.h>
10953
10954+#ifdef __KERNEL__
10955+#ifndef __ASSEMBLY__
10956+#ifdef CONFIG_X86_32
10957+#define arch_mmap_check i386_mmap_check
10958+int i386_mmap_check(unsigned long addr, unsigned long len,
10959+ unsigned long flags);
10960+#endif
10961+#endif
10962+#endif
10963+
10964 #endif /* _ASM_X86_MMAN_H */
10965diff --git a/arch/x86/include/asm/mmu.h b/arch/x86/include/asm/mmu.h
10966index 5f55e69..e20bfb1 100644
10967--- a/arch/x86/include/asm/mmu.h
10968+++ b/arch/x86/include/asm/mmu.h
10969@@ -9,7 +9,7 @@
10970 * we put the segment information here.
10971 */
10972 typedef struct {
10973- void *ldt;
10974+ struct desc_struct *ldt;
10975 int size;
10976
10977 #ifdef CONFIG_X86_64
10978@@ -18,7 +18,19 @@ typedef struct {
10979 #endif
10980
10981 struct mutex lock;
10982- void *vdso;
10983+ unsigned long vdso;
10984+
10985+#ifdef CONFIG_X86_32
10986+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
10987+ unsigned long user_cs_base;
10988+ unsigned long user_cs_limit;
10989+
10990+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_SMP)
10991+ cpumask_t cpu_user_cs_mask;
10992+#endif
10993+
10994+#endif
10995+#endif
10996 } mm_context_t;
10997
10998 #ifdef CONFIG_SMP
10999diff --git a/arch/x86/include/asm/mmu_context.h b/arch/x86/include/asm/mmu_context.h
11000index cdbf367..adb37ac 100644
11001--- a/arch/x86/include/asm/mmu_context.h
11002+++ b/arch/x86/include/asm/mmu_context.h
11003@@ -24,6 +24,18 @@ void destroy_context(struct mm_struct *mm);
11004
11005 static inline void enter_lazy_tlb(struct mm_struct *mm, struct task_struct *tsk)
11006 {
11007+
11008+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
11009+ unsigned int i;
11010+ pgd_t *pgd;
11011+
11012+ pax_open_kernel();
11013+ pgd = get_cpu_pgd(smp_processor_id());
11014+ for (i = USER_PGD_PTRS; i < 2 * USER_PGD_PTRS; ++i)
11015+ set_pgd_batched(pgd+i, native_make_pgd(0));
11016+ pax_close_kernel();
11017+#endif
11018+
11019 #ifdef CONFIG_SMP
11020 if (this_cpu_read(cpu_tlbstate.state) == TLBSTATE_OK)
11021 this_cpu_write(cpu_tlbstate.state, TLBSTATE_LAZY);
11022@@ -34,16 +46,30 @@ static inline void switch_mm(struct mm_struct *prev, struct mm_struct *next,
11023 struct task_struct *tsk)
11024 {
11025 unsigned cpu = smp_processor_id();
11026+#if defined(CONFIG_X86_32) && defined(CONFIG_SMP) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
11027+ int tlbstate = TLBSTATE_OK;
11028+#endif
11029
11030 if (likely(prev != next)) {
11031 #ifdef CONFIG_SMP
11032+#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
11033+ tlbstate = this_cpu_read(cpu_tlbstate.state);
11034+#endif
11035 this_cpu_write(cpu_tlbstate.state, TLBSTATE_OK);
11036 this_cpu_write(cpu_tlbstate.active_mm, next);
11037 #endif
11038 cpumask_set_cpu(cpu, mm_cpumask(next));
11039
11040 /* Re-load page tables */
11041+#ifdef CONFIG_PAX_PER_CPU_PGD
11042+ pax_open_kernel();
11043+ __clone_user_pgds(get_cpu_pgd(cpu), next->pgd);
11044+ __shadow_user_pgds(get_cpu_pgd(cpu) + USER_PGD_PTRS, next->pgd);
11045+ pax_close_kernel();
11046+ load_cr3(get_cpu_pgd(cpu));
11047+#else
11048 load_cr3(next->pgd);
11049+#endif
11050
11051 /* stop flush ipis for the previous mm */
11052 cpumask_clear_cpu(cpu, mm_cpumask(prev));
11053@@ -53,9 +79,38 @@ static inline void switch_mm(struct mm_struct *prev, struct mm_struct *next,
11054 */
11055 if (unlikely(prev->context.ldt != next->context.ldt))
11056 load_LDT_nolock(&next->context);
11057- }
11058+
11059+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_SMP)
11060+ if (!(__supported_pte_mask & _PAGE_NX)) {
11061+ smp_mb__before_clear_bit();
11062+ cpu_clear(cpu, prev->context.cpu_user_cs_mask);
11063+ smp_mb__after_clear_bit();
11064+ cpu_set(cpu, next->context.cpu_user_cs_mask);
11065+ }
11066+#endif
11067+
11068+#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
11069+ if (unlikely(prev->context.user_cs_base != next->context.user_cs_base ||
11070+ prev->context.user_cs_limit != next->context.user_cs_limit))
11071+ set_user_cs(next->context.user_cs_base, next->context.user_cs_limit, cpu);
11072 #ifdef CONFIG_SMP
11073+ else if (unlikely(tlbstate != TLBSTATE_OK))
11074+ set_user_cs(next->context.user_cs_base, next->context.user_cs_limit, cpu);
11075+#endif
11076+#endif
11077+
11078+ }
11079 else {
11080+
11081+#ifdef CONFIG_PAX_PER_CPU_PGD
11082+ pax_open_kernel();
11083+ __clone_user_pgds(get_cpu_pgd(cpu), next->pgd);
11084+ __shadow_user_pgds(get_cpu_pgd(cpu) + USER_PGD_PTRS, next->pgd);
11085+ pax_close_kernel();
11086+ load_cr3(get_cpu_pgd(cpu));
11087+#endif
11088+
11089+#ifdef CONFIG_SMP
11090 this_cpu_write(cpu_tlbstate.state, TLBSTATE_OK);
11091 BUG_ON(this_cpu_read(cpu_tlbstate.active_mm) != next);
11092
11093@@ -64,11 +119,28 @@ static inline void switch_mm(struct mm_struct *prev, struct mm_struct *next,
11094 * tlb flush IPI delivery. We must reload CR3
11095 * to make sure to use no freed page tables.
11096 */
11097+
11098+#ifndef CONFIG_PAX_PER_CPU_PGD
11099 load_cr3(next->pgd);
11100+#endif
11101+
11102 load_LDT_nolock(&next->context);
11103+
11104+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
11105+ if (!(__supported_pte_mask & _PAGE_NX))
11106+ cpu_set(cpu, next->context.cpu_user_cs_mask);
11107+#endif
11108+
11109+#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
11110+#ifdef CONFIG_PAX_PAGEEXEC
11111+ if (!((next->pax_flags & MF_PAX_PAGEEXEC) && (__supported_pte_mask & _PAGE_NX)))
11112+#endif
11113+ set_user_cs(next->context.user_cs_base, next->context.user_cs_limit, cpu);
11114+#endif
11115+
11116 }
11117+#endif
11118 }
11119-#endif
11120 }
11121
11122 #define activate_mm(prev, next) \
11123diff --git a/arch/x86/include/asm/module.h b/arch/x86/include/asm/module.h
11124index 9eae775..c914fea 100644
11125--- a/arch/x86/include/asm/module.h
11126+++ b/arch/x86/include/asm/module.h
11127@@ -5,6 +5,7 @@
11128
11129 #ifdef CONFIG_X86_64
11130 /* X86_64 does not define MODULE_PROC_FAMILY */
11131+#define MODULE_PROC_FAMILY ""
11132 #elif defined CONFIG_M386
11133 #define MODULE_PROC_FAMILY "386 "
11134 #elif defined CONFIG_M486
11135@@ -59,8 +60,20 @@
11136 #error unknown processor family
11137 #endif
11138
11139-#ifdef CONFIG_X86_32
11140-# define MODULE_ARCH_VERMAGIC MODULE_PROC_FAMILY
11141+#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_BTS
11142+#define MODULE_PAX_KERNEXEC "KERNEXEC_BTS "
11143+#elif defined(CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR)
11144+#define MODULE_PAX_KERNEXEC "KERNEXEC_OR "
11145+#else
11146+#define MODULE_PAX_KERNEXEC ""
11147 #endif
11148
11149+#ifdef CONFIG_PAX_MEMORY_UDEREF
11150+#define MODULE_PAX_UDEREF "UDEREF "
11151+#else
11152+#define MODULE_PAX_UDEREF ""
11153+#endif
11154+
11155+#define MODULE_ARCH_VERMAGIC MODULE_PROC_FAMILY MODULE_PAX_KERNEXEC MODULE_PAX_UDEREF
11156+
11157 #endif /* _ASM_X86_MODULE_H */
11158diff --git a/arch/x86/include/asm/page_64_types.h b/arch/x86/include/asm/page_64_types.h
11159index 320f7bb..e89f8f8 100644
11160--- a/arch/x86/include/asm/page_64_types.h
11161+++ b/arch/x86/include/asm/page_64_types.h
11162@@ -56,7 +56,7 @@ void copy_page(void *to, void *from);
11163
11164 /* duplicated to the one in bootmem.h */
11165 extern unsigned long max_pfn;
11166-extern unsigned long phys_base;
11167+extern const unsigned long phys_base;
11168
11169 extern unsigned long __phys_addr(unsigned long);
11170 #define __phys_reloc_hide(x) (x)
11171diff --git a/arch/x86/include/asm/paravirt.h b/arch/x86/include/asm/paravirt.h
11172index a0facf3..c017b15 100644
11173--- a/arch/x86/include/asm/paravirt.h
11174+++ b/arch/x86/include/asm/paravirt.h
11175@@ -632,6 +632,18 @@ static inline void set_pgd(pgd_t *pgdp, pgd_t pgd)
11176 val);
11177 }
11178
11179+static inline void set_pgd_batched(pgd_t *pgdp, pgd_t pgd)
11180+{
11181+ pgdval_t val = native_pgd_val(pgd);
11182+
11183+ if (sizeof(pgdval_t) > sizeof(long))
11184+ PVOP_VCALL3(pv_mmu_ops.set_pgd_batched, pgdp,
11185+ val, (u64)val >> 32);
11186+ else
11187+ PVOP_VCALL2(pv_mmu_ops.set_pgd_batched, pgdp,
11188+ val);
11189+}
11190+
11191 static inline void pgd_clear(pgd_t *pgdp)
11192 {
11193 set_pgd(pgdp, __pgd(0));
11194@@ -713,6 +725,21 @@ static inline void __set_fixmap(unsigned /* enum fixed_addresses */ idx,
11195 pv_mmu_ops.set_fixmap(idx, phys, flags);
11196 }
11197
11198+#ifdef CONFIG_PAX_KERNEXEC
11199+static inline unsigned long pax_open_kernel(void)
11200+{
11201+ return PVOP_CALL0(unsigned long, pv_mmu_ops.pax_open_kernel);
11202+}
11203+
11204+static inline unsigned long pax_close_kernel(void)
11205+{
11206+ return PVOP_CALL0(unsigned long, pv_mmu_ops.pax_close_kernel);
11207+}
11208+#else
11209+static inline unsigned long pax_open_kernel(void) { return 0; }
11210+static inline unsigned long pax_close_kernel(void) { return 0; }
11211+#endif
11212+
11213 #if defined(CONFIG_SMP) && defined(CONFIG_PARAVIRT_SPINLOCKS)
11214
11215 static inline int arch_spin_is_locked(struct arch_spinlock *lock)
11216@@ -929,7 +956,7 @@ extern void default_banner(void);
11217
11218 #define PARA_PATCH(struct, off) ((PARAVIRT_PATCH_##struct + (off)) / 4)
11219 #define PARA_SITE(ptype, clobbers, ops) _PVSITE(ptype, clobbers, ops, .long, 4)
11220-#define PARA_INDIRECT(addr) *%cs:addr
11221+#define PARA_INDIRECT(addr) *%ss:addr
11222 #endif
11223
11224 #define INTERRUPT_RETURN \
11225@@ -1004,6 +1031,21 @@ extern void default_banner(void);
11226 PARA_SITE(PARA_PATCH(pv_cpu_ops, PV_CPU_irq_enable_sysexit), \
11227 CLBR_NONE, \
11228 jmp PARA_INDIRECT(pv_cpu_ops+PV_CPU_irq_enable_sysexit))
11229+
11230+#define GET_CR0_INTO_RDI \
11231+ call PARA_INDIRECT(pv_cpu_ops+PV_CPU_read_cr0); \
11232+ mov %rax,%rdi
11233+
11234+#define SET_RDI_INTO_CR0 \
11235+ call PARA_INDIRECT(pv_cpu_ops+PV_CPU_write_cr0)
11236+
11237+#define GET_CR3_INTO_RDI \
11238+ call PARA_INDIRECT(pv_mmu_ops+PV_MMU_read_cr3); \
11239+ mov %rax,%rdi
11240+
11241+#define SET_RDI_INTO_CR3 \
11242+ call PARA_INDIRECT(pv_mmu_ops+PV_MMU_write_cr3)
11243+
11244 #endif /* CONFIG_X86_32 */
11245
11246 #endif /* __ASSEMBLY__ */
11247diff --git a/arch/x86/include/asm/paravirt_types.h b/arch/x86/include/asm/paravirt_types.h
11248index 142236e..6a6b4a6 100644
11249--- a/arch/x86/include/asm/paravirt_types.h
11250+++ b/arch/x86/include/asm/paravirt_types.h
11251@@ -84,20 +84,20 @@ struct pv_init_ops {
11252 */
11253 unsigned (*patch)(u8 type, u16 clobber, void *insnbuf,
11254 unsigned long addr, unsigned len);
11255-};
11256+} __no_const;
11257
11258
11259 struct pv_lazy_ops {
11260 /* Set deferred update mode, used for batching operations. */
11261 void (*enter)(void);
11262 void (*leave)(void);
11263-};
11264+} __no_const;
11265
11266 struct pv_time_ops {
11267 unsigned long long (*sched_clock)(void);
11268 unsigned long long (*steal_clock)(int cpu);
11269 unsigned long (*get_tsc_khz)(void);
11270-};
11271+} __no_const;
11272
11273 struct pv_cpu_ops {
11274 /* hooks for various privileged instructions */
11275@@ -191,7 +191,7 @@ struct pv_cpu_ops {
11276
11277 void (*start_context_switch)(struct task_struct *prev);
11278 void (*end_context_switch)(struct task_struct *next);
11279-};
11280+} __no_const;
11281
11282 struct pv_irq_ops {
11283 /*
11284@@ -222,7 +222,7 @@ struct pv_apic_ops {
11285 unsigned long start_eip,
11286 unsigned long start_esp);
11287 #endif
11288-};
11289+} __no_const;
11290
11291 struct pv_mmu_ops {
11292 unsigned long (*read_cr2)(void);
11293@@ -312,6 +312,7 @@ struct pv_mmu_ops {
11294 struct paravirt_callee_save make_pud;
11295
11296 void (*set_pgd)(pgd_t *pudp, pgd_t pgdval);
11297+ void (*set_pgd_batched)(pgd_t *pudp, pgd_t pgdval);
11298 #endif /* PAGETABLE_LEVELS == 4 */
11299 #endif /* PAGETABLE_LEVELS >= 3 */
11300
11301@@ -323,6 +324,12 @@ struct pv_mmu_ops {
11302 an mfn. We can tell which is which from the index. */
11303 void (*set_fixmap)(unsigned /* enum fixed_addresses */ idx,
11304 phys_addr_t phys, pgprot_t flags);
11305+
11306+#ifdef CONFIG_PAX_KERNEXEC
11307+ unsigned long (*pax_open_kernel)(void);
11308+ unsigned long (*pax_close_kernel)(void);
11309+#endif
11310+
11311 };
11312
11313 struct arch_spinlock;
11314@@ -333,7 +340,7 @@ struct pv_lock_ops {
11315 void (*spin_lock_flags)(struct arch_spinlock *lock, unsigned long flags);
11316 int (*spin_trylock)(struct arch_spinlock *lock);
11317 void (*spin_unlock)(struct arch_spinlock *lock);
11318-};
11319+} __no_const;
11320
11321 /* This contains all the paravirt structures: we get a convenient
11322 * number for each function using the offset which we use to indicate
11323diff --git a/arch/x86/include/asm/pgalloc.h b/arch/x86/include/asm/pgalloc.h
11324index b4389a4..7024269 100644
11325--- a/arch/x86/include/asm/pgalloc.h
11326+++ b/arch/x86/include/asm/pgalloc.h
11327@@ -63,6 +63,13 @@ static inline void pmd_populate_kernel(struct mm_struct *mm,
11328 pmd_t *pmd, pte_t *pte)
11329 {
11330 paravirt_alloc_pte(mm, __pa(pte) >> PAGE_SHIFT);
11331+ set_pmd(pmd, __pmd(__pa(pte) | _KERNPG_TABLE));
11332+}
11333+
11334+static inline void pmd_populate_user(struct mm_struct *mm,
11335+ pmd_t *pmd, pte_t *pte)
11336+{
11337+ paravirt_alloc_pte(mm, __pa(pte) >> PAGE_SHIFT);
11338 set_pmd(pmd, __pmd(__pa(pte) | _PAGE_TABLE));
11339 }
11340
11341@@ -99,12 +106,22 @@ static inline void __pmd_free_tlb(struct mmu_gather *tlb, pmd_t *pmd,
11342
11343 #ifdef CONFIG_X86_PAE
11344 extern void pud_populate(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd);
11345+static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd)
11346+{
11347+ pud_populate(mm, pudp, pmd);
11348+}
11349 #else /* !CONFIG_X86_PAE */
11350 static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
11351 {
11352 paravirt_alloc_pmd(mm, __pa(pmd) >> PAGE_SHIFT);
11353 set_pud(pud, __pud(_PAGE_TABLE | __pa(pmd)));
11354 }
11355+
11356+static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
11357+{
11358+ paravirt_alloc_pmd(mm, __pa(pmd) >> PAGE_SHIFT);
11359+ set_pud(pud, __pud(_KERNPG_TABLE | __pa(pmd)));
11360+}
11361 #endif /* CONFIG_X86_PAE */
11362
11363 #if PAGETABLE_LEVELS > 3
11364@@ -114,6 +131,12 @@ static inline void pgd_populate(struct mm_struct *mm, pgd_t *pgd, pud_t *pud)
11365 set_pgd(pgd, __pgd(_PAGE_TABLE | __pa(pud)));
11366 }
11367
11368+static inline void pgd_populate_kernel(struct mm_struct *mm, pgd_t *pgd, pud_t *pud)
11369+{
11370+ paravirt_alloc_pud(mm, __pa(pud) >> PAGE_SHIFT);
11371+ set_pgd(pgd, __pgd(_KERNPG_TABLE | __pa(pud)));
11372+}
11373+
11374 static inline pud_t *pud_alloc_one(struct mm_struct *mm, unsigned long addr)
11375 {
11376 return (pud_t *)get_zeroed_page(GFP_KERNEL|__GFP_REPEAT);
11377diff --git a/arch/x86/include/asm/pgtable-2level.h b/arch/x86/include/asm/pgtable-2level.h
11378index f2b489c..4f7e2e5 100644
11379--- a/arch/x86/include/asm/pgtable-2level.h
11380+++ b/arch/x86/include/asm/pgtable-2level.h
11381@@ -18,7 +18,9 @@ static inline void native_set_pte(pte_t *ptep , pte_t pte)
11382
11383 static inline void native_set_pmd(pmd_t *pmdp, pmd_t pmd)
11384 {
11385+ pax_open_kernel();
11386 *pmdp = pmd;
11387+ pax_close_kernel();
11388 }
11389
11390 static inline void native_set_pte_atomic(pte_t *ptep, pte_t pte)
11391diff --git a/arch/x86/include/asm/pgtable-3level.h b/arch/x86/include/asm/pgtable-3level.h
11392index 4cc9f2b..5fd9226 100644
11393--- a/arch/x86/include/asm/pgtable-3level.h
11394+++ b/arch/x86/include/asm/pgtable-3level.h
11395@@ -92,12 +92,16 @@ static inline void native_set_pte_atomic(pte_t *ptep, pte_t pte)
11396
11397 static inline void native_set_pmd(pmd_t *pmdp, pmd_t pmd)
11398 {
11399+ pax_open_kernel();
11400 set_64bit((unsigned long long *)(pmdp), native_pmd_val(pmd));
11401+ pax_close_kernel();
11402 }
11403
11404 static inline void native_set_pud(pud_t *pudp, pud_t pud)
11405 {
11406+ pax_open_kernel();
11407 set_64bit((unsigned long long *)(pudp), native_pud_val(pud));
11408+ pax_close_kernel();
11409 }
11410
11411 /*
11412diff --git a/arch/x86/include/asm/pgtable.h b/arch/x86/include/asm/pgtable.h
11413index c3520d7..cf742ef 100644
11414--- a/arch/x86/include/asm/pgtable.h
11415+++ b/arch/x86/include/asm/pgtable.h
11416@@ -44,6 +44,7 @@ extern struct mm_struct *pgd_page_get_mm(struct page *page);
11417
11418 #ifndef __PAGETABLE_PUD_FOLDED
11419 #define set_pgd(pgdp, pgd) native_set_pgd(pgdp, pgd)
11420+#define set_pgd_batched(pgdp, pgd) native_set_pgd_batched(pgdp, pgd)
11421 #define pgd_clear(pgd) native_pgd_clear(pgd)
11422 #endif
11423
11424@@ -81,12 +82,51 @@ extern struct mm_struct *pgd_page_get_mm(struct page *page);
11425
11426 #define arch_end_context_switch(prev) do {} while(0)
11427
11428+#define pax_open_kernel() native_pax_open_kernel()
11429+#define pax_close_kernel() native_pax_close_kernel()
11430 #endif /* CONFIG_PARAVIRT */
11431
11432+#define __HAVE_ARCH_PAX_OPEN_KERNEL
11433+#define __HAVE_ARCH_PAX_CLOSE_KERNEL
11434+
11435+#ifdef CONFIG_PAX_KERNEXEC
11436+static inline unsigned long native_pax_open_kernel(void)
11437+{
11438+ unsigned long cr0;
11439+
11440+ preempt_disable();
11441+ barrier();
11442+ cr0 = read_cr0() ^ X86_CR0_WP;
11443+ BUG_ON(unlikely(cr0 & X86_CR0_WP));
11444+ write_cr0(cr0);
11445+ return cr0 ^ X86_CR0_WP;
11446+}
11447+
11448+static inline unsigned long native_pax_close_kernel(void)
11449+{
11450+ unsigned long cr0;
11451+
11452+ cr0 = read_cr0() ^ X86_CR0_WP;
11453+ BUG_ON(unlikely(!(cr0 & X86_CR0_WP)));
11454+ write_cr0(cr0);
11455+ barrier();
11456+ preempt_enable_no_resched();
11457+ return cr0 ^ X86_CR0_WP;
11458+}
11459+#else
11460+static inline unsigned long native_pax_open_kernel(void) { return 0; }
11461+static inline unsigned long native_pax_close_kernel(void) { return 0; }
11462+#endif
11463+
11464 /*
11465 * The following only work if pte_present() is true.
11466 * Undefined behaviour if not..
11467 */
11468+static inline int pte_user(pte_t pte)
11469+{
11470+ return pte_val(pte) & _PAGE_USER;
11471+}
11472+
11473 static inline int pte_dirty(pte_t pte)
11474 {
11475 return pte_flags(pte) & _PAGE_DIRTY;
11476@@ -195,9 +235,29 @@ static inline pte_t pte_wrprotect(pte_t pte)
11477 return pte_clear_flags(pte, _PAGE_RW);
11478 }
11479
11480+static inline pte_t pte_mkread(pte_t pte)
11481+{
11482+ return __pte(pte_val(pte) | _PAGE_USER);
11483+}
11484+
11485 static inline pte_t pte_mkexec(pte_t pte)
11486 {
11487- return pte_clear_flags(pte, _PAGE_NX);
11488+#ifdef CONFIG_X86_PAE
11489+ if (__supported_pte_mask & _PAGE_NX)
11490+ return pte_clear_flags(pte, _PAGE_NX);
11491+ else
11492+#endif
11493+ return pte_set_flags(pte, _PAGE_USER);
11494+}
11495+
11496+static inline pte_t pte_exprotect(pte_t pte)
11497+{
11498+#ifdef CONFIG_X86_PAE
11499+ if (__supported_pte_mask & _PAGE_NX)
11500+ return pte_set_flags(pte, _PAGE_NX);
11501+ else
11502+#endif
11503+ return pte_clear_flags(pte, _PAGE_USER);
11504 }
11505
11506 static inline pte_t pte_mkdirty(pte_t pte)
11507@@ -389,6 +449,15 @@ pte_t *populate_extra_pte(unsigned long vaddr);
11508 #endif
11509
11510 #ifndef __ASSEMBLY__
11511+
11512+#ifdef CONFIG_PAX_PER_CPU_PGD
11513+extern pgd_t cpu_pgd[NR_CPUS][PTRS_PER_PGD];
11514+static inline pgd_t *get_cpu_pgd(unsigned int cpu)
11515+{
11516+ return cpu_pgd[cpu];
11517+}
11518+#endif
11519+
11520 #include <linux/mm_types.h>
11521
11522 static inline int pte_none(pte_t pte)
11523@@ -565,7 +634,7 @@ static inline pud_t *pud_offset(pgd_t *pgd, unsigned long address)
11524
11525 static inline int pgd_bad(pgd_t pgd)
11526 {
11527- return (pgd_flags(pgd) & ~_PAGE_USER) != _KERNPG_TABLE;
11528+ return (pgd_flags(pgd) & ~(_PAGE_USER | _PAGE_NX)) != _KERNPG_TABLE;
11529 }
11530
11531 static inline int pgd_none(pgd_t pgd)
11532@@ -588,7 +657,12 @@ static inline int pgd_none(pgd_t pgd)
11533 * pgd_offset() returns a (pgd_t *)
11534 * pgd_index() is used get the offset into the pgd page's array of pgd_t's;
11535 */
11536-#define pgd_offset(mm, address) ((mm)->pgd + pgd_index((address)))
11537+#define pgd_offset(mm, address) ((mm)->pgd + pgd_index(address))
11538+
11539+#ifdef CONFIG_PAX_PER_CPU_PGD
11540+#define pgd_offset_cpu(cpu, address) (get_cpu_pgd(cpu) + pgd_index(address))
11541+#endif
11542+
11543 /*
11544 * a shortcut which implies the use of the kernel's pgd, instead
11545 * of a process's
11546@@ -599,6 +673,20 @@ static inline int pgd_none(pgd_t pgd)
11547 #define KERNEL_PGD_BOUNDARY pgd_index(PAGE_OFFSET)
11548 #define KERNEL_PGD_PTRS (PTRS_PER_PGD - KERNEL_PGD_BOUNDARY)
11549
11550+#ifdef CONFIG_X86_32
11551+#define USER_PGD_PTRS KERNEL_PGD_BOUNDARY
11552+#else
11553+#define TASK_SIZE_MAX_SHIFT CONFIG_TASK_SIZE_MAX_SHIFT
11554+#define USER_PGD_PTRS (_AC(1,UL) << (TASK_SIZE_MAX_SHIFT - PGDIR_SHIFT))
11555+
11556+#ifdef CONFIG_PAX_MEMORY_UDEREF
11557+#define PAX_USER_SHADOW_BASE (_AC(1,UL) << TASK_SIZE_MAX_SHIFT)
11558+#else
11559+#define PAX_USER_SHADOW_BASE (_AC(0,UL))
11560+#endif
11561+
11562+#endif
11563+
11564 #ifndef __ASSEMBLY__
11565
11566 extern int direct_gbpages;
11567@@ -763,11 +851,23 @@ static inline void pmdp_set_wrprotect(struct mm_struct *mm,
11568 * dst and src can be on the same page, but the range must not overlap,
11569 * and must not cross a page boundary.
11570 */
11571-static inline void clone_pgd_range(pgd_t *dst, pgd_t *src, int count)
11572+static inline void clone_pgd_range(pgd_t *dst, const pgd_t *src, int count)
11573 {
11574- memcpy(dst, src, count * sizeof(pgd_t));
11575+ pax_open_kernel();
11576+ while (count--)
11577+ *dst++ = *src++;
11578+ pax_close_kernel();
11579 }
11580
11581+#ifdef CONFIG_PAX_PER_CPU_PGD
11582+extern void __clone_user_pgds(pgd_t *dst, const pgd_t *src);
11583+#endif
11584+
11585+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
11586+extern void __shadow_user_pgds(pgd_t *dst, const pgd_t *src);
11587+#else
11588+static inline void __shadow_user_pgds(pgd_t *dst, const pgd_t *src) {}
11589+#endif
11590
11591 #include <asm-generic/pgtable.h>
11592 #endif /* __ASSEMBLY__ */
11593diff --git a/arch/x86/include/asm/pgtable_32.h b/arch/x86/include/asm/pgtable_32.h
11594index 0c92113..34a77c6 100644
11595--- a/arch/x86/include/asm/pgtable_32.h
11596+++ b/arch/x86/include/asm/pgtable_32.h
11597@@ -25,9 +25,6 @@
11598 struct mm_struct;
11599 struct vm_area_struct;
11600
11601-extern pgd_t swapper_pg_dir[1024];
11602-extern pgd_t initial_page_table[1024];
11603-
11604 static inline void pgtable_cache_init(void) { }
11605 static inline void check_pgt_cache(void) { }
11606 void paging_init(void);
11607@@ -48,6 +45,12 @@ extern void set_pmd_pfn(unsigned long, unsigned long, pgprot_t);
11608 # include <asm/pgtable-2level.h>
11609 #endif
11610
11611+extern pgd_t swapper_pg_dir[PTRS_PER_PGD];
11612+extern pgd_t initial_page_table[PTRS_PER_PGD];
11613+#ifdef CONFIG_X86_PAE
11614+extern pmd_t swapper_pm_dir[PTRS_PER_PGD][PTRS_PER_PMD];
11615+#endif
11616+
11617 #if defined(CONFIG_HIGHPTE)
11618 #define pte_offset_map(dir, address) \
11619 ((pte_t *)kmap_atomic(pmd_page(*(dir))) + \
11620@@ -62,7 +65,9 @@ extern void set_pmd_pfn(unsigned long, unsigned long, pgprot_t);
11621 /* Clear a kernel PTE and flush it from the TLB */
11622 #define kpte_clear_flush(ptep, vaddr) \
11623 do { \
11624+ pax_open_kernel(); \
11625 pte_clear(&init_mm, (vaddr), (ptep)); \
11626+ pax_close_kernel(); \
11627 __flush_tlb_one((vaddr)); \
11628 } while (0)
11629
11630@@ -74,6 +79,9 @@ do { \
11631
11632 #endif /* !__ASSEMBLY__ */
11633
11634+#define HAVE_ARCH_UNMAPPED_AREA
11635+#define HAVE_ARCH_UNMAPPED_AREA_TOPDOWN
11636+
11637 /*
11638 * kern_addr_valid() is (1) for FLATMEM and (0) for
11639 * SPARSEMEM and DISCONTIGMEM
11640diff --git a/arch/x86/include/asm/pgtable_32_types.h b/arch/x86/include/asm/pgtable_32_types.h
11641index ed5903b..c7fe163 100644
11642--- a/arch/x86/include/asm/pgtable_32_types.h
11643+++ b/arch/x86/include/asm/pgtable_32_types.h
11644@@ -8,7 +8,7 @@
11645 */
11646 #ifdef CONFIG_X86_PAE
11647 # include <asm/pgtable-3level_types.h>
11648-# define PMD_SIZE (1UL << PMD_SHIFT)
11649+# define PMD_SIZE (_AC(1, UL) << PMD_SHIFT)
11650 # define PMD_MASK (~(PMD_SIZE - 1))
11651 #else
11652 # include <asm/pgtable-2level_types.h>
11653@@ -46,6 +46,19 @@ extern bool __vmalloc_start_set; /* set once high_memory is set */
11654 # define VMALLOC_END (FIXADDR_START - 2 * PAGE_SIZE)
11655 #endif
11656
11657+#ifdef CONFIG_PAX_KERNEXEC
11658+#ifndef __ASSEMBLY__
11659+extern unsigned char MODULES_EXEC_VADDR[];
11660+extern unsigned char MODULES_EXEC_END[];
11661+#endif
11662+#include <asm/boot.h>
11663+#define ktla_ktva(addr) (addr + LOAD_PHYSICAL_ADDR + PAGE_OFFSET)
11664+#define ktva_ktla(addr) (addr - LOAD_PHYSICAL_ADDR - PAGE_OFFSET)
11665+#else
11666+#define ktla_ktva(addr) (addr)
11667+#define ktva_ktla(addr) (addr)
11668+#endif
11669+
11670 #define MODULES_VADDR VMALLOC_START
11671 #define MODULES_END VMALLOC_END
11672 #define MODULES_LEN (MODULES_VADDR - MODULES_END)
11673diff --git a/arch/x86/include/asm/pgtable_64.h b/arch/x86/include/asm/pgtable_64.h
11674index 8251be0..4ea8b46 100644
11675--- a/arch/x86/include/asm/pgtable_64.h
11676+++ b/arch/x86/include/asm/pgtable_64.h
11677@@ -16,10 +16,14 @@
11678
11679 extern pud_t level3_kernel_pgt[512];
11680 extern pud_t level3_ident_pgt[512];
11681+extern pud_t level3_vmalloc_start_pgt[512];
11682+extern pud_t level3_vmalloc_end_pgt[512];
11683+extern pud_t level3_vmemmap_pgt[512];
11684+extern pud_t level2_vmemmap_pgt[512];
11685 extern pmd_t level2_kernel_pgt[512];
11686 extern pmd_t level2_fixmap_pgt[512];
11687-extern pmd_t level2_ident_pgt[512];
11688-extern pgd_t init_level4_pgt[];
11689+extern pmd_t level2_ident_pgt[512*2];
11690+extern pgd_t init_level4_pgt[512];
11691
11692 #define swapper_pg_dir init_level4_pgt
11693
11694@@ -61,7 +65,9 @@ static inline void native_set_pte_atomic(pte_t *ptep, pte_t pte)
11695
11696 static inline void native_set_pmd(pmd_t *pmdp, pmd_t pmd)
11697 {
11698+ pax_open_kernel();
11699 *pmdp = pmd;
11700+ pax_close_kernel();
11701 }
11702
11703 static inline void native_pmd_clear(pmd_t *pmd)
11704@@ -97,7 +103,9 @@ static inline pmd_t native_pmdp_get_and_clear(pmd_t *xp)
11705
11706 static inline void native_set_pud(pud_t *pudp, pud_t pud)
11707 {
11708+ pax_open_kernel();
11709 *pudp = pud;
11710+ pax_close_kernel();
11711 }
11712
11713 static inline void native_pud_clear(pud_t *pud)
11714@@ -107,6 +115,13 @@ static inline void native_pud_clear(pud_t *pud)
11715
11716 static inline void native_set_pgd(pgd_t *pgdp, pgd_t pgd)
11717 {
11718+ pax_open_kernel();
11719+ *pgdp = pgd;
11720+ pax_close_kernel();
11721+}
11722+
11723+static inline void native_set_pgd_batched(pgd_t *pgdp, pgd_t pgd)
11724+{
11725 *pgdp = pgd;
11726 }
11727
11728diff --git a/arch/x86/include/asm/pgtable_64_types.h b/arch/x86/include/asm/pgtable_64_types.h
11729index 766ea16..5b96cb3 100644
11730--- a/arch/x86/include/asm/pgtable_64_types.h
11731+++ b/arch/x86/include/asm/pgtable_64_types.h
11732@@ -59,5 +59,10 @@ typedef struct { pteval_t pte; } pte_t;
11733 #define MODULES_VADDR _AC(0xffffffffa0000000, UL)
11734 #define MODULES_END _AC(0xffffffffff000000, UL)
11735 #define MODULES_LEN (MODULES_END - MODULES_VADDR)
11736+#define MODULES_EXEC_VADDR MODULES_VADDR
11737+#define MODULES_EXEC_END MODULES_END
11738+
11739+#define ktla_ktva(addr) (addr)
11740+#define ktva_ktla(addr) (addr)
11741
11742 #endif /* _ASM_X86_PGTABLE_64_DEFS_H */
11743diff --git a/arch/x86/include/asm/pgtable_types.h b/arch/x86/include/asm/pgtable_types.h
11744index 013286a..8b42f4f 100644
11745--- a/arch/x86/include/asm/pgtable_types.h
11746+++ b/arch/x86/include/asm/pgtable_types.h
11747@@ -16,13 +16,12 @@
11748 #define _PAGE_BIT_PSE 7 /* 4 MB (or 2MB) page */
11749 #define _PAGE_BIT_PAT 7 /* on 4KB pages */
11750 #define _PAGE_BIT_GLOBAL 8 /* Global TLB entry PPro+ */
11751-#define _PAGE_BIT_UNUSED1 9 /* available for programmer */
11752+#define _PAGE_BIT_SPECIAL 9 /* special mappings, no associated struct page */
11753 #define _PAGE_BIT_IOMAP 10 /* flag used to indicate IO mapping */
11754 #define _PAGE_BIT_HIDDEN 11 /* hidden by kmemcheck */
11755 #define _PAGE_BIT_PAT_LARGE 12 /* On 2MB or 1GB pages */
11756-#define _PAGE_BIT_SPECIAL _PAGE_BIT_UNUSED1
11757-#define _PAGE_BIT_CPA_TEST _PAGE_BIT_UNUSED1
11758-#define _PAGE_BIT_SPLITTING _PAGE_BIT_UNUSED1 /* only valid on a PSE pmd */
11759+#define _PAGE_BIT_CPA_TEST _PAGE_BIT_SPECIAL
11760+#define _PAGE_BIT_SPLITTING _PAGE_BIT_SPECIAL /* only valid on a PSE pmd */
11761 #define _PAGE_BIT_NX 63 /* No execute: only valid after cpuid check */
11762
11763 /* If _PAGE_BIT_PRESENT is clear, we use these: */
11764@@ -40,7 +39,6 @@
11765 #define _PAGE_DIRTY (_AT(pteval_t, 1) << _PAGE_BIT_DIRTY)
11766 #define _PAGE_PSE (_AT(pteval_t, 1) << _PAGE_BIT_PSE)
11767 #define _PAGE_GLOBAL (_AT(pteval_t, 1) << _PAGE_BIT_GLOBAL)
11768-#define _PAGE_UNUSED1 (_AT(pteval_t, 1) << _PAGE_BIT_UNUSED1)
11769 #define _PAGE_IOMAP (_AT(pteval_t, 1) << _PAGE_BIT_IOMAP)
11770 #define _PAGE_PAT (_AT(pteval_t, 1) << _PAGE_BIT_PAT)
11771 #define _PAGE_PAT_LARGE (_AT(pteval_t, 1) << _PAGE_BIT_PAT_LARGE)
11772@@ -57,8 +55,10 @@
11773
11774 #if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
11775 #define _PAGE_NX (_AT(pteval_t, 1) << _PAGE_BIT_NX)
11776-#else
11777+#elif defined(CONFIG_KMEMCHECK)
11778 #define _PAGE_NX (_AT(pteval_t, 0))
11779+#else
11780+#define _PAGE_NX (_AT(pteval_t, 1) << _PAGE_BIT_HIDDEN)
11781 #endif
11782
11783 #define _PAGE_FILE (_AT(pteval_t, 1) << _PAGE_BIT_FILE)
11784@@ -96,6 +96,9 @@
11785 #define PAGE_READONLY_EXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | \
11786 _PAGE_ACCESSED)
11787
11788+#define PAGE_READONLY_NOEXEC PAGE_READONLY
11789+#define PAGE_SHARED_NOEXEC PAGE_SHARED
11790+
11791 #define __PAGE_KERNEL_EXEC \
11792 (_PAGE_PRESENT | _PAGE_RW | _PAGE_DIRTY | _PAGE_ACCESSED | _PAGE_GLOBAL)
11793 #define __PAGE_KERNEL (__PAGE_KERNEL_EXEC | _PAGE_NX)
11794@@ -106,7 +109,7 @@
11795 #define __PAGE_KERNEL_WC (__PAGE_KERNEL | _PAGE_CACHE_WC)
11796 #define __PAGE_KERNEL_NOCACHE (__PAGE_KERNEL | _PAGE_PCD | _PAGE_PWT)
11797 #define __PAGE_KERNEL_UC_MINUS (__PAGE_KERNEL | _PAGE_PCD)
11798-#define __PAGE_KERNEL_VSYSCALL (__PAGE_KERNEL_RX | _PAGE_USER)
11799+#define __PAGE_KERNEL_VSYSCALL (__PAGE_KERNEL_RO | _PAGE_USER)
11800 #define __PAGE_KERNEL_VVAR (__PAGE_KERNEL_RO | _PAGE_USER)
11801 #define __PAGE_KERNEL_VVAR_NOCACHE (__PAGE_KERNEL_VVAR | _PAGE_PCD | _PAGE_PWT)
11802 #define __PAGE_KERNEL_LARGE (__PAGE_KERNEL | _PAGE_PSE)
11803@@ -168,8 +171,8 @@
11804 * bits are combined, this will alow user to access the high address mapped
11805 * VDSO in the presence of CONFIG_COMPAT_VDSO
11806 */
11807-#define PTE_IDENT_ATTR 0x003 /* PRESENT+RW */
11808-#define PDE_IDENT_ATTR 0x067 /* PRESENT+RW+USER+DIRTY+ACCESSED */
11809+#define PTE_IDENT_ATTR 0x063 /* PRESENT+RW+DIRTY+ACCESSED */
11810+#define PDE_IDENT_ATTR 0x063 /* PRESENT+RW+DIRTY+ACCESSED */
11811 #define PGD_IDENT_ATTR 0x001 /* PRESENT (no other attributes) */
11812 #endif
11813
11814@@ -207,7 +210,17 @@ static inline pgdval_t pgd_flags(pgd_t pgd)
11815 {
11816 return native_pgd_val(pgd) & PTE_FLAGS_MASK;
11817 }
11818+#endif
11819
11820+#if PAGETABLE_LEVELS == 3
11821+#include <asm-generic/pgtable-nopud.h>
11822+#endif
11823+
11824+#if PAGETABLE_LEVELS == 2
11825+#include <asm-generic/pgtable-nopmd.h>
11826+#endif
11827+
11828+#ifndef __ASSEMBLY__
11829 #if PAGETABLE_LEVELS > 3
11830 typedef struct { pudval_t pud; } pud_t;
11831
11832@@ -221,8 +234,6 @@ static inline pudval_t native_pud_val(pud_t pud)
11833 return pud.pud;
11834 }
11835 #else
11836-#include <asm-generic/pgtable-nopud.h>
11837-
11838 static inline pudval_t native_pud_val(pud_t pud)
11839 {
11840 return native_pgd_val(pud.pgd);
11841@@ -242,8 +253,6 @@ static inline pmdval_t native_pmd_val(pmd_t pmd)
11842 return pmd.pmd;
11843 }
11844 #else
11845-#include <asm-generic/pgtable-nopmd.h>
11846-
11847 static inline pmdval_t native_pmd_val(pmd_t pmd)
11848 {
11849 return native_pgd_val(pmd.pud.pgd);
11850@@ -283,7 +292,6 @@ typedef struct page *pgtable_t;
11851
11852 extern pteval_t __supported_pte_mask;
11853 extern void set_nx(void);
11854-extern int nx_enabled;
11855
11856 #define pgprot_writecombine pgprot_writecombine
11857 extern pgprot_t pgprot_writecombine(pgprot_t prot);
11858diff --git a/arch/x86/include/asm/processor-flags.h b/arch/x86/include/asm/processor-flags.h
11859index aea1d1d..680cf09 100644
11860--- a/arch/x86/include/asm/processor-flags.h
11861+++ b/arch/x86/include/asm/processor-flags.h
11862@@ -65,6 +65,7 @@
11863 #define X86_CR4_PCIDE 0x00020000 /* enable PCID support */
11864 #define X86_CR4_OSXSAVE 0x00040000 /* enable xsave and xrestore */
11865 #define X86_CR4_SMEP 0x00100000 /* enable SMEP support */
11866+#define X86_CR4_SMAP 0x00200000 /* enable SMAP support */
11867
11868 /*
11869 * x86-64 Task Priority Register, CR8
11870diff --git a/arch/x86/include/asm/processor.h b/arch/x86/include/asm/processor.h
11871index d048cad..45e350f 100644
11872--- a/arch/x86/include/asm/processor.h
11873+++ b/arch/x86/include/asm/processor.h
11874@@ -289,7 +289,7 @@ struct tss_struct {
11875
11876 } ____cacheline_aligned;
11877
11878-DECLARE_PER_CPU_SHARED_ALIGNED(struct tss_struct, init_tss);
11879+extern struct tss_struct init_tss[NR_CPUS];
11880
11881 /*
11882 * Save the original ist values for checking stack pointers during debugging
11883@@ -822,11 +822,18 @@ static inline void spin_lock_prefetch(const void *x)
11884 */
11885 #define TASK_SIZE PAGE_OFFSET
11886 #define TASK_SIZE_MAX TASK_SIZE
11887+
11888+#ifdef CONFIG_PAX_SEGMEXEC
11889+#define SEGMEXEC_TASK_SIZE (TASK_SIZE / 2)
11890+#define STACK_TOP ((current->mm->pax_flags & MF_PAX_SEGMEXEC)?SEGMEXEC_TASK_SIZE:TASK_SIZE)
11891+#else
11892 #define STACK_TOP TASK_SIZE
11893-#define STACK_TOP_MAX STACK_TOP
11894+#endif
11895+
11896+#define STACK_TOP_MAX TASK_SIZE
11897
11898 #define INIT_THREAD { \
11899- .sp0 = sizeof(init_stack) + (long)&init_stack, \
11900+ .sp0 = sizeof(init_stack) + (long)&init_stack - 8, \
11901 .vm86_info = NULL, \
11902 .sysenter_cs = __KERNEL_CS, \
11903 .io_bitmap_ptr = NULL, \
11904@@ -840,7 +847,7 @@ static inline void spin_lock_prefetch(const void *x)
11905 */
11906 #define INIT_TSS { \
11907 .x86_tss = { \
11908- .sp0 = sizeof(init_stack) + (long)&init_stack, \
11909+ .sp0 = sizeof(init_stack) + (long)&init_stack - 8, \
11910 .ss0 = __KERNEL_DS, \
11911 .ss1 = __KERNEL_CS, \
11912 .io_bitmap_base = INVALID_IO_BITMAP_OFFSET, \
11913@@ -851,11 +858,7 @@ static inline void spin_lock_prefetch(const void *x)
11914 extern unsigned long thread_saved_pc(struct task_struct *tsk);
11915
11916 #define THREAD_SIZE_LONGS (THREAD_SIZE/sizeof(unsigned long))
11917-#define KSTK_TOP(info) \
11918-({ \
11919- unsigned long *__ptr = (unsigned long *)(info); \
11920- (unsigned long)(&__ptr[THREAD_SIZE_LONGS]); \
11921-})
11922+#define KSTK_TOP(info) ((container_of(info, struct task_struct, tinfo))->thread.sp0)
11923
11924 /*
11925 * The below -8 is to reserve 8 bytes on top of the ring0 stack.
11926@@ -870,7 +873,7 @@ extern unsigned long thread_saved_pc(struct task_struct *tsk);
11927 #define task_pt_regs(task) \
11928 ({ \
11929 struct pt_regs *__regs__; \
11930- __regs__ = (struct pt_regs *)(KSTK_TOP(task_stack_page(task))-8); \
11931+ __regs__ = (struct pt_regs *)((task)->thread.sp0); \
11932 __regs__ - 1; \
11933 })
11934
11935@@ -880,13 +883,13 @@ extern unsigned long thread_saved_pc(struct task_struct *tsk);
11936 /*
11937 * User space process size. 47bits minus one guard page.
11938 */
11939-#define TASK_SIZE_MAX ((1UL << 47) - PAGE_SIZE)
11940+#define TASK_SIZE_MAX ((1UL << TASK_SIZE_MAX_SHIFT) - PAGE_SIZE)
11941
11942 /* This decides where the kernel will search for a free chunk of vm
11943 * space during mmap's.
11944 */
11945 #define IA32_PAGE_OFFSET ((current->personality & ADDR_LIMIT_3GB) ? \
11946- 0xc0000000 : 0xFFFFe000)
11947+ 0xc0000000 : 0xFFFFf000)
11948
11949 #define TASK_SIZE (test_thread_flag(TIF_ADDR32) ? \
11950 IA32_PAGE_OFFSET : TASK_SIZE_MAX)
11951@@ -897,11 +900,11 @@ extern unsigned long thread_saved_pc(struct task_struct *tsk);
11952 #define STACK_TOP_MAX TASK_SIZE_MAX
11953
11954 #define INIT_THREAD { \
11955- .sp0 = (unsigned long)&init_stack + sizeof(init_stack) \
11956+ .sp0 = (unsigned long)&init_stack + sizeof(init_stack) - 16 \
11957 }
11958
11959 #define INIT_TSS { \
11960- .x86_tss.sp0 = (unsigned long)&init_stack + sizeof(init_stack) \
11961+ .x86_tss.sp0 = (unsigned long)&init_stack + sizeof(init_stack) - 16 \
11962 }
11963
11964 /*
11965@@ -929,6 +932,10 @@ extern void start_thread(struct pt_regs *regs, unsigned long new_ip,
11966 */
11967 #define TASK_UNMAPPED_BASE (PAGE_ALIGN(TASK_SIZE / 3))
11968
11969+#ifdef CONFIG_PAX_SEGMEXEC
11970+#define SEGMEXEC_TASK_UNMAPPED_BASE (PAGE_ALIGN(SEGMEXEC_TASK_SIZE / 3))
11971+#endif
11972+
11973 #define KSTK_EIP(task) (task_pt_regs(task)->ip)
11974
11975 /* Get/set a process' ability to use the timestamp counter instruction */
11976@@ -989,12 +996,12 @@ extern bool cpu_has_amd_erratum(const int *);
11977 #define cpu_has_amd_erratum(x) (false)
11978 #endif /* CONFIG_CPU_SUP_AMD */
11979
11980-extern unsigned long arch_align_stack(unsigned long sp);
11981+#define arch_align_stack(x) ((x) & ~0xfUL)
11982 extern void free_init_pages(char *what, unsigned long begin, unsigned long end);
11983
11984 void default_idle(void);
11985 bool set_pm_idle_to_default(void);
11986
11987-void stop_this_cpu(void *dummy);
11988+void stop_this_cpu(void *dummy) __noreturn;
11989
11990 #endif /* _ASM_X86_PROCESSOR_H */
11991diff --git a/arch/x86/include/asm/ptrace.h b/arch/x86/include/asm/ptrace.h
11992index dcfde52..dbfea06 100644
11993--- a/arch/x86/include/asm/ptrace.h
11994+++ b/arch/x86/include/asm/ptrace.h
11995@@ -155,28 +155,29 @@ static inline unsigned long regs_return_value(struct pt_regs *regs)
11996 }
11997
11998 /*
11999- * user_mode_vm(regs) determines whether a register set came from user mode.
12000+ * user_mode(regs) determines whether a register set came from user mode.
12001 * This is true if V8086 mode was enabled OR if the register set was from
12002 * protected mode with RPL-3 CS value. This tricky test checks that with
12003 * one comparison. Many places in the kernel can bypass this full check
12004- * if they have already ruled out V8086 mode, so user_mode(regs) can be used.
12005+ * if they have already ruled out V8086 mode, so user_mode_novm(regs) can
12006+ * be used.
12007 */
12008-static inline int user_mode(struct pt_regs *regs)
12009+static inline int user_mode_novm(struct pt_regs *regs)
12010 {
12011 #ifdef CONFIG_X86_32
12012 return (regs->cs & SEGMENT_RPL_MASK) == USER_RPL;
12013 #else
12014- return !!(regs->cs & 3);
12015+ return !!(regs->cs & SEGMENT_RPL_MASK);
12016 #endif
12017 }
12018
12019-static inline int user_mode_vm(struct pt_regs *regs)
12020+static inline int user_mode(struct pt_regs *regs)
12021 {
12022 #ifdef CONFIG_X86_32
12023 return ((regs->cs & SEGMENT_RPL_MASK) | (regs->flags & X86_VM_MASK)) >=
12024 USER_RPL;
12025 #else
12026- return user_mode(regs);
12027+ return user_mode_novm(regs);
12028 #endif
12029 }
12030
12031@@ -192,15 +193,16 @@ static inline int v8086_mode(struct pt_regs *regs)
12032 #ifdef CONFIG_X86_64
12033 static inline bool user_64bit_mode(struct pt_regs *regs)
12034 {
12035+ unsigned long cs = regs->cs & 0xffff;
12036 #ifndef CONFIG_PARAVIRT
12037 /*
12038 * On non-paravirt systems, this is the only long mode CPL 3
12039 * selector. We do not allow long mode selectors in the LDT.
12040 */
12041- return regs->cs == __USER_CS;
12042+ return cs == __USER_CS;
12043 #else
12044 /* Headers are too twisted for this to go in paravirt.h. */
12045- return regs->cs == __USER_CS || regs->cs == pv_info.extra_user_64bit_cs;
12046+ return cs == __USER_CS || cs == pv_info.extra_user_64bit_cs;
12047 #endif
12048 }
12049 #endif
12050diff --git a/arch/x86/include/asm/realmode.h b/arch/x86/include/asm/realmode.h
12051index fe1ec5b..dc5c3fe 100644
12052--- a/arch/x86/include/asm/realmode.h
12053+++ b/arch/x86/include/asm/realmode.h
12054@@ -22,16 +22,14 @@ struct real_mode_header {
12055 #endif
12056 /* APM/BIOS reboot */
12057 u32 machine_real_restart_asm;
12058-#ifdef CONFIG_X86_64
12059 u32 machine_real_restart_seg;
12060-#endif
12061 };
12062
12063 /* This must match data at trampoline_32/64.S */
12064 struct trampoline_header {
12065 #ifdef CONFIG_X86_32
12066 u32 start;
12067- u16 gdt_pad;
12068+ u16 boot_cs;
12069 u16 gdt_limit;
12070 u32 gdt_base;
12071 #else
12072diff --git a/arch/x86/include/asm/reboot.h b/arch/x86/include/asm/reboot.h
12073index a82c4f1..ac45053 100644
12074--- a/arch/x86/include/asm/reboot.h
12075+++ b/arch/x86/include/asm/reboot.h
12076@@ -6,13 +6,13 @@
12077 struct pt_regs;
12078
12079 struct machine_ops {
12080- void (*restart)(char *cmd);
12081- void (*halt)(void);
12082- void (*power_off)(void);
12083+ void (* __noreturn restart)(char *cmd);
12084+ void (* __noreturn halt)(void);
12085+ void (* __noreturn power_off)(void);
12086 void (*shutdown)(void);
12087 void (*crash_shutdown)(struct pt_regs *);
12088- void (*emergency_restart)(void);
12089-};
12090+ void (* __noreturn emergency_restart)(void);
12091+} __no_const;
12092
12093 extern struct machine_ops machine_ops;
12094
12095diff --git a/arch/x86/include/asm/rwsem.h b/arch/x86/include/asm/rwsem.h
12096index 2dbe4a7..ce1db00 100644
12097--- a/arch/x86/include/asm/rwsem.h
12098+++ b/arch/x86/include/asm/rwsem.h
12099@@ -64,6 +64,14 @@ static inline void __down_read(struct rw_semaphore *sem)
12100 {
12101 asm volatile("# beginning down_read\n\t"
12102 LOCK_PREFIX _ASM_INC "(%1)\n\t"
12103+
12104+#ifdef CONFIG_PAX_REFCOUNT
12105+ "jno 0f\n"
12106+ LOCK_PREFIX _ASM_DEC "(%1)\n"
12107+ "int $4\n0:\n"
12108+ _ASM_EXTABLE(0b, 0b)
12109+#endif
12110+
12111 /* adds 0x00000001 */
12112 " jns 1f\n"
12113 " call call_rwsem_down_read_failed\n"
12114@@ -85,6 +93,14 @@ static inline int __down_read_trylock(struct rw_semaphore *sem)
12115 "1:\n\t"
12116 " mov %1,%2\n\t"
12117 " add %3,%2\n\t"
12118+
12119+#ifdef CONFIG_PAX_REFCOUNT
12120+ "jno 0f\n"
12121+ "sub %3,%2\n"
12122+ "int $4\n0:\n"
12123+ _ASM_EXTABLE(0b, 0b)
12124+#endif
12125+
12126 " jle 2f\n\t"
12127 LOCK_PREFIX " cmpxchg %2,%0\n\t"
12128 " jnz 1b\n\t"
12129@@ -104,6 +120,14 @@ static inline void __down_write_nested(struct rw_semaphore *sem, int subclass)
12130 long tmp;
12131 asm volatile("# beginning down_write\n\t"
12132 LOCK_PREFIX " xadd %1,(%2)\n\t"
12133+
12134+#ifdef CONFIG_PAX_REFCOUNT
12135+ "jno 0f\n"
12136+ "mov %1,(%2)\n"
12137+ "int $4\n0:\n"
12138+ _ASM_EXTABLE(0b, 0b)
12139+#endif
12140+
12141 /* adds 0xffff0001, returns the old value */
12142 " test %1,%1\n\t"
12143 /* was the count 0 before? */
12144@@ -141,6 +165,14 @@ static inline void __up_read(struct rw_semaphore *sem)
12145 long tmp;
12146 asm volatile("# beginning __up_read\n\t"
12147 LOCK_PREFIX " xadd %1,(%2)\n\t"
12148+
12149+#ifdef CONFIG_PAX_REFCOUNT
12150+ "jno 0f\n"
12151+ "mov %1,(%2)\n"
12152+ "int $4\n0:\n"
12153+ _ASM_EXTABLE(0b, 0b)
12154+#endif
12155+
12156 /* subtracts 1, returns the old value */
12157 " jns 1f\n\t"
12158 " call call_rwsem_wake\n" /* expects old value in %edx */
12159@@ -159,6 +191,14 @@ static inline void __up_write(struct rw_semaphore *sem)
12160 long tmp;
12161 asm volatile("# beginning __up_write\n\t"
12162 LOCK_PREFIX " xadd %1,(%2)\n\t"
12163+
12164+#ifdef CONFIG_PAX_REFCOUNT
12165+ "jno 0f\n"
12166+ "mov %1,(%2)\n"
12167+ "int $4\n0:\n"
12168+ _ASM_EXTABLE(0b, 0b)
12169+#endif
12170+
12171 /* subtracts 0xffff0001, returns the old value */
12172 " jns 1f\n\t"
12173 " call call_rwsem_wake\n" /* expects old value in %edx */
12174@@ -176,6 +216,14 @@ static inline void __downgrade_write(struct rw_semaphore *sem)
12175 {
12176 asm volatile("# beginning __downgrade_write\n\t"
12177 LOCK_PREFIX _ASM_ADD "%2,(%1)\n\t"
12178+
12179+#ifdef CONFIG_PAX_REFCOUNT
12180+ "jno 0f\n"
12181+ LOCK_PREFIX _ASM_SUB "%2,(%1)\n"
12182+ "int $4\n0:\n"
12183+ _ASM_EXTABLE(0b, 0b)
12184+#endif
12185+
12186 /*
12187 * transitions 0xZZZZ0001 -> 0xYYYY0001 (i386)
12188 * 0xZZZZZZZZ00000001 -> 0xYYYYYYYY00000001 (x86_64)
12189@@ -194,7 +242,15 @@ static inline void __downgrade_write(struct rw_semaphore *sem)
12190 */
12191 static inline void rwsem_atomic_add(long delta, struct rw_semaphore *sem)
12192 {
12193- asm volatile(LOCK_PREFIX _ASM_ADD "%1,%0"
12194+ asm volatile(LOCK_PREFIX _ASM_ADD "%1,%0\n"
12195+
12196+#ifdef CONFIG_PAX_REFCOUNT
12197+ "jno 0f\n"
12198+ LOCK_PREFIX _ASM_SUB "%1,%0\n"
12199+ "int $4\n0:\n"
12200+ _ASM_EXTABLE(0b, 0b)
12201+#endif
12202+
12203 : "+m" (sem->count)
12204 : "er" (delta));
12205 }
12206@@ -204,7 +260,7 @@ static inline void rwsem_atomic_add(long delta, struct rw_semaphore *sem)
12207 */
12208 static inline long rwsem_atomic_update(long delta, struct rw_semaphore *sem)
12209 {
12210- return delta + xadd(&sem->count, delta);
12211+ return delta + xadd_check_overflow(&sem->count, delta);
12212 }
12213
12214 #endif /* __KERNEL__ */
12215diff --git a/arch/x86/include/asm/segment.h b/arch/x86/include/asm/segment.h
12216index c48a950..c6d7468 100644
12217--- a/arch/x86/include/asm/segment.h
12218+++ b/arch/x86/include/asm/segment.h
12219@@ -64,10 +64,15 @@
12220 * 26 - ESPFIX small SS
12221 * 27 - per-cpu [ offset to per-cpu data area ]
12222 * 28 - stack_canary-20 [ for stack protector ]
12223- * 29 - unused
12224- * 30 - unused
12225+ * 29 - PCI BIOS CS
12226+ * 30 - PCI BIOS DS
12227 * 31 - TSS for double fault handler
12228 */
12229+#define GDT_ENTRY_KERNEXEC_EFI_CS (1)
12230+#define GDT_ENTRY_KERNEXEC_EFI_DS (2)
12231+#define __KERNEXEC_EFI_CS (GDT_ENTRY_KERNEXEC_EFI_CS*8)
12232+#define __KERNEXEC_EFI_DS (GDT_ENTRY_KERNEXEC_EFI_DS*8)
12233+
12234 #define GDT_ENTRY_TLS_MIN 6
12235 #define GDT_ENTRY_TLS_MAX (GDT_ENTRY_TLS_MIN + GDT_ENTRY_TLS_ENTRIES - 1)
12236
12237@@ -79,6 +84,8 @@
12238
12239 #define GDT_ENTRY_KERNEL_CS (GDT_ENTRY_KERNEL_BASE+0)
12240
12241+#define GDT_ENTRY_KERNEXEC_KERNEL_CS (4)
12242+
12243 #define GDT_ENTRY_KERNEL_DS (GDT_ENTRY_KERNEL_BASE+1)
12244
12245 #define GDT_ENTRY_TSS (GDT_ENTRY_KERNEL_BASE+4)
12246@@ -104,6 +111,12 @@
12247 #define __KERNEL_STACK_CANARY 0
12248 #endif
12249
12250+#define GDT_ENTRY_PCIBIOS_CS (GDT_ENTRY_KERNEL_BASE+17)
12251+#define __PCIBIOS_CS (GDT_ENTRY_PCIBIOS_CS * 8)
12252+
12253+#define GDT_ENTRY_PCIBIOS_DS (GDT_ENTRY_KERNEL_BASE+18)
12254+#define __PCIBIOS_DS (GDT_ENTRY_PCIBIOS_DS * 8)
12255+
12256 #define GDT_ENTRY_DOUBLEFAULT_TSS 31
12257
12258 /*
12259@@ -141,7 +154,7 @@
12260 */
12261
12262 /* Matches PNP_CS32 and PNP_CS16 (they must be consecutive) */
12263-#define SEGMENT_IS_PNP_CODE(x) (((x) & 0xf4) == GDT_ENTRY_PNPBIOS_BASE * 8)
12264+#define SEGMENT_IS_PNP_CODE(x) (((x) & 0xFFFCU) == PNP_CS32 || ((x) & 0xFFFCU) == PNP_CS16)
12265
12266
12267 #else
12268@@ -165,6 +178,8 @@
12269 #define __USER32_CS (GDT_ENTRY_DEFAULT_USER32_CS*8+3)
12270 #define __USER32_DS __USER_DS
12271
12272+#define GDT_ENTRY_KERNEXEC_KERNEL_CS 7
12273+
12274 #define GDT_ENTRY_TSS 8 /* needs two entries */
12275 #define GDT_ENTRY_LDT 10 /* needs two entries */
12276 #define GDT_ENTRY_TLS_MIN 12
12277@@ -185,6 +200,7 @@
12278 #endif
12279
12280 #define __KERNEL_CS (GDT_ENTRY_KERNEL_CS*8)
12281+#define __KERNEXEC_KERNEL_CS (GDT_ENTRY_KERNEXEC_KERNEL_CS*8)
12282 #define __KERNEL_DS (GDT_ENTRY_KERNEL_DS*8)
12283 #define __USER_DS (GDT_ENTRY_DEFAULT_USER_DS*8+3)
12284 #define __USER_CS (GDT_ENTRY_DEFAULT_USER_CS*8+3)
12285@@ -265,7 +281,7 @@ static inline unsigned long get_limit(unsigned long segment)
12286 {
12287 unsigned long __limit;
12288 asm("lsll %1,%0" : "=r" (__limit) : "r" (segment));
12289- return __limit + 1;
12290+ return __limit;
12291 }
12292
12293 #endif /* !__ASSEMBLY__ */
12294diff --git a/arch/x86/include/asm/smp.h b/arch/x86/include/asm/smp.h
12295index 4f19a15..9e14f27 100644
12296--- a/arch/x86/include/asm/smp.h
12297+++ b/arch/x86/include/asm/smp.h
12298@@ -36,7 +36,7 @@ DECLARE_PER_CPU_READ_MOSTLY(cpumask_var_t, cpu_core_map);
12299 /* cpus sharing the last level cache: */
12300 DECLARE_PER_CPU_READ_MOSTLY(cpumask_var_t, cpu_llc_shared_map);
12301 DECLARE_PER_CPU_READ_MOSTLY(u16, cpu_llc_id);
12302-DECLARE_PER_CPU_READ_MOSTLY(int, cpu_number);
12303+DECLARE_PER_CPU_READ_MOSTLY(unsigned int, cpu_number);
12304
12305 static inline struct cpumask *cpu_sibling_mask(int cpu)
12306 {
12307@@ -79,7 +79,7 @@ struct smp_ops {
12308
12309 void (*send_call_func_ipi)(const struct cpumask *mask);
12310 void (*send_call_func_single_ipi)(int cpu);
12311-};
12312+} __no_const;
12313
12314 /* Globals due to paravirt */
12315 extern void set_cpu_sibling_map(int cpu);
12316@@ -190,14 +190,8 @@ extern unsigned disabled_cpus __cpuinitdata;
12317 extern int safe_smp_processor_id(void);
12318
12319 #elif defined(CONFIG_X86_64_SMP)
12320-#define raw_smp_processor_id() (this_cpu_read(cpu_number))
12321-
12322-#define stack_smp_processor_id() \
12323-({ \
12324- struct thread_info *ti; \
12325- __asm__("andq %%rsp,%0; ":"=r" (ti) : "0" (CURRENT_MASK)); \
12326- ti->cpu; \
12327-})
12328+#define raw_smp_processor_id() (this_cpu_read(cpu_number))
12329+#define stack_smp_processor_id() raw_smp_processor_id()
12330 #define safe_smp_processor_id() smp_processor_id()
12331
12332 #endif
12333diff --git a/arch/x86/include/asm/spinlock.h b/arch/x86/include/asm/spinlock.h
12334index 33692ea..350a534 100644
12335--- a/arch/x86/include/asm/spinlock.h
12336+++ b/arch/x86/include/asm/spinlock.h
12337@@ -172,6 +172,14 @@ static inline int arch_write_can_lock(arch_rwlock_t *lock)
12338 static inline void arch_read_lock(arch_rwlock_t *rw)
12339 {
12340 asm volatile(LOCK_PREFIX READ_LOCK_SIZE(dec) " (%0)\n\t"
12341+
12342+#ifdef CONFIG_PAX_REFCOUNT
12343+ "jno 0f\n"
12344+ LOCK_PREFIX READ_LOCK_SIZE(inc) " (%0)\n"
12345+ "int $4\n0:\n"
12346+ _ASM_EXTABLE(0b, 0b)
12347+#endif
12348+
12349 "jns 1f\n"
12350 "call __read_lock_failed\n\t"
12351 "1:\n"
12352@@ -181,6 +189,14 @@ static inline void arch_read_lock(arch_rwlock_t *rw)
12353 static inline void arch_write_lock(arch_rwlock_t *rw)
12354 {
12355 asm volatile(LOCK_PREFIX WRITE_LOCK_SUB(%1) "(%0)\n\t"
12356+
12357+#ifdef CONFIG_PAX_REFCOUNT
12358+ "jno 0f\n"
12359+ LOCK_PREFIX WRITE_LOCK_ADD(%1) "(%0)\n"
12360+ "int $4\n0:\n"
12361+ _ASM_EXTABLE(0b, 0b)
12362+#endif
12363+
12364 "jz 1f\n"
12365 "call __write_lock_failed\n\t"
12366 "1:\n"
12367@@ -210,13 +226,29 @@ static inline int arch_write_trylock(arch_rwlock_t *lock)
12368
12369 static inline void arch_read_unlock(arch_rwlock_t *rw)
12370 {
12371- asm volatile(LOCK_PREFIX READ_LOCK_SIZE(inc) " %0"
12372+ asm volatile(LOCK_PREFIX READ_LOCK_SIZE(inc) " %0\n"
12373+
12374+#ifdef CONFIG_PAX_REFCOUNT
12375+ "jno 0f\n"
12376+ LOCK_PREFIX READ_LOCK_SIZE(dec) " %0\n"
12377+ "int $4\n0:\n"
12378+ _ASM_EXTABLE(0b, 0b)
12379+#endif
12380+
12381 :"+m" (rw->lock) : : "memory");
12382 }
12383
12384 static inline void arch_write_unlock(arch_rwlock_t *rw)
12385 {
12386- asm volatile(LOCK_PREFIX WRITE_LOCK_ADD(%1) "%0"
12387+ asm volatile(LOCK_PREFIX WRITE_LOCK_ADD(%1) "%0\n"
12388+
12389+#ifdef CONFIG_PAX_REFCOUNT
12390+ "jno 0f\n"
12391+ LOCK_PREFIX WRITE_LOCK_SUB(%1) "%0\n"
12392+ "int $4\n0:\n"
12393+ _ASM_EXTABLE(0b, 0b)
12394+#endif
12395+
12396 : "+m" (rw->write) : "i" (RW_LOCK_BIAS) : "memory");
12397 }
12398
12399diff --git a/arch/x86/include/asm/stackprotector.h b/arch/x86/include/asm/stackprotector.h
12400index 6a99859..03cb807 100644
12401--- a/arch/x86/include/asm/stackprotector.h
12402+++ b/arch/x86/include/asm/stackprotector.h
12403@@ -47,7 +47,7 @@
12404 * head_32 for boot CPU and setup_per_cpu_areas() for others.
12405 */
12406 #define GDT_STACK_CANARY_INIT \
12407- [GDT_ENTRY_STACK_CANARY] = GDT_ENTRY_INIT(0x4090, 0, 0x18),
12408+ [GDT_ENTRY_STACK_CANARY] = GDT_ENTRY_INIT(0x4090, 0, 0x17),
12409
12410 /*
12411 * Initialize the stackprotector canary value.
12412@@ -112,7 +112,7 @@ static inline void setup_stack_canary_segment(int cpu)
12413
12414 static inline void load_stack_canary_segment(void)
12415 {
12416-#ifdef CONFIG_X86_32
12417+#if defined(CONFIG_X86_32) && !defined(CONFIG_PAX_MEMORY_UDEREF)
12418 asm volatile ("mov %0, %%gs" : : "r" (0));
12419 #endif
12420 }
12421diff --git a/arch/x86/include/asm/stacktrace.h b/arch/x86/include/asm/stacktrace.h
12422index 70bbe39..4ae2bd4 100644
12423--- a/arch/x86/include/asm/stacktrace.h
12424+++ b/arch/x86/include/asm/stacktrace.h
12425@@ -11,28 +11,20 @@
12426
12427 extern int kstack_depth_to_print;
12428
12429-struct thread_info;
12430+struct task_struct;
12431 struct stacktrace_ops;
12432
12433-typedef unsigned long (*walk_stack_t)(struct thread_info *tinfo,
12434- unsigned long *stack,
12435- unsigned long bp,
12436- const struct stacktrace_ops *ops,
12437- void *data,
12438- unsigned long *end,
12439- int *graph);
12440+typedef unsigned long walk_stack_t(struct task_struct *task,
12441+ void *stack_start,
12442+ unsigned long *stack,
12443+ unsigned long bp,
12444+ const struct stacktrace_ops *ops,
12445+ void *data,
12446+ unsigned long *end,
12447+ int *graph);
12448
12449-extern unsigned long
12450-print_context_stack(struct thread_info *tinfo,
12451- unsigned long *stack, unsigned long bp,
12452- const struct stacktrace_ops *ops, void *data,
12453- unsigned long *end, int *graph);
12454-
12455-extern unsigned long
12456-print_context_stack_bp(struct thread_info *tinfo,
12457- unsigned long *stack, unsigned long bp,
12458- const struct stacktrace_ops *ops, void *data,
12459- unsigned long *end, int *graph);
12460+extern walk_stack_t print_context_stack;
12461+extern walk_stack_t print_context_stack_bp;
12462
12463 /* Generic stack tracer with callbacks */
12464
12465@@ -40,7 +32,7 @@ struct stacktrace_ops {
12466 void (*address)(void *data, unsigned long address, int reliable);
12467 /* On negative return stop dumping */
12468 int (*stack)(void *data, char *name);
12469- walk_stack_t walk_stack;
12470+ walk_stack_t *walk_stack;
12471 };
12472
12473 void dump_trace(struct task_struct *tsk, struct pt_regs *regs,
12474diff --git a/arch/x86/include/asm/switch_to.h b/arch/x86/include/asm/switch_to.h
12475index 4ec45b3..a4f0a8a 100644
12476--- a/arch/x86/include/asm/switch_to.h
12477+++ b/arch/x86/include/asm/switch_to.h
12478@@ -108,7 +108,7 @@ do { \
12479 "call __switch_to\n\t" \
12480 "movq "__percpu_arg([current_task])",%%rsi\n\t" \
12481 __switch_canary \
12482- "movq %P[thread_info](%%rsi),%%r8\n\t" \
12483+ "movq "__percpu_arg([thread_info])",%%r8\n\t" \
12484 "movq %%rax,%%rdi\n\t" \
12485 "testl %[_tif_fork],%P[ti_flags](%%r8)\n\t" \
12486 "jnz ret_from_fork\n\t" \
12487@@ -119,7 +119,7 @@ do { \
12488 [threadrsp] "i" (offsetof(struct task_struct, thread.sp)), \
12489 [ti_flags] "i" (offsetof(struct thread_info, flags)), \
12490 [_tif_fork] "i" (_TIF_FORK), \
12491- [thread_info] "i" (offsetof(struct task_struct, stack)), \
12492+ [thread_info] "m" (current_tinfo), \
12493 [current_task] "m" (current_task) \
12494 __switch_canary_iparam \
12495 : "memory", "cc" __EXTRA_CLOBBER)
12496diff --git a/arch/x86/include/asm/sys_ia32.h b/arch/x86/include/asm/sys_ia32.h
12497index 3fda9db4..4ca1c61 100644
12498--- a/arch/x86/include/asm/sys_ia32.h
12499+++ b/arch/x86/include/asm/sys_ia32.h
12500@@ -40,7 +40,7 @@ asmlinkage long sys32_sigaction(int, struct old_sigaction32 __user *,
12501 struct old_sigaction32 __user *);
12502 asmlinkage long sys32_alarm(unsigned int);
12503
12504-asmlinkage long sys32_waitpid(compat_pid_t, unsigned int *, int);
12505+asmlinkage long sys32_waitpid(compat_pid_t, unsigned int __user *, int);
12506 asmlinkage long sys32_sysfs(int, u32, u32);
12507
12508 asmlinkage long sys32_sched_rr_get_interval(compat_pid_t,
12509diff --git a/arch/x86/include/asm/thread_info.h b/arch/x86/include/asm/thread_info.h
12510index 89f794f..1422765 100644
12511--- a/arch/x86/include/asm/thread_info.h
12512+++ b/arch/x86/include/asm/thread_info.h
12513@@ -10,6 +10,7 @@
12514 #include <linux/compiler.h>
12515 #include <asm/page.h>
12516 #include <asm/types.h>
12517+#include <asm/percpu.h>
12518
12519 /*
12520 * low level task data that entry.S needs immediate access to
12521@@ -24,7 +25,6 @@ struct exec_domain;
12522 #include <linux/atomic.h>
12523
12524 struct thread_info {
12525- struct task_struct *task; /* main task structure */
12526 struct exec_domain *exec_domain; /* execution domain */
12527 __u32 flags; /* low level flags */
12528 __u32 status; /* thread synchronous flags */
12529@@ -34,19 +34,13 @@ struct thread_info {
12530 mm_segment_t addr_limit;
12531 struct restart_block restart_block;
12532 void __user *sysenter_return;
12533-#ifdef CONFIG_X86_32
12534- unsigned long previous_esp; /* ESP of the previous stack in
12535- case of nested (IRQ) stacks
12536- */
12537- __u8 supervisor_stack[0];
12538-#endif
12539+ unsigned long lowest_stack;
12540 unsigned int sig_on_uaccess_error:1;
12541 unsigned int uaccess_err:1; /* uaccess failed */
12542 };
12543
12544-#define INIT_THREAD_INFO(tsk) \
12545+#define INIT_THREAD_INFO \
12546 { \
12547- .task = &tsk, \
12548 .exec_domain = &default_exec_domain, \
12549 .flags = 0, \
12550 .cpu = 0, \
12551@@ -57,7 +51,7 @@ struct thread_info {
12552 }, \
12553 }
12554
12555-#define init_thread_info (init_thread_union.thread_info)
12556+#define init_thread_info (init_thread_union.stack)
12557 #define init_stack (init_thread_union.stack)
12558
12559 #else /* !__ASSEMBLY__ */
12560@@ -98,6 +92,7 @@ struct thread_info {
12561 #define TIF_SYSCALL_TRACEPOINT 28 /* syscall tracepoint instrumentation */
12562 #define TIF_ADDR32 29 /* 32-bit address space on 64 bits */
12563 #define TIF_X32 30 /* 32-bit native x86-64 binary */
12564+#define TIF_GRSEC_SETXID 31 /* update credentials on syscall entry/exit */
12565
12566 #define _TIF_SYSCALL_TRACE (1 << TIF_SYSCALL_TRACE)
12567 #define _TIF_NOTIFY_RESUME (1 << TIF_NOTIFY_RESUME)
12568@@ -122,16 +117,18 @@ struct thread_info {
12569 #define _TIF_SYSCALL_TRACEPOINT (1 << TIF_SYSCALL_TRACEPOINT)
12570 #define _TIF_ADDR32 (1 << TIF_ADDR32)
12571 #define _TIF_X32 (1 << TIF_X32)
12572+#define _TIF_GRSEC_SETXID (1 << TIF_GRSEC_SETXID)
12573
12574 /* work to do in syscall_trace_enter() */
12575 #define _TIF_WORK_SYSCALL_ENTRY \
12576 (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_EMU | _TIF_SYSCALL_AUDIT | \
12577- _TIF_SECCOMP | _TIF_SINGLESTEP | _TIF_SYSCALL_TRACEPOINT)
12578+ _TIF_SECCOMP | _TIF_SINGLESTEP | _TIF_SYSCALL_TRACEPOINT | \
12579+ _TIF_GRSEC_SETXID)
12580
12581 /* work to do in syscall_trace_leave() */
12582 #define _TIF_WORK_SYSCALL_EXIT \
12583 (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | _TIF_SINGLESTEP | \
12584- _TIF_SYSCALL_TRACEPOINT)
12585+ _TIF_SYSCALL_TRACEPOINT | _TIF_GRSEC_SETXID)
12586
12587 /* work to do on interrupt/exception return */
12588 #define _TIF_WORK_MASK \
12589@@ -141,7 +138,8 @@ struct thread_info {
12590
12591 /* work to do on any return to user space */
12592 #define _TIF_ALLWORK_MASK \
12593- ((0x0000FFFF & ~_TIF_SECCOMP) | _TIF_SYSCALL_TRACEPOINT)
12594+ ((0x0000FFFF & ~_TIF_SECCOMP) | _TIF_SYSCALL_TRACEPOINT | \
12595+ _TIF_GRSEC_SETXID)
12596
12597 /* Only used for 64 bit */
12598 #define _TIF_DO_NOTIFY_MASK \
12599@@ -157,45 +155,40 @@ struct thread_info {
12600
12601 #define PREEMPT_ACTIVE 0x10000000
12602
12603-#ifdef CONFIG_X86_32
12604-
12605-#define STACK_WARN (THREAD_SIZE/8)
12606-/*
12607- * macros/functions for gaining access to the thread information structure
12608- *
12609- * preempt_count needs to be 1 initially, until the scheduler is functional.
12610- */
12611-#ifndef __ASSEMBLY__
12612-
12613-
12614-/* how to get the current stack pointer from C */
12615-register unsigned long current_stack_pointer asm("esp") __used;
12616-
12617-/* how to get the thread information struct from C */
12618-static inline struct thread_info *current_thread_info(void)
12619-{
12620- return (struct thread_info *)
12621- (current_stack_pointer & ~(THREAD_SIZE - 1));
12622-}
12623-
12624-#else /* !__ASSEMBLY__ */
12625-
12626+#ifdef __ASSEMBLY__
12627 /* how to get the thread information struct from ASM */
12628 #define GET_THREAD_INFO(reg) \
12629- movl $-THREAD_SIZE, reg; \
12630- andl %esp, reg
12631+ mov PER_CPU_VAR(current_tinfo), reg
12632
12633 /* use this one if reg already contains %esp */
12634-#define GET_THREAD_INFO_WITH_ESP(reg) \
12635- andl $-THREAD_SIZE, reg
12636+#define GET_THREAD_INFO_WITH_ESP(reg) GET_THREAD_INFO(reg)
12637+#else
12638+/* how to get the thread information struct from C */
12639+DECLARE_PER_CPU(struct thread_info *, current_tinfo);
12640+
12641+static __always_inline struct thread_info *current_thread_info(void)
12642+{
12643+ return this_cpu_read_stable(current_tinfo);
12644+}
12645+#endif
12646+
12647+#ifdef CONFIG_X86_32
12648+
12649+#define STACK_WARN (THREAD_SIZE/8)
12650+/*
12651+ * macros/functions for gaining access to the thread information structure
12652+ *
12653+ * preempt_count needs to be 1 initially, until the scheduler is functional.
12654+ */
12655+#ifndef __ASSEMBLY__
12656+
12657+/* how to get the current stack pointer from C */
12658+register unsigned long current_stack_pointer asm("esp") __used;
12659
12660 #endif
12661
12662 #else /* X86_32 */
12663
12664-#include <asm/percpu.h>
12665-#define KERNEL_STACK_OFFSET (5*8)
12666-
12667 /*
12668 * macros/functions for gaining access to the thread information structure
12669 * preempt_count needs to be 1 initially, until the scheduler is functional.
12670@@ -203,27 +196,8 @@ static inline struct thread_info *current_thread_info(void)
12671 #ifndef __ASSEMBLY__
12672 DECLARE_PER_CPU(unsigned long, kernel_stack);
12673
12674-static inline struct thread_info *current_thread_info(void)
12675-{
12676- struct thread_info *ti;
12677- ti = (void *)(this_cpu_read_stable(kernel_stack) +
12678- KERNEL_STACK_OFFSET - THREAD_SIZE);
12679- return ti;
12680-}
12681-
12682-#else /* !__ASSEMBLY__ */
12683-
12684-/* how to get the thread information struct from ASM */
12685-#define GET_THREAD_INFO(reg) \
12686- movq PER_CPU_VAR(kernel_stack),reg ; \
12687- subq $(THREAD_SIZE-KERNEL_STACK_OFFSET),reg
12688-
12689-/*
12690- * Same if PER_CPU_VAR(kernel_stack) is, perhaps with some offset, already in
12691- * a certain register (to be used in assembler memory operands).
12692- */
12693-#define THREAD_INFO(reg, off) KERNEL_STACK_OFFSET+(off)-THREAD_SIZE(reg)
12694-
12695+/* how to get the current stack pointer from C */
12696+register unsigned long current_stack_pointer asm("rsp") __used;
12697 #endif
12698
12699 #endif /* !X86_32 */
12700@@ -284,5 +258,12 @@ static inline bool is_ia32_task(void)
12701 extern void arch_task_cache_init(void);
12702 extern int arch_dup_task_struct(struct task_struct *dst, struct task_struct *src);
12703 extern void arch_release_task_struct(struct task_struct *tsk);
12704+
12705+#define __HAVE_THREAD_FUNCTIONS
12706+#define task_thread_info(task) (&(task)->tinfo)
12707+#define task_stack_page(task) ((task)->stack)
12708+#define setup_thread_stack(p, org) do {} while (0)
12709+#define end_of_stack(p) ((unsigned long *)task_stack_page(p) + 1)
12710+
12711 #endif
12712 #endif /* _ASM_X86_THREAD_INFO_H */
12713diff --git a/arch/x86/include/asm/uaccess.h b/arch/x86/include/asm/uaccess.h
12714index e1f3a17..1ab364d 100644
12715--- a/arch/x86/include/asm/uaccess.h
12716+++ b/arch/x86/include/asm/uaccess.h
12717@@ -7,12 +7,15 @@
12718 #include <linux/compiler.h>
12719 #include <linux/thread_info.h>
12720 #include <linux/string.h>
12721+#include <linux/sched.h>
12722 #include <asm/asm.h>
12723 #include <asm/page.h>
12724
12725 #define VERIFY_READ 0
12726 #define VERIFY_WRITE 1
12727
12728+extern void check_object_size(const void *ptr, unsigned long n, bool to);
12729+
12730 /*
12731 * The fs value determines whether argument validity checking should be
12732 * performed or not. If get_fs() == USER_DS, checking is performed, with
12733@@ -28,7 +31,12 @@
12734
12735 #define get_ds() (KERNEL_DS)
12736 #define get_fs() (current_thread_info()->addr_limit)
12737+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
12738+void __set_fs(mm_segment_t x);
12739+void set_fs(mm_segment_t x);
12740+#else
12741 #define set_fs(x) (current_thread_info()->addr_limit = (x))
12742+#endif
12743
12744 #define segment_eq(a, b) ((a).seg == (b).seg)
12745
12746@@ -76,8 +84,33 @@
12747 * checks that the pointer is in the user space range - after calling
12748 * this function, memory access functions may still return -EFAULT.
12749 */
12750-#define access_ok(type, addr, size) \
12751- (likely(__range_not_ok(addr, size, user_addr_max()) == 0))
12752+#define __access_ok(type, addr, size) (likely(__range_not_ok(addr, size, user_addr_max()) == 0))
12753+#define access_ok(type, addr, size) \
12754+({ \
12755+ long __size = size; \
12756+ unsigned long __addr = (unsigned long)addr; \
12757+ unsigned long __addr_ao = __addr & PAGE_MASK; \
12758+ unsigned long __end_ao = __addr + __size - 1; \
12759+ bool __ret_ao = __range_not_ok(__addr, __size, user_addr_max()) == 0;\
12760+ if (__ret_ao && unlikely((__end_ao ^ __addr_ao) & PAGE_MASK)) { \
12761+ while(__addr_ao <= __end_ao) { \
12762+ char __c_ao; \
12763+ __addr_ao += PAGE_SIZE; \
12764+ if (__size > PAGE_SIZE) \
12765+ cond_resched(); \
12766+ if (__get_user(__c_ao, (char __user *)__addr)) \
12767+ break; \
12768+ if (type != VERIFY_WRITE) { \
12769+ __addr = __addr_ao; \
12770+ continue; \
12771+ } \
12772+ if (__put_user(__c_ao, (char __user *)__addr)) \
12773+ break; \
12774+ __addr = __addr_ao; \
12775+ } \
12776+ } \
12777+ __ret_ao; \
12778+})
12779
12780 /*
12781 * The exception table consists of pairs of addresses relative to the
12782@@ -188,12 +221,20 @@ extern int __get_user_bad(void);
12783 asm volatile("call __put_user_" #size : "=a" (__ret_pu) \
12784 : "0" ((typeof(*(ptr)))(x)), "c" (ptr) : "ebx")
12785
12786-
12787+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
12788+#define __copyuser_seg "gs;"
12789+#define __COPYUSER_SET_ES "pushl %%gs; popl %%es\n"
12790+#define __COPYUSER_RESTORE_ES "pushl %%ss; popl %%es\n"
12791+#else
12792+#define __copyuser_seg
12793+#define __COPYUSER_SET_ES
12794+#define __COPYUSER_RESTORE_ES
12795+#endif
12796
12797 #ifdef CONFIG_X86_32
12798 #define __put_user_asm_u64(x, addr, err, errret) \
12799- asm volatile("1: movl %%eax,0(%2)\n" \
12800- "2: movl %%edx,4(%2)\n" \
12801+ asm volatile("1: "__copyuser_seg"movl %%eax,0(%2)\n" \
12802+ "2: "__copyuser_seg"movl %%edx,4(%2)\n" \
12803 "3:\n" \
12804 ".section .fixup,\"ax\"\n" \
12805 "4: movl %3,%0\n" \
12806@@ -205,8 +246,8 @@ extern int __get_user_bad(void);
12807 : "A" (x), "r" (addr), "i" (errret), "0" (err))
12808
12809 #define __put_user_asm_ex_u64(x, addr) \
12810- asm volatile("1: movl %%eax,0(%1)\n" \
12811- "2: movl %%edx,4(%1)\n" \
12812+ asm volatile("1: "__copyuser_seg"movl %%eax,0(%1)\n" \
12813+ "2: "__copyuser_seg"movl %%edx,4(%1)\n" \
12814 "3:\n" \
12815 _ASM_EXTABLE_EX(1b, 2b) \
12816 _ASM_EXTABLE_EX(2b, 3b) \
12817@@ -258,7 +299,7 @@ extern void __put_user_8(void);
12818 __typeof__(*(ptr)) __pu_val; \
12819 __chk_user_ptr(ptr); \
12820 might_fault(); \
12821- __pu_val = x; \
12822+ __pu_val = (x); \
12823 switch (sizeof(*(ptr))) { \
12824 case 1: \
12825 __put_user_x(1, __pu_val, ptr, __ret_pu); \
12826@@ -379,7 +420,7 @@ do { \
12827 } while (0)
12828
12829 #define __get_user_asm(x, addr, err, itype, rtype, ltype, errret) \
12830- asm volatile("1: mov"itype" %2,%"rtype"1\n" \
12831+ asm volatile("1: "__copyuser_seg"mov"itype" %2,%"rtype"1\n"\
12832 "2:\n" \
12833 ".section .fixup,\"ax\"\n" \
12834 "3: mov %3,%0\n" \
12835@@ -387,7 +428,7 @@ do { \
12836 " jmp 2b\n" \
12837 ".previous\n" \
12838 _ASM_EXTABLE(1b, 3b) \
12839- : "=r" (err), ltype(x) \
12840+ : "=r" (err), ltype (x) \
12841 : "m" (__m(addr)), "i" (errret), "0" (err))
12842
12843 #define __get_user_size_ex(x, ptr, size) \
12844@@ -412,7 +453,7 @@ do { \
12845 } while (0)
12846
12847 #define __get_user_asm_ex(x, addr, itype, rtype, ltype) \
12848- asm volatile("1: mov"itype" %1,%"rtype"0\n" \
12849+ asm volatile("1: "__copyuser_seg"mov"itype" %1,%"rtype"0\n"\
12850 "2:\n" \
12851 _ASM_EXTABLE_EX(1b, 2b) \
12852 : ltype(x) : "m" (__m(addr)))
12853@@ -429,13 +470,24 @@ do { \
12854 int __gu_err; \
12855 unsigned long __gu_val; \
12856 __get_user_size(__gu_val, (ptr), (size), __gu_err, -EFAULT); \
12857- (x) = (__force __typeof__(*(ptr)))__gu_val; \
12858+ (x) = (__typeof__(*(ptr)))__gu_val; \
12859 __gu_err; \
12860 })
12861
12862 /* FIXME: this hack is definitely wrong -AK */
12863 struct __large_struct { unsigned long buf[100]; };
12864-#define __m(x) (*(struct __large_struct __user *)(x))
12865+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
12866+#define ____m(x) \
12867+({ \
12868+ unsigned long ____x = (unsigned long)(x); \
12869+ if (____x < PAX_USER_SHADOW_BASE) \
12870+ ____x += PAX_USER_SHADOW_BASE; \
12871+ (void __user *)____x; \
12872+})
12873+#else
12874+#define ____m(x) (x)
12875+#endif
12876+#define __m(x) (*(struct __large_struct __user *)____m(x))
12877
12878 /*
12879 * Tell gcc we read from memory instead of writing: this is because
12880@@ -443,7 +495,7 @@ struct __large_struct { unsigned long buf[100]; };
12881 * aliasing issues.
12882 */
12883 #define __put_user_asm(x, addr, err, itype, rtype, ltype, errret) \
12884- asm volatile("1: mov"itype" %"rtype"1,%2\n" \
12885+ asm volatile("1: "__copyuser_seg"mov"itype" %"rtype"1,%2\n"\
12886 "2:\n" \
12887 ".section .fixup,\"ax\"\n" \
12888 "3: mov %3,%0\n" \
12889@@ -451,10 +503,10 @@ struct __large_struct { unsigned long buf[100]; };
12890 ".previous\n" \
12891 _ASM_EXTABLE(1b, 3b) \
12892 : "=r"(err) \
12893- : ltype(x), "m" (__m(addr)), "i" (errret), "0" (err))
12894+ : ltype (x), "m" (__m(addr)), "i" (errret), "0" (err))
12895
12896 #define __put_user_asm_ex(x, addr, itype, rtype, ltype) \
12897- asm volatile("1: mov"itype" %"rtype"0,%1\n" \
12898+ asm volatile("1: "__copyuser_seg"mov"itype" %"rtype"0,%1\n"\
12899 "2:\n" \
12900 _ASM_EXTABLE_EX(1b, 2b) \
12901 : : ltype(x), "m" (__m(addr)))
12902@@ -493,8 +545,12 @@ struct __large_struct { unsigned long buf[100]; };
12903 * On error, the variable @x is set to zero.
12904 */
12905
12906+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
12907+#define __get_user(x, ptr) get_user((x), (ptr))
12908+#else
12909 #define __get_user(x, ptr) \
12910 __get_user_nocheck((x), (ptr), sizeof(*(ptr)))
12911+#endif
12912
12913 /**
12914 * __put_user: - Write a simple value into user space, with less checking.
12915@@ -516,8 +572,12 @@ struct __large_struct { unsigned long buf[100]; };
12916 * Returns zero on success, or -EFAULT on error.
12917 */
12918
12919+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
12920+#define __put_user(x, ptr) put_user((x), (ptr))
12921+#else
12922 #define __put_user(x, ptr) \
12923 __put_user_nocheck((__typeof__(*(ptr)))(x), (ptr), sizeof(*(ptr)))
12924+#endif
12925
12926 #define __get_user_unaligned __get_user
12927 #define __put_user_unaligned __put_user
12928@@ -535,7 +595,7 @@ struct __large_struct { unsigned long buf[100]; };
12929 #define get_user_ex(x, ptr) do { \
12930 unsigned long __gue_val; \
12931 __get_user_size_ex((__gue_val), (ptr), (sizeof(*(ptr)))); \
12932- (x) = (__force __typeof__(*(ptr)))__gue_val; \
12933+ (x) = (__typeof__(*(ptr)))__gue_val; \
12934 } while (0)
12935
12936 #ifdef CONFIG_X86_WP_WORKS_OK
12937diff --git a/arch/x86/include/asm/uaccess_32.h b/arch/x86/include/asm/uaccess_32.h
12938index 576e39b..ccd0a39 100644
12939--- a/arch/x86/include/asm/uaccess_32.h
12940+++ b/arch/x86/include/asm/uaccess_32.h
12941@@ -11,15 +11,15 @@
12942 #include <asm/page.h>
12943
12944 unsigned long __must_check __copy_to_user_ll
12945- (void __user *to, const void *from, unsigned long n);
12946+ (void __user *to, const void *from, unsigned long n) __size_overflow(3);
12947 unsigned long __must_check __copy_from_user_ll
12948- (void *to, const void __user *from, unsigned long n);
12949+ (void *to, const void __user *from, unsigned long n) __size_overflow(3);
12950 unsigned long __must_check __copy_from_user_ll_nozero
12951- (void *to, const void __user *from, unsigned long n);
12952+ (void *to, const void __user *from, unsigned long n) __size_overflow(3);
12953 unsigned long __must_check __copy_from_user_ll_nocache
12954- (void *to, const void __user *from, unsigned long n);
12955+ (void *to, const void __user *from, unsigned long n) __size_overflow(3);
12956 unsigned long __must_check __copy_from_user_ll_nocache_nozero
12957- (void *to, const void __user *from, unsigned long n);
12958+ (void *to, const void __user *from, unsigned long n) __size_overflow(3);
12959
12960 /**
12961 * __copy_to_user_inatomic: - Copy a block of data into user space, with less checking.
12962@@ -43,6 +43,9 @@ unsigned long __must_check __copy_from_user_ll_nocache_nozero
12963 static __always_inline unsigned long __must_check
12964 __copy_to_user_inatomic(void __user *to, const void *from, unsigned long n)
12965 {
12966+ if ((long)n < 0)
12967+ return n;
12968+
12969 if (__builtin_constant_p(n)) {
12970 unsigned long ret;
12971
12972@@ -61,6 +64,8 @@ __copy_to_user_inatomic(void __user *to, const void *from, unsigned long n)
12973 return ret;
12974 }
12975 }
12976+ if (!__builtin_constant_p(n))
12977+ check_object_size(from, n, true);
12978 return __copy_to_user_ll(to, from, n);
12979 }
12980
12981@@ -82,12 +87,16 @@ static __always_inline unsigned long __must_check
12982 __copy_to_user(void __user *to, const void *from, unsigned long n)
12983 {
12984 might_fault();
12985+
12986 return __copy_to_user_inatomic(to, from, n);
12987 }
12988
12989 static __always_inline unsigned long
12990 __copy_from_user_inatomic(void *to, const void __user *from, unsigned long n)
12991 {
12992+ if ((long)n < 0)
12993+ return n;
12994+
12995 /* Avoid zeroing the tail if the copy fails..
12996 * If 'n' is constant and 1, 2, or 4, we do still zero on a failure,
12997 * but as the zeroing behaviour is only significant when n is not
12998@@ -137,6 +146,10 @@ static __always_inline unsigned long
12999 __copy_from_user(void *to, const void __user *from, unsigned long n)
13000 {
13001 might_fault();
13002+
13003+ if ((long)n < 0)
13004+ return n;
13005+
13006 if (__builtin_constant_p(n)) {
13007 unsigned long ret;
13008
13009@@ -152,6 +165,8 @@ __copy_from_user(void *to, const void __user *from, unsigned long n)
13010 return ret;
13011 }
13012 }
13013+ if (!__builtin_constant_p(n))
13014+ check_object_size(to, n, false);
13015 return __copy_from_user_ll(to, from, n);
13016 }
13017
13018@@ -159,6 +174,10 @@ static __always_inline unsigned long __copy_from_user_nocache(void *to,
13019 const void __user *from, unsigned long n)
13020 {
13021 might_fault();
13022+
13023+ if ((long)n < 0)
13024+ return n;
13025+
13026 if (__builtin_constant_p(n)) {
13027 unsigned long ret;
13028
13029@@ -181,15 +200,19 @@ static __always_inline unsigned long
13030 __copy_from_user_inatomic_nocache(void *to, const void __user *from,
13031 unsigned long n)
13032 {
13033- return __copy_from_user_ll_nocache_nozero(to, from, n);
13034+ if ((long)n < 0)
13035+ return n;
13036+
13037+ return __copy_from_user_ll_nocache_nozero(to, from, n);
13038 }
13039
13040-unsigned long __must_check copy_to_user(void __user *to,
13041- const void *from, unsigned long n);
13042-unsigned long __must_check _copy_from_user(void *to,
13043- const void __user *from,
13044- unsigned long n);
13045-
13046+extern void copy_to_user_overflow(void)
13047+#ifdef CONFIG_DEBUG_STRICT_USER_COPY_CHECKS
13048+ __compiletime_error("copy_to_user() buffer size is not provably correct")
13049+#else
13050+ __compiletime_warning("copy_to_user() buffer size is not provably correct")
13051+#endif
13052+;
13053
13054 extern void copy_from_user_overflow(void)
13055 #ifdef CONFIG_DEBUG_STRICT_USER_COPY_CHECKS
13056@@ -199,21 +222,65 @@ extern void copy_from_user_overflow(void)
13057 #endif
13058 ;
13059
13060-static inline unsigned long __must_check copy_from_user(void *to,
13061- const void __user *from,
13062- unsigned long n)
13063+/**
13064+ * copy_to_user: - Copy a block of data into user space.
13065+ * @to: Destination address, in user space.
13066+ * @from: Source address, in kernel space.
13067+ * @n: Number of bytes to copy.
13068+ *
13069+ * Context: User context only. This function may sleep.
13070+ *
13071+ * Copy data from kernel space to user space.
13072+ *
13073+ * Returns number of bytes that could not be copied.
13074+ * On success, this will be zero.
13075+ */
13076+static inline unsigned long __must_check
13077+copy_to_user(void __user *to, const void *from, unsigned long n)
13078 {
13079- int sz = __compiletime_object_size(to);
13080+ size_t sz = __compiletime_object_size(from);
13081
13082- if (likely(sz == -1 || sz >= n))
13083- n = _copy_from_user(to, from, n);
13084- else
13085+ if (unlikely(sz != (size_t)-1 && sz < n))
13086+ copy_to_user_overflow();
13087+ else if (access_ok(VERIFY_WRITE, to, n))
13088+ n = __copy_to_user(to, from, n);
13089+ return n;
13090+}
13091+
13092+/**
13093+ * copy_from_user: - Copy a block of data from user space.
13094+ * @to: Destination address, in kernel space.
13095+ * @from: Source address, in user space.
13096+ * @n: Number of bytes to copy.
13097+ *
13098+ * Context: User context only. This function may sleep.
13099+ *
13100+ * Copy data from user space to kernel space.
13101+ *
13102+ * Returns number of bytes that could not be copied.
13103+ * On success, this will be zero.
13104+ *
13105+ * If some data could not be copied, this function will pad the copied
13106+ * data to the requested size using zero bytes.
13107+ */
13108+static inline unsigned long __must_check
13109+copy_from_user(void *to, const void __user *from, unsigned long n)
13110+{
13111+ size_t sz = __compiletime_object_size(to);
13112+
13113+ if (unlikely(sz != (size_t)-1 && sz < n))
13114 copy_from_user_overflow();
13115-
13116+ else if (access_ok(VERIFY_READ, from, n))
13117+ n = __copy_from_user(to, from, n);
13118+ else if ((long)n > 0) {
13119+ if (!__builtin_constant_p(n))
13120+ check_object_size(to, n, false);
13121+ memset(to, 0, n);
13122+ }
13123 return n;
13124 }
13125
13126-unsigned long __must_check clear_user(void __user *mem, unsigned long len);
13127-unsigned long __must_check __clear_user(void __user *mem, unsigned long len);
13128+unsigned long __must_check clear_user(void __user *mem, unsigned long len) __size_overflow(2);
13129+unsigned long __must_check __clear_user(void __user *mem, unsigned long len) __size_overflow(2);
13130
13131 #endif /* _ASM_X86_UACCESS_32_H */
13132diff --git a/arch/x86/include/asm/uaccess_64.h b/arch/x86/include/asm/uaccess_64.h
13133index d8def8b..ac7fc15 100644
13134--- a/arch/x86/include/asm/uaccess_64.h
13135+++ b/arch/x86/include/asm/uaccess_64.h
13136@@ -10,6 +10,9 @@
13137 #include <asm/alternative.h>
13138 #include <asm/cpufeature.h>
13139 #include <asm/page.h>
13140+#include <asm/pgtable.h>
13141+
13142+#define set_fs(x) (current_thread_info()->addr_limit = (x))
13143
13144 /*
13145 * Copy To/From Userspace
13146@@ -17,13 +20,13 @@
13147
13148 /* Handles exceptions in both to and from, but doesn't do access_ok */
13149 __must_check unsigned long
13150-copy_user_enhanced_fast_string(void *to, const void *from, unsigned len);
13151+copy_user_enhanced_fast_string(void *to, const void *from, unsigned len) __size_overflow(3);
13152 __must_check unsigned long
13153-copy_user_generic_string(void *to, const void *from, unsigned len);
13154+copy_user_generic_string(void *to, const void *from, unsigned len) __size_overflow(3);
13155 __must_check unsigned long
13156-copy_user_generic_unrolled(void *to, const void *from, unsigned len);
13157+copy_user_generic_unrolled(void *to, const void *from, unsigned len) __size_overflow(3);
13158
13159-static __always_inline __must_check unsigned long
13160+static __always_inline __must_check __size_overflow(3) unsigned long
13161 copy_user_generic(void *to, const void *from, unsigned len)
13162 {
13163 unsigned ret;
13164@@ -41,142 +44,238 @@ copy_user_generic(void *to, const void *from, unsigned len)
13165 ASM_OUTPUT2("=a" (ret), "=D" (to), "=S" (from),
13166 "=d" (len)),
13167 "1" (to), "2" (from), "3" (len)
13168- : "memory", "rcx", "r8", "r9", "r10", "r11");
13169+ : "memory", "rcx", "r8", "r9", "r11");
13170 return ret;
13171 }
13172
13173+static __always_inline __must_check unsigned long
13174+__copy_to_user(void __user *to, const void *from, unsigned long len) __size_overflow(3);
13175+static __always_inline __must_check unsigned long
13176+__copy_from_user(void *to, const void __user *from, unsigned long len) __size_overflow(3);
13177 __must_check unsigned long
13178-_copy_to_user(void __user *to, const void *from, unsigned len);
13179-__must_check unsigned long
13180-_copy_from_user(void *to, const void __user *from, unsigned len);
13181-__must_check unsigned long
13182-copy_in_user(void __user *to, const void __user *from, unsigned len);
13183+copy_in_user(void __user *to, const void __user *from, unsigned long len) __size_overflow(3);
13184+
13185+extern void copy_to_user_overflow(void)
13186+#ifdef CONFIG_DEBUG_STRICT_USER_COPY_CHECKS
13187+ __compiletime_error("copy_to_user() buffer size is not provably correct")
13188+#else
13189+ __compiletime_warning("copy_to_user() buffer size is not provably correct")
13190+#endif
13191+;
13192+
13193+extern void copy_from_user_overflow(void)
13194+#ifdef CONFIG_DEBUG_STRICT_USER_COPY_CHECKS
13195+ __compiletime_error("copy_from_user() buffer size is not provably correct")
13196+#else
13197+ __compiletime_warning("copy_from_user() buffer size is not provably correct")
13198+#endif
13199+;
13200
13201 static inline unsigned long __must_check copy_from_user(void *to,
13202 const void __user *from,
13203 unsigned long n)
13204 {
13205- int sz = __compiletime_object_size(to);
13206-
13207 might_fault();
13208- if (likely(sz == -1 || sz >= n))
13209- n = _copy_from_user(to, from, n);
13210-#ifdef CONFIG_DEBUG_VM
13211- else
13212- WARN(1, "Buffer overflow detected!\n");
13213-#endif
13214+
13215+ if (access_ok(VERIFY_READ, from, n))
13216+ n = __copy_from_user(to, from, n);
13217+ else if (n < INT_MAX) {
13218+ if (!__builtin_constant_p(n))
13219+ check_object_size(to, n, false);
13220+ memset(to, 0, n);
13221+ }
13222 return n;
13223 }
13224
13225 static __always_inline __must_check
13226-int copy_to_user(void __user *dst, const void *src, unsigned size)
13227+int copy_to_user(void __user *dst, const void *src, unsigned long size)
13228 {
13229 might_fault();
13230
13231- return _copy_to_user(dst, src, size);
13232+ if (access_ok(VERIFY_WRITE, dst, size))
13233+ size = __copy_to_user(dst, src, size);
13234+ return size;
13235 }
13236
13237 static __always_inline __must_check
13238-int __copy_from_user(void *dst, const void __user *src, unsigned size)
13239+unsigned long __copy_from_user(void *dst, const void __user *src, unsigned long size)
13240 {
13241- int ret = 0;
13242+ size_t sz = __compiletime_object_size(dst);
13243+ unsigned ret = 0;
13244
13245 might_fault();
13246- if (!__builtin_constant_p(size))
13247- return copy_user_generic(dst, (__force void *)src, size);
13248+
13249+ if (size > INT_MAX)
13250+ return size;
13251+
13252+#ifdef CONFIG_PAX_MEMORY_UDEREF
13253+ if (!__access_ok(VERIFY_READ, src, size))
13254+ return size;
13255+#endif
13256+
13257+ if (unlikely(sz != (size_t)-1 && sz < size)) {
13258+ copy_from_user_overflow();
13259+ return size;
13260+ }
13261+
13262+ if (!__builtin_constant_p(size)) {
13263+ check_object_size(dst, size, false);
13264+
13265+#ifdef CONFIG_PAX_MEMORY_UDEREF
13266+ if ((unsigned long)src < PAX_USER_SHADOW_BASE)
13267+ src += PAX_USER_SHADOW_BASE;
13268+#endif
13269+
13270+ return copy_user_generic(dst, (__force_kernel const void *)src, size);
13271+ }
13272 switch (size) {
13273- case 1:__get_user_asm(*(u8 *)dst, (u8 __user *)src,
13274+ case 1:__get_user_asm(*(u8 *)dst, (const u8 __user *)src,
13275 ret, "b", "b", "=q", 1);
13276 return ret;
13277- case 2:__get_user_asm(*(u16 *)dst, (u16 __user *)src,
13278+ case 2:__get_user_asm(*(u16 *)dst, (const u16 __user *)src,
13279 ret, "w", "w", "=r", 2);
13280 return ret;
13281- case 4:__get_user_asm(*(u32 *)dst, (u32 __user *)src,
13282+ case 4:__get_user_asm(*(u32 *)dst, (const u32 __user *)src,
13283 ret, "l", "k", "=r", 4);
13284 return ret;
13285- case 8:__get_user_asm(*(u64 *)dst, (u64 __user *)src,
13286+ case 8:__get_user_asm(*(u64 *)dst, (const u64 __user *)src,
13287 ret, "q", "", "=r", 8);
13288 return ret;
13289 case 10:
13290- __get_user_asm(*(u64 *)dst, (u64 __user *)src,
13291+ __get_user_asm(*(u64 *)dst, (const u64 __user *)src,
13292 ret, "q", "", "=r", 10);
13293 if (unlikely(ret))
13294 return ret;
13295 __get_user_asm(*(u16 *)(8 + (char *)dst),
13296- (u16 __user *)(8 + (char __user *)src),
13297+ (const u16 __user *)(8 + (const char __user *)src),
13298 ret, "w", "w", "=r", 2);
13299 return ret;
13300 case 16:
13301- __get_user_asm(*(u64 *)dst, (u64 __user *)src,
13302+ __get_user_asm(*(u64 *)dst, (const u64 __user *)src,
13303 ret, "q", "", "=r", 16);
13304 if (unlikely(ret))
13305 return ret;
13306 __get_user_asm(*(u64 *)(8 + (char *)dst),
13307- (u64 __user *)(8 + (char __user *)src),
13308+ (const u64 __user *)(8 + (const char __user *)src),
13309 ret, "q", "", "=r", 8);
13310 return ret;
13311 default:
13312- return copy_user_generic(dst, (__force void *)src, size);
13313+
13314+#ifdef CONFIG_PAX_MEMORY_UDEREF
13315+ if ((unsigned long)src < PAX_USER_SHADOW_BASE)
13316+ src += PAX_USER_SHADOW_BASE;
13317+#endif
13318+
13319+ return copy_user_generic(dst, (__force_kernel const void *)src, size);
13320 }
13321 }
13322
13323 static __always_inline __must_check
13324-int __copy_to_user(void __user *dst, const void *src, unsigned size)
13325+unsigned long __copy_to_user(void __user *dst, const void *src, unsigned long size)
13326 {
13327- int ret = 0;
13328+ size_t sz = __compiletime_object_size(src);
13329+ unsigned ret = 0;
13330
13331 might_fault();
13332- if (!__builtin_constant_p(size))
13333- return copy_user_generic((__force void *)dst, src, size);
13334+
13335+ if (size > INT_MAX)
13336+ return size;
13337+
13338+#ifdef CONFIG_PAX_MEMORY_UDEREF
13339+ if (!__access_ok(VERIFY_WRITE, dst, size))
13340+ return size;
13341+#endif
13342+
13343+ if (unlikely(sz != (size_t)-1 && sz < size)) {
13344+ copy_to_user_overflow();
13345+ return size;
13346+ }
13347+
13348+ if (!__builtin_constant_p(size)) {
13349+ check_object_size(src, size, true);
13350+
13351+#ifdef CONFIG_PAX_MEMORY_UDEREF
13352+ if ((unsigned long)dst < PAX_USER_SHADOW_BASE)
13353+ dst += PAX_USER_SHADOW_BASE;
13354+#endif
13355+
13356+ return copy_user_generic((__force_kernel void *)dst, src, size);
13357+ }
13358 switch (size) {
13359- case 1:__put_user_asm(*(u8 *)src, (u8 __user *)dst,
13360+ case 1:__put_user_asm(*(const u8 *)src, (u8 __user *)dst,
13361 ret, "b", "b", "iq", 1);
13362 return ret;
13363- case 2:__put_user_asm(*(u16 *)src, (u16 __user *)dst,
13364+ case 2:__put_user_asm(*(const u16 *)src, (u16 __user *)dst,
13365 ret, "w", "w", "ir", 2);
13366 return ret;
13367- case 4:__put_user_asm(*(u32 *)src, (u32 __user *)dst,
13368+ case 4:__put_user_asm(*(const u32 *)src, (u32 __user *)dst,
13369 ret, "l", "k", "ir", 4);
13370 return ret;
13371- case 8:__put_user_asm(*(u64 *)src, (u64 __user *)dst,
13372+ case 8:__put_user_asm(*(const u64 *)src, (u64 __user *)dst,
13373 ret, "q", "", "er", 8);
13374 return ret;
13375 case 10:
13376- __put_user_asm(*(u64 *)src, (u64 __user *)dst,
13377+ __put_user_asm(*(const u64 *)src, (u64 __user *)dst,
13378 ret, "q", "", "er", 10);
13379 if (unlikely(ret))
13380 return ret;
13381 asm("":::"memory");
13382- __put_user_asm(4[(u16 *)src], 4 + (u16 __user *)dst,
13383+ __put_user_asm(4[(const u16 *)src], 4 + (u16 __user *)dst,
13384 ret, "w", "w", "ir", 2);
13385 return ret;
13386 case 16:
13387- __put_user_asm(*(u64 *)src, (u64 __user *)dst,
13388+ __put_user_asm(*(const u64 *)src, (u64 __user *)dst,
13389 ret, "q", "", "er", 16);
13390 if (unlikely(ret))
13391 return ret;
13392 asm("":::"memory");
13393- __put_user_asm(1[(u64 *)src], 1 + (u64 __user *)dst,
13394+ __put_user_asm(1[(const u64 *)src], 1 + (u64 __user *)dst,
13395 ret, "q", "", "er", 8);
13396 return ret;
13397 default:
13398- return copy_user_generic((__force void *)dst, src, size);
13399+
13400+#ifdef CONFIG_PAX_MEMORY_UDEREF
13401+ if ((unsigned long)dst < PAX_USER_SHADOW_BASE)
13402+ dst += PAX_USER_SHADOW_BASE;
13403+#endif
13404+
13405+ return copy_user_generic((__force_kernel void *)dst, src, size);
13406 }
13407 }
13408
13409 static __always_inline __must_check
13410-int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
13411+unsigned long __copy_in_user(void __user *dst, const void __user *src, unsigned long size)
13412 {
13413- int ret = 0;
13414+ unsigned ret = 0;
13415
13416 might_fault();
13417- if (!__builtin_constant_p(size))
13418- return copy_user_generic((__force void *)dst,
13419- (__force void *)src, size);
13420+
13421+ if (size > INT_MAX)
13422+ return size;
13423+
13424+#ifdef CONFIG_PAX_MEMORY_UDEREF
13425+ if (!__access_ok(VERIFY_READ, src, size))
13426+ return size;
13427+ if (!__access_ok(VERIFY_WRITE, dst, size))
13428+ return size;
13429+#endif
13430+
13431+ if (!__builtin_constant_p(size)) {
13432+
13433+#ifdef CONFIG_PAX_MEMORY_UDEREF
13434+ if ((unsigned long)src < PAX_USER_SHADOW_BASE)
13435+ src += PAX_USER_SHADOW_BASE;
13436+ if ((unsigned long)dst < PAX_USER_SHADOW_BASE)
13437+ dst += PAX_USER_SHADOW_BASE;
13438+#endif
13439+
13440+ return copy_user_generic((__force_kernel void *)dst,
13441+ (__force_kernel const void *)src, size);
13442+ }
13443 switch (size) {
13444 case 1: {
13445 u8 tmp;
13446- __get_user_asm(tmp, (u8 __user *)src,
13447+ __get_user_asm(tmp, (const u8 __user *)src,
13448 ret, "b", "b", "=q", 1);
13449 if (likely(!ret))
13450 __put_user_asm(tmp, (u8 __user *)dst,
13451@@ -185,7 +284,7 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
13452 }
13453 case 2: {
13454 u16 tmp;
13455- __get_user_asm(tmp, (u16 __user *)src,
13456+ __get_user_asm(tmp, (const u16 __user *)src,
13457 ret, "w", "w", "=r", 2);
13458 if (likely(!ret))
13459 __put_user_asm(tmp, (u16 __user *)dst,
13460@@ -195,7 +294,7 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
13461
13462 case 4: {
13463 u32 tmp;
13464- __get_user_asm(tmp, (u32 __user *)src,
13465+ __get_user_asm(tmp, (const u32 __user *)src,
13466 ret, "l", "k", "=r", 4);
13467 if (likely(!ret))
13468 __put_user_asm(tmp, (u32 __user *)dst,
13469@@ -204,7 +303,7 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
13470 }
13471 case 8: {
13472 u64 tmp;
13473- __get_user_asm(tmp, (u64 __user *)src,
13474+ __get_user_asm(tmp, (const u64 __user *)src,
13475 ret, "q", "", "=r", 8);
13476 if (likely(!ret))
13477 __put_user_asm(tmp, (u64 __user *)dst,
13478@@ -212,44 +311,89 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
13479 return ret;
13480 }
13481 default:
13482- return copy_user_generic((__force void *)dst,
13483- (__force void *)src, size);
13484+
13485+#ifdef CONFIG_PAX_MEMORY_UDEREF
13486+ if ((unsigned long)src < PAX_USER_SHADOW_BASE)
13487+ src += PAX_USER_SHADOW_BASE;
13488+ if ((unsigned long)dst < PAX_USER_SHADOW_BASE)
13489+ dst += PAX_USER_SHADOW_BASE;
13490+#endif
13491+
13492+ return copy_user_generic((__force_kernel void *)dst,
13493+ (__force_kernel const void *)src, size);
13494 }
13495 }
13496
13497-__must_check unsigned long clear_user(void __user *mem, unsigned long len);
13498-__must_check unsigned long __clear_user(void __user *mem, unsigned long len);
13499+__must_check unsigned long clear_user(void __user *mem, unsigned long len) __size_overflow(2);
13500+__must_check unsigned long __clear_user(void __user *mem, unsigned long len) __size_overflow(2);
13501
13502 static __must_check __always_inline int
13503-__copy_from_user_inatomic(void *dst, const void __user *src, unsigned size)
13504+__copy_from_user_inatomic(void *dst, const void __user *src, unsigned long size)
13505 {
13506- return copy_user_generic(dst, (__force const void *)src, size);
13507+ if (size > INT_MAX)
13508+ return size;
13509+
13510+#ifdef CONFIG_PAX_MEMORY_UDEREF
13511+ if (!__access_ok(VERIFY_READ, src, size))
13512+ return size;
13513+
13514+ if ((unsigned long)src < PAX_USER_SHADOW_BASE)
13515+ src += PAX_USER_SHADOW_BASE;
13516+#endif
13517+
13518+ return copy_user_generic(dst, (__force_kernel const void *)src, size);
13519 }
13520
13521-static __must_check __always_inline int
13522-__copy_to_user_inatomic(void __user *dst, const void *src, unsigned size)
13523+static __must_check __always_inline unsigned long
13524+__copy_to_user_inatomic(void __user *dst, const void *src, unsigned long size)
13525 {
13526- return copy_user_generic((__force void *)dst, src, size);
13527+ if (size > INT_MAX)
13528+ return size;
13529+
13530+#ifdef CONFIG_PAX_MEMORY_UDEREF
13531+ if (!__access_ok(VERIFY_WRITE, dst, size))
13532+ return size;
13533+
13534+ if ((unsigned long)dst < PAX_USER_SHADOW_BASE)
13535+ dst += PAX_USER_SHADOW_BASE;
13536+#endif
13537+
13538+ return copy_user_generic((__force_kernel void *)dst, src, size);
13539 }
13540
13541-extern long __copy_user_nocache(void *dst, const void __user *src,
13542- unsigned size, int zerorest);
13543+extern unsigned long __copy_user_nocache(void *dst, const void __user *src,
13544+ unsigned long size, int zerorest) __size_overflow(3);
13545
13546-static inline int
13547-__copy_from_user_nocache(void *dst, const void __user *src, unsigned size)
13548+static inline unsigned long __copy_from_user_nocache(void *dst, const void __user *src, unsigned long size)
13549 {
13550 might_sleep();
13551+
13552+ if (size > INT_MAX)
13553+ return size;
13554+
13555+#ifdef CONFIG_PAX_MEMORY_UDEREF
13556+ if (!__access_ok(VERIFY_READ, src, size))
13557+ return size;
13558+#endif
13559+
13560 return __copy_user_nocache(dst, src, size, 1);
13561 }
13562
13563-static inline int
13564-__copy_from_user_inatomic_nocache(void *dst, const void __user *src,
13565- unsigned size)
13566+static inline unsigned long __copy_from_user_inatomic_nocache(void *dst, const void __user *src,
13567+ unsigned long size)
13568 {
13569+ if (size > INT_MAX)
13570+ return size;
13571+
13572+#ifdef CONFIG_PAX_MEMORY_UDEREF
13573+ if (!__access_ok(VERIFY_READ, src, size))
13574+ return size;
13575+#endif
13576+
13577 return __copy_user_nocache(dst, src, size, 0);
13578 }
13579
13580-unsigned long
13581-copy_user_handle_tail(char *to, char *from, unsigned len, unsigned zerorest);
13582+extern unsigned long
13583+copy_user_handle_tail(char __user *to, char __user *from, unsigned long len, unsigned zerorest) __size_overflow(3);
13584
13585 #endif /* _ASM_X86_UACCESS_64_H */
13586diff --git a/arch/x86/include/asm/vdso.h b/arch/x86/include/asm/vdso.h
13587index bb05228..d763d5b 100644
13588--- a/arch/x86/include/asm/vdso.h
13589+++ b/arch/x86/include/asm/vdso.h
13590@@ -11,7 +11,7 @@ extern const char VDSO32_PRELINK[];
13591 #define VDSO32_SYMBOL(base, name) \
13592 ({ \
13593 extern const char VDSO32_##name[]; \
13594- (void *)(VDSO32_##name - VDSO32_PRELINK + (unsigned long)(base)); \
13595+ (void __user *)(VDSO32_##name - VDSO32_PRELINK + (unsigned long)(base)); \
13596 })
13597 #endif
13598
13599diff --git a/arch/x86/include/asm/word-at-a-time.h b/arch/x86/include/asm/word-at-a-time.h
13600index 5b238981..77fdd78 100644
13601--- a/arch/x86/include/asm/word-at-a-time.h
13602+++ b/arch/x86/include/asm/word-at-a-time.h
13603@@ -11,7 +11,7 @@
13604 * and shift, for example.
13605 */
13606 struct word_at_a_time {
13607- const unsigned long one_bits, high_bits;
13608+ unsigned long one_bits, high_bits;
13609 };
13610
13611 #define WORD_AT_A_TIME_CONSTANTS { REPEAT_BYTE(0x01), REPEAT_BYTE(0x80) }
13612diff --git a/arch/x86/include/asm/x86_init.h b/arch/x86/include/asm/x86_init.h
13613index 38155f6..e4184ba 100644
13614--- a/arch/x86/include/asm/x86_init.h
13615+++ b/arch/x86/include/asm/x86_init.h
13616@@ -29,7 +29,7 @@ struct x86_init_mpparse {
13617 void (*mpc_oem_bus_info)(struct mpc_bus *m, char *name);
13618 void (*find_smp_config)(void);
13619 void (*get_smp_config)(unsigned int early);
13620-};
13621+} __no_const;
13622
13623 /**
13624 * struct x86_init_resources - platform specific resource related ops
13625@@ -43,7 +43,7 @@ struct x86_init_resources {
13626 void (*probe_roms)(void);
13627 void (*reserve_resources)(void);
13628 char *(*memory_setup)(void);
13629-};
13630+} __no_const;
13631
13632 /**
13633 * struct x86_init_irqs - platform specific interrupt setup
13634@@ -56,7 +56,7 @@ struct x86_init_irqs {
13635 void (*pre_vector_init)(void);
13636 void (*intr_init)(void);
13637 void (*trap_init)(void);
13638-};
13639+} __no_const;
13640
13641 /**
13642 * struct x86_init_oem - oem platform specific customizing functions
13643@@ -66,7 +66,7 @@ struct x86_init_irqs {
13644 struct x86_init_oem {
13645 void (*arch_setup)(void);
13646 void (*banner)(void);
13647-};
13648+} __no_const;
13649
13650 /**
13651 * struct x86_init_mapping - platform specific initial kernel pagetable setup
13652@@ -77,7 +77,7 @@ struct x86_init_oem {
13653 */
13654 struct x86_init_mapping {
13655 void (*pagetable_reserve)(u64 start, u64 end);
13656-};
13657+} __no_const;
13658
13659 /**
13660 * struct x86_init_paging - platform specific paging functions
13661@@ -87,7 +87,7 @@ struct x86_init_mapping {
13662 struct x86_init_paging {
13663 void (*pagetable_setup_start)(pgd_t *base);
13664 void (*pagetable_setup_done)(pgd_t *base);
13665-};
13666+} __no_const;
13667
13668 /**
13669 * struct x86_init_timers - platform specific timer setup
13670@@ -102,7 +102,7 @@ struct x86_init_timers {
13671 void (*tsc_pre_init)(void);
13672 void (*timer_init)(void);
13673 void (*wallclock_init)(void);
13674-};
13675+} __no_const;
13676
13677 /**
13678 * struct x86_init_iommu - platform specific iommu setup
13679@@ -110,7 +110,7 @@ struct x86_init_timers {
13680 */
13681 struct x86_init_iommu {
13682 int (*iommu_init)(void);
13683-};
13684+} __no_const;
13685
13686 /**
13687 * struct x86_init_pci - platform specific pci init functions
13688@@ -124,7 +124,7 @@ struct x86_init_pci {
13689 int (*init)(void);
13690 void (*init_irq)(void);
13691 void (*fixup_irqs)(void);
13692-};
13693+} __no_const;
13694
13695 /**
13696 * struct x86_init_ops - functions for platform specific setup
13697@@ -140,7 +140,7 @@ struct x86_init_ops {
13698 struct x86_init_timers timers;
13699 struct x86_init_iommu iommu;
13700 struct x86_init_pci pci;
13701-};
13702+} __no_const;
13703
13704 /**
13705 * struct x86_cpuinit_ops - platform specific cpu hotplug setups
13706@@ -151,7 +151,7 @@ struct x86_cpuinit_ops {
13707 void (*setup_percpu_clockev)(void);
13708 void (*early_percpu_clock_init)(void);
13709 void (*fixup_cpu_id)(struct cpuinfo_x86 *c, int node);
13710-};
13711+} __no_const;
13712
13713 /**
13714 * struct x86_platform_ops - platform specific runtime functions
13715@@ -177,7 +177,7 @@ struct x86_platform_ops {
13716 void (*save_sched_clock_state)(void);
13717 void (*restore_sched_clock_state)(void);
13718 void (*apic_post_init)(void);
13719-};
13720+} __no_const;
13721
13722 struct pci_dev;
13723
13724@@ -186,14 +186,14 @@ struct x86_msi_ops {
13725 void (*teardown_msi_irq)(unsigned int irq);
13726 void (*teardown_msi_irqs)(struct pci_dev *dev);
13727 void (*restore_msi_irqs)(struct pci_dev *dev, int irq);
13728-};
13729+} __no_const;
13730
13731 struct x86_io_apic_ops {
13732 void (*init) (void);
13733 unsigned int (*read) (unsigned int apic, unsigned int reg);
13734 void (*write) (unsigned int apic, unsigned int reg, unsigned int value);
13735 void (*modify)(unsigned int apic, unsigned int reg, unsigned int value);
13736-};
13737+} __no_const;
13738
13739 extern struct x86_init_ops x86_init;
13740 extern struct x86_cpuinit_ops x86_cpuinit;
13741diff --git a/arch/x86/include/asm/xsave.h b/arch/x86/include/asm/xsave.h
13742index 8a1b6f9..a29c4e4 100644
13743--- a/arch/x86/include/asm/xsave.h
13744+++ b/arch/x86/include/asm/xsave.h
13745@@ -65,6 +65,11 @@ static inline int xsave_user(struct xsave_struct __user *buf)
13746 {
13747 int err;
13748
13749+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
13750+ if ((unsigned long)buf < PAX_USER_SHADOW_BASE)
13751+ buf = (struct xsave_struct __user *)((void __user*)buf + PAX_USER_SHADOW_BASE);
13752+#endif
13753+
13754 /*
13755 * Clear the xsave header first, so that reserved fields are
13756 * initialized to zero.
13757@@ -93,10 +98,15 @@ static inline int xsave_user(struct xsave_struct __user *buf)
13758 static inline int xrestore_user(struct xsave_struct __user *buf, u64 mask)
13759 {
13760 int err;
13761- struct xsave_struct *xstate = ((__force struct xsave_struct *)buf);
13762+ struct xsave_struct *xstate = ((__force_kernel struct xsave_struct *)buf);
13763 u32 lmask = mask;
13764 u32 hmask = mask >> 32;
13765
13766+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
13767+ if ((unsigned long)xstate < PAX_USER_SHADOW_BASE)
13768+ xstate = (struct xsave_struct *)((void *)xstate + PAX_USER_SHADOW_BASE);
13769+#endif
13770+
13771 __asm__ __volatile__("1: .byte " REX_PREFIX "0x0f,0xae,0x2f\n"
13772 "2:\n"
13773 ".section .fixup,\"ax\"\n"
13774diff --git a/arch/x86/kernel/acpi/sleep.c b/arch/x86/kernel/acpi/sleep.c
13775index 1b8e5a0..354fd59 100644
13776--- a/arch/x86/kernel/acpi/sleep.c
13777+++ b/arch/x86/kernel/acpi/sleep.c
13778@@ -69,8 +69,12 @@ int acpi_suspend_lowlevel(void)
13779 #else /* CONFIG_64BIT */
13780 #ifdef CONFIG_SMP
13781 stack_start = (unsigned long)temp_stack + sizeof(temp_stack);
13782+
13783+ pax_open_kernel();
13784 early_gdt_descr.address =
13785 (unsigned long)get_cpu_gdt_table(smp_processor_id());
13786+ pax_close_kernel();
13787+
13788 initial_gs = per_cpu_offset(smp_processor_id());
13789 #endif
13790 initial_code = (unsigned long)wakeup_long64;
13791diff --git a/arch/x86/kernel/acpi/wakeup_32.S b/arch/x86/kernel/acpi/wakeup_32.S
13792index 13ab720..95d5442 100644
13793--- a/arch/x86/kernel/acpi/wakeup_32.S
13794+++ b/arch/x86/kernel/acpi/wakeup_32.S
13795@@ -30,13 +30,11 @@ wakeup_pmode_return:
13796 # and restore the stack ... but you need gdt for this to work
13797 movl saved_context_esp, %esp
13798
13799- movl %cs:saved_magic, %eax
13800- cmpl $0x12345678, %eax
13801+ cmpl $0x12345678, saved_magic
13802 jne bogus_magic
13803
13804 # jump to place where we left off
13805- movl saved_eip, %eax
13806- jmp *%eax
13807+ jmp *(saved_eip)
13808
13809 bogus_magic:
13810 jmp bogus_magic
13811diff --git a/arch/x86/kernel/alternative.c b/arch/x86/kernel/alternative.c
13812index ced4534..3e75d69 100644
13813--- a/arch/x86/kernel/alternative.c
13814+++ b/arch/x86/kernel/alternative.c
13815@@ -281,6 +281,13 @@ void __init_or_module apply_alternatives(struct alt_instr *start,
13816 */
13817 for (a = start; a < end; a++) {
13818 instr = (u8 *)&a->instr_offset + a->instr_offset;
13819+
13820+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
13821+ instr += ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
13822+ if (instr < (u8 *)_text || (u8 *)_einittext <= instr)
13823+ instr -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
13824+#endif
13825+
13826 replacement = (u8 *)&a->repl_offset + a->repl_offset;
13827 BUG_ON(a->replacementlen > a->instrlen);
13828 BUG_ON(a->instrlen > sizeof(insnbuf));
13829@@ -312,10 +319,16 @@ static void alternatives_smp_lock(const s32 *start, const s32 *end,
13830 for (poff = start; poff < end; poff++) {
13831 u8 *ptr = (u8 *)poff + *poff;
13832
13833+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
13834+ ptr += ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
13835+ if (ptr < (u8 *)_text || (u8 *)_einittext <= ptr)
13836+ ptr -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
13837+#endif
13838+
13839 if (!*poff || ptr < text || ptr >= text_end)
13840 continue;
13841 /* turn DS segment override prefix into lock prefix */
13842- if (*ptr == 0x3e)
13843+ if (*ktla_ktva(ptr) == 0x3e)
13844 text_poke(ptr, ((unsigned char []){0xf0}), 1);
13845 };
13846 mutex_unlock(&text_mutex);
13847@@ -333,10 +346,16 @@ static void alternatives_smp_unlock(const s32 *start, const s32 *end,
13848 for (poff = start; poff < end; poff++) {
13849 u8 *ptr = (u8 *)poff + *poff;
13850
13851+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
13852+ ptr += ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
13853+ if (ptr < (u8 *)_text || (u8 *)_einittext <= ptr)
13854+ ptr -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
13855+#endif
13856+
13857 if (!*poff || ptr < text || ptr >= text_end)
13858 continue;
13859 /* turn lock prefix into DS segment override prefix */
13860- if (*ptr == 0xf0)
13861+ if (*ktla_ktva(ptr) == 0xf0)
13862 text_poke(ptr, ((unsigned char []){0x3E}), 1);
13863 };
13864 mutex_unlock(&text_mutex);
13865@@ -505,7 +524,7 @@ void __init_or_module apply_paravirt(struct paravirt_patch_site *start,
13866
13867 BUG_ON(p->len > MAX_PATCH_LEN);
13868 /* prep the buffer with the original instructions */
13869- memcpy(insnbuf, p->instr, p->len);
13870+ memcpy(insnbuf, ktla_ktva(p->instr), p->len);
13871 used = pv_init_ops.patch(p->instrtype, p->clobbers, insnbuf,
13872 (unsigned long)p->instr, p->len);
13873
13874@@ -573,7 +592,7 @@ void __init alternative_instructions(void)
13875 if (smp_alt_once)
13876 free_init_pages("SMP alternatives",
13877 (unsigned long)__smp_locks,
13878- (unsigned long)__smp_locks_end);
13879+ PAGE_ALIGN((unsigned long)__smp_locks_end));
13880
13881 restart_nmi();
13882 }
13883@@ -590,13 +609,17 @@ void __init alternative_instructions(void)
13884 * instructions. And on the local CPU you need to be protected again NMI or MCE
13885 * handlers seeing an inconsistent instruction while you patch.
13886 */
13887-void *__init_or_module text_poke_early(void *addr, const void *opcode,
13888+void *__kprobes text_poke_early(void *addr, const void *opcode,
13889 size_t len)
13890 {
13891 unsigned long flags;
13892 local_irq_save(flags);
13893- memcpy(addr, opcode, len);
13894+
13895+ pax_open_kernel();
13896+ memcpy(ktla_ktva(addr), opcode, len);
13897 sync_core();
13898+ pax_close_kernel();
13899+
13900 local_irq_restore(flags);
13901 /* Could also do a CLFLUSH here to speed up CPU recovery; but
13902 that causes hangs on some VIA CPUs. */
13903@@ -618,36 +641,22 @@ void *__init_or_module text_poke_early(void *addr, const void *opcode,
13904 */
13905 void *__kprobes text_poke(void *addr, const void *opcode, size_t len)
13906 {
13907- unsigned long flags;
13908- char *vaddr;
13909+ unsigned char *vaddr = ktla_ktva(addr);
13910 struct page *pages[2];
13911- int i;
13912+ size_t i;
13913
13914 if (!core_kernel_text((unsigned long)addr)) {
13915- pages[0] = vmalloc_to_page(addr);
13916- pages[1] = vmalloc_to_page(addr + PAGE_SIZE);
13917+ pages[0] = vmalloc_to_page(vaddr);
13918+ pages[1] = vmalloc_to_page(vaddr + PAGE_SIZE);
13919 } else {
13920- pages[0] = virt_to_page(addr);
13921+ pages[0] = virt_to_page(vaddr);
13922 WARN_ON(!PageReserved(pages[0]));
13923- pages[1] = virt_to_page(addr + PAGE_SIZE);
13924+ pages[1] = virt_to_page(vaddr + PAGE_SIZE);
13925 }
13926 BUG_ON(!pages[0]);
13927- local_irq_save(flags);
13928- set_fixmap(FIX_TEXT_POKE0, page_to_phys(pages[0]));
13929- if (pages[1])
13930- set_fixmap(FIX_TEXT_POKE1, page_to_phys(pages[1]));
13931- vaddr = (char *)fix_to_virt(FIX_TEXT_POKE0);
13932- memcpy(&vaddr[(unsigned long)addr & ~PAGE_MASK], opcode, len);
13933- clear_fixmap(FIX_TEXT_POKE0);
13934- if (pages[1])
13935- clear_fixmap(FIX_TEXT_POKE1);
13936- local_flush_tlb();
13937- sync_core();
13938- /* Could also do a CLFLUSH here to speed up CPU recovery; but
13939- that causes hangs on some VIA CPUs. */
13940+ text_poke_early(addr, opcode, len);
13941 for (i = 0; i < len; i++)
13942- BUG_ON(((char *)addr)[i] != ((char *)opcode)[i]);
13943- local_irq_restore(flags);
13944+ BUG_ON((vaddr)[i] != ((const unsigned char *)opcode)[i]);
13945 return addr;
13946 }
13947
13948diff --git a/arch/x86/kernel/apic/apic.c b/arch/x86/kernel/apic/apic.c
13949index 24deb30..94a3426 100644
13950--- a/arch/x86/kernel/apic/apic.c
13951+++ b/arch/x86/kernel/apic/apic.c
13952@@ -185,7 +185,7 @@ int first_system_vector = 0xfe;
13953 /*
13954 * Debug level, exported for io_apic.c
13955 */
13956-unsigned int apic_verbosity;
13957+int apic_verbosity;
13958
13959 int pic_mode;
13960
13961@@ -1923,7 +1923,7 @@ void smp_error_interrupt(struct pt_regs *regs)
13962 apic_write(APIC_ESR, 0);
13963 v1 = apic_read(APIC_ESR);
13964 ack_APIC_irq();
13965- atomic_inc(&irq_err_count);
13966+ atomic_inc_unchecked(&irq_err_count);
13967
13968 apic_printk(APIC_DEBUG, KERN_DEBUG "APIC error on CPU%d: %02x(%02x)",
13969 smp_processor_id(), v0 , v1);
13970@@ -2155,7 +2155,9 @@ void __init apic_set_eoi_write(void (*eoi_write)(u32 reg, u32 v))
13971 for (drv = __apicdrivers; drv < __apicdrivers_end; drv++) {
13972 /* Should happen once for each apic */
13973 WARN_ON((*drv)->eoi_write == eoi_write);
13974- (*drv)->eoi_write = eoi_write;
13975+ pax_open_kernel();
13976+ *(void **)&(*drv)->eoi_write = eoi_write;
13977+ pax_close_kernel();
13978 }
13979 }
13980
13981diff --git a/arch/x86/kernel/apic/io_apic.c b/arch/x86/kernel/apic/io_apic.c
13982index c265593..137c4ac 100644
13983--- a/arch/x86/kernel/apic/io_apic.c
13984+++ b/arch/x86/kernel/apic/io_apic.c
13985@@ -1084,7 +1084,7 @@ int IO_APIC_get_PCI_irq_vector(int bus, int slot, int pin,
13986 }
13987 EXPORT_SYMBOL(IO_APIC_get_PCI_irq_vector);
13988
13989-void lock_vector_lock(void)
13990+void lock_vector_lock(void) __acquires(vector_lock)
13991 {
13992 /* Used to the online set of cpus does not change
13993 * during assign_irq_vector.
13994@@ -1092,7 +1092,7 @@ void lock_vector_lock(void)
13995 raw_spin_lock(&vector_lock);
13996 }
13997
13998-void unlock_vector_lock(void)
13999+void unlock_vector_lock(void) __releases(vector_lock)
14000 {
14001 raw_spin_unlock(&vector_lock);
14002 }
14003@@ -2408,7 +2408,7 @@ static void ack_apic_edge(struct irq_data *data)
14004 ack_APIC_irq();
14005 }
14006
14007-atomic_t irq_mis_count;
14008+atomic_unchecked_t irq_mis_count;
14009
14010 #ifdef CONFIG_GENERIC_PENDING_IRQ
14011 static bool io_apic_level_ack_pending(struct irq_cfg *cfg)
14012@@ -2549,7 +2549,7 @@ static void ack_apic_level(struct irq_data *data)
14013 * at the cpu.
14014 */
14015 if (!(v & (1 << (i & 0x1f)))) {
14016- atomic_inc(&irq_mis_count);
14017+ atomic_inc_unchecked(&irq_mis_count);
14018
14019 eoi_ioapic_irq(irq, cfg);
14020 }
14021diff --git a/arch/x86/kernel/apm_32.c b/arch/x86/kernel/apm_32.c
14022index d65464e..1035d31 100644
14023--- a/arch/x86/kernel/apm_32.c
14024+++ b/arch/x86/kernel/apm_32.c
14025@@ -412,7 +412,7 @@ static DEFINE_MUTEX(apm_mutex);
14026 * This is for buggy BIOS's that refer to (real mode) segment 0x40
14027 * even though they are called in protected mode.
14028 */
14029-static struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4092,
14030+static const struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4093,
14031 (unsigned long)__va(0x400UL), PAGE_SIZE - 0x400 - 1);
14032
14033 static const char driver_version[] = "1.16ac"; /* no spaces */
14034@@ -590,7 +590,10 @@ static long __apm_bios_call(void *_call)
14035 BUG_ON(cpu != 0);
14036 gdt = get_cpu_gdt_table(cpu);
14037 save_desc_40 = gdt[0x40 / 8];
14038+
14039+ pax_open_kernel();
14040 gdt[0x40 / 8] = bad_bios_desc;
14041+ pax_close_kernel();
14042
14043 apm_irq_save(flags);
14044 APM_DO_SAVE_SEGS;
14045@@ -599,7 +602,11 @@ static long __apm_bios_call(void *_call)
14046 &call->esi);
14047 APM_DO_RESTORE_SEGS;
14048 apm_irq_restore(flags);
14049+
14050+ pax_open_kernel();
14051 gdt[0x40 / 8] = save_desc_40;
14052+ pax_close_kernel();
14053+
14054 put_cpu();
14055
14056 return call->eax & 0xff;
14057@@ -666,7 +673,10 @@ static long __apm_bios_call_simple(void *_call)
14058 BUG_ON(cpu != 0);
14059 gdt = get_cpu_gdt_table(cpu);
14060 save_desc_40 = gdt[0x40 / 8];
14061+
14062+ pax_open_kernel();
14063 gdt[0x40 / 8] = bad_bios_desc;
14064+ pax_close_kernel();
14065
14066 apm_irq_save(flags);
14067 APM_DO_SAVE_SEGS;
14068@@ -674,7 +684,11 @@ static long __apm_bios_call_simple(void *_call)
14069 &call->eax);
14070 APM_DO_RESTORE_SEGS;
14071 apm_irq_restore(flags);
14072+
14073+ pax_open_kernel();
14074 gdt[0x40 / 8] = save_desc_40;
14075+ pax_close_kernel();
14076+
14077 put_cpu();
14078 return error;
14079 }
14080@@ -2345,12 +2359,15 @@ static int __init apm_init(void)
14081 * code to that CPU.
14082 */
14083 gdt = get_cpu_gdt_table(0);
14084+
14085+ pax_open_kernel();
14086 set_desc_base(&gdt[APM_CS >> 3],
14087 (unsigned long)__va((unsigned long)apm_info.bios.cseg << 4));
14088 set_desc_base(&gdt[APM_CS_16 >> 3],
14089 (unsigned long)__va((unsigned long)apm_info.bios.cseg_16 << 4));
14090 set_desc_base(&gdt[APM_DS >> 3],
14091 (unsigned long)__va((unsigned long)apm_info.bios.dseg << 4));
14092+ pax_close_kernel();
14093
14094 proc_create("apm", 0, NULL, &apm_file_ops);
14095
14096diff --git a/arch/x86/kernel/asm-offsets.c b/arch/x86/kernel/asm-offsets.c
14097index 68de2dc..1f3c720 100644
14098--- a/arch/x86/kernel/asm-offsets.c
14099+++ b/arch/x86/kernel/asm-offsets.c
14100@@ -33,6 +33,8 @@ void common(void) {
14101 OFFSET(TI_status, thread_info, status);
14102 OFFSET(TI_addr_limit, thread_info, addr_limit);
14103 OFFSET(TI_preempt_count, thread_info, preempt_count);
14104+ OFFSET(TI_lowest_stack, thread_info, lowest_stack);
14105+ DEFINE(TI_task_thread_sp0, offsetof(struct task_struct, thread.sp0) - offsetof(struct task_struct, tinfo));
14106
14107 BLANK();
14108 OFFSET(crypto_tfm_ctx_offset, crypto_tfm, __crt_ctx);
14109@@ -53,8 +55,26 @@ void common(void) {
14110 OFFSET(PV_CPU_irq_enable_sysexit, pv_cpu_ops, irq_enable_sysexit);
14111 OFFSET(PV_CPU_read_cr0, pv_cpu_ops, read_cr0);
14112 OFFSET(PV_MMU_read_cr2, pv_mmu_ops, read_cr2);
14113+
14114+#ifdef CONFIG_PAX_KERNEXEC
14115+ OFFSET(PV_CPU_write_cr0, pv_cpu_ops, write_cr0);
14116 #endif
14117
14118+#ifdef CONFIG_PAX_MEMORY_UDEREF
14119+ OFFSET(PV_MMU_read_cr3, pv_mmu_ops, read_cr3);
14120+ OFFSET(PV_MMU_write_cr3, pv_mmu_ops, write_cr3);
14121+#ifdef CONFIG_X86_64
14122+ OFFSET(PV_MMU_set_pgd_batched, pv_mmu_ops, set_pgd_batched);
14123+#endif
14124+#endif
14125+
14126+#endif
14127+
14128+ BLANK();
14129+ DEFINE(PAGE_SIZE_asm, PAGE_SIZE);
14130+ DEFINE(PAGE_SHIFT_asm, PAGE_SHIFT);
14131+ DEFINE(THREAD_SIZE_asm, THREAD_SIZE);
14132+
14133 #ifdef CONFIG_XEN
14134 BLANK();
14135 OFFSET(XEN_vcpu_info_mask, vcpu_info, evtchn_upcall_mask);
14136diff --git a/arch/x86/kernel/asm-offsets_64.c b/arch/x86/kernel/asm-offsets_64.c
14137index 1b4754f..fbb4227 100644
14138--- a/arch/x86/kernel/asm-offsets_64.c
14139+++ b/arch/x86/kernel/asm-offsets_64.c
14140@@ -76,6 +76,7 @@ int main(void)
14141 BLANK();
14142 #undef ENTRY
14143
14144+ DEFINE(TSS_size, sizeof(struct tss_struct));
14145 OFFSET(TSS_ist, tss_struct, x86_tss.ist);
14146 BLANK();
14147
14148diff --git a/arch/x86/kernel/cpu/Makefile b/arch/x86/kernel/cpu/Makefile
14149index d30a6a9..79becab 100644
14150--- a/arch/x86/kernel/cpu/Makefile
14151+++ b/arch/x86/kernel/cpu/Makefile
14152@@ -8,10 +8,6 @@ CFLAGS_REMOVE_common.o = -pg
14153 CFLAGS_REMOVE_perf_event.o = -pg
14154 endif
14155
14156-# Make sure load_percpu_segment has no stackprotector
14157-nostackp := $(call cc-option, -fno-stack-protector)
14158-CFLAGS_common.o := $(nostackp)
14159-
14160 obj-y := intel_cacheinfo.o scattered.o topology.o
14161 obj-y += proc.o capflags.o powerflags.o common.o
14162 obj-y += vmware.o hypervisor.o mshyperv.o
14163diff --git a/arch/x86/kernel/cpu/amd.c b/arch/x86/kernel/cpu/amd.c
14164index 9d92e19..49d7d79 100644
14165--- a/arch/x86/kernel/cpu/amd.c
14166+++ b/arch/x86/kernel/cpu/amd.c
14167@@ -724,7 +724,7 @@ static unsigned int __cpuinit amd_size_cache(struct cpuinfo_x86 *c,
14168 unsigned int size)
14169 {
14170 /* AMD errata T13 (order #21922) */
14171- if ((c->x86 == 6)) {
14172+ if (c->x86 == 6) {
14173 /* Duron Rev A0 */
14174 if (c->x86_model == 3 && c->x86_mask == 0)
14175 size = 64;
14176diff --git a/arch/x86/kernel/cpu/common.c b/arch/x86/kernel/cpu/common.c
14177index a5fbc3c..2254849 100644
14178--- a/arch/x86/kernel/cpu/common.c
14179+++ b/arch/x86/kernel/cpu/common.c
14180@@ -86,60 +86,6 @@ static const struct cpu_dev __cpuinitconst default_cpu = {
14181
14182 static const struct cpu_dev *this_cpu __cpuinitdata = &default_cpu;
14183
14184-DEFINE_PER_CPU_PAGE_ALIGNED(struct gdt_page, gdt_page) = { .gdt = {
14185-#ifdef CONFIG_X86_64
14186- /*
14187- * We need valid kernel segments for data and code in long mode too
14188- * IRET will check the segment types kkeil 2000/10/28
14189- * Also sysret mandates a special GDT layout
14190- *
14191- * TLS descriptors are currently at a different place compared to i386.
14192- * Hopefully nobody expects them at a fixed place (Wine?)
14193- */
14194- [GDT_ENTRY_KERNEL32_CS] = GDT_ENTRY_INIT(0xc09b, 0, 0xfffff),
14195- [GDT_ENTRY_KERNEL_CS] = GDT_ENTRY_INIT(0xa09b, 0, 0xfffff),
14196- [GDT_ENTRY_KERNEL_DS] = GDT_ENTRY_INIT(0xc093, 0, 0xfffff),
14197- [GDT_ENTRY_DEFAULT_USER32_CS] = GDT_ENTRY_INIT(0xc0fb, 0, 0xfffff),
14198- [GDT_ENTRY_DEFAULT_USER_DS] = GDT_ENTRY_INIT(0xc0f3, 0, 0xfffff),
14199- [GDT_ENTRY_DEFAULT_USER_CS] = GDT_ENTRY_INIT(0xa0fb, 0, 0xfffff),
14200-#else
14201- [GDT_ENTRY_KERNEL_CS] = GDT_ENTRY_INIT(0xc09a, 0, 0xfffff),
14202- [GDT_ENTRY_KERNEL_DS] = GDT_ENTRY_INIT(0xc092, 0, 0xfffff),
14203- [GDT_ENTRY_DEFAULT_USER_CS] = GDT_ENTRY_INIT(0xc0fa, 0, 0xfffff),
14204- [GDT_ENTRY_DEFAULT_USER_DS] = GDT_ENTRY_INIT(0xc0f2, 0, 0xfffff),
14205- /*
14206- * Segments used for calling PnP BIOS have byte granularity.
14207- * They code segments and data segments have fixed 64k limits,
14208- * the transfer segment sizes are set at run time.
14209- */
14210- /* 32-bit code */
14211- [GDT_ENTRY_PNPBIOS_CS32] = GDT_ENTRY_INIT(0x409a, 0, 0xffff),
14212- /* 16-bit code */
14213- [GDT_ENTRY_PNPBIOS_CS16] = GDT_ENTRY_INIT(0x009a, 0, 0xffff),
14214- /* 16-bit data */
14215- [GDT_ENTRY_PNPBIOS_DS] = GDT_ENTRY_INIT(0x0092, 0, 0xffff),
14216- /* 16-bit data */
14217- [GDT_ENTRY_PNPBIOS_TS1] = GDT_ENTRY_INIT(0x0092, 0, 0),
14218- /* 16-bit data */
14219- [GDT_ENTRY_PNPBIOS_TS2] = GDT_ENTRY_INIT(0x0092, 0, 0),
14220- /*
14221- * The APM segments have byte granularity and their bases
14222- * are set at run time. All have 64k limits.
14223- */
14224- /* 32-bit code */
14225- [GDT_ENTRY_APMBIOS_BASE] = GDT_ENTRY_INIT(0x409a, 0, 0xffff),
14226- /* 16-bit code */
14227- [GDT_ENTRY_APMBIOS_BASE+1] = GDT_ENTRY_INIT(0x009a, 0, 0xffff),
14228- /* data */
14229- [GDT_ENTRY_APMBIOS_BASE+2] = GDT_ENTRY_INIT(0x4092, 0, 0xffff),
14230-
14231- [GDT_ENTRY_ESPFIX_SS] = GDT_ENTRY_INIT(0xc092, 0, 0xfffff),
14232- [GDT_ENTRY_PERCPU] = GDT_ENTRY_INIT(0xc092, 0, 0xfffff),
14233- GDT_STACK_CANARY_INIT
14234-#endif
14235-} };
14236-EXPORT_PER_CPU_SYMBOL_GPL(gdt_page);
14237-
14238 static int __init x86_xsave_setup(char *s)
14239 {
14240 setup_clear_cpu_cap(X86_FEATURE_XSAVE);
14241@@ -376,7 +322,7 @@ void switch_to_new_gdt(int cpu)
14242 {
14243 struct desc_ptr gdt_descr;
14244
14245- gdt_descr.address = (long)get_cpu_gdt_table(cpu);
14246+ gdt_descr.address = (unsigned long)get_cpu_gdt_table(cpu);
14247 gdt_descr.size = GDT_SIZE - 1;
14248 load_gdt(&gdt_descr);
14249 /* Reload the per-cpu base */
14250@@ -872,6 +818,10 @@ static void __cpuinit identify_cpu(struct cpuinfo_x86 *c)
14251 /* Filter out anything that depends on CPUID levels we don't have */
14252 filter_cpuid_features(c, true);
14253
14254+#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_SEGMEXEC) || defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF))
14255+ setup_clear_cpu_cap(X86_FEATURE_SEP);
14256+#endif
14257+
14258 /* If the model name is still unset, do table lookup. */
14259 if (!c->x86_model_id[0]) {
14260 const char *p;
14261@@ -1054,10 +1004,12 @@ static __init int setup_disablecpuid(char *arg)
14262 }
14263 __setup("clearcpuid=", setup_disablecpuid);
14264
14265+DEFINE_PER_CPU(struct thread_info *, current_tinfo) = &init_task.tinfo;
14266+EXPORT_PER_CPU_SYMBOL(current_tinfo);
14267+
14268 #ifdef CONFIG_X86_64
14269 struct desc_ptr idt_descr = { NR_VECTORS * 16 - 1, (unsigned long) idt_table };
14270-struct desc_ptr nmi_idt_descr = { NR_VECTORS * 16 - 1,
14271- (unsigned long) nmi_idt_table };
14272+struct desc_ptr nmi_idt_descr = { NR_VECTORS * 16 - 1, (unsigned long) nmi_idt_table };
14273
14274 DEFINE_PER_CPU_FIRST(union irq_stack_union,
14275 irq_stack_union) __aligned(PAGE_SIZE);
14276@@ -1071,7 +1023,7 @@ DEFINE_PER_CPU(struct task_struct *, current_task) ____cacheline_aligned =
14277 EXPORT_PER_CPU_SYMBOL(current_task);
14278
14279 DEFINE_PER_CPU(unsigned long, kernel_stack) =
14280- (unsigned long)&init_thread_union - KERNEL_STACK_OFFSET + THREAD_SIZE;
14281+ (unsigned long)&init_thread_union - 16 + THREAD_SIZE;
14282 EXPORT_PER_CPU_SYMBOL(kernel_stack);
14283
14284 DEFINE_PER_CPU(char *, irq_stack_ptr) =
14285@@ -1165,7 +1117,7 @@ struct pt_regs * __cpuinit idle_regs(struct pt_regs *regs)
14286 {
14287 memset(regs, 0, sizeof(struct pt_regs));
14288 regs->fs = __KERNEL_PERCPU;
14289- regs->gs = __KERNEL_STACK_CANARY;
14290+ savesegment(gs, regs->gs);
14291
14292 return regs;
14293 }
14294@@ -1220,7 +1172,7 @@ void __cpuinit cpu_init(void)
14295 int i;
14296
14297 cpu = stack_smp_processor_id();
14298- t = &per_cpu(init_tss, cpu);
14299+ t = init_tss + cpu;
14300 oist = &per_cpu(orig_ist, cpu);
14301
14302 #ifdef CONFIG_NUMA
14303@@ -1246,7 +1198,7 @@ void __cpuinit cpu_init(void)
14304 switch_to_new_gdt(cpu);
14305 loadsegment(fs, 0);
14306
14307- load_idt((const struct desc_ptr *)&idt_descr);
14308+ load_idt(&idt_descr);
14309
14310 memset(me->thread.tls_array, 0, GDT_ENTRY_TLS_ENTRIES * 8);
14311 syscall_init();
14312@@ -1255,7 +1207,6 @@ void __cpuinit cpu_init(void)
14313 wrmsrl(MSR_KERNEL_GS_BASE, 0);
14314 barrier();
14315
14316- x86_configure_nx();
14317 if (cpu != 0)
14318 enable_x2apic();
14319
14320@@ -1311,7 +1262,7 @@ void __cpuinit cpu_init(void)
14321 {
14322 int cpu = smp_processor_id();
14323 struct task_struct *curr = current;
14324- struct tss_struct *t = &per_cpu(init_tss, cpu);
14325+ struct tss_struct *t = init_tss + cpu;
14326 struct thread_struct *thread = &curr->thread;
14327
14328 if (cpumask_test_and_set_cpu(cpu, cpu_initialized_mask)) {
14329diff --git a/arch/x86/kernel/cpu/intel.c b/arch/x86/kernel/cpu/intel.c
14330index 0a4ce29..f211176 100644
14331--- a/arch/x86/kernel/cpu/intel.c
14332+++ b/arch/x86/kernel/cpu/intel.c
14333@@ -174,7 +174,7 @@ static void __cpuinit trap_init_f00f_bug(void)
14334 * Update the IDT descriptor and reload the IDT so that
14335 * it uses the read-only mapped virtual address.
14336 */
14337- idt_descr.address = fix_to_virt(FIX_F00F_IDT);
14338+ idt_descr.address = (struct desc_struct *)fix_to_virt(FIX_F00F_IDT);
14339 load_idt(&idt_descr);
14340 }
14341 #endif
14342diff --git a/arch/x86/kernel/cpu/mcheck/mce.c b/arch/x86/kernel/cpu/mcheck/mce.c
14343index 292d025..b520c94 100644
14344--- a/arch/x86/kernel/cpu/mcheck/mce.c
14345+++ b/arch/x86/kernel/cpu/mcheck/mce.c
14346@@ -45,6 +45,7 @@
14347 #include <asm/processor.h>
14348 #include <asm/mce.h>
14349 #include <asm/msr.h>
14350+#include <asm/local.h>
14351
14352 #include "mce-internal.h"
14353
14354@@ -253,7 +254,7 @@ static void print_mce(struct mce *m)
14355 !(m->mcgstatus & MCG_STATUS_EIPV) ? " !INEXACT!" : "",
14356 m->cs, m->ip);
14357
14358- if (m->cs == __KERNEL_CS)
14359+ if (m->cs == __KERNEL_CS || m->cs == __KERNEXEC_KERNEL_CS)
14360 print_symbol("{%s}", m->ip);
14361 pr_cont("\n");
14362 }
14363@@ -286,10 +287,10 @@ static void print_mce(struct mce *m)
14364
14365 #define PANIC_TIMEOUT 5 /* 5 seconds */
14366
14367-static atomic_t mce_paniced;
14368+static atomic_unchecked_t mce_paniced;
14369
14370 static int fake_panic;
14371-static atomic_t mce_fake_paniced;
14372+static atomic_unchecked_t mce_fake_paniced;
14373
14374 /* Panic in progress. Enable interrupts and wait for final IPI */
14375 static void wait_for_panic(void)
14376@@ -313,7 +314,7 @@ static void mce_panic(char *msg, struct mce *final, char *exp)
14377 /*
14378 * Make sure only one CPU runs in machine check panic
14379 */
14380- if (atomic_inc_return(&mce_paniced) > 1)
14381+ if (atomic_inc_return_unchecked(&mce_paniced) > 1)
14382 wait_for_panic();
14383 barrier();
14384
14385@@ -321,7 +322,7 @@ static void mce_panic(char *msg, struct mce *final, char *exp)
14386 console_verbose();
14387 } else {
14388 /* Don't log too much for fake panic */
14389- if (atomic_inc_return(&mce_fake_paniced) > 1)
14390+ if (atomic_inc_return_unchecked(&mce_fake_paniced) > 1)
14391 return;
14392 }
14393 /* First print corrected ones that are still unlogged */
14394@@ -693,7 +694,7 @@ static int mce_timed_out(u64 *t)
14395 * might have been modified by someone else.
14396 */
14397 rmb();
14398- if (atomic_read(&mce_paniced))
14399+ if (atomic_read_unchecked(&mce_paniced))
14400 wait_for_panic();
14401 if (!monarch_timeout)
14402 goto out;
14403@@ -1619,7 +1620,7 @@ static void unexpected_machine_check(struct pt_regs *regs, long error_code)
14404 }
14405
14406 /* Call the installed machine check handler for this CPU setup. */
14407-void (*machine_check_vector)(struct pt_regs *, long error_code) =
14408+void (*machine_check_vector)(struct pt_regs *, long error_code) __read_only =
14409 unexpected_machine_check;
14410
14411 /*
14412@@ -1642,7 +1643,9 @@ void __cpuinit mcheck_cpu_init(struct cpuinfo_x86 *c)
14413 return;
14414 }
14415
14416+ pax_open_kernel();
14417 machine_check_vector = do_machine_check;
14418+ pax_close_kernel();
14419
14420 __mcheck_cpu_init_generic();
14421 __mcheck_cpu_init_vendor(c);
14422@@ -1656,7 +1659,7 @@ void __cpuinit mcheck_cpu_init(struct cpuinfo_x86 *c)
14423 */
14424
14425 static DEFINE_SPINLOCK(mce_chrdev_state_lock);
14426-static int mce_chrdev_open_count; /* #times opened */
14427+static local_t mce_chrdev_open_count; /* #times opened */
14428 static int mce_chrdev_open_exclu; /* already open exclusive? */
14429
14430 static int mce_chrdev_open(struct inode *inode, struct file *file)
14431@@ -1664,7 +1667,7 @@ static int mce_chrdev_open(struct inode *inode, struct file *file)
14432 spin_lock(&mce_chrdev_state_lock);
14433
14434 if (mce_chrdev_open_exclu ||
14435- (mce_chrdev_open_count && (file->f_flags & O_EXCL))) {
14436+ (local_read(&mce_chrdev_open_count) && (file->f_flags & O_EXCL))) {
14437 spin_unlock(&mce_chrdev_state_lock);
14438
14439 return -EBUSY;
14440@@ -1672,7 +1675,7 @@ static int mce_chrdev_open(struct inode *inode, struct file *file)
14441
14442 if (file->f_flags & O_EXCL)
14443 mce_chrdev_open_exclu = 1;
14444- mce_chrdev_open_count++;
14445+ local_inc(&mce_chrdev_open_count);
14446
14447 spin_unlock(&mce_chrdev_state_lock);
14448
14449@@ -1683,7 +1686,7 @@ static int mce_chrdev_release(struct inode *inode, struct file *file)
14450 {
14451 spin_lock(&mce_chrdev_state_lock);
14452
14453- mce_chrdev_open_count--;
14454+ local_dec(&mce_chrdev_open_count);
14455 mce_chrdev_open_exclu = 0;
14456
14457 spin_unlock(&mce_chrdev_state_lock);
14458@@ -2407,7 +2410,7 @@ struct dentry *mce_get_debugfs_dir(void)
14459 static void mce_reset(void)
14460 {
14461 cpu_missing = 0;
14462- atomic_set(&mce_fake_paniced, 0);
14463+ atomic_set_unchecked(&mce_fake_paniced, 0);
14464 atomic_set(&mce_executing, 0);
14465 atomic_set(&mce_callin, 0);
14466 atomic_set(&global_nwo, 0);
14467diff --git a/arch/x86/kernel/cpu/mcheck/p5.c b/arch/x86/kernel/cpu/mcheck/p5.c
14468index 2d5454c..51987eb 100644
14469--- a/arch/x86/kernel/cpu/mcheck/p5.c
14470+++ b/arch/x86/kernel/cpu/mcheck/p5.c
14471@@ -11,6 +11,7 @@
14472 #include <asm/processor.h>
14473 #include <asm/mce.h>
14474 #include <asm/msr.h>
14475+#include <asm/pgtable.h>
14476
14477 /* By default disabled */
14478 int mce_p5_enabled __read_mostly;
14479@@ -49,7 +50,9 @@ void intel_p5_mcheck_init(struct cpuinfo_x86 *c)
14480 if (!cpu_has(c, X86_FEATURE_MCE))
14481 return;
14482
14483+ pax_open_kernel();
14484 machine_check_vector = pentium_machine_check;
14485+ pax_close_kernel();
14486 /* Make sure the vector pointer is visible before we enable MCEs: */
14487 wmb();
14488
14489diff --git a/arch/x86/kernel/cpu/mcheck/winchip.c b/arch/x86/kernel/cpu/mcheck/winchip.c
14490index 2d7998f..17c9de1 100644
14491--- a/arch/x86/kernel/cpu/mcheck/winchip.c
14492+++ b/arch/x86/kernel/cpu/mcheck/winchip.c
14493@@ -10,6 +10,7 @@
14494 #include <asm/processor.h>
14495 #include <asm/mce.h>
14496 #include <asm/msr.h>
14497+#include <asm/pgtable.h>
14498
14499 /* Machine check handler for WinChip C6: */
14500 static void winchip_machine_check(struct pt_regs *regs, long error_code)
14501@@ -23,7 +24,9 @@ void winchip_mcheck_init(struct cpuinfo_x86 *c)
14502 {
14503 u32 lo, hi;
14504
14505+ pax_open_kernel();
14506 machine_check_vector = winchip_machine_check;
14507+ pax_close_kernel();
14508 /* Make sure the vector pointer is visible before we enable MCEs: */
14509 wmb();
14510
14511diff --git a/arch/x86/kernel/cpu/mtrr/main.c b/arch/x86/kernel/cpu/mtrr/main.c
14512index 6b96110..0da73eb 100644
14513--- a/arch/x86/kernel/cpu/mtrr/main.c
14514+++ b/arch/x86/kernel/cpu/mtrr/main.c
14515@@ -62,7 +62,7 @@ static DEFINE_MUTEX(mtrr_mutex);
14516 u64 size_or_mask, size_and_mask;
14517 static bool mtrr_aps_delayed_init;
14518
14519-static const struct mtrr_ops *mtrr_ops[X86_VENDOR_NUM];
14520+static const struct mtrr_ops *mtrr_ops[X86_VENDOR_NUM] __read_only;
14521
14522 const struct mtrr_ops *mtrr_if;
14523
14524diff --git a/arch/x86/kernel/cpu/mtrr/mtrr.h b/arch/x86/kernel/cpu/mtrr/mtrr.h
14525index df5e41f..816c719 100644
14526--- a/arch/x86/kernel/cpu/mtrr/mtrr.h
14527+++ b/arch/x86/kernel/cpu/mtrr/mtrr.h
14528@@ -25,7 +25,7 @@ struct mtrr_ops {
14529 int (*validate_add_page)(unsigned long base, unsigned long size,
14530 unsigned int type);
14531 int (*have_wrcomb)(void);
14532-};
14533+} __do_const;
14534
14535 extern int generic_get_free_region(unsigned long base, unsigned long size,
14536 int replace_reg);
14537diff --git a/arch/x86/kernel/cpu/perf_event.c b/arch/x86/kernel/cpu/perf_event.c
14538index 915b876..171f845 100644
14539--- a/arch/x86/kernel/cpu/perf_event.c
14540+++ b/arch/x86/kernel/cpu/perf_event.c
14541@@ -1757,7 +1757,7 @@ static unsigned long get_segment_base(unsigned int segment)
14542 if (idx > GDT_ENTRIES)
14543 return 0;
14544
14545- desc = __this_cpu_ptr(&gdt_page.gdt[0]);
14546+ desc = get_cpu_gdt_table(smp_processor_id());
14547 }
14548
14549 return get_desc_base(desc + idx);
14550@@ -1847,7 +1847,7 @@ perf_callchain_user(struct perf_callchain_entry *entry, struct pt_regs *regs)
14551 break;
14552
14553 perf_callchain_store(entry, frame.return_address);
14554- fp = frame.next_frame;
14555+ fp = (const void __force_user *)frame.next_frame;
14556 }
14557 }
14558
14559diff --git a/arch/x86/kernel/cpu/perf_event_intel.c b/arch/x86/kernel/cpu/perf_event_intel.c
14560index 6bca492..36e4496 100644
14561--- a/arch/x86/kernel/cpu/perf_event_intel.c
14562+++ b/arch/x86/kernel/cpu/perf_event_intel.c
14563@@ -1947,10 +1947,10 @@ __init int intel_pmu_init(void)
14564 * v2 and above have a perf capabilities MSR
14565 */
14566 if (version > 1) {
14567- u64 capabilities;
14568+ u64 capabilities = x86_pmu.intel_cap.capabilities;
14569
14570- rdmsrl(MSR_IA32_PERF_CAPABILITIES, capabilities);
14571- x86_pmu.intel_cap.capabilities = capabilities;
14572+ if (rdmsrl_safe(MSR_IA32_PERF_CAPABILITIES, &x86_pmu.intel_cap.capabilities))
14573+ x86_pmu.intel_cap.capabilities = capabilities;
14574 }
14575
14576 intel_ds_init();
14577diff --git a/arch/x86/kernel/crash.c b/arch/x86/kernel/crash.c
14578index 13ad899..f642b9a 100644
14579--- a/arch/x86/kernel/crash.c
14580+++ b/arch/x86/kernel/crash.c
14581@@ -36,10 +36,8 @@ static void kdump_nmi_callback(int cpu, struct pt_regs *regs)
14582 {
14583 #ifdef CONFIG_X86_32
14584 struct pt_regs fixed_regs;
14585-#endif
14586
14587-#ifdef CONFIG_X86_32
14588- if (!user_mode_vm(regs)) {
14589+ if (!user_mode(regs)) {
14590 crash_fixup_ss_esp(&fixed_regs, regs);
14591 regs = &fixed_regs;
14592 }
14593diff --git a/arch/x86/kernel/doublefault_32.c b/arch/x86/kernel/doublefault_32.c
14594index 37250fe..bf2ec74 100644
14595--- a/arch/x86/kernel/doublefault_32.c
14596+++ b/arch/x86/kernel/doublefault_32.c
14597@@ -11,7 +11,7 @@
14598
14599 #define DOUBLEFAULT_STACKSIZE (1024)
14600 static unsigned long doublefault_stack[DOUBLEFAULT_STACKSIZE];
14601-#define STACK_START (unsigned long)(doublefault_stack+DOUBLEFAULT_STACKSIZE)
14602+#define STACK_START (unsigned long)(doublefault_stack+DOUBLEFAULT_STACKSIZE-2)
14603
14604 #define ptr_ok(x) ((x) > PAGE_OFFSET && (x) < PAGE_OFFSET + MAXMEM)
14605
14606@@ -21,7 +21,7 @@ static void doublefault_fn(void)
14607 unsigned long gdt, tss;
14608
14609 store_gdt(&gdt_desc);
14610- gdt = gdt_desc.address;
14611+ gdt = (unsigned long)gdt_desc.address;
14612
14613 printk(KERN_EMERG "PANIC: double fault, gdt at %08lx [%d bytes]\n", gdt, gdt_desc.size);
14614
14615@@ -58,10 +58,10 @@ struct tss_struct doublefault_tss __cacheline_aligned = {
14616 /* 0x2 bit is always set */
14617 .flags = X86_EFLAGS_SF | 0x2,
14618 .sp = STACK_START,
14619- .es = __USER_DS,
14620+ .es = __KERNEL_DS,
14621 .cs = __KERNEL_CS,
14622 .ss = __KERNEL_DS,
14623- .ds = __USER_DS,
14624+ .ds = __KERNEL_DS,
14625 .fs = __KERNEL_PERCPU,
14626
14627 .__cr3 = __pa_nodebug(swapper_pg_dir),
14628diff --git a/arch/x86/kernel/dumpstack.c b/arch/x86/kernel/dumpstack.c
14629index ae42418b..787c16b 100644
14630--- a/arch/x86/kernel/dumpstack.c
14631+++ b/arch/x86/kernel/dumpstack.c
14632@@ -2,6 +2,9 @@
14633 * Copyright (C) 1991, 1992 Linus Torvalds
14634 * Copyright (C) 2000, 2001, 2002 Andi Kleen, SuSE Labs
14635 */
14636+#ifdef CONFIG_GRKERNSEC_HIDESYM
14637+#define __INCLUDED_BY_HIDESYM 1
14638+#endif
14639 #include <linux/kallsyms.h>
14640 #include <linux/kprobes.h>
14641 #include <linux/uaccess.h>
14642@@ -35,16 +38,14 @@ void printk_address(unsigned long address, int reliable)
14643 static void
14644 print_ftrace_graph_addr(unsigned long addr, void *data,
14645 const struct stacktrace_ops *ops,
14646- struct thread_info *tinfo, int *graph)
14647+ struct task_struct *task, int *graph)
14648 {
14649- struct task_struct *task;
14650 unsigned long ret_addr;
14651 int index;
14652
14653 if (addr != (unsigned long)return_to_handler)
14654 return;
14655
14656- task = tinfo->task;
14657 index = task->curr_ret_stack;
14658
14659 if (!task->ret_stack || index < *graph)
14660@@ -61,7 +62,7 @@ print_ftrace_graph_addr(unsigned long addr, void *data,
14661 static inline void
14662 print_ftrace_graph_addr(unsigned long addr, void *data,
14663 const struct stacktrace_ops *ops,
14664- struct thread_info *tinfo, int *graph)
14665+ struct task_struct *task, int *graph)
14666 { }
14667 #endif
14668
14669@@ -72,10 +73,8 @@ print_ftrace_graph_addr(unsigned long addr, void *data,
14670 * severe exception (double fault, nmi, stack fault, debug, mce) hardware stack
14671 */
14672
14673-static inline int valid_stack_ptr(struct thread_info *tinfo,
14674- void *p, unsigned int size, void *end)
14675+static inline int valid_stack_ptr(void *t, void *p, unsigned int size, void *end)
14676 {
14677- void *t = tinfo;
14678 if (end) {
14679 if (p < end && p >= (end-THREAD_SIZE))
14680 return 1;
14681@@ -86,14 +85,14 @@ static inline int valid_stack_ptr(struct thread_info *tinfo,
14682 }
14683
14684 unsigned long
14685-print_context_stack(struct thread_info *tinfo,
14686+print_context_stack(struct task_struct *task, void *stack_start,
14687 unsigned long *stack, unsigned long bp,
14688 const struct stacktrace_ops *ops, void *data,
14689 unsigned long *end, int *graph)
14690 {
14691 struct stack_frame *frame = (struct stack_frame *)bp;
14692
14693- while (valid_stack_ptr(tinfo, stack, sizeof(*stack), end)) {
14694+ while (valid_stack_ptr(stack_start, stack, sizeof(*stack), end)) {
14695 unsigned long addr;
14696
14697 addr = *stack;
14698@@ -105,7 +104,7 @@ print_context_stack(struct thread_info *tinfo,
14699 } else {
14700 ops->address(data, addr, 0);
14701 }
14702- print_ftrace_graph_addr(addr, data, ops, tinfo, graph);
14703+ print_ftrace_graph_addr(addr, data, ops, task, graph);
14704 }
14705 stack++;
14706 }
14707@@ -114,7 +113,7 @@ print_context_stack(struct thread_info *tinfo,
14708 EXPORT_SYMBOL_GPL(print_context_stack);
14709
14710 unsigned long
14711-print_context_stack_bp(struct thread_info *tinfo,
14712+print_context_stack_bp(struct task_struct *task, void *stack_start,
14713 unsigned long *stack, unsigned long bp,
14714 const struct stacktrace_ops *ops, void *data,
14715 unsigned long *end, int *graph)
14716@@ -122,7 +121,7 @@ print_context_stack_bp(struct thread_info *tinfo,
14717 struct stack_frame *frame = (struct stack_frame *)bp;
14718 unsigned long *ret_addr = &frame->return_address;
14719
14720- while (valid_stack_ptr(tinfo, ret_addr, sizeof(*ret_addr), end)) {
14721+ while (valid_stack_ptr(stack_start, ret_addr, sizeof(*ret_addr), end)) {
14722 unsigned long addr = *ret_addr;
14723
14724 if (!__kernel_text_address(addr))
14725@@ -131,7 +130,7 @@ print_context_stack_bp(struct thread_info *tinfo,
14726 ops->address(data, addr, 1);
14727 frame = frame->next_frame;
14728 ret_addr = &frame->return_address;
14729- print_ftrace_graph_addr(addr, data, ops, tinfo, graph);
14730+ print_ftrace_graph_addr(addr, data, ops, task, graph);
14731 }
14732
14733 return (unsigned long)frame;
14734@@ -189,7 +188,7 @@ void dump_stack(void)
14735
14736 bp = stack_frame(current, NULL);
14737 printk("Pid: %d, comm: %.20s %s %s %.*s\n",
14738- current->pid, current->comm, print_tainted(),
14739+ task_pid_nr(current), current->comm, print_tainted(),
14740 init_utsname()->release,
14741 (int)strcspn(init_utsname()->version, " "),
14742 init_utsname()->version);
14743@@ -225,6 +224,8 @@ unsigned __kprobes long oops_begin(void)
14744 }
14745 EXPORT_SYMBOL_GPL(oops_begin);
14746
14747+extern void gr_handle_kernel_exploit(void);
14748+
14749 void __kprobes oops_end(unsigned long flags, struct pt_regs *regs, int signr)
14750 {
14751 if (regs && kexec_should_crash(current))
14752@@ -246,7 +247,10 @@ void __kprobes oops_end(unsigned long flags, struct pt_regs *regs, int signr)
14753 panic("Fatal exception in interrupt");
14754 if (panic_on_oops)
14755 panic("Fatal exception");
14756- do_exit(signr);
14757+
14758+ gr_handle_kernel_exploit();
14759+
14760+ do_group_exit(signr);
14761 }
14762
14763 int __kprobes __die(const char *str, struct pt_regs *regs, long err)
14764@@ -274,7 +278,7 @@ int __kprobes __die(const char *str, struct pt_regs *regs, long err)
14765 print_modules();
14766 show_regs(regs);
14767 #ifdef CONFIG_X86_32
14768- if (user_mode_vm(regs)) {
14769+ if (user_mode(regs)) {
14770 sp = regs->sp;
14771 ss = regs->ss & 0xffff;
14772 } else {
14773@@ -302,7 +306,7 @@ void die(const char *str, struct pt_regs *regs, long err)
14774 unsigned long flags = oops_begin();
14775 int sig = SIGSEGV;
14776
14777- if (!user_mode_vm(regs))
14778+ if (!user_mode(regs))
14779 report_bug(regs->ip, regs);
14780
14781 if (__die(str, regs, err))
14782diff --git a/arch/x86/kernel/dumpstack_32.c b/arch/x86/kernel/dumpstack_32.c
14783index 1038a41..ac7e5f6 100644
14784--- a/arch/x86/kernel/dumpstack_32.c
14785+++ b/arch/x86/kernel/dumpstack_32.c
14786@@ -38,15 +38,13 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
14787 bp = stack_frame(task, regs);
14788
14789 for (;;) {
14790- struct thread_info *context;
14791+ void *stack_start = (void *)((unsigned long)stack & ~(THREAD_SIZE-1));
14792
14793- context = (struct thread_info *)
14794- ((unsigned long)stack & (~(THREAD_SIZE - 1)));
14795- bp = ops->walk_stack(context, stack, bp, ops, data, NULL, &graph);
14796+ bp = ops->walk_stack(task, stack_start, stack, bp, ops, data, NULL, &graph);
14797
14798- stack = (unsigned long *)context->previous_esp;
14799- if (!stack)
14800+ if (stack_start == task_stack_page(task))
14801 break;
14802+ stack = *(unsigned long **)stack_start;
14803 if (ops->stack(data, "IRQ") < 0)
14804 break;
14805 touch_nmi_watchdog();
14806@@ -86,7 +84,7 @@ void show_regs(struct pt_regs *regs)
14807 {
14808 int i;
14809
14810- __show_regs(regs, !user_mode_vm(regs));
14811+ __show_regs(regs, !user_mode(regs));
14812
14813 pr_emerg("Process %.*s (pid: %d, ti=%p task=%p task.ti=%p)\n",
14814 TASK_COMM_LEN, current->comm, task_pid_nr(current),
14815@@ -95,21 +93,22 @@ void show_regs(struct pt_regs *regs)
14816 * When in-kernel, we also print out the stack and code at the
14817 * time of the fault..
14818 */
14819- if (!user_mode_vm(regs)) {
14820+ if (!user_mode(regs)) {
14821 unsigned int code_prologue = code_bytes * 43 / 64;
14822 unsigned int code_len = code_bytes;
14823 unsigned char c;
14824 u8 *ip;
14825+ unsigned long cs_base = get_desc_base(&get_cpu_gdt_table(smp_processor_id())[(0xffff & regs->cs) >> 3]);
14826
14827 pr_emerg("Stack:\n");
14828 show_stack_log_lvl(NULL, regs, &regs->sp, 0, KERN_EMERG);
14829
14830 pr_emerg("Code:");
14831
14832- ip = (u8 *)regs->ip - code_prologue;
14833+ ip = (u8 *)regs->ip - code_prologue + cs_base;
14834 if (ip < (u8 *)PAGE_OFFSET || probe_kernel_address(ip, c)) {
14835 /* try starting at IP */
14836- ip = (u8 *)regs->ip;
14837+ ip = (u8 *)regs->ip + cs_base;
14838 code_len = code_len - code_prologue + 1;
14839 }
14840 for (i = 0; i < code_len; i++, ip++) {
14841@@ -118,7 +117,7 @@ void show_regs(struct pt_regs *regs)
14842 pr_cont(" Bad EIP value.");
14843 break;
14844 }
14845- if (ip == (u8 *)regs->ip)
14846+ if (ip == (u8 *)regs->ip + cs_base)
14847 pr_cont(" <%02x>", c);
14848 else
14849 pr_cont(" %02x", c);
14850@@ -131,6 +130,7 @@ int is_valid_bugaddr(unsigned long ip)
14851 {
14852 unsigned short ud2;
14853
14854+ ip = ktla_ktva(ip);
14855 if (ip < PAGE_OFFSET)
14856 return 0;
14857 if (probe_kernel_address((unsigned short *)ip, ud2))
14858@@ -138,3 +138,15 @@ int is_valid_bugaddr(unsigned long ip)
14859
14860 return ud2 == 0x0b0f;
14861 }
14862+
14863+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
14864+void pax_check_alloca(unsigned long size)
14865+{
14866+ unsigned long sp = (unsigned long)&sp, stack_left;
14867+
14868+ /* all kernel stacks are of the same size */
14869+ stack_left = sp & (THREAD_SIZE - 1);
14870+ BUG_ON(stack_left < 256 || size >= stack_left - 256);
14871+}
14872+EXPORT_SYMBOL(pax_check_alloca);
14873+#endif
14874diff --git a/arch/x86/kernel/dumpstack_64.c b/arch/x86/kernel/dumpstack_64.c
14875index b653675..33190c0 100644
14876--- a/arch/x86/kernel/dumpstack_64.c
14877+++ b/arch/x86/kernel/dumpstack_64.c
14878@@ -119,9 +119,9 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
14879 unsigned long *irq_stack_end =
14880 (unsigned long *)per_cpu(irq_stack_ptr, cpu);
14881 unsigned used = 0;
14882- struct thread_info *tinfo;
14883 int graph = 0;
14884 unsigned long dummy;
14885+ void *stack_start;
14886
14887 if (!task)
14888 task = current;
14889@@ -142,10 +142,10 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
14890 * current stack address. If the stacks consist of nested
14891 * exceptions
14892 */
14893- tinfo = task_thread_info(task);
14894 for (;;) {
14895 char *id;
14896 unsigned long *estack_end;
14897+
14898 estack_end = in_exception_stack(cpu, (unsigned long)stack,
14899 &used, &id);
14900
14901@@ -153,7 +153,7 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
14902 if (ops->stack(data, id) < 0)
14903 break;
14904
14905- bp = ops->walk_stack(tinfo, stack, bp, ops,
14906+ bp = ops->walk_stack(task, estack_end - EXCEPTION_STKSZ, stack, bp, ops,
14907 data, estack_end, &graph);
14908 ops->stack(data, "<EOE>");
14909 /*
14910@@ -161,6 +161,8 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
14911 * second-to-last pointer (index -2 to end) in the
14912 * exception stack:
14913 */
14914+ if ((u16)estack_end[-1] != __KERNEL_DS)
14915+ goto out;
14916 stack = (unsigned long *) estack_end[-2];
14917 continue;
14918 }
14919@@ -172,7 +174,7 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
14920 if (in_irq_stack(stack, irq_stack, irq_stack_end)) {
14921 if (ops->stack(data, "IRQ") < 0)
14922 break;
14923- bp = ops->walk_stack(tinfo, stack, bp,
14924+ bp = ops->walk_stack(task, irq_stack, stack, bp,
14925 ops, data, irq_stack_end, &graph);
14926 /*
14927 * We link to the next stack (which would be
14928@@ -191,7 +193,9 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
14929 /*
14930 * This handles the process stack:
14931 */
14932- bp = ops->walk_stack(tinfo, stack, bp, ops, data, NULL, &graph);
14933+ stack_start = (void *)((unsigned long)stack & ~(THREAD_SIZE-1));
14934+ bp = ops->walk_stack(task, stack_start, stack, bp, ops, data, NULL, &graph);
14935+out:
14936 put_cpu();
14937 }
14938 EXPORT_SYMBOL(dump_trace);
14939@@ -304,3 +308,50 @@ int is_valid_bugaddr(unsigned long ip)
14940
14941 return ud2 == 0x0b0f;
14942 }
14943+
14944+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
14945+void pax_check_alloca(unsigned long size)
14946+{
14947+ unsigned long sp = (unsigned long)&sp, stack_start, stack_end;
14948+ unsigned cpu, used;
14949+ char *id;
14950+
14951+ /* check the process stack first */
14952+ stack_start = (unsigned long)task_stack_page(current);
14953+ stack_end = stack_start + THREAD_SIZE;
14954+ if (likely(stack_start <= sp && sp < stack_end)) {
14955+ unsigned long stack_left = sp & (THREAD_SIZE - 1);
14956+ BUG_ON(stack_left < 256 || size >= stack_left - 256);
14957+ return;
14958+ }
14959+
14960+ cpu = get_cpu();
14961+
14962+ /* check the irq stacks */
14963+ stack_end = (unsigned long)per_cpu(irq_stack_ptr, cpu);
14964+ stack_start = stack_end - IRQ_STACK_SIZE;
14965+ if (stack_start <= sp && sp < stack_end) {
14966+ unsigned long stack_left = sp & (IRQ_STACK_SIZE - 1);
14967+ put_cpu();
14968+ BUG_ON(stack_left < 256 || size >= stack_left - 256);
14969+ return;
14970+ }
14971+
14972+ /* check the exception stacks */
14973+ used = 0;
14974+ stack_end = (unsigned long)in_exception_stack(cpu, sp, &used, &id);
14975+ stack_start = stack_end - EXCEPTION_STKSZ;
14976+ if (stack_end && stack_start <= sp && sp < stack_end) {
14977+ unsigned long stack_left = sp & (EXCEPTION_STKSZ - 1);
14978+ put_cpu();
14979+ BUG_ON(stack_left < 256 || size >= stack_left - 256);
14980+ return;
14981+ }
14982+
14983+ put_cpu();
14984+
14985+ /* unknown stack */
14986+ BUG();
14987+}
14988+EXPORT_SYMBOL(pax_check_alloca);
14989+#endif
14990diff --git a/arch/x86/kernel/early_printk.c b/arch/x86/kernel/early_printk.c
14991index 9b9f18b..9fcaa04 100644
14992--- a/arch/x86/kernel/early_printk.c
14993+++ b/arch/x86/kernel/early_printk.c
14994@@ -7,6 +7,7 @@
14995 #include <linux/pci_regs.h>
14996 #include <linux/pci_ids.h>
14997 #include <linux/errno.h>
14998+#include <linux/sched.h>
14999 #include <asm/io.h>
15000 #include <asm/processor.h>
15001 #include <asm/fcntl.h>
15002diff --git a/arch/x86/kernel/entry_32.S b/arch/x86/kernel/entry_32.S
15003index 8f8e8ee..3617d6e 100644
15004--- a/arch/x86/kernel/entry_32.S
15005+++ b/arch/x86/kernel/entry_32.S
15006@@ -176,13 +176,153 @@
15007 /*CFI_REL_OFFSET gs, PT_GS*/
15008 .endm
15009 .macro SET_KERNEL_GS reg
15010+
15011+#ifdef CONFIG_CC_STACKPROTECTOR
15012 movl $(__KERNEL_STACK_CANARY), \reg
15013+#elif defined(CONFIG_PAX_MEMORY_UDEREF)
15014+ movl $(__USER_DS), \reg
15015+#else
15016+ xorl \reg, \reg
15017+#endif
15018+
15019 movl \reg, %gs
15020 .endm
15021
15022 #endif /* CONFIG_X86_32_LAZY_GS */
15023
15024-.macro SAVE_ALL
15025+.macro pax_enter_kernel
15026+#ifdef CONFIG_PAX_KERNEXEC
15027+ call pax_enter_kernel
15028+#endif
15029+.endm
15030+
15031+.macro pax_exit_kernel
15032+#ifdef CONFIG_PAX_KERNEXEC
15033+ call pax_exit_kernel
15034+#endif
15035+.endm
15036+
15037+#ifdef CONFIG_PAX_KERNEXEC
15038+ENTRY(pax_enter_kernel)
15039+#ifdef CONFIG_PARAVIRT
15040+ pushl %eax
15041+ pushl %ecx
15042+ call PARA_INDIRECT(pv_cpu_ops+PV_CPU_read_cr0)
15043+ mov %eax, %esi
15044+#else
15045+ mov %cr0, %esi
15046+#endif
15047+ bts $16, %esi
15048+ jnc 1f
15049+ mov %cs, %esi
15050+ cmp $__KERNEL_CS, %esi
15051+ jz 3f
15052+ ljmp $__KERNEL_CS, $3f
15053+1: ljmp $__KERNEXEC_KERNEL_CS, $2f
15054+2:
15055+#ifdef CONFIG_PARAVIRT
15056+ mov %esi, %eax
15057+ call PARA_INDIRECT(pv_cpu_ops+PV_CPU_write_cr0)
15058+#else
15059+ mov %esi, %cr0
15060+#endif
15061+3:
15062+#ifdef CONFIG_PARAVIRT
15063+ popl %ecx
15064+ popl %eax
15065+#endif
15066+ ret
15067+ENDPROC(pax_enter_kernel)
15068+
15069+ENTRY(pax_exit_kernel)
15070+#ifdef CONFIG_PARAVIRT
15071+ pushl %eax
15072+ pushl %ecx
15073+#endif
15074+ mov %cs, %esi
15075+ cmp $__KERNEXEC_KERNEL_CS, %esi
15076+ jnz 2f
15077+#ifdef CONFIG_PARAVIRT
15078+ call PARA_INDIRECT(pv_cpu_ops+PV_CPU_read_cr0);
15079+ mov %eax, %esi
15080+#else
15081+ mov %cr0, %esi
15082+#endif
15083+ btr $16, %esi
15084+ ljmp $__KERNEL_CS, $1f
15085+1:
15086+#ifdef CONFIG_PARAVIRT
15087+ mov %esi, %eax
15088+ call PARA_INDIRECT(pv_cpu_ops+PV_CPU_write_cr0);
15089+#else
15090+ mov %esi, %cr0
15091+#endif
15092+2:
15093+#ifdef CONFIG_PARAVIRT
15094+ popl %ecx
15095+ popl %eax
15096+#endif
15097+ ret
15098+ENDPROC(pax_exit_kernel)
15099+#endif
15100+
15101+.macro pax_erase_kstack
15102+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
15103+ call pax_erase_kstack
15104+#endif
15105+.endm
15106+
15107+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
15108+/*
15109+ * ebp: thread_info
15110+ */
15111+ENTRY(pax_erase_kstack)
15112+ pushl %edi
15113+ pushl %ecx
15114+ pushl %eax
15115+
15116+ mov TI_lowest_stack(%ebp), %edi
15117+ mov $-0xBEEF, %eax
15118+ std
15119+
15120+1: mov %edi, %ecx
15121+ and $THREAD_SIZE_asm - 1, %ecx
15122+ shr $2, %ecx
15123+ repne scasl
15124+ jecxz 2f
15125+
15126+ cmp $2*16, %ecx
15127+ jc 2f
15128+
15129+ mov $2*16, %ecx
15130+ repe scasl
15131+ jecxz 2f
15132+ jne 1b
15133+
15134+2: cld
15135+ mov %esp, %ecx
15136+ sub %edi, %ecx
15137+
15138+ cmp $THREAD_SIZE_asm, %ecx
15139+ jb 3f
15140+ ud2
15141+3:
15142+
15143+ shr $2, %ecx
15144+ rep stosl
15145+
15146+ mov TI_task_thread_sp0(%ebp), %edi
15147+ sub $128, %edi
15148+ mov %edi, TI_lowest_stack(%ebp)
15149+
15150+ popl %eax
15151+ popl %ecx
15152+ popl %edi
15153+ ret
15154+ENDPROC(pax_erase_kstack)
15155+#endif
15156+
15157+.macro __SAVE_ALL _DS
15158 cld
15159 PUSH_GS
15160 pushl_cfi %fs
15161@@ -205,7 +345,7 @@
15162 CFI_REL_OFFSET ecx, 0
15163 pushl_cfi %ebx
15164 CFI_REL_OFFSET ebx, 0
15165- movl $(__USER_DS), %edx
15166+ movl $\_DS, %edx
15167 movl %edx, %ds
15168 movl %edx, %es
15169 movl $(__KERNEL_PERCPU), %edx
15170@@ -213,6 +353,15 @@
15171 SET_KERNEL_GS %edx
15172 .endm
15173
15174+.macro SAVE_ALL
15175+#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
15176+ __SAVE_ALL __KERNEL_DS
15177+ pax_enter_kernel
15178+#else
15179+ __SAVE_ALL __USER_DS
15180+#endif
15181+.endm
15182+
15183 .macro RESTORE_INT_REGS
15184 popl_cfi %ebx
15185 CFI_RESTORE ebx
15186@@ -296,7 +445,7 @@ ENTRY(ret_from_fork)
15187 popfl_cfi
15188 jmp syscall_exit
15189 CFI_ENDPROC
15190-END(ret_from_fork)
15191+ENDPROC(ret_from_fork)
15192
15193 /*
15194 * Interrupt exit functions should be protected against kprobes
15195@@ -329,7 +478,15 @@ ret_from_intr:
15196 andl $SEGMENT_RPL_MASK, %eax
15197 #endif
15198 cmpl $USER_RPL, %eax
15199+
15200+#ifdef CONFIG_PAX_KERNEXEC
15201+ jae resume_userspace
15202+
15203+ pax_exit_kernel
15204+ jmp resume_kernel
15205+#else
15206 jb resume_kernel # not returning to v8086 or userspace
15207+#endif
15208
15209 ENTRY(resume_userspace)
15210 LOCKDEP_SYS_EXIT
15211@@ -341,8 +498,8 @@ ENTRY(resume_userspace)
15212 andl $_TIF_WORK_MASK, %ecx # is there any work to be done on
15213 # int/exception return?
15214 jne work_pending
15215- jmp restore_all
15216-END(ret_from_exception)
15217+ jmp restore_all_pax
15218+ENDPROC(ret_from_exception)
15219
15220 #ifdef CONFIG_PREEMPT
15221 ENTRY(resume_kernel)
15222@@ -357,7 +514,7 @@ need_resched:
15223 jz restore_all
15224 call preempt_schedule_irq
15225 jmp need_resched
15226-END(resume_kernel)
15227+ENDPROC(resume_kernel)
15228 #endif
15229 CFI_ENDPROC
15230 /*
15231@@ -391,28 +548,43 @@ sysenter_past_esp:
15232 /*CFI_REL_OFFSET cs, 0*/
15233 /*
15234 * Push current_thread_info()->sysenter_return to the stack.
15235- * A tiny bit of offset fixup is necessary - 4*4 means the 4 words
15236- * pushed above; +8 corresponds to copy_thread's esp0 setting.
15237 */
15238- pushl_cfi ((TI_sysenter_return)-THREAD_SIZE+8+4*4)(%esp)
15239+ pushl_cfi $0
15240 CFI_REL_OFFSET eip, 0
15241
15242 pushl_cfi %eax
15243 SAVE_ALL
15244+ GET_THREAD_INFO(%ebp)
15245+ movl TI_sysenter_return(%ebp),%ebp
15246+ movl %ebp,PT_EIP(%esp)
15247 ENABLE_INTERRUPTS(CLBR_NONE)
15248
15249 /*
15250 * Load the potential sixth argument from user stack.
15251 * Careful about security.
15252 */
15253+ movl PT_OLDESP(%esp),%ebp
15254+
15255+#ifdef CONFIG_PAX_MEMORY_UDEREF
15256+ mov PT_OLDSS(%esp),%ds
15257+1: movl %ds:(%ebp),%ebp
15258+ push %ss
15259+ pop %ds
15260+#else
15261 cmpl $__PAGE_OFFSET-3,%ebp
15262 jae syscall_fault
15263 1: movl (%ebp),%ebp
15264+#endif
15265+
15266 movl %ebp,PT_EBP(%esp)
15267 _ASM_EXTABLE(1b,syscall_fault)
15268
15269 GET_THREAD_INFO(%ebp)
15270
15271+#ifdef CONFIG_PAX_RANDKSTACK
15272+ pax_erase_kstack
15273+#endif
15274+
15275 testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%ebp)
15276 jnz sysenter_audit
15277 sysenter_do_call:
15278@@ -427,12 +599,24 @@ sysenter_do_call:
15279 testl $_TIF_ALLWORK_MASK, %ecx
15280 jne sysexit_audit
15281 sysenter_exit:
15282+
15283+#ifdef CONFIG_PAX_RANDKSTACK
15284+ pushl_cfi %eax
15285+ movl %esp, %eax
15286+ call pax_randomize_kstack
15287+ popl_cfi %eax
15288+#endif
15289+
15290+ pax_erase_kstack
15291+
15292 /* if something modifies registers it must also disable sysexit */
15293 movl PT_EIP(%esp), %edx
15294 movl PT_OLDESP(%esp), %ecx
15295 xorl %ebp,%ebp
15296 TRACE_IRQS_ON
15297 1: mov PT_FS(%esp), %fs
15298+2: mov PT_DS(%esp), %ds
15299+3: mov PT_ES(%esp), %es
15300 PTGS_TO_GS
15301 ENABLE_INTERRUPTS_SYSEXIT
15302
15303@@ -449,6 +633,9 @@ sysenter_audit:
15304 movl %eax,%edx /* 2nd arg: syscall number */
15305 movl $AUDIT_ARCH_I386,%eax /* 1st arg: audit arch */
15306 call __audit_syscall_entry
15307+
15308+ pax_erase_kstack
15309+
15310 pushl_cfi %ebx
15311 movl PT_EAX(%esp),%eax /* reload syscall number */
15312 jmp sysenter_do_call
15313@@ -474,10 +661,16 @@ sysexit_audit:
15314
15315 CFI_ENDPROC
15316 .pushsection .fixup,"ax"
15317-2: movl $0,PT_FS(%esp)
15318+4: movl $0,PT_FS(%esp)
15319+ jmp 1b
15320+5: movl $0,PT_DS(%esp)
15321+ jmp 1b
15322+6: movl $0,PT_ES(%esp)
15323 jmp 1b
15324 .popsection
15325- _ASM_EXTABLE(1b,2b)
15326+ _ASM_EXTABLE(1b,4b)
15327+ _ASM_EXTABLE(2b,5b)
15328+ _ASM_EXTABLE(3b,6b)
15329 PTGS_TO_GS_EX
15330 ENDPROC(ia32_sysenter_target)
15331
15332@@ -491,6 +684,11 @@ ENTRY(system_call)
15333 pushl_cfi %eax # save orig_eax
15334 SAVE_ALL
15335 GET_THREAD_INFO(%ebp)
15336+
15337+#ifdef CONFIG_PAX_RANDKSTACK
15338+ pax_erase_kstack
15339+#endif
15340+
15341 # system call tracing in operation / emulation
15342 testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%ebp)
15343 jnz syscall_trace_entry
15344@@ -509,6 +707,15 @@ syscall_exit:
15345 testl $_TIF_ALLWORK_MASK, %ecx # current->work
15346 jne syscall_exit_work
15347
15348+restore_all_pax:
15349+
15350+#ifdef CONFIG_PAX_RANDKSTACK
15351+ movl %esp, %eax
15352+ call pax_randomize_kstack
15353+#endif
15354+
15355+ pax_erase_kstack
15356+
15357 restore_all:
15358 TRACE_IRQS_IRET
15359 restore_all_notrace:
15360@@ -565,14 +772,34 @@ ldt_ss:
15361 * compensating for the offset by changing to the ESPFIX segment with
15362 * a base address that matches for the difference.
15363 */
15364-#define GDT_ESPFIX_SS PER_CPU_VAR(gdt_page) + (GDT_ENTRY_ESPFIX_SS * 8)
15365+#define GDT_ESPFIX_SS (GDT_ENTRY_ESPFIX_SS * 8)(%ebx)
15366 mov %esp, %edx /* load kernel esp */
15367 mov PT_OLDESP(%esp), %eax /* load userspace esp */
15368 mov %dx, %ax /* eax: new kernel esp */
15369 sub %eax, %edx /* offset (low word is 0) */
15370+#ifdef CONFIG_SMP
15371+ movl PER_CPU_VAR(cpu_number), %ebx
15372+ shll $PAGE_SHIFT_asm, %ebx
15373+ addl $cpu_gdt_table, %ebx
15374+#else
15375+ movl $cpu_gdt_table, %ebx
15376+#endif
15377 shr $16, %edx
15378- mov %dl, GDT_ESPFIX_SS + 4 /* bits 16..23 */
15379- mov %dh, GDT_ESPFIX_SS + 7 /* bits 24..31 */
15380+
15381+#ifdef CONFIG_PAX_KERNEXEC
15382+ mov %cr0, %esi
15383+ btr $16, %esi
15384+ mov %esi, %cr0
15385+#endif
15386+
15387+ mov %dl, 4 + GDT_ESPFIX_SS /* bits 16..23 */
15388+ mov %dh, 7 + GDT_ESPFIX_SS /* bits 24..31 */
15389+
15390+#ifdef CONFIG_PAX_KERNEXEC
15391+ bts $16, %esi
15392+ mov %esi, %cr0
15393+#endif
15394+
15395 pushl_cfi $__ESPFIX_SS
15396 pushl_cfi %eax /* new kernel esp */
15397 /* Disable interrupts, but do not irqtrace this section: we
15398@@ -601,35 +828,23 @@ work_resched:
15399 movl TI_flags(%ebp), %ecx
15400 andl $_TIF_WORK_MASK, %ecx # is there any work to be done other
15401 # than syscall tracing?
15402- jz restore_all
15403+ jz restore_all_pax
15404 testb $_TIF_NEED_RESCHED, %cl
15405 jnz work_resched
15406
15407 work_notifysig: # deal with pending signals and
15408 # notify-resume requests
15409+ movl %esp, %eax
15410 #ifdef CONFIG_VM86
15411 testl $X86_EFLAGS_VM, PT_EFLAGS(%esp)
15412- movl %esp, %eax
15413- jne work_notifysig_v86 # returning to kernel-space or
15414+ jz 1f # returning to kernel-space or
15415 # vm86-space
15416- TRACE_IRQS_ON
15417- ENABLE_INTERRUPTS(CLBR_NONE)
15418- movb PT_CS(%esp), %bl
15419- andb $SEGMENT_RPL_MASK, %bl
15420- cmpb $USER_RPL, %bl
15421- jb resume_kernel
15422- xorl %edx, %edx
15423- call do_notify_resume
15424- jmp resume_userspace
15425
15426- ALIGN
15427-work_notifysig_v86:
15428 pushl_cfi %ecx # save ti_flags for do_notify_resume
15429 call save_v86_state # %eax contains pt_regs pointer
15430 popl_cfi %ecx
15431 movl %eax, %esp
15432-#else
15433- movl %esp, %eax
15434+1:
15435 #endif
15436 TRACE_IRQS_ON
15437 ENABLE_INTERRUPTS(CLBR_NONE)
15438@@ -640,7 +855,7 @@ work_notifysig_v86:
15439 xorl %edx, %edx
15440 call do_notify_resume
15441 jmp resume_userspace
15442-END(work_pending)
15443+ENDPROC(work_pending)
15444
15445 # perform syscall exit tracing
15446 ALIGN
15447@@ -648,11 +863,14 @@ syscall_trace_entry:
15448 movl $-ENOSYS,PT_EAX(%esp)
15449 movl %esp, %eax
15450 call syscall_trace_enter
15451+
15452+ pax_erase_kstack
15453+
15454 /* What it returned is what we'll actually use. */
15455 cmpl $(NR_syscalls), %eax
15456 jnae syscall_call
15457 jmp syscall_exit
15458-END(syscall_trace_entry)
15459+ENDPROC(syscall_trace_entry)
15460
15461 # perform syscall exit tracing
15462 ALIGN
15463@@ -665,20 +883,24 @@ syscall_exit_work:
15464 movl %esp, %eax
15465 call syscall_trace_leave
15466 jmp resume_userspace
15467-END(syscall_exit_work)
15468+ENDPROC(syscall_exit_work)
15469 CFI_ENDPROC
15470
15471 RING0_INT_FRAME # can't unwind into user space anyway
15472 syscall_fault:
15473+#ifdef CONFIG_PAX_MEMORY_UDEREF
15474+ push %ss
15475+ pop %ds
15476+#endif
15477 GET_THREAD_INFO(%ebp)
15478 movl $-EFAULT,PT_EAX(%esp)
15479 jmp resume_userspace
15480-END(syscall_fault)
15481+ENDPROC(syscall_fault)
15482
15483 syscall_badsys:
15484 movl $-ENOSYS,PT_EAX(%esp)
15485 jmp resume_userspace
15486-END(syscall_badsys)
15487+ENDPROC(syscall_badsys)
15488 CFI_ENDPROC
15489 /*
15490 * End of kprobes section
15491@@ -750,6 +972,36 @@ ENTRY(ptregs_clone)
15492 CFI_ENDPROC
15493 ENDPROC(ptregs_clone)
15494
15495+ ALIGN;
15496+ENTRY(kernel_execve)
15497+ CFI_STARTPROC
15498+ pushl_cfi %ebp
15499+ sub $PT_OLDSS+4,%esp
15500+ pushl_cfi %edi
15501+ pushl_cfi %ecx
15502+ pushl_cfi %eax
15503+ lea 3*4(%esp),%edi
15504+ mov $PT_OLDSS/4+1,%ecx
15505+ xorl %eax,%eax
15506+ rep stosl
15507+ popl_cfi %eax
15508+ popl_cfi %ecx
15509+ popl_cfi %edi
15510+ movl $X86_EFLAGS_IF,PT_EFLAGS(%esp)
15511+ pushl_cfi %esp
15512+ call sys_execve
15513+ add $4,%esp
15514+ CFI_ADJUST_CFA_OFFSET -4
15515+ GET_THREAD_INFO(%ebp)
15516+ test %eax,%eax
15517+ jz syscall_exit
15518+ add $PT_OLDSS+4,%esp
15519+ CFI_ADJUST_CFA_OFFSET -PT_OLDSS-4
15520+ popl_cfi %ebp
15521+ ret
15522+ CFI_ENDPROC
15523+ENDPROC(kernel_execve)
15524+
15525 .macro FIXUP_ESPFIX_STACK
15526 /*
15527 * Switch back for ESPFIX stack to the normal zerobased stack
15528@@ -759,8 +1011,15 @@ ENDPROC(ptregs_clone)
15529 * normal stack and adjusts ESP with the matching offset.
15530 */
15531 /* fixup the stack */
15532- mov GDT_ESPFIX_SS + 4, %al /* bits 16..23 */
15533- mov GDT_ESPFIX_SS + 7, %ah /* bits 24..31 */
15534+#ifdef CONFIG_SMP
15535+ movl PER_CPU_VAR(cpu_number), %ebx
15536+ shll $PAGE_SHIFT_asm, %ebx
15537+ addl $cpu_gdt_table, %ebx
15538+#else
15539+ movl $cpu_gdt_table, %ebx
15540+#endif
15541+ mov 4 + GDT_ESPFIX_SS, %al /* bits 16..23 */
15542+ mov 7 + GDT_ESPFIX_SS, %ah /* bits 24..31 */
15543 shl $16, %eax
15544 addl %esp, %eax /* the adjusted stack pointer */
15545 pushl_cfi $__KERNEL_DS
15546@@ -813,7 +1072,7 @@ vector=vector+1
15547 .endr
15548 2: jmp common_interrupt
15549 .endr
15550-END(irq_entries_start)
15551+ENDPROC(irq_entries_start)
15552
15553 .previous
15554 END(interrupt)
15555@@ -861,7 +1120,7 @@ ENTRY(coprocessor_error)
15556 pushl_cfi $do_coprocessor_error
15557 jmp error_code
15558 CFI_ENDPROC
15559-END(coprocessor_error)
15560+ENDPROC(coprocessor_error)
15561
15562 ENTRY(simd_coprocessor_error)
15563 RING0_INT_FRAME
15564@@ -882,7 +1141,7 @@ ENTRY(simd_coprocessor_error)
15565 #endif
15566 jmp error_code
15567 CFI_ENDPROC
15568-END(simd_coprocessor_error)
15569+ENDPROC(simd_coprocessor_error)
15570
15571 ENTRY(device_not_available)
15572 RING0_INT_FRAME
15573@@ -890,18 +1149,18 @@ ENTRY(device_not_available)
15574 pushl_cfi $do_device_not_available
15575 jmp error_code
15576 CFI_ENDPROC
15577-END(device_not_available)
15578+ENDPROC(device_not_available)
15579
15580 #ifdef CONFIG_PARAVIRT
15581 ENTRY(native_iret)
15582 iret
15583 _ASM_EXTABLE(native_iret, iret_exc)
15584-END(native_iret)
15585+ENDPROC(native_iret)
15586
15587 ENTRY(native_irq_enable_sysexit)
15588 sti
15589 sysexit
15590-END(native_irq_enable_sysexit)
15591+ENDPROC(native_irq_enable_sysexit)
15592 #endif
15593
15594 ENTRY(overflow)
15595@@ -910,7 +1169,7 @@ ENTRY(overflow)
15596 pushl_cfi $do_overflow
15597 jmp error_code
15598 CFI_ENDPROC
15599-END(overflow)
15600+ENDPROC(overflow)
15601
15602 ENTRY(bounds)
15603 RING0_INT_FRAME
15604@@ -918,7 +1177,7 @@ ENTRY(bounds)
15605 pushl_cfi $do_bounds
15606 jmp error_code
15607 CFI_ENDPROC
15608-END(bounds)
15609+ENDPROC(bounds)
15610
15611 ENTRY(invalid_op)
15612 RING0_INT_FRAME
15613@@ -926,7 +1185,7 @@ ENTRY(invalid_op)
15614 pushl_cfi $do_invalid_op
15615 jmp error_code
15616 CFI_ENDPROC
15617-END(invalid_op)
15618+ENDPROC(invalid_op)
15619
15620 ENTRY(coprocessor_segment_overrun)
15621 RING0_INT_FRAME
15622@@ -934,35 +1193,35 @@ ENTRY(coprocessor_segment_overrun)
15623 pushl_cfi $do_coprocessor_segment_overrun
15624 jmp error_code
15625 CFI_ENDPROC
15626-END(coprocessor_segment_overrun)
15627+ENDPROC(coprocessor_segment_overrun)
15628
15629 ENTRY(invalid_TSS)
15630 RING0_EC_FRAME
15631 pushl_cfi $do_invalid_TSS
15632 jmp error_code
15633 CFI_ENDPROC
15634-END(invalid_TSS)
15635+ENDPROC(invalid_TSS)
15636
15637 ENTRY(segment_not_present)
15638 RING0_EC_FRAME
15639 pushl_cfi $do_segment_not_present
15640 jmp error_code
15641 CFI_ENDPROC
15642-END(segment_not_present)
15643+ENDPROC(segment_not_present)
15644
15645 ENTRY(stack_segment)
15646 RING0_EC_FRAME
15647 pushl_cfi $do_stack_segment
15648 jmp error_code
15649 CFI_ENDPROC
15650-END(stack_segment)
15651+ENDPROC(stack_segment)
15652
15653 ENTRY(alignment_check)
15654 RING0_EC_FRAME
15655 pushl_cfi $do_alignment_check
15656 jmp error_code
15657 CFI_ENDPROC
15658-END(alignment_check)
15659+ENDPROC(alignment_check)
15660
15661 ENTRY(divide_error)
15662 RING0_INT_FRAME
15663@@ -970,7 +1229,7 @@ ENTRY(divide_error)
15664 pushl_cfi $do_divide_error
15665 jmp error_code
15666 CFI_ENDPROC
15667-END(divide_error)
15668+ENDPROC(divide_error)
15669
15670 #ifdef CONFIG_X86_MCE
15671 ENTRY(machine_check)
15672@@ -979,7 +1238,7 @@ ENTRY(machine_check)
15673 pushl_cfi machine_check_vector
15674 jmp error_code
15675 CFI_ENDPROC
15676-END(machine_check)
15677+ENDPROC(machine_check)
15678 #endif
15679
15680 ENTRY(spurious_interrupt_bug)
15681@@ -988,7 +1247,7 @@ ENTRY(spurious_interrupt_bug)
15682 pushl_cfi $do_spurious_interrupt_bug
15683 jmp error_code
15684 CFI_ENDPROC
15685-END(spurious_interrupt_bug)
15686+ENDPROC(spurious_interrupt_bug)
15687 /*
15688 * End of kprobes section
15689 */
15690@@ -1102,7 +1361,7 @@ BUILD_INTERRUPT3(xen_hvm_callback_vector, XEN_HVM_EVTCHN_CALLBACK,
15691
15692 ENTRY(mcount)
15693 ret
15694-END(mcount)
15695+ENDPROC(mcount)
15696
15697 ENTRY(ftrace_caller)
15698 cmpl $0, function_trace_stop
15699@@ -1131,7 +1390,7 @@ ftrace_graph_call:
15700 .globl ftrace_stub
15701 ftrace_stub:
15702 ret
15703-END(ftrace_caller)
15704+ENDPROC(ftrace_caller)
15705
15706 #else /* ! CONFIG_DYNAMIC_FTRACE */
15707
15708@@ -1167,7 +1426,7 @@ trace:
15709 popl %ecx
15710 popl %eax
15711 jmp ftrace_stub
15712-END(mcount)
15713+ENDPROC(mcount)
15714 #endif /* CONFIG_DYNAMIC_FTRACE */
15715 #endif /* CONFIG_FUNCTION_TRACER */
15716
15717@@ -1188,7 +1447,7 @@ ENTRY(ftrace_graph_caller)
15718 popl %ecx
15719 popl %eax
15720 ret
15721-END(ftrace_graph_caller)
15722+ENDPROC(ftrace_graph_caller)
15723
15724 .globl return_to_handler
15725 return_to_handler:
15726@@ -1243,15 +1502,18 @@ error_code:
15727 movl $-1, PT_ORIG_EAX(%esp) # no syscall to restart
15728 REG_TO_PTGS %ecx
15729 SET_KERNEL_GS %ecx
15730- movl $(__USER_DS), %ecx
15731+ movl $(__KERNEL_DS), %ecx
15732 movl %ecx, %ds
15733 movl %ecx, %es
15734+
15735+ pax_enter_kernel
15736+
15737 TRACE_IRQS_OFF
15738 movl %esp,%eax # pt_regs pointer
15739 call *%edi
15740 jmp ret_from_exception
15741 CFI_ENDPROC
15742-END(page_fault)
15743+ENDPROC(page_fault)
15744
15745 /*
15746 * Debug traps and NMI can happen at the one SYSENTER instruction
15747@@ -1293,7 +1555,7 @@ debug_stack_correct:
15748 call do_debug
15749 jmp ret_from_exception
15750 CFI_ENDPROC
15751-END(debug)
15752+ENDPROC(debug)
15753
15754 /*
15755 * NMI is doubly nasty. It can happen _while_ we're handling
15756@@ -1330,6 +1592,9 @@ nmi_stack_correct:
15757 xorl %edx,%edx # zero error code
15758 movl %esp,%eax # pt_regs pointer
15759 call do_nmi
15760+
15761+ pax_exit_kernel
15762+
15763 jmp restore_all_notrace
15764 CFI_ENDPROC
15765
15766@@ -1366,12 +1631,15 @@ nmi_espfix_stack:
15767 FIXUP_ESPFIX_STACK # %eax == %esp
15768 xorl %edx,%edx # zero error code
15769 call do_nmi
15770+
15771+ pax_exit_kernel
15772+
15773 RESTORE_REGS
15774 lss 12+4(%esp), %esp # back to espfix stack
15775 CFI_ADJUST_CFA_OFFSET -24
15776 jmp irq_return
15777 CFI_ENDPROC
15778-END(nmi)
15779+ENDPROC(nmi)
15780
15781 ENTRY(int3)
15782 RING0_INT_FRAME
15783@@ -1383,14 +1651,14 @@ ENTRY(int3)
15784 call do_int3
15785 jmp ret_from_exception
15786 CFI_ENDPROC
15787-END(int3)
15788+ENDPROC(int3)
15789
15790 ENTRY(general_protection)
15791 RING0_EC_FRAME
15792 pushl_cfi $do_general_protection
15793 jmp error_code
15794 CFI_ENDPROC
15795-END(general_protection)
15796+ENDPROC(general_protection)
15797
15798 #ifdef CONFIG_KVM_GUEST
15799 ENTRY(async_page_fault)
15800@@ -1398,7 +1666,7 @@ ENTRY(async_page_fault)
15801 pushl_cfi $do_async_page_fault
15802 jmp error_code
15803 CFI_ENDPROC
15804-END(async_page_fault)
15805+ENDPROC(async_page_fault)
15806 #endif
15807
15808 /*
15809diff --git a/arch/x86/kernel/entry_64.S b/arch/x86/kernel/entry_64.S
15810index dcdd0ea..8f32835 100644
15811--- a/arch/x86/kernel/entry_64.S
15812+++ b/arch/x86/kernel/entry_64.S
15813@@ -57,6 +57,8 @@
15814 #include <asm/percpu.h>
15815 #include <asm/asm.h>
15816 #include <linux/err.h>
15817+#include <asm/pgtable.h>
15818+#include <asm/alternative-asm.h>
15819
15820 /* Avoid __ASSEMBLER__'ifying <linux/audit.h> just for this. */
15821 #include <linux/elf-em.h>
15822@@ -70,8 +72,9 @@
15823 #ifdef CONFIG_FUNCTION_TRACER
15824 #ifdef CONFIG_DYNAMIC_FTRACE
15825 ENTRY(mcount)
15826+ pax_force_retaddr
15827 retq
15828-END(mcount)
15829+ENDPROC(mcount)
15830
15831 ENTRY(ftrace_caller)
15832 cmpl $0, function_trace_stop
15833@@ -94,8 +97,9 @@ GLOBAL(ftrace_graph_call)
15834 #endif
15835
15836 GLOBAL(ftrace_stub)
15837+ pax_force_retaddr
15838 retq
15839-END(ftrace_caller)
15840+ENDPROC(ftrace_caller)
15841
15842 #else /* ! CONFIG_DYNAMIC_FTRACE */
15843 ENTRY(mcount)
15844@@ -114,6 +118,7 @@ ENTRY(mcount)
15845 #endif
15846
15847 GLOBAL(ftrace_stub)
15848+ pax_force_retaddr
15849 retq
15850
15851 trace:
15852@@ -123,12 +128,13 @@ trace:
15853 movq 8(%rbp), %rsi
15854 subq $MCOUNT_INSN_SIZE, %rdi
15855
15856+ pax_force_fptr ftrace_trace_function
15857 call *ftrace_trace_function
15858
15859 MCOUNT_RESTORE_FRAME
15860
15861 jmp ftrace_stub
15862-END(mcount)
15863+ENDPROC(mcount)
15864 #endif /* CONFIG_DYNAMIC_FTRACE */
15865 #endif /* CONFIG_FUNCTION_TRACER */
15866
15867@@ -148,8 +154,9 @@ ENTRY(ftrace_graph_caller)
15868
15869 MCOUNT_RESTORE_FRAME
15870
15871+ pax_force_retaddr
15872 retq
15873-END(ftrace_graph_caller)
15874+ENDPROC(ftrace_graph_caller)
15875
15876 GLOBAL(return_to_handler)
15877 subq $24, %rsp
15878@@ -165,6 +172,7 @@ GLOBAL(return_to_handler)
15879 movq 8(%rsp), %rdx
15880 movq (%rsp), %rax
15881 addq $24, %rsp
15882+ pax_force_fptr %rdi
15883 jmp *%rdi
15884 #endif
15885
15886@@ -180,6 +188,273 @@ ENTRY(native_usergs_sysret64)
15887 ENDPROC(native_usergs_sysret64)
15888 #endif /* CONFIG_PARAVIRT */
15889
15890+ .macro ljmpq sel, off
15891+#if defined(CONFIG_MPSC) || defined(CONFIG_MCORE2) || defined (CONFIG_MATOM)
15892+ .byte 0x48; ljmp *1234f(%rip)
15893+ .pushsection .rodata
15894+ .align 16
15895+ 1234: .quad \off; .word \sel
15896+ .popsection
15897+#else
15898+ pushq $\sel
15899+ pushq $\off
15900+ lretq
15901+#endif
15902+ .endm
15903+
15904+ .macro pax_enter_kernel
15905+ pax_set_fptr_mask
15906+#ifdef CONFIG_PAX_KERNEXEC
15907+ call pax_enter_kernel
15908+#endif
15909+ .endm
15910+
15911+ .macro pax_exit_kernel
15912+#ifdef CONFIG_PAX_KERNEXEC
15913+ call pax_exit_kernel
15914+#endif
15915+ .endm
15916+
15917+#ifdef CONFIG_PAX_KERNEXEC
15918+ENTRY(pax_enter_kernel)
15919+ pushq %rdi
15920+
15921+#ifdef CONFIG_PARAVIRT
15922+ PV_SAVE_REGS(CLBR_RDI)
15923+#endif
15924+
15925+ GET_CR0_INTO_RDI
15926+ bts $16,%rdi
15927+ jnc 3f
15928+ mov %cs,%edi
15929+ cmp $__KERNEL_CS,%edi
15930+ jnz 2f
15931+1:
15932+
15933+#ifdef CONFIG_PARAVIRT
15934+ PV_RESTORE_REGS(CLBR_RDI)
15935+#endif
15936+
15937+ popq %rdi
15938+ pax_force_retaddr
15939+ retq
15940+
15941+2: ljmpq __KERNEL_CS,1f
15942+3: ljmpq __KERNEXEC_KERNEL_CS,4f
15943+4: SET_RDI_INTO_CR0
15944+ jmp 1b
15945+ENDPROC(pax_enter_kernel)
15946+
15947+ENTRY(pax_exit_kernel)
15948+ pushq %rdi
15949+
15950+#ifdef CONFIG_PARAVIRT
15951+ PV_SAVE_REGS(CLBR_RDI)
15952+#endif
15953+
15954+ mov %cs,%rdi
15955+ cmp $__KERNEXEC_KERNEL_CS,%edi
15956+ jz 2f
15957+1:
15958+
15959+#ifdef CONFIG_PARAVIRT
15960+ PV_RESTORE_REGS(CLBR_RDI);
15961+#endif
15962+
15963+ popq %rdi
15964+ pax_force_retaddr
15965+ retq
15966+
15967+2: GET_CR0_INTO_RDI
15968+ btr $16,%rdi
15969+ ljmpq __KERNEL_CS,3f
15970+3: SET_RDI_INTO_CR0
15971+ jmp 1b
15972+ENDPROC(pax_exit_kernel)
15973+#endif
15974+
15975+ .macro pax_enter_kernel_user
15976+ pax_set_fptr_mask
15977+#ifdef CONFIG_PAX_MEMORY_UDEREF
15978+ call pax_enter_kernel_user
15979+#endif
15980+ .endm
15981+
15982+ .macro pax_exit_kernel_user
15983+#ifdef CONFIG_PAX_MEMORY_UDEREF
15984+ call pax_exit_kernel_user
15985+#endif
15986+#ifdef CONFIG_PAX_RANDKSTACK
15987+ pushq %rax
15988+ call pax_randomize_kstack
15989+ popq %rax
15990+#endif
15991+ .endm
15992+
15993+#ifdef CONFIG_PAX_MEMORY_UDEREF
15994+ENTRY(pax_enter_kernel_user)
15995+ pushq %rdi
15996+ pushq %rbx
15997+
15998+#ifdef CONFIG_PARAVIRT
15999+ PV_SAVE_REGS(CLBR_RDI)
16000+#endif
16001+
16002+ GET_CR3_INTO_RDI
16003+ mov %rdi,%rbx
16004+ add $__START_KERNEL_map,%rbx
16005+ sub phys_base(%rip),%rbx
16006+
16007+#ifdef CONFIG_PARAVIRT
16008+ pushq %rdi
16009+ cmpl $0, pv_info+PARAVIRT_enabled
16010+ jz 1f
16011+ i = 0
16012+ .rept USER_PGD_PTRS
16013+ mov i*8(%rbx),%rsi
16014+ mov $0,%sil
16015+ lea i*8(%rbx),%rdi
16016+ call PARA_INDIRECT(pv_mmu_ops+PV_MMU_set_pgd_batched)
16017+ i = i + 1
16018+ .endr
16019+ jmp 2f
16020+1:
16021+#endif
16022+
16023+ i = 0
16024+ .rept USER_PGD_PTRS
16025+ movb $0,i*8(%rbx)
16026+ i = i + 1
16027+ .endr
16028+
16029+#ifdef CONFIG_PARAVIRT
16030+2: popq %rdi
16031+#endif
16032+ SET_RDI_INTO_CR3
16033+
16034+#ifdef CONFIG_PAX_KERNEXEC
16035+ GET_CR0_INTO_RDI
16036+ bts $16,%rdi
16037+ SET_RDI_INTO_CR0
16038+#endif
16039+
16040+#ifdef CONFIG_PARAVIRT
16041+ PV_RESTORE_REGS(CLBR_RDI)
16042+#endif
16043+
16044+ popq %rbx
16045+ popq %rdi
16046+ pax_force_retaddr
16047+ retq
16048+ENDPROC(pax_enter_kernel_user)
16049+
16050+ENTRY(pax_exit_kernel_user)
16051+ push %rdi
16052+
16053+#ifdef CONFIG_PARAVIRT
16054+ pushq %rbx
16055+ PV_SAVE_REGS(CLBR_RDI)
16056+#endif
16057+
16058+#ifdef CONFIG_PAX_KERNEXEC
16059+ GET_CR0_INTO_RDI
16060+ btr $16,%rdi
16061+ SET_RDI_INTO_CR0
16062+#endif
16063+
16064+ GET_CR3_INTO_RDI
16065+ add $__START_KERNEL_map,%rdi
16066+ sub phys_base(%rip),%rdi
16067+
16068+#ifdef CONFIG_PARAVIRT
16069+ cmpl $0, pv_info+PARAVIRT_enabled
16070+ jz 1f
16071+ mov %rdi,%rbx
16072+ i = 0
16073+ .rept USER_PGD_PTRS
16074+ mov i*8(%rbx),%rsi
16075+ mov $0x67,%sil
16076+ lea i*8(%rbx),%rdi
16077+ call PARA_INDIRECT(pv_mmu_ops+PV_MMU_set_pgd_batched)
16078+ i = i + 1
16079+ .endr
16080+ jmp 2f
16081+1:
16082+#endif
16083+
16084+ i = 0
16085+ .rept USER_PGD_PTRS
16086+ movb $0x67,i*8(%rdi)
16087+ i = i + 1
16088+ .endr
16089+
16090+#ifdef CONFIG_PARAVIRT
16091+2: PV_RESTORE_REGS(CLBR_RDI)
16092+ popq %rbx
16093+#endif
16094+
16095+ popq %rdi
16096+ pax_force_retaddr
16097+ retq
16098+ENDPROC(pax_exit_kernel_user)
16099+#endif
16100+
16101+.macro pax_erase_kstack
16102+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
16103+ call pax_erase_kstack
16104+#endif
16105+.endm
16106+
16107+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
16108+ENTRY(pax_erase_kstack)
16109+ pushq %rdi
16110+ pushq %rcx
16111+ pushq %rax
16112+ pushq %r11
16113+
16114+ GET_THREAD_INFO(%r11)
16115+ mov TI_lowest_stack(%r11), %rdi
16116+ mov $-0xBEEF, %rax
16117+ std
16118+
16119+1: mov %edi, %ecx
16120+ and $THREAD_SIZE_asm - 1, %ecx
16121+ shr $3, %ecx
16122+ repne scasq
16123+ jecxz 2f
16124+
16125+ cmp $2*8, %ecx
16126+ jc 2f
16127+
16128+ mov $2*8, %ecx
16129+ repe scasq
16130+ jecxz 2f
16131+ jne 1b
16132+
16133+2: cld
16134+ mov %esp, %ecx
16135+ sub %edi, %ecx
16136+
16137+ cmp $THREAD_SIZE_asm, %rcx
16138+ jb 3f
16139+ ud2
16140+3:
16141+
16142+ shr $3, %ecx
16143+ rep stosq
16144+
16145+ mov TI_task_thread_sp0(%r11), %rdi
16146+ sub $256, %rdi
16147+ mov %rdi, TI_lowest_stack(%r11)
16148+
16149+ popq %r11
16150+ popq %rax
16151+ popq %rcx
16152+ popq %rdi
16153+ pax_force_retaddr
16154+ ret
16155+ENDPROC(pax_erase_kstack)
16156+#endif
16157
16158 .macro TRACE_IRQS_IRETQ offset=ARGOFFSET
16159 #ifdef CONFIG_TRACE_IRQFLAGS
16160@@ -271,8 +546,8 @@ ENDPROC(native_usergs_sysret64)
16161 .endm
16162
16163 .macro UNFAKE_STACK_FRAME
16164- addq $8*6, %rsp
16165- CFI_ADJUST_CFA_OFFSET -(6*8)
16166+ addq $8*6 + ARG_SKIP, %rsp
16167+ CFI_ADJUST_CFA_OFFSET -(6*8 + ARG_SKIP)
16168 .endm
16169
16170 /*
16171@@ -359,7 +634,7 @@ ENDPROC(native_usergs_sysret64)
16172 movq %rsp, %rsi
16173
16174 leaq -RBP(%rsp),%rdi /* arg1 for handler */
16175- testl $3, CS-RBP(%rsi)
16176+ testb $3, CS-RBP(%rsi)
16177 je 1f
16178 SWAPGS
16179 /*
16180@@ -394,9 +669,10 @@ ENTRY(save_rest)
16181 movq_cfi r15, R15+16
16182 movq %r11, 8(%rsp) /* return address */
16183 FIXUP_TOP_OF_STACK %r11, 16
16184+ pax_force_retaddr
16185 ret
16186 CFI_ENDPROC
16187-END(save_rest)
16188+ENDPROC(save_rest)
16189
16190 /* save complete stack frame */
16191 .pushsection .kprobes.text, "ax"
16192@@ -425,9 +701,10 @@ ENTRY(save_paranoid)
16193 js 1f /* negative -> in kernel */
16194 SWAPGS
16195 xorl %ebx,%ebx
16196-1: ret
16197+1: pax_force_retaddr_bts
16198+ ret
16199 CFI_ENDPROC
16200-END(save_paranoid)
16201+ENDPROC(save_paranoid)
16202 .popsection
16203
16204 /*
16205@@ -449,7 +726,7 @@ ENTRY(ret_from_fork)
16206
16207 RESTORE_REST
16208
16209- testl $3, CS-ARGOFFSET(%rsp) # from kernel_thread?
16210+ testb $3, CS-ARGOFFSET(%rsp) # from kernel_thread?
16211 jz retint_restore_args
16212
16213 testl $_TIF_IA32, TI_flags(%rcx) # 32-bit compat task needs IRET
16214@@ -459,7 +736,7 @@ ENTRY(ret_from_fork)
16215 jmp ret_from_sys_call # go to the SYSRET fastpath
16216
16217 CFI_ENDPROC
16218-END(ret_from_fork)
16219+ENDPROC(ret_from_fork)
16220
16221 /*
16222 * System call entry. Up to 6 arguments in registers are supported.
16223@@ -495,7 +772,7 @@ END(ret_from_fork)
16224 ENTRY(system_call)
16225 CFI_STARTPROC simple
16226 CFI_SIGNAL_FRAME
16227- CFI_DEF_CFA rsp,KERNEL_STACK_OFFSET
16228+ CFI_DEF_CFA rsp,0
16229 CFI_REGISTER rip,rcx
16230 /*CFI_REGISTER rflags,r11*/
16231 SWAPGS_UNSAFE_STACK
16232@@ -508,16 +785,23 @@ GLOBAL(system_call_after_swapgs)
16233
16234 movq %rsp,PER_CPU_VAR(old_rsp)
16235 movq PER_CPU_VAR(kernel_stack),%rsp
16236+ SAVE_ARGS 8*6,0
16237+ pax_enter_kernel_user
16238+
16239+#ifdef CONFIG_PAX_RANDKSTACK
16240+ pax_erase_kstack
16241+#endif
16242+
16243 /*
16244 * No need to follow this irqs off/on section - it's straight
16245 * and short:
16246 */
16247 ENABLE_INTERRUPTS(CLBR_NONE)
16248- SAVE_ARGS 8,0
16249 movq %rax,ORIG_RAX-ARGOFFSET(%rsp)
16250 movq %rcx,RIP-ARGOFFSET(%rsp)
16251 CFI_REL_OFFSET rip,RIP-ARGOFFSET
16252- testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
16253+ GET_THREAD_INFO(%rcx)
16254+ testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%rcx)
16255 jnz tracesys
16256 system_call_fastpath:
16257 #if __SYSCALL_MASK == ~0
16258@@ -527,7 +811,7 @@ system_call_fastpath:
16259 cmpl $__NR_syscall_max,%eax
16260 #endif
16261 ja badsys
16262- movq %r10,%rcx
16263+ movq R10-ARGOFFSET(%rsp),%rcx
16264 call *sys_call_table(,%rax,8) # XXX: rip relative
16265 movq %rax,RAX-ARGOFFSET(%rsp)
16266 /*
16267@@ -541,10 +825,13 @@ sysret_check:
16268 LOCKDEP_SYS_EXIT
16269 DISABLE_INTERRUPTS(CLBR_NONE)
16270 TRACE_IRQS_OFF
16271- movl TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET),%edx
16272+ GET_THREAD_INFO(%rcx)
16273+ movl TI_flags(%rcx),%edx
16274 andl %edi,%edx
16275 jnz sysret_careful
16276 CFI_REMEMBER_STATE
16277+ pax_exit_kernel_user
16278+ pax_erase_kstack
16279 /*
16280 * sysretq will re-enable interrupts:
16281 */
16282@@ -596,14 +883,18 @@ badsys:
16283 * jump back to the normal fast path.
16284 */
16285 auditsys:
16286- movq %r10,%r9 /* 6th arg: 4th syscall arg */
16287+ movq R10-ARGOFFSET(%rsp),%r9 /* 6th arg: 4th syscall arg */
16288 movq %rdx,%r8 /* 5th arg: 3rd syscall arg */
16289 movq %rsi,%rcx /* 4th arg: 2nd syscall arg */
16290 movq %rdi,%rdx /* 3rd arg: 1st syscall arg */
16291 movq %rax,%rsi /* 2nd arg: syscall number */
16292 movl $AUDIT_ARCH_X86_64,%edi /* 1st arg: audit arch */
16293 call __audit_syscall_entry
16294+
16295+ pax_erase_kstack
16296+
16297 LOAD_ARGS 0 /* reload call-clobbered registers */
16298+ pax_set_fptr_mask
16299 jmp system_call_fastpath
16300
16301 /*
16302@@ -624,7 +915,7 @@ sysret_audit:
16303 /* Do syscall tracing */
16304 tracesys:
16305 #ifdef CONFIG_AUDITSYSCALL
16306- testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
16307+ testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags(%rcx)
16308 jz auditsys
16309 #endif
16310 SAVE_REST
16311@@ -632,12 +923,16 @@ tracesys:
16312 FIXUP_TOP_OF_STACK %rdi
16313 movq %rsp,%rdi
16314 call syscall_trace_enter
16315+
16316+ pax_erase_kstack
16317+
16318 /*
16319 * Reload arg registers from stack in case ptrace changed them.
16320 * We don't reload %rax because syscall_trace_enter() returned
16321 * the value it wants us to use in the table lookup.
16322 */
16323 LOAD_ARGS ARGOFFSET, 1
16324+ pax_set_fptr_mask
16325 RESTORE_REST
16326 #if __SYSCALL_MASK == ~0
16327 cmpq $__NR_syscall_max,%rax
16328@@ -646,7 +941,7 @@ tracesys:
16329 cmpl $__NR_syscall_max,%eax
16330 #endif
16331 ja int_ret_from_sys_call /* RAX(%rsp) set to -ENOSYS above */
16332- movq %r10,%rcx /* fixup for C */
16333+ movq R10-ARGOFFSET(%rsp),%rcx /* fixup for C */
16334 call *sys_call_table(,%rax,8)
16335 movq %rax,RAX-ARGOFFSET(%rsp)
16336 /* Use IRET because user could have changed frame */
16337@@ -667,7 +962,9 @@ GLOBAL(int_with_check)
16338 andl %edi,%edx
16339 jnz int_careful
16340 andl $~TS_COMPAT,TI_status(%rcx)
16341- jmp retint_swapgs
16342+ pax_exit_kernel_user
16343+ pax_erase_kstack
16344+ jmp retint_swapgs_pax
16345
16346 /* Either reschedule or signal or syscall exit tracking needed. */
16347 /* First do a reschedule test. */
16348@@ -713,7 +1010,7 @@ int_restore_rest:
16349 TRACE_IRQS_OFF
16350 jmp int_with_check
16351 CFI_ENDPROC
16352-END(system_call)
16353+ENDPROC(system_call)
16354
16355 /*
16356 * Certain special system calls that need to save a complete full stack frame.
16357@@ -729,7 +1026,7 @@ ENTRY(\label)
16358 call \func
16359 jmp ptregscall_common
16360 CFI_ENDPROC
16361-END(\label)
16362+ENDPROC(\label)
16363 .endm
16364
16365 PTREGSCALL stub_clone, sys_clone, %r8
16366@@ -747,9 +1044,10 @@ ENTRY(ptregscall_common)
16367 movq_cfi_restore R12+8, r12
16368 movq_cfi_restore RBP+8, rbp
16369 movq_cfi_restore RBX+8, rbx
16370+ pax_force_retaddr
16371 ret $REST_SKIP /* pop extended registers */
16372 CFI_ENDPROC
16373-END(ptregscall_common)
16374+ENDPROC(ptregscall_common)
16375
16376 ENTRY(stub_execve)
16377 CFI_STARTPROC
16378@@ -764,7 +1062,7 @@ ENTRY(stub_execve)
16379 RESTORE_REST
16380 jmp int_ret_from_sys_call
16381 CFI_ENDPROC
16382-END(stub_execve)
16383+ENDPROC(stub_execve)
16384
16385 /*
16386 * sigreturn is special because it needs to restore all registers on return.
16387@@ -782,7 +1080,7 @@ ENTRY(stub_rt_sigreturn)
16388 RESTORE_REST
16389 jmp int_ret_from_sys_call
16390 CFI_ENDPROC
16391-END(stub_rt_sigreturn)
16392+ENDPROC(stub_rt_sigreturn)
16393
16394 #ifdef CONFIG_X86_X32_ABI
16395 PTREGSCALL stub_x32_sigaltstack, sys32_sigaltstack, %rdx
16396@@ -851,7 +1149,7 @@ vector=vector+1
16397 2: jmp common_interrupt
16398 .endr
16399 CFI_ENDPROC
16400-END(irq_entries_start)
16401+ENDPROC(irq_entries_start)
16402
16403 .previous
16404 END(interrupt)
16405@@ -871,6 +1169,16 @@ END(interrupt)
16406 subq $ORIG_RAX-RBP, %rsp
16407 CFI_ADJUST_CFA_OFFSET ORIG_RAX-RBP
16408 SAVE_ARGS_IRQ
16409+#ifdef CONFIG_PAX_MEMORY_UDEREF
16410+ testb $3, CS(%rdi)
16411+ jnz 1f
16412+ pax_enter_kernel
16413+ jmp 2f
16414+1: pax_enter_kernel_user
16415+2:
16416+#else
16417+ pax_enter_kernel
16418+#endif
16419 call \func
16420 .endm
16421
16422@@ -902,7 +1210,7 @@ ret_from_intr:
16423
16424 exit_intr:
16425 GET_THREAD_INFO(%rcx)
16426- testl $3,CS-ARGOFFSET(%rsp)
16427+ testb $3,CS-ARGOFFSET(%rsp)
16428 je retint_kernel
16429
16430 /* Interrupt came from user space */
16431@@ -924,12 +1232,16 @@ retint_swapgs: /* return to user-space */
16432 * The iretq could re-enable interrupts:
16433 */
16434 DISABLE_INTERRUPTS(CLBR_ANY)
16435+ pax_exit_kernel_user
16436+retint_swapgs_pax:
16437 TRACE_IRQS_IRETQ
16438 SWAPGS
16439 jmp restore_args
16440
16441 retint_restore_args: /* return to kernel space */
16442 DISABLE_INTERRUPTS(CLBR_ANY)
16443+ pax_exit_kernel
16444+ pax_force_retaddr RIP-ARGOFFSET
16445 /*
16446 * The iretq could re-enable interrupts:
16447 */
16448@@ -1012,7 +1324,7 @@ ENTRY(retint_kernel)
16449 #endif
16450
16451 CFI_ENDPROC
16452-END(common_interrupt)
16453+ENDPROC(common_interrupt)
16454 /*
16455 * End of kprobes section
16456 */
16457@@ -1029,7 +1341,7 @@ ENTRY(\sym)
16458 interrupt \do_sym
16459 jmp ret_from_intr
16460 CFI_ENDPROC
16461-END(\sym)
16462+ENDPROC(\sym)
16463 .endm
16464
16465 #ifdef CONFIG_SMP
16466@@ -1084,12 +1396,22 @@ ENTRY(\sym)
16467 CFI_ADJUST_CFA_OFFSET ORIG_RAX-R15
16468 call error_entry
16469 DEFAULT_FRAME 0
16470+#ifdef CONFIG_PAX_MEMORY_UDEREF
16471+ testb $3, CS(%rsp)
16472+ jnz 1f
16473+ pax_enter_kernel
16474+ jmp 2f
16475+1: pax_enter_kernel_user
16476+2:
16477+#else
16478+ pax_enter_kernel
16479+#endif
16480 movq %rsp,%rdi /* pt_regs pointer */
16481 xorl %esi,%esi /* no error code */
16482 call \do_sym
16483 jmp error_exit /* %ebx: no swapgs flag */
16484 CFI_ENDPROC
16485-END(\sym)
16486+ENDPROC(\sym)
16487 .endm
16488
16489 .macro paranoidzeroentry sym do_sym
16490@@ -1101,15 +1423,25 @@ ENTRY(\sym)
16491 CFI_ADJUST_CFA_OFFSET ORIG_RAX-R15
16492 call save_paranoid
16493 TRACE_IRQS_OFF
16494+#ifdef CONFIG_PAX_MEMORY_UDEREF
16495+ testb $3, CS(%rsp)
16496+ jnz 1f
16497+ pax_enter_kernel
16498+ jmp 2f
16499+1: pax_enter_kernel_user
16500+2:
16501+#else
16502+ pax_enter_kernel
16503+#endif
16504 movq %rsp,%rdi /* pt_regs pointer */
16505 xorl %esi,%esi /* no error code */
16506 call \do_sym
16507 jmp paranoid_exit /* %ebx: no swapgs flag */
16508 CFI_ENDPROC
16509-END(\sym)
16510+ENDPROC(\sym)
16511 .endm
16512
16513-#define INIT_TSS_IST(x) PER_CPU_VAR(init_tss) + (TSS_ist + ((x) - 1) * 8)
16514+#define INIT_TSS_IST(x) (TSS_ist + ((x) - 1) * 8)(%r12)
16515 .macro paranoidzeroentry_ist sym do_sym ist
16516 ENTRY(\sym)
16517 INTR_FRAME
16518@@ -1119,14 +1451,30 @@ ENTRY(\sym)
16519 CFI_ADJUST_CFA_OFFSET ORIG_RAX-R15
16520 call save_paranoid
16521 TRACE_IRQS_OFF_DEBUG
16522+#ifdef CONFIG_PAX_MEMORY_UDEREF
16523+ testb $3, CS(%rsp)
16524+ jnz 1f
16525+ pax_enter_kernel
16526+ jmp 2f
16527+1: pax_enter_kernel_user
16528+2:
16529+#else
16530+ pax_enter_kernel
16531+#endif
16532 movq %rsp,%rdi /* pt_regs pointer */
16533 xorl %esi,%esi /* no error code */
16534+#ifdef CONFIG_SMP
16535+ imul $TSS_size, PER_CPU_VAR(cpu_number), %r12d
16536+ lea init_tss(%r12), %r12
16537+#else
16538+ lea init_tss(%rip), %r12
16539+#endif
16540 subq $EXCEPTION_STKSZ, INIT_TSS_IST(\ist)
16541 call \do_sym
16542 addq $EXCEPTION_STKSZ, INIT_TSS_IST(\ist)
16543 jmp paranoid_exit /* %ebx: no swapgs flag */
16544 CFI_ENDPROC
16545-END(\sym)
16546+ENDPROC(\sym)
16547 .endm
16548
16549 .macro errorentry sym do_sym
16550@@ -1137,13 +1485,23 @@ ENTRY(\sym)
16551 CFI_ADJUST_CFA_OFFSET ORIG_RAX-R15
16552 call error_entry
16553 DEFAULT_FRAME 0
16554+#ifdef CONFIG_PAX_MEMORY_UDEREF
16555+ testb $3, CS(%rsp)
16556+ jnz 1f
16557+ pax_enter_kernel
16558+ jmp 2f
16559+1: pax_enter_kernel_user
16560+2:
16561+#else
16562+ pax_enter_kernel
16563+#endif
16564 movq %rsp,%rdi /* pt_regs pointer */
16565 movq ORIG_RAX(%rsp),%rsi /* get error code */
16566 movq $-1,ORIG_RAX(%rsp) /* no syscall to restart */
16567 call \do_sym
16568 jmp error_exit /* %ebx: no swapgs flag */
16569 CFI_ENDPROC
16570-END(\sym)
16571+ENDPROC(\sym)
16572 .endm
16573
16574 /* error code is on the stack already */
16575@@ -1156,13 +1514,23 @@ ENTRY(\sym)
16576 call save_paranoid
16577 DEFAULT_FRAME 0
16578 TRACE_IRQS_OFF
16579+#ifdef CONFIG_PAX_MEMORY_UDEREF
16580+ testb $3, CS(%rsp)
16581+ jnz 1f
16582+ pax_enter_kernel
16583+ jmp 2f
16584+1: pax_enter_kernel_user
16585+2:
16586+#else
16587+ pax_enter_kernel
16588+#endif
16589 movq %rsp,%rdi /* pt_regs pointer */
16590 movq ORIG_RAX(%rsp),%rsi /* get error code */
16591 movq $-1,ORIG_RAX(%rsp) /* no syscall to restart */
16592 call \do_sym
16593 jmp paranoid_exit /* %ebx: no swapgs flag */
16594 CFI_ENDPROC
16595-END(\sym)
16596+ENDPROC(\sym)
16597 .endm
16598
16599 zeroentry divide_error do_divide_error
16600@@ -1192,9 +1560,10 @@ gs_change:
16601 2: mfence /* workaround */
16602 SWAPGS
16603 popfq_cfi
16604+ pax_force_retaddr
16605 ret
16606 CFI_ENDPROC
16607-END(native_load_gs_index)
16608+ENDPROC(native_load_gs_index)
16609
16610 _ASM_EXTABLE(gs_change,bad_gs)
16611 .section .fixup,"ax"
16612@@ -1213,13 +1582,14 @@ ENTRY(kernel_thread_helper)
16613 * Here we are in the child and the registers are set as they were
16614 * at kernel_thread() invocation in the parent.
16615 */
16616+ pax_force_fptr %rsi
16617 call *%rsi
16618 # exit
16619 mov %eax, %edi
16620 call do_exit
16621 ud2 # padding for call trace
16622 CFI_ENDPROC
16623-END(kernel_thread_helper)
16624+ENDPROC(kernel_thread_helper)
16625
16626 /*
16627 * execve(). This function needs to use IRET, not SYSRET, to set up all state properly.
16628@@ -1246,11 +1616,11 @@ ENTRY(kernel_execve)
16629 RESTORE_REST
16630 testq %rax,%rax
16631 je int_ret_from_sys_call
16632- RESTORE_ARGS
16633 UNFAKE_STACK_FRAME
16634+ pax_force_retaddr
16635 ret
16636 CFI_ENDPROC
16637-END(kernel_execve)
16638+ENDPROC(kernel_execve)
16639
16640 /* Call softirq on interrupt stack. Interrupts are off. */
16641 ENTRY(call_softirq)
16642@@ -1268,9 +1638,10 @@ ENTRY(call_softirq)
16643 CFI_DEF_CFA_REGISTER rsp
16644 CFI_ADJUST_CFA_OFFSET -8
16645 decl PER_CPU_VAR(irq_count)
16646+ pax_force_retaddr
16647 ret
16648 CFI_ENDPROC
16649-END(call_softirq)
16650+ENDPROC(call_softirq)
16651
16652 #ifdef CONFIG_XEN
16653 zeroentry xen_hypervisor_callback xen_do_hypervisor_callback
16654@@ -1308,7 +1679,7 @@ ENTRY(xen_do_hypervisor_callback) # do_hypervisor_callback(struct *pt_regs)
16655 decl PER_CPU_VAR(irq_count)
16656 jmp error_exit
16657 CFI_ENDPROC
16658-END(xen_do_hypervisor_callback)
16659+ENDPROC(xen_do_hypervisor_callback)
16660
16661 /*
16662 * Hypervisor uses this for application faults while it executes.
16663@@ -1367,7 +1738,7 @@ ENTRY(xen_failsafe_callback)
16664 SAVE_ALL
16665 jmp error_exit
16666 CFI_ENDPROC
16667-END(xen_failsafe_callback)
16668+ENDPROC(xen_failsafe_callback)
16669
16670 apicinterrupt XEN_HVM_EVTCHN_CALLBACK \
16671 xen_hvm_callback_vector xen_evtchn_do_upcall
16672@@ -1416,16 +1787,31 @@ ENTRY(paranoid_exit)
16673 TRACE_IRQS_OFF_DEBUG
16674 testl %ebx,%ebx /* swapgs needed? */
16675 jnz paranoid_restore
16676- testl $3,CS(%rsp)
16677+ testb $3,CS(%rsp)
16678 jnz paranoid_userspace
16679+#ifdef CONFIG_PAX_MEMORY_UDEREF
16680+ pax_exit_kernel
16681+ TRACE_IRQS_IRETQ 0
16682+ SWAPGS_UNSAFE_STACK
16683+ RESTORE_ALL 8
16684+ pax_force_retaddr_bts
16685+ jmp irq_return
16686+#endif
16687 paranoid_swapgs:
16688+#ifdef CONFIG_PAX_MEMORY_UDEREF
16689+ pax_exit_kernel_user
16690+#else
16691+ pax_exit_kernel
16692+#endif
16693 TRACE_IRQS_IRETQ 0
16694 SWAPGS_UNSAFE_STACK
16695 RESTORE_ALL 8
16696 jmp irq_return
16697 paranoid_restore:
16698+ pax_exit_kernel
16699 TRACE_IRQS_IRETQ_DEBUG 0
16700 RESTORE_ALL 8
16701+ pax_force_retaddr_bts
16702 jmp irq_return
16703 paranoid_userspace:
16704 GET_THREAD_INFO(%rcx)
16705@@ -1454,7 +1840,7 @@ paranoid_schedule:
16706 TRACE_IRQS_OFF
16707 jmp paranoid_userspace
16708 CFI_ENDPROC
16709-END(paranoid_exit)
16710+ENDPROC(paranoid_exit)
16711
16712 /*
16713 * Exception entry point. This expects an error code/orig_rax on the stack.
16714@@ -1481,12 +1867,13 @@ ENTRY(error_entry)
16715 movq_cfi r14, R14+8
16716 movq_cfi r15, R15+8
16717 xorl %ebx,%ebx
16718- testl $3,CS+8(%rsp)
16719+ testb $3,CS+8(%rsp)
16720 je error_kernelspace
16721 error_swapgs:
16722 SWAPGS
16723 error_sti:
16724 TRACE_IRQS_OFF
16725+ pax_force_retaddr_bts
16726 ret
16727
16728 /*
16729@@ -1513,7 +1900,7 @@ bstep_iret:
16730 movq %rcx,RIP+8(%rsp)
16731 jmp error_swapgs
16732 CFI_ENDPROC
16733-END(error_entry)
16734+ENDPROC(error_entry)
16735
16736
16737 /* ebx: no swapgs flag (1: don't need swapgs, 0: need it) */
16738@@ -1533,7 +1920,7 @@ ENTRY(error_exit)
16739 jnz retint_careful
16740 jmp retint_swapgs
16741 CFI_ENDPROC
16742-END(error_exit)
16743+ENDPROC(error_exit)
16744
16745 /*
16746 * Test if a given stack is an NMI stack or not.
16747@@ -1591,9 +1978,11 @@ ENTRY(nmi)
16748 * If %cs was not the kernel segment, then the NMI triggered in user
16749 * space, which means it is definitely not nested.
16750 */
16751+ cmpl $__KERNEXEC_KERNEL_CS, 16(%rsp)
16752+ je 1f
16753 cmpl $__KERNEL_CS, 16(%rsp)
16754 jne first_nmi
16755-
16756+1:
16757 /*
16758 * Check the special variable on the stack to see if NMIs are
16759 * executing.
16760@@ -1752,6 +2141,17 @@ end_repeat_nmi:
16761 */
16762 movq %cr2, %r12
16763
16764+#ifdef CONFIG_PAX_MEMORY_UDEREF
16765+ testb $3, CS(%rsp)
16766+ jnz 1f
16767+ pax_enter_kernel
16768+ jmp 2f
16769+1: pax_enter_kernel_user
16770+2:
16771+#else
16772+ pax_enter_kernel
16773+#endif
16774+
16775 /* paranoidentry do_nmi, 0; without TRACE_IRQS_OFF */
16776 movq %rsp,%rdi
16777 movq $-1,%rsi
16778@@ -1767,21 +2167,32 @@ end_repeat_nmi:
16779 testl %ebx,%ebx /* swapgs needed? */
16780 jnz nmi_restore
16781 nmi_swapgs:
16782+#ifdef CONFIG_PAX_MEMORY_UDEREF
16783+ pax_exit_kernel_user
16784+#else
16785+ pax_exit_kernel
16786+#endif
16787 SWAPGS_UNSAFE_STACK
16788+ RESTORE_ALL 8
16789+ /* Clear the NMI executing stack variable */
16790+ movq $0, 10*8(%rsp)
16791+ jmp irq_return
16792 nmi_restore:
16793+ pax_exit_kernel
16794 RESTORE_ALL 8
16795+ pax_force_retaddr_bts
16796 /* Clear the NMI executing stack variable */
16797 movq $0, 10*8(%rsp)
16798 jmp irq_return
16799 CFI_ENDPROC
16800-END(nmi)
16801+ENDPROC(nmi)
16802
16803 ENTRY(ignore_sysret)
16804 CFI_STARTPROC
16805 mov $-ENOSYS,%eax
16806 sysret
16807 CFI_ENDPROC
16808-END(ignore_sysret)
16809+ENDPROC(ignore_sysret)
16810
16811 /*
16812 * End of kprobes section
16813diff --git a/arch/x86/kernel/ftrace.c b/arch/x86/kernel/ftrace.c
16814index c3a7cb4..3ad00dc 100644
16815--- a/arch/x86/kernel/ftrace.c
16816+++ b/arch/x86/kernel/ftrace.c
16817@@ -105,6 +105,8 @@ ftrace_modify_code_direct(unsigned long ip, unsigned const char *old_code,
16818 {
16819 unsigned char replaced[MCOUNT_INSN_SIZE];
16820
16821+ ip = ktla_ktva(ip);
16822+
16823 /*
16824 * Note: Due to modules and __init, code can
16825 * disappear and change, we need to protect against faulting
16826@@ -212,7 +214,7 @@ int ftrace_update_ftrace_func(ftrace_func_t func)
16827 unsigned char old[MCOUNT_INSN_SIZE], *new;
16828 int ret;
16829
16830- memcpy(old, &ftrace_call, MCOUNT_INSN_SIZE);
16831+ memcpy(old, (void *)ktla_ktva((unsigned long)ftrace_call), MCOUNT_INSN_SIZE);
16832 new = ftrace_call_replace(ip, (unsigned long)func);
16833
16834 /* See comment above by declaration of modifying_ftrace_code */
16835@@ -605,6 +607,8 @@ static int ftrace_mod_jmp(unsigned long ip,
16836 {
16837 unsigned char code[MCOUNT_INSN_SIZE];
16838
16839+ ip = ktla_ktva(ip);
16840+
16841 if (probe_kernel_read(code, (void *)ip, MCOUNT_INSN_SIZE))
16842 return -EFAULT;
16843
16844diff --git a/arch/x86/kernel/head32.c b/arch/x86/kernel/head32.c
16845index c18f59d..9c0c9f6 100644
16846--- a/arch/x86/kernel/head32.c
16847+++ b/arch/x86/kernel/head32.c
16848@@ -18,6 +18,7 @@
16849 #include <asm/io_apic.h>
16850 #include <asm/bios_ebda.h>
16851 #include <asm/tlbflush.h>
16852+#include <asm/boot.h>
16853
16854 static void __init i386_default_early_setup(void)
16855 {
16856@@ -30,8 +31,7 @@ static void __init i386_default_early_setup(void)
16857
16858 void __init i386_start_kernel(void)
16859 {
16860- memblock_reserve(__pa_symbol(&_text),
16861- __pa_symbol(&__bss_stop) - __pa_symbol(&_text));
16862+ memblock_reserve(LOAD_PHYSICAL_ADDR, __pa_symbol(&__bss_stop) - LOAD_PHYSICAL_ADDR);
16863
16864 #ifdef CONFIG_BLK_DEV_INITRD
16865 /* Reserve INITRD */
16866diff --git a/arch/x86/kernel/head_32.S b/arch/x86/kernel/head_32.S
16867index d42ab17..87b9555 100644
16868--- a/arch/x86/kernel/head_32.S
16869+++ b/arch/x86/kernel/head_32.S
16870@@ -26,6 +26,12 @@
16871 /* Physical address */
16872 #define pa(X) ((X) - __PAGE_OFFSET)
16873
16874+#ifdef CONFIG_PAX_KERNEXEC
16875+#define ta(X) (X)
16876+#else
16877+#define ta(X) ((X) - __PAGE_OFFSET)
16878+#endif
16879+
16880 /*
16881 * References to members of the new_cpu_data structure.
16882 */
16883@@ -55,11 +61,7 @@
16884 * and small than max_low_pfn, otherwise will waste some page table entries
16885 */
16886
16887-#if PTRS_PER_PMD > 1
16888-#define PAGE_TABLE_SIZE(pages) (((pages) / PTRS_PER_PMD) + PTRS_PER_PGD)
16889-#else
16890-#define PAGE_TABLE_SIZE(pages) ((pages) / PTRS_PER_PGD)
16891-#endif
16892+#define PAGE_TABLE_SIZE(pages) ((pages) / PTRS_PER_PTE)
16893
16894 /* Number of possible pages in the lowmem region */
16895 LOWMEM_PAGES = (((1<<32) - __PAGE_OFFSET) >> PAGE_SHIFT)
16896@@ -78,6 +80,12 @@ INIT_MAP_SIZE = PAGE_TABLE_SIZE(KERNEL_PAGES) * PAGE_SIZE
16897 RESERVE_BRK(pagetables, INIT_MAP_SIZE)
16898
16899 /*
16900+ * Real beginning of normal "text" segment
16901+ */
16902+ENTRY(stext)
16903+ENTRY(_stext)
16904+
16905+/*
16906 * 32-bit kernel entrypoint; only used by the boot CPU. On entry,
16907 * %esi points to the real-mode code as a 32-bit pointer.
16908 * CS and DS must be 4 GB flat segments, but we don't depend on
16909@@ -85,6 +93,13 @@ RESERVE_BRK(pagetables, INIT_MAP_SIZE)
16910 * can.
16911 */
16912 __HEAD
16913+
16914+#ifdef CONFIG_PAX_KERNEXEC
16915+ jmp startup_32
16916+/* PaX: fill first page in .text with int3 to catch NULL derefs in kernel mode */
16917+.fill PAGE_SIZE-5,1,0xcc
16918+#endif
16919+
16920 ENTRY(startup_32)
16921 movl pa(stack_start),%ecx
16922
16923@@ -106,6 +121,59 @@ ENTRY(startup_32)
16924 2:
16925 leal -__PAGE_OFFSET(%ecx),%esp
16926
16927+#ifdef CONFIG_SMP
16928+ movl $pa(cpu_gdt_table),%edi
16929+ movl $__per_cpu_load,%eax
16930+ movw %ax,GDT_ENTRY_PERCPU * 8 + 2(%edi)
16931+ rorl $16,%eax
16932+ movb %al,GDT_ENTRY_PERCPU * 8 + 4(%edi)
16933+ movb %ah,GDT_ENTRY_PERCPU * 8 + 7(%edi)
16934+ movl $__per_cpu_end - 1,%eax
16935+ subl $__per_cpu_start,%eax
16936+ movw %ax,GDT_ENTRY_PERCPU * 8 + 0(%edi)
16937+#endif
16938+
16939+#ifdef CONFIG_PAX_MEMORY_UDEREF
16940+ movl $NR_CPUS,%ecx
16941+ movl $pa(cpu_gdt_table),%edi
16942+1:
16943+ movl $((((__PAGE_OFFSET-1) & 0xf0000000) >> 12) | 0x00c09700),GDT_ENTRY_KERNEL_DS * 8 + 4(%edi)
16944+ movl $((((__PAGE_OFFSET-1) & 0xf0000000) >> 12) | 0x00c0fb00),GDT_ENTRY_DEFAULT_USER_CS * 8 + 4(%edi)
16945+ movl $((((__PAGE_OFFSET-1) & 0xf0000000) >> 12) | 0x00c0f300),GDT_ENTRY_DEFAULT_USER_DS * 8 + 4(%edi)
16946+ addl $PAGE_SIZE_asm,%edi
16947+ loop 1b
16948+#endif
16949+
16950+#ifdef CONFIG_PAX_KERNEXEC
16951+ movl $pa(boot_gdt),%edi
16952+ movl $__LOAD_PHYSICAL_ADDR,%eax
16953+ movw %ax,GDT_ENTRY_BOOT_CS * 8 + 2(%edi)
16954+ rorl $16,%eax
16955+ movb %al,GDT_ENTRY_BOOT_CS * 8 + 4(%edi)
16956+ movb %ah,GDT_ENTRY_BOOT_CS * 8 + 7(%edi)
16957+ rorl $16,%eax
16958+
16959+ ljmp $(__BOOT_CS),$1f
16960+1:
16961+
16962+ movl $NR_CPUS,%ecx
16963+ movl $pa(cpu_gdt_table),%edi
16964+ addl $__PAGE_OFFSET,%eax
16965+1:
16966+ movb $0xc0,GDT_ENTRY_KERNEL_CS * 8 + 6(%edi)
16967+ movb $0xc0,GDT_ENTRY_KERNEXEC_KERNEL_CS * 8 + 6(%edi)
16968+ movw %ax,GDT_ENTRY_KERNEL_CS * 8 + 2(%edi)
16969+ movw %ax,GDT_ENTRY_KERNEXEC_KERNEL_CS * 8 + 2(%edi)
16970+ rorl $16,%eax
16971+ movb %al,GDT_ENTRY_KERNEL_CS * 8 + 4(%edi)
16972+ movb %al,GDT_ENTRY_KERNEXEC_KERNEL_CS * 8 + 4(%edi)
16973+ movb %ah,GDT_ENTRY_KERNEL_CS * 8 + 7(%edi)
16974+ movb %ah,GDT_ENTRY_KERNEXEC_KERNEL_CS * 8 + 7(%edi)
16975+ rorl $16,%eax
16976+ addl $PAGE_SIZE_asm,%edi
16977+ loop 1b
16978+#endif
16979+
16980 /*
16981 * Clear BSS first so that there are no surprises...
16982 */
16983@@ -196,8 +264,11 @@ ENTRY(startup_32)
16984 movl %eax, pa(max_pfn_mapped)
16985
16986 /* Do early initialization of the fixmap area */
16987- movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,%eax
16988- movl %eax,pa(initial_pg_pmd+0x1000*KPMDS-8)
16989+#ifdef CONFIG_COMPAT_VDSO
16990+ movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR+_PAGE_USER,pa(initial_pg_pmd+0x1000*KPMDS-8)
16991+#else
16992+ movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,pa(initial_pg_pmd+0x1000*KPMDS-8)
16993+#endif
16994 #else /* Not PAE */
16995
16996 page_pde_offset = (__PAGE_OFFSET >> 20);
16997@@ -227,8 +298,11 @@ page_pde_offset = (__PAGE_OFFSET >> 20);
16998 movl %eax, pa(max_pfn_mapped)
16999
17000 /* Do early initialization of the fixmap area */
17001- movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,%eax
17002- movl %eax,pa(initial_page_table+0xffc)
17003+#ifdef CONFIG_COMPAT_VDSO
17004+ movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR+_PAGE_USER,pa(initial_page_table+0xffc)
17005+#else
17006+ movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,pa(initial_page_table+0xffc)
17007+#endif
17008 #endif
17009
17010 #ifdef CONFIG_PARAVIRT
17011@@ -242,9 +316,7 @@ page_pde_offset = (__PAGE_OFFSET >> 20);
17012 cmpl $num_subarch_entries, %eax
17013 jae bad_subarch
17014
17015- movl pa(subarch_entries)(,%eax,4), %eax
17016- subl $__PAGE_OFFSET, %eax
17017- jmp *%eax
17018+ jmp *pa(subarch_entries)(,%eax,4)
17019
17020 bad_subarch:
17021 WEAK(lguest_entry)
17022@@ -256,10 +328,10 @@ WEAK(xen_entry)
17023 __INITDATA
17024
17025 subarch_entries:
17026- .long default_entry /* normal x86/PC */
17027- .long lguest_entry /* lguest hypervisor */
17028- .long xen_entry /* Xen hypervisor */
17029- .long default_entry /* Moorestown MID */
17030+ .long ta(default_entry) /* normal x86/PC */
17031+ .long ta(lguest_entry) /* lguest hypervisor */
17032+ .long ta(xen_entry) /* Xen hypervisor */
17033+ .long ta(default_entry) /* Moorestown MID */
17034 num_subarch_entries = (. - subarch_entries) / 4
17035 .previous
17036 #else
17037@@ -310,6 +382,7 @@ default_entry:
17038 orl %edx,%eax
17039 movl %eax,%cr4
17040
17041+#ifdef CONFIG_X86_PAE
17042 testb $X86_CR4_PAE, %al # check if PAE is enabled
17043 jz 6f
17044
17045@@ -338,6 +411,9 @@ default_entry:
17046 /* Make changes effective */
17047 wrmsr
17048
17049+ btsl $_PAGE_BIT_NX-32,pa(__supported_pte_mask+4)
17050+#endif
17051+
17052 6:
17053
17054 /*
17055@@ -436,14 +512,20 @@ is386: movl $2,%ecx # set MP
17056 1: movl $(__KERNEL_DS),%eax # reload all the segment registers
17057 movl %eax,%ss # after changing gdt.
17058
17059- movl $(__USER_DS),%eax # DS/ES contains default USER segment
17060+# movl $(__KERNEL_DS),%eax # DS/ES contains default KERNEL segment
17061 movl %eax,%ds
17062 movl %eax,%es
17063
17064 movl $(__KERNEL_PERCPU), %eax
17065 movl %eax,%fs # set this cpu's percpu
17066
17067+#ifdef CONFIG_CC_STACKPROTECTOR
17068 movl $(__KERNEL_STACK_CANARY),%eax
17069+#elif defined(CONFIG_PAX_MEMORY_UDEREF)
17070+ movl $(__USER_DS),%eax
17071+#else
17072+ xorl %eax,%eax
17073+#endif
17074 movl %eax,%gs
17075
17076 xorl %eax,%eax # Clear LDT
17077@@ -520,8 +602,11 @@ setup_once:
17078 * relocation. Manually set base address in stack canary
17079 * segment descriptor.
17080 */
17081- movl $gdt_page,%eax
17082+ movl $cpu_gdt_table,%eax
17083 movl $stack_canary,%ecx
17084+#ifdef CONFIG_SMP
17085+ addl $__per_cpu_load,%ecx
17086+#endif
17087 movw %cx, 8 * GDT_ENTRY_STACK_CANARY + 2(%eax)
17088 shrl $16, %ecx
17089 movb %cl, 8 * GDT_ENTRY_STACK_CANARY + 4(%eax)
17090@@ -552,7 +637,7 @@ ENDPROC(early_idt_handlers)
17091 /* This is global to keep gas from relaxing the jumps */
17092 ENTRY(early_idt_handler)
17093 cld
17094- cmpl $2,%ss:early_recursion_flag
17095+ cmpl $1,%ss:early_recursion_flag
17096 je hlt_loop
17097 incl %ss:early_recursion_flag
17098
17099@@ -590,8 +675,8 @@ ENTRY(early_idt_handler)
17100 pushl (20+6*4)(%esp) /* trapno */
17101 pushl $fault_msg
17102 call printk
17103-#endif
17104 call dump_stack
17105+#endif
17106 hlt_loop:
17107 hlt
17108 jmp hlt_loop
17109@@ -610,8 +695,11 @@ ENDPROC(early_idt_handler)
17110 /* This is the default interrupt "handler" :-) */
17111 ALIGN
17112 ignore_int:
17113- cld
17114 #ifdef CONFIG_PRINTK
17115+ cmpl $2,%ss:early_recursion_flag
17116+ je hlt_loop
17117+ incl %ss:early_recursion_flag
17118+ cld
17119 pushl %eax
17120 pushl %ecx
17121 pushl %edx
17122@@ -620,9 +708,6 @@ ignore_int:
17123 movl $(__KERNEL_DS),%eax
17124 movl %eax,%ds
17125 movl %eax,%es
17126- cmpl $2,early_recursion_flag
17127- je hlt_loop
17128- incl early_recursion_flag
17129 pushl 16(%esp)
17130 pushl 24(%esp)
17131 pushl 32(%esp)
17132@@ -656,29 +741,43 @@ ENTRY(setup_once_ref)
17133 /*
17134 * BSS section
17135 */
17136-__PAGE_ALIGNED_BSS
17137- .align PAGE_SIZE
17138 #ifdef CONFIG_X86_PAE
17139+.section .initial_pg_pmd,"a",@progbits
17140 initial_pg_pmd:
17141 .fill 1024*KPMDS,4,0
17142 #else
17143+.section .initial_page_table,"a",@progbits
17144 ENTRY(initial_page_table)
17145 .fill 1024,4,0
17146 #endif
17147+.section .initial_pg_fixmap,"a",@progbits
17148 initial_pg_fixmap:
17149 .fill 1024,4,0
17150+.section .empty_zero_page,"a",@progbits
17151 ENTRY(empty_zero_page)
17152 .fill 4096,1,0
17153+.section .swapper_pg_dir,"a",@progbits
17154 ENTRY(swapper_pg_dir)
17155+#ifdef CONFIG_X86_PAE
17156+ .fill 4,8,0
17157+#else
17158 .fill 1024,4,0
17159+#endif
17160+
17161+/*
17162+ * The IDT has to be page-aligned to simplify the Pentium
17163+ * F0 0F bug workaround.. We have a special link segment
17164+ * for this.
17165+ */
17166+.section .idt,"a",@progbits
17167+ENTRY(idt_table)
17168+ .fill 256,8,0
17169
17170 /*
17171 * This starts the data section.
17172 */
17173 #ifdef CONFIG_X86_PAE
17174-__PAGE_ALIGNED_DATA
17175- /* Page-aligned for the benefit of paravirt? */
17176- .align PAGE_SIZE
17177+.section .initial_page_table,"a",@progbits
17178 ENTRY(initial_page_table)
17179 .long pa(initial_pg_pmd+PGD_IDENT_ATTR),0 /* low identity map */
17180 # if KPMDS == 3
17181@@ -697,12 +796,20 @@ ENTRY(initial_page_table)
17182 # error "Kernel PMDs should be 1, 2 or 3"
17183 # endif
17184 .align PAGE_SIZE /* needs to be page-sized too */
17185+
17186+#ifdef CONFIG_PAX_PER_CPU_PGD
17187+ENTRY(cpu_pgd)
17188+ .rept NR_CPUS
17189+ .fill 4,8,0
17190+ .endr
17191+#endif
17192+
17193 #endif
17194
17195 .data
17196 .balign 4
17197 ENTRY(stack_start)
17198- .long init_thread_union+THREAD_SIZE
17199+ .long init_thread_union+THREAD_SIZE-8
17200
17201 __INITRODATA
17202 int_msg:
17203@@ -730,7 +837,7 @@ fault_msg:
17204 * segment size, and 32-bit linear address value:
17205 */
17206
17207- .data
17208+.section .rodata,"a",@progbits
17209 .globl boot_gdt_descr
17210 .globl idt_descr
17211
17212@@ -739,7 +846,7 @@ fault_msg:
17213 .word 0 # 32 bit align gdt_desc.address
17214 boot_gdt_descr:
17215 .word __BOOT_DS+7
17216- .long boot_gdt - __PAGE_OFFSET
17217+ .long pa(boot_gdt)
17218
17219 .word 0 # 32-bit align idt_desc.address
17220 idt_descr:
17221@@ -750,7 +857,7 @@ idt_descr:
17222 .word 0 # 32 bit align gdt_desc.address
17223 ENTRY(early_gdt_descr)
17224 .word GDT_ENTRIES*8-1
17225- .long gdt_page /* Overwritten for secondary CPUs */
17226+ .long cpu_gdt_table /* Overwritten for secondary CPUs */
17227
17228 /*
17229 * The boot_gdt must mirror the equivalent in setup.S and is
17230@@ -759,5 +866,65 @@ ENTRY(early_gdt_descr)
17231 .align L1_CACHE_BYTES
17232 ENTRY(boot_gdt)
17233 .fill GDT_ENTRY_BOOT_CS,8,0
17234- .quad 0x00cf9a000000ffff /* kernel 4GB code at 0x00000000 */
17235- .quad 0x00cf92000000ffff /* kernel 4GB data at 0x00000000 */
17236+ .quad 0x00cf9b000000ffff /* kernel 4GB code at 0x00000000 */
17237+ .quad 0x00cf93000000ffff /* kernel 4GB data at 0x00000000 */
17238+
17239+ .align PAGE_SIZE_asm
17240+ENTRY(cpu_gdt_table)
17241+ .rept NR_CPUS
17242+ .quad 0x0000000000000000 /* NULL descriptor */
17243+ .quad 0x0000000000000000 /* 0x0b reserved */
17244+ .quad 0x0000000000000000 /* 0x13 reserved */
17245+ .quad 0x0000000000000000 /* 0x1b reserved */
17246+
17247+#ifdef CONFIG_PAX_KERNEXEC
17248+ .quad 0x00cf9b000000ffff /* 0x20 alternate kernel 4GB code at 0x00000000 */
17249+#else
17250+ .quad 0x0000000000000000 /* 0x20 unused */
17251+#endif
17252+
17253+ .quad 0x0000000000000000 /* 0x28 unused */
17254+ .quad 0x0000000000000000 /* 0x33 TLS entry 1 */
17255+ .quad 0x0000000000000000 /* 0x3b TLS entry 2 */
17256+ .quad 0x0000000000000000 /* 0x43 TLS entry 3 */
17257+ .quad 0x0000000000000000 /* 0x4b reserved */
17258+ .quad 0x0000000000000000 /* 0x53 reserved */
17259+ .quad 0x0000000000000000 /* 0x5b reserved */
17260+
17261+ .quad 0x00cf9b000000ffff /* 0x60 kernel 4GB code at 0x00000000 */
17262+ .quad 0x00cf93000000ffff /* 0x68 kernel 4GB data at 0x00000000 */
17263+ .quad 0x00cffb000000ffff /* 0x73 user 4GB code at 0x00000000 */
17264+ .quad 0x00cff3000000ffff /* 0x7b user 4GB data at 0x00000000 */
17265+
17266+ .quad 0x0000000000000000 /* 0x80 TSS descriptor */
17267+ .quad 0x0000000000000000 /* 0x88 LDT descriptor */
17268+
17269+ /*
17270+ * Segments used for calling PnP BIOS have byte granularity.
17271+ * The code segments and data segments have fixed 64k limits,
17272+ * the transfer segment sizes are set at run time.
17273+ */
17274+ .quad 0x00409b000000ffff /* 0x90 32-bit code */
17275+ .quad 0x00009b000000ffff /* 0x98 16-bit code */
17276+ .quad 0x000093000000ffff /* 0xa0 16-bit data */
17277+ .quad 0x0000930000000000 /* 0xa8 16-bit data */
17278+ .quad 0x0000930000000000 /* 0xb0 16-bit data */
17279+
17280+ /*
17281+ * The APM segments have byte granularity and their bases
17282+ * are set at run time. All have 64k limits.
17283+ */
17284+ .quad 0x00409b000000ffff /* 0xb8 APM CS code */
17285+ .quad 0x00009b000000ffff /* 0xc0 APM CS 16 code (16 bit) */
17286+ .quad 0x004093000000ffff /* 0xc8 APM DS data */
17287+
17288+ .quad 0x00c0930000000000 /* 0xd0 - ESPFIX SS */
17289+ .quad 0x0040930000000000 /* 0xd8 - PERCPU */
17290+ .quad 0x0040910000000017 /* 0xe0 - STACK_CANARY */
17291+ .quad 0x0000000000000000 /* 0xe8 - PCIBIOS_CS */
17292+ .quad 0x0000000000000000 /* 0xf0 - PCIBIOS_DS */
17293+ .quad 0x0000000000000000 /* 0xf8 - GDT entry 31: double-fault TSS */
17294+
17295+ /* Be sure this is zeroed to avoid false validations in Xen */
17296+ .fill PAGE_SIZE_asm - GDT_SIZE,1,0
17297+ .endr
17298diff --git a/arch/x86/kernel/head_64.S b/arch/x86/kernel/head_64.S
17299index 94bf9cc..400455a 100644
17300--- a/arch/x86/kernel/head_64.S
17301+++ b/arch/x86/kernel/head_64.S
17302@@ -20,6 +20,8 @@
17303 #include <asm/processor-flags.h>
17304 #include <asm/percpu.h>
17305 #include <asm/nops.h>
17306+#include <asm/cpufeature.h>
17307+#include <asm/alternative-asm.h>
17308
17309 #ifdef CONFIG_PARAVIRT
17310 #include <asm/asm-offsets.h>
17311@@ -41,6 +43,12 @@ L4_PAGE_OFFSET = pgd_index(__PAGE_OFFSET)
17312 L3_PAGE_OFFSET = pud_index(__PAGE_OFFSET)
17313 L4_START_KERNEL = pgd_index(__START_KERNEL_map)
17314 L3_START_KERNEL = pud_index(__START_KERNEL_map)
17315+L4_VMALLOC_START = pgd_index(VMALLOC_START)
17316+L3_VMALLOC_START = pud_index(VMALLOC_START)
17317+L4_VMALLOC_END = pgd_index(VMALLOC_END)
17318+L3_VMALLOC_END = pud_index(VMALLOC_END)
17319+L4_VMEMMAP_START = pgd_index(VMEMMAP_START)
17320+L3_VMEMMAP_START = pud_index(VMEMMAP_START)
17321
17322 .text
17323 __HEAD
17324@@ -88,35 +96,23 @@ startup_64:
17325 */
17326 addq %rbp, init_level4_pgt + 0(%rip)
17327 addq %rbp, init_level4_pgt + (L4_PAGE_OFFSET*8)(%rip)
17328+ addq %rbp, init_level4_pgt + (L4_VMALLOC_START*8)(%rip)
17329+ addq %rbp, init_level4_pgt + (L4_VMALLOC_END*8)(%rip)
17330+ addq %rbp, init_level4_pgt + (L4_VMEMMAP_START*8)(%rip)
17331 addq %rbp, init_level4_pgt + (L4_START_KERNEL*8)(%rip)
17332
17333 addq %rbp, level3_ident_pgt + 0(%rip)
17334+#ifndef CONFIG_XEN
17335+ addq %rbp, level3_ident_pgt + 8(%rip)
17336+#endif
17337
17338- addq %rbp, level3_kernel_pgt + (510*8)(%rip)
17339- addq %rbp, level3_kernel_pgt + (511*8)(%rip)
17340+ addq %rbp, level3_vmemmap_pgt + (L3_VMEMMAP_START*8)(%rip)
17341+
17342+ addq %rbp, level3_kernel_pgt + (L3_START_KERNEL*8)(%rip)
17343+ addq %rbp, level3_kernel_pgt + (L3_START_KERNEL*8+8)(%rip)
17344
17345 addq %rbp, level2_fixmap_pgt + (506*8)(%rip)
17346-
17347- /* Add an Identity mapping if I am above 1G */
17348- leaq _text(%rip), %rdi
17349- andq $PMD_PAGE_MASK, %rdi
17350-
17351- movq %rdi, %rax
17352- shrq $PUD_SHIFT, %rax
17353- andq $(PTRS_PER_PUD - 1), %rax
17354- jz ident_complete
17355-
17356- leaq (level2_spare_pgt - __START_KERNEL_map + _KERNPG_TABLE)(%rbp), %rdx
17357- leaq level3_ident_pgt(%rip), %rbx
17358- movq %rdx, 0(%rbx, %rax, 8)
17359-
17360- movq %rdi, %rax
17361- shrq $PMD_SHIFT, %rax
17362- andq $(PTRS_PER_PMD - 1), %rax
17363- leaq __PAGE_KERNEL_IDENT_LARGE_EXEC(%rdi), %rdx
17364- leaq level2_spare_pgt(%rip), %rbx
17365- movq %rdx, 0(%rbx, %rax, 8)
17366-ident_complete:
17367+ addq %rbp, level2_fixmap_pgt + (507*8)(%rip)
17368
17369 /*
17370 * Fixup the kernel text+data virtual addresses. Note that
17371@@ -159,8 +155,8 @@ ENTRY(secondary_startup_64)
17372 * after the boot processor executes this code.
17373 */
17374
17375- /* Enable PAE mode and PGE */
17376- movl $(X86_CR4_PAE | X86_CR4_PGE), %eax
17377+ /* Enable PAE mode and PSE/PGE */
17378+ movl $(X86_CR4_PSE | X86_CR4_PAE | X86_CR4_PGE), %eax
17379 movq %rax, %cr4
17380
17381 /* Setup early boot stage 4 level pagetables. */
17382@@ -182,9 +178,17 @@ ENTRY(secondary_startup_64)
17383 movl $MSR_EFER, %ecx
17384 rdmsr
17385 btsl $_EFER_SCE, %eax /* Enable System Call */
17386- btl $20,%edi /* No Execute supported? */
17387+ btl $(X86_FEATURE_NX & 31),%edi /* No Execute supported? */
17388 jnc 1f
17389 btsl $_EFER_NX, %eax
17390+ leaq init_level4_pgt(%rip), %rdi
17391+#ifndef CONFIG_EFI
17392+ btsq $_PAGE_BIT_NX, 8*L4_PAGE_OFFSET(%rdi)
17393+#endif
17394+ btsq $_PAGE_BIT_NX, 8*L4_VMALLOC_START(%rdi)
17395+ btsq $_PAGE_BIT_NX, 8*L4_VMALLOC_END(%rdi)
17396+ btsq $_PAGE_BIT_NX, 8*L4_VMEMMAP_START(%rdi)
17397+ btsq $_PAGE_BIT_NX, __supported_pte_mask(%rip)
17398 1: wrmsr /* Make changes effective */
17399
17400 /* Setup cr0 */
17401@@ -246,6 +250,7 @@ ENTRY(secondary_startup_64)
17402 * jump. In addition we need to ensure %cs is set so we make this
17403 * a far return.
17404 */
17405+ pax_set_fptr_mask
17406 movq initial_code(%rip),%rax
17407 pushq $0 # fake return address to stop unwinder
17408 pushq $__KERNEL_CS # set correct cs
17409@@ -268,7 +273,7 @@ ENTRY(secondary_startup_64)
17410 bad_address:
17411 jmp bad_address
17412
17413- .section ".init.text","ax"
17414+ __INIT
17415 .globl early_idt_handlers
17416 early_idt_handlers:
17417 # 104(%rsp) %rflags
17418@@ -347,11 +352,15 @@ ENTRY(early_idt_handler)
17419 addq $16,%rsp # drop vector number and error code
17420 decl early_recursion_flag(%rip)
17421 INTERRUPT_RETURN
17422+ .previous
17423
17424+ __INITDATA
17425 .balign 4
17426 early_recursion_flag:
17427 .long 0
17428+ .previous
17429
17430+ .section .rodata,"a",@progbits
17431 #ifdef CONFIG_EARLY_PRINTK
17432 early_idt_msg:
17433 .asciz "PANIC: early exception %02lx rip %lx:%lx error %lx cr2 %lx\n"
17434@@ -360,6 +369,7 @@ early_idt_ripmsg:
17435 #endif /* CONFIG_EARLY_PRINTK */
17436 .previous
17437
17438+ .section .rodata,"a",@progbits
17439 #define NEXT_PAGE(name) \
17440 .balign PAGE_SIZE; \
17441 ENTRY(name)
17442@@ -372,7 +382,6 @@ ENTRY(name)
17443 i = i + 1 ; \
17444 .endr
17445
17446- .data
17447 /*
17448 * This default setting generates an ident mapping at address 0x100000
17449 * and a mapping for the kernel that precisely maps virtual address
17450@@ -383,13 +392,41 @@ NEXT_PAGE(init_level4_pgt)
17451 .quad level3_ident_pgt - __START_KERNEL_map + _KERNPG_TABLE
17452 .org init_level4_pgt + L4_PAGE_OFFSET*8, 0
17453 .quad level3_ident_pgt - __START_KERNEL_map + _KERNPG_TABLE
17454+ .org init_level4_pgt + L4_VMALLOC_START*8, 0
17455+ .quad level3_vmalloc_start_pgt - __START_KERNEL_map + _KERNPG_TABLE
17456+ .org init_level4_pgt + L4_VMALLOC_END*8, 0
17457+ .quad level3_vmalloc_end_pgt - __START_KERNEL_map + _KERNPG_TABLE
17458+ .org init_level4_pgt + L4_VMEMMAP_START*8, 0
17459+ .quad level3_vmemmap_pgt - __START_KERNEL_map + _KERNPG_TABLE
17460 .org init_level4_pgt + L4_START_KERNEL*8, 0
17461 /* (2^48-(2*1024*1024*1024))/(2^39) = 511 */
17462 .quad level3_kernel_pgt - __START_KERNEL_map + _PAGE_TABLE
17463
17464+#ifdef CONFIG_PAX_PER_CPU_PGD
17465+NEXT_PAGE(cpu_pgd)
17466+ .rept NR_CPUS
17467+ .fill 512,8,0
17468+ .endr
17469+#endif
17470+
17471 NEXT_PAGE(level3_ident_pgt)
17472 .quad level2_ident_pgt - __START_KERNEL_map + _KERNPG_TABLE
17473+#ifdef CONFIG_XEN
17474 .fill 511,8,0
17475+#else
17476+ .quad level2_ident_pgt + PAGE_SIZE - __START_KERNEL_map + _KERNPG_TABLE
17477+ .fill 510,8,0
17478+#endif
17479+
17480+NEXT_PAGE(level3_vmalloc_start_pgt)
17481+ .fill 512,8,0
17482+
17483+NEXT_PAGE(level3_vmalloc_end_pgt)
17484+ .fill 512,8,0
17485+
17486+NEXT_PAGE(level3_vmemmap_pgt)
17487+ .fill L3_VMEMMAP_START,8,0
17488+ .quad level2_vmemmap_pgt - __START_KERNEL_map + _KERNPG_TABLE
17489
17490 NEXT_PAGE(level3_kernel_pgt)
17491 .fill L3_START_KERNEL,8,0
17492@@ -397,20 +434,23 @@ NEXT_PAGE(level3_kernel_pgt)
17493 .quad level2_kernel_pgt - __START_KERNEL_map + _KERNPG_TABLE
17494 .quad level2_fixmap_pgt - __START_KERNEL_map + _PAGE_TABLE
17495
17496+NEXT_PAGE(level2_vmemmap_pgt)
17497+ .fill 512,8,0
17498+
17499 NEXT_PAGE(level2_fixmap_pgt)
17500- .fill 506,8,0
17501- .quad level1_fixmap_pgt - __START_KERNEL_map + _PAGE_TABLE
17502- /* 8MB reserved for vsyscalls + a 2MB hole = 4 + 1 entries */
17503- .fill 5,8,0
17504+ .fill 507,8,0
17505+ .quad level1_vsyscall_pgt - __START_KERNEL_map + _PAGE_TABLE
17506+ /* 6MB reserved for vsyscalls + a 2MB hole = 3 + 1 entries */
17507+ .fill 4,8,0
17508
17509-NEXT_PAGE(level1_fixmap_pgt)
17510+NEXT_PAGE(level1_vsyscall_pgt)
17511 .fill 512,8,0
17512
17513-NEXT_PAGE(level2_ident_pgt)
17514- /* Since I easily can, map the first 1G.
17515+ /* Since I easily can, map the first 2G.
17516 * Don't set NX because code runs from these pages.
17517 */
17518- PMDS(0, __PAGE_KERNEL_IDENT_LARGE_EXEC, PTRS_PER_PMD)
17519+NEXT_PAGE(level2_ident_pgt)
17520+ PMDS(0, __PAGE_KERNEL_IDENT_LARGE_EXEC, 2*PTRS_PER_PMD)
17521
17522 NEXT_PAGE(level2_kernel_pgt)
17523 /*
17524@@ -423,37 +463,59 @@ NEXT_PAGE(level2_kernel_pgt)
17525 * If you want to increase this then increase MODULES_VADDR
17526 * too.)
17527 */
17528- PMDS(0, __PAGE_KERNEL_LARGE_EXEC,
17529- KERNEL_IMAGE_SIZE/PMD_SIZE)
17530-
17531-NEXT_PAGE(level2_spare_pgt)
17532- .fill 512, 8, 0
17533+ PMDS(0, __PAGE_KERNEL_LARGE_EXEC, KERNEL_IMAGE_SIZE/PMD_SIZE)
17534
17535 #undef PMDS
17536 #undef NEXT_PAGE
17537
17538- .data
17539+ .align PAGE_SIZE
17540+ENTRY(cpu_gdt_table)
17541+ .rept NR_CPUS
17542+ .quad 0x0000000000000000 /* NULL descriptor */
17543+ .quad 0x00cf9b000000ffff /* __KERNEL32_CS */
17544+ .quad 0x00af9b000000ffff /* __KERNEL_CS */
17545+ .quad 0x00cf93000000ffff /* __KERNEL_DS */
17546+ .quad 0x00cffb000000ffff /* __USER32_CS */
17547+ .quad 0x00cff3000000ffff /* __USER_DS, __USER32_DS */
17548+ .quad 0x00affb000000ffff /* __USER_CS */
17549+
17550+#ifdef CONFIG_PAX_KERNEXEC
17551+ .quad 0x00af9b000000ffff /* __KERNEXEC_KERNEL_CS */
17552+#else
17553+ .quad 0x0 /* unused */
17554+#endif
17555+
17556+ .quad 0,0 /* TSS */
17557+ .quad 0,0 /* LDT */
17558+ .quad 0,0,0 /* three TLS descriptors */
17559+ .quad 0x0000f40000000000 /* node/CPU stored in limit */
17560+ /* asm/segment.h:GDT_ENTRIES must match this */
17561+
17562+ /* zero the remaining page */
17563+ .fill PAGE_SIZE / 8 - GDT_ENTRIES,8,0
17564+ .endr
17565+
17566 .align 16
17567 .globl early_gdt_descr
17568 early_gdt_descr:
17569 .word GDT_ENTRIES*8-1
17570 early_gdt_descr_base:
17571- .quad INIT_PER_CPU_VAR(gdt_page)
17572+ .quad cpu_gdt_table
17573
17574 ENTRY(phys_base)
17575 /* This must match the first entry in level2_kernel_pgt */
17576 .quad 0x0000000000000000
17577
17578 #include "../../x86/xen/xen-head.S"
17579-
17580- .section .bss, "aw", @nobits
17581+
17582+ .section .rodata,"a",@progbits
17583 .align L1_CACHE_BYTES
17584 ENTRY(idt_table)
17585- .skip IDT_ENTRIES * 16
17586+ .fill 512,8,0
17587
17588 .align L1_CACHE_BYTES
17589 ENTRY(nmi_idt_table)
17590- .skip IDT_ENTRIES * 16
17591+ .fill 512,8,0
17592
17593 __PAGE_ALIGNED_BSS
17594 .align PAGE_SIZE
17595diff --git a/arch/x86/kernel/i386_ksyms_32.c b/arch/x86/kernel/i386_ksyms_32.c
17596index 9c3bd4a..e1d9b35 100644
17597--- a/arch/x86/kernel/i386_ksyms_32.c
17598+++ b/arch/x86/kernel/i386_ksyms_32.c
17599@@ -20,8 +20,12 @@ extern void cmpxchg8b_emu(void);
17600 EXPORT_SYMBOL(cmpxchg8b_emu);
17601 #endif
17602
17603+EXPORT_SYMBOL_GPL(cpu_gdt_table);
17604+
17605 /* Networking helper routines. */
17606 EXPORT_SYMBOL(csum_partial_copy_generic);
17607+EXPORT_SYMBOL(csum_partial_copy_generic_to_user);
17608+EXPORT_SYMBOL(csum_partial_copy_generic_from_user);
17609
17610 EXPORT_SYMBOL(__get_user_1);
17611 EXPORT_SYMBOL(__get_user_2);
17612@@ -36,3 +40,7 @@ EXPORT_SYMBOL(strstr);
17613
17614 EXPORT_SYMBOL(csum_partial);
17615 EXPORT_SYMBOL(empty_zero_page);
17616+
17617+#ifdef CONFIG_PAX_KERNEXEC
17618+EXPORT_SYMBOL(__LOAD_PHYSICAL_ADDR);
17619+#endif
17620diff --git a/arch/x86/kernel/i387.c b/arch/x86/kernel/i387.c
17621index f250431..54097e7 100644
17622--- a/arch/x86/kernel/i387.c
17623+++ b/arch/x86/kernel/i387.c
17624@@ -59,7 +59,7 @@ static inline bool interrupted_kernel_fpu_idle(void)
17625 static inline bool interrupted_user_mode(void)
17626 {
17627 struct pt_regs *regs = get_irq_regs();
17628- return regs && user_mode_vm(regs);
17629+ return regs && user_mode(regs);
17630 }
17631
17632 /*
17633diff --git a/arch/x86/kernel/i8259.c b/arch/x86/kernel/i8259.c
17634index 36d1853..bf25736 100644
17635--- a/arch/x86/kernel/i8259.c
17636+++ b/arch/x86/kernel/i8259.c
17637@@ -209,7 +209,7 @@ spurious_8259A_irq:
17638 "spurious 8259A interrupt: IRQ%d.\n", irq);
17639 spurious_irq_mask |= irqmask;
17640 }
17641- atomic_inc(&irq_err_count);
17642+ atomic_inc_unchecked(&irq_err_count);
17643 /*
17644 * Theoretically we do not have to handle this IRQ,
17645 * but in Linux this does not cause problems and is
17646diff --git a/arch/x86/kernel/ioport.c b/arch/x86/kernel/ioport.c
17647index 8c96897..be66bfa 100644
17648--- a/arch/x86/kernel/ioport.c
17649+++ b/arch/x86/kernel/ioport.c
17650@@ -6,6 +6,7 @@
17651 #include <linux/sched.h>
17652 #include <linux/kernel.h>
17653 #include <linux/capability.h>
17654+#include <linux/security.h>
17655 #include <linux/errno.h>
17656 #include <linux/types.h>
17657 #include <linux/ioport.h>
17658@@ -28,6 +29,12 @@ asmlinkage long sys_ioperm(unsigned long from, unsigned long num, int turn_on)
17659
17660 if ((from + num <= from) || (from + num > IO_BITMAP_BITS))
17661 return -EINVAL;
17662+#ifdef CONFIG_GRKERNSEC_IO
17663+ if (turn_on && grsec_disable_privio) {
17664+ gr_handle_ioperm();
17665+ return -EPERM;
17666+ }
17667+#endif
17668 if (turn_on && !capable(CAP_SYS_RAWIO))
17669 return -EPERM;
17670
17671@@ -54,7 +61,7 @@ asmlinkage long sys_ioperm(unsigned long from, unsigned long num, int turn_on)
17672 * because the ->io_bitmap_max value must match the bitmap
17673 * contents:
17674 */
17675- tss = &per_cpu(init_tss, get_cpu());
17676+ tss = init_tss + get_cpu();
17677
17678 if (turn_on)
17679 bitmap_clear(t->io_bitmap_ptr, from, num);
17680@@ -102,6 +109,12 @@ long sys_iopl(unsigned int level, struct pt_regs *regs)
17681 return -EINVAL;
17682 /* Trying to gain more privileges? */
17683 if (level > old) {
17684+#ifdef CONFIG_GRKERNSEC_IO
17685+ if (grsec_disable_privio) {
17686+ gr_handle_iopl();
17687+ return -EPERM;
17688+ }
17689+#endif
17690 if (!capable(CAP_SYS_RAWIO))
17691 return -EPERM;
17692 }
17693diff --git a/arch/x86/kernel/irq.c b/arch/x86/kernel/irq.c
17694index d44f782..31ab01e 100644
17695--- a/arch/x86/kernel/irq.c
17696+++ b/arch/x86/kernel/irq.c
17697@@ -18,7 +18,7 @@
17698 #include <asm/mce.h>
17699 #include <asm/hw_irq.h>
17700
17701-atomic_t irq_err_count;
17702+atomic_unchecked_t irq_err_count;
17703
17704 /* Function pointer for generic interrupt vector handling */
17705 void (*x86_platform_ipi_callback)(void) = NULL;
17706@@ -121,9 +121,9 @@ int arch_show_interrupts(struct seq_file *p, int prec)
17707 seq_printf(p, "%10u ", per_cpu(mce_poll_count, j));
17708 seq_printf(p, " Machine check polls\n");
17709 #endif
17710- seq_printf(p, "%*s: %10u\n", prec, "ERR", atomic_read(&irq_err_count));
17711+ seq_printf(p, "%*s: %10u\n", prec, "ERR", atomic_read_unchecked(&irq_err_count));
17712 #if defined(CONFIG_X86_IO_APIC)
17713- seq_printf(p, "%*s: %10u\n", prec, "MIS", atomic_read(&irq_mis_count));
17714+ seq_printf(p, "%*s: %10u\n", prec, "MIS", atomic_read_unchecked(&irq_mis_count));
17715 #endif
17716 return 0;
17717 }
17718@@ -164,10 +164,10 @@ u64 arch_irq_stat_cpu(unsigned int cpu)
17719
17720 u64 arch_irq_stat(void)
17721 {
17722- u64 sum = atomic_read(&irq_err_count);
17723+ u64 sum = atomic_read_unchecked(&irq_err_count);
17724
17725 #ifdef CONFIG_X86_IO_APIC
17726- sum += atomic_read(&irq_mis_count);
17727+ sum += atomic_read_unchecked(&irq_mis_count);
17728 #endif
17729 return sum;
17730 }
17731diff --git a/arch/x86/kernel/irq_32.c b/arch/x86/kernel/irq_32.c
17732index 344faf8..355f60d 100644
17733--- a/arch/x86/kernel/irq_32.c
17734+++ b/arch/x86/kernel/irq_32.c
17735@@ -39,7 +39,7 @@ static int check_stack_overflow(void)
17736 __asm__ __volatile__("andl %%esp,%0" :
17737 "=r" (sp) : "0" (THREAD_SIZE - 1));
17738
17739- return sp < (sizeof(struct thread_info) + STACK_WARN);
17740+ return sp < STACK_WARN;
17741 }
17742
17743 static void print_stack_overflow(void)
17744@@ -59,8 +59,8 @@ static inline void print_stack_overflow(void) { }
17745 * per-CPU IRQ handling contexts (thread information and stack)
17746 */
17747 union irq_ctx {
17748- struct thread_info tinfo;
17749- u32 stack[THREAD_SIZE/sizeof(u32)];
17750+ unsigned long previous_esp;
17751+ u32 stack[THREAD_SIZE/sizeof(u32)];
17752 } __attribute__((aligned(THREAD_SIZE)));
17753
17754 static DEFINE_PER_CPU(union irq_ctx *, hardirq_ctx);
17755@@ -80,10 +80,9 @@ static void call_on_stack(void *func, void *stack)
17756 static inline int
17757 execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
17758 {
17759- union irq_ctx *curctx, *irqctx;
17760+ union irq_ctx *irqctx;
17761 u32 *isp, arg1, arg2;
17762
17763- curctx = (union irq_ctx *) current_thread_info();
17764 irqctx = __this_cpu_read(hardirq_ctx);
17765
17766 /*
17767@@ -92,16 +91,16 @@ execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
17768 * handler) we can't do that and just have to keep using the
17769 * current stack (which is the irq stack already after all)
17770 */
17771- if (unlikely(curctx == irqctx))
17772+ if (unlikely((void *)current_stack_pointer - (void *)irqctx < THREAD_SIZE))
17773 return 0;
17774
17775 /* build the stack frame on the IRQ stack */
17776- isp = (u32 *) ((char *)irqctx + sizeof(*irqctx));
17777- irqctx->tinfo.task = curctx->tinfo.task;
17778- irqctx->tinfo.previous_esp = current_stack_pointer;
17779+ isp = (u32 *) ((char *)irqctx + sizeof(*irqctx) - 8);
17780+ irqctx->previous_esp = current_stack_pointer;
17781
17782- /* Copy the preempt_count so that the [soft]irq checks work. */
17783- irqctx->tinfo.preempt_count = curctx->tinfo.preempt_count;
17784+#ifdef CONFIG_PAX_MEMORY_UDEREF
17785+ __set_fs(MAKE_MM_SEG(0));
17786+#endif
17787
17788 if (unlikely(overflow))
17789 call_on_stack(print_stack_overflow, isp);
17790@@ -113,6 +112,11 @@ execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
17791 : "0" (irq), "1" (desc), "2" (isp),
17792 "D" (desc->handle_irq)
17793 : "memory", "cc", "ecx");
17794+
17795+#ifdef CONFIG_PAX_MEMORY_UDEREF
17796+ __set_fs(current_thread_info()->addr_limit);
17797+#endif
17798+
17799 return 1;
17800 }
17801
17802@@ -121,29 +125,14 @@ execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
17803 */
17804 void __cpuinit irq_ctx_init(int cpu)
17805 {
17806- union irq_ctx *irqctx;
17807-
17808 if (per_cpu(hardirq_ctx, cpu))
17809 return;
17810
17811- irqctx = page_address(alloc_pages_node(cpu_to_node(cpu),
17812- THREADINFO_GFP,
17813- THREAD_SIZE_ORDER));
17814- memset(&irqctx->tinfo, 0, sizeof(struct thread_info));
17815- irqctx->tinfo.cpu = cpu;
17816- irqctx->tinfo.preempt_count = HARDIRQ_OFFSET;
17817- irqctx->tinfo.addr_limit = MAKE_MM_SEG(0);
17818-
17819- per_cpu(hardirq_ctx, cpu) = irqctx;
17820-
17821- irqctx = page_address(alloc_pages_node(cpu_to_node(cpu),
17822- THREADINFO_GFP,
17823- THREAD_SIZE_ORDER));
17824- memset(&irqctx->tinfo, 0, sizeof(struct thread_info));
17825- irqctx->tinfo.cpu = cpu;
17826- irqctx->tinfo.addr_limit = MAKE_MM_SEG(0);
17827-
17828- per_cpu(softirq_ctx, cpu) = irqctx;
17829+ per_cpu(hardirq_ctx, cpu) = page_address(alloc_pages_node(cpu_to_node(cpu), THREADINFO_GFP, THREAD_SIZE_ORDER));
17830+ per_cpu(softirq_ctx, cpu) = page_address(alloc_pages_node(cpu_to_node(cpu), THREADINFO_GFP, THREAD_SIZE_ORDER));
17831+
17832+ printk(KERN_DEBUG "CPU %u irqstacks, hard=%p soft=%p\n",
17833+ cpu, per_cpu(hardirq_ctx, cpu), per_cpu(softirq_ctx, cpu));
17834
17835 printk(KERN_DEBUG "CPU %u irqstacks, hard=%p soft=%p\n",
17836 cpu, per_cpu(hardirq_ctx, cpu), per_cpu(softirq_ctx, cpu));
17837@@ -152,7 +141,6 @@ void __cpuinit irq_ctx_init(int cpu)
17838 asmlinkage void do_softirq(void)
17839 {
17840 unsigned long flags;
17841- struct thread_info *curctx;
17842 union irq_ctx *irqctx;
17843 u32 *isp;
17844
17845@@ -162,15 +150,22 @@ asmlinkage void do_softirq(void)
17846 local_irq_save(flags);
17847
17848 if (local_softirq_pending()) {
17849- curctx = current_thread_info();
17850 irqctx = __this_cpu_read(softirq_ctx);
17851- irqctx->tinfo.task = curctx->task;
17852- irqctx->tinfo.previous_esp = current_stack_pointer;
17853+ irqctx->previous_esp = current_stack_pointer;
17854
17855 /* build the stack frame on the softirq stack */
17856- isp = (u32 *) ((char *)irqctx + sizeof(*irqctx));
17857+ isp = (u32 *) ((char *)irqctx + sizeof(*irqctx) - 8);
17858+
17859+#ifdef CONFIG_PAX_MEMORY_UDEREF
17860+ __set_fs(MAKE_MM_SEG(0));
17861+#endif
17862
17863 call_on_stack(__do_softirq, isp);
17864+
17865+#ifdef CONFIG_PAX_MEMORY_UDEREF
17866+ __set_fs(current_thread_info()->addr_limit);
17867+#endif
17868+
17869 /*
17870 * Shouldn't happen, we returned above if in_interrupt():
17871 */
17872@@ -191,7 +186,7 @@ bool handle_irq(unsigned irq, struct pt_regs *regs)
17873 if (unlikely(!desc))
17874 return false;
17875
17876- if (user_mode_vm(regs) || !execute_on_irq_stack(overflow, desc, irq)) {
17877+ if (user_mode(regs) || !execute_on_irq_stack(overflow, desc, irq)) {
17878 if (unlikely(overflow))
17879 print_stack_overflow();
17880 desc->handle_irq(irq, desc);
17881diff --git a/arch/x86/kernel/irq_64.c b/arch/x86/kernel/irq_64.c
17882index d04d3ec..ea4b374 100644
17883--- a/arch/x86/kernel/irq_64.c
17884+++ b/arch/x86/kernel/irq_64.c
17885@@ -44,7 +44,7 @@ static inline void stack_overflow_check(struct pt_regs *regs)
17886 u64 estack_top, estack_bottom;
17887 u64 curbase = (u64)task_stack_page(current);
17888
17889- if (user_mode_vm(regs))
17890+ if (user_mode(regs))
17891 return;
17892
17893 if (regs->sp >= curbase + sizeof(struct thread_info) +
17894diff --git a/arch/x86/kernel/kdebugfs.c b/arch/x86/kernel/kdebugfs.c
17895index dc1404b..bbc43e7 100644
17896--- a/arch/x86/kernel/kdebugfs.c
17897+++ b/arch/x86/kernel/kdebugfs.c
17898@@ -27,7 +27,7 @@ struct setup_data_node {
17899 u32 len;
17900 };
17901
17902-static ssize_t setup_data_read(struct file *file, char __user *user_buf,
17903+static ssize_t __size_overflow(3) setup_data_read(struct file *file, char __user *user_buf,
17904 size_t count, loff_t *ppos)
17905 {
17906 struct setup_data_node *node = file->private_data;
17907diff --git a/arch/x86/kernel/kgdb.c b/arch/x86/kernel/kgdb.c
17908index 3f61904..873cea9 100644
17909--- a/arch/x86/kernel/kgdb.c
17910+++ b/arch/x86/kernel/kgdb.c
17911@@ -127,11 +127,11 @@ char *dbg_get_reg(int regno, void *mem, struct pt_regs *regs)
17912 #ifdef CONFIG_X86_32
17913 switch (regno) {
17914 case GDB_SS:
17915- if (!user_mode_vm(regs))
17916+ if (!user_mode(regs))
17917 *(unsigned long *)mem = __KERNEL_DS;
17918 break;
17919 case GDB_SP:
17920- if (!user_mode_vm(regs))
17921+ if (!user_mode(regs))
17922 *(unsigned long *)mem = kernel_stack_pointer(regs);
17923 break;
17924 case GDB_GS:
17925@@ -476,12 +476,12 @@ int kgdb_arch_handle_exception(int e_vector, int signo, int err_code,
17926 case 'k':
17927 /* clear the trace bit */
17928 linux_regs->flags &= ~X86_EFLAGS_TF;
17929- atomic_set(&kgdb_cpu_doing_single_step, -1);
17930+ atomic_set_unchecked(&kgdb_cpu_doing_single_step, -1);
17931
17932 /* set the trace bit if we're stepping */
17933 if (remcomInBuffer[0] == 's') {
17934 linux_regs->flags |= X86_EFLAGS_TF;
17935- atomic_set(&kgdb_cpu_doing_single_step,
17936+ atomic_set_unchecked(&kgdb_cpu_doing_single_step,
17937 raw_smp_processor_id());
17938 }
17939
17940@@ -546,7 +546,7 @@ static int __kgdb_notify(struct die_args *args, unsigned long cmd)
17941
17942 switch (cmd) {
17943 case DIE_DEBUG:
17944- if (atomic_read(&kgdb_cpu_doing_single_step) != -1) {
17945+ if (atomic_read_unchecked(&kgdb_cpu_doing_single_step) != -1) {
17946 if (user_mode(regs))
17947 return single_step_cont(regs, args);
17948 break;
17949diff --git a/arch/x86/kernel/kprobes-opt.c b/arch/x86/kernel/kprobes-opt.c
17950index c5e410e..da6aaf9 100644
17951--- a/arch/x86/kernel/kprobes-opt.c
17952+++ b/arch/x86/kernel/kprobes-opt.c
17953@@ -338,7 +338,7 @@ int __kprobes arch_prepare_optimized_kprobe(struct optimized_kprobe *op)
17954 * Verify if the address gap is in 2GB range, because this uses
17955 * a relative jump.
17956 */
17957- rel = (long)op->optinsn.insn - (long)op->kp.addr + RELATIVEJUMP_SIZE;
17958+ rel = (long)op->optinsn.insn - ktla_ktva((long)op->kp.addr) + RELATIVEJUMP_SIZE;
17959 if (abs(rel) > 0x7fffffff)
17960 return -ERANGE;
17961
17962@@ -359,11 +359,11 @@ int __kprobes arch_prepare_optimized_kprobe(struct optimized_kprobe *op)
17963 synthesize_set_arg1(buf + TMPL_MOVE_IDX, (unsigned long)op);
17964
17965 /* Set probe function call */
17966- synthesize_relcall(buf + TMPL_CALL_IDX, optimized_callback);
17967+ synthesize_relcall(buf + TMPL_CALL_IDX, ktla_ktva(optimized_callback));
17968
17969 /* Set returning jmp instruction at the tail of out-of-line buffer */
17970 synthesize_reljump(buf + TMPL_END_IDX + op->optinsn.size,
17971- (u8 *)op->kp.addr + op->optinsn.size);
17972+ (u8 *)ktla_ktva(op->kp.addr) + op->optinsn.size);
17973
17974 flush_icache_range((unsigned long) buf,
17975 (unsigned long) buf + TMPL_END_IDX +
17976@@ -385,7 +385,7 @@ static void __kprobes setup_optimize_kprobe(struct text_poke_param *tprm,
17977 ((long)op->kp.addr + RELATIVEJUMP_SIZE));
17978
17979 /* Backup instructions which will be replaced by jump address */
17980- memcpy(op->optinsn.copied_insn, op->kp.addr + INT3_SIZE,
17981+ memcpy(op->optinsn.copied_insn, ktla_ktva(op->kp.addr) + INT3_SIZE,
17982 RELATIVE_ADDR_SIZE);
17983
17984 insn_buf[0] = RELATIVEJUMP_OPCODE;
17985diff --git a/arch/x86/kernel/kprobes.c b/arch/x86/kernel/kprobes.c
17986index e2f751e..dffa2a0 100644
17987--- a/arch/x86/kernel/kprobes.c
17988+++ b/arch/x86/kernel/kprobes.c
17989@@ -120,8 +120,11 @@ static void __kprobes __synthesize_relative_insn(void *from, void *to, u8 op)
17990 } __attribute__((packed)) *insn;
17991
17992 insn = (struct __arch_relative_insn *)from;
17993+
17994+ pax_open_kernel();
17995 insn->raddr = (s32)((long)(to) - ((long)(from) + 5));
17996 insn->op = op;
17997+ pax_close_kernel();
17998 }
17999
18000 /* Insert a jump instruction at address 'from', which jumps to address 'to'.*/
18001@@ -164,7 +167,7 @@ int __kprobes can_boost(kprobe_opcode_t *opcodes)
18002 kprobe_opcode_t opcode;
18003 kprobe_opcode_t *orig_opcodes = opcodes;
18004
18005- if (search_exception_tables((unsigned long)opcodes))
18006+ if (search_exception_tables(ktva_ktla((unsigned long)opcodes)))
18007 return 0; /* Page fault may occur on this address. */
18008
18009 retry:
18010@@ -332,7 +335,9 @@ int __kprobes __copy_instruction(u8 *dest, u8 *src)
18011 /* Another subsystem puts a breakpoint, failed to recover */
18012 if (insn.opcode.bytes[0] == BREAKPOINT_INSTRUCTION)
18013 return 0;
18014+ pax_open_kernel();
18015 memcpy(dest, insn.kaddr, insn.length);
18016+ pax_close_kernel();
18017
18018 #ifdef CONFIG_X86_64
18019 if (insn_rip_relative(&insn)) {
18020@@ -355,7 +360,9 @@ int __kprobes __copy_instruction(u8 *dest, u8 *src)
18021 newdisp = (u8 *) src + (s64) insn.displacement.value - (u8 *) dest;
18022 BUG_ON((s64) (s32) newdisp != newdisp); /* Sanity check. */
18023 disp = (u8 *) dest + insn_offset_displacement(&insn);
18024+ pax_open_kernel();
18025 *(s32 *) disp = (s32) newdisp;
18026+ pax_close_kernel();
18027 }
18028 #endif
18029 return insn.length;
18030@@ -485,7 +492,7 @@ setup_singlestep(struct kprobe *p, struct pt_regs *regs, struct kprobe_ctlblk *k
18031 * nor set current_kprobe, because it doesn't use single
18032 * stepping.
18033 */
18034- regs->ip = (unsigned long)p->ainsn.insn;
18035+ regs->ip = ktva_ktla((unsigned long)p->ainsn.insn);
18036 preempt_enable_no_resched();
18037 return;
18038 }
18039@@ -504,7 +511,7 @@ setup_singlestep(struct kprobe *p, struct pt_regs *regs, struct kprobe_ctlblk *k
18040 if (p->opcode == BREAKPOINT_INSTRUCTION)
18041 regs->ip = (unsigned long)p->addr;
18042 else
18043- regs->ip = (unsigned long)p->ainsn.insn;
18044+ regs->ip = ktva_ktla((unsigned long)p->ainsn.insn);
18045 }
18046
18047 /*
18048@@ -583,7 +590,7 @@ static int __kprobes kprobe_handler(struct pt_regs *regs)
18049 setup_singlestep(p, regs, kcb, 0);
18050 return 1;
18051 }
18052- } else if (*addr != BREAKPOINT_INSTRUCTION) {
18053+ } else if (*(kprobe_opcode_t *)ktla_ktva((unsigned long)addr) != BREAKPOINT_INSTRUCTION) {
18054 /*
18055 * The breakpoint instruction was removed right
18056 * after we hit it. Another cpu has removed
18057@@ -628,6 +635,9 @@ static void __used __kprobes kretprobe_trampoline_holder(void)
18058 " movq %rax, 152(%rsp)\n"
18059 RESTORE_REGS_STRING
18060 " popfq\n"
18061+#ifdef KERNEXEC_PLUGIN
18062+ " btsq $63,(%rsp)\n"
18063+#endif
18064 #else
18065 " pushf\n"
18066 SAVE_REGS_STRING
18067@@ -765,7 +775,7 @@ static void __kprobes
18068 resume_execution(struct kprobe *p, struct pt_regs *regs, struct kprobe_ctlblk *kcb)
18069 {
18070 unsigned long *tos = stack_addr(regs);
18071- unsigned long copy_ip = (unsigned long)p->ainsn.insn;
18072+ unsigned long copy_ip = ktva_ktla((unsigned long)p->ainsn.insn);
18073 unsigned long orig_ip = (unsigned long)p->addr;
18074 kprobe_opcode_t *insn = p->ainsn.insn;
18075
18076@@ -947,7 +957,7 @@ kprobe_exceptions_notify(struct notifier_block *self, unsigned long val, void *d
18077 struct die_args *args = data;
18078 int ret = NOTIFY_DONE;
18079
18080- if (args->regs && user_mode_vm(args->regs))
18081+ if (args->regs && user_mode(args->regs))
18082 return ret;
18083
18084 switch (val) {
18085diff --git a/arch/x86/kernel/ldt.c b/arch/x86/kernel/ldt.c
18086index ebc9873..1b9724b 100644
18087--- a/arch/x86/kernel/ldt.c
18088+++ b/arch/x86/kernel/ldt.c
18089@@ -66,13 +66,13 @@ static int alloc_ldt(mm_context_t *pc, int mincount, int reload)
18090 if (reload) {
18091 #ifdef CONFIG_SMP
18092 preempt_disable();
18093- load_LDT(pc);
18094+ load_LDT_nolock(pc);
18095 if (!cpumask_equal(mm_cpumask(current->mm),
18096 cpumask_of(smp_processor_id())))
18097 smp_call_function(flush_ldt, current->mm, 1);
18098 preempt_enable();
18099 #else
18100- load_LDT(pc);
18101+ load_LDT_nolock(pc);
18102 #endif
18103 }
18104 if (oldsize) {
18105@@ -94,7 +94,7 @@ static inline int copy_ldt(mm_context_t *new, mm_context_t *old)
18106 return err;
18107
18108 for (i = 0; i < old->size; i++)
18109- write_ldt_entry(new->ldt, i, old->ldt + i * LDT_ENTRY_SIZE);
18110+ write_ldt_entry(new->ldt, i, old->ldt + i);
18111 return 0;
18112 }
18113
18114@@ -115,6 +115,24 @@ int init_new_context(struct task_struct *tsk, struct mm_struct *mm)
18115 retval = copy_ldt(&mm->context, &old_mm->context);
18116 mutex_unlock(&old_mm->context.lock);
18117 }
18118+
18119+ if (tsk == current) {
18120+ mm->context.vdso = 0;
18121+
18122+#ifdef CONFIG_X86_32
18123+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
18124+ mm->context.user_cs_base = 0UL;
18125+ mm->context.user_cs_limit = ~0UL;
18126+
18127+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_SMP)
18128+ cpus_clear(mm->context.cpu_user_cs_mask);
18129+#endif
18130+
18131+#endif
18132+#endif
18133+
18134+ }
18135+
18136 return retval;
18137 }
18138
18139@@ -229,6 +247,13 @@ static int write_ldt(void __user *ptr, unsigned long bytecount, int oldmode)
18140 }
18141 }
18142
18143+#ifdef CONFIG_PAX_SEGMEXEC
18144+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (ldt_info.contents & MODIFY_LDT_CONTENTS_CODE)) {
18145+ error = -EINVAL;
18146+ goto out_unlock;
18147+ }
18148+#endif
18149+
18150 fill_ldt(&ldt, &ldt_info);
18151 if (oldmode)
18152 ldt.avl = 0;
18153diff --git a/arch/x86/kernel/machine_kexec_32.c b/arch/x86/kernel/machine_kexec_32.c
18154index 5b19e4d..6476a76 100644
18155--- a/arch/x86/kernel/machine_kexec_32.c
18156+++ b/arch/x86/kernel/machine_kexec_32.c
18157@@ -26,7 +26,7 @@
18158 #include <asm/cacheflush.h>
18159 #include <asm/debugreg.h>
18160
18161-static void set_idt(void *newidt, __u16 limit)
18162+static void set_idt(struct desc_struct *newidt, __u16 limit)
18163 {
18164 struct desc_ptr curidt;
18165
18166@@ -38,7 +38,7 @@ static void set_idt(void *newidt, __u16 limit)
18167 }
18168
18169
18170-static void set_gdt(void *newgdt, __u16 limit)
18171+static void set_gdt(struct desc_struct *newgdt, __u16 limit)
18172 {
18173 struct desc_ptr curgdt;
18174
18175@@ -216,7 +216,7 @@ void machine_kexec(struct kimage *image)
18176 }
18177
18178 control_page = page_address(image->control_code_page);
18179- memcpy(control_page, relocate_kernel, KEXEC_CONTROL_CODE_MAX_SIZE);
18180+ memcpy(control_page, (void *)ktla_ktva((unsigned long)relocate_kernel), KEXEC_CONTROL_CODE_MAX_SIZE);
18181
18182 relocate_kernel_ptr = control_page;
18183 page_list[PA_CONTROL_PAGE] = __pa(control_page);
18184diff --git a/arch/x86/kernel/microcode_intel.c b/arch/x86/kernel/microcode_intel.c
18185index 0327e2b..e43737b 100644
18186--- a/arch/x86/kernel/microcode_intel.c
18187+++ b/arch/x86/kernel/microcode_intel.c
18188@@ -430,13 +430,13 @@ static enum ucode_state request_microcode_fw(int cpu, struct device *device)
18189
18190 static int get_ucode_user(void *to, const void *from, size_t n)
18191 {
18192- return copy_from_user(to, from, n);
18193+ return copy_from_user(to, (const void __force_user *)from, n);
18194 }
18195
18196 static enum ucode_state
18197 request_microcode_user(int cpu, const void __user *buf, size_t size)
18198 {
18199- return generic_load_microcode(cpu, (void *)buf, size, &get_ucode_user);
18200+ return generic_load_microcode(cpu, (__force_kernel void *)buf, size, &get_ucode_user);
18201 }
18202
18203 static void microcode_fini_cpu(int cpu)
18204diff --git a/arch/x86/kernel/module.c b/arch/x86/kernel/module.c
18205index 216a4d7..b328f09 100644
18206--- a/arch/x86/kernel/module.c
18207+++ b/arch/x86/kernel/module.c
18208@@ -43,15 +43,60 @@ do { \
18209 } while (0)
18210 #endif
18211
18212-void *module_alloc(unsigned long size)
18213+static inline void *__module_alloc(unsigned long size, pgprot_t prot)
18214 {
18215- if (PAGE_ALIGN(size) > MODULES_LEN)
18216+ if (size == 0 || PAGE_ALIGN(size) > MODULES_LEN)
18217 return NULL;
18218 return __vmalloc_node_range(size, 1, MODULES_VADDR, MODULES_END,
18219- GFP_KERNEL | __GFP_HIGHMEM, PAGE_KERNEL_EXEC,
18220+ GFP_KERNEL | __GFP_HIGHMEM | __GFP_ZERO, prot,
18221 -1, __builtin_return_address(0));
18222 }
18223
18224+void *module_alloc(unsigned long size)
18225+{
18226+
18227+#ifdef CONFIG_PAX_KERNEXEC
18228+ return __module_alloc(size, PAGE_KERNEL);
18229+#else
18230+ return __module_alloc(size, PAGE_KERNEL_EXEC);
18231+#endif
18232+
18233+}
18234+
18235+#ifdef CONFIG_PAX_KERNEXEC
18236+#ifdef CONFIG_X86_32
18237+void *module_alloc_exec(unsigned long size)
18238+{
18239+ struct vm_struct *area;
18240+
18241+ if (size == 0)
18242+ return NULL;
18243+
18244+ area = __get_vm_area(size, VM_ALLOC, (unsigned long)&MODULES_EXEC_VADDR, (unsigned long)&MODULES_EXEC_END);
18245+ return area ? area->addr : NULL;
18246+}
18247+EXPORT_SYMBOL(module_alloc_exec);
18248+
18249+void module_free_exec(struct module *mod, void *module_region)
18250+{
18251+ vunmap(module_region);
18252+}
18253+EXPORT_SYMBOL(module_free_exec);
18254+#else
18255+void module_free_exec(struct module *mod, void *module_region)
18256+{
18257+ module_free(mod, module_region);
18258+}
18259+EXPORT_SYMBOL(module_free_exec);
18260+
18261+void *module_alloc_exec(unsigned long size)
18262+{
18263+ return __module_alloc(size, PAGE_KERNEL_RX);
18264+}
18265+EXPORT_SYMBOL(module_alloc_exec);
18266+#endif
18267+#endif
18268+
18269 #ifdef CONFIG_X86_32
18270 int apply_relocate(Elf32_Shdr *sechdrs,
18271 const char *strtab,
18272@@ -62,14 +107,16 @@ int apply_relocate(Elf32_Shdr *sechdrs,
18273 unsigned int i;
18274 Elf32_Rel *rel = (void *)sechdrs[relsec].sh_addr;
18275 Elf32_Sym *sym;
18276- uint32_t *location;
18277+ uint32_t *plocation, location;
18278
18279 DEBUGP("Applying relocate section %u to %u\n",
18280 relsec, sechdrs[relsec].sh_info);
18281 for (i = 0; i < sechdrs[relsec].sh_size / sizeof(*rel); i++) {
18282 /* This is where to make the change */
18283- location = (void *)sechdrs[sechdrs[relsec].sh_info].sh_addr
18284- + rel[i].r_offset;
18285+ plocation = (void *)sechdrs[sechdrs[relsec].sh_info].sh_addr + rel[i].r_offset;
18286+ location = (uint32_t)plocation;
18287+ if (sechdrs[sechdrs[relsec].sh_info].sh_flags & SHF_EXECINSTR)
18288+ plocation = ktla_ktva((void *)plocation);
18289 /* This is the symbol it is referring to. Note that all
18290 undefined symbols have been resolved. */
18291 sym = (Elf32_Sym *)sechdrs[symindex].sh_addr
18292@@ -78,11 +125,15 @@ int apply_relocate(Elf32_Shdr *sechdrs,
18293 switch (ELF32_R_TYPE(rel[i].r_info)) {
18294 case R_386_32:
18295 /* We add the value into the location given */
18296- *location += sym->st_value;
18297+ pax_open_kernel();
18298+ *plocation += sym->st_value;
18299+ pax_close_kernel();
18300 break;
18301 case R_386_PC32:
18302 /* Add the value, subtract its position */
18303- *location += sym->st_value - (uint32_t)location;
18304+ pax_open_kernel();
18305+ *plocation += sym->st_value - location;
18306+ pax_close_kernel();
18307 break;
18308 default:
18309 pr_err("%s: Unknown relocation: %u\n",
18310@@ -127,21 +178,30 @@ int apply_relocate_add(Elf64_Shdr *sechdrs,
18311 case R_X86_64_NONE:
18312 break;
18313 case R_X86_64_64:
18314+ pax_open_kernel();
18315 *(u64 *)loc = val;
18316+ pax_close_kernel();
18317 break;
18318 case R_X86_64_32:
18319+ pax_open_kernel();
18320 *(u32 *)loc = val;
18321+ pax_close_kernel();
18322 if (val != *(u32 *)loc)
18323 goto overflow;
18324 break;
18325 case R_X86_64_32S:
18326+ pax_open_kernel();
18327 *(s32 *)loc = val;
18328+ pax_close_kernel();
18329 if ((s64)val != *(s32 *)loc)
18330 goto overflow;
18331 break;
18332 case R_X86_64_PC32:
18333 val -= (u64)loc;
18334+ pax_open_kernel();
18335 *(u32 *)loc = val;
18336+ pax_close_kernel();
18337+
18338 #if 0
18339 if ((s64)val != *(s32 *)loc)
18340 goto overflow;
18341diff --git a/arch/x86/kernel/nmi.c b/arch/x86/kernel/nmi.c
18342index f84f5c5..e27e54b 100644
18343--- a/arch/x86/kernel/nmi.c
18344+++ b/arch/x86/kernel/nmi.c
18345@@ -479,6 +479,17 @@ static inline void nmi_nesting_postprocess(void)
18346 dotraplinkage notrace __kprobes void
18347 do_nmi(struct pt_regs *regs, long error_code)
18348 {
18349+
18350+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
18351+ if (!user_mode(regs)) {
18352+ unsigned long cs = regs->cs & 0xFFFF;
18353+ unsigned long ip = ktva_ktla(regs->ip);
18354+
18355+ if ((cs == __KERNEL_CS || cs == __KERNEXEC_KERNEL_CS) && ip <= (unsigned long)_etext)
18356+ regs->ip = ip;
18357+ }
18358+#endif
18359+
18360 nmi_nesting_preprocess(regs);
18361
18362 nmi_enter();
18363diff --git a/arch/x86/kernel/paravirt-spinlocks.c b/arch/x86/kernel/paravirt-spinlocks.c
18364index 676b8c7..870ba04 100644
18365--- a/arch/x86/kernel/paravirt-spinlocks.c
18366+++ b/arch/x86/kernel/paravirt-spinlocks.c
18367@@ -13,7 +13,7 @@ default_spin_lock_flags(arch_spinlock_t *lock, unsigned long flags)
18368 arch_spin_lock(lock);
18369 }
18370
18371-struct pv_lock_ops pv_lock_ops = {
18372+struct pv_lock_ops pv_lock_ops __read_only = {
18373 #ifdef CONFIG_SMP
18374 .spin_is_locked = __ticket_spin_is_locked,
18375 .spin_is_contended = __ticket_spin_is_contended,
18376diff --git a/arch/x86/kernel/paravirt.c b/arch/x86/kernel/paravirt.c
18377index 17fff18..7bb2088 100644
18378--- a/arch/x86/kernel/paravirt.c
18379+++ b/arch/x86/kernel/paravirt.c
18380@@ -55,6 +55,9 @@ u64 _paravirt_ident_64(u64 x)
18381 {
18382 return x;
18383 }
18384+#if defined(CONFIG_X86_32) && defined(CONFIG_X86_PAE)
18385+PV_CALLEE_SAVE_REGS_THUNK(_paravirt_ident_64);
18386+#endif
18387
18388 void __init default_banner(void)
18389 {
18390@@ -147,15 +150,19 @@ unsigned paravirt_patch_default(u8 type, u16 clobbers, void *insnbuf,
18391 if (opfunc == NULL)
18392 /* If there's no function, patch it with a ud2a (BUG) */
18393 ret = paravirt_patch_insns(insnbuf, len, ud2a, ud2a+sizeof(ud2a));
18394- else if (opfunc == _paravirt_nop)
18395+ else if (opfunc == (void *)_paravirt_nop)
18396 /* If the operation is a nop, then nop the callsite */
18397 ret = paravirt_patch_nop();
18398
18399 /* identity functions just return their single argument */
18400- else if (opfunc == _paravirt_ident_32)
18401+ else if (opfunc == (void *)_paravirt_ident_32)
18402 ret = paravirt_patch_ident_32(insnbuf, len);
18403- else if (opfunc == _paravirt_ident_64)
18404+ else if (opfunc == (void *)_paravirt_ident_64)
18405 ret = paravirt_patch_ident_64(insnbuf, len);
18406+#if defined(CONFIG_X86_32) && defined(CONFIG_X86_PAE)
18407+ else if (opfunc == (void *)__raw_callee_save__paravirt_ident_64)
18408+ ret = paravirt_patch_ident_64(insnbuf, len);
18409+#endif
18410
18411 else if (type == PARAVIRT_PATCH(pv_cpu_ops.iret) ||
18412 type == PARAVIRT_PATCH(pv_cpu_ops.irq_enable_sysexit) ||
18413@@ -180,7 +187,7 @@ unsigned paravirt_patch_insns(void *insnbuf, unsigned len,
18414 if (insn_len > len || start == NULL)
18415 insn_len = len;
18416 else
18417- memcpy(insnbuf, start, insn_len);
18418+ memcpy(insnbuf, ktla_ktva(start), insn_len);
18419
18420 return insn_len;
18421 }
18422@@ -304,7 +311,7 @@ void arch_flush_lazy_mmu_mode(void)
18423 preempt_enable();
18424 }
18425
18426-struct pv_info pv_info = {
18427+struct pv_info pv_info __read_only = {
18428 .name = "bare hardware",
18429 .paravirt_enabled = 0,
18430 .kernel_rpl = 0,
18431@@ -315,16 +322,16 @@ struct pv_info pv_info = {
18432 #endif
18433 };
18434
18435-struct pv_init_ops pv_init_ops = {
18436+struct pv_init_ops pv_init_ops __read_only = {
18437 .patch = native_patch,
18438 };
18439
18440-struct pv_time_ops pv_time_ops = {
18441+struct pv_time_ops pv_time_ops __read_only = {
18442 .sched_clock = native_sched_clock,
18443 .steal_clock = native_steal_clock,
18444 };
18445
18446-struct pv_irq_ops pv_irq_ops = {
18447+struct pv_irq_ops pv_irq_ops __read_only = {
18448 .save_fl = __PV_IS_CALLEE_SAVE(native_save_fl),
18449 .restore_fl = __PV_IS_CALLEE_SAVE(native_restore_fl),
18450 .irq_disable = __PV_IS_CALLEE_SAVE(native_irq_disable),
18451@@ -336,7 +343,7 @@ struct pv_irq_ops pv_irq_ops = {
18452 #endif
18453 };
18454
18455-struct pv_cpu_ops pv_cpu_ops = {
18456+struct pv_cpu_ops pv_cpu_ops __read_only = {
18457 .cpuid = native_cpuid,
18458 .get_debugreg = native_get_debugreg,
18459 .set_debugreg = native_set_debugreg,
18460@@ -395,21 +402,26 @@ struct pv_cpu_ops pv_cpu_ops = {
18461 .end_context_switch = paravirt_nop,
18462 };
18463
18464-struct pv_apic_ops pv_apic_ops = {
18465+struct pv_apic_ops pv_apic_ops __read_only = {
18466 #ifdef CONFIG_X86_LOCAL_APIC
18467 .startup_ipi_hook = paravirt_nop,
18468 #endif
18469 };
18470
18471-#if defined(CONFIG_X86_32) && !defined(CONFIG_X86_PAE)
18472+#ifdef CONFIG_X86_32
18473+#ifdef CONFIG_X86_PAE
18474+/* 64-bit pagetable entries */
18475+#define PTE_IDENT PV_CALLEE_SAVE(_paravirt_ident_64)
18476+#else
18477 /* 32-bit pagetable entries */
18478 #define PTE_IDENT __PV_IS_CALLEE_SAVE(_paravirt_ident_32)
18479+#endif
18480 #else
18481 /* 64-bit pagetable entries */
18482 #define PTE_IDENT __PV_IS_CALLEE_SAVE(_paravirt_ident_64)
18483 #endif
18484
18485-struct pv_mmu_ops pv_mmu_ops = {
18486+struct pv_mmu_ops pv_mmu_ops __read_only = {
18487
18488 .read_cr2 = native_read_cr2,
18489 .write_cr2 = native_write_cr2,
18490@@ -459,6 +471,7 @@ struct pv_mmu_ops pv_mmu_ops = {
18491 .make_pud = PTE_IDENT,
18492
18493 .set_pgd = native_set_pgd,
18494+ .set_pgd_batched = native_set_pgd_batched,
18495 #endif
18496 #endif /* PAGETABLE_LEVELS >= 3 */
18497
18498@@ -478,6 +491,12 @@ struct pv_mmu_ops pv_mmu_ops = {
18499 },
18500
18501 .set_fixmap = native_set_fixmap,
18502+
18503+#ifdef CONFIG_PAX_KERNEXEC
18504+ .pax_open_kernel = native_pax_open_kernel,
18505+ .pax_close_kernel = native_pax_close_kernel,
18506+#endif
18507+
18508 };
18509
18510 EXPORT_SYMBOL_GPL(pv_time_ops);
18511diff --git a/arch/x86/kernel/pci-iommu_table.c b/arch/x86/kernel/pci-iommu_table.c
18512index 35ccf75..7a15747 100644
18513--- a/arch/x86/kernel/pci-iommu_table.c
18514+++ b/arch/x86/kernel/pci-iommu_table.c
18515@@ -2,7 +2,7 @@
18516 #include <asm/iommu_table.h>
18517 #include <linux/string.h>
18518 #include <linux/kallsyms.h>
18519-
18520+#include <linux/sched.h>
18521
18522 #define DEBUG 1
18523
18524diff --git a/arch/x86/kernel/process.c b/arch/x86/kernel/process.c
18525index ef6a845..8028ed3 100644
18526--- a/arch/x86/kernel/process.c
18527+++ b/arch/x86/kernel/process.c
18528@@ -36,7 +36,8 @@
18529 * section. Since TSS's are completely CPU-local, we want them
18530 * on exact cacheline boundaries, to eliminate cacheline ping-pong.
18531 */
18532-DEFINE_PER_CPU_SHARED_ALIGNED(struct tss_struct, init_tss) = INIT_TSS;
18533+struct tss_struct init_tss[NR_CPUS] ____cacheline_internodealigned_in_smp = { [0 ... NR_CPUS-1] = INIT_TSS };
18534+EXPORT_SYMBOL(init_tss);
18535
18536 #ifdef CONFIG_X86_64
18537 static DEFINE_PER_CPU(unsigned char, is_idle);
18538@@ -94,7 +95,7 @@ void arch_task_cache_init(void)
18539 task_xstate_cachep =
18540 kmem_cache_create("task_xstate", xstate_size,
18541 __alignof__(union thread_xstate),
18542- SLAB_PANIC | SLAB_NOTRACK, NULL);
18543+ SLAB_PANIC | SLAB_NOTRACK | SLAB_USERCOPY, NULL);
18544 }
18545
18546 static inline void drop_fpu(struct task_struct *tsk)
18547@@ -117,7 +118,7 @@ void exit_thread(void)
18548 unsigned long *bp = t->io_bitmap_ptr;
18549
18550 if (bp) {
18551- struct tss_struct *tss = &per_cpu(init_tss, get_cpu());
18552+ struct tss_struct *tss = init_tss + get_cpu();
18553
18554 t->io_bitmap_ptr = NULL;
18555 clear_thread_flag(TIF_IO_BITMAP);
18556@@ -148,7 +149,7 @@ void show_regs_common(void)
18557 board = dmi_get_system_info(DMI_BOARD_NAME);
18558
18559 printk(KERN_DEFAULT "Pid: %d, comm: %.20s %s %s %.*s %s %s%s%s\n",
18560- current->pid, current->comm, print_tainted(),
18561+ task_pid_nr(current), current->comm, print_tainted(),
18562 init_utsname()->release,
18563 (int)strcspn(init_utsname()->version, " "),
18564 init_utsname()->version,
18565@@ -161,6 +162,9 @@ void flush_thread(void)
18566 {
18567 struct task_struct *tsk = current;
18568
18569+#if defined(CONFIG_X86_32) && !defined(CONFIG_CC_STACKPROTECTOR) && !defined(CONFIG_PAX_MEMORY_UDEREF)
18570+ loadsegment(gs, 0);
18571+#endif
18572 flush_ptrace_hw_breakpoint(tsk);
18573 memset(tsk->thread.tls_array, 0, sizeof(tsk->thread.tls_array));
18574 drop_fpu(tsk);
18575@@ -318,10 +322,10 @@ int kernel_thread(int (*fn)(void *), void *arg, unsigned long flags)
18576 regs.di = (unsigned long) arg;
18577
18578 #ifdef CONFIG_X86_32
18579- regs.ds = __USER_DS;
18580- regs.es = __USER_DS;
18581+ regs.ds = __KERNEL_DS;
18582+ regs.es = __KERNEL_DS;
18583 regs.fs = __KERNEL_PERCPU;
18584- regs.gs = __KERNEL_STACK_CANARY;
18585+ savesegment(gs, regs.gs);
18586 #else
18587 regs.ss = __KERNEL_DS;
18588 #endif
18589@@ -407,7 +411,7 @@ static void __exit_idle(void)
18590 void exit_idle(void)
18591 {
18592 /* idle loop has pid 0 */
18593- if (current->pid)
18594+ if (task_pid_nr(current))
18595 return;
18596 __exit_idle();
18597 }
18598@@ -516,7 +520,7 @@ bool set_pm_idle_to_default(void)
18599
18600 return ret;
18601 }
18602-void stop_this_cpu(void *dummy)
18603+__noreturn void stop_this_cpu(void *dummy)
18604 {
18605 local_irq_disable();
18606 /*
18607@@ -744,16 +748,37 @@ static int __init idle_setup(char *str)
18608 }
18609 early_param("idle", idle_setup);
18610
18611-unsigned long arch_align_stack(unsigned long sp)
18612+#ifdef CONFIG_PAX_RANDKSTACK
18613+void pax_randomize_kstack(struct pt_regs *regs)
18614 {
18615- if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
18616- sp -= get_random_int() % 8192;
18617- return sp & ~0xf;
18618-}
18619+ struct thread_struct *thread = &current->thread;
18620+ unsigned long time;
18621
18622-unsigned long arch_randomize_brk(struct mm_struct *mm)
18623-{
18624- unsigned long range_end = mm->brk + 0x02000000;
18625- return randomize_range(mm->brk, range_end, 0) ? : mm->brk;
18626-}
18627+ if (!randomize_va_space)
18628+ return;
18629+
18630+ if (v8086_mode(regs))
18631+ return;
18632
18633+ rdtscl(time);
18634+
18635+ /* P4 seems to return a 0 LSB, ignore it */
18636+#ifdef CONFIG_MPENTIUM4
18637+ time &= 0x3EUL;
18638+ time <<= 2;
18639+#elif defined(CONFIG_X86_64)
18640+ time &= 0xFUL;
18641+ time <<= 4;
18642+#else
18643+ time &= 0x1FUL;
18644+ time <<= 3;
18645+#endif
18646+
18647+ thread->sp0 ^= time;
18648+ load_sp0(init_tss + smp_processor_id(), thread);
18649+
18650+#ifdef CONFIG_X86_64
18651+ this_cpu_write(kernel_stack, thread->sp0);
18652+#endif
18653+}
18654+#endif
18655diff --git a/arch/x86/kernel/process_32.c b/arch/x86/kernel/process_32.c
18656index 516fa18..80bd9e6 100644
18657--- a/arch/x86/kernel/process_32.c
18658+++ b/arch/x86/kernel/process_32.c
18659@@ -64,6 +64,7 @@ asmlinkage void ret_from_fork(void) __asm__("ret_from_fork");
18660 unsigned long thread_saved_pc(struct task_struct *tsk)
18661 {
18662 return ((unsigned long *)tsk->thread.sp)[3];
18663+//XXX return tsk->thread.eip;
18664 }
18665
18666 void __show_regs(struct pt_regs *regs, int all)
18667@@ -73,15 +74,14 @@ void __show_regs(struct pt_regs *regs, int all)
18668 unsigned long sp;
18669 unsigned short ss, gs;
18670
18671- if (user_mode_vm(regs)) {
18672+ if (user_mode(regs)) {
18673 sp = regs->sp;
18674 ss = regs->ss & 0xffff;
18675- gs = get_user_gs(regs);
18676 } else {
18677 sp = kernel_stack_pointer(regs);
18678 savesegment(ss, ss);
18679- savesegment(gs, gs);
18680 }
18681+ gs = get_user_gs(regs);
18682
18683 show_regs_common();
18684
18685@@ -134,13 +134,14 @@ int copy_thread(unsigned long clone_flags, unsigned long sp,
18686 struct task_struct *tsk;
18687 int err;
18688
18689- childregs = task_pt_regs(p);
18690+ childregs = task_stack_page(p) + THREAD_SIZE - sizeof(struct pt_regs) - 8;
18691 *childregs = *regs;
18692 childregs->ax = 0;
18693 childregs->sp = sp;
18694
18695 p->thread.sp = (unsigned long) childregs;
18696 p->thread.sp0 = (unsigned long) (childregs+1);
18697+ p->tinfo.lowest_stack = (unsigned long)task_stack_page(p);
18698
18699 p->thread.ip = (unsigned long) ret_from_fork;
18700
18701@@ -231,7 +232,7 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
18702 struct thread_struct *prev = &prev_p->thread,
18703 *next = &next_p->thread;
18704 int cpu = smp_processor_id();
18705- struct tss_struct *tss = &per_cpu(init_tss, cpu);
18706+ struct tss_struct *tss = init_tss + cpu;
18707 fpu_switch_t fpu;
18708
18709 /* never put a printk in __switch_to... printk() calls wake_up*() indirectly */
18710@@ -255,6 +256,10 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
18711 */
18712 lazy_save_gs(prev->gs);
18713
18714+#ifdef CONFIG_PAX_MEMORY_UDEREF
18715+ __set_fs(task_thread_info(next_p)->addr_limit);
18716+#endif
18717+
18718 /*
18719 * Load the per-thread Thread-Local Storage descriptor.
18720 */
18721@@ -285,6 +290,9 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
18722 */
18723 arch_end_context_switch(next_p);
18724
18725+ this_cpu_write(current_task, next_p);
18726+ this_cpu_write(current_tinfo, &next_p->tinfo);
18727+
18728 /*
18729 * Restore %gs if needed (which is common)
18730 */
18731@@ -293,8 +301,6 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
18732
18733 switch_fpu_finish(next_p, fpu);
18734
18735- this_cpu_write(current_task, next_p);
18736-
18737 return prev_p;
18738 }
18739
18740@@ -324,4 +330,3 @@ unsigned long get_wchan(struct task_struct *p)
18741 } while (count++ < 16);
18742 return 0;
18743 }
18744-
18745diff --git a/arch/x86/kernel/process_64.c b/arch/x86/kernel/process_64.c
18746index 0a980c9..1d0e689 100644
18747--- a/arch/x86/kernel/process_64.c
18748+++ b/arch/x86/kernel/process_64.c
18749@@ -153,8 +153,7 @@ int copy_thread(unsigned long clone_flags, unsigned long sp,
18750 struct pt_regs *childregs;
18751 struct task_struct *me = current;
18752
18753- childregs = ((struct pt_regs *)
18754- (THREAD_SIZE + task_stack_page(p))) - 1;
18755+ childregs = task_stack_page(p) + THREAD_SIZE - sizeof(struct pt_regs) - 16;
18756 *childregs = *regs;
18757
18758 childregs->ax = 0;
18759@@ -166,6 +165,7 @@ int copy_thread(unsigned long clone_flags, unsigned long sp,
18760 p->thread.sp = (unsigned long) childregs;
18761 p->thread.sp0 = (unsigned long) (childregs+1);
18762 p->thread.usersp = me->thread.usersp;
18763+ p->tinfo.lowest_stack = (unsigned long)task_stack_page(p);
18764
18765 set_tsk_thread_flag(p, TIF_FORK);
18766
18767@@ -271,7 +271,7 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
18768 struct thread_struct *prev = &prev_p->thread;
18769 struct thread_struct *next = &next_p->thread;
18770 int cpu = smp_processor_id();
18771- struct tss_struct *tss = &per_cpu(init_tss, cpu);
18772+ struct tss_struct *tss = init_tss + cpu;
18773 unsigned fsindex, gsindex;
18774 fpu_switch_t fpu;
18775
18776@@ -353,10 +353,9 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
18777 prev->usersp = this_cpu_read(old_rsp);
18778 this_cpu_write(old_rsp, next->usersp);
18779 this_cpu_write(current_task, next_p);
18780+ this_cpu_write(current_tinfo, &next_p->tinfo);
18781
18782- this_cpu_write(kernel_stack,
18783- (unsigned long)task_stack_page(next_p) +
18784- THREAD_SIZE - KERNEL_STACK_OFFSET);
18785+ this_cpu_write(kernel_stack, next->sp0);
18786
18787 /*
18788 * Now maybe reload the debug registers and handle I/O bitmaps
18789@@ -425,12 +424,11 @@ unsigned long get_wchan(struct task_struct *p)
18790 if (!p || p == current || p->state == TASK_RUNNING)
18791 return 0;
18792 stack = (unsigned long)task_stack_page(p);
18793- if (p->thread.sp < stack || p->thread.sp >= stack+THREAD_SIZE)
18794+ if (p->thread.sp < stack || p->thread.sp > stack+THREAD_SIZE-16-sizeof(u64))
18795 return 0;
18796 fp = *(u64 *)(p->thread.sp);
18797 do {
18798- if (fp < (unsigned long)stack ||
18799- fp >= (unsigned long)stack+THREAD_SIZE)
18800+ if (fp < stack || fp > stack+THREAD_SIZE-16-sizeof(u64))
18801 return 0;
18802 ip = *(u64 *)(fp+8);
18803 if (!in_sched_functions(ip))
18804diff --git a/arch/x86/kernel/ptrace.c b/arch/x86/kernel/ptrace.c
18805index c4c6a5c..905f440 100644
18806--- a/arch/x86/kernel/ptrace.c
18807+++ b/arch/x86/kernel/ptrace.c
18808@@ -824,7 +824,7 @@ long arch_ptrace(struct task_struct *child, long request,
18809 unsigned long addr, unsigned long data)
18810 {
18811 int ret;
18812- unsigned long __user *datap = (unsigned long __user *)data;
18813+ unsigned long __user *datap = (__force unsigned long __user *)data;
18814
18815 switch (request) {
18816 /* read the word at location addr in the USER area. */
18817@@ -909,14 +909,14 @@ long arch_ptrace(struct task_struct *child, long request,
18818 if ((int) addr < 0)
18819 return -EIO;
18820 ret = do_get_thread_area(child, addr,
18821- (struct user_desc __user *)data);
18822+ (__force struct user_desc __user *) data);
18823 break;
18824
18825 case PTRACE_SET_THREAD_AREA:
18826 if ((int) addr < 0)
18827 return -EIO;
18828 ret = do_set_thread_area(child, addr,
18829- (struct user_desc __user *)data, 0);
18830+ (__force struct user_desc __user *) data, 0);
18831 break;
18832 #endif
18833
18834@@ -1426,7 +1426,7 @@ static void fill_sigtrap_info(struct task_struct *tsk,
18835 memset(info, 0, sizeof(*info));
18836 info->si_signo = SIGTRAP;
18837 info->si_code = si_code;
18838- info->si_addr = user_mode_vm(regs) ? (void __user *)regs->ip : NULL;
18839+ info->si_addr = user_mode(regs) ? (__force void __user *)regs->ip : NULL;
18840 }
18841
18842 void user_single_step_siginfo(struct task_struct *tsk,
18843@@ -1455,6 +1455,10 @@ void send_sigtrap(struct task_struct *tsk, struct pt_regs *regs,
18844 # define IS_IA32 0
18845 #endif
18846
18847+#ifdef CONFIG_GRKERNSEC_SETXID
18848+extern void gr_delayed_cred_worker(void);
18849+#endif
18850+
18851 /*
18852 * We must return the syscall number to actually look up in the table.
18853 * This can be -1L to skip running any syscall at all.
18854@@ -1463,6 +1467,11 @@ long syscall_trace_enter(struct pt_regs *regs)
18855 {
18856 long ret = 0;
18857
18858+#ifdef CONFIG_GRKERNSEC_SETXID
18859+ if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
18860+ gr_delayed_cred_worker();
18861+#endif
18862+
18863 /*
18864 * If we stepped into a sysenter/syscall insn, it trapped in
18865 * kernel mode; do_debug() cleared TF and set TIF_SINGLESTEP.
18866@@ -1511,6 +1520,11 @@ void syscall_trace_leave(struct pt_regs *regs)
18867 {
18868 bool step;
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 audit_syscall_exit(regs);
18876
18877 if (unlikely(test_thread_flag(TIF_SYSCALL_TRACEPOINT)))
18878diff --git a/arch/x86/kernel/pvclock.c b/arch/x86/kernel/pvclock.c
18879index 42eb330..139955c 100644
18880--- a/arch/x86/kernel/pvclock.c
18881+++ b/arch/x86/kernel/pvclock.c
18882@@ -81,11 +81,11 @@ unsigned long pvclock_tsc_khz(struct pvclock_vcpu_time_info *src)
18883 return pv_tsc_khz;
18884 }
18885
18886-static atomic64_t last_value = ATOMIC64_INIT(0);
18887+static atomic64_unchecked_t last_value = ATOMIC64_INIT(0);
18888
18889 void pvclock_resume(void)
18890 {
18891- atomic64_set(&last_value, 0);
18892+ atomic64_set_unchecked(&last_value, 0);
18893 }
18894
18895 cycle_t pvclock_clocksource_read(struct pvclock_vcpu_time_info *src)
18896@@ -121,11 +121,11 @@ cycle_t pvclock_clocksource_read(struct pvclock_vcpu_time_info *src)
18897 * updating at the same time, and one of them could be slightly behind,
18898 * making the assumption that last_value always go forward fail to hold.
18899 */
18900- last = atomic64_read(&last_value);
18901+ last = atomic64_read_unchecked(&last_value);
18902 do {
18903 if (ret < last)
18904 return last;
18905- last = atomic64_cmpxchg(&last_value, last, ret);
18906+ last = atomic64_cmpxchg_unchecked(&last_value, last, ret);
18907 } while (unlikely(last != ret));
18908
18909 return ret;
18910diff --git a/arch/x86/kernel/reboot.c b/arch/x86/kernel/reboot.c
18911index 52190a9..8074389 100644
18912--- a/arch/x86/kernel/reboot.c
18913+++ b/arch/x86/kernel/reboot.c
18914@@ -36,7 +36,7 @@ void (*pm_power_off)(void);
18915 EXPORT_SYMBOL(pm_power_off);
18916
18917 static const struct desc_ptr no_idt = {};
18918-static int reboot_mode;
18919+static unsigned short reboot_mode;
18920 enum reboot_type reboot_type = BOOT_ACPI;
18921 int reboot_force;
18922
18923@@ -157,6 +157,11 @@ static int __init set_bios_reboot(const struct dmi_system_id *d)
18924
18925 void __noreturn machine_real_restart(unsigned int type)
18926 {
18927+
18928+#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF))
18929+ struct desc_struct *gdt;
18930+#endif
18931+
18932 local_irq_disable();
18933
18934 /*
18935@@ -184,7 +189,29 @@ void __noreturn machine_real_restart(unsigned int type)
18936
18937 /* Jump to the identity-mapped low memory code */
18938 #ifdef CONFIG_X86_32
18939- asm volatile("jmpl *%0" : :
18940+
18941+#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
18942+ gdt = get_cpu_gdt_table(smp_processor_id());
18943+ pax_open_kernel();
18944+#ifdef CONFIG_PAX_MEMORY_UDEREF
18945+ gdt[GDT_ENTRY_KERNEL_DS].type = 3;
18946+ gdt[GDT_ENTRY_KERNEL_DS].limit = 0xf;
18947+ loadsegment(ds, __KERNEL_DS);
18948+ loadsegment(es, __KERNEL_DS);
18949+ loadsegment(ss, __KERNEL_DS);
18950+#endif
18951+#ifdef CONFIG_PAX_KERNEXEC
18952+ gdt[GDT_ENTRY_KERNEL_CS].base0 = 0;
18953+ gdt[GDT_ENTRY_KERNEL_CS].base1 = 0;
18954+ gdt[GDT_ENTRY_KERNEL_CS].base2 = 0;
18955+ gdt[GDT_ENTRY_KERNEL_CS].limit0 = 0xffff;
18956+ gdt[GDT_ENTRY_KERNEL_CS].limit = 0xf;
18957+ gdt[GDT_ENTRY_KERNEL_CS].g = 1;
18958+#endif
18959+ pax_close_kernel();
18960+#endif
18961+
18962+ asm volatile("ljmpl *%0" : :
18963 "rm" (real_mode_header->machine_real_restart_asm),
18964 "a" (type));
18965 #else
18966@@ -539,7 +566,7 @@ void __attribute__((weak)) mach_reboot_fixups(void)
18967 * try to force a triple fault and then cycle between hitting the keyboard
18968 * controller and doing that
18969 */
18970-static void native_machine_emergency_restart(void)
18971+static void __noreturn native_machine_emergency_restart(void)
18972 {
18973 int i;
18974 int attempt = 0;
18975@@ -662,13 +689,13 @@ void native_machine_shutdown(void)
18976 #endif
18977 }
18978
18979-static void __machine_emergency_restart(int emergency)
18980+static void __noreturn __machine_emergency_restart(int emergency)
18981 {
18982 reboot_emergency = emergency;
18983 machine_ops.emergency_restart();
18984 }
18985
18986-static void native_machine_restart(char *__unused)
18987+static void __noreturn native_machine_restart(char *__unused)
18988 {
18989 pr_notice("machine restart\n");
18990
18991@@ -677,7 +704,7 @@ static void native_machine_restart(char *__unused)
18992 __machine_emergency_restart(0);
18993 }
18994
18995-static void native_machine_halt(void)
18996+static void __noreturn native_machine_halt(void)
18997 {
18998 /* Stop other cpus and apics */
18999 machine_shutdown();
19000@@ -687,7 +714,7 @@ static void native_machine_halt(void)
19001 stop_this_cpu(NULL);
19002 }
19003
19004-static void native_machine_power_off(void)
19005+static void __noreturn native_machine_power_off(void)
19006 {
19007 if (pm_power_off) {
19008 if (!reboot_force)
19009@@ -696,6 +723,7 @@ static void native_machine_power_off(void)
19010 }
19011 /* A fallback in case there is no PM info available */
19012 tboot_shutdown(TB_SHUTDOWN_HALT);
19013+ unreachable();
19014 }
19015
19016 struct machine_ops machine_ops = {
19017diff --git a/arch/x86/kernel/relocate_kernel_64.S b/arch/x86/kernel/relocate_kernel_64.S
19018index 7a6f3b3..bed145d7 100644
19019--- a/arch/x86/kernel/relocate_kernel_64.S
19020+++ b/arch/x86/kernel/relocate_kernel_64.S
19021@@ -11,6 +11,7 @@
19022 #include <asm/kexec.h>
19023 #include <asm/processor-flags.h>
19024 #include <asm/pgtable_types.h>
19025+#include <asm/alternative-asm.h>
19026
19027 /*
19028 * Must be relocatable PIC code callable as a C function
19029@@ -160,13 +161,14 @@ identity_mapped:
19030 xorq %rbp, %rbp
19031 xorq %r8, %r8
19032 xorq %r9, %r9
19033- xorq %r10, %r9
19034+ xorq %r10, %r10
19035 xorq %r11, %r11
19036 xorq %r12, %r12
19037 xorq %r13, %r13
19038 xorq %r14, %r14
19039 xorq %r15, %r15
19040
19041+ pax_force_retaddr 0, 1
19042 ret
19043
19044 1:
19045diff --git a/arch/x86/kernel/setup.c b/arch/x86/kernel/setup.c
19046index 5cee802..bc22bc3 100644
19047--- a/arch/x86/kernel/setup.c
19048+++ b/arch/x86/kernel/setup.c
19049@@ -440,7 +440,7 @@ static void __init parse_setup_data(void)
19050
19051 switch (data->type) {
19052 case SETUP_E820_EXT:
19053- parse_e820_ext(data);
19054+ parse_e820_ext((struct setup_data __force_kernel *)data);
19055 break;
19056 case SETUP_DTB:
19057 add_dtb(pa_data);
19058@@ -632,7 +632,7 @@ static void __init trim_bios_range(void)
19059 * area (640->1Mb) as ram even though it is not.
19060 * take them out.
19061 */
19062- e820_remove_range(BIOS_BEGIN, BIOS_END - BIOS_BEGIN, E820_RAM, 1);
19063+ e820_remove_range(ISA_START_ADDRESS, ISA_END_ADDRESS - ISA_START_ADDRESS, E820_RAM, 1);
19064 sanitize_e820_map(e820.map, ARRAY_SIZE(e820.map), &e820.nr_map);
19065 }
19066
19067@@ -755,14 +755,14 @@ void __init setup_arch(char **cmdline_p)
19068
19069 if (!boot_params.hdr.root_flags)
19070 root_mountflags &= ~MS_RDONLY;
19071- init_mm.start_code = (unsigned long) _text;
19072- init_mm.end_code = (unsigned long) _etext;
19073+ init_mm.start_code = ktla_ktva((unsigned long) _text);
19074+ init_mm.end_code = ktla_ktva((unsigned long) _etext);
19075 init_mm.end_data = (unsigned long) _edata;
19076 init_mm.brk = _brk_end;
19077
19078- code_resource.start = virt_to_phys(_text);
19079- code_resource.end = virt_to_phys(_etext)-1;
19080- data_resource.start = virt_to_phys(_etext);
19081+ code_resource.start = virt_to_phys(ktla_ktva(_text));
19082+ code_resource.end = virt_to_phys(ktla_ktva(_etext))-1;
19083+ data_resource.start = virt_to_phys(_sdata);
19084 data_resource.end = virt_to_phys(_edata)-1;
19085 bss_resource.start = virt_to_phys(&__bss_start);
19086 bss_resource.end = virt_to_phys(&__bss_stop)-1;
19087diff --git a/arch/x86/kernel/setup_percpu.c b/arch/x86/kernel/setup_percpu.c
19088index 5cdff03..5810740 100644
19089--- a/arch/x86/kernel/setup_percpu.c
19090+++ b/arch/x86/kernel/setup_percpu.c
19091@@ -21,19 +21,17 @@
19092 #include <asm/cpu.h>
19093 #include <asm/stackprotector.h>
19094
19095-DEFINE_PER_CPU_READ_MOSTLY(int, cpu_number);
19096+#ifdef CONFIG_SMP
19097+DEFINE_PER_CPU_READ_MOSTLY(unsigned int, cpu_number);
19098 EXPORT_PER_CPU_SYMBOL(cpu_number);
19099+#endif
19100
19101-#ifdef CONFIG_X86_64
19102 #define BOOT_PERCPU_OFFSET ((unsigned long)__per_cpu_load)
19103-#else
19104-#define BOOT_PERCPU_OFFSET 0
19105-#endif
19106
19107 DEFINE_PER_CPU(unsigned long, this_cpu_off) = BOOT_PERCPU_OFFSET;
19108 EXPORT_PER_CPU_SYMBOL(this_cpu_off);
19109
19110-unsigned long __per_cpu_offset[NR_CPUS] __read_mostly = {
19111+unsigned long __per_cpu_offset[NR_CPUS] __read_only = {
19112 [0 ... NR_CPUS-1] = BOOT_PERCPU_OFFSET,
19113 };
19114 EXPORT_SYMBOL(__per_cpu_offset);
19115@@ -155,10 +153,10 @@ static inline void setup_percpu_segment(int cpu)
19116 {
19117 #ifdef CONFIG_X86_32
19118 struct desc_struct gdt;
19119+ unsigned long base = per_cpu_offset(cpu);
19120
19121- pack_descriptor(&gdt, per_cpu_offset(cpu), 0xFFFFF,
19122- 0x2 | DESCTYPE_S, 0x8);
19123- gdt.s = 1;
19124+ pack_descriptor(&gdt, base, (VMALLOC_END - base - 1) >> PAGE_SHIFT,
19125+ 0x83 | DESCTYPE_S, 0xC);
19126 write_gdt_entry(get_cpu_gdt_table(cpu),
19127 GDT_ENTRY_PERCPU, &gdt, DESCTYPE_S);
19128 #endif
19129@@ -219,6 +217,11 @@ void __init setup_per_cpu_areas(void)
19130 /* alrighty, percpu areas up and running */
19131 delta = (unsigned long)pcpu_base_addr - (unsigned long)__per_cpu_start;
19132 for_each_possible_cpu(cpu) {
19133+#ifdef CONFIG_CC_STACKPROTECTOR
19134+#ifdef CONFIG_X86_32
19135+ unsigned long canary = per_cpu(stack_canary.canary, cpu);
19136+#endif
19137+#endif
19138 per_cpu_offset(cpu) = delta + pcpu_unit_offsets[cpu];
19139 per_cpu(this_cpu_off, cpu) = per_cpu_offset(cpu);
19140 per_cpu(cpu_number, cpu) = cpu;
19141@@ -259,6 +262,12 @@ void __init setup_per_cpu_areas(void)
19142 */
19143 set_cpu_numa_node(cpu, early_cpu_to_node(cpu));
19144 #endif
19145+#ifdef CONFIG_CC_STACKPROTECTOR
19146+#ifdef CONFIG_X86_32
19147+ if (!cpu)
19148+ per_cpu(stack_canary.canary, cpu) = canary;
19149+#endif
19150+#endif
19151 /*
19152 * Up to this point, the boot CPU has been using .init.data
19153 * area. Reload any changed state for the boot CPU.
19154diff --git a/arch/x86/kernel/signal.c b/arch/x86/kernel/signal.c
19155index b280908..6de349e 100644
19156--- a/arch/x86/kernel/signal.c
19157+++ b/arch/x86/kernel/signal.c
19158@@ -194,7 +194,7 @@ static unsigned long align_sigframe(unsigned long sp)
19159 * Align the stack pointer according to the i386 ABI,
19160 * i.e. so that on function entry ((sp + 4) & 15) == 0.
19161 */
19162- sp = ((sp + 4) & -16ul) - 4;
19163+ sp = ((sp - 12) & -16ul) - 4;
19164 #else /* !CONFIG_X86_32 */
19165 sp = round_down(sp, 16) - 8;
19166 #endif
19167@@ -245,11 +245,11 @@ get_sigframe(struct k_sigaction *ka, struct pt_regs *regs, size_t frame_size,
19168 * Return an always-bogus address instead so we will die with SIGSEGV.
19169 */
19170 if (onsigstack && !likely(on_sig_stack(sp)))
19171- return (void __user *)-1L;
19172+ return (__force void __user *)-1L;
19173
19174 /* save i387 state */
19175 if (used_math() && save_i387_xstate(*fpstate) < 0)
19176- return (void __user *)-1L;
19177+ return (__force void __user *)-1L;
19178
19179 return (void __user *)sp;
19180 }
19181@@ -304,9 +304,9 @@ __setup_frame(int sig, struct k_sigaction *ka, sigset_t *set,
19182 }
19183
19184 if (current->mm->context.vdso)
19185- restorer = VDSO32_SYMBOL(current->mm->context.vdso, sigreturn);
19186+ restorer = (__force void __user *)VDSO32_SYMBOL(current->mm->context.vdso, sigreturn);
19187 else
19188- restorer = &frame->retcode;
19189+ restorer = (void __user *)&frame->retcode;
19190 if (ka->sa.sa_flags & SA_RESTORER)
19191 restorer = ka->sa.sa_restorer;
19192
19193@@ -320,7 +320,7 @@ __setup_frame(int sig, struct k_sigaction *ka, sigset_t *set,
19194 * reasons and because gdb uses it as a signature to notice
19195 * signal handler stack frames.
19196 */
19197- err |= __put_user(*((u64 *)&retcode), (u64 *)frame->retcode);
19198+ err |= __put_user(*((u64 *)&retcode), (u64 __user *)frame->retcode);
19199
19200 if (err)
19201 return -EFAULT;
19202@@ -374,7 +374,10 @@ static int __setup_rt_frame(int sig, struct k_sigaction *ka, siginfo_t *info,
19203 err |= __copy_to_user(&frame->uc.uc_sigmask, set, sizeof(*set));
19204
19205 /* Set up to return from userspace. */
19206- restorer = VDSO32_SYMBOL(current->mm->context.vdso, rt_sigreturn);
19207+ if (current->mm->context.vdso)
19208+ restorer = (__force void __user *)VDSO32_SYMBOL(current->mm->context.vdso, rt_sigreturn);
19209+ else
19210+ restorer = (void __user *)&frame->retcode;
19211 if (ka->sa.sa_flags & SA_RESTORER)
19212 restorer = ka->sa.sa_restorer;
19213 put_user_ex(restorer, &frame->pretcode);
19214@@ -386,7 +389,7 @@ static int __setup_rt_frame(int sig, struct k_sigaction *ka, siginfo_t *info,
19215 * reasons and because gdb uses it as a signature to notice
19216 * signal handler stack frames.
19217 */
19218- put_user_ex(*((u64 *)&rt_retcode), (u64 *)frame->retcode);
19219+ put_user_ex(*((u64 *)&rt_retcode), (u64 __user *)frame->retcode);
19220 } put_user_catch(err);
19221
19222 if (err)
19223diff --git a/arch/x86/kernel/smpboot.c b/arch/x86/kernel/smpboot.c
19224index 7c5a8c3..88d422f 100644
19225--- a/arch/x86/kernel/smpboot.c
19226+++ b/arch/x86/kernel/smpboot.c
19227@@ -670,6 +670,7 @@ static int __cpuinit do_boot_cpu(int apicid, int cpu, struct task_struct *idle)
19228 idle->thread.sp = (unsigned long) (((struct pt_regs *)
19229 (THREAD_SIZE + task_stack_page(idle))) - 1);
19230 per_cpu(current_task, cpu) = idle;
19231+ per_cpu(current_tinfo, cpu) = &idle->tinfo;
19232
19233 #ifdef CONFIG_X86_32
19234 /* Stack for startup_32 can be just as for start_secondary onwards */
19235@@ -677,11 +678,13 @@ static int __cpuinit do_boot_cpu(int apicid, int cpu, struct task_struct *idle)
19236 #else
19237 clear_tsk_thread_flag(idle, TIF_FORK);
19238 initial_gs = per_cpu_offset(cpu);
19239- per_cpu(kernel_stack, cpu) =
19240- (unsigned long)task_stack_page(idle) -
19241- KERNEL_STACK_OFFSET + THREAD_SIZE;
19242+ per_cpu(kernel_stack, cpu) = (unsigned long)task_stack_page(idle) - 16 + THREAD_SIZE;
19243 #endif
19244+
19245+ pax_open_kernel();
19246 early_gdt_descr.address = (unsigned long)get_cpu_gdt_table(cpu);
19247+ pax_close_kernel();
19248+
19249 initial_code = (unsigned long)start_secondary;
19250 stack_start = idle->thread.sp;
19251
19252@@ -817,6 +820,12 @@ int __cpuinit native_cpu_up(unsigned int cpu, struct task_struct *tidle)
19253
19254 per_cpu(cpu_state, cpu) = CPU_UP_PREPARE;
19255
19256+#ifdef CONFIG_PAX_PER_CPU_PGD
19257+ clone_pgd_range(get_cpu_pgd(cpu) + KERNEL_PGD_BOUNDARY,
19258+ swapper_pg_dir + KERNEL_PGD_BOUNDARY,
19259+ KERNEL_PGD_PTRS);
19260+#endif
19261+
19262 err = do_boot_cpu(apicid, cpu, tidle);
19263 if (err) {
19264 pr_debug("do_boot_cpu failed %d\n", err);
19265diff --git a/arch/x86/kernel/step.c b/arch/x86/kernel/step.c
19266index c346d11..d43b163 100644
19267--- a/arch/x86/kernel/step.c
19268+++ b/arch/x86/kernel/step.c
19269@@ -27,10 +27,10 @@ unsigned long convert_ip_to_linear(struct task_struct *child, struct pt_regs *re
19270 struct desc_struct *desc;
19271 unsigned long base;
19272
19273- seg &= ~7UL;
19274+ seg >>= 3;
19275
19276 mutex_lock(&child->mm->context.lock);
19277- if (unlikely((seg >> 3) >= child->mm->context.size))
19278+ if (unlikely(seg >= child->mm->context.size))
19279 addr = -1L; /* bogus selector, access would fault */
19280 else {
19281 desc = child->mm->context.ldt + seg;
19282@@ -42,7 +42,8 @@ unsigned long convert_ip_to_linear(struct task_struct *child, struct pt_regs *re
19283 addr += base;
19284 }
19285 mutex_unlock(&child->mm->context.lock);
19286- }
19287+ } else if (seg == __KERNEL_CS || seg == __KERNEXEC_KERNEL_CS)
19288+ addr = ktla_ktva(addr);
19289
19290 return addr;
19291 }
19292@@ -53,6 +54,9 @@ static int is_setting_trap_flag(struct task_struct *child, struct pt_regs *regs)
19293 unsigned char opcode[15];
19294 unsigned long addr = convert_ip_to_linear(child, regs);
19295
19296+ if (addr == -EINVAL)
19297+ return 0;
19298+
19299 copied = access_process_vm(child, addr, opcode, sizeof(opcode), 0);
19300 for (i = 0; i < copied; i++) {
19301 switch (opcode[i]) {
19302diff --git a/arch/x86/kernel/sys_i386_32.c b/arch/x86/kernel/sys_i386_32.c
19303index 0b0cb5f..db6b9ed 100644
19304--- a/arch/x86/kernel/sys_i386_32.c
19305+++ b/arch/x86/kernel/sys_i386_32.c
19306@@ -24,17 +24,224 @@
19307
19308 #include <asm/syscalls.h>
19309
19310-/*
19311- * Do a system call from kernel instead of calling sys_execve so we
19312- * end up with proper pt_regs.
19313- */
19314-int kernel_execve(const char *filename,
19315- const char *const argv[],
19316- const char *const envp[])
19317+int i386_mmap_check(unsigned long addr, unsigned long len, unsigned long flags)
19318 {
19319- long __res;
19320- asm volatile ("int $0x80"
19321- : "=a" (__res)
19322- : "0" (__NR_execve), "b" (filename), "c" (argv), "d" (envp) : "memory");
19323- return __res;
19324+ unsigned long pax_task_size = TASK_SIZE;
19325+
19326+#ifdef CONFIG_PAX_SEGMEXEC
19327+ if (current->mm->pax_flags & MF_PAX_SEGMEXEC)
19328+ pax_task_size = SEGMEXEC_TASK_SIZE;
19329+#endif
19330+
19331+ if (len > pax_task_size || addr > pax_task_size - len)
19332+ return -EINVAL;
19333+
19334+ return 0;
19335+}
19336+
19337+unsigned long
19338+arch_get_unmapped_area(struct file *filp, unsigned long addr,
19339+ unsigned long len, unsigned long pgoff, unsigned long flags)
19340+{
19341+ struct mm_struct *mm = current->mm;
19342+ struct vm_area_struct *vma;
19343+ unsigned long start_addr, pax_task_size = TASK_SIZE;
19344+
19345+#ifdef CONFIG_PAX_SEGMEXEC
19346+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
19347+ pax_task_size = SEGMEXEC_TASK_SIZE;
19348+#endif
19349+
19350+ pax_task_size -= PAGE_SIZE;
19351+
19352+ if (len > pax_task_size)
19353+ return -ENOMEM;
19354+
19355+ if (flags & MAP_FIXED)
19356+ return addr;
19357+
19358+#ifdef CONFIG_PAX_RANDMMAP
19359+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
19360+#endif
19361+
19362+ if (addr) {
19363+ addr = PAGE_ALIGN(addr);
19364+ if (pax_task_size - len >= addr) {
19365+ vma = find_vma(mm, addr);
19366+ if (check_heap_stack_gap(vma, addr, len))
19367+ return addr;
19368+ }
19369+ }
19370+ if (len > mm->cached_hole_size) {
19371+ start_addr = addr = mm->free_area_cache;
19372+ } else {
19373+ start_addr = addr = mm->mmap_base;
19374+ mm->cached_hole_size = 0;
19375+ }
19376+
19377+#ifdef CONFIG_PAX_PAGEEXEC
19378+ if (!(__supported_pte_mask & _PAGE_NX) && (mm->pax_flags & MF_PAX_PAGEEXEC) && (flags & MAP_EXECUTABLE) && start_addr >= mm->mmap_base) {
19379+ start_addr = 0x00110000UL;
19380+
19381+#ifdef CONFIG_PAX_RANDMMAP
19382+ if (mm->pax_flags & MF_PAX_RANDMMAP)
19383+ start_addr += mm->delta_mmap & 0x03FFF000UL;
19384+#endif
19385+
19386+ if (mm->start_brk <= start_addr && start_addr < mm->mmap_base)
19387+ start_addr = addr = mm->mmap_base;
19388+ else
19389+ addr = start_addr;
19390+ }
19391+#endif
19392+
19393+full_search:
19394+ for (vma = find_vma(mm, addr); ; vma = vma->vm_next) {
19395+ /* At this point: (!vma || addr < vma->vm_end). */
19396+ if (pax_task_size - len < addr) {
19397+ /*
19398+ * Start a new search - just in case we missed
19399+ * some holes.
19400+ */
19401+ if (start_addr != mm->mmap_base) {
19402+ start_addr = addr = mm->mmap_base;
19403+ mm->cached_hole_size = 0;
19404+ goto full_search;
19405+ }
19406+ return -ENOMEM;
19407+ }
19408+ if (check_heap_stack_gap(vma, addr, len))
19409+ break;
19410+ if (addr + mm->cached_hole_size < vma->vm_start)
19411+ mm->cached_hole_size = vma->vm_start - addr;
19412+ addr = vma->vm_end;
19413+ if (mm->start_brk <= addr && addr < mm->mmap_base) {
19414+ start_addr = addr = mm->mmap_base;
19415+ mm->cached_hole_size = 0;
19416+ goto full_search;
19417+ }
19418+ }
19419+
19420+ /*
19421+ * Remember the place where we stopped the search:
19422+ */
19423+ mm->free_area_cache = addr + len;
19424+ return addr;
19425+}
19426+
19427+unsigned long
19428+arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
19429+ const unsigned long len, const unsigned long pgoff,
19430+ const unsigned long flags)
19431+{
19432+ struct vm_area_struct *vma;
19433+ struct mm_struct *mm = current->mm;
19434+ unsigned long base = mm->mmap_base, addr = addr0, pax_task_size = TASK_SIZE;
19435+
19436+#ifdef CONFIG_PAX_SEGMEXEC
19437+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
19438+ pax_task_size = SEGMEXEC_TASK_SIZE;
19439+#endif
19440+
19441+ pax_task_size -= PAGE_SIZE;
19442+
19443+ /* requested length too big for entire address space */
19444+ if (len > pax_task_size)
19445+ return -ENOMEM;
19446+
19447+ if (flags & MAP_FIXED)
19448+ return addr;
19449+
19450+#ifdef CONFIG_PAX_PAGEEXEC
19451+ if (!(__supported_pte_mask & _PAGE_NX) && (mm->pax_flags & MF_PAX_PAGEEXEC) && (flags & MAP_EXECUTABLE))
19452+ goto bottomup;
19453+#endif
19454+
19455+#ifdef CONFIG_PAX_RANDMMAP
19456+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
19457+#endif
19458+
19459+ /* requesting a specific address */
19460+ if (addr) {
19461+ addr = PAGE_ALIGN(addr);
19462+ if (pax_task_size - len >= addr) {
19463+ vma = find_vma(mm, addr);
19464+ if (check_heap_stack_gap(vma, addr, len))
19465+ return addr;
19466+ }
19467+ }
19468+
19469+ /* check if free_area_cache is useful for us */
19470+ if (len <= mm->cached_hole_size) {
19471+ mm->cached_hole_size = 0;
19472+ mm->free_area_cache = mm->mmap_base;
19473+ }
19474+
19475+ /* either no address requested or can't fit in requested address hole */
19476+ addr = mm->free_area_cache;
19477+
19478+ /* make sure it can fit in the remaining address space */
19479+ if (addr > len) {
19480+ vma = find_vma(mm, addr-len);
19481+ if (check_heap_stack_gap(vma, addr - len, len))
19482+ /* remember the address as a hint for next time */
19483+ return (mm->free_area_cache = addr-len);
19484+ }
19485+
19486+ if (mm->mmap_base < len)
19487+ goto bottomup;
19488+
19489+ addr = mm->mmap_base-len;
19490+
19491+ do {
19492+ /*
19493+ * Lookup failure means no vma is above this address,
19494+ * else if new region fits below vma->vm_start,
19495+ * return with success:
19496+ */
19497+ vma = find_vma(mm, addr);
19498+ if (check_heap_stack_gap(vma, addr, len))
19499+ /* remember the address as a hint for next time */
19500+ return (mm->free_area_cache = addr);
19501+
19502+ /* remember the largest hole we saw so far */
19503+ if (addr + mm->cached_hole_size < vma->vm_start)
19504+ mm->cached_hole_size = vma->vm_start - addr;
19505+
19506+ /* try just below the current vma->vm_start */
19507+ addr = skip_heap_stack_gap(vma, len);
19508+ } while (!IS_ERR_VALUE(addr));
19509+
19510+bottomup:
19511+ /*
19512+ * A failed mmap() very likely causes application failure,
19513+ * so fall back to the bottom-up function here. This scenario
19514+ * can happen with large stack limits and large mmap()
19515+ * allocations.
19516+ */
19517+
19518+#ifdef CONFIG_PAX_SEGMEXEC
19519+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
19520+ mm->mmap_base = SEGMEXEC_TASK_UNMAPPED_BASE;
19521+ else
19522+#endif
19523+
19524+ mm->mmap_base = TASK_UNMAPPED_BASE;
19525+
19526+#ifdef CONFIG_PAX_RANDMMAP
19527+ if (mm->pax_flags & MF_PAX_RANDMMAP)
19528+ mm->mmap_base += mm->delta_mmap;
19529+#endif
19530+
19531+ mm->free_area_cache = mm->mmap_base;
19532+ mm->cached_hole_size = ~0UL;
19533+ addr = arch_get_unmapped_area(filp, addr0, len, pgoff, flags);
19534+ /*
19535+ * Restore the topdown base:
19536+ */
19537+ mm->mmap_base = base;
19538+ mm->free_area_cache = base;
19539+ mm->cached_hole_size = ~0UL;
19540+
19541+ return addr;
19542 }
19543diff --git a/arch/x86/kernel/sys_x86_64.c b/arch/x86/kernel/sys_x86_64.c
19544index b4d3c39..82bb73b 100644
19545--- a/arch/x86/kernel/sys_x86_64.c
19546+++ b/arch/x86/kernel/sys_x86_64.c
19547@@ -95,8 +95,8 @@ out:
19548 return error;
19549 }
19550
19551-static void find_start_end(unsigned long flags, unsigned long *begin,
19552- unsigned long *end)
19553+static void find_start_end(struct mm_struct *mm, unsigned long flags,
19554+ unsigned long *begin, unsigned long *end)
19555 {
19556 if (!test_thread_flag(TIF_ADDR32) && (flags & MAP_32BIT)) {
19557 unsigned long new_begin;
19558@@ -115,7 +115,7 @@ static void find_start_end(unsigned long flags, unsigned long *begin,
19559 *begin = new_begin;
19560 }
19561 } else {
19562- *begin = TASK_UNMAPPED_BASE;
19563+ *begin = mm->mmap_base;
19564 *end = TASK_SIZE;
19565 }
19566 }
19567@@ -132,16 +132,19 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
19568 if (flags & MAP_FIXED)
19569 return addr;
19570
19571- find_start_end(flags, &begin, &end);
19572+ find_start_end(mm, flags, &begin, &end);
19573
19574 if (len > end)
19575 return -ENOMEM;
19576
19577+#ifdef CONFIG_PAX_RANDMMAP
19578+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
19579+#endif
19580+
19581 if (addr) {
19582 addr = PAGE_ALIGN(addr);
19583 vma = find_vma(mm, addr);
19584- if (end - len >= addr &&
19585- (!vma || addr + len <= vma->vm_start))
19586+ if (end - len >= addr && check_heap_stack_gap(vma, addr, len))
19587 return addr;
19588 }
19589 if (((flags & MAP_32BIT) || test_thread_flag(TIF_ADDR32))
19590@@ -172,7 +175,7 @@ full_search:
19591 }
19592 return -ENOMEM;
19593 }
19594- if (!vma || addr + len <= vma->vm_start) {
19595+ if (check_heap_stack_gap(vma, addr, len)) {
19596 /*
19597 * Remember the place where we stopped the search:
19598 */
19599@@ -195,7 +198,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
19600 {
19601 struct vm_area_struct *vma;
19602 struct mm_struct *mm = current->mm;
19603- unsigned long addr = addr0, start_addr;
19604+ unsigned long base = mm->mmap_base, addr = addr0, start_addr;
19605
19606 /* requested length too big for entire address space */
19607 if (len > TASK_SIZE)
19608@@ -208,13 +211,18 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
19609 if (!test_thread_flag(TIF_ADDR32) && (flags & MAP_32BIT))
19610 goto bottomup;
19611
19612+#ifdef CONFIG_PAX_RANDMMAP
19613+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
19614+#endif
19615+
19616 /* requesting a specific address */
19617 if (addr) {
19618 addr = PAGE_ALIGN(addr);
19619- vma = find_vma(mm, addr);
19620- if (TASK_SIZE - len >= addr &&
19621- (!vma || addr + len <= vma->vm_start))
19622- return addr;
19623+ if (TASK_SIZE - len >= addr) {
19624+ vma = find_vma(mm, addr);
19625+ if (check_heap_stack_gap(vma, addr, len))
19626+ return addr;
19627+ }
19628 }
19629
19630 /* check if free_area_cache is useful for us */
19631@@ -240,7 +248,7 @@ try_again:
19632 * return with success:
19633 */
19634 vma = find_vma(mm, addr);
19635- if (!vma || addr+len <= vma->vm_start)
19636+ if (check_heap_stack_gap(vma, addr, len))
19637 /* remember the address as a hint for next time */
19638 return mm->free_area_cache = addr;
19639
19640@@ -249,8 +257,8 @@ try_again:
19641 mm->cached_hole_size = vma->vm_start - addr;
19642
19643 /* try just below the current vma->vm_start */
19644- addr = vma->vm_start-len;
19645- } while (len < vma->vm_start);
19646+ addr = skip_heap_stack_gap(vma, len);
19647+ } while (!IS_ERR_VALUE(addr));
19648
19649 fail:
19650 /*
19651@@ -270,13 +278,21 @@ bottomup:
19652 * can happen with large stack limits and large mmap()
19653 * allocations.
19654 */
19655+ mm->mmap_base = TASK_UNMAPPED_BASE;
19656+
19657+#ifdef CONFIG_PAX_RANDMMAP
19658+ if (mm->pax_flags & MF_PAX_RANDMMAP)
19659+ mm->mmap_base += mm->delta_mmap;
19660+#endif
19661+
19662+ mm->free_area_cache = mm->mmap_base;
19663 mm->cached_hole_size = ~0UL;
19664- mm->free_area_cache = TASK_UNMAPPED_BASE;
19665 addr = arch_get_unmapped_area(filp, addr0, len, pgoff, flags);
19666 /*
19667 * Restore the topdown base:
19668 */
19669- mm->free_area_cache = mm->mmap_base;
19670+ mm->mmap_base = base;
19671+ mm->free_area_cache = base;
19672 mm->cached_hole_size = ~0UL;
19673
19674 return addr;
19675diff --git a/arch/x86/kernel/tboot.c b/arch/x86/kernel/tboot.c
19676index f84fe00..93fe08f 100644
19677--- a/arch/x86/kernel/tboot.c
19678+++ b/arch/x86/kernel/tboot.c
19679@@ -220,7 +220,7 @@ static int tboot_setup_sleep(void)
19680
19681 void tboot_shutdown(u32 shutdown_type)
19682 {
19683- void (*shutdown)(void);
19684+ void (* __noreturn shutdown)(void);
19685
19686 if (!tboot_enabled())
19687 return;
19688@@ -242,7 +242,7 @@ void tboot_shutdown(u32 shutdown_type)
19689
19690 switch_to_tboot_pt();
19691
19692- shutdown = (void(*)(void))(unsigned long)tboot->shutdown_entry;
19693+ shutdown = (void *)tboot->shutdown_entry;
19694 shutdown();
19695
19696 /* should not reach here */
19697@@ -300,7 +300,7 @@ static int tboot_sleep(u8 sleep_state, u32 pm1a_control, u32 pm1b_control)
19698 return 0;
19699 }
19700
19701-static atomic_t ap_wfs_count;
19702+static atomic_unchecked_t ap_wfs_count;
19703
19704 static int tboot_wait_for_aps(int num_aps)
19705 {
19706@@ -324,9 +324,9 @@ static int __cpuinit tboot_cpu_callback(struct notifier_block *nfb,
19707 {
19708 switch (action) {
19709 case CPU_DYING:
19710- atomic_inc(&ap_wfs_count);
19711+ atomic_inc_unchecked(&ap_wfs_count);
19712 if (num_online_cpus() == 1)
19713- if (tboot_wait_for_aps(atomic_read(&ap_wfs_count)))
19714+ if (tboot_wait_for_aps(atomic_read_unchecked(&ap_wfs_count)))
19715 return NOTIFY_BAD;
19716 break;
19717 }
19718@@ -345,7 +345,7 @@ static __init int tboot_late_init(void)
19719
19720 tboot_create_trampoline();
19721
19722- atomic_set(&ap_wfs_count, 0);
19723+ atomic_set_unchecked(&ap_wfs_count, 0);
19724 register_hotcpu_notifier(&tboot_cpu_notifier);
19725
19726 acpi_os_set_prepare_sleep(&tboot_sleep);
19727diff --git a/arch/x86/kernel/time.c b/arch/x86/kernel/time.c
19728index 24d3c91..d06b473 100644
19729--- a/arch/x86/kernel/time.c
19730+++ b/arch/x86/kernel/time.c
19731@@ -30,9 +30,9 @@ unsigned long profile_pc(struct pt_regs *regs)
19732 {
19733 unsigned long pc = instruction_pointer(regs);
19734
19735- if (!user_mode_vm(regs) && in_lock_functions(pc)) {
19736+ if (!user_mode(regs) && in_lock_functions(pc)) {
19737 #ifdef CONFIG_FRAME_POINTER
19738- return *(unsigned long *)(regs->bp + sizeof(long));
19739+ return ktla_ktva(*(unsigned long *)(regs->bp + sizeof(long)));
19740 #else
19741 unsigned long *sp =
19742 (unsigned long *)kernel_stack_pointer(regs);
19743@@ -41,11 +41,17 @@ unsigned long profile_pc(struct pt_regs *regs)
19744 * or above a saved flags. Eflags has bits 22-31 zero,
19745 * kernel addresses don't.
19746 */
19747+
19748+#ifdef CONFIG_PAX_KERNEXEC
19749+ return ktla_ktva(sp[0]);
19750+#else
19751 if (sp[0] >> 22)
19752 return sp[0];
19753 if (sp[1] >> 22)
19754 return sp[1];
19755 #endif
19756+
19757+#endif
19758 }
19759 return pc;
19760 }
19761diff --git a/arch/x86/kernel/tls.c b/arch/x86/kernel/tls.c
19762index 9d9d2f9..cad418a 100644
19763--- a/arch/x86/kernel/tls.c
19764+++ b/arch/x86/kernel/tls.c
19765@@ -84,6 +84,11 @@ int do_set_thread_area(struct task_struct *p, int idx,
19766 if (idx < GDT_ENTRY_TLS_MIN || idx > GDT_ENTRY_TLS_MAX)
19767 return -EINVAL;
19768
19769+#ifdef CONFIG_PAX_SEGMEXEC
19770+ if ((p->mm->pax_flags & MF_PAX_SEGMEXEC) && (info.contents & MODIFY_LDT_CONTENTS_CODE))
19771+ return -EINVAL;
19772+#endif
19773+
19774 set_tls_desc(p, idx, &info, 1);
19775
19776 return 0;
19777@@ -204,7 +209,7 @@ int regset_tls_set(struct task_struct *target, const struct user_regset *regset,
19778
19779 if (kbuf)
19780 info = kbuf;
19781- else if (__copy_from_user(infobuf, ubuf, count))
19782+ else if (count > sizeof infobuf || __copy_from_user(infobuf, ubuf, count))
19783 return -EFAULT;
19784 else
19785 info = infobuf;
19786diff --git a/arch/x86/kernel/traps.c b/arch/x86/kernel/traps.c
19787index b481341..5918bbe 100644
19788--- a/arch/x86/kernel/traps.c
19789+++ b/arch/x86/kernel/traps.c
19790@@ -70,12 +70,6 @@ asmlinkage int system_call(void);
19791
19792 /* Do we ignore FPU interrupts ? */
19793 char ignore_fpu_irq;
19794-
19795-/*
19796- * The IDT has to be page-aligned to simplify the Pentium
19797- * F0 0F bug workaround.
19798- */
19799-gate_desc idt_table[NR_VECTORS] __page_aligned_data = { { { { 0, 0 } } }, };
19800 #endif
19801
19802 DECLARE_BITMAP(used_vectors, NR_VECTORS);
19803@@ -108,13 +102,13 @@ static inline void preempt_conditional_cli(struct pt_regs *regs)
19804 }
19805
19806 static void __kprobes
19807-do_trap(int trapnr, int signr, char *str, struct pt_regs *regs,
19808+do_trap(int trapnr, int signr, const char *str, struct pt_regs *regs,
19809 long error_code, siginfo_t *info)
19810 {
19811 struct task_struct *tsk = current;
19812
19813 #ifdef CONFIG_X86_32
19814- if (regs->flags & X86_VM_MASK) {
19815+ if (v8086_mode(regs)) {
19816 /*
19817 * traps 0, 1, 3, 4, and 5 should be forwarded to vm86.
19818 * On nmi (interrupt 2), do_trap should not be called.
19819@@ -125,7 +119,7 @@ do_trap(int trapnr, int signr, char *str, struct pt_regs *regs,
19820 }
19821 #endif
19822
19823- if (!user_mode(regs))
19824+ if (!user_mode_novm(regs))
19825 goto kernel_trap;
19826
19827 #ifdef CONFIG_X86_32
19828@@ -147,7 +141,7 @@ trap_signal:
19829 if (show_unhandled_signals && unhandled_signal(tsk, signr) &&
19830 printk_ratelimit()) {
19831 pr_info("%s[%d] trap %s ip:%lx sp:%lx error:%lx",
19832- tsk->comm, tsk->pid, str,
19833+ tsk->comm, task_pid_nr(tsk), str,
19834 regs->ip, regs->sp, error_code);
19835 print_vma_addr(" in ", regs->ip);
19836 pr_cont("\n");
19837@@ -164,8 +158,20 @@ kernel_trap:
19838 if (!fixup_exception(regs)) {
19839 tsk->thread.error_code = error_code;
19840 tsk->thread.trap_nr = trapnr;
19841+
19842+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
19843+ if (trapnr == 12 && ((regs->cs & 0xFFFF) == __KERNEL_CS || (regs->cs & 0xFFFF) == __KERNEXEC_KERNEL_CS))
19844+ str = "PAX: suspicious stack segment fault";
19845+#endif
19846+
19847 die(str, regs, error_code);
19848 }
19849+
19850+#ifdef CONFIG_PAX_REFCOUNT
19851+ if (trapnr == 4)
19852+ pax_report_refcount_overflow(regs);
19853+#endif
19854+
19855 return;
19856
19857 #ifdef CONFIG_X86_32
19858@@ -258,14 +264,30 @@ do_general_protection(struct pt_regs *regs, long error_code)
19859 conditional_sti(regs);
19860
19861 #ifdef CONFIG_X86_32
19862- if (regs->flags & X86_VM_MASK)
19863+ if (v8086_mode(regs))
19864 goto gp_in_vm86;
19865 #endif
19866
19867 tsk = current;
19868- if (!user_mode(regs))
19869+ if (!user_mode_novm(regs))
19870 goto gp_in_kernel;
19871
19872+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
19873+ if (!(__supported_pte_mask & _PAGE_NX) && tsk->mm && (tsk->mm->pax_flags & MF_PAX_PAGEEXEC)) {
19874+ struct mm_struct *mm = tsk->mm;
19875+ unsigned long limit;
19876+
19877+ down_write(&mm->mmap_sem);
19878+ limit = mm->context.user_cs_limit;
19879+ if (limit < TASK_SIZE) {
19880+ track_exec_limit(mm, limit, TASK_SIZE, VM_EXEC);
19881+ up_write(&mm->mmap_sem);
19882+ return;
19883+ }
19884+ up_write(&mm->mmap_sem);
19885+ }
19886+#endif
19887+
19888 tsk->thread.error_code = error_code;
19889 tsk->thread.trap_nr = X86_TRAP_GP;
19890
19891@@ -297,6 +319,13 @@ gp_in_kernel:
19892 if (notify_die(DIE_GPF, "general protection fault", regs, error_code,
19893 X86_TRAP_GP, SIGSEGV) == NOTIFY_STOP)
19894 return;
19895+
19896+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
19897+ if ((regs->cs & 0xFFFF) == __KERNEL_CS || (regs->cs & 0xFFFF) == __KERNEXEC_KERNEL_CS)
19898+ die("PAX: suspicious general protection fault", regs, error_code);
19899+ else
19900+#endif
19901+
19902 die("general protection fault", regs, error_code);
19903 }
19904
19905@@ -432,7 +461,7 @@ dotraplinkage void __kprobes do_debug(struct pt_regs *regs, long error_code)
19906 /* It's safe to allow irq's after DR6 has been saved */
19907 preempt_conditional_sti(regs);
19908
19909- if (regs->flags & X86_VM_MASK) {
19910+ if (v8086_mode(regs)) {
19911 handle_vm86_trap((struct kernel_vm86_regs *) regs, error_code,
19912 X86_TRAP_DB);
19913 preempt_conditional_cli(regs);
19914@@ -447,7 +476,7 @@ dotraplinkage void __kprobes do_debug(struct pt_regs *regs, long error_code)
19915 * We already checked v86 mode above, so we can check for kernel mode
19916 * by just checking the CPL of CS.
19917 */
19918- if ((dr6 & DR_STEP) && !user_mode(regs)) {
19919+ if ((dr6 & DR_STEP) && !user_mode_novm(regs)) {
19920 tsk->thread.debugreg6 &= ~DR_STEP;
19921 set_tsk_thread_flag(tsk, TIF_SINGLESTEP);
19922 regs->flags &= ~X86_EFLAGS_TF;
19923@@ -478,7 +507,7 @@ void math_error(struct pt_regs *regs, int error_code, int trapnr)
19924 return;
19925 conditional_sti(regs);
19926
19927- if (!user_mode_vm(regs))
19928+ if (!user_mode(regs))
19929 {
19930 if (!fixup_exception(regs)) {
19931 task->thread.error_code = error_code;
19932diff --git a/arch/x86/kernel/uprobes.c b/arch/x86/kernel/uprobes.c
19933index 36fd420..7e5892d 100644
19934--- a/arch/x86/kernel/uprobes.c
19935+++ b/arch/x86/kernel/uprobes.c
19936@@ -607,7 +607,7 @@ int arch_uprobe_exception_notify(struct notifier_block *self, unsigned long val,
19937 int ret = NOTIFY_DONE;
19938
19939 /* We are only interested in userspace traps */
19940- if (regs && !user_mode_vm(regs))
19941+ if (regs && !user_mode(regs))
19942 return NOTIFY_DONE;
19943
19944 switch (val) {
19945diff --git a/arch/x86/kernel/verify_cpu.S b/arch/x86/kernel/verify_cpu.S
19946index b9242ba..50c5edd 100644
19947--- a/arch/x86/kernel/verify_cpu.S
19948+++ b/arch/x86/kernel/verify_cpu.S
19949@@ -20,6 +20,7 @@
19950 * arch/x86/boot/compressed/head_64.S: Boot cpu verification
19951 * arch/x86/kernel/trampoline_64.S: secondary processor verification
19952 * arch/x86/kernel/head_32.S: processor startup
19953+ * arch/x86/kernel/acpi/realmode/wakeup.S: 32bit processor resume
19954 *
19955 * verify_cpu, returns the status of longmode and SSE in register %eax.
19956 * 0: Success 1: Failure
19957diff --git a/arch/x86/kernel/vm86_32.c b/arch/x86/kernel/vm86_32.c
19958index 54abcc0..eb6c848 100644
19959--- a/arch/x86/kernel/vm86_32.c
19960+++ b/arch/x86/kernel/vm86_32.c
19961@@ -43,6 +43,7 @@
19962 #include <linux/ptrace.h>
19963 #include <linux/audit.h>
19964 #include <linux/stddef.h>
19965+#include <linux/grsecurity.h>
19966
19967 #include <asm/uaccess.h>
19968 #include <asm/io.h>
19969@@ -150,7 +151,7 @@ struct pt_regs *save_v86_state(struct kernel_vm86_regs *regs)
19970 do_exit(SIGSEGV);
19971 }
19972
19973- tss = &per_cpu(init_tss, get_cpu());
19974+ tss = init_tss + get_cpu();
19975 current->thread.sp0 = current->thread.saved_sp0;
19976 current->thread.sysenter_cs = __KERNEL_CS;
19977 load_sp0(tss, &current->thread);
19978@@ -212,6 +213,13 @@ int sys_vm86old(struct vm86_struct __user *v86, struct pt_regs *regs)
19979 struct task_struct *tsk;
19980 int tmp, ret = -EPERM;
19981
19982+#ifdef CONFIG_GRKERNSEC_VM86
19983+ if (!capable(CAP_SYS_RAWIO)) {
19984+ gr_handle_vm86();
19985+ goto out;
19986+ }
19987+#endif
19988+
19989 tsk = current;
19990 if (tsk->thread.saved_sp0)
19991 goto out;
19992@@ -242,6 +250,14 @@ int sys_vm86(unsigned long cmd, unsigned long arg, struct pt_regs *regs)
19993 int tmp, ret;
19994 struct vm86plus_struct __user *v86;
19995
19996+#ifdef CONFIG_GRKERNSEC_VM86
19997+ if (!capable(CAP_SYS_RAWIO)) {
19998+ gr_handle_vm86();
19999+ ret = -EPERM;
20000+ goto out;
20001+ }
20002+#endif
20003+
20004 tsk = current;
20005 switch (cmd) {
20006 case VM86_REQUEST_IRQ:
20007@@ -328,7 +344,7 @@ static void do_sys_vm86(struct kernel_vm86_struct *info, struct task_struct *tsk
20008 tsk->thread.saved_fs = info->regs32->fs;
20009 tsk->thread.saved_gs = get_user_gs(info->regs32);
20010
20011- tss = &per_cpu(init_tss, get_cpu());
20012+ tss = init_tss + get_cpu();
20013 tsk->thread.sp0 = (unsigned long) &info->VM86_TSS_ESP0;
20014 if (cpu_has_sep)
20015 tsk->thread.sysenter_cs = 0;
20016@@ -535,7 +551,7 @@ static void do_int(struct kernel_vm86_regs *regs, int i,
20017 goto cannot_handle;
20018 if (i == 0x21 && is_revectored(AH(regs), &KVM86->int21_revectored))
20019 goto cannot_handle;
20020- intr_ptr = (unsigned long __user *) (i << 2);
20021+ intr_ptr = (__force unsigned long __user *) (i << 2);
20022 if (get_user(segoffs, intr_ptr))
20023 goto cannot_handle;
20024 if ((segoffs >> 16) == BIOSSEG)
20025diff --git a/arch/x86/kernel/vmlinux.lds.S b/arch/x86/kernel/vmlinux.lds.S
20026index 22a1530..8fbaaad 100644
20027--- a/arch/x86/kernel/vmlinux.lds.S
20028+++ b/arch/x86/kernel/vmlinux.lds.S
20029@@ -26,6 +26,13 @@
20030 #include <asm/page_types.h>
20031 #include <asm/cache.h>
20032 #include <asm/boot.h>
20033+#include <asm/segment.h>
20034+
20035+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
20036+#define __KERNEL_TEXT_OFFSET (LOAD_OFFSET + ____LOAD_PHYSICAL_ADDR)
20037+#else
20038+#define __KERNEL_TEXT_OFFSET 0
20039+#endif
20040
20041 #undef i386 /* in case the preprocessor is a 32bit one */
20042
20043@@ -69,30 +76,43 @@ jiffies_64 = jiffies;
20044
20045 PHDRS {
20046 text PT_LOAD FLAGS(5); /* R_E */
20047+#ifdef CONFIG_X86_32
20048+ module PT_LOAD FLAGS(5); /* R_E */
20049+#endif
20050+#ifdef CONFIG_XEN
20051+ rodata PT_LOAD FLAGS(5); /* R_E */
20052+#else
20053+ rodata PT_LOAD FLAGS(4); /* R__ */
20054+#endif
20055 data PT_LOAD FLAGS(6); /* RW_ */
20056-#ifdef CONFIG_X86_64
20057+ init.begin PT_LOAD FLAGS(6); /* RW_ */
20058 #ifdef CONFIG_SMP
20059 percpu PT_LOAD FLAGS(6); /* RW_ */
20060 #endif
20061+ text.init PT_LOAD FLAGS(5); /* R_E */
20062+ text.exit PT_LOAD FLAGS(5); /* R_E */
20063 init PT_LOAD FLAGS(7); /* RWE */
20064-#endif
20065 note PT_NOTE FLAGS(0); /* ___ */
20066 }
20067
20068 SECTIONS
20069 {
20070 #ifdef CONFIG_X86_32
20071- . = LOAD_OFFSET + LOAD_PHYSICAL_ADDR;
20072- phys_startup_32 = startup_32 - LOAD_OFFSET;
20073+ . = LOAD_OFFSET + ____LOAD_PHYSICAL_ADDR;
20074 #else
20075- . = __START_KERNEL;
20076- phys_startup_64 = startup_64 - LOAD_OFFSET;
20077+ . = __START_KERNEL;
20078 #endif
20079
20080 /* Text and read-only data */
20081- .text : AT(ADDR(.text) - LOAD_OFFSET) {
20082- _text = .;
20083+ .text (. - __KERNEL_TEXT_OFFSET): AT(ADDR(.text) - LOAD_OFFSET + __KERNEL_TEXT_OFFSET) {
20084 /* bootstrapping code */
20085+#ifdef CONFIG_X86_32
20086+ phys_startup_32 = startup_32 - LOAD_OFFSET + __KERNEL_TEXT_OFFSET;
20087+#else
20088+ phys_startup_64 = startup_64 - LOAD_OFFSET + __KERNEL_TEXT_OFFSET;
20089+#endif
20090+ __LOAD_PHYSICAL_ADDR = . - LOAD_OFFSET + __KERNEL_TEXT_OFFSET;
20091+ _text = .;
20092 HEAD_TEXT
20093 #ifdef CONFIG_X86_32
20094 . = ALIGN(PAGE_SIZE);
20095@@ -108,13 +128,48 @@ SECTIONS
20096 IRQENTRY_TEXT
20097 *(.fixup)
20098 *(.gnu.warning)
20099- /* End of text section */
20100- _etext = .;
20101 } :text = 0x9090
20102
20103- NOTES :text :note
20104+ . += __KERNEL_TEXT_OFFSET;
20105
20106- EXCEPTION_TABLE(16) :text = 0x9090
20107+#ifdef CONFIG_X86_32
20108+ . = ALIGN(PAGE_SIZE);
20109+ .module.text : AT(ADDR(.module.text) - LOAD_OFFSET) {
20110+
20111+#if defined(CONFIG_PAX_KERNEXEC) && defined(CONFIG_MODULES)
20112+ MODULES_EXEC_VADDR = .;
20113+ BYTE(0)
20114+ . += (CONFIG_PAX_KERNEXEC_MODULE_TEXT * 1024 * 1024);
20115+ . = ALIGN(HPAGE_SIZE) - 1;
20116+ MODULES_EXEC_END = .;
20117+#endif
20118+
20119+ } :module
20120+#endif
20121+
20122+ .text.end : AT(ADDR(.text.end) - LOAD_OFFSET) {
20123+ /* End of text section */
20124+ BYTE(0)
20125+ _etext = . - __KERNEL_TEXT_OFFSET;
20126+ }
20127+
20128+#ifdef CONFIG_X86_32
20129+ . = ALIGN(PAGE_SIZE);
20130+ .rodata.page_aligned : AT(ADDR(.rodata.page_aligned) - LOAD_OFFSET) {
20131+ *(.idt)
20132+ . = ALIGN(PAGE_SIZE);
20133+ *(.empty_zero_page)
20134+ *(.initial_pg_fixmap)
20135+ *(.initial_pg_pmd)
20136+ *(.initial_page_table)
20137+ *(.swapper_pg_dir)
20138+ } :rodata
20139+#endif
20140+
20141+ . = ALIGN(PAGE_SIZE);
20142+ NOTES :rodata :note
20143+
20144+ EXCEPTION_TABLE(16) :rodata
20145
20146 #if defined(CONFIG_DEBUG_RODATA)
20147 /* .text should occupy whole number of pages */
20148@@ -126,16 +181,20 @@ SECTIONS
20149
20150 /* Data */
20151 .data : AT(ADDR(.data) - LOAD_OFFSET) {
20152+
20153+#ifdef CONFIG_PAX_KERNEXEC
20154+ . = ALIGN(HPAGE_SIZE);
20155+#else
20156+ . = ALIGN(PAGE_SIZE);
20157+#endif
20158+
20159 /* Start of data section */
20160 _sdata = .;
20161
20162 /* init_task */
20163 INIT_TASK_DATA(THREAD_SIZE)
20164
20165-#ifdef CONFIG_X86_32
20166- /* 32 bit has nosave before _edata */
20167 NOSAVE_DATA
20168-#endif
20169
20170 PAGE_ALIGNED_DATA(PAGE_SIZE)
20171
20172@@ -176,12 +235,19 @@ SECTIONS
20173 #endif /* CONFIG_X86_64 */
20174
20175 /* Init code and data - will be freed after init */
20176- . = ALIGN(PAGE_SIZE);
20177 .init.begin : AT(ADDR(.init.begin) - LOAD_OFFSET) {
20178+ BYTE(0)
20179+
20180+#ifdef CONFIG_PAX_KERNEXEC
20181+ . = ALIGN(HPAGE_SIZE);
20182+#else
20183+ . = ALIGN(PAGE_SIZE);
20184+#endif
20185+
20186 __init_begin = .; /* paired with __init_end */
20187- }
20188+ } :init.begin
20189
20190-#if defined(CONFIG_X86_64) && defined(CONFIG_SMP)
20191+#ifdef CONFIG_SMP
20192 /*
20193 * percpu offsets are zero-based on SMP. PERCPU_VADDR() changes the
20194 * output PHDR, so the next output section - .init.text - should
20195@@ -190,12 +256,27 @@ SECTIONS
20196 PERCPU_VADDR(INTERNODE_CACHE_BYTES, 0, :percpu)
20197 #endif
20198
20199- INIT_TEXT_SECTION(PAGE_SIZE)
20200-#ifdef CONFIG_X86_64
20201- :init
20202-#endif
20203+ . = ALIGN(PAGE_SIZE);
20204+ init_begin = .;
20205+ .init.text (. - __KERNEL_TEXT_OFFSET): AT(init_begin - LOAD_OFFSET) {
20206+ VMLINUX_SYMBOL(_sinittext) = .;
20207+ INIT_TEXT
20208+ VMLINUX_SYMBOL(_einittext) = .;
20209+ . = ALIGN(PAGE_SIZE);
20210+ } :text.init
20211
20212- INIT_DATA_SECTION(16)
20213+ /*
20214+ * .exit.text is discard at runtime, not link time, to deal with
20215+ * references from .altinstructions and .eh_frame
20216+ */
20217+ .exit.text : AT(ADDR(.exit.text) - LOAD_OFFSET + __KERNEL_TEXT_OFFSET) {
20218+ EXIT_TEXT
20219+ . = ALIGN(16);
20220+ } :text.exit
20221+ . = init_begin + SIZEOF(.init.text) + SIZEOF(.exit.text);
20222+
20223+ . = ALIGN(PAGE_SIZE);
20224+ INIT_DATA_SECTION(16) :init
20225
20226 .x86_cpu_dev.init : AT(ADDR(.x86_cpu_dev.init) - LOAD_OFFSET) {
20227 __x86_cpu_dev_start = .;
20228@@ -257,19 +338,12 @@ SECTIONS
20229 }
20230
20231 . = ALIGN(8);
20232- /*
20233- * .exit.text is discard at runtime, not link time, to deal with
20234- * references from .altinstructions and .eh_frame
20235- */
20236- .exit.text : AT(ADDR(.exit.text) - LOAD_OFFSET) {
20237- EXIT_TEXT
20238- }
20239
20240 .exit.data : AT(ADDR(.exit.data) - LOAD_OFFSET) {
20241 EXIT_DATA
20242 }
20243
20244-#if !defined(CONFIG_X86_64) || !defined(CONFIG_SMP)
20245+#ifndef CONFIG_SMP
20246 PERCPU_SECTION(INTERNODE_CACHE_BYTES)
20247 #endif
20248
20249@@ -288,16 +362,10 @@ SECTIONS
20250 .smp_locks : AT(ADDR(.smp_locks) - LOAD_OFFSET) {
20251 __smp_locks = .;
20252 *(.smp_locks)
20253- . = ALIGN(PAGE_SIZE);
20254 __smp_locks_end = .;
20255+ . = ALIGN(PAGE_SIZE);
20256 }
20257
20258-#ifdef CONFIG_X86_64
20259- .data_nosave : AT(ADDR(.data_nosave) - LOAD_OFFSET) {
20260- NOSAVE_DATA
20261- }
20262-#endif
20263-
20264 /* BSS */
20265 . = ALIGN(PAGE_SIZE);
20266 .bss : AT(ADDR(.bss) - LOAD_OFFSET) {
20267@@ -313,6 +381,7 @@ SECTIONS
20268 __brk_base = .;
20269 . += 64 * 1024; /* 64k alignment slop space */
20270 *(.brk_reservation) /* areas brk users have reserved */
20271+ . = ALIGN(HPAGE_SIZE);
20272 __brk_limit = .;
20273 }
20274
20275@@ -339,13 +408,12 @@ SECTIONS
20276 * for the boot processor.
20277 */
20278 #define INIT_PER_CPU(x) init_per_cpu__##x = x + __per_cpu_load
20279-INIT_PER_CPU(gdt_page);
20280 INIT_PER_CPU(irq_stack_union);
20281
20282 /*
20283 * Build-time check on the image size:
20284 */
20285-. = ASSERT((_end - _text <= KERNEL_IMAGE_SIZE),
20286+. = ASSERT((_end - _text - __KERNEL_TEXT_OFFSET <= KERNEL_IMAGE_SIZE),
20287 "kernel image bigger than KERNEL_IMAGE_SIZE");
20288
20289 #ifdef CONFIG_SMP
20290diff --git a/arch/x86/kernel/vsmp_64.c b/arch/x86/kernel/vsmp_64.c
20291index 992f890..fc38904 100644
20292--- a/arch/x86/kernel/vsmp_64.c
20293+++ b/arch/x86/kernel/vsmp_64.c
20294@@ -217,8 +217,8 @@ static void fill_vector_allocation_domain(int cpu, struct cpumask *retmask,
20295 static void vsmp_apic_post_init(void)
20296 {
20297 /* need to update phys_pkg_id */
20298- apic->phys_pkg_id = apicid_phys_pkg_id;
20299- apic->vector_allocation_domain = fill_vector_allocation_domain;
20300+ *(void **)&apic->phys_pkg_id = apicid_phys_pkg_id;
20301+ *(void **)&apic->vector_allocation_domain = fill_vector_allocation_domain;
20302 }
20303
20304 void __init vsmp_init(void)
20305diff --git a/arch/x86/kernel/vsyscall_64.c b/arch/x86/kernel/vsyscall_64.c
20306index 8d141b3..40a0fe4 100644
20307--- a/arch/x86/kernel/vsyscall_64.c
20308+++ b/arch/x86/kernel/vsyscall_64.c
20309@@ -56,15 +56,13 @@
20310 DEFINE_VVAR(int, vgetcpu_mode);
20311 DEFINE_VVAR(struct vsyscall_gtod_data, vsyscall_gtod_data);
20312
20313-static enum { EMULATE, NATIVE, NONE } vsyscall_mode = EMULATE;
20314+static enum { EMULATE, NONE } vsyscall_mode = EMULATE;
20315
20316 static int __init vsyscall_setup(char *str)
20317 {
20318 if (str) {
20319 if (!strcmp("emulate", str))
20320 vsyscall_mode = EMULATE;
20321- else if (!strcmp("native", str))
20322- vsyscall_mode = NATIVE;
20323 else if (!strcmp("none", str))
20324 vsyscall_mode = NONE;
20325 else
20326@@ -306,8 +304,7 @@ done:
20327 return true;
20328
20329 sigsegv:
20330- force_sig(SIGSEGV, current);
20331- return true;
20332+ do_group_exit(SIGKILL);
20333 }
20334
20335 /*
20336@@ -360,10 +357,7 @@ void __init map_vsyscall(void)
20337 extern char __vvar_page;
20338 unsigned long physaddr_vvar_page = __pa_symbol(&__vvar_page);
20339
20340- __set_fixmap(VSYSCALL_FIRST_PAGE, physaddr_vsyscall,
20341- vsyscall_mode == NATIVE
20342- ? PAGE_KERNEL_VSYSCALL
20343- : PAGE_KERNEL_VVAR);
20344+ __set_fixmap(VSYSCALL_FIRST_PAGE, physaddr_vsyscall, PAGE_KERNEL_VVAR);
20345 BUILD_BUG_ON((unsigned long)__fix_to_virt(VSYSCALL_FIRST_PAGE) !=
20346 (unsigned long)VSYSCALL_START);
20347
20348diff --git a/arch/x86/kernel/x8664_ksyms_64.c b/arch/x86/kernel/x8664_ksyms_64.c
20349index 6020f6f..bedd6e3 100644
20350--- a/arch/x86/kernel/x8664_ksyms_64.c
20351+++ b/arch/x86/kernel/x8664_ksyms_64.c
20352@@ -30,8 +30,6 @@ EXPORT_SYMBOL(copy_user_generic_string);
20353 EXPORT_SYMBOL(copy_user_generic_unrolled);
20354 EXPORT_SYMBOL(copy_user_enhanced_fast_string);
20355 EXPORT_SYMBOL(__copy_user_nocache);
20356-EXPORT_SYMBOL(_copy_from_user);
20357-EXPORT_SYMBOL(_copy_to_user);
20358
20359 EXPORT_SYMBOL(copy_page);
20360 EXPORT_SYMBOL(clear_page);
20361diff --git a/arch/x86/kernel/xsave.c b/arch/x86/kernel/xsave.c
20362index 3d3e207..1a73ab2 100644
20363--- a/arch/x86/kernel/xsave.c
20364+++ b/arch/x86/kernel/xsave.c
20365@@ -132,7 +132,7 @@ int check_for_xstate(struct i387_fxsave_struct __user *buf,
20366 fx_sw_user->xstate_size > fx_sw_user->extended_size)
20367 return -EINVAL;
20368
20369- err = __get_user(magic2, (__u32 *) (((void *)fpstate) +
20370+ err = __get_user(magic2, (__u32 __user *) (((void __user *)fpstate) +
20371 fx_sw_user->extended_size -
20372 FP_XSTATE_MAGIC2_SIZE));
20373 if (err)
20374@@ -268,7 +268,7 @@ fx_only:
20375 * the other extended state.
20376 */
20377 xrstor_state(init_xstate_buf, pcntxt_mask & ~XSTATE_FPSSE);
20378- return fxrstor_checking((__force struct i387_fxsave_struct *)buf);
20379+ return fxrstor_checking((struct i387_fxsave_struct __force_kernel *)buf);
20380 }
20381
20382 /*
20383@@ -297,7 +297,7 @@ int restore_i387_xstate(void __user *buf)
20384 if (use_xsave())
20385 err = restore_user_xstate(buf);
20386 else
20387- err = fxrstor_checking((__force struct i387_fxsave_struct *)
20388+ err = fxrstor_checking((struct i387_fxsave_struct __force_kernel *)
20389 buf);
20390 if (unlikely(err)) {
20391 /*
20392diff --git a/arch/x86/kvm/cpuid.c b/arch/x86/kvm/cpuid.c
20393index 0595f13..b544fa3 100644
20394--- a/arch/x86/kvm/cpuid.c
20395+++ b/arch/x86/kvm/cpuid.c
20396@@ -124,15 +124,20 @@ int kvm_vcpu_ioctl_set_cpuid2(struct kvm_vcpu *vcpu,
20397 struct kvm_cpuid2 *cpuid,
20398 struct kvm_cpuid_entry2 __user *entries)
20399 {
20400- int r;
20401+ int r, i;
20402
20403 r = -E2BIG;
20404 if (cpuid->nent > KVM_MAX_CPUID_ENTRIES)
20405 goto out;
20406 r = -EFAULT;
20407- if (copy_from_user(&vcpu->arch.cpuid_entries, entries,
20408- cpuid->nent * sizeof(struct kvm_cpuid_entry2)))
20409+ if (!access_ok(VERIFY_READ, entries, cpuid->nent * sizeof(struct kvm_cpuid_entry2)))
20410 goto out;
20411+ for (i = 0; i < cpuid->nent; ++i) {
20412+ struct kvm_cpuid_entry2 cpuid_entry;
20413+ if (__copy_from_user(&cpuid_entry, entries + i, sizeof(cpuid_entry)))
20414+ goto out;
20415+ vcpu->arch.cpuid_entries[i] = cpuid_entry;
20416+ }
20417 vcpu->arch.cpuid_nent = cpuid->nent;
20418 kvm_apic_set_version(vcpu);
20419 kvm_x86_ops->cpuid_update(vcpu);
20420@@ -147,15 +152,19 @@ int kvm_vcpu_ioctl_get_cpuid2(struct kvm_vcpu *vcpu,
20421 struct kvm_cpuid2 *cpuid,
20422 struct kvm_cpuid_entry2 __user *entries)
20423 {
20424- int r;
20425+ int r, i;
20426
20427 r = -E2BIG;
20428 if (cpuid->nent < vcpu->arch.cpuid_nent)
20429 goto out;
20430 r = -EFAULT;
20431- if (copy_to_user(entries, &vcpu->arch.cpuid_entries,
20432- vcpu->arch.cpuid_nent * sizeof(struct kvm_cpuid_entry2)))
20433+ if (!access_ok(VERIFY_WRITE, entries, vcpu->arch.cpuid_nent * sizeof(struct kvm_cpuid_entry2)))
20434 goto out;
20435+ for (i = 0; i < vcpu->arch.cpuid_nent; ++i) {
20436+ struct kvm_cpuid_entry2 cpuid_entry = vcpu->arch.cpuid_entries[i];
20437+ if (__copy_to_user(entries + i, &cpuid_entry, sizeof(cpuid_entry)))
20438+ goto out;
20439+ }
20440 return 0;
20441
20442 out:
20443diff --git a/arch/x86/kvm/cpuid.h b/arch/x86/kvm/cpuid.h
20444index a10e460..58fc514 100644
20445--- a/arch/x86/kvm/cpuid.h
20446+++ b/arch/x86/kvm/cpuid.h
20447@@ -24,6 +24,9 @@ static inline bool guest_cpuid_has_xsave(struct kvm_vcpu *vcpu)
20448 {
20449 struct kvm_cpuid_entry2 *best;
20450
20451+ if (!static_cpu_has(X86_FEATURE_XSAVE))
20452+ return 0;
20453+
20454 best = kvm_find_cpuid_entry(vcpu, 1, 0);
20455 return best && (best->ecx & bit(X86_FEATURE_XSAVE));
20456 }
20457diff --git a/arch/x86/kvm/emulate.c b/arch/x86/kvm/emulate.c
20458index a3b57a2..ebbe732 100644
20459--- a/arch/x86/kvm/emulate.c
20460+++ b/arch/x86/kvm/emulate.c
20461@@ -256,6 +256,7 @@ struct gprefix {
20462
20463 #define ____emulate_2op(ctxt, _op, _x, _y, _suffix, _dsttype) \
20464 do { \
20465+ unsigned long _tmp; \
20466 __asm__ __volatile__ ( \
20467 _PRE_EFLAGS("0", "4", "2") \
20468 _op _suffix " %"_x"3,%1; " \
20469@@ -270,8 +271,6 @@ struct gprefix {
20470 /* Raw emulation: instruction has two explicit operands. */
20471 #define __emulate_2op_nobyte(ctxt,_op,_wx,_wy,_lx,_ly,_qx,_qy) \
20472 do { \
20473- unsigned long _tmp; \
20474- \
20475 switch ((ctxt)->dst.bytes) { \
20476 case 2: \
20477 ____emulate_2op(ctxt,_op,_wx,_wy,"w",u16); \
20478@@ -287,7 +286,6 @@ struct gprefix {
20479
20480 #define __emulate_2op(ctxt,_op,_bx,_by,_wx,_wy,_lx,_ly,_qx,_qy) \
20481 do { \
20482- unsigned long _tmp; \
20483 switch ((ctxt)->dst.bytes) { \
20484 case 1: \
20485 ____emulate_2op(ctxt,_op,_bx,_by,"b",u8); \
20486diff --git a/arch/x86/kvm/lapic.c b/arch/x86/kvm/lapic.c
20487index ce87878..ab48aa3 100644
20488--- a/arch/x86/kvm/lapic.c
20489+++ b/arch/x86/kvm/lapic.c
20490@@ -54,7 +54,7 @@
20491 #define APIC_BUS_CYCLE_NS 1
20492
20493 /* #define apic_debug(fmt,arg...) printk(KERN_WARNING fmt,##arg) */
20494-#define apic_debug(fmt, arg...)
20495+#define apic_debug(fmt, arg...) do {} while (0)
20496
20497 #define APIC_LVT_NUM 6
20498 /* 14 is the version for Xeon and Pentium 8.4.8*/
20499diff --git a/arch/x86/kvm/paging_tmpl.h b/arch/x86/kvm/paging_tmpl.h
20500index bb7cf01..0348a05 100644
20501--- a/arch/x86/kvm/paging_tmpl.h
20502+++ b/arch/x86/kvm/paging_tmpl.h
20503@@ -196,7 +196,7 @@ retry_walk:
20504 if (unlikely(kvm_is_error_hva(host_addr)))
20505 goto error;
20506
20507- ptep_user = (pt_element_t __user *)((void *)host_addr + offset);
20508+ ptep_user = (pt_element_t __force_user *)((void *)host_addr + offset);
20509 if (unlikely(__copy_from_user(&pte, ptep_user, sizeof(pte))))
20510 goto error;
20511
20512diff --git a/arch/x86/kvm/svm.c b/arch/x86/kvm/svm.c
20513index baead95..90feeb4 100644
20514--- a/arch/x86/kvm/svm.c
20515+++ b/arch/x86/kvm/svm.c
20516@@ -3516,7 +3516,11 @@ static void reload_tss(struct kvm_vcpu *vcpu)
20517 int cpu = raw_smp_processor_id();
20518
20519 struct svm_cpu_data *sd = per_cpu(svm_data, cpu);
20520+
20521+ pax_open_kernel();
20522 sd->tss_desc->type = 9; /* available 32/64-bit TSS */
20523+ pax_close_kernel();
20524+
20525 load_TR_desc();
20526 }
20527
20528@@ -3894,6 +3898,10 @@ static void svm_vcpu_run(struct kvm_vcpu *vcpu)
20529 #endif
20530 #endif
20531
20532+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
20533+ __set_fs(current_thread_info()->addr_limit);
20534+#endif
20535+
20536 reload_tss(vcpu);
20537
20538 local_irq_disable();
20539diff --git a/arch/x86/kvm/vmx.c b/arch/x86/kvm/vmx.c
20540index b1eb202..254e292 100644
20541--- a/arch/x86/kvm/vmx.c
20542+++ b/arch/x86/kvm/vmx.c
20543@@ -1331,7 +1331,11 @@ static void reload_tss(void)
20544 struct desc_struct *descs;
20545
20546 descs = (void *)gdt->address;
20547+
20548+ pax_open_kernel();
20549 descs[GDT_ENTRY_TSS].type = 9; /* available TSS */
20550+ pax_close_kernel();
20551+
20552 load_TR_desc();
20553 }
20554
20555@@ -1541,6 +1545,10 @@ static void vmx_vcpu_load(struct kvm_vcpu *vcpu, int cpu)
20556 vmcs_writel(HOST_TR_BASE, kvm_read_tr_base()); /* 22.2.4 */
20557 vmcs_writel(HOST_GDTR_BASE, gdt->address); /* 22.2.4 */
20558
20559+#ifdef CONFIG_PAX_PER_CPU_PGD
20560+ vmcs_writel(HOST_CR3, read_cr3()); /* 22.2.3 FIXME: shadow tables */
20561+#endif
20562+
20563 rdmsrl(MSR_IA32_SYSENTER_ESP, sysenter_esp);
20564 vmcs_writel(HOST_IA32_SYSENTER_ESP, sysenter_esp); /* 22.2.3 */
20565 vmx->loaded_vmcs->cpu = cpu;
20566@@ -2674,8 +2682,11 @@ static __init int hardware_setup(void)
20567 if (!cpu_has_vmx_flexpriority())
20568 flexpriority_enabled = 0;
20569
20570- if (!cpu_has_vmx_tpr_shadow())
20571- kvm_x86_ops->update_cr8_intercept = NULL;
20572+ if (!cpu_has_vmx_tpr_shadow()) {
20573+ pax_open_kernel();
20574+ *(void **)&kvm_x86_ops->update_cr8_intercept = NULL;
20575+ pax_close_kernel();
20576+ }
20577
20578 if (enable_ept && !cpu_has_vmx_ept_2m_page())
20579 kvm_disable_largepages();
20580@@ -3745,7 +3756,10 @@ static void vmx_set_constant_host_state(void)
20581
20582 vmcs_writel(HOST_CR0, read_cr0() | X86_CR0_TS); /* 22.2.3 */
20583 vmcs_writel(HOST_CR4, read_cr4()); /* 22.2.3, 22.2.5 */
20584+
20585+#ifndef CONFIG_PAX_PER_CPU_PGD
20586 vmcs_writel(HOST_CR3, read_cr3()); /* 22.2.3 FIXME: shadow tables */
20587+#endif
20588
20589 vmcs_write16(HOST_CS_SELECTOR, __KERNEL_CS); /* 22.2.4 */
20590 #ifdef CONFIG_X86_64
20591@@ -3767,7 +3781,7 @@ static void vmx_set_constant_host_state(void)
20592 vmcs_writel(HOST_IDTR_BASE, dt.address); /* 22.2.4 */
20593
20594 asm("mov $.Lkvm_vmx_return, %0" : "=r"(tmpl));
20595- vmcs_writel(HOST_RIP, tmpl); /* 22.2.5 */
20596+ vmcs_writel(HOST_RIP, ktla_ktva(tmpl)); /* 22.2.5 */
20597
20598 rdmsr(MSR_IA32_SYSENTER_CS, low32, high32);
20599 vmcs_write32(HOST_IA32_SYSENTER_CS, low32);
20600@@ -6321,6 +6335,12 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
20601 "jmp .Lkvm_vmx_return \n\t"
20602 ".Llaunched: " __ex(ASM_VMX_VMRESUME) "\n\t"
20603 ".Lkvm_vmx_return: "
20604+
20605+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
20606+ "ljmp %[cs],$.Lkvm_vmx_return2\n\t"
20607+ ".Lkvm_vmx_return2: "
20608+#endif
20609+
20610 /* Save guest registers, load host registers, keep flags */
20611 "mov %0, %c[wordsize](%%"R"sp) \n\t"
20612 "pop %0 \n\t"
20613@@ -6369,6 +6389,11 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
20614 #endif
20615 [cr2]"i"(offsetof(struct vcpu_vmx, vcpu.arch.cr2)),
20616 [wordsize]"i"(sizeof(ulong))
20617+
20618+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
20619+ ,[cs]"i"(__KERNEL_CS)
20620+#endif
20621+
20622 : "cc", "memory"
20623 , R"ax", R"bx", R"di", R"si"
20624 #ifdef CONFIG_X86_64
20625@@ -6376,7 +6401,7 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
20626 #endif
20627 );
20628
20629-#ifndef CONFIG_X86_64
20630+#ifdef CONFIG_X86_32
20631 /*
20632 * The sysexit path does not restore ds/es, so we must set them to
20633 * a reasonable value ourselves.
20634@@ -6385,8 +6410,18 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
20635 * may be executed in interrupt context, which saves and restore segments
20636 * around it, nullifying its effect.
20637 */
20638- loadsegment(ds, __USER_DS);
20639- loadsegment(es, __USER_DS);
20640+ loadsegment(ds, __KERNEL_DS);
20641+ loadsegment(es, __KERNEL_DS);
20642+ loadsegment(ss, __KERNEL_DS);
20643+
20644+#ifdef CONFIG_PAX_KERNEXEC
20645+ loadsegment(fs, __KERNEL_PERCPU);
20646+#endif
20647+
20648+#ifdef CONFIG_PAX_MEMORY_UDEREF
20649+ __set_fs(current_thread_info()->addr_limit);
20650+#endif
20651+
20652 #endif
20653
20654 vcpu->arch.regs_avail = ~((1 << VCPU_REGS_RIP) | (1 << VCPU_REGS_RSP)
20655diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
20656index 2966c84..9ac0c3c 100644
20657--- a/arch/x86/kvm/x86.c
20658+++ b/arch/x86/kvm/x86.c
20659@@ -1379,8 +1379,8 @@ static int xen_hvm_config(struct kvm_vcpu *vcpu, u64 data)
20660 {
20661 struct kvm *kvm = vcpu->kvm;
20662 int lm = is_long_mode(vcpu);
20663- u8 *blob_addr = lm ? (u8 *)(long)kvm->arch.xen_hvm_config.blob_addr_64
20664- : (u8 *)(long)kvm->arch.xen_hvm_config.blob_addr_32;
20665+ u8 __user *blob_addr = lm ? (u8 __user *)(long)kvm->arch.xen_hvm_config.blob_addr_64
20666+ : (u8 __user *)(long)kvm->arch.xen_hvm_config.blob_addr_32;
20667 u8 blob_size = lm ? kvm->arch.xen_hvm_config.blob_size_64
20668 : kvm->arch.xen_hvm_config.blob_size_32;
20669 u32 page_num = data & ~PAGE_MASK;
20670@@ -2243,6 +2243,8 @@ long kvm_arch_dev_ioctl(struct file *filp,
20671 if (n < msr_list.nmsrs)
20672 goto out;
20673 r = -EFAULT;
20674+ if (num_msrs_to_save > ARRAY_SIZE(msrs_to_save))
20675+ goto out;
20676 if (copy_to_user(user_msr_list->indices, &msrs_to_save,
20677 num_msrs_to_save * sizeof(u32)))
20678 goto out;
20679@@ -2368,7 +2370,7 @@ static int kvm_vcpu_ioctl_set_lapic(struct kvm_vcpu *vcpu,
20680 static int kvm_vcpu_ioctl_interrupt(struct kvm_vcpu *vcpu,
20681 struct kvm_interrupt *irq)
20682 {
20683- if (irq->irq < 0 || irq->irq >= 256)
20684+ if (irq->irq >= 256)
20685 return -EINVAL;
20686 if (irqchip_in_kernel(vcpu->kvm))
20687 return -ENXIO;
20688@@ -4889,7 +4891,7 @@ static void kvm_set_mmio_spte_mask(void)
20689 kvm_mmu_set_mmio_spte_mask(mask);
20690 }
20691
20692-int kvm_arch_init(void *opaque)
20693+int kvm_arch_init(const void *opaque)
20694 {
20695 int r;
20696 struct kvm_x86_ops *ops = (struct kvm_x86_ops *)opaque;
20697@@ -5762,6 +5764,9 @@ int kvm_arch_vcpu_ioctl_set_sregs(struct kvm_vcpu *vcpu,
20698 int pending_vec, max_bits, idx;
20699 struct desc_ptr dt;
20700
20701+ if (!guest_cpuid_has_xsave(vcpu) && (sregs->cr4 & X86_CR4_OSXSAVE))
20702+ return -EINVAL;
20703+
20704 dt.size = sregs->idt.limit;
20705 dt.address = sregs->idt.base;
20706 kvm_x86_ops->set_idt(vcpu, &dt);
20707diff --git a/arch/x86/lguest/boot.c b/arch/x86/lguest/boot.c
20708index 642d880..cc9ebac 100644
20709--- a/arch/x86/lguest/boot.c
20710+++ b/arch/x86/lguest/boot.c
20711@@ -1116,12 +1116,12 @@ static u32 lguest_apic_safe_wait_icr_idle(void)
20712
20713 static void set_lguest_basic_apic_ops(void)
20714 {
20715- apic->read = lguest_apic_read;
20716- apic->write = lguest_apic_write;
20717- apic->icr_read = lguest_apic_icr_read;
20718- apic->icr_write = lguest_apic_icr_write;
20719- apic->wait_icr_idle = lguest_apic_wait_icr_idle;
20720- apic->safe_wait_icr_idle = lguest_apic_safe_wait_icr_idle;
20721+ *(void **)&apic->read = lguest_apic_read;
20722+ *(void **)&apic->write = lguest_apic_write;
20723+ *(void **)&apic->icr_read = lguest_apic_icr_read;
20724+ *(void **)&apic->icr_write = lguest_apic_icr_write;
20725+ *(void **)&apic->wait_icr_idle = lguest_apic_wait_icr_idle;
20726+ *(void **)&apic->safe_wait_icr_idle = lguest_apic_safe_wait_icr_idle;
20727 };
20728 #endif
20729
20730@@ -1200,9 +1200,10 @@ static __init int early_put_chars(u32 vtermno, const char *buf, int count)
20731 * Rebooting also tells the Host we're finished, but the RESTART flag tells the
20732 * Launcher to reboot us.
20733 */
20734-static void lguest_restart(char *reason)
20735+static __noreturn void lguest_restart(char *reason)
20736 {
20737 hcall(LHCALL_SHUTDOWN, __pa(reason), LGUEST_SHUTDOWN_RESTART, 0, 0);
20738+ BUG();
20739 }
20740
20741 /*G:050
20742diff --git a/arch/x86/lib/atomic64_386_32.S b/arch/x86/lib/atomic64_386_32.S
20743index 00933d5..3a64af9 100644
20744--- a/arch/x86/lib/atomic64_386_32.S
20745+++ b/arch/x86/lib/atomic64_386_32.S
20746@@ -48,6 +48,10 @@ BEGIN(read)
20747 movl (v), %eax
20748 movl 4(v), %edx
20749 RET_ENDP
20750+BEGIN(read_unchecked)
20751+ movl (v), %eax
20752+ movl 4(v), %edx
20753+RET_ENDP
20754 #undef v
20755
20756 #define v %esi
20757@@ -55,6 +59,10 @@ BEGIN(set)
20758 movl %ebx, (v)
20759 movl %ecx, 4(v)
20760 RET_ENDP
20761+BEGIN(set_unchecked)
20762+ movl %ebx, (v)
20763+ movl %ecx, 4(v)
20764+RET_ENDP
20765 #undef v
20766
20767 #define v %esi
20768@@ -70,6 +78,20 @@ RET_ENDP
20769 BEGIN(add)
20770 addl %eax, (v)
20771 adcl %edx, 4(v)
20772+
20773+#ifdef CONFIG_PAX_REFCOUNT
20774+ jno 0f
20775+ subl %eax, (v)
20776+ sbbl %edx, 4(v)
20777+ int $4
20778+0:
20779+ _ASM_EXTABLE(0b, 0b)
20780+#endif
20781+
20782+RET_ENDP
20783+BEGIN(add_unchecked)
20784+ addl %eax, (v)
20785+ adcl %edx, 4(v)
20786 RET_ENDP
20787 #undef v
20788
20789@@ -77,6 +99,24 @@ RET_ENDP
20790 BEGIN(add_return)
20791 addl (v), %eax
20792 adcl 4(v), %edx
20793+
20794+#ifdef CONFIG_PAX_REFCOUNT
20795+ into
20796+1234:
20797+ _ASM_EXTABLE(1234b, 2f)
20798+#endif
20799+
20800+ movl %eax, (v)
20801+ movl %edx, 4(v)
20802+
20803+#ifdef CONFIG_PAX_REFCOUNT
20804+2:
20805+#endif
20806+
20807+RET_ENDP
20808+BEGIN(add_return_unchecked)
20809+ addl (v), %eax
20810+ adcl 4(v), %edx
20811 movl %eax, (v)
20812 movl %edx, 4(v)
20813 RET_ENDP
20814@@ -86,6 +126,20 @@ RET_ENDP
20815 BEGIN(sub)
20816 subl %eax, (v)
20817 sbbl %edx, 4(v)
20818+
20819+#ifdef CONFIG_PAX_REFCOUNT
20820+ jno 0f
20821+ addl %eax, (v)
20822+ adcl %edx, 4(v)
20823+ int $4
20824+0:
20825+ _ASM_EXTABLE(0b, 0b)
20826+#endif
20827+
20828+RET_ENDP
20829+BEGIN(sub_unchecked)
20830+ subl %eax, (v)
20831+ sbbl %edx, 4(v)
20832 RET_ENDP
20833 #undef v
20834
20835@@ -96,6 +150,27 @@ BEGIN(sub_return)
20836 sbbl $0, %edx
20837 addl (v), %eax
20838 adcl 4(v), %edx
20839+
20840+#ifdef CONFIG_PAX_REFCOUNT
20841+ into
20842+1234:
20843+ _ASM_EXTABLE(1234b, 2f)
20844+#endif
20845+
20846+ movl %eax, (v)
20847+ movl %edx, 4(v)
20848+
20849+#ifdef CONFIG_PAX_REFCOUNT
20850+2:
20851+#endif
20852+
20853+RET_ENDP
20854+BEGIN(sub_return_unchecked)
20855+ negl %edx
20856+ negl %eax
20857+ sbbl $0, %edx
20858+ addl (v), %eax
20859+ adcl 4(v), %edx
20860 movl %eax, (v)
20861 movl %edx, 4(v)
20862 RET_ENDP
20863@@ -105,6 +180,20 @@ RET_ENDP
20864 BEGIN(inc)
20865 addl $1, (v)
20866 adcl $0, 4(v)
20867+
20868+#ifdef CONFIG_PAX_REFCOUNT
20869+ jno 0f
20870+ subl $1, (v)
20871+ sbbl $0, 4(v)
20872+ int $4
20873+0:
20874+ _ASM_EXTABLE(0b, 0b)
20875+#endif
20876+
20877+RET_ENDP
20878+BEGIN(inc_unchecked)
20879+ addl $1, (v)
20880+ adcl $0, 4(v)
20881 RET_ENDP
20882 #undef v
20883
20884@@ -114,6 +203,26 @@ BEGIN(inc_return)
20885 movl 4(v), %edx
20886 addl $1, %eax
20887 adcl $0, %edx
20888+
20889+#ifdef CONFIG_PAX_REFCOUNT
20890+ into
20891+1234:
20892+ _ASM_EXTABLE(1234b, 2f)
20893+#endif
20894+
20895+ movl %eax, (v)
20896+ movl %edx, 4(v)
20897+
20898+#ifdef CONFIG_PAX_REFCOUNT
20899+2:
20900+#endif
20901+
20902+RET_ENDP
20903+BEGIN(inc_return_unchecked)
20904+ movl (v), %eax
20905+ movl 4(v), %edx
20906+ addl $1, %eax
20907+ adcl $0, %edx
20908 movl %eax, (v)
20909 movl %edx, 4(v)
20910 RET_ENDP
20911@@ -123,6 +232,20 @@ RET_ENDP
20912 BEGIN(dec)
20913 subl $1, (v)
20914 sbbl $0, 4(v)
20915+
20916+#ifdef CONFIG_PAX_REFCOUNT
20917+ jno 0f
20918+ addl $1, (v)
20919+ adcl $0, 4(v)
20920+ int $4
20921+0:
20922+ _ASM_EXTABLE(0b, 0b)
20923+#endif
20924+
20925+RET_ENDP
20926+BEGIN(dec_unchecked)
20927+ subl $1, (v)
20928+ sbbl $0, 4(v)
20929 RET_ENDP
20930 #undef v
20931
20932@@ -132,6 +255,26 @@ BEGIN(dec_return)
20933 movl 4(v), %edx
20934 subl $1, %eax
20935 sbbl $0, %edx
20936+
20937+#ifdef CONFIG_PAX_REFCOUNT
20938+ into
20939+1234:
20940+ _ASM_EXTABLE(1234b, 2f)
20941+#endif
20942+
20943+ movl %eax, (v)
20944+ movl %edx, 4(v)
20945+
20946+#ifdef CONFIG_PAX_REFCOUNT
20947+2:
20948+#endif
20949+
20950+RET_ENDP
20951+BEGIN(dec_return_unchecked)
20952+ movl (v), %eax
20953+ movl 4(v), %edx
20954+ subl $1, %eax
20955+ sbbl $0, %edx
20956 movl %eax, (v)
20957 movl %edx, 4(v)
20958 RET_ENDP
20959@@ -143,6 +286,13 @@ BEGIN(add_unless)
20960 adcl %edx, %edi
20961 addl (v), %eax
20962 adcl 4(v), %edx
20963+
20964+#ifdef CONFIG_PAX_REFCOUNT
20965+ into
20966+1234:
20967+ _ASM_EXTABLE(1234b, 2f)
20968+#endif
20969+
20970 cmpl %eax, %ecx
20971 je 3f
20972 1:
20973@@ -168,6 +318,13 @@ BEGIN(inc_not_zero)
20974 1:
20975 addl $1, %eax
20976 adcl $0, %edx
20977+
20978+#ifdef CONFIG_PAX_REFCOUNT
20979+ into
20980+1234:
20981+ _ASM_EXTABLE(1234b, 2f)
20982+#endif
20983+
20984 movl %eax, (v)
20985 movl %edx, 4(v)
20986 movl $1, %eax
20987@@ -186,6 +343,13 @@ BEGIN(dec_if_positive)
20988 movl 4(v), %edx
20989 subl $1, %eax
20990 sbbl $0, %edx
20991+
20992+#ifdef CONFIG_PAX_REFCOUNT
20993+ into
20994+1234:
20995+ _ASM_EXTABLE(1234b, 1f)
20996+#endif
20997+
20998 js 1f
20999 movl %eax, (v)
21000 movl %edx, 4(v)
21001diff --git a/arch/x86/lib/atomic64_cx8_32.S b/arch/x86/lib/atomic64_cx8_32.S
21002index f5cc9eb..51fa319 100644
21003--- a/arch/x86/lib/atomic64_cx8_32.S
21004+++ b/arch/x86/lib/atomic64_cx8_32.S
21005@@ -35,10 +35,20 @@ ENTRY(atomic64_read_cx8)
21006 CFI_STARTPROC
21007
21008 read64 %ecx
21009+ pax_force_retaddr
21010 ret
21011 CFI_ENDPROC
21012 ENDPROC(atomic64_read_cx8)
21013
21014+ENTRY(atomic64_read_unchecked_cx8)
21015+ CFI_STARTPROC
21016+
21017+ read64 %ecx
21018+ pax_force_retaddr
21019+ ret
21020+ CFI_ENDPROC
21021+ENDPROC(atomic64_read_unchecked_cx8)
21022+
21023 ENTRY(atomic64_set_cx8)
21024 CFI_STARTPROC
21025
21026@@ -48,10 +58,25 @@ ENTRY(atomic64_set_cx8)
21027 cmpxchg8b (%esi)
21028 jne 1b
21029
21030+ pax_force_retaddr
21031 ret
21032 CFI_ENDPROC
21033 ENDPROC(atomic64_set_cx8)
21034
21035+ENTRY(atomic64_set_unchecked_cx8)
21036+ CFI_STARTPROC
21037+
21038+1:
21039+/* we don't need LOCK_PREFIX since aligned 64-bit writes
21040+ * are atomic on 586 and newer */
21041+ cmpxchg8b (%esi)
21042+ jne 1b
21043+
21044+ pax_force_retaddr
21045+ ret
21046+ CFI_ENDPROC
21047+ENDPROC(atomic64_set_unchecked_cx8)
21048+
21049 ENTRY(atomic64_xchg_cx8)
21050 CFI_STARTPROC
21051
21052@@ -60,12 +85,13 @@ ENTRY(atomic64_xchg_cx8)
21053 cmpxchg8b (%esi)
21054 jne 1b
21055
21056+ pax_force_retaddr
21057 ret
21058 CFI_ENDPROC
21059 ENDPROC(atomic64_xchg_cx8)
21060
21061-.macro addsub_return func ins insc
21062-ENTRY(atomic64_\func\()_return_cx8)
21063+.macro addsub_return func ins insc unchecked=""
21064+ENTRY(atomic64_\func\()_return\unchecked\()_cx8)
21065 CFI_STARTPROC
21066 SAVE ebp
21067 SAVE ebx
21068@@ -82,27 +108,44 @@ ENTRY(atomic64_\func\()_return_cx8)
21069 movl %edx, %ecx
21070 \ins\()l %esi, %ebx
21071 \insc\()l %edi, %ecx
21072+
21073+.ifb \unchecked
21074+#ifdef CONFIG_PAX_REFCOUNT
21075+ into
21076+2:
21077+ _ASM_EXTABLE(2b, 3f)
21078+#endif
21079+.endif
21080+
21081 LOCK_PREFIX
21082 cmpxchg8b (%ebp)
21083 jne 1b
21084-
21085-10:
21086 movl %ebx, %eax
21087 movl %ecx, %edx
21088+
21089+.ifb \unchecked
21090+#ifdef CONFIG_PAX_REFCOUNT
21091+3:
21092+#endif
21093+.endif
21094+
21095 RESTORE edi
21096 RESTORE esi
21097 RESTORE ebx
21098 RESTORE ebp
21099+ pax_force_retaddr
21100 ret
21101 CFI_ENDPROC
21102-ENDPROC(atomic64_\func\()_return_cx8)
21103+ENDPROC(atomic64_\func\()_return\unchecked\()_cx8)
21104 .endm
21105
21106 addsub_return add add adc
21107 addsub_return sub sub sbb
21108+addsub_return add add adc _unchecked
21109+addsub_return sub sub sbb _unchecked
21110
21111-.macro incdec_return func ins insc
21112-ENTRY(atomic64_\func\()_return_cx8)
21113+.macro incdec_return func ins insc unchecked=""
21114+ENTRY(atomic64_\func\()_return\unchecked\()_cx8)
21115 CFI_STARTPROC
21116 SAVE ebx
21117
21118@@ -112,21 +155,39 @@ ENTRY(atomic64_\func\()_return_cx8)
21119 movl %edx, %ecx
21120 \ins\()l $1, %ebx
21121 \insc\()l $0, %ecx
21122+
21123+.ifb \unchecked
21124+#ifdef CONFIG_PAX_REFCOUNT
21125+ into
21126+2:
21127+ _ASM_EXTABLE(2b, 3f)
21128+#endif
21129+.endif
21130+
21131 LOCK_PREFIX
21132 cmpxchg8b (%esi)
21133 jne 1b
21134
21135-10:
21136 movl %ebx, %eax
21137 movl %ecx, %edx
21138+
21139+.ifb \unchecked
21140+#ifdef CONFIG_PAX_REFCOUNT
21141+3:
21142+#endif
21143+.endif
21144+
21145 RESTORE ebx
21146+ pax_force_retaddr
21147 ret
21148 CFI_ENDPROC
21149-ENDPROC(atomic64_\func\()_return_cx8)
21150+ENDPROC(atomic64_\func\()_return\unchecked\()_cx8)
21151 .endm
21152
21153 incdec_return inc add adc
21154 incdec_return dec sub sbb
21155+incdec_return inc add adc _unchecked
21156+incdec_return dec sub sbb _unchecked
21157
21158 ENTRY(atomic64_dec_if_positive_cx8)
21159 CFI_STARTPROC
21160@@ -138,6 +199,13 @@ ENTRY(atomic64_dec_if_positive_cx8)
21161 movl %edx, %ecx
21162 subl $1, %ebx
21163 sbb $0, %ecx
21164+
21165+#ifdef CONFIG_PAX_REFCOUNT
21166+ into
21167+1234:
21168+ _ASM_EXTABLE(1234b, 2f)
21169+#endif
21170+
21171 js 2f
21172 LOCK_PREFIX
21173 cmpxchg8b (%esi)
21174@@ -147,6 +215,7 @@ ENTRY(atomic64_dec_if_positive_cx8)
21175 movl %ebx, %eax
21176 movl %ecx, %edx
21177 RESTORE ebx
21178+ pax_force_retaddr
21179 ret
21180 CFI_ENDPROC
21181 ENDPROC(atomic64_dec_if_positive_cx8)
21182@@ -171,6 +240,13 @@ ENTRY(atomic64_add_unless_cx8)
21183 movl %edx, %ecx
21184 addl %ebp, %ebx
21185 adcl %edi, %ecx
21186+
21187+#ifdef CONFIG_PAX_REFCOUNT
21188+ into
21189+1234:
21190+ _ASM_EXTABLE(1234b, 3f)
21191+#endif
21192+
21193 LOCK_PREFIX
21194 cmpxchg8b (%esi)
21195 jne 1b
21196@@ -181,6 +257,7 @@ ENTRY(atomic64_add_unless_cx8)
21197 CFI_ADJUST_CFA_OFFSET -8
21198 RESTORE ebx
21199 RESTORE ebp
21200+ pax_force_retaddr
21201 ret
21202 4:
21203 cmpl %edx, 4(%esp)
21204@@ -203,6 +280,13 @@ ENTRY(atomic64_inc_not_zero_cx8)
21205 xorl %ecx, %ecx
21206 addl $1, %ebx
21207 adcl %edx, %ecx
21208+
21209+#ifdef CONFIG_PAX_REFCOUNT
21210+ into
21211+1234:
21212+ _ASM_EXTABLE(1234b, 3f)
21213+#endif
21214+
21215 LOCK_PREFIX
21216 cmpxchg8b (%esi)
21217 jne 1b
21218@@ -210,6 +294,7 @@ ENTRY(atomic64_inc_not_zero_cx8)
21219 movl $1, %eax
21220 3:
21221 RESTORE ebx
21222+ pax_force_retaddr
21223 ret
21224 CFI_ENDPROC
21225 ENDPROC(atomic64_inc_not_zero_cx8)
21226diff --git a/arch/x86/lib/checksum_32.S b/arch/x86/lib/checksum_32.S
21227index 2af5df3..62b1a5a 100644
21228--- a/arch/x86/lib/checksum_32.S
21229+++ b/arch/x86/lib/checksum_32.S
21230@@ -29,7 +29,8 @@
21231 #include <asm/dwarf2.h>
21232 #include <asm/errno.h>
21233 #include <asm/asm.h>
21234-
21235+#include <asm/segment.h>
21236+
21237 /*
21238 * computes a partial checksum, e.g. for TCP/UDP fragments
21239 */
21240@@ -293,9 +294,24 @@ unsigned int csum_partial_copy_generic (const char *src, char *dst,
21241
21242 #define ARGBASE 16
21243 #define FP 12
21244-
21245-ENTRY(csum_partial_copy_generic)
21246+
21247+ENTRY(csum_partial_copy_generic_to_user)
21248 CFI_STARTPROC
21249+
21250+#ifdef CONFIG_PAX_MEMORY_UDEREF
21251+ pushl_cfi %gs
21252+ popl_cfi %es
21253+ jmp csum_partial_copy_generic
21254+#endif
21255+
21256+ENTRY(csum_partial_copy_generic_from_user)
21257+
21258+#ifdef CONFIG_PAX_MEMORY_UDEREF
21259+ pushl_cfi %gs
21260+ popl_cfi %ds
21261+#endif
21262+
21263+ENTRY(csum_partial_copy_generic)
21264 subl $4,%esp
21265 CFI_ADJUST_CFA_OFFSET 4
21266 pushl_cfi %edi
21267@@ -317,7 +333,7 @@ ENTRY(csum_partial_copy_generic)
21268 jmp 4f
21269 SRC(1: movw (%esi), %bx )
21270 addl $2, %esi
21271-DST( movw %bx, (%edi) )
21272+DST( movw %bx, %es:(%edi) )
21273 addl $2, %edi
21274 addw %bx, %ax
21275 adcl $0, %eax
21276@@ -329,30 +345,30 @@ DST( movw %bx, (%edi) )
21277 SRC(1: movl (%esi), %ebx )
21278 SRC( movl 4(%esi), %edx )
21279 adcl %ebx, %eax
21280-DST( movl %ebx, (%edi) )
21281+DST( movl %ebx, %es:(%edi) )
21282 adcl %edx, %eax
21283-DST( movl %edx, 4(%edi) )
21284+DST( movl %edx, %es:4(%edi) )
21285
21286 SRC( movl 8(%esi), %ebx )
21287 SRC( movl 12(%esi), %edx )
21288 adcl %ebx, %eax
21289-DST( movl %ebx, 8(%edi) )
21290+DST( movl %ebx, %es:8(%edi) )
21291 adcl %edx, %eax
21292-DST( movl %edx, 12(%edi) )
21293+DST( movl %edx, %es:12(%edi) )
21294
21295 SRC( movl 16(%esi), %ebx )
21296 SRC( movl 20(%esi), %edx )
21297 adcl %ebx, %eax
21298-DST( movl %ebx, 16(%edi) )
21299+DST( movl %ebx, %es:16(%edi) )
21300 adcl %edx, %eax
21301-DST( movl %edx, 20(%edi) )
21302+DST( movl %edx, %es:20(%edi) )
21303
21304 SRC( movl 24(%esi), %ebx )
21305 SRC( movl 28(%esi), %edx )
21306 adcl %ebx, %eax
21307-DST( movl %ebx, 24(%edi) )
21308+DST( movl %ebx, %es:24(%edi) )
21309 adcl %edx, %eax
21310-DST( movl %edx, 28(%edi) )
21311+DST( movl %edx, %es:28(%edi) )
21312
21313 lea 32(%esi), %esi
21314 lea 32(%edi), %edi
21315@@ -366,7 +382,7 @@ DST( movl %edx, 28(%edi) )
21316 shrl $2, %edx # This clears CF
21317 SRC(3: movl (%esi), %ebx )
21318 adcl %ebx, %eax
21319-DST( movl %ebx, (%edi) )
21320+DST( movl %ebx, %es:(%edi) )
21321 lea 4(%esi), %esi
21322 lea 4(%edi), %edi
21323 dec %edx
21324@@ -378,12 +394,12 @@ DST( movl %ebx, (%edi) )
21325 jb 5f
21326 SRC( movw (%esi), %cx )
21327 leal 2(%esi), %esi
21328-DST( movw %cx, (%edi) )
21329+DST( movw %cx, %es:(%edi) )
21330 leal 2(%edi), %edi
21331 je 6f
21332 shll $16,%ecx
21333 SRC(5: movb (%esi), %cl )
21334-DST( movb %cl, (%edi) )
21335+DST( movb %cl, %es:(%edi) )
21336 6: addl %ecx, %eax
21337 adcl $0, %eax
21338 7:
21339@@ -394,7 +410,7 @@ DST( movb %cl, (%edi) )
21340
21341 6001:
21342 movl ARGBASE+20(%esp), %ebx # src_err_ptr
21343- movl $-EFAULT, (%ebx)
21344+ movl $-EFAULT, %ss:(%ebx)
21345
21346 # zero the complete destination - computing the rest
21347 # is too much work
21348@@ -407,11 +423,15 @@ DST( movb %cl, (%edi) )
21349
21350 6002:
21351 movl ARGBASE+24(%esp), %ebx # dst_err_ptr
21352- movl $-EFAULT,(%ebx)
21353+ movl $-EFAULT,%ss:(%ebx)
21354 jmp 5000b
21355
21356 .previous
21357
21358+ pushl_cfi %ss
21359+ popl_cfi %ds
21360+ pushl_cfi %ss
21361+ popl_cfi %es
21362 popl_cfi %ebx
21363 CFI_RESTORE ebx
21364 popl_cfi %esi
21365@@ -421,26 +441,43 @@ DST( movb %cl, (%edi) )
21366 popl_cfi %ecx # equivalent to addl $4,%esp
21367 ret
21368 CFI_ENDPROC
21369-ENDPROC(csum_partial_copy_generic)
21370+ENDPROC(csum_partial_copy_generic_to_user)
21371
21372 #else
21373
21374 /* Version for PentiumII/PPro */
21375
21376 #define ROUND1(x) \
21377+ nop; nop; nop; \
21378 SRC(movl x(%esi), %ebx ) ; \
21379 addl %ebx, %eax ; \
21380- DST(movl %ebx, x(%edi) ) ;
21381+ DST(movl %ebx, %es:x(%edi)) ;
21382
21383 #define ROUND(x) \
21384+ nop; nop; nop; \
21385 SRC(movl x(%esi), %ebx ) ; \
21386 adcl %ebx, %eax ; \
21387- DST(movl %ebx, x(%edi) ) ;
21388+ DST(movl %ebx, %es:x(%edi)) ;
21389
21390 #define ARGBASE 12
21391-
21392-ENTRY(csum_partial_copy_generic)
21393+
21394+ENTRY(csum_partial_copy_generic_to_user)
21395 CFI_STARTPROC
21396+
21397+#ifdef CONFIG_PAX_MEMORY_UDEREF
21398+ pushl_cfi %gs
21399+ popl_cfi %es
21400+ jmp csum_partial_copy_generic
21401+#endif
21402+
21403+ENTRY(csum_partial_copy_generic_from_user)
21404+
21405+#ifdef CONFIG_PAX_MEMORY_UDEREF
21406+ pushl_cfi %gs
21407+ popl_cfi %ds
21408+#endif
21409+
21410+ENTRY(csum_partial_copy_generic)
21411 pushl_cfi %ebx
21412 CFI_REL_OFFSET ebx, 0
21413 pushl_cfi %edi
21414@@ -461,7 +498,7 @@ ENTRY(csum_partial_copy_generic)
21415 subl %ebx, %edi
21416 lea -1(%esi),%edx
21417 andl $-32,%edx
21418- lea 3f(%ebx,%ebx), %ebx
21419+ lea 3f(%ebx,%ebx,2), %ebx
21420 testl %esi, %esi
21421 jmp *%ebx
21422 1: addl $64,%esi
21423@@ -482,19 +519,19 @@ ENTRY(csum_partial_copy_generic)
21424 jb 5f
21425 SRC( movw (%esi), %dx )
21426 leal 2(%esi), %esi
21427-DST( movw %dx, (%edi) )
21428+DST( movw %dx, %es:(%edi) )
21429 leal 2(%edi), %edi
21430 je 6f
21431 shll $16,%edx
21432 5:
21433 SRC( movb (%esi), %dl )
21434-DST( movb %dl, (%edi) )
21435+DST( movb %dl, %es:(%edi) )
21436 6: addl %edx, %eax
21437 adcl $0, %eax
21438 7:
21439 .section .fixup, "ax"
21440 6001: movl ARGBASE+20(%esp), %ebx # src_err_ptr
21441- movl $-EFAULT, (%ebx)
21442+ movl $-EFAULT, %ss:(%ebx)
21443 # zero the complete destination (computing the rest is too much work)
21444 movl ARGBASE+8(%esp),%edi # dst
21445 movl ARGBASE+12(%esp),%ecx # len
21446@@ -502,10 +539,17 @@ DST( movb %dl, (%edi) )
21447 rep; stosb
21448 jmp 7b
21449 6002: movl ARGBASE+24(%esp), %ebx # dst_err_ptr
21450- movl $-EFAULT, (%ebx)
21451+ movl $-EFAULT, %ss:(%ebx)
21452 jmp 7b
21453 .previous
21454
21455+#ifdef CONFIG_PAX_MEMORY_UDEREF
21456+ pushl_cfi %ss
21457+ popl_cfi %ds
21458+ pushl_cfi %ss
21459+ popl_cfi %es
21460+#endif
21461+
21462 popl_cfi %esi
21463 CFI_RESTORE esi
21464 popl_cfi %edi
21465@@ -514,7 +558,7 @@ DST( movb %dl, (%edi) )
21466 CFI_RESTORE ebx
21467 ret
21468 CFI_ENDPROC
21469-ENDPROC(csum_partial_copy_generic)
21470+ENDPROC(csum_partial_copy_generic_to_user)
21471
21472 #undef ROUND
21473 #undef ROUND1
21474diff --git a/arch/x86/lib/clear_page_64.S b/arch/x86/lib/clear_page_64.S
21475index f2145cf..cea889d 100644
21476--- a/arch/x86/lib/clear_page_64.S
21477+++ b/arch/x86/lib/clear_page_64.S
21478@@ -11,6 +11,7 @@ ENTRY(clear_page_c)
21479 movl $4096/8,%ecx
21480 xorl %eax,%eax
21481 rep stosq
21482+ pax_force_retaddr
21483 ret
21484 CFI_ENDPROC
21485 ENDPROC(clear_page_c)
21486@@ -20,6 +21,7 @@ ENTRY(clear_page_c_e)
21487 movl $4096,%ecx
21488 xorl %eax,%eax
21489 rep stosb
21490+ pax_force_retaddr
21491 ret
21492 CFI_ENDPROC
21493 ENDPROC(clear_page_c_e)
21494@@ -43,6 +45,7 @@ ENTRY(clear_page)
21495 leaq 64(%rdi),%rdi
21496 jnz .Lloop
21497 nop
21498+ pax_force_retaddr
21499 ret
21500 CFI_ENDPROC
21501 .Lclear_page_end:
21502@@ -58,7 +61,7 @@ ENDPROC(clear_page)
21503
21504 #include <asm/cpufeature.h>
21505
21506- .section .altinstr_replacement,"ax"
21507+ .section .altinstr_replacement,"a"
21508 1: .byte 0xeb /* jmp <disp8> */
21509 .byte (clear_page_c - clear_page) - (2f - 1b) /* offset */
21510 2: .byte 0xeb /* jmp <disp8> */
21511diff --git a/arch/x86/lib/cmpxchg16b_emu.S b/arch/x86/lib/cmpxchg16b_emu.S
21512index 1e572c5..2a162cd 100644
21513--- a/arch/x86/lib/cmpxchg16b_emu.S
21514+++ b/arch/x86/lib/cmpxchg16b_emu.S
21515@@ -53,11 +53,13 @@ this_cpu_cmpxchg16b_emu:
21516
21517 popf
21518 mov $1, %al
21519+ pax_force_retaddr
21520 ret
21521
21522 not_same:
21523 popf
21524 xor %al,%al
21525+ pax_force_retaddr
21526 ret
21527
21528 CFI_ENDPROC
21529diff --git a/arch/x86/lib/copy_page_64.S b/arch/x86/lib/copy_page_64.S
21530index 6b34d04..dccb07f 100644
21531--- a/arch/x86/lib/copy_page_64.S
21532+++ b/arch/x86/lib/copy_page_64.S
21533@@ -9,6 +9,7 @@ copy_page_c:
21534 CFI_STARTPROC
21535 movl $4096/8,%ecx
21536 rep movsq
21537+ pax_force_retaddr
21538 ret
21539 CFI_ENDPROC
21540 ENDPROC(copy_page_c)
21541@@ -20,12 +21,14 @@ ENDPROC(copy_page_c)
21542
21543 ENTRY(copy_page)
21544 CFI_STARTPROC
21545- subq $2*8,%rsp
21546- CFI_ADJUST_CFA_OFFSET 2*8
21547+ subq $3*8,%rsp
21548+ CFI_ADJUST_CFA_OFFSET 3*8
21549 movq %rbx,(%rsp)
21550 CFI_REL_OFFSET rbx, 0
21551 movq %r12,1*8(%rsp)
21552 CFI_REL_OFFSET r12, 1*8
21553+ movq %r13,2*8(%rsp)
21554+ CFI_REL_OFFSET r13, 2*8
21555
21556 movl $(4096/64)-5,%ecx
21557 .p2align 4
21558@@ -37,7 +40,7 @@ ENTRY(copy_page)
21559 movq 16 (%rsi), %rdx
21560 movq 24 (%rsi), %r8
21561 movq 32 (%rsi), %r9
21562- movq 40 (%rsi), %r10
21563+ movq 40 (%rsi), %r13
21564 movq 48 (%rsi), %r11
21565 movq 56 (%rsi), %r12
21566
21567@@ -48,7 +51,7 @@ ENTRY(copy_page)
21568 movq %rdx, 16 (%rdi)
21569 movq %r8, 24 (%rdi)
21570 movq %r9, 32 (%rdi)
21571- movq %r10, 40 (%rdi)
21572+ movq %r13, 40 (%rdi)
21573 movq %r11, 48 (%rdi)
21574 movq %r12, 56 (%rdi)
21575
21576@@ -67,7 +70,7 @@ ENTRY(copy_page)
21577 movq 16 (%rsi), %rdx
21578 movq 24 (%rsi), %r8
21579 movq 32 (%rsi), %r9
21580- movq 40 (%rsi), %r10
21581+ movq 40 (%rsi), %r13
21582 movq 48 (%rsi), %r11
21583 movq 56 (%rsi), %r12
21584
21585@@ -76,7 +79,7 @@ ENTRY(copy_page)
21586 movq %rdx, 16 (%rdi)
21587 movq %r8, 24 (%rdi)
21588 movq %r9, 32 (%rdi)
21589- movq %r10, 40 (%rdi)
21590+ movq %r13, 40 (%rdi)
21591 movq %r11, 48 (%rdi)
21592 movq %r12, 56 (%rdi)
21593
21594@@ -89,8 +92,11 @@ ENTRY(copy_page)
21595 CFI_RESTORE rbx
21596 movq 1*8(%rsp),%r12
21597 CFI_RESTORE r12
21598- addq $2*8,%rsp
21599- CFI_ADJUST_CFA_OFFSET -2*8
21600+ movq 2*8(%rsp),%r13
21601+ CFI_RESTORE r13
21602+ addq $3*8,%rsp
21603+ CFI_ADJUST_CFA_OFFSET -3*8
21604+ pax_force_retaddr
21605 ret
21606 .Lcopy_page_end:
21607 CFI_ENDPROC
21608@@ -101,7 +107,7 @@ ENDPROC(copy_page)
21609
21610 #include <asm/cpufeature.h>
21611
21612- .section .altinstr_replacement,"ax"
21613+ .section .altinstr_replacement,"a"
21614 1: .byte 0xeb /* jmp <disp8> */
21615 .byte (copy_page_c - copy_page) - (2f - 1b) /* offset */
21616 2:
21617diff --git a/arch/x86/lib/copy_user_64.S b/arch/x86/lib/copy_user_64.S
21618index 5b2995f..78e7644 100644
21619--- a/arch/x86/lib/copy_user_64.S
21620+++ b/arch/x86/lib/copy_user_64.S
21621@@ -17,6 +17,7 @@
21622 #include <asm/cpufeature.h>
21623 #include <asm/alternative-asm.h>
21624 #include <asm/asm.h>
21625+#include <asm/pgtable.h>
21626
21627 /*
21628 * By placing feature2 after feature1 in altinstructions section, we logically
21629@@ -30,7 +31,7 @@
21630 .byte 0xe9 /* 32bit jump */
21631 .long \orig-1f /* by default jump to orig */
21632 1:
21633- .section .altinstr_replacement,"ax"
21634+ .section .altinstr_replacement,"a"
21635 2: .byte 0xe9 /* near jump with 32bit immediate */
21636 .long \alt1-1b /* offset */ /* or alternatively to alt1 */
21637 3: .byte 0xe9 /* near jump with 32bit immediate */
21638@@ -69,47 +70,20 @@
21639 #endif
21640 .endm
21641
21642-/* Standard copy_to_user with segment limit checking */
21643-ENTRY(_copy_to_user)
21644- CFI_STARTPROC
21645- GET_THREAD_INFO(%rax)
21646- movq %rdi,%rcx
21647- addq %rdx,%rcx
21648- jc bad_to_user
21649- cmpq TI_addr_limit(%rax),%rcx
21650- ja bad_to_user
21651- ALTERNATIVE_JUMP X86_FEATURE_REP_GOOD,X86_FEATURE_ERMS, \
21652- copy_user_generic_unrolled,copy_user_generic_string, \
21653- copy_user_enhanced_fast_string
21654- CFI_ENDPROC
21655-ENDPROC(_copy_to_user)
21656-
21657-/* Standard copy_from_user with segment limit checking */
21658-ENTRY(_copy_from_user)
21659- CFI_STARTPROC
21660- GET_THREAD_INFO(%rax)
21661- movq %rsi,%rcx
21662- addq %rdx,%rcx
21663- jc bad_from_user
21664- cmpq TI_addr_limit(%rax),%rcx
21665- ja bad_from_user
21666- ALTERNATIVE_JUMP X86_FEATURE_REP_GOOD,X86_FEATURE_ERMS, \
21667- copy_user_generic_unrolled,copy_user_generic_string, \
21668- copy_user_enhanced_fast_string
21669- CFI_ENDPROC
21670-ENDPROC(_copy_from_user)
21671-
21672 .section .fixup,"ax"
21673 /* must zero dest */
21674 ENTRY(bad_from_user)
21675 bad_from_user:
21676 CFI_STARTPROC
21677+ testl %edx,%edx
21678+ js bad_to_user
21679 movl %edx,%ecx
21680 xorl %eax,%eax
21681 rep
21682 stosb
21683 bad_to_user:
21684 movl %edx,%eax
21685+ pax_force_retaddr
21686 ret
21687 CFI_ENDPROC
21688 ENDPROC(bad_from_user)
21689@@ -139,19 +113,19 @@ ENTRY(copy_user_generic_unrolled)
21690 jz 17f
21691 1: movq (%rsi),%r8
21692 2: movq 1*8(%rsi),%r9
21693-3: movq 2*8(%rsi),%r10
21694+3: movq 2*8(%rsi),%rax
21695 4: movq 3*8(%rsi),%r11
21696 5: movq %r8,(%rdi)
21697 6: movq %r9,1*8(%rdi)
21698-7: movq %r10,2*8(%rdi)
21699+7: movq %rax,2*8(%rdi)
21700 8: movq %r11,3*8(%rdi)
21701 9: movq 4*8(%rsi),%r8
21702 10: movq 5*8(%rsi),%r9
21703-11: movq 6*8(%rsi),%r10
21704+11: movq 6*8(%rsi),%rax
21705 12: movq 7*8(%rsi),%r11
21706 13: movq %r8,4*8(%rdi)
21707 14: movq %r9,5*8(%rdi)
21708-15: movq %r10,6*8(%rdi)
21709+15: movq %rax,6*8(%rdi)
21710 16: movq %r11,7*8(%rdi)
21711 leaq 64(%rsi),%rsi
21712 leaq 64(%rdi),%rdi
21713@@ -177,6 +151,7 @@ ENTRY(copy_user_generic_unrolled)
21714 decl %ecx
21715 jnz 21b
21716 23: xor %eax,%eax
21717+ pax_force_retaddr
21718 ret
21719
21720 .section .fixup,"ax"
21721@@ -246,6 +221,7 @@ ENTRY(copy_user_generic_string)
21722 3: rep
21723 movsb
21724 4: xorl %eax,%eax
21725+ pax_force_retaddr
21726 ret
21727
21728 .section .fixup,"ax"
21729@@ -279,6 +255,7 @@ ENTRY(copy_user_enhanced_fast_string)
21730 1: rep
21731 movsb
21732 2: xorl %eax,%eax
21733+ pax_force_retaddr
21734 ret
21735
21736 .section .fixup,"ax"
21737diff --git a/arch/x86/lib/copy_user_nocache_64.S b/arch/x86/lib/copy_user_nocache_64.S
21738index cacddc7..09d49e4 100644
21739--- a/arch/x86/lib/copy_user_nocache_64.S
21740+++ b/arch/x86/lib/copy_user_nocache_64.S
21741@@ -8,6 +8,7 @@
21742
21743 #include <linux/linkage.h>
21744 #include <asm/dwarf2.h>
21745+#include <asm/alternative-asm.h>
21746
21747 #define FIX_ALIGNMENT 1
21748
21749@@ -15,6 +16,7 @@
21750 #include <asm/asm-offsets.h>
21751 #include <asm/thread_info.h>
21752 #include <asm/asm.h>
21753+#include <asm/pgtable.h>
21754
21755 .macro ALIGN_DESTINATION
21756 #ifdef FIX_ALIGNMENT
21757@@ -48,6 +50,15 @@
21758 */
21759 ENTRY(__copy_user_nocache)
21760 CFI_STARTPROC
21761+
21762+#ifdef CONFIG_PAX_MEMORY_UDEREF
21763+ mov $PAX_USER_SHADOW_BASE,%rcx
21764+ cmp %rcx,%rsi
21765+ jae 1f
21766+ add %rcx,%rsi
21767+1:
21768+#endif
21769+
21770 cmpl $8,%edx
21771 jb 20f /* less then 8 bytes, go to byte copy loop */
21772 ALIGN_DESTINATION
21773@@ -57,19 +68,19 @@ ENTRY(__copy_user_nocache)
21774 jz 17f
21775 1: movq (%rsi),%r8
21776 2: movq 1*8(%rsi),%r9
21777-3: movq 2*8(%rsi),%r10
21778+3: movq 2*8(%rsi),%rax
21779 4: movq 3*8(%rsi),%r11
21780 5: movnti %r8,(%rdi)
21781 6: movnti %r9,1*8(%rdi)
21782-7: movnti %r10,2*8(%rdi)
21783+7: movnti %rax,2*8(%rdi)
21784 8: movnti %r11,3*8(%rdi)
21785 9: movq 4*8(%rsi),%r8
21786 10: movq 5*8(%rsi),%r9
21787-11: movq 6*8(%rsi),%r10
21788+11: movq 6*8(%rsi),%rax
21789 12: movq 7*8(%rsi),%r11
21790 13: movnti %r8,4*8(%rdi)
21791 14: movnti %r9,5*8(%rdi)
21792-15: movnti %r10,6*8(%rdi)
21793+15: movnti %rax,6*8(%rdi)
21794 16: movnti %r11,7*8(%rdi)
21795 leaq 64(%rsi),%rsi
21796 leaq 64(%rdi),%rdi
21797@@ -96,6 +107,7 @@ ENTRY(__copy_user_nocache)
21798 jnz 21b
21799 23: xorl %eax,%eax
21800 sfence
21801+ pax_force_retaddr
21802 ret
21803
21804 .section .fixup,"ax"
21805diff --git a/arch/x86/lib/csum-copy_64.S b/arch/x86/lib/csum-copy_64.S
21806index 2419d5f..953ee51 100644
21807--- a/arch/x86/lib/csum-copy_64.S
21808+++ b/arch/x86/lib/csum-copy_64.S
21809@@ -9,6 +9,7 @@
21810 #include <asm/dwarf2.h>
21811 #include <asm/errno.h>
21812 #include <asm/asm.h>
21813+#include <asm/alternative-asm.h>
21814
21815 /*
21816 * Checksum copy with exception handling.
21817@@ -220,6 +221,7 @@ ENTRY(csum_partial_copy_generic)
21818 CFI_RESTORE rbp
21819 addq $7*8, %rsp
21820 CFI_ADJUST_CFA_OFFSET -7*8
21821+ pax_force_retaddr 0, 1
21822 ret
21823 CFI_RESTORE_STATE
21824
21825diff --git a/arch/x86/lib/csum-wrappers_64.c b/arch/x86/lib/csum-wrappers_64.c
21826index 25b7ae8..3b52ccd 100644
21827--- a/arch/x86/lib/csum-wrappers_64.c
21828+++ b/arch/x86/lib/csum-wrappers_64.c
21829@@ -52,7 +52,13 @@ csum_partial_copy_from_user(const void __user *src, void *dst,
21830 len -= 2;
21831 }
21832 }
21833- isum = csum_partial_copy_generic((__force const void *)src,
21834+
21835+#ifdef CONFIG_PAX_MEMORY_UDEREF
21836+ if ((unsigned long)src < PAX_USER_SHADOW_BASE)
21837+ src += PAX_USER_SHADOW_BASE;
21838+#endif
21839+
21840+ isum = csum_partial_copy_generic((const void __force_kernel *)src,
21841 dst, len, isum, errp, NULL);
21842 if (unlikely(*errp))
21843 goto out_err;
21844@@ -105,7 +111,13 @@ csum_partial_copy_to_user(const void *src, void __user *dst,
21845 }
21846
21847 *errp = 0;
21848- return csum_partial_copy_generic(src, (void __force *)dst,
21849+
21850+#ifdef CONFIG_PAX_MEMORY_UDEREF
21851+ if ((unsigned long)dst < PAX_USER_SHADOW_BASE)
21852+ dst += PAX_USER_SHADOW_BASE;
21853+#endif
21854+
21855+ return csum_partial_copy_generic(src, (void __force_kernel *)dst,
21856 len, isum, NULL, errp);
21857 }
21858 EXPORT_SYMBOL(csum_partial_copy_to_user);
21859diff --git a/arch/x86/lib/getuser.S b/arch/x86/lib/getuser.S
21860index b33b1fb..219f389 100644
21861--- a/arch/x86/lib/getuser.S
21862+++ b/arch/x86/lib/getuser.S
21863@@ -33,15 +33,38 @@
21864 #include <asm/asm-offsets.h>
21865 #include <asm/thread_info.h>
21866 #include <asm/asm.h>
21867+#include <asm/segment.h>
21868+#include <asm/pgtable.h>
21869+#include <asm/alternative-asm.h>
21870+
21871+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
21872+#define __copyuser_seg gs;
21873+#else
21874+#define __copyuser_seg
21875+#endif
21876
21877 .text
21878 ENTRY(__get_user_1)
21879 CFI_STARTPROC
21880+
21881+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
21882 GET_THREAD_INFO(%_ASM_DX)
21883 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
21884 jae bad_get_user
21885-1: movzb (%_ASM_AX),%edx
21886+
21887+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
21888+ mov $PAX_USER_SHADOW_BASE,%_ASM_DX
21889+ cmp %_ASM_DX,%_ASM_AX
21890+ jae 1234f
21891+ add %_ASM_DX,%_ASM_AX
21892+1234:
21893+#endif
21894+
21895+#endif
21896+
21897+1: __copyuser_seg movzb (%_ASM_AX),%edx
21898 xor %eax,%eax
21899+ pax_force_retaddr
21900 ret
21901 CFI_ENDPROC
21902 ENDPROC(__get_user_1)
21903@@ -49,12 +72,26 @@ ENDPROC(__get_user_1)
21904 ENTRY(__get_user_2)
21905 CFI_STARTPROC
21906 add $1,%_ASM_AX
21907+
21908+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
21909 jc bad_get_user
21910 GET_THREAD_INFO(%_ASM_DX)
21911 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
21912 jae bad_get_user
21913-2: movzwl -1(%_ASM_AX),%edx
21914+
21915+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
21916+ mov $PAX_USER_SHADOW_BASE,%_ASM_DX
21917+ cmp %_ASM_DX,%_ASM_AX
21918+ jae 1234f
21919+ add %_ASM_DX,%_ASM_AX
21920+1234:
21921+#endif
21922+
21923+#endif
21924+
21925+2: __copyuser_seg movzwl -1(%_ASM_AX),%edx
21926 xor %eax,%eax
21927+ pax_force_retaddr
21928 ret
21929 CFI_ENDPROC
21930 ENDPROC(__get_user_2)
21931@@ -62,12 +99,26 @@ ENDPROC(__get_user_2)
21932 ENTRY(__get_user_4)
21933 CFI_STARTPROC
21934 add $3,%_ASM_AX
21935+
21936+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
21937 jc bad_get_user
21938 GET_THREAD_INFO(%_ASM_DX)
21939 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
21940 jae bad_get_user
21941-3: mov -3(%_ASM_AX),%edx
21942+
21943+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
21944+ mov $PAX_USER_SHADOW_BASE,%_ASM_DX
21945+ cmp %_ASM_DX,%_ASM_AX
21946+ jae 1234f
21947+ add %_ASM_DX,%_ASM_AX
21948+1234:
21949+#endif
21950+
21951+#endif
21952+
21953+3: __copyuser_seg mov -3(%_ASM_AX),%edx
21954 xor %eax,%eax
21955+ pax_force_retaddr
21956 ret
21957 CFI_ENDPROC
21958 ENDPROC(__get_user_4)
21959@@ -80,8 +131,18 @@ ENTRY(__get_user_8)
21960 GET_THREAD_INFO(%_ASM_DX)
21961 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
21962 jae bad_get_user
21963+
21964+#ifdef CONFIG_PAX_MEMORY_UDEREF
21965+ mov $PAX_USER_SHADOW_BASE,%_ASM_DX
21966+ cmp %_ASM_DX,%_ASM_AX
21967+ jae 1234f
21968+ add %_ASM_DX,%_ASM_AX
21969+1234:
21970+#endif
21971+
21972 4: movq -7(%_ASM_AX),%_ASM_DX
21973 xor %eax,%eax
21974+ pax_force_retaddr
21975 ret
21976 CFI_ENDPROC
21977 ENDPROC(__get_user_8)
21978@@ -91,6 +152,7 @@ bad_get_user:
21979 CFI_STARTPROC
21980 xor %edx,%edx
21981 mov $(-EFAULT),%_ASM_AX
21982+ pax_force_retaddr
21983 ret
21984 CFI_ENDPROC
21985 END(bad_get_user)
21986diff --git a/arch/x86/lib/insn.c b/arch/x86/lib/insn.c
21987index b1e6c4b..21ae8fc 100644
21988--- a/arch/x86/lib/insn.c
21989+++ b/arch/x86/lib/insn.c
21990@@ -21,6 +21,11 @@
21991 #include <linux/string.h>
21992 #include <asm/inat.h>
21993 #include <asm/insn.h>
21994+#ifdef __KERNEL__
21995+#include <asm/pgtable_types.h>
21996+#else
21997+#define ktla_ktva(addr) addr
21998+#endif
21999
22000 /* Verify next sizeof(t) bytes can be on the same instruction */
22001 #define validate_next(t, insn, n) \
22002@@ -49,8 +54,8 @@
22003 void insn_init(struct insn *insn, const void *kaddr, int x86_64)
22004 {
22005 memset(insn, 0, sizeof(*insn));
22006- insn->kaddr = kaddr;
22007- insn->next_byte = kaddr;
22008+ insn->kaddr = ktla_ktva(kaddr);
22009+ insn->next_byte = ktla_ktva(kaddr);
22010 insn->x86_64 = x86_64 ? 1 : 0;
22011 insn->opnd_bytes = 4;
22012 if (x86_64)
22013diff --git a/arch/x86/lib/iomap_copy_64.S b/arch/x86/lib/iomap_copy_64.S
22014index 05a95e7..326f2fa 100644
22015--- a/arch/x86/lib/iomap_copy_64.S
22016+++ b/arch/x86/lib/iomap_copy_64.S
22017@@ -17,6 +17,7 @@
22018
22019 #include <linux/linkage.h>
22020 #include <asm/dwarf2.h>
22021+#include <asm/alternative-asm.h>
22022
22023 /*
22024 * override generic version in lib/iomap_copy.c
22025@@ -25,6 +26,7 @@ ENTRY(__iowrite32_copy)
22026 CFI_STARTPROC
22027 movl %edx,%ecx
22028 rep movsd
22029+ pax_force_retaddr
22030 ret
22031 CFI_ENDPROC
22032 ENDPROC(__iowrite32_copy)
22033diff --git a/arch/x86/lib/memcpy_64.S b/arch/x86/lib/memcpy_64.S
22034index 1c273be..da9cc0e 100644
22035--- a/arch/x86/lib/memcpy_64.S
22036+++ b/arch/x86/lib/memcpy_64.S
22037@@ -33,6 +33,7 @@
22038 rep movsq
22039 movl %edx, %ecx
22040 rep movsb
22041+ pax_force_retaddr
22042 ret
22043 .Lmemcpy_e:
22044 .previous
22045@@ -49,6 +50,7 @@
22046 movq %rdi, %rax
22047 movq %rdx, %rcx
22048 rep movsb
22049+ pax_force_retaddr
22050 ret
22051 .Lmemcpy_e_e:
22052 .previous
22053@@ -76,13 +78,13 @@ ENTRY(memcpy)
22054 */
22055 movq 0*8(%rsi), %r8
22056 movq 1*8(%rsi), %r9
22057- movq 2*8(%rsi), %r10
22058+ movq 2*8(%rsi), %rcx
22059 movq 3*8(%rsi), %r11
22060 leaq 4*8(%rsi), %rsi
22061
22062 movq %r8, 0*8(%rdi)
22063 movq %r9, 1*8(%rdi)
22064- movq %r10, 2*8(%rdi)
22065+ movq %rcx, 2*8(%rdi)
22066 movq %r11, 3*8(%rdi)
22067 leaq 4*8(%rdi), %rdi
22068 jae .Lcopy_forward_loop
22069@@ -105,12 +107,12 @@ ENTRY(memcpy)
22070 subq $0x20, %rdx
22071 movq -1*8(%rsi), %r8
22072 movq -2*8(%rsi), %r9
22073- movq -3*8(%rsi), %r10
22074+ movq -3*8(%rsi), %rcx
22075 movq -4*8(%rsi), %r11
22076 leaq -4*8(%rsi), %rsi
22077 movq %r8, -1*8(%rdi)
22078 movq %r9, -2*8(%rdi)
22079- movq %r10, -3*8(%rdi)
22080+ movq %rcx, -3*8(%rdi)
22081 movq %r11, -4*8(%rdi)
22082 leaq -4*8(%rdi), %rdi
22083 jae .Lcopy_backward_loop
22084@@ -130,12 +132,13 @@ ENTRY(memcpy)
22085 */
22086 movq 0*8(%rsi), %r8
22087 movq 1*8(%rsi), %r9
22088- movq -2*8(%rsi, %rdx), %r10
22089+ movq -2*8(%rsi, %rdx), %rcx
22090 movq -1*8(%rsi, %rdx), %r11
22091 movq %r8, 0*8(%rdi)
22092 movq %r9, 1*8(%rdi)
22093- movq %r10, -2*8(%rdi, %rdx)
22094+ movq %rcx, -2*8(%rdi, %rdx)
22095 movq %r11, -1*8(%rdi, %rdx)
22096+ pax_force_retaddr
22097 retq
22098 .p2align 4
22099 .Lless_16bytes:
22100@@ -148,6 +151,7 @@ ENTRY(memcpy)
22101 movq -1*8(%rsi, %rdx), %r9
22102 movq %r8, 0*8(%rdi)
22103 movq %r9, -1*8(%rdi, %rdx)
22104+ pax_force_retaddr
22105 retq
22106 .p2align 4
22107 .Lless_8bytes:
22108@@ -161,6 +165,7 @@ ENTRY(memcpy)
22109 movl -4(%rsi, %rdx), %r8d
22110 movl %ecx, (%rdi)
22111 movl %r8d, -4(%rdi, %rdx)
22112+ pax_force_retaddr
22113 retq
22114 .p2align 4
22115 .Lless_3bytes:
22116@@ -179,6 +184,7 @@ ENTRY(memcpy)
22117 movb %cl, (%rdi)
22118
22119 .Lend:
22120+ pax_force_retaddr
22121 retq
22122 CFI_ENDPROC
22123 ENDPROC(memcpy)
22124diff --git a/arch/x86/lib/memmove_64.S b/arch/x86/lib/memmove_64.S
22125index ee16461..c39c199 100644
22126--- a/arch/x86/lib/memmove_64.S
22127+++ b/arch/x86/lib/memmove_64.S
22128@@ -61,13 +61,13 @@ ENTRY(memmove)
22129 5:
22130 sub $0x20, %rdx
22131 movq 0*8(%rsi), %r11
22132- movq 1*8(%rsi), %r10
22133+ movq 1*8(%rsi), %rcx
22134 movq 2*8(%rsi), %r9
22135 movq 3*8(%rsi), %r8
22136 leaq 4*8(%rsi), %rsi
22137
22138 movq %r11, 0*8(%rdi)
22139- movq %r10, 1*8(%rdi)
22140+ movq %rcx, 1*8(%rdi)
22141 movq %r9, 2*8(%rdi)
22142 movq %r8, 3*8(%rdi)
22143 leaq 4*8(%rdi), %rdi
22144@@ -81,10 +81,10 @@ ENTRY(memmove)
22145 4:
22146 movq %rdx, %rcx
22147 movq -8(%rsi, %rdx), %r11
22148- lea -8(%rdi, %rdx), %r10
22149+ lea -8(%rdi, %rdx), %r9
22150 shrq $3, %rcx
22151 rep movsq
22152- movq %r11, (%r10)
22153+ movq %r11, (%r9)
22154 jmp 13f
22155 .Lmemmove_end_forward:
22156
22157@@ -95,14 +95,14 @@ ENTRY(memmove)
22158 7:
22159 movq %rdx, %rcx
22160 movq (%rsi), %r11
22161- movq %rdi, %r10
22162+ movq %rdi, %r9
22163 leaq -8(%rsi, %rdx), %rsi
22164 leaq -8(%rdi, %rdx), %rdi
22165 shrq $3, %rcx
22166 std
22167 rep movsq
22168 cld
22169- movq %r11, (%r10)
22170+ movq %r11, (%r9)
22171 jmp 13f
22172
22173 /*
22174@@ -127,13 +127,13 @@ ENTRY(memmove)
22175 8:
22176 subq $0x20, %rdx
22177 movq -1*8(%rsi), %r11
22178- movq -2*8(%rsi), %r10
22179+ movq -2*8(%rsi), %rcx
22180 movq -3*8(%rsi), %r9
22181 movq -4*8(%rsi), %r8
22182 leaq -4*8(%rsi), %rsi
22183
22184 movq %r11, -1*8(%rdi)
22185- movq %r10, -2*8(%rdi)
22186+ movq %rcx, -2*8(%rdi)
22187 movq %r9, -3*8(%rdi)
22188 movq %r8, -4*8(%rdi)
22189 leaq -4*8(%rdi), %rdi
22190@@ -151,11 +151,11 @@ ENTRY(memmove)
22191 * Move data from 16 bytes to 31 bytes.
22192 */
22193 movq 0*8(%rsi), %r11
22194- movq 1*8(%rsi), %r10
22195+ movq 1*8(%rsi), %rcx
22196 movq -2*8(%rsi, %rdx), %r9
22197 movq -1*8(%rsi, %rdx), %r8
22198 movq %r11, 0*8(%rdi)
22199- movq %r10, 1*8(%rdi)
22200+ movq %rcx, 1*8(%rdi)
22201 movq %r9, -2*8(%rdi, %rdx)
22202 movq %r8, -1*8(%rdi, %rdx)
22203 jmp 13f
22204@@ -167,9 +167,9 @@ ENTRY(memmove)
22205 * Move data from 8 bytes to 15 bytes.
22206 */
22207 movq 0*8(%rsi), %r11
22208- movq -1*8(%rsi, %rdx), %r10
22209+ movq -1*8(%rsi, %rdx), %r9
22210 movq %r11, 0*8(%rdi)
22211- movq %r10, -1*8(%rdi, %rdx)
22212+ movq %r9, -1*8(%rdi, %rdx)
22213 jmp 13f
22214 10:
22215 cmpq $4, %rdx
22216@@ -178,9 +178,9 @@ ENTRY(memmove)
22217 * Move data from 4 bytes to 7 bytes.
22218 */
22219 movl (%rsi), %r11d
22220- movl -4(%rsi, %rdx), %r10d
22221+ movl -4(%rsi, %rdx), %r9d
22222 movl %r11d, (%rdi)
22223- movl %r10d, -4(%rdi, %rdx)
22224+ movl %r9d, -4(%rdi, %rdx)
22225 jmp 13f
22226 11:
22227 cmp $2, %rdx
22228@@ -189,9 +189,9 @@ ENTRY(memmove)
22229 * Move data from 2 bytes to 3 bytes.
22230 */
22231 movw (%rsi), %r11w
22232- movw -2(%rsi, %rdx), %r10w
22233+ movw -2(%rsi, %rdx), %r9w
22234 movw %r11w, (%rdi)
22235- movw %r10w, -2(%rdi, %rdx)
22236+ movw %r9w, -2(%rdi, %rdx)
22237 jmp 13f
22238 12:
22239 cmp $1, %rdx
22240@@ -202,6 +202,7 @@ ENTRY(memmove)
22241 movb (%rsi), %r11b
22242 movb %r11b, (%rdi)
22243 13:
22244+ pax_force_retaddr
22245 retq
22246 CFI_ENDPROC
22247
22248@@ -210,6 +211,7 @@ ENTRY(memmove)
22249 /* Forward moving data. */
22250 movq %rdx, %rcx
22251 rep movsb
22252+ pax_force_retaddr
22253 retq
22254 .Lmemmove_end_forward_efs:
22255 .previous
22256diff --git a/arch/x86/lib/memset_64.S b/arch/x86/lib/memset_64.S
22257index 2dcb380..963660a 100644
22258--- a/arch/x86/lib/memset_64.S
22259+++ b/arch/x86/lib/memset_64.S
22260@@ -30,6 +30,7 @@
22261 movl %edx,%ecx
22262 rep stosb
22263 movq %r9,%rax
22264+ pax_force_retaddr
22265 ret
22266 .Lmemset_e:
22267 .previous
22268@@ -52,6 +53,7 @@
22269 movq %rdx,%rcx
22270 rep stosb
22271 movq %r9,%rax
22272+ pax_force_retaddr
22273 ret
22274 .Lmemset_e_e:
22275 .previous
22276@@ -59,7 +61,7 @@
22277 ENTRY(memset)
22278 ENTRY(__memset)
22279 CFI_STARTPROC
22280- movq %rdi,%r10
22281+ movq %rdi,%r11
22282
22283 /* expand byte value */
22284 movzbl %sil,%ecx
22285@@ -117,7 +119,8 @@ ENTRY(__memset)
22286 jnz .Lloop_1
22287
22288 .Lende:
22289- movq %r10,%rax
22290+ movq %r11,%rax
22291+ pax_force_retaddr
22292 ret
22293
22294 CFI_RESTORE_STATE
22295diff --git a/arch/x86/lib/mmx_32.c b/arch/x86/lib/mmx_32.c
22296index c9f2d9b..e7fd2c0 100644
22297--- a/arch/x86/lib/mmx_32.c
22298+++ b/arch/x86/lib/mmx_32.c
22299@@ -29,6 +29,7 @@ void *_mmx_memcpy(void *to, const void *from, size_t len)
22300 {
22301 void *p;
22302 int i;
22303+ unsigned long cr0;
22304
22305 if (unlikely(in_interrupt()))
22306 return __memcpy(to, from, len);
22307@@ -39,44 +40,72 @@ void *_mmx_memcpy(void *to, const void *from, size_t len)
22308 kernel_fpu_begin();
22309
22310 __asm__ __volatile__ (
22311- "1: prefetch (%0)\n" /* This set is 28 bytes */
22312- " prefetch 64(%0)\n"
22313- " prefetch 128(%0)\n"
22314- " prefetch 192(%0)\n"
22315- " prefetch 256(%0)\n"
22316+ "1: prefetch (%1)\n" /* This set is 28 bytes */
22317+ " prefetch 64(%1)\n"
22318+ " prefetch 128(%1)\n"
22319+ " prefetch 192(%1)\n"
22320+ " prefetch 256(%1)\n"
22321 "2: \n"
22322 ".section .fixup, \"ax\"\n"
22323- "3: movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
22324+ "3: \n"
22325+
22326+#ifdef CONFIG_PAX_KERNEXEC
22327+ " movl %%cr0, %0\n"
22328+ " movl %0, %%eax\n"
22329+ " andl $0xFFFEFFFF, %%eax\n"
22330+ " movl %%eax, %%cr0\n"
22331+#endif
22332+
22333+ " movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
22334+
22335+#ifdef CONFIG_PAX_KERNEXEC
22336+ " movl %0, %%cr0\n"
22337+#endif
22338+
22339 " jmp 2b\n"
22340 ".previous\n"
22341 _ASM_EXTABLE(1b, 3b)
22342- : : "r" (from));
22343+ : "=&r" (cr0) : "r" (from) : "ax");
22344
22345 for ( ; i > 5; i--) {
22346 __asm__ __volatile__ (
22347- "1: prefetch 320(%0)\n"
22348- "2: movq (%0), %%mm0\n"
22349- " movq 8(%0), %%mm1\n"
22350- " movq 16(%0), %%mm2\n"
22351- " movq 24(%0), %%mm3\n"
22352- " movq %%mm0, (%1)\n"
22353- " movq %%mm1, 8(%1)\n"
22354- " movq %%mm2, 16(%1)\n"
22355- " movq %%mm3, 24(%1)\n"
22356- " movq 32(%0), %%mm0\n"
22357- " movq 40(%0), %%mm1\n"
22358- " movq 48(%0), %%mm2\n"
22359- " movq 56(%0), %%mm3\n"
22360- " movq %%mm0, 32(%1)\n"
22361- " movq %%mm1, 40(%1)\n"
22362- " movq %%mm2, 48(%1)\n"
22363- " movq %%mm3, 56(%1)\n"
22364+ "1: prefetch 320(%1)\n"
22365+ "2: movq (%1), %%mm0\n"
22366+ " movq 8(%1), %%mm1\n"
22367+ " movq 16(%1), %%mm2\n"
22368+ " movq 24(%1), %%mm3\n"
22369+ " movq %%mm0, (%2)\n"
22370+ " movq %%mm1, 8(%2)\n"
22371+ " movq %%mm2, 16(%2)\n"
22372+ " movq %%mm3, 24(%2)\n"
22373+ " movq 32(%1), %%mm0\n"
22374+ " movq 40(%1), %%mm1\n"
22375+ " movq 48(%1), %%mm2\n"
22376+ " movq 56(%1), %%mm3\n"
22377+ " movq %%mm0, 32(%2)\n"
22378+ " movq %%mm1, 40(%2)\n"
22379+ " movq %%mm2, 48(%2)\n"
22380+ " movq %%mm3, 56(%2)\n"
22381 ".section .fixup, \"ax\"\n"
22382- "3: movw $0x05EB, 1b\n" /* jmp on 5 bytes */
22383+ "3:\n"
22384+
22385+#ifdef CONFIG_PAX_KERNEXEC
22386+ " movl %%cr0, %0\n"
22387+ " movl %0, %%eax\n"
22388+ " andl $0xFFFEFFFF, %%eax\n"
22389+ " movl %%eax, %%cr0\n"
22390+#endif
22391+
22392+ " movw $0x05EB, 1b\n" /* jmp on 5 bytes */
22393+
22394+#ifdef CONFIG_PAX_KERNEXEC
22395+ " movl %0, %%cr0\n"
22396+#endif
22397+
22398 " jmp 2b\n"
22399 ".previous\n"
22400 _ASM_EXTABLE(1b, 3b)
22401- : : "r" (from), "r" (to) : "memory");
22402+ : "=&r" (cr0) : "r" (from), "r" (to) : "memory", "ax");
22403
22404 from += 64;
22405 to += 64;
22406@@ -158,6 +187,7 @@ static void fast_clear_page(void *page)
22407 static void fast_copy_page(void *to, void *from)
22408 {
22409 int i;
22410+ unsigned long cr0;
22411
22412 kernel_fpu_begin();
22413
22414@@ -166,42 +196,70 @@ static void fast_copy_page(void *to, void *from)
22415 * but that is for later. -AV
22416 */
22417 __asm__ __volatile__(
22418- "1: prefetch (%0)\n"
22419- " prefetch 64(%0)\n"
22420- " prefetch 128(%0)\n"
22421- " prefetch 192(%0)\n"
22422- " prefetch 256(%0)\n"
22423+ "1: prefetch (%1)\n"
22424+ " prefetch 64(%1)\n"
22425+ " prefetch 128(%1)\n"
22426+ " prefetch 192(%1)\n"
22427+ " prefetch 256(%1)\n"
22428 "2: \n"
22429 ".section .fixup, \"ax\"\n"
22430- "3: movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
22431+ "3: \n"
22432+
22433+#ifdef CONFIG_PAX_KERNEXEC
22434+ " movl %%cr0, %0\n"
22435+ " movl %0, %%eax\n"
22436+ " andl $0xFFFEFFFF, %%eax\n"
22437+ " movl %%eax, %%cr0\n"
22438+#endif
22439+
22440+ " movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
22441+
22442+#ifdef CONFIG_PAX_KERNEXEC
22443+ " movl %0, %%cr0\n"
22444+#endif
22445+
22446 " jmp 2b\n"
22447 ".previous\n"
22448- _ASM_EXTABLE(1b, 3b) : : "r" (from));
22449+ _ASM_EXTABLE(1b, 3b) : "=&r" (cr0) : "r" (from) : "ax");
22450
22451 for (i = 0; i < (4096-320)/64; i++) {
22452 __asm__ __volatile__ (
22453- "1: prefetch 320(%0)\n"
22454- "2: movq (%0), %%mm0\n"
22455- " movntq %%mm0, (%1)\n"
22456- " movq 8(%0), %%mm1\n"
22457- " movntq %%mm1, 8(%1)\n"
22458- " movq 16(%0), %%mm2\n"
22459- " movntq %%mm2, 16(%1)\n"
22460- " movq 24(%0), %%mm3\n"
22461- " movntq %%mm3, 24(%1)\n"
22462- " movq 32(%0), %%mm4\n"
22463- " movntq %%mm4, 32(%1)\n"
22464- " movq 40(%0), %%mm5\n"
22465- " movntq %%mm5, 40(%1)\n"
22466- " movq 48(%0), %%mm6\n"
22467- " movntq %%mm6, 48(%1)\n"
22468- " movq 56(%0), %%mm7\n"
22469- " movntq %%mm7, 56(%1)\n"
22470+ "1: prefetch 320(%1)\n"
22471+ "2: movq (%1), %%mm0\n"
22472+ " movntq %%mm0, (%2)\n"
22473+ " movq 8(%1), %%mm1\n"
22474+ " movntq %%mm1, 8(%2)\n"
22475+ " movq 16(%1), %%mm2\n"
22476+ " movntq %%mm2, 16(%2)\n"
22477+ " movq 24(%1), %%mm3\n"
22478+ " movntq %%mm3, 24(%2)\n"
22479+ " movq 32(%1), %%mm4\n"
22480+ " movntq %%mm4, 32(%2)\n"
22481+ " movq 40(%1), %%mm5\n"
22482+ " movntq %%mm5, 40(%2)\n"
22483+ " movq 48(%1), %%mm6\n"
22484+ " movntq %%mm6, 48(%2)\n"
22485+ " movq 56(%1), %%mm7\n"
22486+ " movntq %%mm7, 56(%2)\n"
22487 ".section .fixup, \"ax\"\n"
22488- "3: movw $0x05EB, 1b\n" /* jmp on 5 bytes */
22489+ "3:\n"
22490+
22491+#ifdef CONFIG_PAX_KERNEXEC
22492+ " movl %%cr0, %0\n"
22493+ " movl %0, %%eax\n"
22494+ " andl $0xFFFEFFFF, %%eax\n"
22495+ " movl %%eax, %%cr0\n"
22496+#endif
22497+
22498+ " movw $0x05EB, 1b\n" /* jmp on 5 bytes */
22499+
22500+#ifdef CONFIG_PAX_KERNEXEC
22501+ " movl %0, %%cr0\n"
22502+#endif
22503+
22504 " jmp 2b\n"
22505 ".previous\n"
22506- _ASM_EXTABLE(1b, 3b) : : "r" (from), "r" (to) : "memory");
22507+ _ASM_EXTABLE(1b, 3b) : "=&r" (cr0) : "r" (from), "r" (to) : "memory", "ax");
22508
22509 from += 64;
22510 to += 64;
22511@@ -280,47 +338,76 @@ static void fast_clear_page(void *page)
22512 static void fast_copy_page(void *to, void *from)
22513 {
22514 int i;
22515+ unsigned long cr0;
22516
22517 kernel_fpu_begin();
22518
22519 __asm__ __volatile__ (
22520- "1: prefetch (%0)\n"
22521- " prefetch 64(%0)\n"
22522- " prefetch 128(%0)\n"
22523- " prefetch 192(%0)\n"
22524- " prefetch 256(%0)\n"
22525+ "1: prefetch (%1)\n"
22526+ " prefetch 64(%1)\n"
22527+ " prefetch 128(%1)\n"
22528+ " prefetch 192(%1)\n"
22529+ " prefetch 256(%1)\n"
22530 "2: \n"
22531 ".section .fixup, \"ax\"\n"
22532- "3: movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
22533+ "3: \n"
22534+
22535+#ifdef CONFIG_PAX_KERNEXEC
22536+ " movl %%cr0, %0\n"
22537+ " movl %0, %%eax\n"
22538+ " andl $0xFFFEFFFF, %%eax\n"
22539+ " movl %%eax, %%cr0\n"
22540+#endif
22541+
22542+ " movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
22543+
22544+#ifdef CONFIG_PAX_KERNEXEC
22545+ " movl %0, %%cr0\n"
22546+#endif
22547+
22548 " jmp 2b\n"
22549 ".previous\n"
22550- _ASM_EXTABLE(1b, 3b) : : "r" (from));
22551+ _ASM_EXTABLE(1b, 3b) : "=&r" (cr0) : "r" (from) : "ax");
22552
22553 for (i = 0; i < 4096/64; i++) {
22554 __asm__ __volatile__ (
22555- "1: prefetch 320(%0)\n"
22556- "2: movq (%0), %%mm0\n"
22557- " movq 8(%0), %%mm1\n"
22558- " movq 16(%0), %%mm2\n"
22559- " movq 24(%0), %%mm3\n"
22560- " movq %%mm0, (%1)\n"
22561- " movq %%mm1, 8(%1)\n"
22562- " movq %%mm2, 16(%1)\n"
22563- " movq %%mm3, 24(%1)\n"
22564- " movq 32(%0), %%mm0\n"
22565- " movq 40(%0), %%mm1\n"
22566- " movq 48(%0), %%mm2\n"
22567- " movq 56(%0), %%mm3\n"
22568- " movq %%mm0, 32(%1)\n"
22569- " movq %%mm1, 40(%1)\n"
22570- " movq %%mm2, 48(%1)\n"
22571- " movq %%mm3, 56(%1)\n"
22572+ "1: prefetch 320(%1)\n"
22573+ "2: movq (%1), %%mm0\n"
22574+ " movq 8(%1), %%mm1\n"
22575+ " movq 16(%1), %%mm2\n"
22576+ " movq 24(%1), %%mm3\n"
22577+ " movq %%mm0, (%2)\n"
22578+ " movq %%mm1, 8(%2)\n"
22579+ " movq %%mm2, 16(%2)\n"
22580+ " movq %%mm3, 24(%2)\n"
22581+ " movq 32(%1), %%mm0\n"
22582+ " movq 40(%1), %%mm1\n"
22583+ " movq 48(%1), %%mm2\n"
22584+ " movq 56(%1), %%mm3\n"
22585+ " movq %%mm0, 32(%2)\n"
22586+ " movq %%mm1, 40(%2)\n"
22587+ " movq %%mm2, 48(%2)\n"
22588+ " movq %%mm3, 56(%2)\n"
22589 ".section .fixup, \"ax\"\n"
22590- "3: movw $0x05EB, 1b\n" /* jmp on 5 bytes */
22591+ "3:\n"
22592+
22593+#ifdef CONFIG_PAX_KERNEXEC
22594+ " movl %%cr0, %0\n"
22595+ " movl %0, %%eax\n"
22596+ " andl $0xFFFEFFFF, %%eax\n"
22597+ " movl %%eax, %%cr0\n"
22598+#endif
22599+
22600+ " movw $0x05EB, 1b\n" /* jmp on 5 bytes */
22601+
22602+#ifdef CONFIG_PAX_KERNEXEC
22603+ " movl %0, %%cr0\n"
22604+#endif
22605+
22606 " jmp 2b\n"
22607 ".previous\n"
22608 _ASM_EXTABLE(1b, 3b)
22609- : : "r" (from), "r" (to) : "memory");
22610+ : "=&r" (cr0) : "r" (from), "r" (to) : "memory", "ax");
22611
22612 from += 64;
22613 to += 64;
22614diff --git a/arch/x86/lib/msr-reg.S b/arch/x86/lib/msr-reg.S
22615index f6d13ee..aca5f0b 100644
22616--- a/arch/x86/lib/msr-reg.S
22617+++ b/arch/x86/lib/msr-reg.S
22618@@ -3,6 +3,7 @@
22619 #include <asm/dwarf2.h>
22620 #include <asm/asm.h>
22621 #include <asm/msr.h>
22622+#include <asm/alternative-asm.h>
22623
22624 #ifdef CONFIG_X86_64
22625 /*
22626@@ -16,7 +17,7 @@ ENTRY(\op\()_safe_regs)
22627 CFI_STARTPROC
22628 pushq_cfi %rbx
22629 pushq_cfi %rbp
22630- movq %rdi, %r10 /* Save pointer */
22631+ movq %rdi, %r9 /* Save pointer */
22632 xorl %r11d, %r11d /* Return value */
22633 movl (%rdi), %eax
22634 movl 4(%rdi), %ecx
22635@@ -27,16 +28,17 @@ ENTRY(\op\()_safe_regs)
22636 movl 28(%rdi), %edi
22637 CFI_REMEMBER_STATE
22638 1: \op
22639-2: movl %eax, (%r10)
22640+2: movl %eax, (%r9)
22641 movl %r11d, %eax /* Return value */
22642- movl %ecx, 4(%r10)
22643- movl %edx, 8(%r10)
22644- movl %ebx, 12(%r10)
22645- movl %ebp, 20(%r10)
22646- movl %esi, 24(%r10)
22647- movl %edi, 28(%r10)
22648+ movl %ecx, 4(%r9)
22649+ movl %edx, 8(%r9)
22650+ movl %ebx, 12(%r9)
22651+ movl %ebp, 20(%r9)
22652+ movl %esi, 24(%r9)
22653+ movl %edi, 28(%r9)
22654 popq_cfi %rbp
22655 popq_cfi %rbx
22656+ pax_force_retaddr
22657 ret
22658 3:
22659 CFI_RESTORE_STATE
22660diff --git a/arch/x86/lib/putuser.S b/arch/x86/lib/putuser.S
22661index 7f951c8..ebd573a 100644
22662--- a/arch/x86/lib/putuser.S
22663+++ b/arch/x86/lib/putuser.S
22664@@ -15,7 +15,9 @@
22665 #include <asm/thread_info.h>
22666 #include <asm/errno.h>
22667 #include <asm/asm.h>
22668-
22669+#include <asm/segment.h>
22670+#include <asm/pgtable.h>
22671+#include <asm/alternative-asm.h>
22672
22673 /*
22674 * __put_user_X
22675@@ -29,52 +31,119 @@
22676 * as they get called from within inline assembly.
22677 */
22678
22679-#define ENTER CFI_STARTPROC ; \
22680- GET_THREAD_INFO(%_ASM_BX)
22681-#define EXIT ret ; \
22682+#define ENTER CFI_STARTPROC
22683+#define EXIT pax_force_retaddr; ret ; \
22684 CFI_ENDPROC
22685
22686+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
22687+#define _DEST %_ASM_CX,%_ASM_BX
22688+#else
22689+#define _DEST %_ASM_CX
22690+#endif
22691+
22692+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
22693+#define __copyuser_seg gs;
22694+#else
22695+#define __copyuser_seg
22696+#endif
22697+
22698 .text
22699 ENTRY(__put_user_1)
22700 ENTER
22701+
22702+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
22703+ GET_THREAD_INFO(%_ASM_BX)
22704 cmp TI_addr_limit(%_ASM_BX),%_ASM_CX
22705 jae bad_put_user
22706-1: movb %al,(%_ASM_CX)
22707+
22708+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
22709+ mov $PAX_USER_SHADOW_BASE,%_ASM_BX
22710+ cmp %_ASM_BX,%_ASM_CX
22711+ jb 1234f
22712+ xor %ebx,%ebx
22713+1234:
22714+#endif
22715+
22716+#endif
22717+
22718+1: __copyuser_seg movb %al,(_DEST)
22719 xor %eax,%eax
22720 EXIT
22721 ENDPROC(__put_user_1)
22722
22723 ENTRY(__put_user_2)
22724 ENTER
22725+
22726+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
22727+ GET_THREAD_INFO(%_ASM_BX)
22728 mov TI_addr_limit(%_ASM_BX),%_ASM_BX
22729 sub $1,%_ASM_BX
22730 cmp %_ASM_BX,%_ASM_CX
22731 jae bad_put_user
22732-2: movw %ax,(%_ASM_CX)
22733+
22734+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
22735+ mov $PAX_USER_SHADOW_BASE,%_ASM_BX
22736+ cmp %_ASM_BX,%_ASM_CX
22737+ jb 1234f
22738+ xor %ebx,%ebx
22739+1234:
22740+#endif
22741+
22742+#endif
22743+
22744+2: __copyuser_seg movw %ax,(_DEST)
22745 xor %eax,%eax
22746 EXIT
22747 ENDPROC(__put_user_2)
22748
22749 ENTRY(__put_user_4)
22750 ENTER
22751+
22752+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
22753+ GET_THREAD_INFO(%_ASM_BX)
22754 mov TI_addr_limit(%_ASM_BX),%_ASM_BX
22755 sub $3,%_ASM_BX
22756 cmp %_ASM_BX,%_ASM_CX
22757 jae bad_put_user
22758-3: movl %eax,(%_ASM_CX)
22759+
22760+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
22761+ mov $PAX_USER_SHADOW_BASE,%_ASM_BX
22762+ cmp %_ASM_BX,%_ASM_CX
22763+ jb 1234f
22764+ xor %ebx,%ebx
22765+1234:
22766+#endif
22767+
22768+#endif
22769+
22770+3: __copyuser_seg movl %eax,(_DEST)
22771 xor %eax,%eax
22772 EXIT
22773 ENDPROC(__put_user_4)
22774
22775 ENTRY(__put_user_8)
22776 ENTER
22777+
22778+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
22779+ GET_THREAD_INFO(%_ASM_BX)
22780 mov TI_addr_limit(%_ASM_BX),%_ASM_BX
22781 sub $7,%_ASM_BX
22782 cmp %_ASM_BX,%_ASM_CX
22783 jae bad_put_user
22784-4: mov %_ASM_AX,(%_ASM_CX)
22785+
22786+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
22787+ mov $PAX_USER_SHADOW_BASE,%_ASM_BX
22788+ cmp %_ASM_BX,%_ASM_CX
22789+ jb 1234f
22790+ xor %ebx,%ebx
22791+1234:
22792+#endif
22793+
22794+#endif
22795+
22796+4: __copyuser_seg mov %_ASM_AX,(_DEST)
22797 #ifdef CONFIG_X86_32
22798-5: movl %edx,4(%_ASM_CX)
22799+5: __copyuser_seg movl %edx,4(_DEST)
22800 #endif
22801 xor %eax,%eax
22802 EXIT
22803diff --git a/arch/x86/lib/rwlock.S b/arch/x86/lib/rwlock.S
22804index 1cad221..de671ee 100644
22805--- a/arch/x86/lib/rwlock.S
22806+++ b/arch/x86/lib/rwlock.S
22807@@ -16,13 +16,34 @@ ENTRY(__write_lock_failed)
22808 FRAME
22809 0: LOCK_PREFIX
22810 WRITE_LOCK_ADD($RW_LOCK_BIAS) (%__lock_ptr)
22811+
22812+#ifdef CONFIG_PAX_REFCOUNT
22813+ jno 1234f
22814+ LOCK_PREFIX
22815+ WRITE_LOCK_SUB($RW_LOCK_BIAS) (%__lock_ptr)
22816+ int $4
22817+1234:
22818+ _ASM_EXTABLE(1234b, 1234b)
22819+#endif
22820+
22821 1: rep; nop
22822 cmpl $WRITE_LOCK_CMP, (%__lock_ptr)
22823 jne 1b
22824 LOCK_PREFIX
22825 WRITE_LOCK_SUB($RW_LOCK_BIAS) (%__lock_ptr)
22826+
22827+#ifdef CONFIG_PAX_REFCOUNT
22828+ jno 1234f
22829+ LOCK_PREFIX
22830+ WRITE_LOCK_ADD($RW_LOCK_BIAS) (%__lock_ptr)
22831+ int $4
22832+1234:
22833+ _ASM_EXTABLE(1234b, 1234b)
22834+#endif
22835+
22836 jnz 0b
22837 ENDFRAME
22838+ pax_force_retaddr
22839 ret
22840 CFI_ENDPROC
22841 END(__write_lock_failed)
22842@@ -32,13 +53,34 @@ ENTRY(__read_lock_failed)
22843 FRAME
22844 0: LOCK_PREFIX
22845 READ_LOCK_SIZE(inc) (%__lock_ptr)
22846+
22847+#ifdef CONFIG_PAX_REFCOUNT
22848+ jno 1234f
22849+ LOCK_PREFIX
22850+ READ_LOCK_SIZE(dec) (%__lock_ptr)
22851+ int $4
22852+1234:
22853+ _ASM_EXTABLE(1234b, 1234b)
22854+#endif
22855+
22856 1: rep; nop
22857 READ_LOCK_SIZE(cmp) $1, (%__lock_ptr)
22858 js 1b
22859 LOCK_PREFIX
22860 READ_LOCK_SIZE(dec) (%__lock_ptr)
22861+
22862+#ifdef CONFIG_PAX_REFCOUNT
22863+ jno 1234f
22864+ LOCK_PREFIX
22865+ READ_LOCK_SIZE(inc) (%__lock_ptr)
22866+ int $4
22867+1234:
22868+ _ASM_EXTABLE(1234b, 1234b)
22869+#endif
22870+
22871 js 0b
22872 ENDFRAME
22873+ pax_force_retaddr
22874 ret
22875 CFI_ENDPROC
22876 END(__read_lock_failed)
22877diff --git a/arch/x86/lib/rwsem.S b/arch/x86/lib/rwsem.S
22878index 5dff5f0..cadebf4 100644
22879--- a/arch/x86/lib/rwsem.S
22880+++ b/arch/x86/lib/rwsem.S
22881@@ -94,6 +94,7 @@ ENTRY(call_rwsem_down_read_failed)
22882 __ASM_SIZE(pop,_cfi) %__ASM_REG(dx)
22883 CFI_RESTORE __ASM_REG(dx)
22884 restore_common_regs
22885+ pax_force_retaddr
22886 ret
22887 CFI_ENDPROC
22888 ENDPROC(call_rwsem_down_read_failed)
22889@@ -104,6 +105,7 @@ ENTRY(call_rwsem_down_write_failed)
22890 movq %rax,%rdi
22891 call rwsem_down_write_failed
22892 restore_common_regs
22893+ pax_force_retaddr
22894 ret
22895 CFI_ENDPROC
22896 ENDPROC(call_rwsem_down_write_failed)
22897@@ -117,7 +119,8 @@ ENTRY(call_rwsem_wake)
22898 movq %rax,%rdi
22899 call rwsem_wake
22900 restore_common_regs
22901-1: ret
22902+1: pax_force_retaddr
22903+ ret
22904 CFI_ENDPROC
22905 ENDPROC(call_rwsem_wake)
22906
22907@@ -131,6 +134,7 @@ ENTRY(call_rwsem_downgrade_wake)
22908 __ASM_SIZE(pop,_cfi) %__ASM_REG(dx)
22909 CFI_RESTORE __ASM_REG(dx)
22910 restore_common_regs
22911+ pax_force_retaddr
22912 ret
22913 CFI_ENDPROC
22914 ENDPROC(call_rwsem_downgrade_wake)
22915diff --git a/arch/x86/lib/thunk_64.S b/arch/x86/lib/thunk_64.S
22916index a63efd6..ccecad8 100644
22917--- a/arch/x86/lib/thunk_64.S
22918+++ b/arch/x86/lib/thunk_64.S
22919@@ -8,6 +8,7 @@
22920 #include <linux/linkage.h>
22921 #include <asm/dwarf2.h>
22922 #include <asm/calling.h>
22923+#include <asm/alternative-asm.h>
22924
22925 /* rdi: arg1 ... normal C conventions. rax is saved/restored. */
22926 .macro THUNK name, func, put_ret_addr_in_rdi=0
22927@@ -41,5 +42,6 @@
22928 SAVE_ARGS
22929 restore:
22930 RESTORE_ARGS
22931+ pax_force_retaddr
22932 ret
22933 CFI_ENDPROC
22934diff --git a/arch/x86/lib/usercopy_32.c b/arch/x86/lib/usercopy_32.c
22935index 1781b2f..90368dd 100644
22936--- a/arch/x86/lib/usercopy_32.c
22937+++ b/arch/x86/lib/usercopy_32.c
22938@@ -42,10 +42,12 @@ do { \
22939 int __d0; \
22940 might_fault(); \
22941 __asm__ __volatile__( \
22942+ __COPYUSER_SET_ES \
22943 "0: rep; stosl\n" \
22944 " movl %2,%0\n" \
22945 "1: rep; stosb\n" \
22946 "2:\n" \
22947+ __COPYUSER_RESTORE_ES \
22948 ".section .fixup,\"ax\"\n" \
22949 "3: lea 0(%2,%0,4),%0\n" \
22950 " jmp 2b\n" \
22951@@ -97,7 +99,7 @@ EXPORT_SYMBOL(__clear_user);
22952
22953 #ifdef CONFIG_X86_INTEL_USERCOPY
22954 static unsigned long
22955-__copy_user_intel(void __user *to, const void *from, unsigned long size)
22956+__generic_copy_to_user_intel(void __user *to, const void *from, unsigned long size)
22957 {
22958 int d0, d1;
22959 __asm__ __volatile__(
22960@@ -109,36 +111,36 @@ __copy_user_intel(void __user *to, const void *from, unsigned long size)
22961 " .align 2,0x90\n"
22962 "3: movl 0(%4), %%eax\n"
22963 "4: movl 4(%4), %%edx\n"
22964- "5: movl %%eax, 0(%3)\n"
22965- "6: movl %%edx, 4(%3)\n"
22966+ "5: "__copyuser_seg" movl %%eax, 0(%3)\n"
22967+ "6: "__copyuser_seg" movl %%edx, 4(%3)\n"
22968 "7: movl 8(%4), %%eax\n"
22969 "8: movl 12(%4),%%edx\n"
22970- "9: movl %%eax, 8(%3)\n"
22971- "10: movl %%edx, 12(%3)\n"
22972+ "9: "__copyuser_seg" movl %%eax, 8(%3)\n"
22973+ "10: "__copyuser_seg" movl %%edx, 12(%3)\n"
22974 "11: movl 16(%4), %%eax\n"
22975 "12: movl 20(%4), %%edx\n"
22976- "13: movl %%eax, 16(%3)\n"
22977- "14: movl %%edx, 20(%3)\n"
22978+ "13: "__copyuser_seg" movl %%eax, 16(%3)\n"
22979+ "14: "__copyuser_seg" movl %%edx, 20(%3)\n"
22980 "15: movl 24(%4), %%eax\n"
22981 "16: movl 28(%4), %%edx\n"
22982- "17: movl %%eax, 24(%3)\n"
22983- "18: movl %%edx, 28(%3)\n"
22984+ "17: "__copyuser_seg" movl %%eax, 24(%3)\n"
22985+ "18: "__copyuser_seg" movl %%edx, 28(%3)\n"
22986 "19: movl 32(%4), %%eax\n"
22987 "20: movl 36(%4), %%edx\n"
22988- "21: movl %%eax, 32(%3)\n"
22989- "22: movl %%edx, 36(%3)\n"
22990+ "21: "__copyuser_seg" movl %%eax, 32(%3)\n"
22991+ "22: "__copyuser_seg" movl %%edx, 36(%3)\n"
22992 "23: movl 40(%4), %%eax\n"
22993 "24: movl 44(%4), %%edx\n"
22994- "25: movl %%eax, 40(%3)\n"
22995- "26: movl %%edx, 44(%3)\n"
22996+ "25: "__copyuser_seg" movl %%eax, 40(%3)\n"
22997+ "26: "__copyuser_seg" movl %%edx, 44(%3)\n"
22998 "27: movl 48(%4), %%eax\n"
22999 "28: movl 52(%4), %%edx\n"
23000- "29: movl %%eax, 48(%3)\n"
23001- "30: movl %%edx, 52(%3)\n"
23002+ "29: "__copyuser_seg" movl %%eax, 48(%3)\n"
23003+ "30: "__copyuser_seg" movl %%edx, 52(%3)\n"
23004 "31: movl 56(%4), %%eax\n"
23005 "32: movl 60(%4), %%edx\n"
23006- "33: movl %%eax, 56(%3)\n"
23007- "34: movl %%edx, 60(%3)\n"
23008+ "33: "__copyuser_seg" movl %%eax, 56(%3)\n"
23009+ "34: "__copyuser_seg" movl %%edx, 60(%3)\n"
23010 " addl $-64, %0\n"
23011 " addl $64, %4\n"
23012 " addl $64, %3\n"
23013@@ -148,10 +150,12 @@ __copy_user_intel(void __user *to, const void *from, unsigned long size)
23014 " shrl $2, %0\n"
23015 " andl $3, %%eax\n"
23016 " cld\n"
23017+ __COPYUSER_SET_ES
23018 "99: rep; movsl\n"
23019 "36: movl %%eax, %0\n"
23020 "37: rep; movsb\n"
23021 "100:\n"
23022+ __COPYUSER_RESTORE_ES
23023 ".section .fixup,\"ax\"\n"
23024 "101: lea 0(%%eax,%0,4),%0\n"
23025 " jmp 100b\n"
23026@@ -201,46 +205,150 @@ __copy_user_intel(void __user *to, const void *from, unsigned long size)
23027 }
23028
23029 static unsigned long
23030+__generic_copy_from_user_intel(void *to, const void __user *from, unsigned long size)
23031+{
23032+ int d0, d1;
23033+ __asm__ __volatile__(
23034+ " .align 2,0x90\n"
23035+ "1: "__copyuser_seg" movl 32(%4), %%eax\n"
23036+ " cmpl $67, %0\n"
23037+ " jbe 3f\n"
23038+ "2: "__copyuser_seg" movl 64(%4), %%eax\n"
23039+ " .align 2,0x90\n"
23040+ "3: "__copyuser_seg" movl 0(%4), %%eax\n"
23041+ "4: "__copyuser_seg" movl 4(%4), %%edx\n"
23042+ "5: movl %%eax, 0(%3)\n"
23043+ "6: movl %%edx, 4(%3)\n"
23044+ "7: "__copyuser_seg" movl 8(%4), %%eax\n"
23045+ "8: "__copyuser_seg" movl 12(%4),%%edx\n"
23046+ "9: movl %%eax, 8(%3)\n"
23047+ "10: movl %%edx, 12(%3)\n"
23048+ "11: "__copyuser_seg" movl 16(%4), %%eax\n"
23049+ "12: "__copyuser_seg" movl 20(%4), %%edx\n"
23050+ "13: movl %%eax, 16(%3)\n"
23051+ "14: movl %%edx, 20(%3)\n"
23052+ "15: "__copyuser_seg" movl 24(%4), %%eax\n"
23053+ "16: "__copyuser_seg" movl 28(%4), %%edx\n"
23054+ "17: movl %%eax, 24(%3)\n"
23055+ "18: movl %%edx, 28(%3)\n"
23056+ "19: "__copyuser_seg" movl 32(%4), %%eax\n"
23057+ "20: "__copyuser_seg" movl 36(%4), %%edx\n"
23058+ "21: movl %%eax, 32(%3)\n"
23059+ "22: movl %%edx, 36(%3)\n"
23060+ "23: "__copyuser_seg" movl 40(%4), %%eax\n"
23061+ "24: "__copyuser_seg" movl 44(%4), %%edx\n"
23062+ "25: movl %%eax, 40(%3)\n"
23063+ "26: movl %%edx, 44(%3)\n"
23064+ "27: "__copyuser_seg" movl 48(%4), %%eax\n"
23065+ "28: "__copyuser_seg" movl 52(%4), %%edx\n"
23066+ "29: movl %%eax, 48(%3)\n"
23067+ "30: movl %%edx, 52(%3)\n"
23068+ "31: "__copyuser_seg" movl 56(%4), %%eax\n"
23069+ "32: "__copyuser_seg" movl 60(%4), %%edx\n"
23070+ "33: movl %%eax, 56(%3)\n"
23071+ "34: movl %%edx, 60(%3)\n"
23072+ " addl $-64, %0\n"
23073+ " addl $64, %4\n"
23074+ " addl $64, %3\n"
23075+ " cmpl $63, %0\n"
23076+ " ja 1b\n"
23077+ "35: movl %0, %%eax\n"
23078+ " shrl $2, %0\n"
23079+ " andl $3, %%eax\n"
23080+ " cld\n"
23081+ "99: rep; "__copyuser_seg" movsl\n"
23082+ "36: movl %%eax, %0\n"
23083+ "37: rep; "__copyuser_seg" movsb\n"
23084+ "100:\n"
23085+ ".section .fixup,\"ax\"\n"
23086+ "101: lea 0(%%eax,%0,4),%0\n"
23087+ " jmp 100b\n"
23088+ ".previous\n"
23089+ _ASM_EXTABLE(1b,100b)
23090+ _ASM_EXTABLE(2b,100b)
23091+ _ASM_EXTABLE(3b,100b)
23092+ _ASM_EXTABLE(4b,100b)
23093+ _ASM_EXTABLE(5b,100b)
23094+ _ASM_EXTABLE(6b,100b)
23095+ _ASM_EXTABLE(7b,100b)
23096+ _ASM_EXTABLE(8b,100b)
23097+ _ASM_EXTABLE(9b,100b)
23098+ _ASM_EXTABLE(10b,100b)
23099+ _ASM_EXTABLE(11b,100b)
23100+ _ASM_EXTABLE(12b,100b)
23101+ _ASM_EXTABLE(13b,100b)
23102+ _ASM_EXTABLE(14b,100b)
23103+ _ASM_EXTABLE(15b,100b)
23104+ _ASM_EXTABLE(16b,100b)
23105+ _ASM_EXTABLE(17b,100b)
23106+ _ASM_EXTABLE(18b,100b)
23107+ _ASM_EXTABLE(19b,100b)
23108+ _ASM_EXTABLE(20b,100b)
23109+ _ASM_EXTABLE(21b,100b)
23110+ _ASM_EXTABLE(22b,100b)
23111+ _ASM_EXTABLE(23b,100b)
23112+ _ASM_EXTABLE(24b,100b)
23113+ _ASM_EXTABLE(25b,100b)
23114+ _ASM_EXTABLE(26b,100b)
23115+ _ASM_EXTABLE(27b,100b)
23116+ _ASM_EXTABLE(28b,100b)
23117+ _ASM_EXTABLE(29b,100b)
23118+ _ASM_EXTABLE(30b,100b)
23119+ _ASM_EXTABLE(31b,100b)
23120+ _ASM_EXTABLE(32b,100b)
23121+ _ASM_EXTABLE(33b,100b)
23122+ _ASM_EXTABLE(34b,100b)
23123+ _ASM_EXTABLE(35b,100b)
23124+ _ASM_EXTABLE(36b,100b)
23125+ _ASM_EXTABLE(37b,100b)
23126+ _ASM_EXTABLE(99b,101b)
23127+ : "=&c"(size), "=&D" (d0), "=&S" (d1)
23128+ : "1"(to), "2"(from), "0"(size)
23129+ : "eax", "edx", "memory");
23130+ return size;
23131+}
23132+
23133+static unsigned long __size_overflow(3)
23134 __copy_user_zeroing_intel(void *to, const void __user *from, unsigned long size)
23135 {
23136 int d0, d1;
23137 __asm__ __volatile__(
23138 " .align 2,0x90\n"
23139- "0: movl 32(%4), %%eax\n"
23140+ "0: "__copyuser_seg" movl 32(%4), %%eax\n"
23141 " cmpl $67, %0\n"
23142 " jbe 2f\n"
23143- "1: movl 64(%4), %%eax\n"
23144+ "1: "__copyuser_seg" movl 64(%4), %%eax\n"
23145 " .align 2,0x90\n"
23146- "2: movl 0(%4), %%eax\n"
23147- "21: movl 4(%4), %%edx\n"
23148+ "2: "__copyuser_seg" movl 0(%4), %%eax\n"
23149+ "21: "__copyuser_seg" movl 4(%4), %%edx\n"
23150 " movl %%eax, 0(%3)\n"
23151 " movl %%edx, 4(%3)\n"
23152- "3: movl 8(%4), %%eax\n"
23153- "31: movl 12(%4),%%edx\n"
23154+ "3: "__copyuser_seg" movl 8(%4), %%eax\n"
23155+ "31: "__copyuser_seg" movl 12(%4),%%edx\n"
23156 " movl %%eax, 8(%3)\n"
23157 " movl %%edx, 12(%3)\n"
23158- "4: movl 16(%4), %%eax\n"
23159- "41: movl 20(%4), %%edx\n"
23160+ "4: "__copyuser_seg" movl 16(%4), %%eax\n"
23161+ "41: "__copyuser_seg" movl 20(%4), %%edx\n"
23162 " movl %%eax, 16(%3)\n"
23163 " movl %%edx, 20(%3)\n"
23164- "10: movl 24(%4), %%eax\n"
23165- "51: movl 28(%4), %%edx\n"
23166+ "10: "__copyuser_seg" movl 24(%4), %%eax\n"
23167+ "51: "__copyuser_seg" movl 28(%4), %%edx\n"
23168 " movl %%eax, 24(%3)\n"
23169 " movl %%edx, 28(%3)\n"
23170- "11: movl 32(%4), %%eax\n"
23171- "61: movl 36(%4), %%edx\n"
23172+ "11: "__copyuser_seg" movl 32(%4), %%eax\n"
23173+ "61: "__copyuser_seg" movl 36(%4), %%edx\n"
23174 " movl %%eax, 32(%3)\n"
23175 " movl %%edx, 36(%3)\n"
23176- "12: movl 40(%4), %%eax\n"
23177- "71: movl 44(%4), %%edx\n"
23178+ "12: "__copyuser_seg" movl 40(%4), %%eax\n"
23179+ "71: "__copyuser_seg" movl 44(%4), %%edx\n"
23180 " movl %%eax, 40(%3)\n"
23181 " movl %%edx, 44(%3)\n"
23182- "13: movl 48(%4), %%eax\n"
23183- "81: movl 52(%4), %%edx\n"
23184+ "13: "__copyuser_seg" movl 48(%4), %%eax\n"
23185+ "81: "__copyuser_seg" movl 52(%4), %%edx\n"
23186 " movl %%eax, 48(%3)\n"
23187 " movl %%edx, 52(%3)\n"
23188- "14: movl 56(%4), %%eax\n"
23189- "91: movl 60(%4), %%edx\n"
23190+ "14: "__copyuser_seg" movl 56(%4), %%eax\n"
23191+ "91: "__copyuser_seg" movl 60(%4), %%edx\n"
23192 " movl %%eax, 56(%3)\n"
23193 " movl %%edx, 60(%3)\n"
23194 " addl $-64, %0\n"
23195@@ -252,9 +360,9 @@ __copy_user_zeroing_intel(void *to, const void __user *from, unsigned long size)
23196 " shrl $2, %0\n"
23197 " andl $3, %%eax\n"
23198 " cld\n"
23199- "6: rep; movsl\n"
23200+ "6: rep; "__copyuser_seg" movsl\n"
23201 " movl %%eax,%0\n"
23202- "7: rep; movsb\n"
23203+ "7: rep; "__copyuser_seg" movsb\n"
23204 "8:\n"
23205 ".section .fixup,\"ax\"\n"
23206 "9: lea 0(%%eax,%0,4),%0\n"
23207@@ -297,48 +405,48 @@ __copy_user_zeroing_intel(void *to, const void __user *from, unsigned long size)
23208 * hyoshiok@miraclelinux.com
23209 */
23210
23211-static unsigned long __copy_user_zeroing_intel_nocache(void *to,
23212+static unsigned long __size_overflow(3) __copy_user_zeroing_intel_nocache(void *to,
23213 const void __user *from, unsigned long size)
23214 {
23215 int d0, d1;
23216
23217 __asm__ __volatile__(
23218 " .align 2,0x90\n"
23219- "0: movl 32(%4), %%eax\n"
23220+ "0: "__copyuser_seg" movl 32(%4), %%eax\n"
23221 " cmpl $67, %0\n"
23222 " jbe 2f\n"
23223- "1: movl 64(%4), %%eax\n"
23224+ "1: "__copyuser_seg" movl 64(%4), %%eax\n"
23225 " .align 2,0x90\n"
23226- "2: movl 0(%4), %%eax\n"
23227- "21: movl 4(%4), %%edx\n"
23228+ "2: "__copyuser_seg" movl 0(%4), %%eax\n"
23229+ "21: "__copyuser_seg" movl 4(%4), %%edx\n"
23230 " movnti %%eax, 0(%3)\n"
23231 " movnti %%edx, 4(%3)\n"
23232- "3: movl 8(%4), %%eax\n"
23233- "31: movl 12(%4),%%edx\n"
23234+ "3: "__copyuser_seg" movl 8(%4), %%eax\n"
23235+ "31: "__copyuser_seg" movl 12(%4),%%edx\n"
23236 " movnti %%eax, 8(%3)\n"
23237 " movnti %%edx, 12(%3)\n"
23238- "4: movl 16(%4), %%eax\n"
23239- "41: movl 20(%4), %%edx\n"
23240+ "4: "__copyuser_seg" movl 16(%4), %%eax\n"
23241+ "41: "__copyuser_seg" movl 20(%4), %%edx\n"
23242 " movnti %%eax, 16(%3)\n"
23243 " movnti %%edx, 20(%3)\n"
23244- "10: movl 24(%4), %%eax\n"
23245- "51: movl 28(%4), %%edx\n"
23246+ "10: "__copyuser_seg" movl 24(%4), %%eax\n"
23247+ "51: "__copyuser_seg" movl 28(%4), %%edx\n"
23248 " movnti %%eax, 24(%3)\n"
23249 " movnti %%edx, 28(%3)\n"
23250- "11: movl 32(%4), %%eax\n"
23251- "61: movl 36(%4), %%edx\n"
23252+ "11: "__copyuser_seg" movl 32(%4), %%eax\n"
23253+ "61: "__copyuser_seg" movl 36(%4), %%edx\n"
23254 " movnti %%eax, 32(%3)\n"
23255 " movnti %%edx, 36(%3)\n"
23256- "12: movl 40(%4), %%eax\n"
23257- "71: movl 44(%4), %%edx\n"
23258+ "12: "__copyuser_seg" movl 40(%4), %%eax\n"
23259+ "71: "__copyuser_seg" movl 44(%4), %%edx\n"
23260 " movnti %%eax, 40(%3)\n"
23261 " movnti %%edx, 44(%3)\n"
23262- "13: movl 48(%4), %%eax\n"
23263- "81: movl 52(%4), %%edx\n"
23264+ "13: "__copyuser_seg" movl 48(%4), %%eax\n"
23265+ "81: "__copyuser_seg" movl 52(%4), %%edx\n"
23266 " movnti %%eax, 48(%3)\n"
23267 " movnti %%edx, 52(%3)\n"
23268- "14: movl 56(%4), %%eax\n"
23269- "91: movl 60(%4), %%edx\n"
23270+ "14: "__copyuser_seg" movl 56(%4), %%eax\n"
23271+ "91: "__copyuser_seg" movl 60(%4), %%edx\n"
23272 " movnti %%eax, 56(%3)\n"
23273 " movnti %%edx, 60(%3)\n"
23274 " addl $-64, %0\n"
23275@@ -351,9 +459,9 @@ static unsigned long __copy_user_zeroing_intel_nocache(void *to,
23276 " shrl $2, %0\n"
23277 " andl $3, %%eax\n"
23278 " cld\n"
23279- "6: rep; movsl\n"
23280+ "6: rep; "__copyuser_seg" movsl\n"
23281 " movl %%eax,%0\n"
23282- "7: rep; movsb\n"
23283+ "7: rep; "__copyuser_seg" movsb\n"
23284 "8:\n"
23285 ".section .fixup,\"ax\"\n"
23286 "9: lea 0(%%eax,%0,4),%0\n"
23287@@ -391,48 +499,48 @@ static unsigned long __copy_user_zeroing_intel_nocache(void *to,
23288 return size;
23289 }
23290
23291-static unsigned long __copy_user_intel_nocache(void *to,
23292+static unsigned long __size_overflow(3) __copy_user_intel_nocache(void *to,
23293 const void __user *from, unsigned long size)
23294 {
23295 int d0, d1;
23296
23297 __asm__ __volatile__(
23298 " .align 2,0x90\n"
23299- "0: movl 32(%4), %%eax\n"
23300+ "0: "__copyuser_seg" movl 32(%4), %%eax\n"
23301 " cmpl $67, %0\n"
23302 " jbe 2f\n"
23303- "1: movl 64(%4), %%eax\n"
23304+ "1: "__copyuser_seg" movl 64(%4), %%eax\n"
23305 " .align 2,0x90\n"
23306- "2: movl 0(%4), %%eax\n"
23307- "21: movl 4(%4), %%edx\n"
23308+ "2: "__copyuser_seg" movl 0(%4), %%eax\n"
23309+ "21: "__copyuser_seg" movl 4(%4), %%edx\n"
23310 " movnti %%eax, 0(%3)\n"
23311 " movnti %%edx, 4(%3)\n"
23312- "3: movl 8(%4), %%eax\n"
23313- "31: movl 12(%4),%%edx\n"
23314+ "3: "__copyuser_seg" movl 8(%4), %%eax\n"
23315+ "31: "__copyuser_seg" movl 12(%4),%%edx\n"
23316 " movnti %%eax, 8(%3)\n"
23317 " movnti %%edx, 12(%3)\n"
23318- "4: movl 16(%4), %%eax\n"
23319- "41: movl 20(%4), %%edx\n"
23320+ "4: "__copyuser_seg" movl 16(%4), %%eax\n"
23321+ "41: "__copyuser_seg" movl 20(%4), %%edx\n"
23322 " movnti %%eax, 16(%3)\n"
23323 " movnti %%edx, 20(%3)\n"
23324- "10: movl 24(%4), %%eax\n"
23325- "51: movl 28(%4), %%edx\n"
23326+ "10: "__copyuser_seg" movl 24(%4), %%eax\n"
23327+ "51: "__copyuser_seg" movl 28(%4), %%edx\n"
23328 " movnti %%eax, 24(%3)\n"
23329 " movnti %%edx, 28(%3)\n"
23330- "11: movl 32(%4), %%eax\n"
23331- "61: movl 36(%4), %%edx\n"
23332+ "11: "__copyuser_seg" movl 32(%4), %%eax\n"
23333+ "61: "__copyuser_seg" movl 36(%4), %%edx\n"
23334 " movnti %%eax, 32(%3)\n"
23335 " movnti %%edx, 36(%3)\n"
23336- "12: movl 40(%4), %%eax\n"
23337- "71: movl 44(%4), %%edx\n"
23338+ "12: "__copyuser_seg" movl 40(%4), %%eax\n"
23339+ "71: "__copyuser_seg" movl 44(%4), %%edx\n"
23340 " movnti %%eax, 40(%3)\n"
23341 " movnti %%edx, 44(%3)\n"
23342- "13: movl 48(%4), %%eax\n"
23343- "81: movl 52(%4), %%edx\n"
23344+ "13: "__copyuser_seg" movl 48(%4), %%eax\n"
23345+ "81: "__copyuser_seg" movl 52(%4), %%edx\n"
23346 " movnti %%eax, 48(%3)\n"
23347 " movnti %%edx, 52(%3)\n"
23348- "14: movl 56(%4), %%eax\n"
23349- "91: movl 60(%4), %%edx\n"
23350+ "14: "__copyuser_seg" movl 56(%4), %%eax\n"
23351+ "91: "__copyuser_seg" movl 60(%4), %%edx\n"
23352 " movnti %%eax, 56(%3)\n"
23353 " movnti %%edx, 60(%3)\n"
23354 " addl $-64, %0\n"
23355@@ -445,9 +553,9 @@ static unsigned long __copy_user_intel_nocache(void *to,
23356 " shrl $2, %0\n"
23357 " andl $3, %%eax\n"
23358 " cld\n"
23359- "6: rep; movsl\n"
23360+ "6: rep; "__copyuser_seg" movsl\n"
23361 " movl %%eax,%0\n"
23362- "7: rep; movsb\n"
23363+ "7: rep; "__copyuser_seg" movsb\n"
23364 "8:\n"
23365 ".section .fixup,\"ax\"\n"
23366 "9: lea 0(%%eax,%0,4),%0\n"
23367@@ -487,32 +595,36 @@ static unsigned long __copy_user_intel_nocache(void *to,
23368 */
23369 unsigned long __copy_user_zeroing_intel(void *to, const void __user *from,
23370 unsigned long size);
23371-unsigned long __copy_user_intel(void __user *to, const void *from,
23372+unsigned long __generic_copy_to_user_intel(void __user *to, const void *from,
23373+ unsigned long size);
23374+unsigned long __generic_copy_from_user_intel(void *to, const void __user *from,
23375 unsigned long size);
23376 unsigned long __copy_user_zeroing_intel_nocache(void *to,
23377 const void __user *from, unsigned long size);
23378 #endif /* CONFIG_X86_INTEL_USERCOPY */
23379
23380 /* Generic arbitrary sized copy. */
23381-#define __copy_user(to, from, size) \
23382+#define __copy_user(to, from, size, prefix, set, restore) \
23383 do { \
23384 int __d0, __d1, __d2; \
23385 __asm__ __volatile__( \
23386+ set \
23387 " cmp $7,%0\n" \
23388 " jbe 1f\n" \
23389 " movl %1,%0\n" \
23390 " negl %0\n" \
23391 " andl $7,%0\n" \
23392 " subl %0,%3\n" \
23393- "4: rep; movsb\n" \
23394+ "4: rep; "prefix"movsb\n" \
23395 " movl %3,%0\n" \
23396 " shrl $2,%0\n" \
23397 " andl $3,%3\n" \
23398 " .align 2,0x90\n" \
23399- "0: rep; movsl\n" \
23400+ "0: rep; "prefix"movsl\n" \
23401 " movl %3,%0\n" \
23402- "1: rep; movsb\n" \
23403+ "1: rep; "prefix"movsb\n" \
23404 "2:\n" \
23405+ restore \
23406 ".section .fixup,\"ax\"\n" \
23407 "5: addl %3,%0\n" \
23408 " jmp 2b\n" \
23409@@ -537,14 +649,14 @@ do { \
23410 " negl %0\n" \
23411 " andl $7,%0\n" \
23412 " subl %0,%3\n" \
23413- "4: rep; movsb\n" \
23414+ "4: rep; "__copyuser_seg"movsb\n" \
23415 " movl %3,%0\n" \
23416 " shrl $2,%0\n" \
23417 " andl $3,%3\n" \
23418 " .align 2,0x90\n" \
23419- "0: rep; movsl\n" \
23420+ "0: rep; "__copyuser_seg"movsl\n" \
23421 " movl %3,%0\n" \
23422- "1: rep; movsb\n" \
23423+ "1: rep; "__copyuser_seg"movsb\n" \
23424 "2:\n" \
23425 ".section .fixup,\"ax\"\n" \
23426 "5: addl %3,%0\n" \
23427@@ -627,9 +739,9 @@ survive:
23428 }
23429 #endif
23430 if (movsl_is_ok(to, from, n))
23431- __copy_user(to, from, n);
23432+ __copy_user(to, from, n, "", __COPYUSER_SET_ES, __COPYUSER_RESTORE_ES);
23433 else
23434- n = __copy_user_intel(to, from, n);
23435+ n = __generic_copy_to_user_intel(to, from, n);
23436 return n;
23437 }
23438 EXPORT_SYMBOL(__copy_to_user_ll);
23439@@ -649,10 +761,9 @@ unsigned long __copy_from_user_ll_nozero(void *to, const void __user *from,
23440 unsigned long n)
23441 {
23442 if (movsl_is_ok(to, from, n))
23443- __copy_user(to, from, n);
23444+ __copy_user(to, from, n, __copyuser_seg, "", "");
23445 else
23446- n = __copy_user_intel((void __user *)to,
23447- (const void *)from, n);
23448+ n = __generic_copy_from_user_intel(to, from, n);
23449 return n;
23450 }
23451 EXPORT_SYMBOL(__copy_from_user_ll_nozero);
23452@@ -679,65 +790,50 @@ unsigned long __copy_from_user_ll_nocache_nozero(void *to, const void __user *fr
23453 if (n > 64 && cpu_has_xmm2)
23454 n = __copy_user_intel_nocache(to, from, n);
23455 else
23456- __copy_user(to, from, n);
23457+ __copy_user(to, from, n, __copyuser_seg, "", "");
23458 #else
23459- __copy_user(to, from, n);
23460+ __copy_user(to, from, n, __copyuser_seg, "", "");
23461 #endif
23462 return n;
23463 }
23464 EXPORT_SYMBOL(__copy_from_user_ll_nocache_nozero);
23465
23466-/**
23467- * copy_to_user: - Copy a block of data into user space.
23468- * @to: Destination address, in user space.
23469- * @from: Source address, in kernel space.
23470- * @n: Number of bytes to copy.
23471- *
23472- * Context: User context only. This function may sleep.
23473- *
23474- * Copy data from kernel space to user space.
23475- *
23476- * Returns number of bytes that could not be copied.
23477- * On success, this will be zero.
23478- */
23479-unsigned long
23480-copy_to_user(void __user *to, const void *from, unsigned long n)
23481-{
23482- if (access_ok(VERIFY_WRITE, to, n))
23483- n = __copy_to_user(to, from, n);
23484- return n;
23485-}
23486-EXPORT_SYMBOL(copy_to_user);
23487-
23488-/**
23489- * copy_from_user: - Copy a block of data from user space.
23490- * @to: Destination address, in kernel space.
23491- * @from: Source address, in user space.
23492- * @n: Number of bytes to copy.
23493- *
23494- * Context: User context only. This function may sleep.
23495- *
23496- * Copy data from user space to kernel space.
23497- *
23498- * Returns number of bytes that could not be copied.
23499- * On success, this will be zero.
23500- *
23501- * If some data could not be copied, this function will pad the copied
23502- * data to the requested size using zero bytes.
23503- */
23504-unsigned long
23505-_copy_from_user(void *to, const void __user *from, unsigned long n)
23506-{
23507- if (access_ok(VERIFY_READ, from, n))
23508- n = __copy_from_user(to, from, n);
23509- else
23510- memset(to, 0, n);
23511- return n;
23512-}
23513-EXPORT_SYMBOL(_copy_from_user);
23514-
23515 void copy_from_user_overflow(void)
23516 {
23517 WARN(1, "Buffer overflow detected!\n");
23518 }
23519 EXPORT_SYMBOL(copy_from_user_overflow);
23520+
23521+void copy_to_user_overflow(void)
23522+{
23523+ WARN(1, "Buffer overflow detected!\n");
23524+}
23525+EXPORT_SYMBOL(copy_to_user_overflow);
23526+
23527+#ifdef CONFIG_PAX_MEMORY_UDEREF
23528+void __set_fs(mm_segment_t x)
23529+{
23530+ switch (x.seg) {
23531+ case 0:
23532+ loadsegment(gs, 0);
23533+ break;
23534+ case TASK_SIZE_MAX:
23535+ loadsegment(gs, __USER_DS);
23536+ break;
23537+ case -1UL:
23538+ loadsegment(gs, __KERNEL_DS);
23539+ break;
23540+ default:
23541+ BUG();
23542+ }
23543+ return;
23544+}
23545+EXPORT_SYMBOL(__set_fs);
23546+
23547+void set_fs(mm_segment_t x)
23548+{
23549+ current_thread_info()->addr_limit = x;
23550+ __set_fs(x);
23551+}
23552+EXPORT_SYMBOL(set_fs);
23553+#endif
23554diff --git a/arch/x86/lib/usercopy_64.c b/arch/x86/lib/usercopy_64.c
23555index e5b130b..6690d31 100644
23556--- a/arch/x86/lib/usercopy_64.c
23557+++ b/arch/x86/lib/usercopy_64.c
23558@@ -16,6 +16,12 @@ unsigned long __clear_user(void __user *addr, unsigned long size)
23559 {
23560 long __d0;
23561 might_fault();
23562+
23563+#ifdef CONFIG_PAX_MEMORY_UDEREF
23564+ if ((unsigned long)addr < PAX_USER_SHADOW_BASE)
23565+ addr += PAX_USER_SHADOW_BASE;
23566+#endif
23567+
23568 /* no memory constraint because it doesn't change any memory gcc knows
23569 about */
23570 asm volatile(
23571@@ -52,12 +58,20 @@ unsigned long clear_user(void __user *to, unsigned long n)
23572 }
23573 EXPORT_SYMBOL(clear_user);
23574
23575-unsigned long copy_in_user(void __user *to, const void __user *from, unsigned len)
23576+unsigned long copy_in_user(void __user *to, const void __user *from, unsigned long len)
23577 {
23578- if (access_ok(VERIFY_WRITE, to, len) && access_ok(VERIFY_READ, from, len)) {
23579- return copy_user_generic((__force void *)to, (__force void *)from, len);
23580- }
23581- return len;
23582+ if (access_ok(VERIFY_WRITE, to, len) && access_ok(VERIFY_READ, from, len)) {
23583+
23584+#ifdef CONFIG_PAX_MEMORY_UDEREF
23585+ if ((unsigned long)to < PAX_USER_SHADOW_BASE)
23586+ to += PAX_USER_SHADOW_BASE;
23587+ if ((unsigned long)from < PAX_USER_SHADOW_BASE)
23588+ from += PAX_USER_SHADOW_BASE;
23589+#endif
23590+
23591+ return copy_user_generic((void __force_kernel *)to, (void __force_kernel *)from, len);
23592+ }
23593+ return len;
23594 }
23595 EXPORT_SYMBOL(copy_in_user);
23596
23597@@ -67,7 +81,7 @@ EXPORT_SYMBOL(copy_in_user);
23598 * it is not necessary to optimize tail handling.
23599 */
23600 unsigned long
23601-copy_user_handle_tail(char *to, char *from, unsigned len, unsigned zerorest)
23602+copy_user_handle_tail(char __user *to, char __user *from, unsigned long len, unsigned zerorest)
23603 {
23604 char c;
23605 unsigned zero_len;
23606@@ -84,3 +98,15 @@ copy_user_handle_tail(char *to, char *from, unsigned len, unsigned zerorest)
23607 break;
23608 return len;
23609 }
23610+
23611+void copy_from_user_overflow(void)
23612+{
23613+ WARN(1, "Buffer overflow detected!\n");
23614+}
23615+EXPORT_SYMBOL(copy_from_user_overflow);
23616+
23617+void copy_to_user_overflow(void)
23618+{
23619+ WARN(1, "Buffer overflow detected!\n");
23620+}
23621+EXPORT_SYMBOL(copy_to_user_overflow);
23622diff --git a/arch/x86/mm/extable.c b/arch/x86/mm/extable.c
23623index 903ec1e..c4166b2 100644
23624--- a/arch/x86/mm/extable.c
23625+++ b/arch/x86/mm/extable.c
23626@@ -6,12 +6,24 @@
23627 static inline unsigned long
23628 ex_insn_addr(const struct exception_table_entry *x)
23629 {
23630- return (unsigned long)&x->insn + x->insn;
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->insn + x->insn + reloc;
23638 }
23639 static inline unsigned long
23640 ex_fixup_addr(const struct exception_table_entry *x)
23641 {
23642- return (unsigned long)&x->fixup + x->fixup;
23643+ unsigned long reloc = 0;
23644+
23645+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
23646+ reloc = ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
23647+#endif
23648+
23649+ return (unsigned long)&x->fixup + x->fixup + reloc;
23650 }
23651
23652 int fixup_exception(struct pt_regs *regs)
23653@@ -20,7 +32,7 @@ int fixup_exception(struct pt_regs *regs)
23654 unsigned long new_ip;
23655
23656 #ifdef CONFIG_PNPBIOS
23657- if (unlikely(SEGMENT_IS_PNP_CODE(regs->cs))) {
23658+ if (unlikely(!v8086_mode(regs) && SEGMENT_IS_PNP_CODE(regs->cs))) {
23659 extern u32 pnp_bios_fault_eip, pnp_bios_fault_esp;
23660 extern u32 pnp_bios_is_utter_crap;
23661 pnp_bios_is_utter_crap = 1;
23662@@ -145,6 +157,13 @@ void sort_extable(struct exception_table_entry *start,
23663 i += 4;
23664 p->fixup -= i;
23665 i += 4;
23666+
23667+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
23668+ BUILD_BUG_ON(!IS_ENABLED(CONFIG_BUILDTIME_EXTABLE_SORT));
23669+ p->insn -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
23670+ p->fixup -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
23671+#endif
23672+
23673 }
23674 }
23675
23676diff --git a/arch/x86/mm/fault.c b/arch/x86/mm/fault.c
23677index 76dcd9d..e9dffde 100644
23678--- a/arch/x86/mm/fault.c
23679+++ b/arch/x86/mm/fault.c
23680@@ -13,11 +13,18 @@
23681 #include <linux/perf_event.h> /* perf_sw_event */
23682 #include <linux/hugetlb.h> /* hstate_index_to_shift */
23683 #include <linux/prefetch.h> /* prefetchw */
23684+#include <linux/unistd.h>
23685+#include <linux/compiler.h>
23686
23687 #include <asm/traps.h> /* dotraplinkage, ... */
23688 #include <asm/pgalloc.h> /* pgd_*(), ... */
23689 #include <asm/kmemcheck.h> /* kmemcheck_*(), ... */
23690 #include <asm/fixmap.h> /* VSYSCALL_START */
23691+#include <asm/tlbflush.h>
23692+
23693+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
23694+#include <asm/stacktrace.h>
23695+#endif
23696
23697 /*
23698 * Page fault error code bits:
23699@@ -55,7 +62,7 @@ static inline int __kprobes notify_page_fault(struct pt_regs *regs)
23700 int ret = 0;
23701
23702 /* kprobe_running() needs smp_processor_id() */
23703- if (kprobes_built_in() && !user_mode_vm(regs)) {
23704+ if (kprobes_built_in() && !user_mode(regs)) {
23705 preempt_disable();
23706 if (kprobe_running() && kprobe_fault_handler(regs, 14))
23707 ret = 1;
23708@@ -116,7 +123,10 @@ check_prefetch_opcode(struct pt_regs *regs, unsigned char *instr,
23709 return !instr_lo || (instr_lo>>1) == 1;
23710 case 0x00:
23711 /* Prefetch instruction is 0x0F0D or 0x0F18 */
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+ return 0;
23716+ } else if (probe_kernel_address(instr, opcode))
23717 return 0;
23718
23719 *prefetch = (instr_lo == 0xF) &&
23720@@ -150,7 +160,10 @@ is_prefetch(struct pt_regs *regs, unsigned long error_code, unsigned long addr)
23721 while (instr < max_instr) {
23722 unsigned char opcode;
23723
23724- if (probe_kernel_address(instr, opcode))
23725+ if (user_mode(regs)) {
23726+ if (__copy_from_user_inatomic(&opcode, (unsigned char __force_user *)(instr), 1))
23727+ break;
23728+ } else if (probe_kernel_address(instr, opcode))
23729 break;
23730
23731 instr++;
23732@@ -181,6 +194,34 @@ force_sig_info_fault(int si_signo, int si_code, unsigned long address,
23733 force_sig_info(si_signo, &info, tsk);
23734 }
23735
23736+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
23737+static bool pax_is_fetch_fault(struct pt_regs *regs, unsigned long error_code, unsigned long address);
23738+#endif
23739+
23740+#ifdef CONFIG_PAX_EMUTRAMP
23741+static int pax_handle_fetch_fault(struct pt_regs *regs);
23742+#endif
23743+
23744+#ifdef CONFIG_PAX_PAGEEXEC
23745+static inline pmd_t * pax_get_pmd(struct mm_struct *mm, unsigned long address)
23746+{
23747+ pgd_t *pgd;
23748+ pud_t *pud;
23749+ pmd_t *pmd;
23750+
23751+ pgd = pgd_offset(mm, address);
23752+ if (!pgd_present(*pgd))
23753+ return NULL;
23754+ pud = pud_offset(pgd, address);
23755+ if (!pud_present(*pud))
23756+ return NULL;
23757+ pmd = pmd_offset(pud, address);
23758+ if (!pmd_present(*pmd))
23759+ return NULL;
23760+ return pmd;
23761+}
23762+#endif
23763+
23764 DEFINE_SPINLOCK(pgd_lock);
23765 LIST_HEAD(pgd_list);
23766
23767@@ -231,10 +272,22 @@ void vmalloc_sync_all(void)
23768 for (address = VMALLOC_START & PMD_MASK;
23769 address >= TASK_SIZE && address < FIXADDR_TOP;
23770 address += PMD_SIZE) {
23771+
23772+#ifdef CONFIG_PAX_PER_CPU_PGD
23773+ unsigned long cpu;
23774+#else
23775 struct page *page;
23776+#endif
23777
23778 spin_lock(&pgd_lock);
23779+
23780+#ifdef CONFIG_PAX_PER_CPU_PGD
23781+ for (cpu = 0; cpu < nr_cpu_ids; ++cpu) {
23782+ pgd_t *pgd = get_cpu_pgd(cpu);
23783+ pmd_t *ret;
23784+#else
23785 list_for_each_entry(page, &pgd_list, lru) {
23786+ pgd_t *pgd = page_address(page);
23787 spinlock_t *pgt_lock;
23788 pmd_t *ret;
23789
23790@@ -242,8 +295,13 @@ void vmalloc_sync_all(void)
23791 pgt_lock = &pgd_page_get_mm(page)->page_table_lock;
23792
23793 spin_lock(pgt_lock);
23794- ret = vmalloc_sync_one(page_address(page), address);
23795+#endif
23796+
23797+ ret = vmalloc_sync_one(pgd, address);
23798+
23799+#ifndef CONFIG_PAX_PER_CPU_PGD
23800 spin_unlock(pgt_lock);
23801+#endif
23802
23803 if (!ret)
23804 break;
23805@@ -277,6 +335,11 @@ static noinline __kprobes int vmalloc_fault(unsigned long address)
23806 * an interrupt in the middle of a task switch..
23807 */
23808 pgd_paddr = read_cr3();
23809+
23810+#ifdef CONFIG_PAX_PER_CPU_PGD
23811+ BUG_ON(__pa(get_cpu_pgd(smp_processor_id())) != (pgd_paddr & PHYSICAL_PAGE_MASK));
23812+#endif
23813+
23814 pmd_k = vmalloc_sync_one(__va(pgd_paddr), address);
23815 if (!pmd_k)
23816 return -1;
23817@@ -372,7 +435,14 @@ static noinline __kprobes int vmalloc_fault(unsigned long address)
23818 * happen within a race in page table update. In the later
23819 * case just flush:
23820 */
23821+
23822+#ifdef CONFIG_PAX_PER_CPU_PGD
23823+ BUG_ON(__pa(get_cpu_pgd(smp_processor_id())) != (read_cr3() & PHYSICAL_PAGE_MASK));
23824+ pgd = pgd_offset_cpu(smp_processor_id(), address);
23825+#else
23826 pgd = pgd_offset(current->active_mm, address);
23827+#endif
23828+
23829 pgd_ref = pgd_offset_k(address);
23830 if (pgd_none(*pgd_ref))
23831 return -1;
23832@@ -540,7 +610,7 @@ static int is_errata93(struct pt_regs *regs, unsigned long address)
23833 static int is_errata100(struct pt_regs *regs, unsigned long address)
23834 {
23835 #ifdef CONFIG_X86_64
23836- if ((regs->cs == __USER32_CS || (regs->cs & (1<<2))) && (address >> 32))
23837+ if ((regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT)) && (address >> 32))
23838 return 1;
23839 #endif
23840 return 0;
23841@@ -567,7 +637,7 @@ static int is_f00f_bug(struct pt_regs *regs, unsigned long address)
23842 }
23843
23844 static const char nx_warning[] = KERN_CRIT
23845-"kernel tried to execute NX-protected page - exploit attempt? (uid: %d)\n";
23846+"kernel tried to execute NX-protected page - exploit attempt? (uid: %d, task: %s, pid: %d)\n";
23847
23848 static void
23849 show_fault_oops(struct pt_regs *regs, unsigned long error_code,
23850@@ -576,15 +646,26 @@ show_fault_oops(struct pt_regs *regs, unsigned long error_code,
23851 if (!oops_may_print())
23852 return;
23853
23854- if (error_code & PF_INSTR) {
23855+ if ((__supported_pte_mask & _PAGE_NX) && (error_code & PF_INSTR)) {
23856 unsigned int level;
23857
23858 pte_t *pte = lookup_address(address, &level);
23859
23860 if (pte && pte_present(*pte) && !pte_exec(*pte))
23861- printk(nx_warning, from_kuid(&init_user_ns, current_uid()));
23862+ printk(nx_warning, from_kuid(&init_user_ns, current_uid()), current->comm, task_pid_nr(current));
23863 }
23864
23865+#ifdef CONFIG_PAX_KERNEXEC
23866+ if (init_mm.start_code <= address && address < init_mm.end_code) {
23867+ if (current->signal->curr_ip)
23868+ printk(KERN_ERR "PAX: From %pI4: %s:%d, uid/euid: %u/%u, attempted to modify kernel code\n",
23869+ &current->signal->curr_ip, current->comm, task_pid_nr(current), current_uid(), current_euid());
23870+ else
23871+ printk(KERN_ERR "PAX: %s:%d, uid/euid: %u/%u, attempted to modify kernel code\n",
23872+ current->comm, task_pid_nr(current), current_uid(), current_euid());
23873+ }
23874+#endif
23875+
23876 printk(KERN_ALERT "BUG: unable to handle kernel ");
23877 if (address < PAGE_SIZE)
23878 printk(KERN_CONT "NULL pointer dereference");
23879@@ -748,6 +829,21 @@ __bad_area_nosemaphore(struct pt_regs *regs, unsigned long error_code,
23880 }
23881 #endif
23882
23883+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
23884+ if (pax_is_fetch_fault(regs, error_code, address)) {
23885+
23886+#ifdef CONFIG_PAX_EMUTRAMP
23887+ switch (pax_handle_fetch_fault(regs)) {
23888+ case 2:
23889+ return;
23890+ }
23891+#endif
23892+
23893+ pax_report_fault(regs, (void *)regs->ip, (void *)regs->sp);
23894+ do_group_exit(SIGKILL);
23895+ }
23896+#endif
23897+
23898 if (unlikely(show_unhandled_signals))
23899 show_signal_msg(regs, error_code, address, tsk);
23900
23901@@ -844,7 +940,7 @@ do_sigbus(struct pt_regs *regs, unsigned long error_code, unsigned long address,
23902 if (fault & (VM_FAULT_HWPOISON|VM_FAULT_HWPOISON_LARGE)) {
23903 printk(KERN_ERR
23904 "MCE: Killing %s:%d due to hardware memory corruption fault at %lx\n",
23905- tsk->comm, tsk->pid, address);
23906+ tsk->comm, task_pid_nr(tsk), address);
23907 code = BUS_MCEERR_AR;
23908 }
23909 #endif
23910@@ -900,6 +996,99 @@ static int spurious_fault_check(unsigned long error_code, pte_t *pte)
23911 return 1;
23912 }
23913
23914+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
23915+static int pax_handle_pageexec_fault(struct pt_regs *regs, struct mm_struct *mm, unsigned long address, unsigned long error_code)
23916+{
23917+ pte_t *pte;
23918+ pmd_t *pmd;
23919+ spinlock_t *ptl;
23920+ unsigned char pte_mask;
23921+
23922+ if ((__supported_pte_mask & _PAGE_NX) || (error_code & (PF_PROT|PF_USER)) != (PF_PROT|PF_USER) || v8086_mode(regs) ||
23923+ !(mm->pax_flags & MF_PAX_PAGEEXEC))
23924+ return 0;
23925+
23926+ /* PaX: it's our fault, let's handle it if we can */
23927+
23928+ /* PaX: take a look at read faults before acquiring any locks */
23929+ if (unlikely(!(error_code & PF_WRITE) && (regs->ip == address))) {
23930+ /* instruction fetch attempt from a protected page in user mode */
23931+ up_read(&mm->mmap_sem);
23932+
23933+#ifdef CONFIG_PAX_EMUTRAMP
23934+ switch (pax_handle_fetch_fault(regs)) {
23935+ case 2:
23936+ return 1;
23937+ }
23938+#endif
23939+
23940+ pax_report_fault(regs, (void *)regs->ip, (void *)regs->sp);
23941+ do_group_exit(SIGKILL);
23942+ }
23943+
23944+ pmd = pax_get_pmd(mm, address);
23945+ if (unlikely(!pmd))
23946+ return 0;
23947+
23948+ pte = pte_offset_map_lock(mm, pmd, address, &ptl);
23949+ if (unlikely(!(pte_val(*pte) & _PAGE_PRESENT) || pte_user(*pte))) {
23950+ pte_unmap_unlock(pte, ptl);
23951+ return 0;
23952+ }
23953+
23954+ if (unlikely((error_code & PF_WRITE) && !pte_write(*pte))) {
23955+ /* write attempt to a protected page in user mode */
23956+ pte_unmap_unlock(pte, ptl);
23957+ return 0;
23958+ }
23959+
23960+#ifdef CONFIG_SMP
23961+ if (likely(address > get_limit(regs->cs) && cpu_isset(smp_processor_id(), mm->context.cpu_user_cs_mask)))
23962+#else
23963+ if (likely(address > get_limit(regs->cs)))
23964+#endif
23965+ {
23966+ set_pte(pte, pte_mkread(*pte));
23967+ __flush_tlb_one(address);
23968+ pte_unmap_unlock(pte, ptl);
23969+ up_read(&mm->mmap_sem);
23970+ return 1;
23971+ }
23972+
23973+ pte_mask = _PAGE_ACCESSED | _PAGE_USER | ((error_code & PF_WRITE) << (_PAGE_BIT_DIRTY-1));
23974+
23975+ /*
23976+ * PaX: fill DTLB with user rights and retry
23977+ */
23978+ __asm__ __volatile__ (
23979+ "orb %2,(%1)\n"
23980+#if defined(CONFIG_M586) || defined(CONFIG_M586TSC)
23981+/*
23982+ * PaX: let this uncommented 'invlpg' remind us on the behaviour of Intel's
23983+ * (and AMD's) TLBs. namely, they do not cache PTEs that would raise *any*
23984+ * page fault when examined during a TLB load attempt. this is true not only
23985+ * for PTEs holding a non-present entry but also present entries that will
23986+ * raise a page fault (such as those set up by PaX, or the copy-on-write
23987+ * mechanism). in effect it means that we do *not* need to flush the TLBs
23988+ * for our target pages since their PTEs are simply not in the TLBs at all.
23989+
23990+ * the best thing in omitting it is that we gain around 15-20% speed in the
23991+ * fast path of the page fault handler and can get rid of tracing since we
23992+ * can no longer flush unintended entries.
23993+ */
23994+ "invlpg (%0)\n"
23995+#endif
23996+ __copyuser_seg"testb $0,(%0)\n"
23997+ "xorb %3,(%1)\n"
23998+ :
23999+ : "r" (address), "r" (pte), "q" (pte_mask), "i" (_PAGE_USER)
24000+ : "memory", "cc");
24001+ pte_unmap_unlock(pte, ptl);
24002+ up_read(&mm->mmap_sem);
24003+ return 1;
24004+}
24005+#endif
24006+
24007 /*
24008 * Handle a spurious fault caused by a stale TLB entry.
24009 *
24010@@ -972,6 +1161,9 @@ int show_unhandled_signals = 1;
24011 static inline int
24012 access_error(unsigned long error_code, struct vm_area_struct *vma)
24013 {
24014+ if ((__supported_pte_mask & _PAGE_NX) && (error_code & PF_INSTR) && !(vma->vm_flags & VM_EXEC))
24015+ return 1;
24016+
24017 if (error_code & PF_WRITE) {
24018 /* write, present and write, not present: */
24019 if (unlikely(!(vma->vm_flags & VM_WRITE)))
24020@@ -1005,18 +1197,33 @@ do_page_fault(struct pt_regs *regs, unsigned long error_code)
24021 {
24022 struct vm_area_struct *vma;
24023 struct task_struct *tsk;
24024- unsigned long address;
24025 struct mm_struct *mm;
24026 int fault;
24027 int write = error_code & PF_WRITE;
24028 unsigned int flags = FAULT_FLAG_ALLOW_RETRY | FAULT_FLAG_KILLABLE |
24029 (write ? FAULT_FLAG_WRITE : 0);
24030
24031- tsk = current;
24032- mm = tsk->mm;
24033-
24034 /* Get the faulting address: */
24035- address = read_cr2();
24036+ unsigned long address = read_cr2();
24037+
24038+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
24039+ if (!user_mode(regs) && address < 2 * PAX_USER_SHADOW_BASE) {
24040+ if (!search_exception_tables(regs->ip)) {
24041+ printk(KERN_ERR "PAX: please report this to pageexec@freemail.hu\n");
24042+ bad_area_nosemaphore(regs, error_code, address);
24043+ return;
24044+ }
24045+ if (address < PAX_USER_SHADOW_BASE) {
24046+ printk(KERN_ERR "PAX: please report this to pageexec@freemail.hu\n");
24047+ printk(KERN_ERR "PAX: faulting IP: %pS\n", (void *)regs->ip);
24048+ show_trace_log_lvl(NULL, NULL, (void *)regs->sp, regs->bp, KERN_ERR);
24049+ } else
24050+ address -= PAX_USER_SHADOW_BASE;
24051+ }
24052+#endif
24053+
24054+ tsk = current;
24055+ mm = tsk->mm;
24056
24057 /*
24058 * Detect and handle instructions that would cause a page fault for
24059@@ -1077,7 +1284,7 @@ do_page_fault(struct pt_regs *regs, unsigned long error_code)
24060 * User-mode registers count as a user access even for any
24061 * potential system fault or CPU buglet:
24062 */
24063- if (user_mode_vm(regs)) {
24064+ if (user_mode(regs)) {
24065 local_irq_enable();
24066 error_code |= PF_USER;
24067 } else {
24068@@ -1132,6 +1339,11 @@ retry:
24069 might_sleep();
24070 }
24071
24072+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
24073+ if (pax_handle_pageexec_fault(regs, mm, address, error_code))
24074+ return;
24075+#endif
24076+
24077 vma = find_vma(mm, address);
24078 if (unlikely(!vma)) {
24079 bad_area(regs, error_code, address);
24080@@ -1143,18 +1355,24 @@ retry:
24081 bad_area(regs, error_code, address);
24082 return;
24083 }
24084- if (error_code & PF_USER) {
24085- /*
24086- * Accessing the stack below %sp is always a bug.
24087- * The large cushion allows instructions like enter
24088- * and pusha to work. ("enter $65535, $31" pushes
24089- * 32 pointers and then decrements %sp by 65535.)
24090- */
24091- if (unlikely(address + 65536 + 32 * sizeof(unsigned long) < regs->sp)) {
24092- bad_area(regs, error_code, address);
24093- return;
24094- }
24095+ /*
24096+ * Accessing the stack below %sp is always a bug.
24097+ * The large cushion allows instructions like enter
24098+ * and pusha to work. ("enter $65535, $31" pushes
24099+ * 32 pointers and then decrements %sp by 65535.)
24100+ */
24101+ if (unlikely(address + 65536 + 32 * sizeof(unsigned long) < task_pt_regs(tsk)->sp)) {
24102+ bad_area(regs, error_code, address);
24103+ return;
24104 }
24105+
24106+#ifdef CONFIG_PAX_SEGMEXEC
24107+ if (unlikely((mm->pax_flags & MF_PAX_SEGMEXEC) && vma->vm_end - SEGMEXEC_TASK_SIZE - 1 < address - SEGMEXEC_TASK_SIZE - 1)) {
24108+ bad_area(regs, error_code, address);
24109+ return;
24110+ }
24111+#endif
24112+
24113 if (unlikely(expand_stack(vma, address))) {
24114 bad_area(regs, error_code, address);
24115 return;
24116@@ -1209,3 +1427,292 @@ good_area:
24117
24118 up_read(&mm->mmap_sem);
24119 }
24120+
24121+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
24122+static bool pax_is_fetch_fault(struct pt_regs *regs, unsigned long error_code, unsigned long address)
24123+{
24124+ struct mm_struct *mm = current->mm;
24125+ unsigned long ip = regs->ip;
24126+
24127+ if (v8086_mode(regs))
24128+ ip = ((regs->cs & 0xffff) << 4) + (ip & 0xffff);
24129+
24130+#ifdef CONFIG_PAX_PAGEEXEC
24131+ if (mm->pax_flags & MF_PAX_PAGEEXEC) {
24132+ if ((__supported_pte_mask & _PAGE_NX) && (error_code & PF_INSTR))
24133+ return true;
24134+ if (!(error_code & (PF_PROT | PF_WRITE)) && ip == address)
24135+ return true;
24136+ return false;
24137+ }
24138+#endif
24139+
24140+#ifdef CONFIG_PAX_SEGMEXEC
24141+ if (mm->pax_flags & MF_PAX_SEGMEXEC) {
24142+ if (!(error_code & (PF_PROT | PF_WRITE)) && (ip + SEGMEXEC_TASK_SIZE == address))
24143+ return true;
24144+ return false;
24145+ }
24146+#endif
24147+
24148+ return false;
24149+}
24150+#endif
24151+
24152+#ifdef CONFIG_PAX_EMUTRAMP
24153+static int pax_handle_fetch_fault_32(struct pt_regs *regs)
24154+{
24155+ int err;
24156+
24157+ do { /* PaX: libffi trampoline emulation */
24158+ unsigned char mov, jmp;
24159+ unsigned int addr1, addr2;
24160+
24161+#ifdef CONFIG_X86_64
24162+ if ((regs->ip + 9) >> 32)
24163+ break;
24164+#endif
24165+
24166+ err = get_user(mov, (unsigned char __user *)regs->ip);
24167+ err |= get_user(addr1, (unsigned int __user *)(regs->ip + 1));
24168+ err |= get_user(jmp, (unsigned char __user *)(regs->ip + 5));
24169+ err |= get_user(addr2, (unsigned int __user *)(regs->ip + 6));
24170+
24171+ if (err)
24172+ break;
24173+
24174+ if (mov == 0xB8 && jmp == 0xE9) {
24175+ regs->ax = addr1;
24176+ regs->ip = (unsigned int)(regs->ip + addr2 + 10);
24177+ return 2;
24178+ }
24179+ } while (0);
24180+
24181+ do { /* PaX: gcc trampoline emulation #1 */
24182+ unsigned char mov1, mov2;
24183+ unsigned short jmp;
24184+ unsigned int addr1, addr2;
24185+
24186+#ifdef CONFIG_X86_64
24187+ if ((regs->ip + 11) >> 32)
24188+ break;
24189+#endif
24190+
24191+ err = get_user(mov1, (unsigned char __user *)regs->ip);
24192+ err |= get_user(addr1, (unsigned int __user *)(regs->ip + 1));
24193+ err |= get_user(mov2, (unsigned char __user *)(regs->ip + 5));
24194+ err |= get_user(addr2, (unsigned int __user *)(regs->ip + 6));
24195+ err |= get_user(jmp, (unsigned short __user *)(regs->ip + 10));
24196+
24197+ if (err)
24198+ break;
24199+
24200+ if (mov1 == 0xB9 && mov2 == 0xB8 && jmp == 0xE0FF) {
24201+ regs->cx = addr1;
24202+ regs->ax = addr2;
24203+ regs->ip = addr2;
24204+ return 2;
24205+ }
24206+ } while (0);
24207+
24208+ do { /* PaX: gcc trampoline emulation #2 */
24209+ unsigned char mov, jmp;
24210+ unsigned int addr1, addr2;
24211+
24212+#ifdef CONFIG_X86_64
24213+ if ((regs->ip + 9) >> 32)
24214+ break;
24215+#endif
24216+
24217+ err = get_user(mov, (unsigned char __user *)regs->ip);
24218+ err |= get_user(addr1, (unsigned int __user *)(regs->ip + 1));
24219+ err |= get_user(jmp, (unsigned char __user *)(regs->ip + 5));
24220+ err |= get_user(addr2, (unsigned int __user *)(regs->ip + 6));
24221+
24222+ if (err)
24223+ break;
24224+
24225+ if (mov == 0xB9 && jmp == 0xE9) {
24226+ regs->cx = addr1;
24227+ regs->ip = (unsigned int)(regs->ip + addr2 + 10);
24228+ return 2;
24229+ }
24230+ } while (0);
24231+
24232+ return 1; /* PaX in action */
24233+}
24234+
24235+#ifdef CONFIG_X86_64
24236+static int pax_handle_fetch_fault_64(struct pt_regs *regs)
24237+{
24238+ int err;
24239+
24240+ do { /* PaX: libffi trampoline emulation */
24241+ unsigned short mov1, mov2, jmp1;
24242+ unsigned char stcclc, jmp2;
24243+ unsigned long addr1, addr2;
24244+
24245+ err = get_user(mov1, (unsigned short __user *)regs->ip);
24246+ err |= get_user(addr1, (unsigned long __user *)(regs->ip + 2));
24247+ err |= get_user(mov2, (unsigned short __user *)(regs->ip + 10));
24248+ err |= get_user(addr2, (unsigned long __user *)(regs->ip + 12));
24249+ err |= get_user(stcclc, (unsigned char __user *)(regs->ip + 20));
24250+ err |= get_user(jmp1, (unsigned short __user *)(regs->ip + 21));
24251+ err |= get_user(jmp2, (unsigned char __user *)(regs->ip + 23));
24252+
24253+ if (err)
24254+ break;
24255+
24256+ if (mov1 == 0xBB49 && mov2 == 0xBA49 && (stcclc == 0xF8 || stcclc == 0xF9) && jmp1 == 0xFF49 && jmp2 == 0xE3) {
24257+ regs->r11 = addr1;
24258+ regs->r10 = addr2;
24259+ if (stcclc == 0xF8)
24260+ regs->flags &= ~X86_EFLAGS_CF;
24261+ else
24262+ regs->flags |= X86_EFLAGS_CF;
24263+ regs->ip = addr1;
24264+ return 2;
24265+ }
24266+ } while (0);
24267+
24268+ do { /* PaX: gcc trampoline emulation #1 */
24269+ unsigned short mov1, mov2, jmp1;
24270+ unsigned char jmp2;
24271+ unsigned int addr1;
24272+ unsigned long addr2;
24273+
24274+ err = get_user(mov1, (unsigned short __user *)regs->ip);
24275+ err |= get_user(addr1, (unsigned int __user *)(regs->ip + 2));
24276+ err |= get_user(mov2, (unsigned short __user *)(regs->ip + 6));
24277+ err |= get_user(addr2, (unsigned long __user *)(regs->ip + 8));
24278+ err |= get_user(jmp1, (unsigned short __user *)(regs->ip + 16));
24279+ err |= get_user(jmp2, (unsigned char __user *)(regs->ip + 18));
24280+
24281+ if (err)
24282+ break;
24283+
24284+ if (mov1 == 0xBB41 && mov2 == 0xBA49 && jmp1 == 0xFF49 && jmp2 == 0xE3) {
24285+ regs->r11 = addr1;
24286+ regs->r10 = addr2;
24287+ regs->ip = addr1;
24288+ return 2;
24289+ }
24290+ } while (0);
24291+
24292+ do { /* PaX: gcc trampoline emulation #2 */
24293+ unsigned short mov1, mov2, jmp1;
24294+ unsigned char jmp2;
24295+ unsigned long addr1, addr2;
24296+
24297+ err = get_user(mov1, (unsigned short __user *)regs->ip);
24298+ err |= get_user(addr1, (unsigned long __user *)(regs->ip + 2));
24299+ err |= get_user(mov2, (unsigned short __user *)(regs->ip + 10));
24300+ err |= get_user(addr2, (unsigned long __user *)(regs->ip + 12));
24301+ err |= get_user(jmp1, (unsigned short __user *)(regs->ip + 20));
24302+ err |= get_user(jmp2, (unsigned char __user *)(regs->ip + 22));
24303+
24304+ if (err)
24305+ break;
24306+
24307+ if (mov1 == 0xBB49 && mov2 == 0xBA49 && jmp1 == 0xFF49 && jmp2 == 0xE3) {
24308+ regs->r11 = addr1;
24309+ regs->r10 = addr2;
24310+ regs->ip = addr1;
24311+ return 2;
24312+ }
24313+ } while (0);
24314+
24315+ return 1; /* PaX in action */
24316+}
24317+#endif
24318+
24319+/*
24320+ * PaX: decide what to do with offenders (regs->ip = fault address)
24321+ *
24322+ * returns 1 when task should be killed
24323+ * 2 when gcc trampoline was detected
24324+ */
24325+static int pax_handle_fetch_fault(struct pt_regs *regs)
24326+{
24327+ if (v8086_mode(regs))
24328+ return 1;
24329+
24330+ if (!(current->mm->pax_flags & MF_PAX_EMUTRAMP))
24331+ return 1;
24332+
24333+#ifdef CONFIG_X86_32
24334+ return pax_handle_fetch_fault_32(regs);
24335+#else
24336+ if (regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT))
24337+ return pax_handle_fetch_fault_32(regs);
24338+ else
24339+ return pax_handle_fetch_fault_64(regs);
24340+#endif
24341+}
24342+#endif
24343+
24344+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
24345+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
24346+{
24347+ long i;
24348+
24349+ printk(KERN_ERR "PAX: bytes at PC: ");
24350+ for (i = 0; i < 20; i++) {
24351+ unsigned char c;
24352+ if (get_user(c, (unsigned char __force_user *)pc+i))
24353+ printk(KERN_CONT "?? ");
24354+ else
24355+ printk(KERN_CONT "%02x ", c);
24356+ }
24357+ printk("\n");
24358+
24359+ printk(KERN_ERR "PAX: bytes at SP-%lu: ", (unsigned long)sizeof(long));
24360+ for (i = -1; i < 80 / (long)sizeof(long); i++) {
24361+ unsigned long c;
24362+ if (get_user(c, (unsigned long __force_user *)sp+i)) {
24363+#ifdef CONFIG_X86_32
24364+ printk(KERN_CONT "???????? ");
24365+#else
24366+ if ((regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT)))
24367+ printk(KERN_CONT "???????? ???????? ");
24368+ else
24369+ printk(KERN_CONT "???????????????? ");
24370+#endif
24371+ } else {
24372+#ifdef CONFIG_X86_64
24373+ if ((regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT))) {
24374+ printk(KERN_CONT "%08x ", (unsigned int)c);
24375+ printk(KERN_CONT "%08x ", (unsigned int)(c >> 32));
24376+ } else
24377+#endif
24378+ printk(KERN_CONT "%0*lx ", 2 * (int)sizeof(long), c);
24379+ }
24380+ }
24381+ printk("\n");
24382+}
24383+#endif
24384+
24385+/**
24386+ * probe_kernel_write(): safely attempt to write to a location
24387+ * @dst: address to write to
24388+ * @src: pointer to the data that shall be written
24389+ * @size: size of the data chunk
24390+ *
24391+ * Safely write to address @dst from the buffer at @src. If a kernel fault
24392+ * happens, handle that and return -EFAULT.
24393+ */
24394+long notrace probe_kernel_write(void *dst, const void *src, size_t size)
24395+{
24396+ long ret;
24397+ mm_segment_t old_fs = get_fs();
24398+
24399+ set_fs(KERNEL_DS);
24400+ pagefault_disable();
24401+ pax_open_kernel();
24402+ ret = __copy_to_user_inatomic((void __force_user *)dst, src, size);
24403+ pax_close_kernel();
24404+ pagefault_enable();
24405+ set_fs(old_fs);
24406+
24407+ return ret ? -EFAULT : 0;
24408+}
24409diff --git a/arch/x86/mm/gup.c b/arch/x86/mm/gup.c
24410index dd74e46..7d26398 100644
24411--- a/arch/x86/mm/gup.c
24412+++ b/arch/x86/mm/gup.c
24413@@ -255,7 +255,7 @@ int __get_user_pages_fast(unsigned long start, int nr_pages, int write,
24414 addr = start;
24415 len = (unsigned long) nr_pages << PAGE_SHIFT;
24416 end = start + len;
24417- if (unlikely(!access_ok(write ? VERIFY_WRITE : VERIFY_READ,
24418+ if (unlikely(!__access_ok(write ? VERIFY_WRITE : VERIFY_READ,
24419 (void __user *)start, len)))
24420 return 0;
24421
24422diff --git a/arch/x86/mm/highmem_32.c b/arch/x86/mm/highmem_32.c
24423index 6f31ee5..8ee4164 100644
24424--- a/arch/x86/mm/highmem_32.c
24425+++ b/arch/x86/mm/highmem_32.c
24426@@ -44,7 +44,11 @@ void *kmap_atomic_prot(struct page *page, pgprot_t prot)
24427 idx = type + KM_TYPE_NR*smp_processor_id();
24428 vaddr = __fix_to_virt(FIX_KMAP_BEGIN + idx);
24429 BUG_ON(!pte_none(*(kmap_pte-idx)));
24430+
24431+ pax_open_kernel();
24432 set_pte(kmap_pte-idx, mk_pte(page, prot));
24433+ pax_close_kernel();
24434+
24435 arch_flush_lazy_mmu_mode();
24436
24437 return (void *)vaddr;
24438diff --git a/arch/x86/mm/hugetlbpage.c b/arch/x86/mm/hugetlbpage.c
24439index b91e485..d00e7c9 100644
24440--- a/arch/x86/mm/hugetlbpage.c
24441+++ b/arch/x86/mm/hugetlbpage.c
24442@@ -277,13 +277,20 @@ static unsigned long hugetlb_get_unmapped_area_bottomup(struct file *file,
24443 struct hstate *h = hstate_file(file);
24444 struct mm_struct *mm = current->mm;
24445 struct vm_area_struct *vma;
24446- unsigned long start_addr;
24447+ unsigned long start_addr, pax_task_size = TASK_SIZE;
24448+
24449+#ifdef CONFIG_PAX_SEGMEXEC
24450+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
24451+ pax_task_size = SEGMEXEC_TASK_SIZE;
24452+#endif
24453+
24454+ pax_task_size -= PAGE_SIZE;
24455
24456 if (len > mm->cached_hole_size) {
24457- start_addr = mm->free_area_cache;
24458+ start_addr = mm->free_area_cache;
24459 } else {
24460- start_addr = TASK_UNMAPPED_BASE;
24461- mm->cached_hole_size = 0;
24462+ start_addr = mm->mmap_base;
24463+ mm->cached_hole_size = 0;
24464 }
24465
24466 full_search:
24467@@ -291,26 +298,27 @@ full_search:
24468
24469 for (vma = find_vma(mm, addr); ; vma = vma->vm_next) {
24470 /* At this point: (!vma || addr < vma->vm_end). */
24471- if (TASK_SIZE - len < addr) {
24472+ if (pax_task_size - len < addr) {
24473 /*
24474 * Start a new search - just in case we missed
24475 * some holes.
24476 */
24477- if (start_addr != TASK_UNMAPPED_BASE) {
24478- start_addr = TASK_UNMAPPED_BASE;
24479+ if (start_addr != mm->mmap_base) {
24480+ start_addr = mm->mmap_base;
24481 mm->cached_hole_size = 0;
24482 goto full_search;
24483 }
24484 return -ENOMEM;
24485 }
24486- if (!vma || addr + len <= vma->vm_start) {
24487- mm->free_area_cache = addr + len;
24488- return addr;
24489- }
24490+ if (check_heap_stack_gap(vma, addr, len))
24491+ break;
24492 if (addr + mm->cached_hole_size < vma->vm_start)
24493 mm->cached_hole_size = vma->vm_start - addr;
24494 addr = ALIGN(vma->vm_end, huge_page_size(h));
24495 }
24496+
24497+ mm->free_area_cache = addr + len;
24498+ return addr;
24499 }
24500
24501 static unsigned long hugetlb_get_unmapped_area_topdown(struct file *file,
24502@@ -321,9 +329,8 @@ static unsigned long hugetlb_get_unmapped_area_topdown(struct file *file,
24503 struct mm_struct *mm = current->mm;
24504 struct vm_area_struct *vma;
24505 unsigned long base = mm->mmap_base;
24506- unsigned long addr = addr0;
24507+ unsigned long addr;
24508 unsigned long largest_hole = mm->cached_hole_size;
24509- unsigned long start_addr;
24510
24511 /* don't allow allocations above current base */
24512 if (mm->free_area_cache > base)
24513@@ -333,16 +340,15 @@ static unsigned long hugetlb_get_unmapped_area_topdown(struct file *file,
24514 largest_hole = 0;
24515 mm->free_area_cache = base;
24516 }
24517-try_again:
24518- start_addr = mm->free_area_cache;
24519
24520 /* make sure it can fit in the remaining address space */
24521 if (mm->free_area_cache < len)
24522 goto fail;
24523
24524 /* either no address requested or can't fit in requested address hole */
24525- addr = (mm->free_area_cache - len) & huge_page_mask(h);
24526+ addr = mm->free_area_cache - len;
24527 do {
24528+ addr &= huge_page_mask(h);
24529 /*
24530 * Lookup failure means no vma is above this address,
24531 * i.e. return with success:
24532@@ -351,10 +357,10 @@ try_again:
24533 if (!vma)
24534 return addr;
24535
24536- if (addr + len <= vma->vm_start) {
24537+ if (check_heap_stack_gap(vma, addr, len)) {
24538 /* remember the address as a hint for next time */
24539- mm->cached_hole_size = largest_hole;
24540- return (mm->free_area_cache = addr);
24541+ mm->cached_hole_size = largest_hole;
24542+ return (mm->free_area_cache = addr);
24543 } else if (mm->free_area_cache == vma->vm_end) {
24544 /* pull free_area_cache down to the first hole */
24545 mm->free_area_cache = vma->vm_start;
24546@@ -363,29 +369,34 @@ try_again:
24547
24548 /* remember the largest hole we saw so far */
24549 if (addr + largest_hole < vma->vm_start)
24550- largest_hole = vma->vm_start - addr;
24551+ largest_hole = vma->vm_start - addr;
24552
24553 /* try just below the current vma->vm_start */
24554- addr = (vma->vm_start - len) & huge_page_mask(h);
24555- } while (len <= vma->vm_start);
24556+ addr = skip_heap_stack_gap(vma, len);
24557+ } while (!IS_ERR_VALUE(addr));
24558
24559 fail:
24560 /*
24561- * if hint left us with no space for the requested
24562- * mapping then try again:
24563- */
24564- if (start_addr != base) {
24565- mm->free_area_cache = base;
24566- largest_hole = 0;
24567- goto try_again;
24568- }
24569- /*
24570 * A failed mmap() very likely causes application failure,
24571 * so fall back to the bottom-up function here. This scenario
24572 * can happen with large stack limits and large mmap()
24573 * allocations.
24574 */
24575- mm->free_area_cache = TASK_UNMAPPED_BASE;
24576+
24577+#ifdef CONFIG_PAX_SEGMEXEC
24578+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
24579+ mm->mmap_base = SEGMEXEC_TASK_UNMAPPED_BASE;
24580+ else
24581+#endif
24582+
24583+ mm->mmap_base = TASK_UNMAPPED_BASE;
24584+
24585+#ifdef CONFIG_PAX_RANDMMAP
24586+ if (mm->pax_flags & MF_PAX_RANDMMAP)
24587+ mm->mmap_base += mm->delta_mmap;
24588+#endif
24589+
24590+ mm->free_area_cache = mm->mmap_base;
24591 mm->cached_hole_size = ~0UL;
24592 addr = hugetlb_get_unmapped_area_bottomup(file, addr0,
24593 len, pgoff, flags);
24594@@ -393,6 +404,7 @@ fail:
24595 /*
24596 * Restore the topdown base:
24597 */
24598+ mm->mmap_base = base;
24599 mm->free_area_cache = base;
24600 mm->cached_hole_size = ~0UL;
24601
24602@@ -406,10 +418,19 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
24603 struct hstate *h = hstate_file(file);
24604 struct mm_struct *mm = current->mm;
24605 struct vm_area_struct *vma;
24606+ unsigned long pax_task_size = TASK_SIZE;
24607
24608 if (len & ~huge_page_mask(h))
24609 return -EINVAL;
24610- if (len > TASK_SIZE)
24611+
24612+#ifdef CONFIG_PAX_SEGMEXEC
24613+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
24614+ pax_task_size = SEGMEXEC_TASK_SIZE;
24615+#endif
24616+
24617+ pax_task_size -= PAGE_SIZE;
24618+
24619+ if (len > pax_task_size)
24620 return -ENOMEM;
24621
24622 if (flags & MAP_FIXED) {
24623@@ -421,8 +442,7 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
24624 if (addr) {
24625 addr = ALIGN(addr, huge_page_size(h));
24626 vma = find_vma(mm, addr);
24627- if (TASK_SIZE - len >= addr &&
24628- (!vma || addr + len <= vma->vm_start))
24629+ if (pax_task_size - len >= addr && check_heap_stack_gap(vma, addr, len))
24630 return addr;
24631 }
24632 if (mm->get_unmapped_area == arch_get_unmapped_area)
24633diff --git a/arch/x86/mm/init.c b/arch/x86/mm/init.c
24634index d7aea41..0fc945b 100644
24635--- a/arch/x86/mm/init.c
24636+++ b/arch/x86/mm/init.c
24637@@ -4,6 +4,7 @@
24638 #include <linux/swap.h>
24639 #include <linux/memblock.h>
24640 #include <linux/bootmem.h> /* for max_low_pfn */
24641+#include <linux/tboot.h>
24642
24643 #include <asm/cacheflush.h>
24644 #include <asm/e820.h>
24645@@ -16,6 +17,8 @@
24646 #include <asm/tlb.h>
24647 #include <asm/proto.h>
24648 #include <asm/dma.h> /* for MAX_DMA_PFN */
24649+#include <asm/desc.h>
24650+#include <asm/bios_ebda.h>
24651
24652 unsigned long __initdata pgt_buf_start;
24653 unsigned long __meminitdata pgt_buf_end;
24654@@ -44,7 +47,7 @@ static void __init find_early_table_space(struct map_range *mr, int nr_range)
24655 {
24656 int i;
24657 unsigned long puds = 0, pmds = 0, ptes = 0, tables;
24658- unsigned long start = 0, good_end;
24659+ unsigned long start = 0x100000, good_end;
24660 phys_addr_t base;
24661
24662 for (i = 0; i < nr_range; i++) {
24663@@ -321,10 +324,40 @@ unsigned long __init_refok init_memory_mapping(unsigned long start,
24664 * Access has to be given to non-kernel-ram areas as well, these contain the PCI
24665 * mmio resources as well as potential bios/acpi data regions.
24666 */
24667+
24668+#ifdef CONFIG_GRKERNSEC_KMEM
24669+static unsigned int ebda_start __read_only;
24670+static unsigned int ebda_end __read_only;
24671+#endif
24672+
24673 int devmem_is_allowed(unsigned long pagenr)
24674 {
24675- if (pagenr < 256)
24676+#ifdef CONFIG_GRKERNSEC_KMEM
24677+ /* allow BDA */
24678+ if (!pagenr)
24679 return 1;
24680+ /* allow EBDA */
24681+ if (pagenr >= ebda_start && pagenr < ebda_end)
24682+ return 1;
24683+ /* if tboot is in use, allow access to its hardcoded serial log range */
24684+ if (tboot_enabled() && ((0x60000 >> PAGE_SHIFT) <= pagenr) && (pagenr < (0x68000 >> PAGE_SHIFT)))
24685+ return 1;
24686+#else
24687+ if (!pagenr)
24688+ return 1;
24689+#ifdef CONFIG_VM86
24690+ if (pagenr < (ISA_START_ADDRESS >> PAGE_SHIFT))
24691+ return 1;
24692+#endif
24693+#endif
24694+
24695+ if ((ISA_START_ADDRESS >> PAGE_SHIFT) <= pagenr && pagenr < (ISA_END_ADDRESS >> PAGE_SHIFT))
24696+ return 1;
24697+#ifdef CONFIG_GRKERNSEC_KMEM
24698+ /* throw out everything else below 1MB */
24699+ if (pagenr <= 256)
24700+ return 0;
24701+#endif
24702 if (iomem_is_exclusive(pagenr << PAGE_SHIFT))
24703 return 0;
24704 if (!page_is_ram(pagenr))
24705@@ -381,8 +414,117 @@ void free_init_pages(char *what, unsigned long begin, unsigned long end)
24706 #endif
24707 }
24708
24709+#ifdef CONFIG_GRKERNSEC_KMEM
24710+static inline void gr_init_ebda(void)
24711+{
24712+ unsigned int ebda_addr;
24713+ unsigned int ebda_size = 0;
24714+
24715+ ebda_addr = get_bios_ebda();
24716+ if (ebda_addr) {
24717+ ebda_size = *(unsigned char *)phys_to_virt(ebda_addr);
24718+ ebda_size <<= 10;
24719+ }
24720+ if (ebda_addr && ebda_size) {
24721+ ebda_start = ebda_addr >> PAGE_SHIFT;
24722+ ebda_end = min((unsigned int)PAGE_ALIGN(ebda_addr + ebda_size), (unsigned int)0xa0000) >> PAGE_SHIFT;
24723+ } else {
24724+ ebda_start = 0x9f000 >> PAGE_SHIFT;
24725+ ebda_end = 0xa0000 >> PAGE_SHIFT;
24726+ }
24727+}
24728+#else
24729+static inline void gr_init_ebda(void) { }
24730+#endif
24731+
24732 void free_initmem(void)
24733 {
24734+#ifdef CONFIG_PAX_KERNEXEC
24735+#ifdef CONFIG_X86_32
24736+ /* PaX: limit KERNEL_CS to actual size */
24737+ unsigned long addr, limit;
24738+ struct desc_struct d;
24739+ int cpu;
24740+#else
24741+ pgd_t *pgd;
24742+ pud_t *pud;
24743+ pmd_t *pmd;
24744+ unsigned long addr, end;
24745+#endif
24746+#endif
24747+
24748+ gr_init_ebda();
24749+
24750+#ifdef CONFIG_PAX_KERNEXEC
24751+#ifdef CONFIG_X86_32
24752+ limit = paravirt_enabled() ? ktva_ktla(0xffffffff) : (unsigned long)&_etext;
24753+ limit = (limit - 1UL) >> PAGE_SHIFT;
24754+
24755+ memset(__LOAD_PHYSICAL_ADDR + PAGE_OFFSET, POISON_FREE_INITMEM, PAGE_SIZE);
24756+ for (cpu = 0; cpu < nr_cpu_ids; cpu++) {
24757+ pack_descriptor(&d, get_desc_base(&get_cpu_gdt_table(cpu)[GDT_ENTRY_KERNEL_CS]), limit, 0x9B, 0xC);
24758+ write_gdt_entry(get_cpu_gdt_table(cpu), GDT_ENTRY_KERNEL_CS, &d, DESCTYPE_S);
24759+ write_gdt_entry(get_cpu_gdt_table(cpu), GDT_ENTRY_KERNEXEC_KERNEL_CS, &d, DESCTYPE_S);
24760+ }
24761+
24762+ /* PaX: make KERNEL_CS read-only */
24763+ addr = PFN_ALIGN(ktla_ktva((unsigned long)&_text));
24764+ if (!paravirt_enabled())
24765+ set_memory_ro(addr, (PFN_ALIGN(_sdata) - addr) >> PAGE_SHIFT);
24766+/*
24767+ for (addr = ktla_ktva((unsigned long)&_text); addr < (unsigned long)&_sdata; addr += PMD_SIZE) {
24768+ pgd = pgd_offset_k(addr);
24769+ pud = pud_offset(pgd, addr);
24770+ pmd = pmd_offset(pud, addr);
24771+ set_pmd(pmd, __pmd(pmd_val(*pmd) & ~_PAGE_RW));
24772+ }
24773+*/
24774+#ifdef CONFIG_X86_PAE
24775+ set_memory_nx(PFN_ALIGN(__init_begin), (PFN_ALIGN(__init_end) - PFN_ALIGN(__init_begin)) >> PAGE_SHIFT);
24776+/*
24777+ for (addr = (unsigned long)&__init_begin; addr < (unsigned long)&__init_end; addr += PMD_SIZE) {
24778+ pgd = pgd_offset_k(addr);
24779+ pud = pud_offset(pgd, addr);
24780+ pmd = pmd_offset(pud, addr);
24781+ set_pmd(pmd, __pmd(pmd_val(*pmd) | (_PAGE_NX & __supported_pte_mask)));
24782+ }
24783+*/
24784+#endif
24785+
24786+#ifdef CONFIG_MODULES
24787+ set_memory_4k((unsigned long)MODULES_EXEC_VADDR, (MODULES_EXEC_END - MODULES_EXEC_VADDR) >> PAGE_SHIFT);
24788+#endif
24789+
24790+#else
24791+ /* PaX: make kernel code/rodata read-only, rest non-executable */
24792+ for (addr = __START_KERNEL_map; addr < __START_KERNEL_map + KERNEL_IMAGE_SIZE; addr += PMD_SIZE) {
24793+ pgd = pgd_offset_k(addr);
24794+ pud = pud_offset(pgd, addr);
24795+ pmd = pmd_offset(pud, addr);
24796+ if (!pmd_present(*pmd))
24797+ continue;
24798+ if ((unsigned long)_text <= addr && addr < (unsigned long)_sdata)
24799+ set_pmd(pmd, __pmd(pmd_val(*pmd) & ~_PAGE_RW));
24800+ else
24801+ set_pmd(pmd, __pmd(pmd_val(*pmd) | (_PAGE_NX & __supported_pte_mask)));
24802+ }
24803+
24804+ addr = (unsigned long)__va(__pa(__START_KERNEL_map));
24805+ end = addr + KERNEL_IMAGE_SIZE;
24806+ for (; addr < end; addr += PMD_SIZE) {
24807+ pgd = pgd_offset_k(addr);
24808+ pud = pud_offset(pgd, addr);
24809+ pmd = pmd_offset(pud, addr);
24810+ if (!pmd_present(*pmd))
24811+ continue;
24812+ if ((unsigned long)__va(__pa(_text)) <= addr && addr < (unsigned long)__va(__pa(_sdata)))
24813+ set_pmd(pmd, __pmd(pmd_val(*pmd) & ~_PAGE_RW));
24814+ }
24815+#endif
24816+
24817+ flush_tlb_all();
24818+#endif
24819+
24820 free_init_pages("unused kernel memory",
24821 (unsigned long)(&__init_begin),
24822 (unsigned long)(&__init_end));
24823diff --git a/arch/x86/mm/init_32.c b/arch/x86/mm/init_32.c
24824index 575d86f..4987469 100644
24825--- a/arch/x86/mm/init_32.c
24826+++ b/arch/x86/mm/init_32.c
24827@@ -73,36 +73,6 @@ static __init void *alloc_low_page(void)
24828 }
24829
24830 /*
24831- * Creates a middle page table and puts a pointer to it in the
24832- * given global directory entry. This only returns the gd entry
24833- * in non-PAE compilation mode, since the middle layer is folded.
24834- */
24835-static pmd_t * __init one_md_table_init(pgd_t *pgd)
24836-{
24837- pud_t *pud;
24838- pmd_t *pmd_table;
24839-
24840-#ifdef CONFIG_X86_PAE
24841- if (!(pgd_val(*pgd) & _PAGE_PRESENT)) {
24842- if (after_bootmem)
24843- pmd_table = (pmd_t *)alloc_bootmem_pages(PAGE_SIZE);
24844- else
24845- pmd_table = (pmd_t *)alloc_low_page();
24846- paravirt_alloc_pmd(&init_mm, __pa(pmd_table) >> PAGE_SHIFT);
24847- set_pgd(pgd, __pgd(__pa(pmd_table) | _PAGE_PRESENT));
24848- pud = pud_offset(pgd, 0);
24849- BUG_ON(pmd_table != pmd_offset(pud, 0));
24850-
24851- return pmd_table;
24852- }
24853-#endif
24854- pud = pud_offset(pgd, 0);
24855- pmd_table = pmd_offset(pud, 0);
24856-
24857- return pmd_table;
24858-}
24859-
24860-/*
24861 * Create a page table and place a pointer to it in a middle page
24862 * directory entry:
24863 */
24864@@ -122,13 +92,28 @@ static pte_t * __init one_page_table_init(pmd_t *pmd)
24865 page_table = (pte_t *)alloc_low_page();
24866
24867 paravirt_alloc_pte(&init_mm, __pa(page_table) >> PAGE_SHIFT);
24868+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
24869+ set_pmd(pmd, __pmd(__pa(page_table) | _KERNPG_TABLE));
24870+#else
24871 set_pmd(pmd, __pmd(__pa(page_table) | _PAGE_TABLE));
24872+#endif
24873 BUG_ON(page_table != pte_offset_kernel(pmd, 0));
24874 }
24875
24876 return pte_offset_kernel(pmd, 0);
24877 }
24878
24879+static pmd_t * __init one_md_table_init(pgd_t *pgd)
24880+{
24881+ pud_t *pud;
24882+ pmd_t *pmd_table;
24883+
24884+ pud = pud_offset(pgd, 0);
24885+ pmd_table = pmd_offset(pud, 0);
24886+
24887+ return pmd_table;
24888+}
24889+
24890 pmd_t * __init populate_extra_pmd(unsigned long vaddr)
24891 {
24892 int pgd_idx = pgd_index(vaddr);
24893@@ -202,6 +187,7 @@ page_table_range_init(unsigned long start, unsigned long end, pgd_t *pgd_base)
24894 int pgd_idx, pmd_idx;
24895 unsigned long vaddr;
24896 pgd_t *pgd;
24897+ pud_t *pud;
24898 pmd_t *pmd;
24899 pte_t *pte = NULL;
24900
24901@@ -211,8 +197,13 @@ page_table_range_init(unsigned long start, unsigned long end, pgd_t *pgd_base)
24902 pgd = pgd_base + pgd_idx;
24903
24904 for ( ; (pgd_idx < PTRS_PER_PGD) && (vaddr != end); pgd++, pgd_idx++) {
24905- pmd = one_md_table_init(pgd);
24906- pmd = pmd + pmd_index(vaddr);
24907+ pud = pud_offset(pgd, vaddr);
24908+ pmd = pmd_offset(pud, vaddr);
24909+
24910+#ifdef CONFIG_X86_PAE
24911+ paravirt_alloc_pmd(&init_mm, __pa(pmd) >> PAGE_SHIFT);
24912+#endif
24913+
24914 for (; (pmd_idx < PTRS_PER_PMD) && (vaddr != end);
24915 pmd++, pmd_idx++) {
24916 pte = page_table_kmap_check(one_page_table_init(pmd),
24917@@ -224,11 +215,20 @@ page_table_range_init(unsigned long start, unsigned long end, pgd_t *pgd_base)
24918 }
24919 }
24920
24921-static inline int is_kernel_text(unsigned long addr)
24922+static inline int is_kernel_text(unsigned long start, unsigned long end)
24923 {
24924- if (addr >= (unsigned long)_text && addr <= (unsigned long)__init_end)
24925- return 1;
24926- return 0;
24927+ if ((start > ktla_ktva((unsigned long)_etext) ||
24928+ end <= ktla_ktva((unsigned long)_stext)) &&
24929+ (start > ktla_ktva((unsigned long)_einittext) ||
24930+ end <= ktla_ktva((unsigned long)_sinittext)) &&
24931+
24932+#ifdef CONFIG_ACPI_SLEEP
24933+ (start > (unsigned long)__va(acpi_wakeup_address) + 0x4000 || end <= (unsigned long)__va(acpi_wakeup_address)) &&
24934+#endif
24935+
24936+ (start > (unsigned long)__va(0xfffff) || end <= (unsigned long)__va(0xc0000)))
24937+ return 0;
24938+ return 1;
24939 }
24940
24941 /*
24942@@ -245,9 +245,10 @@ kernel_physical_mapping_init(unsigned long start,
24943 unsigned long last_map_addr = end;
24944 unsigned long start_pfn, end_pfn;
24945 pgd_t *pgd_base = swapper_pg_dir;
24946- int pgd_idx, pmd_idx, pte_ofs;
24947+ unsigned int pgd_idx, pmd_idx, pte_ofs;
24948 unsigned long pfn;
24949 pgd_t *pgd;
24950+ pud_t *pud;
24951 pmd_t *pmd;
24952 pte_t *pte;
24953 unsigned pages_2m, pages_4k;
24954@@ -280,8 +281,13 @@ repeat:
24955 pfn = start_pfn;
24956 pgd_idx = pgd_index((pfn<<PAGE_SHIFT) + PAGE_OFFSET);
24957 pgd = pgd_base + pgd_idx;
24958- for (; pgd_idx < PTRS_PER_PGD; pgd++, pgd_idx++) {
24959- pmd = one_md_table_init(pgd);
24960+ for (; pgd_idx < PTRS_PER_PGD && pfn < max_low_pfn; pgd++, pgd_idx++) {
24961+ pud = pud_offset(pgd, 0);
24962+ pmd = pmd_offset(pud, 0);
24963+
24964+#ifdef CONFIG_X86_PAE
24965+ paravirt_alloc_pmd(&init_mm, __pa(pmd) >> PAGE_SHIFT);
24966+#endif
24967
24968 if (pfn >= end_pfn)
24969 continue;
24970@@ -293,14 +299,13 @@ repeat:
24971 #endif
24972 for (; pmd_idx < PTRS_PER_PMD && pfn < end_pfn;
24973 pmd++, pmd_idx++) {
24974- unsigned int addr = pfn * PAGE_SIZE + PAGE_OFFSET;
24975+ unsigned long address = pfn * PAGE_SIZE + PAGE_OFFSET;
24976
24977 /*
24978 * Map with big pages if possible, otherwise
24979 * create normal page tables:
24980 */
24981 if (use_pse) {
24982- unsigned int addr2;
24983 pgprot_t prot = PAGE_KERNEL_LARGE;
24984 /*
24985 * first pass will use the same initial
24986@@ -310,11 +315,7 @@ repeat:
24987 __pgprot(PTE_IDENT_ATTR |
24988 _PAGE_PSE);
24989
24990- addr2 = (pfn + PTRS_PER_PTE-1) * PAGE_SIZE +
24991- PAGE_OFFSET + PAGE_SIZE-1;
24992-
24993- if (is_kernel_text(addr) ||
24994- is_kernel_text(addr2))
24995+ if (is_kernel_text(address, address + PMD_SIZE))
24996 prot = PAGE_KERNEL_LARGE_EXEC;
24997
24998 pages_2m++;
24999@@ -331,7 +332,7 @@ repeat:
25000 pte_ofs = pte_index((pfn<<PAGE_SHIFT) + PAGE_OFFSET);
25001 pte += pte_ofs;
25002 for (; pte_ofs < PTRS_PER_PTE && pfn < end_pfn;
25003- pte++, pfn++, pte_ofs++, addr += PAGE_SIZE) {
25004+ pte++, pfn++, pte_ofs++, address += PAGE_SIZE) {
25005 pgprot_t prot = PAGE_KERNEL;
25006 /*
25007 * first pass will use the same initial
25008@@ -339,7 +340,7 @@ repeat:
25009 */
25010 pgprot_t init_prot = __pgprot(PTE_IDENT_ATTR);
25011
25012- if (is_kernel_text(addr))
25013+ if (is_kernel_text(address, address + PAGE_SIZE))
25014 prot = PAGE_KERNEL_EXEC;
25015
25016 pages_4k++;
25017@@ -465,7 +466,7 @@ void __init native_pagetable_setup_start(pgd_t *base)
25018
25019 pud = pud_offset(pgd, va);
25020 pmd = pmd_offset(pud, va);
25021- if (!pmd_present(*pmd))
25022+ if (!pmd_present(*pmd) || pmd_huge(*pmd))
25023 break;
25024
25025 pte = pte_offset_kernel(pmd, va);
25026@@ -517,12 +518,10 @@ void __init early_ioremap_page_table_range_init(void)
25027
25028 static void __init pagetable_init(void)
25029 {
25030- pgd_t *pgd_base = swapper_pg_dir;
25031-
25032- permanent_kmaps_init(pgd_base);
25033+ permanent_kmaps_init(swapper_pg_dir);
25034 }
25035
25036-pteval_t __supported_pte_mask __read_mostly = ~(_PAGE_NX | _PAGE_GLOBAL | _PAGE_IOMAP);
25037+pteval_t __supported_pte_mask __read_only = ~(_PAGE_NX | _PAGE_GLOBAL | _PAGE_IOMAP);
25038 EXPORT_SYMBOL_GPL(__supported_pte_mask);
25039
25040 /* user-defined highmem size */
25041@@ -734,6 +733,12 @@ void __init mem_init(void)
25042
25043 pci_iommu_alloc();
25044
25045+#ifdef CONFIG_PAX_PER_CPU_PGD
25046+ clone_pgd_range(get_cpu_pgd(0) + KERNEL_PGD_BOUNDARY,
25047+ swapper_pg_dir + KERNEL_PGD_BOUNDARY,
25048+ KERNEL_PGD_PTRS);
25049+#endif
25050+
25051 #ifdef CONFIG_FLATMEM
25052 BUG_ON(!mem_map);
25053 #endif
25054@@ -760,7 +765,7 @@ void __init mem_init(void)
25055 reservedpages++;
25056
25057 codesize = (unsigned long) &_etext - (unsigned long) &_text;
25058- datasize = (unsigned long) &_edata - (unsigned long) &_etext;
25059+ datasize = (unsigned long) &_edata - (unsigned long) &_sdata;
25060 initsize = (unsigned long) &__init_end - (unsigned long) &__init_begin;
25061
25062 printk(KERN_INFO "Memory: %luk/%luk available (%dk kernel code, "
25063@@ -801,10 +806,10 @@ void __init mem_init(void)
25064 ((unsigned long)&__init_end -
25065 (unsigned long)&__init_begin) >> 10,
25066
25067- (unsigned long)&_etext, (unsigned long)&_edata,
25068- ((unsigned long)&_edata - (unsigned long)&_etext) >> 10,
25069+ (unsigned long)&_sdata, (unsigned long)&_edata,
25070+ ((unsigned long)&_edata - (unsigned long)&_sdata) >> 10,
25071
25072- (unsigned long)&_text, (unsigned long)&_etext,
25073+ ktla_ktva((unsigned long)&_text), ktla_ktva((unsigned long)&_etext),
25074 ((unsigned long)&_etext - (unsigned long)&_text) >> 10);
25075
25076 /*
25077@@ -882,6 +887,7 @@ void set_kernel_text_rw(void)
25078 if (!kernel_set_to_readonly)
25079 return;
25080
25081+ start = ktla_ktva(start);
25082 pr_debug("Set kernel text: %lx - %lx for read write\n",
25083 start, start+size);
25084
25085@@ -896,6 +902,7 @@ void set_kernel_text_ro(void)
25086 if (!kernel_set_to_readonly)
25087 return;
25088
25089+ start = ktla_ktva(start);
25090 pr_debug("Set kernel text: %lx - %lx for read only\n",
25091 start, start+size);
25092
25093@@ -924,6 +931,7 @@ void mark_rodata_ro(void)
25094 unsigned long start = PFN_ALIGN(_text);
25095 unsigned long size = PFN_ALIGN(_etext) - start;
25096
25097+ start = ktla_ktva(start);
25098 set_pages_ro(virt_to_page(start), size >> PAGE_SHIFT);
25099 printk(KERN_INFO "Write protecting the kernel text: %luk\n",
25100 size >> 10);
25101diff --git a/arch/x86/mm/init_64.c b/arch/x86/mm/init_64.c
25102index 3baff25..8b37564 100644
25103--- a/arch/x86/mm/init_64.c
25104+++ b/arch/x86/mm/init_64.c
25105@@ -74,7 +74,7 @@ early_param("gbpages", parse_direct_gbpages_on);
25106 * around without checking the pgd every time.
25107 */
25108
25109-pteval_t __supported_pte_mask __read_mostly = ~_PAGE_IOMAP;
25110+pteval_t __supported_pte_mask __read_only = ~(_PAGE_NX | _PAGE_IOMAP);
25111 EXPORT_SYMBOL_GPL(__supported_pte_mask);
25112
25113 int force_personality32;
25114@@ -107,12 +107,22 @@ void sync_global_pgds(unsigned long start, unsigned long end)
25115
25116 for (address = start; address <= end; address += PGDIR_SIZE) {
25117 const pgd_t *pgd_ref = pgd_offset_k(address);
25118+
25119+#ifdef CONFIG_PAX_PER_CPU_PGD
25120+ unsigned long cpu;
25121+#else
25122 struct page *page;
25123+#endif
25124
25125 if (pgd_none(*pgd_ref))
25126 continue;
25127
25128 spin_lock(&pgd_lock);
25129+
25130+#ifdef CONFIG_PAX_PER_CPU_PGD
25131+ for (cpu = 0; cpu < nr_cpu_ids; ++cpu) {
25132+ pgd_t *pgd = pgd_offset_cpu(cpu, address);
25133+#else
25134 list_for_each_entry(page, &pgd_list, lru) {
25135 pgd_t *pgd;
25136 spinlock_t *pgt_lock;
25137@@ -121,6 +131,7 @@ void sync_global_pgds(unsigned long start, unsigned long end)
25138 /* the pgt_lock only for Xen */
25139 pgt_lock = &pgd_page_get_mm(page)->page_table_lock;
25140 spin_lock(pgt_lock);
25141+#endif
25142
25143 if (pgd_none(*pgd))
25144 set_pgd(pgd, *pgd_ref);
25145@@ -128,7 +139,10 @@ void sync_global_pgds(unsigned long start, unsigned long end)
25146 BUG_ON(pgd_page_vaddr(*pgd)
25147 != pgd_page_vaddr(*pgd_ref));
25148
25149+#ifndef CONFIG_PAX_PER_CPU_PGD
25150 spin_unlock(pgt_lock);
25151+#endif
25152+
25153 }
25154 spin_unlock(&pgd_lock);
25155 }
25156@@ -161,7 +175,7 @@ static pud_t *fill_pud(pgd_t *pgd, unsigned long vaddr)
25157 {
25158 if (pgd_none(*pgd)) {
25159 pud_t *pud = (pud_t *)spp_getpage();
25160- pgd_populate(&init_mm, pgd, pud);
25161+ pgd_populate_kernel(&init_mm, pgd, pud);
25162 if (pud != pud_offset(pgd, 0))
25163 printk(KERN_ERR "PAGETABLE BUG #00! %p <-> %p\n",
25164 pud, pud_offset(pgd, 0));
25165@@ -173,7 +187,7 @@ static pmd_t *fill_pmd(pud_t *pud, unsigned long vaddr)
25166 {
25167 if (pud_none(*pud)) {
25168 pmd_t *pmd = (pmd_t *) spp_getpage();
25169- pud_populate(&init_mm, pud, pmd);
25170+ pud_populate_kernel(&init_mm, pud, pmd);
25171 if (pmd != pmd_offset(pud, 0))
25172 printk(KERN_ERR "PAGETABLE BUG #01! %p <-> %p\n",
25173 pmd, pmd_offset(pud, 0));
25174@@ -202,7 +216,9 @@ void set_pte_vaddr_pud(pud_t *pud_page, unsigned long vaddr, pte_t new_pte)
25175 pmd = fill_pmd(pud, vaddr);
25176 pte = fill_pte(pmd, vaddr);
25177
25178+ pax_open_kernel();
25179 set_pte(pte, new_pte);
25180+ pax_close_kernel();
25181
25182 /*
25183 * It's enough to flush this one mapping.
25184@@ -261,14 +277,12 @@ static void __init __init_extra_mapping(unsigned long phys, unsigned long size,
25185 pgd = pgd_offset_k((unsigned long)__va(phys));
25186 if (pgd_none(*pgd)) {
25187 pud = (pud_t *) spp_getpage();
25188- set_pgd(pgd, __pgd(__pa(pud) | _KERNPG_TABLE |
25189- _PAGE_USER));
25190+ set_pgd(pgd, __pgd(__pa(pud) | _PAGE_TABLE));
25191 }
25192 pud = pud_offset(pgd, (unsigned long)__va(phys));
25193 if (pud_none(*pud)) {
25194 pmd = (pmd_t *) spp_getpage();
25195- set_pud(pud, __pud(__pa(pmd) | _KERNPG_TABLE |
25196- _PAGE_USER));
25197+ set_pud(pud, __pud(__pa(pmd) | _PAGE_TABLE));
25198 }
25199 pmd = pmd_offset(pud, phys);
25200 BUG_ON(!pmd_none(*pmd));
25201@@ -329,7 +343,7 @@ static __ref void *alloc_low_page(unsigned long *phys)
25202 if (pfn >= pgt_buf_top)
25203 panic("alloc_low_page: ran out of memory");
25204
25205- adr = early_memremap(pfn * PAGE_SIZE, PAGE_SIZE);
25206+ adr = (void __force_kernel *)early_memremap(pfn * PAGE_SIZE, PAGE_SIZE);
25207 clear_page(adr);
25208 *phys = pfn * PAGE_SIZE;
25209 return adr;
25210@@ -345,7 +359,7 @@ static __ref void *map_low_page(void *virt)
25211
25212 phys = __pa(virt);
25213 left = phys & (PAGE_SIZE - 1);
25214- adr = early_memremap(phys & PAGE_MASK, PAGE_SIZE);
25215+ adr = (void __force_kernel *)early_memremap(phys & PAGE_MASK, PAGE_SIZE);
25216 adr = (void *)(((unsigned long)adr) | left);
25217
25218 return adr;
25219@@ -553,7 +567,7 @@ phys_pud_init(pud_t *pud_page, unsigned long addr, unsigned long end,
25220 unmap_low_page(pmd);
25221
25222 spin_lock(&init_mm.page_table_lock);
25223- pud_populate(&init_mm, pud, __va(pmd_phys));
25224+ pud_populate_kernel(&init_mm, pud, __va(pmd_phys));
25225 spin_unlock(&init_mm.page_table_lock);
25226 }
25227 __flush_tlb_all();
25228@@ -599,7 +613,7 @@ kernel_physical_mapping_init(unsigned long start,
25229 unmap_low_page(pud);
25230
25231 spin_lock(&init_mm.page_table_lock);
25232- pgd_populate(&init_mm, pgd, __va(pud_phys));
25233+ pgd_populate_kernel(&init_mm, pgd, __va(pud_phys));
25234 spin_unlock(&init_mm.page_table_lock);
25235 pgd_changed = true;
25236 }
25237@@ -691,6 +705,12 @@ void __init mem_init(void)
25238
25239 pci_iommu_alloc();
25240
25241+#ifdef CONFIG_PAX_PER_CPU_PGD
25242+ clone_pgd_range(get_cpu_pgd(0) + KERNEL_PGD_BOUNDARY,
25243+ swapper_pg_dir + KERNEL_PGD_BOUNDARY,
25244+ KERNEL_PGD_PTRS);
25245+#endif
25246+
25247 /* clear_bss() already clear the empty_zero_page */
25248
25249 reservedpages = 0;
25250@@ -851,8 +871,8 @@ int kern_addr_valid(unsigned long addr)
25251 static struct vm_area_struct gate_vma = {
25252 .vm_start = VSYSCALL_START,
25253 .vm_end = VSYSCALL_START + (VSYSCALL_MAPPED_PAGES * PAGE_SIZE),
25254- .vm_page_prot = PAGE_READONLY_EXEC,
25255- .vm_flags = VM_READ | VM_EXEC
25256+ .vm_page_prot = PAGE_READONLY,
25257+ .vm_flags = VM_READ
25258 };
25259
25260 struct vm_area_struct *get_gate_vma(struct mm_struct *mm)
25261@@ -886,7 +906,7 @@ int in_gate_area_no_mm(unsigned long addr)
25262
25263 const char *arch_vma_name(struct vm_area_struct *vma)
25264 {
25265- if (vma->vm_mm && vma->vm_start == (long)vma->vm_mm->context.vdso)
25266+ if (vma->vm_mm && vma->vm_start == vma->vm_mm->context.vdso)
25267 return "[vdso]";
25268 if (vma == &gate_vma)
25269 return "[vsyscall]";
25270diff --git a/arch/x86/mm/iomap_32.c b/arch/x86/mm/iomap_32.c
25271index 7b179b4..6bd1777 100644
25272--- a/arch/x86/mm/iomap_32.c
25273+++ b/arch/x86/mm/iomap_32.c
25274@@ -64,7 +64,11 @@ void *kmap_atomic_prot_pfn(unsigned long pfn, pgprot_t prot)
25275 type = kmap_atomic_idx_push();
25276 idx = type + KM_TYPE_NR * smp_processor_id();
25277 vaddr = __fix_to_virt(FIX_KMAP_BEGIN + idx);
25278+
25279+ pax_open_kernel();
25280 set_pte(kmap_pte - idx, pfn_pte(pfn, prot));
25281+ pax_close_kernel();
25282+
25283 arch_flush_lazy_mmu_mode();
25284
25285 return (void *)vaddr;
25286diff --git a/arch/x86/mm/ioremap.c b/arch/x86/mm/ioremap.c
25287index 78fe3f1..8293b6f 100644
25288--- a/arch/x86/mm/ioremap.c
25289+++ b/arch/x86/mm/ioremap.c
25290@@ -97,7 +97,7 @@ static void __iomem *__ioremap_caller(resource_size_t phys_addr,
25291 for (pfn = phys_addr >> PAGE_SHIFT; pfn <= last_pfn; pfn++) {
25292 int is_ram = page_is_ram(pfn);
25293
25294- if (is_ram && pfn_valid(pfn) && !PageReserved(pfn_to_page(pfn)))
25295+ if (is_ram && pfn_valid(pfn) && (pfn >= 0x100 || !PageReserved(pfn_to_page(pfn))))
25296 return NULL;
25297 WARN_ON_ONCE(is_ram);
25298 }
25299@@ -315,6 +315,9 @@ void *xlate_dev_mem_ptr(unsigned long phys)
25300
25301 /* If page is RAM, we can use __va. Otherwise ioremap and unmap. */
25302 if (page_is_ram(start >> PAGE_SHIFT))
25303+#ifdef CONFIG_HIGHMEM
25304+ if ((start >> PAGE_SHIFT) < max_low_pfn)
25305+#endif
25306 return __va(phys);
25307
25308 addr = (void __force *)ioremap_cache(start, PAGE_SIZE);
25309@@ -344,7 +347,7 @@ static int __init early_ioremap_debug_setup(char *str)
25310 early_param("early_ioremap_debug", early_ioremap_debug_setup);
25311
25312 static __initdata int after_paging_init;
25313-static pte_t bm_pte[PAGE_SIZE/sizeof(pte_t)] __page_aligned_bss;
25314+static pte_t bm_pte[PAGE_SIZE/sizeof(pte_t)] __read_only __aligned(PAGE_SIZE);
25315
25316 static inline pmd_t * __init early_ioremap_pmd(unsigned long addr)
25317 {
25318@@ -381,8 +384,7 @@ void __init early_ioremap_init(void)
25319 slot_virt[i] = __fix_to_virt(FIX_BTMAP_BEGIN - NR_FIX_BTMAPS*i);
25320
25321 pmd = early_ioremap_pmd(fix_to_virt(FIX_BTMAP_BEGIN));
25322- memset(bm_pte, 0, sizeof(bm_pte));
25323- pmd_populate_kernel(&init_mm, pmd, bm_pte);
25324+ pmd_populate_user(&init_mm, pmd, bm_pte);
25325
25326 /*
25327 * The boot-ioremap range spans multiple pmds, for which
25328diff --git a/arch/x86/mm/kmemcheck/kmemcheck.c b/arch/x86/mm/kmemcheck/kmemcheck.c
25329index d87dd6d..bf3fa66 100644
25330--- a/arch/x86/mm/kmemcheck/kmemcheck.c
25331+++ b/arch/x86/mm/kmemcheck/kmemcheck.c
25332@@ -622,9 +622,9 @@ bool kmemcheck_fault(struct pt_regs *regs, unsigned long address,
25333 * memory (e.g. tracked pages)? For now, we need this to avoid
25334 * invoking kmemcheck for PnP BIOS calls.
25335 */
25336- if (regs->flags & X86_VM_MASK)
25337+ if (v8086_mode(regs))
25338 return false;
25339- if (regs->cs != __KERNEL_CS)
25340+ if (regs->cs != __KERNEL_CS && regs->cs != __KERNEXEC_KERNEL_CS)
25341 return false;
25342
25343 pte = kmemcheck_pte_lookup(address);
25344diff --git a/arch/x86/mm/mmap.c b/arch/x86/mm/mmap.c
25345index 845df68..1d8d29f 100644
25346--- a/arch/x86/mm/mmap.c
25347+++ b/arch/x86/mm/mmap.c
25348@@ -52,7 +52,7 @@ static unsigned int stack_maxrandom_size(void)
25349 * Leave an at least ~128 MB hole with possible stack randomization.
25350 */
25351 #define MIN_GAP (128*1024*1024UL + stack_maxrandom_size())
25352-#define MAX_GAP (TASK_SIZE/6*5)
25353+#define MAX_GAP (pax_task_size/6*5)
25354
25355 static int mmap_is_legacy(void)
25356 {
25357@@ -82,27 +82,40 @@ static unsigned long mmap_rnd(void)
25358 return rnd << PAGE_SHIFT;
25359 }
25360
25361-static unsigned long mmap_base(void)
25362+static unsigned long mmap_base(struct mm_struct *mm)
25363 {
25364 unsigned long gap = rlimit(RLIMIT_STACK);
25365+ unsigned long pax_task_size = TASK_SIZE;
25366+
25367+#ifdef CONFIG_PAX_SEGMEXEC
25368+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
25369+ pax_task_size = SEGMEXEC_TASK_SIZE;
25370+#endif
25371
25372 if (gap < MIN_GAP)
25373 gap = MIN_GAP;
25374 else if (gap > MAX_GAP)
25375 gap = MAX_GAP;
25376
25377- return PAGE_ALIGN(TASK_SIZE - gap - mmap_rnd());
25378+ return PAGE_ALIGN(pax_task_size - gap - mmap_rnd());
25379 }
25380
25381 /*
25382 * Bottom-up (legacy) layout on X86_32 did not support randomization, X86_64
25383 * does, but not when emulating X86_32
25384 */
25385-static unsigned long mmap_legacy_base(void)
25386+static unsigned long mmap_legacy_base(struct mm_struct *mm)
25387 {
25388- if (mmap_is_ia32())
25389+ if (mmap_is_ia32()) {
25390+
25391+#ifdef CONFIG_PAX_SEGMEXEC
25392+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
25393+ return SEGMEXEC_TASK_UNMAPPED_BASE;
25394+ else
25395+#endif
25396+
25397 return TASK_UNMAPPED_BASE;
25398- else
25399+ } else
25400 return TASK_UNMAPPED_BASE + mmap_rnd();
25401 }
25402
25403@@ -113,11 +126,23 @@ static unsigned long mmap_legacy_base(void)
25404 void arch_pick_mmap_layout(struct mm_struct *mm)
25405 {
25406 if (mmap_is_legacy()) {
25407- mm->mmap_base = mmap_legacy_base();
25408+ mm->mmap_base = mmap_legacy_base(mm);
25409+
25410+#ifdef CONFIG_PAX_RANDMMAP
25411+ if (mm->pax_flags & MF_PAX_RANDMMAP)
25412+ mm->mmap_base += mm->delta_mmap;
25413+#endif
25414+
25415 mm->get_unmapped_area = arch_get_unmapped_area;
25416 mm->unmap_area = arch_unmap_area;
25417 } else {
25418- mm->mmap_base = mmap_base();
25419+ mm->mmap_base = mmap_base(mm);
25420+
25421+#ifdef CONFIG_PAX_RANDMMAP
25422+ if (mm->pax_flags & MF_PAX_RANDMMAP)
25423+ mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
25424+#endif
25425+
25426 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
25427 mm->unmap_area = arch_unmap_area_topdown;
25428 }
25429diff --git a/arch/x86/mm/mmio-mod.c b/arch/x86/mm/mmio-mod.c
25430index dc0b727..dc9d71a 100644
25431--- a/arch/x86/mm/mmio-mod.c
25432+++ b/arch/x86/mm/mmio-mod.c
25433@@ -194,7 +194,7 @@ static void pre(struct kmmio_probe *p, struct pt_regs *regs,
25434 break;
25435 default:
25436 {
25437- unsigned char *ip = (unsigned char *)instptr;
25438+ unsigned char *ip = (unsigned char *)ktla_ktva(instptr);
25439 my_trace->opcode = MMIO_UNKNOWN_OP;
25440 my_trace->width = 0;
25441 my_trace->value = (*ip) << 16 | *(ip + 1) << 8 |
25442@@ -234,7 +234,7 @@ static void post(struct kmmio_probe *p, unsigned long condition,
25443 static void ioremap_trace_core(resource_size_t offset, unsigned long size,
25444 void __iomem *addr)
25445 {
25446- static atomic_t next_id;
25447+ static atomic_unchecked_t next_id;
25448 struct remap_trace *trace = kmalloc(sizeof(*trace), GFP_KERNEL);
25449 /* These are page-unaligned. */
25450 struct mmiotrace_map map = {
25451@@ -258,7 +258,7 @@ static void ioremap_trace_core(resource_size_t offset, unsigned long size,
25452 .private = trace
25453 },
25454 .phys = offset,
25455- .id = atomic_inc_return(&next_id)
25456+ .id = atomic_inc_return_unchecked(&next_id)
25457 };
25458 map.map_id = trace->id;
25459
25460diff --git a/arch/x86/mm/pageattr-test.c b/arch/x86/mm/pageattr-test.c
25461index b008656..773eac2 100644
25462--- a/arch/x86/mm/pageattr-test.c
25463+++ b/arch/x86/mm/pageattr-test.c
25464@@ -36,7 +36,7 @@ enum {
25465
25466 static int pte_testbit(pte_t pte)
25467 {
25468- return pte_flags(pte) & _PAGE_UNUSED1;
25469+ return pte_flags(pte) & _PAGE_CPA_TEST;
25470 }
25471
25472 struct split_state {
25473diff --git a/arch/x86/mm/pageattr.c b/arch/x86/mm/pageattr.c
25474index a718e0d..45efc32 100644
25475--- a/arch/x86/mm/pageattr.c
25476+++ b/arch/x86/mm/pageattr.c
25477@@ -261,7 +261,7 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
25478 */
25479 #ifdef CONFIG_PCI_BIOS
25480 if (pcibios_enabled && within(pfn, BIOS_BEGIN >> PAGE_SHIFT, BIOS_END >> PAGE_SHIFT))
25481- pgprot_val(forbidden) |= _PAGE_NX;
25482+ pgprot_val(forbidden) |= _PAGE_NX & __supported_pte_mask;
25483 #endif
25484
25485 /*
25486@@ -269,9 +269,10 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
25487 * Does not cover __inittext since that is gone later on. On
25488 * 64bit we do not enforce !NX on the low mapping
25489 */
25490- if (within(address, (unsigned long)_text, (unsigned long)_etext))
25491- pgprot_val(forbidden) |= _PAGE_NX;
25492+ if (within(address, ktla_ktva((unsigned long)_text), ktla_ktva((unsigned long)_etext)))
25493+ pgprot_val(forbidden) |= _PAGE_NX & __supported_pte_mask;
25494
25495+#ifdef CONFIG_DEBUG_RODATA
25496 /*
25497 * The .rodata section needs to be read-only. Using the pfn
25498 * catches all aliases.
25499@@ -279,6 +280,7 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
25500 if (within(pfn, __pa((unsigned long)__start_rodata) >> PAGE_SHIFT,
25501 __pa((unsigned long)__end_rodata) >> PAGE_SHIFT))
25502 pgprot_val(forbidden) |= _PAGE_RW;
25503+#endif
25504
25505 #if defined(CONFIG_X86_64) && defined(CONFIG_DEBUG_RODATA)
25506 /*
25507@@ -317,6 +319,13 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
25508 }
25509 #endif
25510
25511+#ifdef CONFIG_PAX_KERNEXEC
25512+ if (within(pfn, __pa((unsigned long)&_text), __pa((unsigned long)&_sdata))) {
25513+ pgprot_val(forbidden) |= _PAGE_RW;
25514+ pgprot_val(forbidden) |= _PAGE_NX & __supported_pte_mask;
25515+ }
25516+#endif
25517+
25518 prot = __pgprot(pgprot_val(prot) & ~pgprot_val(forbidden));
25519
25520 return prot;
25521@@ -369,23 +378,37 @@ EXPORT_SYMBOL_GPL(lookup_address);
25522 static void __set_pmd_pte(pte_t *kpte, unsigned long address, pte_t pte)
25523 {
25524 /* change init_mm */
25525+ pax_open_kernel();
25526 set_pte_atomic(kpte, pte);
25527+
25528 #ifdef CONFIG_X86_32
25529 if (!SHARED_KERNEL_PMD) {
25530+
25531+#ifdef CONFIG_PAX_PER_CPU_PGD
25532+ unsigned long cpu;
25533+#else
25534 struct page *page;
25535+#endif
25536
25537+#ifdef CONFIG_PAX_PER_CPU_PGD
25538+ for (cpu = 0; cpu < nr_cpu_ids; ++cpu) {
25539+ pgd_t *pgd = get_cpu_pgd(cpu);
25540+#else
25541 list_for_each_entry(page, &pgd_list, lru) {
25542- pgd_t *pgd;
25543+ pgd_t *pgd = (pgd_t *)page_address(page);
25544+#endif
25545+
25546 pud_t *pud;
25547 pmd_t *pmd;
25548
25549- pgd = (pgd_t *)page_address(page) + pgd_index(address);
25550+ pgd += pgd_index(address);
25551 pud = pud_offset(pgd, address);
25552 pmd = pmd_offset(pud, address);
25553 set_pte_atomic((pte_t *)pmd, pte);
25554 }
25555 }
25556 #endif
25557+ pax_close_kernel();
25558 }
25559
25560 static int
25561diff --git a/arch/x86/mm/pat.c b/arch/x86/mm/pat.c
25562index 3d68ef6..7f69136 100644
25563--- a/arch/x86/mm/pat.c
25564+++ b/arch/x86/mm/pat.c
25565@@ -376,7 +376,7 @@ int free_memtype(u64 start, u64 end)
25566
25567 if (!entry) {
25568 printk(KERN_INFO "%s:%d freeing invalid memtype [mem %#010Lx-%#010Lx]\n",
25569- current->comm, current->pid, start, end - 1);
25570+ current->comm, task_pid_nr(current), start, end - 1);
25571 return -EINVAL;
25572 }
25573
25574@@ -506,8 +506,8 @@ static inline int range_is_allowed(unsigned long pfn, unsigned long size)
25575
25576 while (cursor < to) {
25577 if (!devmem_is_allowed(pfn)) {
25578- printk(KERN_INFO "Program %s tried to access /dev/mem between [mem %#010Lx-%#010Lx]\n",
25579- current->comm, from, to - 1);
25580+ printk(KERN_INFO "Program %s tried to access /dev/mem between [mem %#010Lx-%#010Lx] (%#010Lx)\n",
25581+ current->comm, from, to - 1, cursor);
25582 return 0;
25583 }
25584 cursor += PAGE_SIZE;
25585@@ -570,7 +570,7 @@ int kernel_map_sync_memtype(u64 base, unsigned long size, unsigned long flags)
25586 if (ioremap_change_attr((unsigned long)__va(base), id_sz, flags) < 0) {
25587 printk(KERN_INFO "%s:%d ioremap_change_attr failed %s "
25588 "for [mem %#010Lx-%#010Lx]\n",
25589- current->comm, current->pid,
25590+ current->comm, task_pid_nr(current),
25591 cattr_name(flags),
25592 base, (unsigned long long)(base + size-1));
25593 return -EINVAL;
25594@@ -605,7 +605,7 @@ static int reserve_pfn_range(u64 paddr, unsigned long size, pgprot_t *vma_prot,
25595 flags = lookup_memtype(paddr);
25596 if (want_flags != flags) {
25597 printk(KERN_WARNING "%s:%d map pfn RAM range req %s for [mem %#010Lx-%#010Lx], got %s\n",
25598- current->comm, current->pid,
25599+ current->comm, task_pid_nr(current),
25600 cattr_name(want_flags),
25601 (unsigned long long)paddr,
25602 (unsigned long long)(paddr + size - 1),
25603@@ -627,7 +627,7 @@ static int reserve_pfn_range(u64 paddr, unsigned long size, pgprot_t *vma_prot,
25604 free_memtype(paddr, paddr + size);
25605 printk(KERN_ERR "%s:%d map pfn expected mapping type %s"
25606 " for [mem %#010Lx-%#010Lx], got %s\n",
25607- current->comm, current->pid,
25608+ current->comm, task_pid_nr(current),
25609 cattr_name(want_flags),
25610 (unsigned long long)paddr,
25611 (unsigned long long)(paddr + size - 1),
25612diff --git a/arch/x86/mm/pf_in.c b/arch/x86/mm/pf_in.c
25613index 9f0614d..92ae64a 100644
25614--- a/arch/x86/mm/pf_in.c
25615+++ b/arch/x86/mm/pf_in.c
25616@@ -148,7 +148,7 @@ enum reason_type get_ins_type(unsigned long ins_addr)
25617 int i;
25618 enum reason_type rv = OTHERS;
25619
25620- p = (unsigned char *)ins_addr;
25621+ p = (unsigned char *)ktla_ktva(ins_addr);
25622 p += skip_prefix(p, &prf);
25623 p += get_opcode(p, &opcode);
25624
25625@@ -168,7 +168,7 @@ static unsigned int get_ins_reg_width(unsigned long ins_addr)
25626 struct prefix_bits prf;
25627 int i;
25628
25629- p = (unsigned char *)ins_addr;
25630+ p = (unsigned char *)ktla_ktva(ins_addr);
25631 p += skip_prefix(p, &prf);
25632 p += get_opcode(p, &opcode);
25633
25634@@ -191,7 +191,7 @@ unsigned int get_ins_mem_width(unsigned long ins_addr)
25635 struct prefix_bits prf;
25636 int i;
25637
25638- p = (unsigned char *)ins_addr;
25639+ p = (unsigned char *)ktla_ktva(ins_addr);
25640 p += skip_prefix(p, &prf);
25641 p += get_opcode(p, &opcode);
25642
25643@@ -415,7 +415,7 @@ unsigned long get_ins_reg_val(unsigned long ins_addr, struct pt_regs *regs)
25644 struct prefix_bits prf;
25645 int i;
25646
25647- p = (unsigned char *)ins_addr;
25648+ p = (unsigned char *)ktla_ktva(ins_addr);
25649 p += skip_prefix(p, &prf);
25650 p += get_opcode(p, &opcode);
25651 for (i = 0; i < ARRAY_SIZE(reg_rop); i++)
25652@@ -470,7 +470,7 @@ unsigned long get_ins_imm_val(unsigned long ins_addr)
25653 struct prefix_bits prf;
25654 int i;
25655
25656- p = (unsigned char *)ins_addr;
25657+ p = (unsigned char *)ktla_ktva(ins_addr);
25658 p += skip_prefix(p, &prf);
25659 p += get_opcode(p, &opcode);
25660 for (i = 0; i < ARRAY_SIZE(imm_wop); i++)
25661diff --git a/arch/x86/mm/pgtable.c b/arch/x86/mm/pgtable.c
25662index 8573b83..4f3ed7e 100644
25663--- a/arch/x86/mm/pgtable.c
25664+++ b/arch/x86/mm/pgtable.c
25665@@ -84,10 +84,64 @@ static inline void pgd_list_del(pgd_t *pgd)
25666 list_del(&page->lru);
25667 }
25668
25669-#define UNSHARED_PTRS_PER_PGD \
25670- (SHARED_KERNEL_PMD ? KERNEL_PGD_BOUNDARY : PTRS_PER_PGD)
25671+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
25672+pgdval_t clone_pgd_mask __read_only = ~_PAGE_PRESENT;
25673
25674+void __shadow_user_pgds(pgd_t *dst, const pgd_t *src)
25675+{
25676+ unsigned int count = USER_PGD_PTRS;
25677
25678+ while (count--)
25679+ *dst++ = __pgd((pgd_val(*src++) | (_PAGE_NX & __supported_pte_mask)) & ~_PAGE_USER);
25680+}
25681+#endif
25682+
25683+#ifdef CONFIG_PAX_PER_CPU_PGD
25684+void __clone_user_pgds(pgd_t *dst, const pgd_t *src)
25685+{
25686+ unsigned int count = USER_PGD_PTRS;
25687+
25688+ while (count--) {
25689+ pgd_t pgd;
25690+
25691+#ifdef CONFIG_X86_64
25692+ pgd = __pgd(pgd_val(*src++) | _PAGE_USER);
25693+#else
25694+ pgd = *src++;
25695+#endif
25696+
25697+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
25698+ pgd = __pgd(pgd_val(pgd) & clone_pgd_mask);
25699+#endif
25700+
25701+ *dst++ = pgd;
25702+ }
25703+
25704+}
25705+#endif
25706+
25707+#ifdef CONFIG_X86_64
25708+#define pxd_t pud_t
25709+#define pyd_t pgd_t
25710+#define paravirt_release_pxd(pfn) paravirt_release_pud(pfn)
25711+#define pxd_free(mm, pud) pud_free((mm), (pud))
25712+#define pyd_populate(mm, pgd, pud) pgd_populate((mm), (pgd), (pud))
25713+#define pyd_offset(mm, address) pgd_offset((mm), (address))
25714+#define PYD_SIZE PGDIR_SIZE
25715+#else
25716+#define pxd_t pmd_t
25717+#define pyd_t pud_t
25718+#define paravirt_release_pxd(pfn) paravirt_release_pmd(pfn)
25719+#define pxd_free(mm, pud) pmd_free((mm), (pud))
25720+#define pyd_populate(mm, pgd, pud) pud_populate((mm), (pgd), (pud))
25721+#define pyd_offset(mm, address) pud_offset((mm), (address))
25722+#define PYD_SIZE PUD_SIZE
25723+#endif
25724+
25725+#ifdef CONFIG_PAX_PER_CPU_PGD
25726+static inline void pgd_ctor(struct mm_struct *mm, pgd_t *pgd) {}
25727+static inline void pgd_dtor(pgd_t *pgd) {}
25728+#else
25729 static void pgd_set_mm(pgd_t *pgd, struct mm_struct *mm)
25730 {
25731 BUILD_BUG_ON(sizeof(virt_to_page(pgd)->index) < sizeof(mm));
25732@@ -128,6 +182,7 @@ static void pgd_dtor(pgd_t *pgd)
25733 pgd_list_del(pgd);
25734 spin_unlock(&pgd_lock);
25735 }
25736+#endif
25737
25738 /*
25739 * List of all pgd's needed for non-PAE so it can invalidate entries
25740@@ -140,7 +195,7 @@ static void pgd_dtor(pgd_t *pgd)
25741 * -- wli
25742 */
25743
25744-#ifdef CONFIG_X86_PAE
25745+#if defined(CONFIG_X86_32) && defined(CONFIG_X86_PAE)
25746 /*
25747 * In PAE mode, we need to do a cr3 reload (=tlb flush) when
25748 * updating the top-level pagetable entries to guarantee the
25749@@ -152,7 +207,7 @@ static void pgd_dtor(pgd_t *pgd)
25750 * not shared between pagetables (!SHARED_KERNEL_PMDS), we allocate
25751 * and initialize the kernel pmds here.
25752 */
25753-#define PREALLOCATED_PMDS UNSHARED_PTRS_PER_PGD
25754+#define PREALLOCATED_PXDS (SHARED_KERNEL_PMD ? KERNEL_PGD_BOUNDARY : PTRS_PER_PGD)
25755
25756 void pud_populate(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd)
25757 {
25758@@ -170,36 +225,38 @@ void pud_populate(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd)
25759 */
25760 flush_tlb_mm(mm);
25761 }
25762+#elif defined(CONFIG_X86_64) && defined(CONFIG_PAX_PER_CPU_PGD)
25763+#define PREALLOCATED_PXDS USER_PGD_PTRS
25764 #else /* !CONFIG_X86_PAE */
25765
25766 /* No need to prepopulate any pagetable entries in non-PAE modes. */
25767-#define PREALLOCATED_PMDS 0
25768+#define PREALLOCATED_PXDS 0
25769
25770 #endif /* CONFIG_X86_PAE */
25771
25772-static void free_pmds(pmd_t *pmds[])
25773+static void free_pxds(pxd_t *pxds[])
25774 {
25775 int i;
25776
25777- for(i = 0; i < PREALLOCATED_PMDS; i++)
25778- if (pmds[i])
25779- free_page((unsigned long)pmds[i]);
25780+ for(i = 0; i < PREALLOCATED_PXDS; i++)
25781+ if (pxds[i])
25782+ free_page((unsigned long)pxds[i]);
25783 }
25784
25785-static int preallocate_pmds(pmd_t *pmds[])
25786+static int preallocate_pxds(pxd_t *pxds[])
25787 {
25788 int i;
25789 bool failed = false;
25790
25791- for(i = 0; i < PREALLOCATED_PMDS; i++) {
25792- pmd_t *pmd = (pmd_t *)__get_free_page(PGALLOC_GFP);
25793- if (pmd == NULL)
25794+ for(i = 0; i < PREALLOCATED_PXDS; i++) {
25795+ pxd_t *pxd = (pxd_t *)__get_free_page(PGALLOC_GFP);
25796+ if (pxd == NULL)
25797 failed = true;
25798- pmds[i] = pmd;
25799+ pxds[i] = pxd;
25800 }
25801
25802 if (failed) {
25803- free_pmds(pmds);
25804+ free_pxds(pxds);
25805 return -ENOMEM;
25806 }
25807
25808@@ -212,51 +269,55 @@ static int preallocate_pmds(pmd_t *pmds[])
25809 * preallocate which never got a corresponding vma will need to be
25810 * freed manually.
25811 */
25812-static void pgd_mop_up_pmds(struct mm_struct *mm, pgd_t *pgdp)
25813+static void pgd_mop_up_pxds(struct mm_struct *mm, pgd_t *pgdp)
25814 {
25815 int i;
25816
25817- for(i = 0; i < PREALLOCATED_PMDS; i++) {
25818+ for(i = 0; i < PREALLOCATED_PXDS; i++) {
25819 pgd_t pgd = pgdp[i];
25820
25821 if (pgd_val(pgd) != 0) {
25822- pmd_t *pmd = (pmd_t *)pgd_page_vaddr(pgd);
25823+ pxd_t *pxd = (pxd_t *)pgd_page_vaddr(pgd);
25824
25825- pgdp[i] = native_make_pgd(0);
25826+ set_pgd(pgdp + i, native_make_pgd(0));
25827
25828- paravirt_release_pmd(pgd_val(pgd) >> PAGE_SHIFT);
25829- pmd_free(mm, pmd);
25830+ paravirt_release_pxd(pgd_val(pgd) >> PAGE_SHIFT);
25831+ pxd_free(mm, pxd);
25832 }
25833 }
25834 }
25835
25836-static void pgd_prepopulate_pmd(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmds[])
25837+static void pgd_prepopulate_pxd(struct mm_struct *mm, pgd_t *pgd, pxd_t *pxds[])
25838 {
25839- pud_t *pud;
25840+ pyd_t *pyd;
25841 unsigned long addr;
25842 int i;
25843
25844- if (PREALLOCATED_PMDS == 0) /* Work around gcc-3.4.x bug */
25845+ if (PREALLOCATED_PXDS == 0) /* Work around gcc-3.4.x bug */
25846 return;
25847
25848- pud = pud_offset(pgd, 0);
25849+#ifdef CONFIG_X86_64
25850+ pyd = pyd_offset(mm, 0L);
25851+#else
25852+ pyd = pyd_offset(pgd, 0L);
25853+#endif
25854
25855- for (addr = i = 0; i < PREALLOCATED_PMDS;
25856- i++, pud++, addr += PUD_SIZE) {
25857- pmd_t *pmd = pmds[i];
25858+ for (addr = i = 0; i < PREALLOCATED_PXDS;
25859+ i++, pyd++, addr += PYD_SIZE) {
25860+ pxd_t *pxd = pxds[i];
25861
25862 if (i >= KERNEL_PGD_BOUNDARY)
25863- memcpy(pmd, (pmd_t *)pgd_page_vaddr(swapper_pg_dir[i]),
25864- sizeof(pmd_t) * PTRS_PER_PMD);
25865+ memcpy(pxd, (pxd_t *)pgd_page_vaddr(swapper_pg_dir[i]),
25866+ sizeof(pxd_t) * PTRS_PER_PMD);
25867
25868- pud_populate(mm, pud, pmd);
25869+ pyd_populate(mm, pyd, pxd);
25870 }
25871 }
25872
25873 pgd_t *pgd_alloc(struct mm_struct *mm)
25874 {
25875 pgd_t *pgd;
25876- pmd_t *pmds[PREALLOCATED_PMDS];
25877+ pxd_t *pxds[PREALLOCATED_PXDS];
25878
25879 pgd = (pgd_t *)__get_free_page(PGALLOC_GFP);
25880
25881@@ -265,11 +326,11 @@ pgd_t *pgd_alloc(struct mm_struct *mm)
25882
25883 mm->pgd = pgd;
25884
25885- if (preallocate_pmds(pmds) != 0)
25886+ if (preallocate_pxds(pxds) != 0)
25887 goto out_free_pgd;
25888
25889 if (paravirt_pgd_alloc(mm) != 0)
25890- goto out_free_pmds;
25891+ goto out_free_pxds;
25892
25893 /*
25894 * Make sure that pre-populating the pmds is atomic with
25895@@ -279,14 +340,14 @@ pgd_t *pgd_alloc(struct mm_struct *mm)
25896 spin_lock(&pgd_lock);
25897
25898 pgd_ctor(mm, pgd);
25899- pgd_prepopulate_pmd(mm, pgd, pmds);
25900+ pgd_prepopulate_pxd(mm, pgd, pxds);
25901
25902 spin_unlock(&pgd_lock);
25903
25904 return pgd;
25905
25906-out_free_pmds:
25907- free_pmds(pmds);
25908+out_free_pxds:
25909+ free_pxds(pxds);
25910 out_free_pgd:
25911 free_page((unsigned long)pgd);
25912 out:
25913@@ -295,7 +356,7 @@ out:
25914
25915 void pgd_free(struct mm_struct *mm, pgd_t *pgd)
25916 {
25917- pgd_mop_up_pmds(mm, pgd);
25918+ pgd_mop_up_pxds(mm, pgd);
25919 pgd_dtor(pgd);
25920 paravirt_pgd_free(mm, pgd);
25921 free_page((unsigned long)pgd);
25922diff --git a/arch/x86/mm/pgtable_32.c b/arch/x86/mm/pgtable_32.c
25923index a69bcb8..19068ab 100644
25924--- a/arch/x86/mm/pgtable_32.c
25925+++ b/arch/x86/mm/pgtable_32.c
25926@@ -47,10 +47,13 @@ void set_pte_vaddr(unsigned long vaddr, pte_t pteval)
25927 return;
25928 }
25929 pte = pte_offset_kernel(pmd, vaddr);
25930+
25931+ pax_open_kernel();
25932 if (pte_val(pteval))
25933 set_pte_at(&init_mm, vaddr, pte, pteval);
25934 else
25935 pte_clear(&init_mm, vaddr, pte);
25936+ pax_close_kernel();
25937
25938 /*
25939 * It's enough to flush this one mapping.
25940diff --git a/arch/x86/mm/setup_nx.c b/arch/x86/mm/setup_nx.c
25941index 410531d..0f16030 100644
25942--- a/arch/x86/mm/setup_nx.c
25943+++ b/arch/x86/mm/setup_nx.c
25944@@ -5,8 +5,10 @@
25945 #include <asm/pgtable.h>
25946 #include <asm/proto.h>
25947
25948+#if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
25949 static int disable_nx __cpuinitdata;
25950
25951+#ifndef CONFIG_PAX_PAGEEXEC
25952 /*
25953 * noexec = on|off
25954 *
25955@@ -28,12 +30,17 @@ static int __init noexec_setup(char *str)
25956 return 0;
25957 }
25958 early_param("noexec", noexec_setup);
25959+#endif
25960+
25961+#endif
25962
25963 void __cpuinit x86_configure_nx(void)
25964 {
25965+#if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
25966 if (cpu_has_nx && !disable_nx)
25967 __supported_pte_mask |= _PAGE_NX;
25968 else
25969+#endif
25970 __supported_pte_mask &= ~_PAGE_NX;
25971 }
25972
25973diff --git a/arch/x86/mm/tlb.c b/arch/x86/mm/tlb.c
25974index 613cd83..3a21f1c 100644
25975--- a/arch/x86/mm/tlb.c
25976+++ b/arch/x86/mm/tlb.c
25977@@ -48,7 +48,11 @@ void leave_mm(int cpu)
25978 BUG();
25979 if (cpumask_test_cpu(cpu, mm_cpumask(active_mm))) {
25980 cpumask_clear_cpu(cpu, mm_cpumask(active_mm));
25981+
25982+#ifndef CONFIG_PAX_PER_CPU_PGD
25983 load_cr3(swapper_pg_dir);
25984+#endif
25985+
25986 }
25987 }
25988 EXPORT_SYMBOL_GPL(leave_mm);
25989diff --git a/arch/x86/net/bpf_jit.S b/arch/x86/net/bpf_jit.S
25990index 877b9a1..a8ecf42 100644
25991--- a/arch/x86/net/bpf_jit.S
25992+++ b/arch/x86/net/bpf_jit.S
25993@@ -9,6 +9,7 @@
25994 */
25995 #include <linux/linkage.h>
25996 #include <asm/dwarf2.h>
25997+#include <asm/alternative-asm.h>
25998
25999 /*
26000 * Calling convention :
26001@@ -35,6 +36,7 @@ sk_load_word_positive_offset:
26002 jle bpf_slow_path_word
26003 mov (SKBDATA,%rsi),%eax
26004 bswap %eax /* ntohl() */
26005+ pax_force_retaddr
26006 ret
26007
26008 sk_load_half:
26009@@ -52,6 +54,7 @@ sk_load_half_positive_offset:
26010 jle bpf_slow_path_half
26011 movzwl (SKBDATA,%rsi),%eax
26012 rol $8,%ax # ntohs()
26013+ pax_force_retaddr
26014 ret
26015
26016 sk_load_byte:
26017@@ -66,6 +69,7 @@ sk_load_byte_positive_offset:
26018 cmp %esi,%r9d /* if (offset >= hlen) goto bpf_slow_path_byte */
26019 jle bpf_slow_path_byte
26020 movzbl (SKBDATA,%rsi),%eax
26021+ pax_force_retaddr
26022 ret
26023
26024 /**
26025@@ -87,6 +91,7 @@ sk_load_byte_msh_positive_offset:
26026 movzbl (SKBDATA,%rsi),%ebx
26027 and $15,%bl
26028 shl $2,%bl
26029+ pax_force_retaddr
26030 ret
26031
26032 /* rsi contains offset and can be scratched */
26033@@ -109,6 +114,7 @@ bpf_slow_path_word:
26034 js bpf_error
26035 mov -12(%rbp),%eax
26036 bswap %eax
26037+ pax_force_retaddr
26038 ret
26039
26040 bpf_slow_path_half:
26041@@ -117,12 +123,14 @@ bpf_slow_path_half:
26042 mov -12(%rbp),%ax
26043 rol $8,%ax
26044 movzwl %ax,%eax
26045+ pax_force_retaddr
26046 ret
26047
26048 bpf_slow_path_byte:
26049 bpf_slow_path_common(1)
26050 js bpf_error
26051 movzbl -12(%rbp),%eax
26052+ pax_force_retaddr
26053 ret
26054
26055 bpf_slow_path_byte_msh:
26056@@ -133,6 +141,7 @@ bpf_slow_path_byte_msh:
26057 and $15,%al
26058 shl $2,%al
26059 xchg %eax,%ebx
26060+ pax_force_retaddr
26061 ret
26062
26063 #define sk_negative_common(SIZE) \
26064@@ -157,6 +166,7 @@ sk_load_word_negative_offset:
26065 sk_negative_common(4)
26066 mov (%rax), %eax
26067 bswap %eax
26068+ pax_force_retaddr
26069 ret
26070
26071 bpf_slow_path_half_neg:
26072@@ -168,6 +178,7 @@ sk_load_half_negative_offset:
26073 mov (%rax),%ax
26074 rol $8,%ax
26075 movzwl %ax,%eax
26076+ pax_force_retaddr
26077 ret
26078
26079 bpf_slow_path_byte_neg:
26080@@ -177,6 +188,7 @@ sk_load_byte_negative_offset:
26081 .globl sk_load_byte_negative_offset
26082 sk_negative_common(1)
26083 movzbl (%rax), %eax
26084+ pax_force_retaddr
26085 ret
26086
26087 bpf_slow_path_byte_msh_neg:
26088@@ -190,6 +202,7 @@ sk_load_byte_msh_negative_offset:
26089 and $15,%al
26090 shl $2,%al
26091 xchg %eax,%ebx
26092+ pax_force_retaddr
26093 ret
26094
26095 bpf_error:
26096@@ -197,4 +210,5 @@ bpf_error:
26097 xor %eax,%eax
26098 mov -8(%rbp),%rbx
26099 leaveq
26100+ pax_force_retaddr
26101 ret
26102diff --git a/arch/x86/net/bpf_jit_comp.c b/arch/x86/net/bpf_jit_comp.c
26103index 33643a8..f6211a0 100644
26104--- a/arch/x86/net/bpf_jit_comp.c
26105+++ b/arch/x86/net/bpf_jit_comp.c
26106@@ -11,6 +11,7 @@
26107 #include <asm/cacheflush.h>
26108 #include <linux/netdevice.h>
26109 #include <linux/filter.h>
26110+#include <linux/random.h>
26111
26112 /*
26113 * Conventions :
26114@@ -48,13 +49,87 @@ static inline u8 *emit_code(u8 *ptr, u32 bytes, unsigned int len)
26115 return ptr + len;
26116 }
26117
26118+#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
26119+#define MAX_INSTR_CODE_SIZE 96
26120+#else
26121+#define MAX_INSTR_CODE_SIZE 64
26122+#endif
26123+
26124 #define EMIT(bytes, len) do { prog = emit_code(prog, bytes, len); } while (0)
26125
26126 #define EMIT1(b1) EMIT(b1, 1)
26127 #define EMIT2(b1, b2) EMIT((b1) + ((b2) << 8), 2)
26128 #define EMIT3(b1, b2, b3) EMIT((b1) + ((b2) << 8) + ((b3) << 16), 3)
26129 #define EMIT4(b1, b2, b3, b4) EMIT((b1) + ((b2) << 8) + ((b3) << 16) + ((b4) << 24), 4)
26130+
26131+#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
26132+/* original constant will appear in ecx */
26133+#define DILUTE_CONST_SEQUENCE(_off, _key) \
26134+do { \
26135+ /* mov ecx, randkey */ \
26136+ EMIT1(0xb9); \
26137+ EMIT(_key, 4); \
26138+ /* xor ecx, randkey ^ off */ \
26139+ EMIT2(0x81, 0xf1); \
26140+ EMIT((_key) ^ (_off), 4); \
26141+} while (0)
26142+
26143+#define EMIT1_off32(b1, _off) \
26144+do { \
26145+ switch (b1) { \
26146+ case 0x05: /* add eax, imm32 */ \
26147+ case 0x2d: /* sub eax, imm32 */ \
26148+ case 0x25: /* and eax, imm32 */ \
26149+ case 0x0d: /* or eax, imm32 */ \
26150+ case 0xb8: /* mov eax, imm32 */ \
26151+ case 0x3d: /* cmp eax, imm32 */ \
26152+ case 0xa9: /* test eax, imm32 */ \
26153+ DILUTE_CONST_SEQUENCE(_off, randkey); \
26154+ EMIT2((b1) - 4, 0xc8); /* convert imm instruction to eax, ecx */\
26155+ break; \
26156+ case 0xbb: /* mov ebx, imm32 */ \
26157+ DILUTE_CONST_SEQUENCE(_off, randkey); \
26158+ /* mov ebx, ecx */ \
26159+ EMIT2(0x89, 0xcb); \
26160+ break; \
26161+ case 0xbe: /* mov esi, imm32 */ \
26162+ DILUTE_CONST_SEQUENCE(_off, randkey); \
26163+ /* mov esi, ecx */ \
26164+ EMIT2(0x89, 0xce); \
26165+ break; \
26166+ case 0xe9: /* jmp rel imm32 */ \
26167+ EMIT1(b1); \
26168+ EMIT(_off, 4); \
26169+ /* prevent fall-through, we're not called if off = 0 */ \
26170+ EMIT(0xcccccccc, 4); \
26171+ EMIT(0xcccccccc, 4); \
26172+ break; \
26173+ default: \
26174+ EMIT1(b1); \
26175+ EMIT(_off, 4); \
26176+ } \
26177+} while (0)
26178+
26179+#define EMIT2_off32(b1, b2, _off) \
26180+do { \
26181+ if ((b1) == 0x8d && (b2) == 0xb3) { /* lea esi, [rbx+imm32] */ \
26182+ EMIT2(0x8d, 0xb3); /* lea esi, [rbx+randkey] */ \
26183+ EMIT(randkey, 4); \
26184+ EMIT2(0x8d, 0xb6); /* lea esi, [esi+off-randkey] */ \
26185+ EMIT((_off) - randkey, 4); \
26186+ } else if ((b1) == 0x69 && (b2) == 0xc0) { /* imul eax, imm32 */\
26187+ DILUTE_CONST_SEQUENCE(_off, randkey); \
26188+ /* imul eax, ecx */ \
26189+ EMIT3(0x0f, 0xaf, 0xc1); \
26190+ } else { \
26191+ EMIT2(b1, b2); \
26192+ EMIT(_off, 4); \
26193+ } \
26194+} while (0)
26195+#else
26196 #define EMIT1_off32(b1, off) do { EMIT1(b1); EMIT(off, 4);} while (0)
26197+#define EMIT2_off32(b1, b2, off) do { EMIT2(b1, b2); EMIT(off, 4);} while (0)
26198+#endif
26199
26200 #define CLEAR_A() EMIT2(0x31, 0xc0) /* xor %eax,%eax */
26201 #define CLEAR_X() EMIT2(0x31, 0xdb) /* xor %ebx,%ebx */
26202@@ -89,6 +164,24 @@ do { \
26203 #define X86_JBE 0x76
26204 #define X86_JA 0x77
26205
26206+#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
26207+#define APPEND_FLOW_VERIFY() \
26208+do { \
26209+ /* mov ecx, randkey */ \
26210+ EMIT1(0xb9); \
26211+ EMIT(randkey, 4); \
26212+ /* cmp ecx, randkey */ \
26213+ EMIT2(0x81, 0xf9); \
26214+ EMIT(randkey, 4); \
26215+ /* jz after 8 int 3s */ \
26216+ EMIT2(0x74, 0x08); \
26217+ EMIT(0xcccccccc, 4); \
26218+ EMIT(0xcccccccc, 4); \
26219+} while (0)
26220+#else
26221+#define APPEND_FLOW_VERIFY() do { } while (0)
26222+#endif
26223+
26224 #define EMIT_COND_JMP(op, offset) \
26225 do { \
26226 if (is_near(offset)) \
26227@@ -96,6 +189,7 @@ do { \
26228 else { \
26229 EMIT2(0x0f, op + 0x10); \
26230 EMIT(offset, 4); /* jxx .+off32 */ \
26231+ APPEND_FLOW_VERIFY(); \
26232 } \
26233 } while (0)
26234
26235@@ -120,12 +214,17 @@ static inline void bpf_flush_icache(void *start, void *end)
26236 set_fs(old_fs);
26237 }
26238
26239+struct bpf_jit_work {
26240+ struct work_struct work;
26241+ void *image;
26242+};
26243+
26244 #define CHOOSE_LOAD_FUNC(K, func) \
26245 ((int)K < 0 ? ((int)K >= SKF_LL_OFF ? func##_negative_offset : func) : func##_positive_offset)
26246
26247 void bpf_jit_compile(struct sk_filter *fp)
26248 {
26249- u8 temp[64];
26250+ u8 temp[MAX_INSTR_CODE_SIZE];
26251 u8 *prog;
26252 unsigned int proglen, oldproglen = 0;
26253 int ilen, i;
26254@@ -138,6 +237,9 @@ void bpf_jit_compile(struct sk_filter *fp)
26255 unsigned int *addrs;
26256 const struct sock_filter *filter = fp->insns;
26257 int flen = fp->len;
26258+#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
26259+ unsigned int randkey;
26260+#endif
26261
26262 if (!bpf_jit_enable)
26263 return;
26264@@ -146,11 +248,19 @@ void bpf_jit_compile(struct sk_filter *fp)
26265 if (addrs == NULL)
26266 return;
26267
26268+ fp->work = kmalloc(sizeof(*fp->work), GFP_KERNEL);
26269+ if (!fp->work)
26270+ goto out;
26271+
26272+#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
26273+ randkey = get_random_int();
26274+#endif
26275+
26276 /* Before first pass, make a rough estimation of addrs[]
26277- * each bpf instruction is translated to less than 64 bytes
26278+ * each bpf instruction is translated to less than MAX_INSTR_CODE_SIZE bytes
26279 */
26280 for (proglen = 0, i = 0; i < flen; i++) {
26281- proglen += 64;
26282+ proglen += MAX_INSTR_CODE_SIZE;
26283 addrs[i] = proglen;
26284 }
26285 cleanup_addr = proglen; /* epilogue address */
26286@@ -258,10 +368,8 @@ void bpf_jit_compile(struct sk_filter *fp)
26287 case BPF_S_ALU_MUL_K: /* A *= K */
26288 if (is_imm8(K))
26289 EMIT3(0x6b, 0xc0, K); /* imul imm8,%eax,%eax */
26290- else {
26291- EMIT2(0x69, 0xc0); /* imul imm32,%eax */
26292- EMIT(K, 4);
26293- }
26294+ else
26295+ EMIT2_off32(0x69, 0xc0, K); /* imul imm32,%eax */
26296 break;
26297 case BPF_S_ALU_DIV_X: /* A /= X; */
26298 seen |= SEEN_XREG;
26299@@ -281,8 +389,14 @@ void bpf_jit_compile(struct sk_filter *fp)
26300 EMIT4(0x31, 0xd2, 0xf7, 0xf3); /* xor %edx,%edx; div %ebx */
26301 break;
26302 case BPF_S_ALU_DIV_K: /* A = reciprocal_divide(A, K); */
26303+#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
26304+ DILUTE_CONST_SEQUENCE(K, randkey);
26305+ // imul rax, rcx
26306+ EMIT4(0x48, 0x0f, 0xaf, 0xc1);
26307+#else
26308 EMIT3(0x48, 0x69, 0xc0); /* imul imm32,%rax,%rax */
26309 EMIT(K, 4);
26310+#endif
26311 EMIT4(0x48, 0xc1, 0xe8, 0x20); /* shr $0x20,%rax */
26312 break;
26313 case BPF_S_ALU_AND_X:
26314@@ -509,8 +623,7 @@ common_load_ind: seen |= SEEN_DATAREF | SEEN_XREG;
26315 if (is_imm8(K)) {
26316 EMIT3(0x8d, 0x73, K); /* lea imm8(%rbx), %esi */
26317 } else {
26318- EMIT2(0x8d, 0xb3); /* lea imm32(%rbx),%esi */
26319- EMIT(K, 4);
26320+ EMIT2_off32(0x8d, 0xb3, K); /* lea imm32(%rbx),%esi */
26321 }
26322 } else {
26323 EMIT2(0x89,0xde); /* mov %ebx,%esi */
26324@@ -593,17 +706,18 @@ cond_branch: f_offset = addrs[i + filter[i].jf] - addrs[i];
26325 break;
26326 default:
26327 /* hmm, too complex filter, give up with jit compiler */
26328- goto out;
26329+ goto error;
26330 }
26331 ilen = prog - temp;
26332 if (image) {
26333 if (unlikely(proglen + ilen > oldproglen)) {
26334 pr_err("bpb_jit_compile fatal error\n");
26335- kfree(addrs);
26336- module_free(NULL, image);
26337- return;
26338+ module_free_exec(NULL, image);
26339+ goto error;
26340 }
26341+ pax_open_kernel();
26342 memcpy(image + proglen, temp, ilen);
26343+ pax_close_kernel();
26344 }
26345 proglen += ilen;
26346 addrs[i] = proglen;
26347@@ -624,11 +738,9 @@ cond_branch: f_offset = addrs[i + filter[i].jf] - addrs[i];
26348 break;
26349 }
26350 if (proglen == oldproglen) {
26351- image = module_alloc(max_t(unsigned int,
26352- proglen,
26353- sizeof(struct work_struct)));
26354+ image = module_alloc_exec(proglen);
26355 if (!image)
26356- goto out;
26357+ goto error;
26358 }
26359 oldproglen = proglen;
26360 }
26361@@ -644,7 +756,10 @@ cond_branch: f_offset = addrs[i + filter[i].jf] - addrs[i];
26362 bpf_flush_icache(image, image + proglen);
26363
26364 fp->bpf_func = (void *)image;
26365- }
26366+ } else
26367+error:
26368+ kfree(fp->work);
26369+
26370 out:
26371 kfree(addrs);
26372 return;
26373@@ -652,18 +767,20 @@ out:
26374
26375 static void jit_free_defer(struct work_struct *arg)
26376 {
26377- module_free(NULL, arg);
26378+ module_free_exec(NULL, ((struct bpf_jit_work *)arg)->image);
26379+ kfree(arg);
26380 }
26381
26382 /* run from softirq, we must use a work_struct to call
26383- * module_free() from process context
26384+ * module_free_exec() from process context
26385 */
26386 void bpf_jit_free(struct sk_filter *fp)
26387 {
26388 if (fp->bpf_func != sk_run_filter) {
26389- struct work_struct *work = (struct work_struct *)fp->bpf_func;
26390+ struct work_struct *work = &fp->work->work;
26391
26392 INIT_WORK(work, jit_free_defer);
26393+ fp->work->image = fp->bpf_func;
26394 schedule_work(work);
26395 }
26396 }
26397diff --git a/arch/x86/oprofile/backtrace.c b/arch/x86/oprofile/backtrace.c
26398index d6aa6e8..266395a 100644
26399--- a/arch/x86/oprofile/backtrace.c
26400+++ b/arch/x86/oprofile/backtrace.c
26401@@ -46,11 +46,11 @@ dump_user_backtrace_32(struct stack_frame_ia32 *head)
26402 struct stack_frame_ia32 *fp;
26403 unsigned long bytes;
26404
26405- bytes = copy_from_user_nmi(bufhead, head, sizeof(bufhead));
26406+ bytes = copy_from_user_nmi(bufhead, (const char __force_user *)head, sizeof(bufhead));
26407 if (bytes != sizeof(bufhead))
26408 return NULL;
26409
26410- fp = (struct stack_frame_ia32 *) compat_ptr(bufhead[0].next_frame);
26411+ fp = (struct stack_frame_ia32 __force_kernel *) compat_ptr(bufhead[0].next_frame);
26412
26413 oprofile_add_trace(bufhead[0].return_address);
26414
26415@@ -92,7 +92,7 @@ static struct stack_frame *dump_user_backtrace(struct stack_frame *head)
26416 struct stack_frame bufhead[2];
26417 unsigned long bytes;
26418
26419- bytes = copy_from_user_nmi(bufhead, head, sizeof(bufhead));
26420+ bytes = copy_from_user_nmi(bufhead, (const char __force_user *)head, sizeof(bufhead));
26421 if (bytes != sizeof(bufhead))
26422 return NULL;
26423
26424@@ -111,7 +111,7 @@ x86_backtrace(struct pt_regs * const regs, unsigned int depth)
26425 {
26426 struct stack_frame *head = (struct stack_frame *)frame_pointer(regs);
26427
26428- if (!user_mode_vm(regs)) {
26429+ if (!user_mode(regs)) {
26430 unsigned long stack = kernel_stack_pointer(regs);
26431 if (depth)
26432 dump_trace(NULL, regs, (unsigned long *)stack, 0,
26433diff --git a/arch/x86/pci/mrst.c b/arch/x86/pci/mrst.c
26434index e14a2ff..3fd6b58 100644
26435--- a/arch/x86/pci/mrst.c
26436+++ b/arch/x86/pci/mrst.c
26437@@ -238,7 +238,9 @@ int __init pci_mrst_init(void)
26438 printk(KERN_INFO "Intel MID platform detected, using MID PCI ops\n");
26439 pci_mmcfg_late_init();
26440 pcibios_enable_irq = mrst_pci_irq_enable;
26441- pci_root_ops = pci_mrst_ops;
26442+ pax_open_kernel();
26443+ memcpy((void *)&pci_root_ops, &pci_mrst_ops, sizeof(pci_mrst_ops));
26444+ pax_close_kernel();
26445 pci_soc_mode = 1;
26446 /* Continue with standard init */
26447 return 1;
26448diff --git a/arch/x86/pci/pcbios.c b/arch/x86/pci/pcbios.c
26449index da8fe05..7ee6704 100644
26450--- a/arch/x86/pci/pcbios.c
26451+++ b/arch/x86/pci/pcbios.c
26452@@ -79,50 +79,93 @@ union bios32 {
26453 static struct {
26454 unsigned long address;
26455 unsigned short segment;
26456-} bios32_indirect = { 0, __KERNEL_CS };
26457+} bios32_indirect __read_only = { 0, __PCIBIOS_CS };
26458
26459 /*
26460 * Returns the entry point for the given service, NULL on error
26461 */
26462
26463-static unsigned long bios32_service(unsigned long service)
26464+static unsigned long __devinit bios32_service(unsigned long service)
26465 {
26466 unsigned char return_code; /* %al */
26467 unsigned long address; /* %ebx */
26468 unsigned long length; /* %ecx */
26469 unsigned long entry; /* %edx */
26470 unsigned long flags;
26471+ struct desc_struct d, *gdt;
26472
26473 local_irq_save(flags);
26474- __asm__("lcall *(%%edi); cld"
26475+
26476+ gdt = get_cpu_gdt_table(smp_processor_id());
26477+
26478+ pack_descriptor(&d, 0UL, 0xFFFFFUL, 0x9B, 0xC);
26479+ write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_CS, &d, DESCTYPE_S);
26480+ pack_descriptor(&d, 0UL, 0xFFFFFUL, 0x93, 0xC);
26481+ write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_DS, &d, DESCTYPE_S);
26482+
26483+ __asm__("movw %w7, %%ds; lcall *(%%edi); push %%ss; pop %%ds; cld"
26484 : "=a" (return_code),
26485 "=b" (address),
26486 "=c" (length),
26487 "=d" (entry)
26488 : "0" (service),
26489 "1" (0),
26490- "D" (&bios32_indirect));
26491+ "D" (&bios32_indirect),
26492+ "r"(__PCIBIOS_DS)
26493+ : "memory");
26494+
26495+ pax_open_kernel();
26496+ gdt[GDT_ENTRY_PCIBIOS_CS].a = 0;
26497+ gdt[GDT_ENTRY_PCIBIOS_CS].b = 0;
26498+ gdt[GDT_ENTRY_PCIBIOS_DS].a = 0;
26499+ gdt[GDT_ENTRY_PCIBIOS_DS].b = 0;
26500+ pax_close_kernel();
26501+
26502 local_irq_restore(flags);
26503
26504 switch (return_code) {
26505- case 0:
26506- return address + entry;
26507- case 0x80: /* Not present */
26508- printk(KERN_WARNING "bios32_service(0x%lx): not present\n", service);
26509- return 0;
26510- default: /* Shouldn't happen */
26511- printk(KERN_WARNING "bios32_service(0x%lx): returned 0x%x -- BIOS bug!\n",
26512- service, return_code);
26513+ case 0: {
26514+ int cpu;
26515+ unsigned char flags;
26516+
26517+ printk(KERN_INFO "bios32_service: base:%08lx length:%08lx entry:%08lx\n", address, length, entry);
26518+ if (address >= 0xFFFF0 || length > 0x100000 - address || length <= entry) {
26519+ printk(KERN_WARNING "bios32_service: not valid\n");
26520 return 0;
26521+ }
26522+ address = address + PAGE_OFFSET;
26523+ length += 16UL; /* some BIOSs underreport this... */
26524+ flags = 4;
26525+ if (length >= 64*1024*1024) {
26526+ length >>= PAGE_SHIFT;
26527+ flags |= 8;
26528+ }
26529+
26530+ for (cpu = 0; cpu < nr_cpu_ids; cpu++) {
26531+ gdt = get_cpu_gdt_table(cpu);
26532+ pack_descriptor(&d, address, length, 0x9b, flags);
26533+ write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_CS, &d, DESCTYPE_S);
26534+ pack_descriptor(&d, address, length, 0x93, flags);
26535+ write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_DS, &d, DESCTYPE_S);
26536+ }
26537+ return entry;
26538+ }
26539+ case 0x80: /* Not present */
26540+ printk(KERN_WARNING "bios32_service(0x%lx): not present\n", service);
26541+ return 0;
26542+ default: /* Shouldn't happen */
26543+ printk(KERN_WARNING "bios32_service(0x%lx): returned 0x%x -- BIOS bug!\n",
26544+ service, return_code);
26545+ return 0;
26546 }
26547 }
26548
26549 static struct {
26550 unsigned long address;
26551 unsigned short segment;
26552-} pci_indirect = { 0, __KERNEL_CS };
26553+} pci_indirect __read_only = { 0, __PCIBIOS_CS };
26554
26555-static int pci_bios_present;
26556+static int pci_bios_present __read_only;
26557
26558 static int __devinit check_pcibios(void)
26559 {
26560@@ -131,11 +174,13 @@ static int __devinit check_pcibios(void)
26561 unsigned long flags, pcibios_entry;
26562
26563 if ((pcibios_entry = bios32_service(PCI_SERVICE))) {
26564- pci_indirect.address = pcibios_entry + PAGE_OFFSET;
26565+ pci_indirect.address = pcibios_entry;
26566
26567 local_irq_save(flags);
26568- __asm__(
26569- "lcall *(%%edi); cld\n\t"
26570+ __asm__("movw %w6, %%ds\n\t"
26571+ "lcall *%%ss:(%%edi); cld\n\t"
26572+ "push %%ss\n\t"
26573+ "pop %%ds\n\t"
26574 "jc 1f\n\t"
26575 "xor %%ah, %%ah\n"
26576 "1:"
26577@@ -144,7 +189,8 @@ static int __devinit check_pcibios(void)
26578 "=b" (ebx),
26579 "=c" (ecx)
26580 : "1" (PCIBIOS_PCI_BIOS_PRESENT),
26581- "D" (&pci_indirect)
26582+ "D" (&pci_indirect),
26583+ "r" (__PCIBIOS_DS)
26584 : "memory");
26585 local_irq_restore(flags);
26586
26587@@ -189,7 +235,10 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
26588
26589 switch (len) {
26590 case 1:
26591- __asm__("lcall *(%%esi); cld\n\t"
26592+ __asm__("movw %w6, %%ds\n\t"
26593+ "lcall *%%ss:(%%esi); cld\n\t"
26594+ "push %%ss\n\t"
26595+ "pop %%ds\n\t"
26596 "jc 1f\n\t"
26597 "xor %%ah, %%ah\n"
26598 "1:"
26599@@ -198,7 +247,8 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
26600 : "1" (PCIBIOS_READ_CONFIG_BYTE),
26601 "b" (bx),
26602 "D" ((long)reg),
26603- "S" (&pci_indirect));
26604+ "S" (&pci_indirect),
26605+ "r" (__PCIBIOS_DS));
26606 /*
26607 * Zero-extend the result beyond 8 bits, do not trust the
26608 * BIOS having done it:
26609@@ -206,7 +256,10 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
26610 *value &= 0xff;
26611 break;
26612 case 2:
26613- __asm__("lcall *(%%esi); cld\n\t"
26614+ __asm__("movw %w6, %%ds\n\t"
26615+ "lcall *%%ss:(%%esi); cld\n\t"
26616+ "push %%ss\n\t"
26617+ "pop %%ds\n\t"
26618 "jc 1f\n\t"
26619 "xor %%ah, %%ah\n"
26620 "1:"
26621@@ -215,7 +268,8 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
26622 : "1" (PCIBIOS_READ_CONFIG_WORD),
26623 "b" (bx),
26624 "D" ((long)reg),
26625- "S" (&pci_indirect));
26626+ "S" (&pci_indirect),
26627+ "r" (__PCIBIOS_DS));
26628 /*
26629 * Zero-extend the result beyond 16 bits, do not trust the
26630 * BIOS having done it:
26631@@ -223,7 +277,10 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
26632 *value &= 0xffff;
26633 break;
26634 case 4:
26635- __asm__("lcall *(%%esi); cld\n\t"
26636+ __asm__("movw %w6, %%ds\n\t"
26637+ "lcall *%%ss:(%%esi); cld\n\t"
26638+ "push %%ss\n\t"
26639+ "pop %%ds\n\t"
26640 "jc 1f\n\t"
26641 "xor %%ah, %%ah\n"
26642 "1:"
26643@@ -232,7 +289,8 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
26644 : "1" (PCIBIOS_READ_CONFIG_DWORD),
26645 "b" (bx),
26646 "D" ((long)reg),
26647- "S" (&pci_indirect));
26648+ "S" (&pci_indirect),
26649+ "r" (__PCIBIOS_DS));
26650 break;
26651 }
26652
26653@@ -256,7 +314,10 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
26654
26655 switch (len) {
26656 case 1:
26657- __asm__("lcall *(%%esi); cld\n\t"
26658+ __asm__("movw %w6, %%ds\n\t"
26659+ "lcall *%%ss:(%%esi); cld\n\t"
26660+ "push %%ss\n\t"
26661+ "pop %%ds\n\t"
26662 "jc 1f\n\t"
26663 "xor %%ah, %%ah\n"
26664 "1:"
26665@@ -265,10 +326,14 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
26666 "c" (value),
26667 "b" (bx),
26668 "D" ((long)reg),
26669- "S" (&pci_indirect));
26670+ "S" (&pci_indirect),
26671+ "r" (__PCIBIOS_DS));
26672 break;
26673 case 2:
26674- __asm__("lcall *(%%esi); cld\n\t"
26675+ __asm__("movw %w6, %%ds\n\t"
26676+ "lcall *%%ss:(%%esi); cld\n\t"
26677+ "push %%ss\n\t"
26678+ "pop %%ds\n\t"
26679 "jc 1f\n\t"
26680 "xor %%ah, %%ah\n"
26681 "1:"
26682@@ -277,10 +342,14 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
26683 "c" (value),
26684 "b" (bx),
26685 "D" ((long)reg),
26686- "S" (&pci_indirect));
26687+ "S" (&pci_indirect),
26688+ "r" (__PCIBIOS_DS));
26689 break;
26690 case 4:
26691- __asm__("lcall *(%%esi); cld\n\t"
26692+ __asm__("movw %w6, %%ds\n\t"
26693+ "lcall *%%ss:(%%esi); cld\n\t"
26694+ "push %%ss\n\t"
26695+ "pop %%ds\n\t"
26696 "jc 1f\n\t"
26697 "xor %%ah, %%ah\n"
26698 "1:"
26699@@ -289,7 +358,8 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
26700 "c" (value),
26701 "b" (bx),
26702 "D" ((long)reg),
26703- "S" (&pci_indirect));
26704+ "S" (&pci_indirect),
26705+ "r" (__PCIBIOS_DS));
26706 break;
26707 }
26708
26709@@ -394,10 +464,13 @@ struct irq_routing_table * pcibios_get_irq_routing_table(void)
26710
26711 DBG("PCI: Fetching IRQ routing table... ");
26712 __asm__("push %%es\n\t"
26713+ "movw %w8, %%ds\n\t"
26714 "push %%ds\n\t"
26715 "pop %%es\n\t"
26716- "lcall *(%%esi); cld\n\t"
26717+ "lcall *%%ss:(%%esi); cld\n\t"
26718 "pop %%es\n\t"
26719+ "push %%ss\n\t"
26720+ "pop %%ds\n"
26721 "jc 1f\n\t"
26722 "xor %%ah, %%ah\n"
26723 "1:"
26724@@ -408,7 +481,8 @@ struct irq_routing_table * pcibios_get_irq_routing_table(void)
26725 "1" (0),
26726 "D" ((long) &opt),
26727 "S" (&pci_indirect),
26728- "m" (opt)
26729+ "m" (opt),
26730+ "r" (__PCIBIOS_DS)
26731 : "memory");
26732 DBG("OK ret=%d, size=%d, map=%x\n", ret, opt.size, map);
26733 if (ret & 0xff00)
26734@@ -432,7 +506,10 @@ int pcibios_set_irq_routing(struct pci_dev *dev, int pin, int irq)
26735 {
26736 int ret;
26737
26738- __asm__("lcall *(%%esi); cld\n\t"
26739+ __asm__("movw %w5, %%ds\n\t"
26740+ "lcall *%%ss:(%%esi); cld\n\t"
26741+ "push %%ss\n\t"
26742+ "pop %%ds\n"
26743 "jc 1f\n\t"
26744 "xor %%ah, %%ah\n"
26745 "1:"
26746@@ -440,7 +517,8 @@ int pcibios_set_irq_routing(struct pci_dev *dev, int pin, int irq)
26747 : "0" (PCIBIOS_SET_PCI_HW_INT),
26748 "b" ((dev->bus->number << 8) | dev->devfn),
26749 "c" ((irq << 8) | (pin + 10)),
26750- "S" (&pci_indirect));
26751+ "S" (&pci_indirect),
26752+ "r" (__PCIBIOS_DS));
26753 return !(ret & 0xff00);
26754 }
26755 EXPORT_SYMBOL(pcibios_set_irq_routing);
26756diff --git a/arch/x86/platform/efi/efi_32.c b/arch/x86/platform/efi/efi_32.c
26757index 40e4469..1ab536e 100644
26758--- a/arch/x86/platform/efi/efi_32.c
26759+++ b/arch/x86/platform/efi/efi_32.c
26760@@ -44,11 +44,22 @@ void efi_call_phys_prelog(void)
26761 {
26762 struct desc_ptr gdt_descr;
26763
26764+#ifdef CONFIG_PAX_KERNEXEC
26765+ struct desc_struct d;
26766+#endif
26767+
26768 local_irq_save(efi_rt_eflags);
26769
26770 load_cr3(initial_page_table);
26771 __flush_tlb_all();
26772
26773+#ifdef CONFIG_PAX_KERNEXEC
26774+ pack_descriptor(&d, 0, 0xFFFFF, 0x9B, 0xC);
26775+ write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_CS, &d, DESCTYPE_S);
26776+ pack_descriptor(&d, 0, 0xFFFFF, 0x93, 0xC);
26777+ write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_DS, &d, DESCTYPE_S);
26778+#endif
26779+
26780 gdt_descr.address = __pa(get_cpu_gdt_table(0));
26781 gdt_descr.size = GDT_SIZE - 1;
26782 load_gdt(&gdt_descr);
26783@@ -58,6 +69,14 @@ void efi_call_phys_epilog(void)
26784 {
26785 struct desc_ptr gdt_descr;
26786
26787+#ifdef CONFIG_PAX_KERNEXEC
26788+ struct desc_struct d;
26789+
26790+ memset(&d, 0, sizeof d);
26791+ write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_CS, &d, DESCTYPE_S);
26792+ write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_DS, &d, DESCTYPE_S);
26793+#endif
26794+
26795 gdt_descr.address = (unsigned long)get_cpu_gdt_table(0);
26796 gdt_descr.size = GDT_SIZE - 1;
26797 load_gdt(&gdt_descr);
26798diff --git a/arch/x86/platform/efi/efi_stub_32.S b/arch/x86/platform/efi/efi_stub_32.S
26799index fbe66e6..eae5e38 100644
26800--- a/arch/x86/platform/efi/efi_stub_32.S
26801+++ b/arch/x86/platform/efi/efi_stub_32.S
26802@@ -6,7 +6,9 @@
26803 */
26804
26805 #include <linux/linkage.h>
26806+#include <linux/init.h>
26807 #include <asm/page_types.h>
26808+#include <asm/segment.h>
26809
26810 /*
26811 * efi_call_phys(void *, ...) is a function with variable parameters.
26812@@ -20,7 +22,7 @@
26813 * service functions will comply with gcc calling convention, too.
26814 */
26815
26816-.text
26817+__INIT
26818 ENTRY(efi_call_phys)
26819 /*
26820 * 0. The function can only be called in Linux kernel. So CS has been
26821@@ -36,10 +38,24 @@ ENTRY(efi_call_phys)
26822 * The mapping of lower virtual memory has been created in prelog and
26823 * epilog.
26824 */
26825- movl $1f, %edx
26826- subl $__PAGE_OFFSET, %edx
26827- jmp *%edx
26828+#ifdef CONFIG_PAX_KERNEXEC
26829+ movl $(__KERNEXEC_EFI_DS), %edx
26830+ mov %edx, %ds
26831+ mov %edx, %es
26832+ mov %edx, %ss
26833+ addl $2f,(1f)
26834+ ljmp *(1f)
26835+
26836+__INITDATA
26837+1: .long __LOAD_PHYSICAL_ADDR, __KERNEXEC_EFI_CS
26838+.previous
26839+
26840+2:
26841+ subl $2b,(1b)
26842+#else
26843+ jmp 1f-__PAGE_OFFSET
26844 1:
26845+#endif
26846
26847 /*
26848 * 2. Now on the top of stack is the return
26849@@ -47,14 +63,8 @@ ENTRY(efi_call_phys)
26850 * parameter 2, ..., param n. To make things easy, we save the return
26851 * address of efi_call_phys in a global variable.
26852 */
26853- popl %edx
26854- movl %edx, saved_return_addr
26855- /* get the function pointer into ECX*/
26856- popl %ecx
26857- movl %ecx, efi_rt_function_ptr
26858- movl $2f, %edx
26859- subl $__PAGE_OFFSET, %edx
26860- pushl %edx
26861+ popl (saved_return_addr)
26862+ popl (efi_rt_function_ptr)
26863
26864 /*
26865 * 3. Clear PG bit in %CR0.
26866@@ -73,9 +83,8 @@ ENTRY(efi_call_phys)
26867 /*
26868 * 5. Call the physical function.
26869 */
26870- jmp *%ecx
26871+ call *(efi_rt_function_ptr-__PAGE_OFFSET)
26872
26873-2:
26874 /*
26875 * 6. After EFI runtime service returns, control will return to
26876 * following instruction. We'd better readjust stack pointer first.
26877@@ -88,35 +97,36 @@ ENTRY(efi_call_phys)
26878 movl %cr0, %edx
26879 orl $0x80000000, %edx
26880 movl %edx, %cr0
26881- jmp 1f
26882-1:
26883+
26884 /*
26885 * 8. Now restore the virtual mode from flat mode by
26886 * adding EIP with PAGE_OFFSET.
26887 */
26888- movl $1f, %edx
26889- jmp *%edx
26890+#ifdef CONFIG_PAX_KERNEXEC
26891+ movl $(__KERNEL_DS), %edx
26892+ mov %edx, %ds
26893+ mov %edx, %es
26894+ mov %edx, %ss
26895+ ljmp $(__KERNEL_CS),$1f
26896+#else
26897+ jmp 1f+__PAGE_OFFSET
26898+#endif
26899 1:
26900
26901 /*
26902 * 9. Balance the stack. And because EAX contain the return value,
26903 * we'd better not clobber it.
26904 */
26905- leal efi_rt_function_ptr, %edx
26906- movl (%edx), %ecx
26907- pushl %ecx
26908+ pushl (efi_rt_function_ptr)
26909
26910 /*
26911- * 10. Push the saved return address onto the stack and return.
26912+ * 10. Return to the saved return address.
26913 */
26914- leal saved_return_addr, %edx
26915- movl (%edx), %ecx
26916- pushl %ecx
26917- ret
26918+ jmpl *(saved_return_addr)
26919 ENDPROC(efi_call_phys)
26920 .previous
26921
26922-.data
26923+__INITDATA
26924 saved_return_addr:
26925 .long 0
26926 efi_rt_function_ptr:
26927diff --git a/arch/x86/platform/efi/efi_stub_64.S b/arch/x86/platform/efi/efi_stub_64.S
26928index 4c07cca..2c8427d 100644
26929--- a/arch/x86/platform/efi/efi_stub_64.S
26930+++ b/arch/x86/platform/efi/efi_stub_64.S
26931@@ -7,6 +7,7 @@
26932 */
26933
26934 #include <linux/linkage.h>
26935+#include <asm/alternative-asm.h>
26936
26937 #define SAVE_XMM \
26938 mov %rsp, %rax; \
26939@@ -40,6 +41,7 @@ ENTRY(efi_call0)
26940 call *%rdi
26941 addq $32, %rsp
26942 RESTORE_XMM
26943+ pax_force_retaddr 0, 1
26944 ret
26945 ENDPROC(efi_call0)
26946
26947@@ -50,6 +52,7 @@ ENTRY(efi_call1)
26948 call *%rdi
26949 addq $32, %rsp
26950 RESTORE_XMM
26951+ pax_force_retaddr 0, 1
26952 ret
26953 ENDPROC(efi_call1)
26954
26955@@ -60,6 +63,7 @@ ENTRY(efi_call2)
26956 call *%rdi
26957 addq $32, %rsp
26958 RESTORE_XMM
26959+ pax_force_retaddr 0, 1
26960 ret
26961 ENDPROC(efi_call2)
26962
26963@@ -71,6 +75,7 @@ ENTRY(efi_call3)
26964 call *%rdi
26965 addq $32, %rsp
26966 RESTORE_XMM
26967+ pax_force_retaddr 0, 1
26968 ret
26969 ENDPROC(efi_call3)
26970
26971@@ -83,6 +88,7 @@ ENTRY(efi_call4)
26972 call *%rdi
26973 addq $32, %rsp
26974 RESTORE_XMM
26975+ pax_force_retaddr 0, 1
26976 ret
26977 ENDPROC(efi_call4)
26978
26979@@ -96,6 +102,7 @@ ENTRY(efi_call5)
26980 call *%rdi
26981 addq $48, %rsp
26982 RESTORE_XMM
26983+ pax_force_retaddr 0, 1
26984 ret
26985 ENDPROC(efi_call5)
26986
26987@@ -112,5 +119,6 @@ ENTRY(efi_call6)
26988 call *%rdi
26989 addq $48, %rsp
26990 RESTORE_XMM
26991+ pax_force_retaddr 0, 1
26992 ret
26993 ENDPROC(efi_call6)
26994diff --git a/arch/x86/platform/mrst/mrst.c b/arch/x86/platform/mrst/mrst.c
26995index fd41a92..9c33628 100644
26996--- a/arch/x86/platform/mrst/mrst.c
26997+++ b/arch/x86/platform/mrst/mrst.c
26998@@ -78,13 +78,15 @@ struct sfi_rtc_table_entry sfi_mrtc_array[SFI_MRTC_MAX];
26999 EXPORT_SYMBOL_GPL(sfi_mrtc_array);
27000 int sfi_mrtc_num;
27001
27002-static void mrst_power_off(void)
27003+static __noreturn void mrst_power_off(void)
27004 {
27005+ BUG();
27006 }
27007
27008-static void mrst_reboot(void)
27009+static __noreturn void mrst_reboot(void)
27010 {
27011 intel_scu_ipc_simple_command(IPCMSG_COLD_BOOT, 0);
27012+ BUG();
27013 }
27014
27015 /* parse all the mtimer info to a static mtimer array */
27016diff --git a/arch/x86/power/cpu.c b/arch/x86/power/cpu.c
27017index 218cdb1..fd55c08 100644
27018--- a/arch/x86/power/cpu.c
27019+++ b/arch/x86/power/cpu.c
27020@@ -132,7 +132,7 @@ static void do_fpu_end(void)
27021 static void fix_processor_context(void)
27022 {
27023 int cpu = smp_processor_id();
27024- struct tss_struct *t = &per_cpu(init_tss, cpu);
27025+ struct tss_struct *t = init_tss + cpu;
27026
27027 set_tss_desc(cpu, t); /*
27028 * This just modifies memory; should not be
27029@@ -142,7 +142,9 @@ static void fix_processor_context(void)
27030 */
27031
27032 #ifdef CONFIG_X86_64
27033+ pax_open_kernel();
27034 get_cpu_gdt_table(cpu)[GDT_ENTRY_TSS].type = 9;
27035+ pax_close_kernel();
27036
27037 syscall_init(); /* This sets MSR_*STAR and related */
27038 #endif
27039diff --git a/arch/x86/realmode/init.c b/arch/x86/realmode/init.c
27040index cbca565..bae7133 100644
27041--- a/arch/x86/realmode/init.c
27042+++ b/arch/x86/realmode/init.c
27043@@ -62,7 +62,13 @@ void __init setup_real_mode(void)
27044 __va(real_mode_header->trampoline_header);
27045
27046 #ifdef CONFIG_X86_32
27047- trampoline_header->start = __pa(startup_32_smp);
27048+ trampoline_header->start = __pa(ktla_ktva(startup_32_smp));
27049+
27050+#ifdef CONFIG_PAX_KERNEXEC
27051+ trampoline_header->start -= LOAD_PHYSICAL_ADDR;
27052+#endif
27053+
27054+ trampoline_header->boot_cs = __BOOT_CS;
27055 trampoline_header->gdt_limit = __BOOT_DS + 7;
27056 trampoline_header->gdt_base = __pa(boot_gdt);
27057 #else
27058diff --git a/arch/x86/realmode/rm/Makefile b/arch/x86/realmode/rm/Makefile
27059index 8869287..d577672 100644
27060--- a/arch/x86/realmode/rm/Makefile
27061+++ b/arch/x86/realmode/rm/Makefile
27062@@ -78,5 +78,8 @@ KBUILD_CFLAGS := $(LINUXINCLUDE) -m32 -g -Os -D_SETUP -D__KERNEL__ -D_WAKEUP \
27063 $(call cc-option, -fno-unit-at-a-time)) \
27064 $(call cc-option, -fno-stack-protector) \
27065 $(call cc-option, -mpreferred-stack-boundary=2)
27066+ifdef CONSTIFY_PLUGIN
27067+KBUILD_CFLAGS += -fplugin-arg-constify_plugin-no-constify
27068+endif
27069 KBUILD_AFLAGS := $(KBUILD_CFLAGS) -D__ASSEMBLY__
27070 GCOV_PROFILE := n
27071diff --git a/arch/x86/realmode/rm/header.S b/arch/x86/realmode/rm/header.S
27072index a28221d..93c40f1 100644
27073--- a/arch/x86/realmode/rm/header.S
27074+++ b/arch/x86/realmode/rm/header.S
27075@@ -30,7 +30,9 @@ GLOBAL(real_mode_header)
27076 #endif
27077 /* APM/BIOS reboot */
27078 .long pa_machine_real_restart_asm
27079-#ifdef CONFIG_X86_64
27080+#ifdef CONFIG_X86_32
27081+ .long __KERNEL_CS
27082+#else
27083 .long __KERNEL32_CS
27084 #endif
27085 END(real_mode_header)
27086diff --git a/arch/x86/realmode/rm/trampoline_32.S b/arch/x86/realmode/rm/trampoline_32.S
27087index c1b2791..f9e31c7 100644
27088--- a/arch/x86/realmode/rm/trampoline_32.S
27089+++ b/arch/x86/realmode/rm/trampoline_32.S
27090@@ -25,6 +25,12 @@
27091 #include <asm/page_types.h>
27092 #include "realmode.h"
27093
27094+#ifdef CONFIG_PAX_KERNEXEC
27095+#define ta(X) (X)
27096+#else
27097+#define ta(X) (pa_ ## X)
27098+#endif
27099+
27100 .text
27101 .code16
27102
27103@@ -39,8 +45,6 @@ ENTRY(trampoline_start)
27104
27105 cli # We should be safe anyway
27106
27107- movl tr_start, %eax # where we need to go
27108-
27109 movl $0xA5A5A5A5, trampoline_status
27110 # write marker for master knows we're running
27111
27112@@ -56,7 +60,7 @@ ENTRY(trampoline_start)
27113 movw $1, %dx # protected mode (PE) bit
27114 lmsw %dx # into protected mode
27115
27116- ljmpl $__BOOT_CS, $pa_startup_32
27117+ ljmpl *(trampoline_header)
27118
27119 .section ".text32","ax"
27120 .code32
27121@@ -67,7 +71,7 @@ ENTRY(startup_32) # note: also used from wakeup_asm.S
27122 .balign 8
27123 GLOBAL(trampoline_header)
27124 tr_start: .space 4
27125- tr_gdt_pad: .space 2
27126+ tr_boot_cs: .space 2
27127 tr_gdt: .space 6
27128 END(trampoline_header)
27129
27130diff --git a/arch/x86/realmode/rm/trampoline_64.S b/arch/x86/realmode/rm/trampoline_64.S
27131index bb360dc..3e5945f 100644
27132--- a/arch/x86/realmode/rm/trampoline_64.S
27133+++ b/arch/x86/realmode/rm/trampoline_64.S
27134@@ -107,7 +107,7 @@ ENTRY(startup_32)
27135 wrmsr
27136
27137 # Enable paging and in turn activate Long Mode
27138- movl $(X86_CR0_PG | X86_CR0_WP | X86_CR0_PE), %eax
27139+ movl $(X86_CR0_PG | X86_CR0_PE), %eax
27140 movl %eax, %cr0
27141
27142 /*
27143diff --git a/arch/x86/tools/relocs.c b/arch/x86/tools/relocs.c
27144index 5a1847d..deccb30 100644
27145--- a/arch/x86/tools/relocs.c
27146+++ b/arch/x86/tools/relocs.c
27147@@ -12,10 +12,13 @@
27148 #include <regex.h>
27149 #include <tools/le_byteshift.h>
27150
27151+#include "../../../include/generated/autoconf.h"
27152+
27153 static void die(char *fmt, ...);
27154
27155 #define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
27156 static Elf32_Ehdr ehdr;
27157+static Elf32_Phdr *phdr;
27158 static unsigned long reloc_count, reloc_idx;
27159 static unsigned long *relocs;
27160 static unsigned long reloc16_count, reloc16_idx;
27161@@ -330,9 +333,39 @@ static void read_ehdr(FILE *fp)
27162 }
27163 }
27164
27165+static void read_phdrs(FILE *fp)
27166+{
27167+ unsigned int i;
27168+
27169+ phdr = calloc(ehdr.e_phnum, sizeof(Elf32_Phdr));
27170+ if (!phdr) {
27171+ die("Unable to allocate %d program headers\n",
27172+ ehdr.e_phnum);
27173+ }
27174+ if (fseek(fp, ehdr.e_phoff, SEEK_SET) < 0) {
27175+ die("Seek to %d failed: %s\n",
27176+ ehdr.e_phoff, strerror(errno));
27177+ }
27178+ if (fread(phdr, sizeof(*phdr), ehdr.e_phnum, fp) != ehdr.e_phnum) {
27179+ die("Cannot read ELF program headers: %s\n",
27180+ strerror(errno));
27181+ }
27182+ for(i = 0; i < ehdr.e_phnum; i++) {
27183+ phdr[i].p_type = elf32_to_cpu(phdr[i].p_type);
27184+ phdr[i].p_offset = elf32_to_cpu(phdr[i].p_offset);
27185+ phdr[i].p_vaddr = elf32_to_cpu(phdr[i].p_vaddr);
27186+ phdr[i].p_paddr = elf32_to_cpu(phdr[i].p_paddr);
27187+ phdr[i].p_filesz = elf32_to_cpu(phdr[i].p_filesz);
27188+ phdr[i].p_memsz = elf32_to_cpu(phdr[i].p_memsz);
27189+ phdr[i].p_flags = elf32_to_cpu(phdr[i].p_flags);
27190+ phdr[i].p_align = elf32_to_cpu(phdr[i].p_align);
27191+ }
27192+
27193+}
27194+
27195 static void read_shdrs(FILE *fp)
27196 {
27197- int i;
27198+ unsigned int i;
27199 Elf32_Shdr shdr;
27200
27201 secs = calloc(ehdr.e_shnum, sizeof(struct section));
27202@@ -367,7 +400,7 @@ static void read_shdrs(FILE *fp)
27203
27204 static void read_strtabs(FILE *fp)
27205 {
27206- int i;
27207+ unsigned int i;
27208 for (i = 0; i < ehdr.e_shnum; i++) {
27209 struct section *sec = &secs[i];
27210 if (sec->shdr.sh_type != SHT_STRTAB) {
27211@@ -392,7 +425,7 @@ static void read_strtabs(FILE *fp)
27212
27213 static void read_symtabs(FILE *fp)
27214 {
27215- int i,j;
27216+ unsigned int i,j;
27217 for (i = 0; i < ehdr.e_shnum; i++) {
27218 struct section *sec = &secs[i];
27219 if (sec->shdr.sh_type != SHT_SYMTAB) {
27220@@ -423,9 +456,11 @@ static void read_symtabs(FILE *fp)
27221 }
27222
27223
27224-static void read_relocs(FILE *fp)
27225+static void read_relocs(FILE *fp, int use_real_mode)
27226 {
27227- int i,j;
27228+ unsigned int i,j;
27229+ uint32_t base;
27230+
27231 for (i = 0; i < ehdr.e_shnum; i++) {
27232 struct section *sec = &secs[i];
27233 if (sec->shdr.sh_type != SHT_REL) {
27234@@ -445,9 +480,22 @@ static void read_relocs(FILE *fp)
27235 die("Cannot read symbol table: %s\n",
27236 strerror(errno));
27237 }
27238+ base = 0;
27239+
27240+#ifdef CONFIG_X86_32
27241+ for (j = 0; !use_real_mode && j < ehdr.e_phnum; j++) {
27242+ if (phdr[j].p_type != PT_LOAD )
27243+ continue;
27244+ 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)
27245+ continue;
27246+ base = CONFIG_PAGE_OFFSET + phdr[j].p_paddr - phdr[j].p_vaddr;
27247+ break;
27248+ }
27249+#endif
27250+
27251 for (j = 0; j < sec->shdr.sh_size/sizeof(Elf32_Rel); j++) {
27252 Elf32_Rel *rel = &sec->reltab[j];
27253- rel->r_offset = elf32_to_cpu(rel->r_offset);
27254+ rel->r_offset = elf32_to_cpu(rel->r_offset) + base;
27255 rel->r_info = elf32_to_cpu(rel->r_info);
27256 }
27257 }
27258@@ -456,13 +504,13 @@ static void read_relocs(FILE *fp)
27259
27260 static void print_absolute_symbols(void)
27261 {
27262- int i;
27263+ unsigned int i;
27264 printf("Absolute symbols\n");
27265 printf(" Num: Value Size Type Bind Visibility Name\n");
27266 for (i = 0; i < ehdr.e_shnum; i++) {
27267 struct section *sec = &secs[i];
27268 char *sym_strtab;
27269- int j;
27270+ unsigned int j;
27271
27272 if (sec->shdr.sh_type != SHT_SYMTAB) {
27273 continue;
27274@@ -489,14 +537,14 @@ static void print_absolute_symbols(void)
27275
27276 static void print_absolute_relocs(void)
27277 {
27278- int i, printed = 0;
27279+ unsigned int i, printed = 0;
27280
27281 for (i = 0; i < ehdr.e_shnum; i++) {
27282 struct section *sec = &secs[i];
27283 struct section *sec_applies, *sec_symtab;
27284 char *sym_strtab;
27285 Elf32_Sym *sh_symtab;
27286- int j;
27287+ unsigned int j;
27288 if (sec->shdr.sh_type != SHT_REL) {
27289 continue;
27290 }
27291@@ -558,13 +606,13 @@ static void print_absolute_relocs(void)
27292 static void walk_relocs(void (*visit)(Elf32_Rel *rel, Elf32_Sym *sym),
27293 int use_real_mode)
27294 {
27295- int i;
27296+ unsigned int i;
27297 /* Walk through the relocations */
27298 for (i = 0; i < ehdr.e_shnum; i++) {
27299 char *sym_strtab;
27300 Elf32_Sym *sh_symtab;
27301 struct section *sec_applies, *sec_symtab;
27302- int j;
27303+ unsigned int j;
27304 struct section *sec = &secs[i];
27305
27306 if (sec->shdr.sh_type != SHT_REL) {
27307@@ -588,6 +636,24 @@ static void walk_relocs(void (*visit)(Elf32_Rel *rel, Elf32_Sym *sym),
27308 sym = &sh_symtab[ELF32_R_SYM(rel->r_info)];
27309 r_type = ELF32_R_TYPE(rel->r_info);
27310
27311+ if (!use_real_mode) {
27312+ /* Don't relocate actual per-cpu variables, they are absolute indices, not addresses */
27313+ if (!strcmp(sec_name(sym->st_shndx), ".data..percpu") && strcmp(sym_name(sym_strtab, sym), "__per_cpu_load"))
27314+ continue;
27315+
27316+#if defined(CONFIG_PAX_KERNEXEC) && defined(CONFIG_X86_32)
27317+ /* Don't relocate actual code, they are relocated implicitly by the base address of KERNEL_CS */
27318+ if (!strcmp(sec_name(sym->st_shndx), ".text.end") && !strcmp(sym_name(sym_strtab, sym), "_etext"))
27319+ continue;
27320+ if (!strcmp(sec_name(sym->st_shndx), ".init.text"))
27321+ continue;
27322+ if (!strcmp(sec_name(sym->st_shndx), ".exit.text"))
27323+ continue;
27324+ if (!strcmp(sec_name(sym->st_shndx), ".text") && strcmp(sym_name(sym_strtab, sym), "__LOAD_PHYSICAL_ADDR"))
27325+ continue;
27326+#endif
27327+ }
27328+
27329 shn_abs = sym->st_shndx == SHN_ABS;
27330
27331 switch (r_type) {
27332@@ -681,7 +747,7 @@ static int write32(unsigned int v, FILE *f)
27333
27334 static void emit_relocs(int as_text, int use_real_mode)
27335 {
27336- int i;
27337+ unsigned int i;
27338 /* Count how many relocations I have and allocate space for them. */
27339 reloc_count = 0;
27340 walk_relocs(count_reloc, use_real_mode);
27341@@ -808,10 +874,11 @@ int main(int argc, char **argv)
27342 fname, strerror(errno));
27343 }
27344 read_ehdr(fp);
27345+ read_phdrs(fp);
27346 read_shdrs(fp);
27347 read_strtabs(fp);
27348 read_symtabs(fp);
27349- read_relocs(fp);
27350+ read_relocs(fp, use_real_mode);
27351 if (show_absolute_syms) {
27352 print_absolute_symbols();
27353 return 0;
27354diff --git a/arch/x86/vdso/Makefile b/arch/x86/vdso/Makefile
27355index fd14be1..e3c79c0 100644
27356--- a/arch/x86/vdso/Makefile
27357+++ b/arch/x86/vdso/Makefile
27358@@ -181,7 +181,7 @@ quiet_cmd_vdso = VDSO $@
27359 -Wl,-T,$(filter %.lds,$^) $(filter %.o,$^) && \
27360 sh $(srctree)/$(src)/checkundef.sh '$(NM)' '$@'
27361
27362-VDSO_LDFLAGS = -fPIC -shared $(call cc-ldoption, -Wl$(comma)--hash-style=sysv)
27363+VDSO_LDFLAGS = -fPIC -shared -Wl,--no-undefined $(call cc-ldoption, -Wl$(comma)--hash-style=sysv)
27364 GCOV_PROFILE := n
27365
27366 #
27367diff --git a/arch/x86/vdso/vdso32-setup.c b/arch/x86/vdso/vdso32-setup.c
27368index 0faad64..39ef157 100644
27369--- a/arch/x86/vdso/vdso32-setup.c
27370+++ b/arch/x86/vdso/vdso32-setup.c
27371@@ -25,6 +25,7 @@
27372 #include <asm/tlbflush.h>
27373 #include <asm/vdso.h>
27374 #include <asm/proto.h>
27375+#include <asm/mman.h>
27376
27377 enum {
27378 VDSO_DISABLED = 0,
27379@@ -226,7 +227,7 @@ static inline void map_compat_vdso(int map)
27380 void enable_sep_cpu(void)
27381 {
27382 int cpu = get_cpu();
27383- struct tss_struct *tss = &per_cpu(init_tss, cpu);
27384+ struct tss_struct *tss = init_tss + cpu;
27385
27386 if (!boot_cpu_has(X86_FEATURE_SEP)) {
27387 put_cpu();
27388@@ -249,7 +250,7 @@ static int __init gate_vma_init(void)
27389 gate_vma.vm_start = FIXADDR_USER_START;
27390 gate_vma.vm_end = FIXADDR_USER_END;
27391 gate_vma.vm_flags = VM_READ | VM_MAYREAD | VM_EXEC | VM_MAYEXEC;
27392- gate_vma.vm_page_prot = __P101;
27393+ gate_vma.vm_page_prot = vm_get_page_prot(gate_vma.vm_flags);
27394
27395 return 0;
27396 }
27397@@ -330,14 +331,14 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
27398 if (compat)
27399 addr = VDSO_HIGH_BASE;
27400 else {
27401- addr = get_unmapped_area(NULL, 0, PAGE_SIZE, 0, 0);
27402+ addr = get_unmapped_area(NULL, 0, PAGE_SIZE, 0, MAP_EXECUTABLE);
27403 if (IS_ERR_VALUE(addr)) {
27404 ret = addr;
27405 goto up_fail;
27406 }
27407 }
27408
27409- current->mm->context.vdso = (void *)addr;
27410+ current->mm->context.vdso = addr;
27411
27412 if (compat_uses_vma || !compat) {
27413 /*
27414@@ -353,11 +354,11 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
27415 }
27416
27417 current_thread_info()->sysenter_return =
27418- VDSO32_SYMBOL(addr, SYSENTER_RETURN);
27419+ (__force void __user *)VDSO32_SYMBOL(addr, SYSENTER_RETURN);
27420
27421 up_fail:
27422 if (ret)
27423- current->mm->context.vdso = NULL;
27424+ current->mm->context.vdso = 0;
27425
27426 up_write(&mm->mmap_sem);
27427
27428@@ -404,8 +405,14 @@ __initcall(ia32_binfmt_init);
27429
27430 const char *arch_vma_name(struct vm_area_struct *vma)
27431 {
27432- if (vma->vm_mm && vma->vm_start == (long)vma->vm_mm->context.vdso)
27433+ if (vma->vm_mm && vma->vm_start == vma->vm_mm->context.vdso)
27434 return "[vdso]";
27435+
27436+#ifdef CONFIG_PAX_SEGMEXEC
27437+ if (vma->vm_mm && vma->vm_mirror && vma->vm_mirror->vm_start == vma->vm_mm->context.vdso)
27438+ return "[vdso]";
27439+#endif
27440+
27441 return NULL;
27442 }
27443
27444@@ -415,7 +422,7 @@ struct vm_area_struct *get_gate_vma(struct mm_struct *mm)
27445 * Check to see if the corresponding task was created in compat vdso
27446 * mode.
27447 */
27448- if (mm && mm->context.vdso == (void *)VDSO_HIGH_BASE)
27449+ if (mm && mm->context.vdso == VDSO_HIGH_BASE)
27450 return &gate_vma;
27451 return NULL;
27452 }
27453diff --git a/arch/x86/vdso/vma.c b/arch/x86/vdso/vma.c
27454index 00aaf04..4a26505 100644
27455--- a/arch/x86/vdso/vma.c
27456+++ b/arch/x86/vdso/vma.c
27457@@ -16,8 +16,6 @@
27458 #include <asm/vdso.h>
27459 #include <asm/page.h>
27460
27461-unsigned int __read_mostly vdso_enabled = 1;
27462-
27463 extern char vdso_start[], vdso_end[];
27464 extern unsigned short vdso_sync_cpuid;
27465
27466@@ -141,7 +139,6 @@ static unsigned long vdso_addr(unsigned long start, unsigned len)
27467 * unaligned here as a result of stack start randomization.
27468 */
27469 addr = PAGE_ALIGN(addr);
27470- addr = align_addr(addr, NULL, ALIGN_VDSO);
27471
27472 return addr;
27473 }
27474@@ -154,30 +151,31 @@ static int setup_additional_pages(struct linux_binprm *bprm,
27475 unsigned size)
27476 {
27477 struct mm_struct *mm = current->mm;
27478- unsigned long addr;
27479+ unsigned long addr = 0;
27480 int ret;
27481
27482- if (!vdso_enabled)
27483- return 0;
27484-
27485 down_write(&mm->mmap_sem);
27486+
27487+#ifdef CONFIG_PAX_RANDMMAP
27488+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
27489+#endif
27490+
27491 addr = vdso_addr(mm->start_stack, size);
27492+ addr = align_addr(addr, NULL, ALIGN_VDSO);
27493 addr = get_unmapped_area(NULL, addr, size, 0, 0);
27494 if (IS_ERR_VALUE(addr)) {
27495 ret = addr;
27496 goto up_fail;
27497 }
27498
27499- current->mm->context.vdso = (void *)addr;
27500+ mm->context.vdso = addr;
27501
27502 ret = install_special_mapping(mm, addr, size,
27503 VM_READ|VM_EXEC|
27504 VM_MAYREAD|VM_MAYWRITE|VM_MAYEXEC,
27505 pages);
27506- if (ret) {
27507- current->mm->context.vdso = NULL;
27508- goto up_fail;
27509- }
27510+ if (ret)
27511+ mm->context.vdso = 0;
27512
27513 up_fail:
27514 up_write(&mm->mmap_sem);
27515@@ -197,10 +195,3 @@ int x32_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
27516 vdsox32_size);
27517 }
27518 #endif
27519-
27520-static __init int vdso_setup(char *s)
27521-{
27522- vdso_enabled = simple_strtoul(s, NULL, 0);
27523- return 0;
27524-}
27525-__setup("vdso=", vdso_setup);
27526diff --git a/arch/x86/xen/enlighten.c b/arch/x86/xen/enlighten.c
27527index c1461de..355f120 100644
27528--- a/arch/x86/xen/enlighten.c
27529+++ b/arch/x86/xen/enlighten.c
27530@@ -98,8 +98,6 @@ EXPORT_SYMBOL_GPL(xen_start_info);
27531
27532 struct shared_info xen_dummy_shared_info;
27533
27534-void *xen_initial_gdt;
27535-
27536 RESERVE_BRK(shared_info_page_brk, PAGE_SIZE);
27537 __read_mostly int xen_have_vector_callback;
27538 EXPORT_SYMBOL_GPL(xen_have_vector_callback);
27539@@ -917,21 +915,21 @@ static u32 xen_safe_apic_wait_icr_idle(void)
27540
27541 static void set_xen_basic_apic_ops(void)
27542 {
27543- apic->read = xen_apic_read;
27544- apic->write = xen_apic_write;
27545- apic->icr_read = xen_apic_icr_read;
27546- apic->icr_write = xen_apic_icr_write;
27547- apic->wait_icr_idle = xen_apic_wait_icr_idle;
27548- apic->safe_wait_icr_idle = xen_safe_apic_wait_icr_idle;
27549- apic->set_apic_id = xen_set_apic_id;
27550- apic->get_apic_id = xen_get_apic_id;
27551+ *(void **)&apic->read = xen_apic_read;
27552+ *(void **)&apic->write = xen_apic_write;
27553+ *(void **)&apic->icr_read = xen_apic_icr_read;
27554+ *(void **)&apic->icr_write = xen_apic_icr_write;
27555+ *(void **)&apic->wait_icr_idle = xen_apic_wait_icr_idle;
27556+ *(void **)&apic->safe_wait_icr_idle = xen_safe_apic_wait_icr_idle;
27557+ *(void **)&apic->set_apic_id = xen_set_apic_id;
27558+ *(void **)&apic->get_apic_id = xen_get_apic_id;
27559
27560 #ifdef CONFIG_SMP
27561- apic->send_IPI_allbutself = xen_send_IPI_allbutself;
27562- apic->send_IPI_mask_allbutself = xen_send_IPI_mask_allbutself;
27563- apic->send_IPI_mask = xen_send_IPI_mask;
27564- apic->send_IPI_all = xen_send_IPI_all;
27565- apic->send_IPI_self = xen_send_IPI_self;
27566+ *(void **)&apic->send_IPI_allbutself = xen_send_IPI_allbutself;
27567+ *(void **)&apic->send_IPI_mask_allbutself = xen_send_IPI_mask_allbutself;
27568+ *(void **)&apic->send_IPI_mask = xen_send_IPI_mask;
27569+ *(void **)&apic->send_IPI_all = xen_send_IPI_all;
27570+ *(void **)&apic->send_IPI_self = xen_send_IPI_self;
27571 #endif
27572 }
27573
27574@@ -1221,30 +1219,30 @@ static const struct pv_apic_ops xen_apic_ops __initconst = {
27575 #endif
27576 };
27577
27578-static void xen_reboot(int reason)
27579+static __noreturn void xen_reboot(int reason)
27580 {
27581 struct sched_shutdown r = { .reason = reason };
27582
27583- if (HYPERVISOR_sched_op(SCHEDOP_shutdown, &r))
27584- BUG();
27585+ HYPERVISOR_sched_op(SCHEDOP_shutdown, &r);
27586+ BUG();
27587 }
27588
27589-static void xen_restart(char *msg)
27590+static __noreturn void xen_restart(char *msg)
27591 {
27592 xen_reboot(SHUTDOWN_reboot);
27593 }
27594
27595-static void xen_emergency_restart(void)
27596+static __noreturn void xen_emergency_restart(void)
27597 {
27598 xen_reboot(SHUTDOWN_reboot);
27599 }
27600
27601-static void xen_machine_halt(void)
27602+static __noreturn void xen_machine_halt(void)
27603 {
27604 xen_reboot(SHUTDOWN_poweroff);
27605 }
27606
27607-static void xen_machine_power_off(void)
27608+static __noreturn void xen_machine_power_off(void)
27609 {
27610 if (pm_power_off)
27611 pm_power_off();
27612@@ -1347,7 +1345,17 @@ asmlinkage void __init xen_start_kernel(void)
27613 __userpte_alloc_gfp &= ~__GFP_HIGHMEM;
27614
27615 /* Work out if we support NX */
27616- x86_configure_nx();
27617+#if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
27618+ if ((cpuid_eax(0x80000000) & 0xffff0000) == 0x80000000 &&
27619+ (cpuid_edx(0x80000001) & (1U << (X86_FEATURE_NX & 31)))) {
27620+ unsigned l, h;
27621+
27622+ __supported_pte_mask |= _PAGE_NX;
27623+ rdmsr(MSR_EFER, l, h);
27624+ l |= EFER_NX;
27625+ wrmsr(MSR_EFER, l, h);
27626+ }
27627+#endif
27628
27629 xen_setup_features();
27630
27631@@ -1378,13 +1386,6 @@ asmlinkage void __init xen_start_kernel(void)
27632
27633 machine_ops = xen_machine_ops;
27634
27635- /*
27636- * The only reliable way to retain the initial address of the
27637- * percpu gdt_page is to remember it here, so we can go and
27638- * mark it RW later, when the initial percpu area is freed.
27639- */
27640- xen_initial_gdt = &per_cpu(gdt_page, 0);
27641-
27642 xen_smp_init();
27643
27644 #ifdef CONFIG_ACPI_NUMA
27645diff --git a/arch/x86/xen/mmu.c b/arch/x86/xen/mmu.c
27646index dde1a3f..6b663e6 100644
27647--- a/arch/x86/xen/mmu.c
27648+++ b/arch/x86/xen/mmu.c
27649@@ -1784,6 +1784,9 @@ pgd_t * __init xen_setup_kernel_pagetable(pgd_t *pgd,
27650 convert_pfn_mfn(init_level4_pgt);
27651 convert_pfn_mfn(level3_ident_pgt);
27652 convert_pfn_mfn(level3_kernel_pgt);
27653+ convert_pfn_mfn(level3_vmalloc_start_pgt);
27654+ convert_pfn_mfn(level3_vmalloc_end_pgt);
27655+ convert_pfn_mfn(level3_vmemmap_pgt);
27656
27657 l3 = m2v(pgd[pgd_index(__START_KERNEL_map)].pgd);
27658 l2 = m2v(l3[pud_index(__START_KERNEL_map)].pud);
27659@@ -1802,7 +1805,11 @@ pgd_t * __init xen_setup_kernel_pagetable(pgd_t *pgd,
27660 set_page_prot(init_level4_pgt, PAGE_KERNEL_RO);
27661 set_page_prot(level3_ident_pgt, PAGE_KERNEL_RO);
27662 set_page_prot(level3_kernel_pgt, PAGE_KERNEL_RO);
27663+ set_page_prot(level3_vmalloc_start_pgt, PAGE_KERNEL_RO);
27664+ set_page_prot(level3_vmalloc_end_pgt, PAGE_KERNEL_RO);
27665+ set_page_prot(level3_vmemmap_pgt, PAGE_KERNEL_RO);
27666 set_page_prot(level3_user_vsyscall, PAGE_KERNEL_RO);
27667+ set_page_prot(level2_vmemmap_pgt, PAGE_KERNEL_RO);
27668 set_page_prot(level2_kernel_pgt, PAGE_KERNEL_RO);
27669 set_page_prot(level2_fixmap_pgt, PAGE_KERNEL_RO);
27670
27671@@ -1986,6 +1993,7 @@ static void __init xen_post_allocator_init(void)
27672 pv_mmu_ops.set_pud = xen_set_pud;
27673 #if PAGETABLE_LEVELS == 4
27674 pv_mmu_ops.set_pgd = xen_set_pgd;
27675+ pv_mmu_ops.set_pgd_batched = xen_set_pgd;
27676 #endif
27677
27678 /* This will work as long as patching hasn't happened yet
27679@@ -2067,6 +2075,7 @@ static const struct pv_mmu_ops xen_mmu_ops __initconst = {
27680 .pud_val = PV_CALLEE_SAVE(xen_pud_val),
27681 .make_pud = PV_CALLEE_SAVE(xen_make_pud),
27682 .set_pgd = xen_set_pgd_hyper,
27683+ .set_pgd_batched = xen_set_pgd_hyper,
27684
27685 .alloc_pud = xen_alloc_pmd_init,
27686 .release_pud = xen_release_pmd_init,
27687diff --git a/arch/x86/xen/smp.c b/arch/x86/xen/smp.c
27688index f58dca7..ad21f52 100644
27689--- a/arch/x86/xen/smp.c
27690+++ b/arch/x86/xen/smp.c
27691@@ -229,11 +229,6 @@ static void __init xen_smp_prepare_boot_cpu(void)
27692 {
27693 BUG_ON(smp_processor_id() != 0);
27694 native_smp_prepare_boot_cpu();
27695-
27696- /* We've switched to the "real" per-cpu gdt, so make sure the
27697- old memory can be recycled */
27698- make_lowmem_page_readwrite(xen_initial_gdt);
27699-
27700 xen_filter_cpu_maps();
27701 xen_setup_vcpu_info_placement();
27702 }
27703@@ -300,12 +295,12 @@ cpu_initialize_context(unsigned int cpu, struct task_struct *idle)
27704 gdt = get_cpu_gdt_table(cpu);
27705
27706 ctxt->flags = VGCF_IN_KERNEL;
27707- ctxt->user_regs.ds = __USER_DS;
27708- ctxt->user_regs.es = __USER_DS;
27709+ ctxt->user_regs.ds = __KERNEL_DS;
27710+ ctxt->user_regs.es = __KERNEL_DS;
27711 ctxt->user_regs.ss = __KERNEL_DS;
27712 #ifdef CONFIG_X86_32
27713 ctxt->user_regs.fs = __KERNEL_PERCPU;
27714- ctxt->user_regs.gs = __KERNEL_STACK_CANARY;
27715+ savesegment(gs, ctxt->user_regs.gs);
27716 #else
27717 ctxt->gs_base_kernel = per_cpu_offset(cpu);
27718 #endif
27719@@ -355,13 +350,12 @@ static int __cpuinit xen_cpu_up(unsigned int cpu, struct task_struct *idle)
27720 int rc;
27721
27722 per_cpu(current_task, cpu) = idle;
27723+ per_cpu(current_tinfo, cpu) = &idle->tinfo;
27724 #ifdef CONFIG_X86_32
27725 irq_ctx_init(cpu);
27726 #else
27727 clear_tsk_thread_flag(idle, TIF_FORK);
27728- per_cpu(kernel_stack, cpu) =
27729- (unsigned long)task_stack_page(idle) -
27730- KERNEL_STACK_OFFSET + THREAD_SIZE;
27731+ per_cpu(kernel_stack, cpu) = (unsigned long)task_stack_page(idle) - 16 + THREAD_SIZE;
27732 #endif
27733 xen_setup_runstate_info(cpu);
27734 xen_setup_timer(cpu);
27735diff --git a/arch/x86/xen/xen-asm_32.S b/arch/x86/xen/xen-asm_32.S
27736index f9643fc..602e8af 100644
27737--- a/arch/x86/xen/xen-asm_32.S
27738+++ b/arch/x86/xen/xen-asm_32.S
27739@@ -84,14 +84,14 @@ ENTRY(xen_iret)
27740 ESP_OFFSET=4 # bytes pushed onto stack
27741
27742 /*
27743- * Store vcpu_info pointer for easy access. Do it this way to
27744- * avoid having to reload %fs
27745+ * Store vcpu_info pointer for easy access.
27746 */
27747 #ifdef CONFIG_SMP
27748- GET_THREAD_INFO(%eax)
27749- movl TI_cpu(%eax), %eax
27750- movl __per_cpu_offset(,%eax,4), %eax
27751- mov xen_vcpu(%eax), %eax
27752+ push %fs
27753+ mov $(__KERNEL_PERCPU), %eax
27754+ mov %eax, %fs
27755+ mov PER_CPU_VAR(xen_vcpu), %eax
27756+ pop %fs
27757 #else
27758 movl xen_vcpu, %eax
27759 #endif
27760diff --git a/arch/x86/xen/xen-head.S b/arch/x86/xen/xen-head.S
27761index aaa7291..3f77960 100644
27762--- a/arch/x86/xen/xen-head.S
27763+++ b/arch/x86/xen/xen-head.S
27764@@ -19,6 +19,17 @@ ENTRY(startup_xen)
27765 #ifdef CONFIG_X86_32
27766 mov %esi,xen_start_info
27767 mov $init_thread_union+THREAD_SIZE,%esp
27768+#ifdef CONFIG_SMP
27769+ movl $cpu_gdt_table,%edi
27770+ movl $__per_cpu_load,%eax
27771+ movw %ax,__KERNEL_PERCPU + 2(%edi)
27772+ rorl $16,%eax
27773+ movb %al,__KERNEL_PERCPU + 4(%edi)
27774+ movb %ah,__KERNEL_PERCPU + 7(%edi)
27775+ movl $__per_cpu_end - 1,%eax
27776+ subl $__per_cpu_start,%eax
27777+ movw %ax,__KERNEL_PERCPU + 0(%edi)
27778+#endif
27779 #else
27780 mov %rsi,xen_start_info
27781 mov $init_thread_union+THREAD_SIZE,%rsp
27782diff --git a/arch/x86/xen/xen-ops.h b/arch/x86/xen/xen-ops.h
27783index 202d4c1..99b072a 100644
27784--- a/arch/x86/xen/xen-ops.h
27785+++ b/arch/x86/xen/xen-ops.h
27786@@ -10,8 +10,6 @@
27787 extern const char xen_hypervisor_callback[];
27788 extern const char xen_failsafe_callback[];
27789
27790-extern void *xen_initial_gdt;
27791-
27792 struct trap_info;
27793 void xen_copy_trap_info(struct trap_info *traps);
27794
27795diff --git a/arch/xtensa/variants/dc232b/include/variant/core.h b/arch/xtensa/variants/dc232b/include/variant/core.h
27796index 525bd3d..ef888b1 100644
27797--- a/arch/xtensa/variants/dc232b/include/variant/core.h
27798+++ b/arch/xtensa/variants/dc232b/include/variant/core.h
27799@@ -119,9 +119,9 @@
27800 ----------------------------------------------------------------------*/
27801
27802 #define XCHAL_ICACHE_LINESIZE 32 /* I-cache line size in bytes */
27803-#define XCHAL_DCACHE_LINESIZE 32 /* D-cache line size in bytes */
27804 #define XCHAL_ICACHE_LINEWIDTH 5 /* log2(I line size in bytes) */
27805 #define XCHAL_DCACHE_LINEWIDTH 5 /* log2(D line size in bytes) */
27806+#define XCHAL_DCACHE_LINESIZE (_AC(1,UL) << XCHAL_DCACHE_LINEWIDTH) /* D-cache line size in bytes */
27807
27808 #define XCHAL_ICACHE_SIZE 16384 /* I-cache size in bytes or 0 */
27809 #define XCHAL_DCACHE_SIZE 16384 /* D-cache size in bytes or 0 */
27810diff --git a/arch/xtensa/variants/fsf/include/variant/core.h b/arch/xtensa/variants/fsf/include/variant/core.h
27811index 2f33760..835e50a 100644
27812--- a/arch/xtensa/variants/fsf/include/variant/core.h
27813+++ b/arch/xtensa/variants/fsf/include/variant/core.h
27814@@ -11,6 +11,7 @@
27815 #ifndef _XTENSA_CORE_H
27816 #define _XTENSA_CORE_H
27817
27818+#include <linux/const.h>
27819
27820 /****************************************************************************
27821 Parameters Useful for Any Code, USER or PRIVILEGED
27822@@ -112,9 +113,9 @@
27823 ----------------------------------------------------------------------*/
27824
27825 #define XCHAL_ICACHE_LINESIZE 16 /* I-cache line size in bytes */
27826-#define XCHAL_DCACHE_LINESIZE 16 /* D-cache line size in bytes */
27827 #define XCHAL_ICACHE_LINEWIDTH 4 /* log2(I line size in bytes) */
27828 #define XCHAL_DCACHE_LINEWIDTH 4 /* log2(D line size in bytes) */
27829+#define XCHAL_DCACHE_LINESIZE (_AC(1,UL) << XCHAL_DCACHE_LINEWIDTH) /* D-cache line size in bytes */
27830
27831 #define XCHAL_ICACHE_SIZE 8192 /* I-cache size in bytes or 0 */
27832 #define XCHAL_DCACHE_SIZE 8192 /* D-cache size in bytes or 0 */
27833diff --git a/arch/xtensa/variants/s6000/include/variant/core.h b/arch/xtensa/variants/s6000/include/variant/core.h
27834index af00795..2bb8105 100644
27835--- a/arch/xtensa/variants/s6000/include/variant/core.h
27836+++ b/arch/xtensa/variants/s6000/include/variant/core.h
27837@@ -11,6 +11,7 @@
27838 #ifndef _XTENSA_CORE_CONFIGURATION_H
27839 #define _XTENSA_CORE_CONFIGURATION_H
27840
27841+#include <linux/const.h>
27842
27843 /****************************************************************************
27844 Parameters Useful for Any Code, USER or PRIVILEGED
27845@@ -118,9 +119,9 @@
27846 ----------------------------------------------------------------------*/
27847
27848 #define XCHAL_ICACHE_LINESIZE 16 /* I-cache line size in bytes */
27849-#define XCHAL_DCACHE_LINESIZE 16 /* D-cache line size in bytes */
27850 #define XCHAL_ICACHE_LINEWIDTH 4 /* log2(I line size in bytes) */
27851 #define XCHAL_DCACHE_LINEWIDTH 4 /* log2(D line size in bytes) */
27852+#define XCHAL_DCACHE_LINESIZE (_AC(1,UL) << XCHAL_DCACHE_LINEWIDTH) /* D-cache line size in bytes */
27853
27854 #define XCHAL_ICACHE_SIZE 32768 /* I-cache size in bytes or 0 */
27855 #define XCHAL_DCACHE_SIZE 32768 /* D-cache size in bytes or 0 */
27856diff --git a/block/blk-iopoll.c b/block/blk-iopoll.c
27857index 58916af..9cb880b 100644
27858--- a/block/blk-iopoll.c
27859+++ b/block/blk-iopoll.c
27860@@ -77,7 +77,7 @@ void blk_iopoll_complete(struct blk_iopoll *iopoll)
27861 }
27862 EXPORT_SYMBOL(blk_iopoll_complete);
27863
27864-static void blk_iopoll_softirq(struct softirq_action *h)
27865+static void blk_iopoll_softirq(void)
27866 {
27867 struct list_head *list = &__get_cpu_var(blk_cpu_iopoll);
27868 int rearm = 0, budget = blk_iopoll_budget;
27869diff --git a/block/blk-map.c b/block/blk-map.c
27870index 623e1cd..ca1e109 100644
27871--- a/block/blk-map.c
27872+++ b/block/blk-map.c
27873@@ -302,7 +302,7 @@ int blk_rq_map_kern(struct request_queue *q, struct request *rq, void *kbuf,
27874 if (!len || !kbuf)
27875 return -EINVAL;
27876
27877- do_copy = !blk_rq_aligned(q, addr, len) || object_is_on_stack(kbuf);
27878+ do_copy = !blk_rq_aligned(q, addr, len) || object_starts_on_stack(kbuf);
27879 if (do_copy)
27880 bio = bio_copy_kern(q, kbuf, len, gfp_mask, reading);
27881 else
27882diff --git a/block/blk-softirq.c b/block/blk-softirq.c
27883index 467c8de..4bddc6d 100644
27884--- a/block/blk-softirq.c
27885+++ b/block/blk-softirq.c
27886@@ -18,7 +18,7 @@ static DEFINE_PER_CPU(struct list_head, blk_cpu_done);
27887 * Softirq action handler - move entries to local list and loop over them
27888 * while passing them to the queue registered handler.
27889 */
27890-static void blk_done_softirq(struct softirq_action *h)
27891+static void blk_done_softirq(void)
27892 {
27893 struct list_head *cpu_list, local_list;
27894
27895diff --git a/block/bsg.c b/block/bsg.c
27896index ff64ae3..593560c 100644
27897--- a/block/bsg.c
27898+++ b/block/bsg.c
27899@@ -176,16 +176,24 @@ static int blk_fill_sgv4_hdr_rq(struct request_queue *q, struct request *rq,
27900 struct sg_io_v4 *hdr, struct bsg_device *bd,
27901 fmode_t has_write_perm)
27902 {
27903+ unsigned char tmpcmd[sizeof(rq->__cmd)];
27904+ unsigned char *cmdptr;
27905+
27906 if (hdr->request_len > BLK_MAX_CDB) {
27907 rq->cmd = kzalloc(hdr->request_len, GFP_KERNEL);
27908 if (!rq->cmd)
27909 return -ENOMEM;
27910- }
27911+ cmdptr = rq->cmd;
27912+ } else
27913+ cmdptr = tmpcmd;
27914
27915- if (copy_from_user(rq->cmd, (void __user *)(unsigned long)hdr->request,
27916+ if (copy_from_user(cmdptr, (void __user *)(unsigned long)hdr->request,
27917 hdr->request_len))
27918 return -EFAULT;
27919
27920+ if (cmdptr != rq->cmd)
27921+ memcpy(rq->cmd, cmdptr, hdr->request_len);
27922+
27923 if (hdr->subprotocol == BSG_SUB_PROTOCOL_SCSI_CMD) {
27924 if (blk_verify_command(rq->cmd, has_write_perm))
27925 return -EPERM;
27926diff --git a/block/compat_ioctl.c b/block/compat_ioctl.c
27927index 7c668c8..db3521c 100644
27928--- a/block/compat_ioctl.c
27929+++ b/block/compat_ioctl.c
27930@@ -340,7 +340,7 @@ static int compat_fd_ioctl(struct block_device *bdev, fmode_t mode,
27931 err |= __get_user(f->spec1, &uf->spec1);
27932 err |= __get_user(f->fmt_gap, &uf->fmt_gap);
27933 err |= __get_user(name, &uf->name);
27934- f->name = compat_ptr(name);
27935+ f->name = (void __force_kernel *)compat_ptr(name);
27936 if (err) {
27937 err = -EFAULT;
27938 goto out;
27939diff --git a/block/partitions/efi.c b/block/partitions/efi.c
27940index 6296b40..417c00f 100644
27941--- a/block/partitions/efi.c
27942+++ b/block/partitions/efi.c
27943@@ -234,14 +234,14 @@ static gpt_entry *alloc_read_gpt_entries(struct parsed_partitions *state,
27944 if (!gpt)
27945 return NULL;
27946
27947+ if (!le32_to_cpu(gpt->num_partition_entries))
27948+ return NULL;
27949+ pte = kcalloc(le32_to_cpu(gpt->num_partition_entries), le32_to_cpu(gpt->sizeof_partition_entry), GFP_KERNEL);
27950+ if (!pte)
27951+ return NULL;
27952+
27953 count = le32_to_cpu(gpt->num_partition_entries) *
27954 le32_to_cpu(gpt->sizeof_partition_entry);
27955- if (!count)
27956- return NULL;
27957- pte = kzalloc(count, GFP_KERNEL);
27958- if (!pte)
27959- return NULL;
27960-
27961 if (read_lba(state, le64_to_cpu(gpt->partition_entry_lba),
27962 (u8 *) pte,
27963 count) < count) {
27964diff --git a/block/scsi_ioctl.c b/block/scsi_ioctl.c
27965index 9a87daa..fb17486 100644
27966--- a/block/scsi_ioctl.c
27967+++ b/block/scsi_ioctl.c
27968@@ -223,8 +223,20 @@ EXPORT_SYMBOL(blk_verify_command);
27969 static int blk_fill_sghdr_rq(struct request_queue *q, struct request *rq,
27970 struct sg_io_hdr *hdr, fmode_t mode)
27971 {
27972- if (copy_from_user(rq->cmd, hdr->cmdp, hdr->cmd_len))
27973+ unsigned char tmpcmd[sizeof(rq->__cmd)];
27974+ unsigned char *cmdptr;
27975+
27976+ if (rq->cmd != rq->__cmd)
27977+ cmdptr = rq->cmd;
27978+ else
27979+ cmdptr = tmpcmd;
27980+
27981+ if (copy_from_user(cmdptr, hdr->cmdp, hdr->cmd_len))
27982 return -EFAULT;
27983+
27984+ if (cmdptr != rq->cmd)
27985+ memcpy(rq->cmd, cmdptr, hdr->cmd_len);
27986+
27987 if (blk_verify_command(rq->cmd, mode & FMODE_WRITE))
27988 return -EPERM;
27989
27990@@ -433,6 +445,8 @@ int sg_scsi_ioctl(struct request_queue *q, struct gendisk *disk, fmode_t mode,
27991 int err;
27992 unsigned int in_len, out_len, bytes, opcode, cmdlen;
27993 char *buffer = NULL, sense[SCSI_SENSE_BUFFERSIZE];
27994+ unsigned char tmpcmd[sizeof(rq->__cmd)];
27995+ unsigned char *cmdptr;
27996
27997 if (!sic)
27998 return -EINVAL;
27999@@ -466,9 +480,18 @@ int sg_scsi_ioctl(struct request_queue *q, struct gendisk *disk, fmode_t mode,
28000 */
28001 err = -EFAULT;
28002 rq->cmd_len = cmdlen;
28003- if (copy_from_user(rq->cmd, sic->data, cmdlen))
28004+
28005+ if (rq->cmd != rq->__cmd)
28006+ cmdptr = rq->cmd;
28007+ else
28008+ cmdptr = tmpcmd;
28009+
28010+ if (copy_from_user(cmdptr, sic->data, cmdlen))
28011 goto error;
28012
28013+ if (rq->cmd != cmdptr)
28014+ memcpy(rq->cmd, cmdptr, cmdlen);
28015+
28016 if (in_len && copy_from_user(buffer, sic->data + cmdlen, in_len))
28017 goto error;
28018
28019diff --git a/crypto/cryptd.c b/crypto/cryptd.c
28020index 671d4d6..afec999 100644
28021--- a/crypto/cryptd.c
28022+++ b/crypto/cryptd.c
28023@@ -63,7 +63,7 @@ struct cryptd_blkcipher_ctx {
28024
28025 struct cryptd_blkcipher_request_ctx {
28026 crypto_completion_t complete;
28027-};
28028+} __no_const;
28029
28030 struct cryptd_hash_ctx {
28031 struct crypto_shash *child;
28032@@ -80,7 +80,7 @@ struct cryptd_aead_ctx {
28033
28034 struct cryptd_aead_request_ctx {
28035 crypto_completion_t complete;
28036-};
28037+} __no_const;
28038
28039 static void cryptd_queue_worker(struct work_struct *work);
28040
28041@@ -137,13 +137,18 @@ static void cryptd_queue_worker(struct work_struct *work)
28042 struct crypto_async_request *req, *backlog;
28043
28044 cpu_queue = container_of(work, struct cryptd_cpu_queue, work);
28045- /* Only handle one request at a time to avoid hogging crypto
28046- * workqueue. preempt_disable/enable is used to prevent
28047- * being preempted by cryptd_enqueue_request() */
28048+ /*
28049+ * Only handle one request at a time to avoid hogging crypto workqueue.
28050+ * preempt_disable/enable is used to prevent being preempted by
28051+ * cryptd_enqueue_request(). local_bh_disable/enable is used to prevent
28052+ * cryptd_enqueue_request() being accessed from software interrupts.
28053+ */
28054+ local_bh_disable();
28055 preempt_disable();
28056 backlog = crypto_get_backlog(&cpu_queue->queue);
28057 req = crypto_dequeue_request(&cpu_queue->queue);
28058 preempt_enable();
28059+ local_bh_enable();
28060
28061 if (!req)
28062 return;
28063diff --git a/drivers/acpi/apei/cper.c b/drivers/acpi/apei/cper.c
28064index e6defd8..c26a225 100644
28065--- a/drivers/acpi/apei/cper.c
28066+++ b/drivers/acpi/apei/cper.c
28067@@ -38,12 +38,12 @@
28068 */
28069 u64 cper_next_record_id(void)
28070 {
28071- static atomic64_t seq;
28072+ static atomic64_unchecked_t seq;
28073
28074- if (!atomic64_read(&seq))
28075- atomic64_set(&seq, ((u64)get_seconds()) << 32);
28076+ if (!atomic64_read_unchecked(&seq))
28077+ atomic64_set_unchecked(&seq, ((u64)get_seconds()) << 32);
28078
28079- return atomic64_inc_return(&seq);
28080+ return atomic64_inc_return_unchecked(&seq);
28081 }
28082 EXPORT_SYMBOL_GPL(cper_next_record_id);
28083
28084diff --git a/drivers/acpi/ec_sys.c b/drivers/acpi/ec_sys.c
28085index 7586544..636a2f0 100644
28086--- a/drivers/acpi/ec_sys.c
28087+++ b/drivers/acpi/ec_sys.c
28088@@ -12,6 +12,7 @@
28089 #include <linux/acpi.h>
28090 #include <linux/debugfs.h>
28091 #include <linux/module.h>
28092+#include <linux/uaccess.h>
28093 #include "internal.h"
28094
28095 MODULE_AUTHOR("Thomas Renninger <trenn@suse.de>");
28096@@ -34,7 +35,7 @@ static ssize_t acpi_ec_read_io(struct file *f, char __user *buf,
28097 * struct acpi_ec *ec = ((struct seq_file *)f->private_data)->private;
28098 */
28099 unsigned int size = EC_SPACE_SIZE;
28100- u8 *data = (u8 *) buf;
28101+ u8 data;
28102 loff_t init_off = *off;
28103 int err = 0;
28104
28105@@ -47,9 +48,11 @@ static ssize_t acpi_ec_read_io(struct file *f, char __user *buf,
28106 size = count;
28107
28108 while (size) {
28109- err = ec_read(*off, &data[*off - init_off]);
28110+ err = ec_read(*off, &data);
28111 if (err)
28112 return err;
28113+ if (put_user(data, &buf[*off - init_off]))
28114+ return -EFAULT;
28115 *off += 1;
28116 size--;
28117 }
28118@@ -65,7 +68,6 @@ static ssize_t acpi_ec_write_io(struct file *f, const char __user *buf,
28119
28120 unsigned int size = count;
28121 loff_t init_off = *off;
28122- u8 *data = (u8 *) buf;
28123 int err = 0;
28124
28125 if (*off >= EC_SPACE_SIZE)
28126@@ -76,7 +78,9 @@ static ssize_t acpi_ec_write_io(struct file *f, const char __user *buf,
28127 }
28128
28129 while (size) {
28130- u8 byte_write = data[*off - init_off];
28131+ u8 byte_write;
28132+ if (get_user(byte_write, &buf[*off - init_off]))
28133+ return -EFAULT;
28134 err = ec_write(*off, byte_write);
28135 if (err)
28136 return err;
28137diff --git a/drivers/acpi/proc.c b/drivers/acpi/proc.c
28138index 251c7b62..000462d 100644
28139--- a/drivers/acpi/proc.c
28140+++ b/drivers/acpi/proc.c
28141@@ -343,19 +343,13 @@ acpi_system_write_wakeup_device(struct file *file,
28142 size_t count, loff_t * ppos)
28143 {
28144 struct list_head *node, *next;
28145- char strbuf[5];
28146- char str[5] = "";
28147- unsigned int len = count;
28148+ char strbuf[5] = {0};
28149
28150- if (len > 4)
28151- len = 4;
28152- if (len < 0)
28153+ if (count > 4)
28154+ count = 4;
28155+ if (copy_from_user(strbuf, buffer, count))
28156 return -EFAULT;
28157-
28158- if (copy_from_user(strbuf, buffer, len))
28159- return -EFAULT;
28160- strbuf[len] = '\0';
28161- sscanf(strbuf, "%s", str);
28162+ strbuf[count] = '\0';
28163
28164 mutex_lock(&acpi_device_lock);
28165 list_for_each_safe(node, next, &acpi_wakeup_device_list) {
28166@@ -364,7 +358,7 @@ acpi_system_write_wakeup_device(struct file *file,
28167 if (!dev->wakeup.flags.valid)
28168 continue;
28169
28170- if (!strncmp(dev->pnp.bus_id, str, 4)) {
28171+ if (!strncmp(dev->pnp.bus_id, strbuf, 4)) {
28172 if (device_can_wakeup(&dev->dev)) {
28173 bool enable = !device_may_wakeup(&dev->dev);
28174 device_set_wakeup_enable(&dev->dev, enable);
28175diff --git a/drivers/acpi/processor_driver.c b/drivers/acpi/processor_driver.c
28176index bfc31cb..8213ce1 100644
28177--- a/drivers/acpi/processor_driver.c
28178+++ b/drivers/acpi/processor_driver.c
28179@@ -551,7 +551,7 @@ static int __cpuinit acpi_processor_add(struct acpi_device *device)
28180 return 0;
28181 #endif
28182
28183- BUG_ON((pr->id >= nr_cpu_ids) || (pr->id < 0));
28184+ BUG_ON(pr->id >= nr_cpu_ids);
28185
28186 /*
28187 * Buggy BIOS check
28188diff --git a/drivers/ata/libata-core.c b/drivers/ata/libata-core.c
28189index 8e1039c..ea9cbd4 100644
28190--- a/drivers/ata/libata-core.c
28191+++ b/drivers/ata/libata-core.c
28192@@ -4750,7 +4750,7 @@ void ata_qc_free(struct ata_queued_cmd *qc)
28193 struct ata_port *ap;
28194 unsigned int tag;
28195
28196- WARN_ON_ONCE(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
28197+ BUG_ON(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
28198 ap = qc->ap;
28199
28200 qc->flags = 0;
28201@@ -4766,7 +4766,7 @@ void __ata_qc_complete(struct ata_queued_cmd *qc)
28202 struct ata_port *ap;
28203 struct ata_link *link;
28204
28205- WARN_ON_ONCE(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
28206+ BUG_ON(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
28207 WARN_ON_ONCE(!(qc->flags & ATA_QCFLAG_ACTIVE));
28208 ap = qc->ap;
28209 link = qc->dev->link;
28210@@ -5828,6 +5828,7 @@ static void ata_finalize_port_ops(struct ata_port_operations *ops)
28211 return;
28212
28213 spin_lock(&lock);
28214+ pax_open_kernel();
28215
28216 for (cur = ops->inherits; cur; cur = cur->inherits) {
28217 void **inherit = (void **)cur;
28218@@ -5841,8 +5842,9 @@ static void ata_finalize_port_ops(struct ata_port_operations *ops)
28219 if (IS_ERR(*pp))
28220 *pp = NULL;
28221
28222- ops->inherits = NULL;
28223+ *(struct ata_port_operations **)&ops->inherits = NULL;
28224
28225+ pax_close_kernel();
28226 spin_unlock(&lock);
28227 }
28228
28229diff --git a/drivers/ata/pata_arasan_cf.c b/drivers/ata/pata_arasan_cf.c
28230index bfaa5cb..3ba1cc3 100644
28231--- a/drivers/ata/pata_arasan_cf.c
28232+++ b/drivers/ata/pata_arasan_cf.c
28233@@ -854,7 +854,9 @@ static int __devinit arasan_cf_probe(struct platform_device *pdev)
28234 /* Handle platform specific quirks */
28235 if (pdata->quirk) {
28236 if (pdata->quirk & CF_BROKEN_PIO) {
28237- ap->ops->set_piomode = NULL;
28238+ pax_open_kernel();
28239+ *(void **)&ap->ops->set_piomode = NULL;
28240+ pax_close_kernel();
28241 ap->pio_mask = 0;
28242 }
28243 if (pdata->quirk & CF_BROKEN_MWDMA)
28244diff --git a/drivers/atm/adummy.c b/drivers/atm/adummy.c
28245index f9b983a..887b9d8 100644
28246--- a/drivers/atm/adummy.c
28247+++ b/drivers/atm/adummy.c
28248@@ -114,7 +114,7 @@ adummy_send(struct atm_vcc *vcc, struct sk_buff *skb)
28249 vcc->pop(vcc, skb);
28250 else
28251 dev_kfree_skb_any(skb);
28252- atomic_inc(&vcc->stats->tx);
28253+ atomic_inc_unchecked(&vcc->stats->tx);
28254
28255 return 0;
28256 }
28257diff --git a/drivers/atm/ambassador.c b/drivers/atm/ambassador.c
28258index 89b30f3..7964211 100644
28259--- a/drivers/atm/ambassador.c
28260+++ b/drivers/atm/ambassador.c
28261@@ -454,7 +454,7 @@ static void tx_complete (amb_dev * dev, tx_out * tx) {
28262 PRINTD (DBG_FLOW|DBG_TX, "tx_complete %p %p", dev, tx);
28263
28264 // VC layer stats
28265- atomic_inc(&ATM_SKB(skb)->vcc->stats->tx);
28266+ atomic_inc_unchecked(&ATM_SKB(skb)->vcc->stats->tx);
28267
28268 // free the descriptor
28269 kfree (tx_descr);
28270@@ -495,7 +495,7 @@ static void rx_complete (amb_dev * dev, rx_out * rx) {
28271 dump_skb ("<<<", vc, skb);
28272
28273 // VC layer stats
28274- atomic_inc(&atm_vcc->stats->rx);
28275+ atomic_inc_unchecked(&atm_vcc->stats->rx);
28276 __net_timestamp(skb);
28277 // end of our responsibility
28278 atm_vcc->push (atm_vcc, skb);
28279@@ -510,7 +510,7 @@ static void rx_complete (amb_dev * dev, rx_out * rx) {
28280 } else {
28281 PRINTK (KERN_INFO, "dropped over-size frame");
28282 // should we count this?
28283- atomic_inc(&atm_vcc->stats->rx_drop);
28284+ atomic_inc_unchecked(&atm_vcc->stats->rx_drop);
28285 }
28286
28287 } else {
28288@@ -1338,7 +1338,7 @@ static int amb_send (struct atm_vcc * atm_vcc, struct sk_buff * skb) {
28289 }
28290
28291 if (check_area (skb->data, skb->len)) {
28292- atomic_inc(&atm_vcc->stats->tx_err);
28293+ atomic_inc_unchecked(&atm_vcc->stats->tx_err);
28294 return -ENOMEM; // ?
28295 }
28296
28297diff --git a/drivers/atm/atmtcp.c b/drivers/atm/atmtcp.c
28298index b22d71c..d6e1049 100644
28299--- a/drivers/atm/atmtcp.c
28300+++ b/drivers/atm/atmtcp.c
28301@@ -207,7 +207,7 @@ static int atmtcp_v_send(struct atm_vcc *vcc,struct sk_buff *skb)
28302 if (vcc->pop) vcc->pop(vcc,skb);
28303 else dev_kfree_skb(skb);
28304 if (dev_data) return 0;
28305- atomic_inc(&vcc->stats->tx_err);
28306+ atomic_inc_unchecked(&vcc->stats->tx_err);
28307 return -ENOLINK;
28308 }
28309 size = skb->len+sizeof(struct atmtcp_hdr);
28310@@ -215,7 +215,7 @@ static int atmtcp_v_send(struct atm_vcc *vcc,struct sk_buff *skb)
28311 if (!new_skb) {
28312 if (vcc->pop) vcc->pop(vcc,skb);
28313 else dev_kfree_skb(skb);
28314- atomic_inc(&vcc->stats->tx_err);
28315+ atomic_inc_unchecked(&vcc->stats->tx_err);
28316 return -ENOBUFS;
28317 }
28318 hdr = (void *) skb_put(new_skb,sizeof(struct atmtcp_hdr));
28319@@ -226,8 +226,8 @@ static int atmtcp_v_send(struct atm_vcc *vcc,struct sk_buff *skb)
28320 if (vcc->pop) vcc->pop(vcc,skb);
28321 else dev_kfree_skb(skb);
28322 out_vcc->push(out_vcc,new_skb);
28323- atomic_inc(&vcc->stats->tx);
28324- atomic_inc(&out_vcc->stats->rx);
28325+ atomic_inc_unchecked(&vcc->stats->tx);
28326+ atomic_inc_unchecked(&out_vcc->stats->rx);
28327 return 0;
28328 }
28329
28330@@ -301,7 +301,7 @@ static int atmtcp_c_send(struct atm_vcc *vcc,struct sk_buff *skb)
28331 out_vcc = find_vcc(dev, ntohs(hdr->vpi), ntohs(hdr->vci));
28332 read_unlock(&vcc_sklist_lock);
28333 if (!out_vcc) {
28334- atomic_inc(&vcc->stats->tx_err);
28335+ atomic_inc_unchecked(&vcc->stats->tx_err);
28336 goto done;
28337 }
28338 skb_pull(skb,sizeof(struct atmtcp_hdr));
28339@@ -313,8 +313,8 @@ static int atmtcp_c_send(struct atm_vcc *vcc,struct sk_buff *skb)
28340 __net_timestamp(new_skb);
28341 skb_copy_from_linear_data(skb, skb_put(new_skb, skb->len), skb->len);
28342 out_vcc->push(out_vcc,new_skb);
28343- atomic_inc(&vcc->stats->tx);
28344- atomic_inc(&out_vcc->stats->rx);
28345+ atomic_inc_unchecked(&vcc->stats->tx);
28346+ atomic_inc_unchecked(&out_vcc->stats->rx);
28347 done:
28348 if (vcc->pop) vcc->pop(vcc,skb);
28349 else dev_kfree_skb(skb);
28350diff --git a/drivers/atm/eni.c b/drivers/atm/eni.c
28351index 2059ee4..faf51c7 100644
28352--- a/drivers/atm/eni.c
28353+++ b/drivers/atm/eni.c
28354@@ -522,7 +522,7 @@ static int rx_aal0(struct atm_vcc *vcc)
28355 DPRINTK(DEV_LABEL "(itf %d): trashing empty cell\n",
28356 vcc->dev->number);
28357 length = 0;
28358- atomic_inc(&vcc->stats->rx_err);
28359+ atomic_inc_unchecked(&vcc->stats->rx_err);
28360 }
28361 else {
28362 length = ATM_CELL_SIZE-1; /* no HEC */
28363@@ -577,7 +577,7 @@ static int rx_aal5(struct atm_vcc *vcc)
28364 size);
28365 }
28366 eff = length = 0;
28367- atomic_inc(&vcc->stats->rx_err);
28368+ atomic_inc_unchecked(&vcc->stats->rx_err);
28369 }
28370 else {
28371 size = (descr & MID_RED_COUNT)*(ATM_CELL_PAYLOAD >> 2);
28372@@ -594,7 +594,7 @@ static int rx_aal5(struct atm_vcc *vcc)
28373 "(VCI=%d,length=%ld,size=%ld (descr 0x%lx))\n",
28374 vcc->dev->number,vcc->vci,length,size << 2,descr);
28375 length = eff = 0;
28376- atomic_inc(&vcc->stats->rx_err);
28377+ atomic_inc_unchecked(&vcc->stats->rx_err);
28378 }
28379 }
28380 skb = eff ? atm_alloc_charge(vcc,eff << 2,GFP_ATOMIC) : NULL;
28381@@ -767,7 +767,7 @@ rx_dequeued++;
28382 vcc->push(vcc,skb);
28383 pushed++;
28384 }
28385- atomic_inc(&vcc->stats->rx);
28386+ atomic_inc_unchecked(&vcc->stats->rx);
28387 }
28388 wake_up(&eni_dev->rx_wait);
28389 }
28390@@ -1227,7 +1227,7 @@ static void dequeue_tx(struct atm_dev *dev)
28391 PCI_DMA_TODEVICE);
28392 if (vcc->pop) vcc->pop(vcc,skb);
28393 else dev_kfree_skb_irq(skb);
28394- atomic_inc(&vcc->stats->tx);
28395+ atomic_inc_unchecked(&vcc->stats->tx);
28396 wake_up(&eni_dev->tx_wait);
28397 dma_complete++;
28398 }
28399@@ -1567,7 +1567,7 @@ tx_complete++;
28400 /*--------------------------------- entries ---------------------------------*/
28401
28402
28403-static const char *media_name[] __devinitdata = {
28404+static const char *media_name[] __devinitconst = {
28405 "MMF", "SMF", "MMF", "03?", /* 0- 3 */
28406 "UTP", "05?", "06?", "07?", /* 4- 7 */
28407 "TAXI","09?", "10?", "11?", /* 8-11 */
28408diff --git a/drivers/atm/firestream.c b/drivers/atm/firestream.c
28409index 86fed1b..6dc4721 100644
28410--- a/drivers/atm/firestream.c
28411+++ b/drivers/atm/firestream.c
28412@@ -749,7 +749,7 @@ static void process_txdone_queue (struct fs_dev *dev, struct queue *q)
28413 }
28414 }
28415
28416- atomic_inc(&ATM_SKB(skb)->vcc->stats->tx);
28417+ atomic_inc_unchecked(&ATM_SKB(skb)->vcc->stats->tx);
28418
28419 fs_dprintk (FS_DEBUG_TXMEM, "i");
28420 fs_dprintk (FS_DEBUG_ALLOC, "Free t-skb: %p\n", skb);
28421@@ -816,7 +816,7 @@ static void process_incoming (struct fs_dev *dev, struct queue *q)
28422 #endif
28423 skb_put (skb, qe->p1 & 0xffff);
28424 ATM_SKB(skb)->vcc = atm_vcc;
28425- atomic_inc(&atm_vcc->stats->rx);
28426+ atomic_inc_unchecked(&atm_vcc->stats->rx);
28427 __net_timestamp(skb);
28428 fs_dprintk (FS_DEBUG_ALLOC, "Free rec-skb: %p (pushed)\n", skb);
28429 atm_vcc->push (atm_vcc, skb);
28430@@ -837,12 +837,12 @@ static void process_incoming (struct fs_dev *dev, struct queue *q)
28431 kfree (pe);
28432 }
28433 if (atm_vcc)
28434- atomic_inc(&atm_vcc->stats->rx_drop);
28435+ atomic_inc_unchecked(&atm_vcc->stats->rx_drop);
28436 break;
28437 case 0x1f: /* Reassembly abort: no buffers. */
28438 /* Silently increment error counter. */
28439 if (atm_vcc)
28440- atomic_inc(&atm_vcc->stats->rx_drop);
28441+ atomic_inc_unchecked(&atm_vcc->stats->rx_drop);
28442 break;
28443 default: /* Hmm. Haven't written the code to handle the others yet... -- REW */
28444 printk (KERN_WARNING "Don't know what to do with RX status %x: %s.\n",
28445diff --git a/drivers/atm/fore200e.c b/drivers/atm/fore200e.c
28446index 361f5ae..7fc552d 100644
28447--- a/drivers/atm/fore200e.c
28448+++ b/drivers/atm/fore200e.c
28449@@ -933,9 +933,9 @@ fore200e_tx_irq(struct fore200e* fore200e)
28450 #endif
28451 /* check error condition */
28452 if (*entry->status & STATUS_ERROR)
28453- atomic_inc(&vcc->stats->tx_err);
28454+ atomic_inc_unchecked(&vcc->stats->tx_err);
28455 else
28456- atomic_inc(&vcc->stats->tx);
28457+ atomic_inc_unchecked(&vcc->stats->tx);
28458 }
28459 }
28460
28461@@ -1084,7 +1084,7 @@ fore200e_push_rpd(struct fore200e* fore200e, struct atm_vcc* vcc, struct rpd* rp
28462 if (skb == NULL) {
28463 DPRINTK(2, "unable to alloc new skb, rx PDU length = %d\n", pdu_len);
28464
28465- atomic_inc(&vcc->stats->rx_drop);
28466+ atomic_inc_unchecked(&vcc->stats->rx_drop);
28467 return -ENOMEM;
28468 }
28469
28470@@ -1127,14 +1127,14 @@ fore200e_push_rpd(struct fore200e* fore200e, struct atm_vcc* vcc, struct rpd* rp
28471
28472 dev_kfree_skb_any(skb);
28473
28474- atomic_inc(&vcc->stats->rx_drop);
28475+ atomic_inc_unchecked(&vcc->stats->rx_drop);
28476 return -ENOMEM;
28477 }
28478
28479 ASSERT(atomic_read(&sk_atm(vcc)->sk_wmem_alloc) >= 0);
28480
28481 vcc->push(vcc, skb);
28482- atomic_inc(&vcc->stats->rx);
28483+ atomic_inc_unchecked(&vcc->stats->rx);
28484
28485 ASSERT(atomic_read(&sk_atm(vcc)->sk_wmem_alloc) >= 0);
28486
28487@@ -1212,7 +1212,7 @@ fore200e_rx_irq(struct fore200e* fore200e)
28488 DPRINTK(2, "damaged PDU on %d.%d.%d\n",
28489 fore200e->atm_dev->number,
28490 entry->rpd->atm_header.vpi, entry->rpd->atm_header.vci);
28491- atomic_inc(&vcc->stats->rx_err);
28492+ atomic_inc_unchecked(&vcc->stats->rx_err);
28493 }
28494 }
28495
28496@@ -1657,7 +1657,7 @@ fore200e_send(struct atm_vcc *vcc, struct sk_buff *skb)
28497 goto retry_here;
28498 }
28499
28500- atomic_inc(&vcc->stats->tx_err);
28501+ atomic_inc_unchecked(&vcc->stats->tx_err);
28502
28503 fore200e->tx_sat++;
28504 DPRINTK(2, "tx queue of device %s is saturated, PDU dropped - heartbeat is %08x\n",
28505diff --git a/drivers/atm/he.c b/drivers/atm/he.c
28506index b182c2f..1c6fa8a 100644
28507--- a/drivers/atm/he.c
28508+++ b/drivers/atm/he.c
28509@@ -1709,7 +1709,7 @@ he_service_rbrq(struct he_dev *he_dev, int group)
28510
28511 if (RBRQ_HBUF_ERR(he_dev->rbrq_head)) {
28512 hprintk("HBUF_ERR! (cid 0x%x)\n", cid);
28513- atomic_inc(&vcc->stats->rx_drop);
28514+ atomic_inc_unchecked(&vcc->stats->rx_drop);
28515 goto return_host_buffers;
28516 }
28517
28518@@ -1736,7 +1736,7 @@ he_service_rbrq(struct he_dev *he_dev, int group)
28519 RBRQ_LEN_ERR(he_dev->rbrq_head)
28520 ? "LEN_ERR" : "",
28521 vcc->vpi, vcc->vci);
28522- atomic_inc(&vcc->stats->rx_err);
28523+ atomic_inc_unchecked(&vcc->stats->rx_err);
28524 goto return_host_buffers;
28525 }
28526
28527@@ -1788,7 +1788,7 @@ he_service_rbrq(struct he_dev *he_dev, int group)
28528 vcc->push(vcc, skb);
28529 spin_lock(&he_dev->global_lock);
28530
28531- atomic_inc(&vcc->stats->rx);
28532+ atomic_inc_unchecked(&vcc->stats->rx);
28533
28534 return_host_buffers:
28535 ++pdus_assembled;
28536@@ -2114,7 +2114,7 @@ __enqueue_tpd(struct he_dev *he_dev, struct he_tpd *tpd, unsigned cid)
28537 tpd->vcc->pop(tpd->vcc, tpd->skb);
28538 else
28539 dev_kfree_skb_any(tpd->skb);
28540- atomic_inc(&tpd->vcc->stats->tx_err);
28541+ atomic_inc_unchecked(&tpd->vcc->stats->tx_err);
28542 }
28543 pci_pool_free(he_dev->tpd_pool, tpd, TPD_ADDR(tpd->status));
28544 return;
28545@@ -2526,7 +2526,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
28546 vcc->pop(vcc, skb);
28547 else
28548 dev_kfree_skb_any(skb);
28549- atomic_inc(&vcc->stats->tx_err);
28550+ atomic_inc_unchecked(&vcc->stats->tx_err);
28551 return -EINVAL;
28552 }
28553
28554@@ -2537,7 +2537,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
28555 vcc->pop(vcc, skb);
28556 else
28557 dev_kfree_skb_any(skb);
28558- atomic_inc(&vcc->stats->tx_err);
28559+ atomic_inc_unchecked(&vcc->stats->tx_err);
28560 return -EINVAL;
28561 }
28562 #endif
28563@@ -2549,7 +2549,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
28564 vcc->pop(vcc, skb);
28565 else
28566 dev_kfree_skb_any(skb);
28567- atomic_inc(&vcc->stats->tx_err);
28568+ atomic_inc_unchecked(&vcc->stats->tx_err);
28569 spin_unlock_irqrestore(&he_dev->global_lock, flags);
28570 return -ENOMEM;
28571 }
28572@@ -2591,7 +2591,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
28573 vcc->pop(vcc, skb);
28574 else
28575 dev_kfree_skb_any(skb);
28576- atomic_inc(&vcc->stats->tx_err);
28577+ atomic_inc_unchecked(&vcc->stats->tx_err);
28578 spin_unlock_irqrestore(&he_dev->global_lock, flags);
28579 return -ENOMEM;
28580 }
28581@@ -2622,7 +2622,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
28582 __enqueue_tpd(he_dev, tpd, cid);
28583 spin_unlock_irqrestore(&he_dev->global_lock, flags);
28584
28585- atomic_inc(&vcc->stats->tx);
28586+ atomic_inc_unchecked(&vcc->stats->tx);
28587
28588 return 0;
28589 }
28590diff --git a/drivers/atm/horizon.c b/drivers/atm/horizon.c
28591index 7d01c2a..4e3ac01 100644
28592--- a/drivers/atm/horizon.c
28593+++ b/drivers/atm/horizon.c
28594@@ -1034,7 +1034,7 @@ static void rx_schedule (hrz_dev * dev, int irq) {
28595 {
28596 struct atm_vcc * vcc = ATM_SKB(skb)->vcc;
28597 // VC layer stats
28598- atomic_inc(&vcc->stats->rx);
28599+ atomic_inc_unchecked(&vcc->stats->rx);
28600 __net_timestamp(skb);
28601 // end of our responsibility
28602 vcc->push (vcc, skb);
28603@@ -1186,7 +1186,7 @@ static void tx_schedule (hrz_dev * const dev, int irq) {
28604 dev->tx_iovec = NULL;
28605
28606 // VC layer stats
28607- atomic_inc(&ATM_SKB(skb)->vcc->stats->tx);
28608+ atomic_inc_unchecked(&ATM_SKB(skb)->vcc->stats->tx);
28609
28610 // free the skb
28611 hrz_kfree_skb (skb);
28612diff --git a/drivers/atm/idt77252.c b/drivers/atm/idt77252.c
28613index 8974bd2..b856f85 100644
28614--- a/drivers/atm/idt77252.c
28615+++ b/drivers/atm/idt77252.c
28616@@ -812,7 +812,7 @@ drain_scq(struct idt77252_dev *card, struct vc_map *vc)
28617 else
28618 dev_kfree_skb(skb);
28619
28620- atomic_inc(&vcc->stats->tx);
28621+ atomic_inc_unchecked(&vcc->stats->tx);
28622 }
28623
28624 atomic_dec(&scq->used);
28625@@ -1075,13 +1075,13 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
28626 if ((sb = dev_alloc_skb(64)) == NULL) {
28627 printk("%s: Can't allocate buffers for aal0.\n",
28628 card->name);
28629- atomic_add(i, &vcc->stats->rx_drop);
28630+ atomic_add_unchecked(i, &vcc->stats->rx_drop);
28631 break;
28632 }
28633 if (!atm_charge(vcc, sb->truesize)) {
28634 RXPRINTK("%s: atm_charge() dropped aal0 packets.\n",
28635 card->name);
28636- atomic_add(i - 1, &vcc->stats->rx_drop);
28637+ atomic_add_unchecked(i - 1, &vcc->stats->rx_drop);
28638 dev_kfree_skb(sb);
28639 break;
28640 }
28641@@ -1098,7 +1098,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
28642 ATM_SKB(sb)->vcc = vcc;
28643 __net_timestamp(sb);
28644 vcc->push(vcc, sb);
28645- atomic_inc(&vcc->stats->rx);
28646+ atomic_inc_unchecked(&vcc->stats->rx);
28647
28648 cell += ATM_CELL_PAYLOAD;
28649 }
28650@@ -1135,13 +1135,13 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
28651 "(CDC: %08x)\n",
28652 card->name, len, rpp->len, readl(SAR_REG_CDC));
28653 recycle_rx_pool_skb(card, rpp);
28654- atomic_inc(&vcc->stats->rx_err);
28655+ atomic_inc_unchecked(&vcc->stats->rx_err);
28656 return;
28657 }
28658 if (stat & SAR_RSQE_CRC) {
28659 RXPRINTK("%s: AAL5 CRC error.\n", card->name);
28660 recycle_rx_pool_skb(card, rpp);
28661- atomic_inc(&vcc->stats->rx_err);
28662+ atomic_inc_unchecked(&vcc->stats->rx_err);
28663 return;
28664 }
28665 if (skb_queue_len(&rpp->queue) > 1) {
28666@@ -1152,7 +1152,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
28667 RXPRINTK("%s: Can't alloc RX skb.\n",
28668 card->name);
28669 recycle_rx_pool_skb(card, rpp);
28670- atomic_inc(&vcc->stats->rx_err);
28671+ atomic_inc_unchecked(&vcc->stats->rx_err);
28672 return;
28673 }
28674 if (!atm_charge(vcc, skb->truesize)) {
28675@@ -1171,7 +1171,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
28676 __net_timestamp(skb);
28677
28678 vcc->push(vcc, skb);
28679- atomic_inc(&vcc->stats->rx);
28680+ atomic_inc_unchecked(&vcc->stats->rx);
28681
28682 return;
28683 }
28684@@ -1193,7 +1193,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
28685 __net_timestamp(skb);
28686
28687 vcc->push(vcc, skb);
28688- atomic_inc(&vcc->stats->rx);
28689+ atomic_inc_unchecked(&vcc->stats->rx);
28690
28691 if (skb->truesize > SAR_FB_SIZE_3)
28692 add_rx_skb(card, 3, SAR_FB_SIZE_3, 1);
28693@@ -1304,14 +1304,14 @@ idt77252_rx_raw(struct idt77252_dev *card)
28694 if (vcc->qos.aal != ATM_AAL0) {
28695 RPRINTK("%s: raw cell for non AAL0 vc %u.%u\n",
28696 card->name, vpi, vci);
28697- atomic_inc(&vcc->stats->rx_drop);
28698+ atomic_inc_unchecked(&vcc->stats->rx_drop);
28699 goto drop;
28700 }
28701
28702 if ((sb = dev_alloc_skb(64)) == NULL) {
28703 printk("%s: Can't allocate buffers for AAL0.\n",
28704 card->name);
28705- atomic_inc(&vcc->stats->rx_err);
28706+ atomic_inc_unchecked(&vcc->stats->rx_err);
28707 goto drop;
28708 }
28709
28710@@ -1330,7 +1330,7 @@ idt77252_rx_raw(struct idt77252_dev *card)
28711 ATM_SKB(sb)->vcc = vcc;
28712 __net_timestamp(sb);
28713 vcc->push(vcc, sb);
28714- atomic_inc(&vcc->stats->rx);
28715+ atomic_inc_unchecked(&vcc->stats->rx);
28716
28717 drop:
28718 skb_pull(queue, 64);
28719@@ -1955,13 +1955,13 @@ idt77252_send_skb(struct atm_vcc *vcc, struct sk_buff *skb, int oam)
28720
28721 if (vc == NULL) {
28722 printk("%s: NULL connection in send().\n", card->name);
28723- atomic_inc(&vcc->stats->tx_err);
28724+ atomic_inc_unchecked(&vcc->stats->tx_err);
28725 dev_kfree_skb(skb);
28726 return -EINVAL;
28727 }
28728 if (!test_bit(VCF_TX, &vc->flags)) {
28729 printk("%s: Trying to transmit on a non-tx VC.\n", card->name);
28730- atomic_inc(&vcc->stats->tx_err);
28731+ atomic_inc_unchecked(&vcc->stats->tx_err);
28732 dev_kfree_skb(skb);
28733 return -EINVAL;
28734 }
28735@@ -1973,14 +1973,14 @@ idt77252_send_skb(struct atm_vcc *vcc, struct sk_buff *skb, int oam)
28736 break;
28737 default:
28738 printk("%s: Unsupported AAL: %d\n", card->name, vcc->qos.aal);
28739- atomic_inc(&vcc->stats->tx_err);
28740+ atomic_inc_unchecked(&vcc->stats->tx_err);
28741 dev_kfree_skb(skb);
28742 return -EINVAL;
28743 }
28744
28745 if (skb_shinfo(skb)->nr_frags != 0) {
28746 printk("%s: No scatter-gather yet.\n", card->name);
28747- atomic_inc(&vcc->stats->tx_err);
28748+ atomic_inc_unchecked(&vcc->stats->tx_err);
28749 dev_kfree_skb(skb);
28750 return -EINVAL;
28751 }
28752@@ -1988,7 +1988,7 @@ idt77252_send_skb(struct atm_vcc *vcc, struct sk_buff *skb, int oam)
28753
28754 err = queue_skb(card, vc, skb, oam);
28755 if (err) {
28756- atomic_inc(&vcc->stats->tx_err);
28757+ atomic_inc_unchecked(&vcc->stats->tx_err);
28758 dev_kfree_skb(skb);
28759 return err;
28760 }
28761@@ -2011,7 +2011,7 @@ idt77252_send_oam(struct atm_vcc *vcc, void *cell, int flags)
28762 skb = dev_alloc_skb(64);
28763 if (!skb) {
28764 printk("%s: Out of memory in send_oam().\n", card->name);
28765- atomic_inc(&vcc->stats->tx_err);
28766+ atomic_inc_unchecked(&vcc->stats->tx_err);
28767 return -ENOMEM;
28768 }
28769 atomic_add(skb->truesize, &sk_atm(vcc)->sk_wmem_alloc);
28770diff --git a/drivers/atm/iphase.c b/drivers/atm/iphase.c
28771index 96cce6d..62c3ec5 100644
28772--- a/drivers/atm/iphase.c
28773+++ b/drivers/atm/iphase.c
28774@@ -1145,7 +1145,7 @@ static int rx_pkt(struct atm_dev *dev)
28775 status = (u_short) (buf_desc_ptr->desc_mode);
28776 if (status & (RX_CER | RX_PTE | RX_OFL))
28777 {
28778- atomic_inc(&vcc->stats->rx_err);
28779+ atomic_inc_unchecked(&vcc->stats->rx_err);
28780 IF_ERR(printk("IA: bad packet, dropping it");)
28781 if (status & RX_CER) {
28782 IF_ERR(printk(" cause: packet CRC error\n");)
28783@@ -1168,7 +1168,7 @@ static int rx_pkt(struct atm_dev *dev)
28784 len = dma_addr - buf_addr;
28785 if (len > iadev->rx_buf_sz) {
28786 printk("Over %d bytes sdu received, dropped!!!\n", iadev->rx_buf_sz);
28787- atomic_inc(&vcc->stats->rx_err);
28788+ atomic_inc_unchecked(&vcc->stats->rx_err);
28789 goto out_free_desc;
28790 }
28791
28792@@ -1318,7 +1318,7 @@ static void rx_dle_intr(struct atm_dev *dev)
28793 ia_vcc = INPH_IA_VCC(vcc);
28794 if (ia_vcc == NULL)
28795 {
28796- atomic_inc(&vcc->stats->rx_err);
28797+ atomic_inc_unchecked(&vcc->stats->rx_err);
28798 atm_return(vcc, skb->truesize);
28799 dev_kfree_skb_any(skb);
28800 goto INCR_DLE;
28801@@ -1330,7 +1330,7 @@ static void rx_dle_intr(struct atm_dev *dev)
28802 if ((length > iadev->rx_buf_sz) || (length >
28803 (skb->len - sizeof(struct cpcs_trailer))))
28804 {
28805- atomic_inc(&vcc->stats->rx_err);
28806+ atomic_inc_unchecked(&vcc->stats->rx_err);
28807 IF_ERR(printk("rx_dle_intr: Bad AAL5 trailer %d (skb len %d)",
28808 length, skb->len);)
28809 atm_return(vcc, skb->truesize);
28810@@ -1346,7 +1346,7 @@ static void rx_dle_intr(struct atm_dev *dev)
28811
28812 IF_RX(printk("rx_dle_intr: skb push");)
28813 vcc->push(vcc,skb);
28814- atomic_inc(&vcc->stats->rx);
28815+ atomic_inc_unchecked(&vcc->stats->rx);
28816 iadev->rx_pkt_cnt++;
28817 }
28818 INCR_DLE:
28819@@ -2826,15 +2826,15 @@ static int ia_ioctl(struct atm_dev *dev, unsigned int cmd, void __user *arg)
28820 {
28821 struct k_sonet_stats *stats;
28822 stats = &PRIV(_ia_dev[board])->sonet_stats;
28823- printk("section_bip: %d\n", atomic_read(&stats->section_bip));
28824- printk("line_bip : %d\n", atomic_read(&stats->line_bip));
28825- printk("path_bip : %d\n", atomic_read(&stats->path_bip));
28826- printk("line_febe : %d\n", atomic_read(&stats->line_febe));
28827- printk("path_febe : %d\n", atomic_read(&stats->path_febe));
28828- printk("corr_hcs : %d\n", atomic_read(&stats->corr_hcs));
28829- printk("uncorr_hcs : %d\n", atomic_read(&stats->uncorr_hcs));
28830- printk("tx_cells : %d\n", atomic_read(&stats->tx_cells));
28831- printk("rx_cells : %d\n", atomic_read(&stats->rx_cells));
28832+ printk("section_bip: %d\n", atomic_read_unchecked(&stats->section_bip));
28833+ printk("line_bip : %d\n", atomic_read_unchecked(&stats->line_bip));
28834+ printk("path_bip : %d\n", atomic_read_unchecked(&stats->path_bip));
28835+ printk("line_febe : %d\n", atomic_read_unchecked(&stats->line_febe));
28836+ printk("path_febe : %d\n", atomic_read_unchecked(&stats->path_febe));
28837+ printk("corr_hcs : %d\n", atomic_read_unchecked(&stats->corr_hcs));
28838+ printk("uncorr_hcs : %d\n", atomic_read_unchecked(&stats->uncorr_hcs));
28839+ printk("tx_cells : %d\n", atomic_read_unchecked(&stats->tx_cells));
28840+ printk("rx_cells : %d\n", atomic_read_unchecked(&stats->rx_cells));
28841 }
28842 ia_cmds.status = 0;
28843 break;
28844@@ -2939,7 +2939,7 @@ static int ia_pkt_tx (struct atm_vcc *vcc, struct sk_buff *skb) {
28845 if ((desc == 0) || (desc > iadev->num_tx_desc))
28846 {
28847 IF_ERR(printk(DEV_LABEL "invalid desc for send: %d\n", desc);)
28848- atomic_inc(&vcc->stats->tx);
28849+ atomic_inc_unchecked(&vcc->stats->tx);
28850 if (vcc->pop)
28851 vcc->pop(vcc, skb);
28852 else
28853@@ -3044,14 +3044,14 @@ static int ia_pkt_tx (struct atm_vcc *vcc, struct sk_buff *skb) {
28854 ATM_DESC(skb) = vcc->vci;
28855 skb_queue_tail(&iadev->tx_dma_q, skb);
28856
28857- atomic_inc(&vcc->stats->tx);
28858+ atomic_inc_unchecked(&vcc->stats->tx);
28859 iadev->tx_pkt_cnt++;
28860 /* Increment transaction counter */
28861 writel(2, iadev->dma+IPHASE5575_TX_COUNTER);
28862
28863 #if 0
28864 /* add flow control logic */
28865- if (atomic_read(&vcc->stats->tx) % 20 == 0) {
28866+ if (atomic_read_unchecked(&vcc->stats->tx) % 20 == 0) {
28867 if (iavcc->vc_desc_cnt > 10) {
28868 vcc->tx_quota = vcc->tx_quota * 3 / 4;
28869 printk("Tx1: vcc->tx_quota = %d \n", (u32)vcc->tx_quota );
28870diff --git a/drivers/atm/lanai.c b/drivers/atm/lanai.c
28871index 68c7588..7036683 100644
28872--- a/drivers/atm/lanai.c
28873+++ b/drivers/atm/lanai.c
28874@@ -1303,7 +1303,7 @@ static void lanai_send_one_aal5(struct lanai_dev *lanai,
28875 vcc_tx_add_aal5_trailer(lvcc, skb->len, 0, 0);
28876 lanai_endtx(lanai, lvcc);
28877 lanai_free_skb(lvcc->tx.atmvcc, skb);
28878- atomic_inc(&lvcc->tx.atmvcc->stats->tx);
28879+ atomic_inc_unchecked(&lvcc->tx.atmvcc->stats->tx);
28880 }
28881
28882 /* Try to fill the buffer - don't call unless there is backlog */
28883@@ -1426,7 +1426,7 @@ static void vcc_rx_aal5(struct lanai_vcc *lvcc, int endptr)
28884 ATM_SKB(skb)->vcc = lvcc->rx.atmvcc;
28885 __net_timestamp(skb);
28886 lvcc->rx.atmvcc->push(lvcc->rx.atmvcc, skb);
28887- atomic_inc(&lvcc->rx.atmvcc->stats->rx);
28888+ atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx);
28889 out:
28890 lvcc->rx.buf.ptr = end;
28891 cardvcc_write(lvcc, endptr, vcc_rxreadptr);
28892@@ -1667,7 +1667,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
28893 DPRINTK("(itf %d) got RX service entry 0x%X for non-AAL5 "
28894 "vcc %d\n", lanai->number, (unsigned int) s, vci);
28895 lanai->stats.service_rxnotaal5++;
28896- atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
28897+ atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
28898 return 0;
28899 }
28900 if (likely(!(s & (SERVICE_TRASH | SERVICE_STREAM | SERVICE_CRCERR)))) {
28901@@ -1679,7 +1679,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
28902 int bytes;
28903 read_unlock(&vcc_sklist_lock);
28904 DPRINTK("got trashed rx pdu on vci %d\n", vci);
28905- atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
28906+ atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
28907 lvcc->stats.x.aal5.service_trash++;
28908 bytes = (SERVICE_GET_END(s) * 16) -
28909 (((unsigned long) lvcc->rx.buf.ptr) -
28910@@ -1691,7 +1691,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
28911 }
28912 if (s & SERVICE_STREAM) {
28913 read_unlock(&vcc_sklist_lock);
28914- atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
28915+ atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
28916 lvcc->stats.x.aal5.service_stream++;
28917 printk(KERN_ERR DEV_LABEL "(itf %d): Got AAL5 stream "
28918 "PDU on VCI %d!\n", lanai->number, vci);
28919@@ -1699,7 +1699,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
28920 return 0;
28921 }
28922 DPRINTK("got rx crc error on vci %d\n", vci);
28923- atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
28924+ atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
28925 lvcc->stats.x.aal5.service_rxcrc++;
28926 lvcc->rx.buf.ptr = &lvcc->rx.buf.start[SERVICE_GET_END(s) * 4];
28927 cardvcc_write(lvcc, SERVICE_GET_END(s), vcc_rxreadptr);
28928diff --git a/drivers/atm/nicstar.c b/drivers/atm/nicstar.c
28929index 1c70c45..300718d 100644
28930--- a/drivers/atm/nicstar.c
28931+++ b/drivers/atm/nicstar.c
28932@@ -1654,7 +1654,7 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
28933 if ((vc = (vc_map *) vcc->dev_data) == NULL) {
28934 printk("nicstar%d: vcc->dev_data == NULL on ns_send().\n",
28935 card->index);
28936- atomic_inc(&vcc->stats->tx_err);
28937+ atomic_inc_unchecked(&vcc->stats->tx_err);
28938 dev_kfree_skb_any(skb);
28939 return -EINVAL;
28940 }
28941@@ -1662,7 +1662,7 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
28942 if (!vc->tx) {
28943 printk("nicstar%d: Trying to transmit on a non-tx VC.\n",
28944 card->index);
28945- atomic_inc(&vcc->stats->tx_err);
28946+ atomic_inc_unchecked(&vcc->stats->tx_err);
28947 dev_kfree_skb_any(skb);
28948 return -EINVAL;
28949 }
28950@@ -1670,14 +1670,14 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
28951 if (vcc->qos.aal != ATM_AAL5 && vcc->qos.aal != ATM_AAL0) {
28952 printk("nicstar%d: Only AAL0 and AAL5 are supported.\n",
28953 card->index);
28954- atomic_inc(&vcc->stats->tx_err);
28955+ atomic_inc_unchecked(&vcc->stats->tx_err);
28956 dev_kfree_skb_any(skb);
28957 return -EINVAL;
28958 }
28959
28960 if (skb_shinfo(skb)->nr_frags != 0) {
28961 printk("nicstar%d: No scatter-gather yet.\n", card->index);
28962- atomic_inc(&vcc->stats->tx_err);
28963+ atomic_inc_unchecked(&vcc->stats->tx_err);
28964 dev_kfree_skb_any(skb);
28965 return -EINVAL;
28966 }
28967@@ -1725,11 +1725,11 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
28968 }
28969
28970 if (push_scqe(card, vc, scq, &scqe, skb) != 0) {
28971- atomic_inc(&vcc->stats->tx_err);
28972+ atomic_inc_unchecked(&vcc->stats->tx_err);
28973 dev_kfree_skb_any(skb);
28974 return -EIO;
28975 }
28976- atomic_inc(&vcc->stats->tx);
28977+ atomic_inc_unchecked(&vcc->stats->tx);
28978
28979 return 0;
28980 }
28981@@ -2046,14 +2046,14 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28982 printk
28983 ("nicstar%d: Can't allocate buffers for aal0.\n",
28984 card->index);
28985- atomic_add(i, &vcc->stats->rx_drop);
28986+ atomic_add_unchecked(i, &vcc->stats->rx_drop);
28987 break;
28988 }
28989 if (!atm_charge(vcc, sb->truesize)) {
28990 RXPRINTK
28991 ("nicstar%d: atm_charge() dropped aal0 packets.\n",
28992 card->index);
28993- atomic_add(i - 1, &vcc->stats->rx_drop); /* already increased by 1 */
28994+ atomic_add_unchecked(i - 1, &vcc->stats->rx_drop); /* already increased by 1 */
28995 dev_kfree_skb_any(sb);
28996 break;
28997 }
28998@@ -2068,7 +2068,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28999 ATM_SKB(sb)->vcc = vcc;
29000 __net_timestamp(sb);
29001 vcc->push(vcc, sb);
29002- atomic_inc(&vcc->stats->rx);
29003+ atomic_inc_unchecked(&vcc->stats->rx);
29004 cell += ATM_CELL_PAYLOAD;
29005 }
29006
29007@@ -2085,7 +2085,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
29008 if (iovb == NULL) {
29009 printk("nicstar%d: Out of iovec buffers.\n",
29010 card->index);
29011- atomic_inc(&vcc->stats->rx_drop);
29012+ atomic_inc_unchecked(&vcc->stats->rx_drop);
29013 recycle_rx_buf(card, skb);
29014 return;
29015 }
29016@@ -2109,7 +2109,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
29017 small or large buffer itself. */
29018 } else if (NS_PRV_IOVCNT(iovb) >= NS_MAX_IOVECS) {
29019 printk("nicstar%d: received too big AAL5 SDU.\n", card->index);
29020- atomic_inc(&vcc->stats->rx_err);
29021+ atomic_inc_unchecked(&vcc->stats->rx_err);
29022 recycle_iovec_rx_bufs(card, (struct iovec *)iovb->data,
29023 NS_MAX_IOVECS);
29024 NS_PRV_IOVCNT(iovb) = 0;
29025@@ -2129,7 +2129,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
29026 ("nicstar%d: Expected a small buffer, and this is not one.\n",
29027 card->index);
29028 which_list(card, skb);
29029- atomic_inc(&vcc->stats->rx_err);
29030+ atomic_inc_unchecked(&vcc->stats->rx_err);
29031 recycle_rx_buf(card, skb);
29032 vc->rx_iov = NULL;
29033 recycle_iov_buf(card, iovb);
29034@@ -2142,7 +2142,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
29035 ("nicstar%d: Expected a large buffer, and this is not one.\n",
29036 card->index);
29037 which_list(card, skb);
29038- atomic_inc(&vcc->stats->rx_err);
29039+ atomic_inc_unchecked(&vcc->stats->rx_err);
29040 recycle_iovec_rx_bufs(card, (struct iovec *)iovb->data,
29041 NS_PRV_IOVCNT(iovb));
29042 vc->rx_iov = NULL;
29043@@ -2165,7 +2165,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
29044 printk(" - PDU size mismatch.\n");
29045 else
29046 printk(".\n");
29047- atomic_inc(&vcc->stats->rx_err);
29048+ atomic_inc_unchecked(&vcc->stats->rx_err);
29049 recycle_iovec_rx_bufs(card, (struct iovec *)iovb->data,
29050 NS_PRV_IOVCNT(iovb));
29051 vc->rx_iov = NULL;
29052@@ -2179,7 +2179,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
29053 /* skb points to a small buffer */
29054 if (!atm_charge(vcc, skb->truesize)) {
29055 push_rxbufs(card, skb);
29056- atomic_inc(&vcc->stats->rx_drop);
29057+ atomic_inc_unchecked(&vcc->stats->rx_drop);
29058 } else {
29059 skb_put(skb, len);
29060 dequeue_sm_buf(card, skb);
29061@@ -2189,7 +2189,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
29062 ATM_SKB(skb)->vcc = vcc;
29063 __net_timestamp(skb);
29064 vcc->push(vcc, skb);
29065- atomic_inc(&vcc->stats->rx);
29066+ atomic_inc_unchecked(&vcc->stats->rx);
29067 }
29068 } else if (NS_PRV_IOVCNT(iovb) == 2) { /* One small plus one large buffer */
29069 struct sk_buff *sb;
29070@@ -2200,7 +2200,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
29071 if (len <= NS_SMBUFSIZE) {
29072 if (!atm_charge(vcc, sb->truesize)) {
29073 push_rxbufs(card, sb);
29074- atomic_inc(&vcc->stats->rx_drop);
29075+ atomic_inc_unchecked(&vcc->stats->rx_drop);
29076 } else {
29077 skb_put(sb, len);
29078 dequeue_sm_buf(card, sb);
29079@@ -2210,7 +2210,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
29080 ATM_SKB(sb)->vcc = vcc;
29081 __net_timestamp(sb);
29082 vcc->push(vcc, sb);
29083- atomic_inc(&vcc->stats->rx);
29084+ atomic_inc_unchecked(&vcc->stats->rx);
29085 }
29086
29087 push_rxbufs(card, skb);
29088@@ -2219,7 +2219,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
29089
29090 if (!atm_charge(vcc, skb->truesize)) {
29091 push_rxbufs(card, skb);
29092- atomic_inc(&vcc->stats->rx_drop);
29093+ atomic_inc_unchecked(&vcc->stats->rx_drop);
29094 } else {
29095 dequeue_lg_buf(card, skb);
29096 #ifdef NS_USE_DESTRUCTORS
29097@@ -2232,7 +2232,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
29098 ATM_SKB(skb)->vcc = vcc;
29099 __net_timestamp(skb);
29100 vcc->push(vcc, skb);
29101- atomic_inc(&vcc->stats->rx);
29102+ atomic_inc_unchecked(&vcc->stats->rx);
29103 }
29104
29105 push_rxbufs(card, sb);
29106@@ -2253,7 +2253,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
29107 printk
29108 ("nicstar%d: Out of huge buffers.\n",
29109 card->index);
29110- atomic_inc(&vcc->stats->rx_drop);
29111+ atomic_inc_unchecked(&vcc->stats->rx_drop);
29112 recycle_iovec_rx_bufs(card,
29113 (struct iovec *)
29114 iovb->data,
29115@@ -2304,7 +2304,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
29116 card->hbpool.count++;
29117 } else
29118 dev_kfree_skb_any(hb);
29119- atomic_inc(&vcc->stats->rx_drop);
29120+ atomic_inc_unchecked(&vcc->stats->rx_drop);
29121 } else {
29122 /* Copy the small buffer to the huge buffer */
29123 sb = (struct sk_buff *)iov->iov_base;
29124@@ -2341,7 +2341,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
29125 #endif /* NS_USE_DESTRUCTORS */
29126 __net_timestamp(hb);
29127 vcc->push(vcc, hb);
29128- atomic_inc(&vcc->stats->rx);
29129+ atomic_inc_unchecked(&vcc->stats->rx);
29130 }
29131 }
29132
29133diff --git a/drivers/atm/solos-pci.c b/drivers/atm/solos-pci.c
29134index 9851093..adb2b1e 100644
29135--- a/drivers/atm/solos-pci.c
29136+++ b/drivers/atm/solos-pci.c
29137@@ -714,7 +714,7 @@ void solos_bh(unsigned long card_arg)
29138 }
29139 atm_charge(vcc, skb->truesize);
29140 vcc->push(vcc, skb);
29141- atomic_inc(&vcc->stats->rx);
29142+ atomic_inc_unchecked(&vcc->stats->rx);
29143 break;
29144
29145 case PKT_STATUS:
29146@@ -1009,7 +1009,7 @@ static uint32_t fpga_tx(struct solos_card *card)
29147 vcc = SKB_CB(oldskb)->vcc;
29148
29149 if (vcc) {
29150- atomic_inc(&vcc->stats->tx);
29151+ atomic_inc_unchecked(&vcc->stats->tx);
29152 solos_pop(vcc, oldskb);
29153 } else
29154 dev_kfree_skb_irq(oldskb);
29155diff --git a/drivers/atm/suni.c b/drivers/atm/suni.c
29156index 0215934..ce9f5b1 100644
29157--- a/drivers/atm/suni.c
29158+++ b/drivers/atm/suni.c
29159@@ -49,8 +49,8 @@ static DEFINE_SPINLOCK(sunis_lock);
29160
29161
29162 #define ADD_LIMITED(s,v) \
29163- atomic_add((v),&stats->s); \
29164- if (atomic_read(&stats->s) < 0) atomic_set(&stats->s,INT_MAX);
29165+ atomic_add_unchecked((v),&stats->s); \
29166+ if (atomic_read_unchecked(&stats->s) < 0) atomic_set_unchecked(&stats->s,INT_MAX);
29167
29168
29169 static void suni_hz(unsigned long from_timer)
29170diff --git a/drivers/atm/uPD98402.c b/drivers/atm/uPD98402.c
29171index 5120a96..e2572bd 100644
29172--- a/drivers/atm/uPD98402.c
29173+++ b/drivers/atm/uPD98402.c
29174@@ -42,7 +42,7 @@ static int fetch_stats(struct atm_dev *dev,struct sonet_stats __user *arg,int ze
29175 struct sonet_stats tmp;
29176 int error = 0;
29177
29178- atomic_add(GET(HECCT),&PRIV(dev)->sonet_stats.uncorr_hcs);
29179+ atomic_add_unchecked(GET(HECCT),&PRIV(dev)->sonet_stats.uncorr_hcs);
29180 sonet_copy_stats(&PRIV(dev)->sonet_stats,&tmp);
29181 if (arg) error = copy_to_user(arg,&tmp,sizeof(tmp));
29182 if (zero && !error) {
29183@@ -161,9 +161,9 @@ static int uPD98402_ioctl(struct atm_dev *dev,unsigned int cmd,void __user *arg)
29184
29185
29186 #define ADD_LIMITED(s,v) \
29187- { atomic_add(GET(v),&PRIV(dev)->sonet_stats.s); \
29188- if (atomic_read(&PRIV(dev)->sonet_stats.s) < 0) \
29189- atomic_set(&PRIV(dev)->sonet_stats.s,INT_MAX); }
29190+ { atomic_add_unchecked(GET(v),&PRIV(dev)->sonet_stats.s); \
29191+ if (atomic_read_unchecked(&PRIV(dev)->sonet_stats.s) < 0) \
29192+ atomic_set_unchecked(&PRIV(dev)->sonet_stats.s,INT_MAX); }
29193
29194
29195 static void stat_event(struct atm_dev *dev)
29196@@ -194,7 +194,7 @@ static void uPD98402_int(struct atm_dev *dev)
29197 if (reason & uPD98402_INT_PFM) stat_event(dev);
29198 if (reason & uPD98402_INT_PCO) {
29199 (void) GET(PCOCR); /* clear interrupt cause */
29200- atomic_add(GET(HECCT),
29201+ atomic_add_unchecked(GET(HECCT),
29202 &PRIV(dev)->sonet_stats.uncorr_hcs);
29203 }
29204 if ((reason & uPD98402_INT_RFO) &&
29205@@ -222,9 +222,9 @@ static int uPD98402_start(struct atm_dev *dev)
29206 PUT(~(uPD98402_INT_PFM | uPD98402_INT_ALM | uPD98402_INT_RFO |
29207 uPD98402_INT_LOS),PIMR); /* enable them */
29208 (void) fetch_stats(dev,NULL,1); /* clear kernel counters */
29209- atomic_set(&PRIV(dev)->sonet_stats.corr_hcs,-1);
29210- atomic_set(&PRIV(dev)->sonet_stats.tx_cells,-1);
29211- atomic_set(&PRIV(dev)->sonet_stats.rx_cells,-1);
29212+ atomic_set_unchecked(&PRIV(dev)->sonet_stats.corr_hcs,-1);
29213+ atomic_set_unchecked(&PRIV(dev)->sonet_stats.tx_cells,-1);
29214+ atomic_set_unchecked(&PRIV(dev)->sonet_stats.rx_cells,-1);
29215 return 0;
29216 }
29217
29218diff --git a/drivers/atm/zatm.c b/drivers/atm/zatm.c
29219index abe4e20..83c4727 100644
29220--- a/drivers/atm/zatm.c
29221+++ b/drivers/atm/zatm.c
29222@@ -459,7 +459,7 @@ printk("dummy: 0x%08lx, 0x%08lx\n",dummy[0],dummy[1]);
29223 }
29224 if (!size) {
29225 dev_kfree_skb_irq(skb);
29226- if (vcc) atomic_inc(&vcc->stats->rx_err);
29227+ if (vcc) atomic_inc_unchecked(&vcc->stats->rx_err);
29228 continue;
29229 }
29230 if (!atm_charge(vcc,skb->truesize)) {
29231@@ -469,7 +469,7 @@ printk("dummy: 0x%08lx, 0x%08lx\n",dummy[0],dummy[1]);
29232 skb->len = size;
29233 ATM_SKB(skb)->vcc = vcc;
29234 vcc->push(vcc,skb);
29235- atomic_inc(&vcc->stats->rx);
29236+ atomic_inc_unchecked(&vcc->stats->rx);
29237 }
29238 zout(pos & 0xffff,MTA(mbx));
29239 #if 0 /* probably a stupid idea */
29240@@ -733,7 +733,7 @@ if (*ZATM_PRV_DSC(skb) != (uPD98401_TXPD_V | uPD98401_TXPD_DP |
29241 skb_queue_head(&zatm_vcc->backlog,skb);
29242 break;
29243 }
29244- atomic_inc(&vcc->stats->tx);
29245+ atomic_inc_unchecked(&vcc->stats->tx);
29246 wake_up(&zatm_vcc->tx_wait);
29247 }
29248
29249diff --git a/drivers/base/devtmpfs.c b/drivers/base/devtmpfs.c
29250index deb4a45..211eff2 100644
29251--- a/drivers/base/devtmpfs.c
29252+++ b/drivers/base/devtmpfs.c
29253@@ -347,7 +347,7 @@ int devtmpfs_mount(const char *mntdir)
29254 if (!thread)
29255 return 0;
29256
29257- err = sys_mount("devtmpfs", (char *)mntdir, "devtmpfs", MS_SILENT, NULL);
29258+ err = sys_mount((char __force_user *)"devtmpfs", (char __force_user *)mntdir, (char __force_user *)"devtmpfs", MS_SILENT, NULL);
29259 if (err)
29260 printk(KERN_INFO "devtmpfs: error mounting %i\n", err);
29261 else
29262diff --git a/drivers/base/power/wakeup.c b/drivers/base/power/wakeup.c
29263index cbb463b..babe2cf 100644
29264--- a/drivers/base/power/wakeup.c
29265+++ b/drivers/base/power/wakeup.c
29266@@ -29,14 +29,14 @@ bool events_check_enabled __read_mostly;
29267 * They need to be modified together atomically, so it's better to use one
29268 * atomic variable to hold them both.
29269 */
29270-static atomic_t combined_event_count = ATOMIC_INIT(0);
29271+static atomic_unchecked_t combined_event_count = ATOMIC_INIT(0);
29272
29273 #define IN_PROGRESS_BITS (sizeof(int) * 4)
29274 #define MAX_IN_PROGRESS ((1 << IN_PROGRESS_BITS) - 1)
29275
29276 static void split_counters(unsigned int *cnt, unsigned int *inpr)
29277 {
29278- unsigned int comb = atomic_read(&combined_event_count);
29279+ unsigned int comb = atomic_read_unchecked(&combined_event_count);
29280
29281 *cnt = (comb >> IN_PROGRESS_BITS);
29282 *inpr = comb & MAX_IN_PROGRESS;
29283@@ -385,7 +385,7 @@ static void wakeup_source_activate(struct wakeup_source *ws)
29284 ws->start_prevent_time = ws->last_time;
29285
29286 /* Increment the counter of events in progress. */
29287- cec = atomic_inc_return(&combined_event_count);
29288+ cec = atomic_inc_return_unchecked(&combined_event_count);
29289
29290 trace_wakeup_source_activate(ws->name, cec);
29291 }
29292@@ -511,7 +511,7 @@ static void wakeup_source_deactivate(struct wakeup_source *ws)
29293 * Increment the counter of registered wakeup events and decrement the
29294 * couter of wakeup events in progress simultaneously.
29295 */
29296- cec = atomic_add_return(MAX_IN_PROGRESS, &combined_event_count);
29297+ cec = atomic_add_return_unchecked(MAX_IN_PROGRESS, &combined_event_count);
29298 trace_wakeup_source_deactivate(ws->name, cec);
29299
29300 split_counters(&cnt, &inpr);
29301diff --git a/drivers/block/cciss.c b/drivers/block/cciss.c
29302index b0f553b..77b928b 100644
29303--- a/drivers/block/cciss.c
29304+++ b/drivers/block/cciss.c
29305@@ -1198,6 +1198,8 @@ static int cciss_ioctl32_passthru(struct block_device *bdev, fmode_t mode,
29306 int err;
29307 u32 cp;
29308
29309+ memset(&arg64, 0, sizeof(arg64));
29310+
29311 err = 0;
29312 err |=
29313 copy_from_user(&arg64.LUN_info, &arg32->LUN_info,
29314@@ -3007,7 +3009,7 @@ static void start_io(ctlr_info_t *h)
29315 while (!list_empty(&h->reqQ)) {
29316 c = list_entry(h->reqQ.next, CommandList_struct, list);
29317 /* can't do anything if fifo is full */
29318- if ((h->access.fifo_full(h))) {
29319+ if ((h->access->fifo_full(h))) {
29320 dev_warn(&h->pdev->dev, "fifo full\n");
29321 break;
29322 }
29323@@ -3017,7 +3019,7 @@ static void start_io(ctlr_info_t *h)
29324 h->Qdepth--;
29325
29326 /* Tell the controller execute command */
29327- h->access.submit_command(h, c);
29328+ h->access->submit_command(h, c);
29329
29330 /* Put job onto the completed Q */
29331 addQ(&h->cmpQ, c);
29332@@ -3443,17 +3445,17 @@ startio:
29333
29334 static inline unsigned long get_next_completion(ctlr_info_t *h)
29335 {
29336- return h->access.command_completed(h);
29337+ return h->access->command_completed(h);
29338 }
29339
29340 static inline int interrupt_pending(ctlr_info_t *h)
29341 {
29342- return h->access.intr_pending(h);
29343+ return h->access->intr_pending(h);
29344 }
29345
29346 static inline long interrupt_not_for_us(ctlr_info_t *h)
29347 {
29348- return ((h->access.intr_pending(h) == 0) ||
29349+ return ((h->access->intr_pending(h) == 0) ||
29350 (h->interrupts_enabled == 0));
29351 }
29352
29353@@ -3486,7 +3488,7 @@ static inline u32 next_command(ctlr_info_t *h)
29354 u32 a;
29355
29356 if (unlikely(!(h->transMethod & CFGTBL_Trans_Performant)))
29357- return h->access.command_completed(h);
29358+ return h->access->command_completed(h);
29359
29360 if ((*(h->reply_pool_head) & 1) == (h->reply_pool_wraparound)) {
29361 a = *(h->reply_pool_head); /* Next cmd in ring buffer */
29362@@ -4044,7 +4046,7 @@ static void __devinit cciss_put_controller_into_performant_mode(ctlr_info_t *h)
29363 trans_support & CFGTBL_Trans_use_short_tags);
29364
29365 /* Change the access methods to the performant access methods */
29366- h->access = SA5_performant_access;
29367+ h->access = &SA5_performant_access;
29368 h->transMethod = CFGTBL_Trans_Performant;
29369
29370 return;
29371@@ -4316,7 +4318,7 @@ static int __devinit cciss_pci_init(ctlr_info_t *h)
29372 if (prod_index < 0)
29373 return -ENODEV;
29374 h->product_name = products[prod_index].product_name;
29375- h->access = *(products[prod_index].access);
29376+ h->access = products[prod_index].access;
29377
29378 if (cciss_board_disabled(h)) {
29379 dev_warn(&h->pdev->dev, "controller appears to be disabled\n");
29380@@ -5041,7 +5043,7 @@ reinit_after_soft_reset:
29381 }
29382
29383 /* make sure the board interrupts are off */
29384- h->access.set_intr_mask(h, CCISS_INTR_OFF);
29385+ h->access->set_intr_mask(h, CCISS_INTR_OFF);
29386 rc = cciss_request_irq(h, do_cciss_msix_intr, do_cciss_intx);
29387 if (rc)
29388 goto clean2;
29389@@ -5093,7 +5095,7 @@ reinit_after_soft_reset:
29390 * fake ones to scoop up any residual completions.
29391 */
29392 spin_lock_irqsave(&h->lock, flags);
29393- h->access.set_intr_mask(h, CCISS_INTR_OFF);
29394+ h->access->set_intr_mask(h, CCISS_INTR_OFF);
29395 spin_unlock_irqrestore(&h->lock, flags);
29396 free_irq(h->intr[h->intr_mode], h);
29397 rc = cciss_request_irq(h, cciss_msix_discard_completions,
29398@@ -5113,9 +5115,9 @@ reinit_after_soft_reset:
29399 dev_info(&h->pdev->dev, "Board READY.\n");
29400 dev_info(&h->pdev->dev,
29401 "Waiting for stale completions to drain.\n");
29402- h->access.set_intr_mask(h, CCISS_INTR_ON);
29403+ h->access->set_intr_mask(h, CCISS_INTR_ON);
29404 msleep(10000);
29405- h->access.set_intr_mask(h, CCISS_INTR_OFF);
29406+ h->access->set_intr_mask(h, CCISS_INTR_OFF);
29407
29408 rc = controller_reset_failed(h->cfgtable);
29409 if (rc)
29410@@ -5138,7 +5140,7 @@ reinit_after_soft_reset:
29411 cciss_scsi_setup(h);
29412
29413 /* Turn the interrupts on so we can service requests */
29414- h->access.set_intr_mask(h, CCISS_INTR_ON);
29415+ h->access->set_intr_mask(h, CCISS_INTR_ON);
29416
29417 /* Get the firmware version */
29418 inq_buff = kzalloc(sizeof(InquiryData_struct), GFP_KERNEL);
29419@@ -5211,7 +5213,7 @@ static void cciss_shutdown(struct pci_dev *pdev)
29420 kfree(flush_buf);
29421 if (return_code != IO_OK)
29422 dev_warn(&h->pdev->dev, "Error flushing cache\n");
29423- h->access.set_intr_mask(h, CCISS_INTR_OFF);
29424+ h->access->set_intr_mask(h, CCISS_INTR_OFF);
29425 free_irq(h->intr[h->intr_mode], h);
29426 }
29427
29428diff --git a/drivers/block/cciss.h b/drivers/block/cciss.h
29429index 7fda30e..eb5dfe0 100644
29430--- a/drivers/block/cciss.h
29431+++ b/drivers/block/cciss.h
29432@@ -101,7 +101,7 @@ struct ctlr_info
29433 /* information about each logical volume */
29434 drive_info_struct *drv[CISS_MAX_LUN];
29435
29436- struct access_method access;
29437+ struct access_method *access;
29438
29439 /* queue and queue Info */
29440 struct list_head reqQ;
29441diff --git a/drivers/block/cpqarray.c b/drivers/block/cpqarray.c
29442index 9125bbe..eede5c8 100644
29443--- a/drivers/block/cpqarray.c
29444+++ b/drivers/block/cpqarray.c
29445@@ -404,7 +404,7 @@ static int __devinit cpqarray_register_ctlr( int i, struct pci_dev *pdev)
29446 if (register_blkdev(COMPAQ_SMART2_MAJOR+i, hba[i]->devname)) {
29447 goto Enomem4;
29448 }
29449- hba[i]->access.set_intr_mask(hba[i], 0);
29450+ hba[i]->access->set_intr_mask(hba[i], 0);
29451 if (request_irq(hba[i]->intr, do_ida_intr,
29452 IRQF_DISABLED|IRQF_SHARED, hba[i]->devname, hba[i]))
29453 {
29454@@ -459,7 +459,7 @@ static int __devinit cpqarray_register_ctlr( int i, struct pci_dev *pdev)
29455 add_timer(&hba[i]->timer);
29456
29457 /* Enable IRQ now that spinlock and rate limit timer are set up */
29458- hba[i]->access.set_intr_mask(hba[i], FIFO_NOT_EMPTY);
29459+ hba[i]->access->set_intr_mask(hba[i], FIFO_NOT_EMPTY);
29460
29461 for(j=0; j<NWD; j++) {
29462 struct gendisk *disk = ida_gendisk[i][j];
29463@@ -694,7 +694,7 @@ DBGINFO(
29464 for(i=0; i<NR_PRODUCTS; i++) {
29465 if (board_id == products[i].board_id) {
29466 c->product_name = products[i].product_name;
29467- c->access = *(products[i].access);
29468+ c->access = products[i].access;
29469 break;
29470 }
29471 }
29472@@ -792,7 +792,7 @@ static int __devinit cpqarray_eisa_detect(void)
29473 hba[ctlr]->intr = intr;
29474 sprintf(hba[ctlr]->devname, "ida%d", nr_ctlr);
29475 hba[ctlr]->product_name = products[j].product_name;
29476- hba[ctlr]->access = *(products[j].access);
29477+ hba[ctlr]->access = products[j].access;
29478 hba[ctlr]->ctlr = ctlr;
29479 hba[ctlr]->board_id = board_id;
29480 hba[ctlr]->pci_dev = NULL; /* not PCI */
29481@@ -980,7 +980,7 @@ static void start_io(ctlr_info_t *h)
29482
29483 while((c = h->reqQ) != NULL) {
29484 /* Can't do anything if we're busy */
29485- if (h->access.fifo_full(h) == 0)
29486+ if (h->access->fifo_full(h) == 0)
29487 return;
29488
29489 /* Get the first entry from the request Q */
29490@@ -988,7 +988,7 @@ static void start_io(ctlr_info_t *h)
29491 h->Qdepth--;
29492
29493 /* Tell the controller to do our bidding */
29494- h->access.submit_command(h, c);
29495+ h->access->submit_command(h, c);
29496
29497 /* Get onto the completion Q */
29498 addQ(&h->cmpQ, c);
29499@@ -1050,7 +1050,7 @@ static irqreturn_t do_ida_intr(int irq, void *dev_id)
29500 unsigned long flags;
29501 __u32 a,a1;
29502
29503- istat = h->access.intr_pending(h);
29504+ istat = h->access->intr_pending(h);
29505 /* Is this interrupt for us? */
29506 if (istat == 0)
29507 return IRQ_NONE;
29508@@ -1061,7 +1061,7 @@ static irqreturn_t do_ida_intr(int irq, void *dev_id)
29509 */
29510 spin_lock_irqsave(IDA_LOCK(h->ctlr), flags);
29511 if (istat & FIFO_NOT_EMPTY) {
29512- while((a = h->access.command_completed(h))) {
29513+ while((a = h->access->command_completed(h))) {
29514 a1 = a; a &= ~3;
29515 if ((c = h->cmpQ) == NULL)
29516 {
29517@@ -1449,11 +1449,11 @@ static int sendcmd(
29518 /*
29519 * Disable interrupt
29520 */
29521- info_p->access.set_intr_mask(info_p, 0);
29522+ info_p->access->set_intr_mask(info_p, 0);
29523 /* Make sure there is room in the command FIFO */
29524 /* Actually it should be completely empty at this time. */
29525 for (i = 200000; i > 0; i--) {
29526- temp = info_p->access.fifo_full(info_p);
29527+ temp = info_p->access->fifo_full(info_p);
29528 if (temp != 0) {
29529 break;
29530 }
29531@@ -1466,7 +1466,7 @@ DBG(
29532 /*
29533 * Send the cmd
29534 */
29535- info_p->access.submit_command(info_p, c);
29536+ info_p->access->submit_command(info_p, c);
29537 complete = pollcomplete(ctlr);
29538
29539 pci_unmap_single(info_p->pci_dev, (dma_addr_t) c->req.sg[0].addr,
29540@@ -1549,9 +1549,9 @@ static int revalidate_allvol(ctlr_info_t *host)
29541 * we check the new geometry. Then turn interrupts back on when
29542 * we're done.
29543 */
29544- host->access.set_intr_mask(host, 0);
29545+ host->access->set_intr_mask(host, 0);
29546 getgeometry(ctlr);
29547- host->access.set_intr_mask(host, FIFO_NOT_EMPTY);
29548+ host->access->set_intr_mask(host, FIFO_NOT_EMPTY);
29549
29550 for(i=0; i<NWD; i++) {
29551 struct gendisk *disk = ida_gendisk[ctlr][i];
29552@@ -1591,7 +1591,7 @@ static int pollcomplete(int ctlr)
29553 /* Wait (up to 2 seconds) for a command to complete */
29554
29555 for (i = 200000; i > 0; i--) {
29556- done = hba[ctlr]->access.command_completed(hba[ctlr]);
29557+ done = hba[ctlr]->access->command_completed(hba[ctlr]);
29558 if (done == 0) {
29559 udelay(10); /* a short fixed delay */
29560 } else
29561diff --git a/drivers/block/cpqarray.h b/drivers/block/cpqarray.h
29562index be73e9d..7fbf140 100644
29563--- a/drivers/block/cpqarray.h
29564+++ b/drivers/block/cpqarray.h
29565@@ -99,7 +99,7 @@ struct ctlr_info {
29566 drv_info_t drv[NWD];
29567 struct proc_dir_entry *proc;
29568
29569- struct access_method access;
29570+ struct access_method *access;
29571
29572 cmdlist_t *reqQ;
29573 cmdlist_t *cmpQ;
29574diff --git a/drivers/block/drbd/drbd_int.h b/drivers/block/drbd/drbd_int.h
29575index b953cc7..e3dc580 100644
29576--- a/drivers/block/drbd/drbd_int.h
29577+++ b/drivers/block/drbd/drbd_int.h
29578@@ -735,7 +735,7 @@ struct drbd_request;
29579 struct drbd_epoch {
29580 struct list_head list;
29581 unsigned int barrier_nr;
29582- atomic_t epoch_size; /* increased on every request added. */
29583+ atomic_unchecked_t epoch_size; /* increased on every request added. */
29584 atomic_t active; /* increased on every req. added, and dec on every finished. */
29585 unsigned long flags;
29586 };
29587@@ -1116,7 +1116,7 @@ struct drbd_conf {
29588 void *int_dig_in;
29589 void *int_dig_vv;
29590 wait_queue_head_t seq_wait;
29591- atomic_t packet_seq;
29592+ atomic_unchecked_t packet_seq;
29593 unsigned int peer_seq;
29594 spinlock_t peer_seq_lock;
29595 unsigned int minor;
29596@@ -1658,30 +1658,30 @@ static inline int drbd_setsockopt(struct socket *sock, int level, int optname,
29597
29598 static inline void drbd_tcp_cork(struct socket *sock)
29599 {
29600- int __user val = 1;
29601+ int val = 1;
29602 (void) drbd_setsockopt(sock, SOL_TCP, TCP_CORK,
29603- (char __user *)&val, sizeof(val));
29604+ (char __force_user *)&val, sizeof(val));
29605 }
29606
29607 static inline void drbd_tcp_uncork(struct socket *sock)
29608 {
29609- int __user val = 0;
29610+ int val = 0;
29611 (void) drbd_setsockopt(sock, SOL_TCP, TCP_CORK,
29612- (char __user *)&val, sizeof(val));
29613+ (char __force_user *)&val, sizeof(val));
29614 }
29615
29616 static inline void drbd_tcp_nodelay(struct socket *sock)
29617 {
29618- int __user val = 1;
29619+ int val = 1;
29620 (void) drbd_setsockopt(sock, SOL_TCP, TCP_NODELAY,
29621- (char __user *)&val, sizeof(val));
29622+ (char __force_user *)&val, sizeof(val));
29623 }
29624
29625 static inline void drbd_tcp_quickack(struct socket *sock)
29626 {
29627- int __user val = 2;
29628+ int val = 2;
29629 (void) drbd_setsockopt(sock, SOL_TCP, TCP_QUICKACK,
29630- (char __user *)&val, sizeof(val));
29631+ (char __force_user *)&val, sizeof(val));
29632 }
29633
29634 void drbd_bump_write_ordering(struct drbd_conf *mdev, enum write_ordering_e wo);
29635diff --git a/drivers/block/drbd/drbd_main.c b/drivers/block/drbd/drbd_main.c
29636index f93a032..71c87bf 100644
29637--- a/drivers/block/drbd/drbd_main.c
29638+++ b/drivers/block/drbd/drbd_main.c
29639@@ -2567,7 +2567,7 @@ static int _drbd_send_ack(struct drbd_conf *mdev, enum drbd_packets cmd,
29640 p.sector = sector;
29641 p.block_id = block_id;
29642 p.blksize = blksize;
29643- p.seq_num = cpu_to_be32(atomic_add_return(1, &mdev->packet_seq));
29644+ p.seq_num = cpu_to_be32(atomic_add_return_unchecked(1, &mdev->packet_seq));
29645
29646 if (!mdev->meta.socket || mdev->state.conn < C_CONNECTED)
29647 return false;
29648@@ -2865,7 +2865,7 @@ int drbd_send_dblock(struct drbd_conf *mdev, struct drbd_request *req)
29649
29650 p.sector = cpu_to_be64(req->sector);
29651 p.block_id = (unsigned long)req;
29652- p.seq_num = cpu_to_be32(atomic_add_return(1, &mdev->packet_seq));
29653+ p.seq_num = cpu_to_be32(atomic_add_return_unchecked(1, &mdev->packet_seq));
29654
29655 dp_flags = bio_flags_to_wire(mdev, req->master_bio->bi_rw);
29656
29657@@ -3150,7 +3150,7 @@ void drbd_init_set_defaults(struct drbd_conf *mdev)
29658 atomic_set(&mdev->unacked_cnt, 0);
29659 atomic_set(&mdev->local_cnt, 0);
29660 atomic_set(&mdev->net_cnt, 0);
29661- atomic_set(&mdev->packet_seq, 0);
29662+ atomic_set_unchecked(&mdev->packet_seq, 0);
29663 atomic_set(&mdev->pp_in_use, 0);
29664 atomic_set(&mdev->pp_in_use_by_net, 0);
29665 atomic_set(&mdev->rs_sect_in, 0);
29666@@ -3232,8 +3232,8 @@ void drbd_mdev_cleanup(struct drbd_conf *mdev)
29667 mdev->receiver.t_state);
29668
29669 /* no need to lock it, I'm the only thread alive */
29670- if (atomic_read(&mdev->current_epoch->epoch_size) != 0)
29671- dev_err(DEV, "epoch_size:%d\n", atomic_read(&mdev->current_epoch->epoch_size));
29672+ if (atomic_read_unchecked(&mdev->current_epoch->epoch_size) != 0)
29673+ dev_err(DEV, "epoch_size:%d\n", atomic_read_unchecked(&mdev->current_epoch->epoch_size));
29674 mdev->al_writ_cnt =
29675 mdev->bm_writ_cnt =
29676 mdev->read_cnt =
29677diff --git a/drivers/block/drbd/drbd_nl.c b/drivers/block/drbd/drbd_nl.c
29678index edb490a..ecd69da 100644
29679--- a/drivers/block/drbd/drbd_nl.c
29680+++ b/drivers/block/drbd/drbd_nl.c
29681@@ -2407,7 +2407,7 @@ static void drbd_connector_callback(struct cn_msg *req, struct netlink_skb_parms
29682 module_put(THIS_MODULE);
29683 }
29684
29685-static atomic_t drbd_nl_seq = ATOMIC_INIT(2); /* two. */
29686+static atomic_unchecked_t drbd_nl_seq = ATOMIC_INIT(2); /* two. */
29687
29688 static unsigned short *
29689 __tl_add_blob(unsigned short *tl, enum drbd_tags tag, const void *data,
29690@@ -2478,7 +2478,7 @@ void drbd_bcast_state(struct drbd_conf *mdev, union drbd_state state)
29691 cn_reply->id.idx = CN_IDX_DRBD;
29692 cn_reply->id.val = CN_VAL_DRBD;
29693
29694- cn_reply->seq = atomic_add_return(1, &drbd_nl_seq);
29695+ cn_reply->seq = atomic_add_return_unchecked(1, &drbd_nl_seq);
29696 cn_reply->ack = 0; /* not used here. */
29697 cn_reply->len = sizeof(struct drbd_nl_cfg_reply) +
29698 (int)((char *)tl - (char *)reply->tag_list);
29699@@ -2510,7 +2510,7 @@ void drbd_bcast_ev_helper(struct drbd_conf *mdev, char *helper_name)
29700 cn_reply->id.idx = CN_IDX_DRBD;
29701 cn_reply->id.val = CN_VAL_DRBD;
29702
29703- cn_reply->seq = atomic_add_return(1, &drbd_nl_seq);
29704+ cn_reply->seq = atomic_add_return_unchecked(1, &drbd_nl_seq);
29705 cn_reply->ack = 0; /* not used here. */
29706 cn_reply->len = sizeof(struct drbd_nl_cfg_reply) +
29707 (int)((char *)tl - (char *)reply->tag_list);
29708@@ -2588,7 +2588,7 @@ void drbd_bcast_ee(struct drbd_conf *mdev,
29709 cn_reply->id.idx = CN_IDX_DRBD;
29710 cn_reply->id.val = CN_VAL_DRBD;
29711
29712- cn_reply->seq = atomic_add_return(1,&drbd_nl_seq);
29713+ cn_reply->seq = atomic_add_return_unchecked(1,&drbd_nl_seq);
29714 cn_reply->ack = 0; // not used here.
29715 cn_reply->len = sizeof(struct drbd_nl_cfg_reply) +
29716 (int)((char*)tl - (char*)reply->tag_list);
29717@@ -2627,7 +2627,7 @@ void drbd_bcast_sync_progress(struct drbd_conf *mdev)
29718 cn_reply->id.idx = CN_IDX_DRBD;
29719 cn_reply->id.val = CN_VAL_DRBD;
29720
29721- cn_reply->seq = atomic_add_return(1, &drbd_nl_seq);
29722+ cn_reply->seq = atomic_add_return_unchecked(1, &drbd_nl_seq);
29723 cn_reply->ack = 0; /* not used here. */
29724 cn_reply->len = sizeof(struct drbd_nl_cfg_reply) +
29725 (int)((char *)tl - (char *)reply->tag_list);
29726diff --git a/drivers/block/drbd/drbd_receiver.c b/drivers/block/drbd/drbd_receiver.c
29727index c74ca2d..860c819 100644
29728--- a/drivers/block/drbd/drbd_receiver.c
29729+++ b/drivers/block/drbd/drbd_receiver.c
29730@@ -898,7 +898,7 @@ retry:
29731 sock->sk->sk_sndtimeo = mdev->net_conf->timeout*HZ/10;
29732 sock->sk->sk_rcvtimeo = MAX_SCHEDULE_TIMEOUT;
29733
29734- atomic_set(&mdev->packet_seq, 0);
29735+ atomic_set_unchecked(&mdev->packet_seq, 0);
29736 mdev->peer_seq = 0;
29737
29738 if (drbd_send_protocol(mdev) == -1)
29739@@ -999,7 +999,7 @@ static enum finish_epoch drbd_may_finish_epoch(struct drbd_conf *mdev,
29740 do {
29741 next_epoch = NULL;
29742
29743- epoch_size = atomic_read(&epoch->epoch_size);
29744+ epoch_size = atomic_read_unchecked(&epoch->epoch_size);
29745
29746 switch (ev & ~EV_CLEANUP) {
29747 case EV_PUT:
29748@@ -1035,7 +1035,7 @@ static enum finish_epoch drbd_may_finish_epoch(struct drbd_conf *mdev,
29749 rv = FE_DESTROYED;
29750 } else {
29751 epoch->flags = 0;
29752- atomic_set(&epoch->epoch_size, 0);
29753+ atomic_set_unchecked(&epoch->epoch_size, 0);
29754 /* atomic_set(&epoch->active, 0); is already zero */
29755 if (rv == FE_STILL_LIVE)
29756 rv = FE_RECYCLED;
29757@@ -1210,14 +1210,14 @@ static int receive_Barrier(struct drbd_conf *mdev, enum drbd_packets cmd, unsign
29758 drbd_wait_ee_list_empty(mdev, &mdev->active_ee);
29759 drbd_flush(mdev);
29760
29761- if (atomic_read(&mdev->current_epoch->epoch_size)) {
29762+ if (atomic_read_unchecked(&mdev->current_epoch->epoch_size)) {
29763 epoch = kmalloc(sizeof(struct drbd_epoch), GFP_NOIO);
29764 if (epoch)
29765 break;
29766 }
29767
29768 epoch = mdev->current_epoch;
29769- wait_event(mdev->ee_wait, atomic_read(&epoch->epoch_size) == 0);
29770+ wait_event(mdev->ee_wait, atomic_read_unchecked(&epoch->epoch_size) == 0);
29771
29772 D_ASSERT(atomic_read(&epoch->active) == 0);
29773 D_ASSERT(epoch->flags == 0);
29774@@ -1229,11 +1229,11 @@ static int receive_Barrier(struct drbd_conf *mdev, enum drbd_packets cmd, unsign
29775 }
29776
29777 epoch->flags = 0;
29778- atomic_set(&epoch->epoch_size, 0);
29779+ atomic_set_unchecked(&epoch->epoch_size, 0);
29780 atomic_set(&epoch->active, 0);
29781
29782 spin_lock(&mdev->epoch_lock);
29783- if (atomic_read(&mdev->current_epoch->epoch_size)) {
29784+ if (atomic_read_unchecked(&mdev->current_epoch->epoch_size)) {
29785 list_add(&epoch->list, &mdev->current_epoch->list);
29786 mdev->current_epoch = epoch;
29787 mdev->epochs++;
29788@@ -1702,7 +1702,7 @@ static int receive_Data(struct drbd_conf *mdev, enum drbd_packets cmd, unsigned
29789 spin_unlock(&mdev->peer_seq_lock);
29790
29791 drbd_send_ack_dp(mdev, P_NEG_ACK, p, data_size);
29792- atomic_inc(&mdev->current_epoch->epoch_size);
29793+ atomic_inc_unchecked(&mdev->current_epoch->epoch_size);
29794 return drbd_drain_block(mdev, data_size);
29795 }
29796
29797@@ -1732,7 +1732,7 @@ static int receive_Data(struct drbd_conf *mdev, enum drbd_packets cmd, unsigned
29798
29799 spin_lock(&mdev->epoch_lock);
29800 e->epoch = mdev->current_epoch;
29801- atomic_inc(&e->epoch->epoch_size);
29802+ atomic_inc_unchecked(&e->epoch->epoch_size);
29803 atomic_inc(&e->epoch->active);
29804 spin_unlock(&mdev->epoch_lock);
29805
29806@@ -3954,7 +3954,7 @@ static void drbd_disconnect(struct drbd_conf *mdev)
29807 D_ASSERT(list_empty(&mdev->done_ee));
29808
29809 /* ok, no more ee's on the fly, it is safe to reset the epoch_size */
29810- atomic_set(&mdev->current_epoch->epoch_size, 0);
29811+ atomic_set_unchecked(&mdev->current_epoch->epoch_size, 0);
29812 D_ASSERT(list_empty(&mdev->current_epoch->list));
29813 }
29814
29815diff --git a/drivers/block/loop.c b/drivers/block/loop.c
29816index 3bba655..6151b66 100644
29817--- a/drivers/block/loop.c
29818+++ b/drivers/block/loop.c
29819@@ -226,7 +226,7 @@ static int __do_lo_send_write(struct file *file,
29820 mm_segment_t old_fs = get_fs();
29821
29822 set_fs(get_ds());
29823- bw = file->f_op->write(file, buf, len, &pos);
29824+ bw = file->f_op->write(file, (const char __force_user *)buf, len, &pos);
29825 set_fs(old_fs);
29826 if (likely(bw == len))
29827 return 0;
29828diff --git a/drivers/char/Kconfig b/drivers/char/Kconfig
29829index ea6f632..eafb192 100644
29830--- a/drivers/char/Kconfig
29831+++ b/drivers/char/Kconfig
29832@@ -8,7 +8,8 @@ source "drivers/tty/Kconfig"
29833
29834 config DEVKMEM
29835 bool "/dev/kmem virtual device support"
29836- default y
29837+ default n
29838+ depends on !GRKERNSEC_KMEM
29839 help
29840 Say Y here if you want to support the /dev/kmem device. The
29841 /dev/kmem device is rarely used, but can be used for certain
29842@@ -581,6 +582,7 @@ config DEVPORT
29843 bool
29844 depends on !M68K
29845 depends on ISA || PCI
29846+ depends on !GRKERNSEC_KMEM
29847 default y
29848
29849 source "drivers/s390/char/Kconfig"
29850diff --git a/drivers/char/agp/frontend.c b/drivers/char/agp/frontend.c
29851index 2e04433..22afc64 100644
29852--- a/drivers/char/agp/frontend.c
29853+++ b/drivers/char/agp/frontend.c
29854@@ -817,7 +817,7 @@ static int agpioc_reserve_wrap(struct agp_file_private *priv, void __user *arg)
29855 if (copy_from_user(&reserve, arg, sizeof(struct agp_region)))
29856 return -EFAULT;
29857
29858- if ((unsigned) reserve.seg_count >= ~0U/sizeof(struct agp_segment))
29859+ if ((unsigned) reserve.seg_count >= ~0U/sizeof(struct agp_segment_priv))
29860 return -EFAULT;
29861
29862 client = agp_find_client_by_pid(reserve.pid);
29863diff --git a/drivers/char/genrtc.c b/drivers/char/genrtc.c
29864index 21cb980..f15107c 100644
29865--- a/drivers/char/genrtc.c
29866+++ b/drivers/char/genrtc.c
29867@@ -272,6 +272,7 @@ static int gen_rtc_ioctl(struct file *file,
29868 switch (cmd) {
29869
29870 case RTC_PLL_GET:
29871+ memset(&pll, 0, sizeof(pll));
29872 if (get_rtc_pll(&pll))
29873 return -EINVAL;
29874 else
29875diff --git a/drivers/char/hpet.c b/drivers/char/hpet.c
29876index dfd7876..c0b0885 100644
29877--- a/drivers/char/hpet.c
29878+++ b/drivers/char/hpet.c
29879@@ -571,7 +571,7 @@ static inline unsigned long hpet_time_div(struct hpets *hpets,
29880 }
29881
29882 static int
29883-hpet_ioctl_common(struct hpet_dev *devp, int cmd, unsigned long arg,
29884+hpet_ioctl_common(struct hpet_dev *devp, unsigned int cmd, unsigned long arg,
29885 struct hpet_info *info)
29886 {
29887 struct hpet_timer __iomem *timer;
29888diff --git a/drivers/char/ipmi/ipmi_msghandler.c b/drivers/char/ipmi/ipmi_msghandler.c
29889index 2c29942..604c5ba 100644
29890--- a/drivers/char/ipmi/ipmi_msghandler.c
29891+++ b/drivers/char/ipmi/ipmi_msghandler.c
29892@@ -420,7 +420,7 @@ struct ipmi_smi {
29893 struct proc_dir_entry *proc_dir;
29894 char proc_dir_name[10];
29895
29896- atomic_t stats[IPMI_NUM_STATS];
29897+ atomic_unchecked_t stats[IPMI_NUM_STATS];
29898
29899 /*
29900 * run_to_completion duplicate of smb_info, smi_info
29901@@ -453,9 +453,9 @@ static DEFINE_MUTEX(smi_watchers_mutex);
29902
29903
29904 #define ipmi_inc_stat(intf, stat) \
29905- atomic_inc(&(intf)->stats[IPMI_STAT_ ## stat])
29906+ atomic_inc_unchecked(&(intf)->stats[IPMI_STAT_ ## stat])
29907 #define ipmi_get_stat(intf, stat) \
29908- ((unsigned int) atomic_read(&(intf)->stats[IPMI_STAT_ ## stat]))
29909+ ((unsigned int) atomic_read_unchecked(&(intf)->stats[IPMI_STAT_ ## stat]))
29910
29911 static int is_lan_addr(struct ipmi_addr *addr)
29912 {
29913@@ -2884,7 +2884,7 @@ int ipmi_register_smi(struct ipmi_smi_handlers *handlers,
29914 INIT_LIST_HEAD(&intf->cmd_rcvrs);
29915 init_waitqueue_head(&intf->waitq);
29916 for (i = 0; i < IPMI_NUM_STATS; i++)
29917- atomic_set(&intf->stats[i], 0);
29918+ atomic_set_unchecked(&intf->stats[i], 0);
29919
29920 intf->proc_dir = NULL;
29921
29922diff --git a/drivers/char/ipmi/ipmi_si_intf.c b/drivers/char/ipmi/ipmi_si_intf.c
29923index 83f85cf..279e63f 100644
29924--- a/drivers/char/ipmi/ipmi_si_intf.c
29925+++ b/drivers/char/ipmi/ipmi_si_intf.c
29926@@ -275,7 +275,7 @@ struct smi_info {
29927 unsigned char slave_addr;
29928
29929 /* Counters and things for the proc filesystem. */
29930- atomic_t stats[SI_NUM_STATS];
29931+ atomic_unchecked_t stats[SI_NUM_STATS];
29932
29933 struct task_struct *thread;
29934
29935@@ -284,9 +284,9 @@ struct smi_info {
29936 };
29937
29938 #define smi_inc_stat(smi, stat) \
29939- atomic_inc(&(smi)->stats[SI_STAT_ ## stat])
29940+ atomic_inc_unchecked(&(smi)->stats[SI_STAT_ ## stat])
29941 #define smi_get_stat(smi, stat) \
29942- ((unsigned int) atomic_read(&(smi)->stats[SI_STAT_ ## stat]))
29943+ ((unsigned int) atomic_read_unchecked(&(smi)->stats[SI_STAT_ ## stat]))
29944
29945 #define SI_MAX_PARMS 4
29946
29947@@ -3193,7 +3193,7 @@ static int try_smi_init(struct smi_info *new_smi)
29948 atomic_set(&new_smi->req_events, 0);
29949 new_smi->run_to_completion = 0;
29950 for (i = 0; i < SI_NUM_STATS; i++)
29951- atomic_set(&new_smi->stats[i], 0);
29952+ atomic_set_unchecked(&new_smi->stats[i], 0);
29953
29954 new_smi->interrupt_disabled = 1;
29955 atomic_set(&new_smi->stop_operation, 0);
29956diff --git a/drivers/char/mbcs.c b/drivers/char/mbcs.c
29957index 47ff7e4..0c7d340 100644
29958--- a/drivers/char/mbcs.c
29959+++ b/drivers/char/mbcs.c
29960@@ -799,7 +799,7 @@ static int mbcs_remove(struct cx_dev *dev)
29961 return 0;
29962 }
29963
29964-static const struct cx_device_id __devinitdata mbcs_id_table[] = {
29965+static const struct cx_device_id __devinitconst mbcs_id_table[] = {
29966 {
29967 .part_num = MBCS_PART_NUM,
29968 .mfg_num = MBCS_MFG_NUM,
29969diff --git a/drivers/char/mem.c b/drivers/char/mem.c
29970index e5eedfa..fcab50ea 100644
29971--- a/drivers/char/mem.c
29972+++ b/drivers/char/mem.c
29973@@ -18,6 +18,7 @@
29974 #include <linux/raw.h>
29975 #include <linux/tty.h>
29976 #include <linux/capability.h>
29977+#include <linux/security.h>
29978 #include <linux/ptrace.h>
29979 #include <linux/device.h>
29980 #include <linux/highmem.h>
29981@@ -37,6 +38,10 @@
29982
29983 #define DEVPORT_MINOR 4
29984
29985+#if defined(CONFIG_GRKERNSEC) && !defined(CONFIG_GRKERNSEC_NO_RBAC)
29986+extern const struct file_operations grsec_fops;
29987+#endif
29988+
29989 static inline unsigned long size_inside_page(unsigned long start,
29990 unsigned long size)
29991 {
29992@@ -68,9 +73,13 @@ static inline int range_is_allowed(unsigned long pfn, unsigned long size)
29993
29994 while (cursor < to) {
29995 if (!devmem_is_allowed(pfn)) {
29996+#ifdef CONFIG_GRKERNSEC_KMEM
29997+ gr_handle_mem_readwrite(from, to);
29998+#else
29999 printk(KERN_INFO
30000 "Program %s tried to access /dev/mem between %Lx->%Lx.\n",
30001 current->comm, from, to);
30002+#endif
30003 return 0;
30004 }
30005 cursor += PAGE_SIZE;
30006@@ -78,6 +87,11 @@ static inline int range_is_allowed(unsigned long pfn, unsigned long size)
30007 }
30008 return 1;
30009 }
30010+#elif defined(CONFIG_GRKERNSEC_KMEM)
30011+static inline int range_is_allowed(unsigned long pfn, unsigned long size)
30012+{
30013+ return 0;
30014+}
30015 #else
30016 static inline int range_is_allowed(unsigned long pfn, unsigned long size)
30017 {
30018@@ -120,6 +134,7 @@ static ssize_t read_mem(struct file *file, char __user *buf,
30019
30020 while (count > 0) {
30021 unsigned long remaining;
30022+ char *temp;
30023
30024 sz = size_inside_page(p, count);
30025
30026@@ -135,7 +150,23 @@ static ssize_t read_mem(struct file *file, char __user *buf,
30027 if (!ptr)
30028 return -EFAULT;
30029
30030- remaining = copy_to_user(buf, ptr, sz);
30031+#ifdef CONFIG_PAX_USERCOPY
30032+ temp = kmalloc(sz, GFP_KERNEL|GFP_USERCOPY);
30033+ if (!temp) {
30034+ unxlate_dev_mem_ptr(p, ptr);
30035+ return -ENOMEM;
30036+ }
30037+ memcpy(temp, ptr, sz);
30038+#else
30039+ temp = ptr;
30040+#endif
30041+
30042+ remaining = copy_to_user(buf, temp, sz);
30043+
30044+#ifdef CONFIG_PAX_USERCOPY
30045+ kfree(temp);
30046+#endif
30047+
30048 unxlate_dev_mem_ptr(p, ptr);
30049 if (remaining)
30050 return -EFAULT;
30051@@ -398,9 +429,8 @@ static ssize_t read_kmem(struct file *file, char __user *buf,
30052 size_t count, loff_t *ppos)
30053 {
30054 unsigned long p = *ppos;
30055- ssize_t low_count, read, sz;
30056+ ssize_t low_count, read, sz, err = 0;
30057 char * kbuf; /* k-addr because vread() takes vmlist_lock rwlock */
30058- int err = 0;
30059
30060 read = 0;
30061 if (p < (unsigned long) high_memory) {
30062@@ -422,6 +452,8 @@ static ssize_t read_kmem(struct file *file, char __user *buf,
30063 }
30064 #endif
30065 while (low_count > 0) {
30066+ char *temp;
30067+
30068 sz = size_inside_page(p, low_count);
30069
30070 /*
30071@@ -431,7 +463,22 @@ static ssize_t read_kmem(struct file *file, char __user *buf,
30072 */
30073 kbuf = xlate_dev_kmem_ptr((char *)p);
30074
30075- if (copy_to_user(buf, kbuf, sz))
30076+#ifdef CONFIG_PAX_USERCOPY
30077+ temp = kmalloc(sz, GFP_KERNEL|GFP_USERCOPY);
30078+ if (!temp)
30079+ return -ENOMEM;
30080+ memcpy(temp, kbuf, sz);
30081+#else
30082+ temp = kbuf;
30083+#endif
30084+
30085+ err = copy_to_user(buf, temp, sz);
30086+
30087+#ifdef CONFIG_PAX_USERCOPY
30088+ kfree(temp);
30089+#endif
30090+
30091+ if (err)
30092 return -EFAULT;
30093 buf += sz;
30094 p += sz;
30095@@ -833,6 +880,9 @@ static const struct memdev {
30096 #ifdef CONFIG_CRASH_DUMP
30097 [12] = { "oldmem", 0, &oldmem_fops, NULL },
30098 #endif
30099+#if defined(CONFIG_GRKERNSEC) && !defined(CONFIG_GRKERNSEC_NO_RBAC)
30100+ [13] = { "grsec",S_IRUSR | S_IWUGO, &grsec_fops, NULL },
30101+#endif
30102 };
30103
30104 static int memory_open(struct inode *inode, struct file *filp)
30105diff --git a/drivers/char/nvram.c b/drivers/char/nvram.c
30106index 9df78e2..01ba9ae 100644
30107--- a/drivers/char/nvram.c
30108+++ b/drivers/char/nvram.c
30109@@ -247,7 +247,7 @@ static ssize_t nvram_read(struct file *file, char __user *buf,
30110
30111 spin_unlock_irq(&rtc_lock);
30112
30113- if (copy_to_user(buf, contents, tmp - contents))
30114+ if (tmp - contents > sizeof(contents) || copy_to_user(buf, contents, tmp - contents))
30115 return -EFAULT;
30116
30117 *ppos = i;
30118diff --git a/drivers/char/pcmcia/synclink_cs.c b/drivers/char/pcmcia/synclink_cs.c
30119index 0a484b4..f48ccd1 100644
30120--- a/drivers/char/pcmcia/synclink_cs.c
30121+++ b/drivers/char/pcmcia/synclink_cs.c
30122@@ -2340,9 +2340,9 @@ static void mgslpc_close(struct tty_struct *tty, struct file * filp)
30123
30124 if (debug_level >= DEBUG_LEVEL_INFO)
30125 printk("%s(%d):mgslpc_close(%s) entry, count=%d\n",
30126- __FILE__,__LINE__, info->device_name, port->count);
30127+ __FILE__,__LINE__, info->device_name, atomic_read(&port->count));
30128
30129- WARN_ON(!port->count);
30130+ WARN_ON(!atomic_read(&port->count));
30131
30132 if (tty_port_close_start(port, tty, filp) == 0)
30133 goto cleanup;
30134@@ -2360,7 +2360,7 @@ static void mgslpc_close(struct tty_struct *tty, struct file * filp)
30135 cleanup:
30136 if (debug_level >= DEBUG_LEVEL_INFO)
30137 printk("%s(%d):mgslpc_close(%s) exit, count=%d\n", __FILE__,__LINE__,
30138- tty->driver->name, port->count);
30139+ tty->driver->name, atomic_read(&port->count));
30140 }
30141
30142 /* Wait until the transmitter is empty.
30143@@ -2502,7 +2502,7 @@ static int mgslpc_open(struct tty_struct *tty, struct file * filp)
30144
30145 if (debug_level >= DEBUG_LEVEL_INFO)
30146 printk("%s(%d):mgslpc_open(%s), old ref count = %d\n",
30147- __FILE__,__LINE__,tty->driver->name, port->count);
30148+ __FILE__,__LINE__,tty->driver->name, atomic_read(&port->count));
30149
30150 /* If port is closing, signal caller to try again */
30151 if (tty_hung_up_p(filp) || port->flags & ASYNC_CLOSING){
30152@@ -2522,11 +2522,11 @@ static int mgslpc_open(struct tty_struct *tty, struct file * filp)
30153 goto cleanup;
30154 }
30155 spin_lock(&port->lock);
30156- port->count++;
30157+ atomic_inc(&port->count);
30158 spin_unlock(&port->lock);
30159 spin_unlock_irqrestore(&info->netlock, flags);
30160
30161- if (port->count == 1) {
30162+ if (atomic_read(&port->count) == 1) {
30163 /* 1st open on this device, init hardware */
30164 retval = startup(info, tty);
30165 if (retval < 0)
30166@@ -3891,7 +3891,7 @@ static int hdlcdev_attach(struct net_device *dev, unsigned short encoding,
30167 unsigned short new_crctype;
30168
30169 /* return error if TTY interface open */
30170- if (info->port.count)
30171+ if (atomic_read(&info->port.count))
30172 return -EBUSY;
30173
30174 switch (encoding)
30175@@ -3994,7 +3994,7 @@ static int hdlcdev_open(struct net_device *dev)
30176
30177 /* arbitrate between network and tty opens */
30178 spin_lock_irqsave(&info->netlock, flags);
30179- if (info->port.count != 0 || info->netcount != 0) {
30180+ if (atomic_read(&info->port.count) != 0 || info->netcount != 0) {
30181 printk(KERN_WARNING "%s: hdlc_open returning busy\n", dev->name);
30182 spin_unlock_irqrestore(&info->netlock, flags);
30183 return -EBUSY;
30184@@ -4083,7 +4083,7 @@ static int hdlcdev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
30185 printk("%s:hdlcdev_ioctl(%s)\n",__FILE__,dev->name);
30186
30187 /* return error if TTY interface open */
30188- if (info->port.count)
30189+ if (atomic_read(&info->port.count))
30190 return -EBUSY;
30191
30192 if (cmd != SIOCWANDEV)
30193diff --git a/drivers/char/random.c b/drivers/char/random.c
30194index b86eae9..4192a7a 100644
30195--- a/drivers/char/random.c
30196+++ b/drivers/char/random.c
30197@@ -272,8 +272,13 @@
30198 /*
30199 * Configuration information
30200 */
30201+#ifdef CONFIG_GRKERNSEC_RANDNET
30202+#define INPUT_POOL_WORDS 512
30203+#define OUTPUT_POOL_WORDS 128
30204+#else
30205 #define INPUT_POOL_WORDS 128
30206 #define OUTPUT_POOL_WORDS 32
30207+#endif
30208 #define SEC_XFER_SIZE 512
30209 #define EXTRACT_SIZE 10
30210
30211@@ -313,10 +318,17 @@ static struct poolinfo {
30212 int poolwords;
30213 int tap1, tap2, tap3, tap4, tap5;
30214 } poolinfo_table[] = {
30215+#ifdef CONFIG_GRKERNSEC_RANDNET
30216+ /* x^512 + x^411 + x^308 + x^208 +x^104 + x + 1 -- 225 */
30217+ { 512, 411, 308, 208, 104, 1 },
30218+ /* x^128 + x^103 + x^76 + x^51 + x^25 + x + 1 -- 105 */
30219+ { 128, 103, 76, 51, 25, 1 },
30220+#else
30221 /* x^128 + x^103 + x^76 + x^51 +x^25 + x + 1 -- 105 */
30222 { 128, 103, 76, 51, 25, 1 },
30223 /* x^32 + x^26 + x^20 + x^14 + x^7 + x + 1 -- 15 */
30224 { 32, 26, 20, 14, 7, 1 },
30225+#endif
30226 #if 0
30227 /* x^2048 + x^1638 + x^1231 + x^819 + x^411 + x + 1 -- 115 */
30228 { 2048, 1638, 1231, 819, 411, 1 },
30229@@ -527,8 +539,8 @@ static void _mix_pool_bytes(struct entropy_store *r, const void *in,
30230 input_rotate += i ? 7 : 14;
30231 }
30232
30233- ACCESS_ONCE(r->input_rotate) = input_rotate;
30234- ACCESS_ONCE(r->add_ptr) = i;
30235+ ACCESS_ONCE_RW(r->input_rotate) = input_rotate;
30236+ ACCESS_ONCE_RW(r->add_ptr) = i;
30237 smp_wmb();
30238
30239 if (out)
30240@@ -799,6 +811,17 @@ void add_disk_randomness(struct gendisk *disk)
30241 }
30242 #endif
30243
30244+#ifdef CONFIG_PAX_LATENT_ENTROPY
30245+u64 latent_entropy;
30246+
30247+__init void transfer_latent_entropy(void)
30248+{
30249+ mix_pool_bytes(&input_pool, &latent_entropy, sizeof(latent_entropy), NULL);
30250+ mix_pool_bytes(&nonblocking_pool, &latent_entropy, sizeof(latent_entropy), NULL);
30251+// printk(KERN_INFO "PAX: transferring latent entropy: %16llx\n", latent_entropy);
30252+}
30253+#endif
30254+
30255 /*********************************************************************
30256 *
30257 * Entropy extraction routines
30258@@ -1008,7 +1031,7 @@ static ssize_t extract_entropy_user(struct entropy_store *r, void __user *buf,
30259
30260 extract_buf(r, tmp);
30261 i = min_t(int, nbytes, EXTRACT_SIZE);
30262- if (copy_to_user(buf, tmp, i)) {
30263+ if (i > sizeof(tmp) || copy_to_user(buf, tmp, i)) {
30264 ret = -EFAULT;
30265 break;
30266 }
30267@@ -1342,7 +1365,7 @@ EXPORT_SYMBOL(generate_random_uuid);
30268 #include <linux/sysctl.h>
30269
30270 static int min_read_thresh = 8, min_write_thresh;
30271-static int max_read_thresh = INPUT_POOL_WORDS * 32;
30272+static int max_read_thresh = OUTPUT_POOL_WORDS * 32;
30273 static int max_write_thresh = INPUT_POOL_WORDS * 32;
30274 static char sysctl_bootid[16];
30275
30276diff --git a/drivers/char/sonypi.c b/drivers/char/sonypi.c
30277index f877805..403375a 100644
30278--- a/drivers/char/sonypi.c
30279+++ b/drivers/char/sonypi.c
30280@@ -54,6 +54,7 @@
30281
30282 #include <asm/uaccess.h>
30283 #include <asm/io.h>
30284+#include <asm/local.h>
30285
30286 #include <linux/sonypi.h>
30287
30288@@ -490,7 +491,7 @@ static struct sonypi_device {
30289 spinlock_t fifo_lock;
30290 wait_queue_head_t fifo_proc_list;
30291 struct fasync_struct *fifo_async;
30292- int open_count;
30293+ local_t open_count;
30294 int model;
30295 struct input_dev *input_jog_dev;
30296 struct input_dev *input_key_dev;
30297@@ -897,7 +898,7 @@ static int sonypi_misc_fasync(int fd, struct file *filp, int on)
30298 static int sonypi_misc_release(struct inode *inode, struct file *file)
30299 {
30300 mutex_lock(&sonypi_device.lock);
30301- sonypi_device.open_count--;
30302+ local_dec(&sonypi_device.open_count);
30303 mutex_unlock(&sonypi_device.lock);
30304 return 0;
30305 }
30306@@ -906,9 +907,9 @@ static int sonypi_misc_open(struct inode *inode, struct file *file)
30307 {
30308 mutex_lock(&sonypi_device.lock);
30309 /* Flush input queue on first open */
30310- if (!sonypi_device.open_count)
30311+ if (!local_read(&sonypi_device.open_count))
30312 kfifo_reset(&sonypi_device.fifo);
30313- sonypi_device.open_count++;
30314+ local_inc(&sonypi_device.open_count);
30315 mutex_unlock(&sonypi_device.lock);
30316
30317 return 0;
30318diff --git a/drivers/char/tpm/tpm.c b/drivers/char/tpm/tpm.c
30319index 4dc8024..90108d1 100644
30320--- a/drivers/char/tpm/tpm.c
30321+++ b/drivers/char/tpm/tpm.c
30322@@ -415,7 +415,7 @@ static ssize_t tpm_transmit(struct tpm_chip *chip, const char *buf,
30323 chip->vendor.req_complete_val)
30324 goto out_recv;
30325
30326- if ((status == chip->vendor.req_canceled)) {
30327+ if (status == chip->vendor.req_canceled) {
30328 dev_err(chip->dev, "Operation Canceled\n");
30329 rc = -ECANCELED;
30330 goto out;
30331diff --git a/drivers/char/tpm/tpm_bios.c b/drivers/char/tpm/tpm_bios.c
30332index 0636520..169c1d0 100644
30333--- a/drivers/char/tpm/tpm_bios.c
30334+++ b/drivers/char/tpm/tpm_bios.c
30335@@ -173,7 +173,7 @@ static void *tpm_bios_measurements_start(struct seq_file *m, loff_t *pos)
30336 event = addr;
30337
30338 if ((event->event_type == 0 && event->event_size == 0) ||
30339- ((addr + sizeof(struct tcpa_event) + event->event_size) >= limit))
30340+ (event->event_size >= limit - addr - sizeof(struct tcpa_event)))
30341 return NULL;
30342
30343 return addr;
30344@@ -198,7 +198,7 @@ static void *tpm_bios_measurements_next(struct seq_file *m, void *v,
30345 return NULL;
30346
30347 if ((event->event_type == 0 && event->event_size == 0) ||
30348- ((v + sizeof(struct tcpa_event) + event->event_size) >= limit))
30349+ (event->event_size >= limit - v - sizeof(struct tcpa_event)))
30350 return NULL;
30351
30352 (*pos)++;
30353@@ -291,7 +291,8 @@ static int tpm_binary_bios_measurements_show(struct seq_file *m, void *v)
30354 int i;
30355
30356 for (i = 0; i < sizeof(struct tcpa_event) + event->event_size; i++)
30357- seq_putc(m, data[i]);
30358+ if (!seq_putc(m, data[i]))
30359+ return -EFAULT;
30360
30361 return 0;
30362 }
30363@@ -410,8 +411,13 @@ static int read_log(struct tpm_bios_log *log)
30364 log->bios_event_log_end = log->bios_event_log + len;
30365
30366 virt = acpi_os_map_memory(start, len);
30367+ if (!virt) {
30368+ kfree(log->bios_event_log);
30369+ log->bios_event_log = NULL;
30370+ return -EFAULT;
30371+ }
30372
30373- memcpy(log->bios_event_log, virt, len);
30374+ memcpy(log->bios_event_log, (const char __force_kernel *)virt, len);
30375
30376 acpi_os_unmap_memory(virt, len);
30377 return 0;
30378diff --git a/drivers/char/virtio_console.c b/drivers/char/virtio_console.c
30379index cdf2f54..e55c197 100644
30380--- a/drivers/char/virtio_console.c
30381+++ b/drivers/char/virtio_console.c
30382@@ -563,7 +563,7 @@ static ssize_t fill_readbuf(struct port *port, char *out_buf, size_t out_count,
30383 if (to_user) {
30384 ssize_t ret;
30385
30386- ret = copy_to_user(out_buf, buf->buf + buf->offset, out_count);
30387+ ret = copy_to_user((char __force_user *)out_buf, buf->buf + buf->offset, out_count);
30388 if (ret)
30389 return -EFAULT;
30390 } else {
30391@@ -662,7 +662,7 @@ static ssize_t port_fops_read(struct file *filp, char __user *ubuf,
30392 if (!port_has_data(port) && !port->host_connected)
30393 return 0;
30394
30395- return fill_readbuf(port, ubuf, count, true);
30396+ return fill_readbuf(port, (char __force_kernel *)ubuf, count, true);
30397 }
30398
30399 static ssize_t port_fops_write(struct file *filp, const char __user *ubuf,
30400diff --git a/drivers/edac/edac_pci_sysfs.c b/drivers/edac/edac_pci_sysfs.c
30401index e164c55..3aabb50 100644
30402--- a/drivers/edac/edac_pci_sysfs.c
30403+++ b/drivers/edac/edac_pci_sysfs.c
30404@@ -26,8 +26,8 @@ static int edac_pci_log_pe = 1; /* log PCI parity errors */
30405 static int edac_pci_log_npe = 1; /* log PCI non-parity error errors */
30406 static int edac_pci_poll_msec = 1000; /* one second workq period */
30407
30408-static atomic_t pci_parity_count = ATOMIC_INIT(0);
30409-static atomic_t pci_nonparity_count = ATOMIC_INIT(0);
30410+static atomic_unchecked_t pci_parity_count = ATOMIC_INIT(0);
30411+static atomic_unchecked_t pci_nonparity_count = ATOMIC_INIT(0);
30412
30413 static struct kobject *edac_pci_top_main_kobj;
30414 static atomic_t edac_pci_sysfs_refcount = ATOMIC_INIT(0);
30415@@ -579,7 +579,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
30416 edac_printk(KERN_CRIT, EDAC_PCI,
30417 "Signaled System Error on %s\n",
30418 pci_name(dev));
30419- atomic_inc(&pci_nonparity_count);
30420+ atomic_inc_unchecked(&pci_nonparity_count);
30421 }
30422
30423 if (status & (PCI_STATUS_PARITY)) {
30424@@ -587,7 +587,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
30425 "Master Data Parity Error on %s\n",
30426 pci_name(dev));
30427
30428- atomic_inc(&pci_parity_count);
30429+ atomic_inc_unchecked(&pci_parity_count);
30430 }
30431
30432 if (status & (PCI_STATUS_DETECTED_PARITY)) {
30433@@ -595,7 +595,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
30434 "Detected Parity Error on %s\n",
30435 pci_name(dev));
30436
30437- atomic_inc(&pci_parity_count);
30438+ atomic_inc_unchecked(&pci_parity_count);
30439 }
30440 }
30441
30442@@ -618,7 +618,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
30443 edac_printk(KERN_CRIT, EDAC_PCI, "Bridge "
30444 "Signaled System Error on %s\n",
30445 pci_name(dev));
30446- atomic_inc(&pci_nonparity_count);
30447+ atomic_inc_unchecked(&pci_nonparity_count);
30448 }
30449
30450 if (status & (PCI_STATUS_PARITY)) {
30451@@ -626,7 +626,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
30452 "Master Data Parity Error on "
30453 "%s\n", pci_name(dev));
30454
30455- atomic_inc(&pci_parity_count);
30456+ atomic_inc_unchecked(&pci_parity_count);
30457 }
30458
30459 if (status & (PCI_STATUS_DETECTED_PARITY)) {
30460@@ -634,7 +634,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
30461 "Detected Parity Error on %s\n",
30462 pci_name(dev));
30463
30464- atomic_inc(&pci_parity_count);
30465+ atomic_inc_unchecked(&pci_parity_count);
30466 }
30467 }
30468 }
30469@@ -676,7 +676,7 @@ void edac_pci_do_parity_check(void)
30470 if (!check_pci_errors)
30471 return;
30472
30473- before_count = atomic_read(&pci_parity_count);
30474+ before_count = atomic_read_unchecked(&pci_parity_count);
30475
30476 /* scan all PCI devices looking for a Parity Error on devices and
30477 * bridges.
30478@@ -688,7 +688,7 @@ void edac_pci_do_parity_check(void)
30479 /* Only if operator has selected panic on PCI Error */
30480 if (edac_pci_get_panic_on_pe()) {
30481 /* If the count is different 'after' from 'before' */
30482- if (before_count != atomic_read(&pci_parity_count))
30483+ if (before_count != atomic_read_unchecked(&pci_parity_count))
30484 panic("EDAC: PCI Parity Error");
30485 }
30486 }
30487diff --git a/drivers/edac/mce_amd.h b/drivers/edac/mce_amd.h
30488index 8c87a5e..a19cbd7 100644
30489--- a/drivers/edac/mce_amd.h
30490+++ b/drivers/edac/mce_amd.h
30491@@ -80,7 +80,7 @@ extern const char * const ii_msgs[];
30492 struct amd_decoder_ops {
30493 bool (*dc_mce)(u16, u8);
30494 bool (*ic_mce)(u16, u8);
30495-};
30496+} __no_const;
30497
30498 void amd_report_gart_errors(bool);
30499 void amd_register_ecc_decoder(void (*f)(int, struct mce *));
30500diff --git a/drivers/firewire/core-card.c b/drivers/firewire/core-card.c
30501index 57ea7f4..789e3c3 100644
30502--- a/drivers/firewire/core-card.c
30503+++ b/drivers/firewire/core-card.c
30504@@ -680,7 +680,7 @@ EXPORT_SYMBOL_GPL(fw_card_release);
30505
30506 void fw_core_remove_card(struct fw_card *card)
30507 {
30508- struct fw_card_driver dummy_driver = dummy_driver_template;
30509+ fw_card_driver_no_const dummy_driver = dummy_driver_template;
30510
30511 card->driver->update_phy_reg(card, 4,
30512 PHY_LINK_ACTIVE | PHY_CONTENDER, 0);
30513diff --git a/drivers/firewire/core-cdev.c b/drivers/firewire/core-cdev.c
30514index f8d2287..5aaf4db 100644
30515--- a/drivers/firewire/core-cdev.c
30516+++ b/drivers/firewire/core-cdev.c
30517@@ -1365,8 +1365,7 @@ static int init_iso_resource(struct client *client,
30518 int ret;
30519
30520 if ((request->channels == 0 && request->bandwidth == 0) ||
30521- request->bandwidth > BANDWIDTH_AVAILABLE_INITIAL ||
30522- request->bandwidth < 0)
30523+ request->bandwidth > BANDWIDTH_AVAILABLE_INITIAL)
30524 return -EINVAL;
30525
30526 r = kmalloc(sizeof(*r), GFP_KERNEL);
30527diff --git a/drivers/firewire/core-transaction.c b/drivers/firewire/core-transaction.c
30528index 87d6f2d..5bf9d90 100644
30529--- a/drivers/firewire/core-transaction.c
30530+++ b/drivers/firewire/core-transaction.c
30531@@ -37,6 +37,7 @@
30532 #include <linux/timer.h>
30533 #include <linux/types.h>
30534 #include <linux/workqueue.h>
30535+#include <linux/sched.h>
30536
30537 #include <asm/byteorder.h>
30538
30539diff --git a/drivers/firewire/core.h b/drivers/firewire/core.h
30540index 515a42c..5ecf3ba 100644
30541--- a/drivers/firewire/core.h
30542+++ b/drivers/firewire/core.h
30543@@ -111,6 +111,7 @@ struct fw_card_driver {
30544
30545 int (*stop_iso)(struct fw_iso_context *ctx);
30546 };
30547+typedef struct fw_card_driver __no_const fw_card_driver_no_const;
30548
30549 void fw_card_initialize(struct fw_card *card,
30550 const struct fw_card_driver *driver, struct device *device);
30551diff --git a/drivers/firmware/dmi_scan.c b/drivers/firmware/dmi_scan.c
30552index b298158..7ed8432 100644
30553--- a/drivers/firmware/dmi_scan.c
30554+++ b/drivers/firmware/dmi_scan.c
30555@@ -452,11 +452,6 @@ void __init dmi_scan_machine(void)
30556 }
30557 }
30558 else {
30559- /*
30560- * no iounmap() for that ioremap(); it would be a no-op, but
30561- * it's so early in setup that sucker gets confused into doing
30562- * what it shouldn't if we actually call it.
30563- */
30564 p = dmi_ioremap(0xF0000, 0x10000);
30565 if (p == NULL)
30566 goto error;
30567@@ -726,7 +721,7 @@ int dmi_walk(void (*decode)(const struct dmi_header *, void *),
30568 if (buf == NULL)
30569 return -1;
30570
30571- dmi_table(buf, dmi_len, dmi_num, decode, private_data);
30572+ dmi_table((char __force_kernel *)buf, dmi_len, dmi_num, decode, private_data);
30573
30574 iounmap(buf);
30575 return 0;
30576diff --git a/drivers/gpio/gpio-vr41xx.c b/drivers/gpio/gpio-vr41xx.c
30577index 82d5c20..44a7177 100644
30578--- a/drivers/gpio/gpio-vr41xx.c
30579+++ b/drivers/gpio/gpio-vr41xx.c
30580@@ -204,7 +204,7 @@ static int giu_get_irq(unsigned int irq)
30581 printk(KERN_ERR "spurious GIU interrupt: %04x(%04x),%04x(%04x)\n",
30582 maskl, pendl, maskh, pendh);
30583
30584- atomic_inc(&irq_err_count);
30585+ atomic_inc_unchecked(&irq_err_count);
30586
30587 return -EINVAL;
30588 }
30589diff --git a/drivers/gpu/drm/drm_crtc_helper.c b/drivers/gpu/drm/drm_crtc_helper.c
30590index 3252e70..b5314ace 100644
30591--- a/drivers/gpu/drm/drm_crtc_helper.c
30592+++ b/drivers/gpu/drm/drm_crtc_helper.c
30593@@ -286,7 +286,7 @@ static bool drm_encoder_crtc_ok(struct drm_encoder *encoder,
30594 struct drm_crtc *tmp;
30595 int crtc_mask = 1;
30596
30597- WARN(!crtc, "checking null crtc?\n");
30598+ BUG_ON(!crtc);
30599
30600 dev = crtc->dev;
30601
30602diff --git a/drivers/gpu/drm/drm_drv.c b/drivers/gpu/drm/drm_drv.c
30603index 9238de4..a27c72a 100644
30604--- a/drivers/gpu/drm/drm_drv.c
30605+++ b/drivers/gpu/drm/drm_drv.c
30606@@ -307,7 +307,7 @@ module_exit(drm_core_exit);
30607 /**
30608 * Copy and IOCTL return string to user space
30609 */
30610-static int drm_copy_field(char *buf, size_t *buf_len, const char *value)
30611+static int drm_copy_field(char __user *buf, size_t *buf_len, const char *value)
30612 {
30613 int len;
30614
30615@@ -390,7 +390,7 @@ long drm_ioctl(struct file *filp,
30616 return -ENODEV;
30617
30618 atomic_inc(&dev->ioctl_count);
30619- atomic_inc(&dev->counts[_DRM_STAT_IOCTLS]);
30620+ atomic_inc_unchecked(&dev->counts[_DRM_STAT_IOCTLS]);
30621 ++file_priv->ioctl_count;
30622
30623 DRM_DEBUG("pid=%d, cmd=0x%02x, nr=0x%02x, dev 0x%lx, auth=%d\n",
30624diff --git a/drivers/gpu/drm/drm_fops.c b/drivers/gpu/drm/drm_fops.c
30625index 7aff5c7..bee6c27 100644
30626--- a/drivers/gpu/drm/drm_fops.c
30627+++ b/drivers/gpu/drm/drm_fops.c
30628@@ -71,7 +71,7 @@ static int drm_setup(struct drm_device * dev)
30629 }
30630
30631 for (i = 0; i < ARRAY_SIZE(dev->counts); i++)
30632- atomic_set(&dev->counts[i], 0);
30633+ atomic_set_unchecked(&dev->counts[i], 0);
30634
30635 dev->sigdata.lock = NULL;
30636
30637@@ -134,7 +134,7 @@ int drm_open(struct inode *inode, struct file *filp)
30638 if (drm_device_is_unplugged(dev))
30639 return -ENODEV;
30640
30641- if (!dev->open_count++)
30642+ if (local_inc_return(&dev->open_count) == 1)
30643 need_setup = 1;
30644 mutex_lock(&dev->struct_mutex);
30645 old_mapping = dev->dev_mapping;
30646@@ -149,7 +149,7 @@ int drm_open(struct inode *inode, struct file *filp)
30647 retcode = drm_open_helper(inode, filp, dev);
30648 if (retcode)
30649 goto err_undo;
30650- atomic_inc(&dev->counts[_DRM_STAT_OPENS]);
30651+ atomic_inc_unchecked(&dev->counts[_DRM_STAT_OPENS]);
30652 if (need_setup) {
30653 retcode = drm_setup(dev);
30654 if (retcode)
30655@@ -164,7 +164,7 @@ err_undo:
30656 iput(container_of(dev->dev_mapping, struct inode, i_data));
30657 dev->dev_mapping = old_mapping;
30658 mutex_unlock(&dev->struct_mutex);
30659- dev->open_count--;
30660+ local_dec(&dev->open_count);
30661 return retcode;
30662 }
30663 EXPORT_SYMBOL(drm_open);
30664@@ -438,7 +438,7 @@ int drm_release(struct inode *inode, struct file *filp)
30665
30666 mutex_lock(&drm_global_mutex);
30667
30668- DRM_DEBUG("open_count = %d\n", dev->open_count);
30669+ DRM_DEBUG("open_count = %ld\n", local_read(&dev->open_count));
30670
30671 if (dev->driver->preclose)
30672 dev->driver->preclose(dev, file_priv);
30673@@ -447,10 +447,10 @@ int drm_release(struct inode *inode, struct file *filp)
30674 * Begin inline drm_release
30675 */
30676
30677- DRM_DEBUG("pid = %d, device = 0x%lx, open_count = %d\n",
30678+ DRM_DEBUG("pid = %d, device = 0x%lx, open_count = %ld\n",
30679 task_pid_nr(current),
30680 (long)old_encode_dev(file_priv->minor->device),
30681- dev->open_count);
30682+ local_read(&dev->open_count));
30683
30684 /* Release any auth tokens that might point to this file_priv,
30685 (do that under the drm_global_mutex) */
30686@@ -546,8 +546,8 @@ int drm_release(struct inode *inode, struct file *filp)
30687 * End inline drm_release
30688 */
30689
30690- atomic_inc(&dev->counts[_DRM_STAT_CLOSES]);
30691- if (!--dev->open_count) {
30692+ atomic_inc_unchecked(&dev->counts[_DRM_STAT_CLOSES]);
30693+ if (local_dec_and_test(&dev->open_count)) {
30694 if (atomic_read(&dev->ioctl_count)) {
30695 DRM_ERROR("Device busy: %d\n",
30696 atomic_read(&dev->ioctl_count));
30697diff --git a/drivers/gpu/drm/drm_global.c b/drivers/gpu/drm/drm_global.c
30698index c87dc96..326055d 100644
30699--- a/drivers/gpu/drm/drm_global.c
30700+++ b/drivers/gpu/drm/drm_global.c
30701@@ -36,7 +36,7 @@
30702 struct drm_global_item {
30703 struct mutex mutex;
30704 void *object;
30705- int refcount;
30706+ atomic_t refcount;
30707 };
30708
30709 static struct drm_global_item glob[DRM_GLOBAL_NUM];
30710@@ -49,7 +49,7 @@ void drm_global_init(void)
30711 struct drm_global_item *item = &glob[i];
30712 mutex_init(&item->mutex);
30713 item->object = NULL;
30714- item->refcount = 0;
30715+ atomic_set(&item->refcount, 0);
30716 }
30717 }
30718
30719@@ -59,7 +59,7 @@ void drm_global_release(void)
30720 for (i = 0; i < DRM_GLOBAL_NUM; ++i) {
30721 struct drm_global_item *item = &glob[i];
30722 BUG_ON(item->object != NULL);
30723- BUG_ON(item->refcount != 0);
30724+ BUG_ON(atomic_read(&item->refcount) != 0);
30725 }
30726 }
30727
30728@@ -70,7 +70,7 @@ int drm_global_item_ref(struct drm_global_reference *ref)
30729 void *object;
30730
30731 mutex_lock(&item->mutex);
30732- if (item->refcount == 0) {
30733+ if (atomic_read(&item->refcount) == 0) {
30734 item->object = kzalloc(ref->size, GFP_KERNEL);
30735 if (unlikely(item->object == NULL)) {
30736 ret = -ENOMEM;
30737@@ -83,7 +83,7 @@ int drm_global_item_ref(struct drm_global_reference *ref)
30738 goto out_err;
30739
30740 }
30741- ++item->refcount;
30742+ atomic_inc(&item->refcount);
30743 ref->object = item->object;
30744 object = item->object;
30745 mutex_unlock(&item->mutex);
30746@@ -100,9 +100,9 @@ void drm_global_item_unref(struct drm_global_reference *ref)
30747 struct drm_global_item *item = &glob[ref->global_type];
30748
30749 mutex_lock(&item->mutex);
30750- BUG_ON(item->refcount == 0);
30751+ BUG_ON(atomic_read(&item->refcount) == 0);
30752 BUG_ON(ref->object != item->object);
30753- if (--item->refcount == 0) {
30754+ if (atomic_dec_and_test(&item->refcount)) {
30755 ref->release(ref);
30756 item->object = NULL;
30757 }
30758diff --git a/drivers/gpu/drm/drm_info.c b/drivers/gpu/drm/drm_info.c
30759index 8928edb..0c79258 100644
30760--- a/drivers/gpu/drm/drm_info.c
30761+++ b/drivers/gpu/drm/drm_info.c
30762@@ -75,10 +75,14 @@ int drm_vm_info(struct seq_file *m, void *data)
30763 struct drm_local_map *map;
30764 struct drm_map_list *r_list;
30765
30766- /* Hardcoded from _DRM_FRAME_BUFFER,
30767- _DRM_REGISTERS, _DRM_SHM, _DRM_AGP, and
30768- _DRM_SCATTER_GATHER and _DRM_CONSISTENT */
30769- const char *types[] = { "FB", "REG", "SHM", "AGP", "SG", "PCI" };
30770+ static const char * const types[] = {
30771+ [_DRM_FRAME_BUFFER] = "FB",
30772+ [_DRM_REGISTERS] = "REG",
30773+ [_DRM_SHM] = "SHM",
30774+ [_DRM_AGP] = "AGP",
30775+ [_DRM_SCATTER_GATHER] = "SG",
30776+ [_DRM_CONSISTENT] = "PCI",
30777+ [_DRM_GEM] = "GEM" };
30778 const char *type;
30779 int i;
30780
30781@@ -89,7 +93,7 @@ int drm_vm_info(struct seq_file *m, void *data)
30782 map = r_list->map;
30783 if (!map)
30784 continue;
30785- if (map->type < 0 || map->type > 5)
30786+ if (map->type >= ARRAY_SIZE(types))
30787 type = "??";
30788 else
30789 type = types[map->type];
30790@@ -254,7 +258,11 @@ int drm_vma_info(struct seq_file *m, void *data)
30791 vma->vm_flags & VM_MAYSHARE ? 's' : 'p',
30792 vma->vm_flags & VM_LOCKED ? 'l' : '-',
30793 vma->vm_flags & VM_IO ? 'i' : '-',
30794+#ifdef CONFIG_GRKERNSEC_HIDESYM
30795+ 0);
30796+#else
30797 vma->vm_pgoff);
30798+#endif
30799
30800 #if defined(__i386__)
30801 pgprot = pgprot_val(vma->vm_page_prot);
30802diff --git a/drivers/gpu/drm/drm_ioc32.c b/drivers/gpu/drm/drm_ioc32.c
30803index 637fcc3..e890b33 100644
30804--- a/drivers/gpu/drm/drm_ioc32.c
30805+++ b/drivers/gpu/drm/drm_ioc32.c
30806@@ -457,7 +457,7 @@ static int compat_drm_infobufs(struct file *file, unsigned int cmd,
30807 request = compat_alloc_user_space(nbytes);
30808 if (!access_ok(VERIFY_WRITE, request, nbytes))
30809 return -EFAULT;
30810- list = (struct drm_buf_desc *) (request + 1);
30811+ list = (struct drm_buf_desc __user *) (request + 1);
30812
30813 if (__put_user(count, &request->count)
30814 || __put_user(list, &request->list))
30815@@ -518,7 +518,7 @@ static int compat_drm_mapbufs(struct file *file, unsigned int cmd,
30816 request = compat_alloc_user_space(nbytes);
30817 if (!access_ok(VERIFY_WRITE, request, nbytes))
30818 return -EFAULT;
30819- list = (struct drm_buf_pub *) (request + 1);
30820+ list = (struct drm_buf_pub __user *) (request + 1);
30821
30822 if (__put_user(count, &request->count)
30823 || __put_user(list, &request->list))
30824diff --git a/drivers/gpu/drm/drm_ioctl.c b/drivers/gpu/drm/drm_ioctl.c
30825index 64a62c6..ceab35e 100644
30826--- a/drivers/gpu/drm/drm_ioctl.c
30827+++ b/drivers/gpu/drm/drm_ioctl.c
30828@@ -252,7 +252,7 @@ int drm_getstats(struct drm_device *dev, void *data,
30829 stats->data[i].value =
30830 (file_priv->master->lock.hw_lock ? file_priv->master->lock.hw_lock->lock : 0);
30831 else
30832- stats->data[i].value = atomic_read(&dev->counts[i]);
30833+ stats->data[i].value = atomic_read_unchecked(&dev->counts[i]);
30834 stats->data[i].type = dev->types[i];
30835 }
30836
30837diff --git a/drivers/gpu/drm/drm_lock.c b/drivers/gpu/drm/drm_lock.c
30838index 3203955..c8090af 100644
30839--- a/drivers/gpu/drm/drm_lock.c
30840+++ b/drivers/gpu/drm/drm_lock.c
30841@@ -86,7 +86,7 @@ int drm_lock(struct drm_device *dev, void *data, struct drm_file *file_priv)
30842 if (drm_lock_take(&master->lock, lock->context)) {
30843 master->lock.file_priv = file_priv;
30844 master->lock.lock_time = jiffies;
30845- atomic_inc(&dev->counts[_DRM_STAT_LOCKS]);
30846+ atomic_inc_unchecked(&dev->counts[_DRM_STAT_LOCKS]);
30847 break; /* Got lock */
30848 }
30849
30850@@ -157,7 +157,7 @@ int drm_unlock(struct drm_device *dev, void *data, struct drm_file *file_priv)
30851 return -EINVAL;
30852 }
30853
30854- atomic_inc(&dev->counts[_DRM_STAT_UNLOCKS]);
30855+ atomic_inc_unchecked(&dev->counts[_DRM_STAT_UNLOCKS]);
30856
30857 if (drm_lock_free(&master->lock, lock->context)) {
30858 /* FIXME: Should really bail out here. */
30859diff --git a/drivers/gpu/drm/drm_stub.c b/drivers/gpu/drm/drm_stub.c
30860index 21bcd4a..8e074e0 100644
30861--- a/drivers/gpu/drm/drm_stub.c
30862+++ b/drivers/gpu/drm/drm_stub.c
30863@@ -511,7 +511,7 @@ void drm_unplug_dev(struct drm_device *dev)
30864
30865 drm_device_set_unplugged(dev);
30866
30867- if (dev->open_count == 0) {
30868+ if (local_read(&dev->open_count) == 0) {
30869 drm_put_dev(dev);
30870 }
30871 mutex_unlock(&drm_global_mutex);
30872diff --git a/drivers/gpu/drm/i810/i810_dma.c b/drivers/gpu/drm/i810/i810_dma.c
30873index 463ec68..f5bd2b5 100644
30874--- a/drivers/gpu/drm/i810/i810_dma.c
30875+++ b/drivers/gpu/drm/i810/i810_dma.c
30876@@ -946,8 +946,8 @@ static int i810_dma_vertex(struct drm_device *dev, void *data,
30877 dma->buflist[vertex->idx],
30878 vertex->discard, vertex->used);
30879
30880- atomic_add(vertex->used, &dev->counts[_DRM_STAT_SECONDARY]);
30881- atomic_inc(&dev->counts[_DRM_STAT_DMA]);
30882+ atomic_add_unchecked(vertex->used, &dev->counts[_DRM_STAT_SECONDARY]);
30883+ atomic_inc_unchecked(&dev->counts[_DRM_STAT_DMA]);
30884 sarea_priv->last_enqueue = dev_priv->counter - 1;
30885 sarea_priv->last_dispatch = (int)hw_status[5];
30886
30887@@ -1107,8 +1107,8 @@ static int i810_dma_mc(struct drm_device *dev, void *data,
30888 i810_dma_dispatch_mc(dev, dma->buflist[mc->idx], mc->used,
30889 mc->last_render);
30890
30891- atomic_add(mc->used, &dev->counts[_DRM_STAT_SECONDARY]);
30892- atomic_inc(&dev->counts[_DRM_STAT_DMA]);
30893+ atomic_add_unchecked(mc->used, &dev->counts[_DRM_STAT_SECONDARY]);
30894+ atomic_inc_unchecked(&dev->counts[_DRM_STAT_DMA]);
30895 sarea_priv->last_enqueue = dev_priv->counter - 1;
30896 sarea_priv->last_dispatch = (int)hw_status[5];
30897
30898diff --git a/drivers/gpu/drm/i810/i810_drv.h b/drivers/gpu/drm/i810/i810_drv.h
30899index 6e0acad..93c8289 100644
30900--- a/drivers/gpu/drm/i810/i810_drv.h
30901+++ b/drivers/gpu/drm/i810/i810_drv.h
30902@@ -108,8 +108,8 @@ typedef struct drm_i810_private {
30903 int page_flipping;
30904
30905 wait_queue_head_t irq_queue;
30906- atomic_t irq_received;
30907- atomic_t irq_emitted;
30908+ atomic_unchecked_t irq_received;
30909+ atomic_unchecked_t irq_emitted;
30910
30911 int front_offset;
30912 } drm_i810_private_t;
30913diff --git a/drivers/gpu/drm/i915/i915_debugfs.c b/drivers/gpu/drm/i915/i915_debugfs.c
30914index 359f6e8..ada68fd 100644
30915--- a/drivers/gpu/drm/i915/i915_debugfs.c
30916+++ b/drivers/gpu/drm/i915/i915_debugfs.c
30917@@ -518,7 +518,7 @@ static int i915_interrupt_info(struct seq_file *m, void *data)
30918 I915_READ(GTIMR));
30919 }
30920 seq_printf(m, "Interrupts received: %d\n",
30921- atomic_read(&dev_priv->irq_received));
30922+ atomic_read_unchecked(&dev_priv->irq_received));
30923 for (i = 0; i < I915_NUM_RINGS; i++) {
30924 if (IS_GEN6(dev) || IS_GEN7(dev)) {
30925 seq_printf(m, "Graphics Interrupt mask (%s): %08x\n",
30926diff --git a/drivers/gpu/drm/i915/i915_dma.c b/drivers/gpu/drm/i915/i915_dma.c
30927index 0969a7c..b9ffa45 100644
30928--- a/drivers/gpu/drm/i915/i915_dma.c
30929+++ b/drivers/gpu/drm/i915/i915_dma.c
30930@@ -1269,7 +1269,7 @@ static bool i915_switcheroo_can_switch(struct pci_dev *pdev)
30931 bool can_switch;
30932
30933 spin_lock(&dev->count_lock);
30934- can_switch = (dev->open_count == 0);
30935+ can_switch = (local_read(&dev->open_count) == 0);
30936 spin_unlock(&dev->count_lock);
30937 return can_switch;
30938 }
30939diff --git a/drivers/gpu/drm/i915/i915_drv.h b/drivers/gpu/drm/i915/i915_drv.h
30940index 627fe35..c9a7346 100644
30941--- a/drivers/gpu/drm/i915/i915_drv.h
30942+++ b/drivers/gpu/drm/i915/i915_drv.h
30943@@ -272,12 +272,12 @@ struct drm_i915_display_funcs {
30944 /* render clock increase/decrease */
30945 /* display clock increase/decrease */
30946 /* pll clock increase/decrease */
30947-};
30948+} __no_const;
30949
30950 struct drm_i915_gt_funcs {
30951 void (*force_wake_get)(struct drm_i915_private *dev_priv);
30952 void (*force_wake_put)(struct drm_i915_private *dev_priv);
30953-};
30954+} __no_const;
30955
30956 struct intel_device_info {
30957 u8 gen;
30958@@ -408,7 +408,7 @@ typedef struct drm_i915_private {
30959 int current_page;
30960 int page_flipping;
30961
30962- atomic_t irq_received;
30963+ atomic_unchecked_t irq_received;
30964
30965 /* protects the irq masks */
30966 spinlock_t irq_lock;
30967@@ -1014,7 +1014,7 @@ struct drm_i915_gem_object {
30968 * will be page flipped away on the next vblank. When it
30969 * reaches 0, dev_priv->pending_flip_queue will be woken up.
30970 */
30971- atomic_t pending_flip;
30972+ atomic_unchecked_t pending_flip;
30973 };
30974
30975 #define to_intel_bo(x) container_of(x, struct drm_i915_gem_object, base)
30976@@ -1482,7 +1482,7 @@ extern struct i2c_adapter *intel_gmbus_get_adapter(
30977 struct drm_i915_private *dev_priv, unsigned port);
30978 extern void intel_gmbus_set_speed(struct i2c_adapter *adapter, int speed);
30979 extern void intel_gmbus_force_bit(struct i2c_adapter *adapter, bool force_bit);
30980-extern inline bool intel_gmbus_is_forced_bit(struct i2c_adapter *adapter)
30981+static inline bool intel_gmbus_is_forced_bit(struct i2c_adapter *adapter)
30982 {
30983 return container_of(adapter, struct intel_gmbus, adapter)->force_bit;
30984 }
30985diff --git a/drivers/gpu/drm/i915/i915_gem_execbuffer.c b/drivers/gpu/drm/i915/i915_gem_execbuffer.c
30986index cdf46b5..e785624 100644
30987--- a/drivers/gpu/drm/i915/i915_gem_execbuffer.c
30988+++ b/drivers/gpu/drm/i915/i915_gem_execbuffer.c
30989@@ -189,7 +189,7 @@ i915_gem_object_set_to_gpu_domain(struct drm_i915_gem_object *obj,
30990 i915_gem_clflush_object(obj);
30991
30992 if (obj->base.pending_write_domain)
30993- cd->flips |= atomic_read(&obj->pending_flip);
30994+ cd->flips |= atomic_read_unchecked(&obj->pending_flip);
30995
30996 /* The actual obj->write_domain will be updated with
30997 * pending_write_domain after we emit the accumulated flush for all
30998@@ -907,9 +907,9 @@ i915_gem_check_execbuffer(struct drm_i915_gem_execbuffer2 *exec)
30999
31000 static int
31001 validate_exec_list(struct drm_i915_gem_exec_object2 *exec,
31002- int count)
31003+ unsigned int count)
31004 {
31005- int i;
31006+ unsigned int i;
31007
31008 for (i = 0; i < count; i++) {
31009 char __user *ptr = (char __user *)(uintptr_t)exec[i].relocs_ptr;
31010diff --git a/drivers/gpu/drm/i915/i915_irq.c b/drivers/gpu/drm/i915/i915_irq.c
31011index 73fa3e1..ab2e9b9 100644
31012--- a/drivers/gpu/drm/i915/i915_irq.c
31013+++ b/drivers/gpu/drm/i915/i915_irq.c
31014@@ -514,7 +514,7 @@ static irqreturn_t valleyview_irq_handler(DRM_IRQ_ARGS)
31015 u32 pipe_stats[I915_MAX_PIPES];
31016 bool blc_event;
31017
31018- atomic_inc(&dev_priv->irq_received);
31019+ atomic_inc_unchecked(&dev_priv->irq_received);
31020
31021 while (true) {
31022 iir = I915_READ(VLV_IIR);
31023@@ -661,7 +661,7 @@ static irqreturn_t ivybridge_irq_handler(DRM_IRQ_ARGS)
31024 irqreturn_t ret = IRQ_NONE;
31025 int i;
31026
31027- atomic_inc(&dev_priv->irq_received);
31028+ atomic_inc_unchecked(&dev_priv->irq_received);
31029
31030 /* disable master interrupt before clearing iir */
31031 de_ier = I915_READ(DEIER);
31032@@ -736,7 +736,7 @@ static irqreturn_t ironlake_irq_handler(DRM_IRQ_ARGS)
31033 u32 de_iir, gt_iir, de_ier, pch_iir, pm_iir;
31034 u32 hotplug_mask;
31035
31036- atomic_inc(&dev_priv->irq_received);
31037+ atomic_inc_unchecked(&dev_priv->irq_received);
31038
31039 /* disable master interrupt before clearing iir */
31040 de_ier = I915_READ(DEIER);
31041@@ -1717,7 +1717,7 @@ static void ironlake_irq_preinstall(struct drm_device *dev)
31042 {
31043 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
31044
31045- atomic_set(&dev_priv->irq_received, 0);
31046+ atomic_set_unchecked(&dev_priv->irq_received, 0);
31047
31048 I915_WRITE(HWSTAM, 0xeffe);
31049
31050@@ -1743,7 +1743,7 @@ static void valleyview_irq_preinstall(struct drm_device *dev)
31051 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
31052 int pipe;
31053
31054- atomic_set(&dev_priv->irq_received, 0);
31055+ atomic_set_unchecked(&dev_priv->irq_received, 0);
31056
31057 /* VLV magic */
31058 I915_WRITE(VLV_IMR, 0);
31059@@ -2048,7 +2048,7 @@ static void i8xx_irq_preinstall(struct drm_device * dev)
31060 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
31061 int pipe;
31062
31063- atomic_set(&dev_priv->irq_received, 0);
31064+ atomic_set_unchecked(&dev_priv->irq_received, 0);
31065
31066 for_each_pipe(pipe)
31067 I915_WRITE(PIPESTAT(pipe), 0);
31068@@ -2099,7 +2099,7 @@ static irqreturn_t i8xx_irq_handler(DRM_IRQ_ARGS)
31069 I915_DISPLAY_PLANE_A_FLIP_PENDING_INTERRUPT |
31070 I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT;
31071
31072- atomic_inc(&dev_priv->irq_received);
31073+ atomic_inc_unchecked(&dev_priv->irq_received);
31074
31075 iir = I915_READ16(IIR);
31076 if (iir == 0)
31077@@ -2184,7 +2184,7 @@ static void i915_irq_preinstall(struct drm_device * dev)
31078 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
31079 int pipe;
31080
31081- atomic_set(&dev_priv->irq_received, 0);
31082+ atomic_set_unchecked(&dev_priv->irq_received, 0);
31083
31084 if (I915_HAS_HOTPLUG(dev)) {
31085 I915_WRITE(PORT_HOTPLUG_EN, 0);
31086@@ -2279,7 +2279,7 @@ static irqreturn_t i915_irq_handler(DRM_IRQ_ARGS)
31087 };
31088 int pipe, ret = IRQ_NONE;
31089
31090- atomic_inc(&dev_priv->irq_received);
31091+ atomic_inc_unchecked(&dev_priv->irq_received);
31092
31093 iir = I915_READ(IIR);
31094 do {
31095@@ -2405,7 +2405,7 @@ static void i965_irq_preinstall(struct drm_device * dev)
31096 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
31097 int pipe;
31098
31099- atomic_set(&dev_priv->irq_received, 0);
31100+ atomic_set_unchecked(&dev_priv->irq_received, 0);
31101
31102 I915_WRITE(PORT_HOTPLUG_EN, 0);
31103 I915_WRITE(PORT_HOTPLUG_STAT, I915_READ(PORT_HOTPLUG_STAT));
31104@@ -2512,7 +2512,7 @@ static irqreturn_t i965_irq_handler(DRM_IRQ_ARGS)
31105 int irq_received;
31106 int ret = IRQ_NONE, pipe;
31107
31108- atomic_inc(&dev_priv->irq_received);
31109+ atomic_inc_unchecked(&dev_priv->irq_received);
31110
31111 iir = I915_READ(IIR);
31112
31113diff --git a/drivers/gpu/drm/i915/intel_display.c b/drivers/gpu/drm/i915/intel_display.c
31114index b634f6f..43c62f5 100644
31115--- a/drivers/gpu/drm/i915/intel_display.c
31116+++ b/drivers/gpu/drm/i915/intel_display.c
31117@@ -2182,7 +2182,7 @@ intel_finish_fb(struct drm_framebuffer *old_fb)
31118
31119 wait_event(dev_priv->pending_flip_queue,
31120 atomic_read(&dev_priv->mm.wedged) ||
31121- atomic_read(&obj->pending_flip) == 0);
31122+ atomic_read_unchecked(&obj->pending_flip) == 0);
31123
31124 /* Big Hammer, we also need to ensure that any pending
31125 * MI_WAIT_FOR_EVENT inside a user batch buffer on the
31126@@ -6168,8 +6168,7 @@ static void do_intel_finish_page_flip(struct drm_device *dev,
31127
31128 obj = work->old_fb_obj;
31129
31130- atomic_clear_mask(1 << intel_crtc->plane,
31131- &obj->pending_flip.counter);
31132+ atomic_clear_mask_unchecked(1 << intel_crtc->plane, &obj->pending_flip);
31133
31134 wake_up(&dev_priv->pending_flip_queue);
31135 schedule_work(&work->work);
31136@@ -6515,7 +6514,7 @@ static int intel_crtc_page_flip(struct drm_crtc *crtc,
31137 /* Block clients from rendering to the new back buffer until
31138 * the flip occurs and the object is no longer visible.
31139 */
31140- atomic_add(1 << intel_crtc->plane, &work->old_fb_obj->pending_flip);
31141+ atomic_add_unchecked(1 << intel_crtc->plane, &work->old_fb_obj->pending_flip);
31142
31143 ret = dev_priv->display.queue_flip(dev, crtc, fb, obj);
31144 if (ret)
31145@@ -6530,7 +6529,7 @@ static int intel_crtc_page_flip(struct drm_crtc *crtc,
31146 return 0;
31147
31148 cleanup_pending:
31149- atomic_sub(1 << intel_crtc->plane, &work->old_fb_obj->pending_flip);
31150+ atomic_sub_unchecked(1 << intel_crtc->plane, &work->old_fb_obj->pending_flip);
31151 drm_gem_object_unreference(&work->old_fb_obj->base);
31152 drm_gem_object_unreference(&obj->base);
31153 mutex_unlock(&dev->struct_mutex);
31154diff --git a/drivers/gpu/drm/mga/mga_drv.h b/drivers/gpu/drm/mga/mga_drv.h
31155index 54558a0..2d97005 100644
31156--- a/drivers/gpu/drm/mga/mga_drv.h
31157+++ b/drivers/gpu/drm/mga/mga_drv.h
31158@@ -120,9 +120,9 @@ typedef struct drm_mga_private {
31159 u32 clear_cmd;
31160 u32 maccess;
31161
31162- atomic_t vbl_received; /**< Number of vblanks received. */
31163+ atomic_unchecked_t vbl_received; /**< Number of vblanks received. */
31164 wait_queue_head_t fence_queue;
31165- atomic_t last_fence_retired;
31166+ atomic_unchecked_t last_fence_retired;
31167 u32 next_fence_to_post;
31168
31169 unsigned int fb_cpp;
31170diff --git a/drivers/gpu/drm/mga/mga_irq.c b/drivers/gpu/drm/mga/mga_irq.c
31171index 2581202..f230a8d9 100644
31172--- a/drivers/gpu/drm/mga/mga_irq.c
31173+++ b/drivers/gpu/drm/mga/mga_irq.c
31174@@ -44,7 +44,7 @@ u32 mga_get_vblank_counter(struct drm_device *dev, int crtc)
31175 if (crtc != 0)
31176 return 0;
31177
31178- return atomic_read(&dev_priv->vbl_received);
31179+ return atomic_read_unchecked(&dev_priv->vbl_received);
31180 }
31181
31182
31183@@ -60,7 +60,7 @@ irqreturn_t mga_driver_irq_handler(DRM_IRQ_ARGS)
31184 /* VBLANK interrupt */
31185 if (status & MGA_VLINEPEN) {
31186 MGA_WRITE(MGA_ICLEAR, MGA_VLINEICLR);
31187- atomic_inc(&dev_priv->vbl_received);
31188+ atomic_inc_unchecked(&dev_priv->vbl_received);
31189 drm_handle_vblank(dev, 0);
31190 handled = 1;
31191 }
31192@@ -79,7 +79,7 @@ irqreturn_t mga_driver_irq_handler(DRM_IRQ_ARGS)
31193 if ((prim_start & ~0x03) != (prim_end & ~0x03))
31194 MGA_WRITE(MGA_PRIMEND, prim_end);
31195
31196- atomic_inc(&dev_priv->last_fence_retired);
31197+ atomic_inc_unchecked(&dev_priv->last_fence_retired);
31198 DRM_WAKEUP(&dev_priv->fence_queue);
31199 handled = 1;
31200 }
31201@@ -130,7 +130,7 @@ int mga_driver_fence_wait(struct drm_device *dev, unsigned int *sequence)
31202 * using fences.
31203 */
31204 DRM_WAIT_ON(ret, dev_priv->fence_queue, 3 * DRM_HZ,
31205- (((cur_fence = atomic_read(&dev_priv->last_fence_retired))
31206+ (((cur_fence = atomic_read_unchecked(&dev_priv->last_fence_retired))
31207 - *sequence) <= (1 << 23)));
31208
31209 *sequence = cur_fence;
31210diff --git a/drivers/gpu/drm/nouveau/nouveau_bios.c b/drivers/gpu/drm/nouveau/nouveau_bios.c
31211index a0a3fe3..209bf10 100644
31212--- a/drivers/gpu/drm/nouveau/nouveau_bios.c
31213+++ b/drivers/gpu/drm/nouveau/nouveau_bios.c
31214@@ -5340,7 +5340,7 @@ parse_bit_U_tbl_entry(struct drm_device *dev, struct nvbios *bios,
31215 struct bit_table {
31216 const char id;
31217 int (* const parse_fn)(struct drm_device *, struct nvbios *, struct bit_entry *);
31218-};
31219+} __no_const;
31220
31221 #define BIT_TABLE(id, funcid) ((struct bit_table){ id, parse_bit_##funcid##_tbl_entry })
31222
31223diff --git a/drivers/gpu/drm/nouveau/nouveau_drv.h b/drivers/gpu/drm/nouveau/nouveau_drv.h
31224index 4f2cc95..9c6c510 100644
31225--- a/drivers/gpu/drm/nouveau/nouveau_drv.h
31226+++ b/drivers/gpu/drm/nouveau/nouveau_drv.h
31227@@ -302,7 +302,7 @@ struct nouveau_exec_engine {
31228 u32 handle, u16 class);
31229 void (*set_tile_region)(struct drm_device *dev, int i);
31230 void (*tlb_flush)(struct drm_device *, int engine);
31231-};
31232+} __no_const;
31233
31234 struct nouveau_instmem_engine {
31235 void *priv;
31236@@ -324,13 +324,13 @@ struct nouveau_instmem_engine {
31237 struct nouveau_mc_engine {
31238 int (*init)(struct drm_device *dev);
31239 void (*takedown)(struct drm_device *dev);
31240-};
31241+} __no_const;
31242
31243 struct nouveau_timer_engine {
31244 int (*init)(struct drm_device *dev);
31245 void (*takedown)(struct drm_device *dev);
31246 uint64_t (*read)(struct drm_device *dev);
31247-};
31248+} __no_const;
31249
31250 struct nouveau_fb_engine {
31251 int num_tiles;
31252@@ -547,7 +547,7 @@ struct nouveau_vram_engine {
31253 void (*put)(struct drm_device *, struct nouveau_mem **);
31254
31255 bool (*flags_valid)(struct drm_device *, u32 tile_flags);
31256-};
31257+} __no_const;
31258
31259 struct nouveau_engine {
31260 struct nouveau_instmem_engine instmem;
31261@@ -693,7 +693,7 @@ struct drm_nouveau_private {
31262 struct drm_global_reference mem_global_ref;
31263 struct ttm_bo_global_ref bo_global_ref;
31264 struct ttm_bo_device bdev;
31265- atomic_t validate_sequence;
31266+ atomic_unchecked_t validate_sequence;
31267 int (*move)(struct nouveau_channel *,
31268 struct ttm_buffer_object *,
31269 struct ttm_mem_reg *, struct ttm_mem_reg *);
31270diff --git a/drivers/gpu/drm/nouveau/nouveau_gem.c b/drivers/gpu/drm/nouveau/nouveau_gem.c
31271index af7cfb8..aadc2a3 100644
31272--- a/drivers/gpu/drm/nouveau/nouveau_gem.c
31273+++ b/drivers/gpu/drm/nouveau/nouveau_gem.c
31274@@ -318,7 +318,7 @@ validate_init(struct nouveau_channel *chan, struct drm_file *file_priv,
31275 int trycnt = 0;
31276 int ret, i;
31277
31278- sequence = atomic_add_return(1, &dev_priv->ttm.validate_sequence);
31279+ sequence = atomic_add_return_unchecked(1, &dev_priv->ttm.validate_sequence);
31280 retry:
31281 if (++trycnt > 100000) {
31282 NV_ERROR(dev, "%s failed and gave up.\n", __func__);
31283diff --git a/drivers/gpu/drm/nouveau/nouveau_state.c b/drivers/gpu/drm/nouveau/nouveau_state.c
31284index f5e9584..05934ba 100644
31285--- a/drivers/gpu/drm/nouveau/nouveau_state.c
31286+++ b/drivers/gpu/drm/nouveau/nouveau_state.c
31287@@ -492,7 +492,7 @@ static bool nouveau_switcheroo_can_switch(struct pci_dev *pdev)
31288 bool can_switch;
31289
31290 spin_lock(&dev->count_lock);
31291- can_switch = (dev->open_count == 0);
31292+ can_switch = (local_read(&dev->open_count) == 0);
31293 spin_unlock(&dev->count_lock);
31294 return can_switch;
31295 }
31296diff --git a/drivers/gpu/drm/nouveau/nv50_sor.c b/drivers/gpu/drm/nouveau/nv50_sor.c
31297index 93240bd..c490f60 100644
31298--- a/drivers/gpu/drm/nouveau/nv50_sor.c
31299+++ b/drivers/gpu/drm/nouveau/nv50_sor.c
31300@@ -304,7 +304,7 @@ nv50_sor_dpms(struct drm_encoder *encoder, int mode)
31301 }
31302
31303 if (nv_encoder->dcb->type == OUTPUT_DP) {
31304- struct dp_train_func func = {
31305+ static struct dp_train_func func = {
31306 .link_set = nv50_sor_dp_link_set,
31307 .train_set = nv50_sor_dp_train_set,
31308 .train_adj = nv50_sor_dp_train_adj
31309diff --git a/drivers/gpu/drm/nouveau/nvd0_display.c b/drivers/gpu/drm/nouveau/nvd0_display.c
31310index 8a2fc89..3a5cf40 100644
31311--- a/drivers/gpu/drm/nouveau/nvd0_display.c
31312+++ b/drivers/gpu/drm/nouveau/nvd0_display.c
31313@@ -1367,7 +1367,7 @@ nvd0_sor_dpms(struct drm_encoder *encoder, int mode)
31314 nv_wait(dev, 0x61c030 + (or * 0x0800), 0x10000000, 0x00000000);
31315
31316 if (nv_encoder->dcb->type == OUTPUT_DP) {
31317- struct dp_train_func func = {
31318+ static struct dp_train_func func = {
31319 .link_set = nvd0_sor_dp_link_set,
31320 .train_set = nvd0_sor_dp_train_set,
31321 .train_adj = nvd0_sor_dp_train_adj
31322diff --git a/drivers/gpu/drm/r128/r128_cce.c b/drivers/gpu/drm/r128/r128_cce.c
31323index bcac90b..53bfc76 100644
31324--- a/drivers/gpu/drm/r128/r128_cce.c
31325+++ b/drivers/gpu/drm/r128/r128_cce.c
31326@@ -378,7 +378,7 @@ static int r128_do_init_cce(struct drm_device *dev, drm_r128_init_t *init)
31327
31328 /* GH: Simple idle check.
31329 */
31330- atomic_set(&dev_priv->idle_count, 0);
31331+ atomic_set_unchecked(&dev_priv->idle_count, 0);
31332
31333 /* We don't support anything other than bus-mastering ring mode,
31334 * but the ring can be in either AGP or PCI space for the ring
31335diff --git a/drivers/gpu/drm/r128/r128_drv.h b/drivers/gpu/drm/r128/r128_drv.h
31336index 930c71b..499aded 100644
31337--- a/drivers/gpu/drm/r128/r128_drv.h
31338+++ b/drivers/gpu/drm/r128/r128_drv.h
31339@@ -90,14 +90,14 @@ typedef struct drm_r128_private {
31340 int is_pci;
31341 unsigned long cce_buffers_offset;
31342
31343- atomic_t idle_count;
31344+ atomic_unchecked_t idle_count;
31345
31346 int page_flipping;
31347 int current_page;
31348 u32 crtc_offset;
31349 u32 crtc_offset_cntl;
31350
31351- atomic_t vbl_received;
31352+ atomic_unchecked_t vbl_received;
31353
31354 u32 color_fmt;
31355 unsigned int front_offset;
31356diff --git a/drivers/gpu/drm/r128/r128_irq.c b/drivers/gpu/drm/r128/r128_irq.c
31357index 429d5a0..7e899ed 100644
31358--- a/drivers/gpu/drm/r128/r128_irq.c
31359+++ b/drivers/gpu/drm/r128/r128_irq.c
31360@@ -42,7 +42,7 @@ u32 r128_get_vblank_counter(struct drm_device *dev, int crtc)
31361 if (crtc != 0)
31362 return 0;
31363
31364- return atomic_read(&dev_priv->vbl_received);
31365+ return atomic_read_unchecked(&dev_priv->vbl_received);
31366 }
31367
31368 irqreturn_t r128_driver_irq_handler(DRM_IRQ_ARGS)
31369@@ -56,7 +56,7 @@ irqreturn_t r128_driver_irq_handler(DRM_IRQ_ARGS)
31370 /* VBLANK interrupt */
31371 if (status & R128_CRTC_VBLANK_INT) {
31372 R128_WRITE(R128_GEN_INT_STATUS, R128_CRTC_VBLANK_INT_AK);
31373- atomic_inc(&dev_priv->vbl_received);
31374+ atomic_inc_unchecked(&dev_priv->vbl_received);
31375 drm_handle_vblank(dev, 0);
31376 return IRQ_HANDLED;
31377 }
31378diff --git a/drivers/gpu/drm/r128/r128_state.c b/drivers/gpu/drm/r128/r128_state.c
31379index a9e33ce..09edd4b 100644
31380--- a/drivers/gpu/drm/r128/r128_state.c
31381+++ b/drivers/gpu/drm/r128/r128_state.c
31382@@ -321,10 +321,10 @@ static void r128_clear_box(drm_r128_private_t *dev_priv,
31383
31384 static void r128_cce_performance_boxes(drm_r128_private_t *dev_priv)
31385 {
31386- if (atomic_read(&dev_priv->idle_count) == 0)
31387+ if (atomic_read_unchecked(&dev_priv->idle_count) == 0)
31388 r128_clear_box(dev_priv, 64, 4, 8, 8, 0, 255, 0);
31389 else
31390- atomic_set(&dev_priv->idle_count, 0);
31391+ atomic_set_unchecked(&dev_priv->idle_count, 0);
31392 }
31393
31394 #endif
31395diff --git a/drivers/gpu/drm/radeon/mkregtable.c b/drivers/gpu/drm/radeon/mkregtable.c
31396index 5a82b6b..9e69c73 100644
31397--- a/drivers/gpu/drm/radeon/mkregtable.c
31398+++ b/drivers/gpu/drm/radeon/mkregtable.c
31399@@ -637,14 +637,14 @@ static int parser_auth(struct table *t, const char *filename)
31400 regex_t mask_rex;
31401 regmatch_t match[4];
31402 char buf[1024];
31403- size_t end;
31404+ long end;
31405 int len;
31406 int done = 0;
31407 int r;
31408 unsigned o;
31409 struct offset *offset;
31410 char last_reg_s[10];
31411- int last_reg;
31412+ unsigned long last_reg;
31413
31414 if (regcomp
31415 (&mask_rex, "(0x[0-9a-fA-F]*) *([_a-zA-Z0-9]*)", REG_EXTENDED)) {
31416diff --git a/drivers/gpu/drm/radeon/radeon.h b/drivers/gpu/drm/radeon/radeon.h
31417index 59a1531..3bab49b 100644
31418--- a/drivers/gpu/drm/radeon/radeon.h
31419+++ b/drivers/gpu/drm/radeon/radeon.h
31420@@ -711,7 +711,7 @@ struct r600_blit_cp_primitives {
31421 int x2, int y2);
31422 void (*draw_auto)(struct radeon_device *rdev);
31423 void (*set_default_state)(struct radeon_device *rdev);
31424-};
31425+} __no_const;
31426
31427 struct r600_blit {
31428 struct radeon_bo *shader_obj;
31429@@ -1216,7 +1216,7 @@ struct radeon_asic {
31430 u32 (*page_flip)(struct radeon_device *rdev, int crtc, u64 crtc_base);
31431 void (*post_page_flip)(struct radeon_device *rdev, int crtc);
31432 } pflip;
31433-};
31434+} __no_const;
31435
31436 /*
31437 * Asic structures
31438diff --git a/drivers/gpu/drm/radeon/radeon_device.c b/drivers/gpu/drm/radeon/radeon_device.c
31439index 7a3daeb..5016171 100644
31440--- a/drivers/gpu/drm/radeon/radeon_device.c
31441+++ b/drivers/gpu/drm/radeon/radeon_device.c
31442@@ -952,7 +952,7 @@ static bool radeon_switcheroo_can_switch(struct pci_dev *pdev)
31443 bool can_switch;
31444
31445 spin_lock(&dev->count_lock);
31446- can_switch = (dev->open_count == 0);
31447+ can_switch = (local_read(&dev->open_count) == 0);
31448 spin_unlock(&dev->count_lock);
31449 return can_switch;
31450 }
31451diff --git a/drivers/gpu/drm/radeon/radeon_drv.h b/drivers/gpu/drm/radeon/radeon_drv.h
31452index a1b59ca..86f2d44 100644
31453--- a/drivers/gpu/drm/radeon/radeon_drv.h
31454+++ b/drivers/gpu/drm/radeon/radeon_drv.h
31455@@ -255,7 +255,7 @@ typedef struct drm_radeon_private {
31456
31457 /* SW interrupt */
31458 wait_queue_head_t swi_queue;
31459- atomic_t swi_emitted;
31460+ atomic_unchecked_t swi_emitted;
31461 int vblank_crtc;
31462 uint32_t irq_enable_reg;
31463 uint32_t r500_disp_irq_reg;
31464diff --git a/drivers/gpu/drm/radeon/radeon_ioc32.c b/drivers/gpu/drm/radeon/radeon_ioc32.c
31465index 48b7cea..342236f 100644
31466--- a/drivers/gpu/drm/radeon/radeon_ioc32.c
31467+++ b/drivers/gpu/drm/radeon/radeon_ioc32.c
31468@@ -359,7 +359,7 @@ static int compat_radeon_cp_setparam(struct file *file, unsigned int cmd,
31469 request = compat_alloc_user_space(sizeof(*request));
31470 if (!access_ok(VERIFY_WRITE, request, sizeof(*request))
31471 || __put_user(req32.param, &request->param)
31472- || __put_user((void __user *)(unsigned long)req32.value,
31473+ || __put_user((unsigned long)req32.value,
31474 &request->value))
31475 return -EFAULT;
31476
31477diff --git a/drivers/gpu/drm/radeon/radeon_irq.c b/drivers/gpu/drm/radeon/radeon_irq.c
31478index 00da384..32f972d 100644
31479--- a/drivers/gpu/drm/radeon/radeon_irq.c
31480+++ b/drivers/gpu/drm/radeon/radeon_irq.c
31481@@ -225,8 +225,8 @@ static int radeon_emit_irq(struct drm_device * dev)
31482 unsigned int ret;
31483 RING_LOCALS;
31484
31485- atomic_inc(&dev_priv->swi_emitted);
31486- ret = atomic_read(&dev_priv->swi_emitted);
31487+ atomic_inc_unchecked(&dev_priv->swi_emitted);
31488+ ret = atomic_read_unchecked(&dev_priv->swi_emitted);
31489
31490 BEGIN_RING(4);
31491 OUT_RING_REG(RADEON_LAST_SWI_REG, ret);
31492@@ -352,7 +352,7 @@ int radeon_driver_irq_postinstall(struct drm_device *dev)
31493 drm_radeon_private_t *dev_priv =
31494 (drm_radeon_private_t *) dev->dev_private;
31495
31496- atomic_set(&dev_priv->swi_emitted, 0);
31497+ atomic_set_unchecked(&dev_priv->swi_emitted, 0);
31498 DRM_INIT_WAITQUEUE(&dev_priv->swi_queue);
31499
31500 dev->max_vblank_count = 0x001fffff;
31501diff --git a/drivers/gpu/drm/radeon/radeon_state.c b/drivers/gpu/drm/radeon/radeon_state.c
31502index e8422ae..d22d4a8 100644
31503--- a/drivers/gpu/drm/radeon/radeon_state.c
31504+++ b/drivers/gpu/drm/radeon/radeon_state.c
31505@@ -2168,7 +2168,7 @@ static int radeon_cp_clear(struct drm_device *dev, void *data, struct drm_file *
31506 if (sarea_priv->nbox > RADEON_NR_SAREA_CLIPRECTS)
31507 sarea_priv->nbox = RADEON_NR_SAREA_CLIPRECTS;
31508
31509- if (DRM_COPY_FROM_USER(&depth_boxes, clear->depth_boxes,
31510+ if (sarea_priv->nbox > RADEON_NR_SAREA_CLIPRECTS || DRM_COPY_FROM_USER(&depth_boxes, clear->depth_boxes,
31511 sarea_priv->nbox * sizeof(depth_boxes[0])))
31512 return -EFAULT;
31513
31514@@ -3031,7 +3031,7 @@ static int radeon_cp_getparam(struct drm_device *dev, void *data, struct drm_fil
31515 {
31516 drm_radeon_private_t *dev_priv = dev->dev_private;
31517 drm_radeon_getparam_t *param = data;
31518- int value;
31519+ int value = 0;
31520
31521 DRM_DEBUG("pid=%d\n", DRM_CURRENTPID);
31522
31523diff --git a/drivers/gpu/drm/radeon/radeon_ttm.c b/drivers/gpu/drm/radeon/radeon_ttm.c
31524index 5b71c71..650f9e4 100644
31525--- a/drivers/gpu/drm/radeon/radeon_ttm.c
31526+++ b/drivers/gpu/drm/radeon/radeon_ttm.c
31527@@ -822,8 +822,10 @@ int radeon_mmap(struct file *filp, struct vm_area_struct *vma)
31528 }
31529 if (unlikely(ttm_vm_ops == NULL)) {
31530 ttm_vm_ops = vma->vm_ops;
31531- radeon_ttm_vm_ops = *ttm_vm_ops;
31532- radeon_ttm_vm_ops.fault = &radeon_ttm_fault;
31533+ pax_open_kernel();
31534+ memcpy((void *)&radeon_ttm_vm_ops, ttm_vm_ops, sizeof(radeon_ttm_vm_ops));
31535+ *(void **)&radeon_ttm_vm_ops.fault = &radeon_ttm_fault;
31536+ pax_close_kernel();
31537 }
31538 vma->vm_ops = &radeon_ttm_vm_ops;
31539 return 0;
31540diff --git a/drivers/gpu/drm/radeon/rs690.c b/drivers/gpu/drm/radeon/rs690.c
31541index 3b663fc..57850f4 100644
31542--- a/drivers/gpu/drm/radeon/rs690.c
31543+++ b/drivers/gpu/drm/radeon/rs690.c
31544@@ -304,9 +304,11 @@ void rs690_crtc_bandwidth_compute(struct radeon_device *rdev,
31545 if (rdev->pm.max_bandwidth.full > rdev->pm.sideport_bandwidth.full &&
31546 rdev->pm.sideport_bandwidth.full)
31547 rdev->pm.max_bandwidth = rdev->pm.sideport_bandwidth;
31548- read_delay_latency.full = dfixed_const(370 * 800 * 1000);
31549+ read_delay_latency.full = dfixed_const(800 * 1000);
31550 read_delay_latency.full = dfixed_div(read_delay_latency,
31551 rdev->pm.igp_sideport_mclk);
31552+ a.full = dfixed_const(370);
31553+ read_delay_latency.full = dfixed_mul(read_delay_latency, a);
31554 } else {
31555 if (rdev->pm.max_bandwidth.full > rdev->pm.k8_bandwidth.full &&
31556 rdev->pm.k8_bandwidth.full)
31557diff --git a/drivers/gpu/drm/ttm/ttm_page_alloc.c b/drivers/gpu/drm/ttm/ttm_page_alloc.c
31558index ebc6fac..a8313ed 100644
31559--- a/drivers/gpu/drm/ttm/ttm_page_alloc.c
31560+++ b/drivers/gpu/drm/ttm/ttm_page_alloc.c
31561@@ -394,9 +394,9 @@ static int ttm_pool_get_num_unused_pages(void)
31562 static int ttm_pool_mm_shrink(struct shrinker *shrink,
31563 struct shrink_control *sc)
31564 {
31565- static atomic_t start_pool = ATOMIC_INIT(0);
31566+ static atomic_unchecked_t start_pool = ATOMIC_INIT(0);
31567 unsigned i;
31568- unsigned pool_offset = atomic_add_return(1, &start_pool);
31569+ unsigned pool_offset = atomic_add_return_unchecked(1, &start_pool);
31570 struct ttm_page_pool *pool;
31571 int shrink_pages = sc->nr_to_scan;
31572
31573diff --git a/drivers/gpu/drm/via/via_drv.h b/drivers/gpu/drm/via/via_drv.h
31574index 88edacc..1e5412b 100644
31575--- a/drivers/gpu/drm/via/via_drv.h
31576+++ b/drivers/gpu/drm/via/via_drv.h
31577@@ -51,7 +51,7 @@ typedef struct drm_via_ring_buffer {
31578 typedef uint32_t maskarray_t[5];
31579
31580 typedef struct drm_via_irq {
31581- atomic_t irq_received;
31582+ atomic_unchecked_t irq_received;
31583 uint32_t pending_mask;
31584 uint32_t enable_mask;
31585 wait_queue_head_t irq_queue;
31586@@ -75,7 +75,7 @@ typedef struct drm_via_private {
31587 struct timeval last_vblank;
31588 int last_vblank_valid;
31589 unsigned usec_per_vblank;
31590- atomic_t vbl_received;
31591+ atomic_unchecked_t vbl_received;
31592 drm_via_state_t hc_state;
31593 char pci_buf[VIA_PCI_BUF_SIZE];
31594 const uint32_t *fire_offsets[VIA_FIRE_BUF_SIZE];
31595diff --git a/drivers/gpu/drm/via/via_irq.c b/drivers/gpu/drm/via/via_irq.c
31596index d391f48..10c8ca3 100644
31597--- a/drivers/gpu/drm/via/via_irq.c
31598+++ b/drivers/gpu/drm/via/via_irq.c
31599@@ -102,7 +102,7 @@ u32 via_get_vblank_counter(struct drm_device *dev, int crtc)
31600 if (crtc != 0)
31601 return 0;
31602
31603- return atomic_read(&dev_priv->vbl_received);
31604+ return atomic_read_unchecked(&dev_priv->vbl_received);
31605 }
31606
31607 irqreturn_t via_driver_irq_handler(DRM_IRQ_ARGS)
31608@@ -117,8 +117,8 @@ irqreturn_t via_driver_irq_handler(DRM_IRQ_ARGS)
31609
31610 status = VIA_READ(VIA_REG_INTERRUPT);
31611 if (status & VIA_IRQ_VBLANK_PENDING) {
31612- atomic_inc(&dev_priv->vbl_received);
31613- if (!(atomic_read(&dev_priv->vbl_received) & 0x0F)) {
31614+ atomic_inc_unchecked(&dev_priv->vbl_received);
31615+ if (!(atomic_read_unchecked(&dev_priv->vbl_received) & 0x0F)) {
31616 do_gettimeofday(&cur_vblank);
31617 if (dev_priv->last_vblank_valid) {
31618 dev_priv->usec_per_vblank =
31619@@ -128,7 +128,7 @@ irqreturn_t via_driver_irq_handler(DRM_IRQ_ARGS)
31620 dev_priv->last_vblank = cur_vblank;
31621 dev_priv->last_vblank_valid = 1;
31622 }
31623- if (!(atomic_read(&dev_priv->vbl_received) & 0xFF)) {
31624+ if (!(atomic_read_unchecked(&dev_priv->vbl_received) & 0xFF)) {
31625 DRM_DEBUG("US per vblank is: %u\n",
31626 dev_priv->usec_per_vblank);
31627 }
31628@@ -138,7 +138,7 @@ irqreturn_t via_driver_irq_handler(DRM_IRQ_ARGS)
31629
31630 for (i = 0; i < dev_priv->num_irqs; ++i) {
31631 if (status & cur_irq->pending_mask) {
31632- atomic_inc(&cur_irq->irq_received);
31633+ atomic_inc_unchecked(&cur_irq->irq_received);
31634 DRM_WAKEUP(&cur_irq->irq_queue);
31635 handled = 1;
31636 if (dev_priv->irq_map[drm_via_irq_dma0_td] == i)
31637@@ -243,11 +243,11 @@ via_driver_irq_wait(struct drm_device *dev, unsigned int irq, int force_sequence
31638 DRM_WAIT_ON(ret, cur_irq->irq_queue, 3 * DRM_HZ,
31639 ((VIA_READ(masks[irq][2]) & masks[irq][3]) ==
31640 masks[irq][4]));
31641- cur_irq_sequence = atomic_read(&cur_irq->irq_received);
31642+ cur_irq_sequence = atomic_read_unchecked(&cur_irq->irq_received);
31643 } else {
31644 DRM_WAIT_ON(ret, cur_irq->irq_queue, 3 * DRM_HZ,
31645 (((cur_irq_sequence =
31646- atomic_read(&cur_irq->irq_received)) -
31647+ atomic_read_unchecked(&cur_irq->irq_received)) -
31648 *sequence) <= (1 << 23)));
31649 }
31650 *sequence = cur_irq_sequence;
31651@@ -285,7 +285,7 @@ void via_driver_irq_preinstall(struct drm_device *dev)
31652 }
31653
31654 for (i = 0; i < dev_priv->num_irqs; ++i) {
31655- atomic_set(&cur_irq->irq_received, 0);
31656+ atomic_set_unchecked(&cur_irq->irq_received, 0);
31657 cur_irq->enable_mask = dev_priv->irq_masks[i][0];
31658 cur_irq->pending_mask = dev_priv->irq_masks[i][1];
31659 DRM_INIT_WAITQUEUE(&cur_irq->irq_queue);
31660@@ -367,7 +367,7 @@ int via_wait_irq(struct drm_device *dev, void *data, struct drm_file *file_priv)
31661 switch (irqwait->request.type & ~VIA_IRQ_FLAGS_MASK) {
31662 case VIA_IRQ_RELATIVE:
31663 irqwait->request.sequence +=
31664- atomic_read(&cur_irq->irq_received);
31665+ atomic_read_unchecked(&cur_irq->irq_received);
31666 irqwait->request.type &= ~_DRM_VBLANK_RELATIVE;
31667 case VIA_IRQ_ABSOLUTE:
31668 break;
31669diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h b/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
31670index 29c984f..4084f1a 100644
31671--- a/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
31672+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
31673@@ -263,7 +263,7 @@ struct vmw_private {
31674 * Fencing and IRQs.
31675 */
31676
31677- atomic_t marker_seq;
31678+ atomic_unchecked_t marker_seq;
31679 wait_queue_head_t fence_queue;
31680 wait_queue_head_t fifo_queue;
31681 int fence_queue_waiters; /* Protected by hw_mutex */
31682diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c b/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c
31683index a0c2f12..68ae6cb 100644
31684--- a/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c
31685+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c
31686@@ -137,7 +137,7 @@ int vmw_fifo_init(struct vmw_private *dev_priv, struct vmw_fifo_state *fifo)
31687 (unsigned int) min,
31688 (unsigned int) fifo->capabilities);
31689
31690- atomic_set(&dev_priv->marker_seq, dev_priv->last_read_seqno);
31691+ atomic_set_unchecked(&dev_priv->marker_seq, dev_priv->last_read_seqno);
31692 iowrite32(dev_priv->last_read_seqno, fifo_mem + SVGA_FIFO_FENCE);
31693 vmw_marker_queue_init(&fifo->marker_queue);
31694 return vmw_fifo_send_fence(dev_priv, &dummy);
31695@@ -355,7 +355,7 @@ void *vmw_fifo_reserve(struct vmw_private *dev_priv, uint32_t bytes)
31696 if (reserveable)
31697 iowrite32(bytes, fifo_mem +
31698 SVGA_FIFO_RESERVED);
31699- return fifo_mem + (next_cmd >> 2);
31700+ return (__le32 __force_kernel *)fifo_mem + (next_cmd >> 2);
31701 } else {
31702 need_bounce = true;
31703 }
31704@@ -475,7 +475,7 @@ int vmw_fifo_send_fence(struct vmw_private *dev_priv, uint32_t *seqno)
31705
31706 fm = vmw_fifo_reserve(dev_priv, bytes);
31707 if (unlikely(fm == NULL)) {
31708- *seqno = atomic_read(&dev_priv->marker_seq);
31709+ *seqno = atomic_read_unchecked(&dev_priv->marker_seq);
31710 ret = -ENOMEM;
31711 (void)vmw_fallback_wait(dev_priv, false, true, *seqno,
31712 false, 3*HZ);
31713@@ -483,7 +483,7 @@ int vmw_fifo_send_fence(struct vmw_private *dev_priv, uint32_t *seqno)
31714 }
31715
31716 do {
31717- *seqno = atomic_add_return(1, &dev_priv->marker_seq);
31718+ *seqno = atomic_add_return_unchecked(1, &dev_priv->marker_seq);
31719 } while (*seqno == 0);
31720
31721 if (!(fifo_state->capabilities & SVGA_FIFO_CAP_FENCE)) {
31722diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c b/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c
31723index cabc95f..14b3d77 100644
31724--- a/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c
31725+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c
31726@@ -107,7 +107,7 @@ bool vmw_seqno_passed(struct vmw_private *dev_priv,
31727 * emitted. Then the fence is stale and signaled.
31728 */
31729
31730- ret = ((atomic_read(&dev_priv->marker_seq) - seqno)
31731+ ret = ((atomic_read_unchecked(&dev_priv->marker_seq) - seqno)
31732 > VMW_FENCE_WRAP);
31733
31734 return ret;
31735@@ -138,7 +138,7 @@ int vmw_fallback_wait(struct vmw_private *dev_priv,
31736
31737 if (fifo_idle)
31738 down_read(&fifo_state->rwsem);
31739- signal_seq = atomic_read(&dev_priv->marker_seq);
31740+ signal_seq = atomic_read_unchecked(&dev_priv->marker_seq);
31741 ret = 0;
31742
31743 for (;;) {
31744diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c b/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c
31745index 8a8725c..afed796 100644
31746--- a/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c
31747+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c
31748@@ -151,7 +151,7 @@ int vmw_wait_lag(struct vmw_private *dev_priv,
31749 while (!vmw_lag_lt(queue, us)) {
31750 spin_lock(&queue->lock);
31751 if (list_empty(&queue->head))
31752- seqno = atomic_read(&dev_priv->marker_seq);
31753+ seqno = atomic_read_unchecked(&dev_priv->marker_seq);
31754 else {
31755 marker = list_first_entry(&queue->head,
31756 struct vmw_marker, head);
31757diff --git a/drivers/hid/hid-core.c b/drivers/hid/hid-core.c
31758index 5de3bb3..08e5063 100644
31759--- a/drivers/hid/hid-core.c
31760+++ b/drivers/hid/hid-core.c
31761@@ -2177,7 +2177,7 @@ static bool hid_ignore(struct hid_device *hdev)
31762
31763 int hid_add_device(struct hid_device *hdev)
31764 {
31765- static atomic_t id = ATOMIC_INIT(0);
31766+ static atomic_unchecked_t id = ATOMIC_INIT(0);
31767 int ret;
31768
31769 if (WARN_ON(hdev->status & HID_STAT_ADDED))
31770@@ -2212,7 +2212,7 @@ int hid_add_device(struct hid_device *hdev)
31771 /* XXX hack, any other cleaner solution after the driver core
31772 * is converted to allow more than 20 bytes as the device name? */
31773 dev_set_name(&hdev->dev, "%04X:%04X:%04X.%04X", hdev->bus,
31774- hdev->vendor, hdev->product, atomic_inc_return(&id));
31775+ hdev->vendor, hdev->product, atomic_inc_return_unchecked(&id));
31776
31777 hid_debug_register(hdev, dev_name(&hdev->dev));
31778 ret = device_add(&hdev->dev);
31779diff --git a/drivers/hid/hid-wiimote-debug.c b/drivers/hid/hid-wiimote-debug.c
31780index eec3291..8ed706b 100644
31781--- a/drivers/hid/hid-wiimote-debug.c
31782+++ b/drivers/hid/hid-wiimote-debug.c
31783@@ -66,7 +66,7 @@ static ssize_t wiidebug_eeprom_read(struct file *f, char __user *u, size_t s,
31784 else if (size == 0)
31785 return -EIO;
31786
31787- if (copy_to_user(u, buf, size))
31788+ if (size > sizeof(buf) || copy_to_user(u, buf, size))
31789 return -EFAULT;
31790
31791 *off += size;
31792diff --git a/drivers/hid/usbhid/hiddev.c b/drivers/hid/usbhid/hiddev.c
31793index 14599e2..711c965 100644
31794--- a/drivers/hid/usbhid/hiddev.c
31795+++ b/drivers/hid/usbhid/hiddev.c
31796@@ -625,7 +625,7 @@ static long hiddev_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
31797 break;
31798
31799 case HIDIOCAPPLICATION:
31800- if (arg < 0 || arg >= hid->maxapplication)
31801+ if (arg >= hid->maxapplication)
31802 break;
31803
31804 for (i = 0; i < hid->maxcollection; i++)
31805diff --git a/drivers/hv/channel.c b/drivers/hv/channel.c
31806index f4c3d28..82f45a9 100644
31807--- a/drivers/hv/channel.c
31808+++ b/drivers/hv/channel.c
31809@@ -402,8 +402,8 @@ int vmbus_establish_gpadl(struct vmbus_channel *channel, void *kbuffer,
31810 int ret = 0;
31811 int t;
31812
31813- next_gpadl_handle = atomic_read(&vmbus_connection.next_gpadl_handle);
31814- atomic_inc(&vmbus_connection.next_gpadl_handle);
31815+ next_gpadl_handle = atomic_read_unchecked(&vmbus_connection.next_gpadl_handle);
31816+ atomic_inc_unchecked(&vmbus_connection.next_gpadl_handle);
31817
31818 ret = create_gpadl_header(kbuffer, size, &msginfo, &msgcount);
31819 if (ret)
31820diff --git a/drivers/hv/hv.c b/drivers/hv/hv.c
31821index 86f8885..ab9cb2b 100644
31822--- a/drivers/hv/hv.c
31823+++ b/drivers/hv/hv.c
31824@@ -132,7 +132,7 @@ static u64 do_hypercall(u64 control, void *input, void *output)
31825 u64 output_address = (output) ? virt_to_phys(output) : 0;
31826 u32 output_address_hi = output_address >> 32;
31827 u32 output_address_lo = output_address & 0xFFFFFFFF;
31828- void *hypercall_page = hv_context.hypercall_page;
31829+ void *hypercall_page = ktva_ktla(hv_context.hypercall_page);
31830
31831 __asm__ __volatile__ ("call *%8" : "=d"(hv_status_hi),
31832 "=a"(hv_status_lo) : "d" (control_hi),
31833diff --git a/drivers/hv/hyperv_vmbus.h b/drivers/hv/hyperv_vmbus.h
31834index 0614ff3..f0b2b5c 100644
31835--- a/drivers/hv/hyperv_vmbus.h
31836+++ b/drivers/hv/hyperv_vmbus.h
31837@@ -555,7 +555,7 @@ enum vmbus_connect_state {
31838 struct vmbus_connection {
31839 enum vmbus_connect_state conn_state;
31840
31841- atomic_t next_gpadl_handle;
31842+ atomic_unchecked_t next_gpadl_handle;
31843
31844 /*
31845 * Represents channel interrupts. Each bit position represents a
31846diff --git a/drivers/hv/vmbus_drv.c b/drivers/hv/vmbus_drv.c
31847index 4748086..3abf845 100644
31848--- a/drivers/hv/vmbus_drv.c
31849+++ b/drivers/hv/vmbus_drv.c
31850@@ -662,10 +662,10 @@ int vmbus_device_register(struct hv_device *child_device_obj)
31851 {
31852 int ret = 0;
31853
31854- static atomic_t device_num = ATOMIC_INIT(0);
31855+ static atomic_unchecked_t device_num = ATOMIC_INIT(0);
31856
31857 dev_set_name(&child_device_obj->device, "vmbus_0_%d",
31858- atomic_inc_return(&device_num));
31859+ atomic_inc_return_unchecked(&device_num));
31860
31861 child_device_obj->device.bus = &hv_bus;
31862 child_device_obj->device.parent = &hv_acpi_dev->dev;
31863diff --git a/drivers/hwmon/sht15.c b/drivers/hwmon/sht15.c
31864index 8b011d0..3de24a1 100644
31865--- a/drivers/hwmon/sht15.c
31866+++ b/drivers/hwmon/sht15.c
31867@@ -166,7 +166,7 @@ struct sht15_data {
31868 int supply_uV;
31869 bool supply_uV_valid;
31870 struct work_struct update_supply_work;
31871- atomic_t interrupt_handled;
31872+ atomic_unchecked_t interrupt_handled;
31873 };
31874
31875 /**
31876@@ -509,13 +509,13 @@ static int sht15_measurement(struct sht15_data *data,
31877 return ret;
31878
31879 gpio_direction_input(data->pdata->gpio_data);
31880- atomic_set(&data->interrupt_handled, 0);
31881+ atomic_set_unchecked(&data->interrupt_handled, 0);
31882
31883 enable_irq(gpio_to_irq(data->pdata->gpio_data));
31884 if (gpio_get_value(data->pdata->gpio_data) == 0) {
31885 disable_irq_nosync(gpio_to_irq(data->pdata->gpio_data));
31886 /* Only relevant if the interrupt hasn't occurred. */
31887- if (!atomic_read(&data->interrupt_handled))
31888+ if (!atomic_read_unchecked(&data->interrupt_handled))
31889 schedule_work(&data->read_work);
31890 }
31891 ret = wait_event_timeout(data->wait_queue,
31892@@ -782,7 +782,7 @@ static irqreturn_t sht15_interrupt_fired(int irq, void *d)
31893
31894 /* First disable the interrupt */
31895 disable_irq_nosync(irq);
31896- atomic_inc(&data->interrupt_handled);
31897+ atomic_inc_unchecked(&data->interrupt_handled);
31898 /* Then schedule a reading work struct */
31899 if (data->state != SHT15_READING_NOTHING)
31900 schedule_work(&data->read_work);
31901@@ -804,11 +804,11 @@ static void sht15_bh_read_data(struct work_struct *work_s)
31902 * If not, then start the interrupt again - care here as could
31903 * have gone low in meantime so verify it hasn't!
31904 */
31905- atomic_set(&data->interrupt_handled, 0);
31906+ atomic_set_unchecked(&data->interrupt_handled, 0);
31907 enable_irq(gpio_to_irq(data->pdata->gpio_data));
31908 /* If still not occurred or another handler was scheduled */
31909 if (gpio_get_value(data->pdata->gpio_data)
31910- || atomic_read(&data->interrupt_handled))
31911+ || atomic_read_unchecked(&data->interrupt_handled))
31912 return;
31913 }
31914
31915diff --git a/drivers/i2c/busses/i2c-amd756-s4882.c b/drivers/i2c/busses/i2c-amd756-s4882.c
31916index 378fcb5..5e91fa8 100644
31917--- a/drivers/i2c/busses/i2c-amd756-s4882.c
31918+++ b/drivers/i2c/busses/i2c-amd756-s4882.c
31919@@ -43,7 +43,7 @@
31920 extern struct i2c_adapter amd756_smbus;
31921
31922 static struct i2c_adapter *s4882_adapter;
31923-static struct i2c_algorithm *s4882_algo;
31924+static i2c_algorithm_no_const *s4882_algo;
31925
31926 /* Wrapper access functions for multiplexed SMBus */
31927 static DEFINE_MUTEX(amd756_lock);
31928diff --git a/drivers/i2c/busses/i2c-nforce2-s4985.c b/drivers/i2c/busses/i2c-nforce2-s4985.c
31929index 29015eb..af2d8e9 100644
31930--- a/drivers/i2c/busses/i2c-nforce2-s4985.c
31931+++ b/drivers/i2c/busses/i2c-nforce2-s4985.c
31932@@ -41,7 +41,7 @@
31933 extern struct i2c_adapter *nforce2_smbus;
31934
31935 static struct i2c_adapter *s4985_adapter;
31936-static struct i2c_algorithm *s4985_algo;
31937+static i2c_algorithm_no_const *s4985_algo;
31938
31939 /* Wrapper access functions for multiplexed SMBus */
31940 static DEFINE_MUTEX(nforce2_lock);
31941diff --git a/drivers/i2c/i2c-mux.c b/drivers/i2c/i2c-mux.c
31942index 1038c38..eb92f51 100644
31943--- a/drivers/i2c/i2c-mux.c
31944+++ b/drivers/i2c/i2c-mux.c
31945@@ -30,7 +30,7 @@
31946 /* multiplexer per channel data */
31947 struct i2c_mux_priv {
31948 struct i2c_adapter adap;
31949- struct i2c_algorithm algo;
31950+ i2c_algorithm_no_const algo;
31951
31952 struct i2c_adapter *parent;
31953 void *mux_priv; /* the mux chip/device */
31954diff --git a/drivers/ide/aec62xx.c b/drivers/ide/aec62xx.c
31955index 57d00ca..0145194 100644
31956--- a/drivers/ide/aec62xx.c
31957+++ b/drivers/ide/aec62xx.c
31958@@ -181,7 +181,7 @@ static const struct ide_port_ops atp86x_port_ops = {
31959 .cable_detect = atp86x_cable_detect,
31960 };
31961
31962-static const struct ide_port_info aec62xx_chipsets[] __devinitdata = {
31963+static const struct ide_port_info aec62xx_chipsets[] __devinitconst = {
31964 { /* 0: AEC6210 */
31965 .name = DRV_NAME,
31966 .init_chipset = init_chipset_aec62xx,
31967diff --git a/drivers/ide/alim15x3.c b/drivers/ide/alim15x3.c
31968index 2c8016a..911a27c 100644
31969--- a/drivers/ide/alim15x3.c
31970+++ b/drivers/ide/alim15x3.c
31971@@ -512,7 +512,7 @@ static const struct ide_dma_ops ali_dma_ops = {
31972 .dma_sff_read_status = ide_dma_sff_read_status,
31973 };
31974
31975-static const struct ide_port_info ali15x3_chipset __devinitdata = {
31976+static const struct ide_port_info ali15x3_chipset __devinitconst = {
31977 .name = DRV_NAME,
31978 .init_chipset = init_chipset_ali15x3,
31979 .init_hwif = init_hwif_ali15x3,
31980diff --git a/drivers/ide/amd74xx.c b/drivers/ide/amd74xx.c
31981index 3747b25..56fc995 100644
31982--- a/drivers/ide/amd74xx.c
31983+++ b/drivers/ide/amd74xx.c
31984@@ -223,7 +223,7 @@ static const struct ide_port_ops amd_port_ops = {
31985 .udma_mask = udma, \
31986 }
31987
31988-static const struct ide_port_info amd74xx_chipsets[] __devinitdata = {
31989+static const struct ide_port_info amd74xx_chipsets[] __devinitconst = {
31990 /* 0: AMD7401 */ DECLARE_AMD_DEV(0x00, ATA_UDMA2),
31991 /* 1: AMD7409 */ DECLARE_AMD_DEV(ATA_SWDMA2, ATA_UDMA4),
31992 /* 2: AMD7411/7441 */ DECLARE_AMD_DEV(ATA_SWDMA2, ATA_UDMA5),
31993diff --git a/drivers/ide/atiixp.c b/drivers/ide/atiixp.c
31994index 15f0ead..cb43480 100644
31995--- a/drivers/ide/atiixp.c
31996+++ b/drivers/ide/atiixp.c
31997@@ -139,7 +139,7 @@ static const struct ide_port_ops atiixp_port_ops = {
31998 .cable_detect = atiixp_cable_detect,
31999 };
32000
32001-static const struct ide_port_info atiixp_pci_info[] __devinitdata = {
32002+static const struct ide_port_info atiixp_pci_info[] __devinitconst = {
32003 { /* 0: IXP200/300/400/700 */
32004 .name = DRV_NAME,
32005 .enablebits = {{0x48,0x01,0x00}, {0x48,0x08,0x00}},
32006diff --git a/drivers/ide/cmd64x.c b/drivers/ide/cmd64x.c
32007index 5f80312..d1fc438 100644
32008--- a/drivers/ide/cmd64x.c
32009+++ b/drivers/ide/cmd64x.c
32010@@ -327,7 +327,7 @@ static const struct ide_dma_ops cmd646_rev1_dma_ops = {
32011 .dma_sff_read_status = ide_dma_sff_read_status,
32012 };
32013
32014-static const struct ide_port_info cmd64x_chipsets[] __devinitdata = {
32015+static const struct ide_port_info cmd64x_chipsets[] __devinitconst = {
32016 { /* 0: CMD643 */
32017 .name = DRV_NAME,
32018 .init_chipset = init_chipset_cmd64x,
32019diff --git a/drivers/ide/cs5520.c b/drivers/ide/cs5520.c
32020index 2c1e5f7..1444762 100644
32021--- a/drivers/ide/cs5520.c
32022+++ b/drivers/ide/cs5520.c
32023@@ -94,7 +94,7 @@ static const struct ide_port_ops cs5520_port_ops = {
32024 .set_dma_mode = cs5520_set_dma_mode,
32025 };
32026
32027-static const struct ide_port_info cyrix_chipset __devinitdata = {
32028+static const struct ide_port_info cyrix_chipset __devinitconst = {
32029 .name = DRV_NAME,
32030 .enablebits = { { 0x60, 0x01, 0x01 }, { 0x60, 0x02, 0x02 } },
32031 .port_ops = &cs5520_port_ops,
32032diff --git a/drivers/ide/cs5530.c b/drivers/ide/cs5530.c
32033index 4dc4eb9..49b40ad 100644
32034--- a/drivers/ide/cs5530.c
32035+++ b/drivers/ide/cs5530.c
32036@@ -245,7 +245,7 @@ static const struct ide_port_ops cs5530_port_ops = {
32037 .udma_filter = cs5530_udma_filter,
32038 };
32039
32040-static const struct ide_port_info cs5530_chipset __devinitdata = {
32041+static const struct ide_port_info cs5530_chipset __devinitconst = {
32042 .name = DRV_NAME,
32043 .init_chipset = init_chipset_cs5530,
32044 .init_hwif = init_hwif_cs5530,
32045diff --git a/drivers/ide/cs5535.c b/drivers/ide/cs5535.c
32046index 5059faf..18d4c85 100644
32047--- a/drivers/ide/cs5535.c
32048+++ b/drivers/ide/cs5535.c
32049@@ -170,7 +170,7 @@ static const struct ide_port_ops cs5535_port_ops = {
32050 .cable_detect = cs5535_cable_detect,
32051 };
32052
32053-static const struct ide_port_info cs5535_chipset __devinitdata = {
32054+static const struct ide_port_info cs5535_chipset __devinitconst = {
32055 .name = DRV_NAME,
32056 .port_ops = &cs5535_port_ops,
32057 .host_flags = IDE_HFLAG_SINGLE | IDE_HFLAG_POST_SET_MODE,
32058diff --git a/drivers/ide/cy82c693.c b/drivers/ide/cy82c693.c
32059index 847553f..3ffb49d 100644
32060--- a/drivers/ide/cy82c693.c
32061+++ b/drivers/ide/cy82c693.c
32062@@ -163,7 +163,7 @@ static const struct ide_port_ops cy82c693_port_ops = {
32063 .set_dma_mode = cy82c693_set_dma_mode,
32064 };
32065
32066-static const struct ide_port_info cy82c693_chipset __devinitdata = {
32067+static const struct ide_port_info cy82c693_chipset __devinitconst = {
32068 .name = DRV_NAME,
32069 .init_iops = init_iops_cy82c693,
32070 .port_ops = &cy82c693_port_ops,
32071diff --git a/drivers/ide/hpt366.c b/drivers/ide/hpt366.c
32072index 58c51cd..4aec3b8 100644
32073--- a/drivers/ide/hpt366.c
32074+++ b/drivers/ide/hpt366.c
32075@@ -443,7 +443,7 @@ static struct hpt_timings hpt37x_timings = {
32076 }
32077 };
32078
32079-static const struct hpt_info hpt36x __devinitdata = {
32080+static const struct hpt_info hpt36x __devinitconst = {
32081 .chip_name = "HPT36x",
32082 .chip_type = HPT36x,
32083 .udma_mask = HPT366_ALLOW_ATA66_3 ? (HPT366_ALLOW_ATA66_4 ? ATA_UDMA4 : ATA_UDMA3) : ATA_UDMA2,
32084@@ -451,7 +451,7 @@ static const struct hpt_info hpt36x __devinitdata = {
32085 .timings = &hpt36x_timings
32086 };
32087
32088-static const struct hpt_info hpt370 __devinitdata = {
32089+static const struct hpt_info hpt370 __devinitconst = {
32090 .chip_name = "HPT370",
32091 .chip_type = HPT370,
32092 .udma_mask = HPT370_ALLOW_ATA100_5 ? ATA_UDMA5 : ATA_UDMA4,
32093@@ -459,7 +459,7 @@ static const struct hpt_info hpt370 __devinitdata = {
32094 .timings = &hpt37x_timings
32095 };
32096
32097-static const struct hpt_info hpt370a __devinitdata = {
32098+static const struct hpt_info hpt370a __devinitconst = {
32099 .chip_name = "HPT370A",
32100 .chip_type = HPT370A,
32101 .udma_mask = HPT370_ALLOW_ATA100_5 ? ATA_UDMA5 : ATA_UDMA4,
32102@@ -467,7 +467,7 @@ static const struct hpt_info hpt370a __devinitdata = {
32103 .timings = &hpt37x_timings
32104 };
32105
32106-static const struct hpt_info hpt374 __devinitdata = {
32107+static const struct hpt_info hpt374 __devinitconst = {
32108 .chip_name = "HPT374",
32109 .chip_type = HPT374,
32110 .udma_mask = ATA_UDMA5,
32111@@ -475,7 +475,7 @@ static const struct hpt_info hpt374 __devinitdata = {
32112 .timings = &hpt37x_timings
32113 };
32114
32115-static const struct hpt_info hpt372 __devinitdata = {
32116+static const struct hpt_info hpt372 __devinitconst = {
32117 .chip_name = "HPT372",
32118 .chip_type = HPT372,
32119 .udma_mask = HPT372_ALLOW_ATA133_6 ? ATA_UDMA6 : ATA_UDMA5,
32120@@ -483,7 +483,7 @@ static const struct hpt_info hpt372 __devinitdata = {
32121 .timings = &hpt37x_timings
32122 };
32123
32124-static const struct hpt_info hpt372a __devinitdata = {
32125+static const struct hpt_info hpt372a __devinitconst = {
32126 .chip_name = "HPT372A",
32127 .chip_type = HPT372A,
32128 .udma_mask = HPT372_ALLOW_ATA133_6 ? ATA_UDMA6 : ATA_UDMA5,
32129@@ -491,7 +491,7 @@ static const struct hpt_info hpt372a __devinitdata = {
32130 .timings = &hpt37x_timings
32131 };
32132
32133-static const struct hpt_info hpt302 __devinitdata = {
32134+static const struct hpt_info hpt302 __devinitconst = {
32135 .chip_name = "HPT302",
32136 .chip_type = HPT302,
32137 .udma_mask = HPT302_ALLOW_ATA133_6 ? ATA_UDMA6 : ATA_UDMA5,
32138@@ -499,7 +499,7 @@ static const struct hpt_info hpt302 __devinitdata = {
32139 .timings = &hpt37x_timings
32140 };
32141
32142-static const struct hpt_info hpt371 __devinitdata = {
32143+static const struct hpt_info hpt371 __devinitconst = {
32144 .chip_name = "HPT371",
32145 .chip_type = HPT371,
32146 .udma_mask = HPT371_ALLOW_ATA133_6 ? ATA_UDMA6 : ATA_UDMA5,
32147@@ -507,7 +507,7 @@ static const struct hpt_info hpt371 __devinitdata = {
32148 .timings = &hpt37x_timings
32149 };
32150
32151-static const struct hpt_info hpt372n __devinitdata = {
32152+static const struct hpt_info hpt372n __devinitconst = {
32153 .chip_name = "HPT372N",
32154 .chip_type = HPT372N,
32155 .udma_mask = HPT372_ALLOW_ATA133_6 ? ATA_UDMA6 : ATA_UDMA5,
32156@@ -515,7 +515,7 @@ static const struct hpt_info hpt372n __devinitdata = {
32157 .timings = &hpt37x_timings
32158 };
32159
32160-static const struct hpt_info hpt302n __devinitdata = {
32161+static const struct hpt_info hpt302n __devinitconst = {
32162 .chip_name = "HPT302N",
32163 .chip_type = HPT302N,
32164 .udma_mask = HPT302_ALLOW_ATA133_6 ? ATA_UDMA6 : ATA_UDMA5,
32165@@ -523,7 +523,7 @@ static const struct hpt_info hpt302n __devinitdata = {
32166 .timings = &hpt37x_timings
32167 };
32168
32169-static const struct hpt_info hpt371n __devinitdata = {
32170+static const struct hpt_info hpt371n __devinitconst = {
32171 .chip_name = "HPT371N",
32172 .chip_type = HPT371N,
32173 .udma_mask = HPT371_ALLOW_ATA133_6 ? ATA_UDMA6 : ATA_UDMA5,
32174@@ -1361,7 +1361,7 @@ static const struct ide_dma_ops hpt36x_dma_ops = {
32175 .dma_sff_read_status = ide_dma_sff_read_status,
32176 };
32177
32178-static const struct ide_port_info hpt366_chipsets[] __devinitdata = {
32179+static const struct ide_port_info hpt366_chipsets[] __devinitconst = {
32180 { /* 0: HPT36x */
32181 .name = DRV_NAME,
32182 .init_chipset = init_chipset_hpt366,
32183diff --git a/drivers/ide/ide-cd.c b/drivers/ide/ide-cd.c
32184index 8126824..55a2798 100644
32185--- a/drivers/ide/ide-cd.c
32186+++ b/drivers/ide/ide-cd.c
32187@@ -768,7 +768,7 @@ static void cdrom_do_block_pc(ide_drive_t *drive, struct request *rq)
32188 alignment = queue_dma_alignment(q) | q->dma_pad_mask;
32189 if ((unsigned long)buf & alignment
32190 || blk_rq_bytes(rq) & q->dma_pad_mask
32191- || object_is_on_stack(buf))
32192+ || object_starts_on_stack(buf))
32193 drive->dma = 0;
32194 }
32195 }
32196diff --git a/drivers/ide/ide-pci-generic.c b/drivers/ide/ide-pci-generic.c
32197index 7f56b73..dab5b67 100644
32198--- a/drivers/ide/ide-pci-generic.c
32199+++ b/drivers/ide/ide-pci-generic.c
32200@@ -53,7 +53,7 @@ static const struct ide_port_ops netcell_port_ops = {
32201 .udma_mask = ATA_UDMA6, \
32202 }
32203
32204-static const struct ide_port_info generic_chipsets[] __devinitdata = {
32205+static const struct ide_port_info generic_chipsets[] __devinitconst = {
32206 /* 0: Unknown */
32207 DECLARE_GENERIC_PCI_DEV(0),
32208
32209diff --git a/drivers/ide/it8172.c b/drivers/ide/it8172.c
32210index 560e66d..d5dd180 100644
32211--- a/drivers/ide/it8172.c
32212+++ b/drivers/ide/it8172.c
32213@@ -115,7 +115,7 @@ static const struct ide_port_ops it8172_port_ops = {
32214 .set_dma_mode = it8172_set_dma_mode,
32215 };
32216
32217-static const struct ide_port_info it8172_port_info __devinitdata = {
32218+static const struct ide_port_info it8172_port_info __devinitconst = {
32219 .name = DRV_NAME,
32220 .port_ops = &it8172_port_ops,
32221 .enablebits = { {0x41, 0x80, 0x80}, {0x00, 0x00, 0x00} },
32222diff --git a/drivers/ide/it8213.c b/drivers/ide/it8213.c
32223index 46816ba..1847aeb 100644
32224--- a/drivers/ide/it8213.c
32225+++ b/drivers/ide/it8213.c
32226@@ -156,7 +156,7 @@ static const struct ide_port_ops it8213_port_ops = {
32227 .cable_detect = it8213_cable_detect,
32228 };
32229
32230-static const struct ide_port_info it8213_chipset __devinitdata = {
32231+static const struct ide_port_info it8213_chipset __devinitconst = {
32232 .name = DRV_NAME,
32233 .enablebits = { {0x41, 0x80, 0x80} },
32234 .port_ops = &it8213_port_ops,
32235diff --git a/drivers/ide/it821x.c b/drivers/ide/it821x.c
32236index 2e3169f..c5611db 100644
32237--- a/drivers/ide/it821x.c
32238+++ b/drivers/ide/it821x.c
32239@@ -630,7 +630,7 @@ static const struct ide_port_ops it821x_port_ops = {
32240 .cable_detect = it821x_cable_detect,
32241 };
32242
32243-static const struct ide_port_info it821x_chipset __devinitdata = {
32244+static const struct ide_port_info it821x_chipset __devinitconst = {
32245 .name = DRV_NAME,
32246 .init_chipset = init_chipset_it821x,
32247 .init_hwif = init_hwif_it821x,
32248diff --git a/drivers/ide/jmicron.c b/drivers/ide/jmicron.c
32249index 74c2c4a..efddd7d 100644
32250--- a/drivers/ide/jmicron.c
32251+++ b/drivers/ide/jmicron.c
32252@@ -102,7 +102,7 @@ static const struct ide_port_ops jmicron_port_ops = {
32253 .cable_detect = jmicron_cable_detect,
32254 };
32255
32256-static const struct ide_port_info jmicron_chipset __devinitdata = {
32257+static const struct ide_port_info jmicron_chipset __devinitconst = {
32258 .name = DRV_NAME,
32259 .enablebits = { { 0x40, 0x01, 0x01 }, { 0x40, 0x10, 0x10 } },
32260 .port_ops = &jmicron_port_ops,
32261diff --git a/drivers/ide/ns87415.c b/drivers/ide/ns87415.c
32262index 95327a2..73f78d8 100644
32263--- a/drivers/ide/ns87415.c
32264+++ b/drivers/ide/ns87415.c
32265@@ -293,7 +293,7 @@ static const struct ide_dma_ops ns87415_dma_ops = {
32266 .dma_sff_read_status = superio_dma_sff_read_status,
32267 };
32268
32269-static const struct ide_port_info ns87415_chipset __devinitdata = {
32270+static const struct ide_port_info ns87415_chipset __devinitconst = {
32271 .name = DRV_NAME,
32272 .init_hwif = init_hwif_ns87415,
32273 .tp_ops = &ns87415_tp_ops,
32274diff --git a/drivers/ide/opti621.c b/drivers/ide/opti621.c
32275index 1a53a4c..39edc66 100644
32276--- a/drivers/ide/opti621.c
32277+++ b/drivers/ide/opti621.c
32278@@ -131,7 +131,7 @@ static const struct ide_port_ops opti621_port_ops = {
32279 .set_pio_mode = opti621_set_pio_mode,
32280 };
32281
32282-static const struct ide_port_info opti621_chipset __devinitdata = {
32283+static const struct ide_port_info opti621_chipset __devinitconst = {
32284 .name = DRV_NAME,
32285 .enablebits = { {0x45, 0x80, 0x00}, {0x40, 0x08, 0x00} },
32286 .port_ops = &opti621_port_ops,
32287diff --git a/drivers/ide/pdc202xx_new.c b/drivers/ide/pdc202xx_new.c
32288index 9546fe2..2e5ceb6 100644
32289--- a/drivers/ide/pdc202xx_new.c
32290+++ b/drivers/ide/pdc202xx_new.c
32291@@ -465,7 +465,7 @@ static const struct ide_port_ops pdcnew_port_ops = {
32292 .udma_mask = udma, \
32293 }
32294
32295-static const struct ide_port_info pdcnew_chipsets[] __devinitdata = {
32296+static const struct ide_port_info pdcnew_chipsets[] __devinitconst = {
32297 /* 0: PDC202{68,70} */ DECLARE_PDCNEW_DEV(ATA_UDMA5),
32298 /* 1: PDC202{69,71,75,76,77} */ DECLARE_PDCNEW_DEV(ATA_UDMA6),
32299 };
32300diff --git a/drivers/ide/pdc202xx_old.c b/drivers/ide/pdc202xx_old.c
32301index 3a35ec6..5634510 100644
32302--- a/drivers/ide/pdc202xx_old.c
32303+++ b/drivers/ide/pdc202xx_old.c
32304@@ -270,7 +270,7 @@ static const struct ide_dma_ops pdc2026x_dma_ops = {
32305 .max_sectors = sectors, \
32306 }
32307
32308-static const struct ide_port_info pdc202xx_chipsets[] __devinitdata = {
32309+static const struct ide_port_info pdc202xx_chipsets[] __devinitconst = {
32310 { /* 0: PDC20246 */
32311 .name = DRV_NAME,
32312 .init_chipset = init_chipset_pdc202xx,
32313diff --git a/drivers/ide/piix.c b/drivers/ide/piix.c
32314index 1892e81..fe0fd60 100644
32315--- a/drivers/ide/piix.c
32316+++ b/drivers/ide/piix.c
32317@@ -344,7 +344,7 @@ static const struct ide_port_ops ich_port_ops = {
32318 .udma_mask = udma, \
32319 }
32320
32321-static const struct ide_port_info piix_pci_info[] __devinitdata = {
32322+static const struct ide_port_info piix_pci_info[] __devinitconst = {
32323 /* 0: MPIIX */
32324 { /*
32325 * MPIIX actually has only a single IDE channel mapped to
32326diff --git a/drivers/ide/rz1000.c b/drivers/ide/rz1000.c
32327index a6414a8..c04173e 100644
32328--- a/drivers/ide/rz1000.c
32329+++ b/drivers/ide/rz1000.c
32330@@ -38,7 +38,7 @@ static int __devinit rz1000_disable_readahead(struct pci_dev *dev)
32331 }
32332 }
32333
32334-static const struct ide_port_info rz1000_chipset __devinitdata = {
32335+static const struct ide_port_info rz1000_chipset __devinitconst = {
32336 .name = DRV_NAME,
32337 .host_flags = IDE_HFLAG_NO_DMA,
32338 };
32339diff --git a/drivers/ide/sc1200.c b/drivers/ide/sc1200.c
32340index 356b9b5..d4758eb 100644
32341--- a/drivers/ide/sc1200.c
32342+++ b/drivers/ide/sc1200.c
32343@@ -291,7 +291,7 @@ static const struct ide_dma_ops sc1200_dma_ops = {
32344 .dma_sff_read_status = ide_dma_sff_read_status,
32345 };
32346
32347-static const struct ide_port_info sc1200_chipset __devinitdata = {
32348+static const struct ide_port_info sc1200_chipset __devinitconst = {
32349 .name = DRV_NAME,
32350 .port_ops = &sc1200_port_ops,
32351 .dma_ops = &sc1200_dma_ops,
32352diff --git a/drivers/ide/scc_pata.c b/drivers/ide/scc_pata.c
32353index b7f5b0c..9701038 100644
32354--- a/drivers/ide/scc_pata.c
32355+++ b/drivers/ide/scc_pata.c
32356@@ -811,7 +811,7 @@ static const struct ide_dma_ops scc_dma_ops = {
32357 .dma_sff_read_status = scc_dma_sff_read_status,
32358 };
32359
32360-static const struct ide_port_info scc_chipset __devinitdata = {
32361+static const struct ide_port_info scc_chipset __devinitconst = {
32362 .name = "sccIDE",
32363 .init_iops = init_iops_scc,
32364 .init_dma = scc_init_dma,
32365diff --git a/drivers/ide/serverworks.c b/drivers/ide/serverworks.c
32366index 35fb8da..24d72ef 100644
32367--- a/drivers/ide/serverworks.c
32368+++ b/drivers/ide/serverworks.c
32369@@ -337,7 +337,7 @@ static const struct ide_port_ops svwks_port_ops = {
32370 .cable_detect = svwks_cable_detect,
32371 };
32372
32373-static const struct ide_port_info serverworks_chipsets[] __devinitdata = {
32374+static const struct ide_port_info serverworks_chipsets[] __devinitconst = {
32375 { /* 0: OSB4 */
32376 .name = DRV_NAME,
32377 .init_chipset = init_chipset_svwks,
32378diff --git a/drivers/ide/siimage.c b/drivers/ide/siimage.c
32379index ddeda44..46f7e30 100644
32380--- a/drivers/ide/siimage.c
32381+++ b/drivers/ide/siimage.c
32382@@ -719,7 +719,7 @@ static const struct ide_dma_ops sil_dma_ops = {
32383 .udma_mask = ATA_UDMA6, \
32384 }
32385
32386-static const struct ide_port_info siimage_chipsets[] __devinitdata = {
32387+static const struct ide_port_info siimage_chipsets[] __devinitconst = {
32388 /* 0: SiI680 */ DECLARE_SII_DEV(&sil_pata_port_ops),
32389 /* 1: SiI3112 */ DECLARE_SII_DEV(&sil_sata_port_ops)
32390 };
32391diff --git a/drivers/ide/sis5513.c b/drivers/ide/sis5513.c
32392index 4a00225..09e61b4 100644
32393--- a/drivers/ide/sis5513.c
32394+++ b/drivers/ide/sis5513.c
32395@@ -563,7 +563,7 @@ static const struct ide_port_ops sis_ata133_port_ops = {
32396 .cable_detect = sis_cable_detect,
32397 };
32398
32399-static const struct ide_port_info sis5513_chipset __devinitdata = {
32400+static const struct ide_port_info sis5513_chipset __devinitconst = {
32401 .name = DRV_NAME,
32402 .init_chipset = init_chipset_sis5513,
32403 .enablebits = { {0x4a, 0x02, 0x02}, {0x4a, 0x04, 0x04} },
32404diff --git a/drivers/ide/sl82c105.c b/drivers/ide/sl82c105.c
32405index f21dc2a..d051cd2 100644
32406--- a/drivers/ide/sl82c105.c
32407+++ b/drivers/ide/sl82c105.c
32408@@ -299,7 +299,7 @@ static const struct ide_dma_ops sl82c105_dma_ops = {
32409 .dma_sff_read_status = ide_dma_sff_read_status,
32410 };
32411
32412-static const struct ide_port_info sl82c105_chipset __devinitdata = {
32413+static const struct ide_port_info sl82c105_chipset __devinitconst = {
32414 .name = DRV_NAME,
32415 .init_chipset = init_chipset_sl82c105,
32416 .enablebits = {{0x40,0x01,0x01}, {0x40,0x10,0x10}},
32417diff --git a/drivers/ide/slc90e66.c b/drivers/ide/slc90e66.c
32418index 864ffe0..863a5e9 100644
32419--- a/drivers/ide/slc90e66.c
32420+++ b/drivers/ide/slc90e66.c
32421@@ -132,7 +132,7 @@ static const struct ide_port_ops slc90e66_port_ops = {
32422 .cable_detect = slc90e66_cable_detect,
32423 };
32424
32425-static const struct ide_port_info slc90e66_chipset __devinitdata = {
32426+static const struct ide_port_info slc90e66_chipset __devinitconst = {
32427 .name = DRV_NAME,
32428 .enablebits = { {0x41, 0x80, 0x80}, {0x43, 0x80, 0x80} },
32429 .port_ops = &slc90e66_port_ops,
32430diff --git a/drivers/ide/tc86c001.c b/drivers/ide/tc86c001.c
32431index 4799d5c..1794678 100644
32432--- a/drivers/ide/tc86c001.c
32433+++ b/drivers/ide/tc86c001.c
32434@@ -192,7 +192,7 @@ static const struct ide_dma_ops tc86c001_dma_ops = {
32435 .dma_sff_read_status = ide_dma_sff_read_status,
32436 };
32437
32438-static const struct ide_port_info tc86c001_chipset __devinitdata = {
32439+static const struct ide_port_info tc86c001_chipset __devinitconst = {
32440 .name = DRV_NAME,
32441 .init_hwif = init_hwif_tc86c001,
32442 .port_ops = &tc86c001_port_ops,
32443diff --git a/drivers/ide/triflex.c b/drivers/ide/triflex.c
32444index 281c914..55ce1b8 100644
32445--- a/drivers/ide/triflex.c
32446+++ b/drivers/ide/triflex.c
32447@@ -92,7 +92,7 @@ static const struct ide_port_ops triflex_port_ops = {
32448 .set_dma_mode = triflex_set_mode,
32449 };
32450
32451-static const struct ide_port_info triflex_device __devinitdata = {
32452+static const struct ide_port_info triflex_device __devinitconst = {
32453 .name = DRV_NAME,
32454 .enablebits = {{0x80, 0x01, 0x01}, {0x80, 0x02, 0x02}},
32455 .port_ops = &triflex_port_ops,
32456diff --git a/drivers/ide/trm290.c b/drivers/ide/trm290.c
32457index 4b42ca0..e494a98 100644
32458--- a/drivers/ide/trm290.c
32459+++ b/drivers/ide/trm290.c
32460@@ -324,7 +324,7 @@ static struct ide_dma_ops trm290_dma_ops = {
32461 .dma_check = trm290_dma_check,
32462 };
32463
32464-static const struct ide_port_info trm290_chipset __devinitdata = {
32465+static const struct ide_port_info trm290_chipset __devinitconst = {
32466 .name = DRV_NAME,
32467 .init_hwif = init_hwif_trm290,
32468 .tp_ops = &trm290_tp_ops,
32469diff --git a/drivers/ide/via82cxxx.c b/drivers/ide/via82cxxx.c
32470index f46f49c..eb77678 100644
32471--- a/drivers/ide/via82cxxx.c
32472+++ b/drivers/ide/via82cxxx.c
32473@@ -403,7 +403,7 @@ static const struct ide_port_ops via_port_ops = {
32474 .cable_detect = via82cxxx_cable_detect,
32475 };
32476
32477-static const struct ide_port_info via82cxxx_chipset __devinitdata = {
32478+static const struct ide_port_info via82cxxx_chipset __devinitconst = {
32479 .name = DRV_NAME,
32480 .init_chipset = init_chipset_via82cxxx,
32481 .enablebits = { { 0x40, 0x02, 0x02 }, { 0x40, 0x01, 0x01 } },
32482diff --git a/drivers/ieee802154/fakehard.c b/drivers/ieee802154/fakehard.c
32483index 73d4531..c90cd2d 100644
32484--- a/drivers/ieee802154/fakehard.c
32485+++ b/drivers/ieee802154/fakehard.c
32486@@ -386,7 +386,7 @@ static int __devinit ieee802154fake_probe(struct platform_device *pdev)
32487 phy->transmit_power = 0xbf;
32488
32489 dev->netdev_ops = &fake_ops;
32490- dev->ml_priv = &fake_mlme;
32491+ dev->ml_priv = (void *)&fake_mlme;
32492
32493 priv = netdev_priv(dev);
32494 priv->phy = phy;
32495diff --git a/drivers/infiniband/core/cm.c b/drivers/infiniband/core/cm.c
32496index d67999f..4c5d083 100644
32497--- a/drivers/infiniband/core/cm.c
32498+++ b/drivers/infiniband/core/cm.c
32499@@ -114,7 +114,7 @@ static char const counter_group_names[CM_COUNTER_GROUPS]
32500
32501 struct cm_counter_group {
32502 struct kobject obj;
32503- atomic_long_t counter[CM_ATTR_COUNT];
32504+ atomic_long_unchecked_t counter[CM_ATTR_COUNT];
32505 };
32506
32507 struct cm_counter_attribute {
32508@@ -1394,7 +1394,7 @@ static void cm_dup_req_handler(struct cm_work *work,
32509 struct ib_mad_send_buf *msg = NULL;
32510 int ret;
32511
32512- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
32513+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
32514 counter[CM_REQ_COUNTER]);
32515
32516 /* Quick state check to discard duplicate REQs. */
32517@@ -1778,7 +1778,7 @@ static void cm_dup_rep_handler(struct cm_work *work)
32518 if (!cm_id_priv)
32519 return;
32520
32521- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
32522+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
32523 counter[CM_REP_COUNTER]);
32524 ret = cm_alloc_response_msg(work->port, work->mad_recv_wc, &msg);
32525 if (ret)
32526@@ -1945,7 +1945,7 @@ static int cm_rtu_handler(struct cm_work *work)
32527 if (cm_id_priv->id.state != IB_CM_REP_SENT &&
32528 cm_id_priv->id.state != IB_CM_MRA_REP_RCVD) {
32529 spin_unlock_irq(&cm_id_priv->lock);
32530- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
32531+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
32532 counter[CM_RTU_COUNTER]);
32533 goto out;
32534 }
32535@@ -2128,7 +2128,7 @@ static int cm_dreq_handler(struct cm_work *work)
32536 cm_id_priv = cm_acquire_id(dreq_msg->remote_comm_id,
32537 dreq_msg->local_comm_id);
32538 if (!cm_id_priv) {
32539- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
32540+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
32541 counter[CM_DREQ_COUNTER]);
32542 cm_issue_drep(work->port, work->mad_recv_wc);
32543 return -EINVAL;
32544@@ -2153,7 +2153,7 @@ static int cm_dreq_handler(struct cm_work *work)
32545 case IB_CM_MRA_REP_RCVD:
32546 break;
32547 case IB_CM_TIMEWAIT:
32548- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
32549+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
32550 counter[CM_DREQ_COUNTER]);
32551 if (cm_alloc_response_msg(work->port, work->mad_recv_wc, &msg))
32552 goto unlock;
32553@@ -2167,7 +2167,7 @@ static int cm_dreq_handler(struct cm_work *work)
32554 cm_free_msg(msg);
32555 goto deref;
32556 case IB_CM_DREQ_RCVD:
32557- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
32558+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
32559 counter[CM_DREQ_COUNTER]);
32560 goto unlock;
32561 default:
32562@@ -2534,7 +2534,7 @@ static int cm_mra_handler(struct cm_work *work)
32563 ib_modify_mad(cm_id_priv->av.port->mad_agent,
32564 cm_id_priv->msg, timeout)) {
32565 if (cm_id_priv->id.lap_state == IB_CM_MRA_LAP_RCVD)
32566- atomic_long_inc(&work->port->
32567+ atomic_long_inc_unchecked(&work->port->
32568 counter_group[CM_RECV_DUPLICATES].
32569 counter[CM_MRA_COUNTER]);
32570 goto out;
32571@@ -2543,7 +2543,7 @@ static int cm_mra_handler(struct cm_work *work)
32572 break;
32573 case IB_CM_MRA_REQ_RCVD:
32574 case IB_CM_MRA_REP_RCVD:
32575- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
32576+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
32577 counter[CM_MRA_COUNTER]);
32578 /* fall through */
32579 default:
32580@@ -2705,7 +2705,7 @@ static int cm_lap_handler(struct cm_work *work)
32581 case IB_CM_LAP_IDLE:
32582 break;
32583 case IB_CM_MRA_LAP_SENT:
32584- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
32585+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
32586 counter[CM_LAP_COUNTER]);
32587 if (cm_alloc_response_msg(work->port, work->mad_recv_wc, &msg))
32588 goto unlock;
32589@@ -2721,7 +2721,7 @@ static int cm_lap_handler(struct cm_work *work)
32590 cm_free_msg(msg);
32591 goto deref;
32592 case IB_CM_LAP_RCVD:
32593- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
32594+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
32595 counter[CM_LAP_COUNTER]);
32596 goto unlock;
32597 default:
32598@@ -3005,7 +3005,7 @@ static int cm_sidr_req_handler(struct cm_work *work)
32599 cur_cm_id_priv = cm_insert_remote_sidr(cm_id_priv);
32600 if (cur_cm_id_priv) {
32601 spin_unlock_irq(&cm.lock);
32602- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
32603+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
32604 counter[CM_SIDR_REQ_COUNTER]);
32605 goto out; /* Duplicate message. */
32606 }
32607@@ -3217,10 +3217,10 @@ static void cm_send_handler(struct ib_mad_agent *mad_agent,
32608 if (!msg->context[0] && (attr_index != CM_REJ_COUNTER))
32609 msg->retries = 1;
32610
32611- atomic_long_add(1 + msg->retries,
32612+ atomic_long_add_unchecked(1 + msg->retries,
32613 &port->counter_group[CM_XMIT].counter[attr_index]);
32614 if (msg->retries)
32615- atomic_long_add(msg->retries,
32616+ atomic_long_add_unchecked(msg->retries,
32617 &port->counter_group[CM_XMIT_RETRIES].
32618 counter[attr_index]);
32619
32620@@ -3430,7 +3430,7 @@ static void cm_recv_handler(struct ib_mad_agent *mad_agent,
32621 }
32622
32623 attr_id = be16_to_cpu(mad_recv_wc->recv_buf.mad->mad_hdr.attr_id);
32624- atomic_long_inc(&port->counter_group[CM_RECV].
32625+ atomic_long_inc_unchecked(&port->counter_group[CM_RECV].
32626 counter[attr_id - CM_ATTR_ID_OFFSET]);
32627
32628 work = kmalloc(sizeof *work + sizeof(struct ib_sa_path_rec) * paths,
32629@@ -3635,7 +3635,7 @@ static ssize_t cm_show_counter(struct kobject *obj, struct attribute *attr,
32630 cm_attr = container_of(attr, struct cm_counter_attribute, attr);
32631
32632 return sprintf(buf, "%ld\n",
32633- atomic_long_read(&group->counter[cm_attr->index]));
32634+ atomic_long_read_unchecked(&group->counter[cm_attr->index]));
32635 }
32636
32637 static const struct sysfs_ops cm_counter_ops = {
32638diff --git a/drivers/infiniband/core/fmr_pool.c b/drivers/infiniband/core/fmr_pool.c
32639index 176c8f9..2627b62 100644
32640--- a/drivers/infiniband/core/fmr_pool.c
32641+++ b/drivers/infiniband/core/fmr_pool.c
32642@@ -98,8 +98,8 @@ struct ib_fmr_pool {
32643
32644 struct task_struct *thread;
32645
32646- atomic_t req_ser;
32647- atomic_t flush_ser;
32648+ atomic_unchecked_t req_ser;
32649+ atomic_unchecked_t flush_ser;
32650
32651 wait_queue_head_t force_wait;
32652 };
32653@@ -180,10 +180,10 @@ static int ib_fmr_cleanup_thread(void *pool_ptr)
32654 struct ib_fmr_pool *pool = pool_ptr;
32655
32656 do {
32657- if (atomic_read(&pool->flush_ser) - atomic_read(&pool->req_ser) < 0) {
32658+ if (atomic_read_unchecked(&pool->flush_ser) - atomic_read_unchecked(&pool->req_ser) < 0) {
32659 ib_fmr_batch_release(pool);
32660
32661- atomic_inc(&pool->flush_ser);
32662+ atomic_inc_unchecked(&pool->flush_ser);
32663 wake_up_interruptible(&pool->force_wait);
32664
32665 if (pool->flush_function)
32666@@ -191,7 +191,7 @@ static int ib_fmr_cleanup_thread(void *pool_ptr)
32667 }
32668
32669 set_current_state(TASK_INTERRUPTIBLE);
32670- if (atomic_read(&pool->flush_ser) - atomic_read(&pool->req_ser) >= 0 &&
32671+ if (atomic_read_unchecked(&pool->flush_ser) - atomic_read_unchecked(&pool->req_ser) >= 0 &&
32672 !kthread_should_stop())
32673 schedule();
32674 __set_current_state(TASK_RUNNING);
32675@@ -283,8 +283,8 @@ struct ib_fmr_pool *ib_create_fmr_pool(struct ib_pd *pd,
32676 pool->dirty_watermark = params->dirty_watermark;
32677 pool->dirty_len = 0;
32678 spin_lock_init(&pool->pool_lock);
32679- atomic_set(&pool->req_ser, 0);
32680- atomic_set(&pool->flush_ser, 0);
32681+ atomic_set_unchecked(&pool->req_ser, 0);
32682+ atomic_set_unchecked(&pool->flush_ser, 0);
32683 init_waitqueue_head(&pool->force_wait);
32684
32685 pool->thread = kthread_run(ib_fmr_cleanup_thread,
32686@@ -412,11 +412,11 @@ int ib_flush_fmr_pool(struct ib_fmr_pool *pool)
32687 }
32688 spin_unlock_irq(&pool->pool_lock);
32689
32690- serial = atomic_inc_return(&pool->req_ser);
32691+ serial = atomic_inc_return_unchecked(&pool->req_ser);
32692 wake_up_process(pool->thread);
32693
32694 if (wait_event_interruptible(pool->force_wait,
32695- atomic_read(&pool->flush_ser) - serial >= 0))
32696+ atomic_read_unchecked(&pool->flush_ser) - serial >= 0))
32697 return -EINTR;
32698
32699 return 0;
32700@@ -526,7 +526,7 @@ int ib_fmr_pool_unmap(struct ib_pool_fmr *fmr)
32701 } else {
32702 list_add_tail(&fmr->list, &pool->dirty_list);
32703 if (++pool->dirty_len >= pool->dirty_watermark) {
32704- atomic_inc(&pool->req_ser);
32705+ atomic_inc_unchecked(&pool->req_ser);
32706 wake_up_process(pool->thread);
32707 }
32708 }
32709diff --git a/drivers/infiniband/hw/cxgb4/mem.c b/drivers/infiniband/hw/cxgb4/mem.c
32710index 57e07c6..56d09d4 100644
32711--- a/drivers/infiniband/hw/cxgb4/mem.c
32712+++ b/drivers/infiniband/hw/cxgb4/mem.c
32713@@ -122,7 +122,7 @@ static int write_tpt_entry(struct c4iw_rdev *rdev, u32 reset_tpt_entry,
32714 int err;
32715 struct fw_ri_tpte tpt;
32716 u32 stag_idx;
32717- static atomic_t key;
32718+ static atomic_unchecked_t key;
32719
32720 if (c4iw_fatal_error(rdev))
32721 return -EIO;
32722@@ -139,7 +139,7 @@ static int write_tpt_entry(struct c4iw_rdev *rdev, u32 reset_tpt_entry,
32723 if (rdev->stats.stag.cur > rdev->stats.stag.max)
32724 rdev->stats.stag.max = rdev->stats.stag.cur;
32725 mutex_unlock(&rdev->stats.lock);
32726- *stag = (stag_idx << 8) | (atomic_inc_return(&key) & 0xff);
32727+ *stag = (stag_idx << 8) | (atomic_inc_return_unchecked(&key) & 0xff);
32728 }
32729 PDBG("%s stag_state 0x%0x type 0x%0x pdid 0x%0x, stag_idx 0x%x\n",
32730 __func__, stag_state, type, pdid, stag_idx);
32731diff --git a/drivers/infiniband/hw/ipath/ipath_rc.c b/drivers/infiniband/hw/ipath/ipath_rc.c
32732index 79b3dbc..96e5fcc 100644
32733--- a/drivers/infiniband/hw/ipath/ipath_rc.c
32734+++ b/drivers/infiniband/hw/ipath/ipath_rc.c
32735@@ -1868,7 +1868,7 @@ void ipath_rc_rcv(struct ipath_ibdev *dev, struct ipath_ib_header *hdr,
32736 struct ib_atomic_eth *ateth;
32737 struct ipath_ack_entry *e;
32738 u64 vaddr;
32739- atomic64_t *maddr;
32740+ atomic64_unchecked_t *maddr;
32741 u64 sdata;
32742 u32 rkey;
32743 u8 next;
32744@@ -1903,11 +1903,11 @@ void ipath_rc_rcv(struct ipath_ibdev *dev, struct ipath_ib_header *hdr,
32745 IB_ACCESS_REMOTE_ATOMIC)))
32746 goto nack_acc_unlck;
32747 /* Perform atomic OP and save result. */
32748- maddr = (atomic64_t *) qp->r_sge.sge.vaddr;
32749+ maddr = (atomic64_unchecked_t *) qp->r_sge.sge.vaddr;
32750 sdata = be64_to_cpu(ateth->swap_data);
32751 e = &qp->s_ack_queue[qp->r_head_ack_queue];
32752 e->atomic_data = (opcode == OP(FETCH_ADD)) ?
32753- (u64) atomic64_add_return(sdata, maddr) - sdata :
32754+ (u64) atomic64_add_return_unchecked(sdata, maddr) - sdata :
32755 (u64) cmpxchg((u64 *) qp->r_sge.sge.vaddr,
32756 be64_to_cpu(ateth->compare_data),
32757 sdata);
32758diff --git a/drivers/infiniband/hw/ipath/ipath_ruc.c b/drivers/infiniband/hw/ipath/ipath_ruc.c
32759index 1f95bba..9530f87 100644
32760--- a/drivers/infiniband/hw/ipath/ipath_ruc.c
32761+++ b/drivers/infiniband/hw/ipath/ipath_ruc.c
32762@@ -266,7 +266,7 @@ static void ipath_ruc_loopback(struct ipath_qp *sqp)
32763 unsigned long flags;
32764 struct ib_wc wc;
32765 u64 sdata;
32766- atomic64_t *maddr;
32767+ atomic64_unchecked_t *maddr;
32768 enum ib_wc_status send_status;
32769
32770 /*
32771@@ -382,11 +382,11 @@ again:
32772 IB_ACCESS_REMOTE_ATOMIC)))
32773 goto acc_err;
32774 /* Perform atomic OP and save result. */
32775- maddr = (atomic64_t *) qp->r_sge.sge.vaddr;
32776+ maddr = (atomic64_unchecked_t *) qp->r_sge.sge.vaddr;
32777 sdata = wqe->wr.wr.atomic.compare_add;
32778 *(u64 *) sqp->s_sge.sge.vaddr =
32779 (wqe->wr.opcode == IB_WR_ATOMIC_FETCH_AND_ADD) ?
32780- (u64) atomic64_add_return(sdata, maddr) - sdata :
32781+ (u64) atomic64_add_return_unchecked(sdata, maddr) - sdata :
32782 (u64) cmpxchg((u64 *) qp->r_sge.sge.vaddr,
32783 sdata, wqe->wr.wr.atomic.swap);
32784 goto send_comp;
32785diff --git a/drivers/infiniband/hw/nes/nes.c b/drivers/infiniband/hw/nes/nes.c
32786index 7140199..da60063 100644
32787--- a/drivers/infiniband/hw/nes/nes.c
32788+++ b/drivers/infiniband/hw/nes/nes.c
32789@@ -103,7 +103,7 @@ MODULE_PARM_DESC(limit_maxrdreqsz, "Limit max read request size to 256 Bytes");
32790 LIST_HEAD(nes_adapter_list);
32791 static LIST_HEAD(nes_dev_list);
32792
32793-atomic_t qps_destroyed;
32794+atomic_unchecked_t qps_destroyed;
32795
32796 static unsigned int ee_flsh_adapter;
32797 static unsigned int sysfs_nonidx_addr;
32798@@ -272,7 +272,7 @@ static void nes_cqp_rem_ref_callback(struct nes_device *nesdev, struct nes_cqp_r
32799 struct nes_qp *nesqp = cqp_request->cqp_callback_pointer;
32800 struct nes_adapter *nesadapter = nesdev->nesadapter;
32801
32802- atomic_inc(&qps_destroyed);
32803+ atomic_inc_unchecked(&qps_destroyed);
32804
32805 /* Free the control structures */
32806
32807diff --git a/drivers/infiniband/hw/nes/nes.h b/drivers/infiniband/hw/nes/nes.h
32808index c438e46..ca30356 100644
32809--- a/drivers/infiniband/hw/nes/nes.h
32810+++ b/drivers/infiniband/hw/nes/nes.h
32811@@ -178,17 +178,17 @@ extern unsigned int nes_debug_level;
32812 extern unsigned int wqm_quanta;
32813 extern struct list_head nes_adapter_list;
32814
32815-extern atomic_t cm_connects;
32816-extern atomic_t cm_accepts;
32817-extern atomic_t cm_disconnects;
32818-extern atomic_t cm_closes;
32819-extern atomic_t cm_connecteds;
32820-extern atomic_t cm_connect_reqs;
32821-extern atomic_t cm_rejects;
32822-extern atomic_t mod_qp_timouts;
32823-extern atomic_t qps_created;
32824-extern atomic_t qps_destroyed;
32825-extern atomic_t sw_qps_destroyed;
32826+extern atomic_unchecked_t cm_connects;
32827+extern atomic_unchecked_t cm_accepts;
32828+extern atomic_unchecked_t cm_disconnects;
32829+extern atomic_unchecked_t cm_closes;
32830+extern atomic_unchecked_t cm_connecteds;
32831+extern atomic_unchecked_t cm_connect_reqs;
32832+extern atomic_unchecked_t cm_rejects;
32833+extern atomic_unchecked_t mod_qp_timouts;
32834+extern atomic_unchecked_t qps_created;
32835+extern atomic_unchecked_t qps_destroyed;
32836+extern atomic_unchecked_t sw_qps_destroyed;
32837 extern u32 mh_detected;
32838 extern u32 mh_pauses_sent;
32839 extern u32 cm_packets_sent;
32840@@ -197,16 +197,16 @@ extern u32 cm_packets_created;
32841 extern u32 cm_packets_received;
32842 extern u32 cm_packets_dropped;
32843 extern u32 cm_packets_retrans;
32844-extern atomic_t cm_listens_created;
32845-extern atomic_t cm_listens_destroyed;
32846+extern atomic_unchecked_t cm_listens_created;
32847+extern atomic_unchecked_t cm_listens_destroyed;
32848 extern u32 cm_backlog_drops;
32849-extern atomic_t cm_loopbacks;
32850-extern atomic_t cm_nodes_created;
32851-extern atomic_t cm_nodes_destroyed;
32852-extern atomic_t cm_accel_dropped_pkts;
32853-extern atomic_t cm_resets_recvd;
32854-extern atomic_t pau_qps_created;
32855-extern atomic_t pau_qps_destroyed;
32856+extern atomic_unchecked_t cm_loopbacks;
32857+extern atomic_unchecked_t cm_nodes_created;
32858+extern atomic_unchecked_t cm_nodes_destroyed;
32859+extern atomic_unchecked_t cm_accel_dropped_pkts;
32860+extern atomic_unchecked_t cm_resets_recvd;
32861+extern atomic_unchecked_t pau_qps_created;
32862+extern atomic_unchecked_t pau_qps_destroyed;
32863
32864 extern u32 int_mod_timer_init;
32865 extern u32 int_mod_cq_depth_256;
32866diff --git a/drivers/infiniband/hw/nes/nes_cm.c b/drivers/infiniband/hw/nes/nes_cm.c
32867index 020e95c..fbb3450 100644
32868--- a/drivers/infiniband/hw/nes/nes_cm.c
32869+++ b/drivers/infiniband/hw/nes/nes_cm.c
32870@@ -68,14 +68,14 @@ u32 cm_packets_dropped;
32871 u32 cm_packets_retrans;
32872 u32 cm_packets_created;
32873 u32 cm_packets_received;
32874-atomic_t cm_listens_created;
32875-atomic_t cm_listens_destroyed;
32876+atomic_unchecked_t cm_listens_created;
32877+atomic_unchecked_t cm_listens_destroyed;
32878 u32 cm_backlog_drops;
32879-atomic_t cm_loopbacks;
32880-atomic_t cm_nodes_created;
32881-atomic_t cm_nodes_destroyed;
32882-atomic_t cm_accel_dropped_pkts;
32883-atomic_t cm_resets_recvd;
32884+atomic_unchecked_t cm_loopbacks;
32885+atomic_unchecked_t cm_nodes_created;
32886+atomic_unchecked_t cm_nodes_destroyed;
32887+atomic_unchecked_t cm_accel_dropped_pkts;
32888+atomic_unchecked_t cm_resets_recvd;
32889
32890 static inline int mini_cm_accelerated(struct nes_cm_core *, struct nes_cm_node *);
32891 static struct nes_cm_listener *mini_cm_listen(struct nes_cm_core *, struct nes_vnic *, struct nes_cm_info *);
32892@@ -148,13 +148,13 @@ static struct nes_cm_ops nes_cm_api = {
32893
32894 static struct nes_cm_core *g_cm_core;
32895
32896-atomic_t cm_connects;
32897-atomic_t cm_accepts;
32898-atomic_t cm_disconnects;
32899-atomic_t cm_closes;
32900-atomic_t cm_connecteds;
32901-atomic_t cm_connect_reqs;
32902-atomic_t cm_rejects;
32903+atomic_unchecked_t cm_connects;
32904+atomic_unchecked_t cm_accepts;
32905+atomic_unchecked_t cm_disconnects;
32906+atomic_unchecked_t cm_closes;
32907+atomic_unchecked_t cm_connecteds;
32908+atomic_unchecked_t cm_connect_reqs;
32909+atomic_unchecked_t cm_rejects;
32910
32911 int nes_add_ref_cm_node(struct nes_cm_node *cm_node)
32912 {
32913@@ -1279,7 +1279,7 @@ static int mini_cm_dec_refcnt_listen(struct nes_cm_core *cm_core,
32914 kfree(listener);
32915 listener = NULL;
32916 ret = 0;
32917- atomic_inc(&cm_listens_destroyed);
32918+ atomic_inc_unchecked(&cm_listens_destroyed);
32919 } else {
32920 spin_unlock_irqrestore(&cm_core->listen_list_lock, flags);
32921 }
32922@@ -1482,7 +1482,7 @@ static struct nes_cm_node *make_cm_node(struct nes_cm_core *cm_core,
32923 cm_node->rem_mac);
32924
32925 add_hte_node(cm_core, cm_node);
32926- atomic_inc(&cm_nodes_created);
32927+ atomic_inc_unchecked(&cm_nodes_created);
32928
32929 return cm_node;
32930 }
32931@@ -1540,7 +1540,7 @@ static int rem_ref_cm_node(struct nes_cm_core *cm_core,
32932 }
32933
32934 atomic_dec(&cm_core->node_cnt);
32935- atomic_inc(&cm_nodes_destroyed);
32936+ atomic_inc_unchecked(&cm_nodes_destroyed);
32937 nesqp = cm_node->nesqp;
32938 if (nesqp) {
32939 nesqp->cm_node = NULL;
32940@@ -1604,7 +1604,7 @@ static int process_options(struct nes_cm_node *cm_node, u8 *optionsloc,
32941
32942 static void drop_packet(struct sk_buff *skb)
32943 {
32944- atomic_inc(&cm_accel_dropped_pkts);
32945+ atomic_inc_unchecked(&cm_accel_dropped_pkts);
32946 dev_kfree_skb_any(skb);
32947 }
32948
32949@@ -1667,7 +1667,7 @@ static void handle_rst_pkt(struct nes_cm_node *cm_node, struct sk_buff *skb,
32950 {
32951
32952 int reset = 0; /* whether to send reset in case of err.. */
32953- atomic_inc(&cm_resets_recvd);
32954+ atomic_inc_unchecked(&cm_resets_recvd);
32955 nes_debug(NES_DBG_CM, "Received Reset, cm_node = %p, state = %u."
32956 " refcnt=%d\n", cm_node, cm_node->state,
32957 atomic_read(&cm_node->ref_count));
32958@@ -2308,7 +2308,7 @@ static struct nes_cm_node *mini_cm_connect(struct nes_cm_core *cm_core,
32959 rem_ref_cm_node(cm_node->cm_core, cm_node);
32960 return NULL;
32961 }
32962- atomic_inc(&cm_loopbacks);
32963+ atomic_inc_unchecked(&cm_loopbacks);
32964 loopbackremotenode->loopbackpartner = cm_node;
32965 loopbackremotenode->tcp_cntxt.rcv_wscale =
32966 NES_CM_DEFAULT_RCV_WND_SCALE;
32967@@ -2583,7 +2583,7 @@ static int mini_cm_recv_pkt(struct nes_cm_core *cm_core,
32968 nes_queue_mgt_skbs(skb, nesvnic, cm_node->nesqp);
32969 else {
32970 rem_ref_cm_node(cm_core, cm_node);
32971- atomic_inc(&cm_accel_dropped_pkts);
32972+ atomic_inc_unchecked(&cm_accel_dropped_pkts);
32973 dev_kfree_skb_any(skb);
32974 }
32975 break;
32976@@ -2891,7 +2891,7 @@ static int nes_cm_disconn_true(struct nes_qp *nesqp)
32977
32978 if ((cm_id) && (cm_id->event_handler)) {
32979 if (issue_disconn) {
32980- atomic_inc(&cm_disconnects);
32981+ atomic_inc_unchecked(&cm_disconnects);
32982 cm_event.event = IW_CM_EVENT_DISCONNECT;
32983 cm_event.status = disconn_status;
32984 cm_event.local_addr = cm_id->local_addr;
32985@@ -2913,7 +2913,7 @@ static int nes_cm_disconn_true(struct nes_qp *nesqp)
32986 }
32987
32988 if (issue_close) {
32989- atomic_inc(&cm_closes);
32990+ atomic_inc_unchecked(&cm_closes);
32991 nes_disconnect(nesqp, 1);
32992
32993 cm_id->provider_data = nesqp;
32994@@ -3049,7 +3049,7 @@ int nes_accept(struct iw_cm_id *cm_id, struct iw_cm_conn_param *conn_param)
32995
32996 nes_debug(NES_DBG_CM, "QP%u, cm_node=%p, jiffies = %lu listener = %p\n",
32997 nesqp->hwqp.qp_id, cm_node, jiffies, cm_node->listener);
32998- atomic_inc(&cm_accepts);
32999+ atomic_inc_unchecked(&cm_accepts);
33000
33001 nes_debug(NES_DBG_CM, "netdev refcnt = %u.\n",
33002 netdev_refcnt_read(nesvnic->netdev));
33003@@ -3251,7 +3251,7 @@ int nes_reject(struct iw_cm_id *cm_id, const void *pdata, u8 pdata_len)
33004 struct nes_cm_core *cm_core;
33005 u8 *start_buff;
33006
33007- atomic_inc(&cm_rejects);
33008+ atomic_inc_unchecked(&cm_rejects);
33009 cm_node = (struct nes_cm_node *)cm_id->provider_data;
33010 loopback = cm_node->loopbackpartner;
33011 cm_core = cm_node->cm_core;
33012@@ -3311,7 +3311,7 @@ int nes_connect(struct iw_cm_id *cm_id, struct iw_cm_conn_param *conn_param)
33013 ntohl(cm_id->local_addr.sin_addr.s_addr),
33014 ntohs(cm_id->local_addr.sin_port));
33015
33016- atomic_inc(&cm_connects);
33017+ atomic_inc_unchecked(&cm_connects);
33018 nesqp->active_conn = 1;
33019
33020 /* cache the cm_id in the qp */
33021@@ -3421,7 +3421,7 @@ int nes_create_listen(struct iw_cm_id *cm_id, int backlog)
33022 g_cm_core->api->stop_listener(g_cm_core, (void *)cm_node);
33023 return err;
33024 }
33025- atomic_inc(&cm_listens_created);
33026+ atomic_inc_unchecked(&cm_listens_created);
33027 }
33028
33029 cm_id->add_ref(cm_id);
33030@@ -3522,7 +3522,7 @@ static void cm_event_connected(struct nes_cm_event *event)
33031
33032 if (nesqp->destroyed)
33033 return;
33034- atomic_inc(&cm_connecteds);
33035+ atomic_inc_unchecked(&cm_connecteds);
33036 nes_debug(NES_DBG_CM, "QP%u attempting to connect to 0x%08X:0x%04X on"
33037 " local port 0x%04X. jiffies = %lu.\n",
33038 nesqp->hwqp.qp_id,
33039@@ -3709,7 +3709,7 @@ static void cm_event_reset(struct nes_cm_event *event)
33040
33041 cm_id->add_ref(cm_id);
33042 ret = cm_id->event_handler(cm_id, &cm_event);
33043- atomic_inc(&cm_closes);
33044+ atomic_inc_unchecked(&cm_closes);
33045 cm_event.event = IW_CM_EVENT_CLOSE;
33046 cm_event.status = 0;
33047 cm_event.provider_data = cm_id->provider_data;
33048@@ -3745,7 +3745,7 @@ static void cm_event_mpa_req(struct nes_cm_event *event)
33049 return;
33050 cm_id = cm_node->cm_id;
33051
33052- atomic_inc(&cm_connect_reqs);
33053+ atomic_inc_unchecked(&cm_connect_reqs);
33054 nes_debug(NES_DBG_CM, "cm_node = %p - cm_id = %p, jiffies = %lu\n",
33055 cm_node, cm_id, jiffies);
33056
33057@@ -3785,7 +3785,7 @@ static void cm_event_mpa_reject(struct nes_cm_event *event)
33058 return;
33059 cm_id = cm_node->cm_id;
33060
33061- atomic_inc(&cm_connect_reqs);
33062+ atomic_inc_unchecked(&cm_connect_reqs);
33063 nes_debug(NES_DBG_CM, "cm_node = %p - cm_id = %p, jiffies = %lu\n",
33064 cm_node, cm_id, jiffies);
33065
33066diff --git a/drivers/infiniband/hw/nes/nes_mgt.c b/drivers/infiniband/hw/nes/nes_mgt.c
33067index 3ba7be3..c81f6ff 100644
33068--- a/drivers/infiniband/hw/nes/nes_mgt.c
33069+++ b/drivers/infiniband/hw/nes/nes_mgt.c
33070@@ -40,8 +40,8 @@
33071 #include "nes.h"
33072 #include "nes_mgt.h"
33073
33074-atomic_t pau_qps_created;
33075-atomic_t pau_qps_destroyed;
33076+atomic_unchecked_t pau_qps_created;
33077+atomic_unchecked_t pau_qps_destroyed;
33078
33079 static void nes_replenish_mgt_rq(struct nes_vnic_mgt *mgtvnic)
33080 {
33081@@ -621,7 +621,7 @@ void nes_destroy_pau_qp(struct nes_device *nesdev, struct nes_qp *nesqp)
33082 {
33083 struct sk_buff *skb;
33084 unsigned long flags;
33085- atomic_inc(&pau_qps_destroyed);
33086+ atomic_inc_unchecked(&pau_qps_destroyed);
33087
33088 /* Free packets that have not yet been forwarded */
33089 /* Lock is acquired by skb_dequeue when removing the skb */
33090@@ -812,7 +812,7 @@ static void nes_mgt_ce_handler(struct nes_device *nesdev, struct nes_hw_nic_cq *
33091 cq->cq_vbase[head].cqe_words[NES_NIC_CQE_HASH_RCVNXT]);
33092 skb_queue_head_init(&nesqp->pau_list);
33093 spin_lock_init(&nesqp->pau_lock);
33094- atomic_inc(&pau_qps_created);
33095+ atomic_inc_unchecked(&pau_qps_created);
33096 nes_change_quad_hash(nesdev, mgtvnic->nesvnic, nesqp);
33097 }
33098
33099diff --git a/drivers/infiniband/hw/nes/nes_nic.c b/drivers/infiniband/hw/nes/nes_nic.c
33100index f3a3ecf..57d311d 100644
33101--- a/drivers/infiniband/hw/nes/nes_nic.c
33102+++ b/drivers/infiniband/hw/nes/nes_nic.c
33103@@ -1277,39 +1277,39 @@ static void nes_netdev_get_ethtool_stats(struct net_device *netdev,
33104 target_stat_values[++index] = mh_detected;
33105 target_stat_values[++index] = mh_pauses_sent;
33106 target_stat_values[++index] = nesvnic->endnode_ipv4_tcp_retransmits;
33107- target_stat_values[++index] = atomic_read(&cm_connects);
33108- target_stat_values[++index] = atomic_read(&cm_accepts);
33109- target_stat_values[++index] = atomic_read(&cm_disconnects);
33110- target_stat_values[++index] = atomic_read(&cm_connecteds);
33111- target_stat_values[++index] = atomic_read(&cm_connect_reqs);
33112- target_stat_values[++index] = atomic_read(&cm_rejects);
33113- target_stat_values[++index] = atomic_read(&mod_qp_timouts);
33114- target_stat_values[++index] = atomic_read(&qps_created);
33115- target_stat_values[++index] = atomic_read(&sw_qps_destroyed);
33116- target_stat_values[++index] = atomic_read(&qps_destroyed);
33117- target_stat_values[++index] = atomic_read(&cm_closes);
33118+ target_stat_values[++index] = atomic_read_unchecked(&cm_connects);
33119+ target_stat_values[++index] = atomic_read_unchecked(&cm_accepts);
33120+ target_stat_values[++index] = atomic_read_unchecked(&cm_disconnects);
33121+ target_stat_values[++index] = atomic_read_unchecked(&cm_connecteds);
33122+ target_stat_values[++index] = atomic_read_unchecked(&cm_connect_reqs);
33123+ target_stat_values[++index] = atomic_read_unchecked(&cm_rejects);
33124+ target_stat_values[++index] = atomic_read_unchecked(&mod_qp_timouts);
33125+ target_stat_values[++index] = atomic_read_unchecked(&qps_created);
33126+ target_stat_values[++index] = atomic_read_unchecked(&sw_qps_destroyed);
33127+ target_stat_values[++index] = atomic_read_unchecked(&qps_destroyed);
33128+ target_stat_values[++index] = atomic_read_unchecked(&cm_closes);
33129 target_stat_values[++index] = cm_packets_sent;
33130 target_stat_values[++index] = cm_packets_bounced;
33131 target_stat_values[++index] = cm_packets_created;
33132 target_stat_values[++index] = cm_packets_received;
33133 target_stat_values[++index] = cm_packets_dropped;
33134 target_stat_values[++index] = cm_packets_retrans;
33135- target_stat_values[++index] = atomic_read(&cm_listens_created);
33136- target_stat_values[++index] = atomic_read(&cm_listens_destroyed);
33137+ target_stat_values[++index] = atomic_read_unchecked(&cm_listens_created);
33138+ target_stat_values[++index] = atomic_read_unchecked(&cm_listens_destroyed);
33139 target_stat_values[++index] = cm_backlog_drops;
33140- target_stat_values[++index] = atomic_read(&cm_loopbacks);
33141- target_stat_values[++index] = atomic_read(&cm_nodes_created);
33142- target_stat_values[++index] = atomic_read(&cm_nodes_destroyed);
33143- target_stat_values[++index] = atomic_read(&cm_accel_dropped_pkts);
33144- target_stat_values[++index] = atomic_read(&cm_resets_recvd);
33145+ target_stat_values[++index] = atomic_read_unchecked(&cm_loopbacks);
33146+ target_stat_values[++index] = atomic_read_unchecked(&cm_nodes_created);
33147+ target_stat_values[++index] = atomic_read_unchecked(&cm_nodes_destroyed);
33148+ target_stat_values[++index] = atomic_read_unchecked(&cm_accel_dropped_pkts);
33149+ target_stat_values[++index] = atomic_read_unchecked(&cm_resets_recvd);
33150 target_stat_values[++index] = nesadapter->free_4kpbl;
33151 target_stat_values[++index] = nesadapter->free_256pbl;
33152 target_stat_values[++index] = int_mod_timer_init;
33153 target_stat_values[++index] = nesvnic->lro_mgr.stats.aggregated;
33154 target_stat_values[++index] = nesvnic->lro_mgr.stats.flushed;
33155 target_stat_values[++index] = nesvnic->lro_mgr.stats.no_desc;
33156- target_stat_values[++index] = atomic_read(&pau_qps_created);
33157- target_stat_values[++index] = atomic_read(&pau_qps_destroyed);
33158+ target_stat_values[++index] = atomic_read_unchecked(&pau_qps_created);
33159+ target_stat_values[++index] = atomic_read_unchecked(&pau_qps_destroyed);
33160 }
33161
33162 /**
33163diff --git a/drivers/infiniband/hw/nes/nes_verbs.c b/drivers/infiniband/hw/nes/nes_verbs.c
33164index 8b8812d..a5e1133 100644
33165--- a/drivers/infiniband/hw/nes/nes_verbs.c
33166+++ b/drivers/infiniband/hw/nes/nes_verbs.c
33167@@ -46,9 +46,9 @@
33168
33169 #include <rdma/ib_umem.h>
33170
33171-atomic_t mod_qp_timouts;
33172-atomic_t qps_created;
33173-atomic_t sw_qps_destroyed;
33174+atomic_unchecked_t mod_qp_timouts;
33175+atomic_unchecked_t qps_created;
33176+atomic_unchecked_t sw_qps_destroyed;
33177
33178 static void nes_unregister_ofa_device(struct nes_ib_device *nesibdev);
33179
33180@@ -1131,7 +1131,7 @@ static struct ib_qp *nes_create_qp(struct ib_pd *ibpd,
33181 if (init_attr->create_flags)
33182 return ERR_PTR(-EINVAL);
33183
33184- atomic_inc(&qps_created);
33185+ atomic_inc_unchecked(&qps_created);
33186 switch (init_attr->qp_type) {
33187 case IB_QPT_RC:
33188 if (nes_drv_opt & NES_DRV_OPT_NO_INLINE_DATA) {
33189@@ -1460,7 +1460,7 @@ static int nes_destroy_qp(struct ib_qp *ibqp)
33190 struct iw_cm_event cm_event;
33191 int ret = 0;
33192
33193- atomic_inc(&sw_qps_destroyed);
33194+ atomic_inc_unchecked(&sw_qps_destroyed);
33195 nesqp->destroyed = 1;
33196
33197 /* Blow away the connection if it exists. */
33198diff --git a/drivers/infiniband/hw/qib/qib.h b/drivers/infiniband/hw/qib/qib.h
33199index 7b1b8669..4b69f85 100644
33200--- a/drivers/infiniband/hw/qib/qib.h
33201+++ b/drivers/infiniband/hw/qib/qib.h
33202@@ -51,6 +51,7 @@
33203 #include <linux/completion.h>
33204 #include <linux/kref.h>
33205 #include <linux/sched.h>
33206+#include <linux/slab.h>
33207
33208 #include "qib_common.h"
33209 #include "qib_verbs.h"
33210diff --git a/drivers/input/gameport/gameport.c b/drivers/input/gameport/gameport.c
33211index da739d9..da1c7f4 100644
33212--- a/drivers/input/gameport/gameport.c
33213+++ b/drivers/input/gameport/gameport.c
33214@@ -487,14 +487,14 @@ EXPORT_SYMBOL(gameport_set_phys);
33215 */
33216 static void gameport_init_port(struct gameport *gameport)
33217 {
33218- static atomic_t gameport_no = ATOMIC_INIT(0);
33219+ static atomic_unchecked_t gameport_no = ATOMIC_INIT(0);
33220
33221 __module_get(THIS_MODULE);
33222
33223 mutex_init(&gameport->drv_mutex);
33224 device_initialize(&gameport->dev);
33225 dev_set_name(&gameport->dev, "gameport%lu",
33226- (unsigned long)atomic_inc_return(&gameport_no) - 1);
33227+ (unsigned long)atomic_inc_return_unchecked(&gameport_no) - 1);
33228 gameport->dev.bus = &gameport_bus;
33229 gameport->dev.release = gameport_release_port;
33230 if (gameport->parent)
33231diff --git a/drivers/input/input.c b/drivers/input/input.c
33232index 8921c61..f5cd63d 100644
33233--- a/drivers/input/input.c
33234+++ b/drivers/input/input.c
33235@@ -1814,7 +1814,7 @@ static void input_cleanse_bitmasks(struct input_dev *dev)
33236 */
33237 int input_register_device(struct input_dev *dev)
33238 {
33239- static atomic_t input_no = ATOMIC_INIT(0);
33240+ static atomic_unchecked_t input_no = ATOMIC_INIT(0);
33241 struct input_handler *handler;
33242 const char *path;
33243 int error;
33244@@ -1851,7 +1851,7 @@ int input_register_device(struct input_dev *dev)
33245 dev->setkeycode = input_default_setkeycode;
33246
33247 dev_set_name(&dev->dev, "input%ld",
33248- (unsigned long) atomic_inc_return(&input_no) - 1);
33249+ (unsigned long) atomic_inc_return_unchecked(&input_no) - 1);
33250
33251 error = device_add(&dev->dev);
33252 if (error)
33253diff --git a/drivers/input/joystick/sidewinder.c b/drivers/input/joystick/sidewinder.c
33254index 04c69af..5f92d00 100644
33255--- a/drivers/input/joystick/sidewinder.c
33256+++ b/drivers/input/joystick/sidewinder.c
33257@@ -30,6 +30,7 @@
33258 #include <linux/kernel.h>
33259 #include <linux/module.h>
33260 #include <linux/slab.h>
33261+#include <linux/sched.h>
33262 #include <linux/init.h>
33263 #include <linux/input.h>
33264 #include <linux/gameport.h>
33265diff --git a/drivers/input/joystick/xpad.c b/drivers/input/joystick/xpad.c
33266index 83811e4..0822b90 100644
33267--- a/drivers/input/joystick/xpad.c
33268+++ b/drivers/input/joystick/xpad.c
33269@@ -726,7 +726,7 @@ static void xpad_led_set(struct led_classdev *led_cdev,
33270
33271 static int xpad_led_probe(struct usb_xpad *xpad)
33272 {
33273- static atomic_t led_seq = ATOMIC_INIT(0);
33274+ static atomic_unchecked_t led_seq = ATOMIC_INIT(0);
33275 long led_no;
33276 struct xpad_led *led;
33277 struct led_classdev *led_cdev;
33278@@ -739,7 +739,7 @@ static int xpad_led_probe(struct usb_xpad *xpad)
33279 if (!led)
33280 return -ENOMEM;
33281
33282- led_no = (long)atomic_inc_return(&led_seq) - 1;
33283+ led_no = (long)atomic_inc_return_unchecked(&led_seq) - 1;
33284
33285 snprintf(led->name, sizeof(led->name), "xpad%ld", led_no);
33286 led->xpad = xpad;
33287diff --git a/drivers/input/mousedev.c b/drivers/input/mousedev.c
33288index 0110b5a..d3ad144 100644
33289--- a/drivers/input/mousedev.c
33290+++ b/drivers/input/mousedev.c
33291@@ -763,7 +763,7 @@ static ssize_t mousedev_read(struct file *file, char __user *buffer,
33292
33293 spin_unlock_irq(&client->packet_lock);
33294
33295- if (copy_to_user(buffer, data, count))
33296+ if (count > sizeof(data) || copy_to_user(buffer, data, count))
33297 return -EFAULT;
33298
33299 return count;
33300diff --git a/drivers/input/serio/serio.c b/drivers/input/serio/serio.c
33301index d0f7533..fb8215b 100644
33302--- a/drivers/input/serio/serio.c
33303+++ b/drivers/input/serio/serio.c
33304@@ -496,7 +496,7 @@ static void serio_release_port(struct device *dev)
33305 */
33306 static void serio_init_port(struct serio *serio)
33307 {
33308- static atomic_t serio_no = ATOMIC_INIT(0);
33309+ static atomic_unchecked_t serio_no = ATOMIC_INIT(0);
33310
33311 __module_get(THIS_MODULE);
33312
33313@@ -507,7 +507,7 @@ static void serio_init_port(struct serio *serio)
33314 mutex_init(&serio->drv_mutex);
33315 device_initialize(&serio->dev);
33316 dev_set_name(&serio->dev, "serio%ld",
33317- (long)atomic_inc_return(&serio_no) - 1);
33318+ (long)atomic_inc_return_unchecked(&serio_no) - 1);
33319 serio->dev.bus = &serio_bus;
33320 serio->dev.release = serio_release_port;
33321 serio->dev.groups = serio_device_attr_groups;
33322diff --git a/drivers/isdn/capi/capi.c b/drivers/isdn/capi/capi.c
33323index 38c4bd8..58965d9 100644
33324--- a/drivers/isdn/capi/capi.c
33325+++ b/drivers/isdn/capi/capi.c
33326@@ -83,8 +83,8 @@ struct capiminor {
33327
33328 struct capi20_appl *ap;
33329 u32 ncci;
33330- atomic_t datahandle;
33331- atomic_t msgid;
33332+ atomic_unchecked_t datahandle;
33333+ atomic_unchecked_t msgid;
33334
33335 struct tty_port port;
33336 int ttyinstop;
33337@@ -392,7 +392,7 @@ gen_data_b3_resp_for(struct capiminor *mp, struct sk_buff *skb)
33338 capimsg_setu16(s, 2, mp->ap->applid);
33339 capimsg_setu8 (s, 4, CAPI_DATA_B3);
33340 capimsg_setu8 (s, 5, CAPI_RESP);
33341- capimsg_setu16(s, 6, atomic_inc_return(&mp->msgid));
33342+ capimsg_setu16(s, 6, atomic_inc_return_unchecked(&mp->msgid));
33343 capimsg_setu32(s, 8, mp->ncci);
33344 capimsg_setu16(s, 12, datahandle);
33345 }
33346@@ -513,14 +513,14 @@ static void handle_minor_send(struct capiminor *mp)
33347 mp->outbytes -= len;
33348 spin_unlock_bh(&mp->outlock);
33349
33350- datahandle = atomic_inc_return(&mp->datahandle);
33351+ datahandle = atomic_inc_return_unchecked(&mp->datahandle);
33352 skb_push(skb, CAPI_DATA_B3_REQ_LEN);
33353 memset(skb->data, 0, CAPI_DATA_B3_REQ_LEN);
33354 capimsg_setu16(skb->data, 0, CAPI_DATA_B3_REQ_LEN);
33355 capimsg_setu16(skb->data, 2, mp->ap->applid);
33356 capimsg_setu8 (skb->data, 4, CAPI_DATA_B3);
33357 capimsg_setu8 (skb->data, 5, CAPI_REQ);
33358- capimsg_setu16(skb->data, 6, atomic_inc_return(&mp->msgid));
33359+ capimsg_setu16(skb->data, 6, atomic_inc_return_unchecked(&mp->msgid));
33360 capimsg_setu32(skb->data, 8, mp->ncci); /* NCCI */
33361 capimsg_setu32(skb->data, 12, (u32)(long)skb->data);/* Data32 */
33362 capimsg_setu16(skb->data, 16, len); /* Data length */
33363diff --git a/drivers/isdn/gigaset/interface.c b/drivers/isdn/gigaset/interface.c
33364index a6d9fd2..afdb8a3 100644
33365--- a/drivers/isdn/gigaset/interface.c
33366+++ b/drivers/isdn/gigaset/interface.c
33367@@ -160,9 +160,9 @@ static int if_open(struct tty_struct *tty, struct file *filp)
33368 }
33369 tty->driver_data = cs;
33370
33371- ++cs->port.count;
33372+ atomic_inc(&cs->port.count);
33373
33374- if (cs->port.count == 1) {
33375+ if (atomic_read(&cs->port.count) == 1) {
33376 tty_port_tty_set(&cs->port, tty);
33377 tty->low_latency = 1;
33378 }
33379@@ -186,9 +186,9 @@ static void if_close(struct tty_struct *tty, struct file *filp)
33380
33381 if (!cs->connected)
33382 gig_dbg(DEBUG_IF, "not connected"); /* nothing to do */
33383- else if (!cs->port.count)
33384+ else if (!atomic_read(&cs->port.count))
33385 dev_warn(cs->dev, "%s: device not opened\n", __func__);
33386- else if (!--cs->port.count)
33387+ else if (!atomic_dec_return(&cs->port.count))
33388 tty_port_tty_set(&cs->port, NULL);
33389
33390 mutex_unlock(&cs->mutex);
33391diff --git a/drivers/isdn/hardware/avm/b1.c b/drivers/isdn/hardware/avm/b1.c
33392index 821f7ac..28d4030 100644
33393--- a/drivers/isdn/hardware/avm/b1.c
33394+++ b/drivers/isdn/hardware/avm/b1.c
33395@@ -176,7 +176,7 @@ int b1_load_t4file(avmcard *card, capiloaddatapart *t4file)
33396 }
33397 if (left) {
33398 if (t4file->user) {
33399- if (copy_from_user(buf, dp, left))
33400+ if (left > sizeof buf || copy_from_user(buf, dp, left))
33401 return -EFAULT;
33402 } else {
33403 memcpy(buf, dp, left);
33404@@ -224,7 +224,7 @@ int b1_load_config(avmcard *card, capiloaddatapart *config)
33405 }
33406 if (left) {
33407 if (config->user) {
33408- if (copy_from_user(buf, dp, left))
33409+ if (left > sizeof buf || copy_from_user(buf, dp, left))
33410 return -EFAULT;
33411 } else {
33412 memcpy(buf, dp, left);
33413diff --git a/drivers/isdn/hardware/eicon/divasync.h b/drivers/isdn/hardware/eicon/divasync.h
33414index dd6b53a..19d9ee6 100644
33415--- a/drivers/isdn/hardware/eicon/divasync.h
33416+++ b/drivers/isdn/hardware/eicon/divasync.h
33417@@ -146,7 +146,7 @@ typedef struct _diva_didd_add_adapter {
33418 } diva_didd_add_adapter_t;
33419 typedef struct _diva_didd_remove_adapter {
33420 IDI_CALL p_request;
33421-} diva_didd_remove_adapter_t;
33422+} __no_const diva_didd_remove_adapter_t;
33423 typedef struct _diva_didd_read_adapter_array {
33424 void *buffer;
33425 dword length;
33426diff --git a/drivers/isdn/hardware/eicon/xdi_adapter.h b/drivers/isdn/hardware/eicon/xdi_adapter.h
33427index d303e65..28bcb7b 100644
33428--- a/drivers/isdn/hardware/eicon/xdi_adapter.h
33429+++ b/drivers/isdn/hardware/eicon/xdi_adapter.h
33430@@ -44,7 +44,7 @@ typedef struct _xdi_mbox_t {
33431 typedef struct _diva_os_idi_adapter_interface {
33432 diva_init_card_proc_t cleanup_adapter_proc;
33433 diva_cmd_card_proc_t cmd_proc;
33434-} diva_os_idi_adapter_interface_t;
33435+} __no_const diva_os_idi_adapter_interface_t;
33436
33437 typedef struct _diva_os_xdi_adapter {
33438 struct list_head link;
33439diff --git a/drivers/isdn/i4l/isdn_tty.c b/drivers/isdn/i4l/isdn_tty.c
33440index 7bc5067..fd36232 100644
33441--- a/drivers/isdn/i4l/isdn_tty.c
33442+++ b/drivers/isdn/i4l/isdn_tty.c
33443@@ -1505,9 +1505,9 @@ isdn_tty_open(struct tty_struct *tty, struct file *filp)
33444 port = &info->port;
33445 #ifdef ISDN_DEBUG_MODEM_OPEN
33446 printk(KERN_DEBUG "isdn_tty_open %s, count = %d\n", tty->name,
33447- port->count);
33448+ atomic_read(&port->count))
33449 #endif
33450- port->count++;
33451+ atomic_inc(&port->count);
33452 tty->driver_data = info;
33453 port->tty = tty;
33454 tty->port = port;
33455@@ -1553,7 +1553,7 @@ isdn_tty_close(struct tty_struct *tty, struct file *filp)
33456 #endif
33457 return;
33458 }
33459- if ((tty->count == 1) && (port->count != 1)) {
33460+ if ((tty->count == 1) && (atomic_read(&port->count) != 1)) {
33461 /*
33462 * Uh, oh. tty->count is 1, which means that the tty
33463 * structure will be freed. Info->count should always
33464@@ -1562,15 +1562,15 @@ isdn_tty_close(struct tty_struct *tty, struct file *filp)
33465 * serial port won't be shutdown.
33466 */
33467 printk(KERN_ERR "isdn_tty_close: bad port count; tty->count is 1, "
33468- "info->count is %d\n", port->count);
33469- port->count = 1;
33470+ "info->count is %d\n", atomic_read(&port->count));
33471+ atomic_set(&port->count, 1);
33472 }
33473- if (--port->count < 0) {
33474+ if (atomic_dec_return(&port->count) < 0) {
33475 printk(KERN_ERR "isdn_tty_close: bad port count for ttyi%d: %d\n",
33476- info->line, port->count);
33477- port->count = 0;
33478+ info->line, atomic_read(&port->count));
33479+ atomic_set(&port->count, 0);
33480 }
33481- if (port->count) {
33482+ if (atomic_read(&port->count)) {
33483 #ifdef ISDN_DEBUG_MODEM_OPEN
33484 printk(KERN_DEBUG "isdn_tty_close after info->count != 0\n");
33485 #endif
33486@@ -1624,7 +1624,7 @@ isdn_tty_hangup(struct tty_struct *tty)
33487 if (isdn_tty_paranoia_check(info, tty->name, "isdn_tty_hangup"))
33488 return;
33489 isdn_tty_shutdown(info);
33490- port->count = 0;
33491+ atomic_set(&port->count, 0);
33492 port->flags &= ~ASYNC_NORMAL_ACTIVE;
33493 port->tty = NULL;
33494 wake_up_interruptible(&port->open_wait);
33495@@ -1964,7 +1964,7 @@ isdn_tty_find_icall(int di, int ch, setup_parm *setup)
33496 for (i = 0; i < ISDN_MAX_CHANNELS; i++) {
33497 modem_info *info = &dev->mdm.info[i];
33498
33499- if (info->port.count == 0)
33500+ if (atomic_read(&info->port.count) == 0)
33501 continue;
33502 if ((info->emu.mdmreg[REG_SI1] & si2bit[si1]) && /* SI1 is matching */
33503 (info->emu.mdmreg[REG_SI2] == si2)) { /* SI2 is matching */
33504diff --git a/drivers/isdn/icn/icn.c b/drivers/isdn/icn/icn.c
33505index e74df7c..03a03ba 100644
33506--- a/drivers/isdn/icn/icn.c
33507+++ b/drivers/isdn/icn/icn.c
33508@@ -1045,7 +1045,7 @@ icn_writecmd(const u_char *buf, int len, int user, icn_card *card)
33509 if (count > len)
33510 count = len;
33511 if (user) {
33512- if (copy_from_user(msg, buf, count))
33513+ if (count > sizeof msg || copy_from_user(msg, buf, count))
33514 return -EFAULT;
33515 } else
33516 memcpy(msg, buf, count);
33517diff --git a/drivers/lguest/core.c b/drivers/lguest/core.c
33518index b5fdcb7..5b6c59f 100644
33519--- a/drivers/lguest/core.c
33520+++ b/drivers/lguest/core.c
33521@@ -92,9 +92,17 @@ static __init int map_switcher(void)
33522 * it's worked so far. The end address needs +1 because __get_vm_area
33523 * allocates an extra guard page, so we need space for that.
33524 */
33525+
33526+#if defined(CONFIG_MODULES) && defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
33527+ switcher_vma = __get_vm_area(TOTAL_SWITCHER_PAGES * PAGE_SIZE,
33528+ VM_ALLOC | VM_KERNEXEC, SWITCHER_ADDR, SWITCHER_ADDR
33529+ + (TOTAL_SWITCHER_PAGES+1) * PAGE_SIZE);
33530+#else
33531 switcher_vma = __get_vm_area(TOTAL_SWITCHER_PAGES * PAGE_SIZE,
33532 VM_ALLOC, SWITCHER_ADDR, SWITCHER_ADDR
33533 + (TOTAL_SWITCHER_PAGES+1) * PAGE_SIZE);
33534+#endif
33535+
33536 if (!switcher_vma) {
33537 err = -ENOMEM;
33538 printk("lguest: could not map switcher pages high\n");
33539@@ -119,7 +127,7 @@ static __init int map_switcher(void)
33540 * Now the Switcher is mapped at the right address, we can't fail!
33541 * Copy in the compiled-in Switcher code (from x86/switcher_32.S).
33542 */
33543- memcpy(switcher_vma->addr, start_switcher_text,
33544+ memcpy(switcher_vma->addr, ktla_ktva(start_switcher_text),
33545 end_switcher_text - start_switcher_text);
33546
33547 printk(KERN_INFO "lguest: mapped switcher at %p\n",
33548diff --git a/drivers/lguest/x86/core.c b/drivers/lguest/x86/core.c
33549index 39809035..ce25c5e 100644
33550--- a/drivers/lguest/x86/core.c
33551+++ b/drivers/lguest/x86/core.c
33552@@ -59,7 +59,7 @@ static struct {
33553 /* Offset from where switcher.S was compiled to where we've copied it */
33554 static unsigned long switcher_offset(void)
33555 {
33556- return SWITCHER_ADDR - (unsigned long)start_switcher_text;
33557+ return SWITCHER_ADDR - (unsigned long)ktla_ktva(start_switcher_text);
33558 }
33559
33560 /* This cpu's struct lguest_pages. */
33561@@ -100,7 +100,13 @@ static void copy_in_guest_info(struct lg_cpu *cpu, struct lguest_pages *pages)
33562 * These copies are pretty cheap, so we do them unconditionally: */
33563 /* Save the current Host top-level page directory.
33564 */
33565+
33566+#ifdef CONFIG_PAX_PER_CPU_PGD
33567+ pages->state.host_cr3 = read_cr3();
33568+#else
33569 pages->state.host_cr3 = __pa(current->mm->pgd);
33570+#endif
33571+
33572 /*
33573 * Set up the Guest's page tables to see this CPU's pages (and no
33574 * other CPU's pages).
33575@@ -472,7 +478,7 @@ void __init lguest_arch_host_init(void)
33576 * compiled-in switcher code and the high-mapped copy we just made.
33577 */
33578 for (i = 0; i < IDT_ENTRIES; i++)
33579- default_idt_entries[i] += switcher_offset();
33580+ default_idt_entries[i] = ktla_ktva(default_idt_entries[i]) + switcher_offset();
33581
33582 /*
33583 * Set up the Switcher's per-cpu areas.
33584@@ -555,7 +561,7 @@ void __init lguest_arch_host_init(void)
33585 * it will be undisturbed when we switch. To change %cs and jump we
33586 * need this structure to feed to Intel's "lcall" instruction.
33587 */
33588- lguest_entry.offset = (long)switch_to_guest + switcher_offset();
33589+ lguest_entry.offset = (long)ktla_ktva(switch_to_guest) + switcher_offset();
33590 lguest_entry.segment = LGUEST_CS;
33591
33592 /*
33593diff --git a/drivers/lguest/x86/switcher_32.S b/drivers/lguest/x86/switcher_32.S
33594index 40634b0..4f5855e 100644
33595--- a/drivers/lguest/x86/switcher_32.S
33596+++ b/drivers/lguest/x86/switcher_32.S
33597@@ -87,6 +87,7 @@
33598 #include <asm/page.h>
33599 #include <asm/segment.h>
33600 #include <asm/lguest.h>
33601+#include <asm/processor-flags.h>
33602
33603 // We mark the start of the code to copy
33604 // It's placed in .text tho it's never run here
33605@@ -149,6 +150,13 @@ ENTRY(switch_to_guest)
33606 // Changes type when we load it: damn Intel!
33607 // For after we switch over our page tables
33608 // That entry will be read-only: we'd crash.
33609+
33610+#ifdef CONFIG_PAX_KERNEXEC
33611+ mov %cr0, %edx
33612+ xor $X86_CR0_WP, %edx
33613+ mov %edx, %cr0
33614+#endif
33615+
33616 movl $(GDT_ENTRY_TSS*8), %edx
33617 ltr %dx
33618
33619@@ -157,9 +165,15 @@ ENTRY(switch_to_guest)
33620 // Let's clear it again for our return.
33621 // The GDT descriptor of the Host
33622 // Points to the table after two "size" bytes
33623- movl (LGUEST_PAGES_host_gdt_desc+2)(%eax), %edx
33624+ movl (LGUEST_PAGES_host_gdt_desc+2)(%eax), %eax
33625 // Clear "used" from type field (byte 5, bit 2)
33626- andb $0xFD, (GDT_ENTRY_TSS*8 + 5)(%edx)
33627+ andb $0xFD, (GDT_ENTRY_TSS*8 + 5)(%eax)
33628+
33629+#ifdef CONFIG_PAX_KERNEXEC
33630+ mov %cr0, %eax
33631+ xor $X86_CR0_WP, %eax
33632+ mov %eax, %cr0
33633+#endif
33634
33635 // Once our page table's switched, the Guest is live!
33636 // The Host fades as we run this final step.
33637@@ -295,13 +309,12 @@ deliver_to_host:
33638 // I consulted gcc, and it gave
33639 // These instructions, which I gladly credit:
33640 leal (%edx,%ebx,8), %eax
33641- movzwl (%eax),%edx
33642- movl 4(%eax), %eax
33643- xorw %ax, %ax
33644- orl %eax, %edx
33645+ movl 4(%eax), %edx
33646+ movw (%eax), %dx
33647 // Now the address of the handler's in %edx
33648 // We call it now: its "iret" drops us home.
33649- jmp *%edx
33650+ ljmp $__KERNEL_CS, $1f
33651+1: jmp *%edx
33652
33653 // Every interrupt can come to us here
33654 // But we must truly tell each apart.
33655diff --git a/drivers/macintosh/macio_asic.c b/drivers/macintosh/macio_asic.c
33656index 20e5c2c..9e849a9 100644
33657--- a/drivers/macintosh/macio_asic.c
33658+++ b/drivers/macintosh/macio_asic.c
33659@@ -748,7 +748,7 @@ static void __devexit macio_pci_remove(struct pci_dev* pdev)
33660 * MacIO is matched against any Apple ID, it's probe() function
33661 * will then decide wether it applies or not
33662 */
33663-static const struct pci_device_id __devinitdata pci_ids [] = { {
33664+static const struct pci_device_id __devinitconst pci_ids [] = { {
33665 .vendor = PCI_VENDOR_ID_APPLE,
33666 .device = PCI_ANY_ID,
33667 .subvendor = PCI_ANY_ID,
33668diff --git a/drivers/md/bitmap.c b/drivers/md/bitmap.c
33669index 94e7f6b..2f4a0d8 100644
33670--- a/drivers/md/bitmap.c
33671+++ b/drivers/md/bitmap.c
33672@@ -1786,7 +1786,7 @@ void bitmap_status(struct seq_file *seq, struct bitmap *bitmap)
33673 chunk_kb ? "KB" : "B");
33674 if (bitmap->storage.file) {
33675 seq_printf(seq, ", file: ");
33676- seq_path(seq, &bitmap->storage.file->f_path, " \t\n");
33677+ seq_path(seq, &bitmap->storage.file->f_path, " \t\n\\");
33678 }
33679
33680 seq_printf(seq, "\n");
33681diff --git a/drivers/md/dm-ioctl.c b/drivers/md/dm-ioctl.c
33682index afd9598..528d8f9 100644
33683--- a/drivers/md/dm-ioctl.c
33684+++ b/drivers/md/dm-ioctl.c
33685@@ -1593,7 +1593,7 @@ static int validate_params(uint cmd, struct dm_ioctl *param)
33686 cmd == DM_LIST_VERSIONS_CMD)
33687 return 0;
33688
33689- if ((cmd == DM_DEV_CREATE_CMD)) {
33690+ if (cmd == DM_DEV_CREATE_CMD) {
33691 if (!*param->name) {
33692 DMWARN("name not supplied when creating device");
33693 return -EINVAL;
33694diff --git a/drivers/md/dm-raid1.c b/drivers/md/dm-raid1.c
33695index bc5ddba8..b961159 100644
33696--- a/drivers/md/dm-raid1.c
33697+++ b/drivers/md/dm-raid1.c
33698@@ -40,7 +40,7 @@ enum dm_raid1_error {
33699
33700 struct mirror {
33701 struct mirror_set *ms;
33702- atomic_t error_count;
33703+ atomic_unchecked_t error_count;
33704 unsigned long error_type;
33705 struct dm_dev *dev;
33706 sector_t offset;
33707@@ -185,7 +185,7 @@ static struct mirror *get_valid_mirror(struct mirror_set *ms)
33708 struct mirror *m;
33709
33710 for (m = ms->mirror; m < ms->mirror + ms->nr_mirrors; m++)
33711- if (!atomic_read(&m->error_count))
33712+ if (!atomic_read_unchecked(&m->error_count))
33713 return m;
33714
33715 return NULL;
33716@@ -217,7 +217,7 @@ static void fail_mirror(struct mirror *m, enum dm_raid1_error error_type)
33717 * simple way to tell if a device has encountered
33718 * errors.
33719 */
33720- atomic_inc(&m->error_count);
33721+ atomic_inc_unchecked(&m->error_count);
33722
33723 if (test_and_set_bit(error_type, &m->error_type))
33724 return;
33725@@ -408,7 +408,7 @@ static struct mirror *choose_mirror(struct mirror_set *ms, sector_t sector)
33726 struct mirror *m = get_default_mirror(ms);
33727
33728 do {
33729- if (likely(!atomic_read(&m->error_count)))
33730+ if (likely(!atomic_read_unchecked(&m->error_count)))
33731 return m;
33732
33733 if (m-- == ms->mirror)
33734@@ -422,7 +422,7 @@ static int default_ok(struct mirror *m)
33735 {
33736 struct mirror *default_mirror = get_default_mirror(m->ms);
33737
33738- return !atomic_read(&default_mirror->error_count);
33739+ return !atomic_read_unchecked(&default_mirror->error_count);
33740 }
33741
33742 static int mirror_available(struct mirror_set *ms, struct bio *bio)
33743@@ -559,7 +559,7 @@ static void do_reads(struct mirror_set *ms, struct bio_list *reads)
33744 */
33745 if (likely(region_in_sync(ms, region, 1)))
33746 m = choose_mirror(ms, bio->bi_sector);
33747- else if (m && atomic_read(&m->error_count))
33748+ else if (m && atomic_read_unchecked(&m->error_count))
33749 m = NULL;
33750
33751 if (likely(m))
33752@@ -938,7 +938,7 @@ static int get_mirror(struct mirror_set *ms, struct dm_target *ti,
33753 }
33754
33755 ms->mirror[mirror].ms = ms;
33756- atomic_set(&(ms->mirror[mirror].error_count), 0);
33757+ atomic_set_unchecked(&(ms->mirror[mirror].error_count), 0);
33758 ms->mirror[mirror].error_type = 0;
33759 ms->mirror[mirror].offset = offset;
33760
33761@@ -1356,7 +1356,7 @@ static void mirror_resume(struct dm_target *ti)
33762 */
33763 static char device_status_char(struct mirror *m)
33764 {
33765- if (!atomic_read(&(m->error_count)))
33766+ if (!atomic_read_unchecked(&(m->error_count)))
33767 return 'A';
33768
33769 return (test_bit(DM_RAID1_FLUSH_ERROR, &(m->error_type))) ? 'F' :
33770diff --git a/drivers/md/dm-stripe.c b/drivers/md/dm-stripe.c
33771index a087bf2..4c94786 100644
33772--- a/drivers/md/dm-stripe.c
33773+++ b/drivers/md/dm-stripe.c
33774@@ -20,7 +20,7 @@ struct stripe {
33775 struct dm_dev *dev;
33776 sector_t physical_start;
33777
33778- atomic_t error_count;
33779+ atomic_unchecked_t error_count;
33780 };
33781
33782 struct stripe_c {
33783@@ -183,7 +183,7 @@ static int stripe_ctr(struct dm_target *ti, unsigned int argc, char **argv)
33784 kfree(sc);
33785 return r;
33786 }
33787- atomic_set(&(sc->stripe[i].error_count), 0);
33788+ atomic_set_unchecked(&(sc->stripe[i].error_count), 0);
33789 }
33790
33791 ti->private = sc;
33792@@ -324,7 +324,7 @@ static int stripe_status(struct dm_target *ti, status_type_t type,
33793 DMEMIT("%d ", sc->stripes);
33794 for (i = 0; i < sc->stripes; i++) {
33795 DMEMIT("%s ", sc->stripe[i].dev->name);
33796- buffer[i] = atomic_read(&(sc->stripe[i].error_count)) ?
33797+ buffer[i] = atomic_read_unchecked(&(sc->stripe[i].error_count)) ?
33798 'D' : 'A';
33799 }
33800 buffer[i] = '\0';
33801@@ -371,8 +371,8 @@ static int stripe_end_io(struct dm_target *ti, struct bio *bio,
33802 */
33803 for (i = 0; i < sc->stripes; i++)
33804 if (!strcmp(sc->stripe[i].dev->name, major_minor)) {
33805- atomic_inc(&(sc->stripe[i].error_count));
33806- if (atomic_read(&(sc->stripe[i].error_count)) <
33807+ atomic_inc_unchecked(&(sc->stripe[i].error_count));
33808+ if (atomic_read_unchecked(&(sc->stripe[i].error_count)) <
33809 DM_IO_ERROR_THRESHOLD)
33810 schedule_work(&sc->trigger_event);
33811 }
33812diff --git a/drivers/md/dm-table.c b/drivers/md/dm-table.c
33813index 100368e..64262ce 100644
33814--- a/drivers/md/dm-table.c
33815+++ b/drivers/md/dm-table.c
33816@@ -390,7 +390,7 @@ static int device_area_is_invalid(struct dm_target *ti, struct dm_dev *dev,
33817 if (!dev_size)
33818 return 0;
33819
33820- if ((start >= dev_size) || (start + len > dev_size)) {
33821+ if ((start >= dev_size) || (len > dev_size - start)) {
33822 DMWARN("%s: %s too small for target: "
33823 "start=%llu, len=%llu, dev_size=%llu",
33824 dm_device_name(ti->table->md), bdevname(bdev, b),
33825diff --git a/drivers/md/dm-thin-metadata.c b/drivers/md/dm-thin-metadata.c
33826index 693e149..b7e0fde 100644
33827--- a/drivers/md/dm-thin-metadata.c
33828+++ b/drivers/md/dm-thin-metadata.c
33829@@ -397,7 +397,7 @@ static void __setup_btree_details(struct dm_pool_metadata *pmd)
33830 {
33831 pmd->info.tm = pmd->tm;
33832 pmd->info.levels = 2;
33833- pmd->info.value_type.context = pmd->data_sm;
33834+ pmd->info.value_type.context = (dm_space_map_no_const *)pmd->data_sm;
33835 pmd->info.value_type.size = sizeof(__le64);
33836 pmd->info.value_type.inc = data_block_inc;
33837 pmd->info.value_type.dec = data_block_dec;
33838@@ -416,7 +416,7 @@ static void __setup_btree_details(struct dm_pool_metadata *pmd)
33839
33840 pmd->bl_info.tm = pmd->tm;
33841 pmd->bl_info.levels = 1;
33842- pmd->bl_info.value_type.context = pmd->data_sm;
33843+ pmd->bl_info.value_type.context = (dm_space_map_no_const *)pmd->data_sm;
33844 pmd->bl_info.value_type.size = sizeof(__le64);
33845 pmd->bl_info.value_type.inc = data_block_inc;
33846 pmd->bl_info.value_type.dec = data_block_dec;
33847diff --git a/drivers/md/dm.c b/drivers/md/dm.c
33848index 67ffa39..cb3b1dd 100644
33849--- a/drivers/md/dm.c
33850+++ b/drivers/md/dm.c
33851@@ -176,9 +176,9 @@ struct mapped_device {
33852 /*
33853 * Event handling.
33854 */
33855- atomic_t event_nr;
33856+ atomic_unchecked_t event_nr;
33857 wait_queue_head_t eventq;
33858- atomic_t uevent_seq;
33859+ atomic_unchecked_t uevent_seq;
33860 struct list_head uevent_list;
33861 spinlock_t uevent_lock; /* Protect access to uevent_list */
33862
33863@@ -1887,8 +1887,8 @@ static struct mapped_device *alloc_dev(int minor)
33864 rwlock_init(&md->map_lock);
33865 atomic_set(&md->holders, 1);
33866 atomic_set(&md->open_count, 0);
33867- atomic_set(&md->event_nr, 0);
33868- atomic_set(&md->uevent_seq, 0);
33869+ atomic_set_unchecked(&md->event_nr, 0);
33870+ atomic_set_unchecked(&md->uevent_seq, 0);
33871 INIT_LIST_HEAD(&md->uevent_list);
33872 spin_lock_init(&md->uevent_lock);
33873
33874@@ -2022,7 +2022,7 @@ static void event_callback(void *context)
33875
33876 dm_send_uevents(&uevents, &disk_to_dev(md->disk)->kobj);
33877
33878- atomic_inc(&md->event_nr);
33879+ atomic_inc_unchecked(&md->event_nr);
33880 wake_up(&md->eventq);
33881 }
33882
33883@@ -2677,18 +2677,18 @@ int dm_kobject_uevent(struct mapped_device *md, enum kobject_action action,
33884
33885 uint32_t dm_next_uevent_seq(struct mapped_device *md)
33886 {
33887- return atomic_add_return(1, &md->uevent_seq);
33888+ return atomic_add_return_unchecked(1, &md->uevent_seq);
33889 }
33890
33891 uint32_t dm_get_event_nr(struct mapped_device *md)
33892 {
33893- return atomic_read(&md->event_nr);
33894+ return atomic_read_unchecked(&md->event_nr);
33895 }
33896
33897 int dm_wait_event(struct mapped_device *md, int event_nr)
33898 {
33899 return wait_event_interruptible(md->eventq,
33900- (event_nr != atomic_read(&md->event_nr)));
33901+ (event_nr != atomic_read_unchecked(&md->event_nr)));
33902 }
33903
33904 void dm_uevent_add(struct mapped_device *md, struct list_head *elist)
33905diff --git a/drivers/md/md.c b/drivers/md/md.c
33906index 308e87b..7f365d6 100644
33907--- a/drivers/md/md.c
33908+++ b/drivers/md/md.c
33909@@ -277,10 +277,10 @@ EXPORT_SYMBOL_GPL(md_trim_bio);
33910 * start build, activate spare
33911 */
33912 static DECLARE_WAIT_QUEUE_HEAD(md_event_waiters);
33913-static atomic_t md_event_count;
33914+static atomic_unchecked_t md_event_count;
33915 void md_new_event(struct mddev *mddev)
33916 {
33917- atomic_inc(&md_event_count);
33918+ atomic_inc_unchecked(&md_event_count);
33919 wake_up(&md_event_waiters);
33920 }
33921 EXPORT_SYMBOL_GPL(md_new_event);
33922@@ -290,7 +290,7 @@ EXPORT_SYMBOL_GPL(md_new_event);
33923 */
33924 static void md_new_event_inintr(struct mddev *mddev)
33925 {
33926- atomic_inc(&md_event_count);
33927+ atomic_inc_unchecked(&md_event_count);
33928 wake_up(&md_event_waiters);
33929 }
33930
33931@@ -1519,7 +1519,7 @@ static int super_1_load(struct md_rdev *rdev, struct md_rdev *refdev, int minor_
33932 if ((le32_to_cpu(sb->feature_map) & MD_FEATURE_RESHAPE_ACTIVE) &&
33933 (le32_to_cpu(sb->feature_map) & MD_FEATURE_NEW_OFFSET))
33934 rdev->new_data_offset += (s32)le32_to_cpu(sb->new_offset);
33935- atomic_set(&rdev->corrected_errors, le32_to_cpu(sb->cnt_corrected_read));
33936+ atomic_set_unchecked(&rdev->corrected_errors, le32_to_cpu(sb->cnt_corrected_read));
33937
33938 rdev->sb_size = le32_to_cpu(sb->max_dev) * 2 + 256;
33939 bmask = queue_logical_block_size(rdev->bdev->bd_disk->queue)-1;
33940@@ -1763,7 +1763,7 @@ static void super_1_sync(struct mddev *mddev, struct md_rdev *rdev)
33941 else
33942 sb->resync_offset = cpu_to_le64(0);
33943
33944- sb->cnt_corrected_read = cpu_to_le32(atomic_read(&rdev->corrected_errors));
33945+ sb->cnt_corrected_read = cpu_to_le32(atomic_read_unchecked(&rdev->corrected_errors));
33946
33947 sb->raid_disks = cpu_to_le32(mddev->raid_disks);
33948 sb->size = cpu_to_le64(mddev->dev_sectors);
33949@@ -2757,7 +2757,7 @@ __ATTR(state, S_IRUGO|S_IWUSR, state_show, state_store);
33950 static ssize_t
33951 errors_show(struct md_rdev *rdev, char *page)
33952 {
33953- return sprintf(page, "%d\n", atomic_read(&rdev->corrected_errors));
33954+ return sprintf(page, "%d\n", atomic_read_unchecked(&rdev->corrected_errors));
33955 }
33956
33957 static ssize_t
33958@@ -2766,7 +2766,7 @@ errors_store(struct md_rdev *rdev, const char *buf, size_t len)
33959 char *e;
33960 unsigned long n = simple_strtoul(buf, &e, 10);
33961 if (*buf && (*e == 0 || *e == '\n')) {
33962- atomic_set(&rdev->corrected_errors, n);
33963+ atomic_set_unchecked(&rdev->corrected_errors, n);
33964 return len;
33965 }
33966 return -EINVAL;
33967@@ -3213,8 +3213,8 @@ int md_rdev_init(struct md_rdev *rdev)
33968 rdev->sb_loaded = 0;
33969 rdev->bb_page = NULL;
33970 atomic_set(&rdev->nr_pending, 0);
33971- atomic_set(&rdev->read_errors, 0);
33972- atomic_set(&rdev->corrected_errors, 0);
33973+ atomic_set_unchecked(&rdev->read_errors, 0);
33974+ atomic_set_unchecked(&rdev->corrected_errors, 0);
33975
33976 INIT_LIST_HEAD(&rdev->same_set);
33977 init_waitqueue_head(&rdev->blocked_wait);
33978@@ -6947,7 +6947,7 @@ static int md_seq_show(struct seq_file *seq, void *v)
33979
33980 spin_unlock(&pers_lock);
33981 seq_printf(seq, "\n");
33982- seq->poll_event = atomic_read(&md_event_count);
33983+ seq->poll_event = atomic_read_unchecked(&md_event_count);
33984 return 0;
33985 }
33986 if (v == (void*)2) {
33987@@ -7050,7 +7050,7 @@ static int md_seq_open(struct inode *inode, struct file *file)
33988 return error;
33989
33990 seq = file->private_data;
33991- seq->poll_event = atomic_read(&md_event_count);
33992+ seq->poll_event = atomic_read_unchecked(&md_event_count);
33993 return error;
33994 }
33995
33996@@ -7064,7 +7064,7 @@ static unsigned int mdstat_poll(struct file *filp, poll_table *wait)
33997 /* always allow read */
33998 mask = POLLIN | POLLRDNORM;
33999
34000- if (seq->poll_event != atomic_read(&md_event_count))
34001+ if (seq->poll_event != atomic_read_unchecked(&md_event_count))
34002 mask |= POLLERR | POLLPRI;
34003 return mask;
34004 }
34005@@ -7108,7 +7108,7 @@ static int is_mddev_idle(struct mddev *mddev, int init)
34006 struct gendisk *disk = rdev->bdev->bd_contains->bd_disk;
34007 curr_events = (int)part_stat_read(&disk->part0, sectors[0]) +
34008 (int)part_stat_read(&disk->part0, sectors[1]) -
34009- atomic_read(&disk->sync_io);
34010+ atomic_read_unchecked(&disk->sync_io);
34011 /* sync IO will cause sync_io to increase before the disk_stats
34012 * as sync_io is counted when a request starts, and
34013 * disk_stats is counted when it completes.
34014diff --git a/drivers/md/md.h b/drivers/md/md.h
34015index f385b03..b600be8 100644
34016--- a/drivers/md/md.h
34017+++ b/drivers/md/md.h
34018@@ -94,13 +94,13 @@ struct md_rdev {
34019 * only maintained for arrays that
34020 * support hot removal
34021 */
34022- atomic_t read_errors; /* number of consecutive read errors that
34023+ atomic_unchecked_t read_errors; /* number of consecutive read errors that
34024 * we have tried to ignore.
34025 */
34026 struct timespec last_read_error; /* monotonic time since our
34027 * last read error
34028 */
34029- atomic_t corrected_errors; /* number of corrected read errors,
34030+ atomic_unchecked_t corrected_errors; /* number of corrected read errors,
34031 * for reporting to userspace and storing
34032 * in superblock.
34033 */
34034@@ -432,7 +432,7 @@ static inline void rdev_dec_pending(struct md_rdev *rdev, struct mddev *mddev)
34035
34036 static inline void md_sync_acct(struct block_device *bdev, unsigned long nr_sectors)
34037 {
34038- atomic_add(nr_sectors, &bdev->bd_contains->bd_disk->sync_io);
34039+ atomic_add_unchecked(nr_sectors, &bdev->bd_contains->bd_disk->sync_io);
34040 }
34041
34042 struct md_personality
34043diff --git a/drivers/md/persistent-data/dm-space-map-disk.c b/drivers/md/persistent-data/dm-space-map-disk.c
34044index f6d29e6..7917f5e 100644
34045--- a/drivers/md/persistent-data/dm-space-map-disk.c
34046+++ b/drivers/md/persistent-data/dm-space-map-disk.c
34047@@ -22,7 +22,7 @@
34048 * Space map interface.
34049 */
34050 struct sm_disk {
34051- struct dm_space_map sm;
34052+ dm_space_map_no_const sm;
34053
34054 struct ll_disk ll;
34055 struct ll_disk old_ll;
34056diff --git a/drivers/md/persistent-data/dm-space-map-metadata.c b/drivers/md/persistent-data/dm-space-map-metadata.c
34057index e89ae5e..062e4c2 100644
34058--- a/drivers/md/persistent-data/dm-space-map-metadata.c
34059+++ b/drivers/md/persistent-data/dm-space-map-metadata.c
34060@@ -43,7 +43,7 @@ struct block_op {
34061 };
34062
34063 struct sm_metadata {
34064- struct dm_space_map sm;
34065+ dm_space_map_no_const sm;
34066
34067 struct ll_disk ll;
34068 struct ll_disk old_ll;
34069diff --git a/drivers/md/persistent-data/dm-space-map.h b/drivers/md/persistent-data/dm-space-map.h
34070index 1cbfc6b..56e1dbb 100644
34071--- a/drivers/md/persistent-data/dm-space-map.h
34072+++ b/drivers/md/persistent-data/dm-space-map.h
34073@@ -60,6 +60,7 @@ struct dm_space_map {
34074 int (*root_size)(struct dm_space_map *sm, size_t *result);
34075 int (*copy_root)(struct dm_space_map *sm, void *copy_to_here_le, size_t len);
34076 };
34077+typedef struct dm_space_map __no_const dm_space_map_no_const;
34078
34079 /*----------------------------------------------------------------*/
34080
34081diff --git a/drivers/md/raid1.c b/drivers/md/raid1.c
34082index 05bb49e..84d7ce6 100644
34083--- a/drivers/md/raid1.c
34084+++ b/drivers/md/raid1.c
34085@@ -1810,7 +1810,7 @@ static int fix_sync_read_error(struct r1bio *r1_bio)
34086 if (r1_sync_page_io(rdev, sect, s,
34087 bio->bi_io_vec[idx].bv_page,
34088 READ) != 0)
34089- atomic_add(s, &rdev->corrected_errors);
34090+ atomic_add_unchecked(s, &rdev->corrected_errors);
34091 }
34092 sectors -= s;
34093 sect += s;
34094@@ -2032,7 +2032,7 @@ static void fix_read_error(struct r1conf *conf, int read_disk,
34095 test_bit(In_sync, &rdev->flags)) {
34096 if (r1_sync_page_io(rdev, sect, s,
34097 conf->tmppage, READ)) {
34098- atomic_add(s, &rdev->corrected_errors);
34099+ atomic_add_unchecked(s, &rdev->corrected_errors);
34100 printk(KERN_INFO
34101 "md/raid1:%s: read error corrected "
34102 "(%d sectors at %llu on %s)\n",
34103diff --git a/drivers/md/raid10.c b/drivers/md/raid10.c
34104index a48c215..6bda6f4 100644
34105--- a/drivers/md/raid10.c
34106+++ b/drivers/md/raid10.c
34107@@ -1810,7 +1810,7 @@ static void end_sync_read(struct bio *bio, int error)
34108 /* The write handler will notice the lack of
34109 * R10BIO_Uptodate and record any errors etc
34110 */
34111- atomic_add(r10_bio->sectors,
34112+ atomic_add_unchecked(r10_bio->sectors,
34113 &conf->mirrors[d].rdev->corrected_errors);
34114
34115 /* for reconstruct, we always reschedule after a read.
34116@@ -2159,7 +2159,7 @@ static void check_decay_read_errors(struct mddev *mddev, struct md_rdev *rdev)
34117 {
34118 struct timespec cur_time_mon;
34119 unsigned long hours_since_last;
34120- unsigned int read_errors = atomic_read(&rdev->read_errors);
34121+ unsigned int read_errors = atomic_read_unchecked(&rdev->read_errors);
34122
34123 ktime_get_ts(&cur_time_mon);
34124
34125@@ -2181,9 +2181,9 @@ static void check_decay_read_errors(struct mddev *mddev, struct md_rdev *rdev)
34126 * overflowing the shift of read_errors by hours_since_last.
34127 */
34128 if (hours_since_last >= 8 * sizeof(read_errors))
34129- atomic_set(&rdev->read_errors, 0);
34130+ atomic_set_unchecked(&rdev->read_errors, 0);
34131 else
34132- atomic_set(&rdev->read_errors, read_errors >> hours_since_last);
34133+ atomic_set_unchecked(&rdev->read_errors, read_errors >> hours_since_last);
34134 }
34135
34136 static int r10_sync_page_io(struct md_rdev *rdev, sector_t sector,
34137@@ -2237,8 +2237,8 @@ static void fix_read_error(struct r10conf *conf, struct mddev *mddev, struct r10
34138 return;
34139
34140 check_decay_read_errors(mddev, rdev);
34141- atomic_inc(&rdev->read_errors);
34142- if (atomic_read(&rdev->read_errors) > max_read_errors) {
34143+ atomic_inc_unchecked(&rdev->read_errors);
34144+ if (atomic_read_unchecked(&rdev->read_errors) > max_read_errors) {
34145 char b[BDEVNAME_SIZE];
34146 bdevname(rdev->bdev, b);
34147
34148@@ -2246,7 +2246,7 @@ static void fix_read_error(struct r10conf *conf, struct mddev *mddev, struct r10
34149 "md/raid10:%s: %s: Raid device exceeded "
34150 "read_error threshold [cur %d:max %d]\n",
34151 mdname(mddev), b,
34152- atomic_read(&rdev->read_errors), max_read_errors);
34153+ atomic_read_unchecked(&rdev->read_errors), max_read_errors);
34154 printk(KERN_NOTICE
34155 "md/raid10:%s: %s: Failing raid device\n",
34156 mdname(mddev), b);
34157@@ -2401,7 +2401,7 @@ static void fix_read_error(struct r10conf *conf, struct mddev *mddev, struct r10
34158 sect +
34159 choose_data_offset(r10_bio, rdev)),
34160 bdevname(rdev->bdev, b));
34161- atomic_add(s, &rdev->corrected_errors);
34162+ atomic_add_unchecked(s, &rdev->corrected_errors);
34163 }
34164
34165 rdev_dec_pending(rdev, mddev);
34166diff --git a/drivers/md/raid5.c b/drivers/md/raid5.c
34167index 0689173..35df76c 100644
34168--- a/drivers/md/raid5.c
34169+++ b/drivers/md/raid5.c
34170@@ -1756,21 +1756,21 @@ static void raid5_end_read_request(struct bio * bi, int error)
34171 mdname(conf->mddev), STRIPE_SECTORS,
34172 (unsigned long long)s,
34173 bdevname(rdev->bdev, b));
34174- atomic_add(STRIPE_SECTORS, &rdev->corrected_errors);
34175+ atomic_add_unchecked(STRIPE_SECTORS, &rdev->corrected_errors);
34176 clear_bit(R5_ReadError, &sh->dev[i].flags);
34177 clear_bit(R5_ReWrite, &sh->dev[i].flags);
34178 } else if (test_bit(R5_ReadNoMerge, &sh->dev[i].flags))
34179 clear_bit(R5_ReadNoMerge, &sh->dev[i].flags);
34180
34181- if (atomic_read(&rdev->read_errors))
34182- atomic_set(&rdev->read_errors, 0);
34183+ if (atomic_read_unchecked(&rdev->read_errors))
34184+ atomic_set_unchecked(&rdev->read_errors, 0);
34185 } else {
34186 const char *bdn = bdevname(rdev->bdev, b);
34187 int retry = 0;
34188 int set_bad = 0;
34189
34190 clear_bit(R5_UPTODATE, &sh->dev[i].flags);
34191- atomic_inc(&rdev->read_errors);
34192+ atomic_inc_unchecked(&rdev->read_errors);
34193 if (test_bit(R5_ReadRepl, &sh->dev[i].flags))
34194 printk_ratelimited(
34195 KERN_WARNING
34196@@ -1798,7 +1798,7 @@ static void raid5_end_read_request(struct bio * bi, int error)
34197 mdname(conf->mddev),
34198 (unsigned long long)s,
34199 bdn);
34200- } else if (atomic_read(&rdev->read_errors)
34201+ } else if (atomic_read_unchecked(&rdev->read_errors)
34202 > conf->max_nr_stripes)
34203 printk(KERN_WARNING
34204 "md/raid:%s: Too many read errors, failing device %s.\n",
34205diff --git a/drivers/media/dvb/ddbridge/ddbridge-core.c b/drivers/media/dvb/ddbridge/ddbridge-core.c
34206index ebf3f05..b1f3e77 100644
34207--- a/drivers/media/dvb/ddbridge/ddbridge-core.c
34208+++ b/drivers/media/dvb/ddbridge/ddbridge-core.c
34209@@ -1679,7 +1679,7 @@ static struct ddb_info ddb_v6 = {
34210 .subvendor = _subvend, .subdevice = _subdev, \
34211 .driver_data = (unsigned long)&_driverdata }
34212
34213-static const struct pci_device_id ddb_id_tbl[] __devinitdata = {
34214+static const struct pci_device_id ddb_id_tbl[] __devinitconst = {
34215 DDB_ID(DDVID, 0x0002, DDVID, 0x0001, ddb_octopus),
34216 DDB_ID(DDVID, 0x0003, DDVID, 0x0001, ddb_octopus),
34217 DDB_ID(DDVID, 0x0003, DDVID, 0x0002, ddb_octopus_le),
34218diff --git a/drivers/media/dvb/dvb-core/dvb_demux.h b/drivers/media/dvb/dvb-core/dvb_demux.h
34219index fa7188a..04a045e 100644
34220--- a/drivers/media/dvb/dvb-core/dvb_demux.h
34221+++ b/drivers/media/dvb/dvb-core/dvb_demux.h
34222@@ -73,7 +73,7 @@ struct dvb_demux_feed {
34223 union {
34224 dmx_ts_cb ts;
34225 dmx_section_cb sec;
34226- } cb;
34227+ } __no_const cb;
34228
34229 struct dvb_demux *demux;
34230 void *priv;
34231diff --git a/drivers/media/dvb/dvb-core/dvbdev.c b/drivers/media/dvb/dvb-core/dvbdev.c
34232index 39eab73..60033e7 100644
34233--- a/drivers/media/dvb/dvb-core/dvbdev.c
34234+++ b/drivers/media/dvb/dvb-core/dvbdev.c
34235@@ -192,7 +192,7 @@ int dvb_register_device(struct dvb_adapter *adap, struct dvb_device **pdvbdev,
34236 const struct dvb_device *template, void *priv, int type)
34237 {
34238 struct dvb_device *dvbdev;
34239- struct file_operations *dvbdevfops;
34240+ file_operations_no_const *dvbdevfops;
34241 struct device *clsdev;
34242 int minor;
34243 int id;
34244diff --git a/drivers/media/dvb/dvb-usb/cxusb.c b/drivers/media/dvb/dvb-usb/cxusb.c
34245index 3940bb0..fb3952a 100644
34246--- a/drivers/media/dvb/dvb-usb/cxusb.c
34247+++ b/drivers/media/dvb/dvb-usb/cxusb.c
34248@@ -1068,7 +1068,7 @@ static struct dib0070_config dib7070p_dib0070_config = {
34249
34250 struct dib0700_adapter_state {
34251 int (*set_param_save) (struct dvb_frontend *);
34252-};
34253+} __no_const;
34254
34255 static int dib7070_set_param_override(struct dvb_frontend *fe)
34256 {
34257diff --git a/drivers/media/dvb/dvb-usb/dw2102.c b/drivers/media/dvb/dvb-usb/dw2102.c
34258index 9382895..ac8093c 100644
34259--- a/drivers/media/dvb/dvb-usb/dw2102.c
34260+++ b/drivers/media/dvb/dvb-usb/dw2102.c
34261@@ -95,7 +95,7 @@ struct su3000_state {
34262
34263 struct s6x0_state {
34264 int (*old_set_voltage)(struct dvb_frontend *f, fe_sec_voltage_t v);
34265-};
34266+} __no_const;
34267
34268 /* debug */
34269 static int dvb_usb_dw2102_debug;
34270diff --git a/drivers/media/dvb/frontends/dib3000.h b/drivers/media/dvb/frontends/dib3000.h
34271index 404f63a..4796533 100644
34272--- a/drivers/media/dvb/frontends/dib3000.h
34273+++ b/drivers/media/dvb/frontends/dib3000.h
34274@@ -39,7 +39,7 @@ struct dib_fe_xfer_ops
34275 int (*fifo_ctrl)(struct dvb_frontend *fe, int onoff);
34276 int (*pid_ctrl)(struct dvb_frontend *fe, int index, int pid, int onoff);
34277 int (*tuner_pass_ctrl)(struct dvb_frontend *fe, int onoff, u8 pll_ctrl);
34278-};
34279+} __no_const;
34280
34281 #if defined(CONFIG_DVB_DIB3000MB) || (defined(CONFIG_DVB_DIB3000MB_MODULE) && defined(MODULE))
34282 extern struct dvb_frontend* dib3000mb_attach(const struct dib3000_config* config,
34283diff --git a/drivers/media/dvb/ngene/ngene-cards.c b/drivers/media/dvb/ngene/ngene-cards.c
34284index 72ee8de..eae0c80 100644
34285--- a/drivers/media/dvb/ngene/ngene-cards.c
34286+++ b/drivers/media/dvb/ngene/ngene-cards.c
34287@@ -479,7 +479,7 @@ static struct ngene_info ngene_info_m780 = {
34288
34289 /****************************************************************************/
34290
34291-static const struct pci_device_id ngene_id_tbl[] __devinitdata = {
34292+static const struct pci_device_id ngene_id_tbl[] __devinitconst = {
34293 NGENE_ID(0x18c3, 0xabc3, ngene_info_cineS2),
34294 NGENE_ID(0x18c3, 0xabc4, ngene_info_cineS2),
34295 NGENE_ID(0x18c3, 0xdb01, ngene_info_satixS2),
34296diff --git a/drivers/media/radio/radio-cadet.c b/drivers/media/radio/radio-cadet.c
34297index 697a421..16c5a5f 100644
34298--- a/drivers/media/radio/radio-cadet.c
34299+++ b/drivers/media/radio/radio-cadet.c
34300@@ -302,6 +302,8 @@ static ssize_t cadet_read(struct file *file, char __user *data, size_t count, lo
34301 unsigned char readbuf[RDS_BUFFER];
34302 int i = 0;
34303
34304+ if (count > RDS_BUFFER)
34305+ return -EFAULT;
34306 mutex_lock(&dev->lock);
34307 if (dev->rdsstat == 0)
34308 cadet_start_rds(dev);
34309@@ -317,7 +319,7 @@ static ssize_t cadet_read(struct file *file, char __user *data, size_t count, lo
34310 while (i < count && dev->rdsin != dev->rdsout)
34311 readbuf[i++] = dev->rdsbuf[dev->rdsout++];
34312
34313- if (i && copy_to_user(data, readbuf, i))
34314+ if (i > sizeof(readbuf) || copy_to_user(data, readbuf, i))
34315 i = -EFAULT;
34316 unlock:
34317 mutex_unlock(&dev->lock);
34318diff --git a/drivers/media/radio/radio-tea5777.h b/drivers/media/radio/radio-tea5777.h
34319index 55cbd78..428b0da 100644
34320--- a/drivers/media/radio/radio-tea5777.h
34321+++ b/drivers/media/radio/radio-tea5777.h
34322@@ -63,7 +63,7 @@ struct radio_tea5777_ops {
34323
34324 struct radio_tea5777 {
34325 struct v4l2_device *v4l2_dev;
34326- struct v4l2_file_operations fops;
34327+ v4l2_file_operations_no_const fops;
34328 struct video_device vd; /* video device */
34329 bool has_am; /* Device can tune to AM freqs */
34330 bool write_before_read; /* must write before read quirk */
34331diff --git a/drivers/media/video/au0828/au0828.h b/drivers/media/video/au0828/au0828.h
34332index 9cde353..8c6a1c3 100644
34333--- a/drivers/media/video/au0828/au0828.h
34334+++ b/drivers/media/video/au0828/au0828.h
34335@@ -191,7 +191,7 @@ struct au0828_dev {
34336
34337 /* I2C */
34338 struct i2c_adapter i2c_adap;
34339- struct i2c_algorithm i2c_algo;
34340+ i2c_algorithm_no_const i2c_algo;
34341 struct i2c_client i2c_client;
34342 u32 i2c_rc;
34343
34344diff --git a/drivers/media/video/cx88/cx88-alsa.c b/drivers/media/video/cx88/cx88-alsa.c
34345index dfac6e3..c26de31 100644
34346--- a/drivers/media/video/cx88/cx88-alsa.c
34347+++ b/drivers/media/video/cx88/cx88-alsa.c
34348@@ -749,7 +749,7 @@ static struct snd_kcontrol_new snd_cx88_alc_switch = {
34349 * Only boards with eeprom and byte 1 at eeprom=1 have it
34350 */
34351
34352-static const struct pci_device_id const cx88_audio_pci_tbl[] __devinitdata = {
34353+static const struct pci_device_id const cx88_audio_pci_tbl[] __devinitconst = {
34354 {0x14f1,0x8801,PCI_ANY_ID,PCI_ANY_ID,0,0,0},
34355 {0x14f1,0x8811,PCI_ANY_ID,PCI_ANY_ID,0,0,0},
34356 {0, }
34357diff --git a/drivers/media/video/omap/omap_vout.c b/drivers/media/video/omap/omap_vout.c
34358index 88cf9d9..bbc4b2c 100644
34359--- a/drivers/media/video/omap/omap_vout.c
34360+++ b/drivers/media/video/omap/omap_vout.c
34361@@ -64,7 +64,6 @@ enum omap_vout_channels {
34362 OMAP_VIDEO2,
34363 };
34364
34365-static struct videobuf_queue_ops video_vbq_ops;
34366 /* Variables configurable through module params*/
34367 static u32 video1_numbuffers = 3;
34368 static u32 video2_numbuffers = 3;
34369@@ -1000,6 +999,12 @@ static int omap_vout_open(struct file *file)
34370 {
34371 struct videobuf_queue *q;
34372 struct omap_vout_device *vout = NULL;
34373+ static struct videobuf_queue_ops video_vbq_ops = {
34374+ .buf_setup = omap_vout_buffer_setup,
34375+ .buf_prepare = omap_vout_buffer_prepare,
34376+ .buf_release = omap_vout_buffer_release,
34377+ .buf_queue = omap_vout_buffer_queue,
34378+ };
34379
34380 vout = video_drvdata(file);
34381 v4l2_dbg(1, debug, &vout->vid_dev->v4l2_dev, "Entering %s\n", __func__);
34382@@ -1017,10 +1022,6 @@ static int omap_vout_open(struct file *file)
34383 vout->type = V4L2_BUF_TYPE_VIDEO_OUTPUT;
34384
34385 q = &vout->vbq;
34386- video_vbq_ops.buf_setup = omap_vout_buffer_setup;
34387- video_vbq_ops.buf_prepare = omap_vout_buffer_prepare;
34388- video_vbq_ops.buf_release = omap_vout_buffer_release;
34389- video_vbq_ops.buf_queue = omap_vout_buffer_queue;
34390 spin_lock_init(&vout->vbq_lock);
34391
34392 videobuf_queue_dma_contig_init(q, &video_vbq_ops, q->dev,
34393diff --git a/drivers/media/video/pvrusb2/pvrusb2-hdw-internal.h b/drivers/media/video/pvrusb2/pvrusb2-hdw-internal.h
34394index 036952f..80d356d 100644
34395--- a/drivers/media/video/pvrusb2/pvrusb2-hdw-internal.h
34396+++ b/drivers/media/video/pvrusb2/pvrusb2-hdw-internal.h
34397@@ -196,7 +196,7 @@ struct pvr2_hdw {
34398
34399 /* I2C stuff */
34400 struct i2c_adapter i2c_adap;
34401- struct i2c_algorithm i2c_algo;
34402+ i2c_algorithm_no_const i2c_algo;
34403 pvr2_i2c_func i2c_func[PVR2_I2C_FUNC_CNT];
34404 int i2c_cx25840_hack_state;
34405 int i2c_linked;
34406diff --git a/drivers/media/video/timblogiw.c b/drivers/media/video/timblogiw.c
34407index 02194c0..091733b 100644
34408--- a/drivers/media/video/timblogiw.c
34409+++ b/drivers/media/video/timblogiw.c
34410@@ -745,7 +745,7 @@ static int timblogiw_mmap(struct file *file, struct vm_area_struct *vma)
34411
34412 /* Platform device functions */
34413
34414-static __devinitconst struct v4l2_ioctl_ops timblogiw_ioctl_ops = {
34415+static __devinitconst v4l2_ioctl_ops_no_const timblogiw_ioctl_ops = {
34416 .vidioc_querycap = timblogiw_querycap,
34417 .vidioc_enum_fmt_vid_cap = timblogiw_enum_fmt,
34418 .vidioc_g_fmt_vid_cap = timblogiw_g_fmt,
34419@@ -767,7 +767,7 @@ static __devinitconst struct v4l2_ioctl_ops timblogiw_ioctl_ops = {
34420 .vidioc_enum_framesizes = timblogiw_enum_framesizes,
34421 };
34422
34423-static __devinitconst struct v4l2_file_operations timblogiw_fops = {
34424+static __devinitconst v4l2_file_operations_no_const timblogiw_fops = {
34425 .owner = THIS_MODULE,
34426 .open = timblogiw_open,
34427 .release = timblogiw_close,
34428diff --git a/drivers/message/fusion/mptbase.c b/drivers/message/fusion/mptbase.c
34429index d99db56..a16b959 100644
34430--- a/drivers/message/fusion/mptbase.c
34431+++ b/drivers/message/fusion/mptbase.c
34432@@ -6751,8 +6751,13 @@ static int mpt_iocinfo_proc_show(struct seq_file *m, void *v)
34433 seq_printf(m, " MaxChainDepth = 0x%02x frames\n", ioc->facts.MaxChainDepth);
34434 seq_printf(m, " MinBlockSize = 0x%02x bytes\n", 4*ioc->facts.BlockSize);
34435
34436+#ifdef CONFIG_GRKERNSEC_HIDESYM
34437+ seq_printf(m, " RequestFrames @ 0x%p (Dma @ 0x%p)\n", NULL, NULL);
34438+#else
34439 seq_printf(m, " RequestFrames @ 0x%p (Dma @ 0x%p)\n",
34440 (void *)ioc->req_frames, (void *)(ulong)ioc->req_frames_dma);
34441+#endif
34442+
34443 /*
34444 * Rounding UP to nearest 4-kB boundary here...
34445 */
34446diff --git a/drivers/message/fusion/mptsas.c b/drivers/message/fusion/mptsas.c
34447index 551262e..7551198 100644
34448--- a/drivers/message/fusion/mptsas.c
34449+++ b/drivers/message/fusion/mptsas.c
34450@@ -446,6 +446,23 @@ mptsas_is_end_device(struct mptsas_devinfo * attached)
34451 return 0;
34452 }
34453
34454+static inline void
34455+mptsas_set_rphy(MPT_ADAPTER *ioc, struct mptsas_phyinfo *phy_info, struct sas_rphy *rphy)
34456+{
34457+ if (phy_info->port_details) {
34458+ phy_info->port_details->rphy = rphy;
34459+ dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "sas_rphy_add: rphy=%p\n",
34460+ ioc->name, rphy));
34461+ }
34462+
34463+ if (rphy) {
34464+ dsaswideprintk(ioc, dev_printk(KERN_DEBUG,
34465+ &rphy->dev, MYIOC_s_FMT "add:", ioc->name));
34466+ dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "rphy=%p release=%p\n",
34467+ ioc->name, rphy, rphy->dev.release));
34468+ }
34469+}
34470+
34471 /* no mutex */
34472 static void
34473 mptsas_port_delete(MPT_ADAPTER *ioc, struct mptsas_portinfo_details * port_details)
34474@@ -484,23 +501,6 @@ mptsas_get_rphy(struct mptsas_phyinfo *phy_info)
34475 return NULL;
34476 }
34477
34478-static inline void
34479-mptsas_set_rphy(MPT_ADAPTER *ioc, struct mptsas_phyinfo *phy_info, struct sas_rphy *rphy)
34480-{
34481- if (phy_info->port_details) {
34482- phy_info->port_details->rphy = rphy;
34483- dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "sas_rphy_add: rphy=%p\n",
34484- ioc->name, rphy));
34485- }
34486-
34487- if (rphy) {
34488- dsaswideprintk(ioc, dev_printk(KERN_DEBUG,
34489- &rphy->dev, MYIOC_s_FMT "add:", ioc->name));
34490- dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "rphy=%p release=%p\n",
34491- ioc->name, rphy, rphy->dev.release));
34492- }
34493-}
34494-
34495 static inline struct sas_port *
34496 mptsas_get_port(struct mptsas_phyinfo *phy_info)
34497 {
34498diff --git a/drivers/message/fusion/mptscsih.c b/drivers/message/fusion/mptscsih.c
34499index 0c3ced7..1fe34ec 100644
34500--- a/drivers/message/fusion/mptscsih.c
34501+++ b/drivers/message/fusion/mptscsih.c
34502@@ -1270,15 +1270,16 @@ mptscsih_info(struct Scsi_Host *SChost)
34503
34504 h = shost_priv(SChost);
34505
34506- if (h) {
34507- if (h->info_kbuf == NULL)
34508- if ((h->info_kbuf = kmalloc(0x1000 /* 4Kb */, GFP_KERNEL)) == NULL)
34509- return h->info_kbuf;
34510- h->info_kbuf[0] = '\0';
34511+ if (!h)
34512+ return NULL;
34513
34514- mpt_print_ioc_summary(h->ioc, h->info_kbuf, &size, 0, 0);
34515- h->info_kbuf[size-1] = '\0';
34516- }
34517+ if (h->info_kbuf == NULL)
34518+ if ((h->info_kbuf = kmalloc(0x1000 /* 4Kb */, GFP_KERNEL)) == NULL)
34519+ return h->info_kbuf;
34520+ h->info_kbuf[0] = '\0';
34521+
34522+ mpt_print_ioc_summary(h->ioc, h->info_kbuf, &size, 0, 0);
34523+ h->info_kbuf[size-1] = '\0';
34524
34525 return h->info_kbuf;
34526 }
34527diff --git a/drivers/message/i2o/i2o_proc.c b/drivers/message/i2o/i2o_proc.c
34528index 8001aa6..b137580 100644
34529--- a/drivers/message/i2o/i2o_proc.c
34530+++ b/drivers/message/i2o/i2o_proc.c
34531@@ -255,12 +255,6 @@ static char *scsi_devices[] = {
34532 "Array Controller Device"
34533 };
34534
34535-static char *chtostr(char *tmp, u8 *chars, int n)
34536-{
34537- tmp[0] = 0;
34538- return strncat(tmp, (char *)chars, n);
34539-}
34540-
34541 static int i2o_report_query_status(struct seq_file *seq, int block_status,
34542 char *group)
34543 {
34544@@ -790,7 +784,6 @@ static int i2o_seq_show_ddm_table(struct seq_file *seq, void *v)
34545 } *result;
34546
34547 i2o_exec_execute_ddm_table ddm_table;
34548- char tmp[28 + 1];
34549
34550 result = kmalloc(sizeof(*result), GFP_KERNEL);
34551 if (!result)
34552@@ -825,8 +818,7 @@ static int i2o_seq_show_ddm_table(struct seq_file *seq, void *v)
34553
34554 seq_printf(seq, "%-#7x", ddm_table.i2o_vendor_id);
34555 seq_printf(seq, "%-#8x", ddm_table.module_id);
34556- seq_printf(seq, "%-29s",
34557- chtostr(tmp, ddm_table.module_name_version, 28));
34558+ seq_printf(seq, "%-.28s", ddm_table.module_name_version);
34559 seq_printf(seq, "%9d ", ddm_table.data_size);
34560 seq_printf(seq, "%8d", ddm_table.code_size);
34561
34562@@ -893,7 +885,6 @@ static int i2o_seq_show_drivers_stored(struct seq_file *seq, void *v)
34563
34564 i2o_driver_result_table *result;
34565 i2o_driver_store_table *dst;
34566- char tmp[28 + 1];
34567
34568 result = kmalloc(sizeof(i2o_driver_result_table), GFP_KERNEL);
34569 if (result == NULL)
34570@@ -928,9 +919,8 @@ static int i2o_seq_show_drivers_stored(struct seq_file *seq, void *v)
34571
34572 seq_printf(seq, "%-#7x", dst->i2o_vendor_id);
34573 seq_printf(seq, "%-#8x", dst->module_id);
34574- seq_printf(seq, "%-29s",
34575- chtostr(tmp, dst->module_name_version, 28));
34576- seq_printf(seq, "%-9s", chtostr(tmp, dst->date, 8));
34577+ seq_printf(seq, "%-.28s", dst->module_name_version);
34578+ seq_printf(seq, "%-.8s", dst->date);
34579 seq_printf(seq, "%8d ", dst->module_size);
34580 seq_printf(seq, "%8d ", dst->mpb_size);
34581 seq_printf(seq, "0x%04x", dst->module_flags);
34582@@ -1250,7 +1240,6 @@ static int i2o_seq_show_dev_identity(struct seq_file *seq, void *v)
34583 // == (allow) 512d bytes (max)
34584 static u16 *work16 = (u16 *) work32;
34585 int token;
34586- char tmp[16 + 1];
34587
34588 token = i2o_parm_field_get(d, 0xF100, -1, &work32, sizeof(work32));
34589
34590@@ -1262,14 +1251,10 @@ static int i2o_seq_show_dev_identity(struct seq_file *seq, void *v)
34591 seq_printf(seq, "Device Class : %s\n", i2o_get_class_name(work16[0]));
34592 seq_printf(seq, "Owner TID : %0#5x\n", work16[2]);
34593 seq_printf(seq, "Parent TID : %0#5x\n", work16[3]);
34594- seq_printf(seq, "Vendor info : %s\n",
34595- chtostr(tmp, (u8 *) (work32 + 2), 16));
34596- seq_printf(seq, "Product info : %s\n",
34597- chtostr(tmp, (u8 *) (work32 + 6), 16));
34598- seq_printf(seq, "Description : %s\n",
34599- chtostr(tmp, (u8 *) (work32 + 10), 16));
34600- seq_printf(seq, "Product rev. : %s\n",
34601- chtostr(tmp, (u8 *) (work32 + 14), 8));
34602+ seq_printf(seq, "Vendor info : %.16s\n", (u8 *) (work32 + 2));
34603+ seq_printf(seq, "Product info : %.16s\n", (u8 *) (work32 + 6));
34604+ seq_printf(seq, "Description : %.16s\n", (u8 *) (work32 + 10));
34605+ seq_printf(seq, "Product rev. : %.8s\n", (u8 *) (work32 + 14));
34606
34607 seq_printf(seq, "Serial number : ");
34608 print_serial_number(seq, (u8 *) (work32 + 16),
34609@@ -1306,8 +1291,6 @@ static int i2o_seq_show_ddm_identity(struct seq_file *seq, void *v)
34610 u8 pad[256]; // allow up to 256 byte (max) serial number
34611 } result;
34612
34613- char tmp[24 + 1];
34614-
34615 token = i2o_parm_field_get(d, 0xF101, -1, &result, sizeof(result));
34616
34617 if (token < 0) {
34618@@ -1316,10 +1299,8 @@ static int i2o_seq_show_ddm_identity(struct seq_file *seq, void *v)
34619 }
34620
34621 seq_printf(seq, "Registering DDM TID : 0x%03x\n", result.ddm_tid);
34622- seq_printf(seq, "Module name : %s\n",
34623- chtostr(tmp, result.module_name, 24));
34624- seq_printf(seq, "Module revision : %s\n",
34625- chtostr(tmp, result.module_rev, 8));
34626+ seq_printf(seq, "Module name : %.24s\n", result.module_name);
34627+ seq_printf(seq, "Module revision : %.8s\n", result.module_rev);
34628
34629 seq_printf(seq, "Serial number : ");
34630 print_serial_number(seq, result.serial_number, sizeof(result) - 36);
34631@@ -1343,8 +1324,6 @@ static int i2o_seq_show_uinfo(struct seq_file *seq, void *v)
34632 u8 instance_number[4];
34633 } result;
34634
34635- char tmp[64 + 1];
34636-
34637 token = i2o_parm_field_get(d, 0xF102, -1, &result, sizeof(result));
34638
34639 if (token < 0) {
34640@@ -1352,14 +1331,10 @@ static int i2o_seq_show_uinfo(struct seq_file *seq, void *v)
34641 return 0;
34642 }
34643
34644- seq_printf(seq, "Device name : %s\n",
34645- chtostr(tmp, result.device_name, 64));
34646- seq_printf(seq, "Service name : %s\n",
34647- chtostr(tmp, result.service_name, 64));
34648- seq_printf(seq, "Physical name : %s\n",
34649- chtostr(tmp, result.physical_location, 64));
34650- seq_printf(seq, "Instance number : %s\n",
34651- chtostr(tmp, result.instance_number, 4));
34652+ seq_printf(seq, "Device name : %.64s\n", result.device_name);
34653+ seq_printf(seq, "Service name : %.64s\n", result.service_name);
34654+ seq_printf(seq, "Physical name : %.64s\n", result.physical_location);
34655+ seq_printf(seq, "Instance number : %.4s\n", result.instance_number);
34656
34657 return 0;
34658 }
34659diff --git a/drivers/message/i2o/iop.c b/drivers/message/i2o/iop.c
34660index a8c08f3..155fe3d 100644
34661--- a/drivers/message/i2o/iop.c
34662+++ b/drivers/message/i2o/iop.c
34663@@ -111,10 +111,10 @@ u32 i2o_cntxt_list_add(struct i2o_controller * c, void *ptr)
34664
34665 spin_lock_irqsave(&c->context_list_lock, flags);
34666
34667- if (unlikely(atomic_inc_and_test(&c->context_list_counter)))
34668- atomic_inc(&c->context_list_counter);
34669+ if (unlikely(atomic_inc_and_test_unchecked(&c->context_list_counter)))
34670+ atomic_inc_unchecked(&c->context_list_counter);
34671
34672- entry->context = atomic_read(&c->context_list_counter);
34673+ entry->context = atomic_read_unchecked(&c->context_list_counter);
34674
34675 list_add(&entry->list, &c->context_list);
34676
34677@@ -1077,7 +1077,7 @@ struct i2o_controller *i2o_iop_alloc(void)
34678
34679 #if BITS_PER_LONG == 64
34680 spin_lock_init(&c->context_list_lock);
34681- atomic_set(&c->context_list_counter, 0);
34682+ atomic_set_unchecked(&c->context_list_counter, 0);
34683 INIT_LIST_HEAD(&c->context_list);
34684 #endif
34685
34686diff --git a/drivers/mfd/abx500-core.c b/drivers/mfd/abx500-core.c
34687index 7ce65f4..e66e9bc 100644
34688--- a/drivers/mfd/abx500-core.c
34689+++ b/drivers/mfd/abx500-core.c
34690@@ -15,7 +15,7 @@ static LIST_HEAD(abx500_list);
34691
34692 struct abx500_device_entry {
34693 struct list_head list;
34694- struct abx500_ops ops;
34695+ abx500_ops_no_const ops;
34696 struct device *dev;
34697 };
34698
34699diff --git a/drivers/mfd/janz-cmodio.c b/drivers/mfd/janz-cmodio.c
34700index 965c480..71f2db9 100644
34701--- a/drivers/mfd/janz-cmodio.c
34702+++ b/drivers/mfd/janz-cmodio.c
34703@@ -13,6 +13,7 @@
34704
34705 #include <linux/kernel.h>
34706 #include <linux/module.h>
34707+#include <linux/slab.h>
34708 #include <linux/init.h>
34709 #include <linux/pci.h>
34710 #include <linux/interrupt.h>
34711diff --git a/drivers/misc/lis3lv02d/lis3lv02d.c b/drivers/misc/lis3lv02d/lis3lv02d.c
34712index a981e2a..5ca0c8b 100644
34713--- a/drivers/misc/lis3lv02d/lis3lv02d.c
34714+++ b/drivers/misc/lis3lv02d/lis3lv02d.c
34715@@ -466,7 +466,7 @@ static irqreturn_t lis302dl_interrupt(int irq, void *data)
34716 * the lid is closed. This leads to interrupts as soon as a little move
34717 * is done.
34718 */
34719- atomic_inc(&lis3->count);
34720+ atomic_inc_unchecked(&lis3->count);
34721
34722 wake_up_interruptible(&lis3->misc_wait);
34723 kill_fasync(&lis3->async_queue, SIGIO, POLL_IN);
34724@@ -552,7 +552,7 @@ static int lis3lv02d_misc_open(struct inode *inode, struct file *file)
34725 if (lis3->pm_dev)
34726 pm_runtime_get_sync(lis3->pm_dev);
34727
34728- atomic_set(&lis3->count, 0);
34729+ atomic_set_unchecked(&lis3->count, 0);
34730 return 0;
34731 }
34732
34733@@ -585,7 +585,7 @@ static ssize_t lis3lv02d_misc_read(struct file *file, char __user *buf,
34734 add_wait_queue(&lis3->misc_wait, &wait);
34735 while (true) {
34736 set_current_state(TASK_INTERRUPTIBLE);
34737- data = atomic_xchg(&lis3->count, 0);
34738+ data = atomic_xchg_unchecked(&lis3->count, 0);
34739 if (data)
34740 break;
34741
34742@@ -626,7 +626,7 @@ static unsigned int lis3lv02d_misc_poll(struct file *file, poll_table *wait)
34743 struct lis3lv02d, miscdev);
34744
34745 poll_wait(file, &lis3->misc_wait, wait);
34746- if (atomic_read(&lis3->count))
34747+ if (atomic_read_unchecked(&lis3->count))
34748 return POLLIN | POLLRDNORM;
34749 return 0;
34750 }
34751diff --git a/drivers/misc/lis3lv02d/lis3lv02d.h b/drivers/misc/lis3lv02d/lis3lv02d.h
34752index 2b1482a..5d33616 100644
34753--- a/drivers/misc/lis3lv02d/lis3lv02d.h
34754+++ b/drivers/misc/lis3lv02d/lis3lv02d.h
34755@@ -266,7 +266,7 @@ struct lis3lv02d {
34756 struct input_polled_dev *idev; /* input device */
34757 struct platform_device *pdev; /* platform device */
34758 struct regulator_bulk_data regulators[2];
34759- atomic_t count; /* interrupt count after last read */
34760+ atomic_unchecked_t count; /* interrupt count after last read */
34761 union axis_conversion ac; /* hw -> logical axis */
34762 int mapped_btns[3];
34763
34764diff --git a/drivers/misc/sgi-gru/gruhandles.c b/drivers/misc/sgi-gru/gruhandles.c
34765index 2f30bad..c4c13d0 100644
34766--- a/drivers/misc/sgi-gru/gruhandles.c
34767+++ b/drivers/misc/sgi-gru/gruhandles.c
34768@@ -44,8 +44,8 @@ static void update_mcs_stats(enum mcs_op op, unsigned long clks)
34769 unsigned long nsec;
34770
34771 nsec = CLKS2NSEC(clks);
34772- atomic_long_inc(&mcs_op_statistics[op].count);
34773- atomic_long_add(nsec, &mcs_op_statistics[op].total);
34774+ atomic_long_inc_unchecked(&mcs_op_statistics[op].count);
34775+ atomic_long_add_unchecked(nsec, &mcs_op_statistics[op].total);
34776 if (mcs_op_statistics[op].max < nsec)
34777 mcs_op_statistics[op].max = nsec;
34778 }
34779diff --git a/drivers/misc/sgi-gru/gruprocfs.c b/drivers/misc/sgi-gru/gruprocfs.c
34780index 950dbe9..eeef0f8 100644
34781--- a/drivers/misc/sgi-gru/gruprocfs.c
34782+++ b/drivers/misc/sgi-gru/gruprocfs.c
34783@@ -32,9 +32,9 @@
34784
34785 #define printstat(s, f) printstat_val(s, &gru_stats.f, #f)
34786
34787-static void printstat_val(struct seq_file *s, atomic_long_t *v, char *id)
34788+static void printstat_val(struct seq_file *s, atomic_long_unchecked_t *v, char *id)
34789 {
34790- unsigned long val = atomic_long_read(v);
34791+ unsigned long val = atomic_long_read_unchecked(v);
34792
34793 seq_printf(s, "%16lu %s\n", val, id);
34794 }
34795@@ -134,8 +134,8 @@ static int mcs_statistics_show(struct seq_file *s, void *p)
34796
34797 seq_printf(s, "%-20s%12s%12s%12s\n", "#id", "count", "aver-clks", "max-clks");
34798 for (op = 0; op < mcsop_last; op++) {
34799- count = atomic_long_read(&mcs_op_statistics[op].count);
34800- total = atomic_long_read(&mcs_op_statistics[op].total);
34801+ count = atomic_long_read_unchecked(&mcs_op_statistics[op].count);
34802+ total = atomic_long_read_unchecked(&mcs_op_statistics[op].total);
34803 max = mcs_op_statistics[op].max;
34804 seq_printf(s, "%-20s%12ld%12ld%12ld\n", id[op], count,
34805 count ? total / count : 0, max);
34806diff --git a/drivers/misc/sgi-gru/grutables.h b/drivers/misc/sgi-gru/grutables.h
34807index 5c3ce24..4915ccb 100644
34808--- a/drivers/misc/sgi-gru/grutables.h
34809+++ b/drivers/misc/sgi-gru/grutables.h
34810@@ -167,82 +167,82 @@ extern unsigned int gru_max_gids;
34811 * GRU statistics.
34812 */
34813 struct gru_stats_s {
34814- atomic_long_t vdata_alloc;
34815- atomic_long_t vdata_free;
34816- atomic_long_t gts_alloc;
34817- atomic_long_t gts_free;
34818- atomic_long_t gms_alloc;
34819- atomic_long_t gms_free;
34820- atomic_long_t gts_double_allocate;
34821- atomic_long_t assign_context;
34822- atomic_long_t assign_context_failed;
34823- atomic_long_t free_context;
34824- atomic_long_t load_user_context;
34825- atomic_long_t load_kernel_context;
34826- atomic_long_t lock_kernel_context;
34827- atomic_long_t unlock_kernel_context;
34828- atomic_long_t steal_user_context;
34829- atomic_long_t steal_kernel_context;
34830- atomic_long_t steal_context_failed;
34831- atomic_long_t nopfn;
34832- atomic_long_t asid_new;
34833- atomic_long_t asid_next;
34834- atomic_long_t asid_wrap;
34835- atomic_long_t asid_reuse;
34836- atomic_long_t intr;
34837- atomic_long_t intr_cbr;
34838- atomic_long_t intr_tfh;
34839- atomic_long_t intr_spurious;
34840- atomic_long_t intr_mm_lock_failed;
34841- atomic_long_t call_os;
34842- atomic_long_t call_os_wait_queue;
34843- atomic_long_t user_flush_tlb;
34844- atomic_long_t user_unload_context;
34845- atomic_long_t user_exception;
34846- atomic_long_t set_context_option;
34847- atomic_long_t check_context_retarget_intr;
34848- atomic_long_t check_context_unload;
34849- atomic_long_t tlb_dropin;
34850- atomic_long_t tlb_preload_page;
34851- atomic_long_t tlb_dropin_fail_no_asid;
34852- atomic_long_t tlb_dropin_fail_upm;
34853- atomic_long_t tlb_dropin_fail_invalid;
34854- atomic_long_t tlb_dropin_fail_range_active;
34855- atomic_long_t tlb_dropin_fail_idle;
34856- atomic_long_t tlb_dropin_fail_fmm;
34857- atomic_long_t tlb_dropin_fail_no_exception;
34858- atomic_long_t tfh_stale_on_fault;
34859- atomic_long_t mmu_invalidate_range;
34860- atomic_long_t mmu_invalidate_page;
34861- atomic_long_t flush_tlb;
34862- atomic_long_t flush_tlb_gru;
34863- atomic_long_t flush_tlb_gru_tgh;
34864- atomic_long_t flush_tlb_gru_zero_asid;
34865+ atomic_long_unchecked_t vdata_alloc;
34866+ atomic_long_unchecked_t vdata_free;
34867+ atomic_long_unchecked_t gts_alloc;
34868+ atomic_long_unchecked_t gts_free;
34869+ atomic_long_unchecked_t gms_alloc;
34870+ atomic_long_unchecked_t gms_free;
34871+ atomic_long_unchecked_t gts_double_allocate;
34872+ atomic_long_unchecked_t assign_context;
34873+ atomic_long_unchecked_t assign_context_failed;
34874+ atomic_long_unchecked_t free_context;
34875+ atomic_long_unchecked_t load_user_context;
34876+ atomic_long_unchecked_t load_kernel_context;
34877+ atomic_long_unchecked_t lock_kernel_context;
34878+ atomic_long_unchecked_t unlock_kernel_context;
34879+ atomic_long_unchecked_t steal_user_context;
34880+ atomic_long_unchecked_t steal_kernel_context;
34881+ atomic_long_unchecked_t steal_context_failed;
34882+ atomic_long_unchecked_t nopfn;
34883+ atomic_long_unchecked_t asid_new;
34884+ atomic_long_unchecked_t asid_next;
34885+ atomic_long_unchecked_t asid_wrap;
34886+ atomic_long_unchecked_t asid_reuse;
34887+ atomic_long_unchecked_t intr;
34888+ atomic_long_unchecked_t intr_cbr;
34889+ atomic_long_unchecked_t intr_tfh;
34890+ atomic_long_unchecked_t intr_spurious;
34891+ atomic_long_unchecked_t intr_mm_lock_failed;
34892+ atomic_long_unchecked_t call_os;
34893+ atomic_long_unchecked_t call_os_wait_queue;
34894+ atomic_long_unchecked_t user_flush_tlb;
34895+ atomic_long_unchecked_t user_unload_context;
34896+ atomic_long_unchecked_t user_exception;
34897+ atomic_long_unchecked_t set_context_option;
34898+ atomic_long_unchecked_t check_context_retarget_intr;
34899+ atomic_long_unchecked_t check_context_unload;
34900+ atomic_long_unchecked_t tlb_dropin;
34901+ atomic_long_unchecked_t tlb_preload_page;
34902+ atomic_long_unchecked_t tlb_dropin_fail_no_asid;
34903+ atomic_long_unchecked_t tlb_dropin_fail_upm;
34904+ atomic_long_unchecked_t tlb_dropin_fail_invalid;
34905+ atomic_long_unchecked_t tlb_dropin_fail_range_active;
34906+ atomic_long_unchecked_t tlb_dropin_fail_idle;
34907+ atomic_long_unchecked_t tlb_dropin_fail_fmm;
34908+ atomic_long_unchecked_t tlb_dropin_fail_no_exception;
34909+ atomic_long_unchecked_t tfh_stale_on_fault;
34910+ atomic_long_unchecked_t mmu_invalidate_range;
34911+ atomic_long_unchecked_t mmu_invalidate_page;
34912+ atomic_long_unchecked_t flush_tlb;
34913+ atomic_long_unchecked_t flush_tlb_gru;
34914+ atomic_long_unchecked_t flush_tlb_gru_tgh;
34915+ atomic_long_unchecked_t flush_tlb_gru_zero_asid;
34916
34917- atomic_long_t copy_gpa;
34918- atomic_long_t read_gpa;
34919+ atomic_long_unchecked_t copy_gpa;
34920+ atomic_long_unchecked_t read_gpa;
34921
34922- atomic_long_t mesq_receive;
34923- atomic_long_t mesq_receive_none;
34924- atomic_long_t mesq_send;
34925- atomic_long_t mesq_send_failed;
34926- atomic_long_t mesq_noop;
34927- atomic_long_t mesq_send_unexpected_error;
34928- atomic_long_t mesq_send_lb_overflow;
34929- atomic_long_t mesq_send_qlimit_reached;
34930- atomic_long_t mesq_send_amo_nacked;
34931- atomic_long_t mesq_send_put_nacked;
34932- atomic_long_t mesq_page_overflow;
34933- atomic_long_t mesq_qf_locked;
34934- atomic_long_t mesq_qf_noop_not_full;
34935- atomic_long_t mesq_qf_switch_head_failed;
34936- atomic_long_t mesq_qf_unexpected_error;
34937- atomic_long_t mesq_noop_unexpected_error;
34938- atomic_long_t mesq_noop_lb_overflow;
34939- atomic_long_t mesq_noop_qlimit_reached;
34940- atomic_long_t mesq_noop_amo_nacked;
34941- atomic_long_t mesq_noop_put_nacked;
34942- atomic_long_t mesq_noop_page_overflow;
34943+ atomic_long_unchecked_t mesq_receive;
34944+ atomic_long_unchecked_t mesq_receive_none;
34945+ atomic_long_unchecked_t mesq_send;
34946+ atomic_long_unchecked_t mesq_send_failed;
34947+ atomic_long_unchecked_t mesq_noop;
34948+ atomic_long_unchecked_t mesq_send_unexpected_error;
34949+ atomic_long_unchecked_t mesq_send_lb_overflow;
34950+ atomic_long_unchecked_t mesq_send_qlimit_reached;
34951+ atomic_long_unchecked_t mesq_send_amo_nacked;
34952+ atomic_long_unchecked_t mesq_send_put_nacked;
34953+ atomic_long_unchecked_t mesq_page_overflow;
34954+ atomic_long_unchecked_t mesq_qf_locked;
34955+ atomic_long_unchecked_t mesq_qf_noop_not_full;
34956+ atomic_long_unchecked_t mesq_qf_switch_head_failed;
34957+ atomic_long_unchecked_t mesq_qf_unexpected_error;
34958+ atomic_long_unchecked_t mesq_noop_unexpected_error;
34959+ atomic_long_unchecked_t mesq_noop_lb_overflow;
34960+ atomic_long_unchecked_t mesq_noop_qlimit_reached;
34961+ atomic_long_unchecked_t mesq_noop_amo_nacked;
34962+ atomic_long_unchecked_t mesq_noop_put_nacked;
34963+ atomic_long_unchecked_t mesq_noop_page_overflow;
34964
34965 };
34966
34967@@ -251,8 +251,8 @@ enum mcs_op {cchop_allocate, cchop_start, cchop_interrupt, cchop_interrupt_sync,
34968 tghop_invalidate, mcsop_last};
34969
34970 struct mcs_op_statistic {
34971- atomic_long_t count;
34972- atomic_long_t total;
34973+ atomic_long_unchecked_t count;
34974+ atomic_long_unchecked_t total;
34975 unsigned long max;
34976 };
34977
34978@@ -275,7 +275,7 @@ extern struct mcs_op_statistic mcs_op_statistics[mcsop_last];
34979
34980 #define STAT(id) do { \
34981 if (gru_options & OPT_STATS) \
34982- atomic_long_inc(&gru_stats.id); \
34983+ atomic_long_inc_unchecked(&gru_stats.id); \
34984 } while (0)
34985
34986 #ifdef CONFIG_SGI_GRU_DEBUG
34987diff --git a/drivers/misc/sgi-xp/xp.h b/drivers/misc/sgi-xp/xp.h
34988index c862cd4..0d176fe 100644
34989--- a/drivers/misc/sgi-xp/xp.h
34990+++ b/drivers/misc/sgi-xp/xp.h
34991@@ -288,7 +288,7 @@ struct xpc_interface {
34992 xpc_notify_func, void *);
34993 void (*received) (short, int, void *);
34994 enum xp_retval (*partid_to_nasids) (short, void *);
34995-};
34996+} __no_const;
34997
34998 extern struct xpc_interface xpc_interface;
34999
35000diff --git a/drivers/misc/sgi-xp/xpc.h b/drivers/misc/sgi-xp/xpc.h
35001index b94d5f7..7f494c5 100644
35002--- a/drivers/misc/sgi-xp/xpc.h
35003+++ b/drivers/misc/sgi-xp/xpc.h
35004@@ -835,6 +835,7 @@ struct xpc_arch_operations {
35005 void (*received_payload) (struct xpc_channel *, void *);
35006 void (*notify_senders_of_disconnect) (struct xpc_channel *);
35007 };
35008+typedef struct xpc_arch_operations __no_const xpc_arch_operations_no_const;
35009
35010 /* struct xpc_partition act_state values (for XPC HB) */
35011
35012@@ -876,7 +877,7 @@ extern struct xpc_registration xpc_registrations[];
35013 /* found in xpc_main.c */
35014 extern struct device *xpc_part;
35015 extern struct device *xpc_chan;
35016-extern struct xpc_arch_operations xpc_arch_ops;
35017+extern xpc_arch_operations_no_const xpc_arch_ops;
35018 extern int xpc_disengage_timelimit;
35019 extern int xpc_disengage_timedout;
35020 extern int xpc_activate_IRQ_rcvd;
35021diff --git a/drivers/misc/sgi-xp/xpc_main.c b/drivers/misc/sgi-xp/xpc_main.c
35022index 8d082b4..aa749ae 100644
35023--- a/drivers/misc/sgi-xp/xpc_main.c
35024+++ b/drivers/misc/sgi-xp/xpc_main.c
35025@@ -162,7 +162,7 @@ static struct notifier_block xpc_die_notifier = {
35026 .notifier_call = xpc_system_die,
35027 };
35028
35029-struct xpc_arch_operations xpc_arch_ops;
35030+xpc_arch_operations_no_const xpc_arch_ops;
35031
35032 /*
35033 * Timer function to enforce the timelimit on the partition disengage.
35034diff --git a/drivers/mmc/host/sdhci-pci.c b/drivers/mmc/host/sdhci-pci.c
35035index 504da71..9722d43 100644
35036--- a/drivers/mmc/host/sdhci-pci.c
35037+++ b/drivers/mmc/host/sdhci-pci.c
35038@@ -653,7 +653,7 @@ static const struct sdhci_pci_fixes sdhci_via = {
35039 .probe = via_probe,
35040 };
35041
35042-static const struct pci_device_id pci_ids[] __devinitdata = {
35043+static const struct pci_device_id pci_ids[] __devinitconst = {
35044 {
35045 .vendor = PCI_VENDOR_ID_RICOH,
35046 .device = PCI_DEVICE_ID_RICOH_R5C822,
35047diff --git a/drivers/mtd/devices/doc2000.c b/drivers/mtd/devices/doc2000.c
35048index a4eb8b5..8c0628f 100644
35049--- a/drivers/mtd/devices/doc2000.c
35050+++ b/drivers/mtd/devices/doc2000.c
35051@@ -753,7 +753,7 @@ static int doc_write(struct mtd_info *mtd, loff_t to, size_t len,
35052
35053 /* The ECC will not be calculated correctly if less than 512 is written */
35054 /* DBB-
35055- if (len != 0x200 && eccbuf)
35056+ if (len != 0x200)
35057 printk(KERN_WARNING
35058 "ECC needs a full sector write (adr: %lx size %lx)\n",
35059 (long) to, (long) len);
35060diff --git a/drivers/mtd/nand/denali.c b/drivers/mtd/nand/denali.c
35061index 0650aaf..7718762 100644
35062--- a/drivers/mtd/nand/denali.c
35063+++ b/drivers/mtd/nand/denali.c
35064@@ -26,6 +26,7 @@
35065 #include <linux/pci.h>
35066 #include <linux/mtd/mtd.h>
35067 #include <linux/module.h>
35068+#include <linux/slab.h>
35069
35070 #include "denali.h"
35071
35072diff --git a/drivers/mtd/nftlmount.c b/drivers/mtd/nftlmount.c
35073index 51b9d6a..52af9a7 100644
35074--- a/drivers/mtd/nftlmount.c
35075+++ b/drivers/mtd/nftlmount.c
35076@@ -24,6 +24,7 @@
35077 #include <asm/errno.h>
35078 #include <linux/delay.h>
35079 #include <linux/slab.h>
35080+#include <linux/sched.h>
35081 #include <linux/mtd/mtd.h>
35082 #include <linux/mtd/nand.h>
35083 #include <linux/mtd/nftl.h>
35084diff --git a/drivers/net/bonding/bond_sysfs.c b/drivers/net/bonding/bond_sysfs.c
35085index dc15d24..ef8d2a0 100644
35086--- a/drivers/net/bonding/bond_sysfs.c
35087+++ b/drivers/net/bonding/bond_sysfs.c
35088@@ -1060,7 +1060,7 @@ static ssize_t bonding_store_primary(struct device *d,
35089 goto out;
35090 }
35091
35092- sscanf(buf, "%16s", ifname); /* IFNAMSIZ */
35093+ sscanf(buf, "%15s", ifname); /* IFNAMSIZ */
35094
35095 /* check to see if we are clearing primary */
35096 if (!strlen(ifname) || buf[0] == '\n') {
35097@@ -1237,7 +1237,7 @@ static ssize_t bonding_store_active_slave(struct device *d,
35098 goto out;
35099 }
35100
35101- sscanf(buf, "%16s", ifname); /* IFNAMSIZ */
35102+ sscanf(buf, "%15s", ifname); /* IFNAMSIZ */
35103
35104 /* check to see if we are clearing active */
35105 if (!strlen(ifname) || buf[0] == '\n') {
35106diff --git a/drivers/net/ethernet/atheros/atlx/atl2.c b/drivers/net/ethernet/atheros/atlx/atl2.c
35107index 57d64b8..623dd86 100644
35108--- a/drivers/net/ethernet/atheros/atlx/atl2.c
35109+++ b/drivers/net/ethernet/atheros/atlx/atl2.c
35110@@ -2845,7 +2845,7 @@ static void atl2_force_ps(struct atl2_hw *hw)
35111 */
35112
35113 #define ATL2_PARAM(X, desc) \
35114- static const int __devinitdata X[ATL2_MAX_NIC + 1] = ATL2_PARAM_INIT; \
35115+ static const int __devinitconst X[ATL2_MAX_NIC + 1] = ATL2_PARAM_INIT; \
35116 MODULE_PARM(X, "1-" __MODULE_STRING(ATL2_MAX_NIC) "i"); \
35117 MODULE_PARM_DESC(X, desc);
35118 #else
35119diff --git a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_main.c b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_main.c
35120index 0875ecf..794cdf3 100644
35121--- a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_main.c
35122+++ b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_main.c
35123@@ -3051,9 +3051,8 @@ static void bnx2x_drv_info_ether_stat(struct bnx2x *bp)
35124 struct eth_stats_info *ether_stat =
35125 &bp->slowpath->drv_info_to_mcp.ether_stat;
35126
35127- /* leave last char as NULL */
35128- memcpy(ether_stat->version, DRV_MODULE_VERSION,
35129- ETH_STAT_INFO_VERSION_LEN - 1);
35130+ strlcpy(ether_stat->version, DRV_MODULE_VERSION,
35131+ ETH_STAT_INFO_VERSION_LEN);
35132
35133 bp->sp_objs[0].mac_obj.get_n_elements(bp, &bp->sp_objs[0].mac_obj,
35134 DRV_INFO_ETH_STAT_NUM_MACS_REQUIRED,
35135diff --git a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h
35136index f83e033..8b4f43a 100644
35137--- a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h
35138+++ b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h
35139@@ -486,7 +486,7 @@ struct bnx2x_rx_mode_obj {
35140
35141 int (*wait_comp)(struct bnx2x *bp,
35142 struct bnx2x_rx_mode_ramrod_params *p);
35143-};
35144+} __no_const;
35145
35146 /********************** Set multicast group ***********************************/
35147
35148diff --git a/drivers/net/ethernet/broadcom/tg3.h b/drivers/net/ethernet/broadcom/tg3.h
35149index 6d52cb2..bc95640 100644
35150--- a/drivers/net/ethernet/broadcom/tg3.h
35151+++ b/drivers/net/ethernet/broadcom/tg3.h
35152@@ -140,6 +140,7 @@
35153 #define CHIPREV_ID_5750_A0 0x4000
35154 #define CHIPREV_ID_5750_A1 0x4001
35155 #define CHIPREV_ID_5750_A3 0x4003
35156+#define CHIPREV_ID_5750_C1 0x4201
35157 #define CHIPREV_ID_5750_C2 0x4202
35158 #define CHIPREV_ID_5752_A0_HW 0x5000
35159 #define CHIPREV_ID_5752_A0 0x6000
35160diff --git a/drivers/net/ethernet/chelsio/cxgb3/l2t.h b/drivers/net/ethernet/chelsio/cxgb3/l2t.h
35161index 8cffcdf..aadf043 100644
35162--- a/drivers/net/ethernet/chelsio/cxgb3/l2t.h
35163+++ b/drivers/net/ethernet/chelsio/cxgb3/l2t.h
35164@@ -87,7 +87,7 @@ typedef void (*arp_failure_handler_func)(struct t3cdev * dev,
35165 */
35166 struct l2t_skb_cb {
35167 arp_failure_handler_func arp_failure_handler;
35168-};
35169+} __no_const;
35170
35171 #define L2T_SKB_CB(skb) ((struct l2t_skb_cb *)(skb)->cb)
35172
35173diff --git a/drivers/net/ethernet/dec/tulip/de4x5.c b/drivers/net/ethernet/dec/tulip/de4x5.c
35174index f879e92..726f20f 100644
35175--- a/drivers/net/ethernet/dec/tulip/de4x5.c
35176+++ b/drivers/net/ethernet/dec/tulip/de4x5.c
35177@@ -5388,7 +5388,7 @@ de4x5_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
35178 for (i=0; i<ETH_ALEN; i++) {
35179 tmp.addr[i] = dev->dev_addr[i];
35180 }
35181- if (copy_to_user(ioc->data, tmp.addr, ioc->len)) return -EFAULT;
35182+ if (ioc->len > sizeof tmp.addr || copy_to_user(ioc->data, tmp.addr, ioc->len)) return -EFAULT;
35183 break;
35184
35185 case DE4X5_SET_HWADDR: /* Set the hardware address */
35186@@ -5428,7 +5428,7 @@ de4x5_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
35187 spin_lock_irqsave(&lp->lock, flags);
35188 memcpy(&statbuf, &lp->pktStats, ioc->len);
35189 spin_unlock_irqrestore(&lp->lock, flags);
35190- if (copy_to_user(ioc->data, &statbuf, ioc->len))
35191+ if (ioc->len > sizeof statbuf || copy_to_user(ioc->data, &statbuf, ioc->len))
35192 return -EFAULT;
35193 break;
35194 }
35195diff --git a/drivers/net/ethernet/dec/tulip/eeprom.c b/drivers/net/ethernet/dec/tulip/eeprom.c
35196index ed7d1dc..d426748 100644
35197--- a/drivers/net/ethernet/dec/tulip/eeprom.c
35198+++ b/drivers/net/ethernet/dec/tulip/eeprom.c
35199@@ -79,7 +79,7 @@ static struct eeprom_fixup eeprom_fixups[] __devinitdata = {
35200 {NULL}};
35201
35202
35203-static const char *block_name[] __devinitdata = {
35204+static const char *block_name[] __devinitconst = {
35205 "21140 non-MII",
35206 "21140 MII PHY",
35207 "21142 Serial PHY",
35208diff --git a/drivers/net/ethernet/dec/tulip/uli526x.c b/drivers/net/ethernet/dec/tulip/uli526x.c
35209index 75d45f8..3d9c55b 100644
35210--- a/drivers/net/ethernet/dec/tulip/uli526x.c
35211+++ b/drivers/net/ethernet/dec/tulip/uli526x.c
35212@@ -129,7 +129,7 @@ struct uli526x_board_info {
35213 struct uli_phy_ops {
35214 void (*write)(struct uli526x_board_info *, u8, u8, u16);
35215 u16 (*read)(struct uli526x_board_info *, u8, u8);
35216- } phy;
35217+ } __no_const phy;
35218 struct net_device *next_dev; /* next device */
35219 struct pci_dev *pdev; /* PCI device */
35220 spinlock_t lock;
35221diff --git a/drivers/net/ethernet/dec/tulip/winbond-840.c b/drivers/net/ethernet/dec/tulip/winbond-840.c
35222index 4d1ffca..7c1ec4d 100644
35223--- a/drivers/net/ethernet/dec/tulip/winbond-840.c
35224+++ b/drivers/net/ethernet/dec/tulip/winbond-840.c
35225@@ -236,7 +236,7 @@ struct pci_id_info {
35226 int drv_flags; /* Driver use, intended as capability flags. */
35227 };
35228
35229-static const struct pci_id_info pci_id_tbl[] __devinitdata = {
35230+static const struct pci_id_info pci_id_tbl[] __devinitconst = {
35231 { /* Sometime a Level-One switch card. */
35232 "Winbond W89c840", CanHaveMII | HasBrokenTx | FDXOnNoMII},
35233 { "Winbond W89c840", CanHaveMII | HasBrokenTx},
35234diff --git a/drivers/net/ethernet/dlink/sundance.c b/drivers/net/ethernet/dlink/sundance.c
35235index d7bb52a..3b83588 100644
35236--- a/drivers/net/ethernet/dlink/sundance.c
35237+++ b/drivers/net/ethernet/dlink/sundance.c
35238@@ -218,7 +218,7 @@ enum {
35239 struct pci_id_info {
35240 const char *name;
35241 };
35242-static const struct pci_id_info pci_id_tbl[] __devinitdata = {
35243+static const struct pci_id_info pci_id_tbl[] __devinitconst = {
35244 {"D-Link DFE-550TX FAST Ethernet Adapter"},
35245 {"D-Link DFE-550FX 100Mbps Fiber-optics Adapter"},
35246 {"D-Link DFE-580TX 4 port Server Adapter"},
35247diff --git a/drivers/net/ethernet/emulex/benet/be_main.c b/drivers/net/ethernet/emulex/benet/be_main.c
35248index 78b8aa8..dd6323a 100644
35249--- a/drivers/net/ethernet/emulex/benet/be_main.c
35250+++ b/drivers/net/ethernet/emulex/benet/be_main.c
35251@@ -403,7 +403,7 @@ static void accumulate_16bit_val(u32 *acc, u16 val)
35252
35253 if (wrapped)
35254 newacc += 65536;
35255- ACCESS_ONCE(*acc) = newacc;
35256+ ACCESS_ONCE_RW(*acc) = newacc;
35257 }
35258
35259 void be_parse_stats(struct be_adapter *adapter)
35260diff --git a/drivers/net/ethernet/faraday/ftgmac100.c b/drivers/net/ethernet/faraday/ftgmac100.c
35261index 74d749e..eefb1bd 100644
35262--- a/drivers/net/ethernet/faraday/ftgmac100.c
35263+++ b/drivers/net/ethernet/faraday/ftgmac100.c
35264@@ -31,6 +31,8 @@
35265 #include <linux/netdevice.h>
35266 #include <linux/phy.h>
35267 #include <linux/platform_device.h>
35268+#include <linux/interrupt.h>
35269+#include <linux/irqreturn.h>
35270 #include <net/ip.h>
35271
35272 #include "ftgmac100.h"
35273diff --git a/drivers/net/ethernet/faraday/ftmac100.c b/drivers/net/ethernet/faraday/ftmac100.c
35274index b901a01..1ff32ee 100644
35275--- a/drivers/net/ethernet/faraday/ftmac100.c
35276+++ b/drivers/net/ethernet/faraday/ftmac100.c
35277@@ -31,6 +31,8 @@
35278 #include <linux/module.h>
35279 #include <linux/netdevice.h>
35280 #include <linux/platform_device.h>
35281+#include <linux/interrupt.h>
35282+#include <linux/irqreturn.h>
35283
35284 #include "ftmac100.h"
35285
35286diff --git a/drivers/net/ethernet/fealnx.c b/drivers/net/ethernet/fealnx.c
35287index 9d71c9c..0e4a0ac 100644
35288--- a/drivers/net/ethernet/fealnx.c
35289+++ b/drivers/net/ethernet/fealnx.c
35290@@ -150,7 +150,7 @@ struct chip_info {
35291 int flags;
35292 };
35293
35294-static const struct chip_info skel_netdrv_tbl[] __devinitdata = {
35295+static const struct chip_info skel_netdrv_tbl[] __devinitconst = {
35296 { "100/10M Ethernet PCI Adapter", HAS_MII_XCVR },
35297 { "100/10M Ethernet PCI Adapter", HAS_CHIP_XCVR },
35298 { "1000/100/10M Ethernet PCI Adapter", HAS_MII_XCVR },
35299diff --git a/drivers/net/ethernet/intel/e1000e/hw.h b/drivers/net/ethernet/intel/e1000e/hw.h
35300index ed5b409..ec37828 100644
35301--- a/drivers/net/ethernet/intel/e1000e/hw.h
35302+++ b/drivers/net/ethernet/intel/e1000e/hw.h
35303@@ -797,6 +797,7 @@ struct e1000_mac_operations {
35304 void (*rar_set)(struct e1000_hw *, u8 *, u32);
35305 s32 (*read_mac_addr)(struct e1000_hw *);
35306 };
35307+typedef struct e1000_mac_operations __no_const e1000_mac_operations_no_const;
35308
35309 /*
35310 * When to use various PHY register access functions:
35311@@ -837,6 +838,7 @@ struct e1000_phy_operations {
35312 void (*power_up)(struct e1000_hw *);
35313 void (*power_down)(struct e1000_hw *);
35314 };
35315+typedef struct e1000_phy_operations __no_const e1000_phy_operations_no_const;
35316
35317 /* Function pointers for the NVM. */
35318 struct e1000_nvm_operations {
35319@@ -849,9 +851,10 @@ struct e1000_nvm_operations {
35320 s32 (*validate)(struct e1000_hw *);
35321 s32 (*write)(struct e1000_hw *, u16, u16, u16 *);
35322 };
35323+typedef struct e1000_nvm_operations __no_const e1000_nvm_operations_no_const;
35324
35325 struct e1000_mac_info {
35326- struct e1000_mac_operations ops;
35327+ e1000_mac_operations_no_const ops;
35328 u8 addr[ETH_ALEN];
35329 u8 perm_addr[ETH_ALEN];
35330
35331@@ -892,7 +895,7 @@ struct e1000_mac_info {
35332 };
35333
35334 struct e1000_phy_info {
35335- struct e1000_phy_operations ops;
35336+ e1000_phy_operations_no_const ops;
35337
35338 enum e1000_phy_type type;
35339
35340@@ -926,7 +929,7 @@ struct e1000_phy_info {
35341 };
35342
35343 struct e1000_nvm_info {
35344- struct e1000_nvm_operations ops;
35345+ e1000_nvm_operations_no_const ops;
35346
35347 enum e1000_nvm_type type;
35348 enum e1000_nvm_override override;
35349diff --git a/drivers/net/ethernet/intel/igb/e1000_hw.h b/drivers/net/ethernet/intel/igb/e1000_hw.h
35350index c2a51dc..c2bd262 100644
35351--- a/drivers/net/ethernet/intel/igb/e1000_hw.h
35352+++ b/drivers/net/ethernet/intel/igb/e1000_hw.h
35353@@ -327,6 +327,7 @@ struct e1000_mac_operations {
35354 void (*release_swfw_sync)(struct e1000_hw *, u16);
35355
35356 };
35357+typedef struct e1000_mac_operations __no_const e1000_mac_operations_no_const;
35358
35359 struct e1000_phy_operations {
35360 s32 (*acquire)(struct e1000_hw *);
35361@@ -343,6 +344,7 @@ struct e1000_phy_operations {
35362 s32 (*set_d3_lplu_state)(struct e1000_hw *, bool);
35363 s32 (*write_reg)(struct e1000_hw *, u32, u16);
35364 };
35365+typedef struct e1000_phy_operations __no_const e1000_phy_operations_no_const;
35366
35367 struct e1000_nvm_operations {
35368 s32 (*acquire)(struct e1000_hw *);
35369@@ -353,6 +355,7 @@ struct e1000_nvm_operations {
35370 s32 (*validate)(struct e1000_hw *);
35371 s32 (*valid_led_default)(struct e1000_hw *, u16 *);
35372 };
35373+typedef struct e1000_nvm_operations __no_const e1000_nvm_operations_no_const;
35374
35375 struct e1000_info {
35376 s32 (*get_invariants)(struct e1000_hw *);
35377@@ -364,7 +367,7 @@ struct e1000_info {
35378 extern const struct e1000_info e1000_82575_info;
35379
35380 struct e1000_mac_info {
35381- struct e1000_mac_operations ops;
35382+ e1000_mac_operations_no_const ops;
35383
35384 u8 addr[6];
35385 u8 perm_addr[6];
35386@@ -402,7 +405,7 @@ struct e1000_mac_info {
35387 };
35388
35389 struct e1000_phy_info {
35390- struct e1000_phy_operations ops;
35391+ e1000_phy_operations_no_const ops;
35392
35393 enum e1000_phy_type type;
35394
35395@@ -437,7 +440,7 @@ struct e1000_phy_info {
35396 };
35397
35398 struct e1000_nvm_info {
35399- struct e1000_nvm_operations ops;
35400+ e1000_nvm_operations_no_const ops;
35401 enum e1000_nvm_type type;
35402 enum e1000_nvm_override override;
35403
35404@@ -482,6 +485,7 @@ struct e1000_mbx_operations {
35405 s32 (*check_for_ack)(struct e1000_hw *, u16);
35406 s32 (*check_for_rst)(struct e1000_hw *, u16);
35407 };
35408+typedef struct e1000_mbx_operations __no_const e1000_mbx_operations_no_const;
35409
35410 struct e1000_mbx_stats {
35411 u32 msgs_tx;
35412@@ -493,7 +497,7 @@ struct e1000_mbx_stats {
35413 };
35414
35415 struct e1000_mbx_info {
35416- struct e1000_mbx_operations ops;
35417+ e1000_mbx_operations_no_const ops;
35418 struct e1000_mbx_stats stats;
35419 u32 timeout;
35420 u32 usec_delay;
35421diff --git a/drivers/net/ethernet/intel/igbvf/vf.h b/drivers/net/ethernet/intel/igbvf/vf.h
35422index 57db3c6..aa825fc 100644
35423--- a/drivers/net/ethernet/intel/igbvf/vf.h
35424+++ b/drivers/net/ethernet/intel/igbvf/vf.h
35425@@ -189,9 +189,10 @@ struct e1000_mac_operations {
35426 s32 (*read_mac_addr)(struct e1000_hw *);
35427 s32 (*set_vfta)(struct e1000_hw *, u16, bool);
35428 };
35429+typedef struct e1000_mac_operations __no_const e1000_mac_operations_no_const;
35430
35431 struct e1000_mac_info {
35432- struct e1000_mac_operations ops;
35433+ e1000_mac_operations_no_const ops;
35434 u8 addr[6];
35435 u8 perm_addr[6];
35436
35437@@ -213,6 +214,7 @@ struct e1000_mbx_operations {
35438 s32 (*check_for_ack)(struct e1000_hw *);
35439 s32 (*check_for_rst)(struct e1000_hw *);
35440 };
35441+typedef struct e1000_mbx_operations __no_const e1000_mbx_operations_no_const;
35442
35443 struct e1000_mbx_stats {
35444 u32 msgs_tx;
35445@@ -224,7 +226,7 @@ struct e1000_mbx_stats {
35446 };
35447
35448 struct e1000_mbx_info {
35449- struct e1000_mbx_operations ops;
35450+ e1000_mbx_operations_no_const ops;
35451 struct e1000_mbx_stats stats;
35452 u32 timeout;
35453 u32 usec_delay;
35454diff --git a/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c b/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c
35455index 3456d56..b688d81 100644
35456--- a/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c
35457+++ b/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c
35458@@ -884,7 +884,7 @@ void ixgbe_ptp_start_cyclecounter(struct ixgbe_adapter *adapter)
35459 /* store the new cycle speed */
35460 adapter->cycle_speed = cycle_speed;
35461
35462- ACCESS_ONCE(adapter->base_incval) = incval;
35463+ ACCESS_ONCE_RW(adapter->base_incval) = incval;
35464 smp_mb();
35465
35466 /* grab the ptp lock */
35467diff --git a/drivers/net/ethernet/intel/ixgbe/ixgbe_type.h b/drivers/net/ethernet/intel/ixgbe/ixgbe_type.h
35468index 400f86a..7f2e062 100644
35469--- a/drivers/net/ethernet/intel/ixgbe/ixgbe_type.h
35470+++ b/drivers/net/ethernet/intel/ixgbe/ixgbe_type.h
35471@@ -2799,6 +2799,7 @@ struct ixgbe_eeprom_operations {
35472 s32 (*update_checksum)(struct ixgbe_hw *);
35473 u16 (*calc_checksum)(struct ixgbe_hw *);
35474 };
35475+typedef struct ixgbe_eeprom_operations __no_const ixgbe_eeprom_operations_no_const;
35476
35477 struct ixgbe_mac_operations {
35478 s32 (*init_hw)(struct ixgbe_hw *);
35479@@ -2865,6 +2866,7 @@ struct ixgbe_mac_operations {
35480 s32 (*get_thermal_sensor_data)(struct ixgbe_hw *);
35481 s32 (*init_thermal_sensor_thresh)(struct ixgbe_hw *hw);
35482 };
35483+typedef struct ixgbe_mac_operations __no_const ixgbe_mac_operations_no_const;
35484
35485 struct ixgbe_phy_operations {
35486 s32 (*identify)(struct ixgbe_hw *);
35487@@ -2884,9 +2886,10 @@ struct ixgbe_phy_operations {
35488 s32 (*write_i2c_eeprom)(struct ixgbe_hw *, u8, u8);
35489 s32 (*check_overtemp)(struct ixgbe_hw *);
35490 };
35491+typedef struct ixgbe_phy_operations __no_const ixgbe_phy_operations_no_const;
35492
35493 struct ixgbe_eeprom_info {
35494- struct ixgbe_eeprom_operations ops;
35495+ ixgbe_eeprom_operations_no_const ops;
35496 enum ixgbe_eeprom_type type;
35497 u32 semaphore_delay;
35498 u16 word_size;
35499@@ -2896,7 +2899,7 @@ struct ixgbe_eeprom_info {
35500
35501 #define IXGBE_FLAGS_DOUBLE_RESET_REQUIRED 0x01
35502 struct ixgbe_mac_info {
35503- struct ixgbe_mac_operations ops;
35504+ ixgbe_mac_operations_no_const ops;
35505 enum ixgbe_mac_type type;
35506 u8 addr[ETH_ALEN];
35507 u8 perm_addr[ETH_ALEN];
35508@@ -2926,7 +2929,7 @@ struct ixgbe_mac_info {
35509 };
35510
35511 struct ixgbe_phy_info {
35512- struct ixgbe_phy_operations ops;
35513+ ixgbe_phy_operations_no_const ops;
35514 struct mdio_if_info mdio;
35515 enum ixgbe_phy_type type;
35516 u32 id;
35517@@ -2954,6 +2957,7 @@ struct ixgbe_mbx_operations {
35518 s32 (*check_for_ack)(struct ixgbe_hw *, u16);
35519 s32 (*check_for_rst)(struct ixgbe_hw *, u16);
35520 };
35521+typedef struct ixgbe_mbx_operations __no_const ixgbe_mbx_operations_no_const;
35522
35523 struct ixgbe_mbx_stats {
35524 u32 msgs_tx;
35525@@ -2965,7 +2969,7 @@ struct ixgbe_mbx_stats {
35526 };
35527
35528 struct ixgbe_mbx_info {
35529- struct ixgbe_mbx_operations ops;
35530+ ixgbe_mbx_operations_no_const ops;
35531 struct ixgbe_mbx_stats stats;
35532 u32 timeout;
35533 u32 usec_delay;
35534diff --git a/drivers/net/ethernet/intel/ixgbevf/vf.h b/drivers/net/ethernet/intel/ixgbevf/vf.h
35535index 25c951d..cc7cf33 100644
35536--- a/drivers/net/ethernet/intel/ixgbevf/vf.h
35537+++ b/drivers/net/ethernet/intel/ixgbevf/vf.h
35538@@ -70,6 +70,7 @@ struct ixgbe_mac_operations {
35539 s32 (*clear_vfta)(struct ixgbe_hw *);
35540 s32 (*set_vfta)(struct ixgbe_hw *, u32, u32, bool);
35541 };
35542+typedef struct ixgbe_mac_operations __no_const ixgbe_mac_operations_no_const;
35543
35544 enum ixgbe_mac_type {
35545 ixgbe_mac_unknown = 0,
35546@@ -79,7 +80,7 @@ enum ixgbe_mac_type {
35547 };
35548
35549 struct ixgbe_mac_info {
35550- struct ixgbe_mac_operations ops;
35551+ ixgbe_mac_operations_no_const ops;
35552 u8 addr[6];
35553 u8 perm_addr[6];
35554
35555@@ -103,6 +104,7 @@ struct ixgbe_mbx_operations {
35556 s32 (*check_for_ack)(struct ixgbe_hw *);
35557 s32 (*check_for_rst)(struct ixgbe_hw *);
35558 };
35559+typedef struct ixgbe_mbx_operations __no_const ixgbe_mbx_operations_no_const;
35560
35561 struct ixgbe_mbx_stats {
35562 u32 msgs_tx;
35563@@ -114,7 +116,7 @@ struct ixgbe_mbx_stats {
35564 };
35565
35566 struct ixgbe_mbx_info {
35567- struct ixgbe_mbx_operations ops;
35568+ ixgbe_mbx_operations_no_const ops;
35569 struct ixgbe_mbx_stats stats;
35570 u32 timeout;
35571 u32 udelay;
35572diff --git a/drivers/net/ethernet/neterion/vxge/vxge-config.h b/drivers/net/ethernet/neterion/vxge/vxge-config.h
35573index 9e0c1ee..8471f77 100644
35574--- a/drivers/net/ethernet/neterion/vxge/vxge-config.h
35575+++ b/drivers/net/ethernet/neterion/vxge/vxge-config.h
35576@@ -514,7 +514,7 @@ struct vxge_hw_uld_cbs {
35577 void (*link_down)(struct __vxge_hw_device *devh);
35578 void (*crit_err)(struct __vxge_hw_device *devh,
35579 enum vxge_hw_event type, u64 ext_data);
35580-};
35581+} __no_const;
35582
35583 /*
35584 * struct __vxge_hw_blockpool_entry - Block private data structure
35585diff --git a/drivers/net/ethernet/neterion/vxge/vxge-traffic.h b/drivers/net/ethernet/neterion/vxge/vxge-traffic.h
35586index 4a518a3..936b334 100644
35587--- a/drivers/net/ethernet/neterion/vxge/vxge-traffic.h
35588+++ b/drivers/net/ethernet/neterion/vxge/vxge-traffic.h
35589@@ -2088,7 +2088,7 @@ struct vxge_hw_mempool_cbs {
35590 struct vxge_hw_mempool_dma *dma_object,
35591 u32 index,
35592 u32 is_last);
35593-};
35594+} __no_const;
35595
35596 #define VXGE_HW_VIRTUAL_PATH_HANDLE(vpath) \
35597 ((struct __vxge_hw_vpath_handle *)(vpath)->vpath_handles.next)
35598diff --git a/drivers/net/ethernet/realtek/r8169.c b/drivers/net/ethernet/realtek/r8169.c
35599index b47d5b3..273a516 100644
35600--- a/drivers/net/ethernet/realtek/r8169.c
35601+++ b/drivers/net/ethernet/realtek/r8169.c
35602@@ -745,22 +745,22 @@ struct rtl8169_private {
35603 struct mdio_ops {
35604 void (*write)(struct rtl8169_private *, int, int);
35605 int (*read)(struct rtl8169_private *, int);
35606- } mdio_ops;
35607+ } __no_const mdio_ops;
35608
35609 struct pll_power_ops {
35610 void (*down)(struct rtl8169_private *);
35611 void (*up)(struct rtl8169_private *);
35612- } pll_power_ops;
35613+ } __no_const pll_power_ops;
35614
35615 struct jumbo_ops {
35616 void (*enable)(struct rtl8169_private *);
35617 void (*disable)(struct rtl8169_private *);
35618- } jumbo_ops;
35619+ } __no_const jumbo_ops;
35620
35621 struct csi_ops {
35622 void (*write)(struct rtl8169_private *, int, int);
35623 u32 (*read)(struct rtl8169_private *, int);
35624- } csi_ops;
35625+ } __no_const csi_ops;
35626
35627 int (*set_speed)(struct net_device *, u8 aneg, u16 sp, u8 dpx, u32 adv);
35628 int (*get_settings)(struct net_device *, struct ethtool_cmd *);
35629diff --git a/drivers/net/ethernet/sis/sis190.c b/drivers/net/ethernet/sis/sis190.c
35630index 4613591..d816601 100644
35631--- a/drivers/net/ethernet/sis/sis190.c
35632+++ b/drivers/net/ethernet/sis/sis190.c
35633@@ -1618,7 +1618,7 @@ static int __devinit sis190_get_mac_addr_from_eeprom(struct pci_dev *pdev,
35634 static int __devinit sis190_get_mac_addr_from_apc(struct pci_dev *pdev,
35635 struct net_device *dev)
35636 {
35637- static const u16 __devinitdata ids[] = { 0x0965, 0x0966, 0x0968 };
35638+ static const u16 __devinitconst ids[] = { 0x0965, 0x0966, 0x0968 };
35639 struct sis190_private *tp = netdev_priv(dev);
35640 struct pci_dev *isa_bridge;
35641 u8 reg, tmp8;
35642diff --git a/drivers/net/ethernet/stmicro/stmmac/mmc_core.c b/drivers/net/ethernet/stmicro/stmmac/mmc_core.c
35643index 0c74a70..3bc6f68 100644
35644--- a/drivers/net/ethernet/stmicro/stmmac/mmc_core.c
35645+++ b/drivers/net/ethernet/stmicro/stmmac/mmc_core.c
35646@@ -140,8 +140,8 @@ void dwmac_mmc_ctrl(void __iomem *ioaddr, unsigned int mode)
35647
35648 writel(value, ioaddr + MMC_CNTRL);
35649
35650- pr_debug("stmmac: MMC ctrl register (offset 0x%x): 0x%08x\n",
35651- MMC_CNTRL, value);
35652+// pr_debug("stmmac: MMC ctrl register (offset 0x%x): 0x%08x\n",
35653+// MMC_CNTRL, value);
35654 }
35655
35656 /* To mask all all interrupts.*/
35657diff --git a/drivers/net/hyperv/hyperv_net.h b/drivers/net/hyperv/hyperv_net.h
35658index 95ceb35..318fc12 100644
35659--- a/drivers/net/hyperv/hyperv_net.h
35660+++ b/drivers/net/hyperv/hyperv_net.h
35661@@ -99,7 +99,7 @@ struct rndis_device {
35662
35663 enum rndis_device_state state;
35664 bool link_state;
35665- atomic_t new_req_id;
35666+ atomic_unchecked_t new_req_id;
35667
35668 spinlock_t request_lock;
35669 struct list_head req_list;
35670diff --git a/drivers/net/hyperv/rndis_filter.c b/drivers/net/hyperv/rndis_filter.c
35671index 1e88a10..1b01736 100644
35672--- a/drivers/net/hyperv/rndis_filter.c
35673+++ b/drivers/net/hyperv/rndis_filter.c
35674@@ -99,7 +99,7 @@ static struct rndis_request *get_rndis_request(struct rndis_device *dev,
35675 * template
35676 */
35677 set = &rndis_msg->msg.set_req;
35678- set->req_id = atomic_inc_return(&dev->new_req_id);
35679+ set->req_id = atomic_inc_return_unchecked(&dev->new_req_id);
35680
35681 /* Add to the request list */
35682 spin_lock_irqsave(&dev->request_lock, flags);
35683@@ -730,7 +730,7 @@ static void rndis_filter_halt_device(struct rndis_device *dev)
35684
35685 /* Setup the rndis set */
35686 halt = &request->request_msg.msg.halt_req;
35687- halt->req_id = atomic_inc_return(&dev->new_req_id);
35688+ halt->req_id = atomic_inc_return_unchecked(&dev->new_req_id);
35689
35690 /* Ignore return since this msg is optional. */
35691 rndis_filter_send_request(dev, request);
35692diff --git a/drivers/net/phy/mdio-bitbang.c b/drivers/net/phy/mdio-bitbang.c
35693index daec9b0..6428fcb 100644
35694--- a/drivers/net/phy/mdio-bitbang.c
35695+++ b/drivers/net/phy/mdio-bitbang.c
35696@@ -234,6 +234,7 @@ void free_mdio_bitbang(struct mii_bus *bus)
35697 struct mdiobb_ctrl *ctrl = bus->priv;
35698
35699 module_put(ctrl->ops->owner);
35700+ mdiobus_unregister(bus);
35701 mdiobus_free(bus);
35702 }
35703 EXPORT_SYMBOL(free_mdio_bitbang);
35704diff --git a/drivers/net/ppp/ppp_generic.c b/drivers/net/ppp/ppp_generic.c
35705index 5c05572..389610b 100644
35706--- a/drivers/net/ppp/ppp_generic.c
35707+++ b/drivers/net/ppp/ppp_generic.c
35708@@ -986,7 +986,6 @@ ppp_net_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
35709 void __user *addr = (void __user *) ifr->ifr_ifru.ifru_data;
35710 struct ppp_stats stats;
35711 struct ppp_comp_stats cstats;
35712- char *vers;
35713
35714 switch (cmd) {
35715 case SIOCGPPPSTATS:
35716@@ -1008,8 +1007,7 @@ ppp_net_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
35717 break;
35718
35719 case SIOCGPPPVER:
35720- vers = PPP_VERSION;
35721- if (copy_to_user(addr, vers, strlen(vers) + 1))
35722+ if (copy_to_user(addr, PPP_VERSION, sizeof(PPP_VERSION)))
35723 break;
35724 err = 0;
35725 break;
35726diff --git a/drivers/net/tun.c b/drivers/net/tun.c
35727index 3a16d4f..a311cec 100644
35728--- a/drivers/net/tun.c
35729+++ b/drivers/net/tun.c
35730@@ -1367,7 +1367,7 @@ static int set_offload(struct tun_struct *tun, unsigned long arg)
35731 }
35732
35733 static long __tun_chr_ioctl(struct file *file, unsigned int cmd,
35734- unsigned long arg, int ifreq_len)
35735+ unsigned long arg, size_t ifreq_len)
35736 {
35737 struct tun_file *tfile = file->private_data;
35738 struct tun_struct *tun;
35739@@ -1378,6 +1378,9 @@ static long __tun_chr_ioctl(struct file *file, unsigned int cmd,
35740 int vnet_hdr_sz;
35741 int ret;
35742
35743+ if (ifreq_len > sizeof ifr)
35744+ return -EFAULT;
35745+
35746 if (cmd == TUNSETIFF || _IOC_TYPE(cmd) == 0x89) {
35747 if (copy_from_user(&ifr, argp, ifreq_len))
35748 return -EFAULT;
35749diff --git a/drivers/net/usb/hso.c b/drivers/net/usb/hso.c
35750index 62f30b4..ff99dfd 100644
35751--- a/drivers/net/usb/hso.c
35752+++ b/drivers/net/usb/hso.c
35753@@ -71,7 +71,7 @@
35754 #include <asm/byteorder.h>
35755 #include <linux/serial_core.h>
35756 #include <linux/serial.h>
35757-
35758+#include <asm/local.h>
35759
35760 #define MOD_AUTHOR "Option Wireless"
35761 #define MOD_DESCRIPTION "USB High Speed Option driver"
35762@@ -1182,7 +1182,7 @@ static void put_rxbuf_data_and_resubmit_ctrl_urb(struct hso_serial *serial)
35763 struct urb *urb;
35764
35765 urb = serial->rx_urb[0];
35766- if (serial->port.count > 0) {
35767+ if (atomic_read(&serial->port.count) > 0) {
35768 count = put_rxbuf_data(urb, serial);
35769 if (count == -1)
35770 return;
35771@@ -1218,7 +1218,7 @@ static void hso_std_serial_read_bulk_callback(struct urb *urb)
35772 DUMP1(urb->transfer_buffer, urb->actual_length);
35773
35774 /* Anyone listening? */
35775- if (serial->port.count == 0)
35776+ if (atomic_read(&serial->port.count) == 0)
35777 return;
35778
35779 if (status == 0) {
35780@@ -1300,8 +1300,7 @@ static int hso_serial_open(struct tty_struct *tty, struct file *filp)
35781 tty_port_tty_set(&serial->port, tty);
35782
35783 /* check for port already opened, if not set the termios */
35784- serial->port.count++;
35785- if (serial->port.count == 1) {
35786+ if (atomic_inc_return(&serial->port.count) == 1) {
35787 serial->rx_state = RX_IDLE;
35788 /* Force default termio settings */
35789 _hso_serial_set_termios(tty, NULL);
35790@@ -1313,7 +1312,7 @@ static int hso_serial_open(struct tty_struct *tty, struct file *filp)
35791 result = hso_start_serial_device(serial->parent, GFP_KERNEL);
35792 if (result) {
35793 hso_stop_serial_device(serial->parent);
35794- serial->port.count--;
35795+ atomic_dec(&serial->port.count);
35796 kref_put(&serial->parent->ref, hso_serial_ref_free);
35797 }
35798 } else {
35799@@ -1350,10 +1349,10 @@ static void hso_serial_close(struct tty_struct *tty, struct file *filp)
35800
35801 /* reset the rts and dtr */
35802 /* do the actual close */
35803- serial->port.count--;
35804+ atomic_dec(&serial->port.count);
35805
35806- if (serial->port.count <= 0) {
35807- serial->port.count = 0;
35808+ if (atomic_read(&serial->port.count) <= 0) {
35809+ atomic_set(&serial->port.count, 0);
35810 tty_port_tty_set(&serial->port, NULL);
35811 if (!usb_gone)
35812 hso_stop_serial_device(serial->parent);
35813@@ -1429,7 +1428,7 @@ static void hso_serial_set_termios(struct tty_struct *tty, struct ktermios *old)
35814
35815 /* the actual setup */
35816 spin_lock_irqsave(&serial->serial_lock, flags);
35817- if (serial->port.count)
35818+ if (atomic_read(&serial->port.count))
35819 _hso_serial_set_termios(tty, old);
35820 else
35821 tty->termios = old;
35822@@ -1888,7 +1887,7 @@ static void intr_callback(struct urb *urb)
35823 D1("Pending read interrupt on port %d\n", i);
35824 spin_lock(&serial->serial_lock);
35825 if (serial->rx_state == RX_IDLE &&
35826- serial->port.count > 0) {
35827+ atomic_read(&serial->port.count) > 0) {
35828 /* Setup and send a ctrl req read on
35829 * port i */
35830 if (!serial->rx_urb_filled[0]) {
35831@@ -3079,7 +3078,7 @@ static int hso_resume(struct usb_interface *iface)
35832 /* Start all serial ports */
35833 for (i = 0; i < HSO_SERIAL_TTY_MINORS; i++) {
35834 if (serial_table[i] && (serial_table[i]->interface == iface)) {
35835- if (dev2ser(serial_table[i])->port.count) {
35836+ if (atomic_read(&dev2ser(serial_table[i])->port.count)) {
35837 result =
35838 hso_start_serial_device(serial_table[i], GFP_NOIO);
35839 hso_kick_transmit(dev2ser(serial_table[i]));
35840diff --git a/drivers/net/wireless/ath/ath.h b/drivers/net/wireless/ath/ath.h
35841index 6169fbd..40e8422 100644
35842--- a/drivers/net/wireless/ath/ath.h
35843+++ b/drivers/net/wireless/ath/ath.h
35844@@ -119,6 +119,7 @@ struct ath_ops {
35845 void (*write_flush) (void *);
35846 u32 (*rmw)(void *, u32 reg_offset, u32 set, u32 clr);
35847 };
35848+typedef struct ath_ops __no_const ath_ops_no_const;
35849
35850 struct ath_common;
35851 struct ath_bus_ops;
35852diff --git a/drivers/net/wireless/ath/ath5k/base.c b/drivers/net/wireless/ath/ath5k/base.c
35853index 2aab20e..b761ef8 100644
35854--- a/drivers/net/wireless/ath/ath5k/base.c
35855+++ b/drivers/net/wireless/ath/ath5k/base.c
35856@@ -1803,7 +1803,7 @@ ath5k_beacon_update(struct ieee80211_hw *hw, struct ieee80211_vif *vif)
35857 {
35858 int ret;
35859 struct ath5k_hw *ah = hw->priv;
35860- struct ath5k_vif *avf = (void *)vif->drv_priv;
35861+ struct ath5k_vif *avf;
35862 struct sk_buff *skb;
35863
35864 if (WARN_ON(!vif)) {
35865@@ -1818,6 +1818,7 @@ ath5k_beacon_update(struct ieee80211_hw *hw, struct ieee80211_vif *vif)
35866 goto out;
35867 }
35868
35869+ avf = (void *)vif->drv_priv;
35870 ath5k_txbuf_free_skb(ah, avf->bbuf);
35871 avf->bbuf->skb = skb;
35872 ret = ath5k_beacon_setup(ah, avf->bbuf);
35873diff --git a/drivers/net/wireless/ath/ath9k/ar9002_mac.c b/drivers/net/wireless/ath/ath9k/ar9002_mac.c
35874index 8d78253..bebbb68 100644
35875--- a/drivers/net/wireless/ath/ath9k/ar9002_mac.c
35876+++ b/drivers/net/wireless/ath/ath9k/ar9002_mac.c
35877@@ -184,8 +184,8 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
35878 ads->ds_txstatus6 = ads->ds_txstatus7 = 0;
35879 ads->ds_txstatus8 = ads->ds_txstatus9 = 0;
35880
35881- ACCESS_ONCE(ads->ds_link) = i->link;
35882- ACCESS_ONCE(ads->ds_data) = i->buf_addr[0];
35883+ ACCESS_ONCE_RW(ads->ds_link) = i->link;
35884+ ACCESS_ONCE_RW(ads->ds_data) = i->buf_addr[0];
35885
35886 ctl1 = i->buf_len[0] | (i->is_last ? 0 : AR_TxMore);
35887 ctl6 = SM(i->keytype, AR_EncrType);
35888@@ -199,26 +199,26 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
35889
35890 if ((i->is_first || i->is_last) &&
35891 i->aggr != AGGR_BUF_MIDDLE && i->aggr != AGGR_BUF_LAST) {
35892- ACCESS_ONCE(ads->ds_ctl2) = set11nTries(i->rates, 0)
35893+ ACCESS_ONCE_RW(ads->ds_ctl2) = set11nTries(i->rates, 0)
35894 | set11nTries(i->rates, 1)
35895 | set11nTries(i->rates, 2)
35896 | set11nTries(i->rates, 3)
35897 | (i->dur_update ? AR_DurUpdateEna : 0)
35898 | SM(0, AR_BurstDur);
35899
35900- ACCESS_ONCE(ads->ds_ctl3) = set11nRate(i->rates, 0)
35901+ ACCESS_ONCE_RW(ads->ds_ctl3) = set11nRate(i->rates, 0)
35902 | set11nRate(i->rates, 1)
35903 | set11nRate(i->rates, 2)
35904 | set11nRate(i->rates, 3);
35905 } else {
35906- ACCESS_ONCE(ads->ds_ctl2) = 0;
35907- ACCESS_ONCE(ads->ds_ctl3) = 0;
35908+ ACCESS_ONCE_RW(ads->ds_ctl2) = 0;
35909+ ACCESS_ONCE_RW(ads->ds_ctl3) = 0;
35910 }
35911
35912 if (!i->is_first) {
35913- ACCESS_ONCE(ads->ds_ctl0) = 0;
35914- ACCESS_ONCE(ads->ds_ctl1) = ctl1;
35915- ACCESS_ONCE(ads->ds_ctl6) = ctl6;
35916+ ACCESS_ONCE_RW(ads->ds_ctl0) = 0;
35917+ ACCESS_ONCE_RW(ads->ds_ctl1) = ctl1;
35918+ ACCESS_ONCE_RW(ads->ds_ctl6) = ctl6;
35919 return;
35920 }
35921
35922@@ -243,7 +243,7 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
35923 break;
35924 }
35925
35926- ACCESS_ONCE(ads->ds_ctl0) = (i->pkt_len & AR_FrameLen)
35927+ ACCESS_ONCE_RW(ads->ds_ctl0) = (i->pkt_len & AR_FrameLen)
35928 | (i->flags & ATH9K_TXDESC_VMF ? AR_VirtMoreFrag : 0)
35929 | SM(i->txpower, AR_XmitPower)
35930 | (i->flags & ATH9K_TXDESC_VEOL ? AR_VEOL : 0)
35931@@ -253,19 +253,19 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
35932 | (i->flags & ATH9K_TXDESC_RTSENA ? AR_RTSEnable :
35933 (i->flags & ATH9K_TXDESC_CTSENA ? AR_CTSEnable : 0));
35934
35935- ACCESS_ONCE(ads->ds_ctl1) = ctl1;
35936- ACCESS_ONCE(ads->ds_ctl6) = ctl6;
35937+ ACCESS_ONCE_RW(ads->ds_ctl1) = ctl1;
35938+ ACCESS_ONCE_RW(ads->ds_ctl6) = ctl6;
35939
35940 if (i->aggr == AGGR_BUF_MIDDLE || i->aggr == AGGR_BUF_LAST)
35941 return;
35942
35943- ACCESS_ONCE(ads->ds_ctl4) = set11nPktDurRTSCTS(i->rates, 0)
35944+ ACCESS_ONCE_RW(ads->ds_ctl4) = set11nPktDurRTSCTS(i->rates, 0)
35945 | set11nPktDurRTSCTS(i->rates, 1);
35946
35947- ACCESS_ONCE(ads->ds_ctl5) = set11nPktDurRTSCTS(i->rates, 2)
35948+ ACCESS_ONCE_RW(ads->ds_ctl5) = set11nPktDurRTSCTS(i->rates, 2)
35949 | set11nPktDurRTSCTS(i->rates, 3);
35950
35951- ACCESS_ONCE(ads->ds_ctl7) = set11nRateFlags(i->rates, 0)
35952+ ACCESS_ONCE_RW(ads->ds_ctl7) = set11nRateFlags(i->rates, 0)
35953 | set11nRateFlags(i->rates, 1)
35954 | set11nRateFlags(i->rates, 2)
35955 | set11nRateFlags(i->rates, 3)
35956diff --git a/drivers/net/wireless/ath/ath9k/ar9003_mac.c b/drivers/net/wireless/ath/ath9k/ar9003_mac.c
35957index 78816b8..1fcdfae 100644
35958--- a/drivers/net/wireless/ath/ath9k/ar9003_mac.c
35959+++ b/drivers/net/wireless/ath/ath9k/ar9003_mac.c
35960@@ -39,47 +39,47 @@ ar9003_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
35961 (i->qcu << AR_TxQcuNum_S) | desc_len;
35962
35963 checksum += val;
35964- ACCESS_ONCE(ads->info) = val;
35965+ ACCESS_ONCE_RW(ads->info) = val;
35966
35967 checksum += i->link;
35968- ACCESS_ONCE(ads->link) = i->link;
35969+ ACCESS_ONCE_RW(ads->link) = i->link;
35970
35971 checksum += i->buf_addr[0];
35972- ACCESS_ONCE(ads->data0) = i->buf_addr[0];
35973+ ACCESS_ONCE_RW(ads->data0) = i->buf_addr[0];
35974 checksum += i->buf_addr[1];
35975- ACCESS_ONCE(ads->data1) = i->buf_addr[1];
35976+ ACCESS_ONCE_RW(ads->data1) = i->buf_addr[1];
35977 checksum += i->buf_addr[2];
35978- ACCESS_ONCE(ads->data2) = i->buf_addr[2];
35979+ ACCESS_ONCE_RW(ads->data2) = i->buf_addr[2];
35980 checksum += i->buf_addr[3];
35981- ACCESS_ONCE(ads->data3) = i->buf_addr[3];
35982+ ACCESS_ONCE_RW(ads->data3) = i->buf_addr[3];
35983
35984 checksum += (val = (i->buf_len[0] << AR_BufLen_S) & AR_BufLen);
35985- ACCESS_ONCE(ads->ctl3) = val;
35986+ ACCESS_ONCE_RW(ads->ctl3) = val;
35987 checksum += (val = (i->buf_len[1] << AR_BufLen_S) & AR_BufLen);
35988- ACCESS_ONCE(ads->ctl5) = val;
35989+ ACCESS_ONCE_RW(ads->ctl5) = val;
35990 checksum += (val = (i->buf_len[2] << AR_BufLen_S) & AR_BufLen);
35991- ACCESS_ONCE(ads->ctl7) = val;
35992+ ACCESS_ONCE_RW(ads->ctl7) = val;
35993 checksum += (val = (i->buf_len[3] << AR_BufLen_S) & AR_BufLen);
35994- ACCESS_ONCE(ads->ctl9) = val;
35995+ ACCESS_ONCE_RW(ads->ctl9) = val;
35996
35997 checksum = (u16) (((checksum & 0xffff) + (checksum >> 16)) & 0xffff);
35998- ACCESS_ONCE(ads->ctl10) = checksum;
35999+ ACCESS_ONCE_RW(ads->ctl10) = checksum;
36000
36001 if (i->is_first || i->is_last) {
36002- ACCESS_ONCE(ads->ctl13) = set11nTries(i->rates, 0)
36003+ ACCESS_ONCE_RW(ads->ctl13) = set11nTries(i->rates, 0)
36004 | set11nTries(i->rates, 1)
36005 | set11nTries(i->rates, 2)
36006 | set11nTries(i->rates, 3)
36007 | (i->dur_update ? AR_DurUpdateEna : 0)
36008 | SM(0, AR_BurstDur);
36009
36010- ACCESS_ONCE(ads->ctl14) = set11nRate(i->rates, 0)
36011+ ACCESS_ONCE_RW(ads->ctl14) = set11nRate(i->rates, 0)
36012 | set11nRate(i->rates, 1)
36013 | set11nRate(i->rates, 2)
36014 | set11nRate(i->rates, 3);
36015 } else {
36016- ACCESS_ONCE(ads->ctl13) = 0;
36017- ACCESS_ONCE(ads->ctl14) = 0;
36018+ ACCESS_ONCE_RW(ads->ctl13) = 0;
36019+ ACCESS_ONCE_RW(ads->ctl14) = 0;
36020 }
36021
36022 ads->ctl20 = 0;
36023@@ -89,17 +89,17 @@ ar9003_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
36024
36025 ctl17 = SM(i->keytype, AR_EncrType);
36026 if (!i->is_first) {
36027- ACCESS_ONCE(ads->ctl11) = 0;
36028- ACCESS_ONCE(ads->ctl12) = i->is_last ? 0 : AR_TxMore;
36029- ACCESS_ONCE(ads->ctl15) = 0;
36030- ACCESS_ONCE(ads->ctl16) = 0;
36031- ACCESS_ONCE(ads->ctl17) = ctl17;
36032- ACCESS_ONCE(ads->ctl18) = 0;
36033- ACCESS_ONCE(ads->ctl19) = 0;
36034+ ACCESS_ONCE_RW(ads->ctl11) = 0;
36035+ ACCESS_ONCE_RW(ads->ctl12) = i->is_last ? 0 : AR_TxMore;
36036+ ACCESS_ONCE_RW(ads->ctl15) = 0;
36037+ ACCESS_ONCE_RW(ads->ctl16) = 0;
36038+ ACCESS_ONCE_RW(ads->ctl17) = ctl17;
36039+ ACCESS_ONCE_RW(ads->ctl18) = 0;
36040+ ACCESS_ONCE_RW(ads->ctl19) = 0;
36041 return;
36042 }
36043
36044- ACCESS_ONCE(ads->ctl11) = (i->pkt_len & AR_FrameLen)
36045+ ACCESS_ONCE_RW(ads->ctl11) = (i->pkt_len & AR_FrameLen)
36046 | (i->flags & ATH9K_TXDESC_VMF ? AR_VirtMoreFrag : 0)
36047 | SM(i->txpower, AR_XmitPower)
36048 | (i->flags & ATH9K_TXDESC_VEOL ? AR_VEOL : 0)
36049@@ -135,22 +135,22 @@ ar9003_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
36050 val = (i->flags & ATH9K_TXDESC_PAPRD) >> ATH9K_TXDESC_PAPRD_S;
36051 ctl12 |= SM(val, AR_PAPRDChainMask);
36052
36053- ACCESS_ONCE(ads->ctl12) = ctl12;
36054- ACCESS_ONCE(ads->ctl17) = ctl17;
36055+ ACCESS_ONCE_RW(ads->ctl12) = ctl12;
36056+ ACCESS_ONCE_RW(ads->ctl17) = ctl17;
36057
36058- ACCESS_ONCE(ads->ctl15) = set11nPktDurRTSCTS(i->rates, 0)
36059+ ACCESS_ONCE_RW(ads->ctl15) = set11nPktDurRTSCTS(i->rates, 0)
36060 | set11nPktDurRTSCTS(i->rates, 1);
36061
36062- ACCESS_ONCE(ads->ctl16) = set11nPktDurRTSCTS(i->rates, 2)
36063+ ACCESS_ONCE_RW(ads->ctl16) = set11nPktDurRTSCTS(i->rates, 2)
36064 | set11nPktDurRTSCTS(i->rates, 3);
36065
36066- ACCESS_ONCE(ads->ctl18) = set11nRateFlags(i->rates, 0)
36067+ ACCESS_ONCE_RW(ads->ctl18) = set11nRateFlags(i->rates, 0)
36068 | set11nRateFlags(i->rates, 1)
36069 | set11nRateFlags(i->rates, 2)
36070 | set11nRateFlags(i->rates, 3)
36071 | SM(i->rtscts_rate, AR_RTSCTSRate);
36072
36073- ACCESS_ONCE(ads->ctl19) = AR_Not_Sounding;
36074+ ACCESS_ONCE_RW(ads->ctl19) = AR_Not_Sounding;
36075 }
36076
36077 static u16 ar9003_calc_ptr_chksum(struct ar9003_txc *ads)
36078diff --git a/drivers/net/wireless/ath/ath9k/hw.h b/drivers/net/wireless/ath/ath9k/hw.h
36079index de6968f..29ac4c1 100644
36080--- a/drivers/net/wireless/ath/ath9k/hw.h
36081+++ b/drivers/net/wireless/ath/ath9k/hw.h
36082@@ -656,7 +656,7 @@ struct ath_hw_private_ops {
36083
36084 /* ANI */
36085 void (*ani_cache_ini_regs)(struct ath_hw *ah);
36086-};
36087+} __no_const;
36088
36089 /**
36090 * struct ath_hw_ops - callbacks used by hardware code and driver code
36091@@ -686,7 +686,7 @@ struct ath_hw_ops {
36092 void (*antdiv_comb_conf_set)(struct ath_hw *ah,
36093 struct ath_hw_antcomb_conf *antconf);
36094
36095-};
36096+} __no_const;
36097
36098 struct ath_nf_limits {
36099 s16 max;
36100@@ -706,7 +706,7 @@ enum ath_cal_list {
36101 #define AH_FASTCC 0x4
36102
36103 struct ath_hw {
36104- struct ath_ops reg_ops;
36105+ ath_ops_no_const reg_ops;
36106
36107 struct ieee80211_hw *hw;
36108 struct ath_common common;
36109diff --git a/drivers/net/wireless/brcm80211/brcmsmac/phy/phy_int.h b/drivers/net/wireless/brcm80211/brcmsmac/phy/phy_int.h
36110index af00e2c..ab04d34 100644
36111--- a/drivers/net/wireless/brcm80211/brcmsmac/phy/phy_int.h
36112+++ b/drivers/net/wireless/brcm80211/brcmsmac/phy/phy_int.h
36113@@ -545,7 +545,7 @@ struct phy_func_ptr {
36114 void (*carrsuppr)(struct brcms_phy *);
36115 s32 (*rxsigpwr)(struct brcms_phy *, s32);
36116 void (*detach)(struct brcms_phy *);
36117-};
36118+} __no_const;
36119
36120 struct brcms_phy {
36121 struct brcms_phy_pub pubpi_ro;
36122diff --git a/drivers/net/wireless/iwlegacy/3945-mac.c b/drivers/net/wireless/iwlegacy/3945-mac.c
36123index faec404..a5277f1 100644
36124--- a/drivers/net/wireless/iwlegacy/3945-mac.c
36125+++ b/drivers/net/wireless/iwlegacy/3945-mac.c
36126@@ -3611,7 +3611,9 @@ il3945_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
36127 */
36128 if (il3945_mod_params.disable_hw_scan) {
36129 D_INFO("Disabling hw_scan\n");
36130- il3945_mac_ops.hw_scan = NULL;
36131+ pax_open_kernel();
36132+ *(void **)&il3945_mac_ops.hw_scan = NULL;
36133+ pax_close_kernel();
36134 }
36135
36136 D_INFO("*** LOAD DRIVER ***\n");
36137diff --git a/drivers/net/wireless/iwlwifi/dvm/debugfs.c b/drivers/net/wireless/iwlwifi/dvm/debugfs.c
36138index a47b306..297daf2 100644
36139--- a/drivers/net/wireless/iwlwifi/dvm/debugfs.c
36140+++ b/drivers/net/wireless/iwlwifi/dvm/debugfs.c
36141@@ -203,7 +203,7 @@ static ssize_t iwl_dbgfs_sram_write(struct file *file,
36142 {
36143 struct iwl_priv *priv = file->private_data;
36144 char buf[64];
36145- int buf_size;
36146+ size_t buf_size;
36147 u32 offset, len;
36148
36149 memset(buf, 0, sizeof(buf));
36150@@ -473,7 +473,7 @@ static ssize_t iwl_dbgfs_rx_handlers_write(struct file *file,
36151 struct iwl_priv *priv = file->private_data;
36152
36153 char buf[8];
36154- int buf_size;
36155+ size_t buf_size;
36156 u32 reset_flag;
36157
36158 memset(buf, 0, sizeof(buf));
36159@@ -554,7 +554,7 @@ static ssize_t iwl_dbgfs_disable_ht40_write(struct file *file,
36160 {
36161 struct iwl_priv *priv = file->private_data;
36162 char buf[8];
36163- int buf_size;
36164+ size_t buf_size;
36165 int ht40;
36166
36167 memset(buf, 0, sizeof(buf));
36168@@ -606,7 +606,7 @@ static ssize_t iwl_dbgfs_sleep_level_override_write(struct file *file,
36169 {
36170 struct iwl_priv *priv = file->private_data;
36171 char buf[8];
36172- int buf_size;
36173+ size_t buf_size;
36174 int value;
36175
36176 memset(buf, 0, sizeof(buf));
36177@@ -1871,7 +1871,7 @@ static ssize_t iwl_dbgfs_clear_ucode_statistics_write(struct file *file,
36178 {
36179 struct iwl_priv *priv = file->private_data;
36180 char buf[8];
36181- int buf_size;
36182+ size_t buf_size;
36183 int clear;
36184
36185 memset(buf, 0, sizeof(buf));
36186@@ -1916,7 +1916,7 @@ static ssize_t iwl_dbgfs_ucode_tracing_write(struct file *file,
36187 {
36188 struct iwl_priv *priv = file->private_data;
36189 char buf[8];
36190- int buf_size;
36191+ size_t buf_size;
36192 int trace;
36193
36194 memset(buf, 0, sizeof(buf));
36195@@ -1987,7 +1987,7 @@ static ssize_t iwl_dbgfs_missed_beacon_write(struct file *file,
36196 {
36197 struct iwl_priv *priv = file->private_data;
36198 char buf[8];
36199- int buf_size;
36200+ size_t buf_size;
36201 int missed;
36202
36203 memset(buf, 0, sizeof(buf));
36204@@ -2028,7 +2028,7 @@ static ssize_t iwl_dbgfs_plcp_delta_write(struct file *file,
36205
36206 struct iwl_priv *priv = file->private_data;
36207 char buf[8];
36208- int buf_size;
36209+ size_t buf_size;
36210 int plcp;
36211
36212 memset(buf, 0, sizeof(buf));
36213@@ -2088,7 +2088,7 @@ static ssize_t iwl_dbgfs_txfifo_flush_write(struct file *file,
36214
36215 struct iwl_priv *priv = file->private_data;
36216 char buf[8];
36217- int buf_size;
36218+ size_t buf_size;
36219 int flush;
36220
36221 memset(buf, 0, sizeof(buf));
36222@@ -2178,7 +2178,7 @@ static ssize_t iwl_dbgfs_protection_mode_write(struct file *file,
36223
36224 struct iwl_priv *priv = file->private_data;
36225 char buf[8];
36226- int buf_size;
36227+ size_t buf_size;
36228 int rts;
36229
36230 if (!priv->cfg->ht_params)
36231@@ -2220,7 +2220,7 @@ static ssize_t iwl_dbgfs_echo_test_write(struct file *file,
36232 {
36233 struct iwl_priv *priv = file->private_data;
36234 char buf[8];
36235- int buf_size;
36236+ size_t buf_size;
36237
36238 memset(buf, 0, sizeof(buf));
36239 buf_size = min(count, sizeof(buf) - 1);
36240@@ -2256,7 +2256,7 @@ static ssize_t iwl_dbgfs_log_event_write(struct file *file,
36241 struct iwl_priv *priv = file->private_data;
36242 u32 event_log_flag;
36243 char buf[8];
36244- int buf_size;
36245+ size_t buf_size;
36246
36247 /* check that the interface is up */
36248 if (!iwl_is_ready(priv))
36249@@ -2310,7 +2310,7 @@ static ssize_t iwl_dbgfs_calib_disabled_write(struct file *file,
36250 struct iwl_priv *priv = file->private_data;
36251 char buf[8];
36252 u32 calib_disabled;
36253- int buf_size;
36254+ size_t buf_size;
36255
36256 memset(buf, 0, sizeof(buf));
36257 buf_size = min(count, sizeof(buf) - 1);
36258diff --git a/drivers/net/wireless/iwlwifi/pcie/trans.c b/drivers/net/wireless/iwlwifi/pcie/trans.c
36259index dbeebef..b45a152 100644
36260--- a/drivers/net/wireless/iwlwifi/pcie/trans.c
36261+++ b/drivers/net/wireless/iwlwifi/pcie/trans.c
36262@@ -1944,7 +1944,7 @@ static ssize_t iwl_dbgfs_interrupt_write(struct file *file,
36263 struct isr_statistics *isr_stats = &trans_pcie->isr_stats;
36264
36265 char buf[8];
36266- int buf_size;
36267+ size_t buf_size;
36268 u32 reset_flag;
36269
36270 memset(buf, 0, sizeof(buf));
36271@@ -1965,7 +1965,7 @@ static ssize_t iwl_dbgfs_csr_write(struct file *file,
36272 {
36273 struct iwl_trans *trans = file->private_data;
36274 char buf[8];
36275- int buf_size;
36276+ size_t buf_size;
36277 int csr;
36278
36279 memset(buf, 0, sizeof(buf));
36280diff --git a/drivers/net/wireless/mac80211_hwsim.c b/drivers/net/wireless/mac80211_hwsim.c
36281index 0083839..fcb7225 100644
36282--- a/drivers/net/wireless/mac80211_hwsim.c
36283+++ b/drivers/net/wireless/mac80211_hwsim.c
36284@@ -1748,9 +1748,11 @@ static int __init init_mac80211_hwsim(void)
36285 return -EINVAL;
36286
36287 if (fake_hw_scan) {
36288- mac80211_hwsim_ops.hw_scan = mac80211_hwsim_hw_scan;
36289- mac80211_hwsim_ops.sw_scan_start = NULL;
36290- mac80211_hwsim_ops.sw_scan_complete = NULL;
36291+ pax_open_kernel();
36292+ *(void **)&mac80211_hwsim_ops.hw_scan = mac80211_hwsim_hw_scan;
36293+ *(void **)&mac80211_hwsim_ops.sw_scan_start = NULL;
36294+ *(void **)&mac80211_hwsim_ops.sw_scan_complete = NULL;
36295+ pax_close_kernel();
36296 }
36297
36298 spin_lock_init(&hwsim_radio_lock);
36299diff --git a/drivers/net/wireless/mwifiex/main.h b/drivers/net/wireless/mwifiex/main.h
36300index e7c2a82..582e228 100644
36301--- a/drivers/net/wireless/mwifiex/main.h
36302+++ b/drivers/net/wireless/mwifiex/main.h
36303@@ -571,7 +571,7 @@ struct mwifiex_if_ops {
36304 int (*event_complete) (struct mwifiex_adapter *, struct sk_buff *);
36305 int (*data_complete) (struct mwifiex_adapter *, struct sk_buff *);
36306 int (*dnld_fw) (struct mwifiex_adapter *, struct mwifiex_fw_image *);
36307-};
36308+} __no_const;
36309
36310 struct mwifiex_adapter {
36311 u8 iface_type;
36312diff --git a/drivers/net/wireless/rndis_wlan.c b/drivers/net/wireless/rndis_wlan.c
36313index 7a4ae9e..56e00bd 100644
36314--- a/drivers/net/wireless/rndis_wlan.c
36315+++ b/drivers/net/wireless/rndis_wlan.c
36316@@ -1235,7 +1235,7 @@ static int set_rts_threshold(struct usbnet *usbdev, u32 rts_threshold)
36317
36318 netdev_dbg(usbdev->net, "%s(): %i\n", __func__, rts_threshold);
36319
36320- if (rts_threshold < 0 || rts_threshold > 2347)
36321+ if (rts_threshold > 2347)
36322 rts_threshold = 2347;
36323
36324 tmp = cpu_to_le32(rts_threshold);
36325diff --git a/drivers/net/wireless/rt2x00/rt2x00.h b/drivers/net/wireless/rt2x00/rt2x00.h
36326index 8afb546..0c0dc5c 100644
36327--- a/drivers/net/wireless/rt2x00/rt2x00.h
36328+++ b/drivers/net/wireless/rt2x00/rt2x00.h
36329@@ -397,7 +397,7 @@ struct rt2x00_intf {
36330 * for hardware which doesn't support hardware
36331 * sequence counting.
36332 */
36333- atomic_t seqno;
36334+ atomic_unchecked_t seqno;
36335 };
36336
36337 static inline struct rt2x00_intf* vif_to_intf(struct ieee80211_vif *vif)
36338diff --git a/drivers/net/wireless/rt2x00/rt2x00queue.c b/drivers/net/wireless/rt2x00/rt2x00queue.c
36339index f7e74a0..da71431 100644
36340--- a/drivers/net/wireless/rt2x00/rt2x00queue.c
36341+++ b/drivers/net/wireless/rt2x00/rt2x00queue.c
36342@@ -240,9 +240,9 @@ static void rt2x00queue_create_tx_descriptor_seq(struct rt2x00_dev *rt2x00dev,
36343 * sequence counter given by mac80211.
36344 */
36345 if (test_bit(ENTRY_TXD_FIRST_FRAGMENT, &txdesc->flags))
36346- seqno = atomic_add_return(0x10, &intf->seqno);
36347+ seqno = atomic_add_return_unchecked(0x10, &intf->seqno);
36348 else
36349- seqno = atomic_read(&intf->seqno);
36350+ seqno = atomic_read_unchecked(&intf->seqno);
36351
36352 hdr->seq_ctrl &= cpu_to_le16(IEEE80211_SCTL_FRAG);
36353 hdr->seq_ctrl |= cpu_to_le16(seqno);
36354diff --git a/drivers/net/wireless/ti/wl1251/wl1251.h b/drivers/net/wireless/ti/wl1251/wl1251.h
36355index fd02060..74ee481 100644
36356--- a/drivers/net/wireless/ti/wl1251/wl1251.h
36357+++ b/drivers/net/wireless/ti/wl1251/wl1251.h
36358@@ -266,7 +266,7 @@ struct wl1251_if_operations {
36359 void (*reset)(struct wl1251 *wl);
36360 void (*enable_irq)(struct wl1251 *wl);
36361 void (*disable_irq)(struct wl1251 *wl);
36362-};
36363+} __no_const;
36364
36365 struct wl1251 {
36366 struct ieee80211_hw *hw;
36367diff --git a/drivers/net/wireless/ti/wlcore/wlcore.h b/drivers/net/wireless/ti/wlcore/wlcore.h
36368index 0ce7a8e..56a0ccf 100644
36369--- a/drivers/net/wireless/ti/wlcore/wlcore.h
36370+++ b/drivers/net/wireless/ti/wlcore/wlcore.h
36371@@ -81,7 +81,7 @@ struct wlcore_ops {
36372 struct ieee80211_sta *sta,
36373 struct ieee80211_key_conf *key_conf);
36374 u32 (*pre_pkt_send)(struct wl1271 *wl, u32 buf_offset, u32 last_len);
36375-};
36376+} __no_const;
36377
36378 enum wlcore_partitions {
36379 PART_DOWN,
36380diff --git a/drivers/oprofile/buffer_sync.c b/drivers/oprofile/buffer_sync.c
36381index f34b5b2..b5abb9f 100644
36382--- a/drivers/oprofile/buffer_sync.c
36383+++ b/drivers/oprofile/buffer_sync.c
36384@@ -343,7 +343,7 @@ static void add_data(struct op_entry *entry, struct mm_struct *mm)
36385 if (cookie == NO_COOKIE)
36386 offset = pc;
36387 if (cookie == INVALID_COOKIE) {
36388- atomic_inc(&oprofile_stats.sample_lost_no_mapping);
36389+ atomic_inc_unchecked(&oprofile_stats.sample_lost_no_mapping);
36390 offset = pc;
36391 }
36392 if (cookie != last_cookie) {
36393@@ -387,14 +387,14 @@ add_sample(struct mm_struct *mm, struct op_sample *s, int in_kernel)
36394 /* add userspace sample */
36395
36396 if (!mm) {
36397- atomic_inc(&oprofile_stats.sample_lost_no_mm);
36398+ atomic_inc_unchecked(&oprofile_stats.sample_lost_no_mm);
36399 return 0;
36400 }
36401
36402 cookie = lookup_dcookie(mm, s->eip, &offset);
36403
36404 if (cookie == INVALID_COOKIE) {
36405- atomic_inc(&oprofile_stats.sample_lost_no_mapping);
36406+ atomic_inc_unchecked(&oprofile_stats.sample_lost_no_mapping);
36407 return 0;
36408 }
36409
36410@@ -563,7 +563,7 @@ void sync_buffer(int cpu)
36411 /* ignore backtraces if failed to add a sample */
36412 if (state == sb_bt_start) {
36413 state = sb_bt_ignore;
36414- atomic_inc(&oprofile_stats.bt_lost_no_mapping);
36415+ atomic_inc_unchecked(&oprofile_stats.bt_lost_no_mapping);
36416 }
36417 }
36418 release_mm(mm);
36419diff --git a/drivers/oprofile/event_buffer.c b/drivers/oprofile/event_buffer.c
36420index c0cc4e7..44d4e54 100644
36421--- a/drivers/oprofile/event_buffer.c
36422+++ b/drivers/oprofile/event_buffer.c
36423@@ -53,7 +53,7 @@ void add_event_entry(unsigned long value)
36424 }
36425
36426 if (buffer_pos == buffer_size) {
36427- atomic_inc(&oprofile_stats.event_lost_overflow);
36428+ atomic_inc_unchecked(&oprofile_stats.event_lost_overflow);
36429 return;
36430 }
36431
36432diff --git a/drivers/oprofile/oprof.c b/drivers/oprofile/oprof.c
36433index ed2c3ec..deda85a 100644
36434--- a/drivers/oprofile/oprof.c
36435+++ b/drivers/oprofile/oprof.c
36436@@ -110,7 +110,7 @@ static void switch_worker(struct work_struct *work)
36437 if (oprofile_ops.switch_events())
36438 return;
36439
36440- atomic_inc(&oprofile_stats.multiplex_counter);
36441+ atomic_inc_unchecked(&oprofile_stats.multiplex_counter);
36442 start_switch_worker();
36443 }
36444
36445diff --git a/drivers/oprofile/oprofile_stats.c b/drivers/oprofile/oprofile_stats.c
36446index 917d28e..d62d981 100644
36447--- a/drivers/oprofile/oprofile_stats.c
36448+++ b/drivers/oprofile/oprofile_stats.c
36449@@ -30,11 +30,11 @@ void oprofile_reset_stats(void)
36450 cpu_buf->sample_invalid_eip = 0;
36451 }
36452
36453- atomic_set(&oprofile_stats.sample_lost_no_mm, 0);
36454- atomic_set(&oprofile_stats.sample_lost_no_mapping, 0);
36455- atomic_set(&oprofile_stats.event_lost_overflow, 0);
36456- atomic_set(&oprofile_stats.bt_lost_no_mapping, 0);
36457- atomic_set(&oprofile_stats.multiplex_counter, 0);
36458+ atomic_set_unchecked(&oprofile_stats.sample_lost_no_mm, 0);
36459+ atomic_set_unchecked(&oprofile_stats.sample_lost_no_mapping, 0);
36460+ atomic_set_unchecked(&oprofile_stats.event_lost_overflow, 0);
36461+ atomic_set_unchecked(&oprofile_stats.bt_lost_no_mapping, 0);
36462+ atomic_set_unchecked(&oprofile_stats.multiplex_counter, 0);
36463 }
36464
36465
36466diff --git a/drivers/oprofile/oprofile_stats.h b/drivers/oprofile/oprofile_stats.h
36467index 38b6fc0..b5cbfce 100644
36468--- a/drivers/oprofile/oprofile_stats.h
36469+++ b/drivers/oprofile/oprofile_stats.h
36470@@ -13,11 +13,11 @@
36471 #include <linux/atomic.h>
36472
36473 struct oprofile_stat_struct {
36474- atomic_t sample_lost_no_mm;
36475- atomic_t sample_lost_no_mapping;
36476- atomic_t bt_lost_no_mapping;
36477- atomic_t event_lost_overflow;
36478- atomic_t multiplex_counter;
36479+ atomic_unchecked_t sample_lost_no_mm;
36480+ atomic_unchecked_t sample_lost_no_mapping;
36481+ atomic_unchecked_t bt_lost_no_mapping;
36482+ atomic_unchecked_t event_lost_overflow;
36483+ atomic_unchecked_t multiplex_counter;
36484 };
36485
36486 extern struct oprofile_stat_struct oprofile_stats;
36487diff --git a/drivers/oprofile/oprofilefs.c b/drivers/oprofile/oprofilefs.c
36488index 849357c..b83c1e0 100644
36489--- a/drivers/oprofile/oprofilefs.c
36490+++ b/drivers/oprofile/oprofilefs.c
36491@@ -185,7 +185,7 @@ static const struct file_operations atomic_ro_fops = {
36492
36493
36494 int oprofilefs_create_ro_atomic(struct super_block *sb, struct dentry *root,
36495- char const *name, atomic_t *val)
36496+ char const *name, atomic_unchecked_t *val)
36497 {
36498 return __oprofilefs_create_file(sb, root, name,
36499 &atomic_ro_fops, 0444, val);
36500diff --git a/drivers/parport/procfs.c b/drivers/parport/procfs.c
36501index 3f56bc0..707d642 100644
36502--- a/drivers/parport/procfs.c
36503+++ b/drivers/parport/procfs.c
36504@@ -64,7 +64,7 @@ static int do_active_device(ctl_table *table, int write,
36505
36506 *ppos += len;
36507
36508- return copy_to_user(result, buffer, len) ? -EFAULT : 0;
36509+ return (len > sizeof buffer || copy_to_user(result, buffer, len)) ? -EFAULT : 0;
36510 }
36511
36512 #ifdef CONFIG_PARPORT_1284
36513@@ -106,7 +106,7 @@ static int do_autoprobe(ctl_table *table, int write,
36514
36515 *ppos += len;
36516
36517- return copy_to_user (result, buffer, len) ? -EFAULT : 0;
36518+ return (len > sizeof buffer || copy_to_user (result, buffer, len)) ? -EFAULT : 0;
36519 }
36520 #endif /* IEEE1284.3 support. */
36521
36522diff --git a/drivers/pci/hotplug/cpci_hotplug.h b/drivers/pci/hotplug/cpci_hotplug.h
36523index 9fff878..ad0ad53 100644
36524--- a/drivers/pci/hotplug/cpci_hotplug.h
36525+++ b/drivers/pci/hotplug/cpci_hotplug.h
36526@@ -59,7 +59,7 @@ struct cpci_hp_controller_ops {
36527 int (*hardware_test) (struct slot* slot, u32 value);
36528 u8 (*get_power) (struct slot* slot);
36529 int (*set_power) (struct slot* slot, int value);
36530-};
36531+} __no_const;
36532
36533 struct cpci_hp_controller {
36534 unsigned int irq;
36535diff --git a/drivers/pci/hotplug/cpqphp_nvram.c b/drivers/pci/hotplug/cpqphp_nvram.c
36536index 76ba8a1..20ca857 100644
36537--- a/drivers/pci/hotplug/cpqphp_nvram.c
36538+++ b/drivers/pci/hotplug/cpqphp_nvram.c
36539@@ -428,9 +428,13 @@ static u32 store_HRT (void __iomem *rom_start)
36540
36541 void compaq_nvram_init (void __iomem *rom_start)
36542 {
36543+
36544+#ifndef CONFIG_PAX_KERNEXEC
36545 if (rom_start) {
36546 compaq_int15_entry_point = (rom_start + ROM_INT15_PHY_ADDR - ROM_PHY_ADDR);
36547 }
36548+#endif
36549+
36550 dbg("int15 entry = %p\n", compaq_int15_entry_point);
36551
36552 /* initialize our int15 lock */
36553diff --git a/drivers/pci/pcie/aspm.c b/drivers/pci/pcie/aspm.c
36554index b500840..d7159d3 100644
36555--- a/drivers/pci/pcie/aspm.c
36556+++ b/drivers/pci/pcie/aspm.c
36557@@ -27,9 +27,9 @@
36558 #define MODULE_PARAM_PREFIX "pcie_aspm."
36559
36560 /* Note: those are not register definitions */
36561-#define ASPM_STATE_L0S_UP (1) /* Upstream direction L0s state */
36562-#define ASPM_STATE_L0S_DW (2) /* Downstream direction L0s state */
36563-#define ASPM_STATE_L1 (4) /* L1 state */
36564+#define ASPM_STATE_L0S_UP (1U) /* Upstream direction L0s state */
36565+#define ASPM_STATE_L0S_DW (2U) /* Downstream direction L0s state */
36566+#define ASPM_STATE_L1 (4U) /* L1 state */
36567 #define ASPM_STATE_L0S (ASPM_STATE_L0S_UP | ASPM_STATE_L0S_DW)
36568 #define ASPM_STATE_ALL (ASPM_STATE_L0S | ASPM_STATE_L1)
36569
36570diff --git a/drivers/pci/probe.c b/drivers/pci/probe.c
36571index 61859d0..124539e 100644
36572--- a/drivers/pci/probe.c
36573+++ b/drivers/pci/probe.c
36574@@ -173,7 +173,7 @@ int __pci_read_base(struct pci_dev *dev, enum pci_bar_type type,
36575 struct pci_bus_region region;
36576 bool bar_too_big = false, bar_disabled = false;
36577
36578- mask = type ? PCI_ROM_ADDRESS_MASK : ~0;
36579+ mask = type ? (u32)PCI_ROM_ADDRESS_MASK : ~0;
36580
36581 /* No printks while decoding is disabled! */
36582 if (!dev->mmio_always_on) {
36583diff --git a/drivers/pci/proc.c b/drivers/pci/proc.c
36584index 27911b5..5b6db88 100644
36585--- a/drivers/pci/proc.c
36586+++ b/drivers/pci/proc.c
36587@@ -476,7 +476,16 @@ static const struct file_operations proc_bus_pci_dev_operations = {
36588 static int __init pci_proc_init(void)
36589 {
36590 struct pci_dev *dev = NULL;
36591+
36592+#ifdef CONFIG_GRKERNSEC_PROC_ADD
36593+#ifdef CONFIG_GRKERNSEC_PROC_USER
36594+ proc_bus_pci_dir = proc_mkdir_mode("bus/pci", S_IRUSR | S_IXUSR, NULL);
36595+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
36596+ proc_bus_pci_dir = proc_mkdir_mode("bus/pci", S_IRUSR | S_IXUSR | S_IRGRP | S_IXGRP, NULL);
36597+#endif
36598+#else
36599 proc_bus_pci_dir = proc_mkdir("bus/pci", NULL);
36600+#endif
36601 proc_create("devices", 0, proc_bus_pci_dir,
36602 &proc_bus_pci_dev_operations);
36603 proc_initialized = 1;
36604diff --git a/drivers/platform/x86/thinkpad_acpi.c b/drivers/platform/x86/thinkpad_acpi.c
36605index 52daaa8..d6b81eb 100644
36606--- a/drivers/platform/x86/thinkpad_acpi.c
36607+++ b/drivers/platform/x86/thinkpad_acpi.c
36608@@ -2097,7 +2097,7 @@ static int hotkey_mask_get(void)
36609 return 0;
36610 }
36611
36612-void static hotkey_mask_warn_incomplete_mask(void)
36613+static void hotkey_mask_warn_incomplete_mask(void)
36614 {
36615 /* log only what the user can fix... */
36616 const u32 wantedmask = hotkey_driver_mask &
36617@@ -2328,11 +2328,6 @@ static void hotkey_read_nvram(struct tp_nvram_state *n, const u32 m)
36618 }
36619 }
36620
36621-static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
36622- struct tp_nvram_state *newn,
36623- const u32 event_mask)
36624-{
36625-
36626 #define TPACPI_COMPARE_KEY(__scancode, __member) \
36627 do { \
36628 if ((event_mask & (1 << __scancode)) && \
36629@@ -2346,36 +2341,42 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
36630 tpacpi_hotkey_send_key(__scancode); \
36631 } while (0)
36632
36633- void issue_volchange(const unsigned int oldvol,
36634- const unsigned int newvol)
36635- {
36636- unsigned int i = oldvol;
36637+static void issue_volchange(const unsigned int oldvol,
36638+ const unsigned int newvol,
36639+ const u32 event_mask)
36640+{
36641+ unsigned int i = oldvol;
36642
36643- while (i > newvol) {
36644- TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEDOWN);
36645- i--;
36646- }
36647- while (i < newvol) {
36648- TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEUP);
36649- i++;
36650- }
36651+ while (i > newvol) {
36652+ TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEDOWN);
36653+ i--;
36654 }
36655+ while (i < newvol) {
36656+ TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEUP);
36657+ i++;
36658+ }
36659+}
36660
36661- void issue_brightnesschange(const unsigned int oldbrt,
36662- const unsigned int newbrt)
36663- {
36664- unsigned int i = oldbrt;
36665+static void issue_brightnesschange(const unsigned int oldbrt,
36666+ const unsigned int newbrt,
36667+ const u32 event_mask)
36668+{
36669+ unsigned int i = oldbrt;
36670
36671- while (i > newbrt) {
36672- TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNEND);
36673- i--;
36674- }
36675- while (i < newbrt) {
36676- TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNHOME);
36677- i++;
36678- }
36679+ while (i > newbrt) {
36680+ TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNEND);
36681+ i--;
36682+ }
36683+ while (i < newbrt) {
36684+ TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNHOME);
36685+ i++;
36686 }
36687+}
36688
36689+static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
36690+ struct tp_nvram_state *newn,
36691+ const u32 event_mask)
36692+{
36693 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_THINKPAD, thinkpad_toggle);
36694 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_FNSPACE, zoom_toggle);
36695 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_FNF7, display_toggle);
36696@@ -2409,7 +2410,7 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
36697 oldn->volume_level != newn->volume_level) {
36698 /* recently muted, or repeated mute keypress, or
36699 * multiple presses ending in mute */
36700- issue_volchange(oldn->volume_level, newn->volume_level);
36701+ issue_volchange(oldn->volume_level, newn->volume_level, event_mask);
36702 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_MUTE);
36703 }
36704 } else {
36705@@ -2419,7 +2420,7 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
36706 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEUP);
36707 }
36708 if (oldn->volume_level != newn->volume_level) {
36709- issue_volchange(oldn->volume_level, newn->volume_level);
36710+ issue_volchange(oldn->volume_level, newn->volume_level, event_mask);
36711 } else if (oldn->volume_toggle != newn->volume_toggle) {
36712 /* repeated vol up/down keypress at end of scale ? */
36713 if (newn->volume_level == 0)
36714@@ -2432,7 +2433,8 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
36715 /* handle brightness */
36716 if (oldn->brightness_level != newn->brightness_level) {
36717 issue_brightnesschange(oldn->brightness_level,
36718- newn->brightness_level);
36719+ newn->brightness_level,
36720+ event_mask);
36721 } else if (oldn->brightness_toggle != newn->brightness_toggle) {
36722 /* repeated key presses that didn't change state */
36723 if (newn->brightness_level == 0)
36724@@ -2441,10 +2443,10 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
36725 && !tp_features.bright_unkfw)
36726 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNHOME);
36727 }
36728+}
36729
36730 #undef TPACPI_COMPARE_KEY
36731 #undef TPACPI_MAY_SEND_KEY
36732-}
36733
36734 /*
36735 * Polling driver
36736diff --git a/drivers/pnp/pnpbios/bioscalls.c b/drivers/pnp/pnpbios/bioscalls.c
36737index 769d265..a3a05ca 100644
36738--- a/drivers/pnp/pnpbios/bioscalls.c
36739+++ b/drivers/pnp/pnpbios/bioscalls.c
36740@@ -58,7 +58,7 @@ do { \
36741 set_desc_limit(&gdt[(selname) >> 3], (size) - 1); \
36742 } while(0)
36743
36744-static struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4092,
36745+static const struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4093,
36746 (unsigned long)__va(0x400UL), PAGE_SIZE - 0x400 - 1);
36747
36748 /*
36749@@ -95,7 +95,10 @@ static inline u16 call_pnp_bios(u16 func, u16 arg1, u16 arg2, u16 arg3,
36750
36751 cpu = get_cpu();
36752 save_desc_40 = get_cpu_gdt_table(cpu)[0x40 / 8];
36753+
36754+ pax_open_kernel();
36755 get_cpu_gdt_table(cpu)[0x40 / 8] = bad_bios_desc;
36756+ pax_close_kernel();
36757
36758 /* On some boxes IRQ's during PnP BIOS calls are deadly. */
36759 spin_lock_irqsave(&pnp_bios_lock, flags);
36760@@ -133,7 +136,10 @@ static inline u16 call_pnp_bios(u16 func, u16 arg1, u16 arg2, u16 arg3,
36761 :"memory");
36762 spin_unlock_irqrestore(&pnp_bios_lock, flags);
36763
36764+ pax_open_kernel();
36765 get_cpu_gdt_table(cpu)[0x40 / 8] = save_desc_40;
36766+ pax_close_kernel();
36767+
36768 put_cpu();
36769
36770 /* If we get here and this is set then the PnP BIOS faulted on us. */
36771@@ -467,7 +473,7 @@ int pnp_bios_read_escd(char *data, u32 nvram_base)
36772 return status;
36773 }
36774
36775-void pnpbios_calls_init(union pnp_bios_install_struct *header)
36776+void __init pnpbios_calls_init(union pnp_bios_install_struct *header)
36777 {
36778 int i;
36779
36780@@ -475,6 +481,8 @@ void pnpbios_calls_init(union pnp_bios_install_struct *header)
36781 pnp_bios_callpoint.offset = header->fields.pm16offset;
36782 pnp_bios_callpoint.segment = PNP_CS16;
36783
36784+ pax_open_kernel();
36785+
36786 for_each_possible_cpu(i) {
36787 struct desc_struct *gdt = get_cpu_gdt_table(i);
36788 if (!gdt)
36789@@ -486,4 +494,6 @@ void pnpbios_calls_init(union pnp_bios_install_struct *header)
36790 set_desc_base(&gdt[GDT_ENTRY_PNPBIOS_DS],
36791 (unsigned long)__va(header->fields.pm16dseg));
36792 }
36793+
36794+ pax_close_kernel();
36795 }
36796diff --git a/drivers/pnp/resource.c b/drivers/pnp/resource.c
36797index b0ecacb..7c9da2e 100644
36798--- a/drivers/pnp/resource.c
36799+++ b/drivers/pnp/resource.c
36800@@ -360,7 +360,7 @@ int pnp_check_irq(struct pnp_dev *dev, struct resource *res)
36801 return 1;
36802
36803 /* check if the resource is valid */
36804- if (*irq < 0 || *irq > 15)
36805+ if (*irq > 15)
36806 return 0;
36807
36808 /* check if the resource is reserved */
36809@@ -424,7 +424,7 @@ int pnp_check_dma(struct pnp_dev *dev, struct resource *res)
36810 return 1;
36811
36812 /* check if the resource is valid */
36813- if (*dma < 0 || *dma == 4 || *dma > 7)
36814+ if (*dma == 4 || *dma > 7)
36815 return 0;
36816
36817 /* check if the resource is reserved */
36818diff --git a/drivers/power/bq27x00_battery.c b/drivers/power/bq27x00_battery.c
36819index 181ddec..774b6da 100644
36820--- a/drivers/power/bq27x00_battery.c
36821+++ b/drivers/power/bq27x00_battery.c
36822@@ -80,7 +80,7 @@
36823 struct bq27x00_device_info;
36824 struct bq27x00_access_methods {
36825 int (*read)(struct bq27x00_device_info *di, u8 reg, bool single);
36826-};
36827+} __no_const;
36828
36829 enum bq27x00_chip { BQ27000, BQ27500, BQ27425};
36830
36831diff --git a/drivers/regulator/max8660.c b/drivers/regulator/max8660.c
36832index 8d53174..04c65de 100644
36833--- a/drivers/regulator/max8660.c
36834+++ b/drivers/regulator/max8660.c
36835@@ -333,8 +333,10 @@ static int __devinit max8660_probe(struct i2c_client *client,
36836 max8660->shadow_regs[MAX8660_OVER1] = 5;
36837 } else {
36838 /* Otherwise devices can be toggled via software */
36839- max8660_dcdc_ops.enable = max8660_dcdc_enable;
36840- max8660_dcdc_ops.disable = max8660_dcdc_disable;
36841+ pax_open_kernel();
36842+ *(void **)&max8660_dcdc_ops.enable = max8660_dcdc_enable;
36843+ *(void **)&max8660_dcdc_ops.disable = max8660_dcdc_disable;
36844+ pax_close_kernel();
36845 }
36846
36847 /*
36848diff --git a/drivers/regulator/mc13892-regulator.c b/drivers/regulator/mc13892-regulator.c
36849index b388b74..ed82573 100644
36850--- a/drivers/regulator/mc13892-regulator.c
36851+++ b/drivers/regulator/mc13892-regulator.c
36852@@ -565,10 +565,12 @@ static int __devinit mc13892_regulator_probe(struct platform_device *pdev)
36853 }
36854 mc13xxx_unlock(mc13892);
36855
36856- mc13892_regulators[MC13892_VCAM].desc.ops->set_mode
36857+ pax_open_kernel();
36858+ *(void **)&mc13892_regulators[MC13892_VCAM].desc.ops->set_mode
36859 = mc13892_vcam_set_mode;
36860- mc13892_regulators[MC13892_VCAM].desc.ops->get_mode
36861+ *(void **)&mc13892_regulators[MC13892_VCAM].desc.ops->get_mode
36862 = mc13892_vcam_get_mode;
36863+ pax_close_kernel();
36864
36865 mc13xxx_data = mc13xxx_parse_regulators_dt(pdev, mc13892_regulators,
36866 ARRAY_SIZE(mc13892_regulators));
36867diff --git a/drivers/rtc/rtc-dev.c b/drivers/rtc/rtc-dev.c
36868index cace6d3..f623fda 100644
36869--- a/drivers/rtc/rtc-dev.c
36870+++ b/drivers/rtc/rtc-dev.c
36871@@ -14,6 +14,7 @@
36872 #include <linux/module.h>
36873 #include <linux/rtc.h>
36874 #include <linux/sched.h>
36875+#include <linux/grsecurity.h>
36876 #include "rtc-core.h"
36877
36878 static dev_t rtc_devt;
36879@@ -345,6 +346,8 @@ static long rtc_dev_ioctl(struct file *file,
36880 if (copy_from_user(&tm, uarg, sizeof(tm)))
36881 return -EFAULT;
36882
36883+ gr_log_timechange();
36884+
36885 return rtc_set_time(rtc, &tm);
36886
36887 case RTC_PIE_ON:
36888diff --git a/drivers/scsi/aacraid/aacraid.h b/drivers/scsi/aacraid/aacraid.h
36889index 9e933a8..4f969f7 100644
36890--- a/drivers/scsi/aacraid/aacraid.h
36891+++ b/drivers/scsi/aacraid/aacraid.h
36892@@ -503,7 +503,7 @@ struct adapter_ops
36893 int (*adapter_scsi)(struct fib * fib, struct scsi_cmnd * cmd);
36894 /* Administrative operations */
36895 int (*adapter_comm)(struct aac_dev * dev, int comm);
36896-};
36897+} __no_const;
36898
36899 /*
36900 * Define which interrupt handler needs to be installed
36901diff --git a/drivers/scsi/aacraid/linit.c b/drivers/scsi/aacraid/linit.c
36902index 7199534..cb7f158 100644
36903--- a/drivers/scsi/aacraid/linit.c
36904+++ b/drivers/scsi/aacraid/linit.c
36905@@ -93,7 +93,7 @@ static DECLARE_PCI_DEVICE_TABLE(aac_pci_tbl) = {
36906 #elif defined(__devinitconst)
36907 static const struct pci_device_id aac_pci_tbl[] __devinitconst = {
36908 #else
36909-static const struct pci_device_id aac_pci_tbl[] __devinitdata = {
36910+static const struct pci_device_id aac_pci_tbl[] __devinitconst = {
36911 #endif
36912 { 0x1028, 0x0001, 0x1028, 0x0001, 0, 0, 0 }, /* PERC 2/Si (Iguana/PERC2Si) */
36913 { 0x1028, 0x0002, 0x1028, 0x0002, 0, 0, 1 }, /* PERC 3/Di (Opal/PERC3Di) */
36914diff --git a/drivers/scsi/aic94xx/aic94xx_init.c b/drivers/scsi/aic94xx/aic94xx_init.c
36915index ff80552..1c4120c 100644
36916--- a/drivers/scsi/aic94xx/aic94xx_init.c
36917+++ b/drivers/scsi/aic94xx/aic94xx_init.c
36918@@ -1012,7 +1012,7 @@ static struct sas_domain_function_template aic94xx_transport_functions = {
36919 .lldd_ata_set_dmamode = asd_set_dmamode,
36920 };
36921
36922-static const struct pci_device_id aic94xx_pci_table[] __devinitdata = {
36923+static const struct pci_device_id aic94xx_pci_table[] __devinitconst = {
36924 {PCI_DEVICE(PCI_VENDOR_ID_ADAPTEC2, 0x410),0, 0, 1},
36925 {PCI_DEVICE(PCI_VENDOR_ID_ADAPTEC2, 0x412),0, 0, 1},
36926 {PCI_DEVICE(PCI_VENDOR_ID_ADAPTEC2, 0x416),0, 0, 1},
36927diff --git a/drivers/scsi/bfa/bfa.h b/drivers/scsi/bfa/bfa.h
36928index 4ad7e36..d004679 100644
36929--- a/drivers/scsi/bfa/bfa.h
36930+++ b/drivers/scsi/bfa/bfa.h
36931@@ -196,7 +196,7 @@ struct bfa_hwif_s {
36932 u32 *end);
36933 int cpe_vec_q0;
36934 int rme_vec_q0;
36935-};
36936+} __no_const;
36937 typedef void (*bfa_cb_iocfc_t) (void *cbarg, enum bfa_status status);
36938
36939 struct bfa_faa_cbfn_s {
36940diff --git a/drivers/scsi/bfa/bfa_fcpim.c b/drivers/scsi/bfa/bfa_fcpim.c
36941index f0f80e2..8ec946b 100644
36942--- a/drivers/scsi/bfa/bfa_fcpim.c
36943+++ b/drivers/scsi/bfa/bfa_fcpim.c
36944@@ -3715,7 +3715,7 @@ bfa_fcp_attach(struct bfa_s *bfa, void *bfad, struct bfa_iocfc_cfg_s *cfg,
36945
36946 bfa_iotag_attach(fcp);
36947
36948- fcp->itn_arr = (struct bfa_itn_s *) bfa_mem_kva_curp(fcp);
36949+ fcp->itn_arr = (bfa_itn_s_no_const *) bfa_mem_kva_curp(fcp);
36950 bfa_mem_kva_curp(fcp) = (u8 *)fcp->itn_arr +
36951 (fcp->num_itns * sizeof(struct bfa_itn_s));
36952 memset(fcp->itn_arr, 0,
36953@@ -3773,7 +3773,7 @@ bfa_itn_create(struct bfa_s *bfa, struct bfa_rport_s *rport,
36954 void (*isr)(struct bfa_s *bfa, struct bfi_msg_s *m))
36955 {
36956 struct bfa_fcp_mod_s *fcp = BFA_FCP_MOD(bfa);
36957- struct bfa_itn_s *itn;
36958+ bfa_itn_s_no_const *itn;
36959
36960 itn = BFA_ITN_FROM_TAG(fcp, rport->rport_tag);
36961 itn->isr = isr;
36962diff --git a/drivers/scsi/bfa/bfa_fcpim.h b/drivers/scsi/bfa/bfa_fcpim.h
36963index 36f26da..38a34a8 100644
36964--- a/drivers/scsi/bfa/bfa_fcpim.h
36965+++ b/drivers/scsi/bfa/bfa_fcpim.h
36966@@ -37,6 +37,7 @@ struct bfa_iotag_s {
36967 struct bfa_itn_s {
36968 bfa_isr_func_t isr;
36969 };
36970+typedef struct bfa_itn_s __no_const bfa_itn_s_no_const;
36971
36972 void bfa_itn_create(struct bfa_s *bfa, struct bfa_rport_s *rport,
36973 void (*isr)(struct bfa_s *bfa, struct bfi_msg_s *m));
36974@@ -147,7 +148,7 @@ struct bfa_fcp_mod_s {
36975 struct list_head iotag_tio_free_q; /* free IO resources */
36976 struct list_head iotag_unused_q; /* unused IO resources*/
36977 struct bfa_iotag_s *iotag_arr;
36978- struct bfa_itn_s *itn_arr;
36979+ bfa_itn_s_no_const *itn_arr;
36980 int num_ioim_reqs;
36981 int num_fwtio_reqs;
36982 int num_itns;
36983diff --git a/drivers/scsi/bfa/bfa_ioc.h b/drivers/scsi/bfa/bfa_ioc.h
36984index 1a99d4b..e85d64b 100644
36985--- a/drivers/scsi/bfa/bfa_ioc.h
36986+++ b/drivers/scsi/bfa/bfa_ioc.h
36987@@ -258,7 +258,7 @@ struct bfa_ioc_cbfn_s {
36988 bfa_ioc_disable_cbfn_t disable_cbfn;
36989 bfa_ioc_hbfail_cbfn_t hbfail_cbfn;
36990 bfa_ioc_reset_cbfn_t reset_cbfn;
36991-};
36992+} __no_const;
36993
36994 /*
36995 * IOC event notification mechanism.
36996@@ -346,7 +346,7 @@ struct bfa_ioc_hwif_s {
36997 void (*ioc_sync_ack) (struct bfa_ioc_s *ioc);
36998 bfa_boolean_t (*ioc_sync_complete) (struct bfa_ioc_s *ioc);
36999 bfa_boolean_t (*ioc_lpu_read_stat) (struct bfa_ioc_s *ioc);
37000-};
37001+} __no_const;
37002
37003 /*
37004 * Queue element to wait for room in request queue. FIFO order is
37005diff --git a/drivers/scsi/hosts.c b/drivers/scsi/hosts.c
37006index 593085a..47aa999 100644
37007--- a/drivers/scsi/hosts.c
37008+++ b/drivers/scsi/hosts.c
37009@@ -42,7 +42,7 @@
37010 #include "scsi_logging.h"
37011
37012
37013-static atomic_t scsi_host_next_hn = ATOMIC_INIT(0); /* host_no for next new host */
37014+static atomic_unchecked_t scsi_host_next_hn = ATOMIC_INIT(0); /* host_no for next new host */
37015
37016
37017 static void scsi_host_cls_release(struct device *dev)
37018@@ -361,7 +361,7 @@ struct Scsi_Host *scsi_host_alloc(struct scsi_host_template *sht, int privsize)
37019 * subtract one because we increment first then return, but we need to
37020 * know what the next host number was before increment
37021 */
37022- shost->host_no = atomic_inc_return(&scsi_host_next_hn) - 1;
37023+ shost->host_no = atomic_inc_return_unchecked(&scsi_host_next_hn) - 1;
37024 shost->dma_channel = 0xff;
37025
37026 /* These three are default values which can be overridden */
37027diff --git a/drivers/scsi/hpsa.c b/drivers/scsi/hpsa.c
37028index f9823f2..7bc3e81 100644
37029--- a/drivers/scsi/hpsa.c
37030+++ b/drivers/scsi/hpsa.c
37031@@ -536,7 +536,7 @@ static inline u32 next_command(struct ctlr_info *h, u8 q)
37032 unsigned long flags;
37033
37034 if (unlikely(!(h->transMethod & CFGTBL_Trans_Performant)))
37035- return h->access.command_completed(h, q);
37036+ return h->access->command_completed(h, q);
37037
37038 if ((rq->head[rq->current_entry] & 1) == rq->wraparound) {
37039 a = rq->head[rq->current_entry];
37040@@ -3355,7 +3355,7 @@ static void start_io(struct ctlr_info *h)
37041 while (!list_empty(&h->reqQ)) {
37042 c = list_entry(h->reqQ.next, struct CommandList, list);
37043 /* can't do anything if fifo is full */
37044- if ((h->access.fifo_full(h))) {
37045+ if ((h->access->fifo_full(h))) {
37046 dev_warn(&h->pdev->dev, "fifo full\n");
37047 break;
37048 }
37049@@ -3377,7 +3377,7 @@ static void start_io(struct ctlr_info *h)
37050
37051 /* Tell the controller execute command */
37052 spin_unlock_irqrestore(&h->lock, flags);
37053- h->access.submit_command(h, c);
37054+ h->access->submit_command(h, c);
37055 spin_lock_irqsave(&h->lock, flags);
37056 }
37057 spin_unlock_irqrestore(&h->lock, flags);
37058@@ -3385,17 +3385,17 @@ static void start_io(struct ctlr_info *h)
37059
37060 static inline unsigned long get_next_completion(struct ctlr_info *h, u8 q)
37061 {
37062- return h->access.command_completed(h, q);
37063+ return h->access->command_completed(h, q);
37064 }
37065
37066 static inline bool interrupt_pending(struct ctlr_info *h)
37067 {
37068- return h->access.intr_pending(h);
37069+ return h->access->intr_pending(h);
37070 }
37071
37072 static inline long interrupt_not_for_us(struct ctlr_info *h)
37073 {
37074- return (h->access.intr_pending(h) == 0) ||
37075+ return (h->access->intr_pending(h) == 0) ||
37076 (h->interrupts_enabled == 0);
37077 }
37078
37079@@ -4299,7 +4299,7 @@ static int __devinit hpsa_pci_init(struct ctlr_info *h)
37080 if (prod_index < 0)
37081 return -ENODEV;
37082 h->product_name = products[prod_index].product_name;
37083- h->access = *(products[prod_index].access);
37084+ h->access = products[prod_index].access;
37085
37086 pci_disable_link_state(h->pdev, PCIE_LINK_STATE_L0S |
37087 PCIE_LINK_STATE_L1 | PCIE_LINK_STATE_CLKPM);
37088@@ -4581,7 +4581,7 @@ static void controller_lockup_detected(struct ctlr_info *h)
37089
37090 assert_spin_locked(&lockup_detector_lock);
37091 remove_ctlr_from_lockup_detector_list(h);
37092- h->access.set_intr_mask(h, HPSA_INTR_OFF);
37093+ h->access->set_intr_mask(h, HPSA_INTR_OFF);
37094 spin_lock_irqsave(&h->lock, flags);
37095 h->lockup_detected = readl(h->vaddr + SA5_SCRATCHPAD_OFFSET);
37096 spin_unlock_irqrestore(&h->lock, flags);
37097@@ -4759,7 +4759,7 @@ reinit_after_soft_reset:
37098 }
37099
37100 /* make sure the board interrupts are off */
37101- h->access.set_intr_mask(h, HPSA_INTR_OFF);
37102+ h->access->set_intr_mask(h, HPSA_INTR_OFF);
37103
37104 if (hpsa_request_irq(h, do_hpsa_intr_msi, do_hpsa_intr_intx))
37105 goto clean2;
37106@@ -4793,7 +4793,7 @@ reinit_after_soft_reset:
37107 * fake ones to scoop up any residual completions.
37108 */
37109 spin_lock_irqsave(&h->lock, flags);
37110- h->access.set_intr_mask(h, HPSA_INTR_OFF);
37111+ h->access->set_intr_mask(h, HPSA_INTR_OFF);
37112 spin_unlock_irqrestore(&h->lock, flags);
37113 free_irqs(h);
37114 rc = hpsa_request_irq(h, hpsa_msix_discard_completions,
37115@@ -4812,9 +4812,9 @@ reinit_after_soft_reset:
37116 dev_info(&h->pdev->dev, "Board READY.\n");
37117 dev_info(&h->pdev->dev,
37118 "Waiting for stale completions to drain.\n");
37119- h->access.set_intr_mask(h, HPSA_INTR_ON);
37120+ h->access->set_intr_mask(h, HPSA_INTR_ON);
37121 msleep(10000);
37122- h->access.set_intr_mask(h, HPSA_INTR_OFF);
37123+ h->access->set_intr_mask(h, HPSA_INTR_OFF);
37124
37125 rc = controller_reset_failed(h->cfgtable);
37126 if (rc)
37127@@ -4835,7 +4835,7 @@ reinit_after_soft_reset:
37128 }
37129
37130 /* Turn the interrupts on so we can service requests */
37131- h->access.set_intr_mask(h, HPSA_INTR_ON);
37132+ h->access->set_intr_mask(h, HPSA_INTR_ON);
37133
37134 hpsa_hba_inquiry(h);
37135 hpsa_register_scsi(h); /* hook ourselves into SCSI subsystem */
37136@@ -4887,7 +4887,7 @@ static void hpsa_shutdown(struct pci_dev *pdev)
37137 * To write all data in the battery backed cache to disks
37138 */
37139 hpsa_flush_cache(h);
37140- h->access.set_intr_mask(h, HPSA_INTR_OFF);
37141+ h->access->set_intr_mask(h, HPSA_INTR_OFF);
37142 hpsa_free_irqs_and_disable_msix(h);
37143 }
37144
37145@@ -5056,7 +5056,7 @@ static __devinit void hpsa_enter_performant_mode(struct ctlr_info *h,
37146 return;
37147 }
37148 /* Change the access methods to the performant access methods */
37149- h->access = SA5_performant_access;
37150+ h->access = &SA5_performant_access;
37151 h->transMethod = CFGTBL_Trans_Performant;
37152 }
37153
37154diff --git a/drivers/scsi/hpsa.h b/drivers/scsi/hpsa.h
37155index 9816479..c5d4e97 100644
37156--- a/drivers/scsi/hpsa.h
37157+++ b/drivers/scsi/hpsa.h
37158@@ -79,7 +79,7 @@ struct ctlr_info {
37159 unsigned int msix_vector;
37160 unsigned int msi_vector;
37161 int intr_mode; /* either PERF_MODE_INT or SIMPLE_MODE_INT */
37162- struct access_method access;
37163+ struct access_method *access;
37164
37165 /* queue and queue Info */
37166 struct list_head reqQ;
37167diff --git a/drivers/scsi/ips.h b/drivers/scsi/ips.h
37168index f2df059..a3a9930 100644
37169--- a/drivers/scsi/ips.h
37170+++ b/drivers/scsi/ips.h
37171@@ -1027,7 +1027,7 @@ typedef struct {
37172 int (*intr)(struct ips_ha *);
37173 void (*enableint)(struct ips_ha *);
37174 uint32_t (*statupd)(struct ips_ha *);
37175-} ips_hw_func_t;
37176+} __no_const ips_hw_func_t;
37177
37178 typedef struct ips_ha {
37179 uint8_t ha_id[IPS_MAX_CHANNELS+1];
37180diff --git a/drivers/scsi/libfc/fc_exch.c b/drivers/scsi/libfc/fc_exch.c
37181index c772d8d..35c362c 100644
37182--- a/drivers/scsi/libfc/fc_exch.c
37183+++ b/drivers/scsi/libfc/fc_exch.c
37184@@ -100,12 +100,12 @@ struct fc_exch_mgr {
37185 u16 pool_max_index;
37186
37187 struct {
37188- atomic_t no_free_exch;
37189- atomic_t no_free_exch_xid;
37190- atomic_t xid_not_found;
37191- atomic_t xid_busy;
37192- atomic_t seq_not_found;
37193- atomic_t non_bls_resp;
37194+ atomic_unchecked_t no_free_exch;
37195+ atomic_unchecked_t no_free_exch_xid;
37196+ atomic_unchecked_t xid_not_found;
37197+ atomic_unchecked_t xid_busy;
37198+ atomic_unchecked_t seq_not_found;
37199+ atomic_unchecked_t non_bls_resp;
37200 } stats;
37201 };
37202
37203@@ -725,7 +725,7 @@ static struct fc_exch *fc_exch_em_alloc(struct fc_lport *lport,
37204 /* allocate memory for exchange */
37205 ep = mempool_alloc(mp->ep_pool, GFP_ATOMIC);
37206 if (!ep) {
37207- atomic_inc(&mp->stats.no_free_exch);
37208+ atomic_inc_unchecked(&mp->stats.no_free_exch);
37209 goto out;
37210 }
37211 memset(ep, 0, sizeof(*ep));
37212@@ -786,7 +786,7 @@ out:
37213 return ep;
37214 err:
37215 spin_unlock_bh(&pool->lock);
37216- atomic_inc(&mp->stats.no_free_exch_xid);
37217+ atomic_inc_unchecked(&mp->stats.no_free_exch_xid);
37218 mempool_free(ep, mp->ep_pool);
37219 return NULL;
37220 }
37221@@ -929,7 +929,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
37222 xid = ntohs(fh->fh_ox_id); /* we originated exch */
37223 ep = fc_exch_find(mp, xid);
37224 if (!ep) {
37225- atomic_inc(&mp->stats.xid_not_found);
37226+ atomic_inc_unchecked(&mp->stats.xid_not_found);
37227 reject = FC_RJT_OX_ID;
37228 goto out;
37229 }
37230@@ -959,7 +959,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
37231 ep = fc_exch_find(mp, xid);
37232 if ((f_ctl & FC_FC_FIRST_SEQ) && fc_sof_is_init(fr_sof(fp))) {
37233 if (ep) {
37234- atomic_inc(&mp->stats.xid_busy);
37235+ atomic_inc_unchecked(&mp->stats.xid_busy);
37236 reject = FC_RJT_RX_ID;
37237 goto rel;
37238 }
37239@@ -970,7 +970,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
37240 }
37241 xid = ep->xid; /* get our XID */
37242 } else if (!ep) {
37243- atomic_inc(&mp->stats.xid_not_found);
37244+ atomic_inc_unchecked(&mp->stats.xid_not_found);
37245 reject = FC_RJT_RX_ID; /* XID not found */
37246 goto out;
37247 }
37248@@ -987,7 +987,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
37249 } else {
37250 sp = &ep->seq;
37251 if (sp->id != fh->fh_seq_id) {
37252- atomic_inc(&mp->stats.seq_not_found);
37253+ atomic_inc_unchecked(&mp->stats.seq_not_found);
37254 if (f_ctl & FC_FC_END_SEQ) {
37255 /*
37256 * Update sequence_id based on incoming last
37257@@ -1437,22 +1437,22 @@ static void fc_exch_recv_seq_resp(struct fc_exch_mgr *mp, struct fc_frame *fp)
37258
37259 ep = fc_exch_find(mp, ntohs(fh->fh_ox_id));
37260 if (!ep) {
37261- atomic_inc(&mp->stats.xid_not_found);
37262+ atomic_inc_unchecked(&mp->stats.xid_not_found);
37263 goto out;
37264 }
37265 if (ep->esb_stat & ESB_ST_COMPLETE) {
37266- atomic_inc(&mp->stats.xid_not_found);
37267+ atomic_inc_unchecked(&mp->stats.xid_not_found);
37268 goto rel;
37269 }
37270 if (ep->rxid == FC_XID_UNKNOWN)
37271 ep->rxid = ntohs(fh->fh_rx_id);
37272 if (ep->sid != 0 && ep->sid != ntoh24(fh->fh_d_id)) {
37273- atomic_inc(&mp->stats.xid_not_found);
37274+ atomic_inc_unchecked(&mp->stats.xid_not_found);
37275 goto rel;
37276 }
37277 if (ep->did != ntoh24(fh->fh_s_id) &&
37278 ep->did != FC_FID_FLOGI) {
37279- atomic_inc(&mp->stats.xid_not_found);
37280+ atomic_inc_unchecked(&mp->stats.xid_not_found);
37281 goto rel;
37282 }
37283 sof = fr_sof(fp);
37284@@ -1461,7 +1461,7 @@ static void fc_exch_recv_seq_resp(struct fc_exch_mgr *mp, struct fc_frame *fp)
37285 sp->ssb_stat |= SSB_ST_RESP;
37286 sp->id = fh->fh_seq_id;
37287 } else if (sp->id != fh->fh_seq_id) {
37288- atomic_inc(&mp->stats.seq_not_found);
37289+ atomic_inc_unchecked(&mp->stats.seq_not_found);
37290 goto rel;
37291 }
37292
37293@@ -1525,9 +1525,9 @@ static void fc_exch_recv_resp(struct fc_exch_mgr *mp, struct fc_frame *fp)
37294 sp = fc_seq_lookup_orig(mp, fp); /* doesn't hold sequence */
37295
37296 if (!sp)
37297- atomic_inc(&mp->stats.xid_not_found);
37298+ atomic_inc_unchecked(&mp->stats.xid_not_found);
37299 else
37300- atomic_inc(&mp->stats.non_bls_resp);
37301+ atomic_inc_unchecked(&mp->stats.non_bls_resp);
37302
37303 fc_frame_free(fp);
37304 }
37305@@ -2174,13 +2174,13 @@ void fc_exch_update_stats(struct fc_lport *lport)
37306
37307 list_for_each_entry(ema, &lport->ema_list, ema_list) {
37308 mp = ema->mp;
37309- st->fc_no_free_exch += atomic_read(&mp->stats.no_free_exch);
37310+ st->fc_no_free_exch += atomic_read_unchecked(&mp->stats.no_free_exch);
37311 st->fc_no_free_exch_xid +=
37312- atomic_read(&mp->stats.no_free_exch_xid);
37313- st->fc_xid_not_found += atomic_read(&mp->stats.xid_not_found);
37314- st->fc_xid_busy += atomic_read(&mp->stats.xid_busy);
37315- st->fc_seq_not_found += atomic_read(&mp->stats.seq_not_found);
37316- st->fc_non_bls_resp += atomic_read(&mp->stats.non_bls_resp);
37317+ atomic_read_unchecked(&mp->stats.no_free_exch_xid);
37318+ st->fc_xid_not_found += atomic_read_unchecked(&mp->stats.xid_not_found);
37319+ st->fc_xid_busy += atomic_read_unchecked(&mp->stats.xid_busy);
37320+ st->fc_seq_not_found += atomic_read_unchecked(&mp->stats.seq_not_found);
37321+ st->fc_non_bls_resp += atomic_read_unchecked(&mp->stats.non_bls_resp);
37322 }
37323 }
37324 EXPORT_SYMBOL(fc_exch_update_stats);
37325diff --git a/drivers/scsi/libsas/sas_ata.c b/drivers/scsi/libsas/sas_ata.c
37326index a59fcdc..abe55f3 100644
37327--- a/drivers/scsi/libsas/sas_ata.c
37328+++ b/drivers/scsi/libsas/sas_ata.c
37329@@ -554,7 +554,7 @@ static struct ata_port_operations sas_sata_ops = {
37330 .postreset = ata_std_postreset,
37331 .error_handler = ata_std_error_handler,
37332 .post_internal_cmd = sas_ata_post_internal,
37333- .qc_defer = ata_std_qc_defer,
37334+ .qc_defer = ata_std_qc_defer,
37335 .qc_prep = ata_noop_qc_prep,
37336 .qc_issue = sas_ata_qc_issue,
37337 .qc_fill_rtf = sas_ata_qc_fill_rtf,
37338diff --git a/drivers/scsi/lpfc/lpfc.h b/drivers/scsi/lpfc/lpfc.h
37339index a65c05a..a39e402 100644
37340--- a/drivers/scsi/lpfc/lpfc.h
37341+++ b/drivers/scsi/lpfc/lpfc.h
37342@@ -420,7 +420,7 @@ struct lpfc_vport {
37343 struct dentry *debug_nodelist;
37344 struct dentry *vport_debugfs_root;
37345 struct lpfc_debugfs_trc *disc_trc;
37346- atomic_t disc_trc_cnt;
37347+ atomic_unchecked_t disc_trc_cnt;
37348 #endif
37349 uint8_t stat_data_enabled;
37350 uint8_t stat_data_blocked;
37351@@ -834,8 +834,8 @@ struct lpfc_hba {
37352 struct timer_list fabric_block_timer;
37353 unsigned long bit_flags;
37354 #define FABRIC_COMANDS_BLOCKED 0
37355- atomic_t num_rsrc_err;
37356- atomic_t num_cmd_success;
37357+ atomic_unchecked_t num_rsrc_err;
37358+ atomic_unchecked_t num_cmd_success;
37359 unsigned long last_rsrc_error_time;
37360 unsigned long last_ramp_down_time;
37361 unsigned long last_ramp_up_time;
37362@@ -871,7 +871,7 @@ struct lpfc_hba {
37363
37364 struct dentry *debug_slow_ring_trc;
37365 struct lpfc_debugfs_trc *slow_ring_trc;
37366- atomic_t slow_ring_trc_cnt;
37367+ atomic_unchecked_t slow_ring_trc_cnt;
37368 /* iDiag debugfs sub-directory */
37369 struct dentry *idiag_root;
37370 struct dentry *idiag_pci_cfg;
37371diff --git a/drivers/scsi/lpfc/lpfc_debugfs.c b/drivers/scsi/lpfc/lpfc_debugfs.c
37372index 3217d63..c417981 100644
37373--- a/drivers/scsi/lpfc/lpfc_debugfs.c
37374+++ b/drivers/scsi/lpfc/lpfc_debugfs.c
37375@@ -106,7 +106,7 @@ MODULE_PARM_DESC(lpfc_debugfs_mask_disc_trc,
37376
37377 #include <linux/debugfs.h>
37378
37379-static atomic_t lpfc_debugfs_seq_trc_cnt = ATOMIC_INIT(0);
37380+static atomic_unchecked_t lpfc_debugfs_seq_trc_cnt = ATOMIC_INIT(0);
37381 static unsigned long lpfc_debugfs_start_time = 0L;
37382
37383 /* iDiag */
37384@@ -147,7 +147,7 @@ lpfc_debugfs_disc_trc_data(struct lpfc_vport *vport, char *buf, int size)
37385 lpfc_debugfs_enable = 0;
37386
37387 len = 0;
37388- index = (atomic_read(&vport->disc_trc_cnt) + 1) &
37389+ index = (atomic_read_unchecked(&vport->disc_trc_cnt) + 1) &
37390 (lpfc_debugfs_max_disc_trc - 1);
37391 for (i = index; i < lpfc_debugfs_max_disc_trc; i++) {
37392 dtp = vport->disc_trc + i;
37393@@ -213,7 +213,7 @@ lpfc_debugfs_slow_ring_trc_data(struct lpfc_hba *phba, char *buf, int size)
37394 lpfc_debugfs_enable = 0;
37395
37396 len = 0;
37397- index = (atomic_read(&phba->slow_ring_trc_cnt) + 1) &
37398+ index = (atomic_read_unchecked(&phba->slow_ring_trc_cnt) + 1) &
37399 (lpfc_debugfs_max_slow_ring_trc - 1);
37400 for (i = index; i < lpfc_debugfs_max_slow_ring_trc; i++) {
37401 dtp = phba->slow_ring_trc + i;
37402@@ -636,14 +636,14 @@ lpfc_debugfs_disc_trc(struct lpfc_vport *vport, int mask, char *fmt,
37403 !vport || !vport->disc_trc)
37404 return;
37405
37406- index = atomic_inc_return(&vport->disc_trc_cnt) &
37407+ index = atomic_inc_return_unchecked(&vport->disc_trc_cnt) &
37408 (lpfc_debugfs_max_disc_trc - 1);
37409 dtp = vport->disc_trc + index;
37410 dtp->fmt = fmt;
37411 dtp->data1 = data1;
37412 dtp->data2 = data2;
37413 dtp->data3 = data3;
37414- dtp->seq_cnt = atomic_inc_return(&lpfc_debugfs_seq_trc_cnt);
37415+ dtp->seq_cnt = atomic_inc_return_unchecked(&lpfc_debugfs_seq_trc_cnt);
37416 dtp->jif = jiffies;
37417 #endif
37418 return;
37419@@ -674,14 +674,14 @@ lpfc_debugfs_slow_ring_trc(struct lpfc_hba *phba, char *fmt,
37420 !phba || !phba->slow_ring_trc)
37421 return;
37422
37423- index = atomic_inc_return(&phba->slow_ring_trc_cnt) &
37424+ index = atomic_inc_return_unchecked(&phba->slow_ring_trc_cnt) &
37425 (lpfc_debugfs_max_slow_ring_trc - 1);
37426 dtp = phba->slow_ring_trc + index;
37427 dtp->fmt = fmt;
37428 dtp->data1 = data1;
37429 dtp->data2 = data2;
37430 dtp->data3 = data3;
37431- dtp->seq_cnt = atomic_inc_return(&lpfc_debugfs_seq_trc_cnt);
37432+ dtp->seq_cnt = atomic_inc_return_unchecked(&lpfc_debugfs_seq_trc_cnt);
37433 dtp->jif = jiffies;
37434 #endif
37435 return;
37436@@ -4090,7 +4090,7 @@ lpfc_debugfs_initialize(struct lpfc_vport *vport)
37437 "slow_ring buffer\n");
37438 goto debug_failed;
37439 }
37440- atomic_set(&phba->slow_ring_trc_cnt, 0);
37441+ atomic_set_unchecked(&phba->slow_ring_trc_cnt, 0);
37442 memset(phba->slow_ring_trc, 0,
37443 (sizeof(struct lpfc_debugfs_trc) *
37444 lpfc_debugfs_max_slow_ring_trc));
37445@@ -4136,7 +4136,7 @@ lpfc_debugfs_initialize(struct lpfc_vport *vport)
37446 "buffer\n");
37447 goto debug_failed;
37448 }
37449- atomic_set(&vport->disc_trc_cnt, 0);
37450+ atomic_set_unchecked(&vport->disc_trc_cnt, 0);
37451
37452 snprintf(name, sizeof(name), "discovery_trace");
37453 vport->debug_disc_trc =
37454diff --git a/drivers/scsi/lpfc/lpfc_init.c b/drivers/scsi/lpfc/lpfc_init.c
37455index 45c1520..35ba744 100644
37456--- a/drivers/scsi/lpfc/lpfc_init.c
37457+++ b/drivers/scsi/lpfc/lpfc_init.c
37458@@ -10478,8 +10478,10 @@ lpfc_init(void)
37459 "misc_register returned with status %d", error);
37460
37461 if (lpfc_enable_npiv) {
37462- lpfc_transport_functions.vport_create = lpfc_vport_create;
37463- lpfc_transport_functions.vport_delete = lpfc_vport_delete;
37464+ pax_open_kernel();
37465+ *(void **)&lpfc_transport_functions.vport_create = lpfc_vport_create;
37466+ *(void **)&lpfc_transport_functions.vport_delete = lpfc_vport_delete;
37467+ pax_close_kernel();
37468 }
37469 lpfc_transport_template =
37470 fc_attach_transport(&lpfc_transport_functions);
37471diff --git a/drivers/scsi/lpfc/lpfc_scsi.c b/drivers/scsi/lpfc/lpfc_scsi.c
37472index 925975d..0f1fc07 100644
37473--- a/drivers/scsi/lpfc/lpfc_scsi.c
37474+++ b/drivers/scsi/lpfc/lpfc_scsi.c
37475@@ -311,7 +311,7 @@ lpfc_rampdown_queue_depth(struct lpfc_hba *phba)
37476 uint32_t evt_posted;
37477
37478 spin_lock_irqsave(&phba->hbalock, flags);
37479- atomic_inc(&phba->num_rsrc_err);
37480+ atomic_inc_unchecked(&phba->num_rsrc_err);
37481 phba->last_rsrc_error_time = jiffies;
37482
37483 if ((phba->last_ramp_down_time + QUEUE_RAMP_DOWN_INTERVAL) > jiffies) {
37484@@ -352,7 +352,7 @@ lpfc_rampup_queue_depth(struct lpfc_vport *vport,
37485 unsigned long flags;
37486 struct lpfc_hba *phba = vport->phba;
37487 uint32_t evt_posted;
37488- atomic_inc(&phba->num_cmd_success);
37489+ atomic_inc_unchecked(&phba->num_cmd_success);
37490
37491 if (vport->cfg_lun_queue_depth <= queue_depth)
37492 return;
37493@@ -396,8 +396,8 @@ lpfc_ramp_down_queue_handler(struct lpfc_hba *phba)
37494 unsigned long num_rsrc_err, num_cmd_success;
37495 int i;
37496
37497- num_rsrc_err = atomic_read(&phba->num_rsrc_err);
37498- num_cmd_success = atomic_read(&phba->num_cmd_success);
37499+ num_rsrc_err = atomic_read_unchecked(&phba->num_rsrc_err);
37500+ num_cmd_success = atomic_read_unchecked(&phba->num_cmd_success);
37501
37502 /*
37503 * The error and success command counters are global per
37504@@ -425,8 +425,8 @@ lpfc_ramp_down_queue_handler(struct lpfc_hba *phba)
37505 }
37506 }
37507 lpfc_destroy_vport_work_array(phba, vports);
37508- atomic_set(&phba->num_rsrc_err, 0);
37509- atomic_set(&phba->num_cmd_success, 0);
37510+ atomic_set_unchecked(&phba->num_rsrc_err, 0);
37511+ atomic_set_unchecked(&phba->num_cmd_success, 0);
37512 }
37513
37514 /**
37515@@ -460,8 +460,8 @@ lpfc_ramp_up_queue_handler(struct lpfc_hba *phba)
37516 }
37517 }
37518 lpfc_destroy_vport_work_array(phba, vports);
37519- atomic_set(&phba->num_rsrc_err, 0);
37520- atomic_set(&phba->num_cmd_success, 0);
37521+ atomic_set_unchecked(&phba->num_rsrc_err, 0);
37522+ atomic_set_unchecked(&phba->num_cmd_success, 0);
37523 }
37524
37525 /**
37526diff --git a/drivers/scsi/pmcraid.c b/drivers/scsi/pmcraid.c
37527index ea8a0b4..812a124 100644
37528--- a/drivers/scsi/pmcraid.c
37529+++ b/drivers/scsi/pmcraid.c
37530@@ -200,8 +200,8 @@ static int pmcraid_slave_alloc(struct scsi_device *scsi_dev)
37531 res->scsi_dev = scsi_dev;
37532 scsi_dev->hostdata = res;
37533 res->change_detected = 0;
37534- atomic_set(&res->read_failures, 0);
37535- atomic_set(&res->write_failures, 0);
37536+ atomic_set_unchecked(&res->read_failures, 0);
37537+ atomic_set_unchecked(&res->write_failures, 0);
37538 rc = 0;
37539 }
37540 spin_unlock_irqrestore(&pinstance->resource_lock, lock_flags);
37541@@ -2676,9 +2676,9 @@ static int pmcraid_error_handler(struct pmcraid_cmd *cmd)
37542
37543 /* If this was a SCSI read/write command keep count of errors */
37544 if (SCSI_CMD_TYPE(scsi_cmd->cmnd[0]) == SCSI_READ_CMD)
37545- atomic_inc(&res->read_failures);
37546+ atomic_inc_unchecked(&res->read_failures);
37547 else if (SCSI_CMD_TYPE(scsi_cmd->cmnd[0]) == SCSI_WRITE_CMD)
37548- atomic_inc(&res->write_failures);
37549+ atomic_inc_unchecked(&res->write_failures);
37550
37551 if (!RES_IS_GSCSI(res->cfg_entry) &&
37552 masked_ioasc != PMCRAID_IOASC_HW_DEVICE_BUS_STATUS_ERROR) {
37553@@ -3534,7 +3534,7 @@ static int pmcraid_queuecommand_lck(
37554 * block of scsi_cmd which is re-used (e.g. cancel/abort), which uses
37555 * hrrq_id assigned here in queuecommand
37556 */
37557- ioarcb->hrrq_id = atomic_add_return(1, &(pinstance->last_message_id)) %
37558+ ioarcb->hrrq_id = atomic_add_return_unchecked(1, &(pinstance->last_message_id)) %
37559 pinstance->num_hrrq;
37560 cmd->cmd_done = pmcraid_io_done;
37561
37562@@ -3859,7 +3859,7 @@ static long pmcraid_ioctl_passthrough(
37563 * block of scsi_cmd which is re-used (e.g. cancel/abort), which uses
37564 * hrrq_id assigned here in queuecommand
37565 */
37566- ioarcb->hrrq_id = atomic_add_return(1, &(pinstance->last_message_id)) %
37567+ ioarcb->hrrq_id = atomic_add_return_unchecked(1, &(pinstance->last_message_id)) %
37568 pinstance->num_hrrq;
37569
37570 if (request_size) {
37571@@ -4497,7 +4497,7 @@ static void pmcraid_worker_function(struct work_struct *workp)
37572
37573 pinstance = container_of(workp, struct pmcraid_instance, worker_q);
37574 /* add resources only after host is added into system */
37575- if (!atomic_read(&pinstance->expose_resources))
37576+ if (!atomic_read_unchecked(&pinstance->expose_resources))
37577 return;
37578
37579 fw_version = be16_to_cpu(pinstance->inq_data->fw_version);
37580@@ -5331,8 +5331,8 @@ static int __devinit pmcraid_init_instance(
37581 init_waitqueue_head(&pinstance->reset_wait_q);
37582
37583 atomic_set(&pinstance->outstanding_cmds, 0);
37584- atomic_set(&pinstance->last_message_id, 0);
37585- atomic_set(&pinstance->expose_resources, 0);
37586+ atomic_set_unchecked(&pinstance->last_message_id, 0);
37587+ atomic_set_unchecked(&pinstance->expose_resources, 0);
37588
37589 INIT_LIST_HEAD(&pinstance->free_res_q);
37590 INIT_LIST_HEAD(&pinstance->used_res_q);
37591@@ -6047,7 +6047,7 @@ static int __devinit pmcraid_probe(
37592 /* Schedule worker thread to handle CCN and take care of adding and
37593 * removing devices to OS
37594 */
37595- atomic_set(&pinstance->expose_resources, 1);
37596+ atomic_set_unchecked(&pinstance->expose_resources, 1);
37597 schedule_work(&pinstance->worker_q);
37598 return rc;
37599
37600diff --git a/drivers/scsi/pmcraid.h b/drivers/scsi/pmcraid.h
37601index e1d150f..6c6df44 100644
37602--- a/drivers/scsi/pmcraid.h
37603+++ b/drivers/scsi/pmcraid.h
37604@@ -748,7 +748,7 @@ struct pmcraid_instance {
37605 struct pmcraid_isr_param hrrq_vector[PMCRAID_NUM_MSIX_VECTORS];
37606
37607 /* Message id as filled in last fired IOARCB, used to identify HRRQ */
37608- atomic_t last_message_id;
37609+ atomic_unchecked_t last_message_id;
37610
37611 /* configuration table */
37612 struct pmcraid_config_table *cfg_table;
37613@@ -777,7 +777,7 @@ struct pmcraid_instance {
37614 atomic_t outstanding_cmds;
37615
37616 /* should add/delete resources to mid-layer now ?*/
37617- atomic_t expose_resources;
37618+ atomic_unchecked_t expose_resources;
37619
37620
37621
37622@@ -813,8 +813,8 @@ struct pmcraid_resource_entry {
37623 struct pmcraid_config_table_entry_ext cfg_entry_ext;
37624 };
37625 struct scsi_device *scsi_dev; /* Link scsi_device structure */
37626- atomic_t read_failures; /* count of failed READ commands */
37627- atomic_t write_failures; /* count of failed WRITE commands */
37628+ atomic_unchecked_t read_failures; /* count of failed READ commands */
37629+ atomic_unchecked_t write_failures; /* count of failed WRITE commands */
37630
37631 /* To indicate add/delete/modify during CCN */
37632 u8 change_detected;
37633diff --git a/drivers/scsi/qla2xxx/qla_attr.c b/drivers/scsi/qla2xxx/qla_attr.c
37634index 5ab9530..2dd80f7 100644
37635--- a/drivers/scsi/qla2xxx/qla_attr.c
37636+++ b/drivers/scsi/qla2xxx/qla_attr.c
37637@@ -1855,7 +1855,7 @@ qla24xx_vport_disable(struct fc_vport *fc_vport, bool disable)
37638 return 0;
37639 }
37640
37641-struct fc_function_template qla2xxx_transport_functions = {
37642+fc_function_template_no_const qla2xxx_transport_functions = {
37643
37644 .show_host_node_name = 1,
37645 .show_host_port_name = 1,
37646@@ -1902,7 +1902,7 @@ struct fc_function_template qla2xxx_transport_functions = {
37647 .bsg_timeout = qla24xx_bsg_timeout,
37648 };
37649
37650-struct fc_function_template qla2xxx_transport_vport_functions = {
37651+fc_function_template_no_const qla2xxx_transport_vport_functions = {
37652
37653 .show_host_node_name = 1,
37654 .show_host_port_name = 1,
37655diff --git a/drivers/scsi/qla2xxx/qla_def.h b/drivers/scsi/qla2xxx/qla_def.h
37656index 39007f5..7fafc64 100644
37657--- a/drivers/scsi/qla2xxx/qla_def.h
37658+++ b/drivers/scsi/qla2xxx/qla_def.h
37659@@ -2284,7 +2284,7 @@ struct isp_operations {
37660 int (*start_scsi) (srb_t *);
37661 int (*abort_isp) (struct scsi_qla_host *);
37662 int (*iospace_config)(struct qla_hw_data*);
37663-};
37664+} __no_const;
37665
37666 /* MSI-X Support *************************************************************/
37667
37668diff --git a/drivers/scsi/qla2xxx/qla_gbl.h b/drivers/scsi/qla2xxx/qla_gbl.h
37669index 9eacd2d..d79629c 100644
37670--- a/drivers/scsi/qla2xxx/qla_gbl.h
37671+++ b/drivers/scsi/qla2xxx/qla_gbl.h
37672@@ -484,8 +484,8 @@ extern void qla2x00_get_sym_node_name(scsi_qla_host_t *, uint8_t *);
37673 struct device_attribute;
37674 extern struct device_attribute *qla2x00_host_attrs[];
37675 struct fc_function_template;
37676-extern struct fc_function_template qla2xxx_transport_functions;
37677-extern struct fc_function_template qla2xxx_transport_vport_functions;
37678+extern fc_function_template_no_const qla2xxx_transport_functions;
37679+extern fc_function_template_no_const qla2xxx_transport_vport_functions;
37680 extern void qla2x00_alloc_sysfs_attr(scsi_qla_host_t *);
37681 extern void qla2x00_free_sysfs_attr(scsi_qla_host_t *);
37682 extern void qla2x00_init_host_attr(scsi_qla_host_t *);
37683diff --git a/drivers/scsi/qla4xxx/ql4_def.h b/drivers/scsi/qla4xxx/ql4_def.h
37684index 7fdba7f..1b4b2c2 100644
37685--- a/drivers/scsi/qla4xxx/ql4_def.h
37686+++ b/drivers/scsi/qla4xxx/ql4_def.h
37687@@ -268,7 +268,7 @@ struct ddb_entry {
37688 * (4000 only) */
37689 atomic_t relogin_timer; /* Max Time to wait for
37690 * relogin to complete */
37691- atomic_t relogin_retry_count; /* Num of times relogin has been
37692+ atomic_unchecked_t relogin_retry_count; /* Num of times relogin has been
37693 * retried */
37694 uint32_t default_time2wait; /* Default Min time between
37695 * relogins (+aens) */
37696diff --git a/drivers/scsi/qla4xxx/ql4_os.c b/drivers/scsi/qla4xxx/ql4_os.c
37697index 9da4266..377b3b6 100644
37698--- a/drivers/scsi/qla4xxx/ql4_os.c
37699+++ b/drivers/scsi/qla4xxx/ql4_os.c
37700@@ -2615,12 +2615,12 @@ static void qla4xxx_check_relogin_flash_ddb(struct iscsi_cls_session *cls_sess)
37701 */
37702 if (!iscsi_is_session_online(cls_sess)) {
37703 /* Reset retry relogin timer */
37704- atomic_inc(&ddb_entry->relogin_retry_count);
37705+ atomic_inc_unchecked(&ddb_entry->relogin_retry_count);
37706 DEBUG2(ql4_printk(KERN_INFO, ha,
37707 "%s: index[%d] relogin timed out-retrying"
37708 " relogin (%d), retry (%d)\n", __func__,
37709 ddb_entry->fw_ddb_index,
37710- atomic_read(&ddb_entry->relogin_retry_count),
37711+ atomic_read_unchecked(&ddb_entry->relogin_retry_count),
37712 ddb_entry->default_time2wait + 4));
37713 set_bit(DPC_RELOGIN_DEVICE, &ha->dpc_flags);
37714 atomic_set(&ddb_entry->retry_relogin_timer,
37715@@ -4635,7 +4635,7 @@ static void qla4xxx_setup_flash_ddb_entry(struct scsi_qla_host *ha,
37716
37717 atomic_set(&ddb_entry->retry_relogin_timer, INVALID_ENTRY);
37718 atomic_set(&ddb_entry->relogin_timer, 0);
37719- atomic_set(&ddb_entry->relogin_retry_count, 0);
37720+ atomic_set_unchecked(&ddb_entry->relogin_retry_count, 0);
37721 def_timeout = le16_to_cpu(ddb_entry->fw_ddb_entry.def_timeout);
37722 ddb_entry->default_relogin_timeout =
37723 (def_timeout > LOGIN_TOV) && (def_timeout < LOGIN_TOV * 10) ?
37724diff --git a/drivers/scsi/scsi.c b/drivers/scsi/scsi.c
37725index 2936b44..546ecdb 100644
37726--- a/drivers/scsi/scsi.c
37727+++ b/drivers/scsi/scsi.c
37728@@ -660,7 +660,7 @@ int scsi_dispatch_cmd(struct scsi_cmnd *cmd)
37729 unsigned long timeout;
37730 int rtn = 0;
37731
37732- atomic_inc(&cmd->device->iorequest_cnt);
37733+ atomic_inc_unchecked(&cmd->device->iorequest_cnt);
37734
37735 /* check if the device is still usable */
37736 if (unlikely(cmd->device->sdev_state == SDEV_DEL)) {
37737diff --git a/drivers/scsi/scsi_lib.c b/drivers/scsi/scsi_lib.c
37738index faa790f..7e351ddd 100644
37739--- a/drivers/scsi/scsi_lib.c
37740+++ b/drivers/scsi/scsi_lib.c
37741@@ -1442,7 +1442,7 @@ static void scsi_kill_request(struct request *req, struct request_queue *q)
37742 shost = sdev->host;
37743 scsi_init_cmd_errh(cmd);
37744 cmd->result = DID_NO_CONNECT << 16;
37745- atomic_inc(&cmd->device->iorequest_cnt);
37746+ atomic_inc_unchecked(&cmd->device->iorequest_cnt);
37747
37748 /*
37749 * SCSI request completion path will do scsi_device_unbusy(),
37750@@ -1468,9 +1468,9 @@ static void scsi_softirq_done(struct request *rq)
37751
37752 INIT_LIST_HEAD(&cmd->eh_entry);
37753
37754- atomic_inc(&cmd->device->iodone_cnt);
37755+ atomic_inc_unchecked(&cmd->device->iodone_cnt);
37756 if (cmd->result)
37757- atomic_inc(&cmd->device->ioerr_cnt);
37758+ atomic_inc_unchecked(&cmd->device->ioerr_cnt);
37759
37760 disposition = scsi_decide_disposition(cmd);
37761 if (disposition != SUCCESS &&
37762diff --git a/drivers/scsi/scsi_sysfs.c b/drivers/scsi/scsi_sysfs.c
37763index ce5224c..8c6d071 100644
37764--- a/drivers/scsi/scsi_sysfs.c
37765+++ b/drivers/scsi/scsi_sysfs.c
37766@@ -661,7 +661,7 @@ show_iostat_##field(struct device *dev, struct device_attribute *attr, \
37767 char *buf) \
37768 { \
37769 struct scsi_device *sdev = to_scsi_device(dev); \
37770- unsigned long long count = atomic_read(&sdev->field); \
37771+ unsigned long long count = atomic_read_unchecked(&sdev->field); \
37772 return snprintf(buf, 20, "0x%llx\n", count); \
37773 } \
37774 static DEVICE_ATTR(field, S_IRUGO, show_iostat_##field, NULL)
37775diff --git a/drivers/scsi/scsi_tgt_lib.c b/drivers/scsi/scsi_tgt_lib.c
37776index 84a1fdf..693b0d6 100644
37777--- a/drivers/scsi/scsi_tgt_lib.c
37778+++ b/drivers/scsi/scsi_tgt_lib.c
37779@@ -362,7 +362,7 @@ static int scsi_map_user_pages(struct scsi_tgt_cmd *tcmd, struct scsi_cmnd *cmd,
37780 int err;
37781
37782 dprintk("%lx %u\n", uaddr, len);
37783- err = blk_rq_map_user(q, rq, NULL, (void *)uaddr, len, GFP_KERNEL);
37784+ err = blk_rq_map_user(q, rq, NULL, (void __user *)uaddr, len, GFP_KERNEL);
37785 if (err) {
37786 /*
37787 * TODO: need to fixup sg_tablesize, max_segment_size,
37788diff --git a/drivers/scsi/scsi_transport_fc.c b/drivers/scsi/scsi_transport_fc.c
37789index e894ca7..de9d7660 100644
37790--- a/drivers/scsi/scsi_transport_fc.c
37791+++ b/drivers/scsi/scsi_transport_fc.c
37792@@ -498,7 +498,7 @@ static DECLARE_TRANSPORT_CLASS(fc_vport_class,
37793 * Netlink Infrastructure
37794 */
37795
37796-static atomic_t fc_event_seq;
37797+static atomic_unchecked_t fc_event_seq;
37798
37799 /**
37800 * fc_get_event_number - Obtain the next sequential FC event number
37801@@ -511,7 +511,7 @@ static atomic_t fc_event_seq;
37802 u32
37803 fc_get_event_number(void)
37804 {
37805- return atomic_add_return(1, &fc_event_seq);
37806+ return atomic_add_return_unchecked(1, &fc_event_seq);
37807 }
37808 EXPORT_SYMBOL(fc_get_event_number);
37809
37810@@ -659,7 +659,7 @@ static __init int fc_transport_init(void)
37811 {
37812 int error;
37813
37814- atomic_set(&fc_event_seq, 0);
37815+ atomic_set_unchecked(&fc_event_seq, 0);
37816
37817 error = transport_class_register(&fc_host_class);
37818 if (error)
37819@@ -849,7 +849,7 @@ static int fc_str_to_dev_loss(const char *buf, unsigned long *val)
37820 char *cp;
37821
37822 *val = simple_strtoul(buf, &cp, 0);
37823- if ((*cp && (*cp != '\n')) || (*val < 0))
37824+ if (*cp && (*cp != '\n'))
37825 return -EINVAL;
37826 /*
37827 * Check for overflow; dev_loss_tmo is u32
37828diff --git a/drivers/scsi/scsi_transport_iscsi.c b/drivers/scsi/scsi_transport_iscsi.c
37829index fa1dfaa..4bb620c 100644
37830--- a/drivers/scsi/scsi_transport_iscsi.c
37831+++ b/drivers/scsi/scsi_transport_iscsi.c
37832@@ -79,7 +79,7 @@ struct iscsi_internal {
37833 struct transport_container session_cont;
37834 };
37835
37836-static atomic_t iscsi_session_nr; /* sysfs session id for next new session */
37837+static atomic_unchecked_t iscsi_session_nr; /* sysfs session id for next new session */
37838 static struct workqueue_struct *iscsi_eh_timer_workq;
37839
37840 static DEFINE_IDA(iscsi_sess_ida);
37841@@ -1064,7 +1064,7 @@ int iscsi_add_session(struct iscsi_cls_session *session, unsigned int target_id)
37842 int err;
37843
37844 ihost = shost->shost_data;
37845- session->sid = atomic_add_return(1, &iscsi_session_nr);
37846+ session->sid = atomic_add_return_unchecked(1, &iscsi_session_nr);
37847
37848 if (target_id == ISCSI_MAX_TARGET) {
37849 id = ida_simple_get(&iscsi_sess_ida, 0, 0, GFP_KERNEL);
37850@@ -2943,7 +2943,7 @@ static __init int iscsi_transport_init(void)
37851 printk(KERN_INFO "Loading iSCSI transport class v%s.\n",
37852 ISCSI_TRANSPORT_VERSION);
37853
37854- atomic_set(&iscsi_session_nr, 0);
37855+ atomic_set_unchecked(&iscsi_session_nr, 0);
37856
37857 err = class_register(&iscsi_transport_class);
37858 if (err)
37859diff --git a/drivers/scsi/scsi_transport_srp.c b/drivers/scsi/scsi_transport_srp.c
37860index 21a045e..ec89e03 100644
37861--- a/drivers/scsi/scsi_transport_srp.c
37862+++ b/drivers/scsi/scsi_transport_srp.c
37863@@ -33,7 +33,7 @@
37864 #include "scsi_transport_srp_internal.h"
37865
37866 struct srp_host_attrs {
37867- atomic_t next_port_id;
37868+ atomic_unchecked_t next_port_id;
37869 };
37870 #define to_srp_host_attrs(host) ((struct srp_host_attrs *)(host)->shost_data)
37871
37872@@ -62,7 +62,7 @@ static int srp_host_setup(struct transport_container *tc, struct device *dev,
37873 struct Scsi_Host *shost = dev_to_shost(dev);
37874 struct srp_host_attrs *srp_host = to_srp_host_attrs(shost);
37875
37876- atomic_set(&srp_host->next_port_id, 0);
37877+ atomic_set_unchecked(&srp_host->next_port_id, 0);
37878 return 0;
37879 }
37880
37881@@ -211,7 +211,7 @@ struct srp_rport *srp_rport_add(struct Scsi_Host *shost,
37882 memcpy(rport->port_id, ids->port_id, sizeof(rport->port_id));
37883 rport->roles = ids->roles;
37884
37885- id = atomic_inc_return(&to_srp_host_attrs(shost)->next_port_id);
37886+ id = atomic_inc_return_unchecked(&to_srp_host_attrs(shost)->next_port_id);
37887 dev_set_name(&rport->dev, "port-%d:%d", shost->host_no, id);
37888
37889 transport_setup_device(&rport->dev);
37890diff --git a/drivers/scsi/sd.c b/drivers/scsi/sd.c
37891index 4df73e5..b691c58 100644
37892--- a/drivers/scsi/sd.c
37893+++ b/drivers/scsi/sd.c
37894@@ -2709,7 +2709,7 @@ static int sd_probe(struct device *dev)
37895 sdkp->disk = gd;
37896 sdkp->index = index;
37897 atomic_set(&sdkp->openers, 0);
37898- atomic_set(&sdkp->device->ioerr_cnt, 0);
37899+ atomic_set_unchecked(&sdkp->device->ioerr_cnt, 0);
37900
37901 if (!sdp->request_queue->rq_timeout) {
37902 if (sdp->type != TYPE_MOD)
37903diff --git a/drivers/scsi/sg.c b/drivers/scsi/sg.c
37904index 9c5c5f2..8414557 100644
37905--- a/drivers/scsi/sg.c
37906+++ b/drivers/scsi/sg.c
37907@@ -1101,7 +1101,7 @@ sg_ioctl(struct file *filp, unsigned int cmd_in, unsigned long arg)
37908 sdp->disk->disk_name,
37909 MKDEV(SCSI_GENERIC_MAJOR, sdp->index),
37910 NULL,
37911- (char *)arg);
37912+ (char __user *)arg);
37913 case BLKTRACESTART:
37914 return blk_trace_startstop(sdp->device->request_queue, 1);
37915 case BLKTRACESTOP:
37916diff --git a/drivers/spi/spi.c b/drivers/spi/spi.c
37917index 84c2861..ece0a31 100644
37918--- a/drivers/spi/spi.c
37919+++ b/drivers/spi/spi.c
37920@@ -1453,7 +1453,7 @@ int spi_bus_unlock(struct spi_master *master)
37921 EXPORT_SYMBOL_GPL(spi_bus_unlock);
37922
37923 /* portable code must never pass more than 32 bytes */
37924-#define SPI_BUFSIZ max(32,SMP_CACHE_BYTES)
37925+#define SPI_BUFSIZ max(32UL,SMP_CACHE_BYTES)
37926
37927 static u8 *buf;
37928
37929diff --git a/drivers/staging/octeon/ethernet-rx.c b/drivers/staging/octeon/ethernet-rx.c
37930index 34afc16..ffe44dd 100644
37931--- a/drivers/staging/octeon/ethernet-rx.c
37932+++ b/drivers/staging/octeon/ethernet-rx.c
37933@@ -421,11 +421,11 @@ static int cvm_oct_napi_poll(struct napi_struct *napi, int budget)
37934 /* Increment RX stats for virtual ports */
37935 if (work->ipprt >= CVMX_PIP_NUM_INPUT_PORTS) {
37936 #ifdef CONFIG_64BIT
37937- atomic64_add(1, (atomic64_t *)&priv->stats.rx_packets);
37938- atomic64_add(skb->len, (atomic64_t *)&priv->stats.rx_bytes);
37939+ atomic64_add_unchecked(1, (atomic64_unchecked_t *)&priv->stats.rx_packets);
37940+ atomic64_add_unchecked(skb->len, (atomic64_unchecked_t *)&priv->stats.rx_bytes);
37941 #else
37942- atomic_add(1, (atomic_t *)&priv->stats.rx_packets);
37943- atomic_add(skb->len, (atomic_t *)&priv->stats.rx_bytes);
37944+ atomic_add_unchecked(1, (atomic_unchecked_t *)&priv->stats.rx_packets);
37945+ atomic_add_unchecked(skb->len, (atomic_unchecked_t *)&priv->stats.rx_bytes);
37946 #endif
37947 }
37948 netif_receive_skb(skb);
37949@@ -437,9 +437,9 @@ static int cvm_oct_napi_poll(struct napi_struct *napi, int budget)
37950 dev->name);
37951 */
37952 #ifdef CONFIG_64BIT
37953- atomic64_add(1, (atomic64_t *)&priv->stats.rx_dropped);
37954+ atomic64_unchecked_add(1, (atomic64_unchecked_t *)&priv->stats.rx_dropped);
37955 #else
37956- atomic_add(1, (atomic_t *)&priv->stats.rx_dropped);
37957+ atomic_add_unchecked(1, (atomic_unchecked_t *)&priv->stats.rx_dropped);
37958 #endif
37959 dev_kfree_skb_irq(skb);
37960 }
37961diff --git a/drivers/staging/octeon/ethernet.c b/drivers/staging/octeon/ethernet.c
37962index 683bedc..86dba9a 100644
37963--- a/drivers/staging/octeon/ethernet.c
37964+++ b/drivers/staging/octeon/ethernet.c
37965@@ -252,11 +252,11 @@ static struct net_device_stats *cvm_oct_common_get_stats(struct net_device *dev)
37966 * since the RX tasklet also increments it.
37967 */
37968 #ifdef CONFIG_64BIT
37969- atomic64_add(rx_status.dropped_packets,
37970- (atomic64_t *)&priv->stats.rx_dropped);
37971+ atomic64_add_unchecked(rx_status.dropped_packets,
37972+ (atomic64_unchecked_t *)&priv->stats.rx_dropped);
37973 #else
37974- atomic_add(rx_status.dropped_packets,
37975- (atomic_t *)&priv->stats.rx_dropped);
37976+ atomic_add_unchecked(rx_status.dropped_packets,
37977+ (atomic_unchecked_t *)&priv->stats.rx_dropped);
37978 #endif
37979 }
37980
37981diff --git a/drivers/staging/omapdrm/omap_drv.c b/drivers/staging/omapdrm/omap_drv.c
37982index 4beab94..44149ee 100644
37983--- a/drivers/staging/omapdrm/omap_drv.c
37984+++ b/drivers/staging/omapdrm/omap_drv.c
37985@@ -761,7 +761,6 @@ static struct drm_driver omap_drm_driver = {
37986 .irq_postinstall = dev_irq_postinstall,
37987 .irq_uninstall = dev_irq_uninstall,
37988 .irq_handler = dev_irq_handler,
37989- .reclaim_buffers = drm_core_reclaim_buffers,
37990 #ifdef CONFIG_DEBUG_FS
37991 .debugfs_init = omap_debugfs_init,
37992 .debugfs_cleanup = omap_debugfs_cleanup,
37993diff --git a/drivers/staging/rtl8712/rtl871x_io.h b/drivers/staging/rtl8712/rtl871x_io.h
37994index dc23395..cf7e9b1 100644
37995--- a/drivers/staging/rtl8712/rtl871x_io.h
37996+++ b/drivers/staging/rtl8712/rtl871x_io.h
37997@@ -108,7 +108,7 @@ struct _io_ops {
37998 u8 *pmem);
37999 u32 (*_write_port)(struct intf_hdl *pintfhdl, u32 addr, u32 cnt,
38000 u8 *pmem);
38001-};
38002+} __no_const;
38003
38004 struct io_req {
38005 struct list_head list;
38006diff --git a/drivers/staging/sbe-2t3e3/netdev.c b/drivers/staging/sbe-2t3e3/netdev.c
38007index c7b5e8b..783d6cb 100644
38008--- a/drivers/staging/sbe-2t3e3/netdev.c
38009+++ b/drivers/staging/sbe-2t3e3/netdev.c
38010@@ -51,7 +51,7 @@ int t3e3_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
38011 t3e3_if_config(sc, cmd_2t3e3, (char *)&param, &resp, &rlen);
38012
38013 if (rlen)
38014- if (copy_to_user(data, &resp, rlen))
38015+ if (rlen > sizeof resp || copy_to_user(data, &resp, rlen))
38016 return -EFAULT;
38017
38018 return 0;
38019diff --git a/drivers/staging/usbip/usbip_common.h b/drivers/staging/usbip/usbip_common.h
38020index 5d89c0f..9261317 100644
38021--- a/drivers/staging/usbip/usbip_common.h
38022+++ b/drivers/staging/usbip/usbip_common.h
38023@@ -289,7 +289,7 @@ struct usbip_device {
38024 void (*shutdown)(struct usbip_device *);
38025 void (*reset)(struct usbip_device *);
38026 void (*unusable)(struct usbip_device *);
38027- } eh_ops;
38028+ } __no_const eh_ops;
38029 };
38030
38031 #define kthread_get_run(threadfn, data, namefmt, ...) \
38032diff --git a/drivers/staging/usbip/vhci.h b/drivers/staging/usbip/vhci.h
38033index c66b8b3..a4a035b 100644
38034--- a/drivers/staging/usbip/vhci.h
38035+++ b/drivers/staging/usbip/vhci.h
38036@@ -83,7 +83,7 @@ struct vhci_hcd {
38037 unsigned resuming:1;
38038 unsigned long re_timeout;
38039
38040- atomic_t seqnum;
38041+ atomic_unchecked_t seqnum;
38042
38043 /*
38044 * NOTE:
38045diff --git a/drivers/staging/usbip/vhci_hcd.c b/drivers/staging/usbip/vhci_hcd.c
38046index 12a9a5f..afd8295 100644
38047--- a/drivers/staging/usbip/vhci_hcd.c
38048+++ b/drivers/staging/usbip/vhci_hcd.c
38049@@ -471,7 +471,7 @@ static void vhci_tx_urb(struct urb *urb)
38050 return;
38051 }
38052
38053- priv->seqnum = atomic_inc_return(&the_controller->seqnum);
38054+ priv->seqnum = atomic_inc_return_unchecked(&the_controller->seqnum);
38055 if (priv->seqnum == 0xffff)
38056 dev_info(&urb->dev->dev, "seqnum max\n");
38057
38058@@ -723,7 +723,7 @@ static int vhci_urb_dequeue(struct usb_hcd *hcd, struct urb *urb, int status)
38059 return -ENOMEM;
38060 }
38061
38062- unlink->seqnum = atomic_inc_return(&the_controller->seqnum);
38063+ unlink->seqnum = atomic_inc_return_unchecked(&the_controller->seqnum);
38064 if (unlink->seqnum == 0xffff)
38065 pr_info("seqnum max\n");
38066
38067@@ -911,7 +911,7 @@ static int vhci_start(struct usb_hcd *hcd)
38068 vdev->rhport = rhport;
38069 }
38070
38071- atomic_set(&vhci->seqnum, 0);
38072+ atomic_set_unchecked(&vhci->seqnum, 0);
38073 spin_lock_init(&vhci->lock);
38074
38075 hcd->power_budget = 0; /* no limit */
38076diff --git a/drivers/staging/usbip/vhci_rx.c b/drivers/staging/usbip/vhci_rx.c
38077index f0eaf04..5a82e06 100644
38078--- a/drivers/staging/usbip/vhci_rx.c
38079+++ b/drivers/staging/usbip/vhci_rx.c
38080@@ -77,7 +77,7 @@ static void vhci_recv_ret_submit(struct vhci_device *vdev,
38081 if (!urb) {
38082 pr_err("cannot find a urb of seqnum %u\n", pdu->base.seqnum);
38083 pr_info("max seqnum %d\n",
38084- atomic_read(&the_controller->seqnum));
38085+ atomic_read_unchecked(&the_controller->seqnum));
38086 usbip_event_add(ud, VDEV_EVENT_ERROR_TCP);
38087 return;
38088 }
38089diff --git a/drivers/staging/vt6655/hostap.c b/drivers/staging/vt6655/hostap.c
38090index 6ac6f45..1b208ba 100644
38091--- a/drivers/staging/vt6655/hostap.c
38092+++ b/drivers/staging/vt6655/hostap.c
38093@@ -73,14 +73,13 @@ static int msglevel =MSG_LEVEL_INFO;
38094 *
38095 */
38096
38097+static net_device_ops_no_const apdev_netdev_ops;
38098+
38099 static int hostap_enable_hostapd(PSDevice pDevice, int rtnl_locked)
38100 {
38101 PSDevice apdev_priv;
38102 struct net_device *dev = pDevice->dev;
38103 int ret;
38104- const struct net_device_ops apdev_netdev_ops = {
38105- .ndo_start_xmit = pDevice->tx_80211,
38106- };
38107
38108 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "%s: Enabling hostapd mode\n", dev->name);
38109
38110@@ -92,6 +91,8 @@ static int hostap_enable_hostapd(PSDevice pDevice, int rtnl_locked)
38111 *apdev_priv = *pDevice;
38112 memcpy(pDevice->apdev->dev_addr, dev->dev_addr, ETH_ALEN);
38113
38114+ /* only half broken now */
38115+ apdev_netdev_ops.ndo_start_xmit = pDevice->tx_80211;
38116 pDevice->apdev->netdev_ops = &apdev_netdev_ops;
38117
38118 pDevice->apdev->type = ARPHRD_IEEE80211;
38119diff --git a/drivers/staging/vt6656/hostap.c b/drivers/staging/vt6656/hostap.c
38120index 682002a..35ed5cf 100644
38121--- a/drivers/staging/vt6656/hostap.c
38122+++ b/drivers/staging/vt6656/hostap.c
38123@@ -60,14 +60,13 @@ static int msglevel =MSG_LEVEL_INFO;
38124 *
38125 */
38126
38127+static net_device_ops_no_const apdev_netdev_ops;
38128+
38129 static int hostap_enable_hostapd(PSDevice pDevice, int rtnl_locked)
38130 {
38131 PSDevice apdev_priv;
38132 struct net_device *dev = pDevice->dev;
38133 int ret;
38134- const struct net_device_ops apdev_netdev_ops = {
38135- .ndo_start_xmit = pDevice->tx_80211,
38136- };
38137
38138 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "%s: Enabling hostapd mode\n", dev->name);
38139
38140@@ -79,6 +78,8 @@ static int hostap_enable_hostapd(PSDevice pDevice, int rtnl_locked)
38141 *apdev_priv = *pDevice;
38142 memcpy(pDevice->apdev->dev_addr, dev->dev_addr, ETH_ALEN);
38143
38144+ /* only half broken now */
38145+ apdev_netdev_ops.ndo_start_xmit = pDevice->tx_80211;
38146 pDevice->apdev->netdev_ops = &apdev_netdev_ops;
38147
38148 pDevice->apdev->type = ARPHRD_IEEE80211;
38149diff --git a/drivers/staging/wlan-ng/hfa384x_usb.c b/drivers/staging/wlan-ng/hfa384x_usb.c
38150index 7843dfd..3db105f 100644
38151--- a/drivers/staging/wlan-ng/hfa384x_usb.c
38152+++ b/drivers/staging/wlan-ng/hfa384x_usb.c
38153@@ -204,7 +204,7 @@ static void unlocked_usbctlx_complete(hfa384x_t *hw, hfa384x_usbctlx_t *ctlx);
38154
38155 struct usbctlx_completor {
38156 int (*complete) (struct usbctlx_completor *);
38157-};
38158+} __no_const;
38159
38160 static int
38161 hfa384x_usbctlx_complete_sync(hfa384x_t *hw,
38162diff --git a/drivers/staging/zcache/tmem.c b/drivers/staging/zcache/tmem.c
38163index eaa9021..43f023b 100644
38164--- a/drivers/staging/zcache/tmem.c
38165+++ b/drivers/staging/zcache/tmem.c
38166@@ -39,7 +39,7 @@
38167 * A tmem host implementation must use this function to register callbacks
38168 * for memory allocation.
38169 */
38170-static struct tmem_hostops tmem_hostops;
38171+static tmem_hostops_no_const tmem_hostops;
38172
38173 static void tmem_objnode_tree_init(void);
38174
38175@@ -53,7 +53,7 @@ void tmem_register_hostops(struct tmem_hostops *m)
38176 * A tmem host implementation must use this function to register
38177 * callbacks for a page-accessible memory (PAM) implementation
38178 */
38179-static struct tmem_pamops tmem_pamops;
38180+static tmem_pamops_no_const tmem_pamops;
38181
38182 void tmem_register_pamops(struct tmem_pamops *m)
38183 {
38184diff --git a/drivers/staging/zcache/tmem.h b/drivers/staging/zcache/tmem.h
38185index 0d4aa82..f7832d4 100644
38186--- a/drivers/staging/zcache/tmem.h
38187+++ b/drivers/staging/zcache/tmem.h
38188@@ -180,6 +180,7 @@ struct tmem_pamops {
38189 void (*new_obj)(struct tmem_obj *);
38190 int (*replace_in_obj)(void *, struct tmem_obj *);
38191 };
38192+typedef struct tmem_pamops __no_const tmem_pamops_no_const;
38193 extern void tmem_register_pamops(struct tmem_pamops *m);
38194
38195 /* memory allocation methods provided by the host implementation */
38196@@ -189,6 +190,7 @@ struct tmem_hostops {
38197 struct tmem_objnode *(*objnode_alloc)(struct tmem_pool *);
38198 void (*objnode_free)(struct tmem_objnode *, struct tmem_pool *);
38199 };
38200+typedef struct tmem_hostops __no_const tmem_hostops_no_const;
38201 extern void tmem_register_hostops(struct tmem_hostops *m);
38202
38203 /* core tmem accessor functions */
38204diff --git a/drivers/target/target_core_transport.c b/drivers/target/target_core_transport.c
38205index 7502660..f214d9f 100644
38206--- a/drivers/target/target_core_transport.c
38207+++ b/drivers/target/target_core_transport.c
38208@@ -1098,7 +1098,7 @@ struct se_device *transport_add_device_to_core_hba(
38209 spin_lock_init(&dev->se_port_lock);
38210 spin_lock_init(&dev->se_tmr_lock);
38211 spin_lock_init(&dev->qf_cmd_lock);
38212- atomic_set(&dev->dev_ordered_id, 0);
38213+ atomic_set_unchecked(&dev->dev_ordered_id, 0);
38214
38215 se_dev_set_default_attribs(dev, dev_limits);
38216
38217@@ -1288,7 +1288,7 @@ static int transport_check_alloc_task_attr(struct se_cmd *cmd)
38218 * Used to determine when ORDERED commands should go from
38219 * Dormant to Active status.
38220 */
38221- cmd->se_ordered_id = atomic_inc_return(&cmd->se_dev->dev_ordered_id);
38222+ cmd->se_ordered_id = atomic_inc_return_unchecked(&cmd->se_dev->dev_ordered_id);
38223 smp_mb__after_atomic_inc();
38224 pr_debug("Allocated se_ordered_id: %u for Task Attr: 0x%02x on %s\n",
38225 cmd->se_ordered_id, cmd->sam_task_attr,
38226diff --git a/drivers/tty/cyclades.c b/drivers/tty/cyclades.c
38227index e61cabd..7617d26 100644
38228--- a/drivers/tty/cyclades.c
38229+++ b/drivers/tty/cyclades.c
38230@@ -1589,10 +1589,10 @@ static int cy_open(struct tty_struct *tty, struct file *filp)
38231 printk(KERN_DEBUG "cyc:cy_open ttyC%d, count = %d\n", info->line,
38232 info->port.count);
38233 #endif
38234- info->port.count++;
38235+ atomic_inc(&info->port.count);
38236 #ifdef CY_DEBUG_COUNT
38237 printk(KERN_DEBUG "cyc:cy_open (%d): incrementing count to %d\n",
38238- current->pid, info->port.count);
38239+ current->pid, atomic_read(&info->port.count));
38240 #endif
38241
38242 /*
38243@@ -3987,7 +3987,7 @@ static int cyclades_proc_show(struct seq_file *m, void *v)
38244 for (j = 0; j < cy_card[i].nports; j++) {
38245 info = &cy_card[i].ports[j];
38246
38247- if (info->port.count) {
38248+ if (atomic_read(&info->port.count)) {
38249 /* XXX is the ldisc num worth this? */
38250 struct tty_struct *tty;
38251 struct tty_ldisc *ld;
38252diff --git a/drivers/tty/hvc/hvc_console.c b/drivers/tty/hvc/hvc_console.c
38253index 2d691eb..be02ebd 100644
38254--- a/drivers/tty/hvc/hvc_console.c
38255+++ b/drivers/tty/hvc/hvc_console.c
38256@@ -315,7 +315,7 @@ static int hvc_open(struct tty_struct *tty, struct file * filp)
38257
38258 spin_lock_irqsave(&hp->port.lock, flags);
38259 /* Check and then increment for fast path open. */
38260- if (hp->port.count++ > 0) {
38261+ if (atomic_inc_return(&hp->port.count) > 1) {
38262 spin_unlock_irqrestore(&hp->port.lock, flags);
38263 hvc_kick();
38264 return 0;
38265@@ -366,7 +366,7 @@ static void hvc_close(struct tty_struct *tty, struct file * filp)
38266
38267 spin_lock_irqsave(&hp->port.lock, flags);
38268
38269- if (--hp->port.count == 0) {
38270+ if (atomic_dec_return(&hp->port.count) == 0) {
38271 spin_unlock_irqrestore(&hp->port.lock, flags);
38272 /* We are done with the tty pointer now. */
38273 tty_port_tty_set(&hp->port, NULL);
38274@@ -384,9 +384,9 @@ static void hvc_close(struct tty_struct *tty, struct file * filp)
38275 */
38276 tty_wait_until_sent_from_close(tty, HVC_CLOSE_WAIT);
38277 } else {
38278- if (hp->port.count < 0)
38279+ if (atomic_read(&hp->port.count) < 0)
38280 printk(KERN_ERR "hvc_close %X: oops, count is %d\n",
38281- hp->vtermno, hp->port.count);
38282+ hp->vtermno, atomic_read(&hp->port.count));
38283 spin_unlock_irqrestore(&hp->port.lock, flags);
38284 }
38285
38286@@ -412,13 +412,13 @@ static void hvc_hangup(struct tty_struct *tty)
38287 * open->hangup case this can be called after the final close so prevent
38288 * that from happening for now.
38289 */
38290- if (hp->port.count <= 0) {
38291+ if (atomic_read(&hp->port.count) <= 0) {
38292 spin_unlock_irqrestore(&hp->port.lock, flags);
38293 return;
38294 }
38295
38296- temp_open_count = hp->port.count;
38297- hp->port.count = 0;
38298+ temp_open_count = atomic_read(&hp->port.count);
38299+ atomic_set(&hp->port.count, 0);
38300 spin_unlock_irqrestore(&hp->port.lock, flags);
38301 tty_port_tty_set(&hp->port, NULL);
38302
38303@@ -471,7 +471,7 @@ static int hvc_write(struct tty_struct *tty, const unsigned char *buf, int count
38304 return -EPIPE;
38305
38306 /* FIXME what's this (unprotected) check for? */
38307- if (hp->port.count <= 0)
38308+ if (atomic_read(&hp->port.count) <= 0)
38309 return -EIO;
38310
38311 spin_lock_irqsave(&hp->lock, flags);
38312diff --git a/drivers/tty/hvc/hvcs.c b/drivers/tty/hvc/hvcs.c
38313index d56788c..12d8f85 100644
38314--- a/drivers/tty/hvc/hvcs.c
38315+++ b/drivers/tty/hvc/hvcs.c
38316@@ -83,6 +83,7 @@
38317 #include <asm/hvcserver.h>
38318 #include <asm/uaccess.h>
38319 #include <asm/vio.h>
38320+#include <asm/local.h>
38321
38322 /*
38323 * 1.3.0 -> 1.3.1 In hvcs_open memset(..,0x00,..) instead of memset(..,0x3F,00).
38324@@ -416,7 +417,7 @@ static ssize_t hvcs_vterm_state_store(struct device *dev, struct device_attribut
38325
38326 spin_lock_irqsave(&hvcsd->lock, flags);
38327
38328- if (hvcsd->port.count > 0) {
38329+ if (atomic_read(&hvcsd->port.count) > 0) {
38330 spin_unlock_irqrestore(&hvcsd->lock, flags);
38331 printk(KERN_INFO "HVCS: vterm state unchanged. "
38332 "The hvcs device node is still in use.\n");
38333@@ -1134,7 +1135,7 @@ static int hvcs_open(struct tty_struct *tty, struct file *filp)
38334 if ((retval = hvcs_partner_connect(hvcsd)))
38335 goto error_release;
38336
38337- hvcsd->port.count = 1;
38338+ atomic_set(&hvcsd->port.count, 1);
38339 hvcsd->port.tty = tty;
38340 tty->driver_data = hvcsd;
38341
38342@@ -1168,7 +1169,7 @@ fast_open:
38343
38344 spin_lock_irqsave(&hvcsd->lock, flags);
38345 tty_port_get(&hvcsd->port);
38346- hvcsd->port.count++;
38347+ atomic_inc(&hvcsd->port.count);
38348 hvcsd->todo_mask |= HVCS_SCHED_READ;
38349 spin_unlock_irqrestore(&hvcsd->lock, flags);
38350
38351@@ -1212,7 +1213,7 @@ static void hvcs_close(struct tty_struct *tty, struct file *filp)
38352 hvcsd = tty->driver_data;
38353
38354 spin_lock_irqsave(&hvcsd->lock, flags);
38355- if (--hvcsd->port.count == 0) {
38356+ if (atomic_dec_and_test(&hvcsd->port.count)) {
38357
38358 vio_disable_interrupts(hvcsd->vdev);
38359
38360@@ -1238,10 +1239,10 @@ static void hvcs_close(struct tty_struct *tty, struct file *filp)
38361 free_irq(irq, hvcsd);
38362 tty_port_put(&hvcsd->port);
38363 return;
38364- } else if (hvcsd->port.count < 0) {
38365+ } else if (atomic_read(&hvcsd->port.count) < 0) {
38366 printk(KERN_ERR "HVCS: vty-server@%X open_count: %d"
38367 " is missmanaged.\n",
38368- hvcsd->vdev->unit_address, hvcsd->port.count);
38369+ hvcsd->vdev->unit_address, atomic_read(&hvcsd->port.count));
38370 }
38371
38372 spin_unlock_irqrestore(&hvcsd->lock, flags);
38373@@ -1257,7 +1258,7 @@ static void hvcs_hangup(struct tty_struct * tty)
38374
38375 spin_lock_irqsave(&hvcsd->lock, flags);
38376 /* Preserve this so that we know how many kref refs to put */
38377- temp_open_count = hvcsd->port.count;
38378+ temp_open_count = atomic_read(&hvcsd->port.count);
38379
38380 /*
38381 * Don't kref put inside the spinlock because the destruction
38382@@ -1272,7 +1273,7 @@ static void hvcs_hangup(struct tty_struct * tty)
38383 tty->driver_data = NULL;
38384 hvcsd->port.tty = NULL;
38385
38386- hvcsd->port.count = 0;
38387+ atomic_set(&hvcsd->port.count, 0);
38388
38389 /* This will drop any buffered data on the floor which is OK in a hangup
38390 * scenario. */
38391@@ -1343,7 +1344,7 @@ static int hvcs_write(struct tty_struct *tty,
38392 * the middle of a write operation? This is a crummy place to do this
38393 * but we want to keep it all in the spinlock.
38394 */
38395- if (hvcsd->port.count <= 0) {
38396+ if (atomic_read(&hvcsd->port.count) <= 0) {
38397 spin_unlock_irqrestore(&hvcsd->lock, flags);
38398 return -ENODEV;
38399 }
38400@@ -1417,7 +1418,7 @@ static int hvcs_write_room(struct tty_struct *tty)
38401 {
38402 struct hvcs_struct *hvcsd = tty->driver_data;
38403
38404- if (!hvcsd || hvcsd->port.count <= 0)
38405+ if (!hvcsd || atomic_read(&hvcsd->port.count) <= 0)
38406 return 0;
38407
38408 return HVCS_BUFF_LEN - hvcsd->chars_in_buffer;
38409diff --git a/drivers/tty/ipwireless/tty.c b/drivers/tty/ipwireless/tty.c
38410index f8b5fa0..4ba9f89 100644
38411--- a/drivers/tty/ipwireless/tty.c
38412+++ b/drivers/tty/ipwireless/tty.c
38413@@ -29,6 +29,7 @@
38414 #include <linux/tty_driver.h>
38415 #include <linux/tty_flip.h>
38416 #include <linux/uaccess.h>
38417+#include <asm/local.h>
38418
38419 #include "tty.h"
38420 #include "network.h"
38421@@ -99,10 +100,10 @@ static int ipw_open(struct tty_struct *linux_tty, struct file *filp)
38422 mutex_unlock(&tty->ipw_tty_mutex);
38423 return -ENODEV;
38424 }
38425- if (tty->port.count == 0)
38426+ if (atomic_read(&tty->port.count) == 0)
38427 tty->tx_bytes_queued = 0;
38428
38429- tty->port.count++;
38430+ atomic_inc(&tty->port.count);
38431
38432 tty->port.tty = linux_tty;
38433 linux_tty->driver_data = tty;
38434@@ -118,9 +119,7 @@ static int ipw_open(struct tty_struct *linux_tty, struct file *filp)
38435
38436 static void do_ipw_close(struct ipw_tty *tty)
38437 {
38438- tty->port.count--;
38439-
38440- if (tty->port.count == 0) {
38441+ if (atomic_dec_return(&tty->port.count) == 0) {
38442 struct tty_struct *linux_tty = tty->port.tty;
38443
38444 if (linux_tty != NULL) {
38445@@ -141,7 +140,7 @@ static void ipw_hangup(struct tty_struct *linux_tty)
38446 return;
38447
38448 mutex_lock(&tty->ipw_tty_mutex);
38449- if (tty->port.count == 0) {
38450+ if (atomic_read(&tty->port.count) == 0) {
38451 mutex_unlock(&tty->ipw_tty_mutex);
38452 return;
38453 }
38454@@ -170,7 +169,7 @@ void ipwireless_tty_received(struct ipw_tty *tty, unsigned char *data,
38455 return;
38456 }
38457
38458- if (!tty->port.count) {
38459+ if (!atomic_read(&tty->port.count)) {
38460 mutex_unlock(&tty->ipw_tty_mutex);
38461 return;
38462 }
38463@@ -212,7 +211,7 @@ static int ipw_write(struct tty_struct *linux_tty,
38464 return -ENODEV;
38465
38466 mutex_lock(&tty->ipw_tty_mutex);
38467- if (!tty->port.count) {
38468+ if (!atomic_read(&tty->port.count)) {
38469 mutex_unlock(&tty->ipw_tty_mutex);
38470 return -EINVAL;
38471 }
38472@@ -252,7 +251,7 @@ static int ipw_write_room(struct tty_struct *linux_tty)
38473 if (!tty)
38474 return -ENODEV;
38475
38476- if (!tty->port.count)
38477+ if (!atomic_read(&tty->port.count))
38478 return -EINVAL;
38479
38480 room = IPWIRELESS_TX_QUEUE_SIZE - tty->tx_bytes_queued;
38481@@ -294,7 +293,7 @@ static int ipw_chars_in_buffer(struct tty_struct *linux_tty)
38482 if (!tty)
38483 return 0;
38484
38485- if (!tty->port.count)
38486+ if (!atomic_read(&tty->port.count))
38487 return 0;
38488
38489 return tty->tx_bytes_queued;
38490@@ -375,7 +374,7 @@ static int ipw_tiocmget(struct tty_struct *linux_tty)
38491 if (!tty)
38492 return -ENODEV;
38493
38494- if (!tty->port.count)
38495+ if (!atomic_read(&tty->port.count))
38496 return -EINVAL;
38497
38498 return get_control_lines(tty);
38499@@ -391,7 +390,7 @@ ipw_tiocmset(struct tty_struct *linux_tty,
38500 if (!tty)
38501 return -ENODEV;
38502
38503- if (!tty->port.count)
38504+ if (!atomic_read(&tty->port.count))
38505 return -EINVAL;
38506
38507 return set_control_lines(tty, set, clear);
38508@@ -405,7 +404,7 @@ static int ipw_ioctl(struct tty_struct *linux_tty,
38509 if (!tty)
38510 return -ENODEV;
38511
38512- if (!tty->port.count)
38513+ if (!atomic_read(&tty->port.count))
38514 return -EINVAL;
38515
38516 /* FIXME: Exactly how is the tty object locked here .. */
38517@@ -561,7 +560,7 @@ void ipwireless_tty_free(struct ipw_tty *tty)
38518 * are gone */
38519 mutex_lock(&ttyj->ipw_tty_mutex);
38520 }
38521- while (ttyj->port.count)
38522+ while (atomic_read(&ttyj->port.count))
38523 do_ipw_close(ttyj);
38524 ipwireless_disassociate_network_ttys(network,
38525 ttyj->channel_idx);
38526diff --git a/drivers/tty/moxa.c b/drivers/tty/moxa.c
38527index 324467d..504cc25 100644
38528--- a/drivers/tty/moxa.c
38529+++ b/drivers/tty/moxa.c
38530@@ -1172,7 +1172,7 @@ static int moxa_open(struct tty_struct *tty, struct file *filp)
38531 }
38532
38533 ch = &brd->ports[port % MAX_PORTS_PER_BOARD];
38534- ch->port.count++;
38535+ atomic_inc(&ch->port.count);
38536 tty->driver_data = ch;
38537 tty_port_tty_set(&ch->port, tty);
38538 mutex_lock(&ch->port.mutex);
38539diff --git a/drivers/tty/n_gsm.c b/drivers/tty/n_gsm.c
38540index 90dff82..08119c3 100644
38541--- a/drivers/tty/n_gsm.c
38542+++ b/drivers/tty/n_gsm.c
38543@@ -1639,7 +1639,7 @@ static struct gsm_dlci *gsm_dlci_alloc(struct gsm_mux *gsm, int addr)
38544 kref_init(&dlci->ref);
38545 mutex_init(&dlci->mutex);
38546 dlci->fifo = &dlci->_fifo;
38547- if (kfifo_alloc(&dlci->_fifo, 4096, GFP_KERNEL) < 0) {
38548+ if (kfifo_alloc(&dlci->_fifo, 4096, GFP_KERNEL)) {
38549 kfree(dlci);
38550 return NULL;
38551 }
38552@@ -2909,7 +2909,7 @@ static int gsmtty_open(struct tty_struct *tty, struct file *filp)
38553 if (dlci == NULL)
38554 return -ENOMEM;
38555 port = &dlci->port;
38556- port->count++;
38557+ atomic_inc(&port->count);
38558 tty->driver_data = dlci;
38559 dlci_get(dlci);
38560 dlci_get(dlci->gsm->dlci[0]);
38561diff --git a/drivers/tty/n_tty.c b/drivers/tty/n_tty.c
38562index 26f0d0e..b7c4273 100644
38563--- a/drivers/tty/n_tty.c
38564+++ b/drivers/tty/n_tty.c
38565@@ -2124,6 +2124,7 @@ void n_tty_inherit_ops(struct tty_ldisc_ops *ops)
38566 {
38567 *ops = tty_ldisc_N_TTY;
38568 ops->owner = NULL;
38569- ops->refcount = ops->flags = 0;
38570+ atomic_set(&ops->refcount, 0);
38571+ ops->flags = 0;
38572 }
38573 EXPORT_SYMBOL_GPL(n_tty_inherit_ops);
38574diff --git a/drivers/tty/pty.c b/drivers/tty/pty.c
38575index 5505ffc..7affff9 100644
38576--- a/drivers/tty/pty.c
38577+++ b/drivers/tty/pty.c
38578@@ -718,8 +718,10 @@ static void __init unix98_pty_init(void)
38579 panic("Couldn't register Unix98 pts driver");
38580
38581 /* Now create the /dev/ptmx special device */
38582+ pax_open_kernel();
38583 tty_default_fops(&ptmx_fops);
38584- ptmx_fops.open = ptmx_open;
38585+ *(void **)&ptmx_fops.open = ptmx_open;
38586+ pax_close_kernel();
38587
38588 cdev_init(&ptmx_cdev, &ptmx_fops);
38589 if (cdev_add(&ptmx_cdev, MKDEV(TTYAUX_MAJOR, 2), 1) ||
38590diff --git a/drivers/tty/rocket.c b/drivers/tty/rocket.c
38591index 777d5f9..56d67ca 100644
38592--- a/drivers/tty/rocket.c
38593+++ b/drivers/tty/rocket.c
38594@@ -924,7 +924,7 @@ static int rp_open(struct tty_struct *tty, struct file *filp)
38595 tty->driver_data = info;
38596 tty_port_tty_set(port, tty);
38597
38598- if (port->count++ == 0) {
38599+ if (atomic_inc_return(&port->count) == 1) {
38600 atomic_inc(&rp_num_ports_open);
38601
38602 #ifdef ROCKET_DEBUG_OPEN
38603@@ -933,7 +933,7 @@ static int rp_open(struct tty_struct *tty, struct file *filp)
38604 #endif
38605 }
38606 #ifdef ROCKET_DEBUG_OPEN
38607- printk(KERN_INFO "rp_open ttyR%d, count=%d\n", info->line, info->port.count);
38608+ printk(KERN_INFO "rp_open ttyR%d, count=%d\n", info->line, atomic-read(&info->port.count));
38609 #endif
38610
38611 /*
38612@@ -1528,7 +1528,7 @@ static void rp_hangup(struct tty_struct *tty)
38613 spin_unlock_irqrestore(&info->port.lock, flags);
38614 return;
38615 }
38616- if (info->port.count)
38617+ if (atomic_read(&info->port.count))
38618 atomic_dec(&rp_num_ports_open);
38619 clear_bit((info->aiop * 8) + info->chan, (void *) &xmit_flags[info->board]);
38620 spin_unlock_irqrestore(&info->port.lock, flags);
38621diff --git a/drivers/tty/serial/kgdboc.c b/drivers/tty/serial/kgdboc.c
38622index 2b42a01..32a2ed3 100644
38623--- a/drivers/tty/serial/kgdboc.c
38624+++ b/drivers/tty/serial/kgdboc.c
38625@@ -24,8 +24,9 @@
38626 #define MAX_CONFIG_LEN 40
38627
38628 static struct kgdb_io kgdboc_io_ops;
38629+static struct kgdb_io kgdboc_io_ops_console;
38630
38631-/* -1 = init not run yet, 0 = unconfigured, 1 = configured. */
38632+/* -1 = init not run yet, 0 = unconfigured, 1/2 = configured. */
38633 static int configured = -1;
38634
38635 static char config[MAX_CONFIG_LEN];
38636@@ -148,6 +149,8 @@ static void cleanup_kgdboc(void)
38637 kgdboc_unregister_kbd();
38638 if (configured == 1)
38639 kgdb_unregister_io_module(&kgdboc_io_ops);
38640+ else if (configured == 2)
38641+ kgdb_unregister_io_module(&kgdboc_io_ops_console);
38642 }
38643
38644 static int configure_kgdboc(void)
38645@@ -157,13 +160,13 @@ static int configure_kgdboc(void)
38646 int err;
38647 char *cptr = config;
38648 struct console *cons;
38649+ int is_console = 0;
38650
38651 err = kgdboc_option_setup(config);
38652 if (err || !strlen(config) || isspace(config[0]))
38653 goto noconfig;
38654
38655 err = -ENODEV;
38656- kgdboc_io_ops.is_console = 0;
38657 kgdb_tty_driver = NULL;
38658
38659 kgdboc_use_kms = 0;
38660@@ -184,7 +187,7 @@ static int configure_kgdboc(void)
38661 int idx;
38662 if (cons->device && cons->device(cons, &idx) == p &&
38663 idx == tty_line) {
38664- kgdboc_io_ops.is_console = 1;
38665+ is_console = 1;
38666 break;
38667 }
38668 cons = cons->next;
38669@@ -194,12 +197,16 @@ static int configure_kgdboc(void)
38670 kgdb_tty_line = tty_line;
38671
38672 do_register:
38673- err = kgdb_register_io_module(&kgdboc_io_ops);
38674+ if (is_console) {
38675+ err = kgdb_register_io_module(&kgdboc_io_ops_console);
38676+ configured = 2;
38677+ } else {
38678+ err = kgdb_register_io_module(&kgdboc_io_ops);
38679+ configured = 1;
38680+ }
38681 if (err)
38682 goto noconfig;
38683
38684- configured = 1;
38685-
38686 return 0;
38687
38688 noconfig:
38689@@ -213,7 +220,7 @@ noconfig:
38690 static int __init init_kgdboc(void)
38691 {
38692 /* Already configured? */
38693- if (configured == 1)
38694+ if (configured >= 1)
38695 return 0;
38696
38697 return configure_kgdboc();
38698@@ -262,7 +269,7 @@ static int param_set_kgdboc_var(const char *kmessage, struct kernel_param *kp)
38699 if (config[len - 1] == '\n')
38700 config[len - 1] = '\0';
38701
38702- if (configured == 1)
38703+ if (configured >= 1)
38704 cleanup_kgdboc();
38705
38706 /* Go and configure with the new params. */
38707@@ -302,6 +309,15 @@ static struct kgdb_io kgdboc_io_ops = {
38708 .post_exception = kgdboc_post_exp_handler,
38709 };
38710
38711+static struct kgdb_io kgdboc_io_ops_console = {
38712+ .name = "kgdboc",
38713+ .read_char = kgdboc_get_char,
38714+ .write_char = kgdboc_put_char,
38715+ .pre_exception = kgdboc_pre_exp_handler,
38716+ .post_exception = kgdboc_post_exp_handler,
38717+ .is_console = 1
38718+};
38719+
38720 #ifdef CONFIG_KGDB_SERIAL_CONSOLE
38721 /* This is only available if kgdboc is a built in for early debugging */
38722 static int __init kgdboc_early_init(char *opt)
38723diff --git a/drivers/tty/serial/serial_core.c b/drivers/tty/serial/serial_core.c
38724index a21dc8e..fe43e9e 100644
38725--- a/drivers/tty/serial/serial_core.c
38726+++ b/drivers/tty/serial/serial_core.c
38727@@ -1392,7 +1392,7 @@ static void uart_hangup(struct tty_struct *tty)
38728 uart_flush_buffer(tty);
38729 uart_shutdown(tty, state);
38730 spin_lock_irqsave(&port->lock, flags);
38731- port->count = 0;
38732+ atomic_set(&port->count, 0);
38733 clear_bit(ASYNCB_NORMAL_ACTIVE, &port->flags);
38734 spin_unlock_irqrestore(&port->lock, flags);
38735 tty_port_tty_set(port, NULL);
38736@@ -1488,7 +1488,7 @@ static int uart_open(struct tty_struct *tty, struct file *filp)
38737 goto end;
38738 }
38739
38740- port->count++;
38741+ atomic_inc(&port->count);
38742 if (!state->uart_port || state->uart_port->flags & UPF_DEAD) {
38743 retval = -ENXIO;
38744 goto err_dec_count;
38745@@ -1515,7 +1515,7 @@ static int uart_open(struct tty_struct *tty, struct file *filp)
38746 /*
38747 * Make sure the device is in D0 state.
38748 */
38749- if (port->count == 1)
38750+ if (atomic_read(&port->count) == 1)
38751 uart_change_pm(state, 0);
38752
38753 /*
38754@@ -1533,7 +1533,7 @@ static int uart_open(struct tty_struct *tty, struct file *filp)
38755 end:
38756 return retval;
38757 err_dec_count:
38758- port->count--;
38759+ atomic_inc(&port->count);
38760 mutex_unlock(&port->mutex);
38761 goto end;
38762 }
38763diff --git a/drivers/tty/synclink.c b/drivers/tty/synclink.c
38764index 593d40a..bdc61f3 100644
38765--- a/drivers/tty/synclink.c
38766+++ b/drivers/tty/synclink.c
38767@@ -3095,7 +3095,7 @@ static void mgsl_close(struct tty_struct *tty, struct file * filp)
38768
38769 if (debug_level >= DEBUG_LEVEL_INFO)
38770 printk("%s(%d):mgsl_close(%s) entry, count=%d\n",
38771- __FILE__,__LINE__, info->device_name, info->port.count);
38772+ __FILE__,__LINE__, info->device_name, atomic_read(&info->port.count));
38773
38774 if (tty_port_close_start(&info->port, tty, filp) == 0)
38775 goto cleanup;
38776@@ -3113,7 +3113,7 @@ static void mgsl_close(struct tty_struct *tty, struct file * filp)
38777 cleanup:
38778 if (debug_level >= DEBUG_LEVEL_INFO)
38779 printk("%s(%d):mgsl_close(%s) exit, count=%d\n", __FILE__,__LINE__,
38780- tty->driver->name, info->port.count);
38781+ tty->driver->name, atomic_read(&info->port.count));
38782
38783 } /* end of mgsl_close() */
38784
38785@@ -3212,8 +3212,8 @@ static void mgsl_hangup(struct tty_struct *tty)
38786
38787 mgsl_flush_buffer(tty);
38788 shutdown(info);
38789-
38790- info->port.count = 0;
38791+
38792+ atomic_set(&info->port.count, 0);
38793 info->port.flags &= ~ASYNC_NORMAL_ACTIVE;
38794 info->port.tty = NULL;
38795
38796@@ -3302,12 +3302,12 @@ static int block_til_ready(struct tty_struct *tty, struct file * filp,
38797
38798 if (debug_level >= DEBUG_LEVEL_INFO)
38799 printk("%s(%d):block_til_ready before block on %s count=%d\n",
38800- __FILE__,__LINE__, tty->driver->name, port->count );
38801+ __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
38802
38803 spin_lock_irqsave(&info->irq_spinlock, flags);
38804 if (!tty_hung_up_p(filp)) {
38805 extra_count = true;
38806- port->count--;
38807+ atomic_dec(&port->count);
38808 }
38809 spin_unlock_irqrestore(&info->irq_spinlock, flags);
38810 port->blocked_open++;
38811@@ -3336,7 +3336,7 @@ static int block_til_ready(struct tty_struct *tty, struct file * filp,
38812
38813 if (debug_level >= DEBUG_LEVEL_INFO)
38814 printk("%s(%d):block_til_ready blocking on %s count=%d\n",
38815- __FILE__,__LINE__, tty->driver->name, port->count );
38816+ __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
38817
38818 tty_unlock();
38819 schedule();
38820@@ -3348,12 +3348,12 @@ static int block_til_ready(struct tty_struct *tty, struct file * filp,
38821
38822 /* FIXME: Racy on hangup during close wait */
38823 if (extra_count)
38824- port->count++;
38825+ atomic_inc(&port->count);
38826 port->blocked_open--;
38827
38828 if (debug_level >= DEBUG_LEVEL_INFO)
38829 printk("%s(%d):block_til_ready after blocking on %s count=%d\n",
38830- __FILE__,__LINE__, tty->driver->name, port->count );
38831+ __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
38832
38833 if (!retval)
38834 port->flags |= ASYNC_NORMAL_ACTIVE;
38835@@ -3398,7 +3398,7 @@ static int mgsl_open(struct tty_struct *tty, struct file * filp)
38836
38837 if (debug_level >= DEBUG_LEVEL_INFO)
38838 printk("%s(%d):mgsl_open(%s), old ref count = %d\n",
38839- __FILE__,__LINE__,tty->driver->name, info->port.count);
38840+ __FILE__,__LINE__,tty->driver->name, atomic_read(&info->port.count));
38841
38842 /* If port is closing, signal caller to try again */
38843 if (tty_hung_up_p(filp) || info->port.flags & ASYNC_CLOSING){
38844@@ -3417,10 +3417,10 @@ static int mgsl_open(struct tty_struct *tty, struct file * filp)
38845 spin_unlock_irqrestore(&info->netlock, flags);
38846 goto cleanup;
38847 }
38848- info->port.count++;
38849+ atomic_inc(&info->port.count);
38850 spin_unlock_irqrestore(&info->netlock, flags);
38851
38852- if (info->port.count == 1) {
38853+ if (atomic_read(&info->port.count) == 1) {
38854 /* 1st open on this device, init hardware */
38855 retval = startup(info);
38856 if (retval < 0)
38857@@ -3444,8 +3444,8 @@ cleanup:
38858 if (retval) {
38859 if (tty->count == 1)
38860 info->port.tty = NULL; /* tty layer will release tty struct */
38861- if(info->port.count)
38862- info->port.count--;
38863+ if (atomic_read(&info->port.count))
38864+ atomic_dec(&info->port.count);
38865 }
38866
38867 return retval;
38868@@ -7653,7 +7653,7 @@ static int hdlcdev_attach(struct net_device *dev, unsigned short encoding,
38869 unsigned short new_crctype;
38870
38871 /* return error if TTY interface open */
38872- if (info->port.count)
38873+ if (atomic_read(&info->port.count))
38874 return -EBUSY;
38875
38876 switch (encoding)
38877@@ -7748,7 +7748,7 @@ static int hdlcdev_open(struct net_device *dev)
38878
38879 /* arbitrate between network and tty opens */
38880 spin_lock_irqsave(&info->netlock, flags);
38881- if (info->port.count != 0 || info->netcount != 0) {
38882+ if (atomic_read(&info->port.count) != 0 || info->netcount != 0) {
38883 printk(KERN_WARNING "%s: hdlc_open returning busy\n", dev->name);
38884 spin_unlock_irqrestore(&info->netlock, flags);
38885 return -EBUSY;
38886@@ -7834,7 +7834,7 @@ static int hdlcdev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
38887 printk("%s:hdlcdev_ioctl(%s)\n",__FILE__,dev->name);
38888
38889 /* return error if TTY interface open */
38890- if (info->port.count)
38891+ if (atomic_read(&info->port.count))
38892 return -EBUSY;
38893
38894 if (cmd != SIOCWANDEV)
38895diff --git a/drivers/tty/synclink_gt.c b/drivers/tty/synclink_gt.c
38896index aa1debf..9297a16 100644
38897--- a/drivers/tty/synclink_gt.c
38898+++ b/drivers/tty/synclink_gt.c
38899@@ -671,7 +671,7 @@ static int open(struct tty_struct *tty, struct file *filp)
38900 tty->driver_data = info;
38901 info->port.tty = tty;
38902
38903- DBGINFO(("%s open, old ref count = %d\n", info->device_name, info->port.count));
38904+ DBGINFO(("%s open, old ref count = %d\n", info->device_name, atomic_read(&info->port.count)));
38905
38906 /* If port is closing, signal caller to try again */
38907 if (tty_hung_up_p(filp) || info->port.flags & ASYNC_CLOSING){
38908@@ -692,10 +692,10 @@ static int open(struct tty_struct *tty, struct file *filp)
38909 mutex_unlock(&info->port.mutex);
38910 goto cleanup;
38911 }
38912- info->port.count++;
38913+ atomic_inc(&info->port.count);
38914 spin_unlock_irqrestore(&info->netlock, flags);
38915
38916- if (info->port.count == 1) {
38917+ if (atomic_read(&info->port.count) == 1) {
38918 /* 1st open on this device, init hardware */
38919 retval = startup(info);
38920 if (retval < 0) {
38921@@ -716,8 +716,8 @@ cleanup:
38922 if (retval) {
38923 if (tty->count == 1)
38924 info->port.tty = NULL; /* tty layer will release tty struct */
38925- if(info->port.count)
38926- info->port.count--;
38927+ if(atomic_read(&info->port.count))
38928+ atomic_dec(&info->port.count);
38929 }
38930
38931 DBGINFO(("%s open rc=%d\n", info->device_name, retval));
38932@@ -730,7 +730,7 @@ static void close(struct tty_struct *tty, struct file *filp)
38933
38934 if (sanity_check(info, tty->name, "close"))
38935 return;
38936- DBGINFO(("%s close entry, count=%d\n", info->device_name, info->port.count));
38937+ DBGINFO(("%s close entry, count=%d\n", info->device_name, atomic_read(&info->port.count)));
38938
38939 if (tty_port_close_start(&info->port, tty, filp) == 0)
38940 goto cleanup;
38941@@ -747,7 +747,7 @@ static void close(struct tty_struct *tty, struct file *filp)
38942 tty_port_close_end(&info->port, tty);
38943 info->port.tty = NULL;
38944 cleanup:
38945- DBGINFO(("%s close exit, count=%d\n", tty->driver->name, info->port.count));
38946+ DBGINFO(("%s close exit, count=%d\n", tty->driver->name, atomic_read(&info->port.count)));
38947 }
38948
38949 static void hangup(struct tty_struct *tty)
38950@@ -765,7 +765,7 @@ static void hangup(struct tty_struct *tty)
38951 shutdown(info);
38952
38953 spin_lock_irqsave(&info->port.lock, flags);
38954- info->port.count = 0;
38955+ atomic_set(&info->port.count, 0);
38956 info->port.flags &= ~ASYNC_NORMAL_ACTIVE;
38957 info->port.tty = NULL;
38958 spin_unlock_irqrestore(&info->port.lock, flags);
38959@@ -1450,7 +1450,7 @@ static int hdlcdev_attach(struct net_device *dev, unsigned short encoding,
38960 unsigned short new_crctype;
38961
38962 /* return error if TTY interface open */
38963- if (info->port.count)
38964+ if (atomic_read(&info->port.count))
38965 return -EBUSY;
38966
38967 DBGINFO(("%s hdlcdev_attach\n", info->device_name));
38968@@ -1545,7 +1545,7 @@ static int hdlcdev_open(struct net_device *dev)
38969
38970 /* arbitrate between network and tty opens */
38971 spin_lock_irqsave(&info->netlock, flags);
38972- if (info->port.count != 0 || info->netcount != 0) {
38973+ if (atomic_read(&info->port.count) != 0 || info->netcount != 0) {
38974 DBGINFO(("%s hdlc_open busy\n", dev->name));
38975 spin_unlock_irqrestore(&info->netlock, flags);
38976 return -EBUSY;
38977@@ -1630,7 +1630,7 @@ static int hdlcdev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
38978 DBGINFO(("%s hdlcdev_ioctl\n", dev->name));
38979
38980 /* return error if TTY interface open */
38981- if (info->port.count)
38982+ if (atomic_read(&info->port.count))
38983 return -EBUSY;
38984
38985 if (cmd != SIOCWANDEV)
38986@@ -2419,7 +2419,7 @@ static irqreturn_t slgt_interrupt(int dummy, void *dev_id)
38987 if (port == NULL)
38988 continue;
38989 spin_lock(&port->lock);
38990- if ((port->port.count || port->netcount) &&
38991+ if ((atomic_read(&port->port.count) || port->netcount) &&
38992 port->pending_bh && !port->bh_running &&
38993 !port->bh_requested) {
38994 DBGISR(("%s bh queued\n", port->device_name));
38995@@ -3308,7 +3308,7 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
38996 spin_lock_irqsave(&info->lock, flags);
38997 if (!tty_hung_up_p(filp)) {
38998 extra_count = true;
38999- port->count--;
39000+ atomic_dec(&port->count);
39001 }
39002 spin_unlock_irqrestore(&info->lock, flags);
39003 port->blocked_open++;
39004@@ -3345,7 +3345,7 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
39005 remove_wait_queue(&port->open_wait, &wait);
39006
39007 if (extra_count)
39008- port->count++;
39009+ atomic_inc(&port->count);
39010 port->blocked_open--;
39011
39012 if (!retval)
39013diff --git a/drivers/tty/synclinkmp.c b/drivers/tty/synclinkmp.c
39014index a3dddc1..8905ab2 100644
39015--- a/drivers/tty/synclinkmp.c
39016+++ b/drivers/tty/synclinkmp.c
39017@@ -742,7 +742,7 @@ static int open(struct tty_struct *tty, struct file *filp)
39018
39019 if (debug_level >= DEBUG_LEVEL_INFO)
39020 printk("%s(%d):%s open(), old ref count = %d\n",
39021- __FILE__,__LINE__,tty->driver->name, info->port.count);
39022+ __FILE__,__LINE__,tty->driver->name, atomic_read(&info->port.count));
39023
39024 /* If port is closing, signal caller to try again */
39025 if (tty_hung_up_p(filp) || info->port.flags & ASYNC_CLOSING){
39026@@ -761,10 +761,10 @@ static int open(struct tty_struct *tty, struct file *filp)
39027 spin_unlock_irqrestore(&info->netlock, flags);
39028 goto cleanup;
39029 }
39030- info->port.count++;
39031+ atomic_inc(&info->port.count);
39032 spin_unlock_irqrestore(&info->netlock, flags);
39033
39034- if (info->port.count == 1) {
39035+ if (atomic_read(&info->port.count) == 1) {
39036 /* 1st open on this device, init hardware */
39037 retval = startup(info);
39038 if (retval < 0)
39039@@ -788,8 +788,8 @@ cleanup:
39040 if (retval) {
39041 if (tty->count == 1)
39042 info->port.tty = NULL; /* tty layer will release tty struct */
39043- if(info->port.count)
39044- info->port.count--;
39045+ if(atomic_read(&info->port.count))
39046+ atomic_dec(&info->port.count);
39047 }
39048
39049 return retval;
39050@@ -807,7 +807,7 @@ static void close(struct tty_struct *tty, struct file *filp)
39051
39052 if (debug_level >= DEBUG_LEVEL_INFO)
39053 printk("%s(%d):%s close() entry, count=%d\n",
39054- __FILE__,__LINE__, info->device_name, info->port.count);
39055+ __FILE__,__LINE__, info->device_name, atomic_read(&info->port.count));
39056
39057 if (tty_port_close_start(&info->port, tty, filp) == 0)
39058 goto cleanup;
39059@@ -826,7 +826,7 @@ static void close(struct tty_struct *tty, struct file *filp)
39060 cleanup:
39061 if (debug_level >= DEBUG_LEVEL_INFO)
39062 printk("%s(%d):%s close() exit, count=%d\n", __FILE__,__LINE__,
39063- tty->driver->name, info->port.count);
39064+ tty->driver->name, atomic_read(&info->port.count));
39065 }
39066
39067 /* Called by tty_hangup() when a hangup is signaled.
39068@@ -849,7 +849,7 @@ static void hangup(struct tty_struct *tty)
39069 shutdown(info);
39070
39071 spin_lock_irqsave(&info->port.lock, flags);
39072- info->port.count = 0;
39073+ atomic_set(&info->port.count, 0);
39074 info->port.flags &= ~ASYNC_NORMAL_ACTIVE;
39075 info->port.tty = NULL;
39076 spin_unlock_irqrestore(&info->port.lock, flags);
39077@@ -1557,7 +1557,7 @@ static int hdlcdev_attach(struct net_device *dev, unsigned short encoding,
39078 unsigned short new_crctype;
39079
39080 /* return error if TTY interface open */
39081- if (info->port.count)
39082+ if (atomic_read(&info->port.count))
39083 return -EBUSY;
39084
39085 switch (encoding)
39086@@ -1652,7 +1652,7 @@ static int hdlcdev_open(struct net_device *dev)
39087
39088 /* arbitrate between network and tty opens */
39089 spin_lock_irqsave(&info->netlock, flags);
39090- if (info->port.count != 0 || info->netcount != 0) {
39091+ if (atomic_read(&info->port.count) != 0 || info->netcount != 0) {
39092 printk(KERN_WARNING "%s: hdlc_open returning busy\n", dev->name);
39093 spin_unlock_irqrestore(&info->netlock, flags);
39094 return -EBUSY;
39095@@ -1738,7 +1738,7 @@ static int hdlcdev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
39096 printk("%s:hdlcdev_ioctl(%s)\n",__FILE__,dev->name);
39097
39098 /* return error if TTY interface open */
39099- if (info->port.count)
39100+ if (atomic_read(&info->port.count))
39101 return -EBUSY;
39102
39103 if (cmd != SIOCWANDEV)
39104@@ -2623,7 +2623,7 @@ static irqreturn_t synclinkmp_interrupt(int dummy, void *dev_id)
39105 * do not request bottom half processing if the
39106 * device is not open in a normal mode.
39107 */
39108- if ( port && (port->port.count || port->netcount) &&
39109+ if ( port && (atomic_read(&port->port.count) || port->netcount) &&
39110 port->pending_bh && !port->bh_running &&
39111 !port->bh_requested ) {
39112 if ( debug_level >= DEBUG_LEVEL_ISR )
39113@@ -3321,12 +3321,12 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
39114
39115 if (debug_level >= DEBUG_LEVEL_INFO)
39116 printk("%s(%d):%s block_til_ready() before block, count=%d\n",
39117- __FILE__,__LINE__, tty->driver->name, port->count );
39118+ __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
39119
39120 spin_lock_irqsave(&info->lock, flags);
39121 if (!tty_hung_up_p(filp)) {
39122 extra_count = true;
39123- port->count--;
39124+ atomic_dec(&port->count);
39125 }
39126 spin_unlock_irqrestore(&info->lock, flags);
39127 port->blocked_open++;
39128@@ -3355,7 +3355,7 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
39129
39130 if (debug_level >= DEBUG_LEVEL_INFO)
39131 printk("%s(%d):%s block_til_ready() count=%d\n",
39132- __FILE__,__LINE__, tty->driver->name, port->count );
39133+ __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
39134
39135 tty_unlock();
39136 schedule();
39137@@ -3366,12 +3366,12 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
39138 remove_wait_queue(&port->open_wait, &wait);
39139
39140 if (extra_count)
39141- port->count++;
39142+ atomic_inc(&port->count);
39143 port->blocked_open--;
39144
39145 if (debug_level >= DEBUG_LEVEL_INFO)
39146 printk("%s(%d):%s block_til_ready() after, count=%d\n",
39147- __FILE__,__LINE__, tty->driver->name, port->count );
39148+ __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
39149
39150 if (!retval)
39151 port->flags |= ASYNC_NORMAL_ACTIVE;
39152diff --git a/drivers/tty/sysrq.c b/drivers/tty/sysrq.c
39153index 05728894..b9d44c6 100644
39154--- a/drivers/tty/sysrq.c
39155+++ b/drivers/tty/sysrq.c
39156@@ -865,7 +865,7 @@ EXPORT_SYMBOL(unregister_sysrq_key);
39157 static ssize_t write_sysrq_trigger(struct file *file, const char __user *buf,
39158 size_t count, loff_t *ppos)
39159 {
39160- if (count) {
39161+ if (count && capable(CAP_SYS_ADMIN)) {
39162 char c;
39163
39164 if (get_user(c, buf))
39165diff --git a/drivers/tty/tty_io.c b/drivers/tty/tty_io.c
39166index b425c79..08a3f06 100644
39167--- a/drivers/tty/tty_io.c
39168+++ b/drivers/tty/tty_io.c
39169@@ -3283,7 +3283,7 @@ EXPORT_SYMBOL_GPL(get_current_tty);
39170
39171 void tty_default_fops(struct file_operations *fops)
39172 {
39173- *fops = tty_fops;
39174+ memcpy((void *)fops, &tty_fops, sizeof(tty_fops));
39175 }
39176
39177 /*
39178diff --git a/drivers/tty/tty_ldisc.c b/drivers/tty/tty_ldisc.c
39179index 6f99c99..8947bc4 100644
39180--- a/drivers/tty/tty_ldisc.c
39181+++ b/drivers/tty/tty_ldisc.c
39182@@ -56,7 +56,7 @@ static void put_ldisc(struct tty_ldisc *ld)
39183 if (atomic_dec_and_lock(&ld->users, &tty_ldisc_lock)) {
39184 struct tty_ldisc_ops *ldo = ld->ops;
39185
39186- ldo->refcount--;
39187+ atomic_dec(&ldo->refcount);
39188 module_put(ldo->owner);
39189 spin_unlock_irqrestore(&tty_ldisc_lock, flags);
39190
39191@@ -91,7 +91,7 @@ int tty_register_ldisc(int disc, struct tty_ldisc_ops *new_ldisc)
39192 spin_lock_irqsave(&tty_ldisc_lock, flags);
39193 tty_ldiscs[disc] = new_ldisc;
39194 new_ldisc->num = disc;
39195- new_ldisc->refcount = 0;
39196+ atomic_set(&new_ldisc->refcount, 0);
39197 spin_unlock_irqrestore(&tty_ldisc_lock, flags);
39198
39199 return ret;
39200@@ -119,7 +119,7 @@ int tty_unregister_ldisc(int disc)
39201 return -EINVAL;
39202
39203 spin_lock_irqsave(&tty_ldisc_lock, flags);
39204- if (tty_ldiscs[disc]->refcount)
39205+ if (atomic_read(&tty_ldiscs[disc]->refcount))
39206 ret = -EBUSY;
39207 else
39208 tty_ldiscs[disc] = NULL;
39209@@ -140,7 +140,7 @@ static struct tty_ldisc_ops *get_ldops(int disc)
39210 if (ldops) {
39211 ret = ERR_PTR(-EAGAIN);
39212 if (try_module_get(ldops->owner)) {
39213- ldops->refcount++;
39214+ atomic_inc(&ldops->refcount);
39215 ret = ldops;
39216 }
39217 }
39218@@ -153,7 +153,7 @@ static void put_ldops(struct tty_ldisc_ops *ldops)
39219 unsigned long flags;
39220
39221 spin_lock_irqsave(&tty_ldisc_lock, flags);
39222- ldops->refcount--;
39223+ atomic_dec(&ldops->refcount);
39224 module_put(ldops->owner);
39225 spin_unlock_irqrestore(&tty_ldisc_lock, flags);
39226 }
39227diff --git a/drivers/tty/tty_port.c b/drivers/tty/tty_port.c
39228index bf6e238..d401c04 100644
39229--- a/drivers/tty/tty_port.c
39230+++ b/drivers/tty/tty_port.c
39231@@ -138,7 +138,7 @@ void tty_port_hangup(struct tty_port *port)
39232 unsigned long flags;
39233
39234 spin_lock_irqsave(&port->lock, flags);
39235- port->count = 0;
39236+ atomic_set(&port->count, 0);
39237 port->flags &= ~ASYNC_NORMAL_ACTIVE;
39238 if (port->tty) {
39239 set_bit(TTY_IO_ERROR, &port->tty->flags);
39240@@ -264,7 +264,7 @@ int tty_port_block_til_ready(struct tty_port *port,
39241 /* The port lock protects the port counts */
39242 spin_lock_irqsave(&port->lock, flags);
39243 if (!tty_hung_up_p(filp))
39244- port->count--;
39245+ atomic_dec(&port->count);
39246 port->blocked_open++;
39247 spin_unlock_irqrestore(&port->lock, flags);
39248
39249@@ -306,7 +306,7 @@ int tty_port_block_til_ready(struct tty_port *port,
39250 we must not mess that up further */
39251 spin_lock_irqsave(&port->lock, flags);
39252 if (!tty_hung_up_p(filp))
39253- port->count++;
39254+ atomic_inc(&port->count);
39255 port->blocked_open--;
39256 if (retval == 0)
39257 port->flags |= ASYNC_NORMAL_ACTIVE;
39258@@ -326,19 +326,19 @@ int tty_port_close_start(struct tty_port *port,
39259 return 0;
39260 }
39261
39262- if (tty->count == 1 && port->count != 1) {
39263+ if (tty->count == 1 && atomic_read(&port->count) != 1) {
39264 printk(KERN_WARNING
39265 "tty_port_close_start: tty->count = 1 port count = %d.\n",
39266- port->count);
39267- port->count = 1;
39268+ atomic_read(&port->count));
39269+ atomic_set(&port->count, 1);
39270 }
39271- if (--port->count < 0) {
39272+ if (atomic_dec_return(&port->count) < 0) {
39273 printk(KERN_WARNING "tty_port_close_start: count = %d\n",
39274- port->count);
39275- port->count = 0;
39276+ atomic_read(&port->count));
39277+ atomic_set(&port->count, 0);
39278 }
39279
39280- if (port->count) {
39281+ if (atomic_read(&port->count)) {
39282 spin_unlock_irqrestore(&port->lock, flags);
39283 if (port->ops->drop)
39284 port->ops->drop(port);
39285@@ -418,7 +418,7 @@ int tty_port_open(struct tty_port *port, struct tty_struct *tty,
39286 {
39287 spin_lock_irq(&port->lock);
39288 if (!tty_hung_up_p(filp))
39289- ++port->count;
39290+ atomic_inc(&port->count);
39291 spin_unlock_irq(&port->lock);
39292 tty_port_tty_set(port, tty);
39293
39294diff --git a/drivers/tty/vt/keyboard.c b/drivers/tty/vt/keyboard.c
39295index 770a854..e5d3db3 100644
39296--- a/drivers/tty/vt/keyboard.c
39297+++ b/drivers/tty/vt/keyboard.c
39298@@ -659,6 +659,16 @@ static void k_spec(struct vc_data *vc, unsigned char value, char up_flag)
39299 kbd->kbdmode == VC_OFF) &&
39300 value != KVAL(K_SAK))
39301 return; /* SAK is allowed even in raw mode */
39302+
39303+#if defined(CONFIG_GRKERNSEC_PROC) || defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
39304+ {
39305+ void *func = fn_handler[value];
39306+ if (func == fn_show_state || func == fn_show_ptregs ||
39307+ func == fn_show_mem)
39308+ return;
39309+ }
39310+#endif
39311+
39312 fn_handler[value](vc);
39313 }
39314
39315@@ -1805,9 +1815,6 @@ int vt_do_kdsk_ioctl(int cmd, struct kbentry __user *user_kbe, int perm,
39316 if (copy_from_user(&tmp, user_kbe, sizeof(struct kbentry)))
39317 return -EFAULT;
39318
39319- if (!capable(CAP_SYS_TTY_CONFIG))
39320- perm = 0;
39321-
39322 switch (cmd) {
39323 case KDGKBENT:
39324 /* Ensure another thread doesn't free it under us */
39325@@ -1822,6 +1829,9 @@ int vt_do_kdsk_ioctl(int cmd, struct kbentry __user *user_kbe, int perm,
39326 spin_unlock_irqrestore(&kbd_event_lock, flags);
39327 return put_user(val, &user_kbe->kb_value);
39328 case KDSKBENT:
39329+ if (!capable(CAP_SYS_TTY_CONFIG))
39330+ perm = 0;
39331+
39332 if (!perm)
39333 return -EPERM;
39334 if (!i && v == K_NOSUCHMAP) {
39335@@ -1912,9 +1922,6 @@ int vt_do_kdgkb_ioctl(int cmd, struct kbsentry __user *user_kdgkb, int perm)
39336 int i, j, k;
39337 int ret;
39338
39339- if (!capable(CAP_SYS_TTY_CONFIG))
39340- perm = 0;
39341-
39342 kbs = kmalloc(sizeof(*kbs), GFP_KERNEL);
39343 if (!kbs) {
39344 ret = -ENOMEM;
39345@@ -1948,6 +1955,9 @@ int vt_do_kdgkb_ioctl(int cmd, struct kbsentry __user *user_kdgkb, int perm)
39346 kfree(kbs);
39347 return ((p && *p) ? -EOVERFLOW : 0);
39348 case KDSKBSENT:
39349+ if (!capable(CAP_SYS_TTY_CONFIG))
39350+ perm = 0;
39351+
39352 if (!perm) {
39353 ret = -EPERM;
39354 goto reterr;
39355diff --git a/drivers/uio/uio.c b/drivers/uio/uio.c
39356index a783d53..cb30d94 100644
39357--- a/drivers/uio/uio.c
39358+++ b/drivers/uio/uio.c
39359@@ -25,6 +25,7 @@
39360 #include <linux/kobject.h>
39361 #include <linux/cdev.h>
39362 #include <linux/uio_driver.h>
39363+#include <asm/local.h>
39364
39365 #define UIO_MAX_DEVICES (1U << MINORBITS)
39366
39367@@ -32,10 +33,10 @@ struct uio_device {
39368 struct module *owner;
39369 struct device *dev;
39370 int minor;
39371- atomic_t event;
39372+ atomic_unchecked_t event;
39373 struct fasync_struct *async_queue;
39374 wait_queue_head_t wait;
39375- int vma_count;
39376+ local_t vma_count;
39377 struct uio_info *info;
39378 struct kobject *map_dir;
39379 struct kobject *portio_dir;
39380@@ -242,7 +243,7 @@ static ssize_t show_event(struct device *dev,
39381 struct device_attribute *attr, char *buf)
39382 {
39383 struct uio_device *idev = dev_get_drvdata(dev);
39384- return sprintf(buf, "%u\n", (unsigned int)atomic_read(&idev->event));
39385+ return sprintf(buf, "%u\n", (unsigned int)atomic_read_unchecked(&idev->event));
39386 }
39387
39388 static struct device_attribute uio_class_attributes[] = {
39389@@ -408,7 +409,7 @@ void uio_event_notify(struct uio_info *info)
39390 {
39391 struct uio_device *idev = info->uio_dev;
39392
39393- atomic_inc(&idev->event);
39394+ atomic_inc_unchecked(&idev->event);
39395 wake_up_interruptible(&idev->wait);
39396 kill_fasync(&idev->async_queue, SIGIO, POLL_IN);
39397 }
39398@@ -461,7 +462,7 @@ static int uio_open(struct inode *inode, struct file *filep)
39399 }
39400
39401 listener->dev = idev;
39402- listener->event_count = atomic_read(&idev->event);
39403+ listener->event_count = atomic_read_unchecked(&idev->event);
39404 filep->private_data = listener;
39405
39406 if (idev->info->open) {
39407@@ -512,7 +513,7 @@ static unsigned int uio_poll(struct file *filep, poll_table *wait)
39408 return -EIO;
39409
39410 poll_wait(filep, &idev->wait, wait);
39411- if (listener->event_count != atomic_read(&idev->event))
39412+ if (listener->event_count != atomic_read_unchecked(&idev->event))
39413 return POLLIN | POLLRDNORM;
39414 return 0;
39415 }
39416@@ -537,7 +538,7 @@ static ssize_t uio_read(struct file *filep, char __user *buf,
39417 do {
39418 set_current_state(TASK_INTERRUPTIBLE);
39419
39420- event_count = atomic_read(&idev->event);
39421+ event_count = atomic_read_unchecked(&idev->event);
39422 if (event_count != listener->event_count) {
39423 if (copy_to_user(buf, &event_count, count))
39424 retval = -EFAULT;
39425@@ -606,13 +607,13 @@ static int uio_find_mem_index(struct vm_area_struct *vma)
39426 static void uio_vma_open(struct vm_area_struct *vma)
39427 {
39428 struct uio_device *idev = vma->vm_private_data;
39429- idev->vma_count++;
39430+ local_inc(&idev->vma_count);
39431 }
39432
39433 static void uio_vma_close(struct vm_area_struct *vma)
39434 {
39435 struct uio_device *idev = vma->vm_private_data;
39436- idev->vma_count--;
39437+ local_dec(&idev->vma_count);
39438 }
39439
39440 static int uio_vma_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
39441@@ -821,7 +822,7 @@ int __uio_register_device(struct module *owner,
39442 idev->owner = owner;
39443 idev->info = info;
39444 init_waitqueue_head(&idev->wait);
39445- atomic_set(&idev->event, 0);
39446+ atomic_set_unchecked(&idev->event, 0);
39447
39448 ret = uio_get_minor(idev);
39449 if (ret)
39450diff --git a/drivers/usb/atm/cxacru.c b/drivers/usb/atm/cxacru.c
39451index b7eb86a..36d28af 100644
39452--- a/drivers/usb/atm/cxacru.c
39453+++ b/drivers/usb/atm/cxacru.c
39454@@ -473,7 +473,7 @@ static ssize_t cxacru_sysfs_store_adsl_config(struct device *dev,
39455 ret = sscanf(buf + pos, "%x=%x%n", &index, &value, &tmp);
39456 if (ret < 2)
39457 return -EINVAL;
39458- if (index < 0 || index > 0x7f)
39459+ if (index > 0x7f)
39460 return -EINVAL;
39461 pos += tmp;
39462
39463diff --git a/drivers/usb/atm/usbatm.c b/drivers/usb/atm/usbatm.c
39464index ee62b35..b663594 100644
39465--- a/drivers/usb/atm/usbatm.c
39466+++ b/drivers/usb/atm/usbatm.c
39467@@ -333,7 +333,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
39468 if (printk_ratelimit())
39469 atm_warn(instance, "%s: OAM not supported (vpi %d, vci %d)!\n",
39470 __func__, vpi, vci);
39471- atomic_inc(&vcc->stats->rx_err);
39472+ atomic_inc_unchecked(&vcc->stats->rx_err);
39473 return;
39474 }
39475
39476@@ -361,7 +361,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
39477 if (length > ATM_MAX_AAL5_PDU) {
39478 atm_rldbg(instance, "%s: bogus length %u (vcc: 0x%p)!\n",
39479 __func__, length, vcc);
39480- atomic_inc(&vcc->stats->rx_err);
39481+ atomic_inc_unchecked(&vcc->stats->rx_err);
39482 goto out;
39483 }
39484
39485@@ -370,14 +370,14 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
39486 if (sarb->len < pdu_length) {
39487 atm_rldbg(instance, "%s: bogus pdu_length %u (sarb->len: %u, vcc: 0x%p)!\n",
39488 __func__, pdu_length, sarb->len, vcc);
39489- atomic_inc(&vcc->stats->rx_err);
39490+ atomic_inc_unchecked(&vcc->stats->rx_err);
39491 goto out;
39492 }
39493
39494 if (crc32_be(~0, skb_tail_pointer(sarb) - pdu_length, pdu_length) != 0xc704dd7b) {
39495 atm_rldbg(instance, "%s: packet failed crc check (vcc: 0x%p)!\n",
39496 __func__, vcc);
39497- atomic_inc(&vcc->stats->rx_err);
39498+ atomic_inc_unchecked(&vcc->stats->rx_err);
39499 goto out;
39500 }
39501
39502@@ -387,7 +387,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
39503 if (printk_ratelimit())
39504 atm_err(instance, "%s: no memory for skb (length: %u)!\n",
39505 __func__, length);
39506- atomic_inc(&vcc->stats->rx_drop);
39507+ atomic_inc_unchecked(&vcc->stats->rx_drop);
39508 goto out;
39509 }
39510
39511@@ -412,7 +412,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
39512
39513 vcc->push(vcc, skb);
39514
39515- atomic_inc(&vcc->stats->rx);
39516+ atomic_inc_unchecked(&vcc->stats->rx);
39517 out:
39518 skb_trim(sarb, 0);
39519 }
39520@@ -615,7 +615,7 @@ static void usbatm_tx_process(unsigned long data)
39521 struct atm_vcc *vcc = UDSL_SKB(skb)->atm.vcc;
39522
39523 usbatm_pop(vcc, skb);
39524- atomic_inc(&vcc->stats->tx);
39525+ atomic_inc_unchecked(&vcc->stats->tx);
39526
39527 skb = skb_dequeue(&instance->sndqueue);
39528 }
39529@@ -770,11 +770,11 @@ static int usbatm_atm_proc_read(struct atm_dev *atm_dev, loff_t * pos, char *pag
39530 if (!left--)
39531 return sprintf(page,
39532 "AAL5: tx %d ( %d err ), rx %d ( %d err, %d drop )\n",
39533- atomic_read(&atm_dev->stats.aal5.tx),
39534- atomic_read(&atm_dev->stats.aal5.tx_err),
39535- atomic_read(&atm_dev->stats.aal5.rx),
39536- atomic_read(&atm_dev->stats.aal5.rx_err),
39537- atomic_read(&atm_dev->stats.aal5.rx_drop));
39538+ atomic_read_unchecked(&atm_dev->stats.aal5.tx),
39539+ atomic_read_unchecked(&atm_dev->stats.aal5.tx_err),
39540+ atomic_read_unchecked(&atm_dev->stats.aal5.rx),
39541+ atomic_read_unchecked(&atm_dev->stats.aal5.rx_err),
39542+ atomic_read_unchecked(&atm_dev->stats.aal5.rx_drop));
39543
39544 if (!left--) {
39545 if (instance->disconnected)
39546diff --git a/drivers/usb/core/devices.c b/drivers/usb/core/devices.c
39547index 3440812..2a4ef1f 100644
39548--- a/drivers/usb/core/devices.c
39549+++ b/drivers/usb/core/devices.c
39550@@ -126,7 +126,7 @@ static const char format_endpt[] =
39551 * time it gets called.
39552 */
39553 static struct device_connect_event {
39554- atomic_t count;
39555+ atomic_unchecked_t count;
39556 wait_queue_head_t wait;
39557 } device_event = {
39558 .count = ATOMIC_INIT(1),
39559@@ -164,7 +164,7 @@ static const struct class_info clas_info[] = {
39560
39561 void usbfs_conn_disc_event(void)
39562 {
39563- atomic_add(2, &device_event.count);
39564+ atomic_add_unchecked(2, &device_event.count);
39565 wake_up(&device_event.wait);
39566 }
39567
39568@@ -648,7 +648,7 @@ static unsigned int usb_device_poll(struct file *file,
39569
39570 poll_wait(file, &device_event.wait, wait);
39571
39572- event_count = atomic_read(&device_event.count);
39573+ event_count = atomic_read_unchecked(&device_event.count);
39574 if (file->f_version != event_count) {
39575 file->f_version = event_count;
39576 return POLLIN | POLLRDNORM;
39577diff --git a/drivers/usb/early/ehci-dbgp.c b/drivers/usb/early/ehci-dbgp.c
39578index 89dcf15..481800b 100644
39579--- a/drivers/usb/early/ehci-dbgp.c
39580+++ b/drivers/usb/early/ehci-dbgp.c
39581@@ -97,7 +97,8 @@ static inline u32 dbgp_len_update(u32 x, u32 len)
39582
39583 #ifdef CONFIG_KGDB
39584 static struct kgdb_io kgdbdbgp_io_ops;
39585-#define dbgp_kgdb_mode (dbg_io_ops == &kgdbdbgp_io_ops)
39586+static struct kgdb_io kgdbdbgp_io_ops_console;
39587+#define dbgp_kgdb_mode (dbg_io_ops == &kgdbdbgp_io_ops || dbg_io_ops == &kgdbdbgp_io_ops_console)
39588 #else
39589 #define dbgp_kgdb_mode (0)
39590 #endif
39591@@ -1035,6 +1036,13 @@ static struct kgdb_io kgdbdbgp_io_ops = {
39592 .write_char = kgdbdbgp_write_char,
39593 };
39594
39595+static struct kgdb_io kgdbdbgp_io_ops_console = {
39596+ .name = "kgdbdbgp",
39597+ .read_char = kgdbdbgp_read_char,
39598+ .write_char = kgdbdbgp_write_char,
39599+ .is_console = 1
39600+};
39601+
39602 static int kgdbdbgp_wait_time;
39603
39604 static int __init kgdbdbgp_parse_config(char *str)
39605@@ -1050,8 +1058,10 @@ static int __init kgdbdbgp_parse_config(char *str)
39606 ptr++;
39607 kgdbdbgp_wait_time = simple_strtoul(ptr, &ptr, 10);
39608 }
39609- kgdb_register_io_module(&kgdbdbgp_io_ops);
39610- kgdbdbgp_io_ops.is_console = early_dbgp_console.index != -1;
39611+ if (early_dbgp_console.index != -1)
39612+ kgdb_register_io_module(&kgdbdbgp_io_ops_console);
39613+ else
39614+ kgdb_register_io_module(&kgdbdbgp_io_ops);
39615
39616 return 0;
39617 }
39618diff --git a/drivers/usb/gadget/u_serial.c b/drivers/usb/gadget/u_serial.c
39619index da6d479..80ed10b 100644
39620--- a/drivers/usb/gadget/u_serial.c
39621+++ b/drivers/usb/gadget/u_serial.c
39622@@ -735,9 +735,9 @@ static int gs_open(struct tty_struct *tty, struct file *file)
39623 spin_lock_irq(&port->port_lock);
39624
39625 /* already open? Great. */
39626- if (port->port.count) {
39627+ if (atomic_read(&port->port.count)) {
39628 status = 0;
39629- port->port.count++;
39630+ atomic_inc(&port->port.count);
39631
39632 /* currently opening/closing? wait ... */
39633 } else if (port->openclose) {
39634@@ -796,7 +796,7 @@ static int gs_open(struct tty_struct *tty, struct file *file)
39635 tty->driver_data = port;
39636 port->port.tty = tty;
39637
39638- port->port.count = 1;
39639+ atomic_set(&port->port.count, 1);
39640 port->openclose = false;
39641
39642 /* if connected, start the I/O stream */
39643@@ -838,11 +838,11 @@ static void gs_close(struct tty_struct *tty, struct file *file)
39644
39645 spin_lock_irq(&port->port_lock);
39646
39647- if (port->port.count != 1) {
39648- if (port->port.count == 0)
39649+ if (atomic_read(&port->port.count) != 1) {
39650+ if (atomic_read(&port->port.count) == 0)
39651 WARN_ON(1);
39652 else
39653- --port->port.count;
39654+ atomic_dec(&port->port.count);
39655 goto exit;
39656 }
39657
39658@@ -852,7 +852,7 @@ static void gs_close(struct tty_struct *tty, struct file *file)
39659 * and sleep if necessary
39660 */
39661 port->openclose = true;
39662- port->port.count = 0;
39663+ atomic_set(&port->port.count, 0);
39664
39665 gser = port->port_usb;
39666 if (gser && gser->disconnect)
39667@@ -1156,7 +1156,7 @@ static int gs_closed(struct gs_port *port)
39668 int cond;
39669
39670 spin_lock_irq(&port->port_lock);
39671- cond = (port->port.count == 0) && !port->openclose;
39672+ cond = (atomic_read(&port->port.count) == 0) && !port->openclose;
39673 spin_unlock_irq(&port->port_lock);
39674 return cond;
39675 }
39676@@ -1269,7 +1269,7 @@ int gserial_connect(struct gserial *gser, u8 port_num)
39677 /* if it's already open, start I/O ... and notify the serial
39678 * protocol about open/close status (connect/disconnect).
39679 */
39680- if (port->port.count) {
39681+ if (atomic_read(&port->port.count)) {
39682 pr_debug("gserial_connect: start ttyGS%d\n", port->port_num);
39683 gs_start_io(port);
39684 if (gser->connect)
39685@@ -1316,7 +1316,7 @@ void gserial_disconnect(struct gserial *gser)
39686
39687 port->port_usb = NULL;
39688 gser->ioport = NULL;
39689- if (port->port.count > 0 || port->openclose) {
39690+ if (atomic_read(&port->port.count) > 0 || port->openclose) {
39691 wake_up_interruptible(&port->drain_wait);
39692 if (port->port.tty)
39693 tty_hangup(port->port.tty);
39694@@ -1332,7 +1332,7 @@ void gserial_disconnect(struct gserial *gser)
39695
39696 /* finally, free any unused/unusable I/O buffers */
39697 spin_lock_irqsave(&port->port_lock, flags);
39698- if (port->port.count == 0 && !port->openclose)
39699+ if (atomic_read(&port->port.count) == 0 && !port->openclose)
39700 gs_buf_free(&port->port_write_buf);
39701 gs_free_requests(gser->out, &port->read_pool, NULL);
39702 gs_free_requests(gser->out, &port->read_queue, NULL);
39703diff --git a/drivers/usb/serial/console.c b/drivers/usb/serial/console.c
39704index b9cca6d..75c75df 100644
39705--- a/drivers/usb/serial/console.c
39706+++ b/drivers/usb/serial/console.c
39707@@ -127,7 +127,7 @@ static int usb_console_setup(struct console *co, char *options)
39708
39709 info->port = port;
39710
39711- ++port->port.count;
39712+ atomic_inc(&port->port.count);
39713 if (!test_bit(ASYNCB_INITIALIZED, &port->port.flags)) {
39714 if (serial->type->set_termios) {
39715 /*
39716@@ -177,7 +177,7 @@ static int usb_console_setup(struct console *co, char *options)
39717 }
39718 /* Now that any required fake tty operations are completed restore
39719 * the tty port count */
39720- --port->port.count;
39721+ atomic_dec(&port->port.count);
39722 /* The console is special in terms of closing the device so
39723 * indicate this port is now acting as a system console. */
39724 port->port.console = 1;
39725@@ -190,7 +190,7 @@ static int usb_console_setup(struct console *co, char *options)
39726 free_tty:
39727 kfree(tty);
39728 reset_open_count:
39729- port->port.count = 0;
39730+ atomic_set(&port->port.count, 0);
39731 usb_autopm_put_interface(serial->interface);
39732 error_get_interface:
39733 usb_serial_put(serial);
39734diff --git a/drivers/usb/wusbcore/wa-hc.h b/drivers/usb/wusbcore/wa-hc.h
39735index d6bea3e..60b250e 100644
39736--- a/drivers/usb/wusbcore/wa-hc.h
39737+++ b/drivers/usb/wusbcore/wa-hc.h
39738@@ -192,7 +192,7 @@ struct wahc {
39739 struct list_head xfer_delayed_list;
39740 spinlock_t xfer_list_lock;
39741 struct work_struct xfer_work;
39742- atomic_t xfer_id_count;
39743+ atomic_unchecked_t xfer_id_count;
39744 };
39745
39746
39747@@ -246,7 +246,7 @@ static inline void wa_init(struct wahc *wa)
39748 INIT_LIST_HEAD(&wa->xfer_delayed_list);
39749 spin_lock_init(&wa->xfer_list_lock);
39750 INIT_WORK(&wa->xfer_work, wa_urb_enqueue_run);
39751- atomic_set(&wa->xfer_id_count, 1);
39752+ atomic_set_unchecked(&wa->xfer_id_count, 1);
39753 }
39754
39755 /**
39756diff --git a/drivers/usb/wusbcore/wa-xfer.c b/drivers/usb/wusbcore/wa-xfer.c
39757index 57c01ab..8a05959 100644
39758--- a/drivers/usb/wusbcore/wa-xfer.c
39759+++ b/drivers/usb/wusbcore/wa-xfer.c
39760@@ -296,7 +296,7 @@ out:
39761 */
39762 static void wa_xfer_id_init(struct wa_xfer *xfer)
39763 {
39764- xfer->id = atomic_add_return(1, &xfer->wa->xfer_id_count);
39765+ xfer->id = atomic_add_return_unchecked(1, &xfer->wa->xfer_id_count);
39766 }
39767
39768 /*
39769diff --git a/drivers/vhost/vhost.c b/drivers/vhost/vhost.c
39770index ef82a0d..da8a0b3 100644
39771--- a/drivers/vhost/vhost.c
39772+++ b/drivers/vhost/vhost.c
39773@@ -634,7 +634,7 @@ static long vhost_set_memory(struct vhost_dev *d, struct vhost_memory __user *m)
39774 return 0;
39775 }
39776
39777-static long vhost_set_vring(struct vhost_dev *d, int ioctl, void __user *argp)
39778+static long vhost_set_vring(struct vhost_dev *d, unsigned int ioctl, void __user *argp)
39779 {
39780 struct file *eventfp, *filep = NULL,
39781 *pollstart = NULL, *pollstop = NULL;
39782diff --git a/drivers/video/aty/aty128fb.c b/drivers/video/aty/aty128fb.c
39783index 747442d..7c0c434 100644
39784--- a/drivers/video/aty/aty128fb.c
39785+++ b/drivers/video/aty/aty128fb.c
39786@@ -149,7 +149,7 @@ enum {
39787 };
39788
39789 /* Must match above enum */
39790-static const char *r128_family[] __devinitdata = {
39791+static const char *r128_family[] __devinitconst = {
39792 "AGP",
39793 "PCI",
39794 "PRO AGP",
39795diff --git a/drivers/video/fbcmap.c b/drivers/video/fbcmap.c
39796index 5c3960d..15cf8fc 100644
39797--- a/drivers/video/fbcmap.c
39798+++ b/drivers/video/fbcmap.c
39799@@ -285,8 +285,7 @@ int fb_set_user_cmap(struct fb_cmap_user *cmap, struct fb_info *info)
39800 rc = -ENODEV;
39801 goto out;
39802 }
39803- if (cmap->start < 0 || (!info->fbops->fb_setcolreg &&
39804- !info->fbops->fb_setcmap)) {
39805+ if (!info->fbops->fb_setcolreg && !info->fbops->fb_setcmap) {
39806 rc = -EINVAL;
39807 goto out1;
39808 }
39809diff --git a/drivers/video/fbmem.c b/drivers/video/fbmem.c
39810index 0dff12a..2ef47b3 100644
39811--- a/drivers/video/fbmem.c
39812+++ b/drivers/video/fbmem.c
39813@@ -428,7 +428,7 @@ static void fb_do_show_logo(struct fb_info *info, struct fb_image *image,
39814 image->dx += image->width + 8;
39815 }
39816 } else if (rotate == FB_ROTATE_UD) {
39817- for (x = 0; x < num && image->dx >= 0; x++) {
39818+ for (x = 0; x < num && (__s32)image->dx >= 0; x++) {
39819 info->fbops->fb_imageblit(info, image);
39820 image->dx -= image->width + 8;
39821 }
39822@@ -440,7 +440,7 @@ static void fb_do_show_logo(struct fb_info *info, struct fb_image *image,
39823 image->dy += image->height + 8;
39824 }
39825 } else if (rotate == FB_ROTATE_CCW) {
39826- for (x = 0; x < num && image->dy >= 0; x++) {
39827+ for (x = 0; x < num && (__s32)image->dy >= 0; x++) {
39828 info->fbops->fb_imageblit(info, image);
39829 image->dy -= image->height + 8;
39830 }
39831@@ -1166,7 +1166,7 @@ static long do_fb_ioctl(struct fb_info *info, unsigned int cmd,
39832 return -EFAULT;
39833 if (con2fb.console < 1 || con2fb.console > MAX_NR_CONSOLES)
39834 return -EINVAL;
39835- if (con2fb.framebuffer < 0 || con2fb.framebuffer >= FB_MAX)
39836+ if (con2fb.framebuffer >= FB_MAX)
39837 return -EINVAL;
39838 if (!registered_fb[con2fb.framebuffer])
39839 request_module("fb%d", con2fb.framebuffer);
39840diff --git a/drivers/video/geode/gx1fb_core.c b/drivers/video/geode/gx1fb_core.c
39841index 5a5d092..265c5ed 100644
39842--- a/drivers/video/geode/gx1fb_core.c
39843+++ b/drivers/video/geode/gx1fb_core.c
39844@@ -29,7 +29,7 @@ static int crt_option = 1;
39845 static char panel_option[32] = "";
39846
39847 /* Modes relevant to the GX1 (taken from modedb.c) */
39848-static const struct fb_videomode __devinitdata gx1_modedb[] = {
39849+static const struct fb_videomode __devinitconst gx1_modedb[] = {
39850 /* 640x480-60 VESA */
39851 { NULL, 60, 640, 480, 39682, 48, 16, 33, 10, 96, 2,
39852 0, FB_VMODE_NONINTERLACED, FB_MODE_IS_VESA },
39853diff --git a/drivers/video/gxt4500.c b/drivers/video/gxt4500.c
39854index 0fad23f..0e9afa4 100644
39855--- a/drivers/video/gxt4500.c
39856+++ b/drivers/video/gxt4500.c
39857@@ -156,7 +156,7 @@ struct gxt4500_par {
39858 static char *mode_option;
39859
39860 /* default mode: 1280x1024 @ 60 Hz, 8 bpp */
39861-static const struct fb_videomode defaultmode __devinitdata = {
39862+static const struct fb_videomode defaultmode __devinitconst = {
39863 .refresh = 60,
39864 .xres = 1280,
39865 .yres = 1024,
39866@@ -581,7 +581,7 @@ static int gxt4500_blank(int blank, struct fb_info *info)
39867 return 0;
39868 }
39869
39870-static const struct fb_fix_screeninfo gxt4500_fix __devinitdata = {
39871+static const struct fb_fix_screeninfo gxt4500_fix __devinitconst = {
39872 .id = "IBM GXT4500P",
39873 .type = FB_TYPE_PACKED_PIXELS,
39874 .visual = FB_VISUAL_PSEUDOCOLOR,
39875diff --git a/drivers/video/i810/i810_accel.c b/drivers/video/i810/i810_accel.c
39876index 7672d2e..b56437f 100644
39877--- a/drivers/video/i810/i810_accel.c
39878+++ b/drivers/video/i810/i810_accel.c
39879@@ -73,6 +73,7 @@ static inline int wait_for_space(struct fb_info *info, u32 space)
39880 }
39881 }
39882 printk("ringbuffer lockup!!!\n");
39883+ printk("head:%u tail:%u iring.size:%u space:%u\n", head, tail, par->iring.size, space);
39884 i810_report_error(mmio);
39885 par->dev_flags |= LOCKUP;
39886 info->pixmap.scan_align = 1;
39887diff --git a/drivers/video/i810/i810_main.c b/drivers/video/i810/i810_main.c
39888index b83f361..2b05a91 100644
39889--- a/drivers/video/i810/i810_main.c
39890+++ b/drivers/video/i810/i810_main.c
39891@@ -97,7 +97,7 @@ static int i810fb_blank (int blank_mode, struct fb_info *info);
39892 static void i810fb_release_resource (struct fb_info *info, struct i810fb_par *par);
39893
39894 /* PCI */
39895-static const char *i810_pci_list[] __devinitdata = {
39896+static const char *i810_pci_list[] __devinitconst = {
39897 "Intel(R) 810 Framebuffer Device" ,
39898 "Intel(R) 810-DC100 Framebuffer Device" ,
39899 "Intel(R) 810E Framebuffer Device" ,
39900diff --git a/drivers/video/jz4740_fb.c b/drivers/video/jz4740_fb.c
39901index de36693..3c63fc2 100644
39902--- a/drivers/video/jz4740_fb.c
39903+++ b/drivers/video/jz4740_fb.c
39904@@ -136,7 +136,7 @@ struct jzfb {
39905 uint32_t pseudo_palette[16];
39906 };
39907
39908-static const struct fb_fix_screeninfo jzfb_fix __devinitdata = {
39909+static const struct fb_fix_screeninfo jzfb_fix __devinitconst = {
39910 .id = "JZ4740 FB",
39911 .type = FB_TYPE_PACKED_PIXELS,
39912 .visual = FB_VISUAL_TRUECOLOR,
39913diff --git a/drivers/video/logo/logo_linux_clut224.ppm b/drivers/video/logo/logo_linux_clut224.ppm
39914index 3c14e43..eafa544 100644
39915--- a/drivers/video/logo/logo_linux_clut224.ppm
39916+++ b/drivers/video/logo/logo_linux_clut224.ppm
39917@@ -1,1604 +1,1123 @@
39918 P3
39919-# Standard 224-color Linux logo
39920 80 80
39921 255
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- 6 6 6 6 6 6 10 10 10 10 10 10
39932- 10 10 10 6 6 6 6 6 6 6 6 6
39933- 0 0 0 0 0 0 0 0 0 0 0 0
39934- 0 0 0 0 0 0 0 0 0 0 0 0
39935- 0 0 0 0 0 0 0 0 0 0 0 0
39936- 0 0 0 0 0 0 0 0 0 0 0 0
39937- 0 0 0 0 0 0 0 0 0 0 0 0
39938- 0 0 0 0 0 0 0 0 0 0 0 0
39939- 0 0 0 0 0 0 0 0 0 0 0 0
39940- 0 0 0 0 0 0 0 0 0 0 0 0
39941- 0 0 0 0 0 0 0 0 0 0 0 0
39942- 0 0 0 0 0 0 0 0 0 0 0 0
39943- 0 0 0 0 0 0 0 0 0 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 6 6 6 10 10 10 14 14 14
39951- 22 22 22 26 26 26 30 30 30 34 34 34
39952- 30 30 30 30 30 30 26 26 26 18 18 18
39953- 14 14 14 10 10 10 6 6 6 0 0 0
39954- 0 0 0 0 0 0 0 0 0 0 0 0
39955- 0 0 0 0 0 0 0 0 0 0 0 0
39956- 0 0 0 0 0 0 0 0 0 0 0 0
39957- 0 0 0 0 0 0 0 0 0 0 0 0
39958- 0 0 0 0 0 0 0 0 0 0 0 0
39959- 0 0 0 0 0 0 0 0 0 0 0 0
39960- 0 0 0 0 0 0 0 0 0 0 0 0
39961- 0 0 0 0 0 0 0 0 0 0 0 0
39962- 0 0 0 0 0 0 0 0 0 0 0 0
39963- 0 0 0 0 0 1 0 0 1 0 0 0
39964- 0 0 0 0 0 0 0 0 0 0 0 0
39965- 0 0 0 0 0 0 0 0 0 0 0 0
39966- 0 0 0 0 0 0 0 0 0 0 0 0
39967- 0 0 0 0 0 0 0 0 0 0 0 0
39968- 0 0 0 0 0 0 0 0 0 0 0 0
39969- 0 0 0 0 0 0 0 0 0 0 0 0
39970- 6 6 6 14 14 14 26 26 26 42 42 42
39971- 54 54 54 66 66 66 78 78 78 78 78 78
39972- 78 78 78 74 74 74 66 66 66 54 54 54
39973- 42 42 42 26 26 26 18 18 18 10 10 10
39974- 6 6 6 0 0 0 0 0 0 0 0 0
39975- 0 0 0 0 0 0 0 0 0 0 0 0
39976- 0 0 0 0 0 0 0 0 0 0 0 0
39977- 0 0 0 0 0 0 0 0 0 0 0 0
39978- 0 0 0 0 0 0 0 0 0 0 0 0
39979- 0 0 0 0 0 0 0 0 0 0 0 0
39980- 0 0 0 0 0 0 0 0 0 0 0 0
39981- 0 0 0 0 0 0 0 0 0 0 0 0
39982- 0 0 0 0 0 0 0 0 0 0 0 0
39983- 0 0 1 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 10 10 10
39990- 22 22 22 42 42 42 66 66 66 86 86 86
39991- 66 66 66 38 38 38 38 38 38 22 22 22
39992- 26 26 26 34 34 34 54 54 54 66 66 66
39993- 86 86 86 70 70 70 46 46 46 26 26 26
39994- 14 14 14 6 6 6 0 0 0 0 0 0
39995- 0 0 0 0 0 0 0 0 0 0 0 0
39996- 0 0 0 0 0 0 0 0 0 0 0 0
39997- 0 0 0 0 0 0 0 0 0 0 0 0
39998- 0 0 0 0 0 0 0 0 0 0 0 0
39999- 0 0 0 0 0 0 0 0 0 0 0 0
40000- 0 0 0 0 0 0 0 0 0 0 0 0
40001- 0 0 0 0 0 0 0 0 0 0 0 0
40002- 0 0 0 0 0 0 0 0 0 0 0 0
40003- 0 0 1 0 0 1 0 0 1 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 10 10 10 26 26 26
40010- 50 50 50 82 82 82 58 58 58 6 6 6
40011- 2 2 6 2 2 6 2 2 6 2 2 6
40012- 2 2 6 2 2 6 2 2 6 2 2 6
40013- 6 6 6 54 54 54 86 86 86 66 66 66
40014- 38 38 38 18 18 18 6 6 6 0 0 0
40015- 0 0 0 0 0 0 0 0 0 0 0 0
40016- 0 0 0 0 0 0 0 0 0 0 0 0
40017- 0 0 0 0 0 0 0 0 0 0 0 0
40018- 0 0 0 0 0 0 0 0 0 0 0 0
40019- 0 0 0 0 0 0 0 0 0 0 0 0
40020- 0 0 0 0 0 0 0 0 0 0 0 0
40021- 0 0 0 0 0 0 0 0 0 0 0 0
40022- 0 0 0 0 0 0 0 0 0 0 0 0
40023- 0 0 0 0 0 0 0 0 0 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 6 6 6 22 22 22 50 50 50
40030- 78 78 78 34 34 34 2 2 6 2 2 6
40031- 2 2 6 2 2 6 2 2 6 2 2 6
40032- 2 2 6 2 2 6 2 2 6 2 2 6
40033- 2 2 6 2 2 6 6 6 6 70 70 70
40034- 78 78 78 46 46 46 22 22 22 6 6 6
40035- 0 0 0 0 0 0 0 0 0 0 0 0
40036- 0 0 0 0 0 0 0 0 0 0 0 0
40037- 0 0 0 0 0 0 0 0 0 0 0 0
40038- 0 0 0 0 0 0 0 0 0 0 0 0
40039- 0 0 0 0 0 0 0 0 0 0 0 0
40040- 0 0 0 0 0 0 0 0 0 0 0 0
40041- 0 0 0 0 0 0 0 0 0 0 0 0
40042- 0 0 0 0 0 0 0 0 0 0 0 0
40043- 0 0 1 0 0 1 0 0 1 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- 6 6 6 18 18 18 42 42 42 82 82 82
40050- 26 26 26 2 2 6 2 2 6 2 2 6
40051- 2 2 6 2 2 6 2 2 6 2 2 6
40052- 2 2 6 2 2 6 2 2 6 14 14 14
40053- 46 46 46 34 34 34 6 6 6 2 2 6
40054- 42 42 42 78 78 78 42 42 42 18 18 18
40055- 6 6 6 0 0 0 0 0 0 0 0 0
40056- 0 0 0 0 0 0 0 0 0 0 0 0
40057- 0 0 0 0 0 0 0 0 0 0 0 0
40058- 0 0 0 0 0 0 0 0 0 0 0 0
40059- 0 0 0 0 0 0 0 0 0 0 0 0
40060- 0 0 0 0 0 0 0 0 0 0 0 0
40061- 0 0 0 0 0 0 0 0 0 0 0 0
40062- 0 0 0 0 0 0 0 0 0 0 0 0
40063- 0 0 1 0 0 0 0 0 1 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- 10 10 10 30 30 30 66 66 66 58 58 58
40070- 2 2 6 2 2 6 2 2 6 2 2 6
40071- 2 2 6 2 2 6 2 2 6 2 2 6
40072- 2 2 6 2 2 6 2 2 6 26 26 26
40073- 86 86 86 101 101 101 46 46 46 10 10 10
40074- 2 2 6 58 58 58 70 70 70 34 34 34
40075- 10 10 10 0 0 0 0 0 0 0 0 0
40076- 0 0 0 0 0 0 0 0 0 0 0 0
40077- 0 0 0 0 0 0 0 0 0 0 0 0
40078- 0 0 0 0 0 0 0 0 0 0 0 0
40079- 0 0 0 0 0 0 0 0 0 0 0 0
40080- 0 0 0 0 0 0 0 0 0 0 0 0
40081- 0 0 0 0 0 0 0 0 0 0 0 0
40082- 0 0 0 0 0 0 0 0 0 0 0 0
40083- 0 0 1 0 0 1 0 0 1 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- 14 14 14 42 42 42 86 86 86 10 10 10
40090- 2 2 6 2 2 6 2 2 6 2 2 6
40091- 2 2 6 2 2 6 2 2 6 2 2 6
40092- 2 2 6 2 2 6 2 2 6 30 30 30
40093- 94 94 94 94 94 94 58 58 58 26 26 26
40094- 2 2 6 6 6 6 78 78 78 54 54 54
40095- 22 22 22 6 6 6 0 0 0 0 0 0
40096- 0 0 0 0 0 0 0 0 0 0 0 0
40097- 0 0 0 0 0 0 0 0 0 0 0 0
40098- 0 0 0 0 0 0 0 0 0 0 0 0
40099- 0 0 0 0 0 0 0 0 0 0 0 0
40100- 0 0 0 0 0 0 0 0 0 0 0 0
40101- 0 0 0 0 0 0 0 0 0 0 0 0
40102- 0 0 0 0 0 0 0 0 0 0 0 0
40103- 0 0 0 0 0 0 0 0 0 0 0 0
40104- 0 0 0 0 0 0 0 0 0 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 6 6 6
40109- 22 22 22 62 62 62 62 62 62 2 2 6
40110- 2 2 6 2 2 6 2 2 6 2 2 6
40111- 2 2 6 2 2 6 2 2 6 2 2 6
40112- 2 2 6 2 2 6 2 2 6 26 26 26
40113- 54 54 54 38 38 38 18 18 18 10 10 10
40114- 2 2 6 2 2 6 34 34 34 82 82 82
40115- 38 38 38 14 14 14 0 0 0 0 0 0
40116- 0 0 0 0 0 0 0 0 0 0 0 0
40117- 0 0 0 0 0 0 0 0 0 0 0 0
40118- 0 0 0 0 0 0 0 0 0 0 0 0
40119- 0 0 0 0 0 0 0 0 0 0 0 0
40120- 0 0 0 0 0 0 0 0 0 0 0 0
40121- 0 0 0 0 0 0 0 0 0 0 0 0
40122- 0 0 0 0 0 0 0 0 0 0 0 0
40123- 0 0 0 0 0 1 0 0 1 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 6 6 6
40129- 30 30 30 78 78 78 30 30 30 2 2 6
40130- 2 2 6 2 2 6 2 2 6 2 2 6
40131- 2 2 6 2 2 6 2 2 6 2 2 6
40132- 2 2 6 2 2 6 2 2 6 10 10 10
40133- 10 10 10 2 2 6 2 2 6 2 2 6
40134- 2 2 6 2 2 6 2 2 6 78 78 78
40135- 50 50 50 18 18 18 6 6 6 0 0 0
40136- 0 0 0 0 0 0 0 0 0 0 0 0
40137- 0 0 0 0 0 0 0 0 0 0 0 0
40138- 0 0 0 0 0 0 0 0 0 0 0 0
40139- 0 0 0 0 0 0 0 0 0 0 0 0
40140- 0 0 0 0 0 0 0 0 0 0 0 0
40141- 0 0 0 0 0 0 0 0 0 0 0 0
40142- 0 0 0 0 0 0 0 0 0 0 0 0
40143- 0 0 1 0 0 0 0 0 0 0 0 0
40144- 0 0 0 0 0 0 0 0 0 0 0 0
40145- 0 0 0 0 0 0 0 0 0 0 0 0
40146- 0 0 0 0 0 0 0 0 0 0 0 0
40147- 0 0 0 0 0 0 0 0 0 0 0 0
40148- 0 0 0 0 0 0 0 0 0 10 10 10
40149- 38 38 38 86 86 86 14 14 14 2 2 6
40150- 2 2 6 2 2 6 2 2 6 2 2 6
40151- 2 2 6 2 2 6 2 2 6 2 2 6
40152- 2 2 6 2 2 6 2 2 6 2 2 6
40153- 2 2 6 2 2 6 2 2 6 2 2 6
40154- 2 2 6 2 2 6 2 2 6 54 54 54
40155- 66 66 66 26 26 26 6 6 6 0 0 0
40156- 0 0 0 0 0 0 0 0 0 0 0 0
40157- 0 0 0 0 0 0 0 0 0 0 0 0
40158- 0 0 0 0 0 0 0 0 0 0 0 0
40159- 0 0 0 0 0 0 0 0 0 0 0 0
40160- 0 0 0 0 0 0 0 0 0 0 0 0
40161- 0 0 0 0 0 0 0 0 0 0 0 0
40162- 0 0 0 0 0 0 0 0 0 0 0 0
40163- 0 0 0 0 0 1 0 0 1 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 14 14 14
40169- 42 42 42 82 82 82 2 2 6 2 2 6
40170- 2 2 6 6 6 6 10 10 10 2 2 6
40171- 2 2 6 2 2 6 2 2 6 2 2 6
40172- 2 2 6 2 2 6 2 2 6 6 6 6
40173- 14 14 14 10 10 10 2 2 6 2 2 6
40174- 2 2 6 2 2 6 2 2 6 18 18 18
40175- 82 82 82 34 34 34 10 10 10 0 0 0
40176- 0 0 0 0 0 0 0 0 0 0 0 0
40177- 0 0 0 0 0 0 0 0 0 0 0 0
40178- 0 0 0 0 0 0 0 0 0 0 0 0
40179- 0 0 0 0 0 0 0 0 0 0 0 0
40180- 0 0 0 0 0 0 0 0 0 0 0 0
40181- 0 0 0 0 0 0 0 0 0 0 0 0
40182- 0 0 0 0 0 0 0 0 0 0 0 0
40183- 0 0 1 0 0 0 0 0 0 0 0 0
40184- 0 0 0 0 0 0 0 0 0 0 0 0
40185- 0 0 0 0 0 0 0 0 0 0 0 0
40186- 0 0 0 0 0 0 0 0 0 0 0 0
40187- 0 0 0 0 0 0 0 0 0 0 0 0
40188- 0 0 0 0 0 0 0 0 0 14 14 14
40189- 46 46 46 86 86 86 2 2 6 2 2 6
40190- 6 6 6 6 6 6 22 22 22 34 34 34
40191- 6 6 6 2 2 6 2 2 6 2 2 6
40192- 2 2 6 2 2 6 18 18 18 34 34 34
40193- 10 10 10 50 50 50 22 22 22 2 2 6
40194- 2 2 6 2 2 6 2 2 6 10 10 10
40195- 86 86 86 42 42 42 14 14 14 0 0 0
40196- 0 0 0 0 0 0 0 0 0 0 0 0
40197- 0 0 0 0 0 0 0 0 0 0 0 0
40198- 0 0 0 0 0 0 0 0 0 0 0 0
40199- 0 0 0 0 0 0 0 0 0 0 0 0
40200- 0 0 0 0 0 0 0 0 0 0 0 0
40201- 0 0 0 0 0 0 0 0 0 0 0 0
40202- 0 0 0 0 0 0 0 0 0 0 0 0
40203- 0 0 1 0 0 1 0 0 1 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 14 14 14
40209- 46 46 46 86 86 86 2 2 6 2 2 6
40210- 38 38 38 116 116 116 94 94 94 22 22 22
40211- 22 22 22 2 2 6 2 2 6 2 2 6
40212- 14 14 14 86 86 86 138 138 138 162 162 162
40213-154 154 154 38 38 38 26 26 26 6 6 6
40214- 2 2 6 2 2 6 2 2 6 2 2 6
40215- 86 86 86 46 46 46 14 14 14 0 0 0
40216- 0 0 0 0 0 0 0 0 0 0 0 0
40217- 0 0 0 0 0 0 0 0 0 0 0 0
40218- 0 0 0 0 0 0 0 0 0 0 0 0
40219- 0 0 0 0 0 0 0 0 0 0 0 0
40220- 0 0 0 0 0 0 0 0 0 0 0 0
40221- 0 0 0 0 0 0 0 0 0 0 0 0
40222- 0 0 0 0 0 0 0 0 0 0 0 0
40223- 0 0 0 0 0 0 0 0 0 0 0 0
40224- 0 0 0 0 0 0 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 14 14 14
40229- 46 46 46 86 86 86 2 2 6 14 14 14
40230-134 134 134 198 198 198 195 195 195 116 116 116
40231- 10 10 10 2 2 6 2 2 6 6 6 6
40232-101 98 89 187 187 187 210 210 210 218 218 218
40233-214 214 214 134 134 134 14 14 14 6 6 6
40234- 2 2 6 2 2 6 2 2 6 2 2 6
40235- 86 86 86 50 50 50 18 18 18 6 6 6
40236- 0 0 0 0 0 0 0 0 0 0 0 0
40237- 0 0 0 0 0 0 0 0 0 0 0 0
40238- 0 0 0 0 0 0 0 0 0 0 0 0
40239- 0 0 0 0 0 0 0 0 0 0 0 0
40240- 0 0 0 0 0 0 0 0 0 0 0 0
40241- 0 0 0 0 0 0 0 0 0 0 0 0
40242- 0 0 0 0 0 0 0 0 1 0 0 0
40243- 0 0 1 0 0 1 0 0 1 0 0 0
40244- 0 0 0 0 0 0 0 0 0 0 0 0
40245- 0 0 0 0 0 0 0 0 0 0 0 0
40246- 0 0 0 0 0 0 0 0 0 0 0 0
40247- 0 0 0 0 0 0 0 0 0 0 0 0
40248- 0 0 0 0 0 0 0 0 0 14 14 14
40249- 46 46 46 86 86 86 2 2 6 54 54 54
40250-218 218 218 195 195 195 226 226 226 246 246 246
40251- 58 58 58 2 2 6 2 2 6 30 30 30
40252-210 210 210 253 253 253 174 174 174 123 123 123
40253-221 221 221 234 234 234 74 74 74 2 2 6
40254- 2 2 6 2 2 6 2 2 6 2 2 6
40255- 70 70 70 58 58 58 22 22 22 6 6 6
40256- 0 0 0 0 0 0 0 0 0 0 0 0
40257- 0 0 0 0 0 0 0 0 0 0 0 0
40258- 0 0 0 0 0 0 0 0 0 0 0 0
40259- 0 0 0 0 0 0 0 0 0 0 0 0
40260- 0 0 0 0 0 0 0 0 0 0 0 0
40261- 0 0 0 0 0 0 0 0 0 0 0 0
40262- 0 0 0 0 0 0 0 0 0 0 0 0
40263- 0 0 0 0 0 0 0 0 0 0 0 0
40264- 0 0 0 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 14 14 14
40269- 46 46 46 82 82 82 2 2 6 106 106 106
40270-170 170 170 26 26 26 86 86 86 226 226 226
40271-123 123 123 10 10 10 14 14 14 46 46 46
40272-231 231 231 190 190 190 6 6 6 70 70 70
40273- 90 90 90 238 238 238 158 158 158 2 2 6
40274- 2 2 6 2 2 6 2 2 6 2 2 6
40275- 70 70 70 58 58 58 22 22 22 6 6 6
40276- 0 0 0 0 0 0 0 0 0 0 0 0
40277- 0 0 0 0 0 0 0 0 0 0 0 0
40278- 0 0 0 0 0 0 0 0 0 0 0 0
40279- 0 0 0 0 0 0 0 0 0 0 0 0
40280- 0 0 0 0 0 0 0 0 0 0 0 0
40281- 0 0 0 0 0 0 0 0 0 0 0 0
40282- 0 0 0 0 0 0 0 0 1 0 0 0
40283- 0 0 1 0 0 1 0 0 1 0 0 0
40284- 0 0 0 0 0 0 0 0 0 0 0 0
40285- 0 0 0 0 0 0 0 0 0 0 0 0
40286- 0 0 0 0 0 0 0 0 0 0 0 0
40287- 0 0 0 0 0 0 0 0 0 0 0 0
40288- 0 0 0 0 0 0 0 0 0 14 14 14
40289- 42 42 42 86 86 86 6 6 6 116 116 116
40290-106 106 106 6 6 6 70 70 70 149 149 149
40291-128 128 128 18 18 18 38 38 38 54 54 54
40292-221 221 221 106 106 106 2 2 6 14 14 14
40293- 46 46 46 190 190 190 198 198 198 2 2 6
40294- 2 2 6 2 2 6 2 2 6 2 2 6
40295- 74 74 74 62 62 62 22 22 22 6 6 6
40296- 0 0 0 0 0 0 0 0 0 0 0 0
40297- 0 0 0 0 0 0 0 0 0 0 0 0
40298- 0 0 0 0 0 0 0 0 0 0 0 0
40299- 0 0 0 0 0 0 0 0 0 0 0 0
40300- 0 0 0 0 0 0 0 0 0 0 0 0
40301- 0 0 0 0 0 0 0 0 0 0 0 0
40302- 0 0 0 0 0 0 0 0 1 0 0 0
40303- 0 0 1 0 0 0 0 0 1 0 0 0
40304- 0 0 0 0 0 0 0 0 0 0 0 0
40305- 0 0 0 0 0 0 0 0 0 0 0 0
40306- 0 0 0 0 0 0 0 0 0 0 0 0
40307- 0 0 0 0 0 0 0 0 0 0 0 0
40308- 0 0 0 0 0 0 0 0 0 14 14 14
40309- 42 42 42 94 94 94 14 14 14 101 101 101
40310-128 128 128 2 2 6 18 18 18 116 116 116
40311-118 98 46 121 92 8 121 92 8 98 78 10
40312-162 162 162 106 106 106 2 2 6 2 2 6
40313- 2 2 6 195 195 195 195 195 195 6 6 6
40314- 2 2 6 2 2 6 2 2 6 2 2 6
40315- 74 74 74 62 62 62 22 22 22 6 6 6
40316- 0 0 0 0 0 0 0 0 0 0 0 0
40317- 0 0 0 0 0 0 0 0 0 0 0 0
40318- 0 0 0 0 0 0 0 0 0 0 0 0
40319- 0 0 0 0 0 0 0 0 0 0 0 0
40320- 0 0 0 0 0 0 0 0 0 0 0 0
40321- 0 0 0 0 0 0 0 0 0 0 0 0
40322- 0 0 0 0 0 0 0 0 1 0 0 1
40323- 0 0 1 0 0 0 0 0 1 0 0 0
40324- 0 0 0 0 0 0 0 0 0 0 0 0
40325- 0 0 0 0 0 0 0 0 0 0 0 0
40326- 0 0 0 0 0 0 0 0 0 0 0 0
40327- 0 0 0 0 0 0 0 0 0 0 0 0
40328- 0 0 0 0 0 0 0 0 0 10 10 10
40329- 38 38 38 90 90 90 14 14 14 58 58 58
40330-210 210 210 26 26 26 54 38 6 154 114 10
40331-226 170 11 236 186 11 225 175 15 184 144 12
40332-215 174 15 175 146 61 37 26 9 2 2 6
40333- 70 70 70 246 246 246 138 138 138 2 2 6
40334- 2 2 6 2 2 6 2 2 6 2 2 6
40335- 70 70 70 66 66 66 26 26 26 6 6 6
40336- 0 0 0 0 0 0 0 0 0 0 0 0
40337- 0 0 0 0 0 0 0 0 0 0 0 0
40338- 0 0 0 0 0 0 0 0 0 0 0 0
40339- 0 0 0 0 0 0 0 0 0 0 0 0
40340- 0 0 0 0 0 0 0 0 0 0 0 0
40341- 0 0 0 0 0 0 0 0 0 0 0 0
40342- 0 0 0 0 0 0 0 0 0 0 0 0
40343- 0 0 0 0 0 0 0 0 0 0 0 0
40344- 0 0 0 0 0 0 0 0 0 0 0 0
40345- 0 0 0 0 0 0 0 0 0 0 0 0
40346- 0 0 0 0 0 0 0 0 0 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 10 10 10
40349- 38 38 38 86 86 86 14 14 14 10 10 10
40350-195 195 195 188 164 115 192 133 9 225 175 15
40351-239 182 13 234 190 10 232 195 16 232 200 30
40352-245 207 45 241 208 19 232 195 16 184 144 12
40353-218 194 134 211 206 186 42 42 42 2 2 6
40354- 2 2 6 2 2 6 2 2 6 2 2 6
40355- 50 50 50 74 74 74 30 30 30 6 6 6
40356- 0 0 0 0 0 0 0 0 0 0 0 0
40357- 0 0 0 0 0 0 0 0 0 0 0 0
40358- 0 0 0 0 0 0 0 0 0 0 0 0
40359- 0 0 0 0 0 0 0 0 0 0 0 0
40360- 0 0 0 0 0 0 0 0 0 0 0 0
40361- 0 0 0 0 0 0 0 0 0 0 0 0
40362- 0 0 0 0 0 0 0 0 0 0 0 0
40363- 0 0 0 0 0 0 0 0 0 0 0 0
40364- 0 0 0 0 0 0 0 0 0 0 0 0
40365- 0 0 0 0 0 0 0 0 0 0 0 0
40366- 0 0 0 0 0 0 0 0 0 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 10 10 10
40369- 34 34 34 86 86 86 14 14 14 2 2 6
40370-121 87 25 192 133 9 219 162 10 239 182 13
40371-236 186 11 232 195 16 241 208 19 244 214 54
40372-246 218 60 246 218 38 246 215 20 241 208 19
40373-241 208 19 226 184 13 121 87 25 2 2 6
40374- 2 2 6 2 2 6 2 2 6 2 2 6
40375- 50 50 50 82 82 82 34 34 34 10 10 10
40376- 0 0 0 0 0 0 0 0 0 0 0 0
40377- 0 0 0 0 0 0 0 0 0 0 0 0
40378- 0 0 0 0 0 0 0 0 0 0 0 0
40379- 0 0 0 0 0 0 0 0 0 0 0 0
40380- 0 0 0 0 0 0 0 0 0 0 0 0
40381- 0 0 0 0 0 0 0 0 0 0 0 0
40382- 0 0 0 0 0 0 0 0 0 0 0 0
40383- 0 0 0 0 0 0 0 0 0 0 0 0
40384- 0 0 0 0 0 0 0 0 0 0 0 0
40385- 0 0 0 0 0 0 0 0 0 0 0 0
40386- 0 0 0 0 0 0 0 0 0 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 10 10 10
40389- 34 34 34 82 82 82 30 30 30 61 42 6
40390-180 123 7 206 145 10 230 174 11 239 182 13
40391-234 190 10 238 202 15 241 208 19 246 218 74
40392-246 218 38 246 215 20 246 215 20 246 215 20
40393-226 184 13 215 174 15 184 144 12 6 6 6
40394- 2 2 6 2 2 6 2 2 6 2 2 6
40395- 26 26 26 94 94 94 42 42 42 14 14 14
40396- 0 0 0 0 0 0 0 0 0 0 0 0
40397- 0 0 0 0 0 0 0 0 0 0 0 0
40398- 0 0 0 0 0 0 0 0 0 0 0 0
40399- 0 0 0 0 0 0 0 0 0 0 0 0
40400- 0 0 0 0 0 0 0 0 0 0 0 0
40401- 0 0 0 0 0 0 0 0 0 0 0 0
40402- 0 0 0 0 0 0 0 0 0 0 0 0
40403- 0 0 0 0 0 0 0 0 0 0 0 0
40404- 0 0 0 0 0 0 0 0 0 0 0 0
40405- 0 0 0 0 0 0 0 0 0 0 0 0
40406- 0 0 0 0 0 0 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 10 10 10
40409- 30 30 30 78 78 78 50 50 50 104 69 6
40410-192 133 9 216 158 10 236 178 12 236 186 11
40411-232 195 16 241 208 19 244 214 54 245 215 43
40412-246 215 20 246 215 20 241 208 19 198 155 10
40413-200 144 11 216 158 10 156 118 10 2 2 6
40414- 2 2 6 2 2 6 2 2 6 2 2 6
40415- 6 6 6 90 90 90 54 54 54 18 18 18
40416- 6 6 6 0 0 0 0 0 0 0 0 0
40417- 0 0 0 0 0 0 0 0 0 0 0 0
40418- 0 0 0 0 0 0 0 0 0 0 0 0
40419- 0 0 0 0 0 0 0 0 0 0 0 0
40420- 0 0 0 0 0 0 0 0 0 0 0 0
40421- 0 0 0 0 0 0 0 0 0 0 0 0
40422- 0 0 0 0 0 0 0 0 0 0 0 0
40423- 0 0 0 0 0 0 0 0 0 0 0 0
40424- 0 0 0 0 0 0 0 0 0 0 0 0
40425- 0 0 0 0 0 0 0 0 0 0 0 0
40426- 0 0 0 0 0 0 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 10 10 10
40429- 30 30 30 78 78 78 46 46 46 22 22 22
40430-137 92 6 210 162 10 239 182 13 238 190 10
40431-238 202 15 241 208 19 246 215 20 246 215 20
40432-241 208 19 203 166 17 185 133 11 210 150 10
40433-216 158 10 210 150 10 102 78 10 2 2 6
40434- 6 6 6 54 54 54 14 14 14 2 2 6
40435- 2 2 6 62 62 62 74 74 74 30 30 30
40436- 10 10 10 0 0 0 0 0 0 0 0 0
40437- 0 0 0 0 0 0 0 0 0 0 0 0
40438- 0 0 0 0 0 0 0 0 0 0 0 0
40439- 0 0 0 0 0 0 0 0 0 0 0 0
40440- 0 0 0 0 0 0 0 0 0 0 0 0
40441- 0 0 0 0 0 0 0 0 0 0 0 0
40442- 0 0 0 0 0 0 0 0 0 0 0 0
40443- 0 0 0 0 0 0 0 0 0 0 0 0
40444- 0 0 0 0 0 0 0 0 0 0 0 0
40445- 0 0 0 0 0 0 0 0 0 0 0 0
40446- 0 0 0 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 10 10 10
40449- 34 34 34 78 78 78 50 50 50 6 6 6
40450- 94 70 30 139 102 15 190 146 13 226 184 13
40451-232 200 30 232 195 16 215 174 15 190 146 13
40452-168 122 10 192 133 9 210 150 10 213 154 11
40453-202 150 34 182 157 106 101 98 89 2 2 6
40454- 2 2 6 78 78 78 116 116 116 58 58 58
40455- 2 2 6 22 22 22 90 90 90 46 46 46
40456- 18 18 18 6 6 6 0 0 0 0 0 0
40457- 0 0 0 0 0 0 0 0 0 0 0 0
40458- 0 0 0 0 0 0 0 0 0 0 0 0
40459- 0 0 0 0 0 0 0 0 0 0 0 0
40460- 0 0 0 0 0 0 0 0 0 0 0 0
40461- 0 0 0 0 0 0 0 0 0 0 0 0
40462- 0 0 0 0 0 0 0 0 0 0 0 0
40463- 0 0 0 0 0 0 0 0 0 0 0 0
40464- 0 0 0 0 0 0 0 0 0 0 0 0
40465- 0 0 0 0 0 0 0 0 0 0 0 0
40466- 0 0 0 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 10 10 10
40469- 38 38 38 86 86 86 50 50 50 6 6 6
40470-128 128 128 174 154 114 156 107 11 168 122 10
40471-198 155 10 184 144 12 197 138 11 200 144 11
40472-206 145 10 206 145 10 197 138 11 188 164 115
40473-195 195 195 198 198 198 174 174 174 14 14 14
40474- 2 2 6 22 22 22 116 116 116 116 116 116
40475- 22 22 22 2 2 6 74 74 74 70 70 70
40476- 30 30 30 10 10 10 0 0 0 0 0 0
40477- 0 0 0 0 0 0 0 0 0 0 0 0
40478- 0 0 0 0 0 0 0 0 0 0 0 0
40479- 0 0 0 0 0 0 0 0 0 0 0 0
40480- 0 0 0 0 0 0 0 0 0 0 0 0
40481- 0 0 0 0 0 0 0 0 0 0 0 0
40482- 0 0 0 0 0 0 0 0 0 0 0 0
40483- 0 0 0 0 0 0 0 0 0 0 0 0
40484- 0 0 0 0 0 0 0 0 0 0 0 0
40485- 0 0 0 0 0 0 0 0 0 0 0 0
40486- 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 6 6 6 18 18 18
40489- 50 50 50 101 101 101 26 26 26 10 10 10
40490-138 138 138 190 190 190 174 154 114 156 107 11
40491-197 138 11 200 144 11 197 138 11 192 133 9
40492-180 123 7 190 142 34 190 178 144 187 187 187
40493-202 202 202 221 221 221 214 214 214 66 66 66
40494- 2 2 6 2 2 6 50 50 50 62 62 62
40495- 6 6 6 2 2 6 10 10 10 90 90 90
40496- 50 50 50 18 18 18 6 6 6 0 0 0
40497- 0 0 0 0 0 0 0 0 0 0 0 0
40498- 0 0 0 0 0 0 0 0 0 0 0 0
40499- 0 0 0 0 0 0 0 0 0 0 0 0
40500- 0 0 0 0 0 0 0 0 0 0 0 0
40501- 0 0 0 0 0 0 0 0 0 0 0 0
40502- 0 0 0 0 0 0 0 0 0 0 0 0
40503- 0 0 0 0 0 0 0 0 0 0 0 0
40504- 0 0 0 0 0 0 0 0 0 0 0 0
40505- 0 0 0 0 0 0 0 0 0 0 0 0
40506- 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 10 10 10 34 34 34
40509- 74 74 74 74 74 74 2 2 6 6 6 6
40510-144 144 144 198 198 198 190 190 190 178 166 146
40511-154 121 60 156 107 11 156 107 11 168 124 44
40512-174 154 114 187 187 187 190 190 190 210 210 210
40513-246 246 246 253 253 253 253 253 253 182 182 182
40514- 6 6 6 2 2 6 2 2 6 2 2 6
40515- 2 2 6 2 2 6 2 2 6 62 62 62
40516- 74 74 74 34 34 34 14 14 14 0 0 0
40517- 0 0 0 0 0 0 0 0 0 0 0 0
40518- 0 0 0 0 0 0 0 0 0 0 0 0
40519- 0 0 0 0 0 0 0 0 0 0 0 0
40520- 0 0 0 0 0 0 0 0 0 0 0 0
40521- 0 0 0 0 0 0 0 0 0 0 0 0
40522- 0 0 0 0 0 0 0 0 0 0 0 0
40523- 0 0 0 0 0 0 0 0 0 0 0 0
40524- 0 0 0 0 0 0 0 0 0 0 0 0
40525- 0 0 0 0 0 0 0 0 0 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 10 10 10 22 22 22 54 54 54
40529- 94 94 94 18 18 18 2 2 6 46 46 46
40530-234 234 234 221 221 221 190 190 190 190 190 190
40531-190 190 190 187 187 187 187 187 187 190 190 190
40532-190 190 190 195 195 195 214 214 214 242 242 242
40533-253 253 253 253 253 253 253 253 253 253 253 253
40534- 82 82 82 2 2 6 2 2 6 2 2 6
40535- 2 2 6 2 2 6 2 2 6 14 14 14
40536- 86 86 86 54 54 54 22 22 22 6 6 6
40537- 0 0 0 0 0 0 0 0 0 0 0 0
40538- 0 0 0 0 0 0 0 0 0 0 0 0
40539- 0 0 0 0 0 0 0 0 0 0 0 0
40540- 0 0 0 0 0 0 0 0 0 0 0 0
40541- 0 0 0 0 0 0 0 0 0 0 0 0
40542- 0 0 0 0 0 0 0 0 0 0 0 0
40543- 0 0 0 0 0 0 0 0 0 0 0 0
40544- 0 0 0 0 0 0 0 0 0 0 0 0
40545- 0 0 0 0 0 0 0 0 0 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- 6 6 6 18 18 18 46 46 46 90 90 90
40549- 46 46 46 18 18 18 6 6 6 182 182 182
40550-253 253 253 246 246 246 206 206 206 190 190 190
40551-190 190 190 190 190 190 190 190 190 190 190 190
40552-206 206 206 231 231 231 250 250 250 253 253 253
40553-253 253 253 253 253 253 253 253 253 253 253 253
40554-202 202 202 14 14 14 2 2 6 2 2 6
40555- 2 2 6 2 2 6 2 2 6 2 2 6
40556- 42 42 42 86 86 86 42 42 42 18 18 18
40557- 6 6 6 0 0 0 0 0 0 0 0 0
40558- 0 0 0 0 0 0 0 0 0 0 0 0
40559- 0 0 0 0 0 0 0 0 0 0 0 0
40560- 0 0 0 0 0 0 0 0 0 0 0 0
40561- 0 0 0 0 0 0 0 0 0 0 0 0
40562- 0 0 0 0 0 0 0 0 0 0 0 0
40563- 0 0 0 0 0 0 0 0 0 0 0 0
40564- 0 0 0 0 0 0 0 0 0 0 0 0
40565- 0 0 0 0 0 0 0 0 0 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 6 6 6
40568- 14 14 14 38 38 38 74 74 74 66 66 66
40569- 2 2 6 6 6 6 90 90 90 250 250 250
40570-253 253 253 253 253 253 238 238 238 198 198 198
40571-190 190 190 190 190 190 195 195 195 221 221 221
40572-246 246 246 253 253 253 253 253 253 253 253 253
40573-253 253 253 253 253 253 253 253 253 253 253 253
40574-253 253 253 82 82 82 2 2 6 2 2 6
40575- 2 2 6 2 2 6 2 2 6 2 2 6
40576- 2 2 6 78 78 78 70 70 70 34 34 34
40577- 14 14 14 6 6 6 0 0 0 0 0 0
40578- 0 0 0 0 0 0 0 0 0 0 0 0
40579- 0 0 0 0 0 0 0 0 0 0 0 0
40580- 0 0 0 0 0 0 0 0 0 0 0 0
40581- 0 0 0 0 0 0 0 0 0 0 0 0
40582- 0 0 0 0 0 0 0 0 0 0 0 0
40583- 0 0 0 0 0 0 0 0 0 0 0 0
40584- 0 0 0 0 0 0 0 0 0 0 0 0
40585- 0 0 0 0 0 0 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 14 14 14
40588- 34 34 34 66 66 66 78 78 78 6 6 6
40589- 2 2 6 18 18 18 218 218 218 253 253 253
40590-253 253 253 253 253 253 253 253 253 246 246 246
40591-226 226 226 231 231 231 246 246 246 253 253 253
40592-253 253 253 253 253 253 253 253 253 253 253 253
40593-253 253 253 253 253 253 253 253 253 253 253 253
40594-253 253 253 178 178 178 2 2 6 2 2 6
40595- 2 2 6 2 2 6 2 2 6 2 2 6
40596- 2 2 6 18 18 18 90 90 90 62 62 62
40597- 30 30 30 10 10 10 0 0 0 0 0 0
40598- 0 0 0 0 0 0 0 0 0 0 0 0
40599- 0 0 0 0 0 0 0 0 0 0 0 0
40600- 0 0 0 0 0 0 0 0 0 0 0 0
40601- 0 0 0 0 0 0 0 0 0 0 0 0
40602- 0 0 0 0 0 0 0 0 0 0 0 0
40603- 0 0 0 0 0 0 0 0 0 0 0 0
40604- 0 0 0 0 0 0 0 0 0 0 0 0
40605- 0 0 0 0 0 0 0 0 0 0 0 0
40606- 0 0 0 0 0 0 0 0 0 0 0 0
40607- 0 0 0 0 0 0 10 10 10 26 26 26
40608- 58 58 58 90 90 90 18 18 18 2 2 6
40609- 2 2 6 110 110 110 253 253 253 253 253 253
40610-253 253 253 253 253 253 253 253 253 253 253 253
40611-250 250 250 253 253 253 253 253 253 253 253 253
40612-253 253 253 253 253 253 253 253 253 253 253 253
40613-253 253 253 253 253 253 253 253 253 253 253 253
40614-253 253 253 231 231 231 18 18 18 2 2 6
40615- 2 2 6 2 2 6 2 2 6 2 2 6
40616- 2 2 6 2 2 6 18 18 18 94 94 94
40617- 54 54 54 26 26 26 10 10 10 0 0 0
40618- 0 0 0 0 0 0 0 0 0 0 0 0
40619- 0 0 0 0 0 0 0 0 0 0 0 0
40620- 0 0 0 0 0 0 0 0 0 0 0 0
40621- 0 0 0 0 0 0 0 0 0 0 0 0
40622- 0 0 0 0 0 0 0 0 0 0 0 0
40623- 0 0 0 0 0 0 0 0 0 0 0 0
40624- 0 0 0 0 0 0 0 0 0 0 0 0
40625- 0 0 0 0 0 0 0 0 0 0 0 0
40626- 0 0 0 0 0 0 0 0 0 0 0 0
40627- 0 0 0 6 6 6 22 22 22 50 50 50
40628- 90 90 90 26 26 26 2 2 6 2 2 6
40629- 14 14 14 195 195 195 250 250 250 253 253 253
40630-253 253 253 253 253 253 253 253 253 253 253 253
40631-253 253 253 253 253 253 253 253 253 253 253 253
40632-253 253 253 253 253 253 253 253 253 253 253 253
40633-253 253 253 253 253 253 253 253 253 253 253 253
40634-250 250 250 242 242 242 54 54 54 2 2 6
40635- 2 2 6 2 2 6 2 2 6 2 2 6
40636- 2 2 6 2 2 6 2 2 6 38 38 38
40637- 86 86 86 50 50 50 22 22 22 6 6 6
40638- 0 0 0 0 0 0 0 0 0 0 0 0
40639- 0 0 0 0 0 0 0 0 0 0 0 0
40640- 0 0 0 0 0 0 0 0 0 0 0 0
40641- 0 0 0 0 0 0 0 0 0 0 0 0
40642- 0 0 0 0 0 0 0 0 0 0 0 0
40643- 0 0 0 0 0 0 0 0 0 0 0 0
40644- 0 0 0 0 0 0 0 0 0 0 0 0
40645- 0 0 0 0 0 0 0 0 0 0 0 0
40646- 0 0 0 0 0 0 0 0 0 0 0 0
40647- 6 6 6 14 14 14 38 38 38 82 82 82
40648- 34 34 34 2 2 6 2 2 6 2 2 6
40649- 42 42 42 195 195 195 246 246 246 253 253 253
40650-253 253 253 253 253 253 253 253 253 250 250 250
40651-242 242 242 242 242 242 250 250 250 253 253 253
40652-253 253 253 253 253 253 253 253 253 253 253 253
40653-253 253 253 250 250 250 246 246 246 238 238 238
40654-226 226 226 231 231 231 101 101 101 6 6 6
40655- 2 2 6 2 2 6 2 2 6 2 2 6
40656- 2 2 6 2 2 6 2 2 6 2 2 6
40657- 38 38 38 82 82 82 42 42 42 14 14 14
40658- 6 6 6 0 0 0 0 0 0 0 0 0
40659- 0 0 0 0 0 0 0 0 0 0 0 0
40660- 0 0 0 0 0 0 0 0 0 0 0 0
40661- 0 0 0 0 0 0 0 0 0 0 0 0
40662- 0 0 0 0 0 0 0 0 0 0 0 0
40663- 0 0 0 0 0 0 0 0 0 0 0 0
40664- 0 0 0 0 0 0 0 0 0 0 0 0
40665- 0 0 0 0 0 0 0 0 0 0 0 0
40666- 0 0 0 0 0 0 0 0 0 0 0 0
40667- 10 10 10 26 26 26 62 62 62 66 66 66
40668- 2 2 6 2 2 6 2 2 6 6 6 6
40669- 70 70 70 170 170 170 206 206 206 234 234 234
40670-246 246 246 250 250 250 250 250 250 238 238 238
40671-226 226 226 231 231 231 238 238 238 250 250 250
40672-250 250 250 250 250 250 246 246 246 231 231 231
40673-214 214 214 206 206 206 202 202 202 202 202 202
40674-198 198 198 202 202 202 182 182 182 18 18 18
40675- 2 2 6 2 2 6 2 2 6 2 2 6
40676- 2 2 6 2 2 6 2 2 6 2 2 6
40677- 2 2 6 62 62 62 66 66 66 30 30 30
40678- 10 10 10 0 0 0 0 0 0 0 0 0
40679- 0 0 0 0 0 0 0 0 0 0 0 0
40680- 0 0 0 0 0 0 0 0 0 0 0 0
40681- 0 0 0 0 0 0 0 0 0 0 0 0
40682- 0 0 0 0 0 0 0 0 0 0 0 0
40683- 0 0 0 0 0 0 0 0 0 0 0 0
40684- 0 0 0 0 0 0 0 0 0 0 0 0
40685- 0 0 0 0 0 0 0 0 0 0 0 0
40686- 0 0 0 0 0 0 0 0 0 0 0 0
40687- 14 14 14 42 42 42 82 82 82 18 18 18
40688- 2 2 6 2 2 6 2 2 6 10 10 10
40689- 94 94 94 182 182 182 218 218 218 242 242 242
40690-250 250 250 253 253 253 253 253 253 250 250 250
40691-234 234 234 253 253 253 253 253 253 253 253 253
40692-253 253 253 253 253 253 253 253 253 246 246 246
40693-238 238 238 226 226 226 210 210 210 202 202 202
40694-195 195 195 195 195 195 210 210 210 158 158 158
40695- 6 6 6 14 14 14 50 50 50 14 14 14
40696- 2 2 6 2 2 6 2 2 6 2 2 6
40697- 2 2 6 6 6 6 86 86 86 46 46 46
40698- 18 18 18 6 6 6 0 0 0 0 0 0
40699- 0 0 0 0 0 0 0 0 0 0 0 0
40700- 0 0 0 0 0 0 0 0 0 0 0 0
40701- 0 0 0 0 0 0 0 0 0 0 0 0
40702- 0 0 0 0 0 0 0 0 0 0 0 0
40703- 0 0 0 0 0 0 0 0 0 0 0 0
40704- 0 0 0 0 0 0 0 0 0 0 0 0
40705- 0 0 0 0 0 0 0 0 0 0 0 0
40706- 0 0 0 0 0 0 0 0 0 6 6 6
40707- 22 22 22 54 54 54 70 70 70 2 2 6
40708- 2 2 6 10 10 10 2 2 6 22 22 22
40709-166 166 166 231 231 231 250 250 250 253 253 253
40710-253 253 253 253 253 253 253 253 253 250 250 250
40711-242 242 242 253 253 253 253 253 253 253 253 253
40712-253 253 253 253 253 253 253 253 253 253 253 253
40713-253 253 253 253 253 253 253 253 253 246 246 246
40714-231 231 231 206 206 206 198 198 198 226 226 226
40715- 94 94 94 2 2 6 6 6 6 38 38 38
40716- 30 30 30 2 2 6 2 2 6 2 2 6
40717- 2 2 6 2 2 6 62 62 62 66 66 66
40718- 26 26 26 10 10 10 0 0 0 0 0 0
40719- 0 0 0 0 0 0 0 0 0 0 0 0
40720- 0 0 0 0 0 0 0 0 0 0 0 0
40721- 0 0 0 0 0 0 0 0 0 0 0 0
40722- 0 0 0 0 0 0 0 0 0 0 0 0
40723- 0 0 0 0 0 0 0 0 0 0 0 0
40724- 0 0 0 0 0 0 0 0 0 0 0 0
40725- 0 0 0 0 0 0 0 0 0 0 0 0
40726- 0 0 0 0 0 0 0 0 0 10 10 10
40727- 30 30 30 74 74 74 50 50 50 2 2 6
40728- 26 26 26 26 26 26 2 2 6 106 106 106
40729-238 238 238 253 253 253 253 253 253 253 253 253
40730-253 253 253 253 253 253 253 253 253 253 253 253
40731-253 253 253 253 253 253 253 253 253 253 253 253
40732-253 253 253 253 253 253 253 253 253 253 253 253
40733-253 253 253 253 253 253 253 253 253 253 253 253
40734-253 253 253 246 246 246 218 218 218 202 202 202
40735-210 210 210 14 14 14 2 2 6 2 2 6
40736- 30 30 30 22 22 22 2 2 6 2 2 6
40737- 2 2 6 2 2 6 18 18 18 86 86 86
40738- 42 42 42 14 14 14 0 0 0 0 0 0
40739- 0 0 0 0 0 0 0 0 0 0 0 0
40740- 0 0 0 0 0 0 0 0 0 0 0 0
40741- 0 0 0 0 0 0 0 0 0 0 0 0
40742- 0 0 0 0 0 0 0 0 0 0 0 0
40743- 0 0 0 0 0 0 0 0 0 0 0 0
40744- 0 0 0 0 0 0 0 0 0 0 0 0
40745- 0 0 0 0 0 0 0 0 0 0 0 0
40746- 0 0 0 0 0 0 0 0 0 14 14 14
40747- 42 42 42 90 90 90 22 22 22 2 2 6
40748- 42 42 42 2 2 6 18 18 18 218 218 218
40749-253 253 253 253 253 253 253 253 253 253 253 253
40750-253 253 253 253 253 253 253 253 253 253 253 253
40751-253 253 253 253 253 253 253 253 253 253 253 253
40752-253 253 253 253 253 253 253 253 253 253 253 253
40753-253 253 253 253 253 253 253 253 253 253 253 253
40754-253 253 253 253 253 253 250 250 250 221 221 221
40755-218 218 218 101 101 101 2 2 6 14 14 14
40756- 18 18 18 38 38 38 10 10 10 2 2 6
40757- 2 2 6 2 2 6 2 2 6 78 78 78
40758- 58 58 58 22 22 22 6 6 6 0 0 0
40759- 0 0 0 0 0 0 0 0 0 0 0 0
40760- 0 0 0 0 0 0 0 0 0 0 0 0
40761- 0 0 0 0 0 0 0 0 0 0 0 0
40762- 0 0 0 0 0 0 0 0 0 0 0 0
40763- 0 0 0 0 0 0 0 0 0 0 0 0
40764- 0 0 0 0 0 0 0 0 0 0 0 0
40765- 0 0 0 0 0 0 0 0 0 0 0 0
40766- 0 0 0 0 0 0 6 6 6 18 18 18
40767- 54 54 54 82 82 82 2 2 6 26 26 26
40768- 22 22 22 2 2 6 123 123 123 253 253 253
40769-253 253 253 253 253 253 253 253 253 253 253 253
40770-253 253 253 253 253 253 253 253 253 253 253 253
40771-253 253 253 253 253 253 253 253 253 253 253 253
40772-253 253 253 253 253 253 253 253 253 253 253 253
40773-253 253 253 253 253 253 253 253 253 253 253 253
40774-253 253 253 253 253 253 253 253 253 250 250 250
40775-238 238 238 198 198 198 6 6 6 38 38 38
40776- 58 58 58 26 26 26 38 38 38 2 2 6
40777- 2 2 6 2 2 6 2 2 6 46 46 46
40778- 78 78 78 30 30 30 10 10 10 0 0 0
40779- 0 0 0 0 0 0 0 0 0 0 0 0
40780- 0 0 0 0 0 0 0 0 0 0 0 0
40781- 0 0 0 0 0 0 0 0 0 0 0 0
40782- 0 0 0 0 0 0 0 0 0 0 0 0
40783- 0 0 0 0 0 0 0 0 0 0 0 0
40784- 0 0 0 0 0 0 0 0 0 0 0 0
40785- 0 0 0 0 0 0 0 0 0 0 0 0
40786- 0 0 0 0 0 0 10 10 10 30 30 30
40787- 74 74 74 58 58 58 2 2 6 42 42 42
40788- 2 2 6 22 22 22 231 231 231 253 253 253
40789-253 253 253 253 253 253 253 253 253 253 253 253
40790-253 253 253 253 253 253 253 253 253 250 250 250
40791-253 253 253 253 253 253 253 253 253 253 253 253
40792-253 253 253 253 253 253 253 253 253 253 253 253
40793-253 253 253 253 253 253 253 253 253 253 253 253
40794-253 253 253 253 253 253 253 253 253 253 253 253
40795-253 253 253 246 246 246 46 46 46 38 38 38
40796- 42 42 42 14 14 14 38 38 38 14 14 14
40797- 2 2 6 2 2 6 2 2 6 6 6 6
40798- 86 86 86 46 46 46 14 14 14 0 0 0
40799- 0 0 0 0 0 0 0 0 0 0 0 0
40800- 0 0 0 0 0 0 0 0 0 0 0 0
40801- 0 0 0 0 0 0 0 0 0 0 0 0
40802- 0 0 0 0 0 0 0 0 0 0 0 0
40803- 0 0 0 0 0 0 0 0 0 0 0 0
40804- 0 0 0 0 0 0 0 0 0 0 0 0
40805- 0 0 0 0 0 0 0 0 0 0 0 0
40806- 0 0 0 6 6 6 14 14 14 42 42 42
40807- 90 90 90 18 18 18 18 18 18 26 26 26
40808- 2 2 6 116 116 116 253 253 253 253 253 253
40809-253 253 253 253 253 253 253 253 253 253 253 253
40810-253 253 253 253 253 253 250 250 250 238 238 238
40811-253 253 253 253 253 253 253 253 253 253 253 253
40812-253 253 253 253 253 253 253 253 253 253 253 253
40813-253 253 253 253 253 253 253 253 253 253 253 253
40814-253 253 253 253 253 253 253 253 253 253 253 253
40815-253 253 253 253 253 253 94 94 94 6 6 6
40816- 2 2 6 2 2 6 10 10 10 34 34 34
40817- 2 2 6 2 2 6 2 2 6 2 2 6
40818- 74 74 74 58 58 58 22 22 22 6 6 6
40819- 0 0 0 0 0 0 0 0 0 0 0 0
40820- 0 0 0 0 0 0 0 0 0 0 0 0
40821- 0 0 0 0 0 0 0 0 0 0 0 0
40822- 0 0 0 0 0 0 0 0 0 0 0 0
40823- 0 0 0 0 0 0 0 0 0 0 0 0
40824- 0 0 0 0 0 0 0 0 0 0 0 0
40825- 0 0 0 0 0 0 0 0 0 0 0 0
40826- 0 0 0 10 10 10 26 26 26 66 66 66
40827- 82 82 82 2 2 6 38 38 38 6 6 6
40828- 14 14 14 210 210 210 253 253 253 253 253 253
40829-253 253 253 253 253 253 253 253 253 253 253 253
40830-253 253 253 253 253 253 246 246 246 242 242 242
40831-253 253 253 253 253 253 253 253 253 253 253 253
40832-253 253 253 253 253 253 253 253 253 253 253 253
40833-253 253 253 253 253 253 253 253 253 253 253 253
40834-253 253 253 253 253 253 253 253 253 253 253 253
40835-253 253 253 253 253 253 144 144 144 2 2 6
40836- 2 2 6 2 2 6 2 2 6 46 46 46
40837- 2 2 6 2 2 6 2 2 6 2 2 6
40838- 42 42 42 74 74 74 30 30 30 10 10 10
40839- 0 0 0 0 0 0 0 0 0 0 0 0
40840- 0 0 0 0 0 0 0 0 0 0 0 0
40841- 0 0 0 0 0 0 0 0 0 0 0 0
40842- 0 0 0 0 0 0 0 0 0 0 0 0
40843- 0 0 0 0 0 0 0 0 0 0 0 0
40844- 0 0 0 0 0 0 0 0 0 0 0 0
40845- 0 0 0 0 0 0 0 0 0 0 0 0
40846- 6 6 6 14 14 14 42 42 42 90 90 90
40847- 26 26 26 6 6 6 42 42 42 2 2 6
40848- 74 74 74 250 250 250 253 253 253 253 253 253
40849-253 253 253 253 253 253 253 253 253 253 253 253
40850-253 253 253 253 253 253 242 242 242 242 242 242
40851-253 253 253 253 253 253 253 253 253 253 253 253
40852-253 253 253 253 253 253 253 253 253 253 253 253
40853-253 253 253 253 253 253 253 253 253 253 253 253
40854-253 253 253 253 253 253 253 253 253 253 253 253
40855-253 253 253 253 253 253 182 182 182 2 2 6
40856- 2 2 6 2 2 6 2 2 6 46 46 46
40857- 2 2 6 2 2 6 2 2 6 2 2 6
40858- 10 10 10 86 86 86 38 38 38 10 10 10
40859- 0 0 0 0 0 0 0 0 0 0 0 0
40860- 0 0 0 0 0 0 0 0 0 0 0 0
40861- 0 0 0 0 0 0 0 0 0 0 0 0
40862- 0 0 0 0 0 0 0 0 0 0 0 0
40863- 0 0 0 0 0 0 0 0 0 0 0 0
40864- 0 0 0 0 0 0 0 0 0 0 0 0
40865- 0 0 0 0 0 0 0 0 0 0 0 0
40866- 10 10 10 26 26 26 66 66 66 82 82 82
40867- 2 2 6 22 22 22 18 18 18 2 2 6
40868-149 149 149 253 253 253 253 253 253 253 253 253
40869-253 253 253 253 253 253 253 253 253 253 253 253
40870-253 253 253 253 253 253 234 234 234 242 242 242
40871-253 253 253 253 253 253 253 253 253 253 253 253
40872-253 253 253 253 253 253 253 253 253 253 253 253
40873-253 253 253 253 253 253 253 253 253 253 253 253
40874-253 253 253 253 253 253 253 253 253 253 253 253
40875-253 253 253 253 253 253 206 206 206 2 2 6
40876- 2 2 6 2 2 6 2 2 6 38 38 38
40877- 2 2 6 2 2 6 2 2 6 2 2 6
40878- 6 6 6 86 86 86 46 46 46 14 14 14
40879- 0 0 0 0 0 0 0 0 0 0 0 0
40880- 0 0 0 0 0 0 0 0 0 0 0 0
40881- 0 0 0 0 0 0 0 0 0 0 0 0
40882- 0 0 0 0 0 0 0 0 0 0 0 0
40883- 0 0 0 0 0 0 0 0 0 0 0 0
40884- 0 0 0 0 0 0 0 0 0 0 0 0
40885- 0 0 0 0 0 0 0 0 0 6 6 6
40886- 18 18 18 46 46 46 86 86 86 18 18 18
40887- 2 2 6 34 34 34 10 10 10 6 6 6
40888-210 210 210 253 253 253 253 253 253 253 253 253
40889-253 253 253 253 253 253 253 253 253 253 253 253
40890-253 253 253 253 253 253 234 234 234 242 242 242
40891-253 253 253 253 253 253 253 253 253 253 253 253
40892-253 253 253 253 253 253 253 253 253 253 253 253
40893-253 253 253 253 253 253 253 253 253 253 253 253
40894-253 253 253 253 253 253 253 253 253 253 253 253
40895-253 253 253 253 253 253 221 221 221 6 6 6
40896- 2 2 6 2 2 6 6 6 6 30 30 30
40897- 2 2 6 2 2 6 2 2 6 2 2 6
40898- 2 2 6 82 82 82 54 54 54 18 18 18
40899- 6 6 6 0 0 0 0 0 0 0 0 0
40900- 0 0 0 0 0 0 0 0 0 0 0 0
40901- 0 0 0 0 0 0 0 0 0 0 0 0
40902- 0 0 0 0 0 0 0 0 0 0 0 0
40903- 0 0 0 0 0 0 0 0 0 0 0 0
40904- 0 0 0 0 0 0 0 0 0 0 0 0
40905- 0 0 0 0 0 0 0 0 0 10 10 10
40906- 26 26 26 66 66 66 62 62 62 2 2 6
40907- 2 2 6 38 38 38 10 10 10 26 26 26
40908-238 238 238 253 253 253 253 253 253 253 253 253
40909-253 253 253 253 253 253 253 253 253 253 253 253
40910-253 253 253 253 253 253 231 231 231 238 238 238
40911-253 253 253 253 253 253 253 253 253 253 253 253
40912-253 253 253 253 253 253 253 253 253 253 253 253
40913-253 253 253 253 253 253 253 253 253 253 253 253
40914-253 253 253 253 253 253 253 253 253 253 253 253
40915-253 253 253 253 253 253 231 231 231 6 6 6
40916- 2 2 6 2 2 6 10 10 10 30 30 30
40917- 2 2 6 2 2 6 2 2 6 2 2 6
40918- 2 2 6 66 66 66 58 58 58 22 22 22
40919- 6 6 6 0 0 0 0 0 0 0 0 0
40920- 0 0 0 0 0 0 0 0 0 0 0 0
40921- 0 0 0 0 0 0 0 0 0 0 0 0
40922- 0 0 0 0 0 0 0 0 0 0 0 0
40923- 0 0 0 0 0 0 0 0 0 0 0 0
40924- 0 0 0 0 0 0 0 0 0 0 0 0
40925- 0 0 0 0 0 0 0 0 0 10 10 10
40926- 38 38 38 78 78 78 6 6 6 2 2 6
40927- 2 2 6 46 46 46 14 14 14 42 42 42
40928-246 246 246 253 253 253 253 253 253 253 253 253
40929-253 253 253 253 253 253 253 253 253 253 253 253
40930-253 253 253 253 253 253 231 231 231 242 242 242
40931-253 253 253 253 253 253 253 253 253 253 253 253
40932-253 253 253 253 253 253 253 253 253 253 253 253
40933-253 253 253 253 253 253 253 253 253 253 253 253
40934-253 253 253 253 253 253 253 253 253 253 253 253
40935-253 253 253 253 253 253 234 234 234 10 10 10
40936- 2 2 6 2 2 6 22 22 22 14 14 14
40937- 2 2 6 2 2 6 2 2 6 2 2 6
40938- 2 2 6 66 66 66 62 62 62 22 22 22
40939- 6 6 6 0 0 0 0 0 0 0 0 0
40940- 0 0 0 0 0 0 0 0 0 0 0 0
40941- 0 0 0 0 0 0 0 0 0 0 0 0
40942- 0 0 0 0 0 0 0 0 0 0 0 0
40943- 0 0 0 0 0 0 0 0 0 0 0 0
40944- 0 0 0 0 0 0 0 0 0 0 0 0
40945- 0 0 0 0 0 0 6 6 6 18 18 18
40946- 50 50 50 74 74 74 2 2 6 2 2 6
40947- 14 14 14 70 70 70 34 34 34 62 62 62
40948-250 250 250 253 253 253 253 253 253 253 253 253
40949-253 253 253 253 253 253 253 253 253 253 253 253
40950-253 253 253 253 253 253 231 231 231 246 246 246
40951-253 253 253 253 253 253 253 253 253 253 253 253
40952-253 253 253 253 253 253 253 253 253 253 253 253
40953-253 253 253 253 253 253 253 253 253 253 253 253
40954-253 253 253 253 253 253 253 253 253 253 253 253
40955-253 253 253 253 253 253 234 234 234 14 14 14
40956- 2 2 6 2 2 6 30 30 30 2 2 6
40957- 2 2 6 2 2 6 2 2 6 2 2 6
40958- 2 2 6 66 66 66 62 62 62 22 22 22
40959- 6 6 6 0 0 0 0 0 0 0 0 0
40960- 0 0 0 0 0 0 0 0 0 0 0 0
40961- 0 0 0 0 0 0 0 0 0 0 0 0
40962- 0 0 0 0 0 0 0 0 0 0 0 0
40963- 0 0 0 0 0 0 0 0 0 0 0 0
40964- 0 0 0 0 0 0 0 0 0 0 0 0
40965- 0 0 0 0 0 0 6 6 6 18 18 18
40966- 54 54 54 62 62 62 2 2 6 2 2 6
40967- 2 2 6 30 30 30 46 46 46 70 70 70
40968-250 250 250 253 253 253 253 253 253 253 253 253
40969-253 253 253 253 253 253 253 253 253 253 253 253
40970-253 253 253 253 253 253 231 231 231 246 246 246
40971-253 253 253 253 253 253 253 253 253 253 253 253
40972-253 253 253 253 253 253 253 253 253 253 253 253
40973-253 253 253 253 253 253 253 253 253 253 253 253
40974-253 253 253 253 253 253 253 253 253 253 253 253
40975-253 253 253 253 253 253 226 226 226 10 10 10
40976- 2 2 6 6 6 6 30 30 30 2 2 6
40977- 2 2 6 2 2 6 2 2 6 2 2 6
40978- 2 2 6 66 66 66 58 58 58 22 22 22
40979- 6 6 6 0 0 0 0 0 0 0 0 0
40980- 0 0 0 0 0 0 0 0 0 0 0 0
40981- 0 0 0 0 0 0 0 0 0 0 0 0
40982- 0 0 0 0 0 0 0 0 0 0 0 0
40983- 0 0 0 0 0 0 0 0 0 0 0 0
40984- 0 0 0 0 0 0 0 0 0 0 0 0
40985- 0 0 0 0 0 0 6 6 6 22 22 22
40986- 58 58 58 62 62 62 2 2 6 2 2 6
40987- 2 2 6 2 2 6 30 30 30 78 78 78
40988-250 250 250 253 253 253 253 253 253 253 253 253
40989-253 253 253 253 253 253 253 253 253 253 253 253
40990-253 253 253 253 253 253 231 231 231 246 246 246
40991-253 253 253 253 253 253 253 253 253 253 253 253
40992-253 253 253 253 253 253 253 253 253 253 253 253
40993-253 253 253 253 253 253 253 253 253 253 253 253
40994-253 253 253 253 253 253 253 253 253 253 253 253
40995-253 253 253 253 253 253 206 206 206 2 2 6
40996- 22 22 22 34 34 34 18 14 6 22 22 22
40997- 26 26 26 18 18 18 6 6 6 2 2 6
40998- 2 2 6 82 82 82 54 54 54 18 18 18
40999- 6 6 6 0 0 0 0 0 0 0 0 0
41000- 0 0 0 0 0 0 0 0 0 0 0 0
41001- 0 0 0 0 0 0 0 0 0 0 0 0
41002- 0 0 0 0 0 0 0 0 0 0 0 0
41003- 0 0 0 0 0 0 0 0 0 0 0 0
41004- 0 0 0 0 0 0 0 0 0 0 0 0
41005- 0 0 0 0 0 0 6 6 6 26 26 26
41006- 62 62 62 106 106 106 74 54 14 185 133 11
41007-210 162 10 121 92 8 6 6 6 62 62 62
41008-238 238 238 253 253 253 253 253 253 253 253 253
41009-253 253 253 253 253 253 253 253 253 253 253 253
41010-253 253 253 253 253 253 231 231 231 246 246 246
41011-253 253 253 253 253 253 253 253 253 253 253 253
41012-253 253 253 253 253 253 253 253 253 253 253 253
41013-253 253 253 253 253 253 253 253 253 253 253 253
41014-253 253 253 253 253 253 253 253 253 253 253 253
41015-253 253 253 253 253 253 158 158 158 18 18 18
41016- 14 14 14 2 2 6 2 2 6 2 2 6
41017- 6 6 6 18 18 18 66 66 66 38 38 38
41018- 6 6 6 94 94 94 50 50 50 18 18 18
41019- 6 6 6 0 0 0 0 0 0 0 0 0
41020- 0 0 0 0 0 0 0 0 0 0 0 0
41021- 0 0 0 0 0 0 0 0 0 0 0 0
41022- 0 0 0 0 0 0 0 0 0 0 0 0
41023- 0 0 0 0 0 0 0 0 0 0 0 0
41024- 0 0 0 0 0 0 0 0 0 6 6 6
41025- 10 10 10 10 10 10 18 18 18 38 38 38
41026- 78 78 78 142 134 106 216 158 10 242 186 14
41027-246 190 14 246 190 14 156 118 10 10 10 10
41028- 90 90 90 238 238 238 253 253 253 253 253 253
41029-253 253 253 253 253 253 253 253 253 253 253 253
41030-253 253 253 253 253 253 231 231 231 250 250 250
41031-253 253 253 253 253 253 253 253 253 253 253 253
41032-253 253 253 253 253 253 253 253 253 253 253 253
41033-253 253 253 253 253 253 253 253 253 253 253 253
41034-253 253 253 253 253 253 253 253 253 246 230 190
41035-238 204 91 238 204 91 181 142 44 37 26 9
41036- 2 2 6 2 2 6 2 2 6 2 2 6
41037- 2 2 6 2 2 6 38 38 38 46 46 46
41038- 26 26 26 106 106 106 54 54 54 18 18 18
41039- 6 6 6 0 0 0 0 0 0 0 0 0
41040- 0 0 0 0 0 0 0 0 0 0 0 0
41041- 0 0 0 0 0 0 0 0 0 0 0 0
41042- 0 0 0 0 0 0 0 0 0 0 0 0
41043- 0 0 0 0 0 0 0 0 0 0 0 0
41044- 0 0 0 6 6 6 14 14 14 22 22 22
41045- 30 30 30 38 38 38 50 50 50 70 70 70
41046-106 106 106 190 142 34 226 170 11 242 186 14
41047-246 190 14 246 190 14 246 190 14 154 114 10
41048- 6 6 6 74 74 74 226 226 226 253 253 253
41049-253 253 253 253 253 253 253 253 253 253 253 253
41050-253 253 253 253 253 253 231 231 231 250 250 250
41051-253 253 253 253 253 253 253 253 253 253 253 253
41052-253 253 253 253 253 253 253 253 253 253 253 253
41053-253 253 253 253 253 253 253 253 253 253 253 253
41054-253 253 253 253 253 253 253 253 253 228 184 62
41055-241 196 14 241 208 19 232 195 16 38 30 10
41056- 2 2 6 2 2 6 2 2 6 2 2 6
41057- 2 2 6 6 6 6 30 30 30 26 26 26
41058-203 166 17 154 142 90 66 66 66 26 26 26
41059- 6 6 6 0 0 0 0 0 0 0 0 0
41060- 0 0 0 0 0 0 0 0 0 0 0 0
41061- 0 0 0 0 0 0 0 0 0 0 0 0
41062- 0 0 0 0 0 0 0 0 0 0 0 0
41063- 0 0 0 0 0 0 0 0 0 0 0 0
41064- 6 6 6 18 18 18 38 38 38 58 58 58
41065- 78 78 78 86 86 86 101 101 101 123 123 123
41066-175 146 61 210 150 10 234 174 13 246 186 14
41067-246 190 14 246 190 14 246 190 14 238 190 10
41068-102 78 10 2 2 6 46 46 46 198 198 198
41069-253 253 253 253 253 253 253 253 253 253 253 253
41070-253 253 253 253 253 253 234 234 234 242 242 242
41071-253 253 253 253 253 253 253 253 253 253 253 253
41072-253 253 253 253 253 253 253 253 253 253 253 253
41073-253 253 253 253 253 253 253 253 253 253 253 253
41074-253 253 253 253 253 253 253 253 253 224 178 62
41075-242 186 14 241 196 14 210 166 10 22 18 6
41076- 2 2 6 2 2 6 2 2 6 2 2 6
41077- 2 2 6 2 2 6 6 6 6 121 92 8
41078-238 202 15 232 195 16 82 82 82 34 34 34
41079- 10 10 10 0 0 0 0 0 0 0 0 0
41080- 0 0 0 0 0 0 0 0 0 0 0 0
41081- 0 0 0 0 0 0 0 0 0 0 0 0
41082- 0 0 0 0 0 0 0 0 0 0 0 0
41083- 0 0 0 0 0 0 0 0 0 0 0 0
41084- 14 14 14 38 38 38 70 70 70 154 122 46
41085-190 142 34 200 144 11 197 138 11 197 138 11
41086-213 154 11 226 170 11 242 186 14 246 190 14
41087-246 190 14 246 190 14 246 190 14 246 190 14
41088-225 175 15 46 32 6 2 2 6 22 22 22
41089-158 158 158 250 250 250 253 253 253 253 253 253
41090-253 253 253 253 253 253 253 253 253 253 253 253
41091-253 253 253 253 253 253 253 253 253 253 253 253
41092-253 253 253 253 253 253 253 253 253 253 253 253
41093-253 253 253 253 253 253 253 253 253 253 253 253
41094-253 253 253 250 250 250 242 242 242 224 178 62
41095-239 182 13 236 186 11 213 154 11 46 32 6
41096- 2 2 6 2 2 6 2 2 6 2 2 6
41097- 2 2 6 2 2 6 61 42 6 225 175 15
41098-238 190 10 236 186 11 112 100 78 42 42 42
41099- 14 14 14 0 0 0 0 0 0 0 0 0
41100- 0 0 0 0 0 0 0 0 0 0 0 0
41101- 0 0 0 0 0 0 0 0 0 0 0 0
41102- 0 0 0 0 0 0 0 0 0 0 0 0
41103- 0 0 0 0 0 0 0 0 0 6 6 6
41104- 22 22 22 54 54 54 154 122 46 213 154 11
41105-226 170 11 230 174 11 226 170 11 226 170 11
41106-236 178 12 242 186 14 246 190 14 246 190 14
41107-246 190 14 246 190 14 246 190 14 246 190 14
41108-241 196 14 184 144 12 10 10 10 2 2 6
41109- 6 6 6 116 116 116 242 242 242 253 253 253
41110-253 253 253 253 253 253 253 253 253 253 253 253
41111-253 253 253 253 253 253 253 253 253 253 253 253
41112-253 253 253 253 253 253 253 253 253 253 253 253
41113-253 253 253 253 253 253 253 253 253 253 253 253
41114-253 253 253 231 231 231 198 198 198 214 170 54
41115-236 178 12 236 178 12 210 150 10 137 92 6
41116- 18 14 6 2 2 6 2 2 6 2 2 6
41117- 6 6 6 70 47 6 200 144 11 236 178 12
41118-239 182 13 239 182 13 124 112 88 58 58 58
41119- 22 22 22 6 6 6 0 0 0 0 0 0
41120- 0 0 0 0 0 0 0 0 0 0 0 0
41121- 0 0 0 0 0 0 0 0 0 0 0 0
41122- 0 0 0 0 0 0 0 0 0 0 0 0
41123- 0 0 0 0 0 0 0 0 0 10 10 10
41124- 30 30 30 70 70 70 180 133 36 226 170 11
41125-239 182 13 242 186 14 242 186 14 246 186 14
41126-246 190 14 246 190 14 246 190 14 246 190 14
41127-246 190 14 246 190 14 246 190 14 246 190 14
41128-246 190 14 232 195 16 98 70 6 2 2 6
41129- 2 2 6 2 2 6 66 66 66 221 221 221
41130-253 253 253 253 253 253 253 253 253 253 253 253
41131-253 253 253 253 253 253 253 253 253 253 253 253
41132-253 253 253 253 253 253 253 253 253 253 253 253
41133-253 253 253 253 253 253 253 253 253 253 253 253
41134-253 253 253 206 206 206 198 198 198 214 166 58
41135-230 174 11 230 174 11 216 158 10 192 133 9
41136-163 110 8 116 81 8 102 78 10 116 81 8
41137-167 114 7 197 138 11 226 170 11 239 182 13
41138-242 186 14 242 186 14 162 146 94 78 78 78
41139- 34 34 34 14 14 14 6 6 6 0 0 0
41140- 0 0 0 0 0 0 0 0 0 0 0 0
41141- 0 0 0 0 0 0 0 0 0 0 0 0
41142- 0 0 0 0 0 0 0 0 0 0 0 0
41143- 0 0 0 0 0 0 0 0 0 6 6 6
41144- 30 30 30 78 78 78 190 142 34 226 170 11
41145-239 182 13 246 190 14 246 190 14 246 190 14
41146-246 190 14 246 190 14 246 190 14 246 190 14
41147-246 190 14 246 190 14 246 190 14 246 190 14
41148-246 190 14 241 196 14 203 166 17 22 18 6
41149- 2 2 6 2 2 6 2 2 6 38 38 38
41150-218 218 218 253 253 253 253 253 253 253 253 253
41151-253 253 253 253 253 253 253 253 253 253 253 253
41152-253 253 253 253 253 253 253 253 253 253 253 253
41153-253 253 253 253 253 253 253 253 253 253 253 253
41154-250 250 250 206 206 206 198 198 198 202 162 69
41155-226 170 11 236 178 12 224 166 10 210 150 10
41156-200 144 11 197 138 11 192 133 9 197 138 11
41157-210 150 10 226 170 11 242 186 14 246 190 14
41158-246 190 14 246 186 14 225 175 15 124 112 88
41159- 62 62 62 30 30 30 14 14 14 6 6 6
41160- 0 0 0 0 0 0 0 0 0 0 0 0
41161- 0 0 0 0 0 0 0 0 0 0 0 0
41162- 0 0 0 0 0 0 0 0 0 0 0 0
41163- 0 0 0 0 0 0 0 0 0 10 10 10
41164- 30 30 30 78 78 78 174 135 50 224 166 10
41165-239 182 13 246 190 14 246 190 14 246 190 14
41166-246 190 14 246 190 14 246 190 14 246 190 14
41167-246 190 14 246 190 14 246 190 14 246 190 14
41168-246 190 14 246 190 14 241 196 14 139 102 15
41169- 2 2 6 2 2 6 2 2 6 2 2 6
41170- 78 78 78 250 250 250 253 253 253 253 253 253
41171-253 253 253 253 253 253 253 253 253 253 253 253
41172-253 253 253 253 253 253 253 253 253 253 253 253
41173-253 253 253 253 253 253 253 253 253 253 253 253
41174-250 250 250 214 214 214 198 198 198 190 150 46
41175-219 162 10 236 178 12 234 174 13 224 166 10
41176-216 158 10 213 154 11 213 154 11 216 158 10
41177-226 170 11 239 182 13 246 190 14 246 190 14
41178-246 190 14 246 190 14 242 186 14 206 162 42
41179-101 101 101 58 58 58 30 30 30 14 14 14
41180- 6 6 6 0 0 0 0 0 0 0 0 0
41181- 0 0 0 0 0 0 0 0 0 0 0 0
41182- 0 0 0 0 0 0 0 0 0 0 0 0
41183- 0 0 0 0 0 0 0 0 0 10 10 10
41184- 30 30 30 74 74 74 174 135 50 216 158 10
41185-236 178 12 246 190 14 246 190 14 246 190 14
41186-246 190 14 246 190 14 246 190 14 246 190 14
41187-246 190 14 246 190 14 246 190 14 246 190 14
41188-246 190 14 246 190 14 241 196 14 226 184 13
41189- 61 42 6 2 2 6 2 2 6 2 2 6
41190- 22 22 22 238 238 238 253 253 253 253 253 253
41191-253 253 253 253 253 253 253 253 253 253 253 253
41192-253 253 253 253 253 253 253 253 253 253 253 253
41193-253 253 253 253 253 253 253 253 253 253 253 253
41194-253 253 253 226 226 226 187 187 187 180 133 36
41195-216 158 10 236 178 12 239 182 13 236 178 12
41196-230 174 11 226 170 11 226 170 11 230 174 11
41197-236 178 12 242 186 14 246 190 14 246 190 14
41198-246 190 14 246 190 14 246 186 14 239 182 13
41199-206 162 42 106 106 106 66 66 66 34 34 34
41200- 14 14 14 6 6 6 0 0 0 0 0 0
41201- 0 0 0 0 0 0 0 0 0 0 0 0
41202- 0 0 0 0 0 0 0 0 0 0 0 0
41203- 0 0 0 0 0 0 0 0 0 6 6 6
41204- 26 26 26 70 70 70 163 133 67 213 154 11
41205-236 178 12 246 190 14 246 190 14 246 190 14
41206-246 190 14 246 190 14 246 190 14 246 190 14
41207-246 190 14 246 190 14 246 190 14 246 190 14
41208-246 190 14 246 190 14 246 190 14 241 196 14
41209-190 146 13 18 14 6 2 2 6 2 2 6
41210- 46 46 46 246 246 246 253 253 253 253 253 253
41211-253 253 253 253 253 253 253 253 253 253 253 253
41212-253 253 253 253 253 253 253 253 253 253 253 253
41213-253 253 253 253 253 253 253 253 253 253 253 253
41214-253 253 253 221 221 221 86 86 86 156 107 11
41215-216 158 10 236 178 12 242 186 14 246 186 14
41216-242 186 14 239 182 13 239 182 13 242 186 14
41217-242 186 14 246 186 14 246 190 14 246 190 14
41218-246 190 14 246 190 14 246 190 14 246 190 14
41219-242 186 14 225 175 15 142 122 72 66 66 66
41220- 30 30 30 10 10 10 0 0 0 0 0 0
41221- 0 0 0 0 0 0 0 0 0 0 0 0
41222- 0 0 0 0 0 0 0 0 0 0 0 0
41223- 0 0 0 0 0 0 0 0 0 6 6 6
41224- 26 26 26 70 70 70 163 133 67 210 150 10
41225-236 178 12 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 246 190 14 246 190 14
41228-246 190 14 246 190 14 246 190 14 246 190 14
41229-232 195 16 121 92 8 34 34 34 106 106 106
41230-221 221 221 253 253 253 253 253 253 253 253 253
41231-253 253 253 253 253 253 253 253 253 253 253 253
41232-253 253 253 253 253 253 253 253 253 253 253 253
41233-253 253 253 253 253 253 253 253 253 253 253 253
41234-242 242 242 82 82 82 18 14 6 163 110 8
41235-216 158 10 236 178 12 242 186 14 246 190 14
41236-246 190 14 246 190 14 246 190 14 246 190 14
41237-246 190 14 246 190 14 246 190 14 246 190 14
41238-246 190 14 246 190 14 246 190 14 246 190 14
41239-246 190 14 246 190 14 242 186 14 163 133 67
41240- 46 46 46 18 18 18 6 6 6 0 0 0
41241- 0 0 0 0 0 0 0 0 0 0 0 0
41242- 0 0 0 0 0 0 0 0 0 0 0 0
41243- 0 0 0 0 0 0 0 0 0 10 10 10
41244- 30 30 30 78 78 78 163 133 67 210 150 10
41245-236 178 12 246 186 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 190 14 246 190 14 246 190 14
41248-246 190 14 246 190 14 246 190 14 246 190 14
41249-241 196 14 215 174 15 190 178 144 253 253 253
41250-253 253 253 253 253 253 253 253 253 253 253 253
41251-253 253 253 253 253 253 253 253 253 253 253 253
41252-253 253 253 253 253 253 253 253 253 253 253 253
41253-253 253 253 253 253 253 253 253 253 218 218 218
41254- 58 58 58 2 2 6 22 18 6 167 114 7
41255-216 158 10 236 178 12 246 186 14 246 190 14
41256-246 190 14 246 190 14 246 190 14 246 190 14
41257-246 190 14 246 190 14 246 190 14 246 190 14
41258-246 190 14 246 190 14 246 190 14 246 190 14
41259-246 190 14 246 186 14 242 186 14 190 150 46
41260- 54 54 54 22 22 22 6 6 6 0 0 0
41261- 0 0 0 0 0 0 0 0 0 0 0 0
41262- 0 0 0 0 0 0 0 0 0 0 0 0
41263- 0 0 0 0 0 0 0 0 0 14 14 14
41264- 38 38 38 86 86 86 180 133 36 213 154 11
41265-236 178 12 246 186 14 246 190 14 246 190 14
41266-246 190 14 246 190 14 246 190 14 246 190 14
41267-246 190 14 246 190 14 246 190 14 246 190 14
41268-246 190 14 246 190 14 246 190 14 246 190 14
41269-246 190 14 232 195 16 190 146 13 214 214 214
41270-253 253 253 253 253 253 253 253 253 253 253 253
41271-253 253 253 253 253 253 253 253 253 253 253 253
41272-253 253 253 253 253 253 253 253 253 253 253 253
41273-253 253 253 250 250 250 170 170 170 26 26 26
41274- 2 2 6 2 2 6 37 26 9 163 110 8
41275-219 162 10 239 182 13 246 186 14 246 190 14
41276-246 190 14 246 190 14 246 190 14 246 190 14
41277-246 190 14 246 190 14 246 190 14 246 190 14
41278-246 190 14 246 190 14 246 190 14 246 190 14
41279-246 186 14 236 178 12 224 166 10 142 122 72
41280- 46 46 46 18 18 18 6 6 6 0 0 0
41281- 0 0 0 0 0 0 0 0 0 0 0 0
41282- 0 0 0 0 0 0 0 0 0 0 0 0
41283- 0 0 0 0 0 0 6 6 6 18 18 18
41284- 50 50 50 109 106 95 192 133 9 224 166 10
41285-242 186 14 246 190 14 246 190 14 246 190 14
41286-246 190 14 246 190 14 246 190 14 246 190 14
41287-246 190 14 246 190 14 246 190 14 246 190 14
41288-246 190 14 246 190 14 246 190 14 246 190 14
41289-242 186 14 226 184 13 210 162 10 142 110 46
41290-226 226 226 253 253 253 253 253 253 253 253 253
41291-253 253 253 253 253 253 253 253 253 253 253 253
41292-253 253 253 253 253 253 253 253 253 253 253 253
41293-198 198 198 66 66 66 2 2 6 2 2 6
41294- 2 2 6 2 2 6 50 34 6 156 107 11
41295-219 162 10 239 182 13 246 186 14 246 190 14
41296-246 190 14 246 190 14 246 190 14 246 190 14
41297-246 190 14 246 190 14 246 190 14 246 190 14
41298-246 190 14 246 190 14 246 190 14 242 186 14
41299-234 174 13 213 154 11 154 122 46 66 66 66
41300- 30 30 30 10 10 10 0 0 0 0 0 0
41301- 0 0 0 0 0 0 0 0 0 0 0 0
41302- 0 0 0 0 0 0 0 0 0 0 0 0
41303- 0 0 0 0 0 0 6 6 6 22 22 22
41304- 58 58 58 154 121 60 206 145 10 234 174 13
41305-242 186 14 246 186 14 246 190 14 246 190 14
41306-246 190 14 246 190 14 246 190 14 246 190 14
41307-246 190 14 246 190 14 246 190 14 246 190 14
41308-246 190 14 246 190 14 246 190 14 246 190 14
41309-246 186 14 236 178 12 210 162 10 163 110 8
41310- 61 42 6 138 138 138 218 218 218 250 250 250
41311-253 253 253 253 253 253 253 253 253 250 250 250
41312-242 242 242 210 210 210 144 144 144 66 66 66
41313- 6 6 6 2 2 6 2 2 6 2 2 6
41314- 2 2 6 2 2 6 61 42 6 163 110 8
41315-216 158 10 236 178 12 246 190 14 246 190 14
41316-246 190 14 246 190 14 246 190 14 246 190 14
41317-246 190 14 246 190 14 246 190 14 246 190 14
41318-246 190 14 239 182 13 230 174 11 216 158 10
41319-190 142 34 124 112 88 70 70 70 38 38 38
41320- 18 18 18 6 6 6 0 0 0 0 0 0
41321- 0 0 0 0 0 0 0 0 0 0 0 0
41322- 0 0 0 0 0 0 0 0 0 0 0 0
41323- 0 0 0 0 0 0 6 6 6 22 22 22
41324- 62 62 62 168 124 44 206 145 10 224 166 10
41325-236 178 12 239 182 13 242 186 14 242 186 14
41326-246 186 14 246 190 14 246 190 14 246 190 14
41327-246 190 14 246 190 14 246 190 14 246 190 14
41328-246 190 14 246 190 14 246 190 14 246 190 14
41329-246 190 14 236 178 12 216 158 10 175 118 6
41330- 80 54 7 2 2 6 6 6 6 30 30 30
41331- 54 54 54 62 62 62 50 50 50 38 38 38
41332- 14 14 14 2 2 6 2 2 6 2 2 6
41333- 2 2 6 2 2 6 2 2 6 2 2 6
41334- 2 2 6 6 6 6 80 54 7 167 114 7
41335-213 154 11 236 178 12 246 190 14 246 190 14
41336-246 190 14 246 190 14 246 190 14 246 190 14
41337-246 190 14 242 186 14 239 182 13 239 182 13
41338-230 174 11 210 150 10 174 135 50 124 112 88
41339- 82 82 82 54 54 54 34 34 34 18 18 18
41340- 6 6 6 0 0 0 0 0 0 0 0 0
41341- 0 0 0 0 0 0 0 0 0 0 0 0
41342- 0 0 0 0 0 0 0 0 0 0 0 0
41343- 0 0 0 0 0 0 6 6 6 18 18 18
41344- 50 50 50 158 118 36 192 133 9 200 144 11
41345-216 158 10 219 162 10 224 166 10 226 170 11
41346-230 174 11 236 178 12 239 182 13 239 182 13
41347-242 186 14 246 186 14 246 190 14 246 190 14
41348-246 190 14 246 190 14 246 190 14 246 190 14
41349-246 186 14 230 174 11 210 150 10 163 110 8
41350-104 69 6 10 10 10 2 2 6 2 2 6
41351- 2 2 6 2 2 6 2 2 6 2 2 6
41352- 2 2 6 2 2 6 2 2 6 2 2 6
41353- 2 2 6 2 2 6 2 2 6 2 2 6
41354- 2 2 6 6 6 6 91 60 6 167 114 7
41355-206 145 10 230 174 11 242 186 14 246 190 14
41356-246 190 14 246 190 14 246 186 14 242 186 14
41357-239 182 13 230 174 11 224 166 10 213 154 11
41358-180 133 36 124 112 88 86 86 86 58 58 58
41359- 38 38 38 22 22 22 10 10 10 6 6 6
41360- 0 0 0 0 0 0 0 0 0 0 0 0
41361- 0 0 0 0 0 0 0 0 0 0 0 0
41362- 0 0 0 0 0 0 0 0 0 0 0 0
41363- 0 0 0 0 0 0 0 0 0 14 14 14
41364- 34 34 34 70 70 70 138 110 50 158 118 36
41365-167 114 7 180 123 7 192 133 9 197 138 11
41366-200 144 11 206 145 10 213 154 11 219 162 10
41367-224 166 10 230 174 11 239 182 13 242 186 14
41368-246 186 14 246 186 14 246 186 14 246 186 14
41369-239 182 13 216 158 10 185 133 11 152 99 6
41370-104 69 6 18 14 6 2 2 6 2 2 6
41371- 2 2 6 2 2 6 2 2 6 2 2 6
41372- 2 2 6 2 2 6 2 2 6 2 2 6
41373- 2 2 6 2 2 6 2 2 6 2 2 6
41374- 2 2 6 6 6 6 80 54 7 152 99 6
41375-192 133 9 219 162 10 236 178 12 239 182 13
41376-246 186 14 242 186 14 239 182 13 236 178 12
41377-224 166 10 206 145 10 192 133 9 154 121 60
41378- 94 94 94 62 62 62 42 42 42 22 22 22
41379- 14 14 14 6 6 6 0 0 0 0 0 0
41380- 0 0 0 0 0 0 0 0 0 0 0 0
41381- 0 0 0 0 0 0 0 0 0 0 0 0
41382- 0 0 0 0 0 0 0 0 0 0 0 0
41383- 0 0 0 0 0 0 0 0 0 6 6 6
41384- 18 18 18 34 34 34 58 58 58 78 78 78
41385-101 98 89 124 112 88 142 110 46 156 107 11
41386-163 110 8 167 114 7 175 118 6 180 123 7
41387-185 133 11 197 138 11 210 150 10 219 162 10
41388-226 170 11 236 178 12 236 178 12 234 174 13
41389-219 162 10 197 138 11 163 110 8 130 83 6
41390- 91 60 6 10 10 10 2 2 6 2 2 6
41391- 18 18 18 38 38 38 38 38 38 38 38 38
41392- 38 38 38 38 38 38 38 38 38 38 38 38
41393- 38 38 38 38 38 38 26 26 26 2 2 6
41394- 2 2 6 6 6 6 70 47 6 137 92 6
41395-175 118 6 200 144 11 219 162 10 230 174 11
41396-234 174 13 230 174 11 219 162 10 210 150 10
41397-192 133 9 163 110 8 124 112 88 82 82 82
41398- 50 50 50 30 30 30 14 14 14 6 6 6
41399- 0 0 0 0 0 0 0 0 0 0 0 0
41400- 0 0 0 0 0 0 0 0 0 0 0 0
41401- 0 0 0 0 0 0 0 0 0 0 0 0
41402- 0 0 0 0 0 0 0 0 0 0 0 0
41403- 0 0 0 0 0 0 0 0 0 0 0 0
41404- 6 6 6 14 14 14 22 22 22 34 34 34
41405- 42 42 42 58 58 58 74 74 74 86 86 86
41406-101 98 89 122 102 70 130 98 46 121 87 25
41407-137 92 6 152 99 6 163 110 8 180 123 7
41408-185 133 11 197 138 11 206 145 10 200 144 11
41409-180 123 7 156 107 11 130 83 6 104 69 6
41410- 50 34 6 54 54 54 110 110 110 101 98 89
41411- 86 86 86 82 82 82 78 78 78 78 78 78
41412- 78 78 78 78 78 78 78 78 78 78 78 78
41413- 78 78 78 82 82 82 86 86 86 94 94 94
41414-106 106 106 101 101 101 86 66 34 124 80 6
41415-156 107 11 180 123 7 192 133 9 200 144 11
41416-206 145 10 200 144 11 192 133 9 175 118 6
41417-139 102 15 109 106 95 70 70 70 42 42 42
41418- 22 22 22 10 10 10 0 0 0 0 0 0
41419- 0 0 0 0 0 0 0 0 0 0 0 0
41420- 0 0 0 0 0 0 0 0 0 0 0 0
41421- 0 0 0 0 0 0 0 0 0 0 0 0
41422- 0 0 0 0 0 0 0 0 0 0 0 0
41423- 0 0 0 0 0 0 0 0 0 0 0 0
41424- 0 0 0 0 0 0 6 6 6 10 10 10
41425- 14 14 14 22 22 22 30 30 30 38 38 38
41426- 50 50 50 62 62 62 74 74 74 90 90 90
41427-101 98 89 112 100 78 121 87 25 124 80 6
41428-137 92 6 152 99 6 152 99 6 152 99 6
41429-138 86 6 124 80 6 98 70 6 86 66 30
41430-101 98 89 82 82 82 58 58 58 46 46 46
41431- 38 38 38 34 34 34 34 34 34 34 34 34
41432- 34 34 34 34 34 34 34 34 34 34 34 34
41433- 34 34 34 34 34 34 38 38 38 42 42 42
41434- 54 54 54 82 82 82 94 86 76 91 60 6
41435-134 86 6 156 107 11 167 114 7 175 118 6
41436-175 118 6 167 114 7 152 99 6 121 87 25
41437-101 98 89 62 62 62 34 34 34 18 18 18
41438- 6 6 6 0 0 0 0 0 0 0 0 0
41439- 0 0 0 0 0 0 0 0 0 0 0 0
41440- 0 0 0 0 0 0 0 0 0 0 0 0
41441- 0 0 0 0 0 0 0 0 0 0 0 0
41442- 0 0 0 0 0 0 0 0 0 0 0 0
41443- 0 0 0 0 0 0 0 0 0 0 0 0
41444- 0 0 0 0 0 0 0 0 0 0 0 0
41445- 0 0 0 6 6 6 6 6 6 10 10 10
41446- 18 18 18 22 22 22 30 30 30 42 42 42
41447- 50 50 50 66 66 66 86 86 86 101 98 89
41448-106 86 58 98 70 6 104 69 6 104 69 6
41449-104 69 6 91 60 6 82 62 34 90 90 90
41450- 62 62 62 38 38 38 22 22 22 14 14 14
41451- 10 10 10 10 10 10 10 10 10 10 10 10
41452- 10 10 10 10 10 10 6 6 6 10 10 10
41453- 10 10 10 10 10 10 10 10 10 14 14 14
41454- 22 22 22 42 42 42 70 70 70 89 81 66
41455- 80 54 7 104 69 6 124 80 6 137 92 6
41456-134 86 6 116 81 8 100 82 52 86 86 86
41457- 58 58 58 30 30 30 14 14 14 6 6 6
41458- 0 0 0 0 0 0 0 0 0 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- 0 0 0 0 0 0 0 0 0 0 0 0
41463- 0 0 0 0 0 0 0 0 0 0 0 0
41464- 0 0 0 0 0 0 0 0 0 0 0 0
41465- 0 0 0 0 0 0 0 0 0 0 0 0
41466- 0 0 0 6 6 6 10 10 10 14 14 14
41467- 18 18 18 26 26 26 38 38 38 54 54 54
41468- 70 70 70 86 86 86 94 86 76 89 81 66
41469- 89 81 66 86 86 86 74 74 74 50 50 50
41470- 30 30 30 14 14 14 6 6 6 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- 6 6 6 18 18 18 34 34 34 58 58 58
41475- 82 82 82 89 81 66 89 81 66 89 81 66
41476- 94 86 66 94 86 76 74 74 74 50 50 50
41477- 26 26 26 14 14 14 6 6 6 0 0 0
41478- 0 0 0 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 0 0 0 0 0 0 0 0 0
41483- 0 0 0 0 0 0 0 0 0 0 0 0
41484- 0 0 0 0 0 0 0 0 0 0 0 0
41485- 0 0 0 0 0 0 0 0 0 0 0 0
41486- 0 0 0 0 0 0 0 0 0 0 0 0
41487- 6 6 6 6 6 6 14 14 14 18 18 18
41488- 30 30 30 38 38 38 46 46 46 54 54 54
41489- 50 50 50 42 42 42 30 30 30 18 18 18
41490- 10 10 10 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 6 6 6 14 14 14 26 26 26
41495- 38 38 38 50 50 50 58 58 58 58 58 58
41496- 54 54 54 42 42 42 30 30 30 18 18 18
41497- 10 10 10 0 0 0 0 0 0 0 0 0
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 0 0 0
41503- 0 0 0 0 0 0 0 0 0 0 0 0
41504- 0 0 0 0 0 0 0 0 0 0 0 0
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 6 6 6
41508- 6 6 6 10 10 10 14 14 14 18 18 18
41509- 18 18 18 14 14 14 10 10 10 6 6 6
41510- 0 0 0 0 0 0 0 0 0 0 0 0
41511- 0 0 0 0 0 0 0 0 0 0 0 0
41512- 0 0 0 0 0 0 0 0 0 0 0 0
41513- 0 0 0 0 0 0 0 0 0 0 0 0
41514- 0 0 0 0 0 0 0 0 0 6 6 6
41515- 14 14 14 18 18 18 22 22 22 22 22 22
41516- 18 18 18 14 14 14 10 10 10 6 6 6
41517- 0 0 0 0 0 0 0 0 0 0 0 0
41518- 0 0 0 0 0 0 0 0 0 0 0 0
41519- 0 0 0 0 0 0 0 0 0 0 0 0
41520- 0 0 0 0 0 0 0 0 0 0 0 0
41521- 0 0 0 0 0 0 0 0 0 0 0 0
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 4 4 4 4 4 4 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
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 4 4 4 4 4 4 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
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 4 4 4 4 4 4 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
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 4 4 4 4 4 4 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
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 4 4 4 4 4 4 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
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 4 4 4 4 4 4 4 4 4 4 4 4
41594+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41595+4 4 4 4 4 4 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 4 4 4 4 4 4 4 4 4
41599+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 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 4 4 4 4 4 4
41604+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41605+4 4 4 4 4 4
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 4 4 4 4 4 4 4 4 4 4 4 4
41608+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41609+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41610+4 4 4 4 4 4 4 4 4 3 3 3 0 0 0 0 0 0
41611+0 0 0 0 0 0 0 0 0 0 0 0 3 3 3 4 4 4
41612+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41613+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41614+4 4 4 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 1 1 1 0 0 0
41616+0 0 0 3 3 3 4 4 4 4 4 4 4 4 4 4 4 4
41617+4 4 4 4 4 4 4 4 4 2 1 0 2 1 0 3 2 2
41618+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41619+4 4 4 4 4 4
41620+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41621+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41622+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41623+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41624+4 4 4 4 4 4 2 2 2 0 0 0 3 4 3 26 28 28
41625+37 38 37 37 38 37 14 17 19 2 2 2 0 0 0 2 2 2
41626+5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41627+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41628+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41629+4 4 4 4 4 4 3 3 3 0 0 0 1 1 1 6 6 6
41630+2 2 2 0 0 0 3 3 3 4 4 4 4 4 4 4 4 4
41631+4 4 5 3 3 3 1 0 0 0 0 0 1 0 0 0 0 0
41632+1 1 1 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41633+4 4 4 4 4 4
41634+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41635+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41636+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41637+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41638+2 2 2 0 0 0 0 0 0 14 17 19 60 74 84 137 136 137
41639+153 152 153 137 136 137 125 124 125 60 73 81 6 6 6 3 1 0
41640+0 0 0 3 3 3 4 4 4 4 4 4 4 4 4 4 4 4
41641+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41642+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41643+4 4 4 4 4 4 0 0 0 4 4 4 41 54 63 125 124 125
41644+60 73 81 6 6 6 4 0 0 3 3 3 4 4 4 4 4 4
41645+4 4 4 0 0 0 6 9 11 41 54 63 41 65 82 22 30 35
41646+2 2 2 2 1 0 4 4 4 4 4 4 4 4 4 4 4 4
41647+4 4 4 4 4 4
41648+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41649+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41650+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41651+4 4 4 4 4 4 5 5 5 5 5 5 2 2 2 0 0 0
41652+4 0 0 6 6 6 41 54 63 137 136 137 174 174 174 167 166 167
41653+165 164 165 165 164 165 163 162 163 163 162 163 125 124 125 41 54 63
41654+1 1 1 0 0 0 0 0 0 3 3 3 5 5 5 4 4 4
41655+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41656+4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 5 5 5
41657+3 3 3 2 0 0 4 0 0 60 73 81 156 155 156 167 166 167
41658+163 162 163 85 115 134 5 7 8 0 0 0 4 4 4 5 5 5
41659+0 0 0 2 5 5 55 98 126 90 154 193 90 154 193 72 125 159
41660+37 51 59 2 0 0 1 1 1 4 5 5 4 4 4 4 4 4
41661+4 4 4 4 4 4
41662+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41663+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41664+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41665+4 4 4 5 5 5 4 4 4 1 1 1 0 0 0 3 3 3
41666+37 38 37 125 124 125 163 162 163 174 174 174 158 157 158 158 157 158
41667+156 155 156 156 155 156 158 157 158 165 164 165 174 174 174 166 165 166
41668+125 124 125 16 19 21 1 0 0 0 0 0 0 0 0 4 4 4
41669+5 5 5 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
41670+4 4 4 4 4 4 4 4 4 5 5 5 5 5 5 1 1 1
41671+0 0 0 0 0 0 37 38 37 153 152 153 174 174 174 158 157 158
41672+174 174 174 163 162 163 37 38 37 4 3 3 4 0 0 1 1 1
41673+0 0 0 22 40 52 101 161 196 101 161 196 90 154 193 101 161 196
41674+64 123 161 14 17 19 0 0 0 4 4 4 4 4 4 4 4 4
41675+4 4 4 4 4 4
41676+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41677+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41678+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
41679+5 5 5 2 2 2 0 0 0 4 0 0 24 26 27 85 115 134
41680+156 155 156 174 174 174 167 166 167 156 155 156 154 153 154 157 156 157
41681+156 155 156 156 155 156 155 154 155 153 152 153 158 157 158 167 166 167
41682+174 174 174 156 155 156 60 74 84 16 19 21 0 0 0 0 0 0
41683+1 1 1 5 5 5 5 5 5 4 4 4 4 4 4 4 4 4
41684+4 4 4 5 5 5 6 6 6 3 3 3 0 0 0 4 0 0
41685+13 16 17 60 73 81 137 136 137 165 164 165 156 155 156 153 152 153
41686+174 174 174 177 184 187 60 73 81 3 1 0 0 0 0 1 1 2
41687+22 30 35 64 123 161 136 185 209 90 154 193 90 154 193 90 154 193
41688+90 154 193 21 29 34 0 0 0 3 2 2 4 4 5 4 4 4
41689+4 4 4 4 4 4
41690+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41691+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41692+4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 3 3 3
41693+0 0 0 0 0 0 10 13 16 60 74 84 157 156 157 174 174 174
41694+174 174 174 158 157 158 153 152 153 154 153 154 156 155 156 155 154 155
41695+156 155 156 155 154 155 154 153 154 157 156 157 154 153 154 153 152 153
41696+163 162 163 174 174 174 177 184 187 137 136 137 60 73 81 13 16 17
41697+4 0 0 0 0 0 3 3 3 5 5 5 4 4 4 4 4 4
41698+5 5 5 4 4 4 1 1 1 0 0 0 3 3 3 41 54 63
41699+131 129 131 174 174 174 174 174 174 174 174 174 167 166 167 174 174 174
41700+190 197 201 137 136 137 24 26 27 4 0 0 16 21 25 50 82 103
41701+90 154 193 136 185 209 90 154 193 101 161 196 101 161 196 101 161 196
41702+31 91 132 3 6 7 0 0 0 4 4 4 4 4 4 4 4 4
41703+4 4 4 4 4 4
41704+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41705+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41706+4 4 4 4 4 4 4 4 4 2 2 2 0 0 0 4 0 0
41707+4 0 0 43 57 68 137 136 137 177 184 187 174 174 174 163 162 163
41708+155 154 155 155 154 155 156 155 156 155 154 155 158 157 158 165 164 165
41709+167 166 167 166 165 166 163 162 163 157 156 157 155 154 155 155 154 155
41710+153 152 153 156 155 156 167 166 167 174 174 174 174 174 174 131 129 131
41711+41 54 63 5 5 5 0 0 0 0 0 0 3 3 3 4 4 4
41712+1 1 1 0 0 0 1 0 0 26 28 28 125 124 125 174 174 174
41713+177 184 187 174 174 174 174 174 174 156 155 156 131 129 131 137 136 137
41714+125 124 125 24 26 27 4 0 0 41 65 82 90 154 193 136 185 209
41715+136 185 209 101 161 196 53 118 160 37 112 160 90 154 193 34 86 122
41716+7 12 15 0 0 0 4 4 4 4 4 4 4 4 4 4 4 4
41717+4 4 4 4 4 4
41718+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41719+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41720+4 4 4 3 3 3 0 0 0 0 0 0 5 5 5 37 38 37
41721+125 124 125 167 166 167 174 174 174 167 166 167 158 157 158 155 154 155
41722+156 155 156 156 155 156 156 155 156 163 162 163 167 166 167 155 154 155
41723+137 136 137 153 152 153 156 155 156 165 164 165 163 162 163 156 155 156
41724+156 155 156 156 155 156 155 154 155 158 157 158 166 165 166 174 174 174
41725+167 166 167 125 124 125 37 38 37 1 0 0 0 0 0 0 0 0
41726+0 0 0 24 26 27 60 74 84 158 157 158 174 174 174 174 174 174
41727+166 165 166 158 157 158 125 124 125 41 54 63 13 16 17 6 6 6
41728+6 6 6 37 38 37 80 127 157 136 185 209 101 161 196 101 161 196
41729+90 154 193 28 67 93 6 10 14 13 20 25 13 20 25 6 10 14
41730+1 1 2 4 3 3 4 4 4 4 4 4 4 4 4 4 4 4
41731+4 4 4 4 4 4
41732+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41733+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41734+1 1 1 1 0 0 4 3 3 37 38 37 60 74 84 153 152 153
41735+167 166 167 167 166 167 158 157 158 154 153 154 155 154 155 156 155 156
41736+157 156 157 158 157 158 167 166 167 167 166 167 131 129 131 43 57 68
41737+26 28 28 37 38 37 60 73 81 131 129 131 165 164 165 166 165 166
41738+158 157 158 155 154 155 156 155 156 156 155 156 156 155 156 158 157 158
41739+165 164 165 174 174 174 163 162 163 60 74 84 16 19 21 13 16 17
41740+60 73 81 131 129 131 174 174 174 174 174 174 167 166 167 165 164 165
41741+137 136 137 60 73 81 24 26 27 4 0 0 4 0 0 16 19 21
41742+52 104 138 101 161 196 136 185 209 136 185 209 90 154 193 27 99 146
41743+13 20 25 4 5 7 2 5 5 4 5 7 1 1 2 0 0 0
41744+4 4 4 4 4 4 3 3 3 2 2 2 2 2 2 4 4 4
41745+4 4 4 4 4 4
41746+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41747+4 4 4 4 4 4 4 4 4 4 4 4 3 3 3 0 0 0
41748+0 0 0 13 16 17 60 73 81 137 136 137 174 174 174 166 165 166
41749+158 157 158 156 155 156 157 156 157 156 155 156 155 154 155 158 157 158
41750+167 166 167 174 174 174 153 152 153 60 73 81 16 19 21 4 0 0
41751+4 0 0 4 0 0 6 6 6 26 28 28 60 74 84 158 157 158
41752+174 174 174 166 165 166 157 156 157 155 154 155 156 155 156 156 155 156
41753+155 154 155 158 157 158 167 166 167 167 166 167 131 129 131 125 124 125
41754+137 136 137 167 166 167 167 166 167 174 174 174 158 157 158 125 124 125
41755+16 19 21 4 0 0 4 0 0 10 13 16 49 76 92 107 159 188
41756+136 185 209 136 185 209 90 154 193 26 108 161 22 40 52 6 10 14
41757+2 3 3 1 1 2 1 1 2 4 4 5 4 4 5 4 4 5
41758+4 4 5 2 2 1 0 0 0 0 0 0 0 0 0 2 2 2
41759+4 4 4 4 4 4
41760+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41761+4 4 4 5 5 5 3 3 3 0 0 0 1 0 0 4 0 0
41762+37 51 59 131 129 131 167 166 167 167 166 167 163 162 163 157 156 157
41763+157 156 157 155 154 155 153 152 153 157 156 157 167 166 167 174 174 174
41764+153 152 153 125 124 125 37 38 37 4 0 0 4 0 0 4 0 0
41765+4 3 3 4 3 3 4 0 0 6 6 6 4 0 0 37 38 37
41766+125 124 125 174 174 174 174 174 174 165 164 165 156 155 156 154 153 154
41767+156 155 156 156 155 156 155 154 155 163 162 163 158 157 158 163 162 163
41768+174 174 174 174 174 174 174 174 174 125 124 125 37 38 37 0 0 0
41769+4 0 0 6 9 11 41 54 63 90 154 193 136 185 209 146 190 211
41770+136 185 209 37 112 160 22 40 52 6 10 14 3 6 7 1 1 2
41771+1 1 2 3 3 3 1 1 2 3 3 3 4 4 4 4 4 4
41772+2 2 2 2 0 0 16 19 21 37 38 37 24 26 27 0 0 0
41773+0 0 0 4 4 4
41774+4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 5 5 5
41775+4 4 4 0 0 0 0 0 0 0 0 0 26 28 28 120 125 127
41776+158 157 158 174 174 174 165 164 165 157 156 157 155 154 155 156 155 156
41777+153 152 153 153 152 153 167 166 167 174 174 174 174 174 174 125 124 125
41778+37 38 37 4 0 0 0 0 0 4 0 0 4 3 3 4 4 4
41779+4 4 4 4 4 4 5 5 5 4 0 0 4 0 0 4 0 0
41780+4 3 3 43 57 68 137 136 137 174 174 174 174 174 174 165 164 165
41781+154 153 154 153 152 153 153 152 153 153 152 153 163 162 163 174 174 174
41782+174 174 174 153 152 153 60 73 81 6 6 6 4 0 0 4 3 3
41783+32 43 50 80 127 157 136 185 209 146 190 211 146 190 211 90 154 193
41784+28 67 93 28 67 93 40 71 93 3 6 7 1 1 2 2 5 5
41785+50 82 103 79 117 143 26 37 45 0 0 0 3 3 3 1 1 1
41786+0 0 0 41 54 63 137 136 137 174 174 174 153 152 153 60 73 81
41787+2 0 0 0 0 0
41788+4 4 4 4 4 4 4 4 4 4 4 4 6 6 6 2 2 2
41789+0 0 0 2 0 0 24 26 27 60 74 84 153 152 153 174 174 174
41790+174 174 174 157 156 157 154 153 154 156 155 156 154 153 154 153 152 153
41791+165 164 165 174 174 174 177 184 187 137 136 137 43 57 68 6 6 6
41792+4 0 0 2 0 0 3 3 3 5 5 5 5 5 5 4 4 4
41793+4 4 4 4 4 4 4 4 4 5 5 5 6 6 6 4 3 3
41794+4 0 0 4 0 0 24 26 27 60 73 81 153 152 153 174 174 174
41795+174 174 174 158 157 158 158 157 158 174 174 174 174 174 174 158 157 158
41796+60 74 84 24 26 27 4 0 0 4 0 0 17 23 27 59 113 148
41797+136 185 209 191 222 234 146 190 211 136 185 209 31 91 132 7 11 13
41798+22 40 52 101 161 196 90 154 193 6 9 11 3 4 4 43 95 132
41799+136 185 209 172 205 220 55 98 126 0 0 0 0 0 0 2 0 0
41800+26 28 28 153 152 153 177 184 187 167 166 167 177 184 187 165 164 165
41801+37 38 37 0 0 0
41802+4 4 4 4 4 4 5 5 5 5 5 5 1 1 1 0 0 0
41803+13 16 17 60 73 81 137 136 137 174 174 174 174 174 174 165 164 165
41804+153 152 153 153 152 153 155 154 155 154 153 154 158 157 158 174 174 174
41805+177 184 187 163 162 163 60 73 81 16 19 21 4 0 0 4 0 0
41806+4 3 3 4 4 4 5 5 5 5 5 5 4 4 4 5 5 5
41807+5 5 5 5 5 5 5 5 5 4 4 4 4 4 4 5 5 5
41808+6 6 6 4 0 0 4 0 0 4 0 0 24 26 27 60 74 84
41809+166 165 166 174 174 174 177 184 187 165 164 165 125 124 125 24 26 27
41810+4 0 0 4 0 0 5 5 5 50 82 103 136 185 209 172 205 220
41811+146 190 211 136 185 209 26 108 161 22 40 52 7 12 15 44 81 103
41812+71 116 144 28 67 93 37 51 59 41 65 82 100 139 164 101 161 196
41813+90 154 193 90 154 193 28 67 93 0 0 0 0 0 0 26 28 28
41814+125 124 125 167 166 167 163 162 163 153 152 153 163 162 163 174 174 174
41815+85 115 134 4 0 0
41816+4 4 4 5 5 5 4 4 4 1 0 0 4 0 0 34 47 55
41817+125 124 125 174 174 174 174 174 174 167 166 167 157 156 157 153 152 153
41818+155 154 155 155 154 155 158 157 158 166 165 166 167 166 167 154 153 154
41819+125 124 125 26 28 28 4 0 0 4 0 0 4 0 0 5 5 5
41820+5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 1 1 1
41821+0 0 0 0 0 0 1 1 1 4 4 4 4 4 4 4 4 4
41822+5 5 5 5 5 5 4 3 3 4 0 0 4 0 0 6 6 6
41823+37 38 37 131 129 131 137 136 137 37 38 37 0 0 0 4 0 0
41824+4 5 5 43 61 72 90 154 193 172 205 220 146 190 211 136 185 209
41825+90 154 193 28 67 93 13 20 25 43 61 72 71 116 144 44 81 103
41826+2 5 5 7 11 13 59 113 148 101 161 196 90 154 193 28 67 93
41827+13 20 25 6 10 14 0 0 0 13 16 17 60 73 81 137 136 137
41828+166 165 166 158 157 158 156 155 156 154 153 154 167 166 167 174 174 174
41829+60 73 81 4 0 0
41830+4 4 4 4 4 4 0 0 0 3 3 3 60 74 84 174 174 174
41831+174 174 174 167 166 167 163 162 163 155 154 155 157 156 157 155 154 155
41832+156 155 156 163 162 163 167 166 167 158 157 158 125 124 125 37 38 37
41833+4 3 3 4 0 0 4 0 0 6 6 6 6 6 6 5 5 5
41834+4 4 4 4 4 4 4 4 4 1 1 1 0 0 0 2 3 3
41835+10 13 16 7 11 13 1 0 0 0 0 0 2 2 1 4 4 4
41836+4 4 4 4 4 4 4 4 4 5 5 5 4 3 3 4 0 0
41837+4 0 0 7 11 13 13 16 17 4 0 0 3 3 3 34 47 55
41838+80 127 157 146 190 211 172 205 220 136 185 209 136 185 209 136 185 209
41839+28 67 93 22 40 52 55 98 126 55 98 126 21 29 34 7 11 13
41840+50 82 103 101 161 196 101 161 196 35 83 115 13 20 25 2 2 1
41841+1 1 2 1 1 2 37 51 59 131 129 131 174 174 174 174 174 174
41842+167 166 167 163 162 163 163 162 163 167 166 167 174 174 174 125 124 125
41843+16 19 21 4 0 0
41844+4 4 4 4 0 0 4 0 0 60 74 84 174 174 174 174 174 174
41845+158 157 158 155 154 155 155 154 155 156 155 156 155 154 155 158 157 158
41846+167 166 167 165 164 165 131 129 131 60 73 81 13 16 17 4 0 0
41847+4 0 0 4 3 3 6 6 6 4 3 3 5 5 5 4 4 4
41848+4 4 4 3 2 2 0 0 0 0 0 0 7 11 13 45 69 86
41849+80 127 157 71 116 144 43 61 72 7 11 13 0 0 0 1 1 1
41850+4 3 3 4 4 4 4 4 4 4 4 4 6 6 6 5 5 5
41851+3 2 2 4 0 0 1 0 0 21 29 34 59 113 148 136 185 209
41852+146 190 211 136 185 209 136 185 209 136 185 209 136 185 209 136 185 209
41853+68 124 159 44 81 103 22 40 52 13 16 17 43 61 72 90 154 193
41854+136 185 209 59 113 148 21 29 34 3 4 3 1 1 1 0 0 0
41855+24 26 27 125 124 125 163 162 163 174 174 174 166 165 166 165 164 165
41856+163 162 163 125 124 125 125 124 125 125 124 125 125 124 125 26 28 28
41857+4 0 0 4 3 3
41858+3 3 3 0 0 0 24 26 27 153 152 153 177 184 187 158 157 158
41859+156 155 156 156 155 156 155 154 155 155 154 155 165 164 165 174 174 174
41860+155 154 155 60 74 84 26 28 28 4 0 0 4 0 0 3 1 0
41861+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 3 3
41862+2 0 0 0 0 0 0 0 0 32 43 50 72 125 159 101 161 196
41863+136 185 209 101 161 196 101 161 196 79 117 143 32 43 50 0 0 0
41864+0 0 0 2 2 2 4 4 4 4 4 4 3 3 3 1 0 0
41865+0 0 0 4 5 5 49 76 92 101 161 196 146 190 211 146 190 211
41866+136 185 209 136 185 209 136 185 209 136 185 209 136 185 209 90 154 193
41867+28 67 93 13 16 17 37 51 59 80 127 157 136 185 209 90 154 193
41868+22 40 52 6 9 11 3 4 3 2 2 1 16 19 21 60 73 81
41869+137 136 137 163 162 163 158 157 158 166 165 166 167 166 167 153 152 153
41870+60 74 84 37 38 37 6 6 6 13 16 17 4 0 0 1 0 0
41871+3 2 2 4 4 4
41872+3 2 2 4 0 0 37 38 37 137 136 137 167 166 167 158 157 158
41873+157 156 157 154 153 154 157 156 157 167 166 167 174 174 174 125 124 125
41874+37 38 37 4 0 0 4 0 0 4 0 0 4 3 3 4 4 4
41875+4 4 4 4 4 4 5 5 5 5 5 5 1 1 1 0 0 0
41876+0 0 0 16 21 25 55 98 126 90 154 193 136 185 209 101 161 196
41877+101 161 196 101 161 196 136 185 209 136 185 209 101 161 196 55 98 126
41878+14 17 19 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
41879+22 40 52 90 154 193 146 190 211 146 190 211 136 185 209 136 185 209
41880+136 185 209 136 185 209 136 185 209 101 161 196 35 83 115 7 11 13
41881+17 23 27 59 113 148 136 185 209 101 161 196 34 86 122 7 12 15
41882+2 5 5 3 4 3 6 6 6 60 73 81 131 129 131 163 162 163
41883+166 165 166 174 174 174 174 174 174 163 162 163 125 124 125 41 54 63
41884+13 16 17 4 0 0 4 0 0 4 0 0 1 0 0 2 2 2
41885+4 4 4 4 4 4
41886+1 1 1 2 1 0 43 57 68 137 136 137 153 152 153 153 152 153
41887+163 162 163 156 155 156 165 164 165 167 166 167 60 74 84 6 6 6
41888+4 0 0 4 0 0 5 5 5 4 4 4 4 4 4 4 4 4
41889+4 5 5 6 6 6 4 3 3 0 0 0 0 0 0 11 15 18
41890+40 71 93 100 139 164 101 161 196 101 161 196 101 161 196 101 161 196
41891+101 161 196 101 161 196 101 161 196 101 161 196 136 185 209 136 185 209
41892+101 161 196 45 69 86 6 6 6 0 0 0 17 23 27 55 98 126
41893+136 185 209 146 190 211 136 185 209 136 185 209 136 185 209 136 185 209
41894+136 185 209 136 185 209 90 154 193 22 40 52 7 11 13 50 82 103
41895+136 185 209 136 185 209 53 118 160 22 40 52 7 11 13 2 5 5
41896+3 4 3 37 38 37 125 124 125 157 156 157 166 165 166 167 166 167
41897+174 174 174 174 174 174 137 136 137 60 73 81 4 0 0 4 0 0
41898+4 0 0 4 0 0 5 5 5 3 3 3 3 3 3 4 4 4
41899+4 4 4 4 4 4
41900+4 0 0 4 0 0 41 54 63 137 136 137 125 124 125 131 129 131
41901+155 154 155 167 166 167 174 174 174 60 74 84 6 6 6 4 0 0
41902+4 3 3 6 6 6 4 4 4 4 4 4 4 4 4 5 5 5
41903+4 4 4 1 1 1 0 0 0 3 6 7 41 65 82 72 125 159
41904+101 161 196 101 161 196 101 161 196 90 154 193 90 154 193 101 161 196
41905+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 136 185 209
41906+136 185 209 136 185 209 80 127 157 55 98 126 101 161 196 146 190 211
41907+136 185 209 136 185 209 136 185 209 101 161 196 136 185 209 101 161 196
41908+136 185 209 101 161 196 35 83 115 22 30 35 101 161 196 172 205 220
41909+90 154 193 28 67 93 7 11 13 2 5 5 3 4 3 13 16 17
41910+85 115 134 167 166 167 174 174 174 174 174 174 174 174 174 174 174 174
41911+167 166 167 60 74 84 13 16 17 4 0 0 4 0 0 4 3 3
41912+6 6 6 5 5 5 4 4 4 5 5 5 4 4 4 5 5 5
41913+5 5 5 5 5 5
41914+1 1 1 4 0 0 41 54 63 137 136 137 137 136 137 125 124 125
41915+131 129 131 167 166 167 157 156 157 37 38 37 6 6 6 4 0 0
41916+6 6 6 5 5 5 4 4 4 4 4 4 4 5 5 2 2 1
41917+0 0 0 0 0 0 26 37 45 58 111 146 101 161 196 101 161 196
41918+101 161 196 90 154 193 90 154 193 90 154 193 101 161 196 101 161 196
41919+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
41920+101 161 196 136 185 209 136 185 209 136 185 209 146 190 211 136 185 209
41921+136 185 209 101 161 196 136 185 209 136 185 209 101 161 196 136 185 209
41922+101 161 196 136 185 209 136 185 209 136 185 209 136 185 209 16 89 141
41923+7 11 13 2 5 5 2 5 5 13 16 17 60 73 81 154 154 154
41924+174 174 174 174 174 174 174 174 174 174 174 174 163 162 163 125 124 125
41925+24 26 27 4 0 0 4 0 0 4 0 0 5 5 5 5 5 5
41926+4 4 4 4 4 4 4 4 4 5 5 5 5 5 5 5 5 5
41927+5 5 5 4 4 4
41928+4 0 0 6 6 6 37 38 37 137 136 137 137 136 137 131 129 131
41929+131 129 131 153 152 153 131 129 131 26 28 28 4 0 0 4 3 3
41930+6 6 6 4 4 4 4 4 4 4 4 4 0 0 0 0 0 0
41931+13 20 25 51 88 114 90 154 193 101 161 196 101 161 196 90 154 193
41932+90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 101 161 196
41933+101 161 196 101 161 196 101 161 196 101 161 196 136 185 209 101 161 196
41934+101 161 196 136 185 209 101 161 196 136 185 209 136 185 209 101 161 196
41935+136 185 209 101 161 196 136 185 209 101 161 196 101 161 196 101 161 196
41936+136 185 209 136 185 209 136 185 209 37 112 160 21 29 34 5 7 8
41937+2 5 5 13 16 17 43 57 68 131 129 131 174 174 174 174 174 174
41938+174 174 174 167 166 167 157 156 157 125 124 125 37 38 37 4 0 0
41939+4 0 0 4 0 0 5 5 5 5 5 5 4 4 4 4 4 4
41940+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41941+4 4 4 4 4 4
41942+1 1 1 4 0 0 41 54 63 153 152 153 137 136 137 137 136 137
41943+137 136 137 153 152 153 125 124 125 24 26 27 4 0 0 3 2 2
41944+4 4 4 4 4 4 4 3 3 4 0 0 3 6 7 43 61 72
41945+64 123 161 101 161 196 90 154 193 90 154 193 90 154 193 90 154 193
41946+90 154 193 90 154 193 90 154 193 90 154 193 101 161 196 90 154 193
41947+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
41948+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
41949+136 185 209 101 161 196 101 161 196 136 185 209 136 185 209 101 161 196
41950+101 161 196 90 154 193 28 67 93 13 16 17 7 11 13 3 6 7
41951+37 51 59 125 124 125 163 162 163 174 174 174 167 166 167 166 165 166
41952+167 166 167 131 129 131 60 73 81 4 0 0 4 0 0 4 0 0
41953+3 3 3 5 5 5 6 6 6 4 4 4 4 4 4 4 4 4
41954+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41955+4 4 4 4 4 4
41956+4 0 0 4 0 0 41 54 63 137 136 137 153 152 153 137 136 137
41957+153 152 153 157 156 157 125 124 125 24 26 27 0 0 0 2 2 2
41958+4 4 4 4 4 4 2 0 0 0 0 0 28 67 93 90 154 193
41959+90 154 193 90 154 193 90 154 193 90 154 193 64 123 161 90 154 193
41960+90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 101 161 196
41961+90 154 193 101 161 196 101 161 196 101 161 196 90 154 193 136 185 209
41962+101 161 196 101 161 196 136 185 209 101 161 196 136 185 209 101 161 196
41963+101 161 196 101 161 196 136 185 209 101 161 196 101 161 196 90 154 193
41964+35 83 115 13 16 17 3 6 7 2 5 5 13 16 17 60 74 84
41965+154 154 154 166 165 166 165 164 165 158 157 158 163 162 163 157 156 157
41966+60 74 84 13 16 17 4 0 0 4 0 0 3 2 2 4 4 4
41967+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41968+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41969+4 4 4 4 4 4
41970+1 1 1 4 0 0 41 54 63 157 156 157 155 154 155 137 136 137
41971+153 152 153 158 157 158 137 136 137 26 28 28 2 0 0 2 2 2
41972+4 4 4 4 4 4 1 0 0 6 10 14 34 86 122 90 154 193
41973+64 123 161 90 154 193 64 123 161 90 154 193 90 154 193 90 154 193
41974+64 123 161 90 154 193 90 154 193 90 154 193 90 154 193 90 154 193
41975+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
41976+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
41977+136 185 209 101 161 196 136 185 209 90 154 193 26 108 161 22 40 52
41978+13 16 17 5 7 8 2 5 5 2 5 5 37 38 37 165 164 165
41979+174 174 174 163 162 163 154 154 154 165 164 165 167 166 167 60 73 81
41980+6 6 6 4 0 0 4 0 0 4 4 4 4 4 4 4 4 4
41981+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41982+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41983+4 4 4 4 4 4
41984+4 0 0 6 6 6 41 54 63 156 155 156 158 157 158 153 152 153
41985+156 155 156 165 164 165 137 136 137 26 28 28 0 0 0 2 2 2
41986+4 4 5 4 4 4 2 0 0 7 12 15 31 96 139 64 123 161
41987+90 154 193 64 123 161 90 154 193 90 154 193 64 123 161 90 154 193
41988+90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 90 154 193
41989+90 154 193 90 154 193 90 154 193 101 161 196 101 161 196 101 161 196
41990+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 136 185 209
41991+101 161 196 136 185 209 26 108 161 22 40 52 7 11 13 5 7 8
41992+2 5 5 2 5 5 2 5 5 2 2 1 37 38 37 158 157 158
41993+174 174 174 154 154 154 156 155 156 167 166 167 165 164 165 37 38 37
41994+4 0 0 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41995+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41996+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41997+4 4 4 4 4 4
41998+3 1 0 4 0 0 60 73 81 157 156 157 163 162 163 153 152 153
41999+158 157 158 167 166 167 137 136 137 26 28 28 2 0 0 2 2 2
42000+4 5 5 4 4 4 4 0 0 7 12 15 24 86 132 26 108 161
42001+37 112 160 64 123 161 90 154 193 64 123 161 90 154 193 90 154 193
42002+90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 90 154 193
42003+90 154 193 101 161 196 90 154 193 101 161 196 101 161 196 101 161 196
42004+101 161 196 101 161 196 101 161 196 136 185 209 101 161 196 136 185 209
42005+90 154 193 35 83 115 13 16 17 13 16 17 7 11 13 3 6 7
42006+5 7 8 6 6 6 3 4 3 2 2 1 30 32 34 154 154 154
42007+167 166 167 154 154 154 154 154 154 174 174 174 165 164 165 37 38 37
42008+6 6 6 4 0 0 6 6 6 4 4 4 4 4 4 4 4 4
42009+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42010+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42011+4 4 4 4 4 4
42012+4 0 0 4 0 0 41 54 63 163 162 163 166 165 166 154 154 154
42013+163 162 163 174 174 174 137 136 137 26 28 28 0 0 0 2 2 2
42014+4 5 5 4 4 5 1 1 2 6 10 14 28 67 93 18 97 151
42015+18 97 151 18 97 151 26 108 161 37 112 160 37 112 160 90 154 193
42016+64 123 161 90 154 193 90 154 193 90 154 193 90 154 193 101 161 196
42017+90 154 193 101 161 196 101 161 196 90 154 193 101 161 196 101 161 196
42018+101 161 196 101 161 196 101 161 196 136 185 209 90 154 193 16 89 141
42019+13 20 25 7 11 13 5 7 8 5 7 8 2 5 5 4 5 5
42020+3 4 3 4 5 5 3 4 3 0 0 0 37 38 37 158 157 158
42021+174 174 174 158 157 158 158 157 158 167 166 167 174 174 174 41 54 63
42022+4 0 0 3 2 2 5 5 5 4 4 4 4 4 4 4 4 4
42023+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42024+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42025+4 4 4 4 4 4
42026+1 1 1 4 0 0 60 73 81 165 164 165 174 174 174 158 157 158
42027+167 166 167 174 174 174 153 152 153 26 28 28 2 0 0 2 2 2
42028+4 5 5 4 4 4 4 0 0 7 12 15 10 87 144 10 87 144
42029+18 97 151 18 97 151 18 97 151 26 108 161 26 108 161 26 108 161
42030+26 108 161 37 112 160 53 118 160 90 154 193 90 154 193 90 154 193
42031+90 154 193 90 154 193 101 161 196 101 161 196 101 161 196 101 161 196
42032+101 161 196 136 185 209 90 154 193 26 108 161 22 40 52 13 16 17
42033+7 11 13 3 6 7 5 7 8 5 7 8 2 5 5 4 5 5
42034+4 5 5 6 6 6 3 4 3 0 0 0 30 32 34 158 157 158
42035+174 174 174 156 155 156 155 154 155 165 164 165 154 153 154 37 38 37
42036+4 0 0 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
42037+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42038+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42039+4 4 4 4 4 4
42040+4 0 0 4 0 0 60 73 81 167 166 167 174 174 174 163 162 163
42041+174 174 174 174 174 174 153 152 153 26 28 28 0 0 0 3 3 3
42042+5 5 5 4 4 4 1 1 2 7 12 15 28 67 93 18 97 151
42043+18 97 151 18 97 151 18 97 151 18 97 151 18 97 151 26 108 161
42044+26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
42045+90 154 193 26 108 161 90 154 193 90 154 193 90 154 193 101 161 196
42046+101 161 196 26 108 161 22 40 52 13 16 17 7 11 13 2 5 5
42047+2 5 5 6 6 6 2 5 5 4 5 5 4 5 5 4 5 5
42048+3 4 3 5 5 5 3 4 3 2 0 0 30 32 34 137 136 137
42049+153 152 153 137 136 137 131 129 131 137 136 137 131 129 131 37 38 37
42050+4 0 0 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
42051+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42052+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42053+4 4 4 4 4 4
42054+1 1 1 4 0 0 60 73 81 167 166 167 174 174 174 166 165 166
42055+174 174 174 177 184 187 153 152 153 30 32 34 1 0 0 3 3 3
42056+5 5 5 4 3 3 4 0 0 7 12 15 10 87 144 10 87 144
42057+18 97 151 18 97 151 18 97 151 26 108 161 26 108 161 26 108 161
42058+26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
42059+26 108 161 26 108 161 26 108 161 90 154 193 90 154 193 26 108 161
42060+35 83 115 13 16 17 7 11 13 5 7 8 3 6 7 5 7 8
42061+2 5 5 6 6 6 4 5 5 4 5 5 3 4 3 4 5 5
42062+3 4 3 6 6 6 3 4 3 0 0 0 26 28 28 125 124 125
42063+131 129 131 125 124 125 125 124 125 131 129 131 131 129 131 37 38 37
42064+4 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
42065+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42066+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42067+4 4 4 4 4 4
42068+3 1 0 4 0 0 60 73 81 174 174 174 177 184 187 167 166 167
42069+174 174 174 177 184 187 153 152 153 30 32 34 0 0 0 3 3 3
42070+5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 18 97 151
42071+18 97 151 18 97 151 18 97 151 18 97 151 18 97 151 26 108 161
42072+26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
42073+26 108 161 90 154 193 26 108 161 26 108 161 24 86 132 13 20 25
42074+7 11 13 13 20 25 22 40 52 5 7 8 3 4 3 3 4 3
42075+4 5 5 3 4 3 4 5 5 3 4 3 4 5 5 3 4 3
42076+4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 125 124 125
42077+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
42078+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
42079+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42080+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42081+4 4 4 4 4 4
42082+1 1 1 4 0 0 60 73 81 174 174 174 177 184 187 174 174 174
42083+174 174 174 190 197 201 157 156 157 30 32 34 1 0 0 3 3 3
42084+5 5 5 4 3 3 4 0 0 7 12 15 10 87 144 10 87 144
42085+18 97 151 19 95 150 19 95 150 18 97 151 18 97 151 26 108 161
42086+18 97 151 26 108 161 26 108 161 26 108 161 26 108 161 90 154 193
42087+26 108 161 26 108 161 26 108 161 22 40 52 2 5 5 3 4 3
42088+28 67 93 37 112 160 34 86 122 2 5 5 3 4 3 3 4 3
42089+3 4 3 3 4 3 3 4 3 2 2 1 3 4 3 4 4 4
42090+4 5 5 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
42091+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
42092+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
42093+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42094+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42095+4 4 4 4 4 4
42096+4 0 0 4 0 0 60 73 81 174 174 174 177 184 187 174 174 174
42097+174 174 174 190 197 201 158 157 158 30 32 34 0 0 0 2 2 2
42098+5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 18 97 151
42099+10 87 144 19 95 150 19 95 150 18 97 151 18 97 151 18 97 151
42100+26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
42101+18 97 151 22 40 52 2 5 5 2 2 1 22 40 52 26 108 161
42102+90 154 193 37 112 160 22 40 52 3 4 3 13 20 25 22 30 35
42103+3 6 7 1 1 1 2 2 2 6 9 11 5 5 5 4 3 3
42104+4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 131 129 131
42105+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
42106+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
42107+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42108+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42109+4 4 4 4 4 4
42110+1 1 1 4 0 0 60 73 81 177 184 187 193 200 203 174 174 174
42111+177 184 187 193 200 203 163 162 163 30 32 34 4 0 0 2 2 2
42112+5 5 5 4 3 3 4 0 0 6 10 14 24 86 132 10 87 144
42113+10 87 144 10 87 144 19 95 150 19 95 150 19 95 150 18 97 151
42114+26 108 161 26 108 161 26 108 161 90 154 193 26 108 161 28 67 93
42115+6 10 14 2 5 5 13 20 25 24 86 132 37 112 160 90 154 193
42116+10 87 144 7 12 15 2 5 5 28 67 93 37 112 160 28 67 93
42117+2 2 1 7 12 15 35 83 115 28 67 93 3 6 7 1 0 0
42118+4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
42119+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
42120+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
42121+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42122+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42123+4 4 4 4 4 4
42124+4 0 0 4 0 0 60 73 81 174 174 174 190 197 201 174 174 174
42125+177 184 187 193 200 203 163 162 163 30 32 34 0 0 0 2 2 2
42126+5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 10 87 144
42127+10 87 144 16 89 141 19 95 150 10 87 144 26 108 161 26 108 161
42128+26 108 161 26 108 161 26 108 161 28 67 93 6 10 14 1 1 2
42129+7 12 15 28 67 93 26 108 161 16 89 141 24 86 132 21 29 34
42130+3 4 3 21 29 34 37 112 160 37 112 160 27 99 146 21 29 34
42131+21 29 34 26 108 161 90 154 193 35 83 115 1 1 2 2 0 0
42132+4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 125 124 125
42133+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
42134+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
42135+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42136+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42137+4 4 4 4 4 4
42138+3 1 0 4 0 0 60 73 81 193 200 203 193 200 203 174 174 174
42139+190 197 201 193 200 203 165 164 165 37 38 37 4 0 0 2 2 2
42140+5 5 5 4 3 3 4 0 0 6 10 14 24 86 132 10 87 144
42141+10 87 144 10 87 144 16 89 141 18 97 151 18 97 151 10 87 144
42142+24 86 132 24 86 132 13 20 25 4 5 7 4 5 7 22 40 52
42143+18 97 151 37 112 160 26 108 161 7 12 15 1 1 1 0 0 0
42144+28 67 93 37 112 160 26 108 161 28 67 93 22 40 52 28 67 93
42145+26 108 161 90 154 193 26 108 161 10 87 144 0 0 0 2 0 0
42146+4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
42147+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
42148+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
42149+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42150+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42151+4 4 4 4 4 4
42152+4 0 0 6 6 6 60 73 81 174 174 174 193 200 203 174 174 174
42153+190 197 201 193 200 203 165 164 165 30 32 34 0 0 0 2 2 2
42154+5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 10 87 144
42155+10 87 144 10 87 144 10 87 144 18 97 151 28 67 93 6 10 14
42156+0 0 0 1 1 2 4 5 7 13 20 25 16 89 141 26 108 161
42157+26 108 161 26 108 161 24 86 132 6 9 11 2 3 3 22 40 52
42158+37 112 160 16 89 141 22 40 52 28 67 93 26 108 161 26 108 161
42159+90 154 193 26 108 161 26 108 161 28 67 93 1 1 1 4 0 0
42160+4 4 4 5 5 5 3 3 3 4 0 0 26 28 28 124 126 130
42161+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
42162+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
42163+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42164+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42165+4 4 4 4 4 4
42166+4 0 0 4 0 0 60 73 81 193 200 203 193 200 203 174 174 174
42167+193 200 203 193 200 203 167 166 167 37 38 37 4 0 0 2 2 2
42168+5 5 5 4 4 4 4 0 0 6 10 14 28 67 93 10 87 144
42169+10 87 144 10 87 144 18 97 151 10 87 144 13 20 25 4 5 7
42170+1 1 2 1 1 1 22 40 52 26 108 161 26 108 161 26 108 161
42171+26 108 161 26 108 161 26 108 161 24 86 132 22 40 52 22 40 52
42172+22 40 52 22 40 52 10 87 144 26 108 161 26 108 161 26 108 161
42173+26 108 161 26 108 161 90 154 193 10 87 144 0 0 0 4 0 0
42174+4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
42175+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
42176+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
42177+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42178+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42179+4 4 4 4 4 4
42180+4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
42181+190 197 201 205 212 215 167 166 167 30 32 34 0 0 0 2 2 2
42182+5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 10 87 144
42183+10 87 144 10 87 144 10 87 144 10 87 144 22 40 52 1 1 2
42184+2 0 0 1 1 2 24 86 132 26 108 161 26 108 161 26 108 161
42185+26 108 161 19 95 150 16 89 141 10 87 144 22 40 52 22 40 52
42186+10 87 144 26 108 161 37 112 160 26 108 161 26 108 161 26 108 161
42187+26 108 161 26 108 161 26 108 161 28 67 93 2 0 0 3 1 0
42188+4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 131 129 131
42189+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
42190+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
42191+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42192+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42193+4 4 4 4 4 4
42194+4 0 0 4 0 0 60 73 81 220 221 221 190 197 201 174 174 174
42195+193 200 203 193 200 203 174 174 174 37 38 37 4 0 0 2 2 2
42196+5 5 5 4 4 4 3 2 2 1 1 2 13 20 25 10 87 144
42197+10 87 144 10 87 144 10 87 144 10 87 144 10 87 144 13 20 25
42198+13 20 25 22 40 52 10 87 144 18 97 151 18 97 151 26 108 161
42199+10 87 144 13 20 25 6 10 14 21 29 34 24 86 132 18 97 151
42200+26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
42201+26 108 161 90 154 193 18 97 151 13 20 25 0 0 0 4 3 3
42202+4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
42203+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
42204+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
42205+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42206+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42207+4 4 4 4 4 4
42208+4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
42209+190 197 201 220 221 221 167 166 167 30 32 34 1 0 0 2 2 2
42210+5 5 5 4 4 4 4 4 5 2 5 5 4 5 7 13 20 25
42211+28 67 93 10 87 144 10 87 144 10 87 144 10 87 144 10 87 144
42212+10 87 144 10 87 144 18 97 151 10 87 144 18 97 151 18 97 151
42213+28 67 93 2 3 3 0 0 0 28 67 93 26 108 161 26 108 161
42214+26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
42215+26 108 161 10 87 144 13 20 25 1 1 2 3 2 2 4 4 4
42216+4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 131 129 131
42217+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
42218+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
42219+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42220+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42221+4 4 4 4 4 4
42222+4 0 0 4 0 0 60 73 81 220 221 221 190 197 201 174 174 174
42223+193 200 203 193 200 203 174 174 174 26 28 28 4 0 0 4 3 3
42224+5 5 5 4 4 4 4 4 4 4 4 5 1 1 2 2 5 5
42225+4 5 7 22 40 52 10 87 144 10 87 144 18 97 151 10 87 144
42226+10 87 144 10 87 144 10 87 144 10 87 144 10 87 144 18 97 151
42227+10 87 144 28 67 93 22 40 52 10 87 144 26 108 161 18 97 151
42228+18 97 151 18 97 151 26 108 161 26 108 161 26 108 161 26 108 161
42229+22 40 52 1 1 2 0 0 0 2 3 3 4 4 4 4 4 4
42230+4 4 4 5 5 5 4 4 4 0 0 0 26 28 28 131 129 131
42231+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
42232+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
42233+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42234+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42235+4 4 4 4 4 4
42236+4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
42237+190 197 201 220 221 221 190 197 201 41 54 63 4 0 0 2 2 2
42238+6 6 6 4 4 4 4 4 4 4 4 5 4 4 5 3 3 3
42239+1 1 2 1 1 2 6 10 14 22 40 52 10 87 144 18 97 151
42240+18 97 151 10 87 144 10 87 144 10 87 144 18 97 151 10 87 144
42241+10 87 144 18 97 151 26 108 161 18 97 151 18 97 151 10 87 144
42242+26 108 161 26 108 161 26 108 161 10 87 144 28 67 93 6 10 14
42243+1 1 2 1 1 2 4 3 3 4 4 5 4 4 4 4 4 4
42244+5 5 5 5 5 5 1 1 1 4 0 0 37 51 59 137 136 137
42245+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
42246+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
42247+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42248+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42249+4 4 4 4 4 4
42250+4 0 0 4 0 0 60 73 81 220 221 221 193 200 203 174 174 174
42251+193 200 203 193 200 203 220 221 221 137 136 137 13 16 17 4 0 0
42252+2 2 2 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5
42253+4 4 5 4 3 3 1 1 2 4 5 7 13 20 25 28 67 93
42254+10 87 144 10 87 144 10 87 144 10 87 144 10 87 144 10 87 144
42255+10 87 144 18 97 151 18 97 151 10 87 144 18 97 151 26 108 161
42256+26 108 161 18 97 151 28 67 93 6 10 14 0 0 0 0 0 0
42257+2 3 3 4 5 5 4 4 5 4 4 4 4 4 4 5 5 5
42258+3 3 3 1 1 1 0 0 0 16 19 21 125 124 125 137 136 137
42259+131 129 131 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
42260+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
42261+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42262+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42263+4 4 4 4 4 4
42264+4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
42265+193 200 203 190 197 201 220 221 221 220 221 221 153 152 153 30 32 34
42266+0 0 0 0 0 0 2 2 2 4 4 4 4 4 4 4 4 4
42267+4 4 4 4 5 5 4 5 7 1 1 2 1 1 2 4 5 7
42268+13 20 25 28 67 93 10 87 144 18 97 151 10 87 144 10 87 144
42269+10 87 144 10 87 144 10 87 144 18 97 151 26 108 161 18 97 151
42270+28 67 93 7 12 15 0 0 0 0 0 0 2 2 1 4 4 4
42271+4 5 5 4 5 5 4 4 4 4 4 4 3 3 3 0 0 0
42272+0 0 0 0 0 0 37 38 37 125 124 125 158 157 158 131 129 131
42273+125 124 125 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
42274+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
42275+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42276+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42277+4 4 4 4 4 4
42278+4 3 3 4 0 0 41 54 63 193 200 203 220 221 221 174 174 174
42279+193 200 203 193 200 203 193 200 203 220 221 221 244 246 246 193 200 203
42280+120 125 127 5 5 5 1 0 0 0 0 0 1 1 1 4 4 4
42281+4 4 4 4 4 4 4 5 5 4 5 5 4 4 5 1 1 2
42282+4 5 7 4 5 7 22 40 52 10 87 144 10 87 144 10 87 144
42283+10 87 144 10 87 144 18 97 151 10 87 144 10 87 144 13 20 25
42284+4 5 7 2 3 3 1 1 2 4 4 4 4 5 5 4 4 4
42285+4 4 4 4 4 4 4 4 4 1 1 1 0 0 0 1 1 2
42286+24 26 27 60 74 84 153 152 153 163 162 163 137 136 137 125 124 125
42287+125 124 125 125 124 125 125 124 125 137 136 137 125 124 125 26 28 28
42288+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
42289+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42290+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42291+4 4 4 4 4 4
42292+4 0 0 6 6 6 26 28 28 156 155 156 220 221 221 220 221 221
42293+174 174 174 193 200 203 193 200 203 193 200 203 205 212 215 220 221 221
42294+220 221 221 167 166 167 60 73 81 7 11 13 0 0 0 0 0 0
42295+3 3 3 4 4 4 4 4 4 4 4 4 4 4 5 4 4 5
42296+4 4 5 1 1 2 1 1 2 4 5 7 22 40 52 10 87 144
42297+10 87 144 10 87 144 10 87 144 22 40 52 4 5 7 1 1 2
42298+1 1 2 4 4 5 4 4 4 4 4 4 4 4 4 4 4 4
42299+5 5 5 2 2 2 0 0 0 4 0 0 16 19 21 60 73 81
42300+137 136 137 167 166 167 158 157 158 137 136 137 131 129 131 131 129 131
42301+125 124 125 125 124 125 131 129 131 155 154 155 60 74 84 5 7 8
42302+0 0 0 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42303+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42304+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42305+4 4 4 4 4 4
42306+5 5 5 4 0 0 4 0 0 60 73 81 193 200 203 220 221 221
42307+193 200 203 193 200 203 193 200 203 193 200 203 205 212 215 220 221 221
42308+220 221 221 220 221 221 220 221 221 137 136 137 43 57 68 6 6 6
42309+4 0 0 1 1 1 4 4 4 4 4 4 4 4 4 4 4 4
42310+4 4 5 4 4 5 3 2 2 1 1 2 2 5 5 13 20 25
42311+22 40 52 22 40 52 13 20 25 2 3 3 1 1 2 3 3 3
42312+4 5 7 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42313+1 1 1 0 0 0 2 3 3 41 54 63 131 129 131 166 165 166
42314+166 165 166 155 154 155 153 152 153 137 136 137 137 136 137 125 124 125
42315+125 124 125 137 136 137 137 136 137 125 124 125 37 38 37 4 3 3
42316+4 3 3 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
42317+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42318+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42319+4 4 4 4 4 4
42320+4 3 3 6 6 6 6 6 6 13 16 17 60 73 81 167 166 167
42321+220 221 221 220 221 221 220 221 221 193 200 203 193 200 203 193 200 203
42322+205 212 215 220 221 221 220 221 221 244 246 246 205 212 215 125 124 125
42323+24 26 27 0 0 0 0 0 0 2 2 2 5 5 5 5 5 5
42324+4 4 4 4 4 4 4 4 4 4 4 5 1 1 2 4 5 7
42325+4 5 7 4 5 7 1 1 2 3 2 2 4 4 5 4 4 4
42326+4 4 4 4 4 4 5 5 5 4 4 4 0 0 0 0 0 0
42327+2 0 0 26 28 28 125 124 125 174 174 174 174 174 174 166 165 166
42328+156 155 156 153 152 153 137 136 137 137 136 137 131 129 131 137 136 137
42329+137 136 137 137 136 137 60 74 84 30 32 34 4 0 0 4 0 0
42330+5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42331+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42332+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42333+4 4 4 4 4 4
42334+5 5 5 6 6 6 4 0 0 4 0 0 6 6 6 26 28 28
42335+125 124 125 174 174 174 220 221 221 220 221 221 220 221 221 193 200 203
42336+205 212 215 220 221 221 205 212 215 220 221 221 220 221 221 244 246 246
42337+193 200 203 60 74 84 13 16 17 4 0 0 0 0 0 3 3 3
42338+5 5 5 5 5 5 4 4 4 4 4 4 4 4 5 3 3 3
42339+1 1 2 3 3 3 4 4 5 4 4 5 4 4 4 4 4 4
42340+5 5 5 5 5 5 2 2 2 0 0 0 0 0 0 13 16 17
42341+60 74 84 174 174 174 193 200 203 174 174 174 167 166 167 163 162 163
42342+153 152 153 153 152 153 137 136 137 137 136 137 153 152 153 137 136 137
42343+125 124 125 41 54 63 24 26 27 4 0 0 4 0 0 5 5 5
42344+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42345+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42346+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42347+4 4 4 4 4 4
42348+4 3 3 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6
42349+6 6 6 37 38 37 131 129 131 220 221 221 220 221 221 220 221 221
42350+193 200 203 193 200 203 220 221 221 205 212 215 220 221 221 244 246 246
42351+244 246 246 244 246 246 174 174 174 41 54 63 0 0 0 0 0 0
42352+0 0 0 4 4 4 5 5 5 5 5 5 4 4 4 4 4 5
42353+4 4 5 4 4 5 4 4 4 4 4 4 6 6 6 6 6 6
42354+3 3 3 0 0 0 2 0 0 13 16 17 60 73 81 156 155 156
42355+220 221 221 193 200 203 174 174 174 165 164 165 163 162 163 154 153 154
42356+153 152 153 153 152 153 158 157 158 163 162 163 137 136 137 60 73 81
42357+13 16 17 4 0 0 4 0 0 4 3 3 4 4 4 4 4 4
42358+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42359+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42360+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42361+4 4 4 4 4 4
42362+5 5 5 4 3 3 4 3 3 6 6 6 6 6 6 6 6 6
42363+6 6 6 6 6 6 6 6 6 37 38 37 167 166 167 244 246 246
42364+244 246 246 220 221 221 205 212 215 205 212 215 220 221 221 193 200 203
42365+220 221 221 244 246 246 244 246 246 244 246 246 137 136 137 37 38 37
42366+3 2 2 0 0 0 1 1 1 5 5 5 5 5 5 4 4 4
42367+4 4 4 4 4 4 4 4 4 5 5 5 4 4 4 1 1 1
42368+0 0 0 5 5 5 43 57 68 153 152 153 193 200 203 220 221 221
42369+177 184 187 174 174 174 167 166 167 166 165 166 158 157 158 157 156 157
42370+158 157 158 166 165 166 156 155 156 85 115 134 13 16 17 4 0 0
42371+4 0 0 4 0 0 5 5 5 5 5 5 4 4 4 4 4 4
42372+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42373+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42374+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42375+4 4 4 4 4 4
42376+5 5 5 4 3 3 6 6 6 6 6 6 4 0 0 6 6 6
42377+6 6 6 6 6 6 6 6 6 6 6 6 13 16 17 60 73 81
42378+177 184 187 220 221 221 220 221 221 220 221 221 205 212 215 220 221 221
42379+220 221 221 205 212 215 220 221 221 244 246 246 244 246 246 205 212 215
42380+125 124 125 30 32 34 0 0 0 0 0 0 2 2 2 5 5 5
42381+4 4 4 4 4 4 4 4 4 1 1 1 0 0 0 1 0 0
42382+37 38 37 131 129 131 205 212 215 220 221 221 193 200 203 174 174 174
42383+174 174 174 174 174 174 167 166 167 165 164 165 166 165 166 167 166 167
42384+158 157 158 125 124 125 37 38 37 4 0 0 4 0 0 4 0 0
42385+4 3 3 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
42386+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
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
42390+4 4 4 5 5 5 4 3 3 4 3 3 6 6 6 6 6 6
42391+4 0 0 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6
42392+26 28 28 125 124 125 205 212 215 220 221 221 220 221 221 220 221 221
42393+205 212 215 220 221 221 205 212 215 220 221 221 220 221 221 244 246 246
42394+244 246 246 190 197 201 60 74 84 16 19 21 4 0 0 0 0 0
42395+0 0 0 0 0 0 0 0 0 0 0 0 16 19 21 120 125 127
42396+177 184 187 220 221 221 205 212 215 177 184 187 174 174 174 177 184 187
42397+174 174 174 174 174 174 167 166 167 174 174 174 166 165 166 137 136 137
42398+60 73 81 13 16 17 4 0 0 4 0 0 4 3 3 6 6 6
42399+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42400+4 4 4 4 4 4 4 4 4 4 4 4 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
42404+5 5 5 4 3 3 5 5 5 4 3 3 6 6 6 4 0 0
42405+6 6 6 6 6 6 4 0 0 6 6 6 4 0 0 6 6 6
42406+6 6 6 6 6 6 37 38 37 137 136 137 193 200 203 220 221 221
42407+220 221 221 205 212 215 220 221 221 205 212 215 205 212 215 220 221 221
42408+220 221 221 220 221 221 244 246 246 166 165 166 43 57 68 2 2 2
42409+0 0 0 4 0 0 16 19 21 60 73 81 157 156 157 202 210 214
42410+220 221 221 193 200 203 177 184 187 177 184 187 177 184 187 174 174 174
42411+174 174 174 174 174 174 174 174 174 157 156 157 60 74 84 24 26 27
42412+4 0 0 4 0 0 4 0 0 6 6 6 4 4 4 4 4 4
42413+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42414+4 4 4 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
42418+4 4 4 4 4 4 5 5 5 4 3 3 5 5 5 6 6 6
42419+6 6 6 4 0 0 6 6 6 6 6 6 6 6 6 4 0 0
42420+4 0 0 4 0 0 6 6 6 24 26 27 60 73 81 167 166 167
42421+220 221 221 220 221 221 220 221 221 205 212 215 205 212 215 205 212 215
42422+205 212 215 220 221 221 220 221 221 220 221 221 205 212 215 137 136 137
42423+60 74 84 125 124 125 137 136 137 190 197 201 220 221 221 193 200 203
42424+177 184 187 177 184 187 177 184 187 174 174 174 174 174 174 177 184 187
42425+190 197 201 174 174 174 125 124 125 37 38 37 6 6 6 4 0 0
42426+4 0 0 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42427+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
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
42432+4 4 4 4 4 4 5 5 5 5 5 5 4 3 3 6 6 6
42433+4 0 0 6 6 6 6 6 6 6 6 6 4 0 0 6 6 6
42434+6 6 6 6 6 6 4 0 0 4 0 0 6 6 6 6 6 6
42435+125 124 125 193 200 203 244 246 246 220 221 221 205 212 215 205 212 215
42436+205 212 215 193 200 203 205 212 215 205 212 215 220 221 221 220 221 221
42437+193 200 203 193 200 203 205 212 215 193 200 203 193 200 203 177 184 187
42438+190 197 201 190 197 201 174 174 174 190 197 201 193 200 203 190 197 201
42439+153 152 153 60 73 81 4 0 0 4 0 0 4 0 0 3 2 2
42440+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42441+4 4 4 4 4 4 4 4 4 4 4 4 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
42446+4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 4 3 3
42447+6 6 6 4 3 3 4 3 3 4 3 3 6 6 6 6 6 6
42448+4 0 0 6 6 6 6 6 6 6 6 6 4 0 0 4 0 0
42449+4 0 0 26 28 28 131 129 131 220 221 221 244 246 246 220 221 221
42450+205 212 215 193 200 203 205 212 215 193 200 203 193 200 203 205 212 215
42451+220 221 221 193 200 203 193 200 203 193 200 203 190 197 201 174 174 174
42452+174 174 174 190 197 201 193 200 203 193 200 203 167 166 167 125 124 125
42453+6 6 6 4 0 0 4 0 0 4 3 3 4 4 4 4 4 4
42454+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42455+4 4 4 4 4 4 4 4 4 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
42460+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
42461+5 5 5 4 3 3 5 5 5 6 6 6 4 3 3 5 5 5
42462+6 6 6 6 6 6 4 0 0 6 6 6 6 6 6 6 6 6
42463+4 0 0 4 0 0 6 6 6 41 54 63 158 157 158 220 221 221
42464+220 221 221 220 221 221 193 200 203 193 200 203 193 200 203 190 197 201
42465+190 197 201 190 197 201 190 197 201 190 197 201 174 174 174 193 200 203
42466+193 200 203 220 221 221 174 174 174 125 124 125 37 38 37 4 0 0
42467+4 0 0 4 3 3 6 6 6 4 4 4 4 4 4 4 4 4
42468+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42469+4 4 4 4 4 4 4 4 4 4 4 4 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
42474+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42475+4 4 4 5 5 5 4 3 3 4 3 3 4 3 3 5 5 5
42476+4 3 3 6 6 6 5 5 5 4 3 3 6 6 6 6 6 6
42477+6 6 6 6 6 6 4 0 0 4 0 0 13 16 17 60 73 81
42478+174 174 174 220 221 221 220 221 221 205 212 215 190 197 201 174 174 174
42479+193 200 203 174 174 174 190 197 201 174 174 174 193 200 203 220 221 221
42480+193 200 203 131 129 131 37 38 37 6 6 6 4 0 0 4 0 0
42481+6 6 6 6 6 6 4 3 3 5 5 5 4 4 4 4 4 4
42482+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42483+4 4 4 4 4 4 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
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 4 4 4 5 5 5 5 5 5 5 5 5
42490+5 5 5 4 3 3 4 3 3 5 5 5 4 3 3 4 3 3
42491+5 5 5 6 6 6 6 6 6 4 0 0 6 6 6 6 6 6
42492+6 6 6 125 124 125 174 174 174 220 221 221 220 221 221 193 200 203
42493+193 200 203 193 200 203 193 200 203 193 200 203 220 221 221 158 157 158
42494+60 73 81 6 6 6 4 0 0 4 0 0 5 5 5 6 6 6
42495+5 5 5 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
42496+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42497+4 4 4 4 4 4 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
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 4 4 4 4 4 4 4 4 4 4 4 4
42504+4 4 4 5 5 5 5 5 5 4 3 3 5 5 5 4 3 3
42505+5 5 5 5 5 5 6 6 6 6 6 6 4 0 0 4 0 0
42506+4 0 0 4 0 0 26 28 28 125 124 125 174 174 174 193 200 203
42507+193 200 203 174 174 174 193 200 203 167 166 167 125 124 125 6 6 6
42508+6 6 6 6 6 6 4 0 0 6 6 6 6 6 6 5 5 5
42509+4 3 3 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
42510+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
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
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 4 4 4 4 4 4 4 4 4 4 4 4
42518+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
42519+4 3 3 6 6 6 4 0 0 6 6 6 6 6 6 6 6 6
42520+6 6 6 4 0 0 4 0 0 6 6 6 37 38 37 125 124 125
42521+153 152 153 131 129 131 125 124 125 37 38 37 6 6 6 6 6 6
42522+6 6 6 4 0 0 6 6 6 6 6 6 4 3 3 5 5 5
42523+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42524+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
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
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 4 4 4 4 4 4 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 5 5 5 5 5 5 4 3 3 5 5 5 4 3 3
42534+6 6 6 6 6 6 4 0 0 4 0 0 6 6 6 6 6 6
42535+24 26 27 24 26 27 6 6 6 6 6 6 6 6 6 4 0 0
42536+6 6 6 6 6 6 4 0 0 6 6 6 5 5 5 4 3 3
42537+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42538+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 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
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 4 4 4 4 4 4 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 5 5 5 4 3 3 5 5 5 6 6 6
42548+4 0 0 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6
42549+6 6 6 6 6 6 6 6 6 4 0 0 6 6 6 6 6 6
42550+4 0 0 6 6 6 6 6 6 4 3 3 5 5 5 4 4 4
42551+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42552+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 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
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 4 4 4 4 4 4 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 5 5 5 4 3 3 5 5 5
42562+5 5 5 5 5 5 4 0 0 6 6 6 4 0 0 6 6 6
42563+6 6 6 6 6 6 6 6 6 4 0 0 6 6 6 4 0 0
42564+6 6 6 4 3 3 5 5 5 4 3 3 5 5 5 4 4 4
42565+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42566+4 4 4 4 4 4 4 4 4 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
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 4 4 4 4 4 4 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 5 5 5
42576+4 3 3 6 6 6 4 3 3 6 6 6 6 6 6 6 6 6
42577+4 0 0 6 6 6 4 0 0 6 6 6 6 6 6 6 6 6
42578+6 6 6 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
42579+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42580+4 4 4 4 4 4 4 4 4 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
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 4 4 4 4 4 4 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 5 5 5 4 3 3 5 5 5 4 0 0 6 6 6
42591+6 6 6 4 0 0 6 6 6 6 6 6 4 0 0 6 6 6
42592+4 3 3 5 5 5 5 5 5 4 4 4 4 4 4 4 4 4
42593+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42594+4 4 4 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
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 4 4 4 4 4 4 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 5 5 5 4 3 3 5 5 5 6 6 6 4 3 3
42605+4 3 3 6 6 6 6 6 6 4 3 3 6 6 6 4 3 3
42606+5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42607+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
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
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 4 4 4 4 4 4 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 5 5 5 4 3 3 6 6 6
42619+5 5 5 4 3 3 4 3 3 4 3 3 5 5 5 5 5 5
42620+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42621+4 4 4 4 4 4 4 4 4 4 4 4 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
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 4 4 4 4 4 4 4 4 4 4 4 4
42630+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42631+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42632+4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 4 3 3
42633+5 5 5 4 3 3 5 5 5 5 5 5 4 4 4 4 4 4
42634+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42635+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42636+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42637+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42638+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42639+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42640+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42641+4 4 4 4 4 4
42642diff --git a/drivers/video/udlfb.c b/drivers/video/udlfb.c
42643index 38fcfff..0072dcd 100644
42644--- a/drivers/video/udlfb.c
42645+++ b/drivers/video/udlfb.c
42646@@ -620,11 +620,11 @@ int dlfb_handle_damage(struct dlfb_data *dev, int x, int y,
42647 dlfb_urb_completion(urb);
42648
42649 error:
42650- atomic_add(bytes_sent, &dev->bytes_sent);
42651- atomic_add(bytes_identical, &dev->bytes_identical);
42652- atomic_add(width*height*2, &dev->bytes_rendered);
42653+ atomic_add_unchecked(bytes_sent, &dev->bytes_sent);
42654+ atomic_add_unchecked(bytes_identical, &dev->bytes_identical);
42655+ atomic_add_unchecked(width*height*2, &dev->bytes_rendered);
42656 end_cycles = get_cycles();
42657- atomic_add(((unsigned int) ((end_cycles - start_cycles)
42658+ atomic_add_unchecked(((unsigned int) ((end_cycles - start_cycles)
42659 >> 10)), /* Kcycles */
42660 &dev->cpu_kcycles_used);
42661
42662@@ -745,11 +745,11 @@ static void dlfb_dpy_deferred_io(struct fb_info *info,
42663 dlfb_urb_completion(urb);
42664
42665 error:
42666- atomic_add(bytes_sent, &dev->bytes_sent);
42667- atomic_add(bytes_identical, &dev->bytes_identical);
42668- atomic_add(bytes_rendered, &dev->bytes_rendered);
42669+ atomic_add_unchecked(bytes_sent, &dev->bytes_sent);
42670+ atomic_add_unchecked(bytes_identical, &dev->bytes_identical);
42671+ atomic_add_unchecked(bytes_rendered, &dev->bytes_rendered);
42672 end_cycles = get_cycles();
42673- atomic_add(((unsigned int) ((end_cycles - start_cycles)
42674+ atomic_add_unchecked(((unsigned int) ((end_cycles - start_cycles)
42675 >> 10)), /* Kcycles */
42676 &dev->cpu_kcycles_used);
42677 }
42678@@ -1373,7 +1373,7 @@ static ssize_t metrics_bytes_rendered_show(struct device *fbdev,
42679 struct fb_info *fb_info = dev_get_drvdata(fbdev);
42680 struct dlfb_data *dev = fb_info->par;
42681 return snprintf(buf, PAGE_SIZE, "%u\n",
42682- atomic_read(&dev->bytes_rendered));
42683+ atomic_read_unchecked(&dev->bytes_rendered));
42684 }
42685
42686 static ssize_t metrics_bytes_identical_show(struct device *fbdev,
42687@@ -1381,7 +1381,7 @@ static ssize_t metrics_bytes_identical_show(struct device *fbdev,
42688 struct fb_info *fb_info = dev_get_drvdata(fbdev);
42689 struct dlfb_data *dev = fb_info->par;
42690 return snprintf(buf, PAGE_SIZE, "%u\n",
42691- atomic_read(&dev->bytes_identical));
42692+ atomic_read_unchecked(&dev->bytes_identical));
42693 }
42694
42695 static ssize_t metrics_bytes_sent_show(struct device *fbdev,
42696@@ -1389,7 +1389,7 @@ static ssize_t metrics_bytes_sent_show(struct device *fbdev,
42697 struct fb_info *fb_info = dev_get_drvdata(fbdev);
42698 struct dlfb_data *dev = fb_info->par;
42699 return snprintf(buf, PAGE_SIZE, "%u\n",
42700- atomic_read(&dev->bytes_sent));
42701+ atomic_read_unchecked(&dev->bytes_sent));
42702 }
42703
42704 static ssize_t metrics_cpu_kcycles_used_show(struct device *fbdev,
42705@@ -1397,7 +1397,7 @@ static ssize_t metrics_cpu_kcycles_used_show(struct device *fbdev,
42706 struct fb_info *fb_info = dev_get_drvdata(fbdev);
42707 struct dlfb_data *dev = fb_info->par;
42708 return snprintf(buf, PAGE_SIZE, "%u\n",
42709- atomic_read(&dev->cpu_kcycles_used));
42710+ atomic_read_unchecked(&dev->cpu_kcycles_used));
42711 }
42712
42713 static ssize_t edid_show(
42714@@ -1457,10 +1457,10 @@ static ssize_t metrics_reset_store(struct device *fbdev,
42715 struct fb_info *fb_info = dev_get_drvdata(fbdev);
42716 struct dlfb_data *dev = fb_info->par;
42717
42718- atomic_set(&dev->bytes_rendered, 0);
42719- atomic_set(&dev->bytes_identical, 0);
42720- atomic_set(&dev->bytes_sent, 0);
42721- atomic_set(&dev->cpu_kcycles_used, 0);
42722+ atomic_set_unchecked(&dev->bytes_rendered, 0);
42723+ atomic_set_unchecked(&dev->bytes_identical, 0);
42724+ atomic_set_unchecked(&dev->bytes_sent, 0);
42725+ atomic_set_unchecked(&dev->cpu_kcycles_used, 0);
42726
42727 return count;
42728 }
42729diff --git a/drivers/video/uvesafb.c b/drivers/video/uvesafb.c
42730index b0e2a42..e2df3ad 100644
42731--- a/drivers/video/uvesafb.c
42732+++ b/drivers/video/uvesafb.c
42733@@ -19,6 +19,7 @@
42734 #include <linux/io.h>
42735 #include <linux/mutex.h>
42736 #include <linux/slab.h>
42737+#include <linux/moduleloader.h>
42738 #include <video/edid.h>
42739 #include <video/uvesafb.h>
42740 #ifdef CONFIG_X86
42741@@ -569,10 +570,32 @@ static int __devinit uvesafb_vbe_getpmi(struct uvesafb_ktask *task,
42742 if ((task->t.regs.eax & 0xffff) != 0x4f || task->t.regs.es < 0xc000) {
42743 par->pmi_setpal = par->ypan = 0;
42744 } else {
42745+
42746+#ifdef CONFIG_PAX_KERNEXEC
42747+#ifdef CONFIG_MODULES
42748+ par->pmi_code = module_alloc_exec((u16)task->t.regs.ecx);
42749+#endif
42750+ if (!par->pmi_code) {
42751+ par->pmi_setpal = par->ypan = 0;
42752+ return 0;
42753+ }
42754+#endif
42755+
42756 par->pmi_base = (u16 *)phys_to_virt(((u32)task->t.regs.es << 4)
42757 + task->t.regs.edi);
42758+
42759+#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
42760+ pax_open_kernel();
42761+ memcpy(par->pmi_code, par->pmi_base, (u16)task->t.regs.ecx);
42762+ pax_close_kernel();
42763+
42764+ par->pmi_start = ktva_ktla(par->pmi_code + par->pmi_base[1]);
42765+ par->pmi_pal = ktva_ktla(par->pmi_code + par->pmi_base[2]);
42766+#else
42767 par->pmi_start = (u8 *)par->pmi_base + par->pmi_base[1];
42768 par->pmi_pal = (u8 *)par->pmi_base + par->pmi_base[2];
42769+#endif
42770+
42771 printk(KERN_INFO "uvesafb: protected mode interface info at "
42772 "%04x:%04x\n",
42773 (u16)task->t.regs.es, (u16)task->t.regs.edi);
42774@@ -816,13 +839,14 @@ static int __devinit uvesafb_vbe_init(struct fb_info *info)
42775 par->ypan = ypan;
42776
42777 if (par->pmi_setpal || par->ypan) {
42778+#if !defined(CONFIG_MODULES) || !defined(CONFIG_PAX_KERNEXEC)
42779 if (__supported_pte_mask & _PAGE_NX) {
42780 par->pmi_setpal = par->ypan = 0;
42781 printk(KERN_WARNING "uvesafb: NX protection is actively."
42782 "We have better not to use the PMI.\n");
42783- } else {
42784+ } else
42785+#endif
42786 uvesafb_vbe_getpmi(task, par);
42787- }
42788 }
42789 #else
42790 /* The protected mode interface is not available on non-x86. */
42791@@ -1836,6 +1860,11 @@ out:
42792 if (par->vbe_modes)
42793 kfree(par->vbe_modes);
42794
42795+#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
42796+ if (par->pmi_code)
42797+ module_free_exec(NULL, par->pmi_code);
42798+#endif
42799+
42800 framebuffer_release(info);
42801 return err;
42802 }
42803@@ -1862,6 +1891,12 @@ static int uvesafb_remove(struct platform_device *dev)
42804 kfree(par->vbe_state_orig);
42805 if (par->vbe_state_saved)
42806 kfree(par->vbe_state_saved);
42807+
42808+#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
42809+ if (par->pmi_code)
42810+ module_free_exec(NULL, par->pmi_code);
42811+#endif
42812+
42813 }
42814
42815 framebuffer_release(info);
42816diff --git a/drivers/video/vesafb.c b/drivers/video/vesafb.c
42817index 501b340..86bd4cf 100644
42818--- a/drivers/video/vesafb.c
42819+++ b/drivers/video/vesafb.c
42820@@ -9,6 +9,7 @@
42821 */
42822
42823 #include <linux/module.h>
42824+#include <linux/moduleloader.h>
42825 #include <linux/kernel.h>
42826 #include <linux/errno.h>
42827 #include <linux/string.h>
42828@@ -52,8 +53,8 @@ static int vram_remap __initdata; /* Set amount of memory to be used */
42829 static int vram_total __initdata; /* Set total amount of memory */
42830 static int pmi_setpal __read_mostly = 1; /* pmi for palette changes ??? */
42831 static int ypan __read_mostly; /* 0..nothing, 1..ypan, 2..ywrap */
42832-static void (*pmi_start)(void) __read_mostly;
42833-static void (*pmi_pal) (void) __read_mostly;
42834+static void (*pmi_start)(void) __read_only;
42835+static void (*pmi_pal) (void) __read_only;
42836 static int depth __read_mostly;
42837 static int vga_compat __read_mostly;
42838 /* --------------------------------------------------------------------- */
42839@@ -233,6 +234,7 @@ static int __init vesafb_probe(struct platform_device *dev)
42840 unsigned int size_vmode;
42841 unsigned int size_remap;
42842 unsigned int size_total;
42843+ void *pmi_code = NULL;
42844
42845 if (screen_info.orig_video_isVGA != VIDEO_TYPE_VLFB)
42846 return -ENODEV;
42847@@ -275,10 +277,6 @@ static int __init vesafb_probe(struct platform_device *dev)
42848 size_remap = size_total;
42849 vesafb_fix.smem_len = size_remap;
42850
42851-#ifndef __i386__
42852- screen_info.vesapm_seg = 0;
42853-#endif
42854-
42855 if (!request_mem_region(vesafb_fix.smem_start, size_total, "vesafb")) {
42856 printk(KERN_WARNING
42857 "vesafb: cannot reserve video memory at 0x%lx\n",
42858@@ -307,9 +305,21 @@ static int __init vesafb_probe(struct platform_device *dev)
42859 printk(KERN_INFO "vesafb: mode is %dx%dx%d, linelength=%d, pages=%d\n",
42860 vesafb_defined.xres, vesafb_defined.yres, vesafb_defined.bits_per_pixel, vesafb_fix.line_length, screen_info.pages);
42861
42862+#ifdef __i386__
42863+
42864+#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
42865+ pmi_code = module_alloc_exec(screen_info.vesapm_size);
42866+ if (!pmi_code)
42867+#elif !defined(CONFIG_PAX_KERNEXEC)
42868+ if (0)
42869+#endif
42870+
42871+#endif
42872+ screen_info.vesapm_seg = 0;
42873+
42874 if (screen_info.vesapm_seg) {
42875- printk(KERN_INFO "vesafb: protected mode interface info at %04x:%04x\n",
42876- screen_info.vesapm_seg,screen_info.vesapm_off);
42877+ printk(KERN_INFO "vesafb: protected mode interface info at %04x:%04x %04x bytes\n",
42878+ screen_info.vesapm_seg,screen_info.vesapm_off,screen_info.vesapm_size);
42879 }
42880
42881 if (screen_info.vesapm_seg < 0xc000)
42882@@ -317,9 +327,25 @@ static int __init vesafb_probe(struct platform_device *dev)
42883
42884 if (ypan || pmi_setpal) {
42885 unsigned short *pmi_base;
42886+
42887 pmi_base = (unsigned short*)phys_to_virt(((unsigned long)screen_info.vesapm_seg << 4) + screen_info.vesapm_off);
42888- pmi_start = (void*)((char*)pmi_base + pmi_base[1]);
42889- pmi_pal = (void*)((char*)pmi_base + pmi_base[2]);
42890+
42891+#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
42892+ pax_open_kernel();
42893+ memcpy(pmi_code, pmi_base, screen_info.vesapm_size);
42894+#else
42895+ pmi_code = pmi_base;
42896+#endif
42897+
42898+ pmi_start = (void*)((char*)pmi_code + pmi_base[1]);
42899+ pmi_pal = (void*)((char*)pmi_code + pmi_base[2]);
42900+
42901+#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
42902+ pmi_start = ktva_ktla(pmi_start);
42903+ pmi_pal = ktva_ktla(pmi_pal);
42904+ pax_close_kernel();
42905+#endif
42906+
42907 printk(KERN_INFO "vesafb: pmi: set display start = %p, set palette = %p\n",pmi_start,pmi_pal);
42908 if (pmi_base[3]) {
42909 printk(KERN_INFO "vesafb: pmi: ports = ");
42910@@ -488,6 +514,11 @@ static int __init vesafb_probe(struct platform_device *dev)
42911 info->node, info->fix.id);
42912 return 0;
42913 err:
42914+
42915+#if defined(__i386__) && defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
42916+ module_free_exec(NULL, pmi_code);
42917+#endif
42918+
42919 if (info->screen_base)
42920 iounmap(info->screen_base);
42921 framebuffer_release(info);
42922diff --git a/drivers/video/via/via_clock.h b/drivers/video/via/via_clock.h
42923index 88714ae..16c2e11 100644
42924--- a/drivers/video/via/via_clock.h
42925+++ b/drivers/video/via/via_clock.h
42926@@ -56,7 +56,7 @@ struct via_clock {
42927
42928 void (*set_engine_pll_state)(u8 state);
42929 void (*set_engine_pll)(struct via_pll_config config);
42930-};
42931+} __no_const;
42932
42933
42934 static inline u32 get_pll_internal_frequency(u32 ref_freq,
42935diff --git a/drivers/virtio/virtio.c b/drivers/virtio/virtio.c
42936index c3b3f7f..abd47c7 100644
42937--- a/drivers/virtio/virtio.c
42938+++ b/drivers/virtio/virtio.c
42939@@ -225,8 +225,10 @@ EXPORT_SYMBOL_GPL(register_virtio_device);
42940
42941 void unregister_virtio_device(struct virtio_device *dev)
42942 {
42943+ int index = dev->index; /* save for after device release */
42944+
42945 device_unregister(&dev->dev);
42946- ida_simple_remove(&virtio_index_ida, dev->index);
42947+ ida_simple_remove(&virtio_index_ida, index);
42948 }
42949 EXPORT_SYMBOL_GPL(unregister_virtio_device);
42950
42951diff --git a/drivers/virtio/virtio_mmio.c b/drivers/virtio/virtio_mmio.c
42952index 453db0c..604973e 100644
42953--- a/drivers/virtio/virtio_mmio.c
42954+++ b/drivers/virtio/virtio_mmio.c
42955@@ -521,7 +521,7 @@ static int vm_cmdline_set(const char *device,
42956
42957 resources[0].end = memparse(device, &str) - 1;
42958
42959- processed = sscanf(str, "@%lli:%u%n:%d%n",
42960+ processed = sscanf(str, "@%lli:%llu%n:%d%n",
42961 &base, &resources[1].start, &consumed,
42962 &vm_cmdline_id, &consumed);
42963
42964diff --git a/drivers/xen/xen-pciback/conf_space.h b/drivers/xen/xen-pciback/conf_space.h
42965index e56c934..fc22f4b 100644
42966--- a/drivers/xen/xen-pciback/conf_space.h
42967+++ b/drivers/xen/xen-pciback/conf_space.h
42968@@ -44,15 +44,15 @@ struct config_field {
42969 struct {
42970 conf_dword_write write;
42971 conf_dword_read read;
42972- } dw;
42973+ } __no_const dw;
42974 struct {
42975 conf_word_write write;
42976 conf_word_read read;
42977- } w;
42978+ } __no_const w;
42979 struct {
42980 conf_byte_write write;
42981 conf_byte_read read;
42982- } b;
42983+ } __no_const b;
42984 } u;
42985 struct list_head list;
42986 };
42987diff --git a/drivers/xen/xenbus/xenbus_dev_frontend.c b/drivers/xen/xenbus/xenbus_dev_frontend.c
42988index 89f7625..ac72702 100644
42989--- a/drivers/xen/xenbus/xenbus_dev_frontend.c
42990+++ b/drivers/xen/xenbus/xenbus_dev_frontend.c
42991@@ -458,7 +458,7 @@ static ssize_t xenbus_file_write(struct file *filp,
42992 goto out;
42993
42994 /* Can't write a xenbus message larger we can buffer */
42995- if ((len + u->len) > sizeof(u->u.buffer)) {
42996+ if (len > sizeof(u->u.buffer) - u->len) {
42997 /* On error, dump existing buffer */
42998 u->len = 0;
42999 rc = -EINVAL;
43000diff --git a/drivers/xen/xenfs/xenstored.c b/drivers/xen/xenfs/xenstored.c
43001index fef20db..d28b1ab 100644
43002--- a/drivers/xen/xenfs/xenstored.c
43003+++ b/drivers/xen/xenfs/xenstored.c
43004@@ -24,7 +24,12 @@ static int xsd_release(struct inode *inode, struct file *file)
43005 static int xsd_kva_open(struct inode *inode, struct file *file)
43006 {
43007 file->private_data = (void *)kasprintf(GFP_KERNEL, "0x%p",
43008+#ifdef CONFIG_GRKERNSEC_HIDESYM
43009+ NULL);
43010+#else
43011 xen_store_interface);
43012+#endif
43013+
43014 if (!file->private_data)
43015 return -ENOMEM;
43016 return 0;
43017diff --git a/fs/9p/vfs_inode.c b/fs/9p/vfs_inode.c
43018index cbf9dbb..35c3af7 100644
43019--- a/fs/9p/vfs_inode.c
43020+++ b/fs/9p/vfs_inode.c
43021@@ -1329,7 +1329,7 @@ static void *v9fs_vfs_follow_link(struct dentry *dentry, struct nameidata *nd)
43022 void
43023 v9fs_vfs_put_link(struct dentry *dentry, struct nameidata *nd, void *p)
43024 {
43025- char *s = nd_get_link(nd);
43026+ const char *s = nd_get_link(nd);
43027
43028 p9_debug(P9_DEBUG_VFS, " %s %s\n",
43029 dentry->d_name.name, IS_ERR(s) ? "<error>" : s);
43030diff --git a/fs/Kconfig.binfmt b/fs/Kconfig.binfmt
43031index 0225742..1cd4732 100644
43032--- a/fs/Kconfig.binfmt
43033+++ b/fs/Kconfig.binfmt
43034@@ -89,7 +89,7 @@ config HAVE_AOUT
43035
43036 config BINFMT_AOUT
43037 tristate "Kernel support for a.out and ECOFF binaries"
43038- depends on HAVE_AOUT
43039+ depends on HAVE_AOUT && BROKEN
43040 ---help---
43041 A.out (Assembler.OUTput) is a set of formats for libraries and
43042 executables used in the earliest versions of UNIX. Linux used
43043diff --git a/fs/aio.c b/fs/aio.c
43044index 71f613c..9d01f1f 100644
43045--- a/fs/aio.c
43046+++ b/fs/aio.c
43047@@ -111,7 +111,7 @@ static int aio_setup_ring(struct kioctx *ctx)
43048 size += sizeof(struct io_event) * nr_events;
43049 nr_pages = (size + PAGE_SIZE-1) >> PAGE_SHIFT;
43050
43051- if (nr_pages < 0)
43052+ if (nr_pages <= 0)
43053 return -EINVAL;
43054
43055 nr_events = (PAGE_SIZE * nr_pages - sizeof(struct aio_ring)) / sizeof(struct io_event);
43056@@ -1373,18 +1373,19 @@ static ssize_t aio_fsync(struct kiocb *iocb)
43057 static ssize_t aio_setup_vectored_rw(int type, struct kiocb *kiocb, bool compat)
43058 {
43059 ssize_t ret;
43060+ struct iovec iovstack;
43061
43062 #ifdef CONFIG_COMPAT
43063 if (compat)
43064 ret = compat_rw_copy_check_uvector(type,
43065 (struct compat_iovec __user *)kiocb->ki_buf,
43066- kiocb->ki_nbytes, 1, &kiocb->ki_inline_vec,
43067+ kiocb->ki_nbytes, 1, &iovstack,
43068 &kiocb->ki_iovec);
43069 else
43070 #endif
43071 ret = rw_copy_check_uvector(type,
43072 (struct iovec __user *)kiocb->ki_buf,
43073- kiocb->ki_nbytes, 1, &kiocb->ki_inline_vec,
43074+ kiocb->ki_nbytes, 1, &iovstack,
43075 &kiocb->ki_iovec);
43076 if (ret < 0)
43077 goto out;
43078@@ -1393,6 +1394,10 @@ static ssize_t aio_setup_vectored_rw(int type, struct kiocb *kiocb, bool compat)
43079 if (ret < 0)
43080 goto out;
43081
43082+ if (kiocb->ki_iovec == &iovstack) {
43083+ kiocb->ki_inline_vec = iovstack;
43084+ kiocb->ki_iovec = &kiocb->ki_inline_vec;
43085+ }
43086 kiocb->ki_nr_segs = kiocb->ki_nbytes;
43087 kiocb->ki_cur_seg = 0;
43088 /* ki_nbytes/left now reflect bytes instead of segs */
43089diff --git a/fs/attr.c b/fs/attr.c
43090index 29e38a1..2bc037b 100644
43091--- a/fs/attr.c
43092+++ b/fs/attr.c
43093@@ -99,6 +99,7 @@ int inode_newsize_ok(const struct inode *inode, loff_t offset)
43094 unsigned long limit;
43095
43096 limit = rlimit(RLIMIT_FSIZE);
43097+ gr_learn_resource(current, RLIMIT_FSIZE, (unsigned long)offset, 1);
43098 if (limit != RLIM_INFINITY && offset > limit)
43099 goto out_sig;
43100 if (offset > inode->i_sb->s_maxbytes)
43101diff --git a/fs/autofs4/waitq.c b/fs/autofs4/waitq.c
43102index da8876d..4456166 100644
43103--- a/fs/autofs4/waitq.c
43104+++ b/fs/autofs4/waitq.c
43105@@ -61,7 +61,7 @@ static int autofs4_write(struct autofs_sb_info *sbi,
43106 {
43107 unsigned long sigpipe, flags;
43108 mm_segment_t fs;
43109- const char *data = (const char *)addr;
43110+ const char __user *data = (const char __force_user *)addr;
43111 ssize_t wr = 0;
43112
43113 sigpipe = sigismember(&current->pending.signal, SIGPIPE);
43114@@ -348,6 +348,10 @@ static int validate_request(struct autofs_wait_queue **wait,
43115 return 1;
43116 }
43117
43118+#ifdef CONFIG_GRKERNSEC_HIDESYM
43119+static atomic_unchecked_t autofs_dummy_name_id = ATOMIC_INIT(0);
43120+#endif
43121+
43122 int autofs4_wait(struct autofs_sb_info *sbi, struct dentry *dentry,
43123 enum autofs_notify notify)
43124 {
43125@@ -381,7 +385,12 @@ int autofs4_wait(struct autofs_sb_info *sbi, struct dentry *dentry,
43126
43127 /* If this is a direct mount request create a dummy name */
43128 if (IS_ROOT(dentry) && autofs_type_trigger(sbi->type))
43129+#ifdef CONFIG_GRKERNSEC_HIDESYM
43130+ /* this name does get written to userland via autofs4_write() */
43131+ qstr.len = sprintf(name, "%08lx", atomic_inc_return_unchecked(&autofs_dummy_name_id));
43132+#else
43133 qstr.len = sprintf(name, "%p", dentry);
43134+#endif
43135 else {
43136 qstr.len = autofs4_getpath(sbi, dentry, &name);
43137 if (!qstr.len) {
43138diff --git a/fs/befs/linuxvfs.c b/fs/befs/linuxvfs.c
43139index cf7f3c6..f61080d 100644
43140--- a/fs/befs/linuxvfs.c
43141+++ b/fs/befs/linuxvfs.c
43142@@ -502,7 +502,7 @@ static void befs_put_link(struct dentry *dentry, struct nameidata *nd, void *p)
43143 {
43144 befs_inode_info *befs_ino = BEFS_I(dentry->d_inode);
43145 if (befs_ino->i_flags & BEFS_LONG_SYMLINK) {
43146- char *link = nd_get_link(nd);
43147+ const char *link = nd_get_link(nd);
43148 if (!IS_ERR(link))
43149 kfree(link);
43150 }
43151diff --git a/fs/binfmt_aout.c b/fs/binfmt_aout.c
43152index d146e18..12d1bd1 100644
43153--- a/fs/binfmt_aout.c
43154+++ b/fs/binfmt_aout.c
43155@@ -16,6 +16,7 @@
43156 #include <linux/string.h>
43157 #include <linux/fs.h>
43158 #include <linux/file.h>
43159+#include <linux/security.h>
43160 #include <linux/stat.h>
43161 #include <linux/fcntl.h>
43162 #include <linux/ptrace.h>
43163@@ -83,6 +84,8 @@ static int aout_core_dump(struct coredump_params *cprm)
43164 #endif
43165 # define START_STACK(u) ((void __user *)u.start_stack)
43166
43167+ memset(&dump, 0, sizeof(dump));
43168+
43169 fs = get_fs();
43170 set_fs(KERNEL_DS);
43171 has_dumped = 1;
43172@@ -94,10 +97,12 @@ static int aout_core_dump(struct coredump_params *cprm)
43173
43174 /* If the size of the dump file exceeds the rlimit, then see what would happen
43175 if we wrote the stack, but not the data area. */
43176+ gr_learn_resource(current, RLIMIT_CORE, (dump.u_dsize + dump.u_ssize+1) * PAGE_SIZE, 1);
43177 if ((dump.u_dsize + dump.u_ssize+1) * PAGE_SIZE > cprm->limit)
43178 dump.u_dsize = 0;
43179
43180 /* Make sure we have enough room to write the stack and data areas. */
43181+ gr_learn_resource(current, RLIMIT_CORE, (dump.u_ssize + 1) * PAGE_SIZE, 1);
43182 if ((dump.u_ssize + 1) * PAGE_SIZE > cprm->limit)
43183 dump.u_ssize = 0;
43184
43185@@ -231,6 +236,8 @@ static int load_aout_binary(struct linux_binprm * bprm, struct pt_regs * regs)
43186 rlim = rlimit(RLIMIT_DATA);
43187 if (rlim >= RLIM_INFINITY)
43188 rlim = ~0;
43189+
43190+ gr_learn_resource(current, RLIMIT_DATA, ex.a_data + ex.a_bss, 1);
43191 if (ex.a_data + ex.a_bss > rlim)
43192 return -ENOMEM;
43193
43194@@ -265,6 +272,27 @@ static int load_aout_binary(struct linux_binprm * bprm, struct pt_regs * regs)
43195
43196 install_exec_creds(bprm);
43197
43198+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
43199+ current->mm->pax_flags = 0UL;
43200+#endif
43201+
43202+#ifdef CONFIG_PAX_PAGEEXEC
43203+ if (!(N_FLAGS(ex) & F_PAX_PAGEEXEC)) {
43204+ current->mm->pax_flags |= MF_PAX_PAGEEXEC;
43205+
43206+#ifdef CONFIG_PAX_EMUTRAMP
43207+ if (N_FLAGS(ex) & F_PAX_EMUTRAMP)
43208+ current->mm->pax_flags |= MF_PAX_EMUTRAMP;
43209+#endif
43210+
43211+#ifdef CONFIG_PAX_MPROTECT
43212+ if (!(N_FLAGS(ex) & F_PAX_MPROTECT))
43213+ current->mm->pax_flags |= MF_PAX_MPROTECT;
43214+#endif
43215+
43216+ }
43217+#endif
43218+
43219 if (N_MAGIC(ex) == OMAGIC) {
43220 unsigned long text_addr, map_size;
43221 loff_t pos;
43222@@ -330,7 +358,7 @@ static int load_aout_binary(struct linux_binprm * bprm, struct pt_regs * regs)
43223 }
43224
43225 error = vm_mmap(bprm->file, N_DATADDR(ex), ex.a_data,
43226- PROT_READ | PROT_WRITE | PROT_EXEC,
43227+ PROT_READ | PROT_WRITE,
43228 MAP_FIXED | MAP_PRIVATE | MAP_DENYWRITE | MAP_EXECUTABLE,
43229 fd_offset + ex.a_text);
43230 if (error != N_DATADDR(ex)) {
43231diff --git a/fs/binfmt_elf.c b/fs/binfmt_elf.c
43232index 0225fdd..0c0d35d 100644
43233--- a/fs/binfmt_elf.c
43234+++ b/fs/binfmt_elf.c
43235@@ -32,6 +32,7 @@
43236 #include <linux/elf.h>
43237 #include <linux/utsname.h>
43238 #include <linux/coredump.h>
43239+#include <linux/xattr.h>
43240 #include <asm/uaccess.h>
43241 #include <asm/param.h>
43242 #include <asm/page.h>
43243@@ -52,6 +53,10 @@ static int elf_core_dump(struct coredump_params *cprm);
43244 #define elf_core_dump NULL
43245 #endif
43246
43247+#ifdef CONFIG_PAX_MPROTECT
43248+static void elf_handle_mprotect(struct vm_area_struct *vma, unsigned long newflags);
43249+#endif
43250+
43251 #if ELF_EXEC_PAGESIZE > PAGE_SIZE
43252 #define ELF_MIN_ALIGN ELF_EXEC_PAGESIZE
43253 #else
43254@@ -71,6 +76,11 @@ static struct linux_binfmt elf_format = {
43255 .load_binary = load_elf_binary,
43256 .load_shlib = load_elf_library,
43257 .core_dump = elf_core_dump,
43258+
43259+#ifdef CONFIG_PAX_MPROTECT
43260+ .handle_mprotect= elf_handle_mprotect,
43261+#endif
43262+
43263 .min_coredump = ELF_EXEC_PAGESIZE,
43264 };
43265
43266@@ -78,6 +88,8 @@ static struct linux_binfmt elf_format = {
43267
43268 static int set_brk(unsigned long start, unsigned long end)
43269 {
43270+ unsigned long e = end;
43271+
43272 start = ELF_PAGEALIGN(start);
43273 end = ELF_PAGEALIGN(end);
43274 if (end > start) {
43275@@ -86,7 +98,7 @@ static int set_brk(unsigned long start, unsigned long end)
43276 if (BAD_ADDR(addr))
43277 return addr;
43278 }
43279- current->mm->start_brk = current->mm->brk = end;
43280+ current->mm->start_brk = current->mm->brk = e;
43281 return 0;
43282 }
43283
43284@@ -147,12 +159,13 @@ create_elf_tables(struct linux_binprm *bprm, struct elfhdr *exec,
43285 elf_addr_t __user *u_rand_bytes;
43286 const char *k_platform = ELF_PLATFORM;
43287 const char *k_base_platform = ELF_BASE_PLATFORM;
43288- unsigned char k_rand_bytes[16];
43289+ u32 k_rand_bytes[4];
43290 int items;
43291 elf_addr_t *elf_info;
43292 int ei_index = 0;
43293 const struct cred *cred = current_cred();
43294 struct vm_area_struct *vma;
43295+ unsigned long saved_auxv[AT_VECTOR_SIZE];
43296
43297 /*
43298 * In some cases (e.g. Hyper-Threading), we want to avoid L1
43299@@ -194,8 +207,12 @@ create_elf_tables(struct linux_binprm *bprm, struct elfhdr *exec,
43300 * Generate 16 random bytes for userspace PRNG seeding.
43301 */
43302 get_random_bytes(k_rand_bytes, sizeof(k_rand_bytes));
43303- u_rand_bytes = (elf_addr_t __user *)
43304- STACK_ALLOC(p, sizeof(k_rand_bytes));
43305+ srandom32(k_rand_bytes[0] ^ random32());
43306+ srandom32(k_rand_bytes[1] ^ random32());
43307+ srandom32(k_rand_bytes[2] ^ random32());
43308+ srandom32(k_rand_bytes[3] ^ random32());
43309+ p = STACK_ROUND(p, sizeof(k_rand_bytes));
43310+ u_rand_bytes = (elf_addr_t __user *) p;
43311 if (__copy_to_user(u_rand_bytes, k_rand_bytes, sizeof(k_rand_bytes)))
43312 return -EFAULT;
43313
43314@@ -307,9 +324,11 @@ create_elf_tables(struct linux_binprm *bprm, struct elfhdr *exec,
43315 return -EFAULT;
43316 current->mm->env_end = p;
43317
43318+ memcpy(saved_auxv, elf_info, ei_index * sizeof(elf_addr_t));
43319+
43320 /* Put the elf_info on the stack in the right place. */
43321 sp = (elf_addr_t __user *)envp + 1;
43322- if (copy_to_user(sp, elf_info, ei_index * sizeof(elf_addr_t)))
43323+ if (copy_to_user(sp, saved_auxv, ei_index * sizeof(elf_addr_t)))
43324 return -EFAULT;
43325 return 0;
43326 }
43327@@ -373,15 +392,14 @@ static unsigned long total_mapping_size(struct elf_phdr *cmds, int nr)
43328 an ELF header */
43329
43330 static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
43331- struct file *interpreter, unsigned long *interp_map_addr,
43332- unsigned long no_base)
43333+ struct file *interpreter, unsigned long no_base)
43334 {
43335 struct elf_phdr *elf_phdata;
43336 struct elf_phdr *eppnt;
43337- unsigned long load_addr = 0;
43338+ unsigned long load_addr = 0, pax_task_size = TASK_SIZE;
43339 int load_addr_set = 0;
43340 unsigned long last_bss = 0, elf_bss = 0;
43341- unsigned long error = ~0UL;
43342+ unsigned long error = -EINVAL;
43343 unsigned long total_size;
43344 int retval, i, size;
43345
43346@@ -427,6 +445,11 @@ static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
43347 goto out_close;
43348 }
43349
43350+#ifdef CONFIG_PAX_SEGMEXEC
43351+ if (current->mm->pax_flags & MF_PAX_SEGMEXEC)
43352+ pax_task_size = SEGMEXEC_TASK_SIZE;
43353+#endif
43354+
43355 eppnt = elf_phdata;
43356 for (i = 0; i < interp_elf_ex->e_phnum; i++, eppnt++) {
43357 if (eppnt->p_type == PT_LOAD) {
43358@@ -450,8 +473,6 @@ static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
43359 map_addr = elf_map(interpreter, load_addr + vaddr,
43360 eppnt, elf_prot, elf_type, total_size);
43361 total_size = 0;
43362- if (!*interp_map_addr)
43363- *interp_map_addr = map_addr;
43364 error = map_addr;
43365 if (BAD_ADDR(map_addr))
43366 goto out_close;
43367@@ -470,8 +491,8 @@ static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
43368 k = load_addr + eppnt->p_vaddr;
43369 if (BAD_ADDR(k) ||
43370 eppnt->p_filesz > eppnt->p_memsz ||
43371- eppnt->p_memsz > TASK_SIZE ||
43372- TASK_SIZE - eppnt->p_memsz < k) {
43373+ eppnt->p_memsz > pax_task_size ||
43374+ pax_task_size - eppnt->p_memsz < k) {
43375 error = -ENOMEM;
43376 goto out_close;
43377 }
43378@@ -523,6 +544,315 @@ out:
43379 return error;
43380 }
43381
43382+#ifdef CONFIG_PAX_PT_PAX_FLAGS
43383+#ifdef CONFIG_PAX_SOFTMODE
43384+static unsigned long pax_parse_pt_pax_softmode(const struct elf_phdr * const elf_phdata)
43385+{
43386+ unsigned long pax_flags = 0UL;
43387+
43388+#ifdef CONFIG_PAX_PAGEEXEC
43389+ if (elf_phdata->p_flags & PF_PAGEEXEC)
43390+ pax_flags |= MF_PAX_PAGEEXEC;
43391+#endif
43392+
43393+#ifdef CONFIG_PAX_SEGMEXEC
43394+ if (elf_phdata->p_flags & PF_SEGMEXEC)
43395+ pax_flags |= MF_PAX_SEGMEXEC;
43396+#endif
43397+
43398+#ifdef CONFIG_PAX_EMUTRAMP
43399+ if ((elf_phdata->p_flags & PF_EMUTRAMP) && (pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)))
43400+ pax_flags |= MF_PAX_EMUTRAMP;
43401+#endif
43402+
43403+#ifdef CONFIG_PAX_MPROTECT
43404+ if (elf_phdata->p_flags & PF_MPROTECT)
43405+ pax_flags |= MF_PAX_MPROTECT;
43406+#endif
43407+
43408+#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
43409+ if (randomize_va_space && (elf_phdata->p_flags & PF_RANDMMAP))
43410+ pax_flags |= MF_PAX_RANDMMAP;
43411+#endif
43412+
43413+ return pax_flags;
43414+}
43415+#endif
43416+
43417+static unsigned long pax_parse_pt_pax_hardmode(const struct elf_phdr * const elf_phdata)
43418+{
43419+ unsigned long pax_flags = 0UL;
43420+
43421+#ifdef CONFIG_PAX_PAGEEXEC
43422+ if (!(elf_phdata->p_flags & PF_NOPAGEEXEC))
43423+ pax_flags |= MF_PAX_PAGEEXEC;
43424+#endif
43425+
43426+#ifdef CONFIG_PAX_SEGMEXEC
43427+ if (!(elf_phdata->p_flags & PF_NOSEGMEXEC))
43428+ pax_flags |= MF_PAX_SEGMEXEC;
43429+#endif
43430+
43431+#ifdef CONFIG_PAX_EMUTRAMP
43432+ if (!(elf_phdata->p_flags & PF_NOEMUTRAMP))
43433+ pax_flags |= MF_PAX_EMUTRAMP;
43434+#endif
43435+
43436+#ifdef CONFIG_PAX_MPROTECT
43437+ if (!(elf_phdata->p_flags & PF_NOMPROTECT))
43438+ pax_flags |= MF_PAX_MPROTECT;
43439+#endif
43440+
43441+#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
43442+ if (randomize_va_space && !(elf_phdata->p_flags & PF_NORANDMMAP))
43443+ pax_flags |= MF_PAX_RANDMMAP;
43444+#endif
43445+
43446+ return pax_flags;
43447+}
43448+#endif
43449+
43450+#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
43451+#ifdef CONFIG_PAX_SOFTMODE
43452+static unsigned long pax_parse_xattr_pax_softmode(unsigned long pax_flags_softmode)
43453+{
43454+ unsigned long pax_flags = 0UL;
43455+
43456+#ifdef CONFIG_PAX_PAGEEXEC
43457+ if (pax_flags_softmode & MF_PAX_PAGEEXEC)
43458+ pax_flags |= MF_PAX_PAGEEXEC;
43459+#endif
43460+
43461+#ifdef CONFIG_PAX_SEGMEXEC
43462+ if (pax_flags_softmode & MF_PAX_SEGMEXEC)
43463+ pax_flags |= MF_PAX_SEGMEXEC;
43464+#endif
43465+
43466+#ifdef CONFIG_PAX_EMUTRAMP
43467+ if (pax_flags_softmode & MF_PAX_EMUTRAMP)
43468+ pax_flags |= MF_PAX_EMUTRAMP;
43469+#endif
43470+
43471+#ifdef CONFIG_PAX_MPROTECT
43472+ if (pax_flags_softmode & MF_PAX_MPROTECT)
43473+ pax_flags |= MF_PAX_MPROTECT;
43474+#endif
43475+
43476+#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
43477+ if (randomize_va_space && (pax_flags_softmode & MF_PAX_RANDMMAP))
43478+ pax_flags |= MF_PAX_RANDMMAP;
43479+#endif
43480+
43481+ return pax_flags;
43482+}
43483+#endif
43484+
43485+static unsigned long pax_parse_xattr_pax_hardmode(unsigned long pax_flags_hardmode)
43486+{
43487+ unsigned long pax_flags = 0UL;
43488+
43489+#ifdef CONFIG_PAX_PAGEEXEC
43490+ if (!(pax_flags_hardmode & MF_PAX_PAGEEXEC))
43491+ pax_flags |= MF_PAX_PAGEEXEC;
43492+#endif
43493+
43494+#ifdef CONFIG_PAX_SEGMEXEC
43495+ if (!(pax_flags_hardmode & MF_PAX_SEGMEXEC))
43496+ pax_flags |= MF_PAX_SEGMEXEC;
43497+#endif
43498+
43499+#ifdef CONFIG_PAX_EMUTRAMP
43500+ if (!(pax_flags_hardmode & MF_PAX_EMUTRAMP))
43501+ pax_flags |= MF_PAX_EMUTRAMP;
43502+#endif
43503+
43504+#ifdef CONFIG_PAX_MPROTECT
43505+ if (!(pax_flags_hardmode & MF_PAX_MPROTECT))
43506+ pax_flags |= MF_PAX_MPROTECT;
43507+#endif
43508+
43509+#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
43510+ if (randomize_va_space && !(pax_flags_hardmode & MF_PAX_RANDMMAP))
43511+ pax_flags |= MF_PAX_RANDMMAP;
43512+#endif
43513+
43514+ return pax_flags;
43515+}
43516+#endif
43517+
43518+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
43519+static unsigned long pax_parse_ei_pax(const struct elfhdr * const elf_ex)
43520+{
43521+ unsigned long pax_flags = 0UL;
43522+
43523+#ifdef CONFIG_PAX_EI_PAX
43524+
43525+#ifdef CONFIG_PAX_PAGEEXEC
43526+ if (!(elf_ex->e_ident[EI_PAX] & EF_PAX_PAGEEXEC))
43527+ pax_flags |= MF_PAX_PAGEEXEC;
43528+#endif
43529+
43530+#ifdef CONFIG_PAX_SEGMEXEC
43531+ if (!(elf_ex->e_ident[EI_PAX] & EF_PAX_SEGMEXEC))
43532+ pax_flags |= MF_PAX_SEGMEXEC;
43533+#endif
43534+
43535+#ifdef CONFIG_PAX_EMUTRAMP
43536+ if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) && (elf_ex->e_ident[EI_PAX] & EF_PAX_EMUTRAMP))
43537+ pax_flags |= MF_PAX_EMUTRAMP;
43538+#endif
43539+
43540+#ifdef CONFIG_PAX_MPROTECT
43541+ if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) && !(elf_ex->e_ident[EI_PAX] & EF_PAX_MPROTECT))
43542+ pax_flags |= MF_PAX_MPROTECT;
43543+#endif
43544+
43545+#ifdef CONFIG_PAX_ASLR
43546+ if (randomize_va_space && !(elf_ex->e_ident[EI_PAX] & EF_PAX_RANDMMAP))
43547+ pax_flags |= MF_PAX_RANDMMAP;
43548+#endif
43549+
43550+#else
43551+
43552+#ifdef CONFIG_PAX_PAGEEXEC
43553+ pax_flags |= MF_PAX_PAGEEXEC;
43554+#endif
43555+
43556+#ifdef CONFIG_PAX_SEGMEXEC
43557+ pax_flags |= MF_PAX_SEGMEXEC;
43558+#endif
43559+
43560+#ifdef CONFIG_PAX_MPROTECT
43561+ pax_flags |= MF_PAX_MPROTECT;
43562+#endif
43563+
43564+#ifdef CONFIG_PAX_RANDMMAP
43565+ if (randomize_va_space)
43566+ pax_flags |= MF_PAX_RANDMMAP;
43567+#endif
43568+
43569+#endif
43570+
43571+ return pax_flags;
43572+}
43573+
43574+static unsigned long pax_parse_pt_pax(const struct elfhdr * const elf_ex, const struct elf_phdr * const elf_phdata)
43575+{
43576+
43577+#ifdef CONFIG_PAX_PT_PAX_FLAGS
43578+ unsigned long i;
43579+
43580+ for (i = 0UL; i < elf_ex->e_phnum; i++)
43581+ if (elf_phdata[i].p_type == PT_PAX_FLAGS) {
43582+ if (((elf_phdata[i].p_flags & PF_PAGEEXEC) && (elf_phdata[i].p_flags & PF_NOPAGEEXEC)) ||
43583+ ((elf_phdata[i].p_flags & PF_SEGMEXEC) && (elf_phdata[i].p_flags & PF_NOSEGMEXEC)) ||
43584+ ((elf_phdata[i].p_flags & PF_EMUTRAMP) && (elf_phdata[i].p_flags & PF_NOEMUTRAMP)) ||
43585+ ((elf_phdata[i].p_flags & PF_MPROTECT) && (elf_phdata[i].p_flags & PF_NOMPROTECT)) ||
43586+ ((elf_phdata[i].p_flags & PF_RANDMMAP) && (elf_phdata[i].p_flags & PF_NORANDMMAP)))
43587+ return ~0UL;
43588+
43589+#ifdef CONFIG_PAX_SOFTMODE
43590+ if (pax_softmode)
43591+ return pax_parse_pt_pax_softmode(&elf_phdata[i]);
43592+ else
43593+#endif
43594+
43595+ return pax_parse_pt_pax_hardmode(&elf_phdata[i]);
43596+ break;
43597+ }
43598+#endif
43599+
43600+ return ~0UL;
43601+}
43602+
43603+static unsigned long pax_parse_xattr_pax(struct file * const file)
43604+{
43605+
43606+#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
43607+ ssize_t xattr_size, i;
43608+ unsigned char xattr_value[5];
43609+ unsigned long pax_flags_hardmode = 0UL, pax_flags_softmode = 0UL;
43610+
43611+ xattr_size = vfs_getxattr(file->f_path.dentry, XATTR_NAME_PAX_FLAGS, xattr_value, sizeof xattr_value);
43612+ if (xattr_size <= 0 || xattr_size > 5)
43613+ return ~0UL;
43614+
43615+ for (i = 0; i < xattr_size; i++)
43616+ switch (xattr_value[i]) {
43617+ default:
43618+ return ~0UL;
43619+
43620+#define parse_flag(option1, option2, flag) \
43621+ case option1: \
43622+ if (pax_flags_hardmode & MF_PAX_##flag) \
43623+ return ~0UL; \
43624+ pax_flags_hardmode |= MF_PAX_##flag; \
43625+ break; \
43626+ case option2: \
43627+ if (pax_flags_softmode & MF_PAX_##flag) \
43628+ return ~0UL; \
43629+ pax_flags_softmode |= MF_PAX_##flag; \
43630+ break;
43631+
43632+ parse_flag('p', 'P', PAGEEXEC);
43633+ parse_flag('e', 'E', EMUTRAMP);
43634+ parse_flag('m', 'M', MPROTECT);
43635+ parse_flag('r', 'R', RANDMMAP);
43636+ parse_flag('s', 'S', SEGMEXEC);
43637+
43638+#undef parse_flag
43639+ }
43640+
43641+ if (pax_flags_hardmode & pax_flags_softmode)
43642+ return ~0UL;
43643+
43644+#ifdef CONFIG_PAX_SOFTMODE
43645+ if (pax_softmode)
43646+ return pax_parse_xattr_pax_softmode(pax_flags_softmode);
43647+ else
43648+#endif
43649+
43650+ return pax_parse_xattr_pax_hardmode(pax_flags_hardmode);
43651+#else
43652+ return ~0UL;
43653+#endif
43654+
43655+}
43656+
43657+static long pax_parse_pax_flags(const struct elfhdr * const elf_ex, const struct elf_phdr * const elf_phdata, struct file * const file)
43658+{
43659+ unsigned long pax_flags, pt_pax_flags, xattr_pax_flags;
43660+
43661+ pax_flags = pax_parse_ei_pax(elf_ex);
43662+ pt_pax_flags = pax_parse_pt_pax(elf_ex, elf_phdata);
43663+ xattr_pax_flags = pax_parse_xattr_pax(file);
43664+
43665+ if (pt_pax_flags == ~0UL)
43666+ pt_pax_flags = xattr_pax_flags;
43667+ else if (xattr_pax_flags == ~0UL)
43668+ xattr_pax_flags = pt_pax_flags;
43669+ if (pt_pax_flags != xattr_pax_flags)
43670+ return -EINVAL;
43671+ if (pt_pax_flags != ~0UL)
43672+ pax_flags = pt_pax_flags;
43673+
43674+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_PAX_SEGMEXEC)
43675+ if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) == (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
43676+ if ((__supported_pte_mask & _PAGE_NX))
43677+ pax_flags &= ~MF_PAX_SEGMEXEC;
43678+ else
43679+ pax_flags &= ~MF_PAX_PAGEEXEC;
43680+ }
43681+#endif
43682+
43683+ if (0 > pax_check_flags(&pax_flags))
43684+ return -EINVAL;
43685+
43686+ current->mm->pax_flags = pax_flags;
43687+ return 0;
43688+}
43689+#endif
43690+
43691 /*
43692 * These are the functions used to load ELF style executables and shared
43693 * libraries. There is no binary dependent code anywhere else.
43694@@ -539,6 +869,11 @@ static unsigned long randomize_stack_top(unsigned long stack_top)
43695 {
43696 unsigned int random_variable = 0;
43697
43698+#ifdef CONFIG_PAX_RANDUSTACK
43699+ if (randomize_va_space)
43700+ return stack_top - current->mm->delta_stack;
43701+#endif
43702+
43703 if ((current->flags & PF_RANDOMIZE) &&
43704 !(current->personality & ADDR_NO_RANDOMIZE)) {
43705 random_variable = get_random_int() & STACK_RND_MASK;
43706@@ -557,7 +892,7 @@ static int load_elf_binary(struct linux_binprm *bprm, struct pt_regs *regs)
43707 unsigned long load_addr = 0, load_bias = 0;
43708 int load_addr_set = 0;
43709 char * elf_interpreter = NULL;
43710- unsigned long error;
43711+ unsigned long error = 0;
43712 struct elf_phdr *elf_ppnt, *elf_phdata;
43713 unsigned long elf_bss, elf_brk;
43714 int retval, i;
43715@@ -567,11 +902,11 @@ static int load_elf_binary(struct linux_binprm *bprm, struct pt_regs *regs)
43716 unsigned long start_code, end_code, start_data, end_data;
43717 unsigned long reloc_func_desc __maybe_unused = 0;
43718 int executable_stack = EXSTACK_DEFAULT;
43719- unsigned long def_flags = 0;
43720 struct {
43721 struct elfhdr elf_ex;
43722 struct elfhdr interp_elf_ex;
43723 } *loc;
43724+ unsigned long pax_task_size = TASK_SIZE;
43725
43726 loc = kmalloc(sizeof(*loc), GFP_KERNEL);
43727 if (!loc) {
43728@@ -707,11 +1042,81 @@ static int load_elf_binary(struct linux_binprm *bprm, struct pt_regs *regs)
43729 goto out_free_dentry;
43730
43731 /* OK, This is the point of no return */
43732- current->mm->def_flags = def_flags;
43733+
43734+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
43735+ current->mm->pax_flags = 0UL;
43736+#endif
43737+
43738+#ifdef CONFIG_PAX_DLRESOLVE
43739+ current->mm->call_dl_resolve = 0UL;
43740+#endif
43741+
43742+#if defined(CONFIG_PPC32) && defined(CONFIG_PAX_EMUSIGRT)
43743+ current->mm->call_syscall = 0UL;
43744+#endif
43745+
43746+#ifdef CONFIG_PAX_ASLR
43747+ current->mm->delta_mmap = 0UL;
43748+ current->mm->delta_stack = 0UL;
43749+#endif
43750+
43751+ current->mm->def_flags = 0;
43752+
43753+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
43754+ if (0 > pax_parse_pax_flags(&loc->elf_ex, elf_phdata, bprm->file)) {
43755+ send_sig(SIGKILL, current, 0);
43756+ goto out_free_dentry;
43757+ }
43758+#endif
43759+
43760+#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
43761+ pax_set_initial_flags(bprm);
43762+#elif defined(CONFIG_PAX_HOOK_ACL_FLAGS)
43763+ if (pax_set_initial_flags_func)
43764+ (pax_set_initial_flags_func)(bprm);
43765+#endif
43766+
43767+#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
43768+ if ((current->mm->pax_flags & MF_PAX_PAGEEXEC) && !(__supported_pte_mask & _PAGE_NX)) {
43769+ current->mm->context.user_cs_limit = PAGE_SIZE;
43770+ current->mm->def_flags |= VM_PAGEEXEC;
43771+ }
43772+#endif
43773+
43774+#ifdef CONFIG_PAX_SEGMEXEC
43775+ if (current->mm->pax_flags & MF_PAX_SEGMEXEC) {
43776+ current->mm->context.user_cs_base = SEGMEXEC_TASK_SIZE;
43777+ current->mm->context.user_cs_limit = TASK_SIZE-SEGMEXEC_TASK_SIZE;
43778+ pax_task_size = SEGMEXEC_TASK_SIZE;
43779+ current->mm->def_flags |= VM_NOHUGEPAGE;
43780+ }
43781+#endif
43782+
43783+#if defined(CONFIG_ARCH_TRACK_EXEC_LIMIT) || defined(CONFIG_PAX_SEGMEXEC)
43784+ if (current->mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
43785+ set_user_cs(current->mm->context.user_cs_base, current->mm->context.user_cs_limit, get_cpu());
43786+ put_cpu();
43787+ }
43788+#endif
43789
43790 /* Do this immediately, since STACK_TOP as used in setup_arg_pages
43791 may depend on the personality. */
43792 SET_PERSONALITY(loc->elf_ex);
43793+
43794+#ifdef CONFIG_PAX_ASLR
43795+ if (current->mm->pax_flags & MF_PAX_RANDMMAP) {
43796+ current->mm->delta_mmap = (pax_get_random_long() & ((1UL << PAX_DELTA_MMAP_LEN)-1)) << PAGE_SHIFT;
43797+ current->mm->delta_stack = (pax_get_random_long() & ((1UL << PAX_DELTA_STACK_LEN)-1)) << PAGE_SHIFT;
43798+ }
43799+#endif
43800+
43801+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
43802+ if (current->mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
43803+ executable_stack = EXSTACK_DISABLE_X;
43804+ current->personality &= ~READ_IMPLIES_EXEC;
43805+ } else
43806+#endif
43807+
43808 if (elf_read_implies_exec(loc->elf_ex, executable_stack))
43809 current->personality |= READ_IMPLIES_EXEC;
43810
43811@@ -802,6 +1207,20 @@ static int load_elf_binary(struct linux_binprm *bprm, struct pt_regs *regs)
43812 #else
43813 load_bias = ELF_PAGESTART(ELF_ET_DYN_BASE - vaddr);
43814 #endif
43815+
43816+#ifdef CONFIG_PAX_RANDMMAP
43817+ /* PaX: randomize base address at the default exe base if requested */
43818+ if ((current->mm->pax_flags & MF_PAX_RANDMMAP) && elf_interpreter) {
43819+#ifdef CONFIG_SPARC64
43820+ load_bias = (pax_get_random_long() & ((1UL << PAX_DELTA_MMAP_LEN) - 1)) << (PAGE_SHIFT+1);
43821+#else
43822+ load_bias = (pax_get_random_long() & ((1UL << PAX_DELTA_MMAP_LEN) - 1)) << PAGE_SHIFT;
43823+#endif
43824+ load_bias = ELF_PAGESTART(PAX_ELF_ET_DYN_BASE - vaddr + load_bias);
43825+ elf_flags |= MAP_FIXED;
43826+ }
43827+#endif
43828+
43829 }
43830
43831 error = elf_map(bprm->file, load_bias + vaddr, elf_ppnt,
43832@@ -834,9 +1253,9 @@ static int load_elf_binary(struct linux_binprm *bprm, struct pt_regs *regs)
43833 * allowed task size. Note that p_filesz must always be
43834 * <= p_memsz so it is only necessary to check p_memsz.
43835 */
43836- if (BAD_ADDR(k) || elf_ppnt->p_filesz > elf_ppnt->p_memsz ||
43837- elf_ppnt->p_memsz > TASK_SIZE ||
43838- TASK_SIZE - elf_ppnt->p_memsz < k) {
43839+ if (k >= pax_task_size || elf_ppnt->p_filesz > elf_ppnt->p_memsz ||
43840+ elf_ppnt->p_memsz > pax_task_size ||
43841+ pax_task_size - elf_ppnt->p_memsz < k) {
43842 /* set_brk can never work. Avoid overflows. */
43843 send_sig(SIGKILL, current, 0);
43844 retval = -EINVAL;
43845@@ -875,17 +1294,44 @@ static int load_elf_binary(struct linux_binprm *bprm, struct pt_regs *regs)
43846 goto out_free_dentry;
43847 }
43848 if (likely(elf_bss != elf_brk) && unlikely(padzero(elf_bss))) {
43849- send_sig(SIGSEGV, current, 0);
43850- retval = -EFAULT; /* Nobody gets to see this, but.. */
43851- goto out_free_dentry;
43852+ /*
43853+ * This bss-zeroing can fail if the ELF
43854+ * file specifies odd protections. So
43855+ * we don't check the return value
43856+ */
43857 }
43858
43859+#ifdef CONFIG_PAX_RANDMMAP
43860+ if (current->mm->pax_flags & MF_PAX_RANDMMAP) {
43861+ unsigned long start, size;
43862+
43863+ start = ELF_PAGEALIGN(elf_brk);
43864+ size = PAGE_SIZE + ((pax_get_random_long() & ((1UL << 22) - 1UL)) << 4);
43865+ down_read(&current->mm->mmap_sem);
43866+ retval = -ENOMEM;
43867+ if (!find_vma_intersection(current->mm, start, start + size + PAGE_SIZE)) {
43868+ unsigned long prot = PROT_NONE;
43869+
43870+ up_read(&current->mm->mmap_sem);
43871+ current->mm->brk_gap = PAGE_ALIGN(size) >> PAGE_SHIFT;
43872+// if (current->personality & ADDR_NO_RANDOMIZE)
43873+// prot = PROT_READ;
43874+ start = vm_mmap(NULL, start, size, prot, MAP_ANONYMOUS | MAP_FIXED | MAP_PRIVATE, 0);
43875+ retval = IS_ERR_VALUE(start) ? start : 0;
43876+ } else
43877+ up_read(&current->mm->mmap_sem);
43878+ if (retval == 0)
43879+ retval = set_brk(start + size, start + size + PAGE_SIZE);
43880+ if (retval < 0) {
43881+ send_sig(SIGKILL, current, 0);
43882+ goto out_free_dentry;
43883+ }
43884+ }
43885+#endif
43886+
43887 if (elf_interpreter) {
43888- unsigned long uninitialized_var(interp_map_addr);
43889-
43890 elf_entry = load_elf_interp(&loc->interp_elf_ex,
43891 interpreter,
43892- &interp_map_addr,
43893 load_bias);
43894 if (!IS_ERR((void *)elf_entry)) {
43895 /*
43896@@ -1107,7 +1553,7 @@ static bool always_dump_vma(struct vm_area_struct *vma)
43897 * Decide what to dump of a segment, part, all or none.
43898 */
43899 static unsigned long vma_dump_size(struct vm_area_struct *vma,
43900- unsigned long mm_flags)
43901+ unsigned long mm_flags, long signr)
43902 {
43903 #define FILTER(type) (mm_flags & (1UL << MMF_DUMP_##type))
43904
43905@@ -1144,7 +1590,7 @@ static unsigned long vma_dump_size(struct vm_area_struct *vma,
43906 if (vma->vm_file == NULL)
43907 return 0;
43908
43909- if (FILTER(MAPPED_PRIVATE))
43910+ if (signr == SIGKILL || FILTER(MAPPED_PRIVATE))
43911 goto whole;
43912
43913 /*
43914@@ -1366,9 +1812,9 @@ static void fill_auxv_note(struct memelfnote *note, struct mm_struct *mm)
43915 {
43916 elf_addr_t *auxv = (elf_addr_t *) mm->saved_auxv;
43917 int i = 0;
43918- do
43919+ do {
43920 i += 2;
43921- while (auxv[i - 2] != AT_NULL);
43922+ } while (auxv[i - 2] != AT_NULL);
43923 fill_note(note, "CORE", NT_AUXV, i * sizeof(elf_addr_t), auxv);
43924 }
43925
43926@@ -1879,14 +2325,14 @@ static void fill_extnum_info(struct elfhdr *elf, struct elf_shdr *shdr4extnum,
43927 }
43928
43929 static size_t elf_core_vma_data_size(struct vm_area_struct *gate_vma,
43930- unsigned long mm_flags)
43931+ struct coredump_params *cprm)
43932 {
43933 struct vm_area_struct *vma;
43934 size_t size = 0;
43935
43936 for (vma = first_vma(current, gate_vma); vma != NULL;
43937 vma = next_vma(vma, gate_vma))
43938- size += vma_dump_size(vma, mm_flags);
43939+ size += vma_dump_size(vma, cprm->mm_flags, cprm->signr);
43940 return size;
43941 }
43942
43943@@ -1980,7 +2426,7 @@ static int elf_core_dump(struct coredump_params *cprm)
43944
43945 dataoff = offset = roundup(offset, ELF_EXEC_PAGESIZE);
43946
43947- offset += elf_core_vma_data_size(gate_vma, cprm->mm_flags);
43948+ offset += elf_core_vma_data_size(gate_vma, cprm);
43949 offset += elf_core_extra_data_size();
43950 e_shoff = offset;
43951
43952@@ -1994,10 +2440,12 @@ static int elf_core_dump(struct coredump_params *cprm)
43953 offset = dataoff;
43954
43955 size += sizeof(*elf);
43956+ gr_learn_resource(current, RLIMIT_CORE, size, 1);
43957 if (size > cprm->limit || !dump_write(cprm->file, elf, sizeof(*elf)))
43958 goto end_coredump;
43959
43960 size += sizeof(*phdr4note);
43961+ gr_learn_resource(current, RLIMIT_CORE, size, 1);
43962 if (size > cprm->limit
43963 || !dump_write(cprm->file, phdr4note, sizeof(*phdr4note)))
43964 goto end_coredump;
43965@@ -2011,7 +2459,7 @@ static int elf_core_dump(struct coredump_params *cprm)
43966 phdr.p_offset = offset;
43967 phdr.p_vaddr = vma->vm_start;
43968 phdr.p_paddr = 0;
43969- phdr.p_filesz = vma_dump_size(vma, cprm->mm_flags);
43970+ phdr.p_filesz = vma_dump_size(vma, cprm->mm_flags, cprm->signr);
43971 phdr.p_memsz = vma->vm_end - vma->vm_start;
43972 offset += phdr.p_filesz;
43973 phdr.p_flags = vma->vm_flags & VM_READ ? PF_R : 0;
43974@@ -2022,6 +2470,7 @@ static int elf_core_dump(struct coredump_params *cprm)
43975 phdr.p_align = ELF_EXEC_PAGESIZE;
43976
43977 size += sizeof(phdr);
43978+ gr_learn_resource(current, RLIMIT_CORE, size, 1);
43979 if (size > cprm->limit
43980 || !dump_write(cprm->file, &phdr, sizeof(phdr)))
43981 goto end_coredump;
43982@@ -2046,7 +2495,7 @@ static int elf_core_dump(struct coredump_params *cprm)
43983 unsigned long addr;
43984 unsigned long end;
43985
43986- end = vma->vm_start + vma_dump_size(vma, cprm->mm_flags);
43987+ end = vma->vm_start + vma_dump_size(vma, cprm->mm_flags, cprm->signr);
43988
43989 for (addr = vma->vm_start; addr < end; addr += PAGE_SIZE) {
43990 struct page *page;
43991@@ -2055,6 +2504,7 @@ static int elf_core_dump(struct coredump_params *cprm)
43992 page = get_dump_page(addr);
43993 if (page) {
43994 void *kaddr = kmap(page);
43995+ gr_learn_resource(current, RLIMIT_CORE, size + PAGE_SIZE, 1);
43996 stop = ((size += PAGE_SIZE) > cprm->limit) ||
43997 !dump_write(cprm->file, kaddr,
43998 PAGE_SIZE);
43999@@ -2072,6 +2522,7 @@ static int elf_core_dump(struct coredump_params *cprm)
44000
44001 if (e_phnum == PN_XNUM) {
44002 size += sizeof(*shdr4extnum);
44003+ gr_learn_resource(current, RLIMIT_CORE, size, 1);
44004 if (size > cprm->limit
44005 || !dump_write(cprm->file, shdr4extnum,
44006 sizeof(*shdr4extnum)))
44007@@ -2092,6 +2543,97 @@ out:
44008
44009 #endif /* CONFIG_ELF_CORE */
44010
44011+#ifdef CONFIG_PAX_MPROTECT
44012+/* PaX: non-PIC ELF libraries need relocations on their executable segments
44013+ * therefore we'll grant them VM_MAYWRITE once during their life. Similarly
44014+ * we'll remove VM_MAYWRITE for good on RELRO segments.
44015+ *
44016+ * The checks favour ld-linux.so behaviour which operates on a per ELF segment
44017+ * basis because we want to allow the common case and not the special ones.
44018+ */
44019+static void elf_handle_mprotect(struct vm_area_struct *vma, unsigned long newflags)
44020+{
44021+ struct elfhdr elf_h;
44022+ struct elf_phdr elf_p;
44023+ unsigned long i;
44024+ unsigned long oldflags;
44025+ bool is_textrel_rw, is_textrel_rx, is_relro;
44026+
44027+ if (!(vma->vm_mm->pax_flags & MF_PAX_MPROTECT))
44028+ return;
44029+
44030+ oldflags = vma->vm_flags & (VM_MAYEXEC | VM_MAYWRITE | VM_MAYREAD | VM_EXEC | VM_WRITE | VM_READ);
44031+ newflags &= VM_MAYEXEC | VM_MAYWRITE | VM_MAYREAD | VM_EXEC | VM_WRITE | VM_READ;
44032+
44033+#ifdef CONFIG_PAX_ELFRELOCS
44034+ /* possible TEXTREL */
44035+ is_textrel_rw = vma->vm_file && !vma->anon_vma && oldflags == (VM_MAYEXEC | VM_MAYREAD | VM_EXEC | VM_READ) && newflags == (VM_WRITE | VM_READ);
44036+ 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);
44037+#else
44038+ is_textrel_rw = false;
44039+ is_textrel_rx = false;
44040+#endif
44041+
44042+ /* possible RELRO */
44043+ is_relro = vma->vm_file && vma->anon_vma && oldflags == (VM_MAYWRITE | VM_MAYREAD | VM_READ) && newflags == (VM_MAYWRITE | VM_MAYREAD | VM_READ);
44044+
44045+ if (!is_textrel_rw && !is_textrel_rx && !is_relro)
44046+ return;
44047+
44048+ if (sizeof(elf_h) != kernel_read(vma->vm_file, 0UL, (char *)&elf_h, sizeof(elf_h)) ||
44049+ memcmp(elf_h.e_ident, ELFMAG, SELFMAG) ||
44050+
44051+#ifdef CONFIG_PAX_ETEXECRELOCS
44052+ ((is_textrel_rw || is_textrel_rx) && (elf_h.e_type != ET_DYN && elf_h.e_type != ET_EXEC)) ||
44053+#else
44054+ ((is_textrel_rw || is_textrel_rx) && elf_h.e_type != ET_DYN) ||
44055+#endif
44056+
44057+ (is_relro && (elf_h.e_type != ET_DYN && elf_h.e_type != ET_EXEC)) ||
44058+ !elf_check_arch(&elf_h) ||
44059+ elf_h.e_phentsize != sizeof(struct elf_phdr) ||
44060+ elf_h.e_phnum > 65536UL / sizeof(struct elf_phdr))
44061+ return;
44062+
44063+ for (i = 0UL; i < elf_h.e_phnum; i++) {
44064+ if (sizeof(elf_p) != kernel_read(vma->vm_file, elf_h.e_phoff + i*sizeof(elf_p), (char *)&elf_p, sizeof(elf_p)))
44065+ return;
44066+ switch (elf_p.p_type) {
44067+ case PT_DYNAMIC:
44068+ if (!is_textrel_rw && !is_textrel_rx)
44069+ continue;
44070+ i = 0UL;
44071+ while ((i+1) * sizeof(elf_dyn) <= elf_p.p_filesz) {
44072+ elf_dyn dyn;
44073+
44074+ if (sizeof(dyn) != kernel_read(vma->vm_file, elf_p.p_offset + i*sizeof(dyn), (char *)&dyn, sizeof(dyn)))
44075+ return;
44076+ if (dyn.d_tag == DT_NULL)
44077+ return;
44078+ if (dyn.d_tag == DT_TEXTREL || (dyn.d_tag == DT_FLAGS && (dyn.d_un.d_val & DF_TEXTREL))) {
44079+ gr_log_textrel(vma);
44080+ if (is_textrel_rw)
44081+ vma->vm_flags |= VM_MAYWRITE;
44082+ else
44083+ /* PaX: disallow write access after relocs are done, hopefully noone else needs it... */
44084+ vma->vm_flags &= ~VM_MAYWRITE;
44085+ return;
44086+ }
44087+ i++;
44088+ }
44089+ return;
44090+
44091+ case PT_GNU_RELRO:
44092+ if (!is_relro)
44093+ continue;
44094+ if ((elf_p.p_offset >> PAGE_SHIFT) == vma->vm_pgoff && ELF_PAGEALIGN(elf_p.p_memsz) == vma->vm_end - vma->vm_start)
44095+ vma->vm_flags &= ~VM_MAYWRITE;
44096+ return;
44097+ }
44098+ }
44099+}
44100+#endif
44101+
44102 static int __init init_elf_binfmt(void)
44103 {
44104 register_binfmt(&elf_format);
44105diff --git a/fs/binfmt_flat.c b/fs/binfmt_flat.c
44106index 178cb70..8972997 100644
44107--- a/fs/binfmt_flat.c
44108+++ b/fs/binfmt_flat.c
44109@@ -562,7 +562,9 @@ static int load_flat_file(struct linux_binprm * bprm,
44110 realdatastart = (unsigned long) -ENOMEM;
44111 printk("Unable to allocate RAM for process data, errno %d\n",
44112 (int)-realdatastart);
44113+ down_write(&current->mm->mmap_sem);
44114 vm_munmap(textpos, text_len);
44115+ up_write(&current->mm->mmap_sem);
44116 ret = realdatastart;
44117 goto err;
44118 }
44119@@ -586,8 +588,10 @@ static int load_flat_file(struct linux_binprm * bprm,
44120 }
44121 if (IS_ERR_VALUE(result)) {
44122 printk("Unable to read data+bss, errno %d\n", (int)-result);
44123+ down_write(&current->mm->mmap_sem);
44124 vm_munmap(textpos, text_len);
44125 vm_munmap(realdatastart, len);
44126+ up_write(&current->mm->mmap_sem);
44127 ret = result;
44128 goto err;
44129 }
44130@@ -654,8 +658,10 @@ static int load_flat_file(struct linux_binprm * bprm,
44131 }
44132 if (IS_ERR_VALUE(result)) {
44133 printk("Unable to read code+data+bss, errno %d\n",(int)-result);
44134+ down_write(&current->mm->mmap_sem);
44135 vm_munmap(textpos, text_len + data_len + extra +
44136 MAX_SHARED_LIBS * sizeof(unsigned long));
44137+ up_write(&current->mm->mmap_sem);
44138 ret = result;
44139 goto err;
44140 }
44141diff --git a/fs/bio.c b/fs/bio.c
44142index 71072ab..439851b 100644
44143--- a/fs/bio.c
44144+++ b/fs/bio.c
44145@@ -842,7 +842,7 @@ struct bio *bio_copy_user_iov(struct request_queue *q,
44146 /*
44147 * Overflow, abort
44148 */
44149- if (end < start)
44150+ if (end < start || end - start > INT_MAX - nr_pages)
44151 return ERR_PTR(-EINVAL);
44152
44153 nr_pages += end - start;
44154@@ -976,7 +976,7 @@ static struct bio *__bio_map_user_iov(struct request_queue *q,
44155 /*
44156 * Overflow, abort
44157 */
44158- if (end < start)
44159+ if (end < start || end - start > INT_MAX - nr_pages)
44160 return ERR_PTR(-EINVAL);
44161
44162 nr_pages += end - start;
44163@@ -1238,7 +1238,7 @@ static void bio_copy_kern_endio(struct bio *bio, int err)
44164 const int read = bio_data_dir(bio) == READ;
44165 struct bio_map_data *bmd = bio->bi_private;
44166 int i;
44167- char *p = bmd->sgvecs[0].iov_base;
44168+ char *p = (char __force_kernel *)bmd->sgvecs[0].iov_base;
44169
44170 __bio_for_each_segment(bvec, bio, i, 0) {
44171 char *addr = page_address(bvec->bv_page);
44172diff --git a/fs/block_dev.c b/fs/block_dev.c
44173index 38e721b..7a9c5bc 100644
44174--- a/fs/block_dev.c
44175+++ b/fs/block_dev.c
44176@@ -704,7 +704,7 @@ static bool bd_may_claim(struct block_device *bdev, struct block_device *whole,
44177 else if (bdev->bd_contains == bdev)
44178 return true; /* is a whole device which isn't held */
44179
44180- else if (whole->bd_holder == bd_may_claim)
44181+ else if (whole->bd_holder == (void *)bd_may_claim)
44182 return true; /* is a partition of a device that is being partitioned */
44183 else if (whole->bd_holder != NULL)
44184 return false; /* is a partition of a held device */
44185diff --git a/fs/btrfs/check-integrity.c b/fs/btrfs/check-integrity.c
44186index 9197e2e..7f731f8 100644
44187--- a/fs/btrfs/check-integrity.c
44188+++ b/fs/btrfs/check-integrity.c
44189@@ -155,7 +155,7 @@ struct btrfsic_block {
44190 union {
44191 bio_end_io_t *bio;
44192 bh_end_io_t *bh;
44193- } orig_bio_bh_end_io;
44194+ } __no_const orig_bio_bh_end_io;
44195 int submit_bio_bh_rw;
44196 u64 flush_gen; /* only valid if !never_written */
44197 };
44198diff --git a/fs/btrfs/ctree.c b/fs/btrfs/ctree.c
44199index 6d183f6..f47cc7a 100644
44200--- a/fs/btrfs/ctree.c
44201+++ b/fs/btrfs/ctree.c
44202@@ -1037,9 +1037,12 @@ static noinline int __btrfs_cow_block(struct btrfs_trans_handle *trans,
44203 free_extent_buffer(buf);
44204 add_root_to_dirty_list(root);
44205 } else {
44206- if (root->root_key.objectid == BTRFS_TREE_RELOC_OBJECTID)
44207- parent_start = parent->start;
44208- else
44209+ if (root->root_key.objectid == BTRFS_TREE_RELOC_OBJECTID) {
44210+ if (parent)
44211+ parent_start = parent->start;
44212+ else
44213+ parent_start = 0;
44214+ } else
44215 parent_start = 0;
44216
44217 WARN_ON(trans->transid != btrfs_header_generation(parent));
44218diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c
44219index ec154f9..bf617a7 100644
44220--- a/fs/btrfs/inode.c
44221+++ b/fs/btrfs/inode.c
44222@@ -7126,7 +7126,7 @@ fail:
44223 return -ENOMEM;
44224 }
44225
44226-static int btrfs_getattr(struct vfsmount *mnt,
44227+int btrfs_getattr(struct vfsmount *mnt,
44228 struct dentry *dentry, struct kstat *stat)
44229 {
44230 struct inode *inode = dentry->d_inode;
44231@@ -7140,6 +7140,14 @@ static int btrfs_getattr(struct vfsmount *mnt,
44232 return 0;
44233 }
44234
44235+EXPORT_SYMBOL(btrfs_getattr);
44236+
44237+dev_t get_btrfs_dev_from_inode(struct inode *inode)
44238+{
44239+ return BTRFS_I(inode)->root->anon_dev;
44240+}
44241+EXPORT_SYMBOL(get_btrfs_dev_from_inode);
44242+
44243 /*
44244 * If a file is moved, it will inherit the cow and compression flags of the new
44245 * directory.
44246diff --git a/fs/btrfs/ioctl.c b/fs/btrfs/ioctl.c
44247index 9df50fa..6cd20d0 100644
44248--- a/fs/btrfs/ioctl.c
44249+++ b/fs/btrfs/ioctl.c
44250@@ -2942,9 +2942,12 @@ long btrfs_ioctl_space_info(struct btrfs_root *root, void __user *arg)
44251 for (i = 0; i < num_types; i++) {
44252 struct btrfs_space_info *tmp;
44253
44254+ /* Don't copy in more than we allocated */
44255 if (!slot_count)
44256 break;
44257
44258+ slot_count--;
44259+
44260 info = NULL;
44261 rcu_read_lock();
44262 list_for_each_entry_rcu(tmp, &root->fs_info->space_info,
44263@@ -2966,10 +2969,7 @@ long btrfs_ioctl_space_info(struct btrfs_root *root, void __user *arg)
44264 memcpy(dest, &space, sizeof(space));
44265 dest++;
44266 space_args.total_spaces++;
44267- slot_count--;
44268 }
44269- if (!slot_count)
44270- break;
44271 }
44272 up_read(&info->groups_sem);
44273 }
44274diff --git a/fs/btrfs/relocation.c b/fs/btrfs/relocation.c
44275index 4da0865..01c4778 100644
44276--- a/fs/btrfs/relocation.c
44277+++ b/fs/btrfs/relocation.c
44278@@ -1269,7 +1269,7 @@ static int __update_reloc_root(struct btrfs_root *root, int del)
44279 }
44280 spin_unlock(&rc->reloc_root_tree.lock);
44281
44282- BUG_ON((struct btrfs_root *)node->data != root);
44283+ BUG_ON(!node || (struct btrfs_root *)node->data != root);
44284
44285 if (!del) {
44286 spin_lock(&rc->reloc_root_tree.lock);
44287diff --git a/fs/cachefiles/bind.c b/fs/cachefiles/bind.c
44288index 622f469..e8d2d55 100644
44289--- a/fs/cachefiles/bind.c
44290+++ b/fs/cachefiles/bind.c
44291@@ -39,13 +39,11 @@ int cachefiles_daemon_bind(struct cachefiles_cache *cache, char *args)
44292 args);
44293
44294 /* start by checking things over */
44295- ASSERT(cache->fstop_percent >= 0 &&
44296- cache->fstop_percent < cache->fcull_percent &&
44297+ ASSERT(cache->fstop_percent < cache->fcull_percent &&
44298 cache->fcull_percent < cache->frun_percent &&
44299 cache->frun_percent < 100);
44300
44301- ASSERT(cache->bstop_percent >= 0 &&
44302- cache->bstop_percent < cache->bcull_percent &&
44303+ ASSERT(cache->bstop_percent < cache->bcull_percent &&
44304 cache->bcull_percent < cache->brun_percent &&
44305 cache->brun_percent < 100);
44306
44307diff --git a/fs/cachefiles/daemon.c b/fs/cachefiles/daemon.c
44308index 0a1467b..6a53245 100644
44309--- a/fs/cachefiles/daemon.c
44310+++ b/fs/cachefiles/daemon.c
44311@@ -196,7 +196,7 @@ static ssize_t cachefiles_daemon_read(struct file *file, char __user *_buffer,
44312 if (n > buflen)
44313 return -EMSGSIZE;
44314
44315- if (copy_to_user(_buffer, buffer, n) != 0)
44316+ if (n > sizeof(buffer) || copy_to_user(_buffer, buffer, n) != 0)
44317 return -EFAULT;
44318
44319 return n;
44320@@ -222,7 +222,7 @@ static ssize_t cachefiles_daemon_write(struct file *file,
44321 if (test_bit(CACHEFILES_DEAD, &cache->flags))
44322 return -EIO;
44323
44324- if (datalen < 0 || datalen > PAGE_SIZE - 1)
44325+ if (datalen > PAGE_SIZE - 1)
44326 return -EOPNOTSUPP;
44327
44328 /* drag the command string into the kernel so we can parse it */
44329@@ -386,7 +386,7 @@ static int cachefiles_daemon_fstop(struct cachefiles_cache *cache, char *args)
44330 if (args[0] != '%' || args[1] != '\0')
44331 return -EINVAL;
44332
44333- if (fstop < 0 || fstop >= cache->fcull_percent)
44334+ if (fstop >= cache->fcull_percent)
44335 return cachefiles_daemon_range_error(cache, args);
44336
44337 cache->fstop_percent = fstop;
44338@@ -458,7 +458,7 @@ static int cachefiles_daemon_bstop(struct cachefiles_cache *cache, char *args)
44339 if (args[0] != '%' || args[1] != '\0')
44340 return -EINVAL;
44341
44342- if (bstop < 0 || bstop >= cache->bcull_percent)
44343+ if (bstop >= cache->bcull_percent)
44344 return cachefiles_daemon_range_error(cache, args);
44345
44346 cache->bstop_percent = bstop;
44347diff --git a/fs/cachefiles/internal.h b/fs/cachefiles/internal.h
44348index bd6bc1b..b627b53 100644
44349--- a/fs/cachefiles/internal.h
44350+++ b/fs/cachefiles/internal.h
44351@@ -57,7 +57,7 @@ struct cachefiles_cache {
44352 wait_queue_head_t daemon_pollwq; /* poll waitqueue for daemon */
44353 struct rb_root active_nodes; /* active nodes (can't be culled) */
44354 rwlock_t active_lock; /* lock for active_nodes */
44355- atomic_t gravecounter; /* graveyard uniquifier */
44356+ atomic_unchecked_t gravecounter; /* graveyard uniquifier */
44357 unsigned frun_percent; /* when to stop culling (% files) */
44358 unsigned fcull_percent; /* when to start culling (% files) */
44359 unsigned fstop_percent; /* when to stop allocating (% files) */
44360@@ -169,19 +169,19 @@ extern int cachefiles_check_in_use(struct cachefiles_cache *cache,
44361 * proc.c
44362 */
44363 #ifdef CONFIG_CACHEFILES_HISTOGRAM
44364-extern atomic_t cachefiles_lookup_histogram[HZ];
44365-extern atomic_t cachefiles_mkdir_histogram[HZ];
44366-extern atomic_t cachefiles_create_histogram[HZ];
44367+extern atomic_unchecked_t cachefiles_lookup_histogram[HZ];
44368+extern atomic_unchecked_t cachefiles_mkdir_histogram[HZ];
44369+extern atomic_unchecked_t cachefiles_create_histogram[HZ];
44370
44371 extern int __init cachefiles_proc_init(void);
44372 extern void cachefiles_proc_cleanup(void);
44373 static inline
44374-void cachefiles_hist(atomic_t histogram[], unsigned long start_jif)
44375+void cachefiles_hist(atomic_unchecked_t histogram[], unsigned long start_jif)
44376 {
44377 unsigned long jif = jiffies - start_jif;
44378 if (jif >= HZ)
44379 jif = HZ - 1;
44380- atomic_inc(&histogram[jif]);
44381+ atomic_inc_unchecked(&histogram[jif]);
44382 }
44383
44384 #else
44385diff --git a/fs/cachefiles/namei.c b/fs/cachefiles/namei.c
44386index b0b5f7c..039bb26 100644
44387--- a/fs/cachefiles/namei.c
44388+++ b/fs/cachefiles/namei.c
44389@@ -318,7 +318,7 @@ try_again:
44390 /* first step is to make up a grave dentry in the graveyard */
44391 sprintf(nbuffer, "%08x%08x",
44392 (uint32_t) get_seconds(),
44393- (uint32_t) atomic_inc_return(&cache->gravecounter));
44394+ (uint32_t) atomic_inc_return_unchecked(&cache->gravecounter));
44395
44396 /* do the multiway lock magic */
44397 trap = lock_rename(cache->graveyard, dir);
44398diff --git a/fs/cachefiles/proc.c b/fs/cachefiles/proc.c
44399index eccd339..4c1d995 100644
44400--- a/fs/cachefiles/proc.c
44401+++ b/fs/cachefiles/proc.c
44402@@ -14,9 +14,9 @@
44403 #include <linux/seq_file.h>
44404 #include "internal.h"
44405
44406-atomic_t cachefiles_lookup_histogram[HZ];
44407-atomic_t cachefiles_mkdir_histogram[HZ];
44408-atomic_t cachefiles_create_histogram[HZ];
44409+atomic_unchecked_t cachefiles_lookup_histogram[HZ];
44410+atomic_unchecked_t cachefiles_mkdir_histogram[HZ];
44411+atomic_unchecked_t cachefiles_create_histogram[HZ];
44412
44413 /*
44414 * display the latency histogram
44415@@ -35,9 +35,9 @@ static int cachefiles_histogram_show(struct seq_file *m, void *v)
44416 return 0;
44417 default:
44418 index = (unsigned long) v - 3;
44419- x = atomic_read(&cachefiles_lookup_histogram[index]);
44420- y = atomic_read(&cachefiles_mkdir_histogram[index]);
44421- z = atomic_read(&cachefiles_create_histogram[index]);
44422+ x = atomic_read_unchecked(&cachefiles_lookup_histogram[index]);
44423+ y = atomic_read_unchecked(&cachefiles_mkdir_histogram[index]);
44424+ z = atomic_read_unchecked(&cachefiles_create_histogram[index]);
44425 if (x == 0 && y == 0 && z == 0)
44426 return 0;
44427
44428diff --git a/fs/cachefiles/rdwr.c b/fs/cachefiles/rdwr.c
44429index c994691..2a1537f 100644
44430--- a/fs/cachefiles/rdwr.c
44431+++ b/fs/cachefiles/rdwr.c
44432@@ -945,7 +945,7 @@ int cachefiles_write_page(struct fscache_storage *op, struct page *page)
44433 old_fs = get_fs();
44434 set_fs(KERNEL_DS);
44435 ret = file->f_op->write(
44436- file, (const void __user *) data, len, &pos);
44437+ file, (const void __force_user *) data, len, &pos);
44438 set_fs(old_fs);
44439 kunmap(page);
44440 if (ret != len)
44441diff --git a/fs/ceph/dir.c b/fs/ceph/dir.c
44442index e5b7731..b9c59fb 100644
44443--- a/fs/ceph/dir.c
44444+++ b/fs/ceph/dir.c
44445@@ -243,7 +243,7 @@ static int ceph_readdir(struct file *filp, void *dirent, filldir_t filldir)
44446 struct ceph_fs_client *fsc = ceph_inode_to_client(inode);
44447 struct ceph_mds_client *mdsc = fsc->mdsc;
44448 unsigned frag = fpos_frag(filp->f_pos);
44449- int off = fpos_off(filp->f_pos);
44450+ unsigned int off = fpos_off(filp->f_pos);
44451 int err;
44452 u32 ftype;
44453 struct ceph_mds_reply_info_parsed *rinfo;
44454diff --git a/fs/cifs/cifs_debug.c b/fs/cifs/cifs_debug.c
44455index d9ea6ed..1e6c8ac 100644
44456--- a/fs/cifs/cifs_debug.c
44457+++ b/fs/cifs/cifs_debug.c
44458@@ -267,8 +267,8 @@ static ssize_t cifs_stats_proc_write(struct file *file,
44459
44460 if (c == '1' || c == 'y' || c == 'Y' || c == '0') {
44461 #ifdef CONFIG_CIFS_STATS2
44462- atomic_set(&totBufAllocCount, 0);
44463- atomic_set(&totSmBufAllocCount, 0);
44464+ atomic_set_unchecked(&totBufAllocCount, 0);
44465+ atomic_set_unchecked(&totSmBufAllocCount, 0);
44466 #endif /* CONFIG_CIFS_STATS2 */
44467 spin_lock(&cifs_tcp_ses_lock);
44468 list_for_each(tmp1, &cifs_tcp_ses_list) {
44469@@ -281,7 +281,7 @@ static ssize_t cifs_stats_proc_write(struct file *file,
44470 tcon = list_entry(tmp3,
44471 struct cifs_tcon,
44472 tcon_list);
44473- atomic_set(&tcon->num_smbs_sent, 0);
44474+ atomic_set_unchecked(&tcon->num_smbs_sent, 0);
44475 if (server->ops->clear_stats)
44476 server->ops->clear_stats(tcon);
44477 }
44478@@ -313,8 +313,8 @@ static int cifs_stats_proc_show(struct seq_file *m, void *v)
44479 smBufAllocCount.counter, cifs_min_small);
44480 #ifdef CONFIG_CIFS_STATS2
44481 seq_printf(m, "Total Large %d Small %d Allocations\n",
44482- atomic_read(&totBufAllocCount),
44483- atomic_read(&totSmBufAllocCount));
44484+ atomic_read_unchecked(&totBufAllocCount),
44485+ atomic_read_unchecked(&totSmBufAllocCount));
44486 #endif /* CONFIG_CIFS_STATS2 */
44487
44488 seq_printf(m, "Operations (MIDs): %d\n", atomic_read(&midCount));
44489@@ -343,7 +343,7 @@ static int cifs_stats_proc_show(struct seq_file *m, void *v)
44490 if (tcon->need_reconnect)
44491 seq_puts(m, "\tDISCONNECTED ");
44492 seq_printf(m, "\nSMBs: %d",
44493- atomic_read(&tcon->num_smbs_sent));
44494+ atomic_read_unchecked(&tcon->num_smbs_sent));
44495 if (server->ops->print_stats)
44496 server->ops->print_stats(m, tcon);
44497 }
44498diff --git a/fs/cifs/cifsfs.c b/fs/cifs/cifsfs.c
44499index db8a404..c712e2e 100644
44500--- a/fs/cifs/cifsfs.c
44501+++ b/fs/cifs/cifsfs.c
44502@@ -1003,7 +1003,7 @@ cifs_init_request_bufs(void)
44503 /* cERROR(1, "CIFSMaxBufSize %d 0x%x",CIFSMaxBufSize,CIFSMaxBufSize); */
44504 cifs_req_cachep = kmem_cache_create("cifs_request",
44505 CIFSMaxBufSize + max_hdr_size, 0,
44506- SLAB_HWCACHE_ALIGN, NULL);
44507+ SLAB_HWCACHE_ALIGN | SLAB_USERCOPY, NULL);
44508 if (cifs_req_cachep == NULL)
44509 return -ENOMEM;
44510
44511@@ -1030,7 +1030,7 @@ cifs_init_request_bufs(void)
44512 efficient to alloc 1 per page off the slab compared to 17K (5page)
44513 alloc of large cifs buffers even when page debugging is on */
44514 cifs_sm_req_cachep = kmem_cache_create("cifs_small_rq",
44515- MAX_CIFS_SMALL_BUFFER_SIZE, 0, SLAB_HWCACHE_ALIGN,
44516+ MAX_CIFS_SMALL_BUFFER_SIZE, 0, SLAB_HWCACHE_ALIGN | SLAB_USERCOPY,
44517 NULL);
44518 if (cifs_sm_req_cachep == NULL) {
44519 mempool_destroy(cifs_req_poolp);
44520@@ -1115,8 +1115,8 @@ init_cifs(void)
44521 atomic_set(&bufAllocCount, 0);
44522 atomic_set(&smBufAllocCount, 0);
44523 #ifdef CONFIG_CIFS_STATS2
44524- atomic_set(&totBufAllocCount, 0);
44525- atomic_set(&totSmBufAllocCount, 0);
44526+ atomic_set_unchecked(&totBufAllocCount, 0);
44527+ atomic_set_unchecked(&totSmBufAllocCount, 0);
44528 #endif /* CONFIG_CIFS_STATS2 */
44529
44530 atomic_set(&midCount, 0);
44531diff --git a/fs/cifs/cifsglob.h b/fs/cifs/cifsglob.h
44532index 977dc0e..ba48ab9 100644
44533--- a/fs/cifs/cifsglob.h
44534+++ b/fs/cifs/cifsglob.h
44535@@ -590,35 +590,35 @@ struct cifs_tcon {
44536 __u16 Flags; /* optional support bits */
44537 enum statusEnum tidStatus;
44538 #ifdef CONFIG_CIFS_STATS
44539- atomic_t num_smbs_sent;
44540+ atomic_unchecked_t num_smbs_sent;
44541 union {
44542 struct {
44543- atomic_t num_writes;
44544- atomic_t num_reads;
44545- atomic_t num_flushes;
44546- atomic_t num_oplock_brks;
44547- atomic_t num_opens;
44548- atomic_t num_closes;
44549- atomic_t num_deletes;
44550- atomic_t num_mkdirs;
44551- atomic_t num_posixopens;
44552- atomic_t num_posixmkdirs;
44553- atomic_t num_rmdirs;
44554- atomic_t num_renames;
44555- atomic_t num_t2renames;
44556- atomic_t num_ffirst;
44557- atomic_t num_fnext;
44558- atomic_t num_fclose;
44559- atomic_t num_hardlinks;
44560- atomic_t num_symlinks;
44561- atomic_t num_locks;
44562- atomic_t num_acl_get;
44563- atomic_t num_acl_set;
44564+ atomic_unchecked_t num_writes;
44565+ atomic_unchecked_t num_reads;
44566+ atomic_unchecked_t num_flushes;
44567+ atomic_unchecked_t num_oplock_brks;
44568+ atomic_unchecked_t num_opens;
44569+ atomic_unchecked_t num_closes;
44570+ atomic_unchecked_t num_deletes;
44571+ atomic_unchecked_t num_mkdirs;
44572+ atomic_unchecked_t num_posixopens;
44573+ atomic_unchecked_t num_posixmkdirs;
44574+ atomic_unchecked_t num_rmdirs;
44575+ atomic_unchecked_t num_renames;
44576+ atomic_unchecked_t num_t2renames;
44577+ atomic_unchecked_t num_ffirst;
44578+ atomic_unchecked_t num_fnext;
44579+ atomic_unchecked_t num_fclose;
44580+ atomic_unchecked_t num_hardlinks;
44581+ atomic_unchecked_t num_symlinks;
44582+ atomic_unchecked_t num_locks;
44583+ atomic_unchecked_t num_acl_get;
44584+ atomic_unchecked_t num_acl_set;
44585 } cifs_stats;
44586 #ifdef CONFIG_CIFS_SMB2
44587 struct {
44588- atomic_t smb2_com_sent[NUMBER_OF_SMB2_COMMANDS];
44589- atomic_t smb2_com_failed[NUMBER_OF_SMB2_COMMANDS];
44590+ atomic_unchecked_t smb2_com_sent[NUMBER_OF_SMB2_COMMANDS];
44591+ atomic_unchecked_t smb2_com_failed[NUMBER_OF_SMB2_COMMANDS];
44592 } smb2_stats;
44593 #endif /* CONFIG_CIFS_SMB2 */
44594 } stats;
44595@@ -862,7 +862,7 @@ build_path_to_root(struct smb_vol *vol, struct cifs_sb_info *cifs_sb,
44596 }
44597
44598 #ifdef CONFIG_CIFS_STATS
44599-#define cifs_stats_inc atomic_inc
44600+#define cifs_stats_inc atomic_inc_unchecked
44601
44602 static inline void cifs_stats_bytes_written(struct cifs_tcon *tcon,
44603 unsigned int bytes)
44604@@ -1227,8 +1227,8 @@ GLOBAL_EXTERN atomic_t tconInfoReconnectCount;
44605 /* Various Debug counters */
44606 GLOBAL_EXTERN atomic_t bufAllocCount; /* current number allocated */
44607 #ifdef CONFIG_CIFS_STATS2
44608-GLOBAL_EXTERN atomic_t totBufAllocCount; /* total allocated over all time */
44609-GLOBAL_EXTERN atomic_t totSmBufAllocCount;
44610+GLOBAL_EXTERN atomic_unchecked_t totBufAllocCount; /* total allocated over all time */
44611+GLOBAL_EXTERN atomic_unchecked_t totSmBufAllocCount;
44612 #endif
44613 GLOBAL_EXTERN atomic_t smBufAllocCount;
44614 GLOBAL_EXTERN atomic_t midCount;
44615diff --git a/fs/cifs/link.c b/fs/cifs/link.c
44616index e6ce3b1..adc21fd 100644
44617--- a/fs/cifs/link.c
44618+++ b/fs/cifs/link.c
44619@@ -602,7 +602,7 @@ symlink_exit:
44620
44621 void cifs_put_link(struct dentry *direntry, struct nameidata *nd, void *cookie)
44622 {
44623- char *p = nd_get_link(nd);
44624+ const char *p = nd_get_link(nd);
44625 if (!IS_ERR(p))
44626 kfree(p);
44627 }
44628diff --git a/fs/cifs/misc.c b/fs/cifs/misc.c
44629index ce41fee..ac0d27a 100644
44630--- a/fs/cifs/misc.c
44631+++ b/fs/cifs/misc.c
44632@@ -169,7 +169,7 @@ cifs_buf_get(void)
44633 memset(ret_buf, 0, buf_size + 3);
44634 atomic_inc(&bufAllocCount);
44635 #ifdef CONFIG_CIFS_STATS2
44636- atomic_inc(&totBufAllocCount);
44637+ atomic_inc_unchecked(&totBufAllocCount);
44638 #endif /* CONFIG_CIFS_STATS2 */
44639 }
44640
44641@@ -204,7 +204,7 @@ cifs_small_buf_get(void)
44642 /* memset(ret_buf, 0, sizeof(struct smb_hdr) + 27);*/
44643 atomic_inc(&smBufAllocCount);
44644 #ifdef CONFIG_CIFS_STATS2
44645- atomic_inc(&totSmBufAllocCount);
44646+ atomic_inc_unchecked(&totSmBufAllocCount);
44647 #endif /* CONFIG_CIFS_STATS2 */
44648
44649 }
44650diff --git a/fs/cifs/smb1ops.c b/fs/cifs/smb1ops.c
44651index 3129ac7..cc4a948 100644
44652--- a/fs/cifs/smb1ops.c
44653+++ b/fs/cifs/smb1ops.c
44654@@ -524,27 +524,27 @@ static void
44655 cifs_clear_stats(struct cifs_tcon *tcon)
44656 {
44657 #ifdef CONFIG_CIFS_STATS
44658- atomic_set(&tcon->stats.cifs_stats.num_writes, 0);
44659- atomic_set(&tcon->stats.cifs_stats.num_reads, 0);
44660- atomic_set(&tcon->stats.cifs_stats.num_flushes, 0);
44661- atomic_set(&tcon->stats.cifs_stats.num_oplock_brks, 0);
44662- atomic_set(&tcon->stats.cifs_stats.num_opens, 0);
44663- atomic_set(&tcon->stats.cifs_stats.num_posixopens, 0);
44664- atomic_set(&tcon->stats.cifs_stats.num_posixmkdirs, 0);
44665- atomic_set(&tcon->stats.cifs_stats.num_closes, 0);
44666- atomic_set(&tcon->stats.cifs_stats.num_deletes, 0);
44667- atomic_set(&tcon->stats.cifs_stats.num_mkdirs, 0);
44668- atomic_set(&tcon->stats.cifs_stats.num_rmdirs, 0);
44669- atomic_set(&tcon->stats.cifs_stats.num_renames, 0);
44670- atomic_set(&tcon->stats.cifs_stats.num_t2renames, 0);
44671- atomic_set(&tcon->stats.cifs_stats.num_ffirst, 0);
44672- atomic_set(&tcon->stats.cifs_stats.num_fnext, 0);
44673- atomic_set(&tcon->stats.cifs_stats.num_fclose, 0);
44674- atomic_set(&tcon->stats.cifs_stats.num_hardlinks, 0);
44675- atomic_set(&tcon->stats.cifs_stats.num_symlinks, 0);
44676- atomic_set(&tcon->stats.cifs_stats.num_locks, 0);
44677- atomic_set(&tcon->stats.cifs_stats.num_acl_get, 0);
44678- atomic_set(&tcon->stats.cifs_stats.num_acl_set, 0);
44679+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_writes, 0);
44680+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_reads, 0);
44681+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_flushes, 0);
44682+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_oplock_brks, 0);
44683+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_opens, 0);
44684+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_posixopens, 0);
44685+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_posixmkdirs, 0);
44686+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_closes, 0);
44687+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_deletes, 0);
44688+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_mkdirs, 0);
44689+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_rmdirs, 0);
44690+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_renames, 0);
44691+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_t2renames, 0);
44692+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_ffirst, 0);
44693+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_fnext, 0);
44694+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_fclose, 0);
44695+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_hardlinks, 0);
44696+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_symlinks, 0);
44697+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_locks, 0);
44698+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_acl_get, 0);
44699+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_acl_set, 0);
44700 #endif
44701 }
44702
44703@@ -553,36 +553,36 @@ cifs_print_stats(struct seq_file *m, struct cifs_tcon *tcon)
44704 {
44705 #ifdef CONFIG_CIFS_STATS
44706 seq_printf(m, " Oplocks breaks: %d",
44707- atomic_read(&tcon->stats.cifs_stats.num_oplock_brks));
44708+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_oplock_brks));
44709 seq_printf(m, "\nReads: %d Bytes: %llu",
44710- atomic_read(&tcon->stats.cifs_stats.num_reads),
44711+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_reads),
44712 (long long)(tcon->bytes_read));
44713 seq_printf(m, "\nWrites: %d Bytes: %llu",
44714- atomic_read(&tcon->stats.cifs_stats.num_writes),
44715+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_writes),
44716 (long long)(tcon->bytes_written));
44717 seq_printf(m, "\nFlushes: %d",
44718- atomic_read(&tcon->stats.cifs_stats.num_flushes));
44719+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_flushes));
44720 seq_printf(m, "\nLocks: %d HardLinks: %d Symlinks: %d",
44721- atomic_read(&tcon->stats.cifs_stats.num_locks),
44722- atomic_read(&tcon->stats.cifs_stats.num_hardlinks),
44723- atomic_read(&tcon->stats.cifs_stats.num_symlinks));
44724+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_locks),
44725+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_hardlinks),
44726+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_symlinks));
44727 seq_printf(m, "\nOpens: %d Closes: %d Deletes: %d",
44728- atomic_read(&tcon->stats.cifs_stats.num_opens),
44729- atomic_read(&tcon->stats.cifs_stats.num_closes),
44730- atomic_read(&tcon->stats.cifs_stats.num_deletes));
44731+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_opens),
44732+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_closes),
44733+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_deletes));
44734 seq_printf(m, "\nPosix Opens: %d Posix Mkdirs: %d",
44735- atomic_read(&tcon->stats.cifs_stats.num_posixopens),
44736- atomic_read(&tcon->stats.cifs_stats.num_posixmkdirs));
44737+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_posixopens),
44738+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_posixmkdirs));
44739 seq_printf(m, "\nMkdirs: %d Rmdirs: %d",
44740- atomic_read(&tcon->stats.cifs_stats.num_mkdirs),
44741- atomic_read(&tcon->stats.cifs_stats.num_rmdirs));
44742+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_mkdirs),
44743+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_rmdirs));
44744 seq_printf(m, "\nRenames: %d T2 Renames %d",
44745- atomic_read(&tcon->stats.cifs_stats.num_renames),
44746- atomic_read(&tcon->stats.cifs_stats.num_t2renames));
44747+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_renames),
44748+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_t2renames));
44749 seq_printf(m, "\nFindFirst: %d FNext %d FClose %d",
44750- atomic_read(&tcon->stats.cifs_stats.num_ffirst),
44751- atomic_read(&tcon->stats.cifs_stats.num_fnext),
44752- atomic_read(&tcon->stats.cifs_stats.num_fclose));
44753+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_ffirst),
44754+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_fnext),
44755+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_fclose));
44756 #endif
44757 }
44758
44759diff --git a/fs/cifs/smb2ops.c b/fs/cifs/smb2ops.c
44760index 826209b..fa460f4 100644
44761--- a/fs/cifs/smb2ops.c
44762+++ b/fs/cifs/smb2ops.c
44763@@ -219,8 +219,8 @@ smb2_clear_stats(struct cifs_tcon *tcon)
44764 #ifdef CONFIG_CIFS_STATS
44765 int i;
44766 for (i = 0; i < NUMBER_OF_SMB2_COMMANDS; i++) {
44767- atomic_set(&tcon->stats.smb2_stats.smb2_com_sent[i], 0);
44768- atomic_set(&tcon->stats.smb2_stats.smb2_com_failed[i], 0);
44769+ atomic_set_unchecked(&tcon->stats.smb2_stats.smb2_com_sent[i], 0);
44770+ atomic_set_unchecked(&tcon->stats.smb2_stats.smb2_com_failed[i], 0);
44771 }
44772 #endif
44773 }
44774@@ -229,66 +229,66 @@ static void
44775 smb2_print_stats(struct seq_file *m, struct cifs_tcon *tcon)
44776 {
44777 #ifdef CONFIG_CIFS_STATS
44778- atomic_t *sent = tcon->stats.smb2_stats.smb2_com_sent;
44779- atomic_t *failed = tcon->stats.smb2_stats.smb2_com_failed;
44780+ atomic_unchecked_t *sent = tcon->stats.smb2_stats.smb2_com_sent;
44781+ atomic_unchecked_t *failed = tcon->stats.smb2_stats.smb2_com_failed;
44782 seq_printf(m, "\nNegotiates: %d sent %d failed",
44783- atomic_read(&sent[SMB2_NEGOTIATE_HE]),
44784- atomic_read(&failed[SMB2_NEGOTIATE_HE]));
44785+ atomic_read_unchecked(&sent[SMB2_NEGOTIATE_HE]),
44786+ atomic_read_unchecked(&failed[SMB2_NEGOTIATE_HE]));
44787 seq_printf(m, "\nSessionSetups: %d sent %d failed",
44788- atomic_read(&sent[SMB2_SESSION_SETUP_HE]),
44789- atomic_read(&failed[SMB2_SESSION_SETUP_HE]));
44790+ atomic_read_unchecked(&sent[SMB2_SESSION_SETUP_HE]),
44791+ atomic_read_unchecked(&failed[SMB2_SESSION_SETUP_HE]));
44792 #define SMB2LOGOFF 0x0002 /* trivial request/resp */
44793 seq_printf(m, "\nLogoffs: %d sent %d failed",
44794- atomic_read(&sent[SMB2_LOGOFF_HE]),
44795- atomic_read(&failed[SMB2_LOGOFF_HE]));
44796+ atomic_read_unchecked(&sent[SMB2_LOGOFF_HE]),
44797+ atomic_read_unchecked(&failed[SMB2_LOGOFF_HE]));
44798 seq_printf(m, "\nTreeConnects: %d sent %d failed",
44799- atomic_read(&sent[SMB2_TREE_CONNECT_HE]),
44800- atomic_read(&failed[SMB2_TREE_CONNECT_HE]));
44801+ atomic_read_unchecked(&sent[SMB2_TREE_CONNECT_HE]),
44802+ atomic_read_unchecked(&failed[SMB2_TREE_CONNECT_HE]));
44803 seq_printf(m, "\nTreeDisconnects: %d sent %d failed",
44804- atomic_read(&sent[SMB2_TREE_DISCONNECT_HE]),
44805- atomic_read(&failed[SMB2_TREE_DISCONNECT_HE]));
44806+ atomic_read_unchecked(&sent[SMB2_TREE_DISCONNECT_HE]),
44807+ atomic_read_unchecked(&failed[SMB2_TREE_DISCONNECT_HE]));
44808 seq_printf(m, "\nCreates: %d sent %d failed",
44809- atomic_read(&sent[SMB2_CREATE_HE]),
44810- atomic_read(&failed[SMB2_CREATE_HE]));
44811+ atomic_read_unchecked(&sent[SMB2_CREATE_HE]),
44812+ atomic_read_unchecked(&failed[SMB2_CREATE_HE]));
44813 seq_printf(m, "\nCloses: %d sent %d failed",
44814- atomic_read(&sent[SMB2_CLOSE_HE]),
44815- atomic_read(&failed[SMB2_CLOSE_HE]));
44816+ atomic_read_unchecked(&sent[SMB2_CLOSE_HE]),
44817+ atomic_read_unchecked(&failed[SMB2_CLOSE_HE]));
44818 seq_printf(m, "\nFlushes: %d sent %d failed",
44819- atomic_read(&sent[SMB2_FLUSH_HE]),
44820- atomic_read(&failed[SMB2_FLUSH_HE]));
44821+ atomic_read_unchecked(&sent[SMB2_FLUSH_HE]),
44822+ atomic_read_unchecked(&failed[SMB2_FLUSH_HE]));
44823 seq_printf(m, "\nReads: %d sent %d failed",
44824- atomic_read(&sent[SMB2_READ_HE]),
44825- atomic_read(&failed[SMB2_READ_HE]));
44826+ atomic_read_unchecked(&sent[SMB2_READ_HE]),
44827+ atomic_read_unchecked(&failed[SMB2_READ_HE]));
44828 seq_printf(m, "\nWrites: %d sent %d failed",
44829- atomic_read(&sent[SMB2_WRITE_HE]),
44830- atomic_read(&failed[SMB2_WRITE_HE]));
44831+ atomic_read_unchecked(&sent[SMB2_WRITE_HE]),
44832+ atomic_read_unchecked(&failed[SMB2_WRITE_HE]));
44833 seq_printf(m, "\nLocks: %d sent %d failed",
44834- atomic_read(&sent[SMB2_LOCK_HE]),
44835- atomic_read(&failed[SMB2_LOCK_HE]));
44836+ atomic_read_unchecked(&sent[SMB2_LOCK_HE]),
44837+ atomic_read_unchecked(&failed[SMB2_LOCK_HE]));
44838 seq_printf(m, "\nIOCTLs: %d sent %d failed",
44839- atomic_read(&sent[SMB2_IOCTL_HE]),
44840- atomic_read(&failed[SMB2_IOCTL_HE]));
44841+ atomic_read_unchecked(&sent[SMB2_IOCTL_HE]),
44842+ atomic_read_unchecked(&failed[SMB2_IOCTL_HE]));
44843 seq_printf(m, "\nCancels: %d sent %d failed",
44844- atomic_read(&sent[SMB2_CANCEL_HE]),
44845- atomic_read(&failed[SMB2_CANCEL_HE]));
44846+ atomic_read_unchecked(&sent[SMB2_CANCEL_HE]),
44847+ atomic_read_unchecked(&failed[SMB2_CANCEL_HE]));
44848 seq_printf(m, "\nEchos: %d sent %d failed",
44849- atomic_read(&sent[SMB2_ECHO_HE]),
44850- atomic_read(&failed[SMB2_ECHO_HE]));
44851+ atomic_read_unchecked(&sent[SMB2_ECHO_HE]),
44852+ atomic_read_unchecked(&failed[SMB2_ECHO_HE]));
44853 seq_printf(m, "\nQueryDirectories: %d sent %d failed",
44854- atomic_read(&sent[SMB2_QUERY_DIRECTORY_HE]),
44855- atomic_read(&failed[SMB2_QUERY_DIRECTORY_HE]));
44856+ atomic_read_unchecked(&sent[SMB2_QUERY_DIRECTORY_HE]),
44857+ atomic_read_unchecked(&failed[SMB2_QUERY_DIRECTORY_HE]));
44858 seq_printf(m, "\nChangeNotifies: %d sent %d failed",
44859- atomic_read(&sent[SMB2_CHANGE_NOTIFY_HE]),
44860- atomic_read(&failed[SMB2_CHANGE_NOTIFY_HE]));
44861+ atomic_read_unchecked(&sent[SMB2_CHANGE_NOTIFY_HE]),
44862+ atomic_read_unchecked(&failed[SMB2_CHANGE_NOTIFY_HE]));
44863 seq_printf(m, "\nQueryInfos: %d sent %d failed",
44864- atomic_read(&sent[SMB2_QUERY_INFO_HE]),
44865- atomic_read(&failed[SMB2_QUERY_INFO_HE]));
44866+ atomic_read_unchecked(&sent[SMB2_QUERY_INFO_HE]),
44867+ atomic_read_unchecked(&failed[SMB2_QUERY_INFO_HE]));
44868 seq_printf(m, "\nSetInfos: %d sent %d failed",
44869- atomic_read(&sent[SMB2_SET_INFO_HE]),
44870- atomic_read(&failed[SMB2_SET_INFO_HE]));
44871+ atomic_read_unchecked(&sent[SMB2_SET_INFO_HE]),
44872+ atomic_read_unchecked(&failed[SMB2_SET_INFO_HE]));
44873 seq_printf(m, "\nOplockBreaks: %d sent %d failed",
44874- atomic_read(&sent[SMB2_OPLOCK_BREAK_HE]),
44875- atomic_read(&failed[SMB2_OPLOCK_BREAK_HE]));
44876+ atomic_read_unchecked(&sent[SMB2_OPLOCK_BREAK_HE]),
44877+ atomic_read_unchecked(&failed[SMB2_OPLOCK_BREAK_HE]));
44878 #endif
44879 }
44880
44881diff --git a/fs/coda/cache.c b/fs/coda/cache.c
44882index 958ae0e..505c9d0 100644
44883--- a/fs/coda/cache.c
44884+++ b/fs/coda/cache.c
44885@@ -24,7 +24,7 @@
44886 #include "coda_linux.h"
44887 #include "coda_cache.h"
44888
44889-static atomic_t permission_epoch = ATOMIC_INIT(0);
44890+static atomic_unchecked_t permission_epoch = ATOMIC_INIT(0);
44891
44892 /* replace or extend an acl cache hit */
44893 void coda_cache_enter(struct inode *inode, int mask)
44894@@ -32,7 +32,7 @@ void coda_cache_enter(struct inode *inode, int mask)
44895 struct coda_inode_info *cii = ITOC(inode);
44896
44897 spin_lock(&cii->c_lock);
44898- cii->c_cached_epoch = atomic_read(&permission_epoch);
44899+ cii->c_cached_epoch = atomic_read_unchecked(&permission_epoch);
44900 if (cii->c_uid != current_fsuid()) {
44901 cii->c_uid = current_fsuid();
44902 cii->c_cached_perm = mask;
44903@@ -46,14 +46,14 @@ void coda_cache_clear_inode(struct inode *inode)
44904 {
44905 struct coda_inode_info *cii = ITOC(inode);
44906 spin_lock(&cii->c_lock);
44907- cii->c_cached_epoch = atomic_read(&permission_epoch) - 1;
44908+ cii->c_cached_epoch = atomic_read_unchecked(&permission_epoch) - 1;
44909 spin_unlock(&cii->c_lock);
44910 }
44911
44912 /* remove all acl caches */
44913 void coda_cache_clear_all(struct super_block *sb)
44914 {
44915- atomic_inc(&permission_epoch);
44916+ atomic_inc_unchecked(&permission_epoch);
44917 }
44918
44919
44920@@ -66,7 +66,7 @@ int coda_cache_check(struct inode *inode, int mask)
44921 spin_lock(&cii->c_lock);
44922 hit = (mask & cii->c_cached_perm) == mask &&
44923 cii->c_uid == current_fsuid() &&
44924- cii->c_cached_epoch == atomic_read(&permission_epoch);
44925+ cii->c_cached_epoch == atomic_read_unchecked(&permission_epoch);
44926 spin_unlock(&cii->c_lock);
44927
44928 return hit;
44929diff --git a/fs/compat.c b/fs/compat.c
44930index 1bdb350..9f28287 100644
44931--- a/fs/compat.c
44932+++ b/fs/compat.c
44933@@ -490,7 +490,7 @@ compat_sys_io_setup(unsigned nr_reqs, u32 __user *ctx32p)
44934
44935 set_fs(KERNEL_DS);
44936 /* The __user pointer cast is valid because of the set_fs() */
44937- ret = sys_io_setup(nr_reqs, (aio_context_t __user *) &ctx64);
44938+ ret = sys_io_setup(nr_reqs, (aio_context_t __force_user *) &ctx64);
44939 set_fs(oldfs);
44940 /* truncating is ok because it's a user address */
44941 if (!ret)
44942@@ -548,7 +548,7 @@ ssize_t compat_rw_copy_check_uvector(int type,
44943 goto out;
44944
44945 ret = -EINVAL;
44946- if (nr_segs > UIO_MAXIOV || nr_segs < 0)
44947+ if (nr_segs > UIO_MAXIOV)
44948 goto out;
44949 if (nr_segs > fast_segs) {
44950 ret = -ENOMEM;
44951@@ -831,6 +831,7 @@ struct compat_old_linux_dirent {
44952
44953 struct compat_readdir_callback {
44954 struct compat_old_linux_dirent __user *dirent;
44955+ struct file * file;
44956 int result;
44957 };
44958
44959@@ -848,6 +849,10 @@ static int compat_fillonedir(void *__buf, const char *name, int namlen,
44960 buf->result = -EOVERFLOW;
44961 return -EOVERFLOW;
44962 }
44963+
44964+ if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
44965+ return 0;
44966+
44967 buf->result++;
44968 dirent = buf->dirent;
44969 if (!access_ok(VERIFY_WRITE, dirent,
44970@@ -880,6 +885,7 @@ asmlinkage long compat_sys_old_readdir(unsigned int fd,
44971
44972 buf.result = 0;
44973 buf.dirent = dirent;
44974+ buf.file = file;
44975
44976 error = vfs_readdir(file, compat_fillonedir, &buf);
44977 if (buf.result)
44978@@ -899,6 +905,7 @@ struct compat_linux_dirent {
44979 struct compat_getdents_callback {
44980 struct compat_linux_dirent __user *current_dir;
44981 struct compat_linux_dirent __user *previous;
44982+ struct file * file;
44983 int count;
44984 int error;
44985 };
44986@@ -920,6 +927,10 @@ static int compat_filldir(void *__buf, const char *name, int namlen,
44987 buf->error = -EOVERFLOW;
44988 return -EOVERFLOW;
44989 }
44990+
44991+ if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
44992+ return 0;
44993+
44994 dirent = buf->previous;
44995 if (dirent) {
44996 if (__put_user(offset, &dirent->d_off))
44997@@ -966,6 +977,7 @@ asmlinkage long compat_sys_getdents(unsigned int fd,
44998 buf.previous = NULL;
44999 buf.count = count;
45000 buf.error = 0;
45001+ buf.file = file;
45002
45003 error = vfs_readdir(file, compat_filldir, &buf);
45004 if (error >= 0)
45005@@ -986,6 +998,7 @@ asmlinkage long compat_sys_getdents(unsigned int fd,
45006 struct compat_getdents_callback64 {
45007 struct linux_dirent64 __user *current_dir;
45008 struct linux_dirent64 __user *previous;
45009+ struct file * file;
45010 int count;
45011 int error;
45012 };
45013@@ -1002,6 +1015,10 @@ static int compat_filldir64(void * __buf, const char * name, int namlen, loff_t
45014 buf->error = -EINVAL; /* only used if we fail.. */
45015 if (reclen > buf->count)
45016 return -EINVAL;
45017+
45018+ if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
45019+ return 0;
45020+
45021 dirent = buf->previous;
45022
45023 if (dirent) {
45024@@ -1052,13 +1069,14 @@ asmlinkage long compat_sys_getdents64(unsigned int fd,
45025 buf.previous = NULL;
45026 buf.count = count;
45027 buf.error = 0;
45028+ buf.file = file;
45029
45030 error = vfs_readdir(file, compat_filldir64, &buf);
45031 if (error >= 0)
45032 error = buf.error;
45033 lastdirent = buf.previous;
45034 if (lastdirent) {
45035- typeof(lastdirent->d_off) d_off = file->f_pos;
45036+ typeof(((struct linux_dirent64 *)0)->d_off) d_off = file->f_pos;
45037 if (__put_user_unaligned(d_off, &lastdirent->d_off))
45038 error = -EFAULT;
45039 else
45040diff --git a/fs/compat_binfmt_elf.c b/fs/compat_binfmt_elf.c
45041index 112e45a..b59845b 100644
45042--- a/fs/compat_binfmt_elf.c
45043+++ b/fs/compat_binfmt_elf.c
45044@@ -30,11 +30,13 @@
45045 #undef elf_phdr
45046 #undef elf_shdr
45047 #undef elf_note
45048+#undef elf_dyn
45049 #undef elf_addr_t
45050 #define elfhdr elf32_hdr
45051 #define elf_phdr elf32_phdr
45052 #define elf_shdr elf32_shdr
45053 #define elf_note elf32_note
45054+#define elf_dyn Elf32_Dyn
45055 #define elf_addr_t Elf32_Addr
45056
45057 /*
45058diff --git a/fs/compat_ioctl.c b/fs/compat_ioctl.c
45059index 5d2069f..75d31d4 100644
45060--- a/fs/compat_ioctl.c
45061+++ b/fs/compat_ioctl.c
45062@@ -623,7 +623,7 @@ static int serial_struct_ioctl(unsigned fd, unsigned cmd,
45063 return -EFAULT;
45064 if (__get_user(udata, &ss32->iomem_base))
45065 return -EFAULT;
45066- ss.iomem_base = compat_ptr(udata);
45067+ ss.iomem_base = (unsigned char __force_kernel *)compat_ptr(udata);
45068 if (__get_user(ss.iomem_reg_shift, &ss32->iomem_reg_shift) ||
45069 __get_user(ss.port_high, &ss32->port_high))
45070 return -EFAULT;
45071@@ -798,7 +798,7 @@ static int compat_ioctl_preallocate(struct file *file,
45072 copy_in_user(&p->l_len, &p32->l_len, sizeof(s64)) ||
45073 copy_in_user(&p->l_sysid, &p32->l_sysid, sizeof(s32)) ||
45074 copy_in_user(&p->l_pid, &p32->l_pid, sizeof(u32)) ||
45075- copy_in_user(&p->l_pad, &p32->l_pad, 4*sizeof(u32)))
45076+ copy_in_user(p->l_pad, &p32->l_pad, 4*sizeof(u32)))
45077 return -EFAULT;
45078
45079 return ioctl_preallocate(file, p);
45080@@ -1612,8 +1612,8 @@ asmlinkage long compat_sys_ioctl(unsigned int fd, unsigned int cmd,
45081 static int __init init_sys32_ioctl_cmp(const void *p, const void *q)
45082 {
45083 unsigned int a, b;
45084- a = *(unsigned int *)p;
45085- b = *(unsigned int *)q;
45086+ a = *(const unsigned int *)p;
45087+ b = *(const unsigned int *)q;
45088 if (a > b)
45089 return 1;
45090 if (a < b)
45091diff --git a/fs/configfs/dir.c b/fs/configfs/dir.c
45092index 7414ae2..d98ad6d 100644
45093--- a/fs/configfs/dir.c
45094+++ b/fs/configfs/dir.c
45095@@ -1564,7 +1564,8 @@ static int configfs_readdir(struct file * filp, void * dirent, filldir_t filldir
45096 }
45097 for (p=q->next; p!= &parent_sd->s_children; p=p->next) {
45098 struct configfs_dirent *next;
45099- const char * name;
45100+ const unsigned char * name;
45101+ char d_name[sizeof(next->s_dentry->d_iname)];
45102 int len;
45103 struct inode *inode = NULL;
45104
45105@@ -1574,7 +1575,12 @@ static int configfs_readdir(struct file * filp, void * dirent, filldir_t filldir
45106 continue;
45107
45108 name = configfs_get_name(next);
45109- len = strlen(name);
45110+ if (next->s_dentry && name == next->s_dentry->d_iname) {
45111+ len = next->s_dentry->d_name.len;
45112+ memcpy(d_name, name, len);
45113+ name = d_name;
45114+ } else
45115+ len = strlen(name);
45116
45117 /*
45118 * We'll have a dentry and an inode for
45119diff --git a/fs/dcache.c b/fs/dcache.c
45120index 693f95b..95f1223 100644
45121--- a/fs/dcache.c
45122+++ b/fs/dcache.c
45123@@ -3164,7 +3164,7 @@ void __init vfs_caches_init(unsigned long mempages)
45124 mempages -= reserve;
45125
45126 names_cachep = kmem_cache_create("names_cache", PATH_MAX, 0,
45127- SLAB_HWCACHE_ALIGN|SLAB_PANIC, NULL);
45128+ SLAB_HWCACHE_ALIGN|SLAB_PANIC|SLAB_USERCOPY, NULL);
45129
45130 dcache_init();
45131 inode_init();
45132diff --git a/fs/debugfs/inode.c b/fs/debugfs/inode.c
45133index 4733eab..71ef6fa 100644
45134--- a/fs/debugfs/inode.c
45135+++ b/fs/debugfs/inode.c
45136@@ -406,7 +406,11 @@ EXPORT_SYMBOL_GPL(debugfs_create_file);
45137 */
45138 struct dentry *debugfs_create_dir(const char *name, struct dentry *parent)
45139 {
45140+#ifdef CONFIG_GRKERNSEC_SYSFS_RESTRICT
45141+ return __create_file(name, S_IFDIR | S_IRWXU,
45142+#else
45143 return __create_file(name, S_IFDIR | S_IRWXU | S_IRUGO | S_IXUGO,
45144+#endif
45145 parent, NULL, NULL);
45146 }
45147 EXPORT_SYMBOL_GPL(debugfs_create_dir);
45148diff --git a/fs/ecryptfs/inode.c b/fs/ecryptfs/inode.c
45149index cc7709e..7e7211f 100644
45150--- a/fs/ecryptfs/inode.c
45151+++ b/fs/ecryptfs/inode.c
45152@@ -674,7 +674,7 @@ static int ecryptfs_readlink_lower(struct dentry *dentry, char **buf,
45153 old_fs = get_fs();
45154 set_fs(get_ds());
45155 rc = lower_dentry->d_inode->i_op->readlink(lower_dentry,
45156- (char __user *)lower_buf,
45157+ (char __force_user *)lower_buf,
45158 PATH_MAX);
45159 set_fs(old_fs);
45160 if (rc < 0)
45161@@ -706,7 +706,7 @@ out:
45162 static void
45163 ecryptfs_put_link(struct dentry *dentry, struct nameidata *nd, void *ptr)
45164 {
45165- char *buf = nd_get_link(nd);
45166+ const char *buf = nd_get_link(nd);
45167 if (!IS_ERR(buf)) {
45168 /* Free the char* */
45169 kfree(buf);
45170diff --git a/fs/ecryptfs/miscdev.c b/fs/ecryptfs/miscdev.c
45171index 412e6ed..4292d22 100644
45172--- a/fs/ecryptfs/miscdev.c
45173+++ b/fs/ecryptfs/miscdev.c
45174@@ -315,7 +315,7 @@ check_list:
45175 goto out_unlock_msg_ctx;
45176 i = PKT_TYPE_SIZE + PKT_CTR_SIZE;
45177 if (msg_ctx->msg) {
45178- if (copy_to_user(&buf[i], packet_length, packet_length_size))
45179+ if (packet_length_size > sizeof(packet_length) || copy_to_user(&buf[i], packet_length, packet_length_size))
45180 goto out_unlock_msg_ctx;
45181 i += packet_length_size;
45182 if (copy_to_user(&buf[i], msg_ctx->msg, msg_ctx->msg_size))
45183diff --git a/fs/ecryptfs/read_write.c b/fs/ecryptfs/read_write.c
45184index b2a34a1..162fa69 100644
45185--- a/fs/ecryptfs/read_write.c
45186+++ b/fs/ecryptfs/read_write.c
45187@@ -48,7 +48,7 @@ int ecryptfs_write_lower(struct inode *ecryptfs_inode, char *data,
45188 return -EIO;
45189 fs_save = get_fs();
45190 set_fs(get_ds());
45191- rc = vfs_write(lower_file, data, size, &offset);
45192+ rc = vfs_write(lower_file, (const char __force_user *)data, size, &offset);
45193 set_fs(fs_save);
45194 mark_inode_dirty_sync(ecryptfs_inode);
45195 return rc;
45196@@ -244,7 +244,7 @@ int ecryptfs_read_lower(char *data, loff_t offset, size_t size,
45197 return -EIO;
45198 fs_save = get_fs();
45199 set_fs(get_ds());
45200- rc = vfs_read(lower_file, data, size, &offset);
45201+ rc = vfs_read(lower_file, (char __force_user *)data, size, &offset);
45202 set_fs(fs_save);
45203 return rc;
45204 }
45205diff --git a/fs/exec.c b/fs/exec.c
45206index fab2c6d..4fa20c0 100644
45207--- a/fs/exec.c
45208+++ b/fs/exec.c
45209@@ -55,6 +55,15 @@
45210 #include <linux/pipe_fs_i.h>
45211 #include <linux/oom.h>
45212 #include <linux/compat.h>
45213+#include <linux/random.h>
45214+#include <linux/seq_file.h>
45215+
45216+#ifdef CONFIG_PAX_REFCOUNT
45217+#include <linux/kallsyms.h>
45218+#include <linux/kdebug.h>
45219+#endif
45220+
45221+#include <trace/events/fs.h>
45222
45223 #include <asm/uaccess.h>
45224 #include <asm/mmu_context.h>
45225@@ -66,6 +75,18 @@
45226
45227 #include <trace/events/sched.h>
45228
45229+#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
45230+void __weak pax_set_initial_flags(struct linux_binprm *bprm)
45231+{
45232+ WARN_ONCE(1, "PAX: PAX_HAVE_ACL_FLAGS was enabled without providing the pax_set_initial_flags callback, this is probably not what you wanted.\n");
45233+}
45234+#endif
45235+
45236+#ifdef CONFIG_PAX_HOOK_ACL_FLAGS
45237+void (*pax_set_initial_flags_func)(struct linux_binprm *bprm);
45238+EXPORT_SYMBOL(pax_set_initial_flags_func);
45239+#endif
45240+
45241 int core_uses_pid;
45242 char core_pattern[CORENAME_MAX_SIZE] = "core";
45243 unsigned int core_pipe_limit;
45244@@ -75,7 +96,7 @@ struct core_name {
45245 char *corename;
45246 int used, size;
45247 };
45248-static atomic_t call_count = ATOMIC_INIT(1);
45249+static atomic_unchecked_t call_count = ATOMIC_INIT(1);
45250
45251 /* The maximal length of core_pattern is also specified in sysctl.c */
45252
45253@@ -191,18 +212,10 @@ static struct page *get_arg_page(struct linux_binprm *bprm, unsigned long pos,
45254 int write)
45255 {
45256 struct page *page;
45257- int ret;
45258
45259-#ifdef CONFIG_STACK_GROWSUP
45260- if (write) {
45261- ret = expand_downwards(bprm->vma, pos);
45262- if (ret < 0)
45263- return NULL;
45264- }
45265-#endif
45266- ret = get_user_pages(current, bprm->mm, pos,
45267- 1, write, 1, &page, NULL);
45268- if (ret <= 0)
45269+ if (0 > expand_downwards(bprm->vma, pos))
45270+ return NULL;
45271+ if (0 >= get_user_pages(current, bprm->mm, pos, 1, write, 1, &page, NULL))
45272 return NULL;
45273
45274 if (write) {
45275@@ -218,6 +231,17 @@ static struct page *get_arg_page(struct linux_binprm *bprm, unsigned long pos,
45276 if (size <= ARG_MAX)
45277 return page;
45278
45279+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
45280+ // only allow 512KB for argv+env on suid/sgid binaries
45281+ // to prevent easy ASLR exhaustion
45282+ if (((bprm->cred->euid != current_euid()) ||
45283+ (bprm->cred->egid != current_egid())) &&
45284+ (size > (512 * 1024))) {
45285+ put_page(page);
45286+ return NULL;
45287+ }
45288+#endif
45289+
45290 /*
45291 * Limit to 1/4-th the stack size for the argv+env strings.
45292 * This ensures that:
45293@@ -277,6 +301,11 @@ static int __bprm_mm_init(struct linux_binprm *bprm)
45294 vma->vm_end = STACK_TOP_MAX;
45295 vma->vm_start = vma->vm_end - PAGE_SIZE;
45296 vma->vm_flags = VM_STACK_FLAGS | VM_STACK_INCOMPLETE_SETUP;
45297+
45298+#ifdef CONFIG_PAX_SEGMEXEC
45299+ vma->vm_flags &= ~(VM_EXEC | VM_MAYEXEC);
45300+#endif
45301+
45302 vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
45303 INIT_LIST_HEAD(&vma->anon_vma_chain);
45304
45305@@ -287,6 +316,12 @@ static int __bprm_mm_init(struct linux_binprm *bprm)
45306 mm->stack_vm = mm->total_vm = 1;
45307 up_write(&mm->mmap_sem);
45308 bprm->p = vma->vm_end - sizeof(void *);
45309+
45310+#ifdef CONFIG_PAX_RANDUSTACK
45311+ if (randomize_va_space)
45312+ bprm->p ^= random32() & ~PAGE_MASK;
45313+#endif
45314+
45315 return 0;
45316 err:
45317 up_write(&mm->mmap_sem);
45318@@ -395,19 +430,7 @@ err:
45319 return err;
45320 }
45321
45322-struct user_arg_ptr {
45323-#ifdef CONFIG_COMPAT
45324- bool is_compat;
45325-#endif
45326- union {
45327- const char __user *const __user *native;
45328-#ifdef CONFIG_COMPAT
45329- compat_uptr_t __user *compat;
45330-#endif
45331- } ptr;
45332-};
45333-
45334-static const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr)
45335+const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr)
45336 {
45337 const char __user *native;
45338
45339@@ -416,14 +439,14 @@ static const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr)
45340 compat_uptr_t compat;
45341
45342 if (get_user(compat, argv.ptr.compat + nr))
45343- return ERR_PTR(-EFAULT);
45344+ return (const char __force_user *)ERR_PTR(-EFAULT);
45345
45346 return compat_ptr(compat);
45347 }
45348 #endif
45349
45350 if (get_user(native, argv.ptr.native + nr))
45351- return ERR_PTR(-EFAULT);
45352+ return (const char __force_user *)ERR_PTR(-EFAULT);
45353
45354 return native;
45355 }
45356@@ -442,7 +465,7 @@ static int count(struct user_arg_ptr argv, int max)
45357 if (!p)
45358 break;
45359
45360- if (IS_ERR(p))
45361+ if (IS_ERR((const char __force_kernel *)p))
45362 return -EFAULT;
45363
45364 if (i++ >= max)
45365@@ -476,7 +499,7 @@ static int copy_strings(int argc, struct user_arg_ptr argv,
45366
45367 ret = -EFAULT;
45368 str = get_user_arg_ptr(argv, argc);
45369- if (IS_ERR(str))
45370+ if (IS_ERR((const char __force_kernel *)str))
45371 goto out;
45372
45373 len = strnlen_user(str, MAX_ARG_STRLEN);
45374@@ -558,7 +581,7 @@ int copy_strings_kernel(int argc, const char *const *__argv,
45375 int r;
45376 mm_segment_t oldfs = get_fs();
45377 struct user_arg_ptr argv = {
45378- .ptr.native = (const char __user *const __user *)__argv,
45379+ .ptr.native = (const char __force_user *const __force_user *)__argv,
45380 };
45381
45382 set_fs(KERNEL_DS);
45383@@ -593,7 +616,8 @@ static int shift_arg_pages(struct vm_area_struct *vma, unsigned long shift)
45384 unsigned long new_end = old_end - shift;
45385 struct mmu_gather tlb;
45386
45387- BUG_ON(new_start > new_end);
45388+ if (new_start >= new_end || new_start < mmap_min_addr)
45389+ return -ENOMEM;
45390
45391 /*
45392 * ensure there are no vmas between where we want to go
45393@@ -602,6 +626,10 @@ static int shift_arg_pages(struct vm_area_struct *vma, unsigned long shift)
45394 if (vma != find_vma(mm, new_start))
45395 return -EFAULT;
45396
45397+#ifdef CONFIG_PAX_SEGMEXEC
45398+ BUG_ON(pax_find_mirror_vma(vma));
45399+#endif
45400+
45401 /*
45402 * cover the whole range: [new_start, old_end)
45403 */
45404@@ -682,10 +710,6 @@ int setup_arg_pages(struct linux_binprm *bprm,
45405 stack_top = arch_align_stack(stack_top);
45406 stack_top = PAGE_ALIGN(stack_top);
45407
45408- if (unlikely(stack_top < mmap_min_addr) ||
45409- unlikely(vma->vm_end - vma->vm_start >= stack_top - mmap_min_addr))
45410- return -ENOMEM;
45411-
45412 stack_shift = vma->vm_end - stack_top;
45413
45414 bprm->p -= stack_shift;
45415@@ -697,8 +721,28 @@ int setup_arg_pages(struct linux_binprm *bprm,
45416 bprm->exec -= stack_shift;
45417
45418 down_write(&mm->mmap_sem);
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 vm_flags = VM_STACK_FLAGS;
45428
45429+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
45430+ if (mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
45431+ vm_flags &= ~VM_EXEC;
45432+
45433+#ifdef CONFIG_PAX_MPROTECT
45434+ if (mm->pax_flags & MF_PAX_MPROTECT)
45435+ vm_flags &= ~VM_MAYEXEC;
45436+#endif
45437+
45438+ }
45439+#endif
45440+
45441 /*
45442 * Adjust stack execute permissions; explicitly enable for
45443 * EXSTACK_ENABLE_X, disable for EXSTACK_DISABLE_X and leave alone
45444@@ -717,13 +761,6 @@ int setup_arg_pages(struct linux_binprm *bprm,
45445 goto out_unlock;
45446 BUG_ON(prev != vma);
45447
45448- /* Move stack pages down in memory. */
45449- if (stack_shift) {
45450- ret = shift_arg_pages(vma, stack_shift);
45451- if (ret)
45452- goto out_unlock;
45453- }
45454-
45455 /* mprotect_fixup is overkill to remove the temporary stack flags */
45456 vma->vm_flags &= ~VM_STACK_INCOMPLETE_SETUP;
45457
45458@@ -781,6 +818,8 @@ struct file *open_exec(const char *name)
45459
45460 fsnotify_open(file);
45461
45462+ trace_open_exec(name);
45463+
45464 err = deny_write_access(file);
45465 if (err)
45466 goto exit;
45467@@ -804,7 +843,7 @@ int kernel_read(struct file *file, loff_t offset,
45468 old_fs = get_fs();
45469 set_fs(get_ds());
45470 /* The cast to a user pointer is valid due to the set_fs() */
45471- result = vfs_read(file, (void __user *)addr, count, &pos);
45472+ result = vfs_read(file, (void __force_user *)addr, count, &pos);
45473 set_fs(old_fs);
45474 return result;
45475 }
45476@@ -1258,7 +1297,7 @@ static int check_unsafe_exec(struct linux_binprm *bprm)
45477 }
45478 rcu_read_unlock();
45479
45480- if (p->fs->users > n_fs) {
45481+ if (atomic_read(&p->fs->users) > n_fs) {
45482 bprm->unsafe |= LSM_UNSAFE_SHARE;
45483 } else {
45484 res = -EAGAIN;
45485@@ -1461,6 +1500,28 @@ int search_binary_handler(struct linux_binprm *bprm,struct pt_regs *regs)
45486
45487 EXPORT_SYMBOL(search_binary_handler);
45488
45489+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
45490+static DEFINE_PER_CPU(u64, exec_counter);
45491+static int __init init_exec_counters(void)
45492+{
45493+ unsigned int cpu;
45494+
45495+ for_each_possible_cpu(cpu) {
45496+ per_cpu(exec_counter, cpu) = (u64)cpu;
45497+ }
45498+
45499+ return 0;
45500+}
45501+early_initcall(init_exec_counters);
45502+static inline void increment_exec_counter(void)
45503+{
45504+ BUILD_BUG_ON(NR_CPUS > (1 << 16));
45505+ current->exec_id = this_cpu_add_return(exec_counter, 1 << 16);
45506+}
45507+#else
45508+static inline void increment_exec_counter(void) {}
45509+#endif
45510+
45511 /*
45512 * sys_execve() executes a new program.
45513 */
45514@@ -1469,6 +1530,11 @@ static int do_execve_common(const char *filename,
45515 struct user_arg_ptr envp,
45516 struct pt_regs *regs)
45517 {
45518+#ifdef CONFIG_GRKERNSEC
45519+ struct file *old_exec_file;
45520+ struct acl_subject_label *old_acl;
45521+ struct rlimit old_rlim[RLIM_NLIMITS];
45522+#endif
45523 struct linux_binprm *bprm;
45524 struct file *file;
45525 struct files_struct *displaced;
45526@@ -1476,6 +1542,8 @@ static int do_execve_common(const char *filename,
45527 int retval;
45528 const struct cred *cred = current_cred();
45529
45530+ gr_learn_resource(current, RLIMIT_NPROC, atomic_read(&current->cred->user->processes), 1);
45531+
45532 /*
45533 * We move the actual failure in case of RLIMIT_NPROC excess from
45534 * set*uid() to execve() because too many poorly written programs
45535@@ -1516,12 +1584,27 @@ static int do_execve_common(const char *filename,
45536 if (IS_ERR(file))
45537 goto out_unmark;
45538
45539+ if (gr_ptrace_readexec(file, bprm->unsafe)) {
45540+ retval = -EPERM;
45541+ goto out_file;
45542+ }
45543+
45544 sched_exec();
45545
45546 bprm->file = file;
45547 bprm->filename = filename;
45548 bprm->interp = filename;
45549
45550+ if (gr_process_user_ban()) {
45551+ retval = -EPERM;
45552+ goto out_file;
45553+ }
45554+
45555+ if (!gr_acl_handle_execve(file->f_dentry, file->f_vfsmnt)) {
45556+ retval = -EACCES;
45557+ goto out_file;
45558+ }
45559+
45560 retval = bprm_mm_init(bprm);
45561 if (retval)
45562 goto out_file;
45563@@ -1538,24 +1621,65 @@ static int do_execve_common(const char *filename,
45564 if (retval < 0)
45565 goto out;
45566
45567+#ifdef CONFIG_GRKERNSEC
45568+ old_acl = current->acl;
45569+ memcpy(old_rlim, current->signal->rlim, sizeof(old_rlim));
45570+ old_exec_file = current->exec_file;
45571+ get_file(file);
45572+ current->exec_file = file;
45573+#endif
45574+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
45575+ /* limit suid stack to 8MB
45576+ we saved the old limits above and will restore them if this exec fails
45577+ */
45578+ if (((bprm->cred->euid != current_euid()) || (bprm->cred->egid != current_egid())) &&
45579+ (old_rlim[RLIMIT_STACK].rlim_cur > (8 * 1024 * 1024)))
45580+ current->signal->rlim[RLIMIT_STACK].rlim_cur = 8 * 1024 * 1024;
45581+#endif
45582+
45583+ if (!gr_tpe_allow(file)) {
45584+ retval = -EACCES;
45585+ goto out_fail;
45586+ }
45587+
45588+ if (gr_check_crash_exec(file)) {
45589+ retval = -EACCES;
45590+ goto out_fail;
45591+ }
45592+
45593+ retval = gr_set_proc_label(file->f_dentry, file->f_vfsmnt,
45594+ bprm->unsafe);
45595+ if (retval < 0)
45596+ goto out_fail;
45597+
45598 retval = copy_strings_kernel(1, &bprm->filename, bprm);
45599 if (retval < 0)
45600- goto out;
45601+ goto out_fail;
45602
45603 bprm->exec = bprm->p;
45604 retval = copy_strings(bprm->envc, envp, bprm);
45605 if (retval < 0)
45606- goto out;
45607+ goto out_fail;
45608
45609 retval = copy_strings(bprm->argc, argv, bprm);
45610 if (retval < 0)
45611- goto out;
45612+ goto out_fail;
45613+
45614+ gr_log_chroot_exec(file->f_dentry, file->f_vfsmnt);
45615+
45616+ gr_handle_exec_args(bprm, argv);
45617
45618 retval = search_binary_handler(bprm,regs);
45619 if (retval < 0)
45620- goto out;
45621+ goto out_fail;
45622+#ifdef CONFIG_GRKERNSEC
45623+ if (old_exec_file)
45624+ fput(old_exec_file);
45625+#endif
45626
45627 /* execve succeeded */
45628+
45629+ increment_exec_counter();
45630 current->fs->in_exec = 0;
45631 current->in_execve = 0;
45632 acct_update_integrals(current);
45633@@ -1564,6 +1688,14 @@ static int do_execve_common(const char *filename,
45634 put_files_struct(displaced);
45635 return retval;
45636
45637+out_fail:
45638+#ifdef CONFIG_GRKERNSEC
45639+ current->acl = old_acl;
45640+ memcpy(current->signal->rlim, old_rlim, sizeof(old_rlim));
45641+ fput(current->exec_file);
45642+ current->exec_file = old_exec_file;
45643+#endif
45644+
45645 out:
45646 if (bprm->mm) {
45647 acct_arg_size(bprm, 0);
45648@@ -1637,7 +1769,7 @@ static int expand_corename(struct core_name *cn)
45649 {
45650 char *old_corename = cn->corename;
45651
45652- cn->size = CORENAME_MAX_SIZE * atomic_inc_return(&call_count);
45653+ cn->size = CORENAME_MAX_SIZE * atomic_inc_return_unchecked(&call_count);
45654 cn->corename = krealloc(old_corename, cn->size, GFP_KERNEL);
45655
45656 if (!cn->corename) {
45657@@ -1734,7 +1866,7 @@ static int format_corename(struct core_name *cn, long signr)
45658 int pid_in_pattern = 0;
45659 int err = 0;
45660
45661- cn->size = CORENAME_MAX_SIZE * atomic_read(&call_count);
45662+ cn->size = CORENAME_MAX_SIZE * atomic_read_unchecked(&call_count);
45663 cn->corename = kmalloc(cn->size, GFP_KERNEL);
45664 cn->used = 0;
45665
45666@@ -1831,6 +1963,250 @@ out:
45667 return ispipe;
45668 }
45669
45670+int pax_check_flags(unsigned long *flags)
45671+{
45672+ int retval = 0;
45673+
45674+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_SEGMEXEC)
45675+ if (*flags & MF_PAX_SEGMEXEC)
45676+ {
45677+ *flags &= ~MF_PAX_SEGMEXEC;
45678+ retval = -EINVAL;
45679+ }
45680+#endif
45681+
45682+ if ((*flags & MF_PAX_PAGEEXEC)
45683+
45684+#ifdef CONFIG_PAX_PAGEEXEC
45685+ && (*flags & MF_PAX_SEGMEXEC)
45686+#endif
45687+
45688+ )
45689+ {
45690+ *flags &= ~MF_PAX_PAGEEXEC;
45691+ retval = -EINVAL;
45692+ }
45693+
45694+ if ((*flags & MF_PAX_MPROTECT)
45695+
45696+#ifdef CONFIG_PAX_MPROTECT
45697+ && !(*flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC))
45698+#endif
45699+
45700+ )
45701+ {
45702+ *flags &= ~MF_PAX_MPROTECT;
45703+ retval = -EINVAL;
45704+ }
45705+
45706+ if ((*flags & MF_PAX_EMUTRAMP)
45707+
45708+#ifdef CONFIG_PAX_EMUTRAMP
45709+ && !(*flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC))
45710+#endif
45711+
45712+ )
45713+ {
45714+ *flags &= ~MF_PAX_EMUTRAMP;
45715+ retval = -EINVAL;
45716+ }
45717+
45718+ return retval;
45719+}
45720+
45721+EXPORT_SYMBOL(pax_check_flags);
45722+
45723+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
45724+void pax_report_fault(struct pt_regs *regs, void *pc, void *sp)
45725+{
45726+ struct task_struct *tsk = current;
45727+ struct mm_struct *mm = current->mm;
45728+ char *buffer_exec = (char *)__get_free_page(GFP_KERNEL);
45729+ char *buffer_fault = (char *)__get_free_page(GFP_KERNEL);
45730+ char *path_exec = NULL;
45731+ char *path_fault = NULL;
45732+ unsigned long start = 0UL, end = 0UL, offset = 0UL;
45733+
45734+ if (buffer_exec && buffer_fault) {
45735+ struct vm_area_struct *vma, *vma_exec = NULL, *vma_fault = NULL;
45736+
45737+ down_read(&mm->mmap_sem);
45738+ vma = mm->mmap;
45739+ while (vma && (!vma_exec || !vma_fault)) {
45740+ if ((vma->vm_flags & VM_EXECUTABLE) && vma->vm_file)
45741+ vma_exec = vma;
45742+ if (vma->vm_start <= (unsigned long)pc && (unsigned long)pc < vma->vm_end)
45743+ vma_fault = vma;
45744+ vma = vma->vm_next;
45745+ }
45746+ if (vma_exec) {
45747+ path_exec = d_path(&vma_exec->vm_file->f_path, buffer_exec, PAGE_SIZE);
45748+ if (IS_ERR(path_exec))
45749+ path_exec = "<path too long>";
45750+ else {
45751+ path_exec = mangle_path(buffer_exec, path_exec, "\t\n\\");
45752+ if (path_exec) {
45753+ *path_exec = 0;
45754+ path_exec = buffer_exec;
45755+ } else
45756+ path_exec = "<path too long>";
45757+ }
45758+ }
45759+ if (vma_fault) {
45760+ start = vma_fault->vm_start;
45761+ end = vma_fault->vm_end;
45762+ offset = vma_fault->vm_pgoff << PAGE_SHIFT;
45763+ if (vma_fault->vm_file) {
45764+ path_fault = d_path(&vma_fault->vm_file->f_path, buffer_fault, PAGE_SIZE);
45765+ if (IS_ERR(path_fault))
45766+ path_fault = "<path too long>";
45767+ else {
45768+ path_fault = mangle_path(buffer_fault, path_fault, "\t\n\\");
45769+ if (path_fault) {
45770+ *path_fault = 0;
45771+ path_fault = buffer_fault;
45772+ } else
45773+ path_fault = "<path too long>";
45774+ }
45775+ } else
45776+ path_fault = "<anonymous mapping>";
45777+ }
45778+ up_read(&mm->mmap_sem);
45779+ }
45780+ if (tsk->signal->curr_ip)
45781+ printk(KERN_ERR "PAX: From %pI4: execution attempt in: %s, %08lx-%08lx %08lx\n", &tsk->signal->curr_ip, path_fault, start, end, offset);
45782+ else
45783+ printk(KERN_ERR "PAX: execution attempt in: %s, %08lx-%08lx %08lx\n", path_fault, start, end, offset);
45784+ printk(KERN_ERR "PAX: terminating task: %s(%s):%d, uid/euid: %u/%u, "
45785+ "PC: %p, SP: %p\n", path_exec, tsk->comm, task_pid_nr(tsk),
45786+ task_uid(tsk), task_euid(tsk), pc, sp);
45787+ free_page((unsigned long)buffer_exec);
45788+ free_page((unsigned long)buffer_fault);
45789+ pax_report_insns(regs, pc, sp);
45790+ do_coredump(SIGKILL, SIGKILL, regs);
45791+}
45792+#endif
45793+
45794+#ifdef CONFIG_PAX_REFCOUNT
45795+void pax_report_refcount_overflow(struct pt_regs *regs)
45796+{
45797+ if (current->signal->curr_ip)
45798+ printk(KERN_ERR "PAX: From %pI4: refcount overflow detected in: %s:%d, uid/euid: %u/%u\n",
45799+ &current->signal->curr_ip, current->comm, task_pid_nr(current), current_uid(), current_euid());
45800+ else
45801+ printk(KERN_ERR "PAX: refcount overflow detected in: %s:%d, uid/euid: %u/%u\n",
45802+ current->comm, task_pid_nr(current), current_uid(), current_euid());
45803+ print_symbol(KERN_ERR "PAX: refcount overflow occured at: %s\n", instruction_pointer(regs));
45804+ show_regs(regs);
45805+ force_sig_info(SIGKILL, SEND_SIG_FORCED, current);
45806+}
45807+#endif
45808+
45809+#ifdef CONFIG_PAX_USERCOPY
45810+/* 0: not at all, 1: fully, 2: fully inside frame, -1: partially (implies an error) */
45811+static noinline int check_stack_object(const void *obj, unsigned long len)
45812+{
45813+ const void * const stack = task_stack_page(current);
45814+ const void * const stackend = stack + THREAD_SIZE;
45815+
45816+#if defined(CONFIG_FRAME_POINTER) && defined(CONFIG_X86)
45817+ const void *frame = NULL;
45818+ const void *oldframe;
45819+#endif
45820+
45821+ if (obj + len < obj)
45822+ return -1;
45823+
45824+ if (obj + len <= stack || stackend <= obj)
45825+ return 0;
45826+
45827+ if (obj < stack || stackend < obj + len)
45828+ return -1;
45829+
45830+#if defined(CONFIG_FRAME_POINTER) && defined(CONFIG_X86)
45831+ oldframe = __builtin_frame_address(1);
45832+ if (oldframe)
45833+ frame = __builtin_frame_address(2);
45834+ /*
45835+ low ----------------------------------------------> high
45836+ [saved bp][saved ip][args][local vars][saved bp][saved ip]
45837+ ^----------------^
45838+ allow copies only within here
45839+ */
45840+ while (stack <= frame && frame < stackend) {
45841+ /* if obj + len extends past the last frame, this
45842+ check won't pass and the next frame will be 0,
45843+ causing us to bail out and correctly report
45844+ the copy as invalid
45845+ */
45846+ if (obj + len <= frame)
45847+ return obj >= oldframe + 2 * sizeof(void *) ? 2 : -1;
45848+ oldframe = frame;
45849+ frame = *(const void * const *)frame;
45850+ }
45851+ return -1;
45852+#else
45853+ return 1;
45854+#endif
45855+}
45856+
45857+static __noreturn void pax_report_usercopy(const void *ptr, unsigned long len, bool to, const char *type)
45858+{
45859+ if (current->signal->curr_ip)
45860+ printk(KERN_ERR "PAX: From %pI4: kernel memory %s attempt detected %s %p (%s) (%lu bytes)\n",
45861+ &current->signal->curr_ip, to ? "leak" : "overwrite", to ? "from" : "to", ptr, type ? : "unknown", len);
45862+ else
45863+ printk(KERN_ERR "PAX: kernel memory %s attempt detected %s %p (%s) (%lu bytes)\n",
45864+ to ? "leak" : "overwrite", to ? "from" : "to", ptr, type ? : "unknown", len);
45865+ dump_stack();
45866+ gr_handle_kernel_exploit();
45867+ do_group_exit(SIGKILL);
45868+}
45869+#endif
45870+
45871+void check_object_size(const void *ptr, unsigned long n, bool to)
45872+{
45873+
45874+#ifdef CONFIG_PAX_USERCOPY
45875+ const char *type;
45876+
45877+ if (!n)
45878+ return;
45879+
45880+ type = check_heap_object(ptr, n, to);
45881+ if (!type) {
45882+ if (check_stack_object(ptr, n) != -1)
45883+ return;
45884+ type = "<process stack>";
45885+ }
45886+
45887+ pax_report_usercopy(ptr, n, to, type);
45888+#endif
45889+
45890+}
45891+EXPORT_SYMBOL(check_object_size);
45892+
45893+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
45894+void pax_track_stack(void)
45895+{
45896+ unsigned long sp = (unsigned long)&sp;
45897+ if (sp < current_thread_info()->lowest_stack &&
45898+ sp > (unsigned long)task_stack_page(current))
45899+ current_thread_info()->lowest_stack = sp;
45900+}
45901+EXPORT_SYMBOL(pax_track_stack);
45902+#endif
45903+
45904+#ifdef CONFIG_PAX_SIZE_OVERFLOW
45905+void report_size_overflow(const char *file, unsigned int line, const char *func, const char *ssa_name)
45906+{
45907+ printk(KERN_ERR "PAX: size overflow detected in function %s %s:%u %s", func, file, line, ssa_name);
45908+ dump_stack();
45909+ do_group_exit(SIGKILL);
45910+}
45911+EXPORT_SYMBOL(report_size_overflow);
45912+#endif
45913+
45914 static int zap_process(struct task_struct *start, int exit_code)
45915 {
45916 struct task_struct *t;
45917@@ -2041,17 +2417,17 @@ static void wait_for_dump_helpers(struct file *file)
45918 pipe = file->f_path.dentry->d_inode->i_pipe;
45919
45920 pipe_lock(pipe);
45921- pipe->readers++;
45922- pipe->writers--;
45923+ atomic_inc(&pipe->readers);
45924+ atomic_dec(&pipe->writers);
45925
45926- while ((pipe->readers > 1) && (!signal_pending(current))) {
45927+ while ((atomic_read(&pipe->readers) > 1) && (!signal_pending(current))) {
45928 wake_up_interruptible_sync(&pipe->wait);
45929 kill_fasync(&pipe->fasync_readers, SIGIO, POLL_IN);
45930 pipe_wait(pipe);
45931 }
45932
45933- pipe->readers--;
45934- pipe->writers++;
45935+ atomic_dec(&pipe->readers);
45936+ atomic_inc(&pipe->writers);
45937 pipe_unlock(pipe);
45938
45939 }
45940@@ -2106,7 +2482,7 @@ void do_coredump(long signr, int exit_code, struct pt_regs *regs)
45941 int flag = 0;
45942 int ispipe;
45943 bool need_nonrelative = false;
45944- static atomic_t core_dump_count = ATOMIC_INIT(0);
45945+ static atomic_unchecked_t core_dump_count = ATOMIC_INIT(0);
45946 struct coredump_params cprm = {
45947 .signr = signr,
45948 .regs = regs,
45949@@ -2121,6 +2497,9 @@ void do_coredump(long signr, int exit_code, struct pt_regs *regs)
45950
45951 audit_core_dumps(signr);
45952
45953+ if (signr == SIGSEGV || signr == SIGBUS || signr == SIGKILL || signr == SIGILL)
45954+ gr_handle_brute_attach(current, cprm.mm_flags);
45955+
45956 binfmt = mm->binfmt;
45957 if (!binfmt || !binfmt->core_dump)
45958 goto fail;
45959@@ -2191,7 +2570,7 @@ void do_coredump(long signr, int exit_code, struct pt_regs *regs)
45960 }
45961 cprm.limit = RLIM_INFINITY;
45962
45963- dump_count = atomic_inc_return(&core_dump_count);
45964+ dump_count = atomic_inc_return_unchecked(&core_dump_count);
45965 if (core_pipe_limit && (core_pipe_limit < dump_count)) {
45966 printk(KERN_WARNING "Pid %d(%s) over core_pipe_limit\n",
45967 task_tgid_vnr(current), current->comm);
45968@@ -2218,6 +2597,8 @@ void do_coredump(long signr, int exit_code, struct pt_regs *regs)
45969 } else {
45970 struct inode *inode;
45971
45972+ gr_learn_resource(current, RLIMIT_CORE, binfmt->min_coredump, 1);
45973+
45974 if (cprm.limit < binfmt->min_coredump)
45975 goto fail_unlock;
45976
45977@@ -2269,7 +2650,7 @@ close_fail:
45978 filp_close(cprm.file, NULL);
45979 fail_dropcount:
45980 if (ispipe)
45981- atomic_dec(&core_dump_count);
45982+ atomic_dec_unchecked(&core_dump_count);
45983 fail_unlock:
45984 kfree(cn.corename);
45985 fail_corename:
45986@@ -2288,7 +2669,7 @@ fail:
45987 */
45988 int dump_write(struct file *file, const void *addr, int nr)
45989 {
45990- return access_ok(VERIFY_READ, addr, nr) && file->f_op->write(file, addr, nr, &file->f_pos) == nr;
45991+ return access_ok(VERIFY_READ, addr, nr) && file->f_op->write(file, (const char __force_user *)addr, nr, &file->f_pos) == nr;
45992 }
45993 EXPORT_SYMBOL(dump_write);
45994
45995diff --git a/fs/ext2/balloc.c b/fs/ext2/balloc.c
45996index 376aa77..59a129c 100644
45997--- a/fs/ext2/balloc.c
45998+++ b/fs/ext2/balloc.c
45999@@ -1190,10 +1190,10 @@ static int ext2_has_free_blocks(struct ext2_sb_info *sbi)
46000
46001 free_blocks = percpu_counter_read_positive(&sbi->s_freeblocks_counter);
46002 root_blocks = le32_to_cpu(sbi->s_es->s_r_blocks_count);
46003- if (free_blocks < root_blocks + 1 && !capable(CAP_SYS_RESOURCE) &&
46004+ if (free_blocks < root_blocks + 1 &&
46005 !uid_eq(sbi->s_resuid, current_fsuid()) &&
46006 (gid_eq(sbi->s_resgid, GLOBAL_ROOT_GID) ||
46007- !in_group_p (sbi->s_resgid))) {
46008+ !in_group_p (sbi->s_resgid)) && !capable_nolog(CAP_SYS_RESOURCE)) {
46009 return 0;
46010 }
46011 return 1;
46012diff --git a/fs/ext3/balloc.c b/fs/ext3/balloc.c
46013index 90d901f..159975f 100644
46014--- a/fs/ext3/balloc.c
46015+++ b/fs/ext3/balloc.c
46016@@ -1438,10 +1438,10 @@ static int ext3_has_free_blocks(struct ext3_sb_info *sbi, int use_reservation)
46017
46018 free_blocks = percpu_counter_read_positive(&sbi->s_freeblocks_counter);
46019 root_blocks = le32_to_cpu(sbi->s_es->s_r_blocks_count);
46020- if (free_blocks < root_blocks + 1 && !capable(CAP_SYS_RESOURCE) &&
46021+ if (free_blocks < root_blocks + 1 &&
46022 !use_reservation && !uid_eq(sbi->s_resuid, current_fsuid()) &&
46023 (gid_eq(sbi->s_resgid, GLOBAL_ROOT_GID) ||
46024- !in_group_p (sbi->s_resgid))) {
46025+ !in_group_p (sbi->s_resgid)) && !capable_nolog(CAP_SYS_RESOURCE)) {
46026 return 0;
46027 }
46028 return 1;
46029diff --git a/fs/ext4/balloc.c b/fs/ext4/balloc.c
46030index cf18217..8f6b9c3 100644
46031--- a/fs/ext4/balloc.c
46032+++ b/fs/ext4/balloc.c
46033@@ -498,8 +498,8 @@ static int ext4_has_free_clusters(struct ext4_sb_info *sbi,
46034 /* Hm, nope. Are (enough) root reserved clusters available? */
46035 if (uid_eq(sbi->s_resuid, current_fsuid()) ||
46036 (!gid_eq(sbi->s_resgid, GLOBAL_ROOT_GID) && in_group_p(sbi->s_resgid)) ||
46037- capable(CAP_SYS_RESOURCE) ||
46038- (flags & EXT4_MB_USE_ROOT_BLOCKS)) {
46039+ (flags & EXT4_MB_USE_ROOT_BLOCKS) ||
46040+ capable_nolog(CAP_SYS_RESOURCE)) {
46041
46042 if (free_clusters >= (nclusters + dirty_clusters))
46043 return 1;
46044diff --git a/fs/ext4/ext4.h b/fs/ext4/ext4.h
46045index 5c69f2b..05dec7f 100644
46046--- a/fs/ext4/ext4.h
46047+++ b/fs/ext4/ext4.h
46048@@ -1248,19 +1248,19 @@ struct ext4_sb_info {
46049 unsigned long s_mb_last_start;
46050
46051 /* stats for buddy allocator */
46052- atomic_t s_bal_reqs; /* number of reqs with len > 1 */
46053- atomic_t s_bal_success; /* we found long enough chunks */
46054- atomic_t s_bal_allocated; /* in blocks */
46055- atomic_t s_bal_ex_scanned; /* total extents scanned */
46056- atomic_t s_bal_goals; /* goal hits */
46057- atomic_t s_bal_breaks; /* too long searches */
46058- atomic_t s_bal_2orders; /* 2^order hits */
46059+ atomic_unchecked_t s_bal_reqs; /* number of reqs with len > 1 */
46060+ atomic_unchecked_t s_bal_success; /* we found long enough chunks */
46061+ atomic_unchecked_t s_bal_allocated; /* in blocks */
46062+ atomic_unchecked_t s_bal_ex_scanned; /* total extents scanned */
46063+ atomic_unchecked_t s_bal_goals; /* goal hits */
46064+ atomic_unchecked_t s_bal_breaks; /* too long searches */
46065+ atomic_unchecked_t s_bal_2orders; /* 2^order hits */
46066 spinlock_t s_bal_lock;
46067 unsigned long s_mb_buddies_generated;
46068 unsigned long long s_mb_generation_time;
46069- atomic_t s_mb_lost_chunks;
46070- atomic_t s_mb_preallocated;
46071- atomic_t s_mb_discarded;
46072+ atomic_unchecked_t s_mb_lost_chunks;
46073+ atomic_unchecked_t s_mb_preallocated;
46074+ atomic_unchecked_t s_mb_discarded;
46075 atomic_t s_lock_busy;
46076
46077 /* locality groups */
46078diff --git a/fs/ext4/mballoc.c b/fs/ext4/mballoc.c
46079index b26410c..7383d90 100644
46080--- a/fs/ext4/mballoc.c
46081+++ b/fs/ext4/mballoc.c
46082@@ -1746,7 +1746,7 @@ void ext4_mb_simple_scan_group(struct ext4_allocation_context *ac,
46083 BUG_ON(ac->ac_b_ex.fe_len != ac->ac_g_ex.fe_len);
46084
46085 if (EXT4_SB(sb)->s_mb_stats)
46086- atomic_inc(&EXT4_SB(sb)->s_bal_2orders);
46087+ atomic_inc_unchecked(&EXT4_SB(sb)->s_bal_2orders);
46088
46089 break;
46090 }
46091@@ -2040,7 +2040,7 @@ repeat:
46092 ac->ac_status = AC_STATUS_CONTINUE;
46093 ac->ac_flags |= EXT4_MB_HINT_FIRST;
46094 cr = 3;
46095- atomic_inc(&sbi->s_mb_lost_chunks);
46096+ atomic_inc_unchecked(&sbi->s_mb_lost_chunks);
46097 goto repeat;
46098 }
46099 }
46100@@ -2551,25 +2551,25 @@ int ext4_mb_release(struct super_block *sb)
46101 if (sbi->s_mb_stats) {
46102 ext4_msg(sb, KERN_INFO,
46103 "mballoc: %u blocks %u reqs (%u success)",
46104- atomic_read(&sbi->s_bal_allocated),
46105- atomic_read(&sbi->s_bal_reqs),
46106- atomic_read(&sbi->s_bal_success));
46107+ atomic_read_unchecked(&sbi->s_bal_allocated),
46108+ atomic_read_unchecked(&sbi->s_bal_reqs),
46109+ atomic_read_unchecked(&sbi->s_bal_success));
46110 ext4_msg(sb, KERN_INFO,
46111 "mballoc: %u extents scanned, %u goal hits, "
46112 "%u 2^N hits, %u breaks, %u lost",
46113- atomic_read(&sbi->s_bal_ex_scanned),
46114- atomic_read(&sbi->s_bal_goals),
46115- atomic_read(&sbi->s_bal_2orders),
46116- atomic_read(&sbi->s_bal_breaks),
46117- atomic_read(&sbi->s_mb_lost_chunks));
46118+ atomic_read_unchecked(&sbi->s_bal_ex_scanned),
46119+ atomic_read_unchecked(&sbi->s_bal_goals),
46120+ atomic_read_unchecked(&sbi->s_bal_2orders),
46121+ atomic_read_unchecked(&sbi->s_bal_breaks),
46122+ atomic_read_unchecked(&sbi->s_mb_lost_chunks));
46123 ext4_msg(sb, KERN_INFO,
46124 "mballoc: %lu generated and it took %Lu",
46125 sbi->s_mb_buddies_generated,
46126 sbi->s_mb_generation_time);
46127 ext4_msg(sb, KERN_INFO,
46128 "mballoc: %u preallocated, %u discarded",
46129- atomic_read(&sbi->s_mb_preallocated),
46130- atomic_read(&sbi->s_mb_discarded));
46131+ atomic_read_unchecked(&sbi->s_mb_preallocated),
46132+ atomic_read_unchecked(&sbi->s_mb_discarded));
46133 }
46134
46135 free_percpu(sbi->s_locality_groups);
46136@@ -3051,16 +3051,16 @@ static void ext4_mb_collect_stats(struct ext4_allocation_context *ac)
46137 struct ext4_sb_info *sbi = EXT4_SB(ac->ac_sb);
46138
46139 if (sbi->s_mb_stats && ac->ac_g_ex.fe_len > 1) {
46140- atomic_inc(&sbi->s_bal_reqs);
46141- atomic_add(ac->ac_b_ex.fe_len, &sbi->s_bal_allocated);
46142+ atomic_inc_unchecked(&sbi->s_bal_reqs);
46143+ atomic_add_unchecked(ac->ac_b_ex.fe_len, &sbi->s_bal_allocated);
46144 if (ac->ac_b_ex.fe_len >= ac->ac_o_ex.fe_len)
46145- atomic_inc(&sbi->s_bal_success);
46146- atomic_add(ac->ac_found, &sbi->s_bal_ex_scanned);
46147+ atomic_inc_unchecked(&sbi->s_bal_success);
46148+ atomic_add_unchecked(ac->ac_found, &sbi->s_bal_ex_scanned);
46149 if (ac->ac_g_ex.fe_start == ac->ac_b_ex.fe_start &&
46150 ac->ac_g_ex.fe_group == ac->ac_b_ex.fe_group)
46151- atomic_inc(&sbi->s_bal_goals);
46152+ atomic_inc_unchecked(&sbi->s_bal_goals);
46153 if (ac->ac_found > sbi->s_mb_max_to_scan)
46154- atomic_inc(&sbi->s_bal_breaks);
46155+ atomic_inc_unchecked(&sbi->s_bal_breaks);
46156 }
46157
46158 if (ac->ac_op == EXT4_MB_HISTORY_ALLOC)
46159@@ -3460,7 +3460,7 @@ ext4_mb_new_inode_pa(struct ext4_allocation_context *ac)
46160 trace_ext4_mb_new_inode_pa(ac, pa);
46161
46162 ext4_mb_use_inode_pa(ac, pa);
46163- atomic_add(pa->pa_free, &sbi->s_mb_preallocated);
46164+ atomic_add_unchecked(pa->pa_free, &sbi->s_mb_preallocated);
46165
46166 ei = EXT4_I(ac->ac_inode);
46167 grp = ext4_get_group_info(sb, ac->ac_b_ex.fe_group);
46168@@ -3520,7 +3520,7 @@ ext4_mb_new_group_pa(struct ext4_allocation_context *ac)
46169 trace_ext4_mb_new_group_pa(ac, pa);
46170
46171 ext4_mb_use_group_pa(ac, pa);
46172- atomic_add(pa->pa_free, &EXT4_SB(sb)->s_mb_preallocated);
46173+ atomic_add_unchecked(pa->pa_free, &EXT4_SB(sb)->s_mb_preallocated);
46174
46175 grp = ext4_get_group_info(sb, ac->ac_b_ex.fe_group);
46176 lg = ac->ac_lg;
46177@@ -3609,7 +3609,7 @@ ext4_mb_release_inode_pa(struct ext4_buddy *e4b, struct buffer_head *bitmap_bh,
46178 * from the bitmap and continue.
46179 */
46180 }
46181- atomic_add(free, &sbi->s_mb_discarded);
46182+ atomic_add_unchecked(free, &sbi->s_mb_discarded);
46183
46184 return err;
46185 }
46186@@ -3627,7 +3627,7 @@ ext4_mb_release_group_pa(struct ext4_buddy *e4b,
46187 ext4_get_group_no_and_offset(sb, pa->pa_pstart, &group, &bit);
46188 BUG_ON(group != e4b->bd_group && pa->pa_len != 0);
46189 mb_free_blocks(pa->pa_inode, e4b, bit, pa->pa_len);
46190- atomic_add(pa->pa_len, &EXT4_SB(sb)->s_mb_discarded);
46191+ atomic_add_unchecked(pa->pa_len, &EXT4_SB(sb)->s_mb_discarded);
46192 trace_ext4_mballoc_discard(sb, NULL, group, bit, pa->pa_len);
46193
46194 return 0;
46195diff --git a/fs/fcntl.c b/fs/fcntl.c
46196index 887b5ba..0e3f2c3 100644
46197--- a/fs/fcntl.c
46198+++ b/fs/fcntl.c
46199@@ -225,6 +225,11 @@ int __f_setown(struct file *filp, struct pid *pid, enum pid_type type,
46200 if (err)
46201 return err;
46202
46203+ if (gr_handle_chroot_fowner(pid, type))
46204+ return -ENOENT;
46205+ if (gr_check_protected_task_fowner(pid, type))
46206+ return -EACCES;
46207+
46208 f_modown(filp, pid, type, force);
46209 return 0;
46210 }
46211@@ -267,7 +272,7 @@ pid_t f_getown(struct file *filp)
46212
46213 static int f_setown_ex(struct file *filp, unsigned long arg)
46214 {
46215- struct f_owner_ex * __user owner_p = (void * __user)arg;
46216+ struct f_owner_ex __user *owner_p = (void __user *)arg;
46217 struct f_owner_ex owner;
46218 struct pid *pid;
46219 int type;
46220@@ -307,7 +312,7 @@ static int f_setown_ex(struct file *filp, unsigned long arg)
46221
46222 static int f_getown_ex(struct file *filp, unsigned long arg)
46223 {
46224- struct f_owner_ex * __user owner_p = (void * __user)arg;
46225+ struct f_owner_ex __user *owner_p = (void __user *)arg;
46226 struct f_owner_ex owner;
46227 int ret = 0;
46228
46229@@ -374,6 +379,7 @@ static long do_fcntl(int fd, unsigned int cmd, unsigned long arg,
46230 switch (cmd) {
46231 case F_DUPFD:
46232 case F_DUPFD_CLOEXEC:
46233+ gr_learn_resource(current, RLIMIT_NOFILE, arg, 0);
46234 if (arg >= rlimit(RLIMIT_NOFILE))
46235 break;
46236 err = alloc_fd(arg, cmd == F_DUPFD_CLOEXEC ? O_CLOEXEC : 0);
46237diff --git a/fs/fifo.c b/fs/fifo.c
46238index cf6f434..3d7942c 100644
46239--- a/fs/fifo.c
46240+++ b/fs/fifo.c
46241@@ -59,10 +59,10 @@ static int fifo_open(struct inode *inode, struct file *filp)
46242 */
46243 filp->f_op = &read_pipefifo_fops;
46244 pipe->r_counter++;
46245- if (pipe->readers++ == 0)
46246+ if (atomic_inc_return(&pipe->readers) == 1)
46247 wake_up_partner(inode);
46248
46249- if (!pipe->writers) {
46250+ if (!atomic_read(&pipe->writers)) {
46251 if ((filp->f_flags & O_NONBLOCK)) {
46252 /* suppress POLLHUP until we have
46253 * seen a writer */
46254@@ -81,15 +81,15 @@ static int fifo_open(struct inode *inode, struct file *filp)
46255 * errno=ENXIO when there is no process reading the FIFO.
46256 */
46257 ret = -ENXIO;
46258- if ((filp->f_flags & O_NONBLOCK) && !pipe->readers)
46259+ if ((filp->f_flags & O_NONBLOCK) && !atomic_read(&pipe->readers))
46260 goto err;
46261
46262 filp->f_op = &write_pipefifo_fops;
46263 pipe->w_counter++;
46264- if (!pipe->writers++)
46265+ if (atomic_inc_return(&pipe->writers) == 1)
46266 wake_up_partner(inode);
46267
46268- if (!pipe->readers) {
46269+ if (!atomic_read(&pipe->readers)) {
46270 if (wait_for_partner(inode, &pipe->r_counter))
46271 goto err_wr;
46272 }
46273@@ -104,11 +104,11 @@ static int fifo_open(struct inode *inode, struct file *filp)
46274 */
46275 filp->f_op = &rdwr_pipefifo_fops;
46276
46277- pipe->readers++;
46278- pipe->writers++;
46279+ atomic_inc(&pipe->readers);
46280+ atomic_inc(&pipe->writers);
46281 pipe->r_counter++;
46282 pipe->w_counter++;
46283- if (pipe->readers == 1 || pipe->writers == 1)
46284+ if (atomic_read(&pipe->readers) == 1 || atomic_read(&pipe->writers) == 1)
46285 wake_up_partner(inode);
46286 break;
46287
46288@@ -122,19 +122,19 @@ static int fifo_open(struct inode *inode, struct file *filp)
46289 return 0;
46290
46291 err_rd:
46292- if (!--pipe->readers)
46293+ if (atomic_dec_and_test(&pipe->readers))
46294 wake_up_interruptible(&pipe->wait);
46295 ret = -ERESTARTSYS;
46296 goto err;
46297
46298 err_wr:
46299- if (!--pipe->writers)
46300+ if (atomic_dec_and_test(&pipe->writers))
46301 wake_up_interruptible(&pipe->wait);
46302 ret = -ERESTARTSYS;
46303 goto err;
46304
46305 err:
46306- if (!pipe->readers && !pipe->writers)
46307+ if (!atomic_read(&pipe->readers) && !atomic_read(&pipe->writers))
46308 free_pipe_info(inode);
46309
46310 err_nocleanup:
46311diff --git a/fs/file.c b/fs/file.c
46312index ba3f605..fade102 100644
46313--- a/fs/file.c
46314+++ b/fs/file.c
46315@@ -15,6 +15,7 @@
46316 #include <linux/slab.h>
46317 #include <linux/vmalloc.h>
46318 #include <linux/file.h>
46319+#include <linux/security.h>
46320 #include <linux/fdtable.h>
46321 #include <linux/bitops.h>
46322 #include <linux/interrupt.h>
46323@@ -255,6 +256,7 @@ int expand_files(struct files_struct *files, int nr)
46324 * N.B. For clone tasks sharing a files structure, this test
46325 * will limit the total number of files that can be opened.
46326 */
46327+ gr_learn_resource(current, RLIMIT_NOFILE, nr, 0);
46328 if (nr >= rlimit(RLIMIT_NOFILE))
46329 return -EMFILE;
46330
46331diff --git a/fs/filesystems.c b/fs/filesystems.c
46332index 96f2428..f5eeb8e 100644
46333--- a/fs/filesystems.c
46334+++ b/fs/filesystems.c
46335@@ -273,7 +273,12 @@ struct file_system_type *get_fs_type(const char *name)
46336 int len = dot ? dot - name : strlen(name);
46337
46338 fs = __get_fs_type(name, len);
46339+
46340+#ifdef CONFIG_GRKERNSEC_MODHARDEN
46341+ if (!fs && (___request_module(true, "grsec_modharden_fs", "%.*s", len, name) == 0))
46342+#else
46343 if (!fs && (request_module("%.*s", len, name) == 0))
46344+#endif
46345 fs = __get_fs_type(name, len);
46346
46347 if (dot && fs && !(fs->fs_flags & FS_HAS_SUBTYPE)) {
46348diff --git a/fs/fs_struct.c b/fs/fs_struct.c
46349index 5df4775..f656176 100644
46350--- a/fs/fs_struct.c
46351+++ b/fs/fs_struct.c
46352@@ -4,6 +4,7 @@
46353 #include <linux/path.h>
46354 #include <linux/slab.h>
46355 #include <linux/fs_struct.h>
46356+#include <linux/grsecurity.h>
46357 #include "internal.h"
46358
46359 /*
46360@@ -19,6 +20,7 @@ void set_fs_root(struct fs_struct *fs, struct path *path)
46361 write_seqcount_begin(&fs->seq);
46362 old_root = fs->root;
46363 fs->root = *path;
46364+ gr_set_chroot_entries(current, path);
46365 write_seqcount_end(&fs->seq);
46366 spin_unlock(&fs->lock);
46367 if (old_root.dentry)
46368@@ -53,6 +55,21 @@ static inline int replace_path(struct path *p, const struct path *old, const str
46369 return 1;
46370 }
46371
46372+static inline int replace_root_path(struct task_struct *task, struct path *p, const struct path *old, struct path *new)
46373+{
46374+ if (likely(p->dentry != old->dentry || p->mnt != old->mnt))
46375+ return 0;
46376+ *p = *new;
46377+
46378+ /* This function is only called from pivot_root(). Leave our
46379+ gr_chroot_dentry and is_chrooted flags as-is, so that a
46380+ pivoted root isn't treated as a chroot
46381+ */
46382+ //gr_set_chroot_entries(task, new);
46383+
46384+ return 1;
46385+}
46386+
46387 void chroot_fs_refs(struct path *old_root, struct path *new_root)
46388 {
46389 struct task_struct *g, *p;
46390@@ -67,7 +84,7 @@ void chroot_fs_refs(struct path *old_root, struct path *new_root)
46391 int hits = 0;
46392 spin_lock(&fs->lock);
46393 write_seqcount_begin(&fs->seq);
46394- hits += replace_path(&fs->root, old_root, new_root);
46395+ hits += replace_root_path(p, &fs->root, old_root, new_root);
46396 hits += replace_path(&fs->pwd, old_root, new_root);
46397 write_seqcount_end(&fs->seq);
46398 while (hits--) {
46399@@ -94,12 +111,15 @@ void exit_fs(struct task_struct *tsk)
46400 {
46401 struct fs_struct *fs = tsk->fs;
46402
46403+ gr_put_exec_file(tsk);
46404+
46405 if (fs) {
46406 int kill;
46407 task_lock(tsk);
46408 spin_lock(&fs->lock);
46409 tsk->fs = NULL;
46410- kill = !--fs->users;
46411+ gr_clear_chroot_entries(tsk);
46412+ kill = !atomic_dec_return(&fs->users);
46413 spin_unlock(&fs->lock);
46414 task_unlock(tsk);
46415 if (kill)
46416@@ -112,7 +132,7 @@ struct fs_struct *copy_fs_struct(struct fs_struct *old)
46417 struct fs_struct *fs = kmem_cache_alloc(fs_cachep, GFP_KERNEL);
46418 /* We don't need to lock fs - think why ;-) */
46419 if (fs) {
46420- fs->users = 1;
46421+ atomic_set(&fs->users, 1);
46422 fs->in_exec = 0;
46423 spin_lock_init(&fs->lock);
46424 seqcount_init(&fs->seq);
46425@@ -121,6 +141,9 @@ struct fs_struct *copy_fs_struct(struct fs_struct *old)
46426 spin_lock(&old->lock);
46427 fs->root = old->root;
46428 path_get(&fs->root);
46429+ /* instead of calling gr_set_chroot_entries here,
46430+ we call it from every caller of this function
46431+ */
46432 fs->pwd = old->pwd;
46433 path_get(&fs->pwd);
46434 spin_unlock(&old->lock);
46435@@ -139,8 +162,9 @@ int unshare_fs_struct(void)
46436
46437 task_lock(current);
46438 spin_lock(&fs->lock);
46439- kill = !--fs->users;
46440+ kill = !atomic_dec_return(&fs->users);
46441 current->fs = new_fs;
46442+ gr_set_chroot_entries(current, &new_fs->root);
46443 spin_unlock(&fs->lock);
46444 task_unlock(current);
46445
46446@@ -153,13 +177,13 @@ EXPORT_SYMBOL_GPL(unshare_fs_struct);
46447
46448 int current_umask(void)
46449 {
46450- return current->fs->umask;
46451+ return current->fs->umask | gr_acl_umask();
46452 }
46453 EXPORT_SYMBOL(current_umask);
46454
46455 /* to be mentioned only in INIT_TASK */
46456 struct fs_struct init_fs = {
46457- .users = 1,
46458+ .users = ATOMIC_INIT(1),
46459 .lock = __SPIN_LOCK_UNLOCKED(init_fs.lock),
46460 .seq = SEQCNT_ZERO,
46461 .umask = 0022,
46462@@ -169,18 +193,21 @@ void daemonize_fs_struct(void)
46463 {
46464 struct fs_struct *fs = current->fs;
46465
46466+ gr_put_exec_file(current);
46467+
46468 if (fs) {
46469 int kill;
46470
46471 task_lock(current);
46472
46473 spin_lock(&init_fs.lock);
46474- init_fs.users++;
46475+ atomic_inc(&init_fs.users);
46476 spin_unlock(&init_fs.lock);
46477
46478 spin_lock(&fs->lock);
46479 current->fs = &init_fs;
46480- kill = !--fs->users;
46481+ gr_set_chroot_entries(current, &current->fs->root);
46482+ kill = !atomic_dec_return(&fs->users);
46483 spin_unlock(&fs->lock);
46484
46485 task_unlock(current);
46486diff --git a/fs/fscache/cookie.c b/fs/fscache/cookie.c
46487index 9905350..02eaec4 100644
46488--- a/fs/fscache/cookie.c
46489+++ b/fs/fscache/cookie.c
46490@@ -68,11 +68,11 @@ struct fscache_cookie *__fscache_acquire_cookie(
46491 parent ? (char *) parent->def->name : "<no-parent>",
46492 def->name, netfs_data);
46493
46494- fscache_stat(&fscache_n_acquires);
46495+ fscache_stat_unchecked(&fscache_n_acquires);
46496
46497 /* if there's no parent cookie, then we don't create one here either */
46498 if (!parent) {
46499- fscache_stat(&fscache_n_acquires_null);
46500+ fscache_stat_unchecked(&fscache_n_acquires_null);
46501 _leave(" [no parent]");
46502 return NULL;
46503 }
46504@@ -87,7 +87,7 @@ struct fscache_cookie *__fscache_acquire_cookie(
46505 /* allocate and initialise a cookie */
46506 cookie = kmem_cache_alloc(fscache_cookie_jar, GFP_KERNEL);
46507 if (!cookie) {
46508- fscache_stat(&fscache_n_acquires_oom);
46509+ fscache_stat_unchecked(&fscache_n_acquires_oom);
46510 _leave(" [ENOMEM]");
46511 return NULL;
46512 }
46513@@ -109,13 +109,13 @@ struct fscache_cookie *__fscache_acquire_cookie(
46514
46515 switch (cookie->def->type) {
46516 case FSCACHE_COOKIE_TYPE_INDEX:
46517- fscache_stat(&fscache_n_cookie_index);
46518+ fscache_stat_unchecked(&fscache_n_cookie_index);
46519 break;
46520 case FSCACHE_COOKIE_TYPE_DATAFILE:
46521- fscache_stat(&fscache_n_cookie_data);
46522+ fscache_stat_unchecked(&fscache_n_cookie_data);
46523 break;
46524 default:
46525- fscache_stat(&fscache_n_cookie_special);
46526+ fscache_stat_unchecked(&fscache_n_cookie_special);
46527 break;
46528 }
46529
46530@@ -126,13 +126,13 @@ struct fscache_cookie *__fscache_acquire_cookie(
46531 if (fscache_acquire_non_index_cookie(cookie) < 0) {
46532 atomic_dec(&parent->n_children);
46533 __fscache_cookie_put(cookie);
46534- fscache_stat(&fscache_n_acquires_nobufs);
46535+ fscache_stat_unchecked(&fscache_n_acquires_nobufs);
46536 _leave(" = NULL");
46537 return NULL;
46538 }
46539 }
46540
46541- fscache_stat(&fscache_n_acquires_ok);
46542+ fscache_stat_unchecked(&fscache_n_acquires_ok);
46543 _leave(" = %p", cookie);
46544 return cookie;
46545 }
46546@@ -168,7 +168,7 @@ static int fscache_acquire_non_index_cookie(struct fscache_cookie *cookie)
46547 cache = fscache_select_cache_for_object(cookie->parent);
46548 if (!cache) {
46549 up_read(&fscache_addremove_sem);
46550- fscache_stat(&fscache_n_acquires_no_cache);
46551+ fscache_stat_unchecked(&fscache_n_acquires_no_cache);
46552 _leave(" = -ENOMEDIUM [no cache]");
46553 return -ENOMEDIUM;
46554 }
46555@@ -256,12 +256,12 @@ static int fscache_alloc_object(struct fscache_cache *cache,
46556 object = cache->ops->alloc_object(cache, cookie);
46557 fscache_stat_d(&fscache_n_cop_alloc_object);
46558 if (IS_ERR(object)) {
46559- fscache_stat(&fscache_n_object_no_alloc);
46560+ fscache_stat_unchecked(&fscache_n_object_no_alloc);
46561 ret = PTR_ERR(object);
46562 goto error;
46563 }
46564
46565- fscache_stat(&fscache_n_object_alloc);
46566+ fscache_stat_unchecked(&fscache_n_object_alloc);
46567
46568 object->debug_id = atomic_inc_return(&fscache_object_debug_id);
46569
46570@@ -377,10 +377,10 @@ void __fscache_update_cookie(struct fscache_cookie *cookie)
46571 struct fscache_object *object;
46572 struct hlist_node *_p;
46573
46574- fscache_stat(&fscache_n_updates);
46575+ fscache_stat_unchecked(&fscache_n_updates);
46576
46577 if (!cookie) {
46578- fscache_stat(&fscache_n_updates_null);
46579+ fscache_stat_unchecked(&fscache_n_updates_null);
46580 _leave(" [no cookie]");
46581 return;
46582 }
46583@@ -414,12 +414,12 @@ void __fscache_relinquish_cookie(struct fscache_cookie *cookie, int retire)
46584 struct fscache_object *object;
46585 unsigned long event;
46586
46587- fscache_stat(&fscache_n_relinquishes);
46588+ fscache_stat_unchecked(&fscache_n_relinquishes);
46589 if (retire)
46590- fscache_stat(&fscache_n_relinquishes_retire);
46591+ fscache_stat_unchecked(&fscache_n_relinquishes_retire);
46592
46593 if (!cookie) {
46594- fscache_stat(&fscache_n_relinquishes_null);
46595+ fscache_stat_unchecked(&fscache_n_relinquishes_null);
46596 _leave(" [no cookie]");
46597 return;
46598 }
46599@@ -435,7 +435,7 @@ void __fscache_relinquish_cookie(struct fscache_cookie *cookie, int retire)
46600
46601 /* wait for the cookie to finish being instantiated (or to fail) */
46602 if (test_bit(FSCACHE_COOKIE_CREATING, &cookie->flags)) {
46603- fscache_stat(&fscache_n_relinquishes_waitcrt);
46604+ fscache_stat_unchecked(&fscache_n_relinquishes_waitcrt);
46605 wait_on_bit(&cookie->flags, FSCACHE_COOKIE_CREATING,
46606 fscache_wait_bit, TASK_UNINTERRUPTIBLE);
46607 }
46608diff --git a/fs/fscache/internal.h b/fs/fscache/internal.h
46609index f6aad48..88dcf26 100644
46610--- a/fs/fscache/internal.h
46611+++ b/fs/fscache/internal.h
46612@@ -144,94 +144,94 @@ extern void fscache_proc_cleanup(void);
46613 extern atomic_t fscache_n_ops_processed[FSCACHE_MAX_THREADS];
46614 extern atomic_t fscache_n_objs_processed[FSCACHE_MAX_THREADS];
46615
46616-extern atomic_t fscache_n_op_pend;
46617-extern atomic_t fscache_n_op_run;
46618-extern atomic_t fscache_n_op_enqueue;
46619-extern atomic_t fscache_n_op_deferred_release;
46620-extern atomic_t fscache_n_op_release;
46621-extern atomic_t fscache_n_op_gc;
46622-extern atomic_t fscache_n_op_cancelled;
46623-extern atomic_t fscache_n_op_rejected;
46624+extern atomic_unchecked_t fscache_n_op_pend;
46625+extern atomic_unchecked_t fscache_n_op_run;
46626+extern atomic_unchecked_t fscache_n_op_enqueue;
46627+extern atomic_unchecked_t fscache_n_op_deferred_release;
46628+extern atomic_unchecked_t fscache_n_op_release;
46629+extern atomic_unchecked_t fscache_n_op_gc;
46630+extern atomic_unchecked_t fscache_n_op_cancelled;
46631+extern atomic_unchecked_t fscache_n_op_rejected;
46632
46633-extern atomic_t fscache_n_attr_changed;
46634-extern atomic_t fscache_n_attr_changed_ok;
46635-extern atomic_t fscache_n_attr_changed_nobufs;
46636-extern atomic_t fscache_n_attr_changed_nomem;
46637-extern atomic_t fscache_n_attr_changed_calls;
46638+extern atomic_unchecked_t fscache_n_attr_changed;
46639+extern atomic_unchecked_t fscache_n_attr_changed_ok;
46640+extern atomic_unchecked_t fscache_n_attr_changed_nobufs;
46641+extern atomic_unchecked_t fscache_n_attr_changed_nomem;
46642+extern atomic_unchecked_t fscache_n_attr_changed_calls;
46643
46644-extern atomic_t fscache_n_allocs;
46645-extern atomic_t fscache_n_allocs_ok;
46646-extern atomic_t fscache_n_allocs_wait;
46647-extern atomic_t fscache_n_allocs_nobufs;
46648-extern atomic_t fscache_n_allocs_intr;
46649-extern atomic_t fscache_n_allocs_object_dead;
46650-extern atomic_t fscache_n_alloc_ops;
46651-extern atomic_t fscache_n_alloc_op_waits;
46652+extern atomic_unchecked_t fscache_n_allocs;
46653+extern atomic_unchecked_t fscache_n_allocs_ok;
46654+extern atomic_unchecked_t fscache_n_allocs_wait;
46655+extern atomic_unchecked_t fscache_n_allocs_nobufs;
46656+extern atomic_unchecked_t fscache_n_allocs_intr;
46657+extern atomic_unchecked_t fscache_n_allocs_object_dead;
46658+extern atomic_unchecked_t fscache_n_alloc_ops;
46659+extern atomic_unchecked_t fscache_n_alloc_op_waits;
46660
46661-extern atomic_t fscache_n_retrievals;
46662-extern atomic_t fscache_n_retrievals_ok;
46663-extern atomic_t fscache_n_retrievals_wait;
46664-extern atomic_t fscache_n_retrievals_nodata;
46665-extern atomic_t fscache_n_retrievals_nobufs;
46666-extern atomic_t fscache_n_retrievals_intr;
46667-extern atomic_t fscache_n_retrievals_nomem;
46668-extern atomic_t fscache_n_retrievals_object_dead;
46669-extern atomic_t fscache_n_retrieval_ops;
46670-extern atomic_t fscache_n_retrieval_op_waits;
46671+extern atomic_unchecked_t fscache_n_retrievals;
46672+extern atomic_unchecked_t fscache_n_retrievals_ok;
46673+extern atomic_unchecked_t fscache_n_retrievals_wait;
46674+extern atomic_unchecked_t fscache_n_retrievals_nodata;
46675+extern atomic_unchecked_t fscache_n_retrievals_nobufs;
46676+extern atomic_unchecked_t fscache_n_retrievals_intr;
46677+extern atomic_unchecked_t fscache_n_retrievals_nomem;
46678+extern atomic_unchecked_t fscache_n_retrievals_object_dead;
46679+extern atomic_unchecked_t fscache_n_retrieval_ops;
46680+extern atomic_unchecked_t fscache_n_retrieval_op_waits;
46681
46682-extern atomic_t fscache_n_stores;
46683-extern atomic_t fscache_n_stores_ok;
46684-extern atomic_t fscache_n_stores_again;
46685-extern atomic_t fscache_n_stores_nobufs;
46686-extern atomic_t fscache_n_stores_oom;
46687-extern atomic_t fscache_n_store_ops;
46688-extern atomic_t fscache_n_store_calls;
46689-extern atomic_t fscache_n_store_pages;
46690-extern atomic_t fscache_n_store_radix_deletes;
46691-extern atomic_t fscache_n_store_pages_over_limit;
46692+extern atomic_unchecked_t fscache_n_stores;
46693+extern atomic_unchecked_t fscache_n_stores_ok;
46694+extern atomic_unchecked_t fscache_n_stores_again;
46695+extern atomic_unchecked_t fscache_n_stores_nobufs;
46696+extern atomic_unchecked_t fscache_n_stores_oom;
46697+extern atomic_unchecked_t fscache_n_store_ops;
46698+extern atomic_unchecked_t fscache_n_store_calls;
46699+extern atomic_unchecked_t fscache_n_store_pages;
46700+extern atomic_unchecked_t fscache_n_store_radix_deletes;
46701+extern atomic_unchecked_t fscache_n_store_pages_over_limit;
46702
46703-extern atomic_t fscache_n_store_vmscan_not_storing;
46704-extern atomic_t fscache_n_store_vmscan_gone;
46705-extern atomic_t fscache_n_store_vmscan_busy;
46706-extern atomic_t fscache_n_store_vmscan_cancelled;
46707+extern atomic_unchecked_t fscache_n_store_vmscan_not_storing;
46708+extern atomic_unchecked_t fscache_n_store_vmscan_gone;
46709+extern atomic_unchecked_t fscache_n_store_vmscan_busy;
46710+extern atomic_unchecked_t fscache_n_store_vmscan_cancelled;
46711
46712-extern atomic_t fscache_n_marks;
46713-extern atomic_t fscache_n_uncaches;
46714+extern atomic_unchecked_t fscache_n_marks;
46715+extern atomic_unchecked_t fscache_n_uncaches;
46716
46717-extern atomic_t fscache_n_acquires;
46718-extern atomic_t fscache_n_acquires_null;
46719-extern atomic_t fscache_n_acquires_no_cache;
46720-extern atomic_t fscache_n_acquires_ok;
46721-extern atomic_t fscache_n_acquires_nobufs;
46722-extern atomic_t fscache_n_acquires_oom;
46723+extern atomic_unchecked_t fscache_n_acquires;
46724+extern atomic_unchecked_t fscache_n_acquires_null;
46725+extern atomic_unchecked_t fscache_n_acquires_no_cache;
46726+extern atomic_unchecked_t fscache_n_acquires_ok;
46727+extern atomic_unchecked_t fscache_n_acquires_nobufs;
46728+extern atomic_unchecked_t fscache_n_acquires_oom;
46729
46730-extern atomic_t fscache_n_updates;
46731-extern atomic_t fscache_n_updates_null;
46732-extern atomic_t fscache_n_updates_run;
46733+extern atomic_unchecked_t fscache_n_updates;
46734+extern atomic_unchecked_t fscache_n_updates_null;
46735+extern atomic_unchecked_t fscache_n_updates_run;
46736
46737-extern atomic_t fscache_n_relinquishes;
46738-extern atomic_t fscache_n_relinquishes_null;
46739-extern atomic_t fscache_n_relinquishes_waitcrt;
46740-extern atomic_t fscache_n_relinquishes_retire;
46741+extern atomic_unchecked_t fscache_n_relinquishes;
46742+extern atomic_unchecked_t fscache_n_relinquishes_null;
46743+extern atomic_unchecked_t fscache_n_relinquishes_waitcrt;
46744+extern atomic_unchecked_t fscache_n_relinquishes_retire;
46745
46746-extern atomic_t fscache_n_cookie_index;
46747-extern atomic_t fscache_n_cookie_data;
46748-extern atomic_t fscache_n_cookie_special;
46749+extern atomic_unchecked_t fscache_n_cookie_index;
46750+extern atomic_unchecked_t fscache_n_cookie_data;
46751+extern atomic_unchecked_t fscache_n_cookie_special;
46752
46753-extern atomic_t fscache_n_object_alloc;
46754-extern atomic_t fscache_n_object_no_alloc;
46755-extern atomic_t fscache_n_object_lookups;
46756-extern atomic_t fscache_n_object_lookups_negative;
46757-extern atomic_t fscache_n_object_lookups_positive;
46758-extern atomic_t fscache_n_object_lookups_timed_out;
46759-extern atomic_t fscache_n_object_created;
46760-extern atomic_t fscache_n_object_avail;
46761-extern atomic_t fscache_n_object_dead;
46762+extern atomic_unchecked_t fscache_n_object_alloc;
46763+extern atomic_unchecked_t fscache_n_object_no_alloc;
46764+extern atomic_unchecked_t fscache_n_object_lookups;
46765+extern atomic_unchecked_t fscache_n_object_lookups_negative;
46766+extern atomic_unchecked_t fscache_n_object_lookups_positive;
46767+extern atomic_unchecked_t fscache_n_object_lookups_timed_out;
46768+extern atomic_unchecked_t fscache_n_object_created;
46769+extern atomic_unchecked_t fscache_n_object_avail;
46770+extern atomic_unchecked_t fscache_n_object_dead;
46771
46772-extern atomic_t fscache_n_checkaux_none;
46773-extern atomic_t fscache_n_checkaux_okay;
46774-extern atomic_t fscache_n_checkaux_update;
46775-extern atomic_t fscache_n_checkaux_obsolete;
46776+extern atomic_unchecked_t fscache_n_checkaux_none;
46777+extern atomic_unchecked_t fscache_n_checkaux_okay;
46778+extern atomic_unchecked_t fscache_n_checkaux_update;
46779+extern atomic_unchecked_t fscache_n_checkaux_obsolete;
46780
46781 extern atomic_t fscache_n_cop_alloc_object;
46782 extern atomic_t fscache_n_cop_lookup_object;
46783@@ -255,6 +255,11 @@ static inline void fscache_stat(atomic_t *stat)
46784 atomic_inc(stat);
46785 }
46786
46787+static inline void fscache_stat_unchecked(atomic_unchecked_t *stat)
46788+{
46789+ atomic_inc_unchecked(stat);
46790+}
46791+
46792 static inline void fscache_stat_d(atomic_t *stat)
46793 {
46794 atomic_dec(stat);
46795@@ -267,6 +272,7 @@ extern const struct file_operations fscache_stats_fops;
46796
46797 #define __fscache_stat(stat) (NULL)
46798 #define fscache_stat(stat) do {} while (0)
46799+#define fscache_stat_unchecked(stat) do {} while (0)
46800 #define fscache_stat_d(stat) do {} while (0)
46801 #endif
46802
46803diff --git a/fs/fscache/object.c b/fs/fscache/object.c
46804index b6b897c..0ffff9c 100644
46805--- a/fs/fscache/object.c
46806+++ b/fs/fscache/object.c
46807@@ -128,7 +128,7 @@ static void fscache_object_state_machine(struct fscache_object *object)
46808 /* update the object metadata on disk */
46809 case FSCACHE_OBJECT_UPDATING:
46810 clear_bit(FSCACHE_OBJECT_EV_UPDATE, &object->events);
46811- fscache_stat(&fscache_n_updates_run);
46812+ fscache_stat_unchecked(&fscache_n_updates_run);
46813 fscache_stat(&fscache_n_cop_update_object);
46814 object->cache->ops->update_object(object);
46815 fscache_stat_d(&fscache_n_cop_update_object);
46816@@ -217,7 +217,7 @@ static void fscache_object_state_machine(struct fscache_object *object)
46817 spin_lock(&object->lock);
46818 object->state = FSCACHE_OBJECT_DEAD;
46819 spin_unlock(&object->lock);
46820- fscache_stat(&fscache_n_object_dead);
46821+ fscache_stat_unchecked(&fscache_n_object_dead);
46822 goto terminal_transit;
46823
46824 /* handle the parent cache of this object being withdrawn from
46825@@ -232,7 +232,7 @@ static void fscache_object_state_machine(struct fscache_object *object)
46826 spin_lock(&object->lock);
46827 object->state = FSCACHE_OBJECT_DEAD;
46828 spin_unlock(&object->lock);
46829- fscache_stat(&fscache_n_object_dead);
46830+ fscache_stat_unchecked(&fscache_n_object_dead);
46831 goto terminal_transit;
46832
46833 /* complain about the object being woken up once it is
46834@@ -461,7 +461,7 @@ static void fscache_lookup_object(struct fscache_object *object)
46835 parent->cookie->def->name, cookie->def->name,
46836 object->cache->tag->name);
46837
46838- fscache_stat(&fscache_n_object_lookups);
46839+ fscache_stat_unchecked(&fscache_n_object_lookups);
46840 fscache_stat(&fscache_n_cop_lookup_object);
46841 ret = object->cache->ops->lookup_object(object);
46842 fscache_stat_d(&fscache_n_cop_lookup_object);
46843@@ -472,7 +472,7 @@ static void fscache_lookup_object(struct fscache_object *object)
46844 if (ret == -ETIMEDOUT) {
46845 /* probably stuck behind another object, so move this one to
46846 * the back of the queue */
46847- fscache_stat(&fscache_n_object_lookups_timed_out);
46848+ fscache_stat_unchecked(&fscache_n_object_lookups_timed_out);
46849 set_bit(FSCACHE_OBJECT_EV_REQUEUE, &object->events);
46850 }
46851
46852@@ -495,7 +495,7 @@ void fscache_object_lookup_negative(struct fscache_object *object)
46853
46854 spin_lock(&object->lock);
46855 if (object->state == FSCACHE_OBJECT_LOOKING_UP) {
46856- fscache_stat(&fscache_n_object_lookups_negative);
46857+ fscache_stat_unchecked(&fscache_n_object_lookups_negative);
46858
46859 /* transit here to allow write requests to begin stacking up
46860 * and read requests to begin returning ENODATA */
46861@@ -541,7 +541,7 @@ void fscache_obtained_object(struct fscache_object *object)
46862 * result, in which case there may be data available */
46863 spin_lock(&object->lock);
46864 if (object->state == FSCACHE_OBJECT_LOOKING_UP) {
46865- fscache_stat(&fscache_n_object_lookups_positive);
46866+ fscache_stat_unchecked(&fscache_n_object_lookups_positive);
46867
46868 clear_bit(FSCACHE_COOKIE_NO_DATA_YET, &cookie->flags);
46869
46870@@ -555,7 +555,7 @@ void fscache_obtained_object(struct fscache_object *object)
46871 set_bit(FSCACHE_OBJECT_EV_REQUEUE, &object->events);
46872 } else {
46873 ASSERTCMP(object->state, ==, FSCACHE_OBJECT_CREATING);
46874- fscache_stat(&fscache_n_object_created);
46875+ fscache_stat_unchecked(&fscache_n_object_created);
46876
46877 object->state = FSCACHE_OBJECT_AVAILABLE;
46878 spin_unlock(&object->lock);
46879@@ -602,7 +602,7 @@ static void fscache_object_available(struct fscache_object *object)
46880 fscache_enqueue_dependents(object);
46881
46882 fscache_hist(fscache_obj_instantiate_histogram, object->lookup_jif);
46883- fscache_stat(&fscache_n_object_avail);
46884+ fscache_stat_unchecked(&fscache_n_object_avail);
46885
46886 _leave("");
46887 }
46888@@ -861,7 +861,7 @@ enum fscache_checkaux fscache_check_aux(struct fscache_object *object,
46889 enum fscache_checkaux result;
46890
46891 if (!object->cookie->def->check_aux) {
46892- fscache_stat(&fscache_n_checkaux_none);
46893+ fscache_stat_unchecked(&fscache_n_checkaux_none);
46894 return FSCACHE_CHECKAUX_OKAY;
46895 }
46896
46897@@ -870,17 +870,17 @@ enum fscache_checkaux fscache_check_aux(struct fscache_object *object,
46898 switch (result) {
46899 /* entry okay as is */
46900 case FSCACHE_CHECKAUX_OKAY:
46901- fscache_stat(&fscache_n_checkaux_okay);
46902+ fscache_stat_unchecked(&fscache_n_checkaux_okay);
46903 break;
46904
46905 /* entry requires update */
46906 case FSCACHE_CHECKAUX_NEEDS_UPDATE:
46907- fscache_stat(&fscache_n_checkaux_update);
46908+ fscache_stat_unchecked(&fscache_n_checkaux_update);
46909 break;
46910
46911 /* entry requires deletion */
46912 case FSCACHE_CHECKAUX_OBSOLETE:
46913- fscache_stat(&fscache_n_checkaux_obsolete);
46914+ fscache_stat_unchecked(&fscache_n_checkaux_obsolete);
46915 break;
46916
46917 default:
46918diff --git a/fs/fscache/operation.c b/fs/fscache/operation.c
46919index 30afdfa..2256596 100644
46920--- a/fs/fscache/operation.c
46921+++ b/fs/fscache/operation.c
46922@@ -17,7 +17,7 @@
46923 #include <linux/slab.h>
46924 #include "internal.h"
46925
46926-atomic_t fscache_op_debug_id;
46927+atomic_unchecked_t fscache_op_debug_id;
46928 EXPORT_SYMBOL(fscache_op_debug_id);
46929
46930 /**
46931@@ -38,7 +38,7 @@ void fscache_enqueue_operation(struct fscache_operation *op)
46932 ASSERTCMP(op->object->state, >=, FSCACHE_OBJECT_AVAILABLE);
46933 ASSERTCMP(atomic_read(&op->usage), >, 0);
46934
46935- fscache_stat(&fscache_n_op_enqueue);
46936+ fscache_stat_unchecked(&fscache_n_op_enqueue);
46937 switch (op->flags & FSCACHE_OP_TYPE) {
46938 case FSCACHE_OP_ASYNC:
46939 _debug("queue async");
46940@@ -69,7 +69,7 @@ static void fscache_run_op(struct fscache_object *object,
46941 wake_up_bit(&op->flags, FSCACHE_OP_WAITING);
46942 if (op->processor)
46943 fscache_enqueue_operation(op);
46944- fscache_stat(&fscache_n_op_run);
46945+ fscache_stat_unchecked(&fscache_n_op_run);
46946 }
46947
46948 /*
46949@@ -98,11 +98,11 @@ int fscache_submit_exclusive_op(struct fscache_object *object,
46950 if (object->n_ops > 1) {
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 } else if (!list_empty(&object->pending_ops)) {
46956 atomic_inc(&op->usage);
46957 list_add_tail(&op->pend_link, &object->pending_ops);
46958- fscache_stat(&fscache_n_op_pend);
46959+ fscache_stat_unchecked(&fscache_n_op_pend);
46960 fscache_start_operations(object);
46961 } else {
46962 ASSERTCMP(object->n_in_progress, ==, 0);
46963@@ -118,7 +118,7 @@ int fscache_submit_exclusive_op(struct fscache_object *object,
46964 object->n_exclusive++; /* reads and writes must wait */
46965 atomic_inc(&op->usage);
46966 list_add_tail(&op->pend_link, &object->pending_ops);
46967- fscache_stat(&fscache_n_op_pend);
46968+ fscache_stat_unchecked(&fscache_n_op_pend);
46969 ret = 0;
46970 } else {
46971 /* not allowed to submit ops in any other state */
46972@@ -203,11 +203,11 @@ int fscache_submit_op(struct fscache_object *object,
46973 if (object->n_exclusive > 0) {
46974 atomic_inc(&op->usage);
46975 list_add_tail(&op->pend_link, &object->pending_ops);
46976- fscache_stat(&fscache_n_op_pend);
46977+ fscache_stat_unchecked(&fscache_n_op_pend);
46978 } else if (!list_empty(&object->pending_ops)) {
46979 atomic_inc(&op->usage);
46980 list_add_tail(&op->pend_link, &object->pending_ops);
46981- fscache_stat(&fscache_n_op_pend);
46982+ fscache_stat_unchecked(&fscache_n_op_pend);
46983 fscache_start_operations(object);
46984 } else {
46985 ASSERTCMP(object->n_exclusive, ==, 0);
46986@@ -219,12 +219,12 @@ int fscache_submit_op(struct fscache_object *object,
46987 object->n_ops++;
46988 atomic_inc(&op->usage);
46989 list_add_tail(&op->pend_link, &object->pending_ops);
46990- fscache_stat(&fscache_n_op_pend);
46991+ fscache_stat_unchecked(&fscache_n_op_pend);
46992 ret = 0;
46993 } else if (object->state == FSCACHE_OBJECT_DYING ||
46994 object->state == FSCACHE_OBJECT_LC_DYING ||
46995 object->state == FSCACHE_OBJECT_WITHDRAWING) {
46996- fscache_stat(&fscache_n_op_rejected);
46997+ fscache_stat_unchecked(&fscache_n_op_rejected);
46998 ret = -ENOBUFS;
46999 } else if (!test_bit(FSCACHE_IOERROR, &object->cache->flags)) {
47000 fscache_report_unexpected_submission(object, op, ostate);
47001@@ -294,7 +294,7 @@ int fscache_cancel_op(struct fscache_operation *op)
47002
47003 ret = -EBUSY;
47004 if (!list_empty(&op->pend_link)) {
47005- fscache_stat(&fscache_n_op_cancelled);
47006+ fscache_stat_unchecked(&fscache_n_op_cancelled);
47007 list_del_init(&op->pend_link);
47008 object->n_ops--;
47009 if (test_bit(FSCACHE_OP_EXCLUSIVE, &op->flags))
47010@@ -331,7 +331,7 @@ void fscache_put_operation(struct fscache_operation *op)
47011 if (test_and_set_bit(FSCACHE_OP_DEAD, &op->flags))
47012 BUG();
47013
47014- fscache_stat(&fscache_n_op_release);
47015+ fscache_stat_unchecked(&fscache_n_op_release);
47016
47017 if (op->release) {
47018 op->release(op);
47019@@ -348,7 +348,7 @@ void fscache_put_operation(struct fscache_operation *op)
47020 * lock, and defer it otherwise */
47021 if (!spin_trylock(&object->lock)) {
47022 _debug("defer put");
47023- fscache_stat(&fscache_n_op_deferred_release);
47024+ fscache_stat_unchecked(&fscache_n_op_deferred_release);
47025
47026 cache = object->cache;
47027 spin_lock(&cache->op_gc_list_lock);
47028@@ -410,7 +410,7 @@ void fscache_operation_gc(struct work_struct *work)
47029
47030 _debug("GC DEFERRED REL OBJ%x OP%x",
47031 object->debug_id, op->debug_id);
47032- fscache_stat(&fscache_n_op_gc);
47033+ fscache_stat_unchecked(&fscache_n_op_gc);
47034
47035 ASSERTCMP(atomic_read(&op->usage), ==, 0);
47036
47037diff --git a/fs/fscache/page.c b/fs/fscache/page.c
47038index 3f7a59b..cf196cc 100644
47039--- a/fs/fscache/page.c
47040+++ b/fs/fscache/page.c
47041@@ -60,7 +60,7 @@ bool __fscache_maybe_release_page(struct fscache_cookie *cookie,
47042 val = radix_tree_lookup(&cookie->stores, page->index);
47043 if (!val) {
47044 rcu_read_unlock();
47045- fscache_stat(&fscache_n_store_vmscan_not_storing);
47046+ fscache_stat_unchecked(&fscache_n_store_vmscan_not_storing);
47047 __fscache_uncache_page(cookie, page);
47048 return true;
47049 }
47050@@ -90,11 +90,11 @@ bool __fscache_maybe_release_page(struct fscache_cookie *cookie,
47051 spin_unlock(&cookie->stores_lock);
47052
47053 if (xpage) {
47054- fscache_stat(&fscache_n_store_vmscan_cancelled);
47055- fscache_stat(&fscache_n_store_radix_deletes);
47056+ fscache_stat_unchecked(&fscache_n_store_vmscan_cancelled);
47057+ fscache_stat_unchecked(&fscache_n_store_radix_deletes);
47058 ASSERTCMP(xpage, ==, page);
47059 } else {
47060- fscache_stat(&fscache_n_store_vmscan_gone);
47061+ fscache_stat_unchecked(&fscache_n_store_vmscan_gone);
47062 }
47063
47064 wake_up_bit(&cookie->flags, 0);
47065@@ -107,7 +107,7 @@ page_busy:
47066 /* we might want to wait here, but that could deadlock the allocator as
47067 * the work threads writing to the cache may all end up sleeping
47068 * on memory allocation */
47069- fscache_stat(&fscache_n_store_vmscan_busy);
47070+ fscache_stat_unchecked(&fscache_n_store_vmscan_busy);
47071 return false;
47072 }
47073 EXPORT_SYMBOL(__fscache_maybe_release_page);
47074@@ -131,7 +131,7 @@ static void fscache_end_page_write(struct fscache_object *object,
47075 FSCACHE_COOKIE_STORING_TAG);
47076 if (!radix_tree_tag_get(&cookie->stores, page->index,
47077 FSCACHE_COOKIE_PENDING_TAG)) {
47078- fscache_stat(&fscache_n_store_radix_deletes);
47079+ fscache_stat_unchecked(&fscache_n_store_radix_deletes);
47080 xpage = radix_tree_delete(&cookie->stores, page->index);
47081 }
47082 spin_unlock(&cookie->stores_lock);
47083@@ -152,7 +152,7 @@ static void fscache_attr_changed_op(struct fscache_operation *op)
47084
47085 _enter("{OBJ%x OP%x}", object->debug_id, op->debug_id);
47086
47087- fscache_stat(&fscache_n_attr_changed_calls);
47088+ fscache_stat_unchecked(&fscache_n_attr_changed_calls);
47089
47090 if (fscache_object_is_active(object)) {
47091 fscache_stat(&fscache_n_cop_attr_changed);
47092@@ -177,11 +177,11 @@ int __fscache_attr_changed(struct fscache_cookie *cookie)
47093
47094 ASSERTCMP(cookie->def->type, !=, FSCACHE_COOKIE_TYPE_INDEX);
47095
47096- fscache_stat(&fscache_n_attr_changed);
47097+ fscache_stat_unchecked(&fscache_n_attr_changed);
47098
47099 op = kzalloc(sizeof(*op), GFP_KERNEL);
47100 if (!op) {
47101- fscache_stat(&fscache_n_attr_changed_nomem);
47102+ fscache_stat_unchecked(&fscache_n_attr_changed_nomem);
47103 _leave(" = -ENOMEM");
47104 return -ENOMEM;
47105 }
47106@@ -199,7 +199,7 @@ int __fscache_attr_changed(struct fscache_cookie *cookie)
47107 if (fscache_submit_exclusive_op(object, op) < 0)
47108 goto nobufs;
47109 spin_unlock(&cookie->lock);
47110- fscache_stat(&fscache_n_attr_changed_ok);
47111+ fscache_stat_unchecked(&fscache_n_attr_changed_ok);
47112 fscache_put_operation(op);
47113 _leave(" = 0");
47114 return 0;
47115@@ -207,7 +207,7 @@ int __fscache_attr_changed(struct fscache_cookie *cookie)
47116 nobufs:
47117 spin_unlock(&cookie->lock);
47118 kfree(op);
47119- fscache_stat(&fscache_n_attr_changed_nobufs);
47120+ fscache_stat_unchecked(&fscache_n_attr_changed_nobufs);
47121 _leave(" = %d", -ENOBUFS);
47122 return -ENOBUFS;
47123 }
47124@@ -243,7 +243,7 @@ static struct fscache_retrieval *fscache_alloc_retrieval(
47125 /* allocate a retrieval operation and attempt to submit it */
47126 op = kzalloc(sizeof(*op), GFP_NOIO);
47127 if (!op) {
47128- fscache_stat(&fscache_n_retrievals_nomem);
47129+ fscache_stat_unchecked(&fscache_n_retrievals_nomem);
47130 return NULL;
47131 }
47132
47133@@ -271,13 +271,13 @@ static int fscache_wait_for_deferred_lookup(struct fscache_cookie *cookie)
47134 return 0;
47135 }
47136
47137- fscache_stat(&fscache_n_retrievals_wait);
47138+ fscache_stat_unchecked(&fscache_n_retrievals_wait);
47139
47140 jif = jiffies;
47141 if (wait_on_bit(&cookie->flags, FSCACHE_COOKIE_LOOKING_UP,
47142 fscache_wait_bit_interruptible,
47143 TASK_INTERRUPTIBLE) != 0) {
47144- fscache_stat(&fscache_n_retrievals_intr);
47145+ fscache_stat_unchecked(&fscache_n_retrievals_intr);
47146 _leave(" = -ERESTARTSYS");
47147 return -ERESTARTSYS;
47148 }
47149@@ -295,8 +295,8 @@ static int fscache_wait_for_deferred_lookup(struct fscache_cookie *cookie)
47150 */
47151 static int fscache_wait_for_retrieval_activation(struct fscache_object *object,
47152 struct fscache_retrieval *op,
47153- atomic_t *stat_op_waits,
47154- atomic_t *stat_object_dead)
47155+ atomic_unchecked_t *stat_op_waits,
47156+ atomic_unchecked_t *stat_object_dead)
47157 {
47158 int ret;
47159
47160@@ -304,7 +304,7 @@ static int fscache_wait_for_retrieval_activation(struct fscache_object *object,
47161 goto check_if_dead;
47162
47163 _debug(">>> WT");
47164- fscache_stat(stat_op_waits);
47165+ fscache_stat_unchecked(stat_op_waits);
47166 if (wait_on_bit(&op->op.flags, FSCACHE_OP_WAITING,
47167 fscache_wait_bit_interruptible,
47168 TASK_INTERRUPTIBLE) < 0) {
47169@@ -321,7 +321,7 @@ static int fscache_wait_for_retrieval_activation(struct fscache_object *object,
47170
47171 check_if_dead:
47172 if (unlikely(fscache_object_is_dead(object))) {
47173- fscache_stat(stat_object_dead);
47174+ fscache_stat_unchecked(stat_object_dead);
47175 return -ENOBUFS;
47176 }
47177 return 0;
47178@@ -348,7 +348,7 @@ int __fscache_read_or_alloc_page(struct fscache_cookie *cookie,
47179
47180 _enter("%p,%p,,,", cookie, page);
47181
47182- fscache_stat(&fscache_n_retrievals);
47183+ fscache_stat_unchecked(&fscache_n_retrievals);
47184
47185 if (hlist_empty(&cookie->backing_objects))
47186 goto nobufs;
47187@@ -381,7 +381,7 @@ int __fscache_read_or_alloc_page(struct fscache_cookie *cookie,
47188 goto nobufs_unlock;
47189 spin_unlock(&cookie->lock);
47190
47191- fscache_stat(&fscache_n_retrieval_ops);
47192+ fscache_stat_unchecked(&fscache_n_retrieval_ops);
47193
47194 /* pin the netfs read context in case we need to do the actual netfs
47195 * read because we've encountered a cache read failure */
47196@@ -411,15 +411,15 @@ int __fscache_read_or_alloc_page(struct fscache_cookie *cookie,
47197
47198 error:
47199 if (ret == -ENOMEM)
47200- fscache_stat(&fscache_n_retrievals_nomem);
47201+ fscache_stat_unchecked(&fscache_n_retrievals_nomem);
47202 else if (ret == -ERESTARTSYS)
47203- fscache_stat(&fscache_n_retrievals_intr);
47204+ fscache_stat_unchecked(&fscache_n_retrievals_intr);
47205 else if (ret == -ENODATA)
47206- fscache_stat(&fscache_n_retrievals_nodata);
47207+ fscache_stat_unchecked(&fscache_n_retrievals_nodata);
47208 else if (ret < 0)
47209- fscache_stat(&fscache_n_retrievals_nobufs);
47210+ fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
47211 else
47212- fscache_stat(&fscache_n_retrievals_ok);
47213+ fscache_stat_unchecked(&fscache_n_retrievals_ok);
47214
47215 fscache_put_retrieval(op);
47216 _leave(" = %d", ret);
47217@@ -429,7 +429,7 @@ nobufs_unlock:
47218 spin_unlock(&cookie->lock);
47219 kfree(op);
47220 nobufs:
47221- fscache_stat(&fscache_n_retrievals_nobufs);
47222+ fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
47223 _leave(" = -ENOBUFS");
47224 return -ENOBUFS;
47225 }
47226@@ -467,7 +467,7 @@ int __fscache_read_or_alloc_pages(struct fscache_cookie *cookie,
47227
47228 _enter("%p,,%d,,,", cookie, *nr_pages);
47229
47230- fscache_stat(&fscache_n_retrievals);
47231+ fscache_stat_unchecked(&fscache_n_retrievals);
47232
47233 if (hlist_empty(&cookie->backing_objects))
47234 goto nobufs;
47235@@ -497,7 +497,7 @@ int __fscache_read_or_alloc_pages(struct fscache_cookie *cookie,
47236 goto nobufs_unlock;
47237 spin_unlock(&cookie->lock);
47238
47239- fscache_stat(&fscache_n_retrieval_ops);
47240+ fscache_stat_unchecked(&fscache_n_retrieval_ops);
47241
47242 /* pin the netfs read context in case we need to do the actual netfs
47243 * read because we've encountered a cache read failure */
47244@@ -527,15 +527,15 @@ int __fscache_read_or_alloc_pages(struct fscache_cookie *cookie,
47245
47246 error:
47247 if (ret == -ENOMEM)
47248- fscache_stat(&fscache_n_retrievals_nomem);
47249+ fscache_stat_unchecked(&fscache_n_retrievals_nomem);
47250 else if (ret == -ERESTARTSYS)
47251- fscache_stat(&fscache_n_retrievals_intr);
47252+ fscache_stat_unchecked(&fscache_n_retrievals_intr);
47253 else if (ret == -ENODATA)
47254- fscache_stat(&fscache_n_retrievals_nodata);
47255+ fscache_stat_unchecked(&fscache_n_retrievals_nodata);
47256 else if (ret < 0)
47257- fscache_stat(&fscache_n_retrievals_nobufs);
47258+ fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
47259 else
47260- fscache_stat(&fscache_n_retrievals_ok);
47261+ fscache_stat_unchecked(&fscache_n_retrievals_ok);
47262
47263 fscache_put_retrieval(op);
47264 _leave(" = %d", ret);
47265@@ -545,7 +545,7 @@ nobufs_unlock:
47266 spin_unlock(&cookie->lock);
47267 kfree(op);
47268 nobufs:
47269- fscache_stat(&fscache_n_retrievals_nobufs);
47270+ fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
47271 _leave(" = -ENOBUFS");
47272 return -ENOBUFS;
47273 }
47274@@ -569,7 +569,7 @@ int __fscache_alloc_page(struct fscache_cookie *cookie,
47275
47276 _enter("%p,%p,,,", cookie, page);
47277
47278- fscache_stat(&fscache_n_allocs);
47279+ fscache_stat_unchecked(&fscache_n_allocs);
47280
47281 if (hlist_empty(&cookie->backing_objects))
47282 goto nobufs;
47283@@ -595,7 +595,7 @@ int __fscache_alloc_page(struct fscache_cookie *cookie,
47284 goto nobufs_unlock;
47285 spin_unlock(&cookie->lock);
47286
47287- fscache_stat(&fscache_n_alloc_ops);
47288+ fscache_stat_unchecked(&fscache_n_alloc_ops);
47289
47290 ret = fscache_wait_for_retrieval_activation(
47291 object, op,
47292@@ -611,11 +611,11 @@ int __fscache_alloc_page(struct fscache_cookie *cookie,
47293
47294 error:
47295 if (ret == -ERESTARTSYS)
47296- fscache_stat(&fscache_n_allocs_intr);
47297+ fscache_stat_unchecked(&fscache_n_allocs_intr);
47298 else if (ret < 0)
47299- fscache_stat(&fscache_n_allocs_nobufs);
47300+ fscache_stat_unchecked(&fscache_n_allocs_nobufs);
47301 else
47302- fscache_stat(&fscache_n_allocs_ok);
47303+ fscache_stat_unchecked(&fscache_n_allocs_ok);
47304
47305 fscache_put_retrieval(op);
47306 _leave(" = %d", ret);
47307@@ -625,7 +625,7 @@ nobufs_unlock:
47308 spin_unlock(&cookie->lock);
47309 kfree(op);
47310 nobufs:
47311- fscache_stat(&fscache_n_allocs_nobufs);
47312+ fscache_stat_unchecked(&fscache_n_allocs_nobufs);
47313 _leave(" = -ENOBUFS");
47314 return -ENOBUFS;
47315 }
47316@@ -666,7 +666,7 @@ static void fscache_write_op(struct fscache_operation *_op)
47317
47318 spin_lock(&cookie->stores_lock);
47319
47320- fscache_stat(&fscache_n_store_calls);
47321+ fscache_stat_unchecked(&fscache_n_store_calls);
47322
47323 /* find a page to store */
47324 page = NULL;
47325@@ -677,7 +677,7 @@ static void fscache_write_op(struct fscache_operation *_op)
47326 page = results[0];
47327 _debug("gang %d [%lx]", n, page->index);
47328 if (page->index > op->store_limit) {
47329- fscache_stat(&fscache_n_store_pages_over_limit);
47330+ fscache_stat_unchecked(&fscache_n_store_pages_over_limit);
47331 goto superseded;
47332 }
47333
47334@@ -689,7 +689,7 @@ static void fscache_write_op(struct fscache_operation *_op)
47335 spin_unlock(&cookie->stores_lock);
47336 spin_unlock(&object->lock);
47337
47338- fscache_stat(&fscache_n_store_pages);
47339+ fscache_stat_unchecked(&fscache_n_store_pages);
47340 fscache_stat(&fscache_n_cop_write_page);
47341 ret = object->cache->ops->write_page(op, page);
47342 fscache_stat_d(&fscache_n_cop_write_page);
47343@@ -757,7 +757,7 @@ int __fscache_write_page(struct fscache_cookie *cookie,
47344 ASSERTCMP(cookie->def->type, !=, FSCACHE_COOKIE_TYPE_INDEX);
47345 ASSERT(PageFsCache(page));
47346
47347- fscache_stat(&fscache_n_stores);
47348+ fscache_stat_unchecked(&fscache_n_stores);
47349
47350 op = kzalloc(sizeof(*op), GFP_NOIO);
47351 if (!op)
47352@@ -808,7 +808,7 @@ int __fscache_write_page(struct fscache_cookie *cookie,
47353 spin_unlock(&cookie->stores_lock);
47354 spin_unlock(&object->lock);
47355
47356- op->op.debug_id = atomic_inc_return(&fscache_op_debug_id);
47357+ op->op.debug_id = atomic_inc_return_unchecked(&fscache_op_debug_id);
47358 op->store_limit = object->store_limit;
47359
47360 if (fscache_submit_op(object, &op->op) < 0)
47361@@ -816,8 +816,8 @@ int __fscache_write_page(struct fscache_cookie *cookie,
47362
47363 spin_unlock(&cookie->lock);
47364 radix_tree_preload_end();
47365- fscache_stat(&fscache_n_store_ops);
47366- fscache_stat(&fscache_n_stores_ok);
47367+ fscache_stat_unchecked(&fscache_n_store_ops);
47368+ fscache_stat_unchecked(&fscache_n_stores_ok);
47369
47370 /* the work queue now carries its own ref on the object */
47371 fscache_put_operation(&op->op);
47372@@ -825,14 +825,14 @@ int __fscache_write_page(struct fscache_cookie *cookie,
47373 return 0;
47374
47375 already_queued:
47376- fscache_stat(&fscache_n_stores_again);
47377+ fscache_stat_unchecked(&fscache_n_stores_again);
47378 already_pending:
47379 spin_unlock(&cookie->stores_lock);
47380 spin_unlock(&object->lock);
47381 spin_unlock(&cookie->lock);
47382 radix_tree_preload_end();
47383 kfree(op);
47384- fscache_stat(&fscache_n_stores_ok);
47385+ fscache_stat_unchecked(&fscache_n_stores_ok);
47386 _leave(" = 0");
47387 return 0;
47388
47389@@ -851,14 +851,14 @@ nobufs:
47390 spin_unlock(&cookie->lock);
47391 radix_tree_preload_end();
47392 kfree(op);
47393- fscache_stat(&fscache_n_stores_nobufs);
47394+ fscache_stat_unchecked(&fscache_n_stores_nobufs);
47395 _leave(" = -ENOBUFS");
47396 return -ENOBUFS;
47397
47398 nomem_free:
47399 kfree(op);
47400 nomem:
47401- fscache_stat(&fscache_n_stores_oom);
47402+ fscache_stat_unchecked(&fscache_n_stores_oom);
47403 _leave(" = -ENOMEM");
47404 return -ENOMEM;
47405 }
47406@@ -876,7 +876,7 @@ void __fscache_uncache_page(struct fscache_cookie *cookie, struct page *page)
47407 ASSERTCMP(cookie->def->type, !=, FSCACHE_COOKIE_TYPE_INDEX);
47408 ASSERTCMP(page, !=, NULL);
47409
47410- fscache_stat(&fscache_n_uncaches);
47411+ fscache_stat_unchecked(&fscache_n_uncaches);
47412
47413 /* cache withdrawal may beat us to it */
47414 if (!PageFsCache(page))
47415@@ -929,7 +929,7 @@ void fscache_mark_pages_cached(struct fscache_retrieval *op,
47416 unsigned long loop;
47417
47418 #ifdef CONFIG_FSCACHE_STATS
47419- atomic_add(pagevec->nr, &fscache_n_marks);
47420+ atomic_add_unchecked(pagevec->nr, &fscache_n_marks);
47421 #endif
47422
47423 for (loop = 0; loop < pagevec->nr; loop++) {
47424diff --git a/fs/fscache/stats.c b/fs/fscache/stats.c
47425index 4765190..2a067f2 100644
47426--- a/fs/fscache/stats.c
47427+++ b/fs/fscache/stats.c
47428@@ -18,95 +18,95 @@
47429 /*
47430 * operation counters
47431 */
47432-atomic_t fscache_n_op_pend;
47433-atomic_t fscache_n_op_run;
47434-atomic_t fscache_n_op_enqueue;
47435-atomic_t fscache_n_op_requeue;
47436-atomic_t fscache_n_op_deferred_release;
47437-atomic_t fscache_n_op_release;
47438-atomic_t fscache_n_op_gc;
47439-atomic_t fscache_n_op_cancelled;
47440-atomic_t fscache_n_op_rejected;
47441+atomic_unchecked_t fscache_n_op_pend;
47442+atomic_unchecked_t fscache_n_op_run;
47443+atomic_unchecked_t fscache_n_op_enqueue;
47444+atomic_unchecked_t fscache_n_op_requeue;
47445+atomic_unchecked_t fscache_n_op_deferred_release;
47446+atomic_unchecked_t fscache_n_op_release;
47447+atomic_unchecked_t fscache_n_op_gc;
47448+atomic_unchecked_t fscache_n_op_cancelled;
47449+atomic_unchecked_t fscache_n_op_rejected;
47450
47451-atomic_t fscache_n_attr_changed;
47452-atomic_t fscache_n_attr_changed_ok;
47453-atomic_t fscache_n_attr_changed_nobufs;
47454-atomic_t fscache_n_attr_changed_nomem;
47455-atomic_t fscache_n_attr_changed_calls;
47456+atomic_unchecked_t fscache_n_attr_changed;
47457+atomic_unchecked_t fscache_n_attr_changed_ok;
47458+atomic_unchecked_t fscache_n_attr_changed_nobufs;
47459+atomic_unchecked_t fscache_n_attr_changed_nomem;
47460+atomic_unchecked_t fscache_n_attr_changed_calls;
47461
47462-atomic_t fscache_n_allocs;
47463-atomic_t fscache_n_allocs_ok;
47464-atomic_t fscache_n_allocs_wait;
47465-atomic_t fscache_n_allocs_nobufs;
47466-atomic_t fscache_n_allocs_intr;
47467-atomic_t fscache_n_allocs_object_dead;
47468-atomic_t fscache_n_alloc_ops;
47469-atomic_t fscache_n_alloc_op_waits;
47470+atomic_unchecked_t fscache_n_allocs;
47471+atomic_unchecked_t fscache_n_allocs_ok;
47472+atomic_unchecked_t fscache_n_allocs_wait;
47473+atomic_unchecked_t fscache_n_allocs_nobufs;
47474+atomic_unchecked_t fscache_n_allocs_intr;
47475+atomic_unchecked_t fscache_n_allocs_object_dead;
47476+atomic_unchecked_t fscache_n_alloc_ops;
47477+atomic_unchecked_t fscache_n_alloc_op_waits;
47478
47479-atomic_t fscache_n_retrievals;
47480-atomic_t fscache_n_retrievals_ok;
47481-atomic_t fscache_n_retrievals_wait;
47482-atomic_t fscache_n_retrievals_nodata;
47483-atomic_t fscache_n_retrievals_nobufs;
47484-atomic_t fscache_n_retrievals_intr;
47485-atomic_t fscache_n_retrievals_nomem;
47486-atomic_t fscache_n_retrievals_object_dead;
47487-atomic_t fscache_n_retrieval_ops;
47488-atomic_t fscache_n_retrieval_op_waits;
47489+atomic_unchecked_t fscache_n_retrievals;
47490+atomic_unchecked_t fscache_n_retrievals_ok;
47491+atomic_unchecked_t fscache_n_retrievals_wait;
47492+atomic_unchecked_t fscache_n_retrievals_nodata;
47493+atomic_unchecked_t fscache_n_retrievals_nobufs;
47494+atomic_unchecked_t fscache_n_retrievals_intr;
47495+atomic_unchecked_t fscache_n_retrievals_nomem;
47496+atomic_unchecked_t fscache_n_retrievals_object_dead;
47497+atomic_unchecked_t fscache_n_retrieval_ops;
47498+atomic_unchecked_t fscache_n_retrieval_op_waits;
47499
47500-atomic_t fscache_n_stores;
47501-atomic_t fscache_n_stores_ok;
47502-atomic_t fscache_n_stores_again;
47503-atomic_t fscache_n_stores_nobufs;
47504-atomic_t fscache_n_stores_oom;
47505-atomic_t fscache_n_store_ops;
47506-atomic_t fscache_n_store_calls;
47507-atomic_t fscache_n_store_pages;
47508-atomic_t fscache_n_store_radix_deletes;
47509-atomic_t fscache_n_store_pages_over_limit;
47510+atomic_unchecked_t fscache_n_stores;
47511+atomic_unchecked_t fscache_n_stores_ok;
47512+atomic_unchecked_t fscache_n_stores_again;
47513+atomic_unchecked_t fscache_n_stores_nobufs;
47514+atomic_unchecked_t fscache_n_stores_oom;
47515+atomic_unchecked_t fscache_n_store_ops;
47516+atomic_unchecked_t fscache_n_store_calls;
47517+atomic_unchecked_t fscache_n_store_pages;
47518+atomic_unchecked_t fscache_n_store_radix_deletes;
47519+atomic_unchecked_t fscache_n_store_pages_over_limit;
47520
47521-atomic_t fscache_n_store_vmscan_not_storing;
47522-atomic_t fscache_n_store_vmscan_gone;
47523-atomic_t fscache_n_store_vmscan_busy;
47524-atomic_t fscache_n_store_vmscan_cancelled;
47525+atomic_unchecked_t fscache_n_store_vmscan_not_storing;
47526+atomic_unchecked_t fscache_n_store_vmscan_gone;
47527+atomic_unchecked_t fscache_n_store_vmscan_busy;
47528+atomic_unchecked_t fscache_n_store_vmscan_cancelled;
47529
47530-atomic_t fscache_n_marks;
47531-atomic_t fscache_n_uncaches;
47532+atomic_unchecked_t fscache_n_marks;
47533+atomic_unchecked_t fscache_n_uncaches;
47534
47535-atomic_t fscache_n_acquires;
47536-atomic_t fscache_n_acquires_null;
47537-atomic_t fscache_n_acquires_no_cache;
47538-atomic_t fscache_n_acquires_ok;
47539-atomic_t fscache_n_acquires_nobufs;
47540-atomic_t fscache_n_acquires_oom;
47541+atomic_unchecked_t fscache_n_acquires;
47542+atomic_unchecked_t fscache_n_acquires_null;
47543+atomic_unchecked_t fscache_n_acquires_no_cache;
47544+atomic_unchecked_t fscache_n_acquires_ok;
47545+atomic_unchecked_t fscache_n_acquires_nobufs;
47546+atomic_unchecked_t fscache_n_acquires_oom;
47547
47548-atomic_t fscache_n_updates;
47549-atomic_t fscache_n_updates_null;
47550-atomic_t fscache_n_updates_run;
47551+atomic_unchecked_t fscache_n_updates;
47552+atomic_unchecked_t fscache_n_updates_null;
47553+atomic_unchecked_t fscache_n_updates_run;
47554
47555-atomic_t fscache_n_relinquishes;
47556-atomic_t fscache_n_relinquishes_null;
47557-atomic_t fscache_n_relinquishes_waitcrt;
47558-atomic_t fscache_n_relinquishes_retire;
47559+atomic_unchecked_t fscache_n_relinquishes;
47560+atomic_unchecked_t fscache_n_relinquishes_null;
47561+atomic_unchecked_t fscache_n_relinquishes_waitcrt;
47562+atomic_unchecked_t fscache_n_relinquishes_retire;
47563
47564-atomic_t fscache_n_cookie_index;
47565-atomic_t fscache_n_cookie_data;
47566-atomic_t fscache_n_cookie_special;
47567+atomic_unchecked_t fscache_n_cookie_index;
47568+atomic_unchecked_t fscache_n_cookie_data;
47569+atomic_unchecked_t fscache_n_cookie_special;
47570
47571-atomic_t fscache_n_object_alloc;
47572-atomic_t fscache_n_object_no_alloc;
47573-atomic_t fscache_n_object_lookups;
47574-atomic_t fscache_n_object_lookups_negative;
47575-atomic_t fscache_n_object_lookups_positive;
47576-atomic_t fscache_n_object_lookups_timed_out;
47577-atomic_t fscache_n_object_created;
47578-atomic_t fscache_n_object_avail;
47579-atomic_t fscache_n_object_dead;
47580+atomic_unchecked_t fscache_n_object_alloc;
47581+atomic_unchecked_t fscache_n_object_no_alloc;
47582+atomic_unchecked_t fscache_n_object_lookups;
47583+atomic_unchecked_t fscache_n_object_lookups_negative;
47584+atomic_unchecked_t fscache_n_object_lookups_positive;
47585+atomic_unchecked_t fscache_n_object_lookups_timed_out;
47586+atomic_unchecked_t fscache_n_object_created;
47587+atomic_unchecked_t fscache_n_object_avail;
47588+atomic_unchecked_t fscache_n_object_dead;
47589
47590-atomic_t fscache_n_checkaux_none;
47591-atomic_t fscache_n_checkaux_okay;
47592-atomic_t fscache_n_checkaux_update;
47593-atomic_t fscache_n_checkaux_obsolete;
47594+atomic_unchecked_t fscache_n_checkaux_none;
47595+atomic_unchecked_t fscache_n_checkaux_okay;
47596+atomic_unchecked_t fscache_n_checkaux_update;
47597+atomic_unchecked_t fscache_n_checkaux_obsolete;
47598
47599 atomic_t fscache_n_cop_alloc_object;
47600 atomic_t fscache_n_cop_lookup_object;
47601@@ -133,113 +133,113 @@ static int fscache_stats_show(struct seq_file *m, void *v)
47602 seq_puts(m, "FS-Cache statistics\n");
47603
47604 seq_printf(m, "Cookies: idx=%u dat=%u spc=%u\n",
47605- atomic_read(&fscache_n_cookie_index),
47606- atomic_read(&fscache_n_cookie_data),
47607- atomic_read(&fscache_n_cookie_special));
47608+ atomic_read_unchecked(&fscache_n_cookie_index),
47609+ atomic_read_unchecked(&fscache_n_cookie_data),
47610+ atomic_read_unchecked(&fscache_n_cookie_special));
47611
47612 seq_printf(m, "Objects: alc=%u nal=%u avl=%u ded=%u\n",
47613- atomic_read(&fscache_n_object_alloc),
47614- atomic_read(&fscache_n_object_no_alloc),
47615- atomic_read(&fscache_n_object_avail),
47616- atomic_read(&fscache_n_object_dead));
47617+ atomic_read_unchecked(&fscache_n_object_alloc),
47618+ atomic_read_unchecked(&fscache_n_object_no_alloc),
47619+ atomic_read_unchecked(&fscache_n_object_avail),
47620+ atomic_read_unchecked(&fscache_n_object_dead));
47621 seq_printf(m, "ChkAux : non=%u ok=%u upd=%u obs=%u\n",
47622- atomic_read(&fscache_n_checkaux_none),
47623- atomic_read(&fscache_n_checkaux_okay),
47624- atomic_read(&fscache_n_checkaux_update),
47625- atomic_read(&fscache_n_checkaux_obsolete));
47626+ atomic_read_unchecked(&fscache_n_checkaux_none),
47627+ atomic_read_unchecked(&fscache_n_checkaux_okay),
47628+ atomic_read_unchecked(&fscache_n_checkaux_update),
47629+ atomic_read_unchecked(&fscache_n_checkaux_obsolete));
47630
47631 seq_printf(m, "Pages : mrk=%u unc=%u\n",
47632- atomic_read(&fscache_n_marks),
47633- atomic_read(&fscache_n_uncaches));
47634+ atomic_read_unchecked(&fscache_n_marks),
47635+ atomic_read_unchecked(&fscache_n_uncaches));
47636
47637 seq_printf(m, "Acquire: n=%u nul=%u noc=%u ok=%u nbf=%u"
47638 " oom=%u\n",
47639- atomic_read(&fscache_n_acquires),
47640- atomic_read(&fscache_n_acquires_null),
47641- atomic_read(&fscache_n_acquires_no_cache),
47642- atomic_read(&fscache_n_acquires_ok),
47643- atomic_read(&fscache_n_acquires_nobufs),
47644- atomic_read(&fscache_n_acquires_oom));
47645+ atomic_read_unchecked(&fscache_n_acquires),
47646+ atomic_read_unchecked(&fscache_n_acquires_null),
47647+ atomic_read_unchecked(&fscache_n_acquires_no_cache),
47648+ atomic_read_unchecked(&fscache_n_acquires_ok),
47649+ atomic_read_unchecked(&fscache_n_acquires_nobufs),
47650+ atomic_read_unchecked(&fscache_n_acquires_oom));
47651
47652 seq_printf(m, "Lookups: n=%u neg=%u pos=%u crt=%u tmo=%u\n",
47653- atomic_read(&fscache_n_object_lookups),
47654- atomic_read(&fscache_n_object_lookups_negative),
47655- atomic_read(&fscache_n_object_lookups_positive),
47656- atomic_read(&fscache_n_object_created),
47657- atomic_read(&fscache_n_object_lookups_timed_out));
47658+ atomic_read_unchecked(&fscache_n_object_lookups),
47659+ atomic_read_unchecked(&fscache_n_object_lookups_negative),
47660+ atomic_read_unchecked(&fscache_n_object_lookups_positive),
47661+ atomic_read_unchecked(&fscache_n_object_created),
47662+ atomic_read_unchecked(&fscache_n_object_lookups_timed_out));
47663
47664 seq_printf(m, "Updates: n=%u nul=%u run=%u\n",
47665- atomic_read(&fscache_n_updates),
47666- atomic_read(&fscache_n_updates_null),
47667- atomic_read(&fscache_n_updates_run));
47668+ atomic_read_unchecked(&fscache_n_updates),
47669+ atomic_read_unchecked(&fscache_n_updates_null),
47670+ atomic_read_unchecked(&fscache_n_updates_run));
47671
47672 seq_printf(m, "Relinqs: n=%u nul=%u wcr=%u rtr=%u\n",
47673- atomic_read(&fscache_n_relinquishes),
47674- atomic_read(&fscache_n_relinquishes_null),
47675- atomic_read(&fscache_n_relinquishes_waitcrt),
47676- atomic_read(&fscache_n_relinquishes_retire));
47677+ atomic_read_unchecked(&fscache_n_relinquishes),
47678+ atomic_read_unchecked(&fscache_n_relinquishes_null),
47679+ atomic_read_unchecked(&fscache_n_relinquishes_waitcrt),
47680+ atomic_read_unchecked(&fscache_n_relinquishes_retire));
47681
47682 seq_printf(m, "AttrChg: n=%u ok=%u nbf=%u oom=%u run=%u\n",
47683- atomic_read(&fscache_n_attr_changed),
47684- atomic_read(&fscache_n_attr_changed_ok),
47685- atomic_read(&fscache_n_attr_changed_nobufs),
47686- atomic_read(&fscache_n_attr_changed_nomem),
47687- atomic_read(&fscache_n_attr_changed_calls));
47688+ atomic_read_unchecked(&fscache_n_attr_changed),
47689+ atomic_read_unchecked(&fscache_n_attr_changed_ok),
47690+ atomic_read_unchecked(&fscache_n_attr_changed_nobufs),
47691+ atomic_read_unchecked(&fscache_n_attr_changed_nomem),
47692+ atomic_read_unchecked(&fscache_n_attr_changed_calls));
47693
47694 seq_printf(m, "Allocs : n=%u ok=%u wt=%u nbf=%u int=%u\n",
47695- atomic_read(&fscache_n_allocs),
47696- atomic_read(&fscache_n_allocs_ok),
47697- atomic_read(&fscache_n_allocs_wait),
47698- atomic_read(&fscache_n_allocs_nobufs),
47699- atomic_read(&fscache_n_allocs_intr));
47700+ atomic_read_unchecked(&fscache_n_allocs),
47701+ atomic_read_unchecked(&fscache_n_allocs_ok),
47702+ atomic_read_unchecked(&fscache_n_allocs_wait),
47703+ atomic_read_unchecked(&fscache_n_allocs_nobufs),
47704+ atomic_read_unchecked(&fscache_n_allocs_intr));
47705 seq_printf(m, "Allocs : ops=%u owt=%u abt=%u\n",
47706- atomic_read(&fscache_n_alloc_ops),
47707- atomic_read(&fscache_n_alloc_op_waits),
47708- atomic_read(&fscache_n_allocs_object_dead));
47709+ atomic_read_unchecked(&fscache_n_alloc_ops),
47710+ atomic_read_unchecked(&fscache_n_alloc_op_waits),
47711+ atomic_read_unchecked(&fscache_n_allocs_object_dead));
47712
47713 seq_printf(m, "Retrvls: n=%u ok=%u wt=%u nod=%u nbf=%u"
47714 " int=%u oom=%u\n",
47715- atomic_read(&fscache_n_retrievals),
47716- atomic_read(&fscache_n_retrievals_ok),
47717- atomic_read(&fscache_n_retrievals_wait),
47718- atomic_read(&fscache_n_retrievals_nodata),
47719- atomic_read(&fscache_n_retrievals_nobufs),
47720- atomic_read(&fscache_n_retrievals_intr),
47721- atomic_read(&fscache_n_retrievals_nomem));
47722+ atomic_read_unchecked(&fscache_n_retrievals),
47723+ atomic_read_unchecked(&fscache_n_retrievals_ok),
47724+ atomic_read_unchecked(&fscache_n_retrievals_wait),
47725+ atomic_read_unchecked(&fscache_n_retrievals_nodata),
47726+ atomic_read_unchecked(&fscache_n_retrievals_nobufs),
47727+ atomic_read_unchecked(&fscache_n_retrievals_intr),
47728+ atomic_read_unchecked(&fscache_n_retrievals_nomem));
47729 seq_printf(m, "Retrvls: ops=%u owt=%u abt=%u\n",
47730- atomic_read(&fscache_n_retrieval_ops),
47731- atomic_read(&fscache_n_retrieval_op_waits),
47732- atomic_read(&fscache_n_retrievals_object_dead));
47733+ atomic_read_unchecked(&fscache_n_retrieval_ops),
47734+ atomic_read_unchecked(&fscache_n_retrieval_op_waits),
47735+ atomic_read_unchecked(&fscache_n_retrievals_object_dead));
47736
47737 seq_printf(m, "Stores : n=%u ok=%u agn=%u nbf=%u oom=%u\n",
47738- atomic_read(&fscache_n_stores),
47739- atomic_read(&fscache_n_stores_ok),
47740- atomic_read(&fscache_n_stores_again),
47741- atomic_read(&fscache_n_stores_nobufs),
47742- atomic_read(&fscache_n_stores_oom));
47743+ atomic_read_unchecked(&fscache_n_stores),
47744+ atomic_read_unchecked(&fscache_n_stores_ok),
47745+ atomic_read_unchecked(&fscache_n_stores_again),
47746+ atomic_read_unchecked(&fscache_n_stores_nobufs),
47747+ atomic_read_unchecked(&fscache_n_stores_oom));
47748 seq_printf(m, "Stores : ops=%u run=%u pgs=%u rxd=%u olm=%u\n",
47749- atomic_read(&fscache_n_store_ops),
47750- atomic_read(&fscache_n_store_calls),
47751- atomic_read(&fscache_n_store_pages),
47752- atomic_read(&fscache_n_store_radix_deletes),
47753- atomic_read(&fscache_n_store_pages_over_limit));
47754+ atomic_read_unchecked(&fscache_n_store_ops),
47755+ atomic_read_unchecked(&fscache_n_store_calls),
47756+ atomic_read_unchecked(&fscache_n_store_pages),
47757+ atomic_read_unchecked(&fscache_n_store_radix_deletes),
47758+ atomic_read_unchecked(&fscache_n_store_pages_over_limit));
47759
47760 seq_printf(m, "VmScan : nos=%u gon=%u bsy=%u can=%u\n",
47761- atomic_read(&fscache_n_store_vmscan_not_storing),
47762- atomic_read(&fscache_n_store_vmscan_gone),
47763- atomic_read(&fscache_n_store_vmscan_busy),
47764- atomic_read(&fscache_n_store_vmscan_cancelled));
47765+ atomic_read_unchecked(&fscache_n_store_vmscan_not_storing),
47766+ atomic_read_unchecked(&fscache_n_store_vmscan_gone),
47767+ atomic_read_unchecked(&fscache_n_store_vmscan_busy),
47768+ atomic_read_unchecked(&fscache_n_store_vmscan_cancelled));
47769
47770 seq_printf(m, "Ops : pend=%u run=%u enq=%u can=%u rej=%u\n",
47771- atomic_read(&fscache_n_op_pend),
47772- atomic_read(&fscache_n_op_run),
47773- atomic_read(&fscache_n_op_enqueue),
47774- atomic_read(&fscache_n_op_cancelled),
47775- atomic_read(&fscache_n_op_rejected));
47776+ atomic_read_unchecked(&fscache_n_op_pend),
47777+ atomic_read_unchecked(&fscache_n_op_run),
47778+ atomic_read_unchecked(&fscache_n_op_enqueue),
47779+ atomic_read_unchecked(&fscache_n_op_cancelled),
47780+ atomic_read_unchecked(&fscache_n_op_rejected));
47781 seq_printf(m, "Ops : dfr=%u rel=%u gc=%u\n",
47782- atomic_read(&fscache_n_op_deferred_release),
47783- atomic_read(&fscache_n_op_release),
47784- atomic_read(&fscache_n_op_gc));
47785+ atomic_read_unchecked(&fscache_n_op_deferred_release),
47786+ atomic_read_unchecked(&fscache_n_op_release),
47787+ atomic_read_unchecked(&fscache_n_op_gc));
47788
47789 seq_printf(m, "CacheOp: alo=%d luo=%d luc=%d gro=%d\n",
47790 atomic_read(&fscache_n_cop_alloc_object),
47791diff --git a/fs/fuse/cuse.c b/fs/fuse/cuse.c
47792index ee8d550..7189d8c 100644
47793--- a/fs/fuse/cuse.c
47794+++ b/fs/fuse/cuse.c
47795@@ -585,10 +585,12 @@ static int __init cuse_init(void)
47796 INIT_LIST_HEAD(&cuse_conntbl[i]);
47797
47798 /* inherit and extend fuse_dev_operations */
47799- cuse_channel_fops = fuse_dev_operations;
47800- cuse_channel_fops.owner = THIS_MODULE;
47801- cuse_channel_fops.open = cuse_channel_open;
47802- cuse_channel_fops.release = cuse_channel_release;
47803+ pax_open_kernel();
47804+ memcpy((void *)&cuse_channel_fops, &fuse_dev_operations, sizeof(fuse_dev_operations));
47805+ *(void **)&cuse_channel_fops.owner = THIS_MODULE;
47806+ *(void **)&cuse_channel_fops.open = cuse_channel_open;
47807+ *(void **)&cuse_channel_fops.release = cuse_channel_release;
47808+ pax_close_kernel();
47809
47810 cuse_class = class_create(THIS_MODULE, "cuse");
47811 if (IS_ERR(cuse_class))
47812diff --git a/fs/fuse/dev.c b/fs/fuse/dev.c
47813index f4246cf..b4aed1d 100644
47814--- a/fs/fuse/dev.c
47815+++ b/fs/fuse/dev.c
47816@@ -1242,7 +1242,7 @@ static ssize_t fuse_dev_splice_read(struct file *in, loff_t *ppos,
47817 ret = 0;
47818 pipe_lock(pipe);
47819
47820- if (!pipe->readers) {
47821+ if (!atomic_read(&pipe->readers)) {
47822 send_sig(SIGPIPE, current, 0);
47823 if (!ret)
47824 ret = -EPIPE;
47825diff --git a/fs/fuse/dir.c b/fs/fuse/dir.c
47826index 324bc08..4fdd56e 100644
47827--- a/fs/fuse/dir.c
47828+++ b/fs/fuse/dir.c
47829@@ -1226,7 +1226,7 @@ static char *read_link(struct dentry *dentry)
47830 return link;
47831 }
47832
47833-static void free_link(char *link)
47834+static void free_link(const char *link)
47835 {
47836 if (!IS_ERR(link))
47837 free_page((unsigned long) link);
47838diff --git a/fs/gfs2/inode.c b/fs/gfs2/inode.c
47839index 753af3d..f7b021a 100644
47840--- a/fs/gfs2/inode.c
47841+++ b/fs/gfs2/inode.c
47842@@ -1498,7 +1498,7 @@ out:
47843
47844 static void gfs2_put_link(struct dentry *dentry, struct nameidata *nd, void *p)
47845 {
47846- char *s = nd_get_link(nd);
47847+ const char *s = nd_get_link(nd);
47848 if (!IS_ERR(s))
47849 kfree(s);
47850 }
47851diff --git a/fs/gfs2/quota.c b/fs/gfs2/quota.c
47852index a3bde91..2524579 100644
47853--- a/fs/gfs2/quota.c
47854+++ b/fs/gfs2/quota.c
47855@@ -497,8 +497,11 @@ int gfs2_quota_hold(struct gfs2_inode *ip, u32 uid, u32 gid)
47856 struct gfs2_quota_data **qd;
47857 int error;
47858
47859- if (ip->i_res == NULL)
47860- gfs2_rs_alloc(ip);
47861+ if (ip->i_res == NULL) {
47862+ error = gfs2_rs_alloc(ip);
47863+ if (error)
47864+ return error;
47865+ }
47866
47867 qd = ip->i_res->rs_qa_qd;
47868
47869diff --git a/fs/gfs2/rgrp.c b/fs/gfs2/rgrp.c
47870index c9ed814..4a45d5f 100644
47871--- a/fs/gfs2/rgrp.c
47872+++ b/fs/gfs2/rgrp.c
47873@@ -477,7 +477,6 @@ void gfs2_free_clones(struct gfs2_rgrpd *rgd)
47874 */
47875 int gfs2_rs_alloc(struct gfs2_inode *ip)
47876 {
47877- int error = 0;
47878 struct gfs2_blkreserv *res;
47879
47880 if (ip->i_res)
47881@@ -485,7 +484,7 @@ int gfs2_rs_alloc(struct gfs2_inode *ip)
47882
47883 res = kmem_cache_zalloc(gfs2_rsrv_cachep, GFP_NOFS);
47884 if (!res)
47885- error = -ENOMEM;
47886+ return -ENOMEM;
47887
47888 down_write(&ip->i_rw_mutex);
47889 if (ip->i_res)
47890@@ -493,7 +492,7 @@ int gfs2_rs_alloc(struct gfs2_inode *ip)
47891 else
47892 ip->i_res = res;
47893 up_write(&ip->i_rw_mutex);
47894- return error;
47895+ return 0;
47896 }
47897
47898 static void dump_rs(struct seq_file *seq, struct gfs2_blkreserv *rs)
47899diff --git a/fs/hugetlbfs/inode.c b/fs/hugetlbfs/inode.c
47900index 8349a89..51a0254 100644
47901--- a/fs/hugetlbfs/inode.c
47902+++ b/fs/hugetlbfs/inode.c
47903@@ -920,7 +920,7 @@ static struct file_system_type hugetlbfs_fs_type = {
47904 .kill_sb = kill_litter_super,
47905 };
47906
47907-static struct vfsmount *hugetlbfs_vfsmount;
47908+struct vfsmount *hugetlbfs_vfsmount;
47909
47910 static int can_do_hugetlb_shm(void)
47911 {
47912diff --git a/fs/inode.c b/fs/inode.c
47913index ac8d904..9f45d40 100644
47914--- a/fs/inode.c
47915+++ b/fs/inode.c
47916@@ -867,8 +867,8 @@ unsigned int get_next_ino(void)
47917
47918 #ifdef CONFIG_SMP
47919 if (unlikely((res & (LAST_INO_BATCH-1)) == 0)) {
47920- static atomic_t shared_last_ino;
47921- int next = atomic_add_return(LAST_INO_BATCH, &shared_last_ino);
47922+ static atomic_unchecked_t shared_last_ino;
47923+ int next = atomic_add_return_unchecked(LAST_INO_BATCH, &shared_last_ino);
47924
47925 res = next - LAST_INO_BATCH;
47926 }
47927diff --git a/fs/jffs2/erase.c b/fs/jffs2/erase.c
47928index 4a6cf28..d3a29d3 100644
47929--- a/fs/jffs2/erase.c
47930+++ b/fs/jffs2/erase.c
47931@@ -452,7 +452,8 @@ static void jffs2_mark_erased_block(struct jffs2_sb_info *c, struct jffs2_eraseb
47932 struct jffs2_unknown_node marker = {
47933 .magic = cpu_to_je16(JFFS2_MAGIC_BITMASK),
47934 .nodetype = cpu_to_je16(JFFS2_NODETYPE_CLEANMARKER),
47935- .totlen = cpu_to_je32(c->cleanmarker_size)
47936+ .totlen = cpu_to_je32(c->cleanmarker_size),
47937+ .hdr_crc = cpu_to_je32(0)
47938 };
47939
47940 jffs2_prealloc_raw_node_refs(c, jeb, 1);
47941diff --git a/fs/jffs2/wbuf.c b/fs/jffs2/wbuf.c
47942index a6597d6..41b30ec 100644
47943--- a/fs/jffs2/wbuf.c
47944+++ b/fs/jffs2/wbuf.c
47945@@ -1023,7 +1023,8 @@ static const struct jffs2_unknown_node oob_cleanmarker =
47946 {
47947 .magic = constant_cpu_to_je16(JFFS2_MAGIC_BITMASK),
47948 .nodetype = constant_cpu_to_je16(JFFS2_NODETYPE_CLEANMARKER),
47949- .totlen = constant_cpu_to_je32(8)
47950+ .totlen = constant_cpu_to_je32(8),
47951+ .hdr_crc = constant_cpu_to_je32(0)
47952 };
47953
47954 /*
47955diff --git a/fs/jfs/super.c b/fs/jfs/super.c
47956index c55c745..f67ee56 100644
47957--- a/fs/jfs/super.c
47958+++ b/fs/jfs/super.c
47959@@ -806,7 +806,7 @@ static int __init init_jfs_fs(void)
47960
47961 jfs_inode_cachep =
47962 kmem_cache_create("jfs_ip", sizeof(struct jfs_inode_info), 0,
47963- SLAB_RECLAIM_ACCOUNT|SLAB_MEM_SPREAD,
47964+ SLAB_RECLAIM_ACCOUNT|SLAB_MEM_SPREAD|SLAB_USERCOPY,
47965 init_once);
47966 if (jfs_inode_cachep == NULL)
47967 return -ENOMEM;
47968diff --git a/fs/libfs.c b/fs/libfs.c
47969index a74cb17..37fcbe4 100644
47970--- a/fs/libfs.c
47971+++ b/fs/libfs.c
47972@@ -165,6 +165,9 @@ int dcache_readdir(struct file * filp, void * dirent, filldir_t filldir)
47973
47974 for (p=q->next; p != &dentry->d_subdirs; p=p->next) {
47975 struct dentry *next;
47976+ char d_name[sizeof(next->d_iname)];
47977+ const unsigned char *name;
47978+
47979 next = list_entry(p, struct dentry, d_u.d_child);
47980 spin_lock_nested(&next->d_lock, DENTRY_D_LOCK_NESTED);
47981 if (!simple_positive(next)) {
47982@@ -174,7 +177,12 @@ int dcache_readdir(struct file * filp, void * dirent, filldir_t filldir)
47983
47984 spin_unlock(&next->d_lock);
47985 spin_unlock(&dentry->d_lock);
47986- if (filldir(dirent, next->d_name.name,
47987+ name = next->d_name.name;
47988+ if (name == next->d_iname) {
47989+ memcpy(d_name, name, next->d_name.len);
47990+ name = d_name;
47991+ }
47992+ if (filldir(dirent, name,
47993 next->d_name.len, filp->f_pos,
47994 next->d_inode->i_ino,
47995 dt_type(next->d_inode)) < 0)
47996diff --git a/fs/lockd/clntproc.c b/fs/lockd/clntproc.c
47997index 05d2912..760abfa 100644
47998--- a/fs/lockd/clntproc.c
47999+++ b/fs/lockd/clntproc.c
48000@@ -36,11 +36,11 @@ static const struct rpc_call_ops nlmclnt_cancel_ops;
48001 /*
48002 * Cookie counter for NLM requests
48003 */
48004-static atomic_t nlm_cookie = ATOMIC_INIT(0x1234);
48005+static atomic_unchecked_t nlm_cookie = ATOMIC_INIT(0x1234);
48006
48007 void nlmclnt_next_cookie(struct nlm_cookie *c)
48008 {
48009- u32 cookie = atomic_inc_return(&nlm_cookie);
48010+ u32 cookie = atomic_inc_return_unchecked(&nlm_cookie);
48011
48012 memcpy(c->data, &cookie, 4);
48013 c->len=4;
48014diff --git a/fs/locks.c b/fs/locks.c
48015index 7e81bfc..c3649aa 100644
48016--- a/fs/locks.c
48017+++ b/fs/locks.c
48018@@ -2066,16 +2066,16 @@ void locks_remove_flock(struct file *filp)
48019 return;
48020
48021 if (filp->f_op && filp->f_op->flock) {
48022- struct file_lock fl = {
48023+ struct file_lock flock = {
48024 .fl_pid = current->tgid,
48025 .fl_file = filp,
48026 .fl_flags = FL_FLOCK,
48027 .fl_type = F_UNLCK,
48028 .fl_end = OFFSET_MAX,
48029 };
48030- filp->f_op->flock(filp, F_SETLKW, &fl);
48031- if (fl.fl_ops && fl.fl_ops->fl_release_private)
48032- fl.fl_ops->fl_release_private(&fl);
48033+ filp->f_op->flock(filp, F_SETLKW, &flock);
48034+ if (flock.fl_ops && flock.fl_ops->fl_release_private)
48035+ flock.fl_ops->fl_release_private(&flock);
48036 }
48037
48038 lock_flocks();
48039diff --git a/fs/namei.c b/fs/namei.c
48040index 091c4b7..fbcb268 100644
48041--- a/fs/namei.c
48042+++ b/fs/namei.c
48043@@ -265,16 +265,32 @@ int generic_permission(struct inode *inode, int mask)
48044 if (ret != -EACCES)
48045 return ret;
48046
48047+#ifdef CONFIG_GRKERNSEC
48048+ /* we'll block if we have to log due to a denied capability use */
48049+ if (mask & MAY_NOT_BLOCK)
48050+ return -ECHILD;
48051+#endif
48052+
48053 if (S_ISDIR(inode->i_mode)) {
48054 /* DACs are overridable for directories */
48055- if (inode_capable(inode, CAP_DAC_OVERRIDE))
48056- return 0;
48057 if (!(mask & MAY_WRITE))
48058- if (inode_capable(inode, CAP_DAC_READ_SEARCH))
48059+ if (inode_capable_nolog(inode, CAP_DAC_OVERRIDE) ||
48060+ inode_capable(inode, CAP_DAC_READ_SEARCH))
48061 return 0;
48062+ if (inode_capable(inode, CAP_DAC_OVERRIDE))
48063+ return 0;
48064 return -EACCES;
48065 }
48066 /*
48067+ * Searching includes executable on directories, else just read.
48068+ */
48069+ mask &= MAY_READ | MAY_WRITE | MAY_EXEC;
48070+ if (mask == MAY_READ)
48071+ if (inode_capable_nolog(inode, CAP_DAC_OVERRIDE) ||
48072+ inode_capable(inode, CAP_DAC_READ_SEARCH))
48073+ return 0;
48074+
48075+ /*
48076 * Read/write DACs are always overridable.
48077 * Executable DACs are overridable when there is
48078 * at least one exec bit set.
48079@@ -283,14 +299,6 @@ int generic_permission(struct inode *inode, int mask)
48080 if (inode_capable(inode, CAP_DAC_OVERRIDE))
48081 return 0;
48082
48083- /*
48084- * Searching includes executable on directories, else just read.
48085- */
48086- mask &= MAY_READ | MAY_WRITE | MAY_EXEC;
48087- if (mask == MAY_READ)
48088- if (inode_capable(inode, CAP_DAC_READ_SEARCH))
48089- return 0;
48090-
48091 return -EACCES;
48092 }
48093
48094@@ -772,7 +780,7 @@ follow_link(struct path *link, struct nameidata *nd, void **p)
48095 {
48096 struct dentry *dentry = link->dentry;
48097 int error;
48098- char *s;
48099+ const char *s;
48100
48101 BUG_ON(nd->flags & LOOKUP_RCU);
48102
48103@@ -793,6 +801,12 @@ follow_link(struct path *link, struct nameidata *nd, void **p)
48104 if (error)
48105 goto out_put_nd_path;
48106
48107+ if (gr_handle_follow_link(dentry->d_parent->d_inode,
48108+ dentry->d_inode, dentry, nd->path.mnt)) {
48109+ error = -EACCES;
48110+ goto out_put_nd_path;
48111+ }
48112+
48113 nd->last_type = LAST_BIND;
48114 *p = dentry->d_inode->i_op->follow_link(dentry, nd);
48115 error = PTR_ERR(*p);
48116@@ -1550,6 +1564,8 @@ static inline int nested_symlink(struct path *path, struct nameidata *nd)
48117 break;
48118 res = walk_component(nd, path, &nd->last,
48119 nd->last_type, LOOKUP_FOLLOW);
48120+ if (res >= 0 && gr_handle_symlink_owner(&link, nd->inode))
48121+ res = -EACCES;
48122 put_link(nd, &link, cookie);
48123 } while (res > 0);
48124
48125@@ -1648,7 +1664,7 @@ EXPORT_SYMBOL(full_name_hash);
48126 static inline unsigned long hash_name(const char *name, unsigned int *hashp)
48127 {
48128 unsigned long a, b, adata, bdata, mask, hash, len;
48129- const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
48130+ static const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
48131
48132 hash = a = 0;
48133 len = -sizeof(unsigned long);
48134@@ -1943,6 +1959,8 @@ static int path_lookupat(int dfd, const char *name,
48135 if (err)
48136 break;
48137 err = lookup_last(nd, &path);
48138+ if (!err && gr_handle_symlink_owner(&link, nd->inode))
48139+ err = -EACCES;
48140 put_link(nd, &link, cookie);
48141 }
48142 }
48143@@ -1950,6 +1968,21 @@ static int path_lookupat(int dfd, const char *name,
48144 if (!err)
48145 err = complete_walk(nd);
48146
48147+ if (!(nd->flags & LOOKUP_PARENT)) {
48148+#ifdef CONFIG_GRKERNSEC
48149+ if (flags & LOOKUP_RCU) {
48150+ if (!err)
48151+ path_put(&nd->path);
48152+ err = -ECHILD;
48153+ } else
48154+#endif
48155+ if (!gr_acl_handle_hidden_file(nd->path.dentry, nd->path.mnt)) {
48156+ if (!err)
48157+ path_put(&nd->path);
48158+ err = -ENOENT;
48159+ }
48160+ }
48161+
48162 if (!err && nd->flags & LOOKUP_DIRECTORY) {
48163 if (!nd->inode->i_op->lookup) {
48164 path_put(&nd->path);
48165@@ -1977,6 +2010,15 @@ static int do_path_lookup(int dfd, const char *name,
48166 retval = path_lookupat(dfd, name, flags | LOOKUP_REVAL, nd);
48167
48168 if (likely(!retval)) {
48169+ if (*name != '/' && nd->path.dentry && nd->inode) {
48170+#ifdef CONFIG_GRKERNSEC
48171+ if (flags & LOOKUP_RCU)
48172+ return -ECHILD;
48173+#endif
48174+ if (!gr_chroot_fchdir(nd->path.dentry, nd->path.mnt))
48175+ return -ENOENT;
48176+ }
48177+
48178 if (unlikely(!audit_dummy_context())) {
48179 if (nd->path.dentry && nd->inode)
48180 audit_inode(name, nd->path.dentry);
48181@@ -2336,6 +2378,13 @@ static int may_open(struct path *path, int acc_mode, int flag)
48182 if (flag & O_NOATIME && !inode_owner_or_capable(inode))
48183 return -EPERM;
48184
48185+ if (gr_handle_rofs_blockwrite(dentry, path->mnt, acc_mode))
48186+ return -EPERM;
48187+ if (gr_handle_rawio(inode))
48188+ return -EPERM;
48189+ if (!gr_acl_handle_open(dentry, path->mnt, acc_mode))
48190+ return -EACCES;
48191+
48192 return 0;
48193 }
48194
48195@@ -2557,7 +2606,7 @@ looked_up:
48196 * cleared otherwise prior to returning.
48197 */
48198 static int lookup_open(struct nameidata *nd, struct path *path,
48199- struct file *file,
48200+ struct path *link, struct file *file,
48201 const struct open_flags *op,
48202 bool got_write, int *opened)
48203 {
48204@@ -2592,6 +2641,17 @@ static int lookup_open(struct nameidata *nd, struct path *path,
48205 /* Negative dentry, just create the file */
48206 if (!dentry->d_inode && (op->open_flag & O_CREAT)) {
48207 umode_t mode = op->mode;
48208+
48209+ if (link && gr_handle_symlink_owner(link, dir->d_inode)) {
48210+ error = -EACCES;
48211+ goto out_dput;
48212+ }
48213+
48214+ if (!gr_acl_handle_creat(dentry, dir, nd->path.mnt, op->open_flag, op->acc_mode, mode)) {
48215+ error = -EACCES;
48216+ goto out_dput;
48217+ }
48218+
48219 if (!IS_POSIXACL(dir->d_inode))
48220 mode &= ~current_umask();
48221 /*
48222@@ -2613,6 +2673,8 @@ static int lookup_open(struct nameidata *nd, struct path *path,
48223 nd->flags & LOOKUP_EXCL);
48224 if (error)
48225 goto out_dput;
48226+ else
48227+ gr_handle_create(dentry, nd->path.mnt);
48228 }
48229 out_no_open:
48230 path->dentry = dentry;
48231@@ -2627,7 +2689,7 @@ out_dput:
48232 /*
48233 * Handle the last step of open()
48234 */
48235-static int do_last(struct nameidata *nd, struct path *path,
48236+static int do_last(struct nameidata *nd, struct path *path, struct path *link,
48237 struct file *file, const struct open_flags *op,
48238 int *opened, const char *pathname)
48239 {
48240@@ -2656,16 +2718,44 @@ static int do_last(struct nameidata *nd, struct path *path,
48241 error = complete_walk(nd);
48242 if (error)
48243 return error;
48244+#ifdef CONFIG_GRKERNSEC
48245+ if (nd->flags & LOOKUP_RCU) {
48246+ error = -ECHILD;
48247+ goto out;
48248+ }
48249+#endif
48250+ if (!gr_acl_handle_hidden_file(nd->path.dentry, nd->path.mnt)) {
48251+ error = -ENOENT;
48252+ goto out;
48253+ }
48254 audit_inode(pathname, nd->path.dentry);
48255 if (open_flag & O_CREAT) {
48256 error = -EISDIR;
48257 goto out;
48258 }
48259+ if (link && gr_handle_symlink_owner(link, nd->inode)) {
48260+ error = -EACCES;
48261+ goto out;
48262+ }
48263 goto finish_open;
48264 case LAST_BIND:
48265 error = complete_walk(nd);
48266 if (error)
48267 return error;
48268+#ifdef CONFIG_GRKERNSEC
48269+ if (nd->flags & LOOKUP_RCU) {
48270+ error = -ECHILD;
48271+ goto out;
48272+ }
48273+#endif
48274+ if (!gr_acl_handle_hidden_file(dir, nd->path.mnt)) {
48275+ error = -ENOENT;
48276+ goto out;
48277+ }
48278+ if (link && gr_handle_symlink_owner(link, nd->inode)) {
48279+ error = -EACCES;
48280+ goto out;
48281+ }
48282 audit_inode(pathname, dir);
48283 goto finish_open;
48284 }
48285@@ -2714,7 +2804,7 @@ retry_lookup:
48286 */
48287 }
48288 mutex_lock(&dir->d_inode->i_mutex);
48289- error = lookup_open(nd, path, file, op, got_write, opened);
48290+ error = lookup_open(nd, path, link, file, op, got_write, opened);
48291 mutex_unlock(&dir->d_inode->i_mutex);
48292
48293 if (error <= 0) {
48294@@ -2738,11 +2828,28 @@ retry_lookup:
48295 goto finish_open_created;
48296 }
48297
48298+ if (!gr_acl_handle_hidden_file(path->dentry, nd->path.mnt)) {
48299+ error = -ENOENT;
48300+ goto exit_dput;
48301+ }
48302+ if (link && gr_handle_symlink_owner(link, path->dentry->d_inode)) {
48303+ error = -EACCES;
48304+ goto exit_dput;
48305+ }
48306+
48307 /*
48308 * create/update audit record if it already exists.
48309 */
48310- if (path->dentry->d_inode)
48311+ if (path->dentry->d_inode) {
48312+ /* only check if O_CREAT is specified, all other checks need to go
48313+ into may_open */
48314+ if (gr_handle_fifo(path->dentry, path->mnt, dir, open_flag, acc_mode)) {
48315+ error = -EACCES;
48316+ goto exit_dput;
48317+ }
48318+
48319 audit_inode(pathname, path->dentry);
48320+ }
48321
48322 /*
48323 * If atomic_open() acquired write access it is dropped now due to
48324@@ -2783,6 +2890,11 @@ finish_lookup:
48325 }
48326 }
48327 BUG_ON(inode != path->dentry->d_inode);
48328+ /* if we're resolving a symlink to another symlink */
48329+ if (link && gr_handle_symlink_owner(link, inode)) {
48330+ error = -EACCES;
48331+ goto out;
48332+ }
48333 return 1;
48334 }
48335
48336@@ -2792,7 +2904,6 @@ finish_lookup:
48337 save_parent.dentry = nd->path.dentry;
48338 save_parent.mnt = mntget(path->mnt);
48339 nd->path.dentry = path->dentry;
48340-
48341 }
48342 nd->inode = inode;
48343 /* Why this, you ask? _Now_ we might have grown LOOKUP_JUMPED... */
48344@@ -2801,6 +2912,22 @@ finish_lookup:
48345 path_put(&save_parent);
48346 return error;
48347 }
48348+
48349+#ifdef CONFIG_GRKERNSEC
48350+ if (nd->flags & LOOKUP_RCU) {
48351+ error = -ECHILD;
48352+ goto out;
48353+ }
48354+#endif
48355+ if (!gr_acl_handle_hidden_file(nd->path.dentry, nd->path.mnt)) {
48356+ error = -ENOENT;
48357+ goto out;
48358+ }
48359+ if (link && gr_handle_symlink_owner(link, nd->inode)) {
48360+ error = -EACCES;
48361+ goto out;
48362+ }
48363+
48364 error = -EISDIR;
48365 if ((open_flag & O_CREAT) && S_ISDIR(nd->inode->i_mode))
48366 goto out;
48367@@ -2899,7 +3026,7 @@ static struct file *path_openat(int dfd, const char *pathname,
48368 if (unlikely(error))
48369 goto out;
48370
48371- error = do_last(nd, &path, file, op, &opened, pathname);
48372+ error = do_last(nd, &path, NULL, file, op, &opened, pathname);
48373 while (unlikely(error > 0)) { /* trailing symlink */
48374 struct path link = path;
48375 void *cookie;
48376@@ -2917,7 +3044,7 @@ static struct file *path_openat(int dfd, const char *pathname,
48377 error = follow_link(&link, nd, &cookie);
48378 if (unlikely(error))
48379 break;
48380- error = do_last(nd, &path, file, op, &opened, pathname);
48381+ error = do_last(nd, &path, &link, file, op, &opened, pathname);
48382 put_link(nd, &link, cookie);
48383 }
48384 out:
48385@@ -3006,8 +3133,12 @@ struct dentry *kern_path_create(int dfd, const char *pathname, struct path *path
48386 goto unlock;
48387
48388 error = -EEXIST;
48389- if (dentry->d_inode)
48390+ if (dentry->d_inode) {
48391+ if (!gr_acl_handle_hidden_file(dentry, nd.path.mnt)) {
48392+ error = -ENOENT;
48393+ }
48394 goto fail;
48395+ }
48396 /*
48397 * Special case - lookup gave negative, but... we had foo/bar/
48398 * From the vfs_mknod() POV we just have a negative dentry -
48399@@ -3058,6 +3189,20 @@ struct dentry *user_path_create(int dfd, const char __user *pathname, struct pat
48400 }
48401 EXPORT_SYMBOL(user_path_create);
48402
48403+static struct dentry *user_path_create_with_name(int dfd, const char __user *pathname, struct path *path, char **to, int is_dir)
48404+{
48405+ char *tmp = getname(pathname);
48406+ struct dentry *res;
48407+ if (IS_ERR(tmp))
48408+ return ERR_CAST(tmp);
48409+ res = kern_path_create(dfd, tmp, path, is_dir);
48410+ if (IS_ERR(res))
48411+ putname(tmp);
48412+ else
48413+ *to = tmp;
48414+ return res;
48415+}
48416+
48417 int vfs_mknod(struct inode *dir, struct dentry *dentry, umode_t mode, dev_t dev)
48418 {
48419 int error = may_create(dir, dentry);
48420@@ -3119,6 +3264,17 @@ SYSCALL_DEFINE4(mknodat, int, dfd, const char __user *, filename, umode_t, mode,
48421
48422 if (!IS_POSIXACL(path.dentry->d_inode))
48423 mode &= ~current_umask();
48424+
48425+ if (gr_handle_chroot_mknod(dentry, path.mnt, mode)) {
48426+ error = -EPERM;
48427+ goto out;
48428+ }
48429+
48430+ if (!gr_acl_handle_mknod(dentry, path.dentry, path.mnt, mode)) {
48431+ error = -EACCES;
48432+ goto out;
48433+ }
48434+
48435 error = security_path_mknod(&path, dentry, mode, dev);
48436 if (error)
48437 goto out;
48438@@ -3135,6 +3291,8 @@ SYSCALL_DEFINE4(mknodat, int, dfd, const char __user *, filename, umode_t, mode,
48439 break;
48440 }
48441 out:
48442+ if (!error)
48443+ gr_handle_create(dentry, path.mnt);
48444 done_path_create(&path, dentry);
48445 return error;
48446 }
48447@@ -3181,9 +3339,18 @@ SYSCALL_DEFINE3(mkdirat, int, dfd, const char __user *, pathname, umode_t, mode)
48448
48449 if (!IS_POSIXACL(path.dentry->d_inode))
48450 mode &= ~current_umask();
48451+
48452+ if (!gr_acl_handle_mkdir(dentry, path.dentry, path.mnt)) {
48453+ error = -EACCES;
48454+ goto out;
48455+ }
48456+
48457 error = security_path_mkdir(&path, dentry, mode);
48458 if (!error)
48459 error = vfs_mkdir(path.dentry->d_inode, dentry, mode);
48460+ if (!error)
48461+ gr_handle_create(dentry, path.mnt);
48462+out:
48463 done_path_create(&path, dentry);
48464 return error;
48465 }
48466@@ -3260,6 +3427,8 @@ static long do_rmdir(int dfd, const char __user *pathname)
48467 char * name;
48468 struct dentry *dentry;
48469 struct nameidata nd;
48470+ ino_t saved_ino = 0;
48471+ dev_t saved_dev = 0;
48472
48473 error = user_path_parent(dfd, pathname, &nd, &name);
48474 if (error)
48475@@ -3291,10 +3460,21 @@ static long do_rmdir(int dfd, const char __user *pathname)
48476 error = -ENOENT;
48477 goto exit3;
48478 }
48479+
48480+ saved_ino = dentry->d_inode->i_ino;
48481+ saved_dev = gr_get_dev_from_dentry(dentry);
48482+
48483+ if (!gr_acl_handle_rmdir(dentry, nd.path.mnt)) {
48484+ error = -EACCES;
48485+ goto exit3;
48486+ }
48487+
48488 error = security_path_rmdir(&nd.path, dentry);
48489 if (error)
48490 goto exit3;
48491 error = vfs_rmdir(nd.path.dentry->d_inode, dentry);
48492+ if (!error && (saved_dev || saved_ino))
48493+ gr_handle_delete(saved_ino, saved_dev);
48494 exit3:
48495 dput(dentry);
48496 exit2:
48497@@ -3356,6 +3536,8 @@ static long do_unlinkat(int dfd, const char __user *pathname)
48498 struct dentry *dentry;
48499 struct nameidata nd;
48500 struct inode *inode = NULL;
48501+ ino_t saved_ino = 0;
48502+ dev_t saved_dev = 0;
48503
48504 error = user_path_parent(dfd, pathname, &nd, &name);
48505 if (error)
48506@@ -3381,10 +3563,22 @@ static long do_unlinkat(int dfd, const char __user *pathname)
48507 if (!inode)
48508 goto slashes;
48509 ihold(inode);
48510+
48511+ if (inode->i_nlink <= 1) {
48512+ saved_ino = inode->i_ino;
48513+ saved_dev = gr_get_dev_from_dentry(dentry);
48514+ }
48515+ if (!gr_acl_handle_unlink(dentry, nd.path.mnt)) {
48516+ error = -EACCES;
48517+ goto exit2;
48518+ }
48519+
48520 error = security_path_unlink(&nd.path, dentry);
48521 if (error)
48522 goto exit2;
48523 error = vfs_unlink(nd.path.dentry->d_inode, dentry);
48524+ if (!error && (saved_ino || saved_dev))
48525+ gr_handle_delete(saved_ino, saved_dev);
48526 exit2:
48527 dput(dentry);
48528 }
48529@@ -3456,9 +3650,17 @@ SYSCALL_DEFINE3(symlinkat, const char __user *, oldname,
48530 if (IS_ERR(dentry))
48531 goto out_putname;
48532
48533+ if (!gr_acl_handle_symlink(dentry, path.dentry, path.mnt, from)) {
48534+ error = -EACCES;
48535+ goto out;
48536+ }
48537+
48538 error = security_path_symlink(&path, dentry, from);
48539 if (!error)
48540 error = vfs_symlink(path.dentry->d_inode, dentry, from);
48541+ if (!error)
48542+ gr_handle_create(dentry, path.mnt);
48543+out:
48544 done_path_create(&path, dentry);
48545 out_putname:
48546 putname(from);
48547@@ -3528,6 +3730,7 @@ SYSCALL_DEFINE5(linkat, int, olddfd, const char __user *, oldname,
48548 {
48549 struct dentry *new_dentry;
48550 struct path old_path, new_path;
48551+ char *to = NULL;
48552 int how = 0;
48553 int error;
48554
48555@@ -3551,7 +3754,7 @@ SYSCALL_DEFINE5(linkat, int, olddfd, const char __user *, oldname,
48556 if (error)
48557 return error;
48558
48559- new_dentry = user_path_create(newdfd, newname, &new_path, 0);
48560+ new_dentry = user_path_create_with_name(newdfd, newname, &new_path, &to, 0);
48561 error = PTR_ERR(new_dentry);
48562 if (IS_ERR(new_dentry))
48563 goto out;
48564@@ -3562,11 +3765,28 @@ SYSCALL_DEFINE5(linkat, int, olddfd, const char __user *, oldname,
48565 error = may_linkat(&old_path);
48566 if (unlikely(error))
48567 goto out_dput;
48568+
48569+ if (gr_handle_hardlink(old_path.dentry, old_path.mnt,
48570+ old_path.dentry->d_inode,
48571+ old_path.dentry->d_inode->i_mode, to)) {
48572+ error = -EACCES;
48573+ goto out_dput;
48574+ }
48575+
48576+ if (!gr_acl_handle_link(new_dentry, new_path.dentry, new_path.mnt,
48577+ old_path.dentry, old_path.mnt, to)) {
48578+ error = -EACCES;
48579+ goto out_dput;
48580+ }
48581+
48582 error = security_path_link(old_path.dentry, &new_path, new_dentry);
48583 if (error)
48584 goto out_dput;
48585 error = vfs_link(old_path.dentry, new_path.dentry->d_inode, new_dentry);
48586+ if (!error)
48587+ gr_handle_create(new_dentry, new_path.mnt);
48588 out_dput:
48589+ putname(to);
48590 done_path_create(&new_path, new_dentry);
48591 out:
48592 path_put(&old_path);
48593@@ -3802,12 +4022,21 @@ SYSCALL_DEFINE4(renameat, int, olddfd, const char __user *, oldname,
48594 if (new_dentry == trap)
48595 goto exit5;
48596
48597+ error = gr_acl_handle_rename(new_dentry, new_dir, newnd.path.mnt,
48598+ old_dentry, old_dir->d_inode, oldnd.path.mnt,
48599+ to);
48600+ if (error)
48601+ goto exit5;
48602+
48603 error = security_path_rename(&oldnd.path, old_dentry,
48604 &newnd.path, new_dentry);
48605 if (error)
48606 goto exit5;
48607 error = vfs_rename(old_dir->d_inode, old_dentry,
48608 new_dir->d_inode, new_dentry);
48609+ if (!error)
48610+ gr_handle_rename(old_dir->d_inode, new_dir->d_inode, old_dentry,
48611+ new_dentry, oldnd.path.mnt, new_dentry->d_inode ? 1 : 0);
48612 exit5:
48613 dput(new_dentry);
48614 exit4:
48615@@ -3832,6 +4061,8 @@ SYSCALL_DEFINE2(rename, const char __user *, oldname, const char __user *, newna
48616
48617 int vfs_readlink(struct dentry *dentry, char __user *buffer, int buflen, const char *link)
48618 {
48619+ char tmpbuf[64];
48620+ const char *newlink;
48621 int len;
48622
48623 len = PTR_ERR(link);
48624@@ -3841,7 +4072,14 @@ int vfs_readlink(struct dentry *dentry, char __user *buffer, int buflen, const c
48625 len = strlen(link);
48626 if (len > (unsigned) buflen)
48627 len = buflen;
48628- if (copy_to_user(buffer, link, len))
48629+
48630+ if (len < sizeof(tmpbuf)) {
48631+ memcpy(tmpbuf, link, len);
48632+ newlink = tmpbuf;
48633+ } else
48634+ newlink = link;
48635+
48636+ if (copy_to_user(buffer, newlink, len))
48637 len = -EFAULT;
48638 out:
48639 return len;
48640diff --git a/fs/namespace.c b/fs/namespace.c
48641index 7bdf790..eb79c4b 100644
48642--- a/fs/namespace.c
48643+++ b/fs/namespace.c
48644@@ -1212,6 +1212,9 @@ static int do_umount(struct mount *mnt, int flags)
48645 if (!(sb->s_flags & MS_RDONLY))
48646 retval = do_remount_sb(sb, MS_RDONLY, NULL, 0);
48647 up_write(&sb->s_umount);
48648+
48649+ gr_log_remount(mnt->mnt_devname, retval);
48650+
48651 return retval;
48652 }
48653
48654@@ -1231,6 +1234,9 @@ static int do_umount(struct mount *mnt, int flags)
48655 br_write_unlock(&vfsmount_lock);
48656 up_write(&namespace_sem);
48657 release_mounts(&umount_list);
48658+
48659+ gr_log_unmount(mnt->mnt_devname, retval);
48660+
48661 return retval;
48662 }
48663
48664@@ -2244,6 +2250,16 @@ long do_mount(char *dev_name, char *dir_name, char *type_page,
48665 MS_NOATIME | MS_NODIRATIME | MS_RELATIME| MS_KERNMOUNT |
48666 MS_STRICTATIME);
48667
48668+ if (gr_handle_rofs_mount(path.dentry, path.mnt, mnt_flags)) {
48669+ retval = -EPERM;
48670+ goto dput_out;
48671+ }
48672+
48673+ if (gr_handle_chroot_mount(path.dentry, path.mnt, dev_name)) {
48674+ retval = -EPERM;
48675+ goto dput_out;
48676+ }
48677+
48678 if (flags & MS_REMOUNT)
48679 retval = do_remount(&path, flags & ~MS_REMOUNT, mnt_flags,
48680 data_page);
48681@@ -2258,6 +2274,9 @@ long do_mount(char *dev_name, char *dir_name, char *type_page,
48682 dev_name, data_page);
48683 dput_out:
48684 path_put(&path);
48685+
48686+ gr_log_mount(dev_name, dir_name, retval);
48687+
48688 return retval;
48689 }
48690
48691@@ -2516,6 +2535,11 @@ SYSCALL_DEFINE2(pivot_root, const char __user *, new_root,
48692 if (error)
48693 goto out2;
48694
48695+ if (gr_handle_chroot_pivot()) {
48696+ error = -EPERM;
48697+ goto out2;
48698+ }
48699+
48700 get_fs_root(current->fs, &root);
48701 error = lock_mount(&old);
48702 if (error)
48703diff --git a/fs/nfs/inode.c b/fs/nfs/inode.c
48704index 9b47610..066975e 100644
48705--- a/fs/nfs/inode.c
48706+++ b/fs/nfs/inode.c
48707@@ -1026,16 +1026,16 @@ static int nfs_size_need_update(const struct inode *inode, const struct nfs_fatt
48708 return nfs_size_to_loff_t(fattr->size) > i_size_read(inode);
48709 }
48710
48711-static atomic_long_t nfs_attr_generation_counter;
48712+static atomic_long_unchecked_t nfs_attr_generation_counter;
48713
48714 static unsigned long nfs_read_attr_generation_counter(void)
48715 {
48716- return atomic_long_read(&nfs_attr_generation_counter);
48717+ return atomic_long_read_unchecked(&nfs_attr_generation_counter);
48718 }
48719
48720 unsigned long nfs_inc_attr_generation_counter(void)
48721 {
48722- return atomic_long_inc_return(&nfs_attr_generation_counter);
48723+ return atomic_long_inc_return_unchecked(&nfs_attr_generation_counter);
48724 }
48725
48726 void nfs_fattr_init(struct nfs_fattr *fattr)
48727diff --git a/fs/nfsd/vfs.c b/fs/nfsd/vfs.c
48728index a9269f1..5490437 100644
48729--- a/fs/nfsd/vfs.c
48730+++ b/fs/nfsd/vfs.c
48731@@ -941,7 +941,7 @@ nfsd_vfs_read(struct svc_rqst *rqstp, struct svc_fh *fhp, struct file *file,
48732 } else {
48733 oldfs = get_fs();
48734 set_fs(KERNEL_DS);
48735- host_err = vfs_readv(file, (struct iovec __user *)vec, vlen, &offset);
48736+ host_err = vfs_readv(file, (struct iovec __force_user *)vec, vlen, &offset);
48737 set_fs(oldfs);
48738 }
48739
48740@@ -1045,7 +1045,7 @@ nfsd_vfs_write(struct svc_rqst *rqstp, struct svc_fh *fhp, struct file *file,
48741
48742 /* Write the data. */
48743 oldfs = get_fs(); set_fs(KERNEL_DS);
48744- host_err = vfs_writev(file, (struct iovec __user *)vec, vlen, &offset);
48745+ host_err = vfs_writev(file, (struct iovec __force_user *)vec, vlen, &offset);
48746 set_fs(oldfs);
48747 if (host_err < 0)
48748 goto out_nfserr;
48749@@ -1581,7 +1581,7 @@ nfsd_readlink(struct svc_rqst *rqstp, struct svc_fh *fhp, char *buf, int *lenp)
48750 */
48751
48752 oldfs = get_fs(); set_fs(KERNEL_DS);
48753- host_err = inode->i_op->readlink(path.dentry, buf, *lenp);
48754+ host_err = inode->i_op->readlink(path.dentry, (char __force_user *)buf, *lenp);
48755 set_fs(oldfs);
48756
48757 if (host_err < 0)
48758diff --git a/fs/notify/fanotify/fanotify.c b/fs/notify/fanotify/fanotify.c
48759index f35794b..a506360 100644
48760--- a/fs/notify/fanotify/fanotify.c
48761+++ b/fs/notify/fanotify/fanotify.c
48762@@ -21,6 +21,7 @@ static bool should_merge(struct fsnotify_event *old, struct fsnotify_event *new)
48763 if ((old->path.mnt == new->path.mnt) &&
48764 (old->path.dentry == new->path.dentry))
48765 return true;
48766+ break;
48767 case (FSNOTIFY_EVENT_NONE):
48768 return true;
48769 default:
48770diff --git a/fs/notify/fanotify/fanotify_user.c b/fs/notify/fanotify/fanotify_user.c
48771index d438036..0ecadde 100644
48772--- a/fs/notify/fanotify/fanotify_user.c
48773+++ b/fs/notify/fanotify/fanotify_user.c
48774@@ -274,7 +274,8 @@ static ssize_t copy_event_to_user(struct fsnotify_group *group,
48775 goto out_close_fd;
48776
48777 ret = -EFAULT;
48778- if (copy_to_user(buf, &fanotify_event_metadata,
48779+ if (fanotify_event_metadata.event_len > sizeof fanotify_event_metadata ||
48780+ copy_to_user(buf, &fanotify_event_metadata,
48781 fanotify_event_metadata.event_len))
48782 goto out_kill_access_response;
48783
48784diff --git a/fs/notify/notification.c b/fs/notify/notification.c
48785index c887b13..0fdf472 100644
48786--- a/fs/notify/notification.c
48787+++ b/fs/notify/notification.c
48788@@ -57,7 +57,7 @@ static struct kmem_cache *fsnotify_event_holder_cachep;
48789 * get set to 0 so it will never get 'freed'
48790 */
48791 static struct fsnotify_event *q_overflow_event;
48792-static atomic_t fsnotify_sync_cookie = ATOMIC_INIT(0);
48793+static atomic_unchecked_t fsnotify_sync_cookie = ATOMIC_INIT(0);
48794
48795 /**
48796 * fsnotify_get_cookie - return a unique cookie for use in synchronizing events.
48797@@ -65,7 +65,7 @@ static atomic_t fsnotify_sync_cookie = ATOMIC_INIT(0);
48798 */
48799 u32 fsnotify_get_cookie(void)
48800 {
48801- return atomic_inc_return(&fsnotify_sync_cookie);
48802+ return atomic_inc_return_unchecked(&fsnotify_sync_cookie);
48803 }
48804 EXPORT_SYMBOL_GPL(fsnotify_get_cookie);
48805
48806diff --git a/fs/ntfs/dir.c b/fs/ntfs/dir.c
48807index 99e3610..02c1068 100644
48808--- a/fs/ntfs/dir.c
48809+++ b/fs/ntfs/dir.c
48810@@ -1329,7 +1329,7 @@ find_next_index_buffer:
48811 ia = (INDEX_ALLOCATION*)(kaddr + (ia_pos & ~PAGE_CACHE_MASK &
48812 ~(s64)(ndir->itype.index.block_size - 1)));
48813 /* Bounds checks. */
48814- if (unlikely((u8*)ia < kaddr || (u8*)ia > kaddr + PAGE_CACHE_SIZE)) {
48815+ if (unlikely(!kaddr || (u8*)ia < kaddr || (u8*)ia > kaddr + PAGE_CACHE_SIZE)) {
48816 ntfs_error(sb, "Out of bounds check failed. Corrupt directory "
48817 "inode 0x%lx or driver bug.", vdir->i_ino);
48818 goto err_out;
48819diff --git a/fs/ntfs/file.c b/fs/ntfs/file.c
48820index 1ecf464..e1ff8bf 100644
48821--- a/fs/ntfs/file.c
48822+++ b/fs/ntfs/file.c
48823@@ -2232,6 +2232,6 @@ const struct inode_operations ntfs_file_inode_ops = {
48824 #endif /* NTFS_RW */
48825 };
48826
48827-const struct file_operations ntfs_empty_file_ops = {};
48828+const struct file_operations ntfs_empty_file_ops __read_only;
48829
48830-const struct inode_operations ntfs_empty_inode_ops = {};
48831+const struct inode_operations ntfs_empty_inode_ops __read_only;
48832diff --git a/fs/ocfs2/localalloc.c b/fs/ocfs2/localalloc.c
48833index a9f78c7..ed8a381 100644
48834--- a/fs/ocfs2/localalloc.c
48835+++ b/fs/ocfs2/localalloc.c
48836@@ -1279,7 +1279,7 @@ static int ocfs2_local_alloc_slide_window(struct ocfs2_super *osb,
48837 goto bail;
48838 }
48839
48840- atomic_inc(&osb->alloc_stats.moves);
48841+ atomic_inc_unchecked(&osb->alloc_stats.moves);
48842
48843 bail:
48844 if (handle)
48845diff --git a/fs/ocfs2/ocfs2.h b/fs/ocfs2/ocfs2.h
48846index d355e6e..578d905 100644
48847--- a/fs/ocfs2/ocfs2.h
48848+++ b/fs/ocfs2/ocfs2.h
48849@@ -235,11 +235,11 @@ enum ocfs2_vol_state
48850
48851 struct ocfs2_alloc_stats
48852 {
48853- atomic_t moves;
48854- atomic_t local_data;
48855- atomic_t bitmap_data;
48856- atomic_t bg_allocs;
48857- atomic_t bg_extends;
48858+ atomic_unchecked_t moves;
48859+ atomic_unchecked_t local_data;
48860+ atomic_unchecked_t bitmap_data;
48861+ atomic_unchecked_t bg_allocs;
48862+ atomic_unchecked_t bg_extends;
48863 };
48864
48865 enum ocfs2_local_alloc_state
48866diff --git a/fs/ocfs2/suballoc.c b/fs/ocfs2/suballoc.c
48867index f169da4..9112253 100644
48868--- a/fs/ocfs2/suballoc.c
48869+++ b/fs/ocfs2/suballoc.c
48870@@ -872,7 +872,7 @@ static int ocfs2_reserve_suballoc_bits(struct ocfs2_super *osb,
48871 mlog_errno(status);
48872 goto bail;
48873 }
48874- atomic_inc(&osb->alloc_stats.bg_extends);
48875+ atomic_inc_unchecked(&osb->alloc_stats.bg_extends);
48876
48877 /* You should never ask for this much metadata */
48878 BUG_ON(bits_wanted >
48879@@ -2008,7 +2008,7 @@ int ocfs2_claim_metadata(handle_t *handle,
48880 mlog_errno(status);
48881 goto bail;
48882 }
48883- atomic_inc(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
48884+ atomic_inc_unchecked(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
48885
48886 *suballoc_loc = res.sr_bg_blkno;
48887 *suballoc_bit_start = res.sr_bit_offset;
48888@@ -2172,7 +2172,7 @@ int ocfs2_claim_new_inode_at_loc(handle_t *handle,
48889 trace_ocfs2_claim_new_inode_at_loc((unsigned long long)di_blkno,
48890 res->sr_bits);
48891
48892- atomic_inc(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
48893+ atomic_inc_unchecked(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
48894
48895 BUG_ON(res->sr_bits != 1);
48896
48897@@ -2214,7 +2214,7 @@ int ocfs2_claim_new_inode(handle_t *handle,
48898 mlog_errno(status);
48899 goto bail;
48900 }
48901- atomic_inc(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
48902+ atomic_inc_unchecked(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
48903
48904 BUG_ON(res.sr_bits != 1);
48905
48906@@ -2318,7 +2318,7 @@ int __ocfs2_claim_clusters(handle_t *handle,
48907 cluster_start,
48908 num_clusters);
48909 if (!status)
48910- atomic_inc(&osb->alloc_stats.local_data);
48911+ atomic_inc_unchecked(&osb->alloc_stats.local_data);
48912 } else {
48913 if (min_clusters > (osb->bitmap_cpg - 1)) {
48914 /* The only paths asking for contiguousness
48915@@ -2344,7 +2344,7 @@ int __ocfs2_claim_clusters(handle_t *handle,
48916 ocfs2_desc_bitmap_to_cluster_off(ac->ac_inode,
48917 res.sr_bg_blkno,
48918 res.sr_bit_offset);
48919- atomic_inc(&osb->alloc_stats.bitmap_data);
48920+ atomic_inc_unchecked(&osb->alloc_stats.bitmap_data);
48921 *num_clusters = res.sr_bits;
48922 }
48923 }
48924diff --git a/fs/ocfs2/super.c b/fs/ocfs2/super.c
48925index 68f4541..89cfe6a 100644
48926--- a/fs/ocfs2/super.c
48927+++ b/fs/ocfs2/super.c
48928@@ -301,11 +301,11 @@ static int ocfs2_osb_dump(struct ocfs2_super *osb, char *buf, int len)
48929 "%10s => GlobalAllocs: %d LocalAllocs: %d "
48930 "SubAllocs: %d LAWinMoves: %d SAExtends: %d\n",
48931 "Stats",
48932- atomic_read(&osb->alloc_stats.bitmap_data),
48933- atomic_read(&osb->alloc_stats.local_data),
48934- atomic_read(&osb->alloc_stats.bg_allocs),
48935- atomic_read(&osb->alloc_stats.moves),
48936- atomic_read(&osb->alloc_stats.bg_extends));
48937+ atomic_read_unchecked(&osb->alloc_stats.bitmap_data),
48938+ atomic_read_unchecked(&osb->alloc_stats.local_data),
48939+ atomic_read_unchecked(&osb->alloc_stats.bg_allocs),
48940+ atomic_read_unchecked(&osb->alloc_stats.moves),
48941+ atomic_read_unchecked(&osb->alloc_stats.bg_extends));
48942
48943 out += snprintf(buf + out, len - out,
48944 "%10s => State: %u Descriptor: %llu Size: %u bits "
48945@@ -2116,11 +2116,11 @@ static int ocfs2_initialize_super(struct super_block *sb,
48946 spin_lock_init(&osb->osb_xattr_lock);
48947 ocfs2_init_steal_slots(osb);
48948
48949- atomic_set(&osb->alloc_stats.moves, 0);
48950- atomic_set(&osb->alloc_stats.local_data, 0);
48951- atomic_set(&osb->alloc_stats.bitmap_data, 0);
48952- atomic_set(&osb->alloc_stats.bg_allocs, 0);
48953- atomic_set(&osb->alloc_stats.bg_extends, 0);
48954+ atomic_set_unchecked(&osb->alloc_stats.moves, 0);
48955+ atomic_set_unchecked(&osb->alloc_stats.local_data, 0);
48956+ atomic_set_unchecked(&osb->alloc_stats.bitmap_data, 0);
48957+ atomic_set_unchecked(&osb->alloc_stats.bg_allocs, 0);
48958+ atomic_set_unchecked(&osb->alloc_stats.bg_extends, 0);
48959
48960 /* Copy the blockcheck stats from the superblock probe */
48961 osb->osb_ecc_stats = *stats;
48962diff --git a/fs/open.c b/fs/open.c
48963index e1f2cdb..3bd5f39 100644
48964--- a/fs/open.c
48965+++ b/fs/open.c
48966@@ -31,6 +31,8 @@
48967 #include <linux/ima.h>
48968 #include <linux/dnotify.h>
48969
48970+#define CREATE_TRACE_POINTS
48971+#include <trace/events/fs.h>
48972 #include "internal.h"
48973
48974 int do_truncate(struct dentry *dentry, loff_t length, unsigned int time_attrs,
48975@@ -112,6 +114,10 @@ static long do_sys_truncate(const char __user *pathname, loff_t length)
48976 error = locks_verify_truncate(inode, NULL, length);
48977 if (!error)
48978 error = security_path_truncate(&path);
48979+
48980+ if (!error && !gr_acl_handle_truncate(path.dentry, path.mnt))
48981+ error = -EACCES;
48982+
48983 if (!error)
48984 error = do_truncate(path.dentry, length, 0, NULL);
48985
48986@@ -364,6 +370,9 @@ SYSCALL_DEFINE3(faccessat, int, dfd, const char __user *, filename, int, mode)
48987 if (__mnt_is_readonly(path.mnt))
48988 res = -EROFS;
48989
48990+ if (!res && !gr_acl_handle_access(path.dentry, path.mnt, mode))
48991+ res = -EACCES;
48992+
48993 out_path_release:
48994 path_put(&path);
48995 out:
48996@@ -390,6 +399,8 @@ SYSCALL_DEFINE1(chdir, const char __user *, filename)
48997 if (error)
48998 goto dput_and_out;
48999
49000+ gr_log_chdir(path.dentry, path.mnt);
49001+
49002 set_fs_pwd(current->fs, &path);
49003
49004 dput_and_out:
49005@@ -416,6 +427,13 @@ SYSCALL_DEFINE1(fchdir, unsigned int, fd)
49006 goto out_putf;
49007
49008 error = inode_permission(inode, MAY_EXEC | MAY_CHDIR);
49009+
49010+ if (!error && !gr_chroot_fchdir(file->f_path.dentry, file->f_path.mnt))
49011+ error = -EPERM;
49012+
49013+ if (!error)
49014+ gr_log_chdir(file->f_path.dentry, file->f_path.mnt);
49015+
49016 if (!error)
49017 set_fs_pwd(current->fs, &file->f_path);
49018 out_putf:
49019@@ -444,7 +462,13 @@ SYSCALL_DEFINE1(chroot, const char __user *, filename)
49020 if (error)
49021 goto dput_and_out;
49022
49023+ if (gr_handle_chroot_chroot(path.dentry, path.mnt))
49024+ goto dput_and_out;
49025+
49026 set_fs_root(current->fs, &path);
49027+
49028+ gr_handle_chroot_chdir(&path);
49029+
49030 error = 0;
49031 dput_and_out:
49032 path_put(&path);
49033@@ -462,6 +486,16 @@ static int chmod_common(struct path *path, umode_t mode)
49034 if (error)
49035 return error;
49036 mutex_lock(&inode->i_mutex);
49037+
49038+ if (!gr_acl_handle_chmod(path->dentry, path->mnt, &mode)) {
49039+ error = -EACCES;
49040+ goto out_unlock;
49041+ }
49042+ if (gr_handle_chroot_chmod(path->dentry, path->mnt, mode)) {
49043+ error = -EACCES;
49044+ goto out_unlock;
49045+ }
49046+
49047 error = security_path_chmod(path, mode);
49048 if (error)
49049 goto out_unlock;
49050@@ -517,6 +551,9 @@ static int chown_common(struct path *path, uid_t user, gid_t group)
49051 uid = make_kuid(current_user_ns(), user);
49052 gid = make_kgid(current_user_ns(), group);
49053
49054+ if (!gr_acl_handle_chown(path->dentry, path->mnt))
49055+ return -EACCES;
49056+
49057 newattrs.ia_valid = ATTR_CTIME;
49058 if (user != (uid_t) -1) {
49059 if (!uid_valid(uid))
49060@@ -958,6 +995,7 @@ long do_sys_open(int dfd, const char __user *filename, int flags, umode_t mode)
49061 } else {
49062 fsnotify_open(f);
49063 fd_install(fd, f);
49064+ trace_do_sys_open(tmp, flags, mode);
49065 }
49066 }
49067 putname(tmp);
49068diff --git a/fs/pipe.c b/fs/pipe.c
49069index 8d85d70..581036b 100644
49070--- a/fs/pipe.c
49071+++ b/fs/pipe.c
49072@@ -438,9 +438,9 @@ redo:
49073 }
49074 if (bufs) /* More to do? */
49075 continue;
49076- if (!pipe->writers)
49077+ if (!atomic_read(&pipe->writers))
49078 break;
49079- if (!pipe->waiting_writers) {
49080+ if (!atomic_read(&pipe->waiting_writers)) {
49081 /* syscall merging: Usually we must not sleep
49082 * if O_NONBLOCK is set, or if we got some data.
49083 * But if a writer sleeps in kernel space, then
49084@@ -504,7 +504,7 @@ pipe_write(struct kiocb *iocb, const struct iovec *_iov,
49085 mutex_lock(&inode->i_mutex);
49086 pipe = inode->i_pipe;
49087
49088- if (!pipe->readers) {
49089+ if (!atomic_read(&pipe->readers)) {
49090 send_sig(SIGPIPE, current, 0);
49091 ret = -EPIPE;
49092 goto out;
49093@@ -553,7 +553,7 @@ redo1:
49094 for (;;) {
49095 int bufs;
49096
49097- if (!pipe->readers) {
49098+ if (!atomic_read(&pipe->readers)) {
49099 send_sig(SIGPIPE, current, 0);
49100 if (!ret)
49101 ret = -EPIPE;
49102@@ -644,9 +644,9 @@ redo2:
49103 kill_fasync(&pipe->fasync_readers, SIGIO, POLL_IN);
49104 do_wakeup = 0;
49105 }
49106- pipe->waiting_writers++;
49107+ atomic_inc(&pipe->waiting_writers);
49108 pipe_wait(pipe);
49109- pipe->waiting_writers--;
49110+ atomic_dec(&pipe->waiting_writers);
49111 }
49112 out:
49113 mutex_unlock(&inode->i_mutex);
49114@@ -716,7 +716,7 @@ pipe_poll(struct file *filp, poll_table *wait)
49115 mask = 0;
49116 if (filp->f_mode & FMODE_READ) {
49117 mask = (nrbufs > 0) ? POLLIN | POLLRDNORM : 0;
49118- if (!pipe->writers && filp->f_version != pipe->w_counter)
49119+ if (!atomic_read(&pipe->writers) && filp->f_version != pipe->w_counter)
49120 mask |= POLLHUP;
49121 }
49122
49123@@ -726,7 +726,7 @@ pipe_poll(struct file *filp, poll_table *wait)
49124 * Most Unices do not set POLLERR for FIFOs but on Linux they
49125 * behave exactly like pipes for poll().
49126 */
49127- if (!pipe->readers)
49128+ if (!atomic_read(&pipe->readers))
49129 mask |= POLLERR;
49130 }
49131
49132@@ -740,10 +740,10 @@ pipe_release(struct inode *inode, int decr, int decw)
49133
49134 mutex_lock(&inode->i_mutex);
49135 pipe = inode->i_pipe;
49136- pipe->readers -= decr;
49137- pipe->writers -= decw;
49138+ atomic_sub(decr, &pipe->readers);
49139+ atomic_sub(decw, &pipe->writers);
49140
49141- if (!pipe->readers && !pipe->writers) {
49142+ if (!atomic_read(&pipe->readers) && !atomic_read(&pipe->writers)) {
49143 free_pipe_info(inode);
49144 } else {
49145 wake_up_interruptible_sync_poll(&pipe->wait, POLLIN | POLLOUT | POLLRDNORM | POLLWRNORM | POLLERR | POLLHUP);
49146@@ -833,7 +833,7 @@ pipe_read_open(struct inode *inode, struct file *filp)
49147
49148 if (inode->i_pipe) {
49149 ret = 0;
49150- inode->i_pipe->readers++;
49151+ atomic_inc(&inode->i_pipe->readers);
49152 }
49153
49154 mutex_unlock(&inode->i_mutex);
49155@@ -850,7 +850,7 @@ pipe_write_open(struct inode *inode, struct file *filp)
49156
49157 if (inode->i_pipe) {
49158 ret = 0;
49159- inode->i_pipe->writers++;
49160+ atomic_inc(&inode->i_pipe->writers);
49161 }
49162
49163 mutex_unlock(&inode->i_mutex);
49164@@ -868,9 +868,9 @@ pipe_rdwr_open(struct inode *inode, struct file *filp)
49165 if (inode->i_pipe) {
49166 ret = 0;
49167 if (filp->f_mode & FMODE_READ)
49168- inode->i_pipe->readers++;
49169+ atomic_inc(&inode->i_pipe->readers);
49170 if (filp->f_mode & FMODE_WRITE)
49171- inode->i_pipe->writers++;
49172+ atomic_inc(&inode->i_pipe->writers);
49173 }
49174
49175 mutex_unlock(&inode->i_mutex);
49176@@ -962,7 +962,7 @@ void free_pipe_info(struct inode *inode)
49177 inode->i_pipe = NULL;
49178 }
49179
49180-static struct vfsmount *pipe_mnt __read_mostly;
49181+struct vfsmount *pipe_mnt __read_mostly;
49182
49183 /*
49184 * pipefs_dname() is called from d_path().
49185@@ -992,7 +992,8 @@ static struct inode * get_pipe_inode(void)
49186 goto fail_iput;
49187 inode->i_pipe = pipe;
49188
49189- pipe->readers = pipe->writers = 1;
49190+ atomic_set(&pipe->readers, 1);
49191+ atomic_set(&pipe->writers, 1);
49192 inode->i_fop = &rdwr_pipefifo_fops;
49193
49194 /*
49195diff --git a/fs/proc/Kconfig b/fs/proc/Kconfig
49196index 15af622..0e9f4467 100644
49197--- a/fs/proc/Kconfig
49198+++ b/fs/proc/Kconfig
49199@@ -30,12 +30,12 @@ config PROC_FS
49200
49201 config PROC_KCORE
49202 bool "/proc/kcore support" if !ARM
49203- depends on PROC_FS && MMU
49204+ depends on PROC_FS && MMU && !GRKERNSEC_PROC_ADD
49205
49206 config PROC_VMCORE
49207 bool "/proc/vmcore support"
49208- depends on PROC_FS && CRASH_DUMP
49209- default y
49210+ depends on PROC_FS && CRASH_DUMP && !GRKERNSEC
49211+ default n
49212 help
49213 Exports the dump image of crashed kernel in ELF format.
49214
49215@@ -59,8 +59,8 @@ config PROC_SYSCTL
49216 limited in memory.
49217
49218 config PROC_PAGE_MONITOR
49219- default y
49220- depends on PROC_FS && MMU
49221+ default n
49222+ depends on PROC_FS && MMU && !GRKERNSEC
49223 bool "Enable /proc page monitoring" if EXPERT
49224 help
49225 Various /proc files exist to monitor process memory utilization:
49226diff --git a/fs/proc/array.c b/fs/proc/array.c
49227index c1c207c..01ce725 100644
49228--- a/fs/proc/array.c
49229+++ b/fs/proc/array.c
49230@@ -60,6 +60,7 @@
49231 #include <linux/tty.h>
49232 #include <linux/string.h>
49233 #include <linux/mman.h>
49234+#include <linux/grsecurity.h>
49235 #include <linux/proc_fs.h>
49236 #include <linux/ioport.h>
49237 #include <linux/uaccess.h>
49238@@ -346,6 +347,21 @@ static void task_cpus_allowed(struct seq_file *m, struct task_struct *task)
49239 seq_putc(m, '\n');
49240 }
49241
49242+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
49243+static inline void task_pax(struct seq_file *m, struct task_struct *p)
49244+{
49245+ if (p->mm)
49246+ seq_printf(m, "PaX:\t%c%c%c%c%c\n",
49247+ p->mm->pax_flags & MF_PAX_PAGEEXEC ? 'P' : 'p',
49248+ p->mm->pax_flags & MF_PAX_EMUTRAMP ? 'E' : 'e',
49249+ p->mm->pax_flags & MF_PAX_MPROTECT ? 'M' : 'm',
49250+ p->mm->pax_flags & MF_PAX_RANDMMAP ? 'R' : 'r',
49251+ p->mm->pax_flags & MF_PAX_SEGMEXEC ? 'S' : 's');
49252+ else
49253+ seq_printf(m, "PaX:\t-----\n");
49254+}
49255+#endif
49256+
49257 int proc_pid_status(struct seq_file *m, struct pid_namespace *ns,
49258 struct pid *pid, struct task_struct *task)
49259 {
49260@@ -363,9 +379,24 @@ int proc_pid_status(struct seq_file *m, struct pid_namespace *ns,
49261 task_cpus_allowed(m, task);
49262 cpuset_task_status_allowed(m, task);
49263 task_context_switch_counts(m, task);
49264+
49265+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
49266+ task_pax(m, task);
49267+#endif
49268+
49269+#if defined(CONFIG_GRKERNSEC) && !defined(CONFIG_GRKERNSEC_NO_RBAC)
49270+ task_grsec_rbac(m, task);
49271+#endif
49272+
49273 return 0;
49274 }
49275
49276+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
49277+#define PAX_RAND_FLAGS(_mm) (_mm != NULL && _mm != current->mm && \
49278+ (_mm->pax_flags & MF_PAX_RANDMMAP || \
49279+ _mm->pax_flags & MF_PAX_SEGMEXEC))
49280+#endif
49281+
49282 static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
49283 struct pid *pid, struct task_struct *task, int whole)
49284 {
49285@@ -387,6 +418,13 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
49286 char tcomm[sizeof(task->comm)];
49287 unsigned long flags;
49288
49289+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
49290+ if (current->exec_id != m->exec_id) {
49291+ gr_log_badprocpid("stat");
49292+ return 0;
49293+ }
49294+#endif
49295+
49296 state = *get_task_state(task);
49297 vsize = eip = esp = 0;
49298 permitted = ptrace_may_access(task, PTRACE_MODE_READ | PTRACE_MODE_NOAUDIT);
49299@@ -458,6 +496,19 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
49300 gtime = task->gtime;
49301 }
49302
49303+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
49304+ if (PAX_RAND_FLAGS(mm)) {
49305+ eip = 0;
49306+ esp = 0;
49307+ wchan = 0;
49308+ }
49309+#endif
49310+#ifdef CONFIG_GRKERNSEC_HIDESYM
49311+ wchan = 0;
49312+ eip =0;
49313+ esp =0;
49314+#endif
49315+
49316 /* scale priority and nice values from timeslices to -20..20 */
49317 /* to make it look like a "normal" Unix priority/nice value */
49318 priority = task_prio(task);
49319@@ -494,9 +545,15 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
49320 seq_put_decimal_ull(m, ' ', vsize);
49321 seq_put_decimal_ull(m, ' ', mm ? get_mm_rss(mm) : 0);
49322 seq_put_decimal_ull(m, ' ', rsslim);
49323+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
49324+ seq_put_decimal_ull(m, ' ', PAX_RAND_FLAGS(mm) ? 1 : (mm ? (permitted ? mm->start_code : 1) : 0));
49325+ seq_put_decimal_ull(m, ' ', PAX_RAND_FLAGS(mm) ? 1 : (mm ? (permitted ? mm->end_code : 1) : 0));
49326+ seq_put_decimal_ull(m, ' ', PAX_RAND_FLAGS(mm) ? 0 : ((permitted && mm) ? mm->start_stack : 0));
49327+#else
49328 seq_put_decimal_ull(m, ' ', mm ? (permitted ? mm->start_code : 1) : 0);
49329 seq_put_decimal_ull(m, ' ', mm ? (permitted ? mm->end_code : 1) : 0);
49330 seq_put_decimal_ull(m, ' ', (permitted && mm) ? mm->start_stack : 0);
49331+#endif
49332 seq_put_decimal_ull(m, ' ', esp);
49333 seq_put_decimal_ull(m, ' ', eip);
49334 /* The signal information here is obsolete.
49335@@ -518,7 +575,11 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
49336 seq_put_decimal_ull(m, ' ', cputime_to_clock_t(gtime));
49337 seq_put_decimal_ll(m, ' ', cputime_to_clock_t(cgtime));
49338
49339- if (mm && permitted) {
49340+ if (mm && permitted
49341+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
49342+ && !PAX_RAND_FLAGS(mm)
49343+#endif
49344+ ) {
49345 seq_put_decimal_ull(m, ' ', mm->start_data);
49346 seq_put_decimal_ull(m, ' ', mm->end_data);
49347 seq_put_decimal_ull(m, ' ', mm->start_brk);
49348@@ -556,8 +617,15 @@ int proc_pid_statm(struct seq_file *m, struct pid_namespace *ns,
49349 struct pid *pid, struct task_struct *task)
49350 {
49351 unsigned long size = 0, resident = 0, shared = 0, text = 0, data = 0;
49352- struct mm_struct *mm = get_task_mm(task);
49353+ struct mm_struct *mm;
49354
49355+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
49356+ if (current->exec_id != m->exec_id) {
49357+ gr_log_badprocpid("statm");
49358+ return 0;
49359+ }
49360+#endif
49361+ mm = get_task_mm(task);
49362 if (mm) {
49363 size = task_statm(mm, &shared, &text, &data, &resident);
49364 mmput(mm);
49365@@ -580,6 +648,13 @@ int proc_pid_statm(struct seq_file *m, struct pid_namespace *ns,
49366 return 0;
49367 }
49368
49369+#ifdef CONFIG_GRKERNSEC_PROC_IPADDR
49370+int proc_pid_ipaddr(struct task_struct *task, char *buffer)
49371+{
49372+ return sprintf(buffer, "%pI4\n", &task->signal->curr_ip);
49373+}
49374+#endif
49375+
49376 #ifdef CONFIG_CHECKPOINT_RESTORE
49377 static struct pid *
49378 get_children_pid(struct inode *inode, struct pid *pid_prev, loff_t pos)
49379diff --git a/fs/proc/base.c b/fs/proc/base.c
49380index 1b6c84c..66b738b 100644
49381--- a/fs/proc/base.c
49382+++ b/fs/proc/base.c
49383@@ -110,6 +110,14 @@ struct pid_entry {
49384 union proc_op op;
49385 };
49386
49387+struct getdents_callback {
49388+ struct linux_dirent __user * current_dir;
49389+ struct linux_dirent __user * previous;
49390+ struct file * file;
49391+ int count;
49392+ int error;
49393+};
49394+
49395 #define NOD(NAME, MODE, IOP, FOP, OP) { \
49396 .name = (NAME), \
49397 .len = sizeof(NAME) - 1, \
49398@@ -209,6 +217,9 @@ static int proc_pid_cmdline(struct task_struct *task, char * buffer)
49399 if (!mm->arg_end)
49400 goto out_mm; /* Shh! No looking before we're done */
49401
49402+ if (gr_acl_handle_procpidmem(task))
49403+ goto out_mm;
49404+
49405 len = mm->arg_end - mm->arg_start;
49406
49407 if (len > PAGE_SIZE)
49408@@ -236,12 +247,28 @@ out:
49409 return res;
49410 }
49411
49412+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
49413+#define PAX_RAND_FLAGS(_mm) (_mm != NULL && _mm != current->mm && \
49414+ (_mm->pax_flags & MF_PAX_RANDMMAP || \
49415+ _mm->pax_flags & MF_PAX_SEGMEXEC))
49416+#endif
49417+
49418 static int proc_pid_auxv(struct task_struct *task, char *buffer)
49419 {
49420 struct mm_struct *mm = mm_access(task, PTRACE_MODE_READ);
49421 int res = PTR_ERR(mm);
49422 if (mm && !IS_ERR(mm)) {
49423 unsigned int nwords = 0;
49424+
49425+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
49426+ /* allow if we're currently ptracing this task */
49427+ if (PAX_RAND_FLAGS(mm) &&
49428+ (!(task->ptrace & PT_PTRACED) || (task->parent != current))) {
49429+ mmput(mm);
49430+ return 0;
49431+ }
49432+#endif
49433+
49434 do {
49435 nwords += 2;
49436 } while (mm->saved_auxv[nwords - 2] != 0); /* AT_NULL */
49437@@ -255,7 +282,7 @@ static int proc_pid_auxv(struct task_struct *task, char *buffer)
49438 }
49439
49440
49441-#ifdef CONFIG_KALLSYMS
49442+#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
49443 /*
49444 * Provides a wchan file via kallsyms in a proper one-value-per-file format.
49445 * Returns the resolved symbol. If that fails, simply return the address.
49446@@ -294,7 +321,7 @@ static void unlock_trace(struct task_struct *task)
49447 mutex_unlock(&task->signal->cred_guard_mutex);
49448 }
49449
49450-#ifdef CONFIG_STACKTRACE
49451+#if defined(CONFIG_STACKTRACE) && !defined(CONFIG_GRKERNSEC_HIDESYM)
49452
49453 #define MAX_STACK_TRACE_DEPTH 64
49454
49455@@ -486,7 +513,7 @@ static int proc_pid_limits(struct task_struct *task, char *buffer)
49456 return count;
49457 }
49458
49459-#ifdef CONFIG_HAVE_ARCH_TRACEHOOK
49460+#if defined(CONFIG_HAVE_ARCH_TRACEHOOK) && !defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
49461 static int proc_pid_syscall(struct task_struct *task, char *buffer)
49462 {
49463 long nr;
49464@@ -515,7 +542,7 @@ static int proc_pid_syscall(struct task_struct *task, char *buffer)
49465 /************************************************************************/
49466
49467 /* permission checks */
49468-static int proc_fd_access_allowed(struct inode *inode)
49469+static int proc_fd_access_allowed(struct inode *inode, unsigned int log)
49470 {
49471 struct task_struct *task;
49472 int allowed = 0;
49473@@ -525,7 +552,10 @@ static int proc_fd_access_allowed(struct inode *inode)
49474 */
49475 task = get_proc_task(inode);
49476 if (task) {
49477- allowed = ptrace_may_access(task, PTRACE_MODE_READ);
49478+ if (log)
49479+ allowed = ptrace_may_access(task, PTRACE_MODE_READ);
49480+ else
49481+ allowed = ptrace_may_access(task, PTRACE_MODE_READ | PTRACE_MODE_NOAUDIT);
49482 put_task_struct(task);
49483 }
49484 return allowed;
49485@@ -563,10 +593,35 @@ static bool has_pid_permissions(struct pid_namespace *pid,
49486 struct task_struct *task,
49487 int hide_pid_min)
49488 {
49489+ if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
49490+ return false;
49491+
49492+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
49493+ rcu_read_lock();
49494+ {
49495+ const struct cred *tmpcred = current_cred();
49496+ const struct cred *cred = __task_cred(task);
49497+
49498+ if (!tmpcred->uid || (tmpcred->uid == cred->uid)
49499+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
49500+ || in_group_p(grsec_proc_gid)
49501+#endif
49502+ ) {
49503+ rcu_read_unlock();
49504+ return true;
49505+ }
49506+ }
49507+ rcu_read_unlock();
49508+
49509+ if (!pid->hide_pid)
49510+ return false;
49511+#endif
49512+
49513 if (pid->hide_pid < hide_pid_min)
49514 return true;
49515 if (in_group_p(pid->pid_gid))
49516 return true;
49517+
49518 return ptrace_may_access(task, PTRACE_MODE_READ);
49519 }
49520
49521@@ -584,7 +639,11 @@ static int proc_pid_permission(struct inode *inode, int mask)
49522 put_task_struct(task);
49523
49524 if (!has_perms) {
49525+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
49526+ {
49527+#else
49528 if (pid->hide_pid == 2) {
49529+#endif
49530 /*
49531 * Let's make getdents(), stat(), and open()
49532 * consistent with each other. If a process
49533@@ -682,6 +741,11 @@ static int __mem_open(struct inode *inode, struct file *file, unsigned int mode)
49534 if (!task)
49535 return -ESRCH;
49536
49537+ if (gr_acl_handle_procpidmem(task)) {
49538+ put_task_struct(task);
49539+ return -EPERM;
49540+ }
49541+
49542 mm = mm_access(task, mode);
49543 put_task_struct(task);
49544
49545@@ -697,6 +761,10 @@ static int __mem_open(struct inode *inode, struct file *file, unsigned int mode)
49546
49547 file->private_data = mm;
49548
49549+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
49550+ file->f_version = current->exec_id;
49551+#endif
49552+
49553 return 0;
49554 }
49555
49556@@ -718,6 +786,17 @@ static ssize_t mem_rw(struct file *file, char __user *buf,
49557 ssize_t copied;
49558 char *page;
49559
49560+#ifdef CONFIG_GRKERNSEC
49561+ if (write)
49562+ return -EPERM;
49563+#endif
49564+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
49565+ if (file->f_version != current->exec_id) {
49566+ gr_log_badprocpid("mem");
49567+ return 0;
49568+ }
49569+#endif
49570+
49571 if (!mm)
49572 return 0;
49573
49574@@ -822,6 +901,13 @@ static ssize_t environ_read(struct file *file, char __user *buf,
49575 if (!mm)
49576 return 0;
49577
49578+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
49579+ if (file->f_version != current->exec_id) {
49580+ gr_log_badprocpid("environ");
49581+ return 0;
49582+ }
49583+#endif
49584+
49585 page = (char *)__get_free_page(GFP_TEMPORARY);
49586 if (!page)
49587 return -ENOMEM;
49588@@ -1435,7 +1521,7 @@ static void *proc_pid_follow_link(struct dentry *dentry, struct nameidata *nd)
49589 int error = -EACCES;
49590
49591 /* Are we allowed to snoop on the tasks file descriptors? */
49592- if (!proc_fd_access_allowed(inode))
49593+ if (!proc_fd_access_allowed(inode, 0))
49594 goto out;
49595
49596 error = PROC_I(inode)->op.proc_get_link(dentry, &path);
49597@@ -1479,8 +1565,18 @@ static int proc_pid_readlink(struct dentry * dentry, char __user * buffer, int b
49598 struct path path;
49599
49600 /* Are we allowed to snoop on the tasks file descriptors? */
49601- if (!proc_fd_access_allowed(inode))
49602- goto out;
49603+ /* logging this is needed for learning on chromium to work properly,
49604+ but we don't want to flood the logs from 'ps' which does a readlink
49605+ on /proc/fd/2 of tasks in the listing, nor do we want 'ps' to learn
49606+ CAP_SYS_PTRACE as it's not necessary for its basic functionality
49607+ */
49608+ if (dentry->d_name.name[0] == '2' && dentry->d_name.name[1] == '\0') {
49609+ if (!proc_fd_access_allowed(inode,0))
49610+ goto out;
49611+ } else {
49612+ if (!proc_fd_access_allowed(inode,1))
49613+ goto out;
49614+ }
49615
49616 error = PROC_I(inode)->op.proc_get_link(dentry, &path);
49617 if (error)
49618@@ -1545,7 +1641,11 @@ struct inode *proc_pid_make_inode(struct super_block * sb, struct task_struct *t
49619 rcu_read_lock();
49620 cred = __task_cred(task);
49621 inode->i_uid = cred->euid;
49622+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
49623+ inode->i_gid = grsec_proc_gid;
49624+#else
49625 inode->i_gid = cred->egid;
49626+#endif
49627 rcu_read_unlock();
49628 }
49629 security_task_to_inode(task, inode);
49630@@ -1581,10 +1681,19 @@ int pid_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat)
49631 return -ENOENT;
49632 }
49633 if ((inode->i_mode == (S_IFDIR|S_IRUGO|S_IXUGO)) ||
49634+#ifdef CONFIG_GRKERNSEC_PROC_USER
49635+ (inode->i_mode == (S_IFDIR|S_IRUSR|S_IXUSR)) ||
49636+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
49637+ (inode->i_mode == (S_IFDIR|S_IRUSR|S_IRGRP|S_IXUSR|S_IXGRP)) ||
49638+#endif
49639 task_dumpable(task)) {
49640 cred = __task_cred(task);
49641 stat->uid = cred->euid;
49642+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
49643+ stat->gid = grsec_proc_gid;
49644+#else
49645 stat->gid = cred->egid;
49646+#endif
49647 }
49648 }
49649 rcu_read_unlock();
49650@@ -1622,11 +1731,20 @@ int pid_revalidate(struct dentry *dentry, unsigned int flags)
49651
49652 if (task) {
49653 if ((inode->i_mode == (S_IFDIR|S_IRUGO|S_IXUGO)) ||
49654+#ifdef CONFIG_GRKERNSEC_PROC_USER
49655+ (inode->i_mode == (S_IFDIR|S_IRUSR|S_IXUSR)) ||
49656+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
49657+ (inode->i_mode == (S_IFDIR|S_IRUSR|S_IRGRP|S_IXUSR|S_IXGRP)) ||
49658+#endif
49659 task_dumpable(task)) {
49660 rcu_read_lock();
49661 cred = __task_cred(task);
49662 inode->i_uid = cred->euid;
49663+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
49664+ inode->i_gid = grsec_proc_gid;
49665+#else
49666 inode->i_gid = cred->egid;
49667+#endif
49668 rcu_read_unlock();
49669 } else {
49670 inode->i_uid = GLOBAL_ROOT_UID;
49671@@ -1744,7 +1862,8 @@ static int proc_fd_info(struct inode *inode, struct path *path, char *info)
49672 int fd = proc_fd(inode);
49673
49674 if (task) {
49675- files = get_files_struct(task);
49676+ if (!gr_acl_handle_procpidmem(task))
49677+ files = get_files_struct(task);
49678 put_task_struct(task);
49679 }
49680 if (files) {
49681@@ -2343,11 +2462,21 @@ static const struct file_operations proc_map_files_operations = {
49682 */
49683 static int proc_fd_permission(struct inode *inode, int mask)
49684 {
49685+ struct task_struct *task;
49686 int rv = generic_permission(inode, mask);
49687- if (rv == 0)
49688- return 0;
49689+
49690 if (task_pid(current) == proc_pid(inode))
49691 rv = 0;
49692+
49693+ task = get_proc_task(inode);
49694+ if (task == NULL)
49695+ return rv;
49696+
49697+ if (gr_acl_handle_procpidmem(task))
49698+ rv = -EACCES;
49699+
49700+ put_task_struct(task);
49701+
49702 return rv;
49703 }
49704
49705@@ -2457,6 +2586,9 @@ static struct dentry *proc_pident_lookup(struct inode *dir,
49706 if (!task)
49707 goto out_no_task;
49708
49709+ if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
49710+ goto out;
49711+
49712 /*
49713 * Yes, it does not scale. And it should not. Don't add
49714 * new entries into /proc/<tgid>/ without very good reasons.
49715@@ -2501,6 +2633,9 @@ static int proc_pident_readdir(struct file *filp,
49716 if (!task)
49717 goto out_no_task;
49718
49719+ if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
49720+ goto out;
49721+
49722 ret = 0;
49723 i = filp->f_pos;
49724 switch (i) {
49725@@ -2771,7 +2906,7 @@ static void *proc_self_follow_link(struct dentry *dentry, struct nameidata *nd)
49726 static void proc_self_put_link(struct dentry *dentry, struct nameidata *nd,
49727 void *cookie)
49728 {
49729- char *s = nd_get_link(nd);
49730+ const char *s = nd_get_link(nd);
49731 if (!IS_ERR(s))
49732 __putname(s);
49733 }
49734@@ -3040,7 +3175,7 @@ static const struct pid_entry tgid_base_stuff[] = {
49735 REG("autogroup", S_IRUGO|S_IWUSR, proc_pid_sched_autogroup_operations),
49736 #endif
49737 REG("comm", S_IRUGO|S_IWUSR, proc_pid_set_comm_operations),
49738-#ifdef CONFIG_HAVE_ARCH_TRACEHOOK
49739+#if defined(CONFIG_HAVE_ARCH_TRACEHOOK) && !defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
49740 INF("syscall", S_IRUGO, proc_pid_syscall),
49741 #endif
49742 INF("cmdline", S_IRUGO, proc_pid_cmdline),
49743@@ -3065,10 +3200,10 @@ static const struct pid_entry tgid_base_stuff[] = {
49744 #ifdef CONFIG_SECURITY
49745 DIR("attr", S_IRUGO|S_IXUGO, proc_attr_dir_inode_operations, proc_attr_dir_operations),
49746 #endif
49747-#ifdef CONFIG_KALLSYMS
49748+#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
49749 INF("wchan", S_IRUGO, proc_pid_wchan),
49750 #endif
49751-#ifdef CONFIG_STACKTRACE
49752+#if defined(CONFIG_STACKTRACE) && !defined(CONFIG_GRKERNSEC_HIDESYM)
49753 ONE("stack", S_IRUGO, proc_pid_stack),
49754 #endif
49755 #ifdef CONFIG_SCHEDSTATS
49756@@ -3102,6 +3237,9 @@ static const struct pid_entry tgid_base_stuff[] = {
49757 #ifdef CONFIG_HARDWALL
49758 INF("hardwall", S_IRUGO, proc_pid_hardwall),
49759 #endif
49760+#ifdef CONFIG_GRKERNSEC_PROC_IPADDR
49761+ INF("ipaddr", S_IRUSR, proc_pid_ipaddr),
49762+#endif
49763 #ifdef CONFIG_USER_NS
49764 REG("uid_map", S_IRUGO|S_IWUSR, proc_uid_map_operations),
49765 REG("gid_map", S_IRUGO|S_IWUSR, proc_gid_map_operations),
49766@@ -3233,7 +3371,14 @@ static struct dentry *proc_pid_instantiate(struct inode *dir,
49767 if (!inode)
49768 goto out;
49769
49770+#ifdef CONFIG_GRKERNSEC_PROC_USER
49771+ inode->i_mode = S_IFDIR|S_IRUSR|S_IXUSR;
49772+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
49773+ inode->i_gid = grsec_proc_gid;
49774+ inode->i_mode = S_IFDIR|S_IRUSR|S_IRGRP|S_IXUSR|S_IXGRP;
49775+#else
49776 inode->i_mode = S_IFDIR|S_IRUGO|S_IXUGO;
49777+#endif
49778 inode->i_op = &proc_tgid_base_inode_operations;
49779 inode->i_fop = &proc_tgid_base_operations;
49780 inode->i_flags|=S_IMMUTABLE;
49781@@ -3275,7 +3420,11 @@ struct dentry *proc_pid_lookup(struct inode *dir, struct dentry * dentry, unsign
49782 if (!task)
49783 goto out;
49784
49785+ if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
49786+ goto out_put_task;
49787+
49788 result = proc_pid_instantiate(dir, dentry, task, NULL);
49789+out_put_task:
49790 put_task_struct(task);
49791 out:
49792 return result;
49793@@ -3338,6 +3487,8 @@ static int proc_pid_fill_cache(struct file *filp, void *dirent, filldir_t filldi
49794 static int fake_filldir(void *buf, const char *name, int namelen,
49795 loff_t offset, u64 ino, unsigned d_type)
49796 {
49797+ struct getdents_callback * __buf = (struct getdents_callback *) buf;
49798+ __buf->error = -EINVAL;
49799 return 0;
49800 }
49801
49802@@ -3404,7 +3555,7 @@ static const struct pid_entry tid_base_stuff[] = {
49803 REG("sched", S_IRUGO|S_IWUSR, proc_pid_sched_operations),
49804 #endif
49805 REG("comm", S_IRUGO|S_IWUSR, proc_pid_set_comm_operations),
49806-#ifdef CONFIG_HAVE_ARCH_TRACEHOOK
49807+#if defined(CONFIG_HAVE_ARCH_TRACEHOOK) && !defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
49808 INF("syscall", S_IRUGO, proc_pid_syscall),
49809 #endif
49810 INF("cmdline", S_IRUGO, proc_pid_cmdline),
49811@@ -3431,10 +3582,10 @@ static const struct pid_entry tid_base_stuff[] = {
49812 #ifdef CONFIG_SECURITY
49813 DIR("attr", S_IRUGO|S_IXUGO, proc_attr_dir_inode_operations, proc_attr_dir_operations),
49814 #endif
49815-#ifdef CONFIG_KALLSYMS
49816+#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
49817 INF("wchan", S_IRUGO, proc_pid_wchan),
49818 #endif
49819-#ifdef CONFIG_STACKTRACE
49820+#if defined(CONFIG_STACKTRACE) && !defined(CONFIG_GRKERNSEC_HIDESYM)
49821 ONE("stack", S_IRUGO, proc_pid_stack),
49822 #endif
49823 #ifdef CONFIG_SCHEDSTATS
49824diff --git a/fs/proc/cmdline.c b/fs/proc/cmdline.c
49825index 82676e3..5f8518a 100644
49826--- a/fs/proc/cmdline.c
49827+++ b/fs/proc/cmdline.c
49828@@ -23,7 +23,11 @@ static const struct file_operations cmdline_proc_fops = {
49829
49830 static int __init proc_cmdline_init(void)
49831 {
49832+#ifdef CONFIG_GRKERNSEC_PROC_ADD
49833+ proc_create_grsec("cmdline", 0, NULL, &cmdline_proc_fops);
49834+#else
49835 proc_create("cmdline", 0, NULL, &cmdline_proc_fops);
49836+#endif
49837 return 0;
49838 }
49839 module_init(proc_cmdline_init);
49840diff --git a/fs/proc/devices.c b/fs/proc/devices.c
49841index b143471..bb105e5 100644
49842--- a/fs/proc/devices.c
49843+++ b/fs/proc/devices.c
49844@@ -64,7 +64,11 @@ static const struct file_operations proc_devinfo_operations = {
49845
49846 static int __init proc_devices_init(void)
49847 {
49848+#ifdef CONFIG_GRKERNSEC_PROC_ADD
49849+ proc_create_grsec("devices", 0, NULL, &proc_devinfo_operations);
49850+#else
49851 proc_create("devices", 0, NULL, &proc_devinfo_operations);
49852+#endif
49853 return 0;
49854 }
49855 module_init(proc_devices_init);
49856diff --git a/fs/proc/inode.c b/fs/proc/inode.c
49857index 7ac817b..c5c9eb0 100644
49858--- a/fs/proc/inode.c
49859+++ b/fs/proc/inode.c
49860@@ -21,11 +21,17 @@
49861 #include <linux/seq_file.h>
49862 #include <linux/slab.h>
49863 #include <linux/mount.h>
49864+#include <linux/grsecurity.h>
49865
49866 #include <asm/uaccess.h>
49867
49868 #include "internal.h"
49869
49870+#ifdef CONFIG_PROC_SYSCTL
49871+extern const struct inode_operations proc_sys_inode_operations;
49872+extern const struct inode_operations proc_sys_dir_operations;
49873+#endif
49874+
49875 static void proc_evict_inode(struct inode *inode)
49876 {
49877 struct proc_dir_entry *de;
49878@@ -51,6 +57,13 @@ static void proc_evict_inode(struct inode *inode)
49879 ns_ops = PROC_I(inode)->ns_ops;
49880 if (ns_ops && ns_ops->put)
49881 ns_ops->put(PROC_I(inode)->ns);
49882+
49883+#ifdef CONFIG_PROC_SYSCTL
49884+ if (inode->i_op == &proc_sys_inode_operations ||
49885+ inode->i_op == &proc_sys_dir_operations)
49886+ gr_handle_delete(inode->i_ino, inode->i_sb->s_dev);
49887+#endif
49888+
49889 }
49890
49891 static struct kmem_cache * proc_inode_cachep;
49892@@ -456,7 +469,11 @@ struct inode *proc_get_inode(struct super_block *sb, struct proc_dir_entry *de)
49893 if (de->mode) {
49894 inode->i_mode = de->mode;
49895 inode->i_uid = de->uid;
49896+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
49897+ inode->i_gid = grsec_proc_gid;
49898+#else
49899 inode->i_gid = de->gid;
49900+#endif
49901 }
49902 if (de->size)
49903 inode->i_size = de->size;
49904diff --git a/fs/proc/internal.h b/fs/proc/internal.h
49905index e1167a1..bd24f20 100644
49906--- a/fs/proc/internal.h
49907+++ b/fs/proc/internal.h
49908@@ -52,6 +52,9 @@ extern int proc_pid_status(struct seq_file *m, struct pid_namespace *ns,
49909 struct pid *pid, struct task_struct *task);
49910 extern int proc_pid_statm(struct seq_file *m, struct pid_namespace *ns,
49911 struct pid *pid, struct task_struct *task);
49912+#ifdef CONFIG_GRKERNSEC_PROC_IPADDR
49913+extern int proc_pid_ipaddr(struct task_struct *task, char *buffer);
49914+#endif
49915 extern loff_t mem_lseek(struct file *file, loff_t offset, int orig);
49916
49917 extern const struct file_operations proc_tid_children_operations;
49918diff --git a/fs/proc/kcore.c b/fs/proc/kcore.c
49919index 86c67ee..cdca321 100644
49920--- a/fs/proc/kcore.c
49921+++ b/fs/proc/kcore.c
49922@@ -480,9 +480,10 @@ read_kcore(struct file *file, char __user *buffer, size_t buflen, loff_t *fpos)
49923 * the addresses in the elf_phdr on our list.
49924 */
49925 start = kc_offset_to_vaddr(*fpos - elf_buflen);
49926- if ((tsz = (PAGE_SIZE - (start & ~PAGE_MASK))) > buflen)
49927+ tsz = PAGE_SIZE - (start & ~PAGE_MASK);
49928+ if (tsz > buflen)
49929 tsz = buflen;
49930-
49931+
49932 while (buflen) {
49933 struct kcore_list *m;
49934
49935@@ -511,20 +512,23 @@ read_kcore(struct file *file, char __user *buffer, size_t buflen, loff_t *fpos)
49936 kfree(elf_buf);
49937 } else {
49938 if (kern_addr_valid(start)) {
49939- unsigned long n;
49940+ char *elf_buf;
49941+ mm_segment_t oldfs;
49942
49943- n = copy_to_user(buffer, (char *)start, tsz);
49944- /*
49945- * We cannot distinguish between fault on source
49946- * and fault on destination. When this happens
49947- * we clear too and hope it will trigger the
49948- * EFAULT again.
49949- */
49950- if (n) {
49951- if (clear_user(buffer + tsz - n,
49952- n))
49953+ elf_buf = kmalloc(tsz, GFP_KERNEL);
49954+ if (!elf_buf)
49955+ return -ENOMEM;
49956+ oldfs = get_fs();
49957+ set_fs(KERNEL_DS);
49958+ if (!__copy_from_user(elf_buf, (const void __user *)start, tsz)) {
49959+ set_fs(oldfs);
49960+ if (copy_to_user(buffer, elf_buf, tsz)) {
49961+ kfree(elf_buf);
49962 return -EFAULT;
49963+ }
49964 }
49965+ set_fs(oldfs);
49966+ kfree(elf_buf);
49967 } else {
49968 if (clear_user(buffer, tsz))
49969 return -EFAULT;
49970@@ -544,6 +548,9 @@ read_kcore(struct file *file, char __user *buffer, size_t buflen, loff_t *fpos)
49971
49972 static int open_kcore(struct inode *inode, struct file *filp)
49973 {
49974+#if defined(CONFIG_GRKERNSEC_PROC_ADD) || defined(CONFIG_GRKERNSEC_HIDESYM)
49975+ return -EPERM;
49976+#endif
49977 if (!capable(CAP_SYS_RAWIO))
49978 return -EPERM;
49979 if (kcore_need_update)
49980diff --git a/fs/proc/meminfo.c b/fs/proc/meminfo.c
49981index 80e4645..53e5fcf 100644
49982--- a/fs/proc/meminfo.c
49983+++ b/fs/proc/meminfo.c
49984@@ -158,7 +158,7 @@ static int meminfo_proc_show(struct seq_file *m, void *v)
49985 vmi.used >> 10,
49986 vmi.largest_chunk >> 10
49987 #ifdef CONFIG_MEMORY_FAILURE
49988- ,atomic_long_read(&mce_bad_pages) << (PAGE_SHIFT - 10)
49989+ ,atomic_long_read_unchecked(&mce_bad_pages) << (PAGE_SHIFT - 10)
49990 #endif
49991 #ifdef CONFIG_TRANSPARENT_HUGEPAGE
49992 ,K(global_page_state(NR_ANON_TRANSPARENT_HUGEPAGES) *
49993diff --git a/fs/proc/nommu.c b/fs/proc/nommu.c
49994index b1822dd..df622cb 100644
49995--- a/fs/proc/nommu.c
49996+++ b/fs/proc/nommu.c
49997@@ -66,7 +66,7 @@ static int nommu_region_show(struct seq_file *m, struct vm_region *region)
49998 if (len < 1)
49999 len = 1;
50000 seq_printf(m, "%*c", len, ' ');
50001- seq_path(m, &file->f_path, "");
50002+ seq_path(m, &file->f_path, "\n\\");
50003 }
50004
50005 seq_putc(m, '\n');
50006diff --git a/fs/proc/proc_net.c b/fs/proc/proc_net.c
50007index fe72cd0..cb9b67d 100644
50008--- a/fs/proc/proc_net.c
50009+++ b/fs/proc/proc_net.c
50010@@ -23,6 +23,7 @@
50011 #include <linux/nsproxy.h>
50012 #include <net/net_namespace.h>
50013 #include <linux/seq_file.h>
50014+#include <linux/grsecurity.h>
50015
50016 #include "internal.h"
50017
50018@@ -105,6 +106,17 @@ static struct net *get_proc_task_net(struct inode *dir)
50019 struct task_struct *task;
50020 struct nsproxy *ns;
50021 struct net *net = NULL;
50022+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
50023+ const struct cred *cred = current_cred();
50024+#endif
50025+
50026+#ifdef CONFIG_GRKERNSEC_PROC_USER
50027+ if (cred->fsuid)
50028+ return net;
50029+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
50030+ if (cred->fsuid && !in_group_p(grsec_proc_gid))
50031+ return net;
50032+#endif
50033
50034 rcu_read_lock();
50035 task = pid_task(proc_pid(dir), PIDTYPE_PID);
50036diff --git a/fs/proc/proc_sysctl.c b/fs/proc/proc_sysctl.c
50037index eb7cc91..7327a46 100644
50038--- a/fs/proc/proc_sysctl.c
50039+++ b/fs/proc/proc_sysctl.c
50040@@ -12,11 +12,15 @@
50041 #include <linux/module.h>
50042 #include "internal.h"
50043
50044+extern int gr_handle_chroot_sysctl(const int op);
50045+extern int gr_handle_sysctl_mod(const char *dirname, const char *name,
50046+ const int op);
50047+
50048 static const struct dentry_operations proc_sys_dentry_operations;
50049 static const struct file_operations proc_sys_file_operations;
50050-static const struct inode_operations proc_sys_inode_operations;
50051+const struct inode_operations proc_sys_inode_operations;
50052 static const struct file_operations proc_sys_dir_file_operations;
50053-static const struct inode_operations proc_sys_dir_operations;
50054+const struct inode_operations proc_sys_dir_operations;
50055
50056 void proc_sys_poll_notify(struct ctl_table_poll *poll)
50057 {
50058@@ -467,6 +471,9 @@ static struct dentry *proc_sys_lookup(struct inode *dir, struct dentry *dentry,
50059
50060 err = NULL;
50061 d_set_d_op(dentry, &proc_sys_dentry_operations);
50062+
50063+ gr_handle_proc_create(dentry, inode);
50064+
50065 d_add(dentry, inode);
50066
50067 out:
50068@@ -482,18 +489,20 @@ static ssize_t proc_sys_call_handler(struct file *filp, void __user *buf,
50069 struct inode *inode = filp->f_path.dentry->d_inode;
50070 struct ctl_table_header *head = grab_header(inode);
50071 struct ctl_table *table = PROC_I(inode)->sysctl_entry;
50072+ int op = write ? MAY_WRITE : MAY_READ;
50073 ssize_t error;
50074 size_t res;
50075
50076 if (IS_ERR(head))
50077 return PTR_ERR(head);
50078
50079+
50080 /*
50081 * At this point we know that the sysctl was not unregistered
50082 * and won't be until we finish.
50083 */
50084 error = -EPERM;
50085- if (sysctl_perm(head->root, table, write ? MAY_WRITE : MAY_READ))
50086+ if (sysctl_perm(head->root, table, op))
50087 goto out;
50088
50089 /* if that can happen at all, it should be -EINVAL, not -EISDIR */
50090@@ -501,6 +510,22 @@ static ssize_t proc_sys_call_handler(struct file *filp, void __user *buf,
50091 if (!table->proc_handler)
50092 goto out;
50093
50094+#ifdef CONFIG_GRKERNSEC
50095+ error = -EPERM;
50096+ if (gr_handle_chroot_sysctl(op))
50097+ goto out;
50098+ dget(filp->f_path.dentry);
50099+ if (gr_handle_sysctl_mod(filp->f_path.dentry->d_parent->d_name.name, table->procname, op)) {
50100+ dput(filp->f_path.dentry);
50101+ goto out;
50102+ }
50103+ dput(filp->f_path.dentry);
50104+ if (!gr_acl_handle_open(filp->f_path.dentry, filp->f_path.mnt, op))
50105+ goto out;
50106+ if (write && !capable(CAP_SYS_ADMIN))
50107+ goto out;
50108+#endif
50109+
50110 /* careful: calling conventions are nasty here */
50111 res = count;
50112 error = table->proc_handler(table, write, buf, &res, ppos);
50113@@ -598,6 +623,9 @@ static int proc_sys_fill_cache(struct file *filp, void *dirent,
50114 return -ENOMEM;
50115 } else {
50116 d_set_d_op(child, &proc_sys_dentry_operations);
50117+
50118+ gr_handle_proc_create(child, inode);
50119+
50120 d_add(child, inode);
50121 }
50122 } else {
50123@@ -641,6 +669,9 @@ static int scan(struct ctl_table_header *head, ctl_table *table,
50124 if ((*pos)++ < file->f_pos)
50125 return 0;
50126
50127+ if (!gr_acl_handle_hidden_file(file->f_path.dentry, file->f_path.mnt))
50128+ return 0;
50129+
50130 if (unlikely(S_ISLNK(table->mode)))
50131 res = proc_sys_link_fill_cache(file, dirent, filldir, head, table);
50132 else
50133@@ -758,6 +789,9 @@ static int proc_sys_getattr(struct vfsmount *mnt, struct dentry *dentry, struct
50134 if (IS_ERR(head))
50135 return PTR_ERR(head);
50136
50137+ if (table && !gr_acl_handle_hidden_file(dentry, mnt))
50138+ return -ENOENT;
50139+
50140 generic_fillattr(inode, stat);
50141 if (table)
50142 stat->mode = (stat->mode & S_IFMT) | table->mode;
50143@@ -780,13 +814,13 @@ static const struct file_operations proc_sys_dir_file_operations = {
50144 .llseek = generic_file_llseek,
50145 };
50146
50147-static const struct inode_operations proc_sys_inode_operations = {
50148+const struct inode_operations proc_sys_inode_operations = {
50149 .permission = proc_sys_permission,
50150 .setattr = proc_sys_setattr,
50151 .getattr = proc_sys_getattr,
50152 };
50153
50154-static const struct inode_operations proc_sys_dir_operations = {
50155+const struct inode_operations proc_sys_dir_operations = {
50156 .lookup = proc_sys_lookup,
50157 .permission = proc_sys_permission,
50158 .setattr = proc_sys_setattr,
50159diff --git a/fs/proc/root.c b/fs/proc/root.c
50160index 9a2d9fd..ddfc92a 100644
50161--- a/fs/proc/root.c
50162+++ b/fs/proc/root.c
50163@@ -187,7 +187,15 @@ void __init proc_root_init(void)
50164 #ifdef CONFIG_PROC_DEVICETREE
50165 proc_device_tree_init();
50166 #endif
50167+#ifdef CONFIG_GRKERNSEC_PROC_ADD
50168+#ifdef CONFIG_GRKERNSEC_PROC_USER
50169+ proc_mkdir_mode("bus", S_IRUSR | S_IXUSR, NULL);
50170+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
50171+ proc_mkdir_mode("bus", S_IRUSR | S_IXUSR | S_IRGRP | S_IXGRP, NULL);
50172+#endif
50173+#else
50174 proc_mkdir("bus", NULL);
50175+#endif
50176 proc_sys_init();
50177 }
50178
50179diff --git a/fs/proc/task_mmu.c b/fs/proc/task_mmu.c
50180index 4540b8f..1b9772f 100644
50181--- a/fs/proc/task_mmu.c
50182+++ b/fs/proc/task_mmu.c
50183@@ -11,12 +11,19 @@
50184 #include <linux/rmap.h>
50185 #include <linux/swap.h>
50186 #include <linux/swapops.h>
50187+#include <linux/grsecurity.h>
50188
50189 #include <asm/elf.h>
50190 #include <asm/uaccess.h>
50191 #include <asm/tlbflush.h>
50192 #include "internal.h"
50193
50194+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
50195+#define PAX_RAND_FLAGS(_mm) (_mm != NULL && _mm != current->mm && \
50196+ (_mm->pax_flags & MF_PAX_RANDMMAP || \
50197+ _mm->pax_flags & MF_PAX_SEGMEXEC))
50198+#endif
50199+
50200 void task_mem(struct seq_file *m, struct mm_struct *mm)
50201 {
50202 unsigned long data, text, lib, swap;
50203@@ -52,8 +59,13 @@ void task_mem(struct seq_file *m, struct mm_struct *mm)
50204 "VmExe:\t%8lu kB\n"
50205 "VmLib:\t%8lu kB\n"
50206 "VmPTE:\t%8lu kB\n"
50207- "VmSwap:\t%8lu kB\n",
50208- hiwater_vm << (PAGE_SHIFT-10),
50209+ "VmSwap:\t%8lu kB\n"
50210+
50211+#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
50212+ "CsBase:\t%8lx\nCsLim:\t%8lx\n"
50213+#endif
50214+
50215+ ,hiwater_vm << (PAGE_SHIFT-10),
50216 (total_vm - mm->reserved_vm) << (PAGE_SHIFT-10),
50217 mm->locked_vm << (PAGE_SHIFT-10),
50218 mm->pinned_vm << (PAGE_SHIFT-10),
50219@@ -62,7 +74,19 @@ void task_mem(struct seq_file *m, struct mm_struct *mm)
50220 data << (PAGE_SHIFT-10),
50221 mm->stack_vm << (PAGE_SHIFT-10), text, lib,
50222 (PTRS_PER_PTE*sizeof(pte_t)*mm->nr_ptes) >> 10,
50223- swap << (PAGE_SHIFT-10));
50224+ swap << (PAGE_SHIFT-10)
50225+
50226+#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
50227+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
50228+ , PAX_RAND_FLAGS(mm) ? 0 : mm->context.user_cs_base
50229+ , PAX_RAND_FLAGS(mm) ? 0 : mm->context.user_cs_limit
50230+#else
50231+ , mm->context.user_cs_base
50232+ , mm->context.user_cs_limit
50233+#endif
50234+#endif
50235+
50236+ );
50237 }
50238
50239 unsigned long task_vsize(struct mm_struct *mm)
50240@@ -231,13 +255,13 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
50241 pgoff = ((loff_t)vma->vm_pgoff) << PAGE_SHIFT;
50242 }
50243
50244- /* We don't show the stack guard page in /proc/maps */
50245+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
50246+ start = PAX_RAND_FLAGS(mm) ? 0UL : vma->vm_start;
50247+ end = PAX_RAND_FLAGS(mm) ? 0UL : vma->vm_end;
50248+#else
50249 start = vma->vm_start;
50250- if (stack_guard_page_start(vma, start))
50251- start += PAGE_SIZE;
50252 end = vma->vm_end;
50253- if (stack_guard_page_end(vma, end))
50254- end -= PAGE_SIZE;
50255+#endif
50256
50257 seq_printf(m, "%08lx-%08lx %c%c%c%c %08llx %02x:%02x %lu %n",
50258 start,
50259@@ -246,7 +270,11 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
50260 flags & VM_WRITE ? 'w' : '-',
50261 flags & VM_EXEC ? 'x' : '-',
50262 flags & VM_MAYSHARE ? 's' : 'p',
50263+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
50264+ PAX_RAND_FLAGS(mm) ? 0UL : pgoff,
50265+#else
50266 pgoff,
50267+#endif
50268 MAJOR(dev), MINOR(dev), ino, &len);
50269
50270 /*
50271@@ -255,7 +283,7 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
50272 */
50273 if (file) {
50274 pad_len_spaces(m, len);
50275- seq_path(m, &file->f_path, "\n");
50276+ seq_path(m, &file->f_path, "\n\\");
50277 goto done;
50278 }
50279
50280@@ -281,8 +309,9 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
50281 * Thread stack in /proc/PID/task/TID/maps or
50282 * the main process stack.
50283 */
50284- if (!is_pid || (vma->vm_start <= mm->start_stack &&
50285- vma->vm_end >= mm->start_stack)) {
50286+ if (!is_pid || (vma->vm_flags & (VM_GROWSDOWN | VM_GROWSUP)) ||
50287+ (vma->vm_start <= mm->start_stack &&
50288+ vma->vm_end >= mm->start_stack)) {
50289 name = "[stack]";
50290 } else {
50291 /* Thread stack in /proc/PID/maps */
50292@@ -306,6 +335,13 @@ static int show_map(struct seq_file *m, void *v, int is_pid)
50293 struct proc_maps_private *priv = m->private;
50294 struct task_struct *task = priv->task;
50295
50296+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
50297+ if (current->exec_id != m->exec_id) {
50298+ gr_log_badprocpid("maps");
50299+ return 0;
50300+ }
50301+#endif
50302+
50303 show_map_vma(m, vma, is_pid);
50304
50305 if (m->count < m->size) /* vma is copied successfully */
50306@@ -492,12 +528,23 @@ static int show_smap(struct seq_file *m, void *v, int is_pid)
50307 .private = &mss,
50308 };
50309
50310+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
50311+ if (current->exec_id != m->exec_id) {
50312+ gr_log_badprocpid("smaps");
50313+ return 0;
50314+ }
50315+#endif
50316 memset(&mss, 0, sizeof mss);
50317- mss.vma = vma;
50318- /* mmap_sem is held in m_start */
50319- if (vma->vm_mm && !is_vm_hugetlb_page(vma))
50320- walk_page_range(vma->vm_start, vma->vm_end, &smaps_walk);
50321-
50322+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
50323+ if (!PAX_RAND_FLAGS(vma->vm_mm)) {
50324+#endif
50325+ mss.vma = vma;
50326+ /* mmap_sem is held in m_start */
50327+ if (vma->vm_mm && !is_vm_hugetlb_page(vma))
50328+ walk_page_range(vma->vm_start, vma->vm_end, &smaps_walk);
50329+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
50330+ }
50331+#endif
50332 show_map_vma(m, vma, is_pid);
50333
50334 seq_printf(m,
50335@@ -515,7 +562,11 @@ static int show_smap(struct seq_file *m, void *v, int is_pid)
50336 "KernelPageSize: %8lu kB\n"
50337 "MMUPageSize: %8lu kB\n"
50338 "Locked: %8lu kB\n",
50339+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
50340+ PAX_RAND_FLAGS(vma->vm_mm) ? 0UL : (vma->vm_end - vma->vm_start) >> 10,
50341+#else
50342 (vma->vm_end - vma->vm_start) >> 10,
50343+#endif
50344 mss.resident >> 10,
50345 (unsigned long)(mss.pss >> (10 + PSS_SHIFT)),
50346 mss.shared_clean >> 10,
50347@@ -1164,6 +1215,13 @@ static int show_numa_map(struct seq_file *m, void *v, int is_pid)
50348 int n;
50349 char buffer[50];
50350
50351+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
50352+ if (current->exec_id != m->exec_id) {
50353+ gr_log_badprocpid("numa_maps");
50354+ return 0;
50355+ }
50356+#endif
50357+
50358 if (!mm)
50359 return 0;
50360
50361@@ -1181,11 +1239,15 @@ static int show_numa_map(struct seq_file *m, void *v, int is_pid)
50362 mpol_to_str(buffer, sizeof(buffer), pol, 0);
50363 mpol_cond_put(pol);
50364
50365+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
50366+ seq_printf(m, "%08lx %s", PAX_RAND_FLAGS(vma->vm_mm) ? 0UL : vma->vm_start, buffer);
50367+#else
50368 seq_printf(m, "%08lx %s", vma->vm_start, buffer);
50369+#endif
50370
50371 if (file) {
50372 seq_printf(m, " file=");
50373- seq_path(m, &file->f_path, "\n\t= ");
50374+ seq_path(m, &file->f_path, "\n\t\\= ");
50375 } else if (vma->vm_start <= mm->brk && vma->vm_end >= mm->start_brk) {
50376 seq_printf(m, " heap");
50377 } else {
50378diff --git a/fs/proc/task_nommu.c b/fs/proc/task_nommu.c
50379index 1ccfa53..0848f95 100644
50380--- a/fs/proc/task_nommu.c
50381+++ b/fs/proc/task_nommu.c
50382@@ -51,7 +51,7 @@ void task_mem(struct seq_file *m, struct mm_struct *mm)
50383 else
50384 bytes += kobjsize(mm);
50385
50386- if (current->fs && current->fs->users > 1)
50387+ if (current->fs && atomic_read(&current->fs->users) > 1)
50388 sbytes += kobjsize(current->fs);
50389 else
50390 bytes += kobjsize(current->fs);
50391@@ -168,7 +168,7 @@ static int nommu_vma_show(struct seq_file *m, struct vm_area_struct *vma,
50392
50393 if (file) {
50394 pad_len_spaces(m, len);
50395- seq_path(m, &file->f_path, "");
50396+ seq_path(m, &file->f_path, "\n\\");
50397 } else if (mm) {
50398 pid_t tid = vm_is_stack(priv->task, vma, is_pid);
50399
50400diff --git a/fs/pstore/platform.c b/fs/pstore/platform.c
50401index 29996e8..2d1e0f3 100644
50402--- a/fs/pstore/platform.c
50403+++ b/fs/pstore/platform.c
50404@@ -161,12 +161,13 @@ static void pstore_console_write(struct console *con, const char *s, unsigned c)
50405
50406 while (s < e) {
50407 unsigned long flags;
50408+ u64 id;
50409
50410 if (c > psinfo->bufsize)
50411 c = psinfo->bufsize;
50412 spin_lock_irqsave(&psinfo->buf_lock, flags);
50413 memcpy(psinfo->buf, s, c);
50414- psinfo->write(PSTORE_TYPE_CONSOLE, 0, NULL, 0, c, psinfo);
50415+ psinfo->write(PSTORE_TYPE_CONSOLE, 0, &id, 0, c, psinfo);
50416 spin_unlock_irqrestore(&psinfo->buf_lock, flags);
50417 s += c;
50418 c = e - s;
50419diff --git a/fs/quota/netlink.c b/fs/quota/netlink.c
50420index d67908b..d13f6a6 100644
50421--- a/fs/quota/netlink.c
50422+++ b/fs/quota/netlink.c
50423@@ -33,7 +33,7 @@ static struct genl_family quota_genl_family = {
50424 void quota_send_warning(short type, unsigned int id, dev_t dev,
50425 const char warntype)
50426 {
50427- static atomic_t seq;
50428+ static atomic_unchecked_t seq;
50429 struct sk_buff *skb;
50430 void *msg_head;
50431 int ret;
50432@@ -49,7 +49,7 @@ void quota_send_warning(short type, unsigned int id, dev_t dev,
50433 "VFS: Not enough memory to send quota warning.\n");
50434 return;
50435 }
50436- msg_head = genlmsg_put(skb, 0, atomic_add_return(1, &seq),
50437+ msg_head = genlmsg_put(skb, 0, atomic_add_return_unchecked(1, &seq),
50438 &quota_genl_family, 0, QUOTA_NL_C_WARNING);
50439 if (!msg_head) {
50440 printk(KERN_ERR
50441diff --git a/fs/readdir.c b/fs/readdir.c
50442index 39e3370..20d446d 100644
50443--- a/fs/readdir.c
50444+++ b/fs/readdir.c
50445@@ -17,6 +17,7 @@
50446 #include <linux/security.h>
50447 #include <linux/syscalls.h>
50448 #include <linux/unistd.h>
50449+#include <linux/namei.h>
50450
50451 #include <asm/uaccess.h>
50452
50453@@ -67,6 +68,7 @@ struct old_linux_dirent {
50454
50455 struct readdir_callback {
50456 struct old_linux_dirent __user * dirent;
50457+ struct file * file;
50458 int result;
50459 };
50460
50461@@ -84,6 +86,10 @@ static int fillonedir(void * __buf, const char * name, int namlen, loff_t offset
50462 buf->result = -EOVERFLOW;
50463 return -EOVERFLOW;
50464 }
50465+
50466+ if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
50467+ return 0;
50468+
50469 buf->result++;
50470 dirent = buf->dirent;
50471 if (!access_ok(VERIFY_WRITE, dirent,
50472@@ -116,6 +122,7 @@ SYSCALL_DEFINE3(old_readdir, unsigned int, fd,
50473
50474 buf.result = 0;
50475 buf.dirent = dirent;
50476+ buf.file = file;
50477
50478 error = vfs_readdir(file, fillonedir, &buf);
50479 if (buf.result)
50480@@ -141,6 +148,7 @@ struct linux_dirent {
50481 struct getdents_callback {
50482 struct linux_dirent __user * current_dir;
50483 struct linux_dirent __user * previous;
50484+ struct file * file;
50485 int count;
50486 int error;
50487 };
50488@@ -162,6 +170,10 @@ static int filldir(void * __buf, const char * name, int namlen, loff_t offset,
50489 buf->error = -EOVERFLOW;
50490 return -EOVERFLOW;
50491 }
50492+
50493+ if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
50494+ return 0;
50495+
50496 dirent = buf->previous;
50497 if (dirent) {
50498 if (__put_user(offset, &dirent->d_off))
50499@@ -208,6 +220,7 @@ SYSCALL_DEFINE3(getdents, unsigned int, fd,
50500 buf.previous = NULL;
50501 buf.count = count;
50502 buf.error = 0;
50503+ buf.file = file;
50504
50505 error = vfs_readdir(file, filldir, &buf);
50506 if (error >= 0)
50507@@ -226,6 +239,7 @@ SYSCALL_DEFINE3(getdents, unsigned int, fd,
50508 struct getdents_callback64 {
50509 struct linux_dirent64 __user * current_dir;
50510 struct linux_dirent64 __user * previous;
50511+ struct file *file;
50512 int count;
50513 int error;
50514 };
50515@@ -241,6 +255,10 @@ static int filldir64(void * __buf, const char * name, int namlen, loff_t offset,
50516 buf->error = -EINVAL; /* only used if we fail.. */
50517 if (reclen > buf->count)
50518 return -EINVAL;
50519+
50520+ if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
50521+ return 0;
50522+
50523 dirent = buf->previous;
50524 if (dirent) {
50525 if (__put_user(offset, &dirent->d_off))
50526@@ -287,6 +305,7 @@ SYSCALL_DEFINE3(getdents64, unsigned int, fd,
50527
50528 buf.current_dir = dirent;
50529 buf.previous = NULL;
50530+ buf.file = file;
50531 buf.count = count;
50532 buf.error = 0;
50533
50534@@ -295,7 +314,7 @@ SYSCALL_DEFINE3(getdents64, unsigned int, fd,
50535 error = buf.error;
50536 lastdirent = buf.previous;
50537 if (lastdirent) {
50538- typeof(lastdirent->d_off) d_off = file->f_pos;
50539+ typeof(((struct linux_dirent64 *)0)->d_off) d_off = file->f_pos;
50540 if (__put_user(d_off, &lastdirent->d_off))
50541 error = -EFAULT;
50542 else
50543diff --git a/fs/reiserfs/do_balan.c b/fs/reiserfs/do_balan.c
50544index 2b7882b..1c5ef48 100644
50545--- a/fs/reiserfs/do_balan.c
50546+++ b/fs/reiserfs/do_balan.c
50547@@ -2051,7 +2051,7 @@ void do_balance(struct tree_balance *tb, /* tree_balance structure */
50548 return;
50549 }
50550
50551- atomic_inc(&(fs_generation(tb->tb_sb)));
50552+ atomic_inc_unchecked(&(fs_generation(tb->tb_sb)));
50553 do_balance_starts(tb);
50554
50555 /* balance leaf returns 0 except if combining L R and S into
50556diff --git a/fs/reiserfs/procfs.c b/fs/reiserfs/procfs.c
50557index e60e870..f40ac16 100644
50558--- a/fs/reiserfs/procfs.c
50559+++ b/fs/reiserfs/procfs.c
50560@@ -112,7 +112,7 @@ static int show_super(struct seq_file *m, struct super_block *sb)
50561 "SMALL_TAILS " : "NO_TAILS ",
50562 replay_only(sb) ? "REPLAY_ONLY " : "",
50563 convert_reiserfs(sb) ? "CONV " : "",
50564- atomic_read(&r->s_generation_counter),
50565+ atomic_read_unchecked(&r->s_generation_counter),
50566 SF(s_disk_reads), SF(s_disk_writes), SF(s_fix_nodes),
50567 SF(s_do_balance), SF(s_unneeded_left_neighbor),
50568 SF(s_good_search_by_key_reada), SF(s_bmaps),
50569diff --git a/fs/reiserfs/reiserfs.h b/fs/reiserfs/reiserfs.h
50570index 33215f5..c5d427a 100644
50571--- a/fs/reiserfs/reiserfs.h
50572+++ b/fs/reiserfs/reiserfs.h
50573@@ -453,7 +453,7 @@ struct reiserfs_sb_info {
50574 /* Comment? -Hans */
50575 wait_queue_head_t s_wait;
50576 /* To be obsoleted soon by per buffer seals.. -Hans */
50577- atomic_t s_generation_counter; // increased by one every time the
50578+ atomic_unchecked_t s_generation_counter; // increased by one every time the
50579 // tree gets re-balanced
50580 unsigned long s_properties; /* File system properties. Currently holds
50581 on-disk FS format */
50582@@ -1978,7 +1978,7 @@ static inline loff_t max_reiserfs_offset(struct inode *inode)
50583 #define REISERFS_USER_MEM 1 /* reiserfs user memory mode */
50584
50585 #define fs_generation(s) (REISERFS_SB(s)->s_generation_counter)
50586-#define get_generation(s) atomic_read (&fs_generation(s))
50587+#define get_generation(s) atomic_read_unchecked (&fs_generation(s))
50588 #define FILESYSTEM_CHANGED_TB(tb) (get_generation((tb)->tb_sb) != (tb)->fs_gen)
50589 #define __fs_changed(gen,s) (gen != get_generation (s))
50590 #define fs_changed(gen,s) \
50591diff --git a/fs/select.c b/fs/select.c
50592index db14c78..3aae1bd 100644
50593--- a/fs/select.c
50594+++ b/fs/select.c
50595@@ -20,6 +20,7 @@
50596 #include <linux/export.h>
50597 #include <linux/slab.h>
50598 #include <linux/poll.h>
50599+#include <linux/security.h>
50600 #include <linux/personality.h> /* for STICKY_TIMEOUTS */
50601 #include <linux/file.h>
50602 #include <linux/fdtable.h>
50603@@ -831,6 +832,7 @@ int do_sys_poll(struct pollfd __user *ufds, unsigned int nfds,
50604 struct poll_list *walk = head;
50605 unsigned long todo = nfds;
50606
50607+ gr_learn_resource(current, RLIMIT_NOFILE, nfds, 1);
50608 if (nfds > rlimit(RLIMIT_NOFILE))
50609 return -EINVAL;
50610
50611diff --git a/fs/seq_file.c b/fs/seq_file.c
50612index 14cf9de..adc4d5b 100644
50613--- a/fs/seq_file.c
50614+++ b/fs/seq_file.c
50615@@ -9,6 +9,7 @@
50616 #include <linux/export.h>
50617 #include <linux/seq_file.h>
50618 #include <linux/slab.h>
50619+#include <linux/sched.h>
50620
50621 #include <asm/uaccess.h>
50622 #include <asm/page.h>
50623@@ -56,6 +57,9 @@ int seq_open(struct file *file, const struct seq_operations *op)
50624 memset(p, 0, sizeof(*p));
50625 mutex_init(&p->lock);
50626 p->op = op;
50627+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
50628+ p->exec_id = current->exec_id;
50629+#endif
50630
50631 /*
50632 * Wrappers around seq_open(e.g. swaps_open) need to be
50633@@ -92,7 +96,7 @@ static int traverse(struct seq_file *m, loff_t offset)
50634 return 0;
50635 }
50636 if (!m->buf) {
50637- m->buf = kmalloc(m->size = PAGE_SIZE, GFP_KERNEL);
50638+ m->buf = kmalloc(m->size = PAGE_SIZE, GFP_KERNEL | GFP_USERCOPY);
50639 if (!m->buf)
50640 return -ENOMEM;
50641 }
50642@@ -132,7 +136,7 @@ static int traverse(struct seq_file *m, loff_t offset)
50643 Eoverflow:
50644 m->op->stop(m, p);
50645 kfree(m->buf);
50646- m->buf = kmalloc(m->size <<= 1, GFP_KERNEL);
50647+ m->buf = kmalloc(m->size <<= 1, GFP_KERNEL | GFP_USERCOPY);
50648 return !m->buf ? -ENOMEM : -EAGAIN;
50649 }
50650
50651@@ -187,7 +191,7 @@ ssize_t seq_read(struct file *file, char __user *buf, size_t size, loff_t *ppos)
50652
50653 /* grab buffer if we didn't have one */
50654 if (!m->buf) {
50655- m->buf = kmalloc(m->size = PAGE_SIZE, GFP_KERNEL);
50656+ m->buf = kmalloc(m->size = PAGE_SIZE, GFP_KERNEL | GFP_USERCOPY);
50657 if (!m->buf)
50658 goto Enomem;
50659 }
50660@@ -228,7 +232,7 @@ ssize_t seq_read(struct file *file, char __user *buf, size_t size, loff_t *ppos)
50661 goto Fill;
50662 m->op->stop(m, p);
50663 kfree(m->buf);
50664- m->buf = kmalloc(m->size <<= 1, GFP_KERNEL);
50665+ m->buf = kmalloc(m->size <<= 1, GFP_KERNEL | GFP_USERCOPY);
50666 if (!m->buf)
50667 goto Enomem;
50668 m->count = 0;
50669@@ -577,7 +581,7 @@ static void single_stop(struct seq_file *p, void *v)
50670 int single_open(struct file *file, int (*show)(struct seq_file *, void *),
50671 void *data)
50672 {
50673- struct seq_operations *op = kmalloc(sizeof(*op), GFP_KERNEL);
50674+ seq_operations_no_const *op = kmalloc(sizeof(*op), GFP_KERNEL);
50675 int res = -ENOMEM;
50676
50677 if (op) {
50678diff --git a/fs/splice.c b/fs/splice.c
50679index 41514dd..6564a93 100644
50680--- a/fs/splice.c
50681+++ b/fs/splice.c
50682@@ -194,7 +194,7 @@ ssize_t splice_to_pipe(struct pipe_inode_info *pipe,
50683 pipe_lock(pipe);
50684
50685 for (;;) {
50686- if (!pipe->readers) {
50687+ if (!atomic_read(&pipe->readers)) {
50688 send_sig(SIGPIPE, current, 0);
50689 if (!ret)
50690 ret = -EPIPE;
50691@@ -248,9 +248,9 @@ ssize_t splice_to_pipe(struct pipe_inode_info *pipe,
50692 do_wakeup = 0;
50693 }
50694
50695- pipe->waiting_writers++;
50696+ atomic_inc(&pipe->waiting_writers);
50697 pipe_wait(pipe);
50698- pipe->waiting_writers--;
50699+ atomic_dec(&pipe->waiting_writers);
50700 }
50701
50702 pipe_unlock(pipe);
50703@@ -563,7 +563,7 @@ static ssize_t kernel_readv(struct file *file, const struct iovec *vec,
50704 old_fs = get_fs();
50705 set_fs(get_ds());
50706 /* The cast to a user pointer is valid due to the set_fs() */
50707- res = vfs_readv(file, (const struct iovec __user *)vec, vlen, &pos);
50708+ res = vfs_readv(file, (const struct iovec __force_user *)vec, vlen, &pos);
50709 set_fs(old_fs);
50710
50711 return res;
50712@@ -578,7 +578,7 @@ static ssize_t kernel_write(struct file *file, const char *buf, size_t count,
50713 old_fs = get_fs();
50714 set_fs(get_ds());
50715 /* The cast to a user pointer is valid due to the set_fs() */
50716- res = vfs_write(file, (const char __user *)buf, count, &pos);
50717+ res = vfs_write(file, (const char __force_user *)buf, count, &pos);
50718 set_fs(old_fs);
50719
50720 return res;
50721@@ -630,7 +630,7 @@ ssize_t default_file_splice_read(struct file *in, loff_t *ppos,
50722 goto err;
50723
50724 this_len = min_t(size_t, len, PAGE_CACHE_SIZE - offset);
50725- vec[i].iov_base = (void __user *) page_address(page);
50726+ vec[i].iov_base = (void __force_user *) page_address(page);
50727 vec[i].iov_len = this_len;
50728 spd.pages[i] = page;
50729 spd.nr_pages++;
50730@@ -849,10 +849,10 @@ EXPORT_SYMBOL(splice_from_pipe_feed);
50731 int splice_from_pipe_next(struct pipe_inode_info *pipe, struct splice_desc *sd)
50732 {
50733 while (!pipe->nrbufs) {
50734- if (!pipe->writers)
50735+ if (!atomic_read(&pipe->writers))
50736 return 0;
50737
50738- if (!pipe->waiting_writers && sd->num_spliced)
50739+ if (!atomic_read(&pipe->waiting_writers) && sd->num_spliced)
50740 return 0;
50741
50742 if (sd->flags & SPLICE_F_NONBLOCK)
50743@@ -1190,7 +1190,7 @@ ssize_t splice_direct_to_actor(struct file *in, struct splice_desc *sd,
50744 * out of the pipe right after the splice_to_pipe(). So set
50745 * PIPE_READERS appropriately.
50746 */
50747- pipe->readers = 1;
50748+ atomic_set(&pipe->readers, 1);
50749
50750 current->splice_pipe = pipe;
50751 }
50752@@ -1743,9 +1743,9 @@ static int ipipe_prep(struct pipe_inode_info *pipe, unsigned int flags)
50753 ret = -ERESTARTSYS;
50754 break;
50755 }
50756- if (!pipe->writers)
50757+ if (!atomic_read(&pipe->writers))
50758 break;
50759- if (!pipe->waiting_writers) {
50760+ if (!atomic_read(&pipe->waiting_writers)) {
50761 if (flags & SPLICE_F_NONBLOCK) {
50762 ret = -EAGAIN;
50763 break;
50764@@ -1777,7 +1777,7 @@ static int opipe_prep(struct pipe_inode_info *pipe, unsigned int flags)
50765 pipe_lock(pipe);
50766
50767 while (pipe->nrbufs >= pipe->buffers) {
50768- if (!pipe->readers) {
50769+ if (!atomic_read(&pipe->readers)) {
50770 send_sig(SIGPIPE, current, 0);
50771 ret = -EPIPE;
50772 break;
50773@@ -1790,9 +1790,9 @@ static int opipe_prep(struct pipe_inode_info *pipe, unsigned int flags)
50774 ret = -ERESTARTSYS;
50775 break;
50776 }
50777- pipe->waiting_writers++;
50778+ atomic_inc(&pipe->waiting_writers);
50779 pipe_wait(pipe);
50780- pipe->waiting_writers--;
50781+ atomic_dec(&pipe->waiting_writers);
50782 }
50783
50784 pipe_unlock(pipe);
50785@@ -1828,14 +1828,14 @@ retry:
50786 pipe_double_lock(ipipe, opipe);
50787
50788 do {
50789- if (!opipe->readers) {
50790+ if (!atomic_read(&opipe->readers)) {
50791 send_sig(SIGPIPE, current, 0);
50792 if (!ret)
50793 ret = -EPIPE;
50794 break;
50795 }
50796
50797- if (!ipipe->nrbufs && !ipipe->writers)
50798+ if (!ipipe->nrbufs && !atomic_read(&ipipe->writers))
50799 break;
50800
50801 /*
50802@@ -1932,7 +1932,7 @@ static int link_pipe(struct pipe_inode_info *ipipe,
50803 pipe_double_lock(ipipe, opipe);
50804
50805 do {
50806- if (!opipe->readers) {
50807+ if (!atomic_read(&opipe->readers)) {
50808 send_sig(SIGPIPE, current, 0);
50809 if (!ret)
50810 ret = -EPIPE;
50811@@ -1977,7 +1977,7 @@ static int link_pipe(struct pipe_inode_info *ipipe,
50812 * return EAGAIN if we have the potential of some data in the
50813 * future, otherwise just return 0
50814 */
50815- if (!ret && ipipe->waiting_writers && (flags & SPLICE_F_NONBLOCK))
50816+ if (!ret && atomic_read(&ipipe->waiting_writers) && (flags & SPLICE_F_NONBLOCK))
50817 ret = -EAGAIN;
50818
50819 pipe_unlock(ipipe);
50820diff --git a/fs/sysfs/dir.c b/fs/sysfs/dir.c
50821index 2fbdff6..5530a61 100644
50822--- a/fs/sysfs/dir.c
50823+++ b/fs/sysfs/dir.c
50824@@ -685,6 +685,18 @@ static int create_dir(struct kobject *kobj, struct sysfs_dirent *parent_sd,
50825 struct sysfs_dirent *sd;
50826 int rc;
50827
50828+#ifdef CONFIG_GRKERNSEC_SYSFS_RESTRICT
50829+ const char *parent_name = parent_sd->s_name;
50830+
50831+ mode = S_IFDIR | S_IRWXU;
50832+
50833+ if ((!strcmp(parent_name, "") && (!strcmp(name, "devices") || !strcmp(name, "fs"))) ||
50834+ (!strcmp(parent_name, "devices") && !strcmp(name, "system")) ||
50835+ (!strcmp(parent_name, "fs") && (!strcmp(name, "selinux") || !strcmp(name, "fuse"))) ||
50836+ (!strcmp(parent_name, "system") && !strcmp(name, "cpu")))
50837+ mode = S_IFDIR | S_IRWXU | S_IRUGO | S_IXUGO;
50838+#endif
50839+
50840 /* allocate */
50841 sd = sysfs_new_dirent(name, mode, SYSFS_DIR);
50842 if (!sd)
50843diff --git a/fs/sysfs/file.c b/fs/sysfs/file.c
50844index 00012e3..8392349 100644
50845--- a/fs/sysfs/file.c
50846+++ b/fs/sysfs/file.c
50847@@ -37,7 +37,7 @@ static DEFINE_SPINLOCK(sysfs_open_dirent_lock);
50848
50849 struct sysfs_open_dirent {
50850 atomic_t refcnt;
50851- atomic_t event;
50852+ atomic_unchecked_t event;
50853 wait_queue_head_t poll;
50854 struct list_head buffers; /* goes through sysfs_buffer.list */
50855 };
50856@@ -81,7 +81,7 @@ static int fill_read_buffer(struct dentry * dentry, struct sysfs_buffer * buffer
50857 if (!sysfs_get_active(attr_sd))
50858 return -ENODEV;
50859
50860- buffer->event = atomic_read(&attr_sd->s_attr.open->event);
50861+ buffer->event = atomic_read_unchecked(&attr_sd->s_attr.open->event);
50862 count = ops->show(kobj, attr_sd->s_attr.attr, buffer->page);
50863
50864 sysfs_put_active(attr_sd);
50865@@ -287,7 +287,7 @@ static int sysfs_get_open_dirent(struct sysfs_dirent *sd,
50866 return -ENOMEM;
50867
50868 atomic_set(&new_od->refcnt, 0);
50869- atomic_set(&new_od->event, 1);
50870+ atomic_set_unchecked(&new_od->event, 1);
50871 init_waitqueue_head(&new_od->poll);
50872 INIT_LIST_HEAD(&new_od->buffers);
50873 goto retry;
50874@@ -432,7 +432,7 @@ static unsigned int sysfs_poll(struct file *filp, poll_table *wait)
50875
50876 sysfs_put_active(attr_sd);
50877
50878- if (buffer->event != atomic_read(&od->event))
50879+ if (buffer->event != atomic_read_unchecked(&od->event))
50880 goto trigger;
50881
50882 return DEFAULT_POLLMASK;
50883@@ -451,7 +451,7 @@ void sysfs_notify_dirent(struct sysfs_dirent *sd)
50884
50885 od = sd->s_attr.open;
50886 if (od) {
50887- atomic_inc(&od->event);
50888+ atomic_inc_unchecked(&od->event);
50889 wake_up_interruptible(&od->poll);
50890 }
50891
50892diff --git a/fs/sysfs/symlink.c b/fs/sysfs/symlink.c
50893index a7ac78f..02158e1 100644
50894--- a/fs/sysfs/symlink.c
50895+++ b/fs/sysfs/symlink.c
50896@@ -286,7 +286,7 @@ static void *sysfs_follow_link(struct dentry *dentry, struct nameidata *nd)
50897
50898 static void sysfs_put_link(struct dentry *dentry, struct nameidata *nd, void *cookie)
50899 {
50900- char *page = nd_get_link(nd);
50901+ const char *page = nd_get_link(nd);
50902 if (!IS_ERR(page))
50903 free_page((unsigned long)page);
50904 }
50905diff --git a/fs/udf/misc.c b/fs/udf/misc.c
50906index c175b4d..8f36a16 100644
50907--- a/fs/udf/misc.c
50908+++ b/fs/udf/misc.c
50909@@ -289,7 +289,7 @@ void udf_new_tag(char *data, uint16_t ident, uint16_t version, uint16_t snum,
50910
50911 u8 udf_tag_checksum(const struct tag *t)
50912 {
50913- u8 *data = (u8 *)t;
50914+ const u8 *data = (const u8 *)t;
50915 u8 checksum = 0;
50916 int i;
50917 for (i = 0; i < sizeof(struct tag); ++i)
50918diff --git a/fs/utimes.c b/fs/utimes.c
50919index fa4dbe4..e12d1b9 100644
50920--- a/fs/utimes.c
50921+++ b/fs/utimes.c
50922@@ -1,6 +1,7 @@
50923 #include <linux/compiler.h>
50924 #include <linux/file.h>
50925 #include <linux/fs.h>
50926+#include <linux/security.h>
50927 #include <linux/linkage.h>
50928 #include <linux/mount.h>
50929 #include <linux/namei.h>
50930@@ -101,6 +102,12 @@ static int utimes_common(struct path *path, struct timespec *times)
50931 goto mnt_drop_write_and_out;
50932 }
50933 }
50934+
50935+ if (!gr_acl_handle_utime(path->dentry, path->mnt)) {
50936+ error = -EACCES;
50937+ goto mnt_drop_write_and_out;
50938+ }
50939+
50940 mutex_lock(&inode->i_mutex);
50941 error = notify_change(path->dentry, &newattrs);
50942 mutex_unlock(&inode->i_mutex);
50943diff --git a/fs/xattr.c b/fs/xattr.c
50944index 4d45b71..2ec08e10 100644
50945--- a/fs/xattr.c
50946+++ b/fs/xattr.c
50947@@ -316,7 +316,7 @@ EXPORT_SYMBOL_GPL(vfs_removexattr);
50948 * Extended attribute SET operations
50949 */
50950 static long
50951-setxattr(struct dentry *d, const char __user *name, const void __user *value,
50952+setxattr(struct path *path, const char __user *name, const void __user *value,
50953 size_t size, int flags)
50954 {
50955 int error;
50956@@ -349,7 +349,12 @@ setxattr(struct dentry *d, const char __user *name, const void __user *value,
50957 }
50958 }
50959
50960- error = vfs_setxattr(d, kname, kvalue, size, flags);
50961+ if (!gr_acl_handle_setxattr(path->dentry, path->mnt)) {
50962+ error = -EACCES;
50963+ goto out;
50964+ }
50965+
50966+ error = vfs_setxattr(path->dentry, kname, kvalue, size, flags);
50967 out:
50968 if (vvalue)
50969 vfree(vvalue);
50970@@ -370,7 +375,7 @@ SYSCALL_DEFINE5(setxattr, const char __user *, pathname,
50971 return error;
50972 error = mnt_want_write(path.mnt);
50973 if (!error) {
50974- error = setxattr(path.dentry, name, value, size, flags);
50975+ error = setxattr(&path, name, value, size, flags);
50976 mnt_drop_write(path.mnt);
50977 }
50978 path_put(&path);
50979@@ -389,7 +394,7 @@ SYSCALL_DEFINE5(lsetxattr, const char __user *, pathname,
50980 return error;
50981 error = mnt_want_write(path.mnt);
50982 if (!error) {
50983- error = setxattr(path.dentry, name, value, size, flags);
50984+ error = setxattr(&path, name, value, size, flags);
50985 mnt_drop_write(path.mnt);
50986 }
50987 path_put(&path);
50988@@ -401,17 +406,15 @@ SYSCALL_DEFINE5(fsetxattr, int, fd, const char __user *, name,
50989 {
50990 int fput_needed;
50991 struct file *f;
50992- struct dentry *dentry;
50993 int error = -EBADF;
50994
50995 f = fget_light(fd, &fput_needed);
50996 if (!f)
50997 return error;
50998- dentry = f->f_path.dentry;
50999- audit_inode(NULL, dentry);
51000+ audit_inode(NULL, f->f_path.dentry);
51001 error = mnt_want_write_file(f);
51002 if (!error) {
51003- error = setxattr(dentry, name, value, size, flags);
51004+ error = setxattr(&f->f_path, name, value, size, flags);
51005 mnt_drop_write_file(f);
51006 }
51007 fput_light(f, fput_needed);
51008diff --git a/fs/xattr_acl.c b/fs/xattr_acl.c
51009index 69d06b0..c0996e5 100644
51010--- a/fs/xattr_acl.c
51011+++ b/fs/xattr_acl.c
51012@@ -17,8 +17,8 @@
51013 struct posix_acl *
51014 posix_acl_from_xattr(const void *value, size_t size)
51015 {
51016- posix_acl_xattr_header *header = (posix_acl_xattr_header *)value;
51017- posix_acl_xattr_entry *entry = (posix_acl_xattr_entry *)(header+1), *end;
51018+ const posix_acl_xattr_header *header = (const posix_acl_xattr_header *)value;
51019+ const posix_acl_xattr_entry *entry = (const posix_acl_xattr_entry *)(header+1), *end;
51020 int count;
51021 struct posix_acl *acl;
51022 struct posix_acl_entry *acl_e;
51023diff --git a/fs/xfs/xfs_bmap.c b/fs/xfs/xfs_bmap.c
51024index 848ffa7..1f249bf 100644
51025--- a/fs/xfs/xfs_bmap.c
51026+++ b/fs/xfs/xfs_bmap.c
51027@@ -189,7 +189,7 @@ xfs_bmap_validate_ret(
51028 int nmap,
51029 int ret_nmap);
51030 #else
51031-#define xfs_bmap_validate_ret(bno,len,flags,mval,onmap,nmap)
51032+#define xfs_bmap_validate_ret(bno,len,flags,mval,onmap,nmap) do {} while (0)
51033 #endif /* DEBUG */
51034
51035 STATIC int
51036diff --git a/fs/xfs/xfs_dir2_sf.c b/fs/xfs/xfs_dir2_sf.c
51037index 1b9fc3e..e1bdde0 100644
51038--- a/fs/xfs/xfs_dir2_sf.c
51039+++ b/fs/xfs/xfs_dir2_sf.c
51040@@ -851,7 +851,15 @@ xfs_dir2_sf_getdents(
51041 }
51042
51043 ino = xfs_dir2_sfe_get_ino(sfp, sfep);
51044- if (filldir(dirent, (char *)sfep->name, sfep->namelen,
51045+ if (dp->i_df.if_u1.if_data == dp->i_df.if_u2.if_inline_data) {
51046+ char name[sfep->namelen];
51047+ memcpy(name, sfep->name, sfep->namelen);
51048+ if (filldir(dirent, name, sfep->namelen,
51049+ off & 0x7fffffff, ino, DT_UNKNOWN)) {
51050+ *offset = off & 0x7fffffff;
51051+ return 0;
51052+ }
51053+ } else if (filldir(dirent, (char *)sfep->name, sfep->namelen,
51054 off & 0x7fffffff, ino, DT_UNKNOWN)) {
51055 *offset = off & 0x7fffffff;
51056 return 0;
51057diff --git a/fs/xfs/xfs_ioctl.c b/fs/xfs/xfs_ioctl.c
51058index 0e0232c..fa5c3fe 100644
51059--- a/fs/xfs/xfs_ioctl.c
51060+++ b/fs/xfs/xfs_ioctl.c
51061@@ -126,7 +126,7 @@ xfs_find_handle(
51062 }
51063
51064 error = -EFAULT;
51065- if (copy_to_user(hreq->ohandle, &handle, hsize) ||
51066+ if (hsize > sizeof handle || copy_to_user(hreq->ohandle, &handle, hsize) ||
51067 copy_to_user(hreq->ohandlen, &hsize, sizeof(__s32)))
51068 goto out_put;
51069
51070diff --git a/fs/xfs/xfs_iops.c b/fs/xfs/xfs_iops.c
51071index 4e00cf0..3374374 100644
51072--- a/fs/xfs/xfs_iops.c
51073+++ b/fs/xfs/xfs_iops.c
51074@@ -394,7 +394,7 @@ xfs_vn_put_link(
51075 struct nameidata *nd,
51076 void *p)
51077 {
51078- char *s = nd_get_link(nd);
51079+ const char *s = nd_get_link(nd);
51080
51081 if (!IS_ERR(s))
51082 kfree(s);
51083diff --git a/grsecurity/Kconfig b/grsecurity/Kconfig
51084new file mode 100644
51085index 0000000..10c36fb
51086--- /dev/null
51087+++ b/grsecurity/Kconfig
51088@@ -0,0 +1,964 @@
51089+#
51090+# grecurity configuration
51091+#
51092+menu "Memory Protections"
51093+depends on GRKERNSEC
51094+
51095+config GRKERNSEC_KMEM
51096+ bool "Deny reading/writing to /dev/kmem, /dev/mem, and /dev/port"
51097+ default y if GRKERNSEC_CONFIG_AUTO
51098+ select STRICT_DEVMEM if (X86 || ARM || TILE || S390)
51099+ help
51100+ If you say Y here, /dev/kmem and /dev/mem won't be allowed to
51101+ be written to or read from to modify or leak the contents of the running
51102+ kernel. /dev/port will also not be allowed to be opened. If you have module
51103+ support disabled, enabling this will close up four ways that are
51104+ currently used to insert malicious code into the running kernel.
51105+ Even with all these features enabled, we still highly recommend that
51106+ you use the RBAC system, as it is still possible for an attacker to
51107+ modify the running kernel through privileged I/O granted by ioperm/iopl.
51108+ If you are not using XFree86, you may be able to stop this additional
51109+ case by enabling the 'Disable privileged I/O' option. Though nothing
51110+ legitimately writes to /dev/kmem, XFree86 does need to write to /dev/mem,
51111+ but only to video memory, which is the only writing we allow in this
51112+ case. If /dev/kmem or /dev/mem are mmaped without PROT_WRITE, they will
51113+ not be allowed to mprotect it with PROT_WRITE later.
51114+ It is highly recommended that you say Y here if you meet all the
51115+ conditions above.
51116+
51117+config GRKERNSEC_VM86
51118+ bool "Restrict VM86 mode"
51119+ default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER)
51120+ depends on X86_32
51121+
51122+ help
51123+ If you say Y here, only processes with CAP_SYS_RAWIO will be able to
51124+ make use of a special execution mode on 32bit x86 processors called
51125+ Virtual 8086 (VM86) mode. XFree86 may need vm86 mode for certain
51126+ video cards and will still work with this option enabled. The purpose
51127+ of the option is to prevent exploitation of emulation errors in
51128+ virtualization of vm86 mode like the one discovered in VMWare in 2009.
51129+ Nearly all users should be able to enable this option.
51130+
51131+config GRKERNSEC_IO
51132+ bool "Disable privileged I/O"
51133+ default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER)
51134+ depends on X86
51135+ select RTC_CLASS
51136+ select RTC_INTF_DEV
51137+ select RTC_DRV_CMOS
51138+
51139+ help
51140+ If you say Y here, all ioperm and iopl calls will return an error.
51141+ Ioperm and iopl can be used to modify the running kernel.
51142+ Unfortunately, some programs need this access to operate properly,
51143+ the most notable of which are XFree86 and hwclock. hwclock can be
51144+ remedied by having RTC support in the kernel, so real-time
51145+ clock support is enabled if this option is enabled, to ensure
51146+ that hwclock operates correctly. XFree86 still will not
51147+ operate correctly with this option enabled, so DO NOT CHOOSE Y
51148+ IF YOU USE XFree86. If you use XFree86 and you still want to
51149+ protect your kernel against modification, use the RBAC system.
51150+
51151+config GRKERNSEC_JIT_HARDEN
51152+ bool "Harden BPF JIT against spray attacks"
51153+ default y if GRKERNSEC_CONFIG_AUTO
51154+ depends on BPF_JIT
51155+ help
51156+ If you say Y here, the native code generated by the kernel's Berkeley
51157+ Packet Filter (BPF) JIT engine will be hardened against JIT-spraying
51158+ attacks that attempt to fit attacker-beneficial instructions in
51159+ 32bit immediate fields of JIT-generated native instructions. The
51160+ attacker will generally aim to cause an unintended instruction sequence
51161+ of JIT-generated native code to execute by jumping into the middle of
51162+ a generated instruction. This feature effectively randomizes the 32bit
51163+ immediate constants present in the generated code to thwart such attacks.
51164+
51165+ If you're using KERNEXEC, it's recommended that you enable this option
51166+ to supplement the hardening of the kernel.
51167+
51168+config GRKERNSEC_PROC_MEMMAP
51169+ bool "Harden ASLR against information leaks and entropy reduction"
51170+ default y if (GRKERNSEC_CONFIG_AUTO || PAX_NOEXEC || PAX_ASLR)
51171+ depends on PAX_NOEXEC || PAX_ASLR
51172+ help
51173+ If you say Y here, the /proc/<pid>/maps and /proc/<pid>/stat files will
51174+ give no information about the addresses of its mappings if
51175+ PaX features that rely on random addresses are enabled on the task.
51176+ In addition to sanitizing this information and disabling other
51177+ dangerous sources of information, this option causes reads of sensitive
51178+ /proc/<pid> entries where the file descriptor was opened in a different
51179+ task than the one performing the read. Such attempts are logged.
51180+ This option also limits argv/env strings for suid/sgid binaries
51181+ to 512KB to prevent a complete exhaustion of the stack entropy provided
51182+ by ASLR. Finally, it places an 8MB stack resource limit on suid/sgid
51183+ binaries to prevent alternative mmap layouts from being abused.
51184+
51185+ If you use PaX it is essential that you say Y here as it closes up
51186+ several holes that make full ASLR useless locally.
51187+
51188+config GRKERNSEC_BRUTE
51189+ bool "Deter exploit bruteforcing"
51190+ default y if GRKERNSEC_CONFIG_AUTO
51191+ help
51192+ If you say Y here, attempts to bruteforce exploits against forking
51193+ daemons such as apache or sshd, as well as against suid/sgid binaries
51194+ will be deterred. When a child of a forking daemon is killed by PaX
51195+ or crashes due to an illegal instruction or other suspicious signal,
51196+ the parent process will be delayed 30 seconds upon every subsequent
51197+ fork until the administrator is able to assess the situation and
51198+ restart the daemon.
51199+ In the suid/sgid case, the attempt is logged, the user has all their
51200+ processes terminated, and they are prevented from executing any further
51201+ processes for 15 minutes.
51202+ It is recommended that you also enable signal logging in the auditing
51203+ section so that logs are generated when a process triggers a suspicious
51204+ signal.
51205+ If the sysctl option is enabled, a sysctl option with name
51206+ "deter_bruteforce" is created.
51207+
51208+
51209+config GRKERNSEC_MODHARDEN
51210+ bool "Harden module auto-loading"
51211+ default y if GRKERNSEC_CONFIG_AUTO
51212+ depends on MODULES
51213+ help
51214+ If you say Y here, module auto-loading in response to use of some
51215+ feature implemented by an unloaded module will be restricted to
51216+ root users. Enabling this option helps defend against attacks
51217+ by unprivileged users who abuse the auto-loading behavior to
51218+ cause a vulnerable module to load that is then exploited.
51219+
51220+ If this option prevents a legitimate use of auto-loading for a
51221+ non-root user, the administrator can execute modprobe manually
51222+ with the exact name of the module mentioned in the alert log.
51223+ Alternatively, the administrator can add the module to the list
51224+ of modules loaded at boot by modifying init scripts.
51225+
51226+ Modification of init scripts will most likely be needed on
51227+ Ubuntu servers with encrypted home directory support enabled,
51228+ as the first non-root user logging in will cause the ecb(aes),
51229+ ecb(aes)-all, cbc(aes), and cbc(aes)-all modules to be loaded.
51230+
51231+config GRKERNSEC_HIDESYM
51232+ bool "Hide kernel symbols"
51233+ default y if GRKERNSEC_CONFIG_AUTO
51234+ select PAX_USERCOPY_SLABS
51235+ help
51236+ If you say Y here, getting information on loaded modules, and
51237+ displaying all kernel symbols through a syscall will be restricted
51238+ to users with CAP_SYS_MODULE. For software compatibility reasons,
51239+ /proc/kallsyms will be restricted to the root user. The RBAC
51240+ system can hide that entry even from root.
51241+
51242+ This option also prevents leaking of kernel addresses through
51243+ several /proc entries.
51244+
51245+ Note that this option is only effective provided the following
51246+ conditions are met:
51247+ 1) The kernel using grsecurity is not precompiled by some distribution
51248+ 2) You have also enabled GRKERNSEC_DMESG
51249+ 3) You are using the RBAC system and hiding other files such as your
51250+ kernel image and System.map. Alternatively, enabling this option
51251+ causes the permissions on /boot, /lib/modules, and the kernel
51252+ source directory to change at compile time to prevent
51253+ reading by non-root users.
51254+ If the above conditions are met, this option will aid in providing a
51255+ useful protection against local kernel exploitation of overflows
51256+ and arbitrary read/write vulnerabilities.
51257+
51258+config GRKERNSEC_KERN_LOCKOUT
51259+ bool "Active kernel exploit response"
51260+ default y if GRKERNSEC_CONFIG_AUTO
51261+ depends on X86 || ARM || PPC || SPARC
51262+ help
51263+ If you say Y here, when a PaX alert is triggered due to suspicious
51264+ activity in the kernel (from KERNEXEC/UDEREF/USERCOPY)
51265+ or an OOPS occurs due to bad memory accesses, instead of just
51266+ terminating the offending process (and potentially allowing
51267+ a subsequent exploit from the same user), we will take one of two
51268+ actions:
51269+ If the user was root, we will panic the system
51270+ If the user was non-root, we will log the attempt, terminate
51271+ all processes owned by the user, then prevent them from creating
51272+ any new processes until the system is restarted
51273+ This deters repeated kernel exploitation/bruteforcing attempts
51274+ and is useful for later forensics.
51275+
51276+endmenu
51277+menu "Role Based Access Control Options"
51278+depends on GRKERNSEC
51279+
51280+config GRKERNSEC_RBAC_DEBUG
51281+ bool
51282+
51283+config GRKERNSEC_NO_RBAC
51284+ bool "Disable RBAC system"
51285+ help
51286+ If you say Y here, the /dev/grsec device will be removed from the kernel,
51287+ preventing the RBAC system from being enabled. You should only say Y
51288+ here if you have no intention of using the RBAC system, so as to prevent
51289+ an attacker with root access from misusing the RBAC system to hide files
51290+ and processes when loadable module support and /dev/[k]mem have been
51291+ locked down.
51292+
51293+config GRKERNSEC_ACL_HIDEKERN
51294+ bool "Hide kernel processes"
51295+ help
51296+ If you say Y here, all kernel threads will be hidden to all
51297+ processes but those whose subject has the "view hidden processes"
51298+ flag.
51299+
51300+config GRKERNSEC_ACL_MAXTRIES
51301+ int "Maximum tries before password lockout"
51302+ default 3
51303+ help
51304+ This option enforces the maximum number of times a user can attempt
51305+ to authorize themselves with the grsecurity RBAC system before being
51306+ denied the ability to attempt authorization again for a specified time.
51307+ The lower the number, the harder it will be to brute-force a password.
51308+
51309+config GRKERNSEC_ACL_TIMEOUT
51310+ int "Time to wait after max password tries, in seconds"
51311+ default 30
51312+ help
51313+ This option specifies the time the user must wait after attempting to
51314+ authorize to the RBAC system with the maximum number of invalid
51315+ passwords. The higher the number, the harder it will be to brute-force
51316+ a password.
51317+
51318+endmenu
51319+menu "Filesystem Protections"
51320+depends on GRKERNSEC
51321+
51322+config GRKERNSEC_PROC
51323+ bool "Proc restrictions"
51324+ default y if GRKERNSEC_CONFIG_AUTO
51325+ help
51326+ If you say Y here, the permissions of the /proc filesystem
51327+ will be altered to enhance system security and privacy. You MUST
51328+ choose either a user only restriction or a user and group restriction.
51329+ Depending upon the option you choose, you can either restrict users to
51330+ see only the processes they themselves run, or choose a group that can
51331+ view all processes and files normally restricted to root if you choose
51332+ the "restrict to user only" option. NOTE: If you're running identd or
51333+ ntpd as a non-root user, you will have to run it as the group you
51334+ specify here.
51335+
51336+config GRKERNSEC_PROC_USER
51337+ bool "Restrict /proc to user only"
51338+ depends on GRKERNSEC_PROC
51339+ help
51340+ If you say Y here, non-root users will only be able to view their own
51341+ processes, and restricts them from viewing network-related information,
51342+ and viewing kernel symbol and module information.
51343+
51344+config GRKERNSEC_PROC_USERGROUP
51345+ bool "Allow special group"
51346+ default y if GRKERNSEC_CONFIG_AUTO
51347+ depends on GRKERNSEC_PROC && !GRKERNSEC_PROC_USER
51348+ help
51349+ If you say Y here, you will be able to select a group that will be
51350+ able to view all processes and network-related information. If you've
51351+ enabled GRKERNSEC_HIDESYM, kernel and symbol information may still
51352+ remain hidden. This option is useful if you want to run identd as
51353+ a non-root user. The group you select may also be chosen at boot time
51354+ via "grsec_proc_gid=" on the kernel commandline.
51355+
51356+config GRKERNSEC_PROC_GID
51357+ int "GID for special group"
51358+ depends on GRKERNSEC_PROC_USERGROUP
51359+ default 1001
51360+
51361+config GRKERNSEC_PROC_ADD
51362+ bool "Additional restrictions"
51363+ default y if GRKERNSEC_CONFIG_AUTO
51364+ depends on GRKERNSEC_PROC_USER || GRKERNSEC_PROC_USERGROUP
51365+ help
51366+ If you say Y here, additional restrictions will be placed on
51367+ /proc that keep normal users from viewing device information and
51368+ slabinfo information that could be useful for exploits.
51369+
51370+config GRKERNSEC_LINK
51371+ bool "Linking restrictions"
51372+ default y if GRKERNSEC_CONFIG_AUTO
51373+ help
51374+ If you say Y here, /tmp race exploits will be prevented, since users
51375+ will no longer be able to follow symlinks owned by other users in
51376+ world-writable +t directories (e.g. /tmp), unless the owner of the
51377+ symlink is the owner of the directory. users will also not be
51378+ able to hardlink to files they do not own. If the sysctl option is
51379+ enabled, a sysctl option with name "linking_restrictions" is created.
51380+
51381+config GRKERNSEC_SYMLINKOWN
51382+ bool "Kernel-enforced SymlinksIfOwnerMatch"
51383+ default y if GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER
51384+ help
51385+ Apache's SymlinksIfOwnerMatch option has an inherent race condition
51386+ that prevents it from being used as a security feature. As Apache
51387+ verifies the symlink by performing a stat() against the target of
51388+ the symlink before it is followed, an attacker can setup a symlink
51389+ to point to a same-owned file, then replace the symlink with one
51390+ that targets another user's file just after Apache "validates" the
51391+ symlink -- a classic TOCTOU race. If you say Y here, a complete,
51392+ race-free replacement for Apache's "SymlinksIfOwnerMatch" option
51393+ will be in place for the group you specify. If the sysctl option
51394+ is enabled, a sysctl option with name "enforce_symlinksifowner" is
51395+ created.
51396+
51397+config GRKERNSEC_SYMLINKOWN_GID
51398+ int "GID for users with kernel-enforced SymlinksIfOwnerMatch"
51399+ depends on GRKERNSEC_SYMLINKOWN
51400+ default 1006
51401+ help
51402+ Setting this GID determines what group kernel-enforced
51403+ SymlinksIfOwnerMatch will be enabled for. If the sysctl option
51404+ is enabled, a sysctl option with name "symlinkown_gid" is created.
51405+
51406+config GRKERNSEC_FIFO
51407+ bool "FIFO restrictions"
51408+ default y if GRKERNSEC_CONFIG_AUTO
51409+ help
51410+ If you say Y here, users will not be able to write to FIFOs they don't
51411+ own in world-writable +t directories (e.g. /tmp), unless the owner of
51412+ the FIFO is the same owner of the directory it's held in. If the sysctl
51413+ option is enabled, a sysctl option with name "fifo_restrictions" is
51414+ created.
51415+
51416+config GRKERNSEC_SYSFS_RESTRICT
51417+ bool "Sysfs/debugfs restriction"
51418+ default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER)
51419+ depends on SYSFS
51420+ help
51421+ If you say Y here, sysfs (the pseudo-filesystem mounted at /sys) and
51422+ any filesystem normally mounted under it (e.g. debugfs) will be
51423+ mostly accessible only by root. These filesystems generally provide access
51424+ to hardware and debug information that isn't appropriate for unprivileged
51425+ users of the system. Sysfs and debugfs have also become a large source
51426+ of new vulnerabilities, ranging from infoleaks to local compromise.
51427+ There has been very little oversight with an eye toward security involved
51428+ in adding new exporters of information to these filesystems, so their
51429+ use is discouraged.
51430+ For reasons of compatibility, a few directories have been whitelisted
51431+ for access by non-root users:
51432+ /sys/fs/selinux
51433+ /sys/fs/fuse
51434+ /sys/devices/system/cpu
51435+
51436+config GRKERNSEC_ROFS
51437+ bool "Runtime read-only mount protection"
51438+ help
51439+ If you say Y here, a sysctl option with name "romount_protect" will
51440+ be created. By setting this option to 1 at runtime, filesystems
51441+ will be protected in the following ways:
51442+ * No new writable mounts will be allowed
51443+ * Existing read-only mounts won't be able to be remounted read/write
51444+ * Write operations will be denied on all block devices
51445+ This option acts independently of grsec_lock: once it is set to 1,
51446+ it cannot be turned off. Therefore, please be mindful of the resulting
51447+ behavior if this option is enabled in an init script on a read-only
51448+ filesystem. This feature is mainly intended for secure embedded systems.
51449+
51450+config GRKERNSEC_CHROOT
51451+ bool "Chroot jail restrictions"
51452+ default y if GRKERNSEC_CONFIG_AUTO
51453+ help
51454+ If you say Y here, you will be able to choose several options that will
51455+ make breaking out of a chrooted jail much more difficult. If you
51456+ encounter no software incompatibilities with the following options, it
51457+ is recommended that you enable each one.
51458+
51459+config GRKERNSEC_CHROOT_MOUNT
51460+ bool "Deny mounts"
51461+ default y if GRKERNSEC_CONFIG_AUTO
51462+ depends on GRKERNSEC_CHROOT
51463+ help
51464+ If you say Y here, processes inside a chroot will not be able to
51465+ mount or remount filesystems. If the sysctl option is enabled, a
51466+ sysctl option with name "chroot_deny_mount" is created.
51467+
51468+config GRKERNSEC_CHROOT_DOUBLE
51469+ bool "Deny double-chroots"
51470+ default y if GRKERNSEC_CONFIG_AUTO
51471+ depends on GRKERNSEC_CHROOT
51472+ help
51473+ If you say Y here, processes inside a chroot will not be able to chroot
51474+ again outside the chroot. This is a widely used method of breaking
51475+ out of a chroot jail and should not be allowed. If the sysctl
51476+ option is enabled, a sysctl option with name
51477+ "chroot_deny_chroot" is created.
51478+
51479+config GRKERNSEC_CHROOT_PIVOT
51480+ bool "Deny pivot_root in chroot"
51481+ default y if GRKERNSEC_CONFIG_AUTO
51482+ depends on GRKERNSEC_CHROOT
51483+ help
51484+ If you say Y here, processes inside a chroot will not be able to use
51485+ a function called pivot_root() that was introduced in Linux 2.3.41. It
51486+ works similar to chroot in that it changes the root filesystem. This
51487+ function could be misused in a chrooted process to attempt to break out
51488+ of the chroot, and therefore should not be allowed. If the sysctl
51489+ option is enabled, a sysctl option with name "chroot_deny_pivot" is
51490+ created.
51491+
51492+config GRKERNSEC_CHROOT_CHDIR
51493+ bool "Enforce chdir(\"/\") on all chroots"
51494+ default y if GRKERNSEC_CONFIG_AUTO
51495+ depends on GRKERNSEC_CHROOT
51496+ help
51497+ If you say Y here, the current working directory of all newly-chrooted
51498+ applications will be set to the the root directory of the chroot.
51499+ The man page on chroot(2) states:
51500+ Note that this call does not change the current working
51501+ directory, so that `.' can be outside the tree rooted at
51502+ `/'. In particular, the super-user can escape from a
51503+ `chroot jail' by doing `mkdir foo; chroot foo; cd ..'.
51504+
51505+ It is recommended that you say Y here, since it's not known to break
51506+ any software. If the sysctl option is enabled, a sysctl option with
51507+ name "chroot_enforce_chdir" is created.
51508+
51509+config GRKERNSEC_CHROOT_CHMOD
51510+ bool "Deny (f)chmod +s"
51511+ default y if GRKERNSEC_CONFIG_AUTO
51512+ depends on GRKERNSEC_CHROOT
51513+ help
51514+ If you say Y here, processes inside a chroot will not be able to chmod
51515+ or fchmod files to make them have suid or sgid bits. This protects
51516+ against another published method of breaking a chroot. If the sysctl
51517+ option is enabled, a sysctl option with name "chroot_deny_chmod" is
51518+ created.
51519+
51520+config GRKERNSEC_CHROOT_FCHDIR
51521+ bool "Deny fchdir out of chroot"
51522+ default y if GRKERNSEC_CONFIG_AUTO
51523+ depends on GRKERNSEC_CHROOT
51524+ help
51525+ If you say Y here, a well-known method of breaking chroots by fchdir'ing
51526+ to a file descriptor of the chrooting process that points to a directory
51527+ outside the filesystem will be stopped. If the sysctl option
51528+ is enabled, a sysctl option with name "chroot_deny_fchdir" is created.
51529+
51530+config GRKERNSEC_CHROOT_MKNOD
51531+ bool "Deny mknod"
51532+ default y if GRKERNSEC_CONFIG_AUTO
51533+ depends on GRKERNSEC_CHROOT
51534+ help
51535+ If you say Y here, processes inside a chroot will not be allowed to
51536+ mknod. The problem with using mknod inside a chroot is that it
51537+ would allow an attacker to create a device entry that is the same
51538+ as one on the physical root of your system, which could range from
51539+ anything from the console device to a device for your harddrive (which
51540+ they could then use to wipe the drive or steal data). It is recommended
51541+ that you say Y here, unless you run into software incompatibilities.
51542+ If the sysctl option is enabled, a sysctl option with name
51543+ "chroot_deny_mknod" is created.
51544+
51545+config GRKERNSEC_CHROOT_SHMAT
51546+ bool "Deny shmat() out of chroot"
51547+ default y if GRKERNSEC_CONFIG_AUTO
51548+ depends on GRKERNSEC_CHROOT
51549+ help
51550+ If you say Y here, processes inside a chroot will not be able to attach
51551+ to shared memory segments that were created outside of the chroot jail.
51552+ It is recommended that you say Y here. If the sysctl option is enabled,
51553+ a sysctl option with name "chroot_deny_shmat" is created.
51554+
51555+config GRKERNSEC_CHROOT_UNIX
51556+ bool "Deny access to abstract AF_UNIX sockets out of chroot"
51557+ default y if GRKERNSEC_CONFIG_AUTO
51558+ depends on GRKERNSEC_CHROOT
51559+ help
51560+ If you say Y here, processes inside a chroot will not be able to
51561+ connect to abstract (meaning not belonging to a filesystem) Unix
51562+ domain sockets that were bound outside of a chroot. It is recommended
51563+ that you say Y here. If the sysctl option is enabled, a sysctl option
51564+ with name "chroot_deny_unix" is created.
51565+
51566+config GRKERNSEC_CHROOT_FINDTASK
51567+ bool "Protect outside processes"
51568+ default y if GRKERNSEC_CONFIG_AUTO
51569+ depends on GRKERNSEC_CHROOT
51570+ help
51571+ If you say Y here, processes inside a chroot will not be able to
51572+ kill, send signals with fcntl, ptrace, capget, getpgid, setpgid,
51573+ getsid, or view any process outside of the chroot. If the sysctl
51574+ option is enabled, a sysctl option with name "chroot_findtask" is
51575+ created.
51576+
51577+config GRKERNSEC_CHROOT_NICE
51578+ bool "Restrict priority changes"
51579+ default y if GRKERNSEC_CONFIG_AUTO
51580+ depends on GRKERNSEC_CHROOT
51581+ help
51582+ If you say Y here, processes inside a chroot will not be able to raise
51583+ the priority of processes in the chroot, or alter the priority of
51584+ processes outside the chroot. This provides more security than simply
51585+ removing CAP_SYS_NICE from the process' capability set. If the
51586+ sysctl option is enabled, a sysctl option with name "chroot_restrict_nice"
51587+ is created.
51588+
51589+config GRKERNSEC_CHROOT_SYSCTL
51590+ bool "Deny sysctl writes"
51591+ default y if GRKERNSEC_CONFIG_AUTO
51592+ depends on GRKERNSEC_CHROOT
51593+ help
51594+ If you say Y here, an attacker in a chroot will not be able to
51595+ write to sysctl entries, either by sysctl(2) or through a /proc
51596+ interface. It is strongly recommended that you say Y here. If the
51597+ sysctl option is enabled, a sysctl option with name
51598+ "chroot_deny_sysctl" is created.
51599+
51600+config GRKERNSEC_CHROOT_CAPS
51601+ bool "Capability restrictions"
51602+ default y if GRKERNSEC_CONFIG_AUTO
51603+ depends on GRKERNSEC_CHROOT
51604+ help
51605+ If you say Y here, the capabilities on all processes within a
51606+ chroot jail will be lowered to stop module insertion, raw i/o,
51607+ system and net admin tasks, rebooting the system, modifying immutable
51608+ files, modifying IPC owned by another, and changing the system time.
51609+ This is left an option because it can break some apps. Disable this
51610+ if your chrooted apps are having problems performing those kinds of
51611+ tasks. If the sysctl option is enabled, a sysctl option with
51612+ name "chroot_caps" is created.
51613+
51614+endmenu
51615+menu "Kernel Auditing"
51616+depends on GRKERNSEC
51617+
51618+config GRKERNSEC_AUDIT_GROUP
51619+ bool "Single group for auditing"
51620+ help
51621+ If you say Y here, the exec, chdir, and (un)mount logging features
51622+ will only operate on a group you specify. This option is recommended
51623+ if you only want to watch certain users instead of having a large
51624+ amount of logs from the entire system. If the sysctl option is enabled,
51625+ a sysctl option with name "audit_group" is created.
51626+
51627+config GRKERNSEC_AUDIT_GID
51628+ int "GID for auditing"
51629+ depends on GRKERNSEC_AUDIT_GROUP
51630+ default 1007
51631+
51632+config GRKERNSEC_EXECLOG
51633+ bool "Exec logging"
51634+ help
51635+ If you say Y here, all execve() calls will be logged (since the
51636+ other exec*() calls are frontends to execve(), all execution
51637+ will be logged). Useful for shell-servers that like to keep track
51638+ of their users. If the sysctl option is enabled, a sysctl option with
51639+ name "exec_logging" is created.
51640+ WARNING: This option when enabled will produce a LOT of logs, especially
51641+ on an active system.
51642+
51643+config GRKERNSEC_RESLOG
51644+ bool "Resource logging"
51645+ default y if GRKERNSEC_CONFIG_AUTO
51646+ help
51647+ If you say Y here, all attempts to overstep resource limits will
51648+ be logged with the resource name, the requested size, and the current
51649+ limit. It is highly recommended that you say Y here. If the sysctl
51650+ option is enabled, a sysctl option with name "resource_logging" is
51651+ created. If the RBAC system is enabled, the sysctl value is ignored.
51652+
51653+config GRKERNSEC_CHROOT_EXECLOG
51654+ bool "Log execs within chroot"
51655+ help
51656+ If you say Y here, all executions inside a chroot jail will be logged
51657+ to syslog. This can cause a large amount of logs if certain
51658+ applications (eg. djb's daemontools) are installed on the system, and
51659+ is therefore left as an option. If the sysctl option is enabled, a
51660+ sysctl option with name "chroot_execlog" is created.
51661+
51662+config GRKERNSEC_AUDIT_PTRACE
51663+ bool "Ptrace logging"
51664+ help
51665+ If you say Y here, all attempts to attach to a process via ptrace
51666+ will be logged. If the sysctl option is enabled, a sysctl option
51667+ with name "audit_ptrace" is created.
51668+
51669+config GRKERNSEC_AUDIT_CHDIR
51670+ bool "Chdir logging"
51671+ help
51672+ If you say Y here, all chdir() calls will be logged. If the sysctl
51673+ option is enabled, a sysctl option with name "audit_chdir" is created.
51674+
51675+config GRKERNSEC_AUDIT_MOUNT
51676+ bool "(Un)Mount logging"
51677+ help
51678+ If you say Y here, all mounts and unmounts will be logged. If the
51679+ sysctl option is enabled, a sysctl option with name "audit_mount" is
51680+ created.
51681+
51682+config GRKERNSEC_SIGNAL
51683+ bool "Signal logging"
51684+ default y if GRKERNSEC_CONFIG_AUTO
51685+ help
51686+ If you say Y here, certain important signals will be logged, such as
51687+ SIGSEGV, which will as a result inform you of when a error in a program
51688+ occurred, which in some cases could mean a possible exploit attempt.
51689+ If the sysctl option is enabled, a sysctl option with name
51690+ "signal_logging" is created.
51691+
51692+config GRKERNSEC_FORKFAIL
51693+ bool "Fork failure logging"
51694+ help
51695+ If you say Y here, all failed fork() attempts will be logged.
51696+ This could suggest a fork bomb, or someone attempting to overstep
51697+ their process limit. If the sysctl option is enabled, a sysctl option
51698+ with name "forkfail_logging" is created.
51699+
51700+config GRKERNSEC_TIME
51701+ bool "Time change logging"
51702+ default y if GRKERNSEC_CONFIG_AUTO
51703+ help
51704+ If you say Y here, any changes of the system clock will be logged.
51705+ If the sysctl option is enabled, a sysctl option with name
51706+ "timechange_logging" is created.
51707+
51708+config GRKERNSEC_PROC_IPADDR
51709+ bool "/proc/<pid>/ipaddr support"
51710+ default y if GRKERNSEC_CONFIG_AUTO
51711+ help
51712+ If you say Y here, a new entry will be added to each /proc/<pid>
51713+ directory that contains the IP address of the person using the task.
51714+ The IP is carried across local TCP and AF_UNIX stream sockets.
51715+ This information can be useful for IDS/IPSes to perform remote response
51716+ to a local attack. The entry is readable by only the owner of the
51717+ process (and root if he has CAP_DAC_OVERRIDE, which can be removed via
51718+ the RBAC system), and thus does not create privacy concerns.
51719+
51720+config GRKERNSEC_RWXMAP_LOG
51721+ bool 'Denied RWX mmap/mprotect logging'
51722+ default y if GRKERNSEC_CONFIG_AUTO
51723+ depends on PAX_MPROTECT && !PAX_EMUPLT && !PAX_EMUSIGRT
51724+ help
51725+ If you say Y here, calls to mmap() and mprotect() with explicit
51726+ usage of PROT_WRITE and PROT_EXEC together will be logged when
51727+ denied by the PAX_MPROTECT feature. If the sysctl option is
51728+ enabled, a sysctl option with name "rwxmap_logging" is created.
51729+
51730+config GRKERNSEC_AUDIT_TEXTREL
51731+ bool 'ELF text relocations logging (READ HELP)'
51732+ depends on PAX_MPROTECT
51733+ help
51734+ If you say Y here, text relocations will be logged with the filename
51735+ of the offending library or binary. The purpose of the feature is
51736+ to help Linux distribution developers get rid of libraries and
51737+ binaries that need text relocations which hinder the future progress
51738+ of PaX. Only Linux distribution developers should say Y here, and
51739+ never on a production machine, as this option creates an information
51740+ leak that could aid an attacker in defeating the randomization of
51741+ a single memory region. If the sysctl option is enabled, a sysctl
51742+ option with name "audit_textrel" is created.
51743+
51744+endmenu
51745+
51746+menu "Executable Protections"
51747+depends on GRKERNSEC
51748+
51749+config GRKERNSEC_DMESG
51750+ bool "Dmesg(8) restriction"
51751+ default y if GRKERNSEC_CONFIG_AUTO
51752+ help
51753+ If you say Y here, non-root users will not be able to use dmesg(8)
51754+ to view up to the last 4kb of messages in the kernel's log buffer.
51755+ The kernel's log buffer often contains kernel addresses and other
51756+ identifying information useful to an attacker in fingerprinting a
51757+ system for a targeted exploit.
51758+ If the sysctl option is enabled, a sysctl option with name "dmesg" is
51759+ created.
51760+
51761+config GRKERNSEC_HARDEN_PTRACE
51762+ bool "Deter ptrace-based process snooping"
51763+ default y if GRKERNSEC_CONFIG_AUTO
51764+ help
51765+ If you say Y here, TTY sniffers and other malicious monitoring
51766+ programs implemented through ptrace will be defeated. If you
51767+ have been using the RBAC system, this option has already been
51768+ enabled for several years for all users, with the ability to make
51769+ fine-grained exceptions.
51770+
51771+ This option only affects the ability of non-root users to ptrace
51772+ processes that are not a descendent of the ptracing process.
51773+ This means that strace ./binary and gdb ./binary will still work,
51774+ but attaching to arbitrary processes will not. If the sysctl
51775+ option is enabled, a sysctl option with name "harden_ptrace" is
51776+ created.
51777+
51778+config GRKERNSEC_PTRACE_READEXEC
51779+ bool "Require read access to ptrace sensitive binaries"
51780+ default y if GRKERNSEC_CONFIG_AUTO
51781+ help
51782+ If you say Y here, unprivileged users will not be able to ptrace unreadable
51783+ binaries. This option is useful in environments that
51784+ remove the read bits (e.g. file mode 4711) from suid binaries to
51785+ prevent infoleaking of their contents. This option adds
51786+ consistency to the use of that file mode, as the binary could normally
51787+ be read out when run without privileges while ptracing.
51788+
51789+ If the sysctl option is enabled, a sysctl option with name "ptrace_readexec"
51790+ is created.
51791+
51792+config GRKERNSEC_SETXID
51793+ bool "Enforce consistent multithreaded privileges"
51794+ default y if GRKERNSEC_CONFIG_AUTO
51795+ depends on (X86 || SPARC64 || PPC || ARM || MIPS)
51796+ help
51797+ If you say Y here, a change from a root uid to a non-root uid
51798+ in a multithreaded application will cause the resulting uids,
51799+ gids, supplementary groups, and capabilities in that thread
51800+ to be propagated to the other threads of the process. In most
51801+ cases this is unnecessary, as glibc will emulate this behavior
51802+ on behalf of the application. Other libcs do not act in the
51803+ same way, allowing the other threads of the process to continue
51804+ running with root privileges. If the sysctl option is enabled,
51805+ a sysctl option with name "consistent_setxid" is created.
51806+
51807+config GRKERNSEC_TPE
51808+ bool "Trusted Path Execution (TPE)"
51809+ default y if GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER
51810+ help
51811+ If you say Y here, you will be able to choose a gid to add to the
51812+ supplementary groups of users you want to mark as "untrusted."
51813+ These users will not be able to execute any files that are not in
51814+ root-owned directories writable only by root. If the sysctl option
51815+ is enabled, a sysctl option with name "tpe" is created.
51816+
51817+config GRKERNSEC_TPE_ALL
51818+ bool "Partially restrict all non-root users"
51819+ depends on GRKERNSEC_TPE
51820+ help
51821+ If you say Y here, all non-root users will be covered under
51822+ a weaker TPE restriction. This is separate from, and in addition to,
51823+ the main TPE options that you have selected elsewhere. Thus, if a
51824+ "trusted" GID is chosen, this restriction applies to even that GID.
51825+ Under this restriction, all non-root users will only be allowed to
51826+ execute files in directories they own that are not group or
51827+ world-writable, or in directories owned by root and writable only by
51828+ root. If the sysctl option is enabled, a sysctl option with name
51829+ "tpe_restrict_all" is created.
51830+
51831+config GRKERNSEC_TPE_INVERT
51832+ bool "Invert GID option"
51833+ depends on GRKERNSEC_TPE
51834+ help
51835+ If you say Y here, the group you specify in the TPE configuration will
51836+ decide what group TPE restrictions will be *disabled* for. This
51837+ option is useful if you want TPE restrictions to be applied to most
51838+ users on the system. If the sysctl option is enabled, a sysctl option
51839+ with name "tpe_invert" is created. Unlike other sysctl options, this
51840+ entry will default to on for backward-compatibility.
51841+
51842+config GRKERNSEC_TPE_GID
51843+ int
51844+ default GRKERNSEC_TPE_UNTRUSTED_GID if (GRKERNSEC_TPE && !GRKERNSEC_TPE_INVERT)
51845+ default GRKERNSEC_TPE_TRUSTED_GID if (GRKERNSEC_TPE && GRKERNSEC_TPE_INVERT)
51846+
51847+config GRKERNSEC_TPE_UNTRUSTED_GID
51848+ int "GID for TPE-untrusted users"
51849+ depends on GRKERNSEC_TPE && !GRKERNSEC_TPE_INVERT
51850+ default 1005
51851+ help
51852+ Setting this GID determines what group TPE restrictions will be
51853+ *enabled* for. If the sysctl option is enabled, a sysctl option
51854+ with name "tpe_gid" is created.
51855+
51856+config GRKERNSEC_TPE_TRUSTED_GID
51857+ int "GID for TPE-trusted users"
51858+ depends on GRKERNSEC_TPE && GRKERNSEC_TPE_INVERT
51859+ default 1005
51860+ help
51861+ Setting this GID determines what group TPE restrictions will be
51862+ *disabled* for. If the sysctl option is enabled, a sysctl option
51863+ with name "tpe_gid" is created.
51864+
51865+endmenu
51866+menu "Network Protections"
51867+depends on GRKERNSEC
51868+
51869+config GRKERNSEC_RANDNET
51870+ bool "Larger entropy pools"
51871+ default y if GRKERNSEC_CONFIG_AUTO
51872+ help
51873+ If you say Y here, the entropy pools used for many features of Linux
51874+ and grsecurity will be doubled in size. Since several grsecurity
51875+ features use additional randomness, it is recommended that you say Y
51876+ here. Saying Y here has a similar effect as modifying
51877+ /proc/sys/kernel/random/poolsize.
51878+
51879+config GRKERNSEC_BLACKHOLE
51880+ bool "TCP/UDP blackhole and LAST_ACK DoS prevention"
51881+ default y if GRKERNSEC_CONFIG_AUTO
51882+ depends on NET
51883+ help
51884+ If you say Y here, neither TCP resets nor ICMP
51885+ destination-unreachable packets will be sent in response to packets
51886+ sent to ports for which no associated listening process exists.
51887+ This feature supports both IPV4 and IPV6 and exempts the
51888+ loopback interface from blackholing. Enabling this feature
51889+ makes a host more resilient to DoS attacks and reduces network
51890+ visibility against scanners.
51891+
51892+ The blackhole feature as-implemented is equivalent to the FreeBSD
51893+ blackhole feature, as it prevents RST responses to all packets, not
51894+ just SYNs. Under most application behavior this causes no
51895+ problems, but applications (like haproxy) may not close certain
51896+ connections in a way that cleanly terminates them on the remote
51897+ end, leaving the remote host in LAST_ACK state. Because of this
51898+ side-effect and to prevent intentional LAST_ACK DoSes, this
51899+ feature also adds automatic mitigation against such attacks.
51900+ The mitigation drastically reduces the amount of time a socket
51901+ can spend in LAST_ACK state. If you're using haproxy and not
51902+ all servers it connects to have this option enabled, consider
51903+ disabling this feature on the haproxy host.
51904+
51905+ If the sysctl option is enabled, two sysctl options with names
51906+ "ip_blackhole" and "lastack_retries" will be created.
51907+ While "ip_blackhole" takes the standard zero/non-zero on/off
51908+ toggle, "lastack_retries" uses the same kinds of values as
51909+ "tcp_retries1" and "tcp_retries2". The default value of 4
51910+ prevents a socket from lasting more than 45 seconds in LAST_ACK
51911+ state.
51912+
51913+config GRKERNSEC_SOCKET
51914+ bool "Socket restrictions"
51915+ depends on NET
51916+ help
51917+ If you say Y here, you will be able to choose from several options.
51918+ If you assign a GID on your system and add it to the supplementary
51919+ groups of users you want to restrict socket access to, this patch
51920+ will perform up to three things, based on the option(s) you choose.
51921+
51922+config GRKERNSEC_SOCKET_ALL
51923+ bool "Deny any sockets to group"
51924+ depends on GRKERNSEC_SOCKET
51925+ help
51926+ If you say Y here, you will be able to choose a GID of whose users will
51927+ be unable to connect to other hosts from your machine or run server
51928+ applications from your machine. If the sysctl option is enabled, a
51929+ sysctl option with name "socket_all" is created.
51930+
51931+config GRKERNSEC_SOCKET_ALL_GID
51932+ int "GID to deny all sockets for"
51933+ depends on GRKERNSEC_SOCKET_ALL
51934+ default 1004
51935+ help
51936+ Here you can choose the GID to disable socket access for. Remember to
51937+ add the users you want socket access disabled for to the GID
51938+ specified here. If the sysctl option is enabled, a sysctl option
51939+ with name "socket_all_gid" is created.
51940+
51941+config GRKERNSEC_SOCKET_CLIENT
51942+ bool "Deny client sockets to group"
51943+ depends on GRKERNSEC_SOCKET
51944+ help
51945+ If you say Y here, you will be able to choose a GID of whose users will
51946+ be unable to connect to other hosts from your machine, but will be
51947+ able to run servers. If this option is enabled, all users in the group
51948+ you specify will have to use passive mode when initiating ftp transfers
51949+ from the shell on your machine. If the sysctl option is enabled, a
51950+ sysctl option with name "socket_client" is created.
51951+
51952+config GRKERNSEC_SOCKET_CLIENT_GID
51953+ int "GID to deny client sockets for"
51954+ depends on GRKERNSEC_SOCKET_CLIENT
51955+ default 1003
51956+ help
51957+ Here you can choose the GID to disable client socket access for.
51958+ Remember to add the users you want client socket access disabled for to
51959+ the GID specified here. If the sysctl option is enabled, a sysctl
51960+ option with name "socket_client_gid" is created.
51961+
51962+config GRKERNSEC_SOCKET_SERVER
51963+ bool "Deny server sockets to group"
51964+ depends on GRKERNSEC_SOCKET
51965+ help
51966+ If you say Y here, you will be able to choose a GID of whose users will
51967+ be unable to run server applications from your machine. If the sysctl
51968+ option is enabled, a sysctl option with name "socket_server" is created.
51969+
51970+config GRKERNSEC_SOCKET_SERVER_GID
51971+ int "GID to deny server sockets for"
51972+ depends on GRKERNSEC_SOCKET_SERVER
51973+ default 1002
51974+ help
51975+ Here you can choose the GID to disable server socket access for.
51976+ Remember to add the users you want server socket access disabled for to
51977+ the GID specified here. If the sysctl option is enabled, a sysctl
51978+ option with name "socket_server_gid" is created.
51979+
51980+endmenu
51981+menu "Sysctl Support"
51982+depends on GRKERNSEC && SYSCTL
51983+
51984+config GRKERNSEC_SYSCTL
51985+ bool "Sysctl support"
51986+ default y if GRKERNSEC_CONFIG_AUTO
51987+ help
51988+ If you say Y here, you will be able to change the options that
51989+ grsecurity runs with at bootup, without having to recompile your
51990+ kernel. You can echo values to files in /proc/sys/kernel/grsecurity
51991+ to enable (1) or disable (0) various features. All the sysctl entries
51992+ are mutable until the "grsec_lock" entry is set to a non-zero value.
51993+ All features enabled in the kernel configuration are disabled at boot
51994+ if you do not say Y to the "Turn on features by default" option.
51995+ All options should be set at startup, and the grsec_lock entry should
51996+ be set to a non-zero value after all the options are set.
51997+ *THIS IS EXTREMELY IMPORTANT*
51998+
51999+config GRKERNSEC_SYSCTL_DISTRO
52000+ bool "Extra sysctl support for distro makers (READ HELP)"
52001+ depends on GRKERNSEC_SYSCTL && GRKERNSEC_IO
52002+ help
52003+ If you say Y here, additional sysctl options will be created
52004+ for features that affect processes running as root. Therefore,
52005+ it is critical when using this option that the grsec_lock entry be
52006+ enabled after boot. Only distros with prebuilt kernel packages
52007+ with this option enabled that can ensure grsec_lock is enabled
52008+ after boot should use this option.
52009+ *Failure to set grsec_lock after boot makes all grsec features
52010+ this option covers useless*
52011+
52012+ Currently this option creates the following sysctl entries:
52013+ "Disable Privileged I/O": "disable_priv_io"
52014+
52015+config GRKERNSEC_SYSCTL_ON
52016+ bool "Turn on features by default"
52017+ default y if GRKERNSEC_CONFIG_AUTO
52018+ depends on GRKERNSEC_SYSCTL
52019+ help
52020+ If you say Y here, instead of having all features enabled in the
52021+ kernel configuration disabled at boot time, the features will be
52022+ enabled at boot time. It is recommended you say Y here unless
52023+ there is some reason you would want all sysctl-tunable features to
52024+ be disabled by default. As mentioned elsewhere, it is important
52025+ to enable the grsec_lock entry once you have finished modifying
52026+ the sysctl entries.
52027+
52028+endmenu
52029+menu "Logging Options"
52030+depends on GRKERNSEC
52031+
52032+config GRKERNSEC_FLOODTIME
52033+ int "Seconds in between log messages (minimum)"
52034+ default 10
52035+ help
52036+ This option allows you to enforce the number of seconds between
52037+ grsecurity log messages. The default should be suitable for most
52038+ people, however, if you choose to change it, choose a value small enough
52039+ to allow informative logs to be produced, but large enough to
52040+ prevent flooding.
52041+
52042+config GRKERNSEC_FLOODBURST
52043+ int "Number of messages in a burst (maximum)"
52044+ default 6
52045+ help
52046+ This option allows you to choose the maximum number of messages allowed
52047+ within the flood time interval you chose in a separate option. The
52048+ default should be suitable for most people, however if you find that
52049+ many of your logs are being interpreted as flooding, you may want to
52050+ raise this value.
52051+
52052+endmenu
52053diff --git a/grsecurity/Makefile b/grsecurity/Makefile
52054new file mode 100644
52055index 0000000..1b9afa9
52056--- /dev/null
52057+++ b/grsecurity/Makefile
52058@@ -0,0 +1,38 @@
52059+# grsecurity's ACL system was originally written in 2001 by Michael Dalton
52060+# during 2001-2009 it has been completely redesigned by Brad Spengler
52061+# into an RBAC system
52062+#
52063+# All code in this directory and various hooks inserted throughout the kernel
52064+# are copyright Brad Spengler - Open Source Security, Inc., and released
52065+# under the GPL v2 or higher
52066+
52067+KBUILD_CFLAGS += -Werror
52068+
52069+obj-y = grsec_chdir.o grsec_chroot.o grsec_exec.o grsec_fifo.o grsec_fork.o \
52070+ grsec_mount.o grsec_sig.o grsec_sysctl.o \
52071+ grsec_time.o grsec_tpe.o grsec_link.o grsec_pax.o grsec_ptrace.o
52072+
52073+obj-$(CONFIG_GRKERNSEC) += grsec_init.o grsum.o gracl.o gracl_segv.o \
52074+ gracl_cap.o gracl_alloc.o gracl_shm.o grsec_mem.o gracl_fs.o \
52075+ gracl_learn.o grsec_log.o
52076+obj-$(CONFIG_GRKERNSEC_RESLOG) += gracl_res.o
52077+
52078+ifdef CONFIG_NET
52079+obj-y += grsec_sock.o
52080+obj-$(CONFIG_GRKERNSEC) += gracl_ip.o
52081+endif
52082+
52083+ifndef CONFIG_GRKERNSEC
52084+obj-y += grsec_disabled.o
52085+endif
52086+
52087+ifdef CONFIG_GRKERNSEC_HIDESYM
52088+extra-y := grsec_hidesym.o
52089+$(obj)/grsec_hidesym.o:
52090+ @-chmod -f 500 /boot
52091+ @-chmod -f 500 /lib/modules
52092+ @-chmod -f 500 /lib64/modules
52093+ @-chmod -f 500 /lib32/modules
52094+ @-chmod -f 700 .
52095+ @echo ' grsec: protected kernel image paths'
52096+endif
52097diff --git a/grsecurity/gracl.c b/grsecurity/gracl.c
52098new file mode 100644
52099index 0000000..4428c82
52100--- /dev/null
52101+++ b/grsecurity/gracl.c
52102@@ -0,0 +1,4056 @@
52103+#include <linux/kernel.h>
52104+#include <linux/module.h>
52105+#include <linux/sched.h>
52106+#include <linux/mm.h>
52107+#include <linux/file.h>
52108+#include <linux/fs.h>
52109+#include <linux/namei.h>
52110+#include <linux/mount.h>
52111+#include <linux/tty.h>
52112+#include <linux/proc_fs.h>
52113+#include <linux/lglock.h>
52114+#include <linux/slab.h>
52115+#include <linux/vmalloc.h>
52116+#include <linux/types.h>
52117+#include <linux/sysctl.h>
52118+#include <linux/netdevice.h>
52119+#include <linux/ptrace.h>
52120+#include <linux/gracl.h>
52121+#include <linux/gralloc.h>
52122+#include <linux/security.h>
52123+#include <linux/grinternal.h>
52124+#include <linux/pid_namespace.h>
52125+#include <linux/stop_machine.h>
52126+#include <linux/fdtable.h>
52127+#include <linux/percpu.h>
52128+#include <linux/lglock.h>
52129+#include "../fs/mount.h"
52130+
52131+#include <asm/uaccess.h>
52132+#include <asm/errno.h>
52133+#include <asm/mman.h>
52134+
52135+extern struct lglock vfsmount_lock;
52136+
52137+static struct acl_role_db acl_role_set;
52138+static struct name_db name_set;
52139+static struct inodev_db inodev_set;
52140+
52141+/* for keeping track of userspace pointers used for subjects, so we
52142+ can share references in the kernel as well
52143+*/
52144+
52145+static struct path real_root;
52146+
52147+static struct acl_subj_map_db subj_map_set;
52148+
52149+static struct acl_role_label *default_role;
52150+
52151+static struct acl_role_label *role_list;
52152+
52153+static u16 acl_sp_role_value;
52154+
52155+extern char *gr_shared_page[4];
52156+static DEFINE_MUTEX(gr_dev_mutex);
52157+DEFINE_RWLOCK(gr_inode_lock);
52158+
52159+struct gr_arg *gr_usermode;
52160+
52161+static unsigned int gr_status __read_only = GR_STATUS_INIT;
52162+
52163+extern int chkpw(struct gr_arg *entry, unsigned char *salt, unsigned char *sum);
52164+extern void gr_clear_learn_entries(void);
52165+
52166+#ifdef CONFIG_GRKERNSEC_RESLOG
52167+extern void gr_log_resource(const struct task_struct *task,
52168+ const int res, const unsigned long wanted, const int gt);
52169+#endif
52170+
52171+unsigned char *gr_system_salt;
52172+unsigned char *gr_system_sum;
52173+
52174+static struct sprole_pw **acl_special_roles = NULL;
52175+static __u16 num_sprole_pws = 0;
52176+
52177+static struct acl_role_label *kernel_role = NULL;
52178+
52179+static unsigned int gr_auth_attempts = 0;
52180+static unsigned long gr_auth_expires = 0UL;
52181+
52182+#ifdef CONFIG_NET
52183+extern struct vfsmount *sock_mnt;
52184+#endif
52185+
52186+extern struct vfsmount *pipe_mnt;
52187+extern struct vfsmount *shm_mnt;
52188+#ifdef CONFIG_HUGETLBFS
52189+extern struct vfsmount *hugetlbfs_vfsmount;
52190+#endif
52191+
52192+static struct acl_object_label *fakefs_obj_rw;
52193+static struct acl_object_label *fakefs_obj_rwx;
52194+
52195+extern int gr_init_uidset(void);
52196+extern void gr_free_uidset(void);
52197+extern void gr_remove_uid(uid_t uid);
52198+extern int gr_find_uid(uid_t uid);
52199+
52200+__inline__ int
52201+gr_acl_is_enabled(void)
52202+{
52203+ return (gr_status & GR_READY);
52204+}
52205+
52206+#ifdef CONFIG_BTRFS_FS
52207+extern dev_t get_btrfs_dev_from_inode(struct inode *inode);
52208+extern int btrfs_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat);
52209+#endif
52210+
52211+static inline dev_t __get_dev(const struct dentry *dentry)
52212+{
52213+#ifdef CONFIG_BTRFS_FS
52214+ if (dentry->d_inode->i_op && dentry->d_inode->i_op->getattr == &btrfs_getattr)
52215+ return get_btrfs_dev_from_inode(dentry->d_inode);
52216+ else
52217+#endif
52218+ return dentry->d_inode->i_sb->s_dev;
52219+}
52220+
52221+dev_t gr_get_dev_from_dentry(struct dentry *dentry)
52222+{
52223+ return __get_dev(dentry);
52224+}
52225+
52226+static char gr_task_roletype_to_char(struct task_struct *task)
52227+{
52228+ switch (task->role->roletype &
52229+ (GR_ROLE_DEFAULT | GR_ROLE_USER | GR_ROLE_GROUP |
52230+ GR_ROLE_SPECIAL)) {
52231+ case GR_ROLE_DEFAULT:
52232+ return 'D';
52233+ case GR_ROLE_USER:
52234+ return 'U';
52235+ case GR_ROLE_GROUP:
52236+ return 'G';
52237+ case GR_ROLE_SPECIAL:
52238+ return 'S';
52239+ }
52240+
52241+ return 'X';
52242+}
52243+
52244+char gr_roletype_to_char(void)
52245+{
52246+ return gr_task_roletype_to_char(current);
52247+}
52248+
52249+__inline__ int
52250+gr_acl_tpe_check(void)
52251+{
52252+ if (unlikely(!(gr_status & GR_READY)))
52253+ return 0;
52254+ if (current->role->roletype & GR_ROLE_TPE)
52255+ return 1;
52256+ else
52257+ return 0;
52258+}
52259+
52260+int
52261+gr_handle_rawio(const struct inode *inode)
52262+{
52263+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
52264+ if (inode && S_ISBLK(inode->i_mode) &&
52265+ grsec_enable_chroot_caps && proc_is_chrooted(current) &&
52266+ !capable(CAP_SYS_RAWIO))
52267+ return 1;
52268+#endif
52269+ return 0;
52270+}
52271+
52272+static int
52273+gr_streq(const char *a, const char *b, const unsigned int lena, const unsigned int lenb)
52274+{
52275+ if (likely(lena != lenb))
52276+ return 0;
52277+
52278+ return !memcmp(a, b, lena);
52279+}
52280+
52281+static int prepend(char **buffer, int *buflen, const char *str, int namelen)
52282+{
52283+ *buflen -= namelen;
52284+ if (*buflen < 0)
52285+ return -ENAMETOOLONG;
52286+ *buffer -= namelen;
52287+ memcpy(*buffer, str, namelen);
52288+ return 0;
52289+}
52290+
52291+static int prepend_name(char **buffer, int *buflen, struct qstr *name)
52292+{
52293+ return prepend(buffer, buflen, name->name, name->len);
52294+}
52295+
52296+static int prepend_path(const struct path *path, struct path *root,
52297+ char **buffer, int *buflen)
52298+{
52299+ struct dentry *dentry = path->dentry;
52300+ struct vfsmount *vfsmnt = path->mnt;
52301+ struct mount *mnt = real_mount(vfsmnt);
52302+ bool slash = false;
52303+ int error = 0;
52304+
52305+ while (dentry != root->dentry || vfsmnt != root->mnt) {
52306+ struct dentry * parent;
52307+
52308+ if (dentry == vfsmnt->mnt_root || IS_ROOT(dentry)) {
52309+ /* Global root? */
52310+ if (!mnt_has_parent(mnt)) {
52311+ goto out;
52312+ }
52313+ dentry = mnt->mnt_mountpoint;
52314+ mnt = mnt->mnt_parent;
52315+ vfsmnt = &mnt->mnt;
52316+ continue;
52317+ }
52318+ parent = dentry->d_parent;
52319+ prefetch(parent);
52320+ spin_lock(&dentry->d_lock);
52321+ error = prepend_name(buffer, buflen, &dentry->d_name);
52322+ spin_unlock(&dentry->d_lock);
52323+ if (!error)
52324+ error = prepend(buffer, buflen, "/", 1);
52325+ if (error)
52326+ break;
52327+
52328+ slash = true;
52329+ dentry = parent;
52330+ }
52331+
52332+out:
52333+ if (!error && !slash)
52334+ error = prepend(buffer, buflen, "/", 1);
52335+
52336+ return error;
52337+}
52338+
52339+/* this must be called with vfsmount_lock and rename_lock held */
52340+
52341+static char *__our_d_path(const struct path *path, struct path *root,
52342+ char *buf, int buflen)
52343+{
52344+ char *res = buf + buflen;
52345+ int error;
52346+
52347+ prepend(&res, &buflen, "\0", 1);
52348+ error = prepend_path(path, root, &res, &buflen);
52349+ if (error)
52350+ return ERR_PTR(error);
52351+
52352+ return res;
52353+}
52354+
52355+static char *
52356+gen_full_path(struct path *path, struct path *root, char *buf, int buflen)
52357+{
52358+ char *retval;
52359+
52360+ retval = __our_d_path(path, root, buf, buflen);
52361+ if (unlikely(IS_ERR(retval)))
52362+ retval = strcpy(buf, "<path too long>");
52363+ else if (unlikely(retval[1] == '/' && retval[2] == '\0'))
52364+ retval[1] = '\0';
52365+
52366+ return retval;
52367+}
52368+
52369+static char *
52370+__d_real_path(const struct dentry *dentry, const struct vfsmount *vfsmnt,
52371+ char *buf, int buflen)
52372+{
52373+ struct path path;
52374+ char *res;
52375+
52376+ path.dentry = (struct dentry *)dentry;
52377+ path.mnt = (struct vfsmount *)vfsmnt;
52378+
52379+ /* we can use real_root.dentry, real_root.mnt, because this is only called
52380+ by the RBAC system */
52381+ res = gen_full_path(&path, &real_root, buf, buflen);
52382+
52383+ return res;
52384+}
52385+
52386+static char *
52387+d_real_path(const struct dentry *dentry, const struct vfsmount *vfsmnt,
52388+ char *buf, int buflen)
52389+{
52390+ char *res;
52391+ struct path path;
52392+ struct path root;
52393+ struct task_struct *reaper = init_pid_ns.child_reaper;
52394+
52395+ path.dentry = (struct dentry *)dentry;
52396+ path.mnt = (struct vfsmount *)vfsmnt;
52397+
52398+ /* we can't use real_root.dentry, real_root.mnt, because they belong only to the RBAC system */
52399+ get_fs_root(reaper->fs, &root);
52400+
52401+ write_seqlock(&rename_lock);
52402+ br_read_lock(&vfsmount_lock);
52403+ res = gen_full_path(&path, &root, buf, buflen);
52404+ br_read_unlock(&vfsmount_lock);
52405+ write_sequnlock(&rename_lock);
52406+
52407+ path_put(&root);
52408+ return res;
52409+}
52410+
52411+static char *
52412+gr_to_filename_rbac(const struct dentry *dentry, const struct vfsmount *mnt)
52413+{
52414+ char *ret;
52415+ write_seqlock(&rename_lock);
52416+ br_read_lock(&vfsmount_lock);
52417+ ret = __d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0],smp_processor_id()),
52418+ PAGE_SIZE);
52419+ br_read_unlock(&vfsmount_lock);
52420+ write_sequnlock(&rename_lock);
52421+ return ret;
52422+}
52423+
52424+static char *
52425+gr_to_proc_filename_rbac(const struct dentry *dentry, const struct vfsmount *mnt)
52426+{
52427+ char *ret;
52428+ char *buf;
52429+ int buflen;
52430+
52431+ write_seqlock(&rename_lock);
52432+ br_read_lock(&vfsmount_lock);
52433+ buf = per_cpu_ptr(gr_shared_page[0], smp_processor_id());
52434+ ret = __d_real_path(dentry, mnt, buf, PAGE_SIZE - 6);
52435+ buflen = (int)(ret - buf);
52436+ if (buflen >= 5)
52437+ prepend(&ret, &buflen, "/proc", 5);
52438+ else
52439+ ret = strcpy(buf, "<path too long>");
52440+ br_read_unlock(&vfsmount_lock);
52441+ write_sequnlock(&rename_lock);
52442+ return ret;
52443+}
52444+
52445+char *
52446+gr_to_filename_nolock(const struct dentry *dentry, const struct vfsmount *mnt)
52447+{
52448+ return __d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0],smp_processor_id()),
52449+ PAGE_SIZE);
52450+}
52451+
52452+char *
52453+gr_to_filename(const struct dentry *dentry, const struct vfsmount *mnt)
52454+{
52455+ return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0], smp_processor_id()),
52456+ PAGE_SIZE);
52457+}
52458+
52459+char *
52460+gr_to_filename1(const struct dentry *dentry, const struct vfsmount *mnt)
52461+{
52462+ return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[1], smp_processor_id()),
52463+ PAGE_SIZE);
52464+}
52465+
52466+char *
52467+gr_to_filename2(const struct dentry *dentry, const struct vfsmount *mnt)
52468+{
52469+ return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[2], smp_processor_id()),
52470+ PAGE_SIZE);
52471+}
52472+
52473+char *
52474+gr_to_filename3(const struct dentry *dentry, const struct vfsmount *mnt)
52475+{
52476+ return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[3], smp_processor_id()),
52477+ PAGE_SIZE);
52478+}
52479+
52480+__inline__ __u32
52481+to_gr_audit(const __u32 reqmode)
52482+{
52483+ /* masks off auditable permission flags, then shifts them to create
52484+ auditing flags, and adds the special case of append auditing if
52485+ we're requesting write */
52486+ return (((reqmode & ~GR_AUDITS) << 10) | ((reqmode & GR_WRITE) ? GR_AUDIT_APPEND : 0));
52487+}
52488+
52489+struct acl_subject_label *
52490+lookup_subject_map(const struct acl_subject_label *userp)
52491+{
52492+ unsigned int index = shash(userp, subj_map_set.s_size);
52493+ struct subject_map *match;
52494+
52495+ match = subj_map_set.s_hash[index];
52496+
52497+ while (match && match->user != userp)
52498+ match = match->next;
52499+
52500+ if (match != NULL)
52501+ return match->kernel;
52502+ else
52503+ return NULL;
52504+}
52505+
52506+static void
52507+insert_subj_map_entry(struct subject_map *subjmap)
52508+{
52509+ unsigned int index = shash(subjmap->user, subj_map_set.s_size);
52510+ struct subject_map **curr;
52511+
52512+ subjmap->prev = NULL;
52513+
52514+ curr = &subj_map_set.s_hash[index];
52515+ if (*curr != NULL)
52516+ (*curr)->prev = subjmap;
52517+
52518+ subjmap->next = *curr;
52519+ *curr = subjmap;
52520+
52521+ return;
52522+}
52523+
52524+static struct acl_role_label *
52525+lookup_acl_role_label(const struct task_struct *task, const uid_t uid,
52526+ const gid_t gid)
52527+{
52528+ unsigned int index = rhash(uid, GR_ROLE_USER, acl_role_set.r_size);
52529+ struct acl_role_label *match;
52530+ struct role_allowed_ip *ipp;
52531+ unsigned int x;
52532+ u32 curr_ip = task->signal->curr_ip;
52533+
52534+ task->signal->saved_ip = curr_ip;
52535+
52536+ match = acl_role_set.r_hash[index];
52537+
52538+ while (match) {
52539+ if ((match->roletype & (GR_ROLE_DOMAIN | GR_ROLE_USER)) == (GR_ROLE_DOMAIN | GR_ROLE_USER)) {
52540+ for (x = 0; x < match->domain_child_num; x++) {
52541+ if (match->domain_children[x] == uid)
52542+ goto found;
52543+ }
52544+ } else if (match->uidgid == uid && match->roletype & GR_ROLE_USER)
52545+ break;
52546+ match = match->next;
52547+ }
52548+found:
52549+ if (match == NULL) {
52550+ try_group:
52551+ index = rhash(gid, GR_ROLE_GROUP, acl_role_set.r_size);
52552+ match = acl_role_set.r_hash[index];
52553+
52554+ while (match) {
52555+ if ((match->roletype & (GR_ROLE_DOMAIN | GR_ROLE_GROUP)) == (GR_ROLE_DOMAIN | GR_ROLE_GROUP)) {
52556+ for (x = 0; x < match->domain_child_num; x++) {
52557+ if (match->domain_children[x] == gid)
52558+ goto found2;
52559+ }
52560+ } else if (match->uidgid == gid && match->roletype & GR_ROLE_GROUP)
52561+ break;
52562+ match = match->next;
52563+ }
52564+found2:
52565+ if (match == NULL)
52566+ match = default_role;
52567+ if (match->allowed_ips == NULL)
52568+ return match;
52569+ else {
52570+ for (ipp = match->allowed_ips; ipp; ipp = ipp->next) {
52571+ if (likely
52572+ ((ntohl(curr_ip) & ipp->netmask) ==
52573+ (ntohl(ipp->addr) & ipp->netmask)))
52574+ return match;
52575+ }
52576+ match = default_role;
52577+ }
52578+ } else if (match->allowed_ips == NULL) {
52579+ return match;
52580+ } else {
52581+ for (ipp = match->allowed_ips; ipp; ipp = ipp->next) {
52582+ if (likely
52583+ ((ntohl(curr_ip) & ipp->netmask) ==
52584+ (ntohl(ipp->addr) & ipp->netmask)))
52585+ return match;
52586+ }
52587+ goto try_group;
52588+ }
52589+
52590+ return match;
52591+}
52592+
52593+struct acl_subject_label *
52594+lookup_acl_subj_label(const ino_t ino, const dev_t dev,
52595+ const struct acl_role_label *role)
52596+{
52597+ unsigned int index = fhash(ino, dev, role->subj_hash_size);
52598+ struct acl_subject_label *match;
52599+
52600+ match = role->subj_hash[index];
52601+
52602+ while (match && (match->inode != ino || match->device != dev ||
52603+ (match->mode & GR_DELETED))) {
52604+ match = match->next;
52605+ }
52606+
52607+ if (match && !(match->mode & GR_DELETED))
52608+ return match;
52609+ else
52610+ return NULL;
52611+}
52612+
52613+struct acl_subject_label *
52614+lookup_acl_subj_label_deleted(const ino_t ino, const dev_t dev,
52615+ const struct acl_role_label *role)
52616+{
52617+ unsigned int index = fhash(ino, dev, role->subj_hash_size);
52618+ struct acl_subject_label *match;
52619+
52620+ match = role->subj_hash[index];
52621+
52622+ while (match && (match->inode != ino || match->device != dev ||
52623+ !(match->mode & GR_DELETED))) {
52624+ match = match->next;
52625+ }
52626+
52627+ if (match && (match->mode & GR_DELETED))
52628+ return match;
52629+ else
52630+ return NULL;
52631+}
52632+
52633+static struct acl_object_label *
52634+lookup_acl_obj_label(const ino_t ino, const dev_t dev,
52635+ const struct acl_subject_label *subj)
52636+{
52637+ unsigned int index = fhash(ino, dev, subj->obj_hash_size);
52638+ struct acl_object_label *match;
52639+
52640+ match = subj->obj_hash[index];
52641+
52642+ while (match && (match->inode != ino || match->device != dev ||
52643+ (match->mode & GR_DELETED))) {
52644+ match = match->next;
52645+ }
52646+
52647+ if (match && !(match->mode & GR_DELETED))
52648+ return match;
52649+ else
52650+ return NULL;
52651+}
52652+
52653+static struct acl_object_label *
52654+lookup_acl_obj_label_create(const ino_t ino, const dev_t dev,
52655+ const struct acl_subject_label *subj)
52656+{
52657+ unsigned int index = fhash(ino, dev, subj->obj_hash_size);
52658+ struct acl_object_label *match;
52659+
52660+ match = subj->obj_hash[index];
52661+
52662+ while (match && (match->inode != ino || match->device != dev ||
52663+ !(match->mode & GR_DELETED))) {
52664+ match = match->next;
52665+ }
52666+
52667+ if (match && (match->mode & GR_DELETED))
52668+ return match;
52669+
52670+ match = subj->obj_hash[index];
52671+
52672+ while (match && (match->inode != ino || match->device != dev ||
52673+ (match->mode & GR_DELETED))) {
52674+ match = match->next;
52675+ }
52676+
52677+ if (match && !(match->mode & GR_DELETED))
52678+ return match;
52679+ else
52680+ return NULL;
52681+}
52682+
52683+static struct name_entry *
52684+lookup_name_entry(const char *name)
52685+{
52686+ unsigned int len = strlen(name);
52687+ unsigned int key = full_name_hash(name, len);
52688+ unsigned int index = key % name_set.n_size;
52689+ struct name_entry *match;
52690+
52691+ match = name_set.n_hash[index];
52692+
52693+ while (match && (match->key != key || !gr_streq(match->name, name, match->len, len)))
52694+ match = match->next;
52695+
52696+ return match;
52697+}
52698+
52699+static struct name_entry *
52700+lookup_name_entry_create(const char *name)
52701+{
52702+ unsigned int len = strlen(name);
52703+ unsigned int key = full_name_hash(name, len);
52704+ unsigned int index = key % name_set.n_size;
52705+ struct name_entry *match;
52706+
52707+ match = name_set.n_hash[index];
52708+
52709+ while (match && (match->key != key || !gr_streq(match->name, name, match->len, len) ||
52710+ !match->deleted))
52711+ match = match->next;
52712+
52713+ if (match && match->deleted)
52714+ return match;
52715+
52716+ match = name_set.n_hash[index];
52717+
52718+ while (match && (match->key != key || !gr_streq(match->name, name, match->len, len) ||
52719+ match->deleted))
52720+ match = match->next;
52721+
52722+ if (match && !match->deleted)
52723+ return match;
52724+ else
52725+ return NULL;
52726+}
52727+
52728+static struct inodev_entry *
52729+lookup_inodev_entry(const ino_t ino, const dev_t dev)
52730+{
52731+ unsigned int index = fhash(ino, dev, inodev_set.i_size);
52732+ struct inodev_entry *match;
52733+
52734+ match = inodev_set.i_hash[index];
52735+
52736+ while (match && (match->nentry->inode != ino || match->nentry->device != dev))
52737+ match = match->next;
52738+
52739+ return match;
52740+}
52741+
52742+static void
52743+insert_inodev_entry(struct inodev_entry *entry)
52744+{
52745+ unsigned int index = fhash(entry->nentry->inode, entry->nentry->device,
52746+ inodev_set.i_size);
52747+ struct inodev_entry **curr;
52748+
52749+ entry->prev = NULL;
52750+
52751+ curr = &inodev_set.i_hash[index];
52752+ if (*curr != NULL)
52753+ (*curr)->prev = entry;
52754+
52755+ entry->next = *curr;
52756+ *curr = entry;
52757+
52758+ return;
52759+}
52760+
52761+static void
52762+__insert_acl_role_label(struct acl_role_label *role, uid_t uidgid)
52763+{
52764+ unsigned int index =
52765+ rhash(uidgid, role->roletype & (GR_ROLE_USER | GR_ROLE_GROUP), acl_role_set.r_size);
52766+ struct acl_role_label **curr;
52767+ struct acl_role_label *tmp, *tmp2;
52768+
52769+ curr = &acl_role_set.r_hash[index];
52770+
52771+ /* simple case, slot is empty, just set it to our role */
52772+ if (*curr == NULL) {
52773+ *curr = role;
52774+ } else {
52775+ /* example:
52776+ 1 -> 2 -> 3 (adding 2 -> 3 to here)
52777+ 2 -> 3
52778+ */
52779+ /* first check to see if we can already be reached via this slot */
52780+ tmp = *curr;
52781+ while (tmp && tmp != role)
52782+ tmp = tmp->next;
52783+ if (tmp == role) {
52784+ /* we don't need to add ourselves to this slot's chain */
52785+ return;
52786+ }
52787+ /* we need to add ourselves to this chain, two cases */
52788+ if (role->next == NULL) {
52789+ /* simple case, append the current chain to our role */
52790+ role->next = *curr;
52791+ *curr = role;
52792+ } else {
52793+ /* 1 -> 2 -> 3 -> 4
52794+ 2 -> 3 -> 4
52795+ 3 -> 4 (adding 1 -> 2 -> 3 -> 4 to here)
52796+ */
52797+ /* trickier case: walk our role's chain until we find
52798+ the role for the start of the current slot's chain */
52799+ tmp = role;
52800+ tmp2 = *curr;
52801+ while (tmp->next && tmp->next != tmp2)
52802+ tmp = tmp->next;
52803+ if (tmp->next == tmp2) {
52804+ /* from example above, we found 3, so just
52805+ replace this slot's chain with ours */
52806+ *curr = role;
52807+ } else {
52808+ /* we didn't find a subset of our role's chain
52809+ in the current slot's chain, so append their
52810+ chain to ours, and set us as the first role in
52811+ the slot's chain
52812+
52813+ we could fold this case with the case above,
52814+ but making it explicit for clarity
52815+ */
52816+ tmp->next = tmp2;
52817+ *curr = role;
52818+ }
52819+ }
52820+ }
52821+
52822+ return;
52823+}
52824+
52825+static void
52826+insert_acl_role_label(struct acl_role_label *role)
52827+{
52828+ int i;
52829+
52830+ if (role_list == NULL) {
52831+ role_list = role;
52832+ role->prev = NULL;
52833+ } else {
52834+ role->prev = role_list;
52835+ role_list = role;
52836+ }
52837+
52838+ /* used for hash chains */
52839+ role->next = NULL;
52840+
52841+ if (role->roletype & GR_ROLE_DOMAIN) {
52842+ for (i = 0; i < role->domain_child_num; i++)
52843+ __insert_acl_role_label(role, role->domain_children[i]);
52844+ } else
52845+ __insert_acl_role_label(role, role->uidgid);
52846+}
52847+
52848+static int
52849+insert_name_entry(char *name, const ino_t inode, const dev_t device, __u8 deleted)
52850+{
52851+ struct name_entry **curr, *nentry;
52852+ struct inodev_entry *ientry;
52853+ unsigned int len = strlen(name);
52854+ unsigned int key = full_name_hash(name, len);
52855+ unsigned int index = key % name_set.n_size;
52856+
52857+ curr = &name_set.n_hash[index];
52858+
52859+ while (*curr && ((*curr)->key != key || !gr_streq((*curr)->name, name, (*curr)->len, len)))
52860+ curr = &((*curr)->next);
52861+
52862+ if (*curr != NULL)
52863+ return 1;
52864+
52865+ nentry = acl_alloc(sizeof (struct name_entry));
52866+ if (nentry == NULL)
52867+ return 0;
52868+ ientry = acl_alloc(sizeof (struct inodev_entry));
52869+ if (ientry == NULL)
52870+ return 0;
52871+ ientry->nentry = nentry;
52872+
52873+ nentry->key = key;
52874+ nentry->name = name;
52875+ nentry->inode = inode;
52876+ nentry->device = device;
52877+ nentry->len = len;
52878+ nentry->deleted = deleted;
52879+
52880+ nentry->prev = NULL;
52881+ curr = &name_set.n_hash[index];
52882+ if (*curr != NULL)
52883+ (*curr)->prev = nentry;
52884+ nentry->next = *curr;
52885+ *curr = nentry;
52886+
52887+ /* insert us into the table searchable by inode/dev */
52888+ insert_inodev_entry(ientry);
52889+
52890+ return 1;
52891+}
52892+
52893+static void
52894+insert_acl_obj_label(struct acl_object_label *obj,
52895+ struct acl_subject_label *subj)
52896+{
52897+ unsigned int index =
52898+ fhash(obj->inode, obj->device, subj->obj_hash_size);
52899+ struct acl_object_label **curr;
52900+
52901+
52902+ obj->prev = NULL;
52903+
52904+ curr = &subj->obj_hash[index];
52905+ if (*curr != NULL)
52906+ (*curr)->prev = obj;
52907+
52908+ obj->next = *curr;
52909+ *curr = obj;
52910+
52911+ return;
52912+}
52913+
52914+static void
52915+insert_acl_subj_label(struct acl_subject_label *obj,
52916+ struct acl_role_label *role)
52917+{
52918+ unsigned int index = fhash(obj->inode, obj->device, role->subj_hash_size);
52919+ struct acl_subject_label **curr;
52920+
52921+ obj->prev = NULL;
52922+
52923+ curr = &role->subj_hash[index];
52924+ if (*curr != NULL)
52925+ (*curr)->prev = obj;
52926+
52927+ obj->next = *curr;
52928+ *curr = obj;
52929+
52930+ return;
52931+}
52932+
52933+/* allocating chained hash tables, so optimal size is where lambda ~ 1 */
52934+
52935+static void *
52936+create_table(__u32 * len, int elementsize)
52937+{
52938+ unsigned int table_sizes[] = {
52939+ 7, 13, 31, 61, 127, 251, 509, 1021, 2039, 4093, 8191, 16381,
52940+ 32749, 65521, 131071, 262139, 524287, 1048573, 2097143,
52941+ 4194301, 8388593, 16777213, 33554393, 67108859
52942+ };
52943+ void *newtable = NULL;
52944+ unsigned int pwr = 0;
52945+
52946+ while ((pwr < ((sizeof (table_sizes) / sizeof (table_sizes[0])) - 1)) &&
52947+ table_sizes[pwr] <= *len)
52948+ pwr++;
52949+
52950+ if (table_sizes[pwr] <= *len || (table_sizes[pwr] > ULONG_MAX / elementsize))
52951+ return newtable;
52952+
52953+ if ((table_sizes[pwr] * elementsize) <= PAGE_SIZE)
52954+ newtable =
52955+ kmalloc(table_sizes[pwr] * elementsize, GFP_KERNEL);
52956+ else
52957+ newtable = vmalloc(table_sizes[pwr] * elementsize);
52958+
52959+ *len = table_sizes[pwr];
52960+
52961+ return newtable;
52962+}
52963+
52964+static int
52965+init_variables(const struct gr_arg *arg)
52966+{
52967+ struct task_struct *reaper = init_pid_ns.child_reaper;
52968+ unsigned int stacksize;
52969+
52970+ subj_map_set.s_size = arg->role_db.num_subjects;
52971+ acl_role_set.r_size = arg->role_db.num_roles + arg->role_db.num_domain_children;
52972+ name_set.n_size = arg->role_db.num_objects;
52973+ inodev_set.i_size = arg->role_db.num_objects;
52974+
52975+ if (!subj_map_set.s_size || !acl_role_set.r_size ||
52976+ !name_set.n_size || !inodev_set.i_size)
52977+ return 1;
52978+
52979+ if (!gr_init_uidset())
52980+ return 1;
52981+
52982+ /* set up the stack that holds allocation info */
52983+
52984+ stacksize = arg->role_db.num_pointers + 5;
52985+
52986+ if (!acl_alloc_stack_init(stacksize))
52987+ return 1;
52988+
52989+ /* grab reference for the real root dentry and vfsmount */
52990+ get_fs_root(reaper->fs, &real_root);
52991+
52992+#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
52993+ printk(KERN_ALERT "Obtained real root device=%d, inode=%lu\n", __get_dev(real_root.dentry), real_root.dentry->d_inode->i_ino);
52994+#endif
52995+
52996+ fakefs_obj_rw = acl_alloc(sizeof(struct acl_object_label));
52997+ if (fakefs_obj_rw == NULL)
52998+ return 1;
52999+ fakefs_obj_rw->mode = GR_FIND | GR_READ | GR_WRITE;
53000+
53001+ fakefs_obj_rwx = acl_alloc(sizeof(struct acl_object_label));
53002+ if (fakefs_obj_rwx == NULL)
53003+ return 1;
53004+ fakefs_obj_rwx->mode = GR_FIND | GR_READ | GR_WRITE | GR_EXEC;
53005+
53006+ subj_map_set.s_hash =
53007+ (struct subject_map **) create_table(&subj_map_set.s_size, sizeof(void *));
53008+ acl_role_set.r_hash =
53009+ (struct acl_role_label **) create_table(&acl_role_set.r_size, sizeof(void *));
53010+ name_set.n_hash = (struct name_entry **) create_table(&name_set.n_size, sizeof(void *));
53011+ inodev_set.i_hash =
53012+ (struct inodev_entry **) create_table(&inodev_set.i_size, sizeof(void *));
53013+
53014+ if (!subj_map_set.s_hash || !acl_role_set.r_hash ||
53015+ !name_set.n_hash || !inodev_set.i_hash)
53016+ return 1;
53017+
53018+ memset(subj_map_set.s_hash, 0,
53019+ sizeof(struct subject_map *) * subj_map_set.s_size);
53020+ memset(acl_role_set.r_hash, 0,
53021+ sizeof (struct acl_role_label *) * acl_role_set.r_size);
53022+ memset(name_set.n_hash, 0,
53023+ sizeof (struct name_entry *) * name_set.n_size);
53024+ memset(inodev_set.i_hash, 0,
53025+ sizeof (struct inodev_entry *) * inodev_set.i_size);
53026+
53027+ return 0;
53028+}
53029+
53030+/* free information not needed after startup
53031+ currently contains user->kernel pointer mappings for subjects
53032+*/
53033+
53034+static void
53035+free_init_variables(void)
53036+{
53037+ __u32 i;
53038+
53039+ if (subj_map_set.s_hash) {
53040+ for (i = 0; i < subj_map_set.s_size; i++) {
53041+ if (subj_map_set.s_hash[i]) {
53042+ kfree(subj_map_set.s_hash[i]);
53043+ subj_map_set.s_hash[i] = NULL;
53044+ }
53045+ }
53046+
53047+ if ((subj_map_set.s_size * sizeof (struct subject_map *)) <=
53048+ PAGE_SIZE)
53049+ kfree(subj_map_set.s_hash);
53050+ else
53051+ vfree(subj_map_set.s_hash);
53052+ }
53053+
53054+ return;
53055+}
53056+
53057+static void
53058+free_variables(void)
53059+{
53060+ struct acl_subject_label *s;
53061+ struct acl_role_label *r;
53062+ struct task_struct *task, *task2;
53063+ unsigned int x;
53064+
53065+ gr_clear_learn_entries();
53066+
53067+ read_lock(&tasklist_lock);
53068+ do_each_thread(task2, task) {
53069+ task->acl_sp_role = 0;
53070+ task->acl_role_id = 0;
53071+ task->acl = NULL;
53072+ task->role = NULL;
53073+ } while_each_thread(task2, task);
53074+ read_unlock(&tasklist_lock);
53075+
53076+ /* release the reference to the real root dentry and vfsmount */
53077+ path_put(&real_root);
53078+ memset(&real_root, 0, sizeof(real_root));
53079+
53080+ /* free all object hash tables */
53081+
53082+ FOR_EACH_ROLE_START(r)
53083+ if (r->subj_hash == NULL)
53084+ goto next_role;
53085+ FOR_EACH_SUBJECT_START(r, s, x)
53086+ if (s->obj_hash == NULL)
53087+ break;
53088+ if ((s->obj_hash_size * sizeof (struct acl_object_label *)) <= PAGE_SIZE)
53089+ kfree(s->obj_hash);
53090+ else
53091+ vfree(s->obj_hash);
53092+ FOR_EACH_SUBJECT_END(s, x)
53093+ FOR_EACH_NESTED_SUBJECT_START(r, s)
53094+ if (s->obj_hash == NULL)
53095+ break;
53096+ if ((s->obj_hash_size * sizeof (struct acl_object_label *)) <= PAGE_SIZE)
53097+ kfree(s->obj_hash);
53098+ else
53099+ vfree(s->obj_hash);
53100+ FOR_EACH_NESTED_SUBJECT_END(s)
53101+ if ((r->subj_hash_size * sizeof (struct acl_subject_label *)) <= PAGE_SIZE)
53102+ kfree(r->subj_hash);
53103+ else
53104+ vfree(r->subj_hash);
53105+ r->subj_hash = NULL;
53106+next_role:
53107+ FOR_EACH_ROLE_END(r)
53108+
53109+ acl_free_all();
53110+
53111+ if (acl_role_set.r_hash) {
53112+ if ((acl_role_set.r_size * sizeof (struct acl_role_label *)) <=
53113+ PAGE_SIZE)
53114+ kfree(acl_role_set.r_hash);
53115+ else
53116+ vfree(acl_role_set.r_hash);
53117+ }
53118+ if (name_set.n_hash) {
53119+ if ((name_set.n_size * sizeof (struct name_entry *)) <=
53120+ PAGE_SIZE)
53121+ kfree(name_set.n_hash);
53122+ else
53123+ vfree(name_set.n_hash);
53124+ }
53125+
53126+ if (inodev_set.i_hash) {
53127+ if ((inodev_set.i_size * sizeof (struct inodev_entry *)) <=
53128+ PAGE_SIZE)
53129+ kfree(inodev_set.i_hash);
53130+ else
53131+ vfree(inodev_set.i_hash);
53132+ }
53133+
53134+ gr_free_uidset();
53135+
53136+ memset(&name_set, 0, sizeof (struct name_db));
53137+ memset(&inodev_set, 0, sizeof (struct inodev_db));
53138+ memset(&acl_role_set, 0, sizeof (struct acl_role_db));
53139+ memset(&subj_map_set, 0, sizeof (struct acl_subj_map_db));
53140+
53141+ default_role = NULL;
53142+ kernel_role = NULL;
53143+ role_list = NULL;
53144+
53145+ return;
53146+}
53147+
53148+static __u32
53149+count_user_objs(struct acl_object_label *userp)
53150+{
53151+ struct acl_object_label o_tmp;
53152+ __u32 num = 0;
53153+
53154+ while (userp) {
53155+ if (copy_from_user(&o_tmp, userp,
53156+ sizeof (struct acl_object_label)))
53157+ break;
53158+
53159+ userp = o_tmp.prev;
53160+ num++;
53161+ }
53162+
53163+ return num;
53164+}
53165+
53166+static struct acl_subject_label *
53167+do_copy_user_subj(struct acl_subject_label *userp, struct acl_role_label *role, int *already_copied);
53168+
53169+static int
53170+copy_user_glob(struct acl_object_label *obj)
53171+{
53172+ struct acl_object_label *g_tmp, **guser;
53173+ unsigned int len;
53174+ char *tmp;
53175+
53176+ if (obj->globbed == NULL)
53177+ return 0;
53178+
53179+ guser = &obj->globbed;
53180+ while (*guser) {
53181+ g_tmp = (struct acl_object_label *)
53182+ acl_alloc(sizeof (struct acl_object_label));
53183+ if (g_tmp == NULL)
53184+ return -ENOMEM;
53185+
53186+ if (copy_from_user(g_tmp, *guser,
53187+ sizeof (struct acl_object_label)))
53188+ return -EFAULT;
53189+
53190+ len = strnlen_user(g_tmp->filename, PATH_MAX);
53191+
53192+ if (!len || len >= PATH_MAX)
53193+ return -EINVAL;
53194+
53195+ if ((tmp = (char *) acl_alloc(len)) == NULL)
53196+ return -ENOMEM;
53197+
53198+ if (copy_from_user(tmp, g_tmp->filename, len))
53199+ return -EFAULT;
53200+ tmp[len-1] = '\0';
53201+ g_tmp->filename = tmp;
53202+
53203+ *guser = g_tmp;
53204+ guser = &(g_tmp->next);
53205+ }
53206+
53207+ return 0;
53208+}
53209+
53210+static int
53211+copy_user_objs(struct acl_object_label *userp, struct acl_subject_label *subj,
53212+ struct acl_role_label *role)
53213+{
53214+ struct acl_object_label *o_tmp;
53215+ unsigned int len;
53216+ int ret;
53217+ char *tmp;
53218+
53219+ while (userp) {
53220+ if ((o_tmp = (struct acl_object_label *)
53221+ acl_alloc(sizeof (struct acl_object_label))) == NULL)
53222+ return -ENOMEM;
53223+
53224+ if (copy_from_user(o_tmp, userp,
53225+ sizeof (struct acl_object_label)))
53226+ return -EFAULT;
53227+
53228+ userp = o_tmp->prev;
53229+
53230+ len = strnlen_user(o_tmp->filename, PATH_MAX);
53231+
53232+ if (!len || len >= PATH_MAX)
53233+ return -EINVAL;
53234+
53235+ if ((tmp = (char *) acl_alloc(len)) == NULL)
53236+ return -ENOMEM;
53237+
53238+ if (copy_from_user(tmp, o_tmp->filename, len))
53239+ return -EFAULT;
53240+ tmp[len-1] = '\0';
53241+ o_tmp->filename = tmp;
53242+
53243+ insert_acl_obj_label(o_tmp, subj);
53244+ if (!insert_name_entry(o_tmp->filename, o_tmp->inode,
53245+ o_tmp->device, (o_tmp->mode & GR_DELETED) ? 1 : 0))
53246+ return -ENOMEM;
53247+
53248+ ret = copy_user_glob(o_tmp);
53249+ if (ret)
53250+ return ret;
53251+
53252+ if (o_tmp->nested) {
53253+ int already_copied;
53254+
53255+ o_tmp->nested = do_copy_user_subj(o_tmp->nested, role, &already_copied);
53256+ if (IS_ERR(o_tmp->nested))
53257+ return PTR_ERR(o_tmp->nested);
53258+
53259+ /* insert into nested subject list if we haven't copied this one yet
53260+ to prevent duplicate entries */
53261+ if (!already_copied) {
53262+ o_tmp->nested->next = role->hash->first;
53263+ role->hash->first = o_tmp->nested;
53264+ }
53265+ }
53266+ }
53267+
53268+ return 0;
53269+}
53270+
53271+static __u32
53272+count_user_subjs(struct acl_subject_label *userp)
53273+{
53274+ struct acl_subject_label s_tmp;
53275+ __u32 num = 0;
53276+
53277+ while (userp) {
53278+ if (copy_from_user(&s_tmp, userp,
53279+ sizeof (struct acl_subject_label)))
53280+ break;
53281+
53282+ userp = s_tmp.prev;
53283+ /* do not count nested subjects against this count, since
53284+ they are not included in the hash table, but are
53285+ attached to objects. We have already counted
53286+ the subjects in userspace for the allocation
53287+ stack
53288+ */
53289+ if (!(s_tmp.mode & GR_NESTED))
53290+ num++;
53291+ }
53292+
53293+ return num;
53294+}
53295+
53296+static int
53297+copy_user_allowedips(struct acl_role_label *rolep)
53298+{
53299+ struct role_allowed_ip *ruserip, *rtmp = NULL, *rlast;
53300+
53301+ ruserip = rolep->allowed_ips;
53302+
53303+ while (ruserip) {
53304+ rlast = rtmp;
53305+
53306+ if ((rtmp = (struct role_allowed_ip *)
53307+ acl_alloc(sizeof (struct role_allowed_ip))) == NULL)
53308+ return -ENOMEM;
53309+
53310+ if (copy_from_user(rtmp, ruserip,
53311+ sizeof (struct role_allowed_ip)))
53312+ return -EFAULT;
53313+
53314+ ruserip = rtmp->prev;
53315+
53316+ if (!rlast) {
53317+ rtmp->prev = NULL;
53318+ rolep->allowed_ips = rtmp;
53319+ } else {
53320+ rlast->next = rtmp;
53321+ rtmp->prev = rlast;
53322+ }
53323+
53324+ if (!ruserip)
53325+ rtmp->next = NULL;
53326+ }
53327+
53328+ return 0;
53329+}
53330+
53331+static int
53332+copy_user_transitions(struct acl_role_label *rolep)
53333+{
53334+ struct role_transition *rusertp, *rtmp = NULL, *rlast;
53335+
53336+ unsigned int len;
53337+ char *tmp;
53338+
53339+ rusertp = rolep->transitions;
53340+
53341+ while (rusertp) {
53342+ rlast = rtmp;
53343+
53344+ if ((rtmp = (struct role_transition *)
53345+ acl_alloc(sizeof (struct role_transition))) == NULL)
53346+ return -ENOMEM;
53347+
53348+ if (copy_from_user(rtmp, rusertp,
53349+ sizeof (struct role_transition)))
53350+ return -EFAULT;
53351+
53352+ rusertp = rtmp->prev;
53353+
53354+ len = strnlen_user(rtmp->rolename, GR_SPROLE_LEN);
53355+
53356+ if (!len || len >= GR_SPROLE_LEN)
53357+ return -EINVAL;
53358+
53359+ if ((tmp = (char *) acl_alloc(len)) == NULL)
53360+ return -ENOMEM;
53361+
53362+ if (copy_from_user(tmp, rtmp->rolename, len))
53363+ return -EFAULT;
53364+ tmp[len-1] = '\0';
53365+ rtmp->rolename = tmp;
53366+
53367+ if (!rlast) {
53368+ rtmp->prev = NULL;
53369+ rolep->transitions = rtmp;
53370+ } else {
53371+ rlast->next = rtmp;
53372+ rtmp->prev = rlast;
53373+ }
53374+
53375+ if (!rusertp)
53376+ rtmp->next = NULL;
53377+ }
53378+
53379+ return 0;
53380+}
53381+
53382+static struct acl_subject_label *
53383+do_copy_user_subj(struct acl_subject_label *userp, struct acl_role_label *role, int *already_copied)
53384+{
53385+ struct acl_subject_label *s_tmp = NULL, *s_tmp2;
53386+ unsigned int len;
53387+ char *tmp;
53388+ __u32 num_objs;
53389+ struct acl_ip_label **i_tmp, *i_utmp2;
53390+ struct gr_hash_struct ghash;
53391+ struct subject_map *subjmap;
53392+ unsigned int i_num;
53393+ int err;
53394+
53395+ if (already_copied != NULL)
53396+ *already_copied = 0;
53397+
53398+ s_tmp = lookup_subject_map(userp);
53399+
53400+ /* we've already copied this subject into the kernel, just return
53401+ the reference to it, and don't copy it over again
53402+ */
53403+ if (s_tmp) {
53404+ if (already_copied != NULL)
53405+ *already_copied = 1;
53406+ return(s_tmp);
53407+ }
53408+
53409+ if ((s_tmp = (struct acl_subject_label *)
53410+ acl_alloc(sizeof (struct acl_subject_label))) == NULL)
53411+ return ERR_PTR(-ENOMEM);
53412+
53413+ subjmap = (struct subject_map *)kmalloc(sizeof (struct subject_map), GFP_KERNEL);
53414+ if (subjmap == NULL)
53415+ return ERR_PTR(-ENOMEM);
53416+
53417+ subjmap->user = userp;
53418+ subjmap->kernel = s_tmp;
53419+ insert_subj_map_entry(subjmap);
53420+
53421+ if (copy_from_user(s_tmp, userp,
53422+ sizeof (struct acl_subject_label)))
53423+ return ERR_PTR(-EFAULT);
53424+
53425+ len = strnlen_user(s_tmp->filename, PATH_MAX);
53426+
53427+ if (!len || len >= PATH_MAX)
53428+ return ERR_PTR(-EINVAL);
53429+
53430+ if ((tmp = (char *) acl_alloc(len)) == NULL)
53431+ return ERR_PTR(-ENOMEM);
53432+
53433+ if (copy_from_user(tmp, s_tmp->filename, len))
53434+ return ERR_PTR(-EFAULT);
53435+ tmp[len-1] = '\0';
53436+ s_tmp->filename = tmp;
53437+
53438+ if (!strcmp(s_tmp->filename, "/"))
53439+ role->root_label = s_tmp;
53440+
53441+ if (copy_from_user(&ghash, s_tmp->hash, sizeof(struct gr_hash_struct)))
53442+ return ERR_PTR(-EFAULT);
53443+
53444+ /* copy user and group transition tables */
53445+
53446+ if (s_tmp->user_trans_num) {
53447+ uid_t *uidlist;
53448+
53449+ uidlist = (uid_t *)acl_alloc_num(s_tmp->user_trans_num, sizeof(uid_t));
53450+ if (uidlist == NULL)
53451+ return ERR_PTR(-ENOMEM);
53452+ if (copy_from_user(uidlist, s_tmp->user_transitions, s_tmp->user_trans_num * sizeof(uid_t)))
53453+ return ERR_PTR(-EFAULT);
53454+
53455+ s_tmp->user_transitions = uidlist;
53456+ }
53457+
53458+ if (s_tmp->group_trans_num) {
53459+ gid_t *gidlist;
53460+
53461+ gidlist = (gid_t *)acl_alloc_num(s_tmp->group_trans_num, sizeof(gid_t));
53462+ if (gidlist == NULL)
53463+ return ERR_PTR(-ENOMEM);
53464+ if (copy_from_user(gidlist, s_tmp->group_transitions, s_tmp->group_trans_num * sizeof(gid_t)))
53465+ return ERR_PTR(-EFAULT);
53466+
53467+ s_tmp->group_transitions = gidlist;
53468+ }
53469+
53470+ /* set up object hash table */
53471+ num_objs = count_user_objs(ghash.first);
53472+
53473+ s_tmp->obj_hash_size = num_objs;
53474+ s_tmp->obj_hash =
53475+ (struct acl_object_label **)
53476+ create_table(&(s_tmp->obj_hash_size), sizeof(void *));
53477+
53478+ if (!s_tmp->obj_hash)
53479+ return ERR_PTR(-ENOMEM);
53480+
53481+ memset(s_tmp->obj_hash, 0,
53482+ s_tmp->obj_hash_size *
53483+ sizeof (struct acl_object_label *));
53484+
53485+ /* add in objects */
53486+ err = copy_user_objs(ghash.first, s_tmp, role);
53487+
53488+ if (err)
53489+ return ERR_PTR(err);
53490+
53491+ /* set pointer for parent subject */
53492+ if (s_tmp->parent_subject) {
53493+ s_tmp2 = do_copy_user_subj(s_tmp->parent_subject, role, NULL);
53494+
53495+ if (IS_ERR(s_tmp2))
53496+ return s_tmp2;
53497+
53498+ s_tmp->parent_subject = s_tmp2;
53499+ }
53500+
53501+ /* add in ip acls */
53502+
53503+ if (!s_tmp->ip_num) {
53504+ s_tmp->ips = NULL;
53505+ goto insert;
53506+ }
53507+
53508+ i_tmp =
53509+ (struct acl_ip_label **) acl_alloc_num(s_tmp->ip_num,
53510+ sizeof (struct acl_ip_label *));
53511+
53512+ if (!i_tmp)
53513+ return ERR_PTR(-ENOMEM);
53514+
53515+ for (i_num = 0; i_num < s_tmp->ip_num; i_num++) {
53516+ *(i_tmp + i_num) =
53517+ (struct acl_ip_label *)
53518+ acl_alloc(sizeof (struct acl_ip_label));
53519+ if (!*(i_tmp + i_num))
53520+ return ERR_PTR(-ENOMEM);
53521+
53522+ if (copy_from_user
53523+ (&i_utmp2, s_tmp->ips + i_num,
53524+ sizeof (struct acl_ip_label *)))
53525+ return ERR_PTR(-EFAULT);
53526+
53527+ if (copy_from_user
53528+ (*(i_tmp + i_num), i_utmp2,
53529+ sizeof (struct acl_ip_label)))
53530+ return ERR_PTR(-EFAULT);
53531+
53532+ if ((*(i_tmp + i_num))->iface == NULL)
53533+ continue;
53534+
53535+ len = strnlen_user((*(i_tmp + i_num))->iface, IFNAMSIZ);
53536+ if (!len || len >= IFNAMSIZ)
53537+ return ERR_PTR(-EINVAL);
53538+ tmp = acl_alloc(len);
53539+ if (tmp == NULL)
53540+ return ERR_PTR(-ENOMEM);
53541+ if (copy_from_user(tmp, (*(i_tmp + i_num))->iface, len))
53542+ return ERR_PTR(-EFAULT);
53543+ (*(i_tmp + i_num))->iface = tmp;
53544+ }
53545+
53546+ s_tmp->ips = i_tmp;
53547+
53548+insert:
53549+ if (!insert_name_entry(s_tmp->filename, s_tmp->inode,
53550+ s_tmp->device, (s_tmp->mode & GR_DELETED) ? 1 : 0))
53551+ return ERR_PTR(-ENOMEM);
53552+
53553+ return s_tmp;
53554+}
53555+
53556+static int
53557+copy_user_subjs(struct acl_subject_label *userp, struct acl_role_label *role)
53558+{
53559+ struct acl_subject_label s_pre;
53560+ struct acl_subject_label * ret;
53561+ int err;
53562+
53563+ while (userp) {
53564+ if (copy_from_user(&s_pre, userp,
53565+ sizeof (struct acl_subject_label)))
53566+ return -EFAULT;
53567+
53568+ /* do not add nested subjects here, add
53569+ while parsing objects
53570+ */
53571+
53572+ if (s_pre.mode & GR_NESTED) {
53573+ userp = s_pre.prev;
53574+ continue;
53575+ }
53576+
53577+ ret = do_copy_user_subj(userp, role, NULL);
53578+
53579+ err = PTR_ERR(ret);
53580+ if (IS_ERR(ret))
53581+ return err;
53582+
53583+ insert_acl_subj_label(ret, role);
53584+
53585+ userp = s_pre.prev;
53586+ }
53587+
53588+ return 0;
53589+}
53590+
53591+static int
53592+copy_user_acl(struct gr_arg *arg)
53593+{
53594+ struct acl_role_label *r_tmp = NULL, **r_utmp, *r_utmp2;
53595+ struct acl_subject_label *subj_list;
53596+ struct sprole_pw *sptmp;
53597+ struct gr_hash_struct *ghash;
53598+ uid_t *domainlist;
53599+ unsigned int r_num;
53600+ unsigned int len;
53601+ char *tmp;
53602+ int err = 0;
53603+ __u16 i;
53604+ __u32 num_subjs;
53605+
53606+ /* we need a default and kernel role */
53607+ if (arg->role_db.num_roles < 2)
53608+ return -EINVAL;
53609+
53610+ /* copy special role authentication info from userspace */
53611+
53612+ num_sprole_pws = arg->num_sprole_pws;
53613+ acl_special_roles = (struct sprole_pw **) acl_alloc_num(num_sprole_pws, sizeof(struct sprole_pw *));
53614+
53615+ if (!acl_special_roles && num_sprole_pws)
53616+ return -ENOMEM;
53617+
53618+ for (i = 0; i < num_sprole_pws; i++) {
53619+ sptmp = (struct sprole_pw *) acl_alloc(sizeof(struct sprole_pw));
53620+ if (!sptmp)
53621+ return -ENOMEM;
53622+ if (copy_from_user(sptmp, arg->sprole_pws + i,
53623+ sizeof (struct sprole_pw)))
53624+ return -EFAULT;
53625+
53626+ len = strnlen_user(sptmp->rolename, GR_SPROLE_LEN);
53627+
53628+ if (!len || len >= GR_SPROLE_LEN)
53629+ return -EINVAL;
53630+
53631+ if ((tmp = (char *) acl_alloc(len)) == NULL)
53632+ return -ENOMEM;
53633+
53634+ if (copy_from_user(tmp, sptmp->rolename, len))
53635+ return -EFAULT;
53636+
53637+ tmp[len-1] = '\0';
53638+#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
53639+ printk(KERN_ALERT "Copying special role %s\n", tmp);
53640+#endif
53641+ sptmp->rolename = tmp;
53642+ acl_special_roles[i] = sptmp;
53643+ }
53644+
53645+ r_utmp = (struct acl_role_label **) arg->role_db.r_table;
53646+
53647+ for (r_num = 0; r_num < arg->role_db.num_roles; r_num++) {
53648+ r_tmp = acl_alloc(sizeof (struct acl_role_label));
53649+
53650+ if (!r_tmp)
53651+ return -ENOMEM;
53652+
53653+ if (copy_from_user(&r_utmp2, r_utmp + r_num,
53654+ sizeof (struct acl_role_label *)))
53655+ return -EFAULT;
53656+
53657+ if (copy_from_user(r_tmp, r_utmp2,
53658+ sizeof (struct acl_role_label)))
53659+ return -EFAULT;
53660+
53661+ len = strnlen_user(r_tmp->rolename, GR_SPROLE_LEN);
53662+
53663+ if (!len || len >= PATH_MAX)
53664+ return -EINVAL;
53665+
53666+ if ((tmp = (char *) acl_alloc(len)) == NULL)
53667+ return -ENOMEM;
53668+
53669+ if (copy_from_user(tmp, r_tmp->rolename, len))
53670+ return -EFAULT;
53671+
53672+ tmp[len-1] = '\0';
53673+ r_tmp->rolename = tmp;
53674+
53675+ if (!strcmp(r_tmp->rolename, "default")
53676+ && (r_tmp->roletype & GR_ROLE_DEFAULT)) {
53677+ default_role = r_tmp;
53678+ } else if (!strcmp(r_tmp->rolename, ":::kernel:::")) {
53679+ kernel_role = r_tmp;
53680+ }
53681+
53682+ if ((ghash = (struct gr_hash_struct *) acl_alloc(sizeof(struct gr_hash_struct))) == NULL)
53683+ return -ENOMEM;
53684+
53685+ if (copy_from_user(ghash, r_tmp->hash, sizeof(struct gr_hash_struct)))
53686+ return -EFAULT;
53687+
53688+ r_tmp->hash = ghash;
53689+
53690+ num_subjs = count_user_subjs(r_tmp->hash->first);
53691+
53692+ r_tmp->subj_hash_size = num_subjs;
53693+ r_tmp->subj_hash =
53694+ (struct acl_subject_label **)
53695+ create_table(&(r_tmp->subj_hash_size), sizeof(void *));
53696+
53697+ if (!r_tmp->subj_hash)
53698+ return -ENOMEM;
53699+
53700+ err = copy_user_allowedips(r_tmp);
53701+ if (err)
53702+ return err;
53703+
53704+ /* copy domain info */
53705+ if (r_tmp->domain_children != NULL) {
53706+ domainlist = acl_alloc_num(r_tmp->domain_child_num, sizeof(uid_t));
53707+ if (domainlist == NULL)
53708+ return -ENOMEM;
53709+
53710+ if (copy_from_user(domainlist, r_tmp->domain_children, r_tmp->domain_child_num * sizeof(uid_t)))
53711+ return -EFAULT;
53712+
53713+ r_tmp->domain_children = domainlist;
53714+ }
53715+
53716+ err = copy_user_transitions(r_tmp);
53717+ if (err)
53718+ return err;
53719+
53720+ memset(r_tmp->subj_hash, 0,
53721+ r_tmp->subj_hash_size *
53722+ sizeof (struct acl_subject_label *));
53723+
53724+ /* acquire the list of subjects, then NULL out
53725+ the list prior to parsing the subjects for this role,
53726+ as during this parsing the list is replaced with a list
53727+ of *nested* subjects for the role
53728+ */
53729+ subj_list = r_tmp->hash->first;
53730+
53731+ /* set nested subject list to null */
53732+ r_tmp->hash->first = NULL;
53733+
53734+ err = copy_user_subjs(subj_list, r_tmp);
53735+
53736+ if (err)
53737+ return err;
53738+
53739+ insert_acl_role_label(r_tmp);
53740+ }
53741+
53742+ if (default_role == NULL || kernel_role == NULL)
53743+ return -EINVAL;
53744+
53745+ return err;
53746+}
53747+
53748+static int
53749+gracl_init(struct gr_arg *args)
53750+{
53751+ int error = 0;
53752+
53753+ memcpy(gr_system_salt, args->salt, GR_SALT_LEN);
53754+ memcpy(gr_system_sum, args->sum, GR_SHA_LEN);
53755+
53756+ if (init_variables(args)) {
53757+ gr_log_str(GR_DONT_AUDIT_GOOD, GR_INITF_ACL_MSG, GR_VERSION);
53758+ error = -ENOMEM;
53759+ free_variables();
53760+ goto out;
53761+ }
53762+
53763+ error = copy_user_acl(args);
53764+ free_init_variables();
53765+ if (error) {
53766+ free_variables();
53767+ goto out;
53768+ }
53769+
53770+ if ((error = gr_set_acls(0))) {
53771+ free_variables();
53772+ goto out;
53773+ }
53774+
53775+ pax_open_kernel();
53776+ gr_status |= GR_READY;
53777+ pax_close_kernel();
53778+
53779+ out:
53780+ return error;
53781+}
53782+
53783+/* derived from glibc fnmatch() 0: match, 1: no match*/
53784+
53785+static int
53786+glob_match(const char *p, const char *n)
53787+{
53788+ char c;
53789+
53790+ while ((c = *p++) != '\0') {
53791+ switch (c) {
53792+ case '?':
53793+ if (*n == '\0')
53794+ return 1;
53795+ else if (*n == '/')
53796+ return 1;
53797+ break;
53798+ case '\\':
53799+ if (*n != c)
53800+ return 1;
53801+ break;
53802+ case '*':
53803+ for (c = *p++; c == '?' || c == '*'; c = *p++) {
53804+ if (*n == '/')
53805+ return 1;
53806+ else if (c == '?') {
53807+ if (*n == '\0')
53808+ return 1;
53809+ else
53810+ ++n;
53811+ }
53812+ }
53813+ if (c == '\0') {
53814+ return 0;
53815+ } else {
53816+ const char *endp;
53817+
53818+ if ((endp = strchr(n, '/')) == NULL)
53819+ endp = n + strlen(n);
53820+
53821+ if (c == '[') {
53822+ for (--p; n < endp; ++n)
53823+ if (!glob_match(p, n))
53824+ return 0;
53825+ } else if (c == '/') {
53826+ while (*n != '\0' && *n != '/')
53827+ ++n;
53828+ if (*n == '/' && !glob_match(p, n + 1))
53829+ return 0;
53830+ } else {
53831+ for (--p; n < endp; ++n)
53832+ if (*n == c && !glob_match(p, n))
53833+ return 0;
53834+ }
53835+
53836+ return 1;
53837+ }
53838+ case '[':
53839+ {
53840+ int not;
53841+ char cold;
53842+
53843+ if (*n == '\0' || *n == '/')
53844+ return 1;
53845+
53846+ not = (*p == '!' || *p == '^');
53847+ if (not)
53848+ ++p;
53849+
53850+ c = *p++;
53851+ for (;;) {
53852+ unsigned char fn = (unsigned char)*n;
53853+
53854+ if (c == '\0')
53855+ return 1;
53856+ else {
53857+ if (c == fn)
53858+ goto matched;
53859+ cold = c;
53860+ c = *p++;
53861+
53862+ if (c == '-' && *p != ']') {
53863+ unsigned char cend = *p++;
53864+
53865+ if (cend == '\0')
53866+ return 1;
53867+
53868+ if (cold <= fn && fn <= cend)
53869+ goto matched;
53870+
53871+ c = *p++;
53872+ }
53873+ }
53874+
53875+ if (c == ']')
53876+ break;
53877+ }
53878+ if (!not)
53879+ return 1;
53880+ break;
53881+ matched:
53882+ while (c != ']') {
53883+ if (c == '\0')
53884+ return 1;
53885+
53886+ c = *p++;
53887+ }
53888+ if (not)
53889+ return 1;
53890+ }
53891+ break;
53892+ default:
53893+ if (c != *n)
53894+ return 1;
53895+ }
53896+
53897+ ++n;
53898+ }
53899+
53900+ if (*n == '\0')
53901+ return 0;
53902+
53903+ if (*n == '/')
53904+ return 0;
53905+
53906+ return 1;
53907+}
53908+
53909+static struct acl_object_label *
53910+chk_glob_label(struct acl_object_label *globbed,
53911+ const struct dentry *dentry, const struct vfsmount *mnt, char **path)
53912+{
53913+ struct acl_object_label *tmp;
53914+
53915+ if (*path == NULL)
53916+ *path = gr_to_filename_nolock(dentry, mnt);
53917+
53918+ tmp = globbed;
53919+
53920+ while (tmp) {
53921+ if (!glob_match(tmp->filename, *path))
53922+ return tmp;
53923+ tmp = tmp->next;
53924+ }
53925+
53926+ return NULL;
53927+}
53928+
53929+static struct acl_object_label *
53930+__full_lookup(const struct dentry *orig_dentry, const struct vfsmount *orig_mnt,
53931+ const ino_t curr_ino, const dev_t curr_dev,
53932+ const struct acl_subject_label *subj, char **path, const int checkglob)
53933+{
53934+ struct acl_subject_label *tmpsubj;
53935+ struct acl_object_label *retval;
53936+ struct acl_object_label *retval2;
53937+
53938+ tmpsubj = (struct acl_subject_label *) subj;
53939+ read_lock(&gr_inode_lock);
53940+ do {
53941+ retval = lookup_acl_obj_label(curr_ino, curr_dev, tmpsubj);
53942+ if (retval) {
53943+ if (checkglob && retval->globbed) {
53944+ retval2 = chk_glob_label(retval->globbed, orig_dentry, orig_mnt, path);
53945+ if (retval2)
53946+ retval = retval2;
53947+ }
53948+ break;
53949+ }
53950+ } while ((tmpsubj = tmpsubj->parent_subject));
53951+ read_unlock(&gr_inode_lock);
53952+
53953+ return retval;
53954+}
53955+
53956+static __inline__ struct acl_object_label *
53957+full_lookup(const struct dentry *orig_dentry, const struct vfsmount *orig_mnt,
53958+ struct dentry *curr_dentry,
53959+ const struct acl_subject_label *subj, char **path, const int checkglob)
53960+{
53961+ int newglob = checkglob;
53962+ ino_t inode;
53963+ dev_t device;
53964+
53965+ /* if we aren't checking a subdirectory of the original path yet, don't do glob checking
53966+ as we don't want a / * rule to match instead of the / object
53967+ don't do this for create lookups that call this function though, since they're looking up
53968+ on the parent and thus need globbing checks on all paths
53969+ */
53970+ if (orig_dentry == curr_dentry && newglob != GR_CREATE_GLOB)
53971+ newglob = GR_NO_GLOB;
53972+
53973+ spin_lock(&curr_dentry->d_lock);
53974+ inode = curr_dentry->d_inode->i_ino;
53975+ device = __get_dev(curr_dentry);
53976+ spin_unlock(&curr_dentry->d_lock);
53977+
53978+ return __full_lookup(orig_dentry, orig_mnt, inode, device, subj, path, newglob);
53979+}
53980+
53981+static struct acl_object_label *
53982+__chk_obj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
53983+ const struct acl_subject_label *subj, char *path, const int checkglob)
53984+{
53985+ struct dentry *dentry = (struct dentry *) l_dentry;
53986+ struct vfsmount *mnt = (struct vfsmount *) l_mnt;
53987+ struct mount *real_mnt = real_mount(mnt);
53988+ struct acl_object_label *retval;
53989+ struct dentry *parent;
53990+
53991+ write_seqlock(&rename_lock);
53992+ br_read_lock(&vfsmount_lock);
53993+
53994+ if (unlikely((mnt == shm_mnt && dentry->d_inode->i_nlink == 0) || mnt == pipe_mnt ||
53995+#ifdef CONFIG_NET
53996+ mnt == sock_mnt ||
53997+#endif
53998+#ifdef CONFIG_HUGETLBFS
53999+ (mnt == hugetlbfs_vfsmount && dentry->d_inode->i_nlink == 0) ||
54000+#endif
54001+ /* ignore Eric Biederman */
54002+ IS_PRIVATE(l_dentry->d_inode))) {
54003+ retval = (subj->mode & GR_SHMEXEC) ? fakefs_obj_rwx : fakefs_obj_rw;
54004+ goto out;
54005+ }
54006+
54007+ for (;;) {
54008+ if (dentry == real_root.dentry && mnt == real_root.mnt)
54009+ break;
54010+
54011+ if (dentry == mnt->mnt_root || IS_ROOT(dentry)) {
54012+ if (!mnt_has_parent(real_mnt))
54013+ break;
54014+
54015+ retval = full_lookup(l_dentry, l_mnt, dentry, subj, &path, checkglob);
54016+ if (retval != NULL)
54017+ goto out;
54018+
54019+ dentry = real_mnt->mnt_mountpoint;
54020+ real_mnt = real_mnt->mnt_parent;
54021+ mnt = &real_mnt->mnt;
54022+ continue;
54023+ }
54024+
54025+ parent = dentry->d_parent;
54026+ retval = full_lookup(l_dentry, l_mnt, dentry, subj, &path, checkglob);
54027+ if (retval != NULL)
54028+ goto out;
54029+
54030+ dentry = parent;
54031+ }
54032+
54033+ retval = full_lookup(l_dentry, l_mnt, dentry, subj, &path, checkglob);
54034+
54035+ /* real_root is pinned so we don't have to hold a reference */
54036+ if (retval == NULL)
54037+ retval = full_lookup(l_dentry, l_mnt, real_root.dentry, subj, &path, checkglob);
54038+out:
54039+ br_read_unlock(&vfsmount_lock);
54040+ write_sequnlock(&rename_lock);
54041+
54042+ BUG_ON(retval == NULL);
54043+
54044+ return retval;
54045+}
54046+
54047+static __inline__ struct acl_object_label *
54048+chk_obj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
54049+ const struct acl_subject_label *subj)
54050+{
54051+ char *path = NULL;
54052+ return __chk_obj_label(l_dentry, l_mnt, subj, path, GR_REG_GLOB);
54053+}
54054+
54055+static __inline__ struct acl_object_label *
54056+chk_obj_label_noglob(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
54057+ const struct acl_subject_label *subj)
54058+{
54059+ char *path = NULL;
54060+ return __chk_obj_label(l_dentry, l_mnt, subj, path, GR_NO_GLOB);
54061+}
54062+
54063+static __inline__ struct acl_object_label *
54064+chk_obj_create_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
54065+ const struct acl_subject_label *subj, char *path)
54066+{
54067+ return __chk_obj_label(l_dentry, l_mnt, subj, path, GR_CREATE_GLOB);
54068+}
54069+
54070+static struct acl_subject_label *
54071+chk_subj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
54072+ const struct acl_role_label *role)
54073+{
54074+ struct dentry *dentry = (struct dentry *) l_dentry;
54075+ struct vfsmount *mnt = (struct vfsmount *) l_mnt;
54076+ struct mount *real_mnt = real_mount(mnt);
54077+ struct acl_subject_label *retval;
54078+ struct dentry *parent;
54079+
54080+ write_seqlock(&rename_lock);
54081+ br_read_lock(&vfsmount_lock);
54082+
54083+ for (;;) {
54084+ if (dentry == real_root.dentry && mnt == real_root.mnt)
54085+ break;
54086+ if (dentry == mnt->mnt_root || IS_ROOT(dentry)) {
54087+ if (!mnt_has_parent(real_mnt))
54088+ break;
54089+
54090+ spin_lock(&dentry->d_lock);
54091+ read_lock(&gr_inode_lock);
54092+ retval =
54093+ lookup_acl_subj_label(dentry->d_inode->i_ino,
54094+ __get_dev(dentry), role);
54095+ read_unlock(&gr_inode_lock);
54096+ spin_unlock(&dentry->d_lock);
54097+ if (retval != NULL)
54098+ goto out;
54099+
54100+ dentry = real_mnt->mnt_mountpoint;
54101+ real_mnt = real_mnt->mnt_parent;
54102+ mnt = &real_mnt->mnt;
54103+ continue;
54104+ }
54105+
54106+ spin_lock(&dentry->d_lock);
54107+ read_lock(&gr_inode_lock);
54108+ retval = lookup_acl_subj_label(dentry->d_inode->i_ino,
54109+ __get_dev(dentry), role);
54110+ read_unlock(&gr_inode_lock);
54111+ parent = dentry->d_parent;
54112+ spin_unlock(&dentry->d_lock);
54113+
54114+ if (retval != NULL)
54115+ goto out;
54116+
54117+ dentry = parent;
54118+ }
54119+
54120+ spin_lock(&dentry->d_lock);
54121+ read_lock(&gr_inode_lock);
54122+ retval = lookup_acl_subj_label(dentry->d_inode->i_ino,
54123+ __get_dev(dentry), role);
54124+ read_unlock(&gr_inode_lock);
54125+ spin_unlock(&dentry->d_lock);
54126+
54127+ if (unlikely(retval == NULL)) {
54128+ /* real_root is pinned, we don't need to hold a reference */
54129+ read_lock(&gr_inode_lock);
54130+ retval = lookup_acl_subj_label(real_root.dentry->d_inode->i_ino,
54131+ __get_dev(real_root.dentry), role);
54132+ read_unlock(&gr_inode_lock);
54133+ }
54134+out:
54135+ br_read_unlock(&vfsmount_lock);
54136+ write_sequnlock(&rename_lock);
54137+
54138+ BUG_ON(retval == NULL);
54139+
54140+ return retval;
54141+}
54142+
54143+static void
54144+gr_log_learn(const struct dentry *dentry, const struct vfsmount *mnt, const __u32 mode)
54145+{
54146+ struct task_struct *task = current;
54147+ const struct cred *cred = current_cred();
54148+
54149+ security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename, task->role->roletype,
54150+ cred->uid, cred->gid, task->exec_file ? gr_to_filename1(task->exec_file->f_path.dentry,
54151+ task->exec_file->f_path.mnt) : task->acl->filename, task->acl->filename,
54152+ 1UL, 1UL, gr_to_filename(dentry, mnt), (unsigned long) mode, &task->signal->saved_ip);
54153+
54154+ return;
54155+}
54156+
54157+static void
54158+gr_log_learn_id_change(const char type, const unsigned int real,
54159+ const unsigned int effective, const unsigned int fs)
54160+{
54161+ struct task_struct *task = current;
54162+ const struct cred *cred = current_cred();
54163+
54164+ security_learn(GR_ID_LEARN_MSG, task->role->rolename, task->role->roletype,
54165+ cred->uid, cred->gid, task->exec_file ? gr_to_filename1(task->exec_file->f_path.dentry,
54166+ task->exec_file->f_path.mnt) : task->acl->filename, task->acl->filename,
54167+ type, real, effective, fs, &task->signal->saved_ip);
54168+
54169+ return;
54170+}
54171+
54172+__u32
54173+gr_search_file(const struct dentry * dentry, const __u32 mode,
54174+ const struct vfsmount * mnt)
54175+{
54176+ __u32 retval = mode;
54177+ struct acl_subject_label *curracl;
54178+ struct acl_object_label *currobj;
54179+
54180+ if (unlikely(!(gr_status & GR_READY)))
54181+ return (mode & ~GR_AUDITS);
54182+
54183+ curracl = current->acl;
54184+
54185+ currobj = chk_obj_label(dentry, mnt, curracl);
54186+ retval = currobj->mode & mode;
54187+
54188+ /* if we're opening a specified transfer file for writing
54189+ (e.g. /dev/initctl), then transfer our role to init
54190+ */
54191+ if (unlikely(currobj->mode & GR_INIT_TRANSFER && retval & GR_WRITE &&
54192+ current->role->roletype & GR_ROLE_PERSIST)) {
54193+ struct task_struct *task = init_pid_ns.child_reaper;
54194+
54195+ if (task->role != current->role) {
54196+ task->acl_sp_role = 0;
54197+ task->acl_role_id = current->acl_role_id;
54198+ task->role = current->role;
54199+ rcu_read_lock();
54200+ read_lock(&grsec_exec_file_lock);
54201+ gr_apply_subject_to_task(task);
54202+ read_unlock(&grsec_exec_file_lock);
54203+ rcu_read_unlock();
54204+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_INIT_TRANSFER_MSG);
54205+ }
54206+ }
54207+
54208+ if (unlikely
54209+ ((curracl->mode & (GR_LEARN | GR_INHERITLEARN)) && !(mode & GR_NOPTRACE)
54210+ && (retval != (mode & ~(GR_AUDITS | GR_SUPPRESS))))) {
54211+ __u32 new_mode = mode;
54212+
54213+ new_mode &= ~(GR_AUDITS | GR_SUPPRESS);
54214+
54215+ retval = new_mode;
54216+
54217+ if (new_mode & GR_EXEC && curracl->mode & GR_INHERITLEARN)
54218+ new_mode |= GR_INHERIT;
54219+
54220+ if (!(mode & GR_NOLEARN))
54221+ gr_log_learn(dentry, mnt, new_mode);
54222+ }
54223+
54224+ return retval;
54225+}
54226+
54227+struct acl_object_label *gr_get_create_object(const struct dentry *new_dentry,
54228+ const struct dentry *parent,
54229+ const struct vfsmount *mnt)
54230+{
54231+ struct name_entry *match;
54232+ struct acl_object_label *matchpo;
54233+ struct acl_subject_label *curracl;
54234+ char *path;
54235+
54236+ if (unlikely(!(gr_status & GR_READY)))
54237+ return NULL;
54238+
54239+ preempt_disable();
54240+ path = gr_to_filename_rbac(new_dentry, mnt);
54241+ match = lookup_name_entry_create(path);
54242+
54243+ curracl = current->acl;
54244+
54245+ if (match) {
54246+ read_lock(&gr_inode_lock);
54247+ matchpo = lookup_acl_obj_label_create(match->inode, match->device, curracl);
54248+ read_unlock(&gr_inode_lock);
54249+
54250+ if (matchpo) {
54251+ preempt_enable();
54252+ return matchpo;
54253+ }
54254+ }
54255+
54256+ // lookup parent
54257+
54258+ matchpo = chk_obj_create_label(parent, mnt, curracl, path);
54259+
54260+ preempt_enable();
54261+ return matchpo;
54262+}
54263+
54264+__u32
54265+gr_check_create(const struct dentry * new_dentry, const struct dentry * parent,
54266+ const struct vfsmount * mnt, const __u32 mode)
54267+{
54268+ struct acl_object_label *matchpo;
54269+ __u32 retval;
54270+
54271+ if (unlikely(!(gr_status & GR_READY)))
54272+ return (mode & ~GR_AUDITS);
54273+
54274+ matchpo = gr_get_create_object(new_dentry, parent, mnt);
54275+
54276+ retval = matchpo->mode & mode;
54277+
54278+ if ((retval != (mode & ~(GR_AUDITS | GR_SUPPRESS)))
54279+ && (current->acl->mode & (GR_LEARN | GR_INHERITLEARN))) {
54280+ __u32 new_mode = mode;
54281+
54282+ new_mode &= ~(GR_AUDITS | GR_SUPPRESS);
54283+
54284+ gr_log_learn(new_dentry, mnt, new_mode);
54285+ return new_mode;
54286+ }
54287+
54288+ return retval;
54289+}
54290+
54291+__u32
54292+gr_check_link(const struct dentry * new_dentry,
54293+ const struct dentry * parent_dentry,
54294+ const struct vfsmount * parent_mnt,
54295+ const struct dentry * old_dentry, const struct vfsmount * old_mnt)
54296+{
54297+ struct acl_object_label *obj;
54298+ __u32 oldmode, newmode;
54299+ __u32 needmode;
54300+ __u32 checkmodes = GR_FIND | GR_APPEND | GR_WRITE | GR_EXEC | GR_SETID | GR_READ |
54301+ GR_DELETE | GR_INHERIT;
54302+
54303+ if (unlikely(!(gr_status & GR_READY)))
54304+ return (GR_CREATE | GR_LINK);
54305+
54306+ obj = chk_obj_label(old_dentry, old_mnt, current->acl);
54307+ oldmode = obj->mode;
54308+
54309+ obj = gr_get_create_object(new_dentry, parent_dentry, parent_mnt);
54310+ newmode = obj->mode;
54311+
54312+ needmode = newmode & checkmodes;
54313+
54314+ // old name for hardlink must have at least the permissions of the new name
54315+ if ((oldmode & needmode) != needmode)
54316+ goto bad;
54317+
54318+ // if old name had restrictions/auditing, make sure the new name does as well
54319+ needmode = oldmode & (GR_NOPTRACE | GR_PTRACERD | GR_INHERIT | GR_AUDITS);
54320+
54321+ // don't allow hardlinking of suid/sgid/fcapped files without permission
54322+ if (is_privileged_binary(old_dentry))
54323+ needmode |= GR_SETID;
54324+
54325+ if ((newmode & needmode) != needmode)
54326+ goto bad;
54327+
54328+ // enforce minimum permissions
54329+ if ((newmode & (GR_CREATE | GR_LINK)) == (GR_CREATE | GR_LINK))
54330+ return newmode;
54331+bad:
54332+ needmode = oldmode;
54333+ if (is_privileged_binary(old_dentry))
54334+ needmode |= GR_SETID;
54335+
54336+ if (current->acl->mode & (GR_LEARN | GR_INHERITLEARN)) {
54337+ gr_log_learn(old_dentry, old_mnt, needmode | GR_CREATE | GR_LINK);
54338+ return (GR_CREATE | GR_LINK);
54339+ } else if (newmode & GR_SUPPRESS)
54340+ return GR_SUPPRESS;
54341+ else
54342+ return 0;
54343+}
54344+
54345+int
54346+gr_check_hidden_task(const struct task_struct *task)
54347+{
54348+ if (unlikely(!(gr_status & GR_READY)))
54349+ return 0;
54350+
54351+ if (!(task->acl->mode & GR_PROCFIND) && !(current->acl->mode & GR_VIEW))
54352+ return 1;
54353+
54354+ return 0;
54355+}
54356+
54357+int
54358+gr_check_protected_task(const struct task_struct *task)
54359+{
54360+ if (unlikely(!(gr_status & GR_READY) || !task))
54361+ return 0;
54362+
54363+ if ((task->acl->mode & GR_PROTECTED) && !(current->acl->mode & GR_KILL) &&
54364+ task->acl != current->acl)
54365+ return 1;
54366+
54367+ return 0;
54368+}
54369+
54370+int
54371+gr_check_protected_task_fowner(struct pid *pid, enum pid_type type)
54372+{
54373+ struct task_struct *p;
54374+ int ret = 0;
54375+
54376+ if (unlikely(!(gr_status & GR_READY) || !pid))
54377+ return ret;
54378+
54379+ read_lock(&tasklist_lock);
54380+ do_each_pid_task(pid, type, p) {
54381+ if ((p->acl->mode & GR_PROTECTED) && !(current->acl->mode & GR_KILL) &&
54382+ p->acl != current->acl) {
54383+ ret = 1;
54384+ goto out;
54385+ }
54386+ } while_each_pid_task(pid, type, p);
54387+out:
54388+ read_unlock(&tasklist_lock);
54389+
54390+ return ret;
54391+}
54392+
54393+void
54394+gr_copy_label(struct task_struct *tsk)
54395+{
54396+ tsk->signal->used_accept = 0;
54397+ tsk->acl_sp_role = 0;
54398+ tsk->acl_role_id = current->acl_role_id;
54399+ tsk->acl = current->acl;
54400+ tsk->role = current->role;
54401+ tsk->signal->curr_ip = current->signal->curr_ip;
54402+ tsk->signal->saved_ip = current->signal->saved_ip;
54403+ if (current->exec_file)
54404+ get_file(current->exec_file);
54405+ tsk->exec_file = current->exec_file;
54406+ tsk->is_writable = current->is_writable;
54407+ if (unlikely(current->signal->used_accept)) {
54408+ current->signal->curr_ip = 0;
54409+ current->signal->saved_ip = 0;
54410+ }
54411+
54412+ return;
54413+}
54414+
54415+static void
54416+gr_set_proc_res(struct task_struct *task)
54417+{
54418+ struct acl_subject_label *proc;
54419+ unsigned short i;
54420+
54421+ proc = task->acl;
54422+
54423+ if (proc->mode & (GR_LEARN | GR_INHERITLEARN))
54424+ return;
54425+
54426+ for (i = 0; i < RLIM_NLIMITS; i++) {
54427+ if (!(proc->resmask & (1 << i)))
54428+ continue;
54429+
54430+ task->signal->rlim[i].rlim_cur = proc->res[i].rlim_cur;
54431+ task->signal->rlim[i].rlim_max = proc->res[i].rlim_max;
54432+ }
54433+
54434+ return;
54435+}
54436+
54437+extern int __gr_process_user_ban(struct user_struct *user);
54438+
54439+int
54440+gr_check_user_change(int real, int effective, int fs)
54441+{
54442+ unsigned int i;
54443+ __u16 num;
54444+ uid_t *uidlist;
54445+ int curuid;
54446+ int realok = 0;
54447+ int effectiveok = 0;
54448+ int fsok = 0;
54449+
54450+#if defined(CONFIG_GRKERNSEC_KERN_LOCKOUT) || defined(CONFIG_GRKERNSEC_BRUTE)
54451+ struct user_struct *user;
54452+
54453+ if (real == -1)
54454+ goto skipit;
54455+
54456+ user = find_user(real);
54457+ if (user == NULL)
54458+ goto skipit;
54459+
54460+ if (__gr_process_user_ban(user)) {
54461+ /* for find_user */
54462+ free_uid(user);
54463+ return 1;
54464+ }
54465+
54466+ /* for find_user */
54467+ free_uid(user);
54468+
54469+skipit:
54470+#endif
54471+
54472+ if (unlikely(!(gr_status & GR_READY)))
54473+ return 0;
54474+
54475+ if (current->acl->mode & (GR_LEARN | GR_INHERITLEARN))
54476+ gr_log_learn_id_change('u', real, effective, fs);
54477+
54478+ num = current->acl->user_trans_num;
54479+ uidlist = current->acl->user_transitions;
54480+
54481+ if (uidlist == NULL)
54482+ return 0;
54483+
54484+ if (real == -1)
54485+ realok = 1;
54486+ if (effective == -1)
54487+ effectiveok = 1;
54488+ if (fs == -1)
54489+ fsok = 1;
54490+
54491+ if (current->acl->user_trans_type & GR_ID_ALLOW) {
54492+ for (i = 0; i < num; i++) {
54493+ curuid = (int)uidlist[i];
54494+ if (real == curuid)
54495+ realok = 1;
54496+ if (effective == curuid)
54497+ effectiveok = 1;
54498+ if (fs == curuid)
54499+ fsok = 1;
54500+ }
54501+ } else if (current->acl->user_trans_type & GR_ID_DENY) {
54502+ for (i = 0; i < num; i++) {
54503+ curuid = (int)uidlist[i];
54504+ if (real == curuid)
54505+ break;
54506+ if (effective == curuid)
54507+ break;
54508+ if (fs == curuid)
54509+ break;
54510+ }
54511+ /* not in deny list */
54512+ if (i == num) {
54513+ realok = 1;
54514+ effectiveok = 1;
54515+ fsok = 1;
54516+ }
54517+ }
54518+
54519+ if (realok && effectiveok && fsok)
54520+ return 0;
54521+ else {
54522+ gr_log_int(GR_DONT_AUDIT, GR_USRCHANGE_ACL_MSG, realok ? (effectiveok ? (fsok ? 0 : fs) : effective) : real);
54523+ return 1;
54524+ }
54525+}
54526+
54527+int
54528+gr_check_group_change(int real, int effective, int fs)
54529+{
54530+ unsigned int i;
54531+ __u16 num;
54532+ gid_t *gidlist;
54533+ int curgid;
54534+ int realok = 0;
54535+ int effectiveok = 0;
54536+ int fsok = 0;
54537+
54538+ if (unlikely(!(gr_status & GR_READY)))
54539+ return 0;
54540+
54541+ if (current->acl->mode & (GR_LEARN | GR_INHERITLEARN))
54542+ gr_log_learn_id_change('g', real, effective, fs);
54543+
54544+ num = current->acl->group_trans_num;
54545+ gidlist = current->acl->group_transitions;
54546+
54547+ if (gidlist == NULL)
54548+ return 0;
54549+
54550+ if (real == -1)
54551+ realok = 1;
54552+ if (effective == -1)
54553+ effectiveok = 1;
54554+ if (fs == -1)
54555+ fsok = 1;
54556+
54557+ if (current->acl->group_trans_type & GR_ID_ALLOW) {
54558+ for (i = 0; i < num; i++) {
54559+ curgid = (int)gidlist[i];
54560+ if (real == curgid)
54561+ realok = 1;
54562+ if (effective == curgid)
54563+ effectiveok = 1;
54564+ if (fs == curgid)
54565+ fsok = 1;
54566+ }
54567+ } else if (current->acl->group_trans_type & GR_ID_DENY) {
54568+ for (i = 0; i < num; i++) {
54569+ curgid = (int)gidlist[i];
54570+ if (real == curgid)
54571+ break;
54572+ if (effective == curgid)
54573+ break;
54574+ if (fs == curgid)
54575+ break;
54576+ }
54577+ /* not in deny list */
54578+ if (i == num) {
54579+ realok = 1;
54580+ effectiveok = 1;
54581+ fsok = 1;
54582+ }
54583+ }
54584+
54585+ if (realok && effectiveok && fsok)
54586+ return 0;
54587+ else {
54588+ gr_log_int(GR_DONT_AUDIT, GR_GRPCHANGE_ACL_MSG, realok ? (effectiveok ? (fsok ? 0 : fs) : effective) : real);
54589+ return 1;
54590+ }
54591+}
54592+
54593+extern int gr_acl_is_capable(const int cap);
54594+
54595+void
54596+gr_set_role_label(struct task_struct *task, const uid_t uid, const uid_t gid)
54597+{
54598+ struct acl_role_label *role = task->role;
54599+ struct acl_subject_label *subj = NULL;
54600+ struct acl_object_label *obj;
54601+ struct file *filp;
54602+
54603+ if (unlikely(!(gr_status & GR_READY)))
54604+ return;
54605+
54606+ filp = task->exec_file;
54607+
54608+ /* kernel process, we'll give them the kernel role */
54609+ if (unlikely(!filp)) {
54610+ task->role = kernel_role;
54611+ task->acl = kernel_role->root_label;
54612+ return;
54613+ } else if (!task->role || !(task->role->roletype & GR_ROLE_SPECIAL))
54614+ role = lookup_acl_role_label(task, uid, gid);
54615+
54616+ /* don't change the role if we're not a privileged process */
54617+ if (role && task->role != role &&
54618+ (((role->roletype & GR_ROLE_USER) && !gr_acl_is_capable(CAP_SETUID)) ||
54619+ ((role->roletype & GR_ROLE_GROUP) && !gr_acl_is_capable(CAP_SETGID))))
54620+ return;
54621+
54622+ /* perform subject lookup in possibly new role
54623+ we can use this result below in the case where role == task->role
54624+ */
54625+ subj = chk_subj_label(filp->f_path.dentry, filp->f_path.mnt, role);
54626+
54627+ /* if we changed uid/gid, but result in the same role
54628+ and are using inheritance, don't lose the inherited subject
54629+ if current subject is other than what normal lookup
54630+ would result in, we arrived via inheritance, don't
54631+ lose subject
54632+ */
54633+ if (role != task->role || (!(task->acl->mode & GR_INHERITLEARN) &&
54634+ (subj == task->acl)))
54635+ task->acl = subj;
54636+
54637+ task->role = role;
54638+
54639+ task->is_writable = 0;
54640+
54641+ /* ignore additional mmap checks for processes that are writable
54642+ by the default ACL */
54643+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, default_role->root_label);
54644+ if (unlikely(obj->mode & GR_WRITE))
54645+ task->is_writable = 1;
54646+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, task->role->root_label);
54647+ if (unlikely(obj->mode & GR_WRITE))
54648+ task->is_writable = 1;
54649+
54650+#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
54651+ printk(KERN_ALERT "Set role label for (%s:%d): role:%s, subject:%s\n", task->comm, task->pid, task->role->rolename, task->acl->filename);
54652+#endif
54653+
54654+ gr_set_proc_res(task);
54655+
54656+ return;
54657+}
54658+
54659+int
54660+gr_set_proc_label(const struct dentry *dentry, const struct vfsmount *mnt,
54661+ const int unsafe_flags)
54662+{
54663+ struct task_struct *task = current;
54664+ struct acl_subject_label *newacl;
54665+ struct acl_object_label *obj;
54666+ __u32 retmode;
54667+
54668+ if (unlikely(!(gr_status & GR_READY)))
54669+ return 0;
54670+
54671+ newacl = chk_subj_label(dentry, mnt, task->role);
54672+
54673+ /* special handling for if we did an strace -f -p <pid> from an admin role, where pid then
54674+ did an exec
54675+ */
54676+ rcu_read_lock();
54677+ read_lock(&tasklist_lock);
54678+ if (task->ptrace && task->parent && ((task->parent->role->roletype & GR_ROLE_GOD) ||
54679+ (task->parent->acl->mode & GR_POVERRIDE))) {
54680+ read_unlock(&tasklist_lock);
54681+ rcu_read_unlock();
54682+ goto skip_check;
54683+ }
54684+ read_unlock(&tasklist_lock);
54685+ rcu_read_unlock();
54686+
54687+ if (unsafe_flags && !(task->acl->mode & GR_POVERRIDE) && (task->acl != newacl) &&
54688+ !(task->role->roletype & GR_ROLE_GOD) &&
54689+ !gr_search_file(dentry, GR_PTRACERD, mnt) &&
54690+ !(task->acl->mode & (GR_LEARN | GR_INHERITLEARN))) {
54691+ if (unsafe_flags & LSM_UNSAFE_SHARE)
54692+ gr_log_fs_generic(GR_DONT_AUDIT, GR_UNSAFESHARE_EXEC_ACL_MSG, dentry, mnt);
54693+ else
54694+ gr_log_fs_generic(GR_DONT_AUDIT, GR_PTRACE_EXEC_ACL_MSG, dentry, mnt);
54695+ return -EACCES;
54696+ }
54697+
54698+skip_check:
54699+
54700+ obj = chk_obj_label(dentry, mnt, task->acl);
54701+ retmode = obj->mode & (GR_INHERIT | GR_AUDIT_INHERIT);
54702+
54703+ if (!(task->acl->mode & GR_INHERITLEARN) &&
54704+ ((newacl->mode & GR_LEARN) || !(retmode & GR_INHERIT))) {
54705+ if (obj->nested)
54706+ task->acl = obj->nested;
54707+ else
54708+ task->acl = newacl;
54709+ } else if (retmode & GR_INHERIT && retmode & GR_AUDIT_INHERIT)
54710+ gr_log_str_fs(GR_DO_AUDIT, GR_INHERIT_ACL_MSG, task->acl->filename, dentry, mnt);
54711+
54712+ task->is_writable = 0;
54713+
54714+ /* ignore additional mmap checks for processes that are writable
54715+ by the default ACL */
54716+ obj = chk_obj_label(dentry, mnt, default_role->root_label);
54717+ if (unlikely(obj->mode & GR_WRITE))
54718+ task->is_writable = 1;
54719+ obj = chk_obj_label(dentry, mnt, task->role->root_label);
54720+ if (unlikely(obj->mode & GR_WRITE))
54721+ task->is_writable = 1;
54722+
54723+ gr_set_proc_res(task);
54724+
54725+#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
54726+ printk(KERN_ALERT "Set subject label for (%s:%d): role:%s, subject:%s\n", task->comm, task->pid, task->role->rolename, task->acl->filename);
54727+#endif
54728+ return 0;
54729+}
54730+
54731+/* always called with valid inodev ptr */
54732+static void
54733+do_handle_delete(struct inodev_entry *inodev, const ino_t ino, const dev_t dev)
54734+{
54735+ struct acl_object_label *matchpo;
54736+ struct acl_subject_label *matchps;
54737+ struct acl_subject_label *subj;
54738+ struct acl_role_label *role;
54739+ unsigned int x;
54740+
54741+ FOR_EACH_ROLE_START(role)
54742+ FOR_EACH_SUBJECT_START(role, subj, x)
54743+ if ((matchpo = lookup_acl_obj_label(ino, dev, subj)) != NULL)
54744+ matchpo->mode |= GR_DELETED;
54745+ FOR_EACH_SUBJECT_END(subj,x)
54746+ FOR_EACH_NESTED_SUBJECT_START(role, subj)
54747+ /* nested subjects aren't in the role's subj_hash table */
54748+ if ((matchpo = lookup_acl_obj_label(ino, dev, subj)) != NULL)
54749+ matchpo->mode |= GR_DELETED;
54750+ FOR_EACH_NESTED_SUBJECT_END(subj)
54751+ if ((matchps = lookup_acl_subj_label(ino, dev, role)) != NULL)
54752+ matchps->mode |= GR_DELETED;
54753+ FOR_EACH_ROLE_END(role)
54754+
54755+ inodev->nentry->deleted = 1;
54756+
54757+ return;
54758+}
54759+
54760+void
54761+gr_handle_delete(const ino_t ino, const dev_t dev)
54762+{
54763+ struct inodev_entry *inodev;
54764+
54765+ if (unlikely(!(gr_status & GR_READY)))
54766+ return;
54767+
54768+ write_lock(&gr_inode_lock);
54769+ inodev = lookup_inodev_entry(ino, dev);
54770+ if (inodev != NULL)
54771+ do_handle_delete(inodev, ino, dev);
54772+ write_unlock(&gr_inode_lock);
54773+
54774+ return;
54775+}
54776+
54777+static void
54778+update_acl_obj_label(const ino_t oldinode, const dev_t olddevice,
54779+ const ino_t newinode, const dev_t newdevice,
54780+ struct acl_subject_label *subj)
54781+{
54782+ unsigned int index = fhash(oldinode, olddevice, subj->obj_hash_size);
54783+ struct acl_object_label *match;
54784+
54785+ match = subj->obj_hash[index];
54786+
54787+ while (match && (match->inode != oldinode ||
54788+ match->device != olddevice ||
54789+ !(match->mode & GR_DELETED)))
54790+ match = match->next;
54791+
54792+ if (match && (match->inode == oldinode)
54793+ && (match->device == olddevice)
54794+ && (match->mode & GR_DELETED)) {
54795+ if (match->prev == NULL) {
54796+ subj->obj_hash[index] = match->next;
54797+ if (match->next != NULL)
54798+ match->next->prev = NULL;
54799+ } else {
54800+ match->prev->next = match->next;
54801+ if (match->next != NULL)
54802+ match->next->prev = match->prev;
54803+ }
54804+ match->prev = NULL;
54805+ match->next = NULL;
54806+ match->inode = newinode;
54807+ match->device = newdevice;
54808+ match->mode &= ~GR_DELETED;
54809+
54810+ insert_acl_obj_label(match, subj);
54811+ }
54812+
54813+ return;
54814+}
54815+
54816+static void
54817+update_acl_subj_label(const ino_t oldinode, const dev_t olddevice,
54818+ const ino_t newinode, const dev_t newdevice,
54819+ struct acl_role_label *role)
54820+{
54821+ unsigned int index = fhash(oldinode, olddevice, role->subj_hash_size);
54822+ struct acl_subject_label *match;
54823+
54824+ match = role->subj_hash[index];
54825+
54826+ while (match && (match->inode != oldinode ||
54827+ match->device != olddevice ||
54828+ !(match->mode & GR_DELETED)))
54829+ match = match->next;
54830+
54831+ if (match && (match->inode == oldinode)
54832+ && (match->device == olddevice)
54833+ && (match->mode & GR_DELETED)) {
54834+ if (match->prev == NULL) {
54835+ role->subj_hash[index] = match->next;
54836+ if (match->next != NULL)
54837+ match->next->prev = NULL;
54838+ } else {
54839+ match->prev->next = match->next;
54840+ if (match->next != NULL)
54841+ match->next->prev = match->prev;
54842+ }
54843+ match->prev = NULL;
54844+ match->next = NULL;
54845+ match->inode = newinode;
54846+ match->device = newdevice;
54847+ match->mode &= ~GR_DELETED;
54848+
54849+ insert_acl_subj_label(match, role);
54850+ }
54851+
54852+ return;
54853+}
54854+
54855+static void
54856+update_inodev_entry(const ino_t oldinode, const dev_t olddevice,
54857+ const ino_t newinode, const dev_t newdevice)
54858+{
54859+ unsigned int index = fhash(oldinode, olddevice, inodev_set.i_size);
54860+ struct inodev_entry *match;
54861+
54862+ match = inodev_set.i_hash[index];
54863+
54864+ while (match && (match->nentry->inode != oldinode ||
54865+ match->nentry->device != olddevice || !match->nentry->deleted))
54866+ match = match->next;
54867+
54868+ if (match && (match->nentry->inode == oldinode)
54869+ && (match->nentry->device == olddevice) &&
54870+ match->nentry->deleted) {
54871+ if (match->prev == NULL) {
54872+ inodev_set.i_hash[index] = match->next;
54873+ if (match->next != NULL)
54874+ match->next->prev = NULL;
54875+ } else {
54876+ match->prev->next = match->next;
54877+ if (match->next != NULL)
54878+ match->next->prev = match->prev;
54879+ }
54880+ match->prev = NULL;
54881+ match->next = NULL;
54882+ match->nentry->inode = newinode;
54883+ match->nentry->device = newdevice;
54884+ match->nentry->deleted = 0;
54885+
54886+ insert_inodev_entry(match);
54887+ }
54888+
54889+ return;
54890+}
54891+
54892+static void
54893+__do_handle_create(const struct name_entry *matchn, ino_t ino, dev_t dev)
54894+{
54895+ struct acl_subject_label *subj;
54896+ struct acl_role_label *role;
54897+ unsigned int x;
54898+
54899+ FOR_EACH_ROLE_START(role)
54900+ update_acl_subj_label(matchn->inode, matchn->device, ino, dev, role);
54901+
54902+ FOR_EACH_NESTED_SUBJECT_START(role, subj)
54903+ if ((subj->inode == ino) && (subj->device == dev)) {
54904+ subj->inode = ino;
54905+ subj->device = dev;
54906+ }
54907+ /* nested subjects aren't in the role's subj_hash table */
54908+ update_acl_obj_label(matchn->inode, matchn->device,
54909+ ino, dev, subj);
54910+ FOR_EACH_NESTED_SUBJECT_END(subj)
54911+ FOR_EACH_SUBJECT_START(role, subj, x)
54912+ update_acl_obj_label(matchn->inode, matchn->device,
54913+ ino, dev, subj);
54914+ FOR_EACH_SUBJECT_END(subj,x)
54915+ FOR_EACH_ROLE_END(role)
54916+
54917+ update_inodev_entry(matchn->inode, matchn->device, ino, dev);
54918+
54919+ return;
54920+}
54921+
54922+static void
54923+do_handle_create(const struct name_entry *matchn, const struct dentry *dentry,
54924+ const struct vfsmount *mnt)
54925+{
54926+ ino_t ino = dentry->d_inode->i_ino;
54927+ dev_t dev = __get_dev(dentry);
54928+
54929+ __do_handle_create(matchn, ino, dev);
54930+
54931+ return;
54932+}
54933+
54934+void
54935+gr_handle_create(const struct dentry *dentry, const struct vfsmount *mnt)
54936+{
54937+ struct name_entry *matchn;
54938+
54939+ if (unlikely(!(gr_status & GR_READY)))
54940+ return;
54941+
54942+ preempt_disable();
54943+ matchn = lookup_name_entry(gr_to_filename_rbac(dentry, mnt));
54944+
54945+ if (unlikely((unsigned long)matchn)) {
54946+ write_lock(&gr_inode_lock);
54947+ do_handle_create(matchn, dentry, mnt);
54948+ write_unlock(&gr_inode_lock);
54949+ }
54950+ preempt_enable();
54951+
54952+ return;
54953+}
54954+
54955+void
54956+gr_handle_proc_create(const struct dentry *dentry, const struct inode *inode)
54957+{
54958+ struct name_entry *matchn;
54959+
54960+ if (unlikely(!(gr_status & GR_READY)))
54961+ return;
54962+
54963+ preempt_disable();
54964+ matchn = lookup_name_entry(gr_to_proc_filename_rbac(dentry, init_pid_ns.proc_mnt));
54965+
54966+ if (unlikely((unsigned long)matchn)) {
54967+ write_lock(&gr_inode_lock);
54968+ __do_handle_create(matchn, inode->i_ino, inode->i_sb->s_dev);
54969+ write_unlock(&gr_inode_lock);
54970+ }
54971+ preempt_enable();
54972+
54973+ return;
54974+}
54975+
54976+void
54977+gr_handle_rename(struct inode *old_dir, struct inode *new_dir,
54978+ struct dentry *old_dentry,
54979+ struct dentry *new_dentry,
54980+ struct vfsmount *mnt, const __u8 replace)
54981+{
54982+ struct name_entry *matchn;
54983+ struct inodev_entry *inodev;
54984+ struct inode *inode = new_dentry->d_inode;
54985+ ino_t old_ino = old_dentry->d_inode->i_ino;
54986+ dev_t old_dev = __get_dev(old_dentry);
54987+
54988+ /* vfs_rename swaps the name and parent link for old_dentry and
54989+ new_dentry
54990+ at this point, old_dentry has the new name, parent link, and inode
54991+ for the renamed file
54992+ if a file is being replaced by a rename, new_dentry has the inode
54993+ and name for the replaced file
54994+ */
54995+
54996+ if (unlikely(!(gr_status & GR_READY)))
54997+ return;
54998+
54999+ preempt_disable();
55000+ matchn = lookup_name_entry(gr_to_filename_rbac(old_dentry, mnt));
55001+
55002+ /* we wouldn't have to check d_inode if it weren't for
55003+ NFS silly-renaming
55004+ */
55005+
55006+ write_lock(&gr_inode_lock);
55007+ if (unlikely(replace && inode)) {
55008+ ino_t new_ino = inode->i_ino;
55009+ dev_t new_dev = __get_dev(new_dentry);
55010+
55011+ inodev = lookup_inodev_entry(new_ino, new_dev);
55012+ if (inodev != NULL && ((inode->i_nlink <= 1) || S_ISDIR(inode->i_mode)))
55013+ do_handle_delete(inodev, new_ino, new_dev);
55014+ }
55015+
55016+ inodev = lookup_inodev_entry(old_ino, old_dev);
55017+ if (inodev != NULL && ((old_dentry->d_inode->i_nlink <= 1) || S_ISDIR(old_dentry->d_inode->i_mode)))
55018+ do_handle_delete(inodev, old_ino, old_dev);
55019+
55020+ if (unlikely((unsigned long)matchn))
55021+ do_handle_create(matchn, old_dentry, mnt);
55022+
55023+ write_unlock(&gr_inode_lock);
55024+ preempt_enable();
55025+
55026+ return;
55027+}
55028+
55029+static int
55030+lookup_special_role_auth(__u16 mode, const char *rolename, unsigned char **salt,
55031+ unsigned char **sum)
55032+{
55033+ struct acl_role_label *r;
55034+ struct role_allowed_ip *ipp;
55035+ struct role_transition *trans;
55036+ unsigned int i;
55037+ int found = 0;
55038+ u32 curr_ip = current->signal->curr_ip;
55039+
55040+ current->signal->saved_ip = curr_ip;
55041+
55042+ /* check transition table */
55043+
55044+ for (trans = current->role->transitions; trans; trans = trans->next) {
55045+ if (!strcmp(rolename, trans->rolename)) {
55046+ found = 1;
55047+ break;
55048+ }
55049+ }
55050+
55051+ if (!found)
55052+ return 0;
55053+
55054+ /* handle special roles that do not require authentication
55055+ and check ip */
55056+
55057+ FOR_EACH_ROLE_START(r)
55058+ if (!strcmp(rolename, r->rolename) &&
55059+ (r->roletype & GR_ROLE_SPECIAL)) {
55060+ found = 0;
55061+ if (r->allowed_ips != NULL) {
55062+ for (ipp = r->allowed_ips; ipp; ipp = ipp->next) {
55063+ if ((ntohl(curr_ip) & ipp->netmask) ==
55064+ (ntohl(ipp->addr) & ipp->netmask))
55065+ found = 1;
55066+ }
55067+ } else
55068+ found = 2;
55069+ if (!found)
55070+ return 0;
55071+
55072+ if (((mode == GR_SPROLE) && (r->roletype & GR_ROLE_NOPW)) ||
55073+ ((mode == GR_SPROLEPAM) && (r->roletype & GR_ROLE_PAM))) {
55074+ *salt = NULL;
55075+ *sum = NULL;
55076+ return 1;
55077+ }
55078+ }
55079+ FOR_EACH_ROLE_END(r)
55080+
55081+ for (i = 0; i < num_sprole_pws; i++) {
55082+ if (!strcmp(rolename, acl_special_roles[i]->rolename)) {
55083+ *salt = acl_special_roles[i]->salt;
55084+ *sum = acl_special_roles[i]->sum;
55085+ return 1;
55086+ }
55087+ }
55088+
55089+ return 0;
55090+}
55091+
55092+static void
55093+assign_special_role(char *rolename)
55094+{
55095+ struct acl_object_label *obj;
55096+ struct acl_role_label *r;
55097+ struct acl_role_label *assigned = NULL;
55098+ struct task_struct *tsk;
55099+ struct file *filp;
55100+
55101+ FOR_EACH_ROLE_START(r)
55102+ if (!strcmp(rolename, r->rolename) &&
55103+ (r->roletype & GR_ROLE_SPECIAL)) {
55104+ assigned = r;
55105+ break;
55106+ }
55107+ FOR_EACH_ROLE_END(r)
55108+
55109+ if (!assigned)
55110+ return;
55111+
55112+ read_lock(&tasklist_lock);
55113+ read_lock(&grsec_exec_file_lock);
55114+
55115+ tsk = current->real_parent;
55116+ if (tsk == NULL)
55117+ goto out_unlock;
55118+
55119+ filp = tsk->exec_file;
55120+ if (filp == NULL)
55121+ goto out_unlock;
55122+
55123+ tsk->is_writable = 0;
55124+
55125+ tsk->acl_sp_role = 1;
55126+ tsk->acl_role_id = ++acl_sp_role_value;
55127+ tsk->role = assigned;
55128+ tsk->acl = chk_subj_label(filp->f_path.dentry, filp->f_path.mnt, tsk->role);
55129+
55130+ /* ignore additional mmap checks for processes that are writable
55131+ by the default ACL */
55132+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, default_role->root_label);
55133+ if (unlikely(obj->mode & GR_WRITE))
55134+ tsk->is_writable = 1;
55135+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, tsk->role->root_label);
55136+ if (unlikely(obj->mode & GR_WRITE))
55137+ tsk->is_writable = 1;
55138+
55139+#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
55140+ printk(KERN_ALERT "Assigning special role:%s subject:%s to process (%s:%d)\n", tsk->role->rolename, tsk->acl->filename, tsk->comm, tsk->pid);
55141+#endif
55142+
55143+out_unlock:
55144+ read_unlock(&grsec_exec_file_lock);
55145+ read_unlock(&tasklist_lock);
55146+ return;
55147+}
55148+
55149+int gr_check_secure_terminal(struct task_struct *task)
55150+{
55151+ struct task_struct *p, *p2, *p3;
55152+ struct files_struct *files;
55153+ struct fdtable *fdt;
55154+ struct file *our_file = NULL, *file;
55155+ int i;
55156+
55157+ if (task->signal->tty == NULL)
55158+ return 1;
55159+
55160+ files = get_files_struct(task);
55161+ if (files != NULL) {
55162+ rcu_read_lock();
55163+ fdt = files_fdtable(files);
55164+ for (i=0; i < fdt->max_fds; i++) {
55165+ file = fcheck_files(files, i);
55166+ if (file && (our_file == NULL) && (file->private_data == task->signal->tty)) {
55167+ get_file(file);
55168+ our_file = file;
55169+ }
55170+ }
55171+ rcu_read_unlock();
55172+ put_files_struct(files);
55173+ }
55174+
55175+ if (our_file == NULL)
55176+ return 1;
55177+
55178+ read_lock(&tasklist_lock);
55179+ do_each_thread(p2, p) {
55180+ files = get_files_struct(p);
55181+ if (files == NULL ||
55182+ (p->signal && p->signal->tty == task->signal->tty)) {
55183+ if (files != NULL)
55184+ put_files_struct(files);
55185+ continue;
55186+ }
55187+ rcu_read_lock();
55188+ fdt = files_fdtable(files);
55189+ for (i=0; i < fdt->max_fds; i++) {
55190+ file = fcheck_files(files, i);
55191+ if (file && S_ISCHR(file->f_path.dentry->d_inode->i_mode) &&
55192+ file->f_path.dentry->d_inode->i_rdev == our_file->f_path.dentry->d_inode->i_rdev) {
55193+ p3 = task;
55194+ while (p3->pid > 0) {
55195+ if (p3 == p)
55196+ break;
55197+ p3 = p3->real_parent;
55198+ }
55199+ if (p3 == p)
55200+ break;
55201+ gr_log_ttysniff(GR_DONT_AUDIT_GOOD, GR_TTYSNIFF_ACL_MSG, p);
55202+ gr_handle_alertkill(p);
55203+ rcu_read_unlock();
55204+ put_files_struct(files);
55205+ read_unlock(&tasklist_lock);
55206+ fput(our_file);
55207+ return 0;
55208+ }
55209+ }
55210+ rcu_read_unlock();
55211+ put_files_struct(files);
55212+ } while_each_thread(p2, p);
55213+ read_unlock(&tasklist_lock);
55214+
55215+ fput(our_file);
55216+ return 1;
55217+}
55218+
55219+static int gr_rbac_disable(void *unused)
55220+{
55221+ pax_open_kernel();
55222+ gr_status &= ~GR_READY;
55223+ pax_close_kernel();
55224+
55225+ return 0;
55226+}
55227+
55228+ssize_t
55229+write_grsec_handler(struct file *file, const char * buf, size_t count, loff_t *ppos)
55230+{
55231+ struct gr_arg_wrapper uwrap;
55232+ unsigned char *sprole_salt = NULL;
55233+ unsigned char *sprole_sum = NULL;
55234+ int error = sizeof (struct gr_arg_wrapper);
55235+ int error2 = 0;
55236+
55237+ mutex_lock(&gr_dev_mutex);
55238+
55239+ if ((gr_status & GR_READY) && !(current->acl->mode & GR_KERNELAUTH)) {
55240+ error = -EPERM;
55241+ goto out;
55242+ }
55243+
55244+ if (count != sizeof (struct gr_arg_wrapper)) {
55245+ gr_log_int_int(GR_DONT_AUDIT_GOOD, GR_DEV_ACL_MSG, (int)count, (int)sizeof(struct gr_arg_wrapper));
55246+ error = -EINVAL;
55247+ goto out;
55248+ }
55249+
55250+
55251+ if (gr_auth_expires && time_after_eq(get_seconds(), gr_auth_expires)) {
55252+ gr_auth_expires = 0;
55253+ gr_auth_attempts = 0;
55254+ }
55255+
55256+ if (copy_from_user(&uwrap, buf, sizeof (struct gr_arg_wrapper))) {
55257+ error = -EFAULT;
55258+ goto out;
55259+ }
55260+
55261+ if ((uwrap.version != GRSECURITY_VERSION) || (uwrap.size != sizeof(struct gr_arg))) {
55262+ error = -EINVAL;
55263+ goto out;
55264+ }
55265+
55266+ if (copy_from_user(gr_usermode, uwrap.arg, sizeof (struct gr_arg))) {
55267+ error = -EFAULT;
55268+ goto out;
55269+ }
55270+
55271+ if (gr_usermode->mode != GR_SPROLE && gr_usermode->mode != GR_SPROLEPAM &&
55272+ gr_auth_attempts >= CONFIG_GRKERNSEC_ACL_MAXTRIES &&
55273+ time_after(gr_auth_expires, get_seconds())) {
55274+ error = -EBUSY;
55275+ goto out;
55276+ }
55277+
55278+ /* if non-root trying to do anything other than use a special role,
55279+ do not attempt authentication, do not count towards authentication
55280+ locking
55281+ */
55282+
55283+ if (gr_usermode->mode != GR_SPROLE && gr_usermode->mode != GR_STATUS &&
55284+ gr_usermode->mode != GR_UNSPROLE && gr_usermode->mode != GR_SPROLEPAM &&
55285+ !uid_eq(current_uid(), GLOBAL_ROOT_UID)) {
55286+ error = -EPERM;
55287+ goto out;
55288+ }
55289+
55290+ /* ensure pw and special role name are null terminated */
55291+
55292+ gr_usermode->pw[GR_PW_LEN - 1] = '\0';
55293+ gr_usermode->sp_role[GR_SPROLE_LEN - 1] = '\0';
55294+
55295+ /* Okay.
55296+ * We have our enough of the argument structure..(we have yet
55297+ * to copy_from_user the tables themselves) . Copy the tables
55298+ * only if we need them, i.e. for loading operations. */
55299+
55300+ switch (gr_usermode->mode) {
55301+ case GR_STATUS:
55302+ if (gr_status & GR_READY) {
55303+ error = 1;
55304+ if (!gr_check_secure_terminal(current))
55305+ error = 3;
55306+ } else
55307+ error = 2;
55308+ goto out;
55309+ case GR_SHUTDOWN:
55310+ if ((gr_status & GR_READY)
55311+ && !(chkpw(gr_usermode, gr_system_salt, gr_system_sum))) {
55312+ stop_machine(gr_rbac_disable, NULL, NULL);
55313+ free_variables();
55314+ memset(gr_usermode, 0, sizeof (struct gr_arg));
55315+ memset(gr_system_salt, 0, GR_SALT_LEN);
55316+ memset(gr_system_sum, 0, GR_SHA_LEN);
55317+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SHUTS_ACL_MSG);
55318+ } else if (gr_status & GR_READY) {
55319+ gr_log_noargs(GR_DONT_AUDIT, GR_SHUTF_ACL_MSG);
55320+ error = -EPERM;
55321+ } else {
55322+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SHUTI_ACL_MSG);
55323+ error = -EAGAIN;
55324+ }
55325+ break;
55326+ case GR_ENABLE:
55327+ if (!(gr_status & GR_READY) && !(error2 = gracl_init(gr_usermode)))
55328+ gr_log_str(GR_DONT_AUDIT_GOOD, GR_ENABLE_ACL_MSG, GR_VERSION);
55329+ else {
55330+ if (gr_status & GR_READY)
55331+ error = -EAGAIN;
55332+ else
55333+ error = error2;
55334+ gr_log_str(GR_DONT_AUDIT, GR_ENABLEF_ACL_MSG, GR_VERSION);
55335+ }
55336+ break;
55337+ case GR_RELOAD:
55338+ if (!(gr_status & GR_READY)) {
55339+ gr_log_str(GR_DONT_AUDIT_GOOD, GR_RELOADI_ACL_MSG, GR_VERSION);
55340+ error = -EAGAIN;
55341+ } else if (!(chkpw(gr_usermode, gr_system_salt, gr_system_sum))) {
55342+ stop_machine(gr_rbac_disable, NULL, NULL);
55343+ free_variables();
55344+ error2 = gracl_init(gr_usermode);
55345+ if (!error2)
55346+ gr_log_str(GR_DONT_AUDIT_GOOD, GR_RELOAD_ACL_MSG, GR_VERSION);
55347+ else {
55348+ gr_log_str(GR_DONT_AUDIT, GR_RELOADF_ACL_MSG, GR_VERSION);
55349+ error = error2;
55350+ }
55351+ } else {
55352+ gr_log_str(GR_DONT_AUDIT, GR_RELOADF_ACL_MSG, GR_VERSION);
55353+ error = -EPERM;
55354+ }
55355+ break;
55356+ case GR_SEGVMOD:
55357+ if (unlikely(!(gr_status & GR_READY))) {
55358+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SEGVMODI_ACL_MSG);
55359+ error = -EAGAIN;
55360+ break;
55361+ }
55362+
55363+ if (!(chkpw(gr_usermode, gr_system_salt, gr_system_sum))) {
55364+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SEGVMODS_ACL_MSG);
55365+ if (gr_usermode->segv_device && gr_usermode->segv_inode) {
55366+ struct acl_subject_label *segvacl;
55367+ segvacl =
55368+ lookup_acl_subj_label(gr_usermode->segv_inode,
55369+ gr_usermode->segv_device,
55370+ current->role);
55371+ if (segvacl) {
55372+ segvacl->crashes = 0;
55373+ segvacl->expires = 0;
55374+ }
55375+ } else if (gr_find_uid(gr_usermode->segv_uid) >= 0) {
55376+ gr_remove_uid(gr_usermode->segv_uid);
55377+ }
55378+ } else {
55379+ gr_log_noargs(GR_DONT_AUDIT, GR_SEGVMODF_ACL_MSG);
55380+ error = -EPERM;
55381+ }
55382+ break;
55383+ case GR_SPROLE:
55384+ case GR_SPROLEPAM:
55385+ if (unlikely(!(gr_status & GR_READY))) {
55386+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SPROLEI_ACL_MSG);
55387+ error = -EAGAIN;
55388+ break;
55389+ }
55390+
55391+ if (current->role->expires && time_after_eq(get_seconds(), current->role->expires)) {
55392+ current->role->expires = 0;
55393+ current->role->auth_attempts = 0;
55394+ }
55395+
55396+ if (current->role->auth_attempts >= CONFIG_GRKERNSEC_ACL_MAXTRIES &&
55397+ time_after(current->role->expires, get_seconds())) {
55398+ error = -EBUSY;
55399+ goto out;
55400+ }
55401+
55402+ if (lookup_special_role_auth
55403+ (gr_usermode->mode, gr_usermode->sp_role, &sprole_salt, &sprole_sum)
55404+ && ((!sprole_salt && !sprole_sum)
55405+ || !(chkpw(gr_usermode, sprole_salt, sprole_sum)))) {
55406+ char *p = "";
55407+ assign_special_role(gr_usermode->sp_role);
55408+ read_lock(&tasklist_lock);
55409+ if (current->real_parent)
55410+ p = current->real_parent->role->rolename;
55411+ read_unlock(&tasklist_lock);
55412+ gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_SPROLES_ACL_MSG,
55413+ p, acl_sp_role_value);
55414+ } else {
55415+ gr_log_str(GR_DONT_AUDIT, GR_SPROLEF_ACL_MSG, gr_usermode->sp_role);
55416+ error = -EPERM;
55417+ if(!(current->role->auth_attempts++))
55418+ current->role->expires = get_seconds() + CONFIG_GRKERNSEC_ACL_TIMEOUT;
55419+
55420+ goto out;
55421+ }
55422+ break;
55423+ case GR_UNSPROLE:
55424+ if (unlikely(!(gr_status & GR_READY))) {
55425+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_UNSPROLEI_ACL_MSG);
55426+ error = -EAGAIN;
55427+ break;
55428+ }
55429+
55430+ if (current->role->roletype & GR_ROLE_SPECIAL) {
55431+ char *p = "";
55432+ int i = 0;
55433+
55434+ read_lock(&tasklist_lock);
55435+ if (current->real_parent) {
55436+ p = current->real_parent->role->rolename;
55437+ i = current->real_parent->acl_role_id;
55438+ }
55439+ read_unlock(&tasklist_lock);
55440+
55441+ gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_UNSPROLES_ACL_MSG, p, i);
55442+ gr_set_acls(1);
55443+ } else {
55444+ error = -EPERM;
55445+ goto out;
55446+ }
55447+ break;
55448+ default:
55449+ gr_log_int(GR_DONT_AUDIT, GR_INVMODE_ACL_MSG, gr_usermode->mode);
55450+ error = -EINVAL;
55451+ break;
55452+ }
55453+
55454+ if (error != -EPERM)
55455+ goto out;
55456+
55457+ if(!(gr_auth_attempts++))
55458+ gr_auth_expires = get_seconds() + CONFIG_GRKERNSEC_ACL_TIMEOUT;
55459+
55460+ out:
55461+ mutex_unlock(&gr_dev_mutex);
55462+ return error;
55463+}
55464+
55465+/* must be called with
55466+ rcu_read_lock();
55467+ read_lock(&tasklist_lock);
55468+ read_lock(&grsec_exec_file_lock);
55469+*/
55470+int gr_apply_subject_to_task(struct task_struct *task)
55471+{
55472+ struct acl_object_label *obj;
55473+ char *tmpname;
55474+ struct acl_subject_label *tmpsubj;
55475+ struct file *filp;
55476+ struct name_entry *nmatch;
55477+
55478+ filp = task->exec_file;
55479+ if (filp == NULL)
55480+ return 0;
55481+
55482+ /* the following is to apply the correct subject
55483+ on binaries running when the RBAC system
55484+ is enabled, when the binaries have been
55485+ replaced or deleted since their execution
55486+ -----
55487+ when the RBAC system starts, the inode/dev
55488+ from exec_file will be one the RBAC system
55489+ is unaware of. It only knows the inode/dev
55490+ of the present file on disk, or the absence
55491+ of it.
55492+ */
55493+ preempt_disable();
55494+ tmpname = gr_to_filename_rbac(filp->f_path.dentry, filp->f_path.mnt);
55495+
55496+ nmatch = lookup_name_entry(tmpname);
55497+ preempt_enable();
55498+ tmpsubj = NULL;
55499+ if (nmatch) {
55500+ if (nmatch->deleted)
55501+ tmpsubj = lookup_acl_subj_label_deleted(nmatch->inode, nmatch->device, task->role);
55502+ else
55503+ tmpsubj = lookup_acl_subj_label(nmatch->inode, nmatch->device, task->role);
55504+ if (tmpsubj != NULL)
55505+ task->acl = tmpsubj;
55506+ }
55507+ if (tmpsubj == NULL)
55508+ task->acl = chk_subj_label(filp->f_path.dentry, filp->f_path.mnt,
55509+ task->role);
55510+ if (task->acl) {
55511+ task->is_writable = 0;
55512+ /* ignore additional mmap checks for processes that are writable
55513+ by the default ACL */
55514+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, default_role->root_label);
55515+ if (unlikely(obj->mode & GR_WRITE))
55516+ task->is_writable = 1;
55517+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, task->role->root_label);
55518+ if (unlikely(obj->mode & GR_WRITE))
55519+ task->is_writable = 1;
55520+
55521+ gr_set_proc_res(task);
55522+
55523+#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
55524+ printk(KERN_ALERT "gr_set_acls for (%s:%d): role:%s, subject:%s\n", task->comm, task->pid, task->role->rolename, task->acl->filename);
55525+#endif
55526+ } else {
55527+ return 1;
55528+ }
55529+
55530+ return 0;
55531+}
55532+
55533+int
55534+gr_set_acls(const int type)
55535+{
55536+ struct task_struct *task, *task2;
55537+ struct acl_role_label *role = current->role;
55538+ __u16 acl_role_id = current->acl_role_id;
55539+ const struct cred *cred;
55540+ int ret;
55541+
55542+ rcu_read_lock();
55543+ read_lock(&tasklist_lock);
55544+ read_lock(&grsec_exec_file_lock);
55545+ do_each_thread(task2, task) {
55546+ /* check to see if we're called from the exit handler,
55547+ if so, only replace ACLs that have inherited the admin
55548+ ACL */
55549+
55550+ if (type && (task->role != role ||
55551+ task->acl_role_id != acl_role_id))
55552+ continue;
55553+
55554+ task->acl_role_id = 0;
55555+ task->acl_sp_role = 0;
55556+
55557+ if (task->exec_file) {
55558+ cred = __task_cred(task);
55559+ task->role = lookup_acl_role_label(task, cred->uid, cred->gid);
55560+ ret = gr_apply_subject_to_task(task);
55561+ if (ret) {
55562+ read_unlock(&grsec_exec_file_lock);
55563+ read_unlock(&tasklist_lock);
55564+ rcu_read_unlock();
55565+ gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_DEFACL_MSG, task->comm, task->pid);
55566+ return ret;
55567+ }
55568+ } else {
55569+ // it's a kernel process
55570+ task->role = kernel_role;
55571+ task->acl = kernel_role->root_label;
55572+#ifdef CONFIG_GRKERNSEC_ACL_HIDEKERN
55573+ task->acl->mode &= ~GR_PROCFIND;
55574+#endif
55575+ }
55576+ } while_each_thread(task2, task);
55577+ read_unlock(&grsec_exec_file_lock);
55578+ read_unlock(&tasklist_lock);
55579+ rcu_read_unlock();
55580+
55581+ return 0;
55582+}
55583+
55584+void
55585+gr_learn_resource(const struct task_struct *task,
55586+ const int res, const unsigned long wanted, const int gt)
55587+{
55588+ struct acl_subject_label *acl;
55589+ const struct cred *cred;
55590+
55591+ if (unlikely((gr_status & GR_READY) &&
55592+ task->acl && (task->acl->mode & (GR_LEARN | GR_INHERITLEARN))))
55593+ goto skip_reslog;
55594+
55595+#ifdef CONFIG_GRKERNSEC_RESLOG
55596+ gr_log_resource(task, res, wanted, gt);
55597+#endif
55598+ skip_reslog:
55599+
55600+ if (unlikely(!(gr_status & GR_READY) || !wanted || res >= GR_NLIMITS))
55601+ return;
55602+
55603+ acl = task->acl;
55604+
55605+ if (likely(!acl || !(acl->mode & (GR_LEARN | GR_INHERITLEARN)) ||
55606+ !(acl->resmask & (1 << (unsigned short) res))))
55607+ return;
55608+
55609+ if (wanted >= acl->res[res].rlim_cur) {
55610+ unsigned long res_add;
55611+
55612+ res_add = wanted;
55613+ switch (res) {
55614+ case RLIMIT_CPU:
55615+ res_add += GR_RLIM_CPU_BUMP;
55616+ break;
55617+ case RLIMIT_FSIZE:
55618+ res_add += GR_RLIM_FSIZE_BUMP;
55619+ break;
55620+ case RLIMIT_DATA:
55621+ res_add += GR_RLIM_DATA_BUMP;
55622+ break;
55623+ case RLIMIT_STACK:
55624+ res_add += GR_RLIM_STACK_BUMP;
55625+ break;
55626+ case RLIMIT_CORE:
55627+ res_add += GR_RLIM_CORE_BUMP;
55628+ break;
55629+ case RLIMIT_RSS:
55630+ res_add += GR_RLIM_RSS_BUMP;
55631+ break;
55632+ case RLIMIT_NPROC:
55633+ res_add += GR_RLIM_NPROC_BUMP;
55634+ break;
55635+ case RLIMIT_NOFILE:
55636+ res_add += GR_RLIM_NOFILE_BUMP;
55637+ break;
55638+ case RLIMIT_MEMLOCK:
55639+ res_add += GR_RLIM_MEMLOCK_BUMP;
55640+ break;
55641+ case RLIMIT_AS:
55642+ res_add += GR_RLIM_AS_BUMP;
55643+ break;
55644+ case RLIMIT_LOCKS:
55645+ res_add += GR_RLIM_LOCKS_BUMP;
55646+ break;
55647+ case RLIMIT_SIGPENDING:
55648+ res_add += GR_RLIM_SIGPENDING_BUMP;
55649+ break;
55650+ case RLIMIT_MSGQUEUE:
55651+ res_add += GR_RLIM_MSGQUEUE_BUMP;
55652+ break;
55653+ case RLIMIT_NICE:
55654+ res_add += GR_RLIM_NICE_BUMP;
55655+ break;
55656+ case RLIMIT_RTPRIO:
55657+ res_add += GR_RLIM_RTPRIO_BUMP;
55658+ break;
55659+ case RLIMIT_RTTIME:
55660+ res_add += GR_RLIM_RTTIME_BUMP;
55661+ break;
55662+ }
55663+
55664+ acl->res[res].rlim_cur = res_add;
55665+
55666+ if (wanted > acl->res[res].rlim_max)
55667+ acl->res[res].rlim_max = res_add;
55668+
55669+ /* only log the subject filename, since resource logging is supported for
55670+ single-subject learning only */
55671+ rcu_read_lock();
55672+ cred = __task_cred(task);
55673+ security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename,
55674+ task->role->roletype, cred->uid, cred->gid, acl->filename,
55675+ acl->filename, acl->res[res].rlim_cur, acl->res[res].rlim_max,
55676+ "", (unsigned long) res, &task->signal->saved_ip);
55677+ rcu_read_unlock();
55678+ }
55679+
55680+ return;
55681+}
55682+
55683+#if defined(CONFIG_PAX_HAVE_ACL_FLAGS) && (defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR))
55684+void
55685+pax_set_initial_flags(struct linux_binprm *bprm)
55686+{
55687+ struct task_struct *task = current;
55688+ struct acl_subject_label *proc;
55689+ unsigned long flags;
55690+
55691+ if (unlikely(!(gr_status & GR_READY)))
55692+ return;
55693+
55694+ flags = pax_get_flags(task);
55695+
55696+ proc = task->acl;
55697+
55698+ if (proc->pax_flags & GR_PAX_DISABLE_PAGEEXEC)
55699+ flags &= ~MF_PAX_PAGEEXEC;
55700+ if (proc->pax_flags & GR_PAX_DISABLE_SEGMEXEC)
55701+ flags &= ~MF_PAX_SEGMEXEC;
55702+ if (proc->pax_flags & GR_PAX_DISABLE_RANDMMAP)
55703+ flags &= ~MF_PAX_RANDMMAP;
55704+ if (proc->pax_flags & GR_PAX_DISABLE_EMUTRAMP)
55705+ flags &= ~MF_PAX_EMUTRAMP;
55706+ if (proc->pax_flags & GR_PAX_DISABLE_MPROTECT)
55707+ flags &= ~MF_PAX_MPROTECT;
55708+
55709+ if (proc->pax_flags & GR_PAX_ENABLE_PAGEEXEC)
55710+ flags |= MF_PAX_PAGEEXEC;
55711+ if (proc->pax_flags & GR_PAX_ENABLE_SEGMEXEC)
55712+ flags |= MF_PAX_SEGMEXEC;
55713+ if (proc->pax_flags & GR_PAX_ENABLE_RANDMMAP)
55714+ flags |= MF_PAX_RANDMMAP;
55715+ if (proc->pax_flags & GR_PAX_ENABLE_EMUTRAMP)
55716+ flags |= MF_PAX_EMUTRAMP;
55717+ if (proc->pax_flags & GR_PAX_ENABLE_MPROTECT)
55718+ flags |= MF_PAX_MPROTECT;
55719+
55720+ pax_set_flags(task, flags);
55721+
55722+ return;
55723+}
55724+#endif
55725+
55726+int
55727+gr_handle_proc_ptrace(struct task_struct *task)
55728+{
55729+ struct file *filp;
55730+ struct task_struct *tmp = task;
55731+ struct task_struct *curtemp = current;
55732+ __u32 retmode;
55733+
55734+#ifndef CONFIG_GRKERNSEC_HARDEN_PTRACE
55735+ if (unlikely(!(gr_status & GR_READY)))
55736+ return 0;
55737+#endif
55738+
55739+ read_lock(&tasklist_lock);
55740+ read_lock(&grsec_exec_file_lock);
55741+ filp = task->exec_file;
55742+
55743+ while (tmp->pid > 0) {
55744+ if (tmp == curtemp)
55745+ break;
55746+ tmp = tmp->real_parent;
55747+ }
55748+
55749+ if (!filp || (tmp->pid == 0 && ((grsec_enable_harden_ptrace && !uid_eq(current_uid(), GLOBAL_ROOT_UID) && !(gr_status & GR_READY)) ||
55750+ ((gr_status & GR_READY) && !(current->acl->mode & GR_RELAXPTRACE))))) {
55751+ read_unlock(&grsec_exec_file_lock);
55752+ read_unlock(&tasklist_lock);
55753+ return 1;
55754+ }
55755+
55756+#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
55757+ if (!(gr_status & GR_READY)) {
55758+ read_unlock(&grsec_exec_file_lock);
55759+ read_unlock(&tasklist_lock);
55760+ return 0;
55761+ }
55762+#endif
55763+
55764+ retmode = gr_search_file(filp->f_path.dentry, GR_NOPTRACE, filp->f_path.mnt);
55765+ read_unlock(&grsec_exec_file_lock);
55766+ read_unlock(&tasklist_lock);
55767+
55768+ if (retmode & GR_NOPTRACE)
55769+ return 1;
55770+
55771+ if (!(current->acl->mode & GR_POVERRIDE) && !(current->role->roletype & GR_ROLE_GOD)
55772+ && (current->acl != task->acl || (current->acl != current->role->root_label
55773+ && current->pid != task->pid)))
55774+ return 1;
55775+
55776+ return 0;
55777+}
55778+
55779+void task_grsec_rbac(struct seq_file *m, struct task_struct *p)
55780+{
55781+ if (unlikely(!(gr_status & GR_READY)))
55782+ return;
55783+
55784+ if (!(current->role->roletype & GR_ROLE_GOD))
55785+ return;
55786+
55787+ seq_printf(m, "RBAC:\t%.64s:%c:%.950s\n",
55788+ p->role->rolename, gr_task_roletype_to_char(p),
55789+ p->acl->filename);
55790+}
55791+
55792+int
55793+gr_handle_ptrace(struct task_struct *task, const long request)
55794+{
55795+ struct task_struct *tmp = task;
55796+ struct task_struct *curtemp = current;
55797+ __u32 retmode;
55798+
55799+#ifndef CONFIG_GRKERNSEC_HARDEN_PTRACE
55800+ if (unlikely(!(gr_status & GR_READY)))
55801+ return 0;
55802+#endif
55803+ if (request == PTRACE_ATTACH || request == PTRACE_SEIZE) {
55804+ read_lock(&tasklist_lock);
55805+ while (tmp->pid > 0) {
55806+ if (tmp == curtemp)
55807+ break;
55808+ tmp = tmp->real_parent;
55809+ }
55810+
55811+ if (tmp->pid == 0 && ((grsec_enable_harden_ptrace && !uid_eq(current_uid(), GLOBAL_ROOT_UID) && !(gr_status & GR_READY)) ||
55812+ ((gr_status & GR_READY) && !(current->acl->mode & GR_RELAXPTRACE)))) {
55813+ read_unlock(&tasklist_lock);
55814+ gr_log_ptrace(GR_DONT_AUDIT, GR_PTRACE_ACL_MSG, task);
55815+ return 1;
55816+ }
55817+ read_unlock(&tasklist_lock);
55818+ }
55819+
55820+#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
55821+ if (!(gr_status & GR_READY))
55822+ return 0;
55823+#endif
55824+
55825+ read_lock(&grsec_exec_file_lock);
55826+ if (unlikely(!task->exec_file)) {
55827+ read_unlock(&grsec_exec_file_lock);
55828+ return 0;
55829+ }
55830+
55831+ retmode = gr_search_file(task->exec_file->f_path.dentry, GR_PTRACERD | GR_NOPTRACE, task->exec_file->f_path.mnt);
55832+ read_unlock(&grsec_exec_file_lock);
55833+
55834+ if (retmode & GR_NOPTRACE) {
55835+ gr_log_ptrace(GR_DONT_AUDIT, GR_PTRACE_ACL_MSG, task);
55836+ return 1;
55837+ }
55838+
55839+ if (retmode & GR_PTRACERD) {
55840+ switch (request) {
55841+ case PTRACE_SEIZE:
55842+ case PTRACE_POKETEXT:
55843+ case PTRACE_POKEDATA:
55844+ case PTRACE_POKEUSR:
55845+#if !defined(CONFIG_PPC32) && !defined(CONFIG_PPC64) && !defined(CONFIG_PARISC) && !defined(CONFIG_ALPHA) && !defined(CONFIG_IA64)
55846+ case PTRACE_SETREGS:
55847+ case PTRACE_SETFPREGS:
55848+#endif
55849+#ifdef CONFIG_X86
55850+ case PTRACE_SETFPXREGS:
55851+#endif
55852+#ifdef CONFIG_ALTIVEC
55853+ case PTRACE_SETVRREGS:
55854+#endif
55855+ return 1;
55856+ default:
55857+ return 0;
55858+ }
55859+ } else if (!(current->acl->mode & GR_POVERRIDE) &&
55860+ !(current->role->roletype & GR_ROLE_GOD) &&
55861+ (current->acl != task->acl)) {
55862+ gr_log_ptrace(GR_DONT_AUDIT, GR_PTRACE_ACL_MSG, task);
55863+ return 1;
55864+ }
55865+
55866+ return 0;
55867+}
55868+
55869+static int is_writable_mmap(const struct file *filp)
55870+{
55871+ struct task_struct *task = current;
55872+ struct acl_object_label *obj, *obj2;
55873+
55874+ if (gr_status & GR_READY && !(task->acl->mode & GR_OVERRIDE) &&
55875+ !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))) {
55876+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, default_role->root_label);
55877+ obj2 = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt,
55878+ task->role->root_label);
55879+ if (unlikely((obj->mode & GR_WRITE) || (obj2->mode & GR_WRITE))) {
55880+ gr_log_fs_generic(GR_DONT_AUDIT, GR_WRITLIB_ACL_MSG, filp->f_path.dentry, filp->f_path.mnt);
55881+ return 1;
55882+ }
55883+ }
55884+ return 0;
55885+}
55886+
55887+int
55888+gr_acl_handle_mmap(const struct file *file, const unsigned long prot)
55889+{
55890+ __u32 mode;
55891+
55892+ if (unlikely(!file || !(prot & PROT_EXEC)))
55893+ return 1;
55894+
55895+ if (is_writable_mmap(file))
55896+ return 0;
55897+
55898+ mode =
55899+ gr_search_file(file->f_path.dentry,
55900+ GR_EXEC | GR_AUDIT_EXEC | GR_SUPPRESS,
55901+ file->f_path.mnt);
55902+
55903+ if (!gr_tpe_allow(file))
55904+ return 0;
55905+
55906+ if (unlikely(!(mode & GR_EXEC) && !(mode & GR_SUPPRESS))) {
55907+ gr_log_fs_rbac_generic(GR_DONT_AUDIT, GR_MMAP_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
55908+ return 0;
55909+ } else if (unlikely(!(mode & GR_EXEC))) {
55910+ return 0;
55911+ } else if (unlikely(mode & GR_EXEC && mode & GR_AUDIT_EXEC)) {
55912+ gr_log_fs_rbac_generic(GR_DO_AUDIT, GR_MMAP_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
55913+ return 1;
55914+ }
55915+
55916+ return 1;
55917+}
55918+
55919+int
55920+gr_acl_handle_mprotect(const struct file *file, const unsigned long prot)
55921+{
55922+ __u32 mode;
55923+
55924+ if (unlikely(!file || !(prot & PROT_EXEC)))
55925+ return 1;
55926+
55927+ if (is_writable_mmap(file))
55928+ return 0;
55929+
55930+ mode =
55931+ gr_search_file(file->f_path.dentry,
55932+ GR_EXEC | GR_AUDIT_EXEC | GR_SUPPRESS,
55933+ file->f_path.mnt);
55934+
55935+ if (!gr_tpe_allow(file))
55936+ return 0;
55937+
55938+ if (unlikely(!(mode & GR_EXEC) && !(mode & GR_SUPPRESS))) {
55939+ gr_log_fs_rbac_generic(GR_DONT_AUDIT, GR_MPROTECT_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
55940+ return 0;
55941+ } else if (unlikely(!(mode & GR_EXEC))) {
55942+ return 0;
55943+ } else if (unlikely(mode & GR_EXEC && mode & GR_AUDIT_EXEC)) {
55944+ gr_log_fs_rbac_generic(GR_DO_AUDIT, GR_MPROTECT_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
55945+ return 1;
55946+ }
55947+
55948+ return 1;
55949+}
55950+
55951+void
55952+gr_acl_handle_psacct(struct task_struct *task, const long code)
55953+{
55954+ unsigned long runtime;
55955+ unsigned long cputime;
55956+ unsigned int wday, cday;
55957+ __u8 whr, chr;
55958+ __u8 wmin, cmin;
55959+ __u8 wsec, csec;
55960+ struct timespec timeval;
55961+
55962+ if (unlikely(!(gr_status & GR_READY) || !task->acl ||
55963+ !(task->acl->mode & GR_PROCACCT)))
55964+ return;
55965+
55966+ do_posix_clock_monotonic_gettime(&timeval);
55967+ runtime = timeval.tv_sec - task->start_time.tv_sec;
55968+ wday = runtime / (3600 * 24);
55969+ runtime -= wday * (3600 * 24);
55970+ whr = runtime / 3600;
55971+ runtime -= whr * 3600;
55972+ wmin = runtime / 60;
55973+ runtime -= wmin * 60;
55974+ wsec = runtime;
55975+
55976+ cputime = (task->utime + task->stime) / HZ;
55977+ cday = cputime / (3600 * 24);
55978+ cputime -= cday * (3600 * 24);
55979+ chr = cputime / 3600;
55980+ cputime -= chr * 3600;
55981+ cmin = cputime / 60;
55982+ cputime -= cmin * 60;
55983+ csec = cputime;
55984+
55985+ gr_log_procacct(GR_DO_AUDIT, GR_ACL_PROCACCT_MSG, task, wday, whr, wmin, wsec, cday, chr, cmin, csec, code);
55986+
55987+ return;
55988+}
55989+
55990+void gr_set_kernel_label(struct task_struct *task)
55991+{
55992+ if (gr_status & GR_READY) {
55993+ task->role = kernel_role;
55994+ task->acl = kernel_role->root_label;
55995+ }
55996+ return;
55997+}
55998+
55999+#ifdef CONFIG_TASKSTATS
56000+int gr_is_taskstats_denied(int pid)
56001+{
56002+ struct task_struct *task;
56003+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
56004+ const struct cred *cred;
56005+#endif
56006+ int ret = 0;
56007+
56008+ /* restrict taskstats viewing to un-chrooted root users
56009+ who have the 'view' subject flag if the RBAC system is enabled
56010+ */
56011+
56012+ rcu_read_lock();
56013+ read_lock(&tasklist_lock);
56014+ task = find_task_by_vpid(pid);
56015+ if (task) {
56016+#ifdef CONFIG_GRKERNSEC_CHROOT
56017+ if (proc_is_chrooted(task))
56018+ ret = -EACCES;
56019+#endif
56020+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
56021+ cred = __task_cred(task);
56022+#ifdef CONFIG_GRKERNSEC_PROC_USER
56023+ if (!uid_eq(cred->uid, GLOBAL_ROOT_UID))
56024+ ret = -EACCES;
56025+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
56026+ if (!uid_eq(cred->uid, GLOBAL_ROOT_UID) && !groups_search(cred->group_info, grsec_proc_gid))
56027+ ret = -EACCES;
56028+#endif
56029+#endif
56030+ if (gr_status & GR_READY) {
56031+ if (!(task->acl->mode & GR_VIEW))
56032+ ret = -EACCES;
56033+ }
56034+ } else
56035+ ret = -ENOENT;
56036+
56037+ read_unlock(&tasklist_lock);
56038+ rcu_read_unlock();
56039+
56040+ return ret;
56041+}
56042+#endif
56043+
56044+/* AUXV entries are filled via a descendant of search_binary_handler
56045+ after we've already applied the subject for the target
56046+*/
56047+int gr_acl_enable_at_secure(void)
56048+{
56049+ if (unlikely(!(gr_status & GR_READY)))
56050+ return 0;
56051+
56052+ if (current->acl->mode & GR_ATSECURE)
56053+ return 1;
56054+
56055+ return 0;
56056+}
56057+
56058+int gr_acl_handle_filldir(const struct file *file, const char *name, const unsigned int namelen, const ino_t ino)
56059+{
56060+ struct task_struct *task = current;
56061+ struct dentry *dentry = file->f_path.dentry;
56062+ struct vfsmount *mnt = file->f_path.mnt;
56063+ struct acl_object_label *obj, *tmp;
56064+ struct acl_subject_label *subj;
56065+ unsigned int bufsize;
56066+ int is_not_root;
56067+ char *path;
56068+ dev_t dev = __get_dev(dentry);
56069+
56070+ if (unlikely(!(gr_status & GR_READY)))
56071+ return 1;
56072+
56073+ if (task->acl->mode & (GR_LEARN | GR_INHERITLEARN))
56074+ return 1;
56075+
56076+ /* ignore Eric Biederman */
56077+ if (IS_PRIVATE(dentry->d_inode))
56078+ return 1;
56079+
56080+ subj = task->acl;
56081+ read_lock(&gr_inode_lock);
56082+ do {
56083+ obj = lookup_acl_obj_label(ino, dev, subj);
56084+ if (obj != NULL) {
56085+ read_unlock(&gr_inode_lock);
56086+ return (obj->mode & GR_FIND) ? 1 : 0;
56087+ }
56088+ } while ((subj = subj->parent_subject));
56089+ read_unlock(&gr_inode_lock);
56090+
56091+ /* this is purely an optimization since we're looking for an object
56092+ for the directory we're doing a readdir on
56093+ if it's possible for any globbed object to match the entry we're
56094+ filling into the directory, then the object we find here will be
56095+ an anchor point with attached globbed objects
56096+ */
56097+ obj = chk_obj_label_noglob(dentry, mnt, task->acl);
56098+ if (obj->globbed == NULL)
56099+ return (obj->mode & GR_FIND) ? 1 : 0;
56100+
56101+ is_not_root = ((obj->filename[0] == '/') &&
56102+ (obj->filename[1] == '\0')) ? 0 : 1;
56103+ bufsize = PAGE_SIZE - namelen - is_not_root;
56104+
56105+ /* check bufsize > PAGE_SIZE || bufsize == 0 */
56106+ if (unlikely((bufsize - 1) > (PAGE_SIZE - 1)))
56107+ return 1;
56108+
56109+ preempt_disable();
56110+ path = d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0], smp_processor_id()),
56111+ bufsize);
56112+
56113+ bufsize = strlen(path);
56114+
56115+ /* if base is "/", don't append an additional slash */
56116+ if (is_not_root)
56117+ *(path + bufsize) = '/';
56118+ memcpy(path + bufsize + is_not_root, name, namelen);
56119+ *(path + bufsize + namelen + is_not_root) = '\0';
56120+
56121+ tmp = obj->globbed;
56122+ while (tmp) {
56123+ if (!glob_match(tmp->filename, path)) {
56124+ preempt_enable();
56125+ return (tmp->mode & GR_FIND) ? 1 : 0;
56126+ }
56127+ tmp = tmp->next;
56128+ }
56129+ preempt_enable();
56130+ return (obj->mode & GR_FIND) ? 1 : 0;
56131+}
56132+
56133+void gr_put_exec_file(struct task_struct *task)
56134+{
56135+ struct file *filp;
56136+
56137+ write_lock(&grsec_exec_file_lock);
56138+ filp = task->exec_file;
56139+ task->exec_file = NULL;
56140+ write_unlock(&grsec_exec_file_lock);
56141+
56142+ if (filp)
56143+ fput(filp);
56144+
56145+ return;
56146+}
56147+
56148+
56149+#ifdef CONFIG_NETFILTER_XT_MATCH_GRADM_MODULE
56150+EXPORT_SYMBOL(gr_acl_is_enabled);
56151+#endif
56152+EXPORT_SYMBOL(gr_learn_resource);
56153+EXPORT_SYMBOL(gr_set_kernel_label);
56154+#ifdef CONFIG_SECURITY
56155+EXPORT_SYMBOL(gr_check_user_change);
56156+EXPORT_SYMBOL(gr_check_group_change);
56157+#endif
56158+
56159diff --git a/grsecurity/gracl_alloc.c b/grsecurity/gracl_alloc.c
56160new file mode 100644
56161index 0000000..34fefda
56162--- /dev/null
56163+++ b/grsecurity/gracl_alloc.c
56164@@ -0,0 +1,105 @@
56165+#include <linux/kernel.h>
56166+#include <linux/mm.h>
56167+#include <linux/slab.h>
56168+#include <linux/vmalloc.h>
56169+#include <linux/gracl.h>
56170+#include <linux/grsecurity.h>
56171+
56172+static unsigned long alloc_stack_next = 1;
56173+static unsigned long alloc_stack_size = 1;
56174+static void **alloc_stack;
56175+
56176+static __inline__ int
56177+alloc_pop(void)
56178+{
56179+ if (alloc_stack_next == 1)
56180+ return 0;
56181+
56182+ kfree(alloc_stack[alloc_stack_next - 2]);
56183+
56184+ alloc_stack_next--;
56185+
56186+ return 1;
56187+}
56188+
56189+static __inline__ int
56190+alloc_push(void *buf)
56191+{
56192+ if (alloc_stack_next >= alloc_stack_size)
56193+ return 1;
56194+
56195+ alloc_stack[alloc_stack_next - 1] = buf;
56196+
56197+ alloc_stack_next++;
56198+
56199+ return 0;
56200+}
56201+
56202+void *
56203+acl_alloc(unsigned long len)
56204+{
56205+ void *ret = NULL;
56206+
56207+ if (!len || len > PAGE_SIZE)
56208+ goto out;
56209+
56210+ ret = kmalloc(len, GFP_KERNEL);
56211+
56212+ if (ret) {
56213+ if (alloc_push(ret)) {
56214+ kfree(ret);
56215+ ret = NULL;
56216+ }
56217+ }
56218+
56219+out:
56220+ return ret;
56221+}
56222+
56223+void *
56224+acl_alloc_num(unsigned long num, unsigned long len)
56225+{
56226+ if (!len || (num > (PAGE_SIZE / len)))
56227+ return NULL;
56228+
56229+ return acl_alloc(num * len);
56230+}
56231+
56232+void
56233+acl_free_all(void)
56234+{
56235+ if (gr_acl_is_enabled() || !alloc_stack)
56236+ return;
56237+
56238+ while (alloc_pop()) ;
56239+
56240+ if (alloc_stack) {
56241+ if ((alloc_stack_size * sizeof (void *)) <= PAGE_SIZE)
56242+ kfree(alloc_stack);
56243+ else
56244+ vfree(alloc_stack);
56245+ }
56246+
56247+ alloc_stack = NULL;
56248+ alloc_stack_size = 1;
56249+ alloc_stack_next = 1;
56250+
56251+ return;
56252+}
56253+
56254+int
56255+acl_alloc_stack_init(unsigned long size)
56256+{
56257+ if ((size * sizeof (void *)) <= PAGE_SIZE)
56258+ alloc_stack =
56259+ (void **) kmalloc(size * sizeof (void *), GFP_KERNEL);
56260+ else
56261+ alloc_stack = (void **) vmalloc(size * sizeof (void *));
56262+
56263+ alloc_stack_size = size;
56264+
56265+ if (!alloc_stack)
56266+ return 0;
56267+ else
56268+ return 1;
56269+}
56270diff --git a/grsecurity/gracl_cap.c b/grsecurity/gracl_cap.c
56271new file mode 100644
56272index 0000000..6d21049
56273--- /dev/null
56274+++ b/grsecurity/gracl_cap.c
56275@@ -0,0 +1,110 @@
56276+#include <linux/kernel.h>
56277+#include <linux/module.h>
56278+#include <linux/sched.h>
56279+#include <linux/gracl.h>
56280+#include <linux/grsecurity.h>
56281+#include <linux/grinternal.h>
56282+
56283+extern const char *captab_log[];
56284+extern int captab_log_entries;
56285+
56286+int gr_task_acl_is_capable(const struct task_struct *task, const struct cred *cred, const int cap)
56287+{
56288+ struct acl_subject_label *curracl;
56289+ kernel_cap_t cap_drop = __cap_empty_set, cap_mask = __cap_empty_set;
56290+ kernel_cap_t cap_audit = __cap_empty_set;
56291+
56292+ if (!gr_acl_is_enabled())
56293+ return 1;
56294+
56295+ curracl = task->acl;
56296+
56297+ cap_drop = curracl->cap_lower;
56298+ cap_mask = curracl->cap_mask;
56299+ cap_audit = curracl->cap_invert_audit;
56300+
56301+ while ((curracl = curracl->parent_subject)) {
56302+ /* if the cap isn't specified in the current computed mask but is specified in the
56303+ current level subject, and is lowered in the current level subject, then add
56304+ it to the set of dropped capabilities
56305+ otherwise, add the current level subject's mask to the current computed mask
56306+ */
56307+ if (!cap_raised(cap_mask, cap) && cap_raised(curracl->cap_mask, cap)) {
56308+ cap_raise(cap_mask, cap);
56309+ if (cap_raised(curracl->cap_lower, cap))
56310+ cap_raise(cap_drop, cap);
56311+ if (cap_raised(curracl->cap_invert_audit, cap))
56312+ cap_raise(cap_audit, cap);
56313+ }
56314+ }
56315+
56316+ if (!cap_raised(cap_drop, cap)) {
56317+ if (cap_raised(cap_audit, cap))
56318+ gr_log_cap(GR_DO_AUDIT, GR_CAP_ACL_MSG2, task, captab_log[cap]);
56319+ return 1;
56320+ }
56321+
56322+ curracl = task->acl;
56323+
56324+ if ((curracl->mode & (GR_LEARN | GR_INHERITLEARN))
56325+ && cap_raised(cred->cap_effective, cap)) {
56326+ security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename,
56327+ task->role->roletype, cred->uid,
56328+ cred->gid, task->exec_file ?
56329+ gr_to_filename(task->exec_file->f_path.dentry,
56330+ task->exec_file->f_path.mnt) : curracl->filename,
56331+ curracl->filename, 0UL,
56332+ 0UL, "", (unsigned long) cap, &task->signal->saved_ip);
56333+ return 1;
56334+ }
56335+
56336+ if ((cap >= 0) && (cap < captab_log_entries) && cap_raised(cred->cap_effective, cap) && !cap_raised(cap_audit, cap))
56337+ gr_log_cap(GR_DONT_AUDIT, GR_CAP_ACL_MSG, task, captab_log[cap]);
56338+
56339+ return 0;
56340+}
56341+
56342+int
56343+gr_acl_is_capable(const int cap)
56344+{
56345+ return gr_task_acl_is_capable(current, current_cred(), cap);
56346+}
56347+
56348+int gr_task_acl_is_capable_nolog(const struct task_struct *task, const int cap)
56349+{
56350+ struct acl_subject_label *curracl;
56351+ kernel_cap_t cap_drop = __cap_empty_set, cap_mask = __cap_empty_set;
56352+
56353+ if (!gr_acl_is_enabled())
56354+ return 1;
56355+
56356+ curracl = task->acl;
56357+
56358+ cap_drop = curracl->cap_lower;
56359+ cap_mask = curracl->cap_mask;
56360+
56361+ while ((curracl = curracl->parent_subject)) {
56362+ /* if the cap isn't specified in the current computed mask but is specified in the
56363+ current level subject, and is lowered in the current level subject, then add
56364+ it to the set of dropped capabilities
56365+ otherwise, add the current level subject's mask to the current computed mask
56366+ */
56367+ if (!cap_raised(cap_mask, cap) && cap_raised(curracl->cap_mask, cap)) {
56368+ cap_raise(cap_mask, cap);
56369+ if (cap_raised(curracl->cap_lower, cap))
56370+ cap_raise(cap_drop, cap);
56371+ }
56372+ }
56373+
56374+ if (!cap_raised(cap_drop, cap))
56375+ return 1;
56376+
56377+ return 0;
56378+}
56379+
56380+int
56381+gr_acl_is_capable_nolog(const int cap)
56382+{
56383+ return gr_task_acl_is_capable_nolog(current, cap);
56384+}
56385+
56386diff --git a/grsecurity/gracl_fs.c b/grsecurity/gracl_fs.c
56387new file mode 100644
56388index 0000000..d28e241
56389--- /dev/null
56390+++ b/grsecurity/gracl_fs.c
56391@@ -0,0 +1,437 @@
56392+#include <linux/kernel.h>
56393+#include <linux/sched.h>
56394+#include <linux/types.h>
56395+#include <linux/fs.h>
56396+#include <linux/file.h>
56397+#include <linux/stat.h>
56398+#include <linux/grsecurity.h>
56399+#include <linux/grinternal.h>
56400+#include <linux/gracl.h>
56401+
56402+umode_t
56403+gr_acl_umask(void)
56404+{
56405+ if (unlikely(!gr_acl_is_enabled()))
56406+ return 0;
56407+
56408+ return current->role->umask;
56409+}
56410+
56411+__u32
56412+gr_acl_handle_hidden_file(const struct dentry * dentry,
56413+ const struct vfsmount * mnt)
56414+{
56415+ __u32 mode;
56416+
56417+ if (unlikely(!dentry->d_inode))
56418+ return GR_FIND;
56419+
56420+ mode =
56421+ gr_search_file(dentry, GR_FIND | GR_AUDIT_FIND | GR_SUPPRESS, mnt);
56422+
56423+ if (unlikely(mode & GR_FIND && mode & GR_AUDIT_FIND)) {
56424+ gr_log_fs_rbac_generic(GR_DO_AUDIT, GR_HIDDEN_ACL_MSG, dentry, mnt);
56425+ return mode;
56426+ } else if (unlikely(!(mode & GR_FIND) && !(mode & GR_SUPPRESS))) {
56427+ gr_log_fs_rbac_generic(GR_DONT_AUDIT, GR_HIDDEN_ACL_MSG, dentry, mnt);
56428+ return 0;
56429+ } else if (unlikely(!(mode & GR_FIND)))
56430+ return 0;
56431+
56432+ return GR_FIND;
56433+}
56434+
56435+__u32
56436+gr_acl_handle_open(const struct dentry * dentry, const struct vfsmount * mnt,
56437+ int acc_mode)
56438+{
56439+ __u32 reqmode = GR_FIND;
56440+ __u32 mode;
56441+
56442+ if (unlikely(!dentry->d_inode))
56443+ return reqmode;
56444+
56445+ if (acc_mode & MAY_APPEND)
56446+ reqmode |= GR_APPEND;
56447+ else if (acc_mode & MAY_WRITE)
56448+ reqmode |= GR_WRITE;
56449+ if ((acc_mode & MAY_READ) && !S_ISDIR(dentry->d_inode->i_mode))
56450+ reqmode |= GR_READ;
56451+
56452+ mode =
56453+ gr_search_file(dentry, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS,
56454+ mnt);
56455+
56456+ if (unlikely(((mode & reqmode) == reqmode) && mode & GR_AUDITS)) {
56457+ gr_log_fs_rbac_mode2(GR_DO_AUDIT, GR_OPEN_ACL_MSG, dentry, mnt,
56458+ reqmode & GR_READ ? " reading" : "",
56459+ reqmode & GR_WRITE ? " writing" : reqmode &
56460+ GR_APPEND ? " appending" : "");
56461+ return reqmode;
56462+ } else
56463+ if (unlikely((mode & reqmode) != reqmode && !(mode & GR_SUPPRESS)))
56464+ {
56465+ gr_log_fs_rbac_mode2(GR_DONT_AUDIT, GR_OPEN_ACL_MSG, dentry, mnt,
56466+ reqmode & GR_READ ? " reading" : "",
56467+ reqmode & GR_WRITE ? " writing" : reqmode &
56468+ GR_APPEND ? " appending" : "");
56469+ return 0;
56470+ } else if (unlikely((mode & reqmode) != reqmode))
56471+ return 0;
56472+
56473+ return reqmode;
56474+}
56475+
56476+__u32
56477+gr_acl_handle_creat(const struct dentry * dentry,
56478+ const struct dentry * p_dentry,
56479+ const struct vfsmount * p_mnt, int open_flags, int acc_mode,
56480+ const int imode)
56481+{
56482+ __u32 reqmode = GR_WRITE | GR_CREATE;
56483+ __u32 mode;
56484+
56485+ if (acc_mode & MAY_APPEND)
56486+ reqmode |= GR_APPEND;
56487+ // if a directory was required or the directory already exists, then
56488+ // don't count this open as a read
56489+ if ((acc_mode & MAY_READ) &&
56490+ !((open_flags & O_DIRECTORY) || (dentry->d_inode && S_ISDIR(dentry->d_inode->i_mode))))
56491+ reqmode |= GR_READ;
56492+ if ((open_flags & O_CREAT) &&
56493+ ((imode & S_ISUID) || ((imode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))))
56494+ reqmode |= GR_SETID;
56495+
56496+ mode =
56497+ gr_check_create(dentry, p_dentry, p_mnt,
56498+ reqmode | to_gr_audit(reqmode) | GR_SUPPRESS);
56499+
56500+ if (unlikely(((mode & reqmode) == reqmode) && mode & GR_AUDITS)) {
56501+ gr_log_fs_rbac_mode2(GR_DO_AUDIT, GR_CREATE_ACL_MSG, dentry, p_mnt,
56502+ reqmode & GR_READ ? " reading" : "",
56503+ reqmode & GR_WRITE ? " writing" : reqmode &
56504+ GR_APPEND ? " appending" : "");
56505+ return reqmode;
56506+ } else
56507+ if (unlikely((mode & reqmode) != reqmode && !(mode & GR_SUPPRESS)))
56508+ {
56509+ gr_log_fs_rbac_mode2(GR_DONT_AUDIT, GR_CREATE_ACL_MSG, dentry, p_mnt,
56510+ reqmode & GR_READ ? " reading" : "",
56511+ reqmode & GR_WRITE ? " writing" : reqmode &
56512+ GR_APPEND ? " appending" : "");
56513+ return 0;
56514+ } else if (unlikely((mode & reqmode) != reqmode))
56515+ return 0;
56516+
56517+ return reqmode;
56518+}
56519+
56520+__u32
56521+gr_acl_handle_access(const struct dentry * dentry, const struct vfsmount * mnt,
56522+ const int fmode)
56523+{
56524+ __u32 mode, reqmode = GR_FIND;
56525+
56526+ if ((fmode & S_IXOTH) && !S_ISDIR(dentry->d_inode->i_mode))
56527+ reqmode |= GR_EXEC;
56528+ if (fmode & S_IWOTH)
56529+ reqmode |= GR_WRITE;
56530+ if (fmode & S_IROTH)
56531+ reqmode |= GR_READ;
56532+
56533+ mode =
56534+ gr_search_file(dentry, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS,
56535+ mnt);
56536+
56537+ if (unlikely(((mode & reqmode) == reqmode) && mode & GR_AUDITS)) {
56538+ gr_log_fs_rbac_mode3(GR_DO_AUDIT, GR_ACCESS_ACL_MSG, dentry, mnt,
56539+ reqmode & GR_READ ? " reading" : "",
56540+ reqmode & GR_WRITE ? " writing" : "",
56541+ reqmode & GR_EXEC ? " executing" : "");
56542+ return reqmode;
56543+ } else
56544+ if (unlikely((mode & reqmode) != reqmode && !(mode & GR_SUPPRESS)))
56545+ {
56546+ gr_log_fs_rbac_mode3(GR_DONT_AUDIT, GR_ACCESS_ACL_MSG, dentry, mnt,
56547+ reqmode & GR_READ ? " reading" : "",
56548+ reqmode & GR_WRITE ? " writing" : "",
56549+ reqmode & GR_EXEC ? " executing" : "");
56550+ return 0;
56551+ } else if (unlikely((mode & reqmode) != reqmode))
56552+ return 0;
56553+
56554+ return reqmode;
56555+}
56556+
56557+static __u32 generic_fs_handler(const struct dentry *dentry, const struct vfsmount *mnt, __u32 reqmode, const char *fmt)
56558+{
56559+ __u32 mode;
56560+
56561+ mode = gr_search_file(dentry, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS, mnt);
56562+
56563+ if (unlikely(((mode & (reqmode)) == (reqmode)) && mode & GR_AUDITS)) {
56564+ gr_log_fs_rbac_generic(GR_DO_AUDIT, fmt, dentry, mnt);
56565+ return mode;
56566+ } else if (unlikely((mode & (reqmode)) != (reqmode) && !(mode & GR_SUPPRESS))) {
56567+ gr_log_fs_rbac_generic(GR_DONT_AUDIT, fmt, dentry, mnt);
56568+ return 0;
56569+ } else if (unlikely((mode & (reqmode)) != (reqmode)))
56570+ return 0;
56571+
56572+ return (reqmode);
56573+}
56574+
56575+__u32
56576+gr_acl_handle_rmdir(const struct dentry * dentry, const struct vfsmount * mnt)
56577+{
56578+ return generic_fs_handler(dentry, mnt, GR_WRITE | GR_DELETE , GR_RMDIR_ACL_MSG);
56579+}
56580+
56581+__u32
56582+gr_acl_handle_unlink(const struct dentry *dentry, const struct vfsmount *mnt)
56583+{
56584+ return generic_fs_handler(dentry, mnt, GR_WRITE | GR_DELETE , GR_UNLINK_ACL_MSG);
56585+}
56586+
56587+__u32
56588+gr_acl_handle_truncate(const struct dentry *dentry, const struct vfsmount *mnt)
56589+{
56590+ return generic_fs_handler(dentry, mnt, GR_WRITE, GR_TRUNCATE_ACL_MSG);
56591+}
56592+
56593+__u32
56594+gr_acl_handle_utime(const struct dentry *dentry, const struct vfsmount *mnt)
56595+{
56596+ return generic_fs_handler(dentry, mnt, GR_WRITE, GR_ATIME_ACL_MSG);
56597+}
56598+
56599+__u32
56600+gr_acl_handle_chmod(const struct dentry *dentry, const struct vfsmount *mnt,
56601+ umode_t *modeptr)
56602+{
56603+ umode_t mode;
56604+
56605+ *modeptr &= ~gr_acl_umask();
56606+ mode = *modeptr;
56607+
56608+ if (unlikely(dentry->d_inode && S_ISSOCK(dentry->d_inode->i_mode)))
56609+ return 1;
56610+
56611+ if (unlikely(dentry->d_inode && !S_ISDIR(dentry->d_inode->i_mode) &&
56612+ ((mode & S_ISUID) || ((mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))))) {
56613+ return generic_fs_handler(dentry, mnt, GR_WRITE | GR_SETID,
56614+ GR_CHMOD_ACL_MSG);
56615+ } else {
56616+ return generic_fs_handler(dentry, mnt, GR_WRITE, GR_CHMOD_ACL_MSG);
56617+ }
56618+}
56619+
56620+__u32
56621+gr_acl_handle_chown(const struct dentry *dentry, const struct vfsmount *mnt)
56622+{
56623+ return generic_fs_handler(dentry, mnt, GR_WRITE, GR_CHOWN_ACL_MSG);
56624+}
56625+
56626+__u32
56627+gr_acl_handle_setxattr(const struct dentry *dentry, const struct vfsmount *mnt)
56628+{
56629+ return generic_fs_handler(dentry, mnt, GR_WRITE, GR_SETXATTR_ACL_MSG);
56630+}
56631+
56632+__u32
56633+gr_acl_handle_execve(const struct dentry *dentry, const struct vfsmount *mnt)
56634+{
56635+ return generic_fs_handler(dentry, mnt, GR_EXEC, GR_EXEC_ACL_MSG);
56636+}
56637+
56638+__u32
56639+gr_acl_handle_unix(const struct dentry *dentry, const struct vfsmount *mnt)
56640+{
56641+ return generic_fs_handler(dentry, mnt, GR_READ | GR_WRITE,
56642+ GR_UNIXCONNECT_ACL_MSG);
56643+}
56644+
56645+/* hardlinks require at minimum create and link permission,
56646+ any additional privilege required is based on the
56647+ privilege of the file being linked to
56648+*/
56649+__u32
56650+gr_acl_handle_link(const struct dentry * new_dentry,
56651+ const struct dentry * parent_dentry,
56652+ const struct vfsmount * parent_mnt,
56653+ const struct dentry * old_dentry,
56654+ const struct vfsmount * old_mnt, const char *to)
56655+{
56656+ __u32 mode;
56657+ __u32 needmode = GR_CREATE | GR_LINK;
56658+ __u32 needaudit = GR_AUDIT_CREATE | GR_AUDIT_LINK;
56659+
56660+ mode =
56661+ gr_check_link(new_dentry, parent_dentry, parent_mnt, old_dentry,
56662+ old_mnt);
56663+
56664+ if (unlikely(((mode & needmode) == needmode) && (mode & needaudit))) {
56665+ gr_log_fs_rbac_str(GR_DO_AUDIT, GR_LINK_ACL_MSG, old_dentry, old_mnt, to);
56666+ return mode;
56667+ } else if (unlikely(((mode & needmode) != needmode) && !(mode & GR_SUPPRESS))) {
56668+ gr_log_fs_rbac_str(GR_DONT_AUDIT, GR_LINK_ACL_MSG, old_dentry, old_mnt, to);
56669+ return 0;
56670+ } else if (unlikely((mode & needmode) != needmode))
56671+ return 0;
56672+
56673+ return 1;
56674+}
56675+
56676+__u32
56677+gr_acl_handle_symlink(const struct dentry * new_dentry,
56678+ const struct dentry * parent_dentry,
56679+ const struct vfsmount * parent_mnt, const char *from)
56680+{
56681+ __u32 needmode = GR_WRITE | GR_CREATE;
56682+ __u32 mode;
56683+
56684+ mode =
56685+ gr_check_create(new_dentry, parent_dentry, parent_mnt,
56686+ GR_CREATE | GR_AUDIT_CREATE |
56687+ GR_WRITE | GR_AUDIT_WRITE | GR_SUPPRESS);
56688+
56689+ if (unlikely(mode & GR_WRITE && mode & GR_AUDITS)) {
56690+ gr_log_fs_str_rbac(GR_DO_AUDIT, GR_SYMLINK_ACL_MSG, from, new_dentry, parent_mnt);
56691+ return mode;
56692+ } else if (unlikely(((mode & needmode) != needmode) && !(mode & GR_SUPPRESS))) {
56693+ gr_log_fs_str_rbac(GR_DONT_AUDIT, GR_SYMLINK_ACL_MSG, from, new_dentry, parent_mnt);
56694+ return 0;
56695+ } else if (unlikely((mode & needmode) != needmode))
56696+ return 0;
56697+
56698+ return (GR_WRITE | GR_CREATE);
56699+}
56700+
56701+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)
56702+{
56703+ __u32 mode;
56704+
56705+ mode = gr_check_create(new_dentry, parent_dentry, parent_mnt, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS);
56706+
56707+ if (unlikely(((mode & (reqmode)) == (reqmode)) && mode & GR_AUDITS)) {
56708+ gr_log_fs_rbac_generic(GR_DO_AUDIT, fmt, new_dentry, parent_mnt);
56709+ return mode;
56710+ } else if (unlikely((mode & (reqmode)) != (reqmode) && !(mode & GR_SUPPRESS))) {
56711+ gr_log_fs_rbac_generic(GR_DONT_AUDIT, fmt, new_dentry, parent_mnt);
56712+ return 0;
56713+ } else if (unlikely((mode & (reqmode)) != (reqmode)))
56714+ return 0;
56715+
56716+ return (reqmode);
56717+}
56718+
56719+__u32
56720+gr_acl_handle_mknod(const struct dentry * new_dentry,
56721+ const struct dentry * parent_dentry,
56722+ const struct vfsmount * parent_mnt,
56723+ const int mode)
56724+{
56725+ __u32 reqmode = GR_WRITE | GR_CREATE;
56726+ if (unlikely((mode & S_ISUID) || ((mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))))
56727+ reqmode |= GR_SETID;
56728+
56729+ return generic_fs_create_handler(new_dentry, parent_dentry, parent_mnt,
56730+ reqmode, GR_MKNOD_ACL_MSG);
56731+}
56732+
56733+__u32
56734+gr_acl_handle_mkdir(const struct dentry *new_dentry,
56735+ const struct dentry *parent_dentry,
56736+ const struct vfsmount *parent_mnt)
56737+{
56738+ return generic_fs_create_handler(new_dentry, parent_dentry, parent_mnt,
56739+ GR_WRITE | GR_CREATE, GR_MKDIR_ACL_MSG);
56740+}
56741+
56742+#define RENAME_CHECK_SUCCESS(old, new) \
56743+ (((old & (GR_WRITE | GR_READ)) == (GR_WRITE | GR_READ)) && \
56744+ ((new & (GR_WRITE | GR_READ)) == (GR_WRITE | GR_READ)))
56745+
56746+int
56747+gr_acl_handle_rename(struct dentry *new_dentry,
56748+ struct dentry *parent_dentry,
56749+ const struct vfsmount *parent_mnt,
56750+ struct dentry *old_dentry,
56751+ struct inode *old_parent_inode,
56752+ struct vfsmount *old_mnt, const char *newname)
56753+{
56754+ __u32 comp1, comp2;
56755+ int error = 0;
56756+
56757+ if (unlikely(!gr_acl_is_enabled()))
56758+ return 0;
56759+
56760+ if (!new_dentry->d_inode) {
56761+ comp1 = gr_check_create(new_dentry, parent_dentry, parent_mnt,
56762+ GR_READ | GR_WRITE | GR_CREATE | GR_AUDIT_READ |
56763+ GR_AUDIT_WRITE | GR_AUDIT_CREATE | GR_SUPPRESS);
56764+ comp2 = gr_search_file(old_dentry, GR_READ | GR_WRITE |
56765+ GR_DELETE | GR_AUDIT_DELETE |
56766+ GR_AUDIT_READ | GR_AUDIT_WRITE |
56767+ GR_SUPPRESS, old_mnt);
56768+ } else {
56769+ comp1 = gr_search_file(new_dentry, GR_READ | GR_WRITE |
56770+ GR_CREATE | GR_DELETE |
56771+ GR_AUDIT_CREATE | GR_AUDIT_DELETE |
56772+ GR_AUDIT_READ | GR_AUDIT_WRITE |
56773+ GR_SUPPRESS, parent_mnt);
56774+ comp2 =
56775+ gr_search_file(old_dentry,
56776+ GR_READ | GR_WRITE | GR_AUDIT_READ |
56777+ GR_DELETE | GR_AUDIT_DELETE |
56778+ GR_AUDIT_WRITE | GR_SUPPRESS, old_mnt);
56779+ }
56780+
56781+ if (RENAME_CHECK_SUCCESS(comp1, comp2) &&
56782+ ((comp1 & GR_AUDITS) || (comp2 & GR_AUDITS)))
56783+ gr_log_fs_rbac_str(GR_DO_AUDIT, GR_RENAME_ACL_MSG, old_dentry, old_mnt, newname);
56784+ else if (!RENAME_CHECK_SUCCESS(comp1, comp2) && !(comp1 & GR_SUPPRESS)
56785+ && !(comp2 & GR_SUPPRESS)) {
56786+ gr_log_fs_rbac_str(GR_DONT_AUDIT, GR_RENAME_ACL_MSG, old_dentry, old_mnt, newname);
56787+ error = -EACCES;
56788+ } else if (unlikely(!RENAME_CHECK_SUCCESS(comp1, comp2)))
56789+ error = -EACCES;
56790+
56791+ return error;
56792+}
56793+
56794+void
56795+gr_acl_handle_exit(void)
56796+{
56797+ u16 id;
56798+ char *rolename;
56799+ struct file *exec_file;
56800+
56801+ if (unlikely(current->acl_sp_role && gr_acl_is_enabled() &&
56802+ !(current->role->roletype & GR_ROLE_PERSIST))) {
56803+ id = current->acl_role_id;
56804+ rolename = current->role->rolename;
56805+ gr_set_acls(1);
56806+ gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_SPROLEL_ACL_MSG, rolename, id);
56807+ }
56808+
56809+ write_lock(&grsec_exec_file_lock);
56810+ exec_file = current->exec_file;
56811+ current->exec_file = NULL;
56812+ write_unlock(&grsec_exec_file_lock);
56813+
56814+ if (exec_file)
56815+ fput(exec_file);
56816+}
56817+
56818+int
56819+gr_acl_handle_procpidmem(const struct task_struct *task)
56820+{
56821+ if (unlikely(!gr_acl_is_enabled()))
56822+ return 0;
56823+
56824+ if (task != current && task->acl->mode & GR_PROTPROCFD)
56825+ return -EACCES;
56826+
56827+ return 0;
56828+}
56829diff --git a/grsecurity/gracl_ip.c b/grsecurity/gracl_ip.c
56830new file mode 100644
56831index 0000000..58800a7
56832--- /dev/null
56833+++ b/grsecurity/gracl_ip.c
56834@@ -0,0 +1,384 @@
56835+#include <linux/kernel.h>
56836+#include <asm/uaccess.h>
56837+#include <asm/errno.h>
56838+#include <net/sock.h>
56839+#include <linux/file.h>
56840+#include <linux/fs.h>
56841+#include <linux/net.h>
56842+#include <linux/in.h>
56843+#include <linux/skbuff.h>
56844+#include <linux/ip.h>
56845+#include <linux/udp.h>
56846+#include <linux/types.h>
56847+#include <linux/sched.h>
56848+#include <linux/netdevice.h>
56849+#include <linux/inetdevice.h>
56850+#include <linux/gracl.h>
56851+#include <linux/grsecurity.h>
56852+#include <linux/grinternal.h>
56853+
56854+#define GR_BIND 0x01
56855+#define GR_CONNECT 0x02
56856+#define GR_INVERT 0x04
56857+#define GR_BINDOVERRIDE 0x08
56858+#define GR_CONNECTOVERRIDE 0x10
56859+#define GR_SOCK_FAMILY 0x20
56860+
56861+static const char * gr_protocols[IPPROTO_MAX] = {
56862+ "ip", "icmp", "igmp", "ggp", "ipencap", "st", "tcp", "cbt",
56863+ "egp", "igp", "bbn-rcc", "nvp", "pup", "argus", "emcon", "xnet",
56864+ "chaos", "udp", "mux", "dcn", "hmp", "prm", "xns-idp", "trunk-1",
56865+ "trunk-2", "leaf-1", "leaf-2", "rdp", "irtp", "iso-tp4", "netblt", "mfe-nsp",
56866+ "merit-inp", "sep", "3pc", "idpr", "xtp", "ddp", "idpr-cmtp", "tp++",
56867+ "il", "ipv6", "sdrp", "ipv6-route", "ipv6-frag", "idrp", "rsvp", "gre",
56868+ "mhrp", "bna", "ipv6-crypt", "ipv6-auth", "i-nlsp", "swipe", "narp", "mobile",
56869+ "tlsp", "skip", "ipv6-icmp", "ipv6-nonxt", "ipv6-opts", "unknown:61", "cftp", "unknown:63",
56870+ "sat-expak", "kryptolan", "rvd", "ippc", "unknown:68", "sat-mon", "visa", "ipcv",
56871+ "cpnx", "cphb", "wsn", "pvp", "br-sat-mon", "sun-nd", "wb-mon", "wb-expak",
56872+ "iso-ip", "vmtp", "secure-vmtp", "vines", "ttp", "nfsnet-igp", "dgp", "tcf",
56873+ "eigrp", "ospf", "sprite-rpc", "larp", "mtp", "ax.25", "ipip", "micp",
56874+ "scc-sp", "etherip", "encap", "unknown:99", "gmtp", "ifmp", "pnni", "pim",
56875+ "aris", "scps", "qnx", "a/n", "ipcomp", "snp", "compaq-peer", "ipx-in-ip",
56876+ "vrrp", "pgm", "unknown:114", "l2tp", "ddx", "iatp", "stp", "srp",
56877+ "uti", "smp", "sm", "ptp", "isis", "fire", "crtp", "crdup",
56878+ "sscopmce", "iplt", "sps", "pipe", "sctp", "fc", "unkown:134", "unknown:135",
56879+ "unknown:136", "unknown:137", "unknown:138", "unknown:139", "unknown:140", "unknown:141", "unknown:142", "unknown:143",
56880+ "unknown:144", "unknown:145", "unknown:146", "unknown:147", "unknown:148", "unknown:149", "unknown:150", "unknown:151",
56881+ "unknown:152", "unknown:153", "unknown:154", "unknown:155", "unknown:156", "unknown:157", "unknown:158", "unknown:159",
56882+ "unknown:160", "unknown:161", "unknown:162", "unknown:163", "unknown:164", "unknown:165", "unknown:166", "unknown:167",
56883+ "unknown:168", "unknown:169", "unknown:170", "unknown:171", "unknown:172", "unknown:173", "unknown:174", "unknown:175",
56884+ "unknown:176", "unknown:177", "unknown:178", "unknown:179", "unknown:180", "unknown:181", "unknown:182", "unknown:183",
56885+ "unknown:184", "unknown:185", "unknown:186", "unknown:187", "unknown:188", "unknown:189", "unknown:190", "unknown:191",
56886+ "unknown:192", "unknown:193", "unknown:194", "unknown:195", "unknown:196", "unknown:197", "unknown:198", "unknown:199",
56887+ "unknown:200", "unknown:201", "unknown:202", "unknown:203", "unknown:204", "unknown:205", "unknown:206", "unknown:207",
56888+ "unknown:208", "unknown:209", "unknown:210", "unknown:211", "unknown:212", "unknown:213", "unknown:214", "unknown:215",
56889+ "unknown:216", "unknown:217", "unknown:218", "unknown:219", "unknown:220", "unknown:221", "unknown:222", "unknown:223",
56890+ "unknown:224", "unknown:225", "unknown:226", "unknown:227", "unknown:228", "unknown:229", "unknown:230", "unknown:231",
56891+ "unknown:232", "unknown:233", "unknown:234", "unknown:235", "unknown:236", "unknown:237", "unknown:238", "unknown:239",
56892+ "unknown:240", "unknown:241", "unknown:242", "unknown:243", "unknown:244", "unknown:245", "unknown:246", "unknown:247",
56893+ "unknown:248", "unknown:249", "unknown:250", "unknown:251", "unknown:252", "unknown:253", "unknown:254", "unknown:255",
56894+ };
56895+
56896+static const char * gr_socktypes[SOCK_MAX] = {
56897+ "unknown:0", "stream", "dgram", "raw", "rdm", "seqpacket", "unknown:6",
56898+ "unknown:7", "unknown:8", "unknown:9", "packet"
56899+ };
56900+
56901+static const char * gr_sockfamilies[AF_MAX+1] = {
56902+ "unspec", "unix", "inet", "ax25", "ipx", "appletalk", "netrom", "bridge", "atmpvc", "x25",
56903+ "inet6", "rose", "decnet", "netbeui", "security", "key", "netlink", "packet", "ash",
56904+ "econet", "atmsvc", "rds", "sna", "irda", "ppox", "wanpipe", "llc", "fam_27", "fam_28",
56905+ "tipc", "bluetooth", "iucv", "rxrpc", "isdn", "phonet", "ieee802154", "ciaf"
56906+ };
56907+
56908+const char *
56909+gr_proto_to_name(unsigned char proto)
56910+{
56911+ return gr_protocols[proto];
56912+}
56913+
56914+const char *
56915+gr_socktype_to_name(unsigned char type)
56916+{
56917+ return gr_socktypes[type];
56918+}
56919+
56920+const char *
56921+gr_sockfamily_to_name(unsigned char family)
56922+{
56923+ return gr_sockfamilies[family];
56924+}
56925+
56926+int
56927+gr_search_socket(const int domain, const int type, const int protocol)
56928+{
56929+ struct acl_subject_label *curr;
56930+ const struct cred *cred = current_cred();
56931+
56932+ if (unlikely(!gr_acl_is_enabled()))
56933+ goto exit;
56934+
56935+ if ((domain < 0) || (type < 0) || (protocol < 0) ||
56936+ (domain >= AF_MAX) || (type >= SOCK_MAX) || (protocol >= IPPROTO_MAX))
56937+ goto exit; // let the kernel handle it
56938+
56939+ curr = current->acl;
56940+
56941+ if (curr->sock_families[domain / 32] & (1 << (domain % 32))) {
56942+ /* the family is allowed, if this is PF_INET allow it only if
56943+ the extra sock type/protocol checks pass */
56944+ if (domain == PF_INET)
56945+ goto inet_check;
56946+ goto exit;
56947+ } else {
56948+ if (curr->mode & (GR_LEARN | GR_INHERITLEARN)) {
56949+ __u32 fakeip = 0;
56950+ security_learn(GR_IP_LEARN_MSG, current->role->rolename,
56951+ current->role->roletype, cred->uid,
56952+ cred->gid, current->exec_file ?
56953+ gr_to_filename(current->exec_file->f_path.dentry,
56954+ current->exec_file->f_path.mnt) :
56955+ curr->filename, curr->filename,
56956+ &fakeip, domain, 0, 0, GR_SOCK_FAMILY,
56957+ &current->signal->saved_ip);
56958+ goto exit;
56959+ }
56960+ goto exit_fail;
56961+ }
56962+
56963+inet_check:
56964+ /* the rest of this checking is for IPv4 only */
56965+ if (!curr->ips)
56966+ goto exit;
56967+
56968+ if ((curr->ip_type & (1 << type)) &&
56969+ (curr->ip_proto[protocol / 32] & (1 << (protocol % 32))))
56970+ goto exit;
56971+
56972+ if (curr->mode & (GR_LEARN | GR_INHERITLEARN)) {
56973+ /* we don't place acls on raw sockets , and sometimes
56974+ dgram/ip sockets are opened for ioctl and not
56975+ bind/connect, so we'll fake a bind learn log */
56976+ if (type == SOCK_RAW || type == SOCK_PACKET) {
56977+ __u32 fakeip = 0;
56978+ security_learn(GR_IP_LEARN_MSG, current->role->rolename,
56979+ current->role->roletype, cred->uid,
56980+ cred->gid, current->exec_file ?
56981+ gr_to_filename(current->exec_file->f_path.dentry,
56982+ current->exec_file->f_path.mnt) :
56983+ curr->filename, curr->filename,
56984+ &fakeip, 0, type,
56985+ protocol, GR_CONNECT, &current->signal->saved_ip);
56986+ } else if ((type == SOCK_DGRAM) && (protocol == IPPROTO_IP)) {
56987+ __u32 fakeip = 0;
56988+ security_learn(GR_IP_LEARN_MSG, current->role->rolename,
56989+ current->role->roletype, cred->uid,
56990+ cred->gid, current->exec_file ?
56991+ gr_to_filename(current->exec_file->f_path.dentry,
56992+ current->exec_file->f_path.mnt) :
56993+ curr->filename, curr->filename,
56994+ &fakeip, 0, type,
56995+ protocol, GR_BIND, &current->signal->saved_ip);
56996+ }
56997+ /* we'll log when they use connect or bind */
56998+ goto exit;
56999+ }
57000+
57001+exit_fail:
57002+ if (domain == PF_INET)
57003+ gr_log_str3(GR_DONT_AUDIT, GR_SOCK_MSG, gr_sockfamily_to_name(domain),
57004+ gr_socktype_to_name(type), gr_proto_to_name(protocol));
57005+ else
57006+ gr_log_str2_int(GR_DONT_AUDIT, GR_SOCK_NOINET_MSG, gr_sockfamily_to_name(domain),
57007+ gr_socktype_to_name(type), protocol);
57008+
57009+ return 0;
57010+exit:
57011+ return 1;
57012+}
57013+
57014+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)
57015+{
57016+ if ((ip->mode & mode) &&
57017+ (ip_port >= ip->low) &&
57018+ (ip_port <= ip->high) &&
57019+ ((ntohl(ip_addr) & our_netmask) ==
57020+ (ntohl(our_addr) & our_netmask))
57021+ && (ip->proto[protocol / 32] & (1 << (protocol % 32)))
57022+ && (ip->type & (1 << type))) {
57023+ if (ip->mode & GR_INVERT)
57024+ return 2; // specifically denied
57025+ else
57026+ return 1; // allowed
57027+ }
57028+
57029+ return 0; // not specifically allowed, may continue parsing
57030+}
57031+
57032+static int
57033+gr_search_connectbind(const int full_mode, struct sock *sk,
57034+ struct sockaddr_in *addr, const int type)
57035+{
57036+ char iface[IFNAMSIZ] = {0};
57037+ struct acl_subject_label *curr;
57038+ struct acl_ip_label *ip;
57039+ struct inet_sock *isk;
57040+ struct net_device *dev;
57041+ struct in_device *idev;
57042+ unsigned long i;
57043+ int ret;
57044+ int mode = full_mode & (GR_BIND | GR_CONNECT);
57045+ __u32 ip_addr = 0;
57046+ __u32 our_addr;
57047+ __u32 our_netmask;
57048+ char *p;
57049+ __u16 ip_port = 0;
57050+ const struct cred *cred = current_cred();
57051+
57052+ if (unlikely(!gr_acl_is_enabled() || sk->sk_family != PF_INET))
57053+ return 0;
57054+
57055+ curr = current->acl;
57056+ isk = inet_sk(sk);
57057+
57058+ /* INADDR_ANY overriding for binds, inaddr_any_override is already in network order */
57059+ if ((full_mode & GR_BINDOVERRIDE) && addr->sin_addr.s_addr == htonl(INADDR_ANY) && curr->inaddr_any_override != 0)
57060+ addr->sin_addr.s_addr = curr->inaddr_any_override;
57061+ if ((full_mode & GR_CONNECT) && isk->inet_saddr == htonl(INADDR_ANY) && curr->inaddr_any_override != 0) {
57062+ struct sockaddr_in saddr;
57063+ int err;
57064+
57065+ saddr.sin_family = AF_INET;
57066+ saddr.sin_addr.s_addr = curr->inaddr_any_override;
57067+ saddr.sin_port = isk->inet_sport;
57068+
57069+ err = security_socket_bind(sk->sk_socket, (struct sockaddr *)&saddr, sizeof(struct sockaddr_in));
57070+ if (err)
57071+ return err;
57072+
57073+ err = sk->sk_socket->ops->bind(sk->sk_socket, (struct sockaddr *)&saddr, sizeof(struct sockaddr_in));
57074+ if (err)
57075+ return err;
57076+ }
57077+
57078+ if (!curr->ips)
57079+ return 0;
57080+
57081+ ip_addr = addr->sin_addr.s_addr;
57082+ ip_port = ntohs(addr->sin_port);
57083+
57084+ if (curr->mode & (GR_LEARN | GR_INHERITLEARN)) {
57085+ security_learn(GR_IP_LEARN_MSG, current->role->rolename,
57086+ current->role->roletype, cred->uid,
57087+ cred->gid, current->exec_file ?
57088+ gr_to_filename(current->exec_file->f_path.dentry,
57089+ current->exec_file->f_path.mnt) :
57090+ curr->filename, curr->filename,
57091+ &ip_addr, ip_port, type,
57092+ sk->sk_protocol, mode, &current->signal->saved_ip);
57093+ return 0;
57094+ }
57095+
57096+ for (i = 0; i < curr->ip_num; i++) {
57097+ ip = *(curr->ips + i);
57098+ if (ip->iface != NULL) {
57099+ strncpy(iface, ip->iface, IFNAMSIZ - 1);
57100+ p = strchr(iface, ':');
57101+ if (p != NULL)
57102+ *p = '\0';
57103+ dev = dev_get_by_name(sock_net(sk), iface);
57104+ if (dev == NULL)
57105+ continue;
57106+ idev = in_dev_get(dev);
57107+ if (idev == NULL) {
57108+ dev_put(dev);
57109+ continue;
57110+ }
57111+ rcu_read_lock();
57112+ for_ifa(idev) {
57113+ if (!strcmp(ip->iface, ifa->ifa_label)) {
57114+ our_addr = ifa->ifa_address;
57115+ our_netmask = 0xffffffff;
57116+ ret = check_ip_policy(ip, ip_addr, ip_port, sk->sk_protocol, mode, type, our_addr, our_netmask);
57117+ if (ret == 1) {
57118+ rcu_read_unlock();
57119+ in_dev_put(idev);
57120+ dev_put(dev);
57121+ return 0;
57122+ } else if (ret == 2) {
57123+ rcu_read_unlock();
57124+ in_dev_put(idev);
57125+ dev_put(dev);
57126+ goto denied;
57127+ }
57128+ }
57129+ } endfor_ifa(idev);
57130+ rcu_read_unlock();
57131+ in_dev_put(idev);
57132+ dev_put(dev);
57133+ } else {
57134+ our_addr = ip->addr;
57135+ our_netmask = ip->netmask;
57136+ ret = check_ip_policy(ip, ip_addr, ip_port, sk->sk_protocol, mode, type, our_addr, our_netmask);
57137+ if (ret == 1)
57138+ return 0;
57139+ else if (ret == 2)
57140+ goto denied;
57141+ }
57142+ }
57143+
57144+denied:
57145+ if (mode == GR_BIND)
57146+ 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));
57147+ else if (mode == GR_CONNECT)
57148+ 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));
57149+
57150+ return -EACCES;
57151+}
57152+
57153+int
57154+gr_search_connect(struct socket *sock, struct sockaddr_in *addr)
57155+{
57156+ /* always allow disconnection of dgram sockets with connect */
57157+ if (addr->sin_family == AF_UNSPEC)
57158+ return 0;
57159+ return gr_search_connectbind(GR_CONNECT | GR_CONNECTOVERRIDE, sock->sk, addr, sock->type);
57160+}
57161+
57162+int
57163+gr_search_bind(struct socket *sock, struct sockaddr_in *addr)
57164+{
57165+ return gr_search_connectbind(GR_BIND | GR_BINDOVERRIDE, sock->sk, addr, sock->type);
57166+}
57167+
57168+int gr_search_listen(struct socket *sock)
57169+{
57170+ struct sock *sk = sock->sk;
57171+ struct sockaddr_in addr;
57172+
57173+ addr.sin_addr.s_addr = inet_sk(sk)->inet_saddr;
57174+ addr.sin_port = inet_sk(sk)->inet_sport;
57175+
57176+ return gr_search_connectbind(GR_BIND | GR_CONNECTOVERRIDE, sock->sk, &addr, sock->type);
57177+}
57178+
57179+int gr_search_accept(struct socket *sock)
57180+{
57181+ struct sock *sk = sock->sk;
57182+ struct sockaddr_in addr;
57183+
57184+ addr.sin_addr.s_addr = inet_sk(sk)->inet_saddr;
57185+ addr.sin_port = inet_sk(sk)->inet_sport;
57186+
57187+ return gr_search_connectbind(GR_BIND | GR_CONNECTOVERRIDE, sock->sk, &addr, sock->type);
57188+}
57189+
57190+int
57191+gr_search_udp_sendmsg(struct sock *sk, struct sockaddr_in *addr)
57192+{
57193+ if (addr)
57194+ return gr_search_connectbind(GR_CONNECT, sk, addr, SOCK_DGRAM);
57195+ else {
57196+ struct sockaddr_in sin;
57197+ const struct inet_sock *inet = inet_sk(sk);
57198+
57199+ sin.sin_addr.s_addr = inet->inet_daddr;
57200+ sin.sin_port = inet->inet_dport;
57201+
57202+ return gr_search_connectbind(GR_CONNECT | GR_CONNECTOVERRIDE, sk, &sin, SOCK_DGRAM);
57203+ }
57204+}
57205+
57206+int
57207+gr_search_udp_recvmsg(struct sock *sk, const struct sk_buff *skb)
57208+{
57209+ struct sockaddr_in sin;
57210+
57211+ if (unlikely(skb->len < sizeof (struct udphdr)))
57212+ return 0; // skip this packet
57213+
57214+ sin.sin_addr.s_addr = ip_hdr(skb)->saddr;
57215+ sin.sin_port = udp_hdr(skb)->source;
57216+
57217+ return gr_search_connectbind(GR_CONNECT | GR_CONNECTOVERRIDE, sk, &sin, SOCK_DGRAM);
57218+}
57219diff --git a/grsecurity/gracl_learn.c b/grsecurity/gracl_learn.c
57220new file mode 100644
57221index 0000000..25f54ef
57222--- /dev/null
57223+++ b/grsecurity/gracl_learn.c
57224@@ -0,0 +1,207 @@
57225+#include <linux/kernel.h>
57226+#include <linux/mm.h>
57227+#include <linux/sched.h>
57228+#include <linux/poll.h>
57229+#include <linux/string.h>
57230+#include <linux/file.h>
57231+#include <linux/types.h>
57232+#include <linux/vmalloc.h>
57233+#include <linux/grinternal.h>
57234+
57235+extern ssize_t write_grsec_handler(struct file * file, const char __user * buf,
57236+ size_t count, loff_t *ppos);
57237+extern int gr_acl_is_enabled(void);
57238+
57239+static DECLARE_WAIT_QUEUE_HEAD(learn_wait);
57240+static int gr_learn_attached;
57241+
57242+/* use a 512k buffer */
57243+#define LEARN_BUFFER_SIZE (512 * 1024)
57244+
57245+static DEFINE_SPINLOCK(gr_learn_lock);
57246+static DEFINE_MUTEX(gr_learn_user_mutex);
57247+
57248+/* we need to maintain two buffers, so that the kernel context of grlearn
57249+ uses a semaphore around the userspace copying, and the other kernel contexts
57250+ use a spinlock when copying into the buffer, since they cannot sleep
57251+*/
57252+static char *learn_buffer;
57253+static char *learn_buffer_user;
57254+static int learn_buffer_len;
57255+static int learn_buffer_user_len;
57256+
57257+static ssize_t
57258+read_learn(struct file *file, char __user * buf, size_t count, loff_t * ppos)
57259+{
57260+ DECLARE_WAITQUEUE(wait, current);
57261+ ssize_t retval = 0;
57262+
57263+ add_wait_queue(&learn_wait, &wait);
57264+ set_current_state(TASK_INTERRUPTIBLE);
57265+ do {
57266+ mutex_lock(&gr_learn_user_mutex);
57267+ spin_lock(&gr_learn_lock);
57268+ if (learn_buffer_len)
57269+ break;
57270+ spin_unlock(&gr_learn_lock);
57271+ mutex_unlock(&gr_learn_user_mutex);
57272+ if (file->f_flags & O_NONBLOCK) {
57273+ retval = -EAGAIN;
57274+ goto out;
57275+ }
57276+ if (signal_pending(current)) {
57277+ retval = -ERESTARTSYS;
57278+ goto out;
57279+ }
57280+
57281+ schedule();
57282+ } while (1);
57283+
57284+ memcpy(learn_buffer_user, learn_buffer, learn_buffer_len);
57285+ learn_buffer_user_len = learn_buffer_len;
57286+ retval = learn_buffer_len;
57287+ learn_buffer_len = 0;
57288+
57289+ spin_unlock(&gr_learn_lock);
57290+
57291+ if (copy_to_user(buf, learn_buffer_user, learn_buffer_user_len))
57292+ retval = -EFAULT;
57293+
57294+ mutex_unlock(&gr_learn_user_mutex);
57295+out:
57296+ set_current_state(TASK_RUNNING);
57297+ remove_wait_queue(&learn_wait, &wait);
57298+ return retval;
57299+}
57300+
57301+static unsigned int
57302+poll_learn(struct file * file, poll_table * wait)
57303+{
57304+ poll_wait(file, &learn_wait, wait);
57305+
57306+ if (learn_buffer_len)
57307+ return (POLLIN | POLLRDNORM);
57308+
57309+ return 0;
57310+}
57311+
57312+void
57313+gr_clear_learn_entries(void)
57314+{
57315+ char *tmp;
57316+
57317+ mutex_lock(&gr_learn_user_mutex);
57318+ spin_lock(&gr_learn_lock);
57319+ tmp = learn_buffer;
57320+ learn_buffer = NULL;
57321+ spin_unlock(&gr_learn_lock);
57322+ if (tmp)
57323+ vfree(tmp);
57324+ if (learn_buffer_user != NULL) {
57325+ vfree(learn_buffer_user);
57326+ learn_buffer_user = NULL;
57327+ }
57328+ learn_buffer_len = 0;
57329+ mutex_unlock(&gr_learn_user_mutex);
57330+
57331+ return;
57332+}
57333+
57334+void
57335+gr_add_learn_entry(const char *fmt, ...)
57336+{
57337+ va_list args;
57338+ unsigned int len;
57339+
57340+ if (!gr_learn_attached)
57341+ return;
57342+
57343+ spin_lock(&gr_learn_lock);
57344+
57345+ /* leave a gap at the end so we know when it's "full" but don't have to
57346+ compute the exact length of the string we're trying to append
57347+ */
57348+ if (learn_buffer_len > LEARN_BUFFER_SIZE - 16384) {
57349+ spin_unlock(&gr_learn_lock);
57350+ wake_up_interruptible(&learn_wait);
57351+ return;
57352+ }
57353+ if (learn_buffer == NULL) {
57354+ spin_unlock(&gr_learn_lock);
57355+ return;
57356+ }
57357+
57358+ va_start(args, fmt);
57359+ len = vsnprintf(learn_buffer + learn_buffer_len, LEARN_BUFFER_SIZE - learn_buffer_len, fmt, args);
57360+ va_end(args);
57361+
57362+ learn_buffer_len += len + 1;
57363+
57364+ spin_unlock(&gr_learn_lock);
57365+ wake_up_interruptible(&learn_wait);
57366+
57367+ return;
57368+}
57369+
57370+static int
57371+open_learn(struct inode *inode, struct file *file)
57372+{
57373+ if (file->f_mode & FMODE_READ && gr_learn_attached)
57374+ return -EBUSY;
57375+ if (file->f_mode & FMODE_READ) {
57376+ int retval = 0;
57377+ mutex_lock(&gr_learn_user_mutex);
57378+ if (learn_buffer == NULL)
57379+ learn_buffer = vmalloc(LEARN_BUFFER_SIZE);
57380+ if (learn_buffer_user == NULL)
57381+ learn_buffer_user = vmalloc(LEARN_BUFFER_SIZE);
57382+ if (learn_buffer == NULL) {
57383+ retval = -ENOMEM;
57384+ goto out_error;
57385+ }
57386+ if (learn_buffer_user == NULL) {
57387+ retval = -ENOMEM;
57388+ goto out_error;
57389+ }
57390+ learn_buffer_len = 0;
57391+ learn_buffer_user_len = 0;
57392+ gr_learn_attached = 1;
57393+out_error:
57394+ mutex_unlock(&gr_learn_user_mutex);
57395+ return retval;
57396+ }
57397+ return 0;
57398+}
57399+
57400+static int
57401+close_learn(struct inode *inode, struct file *file)
57402+{
57403+ if (file->f_mode & FMODE_READ) {
57404+ char *tmp = NULL;
57405+ mutex_lock(&gr_learn_user_mutex);
57406+ spin_lock(&gr_learn_lock);
57407+ tmp = learn_buffer;
57408+ learn_buffer = NULL;
57409+ spin_unlock(&gr_learn_lock);
57410+ if (tmp)
57411+ vfree(tmp);
57412+ if (learn_buffer_user != NULL) {
57413+ vfree(learn_buffer_user);
57414+ learn_buffer_user = NULL;
57415+ }
57416+ learn_buffer_len = 0;
57417+ learn_buffer_user_len = 0;
57418+ gr_learn_attached = 0;
57419+ mutex_unlock(&gr_learn_user_mutex);
57420+ }
57421+
57422+ return 0;
57423+}
57424+
57425+const struct file_operations grsec_fops = {
57426+ .read = read_learn,
57427+ .write = write_grsec_handler,
57428+ .open = open_learn,
57429+ .release = close_learn,
57430+ .poll = poll_learn,
57431+};
57432diff --git a/grsecurity/gracl_res.c b/grsecurity/gracl_res.c
57433new file mode 100644
57434index 0000000..39645c9
57435--- /dev/null
57436+++ b/grsecurity/gracl_res.c
57437@@ -0,0 +1,68 @@
57438+#include <linux/kernel.h>
57439+#include <linux/sched.h>
57440+#include <linux/gracl.h>
57441+#include <linux/grinternal.h>
57442+
57443+static const char *restab_log[] = {
57444+ [RLIMIT_CPU] = "RLIMIT_CPU",
57445+ [RLIMIT_FSIZE] = "RLIMIT_FSIZE",
57446+ [RLIMIT_DATA] = "RLIMIT_DATA",
57447+ [RLIMIT_STACK] = "RLIMIT_STACK",
57448+ [RLIMIT_CORE] = "RLIMIT_CORE",
57449+ [RLIMIT_RSS] = "RLIMIT_RSS",
57450+ [RLIMIT_NPROC] = "RLIMIT_NPROC",
57451+ [RLIMIT_NOFILE] = "RLIMIT_NOFILE",
57452+ [RLIMIT_MEMLOCK] = "RLIMIT_MEMLOCK",
57453+ [RLIMIT_AS] = "RLIMIT_AS",
57454+ [RLIMIT_LOCKS] = "RLIMIT_LOCKS",
57455+ [RLIMIT_SIGPENDING] = "RLIMIT_SIGPENDING",
57456+ [RLIMIT_MSGQUEUE] = "RLIMIT_MSGQUEUE",
57457+ [RLIMIT_NICE] = "RLIMIT_NICE",
57458+ [RLIMIT_RTPRIO] = "RLIMIT_RTPRIO",
57459+ [RLIMIT_RTTIME] = "RLIMIT_RTTIME",
57460+ [GR_CRASH_RES] = "RLIMIT_CRASH"
57461+};
57462+
57463+void
57464+gr_log_resource(const struct task_struct *task,
57465+ const int res, const unsigned long wanted, const int gt)
57466+{
57467+ const struct cred *cred;
57468+ unsigned long rlim;
57469+
57470+ if (!gr_acl_is_enabled() && !grsec_resource_logging)
57471+ return;
57472+
57473+ // not yet supported resource
57474+ if (unlikely(!restab_log[res]))
57475+ return;
57476+
57477+ if (res == RLIMIT_CPU || res == RLIMIT_RTTIME)
57478+ rlim = task_rlimit_max(task, res);
57479+ else
57480+ rlim = task_rlimit(task, res);
57481+
57482+ if (likely((rlim == RLIM_INFINITY) || (gt && wanted <= rlim) || (!gt && wanted < rlim)))
57483+ return;
57484+
57485+ rcu_read_lock();
57486+ cred = __task_cred(task);
57487+
57488+ if (res == RLIMIT_NPROC &&
57489+ (cap_raised(cred->cap_effective, CAP_SYS_ADMIN) ||
57490+ cap_raised(cred->cap_effective, CAP_SYS_RESOURCE)))
57491+ goto out_rcu_unlock;
57492+ else if (res == RLIMIT_MEMLOCK &&
57493+ cap_raised(cred->cap_effective, CAP_IPC_LOCK))
57494+ goto out_rcu_unlock;
57495+ else if (res == RLIMIT_NICE && cap_raised(cred->cap_effective, CAP_SYS_NICE))
57496+ goto out_rcu_unlock;
57497+ rcu_read_unlock();
57498+
57499+ gr_log_res_ulong2_str(GR_DONT_AUDIT, GR_RESOURCE_MSG, task, wanted, restab_log[res], rlim);
57500+
57501+ return;
57502+out_rcu_unlock:
57503+ rcu_read_unlock();
57504+ return;
57505+}
57506diff --git a/grsecurity/gracl_segv.c b/grsecurity/gracl_segv.c
57507new file mode 100644
57508index 0000000..25197e9
57509--- /dev/null
57510+++ b/grsecurity/gracl_segv.c
57511@@ -0,0 +1,299 @@
57512+#include <linux/kernel.h>
57513+#include <linux/mm.h>
57514+#include <asm/uaccess.h>
57515+#include <asm/errno.h>
57516+#include <asm/mman.h>
57517+#include <net/sock.h>
57518+#include <linux/file.h>
57519+#include <linux/fs.h>
57520+#include <linux/net.h>
57521+#include <linux/in.h>
57522+#include <linux/slab.h>
57523+#include <linux/types.h>
57524+#include <linux/sched.h>
57525+#include <linux/timer.h>
57526+#include <linux/gracl.h>
57527+#include <linux/grsecurity.h>
57528+#include <linux/grinternal.h>
57529+
57530+static struct crash_uid *uid_set;
57531+static unsigned short uid_used;
57532+static DEFINE_SPINLOCK(gr_uid_lock);
57533+extern rwlock_t gr_inode_lock;
57534+extern struct acl_subject_label *
57535+ lookup_acl_subj_label(const ino_t inode, const dev_t dev,
57536+ struct acl_role_label *role);
57537+
57538+#ifdef CONFIG_BTRFS_FS
57539+extern dev_t get_btrfs_dev_from_inode(struct inode *inode);
57540+extern int btrfs_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat);
57541+#endif
57542+
57543+static inline dev_t __get_dev(const struct dentry *dentry)
57544+{
57545+#ifdef CONFIG_BTRFS_FS
57546+ if (dentry->d_inode->i_op && dentry->d_inode->i_op->getattr == &btrfs_getattr)
57547+ return get_btrfs_dev_from_inode(dentry->d_inode);
57548+ else
57549+#endif
57550+ return dentry->d_inode->i_sb->s_dev;
57551+}
57552+
57553+int
57554+gr_init_uidset(void)
57555+{
57556+ uid_set =
57557+ kmalloc(GR_UIDTABLE_MAX * sizeof (struct crash_uid), GFP_KERNEL);
57558+ uid_used = 0;
57559+
57560+ return uid_set ? 1 : 0;
57561+}
57562+
57563+void
57564+gr_free_uidset(void)
57565+{
57566+ if (uid_set)
57567+ kfree(uid_set);
57568+
57569+ return;
57570+}
57571+
57572+int
57573+gr_find_uid(const uid_t uid)
57574+{
57575+ struct crash_uid *tmp = uid_set;
57576+ uid_t buid;
57577+ int low = 0, high = uid_used - 1, mid;
57578+
57579+ while (high >= low) {
57580+ mid = (low + high) >> 1;
57581+ buid = tmp[mid].uid;
57582+ if (buid == uid)
57583+ return mid;
57584+ if (buid > uid)
57585+ high = mid - 1;
57586+ if (buid < uid)
57587+ low = mid + 1;
57588+ }
57589+
57590+ return -1;
57591+}
57592+
57593+static __inline__ void
57594+gr_insertsort(void)
57595+{
57596+ unsigned short i, j;
57597+ struct crash_uid index;
57598+
57599+ for (i = 1; i < uid_used; i++) {
57600+ index = uid_set[i];
57601+ j = i;
57602+ while ((j > 0) && uid_set[j - 1].uid > index.uid) {
57603+ uid_set[j] = uid_set[j - 1];
57604+ j--;
57605+ }
57606+ uid_set[j] = index;
57607+ }
57608+
57609+ return;
57610+}
57611+
57612+static __inline__ void
57613+gr_insert_uid(const uid_t uid, const unsigned long expires)
57614+{
57615+ int loc;
57616+
57617+ if (uid_used == GR_UIDTABLE_MAX)
57618+ return;
57619+
57620+ loc = gr_find_uid(uid);
57621+
57622+ if (loc >= 0) {
57623+ uid_set[loc].expires = expires;
57624+ return;
57625+ }
57626+
57627+ uid_set[uid_used].uid = uid;
57628+ uid_set[uid_used].expires = expires;
57629+ uid_used++;
57630+
57631+ gr_insertsort();
57632+
57633+ return;
57634+}
57635+
57636+void
57637+gr_remove_uid(const unsigned short loc)
57638+{
57639+ unsigned short i;
57640+
57641+ for (i = loc + 1; i < uid_used; i++)
57642+ uid_set[i - 1] = uid_set[i];
57643+
57644+ uid_used--;
57645+
57646+ return;
57647+}
57648+
57649+int
57650+gr_check_crash_uid(const uid_t uid)
57651+{
57652+ int loc;
57653+ int ret = 0;
57654+
57655+ if (unlikely(!gr_acl_is_enabled()))
57656+ return 0;
57657+
57658+ spin_lock(&gr_uid_lock);
57659+ loc = gr_find_uid(uid);
57660+
57661+ if (loc < 0)
57662+ goto out_unlock;
57663+
57664+ if (time_before_eq(uid_set[loc].expires, get_seconds()))
57665+ gr_remove_uid(loc);
57666+ else
57667+ ret = 1;
57668+
57669+out_unlock:
57670+ spin_unlock(&gr_uid_lock);
57671+ return ret;
57672+}
57673+
57674+static __inline__ int
57675+proc_is_setxid(const struct cred *cred)
57676+{
57677+ if (!uid_eq(cred->uid, cred->euid) || !uid_eq(cred->uid, cred->suid) ||
57678+ !uid_eq(cred->uid, cred->fsuid))
57679+ return 1;
57680+ if (!uid_eq(cred->gid, cred->egid) || !uid_eq(cred->gid, cred->sgid) ||
57681+ !uid_eq(cred->gid, cred->fsgid))
57682+ return 1;
57683+
57684+ return 0;
57685+}
57686+
57687+extern int gr_fake_force_sig(int sig, struct task_struct *t);
57688+
57689+void
57690+gr_handle_crash(struct task_struct *task, const int sig)
57691+{
57692+ struct acl_subject_label *curr;
57693+ struct task_struct *tsk, *tsk2;
57694+ const struct cred *cred;
57695+ const struct cred *cred2;
57696+
57697+ if (sig != SIGSEGV && sig != SIGKILL && sig != SIGBUS && sig != SIGILL)
57698+ return;
57699+
57700+ if (unlikely(!gr_acl_is_enabled()))
57701+ return;
57702+
57703+ curr = task->acl;
57704+
57705+ if (!(curr->resmask & (1 << GR_CRASH_RES)))
57706+ return;
57707+
57708+ if (time_before_eq(curr->expires, get_seconds())) {
57709+ curr->expires = 0;
57710+ curr->crashes = 0;
57711+ }
57712+
57713+ curr->crashes++;
57714+
57715+ if (!curr->expires)
57716+ curr->expires = get_seconds() + curr->res[GR_CRASH_RES].rlim_max;
57717+
57718+ if ((curr->crashes >= curr->res[GR_CRASH_RES].rlim_cur) &&
57719+ time_after(curr->expires, get_seconds())) {
57720+ rcu_read_lock();
57721+ cred = __task_cred(task);
57722+ if (!uid_eq(cred->uid, GLOBAL_ROOT_UID) && proc_is_setxid(cred)) {
57723+ gr_log_crash1(GR_DONT_AUDIT, GR_SEGVSTART_ACL_MSG, task, curr->res[GR_CRASH_RES].rlim_max);
57724+ spin_lock(&gr_uid_lock);
57725+ gr_insert_uid(cred->uid, curr->expires);
57726+ spin_unlock(&gr_uid_lock);
57727+ curr->expires = 0;
57728+ curr->crashes = 0;
57729+ read_lock(&tasklist_lock);
57730+ do_each_thread(tsk2, tsk) {
57731+ cred2 = __task_cred(tsk);
57732+ if (tsk != task && uid_eq(cred2->uid, cred->uid))
57733+ gr_fake_force_sig(SIGKILL, tsk);
57734+ } while_each_thread(tsk2, tsk);
57735+ read_unlock(&tasklist_lock);
57736+ } else {
57737+ gr_log_crash2(GR_DONT_AUDIT, GR_SEGVNOSUID_ACL_MSG, task, curr->res[GR_CRASH_RES].rlim_max);
57738+ read_lock(&tasklist_lock);
57739+ read_lock(&grsec_exec_file_lock);
57740+ do_each_thread(tsk2, tsk) {
57741+ if (likely(tsk != task)) {
57742+ // if this thread has the same subject as the one that triggered
57743+ // RES_CRASH and it's the same binary, kill it
57744+ if (tsk->acl == task->acl && tsk->exec_file == task->exec_file)
57745+ gr_fake_force_sig(SIGKILL, tsk);
57746+ }
57747+ } while_each_thread(tsk2, tsk);
57748+ read_unlock(&grsec_exec_file_lock);
57749+ read_unlock(&tasklist_lock);
57750+ }
57751+ rcu_read_unlock();
57752+ }
57753+
57754+ return;
57755+}
57756+
57757+int
57758+gr_check_crash_exec(const struct file *filp)
57759+{
57760+ struct acl_subject_label *curr;
57761+
57762+ if (unlikely(!gr_acl_is_enabled()))
57763+ return 0;
57764+
57765+ read_lock(&gr_inode_lock);
57766+ curr = lookup_acl_subj_label(filp->f_path.dentry->d_inode->i_ino,
57767+ __get_dev(filp->f_path.dentry),
57768+ current->role);
57769+ read_unlock(&gr_inode_lock);
57770+
57771+ if (!curr || !(curr->resmask & (1 << GR_CRASH_RES)) ||
57772+ (!curr->crashes && !curr->expires))
57773+ return 0;
57774+
57775+ if ((curr->crashes >= curr->res[GR_CRASH_RES].rlim_cur) &&
57776+ time_after(curr->expires, get_seconds()))
57777+ return 1;
57778+ else if (time_before_eq(curr->expires, get_seconds())) {
57779+ curr->crashes = 0;
57780+ curr->expires = 0;
57781+ }
57782+
57783+ return 0;
57784+}
57785+
57786+void
57787+gr_handle_alertkill(struct task_struct *task)
57788+{
57789+ struct acl_subject_label *curracl;
57790+ __u32 curr_ip;
57791+ struct task_struct *p, *p2;
57792+
57793+ if (unlikely(!gr_acl_is_enabled()))
57794+ return;
57795+
57796+ curracl = task->acl;
57797+ curr_ip = task->signal->curr_ip;
57798+
57799+ if ((curracl->mode & GR_KILLIPPROC) && curr_ip) {
57800+ read_lock(&tasklist_lock);
57801+ do_each_thread(p2, p) {
57802+ if (p->signal->curr_ip == curr_ip)
57803+ gr_fake_force_sig(SIGKILL, p);
57804+ } while_each_thread(p2, p);
57805+ read_unlock(&tasklist_lock);
57806+ } else if (curracl->mode & GR_KILLPROC)
57807+ gr_fake_force_sig(SIGKILL, task);
57808+
57809+ return;
57810+}
57811diff --git a/grsecurity/gracl_shm.c b/grsecurity/gracl_shm.c
57812new file mode 100644
57813index 0000000..9d83a69
57814--- /dev/null
57815+++ b/grsecurity/gracl_shm.c
57816@@ -0,0 +1,40 @@
57817+#include <linux/kernel.h>
57818+#include <linux/mm.h>
57819+#include <linux/sched.h>
57820+#include <linux/file.h>
57821+#include <linux/ipc.h>
57822+#include <linux/gracl.h>
57823+#include <linux/grsecurity.h>
57824+#include <linux/grinternal.h>
57825+
57826+int
57827+gr_handle_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
57828+ const time_t shm_createtime, const uid_t cuid, const int shmid)
57829+{
57830+ struct task_struct *task;
57831+
57832+ if (!gr_acl_is_enabled())
57833+ return 1;
57834+
57835+ rcu_read_lock();
57836+ read_lock(&tasklist_lock);
57837+
57838+ task = find_task_by_vpid(shm_cprid);
57839+
57840+ if (unlikely(!task))
57841+ task = find_task_by_vpid(shm_lapid);
57842+
57843+ if (unlikely(task && (time_before_eq((unsigned long)task->start_time.tv_sec, (unsigned long)shm_createtime) ||
57844+ (task->pid == shm_lapid)) &&
57845+ (task->acl->mode & GR_PROTSHM) &&
57846+ (task->acl != current->acl))) {
57847+ read_unlock(&tasklist_lock);
57848+ rcu_read_unlock();
57849+ gr_log_int3(GR_DONT_AUDIT, GR_SHMAT_ACL_MSG, cuid, shm_cprid, shmid);
57850+ return 0;
57851+ }
57852+ read_unlock(&tasklist_lock);
57853+ rcu_read_unlock();
57854+
57855+ return 1;
57856+}
57857diff --git a/grsecurity/grsec_chdir.c b/grsecurity/grsec_chdir.c
57858new file mode 100644
57859index 0000000..bc0be01
57860--- /dev/null
57861+++ b/grsecurity/grsec_chdir.c
57862@@ -0,0 +1,19 @@
57863+#include <linux/kernel.h>
57864+#include <linux/sched.h>
57865+#include <linux/fs.h>
57866+#include <linux/file.h>
57867+#include <linux/grsecurity.h>
57868+#include <linux/grinternal.h>
57869+
57870+void
57871+gr_log_chdir(const struct dentry *dentry, const struct vfsmount *mnt)
57872+{
57873+#ifdef CONFIG_GRKERNSEC_AUDIT_CHDIR
57874+ if ((grsec_enable_chdir && grsec_enable_group &&
57875+ in_group_p(grsec_audit_gid)) || (grsec_enable_chdir &&
57876+ !grsec_enable_group)) {
57877+ gr_log_fs_generic(GR_DO_AUDIT, GR_CHDIR_AUDIT_MSG, dentry, mnt);
57878+ }
57879+#endif
57880+ return;
57881+}
57882diff --git a/grsecurity/grsec_chroot.c b/grsecurity/grsec_chroot.c
57883new file mode 100644
57884index 0000000..9807ee2
57885--- /dev/null
57886+++ b/grsecurity/grsec_chroot.c
57887@@ -0,0 +1,368 @@
57888+#include <linux/kernel.h>
57889+#include <linux/module.h>
57890+#include <linux/sched.h>
57891+#include <linux/file.h>
57892+#include <linux/fs.h>
57893+#include <linux/mount.h>
57894+#include <linux/types.h>
57895+#include "../fs/mount.h"
57896+#include <linux/grsecurity.h>
57897+#include <linux/grinternal.h>
57898+
57899+void gr_set_chroot_entries(struct task_struct *task, struct path *path)
57900+{
57901+#ifdef CONFIG_GRKERNSEC
57902+ if (task->pid > 1 && path->dentry != init_task.fs->root.dentry &&
57903+ path->dentry != task->nsproxy->mnt_ns->root->mnt.mnt_root)
57904+ task->gr_is_chrooted = 1;
57905+ else
57906+ task->gr_is_chrooted = 0;
57907+
57908+ task->gr_chroot_dentry = path->dentry;
57909+#endif
57910+ return;
57911+}
57912+
57913+void gr_clear_chroot_entries(struct task_struct *task)
57914+{
57915+#ifdef CONFIG_GRKERNSEC
57916+ task->gr_is_chrooted = 0;
57917+ task->gr_chroot_dentry = NULL;
57918+#endif
57919+ return;
57920+}
57921+
57922+int
57923+gr_handle_chroot_unix(const pid_t pid)
57924+{
57925+#ifdef CONFIG_GRKERNSEC_CHROOT_UNIX
57926+ struct task_struct *p;
57927+
57928+ if (unlikely(!grsec_enable_chroot_unix))
57929+ return 1;
57930+
57931+ if (likely(!proc_is_chrooted(current)))
57932+ return 1;
57933+
57934+ rcu_read_lock();
57935+ read_lock(&tasklist_lock);
57936+ p = find_task_by_vpid_unrestricted(pid);
57937+ if (unlikely(p && !have_same_root(current, p))) {
57938+ read_unlock(&tasklist_lock);
57939+ rcu_read_unlock();
57940+ gr_log_noargs(GR_DONT_AUDIT, GR_UNIX_CHROOT_MSG);
57941+ return 0;
57942+ }
57943+ read_unlock(&tasklist_lock);
57944+ rcu_read_unlock();
57945+#endif
57946+ return 1;
57947+}
57948+
57949+int
57950+gr_handle_chroot_nice(void)
57951+{
57952+#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
57953+ if (grsec_enable_chroot_nice && proc_is_chrooted(current)) {
57954+ gr_log_noargs(GR_DONT_AUDIT, GR_NICE_CHROOT_MSG);
57955+ return -EPERM;
57956+ }
57957+#endif
57958+ return 0;
57959+}
57960+
57961+int
57962+gr_handle_chroot_setpriority(struct task_struct *p, const int niceval)
57963+{
57964+#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
57965+ if (grsec_enable_chroot_nice && (niceval < task_nice(p))
57966+ && proc_is_chrooted(current)) {
57967+ gr_log_str_int(GR_DONT_AUDIT, GR_PRIORITY_CHROOT_MSG, p->comm, p->pid);
57968+ return -EACCES;
57969+ }
57970+#endif
57971+ return 0;
57972+}
57973+
57974+int
57975+gr_handle_chroot_rawio(const struct inode *inode)
57976+{
57977+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
57978+ if (grsec_enable_chroot_caps && proc_is_chrooted(current) &&
57979+ inode && S_ISBLK(inode->i_mode) && !capable(CAP_SYS_RAWIO))
57980+ return 1;
57981+#endif
57982+ return 0;
57983+}
57984+
57985+int
57986+gr_handle_chroot_fowner(struct pid *pid, enum pid_type type)
57987+{
57988+#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
57989+ struct task_struct *p;
57990+ int ret = 0;
57991+ if (!grsec_enable_chroot_findtask || !proc_is_chrooted(current) || !pid)
57992+ return ret;
57993+
57994+ read_lock(&tasklist_lock);
57995+ do_each_pid_task(pid, type, p) {
57996+ if (!have_same_root(current, p)) {
57997+ ret = 1;
57998+ goto out;
57999+ }
58000+ } while_each_pid_task(pid, type, p);
58001+out:
58002+ read_unlock(&tasklist_lock);
58003+ return ret;
58004+#endif
58005+ return 0;
58006+}
58007+
58008+int
58009+gr_pid_is_chrooted(struct task_struct *p)
58010+{
58011+#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
58012+ if (!grsec_enable_chroot_findtask || !proc_is_chrooted(current) || p == NULL)
58013+ return 0;
58014+
58015+ if ((p->exit_state & (EXIT_ZOMBIE | EXIT_DEAD)) ||
58016+ !have_same_root(current, p)) {
58017+ return 1;
58018+ }
58019+#endif
58020+ return 0;
58021+}
58022+
58023+EXPORT_SYMBOL(gr_pid_is_chrooted);
58024+
58025+#if defined(CONFIG_GRKERNSEC_CHROOT_DOUBLE) || defined(CONFIG_GRKERNSEC_CHROOT_FCHDIR)
58026+int gr_is_outside_chroot(const struct dentry *u_dentry, const struct vfsmount *u_mnt)
58027+{
58028+ struct path path, currentroot;
58029+ int ret = 0;
58030+
58031+ path.dentry = (struct dentry *)u_dentry;
58032+ path.mnt = (struct vfsmount *)u_mnt;
58033+ get_fs_root(current->fs, &currentroot);
58034+ if (path_is_under(&path, &currentroot))
58035+ ret = 1;
58036+ path_put(&currentroot);
58037+
58038+ return ret;
58039+}
58040+#endif
58041+
58042+int
58043+gr_chroot_fchdir(struct dentry *u_dentry, struct vfsmount *u_mnt)
58044+{
58045+#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
58046+ if (!grsec_enable_chroot_fchdir)
58047+ return 1;
58048+
58049+ if (!proc_is_chrooted(current))
58050+ return 1;
58051+ else if (!gr_is_outside_chroot(u_dentry, u_mnt)) {
58052+ gr_log_fs_generic(GR_DONT_AUDIT, GR_CHROOT_FCHDIR_MSG, u_dentry, u_mnt);
58053+ return 0;
58054+ }
58055+#endif
58056+ return 1;
58057+}
58058+
58059+int
58060+gr_chroot_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
58061+ const time_t shm_createtime)
58062+{
58063+#ifdef CONFIG_GRKERNSEC_CHROOT_SHMAT
58064+ struct task_struct *p;
58065+ time_t starttime;
58066+
58067+ if (unlikely(!grsec_enable_chroot_shmat))
58068+ return 1;
58069+
58070+ if (likely(!proc_is_chrooted(current)))
58071+ return 1;
58072+
58073+ rcu_read_lock();
58074+ read_lock(&tasklist_lock);
58075+
58076+ if ((p = find_task_by_vpid_unrestricted(shm_cprid))) {
58077+ starttime = p->start_time.tv_sec;
58078+ if (time_before_eq((unsigned long)starttime, (unsigned long)shm_createtime)) {
58079+ if (have_same_root(current, p)) {
58080+ goto allow;
58081+ } else {
58082+ read_unlock(&tasklist_lock);
58083+ rcu_read_unlock();
58084+ gr_log_noargs(GR_DONT_AUDIT, GR_SHMAT_CHROOT_MSG);
58085+ return 0;
58086+ }
58087+ }
58088+ /* creator exited, pid reuse, fall through to next check */
58089+ }
58090+ if ((p = find_task_by_vpid_unrestricted(shm_lapid))) {
58091+ if (unlikely(!have_same_root(current, p))) {
58092+ read_unlock(&tasklist_lock);
58093+ rcu_read_unlock();
58094+ gr_log_noargs(GR_DONT_AUDIT, GR_SHMAT_CHROOT_MSG);
58095+ return 0;
58096+ }
58097+ }
58098+
58099+allow:
58100+ read_unlock(&tasklist_lock);
58101+ rcu_read_unlock();
58102+#endif
58103+ return 1;
58104+}
58105+
58106+void
58107+gr_log_chroot_exec(const struct dentry *dentry, const struct vfsmount *mnt)
58108+{
58109+#ifdef CONFIG_GRKERNSEC_CHROOT_EXECLOG
58110+ if (grsec_enable_chroot_execlog && proc_is_chrooted(current))
58111+ gr_log_fs_generic(GR_DO_AUDIT, GR_EXEC_CHROOT_MSG, dentry, mnt);
58112+#endif
58113+ return;
58114+}
58115+
58116+int
58117+gr_handle_chroot_mknod(const struct dentry *dentry,
58118+ const struct vfsmount *mnt, const int mode)
58119+{
58120+#ifdef CONFIG_GRKERNSEC_CHROOT_MKNOD
58121+ if (grsec_enable_chroot_mknod && !S_ISFIFO(mode) && !S_ISREG(mode) &&
58122+ proc_is_chrooted(current)) {
58123+ gr_log_fs_generic(GR_DONT_AUDIT, GR_MKNOD_CHROOT_MSG, dentry, mnt);
58124+ return -EPERM;
58125+ }
58126+#endif
58127+ return 0;
58128+}
58129+
58130+int
58131+gr_handle_chroot_mount(const struct dentry *dentry,
58132+ const struct vfsmount *mnt, const char *dev_name)
58133+{
58134+#ifdef CONFIG_GRKERNSEC_CHROOT_MOUNT
58135+ if (grsec_enable_chroot_mount && proc_is_chrooted(current)) {
58136+ gr_log_str_fs(GR_DONT_AUDIT, GR_MOUNT_CHROOT_MSG, dev_name ? dev_name : "none", dentry, mnt);
58137+ return -EPERM;
58138+ }
58139+#endif
58140+ return 0;
58141+}
58142+
58143+int
58144+gr_handle_chroot_pivot(void)
58145+{
58146+#ifdef CONFIG_GRKERNSEC_CHROOT_PIVOT
58147+ if (grsec_enable_chroot_pivot && proc_is_chrooted(current)) {
58148+ gr_log_noargs(GR_DONT_AUDIT, GR_PIVOT_CHROOT_MSG);
58149+ return -EPERM;
58150+ }
58151+#endif
58152+ return 0;
58153+}
58154+
58155+int
58156+gr_handle_chroot_chroot(const struct dentry *dentry, const struct vfsmount *mnt)
58157+{
58158+#ifdef CONFIG_GRKERNSEC_CHROOT_DOUBLE
58159+ if (grsec_enable_chroot_double && proc_is_chrooted(current) &&
58160+ !gr_is_outside_chroot(dentry, mnt)) {
58161+ gr_log_fs_generic(GR_DONT_AUDIT, GR_CHROOT_CHROOT_MSG, dentry, mnt);
58162+ return -EPERM;
58163+ }
58164+#endif
58165+ return 0;
58166+}
58167+
58168+extern const char *captab_log[];
58169+extern int captab_log_entries;
58170+
58171+int
58172+gr_task_chroot_is_capable(const struct task_struct *task, const struct cred *cred, const int cap)
58173+{
58174+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
58175+ if (grsec_enable_chroot_caps && proc_is_chrooted(task)) {
58176+ kernel_cap_t chroot_caps = GR_CHROOT_CAPS;
58177+ if (cap_raised(chroot_caps, cap)) {
58178+ if (cap_raised(cred->cap_effective, cap) && cap < captab_log_entries) {
58179+ gr_log_cap(GR_DONT_AUDIT, GR_CAP_CHROOT_MSG, task, captab_log[cap]);
58180+ }
58181+ return 0;
58182+ }
58183+ }
58184+#endif
58185+ return 1;
58186+}
58187+
58188+int
58189+gr_chroot_is_capable(const int cap)
58190+{
58191+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
58192+ return gr_task_chroot_is_capable(current, current_cred(), cap);
58193+#endif
58194+ return 1;
58195+}
58196+
58197+int
58198+gr_task_chroot_is_capable_nolog(const struct task_struct *task, const int cap)
58199+{
58200+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
58201+ if (grsec_enable_chroot_caps && proc_is_chrooted(task)) {
58202+ kernel_cap_t chroot_caps = GR_CHROOT_CAPS;
58203+ if (cap_raised(chroot_caps, cap)) {
58204+ return 0;
58205+ }
58206+ }
58207+#endif
58208+ return 1;
58209+}
58210+
58211+int
58212+gr_chroot_is_capable_nolog(const int cap)
58213+{
58214+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
58215+ return gr_task_chroot_is_capable_nolog(current, cap);
58216+#endif
58217+ return 1;
58218+}
58219+
58220+int
58221+gr_handle_chroot_sysctl(const int op)
58222+{
58223+#ifdef CONFIG_GRKERNSEC_CHROOT_SYSCTL
58224+ if (grsec_enable_chroot_sysctl && (op & MAY_WRITE) &&
58225+ proc_is_chrooted(current))
58226+ return -EACCES;
58227+#endif
58228+ return 0;
58229+}
58230+
58231+void
58232+gr_handle_chroot_chdir(struct path *path)
58233+{
58234+#ifdef CONFIG_GRKERNSEC_CHROOT_CHDIR
58235+ if (grsec_enable_chroot_chdir)
58236+ set_fs_pwd(current->fs, path);
58237+#endif
58238+ return;
58239+}
58240+
58241+int
58242+gr_handle_chroot_chmod(const struct dentry *dentry,
58243+ const struct vfsmount *mnt, const int mode)
58244+{
58245+#ifdef CONFIG_GRKERNSEC_CHROOT_CHMOD
58246+ /* allow chmod +s on directories, but not files */
58247+ if (grsec_enable_chroot_chmod && !S_ISDIR(dentry->d_inode->i_mode) &&
58248+ ((mode & S_ISUID) || ((mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))) &&
58249+ proc_is_chrooted(current)) {
58250+ gr_log_fs_generic(GR_DONT_AUDIT, GR_CHMOD_CHROOT_MSG, dentry, mnt);
58251+ return -EPERM;
58252+ }
58253+#endif
58254+ return 0;
58255+}
58256diff --git a/grsecurity/grsec_disabled.c b/grsecurity/grsec_disabled.c
58257new file mode 100644
58258index 0000000..b79fe50
58259--- /dev/null
58260+++ b/grsecurity/grsec_disabled.c
58261@@ -0,0 +1,442 @@
58262+#include <linux/kernel.h>
58263+#include <linux/module.h>
58264+#include <linux/sched.h>
58265+#include <linux/file.h>
58266+#include <linux/fs.h>
58267+#include <linux/kdev_t.h>
58268+#include <linux/net.h>
58269+#include <linux/in.h>
58270+#include <linux/ip.h>
58271+#include <linux/skbuff.h>
58272+#include <linux/sysctl.h>
58273+
58274+#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
58275+void
58276+pax_set_initial_flags(struct linux_binprm *bprm)
58277+{
58278+ return;
58279+}
58280+#endif
58281+
58282+#ifdef CONFIG_SYSCTL
58283+__u32
58284+gr_handle_sysctl(const struct ctl_table * table, const int op)
58285+{
58286+ return 0;
58287+}
58288+#endif
58289+
58290+#ifdef CONFIG_TASKSTATS
58291+int gr_is_taskstats_denied(int pid)
58292+{
58293+ return 0;
58294+}
58295+#endif
58296+
58297+int
58298+gr_acl_is_enabled(void)
58299+{
58300+ return 0;
58301+}
58302+
58303+void
58304+gr_handle_proc_create(const struct dentry *dentry, const struct inode *inode)
58305+{
58306+ return;
58307+}
58308+
58309+int
58310+gr_handle_rawio(const struct inode *inode)
58311+{
58312+ return 0;
58313+}
58314+
58315+void
58316+gr_acl_handle_psacct(struct task_struct *task, const long code)
58317+{
58318+ return;
58319+}
58320+
58321+int
58322+gr_handle_ptrace(struct task_struct *task, const long request)
58323+{
58324+ return 0;
58325+}
58326+
58327+int
58328+gr_handle_proc_ptrace(struct task_struct *task)
58329+{
58330+ return 0;
58331+}
58332+
58333+void
58334+gr_learn_resource(const struct task_struct *task,
58335+ const int res, const unsigned long wanted, const int gt)
58336+{
58337+ return;
58338+}
58339+
58340+int
58341+gr_set_acls(const int type)
58342+{
58343+ return 0;
58344+}
58345+
58346+int
58347+gr_check_hidden_task(const struct task_struct *tsk)
58348+{
58349+ return 0;
58350+}
58351+
58352+int
58353+gr_check_protected_task(const struct task_struct *task)
58354+{
58355+ return 0;
58356+}
58357+
58358+int
58359+gr_check_protected_task_fowner(struct pid *pid, enum pid_type type)
58360+{
58361+ return 0;
58362+}
58363+
58364+void
58365+gr_copy_label(struct task_struct *tsk)
58366+{
58367+ return;
58368+}
58369+
58370+void
58371+gr_set_pax_flags(struct task_struct *task)
58372+{
58373+ return;
58374+}
58375+
58376+int
58377+gr_set_proc_label(const struct dentry *dentry, const struct vfsmount *mnt,
58378+ const int unsafe_share)
58379+{
58380+ return 0;
58381+}
58382+
58383+void
58384+gr_handle_delete(const ino_t ino, const dev_t dev)
58385+{
58386+ return;
58387+}
58388+
58389+void
58390+gr_handle_create(const struct dentry *dentry, const struct vfsmount *mnt)
58391+{
58392+ return;
58393+}
58394+
58395+void
58396+gr_handle_crash(struct task_struct *task, const int sig)
58397+{
58398+ return;
58399+}
58400+
58401+int
58402+gr_check_crash_exec(const struct file *filp)
58403+{
58404+ return 0;
58405+}
58406+
58407+int
58408+gr_check_crash_uid(const uid_t uid)
58409+{
58410+ return 0;
58411+}
58412+
58413+void
58414+gr_handle_rename(struct inode *old_dir, struct inode *new_dir,
58415+ struct dentry *old_dentry,
58416+ struct dentry *new_dentry,
58417+ struct vfsmount *mnt, const __u8 replace)
58418+{
58419+ return;
58420+}
58421+
58422+int
58423+gr_search_socket(const int family, const int type, const int protocol)
58424+{
58425+ return 1;
58426+}
58427+
58428+int
58429+gr_search_connectbind(const int mode, const struct socket *sock,
58430+ const struct sockaddr_in *addr)
58431+{
58432+ return 0;
58433+}
58434+
58435+void
58436+gr_handle_alertkill(struct task_struct *task)
58437+{
58438+ return;
58439+}
58440+
58441+__u32
58442+gr_acl_handle_execve(const struct dentry * dentry, const struct vfsmount * mnt)
58443+{
58444+ return 1;
58445+}
58446+
58447+__u32
58448+gr_acl_handle_hidden_file(const struct dentry * dentry,
58449+ const struct vfsmount * mnt)
58450+{
58451+ return 1;
58452+}
58453+
58454+__u32
58455+gr_acl_handle_open(const struct dentry * dentry, const struct vfsmount * mnt,
58456+ int acc_mode)
58457+{
58458+ return 1;
58459+}
58460+
58461+__u32
58462+gr_acl_handle_rmdir(const struct dentry * dentry, const struct vfsmount * mnt)
58463+{
58464+ return 1;
58465+}
58466+
58467+__u32
58468+gr_acl_handle_unlink(const struct dentry * dentry, const struct vfsmount * mnt)
58469+{
58470+ return 1;
58471+}
58472+
58473+int
58474+gr_acl_handle_mmap(const struct file *file, const unsigned long prot,
58475+ unsigned int *vm_flags)
58476+{
58477+ return 1;
58478+}
58479+
58480+__u32
58481+gr_acl_handle_truncate(const struct dentry * dentry,
58482+ const struct vfsmount * mnt)
58483+{
58484+ return 1;
58485+}
58486+
58487+__u32
58488+gr_acl_handle_utime(const struct dentry * dentry, const struct vfsmount * mnt)
58489+{
58490+ return 1;
58491+}
58492+
58493+__u32
58494+gr_acl_handle_access(const struct dentry * dentry,
58495+ const struct vfsmount * mnt, const int fmode)
58496+{
58497+ return 1;
58498+}
58499+
58500+__u32
58501+gr_acl_handle_chmod(const struct dentry * dentry, const struct vfsmount * mnt,
58502+ umode_t *mode)
58503+{
58504+ return 1;
58505+}
58506+
58507+__u32
58508+gr_acl_handle_chown(const struct dentry * dentry, const struct vfsmount * mnt)
58509+{
58510+ return 1;
58511+}
58512+
58513+__u32
58514+gr_acl_handle_setxattr(const struct dentry * dentry, const struct vfsmount * mnt)
58515+{
58516+ return 1;
58517+}
58518+
58519+void
58520+grsecurity_init(void)
58521+{
58522+ return;
58523+}
58524+
58525+umode_t gr_acl_umask(void)
58526+{
58527+ return 0;
58528+}
58529+
58530+__u32
58531+gr_acl_handle_mknod(const struct dentry * new_dentry,
58532+ const struct dentry * parent_dentry,
58533+ const struct vfsmount * parent_mnt,
58534+ const int mode)
58535+{
58536+ return 1;
58537+}
58538+
58539+__u32
58540+gr_acl_handle_mkdir(const struct dentry * new_dentry,
58541+ const struct dentry * parent_dentry,
58542+ const struct vfsmount * parent_mnt)
58543+{
58544+ return 1;
58545+}
58546+
58547+__u32
58548+gr_acl_handle_symlink(const struct dentry * new_dentry,
58549+ const struct dentry * parent_dentry,
58550+ const struct vfsmount * parent_mnt, const char *from)
58551+{
58552+ return 1;
58553+}
58554+
58555+__u32
58556+gr_acl_handle_link(const struct dentry * new_dentry,
58557+ const struct dentry * parent_dentry,
58558+ const struct vfsmount * parent_mnt,
58559+ const struct dentry * old_dentry,
58560+ const struct vfsmount * old_mnt, const char *to)
58561+{
58562+ return 1;
58563+}
58564+
58565+int
58566+gr_acl_handle_rename(const struct dentry *new_dentry,
58567+ const struct dentry *parent_dentry,
58568+ const struct vfsmount *parent_mnt,
58569+ const struct dentry *old_dentry,
58570+ const struct inode *old_parent_inode,
58571+ const struct vfsmount *old_mnt, const char *newname)
58572+{
58573+ return 0;
58574+}
58575+
58576+int
58577+gr_acl_handle_filldir(const struct file *file, const char *name,
58578+ const int namelen, const ino_t ino)
58579+{
58580+ return 1;
58581+}
58582+
58583+int
58584+gr_handle_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
58585+ const time_t shm_createtime, const uid_t cuid, const int shmid)
58586+{
58587+ return 1;
58588+}
58589+
58590+int
58591+gr_search_bind(const struct socket *sock, const struct sockaddr_in *addr)
58592+{
58593+ return 0;
58594+}
58595+
58596+int
58597+gr_search_accept(const struct socket *sock)
58598+{
58599+ return 0;
58600+}
58601+
58602+int
58603+gr_search_listen(const struct socket *sock)
58604+{
58605+ return 0;
58606+}
58607+
58608+int
58609+gr_search_connect(const struct socket *sock, const struct sockaddr_in *addr)
58610+{
58611+ return 0;
58612+}
58613+
58614+__u32
58615+gr_acl_handle_unix(const struct dentry * dentry, const struct vfsmount * mnt)
58616+{
58617+ return 1;
58618+}
58619+
58620+__u32
58621+gr_acl_handle_creat(const struct dentry * dentry,
58622+ const struct dentry * p_dentry,
58623+ const struct vfsmount * p_mnt, int open_flags, int acc_mode,
58624+ const int imode)
58625+{
58626+ return 1;
58627+}
58628+
58629+void
58630+gr_acl_handle_exit(void)
58631+{
58632+ return;
58633+}
58634+
58635+int
58636+gr_acl_handle_mprotect(const struct file *file, const unsigned long prot)
58637+{
58638+ return 1;
58639+}
58640+
58641+void
58642+gr_set_role_label(const uid_t uid, const gid_t gid)
58643+{
58644+ return;
58645+}
58646+
58647+int
58648+gr_acl_handle_procpidmem(const struct task_struct *task)
58649+{
58650+ return 0;
58651+}
58652+
58653+int
58654+gr_search_udp_recvmsg(const struct sock *sk, const struct sk_buff *skb)
58655+{
58656+ return 0;
58657+}
58658+
58659+int
58660+gr_search_udp_sendmsg(const struct sock *sk, const struct sockaddr_in *addr)
58661+{
58662+ return 0;
58663+}
58664+
58665+void
58666+gr_set_kernel_label(struct task_struct *task)
58667+{
58668+ return;
58669+}
58670+
58671+int
58672+gr_check_user_change(int real, int effective, int fs)
58673+{
58674+ return 0;
58675+}
58676+
58677+int
58678+gr_check_group_change(int real, int effective, int fs)
58679+{
58680+ return 0;
58681+}
58682+
58683+int gr_acl_enable_at_secure(void)
58684+{
58685+ return 0;
58686+}
58687+
58688+dev_t gr_get_dev_from_dentry(struct dentry *dentry)
58689+{
58690+ return dentry->d_inode->i_sb->s_dev;
58691+}
58692+
58693+void gr_put_exec_file(struct task_struct *task)
58694+{
58695+ return;
58696+}
58697+
58698+EXPORT_SYMBOL(gr_learn_resource);
58699+EXPORT_SYMBOL(gr_set_kernel_label);
58700+#ifdef CONFIG_SECURITY
58701+EXPORT_SYMBOL(gr_check_user_change);
58702+EXPORT_SYMBOL(gr_check_group_change);
58703+#endif
58704diff --git a/grsecurity/grsec_exec.c b/grsecurity/grsec_exec.c
58705new file mode 100644
58706index 0000000..abfa971
58707--- /dev/null
58708+++ b/grsecurity/grsec_exec.c
58709@@ -0,0 +1,174 @@
58710+#include <linux/kernel.h>
58711+#include <linux/sched.h>
58712+#include <linux/file.h>
58713+#include <linux/binfmts.h>
58714+#include <linux/fs.h>
58715+#include <linux/types.h>
58716+#include <linux/grdefs.h>
58717+#include <linux/grsecurity.h>
58718+#include <linux/grinternal.h>
58719+#include <linux/capability.h>
58720+#include <linux/module.h>
58721+
58722+#include <asm/uaccess.h>
58723+
58724+#ifdef CONFIG_GRKERNSEC_EXECLOG
58725+static char gr_exec_arg_buf[132];
58726+static DEFINE_MUTEX(gr_exec_arg_mutex);
58727+#endif
58728+
58729+extern const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr);
58730+
58731+void
58732+gr_handle_exec_args(struct linux_binprm *bprm, struct user_arg_ptr argv)
58733+{
58734+#ifdef CONFIG_GRKERNSEC_EXECLOG
58735+ char *grarg = gr_exec_arg_buf;
58736+ unsigned int i, x, execlen = 0;
58737+ char c;
58738+
58739+ if (!((grsec_enable_execlog && grsec_enable_group &&
58740+ in_group_p(grsec_audit_gid))
58741+ || (grsec_enable_execlog && !grsec_enable_group)))
58742+ return;
58743+
58744+ mutex_lock(&gr_exec_arg_mutex);
58745+ memset(grarg, 0, sizeof(gr_exec_arg_buf));
58746+
58747+ for (i = 0; i < bprm->argc && execlen < 128; i++) {
58748+ const char __user *p;
58749+ unsigned int len;
58750+
58751+ p = get_user_arg_ptr(argv, i);
58752+ if (IS_ERR(p))
58753+ goto log;
58754+
58755+ len = strnlen_user(p, 128 - execlen);
58756+ if (len > 128 - execlen)
58757+ len = 128 - execlen;
58758+ else if (len > 0)
58759+ len--;
58760+ if (copy_from_user(grarg + execlen, p, len))
58761+ goto log;
58762+
58763+ /* rewrite unprintable characters */
58764+ for (x = 0; x < len; x++) {
58765+ c = *(grarg + execlen + x);
58766+ if (c < 32 || c > 126)
58767+ *(grarg + execlen + x) = ' ';
58768+ }
58769+
58770+ execlen += len;
58771+ *(grarg + execlen) = ' ';
58772+ *(grarg + execlen + 1) = '\0';
58773+ execlen++;
58774+ }
58775+
58776+ log:
58777+ gr_log_fs_str(GR_DO_AUDIT, GR_EXEC_AUDIT_MSG, bprm->file->f_path.dentry,
58778+ bprm->file->f_path.mnt, grarg);
58779+ mutex_unlock(&gr_exec_arg_mutex);
58780+#endif
58781+ return;
58782+}
58783+
58784+#ifdef CONFIG_GRKERNSEC
58785+extern int gr_acl_is_capable(const int cap);
58786+extern int gr_acl_is_capable_nolog(const int cap);
58787+extern int gr_task_acl_is_capable(const struct task_struct *task, const struct cred *cred, const int cap);
58788+extern int gr_task_acl_is_capable_nolog(const struct task_struct *task, const int cap);
58789+extern int gr_chroot_is_capable(const int cap);
58790+extern int gr_chroot_is_capable_nolog(const int cap);
58791+extern int gr_task_chroot_is_capable(const struct task_struct *task, const struct cred *cred, const int cap);
58792+extern int gr_task_chroot_is_capable_nolog(const struct task_struct *task, const int cap);
58793+#endif
58794+
58795+const char *captab_log[] = {
58796+ "CAP_CHOWN",
58797+ "CAP_DAC_OVERRIDE",
58798+ "CAP_DAC_READ_SEARCH",
58799+ "CAP_FOWNER",
58800+ "CAP_FSETID",
58801+ "CAP_KILL",
58802+ "CAP_SETGID",
58803+ "CAP_SETUID",
58804+ "CAP_SETPCAP",
58805+ "CAP_LINUX_IMMUTABLE",
58806+ "CAP_NET_BIND_SERVICE",
58807+ "CAP_NET_BROADCAST",
58808+ "CAP_NET_ADMIN",
58809+ "CAP_NET_RAW",
58810+ "CAP_IPC_LOCK",
58811+ "CAP_IPC_OWNER",
58812+ "CAP_SYS_MODULE",
58813+ "CAP_SYS_RAWIO",
58814+ "CAP_SYS_CHROOT",
58815+ "CAP_SYS_PTRACE",
58816+ "CAP_SYS_PACCT",
58817+ "CAP_SYS_ADMIN",
58818+ "CAP_SYS_BOOT",
58819+ "CAP_SYS_NICE",
58820+ "CAP_SYS_RESOURCE",
58821+ "CAP_SYS_TIME",
58822+ "CAP_SYS_TTY_CONFIG",
58823+ "CAP_MKNOD",
58824+ "CAP_LEASE",
58825+ "CAP_AUDIT_WRITE",
58826+ "CAP_AUDIT_CONTROL",
58827+ "CAP_SETFCAP",
58828+ "CAP_MAC_OVERRIDE",
58829+ "CAP_MAC_ADMIN",
58830+ "CAP_SYSLOG",
58831+ "CAP_WAKE_ALARM"
58832+};
58833+
58834+int captab_log_entries = sizeof(captab_log)/sizeof(captab_log[0]);
58835+
58836+int gr_is_capable(const int cap)
58837+{
58838+#ifdef CONFIG_GRKERNSEC
58839+ if (gr_acl_is_capable(cap) && gr_chroot_is_capable(cap))
58840+ return 1;
58841+ return 0;
58842+#else
58843+ return 1;
58844+#endif
58845+}
58846+
58847+int gr_task_is_capable(const struct task_struct *task, const struct cred *cred, const int cap)
58848+{
58849+#ifdef CONFIG_GRKERNSEC
58850+ if (gr_task_acl_is_capable(task, cred, cap) && gr_task_chroot_is_capable(task, cred, cap))
58851+ return 1;
58852+ return 0;
58853+#else
58854+ return 1;
58855+#endif
58856+}
58857+
58858+int gr_is_capable_nolog(const int cap)
58859+{
58860+#ifdef CONFIG_GRKERNSEC
58861+ if (gr_acl_is_capable_nolog(cap) && gr_chroot_is_capable_nolog(cap))
58862+ return 1;
58863+ return 0;
58864+#else
58865+ return 1;
58866+#endif
58867+}
58868+
58869+int gr_task_is_capable_nolog(const struct task_struct *task, const int cap)
58870+{
58871+#ifdef CONFIG_GRKERNSEC
58872+ if (gr_task_acl_is_capable_nolog(task, cap) && gr_task_chroot_is_capable_nolog(task, cap))
58873+ return 1;
58874+ return 0;
58875+#else
58876+ return 1;
58877+#endif
58878+}
58879+
58880+EXPORT_SYMBOL(gr_is_capable);
58881+EXPORT_SYMBOL(gr_is_capable_nolog);
58882+EXPORT_SYMBOL(gr_task_is_capable);
58883+EXPORT_SYMBOL(gr_task_is_capable_nolog);
58884diff --git a/grsecurity/grsec_fifo.c b/grsecurity/grsec_fifo.c
58885new file mode 100644
58886index 0000000..d3ee748
58887--- /dev/null
58888+++ b/grsecurity/grsec_fifo.c
58889@@ -0,0 +1,24 @@
58890+#include <linux/kernel.h>
58891+#include <linux/sched.h>
58892+#include <linux/fs.h>
58893+#include <linux/file.h>
58894+#include <linux/grinternal.h>
58895+
58896+int
58897+gr_handle_fifo(const struct dentry *dentry, const struct vfsmount *mnt,
58898+ const struct dentry *dir, const int flag, const int acc_mode)
58899+{
58900+#ifdef CONFIG_GRKERNSEC_FIFO
58901+ const struct cred *cred = current_cred();
58902+
58903+ if (grsec_enable_fifo && S_ISFIFO(dentry->d_inode->i_mode) &&
58904+ !(flag & O_EXCL) && (dir->d_inode->i_mode & S_ISVTX) &&
58905+ (dentry->d_inode->i_uid != dir->d_inode->i_uid) &&
58906+ (cred->fsuid != dentry->d_inode->i_uid)) {
58907+ if (!inode_permission(dentry->d_inode, acc_mode))
58908+ gr_log_fs_int2(GR_DONT_AUDIT, GR_FIFO_MSG, dentry, mnt, dentry->d_inode->i_uid, dentry->d_inode->i_gid);
58909+ return -EACCES;
58910+ }
58911+#endif
58912+ return 0;
58913+}
58914diff --git a/grsecurity/grsec_fork.c b/grsecurity/grsec_fork.c
58915new file mode 100644
58916index 0000000..8ca18bf
58917--- /dev/null
58918+++ b/grsecurity/grsec_fork.c
58919@@ -0,0 +1,23 @@
58920+#include <linux/kernel.h>
58921+#include <linux/sched.h>
58922+#include <linux/grsecurity.h>
58923+#include <linux/grinternal.h>
58924+#include <linux/errno.h>
58925+
58926+void
58927+gr_log_forkfail(const int retval)
58928+{
58929+#ifdef CONFIG_GRKERNSEC_FORKFAIL
58930+ if (grsec_enable_forkfail && (retval == -EAGAIN || retval == -ENOMEM)) {
58931+ switch (retval) {
58932+ case -EAGAIN:
58933+ gr_log_str(GR_DONT_AUDIT, GR_FAILFORK_MSG, "EAGAIN");
58934+ break;
58935+ case -ENOMEM:
58936+ gr_log_str(GR_DONT_AUDIT, GR_FAILFORK_MSG, "ENOMEM");
58937+ break;
58938+ }
58939+ }
58940+#endif
58941+ return;
58942+}
58943diff --git a/grsecurity/grsec_init.c b/grsecurity/grsec_init.c
58944new file mode 100644
58945index 0000000..05a6015
58946--- /dev/null
58947+++ b/grsecurity/grsec_init.c
58948@@ -0,0 +1,283 @@
58949+#include <linux/kernel.h>
58950+#include <linux/sched.h>
58951+#include <linux/mm.h>
58952+#include <linux/gracl.h>
58953+#include <linux/slab.h>
58954+#include <linux/vmalloc.h>
58955+#include <linux/percpu.h>
58956+#include <linux/module.h>
58957+
58958+int grsec_enable_ptrace_readexec;
58959+int grsec_enable_setxid;
58960+int grsec_enable_symlinkown;
58961+int grsec_symlinkown_gid;
58962+int grsec_enable_brute;
58963+int grsec_enable_link;
58964+int grsec_enable_dmesg;
58965+int grsec_enable_harden_ptrace;
58966+int grsec_enable_fifo;
58967+int grsec_enable_execlog;
58968+int grsec_enable_signal;
58969+int grsec_enable_forkfail;
58970+int grsec_enable_audit_ptrace;
58971+int grsec_enable_time;
58972+int grsec_enable_audit_textrel;
58973+int grsec_enable_group;
58974+int grsec_audit_gid;
58975+int grsec_enable_chdir;
58976+int grsec_enable_mount;
58977+int grsec_enable_rofs;
58978+int grsec_enable_chroot_findtask;
58979+int grsec_enable_chroot_mount;
58980+int grsec_enable_chroot_shmat;
58981+int grsec_enable_chroot_fchdir;
58982+int grsec_enable_chroot_double;
58983+int grsec_enable_chroot_pivot;
58984+int grsec_enable_chroot_chdir;
58985+int grsec_enable_chroot_chmod;
58986+int grsec_enable_chroot_mknod;
58987+int grsec_enable_chroot_nice;
58988+int grsec_enable_chroot_execlog;
58989+int grsec_enable_chroot_caps;
58990+int grsec_enable_chroot_sysctl;
58991+int grsec_enable_chroot_unix;
58992+int grsec_enable_tpe;
58993+int grsec_tpe_gid;
58994+int grsec_enable_blackhole;
58995+#ifdef CONFIG_IPV6_MODULE
58996+EXPORT_SYMBOL(grsec_enable_blackhole);
58997+#endif
58998+int grsec_lastack_retries;
58999+int grsec_enable_tpe_all;
59000+int grsec_enable_tpe_invert;
59001+int grsec_enable_socket_all;
59002+int grsec_socket_all_gid;
59003+int grsec_enable_socket_client;
59004+int grsec_socket_client_gid;
59005+int grsec_enable_socket_server;
59006+int grsec_socket_server_gid;
59007+int grsec_resource_logging;
59008+int grsec_disable_privio;
59009+int grsec_enable_log_rwxmaps;
59010+int grsec_lock;
59011+
59012+DEFINE_SPINLOCK(grsec_alert_lock);
59013+unsigned long grsec_alert_wtime = 0;
59014+unsigned long grsec_alert_fyet = 0;
59015+
59016+DEFINE_SPINLOCK(grsec_audit_lock);
59017+
59018+DEFINE_RWLOCK(grsec_exec_file_lock);
59019+
59020+char *gr_shared_page[4];
59021+
59022+char *gr_alert_log_fmt;
59023+char *gr_audit_log_fmt;
59024+char *gr_alert_log_buf;
59025+char *gr_audit_log_buf;
59026+
59027+extern struct gr_arg *gr_usermode;
59028+extern unsigned char *gr_system_salt;
59029+extern unsigned char *gr_system_sum;
59030+
59031+void __init
59032+grsecurity_init(void)
59033+{
59034+ int j;
59035+ /* create the per-cpu shared pages */
59036+
59037+#ifdef CONFIG_X86
59038+ memset((char *)(0x41a + PAGE_OFFSET), 0, 36);
59039+#endif
59040+
59041+ for (j = 0; j < 4; j++) {
59042+ gr_shared_page[j] = (char *)__alloc_percpu(PAGE_SIZE, __alignof__(unsigned long long));
59043+ if (gr_shared_page[j] == NULL) {
59044+ panic("Unable to allocate grsecurity shared page");
59045+ return;
59046+ }
59047+ }
59048+
59049+ /* allocate log buffers */
59050+ gr_alert_log_fmt = kmalloc(512, GFP_KERNEL);
59051+ if (!gr_alert_log_fmt) {
59052+ panic("Unable to allocate grsecurity alert log format buffer");
59053+ return;
59054+ }
59055+ gr_audit_log_fmt = kmalloc(512, GFP_KERNEL);
59056+ if (!gr_audit_log_fmt) {
59057+ panic("Unable to allocate grsecurity audit log format buffer");
59058+ return;
59059+ }
59060+ gr_alert_log_buf = (char *) get_zeroed_page(GFP_KERNEL);
59061+ if (!gr_alert_log_buf) {
59062+ panic("Unable to allocate grsecurity alert log buffer");
59063+ return;
59064+ }
59065+ gr_audit_log_buf = (char *) get_zeroed_page(GFP_KERNEL);
59066+ if (!gr_audit_log_buf) {
59067+ panic("Unable to allocate grsecurity audit log buffer");
59068+ return;
59069+ }
59070+
59071+ /* allocate memory for authentication structure */
59072+ gr_usermode = kmalloc(sizeof(struct gr_arg), GFP_KERNEL);
59073+ gr_system_salt = kmalloc(GR_SALT_LEN, GFP_KERNEL);
59074+ gr_system_sum = kmalloc(GR_SHA_LEN, GFP_KERNEL);
59075+
59076+ if (!gr_usermode || !gr_system_salt || !gr_system_sum) {
59077+ panic("Unable to allocate grsecurity authentication structure");
59078+ return;
59079+ }
59080+
59081+
59082+#ifdef CONFIG_GRKERNSEC_IO
59083+#if !defined(CONFIG_GRKERNSEC_SYSCTL_DISTRO)
59084+ grsec_disable_privio = 1;
59085+#elif defined(CONFIG_GRKERNSEC_SYSCTL_ON)
59086+ grsec_disable_privio = 1;
59087+#else
59088+ grsec_disable_privio = 0;
59089+#endif
59090+#endif
59091+
59092+#ifdef CONFIG_GRKERNSEC_TPE_INVERT
59093+ /* for backward compatibility, tpe_invert always defaults to on if
59094+ enabled in the kernel
59095+ */
59096+ grsec_enable_tpe_invert = 1;
59097+#endif
59098+
59099+#if !defined(CONFIG_GRKERNSEC_SYSCTL) || defined(CONFIG_GRKERNSEC_SYSCTL_ON)
59100+#ifndef CONFIG_GRKERNSEC_SYSCTL
59101+ grsec_lock = 1;
59102+#endif
59103+
59104+#ifdef CONFIG_GRKERNSEC_AUDIT_TEXTREL
59105+ grsec_enable_audit_textrel = 1;
59106+#endif
59107+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
59108+ grsec_enable_log_rwxmaps = 1;
59109+#endif
59110+#ifdef CONFIG_GRKERNSEC_AUDIT_GROUP
59111+ grsec_enable_group = 1;
59112+ grsec_audit_gid = CONFIG_GRKERNSEC_AUDIT_GID;
59113+#endif
59114+#ifdef CONFIG_GRKERNSEC_PTRACE_READEXEC
59115+ grsec_enable_ptrace_readexec = 1;
59116+#endif
59117+#ifdef CONFIG_GRKERNSEC_AUDIT_CHDIR
59118+ grsec_enable_chdir = 1;
59119+#endif
59120+#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
59121+ grsec_enable_harden_ptrace = 1;
59122+#endif
59123+#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
59124+ grsec_enable_mount = 1;
59125+#endif
59126+#ifdef CONFIG_GRKERNSEC_LINK
59127+ grsec_enable_link = 1;
59128+#endif
59129+#ifdef CONFIG_GRKERNSEC_BRUTE
59130+ grsec_enable_brute = 1;
59131+#endif
59132+#ifdef CONFIG_GRKERNSEC_DMESG
59133+ grsec_enable_dmesg = 1;
59134+#endif
59135+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
59136+ grsec_enable_blackhole = 1;
59137+ grsec_lastack_retries = 4;
59138+#endif
59139+#ifdef CONFIG_GRKERNSEC_FIFO
59140+ grsec_enable_fifo = 1;
59141+#endif
59142+#ifdef CONFIG_GRKERNSEC_EXECLOG
59143+ grsec_enable_execlog = 1;
59144+#endif
59145+#ifdef CONFIG_GRKERNSEC_SETXID
59146+ grsec_enable_setxid = 1;
59147+#endif
59148+#ifdef CONFIG_GRKERNSEC_SIGNAL
59149+ grsec_enable_signal = 1;
59150+#endif
59151+#ifdef CONFIG_GRKERNSEC_FORKFAIL
59152+ grsec_enable_forkfail = 1;
59153+#endif
59154+#ifdef CONFIG_GRKERNSEC_TIME
59155+ grsec_enable_time = 1;
59156+#endif
59157+#ifdef CONFIG_GRKERNSEC_RESLOG
59158+ grsec_resource_logging = 1;
59159+#endif
59160+#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
59161+ grsec_enable_chroot_findtask = 1;
59162+#endif
59163+#ifdef CONFIG_GRKERNSEC_CHROOT_UNIX
59164+ grsec_enable_chroot_unix = 1;
59165+#endif
59166+#ifdef CONFIG_GRKERNSEC_CHROOT_MOUNT
59167+ grsec_enable_chroot_mount = 1;
59168+#endif
59169+#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
59170+ grsec_enable_chroot_fchdir = 1;
59171+#endif
59172+#ifdef CONFIG_GRKERNSEC_CHROOT_SHMAT
59173+ grsec_enable_chroot_shmat = 1;
59174+#endif
59175+#ifdef CONFIG_GRKERNSEC_AUDIT_PTRACE
59176+ grsec_enable_audit_ptrace = 1;
59177+#endif
59178+#ifdef CONFIG_GRKERNSEC_CHROOT_DOUBLE
59179+ grsec_enable_chroot_double = 1;
59180+#endif
59181+#ifdef CONFIG_GRKERNSEC_CHROOT_PIVOT
59182+ grsec_enable_chroot_pivot = 1;
59183+#endif
59184+#ifdef CONFIG_GRKERNSEC_CHROOT_CHDIR
59185+ grsec_enable_chroot_chdir = 1;
59186+#endif
59187+#ifdef CONFIG_GRKERNSEC_CHROOT_CHMOD
59188+ grsec_enable_chroot_chmod = 1;
59189+#endif
59190+#ifdef CONFIG_GRKERNSEC_CHROOT_MKNOD
59191+ grsec_enable_chroot_mknod = 1;
59192+#endif
59193+#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
59194+ grsec_enable_chroot_nice = 1;
59195+#endif
59196+#ifdef CONFIG_GRKERNSEC_CHROOT_EXECLOG
59197+ grsec_enable_chroot_execlog = 1;
59198+#endif
59199+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
59200+ grsec_enable_chroot_caps = 1;
59201+#endif
59202+#ifdef CONFIG_GRKERNSEC_CHROOT_SYSCTL
59203+ grsec_enable_chroot_sysctl = 1;
59204+#endif
59205+#ifdef CONFIG_GRKERNSEC_SYMLINKOWN
59206+ grsec_enable_symlinkown = 1;
59207+ grsec_symlinkown_gid = CONFIG_GRKERNSEC_SYMLINKOWN_GID;
59208+#endif
59209+#ifdef CONFIG_GRKERNSEC_TPE
59210+ grsec_enable_tpe = 1;
59211+ grsec_tpe_gid = CONFIG_GRKERNSEC_TPE_GID;
59212+#ifdef CONFIG_GRKERNSEC_TPE_ALL
59213+ grsec_enable_tpe_all = 1;
59214+#endif
59215+#endif
59216+#ifdef CONFIG_GRKERNSEC_SOCKET_ALL
59217+ grsec_enable_socket_all = 1;
59218+ grsec_socket_all_gid = CONFIG_GRKERNSEC_SOCKET_ALL_GID;
59219+#endif
59220+#ifdef CONFIG_GRKERNSEC_SOCKET_CLIENT
59221+ grsec_enable_socket_client = 1;
59222+ grsec_socket_client_gid = CONFIG_GRKERNSEC_SOCKET_CLIENT_GID;
59223+#endif
59224+#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
59225+ grsec_enable_socket_server = 1;
59226+ grsec_socket_server_gid = CONFIG_GRKERNSEC_SOCKET_SERVER_GID;
59227+#endif
59228+#endif
59229+
59230+ return;
59231+}
59232diff --git a/grsecurity/grsec_link.c b/grsecurity/grsec_link.c
59233new file mode 100644
59234index 0000000..589481f
59235--- /dev/null
59236+++ b/grsecurity/grsec_link.c
59237@@ -0,0 +1,58 @@
59238+#include <linux/kernel.h>
59239+#include <linux/sched.h>
59240+#include <linux/fs.h>
59241+#include <linux/file.h>
59242+#include <linux/grinternal.h>
59243+
59244+int gr_handle_symlink_owner(const struct path *link, const struct inode *target)
59245+{
59246+#ifdef CONFIG_GRKERNSEC_SYMLINKOWN
59247+ const struct inode *link_inode = link->dentry->d_inode;
59248+
59249+ if (grsec_enable_symlinkown && in_group_p(grsec_symlinkown_gid) &&
59250+ /* ignore root-owned links, e.g. /proc/self */
59251+ !uid_eq(link_inode->i_uid, GLOBAL_ROOT_UID) && target &&
59252+ !uid_eq(link_inode->i_uid, target->i_uid)) {
59253+ gr_log_fs_int2(GR_DONT_AUDIT, GR_SYMLINKOWNER_MSG, link->dentry, link->mnt, link_inode->i_uid, target->i_uid);
59254+ return 1;
59255+ }
59256+#endif
59257+ return 0;
59258+}
59259+
59260+int
59261+gr_handle_follow_link(const struct inode *parent,
59262+ const struct inode *inode,
59263+ const struct dentry *dentry, const struct vfsmount *mnt)
59264+{
59265+#ifdef CONFIG_GRKERNSEC_LINK
59266+ const struct cred *cred = current_cred();
59267+
59268+ if (grsec_enable_link && S_ISLNK(inode->i_mode) &&
59269+ (parent->i_mode & S_ISVTX) && !uid_eq(parent->i_uid, inode->i_uid) &&
59270+ (parent->i_mode & S_IWOTH) && !uid_eq(cred->fsuid, inode->i_uid)) {
59271+ gr_log_fs_int2(GR_DONT_AUDIT, GR_SYMLINK_MSG, dentry, mnt, inode->i_uid, inode->i_gid);
59272+ return -EACCES;
59273+ }
59274+#endif
59275+ return 0;
59276+}
59277+
59278+int
59279+gr_handle_hardlink(const struct dentry *dentry,
59280+ const struct vfsmount *mnt,
59281+ struct inode *inode, const int mode, const char *to)
59282+{
59283+#ifdef CONFIG_GRKERNSEC_LINK
59284+ const struct cred *cred = current_cred();
59285+
59286+ if (grsec_enable_link && !uid_eq(cred->fsuid, inode->i_uid) &&
59287+ (!S_ISREG(mode) || is_privileged_binary(dentry) ||
59288+ (inode_permission(inode, MAY_READ | MAY_WRITE))) &&
59289+ !capable(CAP_FOWNER) && !uid_eq(cred->uid, GLOBAL_ROOT_UID)) {
59290+ gr_log_fs_int2_str(GR_DONT_AUDIT, GR_HARDLINK_MSG, dentry, mnt, inode->i_uid, inode->i_gid, to);
59291+ return -EPERM;
59292+ }
59293+#endif
59294+ return 0;
59295+}
59296diff --git a/grsecurity/grsec_log.c b/grsecurity/grsec_log.c
59297new file mode 100644
59298index 0000000..a45d2e9
59299--- /dev/null
59300+++ b/grsecurity/grsec_log.c
59301@@ -0,0 +1,322 @@
59302+#include <linux/kernel.h>
59303+#include <linux/sched.h>
59304+#include <linux/file.h>
59305+#include <linux/tty.h>
59306+#include <linux/fs.h>
59307+#include <linux/grinternal.h>
59308+
59309+#ifdef CONFIG_TREE_PREEMPT_RCU
59310+#define DISABLE_PREEMPT() preempt_disable()
59311+#define ENABLE_PREEMPT() preempt_enable()
59312+#else
59313+#define DISABLE_PREEMPT()
59314+#define ENABLE_PREEMPT()
59315+#endif
59316+
59317+#define BEGIN_LOCKS(x) \
59318+ DISABLE_PREEMPT(); \
59319+ rcu_read_lock(); \
59320+ read_lock(&tasklist_lock); \
59321+ read_lock(&grsec_exec_file_lock); \
59322+ if (x != GR_DO_AUDIT) \
59323+ spin_lock(&grsec_alert_lock); \
59324+ else \
59325+ spin_lock(&grsec_audit_lock)
59326+
59327+#define END_LOCKS(x) \
59328+ if (x != GR_DO_AUDIT) \
59329+ spin_unlock(&grsec_alert_lock); \
59330+ else \
59331+ spin_unlock(&grsec_audit_lock); \
59332+ read_unlock(&grsec_exec_file_lock); \
59333+ read_unlock(&tasklist_lock); \
59334+ rcu_read_unlock(); \
59335+ ENABLE_PREEMPT(); \
59336+ if (x == GR_DONT_AUDIT) \
59337+ gr_handle_alertkill(current)
59338+
59339+enum {
59340+ FLOODING,
59341+ NO_FLOODING
59342+};
59343+
59344+extern char *gr_alert_log_fmt;
59345+extern char *gr_audit_log_fmt;
59346+extern char *gr_alert_log_buf;
59347+extern char *gr_audit_log_buf;
59348+
59349+static int gr_log_start(int audit)
59350+{
59351+ char *loglevel = (audit == GR_DO_AUDIT) ? KERN_INFO : KERN_ALERT;
59352+ char *fmt = (audit == GR_DO_AUDIT) ? gr_audit_log_fmt : gr_alert_log_fmt;
59353+ char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
59354+#if (CONFIG_GRKERNSEC_FLOODTIME > 0 && CONFIG_GRKERNSEC_FLOODBURST > 0)
59355+ unsigned long curr_secs = get_seconds();
59356+
59357+ if (audit == GR_DO_AUDIT)
59358+ goto set_fmt;
59359+
59360+ if (!grsec_alert_wtime || time_after(curr_secs, grsec_alert_wtime + CONFIG_GRKERNSEC_FLOODTIME)) {
59361+ grsec_alert_wtime = curr_secs;
59362+ grsec_alert_fyet = 0;
59363+ } else if (time_before_eq(curr_secs, grsec_alert_wtime + CONFIG_GRKERNSEC_FLOODTIME)
59364+ && (grsec_alert_fyet < CONFIG_GRKERNSEC_FLOODBURST)) {
59365+ grsec_alert_fyet++;
59366+ } else if (grsec_alert_fyet == CONFIG_GRKERNSEC_FLOODBURST) {
59367+ grsec_alert_wtime = curr_secs;
59368+ grsec_alert_fyet++;
59369+ printk(KERN_ALERT "grsec: more alerts, logging disabled for %d seconds\n", CONFIG_GRKERNSEC_FLOODTIME);
59370+ return FLOODING;
59371+ }
59372+ else return FLOODING;
59373+
59374+set_fmt:
59375+#endif
59376+ memset(buf, 0, PAGE_SIZE);
59377+ if (current->signal->curr_ip && gr_acl_is_enabled()) {
59378+ sprintf(fmt, "%s%s", loglevel, "grsec: From %pI4: (%.64s:%c:%.950s) ");
59379+ snprintf(buf, PAGE_SIZE - 1, fmt, &current->signal->curr_ip, current->role->rolename, gr_roletype_to_char(), current->acl->filename);
59380+ } else if (current->signal->curr_ip) {
59381+ sprintf(fmt, "%s%s", loglevel, "grsec: From %pI4: ");
59382+ snprintf(buf, PAGE_SIZE - 1, fmt, &current->signal->curr_ip);
59383+ } else if (gr_acl_is_enabled()) {
59384+ sprintf(fmt, "%s%s", loglevel, "grsec: (%.64s:%c:%.950s) ");
59385+ snprintf(buf, PAGE_SIZE - 1, fmt, current->role->rolename, gr_roletype_to_char(), current->acl->filename);
59386+ } else {
59387+ sprintf(fmt, "%s%s", loglevel, "grsec: ");
59388+ strcpy(buf, fmt);
59389+ }
59390+
59391+ return NO_FLOODING;
59392+}
59393+
59394+static void gr_log_middle(int audit, const char *msg, va_list ap)
59395+ __attribute__ ((format (printf, 2, 0)));
59396+
59397+static void gr_log_middle(int audit, const char *msg, va_list ap)
59398+{
59399+ char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
59400+ unsigned int len = strlen(buf);
59401+
59402+ vsnprintf(buf + len, PAGE_SIZE - len - 1, msg, ap);
59403+
59404+ return;
59405+}
59406+
59407+static void gr_log_middle_varargs(int audit, const char *msg, ...)
59408+ __attribute__ ((format (printf, 2, 3)));
59409+
59410+static void gr_log_middle_varargs(int audit, const char *msg, ...)
59411+{
59412+ char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
59413+ unsigned int len = strlen(buf);
59414+ va_list ap;
59415+
59416+ va_start(ap, msg);
59417+ vsnprintf(buf + len, PAGE_SIZE - len - 1, msg, ap);
59418+ va_end(ap);
59419+
59420+ return;
59421+}
59422+
59423+static void gr_log_end(int audit, int append_default)
59424+{
59425+ char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
59426+
59427+ if (append_default) {
59428+ unsigned int len = strlen(buf);
59429+ snprintf(buf + len, PAGE_SIZE - len - 1, DEFAULTSECMSG, DEFAULTSECARGS(current, current_cred(), __task_cred(current->real_parent)));
59430+ }
59431+
59432+ printk("%s\n", buf);
59433+
59434+ return;
59435+}
59436+
59437+void gr_log_varargs(int audit, const char *msg, int argtypes, ...)
59438+{
59439+ int logtype;
59440+ char *result = (audit == GR_DO_AUDIT) ? "successful" : "denied";
59441+ char *str1 = NULL, *str2 = NULL, *str3 = NULL;
59442+ void *voidptr = NULL;
59443+ int num1 = 0, num2 = 0;
59444+ unsigned long ulong1 = 0, ulong2 = 0;
59445+ struct dentry *dentry = NULL;
59446+ struct vfsmount *mnt = NULL;
59447+ struct file *file = NULL;
59448+ struct task_struct *task = NULL;
59449+ const struct cred *cred, *pcred;
59450+ va_list ap;
59451+
59452+ BEGIN_LOCKS(audit);
59453+ logtype = gr_log_start(audit);
59454+ if (logtype == FLOODING) {
59455+ END_LOCKS(audit);
59456+ return;
59457+ }
59458+ va_start(ap, argtypes);
59459+ switch (argtypes) {
59460+ case GR_TTYSNIFF:
59461+ task = va_arg(ap, struct task_struct *);
59462+ 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);
59463+ break;
59464+ case GR_SYSCTL_HIDDEN:
59465+ str1 = va_arg(ap, char *);
59466+ gr_log_middle_varargs(audit, msg, result, str1);
59467+ break;
59468+ case GR_RBAC:
59469+ dentry = va_arg(ap, struct dentry *);
59470+ mnt = va_arg(ap, struct vfsmount *);
59471+ gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt));
59472+ break;
59473+ case GR_RBAC_STR:
59474+ dentry = va_arg(ap, struct dentry *);
59475+ mnt = va_arg(ap, struct vfsmount *);
59476+ str1 = va_arg(ap, char *);
59477+ gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt), str1);
59478+ break;
59479+ case GR_STR_RBAC:
59480+ str1 = va_arg(ap, char *);
59481+ dentry = va_arg(ap, struct dentry *);
59482+ mnt = va_arg(ap, struct vfsmount *);
59483+ gr_log_middle_varargs(audit, msg, result, str1, gr_to_filename(dentry, mnt));
59484+ break;
59485+ case GR_RBAC_MODE2:
59486+ dentry = va_arg(ap, struct dentry *);
59487+ mnt = va_arg(ap, struct vfsmount *);
59488+ str1 = va_arg(ap, char *);
59489+ str2 = va_arg(ap, char *);
59490+ gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt), str1, str2);
59491+ break;
59492+ case GR_RBAC_MODE3:
59493+ dentry = va_arg(ap, struct dentry *);
59494+ mnt = va_arg(ap, struct vfsmount *);
59495+ str1 = va_arg(ap, char *);
59496+ str2 = va_arg(ap, char *);
59497+ str3 = va_arg(ap, char *);
59498+ gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt), str1, str2, str3);
59499+ break;
59500+ case GR_FILENAME:
59501+ dentry = va_arg(ap, struct dentry *);
59502+ mnt = va_arg(ap, struct vfsmount *);
59503+ gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt));
59504+ break;
59505+ case GR_STR_FILENAME:
59506+ str1 = va_arg(ap, char *);
59507+ dentry = va_arg(ap, struct dentry *);
59508+ mnt = va_arg(ap, struct vfsmount *);
59509+ gr_log_middle_varargs(audit, msg, str1, gr_to_filename(dentry, mnt));
59510+ break;
59511+ case GR_FILENAME_STR:
59512+ dentry = va_arg(ap, struct dentry *);
59513+ mnt = va_arg(ap, struct vfsmount *);
59514+ str1 = va_arg(ap, char *);
59515+ gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt), str1);
59516+ break;
59517+ case GR_FILENAME_TWO_INT:
59518+ dentry = va_arg(ap, struct dentry *);
59519+ mnt = va_arg(ap, struct vfsmount *);
59520+ num1 = va_arg(ap, int);
59521+ num2 = va_arg(ap, int);
59522+ gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt), num1, num2);
59523+ break;
59524+ case GR_FILENAME_TWO_INT_STR:
59525+ dentry = va_arg(ap, struct dentry *);
59526+ mnt = va_arg(ap, struct vfsmount *);
59527+ num1 = va_arg(ap, int);
59528+ num2 = va_arg(ap, int);
59529+ str1 = va_arg(ap, char *);
59530+ gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt), num1, num2, str1);
59531+ break;
59532+ case GR_TEXTREL:
59533+ file = va_arg(ap, struct file *);
59534+ ulong1 = va_arg(ap, unsigned long);
59535+ ulong2 = va_arg(ap, unsigned long);
59536+ gr_log_middle_varargs(audit, msg, file ? gr_to_filename(file->f_path.dentry, file->f_path.mnt) : "<anonymous mapping>", ulong1, ulong2);
59537+ break;
59538+ case GR_PTRACE:
59539+ task = va_arg(ap, struct task_struct *);
59540+ 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);
59541+ break;
59542+ case GR_RESOURCE:
59543+ task = va_arg(ap, struct task_struct *);
59544+ cred = __task_cred(task);
59545+ pcred = __task_cred(task->real_parent);
59546+ ulong1 = va_arg(ap, unsigned long);
59547+ str1 = va_arg(ap, char *);
59548+ ulong2 = va_arg(ap, unsigned long);
59549+ 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);
59550+ break;
59551+ case GR_CAP:
59552+ task = va_arg(ap, struct task_struct *);
59553+ cred = __task_cred(task);
59554+ pcred = __task_cred(task->real_parent);
59555+ str1 = va_arg(ap, char *);
59556+ 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);
59557+ break;
59558+ case GR_SIG:
59559+ str1 = va_arg(ap, char *);
59560+ voidptr = va_arg(ap, void *);
59561+ gr_log_middle_varargs(audit, msg, str1, voidptr);
59562+ break;
59563+ case GR_SIG2:
59564+ task = va_arg(ap, struct task_struct *);
59565+ cred = __task_cred(task);
59566+ pcred = __task_cred(task->real_parent);
59567+ num1 = va_arg(ap, int);
59568+ 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);
59569+ break;
59570+ case GR_CRASH1:
59571+ task = va_arg(ap, struct task_struct *);
59572+ cred = __task_cred(task);
59573+ pcred = __task_cred(task->real_parent);
59574+ ulong1 = va_arg(ap, unsigned long);
59575+ 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);
59576+ break;
59577+ case GR_CRASH2:
59578+ task = va_arg(ap, struct task_struct *);
59579+ cred = __task_cred(task);
59580+ pcred = __task_cred(task->real_parent);
59581+ ulong1 = va_arg(ap, unsigned long);
59582+ 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);
59583+ break;
59584+ case GR_RWXMAP:
59585+ file = va_arg(ap, struct file *);
59586+ gr_log_middle_varargs(audit, msg, file ? gr_to_filename(file->f_path.dentry, file->f_path.mnt) : "<anonymous mapping>");
59587+ break;
59588+ case GR_PSACCT:
59589+ {
59590+ unsigned int wday, cday;
59591+ __u8 whr, chr;
59592+ __u8 wmin, cmin;
59593+ __u8 wsec, csec;
59594+ char cur_tty[64] = { 0 };
59595+ char parent_tty[64] = { 0 };
59596+
59597+ task = va_arg(ap, struct task_struct *);
59598+ wday = va_arg(ap, unsigned int);
59599+ cday = va_arg(ap, unsigned int);
59600+ whr = va_arg(ap, int);
59601+ chr = va_arg(ap, int);
59602+ wmin = va_arg(ap, int);
59603+ cmin = va_arg(ap, int);
59604+ wsec = va_arg(ap, int);
59605+ csec = va_arg(ap, int);
59606+ ulong1 = va_arg(ap, unsigned long);
59607+ cred = __task_cred(task);
59608+ pcred = __task_cred(task->real_parent);
59609+
59610+ 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);
59611+ }
59612+ break;
59613+ default:
59614+ gr_log_middle(audit, msg, ap);
59615+ }
59616+ va_end(ap);
59617+ // these don't need DEFAULTSECARGS printed on the end
59618+ if (argtypes == GR_CRASH1 || argtypes == GR_CRASH2)
59619+ gr_log_end(audit, 0);
59620+ else
59621+ gr_log_end(audit, 1);
59622+ END_LOCKS(audit);
59623+}
59624diff --git a/grsecurity/grsec_mem.c b/grsecurity/grsec_mem.c
59625new file mode 100644
59626index 0000000..f536303
59627--- /dev/null
59628+++ b/grsecurity/grsec_mem.c
59629@@ -0,0 +1,40 @@
59630+#include <linux/kernel.h>
59631+#include <linux/sched.h>
59632+#include <linux/mm.h>
59633+#include <linux/mman.h>
59634+#include <linux/grinternal.h>
59635+
59636+void
59637+gr_handle_ioperm(void)
59638+{
59639+ gr_log_noargs(GR_DONT_AUDIT, GR_IOPERM_MSG);
59640+ return;
59641+}
59642+
59643+void
59644+gr_handle_iopl(void)
59645+{
59646+ gr_log_noargs(GR_DONT_AUDIT, GR_IOPL_MSG);
59647+ return;
59648+}
59649+
59650+void
59651+gr_handle_mem_readwrite(u64 from, u64 to)
59652+{
59653+ gr_log_two_u64(GR_DONT_AUDIT, GR_MEM_READWRITE_MSG, from, to);
59654+ return;
59655+}
59656+
59657+void
59658+gr_handle_vm86(void)
59659+{
59660+ gr_log_noargs(GR_DONT_AUDIT, GR_VM86_MSG);
59661+ return;
59662+}
59663+
59664+void
59665+gr_log_badprocpid(const char *entry)
59666+{
59667+ gr_log_str(GR_DONT_AUDIT, GR_BADPROCPID_MSG, entry);
59668+ return;
59669+}
59670diff --git a/grsecurity/grsec_mount.c b/grsecurity/grsec_mount.c
59671new file mode 100644
59672index 0000000..2131422
59673--- /dev/null
59674+++ b/grsecurity/grsec_mount.c
59675@@ -0,0 +1,62 @@
59676+#include <linux/kernel.h>
59677+#include <linux/sched.h>
59678+#include <linux/mount.h>
59679+#include <linux/grsecurity.h>
59680+#include <linux/grinternal.h>
59681+
59682+void
59683+gr_log_remount(const char *devname, const int retval)
59684+{
59685+#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
59686+ if (grsec_enable_mount && (retval >= 0))
59687+ gr_log_str(GR_DO_AUDIT, GR_REMOUNT_AUDIT_MSG, devname ? devname : "none");
59688+#endif
59689+ return;
59690+}
59691+
59692+void
59693+gr_log_unmount(const char *devname, const int retval)
59694+{
59695+#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
59696+ if (grsec_enable_mount && (retval >= 0))
59697+ gr_log_str(GR_DO_AUDIT, GR_UNMOUNT_AUDIT_MSG, devname ? devname : "none");
59698+#endif
59699+ return;
59700+}
59701+
59702+void
59703+gr_log_mount(const char *from, const char *to, const int retval)
59704+{
59705+#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
59706+ if (grsec_enable_mount && (retval >= 0))
59707+ gr_log_str_str(GR_DO_AUDIT, GR_MOUNT_AUDIT_MSG, from ? from : "none", to);
59708+#endif
59709+ return;
59710+}
59711+
59712+int
59713+gr_handle_rofs_mount(struct dentry *dentry, struct vfsmount *mnt, int mnt_flags)
59714+{
59715+#ifdef CONFIG_GRKERNSEC_ROFS
59716+ if (grsec_enable_rofs && !(mnt_flags & MNT_READONLY)) {
59717+ gr_log_fs_generic(GR_DO_AUDIT, GR_ROFS_MOUNT_MSG, dentry, mnt);
59718+ return -EPERM;
59719+ } else
59720+ return 0;
59721+#endif
59722+ return 0;
59723+}
59724+
59725+int
59726+gr_handle_rofs_blockwrite(struct dentry *dentry, struct vfsmount *mnt, int acc_mode)
59727+{
59728+#ifdef CONFIG_GRKERNSEC_ROFS
59729+ if (grsec_enable_rofs && (acc_mode & MAY_WRITE) &&
59730+ dentry->d_inode && S_ISBLK(dentry->d_inode->i_mode)) {
59731+ gr_log_fs_generic(GR_DO_AUDIT, GR_ROFS_BLOCKWRITE_MSG, dentry, mnt);
59732+ return -EPERM;
59733+ } else
59734+ return 0;
59735+#endif
59736+ return 0;
59737+}
59738diff --git a/grsecurity/grsec_pax.c b/grsecurity/grsec_pax.c
59739new file mode 100644
59740index 0000000..a3b12a0
59741--- /dev/null
59742+++ b/grsecurity/grsec_pax.c
59743@@ -0,0 +1,36 @@
59744+#include <linux/kernel.h>
59745+#include <linux/sched.h>
59746+#include <linux/mm.h>
59747+#include <linux/file.h>
59748+#include <linux/grinternal.h>
59749+#include <linux/grsecurity.h>
59750+
59751+void
59752+gr_log_textrel(struct vm_area_struct * vma)
59753+{
59754+#ifdef CONFIG_GRKERNSEC_AUDIT_TEXTREL
59755+ if (grsec_enable_audit_textrel)
59756+ gr_log_textrel_ulong_ulong(GR_DO_AUDIT, GR_TEXTREL_AUDIT_MSG, vma->vm_file, vma->vm_start, vma->vm_pgoff);
59757+#endif
59758+ return;
59759+}
59760+
59761+void
59762+gr_log_rwxmmap(struct file *file)
59763+{
59764+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
59765+ if (grsec_enable_log_rwxmaps)
59766+ gr_log_rwxmap(GR_DONT_AUDIT, GR_RWXMMAP_MSG, file);
59767+#endif
59768+ return;
59769+}
59770+
59771+void
59772+gr_log_rwxmprotect(struct file *file)
59773+{
59774+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
59775+ if (grsec_enable_log_rwxmaps)
59776+ gr_log_rwxmap(GR_DONT_AUDIT, GR_RWXMPROTECT_MSG, file);
59777+#endif
59778+ return;
59779+}
59780diff --git a/grsecurity/grsec_ptrace.c b/grsecurity/grsec_ptrace.c
59781new file mode 100644
59782index 0000000..f7f29aa
59783--- /dev/null
59784+++ b/grsecurity/grsec_ptrace.c
59785@@ -0,0 +1,30 @@
59786+#include <linux/kernel.h>
59787+#include <linux/sched.h>
59788+#include <linux/grinternal.h>
59789+#include <linux/security.h>
59790+
59791+void
59792+gr_audit_ptrace(struct task_struct *task)
59793+{
59794+#ifdef CONFIG_GRKERNSEC_AUDIT_PTRACE
59795+ if (grsec_enable_audit_ptrace)
59796+ gr_log_ptrace(GR_DO_AUDIT, GR_PTRACE_AUDIT_MSG, task);
59797+#endif
59798+ return;
59799+}
59800+
59801+int
59802+gr_ptrace_readexec(struct file *file, int unsafe_flags)
59803+{
59804+#ifdef CONFIG_GRKERNSEC_PTRACE_READEXEC
59805+ const struct dentry *dentry = file->f_path.dentry;
59806+ const struct vfsmount *mnt = file->f_path.mnt;
59807+
59808+ if (grsec_enable_ptrace_readexec && (unsafe_flags & LSM_UNSAFE_PTRACE) &&
59809+ (inode_permission(dentry->d_inode, MAY_READ) || !gr_acl_handle_open(dentry, mnt, MAY_READ))) {
59810+ gr_log_fs_generic(GR_DONT_AUDIT, GR_PTRACE_READEXEC_MSG, dentry, mnt);
59811+ return -EACCES;
59812+ }
59813+#endif
59814+ return 0;
59815+}
59816diff --git a/grsecurity/grsec_sig.c b/grsecurity/grsec_sig.c
59817new file mode 100644
59818index 0000000..b4ac94c
59819--- /dev/null
59820+++ b/grsecurity/grsec_sig.c
59821@@ -0,0 +1,209 @@
59822+#include <linux/kernel.h>
59823+#include <linux/sched.h>
59824+#include <linux/delay.h>
59825+#include <linux/grsecurity.h>
59826+#include <linux/grinternal.h>
59827+#include <linux/hardirq.h>
59828+
59829+char *signames[] = {
59830+ [SIGSEGV] = "Segmentation fault",
59831+ [SIGILL] = "Illegal instruction",
59832+ [SIGABRT] = "Abort",
59833+ [SIGBUS] = "Invalid alignment/Bus error"
59834+};
59835+
59836+void
59837+gr_log_signal(const int sig, const void *addr, const struct task_struct *t)
59838+{
59839+#ifdef CONFIG_GRKERNSEC_SIGNAL
59840+ if (grsec_enable_signal && ((sig == SIGSEGV) || (sig == SIGILL) ||
59841+ (sig == SIGABRT) || (sig == SIGBUS))) {
59842+ if (t->pid == current->pid) {
59843+ gr_log_sig_addr(GR_DONT_AUDIT_GOOD, GR_UNISIGLOG_MSG, signames[sig], addr);
59844+ } else {
59845+ gr_log_sig_task(GR_DONT_AUDIT_GOOD, GR_DUALSIGLOG_MSG, t, sig);
59846+ }
59847+ }
59848+#endif
59849+ return;
59850+}
59851+
59852+int
59853+gr_handle_signal(const struct task_struct *p, const int sig)
59854+{
59855+#ifdef CONFIG_GRKERNSEC
59856+ /* ignore the 0 signal for protected task checks */
59857+ if (current->pid > 1 && sig && gr_check_protected_task(p)) {
59858+ gr_log_sig_task(GR_DONT_AUDIT, GR_SIG_ACL_MSG, p, sig);
59859+ return -EPERM;
59860+ } else if (gr_pid_is_chrooted((struct task_struct *)p)) {
59861+ return -EPERM;
59862+ }
59863+#endif
59864+ return 0;
59865+}
59866+
59867+#ifdef CONFIG_GRKERNSEC
59868+extern int specific_send_sig_info(int sig, struct siginfo *info, struct task_struct *t);
59869+
59870+int gr_fake_force_sig(int sig, struct task_struct *t)
59871+{
59872+ unsigned long int flags;
59873+ int ret, blocked, ignored;
59874+ struct k_sigaction *action;
59875+
59876+ spin_lock_irqsave(&t->sighand->siglock, flags);
59877+ action = &t->sighand->action[sig-1];
59878+ ignored = action->sa.sa_handler == SIG_IGN;
59879+ blocked = sigismember(&t->blocked, sig);
59880+ if (blocked || ignored) {
59881+ action->sa.sa_handler = SIG_DFL;
59882+ if (blocked) {
59883+ sigdelset(&t->blocked, sig);
59884+ recalc_sigpending_and_wake(t);
59885+ }
59886+ }
59887+ if (action->sa.sa_handler == SIG_DFL)
59888+ t->signal->flags &= ~SIGNAL_UNKILLABLE;
59889+ ret = specific_send_sig_info(sig, SEND_SIG_PRIV, t);
59890+
59891+ spin_unlock_irqrestore(&t->sighand->siglock, flags);
59892+
59893+ return ret;
59894+}
59895+#endif
59896+
59897+#ifdef CONFIG_GRKERNSEC_BRUTE
59898+#define GR_USER_BAN_TIME (15 * 60)
59899+
59900+static int __get_dumpable(unsigned long mm_flags)
59901+{
59902+ int ret;
59903+
59904+ ret = mm_flags & MMF_DUMPABLE_MASK;
59905+ return (ret >= 2) ? 2 : ret;
59906+}
59907+#endif
59908+
59909+void gr_handle_brute_attach(struct task_struct *p, unsigned long mm_flags)
59910+{
59911+#ifdef CONFIG_GRKERNSEC_BRUTE
59912+ kuid_t uid = GLOBAL_ROOT_UID;
59913+
59914+ if (!grsec_enable_brute)
59915+ return;
59916+
59917+ rcu_read_lock();
59918+ read_lock(&tasklist_lock);
59919+ read_lock(&grsec_exec_file_lock);
59920+ if (p->real_parent && p->real_parent->exec_file == p->exec_file)
59921+ p->real_parent->brute = 1;
59922+ else {
59923+ const struct cred *cred = __task_cred(p), *cred2;
59924+ struct task_struct *tsk, *tsk2;
59925+
59926+ if (!__get_dumpable(mm_flags) && !uid_eq(cred->uid, GLOBAL_ROOT_UID)) {
59927+ struct user_struct *user;
59928+
59929+ uid = cred->uid;
59930+
59931+ /* this is put upon execution past expiration */
59932+ user = find_user(uid);
59933+ if (user == NULL)
59934+ goto unlock;
59935+ user->banned = 1;
59936+ user->ban_expires = get_seconds() + GR_USER_BAN_TIME;
59937+ if (user->ban_expires == ~0UL)
59938+ user->ban_expires--;
59939+
59940+ do_each_thread(tsk2, tsk) {
59941+ cred2 = __task_cred(tsk);
59942+ if (tsk != p && uid_eq(cred2->uid, uid))
59943+ gr_fake_force_sig(SIGKILL, tsk);
59944+ } while_each_thread(tsk2, tsk);
59945+ }
59946+ }
59947+unlock:
59948+ read_unlock(&grsec_exec_file_lock);
59949+ read_unlock(&tasklist_lock);
59950+ rcu_read_unlock();
59951+
59952+ if (!uid_eq(uid, GLOBAL_ROOT_UID))
59953+ printk(KERN_ALERT "grsec: bruteforce prevention initiated against uid %u, banning for %d minutes\n",
59954+ from_kuid_munged(&init_user_ns, uid), GR_USER_BAN_TIME / 60);
59955+
59956+#endif
59957+ return;
59958+}
59959+
59960+void gr_handle_brute_check(void)
59961+{
59962+#ifdef CONFIG_GRKERNSEC_BRUTE
59963+ if (current->brute)
59964+ msleep(30 * 1000);
59965+#endif
59966+ return;
59967+}
59968+
59969+void gr_handle_kernel_exploit(void)
59970+{
59971+#ifdef CONFIG_GRKERNSEC_KERN_LOCKOUT
59972+ const struct cred *cred;
59973+ struct task_struct *tsk, *tsk2;
59974+ struct user_struct *user;
59975+ kuid_t uid;
59976+
59977+ if (in_irq() || in_serving_softirq() || in_nmi())
59978+ panic("grsec: halting the system due to suspicious kernel crash caused in interrupt context");
59979+
59980+ uid = current_uid();
59981+
59982+ if (uid_eq(uid, GLOBAL_ROOT_UID))
59983+ panic("grsec: halting the system due to suspicious kernel crash caused by root");
59984+ else {
59985+ /* kill all the processes of this user, hold a reference
59986+ to their creds struct, and prevent them from creating
59987+ another process until system reset
59988+ */
59989+ printk(KERN_ALERT "grsec: banning user with uid %u until system restart for suspicious kernel crash\n",
59990+ from_kuid_munged(&init_user_ns, uid));
59991+ /* we intentionally leak this ref */
59992+ user = get_uid(current->cred->user);
59993+ if (user) {
59994+ user->banned = 1;
59995+ user->ban_expires = ~0UL;
59996+ }
59997+
59998+ read_lock(&tasklist_lock);
59999+ do_each_thread(tsk2, tsk) {
60000+ cred = __task_cred(tsk);
60001+ if (uid_eq(cred->uid, uid))
60002+ gr_fake_force_sig(SIGKILL, tsk);
60003+ } while_each_thread(tsk2, tsk);
60004+ read_unlock(&tasklist_lock);
60005+ }
60006+#endif
60007+}
60008+
60009+int __gr_process_user_ban(struct user_struct *user)
60010+{
60011+#if defined(CONFIG_GRKERNSEC_KERN_LOCKOUT) || defined(CONFIG_GRKERNSEC_BRUTE)
60012+ if (unlikely(user->banned)) {
60013+ if (user->ban_expires != ~0UL && time_after_eq(get_seconds(), user->ban_expires)) {
60014+ user->banned = 0;
60015+ user->ban_expires = 0;
60016+ free_uid(user);
60017+ } else
60018+ return -EPERM;
60019+ }
60020+#endif
60021+ return 0;
60022+}
60023+
60024+int gr_process_user_ban(void)
60025+{
60026+#if defined(CONFIG_GRKERNSEC_KERN_LOCKOUT) || defined(CONFIG_GRKERNSEC_BRUTE)
60027+ return __gr_process_user_ban(current->cred->user);
60028+#endif
60029+ return 0;
60030+}
60031diff --git a/grsecurity/grsec_sock.c b/grsecurity/grsec_sock.c
60032new file mode 100644
60033index 0000000..4030d57
60034--- /dev/null
60035+++ b/grsecurity/grsec_sock.c
60036@@ -0,0 +1,244 @@
60037+#include <linux/kernel.h>
60038+#include <linux/module.h>
60039+#include <linux/sched.h>
60040+#include <linux/file.h>
60041+#include <linux/net.h>
60042+#include <linux/in.h>
60043+#include <linux/ip.h>
60044+#include <net/sock.h>
60045+#include <net/inet_sock.h>
60046+#include <linux/grsecurity.h>
60047+#include <linux/grinternal.h>
60048+#include <linux/gracl.h>
60049+
60050+extern int gr_search_udp_recvmsg(const struct sock *sk, const struct sk_buff *skb);
60051+extern int gr_search_udp_sendmsg(const struct sock *sk, const struct sockaddr_in *addr);
60052+
60053+EXPORT_SYMBOL(gr_search_udp_recvmsg);
60054+EXPORT_SYMBOL(gr_search_udp_sendmsg);
60055+
60056+#ifdef CONFIG_UNIX_MODULE
60057+EXPORT_SYMBOL(gr_acl_handle_unix);
60058+EXPORT_SYMBOL(gr_acl_handle_mknod);
60059+EXPORT_SYMBOL(gr_handle_chroot_unix);
60060+EXPORT_SYMBOL(gr_handle_create);
60061+#endif
60062+
60063+#ifdef CONFIG_GRKERNSEC
60064+#define gr_conn_table_size 32749
60065+struct conn_table_entry {
60066+ struct conn_table_entry *next;
60067+ struct signal_struct *sig;
60068+};
60069+
60070+struct conn_table_entry *gr_conn_table[gr_conn_table_size];
60071+DEFINE_SPINLOCK(gr_conn_table_lock);
60072+
60073+extern const char * gr_socktype_to_name(unsigned char type);
60074+extern const char * gr_proto_to_name(unsigned char proto);
60075+extern const char * gr_sockfamily_to_name(unsigned char family);
60076+
60077+static __inline__ int
60078+conn_hash(__u32 saddr, __u32 daddr, __u16 sport, __u16 dport, unsigned int size)
60079+{
60080+ return ((daddr + saddr + (sport << 8) + (dport << 16)) % size);
60081+}
60082+
60083+static __inline__ int
60084+conn_match(const struct signal_struct *sig, __u32 saddr, __u32 daddr,
60085+ __u16 sport, __u16 dport)
60086+{
60087+ if (unlikely(sig->gr_saddr == saddr && sig->gr_daddr == daddr &&
60088+ sig->gr_sport == sport && sig->gr_dport == dport))
60089+ return 1;
60090+ else
60091+ return 0;
60092+}
60093+
60094+static void gr_add_to_task_ip_table_nolock(struct signal_struct *sig, struct conn_table_entry *newent)
60095+{
60096+ struct conn_table_entry **match;
60097+ unsigned int index;
60098+
60099+ index = conn_hash(sig->gr_saddr, sig->gr_daddr,
60100+ sig->gr_sport, sig->gr_dport,
60101+ gr_conn_table_size);
60102+
60103+ newent->sig = sig;
60104+
60105+ match = &gr_conn_table[index];
60106+ newent->next = *match;
60107+ *match = newent;
60108+
60109+ return;
60110+}
60111+
60112+static void gr_del_task_from_ip_table_nolock(struct signal_struct *sig)
60113+{
60114+ struct conn_table_entry *match, *last = NULL;
60115+ unsigned int index;
60116+
60117+ index = conn_hash(sig->gr_saddr, sig->gr_daddr,
60118+ sig->gr_sport, sig->gr_dport,
60119+ gr_conn_table_size);
60120+
60121+ match = gr_conn_table[index];
60122+ while (match && !conn_match(match->sig,
60123+ sig->gr_saddr, sig->gr_daddr, sig->gr_sport,
60124+ sig->gr_dport)) {
60125+ last = match;
60126+ match = match->next;
60127+ }
60128+
60129+ if (match) {
60130+ if (last)
60131+ last->next = match->next;
60132+ else
60133+ gr_conn_table[index] = NULL;
60134+ kfree(match);
60135+ }
60136+
60137+ return;
60138+}
60139+
60140+static struct signal_struct * gr_lookup_task_ip_table(__u32 saddr, __u32 daddr,
60141+ __u16 sport, __u16 dport)
60142+{
60143+ struct conn_table_entry *match;
60144+ unsigned int index;
60145+
60146+ index = conn_hash(saddr, daddr, sport, dport, gr_conn_table_size);
60147+
60148+ match = gr_conn_table[index];
60149+ while (match && !conn_match(match->sig, saddr, daddr, sport, dport))
60150+ match = match->next;
60151+
60152+ if (match)
60153+ return match->sig;
60154+ else
60155+ return NULL;
60156+}
60157+
60158+#endif
60159+
60160+void gr_update_task_in_ip_table(struct task_struct *task, const struct inet_sock *inet)
60161+{
60162+#ifdef CONFIG_GRKERNSEC
60163+ struct signal_struct *sig = task->signal;
60164+ struct conn_table_entry *newent;
60165+
60166+ newent = kmalloc(sizeof(struct conn_table_entry), GFP_ATOMIC);
60167+ if (newent == NULL)
60168+ return;
60169+ /* no bh lock needed since we are called with bh disabled */
60170+ spin_lock(&gr_conn_table_lock);
60171+ gr_del_task_from_ip_table_nolock(sig);
60172+ sig->gr_saddr = inet->inet_rcv_saddr;
60173+ sig->gr_daddr = inet->inet_daddr;
60174+ sig->gr_sport = inet->inet_sport;
60175+ sig->gr_dport = inet->inet_dport;
60176+ gr_add_to_task_ip_table_nolock(sig, newent);
60177+ spin_unlock(&gr_conn_table_lock);
60178+#endif
60179+ return;
60180+}
60181+
60182+void gr_del_task_from_ip_table(struct task_struct *task)
60183+{
60184+#ifdef CONFIG_GRKERNSEC
60185+ spin_lock_bh(&gr_conn_table_lock);
60186+ gr_del_task_from_ip_table_nolock(task->signal);
60187+ spin_unlock_bh(&gr_conn_table_lock);
60188+#endif
60189+ return;
60190+}
60191+
60192+void
60193+gr_attach_curr_ip(const struct sock *sk)
60194+{
60195+#ifdef CONFIG_GRKERNSEC
60196+ struct signal_struct *p, *set;
60197+ const struct inet_sock *inet = inet_sk(sk);
60198+
60199+ if (unlikely(sk->sk_protocol != IPPROTO_TCP))
60200+ return;
60201+
60202+ set = current->signal;
60203+
60204+ spin_lock_bh(&gr_conn_table_lock);
60205+ p = gr_lookup_task_ip_table(inet->inet_daddr, inet->inet_rcv_saddr,
60206+ inet->inet_dport, inet->inet_sport);
60207+ if (unlikely(p != NULL)) {
60208+ set->curr_ip = p->curr_ip;
60209+ set->used_accept = 1;
60210+ gr_del_task_from_ip_table_nolock(p);
60211+ spin_unlock_bh(&gr_conn_table_lock);
60212+ return;
60213+ }
60214+ spin_unlock_bh(&gr_conn_table_lock);
60215+
60216+ set->curr_ip = inet->inet_daddr;
60217+ set->used_accept = 1;
60218+#endif
60219+ return;
60220+}
60221+
60222+int
60223+gr_handle_sock_all(const int family, const int type, const int protocol)
60224+{
60225+#ifdef CONFIG_GRKERNSEC_SOCKET_ALL
60226+ if (grsec_enable_socket_all && in_group_p(grsec_socket_all_gid) &&
60227+ (family != AF_UNIX)) {
60228+ if (family == AF_INET)
60229+ gr_log_str3(GR_DONT_AUDIT, GR_SOCK_MSG, gr_sockfamily_to_name(family), gr_socktype_to_name(type), gr_proto_to_name(protocol));
60230+ else
60231+ gr_log_str2_int(GR_DONT_AUDIT, GR_SOCK_NOINET_MSG, gr_sockfamily_to_name(family), gr_socktype_to_name(type), protocol);
60232+ return -EACCES;
60233+ }
60234+#endif
60235+ return 0;
60236+}
60237+
60238+int
60239+gr_handle_sock_server(const struct sockaddr *sck)
60240+{
60241+#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
60242+ if (grsec_enable_socket_server &&
60243+ in_group_p(grsec_socket_server_gid) &&
60244+ sck && (sck->sa_family != AF_UNIX) &&
60245+ (sck->sa_family != AF_LOCAL)) {
60246+ gr_log_noargs(GR_DONT_AUDIT, GR_BIND_MSG);
60247+ return -EACCES;
60248+ }
60249+#endif
60250+ return 0;
60251+}
60252+
60253+int
60254+gr_handle_sock_server_other(const struct sock *sck)
60255+{
60256+#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
60257+ if (grsec_enable_socket_server &&
60258+ in_group_p(grsec_socket_server_gid) &&
60259+ sck && (sck->sk_family != AF_UNIX) &&
60260+ (sck->sk_family != AF_LOCAL)) {
60261+ gr_log_noargs(GR_DONT_AUDIT, GR_BIND_MSG);
60262+ return -EACCES;
60263+ }
60264+#endif
60265+ return 0;
60266+}
60267+
60268+int
60269+gr_handle_sock_client(const struct sockaddr *sck)
60270+{
60271+#ifdef CONFIG_GRKERNSEC_SOCKET_CLIENT
60272+ if (grsec_enable_socket_client && in_group_p(grsec_socket_client_gid) &&
60273+ sck && (sck->sa_family != AF_UNIX) &&
60274+ (sck->sa_family != AF_LOCAL)) {
60275+ gr_log_noargs(GR_DONT_AUDIT, GR_CONNECT_MSG);
60276+ return -EACCES;
60277+ }
60278+#endif
60279+ return 0;
60280+}
60281diff --git a/grsecurity/grsec_sysctl.c b/grsecurity/grsec_sysctl.c
60282new file mode 100644
60283index 0000000..f55ef0f
60284--- /dev/null
60285+++ b/grsecurity/grsec_sysctl.c
60286@@ -0,0 +1,469 @@
60287+#include <linux/kernel.h>
60288+#include <linux/sched.h>
60289+#include <linux/sysctl.h>
60290+#include <linux/grsecurity.h>
60291+#include <linux/grinternal.h>
60292+
60293+int
60294+gr_handle_sysctl_mod(const char *dirname, const char *name, const int op)
60295+{
60296+#ifdef CONFIG_GRKERNSEC_SYSCTL
60297+ if (dirname == NULL || name == NULL)
60298+ return 0;
60299+ if (!strcmp(dirname, "grsecurity") && grsec_lock && (op & MAY_WRITE)) {
60300+ gr_log_str(GR_DONT_AUDIT, GR_SYSCTL_MSG, name);
60301+ return -EACCES;
60302+ }
60303+#endif
60304+ return 0;
60305+}
60306+
60307+#ifdef CONFIG_GRKERNSEC_ROFS
60308+static int __maybe_unused one = 1;
60309+#endif
60310+
60311+#if defined(CONFIG_GRKERNSEC_SYSCTL) || defined(CONFIG_GRKERNSEC_ROFS)
60312+struct ctl_table grsecurity_table[] = {
60313+#ifdef CONFIG_GRKERNSEC_SYSCTL
60314+#ifdef CONFIG_GRKERNSEC_SYSCTL_DISTRO
60315+#ifdef CONFIG_GRKERNSEC_IO
60316+ {
60317+ .procname = "disable_priv_io",
60318+ .data = &grsec_disable_privio,
60319+ .maxlen = sizeof(int),
60320+ .mode = 0600,
60321+ .proc_handler = &proc_dointvec,
60322+ },
60323+#endif
60324+#endif
60325+#ifdef CONFIG_GRKERNSEC_LINK
60326+ {
60327+ .procname = "linking_restrictions",
60328+ .data = &grsec_enable_link,
60329+ .maxlen = sizeof(int),
60330+ .mode = 0600,
60331+ .proc_handler = &proc_dointvec,
60332+ },
60333+#endif
60334+#ifdef CONFIG_GRKERNSEC_SYMLINKOWN
60335+ {
60336+ .procname = "enforce_symlinksifowner",
60337+ .data = &grsec_enable_symlinkown,
60338+ .maxlen = sizeof(int),
60339+ .mode = 0600,
60340+ .proc_handler = &proc_dointvec,
60341+ },
60342+ {
60343+ .procname = "symlinkown_gid",
60344+ .data = &grsec_symlinkown_gid,
60345+ .maxlen = sizeof(int),
60346+ .mode = 0600,
60347+ .proc_handler = &proc_dointvec,
60348+ },
60349+#endif
60350+#ifdef CONFIG_GRKERNSEC_BRUTE
60351+ {
60352+ .procname = "deter_bruteforce",
60353+ .data = &grsec_enable_brute,
60354+ .maxlen = sizeof(int),
60355+ .mode = 0600,
60356+ .proc_handler = &proc_dointvec,
60357+ },
60358+#endif
60359+#ifdef CONFIG_GRKERNSEC_FIFO
60360+ {
60361+ .procname = "fifo_restrictions",
60362+ .data = &grsec_enable_fifo,
60363+ .maxlen = sizeof(int),
60364+ .mode = 0600,
60365+ .proc_handler = &proc_dointvec,
60366+ },
60367+#endif
60368+#ifdef CONFIG_GRKERNSEC_PTRACE_READEXEC
60369+ {
60370+ .procname = "ptrace_readexec",
60371+ .data = &grsec_enable_ptrace_readexec,
60372+ .maxlen = sizeof(int),
60373+ .mode = 0600,
60374+ .proc_handler = &proc_dointvec,
60375+ },
60376+#endif
60377+#ifdef CONFIG_GRKERNSEC_SETXID
60378+ {
60379+ .procname = "consistent_setxid",
60380+ .data = &grsec_enable_setxid,
60381+ .maxlen = sizeof(int),
60382+ .mode = 0600,
60383+ .proc_handler = &proc_dointvec,
60384+ },
60385+#endif
60386+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
60387+ {
60388+ .procname = "ip_blackhole",
60389+ .data = &grsec_enable_blackhole,
60390+ .maxlen = sizeof(int),
60391+ .mode = 0600,
60392+ .proc_handler = &proc_dointvec,
60393+ },
60394+ {
60395+ .procname = "lastack_retries",
60396+ .data = &grsec_lastack_retries,
60397+ .maxlen = sizeof(int),
60398+ .mode = 0600,
60399+ .proc_handler = &proc_dointvec,
60400+ },
60401+#endif
60402+#ifdef CONFIG_GRKERNSEC_EXECLOG
60403+ {
60404+ .procname = "exec_logging",
60405+ .data = &grsec_enable_execlog,
60406+ .maxlen = sizeof(int),
60407+ .mode = 0600,
60408+ .proc_handler = &proc_dointvec,
60409+ },
60410+#endif
60411+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
60412+ {
60413+ .procname = "rwxmap_logging",
60414+ .data = &grsec_enable_log_rwxmaps,
60415+ .maxlen = sizeof(int),
60416+ .mode = 0600,
60417+ .proc_handler = &proc_dointvec,
60418+ },
60419+#endif
60420+#ifdef CONFIG_GRKERNSEC_SIGNAL
60421+ {
60422+ .procname = "signal_logging",
60423+ .data = &grsec_enable_signal,
60424+ .maxlen = sizeof(int),
60425+ .mode = 0600,
60426+ .proc_handler = &proc_dointvec,
60427+ },
60428+#endif
60429+#ifdef CONFIG_GRKERNSEC_FORKFAIL
60430+ {
60431+ .procname = "forkfail_logging",
60432+ .data = &grsec_enable_forkfail,
60433+ .maxlen = sizeof(int),
60434+ .mode = 0600,
60435+ .proc_handler = &proc_dointvec,
60436+ },
60437+#endif
60438+#ifdef CONFIG_GRKERNSEC_TIME
60439+ {
60440+ .procname = "timechange_logging",
60441+ .data = &grsec_enable_time,
60442+ .maxlen = sizeof(int),
60443+ .mode = 0600,
60444+ .proc_handler = &proc_dointvec,
60445+ },
60446+#endif
60447+#ifdef CONFIG_GRKERNSEC_CHROOT_SHMAT
60448+ {
60449+ .procname = "chroot_deny_shmat",
60450+ .data = &grsec_enable_chroot_shmat,
60451+ .maxlen = sizeof(int),
60452+ .mode = 0600,
60453+ .proc_handler = &proc_dointvec,
60454+ },
60455+#endif
60456+#ifdef CONFIG_GRKERNSEC_CHROOT_UNIX
60457+ {
60458+ .procname = "chroot_deny_unix",
60459+ .data = &grsec_enable_chroot_unix,
60460+ .maxlen = sizeof(int),
60461+ .mode = 0600,
60462+ .proc_handler = &proc_dointvec,
60463+ },
60464+#endif
60465+#ifdef CONFIG_GRKERNSEC_CHROOT_MOUNT
60466+ {
60467+ .procname = "chroot_deny_mount",
60468+ .data = &grsec_enable_chroot_mount,
60469+ .maxlen = sizeof(int),
60470+ .mode = 0600,
60471+ .proc_handler = &proc_dointvec,
60472+ },
60473+#endif
60474+#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
60475+ {
60476+ .procname = "chroot_deny_fchdir",
60477+ .data = &grsec_enable_chroot_fchdir,
60478+ .maxlen = sizeof(int),
60479+ .mode = 0600,
60480+ .proc_handler = &proc_dointvec,
60481+ },
60482+#endif
60483+#ifdef CONFIG_GRKERNSEC_CHROOT_DOUBLE
60484+ {
60485+ .procname = "chroot_deny_chroot",
60486+ .data = &grsec_enable_chroot_double,
60487+ .maxlen = sizeof(int),
60488+ .mode = 0600,
60489+ .proc_handler = &proc_dointvec,
60490+ },
60491+#endif
60492+#ifdef CONFIG_GRKERNSEC_CHROOT_PIVOT
60493+ {
60494+ .procname = "chroot_deny_pivot",
60495+ .data = &grsec_enable_chroot_pivot,
60496+ .maxlen = sizeof(int),
60497+ .mode = 0600,
60498+ .proc_handler = &proc_dointvec,
60499+ },
60500+#endif
60501+#ifdef CONFIG_GRKERNSEC_CHROOT_CHDIR
60502+ {
60503+ .procname = "chroot_enforce_chdir",
60504+ .data = &grsec_enable_chroot_chdir,
60505+ .maxlen = sizeof(int),
60506+ .mode = 0600,
60507+ .proc_handler = &proc_dointvec,
60508+ },
60509+#endif
60510+#ifdef CONFIG_GRKERNSEC_CHROOT_CHMOD
60511+ {
60512+ .procname = "chroot_deny_chmod",
60513+ .data = &grsec_enable_chroot_chmod,
60514+ .maxlen = sizeof(int),
60515+ .mode = 0600,
60516+ .proc_handler = &proc_dointvec,
60517+ },
60518+#endif
60519+#ifdef CONFIG_GRKERNSEC_CHROOT_MKNOD
60520+ {
60521+ .procname = "chroot_deny_mknod",
60522+ .data = &grsec_enable_chroot_mknod,
60523+ .maxlen = sizeof(int),
60524+ .mode = 0600,
60525+ .proc_handler = &proc_dointvec,
60526+ },
60527+#endif
60528+#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
60529+ {
60530+ .procname = "chroot_restrict_nice",
60531+ .data = &grsec_enable_chroot_nice,
60532+ .maxlen = sizeof(int),
60533+ .mode = 0600,
60534+ .proc_handler = &proc_dointvec,
60535+ },
60536+#endif
60537+#ifdef CONFIG_GRKERNSEC_CHROOT_EXECLOG
60538+ {
60539+ .procname = "chroot_execlog",
60540+ .data = &grsec_enable_chroot_execlog,
60541+ .maxlen = sizeof(int),
60542+ .mode = 0600,
60543+ .proc_handler = &proc_dointvec,
60544+ },
60545+#endif
60546+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
60547+ {
60548+ .procname = "chroot_caps",
60549+ .data = &grsec_enable_chroot_caps,
60550+ .maxlen = sizeof(int),
60551+ .mode = 0600,
60552+ .proc_handler = &proc_dointvec,
60553+ },
60554+#endif
60555+#ifdef CONFIG_GRKERNSEC_CHROOT_SYSCTL
60556+ {
60557+ .procname = "chroot_deny_sysctl",
60558+ .data = &grsec_enable_chroot_sysctl,
60559+ .maxlen = sizeof(int),
60560+ .mode = 0600,
60561+ .proc_handler = &proc_dointvec,
60562+ },
60563+#endif
60564+#ifdef CONFIG_GRKERNSEC_TPE
60565+ {
60566+ .procname = "tpe",
60567+ .data = &grsec_enable_tpe,
60568+ .maxlen = sizeof(int),
60569+ .mode = 0600,
60570+ .proc_handler = &proc_dointvec,
60571+ },
60572+ {
60573+ .procname = "tpe_gid",
60574+ .data = &grsec_tpe_gid,
60575+ .maxlen = sizeof(int),
60576+ .mode = 0600,
60577+ .proc_handler = &proc_dointvec,
60578+ },
60579+#endif
60580+#ifdef CONFIG_GRKERNSEC_TPE_INVERT
60581+ {
60582+ .procname = "tpe_invert",
60583+ .data = &grsec_enable_tpe_invert,
60584+ .maxlen = sizeof(int),
60585+ .mode = 0600,
60586+ .proc_handler = &proc_dointvec,
60587+ },
60588+#endif
60589+#ifdef CONFIG_GRKERNSEC_TPE_ALL
60590+ {
60591+ .procname = "tpe_restrict_all",
60592+ .data = &grsec_enable_tpe_all,
60593+ .maxlen = sizeof(int),
60594+ .mode = 0600,
60595+ .proc_handler = &proc_dointvec,
60596+ },
60597+#endif
60598+#ifdef CONFIG_GRKERNSEC_SOCKET_ALL
60599+ {
60600+ .procname = "socket_all",
60601+ .data = &grsec_enable_socket_all,
60602+ .maxlen = sizeof(int),
60603+ .mode = 0600,
60604+ .proc_handler = &proc_dointvec,
60605+ },
60606+ {
60607+ .procname = "socket_all_gid",
60608+ .data = &grsec_socket_all_gid,
60609+ .maxlen = sizeof(int),
60610+ .mode = 0600,
60611+ .proc_handler = &proc_dointvec,
60612+ },
60613+#endif
60614+#ifdef CONFIG_GRKERNSEC_SOCKET_CLIENT
60615+ {
60616+ .procname = "socket_client",
60617+ .data = &grsec_enable_socket_client,
60618+ .maxlen = sizeof(int),
60619+ .mode = 0600,
60620+ .proc_handler = &proc_dointvec,
60621+ },
60622+ {
60623+ .procname = "socket_client_gid",
60624+ .data = &grsec_socket_client_gid,
60625+ .maxlen = sizeof(int),
60626+ .mode = 0600,
60627+ .proc_handler = &proc_dointvec,
60628+ },
60629+#endif
60630+#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
60631+ {
60632+ .procname = "socket_server",
60633+ .data = &grsec_enable_socket_server,
60634+ .maxlen = sizeof(int),
60635+ .mode = 0600,
60636+ .proc_handler = &proc_dointvec,
60637+ },
60638+ {
60639+ .procname = "socket_server_gid",
60640+ .data = &grsec_socket_server_gid,
60641+ .maxlen = sizeof(int),
60642+ .mode = 0600,
60643+ .proc_handler = &proc_dointvec,
60644+ },
60645+#endif
60646+#ifdef CONFIG_GRKERNSEC_AUDIT_GROUP
60647+ {
60648+ .procname = "audit_group",
60649+ .data = &grsec_enable_group,
60650+ .maxlen = sizeof(int),
60651+ .mode = 0600,
60652+ .proc_handler = &proc_dointvec,
60653+ },
60654+ {
60655+ .procname = "audit_gid",
60656+ .data = &grsec_audit_gid,
60657+ .maxlen = sizeof(int),
60658+ .mode = 0600,
60659+ .proc_handler = &proc_dointvec,
60660+ },
60661+#endif
60662+#ifdef CONFIG_GRKERNSEC_AUDIT_CHDIR
60663+ {
60664+ .procname = "audit_chdir",
60665+ .data = &grsec_enable_chdir,
60666+ .maxlen = sizeof(int),
60667+ .mode = 0600,
60668+ .proc_handler = &proc_dointvec,
60669+ },
60670+#endif
60671+#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
60672+ {
60673+ .procname = "audit_mount",
60674+ .data = &grsec_enable_mount,
60675+ .maxlen = sizeof(int),
60676+ .mode = 0600,
60677+ .proc_handler = &proc_dointvec,
60678+ },
60679+#endif
60680+#ifdef CONFIG_GRKERNSEC_AUDIT_TEXTREL
60681+ {
60682+ .procname = "audit_textrel",
60683+ .data = &grsec_enable_audit_textrel,
60684+ .maxlen = sizeof(int),
60685+ .mode = 0600,
60686+ .proc_handler = &proc_dointvec,
60687+ },
60688+#endif
60689+#ifdef CONFIG_GRKERNSEC_DMESG
60690+ {
60691+ .procname = "dmesg",
60692+ .data = &grsec_enable_dmesg,
60693+ .maxlen = sizeof(int),
60694+ .mode = 0600,
60695+ .proc_handler = &proc_dointvec,
60696+ },
60697+#endif
60698+#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
60699+ {
60700+ .procname = "chroot_findtask",
60701+ .data = &grsec_enable_chroot_findtask,
60702+ .maxlen = sizeof(int),
60703+ .mode = 0600,
60704+ .proc_handler = &proc_dointvec,
60705+ },
60706+#endif
60707+#ifdef CONFIG_GRKERNSEC_RESLOG
60708+ {
60709+ .procname = "resource_logging",
60710+ .data = &grsec_resource_logging,
60711+ .maxlen = sizeof(int),
60712+ .mode = 0600,
60713+ .proc_handler = &proc_dointvec,
60714+ },
60715+#endif
60716+#ifdef CONFIG_GRKERNSEC_AUDIT_PTRACE
60717+ {
60718+ .procname = "audit_ptrace",
60719+ .data = &grsec_enable_audit_ptrace,
60720+ .maxlen = sizeof(int),
60721+ .mode = 0600,
60722+ .proc_handler = &proc_dointvec,
60723+ },
60724+#endif
60725+#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
60726+ {
60727+ .procname = "harden_ptrace",
60728+ .data = &grsec_enable_harden_ptrace,
60729+ .maxlen = sizeof(int),
60730+ .mode = 0600,
60731+ .proc_handler = &proc_dointvec,
60732+ },
60733+#endif
60734+ {
60735+ .procname = "grsec_lock",
60736+ .data = &grsec_lock,
60737+ .maxlen = sizeof(int),
60738+ .mode = 0600,
60739+ .proc_handler = &proc_dointvec,
60740+ },
60741+#endif
60742+#ifdef CONFIG_GRKERNSEC_ROFS
60743+ {
60744+ .procname = "romount_protect",
60745+ .data = &grsec_enable_rofs,
60746+ .maxlen = sizeof(int),
60747+ .mode = 0600,
60748+ .proc_handler = &proc_dointvec_minmax,
60749+ .extra1 = &one,
60750+ .extra2 = &one,
60751+ },
60752+#endif
60753+ { }
60754+};
60755+#endif
60756diff --git a/grsecurity/grsec_time.c b/grsecurity/grsec_time.c
60757new file mode 100644
60758index 0000000..0dc13c3
60759--- /dev/null
60760+++ b/grsecurity/grsec_time.c
60761@@ -0,0 +1,16 @@
60762+#include <linux/kernel.h>
60763+#include <linux/sched.h>
60764+#include <linux/grinternal.h>
60765+#include <linux/module.h>
60766+
60767+void
60768+gr_log_timechange(void)
60769+{
60770+#ifdef CONFIG_GRKERNSEC_TIME
60771+ if (grsec_enable_time)
60772+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_TIME_MSG);
60773+#endif
60774+ return;
60775+}
60776+
60777+EXPORT_SYMBOL(gr_log_timechange);
60778diff --git a/grsecurity/grsec_tpe.c b/grsecurity/grsec_tpe.c
60779new file mode 100644
60780index 0000000..07e0dc0
60781--- /dev/null
60782+++ b/grsecurity/grsec_tpe.c
60783@@ -0,0 +1,73 @@
60784+#include <linux/kernel.h>
60785+#include <linux/sched.h>
60786+#include <linux/file.h>
60787+#include <linux/fs.h>
60788+#include <linux/grinternal.h>
60789+
60790+extern int gr_acl_tpe_check(void);
60791+
60792+int
60793+gr_tpe_allow(const struct file *file)
60794+{
60795+#ifdef CONFIG_GRKERNSEC
60796+ struct inode *inode = file->f_path.dentry->d_parent->d_inode;
60797+ const struct cred *cred = current_cred();
60798+ char *msg = NULL;
60799+ char *msg2 = NULL;
60800+
60801+ // never restrict root
60802+ if (!cred->uid)
60803+ return 1;
60804+
60805+ if (grsec_enable_tpe) {
60806+#ifdef CONFIG_GRKERNSEC_TPE_INVERT
60807+ if (grsec_enable_tpe_invert && !in_group_p(grsec_tpe_gid))
60808+ msg = "not being in trusted group";
60809+ else if (!grsec_enable_tpe_invert && in_group_p(grsec_tpe_gid))
60810+ msg = "being in untrusted group";
60811+#else
60812+ if (in_group_p(grsec_tpe_gid))
60813+ msg = "being in untrusted group";
60814+#endif
60815+ }
60816+ if (!msg && gr_acl_tpe_check())
60817+ msg = "being in untrusted role";
60818+
60819+ // not in any affected group/role
60820+ if (!msg)
60821+ goto next_check;
60822+
60823+ if (inode->i_uid)
60824+ msg2 = "file in non-root-owned directory";
60825+ else if (inode->i_mode & S_IWOTH)
60826+ msg2 = "file in world-writable directory";
60827+ else if (inode->i_mode & S_IWGRP)
60828+ msg2 = "file in group-writable directory";
60829+
60830+ if (msg && msg2) {
60831+ char fullmsg[70] = {0};
60832+ snprintf(fullmsg, sizeof(fullmsg)-1, "%s and %s", msg, msg2);
60833+ gr_log_str_fs(GR_DONT_AUDIT, GR_EXEC_TPE_MSG, fullmsg, file->f_path.dentry, file->f_path.mnt);
60834+ return 0;
60835+ }
60836+ msg = NULL;
60837+next_check:
60838+#ifdef CONFIG_GRKERNSEC_TPE_ALL
60839+ if (!grsec_enable_tpe || !grsec_enable_tpe_all)
60840+ return 1;
60841+
60842+ if (inode->i_uid && (inode->i_uid != cred->uid))
60843+ msg = "directory not owned by user";
60844+ else if (inode->i_mode & S_IWOTH)
60845+ msg = "file in world-writable directory";
60846+ else if (inode->i_mode & S_IWGRP)
60847+ msg = "file in group-writable directory";
60848+
60849+ if (msg) {
60850+ gr_log_str_fs(GR_DONT_AUDIT, GR_EXEC_TPE_MSG, msg, file->f_path.dentry, file->f_path.mnt);
60851+ return 0;
60852+ }
60853+#endif
60854+#endif
60855+ return 1;
60856+}
60857diff --git a/grsecurity/grsum.c b/grsecurity/grsum.c
60858new file mode 100644
60859index 0000000..9f7b1ac
60860--- /dev/null
60861+++ b/grsecurity/grsum.c
60862@@ -0,0 +1,61 @@
60863+#include <linux/err.h>
60864+#include <linux/kernel.h>
60865+#include <linux/sched.h>
60866+#include <linux/mm.h>
60867+#include <linux/scatterlist.h>
60868+#include <linux/crypto.h>
60869+#include <linux/gracl.h>
60870+
60871+
60872+#if !defined(CONFIG_CRYPTO) || defined(CONFIG_CRYPTO_MODULE) || !defined(CONFIG_CRYPTO_SHA256) || defined(CONFIG_CRYPTO_SHA256_MODULE)
60873+#error "crypto and sha256 must be built into the kernel"
60874+#endif
60875+
60876+int
60877+chkpw(struct gr_arg *entry, unsigned char *salt, unsigned char *sum)
60878+{
60879+ char *p;
60880+ struct crypto_hash *tfm;
60881+ struct hash_desc desc;
60882+ struct scatterlist sg;
60883+ unsigned char temp_sum[GR_SHA_LEN];
60884+ volatile int retval = 0;
60885+ volatile int dummy = 0;
60886+ unsigned int i;
60887+
60888+ sg_init_table(&sg, 1);
60889+
60890+ tfm = crypto_alloc_hash("sha256", 0, CRYPTO_ALG_ASYNC);
60891+ if (IS_ERR(tfm)) {
60892+ /* should never happen, since sha256 should be built in */
60893+ return 1;
60894+ }
60895+
60896+ desc.tfm = tfm;
60897+ desc.flags = 0;
60898+
60899+ crypto_hash_init(&desc);
60900+
60901+ p = salt;
60902+ sg_set_buf(&sg, p, GR_SALT_LEN);
60903+ crypto_hash_update(&desc, &sg, sg.length);
60904+
60905+ p = entry->pw;
60906+ sg_set_buf(&sg, p, strlen(p));
60907+
60908+ crypto_hash_update(&desc, &sg, sg.length);
60909+
60910+ crypto_hash_final(&desc, temp_sum);
60911+
60912+ memset(entry->pw, 0, GR_PW_LEN);
60913+
60914+ for (i = 0; i < GR_SHA_LEN; i++)
60915+ if (sum[i] != temp_sum[i])
60916+ retval = 1;
60917+ else
60918+ dummy = 1; // waste a cycle
60919+
60920+ crypto_free_hash(tfm);
60921+
60922+ return retval;
60923+}
60924diff --git a/include/acpi/acpi_bus.h b/include/acpi/acpi_bus.h
60925index bde976e..a1cc32a 100644
60926--- a/include/acpi/acpi_bus.h
60927+++ b/include/acpi/acpi_bus.h
60928@@ -136,7 +136,7 @@ struct acpi_device_ops {
60929 acpi_op_bind bind;
60930 acpi_op_unbind unbind;
60931 acpi_op_notify notify;
60932-};
60933+} __no_const;
60934
60935 #define ACPI_DRIVER_ALL_NOTIFY_EVENTS 0x1 /* system AND device events */
60936
60937diff --git a/include/asm-generic/4level-fixup.h b/include/asm-generic/4level-fixup.h
60938index 77ff547..181834f 100644
60939--- a/include/asm-generic/4level-fixup.h
60940+++ b/include/asm-generic/4level-fixup.h
60941@@ -13,8 +13,10 @@
60942 #define pmd_alloc(mm, pud, address) \
60943 ((unlikely(pgd_none(*(pud))) && __pmd_alloc(mm, pud, address))? \
60944 NULL: pmd_offset(pud, address))
60945+#define pmd_alloc_kernel(mm, pud, address) pmd_alloc((mm), (pud), (address))
60946
60947 #define pud_alloc(mm, pgd, address) (pgd)
60948+#define pud_alloc_kernel(mm, pgd, address) pud_alloc((mm), (pgd), (address))
60949 #define pud_offset(pgd, start) (pgd)
60950 #define pud_none(pud) 0
60951 #define pud_bad(pud) 0
60952diff --git a/include/asm-generic/atomic-long.h b/include/asm-generic/atomic-long.h
60953index b7babf0..3ba8aee 100644
60954--- a/include/asm-generic/atomic-long.h
60955+++ b/include/asm-generic/atomic-long.h
60956@@ -22,6 +22,12 @@
60957
60958 typedef atomic64_t atomic_long_t;
60959
60960+#ifdef CONFIG_PAX_REFCOUNT
60961+typedef atomic64_unchecked_t atomic_long_unchecked_t;
60962+#else
60963+typedef atomic64_t atomic_long_unchecked_t;
60964+#endif
60965+
60966 #define ATOMIC_LONG_INIT(i) ATOMIC64_INIT(i)
60967
60968 static inline long atomic_long_read(atomic_long_t *l)
60969@@ -31,6 +37,15 @@ static inline long atomic_long_read(atomic_long_t *l)
60970 return (long)atomic64_read(v);
60971 }
60972
60973+#ifdef CONFIG_PAX_REFCOUNT
60974+static inline long atomic_long_read_unchecked(atomic_long_unchecked_t *l)
60975+{
60976+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
60977+
60978+ return (long)atomic64_read_unchecked(v);
60979+}
60980+#endif
60981+
60982 static inline void atomic_long_set(atomic_long_t *l, long i)
60983 {
60984 atomic64_t *v = (atomic64_t *)l;
60985@@ -38,6 +53,15 @@ static inline void atomic_long_set(atomic_long_t *l, long i)
60986 atomic64_set(v, i);
60987 }
60988
60989+#ifdef CONFIG_PAX_REFCOUNT
60990+static inline void atomic_long_set_unchecked(atomic_long_unchecked_t *l, long i)
60991+{
60992+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
60993+
60994+ atomic64_set_unchecked(v, i);
60995+}
60996+#endif
60997+
60998 static inline void atomic_long_inc(atomic_long_t *l)
60999 {
61000 atomic64_t *v = (atomic64_t *)l;
61001@@ -45,6 +69,15 @@ static inline void atomic_long_inc(atomic_long_t *l)
61002 atomic64_inc(v);
61003 }
61004
61005+#ifdef CONFIG_PAX_REFCOUNT
61006+static inline void atomic_long_inc_unchecked(atomic_long_unchecked_t *l)
61007+{
61008+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
61009+
61010+ atomic64_inc_unchecked(v);
61011+}
61012+#endif
61013+
61014 static inline void atomic_long_dec(atomic_long_t *l)
61015 {
61016 atomic64_t *v = (atomic64_t *)l;
61017@@ -52,6 +85,15 @@ static inline void atomic_long_dec(atomic_long_t *l)
61018 atomic64_dec(v);
61019 }
61020
61021+#ifdef CONFIG_PAX_REFCOUNT
61022+static inline void atomic_long_dec_unchecked(atomic_long_unchecked_t *l)
61023+{
61024+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
61025+
61026+ atomic64_dec_unchecked(v);
61027+}
61028+#endif
61029+
61030 static inline void atomic_long_add(long i, atomic_long_t *l)
61031 {
61032 atomic64_t *v = (atomic64_t *)l;
61033@@ -59,6 +101,15 @@ static inline void atomic_long_add(long i, atomic_long_t *l)
61034 atomic64_add(i, v);
61035 }
61036
61037+#ifdef CONFIG_PAX_REFCOUNT
61038+static inline void atomic_long_add_unchecked(long i, atomic_long_unchecked_t *l)
61039+{
61040+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
61041+
61042+ atomic64_add_unchecked(i, v);
61043+}
61044+#endif
61045+
61046 static inline void atomic_long_sub(long i, atomic_long_t *l)
61047 {
61048 atomic64_t *v = (atomic64_t *)l;
61049@@ -66,6 +117,15 @@ static inline void atomic_long_sub(long i, atomic_long_t *l)
61050 atomic64_sub(i, v);
61051 }
61052
61053+#ifdef CONFIG_PAX_REFCOUNT
61054+static inline void atomic_long_sub_unchecked(long i, atomic_long_unchecked_t *l)
61055+{
61056+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
61057+
61058+ atomic64_sub_unchecked(i, v);
61059+}
61060+#endif
61061+
61062 static inline int atomic_long_sub_and_test(long i, atomic_long_t *l)
61063 {
61064 atomic64_t *v = (atomic64_t *)l;
61065@@ -115,6 +175,15 @@ static inline long atomic_long_inc_return(atomic_long_t *l)
61066 return (long)atomic64_inc_return(v);
61067 }
61068
61069+#ifdef CONFIG_PAX_REFCOUNT
61070+static inline long atomic_long_inc_return_unchecked(atomic_long_unchecked_t *l)
61071+{
61072+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
61073+
61074+ return (long)atomic64_inc_return_unchecked(v);
61075+}
61076+#endif
61077+
61078 static inline long atomic_long_dec_return(atomic_long_t *l)
61079 {
61080 atomic64_t *v = (atomic64_t *)l;
61081@@ -140,6 +209,12 @@ static inline long atomic_long_add_unless(atomic_long_t *l, long a, long u)
61082
61083 typedef atomic_t atomic_long_t;
61084
61085+#ifdef CONFIG_PAX_REFCOUNT
61086+typedef atomic_unchecked_t atomic_long_unchecked_t;
61087+#else
61088+typedef atomic_t atomic_long_unchecked_t;
61089+#endif
61090+
61091 #define ATOMIC_LONG_INIT(i) ATOMIC_INIT(i)
61092 static inline long atomic_long_read(atomic_long_t *l)
61093 {
61094@@ -148,6 +223,15 @@ static inline long atomic_long_read(atomic_long_t *l)
61095 return (long)atomic_read(v);
61096 }
61097
61098+#ifdef CONFIG_PAX_REFCOUNT
61099+static inline long atomic_long_read_unchecked(atomic_long_unchecked_t *l)
61100+{
61101+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
61102+
61103+ return (long)atomic_read_unchecked(v);
61104+}
61105+#endif
61106+
61107 static inline void atomic_long_set(atomic_long_t *l, long i)
61108 {
61109 atomic_t *v = (atomic_t *)l;
61110@@ -155,6 +239,15 @@ static inline void atomic_long_set(atomic_long_t *l, long i)
61111 atomic_set(v, i);
61112 }
61113
61114+#ifdef CONFIG_PAX_REFCOUNT
61115+static inline void atomic_long_set_unchecked(atomic_long_unchecked_t *l, long i)
61116+{
61117+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
61118+
61119+ atomic_set_unchecked(v, i);
61120+}
61121+#endif
61122+
61123 static inline void atomic_long_inc(atomic_long_t *l)
61124 {
61125 atomic_t *v = (atomic_t *)l;
61126@@ -162,6 +255,15 @@ static inline void atomic_long_inc(atomic_long_t *l)
61127 atomic_inc(v);
61128 }
61129
61130+#ifdef CONFIG_PAX_REFCOUNT
61131+static inline void atomic_long_inc_unchecked(atomic_long_unchecked_t *l)
61132+{
61133+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
61134+
61135+ atomic_inc_unchecked(v);
61136+}
61137+#endif
61138+
61139 static inline void atomic_long_dec(atomic_long_t *l)
61140 {
61141 atomic_t *v = (atomic_t *)l;
61142@@ -169,6 +271,15 @@ static inline void atomic_long_dec(atomic_long_t *l)
61143 atomic_dec(v);
61144 }
61145
61146+#ifdef CONFIG_PAX_REFCOUNT
61147+static inline void atomic_long_dec_unchecked(atomic_long_unchecked_t *l)
61148+{
61149+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
61150+
61151+ atomic_dec_unchecked(v);
61152+}
61153+#endif
61154+
61155 static inline void atomic_long_add(long i, atomic_long_t *l)
61156 {
61157 atomic_t *v = (atomic_t *)l;
61158@@ -176,6 +287,15 @@ static inline void atomic_long_add(long i, atomic_long_t *l)
61159 atomic_add(i, v);
61160 }
61161
61162+#ifdef CONFIG_PAX_REFCOUNT
61163+static inline void atomic_long_add_unchecked(long i, atomic_long_unchecked_t *l)
61164+{
61165+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
61166+
61167+ atomic_add_unchecked(i, v);
61168+}
61169+#endif
61170+
61171 static inline void atomic_long_sub(long i, atomic_long_t *l)
61172 {
61173 atomic_t *v = (atomic_t *)l;
61174@@ -183,6 +303,15 @@ static inline void atomic_long_sub(long i, atomic_long_t *l)
61175 atomic_sub(i, v);
61176 }
61177
61178+#ifdef CONFIG_PAX_REFCOUNT
61179+static inline void atomic_long_sub_unchecked(long i, atomic_long_unchecked_t *l)
61180+{
61181+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
61182+
61183+ atomic_sub_unchecked(i, v);
61184+}
61185+#endif
61186+
61187 static inline int atomic_long_sub_and_test(long i, atomic_long_t *l)
61188 {
61189 atomic_t *v = (atomic_t *)l;
61190@@ -232,6 +361,15 @@ static inline long atomic_long_inc_return(atomic_long_t *l)
61191 return (long)atomic_inc_return(v);
61192 }
61193
61194+#ifdef CONFIG_PAX_REFCOUNT
61195+static inline long atomic_long_inc_return_unchecked(atomic_long_unchecked_t *l)
61196+{
61197+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
61198+
61199+ return (long)atomic_inc_return_unchecked(v);
61200+}
61201+#endif
61202+
61203 static inline long atomic_long_dec_return(atomic_long_t *l)
61204 {
61205 atomic_t *v = (atomic_t *)l;
61206@@ -255,4 +393,55 @@ static inline long atomic_long_add_unless(atomic_long_t *l, long a, long u)
61207
61208 #endif /* BITS_PER_LONG == 64 */
61209
61210+#ifdef CONFIG_PAX_REFCOUNT
61211+static inline void pax_refcount_needs_these_functions(void)
61212+{
61213+ atomic_read_unchecked((atomic_unchecked_t *)NULL);
61214+ atomic_set_unchecked((atomic_unchecked_t *)NULL, 0);
61215+ atomic_add_unchecked(0, (atomic_unchecked_t *)NULL);
61216+ atomic_sub_unchecked(0, (atomic_unchecked_t *)NULL);
61217+ atomic_inc_unchecked((atomic_unchecked_t *)NULL);
61218+ (void)atomic_inc_and_test_unchecked((atomic_unchecked_t *)NULL);
61219+ atomic_inc_return_unchecked((atomic_unchecked_t *)NULL);
61220+ atomic_add_return_unchecked(0, (atomic_unchecked_t *)NULL);
61221+ atomic_dec_unchecked((atomic_unchecked_t *)NULL);
61222+ atomic_cmpxchg_unchecked((atomic_unchecked_t *)NULL, 0, 0);
61223+ (void)atomic_xchg_unchecked((atomic_unchecked_t *)NULL, 0);
61224+#ifdef CONFIG_X86
61225+ atomic_clear_mask_unchecked(0, NULL);
61226+ atomic_set_mask_unchecked(0, NULL);
61227+#endif
61228+
61229+ atomic_long_read_unchecked((atomic_long_unchecked_t *)NULL);
61230+ atomic_long_set_unchecked((atomic_long_unchecked_t *)NULL, 0);
61231+ atomic_long_add_unchecked(0, (atomic_long_unchecked_t *)NULL);
61232+ atomic_long_sub_unchecked(0, (atomic_long_unchecked_t *)NULL);
61233+ atomic_long_inc_unchecked((atomic_long_unchecked_t *)NULL);
61234+ atomic_long_inc_return_unchecked((atomic_long_unchecked_t *)NULL);
61235+ atomic_long_dec_unchecked((atomic_long_unchecked_t *)NULL);
61236+}
61237+#else
61238+#define atomic_read_unchecked(v) atomic_read(v)
61239+#define atomic_set_unchecked(v, i) atomic_set((v), (i))
61240+#define atomic_add_unchecked(i, v) atomic_add((i), (v))
61241+#define atomic_sub_unchecked(i, v) atomic_sub((i), (v))
61242+#define atomic_inc_unchecked(v) atomic_inc(v)
61243+#define atomic_inc_and_test_unchecked(v) atomic_inc_and_test(v)
61244+#define atomic_inc_return_unchecked(v) atomic_inc_return(v)
61245+#define atomic_add_return_unchecked(i, v) atomic_add_return((i), (v))
61246+#define atomic_dec_unchecked(v) atomic_dec(v)
61247+#define atomic_cmpxchg_unchecked(v, o, n) atomic_cmpxchg((v), (o), (n))
61248+#define atomic_xchg_unchecked(v, i) atomic_xchg((v), (i))
61249+#define atomic_clear_mask_unchecked(mask, v) atomic_clear_mask((mask), (v))
61250+#define atomic_set_mask_unchecked(mask, v) atomic_set_mask((mask), (v))
61251+
61252+#define atomic_long_read_unchecked(v) atomic_long_read(v)
61253+#define atomic_long_set_unchecked(v, i) atomic_long_set((v), (i))
61254+#define atomic_long_add_unchecked(i, v) atomic_long_add((i), (v))
61255+#define atomic_long_sub_unchecked(i, v) atomic_long_sub((i), (v))
61256+#define atomic_long_inc_unchecked(v) atomic_long_inc(v)
61257+#define atomic_long_inc_return_unchecked(v) atomic_long_inc_return(v)
61258+#define atomic_long_dec_unchecked(v) atomic_long_dec(v)
61259+#endif
61260+
61261 #endif /* _ASM_GENERIC_ATOMIC_LONG_H */
61262diff --git a/include/asm-generic/atomic.h b/include/asm-generic/atomic.h
61263index 1ced641..c896ee8 100644
61264--- a/include/asm-generic/atomic.h
61265+++ b/include/asm-generic/atomic.h
61266@@ -159,7 +159,7 @@ static inline int __atomic_add_unless(atomic_t *v, int a, int u)
61267 * Atomically clears the bits set in @mask from @v
61268 */
61269 #ifndef atomic_clear_mask
61270-static inline void atomic_clear_mask(unsigned long mask, atomic_t *v)
61271+static inline void atomic_clear_mask(unsigned int mask, atomic_t *v)
61272 {
61273 unsigned long flags;
61274
61275diff --git a/include/asm-generic/atomic64.h b/include/asm-generic/atomic64.h
61276index b18ce4f..2ee2843 100644
61277--- a/include/asm-generic/atomic64.h
61278+++ b/include/asm-generic/atomic64.h
61279@@ -16,6 +16,8 @@ typedef struct {
61280 long long counter;
61281 } atomic64_t;
61282
61283+typedef atomic64_t atomic64_unchecked_t;
61284+
61285 #define ATOMIC64_INIT(i) { (i) }
61286
61287 extern long long atomic64_read(const atomic64_t *v);
61288@@ -39,4 +41,14 @@ extern int atomic64_add_unless(atomic64_t *v, long long a, long long u);
61289 #define atomic64_dec_and_test(v) (atomic64_dec_return((v)) == 0)
61290 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1LL, 0LL)
61291
61292+#define atomic64_read_unchecked(v) atomic64_read(v)
61293+#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
61294+#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
61295+#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
61296+#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
61297+#define atomic64_inc_unchecked(v) atomic64_inc(v)
61298+#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
61299+#define atomic64_dec_unchecked(v) atomic64_dec(v)
61300+#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
61301+
61302 #endif /* _ASM_GENERIC_ATOMIC64_H */
61303diff --git a/include/asm-generic/cache.h b/include/asm-generic/cache.h
61304index 1bfcfe5..e04c5c9 100644
61305--- a/include/asm-generic/cache.h
61306+++ b/include/asm-generic/cache.h
61307@@ -6,7 +6,7 @@
61308 * cache lines need to provide their own cache.h.
61309 */
61310
61311-#define L1_CACHE_SHIFT 5
61312-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
61313+#define L1_CACHE_SHIFT 5UL
61314+#define L1_CACHE_BYTES (1UL << L1_CACHE_SHIFT)
61315
61316 #endif /* __ASM_GENERIC_CACHE_H */
61317diff --git a/include/asm-generic/emergency-restart.h b/include/asm-generic/emergency-restart.h
61318index 0d68a1e..b74a761 100644
61319--- a/include/asm-generic/emergency-restart.h
61320+++ b/include/asm-generic/emergency-restart.h
61321@@ -1,7 +1,7 @@
61322 #ifndef _ASM_GENERIC_EMERGENCY_RESTART_H
61323 #define _ASM_GENERIC_EMERGENCY_RESTART_H
61324
61325-static inline void machine_emergency_restart(void)
61326+static inline __noreturn void machine_emergency_restart(void)
61327 {
61328 machine_restart(NULL);
61329 }
61330diff --git a/include/asm-generic/kmap_types.h b/include/asm-generic/kmap_types.h
61331index 90f99c7..00ce236 100644
61332--- a/include/asm-generic/kmap_types.h
61333+++ b/include/asm-generic/kmap_types.h
61334@@ -2,9 +2,9 @@
61335 #define _ASM_GENERIC_KMAP_TYPES_H
61336
61337 #ifdef __WITH_KM_FENCE
61338-# define KM_TYPE_NR 41
61339+# define KM_TYPE_NR 42
61340 #else
61341-# define KM_TYPE_NR 20
61342+# define KM_TYPE_NR 21
61343 #endif
61344
61345 #endif
61346diff --git a/include/asm-generic/local.h b/include/asm-generic/local.h
61347index 9ceb03b..2efbcbd 100644
61348--- a/include/asm-generic/local.h
61349+++ b/include/asm-generic/local.h
61350@@ -39,6 +39,7 @@ typedef struct
61351 #define local_add_return(i, l) atomic_long_add_return((i), (&(l)->a))
61352 #define local_sub_return(i, l) atomic_long_sub_return((i), (&(l)->a))
61353 #define local_inc_return(l) atomic_long_inc_return(&(l)->a)
61354+#define local_dec_return(l) atomic_long_dec_return(&(l)->a)
61355
61356 #define local_cmpxchg(l, o, n) atomic_long_cmpxchg((&(l)->a), (o), (n))
61357 #define local_xchg(l, n) atomic_long_xchg((&(l)->a), (n))
61358diff --git a/include/asm-generic/pgtable-nopmd.h b/include/asm-generic/pgtable-nopmd.h
61359index 725612b..9cc513a 100644
61360--- a/include/asm-generic/pgtable-nopmd.h
61361+++ b/include/asm-generic/pgtable-nopmd.h
61362@@ -1,14 +1,19 @@
61363 #ifndef _PGTABLE_NOPMD_H
61364 #define _PGTABLE_NOPMD_H
61365
61366-#ifndef __ASSEMBLY__
61367-
61368 #include <asm-generic/pgtable-nopud.h>
61369
61370-struct mm_struct;
61371-
61372 #define __PAGETABLE_PMD_FOLDED
61373
61374+#define PMD_SHIFT PUD_SHIFT
61375+#define PTRS_PER_PMD 1
61376+#define PMD_SIZE (_AC(1,UL) << PMD_SHIFT)
61377+#define PMD_MASK (~(PMD_SIZE-1))
61378+
61379+#ifndef __ASSEMBLY__
61380+
61381+struct mm_struct;
61382+
61383 /*
61384 * Having the pmd type consist of a pud gets the size right, and allows
61385 * us to conceptually access the pud entry that this pmd is folded into
61386@@ -16,11 +21,6 @@ struct mm_struct;
61387 */
61388 typedef struct { pud_t pud; } pmd_t;
61389
61390-#define PMD_SHIFT PUD_SHIFT
61391-#define PTRS_PER_PMD 1
61392-#define PMD_SIZE (1UL << PMD_SHIFT)
61393-#define PMD_MASK (~(PMD_SIZE-1))
61394-
61395 /*
61396 * The "pud_xxx()" functions here are trivial for a folded two-level
61397 * setup: the pmd is never bad, and a pmd always exists (as it's folded
61398diff --git a/include/asm-generic/pgtable-nopud.h b/include/asm-generic/pgtable-nopud.h
61399index 810431d..0ec4804f 100644
61400--- a/include/asm-generic/pgtable-nopud.h
61401+++ b/include/asm-generic/pgtable-nopud.h
61402@@ -1,10 +1,15 @@
61403 #ifndef _PGTABLE_NOPUD_H
61404 #define _PGTABLE_NOPUD_H
61405
61406-#ifndef __ASSEMBLY__
61407-
61408 #define __PAGETABLE_PUD_FOLDED
61409
61410+#define PUD_SHIFT PGDIR_SHIFT
61411+#define PTRS_PER_PUD 1
61412+#define PUD_SIZE (_AC(1,UL) << PUD_SHIFT)
61413+#define PUD_MASK (~(PUD_SIZE-1))
61414+
61415+#ifndef __ASSEMBLY__
61416+
61417 /*
61418 * Having the pud type consist of a pgd gets the size right, and allows
61419 * us to conceptually access the pgd entry that this pud is folded into
61420@@ -12,11 +17,6 @@
61421 */
61422 typedef struct { pgd_t pgd; } pud_t;
61423
61424-#define PUD_SHIFT PGDIR_SHIFT
61425-#define PTRS_PER_PUD 1
61426-#define PUD_SIZE (1UL << PUD_SHIFT)
61427-#define PUD_MASK (~(PUD_SIZE-1))
61428-
61429 /*
61430 * The "pgd_xxx()" functions here are trivial for a folded two-level
61431 * setup: the pud is never bad, and a pud always exists (as it's folded
61432@@ -29,6 +29,7 @@ static inline void pgd_clear(pgd_t *pgd) { }
61433 #define pud_ERROR(pud) (pgd_ERROR((pud).pgd))
61434
61435 #define pgd_populate(mm, pgd, pud) do { } while (0)
61436+#define pgd_populate_kernel(mm, pgd, pud) do { } while (0)
61437 /*
61438 * (puds are folded into pgds so this doesn't get actually called,
61439 * but the define is needed for a generic inline function.)
61440diff --git a/include/asm-generic/pgtable.h b/include/asm-generic/pgtable.h
61441index ff4947b..f48183f 100644
61442--- a/include/asm-generic/pgtable.h
61443+++ b/include/asm-generic/pgtable.h
61444@@ -530,6 +530,14 @@ static inline int pmd_trans_unstable(pmd_t *pmd)
61445 #endif
61446 }
61447
61448+#ifndef __HAVE_ARCH_PAX_OPEN_KERNEL
61449+static inline unsigned long pax_open_kernel(void) { return 0; }
61450+#endif
61451+
61452+#ifndef __HAVE_ARCH_PAX_CLOSE_KERNEL
61453+static inline unsigned long pax_close_kernel(void) { return 0; }
61454+#endif
61455+
61456 #endif /* CONFIG_MMU */
61457
61458 #endif /* !__ASSEMBLY__ */
61459diff --git a/include/asm-generic/vmlinux.lds.h b/include/asm-generic/vmlinux.lds.h
61460index 4e2e1cc..12c266b 100644
61461--- a/include/asm-generic/vmlinux.lds.h
61462+++ b/include/asm-generic/vmlinux.lds.h
61463@@ -218,6 +218,7 @@
61464 .rodata : AT(ADDR(.rodata) - LOAD_OFFSET) { \
61465 VMLINUX_SYMBOL(__start_rodata) = .; \
61466 *(.rodata) *(.rodata.*) \
61467+ *(.data..read_only) \
61468 *(__vermagic) /* Kernel version magic */ \
61469 . = ALIGN(8); \
61470 VMLINUX_SYMBOL(__start___tracepoints_ptrs) = .; \
61471@@ -716,17 +717,18 @@
61472 * section in the linker script will go there too. @phdr should have
61473 * a leading colon.
61474 *
61475- * Note that this macros defines __per_cpu_load as an absolute symbol.
61476+ * Note that this macros defines per_cpu_load as an absolute symbol.
61477 * If there is no need to put the percpu section at a predetermined
61478 * address, use PERCPU_SECTION.
61479 */
61480 #define PERCPU_VADDR(cacheline, vaddr, phdr) \
61481- VMLINUX_SYMBOL(__per_cpu_load) = .; \
61482- .data..percpu vaddr : AT(VMLINUX_SYMBOL(__per_cpu_load) \
61483+ per_cpu_load = .; \
61484+ .data..percpu vaddr : AT(VMLINUX_SYMBOL(per_cpu_load) \
61485 - LOAD_OFFSET) { \
61486+ VMLINUX_SYMBOL(__per_cpu_load) = . + per_cpu_load; \
61487 PERCPU_INPUT(cacheline) \
61488 } phdr \
61489- . = VMLINUX_SYMBOL(__per_cpu_load) + SIZEOF(.data..percpu);
61490+ . = VMLINUX_SYMBOL(per_cpu_load) + SIZEOF(.data..percpu);
61491
61492 /**
61493 * PERCPU_SECTION - define output section for percpu area, simple version
61494diff --git a/include/drm/drmP.h b/include/drm/drmP.h
61495index d6b67bb..a272c29 100644
61496--- a/include/drm/drmP.h
61497+++ b/include/drm/drmP.h
61498@@ -72,6 +72,7 @@
61499 #include <linux/workqueue.h>
61500 #include <linux/poll.h>
61501 #include <asm/pgalloc.h>
61502+#include <asm/local.h>
61503 #include "drm.h"
61504
61505 #include <linux/idr.h>
61506@@ -1067,7 +1068,7 @@ struct drm_device {
61507
61508 /** \name Usage Counters */
61509 /*@{ */
61510- int open_count; /**< Outstanding files open */
61511+ local_t open_count; /**< Outstanding files open */
61512 atomic_t ioctl_count; /**< Outstanding IOCTLs pending */
61513 atomic_t vma_count; /**< Outstanding vma areas open */
61514 int buf_use; /**< Buffers in use -- cannot alloc */
61515@@ -1078,7 +1079,7 @@ struct drm_device {
61516 /*@{ */
61517 unsigned long counters;
61518 enum drm_stat_type types[15];
61519- atomic_t counts[15];
61520+ atomic_unchecked_t counts[15];
61521 /*@} */
61522
61523 struct list_head filelist;
61524diff --git a/include/drm/drm_crtc_helper.h b/include/drm/drm_crtc_helper.h
61525index e01cc80..319855d 100644
61526--- a/include/drm/drm_crtc_helper.h
61527+++ b/include/drm/drm_crtc_helper.h
61528@@ -81,7 +81,7 @@ struct drm_crtc_helper_funcs {
61529
61530 /* disable crtc when not in use - more explicit than dpms off */
61531 void (*disable)(struct drm_crtc *crtc);
61532-};
61533+} __no_const;
61534
61535 /**
61536 * drm_encoder_helper_funcs - helper operations for encoders
61537@@ -109,7 +109,7 @@ struct drm_encoder_helper_funcs {
61538 struct drm_connector *connector);
61539 /* disable encoder when not in use - more explicit than dpms off */
61540 void (*disable)(struct drm_encoder *encoder);
61541-};
61542+} __no_const;
61543
61544 /**
61545 * drm_connector_helper_funcs - helper operations for connectors
61546diff --git a/include/drm/ttm/ttm_memory.h b/include/drm/ttm/ttm_memory.h
61547index d6d1da4..fdd1ac5 100644
61548--- a/include/drm/ttm/ttm_memory.h
61549+++ b/include/drm/ttm/ttm_memory.h
61550@@ -48,7 +48,7 @@
61551
61552 struct ttm_mem_shrink {
61553 int (*do_shrink) (struct ttm_mem_shrink *);
61554-};
61555+} __no_const;
61556
61557 /**
61558 * struct ttm_mem_global - Global memory accounting structure.
61559diff --git a/include/linux/a.out.h b/include/linux/a.out.h
61560index e86dfca..40cc55f 100644
61561--- a/include/linux/a.out.h
61562+++ b/include/linux/a.out.h
61563@@ -39,6 +39,14 @@ enum machine_type {
61564 M_MIPS2 = 152 /* MIPS R6000/R4000 binary */
61565 };
61566
61567+/* Constants for the N_FLAGS field */
61568+#define F_PAX_PAGEEXEC 1 /* Paging based non-executable pages */
61569+#define F_PAX_EMUTRAMP 2 /* Emulate trampolines */
61570+#define F_PAX_MPROTECT 4 /* Restrict mprotect() */
61571+#define F_PAX_RANDMMAP 8 /* Randomize mmap() base */
61572+/*#define F_PAX_RANDEXEC 16*/ /* Randomize ET_EXEC base */
61573+#define F_PAX_SEGMEXEC 32 /* Segmentation based non-executable pages */
61574+
61575 #if !defined (N_MAGIC)
61576 #define N_MAGIC(exec) ((exec).a_info & 0xffff)
61577 #endif
61578diff --git a/include/linux/atmdev.h b/include/linux/atmdev.h
61579index 06fd4bb..1caec0d 100644
61580--- a/include/linux/atmdev.h
61581+++ b/include/linux/atmdev.h
61582@@ -237,7 +237,7 @@ struct compat_atm_iobuf {
61583 #endif
61584
61585 struct k_atm_aal_stats {
61586-#define __HANDLE_ITEM(i) atomic_t i
61587+#define __HANDLE_ITEM(i) atomic_unchecked_t i
61588 __AAL_STAT_ITEMS
61589 #undef __HANDLE_ITEM
61590 };
61591diff --git a/include/linux/binfmts.h b/include/linux/binfmts.h
61592index 366422b..1fa7f84 100644
61593--- a/include/linux/binfmts.h
61594+++ b/include/linux/binfmts.h
61595@@ -89,6 +89,7 @@ struct linux_binfmt {
61596 int (*load_binary)(struct linux_binprm *, struct pt_regs * regs);
61597 int (*load_shlib)(struct file *);
61598 int (*core_dump)(struct coredump_params *cprm);
61599+ void (*handle_mprotect)(struct vm_area_struct *vma, unsigned long newflags);
61600 unsigned long min_coredump; /* minimal dump size */
61601 };
61602
61603diff --git a/include/linux/blkdev.h b/include/linux/blkdev.h
61604index 4a2ab7c..a2de7a8 100644
61605--- a/include/linux/blkdev.h
61606+++ b/include/linux/blkdev.h
61607@@ -1420,7 +1420,7 @@ struct block_device_operations {
61608 /* this callback is with swap_lock and sometimes page table lock held */
61609 void (*swap_slot_free_notify) (struct block_device *, unsigned long);
61610 struct module *owner;
61611-};
61612+} __do_const;
61613
61614 extern int __blkdev_driver_ioctl(struct block_device *, fmode_t, unsigned int,
61615 unsigned long);
61616diff --git a/include/linux/blktrace_api.h b/include/linux/blktrace_api.h
61617index 4d1a074..88f929a 100644
61618--- a/include/linux/blktrace_api.h
61619+++ b/include/linux/blktrace_api.h
61620@@ -162,7 +162,7 @@ struct blk_trace {
61621 struct dentry *dir;
61622 struct dentry *dropped_file;
61623 struct dentry *msg_file;
61624- atomic_t dropped;
61625+ atomic_unchecked_t dropped;
61626 };
61627
61628 extern int blk_trace_ioctl(struct block_device *, unsigned, char __user *);
61629diff --git a/include/linux/byteorder/little_endian.h b/include/linux/byteorder/little_endian.h
61630index 83195fb..0b0f77d 100644
61631--- a/include/linux/byteorder/little_endian.h
61632+++ b/include/linux/byteorder/little_endian.h
61633@@ -42,51 +42,51 @@
61634
61635 static inline __le64 __cpu_to_le64p(const __u64 *p)
61636 {
61637- return (__force __le64)*p;
61638+ return (__force const __le64)*p;
61639 }
61640 static inline __u64 __le64_to_cpup(const __le64 *p)
61641 {
61642- return (__force __u64)*p;
61643+ return (__force const __u64)*p;
61644 }
61645 static inline __le32 __cpu_to_le32p(const __u32 *p)
61646 {
61647- return (__force __le32)*p;
61648+ return (__force const __le32)*p;
61649 }
61650 static inline __u32 __le32_to_cpup(const __le32 *p)
61651 {
61652- return (__force __u32)*p;
61653+ return (__force const __u32)*p;
61654 }
61655 static inline __le16 __cpu_to_le16p(const __u16 *p)
61656 {
61657- return (__force __le16)*p;
61658+ return (__force const __le16)*p;
61659 }
61660 static inline __u16 __le16_to_cpup(const __le16 *p)
61661 {
61662- return (__force __u16)*p;
61663+ return (__force const __u16)*p;
61664 }
61665 static inline __be64 __cpu_to_be64p(const __u64 *p)
61666 {
61667- return (__force __be64)__swab64p(p);
61668+ return (__force const __be64)__swab64p(p);
61669 }
61670 static inline __u64 __be64_to_cpup(const __be64 *p)
61671 {
61672- return __swab64p((__u64 *)p);
61673+ return __swab64p((const __u64 *)p);
61674 }
61675 static inline __be32 __cpu_to_be32p(const __u32 *p)
61676 {
61677- return (__force __be32)__swab32p(p);
61678+ return (__force const __be32)__swab32p(p);
61679 }
61680 static inline __u32 __be32_to_cpup(const __be32 *p)
61681 {
61682- return __swab32p((__u32 *)p);
61683+ return __swab32p((const __u32 *)p);
61684 }
61685 static inline __be16 __cpu_to_be16p(const __u16 *p)
61686 {
61687- return (__force __be16)__swab16p(p);
61688+ return (__force const __be16)__swab16p(p);
61689 }
61690 static inline __u16 __be16_to_cpup(const __be16 *p)
61691 {
61692- return __swab16p((__u16 *)p);
61693+ return __swab16p((const __u16 *)p);
61694 }
61695 #define __cpu_to_le64s(x) do { (void)(x); } while (0)
61696 #define __le64_to_cpus(x) do { (void)(x); } while (0)
61697diff --git a/include/linux/cache.h b/include/linux/cache.h
61698index 4c57065..4307975 100644
61699--- a/include/linux/cache.h
61700+++ b/include/linux/cache.h
61701@@ -16,6 +16,10 @@
61702 #define __read_mostly
61703 #endif
61704
61705+#ifndef __read_only
61706+#define __read_only __read_mostly
61707+#endif
61708+
61709 #ifndef ____cacheline_aligned
61710 #define ____cacheline_aligned __attribute__((__aligned__(SMP_CACHE_BYTES)))
61711 #endif
61712diff --git a/include/linux/capability.h b/include/linux/capability.h
61713index d10b7ed..0288b79 100644
61714--- a/include/linux/capability.h
61715+++ b/include/linux/capability.h
61716@@ -553,10 +553,15 @@ extern bool capable(int cap);
61717 extern bool ns_capable(struct user_namespace *ns, int cap);
61718 extern bool nsown_capable(int cap);
61719 extern bool inode_capable(const struct inode *inode, int cap);
61720+extern bool capable_nolog(int cap);
61721+extern bool ns_capable_nolog(struct user_namespace *ns, int cap);
61722+extern bool inode_capable_nolog(const struct inode *inode, int cap);
61723
61724 /* audit system wants to get cap info from files as well */
61725 extern int get_vfs_caps_from_disk(const struct dentry *dentry, struct cpu_vfs_cap_data *cpu_caps);
61726
61727+extern int is_privileged_binary(const struct dentry *dentry);
61728+
61729 #endif /* __KERNEL__ */
61730
61731 #endif /* !_LINUX_CAPABILITY_H */
61732diff --git a/include/linux/cleancache.h b/include/linux/cleancache.h
61733index 42e55de..1cd0e66 100644
61734--- a/include/linux/cleancache.h
61735+++ b/include/linux/cleancache.h
61736@@ -31,7 +31,7 @@ struct cleancache_ops {
61737 void (*invalidate_page)(int, struct cleancache_filekey, pgoff_t);
61738 void (*invalidate_inode)(int, struct cleancache_filekey);
61739 void (*invalidate_fs)(int);
61740-};
61741+} __no_const;
61742
61743 extern struct cleancache_ops
61744 cleancache_register_ops(struct cleancache_ops *ops);
61745diff --git a/include/linux/clk-provider.h b/include/linux/clk-provider.h
61746index 77335fa..6cbe7dd 100644
61747--- a/include/linux/clk-provider.h
61748+++ b/include/linux/clk-provider.h
61749@@ -111,6 +111,7 @@ struct clk_ops {
61750 unsigned long);
61751 void (*init)(struct clk_hw *hw);
61752 };
61753+typedef struct clk_ops __no_const clk_ops_no_const;
61754
61755 /**
61756 * struct clk_init_data - holds init data that's common to all clocks and is
61757diff --git a/include/linux/compiler-gcc4.h b/include/linux/compiler-gcc4.h
61758index 934bc34..1b47129 100644
61759--- a/include/linux/compiler-gcc4.h
61760+++ b/include/linux/compiler-gcc4.h
61761@@ -32,6 +32,21 @@
61762 #define __linktime_error(message) __attribute__((__error__(message)))
61763
61764 #if __GNUC_MINOR__ >= 5
61765+
61766+#ifdef CONSTIFY_PLUGIN
61767+#define __no_const __attribute__((no_const))
61768+#define __do_const __attribute__((do_const))
61769+#endif
61770+
61771+#ifdef SIZE_OVERFLOW_PLUGIN
61772+#define __size_overflow(...) __attribute__((size_overflow(__VA_ARGS__)))
61773+#define __intentional_overflow(...) __attribute__((intentional_overflow(__VA_ARGS__)))
61774+#endif
61775+
61776+#ifdef LATENT_ENTROPY_PLUGIN
61777+#define __latent_entropy __attribute__((latent_entropy))
61778+#endif
61779+
61780 /*
61781 * Mark a position in code as unreachable. This can be used to
61782 * suppress control flow warnings after asm blocks that transfer
61783@@ -47,6 +62,11 @@
61784 #define __noclone __attribute__((__noclone__))
61785
61786 #endif
61787+
61788+#define __alloc_size(...) __attribute((alloc_size(__VA_ARGS__)))
61789+#define __bos(ptr, arg) __builtin_object_size((ptr), (arg))
61790+#define __bos0(ptr) __bos((ptr), 0)
61791+#define __bos1(ptr) __bos((ptr), 1)
61792 #endif
61793
61794 #if __GNUC_MINOR__ >= 6
61795diff --git a/include/linux/compiler.h b/include/linux/compiler.h
61796index f430e41..38be90f 100644
61797--- a/include/linux/compiler.h
61798+++ b/include/linux/compiler.h
61799@@ -5,31 +5,62 @@
61800
61801 #ifdef __CHECKER__
61802 # define __user __attribute__((noderef, address_space(1)))
61803+# define __force_user __force __user
61804 # define __kernel __attribute__((address_space(0)))
61805+# define __force_kernel __force __kernel
61806 # define __safe __attribute__((safe))
61807 # define __force __attribute__((force))
61808 # define __nocast __attribute__((nocast))
61809 # define __iomem __attribute__((noderef, address_space(2)))
61810+# define __force_iomem __force __iomem
61811 # define __acquires(x) __attribute__((context(x,0,1)))
61812 # define __releases(x) __attribute__((context(x,1,0)))
61813 # define __acquire(x) __context__(x,1)
61814 # define __release(x) __context__(x,-1)
61815 # define __cond_lock(x,c) ((c) ? ({ __acquire(x); 1; }) : 0)
61816 # define __percpu __attribute__((noderef, address_space(3)))
61817+# define __force_percpu __force __percpu
61818 #ifdef CONFIG_SPARSE_RCU_POINTER
61819 # define __rcu __attribute__((noderef, address_space(4)))
61820+# define __force_rcu __force __rcu
61821 #else
61822 # define __rcu
61823+# define __force_rcu
61824 #endif
61825 extern void __chk_user_ptr(const volatile void __user *);
61826 extern void __chk_io_ptr(const volatile void __iomem *);
61827+#elif defined(CHECKER_PLUGIN)
61828+//# define __user
61829+//# define __force_user
61830+//# define __kernel
61831+//# define __force_kernel
61832+# define __safe
61833+# define __force
61834+# define __nocast
61835+# define __iomem
61836+# define __force_iomem
61837+# define __chk_user_ptr(x) (void)0
61838+# define __chk_io_ptr(x) (void)0
61839+# define __builtin_warning(x, y...) (1)
61840+# define __acquires(x)
61841+# define __releases(x)
61842+# define __acquire(x) (void)0
61843+# define __release(x) (void)0
61844+# define __cond_lock(x,c) (c)
61845+# define __percpu
61846+# define __force_percpu
61847+# define __rcu
61848+# define __force_rcu
61849 #else
61850 # define __user
61851+# define __force_user
61852 # define __kernel
61853+# define __force_kernel
61854 # define __safe
61855 # define __force
61856 # define __nocast
61857 # define __iomem
61858+# define __force_iomem
61859 # define __chk_user_ptr(x) (void)0
61860 # define __chk_io_ptr(x) (void)0
61861 # define __builtin_warning(x, y...) (1)
61862@@ -39,7 +70,9 @@ extern void __chk_io_ptr(const volatile void __iomem *);
61863 # define __release(x) (void)0
61864 # define __cond_lock(x,c) (c)
61865 # define __percpu
61866+# define __force_percpu
61867 # define __rcu
61868+# define __force_rcu
61869 #endif
61870
61871 #ifdef __KERNEL__
61872@@ -264,6 +297,26 @@ void ftrace_likely_update(struct ftrace_branch_data *f, int val, int expect);
61873 # define __attribute_const__ /* unimplemented */
61874 #endif
61875
61876+#ifndef __no_const
61877+# define __no_const
61878+#endif
61879+
61880+#ifndef __do_const
61881+# define __do_const
61882+#endif
61883+
61884+#ifndef __size_overflow
61885+# define __size_overflow(...)
61886+#endif
61887+
61888+#ifndef __intentional_overflow
61889+# define __intentional_overflow(...)
61890+#endif
61891+
61892+#ifndef __latent_entropy
61893+# define __latent_entropy
61894+#endif
61895+
61896 /*
61897 * Tell gcc if a function is cold. The compiler will assume any path
61898 * directly leading to the call is unlikely.
61899@@ -273,6 +326,22 @@ void ftrace_likely_update(struct ftrace_branch_data *f, int val, int expect);
61900 #define __cold
61901 #endif
61902
61903+#ifndef __alloc_size
61904+#define __alloc_size(...)
61905+#endif
61906+
61907+#ifndef __bos
61908+#define __bos(ptr, arg)
61909+#endif
61910+
61911+#ifndef __bos0
61912+#define __bos0(ptr)
61913+#endif
61914+
61915+#ifndef __bos1
61916+#define __bos1(ptr)
61917+#endif
61918+
61919 /* Simple shorthand for a section definition */
61920 #ifndef __section
61921 # define __section(S) __attribute__ ((__section__(#S)))
61922@@ -312,6 +381,7 @@ void ftrace_likely_update(struct ftrace_branch_data *f, int val, int expect);
61923 * use is to mediate communication between process-level code and irq/NMI
61924 * handlers, all running on the same CPU.
61925 */
61926-#define ACCESS_ONCE(x) (*(volatile typeof(x) *)&(x))
61927+#define ACCESS_ONCE(x) (*(volatile const typeof(x) *)&(x))
61928+#define ACCESS_ONCE_RW(x) (*(volatile typeof(x) *)&(x))
61929
61930 #endif /* __LINUX_COMPILER_H */
61931diff --git a/include/linux/cred.h b/include/linux/cred.h
61932index ebbed2c..908cc2c 100644
61933--- a/include/linux/cred.h
61934+++ b/include/linux/cred.h
61935@@ -208,6 +208,9 @@ static inline void validate_creds_for_do_exit(struct task_struct *tsk)
61936 static inline void validate_process_creds(void)
61937 {
61938 }
61939+static inline void validate_task_creds(struct task_struct *task)
61940+{
61941+}
61942 #endif
61943
61944 /**
61945diff --git a/include/linux/crypto.h b/include/linux/crypto.h
61946index b92eadf..b4ecdc1 100644
61947--- a/include/linux/crypto.h
61948+++ b/include/linux/crypto.h
61949@@ -373,7 +373,7 @@ struct cipher_tfm {
61950 const u8 *key, unsigned int keylen);
61951 void (*cit_encrypt_one)(struct crypto_tfm *tfm, u8 *dst, const u8 *src);
61952 void (*cit_decrypt_one)(struct crypto_tfm *tfm, u8 *dst, const u8 *src);
61953-};
61954+} __no_const;
61955
61956 struct hash_tfm {
61957 int (*init)(struct hash_desc *desc);
61958@@ -394,13 +394,13 @@ struct compress_tfm {
61959 int (*cot_decompress)(struct crypto_tfm *tfm,
61960 const u8 *src, unsigned int slen,
61961 u8 *dst, unsigned int *dlen);
61962-};
61963+} __no_const;
61964
61965 struct rng_tfm {
61966 int (*rng_gen_random)(struct crypto_rng *tfm, u8 *rdata,
61967 unsigned int dlen);
61968 int (*rng_reset)(struct crypto_rng *tfm, u8 *seed, unsigned int slen);
61969-};
61970+} __no_const;
61971
61972 #define crt_ablkcipher crt_u.ablkcipher
61973 #define crt_aead crt_u.aead
61974diff --git a/include/linux/decompress/mm.h b/include/linux/decompress/mm.h
61975index 7925bf0..d5143d2 100644
61976--- a/include/linux/decompress/mm.h
61977+++ b/include/linux/decompress/mm.h
61978@@ -77,7 +77,7 @@ static void free(void *where)
61979 * warnings when not needed (indeed large_malloc / large_free are not
61980 * needed by inflate */
61981
61982-#define malloc(a) kmalloc(a, GFP_KERNEL)
61983+#define malloc(a) kmalloc((a), GFP_KERNEL)
61984 #define free(a) kfree(a)
61985
61986 #define large_malloc(a) vmalloc(a)
61987diff --git a/include/linux/dma-mapping.h b/include/linux/dma-mapping.h
61988index 94af418..b1ca7a2 100644
61989--- a/include/linux/dma-mapping.h
61990+++ b/include/linux/dma-mapping.h
61991@@ -54,7 +54,7 @@ struct dma_map_ops {
61992 u64 (*get_required_mask)(struct device *dev);
61993 #endif
61994 int is_phys;
61995-};
61996+} __do_const;
61997
61998 #define DMA_BIT_MASK(n) (((n) == 64) ? ~0ULL : ((1ULL<<(n))-1))
61999
62000diff --git a/include/linux/dmaengine.h b/include/linux/dmaengine.h
62001index 9c02a45..89fdd73 100644
62002--- a/include/linux/dmaengine.h
62003+++ b/include/linux/dmaengine.h
62004@@ -1017,9 +1017,9 @@ struct dma_pinned_list {
62005 struct dma_pinned_list *dma_pin_iovec_pages(struct iovec *iov, size_t len);
62006 void dma_unpin_iovec_pages(struct dma_pinned_list* pinned_list);
62007
62008-dma_cookie_t dma_memcpy_to_iovec(struct dma_chan *chan, struct iovec *iov,
62009+dma_cookie_t __intentional_overflow(0) dma_memcpy_to_iovec(struct dma_chan *chan, struct iovec *iov,
62010 struct dma_pinned_list *pinned_list, unsigned char *kdata, size_t len);
62011-dma_cookie_t dma_memcpy_pg_to_iovec(struct dma_chan *chan, struct iovec *iov,
62012+dma_cookie_t __intentional_overflow(0) dma_memcpy_pg_to_iovec(struct dma_chan *chan, struct iovec *iov,
62013 struct dma_pinned_list *pinned_list, struct page *page,
62014 unsigned int offset, size_t len);
62015
62016diff --git a/include/linux/efi.h b/include/linux/efi.h
62017index 5782114..e9b1ba1 100644
62018--- a/include/linux/efi.h
62019+++ b/include/linux/efi.h
62020@@ -640,7 +640,7 @@ struct efivar_operations {
62021 efi_get_variable_t *get_variable;
62022 efi_get_next_variable_t *get_next_variable;
62023 efi_set_variable_t *set_variable;
62024-};
62025+} __no_const;
62026
62027 struct efivars {
62028 /*
62029diff --git a/include/linux/elf.h b/include/linux/elf.h
62030index 999b4f5..57753b4 100644
62031--- a/include/linux/elf.h
62032+++ b/include/linux/elf.h
62033@@ -40,6 +40,17 @@ typedef __s64 Elf64_Sxword;
62034 #define PT_GNU_EH_FRAME 0x6474e550
62035
62036 #define PT_GNU_STACK (PT_LOOS + 0x474e551)
62037+#define PT_GNU_RELRO (PT_LOOS + 0x474e552)
62038+
62039+#define PT_PAX_FLAGS (PT_LOOS + 0x5041580)
62040+
62041+/* Constants for the e_flags field */
62042+#define EF_PAX_PAGEEXEC 1 /* Paging based non-executable pages */
62043+#define EF_PAX_EMUTRAMP 2 /* Emulate trampolines */
62044+#define EF_PAX_MPROTECT 4 /* Restrict mprotect() */
62045+#define EF_PAX_RANDMMAP 8 /* Randomize mmap() base */
62046+/*#define EF_PAX_RANDEXEC 16*/ /* Randomize ET_EXEC base */
62047+#define EF_PAX_SEGMEXEC 32 /* Segmentation based non-executable pages */
62048
62049 /*
62050 * Extended Numbering
62051@@ -97,6 +108,8 @@ typedef __s64 Elf64_Sxword;
62052 #define DT_DEBUG 21
62053 #define DT_TEXTREL 22
62054 #define DT_JMPREL 23
62055+#define DT_FLAGS 30
62056+ #define DF_TEXTREL 0x00000004
62057 #define DT_ENCODING 32
62058 #define OLD_DT_LOOS 0x60000000
62059 #define DT_LOOS 0x6000000d
62060@@ -243,6 +256,19 @@ typedef struct elf64_hdr {
62061 #define PF_W 0x2
62062 #define PF_X 0x1
62063
62064+#define PF_PAGEEXEC (1U << 4) /* Enable PAGEEXEC */
62065+#define PF_NOPAGEEXEC (1U << 5) /* Disable PAGEEXEC */
62066+#define PF_SEGMEXEC (1U << 6) /* Enable SEGMEXEC */
62067+#define PF_NOSEGMEXEC (1U << 7) /* Disable SEGMEXEC */
62068+#define PF_MPROTECT (1U << 8) /* Enable MPROTECT */
62069+#define PF_NOMPROTECT (1U << 9) /* Disable MPROTECT */
62070+/*#define PF_RANDEXEC (1U << 10)*/ /* Enable RANDEXEC */
62071+/*#define PF_NORANDEXEC (1U << 11)*/ /* Disable RANDEXEC */
62072+#define PF_EMUTRAMP (1U << 12) /* Enable EMUTRAMP */
62073+#define PF_NOEMUTRAMP (1U << 13) /* Disable EMUTRAMP */
62074+#define PF_RANDMMAP (1U << 14) /* Enable RANDMMAP */
62075+#define PF_NORANDMMAP (1U << 15) /* Disable RANDMMAP */
62076+
62077 typedef struct elf32_phdr{
62078 Elf32_Word p_type;
62079 Elf32_Off p_offset;
62080@@ -335,6 +361,8 @@ typedef struct elf64_shdr {
62081 #define EI_OSABI 7
62082 #define EI_PAD 8
62083
62084+#define EI_PAX 14
62085+
62086 #define ELFMAG0 0x7f /* EI_MAG */
62087 #define ELFMAG1 'E'
62088 #define ELFMAG2 'L'
62089@@ -421,6 +449,7 @@ extern Elf32_Dyn _DYNAMIC [];
62090 #define elf_note elf32_note
62091 #define elf_addr_t Elf32_Off
62092 #define Elf_Half Elf32_Half
62093+#define elf_dyn Elf32_Dyn
62094
62095 #else
62096
62097@@ -431,6 +460,7 @@ extern Elf64_Dyn _DYNAMIC [];
62098 #define elf_note elf64_note
62099 #define elf_addr_t Elf64_Off
62100 #define Elf_Half Elf64_Half
62101+#define elf_dyn Elf64_Dyn
62102
62103 #endif
62104
62105diff --git a/include/linux/filter.h b/include/linux/filter.h
62106index 82b0135..917914d 100644
62107--- a/include/linux/filter.h
62108+++ b/include/linux/filter.h
62109@@ -146,6 +146,7 @@ struct compat_sock_fprog {
62110
62111 struct sk_buff;
62112 struct sock;
62113+struct bpf_jit_work;
62114
62115 struct sk_filter
62116 {
62117@@ -153,6 +154,9 @@ struct sk_filter
62118 unsigned int len; /* Number of filter blocks */
62119 unsigned int (*bpf_func)(const struct sk_buff *skb,
62120 const struct sock_filter *filter);
62121+#ifdef CONFIG_BPF_JIT
62122+ struct bpf_jit_work *work;
62123+#endif
62124 struct rcu_head rcu;
62125 struct sock_filter insns[0];
62126 };
62127diff --git a/include/linux/firewire.h b/include/linux/firewire.h
62128index db04ec5..f6ed627 100644
62129--- a/include/linux/firewire.h
62130+++ b/include/linux/firewire.h
62131@@ -430,7 +430,7 @@ struct fw_iso_context {
62132 union {
62133 fw_iso_callback_t sc;
62134 fw_iso_mc_callback_t mc;
62135- } callback;
62136+ } __no_const callback;
62137 void *callback_data;
62138 };
62139
62140diff --git a/include/linux/frontswap.h b/include/linux/frontswap.h
62141index 0e4e2ee..4ff4312 100644
62142--- a/include/linux/frontswap.h
62143+++ b/include/linux/frontswap.h
62144@@ -11,7 +11,7 @@ struct frontswap_ops {
62145 int (*load)(unsigned, pgoff_t, struct page *);
62146 void (*invalidate_page)(unsigned, pgoff_t);
62147 void (*invalidate_area)(unsigned);
62148-};
62149+} __no_const;
62150
62151 extern bool frontswap_enabled;
62152 extern struct frontswap_ops
62153diff --git a/include/linux/fs.h b/include/linux/fs.h
62154index aa11047..7d046d0 100644
62155--- a/include/linux/fs.h
62156+++ b/include/linux/fs.h
62157@@ -1802,7 +1802,8 @@ struct file_operations {
62158 int (*setlease)(struct file *, long, struct file_lock **);
62159 long (*fallocate)(struct file *file, int mode, loff_t offset,
62160 loff_t len);
62161-};
62162+} __do_const;
62163+typedef struct file_operations __no_const file_operations_no_const;
62164
62165 struct inode_operations {
62166 struct dentry * (*lookup) (struct inode *,struct dentry *, unsigned int);
62167diff --git a/include/linux/fs_struct.h b/include/linux/fs_struct.h
62168index 003dc0f..3c4ea97 100644
62169--- a/include/linux/fs_struct.h
62170+++ b/include/linux/fs_struct.h
62171@@ -6,7 +6,7 @@
62172 #include <linux/seqlock.h>
62173
62174 struct fs_struct {
62175- int users;
62176+ atomic_t users;
62177 spinlock_t lock;
62178 seqcount_t seq;
62179 int umask;
62180diff --git a/include/linux/fscache-cache.h b/include/linux/fscache-cache.h
62181index ce31408..b1ad003 100644
62182--- a/include/linux/fscache-cache.h
62183+++ b/include/linux/fscache-cache.h
62184@@ -102,7 +102,7 @@ struct fscache_operation {
62185 fscache_operation_release_t release;
62186 };
62187
62188-extern atomic_t fscache_op_debug_id;
62189+extern atomic_unchecked_t fscache_op_debug_id;
62190 extern void fscache_op_work_func(struct work_struct *work);
62191
62192 extern void fscache_enqueue_operation(struct fscache_operation *);
62193@@ -122,7 +122,7 @@ static inline void fscache_operation_init(struct fscache_operation *op,
62194 {
62195 INIT_WORK(&op->work, fscache_op_work_func);
62196 atomic_set(&op->usage, 1);
62197- op->debug_id = atomic_inc_return(&fscache_op_debug_id);
62198+ op->debug_id = atomic_inc_return_unchecked(&fscache_op_debug_id);
62199 op->processor = processor;
62200 op->release = release;
62201 INIT_LIST_HEAD(&op->pend_link);
62202diff --git a/include/linux/fsnotify.h b/include/linux/fsnotify.h
62203index a6dfe69..569586df 100644
62204--- a/include/linux/fsnotify.h
62205+++ b/include/linux/fsnotify.h
62206@@ -315,7 +315,7 @@ static inline void fsnotify_change(struct dentry *dentry, unsigned int ia_valid)
62207 */
62208 static inline const unsigned char *fsnotify_oldname_init(const unsigned char *name)
62209 {
62210- return kstrdup(name, GFP_KERNEL);
62211+ return (const unsigned char *)kstrdup((const char *)name, GFP_KERNEL);
62212 }
62213
62214 /*
62215diff --git a/include/linux/fsnotify_backend.h b/include/linux/fsnotify_backend.h
62216index 63d966d..cdcb717 100644
62217--- a/include/linux/fsnotify_backend.h
62218+++ b/include/linux/fsnotify_backend.h
62219@@ -105,6 +105,7 @@ struct fsnotify_ops {
62220 void (*freeing_mark)(struct fsnotify_mark *mark, struct fsnotify_group *group);
62221 void (*free_event_priv)(struct fsnotify_event_private_data *priv);
62222 };
62223+typedef struct fsnotify_ops __no_const fsnotify_ops_no_const;
62224
62225 /*
62226 * A group is a "thing" that wants to receive notification about filesystem
62227diff --git a/include/linux/ftrace_event.h b/include/linux/ftrace_event.h
62228index 642928c..e6c83a7 100644
62229--- a/include/linux/ftrace_event.h
62230+++ b/include/linux/ftrace_event.h
62231@@ -97,7 +97,7 @@ struct trace_event_functions {
62232 trace_print_func raw;
62233 trace_print_func hex;
62234 trace_print_func binary;
62235-};
62236+} __no_const;
62237
62238 struct trace_event {
62239 struct hlist_node node;
62240@@ -266,7 +266,7 @@ extern int trace_define_field(struct ftrace_event_call *call, const char *type,
62241 extern int trace_add_event_call(struct ftrace_event_call *call);
62242 extern void trace_remove_event_call(struct ftrace_event_call *call);
62243
62244-#define is_signed_type(type) (((type)(-1)) < 0)
62245+#define is_signed_type(type) (((type)(-1)) < (type)1)
62246
62247 int trace_set_clr_event(const char *system, const char *event, int set);
62248
62249diff --git a/include/linux/genhd.h b/include/linux/genhd.h
62250index 4f440b3..342233a 100644
62251--- a/include/linux/genhd.h
62252+++ b/include/linux/genhd.h
62253@@ -190,7 +190,7 @@ struct gendisk {
62254 struct kobject *slave_dir;
62255
62256 struct timer_rand_state *random;
62257- atomic_t sync_io; /* RAID */
62258+ atomic_unchecked_t sync_io; /* RAID */
62259 struct disk_events *ev;
62260 #ifdef CONFIG_BLK_DEV_INTEGRITY
62261 struct blk_integrity *integrity;
62262diff --git a/include/linux/gfp.h b/include/linux/gfp.h
62263index 4883f39..26688a8 100644
62264--- a/include/linux/gfp.h
62265+++ b/include/linux/gfp.h
62266@@ -39,6 +39,12 @@ struct vm_area_struct;
62267 #define ___GFP_OTHER_NODE 0x800000u
62268 #define ___GFP_WRITE 0x1000000u
62269
62270+#ifdef CONFIG_PAX_USERCOPY_SLABS
62271+#define ___GFP_USERCOPY 0x2000000u
62272+#else
62273+#define ___GFP_USERCOPY 0
62274+#endif
62275+
62276 /*
62277 * GFP bitmasks..
62278 *
62279@@ -93,6 +99,7 @@ struct vm_area_struct;
62280 #define __GFP_NO_KSWAPD ((__force gfp_t)___GFP_NO_KSWAPD)
62281 #define __GFP_OTHER_NODE ((__force gfp_t)___GFP_OTHER_NODE) /* On behalf of other node */
62282 #define __GFP_WRITE ((__force gfp_t)___GFP_WRITE) /* Allocator intends to dirty page */
62283+#define __GFP_USERCOPY ((__force gfp_t)___GFP_USERCOPY)/* Allocator intends to copy page to/from userland */
62284
62285 /*
62286 * This may seem redundant, but it's a way of annotating false positives vs.
62287@@ -100,7 +107,7 @@ struct vm_area_struct;
62288 */
62289 #define __GFP_NOTRACK_FALSE_POSITIVE (__GFP_NOTRACK)
62290
62291-#define __GFP_BITS_SHIFT 25 /* Room for N __GFP_FOO bits */
62292+#define __GFP_BITS_SHIFT 26 /* Room for N __GFP_FOO bits */
62293 #define __GFP_BITS_MASK ((__force gfp_t)((1 << __GFP_BITS_SHIFT) - 1))
62294
62295 /* This equals 0, but use constants in case they ever change */
62296@@ -154,6 +161,8 @@ struct vm_area_struct;
62297 /* 4GB DMA on some platforms */
62298 #define GFP_DMA32 __GFP_DMA32
62299
62300+#define GFP_USERCOPY __GFP_USERCOPY
62301+
62302 /* Convert GFP flags to their corresponding migrate type */
62303 static inline int allocflags_to_migratetype(gfp_t gfp_flags)
62304 {
62305diff --git a/include/linux/gracl.h b/include/linux/gracl.h
62306new file mode 100644
62307index 0000000..c938b1f
62308--- /dev/null
62309+++ b/include/linux/gracl.h
62310@@ -0,0 +1,319 @@
62311+#ifndef GR_ACL_H
62312+#define GR_ACL_H
62313+
62314+#include <linux/grdefs.h>
62315+#include <linux/resource.h>
62316+#include <linux/capability.h>
62317+#include <linux/dcache.h>
62318+#include <asm/resource.h>
62319+
62320+/* Major status information */
62321+
62322+#define GR_VERSION "grsecurity 2.9.1"
62323+#define GRSECURITY_VERSION 0x2901
62324+
62325+enum {
62326+ GR_SHUTDOWN = 0,
62327+ GR_ENABLE = 1,
62328+ GR_SPROLE = 2,
62329+ GR_RELOAD = 3,
62330+ GR_SEGVMOD = 4,
62331+ GR_STATUS = 5,
62332+ GR_UNSPROLE = 6,
62333+ GR_PASSSET = 7,
62334+ GR_SPROLEPAM = 8,
62335+};
62336+
62337+/* Password setup definitions
62338+ * kernel/grhash.c */
62339+enum {
62340+ GR_PW_LEN = 128,
62341+ GR_SALT_LEN = 16,
62342+ GR_SHA_LEN = 32,
62343+};
62344+
62345+enum {
62346+ GR_SPROLE_LEN = 64,
62347+};
62348+
62349+enum {
62350+ GR_NO_GLOB = 0,
62351+ GR_REG_GLOB,
62352+ GR_CREATE_GLOB
62353+};
62354+
62355+#define GR_NLIMITS 32
62356+
62357+/* Begin Data Structures */
62358+
62359+struct sprole_pw {
62360+ unsigned char *rolename;
62361+ unsigned char salt[GR_SALT_LEN];
62362+ unsigned char sum[GR_SHA_LEN]; /* 256-bit SHA hash of the password */
62363+};
62364+
62365+struct name_entry {
62366+ __u32 key;
62367+ ino_t inode;
62368+ dev_t device;
62369+ char *name;
62370+ __u16 len;
62371+ __u8 deleted;
62372+ struct name_entry *prev;
62373+ struct name_entry *next;
62374+};
62375+
62376+struct inodev_entry {
62377+ struct name_entry *nentry;
62378+ struct inodev_entry *prev;
62379+ struct inodev_entry *next;
62380+};
62381+
62382+struct acl_role_db {
62383+ struct acl_role_label **r_hash;
62384+ __u32 r_size;
62385+};
62386+
62387+struct inodev_db {
62388+ struct inodev_entry **i_hash;
62389+ __u32 i_size;
62390+};
62391+
62392+struct name_db {
62393+ struct name_entry **n_hash;
62394+ __u32 n_size;
62395+};
62396+
62397+struct crash_uid {
62398+ uid_t uid;
62399+ unsigned long expires;
62400+};
62401+
62402+struct gr_hash_struct {
62403+ void **table;
62404+ void **nametable;
62405+ void *first;
62406+ __u32 table_size;
62407+ __u32 used_size;
62408+ int type;
62409+};
62410+
62411+/* Userspace Grsecurity ACL data structures */
62412+
62413+struct acl_subject_label {
62414+ char *filename;
62415+ ino_t inode;
62416+ dev_t device;
62417+ __u32 mode;
62418+ kernel_cap_t cap_mask;
62419+ kernel_cap_t cap_lower;
62420+ kernel_cap_t cap_invert_audit;
62421+
62422+ struct rlimit res[GR_NLIMITS];
62423+ __u32 resmask;
62424+
62425+ __u8 user_trans_type;
62426+ __u8 group_trans_type;
62427+ uid_t *user_transitions;
62428+ gid_t *group_transitions;
62429+ __u16 user_trans_num;
62430+ __u16 group_trans_num;
62431+
62432+ __u32 sock_families[2];
62433+ __u32 ip_proto[8];
62434+ __u32 ip_type;
62435+ struct acl_ip_label **ips;
62436+ __u32 ip_num;
62437+ __u32 inaddr_any_override;
62438+
62439+ __u32 crashes;
62440+ unsigned long expires;
62441+
62442+ struct acl_subject_label *parent_subject;
62443+ struct gr_hash_struct *hash;
62444+ struct acl_subject_label *prev;
62445+ struct acl_subject_label *next;
62446+
62447+ struct acl_object_label **obj_hash;
62448+ __u32 obj_hash_size;
62449+ __u16 pax_flags;
62450+};
62451+
62452+struct role_allowed_ip {
62453+ __u32 addr;
62454+ __u32 netmask;
62455+
62456+ struct role_allowed_ip *prev;
62457+ struct role_allowed_ip *next;
62458+};
62459+
62460+struct role_transition {
62461+ char *rolename;
62462+
62463+ struct role_transition *prev;
62464+ struct role_transition *next;
62465+};
62466+
62467+struct acl_role_label {
62468+ char *rolename;
62469+ uid_t uidgid;
62470+ __u16 roletype;
62471+
62472+ __u16 auth_attempts;
62473+ unsigned long expires;
62474+
62475+ struct acl_subject_label *root_label;
62476+ struct gr_hash_struct *hash;
62477+
62478+ struct acl_role_label *prev;
62479+ struct acl_role_label *next;
62480+
62481+ struct role_transition *transitions;
62482+ struct role_allowed_ip *allowed_ips;
62483+ uid_t *domain_children;
62484+ __u16 domain_child_num;
62485+
62486+ umode_t umask;
62487+
62488+ struct acl_subject_label **subj_hash;
62489+ __u32 subj_hash_size;
62490+};
62491+
62492+struct user_acl_role_db {
62493+ struct acl_role_label **r_table;
62494+ __u32 num_pointers; /* Number of allocations to track */
62495+ __u32 num_roles; /* Number of roles */
62496+ __u32 num_domain_children; /* Number of domain children */
62497+ __u32 num_subjects; /* Number of subjects */
62498+ __u32 num_objects; /* Number of objects */
62499+};
62500+
62501+struct acl_object_label {
62502+ char *filename;
62503+ ino_t inode;
62504+ dev_t device;
62505+ __u32 mode;
62506+
62507+ struct acl_subject_label *nested;
62508+ struct acl_object_label *globbed;
62509+
62510+ /* next two structures not used */
62511+
62512+ struct acl_object_label *prev;
62513+ struct acl_object_label *next;
62514+};
62515+
62516+struct acl_ip_label {
62517+ char *iface;
62518+ __u32 addr;
62519+ __u32 netmask;
62520+ __u16 low, high;
62521+ __u8 mode;
62522+ __u32 type;
62523+ __u32 proto[8];
62524+
62525+ /* next two structures not used */
62526+
62527+ struct acl_ip_label *prev;
62528+ struct acl_ip_label *next;
62529+};
62530+
62531+struct gr_arg {
62532+ struct user_acl_role_db role_db;
62533+ unsigned char pw[GR_PW_LEN];
62534+ unsigned char salt[GR_SALT_LEN];
62535+ unsigned char sum[GR_SHA_LEN];
62536+ unsigned char sp_role[GR_SPROLE_LEN];
62537+ struct sprole_pw *sprole_pws;
62538+ dev_t segv_device;
62539+ ino_t segv_inode;
62540+ uid_t segv_uid;
62541+ __u16 num_sprole_pws;
62542+ __u16 mode;
62543+};
62544+
62545+struct gr_arg_wrapper {
62546+ struct gr_arg *arg;
62547+ __u32 version;
62548+ __u32 size;
62549+};
62550+
62551+struct subject_map {
62552+ struct acl_subject_label *user;
62553+ struct acl_subject_label *kernel;
62554+ struct subject_map *prev;
62555+ struct subject_map *next;
62556+};
62557+
62558+struct acl_subj_map_db {
62559+ struct subject_map **s_hash;
62560+ __u32 s_size;
62561+};
62562+
62563+/* End Data Structures Section */
62564+
62565+/* Hash functions generated by empirical testing by Brad Spengler
62566+ Makes good use of the low bits of the inode. Generally 0-1 times
62567+ in loop for successful match. 0-3 for unsuccessful match.
62568+ Shift/add algorithm with modulus of table size and an XOR*/
62569+
62570+static __inline__ unsigned int
62571+rhash(const uid_t uid, const __u16 type, const unsigned int sz)
62572+{
62573+ return ((((uid + type) << (16 + type)) ^ uid) % sz);
62574+}
62575+
62576+ static __inline__ unsigned int
62577+shash(const struct acl_subject_label *userp, const unsigned int sz)
62578+{
62579+ return ((const unsigned long)userp % sz);
62580+}
62581+
62582+static __inline__ unsigned int
62583+fhash(const ino_t ino, const dev_t dev, const unsigned int sz)
62584+{
62585+ return (((ino + dev) ^ ((ino << 13) + (ino << 23) + (dev << 9))) % sz);
62586+}
62587+
62588+static __inline__ unsigned int
62589+nhash(const char *name, const __u16 len, const unsigned int sz)
62590+{
62591+ return full_name_hash((const unsigned char *)name, len) % sz;
62592+}
62593+
62594+#define FOR_EACH_ROLE_START(role) \
62595+ role = role_list; \
62596+ while (role) {
62597+
62598+#define FOR_EACH_ROLE_END(role) \
62599+ role = role->prev; \
62600+ }
62601+
62602+#define FOR_EACH_SUBJECT_START(role,subj,iter) \
62603+ subj = NULL; \
62604+ iter = 0; \
62605+ while (iter < role->subj_hash_size) { \
62606+ if (subj == NULL) \
62607+ subj = role->subj_hash[iter]; \
62608+ if (subj == NULL) { \
62609+ iter++; \
62610+ continue; \
62611+ }
62612+
62613+#define FOR_EACH_SUBJECT_END(subj,iter) \
62614+ subj = subj->next; \
62615+ if (subj == NULL) \
62616+ iter++; \
62617+ }
62618+
62619+
62620+#define FOR_EACH_NESTED_SUBJECT_START(role,subj) \
62621+ subj = role->hash->first; \
62622+ while (subj != NULL) {
62623+
62624+#define FOR_EACH_NESTED_SUBJECT_END(subj) \
62625+ subj = subj->next; \
62626+ }
62627+
62628+#endif
62629+
62630diff --git a/include/linux/gralloc.h b/include/linux/gralloc.h
62631new file mode 100644
62632index 0000000..323ecf2
62633--- /dev/null
62634+++ b/include/linux/gralloc.h
62635@@ -0,0 +1,9 @@
62636+#ifndef __GRALLOC_H
62637+#define __GRALLOC_H
62638+
62639+void acl_free_all(void);
62640+int acl_alloc_stack_init(unsigned long size);
62641+void *acl_alloc(unsigned long len);
62642+void *acl_alloc_num(unsigned long num, unsigned long len);
62643+
62644+#endif
62645diff --git a/include/linux/grdefs.h b/include/linux/grdefs.h
62646new file mode 100644
62647index 0000000..b30e9bc
62648--- /dev/null
62649+++ b/include/linux/grdefs.h
62650@@ -0,0 +1,140 @@
62651+#ifndef GRDEFS_H
62652+#define GRDEFS_H
62653+
62654+/* Begin grsecurity status declarations */
62655+
62656+enum {
62657+ GR_READY = 0x01,
62658+ GR_STATUS_INIT = 0x00 // disabled state
62659+};
62660+
62661+/* Begin ACL declarations */
62662+
62663+/* Role flags */
62664+
62665+enum {
62666+ GR_ROLE_USER = 0x0001,
62667+ GR_ROLE_GROUP = 0x0002,
62668+ GR_ROLE_DEFAULT = 0x0004,
62669+ GR_ROLE_SPECIAL = 0x0008,
62670+ GR_ROLE_AUTH = 0x0010,
62671+ GR_ROLE_NOPW = 0x0020,
62672+ GR_ROLE_GOD = 0x0040,
62673+ GR_ROLE_LEARN = 0x0080,
62674+ GR_ROLE_TPE = 0x0100,
62675+ GR_ROLE_DOMAIN = 0x0200,
62676+ GR_ROLE_PAM = 0x0400,
62677+ GR_ROLE_PERSIST = 0x0800
62678+};
62679+
62680+/* ACL Subject and Object mode flags */
62681+enum {
62682+ GR_DELETED = 0x80000000
62683+};
62684+
62685+/* ACL Object-only mode flags */
62686+enum {
62687+ GR_READ = 0x00000001,
62688+ GR_APPEND = 0x00000002,
62689+ GR_WRITE = 0x00000004,
62690+ GR_EXEC = 0x00000008,
62691+ GR_FIND = 0x00000010,
62692+ GR_INHERIT = 0x00000020,
62693+ GR_SETID = 0x00000040,
62694+ GR_CREATE = 0x00000080,
62695+ GR_DELETE = 0x00000100,
62696+ GR_LINK = 0x00000200,
62697+ GR_AUDIT_READ = 0x00000400,
62698+ GR_AUDIT_APPEND = 0x00000800,
62699+ GR_AUDIT_WRITE = 0x00001000,
62700+ GR_AUDIT_EXEC = 0x00002000,
62701+ GR_AUDIT_FIND = 0x00004000,
62702+ GR_AUDIT_INHERIT= 0x00008000,
62703+ GR_AUDIT_SETID = 0x00010000,
62704+ GR_AUDIT_CREATE = 0x00020000,
62705+ GR_AUDIT_DELETE = 0x00040000,
62706+ GR_AUDIT_LINK = 0x00080000,
62707+ GR_PTRACERD = 0x00100000,
62708+ GR_NOPTRACE = 0x00200000,
62709+ GR_SUPPRESS = 0x00400000,
62710+ GR_NOLEARN = 0x00800000,
62711+ GR_INIT_TRANSFER= 0x01000000
62712+};
62713+
62714+#define GR_AUDITS (GR_AUDIT_READ | GR_AUDIT_WRITE | GR_AUDIT_APPEND | GR_AUDIT_EXEC | \
62715+ GR_AUDIT_FIND | GR_AUDIT_INHERIT | GR_AUDIT_SETID | \
62716+ GR_AUDIT_CREATE | GR_AUDIT_DELETE | GR_AUDIT_LINK)
62717+
62718+/* ACL subject-only mode flags */
62719+enum {
62720+ GR_KILL = 0x00000001,
62721+ GR_VIEW = 0x00000002,
62722+ GR_PROTECTED = 0x00000004,
62723+ GR_LEARN = 0x00000008,
62724+ GR_OVERRIDE = 0x00000010,
62725+ /* just a placeholder, this mode is only used in userspace */
62726+ GR_DUMMY = 0x00000020,
62727+ GR_PROTSHM = 0x00000040,
62728+ GR_KILLPROC = 0x00000080,
62729+ GR_KILLIPPROC = 0x00000100,
62730+ /* just a placeholder, this mode is only used in userspace */
62731+ GR_NOTROJAN = 0x00000200,
62732+ GR_PROTPROCFD = 0x00000400,
62733+ GR_PROCACCT = 0x00000800,
62734+ GR_RELAXPTRACE = 0x00001000,
62735+ GR_NESTED = 0x00002000,
62736+ GR_INHERITLEARN = 0x00004000,
62737+ GR_PROCFIND = 0x00008000,
62738+ GR_POVERRIDE = 0x00010000,
62739+ GR_KERNELAUTH = 0x00020000,
62740+ GR_ATSECURE = 0x00040000,
62741+ GR_SHMEXEC = 0x00080000
62742+};
62743+
62744+enum {
62745+ GR_PAX_ENABLE_SEGMEXEC = 0x0001,
62746+ GR_PAX_ENABLE_PAGEEXEC = 0x0002,
62747+ GR_PAX_ENABLE_MPROTECT = 0x0004,
62748+ GR_PAX_ENABLE_RANDMMAP = 0x0008,
62749+ GR_PAX_ENABLE_EMUTRAMP = 0x0010,
62750+ GR_PAX_DISABLE_SEGMEXEC = 0x0100,
62751+ GR_PAX_DISABLE_PAGEEXEC = 0x0200,
62752+ GR_PAX_DISABLE_MPROTECT = 0x0400,
62753+ GR_PAX_DISABLE_RANDMMAP = 0x0800,
62754+ GR_PAX_DISABLE_EMUTRAMP = 0x1000,
62755+};
62756+
62757+enum {
62758+ GR_ID_USER = 0x01,
62759+ GR_ID_GROUP = 0x02,
62760+};
62761+
62762+enum {
62763+ GR_ID_ALLOW = 0x01,
62764+ GR_ID_DENY = 0x02,
62765+};
62766+
62767+#define GR_CRASH_RES 31
62768+#define GR_UIDTABLE_MAX 500
62769+
62770+/* begin resource learning section */
62771+enum {
62772+ GR_RLIM_CPU_BUMP = 60,
62773+ GR_RLIM_FSIZE_BUMP = 50000,
62774+ GR_RLIM_DATA_BUMP = 10000,
62775+ GR_RLIM_STACK_BUMP = 1000,
62776+ GR_RLIM_CORE_BUMP = 10000,
62777+ GR_RLIM_RSS_BUMP = 500000,
62778+ GR_RLIM_NPROC_BUMP = 1,
62779+ GR_RLIM_NOFILE_BUMP = 5,
62780+ GR_RLIM_MEMLOCK_BUMP = 50000,
62781+ GR_RLIM_AS_BUMP = 500000,
62782+ GR_RLIM_LOCKS_BUMP = 2,
62783+ GR_RLIM_SIGPENDING_BUMP = 5,
62784+ GR_RLIM_MSGQUEUE_BUMP = 10000,
62785+ GR_RLIM_NICE_BUMP = 1,
62786+ GR_RLIM_RTPRIO_BUMP = 1,
62787+ GR_RLIM_RTTIME_BUMP = 1000000
62788+};
62789+
62790+#endif
62791diff --git a/include/linux/grinternal.h b/include/linux/grinternal.h
62792new file mode 100644
62793index 0000000..c9292f7
62794--- /dev/null
62795+++ b/include/linux/grinternal.h
62796@@ -0,0 +1,223 @@
62797+#ifndef __GRINTERNAL_H
62798+#define __GRINTERNAL_H
62799+
62800+#ifdef CONFIG_GRKERNSEC
62801+
62802+#include <linux/fs.h>
62803+#include <linux/mnt_namespace.h>
62804+#include <linux/nsproxy.h>
62805+#include <linux/gracl.h>
62806+#include <linux/grdefs.h>
62807+#include <linux/grmsg.h>
62808+
62809+void gr_add_learn_entry(const char *fmt, ...)
62810+ __attribute__ ((format (printf, 1, 2)));
62811+__u32 gr_search_file(const struct dentry *dentry, const __u32 mode,
62812+ const struct vfsmount *mnt);
62813+__u32 gr_check_create(const struct dentry *new_dentry,
62814+ const struct dentry *parent,
62815+ const struct vfsmount *mnt, const __u32 mode);
62816+int gr_check_protected_task(const struct task_struct *task);
62817+__u32 to_gr_audit(const __u32 reqmode);
62818+int gr_set_acls(const int type);
62819+int gr_apply_subject_to_task(struct task_struct *task);
62820+int gr_acl_is_enabled(void);
62821+char gr_roletype_to_char(void);
62822+
62823+void gr_handle_alertkill(struct task_struct *task);
62824+char *gr_to_filename(const struct dentry *dentry,
62825+ const struct vfsmount *mnt);
62826+char *gr_to_filename1(const struct dentry *dentry,
62827+ const struct vfsmount *mnt);
62828+char *gr_to_filename2(const struct dentry *dentry,
62829+ const struct vfsmount *mnt);
62830+char *gr_to_filename3(const struct dentry *dentry,
62831+ const struct vfsmount *mnt);
62832+
62833+extern int grsec_enable_ptrace_readexec;
62834+extern int grsec_enable_harden_ptrace;
62835+extern int grsec_enable_link;
62836+extern int grsec_enable_fifo;
62837+extern int grsec_enable_execve;
62838+extern int grsec_enable_shm;
62839+extern int grsec_enable_execlog;
62840+extern int grsec_enable_signal;
62841+extern int grsec_enable_audit_ptrace;
62842+extern int grsec_enable_forkfail;
62843+extern int grsec_enable_time;
62844+extern int grsec_enable_rofs;
62845+extern int grsec_enable_chroot_shmat;
62846+extern int grsec_enable_chroot_mount;
62847+extern int grsec_enable_chroot_double;
62848+extern int grsec_enable_chroot_pivot;
62849+extern int grsec_enable_chroot_chdir;
62850+extern int grsec_enable_chroot_chmod;
62851+extern int grsec_enable_chroot_mknod;
62852+extern int grsec_enable_chroot_fchdir;
62853+extern int grsec_enable_chroot_nice;
62854+extern int grsec_enable_chroot_execlog;
62855+extern int grsec_enable_chroot_caps;
62856+extern int grsec_enable_chroot_sysctl;
62857+extern int grsec_enable_chroot_unix;
62858+extern int grsec_enable_symlinkown;
62859+extern int grsec_symlinkown_gid;
62860+extern int grsec_enable_tpe;
62861+extern int grsec_tpe_gid;
62862+extern int grsec_enable_tpe_all;
62863+extern int grsec_enable_tpe_invert;
62864+extern int grsec_enable_socket_all;
62865+extern int grsec_socket_all_gid;
62866+extern int grsec_enable_socket_client;
62867+extern int grsec_socket_client_gid;
62868+extern int grsec_enable_socket_server;
62869+extern int grsec_socket_server_gid;
62870+extern int grsec_audit_gid;
62871+extern int grsec_enable_group;
62872+extern int grsec_enable_audit_textrel;
62873+extern int grsec_enable_log_rwxmaps;
62874+extern int grsec_enable_mount;
62875+extern int grsec_enable_chdir;
62876+extern int grsec_resource_logging;
62877+extern int grsec_enable_blackhole;
62878+extern int grsec_lastack_retries;
62879+extern int grsec_enable_brute;
62880+extern int grsec_lock;
62881+
62882+extern spinlock_t grsec_alert_lock;
62883+extern unsigned long grsec_alert_wtime;
62884+extern unsigned long grsec_alert_fyet;
62885+
62886+extern spinlock_t grsec_audit_lock;
62887+
62888+extern rwlock_t grsec_exec_file_lock;
62889+
62890+#define gr_task_fullpath(tsk) ((tsk)->exec_file ? \
62891+ gr_to_filename2((tsk)->exec_file->f_path.dentry, \
62892+ (tsk)->exec_file->f_vfsmnt) : "/")
62893+
62894+#define gr_parent_task_fullpath(tsk) ((tsk)->real_parent->exec_file ? \
62895+ gr_to_filename3((tsk)->real_parent->exec_file->f_path.dentry, \
62896+ (tsk)->real_parent->exec_file->f_vfsmnt) : "/")
62897+
62898+#define gr_task_fullpath0(tsk) ((tsk)->exec_file ? \
62899+ gr_to_filename((tsk)->exec_file->f_path.dentry, \
62900+ (tsk)->exec_file->f_vfsmnt) : "/")
62901+
62902+#define gr_parent_task_fullpath0(tsk) ((tsk)->real_parent->exec_file ? \
62903+ gr_to_filename1((tsk)->real_parent->exec_file->f_path.dentry, \
62904+ (tsk)->real_parent->exec_file->f_vfsmnt) : "/")
62905+
62906+#define proc_is_chrooted(tsk_a) ((tsk_a)->gr_is_chrooted)
62907+
62908+#define have_same_root(tsk_a,tsk_b) ((tsk_a)->gr_chroot_dentry == (tsk_b)->gr_chroot_dentry)
62909+
62910+#define DEFAULTSECARGS(task, cred, pcred) gr_task_fullpath(task), (task)->comm, \
62911+ (task)->pid, (cred)->uid, \
62912+ (cred)->euid, (cred)->gid, (cred)->egid, \
62913+ gr_parent_task_fullpath(task), \
62914+ (task)->real_parent->comm, (task)->real_parent->pid, \
62915+ (pcred)->uid, (pcred)->euid, \
62916+ (pcred)->gid, (pcred)->egid
62917+
62918+#define GR_CHROOT_CAPS {{ \
62919+ CAP_TO_MASK(CAP_LINUX_IMMUTABLE) | CAP_TO_MASK(CAP_NET_ADMIN) | \
62920+ CAP_TO_MASK(CAP_SYS_MODULE) | CAP_TO_MASK(CAP_SYS_RAWIO) | \
62921+ CAP_TO_MASK(CAP_SYS_PACCT) | CAP_TO_MASK(CAP_SYS_ADMIN) | \
62922+ CAP_TO_MASK(CAP_SYS_BOOT) | CAP_TO_MASK(CAP_SYS_TIME) | \
62923+ CAP_TO_MASK(CAP_NET_RAW) | CAP_TO_MASK(CAP_SYS_TTY_CONFIG) | \
62924+ CAP_TO_MASK(CAP_IPC_OWNER) | CAP_TO_MASK(CAP_SETFCAP), \
62925+ CAP_TO_MASK(CAP_SYSLOG) | CAP_TO_MASK(CAP_MAC_ADMIN) }}
62926+
62927+#define security_learn(normal_msg,args...) \
62928+({ \
62929+ read_lock(&grsec_exec_file_lock); \
62930+ gr_add_learn_entry(normal_msg "\n", ## args); \
62931+ read_unlock(&grsec_exec_file_lock); \
62932+})
62933+
62934+enum {
62935+ GR_DO_AUDIT,
62936+ GR_DONT_AUDIT,
62937+ /* used for non-audit messages that we shouldn't kill the task on */
62938+ GR_DONT_AUDIT_GOOD
62939+};
62940+
62941+enum {
62942+ GR_TTYSNIFF,
62943+ GR_RBAC,
62944+ GR_RBAC_STR,
62945+ GR_STR_RBAC,
62946+ GR_RBAC_MODE2,
62947+ GR_RBAC_MODE3,
62948+ GR_FILENAME,
62949+ GR_SYSCTL_HIDDEN,
62950+ GR_NOARGS,
62951+ GR_ONE_INT,
62952+ GR_ONE_INT_TWO_STR,
62953+ GR_ONE_STR,
62954+ GR_STR_INT,
62955+ GR_TWO_STR_INT,
62956+ GR_TWO_INT,
62957+ GR_TWO_U64,
62958+ GR_THREE_INT,
62959+ GR_FIVE_INT_TWO_STR,
62960+ GR_TWO_STR,
62961+ GR_THREE_STR,
62962+ GR_FOUR_STR,
62963+ GR_STR_FILENAME,
62964+ GR_FILENAME_STR,
62965+ GR_FILENAME_TWO_INT,
62966+ GR_FILENAME_TWO_INT_STR,
62967+ GR_TEXTREL,
62968+ GR_PTRACE,
62969+ GR_RESOURCE,
62970+ GR_CAP,
62971+ GR_SIG,
62972+ GR_SIG2,
62973+ GR_CRASH1,
62974+ GR_CRASH2,
62975+ GR_PSACCT,
62976+ GR_RWXMAP
62977+};
62978+
62979+#define gr_log_hidden_sysctl(audit, msg, str) gr_log_varargs(audit, msg, GR_SYSCTL_HIDDEN, str)
62980+#define gr_log_ttysniff(audit, msg, task) gr_log_varargs(audit, msg, GR_TTYSNIFF, task)
62981+#define gr_log_fs_rbac_generic(audit, msg, dentry, mnt) gr_log_varargs(audit, msg, GR_RBAC, dentry, mnt)
62982+#define gr_log_fs_rbac_str(audit, msg, dentry, mnt, str) gr_log_varargs(audit, msg, GR_RBAC_STR, dentry, mnt, str)
62983+#define gr_log_fs_str_rbac(audit, msg, str, dentry, mnt) gr_log_varargs(audit, msg, GR_STR_RBAC, str, dentry, mnt)
62984+#define gr_log_fs_rbac_mode2(audit, msg, dentry, mnt, str1, str2) gr_log_varargs(audit, msg, GR_RBAC_MODE2, dentry, mnt, str1, str2)
62985+#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)
62986+#define gr_log_fs_generic(audit, msg, dentry, mnt) gr_log_varargs(audit, msg, GR_FILENAME, dentry, mnt)
62987+#define gr_log_noargs(audit, msg) gr_log_varargs(audit, msg, GR_NOARGS)
62988+#define gr_log_int(audit, msg, num) gr_log_varargs(audit, msg, GR_ONE_INT, num)
62989+#define gr_log_int_str2(audit, msg, num, str1, str2) gr_log_varargs(audit, msg, GR_ONE_INT_TWO_STR, num, str1, str2)
62990+#define gr_log_str(audit, msg, str) gr_log_varargs(audit, msg, GR_ONE_STR, str)
62991+#define gr_log_str_int(audit, msg, str, num) gr_log_varargs(audit, msg, GR_STR_INT, str, num)
62992+#define gr_log_int_int(audit, msg, num1, num2) gr_log_varargs(audit, msg, GR_TWO_INT, num1, num2)
62993+#define gr_log_two_u64(audit, msg, num1, num2) gr_log_varargs(audit, msg, GR_TWO_U64, num1, num2)
62994+#define gr_log_int3(audit, msg, num1, num2, num3) gr_log_varargs(audit, msg, GR_THREE_INT, num1, num2, num3)
62995+#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)
62996+#define gr_log_str_str(audit, msg, str1, str2) gr_log_varargs(audit, msg, GR_TWO_STR, str1, str2)
62997+#define gr_log_str2_int(audit, msg, str1, str2, num) gr_log_varargs(audit, msg, GR_TWO_STR_INT, str1, str2, num)
62998+#define gr_log_str3(audit, msg, str1, str2, str3) gr_log_varargs(audit, msg, GR_THREE_STR, str1, str2, str3)
62999+#define gr_log_str4(audit, msg, str1, str2, str3, str4) gr_log_varargs(audit, msg, GR_FOUR_STR, str1, str2, str3, str4)
63000+#define gr_log_str_fs(audit, msg, str, dentry, mnt) gr_log_varargs(audit, msg, GR_STR_FILENAME, str, dentry, mnt)
63001+#define gr_log_fs_str(audit, msg, dentry, mnt, str) gr_log_varargs(audit, msg, GR_FILENAME_STR, dentry, mnt, str)
63002+#define gr_log_fs_int2(audit, msg, dentry, mnt, num1, num2) gr_log_varargs(audit, msg, GR_FILENAME_TWO_INT, dentry, mnt, num1, num2)
63003+#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)
63004+#define gr_log_textrel_ulong_ulong(audit, msg, file, ulong1, ulong2) gr_log_varargs(audit, msg, GR_TEXTREL, file, ulong1, ulong2)
63005+#define gr_log_ptrace(audit, msg, task) gr_log_varargs(audit, msg, GR_PTRACE, task)
63006+#define gr_log_res_ulong2_str(audit, msg, task, ulong1, str, ulong2) gr_log_varargs(audit, msg, GR_RESOURCE, task, ulong1, str, ulong2)
63007+#define gr_log_cap(audit, msg, task, str) gr_log_varargs(audit, msg, GR_CAP, task, str)
63008+#define gr_log_sig_addr(audit, msg, str, addr) gr_log_varargs(audit, msg, GR_SIG, str, addr)
63009+#define gr_log_sig_task(audit, msg, task, num) gr_log_varargs(audit, msg, GR_SIG2, task, num)
63010+#define gr_log_crash1(audit, msg, task, ulong) gr_log_varargs(audit, msg, GR_CRASH1, task, ulong)
63011+#define gr_log_crash2(audit, msg, task, ulong1) gr_log_varargs(audit, msg, GR_CRASH2, task, ulong1)
63012+#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)
63013+#define gr_log_rwxmap(audit, msg, str) gr_log_varargs(audit, msg, GR_RWXMAP, str)
63014+
63015+void gr_log_varargs(int audit, const char *msg, int argtypes, ...);
63016+
63017+#endif
63018+
63019+#endif
63020diff --git a/include/linux/grmsg.h b/include/linux/grmsg.h
63021new file mode 100644
63022index 0000000..54f4e85
63023--- /dev/null
63024+++ b/include/linux/grmsg.h
63025@@ -0,0 +1,110 @@
63026+#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"
63027+#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"
63028+#define GR_PTRACE_ACL_MSG "denied ptrace of %.950s(%.16s:%d) by "
63029+#define GR_STOPMOD_MSG "denied modification of module state by "
63030+#define GR_ROFS_BLOCKWRITE_MSG "denied write to block device %.950s by "
63031+#define GR_ROFS_MOUNT_MSG "denied writable mount of %.950s by "
63032+#define GR_IOPERM_MSG "denied use of ioperm() by "
63033+#define GR_IOPL_MSG "denied use of iopl() by "
63034+#define GR_SHMAT_ACL_MSG "denied attach of shared memory of UID %u, PID %d, ID %u by "
63035+#define GR_UNIX_CHROOT_MSG "denied connect() to abstract AF_UNIX socket outside of chroot by "
63036+#define GR_SHMAT_CHROOT_MSG "denied attach of shared memory outside of chroot by "
63037+#define GR_MEM_READWRITE_MSG "denied access of range %Lx -> %Lx in /dev/mem by "
63038+#define GR_SYMLINK_MSG "not following symlink %.950s owned by %d.%d by "
63039+#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"
63040+#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"
63041+#define GR_HIDDEN_ACL_MSG "%s access to hidden file %.950s by "
63042+#define GR_OPEN_ACL_MSG "%s open of %.950s for%s%s by "
63043+#define GR_CREATE_ACL_MSG "%s create of %.950s for%s%s by "
63044+#define GR_FIFO_MSG "denied writing FIFO %.950s of %d.%d by "
63045+#define GR_MKNOD_CHROOT_MSG "denied mknod of %.950s from chroot by "
63046+#define GR_MKNOD_ACL_MSG "%s mknod of %.950s by "
63047+#define GR_UNIXCONNECT_ACL_MSG "%s connect() to the unix domain socket %.950s by "
63048+#define GR_TTYSNIFF_ACL_MSG "terminal being sniffed by IP:%pI4 %.480s[%.16s:%d], parent %.480s[%.16s:%d] against "
63049+#define GR_MKDIR_ACL_MSG "%s mkdir of %.950s by "
63050+#define GR_RMDIR_ACL_MSG "%s rmdir of %.950s by "
63051+#define GR_UNLINK_ACL_MSG "%s unlink of %.950s by "
63052+#define GR_SYMLINK_ACL_MSG "%s symlink from %.480s to %.480s by "
63053+#define GR_HARDLINK_MSG "denied hardlink of %.930s (owned by %d.%d) to %.30s for "
63054+#define GR_LINK_ACL_MSG "%s link of %.480s to %.480s by "
63055+#define GR_INHERIT_ACL_MSG "successful inherit of %.480s's ACL for %.480s by "
63056+#define GR_RENAME_ACL_MSG "%s rename of %.480s to %.480s by "
63057+#define GR_UNSAFESHARE_EXEC_ACL_MSG "denied exec with cloned fs of %.950s by "
63058+#define GR_PTRACE_EXEC_ACL_MSG "denied ptrace of %.950s by "
63059+#define GR_EXEC_ACL_MSG "%s execution of %.950s by "
63060+#define GR_EXEC_TPE_MSG "denied untrusted exec (due to %.70s) of %.950s by "
63061+#define GR_SEGVSTART_ACL_MSG "possible exploit bruteforcing on " DEFAULTSECMSG " banning uid %u from login for %lu seconds"
63062+#define GR_SEGVNOSUID_ACL_MSG "possible exploit bruteforcing on " DEFAULTSECMSG " banning execution for %lu seconds"
63063+#define GR_MOUNT_CHROOT_MSG "denied mount of %.256s as %.930s from chroot by "
63064+#define GR_PIVOT_CHROOT_MSG "denied pivot_root from chroot by "
63065+#define GR_TRUNCATE_ACL_MSG "%s truncate of %.950s by "
63066+#define GR_ATIME_ACL_MSG "%s access time change of %.950s by "
63067+#define GR_ACCESS_ACL_MSG "%s access of %.950s for%s%s%s by "
63068+#define GR_CHROOT_CHROOT_MSG "denied double chroot to %.950s by "
63069+#define GR_CHMOD_CHROOT_MSG "denied chmod +s of %.950s by "
63070+#define GR_CHMOD_ACL_MSG "%s chmod of %.950s by "
63071+#define GR_CHROOT_FCHDIR_MSG "denied fchdir outside of chroot to %.950s by "
63072+#define GR_CHOWN_ACL_MSG "%s chown of %.950s by "
63073+#define GR_SETXATTR_ACL_MSG "%s setting extended attributes of %.950s by "
63074+#define GR_WRITLIB_ACL_MSG "denied load of writable library %.950s by "
63075+#define GR_INITF_ACL_MSG "init_variables() failed %s by "
63076+#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"
63077+#define GR_DEV_ACL_MSG "/dev/grsec: %d bytes sent %d required, being fed garbage by "
63078+#define GR_SHUTS_ACL_MSG "shutdown auth success for "
63079+#define GR_SHUTF_ACL_MSG "shutdown auth failure for "
63080+#define GR_SHUTI_ACL_MSG "ignoring shutdown for disabled RBAC system for "
63081+#define GR_SEGVMODS_ACL_MSG "segvmod auth success for "
63082+#define GR_SEGVMODF_ACL_MSG "segvmod auth failure for "
63083+#define GR_SEGVMODI_ACL_MSG "ignoring segvmod for disabled RBAC system for "
63084+#define GR_ENABLE_ACL_MSG "%s RBAC system loaded by "
63085+#define GR_ENABLEF_ACL_MSG "unable to load %s for "
63086+#define GR_RELOADI_ACL_MSG "ignoring reload request for disabled RBAC system"
63087+#define GR_RELOAD_ACL_MSG "%s RBAC system reloaded by "
63088+#define GR_RELOADF_ACL_MSG "failed reload of %s for "
63089+#define GR_SPROLEI_ACL_MSG "ignoring change to special role for disabled RBAC system for "
63090+#define GR_SPROLES_ACL_MSG "successful change to special role %s (id %d) by "
63091+#define GR_SPROLEL_ACL_MSG "special role %s (id %d) exited by "
63092+#define GR_SPROLEF_ACL_MSG "special role %s failure for "
63093+#define GR_UNSPROLEI_ACL_MSG "ignoring unauth of special role for disabled RBAC system for "
63094+#define GR_UNSPROLES_ACL_MSG "successful unauth of special role %s (id %d) by "
63095+#define GR_INVMODE_ACL_MSG "invalid mode %d by "
63096+#define GR_PRIORITY_CHROOT_MSG "denied priority change of process (%.16s:%d) by "
63097+#define GR_FAILFORK_MSG "failed fork with errno %s by "
63098+#define GR_NICE_CHROOT_MSG "denied priority change by "
63099+#define GR_UNISIGLOG_MSG "%.32s occurred at %p in "
63100+#define GR_DUALSIGLOG_MSG "signal %d sent to " DEFAULTSECMSG " by "
63101+#define GR_SIG_ACL_MSG "denied send of signal %d to protected task " DEFAULTSECMSG " by "
63102+#define GR_SYSCTL_MSG "denied modification of grsecurity sysctl value : %.32s by "
63103+#define GR_SYSCTL_ACL_MSG "%s sysctl of %.950s for%s%s by "
63104+#define GR_TIME_MSG "time set by "
63105+#define GR_DEFACL_MSG "fatal: unable to find subject for (%.16s:%d), loaded by "
63106+#define GR_MMAP_ACL_MSG "%s executable mmap of %.950s by "
63107+#define GR_MPROTECT_ACL_MSG "%s executable mprotect of %.950s by "
63108+#define GR_SOCK_MSG "denied socket(%.16s,%.16s,%.16s) by "
63109+#define GR_SOCK_NOINET_MSG "denied socket(%.16s,%.16s,%d) by "
63110+#define GR_BIND_MSG "denied bind() by "
63111+#define GR_CONNECT_MSG "denied connect() by "
63112+#define GR_BIND_ACL_MSG "denied bind() to %pI4 port %u sock type %.16s protocol %.16s by "
63113+#define GR_CONNECT_ACL_MSG "denied connect() to %pI4 port %u sock type %.16s protocol %.16s by "
63114+#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"
63115+#define GR_EXEC_CHROOT_MSG "exec of %.980s within chroot by process "
63116+#define GR_CAP_ACL_MSG "use of %s denied for "
63117+#define GR_CAP_CHROOT_MSG "use of %s in chroot denied for "
63118+#define GR_CAP_ACL_MSG2 "use of %s permitted for "
63119+#define GR_USRCHANGE_ACL_MSG "change to uid %u denied for "
63120+#define GR_GRPCHANGE_ACL_MSG "change to gid %u denied for "
63121+#define GR_REMOUNT_AUDIT_MSG "remount of %.256s by "
63122+#define GR_UNMOUNT_AUDIT_MSG "unmount of %.256s by "
63123+#define GR_MOUNT_AUDIT_MSG "mount of %.256s to %.256s by "
63124+#define GR_CHDIR_AUDIT_MSG "chdir to %.980s by "
63125+#define GR_EXEC_AUDIT_MSG "exec of %.930s (%.128s) by "
63126+#define GR_RESOURCE_MSG "denied resource overstep by requesting %lu for %.16s against limit %lu for "
63127+#define GR_RWXMMAP_MSG "denied RWX mmap of %.950s by "
63128+#define GR_RWXMPROTECT_MSG "denied RWX mprotect of %.950s by "
63129+#define GR_TEXTREL_AUDIT_MSG "text relocation in %s, VMA:0x%08lx 0x%08lx by "
63130+#define GR_VM86_MSG "denied use of vm86 by "
63131+#define GR_PTRACE_AUDIT_MSG "process %.950s(%.16s:%d) attached to via ptrace by "
63132+#define GR_PTRACE_READEXEC_MSG "denied ptrace of unreadable binary %.950s by "
63133+#define GR_INIT_TRANSFER_MSG "persistent special role transferred privilege to init by "
63134+#define GR_BADPROCPID_MSG "denied read of sensitive /proc/pid/%s entry via fd passed across exec by "
63135+#define GR_SYMLINKOWNER_MSG "denied following symlink %.950s since symlink owner %u does not match target owner %u, by "
63136diff --git a/include/linux/grsecurity.h b/include/linux/grsecurity.h
63137new file mode 100644
63138index 0000000..187b3ed
63139--- /dev/null
63140+++ b/include/linux/grsecurity.h
63141@@ -0,0 +1,239 @@
63142+#ifndef GR_SECURITY_H
63143+#define GR_SECURITY_H
63144+#include <linux/fs.h>
63145+#include <linux/fs_struct.h>
63146+#include <linux/binfmts.h>
63147+#include <linux/gracl.h>
63148+
63149+/* notify of brain-dead configs */
63150+#if defined(CONFIG_GRKERNSEC_PROC_USER) && defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
63151+#error "CONFIG_GRKERNSEC_PROC_USER and CONFIG_GRKERNSEC_PROC_USERGROUP cannot both be enabled."
63152+#endif
63153+#if defined(CONFIG_PAX_NOEXEC) && !defined(CONFIG_PAX_PAGEEXEC) && !defined(CONFIG_PAX_SEGMEXEC) && !defined(CONFIG_PAX_KERNEXEC)
63154+#error "CONFIG_PAX_NOEXEC enabled, but PAGEEXEC, SEGMEXEC, and KERNEXEC are disabled."
63155+#endif
63156+#if defined(CONFIG_PAX_ASLR) && !defined(CONFIG_PAX_RANDKSTACK) && !defined(CONFIG_PAX_RANDUSTACK) && !defined(CONFIG_PAX_RANDMMAP)
63157+#error "CONFIG_PAX_ASLR enabled, but RANDKSTACK, RANDUSTACK, and RANDMMAP are disabled."
63158+#endif
63159+#if defined(CONFIG_PAX) && !defined(CONFIG_PAX_NOEXEC) && !defined(CONFIG_PAX_ASLR)
63160+#error "CONFIG_PAX enabled, but no PaX options are enabled."
63161+#endif
63162+
63163+#include <linux/compat.h>
63164+
63165+struct user_arg_ptr {
63166+#ifdef CONFIG_COMPAT
63167+ bool is_compat;
63168+#endif
63169+ union {
63170+ const char __user *const __user *native;
63171+#ifdef CONFIG_COMPAT
63172+ compat_uptr_t __user *compat;
63173+#endif
63174+ } ptr;
63175+};
63176+
63177+void gr_handle_brute_attach(struct task_struct *p, unsigned long mm_flags);
63178+void gr_handle_brute_check(void);
63179+void gr_handle_kernel_exploit(void);
63180+int gr_process_user_ban(void);
63181+
63182+char gr_roletype_to_char(void);
63183+
63184+int gr_acl_enable_at_secure(void);
63185+
63186+int gr_check_user_change(int real, int effective, int fs);
63187+int gr_check_group_change(int real, int effective, int fs);
63188+
63189+void gr_del_task_from_ip_table(struct task_struct *p);
63190+
63191+int gr_pid_is_chrooted(struct task_struct *p);
63192+int gr_handle_chroot_fowner(struct pid *pid, enum pid_type type);
63193+int gr_handle_chroot_nice(void);
63194+int gr_handle_chroot_sysctl(const int op);
63195+int gr_handle_chroot_setpriority(struct task_struct *p,
63196+ const int niceval);
63197+int gr_chroot_fchdir(struct dentry *u_dentry, struct vfsmount *u_mnt);
63198+int gr_handle_chroot_chroot(const struct dentry *dentry,
63199+ const struct vfsmount *mnt);
63200+void gr_handle_chroot_chdir(struct path *path);
63201+int gr_handle_chroot_chmod(const struct dentry *dentry,
63202+ const struct vfsmount *mnt, const int mode);
63203+int gr_handle_chroot_mknod(const struct dentry *dentry,
63204+ const struct vfsmount *mnt, const int mode);
63205+int gr_handle_chroot_mount(const struct dentry *dentry,
63206+ const struct vfsmount *mnt,
63207+ const char *dev_name);
63208+int gr_handle_chroot_pivot(void);
63209+int gr_handle_chroot_unix(const pid_t pid);
63210+
63211+int gr_handle_rawio(const struct inode *inode);
63212+
63213+void gr_handle_ioperm(void);
63214+void gr_handle_iopl(void);
63215+
63216+umode_t gr_acl_umask(void);
63217+
63218+int gr_tpe_allow(const struct file *file);
63219+
63220+void gr_set_chroot_entries(struct task_struct *task, struct path *path);
63221+void gr_clear_chroot_entries(struct task_struct *task);
63222+
63223+void gr_log_forkfail(const int retval);
63224+void gr_log_timechange(void);
63225+void gr_log_signal(const int sig, const void *addr, const struct task_struct *t);
63226+void gr_log_chdir(const struct dentry *dentry,
63227+ const struct vfsmount *mnt);
63228+void gr_log_chroot_exec(const struct dentry *dentry,
63229+ const struct vfsmount *mnt);
63230+void gr_handle_exec_args(struct linux_binprm *bprm, struct user_arg_ptr argv);
63231+void gr_log_remount(const char *devname, const int retval);
63232+void gr_log_unmount(const char *devname, const int retval);
63233+void gr_log_mount(const char *from, const char *to, const int retval);
63234+void gr_log_textrel(struct vm_area_struct *vma);
63235+void gr_log_rwxmmap(struct file *file);
63236+void gr_log_rwxmprotect(struct file *file);
63237+
63238+int gr_handle_follow_link(const struct inode *parent,
63239+ const struct inode *inode,
63240+ const struct dentry *dentry,
63241+ const struct vfsmount *mnt);
63242+int gr_handle_fifo(const struct dentry *dentry,
63243+ const struct vfsmount *mnt,
63244+ const struct dentry *dir, const int flag,
63245+ const int acc_mode);
63246+int gr_handle_hardlink(const struct dentry *dentry,
63247+ const struct vfsmount *mnt,
63248+ struct inode *inode,
63249+ const int mode, const char *to);
63250+
63251+int gr_is_capable(const int cap);
63252+int gr_is_capable_nolog(const int cap);
63253+int gr_task_is_capable(const struct task_struct *task, const struct cred *cred, const int cap);
63254+int gr_task_is_capable_nolog(const struct task_struct *task, const int cap);
63255+
63256+void gr_learn_resource(const struct task_struct *task, const int limit,
63257+ const unsigned long wanted, const int gt);
63258+void gr_copy_label(struct task_struct *tsk);
63259+void gr_handle_crash(struct task_struct *task, const int sig);
63260+int gr_handle_signal(const struct task_struct *p, const int sig);
63261+int gr_check_crash_uid(const uid_t uid);
63262+int gr_check_protected_task(const struct task_struct *task);
63263+int gr_check_protected_task_fowner(struct pid *pid, enum pid_type type);
63264+int gr_acl_handle_mmap(const struct file *file,
63265+ const unsigned long prot);
63266+int gr_acl_handle_mprotect(const struct file *file,
63267+ const unsigned long prot);
63268+int gr_check_hidden_task(const struct task_struct *tsk);
63269+__u32 gr_acl_handle_truncate(const struct dentry *dentry,
63270+ const struct vfsmount *mnt);
63271+__u32 gr_acl_handle_utime(const struct dentry *dentry,
63272+ const struct vfsmount *mnt);
63273+__u32 gr_acl_handle_access(const struct dentry *dentry,
63274+ const struct vfsmount *mnt, const int fmode);
63275+__u32 gr_acl_handle_chmod(const struct dentry *dentry,
63276+ const struct vfsmount *mnt, umode_t *mode);
63277+__u32 gr_acl_handle_chown(const struct dentry *dentry,
63278+ const struct vfsmount *mnt);
63279+__u32 gr_acl_handle_setxattr(const struct dentry *dentry,
63280+ const struct vfsmount *mnt);
63281+int gr_handle_ptrace(struct task_struct *task, const long request);
63282+int gr_handle_proc_ptrace(struct task_struct *task);
63283+__u32 gr_acl_handle_execve(const struct dentry *dentry,
63284+ const struct vfsmount *mnt);
63285+int gr_check_crash_exec(const struct file *filp);
63286+int gr_acl_is_enabled(void);
63287+void gr_set_kernel_label(struct task_struct *task);
63288+void gr_set_role_label(struct task_struct *task, const uid_t uid,
63289+ const gid_t gid);
63290+int gr_set_proc_label(const struct dentry *dentry,
63291+ const struct vfsmount *mnt,
63292+ const int unsafe_flags);
63293+__u32 gr_acl_handle_hidden_file(const struct dentry *dentry,
63294+ const struct vfsmount *mnt);
63295+__u32 gr_acl_handle_open(const struct dentry *dentry,
63296+ const struct vfsmount *mnt, int acc_mode);
63297+__u32 gr_acl_handle_creat(const struct dentry *dentry,
63298+ const struct dentry *p_dentry,
63299+ const struct vfsmount *p_mnt,
63300+ int open_flags, int acc_mode, const int imode);
63301+void gr_handle_create(const struct dentry *dentry,
63302+ const struct vfsmount *mnt);
63303+void gr_handle_proc_create(const struct dentry *dentry,
63304+ const struct inode *inode);
63305+__u32 gr_acl_handle_mknod(const struct dentry *new_dentry,
63306+ const struct dentry *parent_dentry,
63307+ const struct vfsmount *parent_mnt,
63308+ const int mode);
63309+__u32 gr_acl_handle_mkdir(const struct dentry *new_dentry,
63310+ const struct dentry *parent_dentry,
63311+ const struct vfsmount *parent_mnt);
63312+__u32 gr_acl_handle_rmdir(const struct dentry *dentry,
63313+ const struct vfsmount *mnt);
63314+void gr_handle_delete(const ino_t ino, const dev_t dev);
63315+__u32 gr_acl_handle_unlink(const struct dentry *dentry,
63316+ const struct vfsmount *mnt);
63317+__u32 gr_acl_handle_symlink(const struct dentry *new_dentry,
63318+ const struct dentry *parent_dentry,
63319+ const struct vfsmount *parent_mnt,
63320+ const char *from);
63321+__u32 gr_acl_handle_link(const struct dentry *new_dentry,
63322+ const struct dentry *parent_dentry,
63323+ const struct vfsmount *parent_mnt,
63324+ const struct dentry *old_dentry,
63325+ const struct vfsmount *old_mnt, const char *to);
63326+int gr_handle_symlink_owner(const struct path *link, const struct inode *target);
63327+int gr_acl_handle_rename(struct dentry *new_dentry,
63328+ struct dentry *parent_dentry,
63329+ const struct vfsmount *parent_mnt,
63330+ struct dentry *old_dentry,
63331+ struct inode *old_parent_inode,
63332+ struct vfsmount *old_mnt, const char *newname);
63333+void gr_handle_rename(struct inode *old_dir, struct inode *new_dir,
63334+ struct dentry *old_dentry,
63335+ struct dentry *new_dentry,
63336+ struct vfsmount *mnt, const __u8 replace);
63337+__u32 gr_check_link(const struct dentry *new_dentry,
63338+ const struct dentry *parent_dentry,
63339+ const struct vfsmount *parent_mnt,
63340+ const struct dentry *old_dentry,
63341+ const struct vfsmount *old_mnt);
63342+int gr_acl_handle_filldir(const struct file *file, const char *name,
63343+ const unsigned int namelen, const ino_t ino);
63344+
63345+__u32 gr_acl_handle_unix(const struct dentry *dentry,
63346+ const struct vfsmount *mnt);
63347+void gr_acl_handle_exit(void);
63348+void gr_acl_handle_psacct(struct task_struct *task, const long code);
63349+int gr_acl_handle_procpidmem(const struct task_struct *task);
63350+int gr_handle_rofs_mount(struct dentry *dentry, struct vfsmount *mnt, int mnt_flags);
63351+int gr_handle_rofs_blockwrite(struct dentry *dentry, struct vfsmount *mnt, int acc_mode);
63352+void gr_audit_ptrace(struct task_struct *task);
63353+dev_t gr_get_dev_from_dentry(struct dentry *dentry);
63354+void gr_put_exec_file(struct task_struct *task);
63355+
63356+int gr_ptrace_readexec(struct file *file, int unsafe_flags);
63357+
63358+#ifdef CONFIG_GRKERNSEC
63359+void task_grsec_rbac(struct seq_file *m, struct task_struct *p);
63360+void gr_handle_vm86(void);
63361+void gr_handle_mem_readwrite(u64 from, u64 to);
63362+
63363+void gr_log_badprocpid(const char *entry);
63364+
63365+extern int grsec_enable_dmesg;
63366+extern int grsec_disable_privio;
63367+
63368+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
63369+extern int grsec_proc_gid;
63370+#endif
63371+
63372+#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
63373+extern int grsec_enable_chroot_findtask;
63374+#endif
63375+#ifdef CONFIG_GRKERNSEC_SETXID
63376+extern int grsec_enable_setxid;
63377+#endif
63378+#endif
63379+
63380+#endif
63381diff --git a/include/linux/grsock.h b/include/linux/grsock.h
63382new file mode 100644
63383index 0000000..e7ffaaf
63384--- /dev/null
63385+++ b/include/linux/grsock.h
63386@@ -0,0 +1,19 @@
63387+#ifndef __GRSOCK_H
63388+#define __GRSOCK_H
63389+
63390+extern void gr_attach_curr_ip(const struct sock *sk);
63391+extern int gr_handle_sock_all(const int family, const int type,
63392+ const int protocol);
63393+extern int gr_handle_sock_server(const struct sockaddr *sck);
63394+extern int gr_handle_sock_server_other(const struct sock *sck);
63395+extern int gr_handle_sock_client(const struct sockaddr *sck);
63396+extern int gr_search_connect(struct socket * sock,
63397+ struct sockaddr_in * addr);
63398+extern int gr_search_bind(struct socket * sock,
63399+ struct sockaddr_in * addr);
63400+extern int gr_search_listen(struct socket * sock);
63401+extern int gr_search_accept(struct socket * sock);
63402+extern int gr_search_socket(const int domain, const int type,
63403+ const int protocol);
63404+
63405+#endif
63406diff --git a/include/linux/hid.h b/include/linux/hid.h
63407index 42970de..5db3c92 100644
63408--- a/include/linux/hid.h
63409+++ b/include/linux/hid.h
63410@@ -705,7 +705,7 @@ struct hid_ll_driver {
63411 unsigned int code, int value);
63412
63413 int (*parse)(struct hid_device *hdev);
63414-};
63415+} __no_const;
63416
63417 #define PM_HINT_FULLON 1<<5
63418 #define PM_HINT_NORMAL 1<<1
63419diff --git a/include/linux/highmem.h b/include/linux/highmem.h
63420index ef788b5..ac41b7b 100644
63421--- a/include/linux/highmem.h
63422+++ b/include/linux/highmem.h
63423@@ -189,6 +189,18 @@ static inline void clear_highpage(struct page *page)
63424 kunmap_atomic(kaddr);
63425 }
63426
63427+static inline void sanitize_highpage(struct page *page)
63428+{
63429+ void *kaddr;
63430+ unsigned long flags;
63431+
63432+ local_irq_save(flags);
63433+ kaddr = kmap_atomic(page);
63434+ clear_page(kaddr);
63435+ kunmap_atomic(kaddr);
63436+ local_irq_restore(flags);
63437+}
63438+
63439 static inline void zero_user_segments(struct page *page,
63440 unsigned start1, unsigned end1,
63441 unsigned start2, unsigned end2)
63442diff --git a/include/linux/i2c.h b/include/linux/i2c.h
63443index 5970266..1c48c3b 100644
63444--- a/include/linux/i2c.h
63445+++ b/include/linux/i2c.h
63446@@ -369,6 +369,7 @@ struct i2c_algorithm {
63447 /* To determine what the adapter supports */
63448 u32 (*functionality) (struct i2c_adapter *);
63449 };
63450+typedef struct i2c_algorithm __no_const i2c_algorithm_no_const;
63451
63452 /*
63453 * i2c_adapter is the structure used to identify a physical i2c bus along
63454diff --git a/include/linux/i2o.h b/include/linux/i2o.h
63455index d23c3c2..eb63c81 100644
63456--- a/include/linux/i2o.h
63457+++ b/include/linux/i2o.h
63458@@ -565,7 +565,7 @@ struct i2o_controller {
63459 struct i2o_device *exec; /* Executive */
63460 #if BITS_PER_LONG == 64
63461 spinlock_t context_list_lock; /* lock for context_list */
63462- atomic_t context_list_counter; /* needed for unique contexts */
63463+ atomic_unchecked_t context_list_counter; /* needed for unique contexts */
63464 struct list_head context_list; /* list of context id's
63465 and pointers */
63466 #endif
63467diff --git a/include/linux/if_team.h b/include/linux/if_team.h
63468index aa2e167..84024ce 100644
63469--- a/include/linux/if_team.h
63470+++ b/include/linux/if_team.h
63471@@ -109,6 +109,7 @@ struct team_mode_ops {
63472 void (*port_enabled)(struct team *team, struct team_port *port);
63473 void (*port_disabled)(struct team *team, struct team_port *port);
63474 };
63475+typedef struct team_mode_ops __no_const team_mode_ops_no_const;
63476
63477 enum team_option_type {
63478 TEAM_OPTION_TYPE_U32,
63479@@ -181,7 +182,7 @@ struct team {
63480 struct list_head option_inst_list; /* list of option instances */
63481
63482 const struct team_mode *mode;
63483- struct team_mode_ops ops;
63484+ team_mode_ops_no_const ops;
63485 long mode_priv[TEAM_MODE_PRIV_LONGS];
63486 };
63487
63488diff --git a/include/linux/init.h b/include/linux/init.h
63489index 5e664f6..0a1225c 100644
63490--- a/include/linux/init.h
63491+++ b/include/linux/init.h
63492@@ -39,9 +39,15 @@
63493 * Also note, that this data cannot be "const".
63494 */
63495
63496+#ifdef MODULE
63497+#define add_latent_entropy
63498+#else
63499+#define add_latent_entropy __latent_entropy
63500+#endif
63501+
63502 /* These are for everybody (although not all archs will actually
63503 discard it in modules) */
63504-#define __init __section(.init.text) __cold notrace
63505+#define __init __section(.init.text) __cold notrace add_latent_entropy
63506 #define __initdata __section(.init.data)
63507 #define __initconst __section(.init.rodata)
63508 #define __exitdata __section(.exit.data)
63509@@ -83,7 +89,7 @@
63510 #define __exit __section(.exit.text) __exitused __cold notrace
63511
63512 /* Used for HOTPLUG */
63513-#define __devinit __section(.devinit.text) __cold notrace
63514+#define __devinit __section(.devinit.text) __cold notrace add_latent_entropy
63515 #define __devinitdata __section(.devinit.data)
63516 #define __devinitconst __section(.devinit.rodata)
63517 #define __devexit __section(.devexit.text) __exitused __cold notrace
63518@@ -91,7 +97,7 @@
63519 #define __devexitconst __section(.devexit.rodata)
63520
63521 /* Used for HOTPLUG_CPU */
63522-#define __cpuinit __section(.cpuinit.text) __cold notrace
63523+#define __cpuinit __section(.cpuinit.text) __cold notrace add_latent_entropy
63524 #define __cpuinitdata __section(.cpuinit.data)
63525 #define __cpuinitconst __section(.cpuinit.rodata)
63526 #define __cpuexit __section(.cpuexit.text) __exitused __cold notrace
63527@@ -99,7 +105,7 @@
63528 #define __cpuexitconst __section(.cpuexit.rodata)
63529
63530 /* Used for MEMORY_HOTPLUG */
63531-#define __meminit __section(.meminit.text) __cold notrace
63532+#define __meminit __section(.meminit.text) __cold notrace add_latent_entropy
63533 #define __meminitdata __section(.meminit.data)
63534 #define __meminitconst __section(.meminit.rodata)
63535 #define __memexit __section(.memexit.text) __exitused __cold notrace
63536diff --git a/include/linux/init_task.h b/include/linux/init_task.h
63537index 89f1cb1..7986c0f 100644
63538--- a/include/linux/init_task.h
63539+++ b/include/linux/init_task.h
63540@@ -143,6 +143,12 @@ extern struct task_group root_task_group;
63541
63542 #define INIT_TASK_COMM "swapper"
63543
63544+#ifdef CONFIG_X86
63545+#define INIT_TASK_THREAD_INFO .tinfo = INIT_THREAD_INFO,
63546+#else
63547+#define INIT_TASK_THREAD_INFO
63548+#endif
63549+
63550 /*
63551 * INIT_TASK is used to set up the first task table, touch at
63552 * your own risk!. Base=0, limit=0x1fffff (=2MB)
63553@@ -182,6 +188,7 @@ extern struct task_group root_task_group;
63554 RCU_POINTER_INITIALIZER(cred, &init_cred), \
63555 .comm = INIT_TASK_COMM, \
63556 .thread = INIT_THREAD, \
63557+ INIT_TASK_THREAD_INFO \
63558 .fs = &init_fs, \
63559 .files = &init_files, \
63560 .signal = &init_signals, \
63561diff --git a/include/linux/intel-iommu.h b/include/linux/intel-iommu.h
63562index 78e2ada..745564d 100644
63563--- a/include/linux/intel-iommu.h
63564+++ b/include/linux/intel-iommu.h
63565@@ -296,7 +296,7 @@ struct iommu_flush {
63566 u8 fm, u64 type);
63567 void (*flush_iotlb)(struct intel_iommu *iommu, u16 did, u64 addr,
63568 unsigned int size_order, u64 type);
63569-};
63570+} __no_const;
63571
63572 enum {
63573 SR_DMAR_FECTL_REG,
63574diff --git a/include/linux/interrupt.h b/include/linux/interrupt.h
63575index c5f856a..d29c117 100644
63576--- a/include/linux/interrupt.h
63577+++ b/include/linux/interrupt.h
63578@@ -433,7 +433,7 @@ enum
63579 /* map softirq index to softirq name. update 'softirq_to_name' in
63580 * kernel/softirq.c when adding a new softirq.
63581 */
63582-extern char *softirq_to_name[NR_SOFTIRQS];
63583+extern const char * const softirq_to_name[NR_SOFTIRQS];
63584
63585 /* softirq mask and active fields moved to irq_cpustat_t in
63586 * asm/hardirq.h to get better cache usage. KAO
63587@@ -441,12 +441,12 @@ extern char *softirq_to_name[NR_SOFTIRQS];
63588
63589 struct softirq_action
63590 {
63591- void (*action)(struct softirq_action *);
63592+ void (*action)(void);
63593 };
63594
63595 asmlinkage void do_softirq(void);
63596 asmlinkage void __do_softirq(void);
63597-extern void open_softirq(int nr, void (*action)(struct softirq_action *));
63598+extern void open_softirq(int nr, void (*action)(void));
63599 extern void softirq_init(void);
63600 extern void __raise_softirq_irqoff(unsigned int nr);
63601
63602diff --git a/include/linux/kallsyms.h b/include/linux/kallsyms.h
63603index 6883e19..06992b1 100644
63604--- a/include/linux/kallsyms.h
63605+++ b/include/linux/kallsyms.h
63606@@ -15,7 +15,8 @@
63607
63608 struct module;
63609
63610-#ifdef CONFIG_KALLSYMS
63611+#if !defined(__INCLUDED_BY_HIDESYM) || !defined(CONFIG_KALLSYMS)
63612+#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
63613 /* Lookup the address for a symbol. Returns 0 if not found. */
63614 unsigned long kallsyms_lookup_name(const char *name);
63615
63616@@ -106,6 +107,17 @@ static inline int lookup_symbol_attrs(unsigned long addr, unsigned long *size, u
63617 /* Stupid that this does nothing, but I didn't create this mess. */
63618 #define __print_symbol(fmt, addr)
63619 #endif /*CONFIG_KALLSYMS*/
63620+#else /* when included by kallsyms.c, vsnprintf.c, or
63621+ arch/x86/kernel/dumpstack.c, with HIDESYM enabled */
63622+extern void __print_symbol(const char *fmt, unsigned long address);
63623+extern int sprint_backtrace(char *buffer, unsigned long address);
63624+extern int sprint_symbol(char *buffer, unsigned long address);
63625+extern int sprint_symbol_no_offset(char *buffer, unsigned long address);
63626+const char *kallsyms_lookup(unsigned long addr,
63627+ unsigned long *symbolsize,
63628+ unsigned long *offset,
63629+ char **modname, char *namebuf);
63630+#endif
63631
63632 /* This macro allows us to keep printk typechecking */
63633 static __printf(1, 2)
63634diff --git a/include/linux/kgdb.h b/include/linux/kgdb.h
63635index c4d2fc1..5df9c19 100644
63636--- a/include/linux/kgdb.h
63637+++ b/include/linux/kgdb.h
63638@@ -53,7 +53,7 @@ extern int kgdb_connected;
63639 extern int kgdb_io_module_registered;
63640
63641 extern atomic_t kgdb_setting_breakpoint;
63642-extern atomic_t kgdb_cpu_doing_single_step;
63643+extern atomic_unchecked_t kgdb_cpu_doing_single_step;
63644
63645 extern struct task_struct *kgdb_usethread;
63646 extern struct task_struct *kgdb_contthread;
63647@@ -252,7 +252,7 @@ struct kgdb_arch {
63648 void (*disable_hw_break)(struct pt_regs *regs);
63649 void (*remove_all_hw_break)(void);
63650 void (*correct_hw_break)(void);
63651-};
63652+} __do_const;
63653
63654 /**
63655 * struct kgdb_io - Describe the interface for an I/O driver to talk with KGDB.
63656@@ -277,7 +277,7 @@ struct kgdb_io {
63657 void (*pre_exception) (void);
63658 void (*post_exception) (void);
63659 int is_console;
63660-};
63661+} __do_const;
63662
63663 extern struct kgdb_arch arch_kgdb_ops;
63664
63665diff --git a/include/linux/kmod.h b/include/linux/kmod.h
63666index 5398d58..5883a34 100644
63667--- a/include/linux/kmod.h
63668+++ b/include/linux/kmod.h
63669@@ -34,6 +34,8 @@ extern char modprobe_path[]; /* for sysctl */
63670 * usually useless though. */
63671 extern __printf(2, 3)
63672 int __request_module(bool wait, const char *name, ...);
63673+extern __printf(3, 4)
63674+int ___request_module(bool wait, char *param_name, const char *name, ...);
63675 #define request_module(mod...) __request_module(true, mod)
63676 #define request_module_nowait(mod...) __request_module(false, mod)
63677 #define try_then_request_module(x, mod...) \
63678diff --git a/include/linux/kref.h b/include/linux/kref.h
63679index 65af688..0592677 100644
63680--- a/include/linux/kref.h
63681+++ b/include/linux/kref.h
63682@@ -64,7 +64,7 @@ static inline void kref_get(struct kref *kref)
63683 static inline int kref_sub(struct kref *kref, unsigned int count,
63684 void (*release)(struct kref *kref))
63685 {
63686- WARN_ON(release == NULL);
63687+ BUG_ON(release == NULL);
63688
63689 if (atomic_sub_and_test((int) count, &kref->refcount)) {
63690 release(kref);
63691diff --git a/include/linux/kvm_host.h b/include/linux/kvm_host.h
63692index b70b48b..0d7153b 100644
63693--- a/include/linux/kvm_host.h
63694+++ b/include/linux/kvm_host.h
63695@@ -351,7 +351,7 @@ void kvm_vcpu_uninit(struct kvm_vcpu *vcpu);
63696 void vcpu_load(struct kvm_vcpu *vcpu);
63697 void vcpu_put(struct kvm_vcpu *vcpu);
63698
63699-int kvm_init(void *opaque, unsigned vcpu_size, unsigned vcpu_align,
63700+int kvm_init(const void *opaque, unsigned vcpu_size, unsigned vcpu_align,
63701 struct module *module);
63702 void kvm_exit(void);
63703
63704@@ -517,7 +517,7 @@ int kvm_arch_vcpu_ioctl_set_guest_debug(struct kvm_vcpu *vcpu,
63705 struct kvm_guest_debug *dbg);
63706 int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu, struct kvm_run *kvm_run);
63707
63708-int kvm_arch_init(void *opaque);
63709+int kvm_arch_init(const void *opaque);
63710 void kvm_arch_exit(void);
63711
63712 int kvm_arch_vcpu_init(struct kvm_vcpu *vcpu);
63713diff --git a/include/linux/libata.h b/include/linux/libata.h
63714index 64f90e1..32b945b 100644
63715--- a/include/linux/libata.h
63716+++ b/include/linux/libata.h
63717@@ -909,7 +909,7 @@ struct ata_port_operations {
63718 * fields must be pointers.
63719 */
63720 const struct ata_port_operations *inherits;
63721-};
63722+} __do_const;
63723
63724 struct ata_port_info {
63725 unsigned long flags;
63726diff --git a/include/linux/memory.h b/include/linux/memory.h
63727index ff9a9f8..c715deb 100644
63728--- a/include/linux/memory.h
63729+++ b/include/linux/memory.h
63730@@ -143,7 +143,7 @@ struct memory_accessor {
63731 size_t count);
63732 ssize_t (*write)(struct memory_accessor *, const char *buf,
63733 off_t offset, size_t count);
63734-};
63735+} __no_const;
63736
63737 /*
63738 * Kernel text modification mutex, used for code patching. Users of this lock
63739diff --git a/include/linux/mfd/abx500.h b/include/linux/mfd/abx500.h
63740index 1318ca6..7521340 100644
63741--- a/include/linux/mfd/abx500.h
63742+++ b/include/linux/mfd/abx500.h
63743@@ -452,6 +452,7 @@ struct abx500_ops {
63744 int (*event_registers_startup_state_get) (struct device *, u8 *);
63745 int (*startup_irq_enabled) (struct device *, unsigned int);
63746 };
63747+typedef struct abx500_ops __no_const abx500_ops_no_const;
63748
63749 int abx500_register_ops(struct device *core_dev, struct abx500_ops *ops);
63750 void abx500_remove_ops(struct device *dev);
63751diff --git a/include/linux/mfd/abx500/ux500_chargalg.h b/include/linux/mfd/abx500/ux500_chargalg.h
63752index 9b07725..3d55001 100644
63753--- a/include/linux/mfd/abx500/ux500_chargalg.h
63754+++ b/include/linux/mfd/abx500/ux500_chargalg.h
63755@@ -19,7 +19,7 @@ struct ux500_charger_ops {
63756 int (*enable) (struct ux500_charger *, int, int, int);
63757 int (*kick_wd) (struct ux500_charger *);
63758 int (*update_curr) (struct ux500_charger *, int);
63759-};
63760+} __no_const;
63761
63762 /**
63763 * struct ux500_charger - power supply ux500 charger sub class
63764diff --git a/include/linux/mm.h b/include/linux/mm.h
63765index 311be90..5f1638c 100644
63766--- a/include/linux/mm.h
63767+++ b/include/linux/mm.h
63768@@ -116,7 +116,14 @@ extern unsigned int kobjsize(const void *objp);
63769
63770 #define VM_CAN_NONLINEAR 0x08000000 /* Has ->fault & does nonlinear pages */
63771 #define VM_MIXEDMAP 0x10000000 /* Can contain "struct page" and pure PFN pages */
63772+
63773+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
63774+#define VM_SAO 0x00000000 /* Strong Access Ordering (powerpc) */
63775+#define VM_PAGEEXEC 0x20000000 /* vma->vm_page_prot needs special handling */
63776+#else
63777 #define VM_SAO 0x20000000 /* Strong Access Ordering (powerpc) */
63778+#endif
63779+
63780 #define VM_PFN_AT_MMAP 0x40000000 /* PFNMAP vma that is fully mapped at mmap time */
63781 #define VM_MERGEABLE 0x80000000 /* KSM may merge identical pages */
63782
63783@@ -1038,34 +1045,6 @@ int set_page_dirty(struct page *page);
63784 int set_page_dirty_lock(struct page *page);
63785 int clear_page_dirty_for_io(struct page *page);
63786
63787-/* Is the vma a continuation of the stack vma above it? */
63788-static inline int vma_growsdown(struct vm_area_struct *vma, unsigned long addr)
63789-{
63790- return vma && (vma->vm_end == addr) && (vma->vm_flags & VM_GROWSDOWN);
63791-}
63792-
63793-static inline int stack_guard_page_start(struct vm_area_struct *vma,
63794- unsigned long addr)
63795-{
63796- return (vma->vm_flags & VM_GROWSDOWN) &&
63797- (vma->vm_start == addr) &&
63798- !vma_growsdown(vma->vm_prev, addr);
63799-}
63800-
63801-/* Is the vma a continuation of the stack vma below it? */
63802-static inline int vma_growsup(struct vm_area_struct *vma, unsigned long addr)
63803-{
63804- return vma && (vma->vm_start == addr) && (vma->vm_flags & VM_GROWSUP);
63805-}
63806-
63807-static inline int stack_guard_page_end(struct vm_area_struct *vma,
63808- unsigned long addr)
63809-{
63810- return (vma->vm_flags & VM_GROWSUP) &&
63811- (vma->vm_end == addr) &&
63812- !vma_growsup(vma->vm_next, addr);
63813-}
63814-
63815 extern pid_t
63816 vm_is_stack(struct task_struct *task, struct vm_area_struct *vma, int in_group);
63817
63818@@ -1164,6 +1143,15 @@ static inline void sync_mm_rss(struct mm_struct *mm)
63819 }
63820 #endif
63821
63822+#ifdef CONFIG_MMU
63823+pgprot_t vm_get_page_prot(vm_flags_t vm_flags);
63824+#else
63825+static inline pgprot_t vm_get_page_prot(vm_flags_t vm_flags)
63826+{
63827+ return __pgprot(0);
63828+}
63829+#endif
63830+
63831 int vma_wants_writenotify(struct vm_area_struct *vma);
63832
63833 extern pte_t *__get_locked_pte(struct mm_struct *mm, unsigned long addr,
63834@@ -1182,8 +1170,15 @@ static inline int __pud_alloc(struct mm_struct *mm, pgd_t *pgd,
63835 {
63836 return 0;
63837 }
63838+
63839+static inline int __pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd,
63840+ unsigned long address)
63841+{
63842+ return 0;
63843+}
63844 #else
63845 int __pud_alloc(struct mm_struct *mm, pgd_t *pgd, unsigned long address);
63846+int __pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd, unsigned long address);
63847 #endif
63848
63849 #ifdef __PAGETABLE_PMD_FOLDED
63850@@ -1192,8 +1187,15 @@ static inline int __pmd_alloc(struct mm_struct *mm, pud_t *pud,
63851 {
63852 return 0;
63853 }
63854+
63855+static inline int __pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud,
63856+ unsigned long address)
63857+{
63858+ return 0;
63859+}
63860 #else
63861 int __pmd_alloc(struct mm_struct *mm, pud_t *pud, unsigned long address);
63862+int __pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud, unsigned long address);
63863 #endif
63864
63865 int __pte_alloc(struct mm_struct *mm, struct vm_area_struct *vma,
63866@@ -1211,11 +1213,23 @@ static inline pud_t *pud_alloc(struct mm_struct *mm, pgd_t *pgd, unsigned long a
63867 NULL: pud_offset(pgd, address);
63868 }
63869
63870+static inline pud_t *pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd, unsigned long address)
63871+{
63872+ return (unlikely(pgd_none(*pgd)) && __pud_alloc_kernel(mm, pgd, address))?
63873+ NULL: pud_offset(pgd, address);
63874+}
63875+
63876 static inline pmd_t *pmd_alloc(struct mm_struct *mm, pud_t *pud, unsigned long address)
63877 {
63878 return (unlikely(pud_none(*pud)) && __pmd_alloc(mm, pud, address))?
63879 NULL: pmd_offset(pud, address);
63880 }
63881+
63882+static inline pmd_t *pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud, unsigned long address)
63883+{
63884+ return (unlikely(pud_none(*pud)) && __pmd_alloc_kernel(mm, pud, address))?
63885+ NULL: pmd_offset(pud, address);
63886+}
63887 #endif /* CONFIG_MMU && !__ARCH_HAS_4LEVEL_HACK */
63888
63889 #if USE_SPLIT_PTLOCKS
63890@@ -1426,6 +1440,7 @@ extern unsigned long do_mmap_pgoff(struct file *, unsigned long,
63891 unsigned long, unsigned long,
63892 unsigned long, unsigned long);
63893 extern int do_munmap(struct mm_struct *, unsigned long, size_t);
63894+extern int __do_munmap(struct mm_struct *, unsigned long, size_t);
63895
63896 /* These take the mm semaphore themselves */
63897 extern unsigned long vm_brk(unsigned long, unsigned long);
63898@@ -1489,6 +1504,10 @@ extern struct vm_area_struct * find_vma(struct mm_struct * mm, unsigned long add
63899 extern struct vm_area_struct * find_vma_prev(struct mm_struct * mm, unsigned long addr,
63900 struct vm_area_struct **pprev);
63901
63902+extern struct vm_area_struct *pax_find_mirror_vma(struct vm_area_struct *vma);
63903+extern __must_check long pax_mirror_vma(struct vm_area_struct *vma_m, struct vm_area_struct *vma);
63904+extern void pax_mirror_file_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m, spinlock_t *ptl);
63905+
63906 /* Look up the first VMA which intersects the interval start_addr..end_addr-1,
63907 NULL if none. Assume start_addr < end_addr. */
63908 static inline struct vm_area_struct * find_vma_intersection(struct mm_struct * mm, unsigned long start_addr, unsigned long end_addr)
63909@@ -1517,15 +1536,6 @@ static inline struct vm_area_struct *find_exact_vma(struct mm_struct *mm,
63910 return vma;
63911 }
63912
63913-#ifdef CONFIG_MMU
63914-pgprot_t vm_get_page_prot(unsigned long vm_flags);
63915-#else
63916-static inline pgprot_t vm_get_page_prot(unsigned long vm_flags)
63917-{
63918- return __pgprot(0);
63919-}
63920-#endif
63921-
63922 struct vm_area_struct *find_extend_vma(struct mm_struct *, unsigned long addr);
63923 int remap_pfn_range(struct vm_area_struct *, unsigned long addr,
63924 unsigned long pfn, unsigned long size, pgprot_t);
63925@@ -1631,7 +1641,7 @@ extern int unpoison_memory(unsigned long pfn);
63926 extern int sysctl_memory_failure_early_kill;
63927 extern int sysctl_memory_failure_recovery;
63928 extern void shake_page(struct page *p, int access);
63929-extern atomic_long_t mce_bad_pages;
63930+extern atomic_long_unchecked_t mce_bad_pages;
63931 extern int soft_offline_page(struct page *page, int flags);
63932
63933 extern void dump_page(struct page *page);
63934@@ -1662,5 +1672,11 @@ static inline unsigned int debug_guardpage_minorder(void) { return 0; }
63935 static inline bool page_is_guard(struct page *page) { return false; }
63936 #endif /* CONFIG_DEBUG_PAGEALLOC */
63937
63938+#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
63939+extern void track_exec_limit(struct mm_struct *mm, unsigned long start, unsigned long end, unsigned long prot);
63940+#else
63941+static inline void track_exec_limit(struct mm_struct *mm, unsigned long start, unsigned long end, unsigned long prot) {}
63942+#endif
63943+
63944 #endif /* __KERNEL__ */
63945 #endif /* _LINUX_MM_H */
63946diff --git a/include/linux/mm_types.h b/include/linux/mm_types.h
63947index bf78672..debc693 100644
63948--- a/include/linux/mm_types.h
63949+++ b/include/linux/mm_types.h
63950@@ -279,6 +279,8 @@ struct vm_area_struct {
63951 #ifdef CONFIG_NUMA
63952 struct mempolicy *vm_policy; /* NUMA policy for the VMA */
63953 #endif
63954+
63955+ struct vm_area_struct *vm_mirror;/* PaX: mirror vma or NULL */
63956 };
63957
63958 struct core_thread {
63959@@ -353,7 +355,7 @@ struct mm_struct {
63960 unsigned long def_flags;
63961 unsigned long nr_ptes; /* Page table pages */
63962 unsigned long start_code, end_code, start_data, end_data;
63963- unsigned long start_brk, brk, start_stack;
63964+ unsigned long brk_gap, start_brk, brk, start_stack;
63965 unsigned long arg_start, arg_end, env_start, env_end;
63966
63967 unsigned long saved_auxv[AT_VECTOR_SIZE]; /* for /proc/PID/auxv */
63968@@ -405,6 +407,24 @@ struct mm_struct {
63969 struct cpumask cpumask_allocation;
63970 #endif
63971 struct uprobes_state uprobes_state;
63972+
63973+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
63974+ unsigned long pax_flags;
63975+#endif
63976+
63977+#ifdef CONFIG_PAX_DLRESOLVE
63978+ unsigned long call_dl_resolve;
63979+#endif
63980+
63981+#if defined(CONFIG_PPC32) && defined(CONFIG_PAX_EMUSIGRT)
63982+ unsigned long call_syscall;
63983+#endif
63984+
63985+#ifdef CONFIG_PAX_ASLR
63986+ unsigned long delta_mmap; /* randomized offset */
63987+ unsigned long delta_stack; /* randomized offset */
63988+#endif
63989+
63990 };
63991
63992 static inline void mm_init_cpumask(struct mm_struct *mm)
63993diff --git a/include/linux/mmu_notifier.h b/include/linux/mmu_notifier.h
63994index 1d1b1e1..2a13c78 100644
63995--- a/include/linux/mmu_notifier.h
63996+++ b/include/linux/mmu_notifier.h
63997@@ -255,12 +255,12 @@ static inline void mmu_notifier_mm_destroy(struct mm_struct *mm)
63998 */
63999 #define ptep_clear_flush_notify(__vma, __address, __ptep) \
64000 ({ \
64001- pte_t __pte; \
64002+ pte_t ___pte; \
64003 struct vm_area_struct *___vma = __vma; \
64004 unsigned long ___address = __address; \
64005- __pte = ptep_clear_flush(___vma, ___address, __ptep); \
64006+ ___pte = ptep_clear_flush(___vma, ___address, __ptep); \
64007 mmu_notifier_invalidate_page(___vma->vm_mm, ___address); \
64008- __pte; \
64009+ ___pte; \
64010 })
64011
64012 #define pmdp_clear_flush_notify(__vma, __address, __pmdp) \
64013diff --git a/include/linux/mmzone.h b/include/linux/mmzone.h
64014index 2daa54f..bfdf2f5 100644
64015--- a/include/linux/mmzone.h
64016+++ b/include/linux/mmzone.h
64017@@ -414,7 +414,7 @@ struct zone {
64018 unsigned long flags; /* zone flags, see below */
64019
64020 /* Zone statistics */
64021- atomic_long_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
64022+ atomic_long_unchecked_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
64023
64024 /*
64025 * The target ratio of ACTIVE_ANON to INACTIVE_ANON pages on
64026diff --git a/include/linux/mod_devicetable.h b/include/linux/mod_devicetable.h
64027index 6955045..ebdb7cd 100644
64028--- a/include/linux/mod_devicetable.h
64029+++ b/include/linux/mod_devicetable.h
64030@@ -12,7 +12,7 @@
64031 typedef unsigned long kernel_ulong_t;
64032 #endif
64033
64034-#define PCI_ANY_ID (~0)
64035+#define PCI_ANY_ID ((__u16)~0)
64036
64037 struct pci_device_id {
64038 __u32 vendor, device; /* Vendor and device ID or PCI_ANY_ID*/
64039@@ -139,7 +139,7 @@ struct usb_device_id {
64040 #define USB_DEVICE_ID_MATCH_INT_PROTOCOL 0x0200
64041 #define USB_DEVICE_ID_MATCH_INT_NUMBER 0x0400
64042
64043-#define HID_ANY_ID (~0)
64044+#define HID_ANY_ID (~0U)
64045 #define HID_BUS_ANY 0xffff
64046 #define HID_GROUP_ANY 0x0000
64047
64048diff --git a/include/linux/module.h b/include/linux/module.h
64049index fbcafe2..e5d9587 100644
64050--- a/include/linux/module.h
64051+++ b/include/linux/module.h
64052@@ -17,6 +17,7 @@
64053 #include <linux/moduleparam.h>
64054 #include <linux/tracepoint.h>
64055 #include <linux/export.h>
64056+#include <linux/fs.h>
64057
64058 #include <linux/percpu.h>
64059 #include <asm/module.h>
64060@@ -273,19 +274,16 @@ struct module
64061 int (*init)(void);
64062
64063 /* If this is non-NULL, vfree after init() returns */
64064- void *module_init;
64065+ void *module_init_rx, *module_init_rw;
64066
64067 /* Here is the actual code + data, vfree'd on unload. */
64068- void *module_core;
64069+ void *module_core_rx, *module_core_rw;
64070
64071 /* Here are the sizes of the init and core sections */
64072- unsigned int init_size, core_size;
64073+ unsigned int init_size_rw, core_size_rw;
64074
64075 /* The size of the executable code in each section. */
64076- unsigned int init_text_size, core_text_size;
64077-
64078- /* Size of RO sections of the module (text+rodata) */
64079- unsigned int init_ro_size, core_ro_size;
64080+ unsigned int init_size_rx, core_size_rx;
64081
64082 /* Arch-specific module values */
64083 struct mod_arch_specific arch;
64084@@ -341,6 +339,10 @@ struct module
64085 #ifdef CONFIG_EVENT_TRACING
64086 struct ftrace_event_call **trace_events;
64087 unsigned int num_trace_events;
64088+ struct file_operations trace_id;
64089+ struct file_operations trace_enable;
64090+ struct file_operations trace_format;
64091+ struct file_operations trace_filter;
64092 #endif
64093 #ifdef CONFIG_FTRACE_MCOUNT_RECORD
64094 unsigned int num_ftrace_callsites;
64095@@ -388,16 +390,46 @@ bool is_module_address(unsigned long addr);
64096 bool is_module_percpu_address(unsigned long addr);
64097 bool is_module_text_address(unsigned long addr);
64098
64099+static inline int within_module_range(unsigned long addr, void *start, unsigned long size)
64100+{
64101+
64102+#ifdef CONFIG_PAX_KERNEXEC
64103+ if (ktla_ktva(addr) >= (unsigned long)start &&
64104+ ktla_ktva(addr) < (unsigned long)start + size)
64105+ return 1;
64106+#endif
64107+
64108+ return ((void *)addr >= start && (void *)addr < start + size);
64109+}
64110+
64111+static inline int within_module_core_rx(unsigned long addr, struct module *mod)
64112+{
64113+ return within_module_range(addr, mod->module_core_rx, mod->core_size_rx);
64114+}
64115+
64116+static inline int within_module_core_rw(unsigned long addr, struct module *mod)
64117+{
64118+ return within_module_range(addr, mod->module_core_rw, mod->core_size_rw);
64119+}
64120+
64121+static inline int within_module_init_rx(unsigned long addr, struct module *mod)
64122+{
64123+ return within_module_range(addr, mod->module_init_rx, mod->init_size_rx);
64124+}
64125+
64126+static inline int within_module_init_rw(unsigned long addr, struct module *mod)
64127+{
64128+ return within_module_range(addr, mod->module_init_rw, mod->init_size_rw);
64129+}
64130+
64131 static inline int within_module_core(unsigned long addr, struct module *mod)
64132 {
64133- return (unsigned long)mod->module_core <= addr &&
64134- addr < (unsigned long)mod->module_core + mod->core_size;
64135+ return within_module_core_rx(addr, mod) || within_module_core_rw(addr, mod);
64136 }
64137
64138 static inline int within_module_init(unsigned long addr, struct module *mod)
64139 {
64140- return (unsigned long)mod->module_init <= addr &&
64141- addr < (unsigned long)mod->module_init + mod->init_size;
64142+ return within_module_init_rx(addr, mod) || within_module_init_rw(addr, mod);
64143 }
64144
64145 /* Search for module by name: must hold module_mutex. */
64146diff --git a/include/linux/moduleloader.h b/include/linux/moduleloader.h
64147index b2be02e..72d2f78 100644
64148--- a/include/linux/moduleloader.h
64149+++ b/include/linux/moduleloader.h
64150@@ -23,11 +23,23 @@ unsigned int arch_mod_section_prepend(struct module *mod, unsigned int section);
64151
64152 /* Allocator used for allocating struct module, core sections and init
64153 sections. Returns NULL on failure. */
64154-void *module_alloc(unsigned long size);
64155+void *module_alloc(unsigned long size) __size_overflow(1);
64156+
64157+#ifdef CONFIG_PAX_KERNEXEC
64158+void *module_alloc_exec(unsigned long size) __size_overflow(1);
64159+#else
64160+#define module_alloc_exec(x) module_alloc(x)
64161+#endif
64162
64163 /* Free memory returned from module_alloc. */
64164 void module_free(struct module *mod, void *module_region);
64165
64166+#ifdef CONFIG_PAX_KERNEXEC
64167+void module_free_exec(struct module *mod, void *module_region);
64168+#else
64169+#define module_free_exec(x, y) module_free((x), (y))
64170+#endif
64171+
64172 /* Apply the given relocation to the (simplified) ELF. Return -error
64173 or 0. */
64174 int apply_relocate(Elf_Shdr *sechdrs,
64175diff --git a/include/linux/moduleparam.h b/include/linux/moduleparam.h
64176index d6a5806..7c13347 100644
64177--- a/include/linux/moduleparam.h
64178+++ b/include/linux/moduleparam.h
64179@@ -286,7 +286,7 @@ static inline void __kernel_param_unlock(void)
64180 * @len is usually just sizeof(string).
64181 */
64182 #define module_param_string(name, string, len, perm) \
64183- static const struct kparam_string __param_string_##name \
64184+ static const struct kparam_string __param_string_##name __used \
64185 = { len, string }; \
64186 __module_param_call(MODULE_PARAM_PREFIX, name, \
64187 &param_ops_string, \
64188@@ -425,7 +425,7 @@ extern int param_set_bint(const char *val, const struct kernel_param *kp);
64189 */
64190 #define module_param_array_named(name, array, type, nump, perm) \
64191 param_check_##type(name, &(array)[0]); \
64192- static const struct kparam_array __param_arr_##name \
64193+ static const struct kparam_array __param_arr_##name __used \
64194 = { .max = ARRAY_SIZE(array), .num = nump, \
64195 .ops = &param_ops_##type, \
64196 .elemsize = sizeof(array[0]), .elem = array }; \
64197diff --git a/include/linux/namei.h b/include/linux/namei.h
64198index 4bf19d8..5268cea 100644
64199--- a/include/linux/namei.h
64200+++ b/include/linux/namei.h
64201@@ -18,7 +18,7 @@ struct nameidata {
64202 unsigned seq;
64203 int last_type;
64204 unsigned depth;
64205- char *saved_names[MAX_NESTED_LINKS + 1];
64206+ const char *saved_names[MAX_NESTED_LINKS + 1];
64207 };
64208
64209 /*
64210@@ -83,12 +83,12 @@ extern void unlock_rename(struct dentry *, struct dentry *);
64211
64212 extern void nd_jump_link(struct nameidata *nd, struct path *path);
64213
64214-static inline void nd_set_link(struct nameidata *nd, char *path)
64215+static inline void nd_set_link(struct nameidata *nd, const char *path)
64216 {
64217 nd->saved_names[nd->depth] = path;
64218 }
64219
64220-static inline char *nd_get_link(struct nameidata *nd)
64221+static inline const char *nd_get_link(const struct nameidata *nd)
64222 {
64223 return nd->saved_names[nd->depth];
64224 }
64225diff --git a/include/linux/netdevice.h b/include/linux/netdevice.h
64226index 59dc05f3..c905a34 100644
64227--- a/include/linux/netdevice.h
64228+++ b/include/linux/netdevice.h
64229@@ -1027,6 +1027,7 @@ struct net_device_ops {
64230 struct net_device *dev,
64231 int idx);
64232 };
64233+typedef struct net_device_ops __no_const net_device_ops_no_const;
64234
64235 /*
64236 * The DEVICE structure.
64237@@ -1087,7 +1088,7 @@ struct net_device {
64238 int iflink;
64239
64240 struct net_device_stats stats;
64241- atomic_long_t rx_dropped; /* dropped packets by core network
64242+ atomic_long_unchecked_t rx_dropped; /* dropped packets by core network
64243 * Do not use this in drivers.
64244 */
64245
64246diff --git a/include/linux/netfilter/xt_gradm.h b/include/linux/netfilter/xt_gradm.h
64247new file mode 100644
64248index 0000000..33f4af8
64249--- /dev/null
64250+++ b/include/linux/netfilter/xt_gradm.h
64251@@ -0,0 +1,9 @@
64252+#ifndef _LINUX_NETFILTER_XT_GRADM_H
64253+#define _LINUX_NETFILTER_XT_GRADM_H 1
64254+
64255+struct xt_gradm_mtinfo {
64256+ __u16 flags;
64257+ __u16 invflags;
64258+};
64259+
64260+#endif
64261diff --git a/include/linux/of_pdt.h b/include/linux/of_pdt.h
64262index c65a18a..0c05f3a 100644
64263--- a/include/linux/of_pdt.h
64264+++ b/include/linux/of_pdt.h
64265@@ -32,7 +32,7 @@ struct of_pdt_ops {
64266
64267 /* return 0 on success; fill in 'len' with number of bytes in path */
64268 int (*pkg2path)(phandle node, char *buf, const int buflen, int *len);
64269-};
64270+} __no_const;
64271
64272 extern void *prom_early_alloc(unsigned long size);
64273
64274diff --git a/include/linux/oprofile.h b/include/linux/oprofile.h
64275index a4c5624..79d6d88 100644
64276--- a/include/linux/oprofile.h
64277+++ b/include/linux/oprofile.h
64278@@ -139,9 +139,9 @@ int oprofilefs_create_ulong(struct super_block * sb, struct dentry * root,
64279 int oprofilefs_create_ro_ulong(struct super_block * sb, struct dentry * root,
64280 char const * name, ulong * val);
64281
64282-/** Create a file for read-only access to an atomic_t. */
64283+/** Create a file for read-only access to an atomic_unchecked_t. */
64284 int oprofilefs_create_ro_atomic(struct super_block * sb, struct dentry * root,
64285- char const * name, atomic_t * val);
64286+ char const * name, atomic_unchecked_t * val);
64287
64288 /** create a directory */
64289 struct dentry * oprofilefs_mkdir(struct super_block * sb, struct dentry * root,
64290diff --git a/include/linux/perf_event.h b/include/linux/perf_event.h
64291index bdb4161..f373d41 100644
64292--- a/include/linux/perf_event.h
64293+++ b/include/linux/perf_event.h
64294@@ -882,8 +882,8 @@ struct perf_event {
64295
64296 enum perf_event_active_state state;
64297 unsigned int attach_state;
64298- local64_t count;
64299- atomic64_t child_count;
64300+ local64_t count; /* PaX: fix it one day */
64301+ atomic64_unchecked_t child_count;
64302
64303 /*
64304 * These are the total time in nanoseconds that the event
64305@@ -934,8 +934,8 @@ struct perf_event {
64306 * These accumulate total time (in nanoseconds) that children
64307 * events have been enabled and running, respectively.
64308 */
64309- atomic64_t child_total_time_enabled;
64310- atomic64_t child_total_time_running;
64311+ atomic64_unchecked_t child_total_time_enabled;
64312+ atomic64_unchecked_t child_total_time_running;
64313
64314 /*
64315 * Protect attach/detach and child_list:
64316diff --git a/include/linux/personality.h b/include/linux/personality.h
64317index 8fc7dd1a..c19d89e 100644
64318--- a/include/linux/personality.h
64319+++ b/include/linux/personality.h
64320@@ -44,6 +44,7 @@ enum {
64321 #define PER_CLEAR_ON_SETID (READ_IMPLIES_EXEC | \
64322 ADDR_NO_RANDOMIZE | \
64323 ADDR_COMPAT_LAYOUT | \
64324+ ADDR_LIMIT_3GB | \
64325 MMAP_PAGE_ZERO)
64326
64327 /*
64328diff --git a/include/linux/pipe_fs_i.h b/include/linux/pipe_fs_i.h
64329index ad1a427..6419649 100644
64330--- a/include/linux/pipe_fs_i.h
64331+++ b/include/linux/pipe_fs_i.h
64332@@ -45,9 +45,9 @@ struct pipe_buffer {
64333 struct pipe_inode_info {
64334 wait_queue_head_t wait;
64335 unsigned int nrbufs, curbuf, buffers;
64336- unsigned int readers;
64337- unsigned int writers;
64338- unsigned int waiting_writers;
64339+ atomic_t readers;
64340+ atomic_t writers;
64341+ atomic_t waiting_writers;
64342 unsigned int r_counter;
64343 unsigned int w_counter;
64344 struct page *tmp_page;
64345diff --git a/include/linux/pm_runtime.h b/include/linux/pm_runtime.h
64346index f271860..6b3bec5 100644
64347--- a/include/linux/pm_runtime.h
64348+++ b/include/linux/pm_runtime.h
64349@@ -97,7 +97,7 @@ static inline bool pm_runtime_callbacks_present(struct device *dev)
64350
64351 static inline void pm_runtime_mark_last_busy(struct device *dev)
64352 {
64353- ACCESS_ONCE(dev->power.last_busy) = jiffies;
64354+ ACCESS_ONCE_RW(dev->power.last_busy) = jiffies;
64355 }
64356
64357 #else /* !CONFIG_PM_RUNTIME */
64358diff --git a/include/linux/poison.h b/include/linux/poison.h
64359index 2110a81..13a11bb 100644
64360--- a/include/linux/poison.h
64361+++ b/include/linux/poison.h
64362@@ -19,8 +19,8 @@
64363 * under normal circumstances, used to verify that nobody uses
64364 * non-initialized list entries.
64365 */
64366-#define LIST_POISON1 ((void *) 0x00100100 + POISON_POINTER_DELTA)
64367-#define LIST_POISON2 ((void *) 0x00200200 + POISON_POINTER_DELTA)
64368+#define LIST_POISON1 ((void *) (long)0xFFFFFF01)
64369+#define LIST_POISON2 ((void *) (long)0xFFFFFF02)
64370
64371 /********** include/linux/timer.h **********/
64372 /*
64373diff --git a/include/linux/preempt.h b/include/linux/preempt.h
64374index 5a710b9..0b0dab9 100644
64375--- a/include/linux/preempt.h
64376+++ b/include/linux/preempt.h
64377@@ -126,7 +126,7 @@ struct preempt_ops {
64378 void (*sched_in)(struct preempt_notifier *notifier, int cpu);
64379 void (*sched_out)(struct preempt_notifier *notifier,
64380 struct task_struct *next);
64381-};
64382+} __no_const;
64383
64384 /**
64385 * preempt_notifier - key for installing preemption notifiers
64386diff --git a/include/linux/printk.h b/include/linux/printk.h
64387index 9afc01e..92c32e8 100644
64388--- a/include/linux/printk.h
64389+++ b/include/linux/printk.h
64390@@ -101,6 +101,8 @@ void early_printk(const char *fmt, ...);
64391 extern int printk_needs_cpu(int cpu);
64392 extern void printk_tick(void);
64393
64394+extern int kptr_restrict;
64395+
64396 #ifdef CONFIG_PRINTK
64397 asmlinkage __printf(5, 0)
64398 int vprintk_emit(int facility, int level,
64399@@ -135,7 +137,6 @@ extern bool printk_timed_ratelimit(unsigned long *caller_jiffies,
64400
64401 extern int printk_delay_msec;
64402 extern int dmesg_restrict;
64403-extern int kptr_restrict;
64404
64405 void log_buf_kexec_setup(void);
64406 void __init setup_log_buf(int early);
64407diff --git a/include/linux/proc_fs.h b/include/linux/proc_fs.h
64408index 3fd2e87..d93a721 100644
64409--- a/include/linux/proc_fs.h
64410+++ b/include/linux/proc_fs.h
64411@@ -155,6 +155,18 @@ static inline struct proc_dir_entry *proc_create(const char *name, umode_t mode,
64412 return proc_create_data(name, mode, parent, proc_fops, NULL);
64413 }
64414
64415+static inline struct proc_dir_entry *proc_create_grsec(const char *name, umode_t mode,
64416+ struct proc_dir_entry *parent, const struct file_operations *proc_fops)
64417+{
64418+#ifdef CONFIG_GRKERNSEC_PROC_USER
64419+ return proc_create_data(name, S_IRUSR, parent, proc_fops, NULL);
64420+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
64421+ return proc_create_data(name, S_IRUSR | S_IRGRP, parent, proc_fops, NULL);
64422+#else
64423+ return proc_create_data(name, mode, parent, proc_fops, NULL);
64424+#endif
64425+}
64426+
64427 static inline struct proc_dir_entry *create_proc_read_entry(const char *name,
64428 umode_t mode, struct proc_dir_entry *base,
64429 read_proc_t *read_proc, void * data)
64430@@ -258,7 +270,7 @@ union proc_op {
64431 int (*proc_show)(struct seq_file *m,
64432 struct pid_namespace *ns, struct pid *pid,
64433 struct task_struct *task);
64434-};
64435+} __no_const;
64436
64437 struct ctl_table_header;
64438 struct ctl_table;
64439diff --git a/include/linux/random.h b/include/linux/random.h
64440index ac621ce..c1215f3 100644
64441--- a/include/linux/random.h
64442+++ b/include/linux/random.h
64443@@ -53,6 +53,10 @@ extern void add_input_randomness(unsigned int type, unsigned int code,
64444 unsigned int value);
64445 extern void add_interrupt_randomness(int irq, int irq_flags);
64446
64447+#ifdef CONFIG_PAX_LATENT_ENTROPY
64448+extern void transfer_latent_entropy(void);
64449+#endif
64450+
64451 extern void get_random_bytes(void *buf, int nbytes);
64452 extern void get_random_bytes_arch(void *buf, int nbytes);
64453 void generate_random_uuid(unsigned char uuid_out[16]);
64454@@ -69,12 +73,17 @@ void srandom32(u32 seed);
64455
64456 u32 prandom32(struct rnd_state *);
64457
64458+static inline unsigned long pax_get_random_long(void)
64459+{
64460+ return random32() + (sizeof(long) > 4 ? (unsigned long)random32() << 32 : 0);
64461+}
64462+
64463 /*
64464 * Handle minimum values for seeds
64465 */
64466 static inline u32 __seed(u32 x, u32 m)
64467 {
64468- return (x < m) ? x + m : x;
64469+ return (x <= m) ? x + m + 1 : x;
64470 }
64471
64472 /**
64473diff --git a/include/linux/reboot.h b/include/linux/reboot.h
64474index e0879a7..a12f962 100644
64475--- a/include/linux/reboot.h
64476+++ b/include/linux/reboot.h
64477@@ -52,9 +52,9 @@ extern int unregister_reboot_notifier(struct notifier_block *);
64478 * Architecture-specific implementations of sys_reboot commands.
64479 */
64480
64481-extern void machine_restart(char *cmd);
64482-extern void machine_halt(void);
64483-extern void machine_power_off(void);
64484+extern void machine_restart(char *cmd) __noreturn;
64485+extern void machine_halt(void) __noreturn;
64486+extern void machine_power_off(void) __noreturn;
64487
64488 extern void machine_shutdown(void);
64489 struct pt_regs;
64490@@ -65,9 +65,9 @@ extern void machine_crash_shutdown(struct pt_regs *);
64491 */
64492
64493 extern void kernel_restart_prepare(char *cmd);
64494-extern void kernel_restart(char *cmd);
64495-extern void kernel_halt(void);
64496-extern void kernel_power_off(void);
64497+extern void kernel_restart(char *cmd) __noreturn;
64498+extern void kernel_halt(void) __noreturn;
64499+extern void kernel_power_off(void) __noreturn;
64500
64501 extern int C_A_D; /* for sysctl */
64502 void ctrl_alt_del(void);
64503@@ -81,7 +81,7 @@ extern int orderly_poweroff(bool force);
64504 * Emergency restart, callable from an interrupt handler.
64505 */
64506
64507-extern void emergency_restart(void);
64508+extern void emergency_restart(void) __noreturn;
64509 #include <asm/emergency-restart.h>
64510
64511 #endif
64512diff --git a/include/linux/relay.h b/include/linux/relay.h
64513index 91cacc3..b55ff74 100644
64514--- a/include/linux/relay.h
64515+++ b/include/linux/relay.h
64516@@ -160,7 +160,7 @@ struct rchan_callbacks
64517 * The callback should return 0 if successful, negative if not.
64518 */
64519 int (*remove_buf_file)(struct dentry *dentry);
64520-};
64521+} __no_const;
64522
64523 /*
64524 * CONFIG_RELAY kernel API, kernel/relay.c
64525diff --git a/include/linux/rfkill.h b/include/linux/rfkill.h
64526index 6fdf027..ff72610 100644
64527--- a/include/linux/rfkill.h
64528+++ b/include/linux/rfkill.h
64529@@ -147,6 +147,7 @@ struct rfkill_ops {
64530 void (*query)(struct rfkill *rfkill, void *data);
64531 int (*set_block)(void *data, bool blocked);
64532 };
64533+typedef struct rfkill_ops __no_const rfkill_ops_no_const;
64534
64535 #if defined(CONFIG_RFKILL) || defined(CONFIG_RFKILL_MODULE)
64536 /**
64537diff --git a/include/linux/rio.h b/include/linux/rio.h
64538index a90ebad..fd87b5d 100644
64539--- a/include/linux/rio.h
64540+++ b/include/linux/rio.h
64541@@ -321,7 +321,7 @@ struct rio_ops {
64542 int mbox, void *buffer, size_t len);
64543 int (*add_inb_buffer)(struct rio_mport *mport, int mbox, void *buf);
64544 void *(*get_inb_message)(struct rio_mport *mport, int mbox);
64545-};
64546+} __no_const;
64547
64548 #define RIO_RESOURCE_MEM 0x00000100
64549 #define RIO_RESOURCE_DOORBELL 0x00000200
64550diff --git a/include/linux/rmap.h b/include/linux/rmap.h
64551index 3fce545..b4fed6e 100644
64552--- a/include/linux/rmap.h
64553+++ b/include/linux/rmap.h
64554@@ -119,9 +119,9 @@ static inline void anon_vma_unlock(struct anon_vma *anon_vma)
64555 void anon_vma_init(void); /* create anon_vma_cachep */
64556 int anon_vma_prepare(struct vm_area_struct *);
64557 void unlink_anon_vmas(struct vm_area_struct *);
64558-int anon_vma_clone(struct vm_area_struct *, struct vm_area_struct *);
64559+int anon_vma_clone(struct vm_area_struct *, const struct vm_area_struct *);
64560 void anon_vma_moveto_tail(struct vm_area_struct *);
64561-int anon_vma_fork(struct vm_area_struct *, struct vm_area_struct *);
64562+int anon_vma_fork(struct vm_area_struct *, const struct vm_area_struct *);
64563
64564 static inline void anon_vma_merge(struct vm_area_struct *vma,
64565 struct vm_area_struct *next)
64566diff --git a/include/linux/sched.h b/include/linux/sched.h
64567index 23bddac..5976055 100644
64568--- a/include/linux/sched.h
64569+++ b/include/linux/sched.h
64570@@ -101,6 +101,7 @@ struct bio_list;
64571 struct fs_struct;
64572 struct perf_event_context;
64573 struct blk_plug;
64574+struct linux_binprm;
64575
64576 /*
64577 * List of flags we want to share for kernel threads,
64578@@ -384,10 +385,13 @@ struct user_namespace;
64579 #define DEFAULT_MAX_MAP_COUNT (USHRT_MAX - MAPCOUNT_ELF_CORE_MARGIN)
64580
64581 extern int sysctl_max_map_count;
64582+extern unsigned long sysctl_heap_stack_gap;
64583
64584 #include <linux/aio.h>
64585
64586 #ifdef CONFIG_MMU
64587+extern bool check_heap_stack_gap(const struct vm_area_struct *vma, unsigned long addr, unsigned long len);
64588+extern unsigned long skip_heap_stack_gap(const struct vm_area_struct *vma, unsigned long len);
64589 extern void arch_pick_mmap_layout(struct mm_struct *mm);
64590 extern unsigned long
64591 arch_get_unmapped_area(struct file *, unsigned long, unsigned long,
64592@@ -651,6 +655,17 @@ struct signal_struct {
64593 #ifdef CONFIG_TASKSTATS
64594 struct taskstats *stats;
64595 #endif
64596+
64597+#ifdef CONFIG_GRKERNSEC
64598+ u32 curr_ip;
64599+ u32 saved_ip;
64600+ u32 gr_saddr;
64601+ u32 gr_daddr;
64602+ u16 gr_sport;
64603+ u16 gr_dport;
64604+ u8 used_accept:1;
64605+#endif
64606+
64607 #ifdef CONFIG_AUDIT
64608 unsigned audit_tty;
64609 struct tty_audit_buf *tty_audit_buf;
64610@@ -734,6 +749,11 @@ struct user_struct {
64611 struct key *session_keyring; /* UID's default session keyring */
64612 #endif
64613
64614+#if defined(CONFIG_GRKERNSEC_KERN_LOCKOUT) || defined(CONFIG_GRKERNSEC_BRUTE)
64615+ unsigned int banned;
64616+ unsigned long ban_expires;
64617+#endif
64618+
64619 /* Hash table maintenance information */
64620 struct hlist_node uidhash_node;
64621 kuid_t uid;
64622@@ -1356,8 +1376,8 @@ struct task_struct {
64623 struct list_head thread_group;
64624
64625 struct completion *vfork_done; /* for vfork() */
64626- int __user *set_child_tid; /* CLONE_CHILD_SETTID */
64627- int __user *clear_child_tid; /* CLONE_CHILD_CLEARTID */
64628+ pid_t __user *set_child_tid; /* CLONE_CHILD_SETTID */
64629+ pid_t __user *clear_child_tid; /* CLONE_CHILD_CLEARTID */
64630
64631 cputime_t utime, stime, utimescaled, stimescaled;
64632 cputime_t gtime;
64633@@ -1373,11 +1393,6 @@ struct task_struct {
64634 struct task_cputime cputime_expires;
64635 struct list_head cpu_timers[3];
64636
64637-/* process credentials */
64638- const struct cred __rcu *real_cred; /* objective and real subjective task
64639- * credentials (COW) */
64640- const struct cred __rcu *cred; /* effective (overridable) subjective task
64641- * credentials (COW) */
64642 char comm[TASK_COMM_LEN]; /* executable name excluding path
64643 - access with [gs]et_task_comm (which lock
64644 it with task_lock())
64645@@ -1394,6 +1409,10 @@ struct task_struct {
64646 #endif
64647 /* CPU-specific state of this task */
64648 struct thread_struct thread;
64649+/* thread_info moved to task_struct */
64650+#ifdef CONFIG_X86
64651+ struct thread_info tinfo;
64652+#endif
64653 /* filesystem information */
64654 struct fs_struct *fs;
64655 /* open file information */
64656@@ -1467,6 +1486,10 @@ struct task_struct {
64657 gfp_t lockdep_reclaim_gfp;
64658 #endif
64659
64660+/* process credentials */
64661+ const struct cred __rcu *real_cred; /* objective and real subjective task
64662+ * credentials (COW) */
64663+
64664 /* journalling filesystem info */
64665 void *journal_info;
64666
64667@@ -1505,6 +1528,10 @@ struct task_struct {
64668 /* cg_list protected by css_set_lock and tsk->alloc_lock */
64669 struct list_head cg_list;
64670 #endif
64671+
64672+ const struct cred __rcu *cred; /* effective (overridable) subjective task
64673+ * credentials (COW) */
64674+
64675 #ifdef CONFIG_FUTEX
64676 struct robust_list_head __user *robust_list;
64677 #ifdef CONFIG_COMPAT
64678@@ -1589,8 +1616,74 @@ struct task_struct {
64679 #ifdef CONFIG_UPROBES
64680 struct uprobe_task *utask;
64681 #endif
64682+
64683+#ifdef CONFIG_GRKERNSEC
64684+ /* grsecurity */
64685+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
64686+ u64 exec_id;
64687+#endif
64688+#ifdef CONFIG_GRKERNSEC_SETXID
64689+ const struct cred *delayed_cred;
64690+#endif
64691+ struct dentry *gr_chroot_dentry;
64692+ struct acl_subject_label *acl;
64693+ struct acl_role_label *role;
64694+ struct file *exec_file;
64695+ u16 acl_role_id;
64696+ /* is this the task that authenticated to the special role */
64697+ u8 acl_sp_role;
64698+ u8 is_writable;
64699+ u8 brute;
64700+ u8 gr_is_chrooted;
64701+#endif
64702+
64703 };
64704
64705+#define MF_PAX_PAGEEXEC 0x01000000 /* Paging based non-executable pages */
64706+#define MF_PAX_EMUTRAMP 0x02000000 /* Emulate trampolines */
64707+#define MF_PAX_MPROTECT 0x04000000 /* Restrict mprotect() */
64708+#define MF_PAX_RANDMMAP 0x08000000 /* Randomize mmap() base */
64709+/*#define MF_PAX_RANDEXEC 0x10000000*/ /* Randomize ET_EXEC base */
64710+#define MF_PAX_SEGMEXEC 0x20000000 /* Segmentation based non-executable pages */
64711+
64712+#ifdef CONFIG_PAX_SOFTMODE
64713+extern int pax_softmode;
64714+#endif
64715+
64716+extern int pax_check_flags(unsigned long *);
64717+
64718+/* if tsk != current then task_lock must be held on it */
64719+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
64720+static inline unsigned long pax_get_flags(struct task_struct *tsk)
64721+{
64722+ if (likely(tsk->mm))
64723+ return tsk->mm->pax_flags;
64724+ else
64725+ return 0UL;
64726+}
64727+
64728+/* if tsk != current then task_lock must be held on it */
64729+static inline long pax_set_flags(struct task_struct *tsk, unsigned long flags)
64730+{
64731+ if (likely(tsk->mm)) {
64732+ tsk->mm->pax_flags = flags;
64733+ return 0;
64734+ }
64735+ return -EINVAL;
64736+}
64737+#endif
64738+
64739+#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
64740+extern void pax_set_initial_flags(struct linux_binprm *bprm);
64741+#elif defined(CONFIG_PAX_HOOK_ACL_FLAGS)
64742+extern void (*pax_set_initial_flags_func)(struct linux_binprm *bprm);
64743+#endif
64744+
64745+extern void pax_report_fault(struct pt_regs *regs, void *pc, void *sp);
64746+extern void pax_report_insns(struct pt_regs *regs, void *pc, void *sp);
64747+extern void pax_report_refcount_overflow(struct pt_regs *regs);
64748+extern void check_object_size(const void *ptr, unsigned long n, bool to);
64749+
64750 /* Future-safe accessor for struct task_struct's cpus_allowed. */
64751 #define tsk_cpus_allowed(tsk) (&(tsk)->cpus_allowed)
64752
64753@@ -2125,7 +2218,9 @@ void yield(void);
64754 extern struct exec_domain default_exec_domain;
64755
64756 union thread_union {
64757+#ifndef CONFIG_X86
64758 struct thread_info thread_info;
64759+#endif
64760 unsigned long stack[THREAD_SIZE/sizeof(long)];
64761 };
64762
64763@@ -2158,6 +2253,7 @@ extern struct pid_namespace init_pid_ns;
64764 */
64765
64766 extern struct task_struct *find_task_by_vpid(pid_t nr);
64767+extern struct task_struct *find_task_by_vpid_unrestricted(pid_t nr);
64768 extern struct task_struct *find_task_by_pid_ns(pid_t nr,
64769 struct pid_namespace *ns);
64770
64771@@ -2314,7 +2410,7 @@ extern void __cleanup_sighand(struct sighand_struct *);
64772 extern void exit_itimers(struct signal_struct *);
64773 extern void flush_itimer_signals(void);
64774
64775-extern void do_group_exit(int);
64776+extern __noreturn void do_group_exit(int);
64777
64778 extern void daemonize(const char *, ...);
64779 extern int allow_signal(int);
64780@@ -2515,9 +2611,9 @@ static inline unsigned long *end_of_stack(struct task_struct *p)
64781
64782 #endif
64783
64784-static inline int object_is_on_stack(void *obj)
64785+static inline int object_starts_on_stack(void *obj)
64786 {
64787- void *stack = task_stack_page(current);
64788+ const void *stack = task_stack_page(current);
64789
64790 return (obj >= stack) && (obj < (stack + THREAD_SIZE));
64791 }
64792diff --git a/include/linux/screen_info.h b/include/linux/screen_info.h
64793index 899fbb4..1cb4138 100644
64794--- a/include/linux/screen_info.h
64795+++ b/include/linux/screen_info.h
64796@@ -43,7 +43,8 @@ struct screen_info {
64797 __u16 pages; /* 0x32 */
64798 __u16 vesa_attributes; /* 0x34 */
64799 __u32 capabilities; /* 0x36 */
64800- __u8 _reserved[6]; /* 0x3a */
64801+ __u16 vesapm_size; /* 0x3a */
64802+ __u8 _reserved[4]; /* 0x3c */
64803 } __attribute__((packed));
64804
64805 #define VIDEO_TYPE_MDA 0x10 /* Monochrome Text Display */
64806diff --git a/include/linux/security.h b/include/linux/security.h
64807index d143b8e..9f27b95 100644
64808--- a/include/linux/security.h
64809+++ b/include/linux/security.h
64810@@ -26,6 +26,7 @@
64811 #include <linux/capability.h>
64812 #include <linux/slab.h>
64813 #include <linux/err.h>
64814+#include <linux/grsecurity.h>
64815
64816 struct linux_binprm;
64817 struct cred;
64818diff --git a/include/linux/seq_file.h b/include/linux/seq_file.h
64819index 83c44ee..e8a9eba 100644
64820--- a/include/linux/seq_file.h
64821+++ b/include/linux/seq_file.h
64822@@ -25,6 +25,9 @@ struct seq_file {
64823 struct mutex lock;
64824 const struct seq_operations *op;
64825 int poll_event;
64826+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
64827+ u64 exec_id;
64828+#endif
64829 void *private;
64830 };
64831
64832@@ -34,6 +37,7 @@ struct seq_operations {
64833 void * (*next) (struct seq_file *m, void *v, loff_t *pos);
64834 int (*show) (struct seq_file *m, void *v);
64835 };
64836+typedef struct seq_operations __no_const seq_operations_no_const;
64837
64838 #define SEQ_SKIP 1
64839
64840diff --git a/include/linux/shm.h b/include/linux/shm.h
64841index edd0868..f98feee 100644
64842--- a/include/linux/shm.h
64843+++ b/include/linux/shm.h
64844@@ -98,6 +98,10 @@ struct shmid_kernel /* private to the kernel */
64845
64846 /* The task created the shm object. NULL if the task is dead. */
64847 struct task_struct *shm_creator;
64848+#ifdef CONFIG_GRKERNSEC
64849+ time_t shm_createtime;
64850+ pid_t shm_lapid;
64851+#endif
64852 };
64853
64854 /* shm_mode upper byte flags */
64855diff --git a/include/linux/skbuff.h b/include/linux/skbuff.h
64856index f3165d2..2cb3cb7 100644
64857--- a/include/linux/skbuff.h
64858+++ b/include/linux/skbuff.h
64859@@ -577,7 +577,7 @@ extern bool skb_try_coalesce(struct sk_buff *to, struct sk_buff *from,
64860 extern struct sk_buff *__alloc_skb(unsigned int size,
64861 gfp_t priority, int flags, int node);
64862 extern struct sk_buff *build_skb(void *data, unsigned int frag_size);
64863-static inline struct sk_buff *alloc_skb(unsigned int size,
64864+static inline struct sk_buff * __intentional_overflow(0) alloc_skb(unsigned int size,
64865 gfp_t priority)
64866 {
64867 return __alloc_skb(size, priority, 0, NUMA_NO_NODE);
64868@@ -687,7 +687,7 @@ static inline struct skb_shared_hwtstamps *skb_hwtstamps(struct sk_buff *skb)
64869 */
64870 static inline int skb_queue_empty(const struct sk_buff_head *list)
64871 {
64872- return list->next == (struct sk_buff *)list;
64873+ return list->next == (const struct sk_buff *)list;
64874 }
64875
64876 /**
64877@@ -700,7 +700,7 @@ static inline int skb_queue_empty(const struct sk_buff_head *list)
64878 static inline bool skb_queue_is_last(const struct sk_buff_head *list,
64879 const struct sk_buff *skb)
64880 {
64881- return skb->next == (struct sk_buff *)list;
64882+ return skb->next == (const struct sk_buff *)list;
64883 }
64884
64885 /**
64886@@ -713,7 +713,7 @@ static inline bool skb_queue_is_last(const struct sk_buff_head *list,
64887 static inline bool skb_queue_is_first(const struct sk_buff_head *list,
64888 const struct sk_buff *skb)
64889 {
64890- return skb->prev == (struct sk_buff *)list;
64891+ return skb->prev == (const struct sk_buff *)list;
64892 }
64893
64894 /**
64895@@ -1623,7 +1623,7 @@ static inline int pskb_network_may_pull(struct sk_buff *skb, unsigned int len)
64896 * NET_IP_ALIGN(2) + ethernet_header(14) + IP_header(20/40) + ports(8)
64897 */
64898 #ifndef NET_SKB_PAD
64899-#define NET_SKB_PAD max(32, L1_CACHE_BYTES)
64900+#define NET_SKB_PAD max(_AC(32,UL), L1_CACHE_BYTES)
64901 #endif
64902
64903 extern int ___pskb_trim(struct sk_buff *skb, unsigned int len);
64904@@ -2201,7 +2201,7 @@ extern struct sk_buff *skb_recv_datagram(struct sock *sk, unsigned flags,
64905 int noblock, int *err);
64906 extern unsigned int datagram_poll(struct file *file, struct socket *sock,
64907 struct poll_table_struct *wait);
64908-extern int skb_copy_datagram_iovec(const struct sk_buff *from,
64909+extern int __intentional_overflow(0) skb_copy_datagram_iovec(const struct sk_buff *from,
64910 int offset, struct iovec *to,
64911 int size);
64912 extern int skb_copy_and_csum_datagram_iovec(struct sk_buff *skb,
64913diff --git a/include/linux/slab.h b/include/linux/slab.h
64914index 0dd2dfa..2b8677c 100644
64915--- a/include/linux/slab.h
64916+++ b/include/linux/slab.h
64917@@ -11,12 +11,20 @@
64918
64919 #include <linux/gfp.h>
64920 #include <linux/types.h>
64921+#include <linux/err.h>
64922
64923 /*
64924 * Flags to pass to kmem_cache_create().
64925 * The ones marked DEBUG are only valid if CONFIG_SLAB_DEBUG is set.
64926 */
64927 #define SLAB_DEBUG_FREE 0x00000100UL /* DEBUG: Perform (expensive) checks on free */
64928+
64929+#ifdef CONFIG_PAX_USERCOPY_SLABS
64930+#define SLAB_USERCOPY 0x00000200UL /* PaX: Allow copying objs to/from userland */
64931+#else
64932+#define SLAB_USERCOPY 0x00000000UL
64933+#endif
64934+
64935 #define SLAB_RED_ZONE 0x00000400UL /* DEBUG: Red zone objs in a cache */
64936 #define SLAB_POISON 0x00000800UL /* DEBUG: Poison objects */
64937 #define SLAB_HWCACHE_ALIGN 0x00002000UL /* Align objs on cache lines */
64938@@ -87,10 +95,13 @@
64939 * ZERO_SIZE_PTR can be passed to kfree though in the same way that NULL can.
64940 * Both make kfree a no-op.
64941 */
64942-#define ZERO_SIZE_PTR ((void *)16)
64943+#define ZERO_SIZE_PTR \
64944+({ \
64945+ BUILD_BUG_ON(!(MAX_ERRNO & ~PAGE_MASK));\
64946+ (void *)(-MAX_ERRNO-1L); \
64947+})
64948
64949-#define ZERO_OR_NULL_PTR(x) ((unsigned long)(x) <= \
64950- (unsigned long)ZERO_SIZE_PTR)
64951+#define ZERO_OR_NULL_PTR(x) ((unsigned long)(x) - 1 >= (unsigned long)ZERO_SIZE_PTR - 1)
64952
64953 /*
64954 * Common fields provided in kmem_cache by all slab allocators
64955@@ -185,6 +196,8 @@ void * __must_check krealloc(const void *, size_t, gfp_t);
64956 void kfree(const void *);
64957 void kzfree(const void *);
64958 size_t ksize(const void *);
64959+const char *check_heap_object(const void *ptr, unsigned long n, bool to);
64960+bool is_usercopy_object(const void *ptr);
64961
64962 /*
64963 * Allocator specific definitions. These are mainly used to establish optimized
64964@@ -322,7 +335,7 @@ static inline void *kmem_cache_alloc_node(struct kmem_cache *cachep,
64965 */
64966 #if defined(CONFIG_DEBUG_SLAB) || defined(CONFIG_SLUB) || \
64967 (defined(CONFIG_SLAB) && defined(CONFIG_TRACING))
64968-extern void *__kmalloc_track_caller(size_t, gfp_t, unsigned long);
64969+extern void *__kmalloc_track_caller(size_t, gfp_t, unsigned long) __size_overflow(1);
64970 #define kmalloc_track_caller(size, flags) \
64971 __kmalloc_track_caller(size, flags, _RET_IP_)
64972 #else
64973@@ -341,7 +354,7 @@ extern void *__kmalloc_track_caller(size_t, gfp_t, unsigned long);
64974 */
64975 #if defined(CONFIG_DEBUG_SLAB) || defined(CONFIG_SLUB) || \
64976 (defined(CONFIG_SLAB) && defined(CONFIG_TRACING))
64977-extern void *__kmalloc_node_track_caller(size_t, gfp_t, int, unsigned long);
64978+extern void *__kmalloc_node_track_caller(size_t, gfp_t, int, unsigned long) __size_overflow(1);
64979 #define kmalloc_node_track_caller(size, flags, node) \
64980 __kmalloc_node_track_caller(size, flags, node, \
64981 _RET_IP_)
64982diff --git a/include/linux/slab_def.h b/include/linux/slab_def.h
64983index 0c634fa..8616300 100644
64984--- a/include/linux/slab_def.h
64985+++ b/include/linux/slab_def.h
64986@@ -69,10 +69,10 @@ struct kmem_cache {
64987 unsigned long node_allocs;
64988 unsigned long node_frees;
64989 unsigned long node_overflow;
64990- atomic_t allochit;
64991- atomic_t allocmiss;
64992- atomic_t freehit;
64993- atomic_t freemiss;
64994+ atomic_unchecked_t allochit;
64995+ atomic_unchecked_t allocmiss;
64996+ atomic_unchecked_t freehit;
64997+ atomic_unchecked_t freemiss;
64998
64999 /*
65000 * If debugging is enabled, then the allocator can add additional
65001@@ -105,11 +105,16 @@ struct cache_sizes {
65002 #ifdef CONFIG_ZONE_DMA
65003 struct kmem_cache *cs_dmacachep;
65004 #endif
65005+
65006+#ifdef CONFIG_PAX_USERCOPY_SLABS
65007+ struct kmem_cache *cs_usercopycachep;
65008+#endif
65009+
65010 };
65011 extern struct cache_sizes malloc_sizes[];
65012
65013 void *kmem_cache_alloc(struct kmem_cache *, gfp_t);
65014-void *__kmalloc(size_t size, gfp_t flags);
65015+void *__kmalloc(size_t size, gfp_t flags) __size_overflow(1);
65016
65017 #ifdef CONFIG_TRACING
65018 extern void *kmem_cache_alloc_trace(size_t size,
65019@@ -152,6 +157,13 @@ found:
65020 cachep = malloc_sizes[i].cs_dmacachep;
65021 else
65022 #endif
65023+
65024+#ifdef CONFIG_PAX_USERCOPY_SLABS
65025+ if (flags & GFP_USERCOPY)
65026+ cachep = malloc_sizes[i].cs_usercopycachep;
65027+ else
65028+#endif
65029+
65030 cachep = malloc_sizes[i].cs_cachep;
65031
65032 ret = kmem_cache_alloc_trace(size, cachep, flags);
65033@@ -162,7 +174,7 @@ found:
65034 }
65035
65036 #ifdef CONFIG_NUMA
65037-extern void *__kmalloc_node(size_t size, gfp_t flags, int node);
65038+extern void *__kmalloc_node(size_t size, gfp_t flags, int node) __size_overflow(1);
65039 extern void *kmem_cache_alloc_node(struct kmem_cache *, gfp_t flags, int node);
65040
65041 #ifdef CONFIG_TRACING
65042@@ -205,6 +217,13 @@ found:
65043 cachep = malloc_sizes[i].cs_dmacachep;
65044 else
65045 #endif
65046+
65047+#ifdef CONFIG_PAX_USERCOPY_SLABS
65048+ if (flags & GFP_USERCOPY)
65049+ cachep = malloc_sizes[i].cs_usercopycachep;
65050+ else
65051+#endif
65052+
65053 cachep = malloc_sizes[i].cs_cachep;
65054
65055 return kmem_cache_alloc_node_trace(size, cachep, flags, node);
65056diff --git a/include/linux/slob_def.h b/include/linux/slob_def.h
65057index 0ec00b3..22b4715 100644
65058--- a/include/linux/slob_def.h
65059+++ b/include/linux/slob_def.h
65060@@ -9,7 +9,7 @@ static __always_inline void *kmem_cache_alloc(struct kmem_cache *cachep,
65061 return kmem_cache_alloc_node(cachep, flags, -1);
65062 }
65063
65064-void *__kmalloc_node(size_t size, gfp_t flags, int node);
65065+void *__kmalloc_node(size_t size, gfp_t flags, int node) __size_overflow(1);
65066
65067 static __always_inline void *kmalloc_node(size_t size, gfp_t flags, int node)
65068 {
65069@@ -29,7 +29,7 @@ static __always_inline void *kmalloc(size_t size, gfp_t flags)
65070 return __kmalloc_node(size, flags, -1);
65071 }
65072
65073-static __always_inline void *__kmalloc(size_t size, gfp_t flags)
65074+static __always_inline __size_overflow(1) void *__kmalloc(size_t size, gfp_t flags)
65075 {
65076 return kmalloc(size, flags);
65077 }
65078diff --git a/include/linux/slub_def.h b/include/linux/slub_def.h
65079index df448ad..b99e7f6 100644
65080--- a/include/linux/slub_def.h
65081+++ b/include/linux/slub_def.h
65082@@ -91,7 +91,7 @@ struct kmem_cache {
65083 struct kmem_cache_order_objects max;
65084 struct kmem_cache_order_objects min;
65085 gfp_t allocflags; /* gfp flags to use on each alloc */
65086- int refcount; /* Refcount for slab cache destroy */
65087+ atomic_t refcount; /* Refcount for slab cache destroy */
65088 void (*ctor)(void *);
65089 int inuse; /* Offset to metadata */
65090 int align; /* Alignment */
65091@@ -152,7 +152,7 @@ extern struct kmem_cache *kmalloc_caches[SLUB_PAGE_SHIFT];
65092 * Sorry that the following has to be that ugly but some versions of GCC
65093 * have trouble with constant propagation and loops.
65094 */
65095-static __always_inline int kmalloc_index(size_t size)
65096+static __always_inline __size_overflow(1) int kmalloc_index(size_t size)
65097 {
65098 if (!size)
65099 return 0;
65100@@ -217,7 +217,7 @@ static __always_inline struct kmem_cache *kmalloc_slab(size_t size)
65101 }
65102
65103 void *kmem_cache_alloc(struct kmem_cache *, gfp_t);
65104-void *__kmalloc(size_t size, gfp_t flags);
65105+void *__kmalloc(size_t size, gfp_t flags) __alloc_size(1) __size_overflow(1);
65106
65107 static __always_inline void *
65108 kmalloc_order(size_t size, gfp_t flags, unsigned int order)
65109@@ -258,7 +258,7 @@ kmalloc_order_trace(size_t size, gfp_t flags, unsigned int order)
65110 }
65111 #endif
65112
65113-static __always_inline void *kmalloc_large(size_t size, gfp_t flags)
65114+static __always_inline __size_overflow(1) void *kmalloc_large(size_t size, gfp_t flags)
65115 {
65116 unsigned int order = get_order(size);
65117 return kmalloc_order_trace(size, flags, order);
65118@@ -283,7 +283,7 @@ static __always_inline void *kmalloc(size_t size, gfp_t flags)
65119 }
65120
65121 #ifdef CONFIG_NUMA
65122-void *__kmalloc_node(size_t size, gfp_t flags, int node);
65123+void *__kmalloc_node(size_t size, gfp_t flags, int node) __size_overflow(1);
65124 void *kmem_cache_alloc_node(struct kmem_cache *, gfp_t flags, int node);
65125
65126 #ifdef CONFIG_TRACING
65127diff --git a/include/linux/sonet.h b/include/linux/sonet.h
65128index de8832d..0147b46 100644
65129--- a/include/linux/sonet.h
65130+++ b/include/linux/sonet.h
65131@@ -61,7 +61,7 @@ struct sonet_stats {
65132 #include <linux/atomic.h>
65133
65134 struct k_sonet_stats {
65135-#define __HANDLE_ITEM(i) atomic_t i
65136+#define __HANDLE_ITEM(i) atomic_unchecked_t i
65137 __SONET_ITEMS
65138 #undef __HANDLE_ITEM
65139 };
65140diff --git a/include/linux/sunrpc/clnt.h b/include/linux/sunrpc/clnt.h
65141index 523547e..2cb7140 100644
65142--- a/include/linux/sunrpc/clnt.h
65143+++ b/include/linux/sunrpc/clnt.h
65144@@ -174,9 +174,9 @@ static inline unsigned short rpc_get_port(const struct sockaddr *sap)
65145 {
65146 switch (sap->sa_family) {
65147 case AF_INET:
65148- return ntohs(((struct sockaddr_in *)sap)->sin_port);
65149+ return ntohs(((const struct sockaddr_in *)sap)->sin_port);
65150 case AF_INET6:
65151- return ntohs(((struct sockaddr_in6 *)sap)->sin6_port);
65152+ return ntohs(((const struct sockaddr_in6 *)sap)->sin6_port);
65153 }
65154 return 0;
65155 }
65156@@ -209,7 +209,7 @@ static inline bool __rpc_cmp_addr4(const struct sockaddr *sap1,
65157 static inline bool __rpc_copy_addr4(struct sockaddr *dst,
65158 const struct sockaddr *src)
65159 {
65160- const struct sockaddr_in *ssin = (struct sockaddr_in *) src;
65161+ const struct sockaddr_in *ssin = (const struct sockaddr_in *) src;
65162 struct sockaddr_in *dsin = (struct sockaddr_in *) dst;
65163
65164 dsin->sin_family = ssin->sin_family;
65165@@ -312,7 +312,7 @@ static inline u32 rpc_get_scope_id(const struct sockaddr *sa)
65166 if (sa->sa_family != AF_INET6)
65167 return 0;
65168
65169- return ((struct sockaddr_in6 *) sa)->sin6_scope_id;
65170+ return ((const struct sockaddr_in6 *) sa)->sin6_scope_id;
65171 }
65172
65173 #endif /* __KERNEL__ */
65174diff --git a/include/linux/sunrpc/sched.h b/include/linux/sunrpc/sched.h
65175index dc0c3cc..8503fb6 100644
65176--- a/include/linux/sunrpc/sched.h
65177+++ b/include/linux/sunrpc/sched.h
65178@@ -106,6 +106,7 @@ struct rpc_call_ops {
65179 void (*rpc_count_stats)(struct rpc_task *, void *);
65180 void (*rpc_release)(void *);
65181 };
65182+typedef struct rpc_call_ops __no_const rpc_call_ops_no_const;
65183
65184 struct rpc_task_setup {
65185 struct rpc_task *task;
65186diff --git a/include/linux/sunrpc/svc_rdma.h b/include/linux/sunrpc/svc_rdma.h
65187index 0b8e3e6..33e0a01 100644
65188--- a/include/linux/sunrpc/svc_rdma.h
65189+++ b/include/linux/sunrpc/svc_rdma.h
65190@@ -53,15 +53,15 @@ extern unsigned int svcrdma_ord;
65191 extern unsigned int svcrdma_max_requests;
65192 extern unsigned int svcrdma_max_req_size;
65193
65194-extern atomic_t rdma_stat_recv;
65195-extern atomic_t rdma_stat_read;
65196-extern atomic_t rdma_stat_write;
65197-extern atomic_t rdma_stat_sq_starve;
65198-extern atomic_t rdma_stat_rq_starve;
65199-extern atomic_t rdma_stat_rq_poll;
65200-extern atomic_t rdma_stat_rq_prod;
65201-extern atomic_t rdma_stat_sq_poll;
65202-extern atomic_t rdma_stat_sq_prod;
65203+extern atomic_unchecked_t rdma_stat_recv;
65204+extern atomic_unchecked_t rdma_stat_read;
65205+extern atomic_unchecked_t rdma_stat_write;
65206+extern atomic_unchecked_t rdma_stat_sq_starve;
65207+extern atomic_unchecked_t rdma_stat_rq_starve;
65208+extern atomic_unchecked_t rdma_stat_rq_poll;
65209+extern atomic_unchecked_t rdma_stat_rq_prod;
65210+extern atomic_unchecked_t rdma_stat_sq_poll;
65211+extern atomic_unchecked_t rdma_stat_sq_prod;
65212
65213 #define RPCRDMA_VERSION 1
65214
65215diff --git a/include/linux/sysctl.h b/include/linux/sysctl.h
65216index c34b4c8..a65b67d 100644
65217--- a/include/linux/sysctl.h
65218+++ b/include/linux/sysctl.h
65219@@ -155,7 +155,11 @@ enum
65220 KERN_PANIC_ON_NMI=76, /* int: whether we will panic on an unrecovered */
65221 };
65222
65223-
65224+#ifdef CONFIG_PAX_SOFTMODE
65225+enum {
65226+ PAX_SOFTMODE=1 /* PaX: disable/enable soft mode */
65227+};
65228+#endif
65229
65230 /* CTL_VM names: */
65231 enum
65232@@ -948,6 +952,8 @@ typedef int proc_handler (struct ctl_table *ctl, int write,
65233
65234 extern int proc_dostring(struct ctl_table *, int,
65235 void __user *, size_t *, loff_t *);
65236+extern int proc_dostring_modpriv(struct ctl_table *, int,
65237+ void __user *, size_t *, loff_t *);
65238 extern int proc_dointvec(struct ctl_table *, int,
65239 void __user *, size_t *, loff_t *);
65240 extern int proc_dointvec_minmax(struct ctl_table *, int,
65241diff --git a/include/linux/tty.h b/include/linux/tty.h
65242index 9f47ab5..73da944 100644
65243--- a/include/linux/tty.h
65244+++ b/include/linux/tty.h
65245@@ -225,7 +225,7 @@ struct tty_port {
65246 const struct tty_port_operations *ops; /* Port operations */
65247 spinlock_t lock; /* Lock protecting tty field */
65248 int blocked_open; /* Waiting to open */
65249- int count; /* Usage count */
65250+ atomic_t count; /* Usage count */
65251 wait_queue_head_t open_wait; /* Open waiters */
65252 wait_queue_head_t close_wait; /* Close waiters */
65253 wait_queue_head_t delta_msr_wait; /* Modem status change */
65254@@ -525,7 +525,7 @@ extern int tty_port_open(struct tty_port *port,
65255 struct tty_struct *tty, struct file *filp);
65256 static inline int tty_port_users(struct tty_port *port)
65257 {
65258- return port->count + port->blocked_open;
65259+ return atomic_read(&port->count) + port->blocked_open;
65260 }
65261
65262 extern int tty_register_ldisc(int disc, struct tty_ldisc_ops *new_ldisc);
65263diff --git a/include/linux/tty_ldisc.h b/include/linux/tty_ldisc.h
65264index fb79dd8d..07d4773 100644
65265--- a/include/linux/tty_ldisc.h
65266+++ b/include/linux/tty_ldisc.h
65267@@ -149,7 +149,7 @@ struct tty_ldisc_ops {
65268
65269 struct module *owner;
65270
65271- int refcount;
65272+ atomic_t refcount;
65273 };
65274
65275 struct tty_ldisc {
65276diff --git a/include/linux/types.h b/include/linux/types.h
65277index bf0dd75..a1f23aaa 100644
65278--- a/include/linux/types.h
65279+++ b/include/linux/types.h
65280@@ -220,10 +220,26 @@ typedef struct {
65281 int counter;
65282 } atomic_t;
65283
65284+#ifdef CONFIG_PAX_REFCOUNT
65285+typedef struct {
65286+ int counter;
65287+} atomic_unchecked_t;
65288+#else
65289+typedef atomic_t atomic_unchecked_t;
65290+#endif
65291+
65292 #ifdef CONFIG_64BIT
65293 typedef struct {
65294 long counter;
65295 } atomic64_t;
65296+
65297+#ifdef CONFIG_PAX_REFCOUNT
65298+typedef struct {
65299+ long counter;
65300+} atomic64_unchecked_t;
65301+#else
65302+typedef atomic64_t atomic64_unchecked_t;
65303+#endif
65304 #endif
65305
65306 struct list_head {
65307diff --git a/include/linux/uaccess.h b/include/linux/uaccess.h
65308index 5ca0951..ab496a5 100644
65309--- a/include/linux/uaccess.h
65310+++ b/include/linux/uaccess.h
65311@@ -76,11 +76,11 @@ static inline unsigned long __copy_from_user_nocache(void *to,
65312 long ret; \
65313 mm_segment_t old_fs = get_fs(); \
65314 \
65315- set_fs(KERNEL_DS); \
65316 pagefault_disable(); \
65317- ret = __copy_from_user_inatomic(&(retval), (__force typeof(retval) __user *)(addr), sizeof(retval)); \
65318- pagefault_enable(); \
65319+ set_fs(KERNEL_DS); \
65320+ ret = __copy_from_user_inatomic(&(retval), (typeof(retval) __force_user *)(addr), sizeof(retval)); \
65321 set_fs(old_fs); \
65322+ pagefault_enable(); \
65323 ret; \
65324 })
65325
65326diff --git a/include/linux/unaligned/access_ok.h b/include/linux/unaligned/access_ok.h
65327index 99c1b4d..bb94261 100644
65328--- a/include/linux/unaligned/access_ok.h
65329+++ b/include/linux/unaligned/access_ok.h
65330@@ -6,32 +6,32 @@
65331
65332 static inline u16 get_unaligned_le16(const void *p)
65333 {
65334- return le16_to_cpup((__le16 *)p);
65335+ return le16_to_cpup((const __le16 *)p);
65336 }
65337
65338 static inline u32 get_unaligned_le32(const void *p)
65339 {
65340- return le32_to_cpup((__le32 *)p);
65341+ return le32_to_cpup((const __le32 *)p);
65342 }
65343
65344 static inline u64 get_unaligned_le64(const void *p)
65345 {
65346- return le64_to_cpup((__le64 *)p);
65347+ return le64_to_cpup((const __le64 *)p);
65348 }
65349
65350 static inline u16 get_unaligned_be16(const void *p)
65351 {
65352- return be16_to_cpup((__be16 *)p);
65353+ return be16_to_cpup((const __be16 *)p);
65354 }
65355
65356 static inline u32 get_unaligned_be32(const void *p)
65357 {
65358- return be32_to_cpup((__be32 *)p);
65359+ return be32_to_cpup((const __be32 *)p);
65360 }
65361
65362 static inline u64 get_unaligned_be64(const void *p)
65363 {
65364- return be64_to_cpup((__be64 *)p);
65365+ return be64_to_cpup((const __be64 *)p);
65366 }
65367
65368 static inline void put_unaligned_le16(u16 val, void *p)
65369diff --git a/include/linux/usb/renesas_usbhs.h b/include/linux/usb/renesas_usbhs.h
65370index c5d36c6..8478c90 100644
65371--- a/include/linux/usb/renesas_usbhs.h
65372+++ b/include/linux/usb/renesas_usbhs.h
65373@@ -39,7 +39,7 @@ enum {
65374 */
65375 struct renesas_usbhs_driver_callback {
65376 int (*notify_hotplug)(struct platform_device *pdev);
65377-};
65378+} __no_const;
65379
65380 /*
65381 * callback functions for platform
65382@@ -97,7 +97,7 @@ struct renesas_usbhs_platform_callback {
65383 * VBUS control is needed for Host
65384 */
65385 int (*set_vbus)(struct platform_device *pdev, int enable);
65386-};
65387+} __no_const;
65388
65389 /*
65390 * parameters for renesas usbhs
65391diff --git a/include/linux/vermagic.h b/include/linux/vermagic.h
65392index 6f8fbcf..8259001 100644
65393--- a/include/linux/vermagic.h
65394+++ b/include/linux/vermagic.h
65395@@ -25,9 +25,35 @@
65396 #define MODULE_ARCH_VERMAGIC ""
65397 #endif
65398
65399+#ifdef CONFIG_PAX_REFCOUNT
65400+#define MODULE_PAX_REFCOUNT "REFCOUNT "
65401+#else
65402+#define MODULE_PAX_REFCOUNT ""
65403+#endif
65404+
65405+#ifdef CONSTIFY_PLUGIN
65406+#define MODULE_CONSTIFY_PLUGIN "CONSTIFY_PLUGIN "
65407+#else
65408+#define MODULE_CONSTIFY_PLUGIN ""
65409+#endif
65410+
65411+#ifdef STACKLEAK_PLUGIN
65412+#define MODULE_STACKLEAK_PLUGIN "STACKLEAK_PLUGIN "
65413+#else
65414+#define MODULE_STACKLEAK_PLUGIN ""
65415+#endif
65416+
65417+#ifdef CONFIG_GRKERNSEC
65418+#define MODULE_GRSEC "GRSEC "
65419+#else
65420+#define MODULE_GRSEC ""
65421+#endif
65422+
65423 #define VERMAGIC_STRING \
65424 UTS_RELEASE " " \
65425 MODULE_VERMAGIC_SMP MODULE_VERMAGIC_PREEMPT \
65426 MODULE_VERMAGIC_MODULE_UNLOAD MODULE_VERMAGIC_MODVERSIONS \
65427- MODULE_ARCH_VERMAGIC
65428+ MODULE_ARCH_VERMAGIC \
65429+ MODULE_PAX_REFCOUNT MODULE_CONSTIFY_PLUGIN MODULE_STACKLEAK_PLUGIN \
65430+ MODULE_GRSEC
65431
65432diff --git a/include/linux/vmalloc.h b/include/linux/vmalloc.h
65433index 6071e91..ca6a489 100644
65434--- a/include/linux/vmalloc.h
65435+++ b/include/linux/vmalloc.h
65436@@ -14,6 +14,11 @@ struct vm_area_struct; /* vma defining user mapping in mm_types.h */
65437 #define VM_USERMAP 0x00000008 /* suitable for remap_vmalloc_range */
65438 #define VM_VPAGES 0x00000010 /* buffer for pages was vmalloc'ed */
65439 #define VM_UNLIST 0x00000020 /* vm_struct is not listed in vmlist */
65440+
65441+#if defined(CONFIG_MODULES) && defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
65442+#define VM_KERNEXEC 0x00000040 /* allocate from executable kernel memory range */
65443+#endif
65444+
65445 /* bits [20..32] reserved for arch specific ioremap internals */
65446
65447 /*
65448@@ -62,7 +67,7 @@ extern void *vmalloc_32_user(unsigned long size);
65449 extern void *__vmalloc(unsigned long size, gfp_t gfp_mask, pgprot_t prot);
65450 extern void *__vmalloc_node_range(unsigned long size, unsigned long align,
65451 unsigned long start, unsigned long end, gfp_t gfp_mask,
65452- pgprot_t prot, int node, const void *caller);
65453+ pgprot_t prot, int node, const void *caller) __size_overflow(1);
65454 extern void vfree(const void *addr);
65455
65456 extern void *vmap(struct page **pages, unsigned int count,
65457@@ -124,8 +129,8 @@ extern struct vm_struct *alloc_vm_area(size_t size, pte_t **ptes);
65458 extern void free_vm_area(struct vm_struct *area);
65459
65460 /* for /dev/kmem */
65461-extern long vread(char *buf, char *addr, unsigned long count);
65462-extern long vwrite(char *buf, char *addr, unsigned long count);
65463+extern long vread(char *buf, char *addr, unsigned long count) __size_overflow(3);
65464+extern long vwrite(char *buf, char *addr, unsigned long count) __size_overflow(3);
65465
65466 /*
65467 * Internals. Dont't use..
65468diff --git a/include/linux/vmstat.h b/include/linux/vmstat.h
65469index ad2cfd5..74c94ad 100644
65470--- a/include/linux/vmstat.h
65471+++ b/include/linux/vmstat.h
65472@@ -87,18 +87,18 @@ static inline void vm_events_fold_cpu(int cpu)
65473 /*
65474 * Zone based page accounting with per cpu differentials.
65475 */
65476-extern atomic_long_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
65477+extern atomic_long_unchecked_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
65478
65479 static inline void zone_page_state_add(long x, struct zone *zone,
65480 enum zone_stat_item item)
65481 {
65482- atomic_long_add(x, &zone->vm_stat[item]);
65483- atomic_long_add(x, &vm_stat[item]);
65484+ atomic_long_add_unchecked(x, &zone->vm_stat[item]);
65485+ atomic_long_add_unchecked(x, &vm_stat[item]);
65486 }
65487
65488 static inline unsigned long global_page_state(enum zone_stat_item item)
65489 {
65490- long x = atomic_long_read(&vm_stat[item]);
65491+ long x = atomic_long_read_unchecked(&vm_stat[item]);
65492 #ifdef CONFIG_SMP
65493 if (x < 0)
65494 x = 0;
65495@@ -109,7 +109,7 @@ static inline unsigned long global_page_state(enum zone_stat_item item)
65496 static inline unsigned long zone_page_state(struct zone *zone,
65497 enum zone_stat_item item)
65498 {
65499- long x = atomic_long_read(&zone->vm_stat[item]);
65500+ long x = atomic_long_read_unchecked(&zone->vm_stat[item]);
65501 #ifdef CONFIG_SMP
65502 if (x < 0)
65503 x = 0;
65504@@ -126,7 +126,7 @@ static inline unsigned long zone_page_state(struct zone *zone,
65505 static inline unsigned long zone_page_state_snapshot(struct zone *zone,
65506 enum zone_stat_item item)
65507 {
65508- long x = atomic_long_read(&zone->vm_stat[item]);
65509+ long x = atomic_long_read_unchecked(&zone->vm_stat[item]);
65510
65511 #ifdef CONFIG_SMP
65512 int cpu;
65513@@ -216,8 +216,8 @@ static inline void __mod_zone_page_state(struct zone *zone,
65514
65515 static inline void __inc_zone_state(struct zone *zone, enum zone_stat_item item)
65516 {
65517- atomic_long_inc(&zone->vm_stat[item]);
65518- atomic_long_inc(&vm_stat[item]);
65519+ atomic_long_inc_unchecked(&zone->vm_stat[item]);
65520+ atomic_long_inc_unchecked(&vm_stat[item]);
65521 }
65522
65523 static inline void __inc_zone_page_state(struct page *page,
65524@@ -228,8 +228,8 @@ static inline void __inc_zone_page_state(struct page *page,
65525
65526 static inline void __dec_zone_state(struct zone *zone, enum zone_stat_item item)
65527 {
65528- atomic_long_dec(&zone->vm_stat[item]);
65529- atomic_long_dec(&vm_stat[item]);
65530+ atomic_long_dec_unchecked(&zone->vm_stat[item]);
65531+ atomic_long_dec_unchecked(&vm_stat[item]);
65532 }
65533
65534 static inline void __dec_zone_page_state(struct page *page,
65535diff --git a/include/linux/xattr.h b/include/linux/xattr.h
65536index e5d1220..ef6e406 100644
65537--- a/include/linux/xattr.h
65538+++ b/include/linux/xattr.h
65539@@ -57,6 +57,11 @@
65540 #define XATTR_POSIX_ACL_DEFAULT "posix_acl_default"
65541 #define XATTR_NAME_POSIX_ACL_DEFAULT XATTR_SYSTEM_PREFIX XATTR_POSIX_ACL_DEFAULT
65542
65543+/* User namespace */
65544+#define XATTR_PAX_PREFIX XATTR_USER_PREFIX "pax."
65545+#define XATTR_PAX_FLAGS_SUFFIX "flags"
65546+#define XATTR_NAME_PAX_FLAGS XATTR_PAX_PREFIX XATTR_PAX_FLAGS_SUFFIX
65547+
65548 #ifdef __KERNEL__
65549
65550 #include <linux/types.h>
65551diff --git a/include/media/saa7146_vv.h b/include/media/saa7146_vv.h
65552index 944ecdf..a3994fc 100644
65553--- a/include/media/saa7146_vv.h
65554+++ b/include/media/saa7146_vv.h
65555@@ -161,8 +161,8 @@ struct saa7146_ext_vv
65556 int (*std_callback)(struct saa7146_dev*, struct saa7146_standard *);
65557
65558 /* the extension can override this */
65559- struct v4l2_ioctl_ops vid_ops;
65560- struct v4l2_ioctl_ops vbi_ops;
65561+ v4l2_ioctl_ops_no_const vid_ops;
65562+ v4l2_ioctl_ops_no_const vbi_ops;
65563 /* pointer to the saa7146 core ops */
65564 const struct v4l2_ioctl_ops *core_ops;
65565
65566diff --git a/include/media/v4l2-dev.h b/include/media/v4l2-dev.h
65567index 5c416cd..20021aa 100644
65568--- a/include/media/v4l2-dev.h
65569+++ b/include/media/v4l2-dev.h
65570@@ -73,7 +73,8 @@ struct v4l2_file_operations {
65571 int (*mmap) (struct file *, struct vm_area_struct *);
65572 int (*open) (struct file *);
65573 int (*release) (struct file *);
65574-};
65575+} __do_const;
65576+typedef struct v4l2_file_operations __no_const v4l2_file_operations_no_const;
65577
65578 /*
65579 * Newer version of video_device, handled by videodev2.c
65580diff --git a/include/media/v4l2-ioctl.h b/include/media/v4l2-ioctl.h
65581index e614c9c..20602b7 100644
65582--- a/include/media/v4l2-ioctl.h
65583+++ b/include/media/v4l2-ioctl.h
65584@@ -289,7 +289,7 @@ struct v4l2_ioctl_ops {
65585 long (*vidioc_default) (struct file *file, void *fh,
65586 bool valid_prio, int cmd, void *arg);
65587 };
65588-
65589+typedef struct v4l2_ioctl_ops __no_const v4l2_ioctl_ops_no_const;
65590
65591 /* v4l debugging and diagnostics */
65592
65593diff --git a/include/net/caif/caif_hsi.h b/include/net/caif/caif_hsi.h
65594index bcb9cc3..f4ec722e 100644
65595--- a/include/net/caif/caif_hsi.h
65596+++ b/include/net/caif/caif_hsi.h
65597@@ -98,7 +98,7 @@ struct cfhsi_cb_ops {
65598 void (*rx_done_cb) (struct cfhsi_cb_ops *drv);
65599 void (*wake_up_cb) (struct cfhsi_cb_ops *drv);
65600 void (*wake_down_cb) (struct cfhsi_cb_ops *drv);
65601-};
65602+} __no_const;
65603
65604 /* Structure implemented by HSI device. */
65605 struct cfhsi_ops {
65606diff --git a/include/net/caif/cfctrl.h b/include/net/caif/cfctrl.h
65607index 9e5425b..8136ffc 100644
65608--- a/include/net/caif/cfctrl.h
65609+++ b/include/net/caif/cfctrl.h
65610@@ -52,7 +52,7 @@ struct cfctrl_rsp {
65611 void (*radioset_rsp)(void);
65612 void (*reject_rsp)(struct cflayer *layer, u8 linkid,
65613 struct cflayer *client_layer);
65614-};
65615+} __no_const;
65616
65617 /* Link Setup Parameters for CAIF-Links. */
65618 struct cfctrl_link_param {
65619@@ -101,8 +101,8 @@ struct cfctrl_request_info {
65620 struct cfctrl {
65621 struct cfsrvl serv;
65622 struct cfctrl_rsp res;
65623- atomic_t req_seq_no;
65624- atomic_t rsp_seq_no;
65625+ atomic_unchecked_t req_seq_no;
65626+ atomic_unchecked_t rsp_seq_no;
65627 struct list_head list;
65628 /* Protects from simultaneous access to first_req list */
65629 spinlock_t info_list_lock;
65630diff --git a/include/net/flow.h b/include/net/flow.h
65631index 628e11b..4c475df 100644
65632--- a/include/net/flow.h
65633+++ b/include/net/flow.h
65634@@ -221,6 +221,6 @@ extern struct flow_cache_object *flow_cache_lookup(
65635
65636 extern void flow_cache_flush(void);
65637 extern void flow_cache_flush_deferred(void);
65638-extern atomic_t flow_cache_genid;
65639+extern atomic_unchecked_t flow_cache_genid;
65640
65641 #endif
65642diff --git a/include/net/inetpeer.h b/include/net/inetpeer.h
65643index 53f464d..ba76aaa 100644
65644--- a/include/net/inetpeer.h
65645+++ b/include/net/inetpeer.h
65646@@ -47,8 +47,8 @@ struct inet_peer {
65647 */
65648 union {
65649 struct {
65650- atomic_t rid; /* Frag reception counter */
65651- atomic_t ip_id_count; /* IP ID for the next packet */
65652+ atomic_unchecked_t rid; /* Frag reception counter */
65653+ atomic_unchecked_t ip_id_count; /* IP ID for the next packet */
65654 };
65655 struct rcu_head rcu;
65656 struct inet_peer *gc_next;
65657@@ -182,11 +182,11 @@ static inline int inet_getid(struct inet_peer *p, int more)
65658 more++;
65659 inet_peer_refcheck(p);
65660 do {
65661- old = atomic_read(&p->ip_id_count);
65662+ old = atomic_read_unchecked(&p->ip_id_count);
65663 new = old + more;
65664 if (!new)
65665 new = 1;
65666- } while (atomic_cmpxchg(&p->ip_id_count, old, new) != old);
65667+ } while (atomic_cmpxchg_unchecked(&p->ip_id_count, old, new) != old);
65668 return new;
65669 }
65670
65671diff --git a/include/net/ip_fib.h b/include/net/ip_fib.h
65672index 9497be1..5a4fafe 100644
65673--- a/include/net/ip_fib.h
65674+++ b/include/net/ip_fib.h
65675@@ -169,7 +169,7 @@ extern __be32 fib_info_update_nh_saddr(struct net *net, struct fib_nh *nh);
65676
65677 #define FIB_RES_SADDR(net, res) \
65678 ((FIB_RES_NH(res).nh_saddr_genid == \
65679- atomic_read(&(net)->ipv4.dev_addr_genid)) ? \
65680+ atomic_read_unchecked(&(net)->ipv4.dev_addr_genid)) ? \
65681 FIB_RES_NH(res).nh_saddr : \
65682 fib_info_update_nh_saddr((net), &FIB_RES_NH(res)))
65683 #define FIB_RES_GW(res) (FIB_RES_NH(res).nh_gw)
65684diff --git a/include/net/ip_vs.h b/include/net/ip_vs.h
65685index 95374d1..2300e36 100644
65686--- a/include/net/ip_vs.h
65687+++ b/include/net/ip_vs.h
65688@@ -510,7 +510,7 @@ struct ip_vs_conn {
65689 struct ip_vs_conn *control; /* Master control connection */
65690 atomic_t n_control; /* Number of controlled ones */
65691 struct ip_vs_dest *dest; /* real server */
65692- atomic_t in_pkts; /* incoming packet counter */
65693+ atomic_unchecked_t in_pkts; /* incoming packet counter */
65694
65695 /* packet transmitter for different forwarding methods. If it
65696 mangles the packet, it must return NF_DROP or better NF_STOLEN,
65697@@ -648,7 +648,7 @@ struct ip_vs_dest {
65698 __be16 port; /* port number of the server */
65699 union nf_inet_addr addr; /* IP address of the server */
65700 volatile unsigned int flags; /* dest status flags */
65701- atomic_t conn_flags; /* flags to copy to conn */
65702+ atomic_unchecked_t conn_flags; /* flags to copy to conn */
65703 atomic_t weight; /* server weight */
65704
65705 atomic_t refcnt; /* reference counter */
65706diff --git a/include/net/irda/ircomm_core.h b/include/net/irda/ircomm_core.h
65707index 69b610a..fe3962c 100644
65708--- a/include/net/irda/ircomm_core.h
65709+++ b/include/net/irda/ircomm_core.h
65710@@ -51,7 +51,7 @@ typedef struct {
65711 int (*connect_response)(struct ircomm_cb *, struct sk_buff *);
65712 int (*disconnect_request)(struct ircomm_cb *, struct sk_buff *,
65713 struct ircomm_info *);
65714-} call_t;
65715+} __no_const call_t;
65716
65717 struct ircomm_cb {
65718 irda_queue_t queue;
65719diff --git a/include/net/irda/ircomm_tty.h b/include/net/irda/ircomm_tty.h
65720index 59ba38bc..d515662 100644
65721--- a/include/net/irda/ircomm_tty.h
65722+++ b/include/net/irda/ircomm_tty.h
65723@@ -35,6 +35,7 @@
65724 #include <linux/termios.h>
65725 #include <linux/timer.h>
65726 #include <linux/tty.h> /* struct tty_struct */
65727+#include <asm/local.h>
65728
65729 #include <net/irda/irias_object.h>
65730 #include <net/irda/ircomm_core.h>
65731@@ -105,8 +106,8 @@ struct ircomm_tty_cb {
65732 unsigned short close_delay;
65733 unsigned short closing_wait; /* time to wait before closing */
65734
65735- int open_count;
65736- int blocked_open; /* # of blocked opens */
65737+ local_t open_count;
65738+ local_t blocked_open; /* # of blocked opens */
65739
65740 /* Protect concurent access to :
65741 * o self->open_count
65742diff --git a/include/net/iucv/af_iucv.h b/include/net/iucv/af_iucv.h
65743index cc7c197..9f2da2a 100644
65744--- a/include/net/iucv/af_iucv.h
65745+++ b/include/net/iucv/af_iucv.h
65746@@ -141,7 +141,7 @@ struct iucv_sock {
65747 struct iucv_sock_list {
65748 struct hlist_head head;
65749 rwlock_t lock;
65750- atomic_t autobind_name;
65751+ atomic_unchecked_t autobind_name;
65752 };
65753
65754 unsigned int iucv_sock_poll(struct file *file, struct socket *sock,
65755diff --git a/include/net/neighbour.h b/include/net/neighbour.h
65756index 344d898..2ae1302 100644
65757--- a/include/net/neighbour.h
65758+++ b/include/net/neighbour.h
65759@@ -123,7 +123,7 @@ struct neigh_ops {
65760 void (*error_report)(struct neighbour *, struct sk_buff *);
65761 int (*output)(struct neighbour *, struct sk_buff *);
65762 int (*connected_output)(struct neighbour *, struct sk_buff *);
65763-};
65764+} __do_const;
65765
65766 struct pneigh_entry {
65767 struct pneigh_entry *next;
65768diff --git a/include/net/net_namespace.h b/include/net/net_namespace.h
65769index fd87963..312a11f 100644
65770--- a/include/net/net_namespace.h
65771+++ b/include/net/net_namespace.h
65772@@ -102,7 +102,7 @@ struct net {
65773 #endif
65774 struct netns_ipvs *ipvs;
65775 struct sock *diag_nlsk;
65776- atomic_t rt_genid;
65777+ atomic_unchecked_t rt_genid;
65778 };
65779
65780
65781@@ -303,12 +303,12 @@ static inline void unregister_net_sysctl_table(struct ctl_table_header *header)
65782
65783 static inline int rt_genid(struct net *net)
65784 {
65785- return atomic_read(&net->rt_genid);
65786+ return atomic_read_unchecked(&net->rt_genid);
65787 }
65788
65789 static inline void rt_genid_bump(struct net *net)
65790 {
65791- atomic_inc(&net->rt_genid);
65792+ atomic_inc_unchecked(&net->rt_genid);
65793 }
65794
65795 #endif /* __NET_NET_NAMESPACE_H */
65796diff --git a/include/net/netdma.h b/include/net/netdma.h
65797index 8ba8ce2..99b7fff 100644
65798--- a/include/net/netdma.h
65799+++ b/include/net/netdma.h
65800@@ -24,7 +24,7 @@
65801 #include <linux/dmaengine.h>
65802 #include <linux/skbuff.h>
65803
65804-int dma_skb_copy_datagram_iovec(struct dma_chan* chan,
65805+int __intentional_overflow(3,5) dma_skb_copy_datagram_iovec(struct dma_chan* chan,
65806 struct sk_buff *skb, int offset, struct iovec *to,
65807 size_t len, struct dma_pinned_list *pinned_list);
65808
65809diff --git a/include/net/netlink.h b/include/net/netlink.h
65810index 785f37a..c81dc0c 100644
65811--- a/include/net/netlink.h
65812+++ b/include/net/netlink.h
65813@@ -520,7 +520,7 @@ static inline void *nlmsg_get_pos(struct sk_buff *skb)
65814 static inline void nlmsg_trim(struct sk_buff *skb, const void *mark)
65815 {
65816 if (mark)
65817- skb_trim(skb, (unsigned char *) mark - skb->data);
65818+ skb_trim(skb, (const unsigned char *) mark - skb->data);
65819 }
65820
65821 /**
65822diff --git a/include/net/netns/ipv4.h b/include/net/netns/ipv4.h
65823index eb24dbc..567d6ed 100644
65824--- a/include/net/netns/ipv4.h
65825+++ b/include/net/netns/ipv4.h
65826@@ -65,7 +65,7 @@ struct netns_ipv4 {
65827 unsigned int sysctl_ping_group_range[2];
65828 long sysctl_tcp_mem[3];
65829
65830- atomic_t dev_addr_genid;
65831+ atomic_unchecked_t dev_addr_genid;
65832
65833 #ifdef CONFIG_IP_MROUTE
65834 #ifndef CONFIG_IP_MROUTE_MULTIPLE_TABLES
65835diff --git a/include/net/sctp/sctp.h b/include/net/sctp/sctp.h
65836index ff49964..1411fee 100644
65837--- a/include/net/sctp/sctp.h
65838+++ b/include/net/sctp/sctp.h
65839@@ -320,9 +320,9 @@ do { \
65840
65841 #else /* SCTP_DEBUG */
65842
65843-#define SCTP_DEBUG_PRINTK(whatever...)
65844-#define SCTP_DEBUG_PRINTK_CONT(fmt, args...)
65845-#define SCTP_DEBUG_PRINTK_IPADDR(whatever...)
65846+#define SCTP_DEBUG_PRINTK(whatever...) do {} while (0)
65847+#define SCTP_DEBUG_PRINTK_CONT(fmt, args...) do {} while (0)
65848+#define SCTP_DEBUG_PRINTK_IPADDR(whatever...) do {} while (0)
65849 #define SCTP_ENABLE_DEBUG
65850 #define SCTP_DISABLE_DEBUG
65851 #define SCTP_ASSERT(expr, str, func)
65852diff --git a/include/net/sock.h b/include/net/sock.h
65853index adb7da2..1100002 100644
65854--- a/include/net/sock.h
65855+++ b/include/net/sock.h
65856@@ -305,7 +305,7 @@ struct sock {
65857 #ifdef CONFIG_RPS
65858 __u32 sk_rxhash;
65859 #endif
65860- atomic_t sk_drops;
65861+ atomic_unchecked_t sk_drops;
65862 int sk_rcvbuf;
65863
65864 struct sk_filter __rcu *sk_filter;
65865@@ -1764,7 +1764,7 @@ static inline void sk_nocaps_add(struct sock *sk, netdev_features_t flags)
65866 }
65867
65868 static inline int skb_do_copy_data_nocache(struct sock *sk, struct sk_buff *skb,
65869- char __user *from, char *to,
65870+ char __user *from, unsigned char *to,
65871 int copy, int offset)
65872 {
65873 if (skb->ip_summed == CHECKSUM_NONE) {
65874@@ -2023,7 +2023,7 @@ static inline void sk_stream_moderate_sndbuf(struct sock *sk)
65875 }
65876 }
65877
65878-struct sk_buff *sk_stream_alloc_skb(struct sock *sk, int size, gfp_t gfp);
65879+struct sk_buff * __intentional_overflow(0) sk_stream_alloc_skb(struct sock *sk, int size, gfp_t gfp);
65880
65881 static inline struct page *sk_stream_alloc_page(struct sock *sk)
65882 {
65883diff --git a/include/net/tcp.h b/include/net/tcp.h
65884index 1f000ff..e5a8dfb 100644
65885--- a/include/net/tcp.h
65886+++ b/include/net/tcp.h
65887@@ -508,7 +508,7 @@ extern void tcp_retransmit_timer(struct sock *sk);
65888 extern void tcp_xmit_retransmit_queue(struct sock *);
65889 extern void tcp_simple_retransmit(struct sock *);
65890 extern int tcp_trim_head(struct sock *, struct sk_buff *, u32);
65891-extern int tcp_fragment(struct sock *, struct sk_buff *, u32, unsigned int);
65892+extern int __intentional_overflow(3) tcp_fragment(struct sock *, struct sk_buff *, u32, unsigned int);
65893
65894 extern void tcp_send_probe0(struct sock *);
65895 extern void tcp_send_partial(struct sock *);
65896@@ -677,8 +677,8 @@ struct tcp_skb_cb {
65897 struct inet6_skb_parm h6;
65898 #endif
65899 } header; /* For incoming frames */
65900- __u32 seq; /* Starting sequence number */
65901- __u32 end_seq; /* SEQ + FIN + SYN + datalen */
65902+ __u32 seq __intentional_overflow(0); /* Starting sequence number */
65903+ __u32 end_seq __intentional_overflow(0); /* SEQ + FIN + SYN + datalen */
65904 __u32 when; /* used to compute rtt's */
65905 __u8 tcp_flags; /* TCP header flags. (tcp[13]) */
65906
65907@@ -692,7 +692,7 @@ struct tcp_skb_cb {
65908
65909 __u8 ip_dsfield; /* IPv4 tos or IPv6 dsfield */
65910 /* 1 byte hole */
65911- __u32 ack_seq; /* Sequence number ACK'd */
65912+ __u32 ack_seq __intentional_overflow(0); /* Sequence number ACK'd */
65913 };
65914
65915 #define TCP_SKB_CB(__skb) ((struct tcp_skb_cb *)&((__skb)->cb[0]))
65916@@ -1502,7 +1502,7 @@ struct tcp_seq_afinfo {
65917 char *name;
65918 sa_family_t family;
65919 const struct file_operations *seq_fops;
65920- struct seq_operations seq_ops;
65921+ seq_operations_no_const seq_ops;
65922 };
65923
65924 struct tcp_iter_state {
65925diff --git a/include/net/udp.h b/include/net/udp.h
65926index 065f379..b661b40 100644
65927--- a/include/net/udp.h
65928+++ b/include/net/udp.h
65929@@ -244,7 +244,7 @@ struct udp_seq_afinfo {
65930 sa_family_t family;
65931 struct udp_table *udp_table;
65932 const struct file_operations *seq_fops;
65933- struct seq_operations seq_ops;
65934+ seq_operations_no_const seq_ops;
65935 };
65936
65937 struct udp_iter_state {
65938diff --git a/include/net/xfrm.h b/include/net/xfrm.h
65939index 639dd13..15b206c 100644
65940--- a/include/net/xfrm.h
65941+++ b/include/net/xfrm.h
65942@@ -514,7 +514,7 @@ struct xfrm_policy {
65943 struct timer_list timer;
65944
65945 struct flow_cache_object flo;
65946- atomic_t genid;
65947+ atomic_unchecked_t genid;
65948 u32 priority;
65949 u32 index;
65950 struct xfrm_mark mark;
65951diff --git a/include/rdma/iw_cm.h b/include/rdma/iw_cm.h
65952index 1a046b1..ee0bef0 100644
65953--- a/include/rdma/iw_cm.h
65954+++ b/include/rdma/iw_cm.h
65955@@ -122,7 +122,7 @@ struct iw_cm_verbs {
65956 int backlog);
65957
65958 int (*destroy_listen)(struct iw_cm_id *cm_id);
65959-};
65960+} __no_const;
65961
65962 /**
65963 * iw_create_cm_id - Create an IW CM identifier.
65964diff --git a/include/scsi/libfc.h b/include/scsi/libfc.h
65965index 399162b..b337f1a 100644
65966--- a/include/scsi/libfc.h
65967+++ b/include/scsi/libfc.h
65968@@ -762,6 +762,7 @@ struct libfc_function_template {
65969 */
65970 void (*disc_stop_final) (struct fc_lport *);
65971 };
65972+typedef struct libfc_function_template __no_const libfc_function_template_no_const;
65973
65974 /**
65975 * struct fc_disc - Discovery context
65976@@ -866,7 +867,7 @@ struct fc_lport {
65977 struct fc_vport *vport;
65978
65979 /* Operational Information */
65980- struct libfc_function_template tt;
65981+ libfc_function_template_no_const tt;
65982 u8 link_up;
65983 u8 qfull;
65984 enum fc_lport_state state;
65985diff --git a/include/scsi/scsi_device.h b/include/scsi/scsi_device.h
65986index 9895f69..f1418f0 100644
65987--- a/include/scsi/scsi_device.h
65988+++ b/include/scsi/scsi_device.h
65989@@ -166,9 +166,9 @@ struct scsi_device {
65990 unsigned int max_device_blocked; /* what device_blocked counts down from */
65991 #define SCSI_DEFAULT_DEVICE_BLOCKED 3
65992
65993- atomic_t iorequest_cnt;
65994- atomic_t iodone_cnt;
65995- atomic_t ioerr_cnt;
65996+ atomic_unchecked_t iorequest_cnt;
65997+ atomic_unchecked_t iodone_cnt;
65998+ atomic_unchecked_t ioerr_cnt;
65999
66000 struct device sdev_gendev,
66001 sdev_dev;
66002diff --git a/include/scsi/scsi_transport_fc.h b/include/scsi/scsi_transport_fc.h
66003index b797e8f..8e2c3aa 100644
66004--- a/include/scsi/scsi_transport_fc.h
66005+++ b/include/scsi/scsi_transport_fc.h
66006@@ -751,7 +751,8 @@ struct fc_function_template {
66007 unsigned long show_host_system_hostname:1;
66008
66009 unsigned long disable_target_scan:1;
66010-};
66011+} __do_const;
66012+typedef struct fc_function_template __no_const fc_function_template_no_const;
66013
66014
66015 /**
66016diff --git a/include/sound/ak4xxx-adda.h b/include/sound/ak4xxx-adda.h
66017index 030b87c..98a6954 100644
66018--- a/include/sound/ak4xxx-adda.h
66019+++ b/include/sound/ak4xxx-adda.h
66020@@ -35,7 +35,7 @@ struct snd_ak4xxx_ops {
66021 void (*write)(struct snd_akm4xxx *ak, int chip, unsigned char reg,
66022 unsigned char val);
66023 void (*set_rate_val)(struct snd_akm4xxx *ak, unsigned int rate);
66024-};
66025+} __no_const;
66026
66027 #define AK4XXX_IMAGE_SIZE (AK4XXX_MAX_CHIPS * 16) /* 64 bytes */
66028
66029diff --git a/include/sound/hwdep.h b/include/sound/hwdep.h
66030index 8c05e47..2b5df97 100644
66031--- a/include/sound/hwdep.h
66032+++ b/include/sound/hwdep.h
66033@@ -49,7 +49,7 @@ struct snd_hwdep_ops {
66034 struct snd_hwdep_dsp_status *status);
66035 int (*dsp_load)(struct snd_hwdep *hw,
66036 struct snd_hwdep_dsp_image *image);
66037-};
66038+} __no_const;
66039
66040 struct snd_hwdep {
66041 struct snd_card *card;
66042diff --git a/include/sound/info.h b/include/sound/info.h
66043index 9ca1a49..aba1728 100644
66044--- a/include/sound/info.h
66045+++ b/include/sound/info.h
66046@@ -44,7 +44,7 @@ struct snd_info_entry_text {
66047 struct snd_info_buffer *buffer);
66048 void (*write)(struct snd_info_entry *entry,
66049 struct snd_info_buffer *buffer);
66050-};
66051+} __no_const;
66052
66053 struct snd_info_entry_ops {
66054 int (*open)(struct snd_info_entry *entry,
66055diff --git a/include/sound/pcm.h b/include/sound/pcm.h
66056index cdca2ab..10bbe05 100644
66057--- a/include/sound/pcm.h
66058+++ b/include/sound/pcm.h
66059@@ -81,6 +81,7 @@ struct snd_pcm_ops {
66060 int (*mmap)(struct snd_pcm_substream *substream, struct vm_area_struct *vma);
66061 int (*ack)(struct snd_pcm_substream *substream);
66062 };
66063+typedef struct snd_pcm_ops __no_const snd_pcm_ops_no_const;
66064
66065 /*
66066 *
66067diff --git a/include/sound/sb16_csp.h b/include/sound/sb16_csp.h
66068index af1b49e..a5d55a5 100644
66069--- a/include/sound/sb16_csp.h
66070+++ b/include/sound/sb16_csp.h
66071@@ -146,7 +146,7 @@ struct snd_sb_csp_ops {
66072 int (*csp_start) (struct snd_sb_csp * p, int sample_width, int channels);
66073 int (*csp_stop) (struct snd_sb_csp * p);
66074 int (*csp_qsound_transfer) (struct snd_sb_csp * p);
66075-};
66076+} __no_const;
66077
66078 /*
66079 * CSP private data
66080diff --git a/include/sound/soc.h b/include/sound/soc.h
66081index e063380..e8077d5 100644
66082--- a/include/sound/soc.h
66083+++ b/include/sound/soc.h
66084@@ -801,7 +801,7 @@ struct snd_soc_platform_driver {
66085 unsigned int (*read)(struct snd_soc_platform *, unsigned int);
66086 int (*write)(struct snd_soc_platform *, unsigned int, unsigned int);
66087 int (*bespoke_trigger)(struct snd_pcm_substream *, int);
66088-};
66089+} __do_const;
66090
66091 struct snd_soc_platform {
66092 const char *name;
66093@@ -1016,7 +1016,7 @@ struct snd_soc_pcm_runtime {
66094 struct snd_soc_dai_link *dai_link;
66095 struct mutex pcm_mutex;
66096 enum snd_soc_pcm_subclass pcm_subclass;
66097- struct snd_pcm_ops ops;
66098+ snd_pcm_ops_no_const ops;
66099
66100 unsigned int dev_registered:1;
66101
66102diff --git a/include/sound/tea575x-tuner.h b/include/sound/tea575x-tuner.h
66103index fe8590c..aaed363 100644
66104--- a/include/sound/tea575x-tuner.h
66105+++ b/include/sound/tea575x-tuner.h
66106@@ -48,7 +48,7 @@ struct snd_tea575x_ops {
66107
66108 struct snd_tea575x {
66109 struct v4l2_device *v4l2_dev;
66110- struct v4l2_file_operations fops;
66111+ v4l2_file_operations_no_const fops;
66112 struct video_device vd; /* video device */
66113 int radio_nr; /* radio_nr */
66114 bool tea5759; /* 5759 chip is present */
66115diff --git a/include/target/target_core_base.h b/include/target/target_core_base.h
66116index 5be8937..a8e46e9 100644
66117--- a/include/target/target_core_base.h
66118+++ b/include/target/target_core_base.h
66119@@ -434,7 +434,7 @@ struct t10_reservation_ops {
66120 int (*t10_seq_non_holder)(struct se_cmd *, unsigned char *, u32);
66121 int (*t10_pr_register)(struct se_cmd *);
66122 int (*t10_pr_clear)(struct se_cmd *);
66123-};
66124+} __no_const;
66125
66126 struct t10_reservation {
66127 /* Reservation effects all target ports */
66128@@ -758,7 +758,7 @@ struct se_device {
66129 spinlock_t stats_lock;
66130 /* Active commands on this virtual SE device */
66131 atomic_t simple_cmds;
66132- atomic_t dev_ordered_id;
66133+ atomic_unchecked_t dev_ordered_id;
66134 atomic_t dev_ordered_sync;
66135 atomic_t dev_qf_count;
66136 struct se_obj dev_obj;
66137diff --git a/include/trace/events/fs.h b/include/trace/events/fs.h
66138new file mode 100644
66139index 0000000..2efe49d
66140--- /dev/null
66141+++ b/include/trace/events/fs.h
66142@@ -0,0 +1,53 @@
66143+#undef TRACE_SYSTEM
66144+#define TRACE_SYSTEM fs
66145+
66146+#if !defined(_TRACE_FS_H) || defined(TRACE_HEADER_MULTI_READ)
66147+#define _TRACE_FS_H
66148+
66149+#include <linux/fs.h>
66150+#include <linux/tracepoint.h>
66151+
66152+TRACE_EVENT(do_sys_open,
66153+
66154+ TP_PROTO(char *filename, int flags, int mode),
66155+
66156+ TP_ARGS(filename, flags, mode),
66157+
66158+ TP_STRUCT__entry(
66159+ __string( filename, filename )
66160+ __field( int, flags )
66161+ __field( int, mode )
66162+ ),
66163+
66164+ TP_fast_assign(
66165+ __assign_str(filename, filename);
66166+ __entry->flags = flags;
66167+ __entry->mode = mode;
66168+ ),
66169+
66170+ TP_printk("\"%s\" %x %o",
66171+ __get_str(filename), __entry->flags, __entry->mode)
66172+);
66173+
66174+TRACE_EVENT(open_exec,
66175+
66176+ TP_PROTO(const char *filename),
66177+
66178+ TP_ARGS(filename),
66179+
66180+ TP_STRUCT__entry(
66181+ __string( filename, filename )
66182+ ),
66183+
66184+ TP_fast_assign(
66185+ __assign_str(filename, filename);
66186+ ),
66187+
66188+ TP_printk("\"%s\"",
66189+ __get_str(filename))
66190+);
66191+
66192+#endif /* _TRACE_FS_H */
66193+
66194+/* This part must be outside protection */
66195+#include <trace/define_trace.h>
66196diff --git a/include/trace/events/irq.h b/include/trace/events/irq.h
66197index 1c09820..7f5ec79 100644
66198--- a/include/trace/events/irq.h
66199+++ b/include/trace/events/irq.h
66200@@ -36,7 +36,7 @@ struct softirq_action;
66201 */
66202 TRACE_EVENT(irq_handler_entry,
66203
66204- TP_PROTO(int irq, struct irqaction *action),
66205+ TP_PROTO(int irq, const struct irqaction *action),
66206
66207 TP_ARGS(irq, action),
66208
66209@@ -66,7 +66,7 @@ TRACE_EVENT(irq_handler_entry,
66210 */
66211 TRACE_EVENT(irq_handler_exit,
66212
66213- TP_PROTO(int irq, struct irqaction *action, int ret),
66214+ TP_PROTO(int irq, const struct irqaction *action, int ret),
66215
66216 TP_ARGS(irq, action, ret),
66217
66218diff --git a/include/video/udlfb.h b/include/video/udlfb.h
66219index f9466fa..f4e2b81 100644
66220--- a/include/video/udlfb.h
66221+++ b/include/video/udlfb.h
66222@@ -53,10 +53,10 @@ struct dlfb_data {
66223 u32 pseudo_palette[256];
66224 int blank_mode; /*one of FB_BLANK_ */
66225 /* blit-only rendering path metrics, exposed through sysfs */
66226- atomic_t bytes_rendered; /* raw pixel-bytes driver asked to render */
66227- atomic_t bytes_identical; /* saved effort with backbuffer comparison */
66228- atomic_t bytes_sent; /* to usb, after compression including overhead */
66229- atomic_t cpu_kcycles_used; /* transpired during pixel processing */
66230+ atomic_unchecked_t bytes_rendered; /* raw pixel-bytes driver asked to render */
66231+ atomic_unchecked_t bytes_identical; /* saved effort with backbuffer comparison */
66232+ atomic_unchecked_t bytes_sent; /* to usb, after compression including overhead */
66233+ atomic_unchecked_t cpu_kcycles_used; /* transpired during pixel processing */
66234 };
66235
66236 #define NR_USB_REQUEST_I2C_SUB_IO 0x02
66237diff --git a/include/video/uvesafb.h b/include/video/uvesafb.h
66238index 0993a22..32ba2fe 100644
66239--- a/include/video/uvesafb.h
66240+++ b/include/video/uvesafb.h
66241@@ -177,6 +177,7 @@ struct uvesafb_par {
66242 u8 ypan; /* 0 - nothing, 1 - ypan, 2 - ywrap */
66243 u8 pmi_setpal; /* PMI for palette changes */
66244 u16 *pmi_base; /* protected mode interface location */
66245+ u8 *pmi_code; /* protected mode code location */
66246 void *pmi_start;
66247 void *pmi_pal;
66248 u8 *vbe_state_orig; /*
66249diff --git a/init/Kconfig b/init/Kconfig
66250index af6c7f8..5c188f8 100644
66251--- a/init/Kconfig
66252+++ b/init/Kconfig
66253@@ -850,6 +850,7 @@ endif # CGROUPS
66254
66255 config CHECKPOINT_RESTORE
66256 bool "Checkpoint/restore support" if EXPERT
66257+ depends on !GRKERNSEC
66258 default n
66259 help
66260 Enables additional kernel features in a sake of checkpoint/restore.
66261@@ -1029,6 +1030,7 @@ config UIDGID_CONVERTED
66262 # Security modules
66263 depends on SECURITY_TOMOYO = n
66264 depends on SECURITY_APPARMOR = n
66265+ depends on GRKERNSEC = n
66266
66267 config UIDGID_STRICT_TYPE_CHECKS
66268 bool "Require conversions between uid/gids and their internal representation"
66269@@ -1416,7 +1418,7 @@ config SLUB_DEBUG
66270
66271 config COMPAT_BRK
66272 bool "Disable heap randomization"
66273- default y
66274+ default n
66275 help
66276 Randomizing heap placement makes heap exploits harder, but it
66277 also breaks ancient binaries (including anything libc5 based).
66278@@ -1599,7 +1601,7 @@ config INIT_ALL_POSSIBLE
66279 config STOP_MACHINE
66280 bool
66281 default y
66282- depends on (SMP && MODULE_UNLOAD) || HOTPLUG_CPU
66283+ depends on (SMP && MODULE_UNLOAD) || HOTPLUG_CPU || GRKERNSEC
66284 help
66285 Need stop_machine() primitive.
66286
66287diff --git a/init/Makefile b/init/Makefile
66288index 7bc47ee..6da2dc7 100644
66289--- a/init/Makefile
66290+++ b/init/Makefile
66291@@ -2,6 +2,9 @@
66292 # Makefile for the linux kernel.
66293 #
66294
66295+ccflags-y := $(GCC_PLUGINS_CFLAGS)
66296+asflags-y := $(GCC_PLUGINS_AFLAGS)
66297+
66298 obj-y := main.o version.o mounts.o
66299 ifneq ($(CONFIG_BLK_DEV_INITRD),y)
66300 obj-y += noinitramfs.o
66301diff --git a/init/do_mounts.c b/init/do_mounts.c
66302index d3f0aee..c9322f5 100644
66303--- a/init/do_mounts.c
66304+++ b/init/do_mounts.c
66305@@ -336,11 +336,11 @@ static void __init get_fs_names(char *page)
66306 static int __init do_mount_root(char *name, char *fs, int flags, void *data)
66307 {
66308 struct super_block *s;
66309- int err = sys_mount(name, "/root", fs, flags, data);
66310+ int err = sys_mount((char __force_user *)name, (char __force_user *)"/root", (char __force_user *)fs, flags, (void __force_user *)data);
66311 if (err)
66312 return err;
66313
66314- sys_chdir("/root");
66315+ sys_chdir((const char __force_user *)"/root");
66316 s = current->fs->pwd.dentry->d_sb;
66317 ROOT_DEV = s->s_dev;
66318 printk(KERN_INFO
66319@@ -460,18 +460,18 @@ void __init change_floppy(char *fmt, ...)
66320 va_start(args, fmt);
66321 vsprintf(buf, fmt, args);
66322 va_end(args);
66323- fd = sys_open("/dev/root", O_RDWR | O_NDELAY, 0);
66324+ fd = sys_open((char __user *)"/dev/root", O_RDWR | O_NDELAY, 0);
66325 if (fd >= 0) {
66326 sys_ioctl(fd, FDEJECT, 0);
66327 sys_close(fd);
66328 }
66329 printk(KERN_NOTICE "VFS: Insert %s and press ENTER\n", buf);
66330- fd = sys_open("/dev/console", O_RDWR, 0);
66331+ fd = sys_open((__force const char __user *)"/dev/console", O_RDWR, 0);
66332 if (fd >= 0) {
66333 sys_ioctl(fd, TCGETS, (long)&termios);
66334 termios.c_lflag &= ~ICANON;
66335 sys_ioctl(fd, TCSETSF, (long)&termios);
66336- sys_read(fd, &c, 1);
66337+ sys_read(fd, (char __user *)&c, 1);
66338 termios.c_lflag |= ICANON;
66339 sys_ioctl(fd, TCSETSF, (long)&termios);
66340 sys_close(fd);
66341@@ -565,6 +565,6 @@ void __init prepare_namespace(void)
66342 mount_root();
66343 out:
66344 devtmpfs_mount("dev");
66345- sys_mount(".", "/", NULL, MS_MOVE, NULL);
66346- sys_chroot(".");
66347+ sys_mount((char __force_user *)".", (char __force_user *)"/", NULL, MS_MOVE, NULL);
66348+ sys_chroot((const char __force_user *)".");
66349 }
66350diff --git a/init/do_mounts.h b/init/do_mounts.h
66351index f5b978a..69dbfe8 100644
66352--- a/init/do_mounts.h
66353+++ b/init/do_mounts.h
66354@@ -15,15 +15,15 @@ extern int root_mountflags;
66355
66356 static inline int create_dev(char *name, dev_t dev)
66357 {
66358- sys_unlink(name);
66359- return sys_mknod(name, S_IFBLK|0600, new_encode_dev(dev));
66360+ sys_unlink((char __force_user *)name);
66361+ return sys_mknod((char __force_user *)name, S_IFBLK|0600, new_encode_dev(dev));
66362 }
66363
66364 #if BITS_PER_LONG == 32
66365 static inline u32 bstat(char *name)
66366 {
66367 struct stat64 stat;
66368- if (sys_stat64(name, &stat) != 0)
66369+ if (sys_stat64((char __force_user *)name, (struct stat64 __force_user *)&stat) != 0)
66370 return 0;
66371 if (!S_ISBLK(stat.st_mode))
66372 return 0;
66373@@ -35,7 +35,7 @@ static inline u32 bstat(char *name)
66374 static inline u32 bstat(char *name)
66375 {
66376 struct stat stat;
66377- if (sys_newstat(name, &stat) != 0)
66378+ if (sys_newstat((const char __force_user *)name, (struct stat __force_user *)&stat) != 0)
66379 return 0;
66380 if (!S_ISBLK(stat.st_mode))
66381 return 0;
66382diff --git a/init/do_mounts_initrd.c b/init/do_mounts_initrd.c
66383index 135959a2..28a3f43 100644
66384--- a/init/do_mounts_initrd.c
66385+++ b/init/do_mounts_initrd.c
66386@@ -53,13 +53,13 @@ static void __init handle_initrd(void)
66387 create_dev("/dev/root.old", Root_RAM0);
66388 /* mount initrd on rootfs' /root */
66389 mount_block_root("/dev/root.old", root_mountflags & ~MS_RDONLY);
66390- sys_mkdir("/old", 0700);
66391- root_fd = sys_open("/", 0, 0);
66392- old_fd = sys_open("/old", 0, 0);
66393+ sys_mkdir((const char __force_user *)"/old", 0700);
66394+ root_fd = sys_open((const char __force_user *)"/", 0, 0);
66395+ old_fd = sys_open((const char __force_user *)"/old", 0, 0);
66396 /* move initrd over / and chdir/chroot in initrd root */
66397- sys_chdir("/root");
66398- sys_mount(".", "/", NULL, MS_MOVE, NULL);
66399- sys_chroot(".");
66400+ sys_chdir((const char __force_user *)"/root");
66401+ sys_mount((char __force_user *)".", (char __force_user *)"/", NULL, MS_MOVE, NULL);
66402+ sys_chroot((const char __force_user *)".");
66403
66404 /*
66405 * In case that a resume from disk is carried out by linuxrc or one of
66406@@ -76,15 +76,15 @@ static void __init handle_initrd(void)
66407
66408 /* move initrd to rootfs' /old */
66409 sys_fchdir(old_fd);
66410- sys_mount("/", ".", NULL, MS_MOVE, NULL);
66411+ sys_mount((char __force_user *)"/", (char __force_user *)".", NULL, MS_MOVE, NULL);
66412 /* switch root and cwd back to / of rootfs */
66413 sys_fchdir(root_fd);
66414- sys_chroot(".");
66415+ sys_chroot((const char __force_user *)".");
66416 sys_close(old_fd);
66417 sys_close(root_fd);
66418
66419 if (new_decode_dev(real_root_dev) == Root_RAM0) {
66420- sys_chdir("/old");
66421+ sys_chdir((const char __force_user *)"/old");
66422 return;
66423 }
66424
66425@@ -92,17 +92,17 @@ static void __init handle_initrd(void)
66426 mount_root();
66427
66428 printk(KERN_NOTICE "Trying to move old root to /initrd ... ");
66429- error = sys_mount("/old", "/root/initrd", NULL, MS_MOVE, NULL);
66430+ error = sys_mount((char __force_user *)"/old", (char __force_user *)"/root/initrd", NULL, MS_MOVE, NULL);
66431 if (!error)
66432 printk("okay\n");
66433 else {
66434- int fd = sys_open("/dev/root.old", O_RDWR, 0);
66435+ int fd = sys_open((const char __force_user *)"/dev/root.old", O_RDWR, 0);
66436 if (error == -ENOENT)
66437 printk("/initrd does not exist. Ignored.\n");
66438 else
66439 printk("failed\n");
66440 printk(KERN_NOTICE "Unmounting old root\n");
66441- sys_umount("/old", MNT_DETACH);
66442+ sys_umount((char __force_user *)"/old", MNT_DETACH);
66443 printk(KERN_NOTICE "Trying to free ramdisk memory ... ");
66444 if (fd < 0) {
66445 error = fd;
66446@@ -125,11 +125,11 @@ int __init initrd_load(void)
66447 * mounted in the normal path.
66448 */
66449 if (rd_load_image("/initrd.image") && ROOT_DEV != Root_RAM0) {
66450- sys_unlink("/initrd.image");
66451+ sys_unlink((const char __force_user *)"/initrd.image");
66452 handle_initrd();
66453 return 1;
66454 }
66455 }
66456- sys_unlink("/initrd.image");
66457+ sys_unlink((const char __force_user *)"/initrd.image");
66458 return 0;
66459 }
66460diff --git a/init/do_mounts_md.c b/init/do_mounts_md.c
66461index 8cb6db5..d729f50 100644
66462--- a/init/do_mounts_md.c
66463+++ b/init/do_mounts_md.c
66464@@ -180,7 +180,7 @@ static void __init md_setup_drive(void)
66465 partitioned ? "_d" : "", minor,
66466 md_setup_args[ent].device_names);
66467
66468- fd = sys_open(name, 0, 0);
66469+ fd = sys_open((char __force_user *)name, 0, 0);
66470 if (fd < 0) {
66471 printk(KERN_ERR "md: open failed - cannot start "
66472 "array %s\n", name);
66473@@ -243,7 +243,7 @@ static void __init md_setup_drive(void)
66474 * array without it
66475 */
66476 sys_close(fd);
66477- fd = sys_open(name, 0, 0);
66478+ fd = sys_open((char __force_user *)name, 0, 0);
66479 sys_ioctl(fd, BLKRRPART, 0);
66480 }
66481 sys_close(fd);
66482@@ -293,7 +293,7 @@ static void __init autodetect_raid(void)
66483
66484 wait_for_device_probe();
66485
66486- fd = sys_open("/dev/md0", 0, 0);
66487+ fd = sys_open((const char __force_user *) "/dev/md0", 0, 0);
66488 if (fd >= 0) {
66489 sys_ioctl(fd, RAID_AUTORUN, raid_autopart);
66490 sys_close(fd);
66491diff --git a/init/init_task.c b/init/init_task.c
66492index 8b2f399..f0797c9 100644
66493--- a/init/init_task.c
66494+++ b/init/init_task.c
66495@@ -20,5 +20,9 @@ EXPORT_SYMBOL(init_task);
66496 * Initial thread structure. Alignment of this is handled by a special
66497 * linker map entry.
66498 */
66499+#ifdef CONFIG_X86
66500+union thread_union init_thread_union __init_task_data;
66501+#else
66502 union thread_union init_thread_union __init_task_data =
66503 { INIT_THREAD_INFO(init_task) };
66504+#endif
66505diff --git a/init/initramfs.c b/init/initramfs.c
66506index 84c6bf1..8899338 100644
66507--- a/init/initramfs.c
66508+++ b/init/initramfs.c
66509@@ -84,7 +84,7 @@ static void __init free_hash(void)
66510 }
66511 }
66512
66513-static long __init do_utime(char *filename, time_t mtime)
66514+static long __init do_utime(char __force_user *filename, time_t mtime)
66515 {
66516 struct timespec t[2];
66517
66518@@ -119,7 +119,7 @@ static void __init dir_utime(void)
66519 struct dir_entry *de, *tmp;
66520 list_for_each_entry_safe(de, tmp, &dir_list, list) {
66521 list_del(&de->list);
66522- do_utime(de->name, de->mtime);
66523+ do_utime((char __force_user *)de->name, de->mtime);
66524 kfree(de->name);
66525 kfree(de);
66526 }
66527@@ -281,7 +281,7 @@ static int __init maybe_link(void)
66528 if (nlink >= 2) {
66529 char *old = find_link(major, minor, ino, mode, collected);
66530 if (old)
66531- return (sys_link(old, collected) < 0) ? -1 : 1;
66532+ return (sys_link((char __force_user *)old, (char __force_user *)collected) < 0) ? -1 : 1;
66533 }
66534 return 0;
66535 }
66536@@ -290,11 +290,11 @@ static void __init clean_path(char *path, umode_t mode)
66537 {
66538 struct stat st;
66539
66540- if (!sys_newlstat(path, &st) && (st.st_mode^mode) & S_IFMT) {
66541+ if (!sys_newlstat((char __force_user *)path, (struct stat __force_user *)&st) && (st.st_mode^mode) & S_IFMT) {
66542 if (S_ISDIR(st.st_mode))
66543- sys_rmdir(path);
66544+ sys_rmdir((char __force_user *)path);
66545 else
66546- sys_unlink(path);
66547+ sys_unlink((char __force_user *)path);
66548 }
66549 }
66550
66551@@ -315,7 +315,7 @@ static int __init do_name(void)
66552 int openflags = O_WRONLY|O_CREAT;
66553 if (ml != 1)
66554 openflags |= O_TRUNC;
66555- wfd = sys_open(collected, openflags, mode);
66556+ wfd = sys_open((char __force_user *)collected, openflags, mode);
66557
66558 if (wfd >= 0) {
66559 sys_fchown(wfd, uid, gid);
66560@@ -327,17 +327,17 @@ static int __init do_name(void)
66561 }
66562 }
66563 } else if (S_ISDIR(mode)) {
66564- sys_mkdir(collected, mode);
66565- sys_chown(collected, uid, gid);
66566- sys_chmod(collected, mode);
66567+ sys_mkdir((char __force_user *)collected, mode);
66568+ sys_chown((char __force_user *)collected, uid, gid);
66569+ sys_chmod((char __force_user *)collected, mode);
66570 dir_add(collected, mtime);
66571 } else if (S_ISBLK(mode) || S_ISCHR(mode) ||
66572 S_ISFIFO(mode) || S_ISSOCK(mode)) {
66573 if (maybe_link() == 0) {
66574- sys_mknod(collected, mode, rdev);
66575- sys_chown(collected, uid, gid);
66576- sys_chmod(collected, mode);
66577- do_utime(collected, mtime);
66578+ sys_mknod((char __force_user *)collected, mode, rdev);
66579+ sys_chown((char __force_user *)collected, uid, gid);
66580+ sys_chmod((char __force_user *)collected, mode);
66581+ do_utime((char __force_user *)collected, mtime);
66582 }
66583 }
66584 return 0;
66585@@ -346,15 +346,15 @@ static int __init do_name(void)
66586 static int __init do_copy(void)
66587 {
66588 if (count >= body_len) {
66589- sys_write(wfd, victim, body_len);
66590+ sys_write(wfd, (char __force_user *)victim, body_len);
66591 sys_close(wfd);
66592- do_utime(vcollected, mtime);
66593+ do_utime((char __force_user *)vcollected, mtime);
66594 kfree(vcollected);
66595 eat(body_len);
66596 state = SkipIt;
66597 return 0;
66598 } else {
66599- sys_write(wfd, victim, count);
66600+ sys_write(wfd, (char __force_user *)victim, count);
66601 body_len -= count;
66602 eat(count);
66603 return 1;
66604@@ -365,9 +365,9 @@ static int __init do_symlink(void)
66605 {
66606 collected[N_ALIGN(name_len) + body_len] = '\0';
66607 clean_path(collected, 0);
66608- sys_symlink(collected + N_ALIGN(name_len), collected);
66609- sys_lchown(collected, uid, gid);
66610- do_utime(collected, mtime);
66611+ sys_symlink((char __force_user *)collected + N_ALIGN(name_len), (char __force_user *)collected);
66612+ sys_lchown((char __force_user *)collected, uid, gid);
66613+ do_utime((char __force_user *)collected, mtime);
66614 state = SkipIt;
66615 next_state = Reset;
66616 return 0;
66617diff --git a/init/main.c b/init/main.c
66618index d61ec54..bd3144f 100644
66619--- a/init/main.c
66620+++ b/init/main.c
66621@@ -96,6 +96,8 @@ static inline void mark_rodata_ro(void) { }
66622 extern void tc_init(void);
66623 #endif
66624
66625+extern void grsecurity_init(void);
66626+
66627 /*
66628 * Debug helper: via this flag we know that we are in 'early bootup code'
66629 * where only the boot processor is running with IRQ disabled. This means
66630@@ -149,6 +151,61 @@ static int __init set_reset_devices(char *str)
66631
66632 __setup("reset_devices", set_reset_devices);
66633
66634+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
66635+int grsec_proc_gid = CONFIG_GRKERNSEC_PROC_GID;
66636+static int __init setup_grsec_proc_gid(char *str)
66637+{
66638+ grsec_proc_gid = (int)simple_strtol(str, NULL, 0);
66639+ return 1;
66640+}
66641+__setup("grsec_proc_gid=", setup_grsec_proc_gid);
66642+#endif
66643+
66644+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
66645+extern char pax_enter_kernel_user[];
66646+extern char pax_exit_kernel_user[];
66647+extern pgdval_t clone_pgd_mask;
66648+#endif
66649+
66650+#if defined(CONFIG_X86) && defined(CONFIG_PAX_MEMORY_UDEREF)
66651+static int __init setup_pax_nouderef(char *str)
66652+{
66653+#ifdef CONFIG_X86_32
66654+ unsigned int cpu;
66655+ struct desc_struct *gdt;
66656+
66657+ for (cpu = 0; cpu < nr_cpu_ids; cpu++) {
66658+ gdt = get_cpu_gdt_table(cpu);
66659+ gdt[GDT_ENTRY_KERNEL_DS].type = 3;
66660+ gdt[GDT_ENTRY_KERNEL_DS].limit = 0xf;
66661+ gdt[GDT_ENTRY_DEFAULT_USER_CS].limit = 0xf;
66662+ gdt[GDT_ENTRY_DEFAULT_USER_DS].limit = 0xf;
66663+ }
66664+ loadsegment(ds, __KERNEL_DS);
66665+ loadsegment(es, __KERNEL_DS);
66666+ loadsegment(ss, __KERNEL_DS);
66667+#else
66668+ memcpy(pax_enter_kernel_user, (unsigned char []){0xc3}, 1);
66669+ memcpy(pax_exit_kernel_user, (unsigned char []){0xc3}, 1);
66670+ clone_pgd_mask = ~(pgdval_t)0UL;
66671+#endif
66672+
66673+ return 0;
66674+}
66675+early_param("pax_nouderef", setup_pax_nouderef);
66676+#endif
66677+
66678+#ifdef CONFIG_PAX_SOFTMODE
66679+int pax_softmode;
66680+
66681+static int __init setup_pax_softmode(char *str)
66682+{
66683+ get_option(&str, &pax_softmode);
66684+ return 1;
66685+}
66686+__setup("pax_softmode=", setup_pax_softmode);
66687+#endif
66688+
66689 static const char * argv_init[MAX_INIT_ARGS+2] = { "init", NULL, };
66690 const char * envp_init[MAX_INIT_ENVS+2] = { "HOME=/", "TERM=linux", NULL, };
66691 static const char *panic_later, *panic_param;
66692@@ -678,6 +735,7 @@ int __init_or_module do_one_initcall(initcall_t fn)
66693 {
66694 int count = preempt_count();
66695 int ret;
66696+ const char *msg1 = "", *msg2 = "";
66697
66698 if (initcall_debug)
66699 ret = do_one_initcall_debug(fn);
66700@@ -690,15 +748,15 @@ int __init_or_module do_one_initcall(initcall_t fn)
66701 sprintf(msgbuf, "error code %d ", ret);
66702
66703 if (preempt_count() != count) {
66704- strlcat(msgbuf, "preemption imbalance ", sizeof(msgbuf));
66705+ msg1 = " preemption imbalance";
66706 preempt_count() = count;
66707 }
66708 if (irqs_disabled()) {
66709- strlcat(msgbuf, "disabled interrupts ", sizeof(msgbuf));
66710+ msg2 = " disabled interrupts";
66711 local_irq_enable();
66712 }
66713- if (msgbuf[0]) {
66714- printk("initcall %pF returned with %s\n", fn, msgbuf);
66715+ if (msgbuf[0] || *msg1 || *msg2) {
66716+ printk("initcall %pF returned with %s%s%s\n", fn, msgbuf, msg1, msg2);
66717 }
66718
66719 return ret;
66720@@ -752,8 +810,14 @@ static void __init do_initcall_level(int level)
66721 level, level,
66722 &repair_env_string);
66723
66724- for (fn = initcall_levels[level]; fn < initcall_levels[level+1]; fn++)
66725+ for (fn = initcall_levels[level]; fn < initcall_levels[level+1]; fn++) {
66726 do_one_initcall(*fn);
66727+
66728+#ifdef CONFIG_PAX_LATENT_ENTROPY
66729+ transfer_latent_entropy();
66730+#endif
66731+
66732+ }
66733 }
66734
66735 static void __init do_initcalls(void)
66736@@ -787,8 +851,14 @@ static void __init do_pre_smp_initcalls(void)
66737 {
66738 initcall_t *fn;
66739
66740- for (fn = __initcall_start; fn < __initcall0_start; fn++)
66741+ for (fn = __initcall_start; fn < __initcall0_start; fn++) {
66742 do_one_initcall(*fn);
66743+
66744+#ifdef CONFIG_PAX_LATENT_ENTROPY
66745+ transfer_latent_entropy();
66746+#endif
66747+
66748+ }
66749 }
66750
66751 static void run_init_process(const char *init_filename)
66752@@ -870,7 +940,7 @@ static int __init kernel_init(void * unused)
66753 do_basic_setup();
66754
66755 /* Open the /dev/console on the rootfs, this should never fail */
66756- if (sys_open((const char __user *) "/dev/console", O_RDWR, 0) < 0)
66757+ if (sys_open((const char __force_user *) "/dev/console", O_RDWR, 0) < 0)
66758 printk(KERN_WARNING "Warning: unable to open an initial console.\n");
66759
66760 (void) sys_dup(0);
66761@@ -883,11 +953,13 @@ static int __init kernel_init(void * unused)
66762 if (!ramdisk_execute_command)
66763 ramdisk_execute_command = "/init";
66764
66765- if (sys_access((const char __user *) ramdisk_execute_command, 0) != 0) {
66766+ if (sys_access((const char __force_user *) ramdisk_execute_command, 0) != 0) {
66767 ramdisk_execute_command = NULL;
66768 prepare_namespace();
66769 }
66770
66771+ grsecurity_init();
66772+
66773 /*
66774 * Ok, we have completed the initial bootup, and
66775 * we're essentially up and running. Get rid of the
66776diff --git a/ipc/mqueue.c b/ipc/mqueue.c
66777index 9a08acc..e65ebe7 100644
66778--- a/ipc/mqueue.c
66779+++ b/ipc/mqueue.c
66780@@ -279,6 +279,7 @@ static struct inode *mqueue_get_inode(struct super_block *sb,
66781 mq_bytes = mq_treesize + (info->attr.mq_maxmsg *
66782 info->attr.mq_msgsize);
66783
66784+ gr_learn_resource(current, RLIMIT_MSGQUEUE, u->mq_bytes + mq_bytes, 1);
66785 spin_lock(&mq_lock);
66786 if (u->mq_bytes + mq_bytes < u->mq_bytes ||
66787 u->mq_bytes + mq_bytes > rlimit(RLIMIT_MSGQUEUE)) {
66788diff --git a/ipc/msg.c b/ipc/msg.c
66789index 7385de2..a8180e08 100644
66790--- a/ipc/msg.c
66791+++ b/ipc/msg.c
66792@@ -309,18 +309,19 @@ static inline int msg_security(struct kern_ipc_perm *ipcp, int msgflg)
66793 return security_msg_queue_associate(msq, msgflg);
66794 }
66795
66796+static struct ipc_ops msg_ops = {
66797+ .getnew = newque,
66798+ .associate = msg_security,
66799+ .more_checks = NULL
66800+};
66801+
66802 SYSCALL_DEFINE2(msgget, key_t, key, int, msgflg)
66803 {
66804 struct ipc_namespace *ns;
66805- struct ipc_ops msg_ops;
66806 struct ipc_params msg_params;
66807
66808 ns = current->nsproxy->ipc_ns;
66809
66810- msg_ops.getnew = newque;
66811- msg_ops.associate = msg_security;
66812- msg_ops.more_checks = NULL;
66813-
66814 msg_params.key = key;
66815 msg_params.flg = msgflg;
66816
66817diff --git a/ipc/sem.c b/ipc/sem.c
66818index 5215a81..cfc0cac 100644
66819--- a/ipc/sem.c
66820+++ b/ipc/sem.c
66821@@ -364,10 +364,15 @@ static inline int sem_more_checks(struct kern_ipc_perm *ipcp,
66822 return 0;
66823 }
66824
66825+static struct ipc_ops sem_ops = {
66826+ .getnew = newary,
66827+ .associate = sem_security,
66828+ .more_checks = sem_more_checks
66829+};
66830+
66831 SYSCALL_DEFINE3(semget, key_t, key, int, nsems, int, semflg)
66832 {
66833 struct ipc_namespace *ns;
66834- struct ipc_ops sem_ops;
66835 struct ipc_params sem_params;
66836
66837 ns = current->nsproxy->ipc_ns;
66838@@ -375,10 +380,6 @@ SYSCALL_DEFINE3(semget, key_t, key, int, nsems, int, semflg)
66839 if (nsems < 0 || nsems > ns->sc_semmsl)
66840 return -EINVAL;
66841
66842- sem_ops.getnew = newary;
66843- sem_ops.associate = sem_security;
66844- sem_ops.more_checks = sem_more_checks;
66845-
66846 sem_params.key = key;
66847 sem_params.flg = semflg;
66848 sem_params.u.nsems = nsems;
66849diff --git a/ipc/shm.c b/ipc/shm.c
66850index 00faa05..7040960 100644
66851--- a/ipc/shm.c
66852+++ b/ipc/shm.c
66853@@ -69,6 +69,14 @@ static void shm_destroy (struct ipc_namespace *ns, struct shmid_kernel *shp);
66854 static int sysvipc_shm_proc_show(struct seq_file *s, void *it);
66855 #endif
66856
66857+#ifdef CONFIG_GRKERNSEC
66858+extern int gr_handle_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
66859+ const time_t shm_createtime, const uid_t cuid,
66860+ const int shmid);
66861+extern int gr_chroot_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
66862+ const time_t shm_createtime);
66863+#endif
66864+
66865 void shm_init_ns(struct ipc_namespace *ns)
66866 {
66867 ns->shm_ctlmax = SHMMAX;
66868@@ -520,6 +528,14 @@ static int newseg(struct ipc_namespace *ns, struct ipc_params *params)
66869 shp->shm_lprid = 0;
66870 shp->shm_atim = shp->shm_dtim = 0;
66871 shp->shm_ctim = get_seconds();
66872+#ifdef CONFIG_GRKERNSEC
66873+ {
66874+ struct timespec timeval;
66875+ do_posix_clock_monotonic_gettime(&timeval);
66876+
66877+ shp->shm_createtime = timeval.tv_sec;
66878+ }
66879+#endif
66880 shp->shm_segsz = size;
66881 shp->shm_nattch = 0;
66882 shp->shm_file = file;
66883@@ -571,18 +587,19 @@ static inline int shm_more_checks(struct kern_ipc_perm *ipcp,
66884 return 0;
66885 }
66886
66887+static struct ipc_ops shm_ops = {
66888+ .getnew = newseg,
66889+ .associate = shm_security,
66890+ .more_checks = shm_more_checks
66891+};
66892+
66893 SYSCALL_DEFINE3(shmget, key_t, key, size_t, size, int, shmflg)
66894 {
66895 struct ipc_namespace *ns;
66896- struct ipc_ops shm_ops;
66897 struct ipc_params shm_params;
66898
66899 ns = current->nsproxy->ipc_ns;
66900
66901- shm_ops.getnew = newseg;
66902- shm_ops.associate = shm_security;
66903- shm_ops.more_checks = shm_more_checks;
66904-
66905 shm_params.key = key;
66906 shm_params.flg = shmflg;
66907 shm_params.u.size = size;
66908@@ -1001,6 +1018,12 @@ long do_shmat(int shmid, char __user *shmaddr, int shmflg, ulong *raddr,
66909 f_mode = FMODE_READ | FMODE_WRITE;
66910 }
66911 if (shmflg & SHM_EXEC) {
66912+
66913+#ifdef CONFIG_PAX_MPROTECT
66914+ if (current->mm->pax_flags & MF_PAX_MPROTECT)
66915+ goto out;
66916+#endif
66917+
66918 prot |= PROT_EXEC;
66919 acc_mode |= S_IXUGO;
66920 }
66921@@ -1024,9 +1047,21 @@ long do_shmat(int shmid, char __user *shmaddr, int shmflg, ulong *raddr,
66922 if (err)
66923 goto out_unlock;
66924
66925+#ifdef CONFIG_GRKERNSEC
66926+ if (!gr_handle_shmat(shp->shm_cprid, shp->shm_lapid, shp->shm_createtime,
66927+ shp->shm_perm.cuid, shmid) ||
66928+ !gr_chroot_shmat(shp->shm_cprid, shp->shm_lapid, shp->shm_createtime)) {
66929+ err = -EACCES;
66930+ goto out_unlock;
66931+ }
66932+#endif
66933+
66934 path = shp->shm_file->f_path;
66935 path_get(&path);
66936 shp->shm_nattch++;
66937+#ifdef CONFIG_GRKERNSEC
66938+ shp->shm_lapid = current->pid;
66939+#endif
66940 size = i_size_read(path.dentry->d_inode);
66941 shm_unlock(shp);
66942
66943diff --git a/kernel/acct.c b/kernel/acct.c
66944index 02e6167..54824f7 100644
66945--- a/kernel/acct.c
66946+++ b/kernel/acct.c
66947@@ -550,7 +550,7 @@ static void do_acct_process(struct bsd_acct_struct *acct,
66948 */
66949 flim = current->signal->rlim[RLIMIT_FSIZE].rlim_cur;
66950 current->signal->rlim[RLIMIT_FSIZE].rlim_cur = RLIM_INFINITY;
66951- file->f_op->write(file, (char *)&ac,
66952+ file->f_op->write(file, (char __force_user *)&ac,
66953 sizeof(acct_t), &file->f_pos);
66954 current->signal->rlim[RLIMIT_FSIZE].rlim_cur = flim;
66955 set_fs(fs);
66956diff --git a/kernel/audit.c b/kernel/audit.c
66957index a8c84be..8bd034c 100644
66958--- a/kernel/audit.c
66959+++ b/kernel/audit.c
66960@@ -115,7 +115,7 @@ u32 audit_sig_sid = 0;
66961 3) suppressed due to audit_rate_limit
66962 4) suppressed due to audit_backlog_limit
66963 */
66964-static atomic_t audit_lost = ATOMIC_INIT(0);
66965+static atomic_unchecked_t audit_lost = ATOMIC_INIT(0);
66966
66967 /* The netlink socket. */
66968 static struct sock *audit_sock;
66969@@ -237,7 +237,7 @@ void audit_log_lost(const char *message)
66970 unsigned long now;
66971 int print;
66972
66973- atomic_inc(&audit_lost);
66974+ atomic_inc_unchecked(&audit_lost);
66975
66976 print = (audit_failure == AUDIT_FAIL_PANIC || !audit_rate_limit);
66977
66978@@ -256,7 +256,7 @@ void audit_log_lost(const char *message)
66979 printk(KERN_WARNING
66980 "audit: audit_lost=%d audit_rate_limit=%d "
66981 "audit_backlog_limit=%d\n",
66982- atomic_read(&audit_lost),
66983+ atomic_read_unchecked(&audit_lost),
66984 audit_rate_limit,
66985 audit_backlog_limit);
66986 audit_panic(message);
66987@@ -690,7 +690,7 @@ static int audit_receive_msg(struct sk_buff *skb, struct nlmsghdr *nlh)
66988 status_set.pid = audit_pid;
66989 status_set.rate_limit = audit_rate_limit;
66990 status_set.backlog_limit = audit_backlog_limit;
66991- status_set.lost = atomic_read(&audit_lost);
66992+ status_set.lost = atomic_read_unchecked(&audit_lost);
66993 status_set.backlog = skb_queue_len(&audit_skb_queue);
66994 audit_send_reply(NETLINK_CB(skb).pid, seq, AUDIT_GET, 0, 0,
66995 &status_set, sizeof(status_set));
66996diff --git a/kernel/auditsc.c b/kernel/auditsc.c
66997index 4b96415..d8c16ee 100644
66998--- a/kernel/auditsc.c
66999+++ b/kernel/auditsc.c
67000@@ -2289,7 +2289,7 @@ int auditsc_get_stamp(struct audit_context *ctx,
67001 }
67002
67003 /* global counter which is incremented every time something logs in */
67004-static atomic_t session_id = ATOMIC_INIT(0);
67005+static atomic_unchecked_t session_id = ATOMIC_INIT(0);
67006
67007 /**
67008 * audit_set_loginuid - set current task's audit_context loginuid
67009@@ -2313,7 +2313,7 @@ int audit_set_loginuid(uid_t loginuid)
67010 return -EPERM;
67011 #endif /* CONFIG_AUDIT_LOGINUID_IMMUTABLE */
67012
67013- sessionid = atomic_inc_return(&session_id);
67014+ sessionid = atomic_inc_return_unchecked(&session_id);
67015 if (context && context->in_syscall) {
67016 struct audit_buffer *ab;
67017
67018diff --git a/kernel/capability.c b/kernel/capability.c
67019index 493d972..ea17248 100644
67020--- a/kernel/capability.c
67021+++ b/kernel/capability.c
67022@@ -202,6 +202,9 @@ SYSCALL_DEFINE2(capget, cap_user_header_t, header, cap_user_data_t, dataptr)
67023 * before modification is attempted and the application
67024 * fails.
67025 */
67026+ if (tocopy > ARRAY_SIZE(kdata))
67027+ return -EFAULT;
67028+
67029 if (copy_to_user(dataptr, kdata, tocopy
67030 * sizeof(struct __user_cap_data_struct))) {
67031 return -EFAULT;
67032@@ -303,10 +306,11 @@ bool has_ns_capability(struct task_struct *t,
67033 int ret;
67034
67035 rcu_read_lock();
67036- ret = security_capable(__task_cred(t), ns, cap);
67037+ ret = security_capable(__task_cred(t), ns, cap) == 0 &&
67038+ gr_task_is_capable(t, __task_cred(t), cap);
67039 rcu_read_unlock();
67040
67041- return (ret == 0);
67042+ return ret;
67043 }
67044
67045 /**
67046@@ -343,10 +347,10 @@ bool has_ns_capability_noaudit(struct task_struct *t,
67047 int ret;
67048
67049 rcu_read_lock();
67050- ret = security_capable_noaudit(__task_cred(t), ns, cap);
67051+ ret = security_capable_noaudit(__task_cred(t), ns, cap) == 0 && gr_task_is_capable_nolog(t, cap);
67052 rcu_read_unlock();
67053
67054- return (ret == 0);
67055+ return ret;
67056 }
67057
67058 /**
67059@@ -384,7 +388,7 @@ bool ns_capable(struct user_namespace *ns, int cap)
67060 BUG();
67061 }
67062
67063- if (security_capable(current_cred(), ns, cap) == 0) {
67064+ if (security_capable(current_cred(), ns, cap) == 0 && gr_is_capable(cap)) {
67065 current->flags |= PF_SUPERPRIV;
67066 return true;
67067 }
67068@@ -392,6 +396,21 @@ bool ns_capable(struct user_namespace *ns, int cap)
67069 }
67070 EXPORT_SYMBOL(ns_capable);
67071
67072+bool ns_capable_nolog(struct user_namespace *ns, int cap)
67073+{
67074+ if (unlikely(!cap_valid(cap))) {
67075+ printk(KERN_CRIT "capable() called with invalid cap=%u\n", cap);
67076+ BUG();
67077+ }
67078+
67079+ if (security_capable(current_cred(), ns, cap) == 0 && gr_is_capable_nolog(cap)) {
67080+ current->flags |= PF_SUPERPRIV;
67081+ return true;
67082+ }
67083+ return false;
67084+}
67085+EXPORT_SYMBOL(ns_capable_nolog);
67086+
67087 /**
67088 * capable - Determine if the current task has a superior capability in effect
67089 * @cap: The capability to be tested for
67090@@ -408,6 +427,12 @@ bool capable(int cap)
67091 }
67092 EXPORT_SYMBOL(capable);
67093
67094+bool capable_nolog(int cap)
67095+{
67096+ return ns_capable_nolog(&init_user_ns, cap);
67097+}
67098+EXPORT_SYMBOL(capable_nolog);
67099+
67100 /**
67101 * nsown_capable - Check superior capability to one's own user_ns
67102 * @cap: The capability in question
67103@@ -440,3 +465,10 @@ bool inode_capable(const struct inode *inode, int cap)
67104
67105 return ns_capable(ns, cap) && kuid_has_mapping(ns, inode->i_uid);
67106 }
67107+
67108+bool inode_capable_nolog(const struct inode *inode, int cap)
67109+{
67110+ struct user_namespace *ns = current_user_ns();
67111+
67112+ return ns_capable_nolog(ns, cap) && kuid_has_mapping(ns, inode->i_uid);
67113+}
67114diff --git a/kernel/cgroup.c b/kernel/cgroup.c
67115index ff2bce5..a41e8f9 100644
67116--- a/kernel/cgroup.c
67117+++ b/kernel/cgroup.c
67118@@ -5390,7 +5390,7 @@ static int cgroup_css_links_read(struct cgroup *cont,
67119 struct css_set *cg = link->cg;
67120 struct task_struct *task;
67121 int count = 0;
67122- seq_printf(seq, "css_set %p\n", cg);
67123+ seq_printf(seq, "css_set %pK\n", cg);
67124 list_for_each_entry(task, &cg->tasks, cg_list) {
67125 if (count++ > MAX_TASKS_SHOWN_PER_CSS) {
67126 seq_puts(seq, " ...\n");
67127diff --git a/kernel/compat.c b/kernel/compat.c
67128index c28a306..b4d0cf3 100644
67129--- a/kernel/compat.c
67130+++ b/kernel/compat.c
67131@@ -13,6 +13,7 @@
67132
67133 #include <linux/linkage.h>
67134 #include <linux/compat.h>
67135+#include <linux/module.h>
67136 #include <linux/errno.h>
67137 #include <linux/time.h>
67138 #include <linux/signal.h>
67139@@ -220,7 +221,7 @@ static long compat_nanosleep_restart(struct restart_block *restart)
67140 mm_segment_t oldfs;
67141 long ret;
67142
67143- restart->nanosleep.rmtp = (struct timespec __user *) &rmt;
67144+ restart->nanosleep.rmtp = (struct timespec __force_user *) &rmt;
67145 oldfs = get_fs();
67146 set_fs(KERNEL_DS);
67147 ret = hrtimer_nanosleep_restart(restart);
67148@@ -252,7 +253,7 @@ asmlinkage long compat_sys_nanosleep(struct compat_timespec __user *rqtp,
67149 oldfs = get_fs();
67150 set_fs(KERNEL_DS);
67151 ret = hrtimer_nanosleep(&tu,
67152- rmtp ? (struct timespec __user *)&rmt : NULL,
67153+ rmtp ? (struct timespec __force_user *)&rmt : NULL,
67154 HRTIMER_MODE_REL, CLOCK_MONOTONIC);
67155 set_fs(oldfs);
67156
67157@@ -361,7 +362,7 @@ asmlinkage long compat_sys_sigpending(compat_old_sigset_t __user *set)
67158 mm_segment_t old_fs = get_fs();
67159
67160 set_fs(KERNEL_DS);
67161- ret = sys_sigpending((old_sigset_t __user *) &s);
67162+ ret = sys_sigpending((old_sigset_t __force_user *) &s);
67163 set_fs(old_fs);
67164 if (ret == 0)
67165 ret = put_user(s, set);
67166@@ -451,7 +452,7 @@ asmlinkage long compat_sys_old_getrlimit(unsigned int resource,
67167 mm_segment_t old_fs = get_fs();
67168
67169 set_fs(KERNEL_DS);
67170- ret = sys_old_getrlimit(resource, &r);
67171+ ret = sys_old_getrlimit(resource, (struct rlimit __force_user *)&r);
67172 set_fs(old_fs);
67173
67174 if (!ret) {
67175@@ -523,7 +524,7 @@ asmlinkage long compat_sys_getrusage(int who, struct compat_rusage __user *ru)
67176 mm_segment_t old_fs = get_fs();
67177
67178 set_fs(KERNEL_DS);
67179- ret = sys_getrusage(who, (struct rusage __user *) &r);
67180+ ret = sys_getrusage(who, (struct rusage __force_user *) &r);
67181 set_fs(old_fs);
67182
67183 if (ret)
67184@@ -550,8 +551,8 @@ compat_sys_wait4(compat_pid_t pid, compat_uint_t __user *stat_addr, int options,
67185 set_fs (KERNEL_DS);
67186 ret = sys_wait4(pid,
67187 (stat_addr ?
67188- (unsigned int __user *) &status : NULL),
67189- options, (struct rusage __user *) &r);
67190+ (unsigned int __force_user *) &status : NULL),
67191+ options, (struct rusage __force_user *) &r);
67192 set_fs (old_fs);
67193
67194 if (ret > 0) {
67195@@ -576,8 +577,8 @@ asmlinkage long compat_sys_waitid(int which, compat_pid_t pid,
67196 memset(&info, 0, sizeof(info));
67197
67198 set_fs(KERNEL_DS);
67199- ret = sys_waitid(which, pid, (siginfo_t __user *)&info, options,
67200- uru ? (struct rusage __user *)&ru : NULL);
67201+ ret = sys_waitid(which, pid, (siginfo_t __force_user *)&info, options,
67202+ uru ? (struct rusage __force_user *)&ru : NULL);
67203 set_fs(old_fs);
67204
67205 if ((ret < 0) || (info.si_signo == 0))
67206@@ -707,8 +708,8 @@ long compat_sys_timer_settime(timer_t timer_id, int flags,
67207 oldfs = get_fs();
67208 set_fs(KERNEL_DS);
67209 err = sys_timer_settime(timer_id, flags,
67210- (struct itimerspec __user *) &newts,
67211- (struct itimerspec __user *) &oldts);
67212+ (struct itimerspec __force_user *) &newts,
67213+ (struct itimerspec __force_user *) &oldts);
67214 set_fs(oldfs);
67215 if (!err && old && put_compat_itimerspec(old, &oldts))
67216 return -EFAULT;
67217@@ -725,7 +726,7 @@ long compat_sys_timer_gettime(timer_t timer_id,
67218 oldfs = get_fs();
67219 set_fs(KERNEL_DS);
67220 err = sys_timer_gettime(timer_id,
67221- (struct itimerspec __user *) &ts);
67222+ (struct itimerspec __force_user *) &ts);
67223 set_fs(oldfs);
67224 if (!err && put_compat_itimerspec(setting, &ts))
67225 return -EFAULT;
67226@@ -744,7 +745,7 @@ long compat_sys_clock_settime(clockid_t which_clock,
67227 oldfs = get_fs();
67228 set_fs(KERNEL_DS);
67229 err = sys_clock_settime(which_clock,
67230- (struct timespec __user *) &ts);
67231+ (struct timespec __force_user *) &ts);
67232 set_fs(oldfs);
67233 return err;
67234 }
67235@@ -759,7 +760,7 @@ long compat_sys_clock_gettime(clockid_t which_clock,
67236 oldfs = get_fs();
67237 set_fs(KERNEL_DS);
67238 err = sys_clock_gettime(which_clock,
67239- (struct timespec __user *) &ts);
67240+ (struct timespec __force_user *) &ts);
67241 set_fs(oldfs);
67242 if (!err && put_compat_timespec(&ts, tp))
67243 return -EFAULT;
67244@@ -779,7 +780,7 @@ long compat_sys_clock_adjtime(clockid_t which_clock,
67245
67246 oldfs = get_fs();
67247 set_fs(KERNEL_DS);
67248- ret = sys_clock_adjtime(which_clock, (struct timex __user *) &txc);
67249+ ret = sys_clock_adjtime(which_clock, (struct timex __force_user *) &txc);
67250 set_fs(oldfs);
67251
67252 err = compat_put_timex(utp, &txc);
67253@@ -799,7 +800,7 @@ long compat_sys_clock_getres(clockid_t which_clock,
67254 oldfs = get_fs();
67255 set_fs(KERNEL_DS);
67256 err = sys_clock_getres(which_clock,
67257- (struct timespec __user *) &ts);
67258+ (struct timespec __force_user *) &ts);
67259 set_fs(oldfs);
67260 if (!err && tp && put_compat_timespec(&ts, tp))
67261 return -EFAULT;
67262@@ -811,9 +812,9 @@ static long compat_clock_nanosleep_restart(struct restart_block *restart)
67263 long err;
67264 mm_segment_t oldfs;
67265 struct timespec tu;
67266- struct compat_timespec *rmtp = restart->nanosleep.compat_rmtp;
67267+ struct compat_timespec __user *rmtp = restart->nanosleep.compat_rmtp;
67268
67269- restart->nanosleep.rmtp = (struct timespec __user *) &tu;
67270+ restart->nanosleep.rmtp = (struct timespec __force_user *) &tu;
67271 oldfs = get_fs();
67272 set_fs(KERNEL_DS);
67273 err = clock_nanosleep_restart(restart);
67274@@ -845,8 +846,8 @@ long compat_sys_clock_nanosleep(clockid_t which_clock, int flags,
67275 oldfs = get_fs();
67276 set_fs(KERNEL_DS);
67277 err = sys_clock_nanosleep(which_clock, flags,
67278- (struct timespec __user *) &in,
67279- (struct timespec __user *) &out);
67280+ (struct timespec __force_user *) &in,
67281+ (struct timespec __force_user *) &out);
67282 set_fs(oldfs);
67283
67284 if ((err == -ERESTART_RESTARTBLOCK) && rmtp &&
67285diff --git a/kernel/configs.c b/kernel/configs.c
67286index 42e8fa0..9e7406b 100644
67287--- a/kernel/configs.c
67288+++ b/kernel/configs.c
67289@@ -74,8 +74,19 @@ static int __init ikconfig_init(void)
67290 struct proc_dir_entry *entry;
67291
67292 /* create the current config file */
67293+#if defined(CONFIG_GRKERNSEC_PROC_ADD) || defined(CONFIG_GRKERNSEC_HIDESYM)
67294+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_HIDESYM)
67295+ entry = proc_create("config.gz", S_IFREG | S_IRUSR, NULL,
67296+ &ikconfig_file_ops);
67297+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
67298+ entry = proc_create("config.gz", S_IFREG | S_IRUSR | S_IRGRP, NULL,
67299+ &ikconfig_file_ops);
67300+#endif
67301+#else
67302 entry = proc_create("config.gz", S_IFREG | S_IRUGO, NULL,
67303 &ikconfig_file_ops);
67304+#endif
67305+
67306 if (!entry)
67307 return -ENOMEM;
67308
67309diff --git a/kernel/cred.c b/kernel/cred.c
67310index de728ac..e3c267c 100644
67311--- a/kernel/cred.c
67312+++ b/kernel/cred.c
67313@@ -207,6 +207,16 @@ void exit_creds(struct task_struct *tsk)
67314 validate_creds(cred);
67315 alter_cred_subscribers(cred, -1);
67316 put_cred(cred);
67317+
67318+#ifdef CONFIG_GRKERNSEC_SETXID
67319+ cred = (struct cred *) tsk->delayed_cred;
67320+ if (cred != NULL) {
67321+ tsk->delayed_cred = NULL;
67322+ validate_creds(cred);
67323+ alter_cred_subscribers(cred, -1);
67324+ put_cred(cred);
67325+ }
67326+#endif
67327 }
67328
67329 /**
67330@@ -469,7 +479,7 @@ error_put:
67331 * Always returns 0 thus allowing this function to be tail-called at the end
67332 * of, say, sys_setgid().
67333 */
67334-int commit_creds(struct cred *new)
67335+static int __commit_creds(struct cred *new)
67336 {
67337 struct task_struct *task = current;
67338 const struct cred *old = task->real_cred;
67339@@ -488,6 +498,8 @@ int commit_creds(struct cred *new)
67340
67341 get_cred(new); /* we will require a ref for the subj creds too */
67342
67343+ gr_set_role_label(task, new->uid, new->gid);
67344+
67345 /* dumpability changes */
67346 if (!uid_eq(old->euid, new->euid) ||
67347 !gid_eq(old->egid, new->egid) ||
67348@@ -537,6 +549,101 @@ int commit_creds(struct cred *new)
67349 put_cred(old);
67350 return 0;
67351 }
67352+#ifdef CONFIG_GRKERNSEC_SETXID
67353+extern int set_user(struct cred *new);
67354+
67355+void gr_delayed_cred_worker(void)
67356+{
67357+ const struct cred *new = current->delayed_cred;
67358+ struct cred *ncred;
67359+
67360+ current->delayed_cred = NULL;
67361+
67362+ if (current_uid() && new != NULL) {
67363+ // from doing get_cred on it when queueing this
67364+ put_cred(new);
67365+ return;
67366+ } else if (new == NULL)
67367+ return;
67368+
67369+ ncred = prepare_creds();
67370+ if (!ncred)
67371+ goto die;
67372+ // uids
67373+ ncred->uid = new->uid;
67374+ ncred->euid = new->euid;
67375+ ncred->suid = new->suid;
67376+ ncred->fsuid = new->fsuid;
67377+ // gids
67378+ ncred->gid = new->gid;
67379+ ncred->egid = new->egid;
67380+ ncred->sgid = new->sgid;
67381+ ncred->fsgid = new->fsgid;
67382+ // groups
67383+ if (set_groups(ncred, new->group_info) < 0) {
67384+ abort_creds(ncred);
67385+ goto die;
67386+ }
67387+ // caps
67388+ ncred->securebits = new->securebits;
67389+ ncred->cap_inheritable = new->cap_inheritable;
67390+ ncred->cap_permitted = new->cap_permitted;
67391+ ncred->cap_effective = new->cap_effective;
67392+ ncred->cap_bset = new->cap_bset;
67393+
67394+ if (set_user(ncred)) {
67395+ abort_creds(ncred);
67396+ goto die;
67397+ }
67398+
67399+ // from doing get_cred on it when queueing this
67400+ put_cred(new);
67401+
67402+ __commit_creds(ncred);
67403+ return;
67404+die:
67405+ // from doing get_cred on it when queueing this
67406+ put_cred(new);
67407+ do_group_exit(SIGKILL);
67408+}
67409+#endif
67410+
67411+int commit_creds(struct cred *new)
67412+{
67413+#ifdef CONFIG_GRKERNSEC_SETXID
67414+ int ret;
67415+ int schedule_it = 0;
67416+ struct task_struct *t;
67417+
67418+ /* we won't get called with tasklist_lock held for writing
67419+ and interrupts disabled as the cred struct in that case is
67420+ init_cred
67421+ */
67422+ if (grsec_enable_setxid && !current_is_single_threaded() &&
67423+ !current_uid() && new->uid) {
67424+ schedule_it = 1;
67425+ }
67426+ ret = __commit_creds(new);
67427+ if (schedule_it) {
67428+ rcu_read_lock();
67429+ read_lock(&tasklist_lock);
67430+ for (t = next_thread(current); t != current;
67431+ t = next_thread(t)) {
67432+ if (t->delayed_cred == NULL) {
67433+ t->delayed_cred = get_cred(new);
67434+ set_tsk_thread_flag(t, TIF_GRSEC_SETXID);
67435+ set_tsk_need_resched(t);
67436+ }
67437+ }
67438+ read_unlock(&tasklist_lock);
67439+ rcu_read_unlock();
67440+ }
67441+ return ret;
67442+#else
67443+ return __commit_creds(new);
67444+#endif
67445+}
67446+
67447 EXPORT_SYMBOL(commit_creds);
67448
67449 /**
67450diff --git a/kernel/debug/debug_core.c b/kernel/debug/debug_core.c
67451index 0557f24..1a00d9a 100644
67452--- a/kernel/debug/debug_core.c
67453+++ b/kernel/debug/debug_core.c
67454@@ -122,7 +122,7 @@ static DEFINE_RAW_SPINLOCK(dbg_slave_lock);
67455 */
67456 static atomic_t masters_in_kgdb;
67457 static atomic_t slaves_in_kgdb;
67458-static atomic_t kgdb_break_tasklet_var;
67459+static atomic_unchecked_t kgdb_break_tasklet_var;
67460 atomic_t kgdb_setting_breakpoint;
67461
67462 struct task_struct *kgdb_usethread;
67463@@ -132,7 +132,7 @@ int kgdb_single_step;
67464 static pid_t kgdb_sstep_pid;
67465
67466 /* to keep track of the CPU which is doing the single stepping*/
67467-atomic_t kgdb_cpu_doing_single_step = ATOMIC_INIT(-1);
67468+atomic_unchecked_t kgdb_cpu_doing_single_step = ATOMIC_INIT(-1);
67469
67470 /*
67471 * If you are debugging a problem where roundup (the collection of
67472@@ -540,7 +540,7 @@ return_normal:
67473 * kernel will only try for the value of sstep_tries before
67474 * giving up and continuing on.
67475 */
67476- if (atomic_read(&kgdb_cpu_doing_single_step) != -1 &&
67477+ if (atomic_read_unchecked(&kgdb_cpu_doing_single_step) != -1 &&
67478 (kgdb_info[cpu].task &&
67479 kgdb_info[cpu].task->pid != kgdb_sstep_pid) && --sstep_tries) {
67480 atomic_set(&kgdb_active, -1);
67481@@ -634,8 +634,8 @@ cpu_master_loop:
67482 }
67483
67484 kgdb_restore:
67485- if (atomic_read(&kgdb_cpu_doing_single_step) != -1) {
67486- int sstep_cpu = atomic_read(&kgdb_cpu_doing_single_step);
67487+ if (atomic_read_unchecked(&kgdb_cpu_doing_single_step) != -1) {
67488+ int sstep_cpu = atomic_read_unchecked(&kgdb_cpu_doing_single_step);
67489 if (kgdb_info[sstep_cpu].task)
67490 kgdb_sstep_pid = kgdb_info[sstep_cpu].task->pid;
67491 else
67492@@ -861,18 +861,18 @@ static void kgdb_unregister_callbacks(void)
67493 static void kgdb_tasklet_bpt(unsigned long ing)
67494 {
67495 kgdb_breakpoint();
67496- atomic_set(&kgdb_break_tasklet_var, 0);
67497+ atomic_set_unchecked(&kgdb_break_tasklet_var, 0);
67498 }
67499
67500 static DECLARE_TASKLET(kgdb_tasklet_breakpoint, kgdb_tasklet_bpt, 0);
67501
67502 void kgdb_schedule_breakpoint(void)
67503 {
67504- if (atomic_read(&kgdb_break_tasklet_var) ||
67505+ if (atomic_read_unchecked(&kgdb_break_tasklet_var) ||
67506 atomic_read(&kgdb_active) != -1 ||
67507 atomic_read(&kgdb_setting_breakpoint))
67508 return;
67509- atomic_inc(&kgdb_break_tasklet_var);
67510+ atomic_inc_unchecked(&kgdb_break_tasklet_var);
67511 tasklet_schedule(&kgdb_tasklet_breakpoint);
67512 }
67513 EXPORT_SYMBOL_GPL(kgdb_schedule_breakpoint);
67514diff --git a/kernel/debug/kdb/kdb_main.c b/kernel/debug/kdb/kdb_main.c
67515index 31df170..bc98840 100644
67516--- a/kernel/debug/kdb/kdb_main.c
67517+++ b/kernel/debug/kdb/kdb_main.c
67518@@ -1971,7 +1971,7 @@ static int kdb_lsmod(int argc, const char **argv)
67519 list_for_each_entry(mod, kdb_modules, list) {
67520
67521 kdb_printf("%-20s%8u 0x%p ", mod->name,
67522- mod->core_size, (void *)mod);
67523+ mod->core_size_rx + mod->core_size_rw, (void *)mod);
67524 #ifdef CONFIG_MODULE_UNLOAD
67525 kdb_printf("%4ld ", module_refcount(mod));
67526 #endif
67527@@ -1981,7 +1981,7 @@ static int kdb_lsmod(int argc, const char **argv)
67528 kdb_printf(" (Loading)");
67529 else
67530 kdb_printf(" (Live)");
67531- kdb_printf(" 0x%p", mod->module_core);
67532+ kdb_printf(" 0x%p 0x%p", mod->module_core_rx, mod->module_core_rw);
67533
67534 #ifdef CONFIG_MODULE_UNLOAD
67535 {
67536diff --git a/kernel/events/core.c b/kernel/events/core.c
67537index 7fee567..8affa2c 100644
67538--- a/kernel/events/core.c
67539+++ b/kernel/events/core.c
67540@@ -181,7 +181,7 @@ int perf_proc_update_handler(struct ctl_table *table, int write,
67541 return 0;
67542 }
67543
67544-static atomic64_t perf_event_id;
67545+static atomic64_unchecked_t perf_event_id;
67546
67547 static void cpu_ctx_sched_out(struct perf_cpu_context *cpuctx,
67548 enum event_type_t event_type);
67549@@ -2665,7 +2665,7 @@ static void __perf_event_read(void *info)
67550
67551 static inline u64 perf_event_count(struct perf_event *event)
67552 {
67553- return local64_read(&event->count) + atomic64_read(&event->child_count);
67554+ return local64_read(&event->count) + atomic64_read_unchecked(&event->child_count);
67555 }
67556
67557 static u64 perf_event_read(struct perf_event *event)
67558@@ -2995,9 +2995,9 @@ u64 perf_event_read_value(struct perf_event *event, u64 *enabled, u64 *running)
67559 mutex_lock(&event->child_mutex);
67560 total += perf_event_read(event);
67561 *enabled += event->total_time_enabled +
67562- atomic64_read(&event->child_total_time_enabled);
67563+ atomic64_read_unchecked(&event->child_total_time_enabled);
67564 *running += event->total_time_running +
67565- atomic64_read(&event->child_total_time_running);
67566+ atomic64_read_unchecked(&event->child_total_time_running);
67567
67568 list_for_each_entry(child, &event->child_list, child_list) {
67569 total += perf_event_read(child);
67570@@ -3406,10 +3406,10 @@ void perf_event_update_userpage(struct perf_event *event)
67571 userpg->offset -= local64_read(&event->hw.prev_count);
67572
67573 userpg->time_enabled = enabled +
67574- atomic64_read(&event->child_total_time_enabled);
67575+ atomic64_read_unchecked(&event->child_total_time_enabled);
67576
67577 userpg->time_running = running +
67578- atomic64_read(&event->child_total_time_running);
67579+ atomic64_read_unchecked(&event->child_total_time_running);
67580
67581 arch_perf_update_userpage(userpg, now);
67582
67583@@ -3842,11 +3842,11 @@ static void perf_output_read_one(struct perf_output_handle *handle,
67584 values[n++] = perf_event_count(event);
67585 if (read_format & PERF_FORMAT_TOTAL_TIME_ENABLED) {
67586 values[n++] = enabled +
67587- atomic64_read(&event->child_total_time_enabled);
67588+ atomic64_read_unchecked(&event->child_total_time_enabled);
67589 }
67590 if (read_format & PERF_FORMAT_TOTAL_TIME_RUNNING) {
67591 values[n++] = running +
67592- atomic64_read(&event->child_total_time_running);
67593+ atomic64_read_unchecked(&event->child_total_time_running);
67594 }
67595 if (read_format & PERF_FORMAT_ID)
67596 values[n++] = primary_event_id(event);
67597@@ -4524,12 +4524,12 @@ static void perf_event_mmap_event(struct perf_mmap_event *mmap_event)
67598 * need to add enough zero bytes after the string to handle
67599 * the 64bit alignment we do later.
67600 */
67601- buf = kzalloc(PATH_MAX + sizeof(u64), GFP_KERNEL);
67602+ buf = kzalloc(PATH_MAX, GFP_KERNEL);
67603 if (!buf) {
67604 name = strncpy(tmp, "//enomem", sizeof(tmp));
67605 goto got_name;
67606 }
67607- name = d_path(&file->f_path, buf, PATH_MAX);
67608+ name = d_path(&file->f_path, buf, PATH_MAX - sizeof(u64));
67609 if (IS_ERR(name)) {
67610 name = strncpy(tmp, "//toolong", sizeof(tmp));
67611 goto got_name;
67612@@ -5968,7 +5968,7 @@ perf_event_alloc(struct perf_event_attr *attr, int cpu,
67613 event->parent = parent_event;
67614
67615 event->ns = get_pid_ns(current->nsproxy->pid_ns);
67616- event->id = atomic64_inc_return(&perf_event_id);
67617+ event->id = atomic64_inc_return_unchecked(&perf_event_id);
67618
67619 event->state = PERF_EVENT_STATE_INACTIVE;
67620
67621@@ -6567,10 +6567,10 @@ static void sync_child_event(struct perf_event *child_event,
67622 /*
67623 * Add back the child's count to the parent's count:
67624 */
67625- atomic64_add(child_val, &parent_event->child_count);
67626- atomic64_add(child_event->total_time_enabled,
67627+ atomic64_add_unchecked(child_val, &parent_event->child_count);
67628+ atomic64_add_unchecked(child_event->total_time_enabled,
67629 &parent_event->child_total_time_enabled);
67630- atomic64_add(child_event->total_time_running,
67631+ atomic64_add_unchecked(child_event->total_time_running,
67632 &parent_event->child_total_time_running);
67633
67634 /*
67635diff --git a/kernel/exit.c b/kernel/exit.c
67636index f65345f9..1423231 100644
67637--- a/kernel/exit.c
67638+++ b/kernel/exit.c
67639@@ -182,6 +182,10 @@ void release_task(struct task_struct * p)
67640 struct task_struct *leader;
67641 int zap_leader;
67642 repeat:
67643+#ifdef CONFIG_NET
67644+ gr_del_task_from_ip_table(p);
67645+#endif
67646+
67647 /* don't need to get the RCU readlock here - the process is dead and
67648 * can't be modifying its own credentials. But shut RCU-lockdep up */
67649 rcu_read_lock();
67650@@ -394,7 +398,7 @@ int allow_signal(int sig)
67651 * know it'll be handled, so that they don't get converted to
67652 * SIGKILL or just silently dropped.
67653 */
67654- current->sighand->action[(sig)-1].sa.sa_handler = (void __user *)2;
67655+ current->sighand->action[(sig)-1].sa.sa_handler = (__force void __user *)2;
67656 recalc_sigpending();
67657 spin_unlock_irq(&current->sighand->siglock);
67658 return 0;
67659@@ -430,6 +434,8 @@ void daemonize(const char *name, ...)
67660 vsnprintf(current->comm, sizeof(current->comm), name, args);
67661 va_end(args);
67662
67663+ gr_set_kernel_label(current);
67664+
67665 /*
67666 * If we were started as result of loading a module, close all of the
67667 * user space pages. We don't need them, and if we didn't close them
67668@@ -907,6 +913,8 @@ void do_exit(long code)
67669 struct task_struct *tsk = current;
67670 int group_dead;
67671
67672+ set_fs(USER_DS);
67673+
67674 profile_task_exit(tsk);
67675
67676 WARN_ON(blk_needs_flush_plug(tsk));
67677@@ -923,7 +931,6 @@ void do_exit(long code)
67678 * mm_release()->clear_child_tid() from writing to a user-controlled
67679 * kernel address.
67680 */
67681- set_fs(USER_DS);
67682
67683 ptrace_event(PTRACE_EVENT_EXIT, code);
67684
67685@@ -982,6 +989,9 @@ void do_exit(long code)
67686 tsk->exit_code = code;
67687 taskstats_exit(tsk, group_dead);
67688
67689+ gr_acl_handle_psacct(tsk, code);
67690+ gr_acl_handle_exit();
67691+
67692 exit_mm(tsk);
67693
67694 if (group_dead)
67695@@ -1099,7 +1109,7 @@ SYSCALL_DEFINE1(exit, int, error_code)
67696 * Take down every thread in the group. This is called by fatal signals
67697 * as well as by sys_exit_group (below).
67698 */
67699-void
67700+__noreturn void
67701 do_group_exit(int exit_code)
67702 {
67703 struct signal_struct *sig = current->signal;
67704diff --git a/kernel/fork.c b/kernel/fork.c
67705index 2c8857e..288c9c7 100644
67706--- a/kernel/fork.c
67707+++ b/kernel/fork.c
67708@@ -318,7 +318,7 @@ static struct task_struct *dup_task_struct(struct task_struct *orig)
67709 *stackend = STACK_END_MAGIC; /* for overflow detection */
67710
67711 #ifdef CONFIG_CC_STACKPROTECTOR
67712- tsk->stack_canary = get_random_int();
67713+ tsk->stack_canary = pax_get_random_long();
67714 #endif
67715
67716 /*
67717@@ -343,13 +343,78 @@ free_tsk:
67718 }
67719
67720 #ifdef CONFIG_MMU
67721+static struct vm_area_struct *dup_vma(struct mm_struct *mm, struct mm_struct *oldmm, struct vm_area_struct *mpnt)
67722+{
67723+ struct vm_area_struct *tmp;
67724+ unsigned long charge;
67725+ struct mempolicy *pol;
67726+ struct file *file;
67727+
67728+ charge = 0;
67729+ if (mpnt->vm_flags & VM_ACCOUNT) {
67730+ unsigned long len = vma_pages(mpnt);
67731+
67732+ if (security_vm_enough_memory_mm(oldmm, len)) /* sic */
67733+ goto fail_nomem;
67734+ charge = len;
67735+ }
67736+ tmp = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
67737+ if (!tmp)
67738+ goto fail_nomem;
67739+ *tmp = *mpnt;
67740+ tmp->vm_mm = mm;
67741+ INIT_LIST_HEAD(&tmp->anon_vma_chain);
67742+ pol = mpol_dup(vma_policy(mpnt));
67743+ if (IS_ERR(pol))
67744+ goto fail_nomem_policy;
67745+ vma_set_policy(tmp, pol);
67746+ if (anon_vma_fork(tmp, mpnt))
67747+ goto fail_nomem_anon_vma_fork;
67748+ tmp->vm_flags &= ~VM_LOCKED;
67749+ tmp->vm_next = tmp->vm_prev = NULL;
67750+ tmp->vm_mirror = NULL;
67751+ file = tmp->vm_file;
67752+ if (file) {
67753+ struct inode *inode = file->f_path.dentry->d_inode;
67754+ struct address_space *mapping = file->f_mapping;
67755+
67756+ get_file(file);
67757+ if (tmp->vm_flags & VM_DENYWRITE)
67758+ atomic_dec(&inode->i_writecount);
67759+ mutex_lock(&mapping->i_mmap_mutex);
67760+ if (tmp->vm_flags & VM_SHARED)
67761+ mapping->i_mmap_writable++;
67762+ flush_dcache_mmap_lock(mapping);
67763+ /* insert tmp into the share list, just after mpnt */
67764+ vma_prio_tree_add(tmp, mpnt);
67765+ flush_dcache_mmap_unlock(mapping);
67766+ mutex_unlock(&mapping->i_mmap_mutex);
67767+ }
67768+
67769+ /*
67770+ * Clear hugetlb-related page reserves for children. This only
67771+ * affects MAP_PRIVATE mappings. Faults generated by the child
67772+ * are not guaranteed to succeed, even if read-only
67773+ */
67774+ if (is_vm_hugetlb_page(tmp))
67775+ reset_vma_resv_huge_pages(tmp);
67776+
67777+ return tmp;
67778+
67779+fail_nomem_anon_vma_fork:
67780+ mpol_put(pol);
67781+fail_nomem_policy:
67782+ kmem_cache_free(vm_area_cachep, tmp);
67783+fail_nomem:
67784+ vm_unacct_memory(charge);
67785+ return NULL;
67786+}
67787+
67788 static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
67789 {
67790 struct vm_area_struct *mpnt, *tmp, *prev, **pprev;
67791 struct rb_node **rb_link, *rb_parent;
67792 int retval;
67793- unsigned long charge;
67794- struct mempolicy *pol;
67795
67796 down_write(&oldmm->mmap_sem);
67797 flush_cache_dup_mm(oldmm);
67798@@ -361,8 +426,8 @@ static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
67799 mm->locked_vm = 0;
67800 mm->mmap = NULL;
67801 mm->mmap_cache = NULL;
67802- mm->free_area_cache = oldmm->mmap_base;
67803- mm->cached_hole_size = ~0UL;
67804+ mm->free_area_cache = oldmm->free_area_cache;
67805+ mm->cached_hole_size = oldmm->cached_hole_size;
67806 mm->map_count = 0;
67807 cpumask_clear(mm_cpumask(mm));
67808 mm->mm_rb = RB_ROOT;
67809@@ -378,52 +443,15 @@ static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
67810
67811 prev = NULL;
67812 for (mpnt = oldmm->mmap; mpnt; mpnt = mpnt->vm_next) {
67813- struct file *file;
67814-
67815 if (mpnt->vm_flags & VM_DONTCOPY) {
67816 vm_stat_account(mm, mpnt->vm_flags, mpnt->vm_file,
67817 -vma_pages(mpnt));
67818 continue;
67819 }
67820- charge = 0;
67821- if (mpnt->vm_flags & VM_ACCOUNT) {
67822- unsigned long len = vma_pages(mpnt);
67823-
67824- if (security_vm_enough_memory_mm(oldmm, len)) /* sic */
67825- goto fail_nomem;
67826- charge = len;
67827- }
67828- tmp = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
67829- if (!tmp)
67830- goto fail_nomem;
67831- *tmp = *mpnt;
67832- INIT_LIST_HEAD(&tmp->anon_vma_chain);
67833- pol = mpol_dup(vma_policy(mpnt));
67834- retval = PTR_ERR(pol);
67835- if (IS_ERR(pol))
67836- goto fail_nomem_policy;
67837- vma_set_policy(tmp, pol);
67838- tmp->vm_mm = mm;
67839- if (anon_vma_fork(tmp, mpnt))
67840- goto fail_nomem_anon_vma_fork;
67841- tmp->vm_flags &= ~VM_LOCKED;
67842- tmp->vm_next = tmp->vm_prev = NULL;
67843- file = tmp->vm_file;
67844- if (file) {
67845- struct inode *inode = file->f_path.dentry->d_inode;
67846- struct address_space *mapping = file->f_mapping;
67847-
67848- get_file(file);
67849- if (tmp->vm_flags & VM_DENYWRITE)
67850- atomic_dec(&inode->i_writecount);
67851- mutex_lock(&mapping->i_mmap_mutex);
67852- if (tmp->vm_flags & VM_SHARED)
67853- mapping->i_mmap_writable++;
67854- flush_dcache_mmap_lock(mapping);
67855- /* insert tmp into the share list, just after mpnt */
67856- vma_prio_tree_add(tmp, mpnt);
67857- flush_dcache_mmap_unlock(mapping);
67858- mutex_unlock(&mapping->i_mmap_mutex);
67859+ tmp = dup_vma(mm, oldmm, mpnt);
67860+ if (!tmp) {
67861+ retval = -ENOMEM;
67862+ goto out;
67863 }
67864
67865 /*
67866@@ -455,9 +483,34 @@ static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
67867 if (retval)
67868 goto out;
67869
67870- if (file)
67871+ if (tmp->vm_file)
67872 uprobe_mmap(tmp);
67873 }
67874+
67875+#ifdef CONFIG_PAX_SEGMEXEC
67876+ if (oldmm->pax_flags & MF_PAX_SEGMEXEC) {
67877+ struct vm_area_struct *mpnt_m;
67878+
67879+ for (mpnt = oldmm->mmap, mpnt_m = mm->mmap; mpnt; mpnt = mpnt->vm_next, mpnt_m = mpnt_m->vm_next) {
67880+ BUG_ON(!mpnt_m || mpnt_m->vm_mirror || mpnt->vm_mm != oldmm || mpnt_m->vm_mm != mm);
67881+
67882+ if (!mpnt->vm_mirror)
67883+ continue;
67884+
67885+ if (mpnt->vm_end <= SEGMEXEC_TASK_SIZE) {
67886+ BUG_ON(mpnt->vm_mirror->vm_mirror != mpnt);
67887+ mpnt->vm_mirror = mpnt_m;
67888+ } else {
67889+ BUG_ON(mpnt->vm_mirror->vm_mirror == mpnt || mpnt->vm_mirror->vm_mirror->vm_mm != mm);
67890+ mpnt_m->vm_mirror = mpnt->vm_mirror->vm_mirror;
67891+ mpnt_m->vm_mirror->vm_mirror = mpnt_m;
67892+ mpnt->vm_mirror->vm_mirror = mpnt;
67893+ }
67894+ }
67895+ BUG_ON(mpnt_m);
67896+ }
67897+#endif
67898+
67899 /* a new mm has just been created */
67900 arch_dup_mmap(oldmm, mm);
67901 retval = 0;
67902@@ -466,14 +519,6 @@ out:
67903 flush_tlb_mm(oldmm);
67904 up_write(&oldmm->mmap_sem);
67905 return retval;
67906-fail_nomem_anon_vma_fork:
67907- mpol_put(pol);
67908-fail_nomem_policy:
67909- kmem_cache_free(vm_area_cachep, tmp);
67910-fail_nomem:
67911- retval = -ENOMEM;
67912- vm_unacct_memory(charge);
67913- goto out;
67914 }
67915
67916 static inline int mm_alloc_pgd(struct mm_struct *mm)
67917@@ -710,8 +755,8 @@ struct mm_struct *mm_access(struct task_struct *task, unsigned int mode)
67918 return ERR_PTR(err);
67919
67920 mm = get_task_mm(task);
67921- if (mm && mm != current->mm &&
67922- !ptrace_may_access(task, mode)) {
67923+ if (mm && ((mm != current->mm && !ptrace_may_access(task, mode)) ||
67924+ (mode == PTRACE_MODE_ATTACH && (gr_handle_proc_ptrace(task) || gr_acl_handle_procpidmem(task))))) {
67925 mmput(mm);
67926 mm = ERR_PTR(-EACCES);
67927 }
67928@@ -932,13 +977,20 @@ static int copy_fs(unsigned long clone_flags, struct task_struct *tsk)
67929 spin_unlock(&fs->lock);
67930 return -EAGAIN;
67931 }
67932- fs->users++;
67933+ atomic_inc(&fs->users);
67934 spin_unlock(&fs->lock);
67935 return 0;
67936 }
67937 tsk->fs = copy_fs_struct(fs);
67938 if (!tsk->fs)
67939 return -ENOMEM;
67940+ /* Carry through gr_chroot_dentry and is_chrooted instead
67941+ of recomputing it here. Already copied when the task struct
67942+ is duplicated. This allows pivot_root to not be treated as
67943+ a chroot
67944+ */
67945+ //gr_set_chroot_entries(tsk, &tsk->fs->root);
67946+
67947 return 0;
67948 }
67949
67950@@ -1205,6 +1257,9 @@ static struct task_struct *copy_process(unsigned long clone_flags,
67951 DEBUG_LOCKS_WARN_ON(!p->softirqs_enabled);
67952 #endif
67953 retval = -EAGAIN;
67954+
67955+ gr_learn_resource(p, RLIMIT_NPROC, atomic_read(&p->real_cred->user->processes), 0);
67956+
67957 if (atomic_read(&p->real_cred->user->processes) >=
67958 task_rlimit(p, RLIMIT_NPROC)) {
67959 if (!capable(CAP_SYS_ADMIN) && !capable(CAP_SYS_RESOURCE) &&
67960@@ -1427,6 +1482,9 @@ static struct task_struct *copy_process(unsigned long clone_flags,
67961 /* Need tasklist lock for parent etc handling! */
67962 write_lock_irq(&tasklist_lock);
67963
67964+ /* synchronizes with gr_set_acls() */
67965+ gr_copy_label(p);
67966+
67967 /* CLONE_PARENT re-uses the old parent */
67968 if (clone_flags & (CLONE_PARENT|CLONE_THREAD)) {
67969 p->real_parent = current->real_parent;
67970@@ -1537,6 +1595,8 @@ bad_fork_cleanup_count:
67971 bad_fork_free:
67972 free_task(p);
67973 fork_out:
67974+ gr_log_forkfail(retval);
67975+
67976 return ERR_PTR(retval);
67977 }
67978
67979@@ -1637,6 +1697,8 @@ long do_fork(unsigned long clone_flags,
67980 if (clone_flags & CLONE_PARENT_SETTID)
67981 put_user(nr, parent_tidptr);
67982
67983+ gr_handle_brute_check();
67984+
67985 if (clone_flags & CLONE_VFORK) {
67986 p->vfork_done = &vfork;
67987 init_completion(&vfork);
67988@@ -1735,7 +1797,7 @@ static int unshare_fs(unsigned long unshare_flags, struct fs_struct **new_fsp)
67989 return 0;
67990
67991 /* don't need lock here; in the worst case we'll do useless copy */
67992- if (fs->users == 1)
67993+ if (atomic_read(&fs->users) == 1)
67994 return 0;
67995
67996 *new_fsp = copy_fs_struct(fs);
67997@@ -1824,7 +1886,8 @@ SYSCALL_DEFINE1(unshare, unsigned long, unshare_flags)
67998 fs = current->fs;
67999 spin_lock(&fs->lock);
68000 current->fs = new_fs;
68001- if (--fs->users)
68002+ gr_set_chroot_entries(current, &current->fs->root);
68003+ if (atomic_dec_return(&fs->users))
68004 new_fs = NULL;
68005 else
68006 new_fs = fs;
68007diff --git a/kernel/futex.c b/kernel/futex.c
68008index 20ef219..b3a0cb2 100644
68009--- a/kernel/futex.c
68010+++ b/kernel/futex.c
68011@@ -54,6 +54,7 @@
68012 #include <linux/mount.h>
68013 #include <linux/pagemap.h>
68014 #include <linux/syscalls.h>
68015+#include <linux/ptrace.h>
68016 #include <linux/signal.h>
68017 #include <linux/export.h>
68018 #include <linux/magic.h>
68019@@ -239,6 +240,11 @@ get_futex_key(u32 __user *uaddr, int fshared, union futex_key *key, int rw)
68020 struct page *page, *page_head;
68021 int err, ro = 0;
68022
68023+#ifdef CONFIG_PAX_SEGMEXEC
68024+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && address >= SEGMEXEC_TASK_SIZE)
68025+ return -EFAULT;
68026+#endif
68027+
68028 /*
68029 * The futex address must be "naturally" aligned.
68030 */
68031@@ -2717,6 +2723,7 @@ static int __init futex_init(void)
68032 {
68033 u32 curval;
68034 int i;
68035+ mm_segment_t oldfs;
68036
68037 /*
68038 * This will fail and we want it. Some arch implementations do
68039@@ -2728,8 +2735,11 @@ static int __init futex_init(void)
68040 * implementation, the non-functional ones will return
68041 * -ENOSYS.
68042 */
68043+ oldfs = get_fs();
68044+ set_fs(USER_DS);
68045 if (cmpxchg_futex_value_locked(&curval, NULL, 0, 0) == -EFAULT)
68046 futex_cmpxchg_enabled = 1;
68047+ set_fs(oldfs);
68048
68049 for (i = 0; i < ARRAY_SIZE(futex_queues); i++) {
68050 plist_head_init(&futex_queues[i].chain);
68051diff --git a/kernel/gcov/base.c b/kernel/gcov/base.c
68052index 9b22d03..6295b62 100644
68053--- a/kernel/gcov/base.c
68054+++ b/kernel/gcov/base.c
68055@@ -102,11 +102,6 @@ void gcov_enable_events(void)
68056 }
68057
68058 #ifdef CONFIG_MODULES
68059-static inline int within(void *addr, void *start, unsigned long size)
68060-{
68061- return ((addr >= start) && (addr < start + size));
68062-}
68063-
68064 /* Update list and generate events when modules are unloaded. */
68065 static int gcov_module_notifier(struct notifier_block *nb, unsigned long event,
68066 void *data)
68067@@ -121,7 +116,7 @@ static int gcov_module_notifier(struct notifier_block *nb, unsigned long event,
68068 prev = NULL;
68069 /* Remove entries located in module from linked list. */
68070 for (info = gcov_info_head; info; info = info->next) {
68071- if (within(info, mod->module_core, mod->core_size)) {
68072+ if (within_module_core_rw((unsigned long)info, mod)) {
68073 if (prev)
68074 prev->next = info->next;
68075 else
68076diff --git a/kernel/hrtimer.c b/kernel/hrtimer.c
68077index 6db7a5e..25b6648 100644
68078--- a/kernel/hrtimer.c
68079+++ b/kernel/hrtimer.c
68080@@ -1407,7 +1407,7 @@ void hrtimer_peek_ahead_timers(void)
68081 local_irq_restore(flags);
68082 }
68083
68084-static void run_hrtimer_softirq(struct softirq_action *h)
68085+static void run_hrtimer_softirq(void)
68086 {
68087 struct hrtimer_cpu_base *cpu_base = &__get_cpu_var(hrtimer_bases);
68088
68089diff --git a/kernel/jump_label.c b/kernel/jump_label.c
68090index 4304919..408c4c0 100644
68091--- a/kernel/jump_label.c
68092+++ b/kernel/jump_label.c
68093@@ -13,6 +13,7 @@
68094 #include <linux/sort.h>
68095 #include <linux/err.h>
68096 #include <linux/static_key.h>
68097+#include <linux/mm.h>
68098
68099 #ifdef HAVE_JUMP_LABEL
68100
68101@@ -50,7 +51,9 @@ jump_label_sort_entries(struct jump_entry *start, struct jump_entry *stop)
68102
68103 size = (((unsigned long)stop - (unsigned long)start)
68104 / sizeof(struct jump_entry));
68105+ pax_open_kernel();
68106 sort(start, size, sizeof(struct jump_entry), jump_label_cmp, NULL);
68107+ pax_close_kernel();
68108 }
68109
68110 static void jump_label_update(struct static_key *key, int enable);
68111@@ -356,10 +359,12 @@ static void jump_label_invalidate_module_init(struct module *mod)
68112 struct jump_entry *iter_stop = iter_start + mod->num_jump_entries;
68113 struct jump_entry *iter;
68114
68115+ pax_open_kernel();
68116 for (iter = iter_start; iter < iter_stop; iter++) {
68117 if (within_module_init(iter->code, mod))
68118 iter->code = 0;
68119 }
68120+ pax_close_kernel();
68121 }
68122
68123 static int
68124diff --git a/kernel/kallsyms.c b/kernel/kallsyms.c
68125index 2169fee..45c017a 100644
68126--- a/kernel/kallsyms.c
68127+++ b/kernel/kallsyms.c
68128@@ -11,6 +11,9 @@
68129 * Changed the compression method from stem compression to "table lookup"
68130 * compression (see scripts/kallsyms.c for a more complete description)
68131 */
68132+#ifdef CONFIG_GRKERNSEC_HIDESYM
68133+#define __INCLUDED_BY_HIDESYM 1
68134+#endif
68135 #include <linux/kallsyms.h>
68136 #include <linux/module.h>
68137 #include <linux/init.h>
68138@@ -53,12 +56,33 @@ extern const unsigned long kallsyms_markers[] __attribute__((weak));
68139
68140 static inline int is_kernel_inittext(unsigned long addr)
68141 {
68142+ if (system_state != SYSTEM_BOOTING)
68143+ return 0;
68144+
68145 if (addr >= (unsigned long)_sinittext
68146 && addr <= (unsigned long)_einittext)
68147 return 1;
68148 return 0;
68149 }
68150
68151+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
68152+#ifdef CONFIG_MODULES
68153+static inline int is_module_text(unsigned long addr)
68154+{
68155+ if ((unsigned long)MODULES_EXEC_VADDR <= addr && addr <= (unsigned long)MODULES_EXEC_END)
68156+ return 1;
68157+
68158+ addr = ktla_ktva(addr);
68159+ return (unsigned long)MODULES_EXEC_VADDR <= addr && addr <= (unsigned long)MODULES_EXEC_END;
68160+}
68161+#else
68162+static inline int is_module_text(unsigned long addr)
68163+{
68164+ return 0;
68165+}
68166+#endif
68167+#endif
68168+
68169 static inline int is_kernel_text(unsigned long addr)
68170 {
68171 if ((addr >= (unsigned long)_stext && addr <= (unsigned long)_etext) ||
68172@@ -69,13 +93,28 @@ static inline int is_kernel_text(unsigned long addr)
68173
68174 static inline int is_kernel(unsigned long addr)
68175 {
68176+
68177+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
68178+ if (is_kernel_text(addr) || is_kernel_inittext(addr))
68179+ return 1;
68180+
68181+ if (ktla_ktva((unsigned long)_text) <= addr && addr < (unsigned long)_end)
68182+#else
68183 if (addr >= (unsigned long)_stext && addr <= (unsigned long)_end)
68184+#endif
68185+
68186 return 1;
68187 return in_gate_area_no_mm(addr);
68188 }
68189
68190 static int is_ksym_addr(unsigned long addr)
68191 {
68192+
68193+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
68194+ if (is_module_text(addr))
68195+ return 0;
68196+#endif
68197+
68198 if (all_var)
68199 return is_kernel(addr);
68200
68201@@ -470,7 +509,6 @@ static unsigned long get_ksymbol_core(struct kallsym_iter *iter)
68202
68203 static void reset_iter(struct kallsym_iter *iter, loff_t new_pos)
68204 {
68205- iter->name[0] = '\0';
68206 iter->nameoff = get_symbol_offset(new_pos);
68207 iter->pos = new_pos;
68208 }
68209@@ -518,6 +556,11 @@ static int s_show(struct seq_file *m, void *p)
68210 {
68211 struct kallsym_iter *iter = m->private;
68212
68213+#ifdef CONFIG_GRKERNSEC_HIDESYM
68214+ if (current_uid())
68215+ return 0;
68216+#endif
68217+
68218 /* Some debugging symbols have no name. Ignore them. */
68219 if (!iter->name[0])
68220 return 0;
68221@@ -531,6 +574,7 @@ static int s_show(struct seq_file *m, void *p)
68222 */
68223 type = iter->exported ? toupper(iter->type) :
68224 tolower(iter->type);
68225+
68226 seq_printf(m, "%pK %c %s\t[%s]\n", (void *)iter->value,
68227 type, iter->name, iter->module_name);
68228 } else
68229@@ -556,7 +600,7 @@ static int kallsyms_open(struct inode *inode, struct file *file)
68230 struct kallsym_iter *iter;
68231 int ret;
68232
68233- iter = kmalloc(sizeof(*iter), GFP_KERNEL);
68234+ iter = kzalloc(sizeof(*iter), GFP_KERNEL);
68235 if (!iter)
68236 return -ENOMEM;
68237 reset_iter(iter, 0);
68238diff --git a/kernel/kcmp.c b/kernel/kcmp.c
68239index 30b7b22..c726387 100644
68240--- a/kernel/kcmp.c
68241+++ b/kernel/kcmp.c
68242@@ -98,6 +98,10 @@ SYSCALL_DEFINE5(kcmp, pid_t, pid1, pid_t, pid2, int, type,
68243 struct task_struct *task1, *task2;
68244 int ret;
68245
68246+#ifdef CONFIG_GRKERNSEC
68247+ return -ENOSYS;
68248+#endif
68249+
68250 rcu_read_lock();
68251
68252 /*
68253diff --git a/kernel/kexec.c b/kernel/kexec.c
68254index 0668d58..591b6fc 100644
68255--- a/kernel/kexec.c
68256+++ b/kernel/kexec.c
68257@@ -1046,7 +1046,8 @@ asmlinkage long compat_sys_kexec_load(unsigned long entry,
68258 unsigned long flags)
68259 {
68260 struct compat_kexec_segment in;
68261- struct kexec_segment out, __user *ksegments;
68262+ struct kexec_segment out;
68263+ struct kexec_segment __user *ksegments;
68264 unsigned long i, result;
68265
68266 /* Don't allow clients that don't understand the native
68267diff --git a/kernel/kmod.c b/kernel/kmod.c
68268index 6f99aea..eb6e3a0 100644
68269--- a/kernel/kmod.c
68270+++ b/kernel/kmod.c
68271@@ -73,7 +73,7 @@ static void free_modprobe_argv(struct subprocess_info *info)
68272 kfree(info->argv);
68273 }
68274
68275-static int call_modprobe(char *module_name, int wait)
68276+static int call_modprobe(char *module_name, char *module_param, int wait)
68277 {
68278 static char *envp[] = {
68279 "HOME=/",
68280@@ -82,7 +82,7 @@ static int call_modprobe(char *module_name, int wait)
68281 NULL
68282 };
68283
68284- char **argv = kmalloc(sizeof(char *[5]), GFP_KERNEL);
68285+ char **argv = kmalloc(sizeof(char *[6]), GFP_KERNEL);
68286 if (!argv)
68287 goto out;
68288
68289@@ -94,7 +94,8 @@ static int call_modprobe(char *module_name, int wait)
68290 argv[1] = "-q";
68291 argv[2] = "--";
68292 argv[3] = module_name; /* check free_modprobe_argv() */
68293- argv[4] = NULL;
68294+ argv[4] = module_param;
68295+ argv[5] = NULL;
68296
68297 return call_usermodehelper_fns(modprobe_path, argv, envp,
68298 wait | UMH_KILLABLE, NULL, free_modprobe_argv, NULL);
68299@@ -119,9 +120,8 @@ out:
68300 * If module auto-loading support is disabled then this function
68301 * becomes a no-operation.
68302 */
68303-int __request_module(bool wait, const char *fmt, ...)
68304+static int ____request_module(bool wait, char *module_param, const char *fmt, va_list ap)
68305 {
68306- va_list args;
68307 char module_name[MODULE_NAME_LEN];
68308 unsigned int max_modprobes;
68309 int ret;
68310@@ -129,9 +129,7 @@ int __request_module(bool wait, const char *fmt, ...)
68311 #define MAX_KMOD_CONCURRENT 50 /* Completely arbitrary value - KAO */
68312 static int kmod_loop_msg;
68313
68314- va_start(args, fmt);
68315- ret = vsnprintf(module_name, MODULE_NAME_LEN, fmt, args);
68316- va_end(args);
68317+ ret = vsnprintf(module_name, MODULE_NAME_LEN, fmt, ap);
68318 if (ret >= MODULE_NAME_LEN)
68319 return -ENAMETOOLONG;
68320
68321@@ -139,6 +137,20 @@ int __request_module(bool wait, const char *fmt, ...)
68322 if (ret)
68323 return ret;
68324
68325+#ifdef CONFIG_GRKERNSEC_MODHARDEN
68326+ if (!current_uid()) {
68327+ /* hack to workaround consolekit/udisks stupidity */
68328+ read_lock(&tasklist_lock);
68329+ if (!strcmp(current->comm, "mount") &&
68330+ current->real_parent && !strncmp(current->real_parent->comm, "udisk", 5)) {
68331+ read_unlock(&tasklist_lock);
68332+ printk(KERN_ALERT "grsec: denied attempt to auto-load fs module %.64s by udisks\n", module_name);
68333+ return -EPERM;
68334+ }
68335+ read_unlock(&tasklist_lock);
68336+ }
68337+#endif
68338+
68339 /* If modprobe needs a service that is in a module, we get a recursive
68340 * loop. Limit the number of running kmod threads to max_threads/2 or
68341 * MAX_KMOD_CONCURRENT, whichever is the smaller. A cleaner method
68342@@ -167,11 +179,52 @@ int __request_module(bool wait, const char *fmt, ...)
68343
68344 trace_module_request(module_name, wait, _RET_IP_);
68345
68346- ret = call_modprobe(module_name, wait ? UMH_WAIT_PROC : UMH_WAIT_EXEC);
68347+ ret = call_modprobe(module_name, module_param, wait ? UMH_WAIT_PROC : UMH_WAIT_EXEC);
68348
68349 atomic_dec(&kmod_concurrent);
68350 return ret;
68351 }
68352+
68353+int ___request_module(bool wait, char *module_param, const char *fmt, ...)
68354+{
68355+ va_list args;
68356+ int ret;
68357+
68358+ va_start(args, fmt);
68359+ ret = ____request_module(wait, module_param, fmt, args);
68360+ va_end(args);
68361+
68362+ return ret;
68363+}
68364+
68365+int __request_module(bool wait, const char *fmt, ...)
68366+{
68367+ va_list args;
68368+ int ret;
68369+
68370+#ifdef CONFIG_GRKERNSEC_MODHARDEN
68371+ if (current_uid()) {
68372+ char module_param[MODULE_NAME_LEN];
68373+
68374+ memset(module_param, 0, sizeof(module_param));
68375+
68376+ snprintf(module_param, sizeof(module_param) - 1, "grsec_modharden_normal%u_", current_uid());
68377+
68378+ va_start(args, fmt);
68379+ ret = ____request_module(wait, module_param, fmt, args);
68380+ va_end(args);
68381+
68382+ return ret;
68383+ }
68384+#endif
68385+
68386+ va_start(args, fmt);
68387+ ret = ____request_module(wait, NULL, fmt, args);
68388+ va_end(args);
68389+
68390+ return ret;
68391+}
68392+
68393 EXPORT_SYMBOL(__request_module);
68394 #endif /* CONFIG_MODULES */
68395
68396@@ -280,7 +333,7 @@ static int wait_for_helper(void *data)
68397 *
68398 * Thus the __user pointer cast is valid here.
68399 */
68400- sys_wait4(pid, (int __user *)&ret, 0, NULL);
68401+ sys_wait4(pid, (int __force_user *)&ret, 0, NULL);
68402
68403 /*
68404 * If ret is 0, either ____call_usermodehelper failed and the
68405diff --git a/kernel/kprobes.c b/kernel/kprobes.c
68406index c62b854..6fc810d 100644
68407--- a/kernel/kprobes.c
68408+++ b/kernel/kprobes.c
68409@@ -185,7 +185,7 @@ static kprobe_opcode_t __kprobes *__get_insn_slot(struct kprobe_insn_cache *c)
68410 * kernel image and loaded module images reside. This is required
68411 * so x86_64 can correctly handle the %rip-relative fixups.
68412 */
68413- kip->insns = module_alloc(PAGE_SIZE);
68414+ kip->insns = module_alloc_exec(PAGE_SIZE);
68415 if (!kip->insns) {
68416 kfree(kip);
68417 return NULL;
68418@@ -225,7 +225,7 @@ static int __kprobes collect_one_slot(struct kprobe_insn_page *kip, int idx)
68419 */
68420 if (!list_is_singular(&kip->list)) {
68421 list_del(&kip->list);
68422- module_free(NULL, kip->insns);
68423+ module_free_exec(NULL, kip->insns);
68424 kfree(kip);
68425 }
68426 return 1;
68427@@ -1955,7 +1955,7 @@ static int __init init_kprobes(void)
68428 {
68429 int i, err = 0;
68430 unsigned long offset = 0, size = 0;
68431- char *modname, namebuf[128];
68432+ char *modname, namebuf[KSYM_NAME_LEN];
68433 const char *symbol_name;
68434 void *addr;
68435 struct kprobe_blackpoint *kb;
68436@@ -2040,11 +2040,11 @@ static void __kprobes report_probe(struct seq_file *pi, struct kprobe *p,
68437 kprobe_type = "k";
68438
68439 if (sym)
68440- seq_printf(pi, "%p %s %s+0x%x %s ",
68441+ seq_printf(pi, "%pK %s %s+0x%x %s ",
68442 p->addr, kprobe_type, sym, offset,
68443 (modname ? modname : " "));
68444 else
68445- seq_printf(pi, "%p %s %p ",
68446+ seq_printf(pi, "%pK %s %pK ",
68447 p->addr, kprobe_type, p->addr);
68448
68449 if (!pp)
68450@@ -2081,7 +2081,7 @@ static int __kprobes show_kprobe_addr(struct seq_file *pi, void *v)
68451 const char *sym = NULL;
68452 unsigned int i = *(loff_t *) v;
68453 unsigned long offset = 0;
68454- char *modname, namebuf[128];
68455+ char *modname, namebuf[KSYM_NAME_LEN];
68456
68457 head = &kprobe_table[i];
68458 preempt_disable();
68459diff --git a/kernel/ksysfs.c b/kernel/ksysfs.c
68460index 4e316e1..5501eef 100644
68461--- a/kernel/ksysfs.c
68462+++ b/kernel/ksysfs.c
68463@@ -47,6 +47,8 @@ static ssize_t uevent_helper_store(struct kobject *kobj,
68464 {
68465 if (count+1 > UEVENT_HELPER_PATH_LEN)
68466 return -ENOENT;
68467+ if (!capable(CAP_SYS_ADMIN))
68468+ return -EPERM;
68469 memcpy(uevent_helper, buf, count);
68470 uevent_helper[count] = '\0';
68471 if (count && uevent_helper[count-1] == '\n')
68472diff --git a/kernel/lockdep.c b/kernel/lockdep.c
68473index ea9ee45..67ebc8f 100644
68474--- a/kernel/lockdep.c
68475+++ b/kernel/lockdep.c
68476@@ -590,6 +590,10 @@ static int static_obj(void *obj)
68477 end = (unsigned long) &_end,
68478 addr = (unsigned long) obj;
68479
68480+#ifdef CONFIG_PAX_KERNEXEC
68481+ start = ktla_ktva(start);
68482+#endif
68483+
68484 /*
68485 * static variable?
68486 */
68487@@ -730,6 +734,7 @@ register_lock_class(struct lockdep_map *lock, unsigned int subclass, int force)
68488 if (!static_obj(lock->key)) {
68489 debug_locks_off();
68490 printk("INFO: trying to register non-static key.\n");
68491+ printk("lock:%pS key:%pS.\n", lock, lock->key);
68492 printk("the code is fine but needs lockdep annotation.\n");
68493 printk("turning off the locking correctness validator.\n");
68494 dump_stack();
68495@@ -3042,7 +3047,7 @@ static int __lock_acquire(struct lockdep_map *lock, unsigned int subclass,
68496 if (!class)
68497 return 0;
68498 }
68499- atomic_inc((atomic_t *)&class->ops);
68500+ atomic_inc_unchecked((atomic_unchecked_t *)&class->ops);
68501 if (very_verbose(class)) {
68502 printk("\nacquire class [%p] %s", class->key, class->name);
68503 if (class->name_version > 1)
68504diff --git a/kernel/lockdep_proc.c b/kernel/lockdep_proc.c
68505index 91c32a0..7b88d63 100644
68506--- a/kernel/lockdep_proc.c
68507+++ b/kernel/lockdep_proc.c
68508@@ -39,7 +39,7 @@ static void l_stop(struct seq_file *m, void *v)
68509
68510 static void print_name(struct seq_file *m, struct lock_class *class)
68511 {
68512- char str[128];
68513+ char str[KSYM_NAME_LEN];
68514 const char *name = class->name;
68515
68516 if (!name) {
68517@@ -65,7 +65,7 @@ static int l_show(struct seq_file *m, void *v)
68518 return 0;
68519 }
68520
68521- seq_printf(m, "%p", class->key);
68522+ seq_printf(m, "%pK", class->key);
68523 #ifdef CONFIG_DEBUG_LOCKDEP
68524 seq_printf(m, " OPS:%8ld", class->ops);
68525 #endif
68526@@ -83,7 +83,7 @@ static int l_show(struct seq_file *m, void *v)
68527
68528 list_for_each_entry(entry, &class->locks_after, entry) {
68529 if (entry->distance == 1) {
68530- seq_printf(m, " -> [%p] ", entry->class->key);
68531+ seq_printf(m, " -> [%pK] ", entry->class->key);
68532 print_name(m, entry->class);
68533 seq_puts(m, "\n");
68534 }
68535@@ -152,7 +152,7 @@ static int lc_show(struct seq_file *m, void *v)
68536 if (!class->key)
68537 continue;
68538
68539- seq_printf(m, "[%p] ", class->key);
68540+ seq_printf(m, "[%pK] ", class->key);
68541 print_name(m, class);
68542 seq_puts(m, "\n");
68543 }
68544@@ -495,7 +495,7 @@ static void seq_stats(struct seq_file *m, struct lock_stat_data *data)
68545 if (!i)
68546 seq_line(m, '-', 40-namelen, namelen);
68547
68548- snprintf(ip, sizeof(ip), "[<%p>]",
68549+ snprintf(ip, sizeof(ip), "[<%pK>]",
68550 (void *)class->contention_point[i]);
68551 seq_printf(m, "%40s %14lu %29s %pS\n",
68552 name, stats->contention_point[i],
68553@@ -510,7 +510,7 @@ static void seq_stats(struct seq_file *m, struct lock_stat_data *data)
68554 if (!i)
68555 seq_line(m, '-', 40-namelen, namelen);
68556
68557- snprintf(ip, sizeof(ip), "[<%p>]",
68558+ snprintf(ip, sizeof(ip), "[<%pK>]",
68559 (void *)class->contending_point[i]);
68560 seq_printf(m, "%40s %14lu %29s %pS\n",
68561 name, stats->contending_point[i],
68562diff --git a/kernel/module.c b/kernel/module.c
68563index 9ad9ee9..731c128 100644
68564--- a/kernel/module.c
68565+++ b/kernel/module.c
68566@@ -58,6 +58,7 @@
68567 #include <linux/jump_label.h>
68568 #include <linux/pfn.h>
68569 #include <linux/bsearch.h>
68570+#include <linux/grsecurity.h>
68571
68572 #define CREATE_TRACE_POINTS
68573 #include <trace/events/module.h>
68574@@ -114,7 +115,8 @@ static BLOCKING_NOTIFIER_HEAD(module_notify_list);
68575
68576 /* Bounds of module allocation, for speeding __module_address.
68577 * Protected by module_mutex. */
68578-static unsigned long module_addr_min = -1UL, module_addr_max = 0;
68579+static unsigned long module_addr_min_rw = -1UL, module_addr_max_rw = 0;
68580+static unsigned long module_addr_min_rx = -1UL, module_addr_max_rx = 0;
68581
68582 int register_module_notifier(struct notifier_block * nb)
68583 {
68584@@ -278,7 +280,7 @@ bool each_symbol_section(bool (*fn)(const struct symsearch *arr,
68585 return true;
68586
68587 list_for_each_entry_rcu(mod, &modules, list) {
68588- struct symsearch arr[] = {
68589+ struct symsearch modarr[] = {
68590 { mod->syms, mod->syms + mod->num_syms, mod->crcs,
68591 NOT_GPL_ONLY, false },
68592 { mod->gpl_syms, mod->gpl_syms + mod->num_gpl_syms,
68593@@ -300,7 +302,7 @@ bool each_symbol_section(bool (*fn)(const struct symsearch *arr,
68594 #endif
68595 };
68596
68597- if (each_symbol_in_section(arr, ARRAY_SIZE(arr), mod, fn, data))
68598+ if (each_symbol_in_section(modarr, ARRAY_SIZE(modarr), mod, fn, data))
68599 return true;
68600 }
68601 return false;
68602@@ -432,7 +434,7 @@ static inline void __percpu *mod_percpu(struct module *mod)
68603 static int percpu_modalloc(struct module *mod,
68604 unsigned long size, unsigned long align)
68605 {
68606- if (align > PAGE_SIZE) {
68607+ if (align-1 >= PAGE_SIZE) {
68608 printk(KERN_WARNING "%s: per-cpu alignment %li > %li\n",
68609 mod->name, align, PAGE_SIZE);
68610 align = PAGE_SIZE;
68611@@ -1032,7 +1034,7 @@ struct module_attribute module_uevent =
68612 static ssize_t show_coresize(struct module_attribute *mattr,
68613 struct module_kobject *mk, char *buffer)
68614 {
68615- return sprintf(buffer, "%u\n", mk->mod->core_size);
68616+ return sprintf(buffer, "%u\n", mk->mod->core_size_rx + mk->mod->core_size_rw);
68617 }
68618
68619 static struct module_attribute modinfo_coresize =
68620@@ -1041,7 +1043,7 @@ static struct module_attribute modinfo_coresize =
68621 static ssize_t show_initsize(struct module_attribute *mattr,
68622 struct module_kobject *mk, char *buffer)
68623 {
68624- return sprintf(buffer, "%u\n", mk->mod->init_size);
68625+ return sprintf(buffer, "%u\n", mk->mod->init_size_rx + mk->mod->init_size_rw);
68626 }
68627
68628 static struct module_attribute modinfo_initsize =
68629@@ -1255,7 +1257,7 @@ resolve_symbol_wait(struct module *mod,
68630 */
68631 #ifdef CONFIG_SYSFS
68632
68633-#ifdef CONFIG_KALLSYMS
68634+#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
68635 static inline bool sect_empty(const Elf_Shdr *sect)
68636 {
68637 return !(sect->sh_flags & SHF_ALLOC) || sect->sh_size == 0;
68638@@ -1721,21 +1723,21 @@ static void set_section_ro_nx(void *base,
68639
68640 static void unset_module_core_ro_nx(struct module *mod)
68641 {
68642- set_page_attributes(mod->module_core + mod->core_text_size,
68643- mod->module_core + mod->core_size,
68644+ set_page_attributes(mod->module_core_rw,
68645+ mod->module_core_rw + mod->core_size_rw,
68646 set_memory_x);
68647- set_page_attributes(mod->module_core,
68648- mod->module_core + mod->core_ro_size,
68649+ set_page_attributes(mod->module_core_rx,
68650+ mod->module_core_rx + mod->core_size_rx,
68651 set_memory_rw);
68652 }
68653
68654 static void unset_module_init_ro_nx(struct module *mod)
68655 {
68656- set_page_attributes(mod->module_init + mod->init_text_size,
68657- mod->module_init + mod->init_size,
68658+ set_page_attributes(mod->module_init_rw,
68659+ mod->module_init_rw + mod->init_size_rw,
68660 set_memory_x);
68661- set_page_attributes(mod->module_init,
68662- mod->module_init + mod->init_ro_size,
68663+ set_page_attributes(mod->module_init_rx,
68664+ mod->module_init_rx + mod->init_size_rx,
68665 set_memory_rw);
68666 }
68667
68668@@ -1746,14 +1748,14 @@ void set_all_modules_text_rw(void)
68669
68670 mutex_lock(&module_mutex);
68671 list_for_each_entry_rcu(mod, &modules, list) {
68672- if ((mod->module_core) && (mod->core_text_size)) {
68673- set_page_attributes(mod->module_core,
68674- mod->module_core + mod->core_text_size,
68675+ if ((mod->module_core_rx) && (mod->core_size_rx)) {
68676+ set_page_attributes(mod->module_core_rx,
68677+ mod->module_core_rx + mod->core_size_rx,
68678 set_memory_rw);
68679 }
68680- if ((mod->module_init) && (mod->init_text_size)) {
68681- set_page_attributes(mod->module_init,
68682- mod->module_init + mod->init_text_size,
68683+ if ((mod->module_init_rx) && (mod->init_size_rx)) {
68684+ set_page_attributes(mod->module_init_rx,
68685+ mod->module_init_rx + mod->init_size_rx,
68686 set_memory_rw);
68687 }
68688 }
68689@@ -1767,14 +1769,14 @@ void set_all_modules_text_ro(void)
68690
68691 mutex_lock(&module_mutex);
68692 list_for_each_entry_rcu(mod, &modules, list) {
68693- if ((mod->module_core) && (mod->core_text_size)) {
68694- set_page_attributes(mod->module_core,
68695- mod->module_core + mod->core_text_size,
68696+ if ((mod->module_core_rx) && (mod->core_size_rx)) {
68697+ set_page_attributes(mod->module_core_rx,
68698+ mod->module_core_rx + mod->core_size_rx,
68699 set_memory_ro);
68700 }
68701- if ((mod->module_init) && (mod->init_text_size)) {
68702- set_page_attributes(mod->module_init,
68703- mod->module_init + mod->init_text_size,
68704+ if ((mod->module_init_rx) && (mod->init_size_rx)) {
68705+ set_page_attributes(mod->module_init_rx,
68706+ mod->module_init_rx + mod->init_size_rx,
68707 set_memory_ro);
68708 }
68709 }
68710@@ -1820,16 +1822,19 @@ static void free_module(struct module *mod)
68711
68712 /* This may be NULL, but that's OK */
68713 unset_module_init_ro_nx(mod);
68714- module_free(mod, mod->module_init);
68715+ module_free(mod, mod->module_init_rw);
68716+ module_free_exec(mod, mod->module_init_rx);
68717 kfree(mod->args);
68718 percpu_modfree(mod);
68719
68720 /* Free lock-classes: */
68721- lockdep_free_key_range(mod->module_core, mod->core_size);
68722+ lockdep_free_key_range(mod->module_core_rx, mod->core_size_rx);
68723+ lockdep_free_key_range(mod->module_core_rw, mod->core_size_rw);
68724
68725 /* Finally, free the core (containing the module structure) */
68726 unset_module_core_ro_nx(mod);
68727- module_free(mod, mod->module_core);
68728+ module_free_exec(mod, mod->module_core_rx);
68729+ module_free(mod, mod->module_core_rw);
68730
68731 #ifdef CONFIG_MPU
68732 update_protections(current->mm);
68733@@ -1899,9 +1904,31 @@ static int simplify_symbols(struct module *mod, const struct load_info *info)
68734 int ret = 0;
68735 const struct kernel_symbol *ksym;
68736
68737+#ifdef CONFIG_GRKERNSEC_MODHARDEN
68738+ int is_fs_load = 0;
68739+ int register_filesystem_found = 0;
68740+ char *p;
68741+
68742+ p = strstr(mod->args, "grsec_modharden_fs");
68743+ if (p) {
68744+ char *endptr = p + sizeof("grsec_modharden_fs") - 1;
68745+ /* copy \0 as well */
68746+ memmove(p, endptr, strlen(mod->args) - (unsigned int)(endptr - mod->args) + 1);
68747+ is_fs_load = 1;
68748+ }
68749+#endif
68750+
68751 for (i = 1; i < symsec->sh_size / sizeof(Elf_Sym); i++) {
68752 const char *name = info->strtab + sym[i].st_name;
68753
68754+#ifdef CONFIG_GRKERNSEC_MODHARDEN
68755+ /* it's a real shame this will never get ripped and copied
68756+ upstream! ;(
68757+ */
68758+ if (is_fs_load && !strcmp(name, "register_filesystem"))
68759+ register_filesystem_found = 1;
68760+#endif
68761+
68762 switch (sym[i].st_shndx) {
68763 case SHN_COMMON:
68764 /* We compiled with -fno-common. These are not
68765@@ -1922,7 +1949,9 @@ static int simplify_symbols(struct module *mod, const struct load_info *info)
68766 ksym = resolve_symbol_wait(mod, info, name);
68767 /* Ok if resolved. */
68768 if (ksym && !IS_ERR(ksym)) {
68769+ pax_open_kernel();
68770 sym[i].st_value = ksym->value;
68771+ pax_close_kernel();
68772 break;
68773 }
68774
68775@@ -1941,11 +1970,20 @@ static int simplify_symbols(struct module *mod, const struct load_info *info)
68776 secbase = (unsigned long)mod_percpu(mod);
68777 else
68778 secbase = info->sechdrs[sym[i].st_shndx].sh_addr;
68779+ pax_open_kernel();
68780 sym[i].st_value += secbase;
68781+ pax_close_kernel();
68782 break;
68783 }
68784 }
68785
68786+#ifdef CONFIG_GRKERNSEC_MODHARDEN
68787+ if (is_fs_load && !register_filesystem_found) {
68788+ printk(KERN_ALERT "grsec: Denied attempt to load non-fs module %.64s through mount\n", mod->name);
68789+ ret = -EPERM;
68790+ }
68791+#endif
68792+
68793 return ret;
68794 }
68795
68796@@ -2049,22 +2087,12 @@ static void layout_sections(struct module *mod, struct load_info *info)
68797 || s->sh_entsize != ~0UL
68798 || strstarts(sname, ".init"))
68799 continue;
68800- s->sh_entsize = get_offset(mod, &mod->core_size, s, i);
68801+ if ((s->sh_flags & SHF_WRITE) || !(s->sh_flags & SHF_ALLOC))
68802+ s->sh_entsize = get_offset(mod, &mod->core_size_rw, s, i);
68803+ else
68804+ s->sh_entsize = get_offset(mod, &mod->core_size_rx, s, i);
68805 pr_debug("\t%s\n", sname);
68806 }
68807- switch (m) {
68808- case 0: /* executable */
68809- mod->core_size = debug_align(mod->core_size);
68810- mod->core_text_size = mod->core_size;
68811- break;
68812- case 1: /* RO: text and ro-data */
68813- mod->core_size = debug_align(mod->core_size);
68814- mod->core_ro_size = mod->core_size;
68815- break;
68816- case 3: /* whole core */
68817- mod->core_size = debug_align(mod->core_size);
68818- break;
68819- }
68820 }
68821
68822 pr_debug("Init section allocation order:\n");
68823@@ -2078,23 +2106,13 @@ static void layout_sections(struct module *mod, struct load_info *info)
68824 || s->sh_entsize != ~0UL
68825 || !strstarts(sname, ".init"))
68826 continue;
68827- s->sh_entsize = (get_offset(mod, &mod->init_size, s, i)
68828- | INIT_OFFSET_MASK);
68829+ if ((s->sh_flags & SHF_WRITE) || !(s->sh_flags & SHF_ALLOC))
68830+ s->sh_entsize = get_offset(mod, &mod->init_size_rw, s, i);
68831+ else
68832+ s->sh_entsize = get_offset(mod, &mod->init_size_rx, s, i);
68833+ s->sh_entsize |= INIT_OFFSET_MASK;
68834 pr_debug("\t%s\n", sname);
68835 }
68836- switch (m) {
68837- case 0: /* executable */
68838- mod->init_size = debug_align(mod->init_size);
68839- mod->init_text_size = mod->init_size;
68840- break;
68841- case 1: /* RO: text and ro-data */
68842- mod->init_size = debug_align(mod->init_size);
68843- mod->init_ro_size = mod->init_size;
68844- break;
68845- case 3: /* whole init */
68846- mod->init_size = debug_align(mod->init_size);
68847- break;
68848- }
68849 }
68850 }
68851
68852@@ -2266,28 +2284,33 @@ static void layout_symtab(struct module *mod, struct load_info *info)
68853
68854 /* Put symbol section at end of init part of module. */
68855 symsect->sh_flags |= SHF_ALLOC;
68856- symsect->sh_entsize = get_offset(mod, &mod->init_size, symsect,
68857+ symsect->sh_entsize = get_offset(mod, &mod->init_size_rx, symsect,
68858 info->index.sym) | INIT_OFFSET_MASK;
68859 pr_debug("\t%s\n", info->secstrings + symsect->sh_name);
68860
68861 src = (void *)info->hdr + symsect->sh_offset;
68862 nsrc = symsect->sh_size / sizeof(*src);
68863
68864+ /* strtab always starts with a nul, so offset 0 is the empty string. */
68865+ strtab_size = 1;
68866+
68867 /* Compute total space required for the core symbols' strtab. */
68868- for (ndst = i = strtab_size = 1; i < nsrc; ++i, ++src)
68869- if (is_core_symbol(src, info->sechdrs, info->hdr->e_shnum)) {
68870- strtab_size += strlen(&info->strtab[src->st_name]) + 1;
68871+ for (ndst = i = 0; i < nsrc; i++) {
68872+ if (i == 0 ||
68873+ is_core_symbol(src+i, info->sechdrs, info->hdr->e_shnum)) {
68874+ strtab_size += strlen(&info->strtab[src[i].st_name])+1;
68875 ndst++;
68876 }
68877+ }
68878
68879 /* Append room for core symbols at end of core part. */
68880- info->symoffs = ALIGN(mod->core_size, symsect->sh_addralign ?: 1);
68881- info->stroffs = mod->core_size = info->symoffs + ndst * sizeof(Elf_Sym);
68882- mod->core_size += strtab_size;
68883+ info->symoffs = ALIGN(mod->core_size_rx, symsect->sh_addralign ?: 1);
68884+ info->stroffs = mod->core_size_rx = info->symoffs + ndst * sizeof(Elf_Sym);
68885+ mod->core_size_rx += strtab_size;
68886
68887 /* Put string table section at end of init part of module. */
68888 strsect->sh_flags |= SHF_ALLOC;
68889- strsect->sh_entsize = get_offset(mod, &mod->init_size, strsect,
68890+ strsect->sh_entsize = get_offset(mod, &mod->init_size_rx, strsect,
68891 info->index.str) | INIT_OFFSET_MASK;
68892 pr_debug("\t%s\n", info->secstrings + strsect->sh_name);
68893 }
68894@@ -2305,24 +2328,28 @@ static void add_kallsyms(struct module *mod, const struct load_info *info)
68895 /* Make sure we get permanent strtab: don't use info->strtab. */
68896 mod->strtab = (void *)info->sechdrs[info->index.str].sh_addr;
68897
68898+ pax_open_kernel();
68899+
68900 /* Set types up while we still have access to sections. */
68901 for (i = 0; i < mod->num_symtab; i++)
68902 mod->symtab[i].st_info = elf_type(&mod->symtab[i], info);
68903
68904- mod->core_symtab = dst = mod->module_core + info->symoffs;
68905- mod->core_strtab = s = mod->module_core + info->stroffs;
68906+ mod->core_symtab = dst = mod->module_core_rx + info->symoffs;
68907+ mod->core_strtab = s = mod->module_core_rx + info->stroffs;
68908 src = mod->symtab;
68909- *dst = *src;
68910 *s++ = 0;
68911- for (ndst = i = 1; i < mod->num_symtab; ++i, ++src) {
68912- if (!is_core_symbol(src, info->sechdrs, info->hdr->e_shnum))
68913- continue;
68914-
68915- dst[ndst] = *src;
68916- dst[ndst++].st_name = s - mod->core_strtab;
68917- s += strlcpy(s, &mod->strtab[src->st_name], KSYM_NAME_LEN) + 1;
68918+ for (ndst = i = 0; i < mod->num_symtab; i++) {
68919+ if (i == 0 ||
68920+ is_core_symbol(src+i, info->sechdrs, info->hdr->e_shnum)) {
68921+ dst[ndst] = src[i];
68922+ dst[ndst++].st_name = s - mod->core_strtab;
68923+ s += strlcpy(s, &mod->strtab[src[i].st_name],
68924+ KSYM_NAME_LEN) + 1;
68925+ }
68926 }
68927 mod->core_num_syms = ndst;
68928+
68929+ pax_close_kernel();
68930 }
68931 #else
68932 static inline void layout_symtab(struct module *mod, struct load_info *info)
68933@@ -2356,17 +2383,33 @@ void * __weak module_alloc(unsigned long size)
68934 return size == 0 ? NULL : vmalloc_exec(size);
68935 }
68936
68937-static void *module_alloc_update_bounds(unsigned long size)
68938+static void *module_alloc_update_bounds_rw(unsigned long size)
68939 {
68940 void *ret = module_alloc(size);
68941
68942 if (ret) {
68943 mutex_lock(&module_mutex);
68944 /* Update module bounds. */
68945- if ((unsigned long)ret < module_addr_min)
68946- module_addr_min = (unsigned long)ret;
68947- if ((unsigned long)ret + size > module_addr_max)
68948- module_addr_max = (unsigned long)ret + size;
68949+ if ((unsigned long)ret < module_addr_min_rw)
68950+ module_addr_min_rw = (unsigned long)ret;
68951+ if ((unsigned long)ret + size > module_addr_max_rw)
68952+ module_addr_max_rw = (unsigned long)ret + size;
68953+ mutex_unlock(&module_mutex);
68954+ }
68955+ return ret;
68956+}
68957+
68958+static void *module_alloc_update_bounds_rx(unsigned long size)
68959+{
68960+ void *ret = module_alloc_exec(size);
68961+
68962+ if (ret) {
68963+ mutex_lock(&module_mutex);
68964+ /* Update module bounds. */
68965+ if ((unsigned long)ret < module_addr_min_rx)
68966+ module_addr_min_rx = (unsigned long)ret;
68967+ if ((unsigned long)ret + size > module_addr_max_rx)
68968+ module_addr_max_rx = (unsigned long)ret + size;
68969 mutex_unlock(&module_mutex);
68970 }
68971 return ret;
68972@@ -2544,8 +2587,14 @@ static struct module *setup_load_info(struct load_info *info)
68973 static int check_modinfo(struct module *mod, struct load_info *info)
68974 {
68975 const char *modmagic = get_modinfo(info, "vermagic");
68976+ const char *license = get_modinfo(info, "license");
68977 int err;
68978
68979+#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR
68980+ if (!license || !license_is_gpl_compatible(license))
68981+ return -ENOEXEC;
68982+#endif
68983+
68984 /* This is allowed: modprobe --force will invalidate it. */
68985 if (!modmagic) {
68986 err = try_to_force_load(mod, "bad vermagic");
68987@@ -2568,7 +2617,7 @@ static int check_modinfo(struct module *mod, struct load_info *info)
68988 }
68989
68990 /* Set up license info based on the info section */
68991- set_license(mod, get_modinfo(info, "license"));
68992+ set_license(mod, license);
68993
68994 return 0;
68995 }
68996@@ -2662,7 +2711,7 @@ static int move_module(struct module *mod, struct load_info *info)
68997 void *ptr;
68998
68999 /* Do the allocs. */
69000- ptr = module_alloc_update_bounds(mod->core_size);
69001+ ptr = module_alloc_update_bounds_rw(mod->core_size_rw);
69002 /*
69003 * The pointer to this block is stored in the module structure
69004 * which is inside the block. Just mark it as not being a
69005@@ -2672,23 +2721,50 @@ static int move_module(struct module *mod, struct load_info *info)
69006 if (!ptr)
69007 return -ENOMEM;
69008
69009- memset(ptr, 0, mod->core_size);
69010- mod->module_core = ptr;
69011+ memset(ptr, 0, mod->core_size_rw);
69012+ mod->module_core_rw = ptr;
69013
69014- ptr = module_alloc_update_bounds(mod->init_size);
69015+ ptr = module_alloc_update_bounds_rw(mod->init_size_rw);
69016 /*
69017 * The pointer to this block is stored in the module structure
69018 * which is inside the block. This block doesn't need to be
69019 * scanned as it contains data and code that will be freed
69020 * after the module is initialized.
69021 */
69022- kmemleak_ignore(ptr);
69023- if (!ptr && mod->init_size) {
69024- module_free(mod, mod->module_core);
69025+ kmemleak_not_leak(ptr);
69026+ if (!ptr && mod->init_size_rw) {
69027+ module_free(mod, mod->module_core_rw);
69028 return -ENOMEM;
69029 }
69030- memset(ptr, 0, mod->init_size);
69031- mod->module_init = ptr;
69032+ memset(ptr, 0, mod->init_size_rw);
69033+ mod->module_init_rw = ptr;
69034+
69035+ ptr = module_alloc_update_bounds_rx(mod->core_size_rx);
69036+ kmemleak_not_leak(ptr);
69037+ if (!ptr) {
69038+ module_free(mod, mod->module_init_rw);
69039+ module_free(mod, mod->module_core_rw);
69040+ return -ENOMEM;
69041+ }
69042+
69043+ pax_open_kernel();
69044+ memset(ptr, 0, mod->core_size_rx);
69045+ pax_close_kernel();
69046+ mod->module_core_rx = ptr;
69047+
69048+ ptr = module_alloc_update_bounds_rx(mod->init_size_rx);
69049+ kmemleak_not_leak(ptr);
69050+ if (!ptr && mod->init_size_rx) {
69051+ module_free_exec(mod, mod->module_core_rx);
69052+ module_free(mod, mod->module_init_rw);
69053+ module_free(mod, mod->module_core_rw);
69054+ return -ENOMEM;
69055+ }
69056+
69057+ pax_open_kernel();
69058+ memset(ptr, 0, mod->init_size_rx);
69059+ pax_close_kernel();
69060+ mod->module_init_rx = ptr;
69061
69062 /* Transfer each section which specifies SHF_ALLOC */
69063 pr_debug("final section addresses:\n");
69064@@ -2699,16 +2775,45 @@ static int move_module(struct module *mod, struct load_info *info)
69065 if (!(shdr->sh_flags & SHF_ALLOC))
69066 continue;
69067
69068- if (shdr->sh_entsize & INIT_OFFSET_MASK)
69069- dest = mod->module_init
69070- + (shdr->sh_entsize & ~INIT_OFFSET_MASK);
69071- else
69072- dest = mod->module_core + shdr->sh_entsize;
69073+ if (shdr->sh_entsize & INIT_OFFSET_MASK) {
69074+ if ((shdr->sh_flags & SHF_WRITE) || !(shdr->sh_flags & SHF_ALLOC))
69075+ dest = mod->module_init_rw
69076+ + (shdr->sh_entsize & ~INIT_OFFSET_MASK);
69077+ else
69078+ dest = mod->module_init_rx
69079+ + (shdr->sh_entsize & ~INIT_OFFSET_MASK);
69080+ } else {
69081+ if ((shdr->sh_flags & SHF_WRITE) || !(shdr->sh_flags & SHF_ALLOC))
69082+ dest = mod->module_core_rw + shdr->sh_entsize;
69083+ else
69084+ dest = mod->module_core_rx + shdr->sh_entsize;
69085+ }
69086+
69087+ if (shdr->sh_type != SHT_NOBITS) {
69088+
69089+#ifdef CONFIG_PAX_KERNEXEC
69090+#ifdef CONFIG_X86_64
69091+ if ((shdr->sh_flags & SHF_WRITE) && (shdr->sh_flags & SHF_EXECINSTR))
69092+ set_memory_x((unsigned long)dest, (shdr->sh_size + PAGE_SIZE) >> PAGE_SHIFT);
69093+#endif
69094+ if (!(shdr->sh_flags & SHF_WRITE) && (shdr->sh_flags & SHF_ALLOC)) {
69095+ pax_open_kernel();
69096+ memcpy(dest, (void *)shdr->sh_addr, shdr->sh_size);
69097+ pax_close_kernel();
69098+ } else
69099+#endif
69100
69101- if (shdr->sh_type != SHT_NOBITS)
69102 memcpy(dest, (void *)shdr->sh_addr, shdr->sh_size);
69103+ }
69104 /* Update sh_addr to point to copy in image. */
69105- shdr->sh_addr = (unsigned long)dest;
69106+
69107+#ifdef CONFIG_PAX_KERNEXEC
69108+ if (shdr->sh_flags & SHF_EXECINSTR)
69109+ shdr->sh_addr = ktva_ktla((unsigned long)dest);
69110+ else
69111+#endif
69112+
69113+ shdr->sh_addr = (unsigned long)dest;
69114 pr_debug("\t0x%lx %s\n",
69115 (long)shdr->sh_addr, info->secstrings + shdr->sh_name);
69116 }
69117@@ -2763,12 +2868,12 @@ static void flush_module_icache(const struct module *mod)
69118 * Do it before processing of module parameters, so the module
69119 * can provide parameter accessor functions of its own.
69120 */
69121- if (mod->module_init)
69122- flush_icache_range((unsigned long)mod->module_init,
69123- (unsigned long)mod->module_init
69124- + mod->init_size);
69125- flush_icache_range((unsigned long)mod->module_core,
69126- (unsigned long)mod->module_core + mod->core_size);
69127+ if (mod->module_init_rx)
69128+ flush_icache_range((unsigned long)mod->module_init_rx,
69129+ (unsigned long)mod->module_init_rx
69130+ + mod->init_size_rx);
69131+ flush_icache_range((unsigned long)mod->module_core_rx,
69132+ (unsigned long)mod->module_core_rx + mod->core_size_rx);
69133
69134 set_fs(old_fs);
69135 }
69136@@ -2838,8 +2943,10 @@ out:
69137 static void module_deallocate(struct module *mod, struct load_info *info)
69138 {
69139 percpu_modfree(mod);
69140- module_free(mod, mod->module_init);
69141- module_free(mod, mod->module_core);
69142+ module_free_exec(mod, mod->module_init_rx);
69143+ module_free_exec(mod, mod->module_core_rx);
69144+ module_free(mod, mod->module_init_rw);
69145+ module_free(mod, mod->module_core_rw);
69146 }
69147
69148 int __weak module_finalize(const Elf_Ehdr *hdr,
69149@@ -2852,7 +2959,9 @@ int __weak module_finalize(const Elf_Ehdr *hdr,
69150 static int post_relocation(struct module *mod, const struct load_info *info)
69151 {
69152 /* Sort exception table now relocations are done. */
69153+ pax_open_kernel();
69154 sort_extable(mod->extable, mod->extable + mod->num_exentries);
69155+ pax_close_kernel();
69156
69157 /* Copy relocated percpu area over. */
69158 percpu_modcopy(mod, (void *)info->sechdrs[info->index.pcpu].sh_addr,
69159@@ -2903,9 +3012,38 @@ static struct module *load_module(void __user *umod,
69160 if (err)
69161 goto free_unload;
69162
69163+ /* Now copy in args */
69164+ mod->args = strndup_user(uargs, ~0UL >> 1);
69165+ if (IS_ERR(mod->args)) {
69166+ err = PTR_ERR(mod->args);
69167+ goto free_unload;
69168+ }
69169+
69170 /* Set up MODINFO_ATTR fields */
69171 setup_modinfo(mod, &info);
69172
69173+#ifdef CONFIG_GRKERNSEC_MODHARDEN
69174+ {
69175+ char *p, *p2;
69176+
69177+ if (strstr(mod->args, "grsec_modharden_netdev")) {
69178+ 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);
69179+ err = -EPERM;
69180+ goto free_modinfo;
69181+ } else if ((p = strstr(mod->args, "grsec_modharden_normal"))) {
69182+ p += sizeof("grsec_modharden_normal") - 1;
69183+ p2 = strstr(p, "_");
69184+ if (p2) {
69185+ *p2 = '\0';
69186+ printk(KERN_ALERT "grsec: denied kernel module auto-load of %.64s by uid %.9s\n", mod->name, p);
69187+ *p2 = '_';
69188+ }
69189+ err = -EPERM;
69190+ goto free_modinfo;
69191+ }
69192+ }
69193+#endif
69194+
69195 /* Fix up syms, so that st_value is a pointer to location. */
69196 err = simplify_symbols(mod, &info);
69197 if (err < 0)
69198@@ -2921,13 +3059,6 @@ static struct module *load_module(void __user *umod,
69199
69200 flush_module_icache(mod);
69201
69202- /* Now copy in args */
69203- mod->args = strndup_user(uargs, ~0UL >> 1);
69204- if (IS_ERR(mod->args)) {
69205- err = PTR_ERR(mod->args);
69206- goto free_arch_cleanup;
69207- }
69208-
69209 /* Mark state as coming so strong_try_module_get() ignores us. */
69210 mod->state = MODULE_STATE_COMING;
69211
69212@@ -2985,11 +3116,10 @@ static struct module *load_module(void __user *umod,
69213 unlock:
69214 mutex_unlock(&module_mutex);
69215 synchronize_sched();
69216- kfree(mod->args);
69217- free_arch_cleanup:
69218 module_arch_cleanup(mod);
69219 free_modinfo:
69220 free_modinfo(mod);
69221+ kfree(mod->args);
69222 free_unload:
69223 module_unload_free(mod);
69224 free_module:
69225@@ -3030,16 +3160,16 @@ SYSCALL_DEFINE3(init_module, void __user *, umod,
69226 MODULE_STATE_COMING, mod);
69227
69228 /* Set RO and NX regions for core */
69229- set_section_ro_nx(mod->module_core,
69230- mod->core_text_size,
69231- mod->core_ro_size,
69232- mod->core_size);
69233+ set_section_ro_nx(mod->module_core_rx,
69234+ mod->core_size_rx,
69235+ mod->core_size_rx,
69236+ mod->core_size_rx);
69237
69238 /* Set RO and NX regions for init */
69239- set_section_ro_nx(mod->module_init,
69240- mod->init_text_size,
69241- mod->init_ro_size,
69242- mod->init_size);
69243+ set_section_ro_nx(mod->module_init_rx,
69244+ mod->init_size_rx,
69245+ mod->init_size_rx,
69246+ mod->init_size_rx);
69247
69248 do_mod_ctors(mod);
69249 /* Start the module */
69250@@ -3085,11 +3215,12 @@ SYSCALL_DEFINE3(init_module, void __user *, umod,
69251 mod->strtab = mod->core_strtab;
69252 #endif
69253 unset_module_init_ro_nx(mod);
69254- module_free(mod, mod->module_init);
69255- mod->module_init = NULL;
69256- mod->init_size = 0;
69257- mod->init_ro_size = 0;
69258- mod->init_text_size = 0;
69259+ module_free(mod, mod->module_init_rw);
69260+ module_free_exec(mod, mod->module_init_rx);
69261+ mod->module_init_rw = NULL;
69262+ mod->module_init_rx = NULL;
69263+ mod->init_size_rw = 0;
69264+ mod->init_size_rx = 0;
69265 mutex_unlock(&module_mutex);
69266
69267 return 0;
69268@@ -3120,10 +3251,16 @@ static const char *get_ksymbol(struct module *mod,
69269 unsigned long nextval;
69270
69271 /* At worse, next value is at end of module */
69272- if (within_module_init(addr, mod))
69273- nextval = (unsigned long)mod->module_init+mod->init_text_size;
69274+ if (within_module_init_rx(addr, mod))
69275+ nextval = (unsigned long)mod->module_init_rx+mod->init_size_rx;
69276+ else if (within_module_init_rw(addr, mod))
69277+ nextval = (unsigned long)mod->module_init_rw+mod->init_size_rw;
69278+ else if (within_module_core_rx(addr, mod))
69279+ nextval = (unsigned long)mod->module_core_rx+mod->core_size_rx;
69280+ else if (within_module_core_rw(addr, mod))
69281+ nextval = (unsigned long)mod->module_core_rw+mod->core_size_rw;
69282 else
69283- nextval = (unsigned long)mod->module_core+mod->core_text_size;
69284+ return NULL;
69285
69286 /* Scan for closest preceding symbol, and next symbol. (ELF
69287 starts real symbols at 1). */
69288@@ -3358,7 +3495,7 @@ static int m_show(struct seq_file *m, void *p)
69289 char buf[8];
69290
69291 seq_printf(m, "%s %u",
69292- mod->name, mod->init_size + mod->core_size);
69293+ mod->name, mod->init_size_rx + mod->init_size_rw + mod->core_size_rx + mod->core_size_rw);
69294 print_unload_info(m, mod);
69295
69296 /* Informative for users. */
69297@@ -3367,7 +3504,7 @@ static int m_show(struct seq_file *m, void *p)
69298 mod->state == MODULE_STATE_COMING ? "Loading":
69299 "Live");
69300 /* Used by oprofile and other similar tools. */
69301- seq_printf(m, " 0x%pK", mod->module_core);
69302+ seq_printf(m, " 0x%pK 0x%pK", mod->module_core_rx, mod->module_core_rw);
69303
69304 /* Taints info */
69305 if (mod->taints)
69306@@ -3403,7 +3540,17 @@ static const struct file_operations proc_modules_operations = {
69307
69308 static int __init proc_modules_init(void)
69309 {
69310+#ifndef CONFIG_GRKERNSEC_HIDESYM
69311+#ifdef CONFIG_GRKERNSEC_PROC_USER
69312+ proc_create("modules", S_IRUSR, NULL, &proc_modules_operations);
69313+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
69314+ proc_create("modules", S_IRUSR | S_IRGRP, NULL, &proc_modules_operations);
69315+#else
69316 proc_create("modules", 0, NULL, &proc_modules_operations);
69317+#endif
69318+#else
69319+ proc_create("modules", S_IRUSR, NULL, &proc_modules_operations);
69320+#endif
69321 return 0;
69322 }
69323 module_init(proc_modules_init);
69324@@ -3462,12 +3609,12 @@ struct module *__module_address(unsigned long addr)
69325 {
69326 struct module *mod;
69327
69328- if (addr < module_addr_min || addr > module_addr_max)
69329+ if ((addr < module_addr_min_rx || addr > module_addr_max_rx) &&
69330+ (addr < module_addr_min_rw || addr > module_addr_max_rw))
69331 return NULL;
69332
69333 list_for_each_entry_rcu(mod, &modules, list)
69334- if (within_module_core(addr, mod)
69335- || within_module_init(addr, mod))
69336+ if (within_module_init(addr, mod) || within_module_core(addr, mod))
69337 return mod;
69338 return NULL;
69339 }
69340@@ -3501,11 +3648,20 @@ bool is_module_text_address(unsigned long addr)
69341 */
69342 struct module *__module_text_address(unsigned long addr)
69343 {
69344- struct module *mod = __module_address(addr);
69345+ struct module *mod;
69346+
69347+#ifdef CONFIG_X86_32
69348+ addr = ktla_ktva(addr);
69349+#endif
69350+
69351+ if (addr < module_addr_min_rx || addr > module_addr_max_rx)
69352+ return NULL;
69353+
69354+ mod = __module_address(addr);
69355+
69356 if (mod) {
69357 /* Make sure it's within the text section. */
69358- if (!within(addr, mod->module_init, mod->init_text_size)
69359- && !within(addr, mod->module_core, mod->core_text_size))
69360+ if (!within_module_init_rx(addr, mod) && !within_module_core_rx(addr, mod))
69361 mod = NULL;
69362 }
69363 return mod;
69364diff --git a/kernel/mutex-debug.c b/kernel/mutex-debug.c
69365index 7e3443f..b2a1e6b 100644
69366--- a/kernel/mutex-debug.c
69367+++ b/kernel/mutex-debug.c
69368@@ -49,21 +49,21 @@ void debug_mutex_free_waiter(struct mutex_waiter *waiter)
69369 }
69370
69371 void debug_mutex_add_waiter(struct mutex *lock, struct mutex_waiter *waiter,
69372- struct thread_info *ti)
69373+ struct task_struct *task)
69374 {
69375 SMP_DEBUG_LOCKS_WARN_ON(!spin_is_locked(&lock->wait_lock));
69376
69377 /* Mark the current thread as blocked on the lock: */
69378- ti->task->blocked_on = waiter;
69379+ task->blocked_on = waiter;
69380 }
69381
69382 void mutex_remove_waiter(struct mutex *lock, struct mutex_waiter *waiter,
69383- struct thread_info *ti)
69384+ struct task_struct *task)
69385 {
69386 DEBUG_LOCKS_WARN_ON(list_empty(&waiter->list));
69387- DEBUG_LOCKS_WARN_ON(waiter->task != ti->task);
69388- DEBUG_LOCKS_WARN_ON(ti->task->blocked_on != waiter);
69389- ti->task->blocked_on = NULL;
69390+ DEBUG_LOCKS_WARN_ON(waiter->task != task);
69391+ DEBUG_LOCKS_WARN_ON(task->blocked_on != waiter);
69392+ task->blocked_on = NULL;
69393
69394 list_del_init(&waiter->list);
69395 waiter->task = NULL;
69396diff --git a/kernel/mutex-debug.h b/kernel/mutex-debug.h
69397index 0799fd3..d06ae3b 100644
69398--- a/kernel/mutex-debug.h
69399+++ b/kernel/mutex-debug.h
69400@@ -20,9 +20,9 @@ extern void debug_mutex_wake_waiter(struct mutex *lock,
69401 extern void debug_mutex_free_waiter(struct mutex_waiter *waiter);
69402 extern void debug_mutex_add_waiter(struct mutex *lock,
69403 struct mutex_waiter *waiter,
69404- struct thread_info *ti);
69405+ struct task_struct *task);
69406 extern void mutex_remove_waiter(struct mutex *lock, struct mutex_waiter *waiter,
69407- struct thread_info *ti);
69408+ struct task_struct *task);
69409 extern void debug_mutex_unlock(struct mutex *lock);
69410 extern void debug_mutex_init(struct mutex *lock, const char *name,
69411 struct lock_class_key *key);
69412diff --git a/kernel/mutex.c b/kernel/mutex.c
69413index a307cc9..27fd2e9 100644
69414--- a/kernel/mutex.c
69415+++ b/kernel/mutex.c
69416@@ -198,7 +198,7 @@ __mutex_lock_common(struct mutex *lock, long state, unsigned int subclass,
69417 spin_lock_mutex(&lock->wait_lock, flags);
69418
69419 debug_mutex_lock_common(lock, &waiter);
69420- debug_mutex_add_waiter(lock, &waiter, task_thread_info(task));
69421+ debug_mutex_add_waiter(lock, &waiter, task);
69422
69423 /* add waiting tasks to the end of the waitqueue (FIFO): */
69424 list_add_tail(&waiter.list, &lock->wait_list);
69425@@ -227,8 +227,7 @@ __mutex_lock_common(struct mutex *lock, long state, unsigned int subclass,
69426 * TASK_UNINTERRUPTIBLE case.)
69427 */
69428 if (unlikely(signal_pending_state(state, task))) {
69429- mutex_remove_waiter(lock, &waiter,
69430- task_thread_info(task));
69431+ mutex_remove_waiter(lock, &waiter, task);
69432 mutex_release(&lock->dep_map, 1, ip);
69433 spin_unlock_mutex(&lock->wait_lock, flags);
69434
69435@@ -247,7 +246,7 @@ __mutex_lock_common(struct mutex *lock, long state, unsigned int subclass,
69436 done:
69437 lock_acquired(&lock->dep_map, ip);
69438 /* got the lock - rejoice! */
69439- mutex_remove_waiter(lock, &waiter, current_thread_info());
69440+ mutex_remove_waiter(lock, &waiter, task);
69441 mutex_set_owner(lock);
69442
69443 /* set it to 0 if there are no waiters left: */
69444diff --git a/kernel/panic.c b/kernel/panic.c
69445index e1b2822..5edc1d9 100644
69446--- a/kernel/panic.c
69447+++ b/kernel/panic.c
69448@@ -410,7 +410,7 @@ static void warn_slowpath_common(const char *file, int line, void *caller,
69449 const char *board;
69450
69451 printk(KERN_WARNING "------------[ cut here ]------------\n");
69452- printk(KERN_WARNING "WARNING: at %s:%d %pS()\n", file, line, caller);
69453+ printk(KERN_WARNING "WARNING: at %s:%d %pA()\n", file, line, caller);
69454 board = dmi_get_system_info(DMI_PRODUCT_NAME);
69455 if (board)
69456 printk(KERN_WARNING "Hardware name: %s\n", board);
69457@@ -465,7 +465,8 @@ EXPORT_SYMBOL(warn_slowpath_null);
69458 */
69459 void __stack_chk_fail(void)
69460 {
69461- panic("stack-protector: Kernel stack is corrupted in: %p\n",
69462+ dump_stack();
69463+ panic("stack-protector: Kernel stack is corrupted in: %pA\n",
69464 __builtin_return_address(0));
69465 }
69466 EXPORT_SYMBOL(__stack_chk_fail);
69467diff --git a/kernel/pid.c b/kernel/pid.c
69468index e86b291a..e8b0fb5 100644
69469--- a/kernel/pid.c
69470+++ b/kernel/pid.c
69471@@ -33,6 +33,7 @@
69472 #include <linux/rculist.h>
69473 #include <linux/bootmem.h>
69474 #include <linux/hash.h>
69475+#include <linux/security.h>
69476 #include <linux/pid_namespace.h>
69477 #include <linux/init_task.h>
69478 #include <linux/syscalls.h>
69479@@ -45,7 +46,7 @@ struct pid init_struct_pid = INIT_STRUCT_PID;
69480
69481 int pid_max = PID_MAX_DEFAULT;
69482
69483-#define RESERVED_PIDS 300
69484+#define RESERVED_PIDS 500
69485
69486 int pid_max_min = RESERVED_PIDS + 1;
69487 int pid_max_max = PID_MAX_LIMIT;
69488@@ -420,10 +421,18 @@ EXPORT_SYMBOL(pid_task);
69489 */
69490 struct task_struct *find_task_by_pid_ns(pid_t nr, struct pid_namespace *ns)
69491 {
69492+ struct task_struct *task;
69493+
69494 rcu_lockdep_assert(rcu_read_lock_held(),
69495 "find_task_by_pid_ns() needs rcu_read_lock()"
69496 " protection");
69497- return pid_task(find_pid_ns(nr, ns), PIDTYPE_PID);
69498+
69499+ task = pid_task(find_pid_ns(nr, ns), PIDTYPE_PID);
69500+
69501+ if (gr_pid_is_chrooted(task))
69502+ return NULL;
69503+
69504+ return task;
69505 }
69506
69507 struct task_struct *find_task_by_vpid(pid_t vnr)
69508@@ -431,6 +440,14 @@ struct task_struct *find_task_by_vpid(pid_t vnr)
69509 return find_task_by_pid_ns(vnr, current->nsproxy->pid_ns);
69510 }
69511
69512+struct task_struct *find_task_by_vpid_unrestricted(pid_t vnr)
69513+{
69514+ rcu_lockdep_assert(rcu_read_lock_held(),
69515+ "find_task_by_pid_ns() needs rcu_read_lock()"
69516+ " protection");
69517+ return pid_task(find_pid_ns(vnr, current->nsproxy->pid_ns), PIDTYPE_PID);
69518+}
69519+
69520 struct pid *get_task_pid(struct task_struct *task, enum pid_type type)
69521 {
69522 struct pid *pid;
69523diff --git a/kernel/posix-cpu-timers.c b/kernel/posix-cpu-timers.c
69524index 125cb67..a4d1c30 100644
69525--- a/kernel/posix-cpu-timers.c
69526+++ b/kernel/posix-cpu-timers.c
69527@@ -6,6 +6,7 @@
69528 #include <linux/posix-timers.h>
69529 #include <linux/errno.h>
69530 #include <linux/math64.h>
69531+#include <linux/security.h>
69532 #include <asm/uaccess.h>
69533 #include <linux/kernel_stat.h>
69534 #include <trace/events/timer.h>
69535@@ -1578,14 +1579,14 @@ struct k_clock clock_posix_cpu = {
69536
69537 static __init int init_posix_cpu_timers(void)
69538 {
69539- struct k_clock process = {
69540+ static struct k_clock process = {
69541 .clock_getres = process_cpu_clock_getres,
69542 .clock_get = process_cpu_clock_get,
69543 .timer_create = process_cpu_timer_create,
69544 .nsleep = process_cpu_nsleep,
69545 .nsleep_restart = process_cpu_nsleep_restart,
69546 };
69547- struct k_clock thread = {
69548+ static struct k_clock thread = {
69549 .clock_getres = thread_cpu_clock_getres,
69550 .clock_get = thread_cpu_clock_get,
69551 .timer_create = thread_cpu_timer_create,
69552diff --git a/kernel/posix-timers.c b/kernel/posix-timers.c
69553index 69185ae..cc2847a 100644
69554--- a/kernel/posix-timers.c
69555+++ b/kernel/posix-timers.c
69556@@ -43,6 +43,7 @@
69557 #include <linux/idr.h>
69558 #include <linux/posix-clock.h>
69559 #include <linux/posix-timers.h>
69560+#include <linux/grsecurity.h>
69561 #include <linux/syscalls.h>
69562 #include <linux/wait.h>
69563 #include <linux/workqueue.h>
69564@@ -129,7 +130,7 @@ static DEFINE_SPINLOCK(idr_lock);
69565 * which we beg off on and pass to do_sys_settimeofday().
69566 */
69567
69568-static struct k_clock posix_clocks[MAX_CLOCKS];
69569+static struct k_clock *posix_clocks[MAX_CLOCKS];
69570
69571 /*
69572 * These ones are defined below.
69573@@ -227,7 +228,7 @@ static int posix_get_boottime(const clockid_t which_clock, struct timespec *tp)
69574 */
69575 static __init int init_posix_timers(void)
69576 {
69577- struct k_clock clock_realtime = {
69578+ static struct k_clock clock_realtime = {
69579 .clock_getres = hrtimer_get_res,
69580 .clock_get = posix_clock_realtime_get,
69581 .clock_set = posix_clock_realtime_set,
69582@@ -239,7 +240,7 @@ static __init int init_posix_timers(void)
69583 .timer_get = common_timer_get,
69584 .timer_del = common_timer_del,
69585 };
69586- struct k_clock clock_monotonic = {
69587+ static struct k_clock clock_monotonic = {
69588 .clock_getres = hrtimer_get_res,
69589 .clock_get = posix_ktime_get_ts,
69590 .nsleep = common_nsleep,
69591@@ -249,19 +250,19 @@ static __init int init_posix_timers(void)
69592 .timer_get = common_timer_get,
69593 .timer_del = common_timer_del,
69594 };
69595- struct k_clock clock_monotonic_raw = {
69596+ static struct k_clock clock_monotonic_raw = {
69597 .clock_getres = hrtimer_get_res,
69598 .clock_get = posix_get_monotonic_raw,
69599 };
69600- struct k_clock clock_realtime_coarse = {
69601+ static struct k_clock clock_realtime_coarse = {
69602 .clock_getres = posix_get_coarse_res,
69603 .clock_get = posix_get_realtime_coarse,
69604 };
69605- struct k_clock clock_monotonic_coarse = {
69606+ static struct k_clock clock_monotonic_coarse = {
69607 .clock_getres = posix_get_coarse_res,
69608 .clock_get = posix_get_monotonic_coarse,
69609 };
69610- struct k_clock clock_boottime = {
69611+ static struct k_clock clock_boottime = {
69612 .clock_getres = hrtimer_get_res,
69613 .clock_get = posix_get_boottime,
69614 .nsleep = common_nsleep,
69615@@ -473,7 +474,7 @@ void posix_timers_register_clock(const clockid_t clock_id,
69616 return;
69617 }
69618
69619- posix_clocks[clock_id] = *new_clock;
69620+ posix_clocks[clock_id] = new_clock;
69621 }
69622 EXPORT_SYMBOL_GPL(posix_timers_register_clock);
69623
69624@@ -519,9 +520,9 @@ static struct k_clock *clockid_to_kclock(const clockid_t id)
69625 return (id & CLOCKFD_MASK) == CLOCKFD ?
69626 &clock_posix_dynamic : &clock_posix_cpu;
69627
69628- if (id >= MAX_CLOCKS || !posix_clocks[id].clock_getres)
69629+ if (id >= MAX_CLOCKS || !posix_clocks[id] || !posix_clocks[id]->clock_getres)
69630 return NULL;
69631- return &posix_clocks[id];
69632+ return posix_clocks[id];
69633 }
69634
69635 static int common_timer_create(struct k_itimer *new_timer)
69636@@ -959,6 +960,13 @@ SYSCALL_DEFINE2(clock_settime, const clockid_t, which_clock,
69637 if (copy_from_user(&new_tp, tp, sizeof (*tp)))
69638 return -EFAULT;
69639
69640+ /* only the CLOCK_REALTIME clock can be set, all other clocks
69641+ have their clock_set fptr set to a nosettime dummy function
69642+ CLOCK_REALTIME has a NULL clock_set fptr which causes it to
69643+ call common_clock_set, which calls do_sys_settimeofday, which
69644+ we hook
69645+ */
69646+
69647 return kc->clock_set(which_clock, &new_tp);
69648 }
69649
69650diff --git a/kernel/power/poweroff.c b/kernel/power/poweroff.c
69651index d523593..68197a4 100644
69652--- a/kernel/power/poweroff.c
69653+++ b/kernel/power/poweroff.c
69654@@ -37,7 +37,7 @@ static struct sysrq_key_op sysrq_poweroff_op = {
69655 .enable_mask = SYSRQ_ENABLE_BOOT,
69656 };
69657
69658-static int pm_sysrq_init(void)
69659+static int __init pm_sysrq_init(void)
69660 {
69661 register_sysrq_key('o', &sysrq_poweroff_op);
69662 return 0;
69663diff --git a/kernel/power/process.c b/kernel/power/process.c
69664index 19db29f..33b52b6 100644
69665--- a/kernel/power/process.c
69666+++ b/kernel/power/process.c
69667@@ -33,6 +33,7 @@ static int try_to_freeze_tasks(bool user_only)
69668 u64 elapsed_csecs64;
69669 unsigned int elapsed_csecs;
69670 bool wakeup = false;
69671+ bool timedout = false;
69672
69673 do_gettimeofday(&start);
69674
69675@@ -43,6 +44,8 @@ static int try_to_freeze_tasks(bool user_only)
69676
69677 while (true) {
69678 todo = 0;
69679+ if (time_after(jiffies, end_time))
69680+ timedout = true;
69681 read_lock(&tasklist_lock);
69682 do_each_thread(g, p) {
69683 if (p == current || !freeze_task(p))
69684@@ -58,9 +61,13 @@ static int try_to_freeze_tasks(bool user_only)
69685 * guaranteed that TASK_STOPPED/TRACED -> TASK_RUNNING
69686 * transition can't race with task state testing here.
69687 */
69688- if (!task_is_stopped_or_traced(p) &&
69689- !freezer_should_skip(p))
69690+ if (!task_is_stopped_or_traced(p) && !freezer_should_skip(p)) {
69691 todo++;
69692+ if (timedout) {
69693+ printk(KERN_ERR "Task refusing to freeze:\n");
69694+ sched_show_task(p);
69695+ }
69696+ }
69697 } while_each_thread(g, p);
69698 read_unlock(&tasklist_lock);
69699
69700@@ -69,7 +76,7 @@ static int try_to_freeze_tasks(bool user_only)
69701 todo += wq_busy;
69702 }
69703
69704- if (!todo || time_after(jiffies, end_time))
69705+ if (!todo || timedout)
69706 break;
69707
69708 if (pm_wakeup_pending()) {
69709diff --git a/kernel/printk.c b/kernel/printk.c
69710index 66a2ea3..10f3a01 100644
69711--- a/kernel/printk.c
69712+++ b/kernel/printk.c
69713@@ -817,6 +817,11 @@ static int check_syslog_permissions(int type, bool from_file)
69714 if (from_file && type != SYSLOG_ACTION_OPEN)
69715 return 0;
69716
69717+#ifdef CONFIG_GRKERNSEC_DMESG
69718+ if (grsec_enable_dmesg && !capable(CAP_SYSLOG) && !capable_nolog(CAP_SYS_ADMIN))
69719+ return -EPERM;
69720+#endif
69721+
69722 if (syslog_action_restricted(type)) {
69723 if (capable(CAP_SYSLOG))
69724 return 0;
69725diff --git a/kernel/profile.c b/kernel/profile.c
69726index 76b8e77..a2930e8 100644
69727--- a/kernel/profile.c
69728+++ b/kernel/profile.c
69729@@ -39,7 +39,7 @@ struct profile_hit {
69730 /* Oprofile timer tick hook */
69731 static int (*timer_hook)(struct pt_regs *) __read_mostly;
69732
69733-static atomic_t *prof_buffer;
69734+static atomic_unchecked_t *prof_buffer;
69735 static unsigned long prof_len, prof_shift;
69736
69737 int prof_on __read_mostly;
69738@@ -281,7 +281,7 @@ static void profile_flip_buffers(void)
69739 hits[i].pc = 0;
69740 continue;
69741 }
69742- atomic_add(hits[i].hits, &prof_buffer[hits[i].pc]);
69743+ atomic_add_unchecked(hits[i].hits, &prof_buffer[hits[i].pc]);
69744 hits[i].hits = hits[i].pc = 0;
69745 }
69746 }
69747@@ -342,9 +342,9 @@ static void do_profile_hits(int type, void *__pc, unsigned int nr_hits)
69748 * Add the current hit(s) and flush the write-queue out
69749 * to the global buffer:
69750 */
69751- atomic_add(nr_hits, &prof_buffer[pc]);
69752+ atomic_add_unchecked(nr_hits, &prof_buffer[pc]);
69753 for (i = 0; i < NR_PROFILE_HIT; ++i) {
69754- atomic_add(hits[i].hits, &prof_buffer[hits[i].pc]);
69755+ atomic_add_unchecked(hits[i].hits, &prof_buffer[hits[i].pc]);
69756 hits[i].pc = hits[i].hits = 0;
69757 }
69758 out:
69759@@ -419,7 +419,7 @@ static void do_profile_hits(int type, void *__pc, unsigned int nr_hits)
69760 {
69761 unsigned long pc;
69762 pc = ((unsigned long)__pc - (unsigned long)_stext) >> prof_shift;
69763- atomic_add(nr_hits, &prof_buffer[min(pc, prof_len - 1)]);
69764+ atomic_add_unchecked(nr_hits, &prof_buffer[min(pc, prof_len - 1)]);
69765 }
69766 #endif /* !CONFIG_SMP */
69767
69768@@ -517,7 +517,7 @@ read_profile(struct file *file, char __user *buf, size_t count, loff_t *ppos)
69769 return -EFAULT;
69770 buf++; p++; count--; read++;
69771 }
69772- pnt = (char *)prof_buffer + p - sizeof(atomic_t);
69773+ pnt = (char *)prof_buffer + p - sizeof(atomic_unchecked_t);
69774 if (copy_to_user(buf, (void *)pnt, count))
69775 return -EFAULT;
69776 read += count;
69777@@ -548,7 +548,7 @@ static ssize_t write_profile(struct file *file, const char __user *buf,
69778 }
69779 #endif
69780 profile_discard_flip_buffers();
69781- memset(prof_buffer, 0, prof_len * sizeof(atomic_t));
69782+ memset(prof_buffer, 0, prof_len * sizeof(atomic_unchecked_t));
69783 return count;
69784 }
69785
69786diff --git a/kernel/ptrace.c b/kernel/ptrace.c
69787index a232bb5..2a65ef9 100644
69788--- a/kernel/ptrace.c
69789+++ b/kernel/ptrace.c
69790@@ -279,7 +279,7 @@ static int ptrace_attach(struct task_struct *task, long request,
69791
69792 if (seize)
69793 flags |= PT_SEIZED;
69794- if (ns_capable(task_user_ns(task), CAP_SYS_PTRACE))
69795+ if (ns_capable_nolog(task_user_ns(task), CAP_SYS_PTRACE))
69796 flags |= PT_PTRACE_CAP;
69797 task->ptrace = flags;
69798
69799@@ -486,7 +486,7 @@ int ptrace_readdata(struct task_struct *tsk, unsigned long src, char __user *dst
69800 break;
69801 return -EIO;
69802 }
69803- if (copy_to_user(dst, buf, retval))
69804+ if (retval > sizeof(buf) || copy_to_user(dst, buf, retval))
69805 return -EFAULT;
69806 copied += retval;
69807 src += retval;
69808@@ -671,7 +671,7 @@ int ptrace_request(struct task_struct *child, long request,
69809 bool seized = child->ptrace & PT_SEIZED;
69810 int ret = -EIO;
69811 siginfo_t siginfo, *si;
69812- void __user *datavp = (void __user *) data;
69813+ void __user *datavp = (__force void __user *) data;
69814 unsigned long __user *datalp = datavp;
69815 unsigned long flags;
69816
69817@@ -873,14 +873,21 @@ SYSCALL_DEFINE4(ptrace, long, request, long, pid, unsigned long, addr,
69818 goto out;
69819 }
69820
69821+ if (gr_handle_ptrace(child, request)) {
69822+ ret = -EPERM;
69823+ goto out_put_task_struct;
69824+ }
69825+
69826 if (request == PTRACE_ATTACH || request == PTRACE_SEIZE) {
69827 ret = ptrace_attach(child, request, addr, data);
69828 /*
69829 * Some architectures need to do book-keeping after
69830 * a ptrace attach.
69831 */
69832- if (!ret)
69833+ if (!ret) {
69834 arch_ptrace_attach(child);
69835+ gr_audit_ptrace(child);
69836+ }
69837 goto out_put_task_struct;
69838 }
69839
69840@@ -906,7 +913,7 @@ int generic_ptrace_peekdata(struct task_struct *tsk, unsigned long addr,
69841 copied = access_process_vm(tsk, addr, &tmp, sizeof(tmp), 0);
69842 if (copied != sizeof(tmp))
69843 return -EIO;
69844- return put_user(tmp, (unsigned long __user *)data);
69845+ return put_user(tmp, (__force unsigned long __user *)data);
69846 }
69847
69848 int generic_ptrace_pokedata(struct task_struct *tsk, unsigned long addr,
69849@@ -1016,14 +1023,21 @@ asmlinkage long compat_sys_ptrace(compat_long_t request, compat_long_t pid,
69850 goto out;
69851 }
69852
69853+ if (gr_handle_ptrace(child, request)) {
69854+ ret = -EPERM;
69855+ goto out_put_task_struct;
69856+ }
69857+
69858 if (request == PTRACE_ATTACH || request == PTRACE_SEIZE) {
69859 ret = ptrace_attach(child, request, addr, data);
69860 /*
69861 * Some architectures need to do book-keeping after
69862 * a ptrace attach.
69863 */
69864- if (!ret)
69865+ if (!ret) {
69866 arch_ptrace_attach(child);
69867+ gr_audit_ptrace(child);
69868+ }
69869 goto out_put_task_struct;
69870 }
69871
69872diff --git a/kernel/rcutiny.c b/kernel/rcutiny.c
69873index 547b1fe..65e874e 100644
69874--- a/kernel/rcutiny.c
69875+++ b/kernel/rcutiny.c
69876@@ -46,7 +46,7 @@
69877 struct rcu_ctrlblk;
69878 static void invoke_rcu_callbacks(void);
69879 static void __rcu_process_callbacks(struct rcu_ctrlblk *rcp);
69880-static void rcu_process_callbacks(struct softirq_action *unused);
69881+static void rcu_process_callbacks(void);
69882 static void __call_rcu(struct rcu_head *head,
69883 void (*func)(struct rcu_head *rcu),
69884 struct rcu_ctrlblk *rcp);
69885@@ -307,7 +307,7 @@ static void __rcu_process_callbacks(struct rcu_ctrlblk *rcp)
69886 rcu_is_callbacks_kthread()));
69887 }
69888
69889-static void rcu_process_callbacks(struct softirq_action *unused)
69890+static void rcu_process_callbacks(void)
69891 {
69892 __rcu_process_callbacks(&rcu_sched_ctrlblk);
69893 __rcu_process_callbacks(&rcu_bh_ctrlblk);
69894diff --git a/kernel/rcutiny_plugin.h b/kernel/rcutiny_plugin.h
69895index 918fd1e..85089bb 100644
69896--- a/kernel/rcutiny_plugin.h
69897+++ b/kernel/rcutiny_plugin.h
69898@@ -893,7 +893,7 @@ static int rcu_kthread(void *arg)
69899 have_rcu_kthread_work = morework;
69900 local_irq_restore(flags);
69901 if (work)
69902- rcu_process_callbacks(NULL);
69903+ rcu_process_callbacks();
69904 schedule_timeout_interruptible(1); /* Leave CPU for others. */
69905 }
69906
69907diff --git a/kernel/rcutorture.c b/kernel/rcutorture.c
69908index 25b1503..1988a74 100644
69909--- a/kernel/rcutorture.c
69910+++ b/kernel/rcutorture.c
69911@@ -162,12 +162,12 @@ static DEFINE_PER_CPU(long [RCU_TORTURE_PIPE_LEN + 1], rcu_torture_count) =
69912 { 0 };
69913 static DEFINE_PER_CPU(long [RCU_TORTURE_PIPE_LEN + 1], rcu_torture_batch) =
69914 { 0 };
69915-static atomic_t rcu_torture_wcount[RCU_TORTURE_PIPE_LEN + 1];
69916-static atomic_t n_rcu_torture_alloc;
69917-static atomic_t n_rcu_torture_alloc_fail;
69918-static atomic_t n_rcu_torture_free;
69919-static atomic_t n_rcu_torture_mberror;
69920-static atomic_t n_rcu_torture_error;
69921+static atomic_unchecked_t rcu_torture_wcount[RCU_TORTURE_PIPE_LEN + 1];
69922+static atomic_unchecked_t n_rcu_torture_alloc;
69923+static atomic_unchecked_t n_rcu_torture_alloc_fail;
69924+static atomic_unchecked_t n_rcu_torture_free;
69925+static atomic_unchecked_t n_rcu_torture_mberror;
69926+static atomic_unchecked_t n_rcu_torture_error;
69927 static long n_rcu_torture_barrier_error;
69928 static long n_rcu_torture_boost_ktrerror;
69929 static long n_rcu_torture_boost_rterror;
69930@@ -265,11 +265,11 @@ rcu_torture_alloc(void)
69931
69932 spin_lock_bh(&rcu_torture_lock);
69933 if (list_empty(&rcu_torture_freelist)) {
69934- atomic_inc(&n_rcu_torture_alloc_fail);
69935+ atomic_inc_unchecked(&n_rcu_torture_alloc_fail);
69936 spin_unlock_bh(&rcu_torture_lock);
69937 return NULL;
69938 }
69939- atomic_inc(&n_rcu_torture_alloc);
69940+ atomic_inc_unchecked(&n_rcu_torture_alloc);
69941 p = rcu_torture_freelist.next;
69942 list_del_init(p);
69943 spin_unlock_bh(&rcu_torture_lock);
69944@@ -282,7 +282,7 @@ rcu_torture_alloc(void)
69945 static void
69946 rcu_torture_free(struct rcu_torture *p)
69947 {
69948- atomic_inc(&n_rcu_torture_free);
69949+ atomic_inc_unchecked(&n_rcu_torture_free);
69950 spin_lock_bh(&rcu_torture_lock);
69951 list_add_tail(&p->rtort_free, &rcu_torture_freelist);
69952 spin_unlock_bh(&rcu_torture_lock);
69953@@ -403,7 +403,7 @@ rcu_torture_cb(struct rcu_head *p)
69954 i = rp->rtort_pipe_count;
69955 if (i > RCU_TORTURE_PIPE_LEN)
69956 i = RCU_TORTURE_PIPE_LEN;
69957- atomic_inc(&rcu_torture_wcount[i]);
69958+ atomic_inc_unchecked(&rcu_torture_wcount[i]);
69959 if (++rp->rtort_pipe_count >= RCU_TORTURE_PIPE_LEN) {
69960 rp->rtort_mbtest = 0;
69961 rcu_torture_free(rp);
69962@@ -452,7 +452,7 @@ static void rcu_sync_torture_deferred_free(struct rcu_torture *p)
69963 i = rp->rtort_pipe_count;
69964 if (i > RCU_TORTURE_PIPE_LEN)
69965 i = RCU_TORTURE_PIPE_LEN;
69966- atomic_inc(&rcu_torture_wcount[i]);
69967+ atomic_inc_unchecked(&rcu_torture_wcount[i]);
69968 if (++rp->rtort_pipe_count >= RCU_TORTURE_PIPE_LEN) {
69969 rp->rtort_mbtest = 0;
69970 list_del(&rp->rtort_free);
69971@@ -995,7 +995,7 @@ rcu_torture_writer(void *arg)
69972 i = old_rp->rtort_pipe_count;
69973 if (i > RCU_TORTURE_PIPE_LEN)
69974 i = RCU_TORTURE_PIPE_LEN;
69975- atomic_inc(&rcu_torture_wcount[i]);
69976+ atomic_inc_unchecked(&rcu_torture_wcount[i]);
69977 old_rp->rtort_pipe_count++;
69978 cur_ops->deferred_free(old_rp);
69979 }
69980@@ -1080,7 +1080,7 @@ static void rcu_torture_timer(unsigned long unused)
69981 }
69982 do_trace_rcu_torture_read(cur_ops->name, &p->rtort_rcu);
69983 if (p->rtort_mbtest == 0)
69984- atomic_inc(&n_rcu_torture_mberror);
69985+ atomic_inc_unchecked(&n_rcu_torture_mberror);
69986 spin_lock(&rand_lock);
69987 cur_ops->read_delay(&rand);
69988 n_rcu_torture_timers++;
69989@@ -1144,7 +1144,7 @@ rcu_torture_reader(void *arg)
69990 }
69991 do_trace_rcu_torture_read(cur_ops->name, &p->rtort_rcu);
69992 if (p->rtort_mbtest == 0)
69993- atomic_inc(&n_rcu_torture_mberror);
69994+ atomic_inc_unchecked(&n_rcu_torture_mberror);
69995 cur_ops->read_delay(&rand);
69996 preempt_disable();
69997 pipe_count = p->rtort_pipe_count;
69998@@ -1203,11 +1203,11 @@ rcu_torture_printk(char *page)
69999 rcu_torture_current,
70000 rcu_torture_current_version,
70001 list_empty(&rcu_torture_freelist),
70002- atomic_read(&n_rcu_torture_alloc),
70003- atomic_read(&n_rcu_torture_alloc_fail),
70004- atomic_read(&n_rcu_torture_free));
70005+ atomic_read_unchecked(&n_rcu_torture_alloc),
70006+ atomic_read_unchecked(&n_rcu_torture_alloc_fail),
70007+ atomic_read_unchecked(&n_rcu_torture_free));
70008 cnt += sprintf(&page[cnt], "rtmbe: %d rtbke: %ld rtbre: %ld ",
70009- atomic_read(&n_rcu_torture_mberror),
70010+ atomic_read_unchecked(&n_rcu_torture_mberror),
70011 n_rcu_torture_boost_ktrerror,
70012 n_rcu_torture_boost_rterror);
70013 cnt += sprintf(&page[cnt], "rtbf: %ld rtb: %ld nt: %ld ",
70014@@ -1224,14 +1224,14 @@ rcu_torture_printk(char *page)
70015 n_barrier_attempts,
70016 n_rcu_torture_barrier_error);
70017 cnt += sprintf(&page[cnt], "\n%s%s ", torture_type, TORTURE_FLAG);
70018- if (atomic_read(&n_rcu_torture_mberror) != 0 ||
70019+ if (atomic_read_unchecked(&n_rcu_torture_mberror) != 0 ||
70020 n_rcu_torture_barrier_error != 0 ||
70021 n_rcu_torture_boost_ktrerror != 0 ||
70022 n_rcu_torture_boost_rterror != 0 ||
70023 n_rcu_torture_boost_failure != 0 ||
70024 i > 1) {
70025 cnt += sprintf(&page[cnt], "!!! ");
70026- atomic_inc(&n_rcu_torture_error);
70027+ atomic_inc_unchecked(&n_rcu_torture_error);
70028 WARN_ON_ONCE(1);
70029 }
70030 cnt += sprintf(&page[cnt], "Reader Pipe: ");
70031@@ -1245,7 +1245,7 @@ rcu_torture_printk(char *page)
70032 cnt += sprintf(&page[cnt], "Free-Block Circulation: ");
70033 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++) {
70034 cnt += sprintf(&page[cnt], " %d",
70035- atomic_read(&rcu_torture_wcount[i]));
70036+ atomic_read_unchecked(&rcu_torture_wcount[i]));
70037 }
70038 cnt += sprintf(&page[cnt], "\n");
70039 if (cur_ops->stats)
70040@@ -1905,7 +1905,7 @@ rcu_torture_cleanup(void)
70041
70042 if (cur_ops->cleanup)
70043 cur_ops->cleanup();
70044- if (atomic_read(&n_rcu_torture_error) || n_rcu_torture_barrier_error)
70045+ if (atomic_read_unchecked(&n_rcu_torture_error) || n_rcu_torture_barrier_error)
70046 rcu_torture_print_module_parms(cur_ops, "End of test: FAILURE");
70047 else if (n_online_successes != n_online_attempts ||
70048 n_offline_successes != n_offline_attempts)
70049@@ -1974,18 +1974,18 @@ rcu_torture_init(void)
70050
70051 rcu_torture_current = NULL;
70052 rcu_torture_current_version = 0;
70053- atomic_set(&n_rcu_torture_alloc, 0);
70054- atomic_set(&n_rcu_torture_alloc_fail, 0);
70055- atomic_set(&n_rcu_torture_free, 0);
70056- atomic_set(&n_rcu_torture_mberror, 0);
70057- atomic_set(&n_rcu_torture_error, 0);
70058+ atomic_set_unchecked(&n_rcu_torture_alloc, 0);
70059+ atomic_set_unchecked(&n_rcu_torture_alloc_fail, 0);
70060+ atomic_set_unchecked(&n_rcu_torture_free, 0);
70061+ atomic_set_unchecked(&n_rcu_torture_mberror, 0);
70062+ atomic_set_unchecked(&n_rcu_torture_error, 0);
70063 n_rcu_torture_barrier_error = 0;
70064 n_rcu_torture_boost_ktrerror = 0;
70065 n_rcu_torture_boost_rterror = 0;
70066 n_rcu_torture_boost_failure = 0;
70067 n_rcu_torture_boosts = 0;
70068 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++)
70069- atomic_set(&rcu_torture_wcount[i], 0);
70070+ atomic_set_unchecked(&rcu_torture_wcount[i], 0);
70071 for_each_possible_cpu(cpu) {
70072 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++) {
70073 per_cpu(rcu_torture_count, cpu)[i] = 0;
70074diff --git a/kernel/rcutree.c b/kernel/rcutree.c
70075index f7bcd9e..8973e14 100644
70076--- a/kernel/rcutree.c
70077+++ b/kernel/rcutree.c
70078@@ -369,9 +369,9 @@ static void rcu_idle_enter_common(struct rcu_dynticks *rdtp, long long oldval)
70079 rcu_prepare_for_idle(smp_processor_id());
70080 /* CPUs seeing atomic_inc() must see prior RCU read-side crit sects */
70081 smp_mb__before_atomic_inc(); /* See above. */
70082- atomic_inc(&rdtp->dynticks);
70083+ atomic_inc_unchecked(&rdtp->dynticks);
70084 smp_mb__after_atomic_inc(); /* Force ordering with next sojourn. */
70085- WARN_ON_ONCE(atomic_read(&rdtp->dynticks) & 0x1);
70086+ WARN_ON_ONCE(atomic_read_unchecked(&rdtp->dynticks) & 0x1);
70087
70088 /*
70089 * The idle task is not permitted to enter the idle loop while
70090@@ -460,10 +460,10 @@ void rcu_irq_exit(void)
70091 static void rcu_idle_exit_common(struct rcu_dynticks *rdtp, long long oldval)
70092 {
70093 smp_mb__before_atomic_inc(); /* Force ordering w/previous sojourn. */
70094- atomic_inc(&rdtp->dynticks);
70095+ atomic_inc_unchecked(&rdtp->dynticks);
70096 /* CPUs seeing atomic_inc() must see later RCU read-side crit sects */
70097 smp_mb__after_atomic_inc(); /* See above. */
70098- WARN_ON_ONCE(!(atomic_read(&rdtp->dynticks) & 0x1));
70099+ WARN_ON_ONCE(!(atomic_read_unchecked(&rdtp->dynticks) & 0x1));
70100 rcu_cleanup_after_idle(smp_processor_id());
70101 trace_rcu_dyntick("End", oldval, rdtp->dynticks_nesting);
70102 if (!is_idle_task(current)) {
70103@@ -557,14 +557,14 @@ void rcu_nmi_enter(void)
70104 struct rcu_dynticks *rdtp = &__get_cpu_var(rcu_dynticks);
70105
70106 if (rdtp->dynticks_nmi_nesting == 0 &&
70107- (atomic_read(&rdtp->dynticks) & 0x1))
70108+ (atomic_read_unchecked(&rdtp->dynticks) & 0x1))
70109 return;
70110 rdtp->dynticks_nmi_nesting++;
70111 smp_mb__before_atomic_inc(); /* Force delay from prior write. */
70112- atomic_inc(&rdtp->dynticks);
70113+ atomic_inc_unchecked(&rdtp->dynticks);
70114 /* CPUs seeing atomic_inc() must see later RCU read-side crit sects */
70115 smp_mb__after_atomic_inc(); /* See above. */
70116- WARN_ON_ONCE(!(atomic_read(&rdtp->dynticks) & 0x1));
70117+ WARN_ON_ONCE(!(atomic_read_unchecked(&rdtp->dynticks) & 0x1));
70118 }
70119
70120 /**
70121@@ -583,9 +583,9 @@ void rcu_nmi_exit(void)
70122 return;
70123 /* CPUs seeing atomic_inc() must see prior RCU read-side crit sects */
70124 smp_mb__before_atomic_inc(); /* See above. */
70125- atomic_inc(&rdtp->dynticks);
70126+ atomic_inc_unchecked(&rdtp->dynticks);
70127 smp_mb__after_atomic_inc(); /* Force delay to next write. */
70128- WARN_ON_ONCE(atomic_read(&rdtp->dynticks) & 0x1);
70129+ WARN_ON_ONCE(atomic_read_unchecked(&rdtp->dynticks) & 0x1);
70130 }
70131
70132 /**
70133@@ -599,7 +599,7 @@ int rcu_is_cpu_idle(void)
70134 int ret;
70135
70136 preempt_disable();
70137- ret = (atomic_read(&__get_cpu_var(rcu_dynticks).dynticks) & 0x1) == 0;
70138+ ret = (atomic_read_unchecked(&__get_cpu_var(rcu_dynticks).dynticks) & 0x1) == 0;
70139 preempt_enable();
70140 return ret;
70141 }
70142@@ -667,7 +667,7 @@ int rcu_is_cpu_rrupt_from_idle(void)
70143 */
70144 static int dyntick_save_progress_counter(struct rcu_data *rdp)
70145 {
70146- rdp->dynticks_snap = atomic_add_return(0, &rdp->dynticks->dynticks);
70147+ rdp->dynticks_snap = atomic_add_return_unchecked(0, &rdp->dynticks->dynticks);
70148 return (rdp->dynticks_snap & 0x1) == 0;
70149 }
70150
70151@@ -682,7 +682,7 @@ static int rcu_implicit_dynticks_qs(struct rcu_data *rdp)
70152 unsigned int curr;
70153 unsigned int snap;
70154
70155- curr = (unsigned int)atomic_add_return(0, &rdp->dynticks->dynticks);
70156+ curr = (unsigned int)atomic_add_return_unchecked(0, &rdp->dynticks->dynticks);
70157 snap = (unsigned int)rdp->dynticks_snap;
70158
70159 /*
70160@@ -712,10 +712,10 @@ static int jiffies_till_stall_check(void)
70161 * for CONFIG_RCU_CPU_STALL_TIMEOUT.
70162 */
70163 if (till_stall_check < 3) {
70164- ACCESS_ONCE(rcu_cpu_stall_timeout) = 3;
70165+ ACCESS_ONCE_RW(rcu_cpu_stall_timeout) = 3;
70166 till_stall_check = 3;
70167 } else if (till_stall_check > 300) {
70168- ACCESS_ONCE(rcu_cpu_stall_timeout) = 300;
70169+ ACCESS_ONCE_RW(rcu_cpu_stall_timeout) = 300;
70170 till_stall_check = 300;
70171 }
70172 return till_stall_check * HZ + RCU_STALL_DELAY_DELTA;
70173@@ -1351,7 +1351,7 @@ rcu_send_cbs_to_orphanage(int cpu, struct rcu_state *rsp,
70174 rsp->qlen += rdp->qlen;
70175 rdp->n_cbs_orphaned += rdp->qlen;
70176 rdp->qlen_lazy = 0;
70177- ACCESS_ONCE(rdp->qlen) = 0;
70178+ ACCESS_ONCE_RW(rdp->qlen) = 0;
70179 }
70180
70181 /*
70182@@ -1604,7 +1604,7 @@ static void rcu_do_batch(struct rcu_state *rsp, struct rcu_data *rdp)
70183 }
70184 smp_mb(); /* List handling before counting for rcu_barrier(). */
70185 rdp->qlen_lazy -= count_lazy;
70186- ACCESS_ONCE(rdp->qlen) -= count;
70187+ ACCESS_ONCE_RW(rdp->qlen) -= count;
70188 rdp->n_cbs_invoked += count;
70189
70190 /* Reinstate batch limit if we have worked down the excess. */
70191@@ -1836,7 +1836,7 @@ __rcu_process_callbacks(struct rcu_state *rsp)
70192 /*
70193 * Do RCU core processing for the current CPU.
70194 */
70195-static void rcu_process_callbacks(struct softirq_action *unused)
70196+static void rcu_process_callbacks(void)
70197 {
70198 struct rcu_state *rsp;
70199
70200@@ -1943,7 +1943,7 @@ __call_rcu(struct rcu_head *head, void (*func)(struct rcu_head *rcu),
70201 rdp = this_cpu_ptr(rsp->rda);
70202
70203 /* Add the callback to our list. */
70204- ACCESS_ONCE(rdp->qlen)++;
70205+ ACCESS_ONCE_RW(rdp->qlen)++;
70206 if (lazy)
70207 rdp->qlen_lazy++;
70208 else
70209@@ -2057,8 +2057,8 @@ void synchronize_rcu_bh(void)
70210 }
70211 EXPORT_SYMBOL_GPL(synchronize_rcu_bh);
70212
70213-static atomic_t sync_sched_expedited_started = ATOMIC_INIT(0);
70214-static atomic_t sync_sched_expedited_done = ATOMIC_INIT(0);
70215+static atomic_unchecked_t sync_sched_expedited_started = ATOMIC_INIT(0);
70216+static atomic_unchecked_t sync_sched_expedited_done = ATOMIC_INIT(0);
70217
70218 static int synchronize_sched_expedited_cpu_stop(void *data)
70219 {
70220@@ -2119,7 +2119,7 @@ void synchronize_sched_expedited(void)
70221 int firstsnap, s, snap, trycount = 0;
70222
70223 /* Note that atomic_inc_return() implies full memory barrier. */
70224- firstsnap = snap = atomic_inc_return(&sync_sched_expedited_started);
70225+ firstsnap = snap = atomic_inc_return_unchecked(&sync_sched_expedited_started);
70226 get_online_cpus();
70227 WARN_ON_ONCE(cpu_is_offline(raw_smp_processor_id()));
70228
70229@@ -2141,7 +2141,7 @@ void synchronize_sched_expedited(void)
70230 }
70231
70232 /* Check to see if someone else did our work for us. */
70233- s = atomic_read(&sync_sched_expedited_done);
70234+ s = atomic_read_unchecked(&sync_sched_expedited_done);
70235 if (UINT_CMP_GE((unsigned)s, (unsigned)firstsnap)) {
70236 smp_mb(); /* ensure test happens before caller kfree */
70237 return;
70238@@ -2156,7 +2156,7 @@ void synchronize_sched_expedited(void)
70239 * grace period works for us.
70240 */
70241 get_online_cpus();
70242- snap = atomic_read(&sync_sched_expedited_started);
70243+ snap = atomic_read_unchecked(&sync_sched_expedited_started);
70244 smp_mb(); /* ensure read is before try_stop_cpus(). */
70245 }
70246
70247@@ -2167,12 +2167,12 @@ void synchronize_sched_expedited(void)
70248 * than we did beat us to the punch.
70249 */
70250 do {
70251- s = atomic_read(&sync_sched_expedited_done);
70252+ s = atomic_read_unchecked(&sync_sched_expedited_done);
70253 if (UINT_CMP_GE((unsigned)s, (unsigned)snap)) {
70254 smp_mb(); /* ensure test happens before caller kfree */
70255 break;
70256 }
70257- } while (atomic_cmpxchg(&sync_sched_expedited_done, s, snap) != s);
70258+ } while (atomic_cmpxchg_unchecked(&sync_sched_expedited_done, s, snap) != s);
70259
70260 put_online_cpus();
70261 }
70262@@ -2366,7 +2366,7 @@ static void _rcu_barrier(struct rcu_state *rsp)
70263 * ACCESS_ONCE() to prevent the compiler from speculating
70264 * the increment to precede the early-exit check.
70265 */
70266- ACCESS_ONCE(rsp->n_barrier_done)++;
70267+ ACCESS_ONCE_RW(rsp->n_barrier_done)++;
70268 WARN_ON_ONCE((rsp->n_barrier_done & 0x1) != 1);
70269 _rcu_barrier_trace(rsp, "Inc1", -1, rsp->n_barrier_done);
70270 smp_mb(); /* Order ->n_barrier_done increment with below mechanism. */
70271@@ -2448,7 +2448,7 @@ static void _rcu_barrier(struct rcu_state *rsp)
70272
70273 /* Increment ->n_barrier_done to prevent duplicate work. */
70274 smp_mb(); /* Keep increment after above mechanism. */
70275- ACCESS_ONCE(rsp->n_barrier_done)++;
70276+ ACCESS_ONCE_RW(rsp->n_barrier_done)++;
70277 WARN_ON_ONCE((rsp->n_barrier_done & 0x1) != 0);
70278 _rcu_barrier_trace(rsp, "Inc2", -1, rsp->n_barrier_done);
70279 smp_mb(); /* Keep increment before caller's subsequent code. */
70280@@ -2495,10 +2495,10 @@ rcu_boot_init_percpu_data(int cpu, struct rcu_state *rsp)
70281 rdp->grpmask = 1UL << (cpu - rdp->mynode->grplo);
70282 init_callback_list(rdp);
70283 rdp->qlen_lazy = 0;
70284- ACCESS_ONCE(rdp->qlen) = 0;
70285+ ACCESS_ONCE_RW(rdp->qlen) = 0;
70286 rdp->dynticks = &per_cpu(rcu_dynticks, cpu);
70287 WARN_ON_ONCE(rdp->dynticks->dynticks_nesting != DYNTICK_TASK_EXIT_IDLE);
70288- WARN_ON_ONCE(atomic_read(&rdp->dynticks->dynticks) != 1);
70289+ WARN_ON_ONCE(atomic_read_unchecked(&rdp->dynticks->dynticks) != 1);
70290 rdp->cpu = cpu;
70291 rdp->rsp = rsp;
70292 raw_spin_unlock_irqrestore(&rnp->lock, flags);
70293@@ -2526,8 +2526,8 @@ rcu_init_percpu_data(int cpu, struct rcu_state *rsp, int preemptible)
70294 rdp->n_force_qs_snap = rsp->n_force_qs;
70295 rdp->blimit = blimit;
70296 rdp->dynticks->dynticks_nesting = DYNTICK_TASK_EXIT_IDLE;
70297- atomic_set(&rdp->dynticks->dynticks,
70298- (atomic_read(&rdp->dynticks->dynticks) & ~0x1) + 1);
70299+ atomic_set_unchecked(&rdp->dynticks->dynticks,
70300+ (atomic_read_unchecked(&rdp->dynticks->dynticks) & ~0x1) + 1);
70301 rcu_prepare_for_idle_init(cpu);
70302 raw_spin_unlock(&rnp->lock); /* irqs remain disabled. */
70303
70304diff --git a/kernel/rcutree.h b/kernel/rcutree.h
70305index 4d29169..d104a3c 100644
70306--- a/kernel/rcutree.h
70307+++ b/kernel/rcutree.h
70308@@ -86,7 +86,7 @@ struct rcu_dynticks {
70309 long long dynticks_nesting; /* Track irq/process nesting level. */
70310 /* Process level is worth LLONG_MAX/2. */
70311 int dynticks_nmi_nesting; /* Track NMI nesting level. */
70312- atomic_t dynticks; /* Even value for idle, else odd. */
70313+ atomic_unchecked_t dynticks;/* Even value for idle, else odd. */
70314 #ifdef CONFIG_RCU_FAST_NO_HZ
70315 int dyntick_drain; /* Prepare-for-idle state variable. */
70316 unsigned long dyntick_holdoff;
70317diff --git a/kernel/rcutree_plugin.h b/kernel/rcutree_plugin.h
70318index 7f3244c..417d606 100644
70319--- a/kernel/rcutree_plugin.h
70320+++ b/kernel/rcutree_plugin.h
70321@@ -843,7 +843,7 @@ void synchronize_rcu_expedited(void)
70322
70323 /* Clean up and exit. */
70324 smp_mb(); /* ensure expedited GP seen before counter increment. */
70325- ACCESS_ONCE(sync_rcu_preempt_exp_count)++;
70326+ ACCESS_ONCE_RW(sync_rcu_preempt_exp_count)++;
70327 unlock_mb_ret:
70328 mutex_unlock(&sync_rcu_preempt_exp_mutex);
70329 mb_ret:
70330diff --git a/kernel/rcutree_trace.c b/kernel/rcutree_trace.c
70331index abffb48..cbfa6d3 100644
70332--- a/kernel/rcutree_trace.c
70333+++ b/kernel/rcutree_trace.c
70334@@ -93,7 +93,7 @@ static void print_one_rcu_data(struct seq_file *m, struct rcu_data *rdp)
70335 rdp->passed_quiesce, rdp->passed_quiesce_gpnum,
70336 rdp->qs_pending);
70337 seq_printf(m, " dt=%d/%llx/%d df=%lu",
70338- atomic_read(&rdp->dynticks->dynticks),
70339+ atomic_read_unchecked(&rdp->dynticks->dynticks),
70340 rdp->dynticks->dynticks_nesting,
70341 rdp->dynticks->dynticks_nmi_nesting,
70342 rdp->dynticks_fqs);
70343@@ -157,7 +157,7 @@ static void print_one_rcu_data_csv(struct seq_file *m, struct rcu_data *rdp)
70344 rdp->passed_quiesce, rdp->passed_quiesce_gpnum,
70345 rdp->qs_pending);
70346 seq_printf(m, ",%d,%llx,%d,%lu",
70347- atomic_read(&rdp->dynticks->dynticks),
70348+ atomic_read_unchecked(&rdp->dynticks->dynticks),
70349 rdp->dynticks->dynticks_nesting,
70350 rdp->dynticks->dynticks_nmi_nesting,
70351 rdp->dynticks_fqs);
70352diff --git a/kernel/resource.c b/kernel/resource.c
70353index 34d4588..10baa6a 100644
70354--- a/kernel/resource.c
70355+++ b/kernel/resource.c
70356@@ -143,8 +143,18 @@ static const struct file_operations proc_iomem_operations = {
70357
70358 static int __init ioresources_init(void)
70359 {
70360+#ifdef CONFIG_GRKERNSEC_PROC_ADD
70361+#ifdef CONFIG_GRKERNSEC_PROC_USER
70362+ proc_create("ioports", S_IRUSR, NULL, &proc_ioports_operations);
70363+ proc_create("iomem", S_IRUSR, NULL, &proc_iomem_operations);
70364+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
70365+ proc_create("ioports", S_IRUSR | S_IRGRP, NULL, &proc_ioports_operations);
70366+ proc_create("iomem", S_IRUSR | S_IRGRP, NULL, &proc_iomem_operations);
70367+#endif
70368+#else
70369 proc_create("ioports", 0, NULL, &proc_ioports_operations);
70370 proc_create("iomem", 0, NULL, &proc_iomem_operations);
70371+#endif
70372 return 0;
70373 }
70374 __initcall(ioresources_init);
70375diff --git a/kernel/rtmutex-tester.c b/kernel/rtmutex-tester.c
70376index 98ec494..4241d6d 100644
70377--- a/kernel/rtmutex-tester.c
70378+++ b/kernel/rtmutex-tester.c
70379@@ -20,7 +20,7 @@
70380 #define MAX_RT_TEST_MUTEXES 8
70381
70382 static spinlock_t rttest_lock;
70383-static atomic_t rttest_event;
70384+static atomic_unchecked_t rttest_event;
70385
70386 struct test_thread_data {
70387 int opcode;
70388@@ -61,7 +61,7 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
70389
70390 case RTTEST_LOCKCONT:
70391 td->mutexes[td->opdata] = 1;
70392- td->event = atomic_add_return(1, &rttest_event);
70393+ td->event = atomic_add_return_unchecked(1, &rttest_event);
70394 return 0;
70395
70396 case RTTEST_RESET:
70397@@ -74,7 +74,7 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
70398 return 0;
70399
70400 case RTTEST_RESETEVENT:
70401- atomic_set(&rttest_event, 0);
70402+ atomic_set_unchecked(&rttest_event, 0);
70403 return 0;
70404
70405 default:
70406@@ -91,9 +91,9 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
70407 return ret;
70408
70409 td->mutexes[id] = 1;
70410- td->event = atomic_add_return(1, &rttest_event);
70411+ td->event = atomic_add_return_unchecked(1, &rttest_event);
70412 rt_mutex_lock(&mutexes[id]);
70413- td->event = atomic_add_return(1, &rttest_event);
70414+ td->event = atomic_add_return_unchecked(1, &rttest_event);
70415 td->mutexes[id] = 4;
70416 return 0;
70417
70418@@ -104,9 +104,9 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
70419 return ret;
70420
70421 td->mutexes[id] = 1;
70422- td->event = atomic_add_return(1, &rttest_event);
70423+ td->event = atomic_add_return_unchecked(1, &rttest_event);
70424 ret = rt_mutex_lock_interruptible(&mutexes[id], 0);
70425- td->event = atomic_add_return(1, &rttest_event);
70426+ td->event = atomic_add_return_unchecked(1, &rttest_event);
70427 td->mutexes[id] = ret ? 0 : 4;
70428 return ret ? -EINTR : 0;
70429
70430@@ -115,9 +115,9 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
70431 if (id < 0 || id >= MAX_RT_TEST_MUTEXES || td->mutexes[id] != 4)
70432 return ret;
70433
70434- td->event = atomic_add_return(1, &rttest_event);
70435+ td->event = atomic_add_return_unchecked(1, &rttest_event);
70436 rt_mutex_unlock(&mutexes[id]);
70437- td->event = atomic_add_return(1, &rttest_event);
70438+ td->event = atomic_add_return_unchecked(1, &rttest_event);
70439 td->mutexes[id] = 0;
70440 return 0;
70441
70442@@ -164,7 +164,7 @@ void schedule_rt_mutex_test(struct rt_mutex *mutex)
70443 break;
70444
70445 td->mutexes[dat] = 2;
70446- td->event = atomic_add_return(1, &rttest_event);
70447+ td->event = atomic_add_return_unchecked(1, &rttest_event);
70448 break;
70449
70450 default:
70451@@ -184,7 +184,7 @@ void schedule_rt_mutex_test(struct rt_mutex *mutex)
70452 return;
70453
70454 td->mutexes[dat] = 3;
70455- td->event = atomic_add_return(1, &rttest_event);
70456+ td->event = atomic_add_return_unchecked(1, &rttest_event);
70457 break;
70458
70459 case RTTEST_LOCKNOWAIT:
70460@@ -196,7 +196,7 @@ void schedule_rt_mutex_test(struct rt_mutex *mutex)
70461 return;
70462
70463 td->mutexes[dat] = 1;
70464- td->event = atomic_add_return(1, &rttest_event);
70465+ td->event = atomic_add_return_unchecked(1, &rttest_event);
70466 return;
70467
70468 default:
70469diff --git a/kernel/sched/auto_group.c b/kernel/sched/auto_group.c
70470index 0984a21..939f183 100644
70471--- a/kernel/sched/auto_group.c
70472+++ b/kernel/sched/auto_group.c
70473@@ -11,7 +11,7 @@
70474
70475 unsigned int __read_mostly sysctl_sched_autogroup_enabled = 1;
70476 static struct autogroup autogroup_default;
70477-static atomic_t autogroup_seq_nr;
70478+static atomic_unchecked_t autogroup_seq_nr;
70479
70480 void __init autogroup_init(struct task_struct *init_task)
70481 {
70482@@ -78,7 +78,7 @@ static inline struct autogroup *autogroup_create(void)
70483
70484 kref_init(&ag->kref);
70485 init_rwsem(&ag->lock);
70486- ag->id = atomic_inc_return(&autogroup_seq_nr);
70487+ ag->id = atomic_inc_return_unchecked(&autogroup_seq_nr);
70488 ag->tg = tg;
70489 #ifdef CONFIG_RT_GROUP_SCHED
70490 /*
70491diff --git a/kernel/sched/core.c b/kernel/sched/core.c
70492index 1a48cdb..d3949ff 100644
70493--- a/kernel/sched/core.c
70494+++ b/kernel/sched/core.c
70495@@ -4103,6 +4103,8 @@ int can_nice(const struct task_struct *p, const int nice)
70496 /* convert nice value [19,-20] to rlimit style value [1,40] */
70497 int nice_rlim = 20 - nice;
70498
70499+ gr_learn_resource(p, RLIMIT_NICE, nice_rlim, 1);
70500+
70501 return (nice_rlim <= task_rlimit(p, RLIMIT_NICE) ||
70502 capable(CAP_SYS_NICE));
70503 }
70504@@ -4136,7 +4138,8 @@ SYSCALL_DEFINE1(nice, int, increment)
70505 if (nice > 19)
70506 nice = 19;
70507
70508- if (increment < 0 && !can_nice(current, nice))
70509+ if (increment < 0 && (!can_nice(current, nice) ||
70510+ gr_handle_chroot_nice()))
70511 return -EPERM;
70512
70513 retval = security_task_setnice(current, nice);
70514@@ -4290,6 +4293,7 @@ recheck:
70515 unsigned long rlim_rtprio =
70516 task_rlimit(p, RLIMIT_RTPRIO);
70517
70518+ gr_learn_resource(p, RLIMIT_RTPRIO, param->sched_priority, 1);
70519 /* can't set/change the rt policy */
70520 if (policy != p->policy && !rlim_rtprio)
70521 return -EPERM;
70522diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c
70523index 96e2b18..bb31eec 100644
70524--- a/kernel/sched/fair.c
70525+++ b/kernel/sched/fair.c
70526@@ -4923,7 +4923,7 @@ static void nohz_idle_balance(int this_cpu, enum cpu_idle_type idle) { }
70527 * run_rebalance_domains is triggered when needed from the scheduler tick.
70528 * Also triggered for nohz idle balancing (with nohz_balancing_kick set).
70529 */
70530-static void run_rebalance_domains(struct softirq_action *h)
70531+static void run_rebalance_domains(void)
70532 {
70533 int this_cpu = smp_processor_id();
70534 struct rq *this_rq = cpu_rq(this_cpu);
70535diff --git a/kernel/signal.c b/kernel/signal.c
70536index be4f856..453401c 100644
70537--- a/kernel/signal.c
70538+++ b/kernel/signal.c
70539@@ -48,12 +48,12 @@ static struct kmem_cache *sigqueue_cachep;
70540
70541 int print_fatal_signals __read_mostly;
70542
70543-static void __user *sig_handler(struct task_struct *t, int sig)
70544+static __sighandler_t sig_handler(struct task_struct *t, int sig)
70545 {
70546 return t->sighand->action[sig - 1].sa.sa_handler;
70547 }
70548
70549-static int sig_handler_ignored(void __user *handler, int sig)
70550+static int sig_handler_ignored(__sighandler_t handler, int sig)
70551 {
70552 /* Is it explicitly or implicitly ignored? */
70553 return handler == SIG_IGN ||
70554@@ -62,7 +62,7 @@ static int sig_handler_ignored(void __user *handler, int sig)
70555
70556 static int sig_task_ignored(struct task_struct *t, int sig, bool force)
70557 {
70558- void __user *handler;
70559+ __sighandler_t handler;
70560
70561 handler = sig_handler(t, sig);
70562
70563@@ -366,6 +366,9 @@ __sigqueue_alloc(int sig, struct task_struct *t, gfp_t flags, int override_rlimi
70564 atomic_inc(&user->sigpending);
70565 rcu_read_unlock();
70566
70567+ if (!override_rlimit)
70568+ gr_learn_resource(t, RLIMIT_SIGPENDING, atomic_read(&user->sigpending), 1);
70569+
70570 if (override_rlimit ||
70571 atomic_read(&user->sigpending) <=
70572 task_rlimit(t, RLIMIT_SIGPENDING)) {
70573@@ -490,7 +493,7 @@ flush_signal_handlers(struct task_struct *t, int force_default)
70574
70575 int unhandled_signal(struct task_struct *tsk, int sig)
70576 {
70577- void __user *handler = tsk->sighand->action[sig-1].sa.sa_handler;
70578+ __sighandler_t handler = tsk->sighand->action[sig-1].sa.sa_handler;
70579 if (is_global_init(tsk))
70580 return 1;
70581 if (handler != SIG_IGN && handler != SIG_DFL)
70582@@ -816,6 +819,13 @@ static int check_kill_permission(int sig, struct siginfo *info,
70583 }
70584 }
70585
70586+ /* allow glibc communication via tgkill to other threads in our
70587+ thread group */
70588+ if ((info == SEND_SIG_NOINFO || info->si_code != SI_TKILL ||
70589+ sig != (SIGRTMIN+1) || task_tgid_vnr(t) != info->si_pid)
70590+ && gr_handle_signal(t, sig))
70591+ return -EPERM;
70592+
70593 return security_task_kill(t, info, sig, 0);
70594 }
70595
70596@@ -1197,7 +1207,7 @@ __group_send_sig_info(int sig, struct siginfo *info, struct task_struct *p)
70597 return send_signal(sig, info, p, 1);
70598 }
70599
70600-static int
70601+int
70602 specific_send_sig_info(int sig, struct siginfo *info, struct task_struct *t)
70603 {
70604 return send_signal(sig, info, t, 0);
70605@@ -1234,6 +1244,7 @@ force_sig_info(int sig, struct siginfo *info, struct task_struct *t)
70606 unsigned long int flags;
70607 int ret, blocked, ignored;
70608 struct k_sigaction *action;
70609+ int is_unhandled = 0;
70610
70611 spin_lock_irqsave(&t->sighand->siglock, flags);
70612 action = &t->sighand->action[sig-1];
70613@@ -1248,9 +1259,18 @@ force_sig_info(int sig, struct siginfo *info, struct task_struct *t)
70614 }
70615 if (action->sa.sa_handler == SIG_DFL)
70616 t->signal->flags &= ~SIGNAL_UNKILLABLE;
70617+ if (action->sa.sa_handler == SIG_IGN || action->sa.sa_handler == SIG_DFL)
70618+ is_unhandled = 1;
70619 ret = specific_send_sig_info(sig, info, t);
70620 spin_unlock_irqrestore(&t->sighand->siglock, flags);
70621
70622+ /* only deal with unhandled signals, java etc trigger SIGSEGV during
70623+ normal operation */
70624+ if (is_unhandled) {
70625+ gr_log_signal(sig, !is_si_special(info) ? info->si_addr : NULL, t);
70626+ gr_handle_crash(t, sig);
70627+ }
70628+
70629 return ret;
70630 }
70631
70632@@ -1317,8 +1337,11 @@ int group_send_sig_info(int sig, struct siginfo *info, struct task_struct *p)
70633 ret = check_kill_permission(sig, info, p);
70634 rcu_read_unlock();
70635
70636- if (!ret && sig)
70637+ if (!ret && sig) {
70638 ret = do_send_sig_info(sig, info, p, true);
70639+ if (!ret)
70640+ gr_log_signal(sig, !is_si_special(info) ? info->si_addr : NULL, p);
70641+ }
70642
70643 return ret;
70644 }
70645@@ -2873,7 +2896,15 @@ do_send_specific(pid_t tgid, pid_t pid, int sig, struct siginfo *info)
70646 int error = -ESRCH;
70647
70648 rcu_read_lock();
70649- p = find_task_by_vpid(pid);
70650+#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
70651+ /* allow glibc communication via tgkill to other threads in our
70652+ thread group */
70653+ if (grsec_enable_chroot_findtask && info->si_code == SI_TKILL &&
70654+ sig == (SIGRTMIN+1) && tgid == info->si_pid)
70655+ p = find_task_by_vpid_unrestricted(pid);
70656+ else
70657+#endif
70658+ p = find_task_by_vpid(pid);
70659 if (p && (tgid <= 0 || task_tgid_vnr(p) == tgid)) {
70660 error = check_kill_permission(sig, info, p);
70661 /*
70662diff --git a/kernel/softirq.c b/kernel/softirq.c
70663index b73e681..645ab62 100644
70664--- a/kernel/softirq.c
70665+++ b/kernel/softirq.c
70666@@ -56,7 +56,7 @@ static struct softirq_action softirq_vec[NR_SOFTIRQS] __cacheline_aligned_in_smp
70667
70668 DEFINE_PER_CPU(struct task_struct *, ksoftirqd);
70669
70670-char *softirq_to_name[NR_SOFTIRQS] = {
70671+const char * const softirq_to_name[NR_SOFTIRQS] = {
70672 "HI", "TIMER", "NET_TX", "NET_RX", "BLOCK", "BLOCK_IOPOLL",
70673 "TASKLET", "SCHED", "HRTIMER", "RCU"
70674 };
70675@@ -243,7 +243,7 @@ restart:
70676 kstat_incr_softirqs_this_cpu(vec_nr);
70677
70678 trace_softirq_entry(vec_nr);
70679- h->action(h);
70680+ h->action();
70681 trace_softirq_exit(vec_nr);
70682 if (unlikely(prev_count != preempt_count())) {
70683 printk(KERN_ERR "huh, entered softirq %u %s %p"
70684@@ -390,9 +390,11 @@ void __raise_softirq_irqoff(unsigned int nr)
70685 or_softirq_pending(1UL << nr);
70686 }
70687
70688-void open_softirq(int nr, void (*action)(struct softirq_action *))
70689+void open_softirq(int nr, void (*action)(void))
70690 {
70691- softirq_vec[nr].action = action;
70692+ pax_open_kernel();
70693+ *(void **)&softirq_vec[nr].action = action;
70694+ pax_close_kernel();
70695 }
70696
70697 /*
70698@@ -446,7 +448,7 @@ void __tasklet_hi_schedule_first(struct tasklet_struct *t)
70699
70700 EXPORT_SYMBOL(__tasklet_hi_schedule_first);
70701
70702-static void tasklet_action(struct softirq_action *a)
70703+static void tasklet_action(void)
70704 {
70705 struct tasklet_struct *list;
70706
70707@@ -481,7 +483,7 @@ static void tasklet_action(struct softirq_action *a)
70708 }
70709 }
70710
70711-static void tasklet_hi_action(struct softirq_action *a)
70712+static void tasklet_hi_action(void)
70713 {
70714 struct tasklet_struct *list;
70715
70716diff --git a/kernel/srcu.c b/kernel/srcu.c
70717index 2095be3..9a5b89d 100644
70718--- a/kernel/srcu.c
70719+++ b/kernel/srcu.c
70720@@ -302,9 +302,9 @@ int __srcu_read_lock(struct srcu_struct *sp)
70721 preempt_disable();
70722 idx = rcu_dereference_index_check(sp->completed,
70723 rcu_read_lock_sched_held()) & 0x1;
70724- ACCESS_ONCE(this_cpu_ptr(sp->per_cpu_ref)->c[idx]) += 1;
70725+ ACCESS_ONCE_RW(this_cpu_ptr(sp->per_cpu_ref)->c[idx]) += 1;
70726 smp_mb(); /* B */ /* Avoid leaking the critical section. */
70727- ACCESS_ONCE(this_cpu_ptr(sp->per_cpu_ref)->seq[idx]) += 1;
70728+ ACCESS_ONCE_RW(this_cpu_ptr(sp->per_cpu_ref)->seq[idx]) += 1;
70729 preempt_enable();
70730 return idx;
70731 }
70732@@ -320,7 +320,7 @@ void __srcu_read_unlock(struct srcu_struct *sp, int idx)
70733 {
70734 preempt_disable();
70735 smp_mb(); /* C */ /* Avoid leaking the critical section. */
70736- ACCESS_ONCE(this_cpu_ptr(sp->per_cpu_ref)->c[idx]) -= 1;
70737+ ACCESS_ONCE_RW(this_cpu_ptr(sp->per_cpu_ref)->c[idx]) -= 1;
70738 preempt_enable();
70739 }
70740 EXPORT_SYMBOL_GPL(__srcu_read_unlock);
70741diff --git a/kernel/sys.c b/kernel/sys.c
70742index 909148a..cd51acf 100644
70743--- a/kernel/sys.c
70744+++ b/kernel/sys.c
70745@@ -157,6 +157,12 @@ static int set_one_prio(struct task_struct *p, int niceval, int error)
70746 error = -EACCES;
70747 goto out;
70748 }
70749+
70750+ if (gr_handle_chroot_setpriority(p, niceval)) {
70751+ error = -EACCES;
70752+ goto out;
70753+ }
70754+
70755 no_nice = security_task_setnice(p, niceval);
70756 if (no_nice) {
70757 error = no_nice;
70758@@ -595,6 +601,9 @@ SYSCALL_DEFINE2(setregid, gid_t, rgid, gid_t, egid)
70759 goto error;
70760 }
70761
70762+ if (gr_check_group_change(new->gid, new->egid, -1))
70763+ goto error;
70764+
70765 if (rgid != (gid_t) -1 ||
70766 (egid != (gid_t) -1 && !gid_eq(kegid, old->gid)))
70767 new->sgid = new->egid;
70768@@ -630,6 +639,10 @@ SYSCALL_DEFINE1(setgid, gid_t, gid)
70769 old = current_cred();
70770
70771 retval = -EPERM;
70772+
70773+ if (gr_check_group_change(kgid, kgid, kgid))
70774+ goto error;
70775+
70776 if (nsown_capable(CAP_SETGID))
70777 new->gid = new->egid = new->sgid = new->fsgid = kgid;
70778 else if (gid_eq(kgid, old->gid) || gid_eq(kgid, old->sgid))
70779@@ -647,7 +660,7 @@ error:
70780 /*
70781 * change the user struct in a credentials set to match the new UID
70782 */
70783-static int set_user(struct cred *new)
70784+int set_user(struct cred *new)
70785 {
70786 struct user_struct *new_user;
70787
70788@@ -727,6 +740,9 @@ SYSCALL_DEFINE2(setreuid, uid_t, ruid, uid_t, euid)
70789 goto error;
70790 }
70791
70792+ if (gr_check_user_change(new->uid, new->euid, -1))
70793+ goto error;
70794+
70795 if (!uid_eq(new->uid, old->uid)) {
70796 retval = set_user(new);
70797 if (retval < 0)
70798@@ -777,6 +793,12 @@ SYSCALL_DEFINE1(setuid, uid_t, uid)
70799 old = current_cred();
70800
70801 retval = -EPERM;
70802+
70803+ if (gr_check_crash_uid(kuid))
70804+ goto error;
70805+ if (gr_check_user_change(kuid, kuid, kuid))
70806+ goto error;
70807+
70808 if (nsown_capable(CAP_SETUID)) {
70809 new->suid = new->uid = kuid;
70810 if (!uid_eq(kuid, old->uid)) {
70811@@ -846,6 +868,9 @@ SYSCALL_DEFINE3(setresuid, uid_t, ruid, uid_t, euid, uid_t, suid)
70812 goto error;
70813 }
70814
70815+ if (gr_check_user_change(kruid, keuid, -1))
70816+ goto error;
70817+
70818 if (ruid != (uid_t) -1) {
70819 new->uid = kruid;
70820 if (!uid_eq(kruid, old->uid)) {
70821@@ -928,6 +953,9 @@ SYSCALL_DEFINE3(setresgid, gid_t, rgid, gid_t, egid, gid_t, sgid)
70822 goto error;
70823 }
70824
70825+ if (gr_check_group_change(krgid, kegid, -1))
70826+ goto error;
70827+
70828 if (rgid != (gid_t) -1)
70829 new->gid = krgid;
70830 if (egid != (gid_t) -1)
70831@@ -981,6 +1009,9 @@ SYSCALL_DEFINE1(setfsuid, uid_t, uid)
70832 if (!uid_valid(kuid))
70833 return old_fsuid;
70834
70835+ if (gr_check_user_change(-1, -1, kuid))
70836+ goto error;
70837+
70838 new = prepare_creds();
70839 if (!new)
70840 return old_fsuid;
70841@@ -995,6 +1026,7 @@ SYSCALL_DEFINE1(setfsuid, uid_t, uid)
70842 }
70843 }
70844
70845+error:
70846 abort_creds(new);
70847 return old_fsuid;
70848
70849@@ -1027,12 +1059,16 @@ SYSCALL_DEFINE1(setfsgid, gid_t, gid)
70850 if (gid_eq(kgid, old->gid) || gid_eq(kgid, old->egid) ||
70851 gid_eq(kgid, old->sgid) || gid_eq(kgid, old->fsgid) ||
70852 nsown_capable(CAP_SETGID)) {
70853+ if (gr_check_group_change(-1, -1, kgid))
70854+ goto error;
70855+
70856 if (!gid_eq(kgid, old->fsgid)) {
70857 new->fsgid = kgid;
70858 goto change_okay;
70859 }
70860 }
70861
70862+error:
70863 abort_creds(new);
70864 return old_fsgid;
70865
70866@@ -1340,19 +1376,19 @@ SYSCALL_DEFINE1(olduname, struct oldold_utsname __user *, name)
70867 return -EFAULT;
70868
70869 down_read(&uts_sem);
70870- error = __copy_to_user(&name->sysname, &utsname()->sysname,
70871+ error = __copy_to_user(name->sysname, &utsname()->sysname,
70872 __OLD_UTS_LEN);
70873 error |= __put_user(0, name->sysname + __OLD_UTS_LEN);
70874- error |= __copy_to_user(&name->nodename, &utsname()->nodename,
70875+ error |= __copy_to_user(name->nodename, &utsname()->nodename,
70876 __OLD_UTS_LEN);
70877 error |= __put_user(0, name->nodename + __OLD_UTS_LEN);
70878- error |= __copy_to_user(&name->release, &utsname()->release,
70879+ error |= __copy_to_user(name->release, &utsname()->release,
70880 __OLD_UTS_LEN);
70881 error |= __put_user(0, name->release + __OLD_UTS_LEN);
70882- error |= __copy_to_user(&name->version, &utsname()->version,
70883+ error |= __copy_to_user(name->version, &utsname()->version,
70884 __OLD_UTS_LEN);
70885 error |= __put_user(0, name->version + __OLD_UTS_LEN);
70886- error |= __copy_to_user(&name->machine, &utsname()->machine,
70887+ error |= __copy_to_user(name->machine, &utsname()->machine,
70888 __OLD_UTS_LEN);
70889 error |= __put_user(0, name->machine + __OLD_UTS_LEN);
70890 up_read(&uts_sem);
70891@@ -2026,7 +2062,7 @@ SYSCALL_DEFINE5(prctl, int, option, unsigned long, arg2, unsigned long, arg3,
70892 error = get_dumpable(me->mm);
70893 break;
70894 case PR_SET_DUMPABLE:
70895- if (arg2 < 0 || arg2 > 1) {
70896+ if (arg2 > 1) {
70897 error = -EINVAL;
70898 break;
70899 }
70900diff --git a/kernel/sysctl.c b/kernel/sysctl.c
70901index 87174ef..68cbb82 100644
70902--- a/kernel/sysctl.c
70903+++ b/kernel/sysctl.c
70904@@ -92,7 +92,6 @@
70905
70906
70907 #if defined(CONFIG_SYSCTL)
70908-
70909 /* External variables not in a header file. */
70910 extern int sysctl_overcommit_memory;
70911 extern int sysctl_overcommit_ratio;
70912@@ -170,10 +169,8 @@ static int proc_taint(struct ctl_table *table, int write,
70913 void __user *buffer, size_t *lenp, loff_t *ppos);
70914 #endif
70915
70916-#ifdef CONFIG_PRINTK
70917 static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
70918 void __user *buffer, size_t *lenp, loff_t *ppos);
70919-#endif
70920
70921 static int proc_dointvec_minmax_coredump(struct ctl_table *table, int write,
70922 void __user *buffer, size_t *lenp, loff_t *ppos);
70923@@ -202,6 +199,8 @@ static int sysrq_sysctl_handler(ctl_table *table, int write,
70924
70925 #endif
70926
70927+extern struct ctl_table grsecurity_table[];
70928+
70929 static struct ctl_table kern_table[];
70930 static struct ctl_table vm_table[];
70931 static struct ctl_table fs_table[];
70932@@ -216,6 +215,20 @@ extern struct ctl_table epoll_table[];
70933 int sysctl_legacy_va_layout;
70934 #endif
70935
70936+#ifdef CONFIG_PAX_SOFTMODE
70937+static ctl_table pax_table[] = {
70938+ {
70939+ .procname = "softmode",
70940+ .data = &pax_softmode,
70941+ .maxlen = sizeof(unsigned int),
70942+ .mode = 0600,
70943+ .proc_handler = &proc_dointvec,
70944+ },
70945+
70946+ { }
70947+};
70948+#endif
70949+
70950 /* The default sysctl tables: */
70951
70952 static struct ctl_table sysctl_base_table[] = {
70953@@ -262,6 +275,22 @@ static int max_extfrag_threshold = 1000;
70954 #endif
70955
70956 static struct ctl_table kern_table[] = {
70957+#if defined(CONFIG_GRKERNSEC_SYSCTL) || defined(CONFIG_GRKERNSEC_ROFS)
70958+ {
70959+ .procname = "grsecurity",
70960+ .mode = 0500,
70961+ .child = grsecurity_table,
70962+ },
70963+#endif
70964+
70965+#ifdef CONFIG_PAX_SOFTMODE
70966+ {
70967+ .procname = "pax",
70968+ .mode = 0500,
70969+ .child = pax_table,
70970+ },
70971+#endif
70972+
70973 {
70974 .procname = "sched_child_runs_first",
70975 .data = &sysctl_sched_child_runs_first,
70976@@ -546,7 +575,7 @@ static struct ctl_table kern_table[] = {
70977 .data = &modprobe_path,
70978 .maxlen = KMOD_PATH_LEN,
70979 .mode = 0644,
70980- .proc_handler = proc_dostring,
70981+ .proc_handler = proc_dostring_modpriv,
70982 },
70983 {
70984 .procname = "modules_disabled",
70985@@ -713,16 +742,20 @@ static struct ctl_table kern_table[] = {
70986 .extra1 = &zero,
70987 .extra2 = &one,
70988 },
70989+#endif
70990 {
70991 .procname = "kptr_restrict",
70992 .data = &kptr_restrict,
70993 .maxlen = sizeof(int),
70994 .mode = 0644,
70995 .proc_handler = proc_dointvec_minmax_sysadmin,
70996+#ifdef CONFIG_GRKERNSEC_HIDESYM
70997+ .extra1 = &two,
70998+#else
70999 .extra1 = &zero,
71000+#endif
71001 .extra2 = &two,
71002 },
71003-#endif
71004 {
71005 .procname = "ngroups_max",
71006 .data = &ngroups_max,
71007@@ -1219,6 +1252,13 @@ static struct ctl_table vm_table[] = {
71008 .proc_handler = proc_dointvec_minmax,
71009 .extra1 = &zero,
71010 },
71011+ {
71012+ .procname = "heap_stack_gap",
71013+ .data = &sysctl_heap_stack_gap,
71014+ .maxlen = sizeof(sysctl_heap_stack_gap),
71015+ .mode = 0644,
71016+ .proc_handler = proc_doulongvec_minmax,
71017+ },
71018 #else
71019 {
71020 .procname = "nr_trim_pages",
71021@@ -1670,6 +1710,16 @@ int proc_dostring(struct ctl_table *table, int write,
71022 buffer, lenp, ppos);
71023 }
71024
71025+int proc_dostring_modpriv(struct ctl_table *table, int write,
71026+ void __user *buffer, size_t *lenp, loff_t *ppos)
71027+{
71028+ if (write && !capable(CAP_SYS_MODULE))
71029+ return -EPERM;
71030+
71031+ return _proc_do_string(table->data, table->maxlen, write,
71032+ buffer, lenp, ppos);
71033+}
71034+
71035 static size_t proc_skip_spaces(char **buf)
71036 {
71037 size_t ret;
71038@@ -1775,6 +1825,8 @@ static int proc_put_long(void __user **buf, size_t *size, unsigned long val,
71039 len = strlen(tmp);
71040 if (len > *size)
71041 len = *size;
71042+ if (len > sizeof(tmp))
71043+ len = sizeof(tmp);
71044 if (copy_to_user(*buf, tmp, len))
71045 return -EFAULT;
71046 *size -= len;
71047@@ -1967,7 +2019,6 @@ static int proc_taint(struct ctl_table *table, int write,
71048 return err;
71049 }
71050
71051-#ifdef CONFIG_PRINTK
71052 static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
71053 void __user *buffer, size_t *lenp, loff_t *ppos)
71054 {
71055@@ -1976,7 +2027,6 @@ static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
71056
71057 return proc_dointvec_minmax(table, write, buffer, lenp, ppos);
71058 }
71059-#endif
71060
71061 struct do_proc_dointvec_minmax_conv_param {
71062 int *min;
71063@@ -2119,8 +2169,11 @@ static int __do_proc_doulongvec_minmax(void *data, struct ctl_table *table, int
71064 *i = val;
71065 } else {
71066 val = convdiv * (*i) / convmul;
71067- if (!first)
71068+ if (!first) {
71069 err = proc_put_char(&buffer, &left, '\t');
71070+ if (err)
71071+ break;
71072+ }
71073 err = proc_put_long(&buffer, &left, val, false);
71074 if (err)
71075 break;
71076@@ -2512,6 +2565,12 @@ int proc_dostring(struct ctl_table *table, int write,
71077 return -ENOSYS;
71078 }
71079
71080+int proc_dostring_modpriv(struct ctl_table *table, int write,
71081+ void __user *buffer, size_t *lenp, loff_t *ppos)
71082+{
71083+ return -ENOSYS;
71084+}
71085+
71086 int proc_dointvec(struct ctl_table *table, int write,
71087 void __user *buffer, size_t *lenp, loff_t *ppos)
71088 {
71089@@ -2568,5 +2627,6 @@ EXPORT_SYMBOL(proc_dointvec_minmax);
71090 EXPORT_SYMBOL(proc_dointvec_userhz_jiffies);
71091 EXPORT_SYMBOL(proc_dointvec_ms_jiffies);
71092 EXPORT_SYMBOL(proc_dostring);
71093+EXPORT_SYMBOL(proc_dostring_modpriv);
71094 EXPORT_SYMBOL(proc_doulongvec_minmax);
71095 EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax);
71096diff --git a/kernel/sysctl_binary.c b/kernel/sysctl_binary.c
71097index 65bdcf1..21eb831 100644
71098--- a/kernel/sysctl_binary.c
71099+++ b/kernel/sysctl_binary.c
71100@@ -989,7 +989,7 @@ static ssize_t bin_intvec(struct file *file,
71101 int i;
71102
71103 set_fs(KERNEL_DS);
71104- result = vfs_read(file, buffer, BUFSZ - 1, &pos);
71105+ result = vfs_read(file, (char __force_user *)buffer, BUFSZ - 1, &pos);
71106 set_fs(old_fs);
71107 if (result < 0)
71108 goto out_kfree;
71109@@ -1034,7 +1034,7 @@ static ssize_t bin_intvec(struct file *file,
71110 }
71111
71112 set_fs(KERNEL_DS);
71113- result = vfs_write(file, buffer, str - buffer, &pos);
71114+ result = vfs_write(file, (const char __force_user *)buffer, str - buffer, &pos);
71115 set_fs(old_fs);
71116 if (result < 0)
71117 goto out_kfree;
71118@@ -1067,7 +1067,7 @@ static ssize_t bin_ulongvec(struct file *file,
71119 int i;
71120
71121 set_fs(KERNEL_DS);
71122- result = vfs_read(file, buffer, BUFSZ - 1, &pos);
71123+ result = vfs_read(file, (char __force_user *)buffer, BUFSZ - 1, &pos);
71124 set_fs(old_fs);
71125 if (result < 0)
71126 goto out_kfree;
71127@@ -1112,7 +1112,7 @@ static ssize_t bin_ulongvec(struct file *file,
71128 }
71129
71130 set_fs(KERNEL_DS);
71131- result = vfs_write(file, buffer, str - buffer, &pos);
71132+ result = vfs_write(file, (const char __force_user *)buffer, str - buffer, &pos);
71133 set_fs(old_fs);
71134 if (result < 0)
71135 goto out_kfree;
71136@@ -1138,7 +1138,7 @@ static ssize_t bin_uuid(struct file *file,
71137 int i;
71138
71139 set_fs(KERNEL_DS);
71140- result = vfs_read(file, buf, sizeof(buf) - 1, &pos);
71141+ result = vfs_read(file, (char __force_user *)buf, sizeof(buf) - 1, &pos);
71142 set_fs(old_fs);
71143 if (result < 0)
71144 goto out;
71145@@ -1185,7 +1185,7 @@ static ssize_t bin_dn_node_address(struct file *file,
71146 __le16 dnaddr;
71147
71148 set_fs(KERNEL_DS);
71149- result = vfs_read(file, buf, sizeof(buf) - 1, &pos);
71150+ result = vfs_read(file, (char __force_user *)buf, sizeof(buf) - 1, &pos);
71151 set_fs(old_fs);
71152 if (result < 0)
71153 goto out;
71154@@ -1233,7 +1233,7 @@ static ssize_t bin_dn_node_address(struct file *file,
71155 le16_to_cpu(dnaddr) & 0x3ff);
71156
71157 set_fs(KERNEL_DS);
71158- result = vfs_write(file, buf, len, &pos);
71159+ result = vfs_write(file, (const char __force_user *)buf, len, &pos);
71160 set_fs(old_fs);
71161 if (result < 0)
71162 goto out;
71163diff --git a/kernel/taskstats.c b/kernel/taskstats.c
71164index d0a3279..db0ad99 100644
71165--- a/kernel/taskstats.c
71166+++ b/kernel/taskstats.c
71167@@ -27,9 +27,12 @@
71168 #include <linux/cgroup.h>
71169 #include <linux/fs.h>
71170 #include <linux/file.h>
71171+#include <linux/grsecurity.h>
71172 #include <net/genetlink.h>
71173 #include <linux/atomic.h>
71174
71175+extern int gr_is_taskstats_denied(int pid);
71176+
71177 /*
71178 * Maximum length of a cpumask that can be specified in
71179 * the TASKSTATS_CMD_ATTR_REGISTER/DEREGISTER_CPUMASK attribute
71180@@ -561,6 +564,9 @@ err:
71181
71182 static int taskstats_user_cmd(struct sk_buff *skb, struct genl_info *info)
71183 {
71184+ if (gr_is_taskstats_denied(current->pid))
71185+ return -EACCES;
71186+
71187 if (info->attrs[TASKSTATS_CMD_ATTR_REGISTER_CPUMASK])
71188 return cmd_attr_register_cpumask(info);
71189 else if (info->attrs[TASKSTATS_CMD_ATTR_DEREGISTER_CPUMASK])
71190diff --git a/kernel/time.c b/kernel/time.c
71191index ba744cf..267b7c5 100644
71192--- a/kernel/time.c
71193+++ b/kernel/time.c
71194@@ -163,6 +163,11 @@ int do_sys_settimeofday(const struct timespec *tv, const struct timezone *tz)
71195 return error;
71196
71197 if (tz) {
71198+ /* we log in do_settimeofday called below, so don't log twice
71199+ */
71200+ if (!tv)
71201+ gr_log_timechange();
71202+
71203 sys_tz = *tz;
71204 update_vsyscall_tz();
71205 if (firsttime) {
71206diff --git a/kernel/time/alarmtimer.c b/kernel/time/alarmtimer.c
71207index aa27d39..34d221c 100644
71208--- a/kernel/time/alarmtimer.c
71209+++ b/kernel/time/alarmtimer.c
71210@@ -779,7 +779,7 @@ static int __init alarmtimer_init(void)
71211 struct platform_device *pdev;
71212 int error = 0;
71213 int i;
71214- struct k_clock alarm_clock = {
71215+ static struct k_clock alarm_clock = {
71216 .clock_getres = alarm_clock_getres,
71217 .clock_get = alarm_clock_get,
71218 .timer_create = alarm_timer_create,
71219diff --git a/kernel/time/tick-broadcast.c b/kernel/time/tick-broadcast.c
71220index f113755..ec24223 100644
71221--- a/kernel/time/tick-broadcast.c
71222+++ b/kernel/time/tick-broadcast.c
71223@@ -115,7 +115,7 @@ int tick_device_uses_broadcast(struct clock_event_device *dev, int cpu)
71224 * then clear the broadcast bit.
71225 */
71226 if (!(dev->features & CLOCK_EVT_FEAT_C3STOP)) {
71227- int cpu = smp_processor_id();
71228+ cpu = smp_processor_id();
71229
71230 cpumask_clear_cpu(cpu, tick_get_broadcast_mask());
71231 tick_broadcast_clear_oneshot(cpu);
71232diff --git a/kernel/time/timekeeping.c b/kernel/time/timekeeping.c
71233index f791637..00051de 100644
71234--- a/kernel/time/timekeeping.c
71235+++ b/kernel/time/timekeeping.c
71236@@ -14,6 +14,7 @@
71237 #include <linux/init.h>
71238 #include <linux/mm.h>
71239 #include <linux/sched.h>
71240+#include <linux/grsecurity.h>
71241 #include <linux/syscore_ops.h>
71242 #include <linux/clocksource.h>
71243 #include <linux/jiffies.h>
71244@@ -434,6 +435,8 @@ int do_settimeofday(const struct timespec *tv)
71245 if (!timespec_valid_strict(tv))
71246 return -EINVAL;
71247
71248+ gr_log_timechange();
71249+
71250 write_seqlock_irqsave(&tk->lock, flags);
71251
71252 timekeeping_forward_now(tk);
71253diff --git a/kernel/time/timer_list.c b/kernel/time/timer_list.c
71254index af5a7e9..715611a 100644
71255--- a/kernel/time/timer_list.c
71256+++ b/kernel/time/timer_list.c
71257@@ -38,12 +38,16 @@ DECLARE_PER_CPU(struct hrtimer_cpu_base, hrtimer_bases);
71258
71259 static void print_name_offset(struct seq_file *m, void *sym)
71260 {
71261+#ifdef CONFIG_GRKERNSEC_HIDESYM
71262+ SEQ_printf(m, "<%p>", NULL);
71263+#else
71264 char symname[KSYM_NAME_LEN];
71265
71266 if (lookup_symbol_name((unsigned long)sym, symname) < 0)
71267 SEQ_printf(m, "<%pK>", sym);
71268 else
71269 SEQ_printf(m, "%s", symname);
71270+#endif
71271 }
71272
71273 static void
71274@@ -112,7 +116,11 @@ next_one:
71275 static void
71276 print_base(struct seq_file *m, struct hrtimer_clock_base *base, u64 now)
71277 {
71278+#ifdef CONFIG_GRKERNSEC_HIDESYM
71279+ SEQ_printf(m, " .base: %p\n", NULL);
71280+#else
71281 SEQ_printf(m, " .base: %pK\n", base);
71282+#endif
71283 SEQ_printf(m, " .index: %d\n",
71284 base->index);
71285 SEQ_printf(m, " .resolution: %Lu nsecs\n",
71286@@ -293,7 +301,11 @@ static int __init init_timer_list_procfs(void)
71287 {
71288 struct proc_dir_entry *pe;
71289
71290+#ifdef CONFIG_GRKERNSEC_PROC_ADD
71291+ pe = proc_create("timer_list", 0400, NULL, &timer_list_fops);
71292+#else
71293 pe = proc_create("timer_list", 0444, NULL, &timer_list_fops);
71294+#endif
71295 if (!pe)
71296 return -ENOMEM;
71297 return 0;
71298diff --git a/kernel/time/timer_stats.c b/kernel/time/timer_stats.c
71299index 0b537f2..40d6c20 100644
71300--- a/kernel/time/timer_stats.c
71301+++ b/kernel/time/timer_stats.c
71302@@ -116,7 +116,7 @@ static ktime_t time_start, time_stop;
71303 static unsigned long nr_entries;
71304 static struct entry entries[MAX_ENTRIES];
71305
71306-static atomic_t overflow_count;
71307+static atomic_unchecked_t overflow_count;
71308
71309 /*
71310 * The entries are in a hash-table, for fast lookup:
71311@@ -140,7 +140,7 @@ static void reset_entries(void)
71312 nr_entries = 0;
71313 memset(entries, 0, sizeof(entries));
71314 memset(tstat_hash_table, 0, sizeof(tstat_hash_table));
71315- atomic_set(&overflow_count, 0);
71316+ atomic_set_unchecked(&overflow_count, 0);
71317 }
71318
71319 static struct entry *alloc_entry(void)
71320@@ -261,7 +261,7 @@ void timer_stats_update_stats(void *timer, pid_t pid, void *startf,
71321 if (likely(entry))
71322 entry->count++;
71323 else
71324- atomic_inc(&overflow_count);
71325+ atomic_inc_unchecked(&overflow_count);
71326
71327 out_unlock:
71328 raw_spin_unlock_irqrestore(lock, flags);
71329@@ -269,12 +269,16 @@ void timer_stats_update_stats(void *timer, pid_t pid, void *startf,
71330
71331 static void print_name_offset(struct seq_file *m, unsigned long addr)
71332 {
71333+#ifdef CONFIG_GRKERNSEC_HIDESYM
71334+ seq_printf(m, "<%p>", NULL);
71335+#else
71336 char symname[KSYM_NAME_LEN];
71337
71338 if (lookup_symbol_name(addr, symname) < 0)
71339- seq_printf(m, "<%p>", (void *)addr);
71340+ seq_printf(m, "<%pK>", (void *)addr);
71341 else
71342 seq_printf(m, "%s", symname);
71343+#endif
71344 }
71345
71346 static int tstats_show(struct seq_file *m, void *v)
71347@@ -300,9 +304,9 @@ static int tstats_show(struct seq_file *m, void *v)
71348
71349 seq_puts(m, "Timer Stats Version: v0.2\n");
71350 seq_printf(m, "Sample period: %ld.%03ld s\n", period.tv_sec, ms);
71351- if (atomic_read(&overflow_count))
71352+ if (atomic_read_unchecked(&overflow_count))
71353 seq_printf(m, "Overflow: %d entries\n",
71354- atomic_read(&overflow_count));
71355+ atomic_read_unchecked(&overflow_count));
71356
71357 for (i = 0; i < nr_entries; i++) {
71358 entry = entries + i;
71359@@ -417,7 +421,11 @@ static int __init init_tstats_procfs(void)
71360 {
71361 struct proc_dir_entry *pe;
71362
71363+#ifdef CONFIG_GRKERNSEC_PROC_ADD
71364+ pe = proc_create("timer_stats", 0600, NULL, &tstats_fops);
71365+#else
71366 pe = proc_create("timer_stats", 0644, NULL, &tstats_fops);
71367+#endif
71368 if (!pe)
71369 return -ENOMEM;
71370 return 0;
71371diff --git a/kernel/timer.c b/kernel/timer.c
71372index 46ef2b1..ad081f144 100644
71373--- a/kernel/timer.c
71374+++ b/kernel/timer.c
71375@@ -1377,7 +1377,7 @@ void update_process_times(int user_tick)
71376 /*
71377 * This function runs timers and the timer-tq in bottom half context.
71378 */
71379-static void run_timer_softirq(struct softirq_action *h)
71380+static void run_timer_softirq(void)
71381 {
71382 struct tvec_base *base = __this_cpu_read(tvec_bases);
71383
71384diff --git a/kernel/trace/blktrace.c b/kernel/trace/blktrace.c
71385index c0bd030..62a1927 100644
71386--- a/kernel/trace/blktrace.c
71387+++ b/kernel/trace/blktrace.c
71388@@ -317,7 +317,7 @@ static ssize_t blk_dropped_read(struct file *filp, char __user *buffer,
71389 struct blk_trace *bt = filp->private_data;
71390 char buf[16];
71391
71392- snprintf(buf, sizeof(buf), "%u\n", atomic_read(&bt->dropped));
71393+ snprintf(buf, sizeof(buf), "%u\n", atomic_read_unchecked(&bt->dropped));
71394
71395 return simple_read_from_buffer(buffer, count, ppos, buf, strlen(buf));
71396 }
71397@@ -375,7 +375,7 @@ static int blk_subbuf_start_callback(struct rchan_buf *buf, void *subbuf,
71398 return 1;
71399
71400 bt = buf->chan->private_data;
71401- atomic_inc(&bt->dropped);
71402+ atomic_inc_unchecked(&bt->dropped);
71403 return 0;
71404 }
71405
71406@@ -476,7 +476,7 @@ int do_blk_trace_setup(struct request_queue *q, char *name, dev_t dev,
71407
71408 bt->dir = dir;
71409 bt->dev = dev;
71410- atomic_set(&bt->dropped, 0);
71411+ atomic_set_unchecked(&bt->dropped, 0);
71412
71413 ret = -EIO;
71414 bt->dropped_file = debugfs_create_file("dropped", 0444, dir, bt,
71415diff --git a/kernel/trace/ftrace.c b/kernel/trace/ftrace.c
71416index b4f20fb..483c5fa 100644
71417--- a/kernel/trace/ftrace.c
71418+++ b/kernel/trace/ftrace.c
71419@@ -1785,12 +1785,17 @@ ftrace_code_disable(struct module *mod, struct dyn_ftrace *rec)
71420 if (unlikely(ftrace_disabled))
71421 return 0;
71422
71423+ ret = ftrace_arch_code_modify_prepare();
71424+ FTRACE_WARN_ON(ret);
71425+ if (ret)
71426+ return 0;
71427+
71428 ret = ftrace_make_nop(mod, rec, MCOUNT_ADDR);
71429+ FTRACE_WARN_ON(ftrace_arch_code_modify_post_process());
71430 if (ret) {
71431 ftrace_bug(ret, ip);
71432- return 0;
71433 }
71434- return 1;
71435+ return ret ? 0 : 1;
71436 }
71437
71438 /*
71439@@ -2885,7 +2890,7 @@ static void ftrace_free_entry_rcu(struct rcu_head *rhp)
71440
71441 int
71442 register_ftrace_function_probe(char *glob, struct ftrace_probe_ops *ops,
71443- void *data)
71444+ void *data)
71445 {
71446 struct ftrace_func_probe *entry;
71447 struct ftrace_page *pg;
71448@@ -3697,8 +3702,10 @@ static int ftrace_process_locs(struct module *mod,
71449 if (!count)
71450 return 0;
71451
71452+ pax_open_kernel();
71453 sort(start, count, sizeof(*start),
71454 ftrace_cmp_ips, ftrace_swap_ips);
71455+ pax_close_kernel();
71456
71457 start_pg = ftrace_allocate_pages(count);
71458 if (!start_pg)
71459diff --git a/kernel/trace/trace.c b/kernel/trace/trace.c
71460index 5c38c81..88012af 100644
71461--- a/kernel/trace/trace.c
71462+++ b/kernel/trace/trace.c
71463@@ -4437,10 +4437,9 @@ static const struct file_operations tracing_dyn_info_fops = {
71464 };
71465 #endif
71466
71467-static struct dentry *d_tracer;
71468-
71469 struct dentry *tracing_init_dentry(void)
71470 {
71471+ static struct dentry *d_tracer;
71472 static int once;
71473
71474 if (d_tracer)
71475@@ -4460,10 +4459,9 @@ struct dentry *tracing_init_dentry(void)
71476 return d_tracer;
71477 }
71478
71479-static struct dentry *d_percpu;
71480-
71481 struct dentry *tracing_dentry_percpu(void)
71482 {
71483+ static struct dentry *d_percpu;
71484 static int once;
71485 struct dentry *d_tracer;
71486
71487diff --git a/kernel/trace/trace_events.c b/kernel/trace/trace_events.c
71488index 29111da..d190fe2 100644
71489--- a/kernel/trace/trace_events.c
71490+++ b/kernel/trace/trace_events.c
71491@@ -1308,10 +1308,6 @@ static LIST_HEAD(ftrace_module_file_list);
71492 struct ftrace_module_file_ops {
71493 struct list_head list;
71494 struct module *mod;
71495- struct file_operations id;
71496- struct file_operations enable;
71497- struct file_operations format;
71498- struct file_operations filter;
71499 };
71500
71501 static struct ftrace_module_file_ops *
71502@@ -1332,17 +1328,12 @@ trace_create_file_ops(struct module *mod)
71503
71504 file_ops->mod = mod;
71505
71506- file_ops->id = ftrace_event_id_fops;
71507- file_ops->id.owner = mod;
71508-
71509- file_ops->enable = ftrace_enable_fops;
71510- file_ops->enable.owner = mod;
71511-
71512- file_ops->filter = ftrace_event_filter_fops;
71513- file_ops->filter.owner = mod;
71514-
71515- file_ops->format = ftrace_event_format_fops;
71516- file_ops->format.owner = mod;
71517+ pax_open_kernel();
71518+ *(void **)&mod->trace_id.owner = mod;
71519+ *(void **)&mod->trace_enable.owner = mod;
71520+ *(void **)&mod->trace_filter.owner = mod;
71521+ *(void **)&mod->trace_format.owner = mod;
71522+ pax_close_kernel();
71523
71524 list_add(&file_ops->list, &ftrace_module_file_list);
71525
71526@@ -1366,8 +1357,8 @@ static void trace_module_add_events(struct module *mod)
71527
71528 for_each_event(call, start, end) {
71529 __trace_add_event_call(*call, mod,
71530- &file_ops->id, &file_ops->enable,
71531- &file_ops->filter, &file_ops->format);
71532+ &mod->trace_id, &mod->trace_enable,
71533+ &mod->trace_filter, &mod->trace_format);
71534 }
71535 }
71536
71537diff --git a/kernel/trace/trace_mmiotrace.c b/kernel/trace/trace_mmiotrace.c
71538index fd3c8aa..5f324a6 100644
71539--- a/kernel/trace/trace_mmiotrace.c
71540+++ b/kernel/trace/trace_mmiotrace.c
71541@@ -24,7 +24,7 @@ struct header_iter {
71542 static struct trace_array *mmio_trace_array;
71543 static bool overrun_detected;
71544 static unsigned long prev_overruns;
71545-static atomic_t dropped_count;
71546+static atomic_unchecked_t dropped_count;
71547
71548 static void mmio_reset_data(struct trace_array *tr)
71549 {
71550@@ -127,7 +127,7 @@ static void mmio_close(struct trace_iterator *iter)
71551
71552 static unsigned long count_overruns(struct trace_iterator *iter)
71553 {
71554- unsigned long cnt = atomic_xchg(&dropped_count, 0);
71555+ unsigned long cnt = atomic_xchg_unchecked(&dropped_count, 0);
71556 unsigned long over = ring_buffer_overruns(iter->tr->buffer);
71557
71558 if (over > prev_overruns)
71559@@ -317,7 +317,7 @@ static void __trace_mmiotrace_rw(struct trace_array *tr,
71560 event = trace_buffer_lock_reserve(buffer, TRACE_MMIO_RW,
71561 sizeof(*entry), 0, pc);
71562 if (!event) {
71563- atomic_inc(&dropped_count);
71564+ atomic_inc_unchecked(&dropped_count);
71565 return;
71566 }
71567 entry = ring_buffer_event_data(event);
71568@@ -347,7 +347,7 @@ static void __trace_mmiotrace_map(struct trace_array *tr,
71569 event = trace_buffer_lock_reserve(buffer, TRACE_MMIO_MAP,
71570 sizeof(*entry), 0, pc);
71571 if (!event) {
71572- atomic_inc(&dropped_count);
71573+ atomic_inc_unchecked(&dropped_count);
71574 return;
71575 }
71576 entry = ring_buffer_event_data(event);
71577diff --git a/kernel/trace/trace_output.c b/kernel/trace/trace_output.c
71578index 123b189..97b81f5 100644
71579--- a/kernel/trace/trace_output.c
71580+++ b/kernel/trace/trace_output.c
71581@@ -278,7 +278,7 @@ int trace_seq_path(struct trace_seq *s, const struct path *path)
71582
71583 p = d_path(path, s->buffer + s->len, PAGE_SIZE - s->len);
71584 if (!IS_ERR(p)) {
71585- p = mangle_path(s->buffer + s->len, p, "\n");
71586+ p = mangle_path(s->buffer + s->len, p, "\n\\");
71587 if (p) {
71588 s->len = p - s->buffer;
71589 return 1;
71590diff --git a/kernel/trace/trace_stack.c b/kernel/trace/trace_stack.c
71591index d4545f4..a9010a1 100644
71592--- a/kernel/trace/trace_stack.c
71593+++ b/kernel/trace/trace_stack.c
71594@@ -53,7 +53,7 @@ static inline void check_stack(void)
71595 return;
71596
71597 /* we do not handle interrupt stacks yet */
71598- if (!object_is_on_stack(&this_size))
71599+ if (!object_starts_on_stack(&this_size))
71600 return;
71601
71602 local_irq_save(flags);
71603diff --git a/kernel/workqueue.c b/kernel/workqueue.c
71604index 872bd6d..31601a2 100644
71605--- a/kernel/workqueue.c
71606+++ b/kernel/workqueue.c
71607@@ -1422,7 +1422,7 @@ retry:
71608 /* morph UNBOUND to REBIND atomically */
71609 worker_flags &= ~WORKER_UNBOUND;
71610 worker_flags |= WORKER_REBIND;
71611- ACCESS_ONCE(worker->flags) = worker_flags;
71612+ ACCESS_ONCE_RW(worker->flags) = worker_flags;
71613
71614 idle_rebind.cnt++;
71615 worker->idle_rebind = &idle_rebind;
71616@@ -1448,7 +1448,7 @@ retry:
71617 /* morph UNBOUND to REBIND atomically */
71618 worker_flags &= ~WORKER_UNBOUND;
71619 worker_flags |= WORKER_REBIND;
71620- ACCESS_ONCE(worker->flags) = worker_flags;
71621+ ACCESS_ONCE_RW(worker->flags) = worker_flags;
71622
71623 if (test_and_set_bit(WORK_STRUCT_PENDING_BIT,
71624 work_data_bits(rebind_work)))
71625diff --git a/lib/Kconfig.debug b/lib/Kconfig.debug
71626index 2403a63..5c4be4c 100644
71627--- a/lib/Kconfig.debug
71628+++ b/lib/Kconfig.debug
71629@@ -1252,6 +1252,7 @@ config LATENCYTOP
71630 depends on DEBUG_KERNEL
71631 depends on STACKTRACE_SUPPORT
71632 depends on PROC_FS
71633+ depends on !GRKERNSEC_HIDESYM
71634 select FRAME_POINTER if !MIPS && !PPC && !S390 && !MICROBLAZE && !ARM_UNWIND
71635 select KALLSYMS
71636 select KALLSYMS_ALL
71637@@ -1267,7 +1268,7 @@ source kernel/trace/Kconfig
71638
71639 config PROVIDE_OHCI1394_DMA_INIT
71640 bool "Remote debugging over FireWire early on boot"
71641- depends on PCI && X86
71642+ depends on PCI && X86 && !GRKERNSEC
71643 help
71644 If you want to debug problems which hang or crash the kernel early
71645 on boot and the crashing machine has a FireWire port, you can use
71646@@ -1296,7 +1297,7 @@ config PROVIDE_OHCI1394_DMA_INIT
71647
71648 config FIREWIRE_OHCI_REMOTE_DMA
71649 bool "Remote debugging over FireWire with firewire-ohci"
71650- depends on FIREWIRE_OHCI
71651+ depends on FIREWIRE_OHCI && !GRKERNSEC
71652 help
71653 This option lets you use the FireWire bus for remote debugging
71654 with help of the firewire-ohci driver. It enables unfiltered
71655diff --git a/lib/bitmap.c b/lib/bitmap.c
71656index 06fdfa1..97c5c7d 100644
71657--- a/lib/bitmap.c
71658+++ b/lib/bitmap.c
71659@@ -422,7 +422,7 @@ int __bitmap_parse(const char *buf, unsigned int buflen,
71660 {
71661 int c, old_c, totaldigits, ndigits, nchunks, nbits;
71662 u32 chunk;
71663- const char __user __force *ubuf = (const char __user __force *)buf;
71664+ const char __user *ubuf = (const char __force_user *)buf;
71665
71666 bitmap_zero(maskp, nmaskbits);
71667
71668@@ -507,7 +507,7 @@ int bitmap_parse_user(const char __user *ubuf,
71669 {
71670 if (!access_ok(VERIFY_READ, ubuf, ulen))
71671 return -EFAULT;
71672- return __bitmap_parse((const char __force *)ubuf,
71673+ return __bitmap_parse((const char __force_kernel *)ubuf,
71674 ulen, 1, maskp, nmaskbits);
71675
71676 }
71677@@ -598,7 +598,7 @@ static int __bitmap_parselist(const char *buf, unsigned int buflen,
71678 {
71679 unsigned a, b;
71680 int c, old_c, totaldigits;
71681- const char __user __force *ubuf = (const char __user __force *)buf;
71682+ const char __user *ubuf = (const char __force_user *)buf;
71683 int exp_digit, in_range;
71684
71685 totaldigits = c = 0;
71686@@ -698,7 +698,7 @@ int bitmap_parselist_user(const char __user *ubuf,
71687 {
71688 if (!access_ok(VERIFY_READ, ubuf, ulen))
71689 return -EFAULT;
71690- return __bitmap_parselist((const char __force *)ubuf,
71691+ return __bitmap_parselist((const char __force_kernel *)ubuf,
71692 ulen, 1, maskp, nmaskbits);
71693 }
71694 EXPORT_SYMBOL(bitmap_parselist_user);
71695diff --git a/lib/bug.c b/lib/bug.c
71696index a28c141..2bd3d95 100644
71697--- a/lib/bug.c
71698+++ b/lib/bug.c
71699@@ -133,6 +133,8 @@ enum bug_trap_type report_bug(unsigned long bugaddr, struct pt_regs *regs)
71700 return BUG_TRAP_TYPE_NONE;
71701
71702 bug = find_bug(bugaddr);
71703+ if (!bug)
71704+ return BUG_TRAP_TYPE_NONE;
71705
71706 file = NULL;
71707 line = 0;
71708diff --git a/lib/debugobjects.c b/lib/debugobjects.c
71709index d11808c..dc2d6f8 100644
71710--- a/lib/debugobjects.c
71711+++ b/lib/debugobjects.c
71712@@ -287,7 +287,7 @@ static void debug_object_is_on_stack(void *addr, int onstack)
71713 if (limit > 4)
71714 return;
71715
71716- is_on_stack = object_is_on_stack(addr);
71717+ is_on_stack = object_starts_on_stack(addr);
71718 if (is_on_stack == onstack)
71719 return;
71720
71721diff --git a/lib/devres.c b/lib/devres.c
71722index 80b9c76..9e32279 100644
71723--- a/lib/devres.c
71724+++ b/lib/devres.c
71725@@ -80,7 +80,7 @@ EXPORT_SYMBOL(devm_ioremap_nocache);
71726 void devm_iounmap(struct device *dev, void __iomem *addr)
71727 {
71728 WARN_ON(devres_destroy(dev, devm_ioremap_release, devm_ioremap_match,
71729- (void *)addr));
71730+ (void __force *)addr));
71731 iounmap(addr);
71732 }
71733 EXPORT_SYMBOL(devm_iounmap);
71734@@ -192,7 +192,7 @@ void devm_ioport_unmap(struct device *dev, void __iomem *addr)
71735 {
71736 ioport_unmap(addr);
71737 WARN_ON(devres_destroy(dev, devm_ioport_map_release,
71738- devm_ioport_map_match, (void *)addr));
71739+ devm_ioport_map_match, (void __force *)addr));
71740 }
71741 EXPORT_SYMBOL(devm_ioport_unmap);
71742
71743diff --git a/lib/dma-debug.c b/lib/dma-debug.c
71744index 66ce414..6f0a0dd 100644
71745--- a/lib/dma-debug.c
71746+++ b/lib/dma-debug.c
71747@@ -924,7 +924,7 @@ out:
71748
71749 static void check_for_stack(struct device *dev, void *addr)
71750 {
71751- if (object_is_on_stack(addr))
71752+ if (object_starts_on_stack(addr))
71753 err_printk(dev, NULL, "DMA-API: device driver maps memory from"
71754 "stack [addr=%p]\n", addr);
71755 }
71756diff --git a/lib/inflate.c b/lib/inflate.c
71757index 013a761..c28f3fc 100644
71758--- a/lib/inflate.c
71759+++ b/lib/inflate.c
71760@@ -269,7 +269,7 @@ static void free(void *where)
71761 malloc_ptr = free_mem_ptr;
71762 }
71763 #else
71764-#define malloc(a) kmalloc(a, GFP_KERNEL)
71765+#define malloc(a) kmalloc((a), GFP_KERNEL)
71766 #define free(a) kfree(a)
71767 #endif
71768
71769diff --git a/lib/ioremap.c b/lib/ioremap.c
71770index 0c9216c..863bd89 100644
71771--- a/lib/ioremap.c
71772+++ b/lib/ioremap.c
71773@@ -38,7 +38,7 @@ static inline int ioremap_pmd_range(pud_t *pud, unsigned long addr,
71774 unsigned long next;
71775
71776 phys_addr -= addr;
71777- pmd = pmd_alloc(&init_mm, pud, addr);
71778+ pmd = pmd_alloc_kernel(&init_mm, pud, addr);
71779 if (!pmd)
71780 return -ENOMEM;
71781 do {
71782@@ -56,7 +56,7 @@ static inline int ioremap_pud_range(pgd_t *pgd, unsigned long addr,
71783 unsigned long next;
71784
71785 phys_addr -= addr;
71786- pud = pud_alloc(&init_mm, pgd, addr);
71787+ pud = pud_alloc_kernel(&init_mm, pgd, addr);
71788 if (!pud)
71789 return -ENOMEM;
71790 do {
71791diff --git a/lib/is_single_threaded.c b/lib/is_single_threaded.c
71792index bd2bea9..6b3c95e 100644
71793--- a/lib/is_single_threaded.c
71794+++ b/lib/is_single_threaded.c
71795@@ -22,6 +22,9 @@ bool current_is_single_threaded(void)
71796 struct task_struct *p, *t;
71797 bool ret;
71798
71799+ if (!mm)
71800+ return true;
71801+
71802 if (atomic_read(&task->signal->live) != 1)
71803 return false;
71804
71805diff --git a/lib/list_debug.c b/lib/list_debug.c
71806index c24c2f7..bef49ee 100644
71807--- a/lib/list_debug.c
71808+++ b/lib/list_debug.c
71809@@ -23,17 +23,19 @@ void __list_add(struct list_head *new,
71810 struct list_head *prev,
71811 struct list_head *next)
71812 {
71813- WARN(next->prev != prev,
71814+ if (WARN(next->prev != prev,
71815 "list_add corruption. next->prev should be "
71816 "prev (%p), but was %p. (next=%p).\n",
71817- prev, next->prev, next);
71818- WARN(prev->next != next,
71819+ prev, next->prev, next) ||
71820+ WARN(prev->next != next,
71821 "list_add corruption. prev->next should be "
71822 "next (%p), but was %p. (prev=%p).\n",
71823- next, prev->next, prev);
71824- WARN(new == prev || new == next,
71825+ next, prev->next, prev) ||
71826+ WARN(new == prev || new == next,
71827 "list_add double add: new=%p, prev=%p, next=%p.\n",
71828- new, prev, next);
71829+ new, prev, next))
71830+ return;
71831+
71832 next->prev = new;
71833 new->next = next;
71834 new->prev = prev;
71835@@ -86,12 +88,14 @@ EXPORT_SYMBOL(list_del);
71836 void __list_add_rcu(struct list_head *new,
71837 struct list_head *prev, struct list_head *next)
71838 {
71839- WARN(next->prev != prev,
71840+ if (WARN(next->prev != prev,
71841 "list_add_rcu corruption. next->prev should be prev (%p), but was %p. (next=%p).\n",
71842- prev, next->prev, next);
71843- WARN(prev->next != next,
71844+ prev, next->prev, next) ||
71845+ WARN(prev->next != next,
71846 "list_add_rcu corruption. prev->next should be next (%p), but was %p. (prev=%p).\n",
71847- next, prev->next, prev);
71848+ next, prev->next, prev))
71849+ return;
71850+
71851 new->next = next;
71852 new->prev = prev;
71853 rcu_assign_pointer(list_next_rcu(prev), new);
71854diff --git a/lib/radix-tree.c b/lib/radix-tree.c
71855index e796429..6e38f9f 100644
71856--- a/lib/radix-tree.c
71857+++ b/lib/radix-tree.c
71858@@ -92,7 +92,7 @@ struct radix_tree_preload {
71859 int nr;
71860 struct radix_tree_node *nodes[RADIX_TREE_PRELOAD_SIZE];
71861 };
71862-static DEFINE_PER_CPU(struct radix_tree_preload, radix_tree_preloads) = { 0, };
71863+static DEFINE_PER_CPU(struct radix_tree_preload, radix_tree_preloads);
71864
71865 static inline void *ptr_to_indirect(void *ptr)
71866 {
71867diff --git a/lib/strncpy_from_user.c b/lib/strncpy_from_user.c
71868index bb2b201..46abaf9 100644
71869--- a/lib/strncpy_from_user.c
71870+++ b/lib/strncpy_from_user.c
71871@@ -21,7 +21,7 @@
71872 */
71873 static inline long do_strncpy_from_user(char *dst, const char __user *src, long count, unsigned long max)
71874 {
71875- const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
71876+ static const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
71877 long res = 0;
71878
71879 /*
71880diff --git a/lib/strnlen_user.c b/lib/strnlen_user.c
71881index a28df52..3d55877 100644
71882--- a/lib/strnlen_user.c
71883+++ b/lib/strnlen_user.c
71884@@ -26,7 +26,7 @@
71885 */
71886 static inline long do_strnlen_user(const char __user *src, unsigned long count, unsigned long max)
71887 {
71888- const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
71889+ static const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
71890 long align, res = 0;
71891 unsigned long c;
71892
71893diff --git a/lib/vsprintf.c b/lib/vsprintf.c
71894index 0e33754..50a0e63 100644
71895--- a/lib/vsprintf.c
71896+++ b/lib/vsprintf.c
71897@@ -16,6 +16,9 @@
71898 * - scnprintf and vscnprintf
71899 */
71900
71901+#ifdef CONFIG_GRKERNSEC_HIDESYM
71902+#define __INCLUDED_BY_HIDESYM 1
71903+#endif
71904 #include <stdarg.h>
71905 #include <linux/module.h> /* for KSYM_SYMBOL_LEN */
71906 #include <linux/types.h>
71907@@ -536,7 +539,7 @@ char *symbol_string(char *buf, char *end, void *ptr,
71908 char sym[KSYM_SYMBOL_LEN];
71909 if (ext == 'B')
71910 sprint_backtrace(sym, value);
71911- else if (ext != 'f' && ext != 's')
71912+ else if (ext != 'f' && ext != 's' && ext != 'a')
71913 sprint_symbol(sym, value);
71914 else
71915 sprint_symbol_no_offset(sym, value);
71916@@ -969,7 +972,11 @@ char *netdev_feature_string(char *buf, char *end, const u8 *addr,
71917 return number(buf, end, *(const netdev_features_t *)addr, spec);
71918 }
71919
71920+#ifdef CONFIG_GRKERNSEC_HIDESYM
71921+int kptr_restrict __read_mostly = 2;
71922+#else
71923 int kptr_restrict __read_mostly;
71924+#endif
71925
71926 /*
71927 * Show a '%p' thing. A kernel extension is that the '%p' is followed
71928@@ -983,6 +990,8 @@ int kptr_restrict __read_mostly;
71929 * - 'S' For symbolic direct pointers with offset
71930 * - 's' For symbolic direct pointers without offset
71931 * - 'B' For backtraced symbolic direct pointers with offset
71932+ * - 'A' For symbolic direct pointers with offset approved for use with GRKERNSEC_HIDESYM
71933+ * - 'a' For symbolic direct pointers without offset approved for use with GRKERNSEC_HIDESYM
71934 * - 'R' For decoded struct resource, e.g., [mem 0x0-0x1f 64bit pref]
71935 * - 'r' For raw struct resource, e.g., [mem 0x0-0x1f flags 0x201]
71936 * - 'M' For a 6-byte MAC address, it prints the address in the
71937@@ -1038,12 +1047,12 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
71938
71939 if (!ptr && *fmt != 'K') {
71940 /*
71941- * Print (null) with the same width as a pointer so it makes
71942+ * Print (nil) with the same width as a pointer so it makes
71943 * tabular output look nice.
71944 */
71945 if (spec.field_width == -1)
71946 spec.field_width = default_width;
71947- return string(buf, end, "(null)", spec);
71948+ return string(buf, end, "(nil)", spec);
71949 }
71950
71951 switch (*fmt) {
71952@@ -1053,6 +1062,13 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
71953 /* Fallthrough */
71954 case 'S':
71955 case 's':
71956+#ifdef CONFIG_GRKERNSEC_HIDESYM
71957+ break;
71958+#else
71959+ return symbol_string(buf, end, ptr, spec, *fmt);
71960+#endif
71961+ case 'A':
71962+ case 'a':
71963 case 'B':
71964 return symbol_string(buf, end, ptr, spec, *fmt);
71965 case 'R':
71966@@ -1093,6 +1109,8 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
71967 va_end(va);
71968 return buf;
71969 }
71970+ case 'P':
71971+ break;
71972 case 'K':
71973 /*
71974 * %pK cannot be used in IRQ context because its test
71975@@ -1116,6 +1134,21 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
71976 }
71977 break;
71978 }
71979+
71980+#ifdef CONFIG_GRKERNSEC_HIDESYM
71981+ /* 'P' = approved pointers to copy to userland,
71982+ as in the /proc/kallsyms case, as we make it display nothing
71983+ for non-root users, and the real contents for root users
71984+ Also ignore 'K' pointers, since we force their NULLing for non-root users
71985+ above
71986+ */
71987+ if (ptr > TASK_SIZE && *fmt != 'P' && *fmt != 'K' && is_usercopy_object(buf)) {
71988+ printk(KERN_ALERT "grsec: kernel infoleak detected! Please report this log to spender@grsecurity.net.\n");
71989+ dump_stack();
71990+ ptr = NULL;
71991+ }
71992+#endif
71993+
71994 spec.flags |= SMALL;
71995 if (spec.field_width == -1) {
71996 spec.field_width = default_width;
71997@@ -1831,11 +1864,11 @@ int bstr_printf(char *buf, size_t size, const char *fmt, const u32 *bin_buf)
71998 typeof(type) value; \
71999 if (sizeof(type) == 8) { \
72000 args = PTR_ALIGN(args, sizeof(u32)); \
72001- *(u32 *)&value = *(u32 *)args; \
72002- *((u32 *)&value + 1) = *(u32 *)(args + 4); \
72003+ *(u32 *)&value = *(const u32 *)args; \
72004+ *((u32 *)&value + 1) = *(const u32 *)(args + 4); \
72005 } else { \
72006 args = PTR_ALIGN(args, sizeof(type)); \
72007- value = *(typeof(type) *)args; \
72008+ value = *(const typeof(type) *)args; \
72009 } \
72010 args += sizeof(type); \
72011 value; \
72012@@ -1898,7 +1931,7 @@ int bstr_printf(char *buf, size_t size, const char *fmt, const u32 *bin_buf)
72013 case FORMAT_TYPE_STR: {
72014 const char *str_arg = args;
72015 args += strlen(str_arg) + 1;
72016- str = string(str, end, (char *)str_arg, spec);
72017+ str = string(str, end, str_arg, spec);
72018 break;
72019 }
72020
72021diff --git a/localversion-grsec b/localversion-grsec
72022new file mode 100644
72023index 0000000..7cd6065
72024--- /dev/null
72025+++ b/localversion-grsec
72026@@ -0,0 +1 @@
72027+-grsec
72028diff --git a/mm/Kconfig b/mm/Kconfig
72029index d5c8019..f513038 100644
72030--- a/mm/Kconfig
72031+++ b/mm/Kconfig
72032@@ -251,10 +251,10 @@ config KSM
72033 root has set /sys/kernel/mm/ksm/run to 1 (if CONFIG_SYSFS is set).
72034
72035 config DEFAULT_MMAP_MIN_ADDR
72036- int "Low address space to protect from user allocation"
72037+ int "Low address space to protect from user allocation"
72038 depends on MMU
72039- default 4096
72040- help
72041+ default 65536
72042+ help
72043 This is the portion of low virtual memory which should be protected
72044 from userspace allocation. Keeping a user from writing to low pages
72045 can help reduce the impact of kernel NULL pointer bugs.
72046@@ -285,7 +285,7 @@ config MEMORY_FAILURE
72047
72048 config HWPOISON_INJECT
72049 tristate "HWPoison pages injector"
72050- depends on MEMORY_FAILURE && DEBUG_KERNEL && PROC_FS
72051+ depends on MEMORY_FAILURE && DEBUG_KERNEL && PROC_FS && !GRKERNSEC
72052 select PROC_PAGE_MONITOR
72053
72054 config NOMMU_INITIAL_TRIM_EXCESS
72055diff --git a/mm/filemap.c b/mm/filemap.c
72056index 3843445..4fe6833 100644
72057--- a/mm/filemap.c
72058+++ b/mm/filemap.c
72059@@ -1746,7 +1746,7 @@ int generic_file_mmap(struct file * file, struct vm_area_struct * vma)
72060 struct address_space *mapping = file->f_mapping;
72061
72062 if (!mapping->a_ops->readpage)
72063- return -ENOEXEC;
72064+ return -ENODEV;
72065 file_accessed(file);
72066 vma->vm_ops = &generic_file_vm_ops;
72067 vma->vm_flags |= VM_CAN_NONLINEAR;
72068@@ -2087,6 +2087,7 @@ inline int generic_write_checks(struct file *file, loff_t *pos, size_t *count, i
72069 *pos = i_size_read(inode);
72070
72071 if (limit != RLIM_INFINITY) {
72072+ gr_learn_resource(current, RLIMIT_FSIZE,*pos, 0);
72073 if (*pos >= limit) {
72074 send_sig(SIGXFSZ, current, 0);
72075 return -EFBIG;
72076diff --git a/mm/fremap.c b/mm/fremap.c
72077index 9ed4fd4..c42648d 100644
72078--- a/mm/fremap.c
72079+++ b/mm/fremap.c
72080@@ -155,6 +155,11 @@ SYSCALL_DEFINE5(remap_file_pages, unsigned long, start, unsigned long, size,
72081 retry:
72082 vma = find_vma(mm, start);
72083
72084+#ifdef CONFIG_PAX_SEGMEXEC
72085+ if (vma && (mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_flags & VM_MAYEXEC))
72086+ goto out;
72087+#endif
72088+
72089 /*
72090 * Make sure the vma is shared, that it supports prefaulting,
72091 * and that the remapped range is valid and fully within
72092diff --git a/mm/highmem.c b/mm/highmem.c
72093index d517cd1..006a1c5 100644
72094--- a/mm/highmem.c
72095+++ b/mm/highmem.c
72096@@ -137,9 +137,10 @@ static void flush_all_zero_pkmaps(void)
72097 * So no dangers, even with speculative execution.
72098 */
72099 page = pte_page(pkmap_page_table[i]);
72100+ pax_open_kernel();
72101 pte_clear(&init_mm, (unsigned long)page_address(page),
72102 &pkmap_page_table[i]);
72103-
72104+ pax_close_kernel();
72105 set_page_address(page, NULL);
72106 need_flush = 1;
72107 }
72108@@ -198,9 +199,11 @@ start:
72109 }
72110 }
72111 vaddr = PKMAP_ADDR(last_pkmap_nr);
72112+
72113+ pax_open_kernel();
72114 set_pte_at(&init_mm, vaddr,
72115 &(pkmap_page_table[last_pkmap_nr]), mk_pte(page, kmap_prot));
72116-
72117+ pax_close_kernel();
72118 pkmap_count[last_pkmap_nr] = 1;
72119 set_page_address(page, (void *)vaddr);
72120
72121diff --git a/mm/huge_memory.c b/mm/huge_memory.c
72122index 141dbb6..ebff057 100644
72123--- a/mm/huge_memory.c
72124+++ b/mm/huge_memory.c
72125@@ -735,7 +735,7 @@ out:
72126 * run pte_offset_map on the pmd, if an huge pmd could
72127 * materialize from under us from a different thread.
72128 */
72129- if (unlikely(__pte_alloc(mm, vma, pmd, address)))
72130+ if (unlikely(pmd_none(*pmd) && __pte_alloc(mm, vma, pmd, address)))
72131 return VM_FAULT_OOM;
72132 /* if an huge pmd materialized from under us just retry later */
72133 if (unlikely(pmd_trans_huge(*pmd)))
72134diff --git a/mm/hugetlb.c b/mm/hugetlb.c
72135index 3adceaf..dccfea3 100644
72136--- a/mm/hugetlb.c
72137+++ b/mm/hugetlb.c
72138@@ -2512,6 +2512,27 @@ static int unmap_ref_private(struct mm_struct *mm, struct vm_area_struct *vma,
72139 return 1;
72140 }
72141
72142+#ifdef CONFIG_PAX_SEGMEXEC
72143+static void pax_mirror_huge_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m)
72144+{
72145+ struct mm_struct *mm = vma->vm_mm;
72146+ struct vm_area_struct *vma_m;
72147+ unsigned long address_m;
72148+ pte_t *ptep_m;
72149+
72150+ vma_m = pax_find_mirror_vma(vma);
72151+ if (!vma_m)
72152+ return;
72153+
72154+ BUG_ON(address >= SEGMEXEC_TASK_SIZE);
72155+ address_m = address + SEGMEXEC_TASK_SIZE;
72156+ ptep_m = huge_pte_offset(mm, address_m & HPAGE_MASK);
72157+ get_page(page_m);
72158+ hugepage_add_anon_rmap(page_m, vma_m, address_m);
72159+ set_huge_pte_at(mm, address_m, ptep_m, make_huge_pte(vma_m, page_m, 0));
72160+}
72161+#endif
72162+
72163 /*
72164 * Hugetlb_cow() should be called with page lock of the original hugepage held.
72165 * Called with hugetlb_instantiation_mutex held and pte_page locked so we
72166@@ -2628,6 +2649,11 @@ retry_avoidcopy:
72167 make_huge_pte(vma, new_page, 1));
72168 page_remove_rmap(old_page);
72169 hugepage_add_new_anon_rmap(new_page, vma, address);
72170+
72171+#ifdef CONFIG_PAX_SEGMEXEC
72172+ pax_mirror_huge_pte(vma, address, new_page);
72173+#endif
72174+
72175 /* Make the old page be freed below */
72176 new_page = old_page;
72177 mmu_notifier_invalidate_range_end(mm,
72178@@ -2786,6 +2812,10 @@ retry:
72179 && (vma->vm_flags & VM_SHARED)));
72180 set_huge_pte_at(mm, address, ptep, new_pte);
72181
72182+#ifdef CONFIG_PAX_SEGMEXEC
72183+ pax_mirror_huge_pte(vma, address, page);
72184+#endif
72185+
72186 if ((flags & FAULT_FLAG_WRITE) && !(vma->vm_flags & VM_SHARED)) {
72187 /* Optimization, do the COW without a second fault */
72188 ret = hugetlb_cow(mm, vma, address, ptep, new_pte, page);
72189@@ -2815,6 +2845,10 @@ int hugetlb_fault(struct mm_struct *mm, struct vm_area_struct *vma,
72190 static DEFINE_MUTEX(hugetlb_instantiation_mutex);
72191 struct hstate *h = hstate_vma(vma);
72192
72193+#ifdef CONFIG_PAX_SEGMEXEC
72194+ struct vm_area_struct *vma_m;
72195+#endif
72196+
72197 address &= huge_page_mask(h);
72198
72199 ptep = huge_pte_offset(mm, address);
72200@@ -2828,6 +2862,26 @@ int hugetlb_fault(struct mm_struct *mm, struct vm_area_struct *vma,
72201 VM_FAULT_SET_HINDEX(hstate_index(h));
72202 }
72203
72204+#ifdef CONFIG_PAX_SEGMEXEC
72205+ vma_m = pax_find_mirror_vma(vma);
72206+ if (vma_m) {
72207+ unsigned long address_m;
72208+
72209+ if (vma->vm_start > vma_m->vm_start) {
72210+ address_m = address;
72211+ address -= SEGMEXEC_TASK_SIZE;
72212+ vma = vma_m;
72213+ h = hstate_vma(vma);
72214+ } else
72215+ address_m = address + SEGMEXEC_TASK_SIZE;
72216+
72217+ if (!huge_pte_alloc(mm, address_m, huge_page_size(h)))
72218+ return VM_FAULT_OOM;
72219+ address_m &= HPAGE_MASK;
72220+ unmap_hugepage_range(vma, address_m, address_m + HPAGE_SIZE, NULL);
72221+ }
72222+#endif
72223+
72224 ptep = huge_pte_alloc(mm, address, huge_page_size(h));
72225 if (!ptep)
72226 return VM_FAULT_OOM;
72227diff --git a/mm/internal.h b/mm/internal.h
72228index b8c91b3..93e95a3 100644
72229--- a/mm/internal.h
72230+++ b/mm/internal.h
72231@@ -95,6 +95,7 @@ extern void putback_lru_page(struct page *page);
72232 * in mm/page_alloc.c
72233 */
72234 extern void __free_pages_bootmem(struct page *page, unsigned int order);
72235+extern void free_compound_page(struct page *page);
72236 extern void prep_compound_page(struct page *page, unsigned long order);
72237 #ifdef CONFIG_MEMORY_FAILURE
72238 extern bool is_free_buddy_page(struct page *page);
72239diff --git a/mm/kmemleak.c b/mm/kmemleak.c
72240index 45eb621..6ccd8ea 100644
72241--- a/mm/kmemleak.c
72242+++ b/mm/kmemleak.c
72243@@ -363,7 +363,7 @@ static void print_unreferenced(struct seq_file *seq,
72244
72245 for (i = 0; i < object->trace_len; i++) {
72246 void *ptr = (void *)object->trace[i];
72247- seq_printf(seq, " [<%p>] %pS\n", ptr, ptr);
72248+ seq_printf(seq, " [<%p>] %pA\n", ptr, ptr);
72249 }
72250 }
72251
72252diff --git a/mm/maccess.c b/mm/maccess.c
72253index d53adf9..03a24bf 100644
72254--- a/mm/maccess.c
72255+++ b/mm/maccess.c
72256@@ -26,7 +26,7 @@ long __probe_kernel_read(void *dst, const void *src, size_t size)
72257 set_fs(KERNEL_DS);
72258 pagefault_disable();
72259 ret = __copy_from_user_inatomic(dst,
72260- (__force const void __user *)src, size);
72261+ (const void __force_user *)src, size);
72262 pagefault_enable();
72263 set_fs(old_fs);
72264
72265@@ -53,7 +53,7 @@ long __probe_kernel_write(void *dst, const void *src, size_t size)
72266
72267 set_fs(KERNEL_DS);
72268 pagefault_disable();
72269- ret = __copy_to_user_inatomic((__force void __user *)dst, src, size);
72270+ ret = __copy_to_user_inatomic((void __force_user *)dst, src, size);
72271 pagefault_enable();
72272 set_fs(old_fs);
72273
72274diff --git a/mm/madvise.c b/mm/madvise.c
72275index 14d260f..b2a80fd 100644
72276--- a/mm/madvise.c
72277+++ b/mm/madvise.c
72278@@ -48,6 +48,10 @@ static long madvise_behavior(struct vm_area_struct * vma,
72279 pgoff_t pgoff;
72280 unsigned long new_flags = vma->vm_flags;
72281
72282+#ifdef CONFIG_PAX_SEGMEXEC
72283+ struct vm_area_struct *vma_m;
72284+#endif
72285+
72286 switch (behavior) {
72287 case MADV_NORMAL:
72288 new_flags = new_flags & ~VM_RAND_READ & ~VM_SEQ_READ;
72289@@ -119,6 +123,13 @@ success:
72290 /*
72291 * vm_flags is protected by the mmap_sem held in write mode.
72292 */
72293+
72294+#ifdef CONFIG_PAX_SEGMEXEC
72295+ vma_m = pax_find_mirror_vma(vma);
72296+ if (vma_m)
72297+ vma_m->vm_flags = new_flags & ~(VM_WRITE | VM_MAYWRITE | VM_ACCOUNT);
72298+#endif
72299+
72300 vma->vm_flags = new_flags;
72301
72302 out:
72303@@ -177,6 +188,11 @@ static long madvise_dontneed(struct vm_area_struct * vma,
72304 struct vm_area_struct ** prev,
72305 unsigned long start, unsigned long end)
72306 {
72307+
72308+#ifdef CONFIG_PAX_SEGMEXEC
72309+ struct vm_area_struct *vma_m;
72310+#endif
72311+
72312 *prev = vma;
72313 if (vma->vm_flags & (VM_LOCKED|VM_HUGETLB|VM_PFNMAP))
72314 return -EINVAL;
72315@@ -189,6 +205,21 @@ static long madvise_dontneed(struct vm_area_struct * vma,
72316 zap_page_range(vma, start, end - start, &details);
72317 } else
72318 zap_page_range(vma, start, end - start, NULL);
72319+
72320+#ifdef CONFIG_PAX_SEGMEXEC
72321+ vma_m = pax_find_mirror_vma(vma);
72322+ if (vma_m) {
72323+ if (unlikely(vma->vm_flags & VM_NONLINEAR)) {
72324+ struct zap_details details = {
72325+ .nonlinear_vma = vma_m,
72326+ .last_index = ULONG_MAX,
72327+ };
72328+ zap_page_range(vma, start + SEGMEXEC_TASK_SIZE, end - start, &details);
72329+ } else
72330+ zap_page_range(vma, start + SEGMEXEC_TASK_SIZE, end - start, NULL);
72331+ }
72332+#endif
72333+
72334 return 0;
72335 }
72336
72337@@ -393,6 +424,16 @@ SYSCALL_DEFINE3(madvise, unsigned long, start, size_t, len_in, int, behavior)
72338 if (end < start)
72339 goto out;
72340
72341+#ifdef CONFIG_PAX_SEGMEXEC
72342+ if (current->mm->pax_flags & MF_PAX_SEGMEXEC) {
72343+ if (end > SEGMEXEC_TASK_SIZE)
72344+ goto out;
72345+ } else
72346+#endif
72347+
72348+ if (end > TASK_SIZE)
72349+ goto out;
72350+
72351 error = 0;
72352 if (end == start)
72353 goto out;
72354diff --git a/mm/memory-failure.c b/mm/memory-failure.c
72355index a6e2141..eaf5aad 100644
72356--- a/mm/memory-failure.c
72357+++ b/mm/memory-failure.c
72358@@ -61,7 +61,7 @@ int sysctl_memory_failure_early_kill __read_mostly = 0;
72359
72360 int sysctl_memory_failure_recovery __read_mostly = 1;
72361
72362-atomic_long_t mce_bad_pages __read_mostly = ATOMIC_LONG_INIT(0);
72363+atomic_long_unchecked_t mce_bad_pages __read_mostly = ATOMIC_LONG_INIT(0);
72364
72365 #if defined(CONFIG_HWPOISON_INJECT) || defined(CONFIG_HWPOISON_INJECT_MODULE)
72366
72367@@ -202,7 +202,7 @@ static int kill_proc(struct task_struct *t, unsigned long addr, int trapno,
72368 pfn, t->comm, t->pid);
72369 si.si_signo = SIGBUS;
72370 si.si_errno = 0;
72371- si.si_addr = (void *)addr;
72372+ si.si_addr = (void __user *)addr;
72373 #ifdef __ARCH_SI_TRAPNO
72374 si.si_trapno = trapno;
72375 #endif
72376@@ -1038,7 +1038,7 @@ int memory_failure(unsigned long pfn, int trapno, int flags)
72377 }
72378
72379 nr_pages = 1 << compound_trans_order(hpage);
72380- atomic_long_add(nr_pages, &mce_bad_pages);
72381+ atomic_long_add_unchecked(nr_pages, &mce_bad_pages);
72382
72383 /*
72384 * We need/can do nothing about count=0 pages.
72385@@ -1068,7 +1068,7 @@ int memory_failure(unsigned long pfn, int trapno, int flags)
72386 if (!PageHWPoison(hpage)
72387 || (hwpoison_filter(p) && TestClearPageHWPoison(p))
72388 || (p != hpage && TestSetPageHWPoison(hpage))) {
72389- atomic_long_sub(nr_pages, &mce_bad_pages);
72390+ atomic_long_sub_unchecked(nr_pages, &mce_bad_pages);
72391 return 0;
72392 }
72393 set_page_hwpoison_huge_page(hpage);
72394@@ -1126,7 +1126,7 @@ int memory_failure(unsigned long pfn, int trapno, int flags)
72395 }
72396 if (hwpoison_filter(p)) {
72397 if (TestClearPageHWPoison(p))
72398- atomic_long_sub(nr_pages, &mce_bad_pages);
72399+ atomic_long_sub_unchecked(nr_pages, &mce_bad_pages);
72400 unlock_page(hpage);
72401 put_page(hpage);
72402 return 0;
72403@@ -1321,7 +1321,7 @@ int unpoison_memory(unsigned long pfn)
72404 return 0;
72405 }
72406 if (TestClearPageHWPoison(p))
72407- atomic_long_sub(nr_pages, &mce_bad_pages);
72408+ atomic_long_sub_unchecked(nr_pages, &mce_bad_pages);
72409 pr_info("MCE: Software-unpoisoned free page %#lx\n", pfn);
72410 return 0;
72411 }
72412@@ -1335,7 +1335,7 @@ int unpoison_memory(unsigned long pfn)
72413 */
72414 if (TestClearPageHWPoison(page)) {
72415 pr_info("MCE: Software-unpoisoned page %#lx\n", pfn);
72416- atomic_long_sub(nr_pages, &mce_bad_pages);
72417+ atomic_long_sub_unchecked(nr_pages, &mce_bad_pages);
72418 freeit = 1;
72419 if (PageHuge(page))
72420 clear_page_hwpoison_huge_page(page);
72421@@ -1440,7 +1440,7 @@ static int soft_offline_huge_page(struct page *page, int flags)
72422 }
72423 done:
72424 if (!PageHWPoison(hpage))
72425- atomic_long_add(1 << compound_trans_order(hpage),
72426+ atomic_long_add_unchecked(1 << compound_trans_order(hpage),
72427 &mce_bad_pages);
72428 set_page_hwpoison_huge_page(hpage);
72429 dequeue_hwpoisoned_huge_page(hpage);
72430@@ -1572,7 +1572,7 @@ int soft_offline_page(struct page *page, int flags)
72431 return ret;
72432
72433 done:
72434- atomic_long_add(1, &mce_bad_pages);
72435+ atomic_long_add_unchecked(1, &mce_bad_pages);
72436 SetPageHWPoison(page);
72437 /* keep elevated page count for bad page */
72438 return ret;
72439diff --git a/mm/memory.c b/mm/memory.c
72440index 5736170..8e04800 100644
72441--- a/mm/memory.c
72442+++ b/mm/memory.c
72443@@ -426,6 +426,7 @@ static inline void free_pmd_range(struct mmu_gather *tlb, pud_t *pud,
72444 free_pte_range(tlb, pmd, addr);
72445 } while (pmd++, addr = next, addr != end);
72446
72447+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_PER_CPU_PGD)
72448 start &= PUD_MASK;
72449 if (start < floor)
72450 return;
72451@@ -440,6 +441,8 @@ static inline void free_pmd_range(struct mmu_gather *tlb, pud_t *pud,
72452 pmd = pmd_offset(pud, start);
72453 pud_clear(pud);
72454 pmd_free_tlb(tlb, pmd, start);
72455+#endif
72456+
72457 }
72458
72459 static inline void free_pud_range(struct mmu_gather *tlb, pgd_t *pgd,
72460@@ -459,6 +462,7 @@ static inline void free_pud_range(struct mmu_gather *tlb, pgd_t *pgd,
72461 free_pmd_range(tlb, pud, addr, next, floor, ceiling);
72462 } while (pud++, addr = next, addr != end);
72463
72464+#if !defined(CONFIG_X86_64) || !defined(CONFIG_PAX_PER_CPU_PGD)
72465 start &= PGDIR_MASK;
72466 if (start < floor)
72467 return;
72468@@ -473,6 +477,8 @@ static inline void free_pud_range(struct mmu_gather *tlb, pgd_t *pgd,
72469 pud = pud_offset(pgd, start);
72470 pgd_clear(pgd);
72471 pud_free_tlb(tlb, pud, start);
72472+#endif
72473+
72474 }
72475
72476 /*
72477@@ -1614,12 +1620,6 @@ no_page_table:
72478 return page;
72479 }
72480
72481-static inline int stack_guard_page(struct vm_area_struct *vma, unsigned long addr)
72482-{
72483- return stack_guard_page_start(vma, addr) ||
72484- stack_guard_page_end(vma, addr+PAGE_SIZE);
72485-}
72486-
72487 /**
72488 * __get_user_pages() - pin user pages in memory
72489 * @tsk: task_struct of target task
72490@@ -1692,10 +1692,10 @@ int __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
72491 (VM_MAYREAD | VM_MAYWRITE) : (VM_READ | VM_WRITE);
72492 i = 0;
72493
72494- do {
72495+ while (nr_pages) {
72496 struct vm_area_struct *vma;
72497
72498- vma = find_extend_vma(mm, start);
72499+ vma = find_vma(mm, start);
72500 if (!vma && in_gate_area(mm, start)) {
72501 unsigned long pg = start & PAGE_MASK;
72502 pgd_t *pgd;
72503@@ -1743,7 +1743,7 @@ int __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
72504 goto next_page;
72505 }
72506
72507- if (!vma ||
72508+ if (!vma || start < vma->vm_start ||
72509 (vma->vm_flags & (VM_IO | VM_PFNMAP)) ||
72510 !(vm_flags & vma->vm_flags))
72511 return i ? : -EFAULT;
72512@@ -1770,11 +1770,6 @@ int __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
72513 int ret;
72514 unsigned int fault_flags = 0;
72515
72516- /* For mlock, just skip the stack guard page. */
72517- if (foll_flags & FOLL_MLOCK) {
72518- if (stack_guard_page(vma, start))
72519- goto next_page;
72520- }
72521 if (foll_flags & FOLL_WRITE)
72522 fault_flags |= FAULT_FLAG_WRITE;
72523 if (nonblocking)
72524@@ -1848,7 +1843,7 @@ next_page:
72525 start += PAGE_SIZE;
72526 nr_pages--;
72527 } while (nr_pages && start < vma->vm_end);
72528- } while (nr_pages);
72529+ }
72530 return i;
72531 }
72532 EXPORT_SYMBOL(__get_user_pages);
72533@@ -2055,6 +2050,10 @@ static int insert_page(struct vm_area_struct *vma, unsigned long addr,
72534 page_add_file_rmap(page);
72535 set_pte_at(mm, addr, pte, mk_pte(page, prot));
72536
72537+#ifdef CONFIG_PAX_SEGMEXEC
72538+ pax_mirror_file_pte(vma, addr, page, ptl);
72539+#endif
72540+
72541 retval = 0;
72542 pte_unmap_unlock(pte, ptl);
72543 return retval;
72544@@ -2089,10 +2088,22 @@ out:
72545 int vm_insert_page(struct vm_area_struct *vma, unsigned long addr,
72546 struct page *page)
72547 {
72548+
72549+#ifdef CONFIG_PAX_SEGMEXEC
72550+ struct vm_area_struct *vma_m;
72551+#endif
72552+
72553 if (addr < vma->vm_start || addr >= vma->vm_end)
72554 return -EFAULT;
72555 if (!page_count(page))
72556 return -EINVAL;
72557+
72558+#ifdef CONFIG_PAX_SEGMEXEC
72559+ vma_m = pax_find_mirror_vma(vma);
72560+ if (vma_m)
72561+ vma_m->vm_flags |= VM_INSERTPAGE;
72562+#endif
72563+
72564 vma->vm_flags |= VM_INSERTPAGE;
72565 return insert_page(vma, addr, page, vma->vm_page_prot);
72566 }
72567@@ -2178,6 +2189,7 @@ int vm_insert_mixed(struct vm_area_struct *vma, unsigned long addr,
72568 unsigned long pfn)
72569 {
72570 BUG_ON(!(vma->vm_flags & VM_MIXEDMAP));
72571+ BUG_ON(vma->vm_mirror);
72572
72573 if (addr < vma->vm_start || addr >= vma->vm_end)
72574 return -EFAULT;
72575@@ -2385,7 +2397,9 @@ static int apply_to_pmd_range(struct mm_struct *mm, pud_t *pud,
72576
72577 BUG_ON(pud_huge(*pud));
72578
72579- pmd = pmd_alloc(mm, pud, addr);
72580+ pmd = (mm == &init_mm) ?
72581+ pmd_alloc_kernel(mm, pud, addr) :
72582+ pmd_alloc(mm, pud, addr);
72583 if (!pmd)
72584 return -ENOMEM;
72585 do {
72586@@ -2405,7 +2419,9 @@ static int apply_to_pud_range(struct mm_struct *mm, pgd_t *pgd,
72587 unsigned long next;
72588 int err;
72589
72590- pud = pud_alloc(mm, pgd, addr);
72591+ pud = (mm == &init_mm) ?
72592+ pud_alloc_kernel(mm, pgd, addr) :
72593+ pud_alloc(mm, pgd, addr);
72594 if (!pud)
72595 return -ENOMEM;
72596 do {
72597@@ -2493,6 +2509,186 @@ static inline void cow_user_page(struct page *dst, struct page *src, unsigned lo
72598 copy_user_highpage(dst, src, va, vma);
72599 }
72600
72601+#ifdef CONFIG_PAX_SEGMEXEC
72602+static void pax_unmap_mirror_pte(struct vm_area_struct *vma, unsigned long address, pmd_t *pmd)
72603+{
72604+ struct mm_struct *mm = vma->vm_mm;
72605+ spinlock_t *ptl;
72606+ pte_t *pte, entry;
72607+
72608+ pte = pte_offset_map_lock(mm, pmd, address, &ptl);
72609+ entry = *pte;
72610+ if (!pte_present(entry)) {
72611+ if (!pte_none(entry)) {
72612+ BUG_ON(pte_file(entry));
72613+ free_swap_and_cache(pte_to_swp_entry(entry));
72614+ pte_clear_not_present_full(mm, address, pte, 0);
72615+ }
72616+ } else {
72617+ struct page *page;
72618+
72619+ flush_cache_page(vma, address, pte_pfn(entry));
72620+ entry = ptep_clear_flush(vma, address, pte);
72621+ BUG_ON(pte_dirty(entry));
72622+ page = vm_normal_page(vma, address, entry);
72623+ if (page) {
72624+ update_hiwater_rss(mm);
72625+ if (PageAnon(page))
72626+ dec_mm_counter_fast(mm, MM_ANONPAGES);
72627+ else
72628+ dec_mm_counter_fast(mm, MM_FILEPAGES);
72629+ page_remove_rmap(page);
72630+ page_cache_release(page);
72631+ }
72632+ }
72633+ pte_unmap_unlock(pte, ptl);
72634+}
72635+
72636+/* PaX: if vma is mirrored, synchronize the mirror's PTE
72637+ *
72638+ * the ptl of the lower mapped page is held on entry and is not released on exit
72639+ * or inside to ensure atomic changes to the PTE states (swapout, mremap, munmap, etc)
72640+ */
72641+static void pax_mirror_anon_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m, spinlock_t *ptl)
72642+{
72643+ struct mm_struct *mm = vma->vm_mm;
72644+ unsigned long address_m;
72645+ spinlock_t *ptl_m;
72646+ struct vm_area_struct *vma_m;
72647+ pmd_t *pmd_m;
72648+ pte_t *pte_m, entry_m;
72649+
72650+ BUG_ON(!page_m || !PageAnon(page_m));
72651+
72652+ vma_m = pax_find_mirror_vma(vma);
72653+ if (!vma_m)
72654+ return;
72655+
72656+ BUG_ON(!PageLocked(page_m));
72657+ BUG_ON(address >= SEGMEXEC_TASK_SIZE);
72658+ address_m = address + SEGMEXEC_TASK_SIZE;
72659+ pmd_m = pmd_offset(pud_offset(pgd_offset(mm, address_m), address_m), address_m);
72660+ pte_m = pte_offset_map(pmd_m, address_m);
72661+ ptl_m = pte_lockptr(mm, pmd_m);
72662+ if (ptl != ptl_m) {
72663+ spin_lock_nested(ptl_m, SINGLE_DEPTH_NESTING);
72664+ if (!pte_none(*pte_m))
72665+ goto out;
72666+ }
72667+
72668+ entry_m = pfn_pte(page_to_pfn(page_m), vma_m->vm_page_prot);
72669+ page_cache_get(page_m);
72670+ page_add_anon_rmap(page_m, vma_m, address_m);
72671+ inc_mm_counter_fast(mm, MM_ANONPAGES);
72672+ set_pte_at(mm, address_m, pte_m, entry_m);
72673+ update_mmu_cache(vma_m, address_m, entry_m);
72674+out:
72675+ if (ptl != ptl_m)
72676+ spin_unlock(ptl_m);
72677+ pte_unmap(pte_m);
72678+ unlock_page(page_m);
72679+}
72680+
72681+void pax_mirror_file_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m, spinlock_t *ptl)
72682+{
72683+ struct mm_struct *mm = vma->vm_mm;
72684+ unsigned long address_m;
72685+ spinlock_t *ptl_m;
72686+ struct vm_area_struct *vma_m;
72687+ pmd_t *pmd_m;
72688+ pte_t *pte_m, entry_m;
72689+
72690+ BUG_ON(!page_m || PageAnon(page_m));
72691+
72692+ vma_m = pax_find_mirror_vma(vma);
72693+ if (!vma_m)
72694+ return;
72695+
72696+ BUG_ON(address >= SEGMEXEC_TASK_SIZE);
72697+ address_m = address + SEGMEXEC_TASK_SIZE;
72698+ pmd_m = pmd_offset(pud_offset(pgd_offset(mm, address_m), address_m), address_m);
72699+ pte_m = pte_offset_map(pmd_m, address_m);
72700+ ptl_m = pte_lockptr(mm, pmd_m);
72701+ if (ptl != ptl_m) {
72702+ spin_lock_nested(ptl_m, SINGLE_DEPTH_NESTING);
72703+ if (!pte_none(*pte_m))
72704+ goto out;
72705+ }
72706+
72707+ entry_m = pfn_pte(page_to_pfn(page_m), vma_m->vm_page_prot);
72708+ page_cache_get(page_m);
72709+ page_add_file_rmap(page_m);
72710+ inc_mm_counter_fast(mm, MM_FILEPAGES);
72711+ set_pte_at(mm, address_m, pte_m, entry_m);
72712+ update_mmu_cache(vma_m, address_m, entry_m);
72713+out:
72714+ if (ptl != ptl_m)
72715+ spin_unlock(ptl_m);
72716+ pte_unmap(pte_m);
72717+}
72718+
72719+static void pax_mirror_pfn_pte(struct vm_area_struct *vma, unsigned long address, unsigned long pfn_m, spinlock_t *ptl)
72720+{
72721+ struct mm_struct *mm = vma->vm_mm;
72722+ unsigned long address_m;
72723+ spinlock_t *ptl_m;
72724+ struct vm_area_struct *vma_m;
72725+ pmd_t *pmd_m;
72726+ pte_t *pte_m, entry_m;
72727+
72728+ vma_m = pax_find_mirror_vma(vma);
72729+ if (!vma_m)
72730+ return;
72731+
72732+ BUG_ON(address >= SEGMEXEC_TASK_SIZE);
72733+ address_m = address + SEGMEXEC_TASK_SIZE;
72734+ pmd_m = pmd_offset(pud_offset(pgd_offset(mm, address_m), address_m), address_m);
72735+ pte_m = pte_offset_map(pmd_m, address_m);
72736+ ptl_m = pte_lockptr(mm, pmd_m);
72737+ if (ptl != ptl_m) {
72738+ spin_lock_nested(ptl_m, SINGLE_DEPTH_NESTING);
72739+ if (!pte_none(*pte_m))
72740+ goto out;
72741+ }
72742+
72743+ entry_m = pfn_pte(pfn_m, vma_m->vm_page_prot);
72744+ set_pte_at(mm, address_m, pte_m, entry_m);
72745+out:
72746+ if (ptl != ptl_m)
72747+ spin_unlock(ptl_m);
72748+ pte_unmap(pte_m);
72749+}
72750+
72751+static void pax_mirror_pte(struct vm_area_struct *vma, unsigned long address, pte_t *pte, pmd_t *pmd, spinlock_t *ptl)
72752+{
72753+ struct page *page_m;
72754+ pte_t entry;
72755+
72756+ if (!(vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC))
72757+ goto out;
72758+
72759+ entry = *pte;
72760+ page_m = vm_normal_page(vma, address, entry);
72761+ if (!page_m)
72762+ pax_mirror_pfn_pte(vma, address, pte_pfn(entry), ptl);
72763+ else if (PageAnon(page_m)) {
72764+ if (pax_find_mirror_vma(vma)) {
72765+ pte_unmap_unlock(pte, ptl);
72766+ lock_page(page_m);
72767+ pte = pte_offset_map_lock(vma->vm_mm, pmd, address, &ptl);
72768+ if (pte_same(entry, *pte))
72769+ pax_mirror_anon_pte(vma, address, page_m, ptl);
72770+ else
72771+ unlock_page(page_m);
72772+ }
72773+ } else
72774+ pax_mirror_file_pte(vma, address, page_m, ptl);
72775+
72776+out:
72777+ pte_unmap_unlock(pte, ptl);
72778+}
72779+#endif
72780+
72781 /*
72782 * This routine handles present pages, when users try to write
72783 * to a shared page. It is done by copying the page to a new address
72784@@ -2703,6 +2899,12 @@ gotten:
72785 */
72786 page_table = pte_offset_map_lock(mm, pmd, address, &ptl);
72787 if (likely(pte_same(*page_table, orig_pte))) {
72788+
72789+#ifdef CONFIG_PAX_SEGMEXEC
72790+ if (pax_find_mirror_vma(vma))
72791+ BUG_ON(!trylock_page(new_page));
72792+#endif
72793+
72794 if (old_page) {
72795 if (!PageAnon(old_page)) {
72796 dec_mm_counter_fast(mm, MM_FILEPAGES);
72797@@ -2754,6 +2956,10 @@ gotten:
72798 page_remove_rmap(old_page);
72799 }
72800
72801+#ifdef CONFIG_PAX_SEGMEXEC
72802+ pax_mirror_anon_pte(vma, address, new_page, ptl);
72803+#endif
72804+
72805 /* Free the old page.. */
72806 new_page = old_page;
72807 ret |= VM_FAULT_WRITE;
72808@@ -3033,6 +3239,11 @@ static int do_swap_page(struct mm_struct *mm, struct vm_area_struct *vma,
72809 swap_free(entry);
72810 if (vm_swap_full() || (vma->vm_flags & VM_LOCKED) || PageMlocked(page))
72811 try_to_free_swap(page);
72812+
72813+#ifdef CONFIG_PAX_SEGMEXEC
72814+ if ((flags & FAULT_FLAG_WRITE) || !pax_find_mirror_vma(vma))
72815+#endif
72816+
72817 unlock_page(page);
72818 if (swapcache) {
72819 /*
72820@@ -3056,6 +3267,11 @@ static int do_swap_page(struct mm_struct *mm, struct vm_area_struct *vma,
72821
72822 /* No need to invalidate - it was non-present before */
72823 update_mmu_cache(vma, address, page_table);
72824+
72825+#ifdef CONFIG_PAX_SEGMEXEC
72826+ pax_mirror_anon_pte(vma, address, page, ptl);
72827+#endif
72828+
72829 unlock:
72830 pte_unmap_unlock(page_table, ptl);
72831 out:
72832@@ -3075,40 +3291,6 @@ out_release:
72833 }
72834
72835 /*
72836- * This is like a special single-page "expand_{down|up}wards()",
72837- * except we must first make sure that 'address{-|+}PAGE_SIZE'
72838- * doesn't hit another vma.
72839- */
72840-static inline int check_stack_guard_page(struct vm_area_struct *vma, unsigned long address)
72841-{
72842- address &= PAGE_MASK;
72843- if ((vma->vm_flags & VM_GROWSDOWN) && address == vma->vm_start) {
72844- struct vm_area_struct *prev = vma->vm_prev;
72845-
72846- /*
72847- * Is there a mapping abutting this one below?
72848- *
72849- * That's only ok if it's the same stack mapping
72850- * that has gotten split..
72851- */
72852- if (prev && prev->vm_end == address)
72853- return prev->vm_flags & VM_GROWSDOWN ? 0 : -ENOMEM;
72854-
72855- expand_downwards(vma, address - PAGE_SIZE);
72856- }
72857- if ((vma->vm_flags & VM_GROWSUP) && address + PAGE_SIZE == vma->vm_end) {
72858- struct vm_area_struct *next = vma->vm_next;
72859-
72860- /* As VM_GROWSDOWN but s/below/above/ */
72861- if (next && next->vm_start == address + PAGE_SIZE)
72862- return next->vm_flags & VM_GROWSUP ? 0 : -ENOMEM;
72863-
72864- expand_upwards(vma, address + PAGE_SIZE);
72865- }
72866- return 0;
72867-}
72868-
72869-/*
72870 * We enter with non-exclusive mmap_sem (to exclude vma changes,
72871 * but allow concurrent faults), and pte mapped but not yet locked.
72872 * We return with mmap_sem still held, but pte unmapped and unlocked.
72873@@ -3117,27 +3299,23 @@ static int do_anonymous_page(struct mm_struct *mm, struct vm_area_struct *vma,
72874 unsigned long address, pte_t *page_table, pmd_t *pmd,
72875 unsigned int flags)
72876 {
72877- struct page *page;
72878+ struct page *page = NULL;
72879 spinlock_t *ptl;
72880 pte_t entry;
72881
72882- pte_unmap(page_table);
72883-
72884- /* Check if we need to add a guard page to the stack */
72885- if (check_stack_guard_page(vma, address) < 0)
72886- return VM_FAULT_SIGBUS;
72887-
72888- /* Use the zero-page for reads */
72889 if (!(flags & FAULT_FLAG_WRITE)) {
72890 entry = pte_mkspecial(pfn_pte(my_zero_pfn(address),
72891 vma->vm_page_prot));
72892- page_table = pte_offset_map_lock(mm, pmd, address, &ptl);
72893+ ptl = pte_lockptr(mm, pmd);
72894+ spin_lock(ptl);
72895 if (!pte_none(*page_table))
72896 goto unlock;
72897 goto setpte;
72898 }
72899
72900 /* Allocate our own private page. */
72901+ pte_unmap(page_table);
72902+
72903 if (unlikely(anon_vma_prepare(vma)))
72904 goto oom;
72905 page = alloc_zeroed_user_highpage_movable(vma, address);
72906@@ -3156,6 +3334,11 @@ static int do_anonymous_page(struct mm_struct *mm, struct vm_area_struct *vma,
72907 if (!pte_none(*page_table))
72908 goto release;
72909
72910+#ifdef CONFIG_PAX_SEGMEXEC
72911+ if (pax_find_mirror_vma(vma))
72912+ BUG_ON(!trylock_page(page));
72913+#endif
72914+
72915 inc_mm_counter_fast(mm, MM_ANONPAGES);
72916 page_add_new_anon_rmap(page, vma, address);
72917 setpte:
72918@@ -3163,6 +3346,12 @@ setpte:
72919
72920 /* No need to invalidate - it was non-present before */
72921 update_mmu_cache(vma, address, page_table);
72922+
72923+#ifdef CONFIG_PAX_SEGMEXEC
72924+ if (page)
72925+ pax_mirror_anon_pte(vma, address, page, ptl);
72926+#endif
72927+
72928 unlock:
72929 pte_unmap_unlock(page_table, ptl);
72930 return 0;
72931@@ -3306,6 +3495,12 @@ static int __do_fault(struct mm_struct *mm, struct vm_area_struct *vma,
72932 */
72933 /* Only go through if we didn't race with anybody else... */
72934 if (likely(pte_same(*page_table, orig_pte))) {
72935+
72936+#ifdef CONFIG_PAX_SEGMEXEC
72937+ if (anon && pax_find_mirror_vma(vma))
72938+ BUG_ON(!trylock_page(page));
72939+#endif
72940+
72941 flush_icache_page(vma, page);
72942 entry = mk_pte(page, vma->vm_page_prot);
72943 if (flags & FAULT_FLAG_WRITE)
72944@@ -3325,6 +3520,14 @@ static int __do_fault(struct mm_struct *mm, struct vm_area_struct *vma,
72945
72946 /* no need to invalidate: a not-present page won't be cached */
72947 update_mmu_cache(vma, address, page_table);
72948+
72949+#ifdef CONFIG_PAX_SEGMEXEC
72950+ if (anon)
72951+ pax_mirror_anon_pte(vma, address, page, ptl);
72952+ else
72953+ pax_mirror_file_pte(vma, address, page, ptl);
72954+#endif
72955+
72956 } else {
72957 if (cow_page)
72958 mem_cgroup_uncharge_page(cow_page);
72959@@ -3479,6 +3682,12 @@ int handle_pte_fault(struct mm_struct *mm,
72960 if (flags & FAULT_FLAG_WRITE)
72961 flush_tlb_fix_spurious_fault(vma, address);
72962 }
72963+
72964+#ifdef CONFIG_PAX_SEGMEXEC
72965+ pax_mirror_pte(vma, address, pte, pmd, ptl);
72966+ return 0;
72967+#endif
72968+
72969 unlock:
72970 pte_unmap_unlock(pte, ptl);
72971 return 0;
72972@@ -3495,6 +3704,10 @@ int handle_mm_fault(struct mm_struct *mm, struct vm_area_struct *vma,
72973 pmd_t *pmd;
72974 pte_t *pte;
72975
72976+#ifdef CONFIG_PAX_SEGMEXEC
72977+ struct vm_area_struct *vma_m;
72978+#endif
72979+
72980 __set_current_state(TASK_RUNNING);
72981
72982 count_vm_event(PGFAULT);
72983@@ -3506,6 +3719,34 @@ int handle_mm_fault(struct mm_struct *mm, struct vm_area_struct *vma,
72984 if (unlikely(is_vm_hugetlb_page(vma)))
72985 return hugetlb_fault(mm, vma, address, flags);
72986
72987+#ifdef CONFIG_PAX_SEGMEXEC
72988+ vma_m = pax_find_mirror_vma(vma);
72989+ if (vma_m) {
72990+ unsigned long address_m;
72991+ pgd_t *pgd_m;
72992+ pud_t *pud_m;
72993+ pmd_t *pmd_m;
72994+
72995+ if (vma->vm_start > vma_m->vm_start) {
72996+ address_m = address;
72997+ address -= SEGMEXEC_TASK_SIZE;
72998+ vma = vma_m;
72999+ } else
73000+ address_m = address + SEGMEXEC_TASK_SIZE;
73001+
73002+ pgd_m = pgd_offset(mm, address_m);
73003+ pud_m = pud_alloc(mm, pgd_m, address_m);
73004+ if (!pud_m)
73005+ return VM_FAULT_OOM;
73006+ pmd_m = pmd_alloc(mm, pud_m, address_m);
73007+ if (!pmd_m)
73008+ return VM_FAULT_OOM;
73009+ if (!pmd_present(*pmd_m) && __pte_alloc(mm, vma_m, pmd_m, address_m))
73010+ return VM_FAULT_OOM;
73011+ pax_unmap_mirror_pte(vma_m, address_m, pmd_m);
73012+ }
73013+#endif
73014+
73015 retry:
73016 pgd = pgd_offset(mm, address);
73017 pud = pud_alloc(mm, pgd, address);
73018@@ -3547,7 +3788,7 @@ retry:
73019 * run pte_offset_map on the pmd, if an huge pmd could
73020 * materialize from under us from a different thread.
73021 */
73022- if (unlikely(pmd_none(*pmd)) && __pte_alloc(mm, vma, pmd, address))
73023+ if (unlikely(pmd_none(*pmd) && __pte_alloc(mm, vma, pmd, address)))
73024 return VM_FAULT_OOM;
73025 /* if an huge pmd materialized from under us just retry later */
73026 if (unlikely(pmd_trans_huge(*pmd)))
73027@@ -3584,6 +3825,23 @@ int __pud_alloc(struct mm_struct *mm, pgd_t *pgd, unsigned long address)
73028 spin_unlock(&mm->page_table_lock);
73029 return 0;
73030 }
73031+
73032+int __pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd, unsigned long address)
73033+{
73034+ pud_t *new = pud_alloc_one(mm, address);
73035+ if (!new)
73036+ return -ENOMEM;
73037+
73038+ smp_wmb(); /* See comment in __pte_alloc */
73039+
73040+ spin_lock(&mm->page_table_lock);
73041+ if (pgd_present(*pgd)) /* Another has populated it */
73042+ pud_free(mm, new);
73043+ else
73044+ pgd_populate_kernel(mm, pgd, new);
73045+ spin_unlock(&mm->page_table_lock);
73046+ return 0;
73047+}
73048 #endif /* __PAGETABLE_PUD_FOLDED */
73049
73050 #ifndef __PAGETABLE_PMD_FOLDED
73051@@ -3614,6 +3872,30 @@ int __pmd_alloc(struct mm_struct *mm, pud_t *pud, unsigned long address)
73052 spin_unlock(&mm->page_table_lock);
73053 return 0;
73054 }
73055+
73056+int __pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud, unsigned long address)
73057+{
73058+ pmd_t *new = pmd_alloc_one(mm, address);
73059+ if (!new)
73060+ return -ENOMEM;
73061+
73062+ smp_wmb(); /* See comment in __pte_alloc */
73063+
73064+ spin_lock(&mm->page_table_lock);
73065+#ifndef __ARCH_HAS_4LEVEL_HACK
73066+ if (pud_present(*pud)) /* Another has populated it */
73067+ pmd_free(mm, new);
73068+ else
73069+ pud_populate_kernel(mm, pud, new);
73070+#else
73071+ if (pgd_present(*pud)) /* Another has populated it */
73072+ pmd_free(mm, new);
73073+ else
73074+ pgd_populate_kernel(mm, pud, new);
73075+#endif /* __ARCH_HAS_4LEVEL_HACK */
73076+ spin_unlock(&mm->page_table_lock);
73077+ return 0;
73078+}
73079 #endif /* __PAGETABLE_PMD_FOLDED */
73080
73081 int make_pages_present(unsigned long addr, unsigned long end)
73082@@ -3651,7 +3933,7 @@ static int __init gate_vma_init(void)
73083 gate_vma.vm_start = FIXADDR_USER_START;
73084 gate_vma.vm_end = FIXADDR_USER_END;
73085 gate_vma.vm_flags = VM_READ | VM_MAYREAD | VM_EXEC | VM_MAYEXEC;
73086- gate_vma.vm_page_prot = __P101;
73087+ gate_vma.vm_page_prot = vm_get_page_prot(gate_vma.vm_flags);
73088
73089 return 0;
73090 }
73091diff --git a/mm/mempolicy.c b/mm/mempolicy.c
73092index 3d64b36..c6ab69c 100644
73093--- a/mm/mempolicy.c
73094+++ b/mm/mempolicy.c
73095@@ -655,6 +655,10 @@ static int mbind_range(struct mm_struct *mm, unsigned long start,
73096 unsigned long vmstart;
73097 unsigned long vmend;
73098
73099+#ifdef CONFIG_PAX_SEGMEXEC
73100+ struct vm_area_struct *vma_m;
73101+#endif
73102+
73103 vma = find_vma(mm, start);
73104 if (!vma || vma->vm_start > start)
73105 return -EFAULT;
73106@@ -691,9 +695,20 @@ static int mbind_range(struct mm_struct *mm, unsigned long start,
73107 if (err)
73108 goto out;
73109 }
73110+
73111 err = vma_replace_policy(vma, new_pol);
73112 if (err)
73113 goto out;
73114+
73115+#ifdef CONFIG_PAX_SEGMEXEC
73116+ vma_m = pax_find_mirror_vma(vma);
73117+ if (vma_m) {
73118+ err = vma_replace_policy(vma_m, new_pol);
73119+ if (err)
73120+ goto out;
73121+ }
73122+#endif
73123+
73124 }
73125
73126 out:
73127@@ -1147,6 +1162,17 @@ static long do_mbind(unsigned long start, unsigned long len,
73128
73129 if (end < start)
73130 return -EINVAL;
73131+
73132+#ifdef CONFIG_PAX_SEGMEXEC
73133+ if (mm->pax_flags & MF_PAX_SEGMEXEC) {
73134+ if (end > SEGMEXEC_TASK_SIZE)
73135+ return -EINVAL;
73136+ } else
73137+#endif
73138+
73139+ if (end > TASK_SIZE)
73140+ return -EINVAL;
73141+
73142 if (end == start)
73143 return 0;
73144
73145@@ -1370,8 +1396,7 @@ SYSCALL_DEFINE4(migrate_pages, pid_t, pid, unsigned long, maxnode,
73146 */
73147 tcred = __task_cred(task);
73148 if (!uid_eq(cred->euid, tcred->suid) && !uid_eq(cred->euid, tcred->uid) &&
73149- !uid_eq(cred->uid, tcred->suid) && !uid_eq(cred->uid, tcred->uid) &&
73150- !capable(CAP_SYS_NICE)) {
73151+ !uid_eq(cred->uid, tcred->suid) && !capable(CAP_SYS_NICE)) {
73152 rcu_read_unlock();
73153 err = -EPERM;
73154 goto out_put;
73155@@ -1402,6 +1427,15 @@ SYSCALL_DEFINE4(migrate_pages, pid_t, pid, unsigned long, maxnode,
73156 goto out;
73157 }
73158
73159+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
73160+ if (mm != current->mm &&
73161+ (mm->pax_flags & MF_PAX_RANDMMAP || mm->pax_flags & MF_PAX_SEGMEXEC)) {
73162+ mmput(mm);
73163+ err = -EPERM;
73164+ goto out;
73165+ }
73166+#endif
73167+
73168 err = do_migrate_pages(mm, old, new,
73169 capable(CAP_SYS_NICE) ? MPOL_MF_MOVE_ALL : MPOL_MF_MOVE);
73170
73171diff --git a/mm/migrate.c b/mm/migrate.c
73172index 77ed2d7..317d528 100644
73173--- a/mm/migrate.c
73174+++ b/mm/migrate.c
73175@@ -1350,8 +1350,7 @@ SYSCALL_DEFINE6(move_pages, pid_t, pid, unsigned long, nr_pages,
73176 */
73177 tcred = __task_cred(task);
73178 if (!uid_eq(cred->euid, tcred->suid) && !uid_eq(cred->euid, tcred->uid) &&
73179- !uid_eq(cred->uid, tcred->suid) && !uid_eq(cred->uid, tcred->uid) &&
73180- !capable(CAP_SYS_NICE)) {
73181+ !uid_eq(cred->uid, tcred->suid) && !capable(CAP_SYS_NICE)) {
73182 rcu_read_unlock();
73183 err = -EPERM;
73184 goto out;
73185diff --git a/mm/mlock.c b/mm/mlock.c
73186index ef726e8..cd7f1ec 100644
73187--- a/mm/mlock.c
73188+++ b/mm/mlock.c
73189@@ -13,6 +13,7 @@
73190 #include <linux/pagemap.h>
73191 #include <linux/mempolicy.h>
73192 #include <linux/syscalls.h>
73193+#include <linux/security.h>
73194 #include <linux/sched.h>
73195 #include <linux/export.h>
73196 #include <linux/rmap.h>
73197@@ -376,7 +377,7 @@ static int do_mlock(unsigned long start, size_t len, int on)
73198 {
73199 unsigned long nstart, end, tmp;
73200 struct vm_area_struct * vma, * prev;
73201- int error;
73202+ int error = 0;
73203
73204 VM_BUG_ON(start & ~PAGE_MASK);
73205 VM_BUG_ON(len != PAGE_ALIGN(len));
73206@@ -385,6 +386,9 @@ static int do_mlock(unsigned long start, size_t len, int on)
73207 return -EINVAL;
73208 if (end == start)
73209 return 0;
73210+ if (end > TASK_SIZE)
73211+ return -EINVAL;
73212+
73213 vma = find_vma(current->mm, start);
73214 if (!vma || vma->vm_start > start)
73215 return -ENOMEM;
73216@@ -396,6 +400,11 @@ static int do_mlock(unsigned long start, size_t len, int on)
73217 for (nstart = start ; ; ) {
73218 vm_flags_t newflags;
73219
73220+#ifdef CONFIG_PAX_SEGMEXEC
73221+ if ((current->mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_start >= SEGMEXEC_TASK_SIZE))
73222+ break;
73223+#endif
73224+
73225 /* Here we know that vma->vm_start <= nstart < vma->vm_end. */
73226
73227 newflags = vma->vm_flags | VM_LOCKED;
73228@@ -501,6 +510,7 @@ SYSCALL_DEFINE2(mlock, unsigned long, start, size_t, len)
73229 lock_limit >>= PAGE_SHIFT;
73230
73231 /* check against resource limits */
73232+ gr_learn_resource(current, RLIMIT_MEMLOCK, (current->mm->locked_vm << PAGE_SHIFT) + len, 1);
73233 if ((locked <= lock_limit) || capable(CAP_IPC_LOCK))
73234 error = do_mlock(start, len, 1);
73235 up_write(&current->mm->mmap_sem);
73236@@ -524,17 +534,23 @@ SYSCALL_DEFINE2(munlock, unsigned long, start, size_t, len)
73237 static int do_mlockall(int flags)
73238 {
73239 struct vm_area_struct * vma, * prev = NULL;
73240- unsigned int def_flags = 0;
73241
73242 if (flags & MCL_FUTURE)
73243- def_flags = VM_LOCKED;
73244- current->mm->def_flags = def_flags;
73245+ current->mm->def_flags |= VM_LOCKED;
73246+ else
73247+ current->mm->def_flags &= ~VM_LOCKED;
73248 if (flags == MCL_FUTURE)
73249 goto out;
73250
73251 for (vma = current->mm->mmap; vma ; vma = prev->vm_next) {
73252 vm_flags_t newflags;
73253
73254+#ifdef CONFIG_PAX_SEGMEXEC
73255+ if ((current->mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_start >= SEGMEXEC_TASK_SIZE))
73256+ break;
73257+#endif
73258+
73259+ BUG_ON(vma->vm_end > TASK_SIZE);
73260 newflags = vma->vm_flags | VM_LOCKED;
73261 if (!(flags & MCL_CURRENT))
73262 newflags &= ~VM_LOCKED;
73263@@ -567,6 +583,7 @@ SYSCALL_DEFINE1(mlockall, int, flags)
73264 lock_limit >>= PAGE_SHIFT;
73265
73266 ret = -ENOMEM;
73267+ gr_learn_resource(current, RLIMIT_MEMLOCK, current->mm->total_vm << PAGE_SHIFT, 1);
73268 if (!(flags & MCL_CURRENT) || (current->mm->total_vm <= lock_limit) ||
73269 capable(CAP_IPC_LOCK))
73270 ret = do_mlockall(flags);
73271diff --git a/mm/mmap.c b/mm/mmap.c
73272index ae18a48..86cf99e 100644
73273--- a/mm/mmap.c
73274+++ b/mm/mmap.c
73275@@ -47,6 +47,16 @@
73276 #define arch_rebalance_pgtables(addr, len) (addr)
73277 #endif
73278
73279+static inline void verify_mm_writelocked(struct mm_struct *mm)
73280+{
73281+#if defined(CONFIG_DEBUG_VM) || defined(CONFIG_PAX)
73282+ if (unlikely(down_read_trylock(&mm->mmap_sem))) {
73283+ up_read(&mm->mmap_sem);
73284+ BUG();
73285+ }
73286+#endif
73287+}
73288+
73289 static void unmap_region(struct mm_struct *mm,
73290 struct vm_area_struct *vma, struct vm_area_struct *prev,
73291 unsigned long start, unsigned long end);
73292@@ -72,22 +82,32 @@ static void unmap_region(struct mm_struct *mm,
73293 * x: (no) no x: (no) yes x: (no) yes x: (yes) yes
73294 *
73295 */
73296-pgprot_t protection_map[16] = {
73297+pgprot_t protection_map[16] __read_only = {
73298 __P000, __P001, __P010, __P011, __P100, __P101, __P110, __P111,
73299 __S000, __S001, __S010, __S011, __S100, __S101, __S110, __S111
73300 };
73301
73302-pgprot_t vm_get_page_prot(unsigned long vm_flags)
73303+pgprot_t vm_get_page_prot(vm_flags_t vm_flags)
73304 {
73305- return __pgprot(pgprot_val(protection_map[vm_flags &
73306+ pgprot_t prot = __pgprot(pgprot_val(protection_map[vm_flags &
73307 (VM_READ|VM_WRITE|VM_EXEC|VM_SHARED)]) |
73308 pgprot_val(arch_vm_get_page_prot(vm_flags)));
73309+
73310+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
73311+ if (!(__supported_pte_mask & _PAGE_NX) &&
73312+ (vm_flags & (VM_PAGEEXEC | VM_EXEC)) == VM_PAGEEXEC &&
73313+ (vm_flags & (VM_READ | VM_WRITE)))
73314+ prot = __pgprot(pte_val(pte_exprotect(__pte(pgprot_val(prot)))));
73315+#endif
73316+
73317+ return prot;
73318 }
73319 EXPORT_SYMBOL(vm_get_page_prot);
73320
73321 int sysctl_overcommit_memory __read_mostly = OVERCOMMIT_GUESS; /* heuristic overcommit */
73322 int sysctl_overcommit_ratio __read_mostly = 50; /* default is 50% */
73323 int sysctl_max_map_count __read_mostly = DEFAULT_MAX_MAP_COUNT;
73324+unsigned long sysctl_heap_stack_gap __read_mostly = 64*1024;
73325 /*
73326 * Make sure vm_committed_as in one cacheline and not cacheline shared with
73327 * other variables. It can be updated by several CPUs frequently.
73328@@ -229,6 +249,7 @@ static struct vm_area_struct *remove_vma(struct vm_area_struct *vma)
73329 struct vm_area_struct *next = vma->vm_next;
73330
73331 might_sleep();
73332+ BUG_ON(vma->vm_mirror);
73333 if (vma->vm_ops && vma->vm_ops->close)
73334 vma->vm_ops->close(vma);
73335 if (vma->vm_file) {
73336@@ -275,6 +296,7 @@ SYSCALL_DEFINE1(brk, unsigned long, brk)
73337 * not page aligned -Ram Gupta
73338 */
73339 rlim = rlimit(RLIMIT_DATA);
73340+ gr_learn_resource(current, RLIMIT_DATA, (brk - mm->start_brk) + (mm->end_data - mm->start_data), 1);
73341 if (rlim < RLIM_INFINITY && (brk - mm->start_brk) +
73342 (mm->end_data - mm->start_data) > rlim)
73343 goto out;
73344@@ -708,6 +730,12 @@ static int
73345 can_vma_merge_before(struct vm_area_struct *vma, unsigned long vm_flags,
73346 struct anon_vma *anon_vma, struct file *file, pgoff_t vm_pgoff)
73347 {
73348+
73349+#ifdef CONFIG_PAX_SEGMEXEC
73350+ if ((vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) && vma->vm_start == SEGMEXEC_TASK_SIZE)
73351+ return 0;
73352+#endif
73353+
73354 if (is_mergeable_vma(vma, file, vm_flags) &&
73355 is_mergeable_anon_vma(anon_vma, vma->anon_vma, vma)) {
73356 if (vma->vm_pgoff == vm_pgoff)
73357@@ -727,6 +755,12 @@ static int
73358 can_vma_merge_after(struct vm_area_struct *vma, unsigned long vm_flags,
73359 struct anon_vma *anon_vma, struct file *file, pgoff_t vm_pgoff)
73360 {
73361+
73362+#ifdef CONFIG_PAX_SEGMEXEC
73363+ if ((vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) && vma->vm_end == SEGMEXEC_TASK_SIZE)
73364+ return 0;
73365+#endif
73366+
73367 if (is_mergeable_vma(vma, file, vm_flags) &&
73368 is_mergeable_anon_vma(anon_vma, vma->anon_vma, vma)) {
73369 pgoff_t vm_pglen;
73370@@ -769,13 +803,20 @@ can_vma_merge_after(struct vm_area_struct *vma, unsigned long vm_flags,
73371 struct vm_area_struct *vma_merge(struct mm_struct *mm,
73372 struct vm_area_struct *prev, unsigned long addr,
73373 unsigned long end, unsigned long vm_flags,
73374- struct anon_vma *anon_vma, struct file *file,
73375+ struct anon_vma *anon_vma, struct file *file,
73376 pgoff_t pgoff, struct mempolicy *policy)
73377 {
73378 pgoff_t pglen = (end - addr) >> PAGE_SHIFT;
73379 struct vm_area_struct *area, *next;
73380 int err;
73381
73382+#ifdef CONFIG_PAX_SEGMEXEC
73383+ unsigned long addr_m = addr + SEGMEXEC_TASK_SIZE, end_m = end + SEGMEXEC_TASK_SIZE;
73384+ struct vm_area_struct *area_m = NULL, *next_m = NULL, *prev_m = NULL;
73385+
73386+ BUG_ON((mm->pax_flags & MF_PAX_SEGMEXEC) && SEGMEXEC_TASK_SIZE < end);
73387+#endif
73388+
73389 /*
73390 * We later require that vma->vm_flags == vm_flags,
73391 * so this tests vma->vm_flags & VM_SPECIAL, too.
73392@@ -791,6 +832,15 @@ struct vm_area_struct *vma_merge(struct mm_struct *mm,
73393 if (next && next->vm_end == end) /* cases 6, 7, 8 */
73394 next = next->vm_next;
73395
73396+#ifdef CONFIG_PAX_SEGMEXEC
73397+ if (prev)
73398+ prev_m = pax_find_mirror_vma(prev);
73399+ if (area)
73400+ area_m = pax_find_mirror_vma(area);
73401+ if (next)
73402+ next_m = pax_find_mirror_vma(next);
73403+#endif
73404+
73405 /*
73406 * Can it merge with the predecessor?
73407 */
73408@@ -810,9 +860,24 @@ struct vm_area_struct *vma_merge(struct mm_struct *mm,
73409 /* cases 1, 6 */
73410 err = vma_adjust(prev, prev->vm_start,
73411 next->vm_end, prev->vm_pgoff, NULL);
73412- } else /* cases 2, 5, 7 */
73413+
73414+#ifdef CONFIG_PAX_SEGMEXEC
73415+ if (!err && prev_m)
73416+ err = vma_adjust(prev_m, prev_m->vm_start,
73417+ next_m->vm_end, prev_m->vm_pgoff, NULL);
73418+#endif
73419+
73420+ } else { /* cases 2, 5, 7 */
73421 err = vma_adjust(prev, prev->vm_start,
73422 end, prev->vm_pgoff, NULL);
73423+
73424+#ifdef CONFIG_PAX_SEGMEXEC
73425+ if (!err && prev_m)
73426+ err = vma_adjust(prev_m, prev_m->vm_start,
73427+ end_m, prev_m->vm_pgoff, NULL);
73428+#endif
73429+
73430+ }
73431 if (err)
73432 return NULL;
73433 khugepaged_enter_vma_merge(prev);
73434@@ -826,12 +891,27 @@ struct vm_area_struct *vma_merge(struct mm_struct *mm,
73435 mpol_equal(policy, vma_policy(next)) &&
73436 can_vma_merge_before(next, vm_flags,
73437 anon_vma, file, pgoff+pglen)) {
73438- if (prev && addr < prev->vm_end) /* case 4 */
73439+ if (prev && addr < prev->vm_end) { /* case 4 */
73440 err = vma_adjust(prev, prev->vm_start,
73441 addr, prev->vm_pgoff, NULL);
73442- else /* cases 3, 8 */
73443+
73444+#ifdef CONFIG_PAX_SEGMEXEC
73445+ if (!err && prev_m)
73446+ err = vma_adjust(prev_m, prev_m->vm_start,
73447+ addr_m, prev_m->vm_pgoff, NULL);
73448+#endif
73449+
73450+ } else { /* cases 3, 8 */
73451 err = vma_adjust(area, addr, next->vm_end,
73452 next->vm_pgoff - pglen, NULL);
73453+
73454+#ifdef CONFIG_PAX_SEGMEXEC
73455+ if (!err && area_m)
73456+ err = vma_adjust(area_m, addr_m, next_m->vm_end,
73457+ next_m->vm_pgoff - pglen, NULL);
73458+#endif
73459+
73460+ }
73461 if (err)
73462 return NULL;
73463 khugepaged_enter_vma_merge(area);
73464@@ -940,16 +1020,13 @@ none:
73465 void vm_stat_account(struct mm_struct *mm, unsigned long flags,
73466 struct file *file, long pages)
73467 {
73468- const unsigned long stack_flags
73469- = VM_STACK_FLAGS & (VM_GROWSUP|VM_GROWSDOWN);
73470-
73471 mm->total_vm += pages;
73472
73473 if (file) {
73474 mm->shared_vm += pages;
73475 if ((flags & (VM_EXEC|VM_WRITE)) == VM_EXEC)
73476 mm->exec_vm += pages;
73477- } else if (flags & stack_flags)
73478+ } else if (flags & (VM_GROWSUP|VM_GROWSDOWN))
73479 mm->stack_vm += pages;
73480 if (flags & (VM_RESERVED|VM_IO))
73481 mm->reserved_vm += pages;
73482@@ -987,7 +1064,7 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
73483 * (the exception is when the underlying filesystem is noexec
73484 * mounted, in which case we dont add PROT_EXEC.)
73485 */
73486- if ((prot & PROT_READ) && (current->personality & READ_IMPLIES_EXEC))
73487+ if ((prot & (PROT_READ | PROT_WRITE)) && (current->personality & READ_IMPLIES_EXEC))
73488 if (!(file && (file->f_path.mnt->mnt_flags & MNT_NOEXEC)))
73489 prot |= PROT_EXEC;
73490
73491@@ -1013,7 +1090,7 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
73492 /* Obtain the address to map to. we verify (or select) it and ensure
73493 * that it represents a valid section of the address space.
73494 */
73495- addr = get_unmapped_area(file, addr, len, pgoff, flags);
73496+ addr = get_unmapped_area(file, addr, len, pgoff, flags | ((prot & PROT_EXEC) ? MAP_EXECUTABLE : 0));
73497 if (addr & ~PAGE_MASK)
73498 return addr;
73499
73500@@ -1024,6 +1101,36 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
73501 vm_flags = calc_vm_prot_bits(prot) | calc_vm_flag_bits(flags) |
73502 mm->def_flags | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC;
73503
73504+#ifdef CONFIG_PAX_MPROTECT
73505+ if (mm->pax_flags & MF_PAX_MPROTECT) {
73506+#ifndef CONFIG_PAX_MPROTECT_COMPAT
73507+ if ((vm_flags & (VM_WRITE | VM_EXEC)) == (VM_WRITE | VM_EXEC)) {
73508+ gr_log_rwxmmap(file);
73509+
73510+#ifdef CONFIG_PAX_EMUPLT
73511+ vm_flags &= ~VM_EXEC;
73512+#else
73513+ return -EPERM;
73514+#endif
73515+
73516+ }
73517+
73518+ if (!(vm_flags & VM_EXEC))
73519+ vm_flags &= ~VM_MAYEXEC;
73520+#else
73521+ if ((vm_flags & (VM_WRITE | VM_EXEC)) != VM_EXEC)
73522+ vm_flags &= ~(VM_EXEC | VM_MAYEXEC);
73523+#endif
73524+ else
73525+ vm_flags &= ~VM_MAYWRITE;
73526+ }
73527+#endif
73528+
73529+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
73530+ if ((mm->pax_flags & MF_PAX_PAGEEXEC) && file)
73531+ vm_flags &= ~VM_PAGEEXEC;
73532+#endif
73533+
73534 if (flags & MAP_LOCKED)
73535 if (!can_do_mlock())
73536 return -EPERM;
73537@@ -1035,6 +1142,7 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
73538 locked += mm->locked_vm;
73539 lock_limit = rlimit(RLIMIT_MEMLOCK);
73540 lock_limit >>= PAGE_SHIFT;
73541+ gr_learn_resource(current, RLIMIT_MEMLOCK, locked << PAGE_SHIFT, 1);
73542 if (locked > lock_limit && !capable(CAP_IPC_LOCK))
73543 return -EAGAIN;
73544 }
73545@@ -1101,6 +1209,9 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
73546 }
73547 }
73548
73549+ if (!gr_acl_handle_mmap(file, prot))
73550+ return -EACCES;
73551+
73552 return mmap_region(file, addr, len, flags, vm_flags, pgoff);
73553 }
73554
73555@@ -1177,7 +1288,7 @@ int vma_wants_writenotify(struct vm_area_struct *vma)
73556 vm_flags_t vm_flags = vma->vm_flags;
73557
73558 /* If it was private or non-writable, the write bit is already clear */
73559- if ((vm_flags & (VM_WRITE|VM_SHARED)) != ((VM_WRITE|VM_SHARED)))
73560+ if ((vm_flags & (VM_WRITE|VM_SHARED)) != (VM_WRITE|VM_SHARED))
73561 return 0;
73562
73563 /* The backer wishes to know when pages are first written to? */
73564@@ -1226,14 +1337,24 @@ unsigned long mmap_region(struct file *file, unsigned long addr,
73565 unsigned long charged = 0;
73566 struct inode *inode = file ? file->f_path.dentry->d_inode : NULL;
73567
73568+#ifdef CONFIG_PAX_SEGMEXEC
73569+ struct vm_area_struct *vma_m = NULL;
73570+#endif
73571+
73572+ /*
73573+ * mm->mmap_sem is required to protect against another thread
73574+ * changing the mappings in case we sleep.
73575+ */
73576+ verify_mm_writelocked(mm);
73577+
73578 /* Clear old maps */
73579 error = -ENOMEM;
73580-munmap_back:
73581 vma = find_vma_prepare(mm, addr, &prev, &rb_link, &rb_parent);
73582 if (vma && vma->vm_start < addr + len) {
73583 if (do_munmap(mm, addr, len))
73584 return -ENOMEM;
73585- goto munmap_back;
73586+ vma = find_vma_prepare(mm, addr, &prev, &rb_link, &rb_parent);
73587+ BUG_ON(vma && vma->vm_start < addr + len);
73588 }
73589
73590 /* Check against address space limit. */
73591@@ -1282,6 +1403,16 @@ munmap_back:
73592 goto unacct_error;
73593 }
73594
73595+#ifdef CONFIG_PAX_SEGMEXEC
73596+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (vm_flags & VM_EXEC)) {
73597+ vma_m = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
73598+ if (!vma_m) {
73599+ error = -ENOMEM;
73600+ goto free_vma;
73601+ }
73602+ }
73603+#endif
73604+
73605 vma->vm_mm = mm;
73606 vma->vm_start = addr;
73607 vma->vm_end = addr + len;
73608@@ -1306,6 +1437,19 @@ munmap_back:
73609 error = file->f_op->mmap(file, vma);
73610 if (error)
73611 goto unmap_and_free_vma;
73612+
73613+#ifdef CONFIG_PAX_SEGMEXEC
73614+ if (vma_m && (vm_flags & VM_EXECUTABLE))
73615+ added_exe_file_vma(mm);
73616+#endif
73617+
73618+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
73619+ if ((mm->pax_flags & MF_PAX_PAGEEXEC) && !(vma->vm_flags & VM_SPECIAL)) {
73620+ vma->vm_flags |= VM_PAGEEXEC;
73621+ vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
73622+ }
73623+#endif
73624+
73625 if (vm_flags & VM_EXECUTABLE)
73626 added_exe_file_vma(mm);
73627
73628@@ -1343,6 +1487,11 @@ munmap_back:
73629 vma_link(mm, vma, prev, rb_link, rb_parent);
73630 file = vma->vm_file;
73631
73632+#ifdef CONFIG_PAX_SEGMEXEC
73633+ if (vma_m)
73634+ BUG_ON(pax_mirror_vma(vma_m, vma));
73635+#endif
73636+
73637 /* Once vma denies write, undo our temporary denial count */
73638 if (correct_wcount)
73639 atomic_inc(&inode->i_writecount);
73640@@ -1350,6 +1499,7 @@ out:
73641 perf_event_mmap(vma);
73642
73643 vm_stat_account(mm, vm_flags, file, len >> PAGE_SHIFT);
73644+ track_exec_limit(mm, addr, addr + len, vm_flags);
73645 if (vm_flags & VM_LOCKED) {
73646 if (!mlock_vma_pages_range(vma, addr, addr + len))
73647 mm->locked_vm += (len >> PAGE_SHIFT);
73648@@ -1371,6 +1521,12 @@ unmap_and_free_vma:
73649 unmap_region(mm, vma, prev, vma->vm_start, vma->vm_end);
73650 charged = 0;
73651 free_vma:
73652+
73653+#ifdef CONFIG_PAX_SEGMEXEC
73654+ if (vma_m)
73655+ kmem_cache_free(vm_area_cachep, vma_m);
73656+#endif
73657+
73658 kmem_cache_free(vm_area_cachep, vma);
73659 unacct_error:
73660 if (charged)
73661@@ -1378,6 +1534,44 @@ unacct_error:
73662 return error;
73663 }
73664
73665+bool check_heap_stack_gap(const struct vm_area_struct *vma, unsigned long addr, unsigned long len)
73666+{
73667+ if (!vma) {
73668+#ifdef CONFIG_STACK_GROWSUP
73669+ if (addr > sysctl_heap_stack_gap)
73670+ vma = find_vma(current->mm, addr - sysctl_heap_stack_gap);
73671+ else
73672+ vma = find_vma(current->mm, 0);
73673+ if (vma && (vma->vm_flags & VM_GROWSUP))
73674+ return false;
73675+#endif
73676+ return true;
73677+ }
73678+
73679+ if (addr + len > vma->vm_start)
73680+ return false;
73681+
73682+ if (vma->vm_flags & VM_GROWSDOWN)
73683+ return sysctl_heap_stack_gap <= vma->vm_start - addr - len;
73684+#ifdef CONFIG_STACK_GROWSUP
73685+ else if (vma->vm_prev && (vma->vm_prev->vm_flags & VM_GROWSUP))
73686+ return addr - vma->vm_prev->vm_end <= sysctl_heap_stack_gap;
73687+#endif
73688+
73689+ return true;
73690+}
73691+
73692+unsigned long skip_heap_stack_gap(const struct vm_area_struct *vma, unsigned long len)
73693+{
73694+ if (vma->vm_start < len)
73695+ return -ENOMEM;
73696+ if (!(vma->vm_flags & VM_GROWSDOWN))
73697+ return vma->vm_start - len;
73698+ if (sysctl_heap_stack_gap <= vma->vm_start - len)
73699+ return vma->vm_start - len - sysctl_heap_stack_gap;
73700+ return -ENOMEM;
73701+}
73702+
73703 /* Get an address range which is currently unmapped.
73704 * For shmat() with addr=0.
73705 *
73706@@ -1404,18 +1598,23 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
73707 if (flags & MAP_FIXED)
73708 return addr;
73709
73710+#ifdef CONFIG_PAX_RANDMMAP
73711+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
73712+#endif
73713+
73714 if (addr) {
73715 addr = PAGE_ALIGN(addr);
73716- vma = find_vma(mm, addr);
73717- if (TASK_SIZE - len >= addr &&
73718- (!vma || addr + len <= vma->vm_start))
73719- return addr;
73720+ if (TASK_SIZE - len >= addr) {
73721+ vma = find_vma(mm, addr);
73722+ if (check_heap_stack_gap(vma, addr, len))
73723+ return addr;
73724+ }
73725 }
73726 if (len > mm->cached_hole_size) {
73727- start_addr = addr = mm->free_area_cache;
73728+ start_addr = addr = mm->free_area_cache;
73729 } else {
73730- start_addr = addr = TASK_UNMAPPED_BASE;
73731- mm->cached_hole_size = 0;
73732+ start_addr = addr = mm->mmap_base;
73733+ mm->cached_hole_size = 0;
73734 }
73735
73736 full_search:
73737@@ -1426,34 +1625,40 @@ full_search:
73738 * Start a new search - just in case we missed
73739 * some holes.
73740 */
73741- if (start_addr != TASK_UNMAPPED_BASE) {
73742- addr = TASK_UNMAPPED_BASE;
73743- start_addr = addr;
73744+ if (start_addr != mm->mmap_base) {
73745+ start_addr = addr = mm->mmap_base;
73746 mm->cached_hole_size = 0;
73747 goto full_search;
73748 }
73749 return -ENOMEM;
73750 }
73751- if (!vma || addr + len <= vma->vm_start) {
73752- /*
73753- * Remember the place where we stopped the search:
73754- */
73755- mm->free_area_cache = addr + len;
73756- return addr;
73757- }
73758+ if (check_heap_stack_gap(vma, addr, len))
73759+ break;
73760 if (addr + mm->cached_hole_size < vma->vm_start)
73761 mm->cached_hole_size = vma->vm_start - addr;
73762 addr = vma->vm_end;
73763 }
73764+
73765+ /*
73766+ * Remember the place where we stopped the search:
73767+ */
73768+ mm->free_area_cache = addr + len;
73769+ return addr;
73770 }
73771 #endif
73772
73773 void arch_unmap_area(struct mm_struct *mm, unsigned long addr)
73774 {
73775+
73776+#ifdef CONFIG_PAX_SEGMEXEC
73777+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && SEGMEXEC_TASK_SIZE <= addr)
73778+ return;
73779+#endif
73780+
73781 /*
73782 * Is this a new hole at the lowest possible address?
73783 */
73784- if (addr >= TASK_UNMAPPED_BASE && addr < mm->free_area_cache)
73785+ if (addr >= mm->mmap_base && addr < mm->free_area_cache)
73786 mm->free_area_cache = addr;
73787 }
73788
73789@@ -1469,7 +1674,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
73790 {
73791 struct vm_area_struct *vma;
73792 struct mm_struct *mm = current->mm;
73793- unsigned long addr = addr0, start_addr;
73794+ unsigned long base = mm->mmap_base, addr = addr0, start_addr;
73795
73796 /* requested length too big for entire address space */
73797 if (len > TASK_SIZE)
73798@@ -1478,13 +1683,18 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
73799 if (flags & MAP_FIXED)
73800 return addr;
73801
73802+#ifdef CONFIG_PAX_RANDMMAP
73803+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
73804+#endif
73805+
73806 /* requesting a specific address */
73807 if (addr) {
73808 addr = PAGE_ALIGN(addr);
73809- vma = find_vma(mm, addr);
73810- if (TASK_SIZE - len >= addr &&
73811- (!vma || addr + len <= vma->vm_start))
73812- return addr;
73813+ if (TASK_SIZE - len >= addr) {
73814+ vma = find_vma(mm, addr);
73815+ if (check_heap_stack_gap(vma, addr, len))
73816+ return addr;
73817+ }
73818 }
73819
73820 /* check if free_area_cache is useful for us */
73821@@ -1508,7 +1718,7 @@ try_again:
73822 * return with success:
73823 */
73824 vma = find_vma(mm, addr);
73825- if (!vma || addr+len <= vma->vm_start)
73826+ if (check_heap_stack_gap(vma, addr, len))
73827 /* remember the address as a hint for next time */
73828 return (mm->free_area_cache = addr);
73829
73830@@ -1517,8 +1727,8 @@ try_again:
73831 mm->cached_hole_size = vma->vm_start - addr;
73832
73833 /* try just below the current vma->vm_start */
73834- addr = vma->vm_start-len;
73835- } while (len < vma->vm_start);
73836+ addr = skip_heap_stack_gap(vma, len);
73837+ } while (!IS_ERR_VALUE(addr));
73838
73839 fail:
73840 /*
73841@@ -1541,13 +1751,21 @@ fail:
73842 * can happen with large stack limits and large mmap()
73843 * allocations.
73844 */
73845+ mm->mmap_base = TASK_UNMAPPED_BASE;
73846+
73847+#ifdef CONFIG_PAX_RANDMMAP
73848+ if (mm->pax_flags & MF_PAX_RANDMMAP)
73849+ mm->mmap_base += mm->delta_mmap;
73850+#endif
73851+
73852+ mm->free_area_cache = mm->mmap_base;
73853 mm->cached_hole_size = ~0UL;
73854- mm->free_area_cache = TASK_UNMAPPED_BASE;
73855 addr = arch_get_unmapped_area(filp, addr0, len, pgoff, flags);
73856 /*
73857 * Restore the topdown base:
73858 */
73859- mm->free_area_cache = mm->mmap_base;
73860+ mm->mmap_base = base;
73861+ mm->free_area_cache = base;
73862 mm->cached_hole_size = ~0UL;
73863
73864 return addr;
73865@@ -1556,6 +1774,12 @@ fail:
73866
73867 void arch_unmap_area_topdown(struct mm_struct *mm, unsigned long addr)
73868 {
73869+
73870+#ifdef CONFIG_PAX_SEGMEXEC
73871+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && SEGMEXEC_TASK_SIZE <= addr)
73872+ return;
73873+#endif
73874+
73875 /*
73876 * Is this a new hole at the highest possible address?
73877 */
73878@@ -1563,8 +1787,10 @@ void arch_unmap_area_topdown(struct mm_struct *mm, unsigned long addr)
73879 mm->free_area_cache = addr;
73880
73881 /* dont allow allocations above current base */
73882- if (mm->free_area_cache > mm->mmap_base)
73883+ if (mm->free_area_cache > mm->mmap_base) {
73884 mm->free_area_cache = mm->mmap_base;
73885+ mm->cached_hole_size = ~0UL;
73886+ }
73887 }
73888
73889 unsigned long
73890@@ -1663,6 +1889,28 @@ find_vma_prev(struct mm_struct *mm, unsigned long addr,
73891 return vma;
73892 }
73893
73894+#ifdef CONFIG_PAX_SEGMEXEC
73895+struct vm_area_struct *pax_find_mirror_vma(struct vm_area_struct *vma)
73896+{
73897+ struct vm_area_struct *vma_m;
73898+
73899+ BUG_ON(!vma || vma->vm_start >= vma->vm_end);
73900+ if (!(vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) || !(vma->vm_flags & VM_EXEC)) {
73901+ BUG_ON(vma->vm_mirror);
73902+ return NULL;
73903+ }
73904+ BUG_ON(vma->vm_start < SEGMEXEC_TASK_SIZE && SEGMEXEC_TASK_SIZE < vma->vm_end);
73905+ vma_m = vma->vm_mirror;
73906+ BUG_ON(!vma_m || vma_m->vm_mirror != vma);
73907+ BUG_ON(vma->vm_file != vma_m->vm_file);
73908+ BUG_ON(vma->vm_end - vma->vm_start != vma_m->vm_end - vma_m->vm_start);
73909+ BUG_ON(vma->vm_pgoff != vma_m->vm_pgoff);
73910+ BUG_ON(vma->anon_vma != vma_m->anon_vma && vma->anon_vma->root != vma_m->anon_vma->root);
73911+ BUG_ON((vma->vm_flags ^ vma_m->vm_flags) & ~(VM_WRITE | VM_MAYWRITE | VM_ACCOUNT | VM_LOCKED | VM_RESERVED));
73912+ return vma_m;
73913+}
73914+#endif
73915+
73916 /*
73917 * Verify that the stack growth is acceptable and
73918 * update accounting. This is shared with both the
73919@@ -1679,6 +1927,7 @@ static int acct_stack_growth(struct vm_area_struct *vma, unsigned long size, uns
73920 return -ENOMEM;
73921
73922 /* Stack limit test */
73923+ gr_learn_resource(current, RLIMIT_STACK, size, 1);
73924 if (size > ACCESS_ONCE(rlim[RLIMIT_STACK].rlim_cur))
73925 return -ENOMEM;
73926
73927@@ -1689,6 +1938,7 @@ static int acct_stack_growth(struct vm_area_struct *vma, unsigned long size, uns
73928 locked = mm->locked_vm + grow;
73929 limit = ACCESS_ONCE(rlim[RLIMIT_MEMLOCK].rlim_cur);
73930 limit >>= PAGE_SHIFT;
73931+ gr_learn_resource(current, RLIMIT_MEMLOCK, locked << PAGE_SHIFT, 1);
73932 if (locked > limit && !capable(CAP_IPC_LOCK))
73933 return -ENOMEM;
73934 }
73935@@ -1718,37 +1968,48 @@ static int acct_stack_growth(struct vm_area_struct *vma, unsigned long size, uns
73936 * PA-RISC uses this for its stack; IA64 for its Register Backing Store.
73937 * vma is the last one with address > vma->vm_end. Have to extend vma.
73938 */
73939+#ifndef CONFIG_IA64
73940+static
73941+#endif
73942 int expand_upwards(struct vm_area_struct *vma, unsigned long address)
73943 {
73944 int error;
73945+ bool locknext;
73946
73947 if (!(vma->vm_flags & VM_GROWSUP))
73948 return -EFAULT;
73949
73950+ /* Also guard against wrapping around to address 0. */
73951+ if (address < PAGE_ALIGN(address+1))
73952+ address = PAGE_ALIGN(address+1);
73953+ else
73954+ return -ENOMEM;
73955+
73956 /*
73957 * We must make sure the anon_vma is allocated
73958 * so that the anon_vma locking is not a noop.
73959 */
73960 if (unlikely(anon_vma_prepare(vma)))
73961 return -ENOMEM;
73962+ locknext = vma->vm_next && (vma->vm_next->vm_flags & VM_GROWSDOWN);
73963+ if (locknext && anon_vma_prepare(vma->vm_next))
73964+ return -ENOMEM;
73965 vma_lock_anon_vma(vma);
73966+ if (locknext)
73967+ vma_lock_anon_vma(vma->vm_next);
73968
73969 /*
73970 * vma->vm_start/vm_end cannot change under us because the caller
73971 * is required to hold the mmap_sem in read mode. We need the
73972- * anon_vma lock to serialize against concurrent expand_stacks.
73973- * Also guard against wrapping around to address 0.
73974+ * anon_vma locks to serialize against concurrent expand_stacks
73975+ * and expand_upwards.
73976 */
73977- if (address < PAGE_ALIGN(address+4))
73978- address = PAGE_ALIGN(address+4);
73979- else {
73980- vma_unlock_anon_vma(vma);
73981- return -ENOMEM;
73982- }
73983 error = 0;
73984
73985 /* Somebody else might have raced and expanded it already */
73986- if (address > vma->vm_end) {
73987+ 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)
73988+ error = -ENOMEM;
73989+ else if (address > vma->vm_end && (!locknext || vma->vm_next->vm_start >= address)) {
73990 unsigned long size, grow;
73991
73992 size = address - vma->vm_start;
73993@@ -1763,6 +2024,8 @@ int expand_upwards(struct vm_area_struct *vma, unsigned long address)
73994 }
73995 }
73996 }
73997+ if (locknext)
73998+ vma_unlock_anon_vma(vma->vm_next);
73999 vma_unlock_anon_vma(vma);
74000 khugepaged_enter_vma_merge(vma);
74001 return error;
74002@@ -1776,6 +2039,8 @@ int expand_downwards(struct vm_area_struct *vma,
74003 unsigned long address)
74004 {
74005 int error;
74006+ bool lockprev = false;
74007+ struct vm_area_struct *prev;
74008
74009 /*
74010 * We must make sure the anon_vma is allocated
74011@@ -1789,6 +2054,15 @@ int expand_downwards(struct vm_area_struct *vma,
74012 if (error)
74013 return error;
74014
74015+ prev = vma->vm_prev;
74016+#if defined(CONFIG_STACK_GROWSUP) || defined(CONFIG_IA64)
74017+ lockprev = prev && (prev->vm_flags & VM_GROWSUP);
74018+#endif
74019+ if (lockprev && anon_vma_prepare(prev))
74020+ return -ENOMEM;
74021+ if (lockprev)
74022+ vma_lock_anon_vma(prev);
74023+
74024 vma_lock_anon_vma(vma);
74025
74026 /*
74027@@ -1798,9 +2072,17 @@ int expand_downwards(struct vm_area_struct *vma,
74028 */
74029
74030 /* Somebody else might have raced and expanded it already */
74031- if (address < vma->vm_start) {
74032+ if (prev && (prev->vm_flags & (VM_READ | VM_WRITE | VM_EXEC)) && address - prev->vm_end < sysctl_heap_stack_gap)
74033+ error = -ENOMEM;
74034+ else if (address < vma->vm_start && (!lockprev || prev->vm_end <= address)) {
74035 unsigned long size, grow;
74036
74037+#ifdef CONFIG_PAX_SEGMEXEC
74038+ struct vm_area_struct *vma_m;
74039+
74040+ vma_m = pax_find_mirror_vma(vma);
74041+#endif
74042+
74043 size = vma->vm_end - address;
74044 grow = (vma->vm_start - address) >> PAGE_SHIFT;
74045
74046@@ -1810,11 +2092,22 @@ int expand_downwards(struct vm_area_struct *vma,
74047 if (!error) {
74048 vma->vm_start = address;
74049 vma->vm_pgoff -= grow;
74050+ track_exec_limit(vma->vm_mm, vma->vm_start, vma->vm_end, vma->vm_flags);
74051+
74052+#ifdef CONFIG_PAX_SEGMEXEC
74053+ if (vma_m) {
74054+ vma_m->vm_start -= grow << PAGE_SHIFT;
74055+ vma_m->vm_pgoff -= grow;
74056+ }
74057+#endif
74058+
74059 perf_event_mmap(vma);
74060 }
74061 }
74062 }
74063 vma_unlock_anon_vma(vma);
74064+ if (lockprev)
74065+ vma_unlock_anon_vma(prev);
74066 khugepaged_enter_vma_merge(vma);
74067 return error;
74068 }
74069@@ -1886,6 +2179,13 @@ static void remove_vma_list(struct mm_struct *mm, struct vm_area_struct *vma)
74070 do {
74071 long nrpages = vma_pages(vma);
74072
74073+#ifdef CONFIG_PAX_SEGMEXEC
74074+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_start >= SEGMEXEC_TASK_SIZE)) {
74075+ vma = remove_vma(vma);
74076+ continue;
74077+ }
74078+#endif
74079+
74080 if (vma->vm_flags & VM_ACCOUNT)
74081 nr_accounted += nrpages;
74082 vm_stat_account(mm, vma->vm_flags, vma->vm_file, -nrpages);
74083@@ -1931,6 +2231,16 @@ detach_vmas_to_be_unmapped(struct mm_struct *mm, struct vm_area_struct *vma,
74084 insertion_point = (prev ? &prev->vm_next : &mm->mmap);
74085 vma->vm_prev = NULL;
74086 do {
74087+
74088+#ifdef CONFIG_PAX_SEGMEXEC
74089+ if (vma->vm_mirror) {
74090+ BUG_ON(!vma->vm_mirror->vm_mirror || vma->vm_mirror->vm_mirror != vma);
74091+ vma->vm_mirror->vm_mirror = NULL;
74092+ vma->vm_mirror->vm_flags &= ~VM_EXEC;
74093+ vma->vm_mirror = NULL;
74094+ }
74095+#endif
74096+
74097 rb_erase(&vma->vm_rb, &mm->mm_rb);
74098 mm->map_count--;
74099 tail_vma = vma;
74100@@ -1959,14 +2269,33 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
74101 struct vm_area_struct *new;
74102 int err = -ENOMEM;
74103
74104+#ifdef CONFIG_PAX_SEGMEXEC
74105+ struct vm_area_struct *vma_m, *new_m = NULL;
74106+ unsigned long addr_m = addr + SEGMEXEC_TASK_SIZE;
74107+#endif
74108+
74109 if (is_vm_hugetlb_page(vma) && (addr &
74110 ~(huge_page_mask(hstate_vma(vma)))))
74111 return -EINVAL;
74112
74113+#ifdef CONFIG_PAX_SEGMEXEC
74114+ vma_m = pax_find_mirror_vma(vma);
74115+#endif
74116+
74117 new = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
74118 if (!new)
74119 goto out_err;
74120
74121+#ifdef CONFIG_PAX_SEGMEXEC
74122+ if (vma_m) {
74123+ new_m = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
74124+ if (!new_m) {
74125+ kmem_cache_free(vm_area_cachep, new);
74126+ goto out_err;
74127+ }
74128+ }
74129+#endif
74130+
74131 /* most fields are the same, copy all, and then fixup */
74132 *new = *vma;
74133
74134@@ -1979,6 +2308,22 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
74135 new->vm_pgoff += ((addr - vma->vm_start) >> PAGE_SHIFT);
74136 }
74137
74138+#ifdef CONFIG_PAX_SEGMEXEC
74139+ if (vma_m) {
74140+ *new_m = *vma_m;
74141+ INIT_LIST_HEAD(&new_m->anon_vma_chain);
74142+ new_m->vm_mirror = new;
74143+ new->vm_mirror = new_m;
74144+
74145+ if (new_below)
74146+ new_m->vm_end = addr_m;
74147+ else {
74148+ new_m->vm_start = addr_m;
74149+ new_m->vm_pgoff += ((addr_m - vma_m->vm_start) >> PAGE_SHIFT);
74150+ }
74151+ }
74152+#endif
74153+
74154 pol = mpol_dup(vma_policy(vma));
74155 if (IS_ERR(pol)) {
74156 err = PTR_ERR(pol);
74157@@ -2004,6 +2349,42 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
74158 else
74159 err = vma_adjust(vma, vma->vm_start, addr, vma->vm_pgoff, new);
74160
74161+#ifdef CONFIG_PAX_SEGMEXEC
74162+ if (!err && vma_m) {
74163+ if (anon_vma_clone(new_m, vma_m))
74164+ goto out_free_mpol;
74165+
74166+ mpol_get(pol);
74167+ vma_set_policy(new_m, pol);
74168+
74169+ if (new_m->vm_file) {
74170+ get_file(new_m->vm_file);
74171+ if (vma_m->vm_flags & VM_EXECUTABLE)
74172+ added_exe_file_vma(mm);
74173+ }
74174+
74175+ if (new_m->vm_ops && new_m->vm_ops->open)
74176+ new_m->vm_ops->open(new_m);
74177+
74178+ if (new_below)
74179+ err = vma_adjust(vma_m, addr_m, vma_m->vm_end, vma_m->vm_pgoff +
74180+ ((addr_m - new_m->vm_start) >> PAGE_SHIFT), new_m);
74181+ else
74182+ err = vma_adjust(vma_m, vma_m->vm_start, addr_m, vma_m->vm_pgoff, new_m);
74183+
74184+ if (err) {
74185+ if (new_m->vm_ops && new_m->vm_ops->close)
74186+ new_m->vm_ops->close(new_m);
74187+ if (new_m->vm_file) {
74188+ if (vma_m->vm_flags & VM_EXECUTABLE)
74189+ removed_exe_file_vma(mm);
74190+ fput(new_m->vm_file);
74191+ }
74192+ mpol_put(pol);
74193+ }
74194+ }
74195+#endif
74196+
74197 /* Success. */
74198 if (!err)
74199 return 0;
74200@@ -2016,10 +2397,18 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
74201 removed_exe_file_vma(mm);
74202 fput(new->vm_file);
74203 }
74204- unlink_anon_vmas(new);
74205 out_free_mpol:
74206 mpol_put(pol);
74207 out_free_vma:
74208+
74209+#ifdef CONFIG_PAX_SEGMEXEC
74210+ if (new_m) {
74211+ unlink_anon_vmas(new_m);
74212+ kmem_cache_free(vm_area_cachep, new_m);
74213+ }
74214+#endif
74215+
74216+ unlink_anon_vmas(new);
74217 kmem_cache_free(vm_area_cachep, new);
74218 out_err:
74219 return err;
74220@@ -2032,6 +2421,15 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
74221 int split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
74222 unsigned long addr, int new_below)
74223 {
74224+
74225+#ifdef CONFIG_PAX_SEGMEXEC
74226+ if (mm->pax_flags & MF_PAX_SEGMEXEC) {
74227+ BUG_ON(vma->vm_end > SEGMEXEC_TASK_SIZE);
74228+ if (mm->map_count >= sysctl_max_map_count-1)
74229+ return -ENOMEM;
74230+ } else
74231+#endif
74232+
74233 if (mm->map_count >= sysctl_max_map_count)
74234 return -ENOMEM;
74235
74236@@ -2043,11 +2441,30 @@ int split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
74237 * work. This now handles partial unmappings.
74238 * Jeremy Fitzhardinge <jeremy@goop.org>
74239 */
74240+#ifdef CONFIG_PAX_SEGMEXEC
74241 int do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
74242 {
74243+ int ret = __do_munmap(mm, start, len);
74244+ if (ret || !(mm->pax_flags & MF_PAX_SEGMEXEC))
74245+ return ret;
74246+
74247+ return __do_munmap(mm, start + SEGMEXEC_TASK_SIZE, len);
74248+}
74249+
74250+int __do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
74251+#else
74252+int do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
74253+#endif
74254+{
74255 unsigned long end;
74256 struct vm_area_struct *vma, *prev, *last;
74257
74258+ /*
74259+ * mm->mmap_sem is required to protect against another thread
74260+ * changing the mappings in case we sleep.
74261+ */
74262+ verify_mm_writelocked(mm);
74263+
74264 if ((start & ~PAGE_MASK) || start > TASK_SIZE || len > TASK_SIZE-start)
74265 return -EINVAL;
74266
74267@@ -2122,6 +2539,8 @@ int do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
74268 /* Fix up all other VM information */
74269 remove_vma_list(mm, vma);
74270
74271+ track_exec_limit(mm, start, end, 0UL);
74272+
74273 return 0;
74274 }
74275
74276@@ -2130,6 +2549,13 @@ int vm_munmap(unsigned long start, size_t len)
74277 int ret;
74278 struct mm_struct *mm = current->mm;
74279
74280+
74281+#ifdef CONFIG_PAX_SEGMEXEC
74282+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) &&
74283+ (len > SEGMEXEC_TASK_SIZE || start > SEGMEXEC_TASK_SIZE-len))
74284+ return -EINVAL;
74285+#endif
74286+
74287 down_write(&mm->mmap_sem);
74288 ret = do_munmap(mm, start, len);
74289 up_write(&mm->mmap_sem);
74290@@ -2143,16 +2569,6 @@ SYSCALL_DEFINE2(munmap, unsigned long, addr, size_t, len)
74291 return vm_munmap(addr, len);
74292 }
74293
74294-static inline void verify_mm_writelocked(struct mm_struct *mm)
74295-{
74296-#ifdef CONFIG_DEBUG_VM
74297- if (unlikely(down_read_trylock(&mm->mmap_sem))) {
74298- WARN_ON(1);
74299- up_read(&mm->mmap_sem);
74300- }
74301-#endif
74302-}
74303-
74304 /*
74305 * this is really a simplified "do_mmap". it only handles
74306 * anonymous maps. eventually we may be able to do some
74307@@ -2166,6 +2582,7 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
74308 struct rb_node ** rb_link, * rb_parent;
74309 pgoff_t pgoff = addr >> PAGE_SHIFT;
74310 int error;
74311+ unsigned long charged;
74312
74313 len = PAGE_ALIGN(len);
74314 if (!len)
74315@@ -2173,16 +2590,30 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
74316
74317 flags = VM_DATA_DEFAULT_FLAGS | VM_ACCOUNT | mm->def_flags;
74318
74319+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
74320+ if (mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
74321+ flags &= ~VM_EXEC;
74322+
74323+#ifdef CONFIG_PAX_MPROTECT
74324+ if (mm->pax_flags & MF_PAX_MPROTECT)
74325+ flags &= ~VM_MAYEXEC;
74326+#endif
74327+
74328+ }
74329+#endif
74330+
74331 error = get_unmapped_area(NULL, addr, len, 0, MAP_FIXED);
74332 if (error & ~PAGE_MASK)
74333 return error;
74334
74335+ charged = len >> PAGE_SHIFT;
74336+
74337 /*
74338 * mlock MCL_FUTURE?
74339 */
74340 if (mm->def_flags & VM_LOCKED) {
74341 unsigned long locked, lock_limit;
74342- locked = len >> PAGE_SHIFT;
74343+ locked = charged;
74344 locked += mm->locked_vm;
74345 lock_limit = rlimit(RLIMIT_MEMLOCK);
74346 lock_limit >>= PAGE_SHIFT;
74347@@ -2199,22 +2630,22 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
74348 /*
74349 * Clear old maps. this also does some error checking for us
74350 */
74351- munmap_back:
74352 vma = find_vma_prepare(mm, addr, &prev, &rb_link, &rb_parent);
74353 if (vma && vma->vm_start < addr + len) {
74354 if (do_munmap(mm, addr, len))
74355 return -ENOMEM;
74356- goto munmap_back;
74357- }
74358+ vma = find_vma_prepare(mm, addr, &prev, &rb_link, &rb_parent);
74359+ BUG_ON(vma && vma->vm_start < addr + len);
74360+ }
74361
74362 /* Check against address space limits *after* clearing old maps... */
74363- if (!may_expand_vm(mm, len >> PAGE_SHIFT))
74364+ if (!may_expand_vm(mm, charged))
74365 return -ENOMEM;
74366
74367 if (mm->map_count > sysctl_max_map_count)
74368 return -ENOMEM;
74369
74370- if (security_vm_enough_memory_mm(mm, len >> PAGE_SHIFT))
74371+ if (security_vm_enough_memory_mm(mm, charged))
74372 return -ENOMEM;
74373
74374 /* Can we just expand an old private anonymous mapping? */
74375@@ -2228,7 +2659,7 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
74376 */
74377 vma = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
74378 if (!vma) {
74379- vm_unacct_memory(len >> PAGE_SHIFT);
74380+ vm_unacct_memory(charged);
74381 return -ENOMEM;
74382 }
74383
74384@@ -2242,11 +2673,12 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
74385 vma_link(mm, vma, prev, rb_link, rb_parent);
74386 out:
74387 perf_event_mmap(vma);
74388- mm->total_vm += len >> PAGE_SHIFT;
74389+ mm->total_vm += charged;
74390 if (flags & VM_LOCKED) {
74391 if (!mlock_vma_pages_range(vma, addr, addr + len))
74392- mm->locked_vm += (len >> PAGE_SHIFT);
74393+ mm->locked_vm += charged;
74394 }
74395+ track_exec_limit(mm, addr, addr + len, flags);
74396 return addr;
74397 }
74398
74399@@ -2304,6 +2736,7 @@ void exit_mmap(struct mm_struct *mm)
74400 while (vma) {
74401 if (vma->vm_flags & VM_ACCOUNT)
74402 nr_accounted += vma_pages(vma);
74403+ vma->vm_mirror = NULL;
74404 vma = remove_vma(vma);
74405 }
74406 vm_unacct_memory(nr_accounted);
74407@@ -2320,6 +2753,13 @@ int insert_vm_struct(struct mm_struct * mm, struct vm_area_struct * vma)
74408 struct vm_area_struct * __vma, * prev;
74409 struct rb_node ** rb_link, * rb_parent;
74410
74411+#ifdef CONFIG_PAX_SEGMEXEC
74412+ struct vm_area_struct *vma_m = NULL;
74413+#endif
74414+
74415+ if (security_mmap_addr(vma->vm_start))
74416+ return -EPERM;
74417+
74418 /*
74419 * The vm_pgoff of a purely anonymous vma should be irrelevant
74420 * until its first write fault, when page's anon_vma and index
74421@@ -2343,7 +2783,21 @@ int insert_vm_struct(struct mm_struct * mm, struct vm_area_struct * vma)
74422 security_vm_enough_memory_mm(mm, vma_pages(vma)))
74423 return -ENOMEM;
74424
74425+#ifdef CONFIG_PAX_SEGMEXEC
74426+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_flags & VM_EXEC)) {
74427+ vma_m = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
74428+ if (!vma_m)
74429+ return -ENOMEM;
74430+ }
74431+#endif
74432+
74433 vma_link(mm, vma, prev, rb_link, rb_parent);
74434+
74435+#ifdef CONFIG_PAX_SEGMEXEC
74436+ if (vma_m)
74437+ BUG_ON(pax_mirror_vma(vma_m, vma));
74438+#endif
74439+
74440 return 0;
74441 }
74442
74443@@ -2362,6 +2816,8 @@ struct vm_area_struct *copy_vma(struct vm_area_struct **vmap,
74444 struct mempolicy *pol;
74445 bool faulted_in_anon_vma = true;
74446
74447+ BUG_ON(vma->vm_mirror);
74448+
74449 /*
74450 * If anonymous vma has not yet been faulted, update new pgoff
74451 * to match new location, to increase its chance of merging.
74452@@ -2430,6 +2886,39 @@ struct vm_area_struct *copy_vma(struct vm_area_struct **vmap,
74453 return NULL;
74454 }
74455
74456+#ifdef CONFIG_PAX_SEGMEXEC
74457+long pax_mirror_vma(struct vm_area_struct *vma_m, struct vm_area_struct *vma)
74458+{
74459+ struct vm_area_struct *prev_m;
74460+ struct rb_node **rb_link_m, *rb_parent_m;
74461+ struct mempolicy *pol_m;
74462+
74463+ BUG_ON(!(vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) || !(vma->vm_flags & VM_EXEC));
74464+ BUG_ON(vma->vm_mirror || vma_m->vm_mirror);
74465+ BUG_ON(!mpol_equal(vma_policy(vma), vma_policy(vma_m)));
74466+ *vma_m = *vma;
74467+ INIT_LIST_HEAD(&vma_m->anon_vma_chain);
74468+ if (anon_vma_clone(vma_m, vma))
74469+ return -ENOMEM;
74470+ pol_m = vma_policy(vma_m);
74471+ mpol_get(pol_m);
74472+ vma_set_policy(vma_m, pol_m);
74473+ vma_m->vm_start += SEGMEXEC_TASK_SIZE;
74474+ vma_m->vm_end += SEGMEXEC_TASK_SIZE;
74475+ vma_m->vm_flags &= ~(VM_WRITE | VM_MAYWRITE | VM_ACCOUNT | VM_LOCKED);
74476+ vma_m->vm_page_prot = vm_get_page_prot(vma_m->vm_flags);
74477+ if (vma_m->vm_file)
74478+ get_file(vma_m->vm_file);
74479+ if (vma_m->vm_ops && vma_m->vm_ops->open)
74480+ vma_m->vm_ops->open(vma_m);
74481+ find_vma_prepare(vma->vm_mm, vma_m->vm_start, &prev_m, &rb_link_m, &rb_parent_m);
74482+ vma_link(vma->vm_mm, vma_m, prev_m, rb_link_m, rb_parent_m);
74483+ vma_m->vm_mirror = vma;
74484+ vma->vm_mirror = vma_m;
74485+ return 0;
74486+}
74487+#endif
74488+
74489 /*
74490 * Return true if the calling process may expand its vm space by the passed
74491 * number of pages
74492@@ -2441,6 +2930,12 @@ int may_expand_vm(struct mm_struct *mm, unsigned long npages)
74493
74494 lim = rlimit(RLIMIT_AS) >> PAGE_SHIFT;
74495
74496+#ifdef CONFIG_PAX_RANDMMAP
74497+ if (mm->pax_flags & MF_PAX_RANDMMAP)
74498+ cur -= mm->brk_gap;
74499+#endif
74500+
74501+ gr_learn_resource(current, RLIMIT_AS, (cur + npages) << PAGE_SHIFT, 1);
74502 if (cur + npages > lim)
74503 return 0;
74504 return 1;
74505@@ -2511,6 +3006,22 @@ int install_special_mapping(struct mm_struct *mm,
74506 vma->vm_start = addr;
74507 vma->vm_end = addr + len;
74508
74509+#ifdef CONFIG_PAX_MPROTECT
74510+ if (mm->pax_flags & MF_PAX_MPROTECT) {
74511+#ifndef CONFIG_PAX_MPROTECT_COMPAT
74512+ if ((vm_flags & (VM_WRITE | VM_EXEC)) == (VM_WRITE | VM_EXEC))
74513+ return -EPERM;
74514+ if (!(vm_flags & VM_EXEC))
74515+ vm_flags &= ~VM_MAYEXEC;
74516+#else
74517+ if ((vm_flags & (VM_WRITE | VM_EXEC)) != VM_EXEC)
74518+ vm_flags &= ~(VM_EXEC | VM_MAYEXEC);
74519+#endif
74520+ else
74521+ vm_flags &= ~VM_MAYWRITE;
74522+ }
74523+#endif
74524+
74525 vma->vm_flags = vm_flags | mm->def_flags | VM_DONTEXPAND;
74526 vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
74527
74528diff --git a/mm/mprotect.c b/mm/mprotect.c
74529index a409926..8b32e6d 100644
74530--- a/mm/mprotect.c
74531+++ b/mm/mprotect.c
74532@@ -23,10 +23,17 @@
74533 #include <linux/mmu_notifier.h>
74534 #include <linux/migrate.h>
74535 #include <linux/perf_event.h>
74536+
74537+#ifdef CONFIG_PAX_MPROTECT
74538+#include <linux/elf.h>
74539+#include <linux/binfmts.h>
74540+#endif
74541+
74542 #include <asm/uaccess.h>
74543 #include <asm/pgtable.h>
74544 #include <asm/cacheflush.h>
74545 #include <asm/tlbflush.h>
74546+#include <asm/mmu_context.h>
74547
74548 #ifndef pgprot_modify
74549 static inline pgprot_t pgprot_modify(pgprot_t oldprot, pgprot_t newprot)
74550@@ -141,6 +148,48 @@ static void change_protection(struct vm_area_struct *vma,
74551 flush_tlb_range(vma, start, end);
74552 }
74553
74554+#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
74555+/* called while holding the mmap semaphor for writing except stack expansion */
74556+void track_exec_limit(struct mm_struct *mm, unsigned long start, unsigned long end, unsigned long prot)
74557+{
74558+ unsigned long oldlimit, newlimit = 0UL;
74559+
74560+ if (!(mm->pax_flags & MF_PAX_PAGEEXEC) || (__supported_pte_mask & _PAGE_NX))
74561+ return;
74562+
74563+ spin_lock(&mm->page_table_lock);
74564+ oldlimit = mm->context.user_cs_limit;
74565+ if ((prot & VM_EXEC) && oldlimit < end)
74566+ /* USER_CS limit moved up */
74567+ newlimit = end;
74568+ else if (!(prot & VM_EXEC) && start < oldlimit && oldlimit <= end)
74569+ /* USER_CS limit moved down */
74570+ newlimit = start;
74571+
74572+ if (newlimit) {
74573+ mm->context.user_cs_limit = newlimit;
74574+
74575+#ifdef CONFIG_SMP
74576+ wmb();
74577+ cpus_clear(mm->context.cpu_user_cs_mask);
74578+ cpu_set(smp_processor_id(), mm->context.cpu_user_cs_mask);
74579+#endif
74580+
74581+ set_user_cs(mm->context.user_cs_base, mm->context.user_cs_limit, smp_processor_id());
74582+ }
74583+ spin_unlock(&mm->page_table_lock);
74584+ if (newlimit == end) {
74585+ struct vm_area_struct *vma = find_vma(mm, oldlimit);
74586+
74587+ for (; vma && vma->vm_start < end; vma = vma->vm_next)
74588+ if (is_vm_hugetlb_page(vma))
74589+ hugetlb_change_protection(vma, vma->vm_start, vma->vm_end, vma->vm_page_prot);
74590+ else
74591+ change_protection(vma, vma->vm_start, vma->vm_end, vma->vm_page_prot, vma_wants_writenotify(vma));
74592+ }
74593+}
74594+#endif
74595+
74596 int
74597 mprotect_fixup(struct vm_area_struct *vma, struct vm_area_struct **pprev,
74598 unsigned long start, unsigned long end, unsigned long newflags)
74599@@ -153,11 +202,29 @@ mprotect_fixup(struct vm_area_struct *vma, struct vm_area_struct **pprev,
74600 int error;
74601 int dirty_accountable = 0;
74602
74603+#ifdef CONFIG_PAX_SEGMEXEC
74604+ struct vm_area_struct *vma_m = NULL;
74605+ unsigned long start_m, end_m;
74606+
74607+ start_m = start + SEGMEXEC_TASK_SIZE;
74608+ end_m = end + SEGMEXEC_TASK_SIZE;
74609+#endif
74610+
74611 if (newflags == oldflags) {
74612 *pprev = vma;
74613 return 0;
74614 }
74615
74616+ if (newflags & (VM_READ | VM_WRITE | VM_EXEC)) {
74617+ struct vm_area_struct *prev = vma->vm_prev, *next = vma->vm_next;
74618+
74619+ if (next && (next->vm_flags & VM_GROWSDOWN) && sysctl_heap_stack_gap > next->vm_start - end)
74620+ return -ENOMEM;
74621+
74622+ if (prev && (prev->vm_flags & VM_GROWSUP) && sysctl_heap_stack_gap > start - prev->vm_end)
74623+ return -ENOMEM;
74624+ }
74625+
74626 /*
74627 * If we make a private mapping writable we increase our commit;
74628 * but (without finer accounting) cannot reduce our commit if we
74629@@ -174,6 +241,42 @@ mprotect_fixup(struct vm_area_struct *vma, struct vm_area_struct **pprev,
74630 }
74631 }
74632
74633+#ifdef CONFIG_PAX_SEGMEXEC
74634+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && ((oldflags ^ newflags) & VM_EXEC)) {
74635+ if (start != vma->vm_start) {
74636+ error = split_vma(mm, vma, start, 1);
74637+ if (error)
74638+ goto fail;
74639+ BUG_ON(!*pprev || (*pprev)->vm_next == vma);
74640+ *pprev = (*pprev)->vm_next;
74641+ }
74642+
74643+ if (end != vma->vm_end) {
74644+ error = split_vma(mm, vma, end, 0);
74645+ if (error)
74646+ goto fail;
74647+ }
74648+
74649+ if (pax_find_mirror_vma(vma)) {
74650+ error = __do_munmap(mm, start_m, end_m - start_m);
74651+ if (error)
74652+ goto fail;
74653+ } else {
74654+ vma_m = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
74655+ if (!vma_m) {
74656+ error = -ENOMEM;
74657+ goto fail;
74658+ }
74659+ vma->vm_flags = newflags;
74660+ error = pax_mirror_vma(vma_m, vma);
74661+ if (error) {
74662+ vma->vm_flags = oldflags;
74663+ goto fail;
74664+ }
74665+ }
74666+ }
74667+#endif
74668+
74669 /*
74670 * First try to merge with previous and/or next vma.
74671 */
74672@@ -204,9 +307,21 @@ success:
74673 * vm_flags and vm_page_prot are protected by the mmap_sem
74674 * held in write mode.
74675 */
74676+
74677+#ifdef CONFIG_PAX_SEGMEXEC
74678+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (newflags & VM_EXEC) && ((vma->vm_flags ^ newflags) & VM_READ))
74679+ pax_find_mirror_vma(vma)->vm_flags ^= VM_READ;
74680+#endif
74681+
74682 vma->vm_flags = newflags;
74683+
74684+#ifdef CONFIG_PAX_MPROTECT
74685+ if (mm->binfmt && mm->binfmt->handle_mprotect)
74686+ mm->binfmt->handle_mprotect(vma, newflags);
74687+#endif
74688+
74689 vma->vm_page_prot = pgprot_modify(vma->vm_page_prot,
74690- vm_get_page_prot(newflags));
74691+ vm_get_page_prot(vma->vm_flags));
74692
74693 if (vma_wants_writenotify(vma)) {
74694 vma->vm_page_prot = vm_get_page_prot(newflags & ~VM_SHARED);
74695@@ -248,6 +363,17 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
74696 end = start + len;
74697 if (end <= start)
74698 return -ENOMEM;
74699+
74700+#ifdef CONFIG_PAX_SEGMEXEC
74701+ if (current->mm->pax_flags & MF_PAX_SEGMEXEC) {
74702+ if (end > SEGMEXEC_TASK_SIZE)
74703+ return -EINVAL;
74704+ } else
74705+#endif
74706+
74707+ if (end > TASK_SIZE)
74708+ return -EINVAL;
74709+
74710 if (!arch_validate_prot(prot))
74711 return -EINVAL;
74712
74713@@ -255,7 +381,7 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
74714 /*
74715 * Does the application expect PROT_READ to imply PROT_EXEC:
74716 */
74717- if ((prot & PROT_READ) && (current->personality & READ_IMPLIES_EXEC))
74718+ if ((prot & (PROT_READ | PROT_WRITE)) && (current->personality & READ_IMPLIES_EXEC))
74719 prot |= PROT_EXEC;
74720
74721 vm_flags = calc_vm_prot_bits(prot);
74722@@ -288,6 +414,11 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
74723 if (start > vma->vm_start)
74724 prev = vma;
74725
74726+#ifdef CONFIG_PAX_MPROTECT
74727+ if (current->mm->binfmt && current->mm->binfmt->handle_mprotect)
74728+ current->mm->binfmt->handle_mprotect(vma, vm_flags);
74729+#endif
74730+
74731 for (nstart = start ; ; ) {
74732 unsigned long newflags;
74733
74734@@ -297,6 +428,14 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
74735
74736 /* newflags >> 4 shift VM_MAY% in place of VM_% */
74737 if ((newflags & ~(newflags >> 4)) & (VM_READ | VM_WRITE | VM_EXEC)) {
74738+ if (prot & (PROT_WRITE | PROT_EXEC))
74739+ gr_log_rwxmprotect(vma->vm_file);
74740+
74741+ error = -EACCES;
74742+ goto out;
74743+ }
74744+
74745+ if (!gr_acl_handle_mprotect(vma->vm_file, prot)) {
74746 error = -EACCES;
74747 goto out;
74748 }
74749@@ -311,6 +450,9 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
74750 error = mprotect_fixup(vma, &prev, nstart, tmp, newflags);
74751 if (error)
74752 goto out;
74753+
74754+ track_exec_limit(current->mm, nstart, tmp, vm_flags);
74755+
74756 nstart = tmp;
74757
74758 if (nstart < prev->vm_end)
74759diff --git a/mm/mremap.c b/mm/mremap.c
74760index cc06d0e..40b5d18 100644
74761--- a/mm/mremap.c
74762+++ b/mm/mremap.c
74763@@ -106,6 +106,12 @@ static void move_ptes(struct vm_area_struct *vma, pmd_t *old_pmd,
74764 continue;
74765 pte = ptep_get_and_clear(mm, old_addr, old_pte);
74766 pte = move_pte(pte, new_vma->vm_page_prot, old_addr, new_addr);
74767+
74768+#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
74769+ if (!(__supported_pte_mask & _PAGE_NX) && (new_vma->vm_flags & (VM_PAGEEXEC | VM_EXEC)) == VM_PAGEEXEC)
74770+ pte = pte_exprotect(pte);
74771+#endif
74772+
74773 set_pte_at(mm, new_addr, new_pte, pte);
74774 }
74775
74776@@ -298,6 +304,11 @@ static struct vm_area_struct *vma_to_resize(unsigned long addr,
74777 if (is_vm_hugetlb_page(vma))
74778 goto Einval;
74779
74780+#ifdef CONFIG_PAX_SEGMEXEC
74781+ if (pax_find_mirror_vma(vma))
74782+ goto Einval;
74783+#endif
74784+
74785 /* We can't remap across vm area boundaries */
74786 if (old_len > vma->vm_end - addr)
74787 goto Efault;
74788@@ -354,20 +365,25 @@ static unsigned long mremap_to(unsigned long addr,
74789 unsigned long ret = -EINVAL;
74790 unsigned long charged = 0;
74791 unsigned long map_flags;
74792+ unsigned long pax_task_size = TASK_SIZE;
74793
74794 if (new_addr & ~PAGE_MASK)
74795 goto out;
74796
74797- if (new_len > TASK_SIZE || new_addr > TASK_SIZE - new_len)
74798+#ifdef CONFIG_PAX_SEGMEXEC
74799+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
74800+ pax_task_size = SEGMEXEC_TASK_SIZE;
74801+#endif
74802+
74803+ pax_task_size -= PAGE_SIZE;
74804+
74805+ if (new_len > TASK_SIZE || new_addr > pax_task_size - new_len)
74806 goto out;
74807
74808 /* Check if the location we're moving into overlaps the
74809 * old location at all, and fail if it does.
74810 */
74811- if ((new_addr <= addr) && (new_addr+new_len) > addr)
74812- goto out;
74813-
74814- if ((addr <= new_addr) && (addr+old_len) > new_addr)
74815+ if (addr + old_len > new_addr && new_addr + new_len > addr)
74816 goto out;
74817
74818 ret = do_munmap(mm, new_addr, new_len);
74819@@ -435,6 +451,7 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
74820 struct vm_area_struct *vma;
74821 unsigned long ret = -EINVAL;
74822 unsigned long charged = 0;
74823+ unsigned long pax_task_size = TASK_SIZE;
74824
74825 down_write(&current->mm->mmap_sem);
74826
74827@@ -455,6 +472,17 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
74828 if (!new_len)
74829 goto out;
74830
74831+#ifdef CONFIG_PAX_SEGMEXEC
74832+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
74833+ pax_task_size = SEGMEXEC_TASK_SIZE;
74834+#endif
74835+
74836+ pax_task_size -= PAGE_SIZE;
74837+
74838+ if (new_len > pax_task_size || addr > pax_task_size-new_len ||
74839+ old_len > pax_task_size || addr > pax_task_size-old_len)
74840+ goto out;
74841+
74842 if (flags & MREMAP_FIXED) {
74843 if (flags & MREMAP_MAYMOVE)
74844 ret = mremap_to(addr, old_len, new_addr, new_len);
74845@@ -503,6 +531,7 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
74846 addr + new_len);
74847 }
74848 ret = addr;
74849+ track_exec_limit(vma->vm_mm, vma->vm_start, addr + new_len, vma->vm_flags);
74850 goto out;
74851 }
74852 }
74853@@ -526,7 +555,12 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
74854 goto out;
74855 }
74856
74857+ map_flags = vma->vm_flags;
74858 ret = move_vma(vma, addr, old_len, new_len, new_addr);
74859+ if (!(ret & ~PAGE_MASK)) {
74860+ track_exec_limit(current->mm, addr, addr + old_len, 0UL);
74861+ track_exec_limit(current->mm, new_addr, new_addr + new_len, map_flags);
74862+ }
74863 }
74864 out:
74865 if (ret & ~PAGE_MASK)
74866diff --git a/mm/nommu.c b/mm/nommu.c
74867index d4b0c10..ed421b5 100644
74868--- a/mm/nommu.c
74869+++ b/mm/nommu.c
74870@@ -62,7 +62,6 @@ int sysctl_overcommit_memory = OVERCOMMIT_GUESS; /* heuristic overcommit */
74871 int sysctl_overcommit_ratio = 50; /* default is 50% */
74872 int sysctl_max_map_count = DEFAULT_MAX_MAP_COUNT;
74873 int sysctl_nr_trim_pages = CONFIG_NOMMU_INITIAL_TRIM_EXCESS;
74874-int heap_stack_gap = 0;
74875
74876 atomic_long_t mmap_pages_allocated;
74877
74878@@ -827,15 +826,6 @@ struct vm_area_struct *find_vma(struct mm_struct *mm, unsigned long addr)
74879 EXPORT_SYMBOL(find_vma);
74880
74881 /*
74882- * find a VMA
74883- * - we don't extend stack VMAs under NOMMU conditions
74884- */
74885-struct vm_area_struct *find_extend_vma(struct mm_struct *mm, unsigned long addr)
74886-{
74887- return find_vma(mm, addr);
74888-}
74889-
74890-/*
74891 * expand a stack to a given address
74892 * - not supported under NOMMU conditions
74893 */
74894@@ -1551,6 +1541,7 @@ int split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
74895
74896 /* most fields are the same, copy all, and then fixup */
74897 *new = *vma;
74898+ INIT_LIST_HEAD(&new->anon_vma_chain);
74899 *region = *vma->vm_region;
74900 new->vm_region = region;
74901
74902diff --git a/mm/page_alloc.c b/mm/page_alloc.c
74903index c13ea75..081ab2c 100644
74904--- a/mm/page_alloc.c
74905+++ b/mm/page_alloc.c
74906@@ -340,7 +340,7 @@ out:
74907 * This usage means that zero-order pages may not be compound.
74908 */
74909
74910-static void free_compound_page(struct page *page)
74911+void free_compound_page(struct page *page)
74912 {
74913 __free_pages_ok(page, compound_order(page));
74914 }
74915@@ -697,6 +697,10 @@ static bool free_pages_prepare(struct page *page, unsigned int order)
74916 int i;
74917 int bad = 0;
74918
74919+#ifdef CONFIG_PAX_MEMORY_SANITIZE
74920+ unsigned long index = 1UL << order;
74921+#endif
74922+
74923 trace_mm_page_free(page, order);
74924 kmemcheck_free_shadow(page, order);
74925
74926@@ -712,6 +716,12 @@ static bool free_pages_prepare(struct page *page, unsigned int order)
74927 debug_check_no_obj_freed(page_address(page),
74928 PAGE_SIZE << order);
74929 }
74930+
74931+#ifdef CONFIG_PAX_MEMORY_SANITIZE
74932+ for (; index; --index)
74933+ sanitize_highpage(page + index - 1);
74934+#endif
74935+
74936 arch_free_page(page, order);
74937 kernel_map_pages(page, 1 << order, 0);
74938
74939@@ -853,8 +863,10 @@ static int prep_new_page(struct page *page, int order, gfp_t gfp_flags)
74940 arch_alloc_page(page, order);
74941 kernel_map_pages(page, 1 << order, 1);
74942
74943+#ifndef CONFIG_PAX_MEMORY_SANITIZE
74944 if (gfp_flags & __GFP_ZERO)
74945 prep_zero_page(page, order, gfp_flags);
74946+#endif
74947
74948 if (order && (gfp_flags & __GFP_COMP))
74949 prep_compound_page(page, order);
74950@@ -3648,7 +3660,13 @@ static int pageblock_is_reserved(unsigned long start_pfn, unsigned long end_pfn)
74951 unsigned long pfn;
74952
74953 for (pfn = start_pfn; pfn < end_pfn; pfn++) {
74954+#ifdef CONFIG_X86_32
74955+ /* boot failures in VMware 8 on 32bit vanilla since
74956+ this change */
74957+ if (!pfn_valid(pfn) || PageReserved(pfn_to_page(pfn)))
74958+#else
74959 if (!pfn_valid_within(pfn) || PageReserved(pfn_to_page(pfn)))
74960+#endif
74961 return 1;
74962 }
74963 return 0;
74964diff --git a/mm/percpu.c b/mm/percpu.c
74965index bb4be74..a43ea85 100644
74966--- a/mm/percpu.c
74967+++ b/mm/percpu.c
74968@@ -122,7 +122,7 @@ static unsigned int pcpu_low_unit_cpu __read_mostly;
74969 static unsigned int pcpu_high_unit_cpu __read_mostly;
74970
74971 /* the address of the first chunk which starts with the kernel static area */
74972-void *pcpu_base_addr __read_mostly;
74973+void *pcpu_base_addr __read_only;
74974 EXPORT_SYMBOL_GPL(pcpu_base_addr);
74975
74976 static const int *pcpu_unit_map __read_mostly; /* cpu -> unit */
74977diff --git a/mm/process_vm_access.c b/mm/process_vm_access.c
74978index 926b466..b23df53 100644
74979--- a/mm/process_vm_access.c
74980+++ b/mm/process_vm_access.c
74981@@ -13,6 +13,7 @@
74982 #include <linux/uio.h>
74983 #include <linux/sched.h>
74984 #include <linux/highmem.h>
74985+#include <linux/security.h>
74986 #include <linux/ptrace.h>
74987 #include <linux/slab.h>
74988 #include <linux/syscalls.h>
74989@@ -258,19 +259,19 @@ static ssize_t process_vm_rw_core(pid_t pid, const struct iovec *lvec,
74990 size_t iov_l_curr_offset = 0;
74991 ssize_t iov_len;
74992
74993+ return -ENOSYS; // PaX: until properly audited
74994+
74995 /*
74996 * Work out how many pages of struct pages we're going to need
74997 * when eventually calling get_user_pages
74998 */
74999 for (i = 0; i < riovcnt; i++) {
75000 iov_len = rvec[i].iov_len;
75001- if (iov_len > 0) {
75002- nr_pages_iov = ((unsigned long)rvec[i].iov_base
75003- + iov_len)
75004- / PAGE_SIZE - (unsigned long)rvec[i].iov_base
75005- / PAGE_SIZE + 1;
75006- nr_pages = max(nr_pages, nr_pages_iov);
75007- }
75008+ if (iov_len <= 0)
75009+ continue;
75010+ nr_pages_iov = ((unsigned long)rvec[i].iov_base + iov_len) / PAGE_SIZE -
75011+ (unsigned long)rvec[i].iov_base / PAGE_SIZE + 1;
75012+ nr_pages = max(nr_pages, nr_pages_iov);
75013 }
75014
75015 if (nr_pages == 0)
75016@@ -298,6 +299,11 @@ static ssize_t process_vm_rw_core(pid_t pid, const struct iovec *lvec,
75017 goto free_proc_pages;
75018 }
75019
75020+ if (gr_handle_ptrace(task, vm_write ? PTRACE_POKETEXT : PTRACE_ATTACH)) {
75021+ rc = -EPERM;
75022+ goto put_task_struct;
75023+ }
75024+
75025 mm = mm_access(task, PTRACE_MODE_ATTACH);
75026 if (!mm || IS_ERR(mm)) {
75027 rc = IS_ERR(mm) ? PTR_ERR(mm) : -ESRCH;
75028diff --git a/mm/rmap.c b/mm/rmap.c
75029index aa95e59..b681a63 100644
75030--- a/mm/rmap.c
75031+++ b/mm/rmap.c
75032@@ -168,6 +168,10 @@ int anon_vma_prepare(struct vm_area_struct *vma)
75033 struct anon_vma *anon_vma = vma->anon_vma;
75034 struct anon_vma_chain *avc;
75035
75036+#ifdef CONFIG_PAX_SEGMEXEC
75037+ struct anon_vma_chain *avc_m = NULL;
75038+#endif
75039+
75040 might_sleep();
75041 if (unlikely(!anon_vma)) {
75042 struct mm_struct *mm = vma->vm_mm;
75043@@ -177,6 +181,12 @@ int anon_vma_prepare(struct vm_area_struct *vma)
75044 if (!avc)
75045 goto out_enomem;
75046
75047+#ifdef CONFIG_PAX_SEGMEXEC
75048+ avc_m = anon_vma_chain_alloc(GFP_KERNEL);
75049+ if (!avc_m)
75050+ goto out_enomem_free_avc;
75051+#endif
75052+
75053 anon_vma = find_mergeable_anon_vma(vma);
75054 allocated = NULL;
75055 if (!anon_vma) {
75056@@ -190,6 +200,18 @@ int anon_vma_prepare(struct vm_area_struct *vma)
75057 /* page_table_lock to protect against threads */
75058 spin_lock(&mm->page_table_lock);
75059 if (likely(!vma->anon_vma)) {
75060+
75061+#ifdef CONFIG_PAX_SEGMEXEC
75062+ struct vm_area_struct *vma_m = pax_find_mirror_vma(vma);
75063+
75064+ if (vma_m) {
75065+ BUG_ON(vma_m->anon_vma);
75066+ vma_m->anon_vma = anon_vma;
75067+ anon_vma_chain_link(vma_m, avc_m, anon_vma);
75068+ avc_m = NULL;
75069+ }
75070+#endif
75071+
75072 vma->anon_vma = anon_vma;
75073 anon_vma_chain_link(vma, avc, anon_vma);
75074 allocated = NULL;
75075@@ -200,12 +222,24 @@ int anon_vma_prepare(struct vm_area_struct *vma)
75076
75077 if (unlikely(allocated))
75078 put_anon_vma(allocated);
75079+
75080+#ifdef CONFIG_PAX_SEGMEXEC
75081+ if (unlikely(avc_m))
75082+ anon_vma_chain_free(avc_m);
75083+#endif
75084+
75085 if (unlikely(avc))
75086 anon_vma_chain_free(avc);
75087 }
75088 return 0;
75089
75090 out_enomem_free_avc:
75091+
75092+#ifdef CONFIG_PAX_SEGMEXEC
75093+ if (avc_m)
75094+ anon_vma_chain_free(avc_m);
75095+#endif
75096+
75097 anon_vma_chain_free(avc);
75098 out_enomem:
75099 return -ENOMEM;
75100@@ -241,7 +275,7 @@ static inline void unlock_anon_vma_root(struct anon_vma *root)
75101 * Attach the anon_vmas from src to dst.
75102 * Returns 0 on success, -ENOMEM on failure.
75103 */
75104-int anon_vma_clone(struct vm_area_struct *dst, struct vm_area_struct *src)
75105+int anon_vma_clone(struct vm_area_struct *dst, const struct vm_area_struct *src)
75106 {
75107 struct anon_vma_chain *avc, *pavc;
75108 struct anon_vma *root = NULL;
75109@@ -319,7 +353,7 @@ void anon_vma_moveto_tail(struct vm_area_struct *dst)
75110 * the corresponding VMA in the parent process is attached to.
75111 * Returns 0 on success, non-zero on failure.
75112 */
75113-int anon_vma_fork(struct vm_area_struct *vma, struct vm_area_struct *pvma)
75114+int anon_vma_fork(struct vm_area_struct *vma, const struct vm_area_struct *pvma)
75115 {
75116 struct anon_vma_chain *avc;
75117 struct anon_vma *anon_vma;
75118diff --git a/mm/shmem.c b/mm/shmem.c
75119index d2eeca1..92f3123 100644
75120--- a/mm/shmem.c
75121+++ b/mm/shmem.c
75122@@ -31,7 +31,7 @@
75123 #include <linux/export.h>
75124 #include <linux/swap.h>
75125
75126-static struct vfsmount *shm_mnt;
75127+struct vfsmount *shm_mnt;
75128
75129 #ifdef CONFIG_SHMEM
75130 /*
75131@@ -75,7 +75,7 @@ static struct vfsmount *shm_mnt;
75132 #define BOGO_DIRENT_SIZE 20
75133
75134 /* Symlink up to this size is kmalloc'ed instead of using a swappable page */
75135-#define SHORT_SYMLINK_LEN 128
75136+#define SHORT_SYMLINK_LEN 64
75137
75138 struct shmem_xattr {
75139 struct list_head list; /* anchored by shmem_inode_info->xattr_list */
75140@@ -2207,6 +2207,11 @@ static const struct xattr_handler *shmem_xattr_handlers[] = {
75141 static int shmem_xattr_validate(const char *name)
75142 {
75143 struct { const char *prefix; size_t len; } arr[] = {
75144+
75145+#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
75146+ { XATTR_USER_PREFIX, XATTR_USER_PREFIX_LEN},
75147+#endif
75148+
75149 { XATTR_SECURITY_PREFIX, XATTR_SECURITY_PREFIX_LEN },
75150 { XATTR_TRUSTED_PREFIX, XATTR_TRUSTED_PREFIX_LEN }
75151 };
75152@@ -2260,6 +2265,15 @@ static int shmem_setxattr(struct dentry *dentry, const char *name,
75153 if (err)
75154 return err;
75155
75156+#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
75157+ if (!strncmp(name, XATTR_USER_PREFIX, XATTR_USER_PREFIX_LEN)) {
75158+ if (strcmp(name, XATTR_NAME_PAX_FLAGS))
75159+ return -EOPNOTSUPP;
75160+ if (size > 8)
75161+ return -EINVAL;
75162+ }
75163+#endif
75164+
75165 if (size == 0)
75166 value = ""; /* empty EA, do not remove */
75167
75168@@ -2594,8 +2608,7 @@ int shmem_fill_super(struct super_block *sb, void *data, int silent)
75169 int err = -ENOMEM;
75170
75171 /* Round up to L1_CACHE_BYTES to resist false sharing */
75172- sbinfo = kzalloc(max((int)sizeof(struct shmem_sb_info),
75173- L1_CACHE_BYTES), GFP_KERNEL);
75174+ sbinfo = kzalloc(max(sizeof(struct shmem_sb_info), L1_CACHE_BYTES), GFP_KERNEL);
75175 if (!sbinfo)
75176 return -ENOMEM;
75177
75178diff --git a/mm/slab.c b/mm/slab.c
75179index d066037..5bb78d9 100644
75180--- a/mm/slab.c
75181+++ b/mm/slab.c
75182@@ -164,7 +164,7 @@ static bool pfmemalloc_active __read_mostly;
75183
75184 /* Legal flag mask for kmem_cache_create(). */
75185 #if DEBUG
75186-# define CREATE_MASK (SLAB_RED_ZONE | \
75187+# define CREATE_MASK (SLAB_USERCOPY | SLAB_RED_ZONE | \
75188 SLAB_POISON | SLAB_HWCACHE_ALIGN | \
75189 SLAB_CACHE_DMA | \
75190 SLAB_STORE_USER | \
75191@@ -172,7 +172,7 @@ static bool pfmemalloc_active __read_mostly;
75192 SLAB_DESTROY_BY_RCU | SLAB_MEM_SPREAD | \
75193 SLAB_DEBUG_OBJECTS | SLAB_NOLEAKTRACE | SLAB_NOTRACK)
75194 #else
75195-# define CREATE_MASK (SLAB_HWCACHE_ALIGN | \
75196+# define CREATE_MASK (SLAB_USERCOPY | SLAB_HWCACHE_ALIGN | \
75197 SLAB_CACHE_DMA | \
75198 SLAB_RECLAIM_ACCOUNT | SLAB_PANIC | \
75199 SLAB_DESTROY_BY_RCU | SLAB_MEM_SPREAD | \
75200@@ -322,7 +322,7 @@ struct kmem_list3 {
75201 * Need this for bootstrapping a per node allocator.
75202 */
75203 #define NUM_INIT_LISTS (3 * MAX_NUMNODES)
75204-static struct kmem_list3 __initdata initkmem_list3[NUM_INIT_LISTS];
75205+static struct kmem_list3 initkmem_list3[NUM_INIT_LISTS];
75206 #define CACHE_CACHE 0
75207 #define SIZE_AC MAX_NUMNODES
75208 #define SIZE_L3 (2 * MAX_NUMNODES)
75209@@ -423,10 +423,10 @@ static void kmem_list3_init(struct kmem_list3 *parent)
75210 if ((x)->max_freeable < i) \
75211 (x)->max_freeable = i; \
75212 } while (0)
75213-#define STATS_INC_ALLOCHIT(x) atomic_inc(&(x)->allochit)
75214-#define STATS_INC_ALLOCMISS(x) atomic_inc(&(x)->allocmiss)
75215-#define STATS_INC_FREEHIT(x) atomic_inc(&(x)->freehit)
75216-#define STATS_INC_FREEMISS(x) atomic_inc(&(x)->freemiss)
75217+#define STATS_INC_ALLOCHIT(x) atomic_inc_unchecked(&(x)->allochit)
75218+#define STATS_INC_ALLOCMISS(x) atomic_inc_unchecked(&(x)->allocmiss)
75219+#define STATS_INC_FREEHIT(x) atomic_inc_unchecked(&(x)->freehit)
75220+#define STATS_INC_FREEMISS(x) atomic_inc_unchecked(&(x)->freemiss)
75221 #else
75222 #define STATS_INC_ACTIVE(x) do { } while (0)
75223 #define STATS_DEC_ACTIVE(x) do { } while (0)
75224@@ -549,7 +549,7 @@ static inline void *index_to_obj(struct kmem_cache *cache, struct slab *slab,
75225 * reciprocal_divide(offset, cache->reciprocal_buffer_size)
75226 */
75227 static inline unsigned int obj_to_index(const struct kmem_cache *cache,
75228- const struct slab *slab, void *obj)
75229+ const struct slab *slab, const void *obj)
75230 {
75231 u32 offset = (obj - slab->s_mem);
75232 return reciprocal_divide(offset, cache->reciprocal_buffer_size);
75233@@ -570,12 +570,13 @@ EXPORT_SYMBOL(malloc_sizes);
75234 struct cache_names {
75235 char *name;
75236 char *name_dma;
75237+ char *name_usercopy;
75238 };
75239
75240 static struct cache_names __initdata cache_names[] = {
75241-#define CACHE(x) { .name = "size-" #x, .name_dma = "size-" #x "(DMA)" },
75242+#define CACHE(x) { .name = "size-" #x, .name_dma = "size-" #x "(DMA)", .name_usercopy = "size-" #x "(USERCOPY)" },
75243 #include <linux/kmalloc_sizes.h>
75244- {NULL,}
75245+ {NULL}
75246 #undef CACHE
75247 };
75248
75249@@ -736,6 +737,12 @@ static inline struct kmem_cache *__find_general_cachep(size_t size,
75250 if (unlikely(gfpflags & GFP_DMA))
75251 return csizep->cs_dmacachep;
75252 #endif
75253+
75254+#ifdef CONFIG_PAX_USERCOPY_SLABS
75255+ if (unlikely(gfpflags & GFP_USERCOPY))
75256+ return csizep->cs_usercopycachep;
75257+#endif
75258+
75259 return csizep->cs_cachep;
75260 }
75261
75262@@ -1684,7 +1691,7 @@ void __init kmem_cache_init(void)
75263 sizes[INDEX_AC].cs_cachep = __kmem_cache_create(names[INDEX_AC].name,
75264 sizes[INDEX_AC].cs_size,
75265 ARCH_KMALLOC_MINALIGN,
75266- ARCH_KMALLOC_FLAGS|SLAB_PANIC,
75267+ ARCH_KMALLOC_FLAGS|SLAB_PANIC|SLAB_USERCOPY,
75268 NULL);
75269
75270 if (INDEX_AC != INDEX_L3) {
75271@@ -1692,7 +1699,7 @@ void __init kmem_cache_init(void)
75272 __kmem_cache_create(names[INDEX_L3].name,
75273 sizes[INDEX_L3].cs_size,
75274 ARCH_KMALLOC_MINALIGN,
75275- ARCH_KMALLOC_FLAGS|SLAB_PANIC,
75276+ ARCH_KMALLOC_FLAGS|SLAB_PANIC|SLAB_USERCOPY,
75277 NULL);
75278 }
75279
75280@@ -1710,7 +1717,7 @@ void __init kmem_cache_init(void)
75281 sizes->cs_cachep = __kmem_cache_create(names->name,
75282 sizes->cs_size,
75283 ARCH_KMALLOC_MINALIGN,
75284- ARCH_KMALLOC_FLAGS|SLAB_PANIC,
75285+ ARCH_KMALLOC_FLAGS|SLAB_PANIC|SLAB_USERCOPY,
75286 NULL);
75287 }
75288 #ifdef CONFIG_ZONE_DMA
75289@@ -1722,6 +1729,16 @@ void __init kmem_cache_init(void)
75290 SLAB_PANIC,
75291 NULL);
75292 #endif
75293+
75294+#ifdef CONFIG_PAX_USERCOPY_SLABS
75295+ sizes->cs_usercopycachep = kmem_cache_create(
75296+ names->name_usercopy,
75297+ sizes->cs_size,
75298+ ARCH_KMALLOC_MINALIGN,
75299+ ARCH_KMALLOC_FLAGS|SLAB_PANIC|SLAB_USERCOPY,
75300+ NULL);
75301+#endif
75302+
75303 sizes++;
75304 names++;
75305 }
75306@@ -4467,10 +4484,10 @@ static int s_show(struct seq_file *m, void *p)
75307 }
75308 /* cpu stats */
75309 {
75310- unsigned long allochit = atomic_read(&cachep->allochit);
75311- unsigned long allocmiss = atomic_read(&cachep->allocmiss);
75312- unsigned long freehit = atomic_read(&cachep->freehit);
75313- unsigned long freemiss = atomic_read(&cachep->freemiss);
75314+ unsigned long allochit = atomic_read_unchecked(&cachep->allochit);
75315+ unsigned long allocmiss = atomic_read_unchecked(&cachep->allocmiss);
75316+ unsigned long freehit = atomic_read_unchecked(&cachep->freehit);
75317+ unsigned long freemiss = atomic_read_unchecked(&cachep->freemiss);
75318
75319 seq_printf(m, " : cpustat %6lu %6lu %6lu %6lu",
75320 allochit, allocmiss, freehit, freemiss);
75321@@ -4729,13 +4746,71 @@ static int __init slab_proc_init(void)
75322 {
75323 proc_create("slabinfo",S_IWUSR|S_IRUSR,NULL,&proc_slabinfo_operations);
75324 #ifdef CONFIG_DEBUG_SLAB_LEAK
75325- proc_create("slab_allocators", 0, NULL, &proc_slabstats_operations);
75326+ proc_create("slab_allocators", S_IRUSR, NULL, &proc_slabstats_operations);
75327 #endif
75328 return 0;
75329 }
75330 module_init(slab_proc_init);
75331 #endif
75332
75333+bool is_usercopy_object(const void *ptr)
75334+{
75335+ struct page *page;
75336+ struct kmem_cache *cachep;
75337+
75338+ if (ZERO_OR_NULL_PTR(ptr))
75339+ return false;
75340+
75341+ if (!slab_is_available())
75342+ return false;
75343+
75344+ if (!virt_addr_valid(ptr))
75345+ return false;
75346+
75347+ page = virt_to_head_page(ptr);
75348+
75349+ if (!PageSlab(page))
75350+ return false;
75351+
75352+ cachep = page_get_cache(page);
75353+ return cachep->flags & SLAB_USERCOPY;
75354+}
75355+
75356+#ifdef CONFIG_PAX_USERCOPY
75357+const char *check_heap_object(const void *ptr, unsigned long n, bool to)
75358+{
75359+ struct page *page;
75360+ struct kmem_cache *cachep;
75361+ struct slab *slabp;
75362+ unsigned int objnr;
75363+ unsigned long offset;
75364+
75365+ if (ZERO_OR_NULL_PTR(ptr))
75366+ return "<null>";
75367+
75368+ if (!virt_addr_valid(ptr))
75369+ return NULL;
75370+
75371+ page = virt_to_head_page(ptr);
75372+
75373+ if (!PageSlab(page))
75374+ return NULL;
75375+
75376+ cachep = page_get_cache(page);
75377+ if (!(cachep->flags & SLAB_USERCOPY))
75378+ return cachep->name;
75379+
75380+ slabp = page->slab_page;
75381+ objnr = obj_to_index(cachep, slabp, ptr);
75382+ BUG_ON(objnr >= cachep->num);
75383+ offset = ptr - index_to_obj(cachep, slabp, objnr) - obj_offset(cachep);
75384+ if (offset <= cachep->object_size && n <= cachep->object_size - offset)
75385+ return NULL;
75386+
75387+ return cachep->name;
75388+}
75389+#endif
75390+
75391 /**
75392 * ksize - get the actual amount of memory allocated for a given object
75393 * @objp: Pointer to the object
75394diff --git a/mm/slob.c b/mm/slob.c
75395index 45d4ca7..88943c1 100644
75396--- a/mm/slob.c
75397+++ b/mm/slob.c
75398@@ -159,7 +159,7 @@ static void set_slob(slob_t *s, slobidx_t size, slob_t *next)
75399 /*
75400 * Return the size of a slob block.
75401 */
75402-static slobidx_t slob_units(slob_t *s)
75403+static slobidx_t slob_units(const slob_t *s)
75404 {
75405 if (s->units > 0)
75406 return s->units;
75407@@ -169,7 +169,7 @@ static slobidx_t slob_units(slob_t *s)
75408 /*
75409 * Return the next free slob block pointer after this one.
75410 */
75411-static slob_t *slob_next(slob_t *s)
75412+static slob_t *slob_next(const slob_t *s)
75413 {
75414 slob_t *base = (slob_t *)((unsigned long)s & PAGE_MASK);
75415 slobidx_t next;
75416@@ -184,14 +184,14 @@ static slob_t *slob_next(slob_t *s)
75417 /*
75418 * Returns true if s is the last free block in its page.
75419 */
75420-static int slob_last(slob_t *s)
75421+static int slob_last(const slob_t *s)
75422 {
75423 return !((unsigned long)slob_next(s) & ~PAGE_MASK);
75424 }
75425
75426-static void *slob_new_pages(gfp_t gfp, int order, int node)
75427+static struct page *slob_new_pages(gfp_t gfp, unsigned int order, int node)
75428 {
75429- void *page;
75430+ struct page *page;
75431
75432 #ifdef CONFIG_NUMA
75433 if (node != -1)
75434@@ -203,14 +203,18 @@ static void *slob_new_pages(gfp_t gfp, int order, int node)
75435 if (!page)
75436 return NULL;
75437
75438- return page_address(page);
75439+ __SetPageSlab(page);
75440+ return page;
75441 }
75442
75443-static void slob_free_pages(void *b, int order)
75444+static void slob_free_pages(struct page *sp, int order)
75445 {
75446 if (current->reclaim_state)
75447 current->reclaim_state->reclaimed_slab += 1 << order;
75448- free_pages((unsigned long)b, order);
75449+ __ClearPageSlab(sp);
75450+ reset_page_mapcount(sp);
75451+ sp->private = 0;
75452+ __free_pages(sp, order);
75453 }
75454
75455 /*
75456@@ -315,15 +319,15 @@ static void *slob_alloc(size_t size, gfp_t gfp, int align, int node)
75457
75458 /* Not enough space: must allocate a new page */
75459 if (!b) {
75460- b = slob_new_pages(gfp & ~__GFP_ZERO, 0, node);
75461- if (!b)
75462+ sp = slob_new_pages(gfp & ~__GFP_ZERO, 0, node);
75463+ if (!sp)
75464 return NULL;
75465- sp = virt_to_page(b);
75466- __SetPageSlab(sp);
75467+ b = page_address(sp);
75468
75469 spin_lock_irqsave(&slob_lock, flags);
75470 sp->units = SLOB_UNITS(PAGE_SIZE);
75471 sp->freelist = b;
75472+ sp->private = 0;
75473 INIT_LIST_HEAD(&sp->list);
75474 set_slob(b, SLOB_UNITS(PAGE_SIZE), b + SLOB_UNITS(PAGE_SIZE));
75475 set_slob_page_free(sp, slob_list);
75476@@ -361,9 +365,7 @@ static void slob_free(void *block, int size)
75477 if (slob_page_free(sp))
75478 clear_slob_page_free(sp);
75479 spin_unlock_irqrestore(&slob_lock, flags);
75480- __ClearPageSlab(sp);
75481- reset_page_mapcount(sp);
75482- slob_free_pages(b, 0);
75483+ slob_free_pages(sp, 0);
75484 return;
75485 }
75486
75487@@ -425,11 +427,10 @@ out:
75488 * End of slob allocator proper. Begin kmem_cache_alloc and kmalloc frontend.
75489 */
75490
75491-void *__kmalloc_node(size_t size, gfp_t gfp, int node)
75492+static void *__kmalloc_node_align(size_t size, gfp_t gfp, int node, int align)
75493 {
75494- unsigned int *m;
75495- int align = max(ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
75496- void *ret;
75497+ slob_t *m;
75498+ void *ret = NULL;
75499
75500 gfp &= gfp_allowed_mask;
75501
75502@@ -443,20 +444,23 @@ void *__kmalloc_node(size_t size, gfp_t gfp, int node)
75503
75504 if (!m)
75505 return NULL;
75506- *m = size;
75507+ BUILD_BUG_ON(ARCH_KMALLOC_MINALIGN < 2 * SLOB_UNIT);
75508+ BUILD_BUG_ON(ARCH_SLAB_MINALIGN < 2 * SLOB_UNIT);
75509+ m[0].units = size;
75510+ m[1].units = align;
75511 ret = (void *)m + align;
75512
75513 trace_kmalloc_node(_RET_IP_, ret,
75514 size, size + align, gfp, node);
75515 } else {
75516 unsigned int order = get_order(size);
75517+ struct page *page;
75518
75519 if (likely(order))
75520 gfp |= __GFP_COMP;
75521- ret = slob_new_pages(gfp, order, node);
75522- if (ret) {
75523- struct page *page;
75524- page = virt_to_page(ret);
75525+ page = slob_new_pages(gfp, order, node);
75526+ if (page) {
75527+ ret = page_address(page);
75528 page->private = size;
75529 }
75530
75531@@ -464,7 +468,16 @@ void *__kmalloc_node(size_t size, gfp_t gfp, int node)
75532 size, PAGE_SIZE << order, gfp, node);
75533 }
75534
75535- kmemleak_alloc(ret, size, 1, gfp);
75536+ return ret;
75537+}
75538+
75539+void *__kmalloc_node(size_t size, gfp_t gfp, int node)
75540+{
75541+ int align = max(ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
75542+ void *ret = __kmalloc_node_align(size, gfp, node, align);
75543+
75544+ if (!ZERO_OR_NULL_PTR(ret))
75545+ kmemleak_alloc(ret, size, 1, gfp);
75546 return ret;
75547 }
75548 EXPORT_SYMBOL(__kmalloc_node);
75549@@ -480,15 +493,91 @@ void kfree(const void *block)
75550 kmemleak_free(block);
75551
75552 sp = virt_to_page(block);
75553- if (PageSlab(sp)) {
75554+ VM_BUG_ON(!PageSlab(sp));
75555+ if (!sp->private) {
75556 int align = max(ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
75557- unsigned int *m = (unsigned int *)(block - align);
75558- slob_free(m, *m + align);
75559- } else
75560+ slob_t *m = (slob_t *)(block - align);
75561+ slob_free(m, m[0].units + align);
75562+ } else {
75563+ __ClearPageSlab(sp);
75564+ reset_page_mapcount(sp);
75565+ sp->private = 0;
75566 put_page(sp);
75567+ }
75568 }
75569 EXPORT_SYMBOL(kfree);
75570
75571+bool is_usercopy_object(const void *ptr)
75572+{
75573+ if (!slab_is_available())
75574+ return false;
75575+
75576+ // PAX: TODO
75577+
75578+ return false;
75579+}
75580+
75581+#ifdef CONFIG_PAX_USERCOPY
75582+const char *check_heap_object(const void *ptr, unsigned long n, bool to)
75583+{
75584+ struct page *page;
75585+ const slob_t *free;
75586+ const void *base;
75587+ unsigned long flags;
75588+
75589+ if (ZERO_OR_NULL_PTR(ptr))
75590+ return "<null>";
75591+
75592+ if (!virt_addr_valid(ptr))
75593+ return NULL;
75594+
75595+ page = virt_to_head_page(ptr);
75596+ if (!PageSlab(page))
75597+ return NULL;
75598+
75599+ if (page->private) {
75600+ base = page;
75601+ if (base <= ptr && n <= page->private - (ptr - base))
75602+ return NULL;
75603+ return "<slob>";
75604+ }
75605+
75606+ /* some tricky double walking to find the chunk */
75607+ spin_lock_irqsave(&slob_lock, flags);
75608+ base = (void *)((unsigned long)ptr & PAGE_MASK);
75609+ free = page->freelist;
75610+
75611+ while (!slob_last(free) && (void *)free <= ptr) {
75612+ base = free + slob_units(free);
75613+ free = slob_next(free);
75614+ }
75615+
75616+ while (base < (void *)free) {
75617+ slobidx_t m = ((slob_t *)base)[0].units, align = ((slob_t *)base)[1].units;
75618+ int size = SLOB_UNIT * SLOB_UNITS(m + align);
75619+ int offset;
75620+
75621+ if (ptr < base + align)
75622+ break;
75623+
75624+ offset = ptr - base - align;
75625+ if (offset >= m) {
75626+ base += size;
75627+ continue;
75628+ }
75629+
75630+ if (n > m - offset)
75631+ break;
75632+
75633+ spin_unlock_irqrestore(&slob_lock, flags);
75634+ return NULL;
75635+ }
75636+
75637+ spin_unlock_irqrestore(&slob_lock, flags);
75638+ return "<slob>";
75639+}
75640+#endif
75641+
75642 /* can't use ksize for kmem_cache_alloc memory, only kmalloc */
75643 size_t ksize(const void *block)
75644 {
75645@@ -499,10 +588,11 @@ size_t ksize(const void *block)
75646 return 0;
75647
75648 sp = virt_to_page(block);
75649- if (PageSlab(sp)) {
75650+ VM_BUG_ON(!PageSlab(sp));
75651+ if (!sp->private) {
75652 int align = max(ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
75653- unsigned int *m = (unsigned int *)(block - align);
75654- return SLOB_UNITS(*m) * SLOB_UNIT;
75655+ slob_t *m = (slob_t *)(block - align);
75656+ return SLOB_UNITS(m[0].units) * SLOB_UNIT;
75657 } else
75658 return sp->private;
75659 }
75660@@ -513,8 +603,13 @@ struct kmem_cache *__kmem_cache_create(const char *name, size_t size,
75661 {
75662 struct kmem_cache *c;
75663
75664+#ifdef CONFIG_PAX_USERCOPY_SLABS
75665+ c = __kmalloc_node_align(sizeof(struct kmem_cache),
75666+ GFP_KERNEL, -1, ARCH_KMALLOC_MINALIGN);
75667+#else
75668 c = slob_alloc(sizeof(struct kmem_cache),
75669 GFP_KERNEL, ARCH_KMALLOC_MINALIGN, -1);
75670+#endif
75671
75672 if (c) {
75673 c->name = name;
75674@@ -549,23 +644,33 @@ EXPORT_SYMBOL(kmem_cache_destroy);
75675
75676 void *kmem_cache_alloc_node(struct kmem_cache *c, gfp_t flags, int node)
75677 {
75678- void *b;
75679+ void *b = NULL;
75680
75681 flags &= gfp_allowed_mask;
75682
75683 lockdep_trace_alloc(flags);
75684
75685+#ifdef CONFIG_PAX_USERCOPY_SLABS
75686+ b = __kmalloc_node_align(c->size, flags, node, c->align);
75687+#else
75688 if (c->size < PAGE_SIZE) {
75689 b = slob_alloc(c->size, flags, c->align, node);
75690 trace_kmem_cache_alloc_node(_RET_IP_, b, c->size,
75691 SLOB_UNITS(c->size) * SLOB_UNIT,
75692 flags, node);
75693 } else {
75694- b = slob_new_pages(flags, get_order(c->size), node);
75695+ struct page *sp;
75696+
75697+ sp = slob_new_pages(flags, get_order(c->size), node);
75698+ if (sp) {
75699+ b = page_address(sp);
75700+ sp->private = c->size;
75701+ }
75702 trace_kmem_cache_alloc_node(_RET_IP_, b, c->size,
75703 PAGE_SIZE << get_order(c->size),
75704 flags, node);
75705 }
75706+#endif
75707
75708 if (c->ctor)
75709 c->ctor(b);
75710@@ -577,10 +682,14 @@ EXPORT_SYMBOL(kmem_cache_alloc_node);
75711
75712 static void __kmem_cache_free(void *b, int size)
75713 {
75714- if (size < PAGE_SIZE)
75715+ struct page *sp;
75716+
75717+ sp = virt_to_page(b);
75718+ BUG_ON(!PageSlab(sp));
75719+ if (!sp->private)
75720 slob_free(b, size);
75721 else
75722- slob_free_pages(b, get_order(size));
75723+ slob_free_pages(sp, get_order(size));
75724 }
75725
75726 static void kmem_rcu_free(struct rcu_head *head)
75727@@ -593,17 +702,31 @@ static void kmem_rcu_free(struct rcu_head *head)
75728
75729 void kmem_cache_free(struct kmem_cache *c, void *b)
75730 {
75731+ int size = c->size;
75732+
75733+#ifdef CONFIG_PAX_USERCOPY_SLABS
75734+ if (size + c->align < PAGE_SIZE) {
75735+ size += c->align;
75736+ b -= c->align;
75737+ }
75738+#endif
75739+
75740 kmemleak_free_recursive(b, c->flags);
75741 if (unlikely(c->flags & SLAB_DESTROY_BY_RCU)) {
75742 struct slob_rcu *slob_rcu;
75743- slob_rcu = b + (c->size - sizeof(struct slob_rcu));
75744- slob_rcu->size = c->size;
75745+ slob_rcu = b + (size - sizeof(struct slob_rcu));
75746+ slob_rcu->size = size;
75747 call_rcu(&slob_rcu->head, kmem_rcu_free);
75748 } else {
75749- __kmem_cache_free(b, c->size);
75750+ __kmem_cache_free(b, size);
75751 }
75752
75753+#ifdef CONFIG_PAX_USERCOPY_SLABS
75754+ trace_kfree(_RET_IP_, b);
75755+#else
75756 trace_kmem_cache_free(_RET_IP_, b);
75757+#endif
75758+
75759 }
75760 EXPORT_SYMBOL(kmem_cache_free);
75761
75762diff --git a/mm/slub.c b/mm/slub.c
75763index 2fdd96f..1e2f893 100644
75764--- a/mm/slub.c
75765+++ b/mm/slub.c
75766@@ -201,7 +201,7 @@ struct track {
75767
75768 enum track_item { TRACK_ALLOC, TRACK_FREE };
75769
75770-#ifdef CONFIG_SYSFS
75771+#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
75772 static int sysfs_slab_add(struct kmem_cache *);
75773 static int sysfs_slab_alias(struct kmem_cache *, const char *);
75774 static void sysfs_slab_remove(struct kmem_cache *);
75775@@ -525,7 +525,7 @@ static void print_track(const char *s, struct track *t)
75776 if (!t->addr)
75777 return;
75778
75779- printk(KERN_ERR "INFO: %s in %pS age=%lu cpu=%u pid=%d\n",
75780+ printk(KERN_ERR "INFO: %s in %pA age=%lu cpu=%u pid=%d\n",
75781 s, (void *)t->addr, jiffies - t->when, t->cpu, t->pid);
75782 #ifdef CONFIG_STACKTRACE
75783 {
75784@@ -2612,6 +2612,8 @@ void kmem_cache_free(struct kmem_cache *s, void *x)
75785
75786 page = virt_to_head_page(x);
75787
75788+ BUG_ON(!PageSlab(page));
75789+
75790 slab_free(s, page, x, _RET_IP_);
75791
75792 trace_kmem_cache_free(_RET_IP_, x);
75793@@ -2645,7 +2647,7 @@ static int slub_min_objects;
75794 * Merge control. If this is set then no merging of slab caches will occur.
75795 * (Could be removed. This was introduced to pacify the merge skeptics.)
75796 */
75797-static int slub_nomerge;
75798+static int slub_nomerge = 1;
75799
75800 /*
75801 * Calculate the order of allocation given an slab object size.
75802@@ -3098,7 +3100,7 @@ static int kmem_cache_open(struct kmem_cache *s,
75803 else
75804 s->cpu_partial = 30;
75805
75806- s->refcount = 1;
75807+ atomic_set(&s->refcount, 1);
75808 #ifdef CONFIG_NUMA
75809 s->remote_node_defrag_ratio = 1000;
75810 #endif
75811@@ -3202,8 +3204,7 @@ static inline int kmem_cache_close(struct kmem_cache *s)
75812 void kmem_cache_destroy(struct kmem_cache *s)
75813 {
75814 mutex_lock(&slab_mutex);
75815- s->refcount--;
75816- if (!s->refcount) {
75817+ if (atomic_dec_and_test(&s->refcount)) {
75818 list_del(&s->list);
75819 mutex_unlock(&slab_mutex);
75820 if (kmem_cache_close(s)) {
75821@@ -3232,6 +3233,10 @@ static struct kmem_cache *kmem_cache;
75822 static struct kmem_cache *kmalloc_dma_caches[SLUB_PAGE_SHIFT];
75823 #endif
75824
75825+#ifdef CONFIG_PAX_USERCOPY_SLABS
75826+static struct kmem_cache *kmalloc_usercopy_caches[SLUB_PAGE_SHIFT];
75827+#endif
75828+
75829 static int __init setup_slub_min_order(char *str)
75830 {
75831 get_option(&str, &slub_min_order);
75832@@ -3346,6 +3351,13 @@ static struct kmem_cache *get_slab(size_t size, gfp_t flags)
75833 return kmalloc_dma_caches[index];
75834
75835 #endif
75836+
75837+#ifdef CONFIG_PAX_USERCOPY_SLABS
75838+ if (flags & SLAB_USERCOPY)
75839+ return kmalloc_usercopy_caches[index];
75840+
75841+#endif
75842+
75843 return kmalloc_caches[index];
75844 }
75845
75846@@ -3414,6 +3426,59 @@ void *__kmalloc_node(size_t size, gfp_t flags, int node)
75847 EXPORT_SYMBOL(__kmalloc_node);
75848 #endif
75849
75850+bool is_usercopy_object(const void *ptr)
75851+{
75852+ struct page *page;
75853+ struct kmem_cache *s;
75854+
75855+ if (ZERO_OR_NULL_PTR(ptr))
75856+ return false;
75857+
75858+ if (!slab_is_available())
75859+ return false;
75860+
75861+ if (!virt_addr_valid(ptr))
75862+ return false;
75863+
75864+ page = virt_to_head_page(ptr);
75865+
75866+ if (!PageSlab(page))
75867+ return false;
75868+
75869+ s = page->slab;
75870+ return s->flags & SLAB_USERCOPY;
75871+}
75872+
75873+#ifdef CONFIG_PAX_USERCOPY
75874+const char *check_heap_object(const void *ptr, unsigned long n, bool to)
75875+{
75876+ struct page *page;
75877+ struct kmem_cache *s;
75878+ unsigned long offset;
75879+
75880+ if (ZERO_OR_NULL_PTR(ptr))
75881+ return "<null>";
75882+
75883+ if (!virt_addr_valid(ptr))
75884+ return NULL;
75885+
75886+ page = virt_to_head_page(ptr);
75887+
75888+ if (!PageSlab(page))
75889+ return NULL;
75890+
75891+ s = page->slab;
75892+ if (!(s->flags & SLAB_USERCOPY))
75893+ return s->name;
75894+
75895+ offset = (ptr - page_address(page)) % s->size;
75896+ if (offset <= s->object_size && n <= s->object_size - offset)
75897+ return NULL;
75898+
75899+ return s->name;
75900+}
75901+#endif
75902+
75903 size_t ksize(const void *object)
75904 {
75905 struct page *page;
75906@@ -3688,7 +3753,7 @@ static void __init kmem_cache_bootstrap_fixup(struct kmem_cache *s)
75907 int node;
75908
75909 list_add(&s->list, &slab_caches);
75910- s->refcount = -1;
75911+ atomic_set(&s->refcount, -1);
75912
75913 for_each_node_state(node, N_NORMAL_MEMORY) {
75914 struct kmem_cache_node *n = get_node(s, node);
75915@@ -3808,17 +3873,17 @@ void __init kmem_cache_init(void)
75916
75917 /* Caches that are not of the two-to-the-power-of size */
75918 if (KMALLOC_MIN_SIZE <= 32) {
75919- kmalloc_caches[1] = create_kmalloc_cache("kmalloc-96", 96, 0);
75920+ kmalloc_caches[1] = create_kmalloc_cache("kmalloc-96", 96, SLAB_USERCOPY);
75921 caches++;
75922 }
75923
75924 if (KMALLOC_MIN_SIZE <= 64) {
75925- kmalloc_caches[2] = create_kmalloc_cache("kmalloc-192", 192, 0);
75926+ kmalloc_caches[2] = create_kmalloc_cache("kmalloc-192", 192, SLAB_USERCOPY);
75927 caches++;
75928 }
75929
75930 for (i = KMALLOC_SHIFT_LOW; i < SLUB_PAGE_SHIFT; i++) {
75931- kmalloc_caches[i] = create_kmalloc_cache("kmalloc", 1 << i, 0);
75932+ kmalloc_caches[i] = create_kmalloc_cache("kmalloc", 1 << i, SLAB_USERCOPY);
75933 caches++;
75934 }
75935
75936@@ -3860,6 +3925,22 @@ void __init kmem_cache_init(void)
75937 }
75938 }
75939 #endif
75940+
75941+#ifdef CONFIG_PAX_USERCOPY_SLABS
75942+ for (i = 0; i < SLUB_PAGE_SHIFT; i++) {
75943+ struct kmem_cache *s = kmalloc_caches[i];
75944+
75945+ if (s && s->size) {
75946+ char *name = kasprintf(GFP_NOWAIT,
75947+ "usercopy-kmalloc-%d", s->object_size);
75948+
75949+ BUG_ON(!name);
75950+ kmalloc_usercopy_caches[i] = create_kmalloc_cache(name,
75951+ s->object_size, SLAB_USERCOPY);
75952+ }
75953+ }
75954+#endif
75955+
75956 printk(KERN_INFO
75957 "SLUB: Genslabs=%d, HWalign=%d, Order=%d-%d, MinObjects=%d,"
75958 " CPUs=%d, Nodes=%d\n",
75959@@ -3886,7 +3967,7 @@ static int slab_unmergeable(struct kmem_cache *s)
75960 /*
75961 * We may have set a slab to be unmergeable during bootstrap.
75962 */
75963- if (s->refcount < 0)
75964+ if (atomic_read(&s->refcount) < 0)
75965 return 1;
75966
75967 return 0;
75968@@ -3941,7 +4022,7 @@ struct kmem_cache *__kmem_cache_create(const char *name, size_t size,
75969
75970 s = find_mergeable(size, align, flags, name, ctor);
75971 if (s) {
75972- s->refcount++;
75973+ atomic_inc(&s->refcount);
75974 /*
75975 * Adjust the object sizes so that we clear
75976 * the complete object on kzalloc.
75977@@ -3950,7 +4031,7 @@ struct kmem_cache *__kmem_cache_create(const char *name, size_t size,
75978 s->inuse = max_t(int, s->inuse, ALIGN(size, sizeof(void *)));
75979
75980 if (sysfs_slab_alias(s, name)) {
75981- s->refcount--;
75982+ atomic_dec(&s->refcount);
75983 return NULL;
75984 }
75985 return s;
75986@@ -4072,7 +4153,7 @@ void *__kmalloc_node_track_caller(size_t size, gfp_t gfpflags,
75987 }
75988 #endif
75989
75990-#ifdef CONFIG_SYSFS
75991+#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
75992 static int count_inuse(struct page *page)
75993 {
75994 return page->inuse;
75995@@ -4459,12 +4540,12 @@ static void resiliency_test(void)
75996 validate_slab_cache(kmalloc_caches[9]);
75997 }
75998 #else
75999-#ifdef CONFIG_SYSFS
76000+#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
76001 static void resiliency_test(void) {};
76002 #endif
76003 #endif
76004
76005-#ifdef CONFIG_SYSFS
76006+#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
76007 enum slab_stat_type {
76008 SL_ALL, /* All slabs */
76009 SL_PARTIAL, /* Only partially allocated slabs */
76010@@ -4708,7 +4789,7 @@ SLAB_ATTR_RO(ctor);
76011
76012 static ssize_t aliases_show(struct kmem_cache *s, char *buf)
76013 {
76014- return sprintf(buf, "%d\n", s->refcount - 1);
76015+ return sprintf(buf, "%d\n", atomic_read(&s->refcount) - 1);
76016 }
76017 SLAB_ATTR_RO(aliases);
76018
76019@@ -5279,6 +5360,7 @@ static char *create_unique_id(struct kmem_cache *s)
76020 return name;
76021 }
76022
76023+#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
76024 static int sysfs_slab_add(struct kmem_cache *s)
76025 {
76026 int err;
76027@@ -5341,6 +5423,7 @@ static void sysfs_slab_remove(struct kmem_cache *s)
76028 kobject_del(&s->kobj);
76029 kobject_put(&s->kobj);
76030 }
76031+#endif
76032
76033 /*
76034 * Need to buffer aliases during bootup until sysfs becomes
76035@@ -5354,6 +5437,7 @@ struct saved_alias {
76036
76037 static struct saved_alias *alias_list;
76038
76039+#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
76040 static int sysfs_slab_alias(struct kmem_cache *s, const char *name)
76041 {
76042 struct saved_alias *al;
76043@@ -5376,6 +5460,7 @@ static int sysfs_slab_alias(struct kmem_cache *s, const char *name)
76044 alias_list = al;
76045 return 0;
76046 }
76047+#endif
76048
76049 static int __init slab_sysfs_init(void)
76050 {
76051diff --git a/mm/sparse-vmemmap.c b/mm/sparse-vmemmap.c
76052index 1b7e22a..3fcd4f3 100644
76053--- a/mm/sparse-vmemmap.c
76054+++ b/mm/sparse-vmemmap.c
76055@@ -128,7 +128,7 @@ pud_t * __meminit vmemmap_pud_populate(pgd_t *pgd, unsigned long addr, int node)
76056 void *p = vmemmap_alloc_block(PAGE_SIZE, node);
76057 if (!p)
76058 return NULL;
76059- pud_populate(&init_mm, pud, p);
76060+ pud_populate_kernel(&init_mm, pud, p);
76061 }
76062 return pud;
76063 }
76064@@ -140,7 +140,7 @@ pgd_t * __meminit vmemmap_pgd_populate(unsigned long addr, int node)
76065 void *p = vmemmap_alloc_block(PAGE_SIZE, node);
76066 if (!p)
76067 return NULL;
76068- pgd_populate(&init_mm, pgd, p);
76069+ pgd_populate_kernel(&init_mm, pgd, p);
76070 }
76071 return pgd;
76072 }
76073diff --git a/mm/swap.c b/mm/swap.c
76074index 7782588..228c784 100644
76075--- a/mm/swap.c
76076+++ b/mm/swap.c
76077@@ -30,6 +30,7 @@
76078 #include <linux/backing-dev.h>
76079 #include <linux/memcontrol.h>
76080 #include <linux/gfp.h>
76081+#include <linux/hugetlb.h>
76082
76083 #include "internal.h"
76084
76085@@ -72,6 +73,8 @@ static void __put_compound_page(struct page *page)
76086
76087 __page_cache_release(page);
76088 dtor = get_compound_page_dtor(page);
76089+ if (!PageHuge(page))
76090+ BUG_ON(dtor != free_compound_page);
76091 (*dtor)(page);
76092 }
76093
76094diff --git a/mm/swapfile.c b/mm/swapfile.c
76095index 14e254c..a6af32c 100644
76096--- a/mm/swapfile.c
76097+++ b/mm/swapfile.c
76098@@ -64,7 +64,7 @@ static DEFINE_MUTEX(swapon_mutex);
76099
76100 static DECLARE_WAIT_QUEUE_HEAD(proc_poll_wait);
76101 /* Activity counter to indicate that a swapon or swapoff has occurred */
76102-static atomic_t proc_poll_event = ATOMIC_INIT(0);
76103+static atomic_unchecked_t proc_poll_event = ATOMIC_INIT(0);
76104
76105 static inline unsigned char swap_count(unsigned char ent)
76106 {
76107@@ -1603,7 +1603,7 @@ SYSCALL_DEFINE1(swapoff, const char __user *, specialfile)
76108 }
76109 filp_close(swap_file, NULL);
76110 err = 0;
76111- atomic_inc(&proc_poll_event);
76112+ atomic_inc_unchecked(&proc_poll_event);
76113 wake_up_interruptible(&proc_poll_wait);
76114
76115 out_dput:
76116@@ -1619,8 +1619,8 @@ static unsigned swaps_poll(struct file *file, poll_table *wait)
76117
76118 poll_wait(file, &proc_poll_wait, wait);
76119
76120- if (seq->poll_event != atomic_read(&proc_poll_event)) {
76121- seq->poll_event = atomic_read(&proc_poll_event);
76122+ if (seq->poll_event != atomic_read_unchecked(&proc_poll_event)) {
76123+ seq->poll_event = atomic_read_unchecked(&proc_poll_event);
76124 return POLLIN | POLLRDNORM | POLLERR | POLLPRI;
76125 }
76126
76127@@ -1718,7 +1718,7 @@ static int swaps_open(struct inode *inode, struct file *file)
76128 return ret;
76129
76130 seq = file->private_data;
76131- seq->poll_event = atomic_read(&proc_poll_event);
76132+ seq->poll_event = atomic_read_unchecked(&proc_poll_event);
76133 return 0;
76134 }
76135
76136@@ -2060,7 +2060,7 @@ SYSCALL_DEFINE2(swapon, const char __user *, specialfile, int, swap_flags)
76137 (frontswap_map) ? "FS" : "");
76138
76139 mutex_unlock(&swapon_mutex);
76140- atomic_inc(&proc_poll_event);
76141+ atomic_inc_unchecked(&proc_poll_event);
76142 wake_up_interruptible(&proc_poll_wait);
76143
76144 if (S_ISREG(inode->i_mode))
76145diff --git a/mm/util.c b/mm/util.c
76146index 8c7265a..c96d884 100644
76147--- a/mm/util.c
76148+++ b/mm/util.c
76149@@ -285,6 +285,12 @@ done:
76150 void arch_pick_mmap_layout(struct mm_struct *mm)
76151 {
76152 mm->mmap_base = TASK_UNMAPPED_BASE;
76153+
76154+#ifdef CONFIG_PAX_RANDMMAP
76155+ if (mm->pax_flags & MF_PAX_RANDMMAP)
76156+ mm->mmap_base += mm->delta_mmap;
76157+#endif
76158+
76159 mm->get_unmapped_area = arch_get_unmapped_area;
76160 mm->unmap_area = arch_unmap_area;
76161 }
76162diff --git a/mm/vmalloc.c b/mm/vmalloc.c
76163index 2bb90b1..3795e47 100644
76164--- a/mm/vmalloc.c
76165+++ b/mm/vmalloc.c
76166@@ -39,8 +39,19 @@ static void vunmap_pte_range(pmd_t *pmd, unsigned long addr, unsigned long end)
76167
76168 pte = pte_offset_kernel(pmd, addr);
76169 do {
76170- pte_t ptent = ptep_get_and_clear(&init_mm, addr, pte);
76171- WARN_ON(!pte_none(ptent) && !pte_present(ptent));
76172+
76173+#if defined(CONFIG_MODULES) && defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
76174+ if ((unsigned long)MODULES_EXEC_VADDR <= addr && addr < (unsigned long)MODULES_EXEC_END) {
76175+ BUG_ON(!pte_exec(*pte));
76176+ set_pte_at(&init_mm, addr, pte, pfn_pte(__pa(addr) >> PAGE_SHIFT, PAGE_KERNEL_EXEC));
76177+ continue;
76178+ }
76179+#endif
76180+
76181+ {
76182+ pte_t ptent = ptep_get_and_clear(&init_mm, addr, pte);
76183+ WARN_ON(!pte_none(ptent) && !pte_present(ptent));
76184+ }
76185 } while (pte++, addr += PAGE_SIZE, addr != end);
76186 }
76187
76188@@ -100,16 +111,29 @@ static int vmap_pte_range(pmd_t *pmd, unsigned long addr,
76189 pte = pte_alloc_kernel(pmd, addr);
76190 if (!pte)
76191 return -ENOMEM;
76192+
76193+ pax_open_kernel();
76194 do {
76195 struct page *page = pages[*nr];
76196
76197- if (WARN_ON(!pte_none(*pte)))
76198+#if defined(CONFIG_MODULES) && defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
76199+ if (pgprot_val(prot) & _PAGE_NX)
76200+#endif
76201+
76202+ if (!pte_none(*pte)) {
76203+ pax_close_kernel();
76204+ WARN_ON(1);
76205 return -EBUSY;
76206- if (WARN_ON(!page))
76207+ }
76208+ if (!page) {
76209+ pax_close_kernel();
76210+ WARN_ON(1);
76211 return -ENOMEM;
76212+ }
76213 set_pte_at(&init_mm, addr, pte, mk_pte(page, prot));
76214 (*nr)++;
76215 } while (pte++, addr += PAGE_SIZE, addr != end);
76216+ pax_close_kernel();
76217 return 0;
76218 }
76219
76220@@ -119,7 +143,7 @@ static int vmap_pmd_range(pud_t *pud, unsigned long addr,
76221 pmd_t *pmd;
76222 unsigned long next;
76223
76224- pmd = pmd_alloc(&init_mm, pud, addr);
76225+ pmd = pmd_alloc_kernel(&init_mm, pud, addr);
76226 if (!pmd)
76227 return -ENOMEM;
76228 do {
76229@@ -136,7 +160,7 @@ static int vmap_pud_range(pgd_t *pgd, unsigned long addr,
76230 pud_t *pud;
76231 unsigned long next;
76232
76233- pud = pud_alloc(&init_mm, pgd, addr);
76234+ pud = pud_alloc_kernel(&init_mm, pgd, addr);
76235 if (!pud)
76236 return -ENOMEM;
76237 do {
76238@@ -191,11 +215,20 @@ int is_vmalloc_or_module_addr(const void *x)
76239 * and fall back on vmalloc() if that fails. Others
76240 * just put it in the vmalloc space.
76241 */
76242-#if defined(CONFIG_MODULES) && defined(MODULES_VADDR)
76243+#ifdef CONFIG_MODULES
76244+#ifdef MODULES_VADDR
76245 unsigned long addr = (unsigned long)x;
76246 if (addr >= MODULES_VADDR && addr < MODULES_END)
76247 return 1;
76248 #endif
76249+
76250+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
76251+ if (x >= (const void *)MODULES_EXEC_VADDR && x < (const void *)MODULES_EXEC_END)
76252+ return 1;
76253+#endif
76254+
76255+#endif
76256+
76257 return is_vmalloc_addr(x);
76258 }
76259
76260@@ -216,8 +249,14 @@ struct page *vmalloc_to_page(const void *vmalloc_addr)
76261
76262 if (!pgd_none(*pgd)) {
76263 pud_t *pud = pud_offset(pgd, addr);
76264+#ifdef CONFIG_X86
76265+ if (!pud_large(*pud))
76266+#endif
76267 if (!pud_none(*pud)) {
76268 pmd_t *pmd = pmd_offset(pud, addr);
76269+#ifdef CONFIG_X86
76270+ if (!pmd_large(*pmd))
76271+#endif
76272 if (!pmd_none(*pmd)) {
76273 pte_t *ptep, pte;
76274
76275@@ -329,7 +368,7 @@ static void purge_vmap_area_lazy(void);
76276 * Allocate a region of KVA of the specified size and alignment, within the
76277 * vstart and vend.
76278 */
76279-static struct vmap_area *alloc_vmap_area(unsigned long size,
76280+static __size_overflow(1) struct vmap_area *alloc_vmap_area(unsigned long size,
76281 unsigned long align,
76282 unsigned long vstart, unsigned long vend,
76283 int node, gfp_t gfp_mask)
76284@@ -1328,6 +1367,16 @@ static struct vm_struct *__get_vm_area_node(unsigned long size,
76285 struct vm_struct *area;
76286
76287 BUG_ON(in_interrupt());
76288+
76289+#if defined(CONFIG_MODULES) && defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
76290+ if (flags & VM_KERNEXEC) {
76291+ if (start != VMALLOC_START || end != VMALLOC_END)
76292+ return NULL;
76293+ start = (unsigned long)MODULES_EXEC_VADDR;
76294+ end = (unsigned long)MODULES_EXEC_END;
76295+ }
76296+#endif
76297+
76298 if (flags & VM_IOREMAP) {
76299 int bit = fls(size);
76300
76301@@ -1568,6 +1617,11 @@ void *vmap(struct page **pages, unsigned int count,
76302 if (count > totalram_pages)
76303 return NULL;
76304
76305+#if defined(CONFIG_MODULES) && defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
76306+ if (!(pgprot_val(prot) & _PAGE_NX))
76307+ flags |= VM_KERNEXEC;
76308+#endif
76309+
76310 area = get_vm_area_caller((count << PAGE_SHIFT), flags,
76311 __builtin_return_address(0));
76312 if (!area)
76313@@ -1669,6 +1723,13 @@ void *__vmalloc_node_range(unsigned long size, unsigned long align,
76314 if (!size || (size >> PAGE_SHIFT) > totalram_pages)
76315 goto fail;
76316
76317+#if defined(CONFIG_MODULES) && defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
76318+ if (!(pgprot_val(prot) & _PAGE_NX))
76319+ area = __get_vm_area_node(size, align, VM_ALLOC | VM_UNLIST | VM_KERNEXEC,
76320+ VMALLOC_START, VMALLOC_END, node, gfp_mask, caller);
76321+ else
76322+#endif
76323+
76324 area = __get_vm_area_node(size, align, VM_ALLOC | VM_UNLIST,
76325 start, end, node, gfp_mask, caller);
76326 if (!area)
76327@@ -1842,10 +1903,9 @@ EXPORT_SYMBOL(vzalloc_node);
76328 * For tight control over page level allocator and protection flags
76329 * use __vmalloc() instead.
76330 */
76331-
76332 void *vmalloc_exec(unsigned long size)
76333 {
76334- return __vmalloc_node(size, 1, GFP_KERNEL | __GFP_HIGHMEM, PAGE_KERNEL_EXEC,
76335+ return __vmalloc_node(size, 1, GFP_KERNEL | __GFP_HIGHMEM | __GFP_ZERO, PAGE_KERNEL_EXEC,
76336 -1, __builtin_return_address(0));
76337 }
76338
76339@@ -2136,6 +2196,8 @@ int remap_vmalloc_range(struct vm_area_struct *vma, void *addr,
76340 unsigned long uaddr = vma->vm_start;
76341 unsigned long usize = vma->vm_end - vma->vm_start;
76342
76343+ BUG_ON(vma->vm_mirror);
76344+
76345 if ((PAGE_SIZE-1) & (unsigned long)addr)
76346 return -EINVAL;
76347
76348@@ -2572,7 +2634,7 @@ static int s_show(struct seq_file *m, void *p)
76349 {
76350 struct vm_struct *v = p;
76351
76352- seq_printf(m, "0x%p-0x%p %7ld",
76353+ seq_printf(m, "0x%pK-0x%pK %7ld",
76354 v->addr, v->addr + v->size, v->size);
76355
76356 if (v->caller)
76357diff --git a/mm/vmscan.c b/mm/vmscan.c
76358index 99b434b..a018dfc 100644
76359--- a/mm/vmscan.c
76360+++ b/mm/vmscan.c
76361@@ -2953,6 +2953,8 @@ static int kswapd(void *p)
76362 &balanced_classzone_idx);
76363 }
76364 }
76365+
76366+ current->reclaim_state = NULL;
76367 return 0;
76368 }
76369
76370diff --git a/mm/vmstat.c b/mm/vmstat.c
76371index df7a674..8b4a4f3 100644
76372--- a/mm/vmstat.c
76373+++ b/mm/vmstat.c
76374@@ -78,7 +78,7 @@ void vm_events_fold_cpu(int cpu)
76375 *
76376 * vm_stat contains the global counters
76377 */
76378-atomic_long_t vm_stat[NR_VM_ZONE_STAT_ITEMS] __cacheline_aligned_in_smp;
76379+atomic_long_unchecked_t vm_stat[NR_VM_ZONE_STAT_ITEMS] __cacheline_aligned_in_smp;
76380 EXPORT_SYMBOL(vm_stat);
76381
76382 #ifdef CONFIG_SMP
76383@@ -454,7 +454,7 @@ void refresh_cpu_vm_stats(int cpu)
76384 v = p->vm_stat_diff[i];
76385 p->vm_stat_diff[i] = 0;
76386 local_irq_restore(flags);
76387- atomic_long_add(v, &zone->vm_stat[i]);
76388+ atomic_long_add_unchecked(v, &zone->vm_stat[i]);
76389 global_diff[i] += v;
76390 #ifdef CONFIG_NUMA
76391 /* 3 seconds idle till flush */
76392@@ -492,7 +492,7 @@ void refresh_cpu_vm_stats(int cpu)
76393
76394 for (i = 0; i < NR_VM_ZONE_STAT_ITEMS; i++)
76395 if (global_diff[i])
76396- atomic_long_add(global_diff[i], &vm_stat[i]);
76397+ atomic_long_add_unchecked(global_diff[i], &vm_stat[i]);
76398 }
76399
76400 #endif
76401@@ -1212,10 +1212,20 @@ static int __init setup_vmstat(void)
76402 start_cpu_timer(cpu);
76403 #endif
76404 #ifdef CONFIG_PROC_FS
76405- proc_create("buddyinfo", S_IRUGO, NULL, &fragmentation_file_operations);
76406- proc_create("pagetypeinfo", S_IRUGO, NULL, &pagetypeinfo_file_ops);
76407- proc_create("vmstat", S_IRUGO, NULL, &proc_vmstat_file_operations);
76408- proc_create("zoneinfo", S_IRUGO, NULL, &proc_zoneinfo_file_operations);
76409+ {
76410+ mode_t gr_mode = S_IRUGO;
76411+#ifdef CONFIG_GRKERNSEC_PROC_ADD
76412+ gr_mode = S_IRUSR;
76413+#endif
76414+ proc_create("buddyinfo", gr_mode, NULL, &fragmentation_file_operations);
76415+ proc_create("pagetypeinfo", gr_mode, NULL, &pagetypeinfo_file_ops);
76416+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
76417+ proc_create("vmstat", gr_mode | S_IRGRP, NULL, &proc_vmstat_file_operations);
76418+#else
76419+ proc_create("vmstat", gr_mode, NULL, &proc_vmstat_file_operations);
76420+#endif
76421+ proc_create("zoneinfo", gr_mode, NULL, &proc_zoneinfo_file_operations);
76422+ }
76423 #endif
76424 return 0;
76425 }
76426diff --git a/net/8021q/vlan.c b/net/8021q/vlan.c
76427index 9096bcb..43ed7bb 100644
76428--- a/net/8021q/vlan.c
76429+++ b/net/8021q/vlan.c
76430@@ -557,8 +557,7 @@ static int vlan_ioctl_handler(struct net *net, void __user *arg)
76431 err = -EPERM;
76432 if (!capable(CAP_NET_ADMIN))
76433 break;
76434- if ((args.u.name_type >= 0) &&
76435- (args.u.name_type < VLAN_NAME_TYPE_HIGHEST)) {
76436+ if (args.u.name_type < VLAN_NAME_TYPE_HIGHEST) {
76437 struct vlan_net *vn;
76438
76439 vn = net_generic(net, vlan_net_id);
76440diff --git a/net/9p/trans_fd.c b/net/9p/trans_fd.c
76441index 6449bae..8c1f454 100644
76442--- a/net/9p/trans_fd.c
76443+++ b/net/9p/trans_fd.c
76444@@ -425,7 +425,7 @@ static int p9_fd_write(struct p9_client *client, void *v, int len)
76445 oldfs = get_fs();
76446 set_fs(get_ds());
76447 /* The cast to a user pointer is valid due to the set_fs() */
76448- ret = vfs_write(ts->wr, (__force void __user *)v, len, &ts->wr->f_pos);
76449+ ret = vfs_write(ts->wr, (void __force_user *)v, len, &ts->wr->f_pos);
76450 set_fs(oldfs);
76451
76452 if (ret <= 0 && ret != -ERESTARTSYS && ret != -EAGAIN)
76453diff --git a/net/atm/atm_misc.c b/net/atm/atm_misc.c
76454index 876fbe8..8bbea9f 100644
76455--- a/net/atm/atm_misc.c
76456+++ b/net/atm/atm_misc.c
76457@@ -17,7 +17,7 @@ int atm_charge(struct atm_vcc *vcc, int truesize)
76458 if (atomic_read(&sk_atm(vcc)->sk_rmem_alloc) <= sk_atm(vcc)->sk_rcvbuf)
76459 return 1;
76460 atm_return(vcc, truesize);
76461- atomic_inc(&vcc->stats->rx_drop);
76462+ atomic_inc_unchecked(&vcc->stats->rx_drop);
76463 return 0;
76464 }
76465 EXPORT_SYMBOL(atm_charge);
76466@@ -39,7 +39,7 @@ struct sk_buff *atm_alloc_charge(struct atm_vcc *vcc, int pdu_size,
76467 }
76468 }
76469 atm_return(vcc, guess);
76470- atomic_inc(&vcc->stats->rx_drop);
76471+ atomic_inc_unchecked(&vcc->stats->rx_drop);
76472 return NULL;
76473 }
76474 EXPORT_SYMBOL(atm_alloc_charge);
76475@@ -86,7 +86,7 @@ EXPORT_SYMBOL(atm_pcr_goal);
76476
76477 void sonet_copy_stats(struct k_sonet_stats *from, struct sonet_stats *to)
76478 {
76479-#define __HANDLE_ITEM(i) to->i = atomic_read(&from->i)
76480+#define __HANDLE_ITEM(i) to->i = atomic_read_unchecked(&from->i)
76481 __SONET_ITEMS
76482 #undef __HANDLE_ITEM
76483 }
76484@@ -94,7 +94,7 @@ EXPORT_SYMBOL(sonet_copy_stats);
76485
76486 void sonet_subtract_stats(struct k_sonet_stats *from, struct sonet_stats *to)
76487 {
76488-#define __HANDLE_ITEM(i) atomic_sub(to->i, &from->i)
76489+#define __HANDLE_ITEM(i) atomic_sub_unchecked(to->i,&from->i)
76490 __SONET_ITEMS
76491 #undef __HANDLE_ITEM
76492 }
76493diff --git a/net/atm/lec.h b/net/atm/lec.h
76494index a86aff9..3a0d6f6 100644
76495--- a/net/atm/lec.h
76496+++ b/net/atm/lec.h
76497@@ -48,7 +48,7 @@ struct lane2_ops {
76498 const u8 *tlvs, u32 sizeoftlvs);
76499 void (*associate_indicator) (struct net_device *dev, const u8 *mac_addr,
76500 const u8 *tlvs, u32 sizeoftlvs);
76501-};
76502+} __no_const;
76503
76504 /*
76505 * ATM LAN Emulation supports both LLC & Dix Ethernet EtherType
76506diff --git a/net/atm/mpc.h b/net/atm/mpc.h
76507index 0919a88..a23d54e 100644
76508--- a/net/atm/mpc.h
76509+++ b/net/atm/mpc.h
76510@@ -33,7 +33,7 @@ struct mpoa_client {
76511 struct mpc_parameters parameters; /* parameters for this client */
76512
76513 const struct net_device_ops *old_ops;
76514- struct net_device_ops new_ops;
76515+ net_device_ops_no_const new_ops;
76516 };
76517
76518
76519diff --git a/net/atm/proc.c b/net/atm/proc.c
76520index 0d020de..011c7bb 100644
76521--- a/net/atm/proc.c
76522+++ b/net/atm/proc.c
76523@@ -45,9 +45,9 @@ static void add_stats(struct seq_file *seq, const char *aal,
76524 const struct k_atm_aal_stats *stats)
76525 {
76526 seq_printf(seq, "%s ( %d %d %d %d %d )", aal,
76527- atomic_read(&stats->tx), atomic_read(&stats->tx_err),
76528- atomic_read(&stats->rx), atomic_read(&stats->rx_err),
76529- atomic_read(&stats->rx_drop));
76530+ atomic_read_unchecked(&stats->tx),atomic_read_unchecked(&stats->tx_err),
76531+ atomic_read_unchecked(&stats->rx),atomic_read_unchecked(&stats->rx_err),
76532+ atomic_read_unchecked(&stats->rx_drop));
76533 }
76534
76535 static void atm_dev_info(struct seq_file *seq, const struct atm_dev *dev)
76536diff --git a/net/atm/resources.c b/net/atm/resources.c
76537index 23f45ce..c748f1a 100644
76538--- a/net/atm/resources.c
76539+++ b/net/atm/resources.c
76540@@ -160,7 +160,7 @@ EXPORT_SYMBOL(atm_dev_deregister);
76541 static void copy_aal_stats(struct k_atm_aal_stats *from,
76542 struct atm_aal_stats *to)
76543 {
76544-#define __HANDLE_ITEM(i) to->i = atomic_read(&from->i)
76545+#define __HANDLE_ITEM(i) to->i = atomic_read_unchecked(&from->i)
76546 __AAL_STAT_ITEMS
76547 #undef __HANDLE_ITEM
76548 }
76549@@ -168,7 +168,7 @@ static void copy_aal_stats(struct k_atm_aal_stats *from,
76550 static void subtract_aal_stats(struct k_atm_aal_stats *from,
76551 struct atm_aal_stats *to)
76552 {
76553-#define __HANDLE_ITEM(i) atomic_sub(to->i, &from->i)
76554+#define __HANDLE_ITEM(i) atomic_sub_unchecked(to->i, &from->i)
76555 __AAL_STAT_ITEMS
76556 #undef __HANDLE_ITEM
76557 }
76558diff --git a/net/batman-adv/bat_iv_ogm.c b/net/batman-adv/bat_iv_ogm.c
76559index 469daab..262851c 100644
76560--- a/net/batman-adv/bat_iv_ogm.c
76561+++ b/net/batman-adv/bat_iv_ogm.c
76562@@ -62,7 +62,7 @@ static int batadv_iv_ogm_iface_enable(struct batadv_hard_iface *hard_iface)
76563
76564 /* randomize initial seqno to avoid collision */
76565 get_random_bytes(&random_seqno, sizeof(random_seqno));
76566- atomic_set(&hard_iface->seqno, random_seqno);
76567+ atomic_set_unchecked(&hard_iface->seqno, random_seqno);
76568
76569 hard_iface->packet_len = BATADV_OGM_HLEN;
76570 hard_iface->packet_buff = kmalloc(hard_iface->packet_len, GFP_ATOMIC);
76571@@ -600,8 +600,8 @@ static void batadv_iv_ogm_schedule(struct batadv_hard_iface *hard_iface)
76572
76573 /* change sequence number to network order */
76574 batadv_ogm_packet->seqno =
76575- htonl((uint32_t)atomic_read(&hard_iface->seqno));
76576- atomic_inc(&hard_iface->seqno);
76577+ htonl((uint32_t)atomic_read_unchecked(&hard_iface->seqno));
76578+ atomic_inc_unchecked(&hard_iface->seqno);
76579
76580 batadv_ogm_packet->ttvn = atomic_read(&bat_priv->ttvn);
76581 batadv_ogm_packet->tt_crc = htons(bat_priv->tt_crc);
76582@@ -1001,7 +1001,7 @@ static void batadv_iv_ogm_process(const struct ethhdr *ethhdr,
76583 return;
76584
76585 /* could be changed by schedule_own_packet() */
76586- if_incoming_seqno = atomic_read(&if_incoming->seqno);
76587+ if_incoming_seqno = atomic_read_unchecked(&if_incoming->seqno);
76588
76589 if (batadv_ogm_packet->flags & BATADV_DIRECTLINK)
76590 has_directlink_flag = 1;
76591diff --git a/net/batman-adv/hard-interface.c b/net/batman-adv/hard-interface.c
76592index 282bf6e..4b2603d 100644
76593--- a/net/batman-adv/hard-interface.c
76594+++ b/net/batman-adv/hard-interface.c
76595@@ -320,7 +320,7 @@ int batadv_hardif_enable_interface(struct batadv_hard_iface *hard_iface,
76596 hard_iface->batman_adv_ptype.dev = hard_iface->net_dev;
76597 dev_add_pack(&hard_iface->batman_adv_ptype);
76598
76599- atomic_set(&hard_iface->frag_seqno, 1);
76600+ atomic_set_unchecked(&hard_iface->frag_seqno, 1);
76601 batadv_info(hard_iface->soft_iface, "Adding interface: %s\n",
76602 hard_iface->net_dev->name);
76603
76604@@ -443,7 +443,7 @@ batadv_hardif_add_interface(struct net_device *net_dev)
76605 /* This can't be called via a bat_priv callback because
76606 * we have no bat_priv yet.
76607 */
76608- atomic_set(&hard_iface->seqno, 1);
76609+ atomic_set_unchecked(&hard_iface->seqno, 1);
76610 hard_iface->packet_buff = NULL;
76611
76612 return hard_iface;
76613diff --git a/net/batman-adv/soft-interface.c b/net/batman-adv/soft-interface.c
76614index 21c5357..768be1a 100644
76615--- a/net/batman-adv/soft-interface.c
76616+++ b/net/batman-adv/soft-interface.c
76617@@ -227,7 +227,7 @@ static int batadv_interface_tx(struct sk_buff *skb,
76618
76619 /* set broadcast sequence number */
76620 bcast_packet->seqno =
76621- htonl(atomic_inc_return(&bat_priv->bcast_seqno));
76622+ htonl(atomic_inc_return_unchecked(&bat_priv->bcast_seqno));
76623
76624 batadv_add_bcast_packet_to_list(bat_priv, skb, 1);
76625
76626@@ -407,7 +407,7 @@ struct net_device *batadv_softif_create(const char *name)
76627 atomic_set(&bat_priv->batman_queue_left, BATADV_BATMAN_QUEUE_LEN);
76628
76629 atomic_set(&bat_priv->mesh_state, BATADV_MESH_INACTIVE);
76630- atomic_set(&bat_priv->bcast_seqno, 1);
76631+ atomic_set_unchecked(&bat_priv->bcast_seqno, 1);
76632 atomic_set(&bat_priv->ttvn, 0);
76633 atomic_set(&bat_priv->tt_local_changes, 0);
76634 atomic_set(&bat_priv->tt_ogm_append_cnt, 0);
76635diff --git a/net/batman-adv/types.h b/net/batman-adv/types.h
76636index 12635fd..d99d837 100644
76637--- a/net/batman-adv/types.h
76638+++ b/net/batman-adv/types.h
76639@@ -33,8 +33,8 @@ struct batadv_hard_iface {
76640 int16_t if_num;
76641 char if_status;
76642 struct net_device *net_dev;
76643- atomic_t seqno;
76644- atomic_t frag_seqno;
76645+ atomic_unchecked_t seqno;
76646+ atomic_unchecked_t frag_seqno;
76647 unsigned char *packet_buff;
76648 int packet_len;
76649 struct kobject *hardif_obj;
76650@@ -176,7 +176,7 @@ struct batadv_priv {
76651 atomic_t orig_interval; /* uint */
76652 atomic_t hop_penalty; /* uint */
76653 atomic_t log_level; /* uint */
76654- atomic_t bcast_seqno;
76655+ atomic_unchecked_t bcast_seqno;
76656 atomic_t bcast_queue_left;
76657 atomic_t batman_queue_left;
76658 atomic_t ttvn; /* translation table version number */
76659diff --git a/net/batman-adv/unicast.c b/net/batman-adv/unicast.c
76660index 0016464..0ef3e53 100644
76661--- a/net/batman-adv/unicast.c
76662+++ b/net/batman-adv/unicast.c
76663@@ -269,7 +269,7 @@ int batadv_frag_send_skb(struct sk_buff *skb, struct batadv_priv *bat_priv,
76664 frag1->flags = BATADV_UNI_FRAG_HEAD | large_tail;
76665 frag2->flags = large_tail;
76666
76667- seqno = atomic_add_return(2, &hard_iface->frag_seqno);
76668+ seqno = atomic_add_return_unchecked(2, &hard_iface->frag_seqno);
76669 frag1->seqno = htons(seqno - 1);
76670 frag2->seqno = htons(seqno);
76671
76672diff --git a/net/bluetooth/hci_sock.c b/net/bluetooth/hci_sock.c
76673index d5ace1e..231c4bf 100644
76674--- a/net/bluetooth/hci_sock.c
76675+++ b/net/bluetooth/hci_sock.c
76676@@ -934,7 +934,7 @@ static int hci_sock_setsockopt(struct socket *sock, int level, int optname,
76677 uf.event_mask[1] = *((u32 *) f->event_mask + 1);
76678 }
76679
76680- len = min_t(unsigned int, len, sizeof(uf));
76681+ len = min((size_t)len, sizeof(uf));
76682 if (copy_from_user(&uf, optval, len)) {
76683 err = -EFAULT;
76684 break;
76685diff --git a/net/bluetooth/l2cap_core.c b/net/bluetooth/l2cap_core.c
76686index 38c00f1..e9d566e 100644
76687--- a/net/bluetooth/l2cap_core.c
76688+++ b/net/bluetooth/l2cap_core.c
76689@@ -3165,8 +3165,10 @@ static int l2cap_parse_conf_rsp(struct l2cap_chan *chan, void *rsp, int len, voi
76690 break;
76691
76692 case L2CAP_CONF_RFC:
76693- if (olen == sizeof(rfc))
76694- memcpy(&rfc, (void *)val, olen);
76695+ if (olen != sizeof(rfc))
76696+ break;
76697+
76698+ memcpy(&rfc, (void *)val, olen);
76699
76700 if (test_bit(CONF_STATE2_DEVICE, &chan->conf_state) &&
76701 rfc.mode != chan->mode)
76702diff --git a/net/bluetooth/l2cap_sock.c b/net/bluetooth/l2cap_sock.c
76703index 34bbe1c..451c19b 100644
76704--- a/net/bluetooth/l2cap_sock.c
76705+++ b/net/bluetooth/l2cap_sock.c
76706@@ -467,7 +467,8 @@ static int l2cap_sock_setsockopt_old(struct socket *sock, int optname, char __us
76707 struct sock *sk = sock->sk;
76708 struct l2cap_chan *chan = l2cap_pi(sk)->chan;
76709 struct l2cap_options opts;
76710- int len, err = 0;
76711+ int err = 0;
76712+ size_t len = optlen;
76713 u32 opt;
76714
76715 BT_DBG("sk %p", sk);
76716@@ -489,7 +490,7 @@ static int l2cap_sock_setsockopt_old(struct socket *sock, int optname, char __us
76717 opts.max_tx = chan->max_tx;
76718 opts.txwin_size = chan->tx_win;
76719
76720- len = min_t(unsigned int, sizeof(opts), optlen);
76721+ len = min(sizeof(opts), len);
76722 if (copy_from_user((char *) &opts, optval, len)) {
76723 err = -EFAULT;
76724 break;
76725@@ -567,7 +568,8 @@ static int l2cap_sock_setsockopt(struct socket *sock, int level, int optname, ch
76726 struct bt_security sec;
76727 struct bt_power pwr;
76728 struct l2cap_conn *conn;
76729- int len, err = 0;
76730+ int err = 0;
76731+ size_t len = optlen;
76732 u32 opt;
76733
76734 BT_DBG("sk %p", sk);
76735@@ -590,7 +592,7 @@ static int l2cap_sock_setsockopt(struct socket *sock, int level, int optname, ch
76736
76737 sec.level = BT_SECURITY_LOW;
76738
76739- len = min_t(unsigned int, sizeof(sec), optlen);
76740+ len = min(sizeof(sec), len);
76741 if (copy_from_user((char *) &sec, optval, len)) {
76742 err = -EFAULT;
76743 break;
76744@@ -687,7 +689,7 @@ static int l2cap_sock_setsockopt(struct socket *sock, int level, int optname, ch
76745
76746 pwr.force_active = BT_POWER_FORCE_ACTIVE_ON;
76747
76748- len = min_t(unsigned int, sizeof(pwr), optlen);
76749+ len = min(sizeof(pwr), len);
76750 if (copy_from_user((char *) &pwr, optval, len)) {
76751 err = -EFAULT;
76752 break;
76753diff --git a/net/bluetooth/rfcomm/sock.c b/net/bluetooth/rfcomm/sock.c
76754index 1a17850..65a3129 100644
76755--- a/net/bluetooth/rfcomm/sock.c
76756+++ b/net/bluetooth/rfcomm/sock.c
76757@@ -667,7 +667,7 @@ static int rfcomm_sock_setsockopt(struct socket *sock, int level, int optname, c
76758 struct sock *sk = sock->sk;
76759 struct bt_security sec;
76760 int err = 0;
76761- size_t len;
76762+ size_t len = optlen;
76763 u32 opt;
76764
76765 BT_DBG("sk %p", sk);
76766@@ -689,7 +689,7 @@ static int rfcomm_sock_setsockopt(struct socket *sock, int level, int optname, c
76767
76768 sec.level = BT_SECURITY_LOW;
76769
76770- len = min_t(unsigned int, sizeof(sec), optlen);
76771+ len = min(sizeof(sec), len);
76772 if (copy_from_user((char *) &sec, optval, len)) {
76773 err = -EFAULT;
76774 break;
76775diff --git a/net/bluetooth/rfcomm/tty.c b/net/bluetooth/rfcomm/tty.c
76776index 56f1823..da44330 100644
76777--- a/net/bluetooth/rfcomm/tty.c
76778+++ b/net/bluetooth/rfcomm/tty.c
76779@@ -309,7 +309,7 @@ static void rfcomm_dev_del(struct rfcomm_dev *dev)
76780 BUG_ON(test_and_set_bit(RFCOMM_TTY_RELEASED, &dev->flags));
76781
76782 spin_lock_irqsave(&dev->port.lock, flags);
76783- if (dev->port.count > 0) {
76784+ if (atomic_read(&dev->port.count) > 0) {
76785 spin_unlock_irqrestore(&dev->port.lock, flags);
76786 return;
76787 }
76788@@ -664,10 +664,10 @@ static int rfcomm_tty_open(struct tty_struct *tty, struct file *filp)
76789 return -ENODEV;
76790
76791 BT_DBG("dev %p dst %s channel %d opened %d", dev, batostr(&dev->dst),
76792- dev->channel, dev->port.count);
76793+ dev->channel, atomic_read(&dev->port.count));
76794
76795 spin_lock_irqsave(&dev->port.lock, flags);
76796- if (++dev->port.count > 1) {
76797+ if (atomic_inc_return(&dev->port.count) > 1) {
76798 spin_unlock_irqrestore(&dev->port.lock, flags);
76799 return 0;
76800 }
76801@@ -732,10 +732,10 @@ static void rfcomm_tty_close(struct tty_struct *tty, struct file *filp)
76802 return;
76803
76804 BT_DBG("tty %p dev %p dlc %p opened %d", tty, dev, dev->dlc,
76805- dev->port.count);
76806+ atomic_read(&dev->port.count));
76807
76808 spin_lock_irqsave(&dev->port.lock, flags);
76809- if (!--dev->port.count) {
76810+ if (!atomic_dec_return(&dev->port.count)) {
76811 spin_unlock_irqrestore(&dev->port.lock, flags);
76812 if (dev->tty_dev->parent)
76813 device_move(dev->tty_dev, NULL, DPM_ORDER_DEV_LAST);
76814diff --git a/net/bridge/netfilter/ebtables.c b/net/bridge/netfilter/ebtables.c
76815index 5fe2ff3..121d696 100644
76816--- a/net/bridge/netfilter/ebtables.c
76817+++ b/net/bridge/netfilter/ebtables.c
76818@@ -1523,7 +1523,7 @@ static int do_ebt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
76819 tmp.valid_hooks = t->table->valid_hooks;
76820 }
76821 mutex_unlock(&ebt_mutex);
76822- if (copy_to_user(user, &tmp, *len) != 0){
76823+ if (*len > sizeof(tmp) || copy_to_user(user, &tmp, *len) != 0){
76824 BUGPRINT("c2u Didn't work\n");
76825 ret = -EFAULT;
76826 break;
76827@@ -2327,7 +2327,7 @@ static int compat_do_ebt_get_ctl(struct sock *sk, int cmd,
76828 goto out;
76829 tmp.valid_hooks = t->valid_hooks;
76830
76831- if (copy_to_user(user, &tmp, *len) != 0) {
76832+ if (*len > sizeof(tmp) || copy_to_user(user, &tmp, *len) != 0) {
76833 ret = -EFAULT;
76834 break;
76835 }
76836@@ -2338,7 +2338,7 @@ static int compat_do_ebt_get_ctl(struct sock *sk, int cmd,
76837 tmp.entries_size = t->table->entries_size;
76838 tmp.valid_hooks = t->table->valid_hooks;
76839
76840- if (copy_to_user(user, &tmp, *len) != 0) {
76841+ if (*len > sizeof(tmp) || copy_to_user(user, &tmp, *len) != 0) {
76842 ret = -EFAULT;
76843 break;
76844 }
76845diff --git a/net/caif/cfctrl.c b/net/caif/cfctrl.c
76846index 44f270f..1f5602d 100644
76847--- a/net/caif/cfctrl.c
76848+++ b/net/caif/cfctrl.c
76849@@ -10,6 +10,7 @@
76850 #include <linux/spinlock.h>
76851 #include <linux/slab.h>
76852 #include <linux/pkt_sched.h>
76853+#include <linux/sched.h>
76854 #include <net/caif/caif_layer.h>
76855 #include <net/caif/cfpkt.h>
76856 #include <net/caif/cfctrl.h>
76857@@ -43,8 +44,8 @@ struct cflayer *cfctrl_create(void)
76858 memset(&dev_info, 0, sizeof(dev_info));
76859 dev_info.id = 0xff;
76860 cfsrvl_init(&this->serv, 0, &dev_info, false);
76861- atomic_set(&this->req_seq_no, 1);
76862- atomic_set(&this->rsp_seq_no, 1);
76863+ atomic_set_unchecked(&this->req_seq_no, 1);
76864+ atomic_set_unchecked(&this->rsp_seq_no, 1);
76865 this->serv.layer.receive = cfctrl_recv;
76866 sprintf(this->serv.layer.name, "ctrl");
76867 this->serv.layer.ctrlcmd = cfctrl_ctrlcmd;
76868@@ -130,8 +131,8 @@ static void cfctrl_insert_req(struct cfctrl *ctrl,
76869 struct cfctrl_request_info *req)
76870 {
76871 spin_lock_bh(&ctrl->info_list_lock);
76872- atomic_inc(&ctrl->req_seq_no);
76873- req->sequence_no = atomic_read(&ctrl->req_seq_no);
76874+ atomic_inc_unchecked(&ctrl->req_seq_no);
76875+ req->sequence_no = atomic_read_unchecked(&ctrl->req_seq_no);
76876 list_add_tail(&req->list, &ctrl->list);
76877 spin_unlock_bh(&ctrl->info_list_lock);
76878 }
76879@@ -149,7 +150,7 @@ static struct cfctrl_request_info *cfctrl_remove_req(struct cfctrl *ctrl,
76880 if (p != first)
76881 pr_warn("Requests are not received in order\n");
76882
76883- atomic_set(&ctrl->rsp_seq_no,
76884+ atomic_set_unchecked(&ctrl->rsp_seq_no,
76885 p->sequence_no);
76886 list_del(&p->list);
76887 goto out;
76888diff --git a/net/can/gw.c b/net/can/gw.c
76889index b54d5e6..91c3b25 100644
76890--- a/net/can/gw.c
76891+++ b/net/can/gw.c
76892@@ -96,7 +96,7 @@ struct cf_mod {
76893 struct {
76894 void (*xor)(struct can_frame *cf, struct cgw_csum_xor *xor);
76895 void (*crc8)(struct can_frame *cf, struct cgw_csum_crc8 *crc8);
76896- } csumfunc;
76897+ } __no_const csumfunc;
76898 };
76899
76900
76901diff --git a/net/compat.c b/net/compat.c
76902index 74ed1d7..3695bd9 100644
76903--- a/net/compat.c
76904+++ b/net/compat.c
76905@@ -71,9 +71,9 @@ int get_compat_msghdr(struct msghdr *kmsg, struct compat_msghdr __user *umsg)
76906 __get_user(kmsg->msg_controllen, &umsg->msg_controllen) ||
76907 __get_user(kmsg->msg_flags, &umsg->msg_flags))
76908 return -EFAULT;
76909- kmsg->msg_name = compat_ptr(tmp1);
76910- kmsg->msg_iov = compat_ptr(tmp2);
76911- kmsg->msg_control = compat_ptr(tmp3);
76912+ kmsg->msg_name = (void __force_kernel *)compat_ptr(tmp1);
76913+ kmsg->msg_iov = (void __force_kernel *)compat_ptr(tmp2);
76914+ kmsg->msg_control = (void __force_kernel *)compat_ptr(tmp3);
76915 return 0;
76916 }
76917
76918@@ -85,7 +85,7 @@ int verify_compat_iovec(struct msghdr *kern_msg, struct iovec *kern_iov,
76919
76920 if (kern_msg->msg_namelen) {
76921 if (mode == VERIFY_READ) {
76922- int err = move_addr_to_kernel(kern_msg->msg_name,
76923+ int err = move_addr_to_kernel((void __force_user *)kern_msg->msg_name,
76924 kern_msg->msg_namelen,
76925 kern_address);
76926 if (err < 0)
76927@@ -96,7 +96,7 @@ int verify_compat_iovec(struct msghdr *kern_msg, struct iovec *kern_iov,
76928 kern_msg->msg_name = NULL;
76929
76930 tot_len = iov_from_user_compat_to_kern(kern_iov,
76931- (struct compat_iovec __user *)kern_msg->msg_iov,
76932+ (struct compat_iovec __force_user *)kern_msg->msg_iov,
76933 kern_msg->msg_iovlen);
76934 if (tot_len >= 0)
76935 kern_msg->msg_iov = kern_iov;
76936@@ -116,20 +116,20 @@ int verify_compat_iovec(struct msghdr *kern_msg, struct iovec *kern_iov,
76937
76938 #define CMSG_COMPAT_FIRSTHDR(msg) \
76939 (((msg)->msg_controllen) >= sizeof(struct compat_cmsghdr) ? \
76940- (struct compat_cmsghdr __user *)((msg)->msg_control) : \
76941+ (struct compat_cmsghdr __force_user *)((msg)->msg_control) : \
76942 (struct compat_cmsghdr __user *)NULL)
76943
76944 #define CMSG_COMPAT_OK(ucmlen, ucmsg, mhdr) \
76945 ((ucmlen) >= sizeof(struct compat_cmsghdr) && \
76946 (ucmlen) <= (unsigned long) \
76947 ((mhdr)->msg_controllen - \
76948- ((char *)(ucmsg) - (char *)(mhdr)->msg_control)))
76949+ ((char __force_kernel *)(ucmsg) - (char *)(mhdr)->msg_control)))
76950
76951 static inline struct compat_cmsghdr __user *cmsg_compat_nxthdr(struct msghdr *msg,
76952 struct compat_cmsghdr __user *cmsg, int cmsg_len)
76953 {
76954 char __user *ptr = (char __user *)cmsg + CMSG_COMPAT_ALIGN(cmsg_len);
76955- if ((unsigned long)(ptr + 1 - (char __user *)msg->msg_control) >
76956+ if ((unsigned long)(ptr + 1 - (char __force_user *)msg->msg_control) >
76957 msg->msg_controllen)
76958 return NULL;
76959 return (struct compat_cmsghdr __user *)ptr;
76960@@ -219,7 +219,7 @@ Efault:
76961
76962 int put_cmsg_compat(struct msghdr *kmsg, int level, int type, int len, void *data)
76963 {
76964- struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __user *) kmsg->msg_control;
76965+ struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __force_user *) kmsg->msg_control;
76966 struct compat_cmsghdr cmhdr;
76967 struct compat_timeval ctv;
76968 struct compat_timespec cts[3];
76969@@ -275,7 +275,7 @@ int put_cmsg_compat(struct msghdr *kmsg, int level, int type, int len, void *dat
76970
76971 void scm_detach_fds_compat(struct msghdr *kmsg, struct scm_cookie *scm)
76972 {
76973- struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __user *) kmsg->msg_control;
76974+ struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __force_user *) kmsg->msg_control;
76975 int fdmax = (kmsg->msg_controllen - sizeof(struct compat_cmsghdr)) / sizeof(int);
76976 int fdnum = scm->fp->count;
76977 struct file **fp = scm->fp->fp;
76978@@ -364,7 +364,7 @@ static int do_set_sock_timeout(struct socket *sock, int level,
76979 return -EFAULT;
76980 old_fs = get_fs();
76981 set_fs(KERNEL_DS);
76982- err = sock_setsockopt(sock, level, optname, (char *)&ktime, sizeof(ktime));
76983+ err = sock_setsockopt(sock, level, optname, (char __force_user *)&ktime, sizeof(ktime));
76984 set_fs(old_fs);
76985
76986 return err;
76987@@ -425,7 +425,7 @@ static int do_get_sock_timeout(struct socket *sock, int level, int optname,
76988 len = sizeof(ktime);
76989 old_fs = get_fs();
76990 set_fs(KERNEL_DS);
76991- err = sock_getsockopt(sock, level, optname, (char *) &ktime, &len);
76992+ err = sock_getsockopt(sock, level, optname, (char __force_user *) &ktime, (int __force_user *)&len);
76993 set_fs(old_fs);
76994
76995 if (!err) {
76996@@ -568,7 +568,7 @@ int compat_mc_setsockopt(struct sock *sock, int level, int optname,
76997 case MCAST_JOIN_GROUP:
76998 case MCAST_LEAVE_GROUP:
76999 {
77000- struct compat_group_req __user *gr32 = (void *)optval;
77001+ struct compat_group_req __user *gr32 = (void __user *)optval;
77002 struct group_req __user *kgr =
77003 compat_alloc_user_space(sizeof(struct group_req));
77004 u32 interface;
77005@@ -589,7 +589,7 @@ int compat_mc_setsockopt(struct sock *sock, int level, int optname,
77006 case MCAST_BLOCK_SOURCE:
77007 case MCAST_UNBLOCK_SOURCE:
77008 {
77009- struct compat_group_source_req __user *gsr32 = (void *)optval;
77010+ struct compat_group_source_req __user *gsr32 = (void __user *)optval;
77011 struct group_source_req __user *kgsr = compat_alloc_user_space(
77012 sizeof(struct group_source_req));
77013 u32 interface;
77014@@ -610,7 +610,7 @@ int compat_mc_setsockopt(struct sock *sock, int level, int optname,
77015 }
77016 case MCAST_MSFILTER:
77017 {
77018- struct compat_group_filter __user *gf32 = (void *)optval;
77019+ struct compat_group_filter __user *gf32 = (void __user *)optval;
77020 struct group_filter __user *kgf;
77021 u32 interface, fmode, numsrc;
77022
77023@@ -648,7 +648,7 @@ int compat_mc_getsockopt(struct sock *sock, int level, int optname,
77024 char __user *optval, int __user *optlen,
77025 int (*getsockopt)(struct sock *, int, int, char __user *, int __user *))
77026 {
77027- struct compat_group_filter __user *gf32 = (void *)optval;
77028+ struct compat_group_filter __user *gf32 = (void __user *)optval;
77029 struct group_filter __user *kgf;
77030 int __user *koptlen;
77031 u32 interface, fmode, numsrc;
77032@@ -797,7 +797,7 @@ asmlinkage long compat_sys_socketcall(int call, u32 __user *args)
77033
77034 if (call < SYS_SOCKET || call > SYS_SENDMMSG)
77035 return -EINVAL;
77036- if (copy_from_user(a, args, nas[call]))
77037+ if (nas[call] > sizeof a || copy_from_user(a, args, nas[call]))
77038 return -EFAULT;
77039 a0 = a[0];
77040 a1 = a[1];
77041diff --git a/net/core/datagram.c b/net/core/datagram.c
77042index 0337e2b..47914a0 100644
77043--- a/net/core/datagram.c
77044+++ b/net/core/datagram.c
77045@@ -289,7 +289,7 @@ int skb_kill_datagram(struct sock *sk, struct sk_buff *skb, unsigned int flags)
77046 }
77047
77048 kfree_skb(skb);
77049- atomic_inc(&sk->sk_drops);
77050+ atomic_inc_unchecked(&sk->sk_drops);
77051 sk_mem_reclaim_partial(sk);
77052
77053 return err;
77054diff --git a/net/core/dev.c b/net/core/dev.c
77055index aed87a4..72cc526 100644
77056--- a/net/core/dev.c
77057+++ b/net/core/dev.c
77058@@ -1138,9 +1138,13 @@ void dev_load(struct net *net, const char *name)
77059 if (no_module && capable(CAP_NET_ADMIN))
77060 no_module = request_module("netdev-%s", name);
77061 if (no_module && capable(CAP_SYS_MODULE)) {
77062+#ifdef CONFIG_GRKERNSEC_MODHARDEN
77063+ ___request_module(true, "grsec_modharden_netdev", "%s", name);
77064+#else
77065 if (!request_module("%s", name))
77066 pr_warn("Loading kernel module for a network device with CAP_SYS_MODULE (deprecated). Use CAP_NET_ADMIN and alias netdev-%s instead.\n",
77067 name);
77068+#endif
77069 }
77070 }
77071 EXPORT_SYMBOL(dev_load);
77072@@ -1605,7 +1609,7 @@ int dev_forward_skb(struct net_device *dev, struct sk_buff *skb)
77073 {
77074 if (skb_shinfo(skb)->tx_flags & SKBTX_DEV_ZEROCOPY) {
77075 if (skb_copy_ubufs(skb, GFP_ATOMIC)) {
77076- atomic_long_inc(&dev->rx_dropped);
77077+ atomic_long_inc_unchecked(&dev->rx_dropped);
77078 kfree_skb(skb);
77079 return NET_RX_DROP;
77080 }
77081@@ -1615,7 +1619,7 @@ int dev_forward_skb(struct net_device *dev, struct sk_buff *skb)
77082 nf_reset(skb);
77083
77084 if (unlikely(!is_skb_forwardable(dev, skb))) {
77085- atomic_long_inc(&dev->rx_dropped);
77086+ atomic_long_inc_unchecked(&dev->rx_dropped);
77087 kfree_skb(skb);
77088 return NET_RX_DROP;
77089 }
77090@@ -2071,7 +2075,7 @@ static int illegal_highdma(struct net_device *dev, struct sk_buff *skb)
77091
77092 struct dev_gso_cb {
77093 void (*destructor)(struct sk_buff *skb);
77094-};
77095+} __no_const;
77096
77097 #define DEV_GSO_CB(skb) ((struct dev_gso_cb *)(skb)->cb)
77098
77099@@ -2928,7 +2932,7 @@ enqueue:
77100
77101 local_irq_restore(flags);
77102
77103- atomic_long_inc(&skb->dev->rx_dropped);
77104+ atomic_long_inc_unchecked(&skb->dev->rx_dropped);
77105 kfree_skb(skb);
77106 return NET_RX_DROP;
77107 }
77108@@ -3000,7 +3004,7 @@ int netif_rx_ni(struct sk_buff *skb)
77109 }
77110 EXPORT_SYMBOL(netif_rx_ni);
77111
77112-static void net_tx_action(struct softirq_action *h)
77113+static void net_tx_action(void)
77114 {
77115 struct softnet_data *sd = &__get_cpu_var(softnet_data);
77116
77117@@ -3331,7 +3335,7 @@ ncls:
77118 ret = pt_prev->func(skb, skb->dev, pt_prev, orig_dev);
77119 } else {
77120 drop:
77121- atomic_long_inc(&skb->dev->rx_dropped);
77122+ atomic_long_inc_unchecked(&skb->dev->rx_dropped);
77123 kfree_skb(skb);
77124 /* Jamal, now you will not able to escape explaining
77125 * me how you were going to use this. :-)
77126@@ -3898,7 +3902,7 @@ void netif_napi_del(struct napi_struct *napi)
77127 }
77128 EXPORT_SYMBOL(netif_napi_del);
77129
77130-static void net_rx_action(struct softirq_action *h)
77131+static void net_rx_action(void)
77132 {
77133 struct softnet_data *sd = &__get_cpu_var(softnet_data);
77134 unsigned long time_limit = jiffies + 2;
77135@@ -4368,8 +4372,13 @@ static int ptype_seq_show(struct seq_file *seq, void *v)
77136 else
77137 seq_printf(seq, "%04x", ntohs(pt->type));
77138
77139+#ifdef CONFIG_GRKERNSEC_HIDESYM
77140+ seq_printf(seq, " %-8s %p\n",
77141+ pt->dev ? pt->dev->name : "", NULL);
77142+#else
77143 seq_printf(seq, " %-8s %pF\n",
77144 pt->dev ? pt->dev->name : "", pt->func);
77145+#endif
77146 }
77147
77148 return 0;
77149@@ -5922,7 +5931,7 @@ struct rtnl_link_stats64 *dev_get_stats(struct net_device *dev,
77150 } else {
77151 netdev_stats_to_stats64(storage, &dev->stats);
77152 }
77153- storage->rx_dropped += atomic_long_read(&dev->rx_dropped);
77154+ storage->rx_dropped += atomic_long_read_unchecked(&dev->rx_dropped);
77155 return storage;
77156 }
77157 EXPORT_SYMBOL(dev_get_stats);
77158diff --git a/net/core/flow.c b/net/core/flow.c
77159index e318c7e..168b1d0 100644
77160--- a/net/core/flow.c
77161+++ b/net/core/flow.c
77162@@ -61,7 +61,7 @@ struct flow_cache {
77163 struct timer_list rnd_timer;
77164 };
77165
77166-atomic_t flow_cache_genid = ATOMIC_INIT(0);
77167+atomic_unchecked_t flow_cache_genid = ATOMIC_INIT(0);
77168 EXPORT_SYMBOL(flow_cache_genid);
77169 static struct flow_cache flow_cache_global;
77170 static struct kmem_cache *flow_cachep __read_mostly;
77171@@ -86,7 +86,7 @@ static void flow_cache_new_hashrnd(unsigned long arg)
77172
77173 static int flow_entry_valid(struct flow_cache_entry *fle)
77174 {
77175- if (atomic_read(&flow_cache_genid) != fle->genid)
77176+ if (atomic_read_unchecked(&flow_cache_genid) != fle->genid)
77177 return 0;
77178 if (fle->object && !fle->object->ops->check(fle->object))
77179 return 0;
77180@@ -259,7 +259,7 @@ flow_cache_lookup(struct net *net, const struct flowi *key, u16 family, u8 dir,
77181 hlist_add_head(&fle->u.hlist, &fcp->hash_table[hash]);
77182 fcp->hash_count++;
77183 }
77184- } else if (likely(fle->genid == atomic_read(&flow_cache_genid))) {
77185+ } else if (likely(fle->genid == atomic_read_unchecked(&flow_cache_genid))) {
77186 flo = fle->object;
77187 if (!flo)
77188 goto ret_object;
77189@@ -280,7 +280,7 @@ nocache:
77190 }
77191 flo = resolver(net, key, family, dir, flo, ctx);
77192 if (fle) {
77193- fle->genid = atomic_read(&flow_cache_genid);
77194+ fle->genid = atomic_read_unchecked(&flow_cache_genid);
77195 if (!IS_ERR(flo))
77196 fle->object = flo;
77197 else
77198diff --git a/net/core/iovec.c b/net/core/iovec.c
77199index 7e7aeb0..2a998cb 100644
77200--- a/net/core/iovec.c
77201+++ b/net/core/iovec.c
77202@@ -42,7 +42,7 @@ int verify_iovec(struct msghdr *m, struct iovec *iov, struct sockaddr_storage *a
77203 if (m->msg_namelen) {
77204 if (mode == VERIFY_READ) {
77205 void __user *namep;
77206- namep = (void __user __force *) m->msg_name;
77207+ namep = (void __force_user *) m->msg_name;
77208 err = move_addr_to_kernel(namep, m->msg_namelen,
77209 address);
77210 if (err < 0)
77211@@ -54,7 +54,7 @@ int verify_iovec(struct msghdr *m, struct iovec *iov, struct sockaddr_storage *a
77212 }
77213
77214 size = m->msg_iovlen * sizeof(struct iovec);
77215- if (copy_from_user(iov, (void __user __force *) m->msg_iov, size))
77216+ if (copy_from_user(iov, (void __force_user *) m->msg_iov, size))
77217 return -EFAULT;
77218
77219 m->msg_iov = iov;
77220diff --git a/net/core/rtnetlink.c b/net/core/rtnetlink.c
77221index 2c5a0a0..a45f90c 100644
77222--- a/net/core/rtnetlink.c
77223+++ b/net/core/rtnetlink.c
77224@@ -58,7 +58,7 @@ struct rtnl_link {
77225 rtnl_doit_func doit;
77226 rtnl_dumpit_func dumpit;
77227 rtnl_calcit_func calcit;
77228-};
77229+} __no_const;
77230
77231 static DEFINE_MUTEX(rtnl_mutex);
77232
77233diff --git a/net/core/scm.c b/net/core/scm.c
77234index 040cebe..5b1e312 100644
77235--- a/net/core/scm.c
77236+++ b/net/core/scm.c
77237@@ -203,7 +203,7 @@ EXPORT_SYMBOL(__scm_send);
77238 int put_cmsg(struct msghdr * msg, int level, int type, int len, void *data)
77239 {
77240 struct cmsghdr __user *cm
77241- = (__force struct cmsghdr __user *)msg->msg_control;
77242+ = (struct cmsghdr __force_user *)msg->msg_control;
77243 struct cmsghdr cmhdr;
77244 int cmlen = CMSG_LEN(len);
77245 int err;
77246@@ -226,7 +226,7 @@ int put_cmsg(struct msghdr * msg, int level, int type, int len, void *data)
77247 err = -EFAULT;
77248 if (copy_to_user(cm, &cmhdr, sizeof cmhdr))
77249 goto out;
77250- if (copy_to_user(CMSG_DATA(cm), data, cmlen - sizeof(struct cmsghdr)))
77251+ if (copy_to_user((void __force_user *)CMSG_DATA((void __force_kernel *)cm), data, cmlen - sizeof(struct cmsghdr)))
77252 goto out;
77253 cmlen = CMSG_SPACE(len);
77254 if (msg->msg_controllen < cmlen)
77255@@ -242,7 +242,7 @@ EXPORT_SYMBOL(put_cmsg);
77256 void scm_detach_fds(struct msghdr *msg, struct scm_cookie *scm)
77257 {
77258 struct cmsghdr __user *cm
77259- = (__force struct cmsghdr __user*)msg->msg_control;
77260+ = (struct cmsghdr __force_user *)msg->msg_control;
77261
77262 int fdmax = 0;
77263 int fdnum = scm->fp->count;
77264@@ -262,7 +262,7 @@ void scm_detach_fds(struct msghdr *msg, struct scm_cookie *scm)
77265 if (fdnum < fdmax)
77266 fdmax = fdnum;
77267
77268- for (i=0, cmfptr=(__force int __user *)CMSG_DATA(cm); i<fdmax;
77269+ for (i=0, cmfptr=(int __force_user *)CMSG_DATA((void __force_kernel *)cm); i<fdmax;
77270 i++, cmfptr++)
77271 {
77272 struct socket *sock;
77273diff --git a/net/core/sock.c b/net/core/sock.c
77274index a6000fb..d4aee72 100644
77275--- a/net/core/sock.c
77276+++ b/net/core/sock.c
77277@@ -399,7 +399,7 @@ int sock_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
77278 struct sk_buff_head *list = &sk->sk_receive_queue;
77279
77280 if (atomic_read(&sk->sk_rmem_alloc) >= sk->sk_rcvbuf) {
77281- atomic_inc(&sk->sk_drops);
77282+ atomic_inc_unchecked(&sk->sk_drops);
77283 trace_sock_rcvqueue_full(sk, skb);
77284 return -ENOMEM;
77285 }
77286@@ -409,7 +409,7 @@ int sock_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
77287 return err;
77288
77289 if (!sk_rmem_schedule(sk, skb, skb->truesize)) {
77290- atomic_inc(&sk->sk_drops);
77291+ atomic_inc_unchecked(&sk->sk_drops);
77292 return -ENOBUFS;
77293 }
77294
77295@@ -429,7 +429,7 @@ int sock_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
77296 skb_dst_force(skb);
77297
77298 spin_lock_irqsave(&list->lock, flags);
77299- skb->dropcount = atomic_read(&sk->sk_drops);
77300+ skb->dropcount = atomic_read_unchecked(&sk->sk_drops);
77301 __skb_queue_tail(list, skb);
77302 spin_unlock_irqrestore(&list->lock, flags);
77303
77304@@ -449,7 +449,7 @@ int sk_receive_skb(struct sock *sk, struct sk_buff *skb, const int nested)
77305 skb->dev = NULL;
77306
77307 if (sk_rcvqueues_full(sk, skb, sk->sk_rcvbuf)) {
77308- atomic_inc(&sk->sk_drops);
77309+ atomic_inc_unchecked(&sk->sk_drops);
77310 goto discard_and_relse;
77311 }
77312 if (nested)
77313@@ -467,7 +467,7 @@ int sk_receive_skb(struct sock *sk, struct sk_buff *skb, const int nested)
77314 mutex_release(&sk->sk_lock.dep_map, 1, _RET_IP_);
77315 } else if (sk_add_backlog(sk, skb, sk->sk_rcvbuf)) {
77316 bh_unlock_sock(sk);
77317- atomic_inc(&sk->sk_drops);
77318+ atomic_inc_unchecked(&sk->sk_drops);
77319 goto discard_and_relse;
77320 }
77321
77322@@ -886,12 +886,12 @@ int sock_getsockopt(struct socket *sock, int level, int optname,
77323 struct timeval tm;
77324 } v;
77325
77326- int lv = sizeof(int);
77327- int len;
77328+ unsigned int lv = sizeof(int);
77329+ unsigned int len;
77330
77331 if (get_user(len, optlen))
77332 return -EFAULT;
77333- if (len < 0)
77334+ if (len > INT_MAX)
77335 return -EINVAL;
77336
77337 memset(&v, 0, sizeof(v));
77338@@ -1039,11 +1039,11 @@ int sock_getsockopt(struct socket *sock, int level, int optname,
77339
77340 case SO_PEERNAME:
77341 {
77342- char address[128];
77343+ char address[_K_SS_MAXSIZE];
77344
77345 if (sock->ops->getname(sock, (struct sockaddr *)address, &lv, 2))
77346 return -ENOTCONN;
77347- if (lv < len)
77348+ if (lv < len || sizeof address < len)
77349 return -EINVAL;
77350 if (copy_to_user(optval, address, len))
77351 return -EFAULT;
77352@@ -1091,7 +1091,7 @@ int sock_getsockopt(struct socket *sock, int level, int optname,
77353
77354 if (len > lv)
77355 len = lv;
77356- if (copy_to_user(optval, &v, len))
77357+ if (len > sizeof(v) || copy_to_user(optval, &v, len))
77358 return -EFAULT;
77359 lenout:
77360 if (put_user(len, optlen))
77361@@ -2193,7 +2193,7 @@ void sock_init_data(struct socket *sock, struct sock *sk)
77362 */
77363 smp_wmb();
77364 atomic_set(&sk->sk_refcnt, 1);
77365- atomic_set(&sk->sk_drops, 0);
77366+ atomic_set_unchecked(&sk->sk_drops, 0);
77367 }
77368 EXPORT_SYMBOL(sock_init_data);
77369
77370diff --git a/net/core/sock_diag.c b/net/core/sock_diag.c
77371index 9d8755e..26de8bc 100644
77372--- a/net/core/sock_diag.c
77373+++ b/net/core/sock_diag.c
77374@@ -15,20 +15,27 @@ static DEFINE_MUTEX(sock_diag_table_mutex);
77375
77376 int sock_diag_check_cookie(void *sk, __u32 *cookie)
77377 {
77378+#ifndef CONFIG_GRKERNSEC_HIDESYM
77379 if ((cookie[0] != INET_DIAG_NOCOOKIE ||
77380 cookie[1] != INET_DIAG_NOCOOKIE) &&
77381 ((u32)(unsigned long)sk != cookie[0] ||
77382 (u32)((((unsigned long)sk) >> 31) >> 1) != cookie[1]))
77383 return -ESTALE;
77384 else
77385+#endif
77386 return 0;
77387 }
77388 EXPORT_SYMBOL_GPL(sock_diag_check_cookie);
77389
77390 void sock_diag_save_cookie(void *sk, __u32 *cookie)
77391 {
77392+#ifdef CONFIG_GRKERNSEC_HIDESYM
77393+ cookie[0] = 0;
77394+ cookie[1] = 0;
77395+#else
77396 cookie[0] = (u32)(unsigned long)sk;
77397 cookie[1] = (u32)(((unsigned long)sk >> 31) >> 1);
77398+#endif
77399 }
77400 EXPORT_SYMBOL_GPL(sock_diag_save_cookie);
77401
77402diff --git a/net/decnet/sysctl_net_decnet.c b/net/decnet/sysctl_net_decnet.c
77403index a55eecc..dd8428c 100644
77404--- a/net/decnet/sysctl_net_decnet.c
77405+++ b/net/decnet/sysctl_net_decnet.c
77406@@ -174,7 +174,7 @@ static int dn_node_address_handler(ctl_table *table, int write,
77407
77408 if (len > *lenp) len = *lenp;
77409
77410- if (copy_to_user(buffer, addr, len))
77411+ if (len > sizeof addr || copy_to_user(buffer, addr, len))
77412 return -EFAULT;
77413
77414 *lenp = len;
77415@@ -237,7 +237,7 @@ static int dn_def_dev_handler(ctl_table *table, int write,
77416
77417 if (len > *lenp) len = *lenp;
77418
77419- if (copy_to_user(buffer, devname, len))
77420+ if (len > sizeof devname || copy_to_user(buffer, devname, len))
77421 return -EFAULT;
77422
77423 *lenp = len;
77424diff --git a/net/ipv4/fib_frontend.c b/net/ipv4/fib_frontend.c
77425index f444ac7..b7bdda9 100644
77426--- a/net/ipv4/fib_frontend.c
77427+++ b/net/ipv4/fib_frontend.c
77428@@ -1020,12 +1020,12 @@ static int fib_inetaddr_event(struct notifier_block *this, unsigned long event,
77429 #ifdef CONFIG_IP_ROUTE_MULTIPATH
77430 fib_sync_up(dev);
77431 #endif
77432- atomic_inc(&net->ipv4.dev_addr_genid);
77433+ atomic_inc_unchecked(&net->ipv4.dev_addr_genid);
77434 rt_cache_flush(dev_net(dev));
77435 break;
77436 case NETDEV_DOWN:
77437 fib_del_ifaddr(ifa, NULL);
77438- atomic_inc(&net->ipv4.dev_addr_genid);
77439+ atomic_inc_unchecked(&net->ipv4.dev_addr_genid);
77440 if (ifa->ifa_dev->ifa_list == NULL) {
77441 /* Last address was deleted from this interface.
77442 * Disable IP.
77443@@ -1062,7 +1062,7 @@ static int fib_netdev_event(struct notifier_block *this, unsigned long event, vo
77444 #ifdef CONFIG_IP_ROUTE_MULTIPATH
77445 fib_sync_up(dev);
77446 #endif
77447- atomic_inc(&net->ipv4.dev_addr_genid);
77448+ atomic_inc_unchecked(&net->ipv4.dev_addr_genid);
77449 rt_cache_flush(dev_net(dev));
77450 break;
77451 case NETDEV_DOWN:
77452diff --git a/net/ipv4/fib_semantics.c b/net/ipv4/fib_semantics.c
77453index 9633661..4e0bc08 100644
77454--- a/net/ipv4/fib_semantics.c
77455+++ b/net/ipv4/fib_semantics.c
77456@@ -767,7 +767,7 @@ __be32 fib_info_update_nh_saddr(struct net *net, struct fib_nh *nh)
77457 nh->nh_saddr = inet_select_addr(nh->nh_dev,
77458 nh->nh_gw,
77459 nh->nh_parent->fib_scope);
77460- nh->nh_saddr_genid = atomic_read(&net->ipv4.dev_addr_genid);
77461+ nh->nh_saddr_genid = atomic_read_unchecked(&net->ipv4.dev_addr_genid);
77462
77463 return nh->nh_saddr;
77464 }
77465diff --git a/net/ipv4/inet_hashtables.c b/net/ipv4/inet_hashtables.c
77466index 7880af9..70f92a3 100644
77467--- a/net/ipv4/inet_hashtables.c
77468+++ b/net/ipv4/inet_hashtables.c
77469@@ -18,12 +18,15 @@
77470 #include <linux/sched.h>
77471 #include <linux/slab.h>
77472 #include <linux/wait.h>
77473+#include <linux/security.h>
77474
77475 #include <net/inet_connection_sock.h>
77476 #include <net/inet_hashtables.h>
77477 #include <net/secure_seq.h>
77478 #include <net/ip.h>
77479
77480+extern void gr_update_task_in_ip_table(struct task_struct *task, const struct inet_sock *inet);
77481+
77482 /*
77483 * Allocate and initialize a new local port bind bucket.
77484 * The bindhash mutex for snum's hash chain must be held here.
77485@@ -530,6 +533,8 @@ ok:
77486 twrefcnt += inet_twsk_bind_unhash(tw, hinfo);
77487 spin_unlock(&head->lock);
77488
77489+ gr_update_task_in_ip_table(current, inet_sk(sk));
77490+
77491 if (tw) {
77492 inet_twsk_deschedule(tw, death_row);
77493 while (twrefcnt) {
77494diff --git a/net/ipv4/inetpeer.c b/net/ipv4/inetpeer.c
77495index c7527f6..d8bba61 100644
77496--- a/net/ipv4/inetpeer.c
77497+++ b/net/ipv4/inetpeer.c
77498@@ -503,8 +503,8 @@ relookup:
77499 if (p) {
77500 p->daddr = *daddr;
77501 atomic_set(&p->refcnt, 1);
77502- atomic_set(&p->rid, 0);
77503- atomic_set(&p->ip_id_count,
77504+ atomic_set_unchecked(&p->rid, 0);
77505+ atomic_set_unchecked(&p->ip_id_count,
77506 (daddr->family == AF_INET) ?
77507 secure_ip_id(daddr->addr.a4) :
77508 secure_ipv6_id(daddr->addr.a6));
77509diff --git a/net/ipv4/ip_fragment.c b/net/ipv4/ip_fragment.c
77510index 8d07c97..d0812ef 100644
77511--- a/net/ipv4/ip_fragment.c
77512+++ b/net/ipv4/ip_fragment.c
77513@@ -322,7 +322,7 @@ static inline int ip_frag_too_far(struct ipq *qp)
77514 return 0;
77515
77516 start = qp->rid;
77517- end = atomic_inc_return(&peer->rid);
77518+ end = atomic_inc_return_unchecked(&peer->rid);
77519 qp->rid = end;
77520
77521 rc = qp->q.fragments && (end - start) > max;
77522diff --git a/net/ipv4/ip_sockglue.c b/net/ipv4/ip_sockglue.c
77523index 5eea4a8..49819c2 100644
77524--- a/net/ipv4/ip_sockglue.c
77525+++ b/net/ipv4/ip_sockglue.c
77526@@ -1142,7 +1142,8 @@ static int do_ip_getsockopt(struct sock *sk, int level, int optname,
77527 len = min_t(unsigned int, len, opt->optlen);
77528 if (put_user(len, optlen))
77529 return -EFAULT;
77530- if (copy_to_user(optval, opt->__data, len))
77531+ if ((len > (sizeof(optbuf) - sizeof(struct ip_options))) ||
77532+ copy_to_user(optval, opt->__data, len))
77533 return -EFAULT;
77534 return 0;
77535 }
77536@@ -1273,7 +1274,7 @@ static int do_ip_getsockopt(struct sock *sk, int level, int optname,
77537 if (sk->sk_type != SOCK_STREAM)
77538 return -ENOPROTOOPT;
77539
77540- msg.msg_control = optval;
77541+ msg.msg_control = (void __force_kernel *)optval;
77542 msg.msg_controllen = len;
77543 msg.msg_flags = flags;
77544
77545diff --git a/net/ipv4/ipconfig.c b/net/ipv4/ipconfig.c
77546index 67e8a6b..386764d 100644
77547--- a/net/ipv4/ipconfig.c
77548+++ b/net/ipv4/ipconfig.c
77549@@ -321,7 +321,7 @@ static int __init ic_devinet_ioctl(unsigned int cmd, struct ifreq *arg)
77550
77551 mm_segment_t oldfs = get_fs();
77552 set_fs(get_ds());
77553- res = devinet_ioctl(&init_net, cmd, (struct ifreq __user *) arg);
77554+ res = devinet_ioctl(&init_net, cmd, (struct ifreq __force_user *) arg);
77555 set_fs(oldfs);
77556 return res;
77557 }
77558@@ -332,7 +332,7 @@ static int __init ic_dev_ioctl(unsigned int cmd, struct ifreq *arg)
77559
77560 mm_segment_t oldfs = get_fs();
77561 set_fs(get_ds());
77562- res = dev_ioctl(&init_net, cmd, (struct ifreq __user *) arg);
77563+ res = dev_ioctl(&init_net, cmd, (struct ifreq __force_user *) arg);
77564 set_fs(oldfs);
77565 return res;
77566 }
77567@@ -343,7 +343,7 @@ static int __init ic_route_ioctl(unsigned int cmd, struct rtentry *arg)
77568
77569 mm_segment_t oldfs = get_fs();
77570 set_fs(get_ds());
77571- res = ip_rt_ioctl(&init_net, cmd, (void __user *) arg);
77572+ res = ip_rt_ioctl(&init_net, cmd, (void __force_user *) arg);
77573 set_fs(oldfs);
77574 return res;
77575 }
77576diff --git a/net/ipv4/netfilter/arp_tables.c b/net/ipv4/netfilter/arp_tables.c
77577index 97e61ea..cac1bbb 100644
77578--- a/net/ipv4/netfilter/arp_tables.c
77579+++ b/net/ipv4/netfilter/arp_tables.c
77580@@ -879,14 +879,14 @@ static int compat_table_info(const struct xt_table_info *info,
77581 #endif
77582
77583 static int get_info(struct net *net, void __user *user,
77584- const int *len, int compat)
77585+ int len, int compat)
77586 {
77587 char name[XT_TABLE_MAXNAMELEN];
77588 struct xt_table *t;
77589 int ret;
77590
77591- if (*len != sizeof(struct arpt_getinfo)) {
77592- duprintf("length %u != %Zu\n", *len,
77593+ if (len != sizeof(struct arpt_getinfo)) {
77594+ duprintf("length %u != %Zu\n", len,
77595 sizeof(struct arpt_getinfo));
77596 return -EINVAL;
77597 }
77598@@ -923,7 +923,7 @@ static int get_info(struct net *net, void __user *user,
77599 info.size = private->size;
77600 strcpy(info.name, name);
77601
77602- if (copy_to_user(user, &info, *len) != 0)
77603+ if (copy_to_user(user, &info, len) != 0)
77604 ret = -EFAULT;
77605 else
77606 ret = 0;
77607@@ -1682,7 +1682,7 @@ static int compat_do_arpt_get_ctl(struct sock *sk, int cmd, void __user *user,
77608
77609 switch (cmd) {
77610 case ARPT_SO_GET_INFO:
77611- ret = get_info(sock_net(sk), user, len, 1);
77612+ ret = get_info(sock_net(sk), user, *len, 1);
77613 break;
77614 case ARPT_SO_GET_ENTRIES:
77615 ret = compat_get_entries(sock_net(sk), user, len);
77616@@ -1727,7 +1727,7 @@ static int do_arpt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len
77617
77618 switch (cmd) {
77619 case ARPT_SO_GET_INFO:
77620- ret = get_info(sock_net(sk), user, len, 0);
77621+ ret = get_info(sock_net(sk), user, *len, 0);
77622 break;
77623
77624 case ARPT_SO_GET_ENTRIES:
77625diff --git a/net/ipv4/netfilter/ip_tables.c b/net/ipv4/netfilter/ip_tables.c
77626index 170b1fd..6105b91 100644
77627--- a/net/ipv4/netfilter/ip_tables.c
77628+++ b/net/ipv4/netfilter/ip_tables.c
77629@@ -1068,14 +1068,14 @@ static int compat_table_info(const struct xt_table_info *info,
77630 #endif
77631
77632 static int get_info(struct net *net, void __user *user,
77633- const int *len, int compat)
77634+ int len, int compat)
77635 {
77636 char name[XT_TABLE_MAXNAMELEN];
77637 struct xt_table *t;
77638 int ret;
77639
77640- if (*len != sizeof(struct ipt_getinfo)) {
77641- duprintf("length %u != %zu\n", *len,
77642+ if (len != sizeof(struct ipt_getinfo)) {
77643+ duprintf("length %u != %zu\n", len,
77644 sizeof(struct ipt_getinfo));
77645 return -EINVAL;
77646 }
77647@@ -1112,7 +1112,7 @@ static int get_info(struct net *net, void __user *user,
77648 info.size = private->size;
77649 strcpy(info.name, name);
77650
77651- if (copy_to_user(user, &info, *len) != 0)
77652+ if (copy_to_user(user, &info, len) != 0)
77653 ret = -EFAULT;
77654 else
77655 ret = 0;
77656@@ -1966,7 +1966,7 @@ compat_do_ipt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
77657
77658 switch (cmd) {
77659 case IPT_SO_GET_INFO:
77660- ret = get_info(sock_net(sk), user, len, 1);
77661+ ret = get_info(sock_net(sk), user, *len, 1);
77662 break;
77663 case IPT_SO_GET_ENTRIES:
77664 ret = compat_get_entries(sock_net(sk), user, len);
77665@@ -2013,7 +2013,7 @@ do_ipt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
77666
77667 switch (cmd) {
77668 case IPT_SO_GET_INFO:
77669- ret = get_info(sock_net(sk), user, len, 0);
77670+ ret = get_info(sock_net(sk), user, *len, 0);
77671 break;
77672
77673 case IPT_SO_GET_ENTRIES:
77674diff --git a/net/ipv4/ping.c b/net/ipv4/ping.c
77675index 6232d47..6b88607 100644
77676--- a/net/ipv4/ping.c
77677+++ b/net/ipv4/ping.c
77678@@ -847,7 +847,7 @@ static void ping_format_sock(struct sock *sp, struct seq_file *f,
77679 sk_rmem_alloc_get(sp),
77680 0, 0L, 0, sock_i_uid(sp), 0, sock_i_ino(sp),
77681 atomic_read(&sp->sk_refcnt), sp,
77682- atomic_read(&sp->sk_drops), len);
77683+ atomic_read_unchecked(&sp->sk_drops), len);
77684 }
77685
77686 static int ping_seq_show(struct seq_file *seq, void *v)
77687diff --git a/net/ipv4/raw.c b/net/ipv4/raw.c
77688index d23c657..cb69cc2 100644
77689--- a/net/ipv4/raw.c
77690+++ b/net/ipv4/raw.c
77691@@ -311,7 +311,7 @@ static int raw_rcv_skb(struct sock *sk, struct sk_buff *skb)
77692 int raw_rcv(struct sock *sk, struct sk_buff *skb)
77693 {
77694 if (!xfrm4_policy_check(sk, XFRM_POLICY_IN, skb)) {
77695- atomic_inc(&sk->sk_drops);
77696+ atomic_inc_unchecked(&sk->sk_drops);
77697 kfree_skb(skb);
77698 return NET_RX_DROP;
77699 }
77700@@ -747,16 +747,20 @@ static int raw_init(struct sock *sk)
77701
77702 static int raw_seticmpfilter(struct sock *sk, char __user *optval, int optlen)
77703 {
77704+ struct icmp_filter filter;
77705+
77706 if (optlen > sizeof(struct icmp_filter))
77707 optlen = sizeof(struct icmp_filter);
77708- if (copy_from_user(&raw_sk(sk)->filter, optval, optlen))
77709+ if (copy_from_user(&filter, optval, optlen))
77710 return -EFAULT;
77711+ raw_sk(sk)->filter = filter;
77712 return 0;
77713 }
77714
77715 static int raw_geticmpfilter(struct sock *sk, char __user *optval, int __user *optlen)
77716 {
77717 int len, ret = -EFAULT;
77718+ struct icmp_filter filter;
77719
77720 if (get_user(len, optlen))
77721 goto out;
77722@@ -766,8 +770,8 @@ static int raw_geticmpfilter(struct sock *sk, char __user *optval, int __user *o
77723 if (len > sizeof(struct icmp_filter))
77724 len = sizeof(struct icmp_filter);
77725 ret = -EFAULT;
77726- if (put_user(len, optlen) ||
77727- copy_to_user(optval, &raw_sk(sk)->filter, len))
77728+ filter = raw_sk(sk)->filter;
77729+ if (put_user(len, optlen) || len > sizeof filter || copy_to_user(optval, &filter, len))
77730 goto out;
77731 ret = 0;
77732 out: return ret;
77733@@ -995,7 +999,13 @@ static void raw_sock_seq_show(struct seq_file *seq, struct sock *sp, int i)
77734 sk_wmem_alloc_get(sp),
77735 sk_rmem_alloc_get(sp),
77736 0, 0L, 0, sock_i_uid(sp), 0, sock_i_ino(sp),
77737- atomic_read(&sp->sk_refcnt), sp, atomic_read(&sp->sk_drops));
77738+ atomic_read(&sp->sk_refcnt),
77739+#ifdef CONFIG_GRKERNSEC_HIDESYM
77740+ NULL,
77741+#else
77742+ sp,
77743+#endif
77744+ atomic_read_unchecked(&sp->sk_drops));
77745 }
77746
77747 static int raw_seq_show(struct seq_file *seq, void *v)
77748diff --git a/net/ipv4/route.c b/net/ipv4/route.c
77749index c017cb1..9eb15b7d 100644
77750--- a/net/ipv4/route.c
77751+++ b/net/ipv4/route.c
77752@@ -2526,7 +2526,7 @@ static __net_initdata struct pernet_operations sysctl_route_ops = {
77753
77754 static __net_init int rt_genid_init(struct net *net)
77755 {
77756- atomic_set(&net->rt_genid, 0);
77757+ atomic_set_unchecked(&net->rt_genid, 0);
77758 get_random_bytes(&net->ipv4.dev_addr_genid,
77759 sizeof(net->ipv4.dev_addr_genid));
77760 return 0;
77761diff --git a/net/ipv4/tcp_input.c b/net/ipv4/tcp_input.c
77762index c92c4da..f19e3ec 100644
77763--- a/net/ipv4/tcp_input.c
77764+++ b/net/ipv4/tcp_input.c
77765@@ -4731,7 +4731,7 @@ static struct sk_buff *tcp_collapse_one(struct sock *sk, struct sk_buff *skb,
77766 * simplifies code)
77767 */
77768 static void
77769-tcp_collapse(struct sock *sk, struct sk_buff_head *list,
77770+__intentional_overflow(5,6) tcp_collapse(struct sock *sk, struct sk_buff_head *list,
77771 struct sk_buff *head, struct sk_buff *tail,
77772 u32 start, u32 end)
77773 {
77774diff --git a/net/ipv4/tcp_ipv4.c b/net/ipv4/tcp_ipv4.c
77775index db7bfad..bfea796 100644
77776--- a/net/ipv4/tcp_ipv4.c
77777+++ b/net/ipv4/tcp_ipv4.c
77778@@ -90,6 +90,10 @@ int sysctl_tcp_low_latency __read_mostly;
77779 EXPORT_SYMBOL(sysctl_tcp_low_latency);
77780
77781
77782+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
77783+extern int grsec_enable_blackhole;
77784+#endif
77785+
77786 #ifdef CONFIG_TCP_MD5SIG
77787 static int tcp_v4_md5_hash_hdr(char *md5_hash, const struct tcp_md5sig_key *key,
77788 __be32 daddr, __be32 saddr, const struct tcphdr *th);
77789@@ -1664,6 +1668,9 @@ int tcp_v4_do_rcv(struct sock *sk, struct sk_buff *skb)
77790 return 0;
77791
77792 reset:
77793+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
77794+ if (!grsec_enable_blackhole)
77795+#endif
77796 tcp_v4_send_reset(rsk, skb);
77797 discard:
77798 kfree_skb(skb);
77799@@ -1764,12 +1771,19 @@ int tcp_v4_rcv(struct sk_buff *skb)
77800 TCP_SKB_CB(skb)->sacked = 0;
77801
77802 sk = __inet_lookup_skb(&tcp_hashinfo, skb, th->source, th->dest);
77803- if (!sk)
77804+ if (!sk) {
77805+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
77806+ ret = 1;
77807+#endif
77808 goto no_tcp_socket;
77809-
77810+ }
77811 process:
77812- if (sk->sk_state == TCP_TIME_WAIT)
77813+ if (sk->sk_state == TCP_TIME_WAIT) {
77814+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
77815+ ret = 2;
77816+#endif
77817 goto do_time_wait;
77818+ }
77819
77820 if (unlikely(iph->ttl < inet_sk(sk)->min_ttl)) {
77821 NET_INC_STATS_BH(net, LINUX_MIB_TCPMINTTLDROP);
77822@@ -1820,6 +1834,10 @@ no_tcp_socket:
77823 bad_packet:
77824 TCP_INC_STATS_BH(net, TCP_MIB_INERRS);
77825 } else {
77826+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
77827+ if (!grsec_enable_blackhole || (ret == 1 &&
77828+ (skb->dev->flags & IFF_LOOPBACK)))
77829+#endif
77830 tcp_v4_send_reset(NULL, skb);
77831 }
77832
77833@@ -2415,7 +2433,11 @@ static void get_openreq4(const struct sock *sk, const struct request_sock *req,
77834 0, /* non standard timer */
77835 0, /* open_requests have no inode */
77836 atomic_read(&sk->sk_refcnt),
77837+#ifdef CONFIG_GRKERNSEC_HIDESYM
77838+ NULL,
77839+#else
77840 req,
77841+#endif
77842 len);
77843 }
77844
77845@@ -2465,7 +2487,12 @@ static void get_tcp4_sock(struct sock *sk, struct seq_file *f, int i, int *len)
77846 sock_i_uid(sk),
77847 icsk->icsk_probes_out,
77848 sock_i_ino(sk),
77849- atomic_read(&sk->sk_refcnt), sk,
77850+ atomic_read(&sk->sk_refcnt),
77851+#ifdef CONFIG_GRKERNSEC_HIDESYM
77852+ NULL,
77853+#else
77854+ sk,
77855+#endif
77856 jiffies_to_clock_t(icsk->icsk_rto),
77857 jiffies_to_clock_t(icsk->icsk_ack.ato),
77858 (icsk->icsk_ack.quick << 1) | icsk->icsk_ack.pingpong,
77859@@ -2493,7 +2520,13 @@ static void get_timewait4_sock(const struct inet_timewait_sock *tw,
77860 " %02X %08X:%08X %02X:%08lX %08X %5d %8d %d %d %pK%n",
77861 i, src, srcp, dest, destp, tw->tw_substate, 0, 0,
77862 3, jiffies_to_clock_t(ttd), 0, 0, 0, 0,
77863- atomic_read(&tw->tw_refcnt), tw, len);
77864+ atomic_read(&tw->tw_refcnt),
77865+#ifdef CONFIG_GRKERNSEC_HIDESYM
77866+ NULL,
77867+#else
77868+ tw,
77869+#endif
77870+ len);
77871 }
77872
77873 #define TMPSZ 150
77874diff --git a/net/ipv4/tcp_minisocks.c b/net/ipv4/tcp_minisocks.c
77875index 6ff7f10..38de56e 100644
77876--- a/net/ipv4/tcp_minisocks.c
77877+++ b/net/ipv4/tcp_minisocks.c
77878@@ -27,6 +27,10 @@
77879 #include <net/inet_common.h>
77880 #include <net/xfrm.h>
77881
77882+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
77883+extern int grsec_enable_blackhole;
77884+#endif
77885+
77886 int sysctl_tcp_syncookies __read_mostly = 1;
77887 EXPORT_SYMBOL(sysctl_tcp_syncookies);
77888
77889@@ -707,6 +711,10 @@ listen_overflow:
77890
77891 embryonic_reset:
77892 NET_INC_STATS_BH(sock_net(sk), LINUX_MIB_EMBRYONICRSTS);
77893+
77894+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
77895+ if (!grsec_enable_blackhole)
77896+#endif
77897 if (!(flg & TCP_FLAG_RST))
77898 req->rsk_ops->send_reset(sk, skb);
77899
77900diff --git a/net/ipv4/tcp_probe.c b/net/ipv4/tcp_probe.c
77901index 4526fe6..1a34e43 100644
77902--- a/net/ipv4/tcp_probe.c
77903+++ b/net/ipv4/tcp_probe.c
77904@@ -204,7 +204,7 @@ static ssize_t tcpprobe_read(struct file *file, char __user *buf,
77905 if (cnt + width >= len)
77906 break;
77907
77908- if (copy_to_user(buf + cnt, tbuf, width))
77909+ if (width > sizeof tbuf || copy_to_user(buf + cnt, tbuf, width))
77910 return -EFAULT;
77911 cnt += width;
77912 }
77913diff --git a/net/ipv4/tcp_timer.c b/net/ipv4/tcp_timer.c
77914index b774a03..3873efe 100644
77915--- a/net/ipv4/tcp_timer.c
77916+++ b/net/ipv4/tcp_timer.c
77917@@ -22,6 +22,10 @@
77918 #include <linux/gfp.h>
77919 #include <net/tcp.h>
77920
77921+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
77922+extern int grsec_lastack_retries;
77923+#endif
77924+
77925 int sysctl_tcp_syn_retries __read_mostly = TCP_SYN_RETRIES;
77926 int sysctl_tcp_synack_retries __read_mostly = TCP_SYNACK_RETRIES;
77927 int sysctl_tcp_keepalive_time __read_mostly = TCP_KEEPALIVE_TIME;
77928@@ -185,6 +189,13 @@ static int tcp_write_timeout(struct sock *sk)
77929 }
77930 }
77931
77932+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
77933+ if ((sk->sk_state == TCP_LAST_ACK) &&
77934+ (grsec_lastack_retries > 0) &&
77935+ (grsec_lastack_retries < retry_until))
77936+ retry_until = grsec_lastack_retries;
77937+#endif
77938+
77939 if (retransmits_timed_out(sk, retry_until,
77940 syn_set ? 0 : icsk->icsk_user_timeout, syn_set)) {
77941 /* Has it gone just too far? */
77942diff --git a/net/ipv4/udp.c b/net/ipv4/udp.c
77943index 2814f66..fa2b223 100644
77944--- a/net/ipv4/udp.c
77945+++ b/net/ipv4/udp.c
77946@@ -87,6 +87,7 @@
77947 #include <linux/types.h>
77948 #include <linux/fcntl.h>
77949 #include <linux/module.h>
77950+#include <linux/security.h>
77951 #include <linux/socket.h>
77952 #include <linux/sockios.h>
77953 #include <linux/igmp.h>
77954@@ -111,6 +112,10 @@
77955 #include <trace/events/skb.h>
77956 #include "udp_impl.h"
77957
77958+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
77959+extern int grsec_enable_blackhole;
77960+#endif
77961+
77962 struct udp_table udp_table __read_mostly;
77963 EXPORT_SYMBOL(udp_table);
77964
77965@@ -569,6 +574,9 @@ found:
77966 return s;
77967 }
77968
77969+extern int gr_search_udp_recvmsg(struct sock *sk, const struct sk_buff *skb);
77970+extern int gr_search_udp_sendmsg(struct sock *sk, struct sockaddr_in *addr);
77971+
77972 /*
77973 * This routine is called by the ICMP module when it gets some
77974 * sort of error condition. If err < 0 then the socket should
77975@@ -864,9 +872,18 @@ int udp_sendmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg,
77976 dport = usin->sin_port;
77977 if (dport == 0)
77978 return -EINVAL;
77979+
77980+ err = gr_search_udp_sendmsg(sk, usin);
77981+ if (err)
77982+ return err;
77983 } else {
77984 if (sk->sk_state != TCP_ESTABLISHED)
77985 return -EDESTADDRREQ;
77986+
77987+ err = gr_search_udp_sendmsg(sk, NULL);
77988+ if (err)
77989+ return err;
77990+
77991 daddr = inet->inet_daddr;
77992 dport = inet->inet_dport;
77993 /* Open fast path for connected socket.
77994@@ -1108,7 +1125,7 @@ static unsigned int first_packet_length(struct sock *sk)
77995 udp_lib_checksum_complete(skb)) {
77996 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS,
77997 IS_UDPLITE(sk));
77998- atomic_inc(&sk->sk_drops);
77999+ atomic_inc_unchecked(&sk->sk_drops);
78000 __skb_unlink(skb, rcvq);
78001 __skb_queue_tail(&list_kill, skb);
78002 }
78003@@ -1194,6 +1211,10 @@ try_again:
78004 if (!skb)
78005 goto out;
78006
78007+ err = gr_search_udp_recvmsg(sk, skb);
78008+ if (err)
78009+ goto out_free;
78010+
78011 ulen = skb->len - sizeof(struct udphdr);
78012 copied = len;
78013 if (copied > ulen)
78014@@ -1227,7 +1248,7 @@ try_again:
78015 if (unlikely(err)) {
78016 trace_kfree_skb(skb, udp_recvmsg);
78017 if (!peeked) {
78018- atomic_inc(&sk->sk_drops);
78019+ atomic_inc_unchecked(&sk->sk_drops);
78020 UDP_INC_STATS_USER(sock_net(sk),
78021 UDP_MIB_INERRORS, is_udplite);
78022 }
78023@@ -1510,7 +1531,7 @@ int udp_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
78024
78025 drop:
78026 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS, is_udplite);
78027- atomic_inc(&sk->sk_drops);
78028+ atomic_inc_unchecked(&sk->sk_drops);
78029 kfree_skb(skb);
78030 return -1;
78031 }
78032@@ -1529,7 +1550,7 @@ static void flush_stack(struct sock **stack, unsigned int count,
78033 skb1 = (i == final) ? skb : skb_clone(skb, GFP_ATOMIC);
78034
78035 if (!skb1) {
78036- atomic_inc(&sk->sk_drops);
78037+ atomic_inc_unchecked(&sk->sk_drops);
78038 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_RCVBUFERRORS,
78039 IS_UDPLITE(sk));
78040 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS,
78041@@ -1698,6 +1719,9 @@ int __udp4_lib_rcv(struct sk_buff *skb, struct udp_table *udptable,
78042 goto csum_error;
78043
78044 UDP_INC_STATS_BH(net, UDP_MIB_NOPORTS, proto == IPPROTO_UDPLITE);
78045+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
78046+ if (!grsec_enable_blackhole || (skb->dev->flags & IFF_LOOPBACK))
78047+#endif
78048 icmp_send(skb, ICMP_DEST_UNREACH, ICMP_PORT_UNREACH, 0);
78049
78050 /*
78051@@ -2116,8 +2140,13 @@ static void udp4_format_sock(struct sock *sp, struct seq_file *f,
78052 sk_wmem_alloc_get(sp),
78053 sk_rmem_alloc_get(sp),
78054 0, 0L, 0, sock_i_uid(sp), 0, sock_i_ino(sp),
78055- atomic_read(&sp->sk_refcnt), sp,
78056- atomic_read(&sp->sk_drops), len);
78057+ atomic_read(&sp->sk_refcnt),
78058+#ifdef CONFIG_GRKERNSEC_HIDESYM
78059+ NULL,
78060+#else
78061+ sp,
78062+#endif
78063+ atomic_read_unchecked(&sp->sk_drops), len);
78064 }
78065
78066 int udp4_seq_show(struct seq_file *seq, void *v)
78067diff --git a/net/ipv6/addrconf.c b/net/ipv6/addrconf.c
78068index b10374d..0baa1f9 100644
78069--- a/net/ipv6/addrconf.c
78070+++ b/net/ipv6/addrconf.c
78071@@ -2144,7 +2144,7 @@ int addrconf_set_dstaddr(struct net *net, void __user *arg)
78072 p.iph.ihl = 5;
78073 p.iph.protocol = IPPROTO_IPV6;
78074 p.iph.ttl = 64;
78075- ifr.ifr_ifru.ifru_data = (__force void __user *)&p;
78076+ ifr.ifr_ifru.ifru_data = (void __force_user *)&p;
78077
78078 if (ops->ndo_do_ioctl) {
78079 mm_segment_t oldfs = get_fs();
78080diff --git a/net/ipv6/ipv6_sockglue.c b/net/ipv6/ipv6_sockglue.c
78081index ba6d13d..6899122 100644
78082--- a/net/ipv6/ipv6_sockglue.c
78083+++ b/net/ipv6/ipv6_sockglue.c
78084@@ -989,7 +989,7 @@ static int do_ipv6_getsockopt(struct sock *sk, int level, int optname,
78085 if (sk->sk_type != SOCK_STREAM)
78086 return -ENOPROTOOPT;
78087
78088- msg.msg_control = optval;
78089+ msg.msg_control = (void __force_kernel *)optval;
78090 msg.msg_controllen = len;
78091 msg.msg_flags = flags;
78092
78093diff --git a/net/ipv6/netfilter/ip6_tables.c b/net/ipv6/netfilter/ip6_tables.c
78094index d7cb045..8c0ded6 100644
78095--- a/net/ipv6/netfilter/ip6_tables.c
78096+++ b/net/ipv6/netfilter/ip6_tables.c
78097@@ -1078,14 +1078,14 @@ static int compat_table_info(const struct xt_table_info *info,
78098 #endif
78099
78100 static int get_info(struct net *net, void __user *user,
78101- const int *len, int compat)
78102+ int len, int compat)
78103 {
78104 char name[XT_TABLE_MAXNAMELEN];
78105 struct xt_table *t;
78106 int ret;
78107
78108- if (*len != sizeof(struct ip6t_getinfo)) {
78109- duprintf("length %u != %zu\n", *len,
78110+ if (len != sizeof(struct ip6t_getinfo)) {
78111+ duprintf("length %u != %zu\n", len,
78112 sizeof(struct ip6t_getinfo));
78113 return -EINVAL;
78114 }
78115@@ -1122,7 +1122,7 @@ static int get_info(struct net *net, void __user *user,
78116 info.size = private->size;
78117 strcpy(info.name, name);
78118
78119- if (copy_to_user(user, &info, *len) != 0)
78120+ if (copy_to_user(user, &info, len) != 0)
78121 ret = -EFAULT;
78122 else
78123 ret = 0;
78124@@ -1976,7 +1976,7 @@ compat_do_ip6t_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
78125
78126 switch (cmd) {
78127 case IP6T_SO_GET_INFO:
78128- ret = get_info(sock_net(sk), user, len, 1);
78129+ ret = get_info(sock_net(sk), user, *len, 1);
78130 break;
78131 case IP6T_SO_GET_ENTRIES:
78132 ret = compat_get_entries(sock_net(sk), user, len);
78133@@ -2023,7 +2023,7 @@ do_ip6t_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
78134
78135 switch (cmd) {
78136 case IP6T_SO_GET_INFO:
78137- ret = get_info(sock_net(sk), user, len, 0);
78138+ ret = get_info(sock_net(sk), user, *len, 0);
78139 break;
78140
78141 case IP6T_SO_GET_ENTRIES:
78142diff --git a/net/ipv6/raw.c b/net/ipv6/raw.c
78143index 4a5f78b..3f22ebe 100644
78144--- a/net/ipv6/raw.c
78145+++ b/net/ipv6/raw.c
78146@@ -379,7 +379,7 @@ static inline int rawv6_rcv_skb(struct sock *sk, struct sk_buff *skb)
78147 {
78148 if ((raw6_sk(sk)->checksum || rcu_access_pointer(sk->sk_filter)) &&
78149 skb_checksum_complete(skb)) {
78150- atomic_inc(&sk->sk_drops);
78151+ atomic_inc_unchecked(&sk->sk_drops);
78152 kfree_skb(skb);
78153 return NET_RX_DROP;
78154 }
78155@@ -407,7 +407,7 @@ int rawv6_rcv(struct sock *sk, struct sk_buff *skb)
78156 struct raw6_sock *rp = raw6_sk(sk);
78157
78158 if (!xfrm6_policy_check(sk, XFRM_POLICY_IN, skb)) {
78159- atomic_inc(&sk->sk_drops);
78160+ atomic_inc_unchecked(&sk->sk_drops);
78161 kfree_skb(skb);
78162 return NET_RX_DROP;
78163 }
78164@@ -431,7 +431,7 @@ int rawv6_rcv(struct sock *sk, struct sk_buff *skb)
78165
78166 if (inet->hdrincl) {
78167 if (skb_checksum_complete(skb)) {
78168- atomic_inc(&sk->sk_drops);
78169+ atomic_inc_unchecked(&sk->sk_drops);
78170 kfree_skb(skb);
78171 return NET_RX_DROP;
78172 }
78173@@ -604,7 +604,7 @@ out:
78174 return err;
78175 }
78176
78177-static int rawv6_send_hdrinc(struct sock *sk, void *from, int length,
78178+static int rawv6_send_hdrinc(struct sock *sk, void *from, unsigned int length,
78179 struct flowi6 *fl6, struct dst_entry **dstp,
78180 unsigned int flags)
78181 {
78182@@ -916,12 +916,15 @@ do_confirm:
78183 static int rawv6_seticmpfilter(struct sock *sk, int level, int optname,
78184 char __user *optval, int optlen)
78185 {
78186+ struct icmp6_filter filter;
78187+
78188 switch (optname) {
78189 case ICMPV6_FILTER:
78190 if (optlen > sizeof(struct icmp6_filter))
78191 optlen = sizeof(struct icmp6_filter);
78192- if (copy_from_user(&raw6_sk(sk)->filter, optval, optlen))
78193+ if (copy_from_user(&filter, optval, optlen))
78194 return -EFAULT;
78195+ raw6_sk(sk)->filter = filter;
78196 return 0;
78197 default:
78198 return -ENOPROTOOPT;
78199@@ -934,6 +937,7 @@ static int rawv6_geticmpfilter(struct sock *sk, int level, int optname,
78200 char __user *optval, int __user *optlen)
78201 {
78202 int len;
78203+ struct icmp6_filter filter;
78204
78205 switch (optname) {
78206 case ICMPV6_FILTER:
78207@@ -945,7 +949,8 @@ static int rawv6_geticmpfilter(struct sock *sk, int level, int optname,
78208 len = sizeof(struct icmp6_filter);
78209 if (put_user(len, optlen))
78210 return -EFAULT;
78211- if (copy_to_user(optval, &raw6_sk(sk)->filter, len))
78212+ filter = raw6_sk(sk)->filter;
78213+ if (len > sizeof filter || copy_to_user(optval, &filter, len))
78214 return -EFAULT;
78215 return 0;
78216 default:
78217@@ -1252,7 +1257,13 @@ static void raw6_sock_seq_show(struct seq_file *seq, struct sock *sp, int i)
78218 0, 0L, 0,
78219 sock_i_uid(sp), 0,
78220 sock_i_ino(sp),
78221- atomic_read(&sp->sk_refcnt), sp, atomic_read(&sp->sk_drops));
78222+ atomic_read(&sp->sk_refcnt),
78223+#ifdef CONFIG_GRKERNSEC_HIDESYM
78224+ NULL,
78225+#else
78226+ sp,
78227+#endif
78228+ atomic_read_unchecked(&sp->sk_drops));
78229 }
78230
78231 static int raw6_seq_show(struct seq_file *seq, void *v)
78232diff --git a/net/ipv6/tcp_ipv6.c b/net/ipv6/tcp_ipv6.c
78233index 7e32d42..5d975ba 100644
78234--- a/net/ipv6/tcp_ipv6.c
78235+++ b/net/ipv6/tcp_ipv6.c
78236@@ -106,6 +106,10 @@ static void inet6_sk_rx_dst_set(struct sock *sk, const struct sk_buff *skb)
78237 inet6_sk(sk)->rx_dst_cookie = rt->rt6i_node->fn_sernum;
78238 }
78239
78240+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
78241+extern int grsec_enable_blackhole;
78242+#endif
78243+
78244 static void tcp_v6_hash(struct sock *sk)
78245 {
78246 if (sk->sk_state != TCP_CLOSE) {
78247@@ -1511,6 +1515,9 @@ static int tcp_v6_do_rcv(struct sock *sk, struct sk_buff *skb)
78248 return 0;
78249
78250 reset:
78251+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
78252+ if (!grsec_enable_blackhole)
78253+#endif
78254 tcp_v6_send_reset(sk, skb);
78255 discard:
78256 if (opt_skb)
78257@@ -1592,12 +1599,20 @@ static int tcp_v6_rcv(struct sk_buff *skb)
78258 TCP_SKB_CB(skb)->sacked = 0;
78259
78260 sk = __inet6_lookup_skb(&tcp_hashinfo, skb, th->source, th->dest);
78261- if (!sk)
78262+ if (!sk) {
78263+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
78264+ ret = 1;
78265+#endif
78266 goto no_tcp_socket;
78267+ }
78268
78269 process:
78270- if (sk->sk_state == TCP_TIME_WAIT)
78271+ if (sk->sk_state == TCP_TIME_WAIT) {
78272+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
78273+ ret = 2;
78274+#endif
78275 goto do_time_wait;
78276+ }
78277
78278 if (hdr->hop_limit < inet6_sk(sk)->min_hopcount) {
78279 NET_INC_STATS_BH(net, LINUX_MIB_TCPMINTTLDROP);
78280@@ -1646,6 +1661,10 @@ no_tcp_socket:
78281 bad_packet:
78282 TCP_INC_STATS_BH(net, TCP_MIB_INERRS);
78283 } else {
78284+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
78285+ if (!grsec_enable_blackhole || (ret == 1 &&
78286+ (skb->dev->flags & IFF_LOOPBACK)))
78287+#endif
78288 tcp_v6_send_reset(NULL, skb);
78289 }
78290
78291@@ -1857,7 +1876,13 @@ static void get_openreq6(struct seq_file *seq,
78292 uid,
78293 0, /* non standard timer */
78294 0, /* open_requests have no inode */
78295- 0, req);
78296+ 0,
78297+#ifdef CONFIG_GRKERNSEC_HIDESYM
78298+ NULL
78299+#else
78300+ req
78301+#endif
78302+ );
78303 }
78304
78305 static void get_tcp6_sock(struct seq_file *seq, struct sock *sp, int i)
78306@@ -1907,7 +1932,12 @@ static void get_tcp6_sock(struct seq_file *seq, struct sock *sp, int i)
78307 sock_i_uid(sp),
78308 icsk->icsk_probes_out,
78309 sock_i_ino(sp),
78310- atomic_read(&sp->sk_refcnt), sp,
78311+ atomic_read(&sp->sk_refcnt),
78312+#ifdef CONFIG_GRKERNSEC_HIDESYM
78313+ NULL,
78314+#else
78315+ sp,
78316+#endif
78317 jiffies_to_clock_t(icsk->icsk_rto),
78318 jiffies_to_clock_t(icsk->icsk_ack.ato),
78319 (icsk->icsk_ack.quick << 1 ) | icsk->icsk_ack.pingpong,
78320@@ -1942,7 +1972,13 @@ static void get_timewait6_sock(struct seq_file *seq,
78321 dest->s6_addr32[2], dest->s6_addr32[3], destp,
78322 tw->tw_substate, 0, 0,
78323 3, jiffies_to_clock_t(ttd), 0, 0, 0, 0,
78324- atomic_read(&tw->tw_refcnt), tw);
78325+ atomic_read(&tw->tw_refcnt),
78326+#ifdef CONFIG_GRKERNSEC_HIDESYM
78327+ NULL
78328+#else
78329+ tw
78330+#endif
78331+ );
78332 }
78333
78334 static int tcp6_seq_show(struct seq_file *seq, void *v)
78335diff --git a/net/ipv6/udp.c b/net/ipv6/udp.c
78336index 07e2bfe..328dae8 100644
78337--- a/net/ipv6/udp.c
78338+++ b/net/ipv6/udp.c
78339@@ -51,6 +51,10 @@
78340 #include <trace/events/skb.h>
78341 #include "udp_impl.h"
78342
78343+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
78344+extern int grsec_enable_blackhole;
78345+#endif
78346+
78347 int ipv6_rcv_saddr_equal(const struct sock *sk, const struct sock *sk2)
78348 {
78349 const struct in6_addr *sk_rcv_saddr6 = &inet6_sk(sk)->rcv_saddr;
78350@@ -395,7 +399,7 @@ try_again:
78351 if (unlikely(err)) {
78352 trace_kfree_skb(skb, udpv6_recvmsg);
78353 if (!peeked) {
78354- atomic_inc(&sk->sk_drops);
78355+ atomic_inc_unchecked(&sk->sk_drops);
78356 if (is_udp4)
78357 UDP_INC_STATS_USER(sock_net(sk),
78358 UDP_MIB_INERRORS,
78359@@ -633,7 +637,7 @@ int udpv6_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
78360 return rc;
78361 drop:
78362 UDP6_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS, is_udplite);
78363- atomic_inc(&sk->sk_drops);
78364+ atomic_inc_unchecked(&sk->sk_drops);
78365 kfree_skb(skb);
78366 return -1;
78367 }
78368@@ -691,7 +695,7 @@ static void flush_stack(struct sock **stack, unsigned int count,
78369 if (likely(skb1 == NULL))
78370 skb1 = (i == final) ? skb : skb_clone(skb, GFP_ATOMIC);
78371 if (!skb1) {
78372- atomic_inc(&sk->sk_drops);
78373+ atomic_inc_unchecked(&sk->sk_drops);
78374 UDP6_INC_STATS_BH(sock_net(sk), UDP_MIB_RCVBUFERRORS,
78375 IS_UDPLITE(sk));
78376 UDP6_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS,
78377@@ -862,6 +866,9 @@ int __udp6_lib_rcv(struct sk_buff *skb, struct udp_table *udptable,
78378 goto discard;
78379
78380 UDP6_INC_STATS_BH(net, UDP_MIB_NOPORTS, proto == IPPROTO_UDPLITE);
78381+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
78382+ if (!grsec_enable_blackhole || (skb->dev->flags & IFF_LOOPBACK))
78383+#endif
78384 icmpv6_send(skb, ICMPV6_DEST_UNREACH, ICMPV6_PORT_UNREACH, 0);
78385
78386 kfree_skb(skb);
78387@@ -1471,8 +1478,13 @@ static void udp6_sock_seq_show(struct seq_file *seq, struct sock *sp, int bucket
78388 0, 0L, 0,
78389 sock_i_uid(sp), 0,
78390 sock_i_ino(sp),
78391- atomic_read(&sp->sk_refcnt), sp,
78392- atomic_read(&sp->sk_drops));
78393+ atomic_read(&sp->sk_refcnt),
78394+#ifdef CONFIG_GRKERNSEC_HIDESYM
78395+ NULL,
78396+#else
78397+ sp,
78398+#endif
78399+ atomic_read_unchecked(&sp->sk_drops));
78400 }
78401
78402 int udp6_seq_show(struct seq_file *seq, void *v)
78403diff --git a/net/irda/ircomm/ircomm_tty.c b/net/irda/ircomm/ircomm_tty.c
78404index 6b9d5a0..4dffaf1 100644
78405--- a/net/irda/ircomm/ircomm_tty.c
78406+++ b/net/irda/ircomm/ircomm_tty.c
78407@@ -281,16 +281,16 @@ static int ircomm_tty_block_til_ready(struct ircomm_tty_cb *self,
78408 add_wait_queue(&self->open_wait, &wait);
78409
78410 IRDA_DEBUG(2, "%s(%d):block_til_ready before block on %s open_count=%d\n",
78411- __FILE__,__LINE__, tty->driver->name, self->open_count );
78412+ __FILE__,__LINE__, tty->driver->name, local_read(&self->open_count) );
78413
78414 /* As far as I can see, we protect open_count - Jean II */
78415 spin_lock_irqsave(&self->spinlock, flags);
78416 if (!tty_hung_up_p(filp)) {
78417 extra_count = 1;
78418- self->open_count--;
78419+ local_dec(&self->open_count);
78420 }
78421 spin_unlock_irqrestore(&self->spinlock, flags);
78422- self->blocked_open++;
78423+ local_inc(&self->blocked_open);
78424
78425 while (1) {
78426 if (tty->termios->c_cflag & CBAUD) {
78427@@ -330,7 +330,7 @@ static int ircomm_tty_block_til_ready(struct ircomm_tty_cb *self,
78428 }
78429
78430 IRDA_DEBUG(1, "%s(%d):block_til_ready blocking on %s open_count=%d\n",
78431- __FILE__,__LINE__, tty->driver->name, self->open_count );
78432+ __FILE__,__LINE__, tty->driver->name, local_read(&self->open_count) );
78433
78434 schedule();
78435 }
78436@@ -341,13 +341,13 @@ static int ircomm_tty_block_til_ready(struct ircomm_tty_cb *self,
78437 if (extra_count) {
78438 /* ++ is not atomic, so this should be protected - Jean II */
78439 spin_lock_irqsave(&self->spinlock, flags);
78440- self->open_count++;
78441+ local_inc(&self->open_count);
78442 spin_unlock_irqrestore(&self->spinlock, flags);
78443 }
78444- self->blocked_open--;
78445+ local_dec(&self->blocked_open);
78446
78447 IRDA_DEBUG(1, "%s(%d):block_til_ready after blocking on %s open_count=%d\n",
78448- __FILE__,__LINE__, tty->driver->name, self->open_count);
78449+ __FILE__,__LINE__, tty->driver->name, local_read(&self->open_count));
78450
78451 if (!retval)
78452 self->flags |= ASYNC_NORMAL_ACTIVE;
78453@@ -412,14 +412,14 @@ static int ircomm_tty_open(struct tty_struct *tty, struct file *filp)
78454 }
78455 /* ++ is not atomic, so this should be protected - Jean II */
78456 spin_lock_irqsave(&self->spinlock, flags);
78457- self->open_count++;
78458+ local_inc(&self->open_count);
78459
78460 tty->driver_data = self;
78461 self->tty = tty;
78462 spin_unlock_irqrestore(&self->spinlock, flags);
78463
78464 IRDA_DEBUG(1, "%s(), %s%d, count = %d\n", __func__ , tty->driver->name,
78465- self->line, self->open_count);
78466+ self->line, local_read(&self->open_count));
78467
78468 /* Not really used by us, but lets do it anyway */
78469 self->tty->low_latency = (self->flags & ASYNC_LOW_LATENCY) ? 1 : 0;
78470@@ -505,7 +505,7 @@ static void ircomm_tty_close(struct tty_struct *tty, struct file *filp)
78471 return;
78472 }
78473
78474- if ((tty->count == 1) && (self->open_count != 1)) {
78475+ if ((tty->count == 1) && (local_read(&self->open_count) != 1)) {
78476 /*
78477 * Uh, oh. tty->count is 1, which means that the tty
78478 * structure will be freed. state->count should always
78479@@ -515,16 +515,16 @@ static void ircomm_tty_close(struct tty_struct *tty, struct file *filp)
78480 */
78481 IRDA_DEBUG(0, "%s(), bad serial port count; "
78482 "tty->count is 1, state->count is %d\n", __func__ ,
78483- self->open_count);
78484- self->open_count = 1;
78485+ local_read(&self->open_count));
78486+ local_set(&self->open_count, 1);
78487 }
78488
78489- if (--self->open_count < 0) {
78490+ if (local_dec_return(&self->open_count) < 0) {
78491 IRDA_ERROR("%s(), bad serial port count for ttys%d: %d\n",
78492- __func__, self->line, self->open_count);
78493- self->open_count = 0;
78494+ __func__, self->line, local_read(&self->open_count));
78495+ local_set(&self->open_count, 0);
78496 }
78497- if (self->open_count) {
78498+ if (local_read(&self->open_count)) {
78499 spin_unlock_irqrestore(&self->spinlock, flags);
78500
78501 IRDA_DEBUG(0, "%s(), open count > 0\n", __func__ );
78502@@ -556,7 +556,7 @@ static void ircomm_tty_close(struct tty_struct *tty, struct file *filp)
78503 tty->closing = 0;
78504 self->tty = NULL;
78505
78506- if (self->blocked_open) {
78507+ if (local_read(&self->blocked_open)) {
78508 if (self->close_delay)
78509 schedule_timeout_interruptible(self->close_delay);
78510 wake_up_interruptible(&self->open_wait);
78511@@ -1008,7 +1008,7 @@ static void ircomm_tty_hangup(struct tty_struct *tty)
78512 spin_lock_irqsave(&self->spinlock, flags);
78513 self->flags &= ~ASYNC_NORMAL_ACTIVE;
78514 self->tty = NULL;
78515- self->open_count = 0;
78516+ local_set(&self->open_count, 0);
78517 spin_unlock_irqrestore(&self->spinlock, flags);
78518
78519 wake_up_interruptible(&self->open_wait);
78520@@ -1355,7 +1355,7 @@ static void ircomm_tty_line_info(struct ircomm_tty_cb *self, struct seq_file *m)
78521 seq_putc(m, '\n');
78522
78523 seq_printf(m, "Role: %s\n", self->client ? "client" : "server");
78524- seq_printf(m, "Open count: %d\n", self->open_count);
78525+ seq_printf(m, "Open count: %d\n", local_read(&self->open_count));
78526 seq_printf(m, "Max data size: %d\n", self->max_data_size);
78527 seq_printf(m, "Max header size: %d\n", self->max_header_size);
78528
78529diff --git a/net/iucv/af_iucv.c b/net/iucv/af_iucv.c
78530index cd6f7a9..e63fe89 100644
78531--- a/net/iucv/af_iucv.c
78532+++ b/net/iucv/af_iucv.c
78533@@ -782,10 +782,10 @@ static int iucv_sock_autobind(struct sock *sk)
78534
78535 write_lock_bh(&iucv_sk_list.lock);
78536
78537- sprintf(name, "%08x", atomic_inc_return(&iucv_sk_list.autobind_name));
78538+ sprintf(name, "%08x", atomic_inc_return_unchecked(&iucv_sk_list.autobind_name));
78539 while (__iucv_get_sock_by_name(name)) {
78540 sprintf(name, "%08x",
78541- atomic_inc_return(&iucv_sk_list.autobind_name));
78542+ atomic_inc_return_unchecked(&iucv_sk_list.autobind_name));
78543 }
78544
78545 write_unlock_bh(&iucv_sk_list.lock);
78546diff --git a/net/key/af_key.c b/net/key/af_key.c
78547index 34e4185..8823368 100644
78548--- a/net/key/af_key.c
78549+++ b/net/key/af_key.c
78550@@ -3016,10 +3016,10 @@ static int pfkey_send_policy_notify(struct xfrm_policy *xp, int dir, const struc
78551 static u32 get_acqseq(void)
78552 {
78553 u32 res;
78554- static atomic_t acqseq;
78555+ static atomic_unchecked_t acqseq;
78556
78557 do {
78558- res = atomic_inc_return(&acqseq);
78559+ res = atomic_inc_return_unchecked(&acqseq);
78560 } while (!res);
78561 return res;
78562 }
78563diff --git a/net/mac80211/ieee80211_i.h b/net/mac80211/ieee80211_i.h
78564index bb61f77..3788d63 100644
78565--- a/net/mac80211/ieee80211_i.h
78566+++ b/net/mac80211/ieee80211_i.h
78567@@ -28,6 +28,7 @@
78568 #include <net/ieee80211_radiotap.h>
78569 #include <net/cfg80211.h>
78570 #include <net/mac80211.h>
78571+#include <asm/local.h>
78572 #include "key.h"
78573 #include "sta_info.h"
78574 #include "debug.h"
78575@@ -840,7 +841,7 @@ struct ieee80211_local {
78576 /* also used to protect ampdu_ac_queue and amdpu_ac_stop_refcnt */
78577 spinlock_t queue_stop_reason_lock;
78578
78579- int open_count;
78580+ local_t open_count;
78581 int monitors, cooked_mntrs;
78582 /* number of interfaces with corresponding FIF_ flags */
78583 int fif_fcsfail, fif_plcpfail, fif_control, fif_other_bss, fif_pspoll,
78584diff --git a/net/mac80211/iface.c b/net/mac80211/iface.c
78585index c93d395..a305570 100644
78586--- a/net/mac80211/iface.c
78587+++ b/net/mac80211/iface.c
78588@@ -454,7 +454,7 @@ static int ieee80211_do_open(struct net_device *dev, bool coming_up)
78589 break;
78590 }
78591
78592- if (local->open_count == 0) {
78593+ if (local_read(&local->open_count) == 0) {
78594 res = drv_start(local);
78595 if (res)
78596 goto err_del_bss;
78597@@ -497,7 +497,7 @@ static int ieee80211_do_open(struct net_device *dev, bool coming_up)
78598 break;
78599 }
78600
78601- if (local->monitors == 0 && local->open_count == 0) {
78602+ if (local->monitors == 0 && local_read(&local->open_count) == 0) {
78603 res = ieee80211_add_virtual_monitor(local);
78604 if (res)
78605 goto err_stop;
78606@@ -594,7 +594,7 @@ static int ieee80211_do_open(struct net_device *dev, bool coming_up)
78607 mutex_unlock(&local->mtx);
78608
78609 if (coming_up)
78610- local->open_count++;
78611+ local_inc(&local->open_count);
78612
78613 if (hw_reconf_flags)
78614 ieee80211_hw_config(local, hw_reconf_flags);
78615@@ -607,7 +607,7 @@ static int ieee80211_do_open(struct net_device *dev, bool coming_up)
78616 err_del_interface:
78617 drv_remove_interface(local, sdata);
78618 err_stop:
78619- if (!local->open_count)
78620+ if (!local_read(&local->open_count))
78621 drv_stop(local);
78622 err_del_bss:
78623 sdata->bss = NULL;
78624@@ -736,7 +736,7 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
78625 }
78626
78627 if (going_down)
78628- local->open_count--;
78629+ local_dec(&local->open_count);
78630
78631 switch (sdata->vif.type) {
78632 case NL80211_IFTYPE_AP_VLAN:
78633@@ -796,7 +796,7 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
78634
78635 ieee80211_recalc_ps(local, -1);
78636
78637- if (local->open_count == 0) {
78638+ if (local_read(&local->open_count) == 0) {
78639 if (local->ops->napi_poll)
78640 napi_disable(&local->napi);
78641 ieee80211_clear_tx_pending(local);
78642@@ -828,7 +828,7 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
78643 }
78644 spin_unlock_irqrestore(&local->queue_stop_reason_lock, flags);
78645
78646- if (local->monitors == local->open_count && local->monitors > 0)
78647+ if (local->monitors == local_read(&local->open_count) && local->monitors > 0)
78648 ieee80211_add_virtual_monitor(local);
78649 }
78650
78651diff --git a/net/mac80211/main.c b/net/mac80211/main.c
78652index c26e231..8916637 100644
78653--- a/net/mac80211/main.c
78654+++ b/net/mac80211/main.c
78655@@ -166,7 +166,7 @@ int ieee80211_hw_config(struct ieee80211_local *local, u32 changed)
78656 local->hw.conf.power_level = power;
78657 }
78658
78659- if (changed && local->open_count) {
78660+ if (changed && local_read(&local->open_count)) {
78661 ret = drv_config(local, changed);
78662 /*
78663 * Goal:
78664diff --git a/net/mac80211/pm.c b/net/mac80211/pm.c
78665index 5c572e7..ecf75ce 100644
78666--- a/net/mac80211/pm.c
78667+++ b/net/mac80211/pm.c
78668@@ -34,7 +34,7 @@ int __ieee80211_suspend(struct ieee80211_hw *hw, struct cfg80211_wowlan *wowlan)
78669 struct ieee80211_sub_if_data *sdata;
78670 struct sta_info *sta;
78671
78672- if (!local->open_count)
78673+ if (!local_read(&local->open_count))
78674 goto suspend;
78675
78676 ieee80211_scan_cancel(local);
78677@@ -72,7 +72,7 @@ int __ieee80211_suspend(struct ieee80211_hw *hw, struct cfg80211_wowlan *wowlan)
78678 cancel_work_sync(&local->dynamic_ps_enable_work);
78679 del_timer_sync(&local->dynamic_ps_timer);
78680
78681- local->wowlan = wowlan && local->open_count;
78682+ local->wowlan = wowlan && local_read(&local->open_count);
78683 if (local->wowlan) {
78684 int err = drv_suspend(local, wowlan);
78685 if (err < 0) {
78686@@ -143,7 +143,7 @@ int __ieee80211_suspend(struct ieee80211_hw *hw, struct cfg80211_wowlan *wowlan)
78687 drv_remove_interface(local, sdata);
78688
78689 /* stop hardware - this must stop RX */
78690- if (local->open_count)
78691+ if (local_read(&local->open_count))
78692 ieee80211_stop_device(local);
78693
78694 suspend:
78695diff --git a/net/mac80211/rate.c b/net/mac80211/rate.c
78696index 3313c11..bec9f17 100644
78697--- a/net/mac80211/rate.c
78698+++ b/net/mac80211/rate.c
78699@@ -494,7 +494,7 @@ int ieee80211_init_rate_ctrl_alg(struct ieee80211_local *local,
78700
78701 ASSERT_RTNL();
78702
78703- if (local->open_count)
78704+ if (local_read(&local->open_count))
78705 return -EBUSY;
78706
78707 if (local->hw.flags & IEEE80211_HW_HAS_RATE_CONTROL) {
78708diff --git a/net/mac80211/rc80211_pid_debugfs.c b/net/mac80211/rc80211_pid_debugfs.c
78709index c97a065..ff61928 100644
78710--- a/net/mac80211/rc80211_pid_debugfs.c
78711+++ b/net/mac80211/rc80211_pid_debugfs.c
78712@@ -193,7 +193,7 @@ static ssize_t rate_control_pid_events_read(struct file *file, char __user *buf,
78713
78714 spin_unlock_irqrestore(&events->lock, status);
78715
78716- if (copy_to_user(buf, pb, p))
78717+ if (p > sizeof(pb) || copy_to_user(buf, pb, p))
78718 return -EFAULT;
78719
78720 return p;
78721diff --git a/net/mac80211/util.c b/net/mac80211/util.c
78722index 1cfe6d5..c428ba3 100644
78723--- a/net/mac80211/util.c
78724+++ b/net/mac80211/util.c
78725@@ -1279,7 +1279,7 @@ int ieee80211_reconfig(struct ieee80211_local *local)
78726 }
78727 #endif
78728 /* everything else happens only if HW was up & running */
78729- if (!local->open_count)
78730+ if (!local_read(&local->open_count))
78731 goto wake_up;
78732
78733 /*
78734diff --git a/net/netfilter/Kconfig b/net/netfilter/Kconfig
78735index c19b214..471fad1 100644
78736--- a/net/netfilter/Kconfig
78737+++ b/net/netfilter/Kconfig
78738@@ -872,6 +872,16 @@ config NETFILTER_XT_MATCH_ESP
78739
78740 To compile it as a module, choose M here. If unsure, say N.
78741
78742+config NETFILTER_XT_MATCH_GRADM
78743+ tristate '"gradm" match support'
78744+ depends on NETFILTER_XTABLES && NETFILTER_ADVANCED
78745+ depends on GRKERNSEC && !GRKERNSEC_NO_RBAC
78746+ ---help---
78747+ The gradm match allows to match on grsecurity RBAC being enabled.
78748+ It is useful when iptables rules are applied early on bootup to
78749+ prevent connections to the machine (except from a trusted host)
78750+ while the RBAC system is disabled.
78751+
78752 config NETFILTER_XT_MATCH_HASHLIMIT
78753 tristate '"hashlimit" match support'
78754 depends on (IP6_NF_IPTABLES || IP6_NF_IPTABLES=n)
78755diff --git a/net/netfilter/Makefile b/net/netfilter/Makefile
78756index 1c5160f..145ae21 100644
78757--- a/net/netfilter/Makefile
78758+++ b/net/netfilter/Makefile
78759@@ -90,6 +90,7 @@ obj-$(CONFIG_NETFILTER_XT_MATCH_DEVGROUP) += xt_devgroup.o
78760 obj-$(CONFIG_NETFILTER_XT_MATCH_DSCP) += xt_dscp.o
78761 obj-$(CONFIG_NETFILTER_XT_MATCH_ECN) += xt_ecn.o
78762 obj-$(CONFIG_NETFILTER_XT_MATCH_ESP) += xt_esp.o
78763+obj-$(CONFIG_NETFILTER_XT_MATCH_GRADM) += xt_gradm.o
78764 obj-$(CONFIG_NETFILTER_XT_MATCH_HASHLIMIT) += xt_hashlimit.o
78765 obj-$(CONFIG_NETFILTER_XT_MATCH_HELPER) += xt_helper.o
78766 obj-$(CONFIG_NETFILTER_XT_MATCH_HL) += xt_hl.o
78767diff --git a/net/netfilter/ipvs/ip_vs_conn.c b/net/netfilter/ipvs/ip_vs_conn.c
78768index 1548df9..98ad9b4 100644
78769--- a/net/netfilter/ipvs/ip_vs_conn.c
78770+++ b/net/netfilter/ipvs/ip_vs_conn.c
78771@@ -557,7 +557,7 @@ ip_vs_bind_dest(struct ip_vs_conn *cp, struct ip_vs_dest *dest)
78772 /* Increase the refcnt counter of the dest */
78773 atomic_inc(&dest->refcnt);
78774
78775- conn_flags = atomic_read(&dest->conn_flags);
78776+ conn_flags = atomic_read_unchecked(&dest->conn_flags);
78777 if (cp->protocol != IPPROTO_UDP)
78778 conn_flags &= ~IP_VS_CONN_F_ONE_PACKET;
78779 flags = cp->flags;
78780@@ -902,7 +902,7 @@ ip_vs_conn_new(const struct ip_vs_conn_param *p,
78781 atomic_set(&cp->refcnt, 1);
78782
78783 atomic_set(&cp->n_control, 0);
78784- atomic_set(&cp->in_pkts, 0);
78785+ atomic_set_unchecked(&cp->in_pkts, 0);
78786
78787 atomic_inc(&ipvs->conn_count);
78788 if (flags & IP_VS_CONN_F_NO_CPORT)
78789@@ -1183,7 +1183,7 @@ static inline int todrop_entry(struct ip_vs_conn *cp)
78790
78791 /* Don't drop the entry if its number of incoming packets is not
78792 located in [0, 8] */
78793- i = atomic_read(&cp->in_pkts);
78794+ i = atomic_read_unchecked(&cp->in_pkts);
78795 if (i > 8 || i < 0) return 0;
78796
78797 if (!todrop_rate[i]) return 0;
78798diff --git a/net/netfilter/ipvs/ip_vs_core.c b/net/netfilter/ipvs/ip_vs_core.c
78799index b54ecce..fc5f6cf 100644
78800--- a/net/netfilter/ipvs/ip_vs_core.c
78801+++ b/net/netfilter/ipvs/ip_vs_core.c
78802@@ -562,7 +562,7 @@ int ip_vs_leave(struct ip_vs_service *svc, struct sk_buff *skb,
78803 ret = cp->packet_xmit(skb, cp, pd->pp);
78804 /* do not touch skb anymore */
78805
78806- atomic_inc(&cp->in_pkts);
78807+ atomic_inc_unchecked(&cp->in_pkts);
78808 ip_vs_conn_put(cp);
78809 return ret;
78810 }
78811@@ -1611,7 +1611,7 @@ ip_vs_in(unsigned int hooknum, struct sk_buff *skb, int af)
78812 if (cp->flags & IP_VS_CONN_F_ONE_PACKET)
78813 pkts = sysctl_sync_threshold(ipvs);
78814 else
78815- pkts = atomic_add_return(1, &cp->in_pkts);
78816+ pkts = atomic_add_return_unchecked(1, &cp->in_pkts);
78817
78818 if (ipvs->sync_state & IP_VS_STATE_MASTER)
78819 ip_vs_sync_conn(net, cp, pkts);
78820diff --git a/net/netfilter/ipvs/ip_vs_ctl.c b/net/netfilter/ipvs/ip_vs_ctl.c
78821index f51013c..c99ee52 100644
78822--- a/net/netfilter/ipvs/ip_vs_ctl.c
78823+++ b/net/netfilter/ipvs/ip_vs_ctl.c
78824@@ -788,7 +788,7 @@ __ip_vs_update_dest(struct ip_vs_service *svc, struct ip_vs_dest *dest,
78825 ip_vs_rs_hash(ipvs, dest);
78826 write_unlock_bh(&ipvs->rs_lock);
78827 }
78828- atomic_set(&dest->conn_flags, conn_flags);
78829+ atomic_set_unchecked(&dest->conn_flags, conn_flags);
78830
78831 /* bind the service */
78832 if (!dest->svc) {
78833@@ -2076,7 +2076,7 @@ static int ip_vs_info_seq_show(struct seq_file *seq, void *v)
78834 " %-7s %-6d %-10d %-10d\n",
78835 &dest->addr.in6,
78836 ntohs(dest->port),
78837- ip_vs_fwd_name(atomic_read(&dest->conn_flags)),
78838+ ip_vs_fwd_name(atomic_read_unchecked(&dest->conn_flags)),
78839 atomic_read(&dest->weight),
78840 atomic_read(&dest->activeconns),
78841 atomic_read(&dest->inactconns));
78842@@ -2087,7 +2087,7 @@ static int ip_vs_info_seq_show(struct seq_file *seq, void *v)
78843 "%-7s %-6d %-10d %-10d\n",
78844 ntohl(dest->addr.ip),
78845 ntohs(dest->port),
78846- ip_vs_fwd_name(atomic_read(&dest->conn_flags)),
78847+ ip_vs_fwd_name(atomic_read_unchecked(&dest->conn_flags)),
78848 atomic_read(&dest->weight),
78849 atomic_read(&dest->activeconns),
78850 atomic_read(&dest->inactconns));
78851@@ -2557,7 +2557,7 @@ __ip_vs_get_dest_entries(struct net *net, const struct ip_vs_get_dests *get,
78852
78853 entry.addr = dest->addr.ip;
78854 entry.port = dest->port;
78855- entry.conn_flags = atomic_read(&dest->conn_flags);
78856+ entry.conn_flags = atomic_read_unchecked(&dest->conn_flags);
78857 entry.weight = atomic_read(&dest->weight);
78858 entry.u_threshold = dest->u_threshold;
78859 entry.l_threshold = dest->l_threshold;
78860@@ -3092,7 +3092,7 @@ static int ip_vs_genl_fill_dest(struct sk_buff *skb, struct ip_vs_dest *dest)
78861 if (nla_put(skb, IPVS_DEST_ATTR_ADDR, sizeof(dest->addr), &dest->addr) ||
78862 nla_put_u16(skb, IPVS_DEST_ATTR_PORT, dest->port) ||
78863 nla_put_u32(skb, IPVS_DEST_ATTR_FWD_METHOD,
78864- (atomic_read(&dest->conn_flags) &
78865+ (atomic_read_unchecked(&dest->conn_flags) &
78866 IP_VS_CONN_F_FWD_MASK)) ||
78867 nla_put_u32(skb, IPVS_DEST_ATTR_WEIGHT,
78868 atomic_read(&dest->weight)) ||
78869diff --git a/net/netfilter/ipvs/ip_vs_sync.c b/net/netfilter/ipvs/ip_vs_sync.c
78870index effa10c..9058928 100644
78871--- a/net/netfilter/ipvs/ip_vs_sync.c
78872+++ b/net/netfilter/ipvs/ip_vs_sync.c
78873@@ -596,7 +596,7 @@ static void ip_vs_sync_conn_v0(struct net *net, struct ip_vs_conn *cp,
78874 cp = cp->control;
78875 if (cp) {
78876 if (cp->flags & IP_VS_CONN_F_TEMPLATE)
78877- pkts = atomic_add_return(1, &cp->in_pkts);
78878+ pkts = atomic_add_return_unchecked(1, &cp->in_pkts);
78879 else
78880 pkts = sysctl_sync_threshold(ipvs);
78881 ip_vs_sync_conn(net, cp->control, pkts);
78882@@ -758,7 +758,7 @@ control:
78883 if (!cp)
78884 return;
78885 if (cp->flags & IP_VS_CONN_F_TEMPLATE)
78886- pkts = atomic_add_return(1, &cp->in_pkts);
78887+ pkts = atomic_add_return_unchecked(1, &cp->in_pkts);
78888 else
78889 pkts = sysctl_sync_threshold(ipvs);
78890 goto sloop;
78891@@ -885,7 +885,7 @@ static void ip_vs_proc_conn(struct net *net, struct ip_vs_conn_param *param,
78892
78893 if (opt)
78894 memcpy(&cp->in_seq, opt, sizeof(*opt));
78895- atomic_set(&cp->in_pkts, sysctl_sync_threshold(ipvs));
78896+ atomic_set_unchecked(&cp->in_pkts, sysctl_sync_threshold(ipvs));
78897 cp->state = state;
78898 cp->old_state = cp->state;
78899 /*
78900diff --git a/net/netfilter/ipvs/ip_vs_xmit.c b/net/netfilter/ipvs/ip_vs_xmit.c
78901index c3c6291..3376d73 100644
78902--- a/net/netfilter/ipvs/ip_vs_xmit.c
78903+++ b/net/netfilter/ipvs/ip_vs_xmit.c
78904@@ -1157,7 +1157,7 @@ ip_vs_icmp_xmit(struct sk_buff *skb, struct ip_vs_conn *cp,
78905 else
78906 rc = NF_ACCEPT;
78907 /* do not touch skb anymore */
78908- atomic_inc(&cp->in_pkts);
78909+ atomic_inc_unchecked(&cp->in_pkts);
78910 goto out;
78911 }
78912
78913@@ -1278,7 +1278,7 @@ ip_vs_icmp_xmit_v6(struct sk_buff *skb, struct ip_vs_conn *cp,
78914 else
78915 rc = NF_ACCEPT;
78916 /* do not touch skb anymore */
78917- atomic_inc(&cp->in_pkts);
78918+ atomic_inc_unchecked(&cp->in_pkts);
78919 goto out;
78920 }
78921
78922diff --git a/net/netfilter/nf_conntrack_core.c b/net/netfilter/nf_conntrack_core.c
78923index 2ceec64..a5b8a61 100644
78924--- a/net/netfilter/nf_conntrack_core.c
78925+++ b/net/netfilter/nf_conntrack_core.c
78926@@ -1529,6 +1529,10 @@ err_extend:
78927 #define UNCONFIRMED_NULLS_VAL ((1<<30)+0)
78928 #define DYING_NULLS_VAL ((1<<30)+1)
78929
78930+#ifdef CONFIG_GRKERNSEC_HIDESYM
78931+static atomic_unchecked_t conntrack_cache_id = ATOMIC_INIT(0);
78932+#endif
78933+
78934 static int nf_conntrack_init_net(struct net *net)
78935 {
78936 int ret;
78937@@ -1542,7 +1546,11 @@ static int nf_conntrack_init_net(struct net *net)
78938 goto err_stat;
78939 }
78940
78941+#ifdef CONFIG_GRKERNSEC_HIDESYM
78942+ net->ct.slabname = kasprintf(GFP_KERNEL, "nf_conntrack_%08lx", atomic_inc_return_unchecked(&conntrack_cache_id));
78943+#else
78944 net->ct.slabname = kasprintf(GFP_KERNEL, "nf_conntrack_%p", net);
78945+#endif
78946 if (!net->ct.slabname) {
78947 ret = -ENOMEM;
78948 goto err_slabname;
78949diff --git a/net/netfilter/nfnetlink_log.c b/net/netfilter/nfnetlink_log.c
78950index 5cfb5be..217c6d8 100644
78951--- a/net/netfilter/nfnetlink_log.c
78952+++ b/net/netfilter/nfnetlink_log.c
78953@@ -70,7 +70,7 @@ struct nfulnl_instance {
78954 };
78955
78956 static DEFINE_SPINLOCK(instances_lock);
78957-static atomic_t global_seq;
78958+static atomic_unchecked_t global_seq;
78959
78960 #define INSTANCE_BUCKETS 16
78961 static struct hlist_head instance_table[INSTANCE_BUCKETS];
78962@@ -523,7 +523,7 @@ __build_packet_message(struct nfulnl_instance *inst,
78963 /* global sequence number */
78964 if ((inst->flags & NFULNL_CFG_F_SEQ_GLOBAL) &&
78965 nla_put_be32(inst->skb, NFULA_SEQ_GLOBAL,
78966- htonl(atomic_inc_return(&global_seq))))
78967+ htonl(atomic_inc_return_unchecked(&global_seq))))
78968 goto nla_put_failure;
78969
78970 if (data_len) {
78971diff --git a/net/netfilter/xt_gradm.c b/net/netfilter/xt_gradm.c
78972new file mode 100644
78973index 0000000..c566332
78974--- /dev/null
78975+++ b/net/netfilter/xt_gradm.c
78976@@ -0,0 +1,51 @@
78977+/*
78978+ * gradm match for netfilter
78979